{"source_code": "require 'time'\nn=gets.to_i\ntab=[]; result=1\nn.times{tab< y\n\t\tresult += 1\n\tend\n\ty\nend\n\nputs result\n\n", "positive_code": [{"source_code": "D = 1440\nn = gets.to_i\nn.times{$* << ($1.to_i % 12 * 60 + $2.to_i + ($3 == 'a' ? 0 : 720)) % D if gets =~ /^\\[(\\d+):(\\d+) ([ap])/}\n$*.each_index do |i|\n\t$*[i] += D while i >= 1 && $*[i] < $*[i - 1]\n\t$*[i] += D while i >= 10 && $*[i] == $*[i - 10]\nend\np $*[-1] / D + 1\n"}, {"source_code": "n = gets.to_i\nm = (0...n).map do \n h, m, ap = gets.strip.match(/\\[(\\d+):(\\d+) (.).+\\]/)[1..-1]\n (h.to_i % 12 * 60 + m.to_i + (ap == ?a ? 0 : 720)) % 1440\nend\nans = 1\ni = 0\nuntil i + 1 == n\n if m[i] > m[i + 1]\n ans += 1\n i += 1\n elsif m[i] == m[i + 1]\n j = i + 1\n j += 1 until j == n || j - i == 11 || m[j] != m[i]\n if j - i == 11\n ans += 1\n i = j - 1\n else\n i += 1\n end\n else\n i += 1\n end\nend\np ans\n"}], "negative_code": [{"source_code": "n = gets.to_i\nn.times{$* << ($1.to_i * 60 + $2.to_i + ($3 == 'a' ? 0 : 720)) % 1440 if gets =~ /^\\[(\\d+):(\\d+) ([ap])/}\n$*.each_index do |i|\n\t$*[i] += 1440 while i >= 1 && $*[i] < $*[i - 1]\n\t$*[i] += 1440 while i >= 10 && $*[i] <= $*[i - 10]\nend\np $*[-1] / 1440 + 1\n"}, {"source_code": "n = gets.to_i\nhm = (0...n).map do \n h, m, ap = gets.strip.match(/\\[(\\d+):(\\d+) (.).+\\]/)[1..-1]\n [h.to_i % 12 + (ap == ?a ? 0 : 12), m.to_i]\nend\nans = 1\ni = 0\nuntil i == n\n j = i + 1\n until j == n\n if hm[j - 1][0] < 24 && hm[j][0] == 24 || (hm[j - 1] <=> hm[j]) == 1\n ans += 1\n elsif hm[j - 1] == hm[j]\n k = j + 1\n until k == n || k - i == 11 || hm[k] != hm[i]\n k += 1\n end\n if k - i == 11\n ans += 1\n j = k - 1\n break\n end\n end\n j += 1\n end\n i = j\nend\np ans\n"}, {"source_code": "n = gets.to_i\nhm = (0...n).map do \n h, m, ap = gets.strip.match(/\\[(\\d+):(\\d+) (.).+\\]/)[1..-1]\n [h.to_i + (ap == ?a ? 0 : 12), m.to_i]\nend\nans = 1\ni = 0\nuntil i == n\n j = i + 1\n until j == n\n if hm[j - 1][0] < 24 && hm[j][0] == 24 || (hm[j - 1] <=> hm[j]) == 1\n ans += 1\n elsif hm[j - 1] == hm[j]\n k = j + 1\n until k == n || k - i == 11 || hm[k] != hm[i]\n k += 1\n end\n if k - i == 11\n ans += 1\n j = k\n break\n end\n end\n j += 1\n end\n i = j\nend\np ans\n"}, {"source_code": "n = gets.to_i\nhm = (0...n).map do \n h, m, ap = gets.strip.match(/\\[(\\d+):(\\d+) (.).+\\]/)[1..-1]\n [h.to_i % 12 + (ap == ?a ? 0 : 12), m.to_i]\nend\nans = 1\ni = 0\nuntil i == n\n j = i + 1\n until j == n\n if hm[j - 1][0] < 24 && hm[j][0] == 24 || (hm[j - 1] <=> hm[j]) == 1\n ans += 1\n elsif hm[j - 1] == hm[j]\n k = j + 1\n until k == n || k - i == 11 || hm[k] != hm[i]\n k += 1\n end\n if k - i == 1000\n ans += 1\n j = k\n break\n end\n end\n j += 1\n end\n i = j\nend\np ans\n"}, {"source_code": "n = gets.to_i\nhm = (0...n).map do \n h, m, ap = gets.strip.match(/\\[(\\d+):(\\d+) (.).+\\]/)[1..-1]\n [h.to_i % 12 + (ap == ?a ? 0 : 12), m.to_i]\nend\nans = 1\ni = 0\nuntil i == n\n j = i + 1\n until j == n\n if hm[j - 1][0] < 24 && hm[j][0] == 24 || (hm[j - 1] <=> hm[j]) == 1\n ans += 1\n elsif hm[j - 1] == hm[j]\n k = j + 1\n until k == n || k - i == 11 || hm[k] != hm[i]\n k += 1\n end\n if k - i == 11\n ans += 1\n j = k\n break\n end\n end\n j += 1\n end\n i = j\nend\np ans\n"}, {"source_code": "require 'time'\nn=gets.to_i\ntab=[]; result=1\nn.times{tab< y\n\t\tresult += 1\n\tend\n\ty\nend\n\nputs result\n\n"}], "src_uid": "54f8b8e6711ff5c69e0bc38a6e2f4999"} {"source_code": "gets;a=gets.split.map &:to_i\nc,t=(1..a.max).map{|t|[a.map{|x|[(t-x).abs-1,0].max}.reduce(:+),t]}.min\nputs [t,c]*' '", "positive_code": [{"source_code": "n = gets.to_i\narr = gets.split(\" \").map{|i| i.to_i }\nsum, n = 1000000, 0\n(arr.min..arr.max).each do |t|\n s = 0\n arr.each { |i|\n s += i - t - 1 if i > t\n s += t - i - 1 if t > i\n }\n if s < sum\n sum = s\n n = t\n end\nend\nputs \"#{n} #{sum}\""}, {"source_code": "stick_num = gets.to_i\nstick_length = gets.split.map(&:to_i)\ncomp_num = 0\nsum_cost = 0\ntotal_cost = 0\nlength = 0\nindex = 0\n\nfor x in stick_length.min..stick_length.max do\n for i in 0..stick_num - 1 do\n if stick_length[i] < x\n comp_num = x - 1\n elsif stick_length[i] > x\n comp_num = x + 1\n else\n next\n end\n sum_cost += (comp_num - stick_length[i]).abs\n end\n if x == stick_length.min || total_cost > sum_cost\n total_cost = sum_cost\n length = x\n end\n sum_cost = 0\nend\n\nputs \"#{length} #{total_cost}\""}, {"source_code": "n = gets.to_i\narr = gets.split.map(&:to_i)\nt = 1\nres = 0\nans = [1e9, 1e9]\n(1..100).each do |t|\n arr.each do |e|\n if (e > t)\n res += e - t - 1\n else\n if (e < t)\n res += t - e - 1\n end\n end\n end\n if (res < ans[1])\n ans = [t, res]\n end\n res = 0\nend\nputs ans.join(' ')"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nans = 10**6\nm = 1\nfor i in 1..100\n ret = 0\n a.each do |num|\n if num > i\n ret += num-i-1\n elsif num < i\n ret += i-num-1\n end\n end\n if ans > ret\n ans = ret\n m = i\n end\nend\nputs \"#{m} #{ans}\""}, {"source_code": "DBG = true\nn = gets.to_i\na = gets.split.map{|z| z.to_i}\n\ndef foo(j, t)\n if j >= t+1\n return j-t-1\n elsif j <= t-1\n return t-1-j\n else\n return 0\n end\nend\n\nsumbest = 99999999\ntbest = -1\nfor t in 2..99\n sum = 0\n for i in 0...n\n sum += foo(a[i], t)\n end\n if sum < sumbest\n sumbest = sum\n tbest = t\n end\nend\nputs \"#{tbest} #{sumbest}\"\n"}, {"source_code": "def lscan; gets.split.map(&:to_i); end\n\nN = gets.to_i\nA = lscan.sort\n\nbest = [1e18, 0]\n\n(1..1000).each do |i|\n m = i\n c = A.reduce(0){|s,e| s += [(e-m).abs-1, 0].max}\n best = [best, [c, m]].min\nend\n\nputs best.reverse*\" \""}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nn = gets.to_i\na = gets.chomp.split(\" \").map(&:to_i)\n\n\nsums = [0]*100\n\n(1..100).each do |x|\n\ta.each do |y|\n\t\tsums[x-1] += [(y-x).abs-1,0].max\n\tend\nend\n\n#p sums\nputs \"#{sums.index(sums.min)+1} #{sums.min}\""}], "negative_code": [{"source_code": "n = gets.to_i\narr = gets.split.map(&:to_i)\nt1 = (arr.inject(0.0) { |sum, x| sum += x } / arr.size).ceil\nt2 = (arr.inject(0.0) { |sum, x| sum += x } / arr.size).truncate\nres1 = 0\nres2 = 0\narr.each do |e|\n if (e > t1)\n res1 += e - t1 - 1\n else\n if (e < t1)\n res1 += t1 - e - 1\n end\n end\n if (e > t2)\n res2 += e - t2 - 1\n else\n if (e < t2)\n res2 += t2 - e - 1\n end\n end\nend\nif (res1 < res2)\n puts [t1, res1].join(' ')\nelse\n puts [t2, res2].join(' ')\nend"}, {"source_code": "def lscan; gets.split.map(&:to_i); end\n\nN = gets.to_i\nA = lscan.sort\n\nbest = [1e18, 0]\n\n(0..1000).each do |i|\n m = i\n c = A.reduce(0){|s,e| s += [(e-m).abs-1, 0].max}\n best = [best, [c, m]].min\nend\n\nputs best.reverse*\" \""}, {"source_code": "def lscan; gets.split.map(&:to_i); end\n\nN = gets.to_i\nA = lscan.sort\n\nmid = (A[N/2] + A[(N-1)/2])/2 - 1\n\nbest = [1e9, mid]\n\n(-1..1).each do |i|\n m = mid + i\n c = A.reduce(0){|s,e| s += [(e-m).abs-1, 0].max}\n best = [best, [c, m]].min\nend\n\nputs best.reverse*\" \""}, {"source_code": "def lscan; gets.split.map(&:to_i); end\n\nN = gets.to_i\nA = lscan.sort\n\nmid = (A[N/2] + A[(N-1)/2])/2 - 1\n\nbest = [1e9, mid]\n\n(0..100).each do |i|\n m = i\n c = A.reduce(0){|s,e| s += [(e-m).abs-1, 0].max}\n best = [best, [c, m]].min\nend\n\nputs best.reverse*\" \""}], "src_uid": "bce9ebad1dc8bd5aae516c4ca9e551c0"} {"source_code": "gets.to_i.times do\n n = gets.to_i\n x = 0\n if n & 1 == 1 && n >= 9\n n -= 9\n x += 1\n end\n if n % 4 == 2 && n >= 6\n n -= 6\n x += 1\n end\n if n % 4 == 0\n puts x + n / 4\n else\n puts -1\n end\nend\n", "positive_code": [{"source_code": "gets.to_i.times{\nx = gets.to_i\n\tputs ([1,2,3,5,7,11].include?(x) ? -1 : x/4-x%2)\n}"}], "negative_code": [], "src_uid": "0c2550b2df0849a62969edf5b73e0ac5"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).to_a.sort\n\nif a[n] > a[n - 1]\n puts :YES\nelse\n puts :NO\nend\n", "positive_code": [{"source_code": "n,*a=$<.read.split.map &:to_i\na.sort!\nputs a[n-1] a[n - 1]\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).to_a.sort!\n\nif a[n] > a[n - 1]\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).to_a.sort!\n\nif a[n] > a[n - 1]\n puts :YES\nelse\n puts :NO\nend\n"}, {"source_code": "n, a = gets.to_i, gets.split.map(&:to_i).sort!\nputs a[n - 1] < a[n] ? :YES : :NO\n"}, {"source_code": "n, a = gets.to_i, gets.split.map(&:to_i).sort!\nputs a[n - 1] < a[n] ? :YES : :NO\n\n"}, {"source_code": "n = gets.to_i\narray = gets.split.map(&:to_i)\narray.sort!\nputs array[n] > array[n-1] ? 'YES' : 'NO'\n"}], "negative_code": [{"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i).sort\ni = 0\nj = n\nans = \"YES\"\nwhile i < n && j < 2 * n\n if a[i] >= a[j]\n ans = \"NO\"\n break\n end\n i += 1\n j += 1\nend\nputs ans\n"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i).sort\nans = \"YES\"\ncount = Array.new(1000, 0)\n(2 * n).times do |i|\n count[a[i]] += 1\n if count[a[i]] > 1\n ans = \"NO\"\n break\n end\nend\nputs ans\n"}, {"source_code": "n, aa = gets.to_i, gets.split.map(&:to_i).sort!\nputs (0...n).map {|i| aa[i] < aa[i + n]}.all? ? :YES : :NO\n\n"}], "src_uid": "7b806b9a402a83a5b8943e7f3436cc9a"} {"source_code": "n = gets.to_i\ncnt = 0\nleft = -9999999999\n\ntrees = 1.upto(n).map do |_|\n gets.split(' ').map(&:to_i)\nend\n\ntrees.each_with_index do |tree, idx|\n if left < tree[0] - tree[1]\n cnt += 1\n left = tree[0]\n elsif idx == n-1 || tree[0] + tree[1] < trees[idx+1][0]\n cnt += 1\n left = tree[0] + tree[1]\n else\n left = tree[0]\n end\nend\n\nputs cnt", "positive_code": [{"source_code": "def solution(arr)\n count = 0\n last = -2<<2048\n for i in 0...arr.size-1 do\n if arr[i][0] - arr[i][1] > last\n count += 1\n last = arr[i][0]\n elsif arr[i][0] + arr[i][1] < arr[i+1][0]\n count += 1\n last = arr[i][0] + arr[i][1]\n else\n last = arr[i][0]\n end\n end\n count += 1\nend\n\nn = gets.to_i\narr = []\nn.times do\n arr << gets.split.map(&:to_i)\nend\nputs solution(arr)"}, {"source_code": "n = Integer gets\nx = Array.new n\nh = Array.new n\n(0...n).each do |i|\n\tt = gets.split\n\tx[i] = Integer t[0]\n\th[i] = Integer t[1]\nend\n\npx, a = x[0], 1\n(1...n).each do |i|\n\tif i == n - 1\n\t\ta += 1 \n\telsif x[i] - h[i] > px\n\t\tpx = x[i]\n\t\ta += 1\n\telsif x[i] + h[i] < x[i+1] \n\t\ta += 1\n\t\tpx = x[i] + h[i]\n\telse\n\t\tpx = x[i]\n\tend\nend\nputs a"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nind = a[0][0]\ncnt = 2\n1.upto(n - 2) do |i|\n if a[i][0] - a[i][1] > ind\n ind = a[i][0]\n cnt += 1\n elsif a[i + 1][0] - a[i][1] > a[i][0]\n ind = a[i][0] + a[i][1]\n cnt += 1\n else\n ind = a[i][0]\n end\nend\np [cnt, n].min\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nind = a[0][0]\nif n == 1\n cnt = 1\nelse\n cnt = 2\nend\n1.upto(n - 2) do |i|\n if a[i][0] - a[i][1] > ind\n ind = a[i][0]\n cnt += 1\n elsif a[i + 1][0] - a[i][1] > a[i][0]\n ind = a[i][0] + a[i][1]\n cnt += 1\n else\n ind = a[i][0]\n end\nend\np cnt\n"}, {"source_code": "n = gets.to_i\nx = Array.new(n)\nh = Array.new(n)\nn.times do |i|\n x[i], h[i] = gets.split.map(&:to_i)\nend\nans = 2\n(1..n-2).each do |i|\n if x[i] - h[i] > x[i - 1]\n ans += 1\n elsif x[i] + h[i] < x[i + 1] \n ans += 1\n x[i] += h[i]\n end\nend\nputs [ans, n].min"}, {"source_code": "n=gets.to_i\nx=[]\nn.times{\n\ta,b=gets.split.map{|e| e.to_i}\n\tx<<[a,b]\n}\nans=1\nt1=x[0]\nx.shift\n\n\nwhile !x.empty?\n\tt2=x[0]\n\tl=t2[0]-t2[1]\n\tif t1[0]1 then\n\t\t\tt3=x[1]\n\t\t\tr=t2[0]+t2[1]\n\t\t\tif r h\n l = true\n else\n s = true\n r = true\n end\n else\n # revert last one to stand, must be rightfell (always x_n < x_n+1)\n left -= last_height\n fell -= 1\n if x - left > h\n l = true\n else\n s = true\n r = true\n end\n end\n\n left = x # next left\n\n if l == true\n fell += 1\n last_height = 0 # don't care\n else\n if r == true\n fell += 1\n left += h\n last_height = h\n end\n end\n\n # p \"l #{l} s #{s} r #{r}, left = #{left}, last_height = #{last_height}, fell = #{fell}\"\n}\n\nputs fell\n"}], "negative_code": [{"source_code": "def solution(arr)\n count = 0\n last = -2<<2048\n for i in 0...arr.size-1 do\n if arr[i][0] - arr[i][1] > last\n count += 1\n last = arr[i][0]\n elsif arr[i][0] + arr[i][1] < arr[i+1][0]\n count += 1\n last = arr[i][0] + arr[i][1]\n end\n end\n count += 1\nend\n\nn = gets.to_i\narr = []\nn.times do\n arr << gets.split.map(&:to_i)\nend\nputs solution(arr)\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nind = a[0][0]\ncnt = 2\n1.upto(n - 2) do |i|\n if a[i][0] - ind > a[i][1]\n ind = a[i][0]\n cnt += 1\n elsif a[i + 1][0] - a[i][0] > a[i][1]\n ind = a[i][0] + a[i][1]\n cnt += 1\n end\nend\np cnt\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nind = a[0][0]\ncnt = 2\n# p a\n1.upto(n - 2) do |i|\n if a[i][0] - a[i][1] > ind\n ind = a[i][0]\n cnt += 1\n elsif a[i + 1][0] - a[i][1] > a[i][0]\n ind = a[i][0] + a[i][1]\n cnt += 1\n else\n ind = a[i][0]\n end\n # p \"#{a[i]} #{cnt}\"\nend\np cnt\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nputs 2 + a.each_cons(3).count{|x, y, z| y[0] - x[0] > y[1] || z[0] - y[0] > y[1]}\n"}, {"source_code": "n = Integer gets\nx = Array.new n\nh = Array.new n\n(0...n).each do |i|\n\tt = gets.split\n\tx[i] = Integer t[0]\n\th[i] = Integer t[1]\nend\n\npx = x[0]\na = 1\n(1...n).each do |i|\n\tif x[i] - h[i] > px\n\t\tpx = x[i]\n\t\ta += 1\n\telsif i == n - 1\n\t\ta += 1 \n\telsif x[i] + h[i] < x[i+1] \n\t\ta += 1\n\t\tpx = x[i] + h[i]\n\tend\nend\nputs a"}, {"source_code": "n=gets.to_i\nx=[]\nn.times{\n\ta,b=gets.split.map{|e| e.to_i}\n\tx<<[a,a-b]\n\tx<<[a+b,a]\n}\nx.sort!\nans=1\nt1=x[0]\nx.shift\nwhile !x.empty?\n\tt2=x[0]\n\tif t1[0] a ? b - a : (a + b) % 2\nend\n\ndef taskB\n a, b, c = gets.chomp.split(\" \").map(&:to_i)\n z, x, y = gets.chomp.split(\" \").map(&:to_i)\n minCX = [c, x].min\n puts (minCX - [0, y - a - c + minCX].max)*2\nend\n\nt = gets.chomp.to_i\nwhile (t-=1) >= 0\n taskA\nend\n", "positive_code": [{"source_code": "gets.to_i.times{n,k=gets.split.map{|x|x.to_i};p [k-n,n-k&1].max}"}, {"source_code": "t =gets.to_i\n\nt.times do\n n,k = gets.split.map(&:to_i)\n if k <= n then \n if (n-k)&1==0 then puts 0\n else puts 1\n end\n else puts k-n\n end\nend"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n if n <= k\n puts k - n;\n else\n if n.even? && k.odd? || n.odd? && k.even?\n puts 1\n else\n puts 0\n end\n end\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n a,k = gets.chomp.split(\" \").map(&:to_i)\n if a <= k\n ans << k-a\n else\n if a % 2 == k % 2\n ans << 0\n else\n ans << 1\n end\n end\nend\nans.each do |x|\n puts x\nend"}, {"source_code": "gets.to_i.times{n,k=gets.split.map(&:to_i);p [k-n,n-k&1].max}\n"}, {"source_code": "gets.to_i.times do\n a, d = gets.split.map(&:to_i)\n puts d >= a ? d - a : ((a.even? && d.even?) || (a.odd? && d.odd?)) ? 0 : 1\nend"}, {"source_code": "gets.to_i.times{n,k=gets.split.map(&:to_i);p [k-n,n-k&1].max}\n"}, {"source_code": "t = gets.chomp.to_i\n\nwhile (t-=1) >= 0\n a, b = gets.chomp.split(\" \").map(&:to_i)\n puts b > a ? b - a : (a + b) % 2\nend"}, {"source_code": "gets.to_i.times{n,k=gets.split.map{|x|x.to_i};p [k-n,n-k&1].max}"}, {"source_code": "gets.to_i.times{n,k=gets.split.map{|x|x.to_i};puts [k-n,(n-k)%2].max}"}, {"source_code": "gets.to_i.times{n,k=gets.split.map{|x|x.to_i};puts [k-n,n-k&1].max}"}, {"source_code": "gets.to_i.times{n,k=gets.split.map(&:to_i);p [k-n,n-k&1].max}\n"}, {"source_code": "gets.to_i.times{n,k=gets.split.map(&:to_i);p [k-n,n-k&1].max}\n"}], "negative_code": [], "src_uid": "f98d1d426f68241bad437eb221f617f4"} {"source_code": "def solution\n gets\n as = read_ints\n\n final = as.map { |x| x.odd? ? x : x - 1 }\n puts final.join(' ')\n\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\nsolution", "positive_code": [{"source_code": "gets;puts gets.split.map{|_|n=_.to_i;n+n%2-1}*' '"}, {"source_code": "gets\nputs gets.split.map{|c| (c.to_i-1)/2*2+1}.join(' ')"}, {"source_code": "ary_size = gets.to_i\n\ngets.split(\" \").each do |number|\n number = number.to_i\n number = number % 2 === 0 ? (number-1) : number\n space = ary_size === 1 ? \"\" : \" \"\n print \"#{number}#{space}\"\n ary_size -= 1\nend\nSTDOUT.flush\n"}, {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\nputs as.map { |a| a.even? ? a - 1 : a }.join(\" \")"}, {"source_code": "x = gets.chomp.to_i\ny = gets.strip.split(' ').map(&:to_i)\n\ny.each do |x|\n if (x%2 == 0)\n print \"#{x-1} \"\n else\n print \"#{x} \"\n end\nend"}, {"source_code": "gets\nputs(gets.split.map{|x| x.to_i}.map{|x| x%2 == 0 ? x - 1 : x}.join(' '))\n"}, {"source_code": "t = gets.to_i\narr = gets.chomp.split(\" \").map(&:to_i)\n\narr.each do |x|\n if x%2==0\n print x-1\n else\n print x\n end\n print ' '\nend"}, {"source_code": "gets;puts gets.split.map{|_|n=_.to_i;n+n%2-1}*' '"}, {"source_code": "n=gets.to_i\na=gets.split\nlen=a.length\ni=0\nwhile i 0 ? \"No\" : \"Yes\"\nend", "positive_code": [{"source_code": "def read_array(to)\n gets.strip.split(' ').map(&to)\nend\n\nn, q = read_array(:to_i)\n\ngrid = [\n Array.new(n, 0),\n Array.new(n, 0),\n]\n\ndef flip(n)\n 1 - n\nend\n\nblocked = 0\n\nq.times do\n r, c = read_array(:to_i).map { |x| x - 1 }\n grid[r][c] = flip(grid[r][c])\n\n if grid[r][c] == 1\n [-1, 0, 1].select { |x| (c + x).between?(0, n -1) && grid[flip(r)][c + x] == 1 }.each do |x|\n blocked += 1\n end\n else\n [-1, 0, 1].select { |x| (c + x).between?(0, n -1) && grid[flip(r)][c + x] == 1 }.each do |x|\n blocked -= 1\n end\n end\n\n puts blocked == 0 ? \"Yes\" : \"No\"\nend"}, {"source_code": "n, q = gets.chomp.split(' ').map(&:to_i) # frozen_string_literal: true\nqueries = []\nq.times do\n x, y = gets.chomp.split(' ').map(&:to_i)\n queries << [x, y]\nend\n\nbad_nei = 0\nis_forbidden = {\n 0 => Array.new(n, false),\n 1 => Array.new(n, false)\n}\nqueries.each do |query|\n row = query[0] - 1\n col = query[1] - 1\n was_forbidden = is_forbidden[row][col]\n\n for r in (row - 1..row + 1)\n for c in (col - 1..col + 1)\n next if r == row\n next unless r >= 0 && r <= 1 && c >= 0 && c < n\n\n if is_forbidden[r][c] == true\n if was_forbidden\n bad_nei -= 1\n else\n bad_nei += 1\n end\n end\n\n end\n end\n\n is_forbidden[row][col] = !is_forbidden[row][col]\n\n if bad_nei >= 1\n puts 'NO'\n else\n puts 'YES'\n end\nend\n"}], "negative_code": [], "src_uid": "af036416721694d1843368988ca78e8e"} {"source_code": "#!/usr/bin/ruby\nn,k=gets.split.map &:to_i\nb=[*'a'..'z'][0,k]\na=[]\na+=b while a.size 0\n if n == k\n myAlphabet.each do |letter|\n password = password + letter\n end\n n -= k\n elsif n < k\n myAlphabet = myAlphabet[0,n]\n myAlphabet.each do |letter|\n password = password + letter\n end\n n -= k\n else\n myAlphabet.each do |letter|\n password = password + letter\n end\n n -= k\n end\nend\n\nputs password\n"}], "negative_code": [], "src_uid": "39f5e934bf293053246bd3faa8061c3b"} {"source_code": "gets\np gets.split.map(&:to_i).each_with_index.sort_by(&:first).each_cons(2).map{|a,b|(b.last-a.last).abs}.inject(:+)||0\n", "positive_code": [{"source_code": "gets\np gets.split.map(&:to_i).each_with_index.sort_by(&:first).each_cons(2).map{|a,b|(b.last-a.last).abs}.inject(:+)||0\n"}, {"source_code": "n = gets.strip.to_i\nar = gets.strip.split.map(&:to_i)\n\ntb = Array.new(n)\n\nn.times do |i|\n\ttb[ar[i]-1] = i+1\nend\n\nif n == 1\n\tputs 0\nelse\n\tputs tb.each_cons(2).map{|a,b| (a-b).abs}.reduce(:+)\nend "}, {"source_code": "gets\np gets.split.map(&:to_i).each_with_index.sort_by(&:first).each_cons(2).map{|a,b|(b.last-a.last).abs}.inject(:+)||0\n"}, {"source_code": "gets\np gets.split.map(&:to_i).each_with_index.sort_by(&:first).each_cons(2).map{|a,b|(b.last-a.last).abs}.inject(:+)||0\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\na = a.each_with_index.to_a.sort_by(&:first).map(&:last)\ndist = 0\n(1...a.size).each do |i|\n dist += (a[i] - a[i - 1]).abs\nend\nputs dist\n"}, {"source_code": "gets\np gets.split.map(&:to_i).each_with_index.sort_by(&:first).each_cons(2).map{|a,b|(b.last-a.last).abs}.inject(:+)||0\n"}, {"source_code": "gets\np gets.split.map(&:to_i).each_with_index.sort_by(&:first).each_cons(2).map{|a,b|(b.last-a.last).abs}.inject(:+)||0\n"}, {"source_code": "gets\np gets.split.map(&:to_i).each_with_index.sort_by(&:first).each_cons(2).map{|a,b|(b.last-a.last).abs}.inject(:+)||0"}, {"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\tf = gets.split.map { |x| x.to_i }\n\t\tpos = Array.new(n + 1, 0)\n\t\tf.each.with_index do |x, i|\n\t\t\tpos[x] = i\n\t\tend\n\t\tans = 0\n\t\t1.upto(n - 1) do |i|\n\t\t\tans += (pos[i] - pos[i + 1]).abs\n\t\tend\n\t\tputs ans\n\tend\nend\nSolver.new.main"}, {"source_code": "gets\np gets.split.map(&:to_i).each_with_index.sort_by(&:first).each_cons(2).map{|a,b|(b.last-a.last).abs}.inject(:+)||0\n"}], "negative_code": [{"source_code": "n = gets.strip.to_i\nar = gets.strip.split.map(&:to_i)\n\ntb = Array.new(n)\n\nn.times do |i|\n\ttb[ar[i]-1] = i+1\nend\n\nputs tb.each_cons(2).map{|a,b| (a-b).abs}.reduce(:+)"}, {"source_code": "n = gets.strip.to_i\nputs n\nar = gets.strip.split.map(&:to_i)\n\ntb = Array.new(ar.size)\n\nar.size.times do |i|\n\ttb[ar[i]-1] = i+1\nend\n\nputs tb.each_cons(2).map{|a,b| a-b}.each.map(&:abs).reduce(:+)"}, {"source_code": "n = gets.strip.to_i\nar = gets.strip.split.map(&:to_i)\n\ntb = Array.new(ar.size)\n\nar.size.times do |i|\n\ttb[ar[i]-1] = i+1\nend\n\nputs tb.each_cons(2).map{|a,b| a-b}.each.map(&:abs).reduce(:+)"}, {"source_code": "n = gets.strip.to_i\nar = gets.strip.split.map(&:to_i)\n\ntb = Array.new(n)\n\nn.times do |i|\n\ttb[ar[i]-1] = i+1\nend\n\na = tb.each_cons(2).map{|a,b| (a-b).abs}.reduce(:+)\na = 1 if a== 0\nputs a"}, {"source_code": "n = gets.strip.to_i\nar = gets.strip.split.map(&:to_i)\n\ntb = Array.new(n)\n\nn.times do |i|\n\ttb[ar[i]-1] = i+1\nend\n\nif n == 1\n\tputs 1\nelse\n\tputs tb.each_cons(2).map{|a,b| (a-b).abs}.reduce(:+)\nend "}, {"source_code": "gets\np gets.split.map(&:to_i).each_with_index.sort_by(&:first).each_cons(2).map{|a,b|(b.last-a.last).abs}.inject(:+)"}], "src_uid": "54e2b6bea0dc6ee68366405945af50c6"} {"source_code": "N = gets.chomp.to_i\nT = gets.split.map &:to_i\nA = gets.split.map &:to_i\n\nadj = Array.new(N) { Array.new }\nradj = Array.new(N) { Array.new }\nN.times { |i| next if A[i] == 0; adj[A[i] - 1] << i; radj[i] << A[i] - 1 }\n\nmax_len, best_st = -1, nil\nN.times { |i| next if T[i] == 0\n que = [[1, i]]\n until que.size == 0\n d, u = que[0]\n que.shift\n if max_len < d\n max_len, best_st = d, u\n end\n radj[u].each { |v| next if T[v] == 1 or adj[v].size > 1\n que << [d + 1, v]\n }\n end\n}\n\nans = [best_st].tap { |a| loop { break if T[a[-1]] == 1; a << adj[a[-1]][0] } }\nputs ans.size\nputs ans.map(&:next).join ' '\n", "positive_code": [{"source_code": "objn = gets.to_i\nobjtypes = gets.split.map(&:to_i)\nobjtypes.unshift(0)\npaths = gets.split.map(&:to_i)\npaths.unshift(0)\nhotels = []\npathscnt = Array::new(objn+1, 0)\npaths.each_with_index{|p, i| \n\tpathscnt[p] += 1\n\thotels << i if objtypes[i] == 1\n}\nbestpath = []\ncurpath = []\nhotels.each{|h|\n\tcurpath << h\n\tprev = paths[h]\n\twhile prev != 0 && pathscnt[prev] == 1 && objtypes[prev] == 0\n\t\tcurpath << prev\n\t\tprev = paths[prev]\n\tend\n\tbestpath.replace(curpath) if bestpath.size < curpath.size\n\tcurpath.replace([])\n}\n\nputs bestpath.size\nputs bestpath.reverse.join(\" \")"}], "negative_code": [], "src_uid": "a704760d5ccd09d08558ea98d6007835"} {"source_code": "s = gets.strip\nx = s.each_byte.inject(0) {|z, b| z + b} % 3\nif x != 0 then\n r, sep = '', [/[147]/, /[258]/]\n s.reverse!\n (x == 1 ? sep : sep.reverse).zip([2, 3]) do |sep, le|\n l = s.split(sep, le)\n if l.length == le then\n t = l.join.reverse.sub(/^(?:0+)(?=.)/, '')\n r = t if r.length < t.length\n end\n end\n s = r.empty? ? '-1' : r\nend\nputs s", "positive_code": [{"source_code": "$num = gets.strip\n$rnum = $num.reverse\n\np3c = [0]*3\nfor digit in $num.each_char do\n p3c[digit.to_i % 3] += 1\nend\n\nnump3 = (p3c[1] + 2*p3c[2]) % 3\n$ans = []\n\ndef add_ans(delp1, delp2)\n cans = []\n for digit in $rnum.each_char do\n #p digit\n p3d = digit.to_i % 3\n if (p3d == 1) and (delp1 > 0) \n delp1 -= 1 \n elsif (p3d == 2) and (delp2 > 0) \n delp2 -= 1\n else \n cans << digit \n end\n end\n \n cans.pop while (cans.length > 1) and (cans[-1] == '0')\n #p cans\n $ans << cans if (cans.length > 0) and (delp1 == 0) and (delp2 == 0)\nend\n\n#p nump3\nif nump3 == 0\n puts $num\n exit\nelsif nump3 == 1\n add_ans(1,0)\n add_ans(0,2)\nelse # if nump3 == 2\n add_ans(2,0)\n add_ans(0,1)\nend\n\nif $ans.empty?\n puts -1\n exit\nend\n\nbest = 0\nfor idx in (1...$ans.length)\n best = idx if $ans[idx].length > $ans[best].length\nend\n\nputs $ans[best].reverse.join ''\n"}], "negative_code": [{"source_code": "s = gets.strip\nx = s.each_byte.inject(0) {|z, b| z + b} % 3\nif x != 0 then\n r, sep = '', [/[147]/, /[258]/]\n s.reverse!\n (x == 1 ? sep : sep.reverse).zip([2, 3]) do |sep, le|\n l = s.split(sep, le)\n if l.length == le then\n t = l.join.reverse.sub(/^(?=0+)./, '')\n r = t if r.length < t.length\n end\n end\n s = r.empty? ? '-1' : r\nend\nputs s\n"}, {"source_code": "$num = gets.strip\n$rnum = $num.reverse\n\np3c = [0]*3\nfor digit in $num.each_char do\n p3c[digit.to_i % 3] += 1\nend\n\nnump3 = (p3c[1] + 2*p3c[2]) % 3\n$ans = []\n\ndef add_ans(delp1, delp2)\n cans = []\n for digit in $rnum.each_char do\n #p digit\n p3d = digit.to_i % 3\n if (p3d == 1) and (delp1 > 0) \n delp1 -= 1 \n elsif (p3d == 2) and (delp2 > 0) \n delp1 -= 2 \n else \n cans << digit \n end\n end\n \n cans.pop while (cans.length > 1) and (cans[-1] == '0')\n #p cans\n $ans << cans if (cans.length > 0) and (delp1 == 0) and (delp2 == 0)\nend\n\nif nump3 == 0\n puts $num\n exit\nelsif nump3 == 1\n add_ans(1,0)\n add_ans(0,2)\nelse # if nump3 == 2\n add_ans(2,0)\n add_ans(0,1)\nend\n\nif $ans.empty?\n puts -1\n exit\nend\n\nbest = 0\nfor idx in (1...$ans.length)\n best = idx if $ans[idx].length > $ans[best].length\nend\n\nputs $ans[best].reverse.join ''\n"}], "src_uid": "df9942d1eb66b1f3b5c6b665b446cd3e"} {"source_code": "gets.to_i.times do\n\tn, p = gets.split(' ').map{|x|x.to_i}\n\tputs Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n\tn, p = gets.split(' ').map{|x|x.to_i}\n\tputs Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\nend"}, {"source_code": "gets.to_i.times do\n n,p=gets.split(' ').map{|x|x.to_i}\n puts Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\n\nend"}, {"source_code": "gets.to_i.times do\n\tn, p = gets.split(' ').map{|x|x.to_i}\n\tputs Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\nend\n"}, {"source_code": "gets.to_i.times do\n\tn, p = gets.split(' ').map{|x|x.to_i}\n\tputs Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\nend\n"}, {"source_code": "gets.to_i.times do\n\tn, p = gets.split(' ').map{|x|x.to_i}\n\tputs Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\nend\n"}, {"source_code": "gets.to_i.times do\n\tn, p = gets.split(' ').map{|x|x.to_i}\n\tputs Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\nend\n"}, {"source_code": "gets.to_i.times do\n\tn, p = gets.split(' ').map{|x|x.to_i}\n\tputs Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\nend\n"}, {"source_code": "gets.to_i.times do\n\tn, p = gets.split(' ').map{|x|x.to_i}\n\tputs Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\nend\n"}, {"source_code": "gets.to_i.times do\n\tn, p = gets.split(' ').map{|x|x.to_i}\n\tputs Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\nend"}, {"source_code": "gets.to_i.times do\n\tn, p = gets.split(' ').map{|x|x.to_i}\n\tputs Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\nend\n"}, {"source_code": "gets.to_i.times do\n\tn, p = gets.split(' ').map{|x|x.to_i}\n\tputs Array(1..n).combination(2).to_a[0..n*2+p-1].map{|a|a.join' '}\nend"}], "negative_code": [], "src_uid": "ddbac4053bd07eada84bc44275367ae2"} {"source_code": "k,x,n,m=gets.split.map(&:to_i)\nn1= [1,0]\nn2= [0,1]\nn12=[0,0,1]\nn22=[0,0,0,0,1]\nn21=[0,0,0,1,1]\nk.times do |i|\n n1<=n12\n 2.times do |i22|\n f22=i22==1&&m>1&&x>=n22\n 2.times do |i21|\n f21=i21==1&&x>=n21&&(m>1&&n>1||!f12)\n nn=n\n mm=m\n nn-=1 if f12||f21\n if f22\n mm-=2\n elsif f21||f12\n mm-=1\n end\n (nn/2+1).times do |i|\n (mm/2+1).times do |j|\n if i*n1+j*n2+(f12 ? n12:0)+(f22 ? n22:0)+(f21 ? n21:0)==x\n s1='B'*n\n s2='B'*m\n (s1[-1]='A';s2[0]='C') if f12\n (s2[-1]='A';s2[0]='C') if f22\n (s2[-1]='A';s1[0]='C') if f21\n s1.sub!('B'*(i*2),'AC'*i)\n s2.sub!('B'*(j*2),'AC'*j)\n puts s1,s2\n exit\n end\n end\n end\n end\n end\nend\nputs 'Happy new year!'", "positive_code": [{"source_code": "k,x,n,m=gets.split.map(&:to_i)\n#k,x,n,m=10,143,4,6\nn1= [1,0,1,1,2]\nn2= [0,1,1,2,3]\nn12=[0,0,1,1,2]\nn22=[0,0,0,0,1]\nn21=[0,0,0,1,1]\nk.times do |i|\n n1<=n12)\n 2.times do |i22|\n x-=n22 if (f22=i22==1&&m>1&&x>=n22)\n 2.times do |i21|\n x-=n21 if (f21=i21==1&&x>=n21&&(m>1&&n>1||!f12))\n nn=n\n mm=m\n nn-=1 if f12||f21\n if f22\n mm-=2\n elsif f21||f12\n mm-=1\n end\n\n (nn/2+1).times do |i|\n (mm/2+1).times do |j|\n if i*n1+j*n2==x\n s1='B'*n\n s2='B'*m\n (s1[-1]='A';s2[0]='C') if f12\n (s2[-1]='A';s2[0]='C') if f22\n (s2[-1]='A';s1[0]='C') if f21\n s1.sub!('B'*(i*2),'AC'*i)\n s2.sub!('B'*(j*2),'AC'*j)\n puts s1,s2\n exit\n end\n end\n end\n\n x+=n21 if f21\n end\n x+=n22 if f22\n end\n x+=n12 if f12\nend\nputs 'Happy new year!'"}], "negative_code": [{"source_code": "#k,x,n,m=gets.split.map(&:to_i)\nk,x,n,m=5,4,3,2\nn1= [1,0,1,1,2]\nn2= [0,1,1,2,3]\nn12=[0,0,1,1,2]\nn22=[0,0,0,0,1]\nn21=[0,0,0,1,1]\nk.times do |i|\n n1<=n12)\n 2.times do |i22|\n x-=n22 if (f22=i22==1&&m>1&&x>=n22)\n 2.times do |i21|\n x-=n21 if (f21=i21==1&&x>=n21&&(!f12))\n nn=n\n mm=m\n nn-=1 if f12||f21\n if f22\n mm-=2\n elsif f21||f12\n mm-=1\n end\n\n (nn/2+1).times do |i|\n (mm/2+1).times do |j|\n if i*n1+j*n2==x\n s1='B'*n\n s2='B'*m\n (s1[-1]='A';s2[0]='C') if f12\n (s2[-1]='A';s2[0]='C') if f22\n (s2[-1]='A';s1[0]='C') if f21\n s1.sub!('B'*(i*2),'AC'*i) if i>0\n s2.sub!('B'*(j*2),'AC'*j) if j>0\n puts s1,s2\n exit\n end\n end\n end\n\n x+=n21 if f21\n end\n x+=n22 if f22\n end\n x+=n12 if f12\nend\nputs 'Happy new year!'"}, {"source_code": "k,x,n,m=gets.split.map(&:to_i)\nn1= [1,0,1,1,2]\nn2= [0,1,1,2,3]\nn12=[0,0,1,1,2]\nn22=[0,0,0,0,1]\nn21=[0,0,0,1,1]\nk.times do |i|\n n1<=n12)\n 2.times do |i22|\n x-=n22 if (f22=i22==1&&m>1&&x>=n22)\n 2.times do |i21|\n x-=n21 if (f21=i21==1&&x>=n21&&(!f12))\n mm=m\n mm-=1 if f12||f21\n nn=n\n if f22\n nn-=2\n elsif f21||f12\n nn-=1\n end\n\n (nn/2+1).times do |i|\n (mm/2+1).times do |j|\n if i*n1+j*n2==x\n s1='B'*n\n s2='B'*m\n (s1[-1]='A';s2[0]='C') if f12\n (s2[-1]='A';s2[0]='C') if f22\n (s2[-1]='A';s1[0]='C') if f21\n s1.sub!('B'*(i*2),'AC'*i) if i>0\n s2.sub!('B'*(j*2),'AC'*j) if j>0\n puts s1,s2\n exit\n end\n end\n end\n\n x+=n21 if f21\n end\n x+=n22 if f22\n end\n x+=n12 if f12\nend\nputs 'Happy new year!'"}, {"source_code": "k,x,n,m=gets.split.map(&:to_i)\n#k,x,n,m=5,4,3,2\nn1= [1,0,1,1,2]\nn2= [0,1,1,2,3]\nn12=[0,0,1,1,2]\nn22=[0,0,0,0,1]\nn21=[0,0,0,1,1]\nk.times do |i|\n n1<=n12)\n 2.times do |i22|\n x-=n22 if (f22=i22==1&&m>1&&x>=n22)\n 2.times do |i21|\n x-=n21 if (f21=i21==1&&x>=n21&&(!f12))\n nn=n\n mm=m\n nn-=1 if f12||f21\n if f22\n mm-=2\n elsif f21||f12\n mm-=1\n end\n\n (nn/2+1).times do |i|\n (mm/2+1).times do |j|\n if i*n1+j*n2==x\n s1='B'*n\n s2='B'*m\n (s1[-1]='A';s2[0]='C') if f12\n (s2[-1]='A';s2[0]='C') if f22\n (s2[-1]='A';s1[0]='C') if f21\n s1.sub!('B'*(i*2),'AC'*i) if i>0\n s2.sub!('B'*(j*2),'AC'*j) if j>0\n puts s1,s2\n exit\n end\n end\n end\n\n x+=n21 if f21\n end\n x+=n22 if f22\n end\n x+=n12 if f12\nend\nputs 'Happy new year!'"}], "src_uid": "1d55d31320368ddb1439ee086d40b57c"} {"source_code": "# https://codeforces.com/problemset/problem/1335/B\nC = \"a\".ord\n\ndef solution(n, a, b)\n s = \"\"\n c = C\n i = 0\n j = 0\n n.times do\n s += c.chr\n\n c += 1\n i += 1\n j += 1\n\n if i == b\n c = C\n i = 0\n end\n if j == a\n c = C\n i = 0\n j = 0\n end\n end\n return s\nend\n\nt = gets.chomp.to_i\n\nwhile t > 0 do\n n, a, b = gets.chomp\n .split(\" \")\n .map(&:to_i)\n puts solution(n, a, b)\n t -= 1\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n\tn, a, b = gets.split.map(&:to_i)\n\tstr = ('a'...('a'.ord + b).chr).to_a.join + 'a' * (a - b)\n\tputs (str * ((n + a - 1) / a))[0, n]\nend\n"}, {"source_code": "LETTERS = 'abcdefghijklmnopqrstuvwxyz'\n\ngets.to_i.times {\n n, a, b = gets.split.map { |v| v.to_i }\n s = LETTERS[0...b] * (a / b) + LETTERS[0...(a % b)]\n puts s * (n / a) + s[0...(n % a)]\n}\n\n"}, {"source_code": "t = gets.chomp.to_i\n\n(1..t).each{\n n, a, b = gets.chomp.split.map{|x| x.to_i}\n \n (0...n).each{|i|\n print (i % b + 97).chr\n }\n puts\n}"}, {"source_code": "t = gets.to_i\n\n1.upto(t) do\n n, a, b = gets.split(' ').map(&:to_i)\n\n puts (('a'..'z').to_a[0, b].join * (n.div(b) + 1))[0, n]\nend\n"}, {"source_code": "t = gets.to_i\n(1).upto(t) do\n a=gets.split(' ').map(&:to_i)\n str=[]\n (97).upto(97+a[2]-1) do |i|\n str.push(i.chr)\n end\n while(str.length < a[1]) do\n str.push((97+a[2]-1).chr)\n end\n (0..a[0]-1).each do |i|\n print(str[i.modulo(a[1])])\n end\n puts\nend\n"}], "negative_code": [], "src_uid": "a82f15c1b0ddcacc1de966be20cfc5a2"} {"source_code": "n = gets.split.map(&:to_i)[0]\nc = gets.split.map(&:to_i)\ngao = Hash.new(false)\nans = 0\nfor i in 0..n-1 do\n c[i] += 1 and ans += 1 until !gao[c[i]]\n gao[c[i]] = true\nend\nprint ans", "positive_code": [{"source_code": "n = ARGF.readline.to_i\nline = ARGF.readline.split(\" \")\nnumbers = []\nline.each do |n|\nnumbers.push(n.to_i)\nend\n\nnumbers = numbers.sort\ncounter = 0\n\nfor i in 1..(numbers.length - 1)\n if numbers[i] <= numbers[i - 1]\n \ttemp = (numbers[i] - numbers[i - 1]).abs + 1\n \tnumbers[i] = numbers[i] + temp\n \tcounter = counter + temp\n end\nend\n\nputs counter"}, {"source_code": "total_badges = gets.to_i\nbadges = gets.split(' ')\ncoolness = []\n(total_badges*2+1).times do |x|\n coolness[x] = 0\nend\nbadges.inject(0) do |sum, badge|\n coolness[badge.to_i]+=1\nend\ntotal = 0\ncoolness.each_with_index do |cool, index|\n badge_count_increased = cool-1\n if badge_count_increased > 0\n coolness[index+1]+=badge_count_increased \n total+=badge_count_increased\n end\nend\nputs total"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\na.sort!\nans = 0\nlast = 0\na.each do |x|\n while x <= last\n ans += 1\n x += 1\n end\n last = x\nend\nputs ans"}, {"source_code": "n = gets.chomp.to_i\nfactors = gets.chomp.split.map(&:to_i).sort\nsum = factors.inject(0, :+)\n\n(1...n).each do |idx|\n factors[idx] = factors[idx - 1] + 1 if factors[idx] <= factors[idx - 1]\nend\n\nputs factors.inject(0, :+) - sum\n"}, {"source_code": "badgeNum = gets.chomp.to_i\nbadges = gets.chomp.split(' ').map {|item| item.to_i }\n\nbadges.sort!\n\nunique = badges.select { |e| badges.count(e) == 1 }\nduplicate = badges.select { |e| badges.count(e) > 1}\n\npayNum = 0\nsumNumber = 0\n\n\nfor i in 0...badges.length - 1\n\t#puts \"Debug : #{badges[i]}\"\n\t#puts \"i : #{i}\"\n\tpayNum += (badges[i + 1] - badges[i]).abs + 1 if badges[i] >= badges[i + 1]\n\tbadges[i + 1] += (badges[i + 1] - badges[i]).abs + 1 if badges[i] >= badges[i + 1]\nend\n\n=begin\nuntil duplicate.length == 0\n\n\n\tprint \"Debug : \"\n\tduplicate.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\tputs ''\n\n\tprint \"Debug_2 : \"\n\tunique.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\tputs ''\n\n\n\tif duplicate.count(duplicate[0]) % 2 == 1 && !unique.include?(duplicate[0])\n\t\tunique << duplicate[0]\n\t\tduplicate.delete_at(0)\n\t\tnext\n\tend\n\n\tsumNumber = duplicate\n\n\tloop do\n\t#\tputs \"sumNumber : #{sumNumber}\"\n\t\tbreak if !unique.include?(duplicate[0] + sumNumber)\n\t\tsumNumber += 1\n\tend\n\n\tunique << duplicate[0] + sumNumber\n\tduplicate.delete_at(0)\n\tpayNum += sumNumber\n\tsumNumber = 0\nend\n=end\n\nputs payNum"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").map{|i| i.to_i}\nb.sort!\nr=b[0]\nans=0\n1.upto(a-1) do |i|\nif b[i]<=r+1\nans+=r+1-b[i]\nr+=1\nelse\nr=b[i]\nend\nend\nputs \"#{ans}\""}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").map{|i| i.to_i}\nb.sort!\nr=b[0]\nans=0\n1.upto(a-1) do |i|\nif b[i]<=r+1\nans+=r+1-b[i]\nr+=1\nelse\nr=b[i]\nend\nend\nputs \"#{ans}\""}, {"source_code": "n=gets.to_i\na=gets.split.map{|e| e.to_i}.sort\nans=0\n1.upto(n-1){|i|\n\tif a[i-1]>=a[i] then\n\t\tans+=a[i-1]-a[i]+1\n\t\ta[i]=a[i-1]+1\n\tend\n}\nputs ans\n\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}.sort\n\nans=0\na1=x[0]\nx.shift\nx.each{|e|\n\tif a1>=e then\n\t\tans+=(a1-e+1)\n\t\ta1+=1\n\telse\n\t\ta1=e\n\tend\n}\nputs ans\n\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\na = gets.split.map(&:to_i).sort\ncoins = 0\nfor i in 1...n\n if a[i-1] >= a[i]\n addition = a[i-1] - a[i] + 1\n a[i] += addition\n coins += addition\n end\nend\n\nputs coins"}, {"source_code": "n=gets.to_i\nv=gets.split.map(&:to_i)\nans=0\nv=v.sort\nfor i in 0...v.length do\n for j in 0...v.length do\n if i!=j\n if v[i]==v[j]\n ans+=1\n v[j]+=1\n end\n end\n\n end\nend\nputs ans\n"}, {"source_code": "n=gets.to_i\nv=gets.split.map(&:to_i)\nans=0\nv=v.sort\nfor i in 1...v.length do\n if v[i]<=v[i-1]\n ans+=v[i-1]-v[i]+1\n v[i]=v[i-1]+1\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}.sort\nans = 0\ncur = a[0]\n(1...n).each do |i|\n if a[i] <= cur\n ans += cur-a[i]+1\n cur += 1\n else\n cur = a[i]\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\ns = gets.split.map(&:to_i).sort\nans = 0\n1.upto(n - 1) do |i|\n if s[i] <= s[i - 1]\n ans += s[i - 1] - s[i] + 1\n s[i] = s[i - 1] + 1\n end\nend\nputs ans\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = ARGF.gets.to_i # number of badges\ncoolness = ARGF.gets.split(' ').map { |s| s.to_i}\ncoolness.sort!\n\ncoins = 0\n\nfor i in 0...n-1 do\n if coolness[i] >= coolness[i+1]\n cost = 1 + (coolness[i] - coolness[i+1])\n coolness[i+1] += cost \n coins += cost\n end\nend\n\np coins\n\n\n\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nfactors = gets.chomp.split.map(&:to_i).sort\nmin = factors.first\n\nmin_cost = factors.map.with_index do |v, i|\n (v - (min + i)).abs\nend.inject(0, :+)\n\nputs min_cost\n"}, {"source_code": "n = gets.chomp.to_i\nfactors = gets.chomp.split.map(&:to_i).sort\n\nmin_cost = factors.map.with_index { |v, i| (v - (i + 1)).abs }.inject(0, :+)\nputs min_cost\n"}, {"source_code": "badgeNum = gets.chomp.to_i\nbadges = gets.chomp.split(' ').map {|item| item.to_i }\n\nbadges.sort!\n\nunique = badges.select { |e| badges.count(e) == 1 }\nduplicate = badges.select { |e| badges.count(e) > 1}\n\npayNum = 0\nsumNumber = 0\n\n\nfor i in 0...badges.length - 1\n\tputs \"Debug : #{badges[i]}\"\n\tputs \"i : #{i}\"\n\tpayNum += (badges[i + 1] - badges[i]).abs + 1 if badges[i] >= badges[i + 1]\n\tbadges[i + 1] += (badges[i + 1] - badges[i]).abs + 1 if badges[i] >= badges[i + 1]\nend\n\n=begin\nuntil duplicate.length == 0\n\n\n\tprint \"Debug : \"\n\tduplicate.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\tputs ''\n\n\tprint \"Debug_2 : \"\n\tunique.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\tputs ''\n\n\n\tif duplicate.count(duplicate[0]) % 2 == 1 && !unique.include?(duplicate[0])\n\t\tunique << duplicate[0]\n\t\tduplicate.delete_at(0)\n\t\tnext\n\tend\n\n\tsumNumber = duplicate\n\n\tloop do\n\t#\tputs \"sumNumber : #{sumNumber}\"\n\t\tbreak if !unique.include?(duplicate[0] + sumNumber)\n\t\tsumNumber += 1\n\tend\n\n\tunique << duplicate[0] + sumNumber\n\tduplicate.delete_at(0)\n\tpayNum += sumNumber\n\tsumNumber = 0\nend\n=end\n\nputs payNum"}, {"source_code": "badgeNum = gets.chomp.to_i\nbadges = gets.chomp.split(' ').map {|item| item.to_i }\n\nunique = badges.select { |e| badges.count(e) == 1 }\nduplicate = badges.select { |e| badges.count(e) > 1}\ntemp = badges.select { |e| badges.count(e) > 1}\n\nindex = 0\npayNum = 0\n\nuntil duplicate.length == 0\n\n=begin\n\tprint \"Debug : \"\n\tduplicate.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\tputs ''\n\n\tprint \"Debug_2 : \"\n\ttemp.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\tputs ''\n=end\n\n\tsumNumber = 0\n\n\tloop do\n\t#\tputs \"sumNumber : #{sumNumber}\"\n\t\tbreak if !temp.include?(duplicate[0] + sumNumber) && !unique.include?(duplicate[0] + sumNumber)\n\t\tsumNumber += 1\n\tend\n\n\ttemp.delete(duplicate[0])\n\ttemp.delete(duplicate[0])\n\n\ttemp << duplicate[0] + sumNumber\n\ttemp << duplicate[0] + sumNumber\n\n\tduplicate.delete_at(0)\n\tpayNum += sumNumber\n\tsumNumber = 0\n\n\tindex += 1\nend\n\nputs payNum"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").map{|i| i.to_i}\nb.sort!\ntr=0\nans=0\n0.upto(a-1) do |i|\nif b[i]+tr<=i+1\nans+=i+1-b[i]-tr\nelse\nans+=(a-i-1)*(b[i]+tr-i-1)\ntr+=1**(b[i]+tr-i-1)\nend\nend\nputs \"#{ans}\""}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").map{|i| i.to_i}\nk=(a*(a+1))/2\nsum=0\nb.each {|i| sum+=i }\nputs \"#{k-sum}\"\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\na = gets.split.map(&:to_i).sort\ncoins = 0\nfor i in 1...n\n if a[i-1] == a[i]\n a[i] += 1\n coins += 1\n end\nend\n\nputs coins"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\na = gets.split.map(&:to_i).sort\ncoins = 0\nfor i in 1...(n-1)\n if a[i-1] == a[i]\n a[i] += 1\n coins += 1\n end\nend\n\nputs coins"}, {"source_code": "n = gets.split.map(&:to_i)[0]\nc = gets.split.map(&:to_i)\ngao = Hash.new(false)\nans = 0\nfor i in 0..n-1 do\n c[i] += 1 and ans += 1 until !gao[c[i]]\n gao[c[i]] = true\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nans = 0\nn.times do |i|\n if a[i] == a[i + 1]\n a[i] += 1\n ans += 1\n a.sort!\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\ns = [nil] + gets.split.map(&:to_i).sort\nans = 0\nn.downto(1) do |i|\n if s[i] != i\n ans += i - s[i]\n s[i] = i\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\ns = [nil] + gets.split.map(&:to_i).sort\nans = 0\nm = [n + s[1..-1].min - 1, s[1..-1].max].max\nmi = m - n + 1\nm.downto(mi) do |i|\n j = i - mi + 1\n if s[j] != i\n ans += i - s[j]\n s[j] = i\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\ns = [nil] + gets.split.map(&:to_i).sort\nans = 0\nmi = s[1..-1].min\nm = n + mi - 1\nm.downto(mi) do |i|\n j = i - mi + 1\n if s[j] != i\n ans += i - s[j]\n s[j] = i\n end\nend\nputs ans\n"}], "src_uid": "53ae714f04fd29721b8bbf77576b7ccf"} {"source_code": "a,b,c,d=readline.split(' ').map(&:to_i)\nr=1.0*a*d/(a*d+b*c-a*c)\nputs r\n", "positive_code": [{"source_code": "a, b, c, d = gets.split.map(&:to_f)\na /= b\nc /= d\nx = (1 - a) * (1 - c)\ny = (1 - a) * c\np 1 - y / (1 - x)\n"}, {"source_code": "a, b, c, d = gets.chomp.split\na = a.to_f\nb = b.to_f\nc = c.to_f\nd = d.to_f\nprobe1 = 0\nprobe2 = a/b\nn = 2\nwhile (probe2 - probe1 > 0.000000001)\n probe1 = probe2\n probe2 += ((1-a/b)**(n - 1))*((1 - c/d)**(n-1))*(a/b)\n n += 1\nend\nputs probe2"}, {"source_code": "def myfun\nn = gets.chomp\nar = n.split(' ')\na = ar[0].to_i\nb = ar[1].to_i\nc = ar[2].to_i\nd = ar[3].to_i\n\nr = a*d*1.0000000\nr = r/((b*c)+(a*d)-(a*c))\nputs r\nreturn nil\nend\n\nputs myfun\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\na, b, c, d = STDIN.readline.split.collect {|s| s.to_i }\n\nr = 1.0*a/b\n\nk = 1.0*(b-a)*(d-c)/(b*d)\n\nx = r/(1-k)\n\nputs x\n\n"}, {"source_code": "a, b, c, d = gets.split.map(&:to_i)\npa = 1.0 * a / b\npb = 1.0 * c / d\n\nputs(1.0 / (1.0 - (1.0 - pa) * (1.0 - pb)) * pa)\n"}, {"source_code": "a,b,c,d=gets.chomp.split.map(&:to_f)\nputs (a/b)/(1-((1-c/d)*(1-a/b)))"}, {"source_code": "input = STDIN.read\n\ninput =~ /^(\\d+) (\\d+) (\\d+) (\\d+)/\na, b, c, d = $1.to_f, $2.to_f, $3.to_f, $4.to_f\n \np1 = a / b\n\ns = p1 / (1 - (1 - p1) * (1 - (c / d)))\n\nputs s\n\n"}, {"source_code": "str = gets.chomp\na, b, c, d = str.split.map { |i| i.to_f }\nputs (a * d) / (b * c + a * d - a * c)\n"}, {"source_code": "a,b,c,d = gets.split(\" \").map(&:to_i)\np = a/b.to_f\nz = c/d.to_f\nq = (1-p)*(1-z)\n\nputs (p/(1-q))"}, {"source_code": "a,b,c,d = gets.chomp.split(\" \").collect {|x| x.to_i}\n\np1 = a*1.0/b\np2 = c*1.0/d\n\np = (1-p1)*(1-p2)\n\nres = p1 * 1.0/(1-p)\n\nputs res"}, {"source_code": "a, b, c, d = gets.split().map(&:to_i)\ns = a*1.0/b\nz = c*1.0/d\nputs s/(1-(1-s)*(1-z))\n"}, {"source_code": "require 'bigdecimal'\n\na,b,c,d = gets.strip.split(' ').map {|x| x.to_i}\n\np1 = 1 - BigDecimal.new(a)/BigDecimal.new(b)\np2 = 1 - BigDecimal.new(c)/BigDecimal.new(d)\n\nr = (1 - p1)/(1 - p1*p2)\nputs r.to_s(\"F\")"}, {"source_code": "a, b, c, d = gets.split.map(&:to_i)\nputs 1.0 * a * d / (b * d - (b - a) * (d - c))\n"}, {"source_code": "#!/usr/bin/ruby\n\na, b, c, d = gets.chomp.split(\" \").map(&:to_f)\n\np = a / b\nq = c / d\n\nputs p / (1 - (1 - p) * (1 - q))\n"}], "negative_code": [{"source_code": "a, b, c, d = gets.chomp.split\na = a.to_f\nb = b.to_f\nc = c.to_f\nd = d.to_f\nprobe1 = 0\nprobe2 = a/b\nn = 2\nwhile (probe2 - probe1 > 0.0000001)\n probe1 = probe2\n probe2 += ((1-a/b)**(n - 1))*((1 - c/d)**(n-1))*(a/b)\n n += 1\nend\nputs probe2"}, {"source_code": "a, b, c, d = ARGV[0].to_f, ARGV[1].to_f, ARGV[2].to_f, ARGV[3].to_f\nprobe1 = 0\nprobe2 = a/b\nn = 2\nwhile (probe2 - probe1 > 0.0000001)\n probe1 = probe2\n probe2 += ((1-a/b)**(n - 1))*((1 - c/d)**(n-1))*(a/b)\n n += 1\nend\nputs probe2"}, {"source_code": "#!/usr/bin/ruby\n\na, b, c, d = gets.chomp.split(\" \").map(&:to_f)\n#puts a, b, c, d\nputs (2.0 * (a / b)) / (3.0 * (c / d))\n"}], "src_uid": "7b932b2d3ab65a353b18d81cf533a54e"} {"source_code": "s = gets.chomp.split(//)\nstk = []\nfor i in s\n if stk.last == i\n stk.pop\n else\n stk.push(i)\n end\nend\nputs stk.length > 0 ? :No : :Yes\n", "positive_code": [{"source_code": "class D\n def initialize\n sequence = gets.chomp\n\n right = 0\n left = 0\n last = ''\n\n if sequence.size.odd? \n puts \"No\"\n exit\n end\n\n sequence.split('').each_slice(2).map(&:join).each do |elem|\n case elem\n when '++'\n last = '+'\n when '--'\n last = '-'\n when '+-'\n right += 1\n last = '-'\n when '-+'\n left += 1\n last = '+'\n when '-'\n if last == '+'\n left += 1\n end\n when '+'\n if last == '-'\n right += 1\n end\n end\n end\n\n if right == left\n puts \"Yes\"\n else\n puts \"No\"\n end\n end\nend\n\nd = D.new"}, {"source_code": "s=gets.chomp.strip.split('').map(&:to_s)\na=Array.new(100005,0)\np=0\nfor i in s\n\tif i!=a[p]\n\t\tp+=1\n\t\ta[p]=i\n\telse\n\t\tp-=1\n\tend\nend\nif p==0\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "class D\n def initialize\n sequence = gets.chomp\n\n right = 0\n left = 0\n last = ''\n\n if sequence.size.odd? \n puts \"No\"\n exit\n end\n\n sequence.split('').each_slice(2).map(&:join).each do |elem|\n case elem\n when '++'\n when '--'\n when '+-'\n right += 1\n when '-+'\n left += 1\n end\n end\n\n if right == left\n puts \"Yes\"\n else\n puts \"No\"\n end\n end\nend\n\nd = D.new"}], "negative_code": [{"source_code": "class D\n def initialize\n sequence = gets.chomp\n\n right = 0\n left = 0\n last = ''\n\n if sequence.size == 1\n puts \"No\"\n exit\n end\n\n sequence.split('').each_slice(2).map(&:join).each do |elem|\n case elem\n when '++'\n last = '+'\n when '--'\n last = '-'\n when '+-'\n right += 1\n last = '-'\n when '-+'\n left += 1\n last = '+'\n when '-'\n if last == '+'\n left += 1\n end\n when '+'\n if last == '-'\n right += 1\n end\n end\n end\n\n if right == left\n puts \"Yes\"\n else\n puts \"No\"\n end\n end\nend\n\nd = D.new"}, {"source_code": "class D\n def initialize\n sequence = gets.chomp\n\n right = 0\n left = 0\n last = ''\n\n if sequence.size == 1\n puts \"No\"\n exit\n end\n\n sequence.split('').each_cons(2).map(&:join).each do |elem|\n case elem\n when '++'\n when '--'\n when '+-'\n right += 1\n when '-+'\n left += 1\n end\n end\n\n if right == left\n puts \"Yes\"\n else\n puts \"No\"\n end\n end\nend\n\nd = D.new"}], "src_uid": "89b4a7b4a6160ce784c588409b6ce935"} {"source_code": "gets;$<.map{a=gets.split;puts a.index(a.min_by{|it|a.count it})+1}", "positive_code": [{"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each_slice(2) do |inp|\r\n inp.shift\r\n nums = inp[0].split(' ').map(&:to_i)\r\n\r\n nums.uniq.each do |n|\r\n next if nums.count{|i| i == n} != 1\r\n\r\n puts nums.index(n) + 1\r\n\r\n break\r\n end\r\nend"}, {"source_code": "for i in 0...gets.chomp.to_i\r\n n = gets.chomp.to_i\r\n arr = gets.chomp.split(\" \").map{|item| item.to_i}\r\n temp = arr.uniq\r\n for i in temp\r\n if arr.count(i) == 1\r\n puts arr.index(i) + 1\r\n end\r\n end\r\nend"}, {"source_code": "t = gets.chomp\r\nfor i in 0...t.to_i\r\n n = gets.chomp\r\n a = gets.chomp.split(\" \")\r\n if a[0] == a[1]\r\n for j in 2...n.to_i\r\n if a[j] != a[0]\r\n puts j + 1\r\n break\r\n end\r\n end\r\n else\r\n if a[0] == a[2] then puts 2\r\n else puts 1\r\n end\r\n end\r\nend"}, {"source_code": "t = gets.to_s.to_i\n\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }\n b = a.sort\n v1 = b[0]\n v2 = b[-1]\n if b[1] != v1\n printf(\"%d\\n\", a.index(v1) + 1)\n else\n printf(\"%d\\n\", a.index(v2) + 1)\n end\nend\n\n"}, {"source_code": "gets;$<.map{a=gets.split;puts a.index(a.min_by{|it|a.count it})+1}"}, {"source_code": "gets;$<.map{a=gets.split;puts a.index(a.min_by{|it|a.count it})+1}"}, {"source_code": "t = gets.strip.to_i\r\nt.times do\r\n\tn = gets.strip.to_i\r\n\ta = gets.strip.split.map(&:to_i)\r\n\tcount = {}\r\n\tn.times do |i|\r\n\t\tcurrent = a[i]\r\n\t\tif !count.has_key? current\r\n\t\t\tcount[current] = [1, i]\r\n\t\telse\r\n\t\t\tcount[current][0] += 1\r\n\t\tend\r\n\t\tcount[current][1] = i\r\n\tend\r\n\tans = 0\r\n\tcount.each do |k, v|\r\n\t\tif v[0] == 1\r\n\t\t\tans = v[1] + 1\r\n\t\t\tbreak\r\n\t\tend\r\n\tend\r\n\tputs ans\r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n\tn = gets.to_i\r\n\ta = gets.split\r\n\r\n\tidx = 0\r\n\r\n\tif a[0] != a[1]\r\n\t\tif a[0] == a[2]\r\n\t\t\tidx = 2\r\n\t\telse\r\n\t\t\tidx = 1\r\n\t\tend\r\n\telse\r\n\t\tfor i in 1...n\r\n\t\t\tif a[i] != a[0]\r\n\t\t\t\tidx = i + 1\r\n\t\t\t\tbreak\r\n\t\t\tend\r\n\t\tend\r\n\tend\r\n\r\n\tputs idx\r\nend\r\n"}, {"source_code": "t = gets.to_i\ninputs = []\n\n(0..t-1).each do |i|\n len = gets.to_i\n arr = gets.chomp\n arr = arr.split(\" \").map(&:to_i)\n inputs.push([arr, len])\nend\n\ninputs.each do |input|\n arr = input[0]\n n = input[1]\n map = {}\n index = -1\n (0..n-1).each do |i|\n if map.key?(arr[i])\n map[arr[i]] = [true, i]\n else\n map[arr[i]] = [false, i]\n end\n end\n map.each do |k, v|\n if v[0] == false\n puts v[1]+1\n end\n end\nend\n\n"}, {"source_code": "gets;$<.map{a=gets.split;puts a.index(a.min_by{|it|a.count it})+1}"}, {"source_code": "gets;$<.map{a=gets.split;puts a.index(a.min_by{|it|a.count it})+1}"}], "negative_code": [{"source_code": "gets;$<.map{|s|gets;a=s.split;puts a.index(a.min_by{|it|a.count it})+1}"}, {"source_code": "gets;$<.map{|s|gets;a=s.split;puts a.index(a.min_by {a.count})+1}"}], "src_uid": "224a0b09547ec1441474efbd8e06353b"} {"source_code": "# coding: utf-8\n\n# \ucd1d \ud14c\uc2a4\ud2b8 \ucf00\uc774\uc2a4 t \uc5d0 \ub300\ud574, \uaf43\uc744 a\uac1c\ubd80\ud130 b\uac1c \uc0ac\uc774\ub85c \uba39\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c \uacc4\uc0b0\ud55c\ub2e4\n# \ub2e8 \ud770 \uaf43\uc740 k\uac1c \ub2e8\uc704\ub85c\ub9cc \uba39\uc744 \uc218 \uc788\ub2e4.\n# \uc608) k = 2\uc77c\ub54c, \uaf43 4\uac1c\ub97c \uba39\uc744 \ub54c\ub294 \ud770\uc0c9\ub9cc 4\uac1c\ub97c \uba39\uc744 \uc218 \uc788\uc9c0\ub9cc,\n# k = 3\uc77c\ub54c\ub294 3\uac1c\ub97c \uba39\uc744 \uc218 \uc5c6\ub2e4.\n# \uc774\ub54c \ube68\uac04 \uaf43 R\uacfc \ud770\uaf43 W\ub97c \uc11e\uc5b4\uc11c \uba39\uc744 \uc218 \uc788\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c modulo 10**9 + 7 \ub85c \uacc4\uc0b0\nMODULO_BASE = 10**9 + 7\nMAX_HEIGHT = 10**5\n# \ud639\uc2dc k-Tree \ubb38\uc81c \uc0dd\uac01\ub098\uc2ed\ub2c8\uae4c? \uc74c \ub3c4\uc6c0\uc774 \ub420\uc9c0 \ubaa8\ub974\uaca0\ub294\ub370\n# \uac01 \uc790\ub9ac\uc5d0 \uc62c \uc218 \uc788\ub294\uac74 R \ub610\ub294 W\uc785\ub2c8\ub2e4. \uc774\uac83\uc740 \uc774\uc9c4\ud2b8\ub9ac\uc785\ub2c8\ub2e4.\n# \uc774\uc9c4\ud2b8\ub9ac\uc758 \uc21c\ud68c\ub294 DFS\uc640 BFS\uc911 \ud558\ub098\ub85c \ud480 \uc218 \uc788\uaca0\uc8e0.\n# growing\uc744 \uc5b4\ub5bb\uac8c \ud560\uae4c\uc694, \ub418\ub294 \ub178\ub4dc\ub9cc \uacc4\uc0b0\ud569\uc2dc\ub2e4. \uc5b8\uc81c \ub9dd\ud55c \ub178\ub4dc\ub3c4 \uacc4\uc0b0\ud574\uc694\n# D0: (root) (K = 3) Z = WWW (unbalanced)\n# D1: R1 Z3\n# D2: RR2 RZ4 ZR4 ZZ6\n# D3: RRR3 RRZ5 RZR5 RZZ7 ZRR5 ZRZ7 ZZR7 ZZZ9 \n# D4: RRRR4 RRRZ6 RRZR6 RRZZ8 RZRR6 RZRZ8 RZZR8 RZZZ10 ZRRR6 ZRRZ8 ZRZR8 ZRZZ10 ZZRR8 ZZRZ10 ZZZR10 ZZZZ12 \nt, k = gets.split.map(&:to_i)\n# \uc544 \uc2dc\ubc1c \uc774\ub7f0 \ub73b\uc774\ub77c\ub2c8\n# \uac01 \uaf43\uc758 \uac1c\uc218\ub97c \ubaa9\uc801\uce58\ub85c \uc124\uc815\ud569\ub2c8\ub2e4.\n# \ubaa8\ub4e0 \uacbd\uc6b0\uc5d0 \ub300\ud574 R\ub85c \ucc44\uc6b0\ub294 1\uac00\uc9c0\uac00 \uc788\uc73c\ubbc0\ub85c dp[x] += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# dp[x]\ub85c\ubd80\ud130, k\uc529 \ub354\ud574 \ubc29\ubb38 \uac00\ub2a5\ud55c \uac1c\uc218\ub97c 1\uc529 \uc99d\uac00\uc2dc\ud0b5\ub2c8\ub2e4\n# dp[x+1]\ub85c \ub118\uc5b4\uac00\uc11c dp[x+1]\uc5d0 \ub300\ud574 \ubc29\ubb38\ud558\uc600\uc73c\ubbc0\ub85c += 1\uc744 \uc218\ud589\ud558\uace0, \uc5ec\uae30\ub85c\ubd80\ud130 \ubc29\ubb38 \uac00\ub2a5\ud55c x+k\ubc30\uc218\ub97c \ubaa8\ub450 += 1\ud569\ub2c8\ub2e4.\n# \uc790\uc5f0\uc2a4\ub7fd\uac8c x' \uac00 x + k \uc640 \uac19\uc544\uc9c0\ub294 \uc21c\uac04\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub54c\ub3c4 += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# \ndp = Array.new(MAX_HEIGHT + k) { 0 } # 0\ubc88 \uc778\ub371\uc2a4 \uc548\uc368\uc694\n# \uc774\ub807\uac8c \ucd08\uae30\ud654\ud574\uc57c\ud558\ub294 \uc774\uc720\uac00 \uc788\uc74c\n# K = 1\uc77c\ub54c\ub294 \ud55c \uc790\ub9ac\uc5d0 \ub450\uac00\uc9c0 \uacbd\uc6b0\uac00 \ubc14\ub85c \ubc1c\uc0dd\ub428. \uadf8\uac78 \ud45c\ud604\ud558\ub824\uba74 \uc774 \ubc29\ubc95\uc774 \uc88b\ub2e4.\ndp[1] += 1\ndp[k] += 1\nacc_dp = Array.new(MAX_HEIGHT + k)\nacc_dp[0] = 0\nacc_dp[1] = dp[1] # \uc5ec\uae30\ub3c4 \ucd08\uae30\ud654\ub97c \uc774\ub807\uac8c \ud574\uc57c\ud568, \uc65c \ud56d\uc0c1 \ucc98\uc74c\uc774 1\uc77c\uac70\ub77c \uc0dd\uac01\ud558\ub294\uac70\uc9c0? K=1\uc774\uba74 \uc774 \uc790\ub9ac\ub294 2\uc774\ub2e4.\nacc = dp[1]\nfor i in 2..MAX_HEIGHT\n if i <= k\n dp[i] += 1 # No more cases...\n else\n dp[i] += (dp[i-1]%MODULO_BASE + dp[i-k]%MODULO_BASE) % MODULO_BASE # Came from prev R(i-1), from prev Z(i-k)\n end\n acc += dp[i]\n acc_dp[i] = acc\nend\n\nt.times {\n a, b = gets.split.map(&:to_i)\n # p \"#{acc_dp[b]} #{acc_dp[a-1]}\"\n puts (acc_dp[b] - acc_dp[a-1])%MODULO_BASE\n}", "positive_code": [{"source_code": "dp=[]\n mod=1000000007\n na=gets.chomp\n \n t=na[0..na.index(\" \")-1].to_i\n i=na.index(\" \")\n k=na[i+1..na.length-1].to_i\n i=1\n dp[0]=1\n while i<100001\n dp[i]=0 \n if(i-k>=0)\n dp[i]=dp[i-k] \n end \n dp[i]+=dp[i-1] \n dp[i]=(dp[i])% mod\n i+=1\n end\n i=1\n while i<100001\n dp[i]+=dp[i-1]\n dp[i]=(dp[i])% mod\n i+=1\n end\n \n while t>0\n na=gets.chomp\n \n a=na[0..na.index(\" \")-1].to_i\n i=na.index(\" \")\n b=na[i+1..na.length-1].to_i\n temp=(dp[b]-dp[a-1])% mod\n puts temp\n \n t-=1\n end"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# \ucd1d \ud14c\uc2a4\ud2b8 \ucf00\uc774\uc2a4 t \uc5d0 \ub300\ud574, \uaf43\uc744 a\uac1c\ubd80\ud130 b\uac1c \uc0ac\uc774\ub85c \uba39\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c \uacc4\uc0b0\ud55c\ub2e4\n# \ub2e8 \ud770 \uaf43\uc740 k\uac1c \ub2e8\uc704\ub85c\ub9cc \uba39\uc744 \uc218 \uc788\ub2e4.\n# \uc608) k = 2\uc77c\ub54c, \uaf43 4\uac1c\ub97c \uba39\uc744 \ub54c\ub294 \ud770\uc0c9\ub9cc 4\uac1c\ub97c \uba39\uc744 \uc218 \uc788\uc9c0\ub9cc,\n# k = 3\uc77c\ub54c\ub294 3\uac1c\ub97c \uba39\uc744 \uc218 \uc5c6\ub2e4.\n# \uc774\ub54c \ube68\uac04 \uaf43 R\uacfc \ud770\uaf43 W\ub97c \uc11e\uc5b4\uc11c \uba39\uc744 \uc218 \uc788\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c modulo 10**9 + 7 \ub85c \uacc4\uc0b0\nMODULO_BASE = 10**9 + 7\nMAX_HEIGHT = 10**5\n# \ud639\uc2dc k-Tree \ubb38\uc81c \uc0dd\uac01\ub098\uc2ed\ub2c8\uae4c? \uc74c \ub3c4\uc6c0\uc774 \ub420\uc9c0 \ubaa8\ub974\uaca0\ub294\ub370\n# \uac01 \uc790\ub9ac\uc5d0 \uc62c \uc218 \uc788\ub294\uac74 R \ub610\ub294 W\uc785\ub2c8\ub2e4. \uc774\uac83\uc740 \uc774\uc9c4\ud2b8\ub9ac\uc785\ub2c8\ub2e4.\n# \uc774\uc9c4\ud2b8\ub9ac\uc758 \uc21c\ud68c\ub294 DFS\uc640 BFS\uc911 \ud558\ub098\ub85c \ud480 \uc218 \uc788\uaca0\uc8e0.\n# growing\uc744 \uc5b4\ub5bb\uac8c \ud560\uae4c\uc694, \ub418\ub294 \ub178\ub4dc\ub9cc \uacc4\uc0b0\ud569\uc2dc\ub2e4. \uc5b8\uc81c \ub9dd\ud55c \ub178\ub4dc\ub3c4 \uacc4\uc0b0\ud574\uc694\n# D0: (root) (K = 3) Z = WWW (unbalanced)\n# D1: R1 Z3\n# D2: RR2 RZ4 ZR4 ZZ6\n# D3: RRR3 RRZ5 RZR5 RZZ7 ZRR5 ZRZ7 ZZR7 ZZZ9 \n# D4: RRRR4 RRRZ6 RRZR6 RRZZ8 RZRR6 RZRZ8 RZZR8 RZZZ10 ZRRR6 ZRRZ8 ZRZR8 ZRZZ10 ZZRR8 ZZRZ10 ZZZR10 ZZZZ12 \nt, k = gets.split.map(&:to_i)\n# \uc544 \uc2dc\ubc1c \uc774\ub7f0 \ub73b\uc774\ub77c\ub2c8\n# \uac01 \uaf43\uc758 \uac1c\uc218\ub97c \ubaa9\uc801\uce58\ub85c \uc124\uc815\ud569\ub2c8\ub2e4.\n# \ubaa8\ub4e0 \uacbd\uc6b0\uc5d0 \ub300\ud574 R\ub85c \ucc44\uc6b0\ub294 1\uac00\uc9c0\uac00 \uc788\uc73c\ubbc0\ub85c dp[x] += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# dp[x]\ub85c\ubd80\ud130, k\uc529 \ub354\ud574 \ubc29\ubb38 \uac00\ub2a5\ud55c \uac1c\uc218\ub97c 1\uc529 \uc99d\uac00\uc2dc\ud0b5\ub2c8\ub2e4\n# dp[x+1]\ub85c \ub118\uc5b4\uac00\uc11c dp[x+1]\uc5d0 \ub300\ud574 \ubc29\ubb38\ud558\uc600\uc73c\ubbc0\ub85c += 1\uc744 \uc218\ud589\ud558\uace0, \uc5ec\uae30\ub85c\ubd80\ud130 \ubc29\ubb38 \uac00\ub2a5\ud55c x+k\ubc30\uc218\ub97c \ubaa8\ub450 += 1\ud569\ub2c8\ub2e4.\n# \uc790\uc5f0\uc2a4\ub7fd\uac8c x' \uac00 x + k \uc640 \uac19\uc544\uc9c0\ub294 \uc21c\uac04\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub54c\ub3c4 += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# \ndp = Array.new(MAX_HEIGHT + k) { 0 } # 0\ubc88 \uc778\ub371\uc2a4 \uc548\uc368\uc694\ndp[1] = 1\ndp[k] = 1\nacc_dp = Array.new(MAX_HEIGHT + k)\nacc_dp[0] = 0\nacc_dp[1] = 1\nacc = 1\nfor i in 2..MAX_HEIGHT\n if i < k\n dp[i] += 1 # No more cases...\n else\n dp[i] += (dp[i-1]%MODULO_BASE + dp[i-k]%MODULO_BASE) % MODULO_BASE # Came from prev R(i-1), from prev Z(i-k)\n end\n acc += dp[i]\n acc_dp[i] = acc\nend\n\nt.times {\n a, b = gets.split.map(&:to_i)\n puts (acc_dp[b] - acc_dp[a-1])%MODULO_BASE\n}"}, {"source_code": "# coding: utf-8\n\n# \ucd1d \ud14c\uc2a4\ud2b8 \ucf00\uc774\uc2a4 t \uc5d0 \ub300\ud574, \uaf43\uc744 a\uac1c\ubd80\ud130 b\uac1c \uc0ac\uc774\ub85c \uba39\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c \uacc4\uc0b0\ud55c\ub2e4\n# \ub2e8 \ud770 \uaf43\uc740 k\uac1c \ub2e8\uc704\ub85c\ub9cc \uba39\uc744 \uc218 \uc788\ub2e4.\n# \uc608) k = 2\uc77c\ub54c, \uaf43 4\uac1c\ub97c \uba39\uc744 \ub54c\ub294 \ud770\uc0c9\ub9cc 4\uac1c\ub97c \uba39\uc744 \uc218 \uc788\uc9c0\ub9cc,\n# k = 3\uc77c\ub54c\ub294 3\uac1c\ub97c \uba39\uc744 \uc218 \uc5c6\ub2e4.\n# \uc774\ub54c \ube68\uac04 \uaf43 R\uacfc \ud770\uaf43 W\ub97c \uc11e\uc5b4\uc11c \uba39\uc744 \uc218 \uc788\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c modulo 10**9 + 7 \ub85c \uacc4\uc0b0\nMODULO_BASE = 10**9 + 7\nMAX_HEIGHT = 10**5\n# \ud639\uc2dc k-Tree \ubb38\uc81c \uc0dd\uac01\ub098\uc2ed\ub2c8\uae4c? \uc74c \ub3c4\uc6c0\uc774 \ub420\uc9c0 \ubaa8\ub974\uaca0\ub294\ub370\n# \uac01 \uc790\ub9ac\uc5d0 \uc62c \uc218 \uc788\ub294\uac74 R \ub610\ub294 W\uc785\ub2c8\ub2e4. \uc774\uac83\uc740 \uc774\uc9c4\ud2b8\ub9ac\uc785\ub2c8\ub2e4.\n# \uc774\uc9c4\ud2b8\ub9ac\uc758 \uc21c\ud68c\ub294 DFS\uc640 BFS\uc911 \ud558\ub098\ub85c \ud480 \uc218 \uc788\uaca0\uc8e0.\n# growing\uc744 \uc5b4\ub5bb\uac8c \ud560\uae4c\uc694, \ub418\ub294 \ub178\ub4dc\ub9cc \uacc4\uc0b0\ud569\uc2dc\ub2e4. \uc5b8\uc81c \ub9dd\ud55c \ub178\ub4dc\ub3c4 \uacc4\uc0b0\ud574\uc694\n# D0: (root) (K = 3) Z = WWW (unbalanced)\n# D1: R1 Z3\n# D2: RR2 RZ4 ZR4 ZZ6\n# D3: RRR3 RRZ5 RZR5 RZZ7 ZRR5 ZRZ7 ZZR7 ZZZ9 \n# D4: RRRR4 RRRZ6 RRZR6 RRZZ8 RZRR6 RZRZ8 RZZR8 RZZZ10 ZRRR6 ZRRZ8 ZRZR8 ZRZZ10 ZZRR8 ZZRZ10 ZZZR10 ZZZZ12 \nt, k = gets.split.map(&:to_i)\n# \uc544 \uc2dc\ubc1c \uc774\ub7f0 \ub73b\uc774\ub77c\ub2c8\n# \uac01 \uaf43\uc758 \uac1c\uc218\ub97c \ubaa9\uc801\uce58\ub85c \uc124\uc815\ud569\ub2c8\ub2e4.\n# \ubaa8\ub4e0 \uacbd\uc6b0\uc5d0 \ub300\ud574 R\ub85c \ucc44\uc6b0\ub294 1\uac00\uc9c0\uac00 \uc788\uc73c\ubbc0\ub85c dp[x] += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# dp[x]\ub85c\ubd80\ud130, k\uc529 \ub354\ud574 \ubc29\ubb38 \uac00\ub2a5\ud55c \uac1c\uc218\ub97c 1\uc529 \uc99d\uac00\uc2dc\ud0b5\ub2c8\ub2e4\n# dp[x+1]\ub85c \ub118\uc5b4\uac00\uc11c dp[x+1]\uc5d0 \ub300\ud574 \ubc29\ubb38\ud558\uc600\uc73c\ubbc0\ub85c += 1\uc744 \uc218\ud589\ud558\uace0, \uc5ec\uae30\ub85c\ubd80\ud130 \ubc29\ubb38 \uac00\ub2a5\ud55c x+k\ubc30\uc218\ub97c \ubaa8\ub450 += 1\ud569\ub2c8\ub2e4.\n# \uc790\uc5f0\uc2a4\ub7fd\uac8c x' \uac00 x + k \uc640 \uac19\uc544\uc9c0\ub294 \uc21c\uac04\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub54c\ub3c4 += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# \ndp = Array.new(MAX_HEIGHT + k) { 0 } # 0\ubc88 \uc778\ub371\uc2a4 \uc548\uc368\uc694\n# \uc774\ub807\uac8c \ucd08\uae30\ud654\ud574\uc57c\ud558\ub294 \uc774\uc720\uac00 \uc788\uc74c\n# K = 1\uc77c\ub54c\ub294 \ud55c \uc790\ub9ac\uc5d0 \ub450\uac00\uc9c0 \uacbd\uc6b0\uac00 \ubc14\ub85c \ubc1c\uc0dd\ub428. \uadf8\uac78 \ud45c\ud604\ud558\ub824\uba74 \uc774 \ubc29\ubc95\uc774 \uc88b\ub2e4.\ndp[1] += 1\ndp[k] += 1\nacc_dp = Array.new(MAX_HEIGHT + k)\nacc_dp[0] = 0\nacc_dp[1] = dp[1] # \uc5ec\uae30\ub3c4 \ucd08\uae30\ud654\ub97c \uc774\ub807\uac8c \ud574\uc57c\ud568, \uc65c \ud56d\uc0c1 \ucc98\uc74c\uc774 1\uc77c\uac70\ub77c \uc0dd\uac01\ud558\ub294\uac70\uc9c0? K=1\uc774\uba74 \uc774 \uc790\ub9ac\ub294 2\uc774\ub2e4.\nacc = 1\nfor i in 2..MAX_HEIGHT\n if i <= k\n dp[i] += 1 # No more cases...\n else\n dp[i] += (dp[i-1]%MODULO_BASE + dp[i-k]%MODULO_BASE) % MODULO_BASE # Came from prev R(i-1), from prev Z(i-k)\n end\n acc += dp[i]\n acc_dp[i] = acc\nend\n\nt.times {\n a, b = gets.split.map(&:to_i)\n # p \"#{acc_dp[b]} #{acc_dp[a-1]}\"\n puts (acc_dp[b] - acc_dp[a-1])%MODULO_BASE\n}"}, {"source_code": "# coding: utf-8\n\n# \ucd1d \ud14c\uc2a4\ud2b8 \ucf00\uc774\uc2a4 t \uc5d0 \ub300\ud574, \uaf43\uc744 a\uac1c\ubd80\ud130 b\uac1c \uc0ac\uc774\ub85c \uba39\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c \uacc4\uc0b0\ud55c\ub2e4\n# \ub2e8 \ud770 \uaf43\uc740 k\uac1c \ub2e8\uc704\ub85c\ub9cc \uba39\uc744 \uc218 \uc788\ub2e4.\n# \uc608) k = 2\uc77c\ub54c, \uaf43 4\uac1c\ub97c \uba39\uc744 \ub54c\ub294 \ud770\uc0c9\ub9cc 4\uac1c\ub97c \uba39\uc744 \uc218 \uc788\uc9c0\ub9cc,\n# k = 3\uc77c\ub54c\ub294 3\uac1c\ub97c \uba39\uc744 \uc218 \uc5c6\ub2e4.\n# \uc774\ub54c \ube68\uac04 \uaf43 R\uacfc \ud770\uaf43 W\ub97c \uc11e\uc5b4\uc11c \uba39\uc744 \uc218 \uc788\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c modulo 10**9 + 7 \ub85c \uacc4\uc0b0\nMODULO_BASE = 10**9 + 7\nMAX_HEIGHT = 10**5\n# \ud639\uc2dc k-Tree \ubb38\uc81c \uc0dd\uac01\ub098\uc2ed\ub2c8\uae4c? \uc74c \ub3c4\uc6c0\uc774 \ub420\uc9c0 \ubaa8\ub974\uaca0\ub294\ub370\n# \uac01 \uc790\ub9ac\uc5d0 \uc62c \uc218 \uc788\ub294\uac74 R \ub610\ub294 W\uc785\ub2c8\ub2e4. \uc774\uac83\uc740 \uc774\uc9c4\ud2b8\ub9ac\uc785\ub2c8\ub2e4.\n# \uc774\uc9c4\ud2b8\ub9ac\uc758 \uc21c\ud68c\ub294 DFS\uc640 BFS\uc911 \ud558\ub098\ub85c \ud480 \uc218 \uc788\uaca0\uc8e0.\n# growing\uc744 \uc5b4\ub5bb\uac8c \ud560\uae4c\uc694, \ub418\ub294 \ub178\ub4dc\ub9cc \uacc4\uc0b0\ud569\uc2dc\ub2e4. \uc5b8\uc81c \ub9dd\ud55c \ub178\ub4dc\ub3c4 \uacc4\uc0b0\ud574\uc694\n# D0: (root) (K = 3) Z = WWW (unbalanced)\n# D1: R1 Z3\n# D2: RR2 RZ4 ZR4 ZZ6\n# D3: RRR3 RRZ5 RZR5 RZZ7 ZRR5 ZRZ7 ZZR7 ZZZ9 \n# D4: RRRR4 RRRZ6 RRZR6 RRZZ8 RZRR6 RZRZ8 RZZR8 RZZZ10 ZRRR6 ZRRZ8 ZRZR8 ZRZZ10 ZZRR8 ZZRZ10 ZZZR10 ZZZZ12 \nt, k = gets.split.map(&:to_i)\n# \uc544 \uc2dc\ubc1c \uc774\ub7f0 \ub73b\uc774\ub77c\ub2c8\n# \uac01 \uaf43\uc758 \uac1c\uc218\ub97c \ubaa9\uc801\uce58\ub85c \uc124\uc815\ud569\ub2c8\ub2e4.\n# \ubaa8\ub4e0 \uacbd\uc6b0\uc5d0 \ub300\ud574 R\ub85c \ucc44\uc6b0\ub294 1\uac00\uc9c0\uac00 \uc788\uc73c\ubbc0\ub85c dp[x] += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# dp[x]\ub85c\ubd80\ud130, k\uc529 \ub354\ud574 \ubc29\ubb38 \uac00\ub2a5\ud55c \uac1c\uc218\ub97c 1\uc529 \uc99d\uac00\uc2dc\ud0b5\ub2c8\ub2e4\n# dp[x+1]\ub85c \ub118\uc5b4\uac00\uc11c dp[x+1]\uc5d0 \ub300\ud574 \ubc29\ubb38\ud558\uc600\uc73c\ubbc0\ub85c += 1\uc744 \uc218\ud589\ud558\uace0, \uc5ec\uae30\ub85c\ubd80\ud130 \ubc29\ubb38 \uac00\ub2a5\ud55c x+k\ubc30\uc218\ub97c \ubaa8\ub450 += 1\ud569\ub2c8\ub2e4.\n# \uc790\uc5f0\uc2a4\ub7fd\uac8c x' \uac00 x + k \uc640 \uac19\uc544\uc9c0\ub294 \uc21c\uac04\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub54c\ub3c4 += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# \ndp = Array.new(MAX_HEIGHT + k) { 0 } # 0\ubc88 \uc778\ub371\uc2a4 \uc548\uc368\uc694\ndp[1] = 1\ndp[k] = 1\nacc_dp = Array.new(MAX_HEIGHT + k)\nacc_dp[0] = 0\nacc_dp[1] = 1\nacc = 1\nfor i in 2..MAX_HEIGHT\n if i < k\n dp[i] += 1 # No more cases...\n else\n dp[i] += (dp[i-1]%MODULO_BASE + dp[i-k]%MODULO_BASE) % MODULO_BASE # Came from prev R(i-1), from prev Z(i-k)\n end\n acc = (acc%MODULO_BASE + dp[i]%MODULO_BASE)%MODULO_BASE\n acc_dp[i] = acc\nend\n\nt.times {\n a, b = gets.split.map(&:to_i)\n puts (acc_dp[b] - acc_dp[a-1]).abs\n}"}, {"source_code": "# coding: utf-8\n\n# \ucd1d \ud14c\uc2a4\ud2b8 \ucf00\uc774\uc2a4 t \uc5d0 \ub300\ud574, \uaf43\uc744 a\uac1c\ubd80\ud130 b\uac1c \uc0ac\uc774\ub85c \uba39\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c \uacc4\uc0b0\ud55c\ub2e4\n# \ub2e8 \ud770 \uaf43\uc740 k\uac1c \ub2e8\uc704\ub85c\ub9cc \uba39\uc744 \uc218 \uc788\ub2e4.\n# \uc608) k = 2\uc77c\ub54c, \uaf43 4\uac1c\ub97c \uba39\uc744 \ub54c\ub294 \ud770\uc0c9\ub9cc 4\uac1c\ub97c \uba39\uc744 \uc218 \uc788\uc9c0\ub9cc,\n# k = 3\uc77c\ub54c\ub294 3\uac1c\ub97c \uba39\uc744 \uc218 \uc5c6\ub2e4.\n# \uc774\ub54c \ube68\uac04 \uaf43 R\uacfc \ud770\uaf43 W\ub97c \uc11e\uc5b4\uc11c \uba39\uc744 \uc218 \uc788\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c modulo 10**9 + 7 \ub85c \uacc4\uc0b0\nMODULO_BASE = 10**9 + 7\nMAX_HEIGHT = 10**5\n# \ud639\uc2dc k-Tree \ubb38\uc81c \uc0dd\uac01\ub098\uc2ed\ub2c8\uae4c? \uc74c \ub3c4\uc6c0\uc774 \ub420\uc9c0 \ubaa8\ub974\uaca0\ub294\ub370\n# \uac01 \uc790\ub9ac\uc5d0 \uc62c \uc218 \uc788\ub294\uac74 R \ub610\ub294 W\uc785\ub2c8\ub2e4. \uc774\uac83\uc740 \uc774\uc9c4\ud2b8\ub9ac\uc785\ub2c8\ub2e4.\n# \uc774\uc9c4\ud2b8\ub9ac\uc758 \uc21c\ud68c\ub294 DFS\uc640 BFS\uc911 \ud558\ub098\ub85c \ud480 \uc218 \uc788\uaca0\uc8e0.\n# growing\uc744 \uc5b4\ub5bb\uac8c \ud560\uae4c\uc694, \ub418\ub294 \ub178\ub4dc\ub9cc \uacc4\uc0b0\ud569\uc2dc\ub2e4. \uc5b8\uc81c \ub9dd\ud55c \ub178\ub4dc\ub3c4 \uacc4\uc0b0\ud574\uc694\n# D0: (root) (K = 3) Z = WWW (unbalanced)\n# D1: R1 Z3\n# D2: RR2 RZ4 ZR4 ZZ6\n# D3: RRR3 RRZ5 RZR5 RZZ7 ZRR5 ZRZ7 ZZR7 ZZZ9 \n# D4: RRRR4 RRRZ6 RRZR6 RRZZ8 RZRR6 RZRZ8 RZZR8 RZZZ10 ZRRR6 ZRRZ8 ZRZR8 ZRZZ10 ZZRR8 ZZRZ10 ZZZR10 ZZZZ12 \nt, k = gets.split.map(&:to_i)\n# \uc544 \uc2dc\ubc1c \uc774\ub7f0 \ub73b\uc774\ub77c\ub2c8\n# \uac01 \uaf43\uc758 \uac1c\uc218\ub97c \ubaa9\uc801\uce58\ub85c \uc124\uc815\ud569\ub2c8\ub2e4.\n# \ubaa8\ub4e0 \uacbd\uc6b0\uc5d0 \ub300\ud574 R\ub85c \ucc44\uc6b0\ub294 1\uac00\uc9c0\uac00 \uc788\uc73c\ubbc0\ub85c dp[x] += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# dp[x]\ub85c\ubd80\ud130, k\uc529 \ub354\ud574 \ubc29\ubb38 \uac00\ub2a5\ud55c \uac1c\uc218\ub97c 1\uc529 \uc99d\uac00\uc2dc\ud0b5\ub2c8\ub2e4\n# dp[x+1]\ub85c \ub118\uc5b4\uac00\uc11c dp[x+1]\uc5d0 \ub300\ud574 \ubc29\ubb38\ud558\uc600\uc73c\ubbc0\ub85c += 1\uc744 \uc218\ud589\ud558\uace0, \uc5ec\uae30\ub85c\ubd80\ud130 \ubc29\ubb38 \uac00\ub2a5\ud55c x+k\ubc30\uc218\ub97c \ubaa8\ub450 += 1\ud569\ub2c8\ub2e4.\n# \uc790\uc5f0\uc2a4\ub7fd\uac8c x' \uac00 x + k \uc640 \uac19\uc544\uc9c0\ub294 \uc21c\uac04\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub54c\ub3c4 += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# \ndp = Array.new(MAX_HEIGHT + k) { 0 } # 0\ubc88 \uc778\ub371\uc2a4 \uc548\uc368\uc694\n# \uc774\ub807\uac8c \ucd08\uae30\ud654\ud574\uc57c\ud558\ub294 \uc774\uc720\uac00 \uc788\uc74c\n# K = 1\uc77c\ub54c\ub294 \ud55c \uc790\ub9ac\uc5d0 \ub450\uac00\uc9c0 \uacbd\uc6b0\uac00 \ubc14\ub85c \ubc1c\uc0dd\ub428. \uadf8\uac78 \ud45c\ud604\ud558\ub824\uba74 \uc774 \ubc29\ubc95\uc774 \uc88b\ub2e4.\ndp[1] += 1\ndp[k] += 1\nacc_dp = Array.new(MAX_HEIGHT + k)\nacc_dp[0] = 0\nacc_dp[1] = dp[1] # \uc5ec\uae30\ub3c4 \ucd08\uae30\ud654\ub97c \uc774\ub807\uac8c \ud574\uc57c\ud568, \uc65c \ud56d\uc0c1 \ucc98\uc74c\uc774 1\uc77c\uac70\ub77c \uc0dd\uac01\ud558\ub294\uac70\uc9c0? K=1\uc774\uba74 \uc774 \uc790\ub9ac\ub294 2\uc774\ub2e4.\nacc = 1\nfor i in 2..MAX_HEIGHT\n if i < k\n dp[i] += 1 # No more cases...\n else\n dp[i] += (dp[i-1]%MODULO_BASE + dp[i-k]%MODULO_BASE) % MODULO_BASE # Came from prev R(i-1), from prev Z(i-k)\n end\n acc += dp[i]\n acc_dp[i] = acc\nend\n\nt.times {\n a, b = gets.split.map(&:to_i)\n # p \"#{acc_dp[b]} #{acc_dp[a-1]}\"\n puts (acc_dp[b]%MODULO_BASE - acc_dp[a-1]%MODULO_BASE)%MODULO_BASE\n}"}, {"source_code": "# coding: utf-8\n\n# \ucd1d \ud14c\uc2a4\ud2b8 \ucf00\uc774\uc2a4 t \uc5d0 \ub300\ud574, \uaf43\uc744 a\uac1c\ubd80\ud130 b\uac1c \uc0ac\uc774\ub85c \uba39\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c \uacc4\uc0b0\ud55c\ub2e4\n# \ub2e8 \ud770 \uaf43\uc740 k\uac1c \ub2e8\uc704\ub85c\ub9cc \uba39\uc744 \uc218 \uc788\ub2e4.\n# \uc608) k = 2\uc77c\ub54c, \uaf43 4\uac1c\ub97c \uba39\uc744 \ub54c\ub294 \ud770\uc0c9\ub9cc 4\uac1c\ub97c \uba39\uc744 \uc218 \uc788\uc9c0\ub9cc,\n# k = 3\uc77c\ub54c\ub294 3\uac1c\ub97c \uba39\uc744 \uc218 \uc5c6\ub2e4.\n# \uc774\ub54c \ube68\uac04 \uaf43 R\uacfc \ud770\uaf43 W\ub97c \uc11e\uc5b4\uc11c \uba39\uc744 \uc218 \uc788\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c modulo 10**9 + 7 \ub85c \uacc4\uc0b0\nMODULO_BASE = 10**9 + 7\nMAX_HEIGHT = 10**5\n# \ud639\uc2dc k-Tree \ubb38\uc81c \uc0dd\uac01\ub098\uc2ed\ub2c8\uae4c? \uc74c \ub3c4\uc6c0\uc774 \ub420\uc9c0 \ubaa8\ub974\uaca0\ub294\ub370\n# \uac01 \uc790\ub9ac\uc5d0 \uc62c \uc218 \uc788\ub294\uac74 R \ub610\ub294 W\uc785\ub2c8\ub2e4. \uc774\uac83\uc740 \uc774\uc9c4\ud2b8\ub9ac\uc785\ub2c8\ub2e4.\n# \uc774\uc9c4\ud2b8\ub9ac\uc758 \uc21c\ud68c\ub294 DFS\uc640 BFS\uc911 \ud558\ub098\ub85c \ud480 \uc218 \uc788\uaca0\uc8e0.\n# growing\uc744 \uc5b4\ub5bb\uac8c \ud560\uae4c\uc694, \ub418\ub294 \ub178\ub4dc\ub9cc \uacc4\uc0b0\ud569\uc2dc\ub2e4. \uc5b8\uc81c \ub9dd\ud55c \ub178\ub4dc\ub3c4 \uacc4\uc0b0\ud574\uc694\n# D0: (root) (K = 3) Z = WWW (unbalanced)\n# D1: R1 Z3\n# D2: RR2 RZ4 ZR4 ZZ6\n# D3: RRR3 RRZ5 RZR5 RZZ7 ZRR5 ZRZ7 ZZR7 ZZZ9 \n# D4: RRRR4 RRRZ6 RRZR6 RRZZ8 RZRR6 RZRZ8 RZZR8 RZZZ10 ZRRR6 ZRRZ8 ZRZR8 ZRZZ10 ZZRR8 ZZRZ10 ZZZR10 ZZZZ12 \nt, k = gets.split.map(&:to_i)\n# \uc544 \uc2dc\ubc1c \uc774\ub7f0 \ub73b\uc774\ub77c\ub2c8\n# \uac01 \uaf43\uc758 \uac1c\uc218\ub97c \ubaa9\uc801\uce58\ub85c \uc124\uc815\ud569\ub2c8\ub2e4.\n# \ubaa8\ub4e0 \uacbd\uc6b0\uc5d0 \ub300\ud574 R\ub85c \ucc44\uc6b0\ub294 1\uac00\uc9c0\uac00 \uc788\uc73c\ubbc0\ub85c dp[x] += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# dp[x]\ub85c\ubd80\ud130, k\uc529 \ub354\ud574 \ubc29\ubb38 \uac00\ub2a5\ud55c \uac1c\uc218\ub97c 1\uc529 \uc99d\uac00\uc2dc\ud0b5\ub2c8\ub2e4\n# dp[x+1]\ub85c \ub118\uc5b4\uac00\uc11c dp[x+1]\uc5d0 \ub300\ud574 \ubc29\ubb38\ud558\uc600\uc73c\ubbc0\ub85c += 1\uc744 \uc218\ud589\ud558\uace0, \uc5ec\uae30\ub85c\ubd80\ud130 \ubc29\ubb38 \uac00\ub2a5\ud55c x+k\ubc30\uc218\ub97c \ubaa8\ub450 += 1\ud569\ub2c8\ub2e4.\n# \uc790\uc5f0\uc2a4\ub7fd\uac8c x' \uac00 x + k \uc640 \uac19\uc544\uc9c0\ub294 \uc21c\uac04\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub54c\ub3c4 += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# \ndp = Array.new(MAX_HEIGHT + k) { 0 } # 0\ubc88 \uc778\ub371\uc2a4 \uc548\uc368\uc694\ndp[1] = 1\ndp[k] = 1\nacc_dp = Array.new(MAX_HEIGHT + k)\nacc_dp[0] = 0\nacc_dp[1] = 1\nacc = 1\nfor i in 2..MAX_HEIGHT\n if i < k\n dp[i] += 1 # No more cases...\n else\n dp[i] += (dp[i-1]%MODULO_BASE + dp[i-k]%MODULO_BASE) % MODULO_BASE # Came from prev R(i-1), from prev Z(i-k)\n end\n acc += dp[i]\n acc_dp[i] = acc\nend\n\nt.times {\n a, b = gets.split.map(&:to_i)\n puts (acc_dp[b] - acc_dp[a-1])\n}"}, {"source_code": "# coding: utf-8\n\n# \ucd1d \ud14c\uc2a4\ud2b8 \ucf00\uc774\uc2a4 t \uc5d0 \ub300\ud574, \uaf43\uc744 a\uac1c\ubd80\ud130 b\uac1c \uc0ac\uc774\ub85c \uba39\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c \uacc4\uc0b0\ud55c\ub2e4\n# \ub2e8 \ud770 \uaf43\uc740 k\uac1c \ub2e8\uc704\ub85c\ub9cc \uba39\uc744 \uc218 \uc788\ub2e4.\n# \uc608) k = 2\uc77c\ub54c, \uaf43 4\uac1c\ub97c \uba39\uc744 \ub54c\ub294 \ud770\uc0c9\ub9cc 4\uac1c\ub97c \uba39\uc744 \uc218 \uc788\uc9c0\ub9cc,\n# k = 3\uc77c\ub54c\ub294 3\uac1c\ub97c \uba39\uc744 \uc218 \uc5c6\ub2e4.\n# \uc774\ub54c \ube68\uac04 \uaf43 R\uacfc \ud770\uaf43 W\ub97c \uc11e\uc5b4\uc11c \uba39\uc744 \uc218 \uc788\ub294 \uacbd\uc6b0\uc758 \uc218\ub97c modulo 10**9 + 7 \ub85c \uacc4\uc0b0\nMODULO_BASE = 10**9 + 7\nMAX_HEIGHT = 10**5\n# \ud639\uc2dc k-Tree \ubb38\uc81c \uc0dd\uac01\ub098\uc2ed\ub2c8\uae4c? \uc74c \ub3c4\uc6c0\uc774 \ub420\uc9c0 \ubaa8\ub974\uaca0\ub294\ub370\n# \uac01 \uc790\ub9ac\uc5d0 \uc62c \uc218 \uc788\ub294\uac74 R \ub610\ub294 W\uc785\ub2c8\ub2e4. \uc774\uac83\uc740 \uc774\uc9c4\ud2b8\ub9ac\uc785\ub2c8\ub2e4.\n# \uc774\uc9c4\ud2b8\ub9ac\uc758 \uc21c\ud68c\ub294 DFS\uc640 BFS\uc911 \ud558\ub098\ub85c \ud480 \uc218 \uc788\uaca0\uc8e0.\n# growing\uc744 \uc5b4\ub5bb\uac8c \ud560\uae4c\uc694, \ub418\ub294 \ub178\ub4dc\ub9cc \uacc4\uc0b0\ud569\uc2dc\ub2e4. \uc5b8\uc81c \ub9dd\ud55c \ub178\ub4dc\ub3c4 \uacc4\uc0b0\ud574\uc694\n# D0: (root) (K = 3) Z = WWW (unbalanced)\n# D1: R1 Z3\n# D2: RR2 RZ4 ZR4 ZZ6\n# D3: RRR3 RRZ5 RZR5 RZZ7 ZRR5 ZRZ7 ZZR7 ZZZ9 \n# D4: RRRR4 RRRZ6 RRZR6 RRZZ8 RZRR6 RZRZ8 RZZR8 RZZZ10 ZRRR6 ZRRZ8 ZRZR8 ZRZZ10 ZZRR8 ZZRZ10 ZZZR10 ZZZZ12 \nt, k = gets.split.map(&:to_i)\n# \uc544 \uc2dc\ubc1c \uc774\ub7f0 \ub73b\uc774\ub77c\ub2c8\n# \uac01 \uaf43\uc758 \uac1c\uc218\ub97c \ubaa9\uc801\uce58\ub85c \uc124\uc815\ud569\ub2c8\ub2e4.\n# \ubaa8\ub4e0 \uacbd\uc6b0\uc5d0 \ub300\ud574 R\ub85c \ucc44\uc6b0\ub294 1\uac00\uc9c0\uac00 \uc788\uc73c\ubbc0\ub85c dp[x] += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# dp[x]\ub85c\ubd80\ud130, k\uc529 \ub354\ud574 \ubc29\ubb38 \uac00\ub2a5\ud55c \uac1c\uc218\ub97c 1\uc529 \uc99d\uac00\uc2dc\ud0b5\ub2c8\ub2e4\n# dp[x+1]\ub85c \ub118\uc5b4\uac00\uc11c dp[x+1]\uc5d0 \ub300\ud574 \ubc29\ubb38\ud558\uc600\uc73c\ubbc0\ub85c += 1\uc744 \uc218\ud589\ud558\uace0, \uc5ec\uae30\ub85c\ubd80\ud130 \ubc29\ubb38 \uac00\ub2a5\ud55c x+k\ubc30\uc218\ub97c \ubaa8\ub450 += 1\ud569\ub2c8\ub2e4.\n# \uc790\uc5f0\uc2a4\ub7fd\uac8c x' \uac00 x + k \uc640 \uac19\uc544\uc9c0\ub294 \uc21c\uac04\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub54c\ub3c4 += 1\uc744 \uc801\uc6a9\ud569\ub2c8\ub2e4.\n# \ndp = Array.new(MAX_HEIGHT + k) { 0 } # 0\ubc88 \uc778\ub371\uc2a4 \uc548\uc368\uc694\n# \uc774\ub807\uac8c \ucd08\uae30\ud654\ud574\uc57c\ud558\ub294 \uc774\uc720\uac00 \uc788\uc74c\n# K = 1\uc77c\ub54c\ub294 \ud55c \uc790\ub9ac\uc5d0 \ub450\uac00\uc9c0 \uacbd\uc6b0\uac00 \ubc14\ub85c \ubc1c\uc0dd\ub428. \uadf8\uac78 \ud45c\ud604\ud558\ub824\uba74 \uc774 \ubc29\ubc95\uc774 \uc88b\ub2e4.\ndp[1] += 1\ndp[k] += 1\nacc_dp = Array.new(MAX_HEIGHT + k)\nacc_dp[0] = 0\nacc_dp[1] = dp[1] # \uc5ec\uae30\ub3c4 \ucd08\uae30\ud654\ub97c \uc774\ub807\uac8c \ud574\uc57c\ud568, \uc65c \ud56d\uc0c1 \ucc98\uc74c\uc774 1\uc77c\uac70\ub77c \uc0dd\uac01\ud558\ub294\uac70\uc9c0? K=1\uc774\uba74 \uc774 \uc790\ub9ac\ub294 2\uc774\ub2e4.\nacc = 1\nfor i in 2..MAX_HEIGHT\n if i < k\n dp[i] += 1 # No more cases...\n else\n dp[i] += (dp[i-1]%MODULO_BASE + dp[i-k]%MODULO_BASE) % MODULO_BASE # Came from prev R(i-1), from prev Z(i-k)\n end\n acc += dp[i]\n acc_dp[i] = acc\nend\n\nt.times {\n a, b = gets.split.map(&:to_i)\n # p \"#{acc_dp[b]} #{acc_dp[a-1]}\"\n puts (acc_dp[b] - acc_dp[a-1])%MODULO_BASE\n}"}], "src_uid": "16c016c0735be1815c7b94c5c50516f1"} {"source_code": "gets.to_i.times do\n s=gets.chomp\n cur=nil\n s.each_char do|c|\n if cur==nil\n if c!='Y' and c!='e' and c!='s'\n cur=nil\n break\n else \n cur=c\n end\n elsif (cur=='Y' and c=='e') or (cur=='e' and c=='s') or (cur=='s' and c=='Y')\n cur=c\n else\n cur=nil \n break\n end\n end \n if cur==nil\n puts 'NO'\n else\n puts 'YES'\n end\nend", "positive_code": [{"source_code": "main = -> {\r\n s = gets.chomp\r\n yes = \"Yes\" * 50\r\n yes.include?(s) ? \"YES\" : \"NO\"\r\n}\r\n\r\nt = gets.to_i\r\nputs t.times.map{ main.call }.join(\"\\n\")"}, {"source_code": "ans = []\r\ngets.to_i.times do\r\n s = gets.chomp\r\n a = 'Yes' * 50\r\n ans << if a.include? s\r\n 'YES'\r\n else\r\n 'NO'\r\n end\r\nend\r\nputs ans\r\n"}], "negative_code": [], "src_uid": "3cd56870a96baf8860e9b7e89008d895"} {"source_code": "testcases = gets.to_i\ntestcases.times do\n n = gets.to_i\n an = gets.chomp!.split.map(&:to_i)\n an.sort!\n an.reverse!\n if an.size <= 2\n p 0\n else\n res = an[0] * (n - 1) - an.sum\n p res >=0 ? res : res % (n-1)\n end\nend\n", "positive_code": [{"source_code": "testcases = gets.to_i\ntestcases.times do\n n = gets.to_i\n an = gets.chomp!.split.map(&:to_i)\n if an.size <= 2\n p 0\n else\n res = an.max * (n - 1) - an.sum\n p res >=0 ? res : res % (n-1)\n end\nend"}, {"source_code": "DEBUG = false\nMOD = 10**9+7\nYESNO = %w(Yes No)\n\ndef main\n t = int\n t.times do\n n = int\n a = ints\n\n seg = Segtree.new(a, 0) { |x, y| max(x, y) }\n sum = a.sum\n\n ans_max = 0\n n.times do |i|\n othermax = max(seg.prod(0, i), seg.prod(i+1, n))\n diff = othermax * (n-1) - sum\n if diff < 0\n diff %= n - 1\n end\n ans_max = max(ans_max, diff)\n end\n\n puts ans_max\n end\nend\n\ndef int; gets.to_i; end\ndef ints; gets.split.map &:to_i; end\ndef float; gets.to_f; end\ndef floats; gets.split.map &:to_f; end\ndef array(&convert); gets.split.map(&convert); end\ndef string; gets.chomp; end\ndef rep(n, &b); Array.new(n, &b); end\ndef yes; puts YESNO[0]; end\ndef no; puts YESNO[1]; end\ndef yesno t; t ? yes : no; end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } }; end\ndef sorted_uniq(xs); x = nil; xs.filter! { |y| c = x === y; x = y; !c }; end\ndef max(*xs); xs.max; end\ndef min(*xs); xs.min; end\ndef minmax(*xs); xs.minmax; end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w }; end\ndef debug(x); if DEBUG; STDERR.puts (block_given? ? yield(x) : x).inspect; end; x; end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid; end\ndef if_debug; yield if DEBUG; end\n\ndef div_ceil(x, y); (x + y - 1) / y; end\ndef gcd(*xs); xs.inject(0) { |y, x| y.gcd(x) }; end\ndef factorial(n, mod); (2..n).inject(1) { |f, x| f * x % mod }; end\ndef cumsum(xs); ys = [0]; xs.each { |x| ys << x + ys[-1] }; ys; end\ndef cumdiff(ys); xs = []; xs.inject { |x, y| xs << (d = y - x); d }; end\ndef cumfold(ys, range); r = range.end; r -= 1 if range.exclusive_end?; ys[r] - ys[range.begin-1]; end\ndef mod_inv(x, mod); x.pow(mod-2, mod); end\ndef mod_div(x, y, mod); x * mod_inv(y, mod) % mod; end\ndef bitbrute(size, &block); (1<> i) }\n end\n\n def get(pos)\n @d[@leaf_size + pos]\n end\n\n def prod(l, r)\n return @e if l == r\n\n sml = @e\n smr = @e\n l += @leaf_size\n r += @leaf_size\n\n while l < r\n if l[0] == 1\n sml = @op.call(sml, @d[l])\n l += 1\n end\n if r[0] == 1\n r -= 1\n smr = @op.call(@d[r], smr)\n end\n l /= 2\n r /= 2\n end\n\n @op.call(sml, smr)\n end\n\n def all_prod\n @d[1]\n end\n\n def max_right(l, &block)\n return @n if l == @n\n\n f = proc(&block)\n\n l += @leaf_size\n sm = @e\n loop do\n l /= 2 while l.even?\n unless f.call(@op.call(sm, @d[l]))\n while l < @leaf_size\n l *= 2\n if f.call(@op.call(sm, @d[l]))\n sm = @op.call(sm, @d[l])\n l += 1\n end\n end\n\n return l - @leaf_size\n end\n\n sm = @op.call(sm, @d[l])\n l += 1\n break if (l & -l) == l\n end\n\n @n\n end\n\n def min_left(r, &block)\n return 0 if r == 0\n\n f = proc(&block)\n\n r += @leaf_size\n sm = @e\n loop do\n r -= 1\n r /= 2 while r > 1 && r.odd?\n unless f.call(@op.call(@d[r], sm))\n while r < @leaf_size\n r = r * 2 + 1\n if f.call(@op.call(@d[r], sm))\n sm = @op.call(@d[r], sm)\n r -= 1\n end\n end\n\n return r + 1 - @leaf_size\n end\n\n sm = @op.call(@d[r], sm)\n break if (r & -r) == r\n end\n\n 0\n end\n\n def update(k)\n @d[k] = @op.call(@d[2 * k], @d[2 * k + 1])\n end\n\n def inspect\n t = 0\n res = \"SegmentTree @e = #{@e}, @n = #{@n}, @leaf_size = #{@leaf_size} @op = #{@op}\\n \"\n a = @d[1, @d.size - 1]\n a.each_with_index do |e, i|\n res << e.to_s << ' '\n if t == i && i < @leaf_size\n res << \"\\n \"\n t = t * 2 + 2\n end\n end\n res\n end\nend\n\nmain"}], "negative_code": [{"source_code": "DEBUG = false\nMOD = 10**9+7\nYESNO = %w(Yes No)\n\ndef main\n t = int\n t.times do\n n = int\n a = ints\n\n seg = Segtree.new(a, 0) { |x, y| max(x, y) }\n sum = a.sum\n\n ans_min = 2e9\n n.times do |i|\n othermax = max(seg.prod(0, i), seg.prod(i+1, n))\n diff = othermax * (n-1) - sum\n diff %= n - 1 if diff < 0\n ans_min = min(ans_min, diff)\n end\n\n puts ans_min\n end\nend\n\ndef int; gets.to_i; end\ndef ints; gets.split.map &:to_i; end\ndef float; gets.to_f; end\ndef floats; gets.split.map &:to_f; end\ndef array(&convert); gets.split.map(&convert); end\ndef string; gets.chomp; end\ndef rep(n, &b); Array.new(n, &b); end\ndef yes; puts YESNO[0]; end\ndef no; puts YESNO[1]; end\ndef yesno t; t ? yes : no; end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } }; end\ndef sorted_uniq(xs); x = nil; xs.filter! { |y| c = x === y; x = y; !c }; end\ndef max(*xs); xs.max; end\ndef min(*xs); xs.min; end\ndef minmax(*xs); xs.minmax; end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w }; end\ndef debug(x); if DEBUG; STDERR.puts (block_given? ? yield(x) : x).inspect; end; x; end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid; end\ndef if_debug; yield if DEBUG; end\n\ndef div_ceil(x, y); (x + y - 1) / y; end\ndef gcd(*xs); xs.inject(0) { |y, x| y.gcd(x) }; end\ndef factorial(n, mod); (2..n).inject(1) { |f, x| f * x % mod }; end\ndef cumsum(xs); ys = [0]; xs.each { |x| ys << x + ys[-1] }; ys; end\ndef cumdiff(ys); xs = []; xs.inject { |x, y| xs << (d = y - x); d }; end\ndef cumfold(ys, range); r = range.end; r -= 1 if range.exclusive_end?; ys[r] - ys[range.begin-1]; end\ndef mod_inv(x, mod); x.pow(mod-2, mod); end\ndef mod_div(x, y, mod); x * mod_inv(y, mod) % mod; end\ndef bitbrute(size, &block); (1<> i) }\n end\n\n def get(pos)\n @d[@leaf_size + pos]\n end\n\n def prod(l, r)\n return @e if l == r\n\n sml = @e\n smr = @e\n l += @leaf_size\n r += @leaf_size\n\n while l < r\n if l[0] == 1\n sml = @op.call(sml, @d[l])\n l += 1\n end\n if r[0] == 1\n r -= 1\n smr = @op.call(@d[r], smr)\n end\n l /= 2\n r /= 2\n end\n\n @op.call(sml, smr)\n end\n\n def all_prod\n @d[1]\n end\n\n def max_right(l, &block)\n return @n if l == @n\n\n f = proc(&block)\n\n l += @leaf_size\n sm = @e\n loop do\n l /= 2 while l.even?\n unless f.call(@op.call(sm, @d[l]))\n while l < @leaf_size\n l *= 2\n if f.call(@op.call(sm, @d[l]))\n sm = @op.call(sm, @d[l])\n l += 1\n end\n end\n\n return l - @leaf_size\n end\n\n sm = @op.call(sm, @d[l])\n l += 1\n break if (l & -l) == l\n end\n\n @n\n end\n\n def min_left(r, &block)\n return 0 if r == 0\n\n f = proc(&block)\n\n r += @leaf_size\n sm = @e\n loop do\n r -= 1\n r /= 2 while r > 1 && r.odd?\n unless f.call(@op.call(@d[r], sm))\n while r < @leaf_size\n r = r * 2 + 1\n if f.call(@op.call(@d[r], sm))\n sm = @op.call(@d[r], sm)\n r -= 1\n end\n end\n\n return r + 1 - @leaf_size\n end\n\n sm = @op.call(@d[r], sm)\n break if (r & -r) == r\n end\n\n 0\n end\n\n def update(k)\n @d[k] = @op.call(@d[2 * k], @d[2 * k + 1])\n end\n\n def inspect\n t = 0\n res = \"SegmentTree @e = #{@e}, @n = #{@n}, @leaf_size = #{@leaf_size} @op = #{@op}\\n \"\n a = @d[1, @d.size - 1]\n a.each_with_index do |e, i|\n res << e.to_s << ' '\n if t == i && i < @leaf_size\n res << \"\\n \"\n t = t * 2 + 2\n end\n end\n res\n end\nend\n\nmain"}, {"source_code": "DEBUG = false\nMOD = 10**9+7\nYESNO = %w(Yes No)\n\ndef main\n t = int\n t.times do\n n = int\n a = ints\n\n cumax1 = [0] + a\n 1.upto(n) { |i| cumax1[i] = cumax1[i-1] if cumax1[i] < cumax1[i-1] }\n cumax2 = a + [0]\n (n-1).downto(0) { |i| cumax1[i] = cumax1[i+1] if cumax1[i] < cumax1[i+1] }\n sum = a.sum\n\n ans_min = 2e9\n n.times do |i|\n othermax = max(cumax1[i], cumax2[i+1])\n diff = othermax * (n-1) - sum\n diff %= n - 1 if diff < 0\n ans_min = min(ans_min, diff)\n end\n\n puts ans_min\n end\nend\n\ndef int; gets.to_i; end\ndef ints; gets.split.map &:to_i; end\ndef float; gets.to_f; end\ndef floats; gets.split.map &:to_f; end\ndef array(&convert); gets.split.map(&convert); end\ndef string; gets.chomp; end\ndef rep(n, &b); Array.new(n, &b); end\ndef yes; puts YESNO[0]; end\ndef no; puts YESNO[1]; end\ndef yesno t; t ? yes : no; end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } }; end\ndef sorted_uniq(xs); x = nil; xs.filter! { |y| c = x === y; x = y; !c }; end\ndef max(*xs); xs.max; end\ndef min(*xs); xs.min; end\ndef minmax(*xs); xs.minmax; end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w }; end\ndef debug(x); if DEBUG; STDERR.puts (block_given? ? yield(x) : x).inspect; end; x; end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid; end\ndef if_debug; yield if DEBUG; end\n\ndef div_ceil(x, y); (x + y - 1) / y; end\ndef gcd(*xs); xs.inject(0) { |y, x| y.gcd(x) }; end\ndef factorial(n, mod); (2..n).inject(1) { |f, x| f * x % mod }; end\ndef cumsum(xs); ys = [0]; xs.each { |x| ys << x + ys[-1] }; ys; end\ndef cumdiff(ys); xs = []; xs.inject { |x, y| xs << (d = y - x); d }; end\ndef cumfold(ys, range); r = range.end; r -= 1 if range.exclusive_end?; ys[r] - ys[range.begin-1]; end\ndef mod_inv(x, mod); x.pow(mod-2, mod); end\ndef mod_div(x, y, mod); x * mod_inv(y, mod) % mod; end\ndef bitbrute(size, &block); (1<> i) }\n end\n\n def get(pos)\n @d[@leaf_size + pos]\n end\n\n def prod(l, r)\n return @e if l == r\n\n sml = @e\n smr = @e\n l += @leaf_size\n r += @leaf_size\n\n while l < r\n if l[0] == 1\n sml = @op.call(sml, @d[l])\n l += 1\n end\n if r[0] == 1\n r -= 1\n smr = @op.call(@d[r], smr)\n end\n l /= 2\n r /= 2\n end\n\n @op.call(sml, smr)\n end\n\n def all_prod\n @d[1]\n end\n\n def max_right(l, &block)\n return @n if l == @n\n\n f = proc(&block)\n\n l += @leaf_size\n sm = @e\n loop do\n l /= 2 while l.even?\n unless f.call(@op.call(sm, @d[l]))\n while l < @leaf_size\n l *= 2\n if f.call(@op.call(sm, @d[l]))\n sm = @op.call(sm, @d[l])\n l += 1\n end\n end\n\n return l - @leaf_size\n end\n\n sm = @op.call(sm, @d[l])\n l += 1\n break if (l & -l) == l\n end\n\n @n\n end\n\n def min_left(r, &block)\n return 0 if r == 0\n\n f = proc(&block)\n\n r += @leaf_size\n sm = @e\n loop do\n r -= 1\n r /= 2 while r > 1 && r.odd?\n unless f.call(@op.call(@d[r], sm))\n while r < @leaf_size\n r = r * 2 + 1\n if f.call(@op.call(@d[r], sm))\n sm = @op.call(@d[r], sm)\n r -= 1\n end\n end\n\n return r + 1 - @leaf_size\n end\n\n sm = @op.call(@d[r], sm)\n break if (r & -r) == r\n end\n\n 0\n end\n\n def update(k)\n @d[k] = @op.call(@d[2 * k], @d[2 * k + 1])\n end\n\n def inspect\n t = 0\n res = \"SegmentTree @e = #{@e}, @n = #{@n}, @leaf_size = #{@leaf_size} @op = #{@op}\\n \"\n a = @d[1, @d.size - 1]\n a.each_with_index do |e, i|\n res << e.to_s << ' '\n if t == i && i < @leaf_size\n res << \"\\n \"\n t = t * 2 + 2\n end\n end\n res\n end\nend\n\nmain"}], "src_uid": "e75b88ce4341062c20b6014da1152d29"} {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nI = ->{gets.split.map(&:to_i)}\nm, k = I[]\nf = I[]\nn, _ = I[]\na = Array.new(n){\n I[]\n I[]\n b = I[]\n x = b.count{|_| f.index(_)}\n y = b.count(0)\n [[x + y, k].min, [x, b.size - (m - k)].max]\n}\nputs a.map{|i|\n a.all?{|j| i === j || i[1] >= j[0]} ?\n 0 :\n a.all?{|j| i[0] >= j[1]} ? 2 : 1\n} * \"\\n\"\n\n", "positive_code": [{"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nI = ->{gets.split.map(&:to_i)}\nm, k = I[]\nf = I[]\nn, _ = I[]\na = Array.new(n){\n I[]\n I[]\n b = I[]\n x = b.count{|_| f.index(_)}\n y = b.count(0)\n [[x + y, k].min, [x, b.size - (m - k)].max]\n}\nputs a.map{|i|\n a.all?{|j| i === j || i[1] >= j[0]} ?\n 0 :\n a.all?{|j| i[0] >= j[1]} ? 2 : 1\n} * \"\\n\"\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nI = ->{gets.split.map(&:to_i)}\nm, k = I[]\nf = I[]\nn, _ = I[]\na = Array.new(n){\n I[]\n I[]\n b = I[]\n x = b.count{|_| f.index(_)}\n y = b.count(0)\n [[x + y, k].min, [x, b.size - (m - k)].max]\n}\nputs a.map{|i|\n a.all?{|j| i === j || i[1] >= j[0]} ?\n 0 :\n a.all?{|j| i[0] >= j[1]} ? 2 : 1\n} * \"\\n\"\n\n"}, {"source_code": "=begin\n , \\ / ,\n / \\ )\\__/( / \\\n / \\ (_\\ /_) / \\\n ____/_____\\__\\@ @/___/_____\\____\n | |\\../| |\n | \\VV/ |\n | ------hoi------- |\n |_________________________________|\n | /\\ / \\\\ \\ /\\ |\n | / V )) V \\ |\n |/ ` // ' \\|\n ` V '\n=end\n\n$stdin = open('input.txt')\n$> = open('output.txt', 'w')\n\n\nI = ->{gets.split.map(&:to_i)}\nm, k = I[]\nf = I[]\nn, _ = I[]\na = Array.new(n){\n I[]\n I[]\n b = I[]\n x = b.count{|_| f.index(_)}\n y = b.count(0)\n [[x + y, k].min, [x, b.size - (m - k)].max]\n}\nputs a.map{|i|\n a.all?{|j| i === j || i[1] >= j[0]} ?\n 0 :\n a.all?{|j| i[0] >= j[1]} ? 2 : 1\n} * \"\\n\" "}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nI = ->{gets.split.map(&:to_i)}\nm, k = I[]\nf = I[]\nn, _ = I[]\na = Array.new(n){\n I[]\n I[]\n b = I[]\n x = b.count{|_| f.index(_)}\n y = b.count(0)\n [[x + y, k].min, [x, b.size - (m - k)].max]\n}\nputs a.map{|i|\n a.all?{|j| i === j || i[1] >= j[0]} ?\n 0 :\n a.all?{|j| i[0] >= j[1]} ? 2 : 1\n} * \"\\n\"\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nI = ->{gets.split.map(&:to_i)}\nm, k = I[]\nf = I[]\nn, _ = I[]\na = Array.new(n){\n I[]\n I[]\n b = I[]\n x = b.count{|_| f.index(_)}\n y = b.count(0)\n [[x + y, k].min, [x, b.size - (m - k)].max]\n}\nputs a.map{|i|\n a.all?{|j| i === j || i[1] >= j[0]} ?\n 0 :\n a.all?{|j| i[0] >= j[1]} ? 2 : 1\n} * \"\\n\"\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n I = ->{gets.split.map(&:to_i)}\nm, k = I[]\nf = I[]\nn, _ = I[]\na = Array.new(n){\n I[]\n I[]\n b = I[]\n x = b.count{|_| f.index(_)}\n y = b.count(0)\n [[x + y, k].min, [x, b.size - (m - k)].max]\n}\nputs a.map{|i|\n a.all?{|j| i === j || i[1] >= j[0]} ?\n 0 :\n a.all?{|j| i[0] >= j[1]} ? 2 : 1\n} * \"\\n\""}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nI = ->{gets.split.map(&:to_i)}\nm, k = I[]\nf = I[]\nn, _ = I[]\na = Array.new(n){\n I[]\n I[]\n b = I[]\n x = b.count{|_| f.index(_)}\n y = b.count(0)\n [[x + y, k].min, [x, b.size - (m - k)].max]\n}\nputs a.map{|i|\n a.all?{|j| i === j || i[1] >= j[0]} ?\n 0 :\n a.all?{|j| i[0] >= j[1]} ? 2 : 1\n} * \"\\n\"\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nI = ->{gets.split.map(&:to_i)}\nm, k = I[]\nf = I[]\nn, _ = I[]\na = Array.new(n){\n I[]\n I[]\n b = I[]\n x = b.count{|_| f.index(_)}\n y = b.count(0)\n [[x + y, k].min, [x, b.size - (m - k)].max]\n}\nputs a.map{|i|\n a.all?{|j| i === j || i[1] >= j[0]} ?\n 0 :\n a.all?{|j| i[0] >= j[1]} ? 2 : 1\n} * \"\\n\"\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nI = ->{gets.split.map(&:to_i)}\nm, k = I[]\nf = I[]\nn, _ = I[]\na = Array.new(n){\n I[]\n I[]\n b = I[]\n x = b.count{|_| f.index(_)}\n y = b.count(0)\n [[x + y, k].min, [x, b.size - (m - k)].max]\n}\nputs a.map{|i|\n a.all?{|j| i === j || i[1] >= j[0]} ?\n 0 :\n a.all?{|j| i[0] >= j[1]} ? 2 : 1\n} * \"\\n\"\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nI = ->{gets.split.map(&:to_i)}\nm, k = I[]\nf = I[]\nn, _ = I[]\na = Array.new(n){\n I[]\n I[]\n b = I[]\n x = b.count{|_| f.index(_)}\n y = b.count(0)\n [[x + y, k].min, [x, b.size - (m - k)].max]\n}\nputs a.map{|i|\n a.all?{|j| i === j || i[1] >= j[0]} ?\n 0 :\n a.all?{|j| i[0] >= j[1]} ? 2 : 1\n} * \"\\n\"\n\n"}], "negative_code": [], "src_uid": "93437df101a317c2306b37bf020a5012"} {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n arr = []\n n.times do |i|\n arr << i+1\n end\n ans << arr\nend\nans.each do |ar|\n ar.each do |x|\n print \"#{x} \"\n end\n puts \"\"\nend", "positive_code": [{"source_code": "gets.to_i.times{|s|puts (1..gets.to_i).to_a.join(\" \")}"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n n = gets.chomp.to_i\n n.downto (1) do |i|\n print i\n if i != 1\n print \" \"\n elsif i == 1\n print \"\\n\"\n end\n end\nend"}], "negative_code": [], "src_uid": "1b3ac752bc9c0b5e20a76f028d4b3c15"} {"source_code": "require 'set'\n\ndef solve arr, k\n return [arr.length, arr] if arr.length == k\n uniq = arr.to_set\n return [-1, nil] if uniq.length > k\n res = []\n expect = uniq.to_a\n expect << 1 while expect.length < k\n idx = 0\n iter = 0\n arr.each do |i|\n until i == expect[idx % k]\n res << expect[idx % k]\n idx += 1\n end\n res << i\n idx += 1\n end\n [res.length, res]\nend\n\nt = STDIN.gets.chomp.to_i\n\n(1..t).each do |i|\n n, k = STDIN.gets.chomp.split.map {|i| i.to_i}\n arr = STDIN.gets.chomp.split.map {|i| i.to_i}\n res = solve arr, k\n puts res[0]\n puts res[1].join(\" \") unless res[0] == -1\nend\n", "positive_code": [{"source_code": "require 'set'\n\n$cpp = []\ndef solve arr, k\n return [arr.length, arr] if arr.length == k\n uniq = arr.to_set\n return [-1, nil] if uniq.length > k\n expect = uniq.to_a\n expect << 1 while expect.length < k\n idx = 0\n iter = 0\n arr.each do |i|\n until i == expect[idx % k]\n $cpp << expect[idx % k]\n idx += 1\n end\n $cpp << i\n idx += 1\n end\n [$cpp.length, $cpp]\nend\n\nt = STDIN.gets.chomp.to_i\n\n(1..t).each do |i|\n n, k = STDIN.gets.chomp.split.map {|i| i.to_i}\n arr = STDIN.gets.chomp.split.map {|i| i.to_i}\n res = solve arr, k\n puts res[0]\n puts res[1].join(\" \") unless res[0] == -1\n $cpp = []\nend\n"}], "negative_code": [], "src_uid": "80d4b2d01215b12ebd89b8ee2d1ac6ed"} {"source_code": "def normalize(a)\n a.length.times do |i|\n l = a[i].index('1')\n r = a[i].rindex('1')\n l = l + 1 if l != nil\n r = r + 1 if r != nil\n a[i] = {:l => l, :r => r}\n end\nend\n\n\nn, m = gets.chomp.split.map(&:to_i)\nm += 2\na = []\ncur_pos = 1\nans = n * m\n\nvars = [:l, :r].repeated_permutation(n).to_a\n\nn.times do |x|\n a.push(gets.chomp)\nend\n\na.reverse!\nnormalize(a)\n\nwhile n > 0 and a[-1][:l] == nil\n n -= 1\n a.pop\nend\n\nif n == 0\n puts 0\n exit\nend\n\nvars.length.times do |i|\n if vars[i][0] != :r\n lans = 0\n (1..n-1).each do |j|\n if vars[i][j-1] != vars[i][j]\n lans += (m - 1)\n elsif a[j-1][:l] == nil\n lans += 0\n elsif vars[i][j] == :r\n lans += (m - a[j-1][:l]) * 2\n elsif vars[i][j] == :l\n lans += (a[j-1][:r] - 1) * 2\n end\n end\n if a[n-1][:l] == nil\n lans += 0\n elsif vars[i][n-1] == :r\n lans += (m - a[n-1][:l])\n else\n lans += (a[n-1][:r] - 1)\n end\n if lans < ans\n ans = lans\n end\n end\nend\n\nans += n - 1\nputs ans\n", "positive_code": [{"source_code": "N, M = gets.chomp.split(\" \").map(&:to_i)\n$bldg = Array.new()\n\nnflr = 0\nN.times do\n flr = gets.chomp.split(\"\").map(&:to_i)\n $bldg << flr\n nflr += 1 if flr.include?(1)\nend\n$bldg.reverse!\n$ret = []\n\ndef hausmeister(i, s, t, last)\n curr = 0\n flr = $bldg[i]\n if flr.include?(1) then\n if s == 0 then\n pos = flr.rindex(1)\n curr += pos\n else\n pos = flr.index(1)\n curr += (M + 2 - pos - 1)\n end\n left = pos + 1\n right = M + 2 - pos\n if i == N - 1 then\n $ret << t + curr\n return t + curr\n end\n hausmeister(i+1, 0, t + curr + left, left)\n hausmeister(i+1, -1, t + curr + right, right)\n else\n if i == N - 1 then\n $ret << t - last\n return t - last\n end\n if s == 0 then\n pos = 0\n else\n pos = M + 1\n end\n left = pos + 1\n right = M + 2 - pos\n hausmeister(i+1, 0, t + left, last + left)\n hausmeister(i+1, -1, t + right, last + right)\n end\nend\nif nflr > 0 then\n hausmeister(0, 0, 0, 0)\n puts $ret.min\nelse\n puts 0\nend\n"}], "negative_code": [{"source_code": "n, M = gets.chomp.split(\" \").map(&:to_i)\n$bldg = Array.new()\nn.times do\n flr = gets.chomp.split(\"\").map(&:to_i)\n $bldg << flr if flr.include?(1)\nend\n$bldg.reverse!\n$ret = []\nN = $bldg.length\ndef hausmeister(i, s, t)\n curr = 0\n flr = $bldg[i]\n\n if flr.include?(1) then\n if s == 0 then\n pos = flr.rindex(1)\n curr += pos\n else\n pos = flr.index(1)\n curr += (M + 2 - pos - 1)\n end\n left = pos + 1\n right = M + 2 - pos\n if i == N - 1 then\n $ret << t + curr\n return t + curr\n end\n hausmeister(i+1, 0, t + curr + left)\n hausmeister(i+1, -1, t + curr + right)\n else\n if i == N - 1 then\n $ret << t\n return t + curr\n end\n if s == 0 then\n pos = 0\n else\n pos = M + 1\n end\n left = pos + 1\n right = M + 2 - pos\n hausmeister(i+1, 0, t + left)\n hausmeister(i+1, -1, t + right)\n end\nend\nif N > 0 then\n hausmeister(0, 0, 0)\n puts $ret.min\nelse\n puts 0\nend"}, {"source_code": "N, M = gets.chomp.split(\" \").map(&:to_i)\n$bldg = Array.new()\nN.times do\n flr = gets.chomp.split(\"\").map(&:to_i)\n $bldg << flr\nend\n$bldg.reverse!\n$ret = []\ndef hausmeister(i, s, t)\n curr = 0\n flr = $bldg[i]\n\n nlight = flr.inject(:+)\n if nlight > 0 then\n if s == 0 then\n pos = flr.rindex(1)\n curr += pos\n else\n pos = flr.index(1)\n curr += (M + 2 - pos - 1)\n end\n left = pos + 1\n right = M + 2 - pos\n if i == N - 1 then\n $ret << t + curr\n return t + curr\n end\n hausmeister(i+1, 0, t + curr + left)\n hausmeister(i+1, -1, t + curr + right)\n else\n if i == N - 1 then\n $ret << t + curr\n return t + curr\n end\n if s == 0 then\n pos = 0\n else\n pos = M + 1\n end\n left = pos + 1\n right = M + 2 - pos\n hausmeister(i+1, 0, t + left)\n hausmeister(i+1, -1, t + right)\n end\nend\n\nhausmeister(0, 0, 0)\nputs $ret.min"}, {"source_code": "N, M = gets.chomp.split(\" \").map(&:to_i)\n$bldg = Array.new()\n\nnflr = 0\nN.times do\n flr = gets.chomp.split(\"\").map(&:to_i)\n $bldg << flr\n nflr += 1 if flr.include?(1)\nend\n$bldg.reverse!\n$ret = []\n\ndef hausmeister(i, s, t, last)\n curr = 0\n flr = $bldg[i]\n if flr.include?(1) then\n if s == 0 then\n pos = flr.rindex(1)\n curr += pos\n else\n pos = flr.index(1)\n curr += (M + 2 - pos - 1)\n end\n left = pos + 1\n right = M + 2 - pos\n if i == N - 1 then\n $ret << t + curr\n return t + curr\n end\n hausmeister(i+1, 0, t + curr + left, left)\n hausmeister(i+1, -1, t + curr + right, right)\n else\n if i == N - 1 then\n $ret << t - last\n return t - last\n end\n if s == 0 then\n pos = 0\n else\n pos = M + 1\n end\n left = pos + 1\n right = M + 2 - pos\n hausmeister(i+1, 0, t + left, left)\n hausmeister(i+1, -1, t + right, right)\n end\nend\nif nflr > 0 then\n hausmeister(0, 0, 0, 0)\n puts $ret.min\nelse\n puts 0\nend\n"}], "src_uid": "55070f8e5dba8a6ec669a53a169e557d"} {"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}\np (a.count(a.max)**n)%1000000007\n", "positive_code": [{"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}\np (a.count(a.max)**n)%1000000007"}, {"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}\np (a.count(a.max)**n)%1000000007\n"}, {"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}\np (a.count(a.max)**n)%1000000007\n"}, {"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}\np (a.count(a.max)**n)%1000000007\n"}, {"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}\np (a.count(a.max)**n)%1000000007\n"}, {"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}\np (a.count(a.max)**n)%1000000007\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nm = [s.count(\"A\"), s.count(\"C\"), s.count(\"T\"), s.count(\"G\")]\ncntmax = m.max\ncnt = 0\nm.each{|mm| cnt += 1 if mm == cntmax}\nputs (cnt**n)%(10**9+7)\n"}, {"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}\np (a.count(a.max)**n)%1000000007\n"}, {"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}\np (a.count(a.max)**n)%1000000007\n"}, {"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}\np (a.count(a.max)**n)%1000000007"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nm = [s.count(\"A\"), s.count(\"C\"), s.count(\"T\"), s.count(\"G\")]\ncntmax = m.max\ncnt = 0\nm.each{|mm| cnt += 1 if mm == cntmax}\nputs (cnt**n)%(10**9+7)\n"}], "negative_code": [{"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}.sort-[0]\nb=a.chunk{|i|i}\nc=b.map{|k,v|[k,k*v.size]}\nd=b.map{|k,v|v.size**(k*v.size)}.inject(:*)\np (1..n).inject(:*)/c.map{|_,i|(1..i).inject(:*)}.inject(:*)*d\n"}, {"source_code": "n=gets.to_i\ns=gets\na=\"ACGT\".chars.map{|c|s.count(c)}.sort-[0]\nb=a.chunk{|i|i}\nc=b.map{|k,v|[k,k*v.size]}\nd=b.map{|k,v|v.size**(k*v.size)}.inject(:*)\np (1..n).inject(:*)/c.map{|_,i|(1..i).inject(:*)}.inject(:*)*d%1000000007\n"}], "src_uid": "f35c042f23747988f65c5b5e8d5ddacd"} {"source_code": "\ndef init(n)\n n.times do |i|\n Parent[i] = i\n Next[i] = nil\n Last[i] = i\n Rank[i] = 0\n end\nend\n\ndef find(x)\n if Parent[x] == x\n return x\n else\n return Parent[x] = find(Parent[x])\n end\nend\n\ndef unite(x,y)\n x,y = find(x),find(y)\n return if x==y\n\n x,y = y,x if Rank[x] < Rank[y]\n Rank[x] += 1 if Rank[x] == Rank[y]\n\n Parent[y] = x;\n Next[Last[x]] = y\n Last[x] = Last[y]\nend\n\nn = gets.to_i\nParent,Rank,Next,Last = [],[],[],[]\ninit(n+1)\n\n(n-1).times do\n a,b = gets.split.map(&:to_i)\n unite(a,b)\nend\nt = find(1)\nn.times do |i|\n print \"#{t}\"\n print \" \" if i < n-1\n t = Next[t]\nend\n\n", "positive_code": [{"source_code": "class Base\n attr_accessor :parent\n def root\n parent ? parent.root : self\n end\nend\n\nclass Integer\n def size\n 1\n end\n\n def parent=(a)\n end\nend\n\nclass Node < Base\n attr_reader :size, :items\n def initialize(items)\n @size = items.map(&:size).reduce(&:+)\n @items = items\n @items.each do |item|\n item.parent = item\n end\n end\n\n def add(item)\n @items << item\n @size += item.size\n item.parent = self\n self\n end\n\n def merge(b)\n if size >= b.size\n add(b)\n else\n b.add(self)\n end\n end\nend\n\nN = STDIN.gets.to_i\nmap = Array.new(N) { nil }\n\n(N-1).times do |i|\n a,b = STDIN.gets.strip.split.map(&:to_i)\n a -= 1\n b -= 1\n map[a] ||= Node.new([a])\n map[b] ||= Node.new([b])\n map[a].root.merge(map[b].root)\nend\n\ndef print_node(node)\n case node\n when Integer\n print(\"#{node+1} \")\n else\n node.items.each do |item|\n print_node(item)\n end\n end\nend\n\nprint_node(map[0].root)\nputs"}, {"source_code": "DBG = !true\n\ndef edge(x)\n return x if $lbl[x] == -1\n y = edge($lbl[x])\n $lbl[x] = y if y != x\n return y\nend\n\ndef setedge(x,lb)\n if $lbl[x] != -1 && $lbl[x] != lb\n setedge($lbl[x], lb)\n end\n $lbl[x] = lb if lb != x\nend\n\ndef con(x,y)\n p = edge(x)\n q = edge(y)\n setedge(x,$top)\n setedge(y,$top)\n $lbl[p] = $top\n $lbl[q] = $top\n $rev1[$top] = p\n $rev2[$top] = q\n $top += 1\n if DBG\n print $a\n puts \" - a\"\n print $rev1\n puts \" - rev1\"\n print $rev2\n puts \" - rev2\"\n print $lbl\n puts \" - lbl\"\n end\nend\n\ndef pr(y)\n stk = [y]\n while !stk.empty?\n x = stk.pop\n if x >= $n\n stk << ($rev2[x])\n stk << ($rev1[x])\n else\n print \"#{x+1} \"\n end\n end\n puts \"\"\nend\n\n#### main\n\nn = gets.to_i\n$n = n\n$top = n\n$a = Array.new(2*n+1, -1)\n$rev1 = Array.new(2*n+1, -1)\n$rev2 = Array.new(2*n+1, -1)\n$lbl = Array.new(2*n+1, -1)\n\nfor i in 1...n\n x,y = gets.split.map{|z| z.to_i}\n puts \"do #{x-1} #{y-1}\" if DBG\n con(x-1, y-1)\nend\npr($top-1)\n"}], "negative_code": [{"source_code": "\ndef init(n)\n n.times do |i|\n Parent[i] = i\n Member[i] =[i]\n Rank[i] = 0\n end\nend\n\ndef find(x)\n if Parent[x] == x\n return x\n else\n return Parent[x] = find(Parent[x])\n end\nend\n\ndef unite(x,y)\n x,y = find(x),find(y)\n return if x==y\n\n if Rank[x] < Rank[y]\n Parent[x] = y\n Member[y] += Member[x]\n else\n Parent[y] = x;\n Member[x] += Member[y]\n Rank[x] += 1 if Rank[x] == Rank[y]\n end\nend\n\nn = gets.to_i\nParent = []*(n+1)\nRank = []*(n+1)\nMember = []*(n+1)\ninit(n+1)\n\n(n-1).times do\n a,b = gets.split.map(&:to_i)\n unite(a,b)\nend\nn.times do |i|\n print \"#{Member[1][i]}\"\n print \" \" if i < n-1\nend\n\n"}], "src_uid": "2c665f95370058bc7fdec405db7d155d"} {"source_code": "r=lambda{gets.split.map{|i| i.to_i}}\nn,m,k=r.call\na=[]\ns=[0]*m\nb=[0]*n\nn.times{a<= 2 and $array[-1] == $array[-2]\n $array.pop\n $array.pop\n collapse\n end\nend\ns = gets.chomp\n$array = []\ns.split('').each do |c|\n $array.push c\n collapse\nend\nputs $array*''"}, {"source_code": "s=%w()\ngets.scan(/./).each{|i| s[-1] == i ? s.pop : s<= rh\n cost = (perimeter.to_f / ((pl / rh) * pw)).ceil * price\n best = [best, cost].min\n end\n end\n result += best\nend\nputs result\n", "positive_code": [{"source_code": "a = gets.to_i.times.map{gets.split.map{|i| i.to_i}}\nb = gets.to_i.times.map{gets.split.map{|i| i.to_i}}\nr = 0\na.each{ |a|\n\ts = 1 << 20\n\tp = (a[0] + a[1]) * 2\n\tb.each{ |b|\n\t\tif b[0] >= a[2]\n\t\t\th = b[0] / a[2] * b[1]\n\t\t\tw = (p - 1) / h + 1\n\t\t\ts = [s, w * b[2]].min\n\t\tend\n\t}\n\tr += s\n}\nputs r\n"}, {"source_code": "#f = File.open(\"b.in\", \"r\")\nn = gets.to_i\na = Array.new(n) {Array.new(3)}\nfor i in 0...n\n\ta[i] = gets.split.map{|i| i.to_i}\nend\nm = gets.to_i\nb = Array.new(m) {Array.new(3)}\nr = 0\nfor i in 0...m\n\tb[i] = gets.split.map{|i| i.to_i}\nend\nfor i in 0...n\n\ts = 1 << 20\n\tp = a[i][0] * 2 + a[i][1] * 2\n\tfor j in 0...m\n\t\tif b[j][0] >= a[i][2]\n\t\t\th = b[j][0] / a[i][2] * b[j][1]\n\t\t\tw = (p - 1) / h + 1\n\t\t\ts = [s, w * b[j][2]].min\n\t\tend\n\tend\n\tr += s\nend\nputs r\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map{|i| i.to_i}}\nm = gets.to_i\nb = m.times.map{gets.split.map{|i| i.to_i}}\nr = 0\nfor i in 0...n\n\ts = 1 << 20\n\tp = (a[i][0] + a[i][1]) * 2\n\tfor j in 0...m\n\t\tif b[j][0] >= a[i][2]\n\t\t\th = b[j][0] / a[i][2] * b[j][1]\n\t\t\tw = (p - 1) / h + 1\n\t\t\ts = [s, w * b[j][2]].min\n\t\tend\n\tend\n\tr += s\nend\nputs r\n"}, {"source_code": "n = STDIN.readline.to_i\nrooms = n.times.map { STDIN.readline.split.map {|s| s.to_i } }\nm = STDIN.readline.to_i\nwallpapers = m.times.map { STDIN.readline.split.map {|s| s.to_i } }\ntotal = 0\n\nrooms.each do |length, width, height|\n circumference = 2*(length + width)\n best = -1\n wallpapers.each do |length, width, price|\n strips = (circumference + width - 1) / width\n strips_per_roll = length / height\n next if strips_per_roll == 0\n rolls = (strips + strips_per_roll - 1) / strips_per_roll\n cost = rolls * price\n #puts '%d * %d = %d' % [rolls, price, cost]\n if best == -1 or cost < best\n best = cost\n end\n end\n total += best\nend\n\nputs total\n"}, {"source_code": "#!/usr/bin/ruby\nn = gets.chomp.to_i\nmvys = Array.new(n)\nmsir = Array.new(n)\nmhl = Array.new(n)\ncenacelkem = 0\nfor i in 0..n-1\n\tk = gets.chomp.split(' ')\n\tmsir[i] = k[0].to_i\n\tmhl[i] = k[1].to_i\n\tmvys[i] = k[2].to_i\n\t#puts(k)\nend\nm = gets.chomp.to_i\ntapvys = Array.new(m)\ntapsir = Array.new(m)\ntapcena = Array.new(m)\nfor i in 0..m-1\n\tk = gets.chomp.split(' ')\n\ttapvys[i] = k[0].to_i\n\t#puts tapvys[i]\n\ttapsir[i] = k[1].to_i\n\ttapcena[i] = k[2].to_i\nend\nfor i in 0..n-1\n\tobvod = msir[i]+msir[i]+mhl[i]+mhl[i]\n\tvys = mvys[i]\n\t#puts obvod\n\tcenamin = 2147486646\n\tfor j in 0..m-1\n\t\tvtap = tapvys[j]\n\t\tstap = tapsir[j]\n\t\tctap = tapcena[j]\n\t\t#puts vtap\n\t\tif vtap >= vys\n\t\t\t#puts((vtap/vys).to_s)\n\t\t\tprouzku = vtap/vys\n\t\t\trolem = prouzku*stap\n\t\t\t#puts rolem\n\t\t\troli = (obvod/rolem.to_f).ceil\n\t\t\tcena = roli*ctap;\n\t\t\tif cenamin > cena\n\t\t\t\tcenamin = cena\n\t\t\tend\n\t\tend\n\tend\n\tcenacelkem = cenacelkem + cenamin\nend\nputs cenacelkem\n"}, {"source_code": "n = gets.chomp.to_i\nrooms = Array.new(n) { gets.split.collect{|x| x.to_i} }\n\nm = gets.chomp.to_i\ntypes = Array.new(m) { gets.split.collect{|x| x.to_i} }\n \nsum_cost = 0\nrooms.each{|room|\n l,w,h = room\n min_cost = nil\n \n types.each{|type|\n lt,wt,c = type\n cols = lt / h\n next if cols == 0\n \n cols_req = ((2 * l + 2 * w) / wt.to_f).ceil\n cost = c * (cols_req / cols.to_f).ceil\n \n min_cost = cost if min_cost.nil? or cost < min_cost\n }\n sum_cost += min_cost\n}\n\nputs sum_cost"}, {"source_code": "n=gets.to_i\nrooms=n.times.map{gets.split.map(&:to_i)}\nm=gets.to_i\npapers=m.times.map{gets.split.map(&:to_i)}\n\ns=0\nrooms.each{|l,w,h|\n\tperimeter=(l+w)*2\n\ts+=papers.map{|p_l,p_w,p_p|\n\t\tif p_l 0\n\t\t\trollcount += 1\n\t\tend\n\t\twk = rollcount * ma[j][2]\n\t\tif sumwk < 0 || sumwk > wk\n\t\t\tsumwk = wk\n\t\tend\n\tend\n\tsum += sumwk\nend\nputs sum\n"}, {"source_code": "n = gets.to_i\na = Array.new(n) do\n l, w, h = gets.split.map(&:to_i)\n [h, 2 * (l + w)]\nend\nm = gets.to_i\nb = Array.new(m) do\n gets.split.map(&:to_i)\nend\n\ns = 0\na.each do |x, y|\n t = 9e9\n b.each do |u, v, w|\n u /= x\n next if u == 0\n v *= u\n t = [t, (y + v - 1) / v * w].min\n end\n s += t\nend\np s\n"}, {"source_code": "n=gets.split[0].to_i\nroom=Array.new()\nn.times{ room.push(gets.split.map(&:to_i)) }\nm=gets.split[0].to_i\npaper=Array.new()\nm.times{ paper.push(gets.split.map(&:to_i)) }\n\nans=0\nroom.each{|a|\n room_ans=[]\n paper.each{|p|\n t=2*(a[0]+a[1])\n next if p[0]= a[2] }\n\tr += s\n}\nputs r\n"}], "negative_code": [{"source_code": "#f = File.open(\"b.in\", \"r\")\nn = gets.to_i\na = Array.new(n) {Array.new(3)}\nfor i in 0...n\n\ta[i] = gets.split.map{|i| i.to_i}\nend\nm = gets.to_i\nb = Array.new(m) {Array.new(3)}\nr = 0\nfor i in 0...m\n\tb[i] = gets.split.map{|i| i.to_i}\nend\nfor i in 0...n\n\ts = 1 << 20\n\tp = a[i][0] * 2 + a[i][1] * 2\n\tfor j in 0...m\n\t\tif b[j][0] > a[i][2]\n\t\t\th = b[j][0] / a[i][2] * b[j][1]\n\t\t\tw = (p - 1) / h + 1\n\t\t\ts = [s, w * b[j][2]].min\n\t\telse\n\t\t\th = (a[i][2] - 1) / b[j][0] + 1\n\t\t\tw = (p - 1) / b[j][1] + 1\n\t\t\ts = [s, w * b[j][2] * h].min\n\t\tend\n\tend\n\tr += s\nend\nputs r\n"}, {"source_code": "#!/usr/bin/env ruby\n\n\ndef read_ints\n return gets.split.map(&:to_i)\nend\n\nn = gets.to_i\nrooms = []\nn.times do\n rooms << read_ints\nend\n\nm = gets.to_i\npapers = []\nm.times do\n papers << read_ints\nend\n\nrooms.each do |rl, rw, rh|\n perimeter = 2 * (rl + rw)\n best = 10**10\n papers.each do |pl, pw, price|\n if pl >= rh\n cost = (perimeter.to_f / ((pl / rh) * pw)).ceil * price\n best = [best, cost].min\n end\n end\n puts best\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef read_ints\n return gets.split.map(&:to_i)\nend\n\nn = gets.to_i\nrooms = []\nn.times do\n rooms << read_ints\nend\n\nm = gets.to_i\npapers = []\nm.times do\n papers << read_ints\nend\n\nrooms.each do |rl, rw, rh|\n perimeter = 2 * (rl + rw)\n best = 10**10\n papers.each do |pl, pw, price|\n div = pl < rh ? 1 : pl / rh\n mul = pl < rh ? rh / pl : 1\n cost = (perimeter.to_f / (div * pw)).ceil * mul * price\n best = [best, cost].min\n end\n puts best\nend\n\n"}], "src_uid": "29639971c98dd98f0292d994d4433e3a"} {"source_code": "# http://codeforces.com/problemset/problem/551/A\n\nn = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\nsorted_a = a.sort\nresult = {}\n\nfor i in 0..(n - 1)\n if sorted_a[i + 1] != sorted_a[i]\n result[sorted_a[i]] = n - i\n end\nend\n\nfor i in 0..(n - 1)\n print result[a[i]], \" \"\nend\n", "positive_code": [{"source_code": "gets\nx=gets.split.map{|e| e.to_i}\nc=(0..2000).map{0}\nx.each{|e|\n\tc[e]+=1\n}\nans=1\n2000.downto(1){|i|\n\tif c[i]>0 then\n\t\tt=c[i]\n\t\tc[i]=ans\n\t\tans+=t\n\tend\n}\n\nputs x.map{|e|\n\tc[e]\n}*\" \"\n\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(\"\\s\").map.with_index { |e, i| [i, e.to_i] }.sort { |a, b| b[1] <=> a[1] }\n\nbefore = -Float::INFINITY\nposition = 0\nres = []\n\nn.times do |i|\n position = i + 1 unless before == a[i][1]\n res << [a[i][0], position]\n before = a[i][1]\nend\n\nputs res.sort { |a, b| a[0] <=> b[0] }.map { |e| e[1] }.join(\"\\s\")\n"}, {"source_code": "a=Hash[(1..gets.to_i).zip(gets.split.map{|t|t.to_i})]\nputs a.map{|i,ai|1+a.select{|j,aj|(j!=i)&&(aj>ai)}.size}.join(' ')\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ns = a.each_with_index.to_a.sort { |x,y| y <=> x }\nanswer = [0] * n\nt = nil\nlast = nil\ns.each_with_index do |tuple, index|\n if last != tuple[0]\n last = tuple[0]\n t = index + 1\n end\n answer[tuple[1]] = t\n\nend\nputs answer.join ' '"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nar = gets.split.map(&:to_i)\nac = Array.new(2000 + 1) { 0 }\nfor i in ar\n ac[i] += 1\nend\narc = [0]\nacc = 0\nfor i in 1..2000\n acc += ac[i]\n arc << acc\nend\nresults = []\nfor i in ar\n results << 1 + (arc[2000] - arc[i])\nend\nputs results.join(' ')"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.map{|x| a.count{|y| y > x} + 1}\nputs b.join(' ')\n"}, {"source_code": "def solution(n, arr)\n arr2 = arr.sort\n h = {}\n (0...n).each do |i|\n j = i + 1\n while(arr2[j] == arr2[i]) do\n j += 1\n end\n h[arr2[i]] = n - j + 1\n end\n\n puts arr.map{|a| a = h[a]}.join(' ')\nend\n\nsolution(gets.chomp.to_i, gets.split.map(&:to_i))"}, {"source_code": "n = gets().chomp().to_i\nstudent = []\nstudent = gets().split(' ').map {|p| p.to_i}\n\ndef find_max(student)\n n= student.size()\nmaximum =0\nindex =0\nfor i in (0..n-1)\n if student[i]>maximum\n maximum = student[i]\n index = i\n end\nend\n\nreturn maximum,index\nend\n\n\nposition = Array.new(n,0)\n\n\nfound =false\nrating = 1\n\nlast,index = find_max(student)\n\nfor j in (1..n)\n maximum,index = find_max(student)\n\n student[index]=0\n if last > maximum\n position[index]=j\n rating = j\n else\n position[index]=rating\n end\n last = maximum\n=begin\n for i in (0..n-1)\n if student[i]==maximum\n student[i]=0\n position[i]=rating\n found =true\n break\n end\n end\n\n\n if found\n found = false\n else\n puts \"hello\"\n rating = j+1\n end\n=end\nend\n\nposition.each { |p| print \"#{p} \"}\nputs\n"}, {"source_code": "#!/usr/bin/ruby\n#coding:utf-8\n#derived from 3\u5e74C\u7d44\u306e\u6210\u7e3e\u8868\ngets\nm=gets.split.map(&:to_i).each_with_index.to_a\n1.times{|i| # \u5404\u5217\u3092\u9806\u4f4d\u306b\u5909\u63db\n\tm.sort_by!{|e|-e[i]}\n\ta=[] # \u9806\u4f4d\n\trank=1\n\tadd=0\n\ta<m[j][i] # \u70b9\u6570\u304c\u7570\u306a\u3063\u3066\u3044\u305f\u3089\u3001\u540c\u3058\u3060\u3063\u305f\u4eba\u6570\u3092\u9806\u4f4d\u306b\u52a0\u3048\u308b\n\t\t\trank+=add\n\t\t\tadd=0\n\t\tend\n\t\ta< a}\n\nnewScore.each_with_index do |value, index|\n\tif !hash.has_key?(value)\n\t\thash[value] = index + 1\n\tend\nend\n\nscore.each do |value|\n\tprint \"#{hash[value]} \"\nend\n\nputs ''"}, {"source_code": "n = gets.to_i\na = gets.split.map{|r| r.to_i}\nf = Array.new(n)\n\nfor i in 0..n-1\n f[i] = 1\n max = a[i]\n a.each do |x|\n if x>max\n f[i]+=1\n end\n end\nend\nputs f"}, {"source_code": "gets\narr = gets.split.map { |x| x.to_i }\nhashed = Hash.new(0)\narr.uniq.each { |x| hashed[x] = arr.sort.count { |y| y > x } + 1 }\narr.each do |x|\n print hashed[x], \" \" \nend\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.split.map(&:to_i)\narr2 = arr.sort\nnumber = Hash.new\nn.times do |i|\n number[arr2[i]] = i\nend\nn.times do |i|\n print n-number[arr[i]] ; print \" \"\nend"}, {"source_code": "n = gets.split(' ').map(&:to_i)\na = gets.split(' ').map(&:to_i)\nb = a.clone()\nb = b.sort!.reverse\nfor x in a\n b.length.times{ |i|\n if (b[i]==x)\n print i+1\n print ' '\n break\n end\n }\nend"}, {"source_code": "gets\na=1\nputs gets.split.map(&:to_i).each_with_index.sort_by{|r|-r[0]}.chunk{|r|r[0]}.reduce([]){|z,r|z+=r[1].map{|s|[s[1],a]};a+=r[1].size;z}.sort.map{|r|r[1]}*?\\s\n"}], "negative_code": [{"source_code": "def solution(n, arr)\n arr.sort!\n (0...n).each do |index|\n arr[index] = arr[n-1] - arr[index] + 1\n end\n print arr\nend\n\nsolution(gets.chomp.to_i, gets.split.map(&:to_i))"}, {"source_code": "def solution(n, arr)\n arr.sort!\n (0...n).each do |i|\n j = i + 1\n while(arr[j] == arr[i]) do\n j += 1\n end\n arr[i] = n - j + 1\n end\n puts arr.join(' ')\nend\n\nsolution(gets.chomp.to_i, gets.split.map(&:to_i))"}, {"source_code": "gets\narr = gets.chomp.split.join(\"\")\nmax = 0\narr.scan(/0+/) { |x| max = x.length if x.length > max }\nputs arr.split(\"\").count { |x| x == \"1\" } + max\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.split.map(&:to_i)\nnumber = Hash.new\nn.times do |i|\n number[arr[i]] = i\nend\nn.times do |i|\n print n-number[arr[i]] ; print \" \"\nend"}], "src_uid": "a5edbf422616cdac35e95a4f07efc7fd"} {"source_code": "\ufeff# Codeforces Round\n\n=begin\n# A\na, b = gets.split.map(&:to_i)\nc, d = [a, b].min, [a, b].max\nputs \"#{[a, b].min} #{(a - b).abs / 2}\"\n\n# B\nn = gets.to_i\nh = gets.split.map(&:to_i)\nm, a = [0] * (n - 1) + [h[n - 1]], [0] * n\n(n - 2).downto(0) do |i|\n if h[i] <= m[i + 1]\n m[i] = m[i + 1]\n a[i] = m[i] - h[i] + 1\n else\n m[i] = h[i]\n end\nend\nputs a.join(' ')\n=end\n\n# C\nn, k = gets.split.map(&:to_i)\ncmp = ->(x, y) { (y % 10) <=> (x % 10) }\na = gets.split.map(&:to_i).sort(&cmp).map do |x|\n if x % 10 == 0 || k == 0\n x\n else\n d = [10 - x % 10, k].min\n k -= d\n x += d\n end\nend\nans = 0\na.each do |y|\n d = [100 - y, k].min\n k -= d\n ans += (y + d) / 10\nend\nputs ans\n", "positive_code": [{"source_code": "input = STDIN.gets\narr = input.split.map(&:to_i)\n# \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u0432\u044b\u043a\u043e\u0432\nn = arr[0]\n# \u043e\u0447\u043a\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439\nk = arr[1]\n# \u043e\u0447\u043a\u043e\u0432 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u043e\u0440\u043e\u0432\u043d\u0443\n# constant = (k / n).floor\n# \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u043e\u0447\u043a\u0438\ninput = STDIN.gets\nabilities = input.split.map(&:to_i)\n# \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c\nindexes = Hash.new\n\ni = 0\n# n \u0448\u0430\u0433\u043e\u0432\nabilities.each do |item|\n # \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438\n indexes[i] = 10 - item % 10\n i += 1\nend\n# \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e\n# \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\n# ? \u0448\u0430\u0433\u043e\u0432 - \u043d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430\nsort = Hash[indexes.sort_by{|k, v| v}]\n\n# \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0447\u043a\u0438 \u0442\u0430\u043c, \u0433\u0434\u0435 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e,\n# \u0447\u0442\u043e\u0431\u044b \"\u0434\u043e\u0431\u0438\u0442\u044c\" \u0434\u043e \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b, \u043a\u0440\u0430\u0442\u043d\u043e\u0439 10-\u0442\u0438\n# \u0435\u0449\u0451 n \u0448\u0430\u0433\u043e\u0432\nsort.each do |key, value|\n if k - value >= 0\n abilities[key] += value\n k = k - value\n else\n break\n end\nend\n\n# \u0435\u0441\u043b\u0438 \u0435\u0449\u0451 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u043e\u0447\u043a\u0438 - \u0440\u0430\u0437\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u0445 \u043f\u043e \u0432\u0441\u0435\u043c, \u0434\u043e\u0431\u0438\u0432\u0430\u044f \u0434\u043e 100 \u0441\u043a\u043e\u043b\u044c\u043a\u043e\n# \u0441\u043c\u043e\u0436\u0435\u043c\nif k > 0\n abilities.map! { |element|\n if k >= 100 - element\n k = k - (100 - element)\n 100\n else\n prev_k = k\n k = 0\n element + prev_k\n end\n }\nend\n\nrating = 0\n# \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0445\u043e\u0434\n# n \u0448\u0430\u0433\u043e\u0432\nabilities.each do |item|\n if item > 100\n item = 100\n end\n rating += (item * 0.1).floor\nend\n\n# \u0418\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e\n# 3n + ? \u0448\u0430\u0433\u043e\u0432\n# ? - \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430\nputs \"#{rating}\"\n"}, {"source_code": "#!/usr/bin/ruby\nn,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).sort_by{|e|0-e%10}\na.size.times{|i|\n\ty=10-a[i]%10\n\tnext if y==10\n\tx=[y,k].min\n\ta[i]+=x\n\tk-=x\n}\na.size.times{|i|\n\ty=100-a[i]\n\tnext if y==0\n\tx=[y,k].min\n\ta[i]+=x\n\tk-=x\n}\np a.map{|e|e/10}.reduce(:+)"}, {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nk = Integer(input[1])\ninput = gets.chomp.split\nskills = []\nfor i in 0...n\n skills[i] = Integer(input[i])\nend\n\nsum = 0\nsequence = []\nskill = []\nfor i in 0...n\n if skills[i] == 100\n sum += 10\n else\n skill.push(skills[i])\n end\nend\nfor i in 0...skill.length\n sequence[i] = []\n sequence[i][0] = skill[i] / 10\n sequence[i][1] = skill[i] % 10\nend\nsequence = sequence.sort{|x, y| y[1] <=> x[1]}\nfor i in 0...sequence.length\n if 10 - sequence[i][1] < k\n k -= 10 - sequence[i][1]\n sequence[i][1] = 10\n else\n sequence[i][1] += k\n k = 0\n break\n end\nend\nnumbers = []\nfor i in 0...sequence.length\n numbers[i] = 10 * sequence[i][0] + sequence[i][1]\nend\nif k >= 10\n for i in 0...numbers.length\n if k >= 100 - numbers[i]\n k -= 100 - numbers[i]\n numbers[i] = 100\n else\n numbers[i] += k\n k = 0\n break\n end\n end\nend\n\nfor i in 0...numbers.length\n sum += (numbers[i].to_f / 10).floor\nend\nputs sum\n"}, {"source_code": "firstInput = gets.chomp.split(' ').map {|item| item.to_i}\nskillNum, itemNum = firstInput[0], firstInput[1]\nans = 0\nskillLevel = gets.chomp.split(' ').map {|item| item.to_i}\nskillLevel.sort! {|a, b| b % 10 <=> a % 10}\n\n10.times do |a|\nindex = 0\nuntil itemNum == 0 || index == skillNum\n\tif skillLevel[index] == 100\n\t\tindex += 1\n\t\tnext\n\tend\n\n\trest = 10 - (skillLevel[index] % 10)\n\titemNum -= rest\n\tbreak if itemNum < 0\n\tskillLevel[index] += rest\n\tindex += 1\nend\nend\n\nskillLevel.each do |level|\n\tans += (level / 10)\nend\n\nputs ans"}], "negative_code": [{"source_code": "input = STDIN.gets\narr = input.split.map(&:to_i)\n# \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u0432\u044b\u043a\u043e\u0432\nn = arr[0]\n# \u043e\u0447\u043a\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439\nk = arr[1]\n# \u043e\u0447\u043a\u043e\u0432 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u043e\u0440\u043e\u0432\u043d\u0443\n# constant = (k / n).floor\n# \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u043e\u0447\u043a\u0438\ninput = STDIN.gets\nabilities = input.split.map(&:to_i)\n# \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c\nindexes = Hash.new\n\ni = 0\n# n \u0448\u0430\u0433\u043e\u0432\nabilities.each do |item|\n # \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438\n indexes[i] = 10 - item % 10\n i += 1\nend\n# \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e\n# \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\n# ? \u0448\u0430\u0433\u043e\u0432 - \u043d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430\nsort = Hash[indexes.sort_by{|k, v| v}]\n\n# \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0447\u043a\u0438 \u0442\u0430\u043c, \u0433\u0434\u0435 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e,\n# \u0447\u0442\u043e\u0431\u044b \"\u0434\u043e\u0431\u0438\u0442\u044c\" \u0434\u043e \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b, \u043a\u0440\u0430\u0442\u043d\u043e\u0439 10-\u0442\u0438\n# \u0435\u0449\u0451 n \u0448\u0430\u0433\u043e\u0432\nsort.each do |key, value|\n if k - value >= 0\n abilities[key] += value\n k = k - value\n else\n break\n end\nend\n\n# \u0435\u0441\u043b\u0438 \u0435\u0449\u0451 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u043e\u0447\u043a\u0438 - \u0440\u0430\u0437\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u0445 \u043f\u043e \u0432\u0441\u0435\u043c, \u0434\u043e\u0431\u0438\u0432\u0430\u044f \u0434\u043e 100 \u0441\u043a\u043e\u043b\u044c\u043a\u043e\n# \u0441\u043c\u043e\u0436\u0435\u043c\nif k > 0\n abilities.map! { |element|\n if k >= 100 - element\n k = k - (100 - element)\n element = 100\n else\n element += k\n k = 0\n end\n }\nend\n\nrating = 0\n# \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0445\u043e\u0434\n# n \u0448\u0430\u0433\u043e\u0432\nabilities.each do |item|\n if item > 100\n item = 100\n end\n rating += (item * 0.1).floor\nend\n\n# \u0418\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e\n# 3n + ? \u0448\u0430\u0433\u043e\u0432\n# ? - \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430\nputs \"#{rating}\"\n"}, {"source_code": "input = STDIN.gets\narr = input.split.map(&:to_i)\n# \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u0432\u044b\u043a\u043e\u0432\nn = arr[0]\n# \u043e\u0447\u043a\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439\nk = arr[1]\n# \u043e\u0447\u043a\u043e\u0432 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u043e\u0440\u043e\u0432\u043d\u0443\n# constant = (k / n).floor\n# \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u043e\u0447\u043a\u0438\ninput = STDIN.gets\nabilities = input.split.map(&:to_i)\n# \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c\nindexes = Hash.new\n\ni = 0\n# n \u0448\u0430\u0433\u043e\u0432\nabilities.each do |item|\n # \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438\n indexes[i] = 10 - item % 10\n i += 1\nend\n# \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e\n# \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\n# ? \u0448\u0430\u0433\u043e\u0432 - \u043d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430\nsort = Hash[indexes.sort_by{|k, v| v}]\n\n# \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0447\u043a\u0438 \u0442\u0430\u043c, \u0433\u0434\u0435 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e,\n# \u0447\u0442\u043e\u0431\u044b \"\u0434\u043e\u0431\u0438\u0442\u044c\" \u0434\u043e \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b, \u043a\u0440\u0430\u0442\u043d\u043e\u0439 10-\u0442\u0438\n# \u0435\u0449\u0451 n \u0448\u0430\u0433\u043e\u0432\nsort.each do |key, value|\n if k - value >= 0\n abilities[key] += value\n k = k - value\n else\n break\n end\nend\n\n# \u0435\u0441\u043b\u0438 \u0435\u0449\u0451 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u043e\u0447\u043a\u0438 - \u0440\u0430\u0437\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u0445 \u043f\u043e \u0432\u0441\u0435\u043c, \u0434\u043e\u0431\u0438\u0432\u0430\u044f \u0434\u043e 100 \u0441\u043a\u043e\u043b\u044c\u043a\u043e\n# \u0441\u043c\u043e\u0436\u0435\u043c\nif k > 0\n abilities.map! { |element|\n if k >= 100 - element\n k = k - (100 - element)\n element = 100\n else\n element += k\n k = 0\n end\n }\nend\n\nputs \"#{abilities}\"\nrating = 0\n# \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0445\u043e\u0434\n# n \u0448\u0430\u0433\u043e\u0432\nabilities.each do |item|\n if item > 100\n item = 100\n end\n rating += (item * 0.1).floor\nend\n\n# \u0418\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e\n# 3n + ? \u0448\u0430\u0433\u043e\u0432\n# ? - \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430\nputs \"#{rating}\"\n"}, {"source_code": "input = STDIN.gets\narr = input.split.map(&:to_i)\n# \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u0432\u044b\u043a\u043e\u0432\nn = arr[0]\n# \u043e\u0447\u043a\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439\nk = arr[1]\n# \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u043e\u0447\u043a\u0438\ninput = STDIN.gets\nabilities = input.split.map(&:to_i)\n# \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c\nindexes = Hash.new\n\ni = 0\n# n \u0448\u0430\u0433\u043e\u0432\nabilities.each do |item|\n # \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438\n indexes[i] = 10 - item % 10\n i += 1\nend\n# \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e\n# \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\n# ? \u0448\u0430\u0433\u043e\u0432 - \u043d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430\nsort = Hash[indexes.sort_by{|k, v| v}]\n\n# \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0447\u043a\u0438 \u0442\u0430\u043c, \u0433\u0434\u0435 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e,\n# \u0447\u0442\u043e\u0431\u044b \"\u0434\u043e\u0431\u0438\u0442\u044c\" \u0434\u043e \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b, \u043a\u0440\u0430\u0442\u043d\u043e\u0439 10-\u0442\u0438\n# \u0435\u0449\u0451 n \u0448\u0430\u0433\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0435, \u0445\u043e\u0442\u044f \u043c\u043e\u0436\u0435\u0442 \u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c\u0441\u044f\nsort.each do |key, value|\n if k - value >= 0\n abilities[key] += value\n k = k - value\n else\n break\n end\nend\n\nrating = 0\n# \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0445\u043e\u0434\n# n \u0448\u0430\u0433\u043e\u0432\nabilities.each do |item|\n rating += (item * 0.1).floor\nend\n\n# \u0418\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e\n# 3n + ? \u0448\u0430\u0433\u043e\u0432\n# ? - \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430\nputs \"#{rating}\"\n"}, {"source_code": "input = STDIN.gets\narr = input.split.map(&:to_i)\n# \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u0432\u044b\u043a\u043e\u0432\nn = arr[0]\n# \u043e\u0447\u043a\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439\nk = arr[1]\n# \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u043e\u0447\u043a\u0438\ninput = STDIN.gets\nabilities = input.split.map(&:to_i)\n# \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c\nindexes = Hash.new\n\nrating = 0\ni = 0\n# n \u0448\u0430\u0433\u043e\u0432\nabilities.each do |item|\n # \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438\n indexes[i] = 10 - item % 10\n i += 1\nend\n# \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e\n# \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\n# ? \u0448\u0430\u0433\u043e\u0432 - \u043d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430\nsort = Hash[indexes.sort_by{|k, v| v}]\n\n# \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0447\u043a\u0438 \u0442\u0430\u043c, \u0433\u0434\u0435 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e,\n# \u0447\u0442\u043e\u0431\u044b \"\u0434\u043e\u0431\u0438\u0442\u044c\" \u0434\u043e \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b, \u043a\u0440\u0430\u0442\u043d\u043e\u0439 10-\u0442\u0438\n# \u0435\u0449\u0451 n \u0448\u0430\u0433\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0435, \u0445\u043e\u0442\u044f \u043c\u043e\u0436\u0435\u0442 \u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c\u0441\u044f\nsort.each do |key, value|\n if k - value > 0\n abilities[key] += value\n k = k - value\n else\n break\n end\nend\n\n# \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0445\u043e\u0434\n# n \u0448\u0430\u0433\u043e\u0432\nabilities.each do |item|\n rating += (item * 0.1).floor\nend\n\n# \u0418\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e\n# 3n + ? \u0448\u0430\u0433\u043e\u0432\n# ? - \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430\nputs \"#{rating}\"\n"}, {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nk = Integer(input[1])\ninput = gets.chomp.split\nskills = []\nfor i in 0...n\n skills[i] = Integer(input[i])\nend\n\nskills.sort!{|x, y| y <=> x}\nfor i in 0...n\n if skills[i] % 10 != 0\n unit_needed = 10 - skills[i] % 10\n else\n unit_needed = 0\n end\n if unit_needed > k\n break\n else\n skills[i] += unit_needed\n k -= unit_needed\n end\nend\nif k >= 10 \n for i in 0...n\n x = k / 10\n if skills[i] < 100\n y = (100 - skills[i]) / 10\n if x <= y\n skills[i] += 10 * x\n break\n else\n skills[i] = 100\n k -= 10 * y\n end\n end\n end\nend\nsum = 0\nif skills[0] == skills[n-1] && skills[0] == 0\n sum = (k.to_f / 10).floor\nelse\n for i in 0...n\n sum += (skills[i].to_f / 10).floor\n end\nend\nputs sum"}, {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nk = Integer(input[1])\ninput = gets.chomp.split\nskills = []\nfor i in 0...n\n skills[i] = Integer(input[i])\nend\n\nsum = 0\nfor i in 0...skills.length\n if skills[i] == 100\n sum += 10\n skills.delete_at(i)\n end\nend\nsequence = []\nfor i in 0...skills.length\n sequence[i] = []\n sequence[i][0] = skills[i] / 10\n sequence[i][1] = skills[i] % 10\nend\nsequence = sequence.sort{|x, y| y[1] <=> x[1]}\nfor i in 0...sequence.length\n if 10 - sequence[i][1] < k\n k -= 10 - sequence[i][1]\n sequence[i][1] = 10\n else\n sequence[i][1] += k\n k = 0\n break\n end\nend\nnumbers = []\nfor i in 0...sequence.length\n numbers[i] = 10 * sequence[i][0] + sequence[i][1]\nend\nif k >= 10\n for i in 0...numbers.length\n if k >= 100 - numbers[i]\n numbers[i] = 100\n k -= 100 - numbers[i]\n else\n numbers[i] += k\n k = 0\n break\n end\n end\nend\nfor i in 0...numbers.length\n sum += (numbers[i].to_f / 10).floor\nend\nputs sum\n"}, {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nk = Integer(input[1])\ninput = gets.chomp.split\nskills = []\nfor i in 0...n\n skills[i] = Integer(input[i])\nend\n\nskills.sort!{|x, y| y <=> x}\nfor i in 0...n\n if skills[i] % 10 != 0\n unit_needed = 10 - skills[i] % 10\n else\n unit_needed = 0\n end\n if unit_needed > k\n break\n else\n skills[i] += unit_needed\n k -= unit_needed\n end\nend\nsum = 0\nif skills[0] == skills[n-1] && skills[0] == 0\n sum = (k.to_f / 10).floor\nelse\n for i in 0...n\n sum += (skills[i].to_f / 10).floor\n end\nend\nputs sum"}, {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nk = Integer(input[1])\ninput = gets.chomp.split\nskills = []\nfor i in 0...n\n skills[i] = Integer(input[i])\nend\n\nskills.sort!{|x, y| y <=> x}\nfor i in 0...n\n if skills[i] % 10 != 0\n unit_needed = 10 - skills[i] % 10\n else\n unit_needed = 0\n end\n if unit_needed > k\n break\n else\n skills[i] += unit_needed\n k -= unit_needed\n end\nend\nif k >= 10\n skills[0] += 10 * (k / 10)\nend\nsum = 0\nif skills[0] == skills[n-1] && skills[0] == 0\n sum = (k.to_f / 10).floor\nelse\n for i in 0...n\n sum += (skills[i].to_f / 10).floor\n end\nend\nputs sum"}, {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nk = Integer(input[1])\ninput = gets.chomp.split\nskills = []\nfor i in 0...n\n skills[i] = Integer(input[i])\nend\n\nskills.sort!{|x, y| y <=> x}\nfor i in 0...n\n if skills[i] % 10 != 0\n unit_needed = 10 - skills[i] % 10\n else\n unit_needed = 0\n end\n if unit_needed > k\n break\n else\n skills[i] += unit_needed\n k -= unit_needed\n end\nend\nsum = 0\nfor i in 0...n\n sum += (skills[i].to_f / 10).floor\nend\nputs sum"}, {"source_code": "firstInput = gets.chomp.split(' ').map {|item| item.to_i}\nskillNum, itemNum = firstInput[0], firstInput[1]\nskillHash = {}\nans = 0\nskillLevel = gets.chomp.split(' ').map {|item| item.to_i}\nskillLevel.each_with_index do |value, index|\n\tskillHash[index] = value % 10\nend\n\nskillLevel.sort! {|a, b| b % 10 <=> a % 10}\n\nindex = 0\nuntil itemNum == 0 || index == skillNum\n\trest = 10 - (skillLevel[index] % 10)\n\titemNum -= rest\n\tbreak if itemNum < 0\n\tskillLevel[index] += rest\n\tindex += 1\nend\n\nskillLevel.each do |level|\n\tans += (level / 10)\nend\n\nputs ans\n\n"}, {"source_code": "firstInput = gets.chomp.split(' ').map {|item| item.to_i}\nskillNum, itemNum = firstInput[0], firstInput[1]\nans = 0\nskillLevel = gets.chomp.split(' ').map {|item| item.to_i}\nskillLevel.sort! {|a, b| b % 10 <=> a % 10}\n\nindex = 0\nuntil itemNum == 0 || index == skillNum\n\tif skillLevel[index] == 100\n\t\tindex += 1\n\t\tnext\n\tend\n\n\trest = 10 - (skillLevel[index] % 10)\n\titemNum -= rest\n\tbreak if itemNum < 0\n\tskillLevel[index] += rest\n\tindex += 1\nend\n\nskillLevel.sort! {|a, b| b % 100 <=> a % 100}\n\nindex = 0\nuntil itemNum == 0 || index == skillNum\n\tif skillLevel[index] == 100\n\t\tindex += 1\n\t\tnext\n\tend\n\n\trest = 100 - (skillLevel[index] % 100)\n\titemNum -= rest\n\tbreak if itemNum < 0\n\tskillLevel[index] += rest\n\tindex += 1\nend\n\nskillLevel.each do |level|\n\tans += (level / 10)\nend\n\nputs ans"}], "src_uid": "b4341e1b0ec0b7341fdbe6edfe81a0d4"} {"source_code": "m,k=gets.split.map(&:to_i)\nd=gets.split.map(&:to_i)\ns=gets.split.map(&:to_i)\nf=0\nmaxi=0\nres=0\nfor i in 0..m-1 do\n maxi=i if s[maxi]=d[i]\n\t\t\tpet-=d[i]\n\t\t\tmint+=d[i]\n\t\t\tif i < m-1\n\t\t\t\tpet+=s[i+1]\n\t\t\tend\n\t\telse\n\t\t\tmaxp=s[0..i].max\n\t\t\twhile(pet=d[i]\n pet-=d[i]\n tiws+=d[i]\n if i < m-1\n pet+=s[i+1]\n end\n else\n stop=true;\n break;\n end\n end\n if stop\n pet=s[0]\n for i in 0...m\n if pet>=d[i]\n pet-=d[i]\n mint+=d[i]\n if i < m-1\n pet+=s[i+1]\n end\n else\n maxp=s[0..i].max\n while(pet=d[i]\n\t\t\tpet-=d[i]\n\t\t\ttiws+=d[i]\n\t\t\tif i < m-1\n\t\t\t\tpet+=s[i+1]\n\t\t\tend\n\t\telse\n\t\t\tstop=true;\n\t\t\tbreak;\n\t\tend\n\tend\n\tif stop\n\t\tpet=s[0]\n\t\tfor i in 0...m\n\t\t\tif pet>=d[i]\n\t\t\t\tpet-=d[i]\n\t\t\t\tmint+=d[i]\n\t\t\t\tif i < m\n\t\t\t\t\tpet+=s[i+1]\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tmaxp=s[0..i].max\n\t\t\t\twhile(pet2\n end\n if h.size==1\n if h[0]>0\n puts 1,a[0]\n else\n d=a[1]-a[0]\n puts 2,[a[0]-d,a[-1]+d].sort*' '\n end\n elsif h.size==2\n k=h.keys\n d=e=nil\n if k[0]*2==k[1]\n d=k[0]\n e=k[1]\n elsif k[1]*2==k[0]\n d=k[1]\n e=k[0]\n end\n if d&&e&&h[e]==1\n (1...n).each do |i|\n if a[i]-a[i-1]==e\n puts 1,a[i-1]+d\n exit\n end\n end\n else\n p 0\n end\n else\n p 0\n end\nend"}, {"source_code": "inp = ARGF.read.split\nn = inp.shift.to_i\na = inp.map(&:to_i).sort!\n\nsolve = lambda {\n if n == 0 then 0\n elsif n == 1 then -1\n else\n mp = {}\n (1...n).each { |i|\n x = a[i] - a[i - 1]\n mp[x] = 0 if not mp.key? x\n mp[x] += 1\n }\n x, y = mp.keys.min, mp.keys.max\n if mp.size == 1\n d = a[1] - a[0]\n il = [a[0] - d, a[n - 1] + d]\n il << a[0] + d / 2 if a.size == 2 and d % 2 == 0\n il.sort!.uniq!\n il.size.to_s + \"\\n\" + il.map(&:to_s).join(' ')\n elsif mp.size == 2 and mp[y] == 1 and x * 2 == y\n (1...n).step(1) { |i|\n return \"1\\n#{a[i - 1] + x}\" if a[i] - a[i - 1] == y\n }\n else 0 end\n end\n}\n\nputs solve.call\n"}], "negative_code": [{"source_code": "# Sort the elements\n# find diff array\n# check if d is the same for all elements\n# if so insert at first and last\n# if d is diff for just one element insert at that position\n# if d is diff for more than one element no ap is possible\n# special case when 2 elements - can be inserted in between by changing d as d/ 2\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nans = nil\nif arr.length == 1\n\tputs -1\nelse\n\tarr.sort!\n\tif arr.length == 2\n\t\td = arr[1] - arr[0]\n\t\tans = [arr[0] - d,arr[1]+d]\n\t\tmid = (arr[0] + arr[1]) / 2\n\t\tans << mid if (mid - arr[0] == arr[1] - mid) \n\telse\n\t\tdiff = []\n\t\tarr.each_cons(2) do |a,b|\n\t\t\tdiff << b - a\n\t\tend\n\t\td = diff.min\n\t\tcount = diff.count{|x| x!=d}\n\t\tif count == 0\n\t\t\tans = [arr[0] - d,arr[-1]+d]\n\t\telsif count == 1\n\t\t\ti = diff.index{|x| x!=d}\n\t\t\tans = [arr[i]+d] if arr[i]+d == arr[i+1]-d\n\t\tend\n\n\tend\n\n\tif ans\n\t\tputs ans.length\n\t\tputs ans.sort.join(\" \")\n\telse\n\t\tputs 0\n\tend\nend"}, {"source_code": "inp = ARGF.read.split\nn = inp.shift.to_i\na = inp.map(&:to_i).sort!\n\nsolve = lambda {\n if n == 0 then 0\n elsif n == 1 then -1\n else\n mp = {}\n (1...n).each { |i|\n x = a[n - i] - a[n - i - 1]\n mp[x] = 0 if not mp.key? x\n mp[x] += 1\n }\n if mp.size == 1\n d = a[1] - a[0]\n il = [a[0] - d, a[n - 1] + d]\n il << a[0] + d / 2 if a.size == 2 and d % 2 == 0\n il.sort!.uniq!\n il.size.to_s + \"\\n\" + il.map(&:to_s).join(' ')\n elsif mp.size == 2\n x, y = mp.keys.min, mp.keys.max\n if x * 2 == y\n (1...n).step(1) { |i|\n return \"1\\n#{a[i - 1] + x}\" if a[i] - a[i - 1] == y\n }\n else 0 end\n end\n end\n}\n\nputs solve.call\n"}], "src_uid": "e3ca8338beb8852c201be72650e9aabd"} {"source_code": "n,*a=$<.read.split.map &:to_i\ns=a.reduce :+\nr=0\np (1..n).find{|i|(r+=a[i-1])*2>=s}", "positive_code": [{"source_code": "n,*a=$<.read.split.map &:to_i\ns=a.reduce :+\nr=0\np (1..n).find{|i|(r+=a[i-1])*2>=s}"}], "negative_code": [], "src_uid": "241157c465fe5dd96acd514010904321"} {"source_code": "gets\r\nx=$<.map{|x|x.split.map(&:to_i).sort[1]}\r\nputs x", "positive_code": [{"source_code": "=begin\n\nWelcome to GDB Online.\nGDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,\nC#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.\nCode, Compile, Run and Debug online from anywhere in world.\n\n=end\n\nt=gets.to_i\nfor i in 1..t\n a,b,c =gets.split.map &:to_i\n\n if a>b\n if (b>c)\n p b\n elsif a>c\n p c\n else\n p a\n end \n else\n if (a>c)\n p a\n elsif b>c\n p c\n else\n p b\n end \n end\n\nend\n"}, {"source_code": "main = -> {\n abc = gets.split.map(&:to_i)\n abc.sum - abc.min - abc.max\n}\n\n\nt = gets.to_i\nputs t.times.map{ main.call }.join(\"\\n\")\n"}, {"source_code": "gets.to_i.times{\r\n n=gets.split.map &:to_i\r\n n=n.sort\r\n puts n[1]\r\n}"}], "negative_code": [], "src_uid": "63c2142461c93ae4c962eac1ecb5b192"} {"source_code": "gets;p$<.map{|e|e.split.map(&:to_i).min}.max\n", "positive_code": [{"source_code": "gets;p$<.map{|e|e.split.map(&:to_i).min}.max"}, {"source_code": "max_min = 0\nn, m = gets.split.map(&:to_i)\nfor i in 1..n do\n row = gets.split.map(&:to_i)\n min = 1000000001\n row.each do |num|\n min = num if num < min \n end\n max_min = min if min > max_min\nend\nputs max_min\n"}, {"source_code": "n, _ = gets.split.map &:to_i\nprices = Array.new n\nn.times do |i|\n prices[i] = gets.split.map(&:to_i).min\nend\nputs prices.max\n"}, {"source_code": "ans = 0\nrows, cols = gets.split.map(&:to_i)\nrows.times do\n\tans = [ans, gets.split.map(&:to_i).min].max\nend\n\nputs ans\n"}, {"source_code": "gets;p$<.map{|e|e.split.map(&:to_i).min}.max\n"}, {"source_code": "n_e_m = gets.split(\" \")\nn = n_e_m[0].to_i\nm = n_e_m[1].to_i\nrestaurantes = []\nrestaurante_escolhido = 0\nn.times do \n\truas_numero = []\n\truas = gets.split(\" \")\n\tfor i in 0..ruas.size - 1 do\n\t\truas_numero << ruas[i].to_i\n\tend\n\trestaurantes << ruas_numero.sort\nend\nfor avenida in 0..restaurantes.size-1 do\n\tif restaurantes[avenida][0] > restaurante_escolhido\n\t\trestaurante_escolhido = restaurantes[avenida][0]\n\tend\nend\nputs restaurante_escolhido\n"}, {"source_code": "n, m = gets.chomp.split(\" \").map(&:to_i)\nrestraunts = []\nstreet = gets.chomp.split(\" \").map(&:to_i)\nstreet_min = street.min\nrow = 0\nrestraunts << street\n(n-1).times do |i|\n street = gets.chomp.split(\" \").map(&:to_i)\n if street_min < street.min then\n street_min = street.min\n row = i + 1\n end\n restraunts << street\nend\nputs restraunts[row].min"}, {"source_code": "n, m = gets.split(' ').map(&:to_i);\na = [];\nn.times {\n a += [(gets.split(' ').map(&:to_i).min)];\n}\nputs a.max;\n"}, {"source_code": "n =gets.split\nans=0\nn[0].to_i.times do\n now=2000000000\n a=gets.split\n for x in a do\n now=x.to_i if x.to_ians\nend\np ans"}, {"source_code": "gets;p$<.map{|e|e.split.map(&:to_i).min}.max\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nmax = 0\nn.times do\n a = gets.split.map(&:to_i).min\n max = a if a > max\nend\nputs max"}, {"source_code": "gets;p$<.map{|e|e.split.map(&:to_i).min}.max\n"}], "negative_code": [{"source_code": "n_e_m = gets.split(\" \")\nn = n_e_m[0].to_i\nm = n_e_m[1].to_i\nrestaurantes = []\nruas_numero = []\nrestaurante_escolhido = 0\nn.times do \n\truas = gets.split(\" \")\n\truas.each do |rua|\n\t\truas_numero << rua.to_i\n\tend\n\trestaurantes << ruas_numero.sort\nend\nfor avenida in 0..restaurantes.size-1 do\n\tif restaurantes[avenida][0] > restaurante_escolhido\n\t\trestaurante_escolhido = restaurantes[avenida][0]\n\tend\nend\nputs restaurante_escolhido"}, {"source_code": "n_e_m = gets.split(\" \")\nn = n_e_m[0].to_i\nrestaurantes = []\nrestaurante_escolhido = 0\nn.times do \n\trestaurantes << gets.split(\" \").sort\nend\nfor avenida in 0..restaurantes.size-1 do\n\tif restaurantes[avenida][0].to_i > restaurante_escolhido\n\t\tavenida_escolhida = restaurantes[avenida]\n\t\trestaurante_escolhido = restaurantes[avenida][0].to_i\n\tend\nend\nputs restaurante_escolhido"}, {"source_code": "n_e_m = gets.split(\" \")\nn = n_e_m[0].to_i\nm = n_e_m[1].to_i\nrestaurantes = []\navenida_letras = []\nrestaurante_da_emma = 0\nemma = 0\njack = 100000000\nn.times do \n\trestaurantes << gets.split(\" \")\nend\nrestaurantes.each_with_index do |avenida, index|\n\tfor rua in 0..avenida.size - 1 do\n\t\trestaurante_atual = restaurantes[index][rua].to_i\n\t\tif restaurante_atual > restaurante_da_emma\n\t\t\temma = index\n\t\t\trestaurante_da_emma = restaurante_atual\n\t\tend\n\tend\nend\nescolha_da_emma = restaurantes[emma]\nfor escolha in 0..escolha_da_emma.size-1 do\n\tif escolha_da_emma[escolha].to_i < jack\n\t\tjack = escolha_da_emma[escolha].to_i\n\tend\nend\nputs jack\n\n"}, {"source_code": "n_e_m = gets.split(\" \")\nn = n_e_m[0].to_i\nm = n_e_m[1].to_i\nrestaurantes = []\navenida_letras = []\nemma = 0\nnova_emma = 1000000000\njack = 100000000\nn.times do \n\trestaurantes << gets.split(\" \")\nend\nrestaurantes.each_with_index do |avenida, index|\n\tfor rua in 0..avenida.size - 1 do\n\t\trestaurante_atual = restaurantes[index][rua].to_i\n\t\tif restaurante_atual < nova_emma\n\t\t\tnova_emma = restaurante_atual\n\t\tend\n\tend\n\tif nova_emma > emma\n\t\temma = index\n\tend\nend\nescolha_da_emma = restaurantes[emma]\nfor escolha in 0..escolha_da_emma.size-1 do\n\tif escolha_da_emma[escolha].to_i < jack\n\t\tjack = escolha_da_emma[escolha].to_i\n\tend\nend\nputs jack\n\n"}, {"source_code": "n_e_m = gets.split(\" \")\nn = n_e_m[0].to_i\nm = n_e_m[1].to_i\nrestaurantes = []\navenida_letras = []\nemma = 0\nnova_emma = 1000000000\njack = 100000000\nn.times do \n\trestaurantes << gets.split(\" \")\nend\nrestaurantes.each_with_index do |avenida, index|\n\tfor rua in 0..avenida.size - 1 do\n\t\trestaurante_atual = restaurantes[index][rua].to_i\n\t\tif restaurante_atual > nova_emma\n\t\t\tnova_emma = restaurante_atual\n\t\tend\n\tend\n\tif nova_emma > emma\n\t\temma = index\n\tend\nend\nescolha_da_emma = restaurantes[emma]\nfor escolha in 0..escolha_da_emma.size-1 do\n\tif escolha_da_emma[escolha].to_i < jack\n\t\tjack = escolha_da_emma[escolha].to_i\n\tend\nend\nputs jack"}], "src_uid": "f2142bc2f44e5d8b77f8561c29038a73"} {"source_code": "gets.to_i.times do\n a, b, k = gets.split.map(&:to_i)\n puts (k/2) * (a-b) + (k%2)*a\nend\n", "positive_code": [{"source_code": "def solve()\n line = gets\n\n a = line.split(' ')[0].to_i\n b = line.split(' ')[1].to_i\n k = line.split(' ')[2].to_i\n\n if ( k%2 == 0 )\n return ( a * (k/2) - b * (k/2)) \n end\n\n return ( a * (k/2) - b * (k/2)) + a\nend\n\nntest = gets\n\nntest.to_i.times { |nn|\n\n puts solve()\n\n}\n"}, {"source_code": "1.upto(gets.to_i) do\n a, b, k = gets.split(' ').map(&:to_i)\n\n puts (a-b)*k.div(2) + a*k.modulo(2)\nend\n"}, {"source_code": "t=gets.to_i\n(1).upto(t) do\n a=gets.split(' ').map(&:to_i)\n x = a[1]*(a[2]>>1)\n y = a[0]*(1+a[2]>>1)\n puts y-x\nend\n"}, {"source_code": "gets;p *$<.map{|e|a,b,k=e.split.map &:to_i;k/2*(a-b)+k%2*a}"}, {"source_code": "#(5-2) * (3/2 - 3%2 /2) + 5 * (3%2)\nn = gets.to_i\n\nfor i in 0...n\n pos = 0\n a, b, t = gets.split.map(&:to_i)\n pos += (a - b) * (t / 2) + a * (t % 2)\n puts pos\nend"}, {"source_code": "n = gets.strip.to_i\nresults = []\nfor i in 0..n-1\n a, b, k = gets.strip.split.map(&:to_i)\n\n result = 0\n\n if a == b\n if k % 2 == 0\n result = 0\n else\n result = a\n end\n else\n if k % 2 == 0\n result = a*k/2-b*k/2\n else\n result = a*((k/2).floor+1)-b*(k/2).floor\n end\n end\n\n results << result\nend\nresults.each do |result|\n p result\nend\n"}, {"source_code": "class Sol\n def initialize(a, b, k)\n @k = k\n @b = b\n @a = a\n end\n\n def res\n puts (@k + 1) / 2 * @a - (@k / 2) * @b\n end\nend\n\nt = gets.to_i\nt.times do\n a, b, k = gets.split.map &:to_i\n s = Sol.new(a, b, k)\n s.res\nend\n\n"}, {"source_code": "t = gets.strip.to_i\nt.times do\n a, b, k = gets.strip.split.map(&:to_i)\n puts (a - b) * (k / 2) + ((k % 2).zero? ? 0 : a)\nend"}, {"source_code": "gets.to_i.times do\n a,b,k = gets.split.map(&:to_i)\n puts a*((k+1)/2)-b*(k/2)\nend"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nt = gets.to_i\nt.times {\n a, b, k = gets.split.map(&:to_i)\n even_jumps, odd_jumps = (k/2.0).ceil, k/2\n puts even_jumps * a - odd_jumps * b\n}\n"}, {"source_code": "t = gets.to_i\n\nt.times do\n s = gets.split.map &:to_i\n q = s[2] / 2 + s[2] % 2\n puts q * s[0] - (s[2] - q) * s[1]\nend"}, {"source_code": "t = gets.to_i\nt.times do\n a, b, k = gets.split.map(&:to_i)\n p(a*((k + 1)/2) - b*(k/2))\nend\n"}], "negative_code": [], "src_uid": "1f435ba837f59b007167419896c836ae"} {"source_code": "n = gets.to_i\r\nn.times do\r\n _ = gets.to_i\r\n puts gets.split(' ').uniq! ? 'NO' : 'YES'\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n a=gets.split.map(&:to_i).uniq\r\n puts a.size==n ? 'YES' : 'NO'\r\nend"}, {"source_code": "t=gets.to_i\nt.times do\n _=gets\n a=gets.split.map(&:to_i)\n l=a.length\n nl=a.uniq.length\n if l==nl\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "gets.to_i.times do\n n=gets.to_i\n a=gets.split.map(&:to_i).uniq\n puts a.size==n ? 'YES' : 'NO'\nend\n"}], "negative_code": [], "src_uid": "288f147bb8a3c30b0bb712a01c65109b"} {"source_code": "class Solution\n def initialize\n @n = gets.to_i\n @cities = []\n @n.times {@cities << gets.chomp}\n @d = gets.chomp\n end\n\n def solve\n length = (@cities.inject(0){|x, s| x + s.length})/(@n/2)\n\n left = []\n right = []\n str_by_len = []\n for c in @cities do\n str_by_len[c.length] ||= []\n str_by_len[c.length] << c\n end\n (1..10).each do |i|\n unless str_by_len[i].nil?\n str_by_len[i].sort!\n end\n end\n\n (@n/2).times do\n min_s = '~' * 21\n min_i = -1\n min_j = -1\n (1..10).each do |i|\n next if str_by_len[i].nil? or str_by_len[i].empty?\n s1 = str_by_len[i].shift\n j = length - i\n next if str_by_len[j].nil? or str_by_len[j].empty?\n s2 = str_by_len[j].shift\n if s1 + @d + s2 < min_s\n min_s = s1 + @d + s2\n min_i = i\n min_j = j\n end\n str_by_len[j].unshift(s2)\n str_by_len[i].unshift(s1)\n end\n left << str_by_len[min_i].shift\n right << str_by_len[min_j].shift\n end\n \n # find the last right column item\n (1..10).each do |i|\n if (not str_by_len[i].nil?) and (not str_by_len[i].empty?)\n right << str_by_len[i].shift\n break\n end\n end\n\n (@n/2).times do\n puts left.shift + @d + right.shift\n end\n end\nend\n\nsolution = Solution.new\nsolution.solve\n", "positive_code": [{"source_code": "class Solution\n def initialize\n @n = gets.to_i\n @cities = []\n @n.times {@cities << gets.chomp}\n @d = gets.chomp\n end\n\n def solve\n length = (@cities.inject(0){|x, s| x + s.length})/(@n/2)\n\n left = []\n right = []\n str_by_len = []\n for c in @cities do\n str_by_len[c.length] ||= []\n str_by_len[c.length] << c\n end\n (1..10).each do |i|\n unless str_by_len[i].nil?\n str_by_len[i].sort!\n end\n end\n\n (@n/2).times do\n min_s = '~' * 21\n min_i = -1\n min_j = -1\n (1..10).each do |i|\n next if str_by_len[i].nil? or str_by_len[i].empty?\n s1 = str_by_len[i].shift\n j = length - i\n next if str_by_len[j].nil? or str_by_len[j].empty?\n s2 = str_by_len[j].shift\n if s1 + @d + s2 < min_s\n min_s = s1 + @d + s2\n min_i = i\n min_j = j\n end\n str_by_len[j].unshift(s2)\n str_by_len[i].unshift(s1)\n end\n left << str_by_len[min_i].shift\n right << str_by_len[min_j].shift\n end\n \n (@n/2).times do\n puts left.shift + @d + right.shift\n end\n end\nend\n\nsolution = Solution.new\nsolution.solve\n"}], "negative_code": [], "src_uid": "0f04f757dc734208d803ee0f6be5d1f0"} {"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\np0 = gets.chomp.split(/ /).map!{|x| x.to_i}\nk = gets.chomp.to_i\nstep = 0\nfor i in 0..k-1\n\tp = gets.chomp.split(/ /).map!{|x| x.to_i}\n\tsx = 0\n\tsy = 0\n\tif p[0] != 0\n\t\tif p[0] < 0\n\t\t\tsx = (p0[0]-1) / -p[0]\n\t\telse\n\t\t\tsx = (n - p0[0]) / p[0]\n\t\tend\n\tend\n\tif p[1] != 0\n\t\tif p[1] < 0\n\t\t\tsy = (p0[1]-1) / -p[1]\n\t\telse\n\t\t\tsy = (m - p0[1]) / p[1]\n\t\tend\n\tend\n\tws = [sx, sy].min\n\tws = sy if p[0] == 0 && p[1] != 0\n\tws = sx if p[0] != 0 && p[1] == 0\n\tp0 = [p0[0]+p[0]*ws, p0[1]+p[1]*ws]\n\tstep += ws\nend\nputs step\n\n", "positive_code": [{"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? 10 ** 10 : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n\n"}, {"source_code": "w,h=gets.split.map(&:to_i)\nx,y=gets.split.map(&:to_i)\nx,y=x-1,y-1\nk=gets.to_i\nans=0\nk.times{|i|\n\tdx,dy=gets.split.map(&:to_i)\n\tminimum=[]\n\tif dx<0\n\t\tminimum+=[x/-dx]\n\telsif dx>0\n\t\tminimum+=[(w-x-1)/dx]\n\tend\n\n\tif dy<0\n\t\tminimum+=[y/-dy]\n\telsif dy>0\n\t\tminimum+=[(h-y-1)/dy]\n\tend\n\tans+=minimum.min\n\tx+=dx*minimum.min\n\ty+=dy*minimum.min\n}\n\np ans\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef getmax(cur, lim, d)\n if d > 0\n (lim-cur) / d\n elsif d < 0\n (cur-1) / (-d)\n else\n 1000000000\n end\nend\n\nn, m = gets.split.map(&:to_i)\nx, y = gets.split.map(&:to_i)\nk = gets.to_i\n\nans = 0\nk.times do\n dx, dy = gets.split.map(&:to_i)\n max_x = getmax(x, n, dx)\n max_y = getmax(y, m, dy)\n maxstep = [max_x, max_y].min\n x += dx*maxstep\n y += dy*maxstep\n ans += maxstep\nend\n\np ans\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? 10 ** 10 : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n\n\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? 10 ** 10 : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n\n\n"}, {"source_code": "n, m = STDIN.readline.split.map {|s| s.to_i }\nx, y = STDIN.readline.split.map {|s| s.to_i }\n\ndef max_steps(x, d, n)\n return 10**9 if d == 0\n span = (d > 0 ? n-x : x-1)\n d = d.abs\n return span/d\nend\n\ncount = 0\nk = STDIN.readline.to_i\nk.times do\n dx, dy = STDIN.readline.split.map {|s| s.to_i }\n a, b = max_steps(x, dx, n), max_steps(y, dy, m)\n c = [a, b].min\n x += c*dx\n y += c*dy\n count += c\nend\n\nputs count\n\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? 10 ** 10 : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? 10 ** 10 : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n\n\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? 10 ** 10 : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n\n\n"}, {"source_code": "sizes=gets.chomp\ninit=gets.chomp\nv=[]\nn=gets.chomp.to_i\nn.times do\n v<-1 do\n delta=(max-min)/2\n i=min+delta\n if !(c[0]+a[j][0]*i<1||c[0]+a[j][0]*i>s[0]||c[1]+a[j][1]*i<1||c[1]+a[j][1]*i>s[1])\n min=i\n if delta==0\n c[0]+=a[j][0]*i;c[1]+=a[j][1]*i\n steps+=i\n break\n end\n else\n max=i\n end\nend\nend\nputs steps"}, {"source_code": "n,m = gets.split.map(&:to_i)\nx,y = gets.split.map(&:to_i)\nvs = gets.to_i\nv = []\nvs.times{ v << gets.split.map(&:to_i) }\nst = 0\n\nv.each do |dxy|\n dx,dy = dxy[0],dxy[1]\n cx = dx > 0 ? n : 1\n cy = dy > 0 ? m : 1\n xx = dx != 0 ? ((cx-x)/dx).abs : 1000000000000\n yy = dy != 0 ? ((cy-y)/dy).abs : 1000000000000\n s = [yy,xx].min\n y = y+s*dy\n x = x+s*dx\n st += s\nend\np st\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? 10 ** 10 : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? 10 ** 10 : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n\n\n"}, {"source_code": "inp = gets.split(\" \")\nn = inp[0].to_i\nm = inp[1].to_i\ninp = gets.split(\" \")\nxc = inp[0].to_i\nyc = inp[1].to_i\nk = gets.to_i\nsteps = 0\nfor i in 0..(k-1)\n\n inp = gets.split(\" \")\n dxi = inp[0].to_i\n dyi = inp[1].to_i\n \n xsteps = 1000000000\n ysteps = 1000000000\n if(dxi > 0)\n xsteps = (n - xc) / dxi\n elsif (dxi < 0)\n xsteps = (xc - 1) / (-dxi)\n end\n if(dyi > 0)\n ysteps = (m - yc) / dyi\n elsif (dyi < 0)\n ysteps = (yc - 1) / (-dyi)\n end\n #puts ysteps\n s = [xsteps, ysteps].min\n xc += s * dxi\n yc += s * dyi\n #puts s\n #puts xc.to_s + \",\" + yc.to_s\n steps += s\nend\n\nputs steps"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? 10 ** 10 : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n\n\n"}, {"source_code": "INF = 1000000001\nnm = gets.split(\" \")\nn = nm[0].to_i\nm = nm[1].to_i\n\nxy = gets.split(\" \")\nx = xy[0].to_i\ny = xy[1].to_i\n\nk = gets.to_i\nans = 0\nwhile k > 0\n dxy = gets.split(\" \")\n dx = dxy[0].to_i\n w = INF\n if dx > 0 then\n w = (n - x) / dx\n elsif dx < 0 then\n w = (x-1) / (-dx)\n end\n dy = dxy[1].to_i\n h = INF\n if dy > 0 then\n h = (m - y) / dy\n elsif dy < 0 then\n h = (y - 1) / (-dy)\n end\n mn = w < h ? w : h\n ans += mn\n x += dx * mn\n y += dy * mn\n k = k-1\nend\n\nputs ans\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? 10 ** 10 : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n\n\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? 10 ** 10 : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n\n\n"}], "negative_code": [{"source_code": "I = ->{gets.split.map(&:to_i)}\nF = ->(s, t, d){d == 0 ? t : (d > 0 ? t - s : 1 - s) / d}\nr, c = I[]\nx, y = I[]\nn = 0\nI[][0].times do\n u, v = I[]\n m = [F[x, r, u], F[y, c, v]].min\n n += m\n x += m * u\n y += m * v\nend\np n\n"}, {"source_code": "sizes=gets.chomp\ninit=gets.chomp\nv=[]\nn=gets.chomp.to_i\nn.times do\n v<0 do\n if !(c[0]+a[j][0]*i<1||c[0]+a[j][0]*i>s[0]||c[1]+a[j][1]*i<1||c[1]+a[j][1]*i>s[1])\n c[0]+=a[j][0]*i;c[1]+=a[j][1]*i\n steps+=i\n break\n end\n i/=2\nend\nend\nputs steps"}, {"source_code": "sizes=gets.chomp\ninit=gets.chomp\nv=[]\n(n_v=gets.chomp.to_i).times do\n v<s[0]||c[1]<1||c[1]>s[1] do\n c[0]+=a[i][0];c[1]+=a[i][1]\n if c[0]<1||c[0]>s[0]||c[1]<1||c[1]>s[1]\n c[0]-=a[i][0];c[1]-=a[i][1]\n break\n end\n steps+=1\n end\n i+=1\nend\nputs steps\n"}, {"source_code": "inp = gets.split(\" \")\nn = inp[0].to_i\nm = inp[1].to_i\ninp = gets.split(\" \")\nxc = inp[0].to_i\nyc = inp[1].to_i\nk = gets.to_i\nsteps = 0\nfor i in 0..(k-1)\n\n inp = gets.split(\" \")\n dxi = inp[0].to_i\n dyi = inp[1].to_i\n \n xsteps = 1000000000\n ysteps = 1000000000\n if(dxi > 0)\n xsteps = (n - xc) / dxi\n elsif (dxi < 0)\n xsteps = (xc - 1) / (-dxi)\n end\n if(dyi > 0)\n ysteps = (m - yc) / dyi\n elsif (dyi < 0)\n ysteps = (yc - 1) / (-dyi)\n end\n #puts ysteps\n s = [xsteps, ysteps].min\n xc += s * dxi\n yc += s * dyi\n puts s\n puts xc.to_s + \",\" + yc.to_s\n steps += s\nend\n\nputs steps"}, {"source_code": "inp = gets.split(\" \")\nn = inp[0].to_i\nm = inp[1].to_i\ninp = gets.split(\" \")\nxc = inp[0].to_i\nyc = inp[1].to_i\nk = gets.to_i\nsteps = 0\nfor i in 0..(k-1)\n\n inp = gets.split(\" \")\n dxi = inp[0].to_i\n dyi = inp[1].to_i\n \n xsteps = 1000000000\n ysteps = 1000000000\n if(dxi > 0)\n xsteps = (n - xc) / dxi\n elsif (dxi < 0)\n xsteps = (xc - 1) / (-dxi)\n end\n if(dyi > 0)\n ysteps = (n - yc) / dyi\n elsif (dyi < 0)\n ysteps = (yc - 1) / (-dyi)\n end\n #puts ysteps\n s = [xsteps, ysteps].min\n xc += s * dxi\n yc += s * dyi\n #puts s\n #puts xc.to_s + \",\" + yc.to_s\n steps += s\nend\n\nputs steps"}], "src_uid": "2737d7aa245627b1f7992b1148ed49ce"} {"source_code": "n, m = STDIN.gets.chomp.split(\" \").map(&:to_i)\n\nfreq = Array.new(m){ {'A' => 0, 'B' => 0, 'C' => 0, 'D' => 0, 'E' => 0} }\n\nn.times do |i|\n line = STDIN.gets.chomp.each_char.with_index do |c, j|\n freq[j][c] += 1\n end\nend\n\nscores = STDIN.gets.chomp.split(\" \").map(&:to_i)\nputs freq.map.with_index{|f, i| f.values.max*scores[i]}.reduce(&:+)\n", "positive_code": [{"source_code": "a, b = gets.split.map(&:to_i)\nc = Array.new(a).map do\n gets.chomp.bytes\nend\nf = gets.split.map(&:to_i)\nputs(\n c.transpose.zip(f).map do |d, i|\n i * d.uniq.map{ |e| d.count e }.max\n end.inject(:+)\n)\n"}, {"source_code": "n, m = gets.split.map &:to_i\ns = []\nn.times { s << gets.chomp }\nb = m.times.map do |j|\n h = {}\n (0...n).each do |i|\n h[s[i][j]] ||= 0\n h[s[i][j]] += 1\n end\n h.values.max\nend\nputs gets.split.each_with_index.inject(0) { |s, x| s + x[0].to_i*b[x[1]] }\n"}], "negative_code": [], "src_uid": "2022f53e5a88d5833e133dc3608a122c"} {"source_code": "n = gets.to_i\na = [[-1e9, -1e9]] + 1.upto(n).map{|i| gets.split.map(&:to_i) << i}.sort + [[1e9, 1e9]]\nb = a.map{1}\n1.upto(n + 1){|i| b[i] = b[i - 1] && a[i - 1][1] <= a[i][0]}\nc = a.map{1}\n(n).downto(0){|i| c[i] = c[i + 1] && a[i][1] <= a[i + 1][0]}\nd = (1 .. n).select{|i| b[i - 1] && c[i + 1] && a[i - 1][1] <= a[i + 1][0]}.map{|i| a[i][2]}\np d.size\nputs d.sort * ' '\n\n", "positive_code": [{"source_code": "n = gets.to_i\na = [[-1e9, -1e9]] + 1.upto(n).map{|i| gets.split.map(&:to_i) << i}.sort + [[1e9, 1e9]]\nb = a.map{1}\n1.upto(n + 1){|i| b[i] = b[i - 1] && a[i - 1][1] <= a[i][0]}\nc = a.map{1}\n(n).downto(0){|i| c[i] = c[i + 1] && a[i][1] <= a[i + 1][0]}\nd = (1 .. n).select{|i| b[i - 1] && c[i + 1] && a[i - 1][1] <= a[i + 1][0]}.map{|i| a[i][2]}\np d.size\nputs d.sort * ' '\n"}, {"source_code": "n = gets.to_i\na = [[-1e9, -1e9]] + 1.upto(n).map{|i| gets.split.map(&:to_i) << i}.sort + [[1e9, 1e9]]\nb = a.map{1}\n1.upto(n + 1){|i| b[i] = b[i - 1] && a[i - 1][1] <= a[i][0]}\nc = a.map{1}\n(n).downto(0){|i| c[i] = c[i + 1] && a[i][1] <= a[i + 1][0]}\nd = (1 .. n).select{|i| b[i - 1] && c[i + 1] && a[i - 1][1] <= a[i + 1][0]}.map{|i| a[i][2]}\np d.size\nputs d.sort * ' '\n\n"}, {"source_code": "=begin\n , \\ / ,\n / \\ )\\__/( / \\\n / \\ (_\\ /_) / \\\n ____/_____\\__\\@ @/___/_____\\____\n | |\\../| |\n | \\VV/ |\n | ------hoi------- |\n |_________________________________|\n | /\\ / \\\\ \\ /\\ |\n | / V )) V \\ |\n |/ ` // ' \\|\n ` V '\n=end\n\nn = gets.to_i\na = [[-1e9, -1e9]] + 1.upto(n).map{|i| gets.split.map(&:to_i) << i}.sort + [[1e9, 1e9]]\nb = a.map{1}\n1.upto(n + 1){|i| b[i] = b[i - 1] && a[i - 1][1] <= a[i][0]}\nc = a.map{1}\n(n).downto(0){|i| c[i] = c[i + 1] && a[i][1] <= a[i + 1][0]}\nd = (1 .. n).select{|i| b[i - 1] && c[i + 1] && a[i - 1][1] <= a[i + 1][0]}.map{|i| a[i][2]}\np d.size\nputs d.sort * ' '"}, {"source_code": "n = gets.to_i\na = [[-1e9, -1e9]] + 1.upto(n).map{|i| gets.split.map(&:to_i) << i}.sort + [[1e9, 1e9]]\nb = a.map{1}\n1.upto(n + 1){|i| b[i] = b[i - 1] && a[i - 1][1] <= a[i][0]}\nc = a.map{1}\n(n).downto(0){|i| c[i] = c[i + 1] && a[i][1] <= a[i + 1][0]}\nd = (1 .. n).select{|i| b[i - 1] && c[i + 1] && a[i - 1][1] <= a[i + 1][0]}.map{|i| a[i][2]}\np d.size\nputs d.sort * ' '\n\n"}, {"source_code": "n = gets.to_i\na = [[-1e9, -1e9]] + 1.upto(n).map{|i| gets.split.map(&:to_i) << i}.sort + [[1e9, 1e9]]\nb = a.map{1}\n1.upto(n + 1){|i| b[i] = b[i - 1] && a[i - 1][1] <= a[i][0]}\nc = a.map{1}\n(n).downto(0){|i| c[i] = c[i + 1] && a[i][1] <= a[i + 1][0]}\nd = (1 .. n).select{|i| b[i - 1] && c[i + 1] && a[i - 1][1] <= a[i + 1][0]}.map{|i| a[i][2]}\np d.size\nputs d.sort * ' '\n\n"}, {"source_code": "n = gets.to_i\na = [[-1e9, -1e9]] + 1.upto(n).map{|i| gets.split.map(&:to_i) << i}.sort + [[1e9, 1e9]]\nb = a.map{1}\n1.upto(n + 1){|i| b[i] = b[i - 1] && a[i - 1][1] <= a[i][0]}\nc = a.map{1}\n(n).downto(0){|i| c[i] = c[i + 1] && a[i][1] <= a[i + 1][0]}\nd = (1 .. n).select{|i| b[i - 1] && c[i + 1] && a[i - 1][1] <= a[i + 1][0]}.map{|i| a[i][2]}\np d.size\nputs d.sort * ' '"}, {"source_code": "n = gets.to_i\na = [[-1e9, -1e9]] + 1.upto(n).map{|i| gets.split.map(&:to_i) << i}.sort + [[1e9, 1e9]]\nb = a.map{1}\n1.upto(n + 1){|i| b[i] = b[i - 1] && a[i - 1][1] <= a[i][0]}\nc = a.map{1}\n(n).downto(0){|i| c[i] = c[i + 1] && a[i][1] <= a[i + 1][0]}\nd = (1 .. n).select{|i| b[i - 1] && c[i + 1] && a[i - 1][1] <= a[i + 1][0]}.map{|i| a[i][2]}\np d.size\nputs d.sort * ' '\n\n"}, {"source_code": "n = gets.to_i\na = [[-1e9, -1e9]] + 1.upto(n).map{|i| gets.split.map(&:to_i) << i}.sort + [[1e9, 1e9]]\nb = a.map{1}\n1.upto(n + 1){|i| b[i] = b[i - 1] && a[i - 1][1] <= a[i][0]}\nc = a.map{1}\n(n).downto(0){|i| c[i] = c[i + 1] && a[i][1] <= a[i + 1][0]}\nd = (1 .. n).select{|i| b[i - 1] && c[i + 1] && a[i - 1][1] <= a[i + 1][0]}.map{|i| a[i][2]}\np d.size\nputs d.sort * ' '\n\n"}, {"source_code": "n = gets.to_i\na = [[-1e9, -1e9]] + 1.upto(n).map{|i| gets.split.map(&:to_i) << i}.sort + [[1e9, 1e9]]\nb = a.map{1}\n1.upto(n + 1){|i| b[i] = b[i - 1] && a[i - 1][1] <= a[i][0]}\nc = a.map{1}\n(n).downto(0){|i| c[i] = c[i + 1] && a[i][1] <= a[i + 1][0]}\nd = (1 .. n).select{|i| b[i - 1] && c[i + 1] && a[i - 1][1] <= a[i + 1][0]}.map{|i| a[i][2]}\np d.size\nputs d.sort * ' '\n\n"}, {"source_code": "n = gets.to_i\na = [[-1e9, -1e9]] + 1.upto(n).map{|i| gets.split.map(&:to_i) << i}.sort + [[1e9, 1e9]]\nb = a.map{1}\n1.upto(n + 1){|i| b[i] = b[i - 1] && a[i - 1][1] <= a[i][0]}\nc = a.map{1}\n(n).downto(0){|i| c[i] = c[i + 1] && a[i][1] <= a[i + 1][0]}\nd = (1 .. n).select{|i| b[i - 1] && c[i + 1] && a[i - 1][1] <= a[i + 1][0]}.map{|i| a[i][2]}\np d.size\nputs d.sort * ' '\n\n"}], "negative_code": [], "src_uid": "df28bb63a627a41d67f02cbd927d5e9a"} {"source_code": "m,d = gets.split.map{|s| s.to_i}\nmen = Array::new(m+1,0)\nd.times {\n\tcd = gets.split.map{|s| s.to_i}\n\tfixed = 1\n\tcd.each {|i| \n\t\tfixed = men[i] if men[i] > 0 # only one men participating in the dance may have color associated previously\n\t}\n\tidx = fixed\n\tcd.each {|i|\n\t\tif men[i] != fixed\n\t\t\tmen[i] = idx%3 + 1\n\t\t\tidx += 1\n\t\tend\t\n\t}\n}\nprint men[1..-1].join(\" \")", "positive_code": [{"source_code": "ar=Array.new(100100,0)\nn,m=gets.chomp.split.map(&:to_i)\nm.times do\n\ta=gets.chomp.split.map(&:to_i)\n\tb=[0,0,0,0]\n\tb[ar[a[0]]],b[ar[a[1]]],b[ar[a[2]]]=1,1,1\n\t3.times do |i|\n\t\tfor j in 1...4\n\t\t\tif b[j]==0 && ar[a[i]]==0\n\t\t\t\tar[a[i]]=j\n\t\t\t\tb[j]=1\n\t\t\tend\n\t\tend\n\tend\nend\nfor i in 1..n\n\tprint \"#{ar[i]} \"\nend\nputs"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\n\n\nassignment = {}\n\nm.times do\n\tarr = gets.split(\" \").map(&:to_i)\n\tcolors = [3,2,1]\n\tintersec = arr.detect{|a| assignment[a]}\n\tif intersec\n\t\tarr = arr - [intersec]\n\t\tcolors -= [assignment[intersec]]\n\t\t# puts \"colors #{intersec}\"\n\tend\n\tarr.each do |a|\t\t\n\t\tassignment[a] = colors.pop\t\t\n\tend\nend\nans = []\nassignment.keys.sort.each do |k|\n\tans << assignment[k]\t\nend\nputs ans.join(\" \")"}, {"source_code": "inp = gets.split.map(&:to_i)\nd = inp[1].times.map{gets.split.map(&:to_i)}\nans = Array.new(inp[0])\nd.each do |x|\n\tif ans[x[0]]==1 && ans[x[1]]==2\n\t\tans[x[2]] = 3\n\telsif ans[x[0]]==1 && ans[x[1]]==3\n\t\tans[x[2]] = 2\n\telsif ans[x[0]]==2 && ans[x[1]]==3\n\t\tans[x[2]] = 1\n\telsif ans[x[0]]==1 && ans[x[2]]==2\n\t\tans[x[1]] = 3\n\telsif ans[x[0]]==1 && ans[x[2]]==3\n\t\tans[x[1]] = 2\n\telsif ans[x[0]]==2 && ans[x[2]]==3\n\t\tans[x[1]] = 1\n\telsif ans[x[1]]==1 && ans[x[2]]==2\n\t\tans[x[0]] = 3\n\telsif ans[x[1]]==1 && ans[x[2]]==3\n\t\tans[x[0]] = 2\n\telsif ans[x[1]]==2 && ans[x[2]]==3\n\t\tans[x[0]] = 1\n\telsif ans[x[0]] == 1\n\t\tans[x[1]] = 2\n\t\tans[x[2]] = 3\n\telsif ans[x[0]] == 2\n\t\tans[x[1]] = 1\n\t\tans[x[2]] = 3\n\telsif ans[x[0]] == 3\n\t\tans[x[1]] = 1\n\t\tans[x[2]] = 2\n\telsif ans[x[1]] == 1\n\t\tans[x[0]] = 2\n\t\tans[x[2]] = 3\n\telsif ans[x[1]] == 2\n\t\tans[x[0]] = 1\n\t\tans[x[2]] = 3\n\telsif ans[x[1]] == 3\n\t\tans[x[0]] = 1\n\t\tans[x[2]] = 2\n\telsif ans[x[2]] == 1\n\t\tans[x[0]] = 2\n\t\tans[x[1]] = 3\n\telsif ans[x[2]] == 2\n\t\tans[x[0]] = 1\n\t\tans[x[1]] = 3\n\telsif ans[x[1]] == 3\n\t\tans[x[0]] = 1\n\t\tans[x[1]] = 2\n\telse\n\t\tans[x[0]] = 1\n\t\tans[x[1]] = 2\n\t\tans[x[2]] = 3\n\tend\nend\n\n(inp[0]+1).times do |i|\n\tif i>0\n\t\tprint ans[i]\n\t\tprint \" \"\n\tend\nend"}, {"source_code": "def solution(n, dancers)\n input = {}\n value = 0\n\n dancers.each do |i|\n color = [1, 2, 3]\n value = 0\n\n i.each do |j|\n if input.has_key?(j)\n color.delete(input[j])\n end\n end\n\n i.each_with_index do |j, k|\n value += 1 if input.has_key?(j)\n input[j] = color[k-value] unless input.has_key?(j)\n end\n end\n\n output = []\n n.times { |i| output << input[i+1] }\n\n output.join(\" \") \nend\n\n\nn, m = STDIN.readline.split(\" \").map(&:to_i)\ndancers = []\nm.times do \n dancers << STDIN.readline.split(\" \").map(&:to_i)\nend\n\nvalues = solution(n,dancers)\nputs values\n\n\n"}, {"source_code": "#! /usr/bin/env ruby\n\nWHITE = 4\nRED = 2\nBLUE = 1\n\ndef convert(calc_num)\n case calc_num\n when WHITE\n 1\n when RED\n 2\n when BLUE\n 3\n end\nend\n\nn, m = STDIN.gets.split(' ').map(&:to_i)\ndances = []\nm.times {\n dances << STDIN.gets.split(' ').map(&:to_i)\n}\n\n\ncolors = Array.new(n){0}\n\ndef fill(colors, dancers, color)\n dancers.each do |dancer|\n if colors[dancer.to_i - 1].zero?\n colors[dancer.to_i - 1] = color\n break\n end\n end\n colors\nend\n\ndances.each do |dancers|\n result = dancers.inject(0) {|s, i|\n s += colors[i - 1]\n }\n next if result == 7\n\n if result < WHITE\n colors = fill(colors, dancers, WHITE)\n else\n result -= WHITE\n end\n\n if result < RED\n colors = fill(colors, dancers, RED)\n else\n result -= RED\n end\n\n if result < BLUE\n colors = fill(colors, dancers, BLUE)\n end\nend\n\nanswer = colors.map do |color|\n convert(color)\nend.join(' ')\nputs answer\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\ncolor = Array.new(n+1, 0)\nfor i in 0...m\n a = gets.split.map(&:to_i)\n mark = Array.new(4, false)\n mark[color[a[0]]] = true\n mark[color[a[1]]] = true\n mark[color[a[2]]] = true\n if !mark[1] then\n for j in 0..2\n if color[a[j]] == 0 then\n\tcolor[a[j]] = 1\n\tbreak\n end\n end\n end\n if !mark[2] then\n for j in 0..2\n if color[a[j]] == 0 then\n\tcolor[a[j]] = 2\n\tbreak\n end\n end\n end\n if !mark[3] then\n for j in 0..2\n if color[a[j]] == 0 then\n\tcolor[a[j]] = 3\n\tbreak\n end\n end\n end\nend\n\nfor i in 1..n\n print color[i], \" \"\nend\n\n"}], "negative_code": [{"source_code": "n,m = gets.split(\" \").map(&:to_i)\n\n\nassignment = {}\n\nm.times do\n\tarr = gets.split(\" \").map(&:to_i)\n\tcolors = [3,2,1]\n\tintersec = arr.detect{|a| assignment[a]}\n\tif !intersec\n\t\tarr = arr - [intersec]\n\t\tcolors -= [assignment[intersec]]\n\t\t# puts \"colors #{intersec}\"\n\tend\n\tarr.each do |a|\t\t\n\t\tassignment[a] = colors.pop\t\t\n\tend\nend\nans = []\nassignment.keys.sort.each do |k|\n\tans << assignment[k]\t\nend\nputs ans.join(\" \")"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\n\n\nassignment = {}\n\nm.times do\n\tarr = gets.split(\" \").map(&:to_i)\n\tcolors = [3,2,1]\n\tintersec = arr & assignment.keys\n\tif !intersec.empty?\n\t\tarr = arr - assignment.keys \n\t\tcolors -= [assignment[intersec[0]]]\n\t\t# puts \"colors #{intersec}\"\n\tend\n\tarr.each do |a|\t\t\n\t\tassignment[a] = colors.pop\t\t\n\tend\nend\nputs assignment.values.join(\" \")"}, {"source_code": "def solution(n, dancers)\n input = {}\n value = 0\n\n dancers.each do |i|\n color = [1, 2, 3]\n value = 0\n i.each_with_index do |j, k|\n if input.has_key?(j)\n color.delete(input[j])\n value += 1\n else\n input[j] = color[k-value]\n end\n end\n end\n\n input.values.join(\" \") \nend\n\n\nn, m = STDIN.readline.split(\" \").map(&:to_i)\ndancers = []\nm.times do \n dancers << STDIN.readline.split(\" \").map(&:to_i)\nend\n\nvalues = solution(n,dancers)\nputs values\n"}, {"source_code": "def solution(n, dancers)\n input = {}\n value = 0\n\n dancers.each do |i|\n color = [1, 2, 3]\n value = 0\n i. each do |j| \n if input.has_key?(j)\n color.delete(input[j])\n value += 1\n end\n end\n\n i.each_with_index do |j, k|\n input[j] = color[k-value]\n end\n end\n\n output = []\n n.times { |i| output << input[i+1] }\n\n output.join(\" \") \nend\n\n\nn, m = STDIN.readline.split(\" \").map(&:to_i)\ndancers = []\nm.times do \n dancers << STDIN.readline.split(\" \").map(&:to_i)\nend\n\nvalues = solution(n,dancers)\nputs values\n\n\n"}, {"source_code": "def solution(n, dancers)\n input = {}\n value = 0\n\n dancers.each do |i|\n color = [1, 2, 3]\n value = 0\n i. each do |j| \n if input.has_key?(j)\n color.delete(input[j])\n value += 1\n end\n end\n\n i.each_with_index do |j, k|\n input[j] = color[k]\n end\n end\n\n output = []\n n.times { |i| output << input[i+1] }\n\n output.join(\" \") \nend\n\n\nn, m = STDIN.readline.split(\" \").map(&:to_i)\ndancers = []\nm.times do \n dancers << STDIN.readline.split(\" \").map(&:to_i)\nend\n\nvalues = solution(n,dancers)\nputs values\n\n\n"}, {"source_code": "def solution(n, dancers)\n input = {}\n value = 0\n\n dancers.each do |i|\n color = [1, 2, 3]\n value = 0\n i.each_with_index do |j, k|\n if input.has_key?(j)\n color.delete(input[j])\n value += 1\n else\n input[j] = color[k-value]\n end\n end\n end\n\n output = []\n n.times { |i| output << input[i+1] }\n\n output.join(\" \") \nend\n\n\nn, m = STDIN.readline.split(\" \").map(&:to_i)\ndancers = []\nm.times do \n dancers << STDIN.readline.split(\" \").map(&:to_i)\nend\n\nvalues = solution(n,dancers)\nputs values\n"}], "src_uid": "ee523bb4da5cb794e05fb62b7da8bb89"} {"source_code": "n = gets.chomp.to_i\nn.times do \n\tngo = gets.chomp.to_i\n\tif ngo <= 3\n\t\tputs 4 - ngo\n\telsif ngo.even?\n\t\tputs 0\n\telse\n\t puts 1\n\tend\nend\n\n\n\n", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n puts n == 2 ? 2 : n % 2\nend"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1223/A\n\ncount = gets.to_i\nanswers = []\n\ncount.times do\n match_count = gets.to_i\n answers << if match_count == 2\n 2\n else\n match_count % 2\n end\nend\n\nanswers.each { |answer| puts answer }\n"}, {"source_code": "q = gets.to_i\nq.times do\n n = gets.to_i\n if n == 1\n puts 3\n elsif n == 2\n puts 2\n else\n a = (n.to_f/2).ceil\n b = n - a\n puts (a-b).abs\n end\nend\n"}, {"source_code": "q = gets.to_i\nq.times do\n n = gets.to_i\n puts n < 4 ? 4 - n : n%2\nend\n"}, {"source_code": "1.upto(gets.to_i) do\n n = gets.to_i\n\n case n\n when 2..4\n puts 4 - n\n when proc(&:odd?)\n puts 1\n else\n puts 0\n end\nend\n"}], "negative_code": [], "src_uid": "178876bfe161ba9ccfd80c9310f75cbc"} {"source_code": "t = Integer(gets)\r\n\r\nfor i in 0..t-1\r\n n = Integer(gets)\r\n arr = Array.new\r\n a = gets\r\n arr = a.split(\" \")\r\n \r\n for j in 0..n-1\r\n arr[j] = Integer(arr[j]);\r\n end\r\n \r\n mn = arr.min\r\n ans = 0\r\n for j in 0..n-1\r\n ans += (arr[j] - mn)\r\n end\r\n puts ans\r\nend", "positive_code": [{"source_code": "gets.to_i.times do\n gets\n as = gets.split.map(&:to_i)\n m = as.min\n puts as.map { _1 - m }.sum\nend\n"}, {"source_code": "def main\n gets.to_i.times do\n n = gi\n a = gli.sort\n puts a.sum - a[0] * n\n end\nend\n\nMOD = 10**9 + 7\ndef gs = gets.chomp\ndef gi = gets.to_i\ndef gli = gets.split.map(&:to_i)\ndef cyesno(x) = x ? :Yes : :No\ndef uyesno(x) = x ? :YES : :NO\n\nmain\n"}, {"source_code": "main = -> {\r\n T = int\r\n T.times do\r\n n = int\r\n a = ints\r\n m = a.min\r\n puts a.sum { |x| x - m }\r\n end\r\n}\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\n$yesno = %w(No Yes)\r\nYesNo = %w(No Yes)\r\nYESNO = %w(NO YES)\r\nINF = 10**18\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t] end\r\ndef YesNo t; puts YesNo[t] end\r\ndef YESNO t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]"}, {"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n min = xs.min\r\n p xs.map { |x| x - min }.sum\r\nend\r\n"}], "negative_code": [], "src_uid": "20dd260775ea71b1fb5b42bcac90a6f2"} {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nn = inp[0]\nn.times do\n d = inp[0]\n keta = 0\n ld = d\n li = 0\n 100000.times do |i|\n ld = d\n keta += (i+1).to_s.size\n d -= keta\n li = i\n break if(d <= 0)\n end\n pta = keta\n keta = 0\n d = ld\n while 0 < d\n ld = d\n keta += 1\n d -= (9*(10**(keta-1)))*keta\n end\n ld -= 1\n no = ld % keta\n ka = ld/keta\n puts (ka+10**(keta-1)).to_s[no]\nend", "positive_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n \ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n \ndef inps() a=gets.chomp.split(\" \")end\n \ndef copy(a) Marshal.load(Marshal.dump(a)) end\n \ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n \ndef na(n,d=0) Array.new(n,d)end\n \ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n \ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n \ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n \ndef r_up(a, b) (a+b-1)/b end\n \ndef sum(a) a.inject(:+) end\n \nn = inp[0]\nn.times do\n d = inp[0]\n keta = 0\n ld = d\n li = 0\n 100000.times do |i|\n ld = d\n keta += (i+1).to_s.size\n d -= keta\n li = i\n break if(d <= 0)\n end\n pta = keta\n keta = 0\n d = ld\n while 0 < d\n ld = d\n keta += 1\n d -= (9*(10**(keta-1)))*keta\n end\n ld -= 1\n no = ld % keta\n ka = ld/keta\n puts (ka+10**(keta-1)).to_s[no]\nend"}], "negative_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nn = inp[0]\nn.times do\n d = inp[0]\n keta = 0\n ld = d\n li = 0\n 100000.times do |i|\n ld = d\n keta += (i+1).to_s.size\n d -= keta\n li = i\n break if(d <= 0)\n end\n pta = keta\n keta = 0\n d = ld\n while 0 <= d\n ld = d\n keta += 1\n d -= (9*(10**(keta-1)))*keta\n end\n ld -= 1\n no = ld % keta\n ka = ld/keta\n puts (ka+10**(keta-1)).to_s[no]\nend"}], "src_uid": "7e03c9e316f36c1d9487286237e24c6f"} {"source_code": "\nn = gets.to_i\ns = gets.chomp\n\nk = n % 3\nr = ''\nif k != 0\n r = s[0, 2] + '-'\n s = s[2 ... s.length]\nend\n\nfor i in 0...n/3\n r = r + s[3 * i, 3] + '-'\nend\nputs r[0, r.length - 1]\n", "positive_code": [{"source_code": "d=gets.to_i\nw=gets\nif d%2==0\n\tputs w.scan(/../)*'-'\nelse\n\tputs [w[0,3],*w[3..-1].scan(/../)]*'-'\nend"}, {"source_code": "n = gets.chomp.to_i\ns = gets.chomp\nfirst = true\nif n % 2 == 0\n\twhile s.length > 0\n\t\tprint \"-\" if not first\n\t\tprint s.slice!(0,2)\n\t\tfirst = false\n\tend\nelse\n\tlen = 3\n\twhile s.length > 0\n\t\tprint \"-\" if not first\n\t\tprint s.slice!(0,len)\n\t\tfirst = false\n\t\tlen = 2\n\tend\nend\nputs\n"}, {"source_code": "#!/usr/bin/ruby\ngets;s=gets.chomp\nif s.size%3==1\n\tt=s[-4..-1]\n\tx=s[0..-5].chars.each_slice(3).map{|e|e*''}*'-'\n\tputs (x.size>0 ? x+'-' : '')+t[0,2]+'-'+t[2,2]\nelse\n\tputs s.chars.each_slice(3).map{|e|e*''}*'-'\nend"}, {"source_code": "gets\ns = gets.chop\nprint s.slice!(0..1)+'-' if s.size % 3 == 1\ns.gsub!(/.../){$&+'-'}\ns.chop! if s =~ /-$/\nputs s\n"}, {"source_code": "\nn=gets.to_i\nm=gets.split[0]\ni=0\ns=0\nif n%3==1 then\n print m[0..1]\n print \"-\"\n print m[2..3]\n s=1\n i=4\nelsif n%3==2 then\n print m[0..1]\n s=1\n i=2\nend\nwhile i0 then\n print \"-\"\n end\n s=1\n print m[i..(i+2)]\n i+=3\nend\nputs\n\n"}, {"source_code": "n=gets.chomp.to_i\nphone=gets.chomp\ns=\"\"\nif n%2==0\n n.times do |i|\n s+=phone[i,1]\n if i%2 == 1\n s+=\"-\"\n end\n end\n puts s[0,s.length-1]\nelse\n (n-2).times do |i|\n s+=phone[i,1]\n if i%2 == 1\n s+=\"-\"\n end\n end\n s+=phone[-2,3]\n puts s\nend\n"}, {"source_code": "digits = gets.to_i\nnumber = gets.chomp\nif digits % 2 == 0\n telephone = number.scan(/.{2}/)\n (0...telephone.size).each do |i|\n if i == telephone.size - 1\n puts telephone[i]\n else\n print \"#{telephone[i]}-\"\n end\n end\nelse\n if digits % 3 == 0\n telephone = number.scan(/.{3}/)\n (0...telephone.size).each do |i|\n if i == telephone.size - 1\n puts telephone[i]\n else\n print \"#{telephone[i]}-\"\n end\n end\n else\n if (digits-3) % 2 == 0\n telephone = number[0...digits-3].scan(/.{2}/)\n (0...telephone.size).each do |i|\n print \"#{telephone[i]}-\"\n end\n puts number[digits-3...digits]\n end\n end\nend"}, {"source_code": "n, phone = gets, gets.chomp\nleft = phone.length\ni=0\ns=\"\"\nwhile left>0\n s+=\"-\" if s!=\"\"\n x = left==3?2:1;\n s << phone[i..i+x]\n i = i+x+1\n left = left-x-1\nend\nputs s"}, {"source_code": "n = gets.to_i\ngets.strip.each_char.with_index do |y,i|\n if i > 0 && (i%2 == 0 && i < n-1 || i == n-3 && n%2 != 0)\n print '-';\n end\n print y\nend\n"}, {"source_code": "n = gets.to_i\ngets.strip.each_char.with_index do |y,i|\n if i > 0 && (i%2 == 0 && i < n-1 || i == n-3 && n%2 != 0)\n print '-';\n end;\n print y;\nend;\n"}, {"source_code": "n = gets.to_i\ngets.strip.each_char.with_index do |y,i|\n if i > 0 && (i%2 == 0 && i < n-1 || i == n-3 && n%2 != 0)\n print '-';\n end;\n print y\nend\n"}, {"source_code": "n = gets.to_i\ngets.strip.each_char.with_index do |y,i|\n if i > 0 && (i%2 == 0 && i < n-1 || i == n-3 && n%2 != 0)\n print '-'\n end\n print y\nend\n"}, {"source_code": "n = gets.to_i\ngets.strip.each_char.with_index do |y,i|\n if i > 0 && (i%2 == 0 && i < n-1 || i == n-3 && n%2 != 0)\n print '-';\n end;\n print y;\nend\n"}, {"source_code": "n = gets.to_i\ngets.strip.each_char.with_index do |y,i|\n if i > 0 && (i%2 == 0 && i < n-1 || i == n-3 && n%2 != 0);\n print '-';\n end;\n print y;\nend;\n"}, {"source_code": "numOfDigits = gets.chomp.to_i\nphoneNumber = gets.chomp\n\ndiv5 = numOfDigits / 5\nmod5 = numOfDigits % 5\n\nnumOf2 = div5\nnumOf3 = div5\n\nif mod5 > 0\n if mod5 % 2 == 0\n #2 or 4\n numOf2 = numOf2 + (mod5 / 2)\n elsif mod5 % 3 == 0\n #3\n numOf3 = numOf3 + 1\n else\n #1\n numOf2 = numOf2 - 1\n numOf3 = numOf3 + 1\n end \nend\n\nresult = \"\"\nindex = 0\n\n1.upto(numOf2) do |i|\n result = result + \"-\" + phoneNumber[index, 2]\n index = index + 2 \nend\n\n1.upto(numOf3) do |i|\n result = result + \"-\" + phoneNumber[index, 3]\n index = index + 3 \nend\n\nif result[0, 1] == \"-\"\n result = result[1, result.length - 1]\nend\n\nputs result"}, {"source_code": "gets\nphone = gets.chomp.scan(/./)\n\nres = \"\"\nwhile phone.size >= 2\n res << phone.shift(2).join << '-'\nend\nres = res[0..-2]\nres << phone.join\n\nputs res"}, {"source_code": "puts gets.to_i%2<1 ? gets.scan(/../).to_a*\"-\" : ([gets[0..2]]+$_[3..-1].scan(/../).to_a)*\"-\""}], "negative_code": [{"source_code": "gets\nw=gets\nif w.size%2==0\n\tputs w.scan(/../)*'-'\nelse\n\tputs [*w[0..-3].scan(/../),w[-3..-1]]*'-'\nend"}, {"source_code": "gets\nw=gets\nif w.size%2==0\n\tputs w.scan(/../)*'-'\nelse\n\tputs [w[0,3],*w[3..-1].scan(/../)]*'-'\nend"}, {"source_code": "#!/usr/bin/ruby\ngets;s=gets.chomp\nif s.size%3==1\n\tt=s[-4..-1]\n\tputs s[0..-5].chars.each_slice(3).map{|e|e*''}*'-'+'-'+t[0,2]+'-'+t[2,2]\nelse\n\tputs s.chars.each_slice(3).map{|e|e*''}*'-'\nend"}], "src_uid": "6f6859aabc1c9cbb9ee0d910064d87c2"} {"source_code": "n=gets.to_i\na=n.times.map{gets.split.map(&:to_i).max}\na[a.index(n-1)]=n\nputs a*' '", "positive_code": [{"source_code": "n = gets.to_i\nm = (1..n).map{gets.strip.split(\" \").map(&:to_i)}\n\na = [nil] * n\n\ni = 1\nwhile i <= n\n m.each_with_index do |s, k|\n if s.all? {|x| x <= i} && s.any? {|x| x == i-1}\n a[k] = i\n i += 1\n end\n end\nend\n\nputs a.join(\" \")\n"}, {"source_code": "# http://codeforces.com/problemset/problem/618/B\n\nn = gets.to_i\nans = []\nn.times do |i|\n arr = gets.split.map(&:to_i)\n ans << arr.max\nend\nans[ans.index(n - 1)] = n\nputs ans * \" \""}, {"source_code": "n=gets.to_i\na=n.times.map{gets.split.map(&:to_i).max}\na[a.index(n-1)]=n\nputs a*' '\n"}, {"source_code": "n=gets.to_i\na=n.times.map{gets.split.map(&:to_i).max}\na[a.index(n-1)]=n\nputs a*' '\n"}, {"source_code": "n = gets.chomp.to_i\nps = []\nf = false\nn.times do\n as = gets.chomp.split.map(&:to_i)\n p = as.sort!.uniq.size - 1\n if p == n - 1\n ps << (f ? p : n)\n f = true\n else\n ps << p\n end\nend\n\nputs ps.*' '\n"}, {"source_code": "n = gets.to_i\ng = []\nfor _ in 0...n\n a = gets.split(' ').map(&:to_i)\n g << a\nend\n\nr = []\nfor j in 0...n\n for k in 0..j\n if g[j][k] == n-1\n r[j] = n\n r[k] = n-1\n end\n end\nend\n\nfor i in 2...n\n x = n-i\n for j in 0...n\n for k in 0..j\n if g[j][k] == x && (!r[j] || !r[k])\n if r[k]\n r[j] = x\n else\n r[k] = x\n end\n end\n end\n end\nend\n\nputs r.join(' ')"}, {"source_code": "n = gets.chomp.to_i\nn.times do |i|\n r = gets.chomp.split(\" \")\n if r.uniq.length == n then\n r[i] = n\n puts r.join(\" \")\n exit\n end\nend\n"}, {"source_code": "n=gets.to_i\na=n.times.map{gets.split.map(&:to_i).max}\na[a.index(n-1)]=n\nputs a*' '\n"}, {"source_code": "n=gets.to_i\na=n.times.map{gets.split.map(&:to_i).max}\na[a.index(n-1)]=n\nputs a*' '\n"}, {"source_code": "n=gets.to_i\na=n.times.map{gets.split.map(&:to_i).max}\na[a.index(n-1)]=n\nputs a*' '\n"}], "negative_code": [{"source_code": "# http://codeforces.com/problemset/problem/618/B\n\nn = gets.to_i\nans = []\nn.times do |i|\n arr = gets.split.map(&:to_i)\n ans << arr.max\nend\nans[ans.index(n - 1)] = n\np ans * \" \""}], "src_uid": "1524c658129aaa4175208b278fdc467c"} {"source_code": "gets;n=gets;k,l,m=n.count(\"1\"),n.count(\"2\"),n.count(\"3\");puts (k>l ?(k>m ?(m+l):(k+l)):(l>m ?(k+m):(k+l)))", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nputs n - (1..3).map{|x| a.count(x)}.max\n"}, {"source_code": "def function\na=gets.chomp\nb=gets.chomp\nb=b.split.map(&:to_i)\nputs (b.length-b.count(b.uniq.max_by{ |i| b.count( i ) }))\nend\nfunction\n"}, {"source_code": "a=gets.to_i;gets;p a-(?1..?3).map{|i|$_.count i}.max\n"}, {"source_code": "a=gets.to_i;gets;p a-(?1..?3).map{|i|$_.count i}.max\n"}, {"source_code": "n = gets.chomp.to_i\nints = gets.chomp.split\nh = Hash.new(0)\nints.each { |i| h[i] += 1 }\nputs n - h.values.max"}, {"source_code": "a=gets.to_i;gets;p a-(?1..?3).map{|i|$_.count i}.max"}, {"source_code": "n=gets.to_i\narr=gets.split(' ').map(&:to_i)\na = [0,0,0,0]\narr.each do |x|\na[x] += 1\nend\nb = [a[1]+a[2],a[1]+a[3],a[2]+a[3]]\nputs b.min"}, {"source_code": "a=gets.to_i;gets;p a-(?1..?3).map{|i|$_.count i}.max\n"}, {"source_code": "a=gets.to_i;gets;p a-(?1..?3).map{|i|$_.count i}.max\n"}, {"source_code": "a=gets.to_i;gets;p a-(?1..?3).map{|i|$_.count i}.max"}, {"source_code": "n = gets\narr = gets\n\nnr1 = 0\nnr2 = 0\nnr3 = 0\n\narr.split(\" \").map(&:to_i).each do |x|\n if x == 1\n nr1 += 1\n elsif x == 2\n nr2 += 1\n else\n nr3 += 1\n end\nend\n\nputs n.to_i - [nr1,nr2, nr3].max"}, {"source_code": "a=gets.to_i;gets;p a-(?1..?3).map{|i|$_.count i}.max"}, {"source_code": "a=gets.to_i;gets;p a-(?1..?3).map{|i|$_.count i}.max\n"}, {"source_code": "n = gets.chomp.to_i\nints = gets.chomp.split\nh = Hash.new(0)\nints.each { |i| h[i] += 1 }\nputs n - h.values.max"}, {"source_code": "n = gets.chomp.to_i\nints = gets.chomp.split\nh = Hash.new(0)\nints.each { |i| h[i] += 1 }\nputs n - h.values.max"}, {"source_code": "a=gets.to_i;gets;p a-(?1..?3).map{|i|$_.count i}.max\n"}, {"source_code": "a=gets.to_i;gets;p a-(?1..?3).map{|i|$_.count i}.max\n"}, {"source_code": "gets\ngets\np [*?1..?3].map{|_|$_.count _}.combination(2).map{|a,b|a+b}.min"}, {"source_code": "gets; n = gets.strip\nprint [n.count(\"1\"), n.count(\"2\"), n.count(\"3\")].sort[0,2].inject(0) { |sum, e| sum += e }\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\nputs n - [a.select {|x| x == 3 }.length, a.select{|x| x==2}.length, a.select{|x| x==1}.length].max"}], "negative_code": [{"source_code": "def function\na=gets.chomp\nb=gets.chomp\nb=b.split.map(&:to_i)\nprint (b.length-b.count(b.uniq.max_by{ |i| b.count( i ) }))\nend\n"}, {"source_code": "def function\na=gets.chomp\nb=gets.chomp\nb=b.split.map(&:to_i)\nputs b.length-b.count(b.uniq.max_by{ |i| b.count( i ) })\nend\n"}, {"source_code": "n = gets\narr = gets\n\nnr1 = 0\nnr2 = 0\nnr3 = 0\n\narr.split(\" \").map(&:to_i).each do |x|\n if x == 1\n nr1 += 1\n elsif x == 2\n nr2 += 1\n else\n nr3 += 1\n end\nend\n\nn.to_i - [nr1,nr2, nr3].max"}, {"source_code": "n = gets\narr = gets\n\nnr1 = 0\nnr2 = 0\nnr3 = 0\n\nif n.to_i == 0\n puts 0\nelsif n.to_i == 1\n puts 0\nend\n\narr.split(\" \").map(&:to_i).each do |x|\n if x == 1\n nr1 += 1\n elsif x == 2\n nr2 += 1\n else\n nr3 += 1\n end\nend\n\nputs n.to_i - [nr1,nr2, nr3].max"}, {"source_code": "n = gets\narr = gets\n\nnr1 = 0\nnr2 = 0\nnr3 = 0\n\nif n.to_i == 0\n puts 0\nelsif n.to_i == 1\n puts 1\nend\n\narr.split(\" \").map(&:to_i).each do |x|\n if x == 1\n nr1 += 1\n elsif x == 2\n nr2 += 1\n else\n nr3 += 1\n end\nend\n\nputs n.to_i - [nr1,nr2, nr3].max"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\nputs n - [a.select {|x| x == 1 }.length, a.select{|x| x==2}.length, a.select{|x| x==1}.length].max"}], "src_uid": "fcb6a715dfe302d7ae5a6695ca8976aa"} {"source_code": "gets\nflowers = gets.chomp.split.map(&:to_i).sort\nsum = flowers.inject(0) { |s, v| s + v }\n\nif sum.odd?\n puts sum\n exit\nelse\n first_odd = flowers.detect{ |f| f.odd? }\n if first_odd\n puts sum - first_odd\n exit\n end\nend\nputs 0", "positive_code": [{"source_code": "s = gets\nodds = []\nevens = []\n\ngets.split(\" \").each {|e|\n t = e.to_i\n if (t % 2 == 0)\n evens.push t\n else\n odds.push t\n end\n}\n\nodds.sort!\nevens.sort!\n\nif (odds.size == 0)\n puts 0\nelse\n t = odds.inject(0) {|r, i| r + i} + evens.inject(0) {|r, i| r + i}\n if (odds.size % 2 == 0) \n t -= odds[0]\n end\n puts t\nend\n"}, {"source_code": "N = gets.to_i\na = gets.split(' ').map {|i| i.to_i}\nsum = a.inject(0) {|s, i| s + i}\ncntNe = a.inject(0) {|s, i|\n r = s\n r += 1 if i % 2 != 0\n r\n}\n\nif cntNe == 0\n puts 0\n exit\nend\n\nif cntNe % 2 != 0\n puts sum\n exit\nend\n\nputs sum - a.select{|i| i % 2 != 0}.min"}, {"source_code": "n = gets.chomp\ninput = gets.chomp.split(' ').collect { |i| i.to_i }\nsum = 0\n\nsmallestOdd = input.collect do |i| \n\t\t\t\t\tif i.odd? then i else 101 end\n\t\t\t end.min\nsmallestOdd = -1 if smallestOdd == 101\ninput.each { |i| sum = sum + i }\n\nif sum.odd? \n puts sum\nelsif smallestOdd == -1\nputs 0\nelse \nputs sum - smallestOdd\nend\n\n\n\n\n\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i).sort\nb,c=[],[]\na.each{|k|\n if k%2==0 then\n b.push(k)\n else\n c.push(k)\n end\n}\ninit=1\nif c.length==0 then\n puts 0\n exit\nend\nans=0\nif c.length%2==0 then\n for i in 1..(c.length-1)\n ans+=c[i]\n end\nelse\n for i in 0..(c.length-1)\n ans+=c[i]\n end\nend\nb.each{|k| ans+=k}\np ans\n"}], "negative_code": [{"source_code": "\nn=gets.to_i\na=gets.split.map(&:to_i)\nb,c=[],[]\na.each{|k|\n if k%2==0 then\n b.push(k)\n else\n c.push(k)\n end\n}\ninit=1\nif c.length==0 then\n puts 0\n exit\nend\nans=0\nif c.length%2==0 then\n for i in 1..(c.length-1)\n ans+=c[i]\n end\nelse\n for i in 0..(c.length-1)\n ans+=c[i]\n end\nend\nb.each{|k| ans+=k}\np ans\n"}, {"source_code": "n = gets.chomp\ninput = gets.chomp.split(' ').collect { |i| i.to_i }\nsum = 0\n\nsmallestOdd = input.collect do |i| \n\t\t\t\t\tif i.odd? then i else 101 end\n\t\t\t end.min\nsmallestOdd = 0 if smallestOdd == 101\ninput.each { |i| sum = sum + i }\n\nif sum.odd? then puts sum\nelse puts sum - smallestOdd\nend\n\n\n\n\n\n\n"}, {"source_code": "\n\nn = gets.chomp\ninput = gets.chomp.split(' ').collect { |i| i.to_i }\nsum = 0\n\nsmallestOdd = input.collect do |i| \n\t\t\t\t\tif i.odd? then i else 101 end\n\t\t\t end.min\ninput.each { |i| sum = sum + i }\n\nputs sum - smallestOdd if sum.even?\nputs sum if sum.odd?\n\n\n\n"}, {"source_code": "gets\nflowers = gets.chomp.split.map(&:to_i).sort\nsum = flowers.inject(0) { |s, v| s + v }\n\nif sum.odd?\n puts sum\n exit\nelse\n while flowers.size > 0\n sum = sum - flowers.shift\n if sum.odd?\n puts sum\n exit\n end\n end\nend\nputs 0"}], "src_uid": "a5d56056fd66713128616bc7c2de8b22"} {"source_code": "tc = gets().to_i\ntc.times do\n n = gets().to_i\n arr = gets().split(' ').map(&:to_i).sort\n k = true\n for i in (1..n-1) do\n if arr[i]-arr[i-1] > 1\n puts \"NO\";\n k = false\n break;\n end\n end\n if (k)\n puts \"YES\"\n end\nend", "positive_code": [{"source_code": "gets.to_i.times do\n answer = true\n \n gets\n gets.split(' ').map(&:to_i).sort.each_cons(2) { |a, b| answer &&= b - a <= 1 }\n \n puts answer ? 'YES' : 'NO'\nend"}, {"source_code": "gets.to_i.times do\n gets\n a = gets.split(' ').map(&:to_i).sort\n\n p = a.shift\n x = 0\n\n while a.size > 0\n x += 1 if (a.first - p).abs > 1\n p = a.shift\n end\n\n puts x.zero? ? \"YES\" : \"NO\"\nend\n"}, {"source_code": "test_case = gets.to_i\ni = 0\nwhile i < test_case\n result = true\n i += 1\n len_ = gets.to_i\n Acase = gets.chomp.split(' ').map(&:to_i)\n Acase.sort!\n #puts Acase.inspect()\n j = 0\n while j < len_-1\n \n if Acase[j+1].to_i - Acase[j].to_i >= 2\n result = false\n j += 1\n break\n end\n j += 1\n end\n puts (result) ? \"Yes\" : \"No\" \n \nend"}, {"source_code": "gets.to_i.times do\n answer = true\n\n gets\n gets.split(' ').map(&:to_i).sort.each_cons(2) { |a, b| answer &&= b - a <= 1 }\n\n puts answer ? 'YES' : 'NO'\nend\n"}, {"source_code": "t=gets.chomp.to_i\n#p \"t= #{t}\"\nwhile t!=0\n\nlen=gets.chomp.to_i\n#p \"length= #{len}\"\nk=0\n#while k<=len-1\nar = gets.chomp.split(' ').map!{ |o| o.to_i }\n#k+=1\n#end\nar.sort!\n #p ar\ndef func(ar)\n \nl=ar.size\nif l==1\n return \"YES\"\nend\n i=0\nwhile i < l-1\n \nif ar[i+1]-ar[i]>1\n return \"NO\"\nend\ni+=1\nend\nreturn \"YES\"\nend\n \n \nputs func(ar)\n \nt-=1\nend"}, {"source_code": "times = gets.to_i\n\ndef resolve(array)\n array.sort.each_cons(2) {|e,n| return \"NO\" if n-e >1}\n \"YES\"\nend\n\n(1..times).each do |i|\n array_size = gets.to_i\n\n a = Array.new(array_size)\n a = gets.split(/\\s+/).map(&:to_i)\n puts resolve(a)\nend"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n aa = a.sort\n i = 0\n while true\n if n.to_s == \"1\"\n puts \"YES\"\n break\n end\n sa = (aa[i+1] - aa[i]).abs\n if sa <= 1\n aa.shift\n i = 0\n else\n puts \"NO\"\n break\n end\n if aa.size == 1\n puts \"YES\"\n break\n end\n end\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i).sort!\n ok = true\n (1...n).each do |i|\n ok &= a[i] - a[i - 1] <= 1\n end\n puts ok ? \"YES\" : \"NO\"\nend "}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i).sort\n judge = true\n (n-1).times do |i|\n if a[i+1] - a[i] >= 2\n judge = false\n end\n end\n if judge\n ans << \"YES\"\n else\n ans << \"NO\"\n end\nend\nans.each do |str|\n puts str\nend\n"}], "negative_code": [{"source_code": "t=gets.chomp.to_i\n#p \"t= #{t}\"\nwhile t!=0\n\nlen=gets.chomp.to_i\n#p \"length= #{len}\"\nk=0\n#while k<=len-1\nar = gets.chomp.split(' ').map!{ |o| o.to_i }\n#k+=1\n#end\nar.sort!\n p ar\ndef func(ar)\n \nl=ar.size\nif l==1\n return \"YES\"\nend\n i=0\nwhile i < l-1\n \nif ar[i+1]-ar[i]>1\n return \"NO\"\nend\ni+=1\nend\nreturn \"YES\"\nend\n \n \np func(ar)\n \nt-=1\nend"}, {"source_code": "t=gets.chomp.to_i\n#p \"t= #{t}\"\nwhile t!=0\n\nlen=gets.chomp.to_i\n#p \"length= #{len}\"\nk=0\n#while k<=len-1\nar = gets.chomp.split(' ').map!{ |o| o.to_i }\n#k+=1\n#end\nar.sort!\n #p ar\ndef func(ar)\n \nl=ar.size\nif l==1\n return \"YES\"\nend\n i=0\nwhile i < l-1\n \nif ar[i+1]-ar[i]>1\n return \"NO\"\nend\ni+=1\nend\nreturn \"YES\"\nend\n \n \np func(ar)\n \nt-=1\nend"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n aa = a.sort\n i = 0\n while true\n if n == 1\n puts \"YES\"\n break\n end\n sa = (a[i+1] - a[i]).abs\n if sa <= 1\n a.shift\n i = 0\n else\n puts \"NO\"\n break\n end\n if a.size == 1\n puts \"YES\"\n break\n end\n end\nend\n"}, {"source_code": "def array(arr)\n arr.sort!.each_cons(2) do |a, b|\n b - a > 1 ? 'NO' : 'YES'\n end\nend"}, {"source_code": "test_case = gets.to_i\ni = 0\nwhile i < test_case\n result = true\n i += 1\n len_ = gets.to_i\n Acase = gets.chomp.split(' ').map(&:to_i)\n Acase.sort!\n #puts Acase.inspect()\n j = 0\n while j < len_-1\n j += 1\n if Acase[j+1].to_i - Acase[j].to_i >= 2\n result = false\n break\n end\n end\n puts (result) ? \"Yes\" : \"No\" \n \nend"}, {"source_code": "tc = gets().to_i\ntc.times do\n n = gets().to_i\n arr = gets().split(' ').map(&:to_i).sort\n if arr[n-1]-arr[0] > 1\n puts(\"NO\")\n else\n puts(\"YES\")\n end\nend"}, {"source_code": "tc = gets().to_i\ntc.times do\n n = gets().to_i\n arr = gets().split(' ').map(&:to_i)\n k = true\n for i in (1..n-1) do\n if arr[i]-arr[i-1] > 1\n puts \"NO\";\n k = false\n break;\n end\n end\n if (k)\n puts \"YES\"\n end\nend"}], "src_uid": "ed449ba7c453a43e2ac5904dc0174530"} {"source_code": "n = gets.to_i\na = n.times.map{\n\t x, y = gets.split\n\t\t\t [y.to_i, x]\n}.sort\nb = []\na.each do |x, y|\n\t break if x > b.size\n\t\t\t b.each{|_| _[1] += 1 if _[1] >= x}\n\t\t\t\t\t b << [y, x]\nend\nputs b.size < n ? -1 : b.map{|i, j| \"#{i} #{n - j}\"} * \"\\n\"\n", "positive_code": [{"source_code": "n = gets.to_i\na = n.times.map{\n x, y = gets.split\n [y.to_i, x]\n}.sort\nb = []\na.each do |x, y|\n break if x > b.size\n b.each{|_| _[1] += 1 if _[1] >= x}\n b << [y, x]\nend\nputs b.size < n ? -1 : b.map{|i, j| \"#{i} #{n - j}\"} * \"\\n\"\n"}, {"source_code": "n=gets.to_i\nans=[]\nn.times.map{name,a=gets.split;[name,a.to_i]}.sort_by{|name,a|a}.each{|name,a|\n\tif ans.size i\n ho[a, 0] = n\n end\n\n data.each do |n, a|\n ret << [n, data.size-ho.index(n)]\n end\n ret\nend\n\ndef check(sol)\n hs = []\n sol.map{|n,h| v = [n, hs.count{|x| x > h}]; hs << h; v}\nend\n\ndef test\n srand(122039)\n 100.times do |i|\n p i\n d0 = 30.times.map{|x|[\"a#{x}\", rand(10**9)]}\n input = check(d0)\n out = solve(input)\n input2 = check(out)\n if input != input2\n p d0, input, input2 \n raise\n end\n end\n exit\nend\n\nn = gets.to_i\ndata = n.times.map{ a, b = gets.split; [a, b.to_i]}\nret = solve(data)\nif ret\n ret.each{|a| puts a*\" \"}\nelse\n puts -1\nend\n"}, {"source_code": "n=gets.to_i\nans=[]\nn.times.map{name,a=gets.split;[name,a.to_i]}.sort_by{|name,a|a}.each{|name,a|\n\tif ans.size 0\n\t\tpos += 1\n\telse\n\t\tneg += 1\n\tend\nend\n\nif pos == arr.size || neg == arr.size\n\tprint \"Yes\"\nelse\n\tif pos == 1 || neg == 1\n\t\tprint \"Yes\"\n\telse\n\t\tprint \"No\"\n\tend\nend"}, {"source_code": "gets;puts$<.partition{|e|e.to_i<0}.any?{|e|e.size<2} ? :YES : :NO"}, {"source_code": "n=gets.to_i\nx=y=0;\nn.times{ gets.to_i<0 ? y+=1 : x+=1 }\nputs ([x, y].min<2 ? \"Yes\" : \"No\")\n"}], "negative_code": [{"source_code": "puts gets.to_i.times.count{gets.split.map(&:to_i).reduce(:+)<1}<1 ? :YES : :NO"}, {"source_code": "puts gets.to_i.times.count{gets.split.map(&:to_i).reduce(:+)<1}<2 ? :YES : :NO"}, {"source_code": "gets;puts$<.group_by{|e|e.to_i<0}.any?{|k,v|v.size<2} ? :YES : :NO"}], "src_uid": "cf7bf89a6038586b69d3b8021cee0b27"} {"source_code": "gets.to_i.times do\n n, k = gets.split.map &:to_i\n if n.even? and k.even?\n if k > n\n puts \"NO\"\n else\n puts \"YES\"\n puts \"1 \"*(k - 1) + (n - k + 1).to_s\n end\n elsif n.even? and k.odd?\n if k*2 > n\n puts \"NO\"\n else\n puts \"YES\"\n puts \"2 \"*(k - 1) + (n - (k - 1)*2).to_s\n end\n else\n if k.even? or k > n\n puts \"NO\"\n else\n puts \"YES\"\n puts \"1 \"*(k - 1) + (n - k + 1).to_s\n end\n end\nend\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\n\ntests = []\n\nn.times do\n tests.push(gets.split(' ').map {|e| e.to_i})\nend\n\ntests.each do |test|\n n, k = test\n \n if n < k then\n puts 'NO'\n next\n end\n \n if n.odd? && k.even? then\n puts 'NO'\n next\n end\n\n results = []\n if n.even? && k.odd? then\n if 2 * k > n then\n puts 'NO'\n next\n end\n results.fill(2, 0..k - 2)\n results_sum = results.reduce(0) {|sum, value| sum + value }\n results.push(n - results_sum)\n puts 'YES'\n puts results.join(' ')\n else\n results.fill(1, 0..k - 2)\n results_sum = results.reduce(0) {|sum, value| sum + value }\n results.push(n - results_sum)\n puts 'YES'\n puts results.join(' ')\n end\n\nend"}, {"source_code": " t = gets.to_i\n t.times do\n n, k = gets.split(' ').map(&:to_i)\n if k == 1\n puts 'YES'\n puts n\n next\n end\n res = []\n (k-1).times do |i|\n res << 1\n end\n if((_res = n - res.reduce(&:+)) % 2 != 0 && _res > 0)\n res << _res\n puts 'YES'\n puts res.join(' ')\n else\n res = []\n (k-1).times do |i|\n res << 2\n end\n if((_res = n - res.reduce(&:+)) % 2 == 0 && _res > 0)\n res << _res\n puts 'YES'\n puts res.join(' ')\n else\n puts 'NO'\n end\n end\n end"}, {"source_code": "t = gets.to_i\n\ndef all(a,b)\n puts \"YES\"\n (1..a).each do\n print \"#{b} \"\n end\n puts\nend\n\ndef printArr(arr)\n puts \"YES\"\n arr.each do |x|\n print \"#{x} \"\n end\n puts\nend\n\n(1).upto(t) do\n x = gets.split(' ')\n n = x[0].to_i\n k = x[1].to_i\n val1 = n/k\n val2 = n.modulo(k)\n if val1 ==0\n puts \"NO\"\n next\n end\n if(val2 == 0)\n all(k,val1)\n next\n end\n arr = []\n (1..k).each do\n arr.push(val1)\n end\n if val2.modulo(2)==0\n arr[0]+=val2\n printArr(arr)\n next\n end\n if k.modulo(2)==0\n puts \"NO\"\n next\n end\n if arr[0]!=1\n (0.. arr.length-1).each do |i|\n arr[i]-=1\n val2+=1\n end\n arr[0]+=val2\n printArr(arr)\n next\n end\n puts \"NO\"\nend\n"}, {"source_code": "# Created by IntelliJ IDEA.\n# User: gautam.roy\n# Date: 5/9/20\n# Time: 9:37 PM\n# To change this template use File | Settings | File Templates.\n\nt = gets.to_i\nfor i in 1..t do\n n, k = gets.split(' ').map { |s| s.to_i }\n ret = []\n if n < k\n puts \"NO\"\n next\n end\n if k == 1\n puts \"Yes\"\n puts n\n next\n end\n if k.even? && !n.even?\n puts \"NO\"\n next\n end\n if (k.even? && n.even?) || (!k.even? && !n.even?)\n puts \"Yes\"\n for j in 1..(k - 1)\n ret << 1\n end\n ret << n - (k - 1)\n puts ret.join(\" \")\n next\n end\n # k odd and n even\n if (n - 2 * (k - 1)) > 0\n puts \"YES\"\n for j in 1..(k - 1)\n ret << 2\n end\n ret << n - 2 * (k - 1)\n puts ret.join(\" \")\n else\n puts \"NO\"\n end\nend"}, {"source_code": "gets.to_i.times{\n n,k=gets.split.map &:to_i\n res=[1]*(k-1)\n res< 0 && (delta.even? == i.even?)\n end\n\n if f\n puts \"YES\"\n puts \"#{f} \" * (k-1) + (n - (k-1)*f).to_s\n else\n puts \"NO\"\n end \nend\n"}], "negative_code": [{"source_code": "t = gets.to_i\nt.times do\n n, k = gets.split(' ').map(&:to_i)\n _res = n / k\n res = []\n if n % k == 0\n k.times { res << _res }\n else\n t_res = _res + 1\n n_res = n - (t_res * (k-1))\n if n_res < 1\n elsif((n_res.odd? && t_res.odd?) || (n_res.even? && t_res.even?))\n (k - 1).times { res << t_res }\n res << n_res\n end\n (2..(k-1)).to_a.each do |i|\n t_res += 1\n n_res = (n - (t_res * (k-i))) / i\n if n_res < 1\n elsif((n_res.odd? && t_res.odd?) || (n_res.even? && t_res.even?))\n (k - i).times { res << t_res }\n i.times { res << n_res }\n end\n if res.length != 0 && res.reduce(&:+) == n\n break\n else\n res = []\n end\n end if res.length == 0\n end\n puts(res.length == 0 ? 'NO' : 'YES')\n next if res.length == 0\n puts(res.join(' '))\nend\n"}, {"source_code": "t = gets.to_i\n\ndef all(a,b)\n puts \"YES\"\n (1..a).each do\n print \"#{b} \"\n end\n puts\nend\n\ndef printArr(arr)\n puts \"YES\"\n arr.each do |x|\n print \"#{x} \"\n end\n puts\nend\n\n(1).upto(t) do\n x = gets.split(' ')\n n = x[0].to_i\n k = x[1].to_i\n val1 = n/k\n val2 = n.modulo(k)\n if(val2 == 0)\n all(k,val1)\n next\n end\n arr = []\n (1..k).each do\n arr.push(val1)\n end\n if val2.modulo(2)==0\n arr[0]+=val2\n printArr(arr)\n next\n end\n if k.modulo(2)==0\n puts \"NO\"\n next\n end\n if arr[0]!=1\n (0.. arr.length-1).each do |i|\n arr[i]-=1\n val2+=1\n end\n arr[0]+=val2\n printArr(arr)\n next\n end\n puts \"NO\"\nend\n"}, {"source_code": "def func(n, k)\n res=2**40-1\n a=2**39\n while a>0\n t=res^a\n cnt=t-t/n\n res=t if cnt>=k\n a>>=1\n end\n res\nend\n\ngets.to_i.times{\n n, k=gets.split.map &:to_i\n puts func(n, k)\n}\n"}, {"source_code": "gets.to_i.times do\n n, k = gets.split.map &:to_i\n if n.even? and k.even?\n if k > n\n puts \"NO\"\n else\n puts \"YES\"\n puts \"1 \"*(k - 1) + (n - k + 1).to_s\n end\n elsif n.even? and k.odd?\n if k*2 > n\n puts \"NO\"\n else\n puts \"YES\"\n puts \"2 \"*(k - 1) + (n - (k - 1)*2).to_s\n end\n else\n if k.even?\n puts \"NO\"\n else\n puts \"YES\"\n puts \"1 \"*(k - 1) + (n - k + 1).to_s\n end\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\ntests = []\n\nn.times do\n tests.push(gets.split(' ').map {|e| e.to_i})\nend\n\ntests.each do |test|\n if test[0] % 2 == 1 && test[1] % 2 == 0 then\n puts 'NO'\n next\n end\n \n if test[0] < test[1] then\n puts 'NO'\n next\n end\n \n results = []\n \n if test[0] == test[1] then\n puts 'YES'\n results.fill(1, 0..test[1])\n puts results.join(' ')\n next\n end\n \n if test[0] % test[1] == 0 then\n puts 'YES'\n results.fill(test[0] / test[1], 0..test[1]-1)\n puts results.join(' ')\n elsif test[0] % 2 == 0 && test[1] % 2 == 1 then\n division = test[0] / test[1]\n division -= 1\n if division > 0 then\n results.fill(division, 0..test[1]-2)\n sum = results.reduce(0){|sum, value| sum + value}\n results.push(test[0] - sum)\n puts 'YES'\n puts results.join(' ')\n else\n puts 'NO' \n end\n elsif test[0] % 2 == 1 && test[1] % 2 == 1 then\n division = test[0] / test[1]\n results.fill(division, 0..test[1]-2)\n sum = results.reduce(0){|sum, value| sum + value}\n results.push(test[0] - sum)\n puts 'YES'\n puts results.join(' ')\n end\nend"}, {"source_code": "n = gets.chomp.to_i\n\ntests = []\n\nn.times do\n tests.push(gets.split(' ').map {|e| e.to_i})\nend\n\ntests.each do |test|\n if test[0] % 2 == 1 && test[1] % 2 == 0 then\n puts 'NO'\n next\n end\n \n if test[0] < test[1] then\n puts 'NO'\n next\n end\n \n results = []\n \n if test[0] == test[1] then\n puts 'YES'\n results.fill(1, 0..test[1]-1)\n puts results.join(' ')\n next\n end\n \n if test[0] % test[1] == 0 then\n puts 'YES'\n results.fill(test[0] / test[1], 0..test[1]-1)\n puts results.join(' ')\n elsif test[0] % 2 == 0 && test[1] % 2 == 1 then\n division = test[0] / test[1]\n division -= 1\n if division > 0 then\n results.fill(division, 0..test[1]-2)\n sum = results.reduce(0){|sum, value| sum + value}\n results.push(test[0] - sum)\n puts 'YES'\n puts results.join(' ')\n else\n puts 'NO' \n end\n elsif test[0] % 2 == 1 && test[1] % 2 == 1 then\n division = test[0] / test[1]\n results.fill(division, 0..test[1]-2)\n sum = results.reduce(0){|sum, value| sum + value}\n results.push(test[0] - sum)\n puts 'YES'\n puts results.join(' ')\n end\nend"}, {"source_code": "n = gets.chomp.to_i\n\ntests = []\n\nn.times do\n tests.push(gets.split(' ').map {|e| e.to_i})\nend\n\ntests.each do |test|\n n, k = test\n \n if n < k then\n puts 'NO'\n next\n end\n \n if n.odd? && k.even? then\n puts 'NO'\n next\n end\n \n if n - k == 1 && n.even? then\n puts 'NO'\n next\n end\n \n results = []\n if n.even? && k.odd? then\n results.fill(2, 0..k - 2)\n results_sum = results.reduce(0) {|sum, value| sum + value }\n results.push(n - results_sum)\n puts 'YES'\n puts results.join(' ')\n else\n results.fill(1, 0..k - 2)\n results_sum = results.reduce(0) {|sum, value| sum + value }\n results.push(n - results_sum)\n puts 'YES'\n puts results.join(' ')\n end\n\nend"}, {"source_code": "n = gets.chomp.to_i\n\ntests = []\n\nn.times do\n tests.push(gets.split(' ').map {|e| e.to_i})\nend\n\ntests.each do |test|\n n, k = test\n \n if n < k then\n puts 'NO'\n next\n end\n \n if n.odd? && k.even? then\n puts 'NO'\n next\n end\n \n if n - k == 1 && n.even? then\n puts 'NO'\n next\n end\n \n results = []\n \n results.fill(1, 0..k - 2)\n results_sum = results.reduce(0) {|sum, value| sum + value }\n results.push(n - results_sum)\n puts 'YES'\n puts results.join(' ')\nend"}], "src_uid": "6b94dcd088b0328966b54acefb5c6d22"} {"source_code": "MOD = 10 ** 9 + 7\r\ndef gs; gets.chomp; end\r\ndef gi; gets.to_i; end\r\ndef gli; gets.split.map(&:to_i); end\r\ndef cyesno(x); puts x ? :Yes : :No; end\r\ndef uyesno(x); puts x ? :YES : :NO; end\r\ndef array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end\r\n\r\na = []\r\nc = 0\r\ni = 1;\r\nwhile c < 1010\r\n unless i% 3 == 0 || i % 10 == 3\r\n a << i\r\n c += 1\r\n end\r\n i += 1\r\nend\r\n\r\ngets.to_i.times do \r\n g = gets.to_i\r\n puts a[g-1]\r\nend\r\n", "positive_code": [{"source_code": "# 1 2 3 4 5 6 7 8 9 1000\n# 1 2 4 5 7 8 10 11 14 1666\n\nt = gets.to_i\nk = []\n(0..t-1).each do\n x = gets.to_i\n k.push(x)\nend\n\nk.each do |i|\n j = 1\n c = 0\n while true\n if j % 3 != 0 && j % 10 != 3\n c += 1\n end\n if c == i\n puts j\n break\n end\n j += 1\n end\n # p arr\n # puts arr.last\nend"}, {"source_code": "t = gets.to_i\na = []\ni = 1\nwhile a.length() < 1001\n if i % 3 != 0 && i.to_s[-1] != \"3\"\n a << i\n end\n i += 1\nend\nwhile t > 0\n t -= 1\n n = gets.to_i\n puts a[n - 1]\nend\n"}, {"source_code": "\ndef solve(k)\n cnt = 0\n ptr = 0\n while cnt < k do\n ptr += 1\n next if ptr % 3 == 0 || ptr%10 == 3\n cnt += 1\n end\n ptr\nend\n\nt = gets.chomp.to_i\n\nt.times do\n k = gets.chomp.to_i\n puts \"#{solve(k)}\\n\"\nend\n"}], "negative_code": [{"source_code": "MOD = 10 ** 9 + 7\r\ndef gs; gets.chomp; end\r\ndef gi; gets.to_i; end\r\ndef gli; gets.split.map(&:to_i); end\r\ndef cyesno(x); puts x ? :Yes : :No; end\r\ndef uyesno(x); puts x ? :YES : :NO; end\r\ndef array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end\r\n\r\na = []\r\nc = 0\r\ni = 1;\r\nwhile c < 1010\r\n unless i% 3 == 0 || i % 10 == 0\r\n a << i\r\n c += 1\r\n end\r\n i += 1\r\nend\r\n\r\ngets.to_i.times do \r\n g = gets.to_i\r\n puts a[g-1]\r\nend\r\n"}], "src_uid": "c37604d5d833a567ff284d7ce5eda059"} {"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\nwords = []\nn.times { words.push(STDIN.readline.strip) }\n\ntitle = 'a'\n\nwhile true\n\tokay = true\n\tn.times do |i|\n\t\tif words[i].index(title) != nil\n\t\t\tokay = false\n\t\t\tbreak\n\t\tend\n\tend\n\tif okay\n\t\tputs title\n\t\texit\n\tend\n\n\ttitle = title.next\nend\n\n", "positive_code": [{"source_code": "a = ''\nn = gets.to_i.times{ a += (gets.to_s.chomp + ' ')}\ns = 'a'\nwhile a.index(s) != nil do\n\ts.next!\nend\nputs s\n"}, {"source_code": "a = ''\nn = gets.to_i.times{ a += (gets.to_s.chomp + ' ')}\ns = 'a'\nwhile a.index(s) != nil do\n\ts.next!\nend\nputs s\n\n"}, {"source_code": "a = ''\nn = gets.to_i.times{ a += (gets.to_s.chomp + ' ')}\ns = 'a'\nwhile a.index(s) != nil do\n\ts.next!\nend\nputs s\n\n"}, {"source_code": "n=gets.to_i\ns=[]\nn.times do\n s< y.size\n 1\n else\n if x <= y then -1 else 1 end\n end\n}.uniq\nans=\"a\"\na.each{|x| \n break if x != ans\n ans.succ!\n}\nputs ans\n\n"}, {"source_code": "def titles(prefix = '', len)\n len -= 1\n block = (len == 0) ? lambda { |z| prefix + z } : lambda { |z| titles(prefix + z, len) }\n ('a'..'z').to_a.map &block\nend\n\ndef solve(used_titles)\n (1..2).each { |i|\n titles(i).flatten.each { |title|\n return title if used_titles.all? { |used_title| !used_title.include? title }\n }\n }\nend\n\nif __FILE__ == $0\n puts solve((1..gets.to_i).map { gets.chomp })\nend"}, {"source_code": "def titles(prefix = '', len)\n len -= 1\n block = (len == 0) ? lambda { |z| prefix + z } : lambda { |z| titles(prefix + z, len) }\n ('a'..'z').to_a.map &block\nend\n\ndef solve(used_titles)\n (1..3).each { |i|\n titles(i).flatten.each { |title|\n return title if used_titles.all? { |used_title| !used_title.include? title }\n }\n }\nend\n\nif __FILE__ == $0\n puts solve((1..gets.to_i).map { gets.chomp })\nend"}, {"source_code": "ns = gets.to_i.times.map { gets.chomp }\nstart = \"a\"\nwhile ns.any? { |n| n.index(start) }\n start.succ!\nend\nputs start"}, {"source_code": "a = ''\nn = gets.to_i.times{ a += (gets.to_s.chomp + ' ')}\ns = 'a'\nwhile a.index(s) != nil do\n\ts.next!\nend\nputs s\n\n"}, {"source_code": "ns = gets.to_i.times.map { gets.chomp }\nstart = \"a\"\nwhile ns.any? { |n| n.index(start) }\n start.succ!\nend\nputs start"}, {"source_code": "a = ''\nn = gets.to_i.times{ a += (gets.to_s.chomp + ' ')}\ns = 'a'\nwhile a.index(s) != nil do\n\ts.next!\nend\nputs s\n\n"}, {"source_code": " def nl(x)\n case x[-1]\n when \"a\"\n return (x[0...-1] + \"b\")\n when \"b\"\n return (x[0...-1] + \"c\")\n when \"c\"\n return (x[0...-1] + \"d\")\n when \"d\"\n return (x[0...-1] + \"e\")\n when \"e\"\n return (x[0...-1] + \"f\")\n when \"f\"\n return (x[0...-1] + \"g\")\n when \"g\"\n return (x[0...-1] + \"h\")\n when \"h\"\n return (x[0...-1] + \"i\")\n when \"i\"\n return (x[0...-1] + \"j\")\n when \"j\"\n return (x[0...-1] + \"k\")\n when \"k\"\n return (x[0...-1] + \"l\")\n when \"l\"\n return (x[0...-1] + \"m\")\n when \"m\"\n return (x[0...-1] + \"n\")\n when \"n\"\n return (x[0...-1] + \"o\")\n when \"o\"\n return (x[0...-1] + \"p\")\n when \"p\"\n return (x[0...-1] + \"q\")\n when \"q\"\n return (x[0...-1] + \"r\")\n when \"r\"\n return (x[0...-1] + \"s\")\n when \"s\"\n return (x[0...-1] + \"t\")\n when \"t\"\n return (x[0...-1] + \"u\")\n when \"u\"\n return (x[0...-1] + \"v\")\n when \"v\"\n return (x[0...-1] + \"w\")\n when \"w\"\n return (x[0...-1] + \"x\")\n when \"x\"\n return (x[0...-1] + \"y\")\n when \"y\"\n return (x[0...-1] + \"z\")\n when \"z\"\n return nil\n end\n end\n\n def func(mas, st,n)\n ans = []\n for s in \"a\"..\"z\" do\n t = true\n i = 0\n while t && i < n do\n if mas[i].include? (st + s) then\n t = false\n end\n i += 1\n end\n if t then \n ans << (st + s)\n end\n end\n return ans\n end\n\n n = gets.to_i\n\n names = []\n n.times do \n names << gets.chomp\n end\n\n ans = func(names,\"\",n)\n st = \"a\"\n k = 1\n while ans.empty? do\n if !st then\n k += 1\n st = k*\"a\"\n end\n ans = func(names,st,n)\n st = nl(st)\n end\n\n puts ans.min"}, {"source_code": "a = ''\nn = gets.to_i.times{ a += (gets.to_s.chomp + ' ')}\ns = 'a'\nwhile a.index(s) != nil do\n\ts.next!\nend\nputs s\n\n"}, {"source_code": "a = ''\nn = gets.to_i.times{ a += (gets.to_s.chomp + ' ')}\ns = 'a'\nwhile a.index(s) != nil do\n\ts.next!\nend\nputs s\n"}, {"source_code": "def get_str(x)\n abc = \" abcdefghijklmnopqrstuvwxyz\".split(\"\")\n sn = x.to_s 27\n r = \"\"\n sn.split(\"\").each do |l|\n r += abc[l.to_i 27]\n end\n r\nend\n\ntn = gets.chomp.to_i\ntitles = []\ntn.times do\n titles.push(gets.chomp)\nend\n\nn = 0\nwhile true do\n n+=1\n done = true\n if n%27 != 0 then\n str = get_str n\n titles.each do |ttl|\n if ttl.include? str then\n done = false\n break\n end\n end\n puts str if done\n break if done\n end\nend\n\n"}, {"source_code": "a = ''\nn = gets.to_i.times{ a += (gets.to_s.chomp + ' ')}\ns = 'a'\nwhile a.index(s) != nil do\n\ts.next!\nend\nputs s\n\n"}, {"source_code": "a = ''\nn = gets.to_i.times{ a += (gets.to_s.chomp + ' ')}\ns = 'a'\nwhile a.index(s) != nil do\n s.next!\nend\nputs s"}, {"source_code": "a = ''\nn = gets.to_i.times{ a += (gets.to_s.chomp + ' ')}\ns = 'a'\nwhile a.index(s) != nil do\n s.next!\nend\nputs s"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\nwords = []\nn.times { words.push(STDIN.readline.strip) }\n\ntitle = ''\n\nwhile true\n\tpos = title.length-1\n\twhile true\n\t\tif pos == -1\n\t\t\ttitle = (title.length+1).times.collect { 'a' }.join\n\t\t\tbreak\n\t\tend\n\t\tif title[pos] < 'z'\n\t\t\tsuffix = (title.length-1-pos).times.collect { 'a' }.join\n\t\t\ttitle = title.slice(0, pos) + title[pos].next + suffix\n\t\t\tbreak\n\t\tend\n\t\tpos -= 1\n\tend\n\n\tokay = true\n\tn.times do |i|\n\t\tif words[i].index(title) != nil\n\t\t\tokay = false\n\t\t\tbreak\n\t\tend\n\tend\n\tif okay\n\t\tputs title\n\t\texit\n\tend\nend\n\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\nhash = {}\nn.times do\n\tword = STDIN.readline.strip\n\t(0..word.length-1).each do |start|\n\t\t(1..word.length-start).each do |length|\n\t\t\thash[word.slice(start, length)] = true\n\t\tend\n\tend\nend\n\ntitle = 'a'\ntitle = title.next while hash[title] != nil\nputs title\n\n"}], "negative_code": [{"source_code": "def get_str(x)\n abc = \" abcdefghijklmnopqrstuvwxyz\".split(\"\")\n sn = x.to_s 27\n r = \"\"\n sn.split(\"\").each do |l|\n r += abc[l.to_i 27]\n end\n r\nend\n\nn = gets.chomp.to_i\ntitles = []\nn.times do\n titles.push(gets.chomp)\nend\n\nn = 0\nwhile true do\n n+=1\n done = true\n if n%27 != 0 then\n str = get_str n\n titles.each do |ttl|\n puts ttl\n if ttl.include? str then\n done = false\n break\n end\n end\n puts str if done\n break if done\n end\nend\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = STDIN.readline.to_i\n\ntitles = []\nn.times { titles.push(STDIN.readline.strip) }\n\nanswer = ''\n\nwhile true\n\t('a'..'z').each do |ch|\n\t\tcandidate = answer+ch\n\t\tokay = true\n\t\ttitles.each do |title|\n\t\t\tif title.index(candidate) != nil\n\t\t\t\tokay = false\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tif okay\n\t\t\tputs candidate\n\t\t\texit\n\t\tend\n\tend\n\tanswer += 'a'\nend\n\n"}, {"source_code": "n = gets.to_i\n\ns = []\nn.times do |i|\n\ts[i] = gets\nend\n\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\".split(' ')\n\nmyname = \"idk\"\nfound = false\n\nallstring = s.join('')\n\nalphabet.each do |let|\n\tif !allstring.include?(let)\n\t\tmyname = let\n\t\tfound = true\n\t\tbreak\n\tend\nend\n\n\nmyname = \"a\" if !found\nwhile !found do\n\talphabet.each do |let|\n\t\t# p myname + let\n\t\tif !allstring.include?(myname + let)\n\t\t\tmyname = myname + let\n\t\t\tfound = true\n\t\t\tbreak\n\t\tend\n\n\t\t# myname += \"a\" if let = \"z\" && !found\n\tend\n\tmyname += \"a\" if !found\nend\n\n\np myname"}, {"source_code": "ns = gets.to_i.times.map { gets.chomp }\nstart = \"a\"\nwhile ns.any? { |n| n.index(start) }\n start.succ!\nend\np start"}], "src_uid": "58fa5c2f270e2c34e8f9671d5ffdb9c8"} {"source_code": "n = gets.to_i\na = []\n\ndef find_ans(s,w)\n i = 0\n time = 0\n while (i < w.length - 1)\n if (w[i] == w[i+1])\n time += 0\n else\n time += (s.index(w[i]) - s.index(w[i+1])).abs\n end\n i += 1\n end\n time\nend\n \n(0..n-1).each do |x|\n\ts = gets.chomp\n w = gets.chomp\n\ta.append(find_ans(s,w))\nend\n \n \na.each do |x|\n p x\nend", "positive_code": [{"source_code": "for _ in 0...gets.chomp.to_i\r\n keyboard = gets.chomp\r\n word = gets.chomp\r\n time = 0\r\n if word.length() <= 1\r\n puts time\r\n else\r\n for i in 0...(word.length() - 1)\r\n time += (keyboard.index(word[i]) - keyboard.index(word[i + 1])).abs\r\n end\r\n puts time\r\n end\r\nend"}, {"source_code": "arr = []\r\nt = gets.chomp.to_i\r\nindex = 0\r\nwhile t>index\r\n s1 = gets.chomp.chars\r\n s2 = gets.chomp.chars\r\n kol_s2 = s2.length.to_i-1\r\n summa =0;\r\n i=1;\r\n while kol_s2>=1\r\n if s2.length>1\r\n summa = summa + ((s1.index(s2[i]))-(s1.index(s2[i-1]))).abs\r\n kol_s2-=1\r\n i+=1\r\n else\r\n summa = 0\r\n end\r\n end\r\n arr[index] = summa\r\n index+=1\r\nend\r\narr.each{|a| puts a}"}, {"source_code": "gets.to_i.times do\r\n a=gets.chomp.chars\r\n h={}\r\n 26.times do |i|\r\n h[a[i]]=i\r\n end\r\n c=0\r\n s=gets.chomp.chars\r\n (s.size-1).times do |i|\r\n c+=(h[s[i+1]]-h[s[i]]).abs\r\n end\r\n puts c\r\nend\r\n"}, {"source_code": "STDIN.read\r\n .split(/\\n/)\r\n .drop(1)\r\n .map!(&:strip)\r\n .each_slice(2) do |alphabet, word|\r\n puts word\r\n .split(\"\")\r\n .map{ |c| alphabet.index(c) }\r\n .each_cons(2)\r\n .map{|a, b| (a - b).abs}\r\n .sum\r\n end\r\n"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n dist = {}\r\n keys = gets.chomp\r\n s = gets.chomp\r\n keys.each_char.with_index do |c, i|\r\n dist[c] = i\r\n end\r\n ans = 0\r\n s.chars.each_cons(2) do |c1, c2|\r\n ans += (dist[c1] - dist[c2]).abs\r\n end\r\n puts ans\r\nend"}, {"source_code": "t = gets.to_i\nt.times do\n dist = {}\n keys = gets.chomp\n s = gets.chomp\n keys.each_char.with_index do |c, i|\n dist[c] = i\n end\n ans = 0\n s.chars.each_cons(2) do |c1, c2|\n ans += (dist[c1] - dist[c2]).abs\n end\n puts ans\nend"}, {"source_code": "gets.to_i.times do\r\n xs = gets.chomp.chars\r\n puts gets.chomp.chars.each_cons(2).map { |a, b| (xs.index(a) - xs.index(b)).abs }.sum\r\nend"}], "negative_code": [], "src_uid": "7f9853be7ac857bb3c4eb17e554ad3f1"} {"source_code": "n = gets.to_i\nh = Hash.new { |hash, key| hash[key] = [] }\n(n * (n - 1) / 2).times do |i|\n t, *v = gets.split.map(&:to_i)\n v.each do |x|\n h[x].push << i\n end\nend\n\nhash2 = Hash.new { |hash, key| hash[key] = [] }\nh.each do |k, v|\n hash2[v] << k\nend\n\nif n != 2\n hash2.each do |k, v|\n puts \"#{v.size} #{v.join(\" \")}\"\n end\nelse\n tmp = hash2[[0]]\n puts \"1 #{tmp.pop}\"\n puts \"#{tmp.size} #{tmp.join(\" \")}\"\nend", "positive_code": [{"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\n\nsets=[]\nall_sets=n*(n-1)/2\n\nall_sets.times{\n\tset=gets.split.map(&:to_i)[1..-1]\n\tsets << set.sort\n}\n\nsets.sort!\n\nif all_sets==1\n\tputs \"1 #{sets[0][0]}\"\n\tputs \"#{sets[0][1..-1].size} #{sets[0][1..-1].join(\" \")}\"\n\texit\nend\n\nresulting_sets=Hash.new(nil)\nfor i in 0...sets.size-1\n\ta, b=sets[i], sets[i+1]\n\tunion=a&b\n\t\n\tif !union.empty?\n\t\ttmp_sets=[a-union, b-union, union]\n\t\t\n\t\ttmp_sets.each{|s| resulting_sets[s.sort]=1 if !resulting_sets.has_key?(s.sort)}\n\tend\nend\n\nresulting_sets.keys.each{|v|\n\tputs \"#{v.size} #{v.join(\" \")}\"\n}\n"}, {"source_code": "N = gets.to_i\n \nh = Hash.new\n(N * (N - 1) / 2).times do |i|\n k, *as = gets.chomp.split.map{|e| e.to_i}\n as.each {|a|\n h[a] ||= []\n h[a].push i\n }\nend\n \nnew_hash = Hash.new\nh.each {|k, v|\n new_hash[v] ||= []\n new_hash[v].push k\n}\n \nif N != 2\n new_hash.each {|k, v|\n puts \"#{v.size} #{v.join(\" \")}\"\n }\nelse\n tmp = new_hash[[0]]\n puts \"1 #{tmp.pop}\"\n puts \"#{tmp.size} #{tmp.join(\" \")}\"\nend"}, {"source_code": "require 'set'\nn = gets.to_i\nm = n * (n - 1) / 2\nb = m.times.map{gets.split.map(&:to_i)[1..-1].to_set}\nif n == 2\n\ta = [b[0].to_a[0..0], b[0].to_a[1..-1]]\nelse\n\ta = []\n\t1.upto(b.size - 1) do |i|\n\t\tunless (b[0] & b[i]).empty?\n\t\t\ta << (b[0] & b[i])\n\t\t\tbreak\n\t\tend\n\tend\n\tb.each do |c|\n\t\tunless (c & a[0]).empty?\n\t\t\ta << (c - a[0])\n\t\tend\n\tend\nend\na.each do |c|\n\tputs \"#{c.size} #{c.to_a * ' '}\"\nend\n\n"}, {"source_code": "\ndef and_(x,y_)\n b=0\n res=[]\n y=y_+[9999999999]\n x.length.times{|a|\n while x[a]>y[b]\n b+=1\n end\n if x[a]==y[b] then\n res.push(x[a])\n end\n }\n return res\nend\n\nsets=[]\nn=gets.to_i\n(n*(n-1)/2).times{\n k=gets.split.map(&:to_i)\n k.shift\n k.sort!\n sets.push(k)\n\n}\nif n==2 then\n printf \"1 %d\\n\",sets[0][0]\n printf \"%d \",sets[0].length-1\n 1.upto(sets[0].length-1){|i|\n printf \"%d \",sets[0][i]\n }\n puts\n exit\nend\nans={}\nloop do\n i=rand(sets.length)\n j=rand(sets.length)\n if i==j then\n next\n end\n t=and_(sets[i],sets[j])\n\n if t.length==0 then\n next\n end\n ans[t]=1\n\n if ans.length==n then\n break\n end\nend\nans=ans.keys\nans.each{|a|\n printf \"%d \",a.length\n a.each{|x|\n printf \"%d \",x\n }\n puts\n}\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\nN = gets.to_i\nh = Hash.new\n\n(N * (N-1) / 2).times do |i|\n k, *as = gets.chomp.split.map{|e| e.to_i }\n\n as.each {|a|\n h[a] ||= []\n h[a].push i\n }\nend\n\nwarn h\n\nnh = Hash.new\nh.each do |k, v|\n nh[v] ||= []\n nh[v].push k\nend\n\nif N != 2\n nh.each do |k,v|\n puts \"#{v.size} #{v.join(\" \")}\"\n end\nelse\n tmp = nh[[0]]\n puts \"1 #{tmp.pop}\"\n puts \"#{tmp.size} #{tmp.join(\" \")}\"\nend\n\n"}, {"source_code": "N = gets.to_i\n\nh = Hash.new\n(N * (N - 1) / 2).times do |i|\n k, *as = gets.chomp.split.map{|e| e.to_i}\n as.each {|a|\n h[a] ||= []\n h[a].push i\n }\nend\n\nnew_hash = Hash.new\nh.each {|k, v|\n new_hash[v] ||= []\n new_hash[v].push k\n}\n\nif N != 2\n new_hash.each {|k, v|\n puts \"#{v.size} #{v.join(\" \")}\"\n }\nelse\n tmp = new_hash[[0]]\n puts \"1 #{tmp.pop}\"\n puts \"#{tmp.size} #{tmp.join(\" \")}\"\nend\n\n\n"}], "negative_code": [{"source_code": "\ndef and_(x,y_)\n b=0\n res=[]\n y=y_+[9999999999]\n x.length.times{|a|\n while x[a]>y[b]\n b+=1\n end\n if x[a]==y[b] then\n res.push(x[a])\n end\n }\n return res\nend\n\nsets=[]\nn=gets.to_i\n(n*(n-1)/2).times{\n k=gets.split.map(&:to_i)\n k.shift\n k.sort!\n sets.push(k)\n\n}\nif n==2 then\n printf \"1 %d\\n\",sets[0][1]\n printf \"%d \",sets[0].length-1\n 1.upto(sets[0].length-1){|i|\n printf \"%d \",sets[0][i]\n }\n puts\n exit\nend\nans={}\nloop do\n i=rand(sets.length)\n j=rand(sets.length)\n if i==j then\n next\n end\n t=and_(sets[i],sets[j])\n\n if t.length==0 then\n next\n end\n ans[t]=1\n\n if ans.length==n then\n break\n end\nend\nans=ans.keys\nans.each{|a|\n printf \"%d \",a.length\n a.each{|x|\n printf \"%d \",x\n }\n puts\n}\n"}, {"source_code": "def and(x,y_)\n b=0\n res=[]\n y=y_+[9999999999]\n x.length.times{|a|\n while x[a]y[b]\n b+=1\n end\n if x[a]==y[b] then\n res.push(x[a])\n end\n }\n return res\nend\n\nsets=[]\nn=gets.to_i\n(n*(n-1)/2).times{\n k=gets.split.map(&:to_i)\n k.shift\n k.sort!\n sets.push(k)\n\n}\nif n==2 then\n printf \"1 %d\\n\",sets[0][1]\n printf \"1 %d\\n\",sets[0][0]\n exit\nend\nans={}\nloop do\n i=rand(sets.length)\n j=rand(sets.length)\n if i==j then\n next\n end\n t=and_(sets[i],sets[j])\n\n if t.length==0 then\n next\n end\n ans[t]=1\n\n if ans.length==n then\n break\n end\nend\nans=ans.keys\nans.each{|a|\n printf \"%d \",a.length\n a.each{|x|\n printf \"%d \",x\n }\n puts\n}\n"}, {"source_code": "\ndef and_(x,y_)\n b=0\n res=[]\n y=y_+[9999999999]\n x.length.times{|a|\n while x[a]>y[b]\n b+=1\n end\n if x[a]==y[b] then\n res.push(x[a])\n end\n }\n return res\nend\n\nsets=[]\nn=gets.to_i\n(n*(n-1)/2).times{\n k=gets.split.map(&:to_i)\n k.shift\n k.sort!\n sets.push(k)\n\n}\nif n==2 then\n printf \"1 %d\\n\",sets[0][1]\n printf \"2 %d\\n\",sets[0][0]\n exit\nend\nans={}\nloop do\n i=rand(sets.length)\n j=rand(sets.length)\n if i==j then\n next\n end\n t=and_(sets[i],sets[j])\n\n if t.length==0 then\n next\n end\n ans[t]=1\n\n if ans.length==n then\n break\n end\nend\nans=ans.keys\nans.each{|a|\n printf \"%d \",a.length\n a.each{|x|\n printf \"%d \",x\n }\n puts\n}\n"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\n\nsets=[]\nall_sets=n*(n-1)/2\nall_sets.times{\n\tset=gets.split.map(&:to_i)[1..-1]\n\tsets << set.sort\n}\n\nsets.sort!\n\nresulting_sets=Hash.new(nil)\nfor i in 0...sets.size-1\n\ta, b=sets[i], sets[i+1]\n\tunion=a&b\n\t\n\tif !union.empty?\n\t\ttmp_sets=[a-union, b-union, union]\n\t\t\n\t\ttmp_sets.each{|s| resulting_sets[s]=1 if !resulting_sets.has_key?(s)}\n\tend\nend\n\nresulting_sets.keys.each{|v|\n\tputs \"#{v.size} #{v.join(\" \")}\"\n}\n"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\n\nsets=[]\nall_sets=n*(n-1)/2\nall_sets.times{\n\tset=gets.split.map(&:to_i)[1..-1]\n\tsets << set.sort\n}\n\nsets.sort!\n\nresulting_sets=Hash.new(nil)\nfor i in 0...sets.size-1\n\ta, b=sets[i], sets[i+1]\n\tunion=a&b\n\t\n\tif !union.empty?\n\t\ttmp_sets=[a-union, b-union, union]\n\t\t\n\t\ttmp_sets.each{|s| resulting_sets[s.sort]=1 if !resulting_sets.has_key?(s.sort)}\n\tend\nend\n\nresulting_sets.keys.each{|v|\n\tputs \"#{v.size} #{v.join(\" \")}\"\n}\n"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\n\nsets=[]\nall_sets=n*(n-1)/2\n\nall_sets.times{\n\tset=gets.split.map(&:to_i)[1..-1]\n\tsets << set.sort\n}\n\nsets.sort!\n\nif all_sets==1\n\tputs \"1 #{sets[0][0]}\"\n\tputs \"1 #{sets[0][1]}\"\n\texit\nend\n\nresulting_sets=Hash.new(nil)\nfor i in 0...sets.size-1\n\ta, b=sets[i], sets[i+1]\n\tunion=a&b\n\t\n\tif !union.empty?\n\t\ttmp_sets=[a-union, b-union, union]\n\t\t\n\t\ttmp_sets.each{|s| resulting_sets[s.sort]=1 if !resulting_sets.has_key?(s.sort)}\n\tend\nend\n\nresulting_sets.keys.each{|v|\n\tputs \"#{v.size} #{v.join(\" \")}\"\n}\n"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\n\nsets=[]\nall_sets=n*(n-1)/2\n\nall_sets.times{\n\tset=gets.split.map(&:to_i)[1..-1]\n\tsets << set.sort\n}\n\nsets.sort!\n\nif all_sets==1\n\tputs \"1 #{sets[0][0]}\"\n\tputs \"1 #{sets[0][1..-1]}\"\n\texit\nend\n\nresulting_sets=Hash.new(nil)\nfor i in 0...sets.size-1\n\ta, b=sets[i], sets[i+1]\n\tunion=a&b\n\t\n\tif !union.empty?\n\t\ttmp_sets=[a-union, b-union, union]\n\t\t\n\t\ttmp_sets.each{|s| resulting_sets[s.sort]=1 if !resulting_sets.has_key?(s.sort)}\n\tend\nend\n\nresulting_sets.keys.each{|v|\n\tputs \"#{v.size} #{v.join(\" \")}\"\n}\n"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\n\nsets=[]\nall_sets=n*(n-1)/2\n\nall_sets.times{\n\tset=gets.split.map(&:to_i)[1..-1]\n\tsets << set.sort\n}\n\nsets.sort!\n\nif all_sets==1\n\tputs \"1 #{sets[0][0]}\"\n\tputs \"1 #{sets[0][1..-1].join(\" \")}\"\n\texit\nend\n\nresulting_sets=Hash.new(nil)\nfor i in 0...sets.size-1\n\ta, b=sets[i], sets[i+1]\n\tunion=a&b\n\t\n\tif !union.empty?\n\t\ttmp_sets=[a-union, b-union, union]\n\t\t\n\t\ttmp_sets.each{|s| resulting_sets[s.sort]=1 if !resulting_sets.has_key?(s.sort)}\n\tend\nend\n\nresulting_sets.keys.each{|v|\n\tputs \"#{v.size} #{v.join(\" \")}\"\n}\n"}, {"source_code": "require 'set'\n\nn = gets.to_i\nsets = []\n(n * (n - 1) / 2).times do\n t, *x = gets.split.map(&:to_i) \n sets << Set.new(x)\nend\n\n$EMPTY = Set.new\n\nsol = Array.new\nfor i in 0...sets.size\n next if sets[i].empty?\n \n for j in (i + 1)...sets.size\n next if sets[j].empty?\n \n t = sets[i] & sets[j]\n unless t.empty?\n sol << t\n sets[i] -= t\n sets[j] -= t\n sol << sets[i] unless sets[i].empty?\n sol << sets[j] unless sets[j].empty?\n \n for k in (j + 1)...sets.size\n next if sets[k].empty?\n sets[k] -= sets[i]\n sets[k] -= sets[j]\n tt = sets[k] & t\n unless tt.empty?\n uu = sets[k] - t\n sol << sets[k] unless sets[k].empty?\n sets[k] = $EMPTY\n end\n end\n sets[i] = $EMPTY\n sets[j] = $EMPTY\n end\n end\nend\n\nsol.each do |x|\n print \"#{x.size}\"\n x.each do |t|\n print \" #{t}\"\n end\n puts \"\"\nend\n"}], "src_uid": "bde894dc01c65da67d32c716981926f6"} {"source_code": "s = gets.chomp\n\nstart = s.length\nfor i in 0...s.length\n if s[i] != \" \"\n start = i\n break\n end\nend\n\ni = start\nif s.length - start > 1\n while i < s.length \n if s[i] != \" \"\n if s[i] == \"\\\"\"\n #for j in i+1...s.length\n j = i + 1\n while j < s.length\n if s[j] == \"\\\"\"\n stop = j \n if start + 1 == stop\n print \"<>\\n\"\n else\n print \"<\", s[start+1..stop-1], \">\\n\"\n end\n start = j + 1\n break\n elsif j == s.length - 1\n print \"<\", s[start], \">\\n\"\n start += 1\n break\n end \n j += 1 \n end\n else\n #for j in i+1...s.length\n if i == s.length - 1\n print \"<\", s[i], \">\\n\"\n start = s.length\n else\n j = i + 1\n while j < s.length\n if s[j] == \" \"\n stop = j\n print \"<\", s[start..stop-1], \">\\n\"\n start = j + 1\n break\n elsif j == s.length - 1 && s[j] != \" \"\n print \"<\", s[start..j], \">\\n\"\n start = j + 1\n break\n end\n j += 1 \n end\n end\n end\n else \n start += 1 \n end\n i = start\n end\nelse\n print \"<\", s[start], \">\\n\"\nend\n\n", "positive_code": [{"source_code": "s = gets.chomp\n\ni = 0\nstate = 0\nwhile i < s.length\n if state == 2\n if s[i].ord == 34\n print \">\\n\"\n state = 0\n else\n print s[i]\n end\n elsif state == 0\n if s[i].ord == 34\n state = 2\n print \"<\"\n elsif s[i].ord == 32\n else\n state = 1\n print \"<\"\n print s[i]\n end\n else\n if s[i].ord == 34\n state = 2\n print \">\\n\"\n elsif s[i].ord == 32\n print \">\\n\"\n state = 0\n else\n print s[i]\n end\n end\n i += 1\nend\nif state == 1\n print \">\\n\"\n state = 0\nend"}, {"source_code": "def output(str)\n puts \"<#{str}>\"\nend\n\n(\" \" << gets).split('\"').each_with_index do |str, i|\n if i.even?\n str.split.each(&method(:output))\n else\n output(str)\n end\nend\n"}, {"source_code": "str=gets.chomp\nq_flag=false\nbuf=\"\"\nstr.each_char do |c| \n if c=='\"' then\n if q_flag then\n print '<'\n print buf\n puts '>'\n buf=\"\"\n end \n q_flag=!q_flag\n next\n end\n if q_flag \n buf=buf+c\n else\n if c==' ' && !buf.empty? then\n print '<'\n print buf\n puts '>'\n buf=\"\"\n end\n if c!=' ' \n buf=buf+c\n end\n end \nend\nif !buf.empty? then\n print '<'\n print buf\n puts '>'\nend"}, {"source_code": "str = gets.chomp\n\n\nstr.scan(/(?:\"(?:\\\\.|[^\"])*\"|[^\" ])+/).each do |arg|\n puts \"<#{arg.gsub /\"/, ''}>\"\nend\n"}, {"source_code": "result = []\ni = 0\nqmode = false\n(ARGF.readlines.last || '').strip.each_char do |c|\n\tresult[i] = result[i] || ''\n\tcase c\n\twhen ' ' then\n\tif qmode \n\t\t\tresult[i] << c \n\t\telse\n\t\t\ti+=1 unless result[i].empty?\n\t\tend\t\n\twhen '\"' then\n\t\tqmode = !qmode\n\t\ti+=1 unless (qmode && result[i].empty?)\n\telse\n\t\tresult[i] << c\n\tend\nend\n\n\nputs result.map{|x| '<'+x+'>'}\n"}, {"source_code": "s = gets.chomp\ns += ' '\ns.split(/\"/).each_with_index do |l, i|\n if i%2 == 1\n puts \"<#{l}>\"\n else\n l.split(/ /).each do |w|\n puts \"<#{w}>\" unless w.size == 0\n end\n end\nend"}, {"source_code": "str = gets.chomp\nts = []\ns = 0\np = ' '\nword = false\nfor i in 0...str.size\n if word\n if str[i] == p\n ts << str[s...i]\n word = false\n end\n elsif str[i] != ' '\n if str[i] == '\"'\n s = i + 1\n p = '\"'\n else\n s = i\n p = ' '\n end\n word = true\n end\nend\nts << str[s...str.size] if word\nputs(ts.map { |t| \"<#{t}>\" })"}, {"source_code": "str = gets.strip\nlexems = []\nstate = :init\nlexem = ''\nstr.chars.each do |char|\n case char\n when ' '\n if state == :quote_lexem\n lexem += char\n else\n state = :end_lexem\n lexems << lexem unless lexem.empty?\n lexem = ''\n end\n when '\"'\n if state == :quote_lexem\n state = :end_lexem\n lexems << lexem\n lexem = ''\n else\n state = :quote_lexem\n end\n else\n lexem += char\n end\nend\nlexems << lexem unless lexem.empty?\n\nlexems.each do |lexem|\n puts '<'+lexem+'>'\nend\n"}, {"source_code": "str = gets\nregsplit = str.scan(/(\\\"[^\\\"\"]*\\\"|[^\\\"\\s]+)/).flatten\nlex = []\nlex = regsplit.collect do |e|\n if e[0] == '\"' then\n e = \"<#{e[1,e.length-2]}>\"\n else\n e = \"<#{e}>\"\n end\nend\nputs lex"}, {"source_code": "s = gets.chomp\nquote = false\nt = \"\"\ns.each_char do |c|\n if c == '\"'\n quote = !quote\n if quote == false\n puts \"<#{t}>\"\n t=''\n end\n else\n if quote == false\n if c == ' '\n puts \"<#{t}>\" if t!=''\n t=\"\"\n else\n t<\" if t.size > 0"}, {"source_code": "class Command\n attr_accessor :commands\n\n def initialize\n @commands = []\n end\n\n def read_commands command_string\n this_lexume = ''\n in_lexume = false\n block_mode = false\n command_string.each_char do |c|\n\n # Handle opening block\n if not in_lexume\n # New lexume if the char is not a space\n if c != ' '\n in_lexume = true\n block_mode = (c == '\"')\n this_lexume = ''\n this_lexume << c if not block_mode\n end\n next\n end\n\n # Handle closing block\n if in_lexume\n if block_mode and c == '\"'\n in_lexume = false\n end\n\n if not block_mode and c == ' '\n in_lexume = false\n end\n \n if not in_lexume\n @commands.push(this_lexume)\n next\n end\n\n end\n\n # Add char to this lexume\n this_lexume << c if in_lexume\n end\n\n # Handle the last lexume\n @commands.push(this_lexume) if in_lexume\n end\n\n def print_commands\n @commands.each do |command|\n puts \"<#{command}>\"\n end\n end\nend\n\ndef main\n input = gets.chomp\n c = Command.new\n c.read_commands(input)\n c.print_commands\nend\n\nmain"}, {"source_code": "class Command\n attr_accessor :commands\n\n def initialize\n @commands = []\n end\n\n def read_commands command_string\n this_lexume = ''\n in_lexume = false\n block_mode = false\n command_string.each_char do |c|\n\n # Handle opening block\n if not in_lexume\n # New lexume if the char is not a space\n if c != ' '\n in_lexume = true\n block_mode = (c == '\"')\n this_lexume = ''\n this_lexume << c if not block_mode\n end\n next\n end\n\n # Handle closing block\n if in_lexume\n in_lexume = false if block_mode and c == '\"'\n in_lexume = false if not block_mode and c == ' '\n \n if in_lexume # If still in lexume, append the char\n this_lexume << c\n else # Else, save this lexume\n @commands.push(this_lexume)\n next\n end\n\n end\n end\n\n # Handle the last lexume\n @commands.push(this_lexume) if in_lexume\n end\n\n def print_commands\n @commands.each do |command|\n puts \"<#{command}>\"\n end\n end\nend\n\ndef main\n input = gets.chomp\n c = Command.new\n c.read_commands(input)\n c.print_commands\nend\n\nmain"}, {"source_code": "class Command\n attr_accessor :commands\n\n def initialize\n @commands = []\n end\n\n def read_commands command_string\n this_lexume = ''\n in_lexume = false\n quote_mode = false\n command_string.each_char do |c|\n\n # Handle opening block\n if not in_lexume\n # New lexume if the char is not a space\n if c != ' '\n in_lexume = true\n quote_mode = (c == '\"')\n this_lexume = ''\n this_lexume << c if not quote_mode\n end\n next\n end\n\n # Handle closing block\n if in_lexume\n in_lexume = false if quote_mode and c == '\"'\n in_lexume = false if not quote_mode and c == ' '\n \n if in_lexume # If still in lexume, append the char\n this_lexume << c\n else # Else, save this lexume\n @commands.push(this_lexume)\n next\n end\n\n end\n end\n\n # Handle the last lexume\n @commands.push(this_lexume) if in_lexume\n end\n\n def print_commands\n @commands.each do |command|\n puts \"<#{command}>\"\n end\n end\nend\n\ndef main\n input = gets.chomp\n c = Command.new\n c.read_commands(input)\n c.print_commands\nend\n\nmain"}, {"source_code": "class B\n def initialize\n str = $stdin.gets.chomp\n list = parse(str)\n\n list.each do |elem|\n puts \"<#{elem}>\"\n end\n end\n\n def parse(str)\n list = []\n elem = \"\"\n elem2 = \"\"\n flag = false\n str.each_char do |ch|\n if ch == '\"'\n flag ^= true\n unless flag\n list << elem\n elem = \"\"\n end\n next\n end\n\n if ch != ' ' && !flag\n elem2 += ch\n elsif !flag\n list << elem2 if elem2.size > 0\n elem2 = \"\"\n end\n\n if flag && ch != '\"'\n elem += ch\n next\n end\n end\n\n list << elem2 if elem2.size > 0\n list\n end\nend\n\nb = B.new"}, {"source_code": "def parse_command(command)\n regex = /\"(.*?)\"|\\s*([a-zA-Z0-9.,?!]+)\\s*/\n command.scan(regex).map { |quoted, spaced| quoted || spaced }\nend\n\ncommand = STDIN.read\nlexemes = parse_command(command)\nlexemes.each { |lexeme| puts \"<#{lexeme}>\" }\n"}], "negative_code": [{"source_code": "s = gets.chomp\nquote = false\nt = \"\"\ns.each_char do |c|\n if c == '\"'\n quote = !quote\n if quote == false\n puts \"<#{t}>\"\n t=''\n end\n else\n if quote == false\n if c == ' '\n puts \"<#{t}>\" if t!=''\n t=\"\"\n else\n t<\"\n end\n end\n\n def parse(str)\n list = []\n elem = \"\"\n elem2 = \"\"\n flag = false\n str.each_char do |ch|\n if ch == '\"'\n flag ^= true\n unless flag\n list << elem\n elem = \"\"\n end\n end\n\n if ch != ' ' && ch != '\"' && !flag\n elem2 += ch\n else\n list << elem2 if elem2.size > 0\n elem2 = \"\"\n end\n\n if flag && ch != '\"'\n elem += ch\n end\n end\n\n list\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n str = $stdin.gets.chomp\n list = parse(str)\n\n list.each do |elem|\n puts \"<#{elem}>\"\n end\n end\n\n def parse(str)\n list = []\n elem = \"\"\n elem2 = \"\"\n flag = false\n str.each_char do |ch|\n if ch == '\"'\n flag ^= true\n unless flag\n list << elem\n elem = \"\"\n end\n next\n end\n\n if ch != ' ' && !flag\n elem2 += ch\n next\n elsif !flag\n list << elem2 if elem2.size > 0\n elem2 = \"\"\n end\n\n if flag && ch != '\"'\n elem += ch\n next\n end\n end\n\n list\n end\nend\n\nb = B.new"}, {"source_code": "s = gets.chomp\n\nstart = 0\nfor i in 0...s.length\n if s[i] != \" \"\n start = i\n break\n end\nend\n\ni = start\nwhile i < s.length\n if s.length - start > 1\n if s[i] != \" \"\n if s[i] == \"\\\"\"\n for j in i+1...s.length\n if s[j] == \"\\\"\"\n stop = j \n if start + 1 == stop\n print \"<>\"\n puts\n else\n print \"<\", s[start+1..stop-1], \">\"\n puts\n end\n start = j + 1\n break\n end \n end\n else\n for j in i+1...s.length\n if s[j] == \" \"\n stop = j\n print \"<\", s[start..stop-1], \">\"\n puts\n start = j + 1\n break\n end \n end\n end\n else \n start += 1 \n end\n i = start\n else\n print \"<\", s[start], \">\"\n break\n end\nend\n"}, {"source_code": "s = gets.chomp\n\ni = 0\nstate = 0\nwhile i < s.length\n if state == 2\n if s[i].ord == 34\n print \">\\n\"\n state = 0\n else\n print s[i]\n end\n elsif state == 0\n if s[i].ord == 34\n state = 2\n print \"<\"\n elsif s[i].ord == 32\n else\n state = 1\n print \"<\"\n print s[i]\n end\n else\n if s[i].ord == 34\n state = 2\n print \">\\n\"\n elsif s[i].ord == 32\n print \">\\n\"\n state = 0\n else\n print s[i]\n end\n end\n i += 1\nend"}, {"source_code": "str=gets.chomp\nq_flag=false\nbuf=\"\"\nstr.each_char do |c| \n if c=='\"' then\n if q_flag then\n print '<'\n print buf\n puts '>'\n buf=\"\"\n end \n q_flag=!q_flag\n next\n end\n if q_flag \n buf=buf+c\n else\n if c==' ' && !buf.empty? then\n print '<'\n print buf\n puts '>'\n buf=\"\"\n end\n if c!=' ' \n buf=buf+c\n end\n end \nend"}, {"source_code": "str = gets.chomp\n\nstr.scan(/(?:\\.|\"[^\"]*\")+/).each do |arg|\n puts \"<#{arg.gsub /\"/, ''}>\"\nend\n"}, {"source_code": "str = gets.chomp\n\nstr.scan(/(?:\\w|\"[^\"]*\")+/).each do |arg|\n puts \"<#{arg.gsub /\"/, ''}>\"\nend\n"}, {"source_code": "s = gets.chomp\nif s=='\"\"'\n puts \"<>\"\n exit\nend\ns.split(/\"/).each_with_index do |l, i|\n if i%2 == 1\n puts \"<#{l}>\"\n else\n l.split(/ /).each do |w|\n puts \"<#{w}>\" unless w.size == 0\n end\n end\nend"}, {"source_code": "s = gets.chomp\ns += ' '\nputs s.split(/\"/).inspect\ns.split(/\"/).each_with_index do |l, i|\n if i%2 == 1\n puts \"<#{l}>\"\n else\n l.split(/ /).each do |w|\n puts \"<#{w}>\" unless w.size == 0\n end\n end\nend"}, {"source_code": "str = gets.chomp\nts = []\ns = 0\np = ' '\nword = false\nfor i in 0...str.size\n if word\n if str[i] == p\n ts << str[s...i]\n word = false\n end\n elsif str[i] != ' '\n if str[i] == '\"'\n s = i + 1\n p = '\"'\n else\n s = i\n p = ' '\n end\n word = true\n end\nend\nputs(ts.map { |t| \"<#{t}>\" })"}, {"source_code": "str = gets.strip\nlexems = []\nstate = :init\nlexem = ''\nstr.chars.each do |char|\n case char\n when ' '\n if state == :quote_lexem\n lexem += char\n else\n state = :end_lexem\n lexems << lexem unless lexem.empty?\n lexem = ''\n end\n when '\"'\n if state == :quote_lexem\n state = :end_lexem\n lexems << lexem\n lexem = ''\n else\n state = :quote_lexem\n end\n else\n lexem += char\n end\nend\n\nlexems.each do |lexem|\n puts '<'+lexem+'>'\nend\n"}], "src_uid": "6c7858731c57e1b24c7a299a8eeab373"} {"source_code": "p gets(p).split($/).uniq.size-1\n", "positive_code": [{"source_code": "p gets(p).split($/).uniq.size-1\n"}, {"source_code": "p gets(p).split($/).uniq.size-1\n"}, {"source_code": "p gets(p).split($/).uniq.size-1"}, {"source_code": "ls = Hash.new { |a, b| a[b] = [] }\nn, count = gets.to_i, 0\n\nn.times do\n\tl, c = gets.strip.split(\" \").map &:to_sym\n\tunless ls[l].include? c\n\t\tls[l].push c \n\t\tcount += 1\n\tend\nend\n\nprint count"}, {"source_code": "p gets(p).split($/).uniq.size-1\n"}, {"source_code": "Leaf = Struct.new(\"Leaf\", :tree, :color)\n\ncollection = {}\n\ngets.to_i.times do\n collection[Leaf.new(*gets.split)] = true\nend\n\n\nputs collection.size\n\n"}, {"source_code": "n = gets.to_i\n\nt = {}\nl = 0\n\nn.times do |i|\n tree,color = gets.split\n if t[tree] then\n if !(t[tree].include? color) then\n t[tree] << color \n l += 1\n end\n else\n t[tree] = [color]\n l += 1\n end\nend\n\nputs l"}, {"source_code": "n = gets.chomp.to_i\nh = Hash.new\nfor i in 0..n-1\n\th[gets.chomp] = true\nend\nputs h.length\n"}, {"source_code": "p gets(p).split($/).uniq.size-1\n"}, {"source_code": "#!/usr/bin/ruby\nh={}\ngets.to_i.times{h[gets]=1}\np h.size"}, {"source_code": "p gets(p).split($/).uniq.size-1\n"}, {"source_code": "p gets(p).split($/).uniq.size-1\n"}, {"source_code": "p gets(p).split($/).uniq.size-1"}, {"source_code": "p gets(p).split($/).uniq.size-1\n"}, {"source_code": "p gets(p).split($/).uniq.size-1\n"}, {"source_code": "p gets(p).split($/).uniq.size-1"}, {"source_code": "n = gets.to_i\n\nmas = Array.new()\nfor i in 0..n-1\n mas[i] = gets\nend\n\nputs mas.uniq.size"}], "negative_code": [], "src_uid": "07c370b99fe85984f5e20826a3bf5eb9"} {"source_code": "s = gets.chomp.to_s\ns = s.gsub(/(.)\\1\\1+/m,'\\1\\1')\ns = s.gsub(/(.)\\1(.)\\2/m,'\\1\\1\\2')\nputs s\n", "positive_code": [{"source_code": "s = gets.chomp.to_s\ns = s.gsub(/(.)\\1\\1+/m,'\\1\\1')\ns = s.gsub(/(.)\\1(.)\\2/m,'\\1\\1\\2')\nputs s\n"}, {"source_code": "s = gets.chomp.to_s\ns = s.gsub(/(.)\\1\\1+/m,'\\1\\1')\ns = s.gsub(/(.)\\1(.)\\2/m,'\\1\\1\\2')\nputs s\n"}, {"source_code": "s = gets.chomp.to_s\ns = s.gsub(/(.)\\1\\1+/m,'\\1\\1')\ns = s.gsub(/(.)\\1(.)\\2/m,'\\1\\1\\2')\nputs s\n"}, {"source_code": "string = gets.chomp\nlength = string.length\n\ncharacter_old = nil\ncharacter_current = nil\ncount_old = 0\ncount_current = 0\ni = 0\nstr = \"\"\nwhile i < length do\n if string[i] != character_current\n print character_old * count_old if character_old\n character_old = character_current\n character_current = string[i]\n count_old = count_current\n count_current = 1\n else\n count_current += 1\n if count_current == 3\n count_current -= 1\n elsif count_current == 2\n if count_old == 2\n count_current -=1\n end\n else\n end\n end\n i += 1\nend\n\nprint character_old * count_old if character_old\nprint character_current * count_current\n"}, {"source_code": "s = gets.chomp.to_s\ns = s.gsub(/(.)\\1\\1+/m,'\\1\\1')\ns = s.gsub(/(.)\\1(.)\\2/m,'\\1\\1\\2')\nputs s"}, {"source_code": "s = gets.chomp.to_s\ns = s.gsub(/(.)\\1\\1+/m,'\\1\\1')\ns = s.gsub(/(.)\\1(.)\\2/m,'\\1\\1\\2')\nputs s\n"}, {"source_code": "s = gets.chomp\nans = \"\"\ns.each_char do |a|\n\tif ((a == ans[-1]) && ans[-2] && (a == ans[-2])) || ((a == ans[-1]) && (ans[-2] && ans[-3] && (ans[-2] == ans[-3])))\n\telse\n\t\tans << a\n\tend\nend\nputs ans"}, {"source_code": "s = gets.strip\n\na = Array.new(s.size + 5)\npos = 0\n\nx = '*'\ny = '!'\nz = '~'\n\ns.each_char do |c|\n next if y == z and z == c\n next if x == y and z == c\n\n pos += 1\n a[pos] = c\n\n x = y\n y = z\n z = c\nend\n\n1.upto(pos) do |i|\n print a[i]\nend\nputs \"\"\n"}, {"source_code": "s = gets.chomp.to_s\ns = s.gsub(/(.)\\1\\1+/m,'\\1\\1')\ns = s.gsub(/(.)\\1(.)\\2/m,'\\1\\1\\2')\nputs s\n"}, {"source_code": "s = gets.chomp.to_s\ns = s.gsub(/(.)\\1\\1+/m,'\\1\\1')\ns = s.gsub(/(.)\\1(.)\\2/m,'\\1\\1\\2')\nputs s\n"}, {"source_code": "s = gets.chomp.to_s\ns = s.gsub(/(.)\\1\\1+/m,'\\1\\1')\ns = s.gsub(/(.)\\1(.)\\2/m,'\\1\\1\\2')\nputs s\n"}], "negative_code": [{"source_code": "string = gets.chomp\nlength = string.length\n\ncharacter_old = nil\ncharacter_current = nil\ncount_old = 0\ncount_current = 0\ni = 0\nremove_indexes = []\nwhile i < length do\n if string[i] != character_current\n character_old = character_current\n character_current = string[i]\n\n count_old = count_current\n count_current = 1\n else\n count_current += 1\n if count_current == 3\n remove_indexes << i - 1\n count_current -= 1\n elsif count_current == 2\n if count_old == 2\n remove_indexes << i - 2\n count_old -=1\n end\n else\n end\n end\n i += 1\nend\n\nstr = \"\"\nlength.times do |i|\n str += string[i] unless remove_indexes.include?(i)\nend\n\nputs str\n"}, {"source_code": "s = gets.chomp.to_s\ns = s.gsub(/(.)\\1\\1/m,'\\1\\1')\ns = s.gsub(/(.)\\1(.)\\2/m,'\\1\\1\\2')\nputs s"}, {"source_code": "s = gets.chomp\nans = \"\"\ns.each_char do |a|\n\tif (a == ans[-1] && a == ans[-2]) || ((a == ans[-1]) && (ans[-2] == ans[-3]))\n\telse\n\t\tans << a\n\tend\nend\nputs ans"}, {"source_code": "s = gets.strip\n\na = Array.new(s.size + 5)\npos = 0\n\nx = '*'\ny = '*'\nz = '*'\n\ns.each_char do |c|\n next if y == z and z == c\n next if x == y and z == c\n\n pos += 1\n a[pos] = c\n\n x = y\n y = z\n z = c\nend\n\n1.upto(pos) do |i|\n print a[i]\nend\nputs \"\"\n"}], "src_uid": "31d803d886c47fe681bdcfbe6c74f090"} {"source_code": "test_cases = gets.chomp.to_i\r\nfor i in 1..test_cases do\r\n line = gets.chomp.split(\" \")\r\n r = line[0].to_i\r\n b = line[1].to_i\r\n d = line[2].to_i\r\n puts [r, b].min * (d + 1) >= [r, b].max ? \"Yes\" : \"No\"\r\nend", "positive_code": [{"source_code": "gets.to_i.times{\r\n r,b,d = gets.split.map(&:to_i)\r\n r,b = [r,b].sort\r\n\tb = (b.to_f/r.to_f).ceil\r\n if b-1>d\r\n puts \"NO\"\r\n else \r\n puts \"YES\"\r\n end\r\n}\r\n"}, {"source_code": "t = gets.to_s.to_i\n\ndef solve(r, b, d)\n if d == 0\n return r == b\n end\n\n maxb = b + b * d\n return maxb >= r\nend\n\n1.upto(t) do |casenum|\n r, b, d = gets.to_s.split.map {|x| x.to_i }\n printf(\"%s\\n\", solve([r, b].max, [r, b].min, d) ? \"YES\" : \"NO\")\nend\n"}], "negative_code": [{"source_code": "gets.to_i.times{\r\n r,b,d = gets.split.map(&:to_i)\r\n r,b = [r,b].sort\r\n\tb = (b/r)+b%r\r\n if b-1>d\r\n puts \"NO\"\r\n else \r\n puts \"YES\"\r\n end\r\n}\r\n"}, {"source_code": "gets.to_i.times{\r\n r,b,d = gets.split.map(&:to_i)\r\n r,b = [r,b].sort\r\n\tb = (b/r)+b%r\r\n\tp b\r\n if b-1>d\r\n puts \"NO\"\r\n else \r\n puts \"YES\"\r\n end\r\n}\r\n"}], "src_uid": "c0ad2a6d14b0c9e09af2221d88a34d52"} {"source_code": "# http://codeforces.com/contest/1207/problem/A\n\ndef maximum_profit\n q = gets.chomp.to_i\n results = Array.new\n until q.zero? do\n ingredients = gets.chomp\n ingredients = get_each(ingredients)\n prices = gets.chomp\n prices = get_each(prices)\n results << get_maximum(ingredients, prices)\n q -= 1\n end\n results\nend\n$burger_num = 0\n\ndef get_maximum(ingredients, prices)\n $burger_num = ingredients[0]/2\n ham_num = ingredients[1]\n chicken_num = ingredients[2]\n pay = 0\n if prices[0] >= prices[1]\n pay += payment(prices[0], ham_num)\n pay += payment(prices[1], chicken_num)\n else\n pay += payment(prices[1], chicken_num)\n pay += payment(prices[0], ham_num)\n end\n pay\nend\n\ndef payment(price, ingredient)\n pay = 0\n if $burger_num >= ingredient\n pay = price * ingredient\n $burger_num -= ingredient\n else\n pay = price * $burger_num\n $burger_num = 0\n end\n pay\nend\n\ndef get_each(str)\n arr = Array.new\n num = 0\n str.each_char do |e|\n if e == ' '\n arr << num\n num = 0\n else\n num = num * 10 + e.to_i\n end\n end\n arr << num unless num.zero?\n arr\nend\n\nputs maximum_profit\n", "positive_code": [{"source_code": "t = readline.to_i\n\nt.times do\n b,p,f = readline.split.map(&:to_i)\n h,c = readline.split.map(&:to_i)\n if h >= c\n p1 = [b/2,p].min\n p2 = [(b - 2*p1)/2,f].min\n else\n p2 = [b/2,f].min\n p1 = [(b - 2*p2)/2,p].min\n end\n puts h*p1 + c*p2\nend"}, {"source_code": "q = gets.to_i\nq.times do\n n,a,b = gets.split.map(&:to_i)\n h,c = gets.split.map(&:to_i)\n ans = 0\n if h > c\n t = [n/2,a].min\n ans += t*h\n n -= t*2\n ans += c*[n/2,b].min\n else\n t = [n/2,b].min\n ans += t*c\n n -= t*2\n ans += h*[n/2,a].min\n end\n p ans\nend"}, {"source_code": "t=gets.to_i\nwhile t > 0\n total = 0\n b, p, f = gets.split.map(&:to_i)\n h, c= gets.split.map(&:to_i)\n t-=1\n if h > c\n total += ([(b/2).to_i, p].min) * h\n b -= ([(b/2).to_i, p].min)*2\n total += ([(b/2).to_i, f].min) * c\n else\n total += ([(b/2).to_i, f].min) * c\n b -= ([(b/2).to_i, f].min)*2\n total += ([(b/2).to_i, p].min) * h\n end\n puts(total) \nend\n"}, {"source_code": "gets.to_i.times do\n b, p, f = gets.split.map(&:to_i)\n h, c = gets.split.map(&:to_i)\n ans = 0\n if h >= c\n p_num = [b/2, p].min\n b -= p_num * 2\n ans += p_num * h\n ans += [b/2, f].min * c\n else\n f_num = [b/2, f].min\n b -= f_num * 2\n ans += f_num * c\n ans += [b/2, p].min * h\n end\n puts ans\nend"}, {"source_code": "def maximum_profit\n q = gets.chomp.to_i\n results = Array.new\n until q.zero? do\n ingredients = gets.chomp\n ingredients = get_each(ingredients)\n prices = gets.chomp\n prices = get_each(prices)\n results << get_maximum(ingredients, prices)\n q -= 1\n end\n results\nend\n$burger_num = 0\n\ndef get_maximum(ingredients, prices)\n $burger_num = ingredients[0]/2\n ham_num = ingredients[1]\n chicken_num = ingredients[2]\n pay = 0\n if prices[0] >= prices[1]\n pay += payment(prices[0], ham_num)\n pay += payment(prices[1], chicken_num)\n else\n pay += payment(prices[1], chicken_num)\n pay += payment(prices[0], ham_num)\n end\n pay\nend\n\ndef payment(price, ingredient)\n pay = 0\n if $burger_num >= ingredient\n pay = price * ingredient\n $burger_num -= ingredient\n else\n pay = price * $burger_num\n $burger_num = 0\n end\n pay\nend\n\ndef get_each(str)\n arr = Array.new\n num = 0\n str.each_char do |e|\n if e == ' '\n arr << num\n num = 0\n else\n num = num * 10 + e.to_i\n end\n end\n arr << num unless num.zero?\n arr\nend\n\nputs maximum_profit\n"}, {"source_code": "t = gets.to_i\nbpf = []\nhc = []\nt.times do|_x|\n bpf << gets.split.map(&:to_i)\n hc << gets.split.map(&:to_i)\nend\n\nmax = []\n0.upto(t-1) do |i|\n price = 0\n buns = bpf[i][0]\n beef = bpf[i][1]\n chi = bpf[i][2]\n price1 = hc[i][0]\n price2 = hc[i][1]\n\n if price1 >= price2\n # \u30cf\u30f3\u30d0\u30fc\u30ac\u30fc\u3092\u512a\u5148\u3057\u3066\u4f5c\u308b\n if beef*2 > buns\n # beef\u304c\u591a\u3044\u306a\u3089buns\u304c\u8db3\u308a\u308b\u307e\u3067\u4f7f\u3046\n price = buns / 2 * price1\n else\n buns -= beef * 2\n price = beef*price1 + (chi*2>buns ? buns/2 : chi)*price2\n end\n else\n # \u30c1\u30ad\u30f3\u30d0\u30fc\u30ac\u30fc\u3092\u512a\u5148\u3057\u3066\u4f5c\u308b\n if chi*2 > buns\n # chi\u304c\u591a\u3044\u306a\u3089buns\u304c\u8db3\u308a\u308b\u307e\u3067\u4f7f\u3046\n price = buns / 2 * price2\n else\n buns -= chi * 2\n price = chi*price2 + (beef*2>buns ? buns/2 : beef)*price1\n end\n end\n max << price\nend\nputs max.join(\"\\n\")"}, {"source_code": "t = gets.to_i\nt.times do\n b, p, f = gets.split.map &:to_i\n h, c = gets.split.map &:to_i\n if h > c\n hs = [b/2, p].min\n cs = [(b - hs*2)/2, f].min\n else\n cs = [b/2, f].min\n hs = [(b - cs*2)/2, p].min\n end\n puts hs*h + cs*c\nend\n"}, {"source_code": "1.upto(gets.to_i) do\n b, p, f = gets.split(' ').map(&:to_i)\n h, c = gets.split(' ').map(&:to_i)\n\n puts (0..b/2).map { |x| [x, p].min*h + [(b/2 - x), f].min*c }.max\nend\n"}], "negative_code": [], "src_uid": "92bf30e66f4d5ddebb697d2fa4fa0689"} {"source_code": "n,m = gets.split.map &:to_i\na = [nil]*(n+m)\n0.upto(n+m) {|i| a[i] = []}\n\n0.upto(n-1) do |i|\n s = gets.chomp\n len = s.size\n 0.upto(len) do |j|\n if s[j] == '#'\n a[i] << n+j\n a[n+j] << i\n end\n end\nend\n\nd = [100500] * 2100\nq = []\nd[0] = 0\nq << 0\nwhile !q.empty? do\n x = q.shift\n a[x].each do |y|\n if d[y] == 100500\n d[y] = d[x] + 1\n q << y\n end\n end\nend\n\nif d[n-1] == 100500\n puts -1\n exit\nend\nputs d[n-1]\n\n", "positive_code": [{"source_code": "n,m = gets.split.map &:to_i\na = [nil]*(n+m)\n0.upto(n+m) {|i| a[i] = []}\n\n0.upto(n-1) do |i|\n s = gets.chomp\n len = s.size\n 0.upto(len) do |j|\n if s[j] == '#'\n a[i] << n+j\n a[n+j] << i\n end\n end\nend\n\nd = [100500] * 2100\nq = []\nd[0] = 0\nq << 0\nwhile !q.empty? do\n x = q.shift\n a[x].each do |y|\n if d[y] == 100500\n d[y] = d[x] + 1\n q << y\n end\n end\nend\n\nif d[n-1] == 100500\n puts -1\n exit\nend\nputs d[n-1]\n\n"}, {"source_code": "n,m = gets.split.map &:to_i\na = [nil]*(n+m)\n0.upto(n+m) {|i| a[i] = []}\n\n0.upto(n-1) do |i|\n s = gets.chomp\n len = s.size\n 0.upto(len) do |j|\n if s[j] == '#'\n a[i] << n+j\n a[n+j] << i\n end\n end\nend\n\nd = [100500] * 2100\nq = []\nd[0] = 0\nq << 0\nwhile !q.empty? do\n x = q.shift\n a[x].each do |y|\n if d[y] == 100500\n d[y] = d[x] + 1\n q << y\n end\n end\nend\n\nif d[n-1] == 100500\n puts -1\n exit\nend\nputs d[n-1]\n\n"}, {"source_code": "n,m = gets.split.map &:to_i\na = [nil]*(n+m)\n0.upto(n+m) {|i| a[i] = []}\n\n0.upto(n-1) do |i|\n s = gets.chomp\n len = s.size\n 0.upto(len) do |j|\n if s[j] == '#'\n a[i] << n+j\n a[n+j] << i\n end\n end\nend\n\nd = [100500] * 2100\nq = []\nd[0] = 0\nq << 0\nwhile !q.empty? do\n x = q.shift\n a[x].each do |y|\n if d[y] == 100500\n d[y] = d[x] + 1\n q << y\n end\n end\nend\n\nif d[n-1] == 100500\n puts -1\n exit\nend\nputs d[n-1]\n"}, {"source_code": "n,m = gets.split.map &:to_i\na = [nil]*(n+m)\n0.upto(n+m) {|i| a[i] = []}\n\n0.upto(n-1) do |i|\n s = gets.chomp\n len = s.size\n 0.upto(len) do |j|\n if s[j] == '#'\n a[i] << n+j\n a[n+j] << i\n end\n end\nend\n\nd = [100500] * 2100\nq = []\nd[0] = 0\nq << 0\nwhile !q.empty? do\n x = q.shift\n a[x].each do |y|\n if d[y] == 100500\n d[y] = d[x] + 1\n q << y\n end\n end\nend\n\nif d[n-1] == 100500\n puts -1\n exit\nend\nputs d[n-1]\n\n"}, {"source_code": "n,m = gets.split.map &:to_i\na = [nil]*(n+m)\n0.upto(n+m) {|i| a[i] = []}\n\n0.upto(n-1) do |i|\n s = gets.chomp\n len = s.size\n 0.upto(len) do |j|\n if s[j] == '#'\n a[i] << n+j\n a[n+j] << i\n end\n end\nend\n\nd = [100500] * 2100\nq = []\nd[0] = 0\nq << 0\nwhile !q.empty? do\n x = q.shift\n a[x].each do |y|\n if d[y] == 100500\n d[y] = d[x] + 1\n q << y\n end\n end\nend\n\nif d[n-1] == 100500\n puts -1\n exit\nend\nputs d[n-1]\n\n"}, {"source_code": "n,m = gets.split.map &:to_i\na = [nil]*(n+m)\n0.upto(n+m) {|i| a[i] = []}\n 0.upto(n-1) do |i|\n s = gets.chomp\n len = s.size\n 0.upto(len) do |j|\n if s[j] == '#'\n a[i] << n+j\n a[n+j] << i\n end\n end\nend\n d = [100500] * 2100\nq = []\nd[0] = 0\nq << 0\nwhile !q.empty? do\n x = q.shift\n a[x].each do |y|\n if d[y] == 100500\n d[y] = d[x] + 1\n q << y\n end\n end\nend\n if d[n-1] == 100500\n puts -1\n exit\nend\nputs d[n-1]"}, {"source_code": "n,m = gets.split.map &:to_i\na = [nil]*(n+m)\n0.upto(n+m) {|i| a[i] = []}\n\n0.upto(n-1) do |i|\n s = gets.chomp\n len = s.size\n 0.upto(len) do |j|\n if s[j] == '#'\n a[i] << n+j\n a[n+j] << i\n end\n end\nend\n\nd = [100500] * 2100\nq = []\nd[0] = 0\nq << 0\nwhile !q.empty? do\n x = q.shift\n a[x].each do |y|\n if d[y] == 100500\n d[y] = d[x] + 1\n q << y\n end\n end\nend\n\nif d[n-1] == 100500\n puts -1\n exit\nend\nputs d[n-1]\n"}, {"source_code": "n,m = gets.split.map &:to_i\na = [nil]*(n+m)\n0.upto(n+m) {|i| a[i] = []}\n\n0.upto(n-1) do |i|\n s = gets.chomp\n len = s.size\n 0.upto(len) do |j|\n if s[j] == '#'\n a[i] << n+j\n a[n+j] << i\n end\n end\nend\n\nd = [100500] * 2100\nq = []\nd[0] = 0\nq << 0\nwhile !q.empty? do\n x = q.shift\n a[x].each do |y|\n if d[y] == 100500\n d[y] = d[x] + 1\n q << y\n end\n end\nend\n\nif d[n-1] == 100500\n puts -1\n exit\nend\nputs d[n-1]\n\n"}, {"source_code": "n,m = gets.split.map &:to_i\na = [nil]*(n+m)\n0.upto(n+m) {|i| a[i] = []}\n\n0.upto(n-1) do |i|\n s = gets.chomp\n len = s.size\n 0.upto(len) do |j|\n if s[j] == '#'\n a[i] << n+j\n a[n+j] << i\n end\n end\nend\n\nd = [100500] * 2100\nq = []\nd[0] = 0\nq << 0\nwhile !q.empty? do\n x = q.shift\n a[x].each do |y|\n if d[y] == 100500\n d[y] = d[x] + 1\n q << y\n end\n end\nend\n\nif d[n-1] == 100500\n puts -1\n exit\nend\nputs d[n-1]\n\n"}, {"source_code": "n,m = gets.split.map &:to_i\na = [nil]*(n+m)\n0.upto(n+m) {|i| a[i] = []}\n\n0.upto(n-1) do |i|\n s = gets.chomp\n len = s.size\n 0.upto(len) do |j|\n if s[j] == '#'\n a[i] << n+j\n a[n+j] << i\n end\n end\nend\n\nd = [100500] * 2100\nq = []\nd[0] = 0\nq << 0\nwhile !q.empty? do\n x = q.shift\n a[x].each do |y|\n if d[y] == 100500\n d[y] = d[x] + 1\n q << y\n end\n end\nend\n\nif d[n-1] == 100500\n puts -1\n exit\nend\nputs d[n-1]\n\n"}], "negative_code": [], "src_uid": "8b6f93cf2a41445649e0cbfc471541b6"} {"source_code": "gets.to_i.times {\n gets\n s = gets.strip\n n = s.count '0'\n if s.size.odd? && s[s.size / 2] == '0'\n puts(n > 1 ? 'ALICE' : 'BOB')\n else\n #puts(n % 4 == 0 ? 'DRAW' : 'BOB')\n puts 'BOB'\n end\n}\n", "positive_code": [{"source_code": "gets.to_i.times{|c|\r\n\tn = gets.to_i\r\n\ts = gets.chomp\r\n\tif s.count(?0)==1 then\r\n\t\tputs 'BOB'\r\n\t\tnext\r\n\telsif s.count(?0)==0 then\r\n\t\tputs 'DRAW'\r\n\t\tnext\r\n\tend\r\n\tputs (n%2==1&&s[n/2]=='0') ? 'ALICE' : 'BOB'\r\n}"}, {"source_code": "gets.to_i.times do\r\n gets\r\n s = gets.chomp\r\n cnt = s.count '0'\r\n if cnt == 1\r\n puts \"BOB\"\r\n elsif cnt % 2 == 1\r\n puts \"ALICE\"\r\n else\r\n puts \"BOB\"\r\n end\r\nend"}], "negative_code": [{"source_code": "gets.to_i.times {\n gets\n n = gets.strip.count '0'\n puts(n % 4 == 0 ? 'DRAW' : 'BOB')\n}\n"}], "src_uid": "42b425305ccc28b0d081b4c417fe77a1"} {"source_code": "n, m = gets.split(' ').map(&:to_i)\nl = gets.split(' ')\nsa, r = l[0], []\na = sa.to_i\n(1...n).each do |i|\n sb = l[i]\n b = sb.to_i\n l[i] = \"#{a} #{b}\"\n a, sa, sb = b, sb, sa, a if a < b\n r.push sb\nend\nn -= 1\nm.times do\n q = gets.to_i\n puts n < q ? \"#{a} #{r[(q - 1) % n]}\" : l[q]\nend", "positive_code": [{"source_code": "n, m = gets.split(' ').map(&:to_i)\nl = gets.split(' ')\nsa, r = l[0], []\na = sa.to_i\n(1...n).each do |i|\n sb = l[i]\n b = sb.to_i\n l[i] = \"#{a} #{b}\"\n a, sa, sb = b, sb, sa, a if a < b\n r.push sb\nend\nn -= 1\nm.times do\n q = gets.to_i\n puts n < q ? \"#{sa} #{r[(q - 1) % n]}\" : l[q]\nend"}, {"source_code": "inp = gets\nn, q = inp.split(' ').map(&:to_i)\n\ninp = gets\na = inp.split(' ').map(&:to_i)\n\ni_max = 0\ndeque = []\nn_deque = 0\n\nfor i in 0..n-1\n if a[i] > a[i_max]\n i_max = i\n end\nend\n\nfor i in i_max+1..n-1\n deque[n_deque] = a[i]\n n_deque += 1\nend\n\nst = []\ned = []\nn_query = 0\ni1 = 0\ni2 = 1\n\nwhile i1 != i_max \n st[n_query] = a[i1]\n ed[n_query] = a[i2]\n if a[i1] > a[i2]\n deque[n_deque] = a[i2]\n i2 += 1\n else\n deque[n_deque] = a[i1]\n i1 = i2\n i2 += 1 \n end\n n_deque += 1\n n_query += 1\nend\n\nfor i in 0..q-1\n inp = gets\n q_i = inp.to_i\n if q_i <= n_query\n puts \"#{st[q_i-1]} #{ed[q_i-1]}\"\n else\n puts \"#{a[i_max]} #{deque[(q_i - i_max + n_deque) % n_deque - 1]}\"\n end\nend"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\nl = gets.split(' ').map(&:to_i)\na, r = l[0], []\n(1...n).each do |i|\n b = l[i]\n l[i] = \"#{a} #{b}\"\n a, b = b, a if a < b\n r.push b\nend\nn -= 1\nm.times do\n q = gets.to_i\n puts n < q ? \"#{a} #{r[(q - 1) % n]}\" : l[q]\nend"}], "negative_code": [{"source_code": "inp = gets\nn, q = inp.split(' ').map(&:to_i)\n\ninp = gets\na = inp.split(' ').map(&:to_i)\n\ni_max = 0\ndeque = []\nn_deque = 0\n\nfor i in 0..n-1\n if a[i] > a[i_max]\n i_max = i\n end\nend\n\nfor i in i_max+1..n-1\n deque[n_deque] = a[i]\n n_deque += 1\nend\n\nst = []\ned = []\nn_query = 0\ni1 = 0\ni2 = 1\n\nwhile i1 != i_max \n st[n_query] = a[i1]\n ed[n_query] = a[i2]\n if a[i1] > a[i2]\n deque[n_deque] = a[i2]\n i2 += 1\n else\n deque[n_deque] = a[i1]\n i1 = i2\n i2 += 1 \n end\n n_deque += 1\n n_query += 1\nend\n\nfor i in 0..q-1\n inp = gets\n q_i = inp.to_i\n if q_i <= n_query\n puts \"#{st[q_i-1]} #{ed[q_i-1]}\"\n else\n puts i_max\n puts q_i\n puts n_deque\n puts \"#{a[i_max]} #{deque[(q_i - i_max + n_deque) % n_deque - 1]}\"\n end\nend"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\nl = gets.split(' ').map(&:to_i)\na, buf, res = l.shift, [], []\nl.each do |b|\n buf.push \"#{a} #{b}\"\n a, b = b, a if a < b\n res.push b\nend\nn -= 1\nm.times do\n q = gets.to_i\n puts q < n ? buf[q - 1] : \"#{a} #{res[(q - 1) % n]}\"\nend"}], "src_uid": "3cb19ef77e9cb919a2f0a1d687b2845d"} {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\nans = 4\nn.times do |i|\n line = gets.chomp.split(/ /).map(&:to_i)\n m.times do |j|\n if line[j] == 1\n ans = 2 if i == 0 || i == n - 1\n ans = 2 if j == 0 || j == m - 1\n end\n end\nend\nputs ans\n", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nn.times do |i|\n a = gets.split(' ')\n if i == 0 || i == n-1\n if a.any? { |e| e == '1' }\n puts 2\n exit\n end\n elsif a.first == '1' || a.last == '1'\n puts 2\n exit\n end\nend\nputs 4\n"}, {"source_code": "n,m=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.include? '1'\nfor i in 0..n-3 do\n\tx=gets.chomp.split\n\tif x[-1]=='1' || x[0]=='1'\n\t\tb=true\n\tend\nend\nc=gets.chomp.split.include? '1'\nputs (a||c||b)? \"2\" : \"4\""}, {"source_code": "def run\n m, n = $stdin.gets.split.map(&:to_i)\n a = $stdin.readlines.map {|line| line.split.map(&:to_i) }\n min = 4\n a.each_with_index do |x, i|\n x.each_with_index do |y, j|\n if y == 1\n cnt = 0\n cnt += 1 if i == 0 or i == m - 1\n cnt += 1 if j == 0 or j == n - 1\n\n if cnt == 1\n min = [2, min].min\n elsif cnt == 2\n min = [1, min].min\n end\n end\n end\n end\n\n puts min\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "m,n = gets.split(\" \").map(&:to_i)\narr = []\nm.times do\n\tarr << gets.split(\" \").map(&:to_i)\nend\nans = nil\nans = 2 if arr[0].include?(1) || arr[m-1].include?(1)\nunless ans\n\tj = 0\n\t(0..m-1).each do |i|\n\t\tif arr[i][j] == 1\n\t\t\tans = 2\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nunless ans\n\tj = n - 1\n\t(0..m-1).each do |i|\n\t\tif arr[i][j] == 1\n\t\t\tans = 2\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nans = 4 unless ans\nputs ans"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\na = Array.new(n)\n(0...n).each do |i|\n a[i] = gets.split\nend\nif a[0].count(\"1\") > 0 or a[n-1].count(\"1\") > 0 or\\\n a.transpose[0].count(\"1\") > 0 or a.transpose[m-1].count(\"1\") > 0\n puts 2\nelse\n puts 4\nend\n"}, {"source_code": "def parse(s)\n s = s.split\n for i in 0...s.length do s[i] = s[i].to_i end\n s\nend\n \nn,m = parse gets\na = []\n(0...n).each { |i|\n a << []\n (parse gets).each { |val|\n a[-1] << val\n } \n}\n\n(a[0]+a[-1]).each do |i| if i == 1 then puts 2; exit 0 end end\n(0...n).each do |i| if a[i][-1] == 1 or a[i][0] == 1 then puts 2; exit 0 end end\nputs 4\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nd=false\nn.times do |i|\n r=gets.split.map(&:to_i)\n if (i==0||i==n-1)&&r.include?(1)||r[0]==1|| r[m-1]==1\n d=true\n break\n end\nend\np d ? 2:4\n\n"}, {"source_code": "line = gets.chomp.split(\" \").map {|e| e.to_i}\n\nside = false\n\ntable = []\nline[0].times do\n row = gets.chomp.split(\" \").map {|e| e.to_i}\n if ((table.length == 0 || table.length == (line[0] - 1)) && row.include?(1))\n side = true\n end\n\n if row[0] == 1 || row[line[1] - 1] == 1\n side = true\n end\n\n table.push(row)\nend\n\nif side\n puts 2\nelse\n puts 4\nend\n\n\n"}, {"source_code": "def main\n n, m = STDIN.readline.chomp.split.map{|x| x.to_i}\n lis = []\n n.times do |i|\n lis << STDIN.readline.chomp.split.map{|x|x.to_i}\n end\n \n if (not lis.first.select{|x| x == 1}.empty?) or (not lis.last.select{|x| x == 1}.empty?) then\n puts 2\n return\n else\n lis.each do |x|\n if x.first == 1 or x.last == 1 then\n puts 2\n return\n end\n end\n end\n puts 4\nend\n\nif __FILE__ == $0\n main\nend\n"}], "negative_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nn.times do\n a = gets.split(' ')\n if a.first == '1' || a.last == '1'\n puts 2\n exit\n end\nend\nputs 4\n"}, {"source_code": "n,m=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.include? '1'\nfor i in 0..n-3 do\n\tx=gets.chomp.split\n\tif x[-1]=='1'\n\t\tb=true\n\tend\nend\nc=gets.chomp.split.include? '1'\nputs (a||c||b)? \"2\" : \"4\""}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\ngood_cells = []\nn.times do |i|\n line = gets.chomp.split(/ /).map(&:to_i)\n line.each do |j|\n good_cells << [i, j] if line[j] == 1\n end\nend\nans = 4\ngood_cells.each do |cell|\n x = cell[0]\n y = cell[1]\n if x == 0 || y == 0 || x == n - 1 || y == m - 1\n ans = 2\n break\n end\nend\nputs ans\n"}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\ntable = []\ngood_cells = []\nn.times do |i|\n line = gets.chomp.split(/ /).map(&:to_i)\n line.each do |j|\n good_cells << [i, j] if line[j] == 1\n end\n table << line\nend\nans = 4\ngood_cells.each do |cell|\n x = cell[0]\n y = cell[1]\n ans = 2 if x == 0 || y == 0 || x == n - 1 || y == m - 1\nend\nputs ans\n"}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\ntable = []\ngood_cells = []\nn.times do |i|\n line = gets.chomp.split(/ /).map(&:to_i)\n line.each do |j|\n good_cells << [i, j] if line[j] == 1\n end\n table << line\nend\nans = 4\ngood_cells.each do |cell|\n x = cell[0]\n y = cell[1]\n ans = 2 if x == 0 || x == n - 1\n ans = 2 if y == 0 || y == m - 1\nend\nputs ans\n"}], "src_uid": "0d2fd9b58142c4f5282507c916690244"} {"source_code": "require 'openssl'\nrequire 'prime'\n\n$stdout.sync = true\n\ndef ask(x)\n puts \"sqrt #{x}\"\n gets.to_i\nend\n\ndef run(n)\n loop do\n a = rand(2..n - 1)\n g = n.gcd(a)\n return g if g != 1\n a2 = a * a % n\n next if a2.gcd(n) != 1\n r = ask(a2) % n\n next if r == -1 || r == a || r == n - a\n g = n.gcd(n + r - a)\n next if g == 1\n return g\n end\nend\n\nn = gets.to_i\nfac = [n]\n\nuntil fac.all?{|f| f.to_bn.prime?}\n x = run(n)\n nfac = []\n fac.each do |y|\n g = x.gcd(y)\n if g == 1 || g == y\n nfac << y\n else\n nfac << g << y / g\n x /= g\n end\n end\n fac << x if x > 1\n fac = nfac\nend\n\nputs \"! #{fac.size} #{fac * ' '}\"\n", "positive_code": [{"source_code": "def modpow(a,b,m)\n r = 1\n while b > 0\n r = r * a % m if b % 2 == 1\n a = a * a % m\n b >>= 1\n end\n return r\nend\n\ndef isprime(n)\n return true if n == 2\n return false if n == 1 || n & 1 == 0\n d = n-1\n d >>= 1 while d & 1 == 0\n 20.times do\n a = rand(n-2) + 1\n t = d\n y = modpow(a,t,n)\n while t != n-1 && y != 1 && y != n-1\n y = (y * y) % n\n t <<= 1\n end\n return false if y != n-1 && t & 1 == 0\n end\n return true\nend\n\ndef solve(n,gn)\n # puts \"solve #{n}\"\n while true\n x = rand(1...n)\n x2 = x * x % gn\n puts \"sqrt #{x2}\"\n STDOUT.flush\n y = gets.chomp.to_i % n\n next if x == y\n gg = x - y\n gg = -gg if gg < 0\n q = n.gcd(gg)\n next if q == 1 or q == n\n # ok\n ret = []\n if isprime(q)\n ret.push(q)\n else\n ret = solve(q,gn)\n end\n q = n/q\n if isprime(q)\n ret.push(q)\n else\n ret.concat(solve(q,gn))\n end\n return ret\n end\nend\n\nn = gets.chomp.to_i\nans = solve(n,n)\nansstr = \"! #{ans.length} #{ans.join(' ')}\"\nputs ansstr\nSTDOUT.flush\n"}], "negative_code": [{"source_code": "def modpow(a,b,m)\n r = 1\n while b > 0\n r = r * a % m if b % 2 == 1\n a = a * a % m\n b >>= 1\n end\n return r\nend\n\ndef isprime(n)\n return true if n == 2\n return false if n == 1 || n & 1 == 0\n d = n-1\n d >>= 1 while d & 1 == 0\n 20.times do\n a = rand(n-2) + 1\n t = d\n y = modpow(a,t,n)\n while t != n-1 && y != 1 && y != n-1\n y = (y * y) % n\n t <<= 1\n end\n return false if y != n-1 && t & 1 == 0\n end\n return true\nend\n\ndef solve(n,gn)\n # puts \"solve #{n}\"\n while true\n x = rand(1...n)\n x2 = x * x % n\n puts \"sqrt #{x2}\"\n STDOUT.flush\n y = gets.chomp.to_i % n\n next if x == y\n gg = x - y\n gg = -gg if gg < 0\n q = n.gcd(gg)\n next if q == 1 or q == n\n # ok\n ret = []\n if isprime(q)\n ret.push(q)\n else\n ret = solve(q,gn)\n end\n q = n/q\n if isprime(q)\n ret.push(q)\n else\n ret.concat(solve(q,gn))\n end\n return ret\n end\nend\n\nn = gets.chomp.to_i\nans = solve(n,n)\nansstr = \"! #{ans.length} #{ans.join(' ')}\"\nputs ansstr\nSTDOUT.flush\n"}, {"source_code": "def modpow(a,b,m)\n r = 1\n while b > 0\n r = r * a % m if b % 2 == 1\n a = a * a % m\n b >>= 1\n end\n return r\nend\n\ndef isprime(n)\n return true if n == 2\n return false if n == 1 || n & 1 == 0\n d = n-1\n d >>= 1 while d & 1 == 0\n 20.times do\n a = rand(n-2) + 1\n t = d\n y = modpow(a,t,n)\n while t != n-1 && y != 1 && y != n-1\n y = (y * y) % n\n t <<= 1\n end\n return false if y != n-1 && t & 1 == 0\n end\n return true\nend\n\ndef solve(n)\n while true\n x = rand(1...n)\n x2 = x * x % n\n puts \"sqrt #{x2}\"\n STDOUT.flush\n y = gets.chomp.to_i\n next if x == y\n gg = x - y\n gg = -gg if gg < 0\n q = n.gcd(gg)\n next if q == 1 or q == n\n # ok\n ret = []\n if isprime(q)\n ret.push(q)\n else\n ret = solve(q)\n end\n q = n/q\n if isprime(q)\n ret.push(q)\n else\n ret.concat(solve(q))\n end\n return ret\n end\nend\n\nn = gets.chomp.to_i\nans = solve(n)\nm = 1\nfor i in 0...ans.length\n m = m * ans[i]\nend\nif m != n\n exit(1)\nend\nansstr = \"! #{ans.length} #{ans.join(' ')}\"\nputs ansstr\nSTDOUT.flush\n"}, {"source_code": "def modpow(a,b,m)\n r = 1\n while b > 0\n r = r * a % m if b % 2 == 1\n a = a * a % m\n b >>= 1\n end\n return r\nend\n\ndef isprime(n)\n return true if n == 2\n return false if n == 1 || n & 1 == 0\n d = n-1\n d >>= 1 while d & 1 == 0\n 20.times do\n a = rand(n-2) + 1\n t = d\n y = modpow(a,t,n)\n while t != n-1 && y != 1 && y != n-1\n y = (y * y) % n\n t <<= 1\n end\n return false if y != n-1 && t & 1 == 0\n end\n return true\nend\n\ndef solve(n)\n while true\n x = rand(1...n)\n x2 = x * x % n\n puts \"sqrt #{x2}\"\n STDOUT.flush\n y = gets.chomp.to_i\n next if x == y\n gg = x - y\n gg = -gg if gg < 0\n q = n.gcd(gg)\n next if q == 1 or q == n\n # ok\n ret = []\n if isprime(q)\n ret.push(q)\n else\n ret = solve(q)\n end\n q = n/q\n if isprime(q)\n ret.push(q)\n else\n ret.concat(solve(q))\n end\n return ret\n end\nend\n\nn = gets.chomp.to_i\nans = solve(n)\nansstr = \"! #{ans.length} #{ans.join(' ')}\"\nputs ansstr"}, {"source_code": "def modpow(a,b,m)\n r = 1\n while b > 0\n r = r * a % m if b % 2 == 1\n a = a * a % m\n b >>= 1\n end\n return r\nend\n\ndef fa()\n n = 30\n while true\n n = n * n\n n = n % 252521\n end\n return n\nend\ncnt = 0\n\ndef isprime(n)\n return true if n == 2\n return false if n == 1 || n & 1 == 0\n d = n-1\n d >>= 1 while d & 1 == 0\n 20.times do\n a = rand(n-2) + 1\n t = d\n y = modpow(a,t,n)\n while t != n-1 && y != 1 && y != n-1\n y = (y * y) % n\n t <<= 1\n end\n return false if y != n-1 && t & 1 == 0\n end\n return true\nend\n\ndef solve(n)\n while true\n x = rand(1...n)\n x2 = x * x % n\n puts \"sqrt #{x2}\"\n STDOUT.flush\n y = gets.chomp.to_i % n\n next if x == y\n gg = x - y\n gg = -gg if gg < 0\n q = n.gcd(gg)\n next if q == 1 or q == n\n # ok\n ret = []\n if isprime(q)\n ret.push(q)\n else\n ret = solve(q)\n end\n q = n/q\n if isprime(q)\n ret.push(q)\n else\n ret.concat(solve(q))\n end\n return ret\n end\nend\n\nn = gets.chomp.to_i\nans = solve(n)\nansstr = \"! #{ans.length} #{ans.join(' ')}\"\nputs ansstr\nSTDOUT.flush\n"}, {"source_code": "require 'openssl'\nrequire 'prime'\n\n$stdout.sync = true\n$sol = []\n$memo = {}\n\ndef ask(x)\n return -1 if x.gcd($n) != 1\n return -1 if x < 0 || x >= $n\n return $memo[x] if $memo.include?(x)\n puts \"sqrt #{x}\"\n ans = gets.to_i\n $memo[x] = ans\n ans\nend\n\ndef go(n)\n if n.to_bn.prime?\n $sol << n\n return\n end\n\n if n < 100000\n $sol += n.prime_division.map(&:first)\n return\n end\n\n loop do\n a = rand(2..n-1)\n g = n.gcd(a)\n if g != 1 && g != n\n go(g)\n go(n / g)\n break\n end\n a2 = a * a % n\n r = ask(a2)\n next if r == -1\n r %= n\n next unless r * r % n == a2\n next if r == a || r == n - a\n g = n.gcd(n + r - a)\n next if g == 1 || g == n\n go(g)\n go(n / g)\n break\n end\nend\n\nn = gets.to_i\n$n = n\ngo(n)\nputs \"! #{$sol.size} #{$sol.sort.join(' ')}\"\n"}, {"source_code": "require 'openssl'\nrequire 'prime'\n\n$stdout.sync = true\n\ndef ask(x)\n puts \"sqrt #{x}\"\n gets.to_i\nend\n\ndef run(n)\n loop do\n a = rand(2..n - 1)\n g = n.gcd(a)\n return g if g != 1\n a2 = a * a % n\n next if a2.gcd(n) != 1\n r = ask(a2) % n\n next if r == -1 || r == a || r == n - a\n g = n.gcd(n + r - a)\n next if g == 1\n return g\n end\nend\n\nn = gets.to_i\nfac = [n]\n\nuntil fac.all?{|f| f.to_bn.prime?}\n x = run(n)\n nfac = []\n fac.each do |y|\n g = x.gcd(y)\n if g == 1\n nfac << y\n else\n nfac << g << y / g\n x /= g\n end\n end\n fac = nfac\nend\n\nputs \"! #{fac.size} #{fac * ' '}\"\n"}, {"source_code": "require 'openssl'\nrequire 'prime'\n\n$stdout.sync = true\n$sol = []\n\ndef go(n)\n if n.to_bn.prime?\n $sol << n\n return\n end\n\n if n < 100000\n $sol += n.prime_division.map(&:first)\n return\n end\n\n loop do\n a = rand(2..n-1)\n g = n.gcd(a)\n if g != 1 && g != n\n go(g)\n go(n / g)\n break\n end\n a2 = a * a % n\n puts \"sqrt #{a2}\"\n r = gets.to_i\n next if r == -1\n r %= n\n next unless r * r % n == a2\n next if r == a || r == n - a\n g = n.gcd(n + r - a)\n next if g == 1 || g == n\n go(g)\n go(n / g)\n break\n end\nend\n\nn = gets.to_i\ngo(n)\nputs \"! #{$sol.size} #{$sol.sort.join(' ')}\"\n"}, {"source_code": "require 'openssl'\nrequire 'prime'\n\n$stdout.sync = true\n$sol = []\n\ndef go(n)\n if n.to_bn.prime?\n $sol << n\n return\n end\n\n # if n < 100000\n # $sol += n.prime_division.map(&:first)\n # return\n # end\n\n loop do\n a = rand(2..n-1)\n a2 = a * a % n\n if a2 == 0\n g = n.gcd(a)\n next if g == 1 || g == n\n go(g)\n go(n / g)\n break\n end\n puts \"sqrt #{a2}\"\n r = gets.to_i\n next if r == -1\n r %= n\n next unless r * r % n == a2\n next if r == a || r == n - a\n g = n.gcd(n + r - a)\n next if g == 1 || g == n\n go(g)\n go(n / g)\n break\n end\nend\n\nn = gets.to_i\ngo(n)\nputs \"! #{$sol.size} #{$sol.sort.join(' ')}\"\n"}, {"source_code": "require 'openssl'\nrequire 'prime'\n\n$stdout.sync = true\n$sol = []\n$memo = {}\n\ndef ask(x)\n return -1 if x.gcd($n) != 1\n return $memo[x] if $memo.include?(x)\n puts \"sqrt #{x}\"\n ans = gets.to_i\n $memo[x] = ans\n ans\nend\n\ndef go(n)\n if n.to_bn.prime?\n $sol << n\n return\n end\n\n if n < 100000\n $sol += n.prime_division.map(&:first)\n return\n end\n\n loop do\n a = rand(2..n-1)\n g = n.gcd(a)\n if g != 1 && g != n\n go(g)\n go(n / g)\n break\n end\n a2 = a * a % n\n r = ask(a2)\n next if r == -1\n r %= n\n next unless r * r % n == a2\n next if r == a || r == n - a\n g = n.gcd(n + r - a)\n next if g == 1 || g == n\n go(g)\n go(n / g)\n break\n end\nend\n\nn = gets.to_i\n$n = n\ngo(n)\nputs \"! #{$sol.size} #{$sol.sort.join(' ')}\"\n"}, {"source_code": "require 'openssl'\nrequire 'prime'\n\n$stdout.sync = true\n$sol = []\n\ndef ask(x)\n return -1 if x.gcd($n) != 1\n puts \"sqrt #{x}\"\n gets.to_i\nend\n\ndef go(n)\n if n.to_bn.prime?\n $sol << n\n return\n end\n\n if n < 100000\n $sol += n.prime_division.map(&:first)\n return\n end\n\n loop do\n a = rand(2..n-1)\n g = n.gcd(a)\n if g != 1 && g != n\n go(g)\n go(n / g)\n break\n end\n a2 = a * a % n\n r = ask(a2)\n next if r == -1\n r %= n\n next unless r * r % n == a2\n next if r == a || r == n - a\n g = n.gcd(n + r - a)\n next if g == 1 || g == n\n go(g)\n go(n / g)\n break\n end\nend\n\nn = gets.to_i\n$n = n\ngo(n)\nputs \"! #{$sol.size} #{$sol.sort.join(' ')}\"\n"}, {"source_code": "require 'openssl'\nrequire 'prime'\n\n$stdout.sync = true\n$sol = []\n$memo = {}\n\ndef ask(x)\n return -1 if x.gcd($n) != 1\n return -1 if x < 0 || x >= $n\n return $memo[x] if $memo.include?(x)\n puts \"sqrt #{x}\"\n ans = gets.to_i\n $memo[x] = ans\n ans\nend\n\ndef go(n)\n if n.to_bn.prime?\n $sol << n\n return\n end\n\n if n < 1000000\n $sol += n.prime_division.map(&:first)\n return\n end\n\n loop do\n a = rand(2..n-1)\n g = n.gcd(a)\n if g != 1 && g != n\n go(g)\n go(n / g)\n break\n end\n a2 = a * a % n\n r = ask(a2)\n next if r == -1\n r %= n\n next unless r * r % n == a2\n next if r == a || r == n - a\n g = n.gcd(n + r - a)\n next if g == 1 || g == n\n go(g)\n go(n / g)\n break\n end\nend\n\nn = gets.to_i\n$n = n\ngo(n)\nputs \"! #{$sol.size} #{$sol.sort.join(' ')}\"\n"}, {"source_code": "require 'openssl'\nrequire 'prime'\n\n$stdout.sync = true\n$sol = []\n$memo = {}\n\ndef ask(x)\n return -1 if x.gcd($n) != 1\n return -1 if x < 0 || x >= $n\n return $memo[x] if $memo.include?(x)\n puts \"sqrt #{x}\"\n ans = gets.to_i\n $memo[x] = ans\n ans\nend\n\nn = gets.to_i\n$n = n\n\ndef chk(x)\n if x.to_bn.prime?\n $sol << x\n $sol.uniq!\n m = 1\n $sol.each{|t| m *= t}\n if m == $n\n puts \"! #{$sol.size} #{$sol.sort.join(' ')}\"\n exit\n end\n end\nend\n\nloop do\n a = rand(2..n-1)\n g = n.gcd(a)\n if g != 1 && g != n\n chk(g)\n chk(n / g)\n next\n end\n a2 = a * a % n\n r = ask(a2)\n next if r == -1\n r %= n\n next unless r * r % n == a2\n next if r == a || r == n - a\n g = n.gcd(n + r - a)\n next if g == 1 || g == n\n chk(g)\n chk(n / g)\nend\nputs \"! #{$sol.size} #{$sol.sort.join(' ')}\"\n"}, {"source_code": "require 'openssl'\nrequire 'prime'\n\n$stdout.sync = true\n$sol = []\n\ndef go(n)\n if n.to_bn.prime?\n $sol << n\n return\n end\n\n if n < 10000\n $sol += n.prime_division.map(&:first)\n return\n end\n\n loop do\n a = rand(2..n-1)\n a2 = a * a % n\n puts \"sqrt #{a2}\"\n r = gets.to_i\n next if r == -1 || r == a || r == n - a\n g = n.gcd(n + r - a)\n next if g == 1 || g == n\n go(g)\n go(n / g)\n break\n end\nend\n\nn = gets.to_i\ngo(n)\nputs \"! #{$sol.size} #{$sol.sort.join(' ')}\"\n"}, {"source_code": "require 'openssl'\nrequire 'prime'\n\n$stdout.sync = true\n$sol = []\n\ndef go(n)\n if n.to_bn.prime?\n $sol << n\n return\n end\n\n if n < 10000\n $sol += n.prime_division.map(&:first)\n return\n end\n\n loop do\n a = rand(2..n-1)\n a2 = a * a % n\n puts \"sqrt #{a2}\"\n r = gets.to_i\n next if r == -1 || r == a || r == n - a\n g = n.gcd(n + r - a)\n next if g == 1 || g == n\n go(g)\n go(n / g)\n break\n end\nend\n\nn = gets.to_i\ngo(n)\nputs \"! #{$sol.sort.join(' ')}\"\n"}], "src_uid": "166fbe42dd60317e85e699d9bed76957"} {"source_code": "t = gets.chomp.to_i\r\n\r\ndef count_em(string, substring)\r\n string.scan(/(?=#{substring})/).count\r\nend\r\n\r\nvars = Hash.new\r\n\r\n(1..t).each do\r\n n = gets.chomp.to_i\r\n (1..n).each do |j|\r\n inp = gets.chomp.split(\" \")\r\n if inp[1] == \":=\"\r\n l = inp[2].length\r\n vars[inp[0]] = {cnt: count_em(inp[2], \"haha\"),\r\n s: inp[2][0..2], end: inp[2][[l - 3, 0].max..l - 1]}\r\n else\r\n tmp = (vars[inp[2]][:end] + vars[inp[4]][:s])\r\n sum = vars[inp[2]][:cnt] + vars[inp[4]][:cnt]\r\n cont = count_em(tmp, \"haha\")\r\n l = tmp.length\r\n s = vars[inp[2]][:s]\r\n if s.length < 3 then s = (s + vars[inp[4]][:s])[0..2] end\r\n endd = vars[inp[4]][:end]\r\n if endd.length < 3\r\n endd = vars[inp[2]][:end] + endd\r\n l = endd.length\r\n endd = endd[[l - 3, 0].max..l - 1]\r\n end\r\n vars[inp[0]] = {cnt: sum + cont,\r\n s: s,\r\n end: endd}\r\n end\r\n puts vars[inp[0]][:cnt] if j == n\r\n end\r\nend", "positive_code": [{"source_code": "def o (s)\n (0..(s.size - 1)).map {|i| s[i..i+3]}.select {|a| a == \"haha\"}.size\nend\n\ndef add (s)\n [s, o(s)]\nend\n\ndef m (s, t)\n x = s + t\n x = s[0..2] + 'x' + t.reverse[0..2].reverse if x.size > 6\n x\nend\n\ndef cs (s, t)\n s.reverse[0..2].reverse + t[0..2]\nend\n\ndef c (s, t)\n [m(s[0], t[0]), s[1] + t[1] + o(cs(s[0], t[0]))]\nend\n\ndef solve (n, a)\n h = Hash.new\n last = []\n a.each {|s| last = h[s[0]] = (s[1] == ':=' ? add(s[2]) : c(h[s[2]], h[s[4]]))}\n last[1]\nend\n\n(1..(gets.to_i)).each { puts solve(n = gets.to_i, (1..n).map {|i| gets.split(' ')})}\n"}, {"source_code": "def get_occ (s)\r\n (0..(s.size - 1)).map {|i| s[i..i+3]}.select {|a| a == \"haha\"}.size\r\nend\r\n\r\ndef add (s)\r\n [s, get_occ(s)]\r\nend\r\n\r\ndef merge_chars (s, t)\r\n x = s + t\r\n x = s[0..2] + 'x' + t[(t.size - [t.size, 3].min)..(t.size - 1)] if x.size >= 7\r\n x\r\nend\r\n\r\ndef concat_sub_strings (s, t)\r\n s[(s.size - [s.size, 3].min)..(s.size - 1)] + t[0..2]\r\nend\r\n\r\ndef concat (s, t)\r\n [merge_chars(s[0], t[0]), s[1] + t[1] + get_occ(concat_sub_strings(s[0], t[0]))]\r\nend\r\n\r\ndef solve (n, a)\r\n mp = Hash.new\r\n last = []\r\n a.each {|s| last = mp[s[0]] = (s[1] == ':=' ? add(s[2]) : concat(mp[s[2]], mp[s[4]]))}\r\n last[1]\r\nend\r\n\r\nt = gets.to_i\r\n\r\n(1..t).each do\r\n n = gets.to_i\r\n a = (1..n).map {|i| gets.split(' ')}\r\n puts solve(n, a)\r\nend\r\n"}], "negative_code": [{"source_code": "def get_occ (s)\n (0..(s.size - 1)).map {|i| s[i..i+3]}.select {|a| a ==\"haha\"}.size\nend\n\ndef add (s)\n [s, get_occ(s)]\nend\n\ndef merge_chars (s, t)\n x = s + t\n x = s[0..2] + 'x' + t[(t.size - [t.size, 3].min)..(t.size - 1)] if x.size > 6\n x\nend\n\ndef concat (s, t)\n [merge_chars(s[0], t[0]), s[1] + t[1] + [1, get_occ(s[0] + t[0])].min]\nend\n\ndef solve (n, a)\n mp = Hash.new\n last = []\n a.each {|s| last = mp[s[0]] = (s[1] == ':=' ? add(s[2]):concat(mp[s[2]], mp[s[4]]))}\n last[1]\nend\n\nt = gets.to_i\n\n(1..t).each do\n n = gets.to_i\n a = (1..n).map {|i| gets.split(' ')}\n puts solve(n, a)\nend\n\n"}, {"source_code": "def get_occ (s)\n result = 0\n (0..(s.size - 1)).each do |i|\n a = s[i..i+3]\n result += 1 if a ==\"haha\"\n end\n result\nend\n\n\ndef add (s)\n [s, get_occ(s), s]\nend\n\ndef merge_chars (s, t)\n x = s + t\n x = s[0..3] + 'x' + t[(t.size - [t.size, 3].min)..(t.size - 1)] if x.size > 6\n [x, x]\nend\n\ndef concat (s, t)\n pref, suff = merge_chars(s[0], t[-1])\n [pref, s[1] + t[1] + get_occ(s[-1] + t[0]), suff]\nend\n\ndef solve (n, a)\n mp = Hash.new\n last = []\n a.each do |s|\n if s[1] == ':='\n mp[s[0]] = add(s[2])\n else\n mp[s[0]] = concat(mp[s[2]], mp[s[4]])\n end\n last = mp[s[0]]\n end\n last[1] + 1\nend\n\nt = gets.to_i\n\n(1..t).each do\n n = gets.to_i\n a = (1..n).map{|i| gets.split(' ')}\n puts solve(n, a) >> 1\n\nend\n"}], "src_uid": "356bd72aa9143681f1efd695969a8c8e"} {"source_code": "N, M = gets.split.map(&:to_i)\nmin, max = 0, 0\nN.times do |i|\n min += (i-N/2).abs\n max += i\nend\n\nans = 0\nM.times do\n x, d = gets.split.map(&:to_i)\n ans += N * x + d * (d>0 ? max : min)\nend\nputs ans.to_f/N", "positive_code": [{"source_code": "n, m = gets.strip.split.map(&:to_i)\naps = []\nm.times do\n aps << gets.strip.split.map(&:to_i)\nend\n\nps=0\npo=0\naps.each do |ap|\n if ap[1]>=0\n po += ap[0]\n ps += ap[1]\n end\nend\n\nsum = 0\nsum += (po * n)\nsum += (ps * ((n*(n-1))/2))\n\nns=0\nno=0\naps.each do |ap|\n if ap[1]<0\n no += ap[0]\n ns += ap[1]\n end\nend\n\nsum += (no * n)\nif n%2==0\n an = n/2\n sum += (ns * ((an*(an+1))/2))\n sum += (ns * ((an*(an-1))/2))\nelse\n an = n/2\n sum += (ns * ((an*(an+1))/2))\n sum += (ns * ((an*(an+1))/2))\nend\n\nputs (1.0*sum)/(1.0*n)"}], "negative_code": [], "src_uid": "1c8423407ea7a0b2647e41392670d6b7"} {"source_code": "gets.to_i.times.each do\r\n w0, h0 = gets.split.map(&:to_i)\r\n x1, y1, x2, y2 = gets.split.map(&:to_i)\r\n w, h = gets.split.map(&:to_i)\r\n dw = [w - [x1, w0 - x2].max, 0].max\r\n dh = [h - [y1, h0 - y2].max, 0].max\r\n nw = w0 < x2 - x1 + w\r\n nh = h0 < y2 - y1 + h\r\n puts case\r\n when nw && nh then -1\r\n when nw then dh\r\n when nh then dw\r\n else [dw, dh].min\r\n end\r\nend", "positive_code": [{"source_code": "MOD = 10 ** 9 + 7\r\ndef gs; gets.chomp; end\r\ndef gi; gets.to_i; end\r\ndef gli; gets.split.map(&:to_i); end\r\ndef cyesno(x); puts x ? :Yes : :No; end\r\ndef uyesno(x); puts x ? :YES : :NO; end\r\ndef array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end\r\n\r\ndef solve\r\n w, h = gli\r\n x1, y1, x2, y2 = gli\r\n wq, hq = gli\r\n w1 = x2 - x1\r\n h1 = y2 - y1\r\n if w1 + wq > w && h1 + hq > h\r\n puts (-1) ** 1\r\n else\r\n d = []\r\n d << [wq - x1, 0].max if w1 + wq <= w\r\n d << [hq - y1, 0].max if h1 + hq <= h\r\n d << [y2 - (h - hq), 0].max if h1 + hq <= h\r\n d << [x2 - (w - wq), 0].max if w1 + wq <= w\r\n puts d.min\r\n end\r\nend\r\n\r\ndef main\r\n gi.times { solve }\r\nend\r\n\r\nmain\r\n"}], "negative_code": [{"source_code": "gets.to_i.times.each do\r\n w0, h0 = gets.split.map(&:to_i)\r\n x1, y1, x2, y2 = gets.split.map(&:to_i)\r\n w, h = gets.split.map(&:to_i)\r\n dw = w - [x1, w0 - x2].max\r\n dh = h - [y1, h0 - y2].max\r\n nw = w0 < x2 - x1 + w\r\n nh = h0 < y2 - y1 + h\r\n puts case\r\n when nw && nh then -1\r\n when nw then dh\r\n when nh then dw\r\n else [dh, dw].min\r\n end\r\nend"}], "src_uid": "29fd4c77a2f28478ebce98dfc6496aac"} {"source_code": "n = gets\nn = n.to_i\n\nwhile n > 0 do\n a = gets\n a = a.split\n a[0] = a[0].to_f\n a[1] = a[1].to_f\n\n area1 = a[0] * a[1]\n #puts area1\n\n b = gets\n b = b.split\n\n b[0] = b[0].to_f\n b[1] = b[1].to_f\n\n area2 = b[0] * b[1]\n \n area_total = area1 + area2\n\n\n if a[0] + b[0] == a[1] and a[0] + b[0] == b[1]\n puts \"Yes\"\n elsif a[0] + b[1] == a[1] and a[0] + b[1] == b[0]\n puts \"Yes\"\n elsif a[1] + b[0] == a[0] and a[1] + b[0] == b[1]\n puts \"Yes\"\n elsif a[1] + b[1] == a[0] and a[1] + b[1] == b[0]\n puts \"Yes\"\n else\n puts \"No\"\n end\n n = n - 1\nend", "positive_code": [{"source_code": "gets.to_i.times do\n a = gets.split.map(&:to_i).sort\n b = gets.split.map(&:to_i).sort\n puts a[0] + b[0] == a[1] && a[1] == b[1] ? :Yes : :No\nend"}, {"source_code": "t = gets.to_i\nt.times do\n\ta, b = gets.split.map(&:to_i)\n\tc, d = gets.split.map(&:to_i)\n\tif (a == d && a == b + c) || (b == c && b == a + d) || (a == c && a == b + d) || (b == d && b == a + c)\n\t\tputs \"Yes\"\n\telse\n\t\tputs \"No\"\n\tend\nend"}, {"source_code": "i = gets.chomp.to_i\n\ndef isCube(b, c, d, e)\n if b + d == c && b + d == e\n return 1\n end\n\n if b + e == c && b + e == d\n return 1\n end\n\n if c + d == b && c + d == e\n return 1\n end\n\n if c + e == b && c + e == d\n return 1\n end\n\n return 0\nend\n\nwhile (i > 0)\n a1, a2 = gets.split.map(&:to_i)\n b1, b2 = gets.split.map(&:to_i)\n\n if isCube(a1, a2, b1, b2) == 1\n puts 'Yes'\n else\n puts 'No'\n end\n\n i -= 1\nend"}, {"source_code": "1.upto(gets.chomp.to_i) do\n\n a,b = gets.chomp.split.map(&:to_i)\n c,d = gets.chomp.split.map(&:to_i)\n\n if ([a,b].max == [c,d].max) && ([a,b].min + [c,d].min == [a,b].max)\n puts 'Yes'\n else\n puts 'No'\n end\n\nend\n"}, {"source_code": "n = gets.to_i\nfor i in 1..n\n a1, b1 = gets.chomp.split(' ').map(&:to_i)\n a2, b2 = gets.chomp.split(' ').map(&:to_i)\n f0 = ((a1 + a2) == b1) && (a1 + a2) == b2\n f1 = ((a1 + b2) == b1) && (a1 + b2) == a2\n f2 = ((b1 + a2) == a1) && (b1 + a2) == b2\n f3 = ((b1 + b2) == a1) && (b1 + b2) == a2\n f = f0 || f1 || f2 || f3\n if f\n puts \"Yes\"\n else\n puts \"No\"\n end\nend"}, {"source_code": "t = gets.chomp.to_i\nwhile t > 0\n r1 = gets.chomp.split(' ').map { |x| x.to_i }.sort\n r2 = gets.chomp.split(' ').map { |x| x.to_i }.sort\n\n if r1.last != r2.last\n puts 'No'\n elsif r1.last == r1.first + r2.first\n puts 'Yes'\n else\n puts 'No'\n end\n\n t -= 1\nend\n"}], "negative_code": [{"source_code": "n = gets\nn = n.to_i\n\nwhile n > 0 do\n a = gets\n a = a.split\n a[0] = a[0].to_f\n a[1] = a[1].to_f\n\n area1 = a[0] * a[1]\n #puts area1\n\n b = gets\n b = b.split\n\n b[0] = b[0].to_f\n b[1] = b[1].to_f\n\n if a[0] + b[0] == a[1]\n puts \"yes\"\n elsif a[0] + b[1] == a[1]\n puts \"yes\"\n elsif a[1] + b[0] == a[0]\n puts \"yes\"\n elsif a[1] + b[1] == a[0]\n puts \"yes\"\n else\n puts \"no\"\n end\n n = n - 1\nend"}, {"source_code": "n = gets\nn = n.to_i\n\nwhile n > 0 do\n a = gets\n a = a.split\n a[0] = a[0].to_f\n a[1] = a[1].to_f\n\n area1 = a[0] * a[1]\n #puts area1\n\n b = gets\n b = b.split\n\n b[0] = b[0].to_f\n b[1] = b[1].to_f\n\n area2 = b[0] * b[1]\n \n area_total = area1 + area2\n\n\n if a[0] + b[0] == a[1] and a[0] + b[0] == b[1]\n puts \"Yes\"\n elsif a[0] + b[1] == a[1] and a[0] + b[1] == b[1]\n puts \"Yes\"\n elsif a[1] + b[0] == a[0] and a[1] + b[0] == b[0]\n puts \"Yes\"\n elsif a[1] + b[1] == a[0] and a[1] + b[1] == b[0]\n puts \"Yes\"\n else\n puts \"No\"\n end\n n = n - 1\nend"}, {"source_code": "n = gets\nn = n.to_i\n\nwhile n > 0 do\n a = gets\n a = a.split\n a[0] = a[0].to_f\n a[1] = a[1].to_f\n\n area1 = a[0] * a[1]\n #puts area1\n\n b = gets\n b = b.split\n\n b[0] = b[0].to_f\n b[1] = b[1].to_f\n\n if a[0] + b[0] == a[1]\n puts \"Yes\"\n elsif a[0] + b[1] == a[1]\n puts \"Yes\"\n elsif a[1] + b[0] == a[0]\n puts \"Yes\"\n elsif a[1] + b[1] == a[0]\n puts \"Yes\"\n else\n puts \"No\"\n end\n n = n - 1\nend"}, {"source_code": "n = gets\nn = n.to_i\n\nwhile n > 0 do\n a = gets\n a = a.split\n a[0] = a[0].to_f\n a[1] = a[1].to_f\n\n area1 = a[0] * a[1]\n\n b = gets\n b = b.split\n\n b[0] = b[0].to_f\n b[1] = b[1].to_f\n\n area2 = b[0] * b[1]\n\n area_total = area1 + area2\n\n if Math.sqrt(area_total) % 1 == 0\n if ( a[0] + b[0] != a[1] + b[1] ) or ( a[0] + b[1] != a[1] + b[0] )\n puts \"no\"\n break\n end\n puts \"yes\"\n else\n puts \"no\"\n end\n n = n - 1\nend"}, {"source_code": "n = gets\nn = n.to_i\n\nwhile n > 0 do\n a = gets\n a = a.split\n a[0] = a[0].to_f\n a[1] = a[1].to_f\n\n area1 = a[0] * a[1]\n #puts area1\n\n b = gets\n b = b.split\n\n b[0] = b[0].to_f\n b[1] = b[1].to_f\n\n area2 = b[0] * b[1]\n\n area_total = area1 + area2\n\n if Math.sqrt(area_total) % 1 == 0\n if (( a[0] + b[0] != a[1] + b[1] ) and ( a[0] + b[1] != a[1] + b[0] )) and Math.sqrt(area_total) % 2 == 0\n puts \"no\"\n else\n puts \"yes\"\n end\n\n else\n puts \"no\"\n end\n n = n - 1\nend"}, {"source_code": "n = gets\nn = n.to_i\n\nwhile n > 0 do\n a = gets\n a = a.split\n a[0] = a[0].to_f\n a[1] = a[1].to_f\n\n area1 = a[0] * a[1]\n #puts area1\n\n b = gets\n b = b.split\n\n b[0] = b[0].to_f\n b[1] = b[1].to_f\n\n area2 = b[0] * b[1]\n\n area_total = area1 + area2\n\n if Math.sqrt(area_total) % 1 == 0\n if ( a[0] + b[0] != a[1] + b[1] ) or ( a[0] + b[1] != a[1] + b[0] )\n puts \"no\"\n break\n end\n puts \"yes\"\n else\n puts \"no\"\n end\n n = n - 1\nend"}, {"source_code": "n = gets\nn = n.to_i\n\nwhile n > 0 do\n a = gets\n a = a.split\n a[0] = a[0].to_f\n a[1] = a[1].to_f\n\n area1 = a[0] * a[1]\n #puts area1\n\n b = gets\n b = b.split\n\n b[0] = b[0].to_f\n b[1] = b[1].to_f\n\n area2 = b[0] * b[1]\n\n area_total = area1 + area2\n\n if Math.sqrt(area_total) % 1 == 0\n if ( a[0] + b[0] != a[1] + b[1] ) or ( a[0] + b[1] != a[1] + b[0] )\n puts \"no\"\n else\n puts \"yes\"\n end\n\n else\n puts \"no\"\n end\n n = n - 1\nend"}, {"source_code": "n = gets\nn = n.to_i\n\nwhile n > 0 do\n a = gets\n a = a.split\n a[0] = a[0].to_f\n a[1] = a[1].to_f\n\n area1 = a[0] * a[1]\n #puts area1\n\n b = gets\n b = b.split\n\n b[0] = b[0].to_f\n b[1] = b[1].to_f\n\n area2 = b[0] * b[1]\n\n area_total = area1 + area2\n\n if Math.sqrt(area_total) % 1 == 0\n puts \"yes\"\n else\n puts \"no\"\n end\n n = n - 1\nend"}, {"source_code": "n = gets\nn = n.to_i\n\nwhile n > 0 do\n a = gets\n a = a.split\n a[0] = a[0].to_f\n a[1] = a[1].to_f\n\n area1 = a[0] * a[1]\n #puts area1\n\n b = gets\n b = b.split\n\n b[0] = b[0].to_f\n b[1] = b[1].to_f\n\n area2 = b[0] * b[1]\n\n area_total = area1 + area2\n\n if Math.sqrt(area_total) % 1 == 0\n if (( a[0] + b[0] != a[1] + b[1] ) or ( a[0] + b[1] != a[1] + b[0] )) and Math.sqrt(area_total) % 2 == 0\n puts \"no\"\n else\n puts \"yes\"\n end\n\n else\n puts \"no\"\n end\n n = n - 1\nend"}, {"source_code": "t = gets.to_i\nt.times do\n\ta, b = gets.split.map(&:to_i)\n\tc, d = gets.split.map(&:to_i)\n\tif (a == d && a == b + c) || (b == c && b == a + d)\n\t\tputs \"Yes\"\n\telse\n\t\tputs \"No\"\n\tend\nend"}, {"source_code": "t = gets.to_i\nt.times do\n\ta, b = gets.split.map(&:to_i)\n\tc, d = gets.split.map(&:to_i)\n\tif (a == d && a == b + c) || (b == c && b == a + d) || (a == c && a == b + d)\n\t\tputs \"Yes\"\n\telse\n\t\tputs \"No\"\n\tend\nend"}, {"source_code": "n = gets.to_i\nfor i in 1..n\n a1, b1 = gets.chomp.split(' ').map(&:to_i)\n a2, b2 = gets.chomp.split(' ').map(&:to_i)\n if a1 == a2\n if b1 + b2 == a1\n puts \"YES\"\n else\n puts \"NO\"\n end\n elsif a1 == b2\n if b1 + a2 == a1\n puts \"YES\"\n else\n puts \"NO\"\n end\n elsif a2 == b1\n if a1 + b2 == a2\n puts \"YES\"\n else\n puts \"NO\"\n end\n elsif b1 == b2\n if a1 + a2 == b2\n puts \"YES\"\n else\n puts \"NO\"\n end\n else\n puts \"NO\"\n end\nend"}], "src_uid": "a375dd323b7adbfa9f1cad9aa48f7247"} {"source_code": "def is_white?(x, y)\n (x + y)%2 == 0\nend\n\ndef is_black?(x, y)\n (x + y)%2 != 0\nend\n\ndef white(x1, y1, x2, y2)\n return 0 if x2 < x1 || y2 < y1\n o = 1 + (x2 - x1)/2\n e = (x2 - x1 + 1)/2\n no = 1 + (y2 - y1)/2\n ne = (y2 - y1 + 1)/2\n\n if is_white?(x1, y1)\n no*o + ne*e\n else\n ne*o + no*e\n end\nend\n\ndef black(x1, y1, x2, y2)\n return 0 if x2 < x1 || y2 < y1\n o = 1 + (x2 - x1)/2\n e = (x2 - x1 + 1)/2\n no = 1 + (y2 - y1)/2\n ne = (y2 - y1 + 1)/2\n\n if is_black?(x1, y1)\n no*o + ne*e\n else\n ne*o + no*e\n end \nend\n\ndef intersect(x1, y1, x2, y2, x3, y3, x4, y4)\n f, s = [x1, y1, x2, y2], [x3, y3, x4, y4]\n f, s = s, f if x3 < x1\n return nil if s[1] > f[3] || s[0] > f[2] || s[3] < f[1]\n xi1, yi1 = [f[2], s[0]].min, [f[1], s[1]].max\n xi2, yi2 = [s[2], f[2]].min, [s[3], f[3]].min\n [xi1, yi1, xi2, yi2]\nend\n\nt = gets.to_i\nt.times do\n n, m = gets.split.map{|x| x.to_i}\n x1, y1, x2, y2 = gets.split.map{|x| x.to_i}\n x3, y3, x4, y4 = gets.split.map{|x| x.to_i}\n nwhite = white(1, 1, m, n)\n nblack = black(1, 1, m, n)\n #p [nwhite, nblack]\n nwhite += black(x1, y1, x2, y2)\n nblack -= black(x1, y1, x2, y2)\n #p [nwhite, nblack]\n inter = intersect(x1, y1, x2, y2, x3, y3, x4, y4)\n #p inter\n if inter\n ab = black(inter[0], inter[1], inter[2], inter[3])\n else\n ab = 0\n end\n nwhite -= white(x3, y3, x4, y4) + ab\n nblack += white(x3, y3, x4, y4) + ab\n puts nwhite.to_s + ' ' + nblack.to_s\nend\n", "positive_code": [{"source_code": "t = gets.to_i\n\n\ndef colorsin(a,b,n,m)\n\n squares = (n-a+1)*(m-b+1)\n if (a+b)%2 == 0 #bottom left square is white (more whites)\n black = squares/2\n white = squares-black\n else\n white = squares/2\n black = squares-white\n end\n\n return [white,black]\nend\n\n\nt.times do\n nm = gets.chomp.split(\" \").map(&:to_i)\n rec1 = gets.chomp.split(\" \").map(&:to_i)\n rec2 = gets.chomp.split(\" \").map(&:to_i)\n\n n = nm[0]\n m = nm[1]\n\n x1 = rec1[0]\n y1 = rec1[1]\n x2 = rec1[2]\n y2 = rec1[3]\n\n x3 = rec2[0]\n y3 = rec2[1]\n x4 = rec2[2]\n y4 = rec2[3]\n\n squares = n*m\n blacks = (squares)/2\n whites = squares-blacks\n\n\n overlap = true\n if (x3>x2 || x4y2 || y4= 0 && a[i-1] != max) || (i+1 < n && a[i+1] != max)\n index = i+1\n end\n end\n end\n ans << index\nend\nputs ans", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n m = a.max\n\n ans = -1\n\n n.times do |i|\n next if a[i] != m\n\n if i - 1 >= 0 && a[i - 1] < m\n ans = i + 1\n end\n\n if i + 1 < n && a[i + 1] < m\n ans = i + 1\n end\n end\n\n puts ans\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n max = 0\n arr = []\n count = 0\n a.each_with_index do |i,j|\n max = [max,i].max\n if n >= 3\n if i >= max && j >= 1 && j <= n - 2\n if i != a[j-1] || i != a[j+1]\n arr << j\n end\n elsif i >= max && j == 0\n # p i\n # puts \"I\"\n if i != a[j+1]\n # p i\n # p j\n # puts \"Iiiii\"\n arr << j\n end\n elsif i >= max && j == n - 1\n if i != a[j-1]\n arr << j\n end\n #max = [max,i].max\n #arr << j\n #count += 1\n end\n end\n # puts \"OOOOO\"\n # p max\n # puts \"IIIIIIIII\"\n end\n if n == 2\n big = a.max\n a.each_with_index do |i,j|\n if i == big\n arr << j\n end\n end\n end\n a = a.map(&:to_s)\n a = a.uniq\n if a.size == 1\n puts \"-1\"\n else\n ans = arr.pop + 1\n puts ans\n end\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n v = gets.split.map(&:to_i)\n max = v.max\n r = (0...n).find do |i|\n v[i] == max && ((i > 0 && v[i] > v[i-1]) || (i+1 < n && v[i] > v[i+1]))\n end\n puts r.nil? ? -1 : r+1\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n v = gets.split.map(&:to_i)\n max = v.max\n r = (0...n).find { |i| v[i] == max && ((i > 0 && v[i] > v[i - 1]) || (i + 1 < n && v[i] > v[i + 1])) }\n puts r.nil? ? -1 : r + 1\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n ma = a.max\n next puts(-1) if a.count(ma) == a.length\n puts (n.times do |i|\n break i + 1 if i > 0 and a[i] == ma and a[i] > a[i - 1]\n break i + 1 if a[i] == ma and a[i] > a[i + 1]\n end\n )\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n ma = a.max\n if a.count(ma) == a.length\n puts(-1)\n else \n puts (n.times do |i|\n break i + 1 if i > 0 and a[i] == ma and a[i] > a[i - 1]\n break i + 1 if a[i] == ma and a[i] > a[i + 1]\n end\n )\n end\nend\n"}, {"source_code": "t=gets.to_i\nt.times do \n n=gets.to_i\n if n==1\n p 1\n next\n end\n an=gets.chomp.split(' ').map(&:to_i)\n maxi = an.max\n flag = false\n catch(:break_loop) do\n n.times do |i|\n if an[i]==maxi && (i!=0 && an[i-1] 1\r\n q << i\r\n d[i] = 1\r\n end\r\n q.each { |v| nbrs[v].delete(v) }\r\n\r\n while (v = q.shift)\r\n dv = d[v]\r\n nbrs[v].each do |u|\r\n nbrs[u].delete(v)\r\n next if nbrs[u].size > 1\r\n next if d[u]\r\n d[u] = dv + 1\r\n q << u\r\n end\r\n end\r\n\r\n d[0] = 0\r\n d\r\nend\r\n\r\ngets.to_i.times do\r\n\r\ngets # empty line\r\nn, k = gets.split.map!(&:to_i)\r\nnbrs = Array.new(n + 1) { Set.new }\r\nn.pred.times do\r\n u, v = gets.split.map!(&:to_i)\r\n nbrs[u] << v\r\n nbrs[v] << u\r\nend\r\n\r\nd = f(nbrs)\r\nputs d.count { |di| di > k }\r\n\r\nend\r\n", "positive_code": [{"source_code": "require 'set'\n \ndef f(a)\n d = Array.new(a.size)\n q = []\n a.each_with_index do |j, i|\n next if j.size > 1\n q << i\n d[i] = 1\n end\n q.each { |v| a[v].delete(v) }\n while (v = q.shift)\n dv = d[v]\n a[v].each do |u|\n a[u].delete(v)\n next if a[u].size > 1\n next if d[u]\n d[u] = dv + 1\n q << u\n end\n end\n d[0] = 0\n d\nend\n \ngets.to_i.times do\n gets\n n, k = gets.split.map!(&:to_i)\n a = Array.new(n + 1) { Set.new }\n n.pred.times do\n u, v = gets.split.map!(&:to_i)\n a[u] << v\n a[v] << u\n end \n d = f(a)\n puts d.count { |di| di > k }\nend"}], "negative_code": [{"source_code": "require 'set'\r\n\r\ndef f(nbrs)\r\n d = Array.new(nbrs.size)\r\n\r\n q = []\r\n nbrs.each_with_index do |nbr, i|\r\n next if nbr.size > 1\r\n q << i\r\n d[i] = 1\r\n end\r\n q.each { |v| nbrs[v].delete(v) }\r\n\r\n while (v = q.shift)\r\n dv = d[v]\r\n nbrs[v].each do |u|\r\n nbrs[u].delete(v)\r\n next if nbrs[u].size > 1\r\n d[u] = dv + 1\r\n q << u\r\n end\r\n end\r\n\r\n d[0] = 0\r\n d\r\nend\r\n\r\ngets.to_i.times do\r\n\r\ngets # empty line\r\nn, k = gets.split.map!(&:to_i)\r\nnbrs = Array.new(n + 1) { Set.new }\r\nn.pred.times do\r\n u, v = gets.split.map!(&:to_i)\r\n nbrs[u] << v\r\n nbrs[v] << u\r\nend\r\n\r\nd = f(nbrs)\r\nputs d.count { |di| di > k }\r\n\r\nend\r\n"}], "src_uid": "07ac198c1086323517540ecd0669eb4c"} {"source_code": "def min(x, lim)\n (lim..\"2011\").each do |s|\n d = 0\n for i in 0..3\n d += (s[i] == x[i]) ? 0 : 1\n end\n next if d > 1\n\n return s\n end\n\n return false\nend\n\nlim = \"1000\"\no = []\ngets.to_i.times do \n s = gets.chomp\n r = min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\nputs o\n", "positive_code": [{"source_code": "def min(x, lim)\n (lim..\"2011\").each do |s|\n d = 0\n for i in 0..3\n d += (s[i] == x[i]) ? 0 : 1\n end\n next if d > 1\n\n return s\n end\n\n return false\nend\n\nlim = \"1000\"\no = []\ngets.to_i.times do \n s = gets.chomp\n r = min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\nputs o\n"}, {"source_code": "def min(x, lim)\n (lim..\"2011\").each do |s|\n d = 0\n for i in 0..3\n d += (s[i] == x[i]) ? 0 : 1\n end\n next if d > 1\n\n return s\n end\n\n return false\nend\n\nlim = \"1000\"\no = []\ngets.to_i.times do \n s = gets.chomp\n r = min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\nputs o\n"}, {"source_code": "def min(x, lim)\n (lim..\"2011\").each do |s|\n d = 0\n for i in 0..3\n d += (s[i] == x[i]) ? 0 : 1\n end\n next if d > 1\n\n return s\n end\n\n return false\nend\n\nlim = \"1000\"\no = []\ngets.to_i.times do \n s = gets.chomp\n r = min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\nputs o"}, {"source_code": "def min(x, lim)\n (lim..\"2011\").each do |s|\n d = 0\n for i in 0..3\n d += (s[i] == x[i]) ? 0 : 1\n end\n next if d > 1\n\n return s\n end\n\n return false\nend\n\nlim = \"1000\"\no = []\ngets.to_i.times do \n s = gets.chomp\n r = min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\nputs o\n"}, {"source_code": "def min(x, lim)\n (lim..\"2011\").each do |s|\n d = 0\n for i in 0..3\n d += (s[i] == x[i]) ? 0 : 1\n end\n next if d > 1\n\n return s\n end\n\n return false\nend\n\nlim = \"1000\"\no = []\ngets.to_i.times do \n s = gets.chomp\n r = min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\nputs o\n"}, {"source_code": "def min(x, lim)\n (lim..\"2011\").each do |s|\n d = 0\n for i in 0..3\n d += (s[i] == x[i]) ? 0 : 1\n end\n next if d > 1\n\n return s\n end\n\n return false\nend\n\nlim = \"1000\"\no = []\ngets.to_i.times do \n s = gets.chomp\n r = min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\nputs o"}, {"source_code": "N = gets.to_i\nyears = []\nans = []\n\nN.times {\n tmp = []\n year = gets.chomp\n 0.upto(3) { |i|\n 0.upto(9) {|j|\n changed = year.dup\n changed[i, 1] = j.to_s\n changed = changed.to_i\n if (changed >= 1000 && changed <= 2011)\n tmp.push changed\n end\n }\n }\n tmp.sort!\n years.push tmp\n}\n\nfailed = false\nans.push years[0][0]\n\n1.upto(N - 1) {|i|\n ans[i] = -1\n years[i].each {|e|\n if (e >= ans[i - 1]) \n ans[i] = e\n break\n end\n }\n if (ans[i] == -1)\n puts \"No solution\"\n exit\n end\n}\n\nans.each {|e| puts e}\n"}, {"source_code": "def min(x, lim)\n (lim..\"2011\").each do |s|\n d = 0\n for i in 0..3\n d += (s[i] == x[i]) ? 0 : 1\n end\n next if d > 1\n\n return s\n end\n\n return false\nend\n\nlim = \"1000\"\no = []\ngets.to_i.times do \n s = gets.chomp\n r = min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\nputs o"}, {"source_code": "def min(x, lim)\n (lim..\"2011\").each do |s|\n d = 0\n for i in 0..3\n d += (s[i] == x[i]) ? 0 : 1\n end\n next if d > 1\n\n return s\n end\n\n return false\nend\n\nlim = \"1000\"\no = []\ngets.to_i.times do \n s = gets.chomp\n r = min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\nputs o\n"}, {"source_code": "def find_min(x, lim)\n return false if lim > \"2011\"\n\n (lim..\"2011\").each do |s|\n sum = (s[0] == x[0]) ? 0 : 1\n sum += (s[1] == x[1]) ? 0 : 1\n next if sum > 1\n sum += (s[2] == x[2]) ? 0 : 1\n next if sum > 1\n sum += (s[3] == x[3]) ? 0 : 1\n next if sum > 1\n\n return s\n end\n\n return false\nend\n\nn = gets.to_i\nlim = \"1000\"\no = []\nn.times do \n s = gets.chomp\n r = find_min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\n\nputs o\n"}, {"source_code": "def min(x, lim)\n (lim..\"2011\").each do |s|\n d = 0\n for i in 0..3\n d += (s[i] == x[i]) ? 0 : 1\n end\n next if d > 1\n\n return s\n end\n\n return false\nend\n\nlim = \"1000\"\no = []\ngets.to_i.times do \n s = gets.chomp\n r = min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\nputs o\n"}, {"source_code": "def min(x, lim)\n (lim..\"2011\").each do |s|\n d = 0\n for i in 0..3\n d += (s[i] == x[i]) ? 0 : 1\n end\n next if d > 1\n\n return s\n end\n\n return false\nend\n\nlim = \"1000\"\no = []\ngets.to_i.times do \n s = gets.chomp\n r = min(s, lim)\n unless r\n puts \"No solution\"\n exit\n end\n o << r\n lim = r\nend\nputs o\n"}], "negative_code": [], "src_uid": "c175d010d75c391d0b25391fecff007c"} {"source_code": "n = Integer(gets.chomp)\na = []\na = gets.chomp.split.map &:to_i\nb = []\nb = gets.chomp.split.map &:to_i\n\nx = Array.new(n) { |i| i + 1}\nposition = 0\nposition_other = 0\nfor i in 0...n\n if x.include?(a[i])\n x.delete(a[i])\n else\n position = i\n end\nend\nleft = x[0]\n\n\nfor i in 0...n\n if a[i] == a[position]\n position_other = i\n break\n end\nend\noutput1 = []\noutput1.replace(a)\noutput1[position_other] = left \noutput2 = []\noutput2.replace(a)\noutput2[position] = left\ncount = 0\nfor i in 0...n\n if b[i] != output1[i]\n count += 1\n end\nend\nif count == 1\n print output1.join(\" \")\nelse\n print output2.join(\" \")\nend", "positive_code": [{"source_code": "n = gets.chomp.to_i\n\nax = ay = missing = -1\na = gets.chomp.split.map &:to_i\nfor i in 0...n\n for j in 0...i\n if a[i] == a[j]\n ax = i\n ay = j\n end\n end\nend\nfor i in 1..n\n has = false\n for j in 0...n\n if a[j] == i\n has = true\n end\n end\n if !has\n missing = i\n end\nend\n\nb = gets.chomp.split.map &:to_i\n\nif a[ax] == b[ax] || b[ay] == missing\n a[ay] = missing\nelse \n a[ax] = missing\nend\nputs a.join \" \""}, {"source_code": "def ok(a, b, p)\n n = p.length\n x = 0\n y = 0\n for i in 0...n\n x += 1 if a[i] == p[i]\n y += 1 if b[i] == p[i]\n end\n return x == n - 1 && y == n - 1\nend\n\ndef solve(a, b)\n x = -1\n y = -1\n n = a.length\n\n mrk = Hash.new(0)\n\n p = []\n for i in 0...n\n if a[i] != b[i]\n if x == -1\n x = i\n p.push(-1)\n else\n y = i\n p.push(-1)\n end\n else\n mrk[a[i]] = 1\n p.push(a[i])\n end\n end\n\n if y == -1\n for i in 1..n\n if mrk[i] == 0\n p[x] = i\n end\n end\n\n return p\n end\n\n lst = []\n for i in 1..n\n if mrk[i] == 0\n lst.push(i)\n end\n end\n\n p[x] = lst[0]\n p[y] = lst[1]\n\n return p if ok(a, b, p)\n\n p[x] = lst[1]\n p[y] = lst[0]\n \n return p\nend\n\nn = gets.split.map(&:to_i)\n\nline = gets.chomp\na = line.split.map(&:to_i)\n\nline = gets.chomp\nb = line.split.map(&:to_i)\n\np = solve(a, b)\np.each { |x| print x.to_s + \" \" }\nputs\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\n\nax = ay = missing = -1\na = gets.chomp.split.map &:to_i\nfor i in 0...n\n for j in 0...i\n if a[i] == a[j]\n ax = i\n ay = j\n end\n end\nend\nfor i in 1..n\n has = false\n for j in 0...n\n if a[j] == i\n has = true\n end\n end\n if !has\n missing = i\n end\nend\n\nb = gets.chomp.split.map &:to_i\n\nif a[ax] == b[ax]\n a[ay] = missing\nelse \n a[ax] = missing\nend\nputs a.join \" \""}, {"source_code": "n = gets.chomp.to_i\n\nax = ay = missing = -1\na = gets.chomp.split.map &:to_i\nfor i in 0...n\n for j in 0...i\n if a[i] == a[j]\n ax = i\n ay = j\n end\n end\nend\nfor i in 1..n\n has = false\n for j in 0...n\n if a[j] == i\n has = true\n end\n end\n if !has\n missing = i\n end\nend\n\nbx = by = -1\nb = gets.chomp.split.map &:to_i\nfor i in 0...n\n for j in 0...i\n if b[i] == b[j]\n bx = i\n by = j\n end\n end\nend\n\nif ax == bx || ax == by\n a[ax] = missing\nelsif\n a[ay] = missing\nend\n\nputs a.join \" \""}, {"source_code": "n = Integer(gets.chomp)\na = []\na = gets.chomp.split.map &:to_i\nb = []\nb = gets.chomp.split.map &:to_i\n\nx = Array.new(n) { |i| i + 1}\nposition = 0\nposition_other = 0\nfor i in 0...n\n if x.include?(a[i])\n x.delete(a[i])\n else\n position = i\n end\nend\nleft = x[0]\n\n\nfor i in 0...n\n if a[i] == a[position]\n position_other = i\n break\n end\nend\noutput1 = []\noutput1.replace(a)\noutput1[position_other] = left \noutput2 = []\noutput2.replace(a)\noutput2[position] = left\ncount = 0\nfor i in 0...n\n if b[i] != output1[i]\n count += 1\n end\nend\nif count == 1\n print output1\nelse\n print output2\nend"}, {"source_code": "def solve(a, b)\n x = -1\n y = -1\n n = a.length\n\n mrk = Hash.new(0)\n\n p = []\n i = 0\n \n while i < n\n if a[i] != b[i]\n if x == -1\n x = i\n p.push(-1)\n else\n y = i\n p.push(-1)\n end\n else\n mrk[a[i]] = 1\n p.push(a[i])\n end\n i += 1\n end\n\n if y == -1\n for i in 1..n\n if mrk[i] == 0\n p[x] = i\n end\n end\n\n return p\n end\n\n for i in 1..n\n if mrk[i] == 0\n if (a[x] == i || b[x] == i) && x != -1\n p[x] = i\n x = -1\n else\n p[y] = i\n end\n end\n end\n \n return p\nend\n\nn = gets.split.map(&:to_i)\n\nline = gets.chomp\na = line.split.map(&:to_i)\n\nline = gets.chomp\nb = line.split.map(&:to_i)\n\np = solve(a, b)\np.each { |x| print x.to_s + \" \" }\nputs\n"}], "src_uid": "6fc3da19da8d9ab024cdd5acfc4f4164"} {"source_code": "len = gets.strip.to_i\nstr = gets.strip\n\ndiff = false\n\nlast_char = str[0]\nskip = true\nout = nil\nstr.each_char do |c|\n if skip\n skip = false\n next\n end\n if c != last_char\n out = last_char + c\n break\n end\nend\n\nif out.nil?\n puts \"NO\"\nelse\n puts \"YES\"\n puts out\nend\n", "positive_code": [{"source_code": "# http://codeforces.com/contest/1073/problem/A\n\nn = gets.chomp.to_i\ns = gets.chomp\n\nA_ORD = 'a'.ord\n\ndef solve(n, s)\n results = []\n\n s.each_char.each_with_index do |char, i|\n new_result = Array.new(26, 0)\n new_ord = char.ord - A_ORD\n new_result[new_ord] = 1\n\n results.each_with_index do |(result, total, max), j|\n result[new_ord] += 1\n if result[new_ord] > max\n max = result[new_ord]\n end\n\n return [i, j] if max <= (total + 1) / 2\n\n results[j] = [result, total + 1, max]\n end\n\n results << [new_result, 1, 1]\n end\n\n nil\nend\n\nresult = solve(n, s)\n\nif result.nil?\n puts 'NO'\nelse\n puts 'YES'\n i, j = result\n puts s[j..i]\nend\n"}, {"source_code": "gets;s=gets.chomp.chars.uniq\nputs s.size<2 ? :NO : \"YES\\n%s%s\"%s[0,2]"}], "negative_code": [{"source_code": "s=gets.chomp.chars.uniq\nputs s.size<2 ? :NO : \"YES\\n%s %s\"%[s,2]"}, {"source_code": "gets;s=gets.chomp.chars.uniq\nputs s.size<2 ? :NO : \"YES\\n%s %s\"%s[0,2]"}, {"source_code": "s=gets.chomp.chars.uniq\nputs s.size<2 ? :NO : \"YES\\n%s %s\"%s[0,2]"}, {"source_code": "# http://codeforces.com/contest/1073/problem/A\n\nn = gets.chomp.to_i\ns = gets.chomp\n\ndef solve(n, s)\n last_result = {}\n results = [last_result]\n\n s.each_char do |char|\n new_result = last_result.dup\n new_result[char] ||= 0\n new_result[char] += 1\n last_result = new_result\n results << new_result\n end\n\n length = results.length\n\n length.times do |i|\n (i - 1).times do |j|\n differences = results[i].inject({}) do |result, (char, count)|\n j_count = results[j][char] || 0\n result.merge(char => count - j_count)\n end\n\n total_count = differences.inject(0) { |sum, (_, count)| sum + count }\n\n differences.each do |char, count|\n if count <= total_count / 2\n return [i-1, j]\n end\n end\n end\n end\n\n nil\nend\n\nresult = solve(n, s)\n\nif result.nil?\n puts 'NO'\nelse\n puts 'YES'\n i, j = result\n puts s[j..i]\nend\n"}], "src_uid": "ce4443581d4ee12db6607695cd567070"} {"source_code": "n = gets.to_i\n\nk=2\nfor i in 2..n+1\n puts (i**2 * (i-1)**2 - k) / (i-1)\n k=i*(i-1)\nend", "positive_code": [{"source_code": "$vis = Array.new(100005,0)\ndef cal\n\tpre = 2\n sim = 2\n for i in 1...100002\n pre /= i\n n = i\n while true\n cur = i * n * n + 2 * n * n + (n * n / i)\n if cur >= pre\n $vis[i] = cur - pre\n pre = (i+1) * n\n break\n end\n end\n sim = (sim + ($vis[i] * i))\n temp = Math.sqrt(sim).to_i\n if (temp * temp != sim || temp % (i+1) != 0)\n puts temp\n end\n sim = temp\n\tend\nend\n\ncal()\n\nN = gets.to_i\nfor i in 1..N\n\tputs $vis[i]\nend\n\n"}, {"source_code": "n = gets.to_i\n\nputs 2\n\n(2..n).each do |k|\n puts k*(k+1)*(k+1) - (k-1)\nend\n"}, {"source_code": "n=gets.to_i\nk=2\nfor i in 2..n+1\n puts (i*i*(i-1)*(i-1)-k)/(i-1)\n k=i*(i-1)\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\nans = [2]\nfor k in 2..n\n x = (k - 1) * k\n y = k * (k + 1)\n ans << (y**2 - x) / k\nend\nputs ans.*\"\\n\"\n\n"}, {"source_code": "n = gets.to_i\nsr = 2\nx = 2\nans = [2]\n2.upto(n) do |m|\n sr = sr + 2 * m\n ans << (sr * sr - x) / m\n x = sr\nend\nans.each{|x| puts x}\n"}, {"source_code": "level = gets.chomp.to_i\n\n(1..level).each do |l|\n puts 2 if l == 1\n puts l * (l + 1) * (l + 1) - (l - 1) if l != 1\nend"}, {"source_code": "def gcd(a, b)\n return a if b == 0\n return gcd(b, a % b)\nend\n\ndef lcm(a, b)\n return a * b / gcd(a, b)\nend\n\nn = gets.to_i\n\ncur = 2\n1.upto(n) do |ni|\n nxt = lcm(ni, ni + 1)\n k = (nxt * nxt - cur) / ni\n puts k\n cur = nxt\nend\n"}, {"source_code": "n=gets.to_i\nk=2\nfor i in 2..n+1\n puts (i*i*(i-1)*(i-1)-k)/(i-1)\n k=i*(i-1)\nend"}, {"source_code": "n=gets.to_i()\nm=2\n(1..n).each{|k|\n\tb=k*k+k\n\tputs (b*b-m)/k\n\tm=b\n}"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\n\nx = 2\nfor k in 1..n\n x = k * (k + 1)\n y = k * (k + 1) * (k + 2)\n puts (y**2 - x) / k\nend\n\n"}, {"source_code": "n = gets.to_i\nsr = 2\nx = 2\nans = []\n2.upto(n) do |m|\n sr = sr + 2 * m\n ans << (sr * sr - x) / m\n x = sr\nend\nans.each{|x| puts x}\n"}, {"source_code": "level = gets.chomp.to_i\nlevel += 1\n\ntarget = level ** 2\ncurrent = 1\nnumber = 2\n\nuntil current == level\nhit = target - number * current\n\n\nnumber = target ** 0.5\n\n\ncurrent += 1\nuntil number % current == 0\n\tcurrent += 1\nend\n\nputs hit\n#puts \"Number = #{number}\"\n#puts \"Hit = #{hit}\"\n#puts \"Curr = #{current}\"\nend"}, {"source_code": "level = gets.chomp.to_i\nlevel += 1\n\ntarget = level ** 2\ncurrent = 1\nnumber = 2\n\nuntil current == level\nhit = target - number * current\n\n\nnumber = target ** 0.5\n\n\ncurrent += 1\nuntil number % current == 0\n\tcurrent += 1\nend\n\nputs hit.to_i\n#puts \"Number = #{number}\"\n#puts \"Hit = #{hit}\"\n#puts \"Curr = #{current}\"\nend"}, {"source_code": "level = gets.chomp.to_i\nlevel += 1\n\ntarget = (level ** 2) * 4\ncurrent = 1\nnumber = 2\n\nuntil current == level\nhit = (target - number) / current\n\n\nnumber = target ** 0.5\n\n\ncurrent += 1\nuntil number % current == 0\n\tcurrent += 1\nend\n\nputs hit.to_i\n#puts \"Number = #{number}\"\n#puts \"Hit = #{hit}\"\n#puts \"Curr = #{current}\"\nend"}, {"source_code": "level = gets.chomp.to_i\nlevel += 1\n\ntarget = level ** 2\ncurrent = 1\nnumber = 2\n\nuntil current == level\nhit = (target - number) / current\n\n\nnumber = target ** 0.5\n\n\ncurrent += 1\nuntil number % current == 0\n\tcurrent += 1\nend\n\nputs hit.to_i\n#puts \"Number = #{number}\"\n#puts \"Hit = #{hit}\"\n#puts \"Curr = #{current}\"\nend"}], "src_uid": "6264405c66b2690ada9f8cc6cff55f0b"} {"source_code": "n, k = gets.split.map{|x| x.to_i}\nh = gets.split.map{|x| x.to_i}\na = [h[0..k-1].inject(0){|s, x| s + x}]\n(k..n-1).each{|i| a << a.last + h[i] - h[i - k]}\nputs(a.index(a.min) + 1)\n", "positive_code": [{"source_code": "line = gets.chomp.split(\" \").map {|e| e.to_i}\nn = line[0]\nk = line[1]\n\nhs = gets.chomp.split(\" \").map {|e| e.to_i}\n\nif k == 1\n min = -1\n minInd = -1\n for i in 0...(hs.length)\n if min == -1 || hs[i] < min\n min = hs[i]\n minInd = i + 1\n end\n end\n puts minInd\nelse\n ps = [0]\n\n acc = 0\n for i in 0...(hs.length)\n acc += hs[i]\n ps.push acc\n end\n\n min = -1\n minInd = -1\n for i in k..(hs.length)\n t = ps[i] - ps[i - k]\n if min == -1 || t < min\n min = t\n minInd = i - k\n end\n end\n\n puts (minInd + 1)\nend\n"}, {"source_code": "INF = 1.5 * 10 * 10 * 10 * 10 * 10 * 1000\n\ntmp = gets.chomp.split(\" \")\nn, k = tmp[0].to_i, tmp[1].to_i\nfence = gets.chomp.split(\" \").map!{|v| v.to_i}\nfor i in 1...fence.size do\n fence[i] += fence[i - 1]\nend\nfence = [0] + fence\nans, max = 0, INF\nfor i in 0...(fence.size - k) do\n if (max > fence[i + k] - fence[i])\n ans = i + 1\n max = fence[i + k] - fence[i]\n end\nend\nputs ans\n"}, {"source_code": "n,w=gets.split.map{|e| e.to_i}\na=gets.split.map{|e| e.to_i}\n\ns=0\nans=1\nw.times{|i|\n\ts+=a[i]\n}\nt=s\n1.upto(n-w){|i|\n\ts=s+a[i+w-1]-a[i-1]\n\tif t>s then\n\t\tt=s\n\t\tans=i+1\n\tend\n}\nputs ans\n\n"}, {"source_code": "n,k = gets.chomp.split(\" \").map{|i| i.to_i}\nh = gets.chomp.split(\" \").map{|i| i.to_i}\n\nmin = h[0...k].inject(0) {|sum, i| sum += i}\nmin_index = 0\nlast_sum = min\n(k...n).each do |i|\n last_sum = last_sum + h[i] - h[i-k]\n if min > last_sum\n min_index = i - k + 1\n min = last_sum\n end\nend\n\nputs min_index + 1\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn, k = gets.split.map(&:to_i)\nhs = gets.split.map(&:to_i)\nhsum = hs[0...k].reduce(:+)\nminimum_hsum = hsum\nminimum_idx = 1 #zero-based\n(0...(n-k)).each { |idx|\n hsum -= hs[idx]\n hsum += hs[idx + k]\n\n if hsum < minimum_hsum\n minimum_hsum = hsum\n minimum_idx = idx + 1 + 1 # one-based, exact index\n end\n}\n\nputs minimum_idx\n"}, {"source_code": "def solution(fence, take)\n cost = Array.new(fence.size, Float::INFINITY)\n cost[0] = fence[0...take].reduce(:+)\n \n for i in 1...fence.size-take+1 do\n cost[i] = cost[i-1] - fence[i-1] + fence[i + take - 1]\n end\n\n remove = 0\n min_cost = Float::INFINITY\n cost.each_with_index do |c, index|\n if min_cost > c\n min_cost = c\n remove = index \n end\n end\n remove + 1\nend\n\n\ntables, take = gets.split.map(&:to_i)\nfence = gets.split.map(&:to_i)\n\nputs solution(fence, take)\n"}, {"source_code": "def solution(fence, take)\n prefix_sum = fence.inject([0]) { |v, i| v << v.last + i }\n\n min_cost = Float::INFINITY\n for i in 0...prefix_sum.size-take do\n if min_cost > prefix_sum[i+take] - prefix_sum[i]\n min_cost = prefix_sum[i+take] - prefix_sum[i]\n index = i + 1\n end\n end\n index\nend\n\ntables, take = gets.split.map(&:to_i)\nfence = gets.split.map(&:to_i)\n\nputs solution(fence, take)\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = []\nc = 0\nn.times do |i|\n c += a[i]\n if i >= k - 1\n b << c \n c -= a[i - k + 1]\n end\nend\nputs b.index(b.min) + 1\n"}, {"source_code": "s = gets.split.map(&:to_i)\nn = s[0]\nk = s[1]\na = gets.split.map(&:to_i)\n\nsum = Array.new(n + 1, 0)\nminimum = 10000000000\nbest = 0\n\n1.upto(n) do |i|\n sum[i] = sum[i - 1] + a[i - 1]\n if i >= k\n sumk = sum[i] - sum[i - k]\n if sumk < minimum\n minimum = sumk\n best = i - k + 1\n end\n end\nend\n\nputs best\n"}, {"source_code": "n, k = gets.split(' ').map(&:to_i)\na = gets.split(' ').map(&:to_i)\na.unshift(0)\n\nsum = 0\nans = -1\nmin = 1_000_000_000\na.each_with_index do |e, i|\n sum += e\n sum -= a[i-k] if i>k\n\n if i >= k && min > sum\n min = sum\n ans = i - k + 1\n end\nend\n\nputs ans\n"}], "negative_code": [{"source_code": "n,k = gets.chomp.split(\" \").map{|i| i.to_i}\nh = gets.chomp.split(\" \").map{|i| i.to_i}\n\nmin = h[0...k].inject(0) {|sum, i| sum += i}\nlast_sum = min\n(k...n).each do |i|\n last_sum = last_sum + h[i] - h[i-k]\n min = last_sum if min > last_sum\nend\n\nputs min\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn, k = gets.split.map(&:to_i)\nhs = gets.split.map(&:to_i)\nhsum = hs[0...k].reduce(:+)\nminimum_hsum = hsum\nminimum_idx = 0 #zero-based\n(0...(n-k)).each { |idx|\n hsum -= hs[idx]\n hsum += hs[idx + k]\n\n if hsum < minimum_hsum\n minimum_hsum = hsum\n minimum_idx = idx\n end\n}\n\n# p [minimum_idx, minimum_hsum]\nputs minimum_idx+1+1 #1-based index, another one for obtaining exact index\n"}, {"source_code": "def solution(fence, take)\n prefix_sum = fence.inject([0]) { |v, i| v << v.last + i }\n\n min_cost = Float::INFINITY\n index = 1\n \n for i in 1...fence.size-take do\n if min_cost > prefix_sum[i+take-1] - prefix_sum[i-1]\n min_cost = prefix_sum[i+take-1] - prefix_sum[i-1]\n index = i\n end\n end\n index\nend\n\ntables, take = gets.split.map(&:to_i)\nfence = gets.split.map(&:to_i)\n\nputs solution(fence, take)"}, {"source_code": "def solution(fence, take)\n\n prefix_sum = fence.inject([0]) { |v, i| v << v.last + i }\n\n min_cost = Float::INFINITY\n index = -1\n \n for i in 1...fence.size-take do\n if min_cost > prefix_sum[i+take-1] - prefix_sum[i-1]\n min_cost = prefix_sum[i+take-1] - prefix_sum[i-1]\n index = i\n end\n end\n index\nend\n\ntables, take = gets.split.map(&:to_i)\nfence = gets.split.map(&:to_i)\n\nputs solution(fence, take)\n"}, {"source_code": "n, k = gets.split(' ').map(&:to_i)\na = gets.split(' ').map(&:to_i)\na.unshift(0)\n\nsum = 0\nans = -1\nmin = 1_000_000\na.each_with_index do |e, i|\n sum += e\n sum -= a[i-k] if i>k\n\n if i >= k && min > sum\n min = sum\n ans = i - k + 1\n end\nend\n\nputs ans\n"}, {"source_code": "line = gets.chomp.split(\" \").map {|e| e.to_i}\nn = line[0]\nk = line[1]\n\nhs = gets.chomp.split(\" \").map {|e| e.to_i}\n\nif k == 1\n min = -1\n minInd = -1\n for i in 0...(hs.length)\n if min == -1 || hs[i] < min\n min = hs[i]\n minInd = i + 1\n end\n end\n puts minInd\nelse\n ps = []\n\n acc = 0\n for i in 0...(hs.length)\n acc += hs[i]\n ps.push acc\n end\n\n min = -1\n minInd = -1\n for i in (k - 1)...(hs.length)\n t = ps[i] - ps[i - k + 1]\n if min == -1 || t < min\n min = t\n minInd = i - k + 1\n end\n end\n\n puts (minInd + 1)\n\nend\n"}, {"source_code": "line = gets.chomp.split(\" \").map {|e| e.to_i}\nn = line[0]\nk = line[1]\n\nhs = gets.chomp.split(\" \").map {|e| e.to_i}\n\nif k == 1\n min = -1\n minInd = -1\n for i in 0...(hs.length)\n if min == -1 || hs[i] < min\n min = hs[i]\n minInd = i + 1\n end\n end\n puts minInd\nelse\n ps = [0]\n\n acc = 0\n for i in 0...(hs.length)\n acc += hs[i]\n ps.push acc\n end\n\n min = -1\n minInd = -1\n for i in k...(hs.length)\n t = ps[i] - ps[i - k]\n if min == -1 || t < min\n min = t\n minInd = i - k\n end\n end\n\n puts (minInd + 1)\nend\n"}, {"source_code": "line = gets.chomp.split(\" \").map {|e| e.to_i}\nn = line[0]\nk = line[1]\n\nhs = gets.chomp.split(\" \").map {|e| e.to_i}\nps = []\n\nacc = 0\nfor i in 0...(hs.length)\n acc += hs[i]\n ps.push acc\nend\n\nmin = -1\nminInd = -1\nfor i in (k - 1)...(hs.length)\n t = ps[i] - ps[i - k + 1]\n if min == -1 || t < min\n min = t\n minInd = i - k + 1\n end\nend\n\nputs (minInd + 1)\n\n"}], "src_uid": "69f4e340b3f6e1d807e0545ebea1fe2f"} {"source_code": "def solve(num)\n start = num[0].to_i.to_s(2)\n target = num[1].to_i.to_s(2)\n i = 0\n while start[i] == 0\n start.shift\n end\n i = 0\n while target[i] == 0\n target.shift\n end\n start_index = start.rindex(\"1\")\n target_index = target.rindex(\"1\")\n return -1 if start_index != target_index\n i = 0\n while i <= start_index\n foo = start[i]\n bar = target[i]\n return -1 if foo != bar \n i += 1\n end\n \n foo = [start.length, target.length].max\n baz = [start.length, target.length].min\n t = foo - baz\n (t / 3.0).ceil\n\nend\n\namount = gets.chomp.to_i\namount.times do\n input = gets.chomp.split(\" \")\n puts solve(input)\nend\n", "positive_code": [{"source_code": "t = 0\nt = gets.chomp.to_i\n\nwhile t>0\n a,b = gets.chomp.split(' ').map{|a| a.to_i}\n #puts \"Value of a is\" ,a\n #puts \"Value of b is \",b\n i = 0\n min = 0\n value = 0\n if a < b\n while(a to_value\n\t\tif from_value % to_value > 0\n\t\t\tputs -1\n\t\t\tnext\n\t\tend\n\t\tif (from_value / to_value) % 2 > 0\n\t\t\tputs -1\n\t\t\tnext\n\t\tend\n\tend\n\tif to_value > from_value\n\t\tif to_value % from_value > 0\n\t\t\tputs -1\n\t\t\tnext\n\t\tend\n\t\tif (to_value / from_value) % 2 > 0\n\t\t\tputs -1\n\t\t\tnext\n\t\tend\n\tend\n\tresult = nil\n\titer = 0\n\tif from_value > to_value\n\t\ttmp = to_value\n\t\tto_value = from_value\n\t\tfrom_value = tmp\n\tend\n\t# p 'from_value = ' + from_value.to_s\n\t# p 'to_value = ' + to_value.to_s\n\n\twhile from_value != to_value\n\t\t# p 'from_value = ' + from_value.to_s\n\t\titer += 1\n\t\t\n\t\tif to_value >= from_value * 8\n\t\t\t# p 'yes'\n\t\t\tfrom_value = from_value * 8\n\t\telsif to_value >= from_value * 4\n\t\t\t# p 'yes2'\n\t\t\tfrom_value = from_value * 4\n\t\telsif to_value >= from_value * 2\n\t\t\t# p 'yes3'\n\t\t\tfrom_value = from_value * 2\n\t\telse\n\t\t\tfrom_value = to_value\n\t\t\titer = -1\n\t\tend\n\tend\n\tputs iter\nend\n\n"}, {"source_code": "def solve(num)\n start = num[0].to_i.to_s(2)\n target = num[1].to_i.to_s(2)\n start_index = start.index(\"1\")\n target_index = target.index(\"1\")\n start = start[start_index..-1]\n target = target[target_index..-1]\n start_rindex = start.rindex(\"1\")\n target_rindex = target.rindex(\"1\")\n return -1 if start_rindex != target_rindex\n i = 0\n while i <= start_rindex\n return -1 if start[i] != target[i]\n i += 1\n end\n longer = [start.length, target.length].max\n shorter = [start.length, target.length].min\n diff = longer - shorter \n (diff / 3.0).ceil\nend\n\namount = gets.chomp.to_i\namount.times do\n input = gets.chomp.split(\" \")\n puts solve(input)\nend\n"}], "negative_code": [], "src_uid": "541039ef3c9b8251b758608811533e06"} {"source_code": "s=gets.strip\nn=gets.to_i\nm=\"\"\nn.times{|i| w=gets.strip; m=(m= s}\nif t.nil? or (/#{s}/ =~ t) != 0\n puts s\nelse\n puts t\nend\n"}, {"source_code": "a=gets.chop;puts$<.select{|s|s=~/^#{a}/}.min||a\n"}, {"source_code": "word = gets.strip\nn = gets.to_i\n\na = []\no = []\n\nfor i in 0..(n-1)\n a << gets.strip \nend\n\na.each {|x| o << x if x.start_with?(word) }\n\no.length == 0 ? (puts word) : (puts o.min)"}, {"source_code": "a=gets.chop;puts$<.select{|s|s=~/^#{a}/}.min||a\n"}, {"source_code": "str = STDIN.gets.chomp\nn = STDIN.gets.to_i\nlines = []\nn.times { lines << STDIN.gets.chomp }\n\nlines.sort.each do |line|\n if line.rindex(str) == 0\n puts line\n exit\n end\nend\nputs str"}, {"source_code": "a=gets.chop;puts$<.select{|s|s=~/^#{a}/}.min||a"}, {"source_code": "a=gets.chop;puts$<.select{|s|s=~/^#{a}/}.min||a"}, {"source_code": "s, n = gets.chomp, gets.to_i\nlines = []\nn.times { lines << gets.chomp }\n\nlines.sort.each do |line|\n if line.start_with?(s)\n puts line; exit\n end\nend\nputs s"}, {"source_code": "a=gets.chop;puts$<.select{|s|s=~/^#{a}/}.min||a\n"}, {"source_code": "a=gets.chop;puts$<.select{|s|s=~/^#{a}/}.min||a\n"}, {"source_code": "=begin 59A - Word\nstr = gets.chomp\nlower = 0\nupper = 0\nstr.each_char { |w| /[[:lower:]]/.match(w) ? lower+= 1 : upper+= 1 }\nputs upper > lower ? str.upcase : str.downcase\n=end\nstr = gets.chomp\nn = gets.to_i\nout = nil\nwhile n > 0\n\ttmp = gets.chomp\n if /\\A#{str}[[:lower:]]*/.match(tmp)\n if out.nil? || tmp < out\n out = tmp\n end\n end\n n-=1\nend\nputs out.nil? ? str : out"}, {"source_code": "a=gets.chop;puts$<.select{|s|s=~/^#{a}/}.min||a"}, {"source_code": "a=gets.chop;puts$<.select{|s|s=~/^#{a}/}.min||a\n"}, {"source_code": "s = gets.chomp!\nn = gets.to_i\n\nmas = Array.new()\nfor i in 0..n-1\n mas[i] = gets.chomp!\nend\n\nmas.sort!\nfor i in 0..n-1\n if (mas[i].index(s) == 0)\n puts mas[i]\n exit\n end\nend\n\nputs s"}, {"source_code": "str = gets.chomp\nnum = gets.chomp.to_i\n\nlines = []\nnum.times {|i|\n lines << gets.chomp\n}\n\nregexp = Regexp.new(\"^\" + str)\nstrs = lines.select {|line| regexp =~ line}\nif strs.length == 0\n puts str\nelse\n puts strs.sort[0]\nend\n"}, {"source_code": "s = gets.strip\na = []\n\ngets.to_i.times {\n n = gets.strip\n a.push n if n.start_with? s\n}\n\nputs a.empty? ? s : a.sort.first"}, {"source_code": "str = STDIN.gets.chomp\nn = STDIN.gets.to_i\nlines = []\nn.times { lines << STDIN.gets.chomp }\nlines.sort!\n\nlines.each do |line|\n if line.rindex(str) == 0\n puts line\n exit\n end\nend\nputs str"}, {"source_code": "a=gets.chop;puts$<.select{|s|s=~/^#{a}/}.min||a\n"}, {"source_code": "a=gets.chop;puts$<.select{|s|s=~/^#{a}/}.min||a\n"}, {"source_code": "$s=gets.chop\nputs$<.select{|l|l=~/^#$s/}.sort[0]||$s"}, {"source_code": "str = gets.strip; gets; auto = []\nwhile g = gets; auto.push g.strip; end\ns = auto.sort.grep(/^#{str}+/).first\nprint s ? s : str\n"}, {"source_code": "a=gets.chop;puts$<.select{|s|s=~/^#{a}/}.min||a\n"}], "negative_code": [{"source_code": "=begin 59A - Word\nstr = gets.chomp\nlower = 0\nupper = 0\nstr.each_char { |w| /[[:lower:]]/.match(w) ? lower+= 1 : upper+= 1 }\nputs upper > lower ? str.upcase : str.downcase\n=end\nstr = gets.chomp\nn = gets.to_i\nmax = 101\nout = str\nwhile n > 0\n\ttmp = gets.chomp\n if /\\A#{str}[[:lower:]]*/.match(tmp)\n if tmp.size < max\n max = tmp.size\n out = tmp\n end\n end\n n-=1\nend\nputs out"}, {"source_code": "=begin 59A - Word\nstr = gets.chomp\nlower = 0\nupper = 0\nstr.each_char { |w| /[[:lower:]]/.match(w) ? lower+= 1 : upper+= 1 }\nputs upper > lower ? str.upcase : str.downcase\n=end\nstr = gets.chomp\nn = gets.to_i\nmax = 101\nout = str\nwhile n > 0\n\ttmp = gets.chomp\n if /\\A#{str}[[:lower:]]*/.match(tmp)\n if tmp.size < max\n max = tmp.size\n out = tmp\n elsif tmp.size == max\n out = tmp < out ? tmp : out\n end\n end\n n-=1\nend\nputs out"}, {"source_code": "s=gets.strip\nn=gets.to_i # n can bo omitted in calculations\nok=false\nm=\"\"\nn.times{|i| w=gets.strip; m,ok=((m= 0 && (k ** 0.5).to_i ** 2 == k do\n k = a.pop\nend\nputs k\n"}, {"source_code": "gets\np gets.split.map(&:to_i).select {|x| x < 0 || Math.sqrt(x).modulo(1) != 0}.max\n"}, {"source_code": "a = gets.to_i\narray = gets.chomp.split(\" \")\narray = array.map { |n| n.to_i }\nx = array.select { |n| n>=0 and Math.sqrt(n)%1!=0 }.max\ny = array.select { |n| n<0 }.max\nans = []\nif x !=nil\n ans << x\nend\n\nif y !=nil\n ans << y\nend\n\nif ans.length !=0\n puts ans.max\nend"}, {"source_code": "gets;p gets.split.map(&:to_i).select{|x|x<0||Math.sqrt(x).floor**2!=x}.sort[-1]"}, {"source_code": "gets\np gets.split.map{|e|e[0]!=?- && (e.to_i**0.5).to_i**2==e.to_i ? -10**9 : e.to_i}.max\n"}, {"source_code": "n=gets.to_i;p gets.split.map(&:to_i).select{|x|x<0||Math.sqrt(x).floor**2!=x}.sort[-1]"}, {"source_code": "n = gets.to_i\nnum = gets.chomp.split(' ').map{|n| n.to_i }.sort\naddress = n -1\nwhile (address > 0) do\n if num[address] == -1\n break\n end\n if ((Math.sqrt(num[address].abs) - Math.sqrt(num[address].abs).to_i) != 0)\n break\n end\n address = address - 1\nend\n\nputs num[address]\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort.reverse\n\na.each{|t|\n y = Math.sqrt(t.abs).to_i\n if y*y!=t\n puts t\n exit\n end\n}\n"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na.sort!\nk = a.pop\nwhile k > 0 && (k ** 0.5).to_i ** 2 == k do\n k = a.pop\nend\nputs k\n"}, {"source_code": "n = gets.to_i\nnum = gets.chomp.split(' ').map{|n| n.to_i }.sort\naddress = n -1\nwhile (address > 0) do\n if num[address].abs == 1\n break\n end\n if ((Math.sqrt(num[address].abs) - Math.sqrt(num[address].abs).to_i) != 0)\n break\n end\n address = address - 1\nend\n\nputs num[address]"}, {"source_code": "n = gets.to_i\nnum = gets.chomp.split(' ').map{|n| n.to_i }.sort\naddress = n -1\nwhile (address > 0) do\n if ((Math.sqrt(num[address].abs) - Math.sqrt(num[address].abs).to_i) != 0)\n break\n end\n address = address - 1\nend\nputs num[address]\n"}, {"source_code": "n = gets.to_i\nnum = gets.chomp.split(' ').map{|n| n.to_i }\naddress = n -1\nwhile (address > 0) do\n if ((Math.sqrt(num[address].abs) - Math.sqrt(num[address].abs).to_i) != 0)\n break\n end\n address = address - 1\nend\nputs num[address]\n"}, {"source_code": "gets\np gets.split.map(&:to_i).select {|x| x >= 0 && Math.sqrt(x).modulo(1) != 0}.max\n"}, {"source_code": "n=gets.to_i;p gets.split.map(&:to_i).reject{|x|x<0 or Math.sqrt(x).floor**2==x}.sort[-1]\n\n"}, {"source_code": "a = gets.to_i\narray = gets.chomp.split(\" \")\narray = array.map { |n| n.to_i }\nx = array.select { |n| n>=0 and (Math.sqrt(n)%1!=0 or n==1) }.max\ny = array.select { |n| n<0 }.max\nans = []\nif x !=nil\n ans << x\nend\n\nif y !=nil\n ans << y\nend\n\nif ans.length !=0\n puts ans.max\nend"}, {"source_code": "a = gets.to_i\narray = gets.chomp.split(\" \")\narray = array.map { |n| n.to_i }\nx = array.select { |n| n>=0 and (Math.sqrt(n)%1!=0 or n==1) }.max\ny = array.select { |n| n<0 and (Math.sqrt(n*-1)%1!=0 or n==-1) }.max\nans = []\nif x !=nil\n ans << x\nend\n\nif y !=nil\n ans << y\nend\n\nif ans.length !=0\n puts ans.max\nend"}, {"source_code": "a = gets.to_i\narray = gets.chomp.split(\" \")\narray = array.map { |n| n.to_i }\nx = array.select { |n| n>=0 and Math.sqrt(n)%1!=0 }.max\ny = array.select { |n| n<0 and Math.sqrt(n*-1)%1!=0 }.max\nans = []\nif x !=nil\n ans << x\nend\n\nif y !=nil\n ans << y\nend\n\nif ans.length !=0\n puts ans.max\nend"}], "src_uid": "d46d5f130d8c443f28b52096c384fef3"} {"source_code": "n=gets.to_i\nmas=gets.split.map &:to_i\ni=mas.index(mas.max)+1\nmas[mas.index(mas.max)]=-1\nputs \"#{i} #{mas.max}\"", "positive_code": [{"source_code": "n = gets.to_i\ndx = gets.split().map{|i| i.to_i }\ni = dx.index(dx.max) + 1\ndx.sort!.reverse!\nputs i.to_s + \" \" + dx[1].to_s\n"}, {"source_code": "# https://codeforces.com/problemset/problem/386/A\n\ngets\nbids = gets.split(' ').map(&:to_i)\n\nhighest_bid = 0\nhighest_bid_index = 0\nsecond_highest_bid = 0\n\nbids.each_with_index do |bid, index|\n if bid > highest_bid\n second_highest_bid = highest_bid\n highest_bid = bid\n highest_bid_index = index\n elsif bid > second_highest_bid\n second_highest_bid = bid\n end\nend\n\nputs \"#{highest_bid_index+1} #{second_highest_bid}\"\n"}, {"source_code": "n = gets.to_i\nv = gets.split.map(&:to_i)\nans = v.map.with_index.to_a.sort{ |a, b| b[0] <=> a[0] }\nputs \"#{ans[0][1] + 1} #{ans[1][0]}\"\n"}, {"source_code": "#!/usr/bin/ruby\ngets\na=gets.split.map(&:to_i).each_with_index.to_a.sort.reverse\nputs \"#{a[0].last+1} #{a[1].first}\""}], "negative_code": [], "src_uid": "1d4aaf15e5c6fcde50515880aae74720"} {"source_code": "n,h = gets.split.map(&:to_f)\nfor i in 1..n-1\np h*((i/n)**0.5)\nend\n ", "positive_code": [{"source_code": "n, h = gets.chomp.split(\" \").map(&:to_f)\nb = 1\n\nhh = h / Math.sqrt(n)\n\n(n.to_i - 1).times do |i| \n print(hh * Math.sqrt(i+1), \" \")\nend\nputs "}, {"source_code": "n, h = gets.chomp.split.map(&:to_i)\na = []\n(1...n).each { |i|\n a << Math.sqrt(i.to_f / n) * h\n}\nputs a.map(&:to_s).join(' ')\n"}], "negative_code": [], "src_uid": "6f8a1a138ea2620f2013f426e29e4d98"} {"source_code": "inp = gets.split(' ')\n\na = gets.chomp\nb = gets.chomp\n\ndef match(a,b)\n\tmin_errors_size = 10**9\n\tmin_errors_array = Array.new\n\tfor i in (0..b.size-a.size)\n\t\terrors = []\n\t\tfor j in (0..a.size-1)\n\t\t\tif a[j]!=b[i+j]\n\t\t\t\t\terrors << j+1\n\t\t\tend\n\t\tend\n\t\tif errors.size < min_errors_size\n\t\t\tmin_errors_array = errors\n\t\t\tmin_errors_size = errors.size\n\t\tend\n\tend\n\treturn min_errors_array\nend\n\nans = match(a,b)\n\nputs ans.size\n\nputs ans.join(' ')", "positive_code": [{"source_code": "sub_str_length, str_length = gets.split.map(&:to_i)\n\nsub_str = gets.chomp\nstr = gets.chomp \nmin_replacements = 1000;\nmin_replace = *(1..sub_str_length)\n\ndef string_diff(str1, str2)\n return [] if (str1 == str2)\n (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact\nend\n\nif str == sub_str\n puts 0\nelsif sub_str == ''\n puts str.length\nelse\n (0..(str_length - sub_str_length)).each do |i|\n replacements = string_diff(str[i, sub_str_length], sub_str)\n min_replace == replacements if i == 0\n if replacements.empty?\n min_replacements = 0\n min_replace = []\n break\n elsif replacements.length < min_replacements\n min_replacements = replacements.length\n min_replace = replacements\n end\n end\n puts min_replacements\n puts min_replace.join(' ')\nend\n\n\n"}, {"source_code": "str = gets.split(\" \")\nn = str[0].to_i; m = str[1].to_i\ns = gets.chomp\nt = gets.chomp\n\nres = []\nans = 1e5\n\nfor i in (0...(m-n+1))\n cnt = 0\n temp = []\n k = i\n for j in (0...n)\n if t[k] != s[j]\n cnt+=1\n temp.push(j+1)\n end\n k+=1\n end\n if cnt < ans\n ans = cnt\n res = temp\n end\nend\n\nprint ans\nprint \"\\n\"\n\nres.each do |val|\n print \"#{val} \"\nend"}, {"source_code": "def go a, b\n res = []\n for i in 0..(a.length)\n if a[i] != b[i]\n res.push i\n end\n end\n\n return res\nend\n\nn, m = gets.strip.split.map &:to_i\na = gets.strip\nb = gets.strip\n\nres = *(1..n)\nfor i in 0..(m-n)\n curr = go(a, b[i..i+n-1]).map{ |x| x + 1 }\n if curr.length < res.length\n res = curr\n end\nend\n\nprint res.length.to_s + \"\\n\"\nres.each{ |x| print x.to_s + \" \" }\nprint \"\\n\"\n"}], "negative_code": [{"source_code": "sub_str_length, str_length = gets.split.map(&:to_i)\n\nsub_str = gets.chomp\nstr = gets.chomp\nmin_replacements = 1000;\nmin_replace = []\n\ndef string_diff(str1, str2)\n return [] if(str1 == str2)\n (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact\nend\n\nif str == sub_str\n puts 0\nelse\n (0..(str_length - sub_str_length)).each do |i|\n replacements = string_diff(str[i, sub_str_length + i - 1], sub_str)\n if replacements.empty?\n min_replacements = 0\n min_replace = []\n break\n elsif replacements.length < min_replacements\n min_replacements = replacements.length\n min_replace = replacements\n end\n end\n puts min_replacements\n puts min_replace.join(' ')\nend"}, {"source_code": "sub_str_length, str_length = gets.split.map(&:to_i)\n\nsub_str = gets.chomp\nstr = gets.chomp\nmin_replacements = 1000;\nmin_replace = []\n\ndef string_diff(str1, str2)\n return [] if(str1 == str2)\n (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact\nend\n\nif str == sub_str\n puts 0\nelse\n (0..(str_length - sub_str_length)).each do |i|\n replacements = string_diff(str[i, sub_str_length], sub_str)\n if replacements.empty?\n min_replacements = 0\n min_replace = []\n break\n elsif replacements.length < min_replacements\n min_replacements = replacements.length\n min_replace = replacements\n end\n end\n puts min_replacements\n puts min_replace.join(' ')\nend"}, {"source_code": "sub_str_length, str_length = gets.split.map(&:to_i)\n\nsub_str = gets.chomp\nstr = gets.chomp\nmin_replacements = 1000;\nmin_replace = []\n\ndef string_diff(str1, str2)\n return [] if(str1 == str2)\n (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact\nend\n\nif str == sub_str\n puts 0\nelse\n (0..(str_length - sub_str_length)).each do |i|\n replacements = string_diff(str[i, sub_str_length + i], sub_str)\n if replacements.empty?\n min_replacements = 0\n min_replace = []\n break\n elsif replacements.length < min_replacements\n min_replacements = replacements.length\n min_replace = replacements\n end\n end\n puts min_replacements\n puts min_replace.join(' ')\nend"}, {"source_code": "sub_str_length, str_length = gets.split.map(&:to_i)\n\nsub_str = gets.chomp\nstr = gets.chomp\nmin_replacements = 1000;\nmin_replace = []\n\ndef string_diff(str1, str2)\n return [] if(str1 == str2)\n puts \"=====#{str1}========#{str2}====\"\n (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact\nend\n\nif str == sub_str\n puts 0\nelse\n (0..(str_length - sub_str_length)).each do |i|\n replacements = string_diff(str[i, sub_str_length], sub_str)\n if replacements.empty?\n min_replacements = 0\n min_replace = []\n break\n elsif replacements.length < min_replacements\n min_replacements = replacements.length\n min_replace = replacements\n end\n end\n puts min_replacements\n puts min_replace.join(' ')\nend"}, {"source_code": "sub_str_length, str_length = gets.split.map(&:to_i)\n\nsub_str = gets.chomp\nstr = gets.chomp\nmin_replacements = 1000;\nmin_replace = []\n\ndef string_diff(str1, str2)\n (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact\nend\n\n(0..(str_length - sub_str_length)).each do |i|\n replacements = string_diff(str[i, sub_str_length + i - 1], sub_str)\n if replacements.length < min_replacements\n min_replacements = replacements.length\n min_replace = replacements\n end\nend\n\nputs min_replacements\nputs min_replace.join(' ')"}, {"source_code": "sub_str_length, str_length = gets.split.map(&:to_i)\n\nsub_str = gets.chomp\nstr = gets.chomp\nmin_replacements = 1000;\nmin_replace = []\n\ndef string_diff(str1, str2)\n (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact\nend\n\n(0..(str_length - sub_str_length)).each do |i|\n replacements = string_diff(str[i, sub_str_length + i - 1], sub_str)\n if replacements.length < min_replacements\n min_replacements = replacements.length\n min_replace = replacements\n end\nend\n\nputs min_replacements\np min_replace.join(' ')"}, {"source_code": "inp = gets.split(' ')\n\nn = inp.first.to_i\nm = inp.last.to_i\n\na = gets.chomp\nb = gets.chomp\n\ndef match(a,b)\n\tmin_errors_size = 10**9\n\tmin_errors_array = Array.new\n\tfor i in (0..b.size-1)\n\t\terrors = []\n\t\tfor j in (0..a.size-1)\n\t\t\tif a[j]!=b[i+j]\n\t\t\t\t\terrors << j+1\n\t\t\tend\n\t\tend\n\t\tif errors.size < min_errors_size\n\t\t\tmin_errors_array = errors\n\t\t\tmin_errors_size = errors.size\n\t\tend\n\tend\n\treturn min_errors_array\nend\n\nans = match(a,b)\n\nputs ans.size\n\nputs ans.join(' ')"}], "src_uid": "dd26f45869b73137e5e5cc6820cdc2e4"} {"source_code": "n = gets.to_i\nz = []\nn.times {\n z << gets.chomp.split.map(&:to_i)\n}\n\nz.sort! { |x, y| p = x[0] <=> y[0]; p != 0 ? p : x[1] <=> y[1] }\nx = z[0][1]\n(1...n).each do |i|\n x = z[i][1] >= x ? z[i][1] : z[i][0]\nend\nputs x", "positive_code": [{"source_code": "n = gets.to_i\narr = []\nb_arr = []\nn.times do\n\tarr << gets.split(\" \").map(&:to_i)\n\tb_arr << arr[-1][1]\nend\narr.sort!\n# max_h = {}\n# x = arr.chunk{|x| x[0]}.each do |a|\n# \tmax_h[a[0]] = a[1].collect{|e| e[1]}.max\n# end\nmax = 0\narr.each do |a|\n\tif max <= a[1] \n\t\tmax = a[1]\n\telse\n\t\tmax = a[0]\n\tend\nend\nputs \"#{max}\""}, {"source_code": "n = gets.to_i\na = []\nn.times do\n\ta << gets.split.map(&:to_i)\nend\na.sort!\n\nprev = 0\nn.times do |i|\n\tprev = a[i][1] >= prev ? a[i][1] : a[i][0]\nend\nputs prev"}, {"source_code": "n = gets.to_i\na = []\nn.times do\n a << gets.chomp.split.map(&:to_i)\nend\na.sort!\nd = 0\nfor i in 0...n\n a[i].sort!\n if a[i][0] >= d\n s = a[i][0]\n elsif a[i][1] >= d\n s = a[i][1]\n end\n d = s\nend\nputs d\n"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\npairs = []\nn.times do\n\ta, b = STDIN.readline.split.map {|s| s.to_i }\n\tpairs.push([a, b])\nend\npairs.sort!\npos = 0\npairs.each do |late, early|\n\tif early >= pos\n\t\tpos = early\n\telse\n\t\tpos = late\n\tend\nend\nputs pos\n"}, {"source_code": "\nn = gets.chomp.to_i;\narr = Array.new(n);\n\nn.times { |x|\n arr[x] = gets.chomp.split(' ').map(&:to_i);\n}\narr.sort!;\npre = -1;\n\narr.each { |x, y|\n if (pre <= y)\n pre = y;\n else\n pre = x;\n end \n}\nputs pre;\n"}, {"source_code": "n=gets.to_i\narr=[]\nn.times{|e|\n\tx=gets.split.map{|e| e.to_i}\n\tarr<= x\n\t\tx = arr[i].min\n\telse\n\t\tx = arr[i].max\n\tend\nend\n\nprint x"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\nDay = Struct.new(:a, :b)\nn = gets.to_i\ndays = []\nn.times {\n a, b = gets.split.map(&:to_i)\n days << Day.new(a, b)\n}\ndays.sort! { |d1, d2|\n if d1.a != d2.a\n d1.a - d2.a\n else\n d1.b - d2.b\n end\n}\nbday_broken = false\nbprev = 0\ndays.each { |day|\n if bprev <= day.b\n bprev = day.b\n else\n bday_broken = true\n end\n}\n\nif bday_broken\n puts days.last.a\nelse\n puts days.last.b\nend\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\nDay = Struct.new(:a, :b)\nn = gets.to_i\ndays = []\nn.times {\n a, b = gets.split.map(&:to_i)\n days << Day.new(a, b)\n}\ndays.sort! { |d1, d2|\n if d1.a != d2.a\n d1.a - d2.a\n else\n d1.b - d1.b\n end\n}\nbday_broken = false\nbprev = 0\ndays.each { |day|\n if bprev <= day.b\n bprev = day.b\n else\n bday_broken = true\n end\n}\n\nif bday_broken\n puts days.last.a\nelse\n puts days.last.b\nend\n"}, {"source_code": "n = Integer(gets)\na = []\nnums = []\nfor i in 0...n\n a[i] = []\n nums[i] = []\n nums[i] = gets.chomp.split\n a[i][0] = Integer(nums[i][0])\n a[i][1] = Integer(nums[i][1])\nend\n\na = a.sort_by{|x,y|x}\nbest = -1\nfor i in 0...n\n if best <= a[i][1]\n best = a[i][1]\n else\n best = a[i][0]\n end\nend\nprint best"}, {"source_code": "n = Integer(gets)\na = []\nnums = []\nfor i in 0...n\n a[i] = []\n nums[i] = []\n nums[i] = gets.chomp.split\n a[i][0] = Integer(nums[i][0])\n a[i][1] = Integer(nums[i][1])\nend\npointer = 1\nfor i in 0...n-1\n if a[i][0] == a[i + 1][0]\n pointer = 1\n else\n pointer = 0\n break\n end\nend\nbest = -1\nif pointer == 0\n a = a.sort_by{|x,y|x}\nelse\n a = a.sort_by{|x,y|y}\nend\nfor i in 0...n\n if best <= a[i][1]\n best = a[i][1]\n else\n best = a[i][0]\n end\nend\nprint best"}, {"source_code": "n = gets.chomp.to_i\narr = []\nfor i in (0..n-1)\n\tarr << gets.chomp.split.map(&:to_i)\nend\n\narr = arr.sort_by{|x,y| x&&y}\n\nx = arr[0].min\nfor i in (1..n-1)\n\tif arr[i].min >= x\n\t\tx = arr[i].min\n\telse\n\t\tx = arr[i].max\n\tend\nend\n\nprint x"}, {"source_code": "n = gets.chomp.to_i\narr = []\nfor i in (0..n-1)\n\tarr << gets.chomp.split.map(&:to_i)\nend\n\narr = arr.sort_by{|x,y| y&&x}\n\nx = arr[0].min\nfor i in (1..n-1)\n\tif arr[i].min >= x\n\t\tx = arr[i].min\n\telse\n\t\tx = arr[i].max\n\tend\nend\n\nprint x"}, {"source_code": "n = gets.chomp.to_i\narr = []\nfor i in (0..n-1)\n\tarr << gets.chomp.split.map(&:to_i)\nend\n\narr = arr.sort_by{|x,y| y&&x}\nif arr[0].min <= arr[n-1].min\n\tprint arr[n-1].min\nelse\n\tprint arr[n-1].max\nend"}, {"source_code": "n = gets.to_i\narr = []\nb_arr = []\nn.times do\n\tarr << gets.split(\" \").map(&:to_i)\n\tb_arr << arr[-1][1]\nend\narr.sort!\nmax_h = {}\nx = arr.chunk{|x| x[0]}.each do |a|\n\tmax_h[a[0]] = a[1].collect{|e| e[1]}.max\nend\nmax = 0\nmax_h.each do |k,v|\n\tif max <= v \n\t\tmax = v\n\telse\n\t\tmax = k\n\tend\nend\nputs \"#{max}\""}, {"source_code": "n = gets.to_i\narr = []\nb_arr = []\nn.times do\n\tarr << gets.split(\" \").map(&:to_i)\n\tb_arr << arr[-1][1]\nend\narr.sort!\nmax_h = {}\nx = arr.chunk{|x| x[0]}.each do |a|\n\tmax_h[a[0]] = a[1].collect{|e| e[1]}.max\nend\nmax = 0\nmax_h.each do |k,v|\n\tif v >= max\n\t\tmax = v\n\telse\n\t\tmax = k\n\tend\nend\nputs \"#{max}\""}, {"source_code": "n = gets.to_i\narr = []\nb_arr = []\nn.times do\n\tarr << gets.split(\" \").map(&:to_i)\n\tb_arr << arr[-1][1]\nend\narr.sort!\nx = arr.chunk{|x| x[0]}.to_a.last[1].collect{|e| e[1]}\nz = x.max\nif b_arr.all?{|e| z >= e}\n\tans = z\nelse\n\tans = arr[-1][0]\nend\nputs ans"}, {"source_code": "n = gets.to_i\nz = []\nn.times {\n z << gets.chomp.split.map(&:to_i)\n}\n\nz.sort! { |x, y| x[0] <=> y[0] }\nx = z[0][1]\n(1...n).each do |i|\n x = z[i][1] >= x ? z[i][1] : z[i][0]\nend\nputs x"}], "src_uid": "71bc7c4eb577441f2563e40d95306752"} {"source_code": "h = {}\n# ?a.upto(?z) { |c| h[c] = 0 }\ns = STDIN.readline.chop\ns.each_char do |c|\n\tif h[c] == nil ;\n\t\th[c] = 0\n\tend\n\th[c] += 1\nend\n\nans = 0\nflag = true\ns = STDIN.readline.chop\ns.each_char do |c|\n\tif h[c] == nil ;\n\t\tflag = false\n\telsif h[c] > 0 ;\n\t\th[c] -= 1\n\t\tans += 1\n\tend\nend\n\nprint flag ? ans : -1\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\nh=Hash.new(0)\ngets.chomp.each_char{|c|h[c]+=1}\ng=Hash.new(0)\ngets.chomp.each_char{|c|g[c]+=1}\nr=0\ng.each{|k,v|\n\tif h[k]==0\n\t\tp -1\n\t\texit\n\tend\n\tr+=[h[k],v].min\n}\np r"}, {"source_code": "a,b,ans=Array.new(26,0),Array.new(26,0),0\ngets.chomp.split('').each{|i| a[i.ord-97]+=1}\ngets.chomp.split('').each{|i| b[i.ord-97]+=1}\n26.times do |i|\n\tif a[i]==0 and a[i]!=b[i]\n\t\tputs \"-1\"\n\t\texit\n\tend\nend\n26.times{|i| ans+=[a[i],b[i]].min}\nputs ans"}, {"source_code": "s1 = gets.chomp.split(\"\")\ns2 = gets.chomp.split(\"\")\ncount1 = Hash.new(0)\ns1.each do |a|\n\tcount1[a] += 1\nend\n\ncount2 = Hash.new(0)\ns2.each do |a|\n\tcount2[a] += 1\nend\n\nans = true\ns = 0\ncount2.each do |k,v|\t\n\tif count1[k] != 0\n\t\ts += [count1[k],v].min\n\telse\n\t\tans = false\n\t\tbreak\n\tend\t\nend\nputs ans ? s : \"-1\""}, {"source_code": "c1, c2 = {}, {}\ngets.chomp.each_byte{|c| c1[c]=c1[c].nil? ? 1 : c1[c]+1}\ngets.chomp.each_byte{|c| c2[c]=c2[c].nil? ? 1 : c2[c]+1}\nsum = 0\nc2.each do |k,v|\n\tif c1[k].nil?\n\t\tputs -1\n\t\texit 0\n\tend\n\tsum += [v, c1[k]].min\nend\nputs sum\n"}, {"source_code": "a = gets.chomp\nb = gets.chomp\ncnt1 = Hash.new\ncnt2 = Hash.new\nfor x in a.scan /./\n if cnt1[x] == nil\n cnt1[x] = 0\n end\n cnt1[x] += 1\nend\nfor x in b.scan /./\n if cnt2[x] == nil\n cnt2[x] = 0\n end\n cnt2[x] += 1\nend\nans = 0\ncnt2.each_pair do |k, v|\n if cnt1[k] == nil\n puts -1\n exit\n end\n ans += [v, cnt1[k]].min\nend\nputs ans\n"}], "negative_code": [{"source_code": "h = {}\n?a.upto(?z) { |c| h[c] = 0 }\ns = STDIN.readline.chop\ns.each_char { |c| h[c] += 1 }\n\nans = 0\ns = STDIN.readline.chop\ns.each_char do |c|\n\tif h[c] > 0\n\t\th[c] -= 1\n\t\tans += 1\n\tend\nend\nans = -1 if ans == 0\nprint ans\n"}, {"source_code": "t = gets.to_i\nt.times do \n\tn = gets.to_i\n\ts = 0\n\ti = 1\n\tans = -1\n\t(1..n).each do |i|\n\t\ts += i\n\t\tif s >= n\n\t\t\tans = i\n\t\t\ts -= i\n\t\t\tbreak\n\t\tend\n\tend\n\trow,col = ans,n - s\n\n\n\tsum = row + 1\n\tnumerator = sum - col\n\tdenominator = col\n\n\tnumerator,denominator = denominator,numerator if row.even?\n\n\tputs \"TERM #{n} IS #{numerator}/#{denominator}\"\nend"}, {"source_code": "c1, c2 = {}, {}\ngets.chomp.each_byte{|c| c1[c]=c1[c].nil? ? 1 : c1[c]+1}\ngets.chomp.each_byte{|c| c2[c]=c2[c].nil? ? 1 : c2[c]+1}\nsum = 0\nc1.each{|k,v| sum+=[v,c2[k].nil? ? 0 : c2[k]].min}\nsum = -1 if sum == 0\nputs sum\n"}], "src_uid": "b1e09df7c47dbd04992e64826337c28a"} {"source_code": "=begin\narr = [1]\nsign = -1\n25.times { |i|\n print \"%d: \" % i\n p arr\n n_arr = Array.new(arr.length + 1, 0)\n for i in 0..arr.length\n n_arr[i] += arr[i - 1] if i - 1 >= 0\n (n_arr[i] += sign * arr[i]; sign *= -1) if i < arr.length\n end\n arr, n_arr = n_arr, arr\n}\n0: [1]\n1: [-1, 1]\n2: [-1, -2, 1]\n3: [-1, 1, -1, 1]\n4: [1, 0, 2, 0, 1]\n5: [-1, 1, -2, 2, -1, 1]\n6: [-1, -2, -1, -4, 1, -2, 1]\n7: [-1, 1, -3, 3, -3, 3, -1, 1]\n8: [1, 0, 4, 0, 6, 0, 4, 0, 1]\n9: [-1, 1, -4, 4, -6, 6, -4, 4, -1, 1]\n10: [-1, -2, -3, -8, -2, -12, 2, -8, 3, -2, 1]\n11: [-1, 1, -5, 5, -10, 10, -10, 10, -5, 5, -1, 1]\n12: [1, 0, 6, 0, 15, 0, 20, 0, 15, 0, 6, 0, 1]\n13: [-1, 1, -6, 6, -15, 15, -20, 20, -15, 15, -6, 6, -1, 1]\n14: [-1, -2, -5, -12, -9, -30, -5, -40, 5, -30, 9, -12, 5, -2, 1]\n15: [-1, 1, -7, 7, -21, 21, -35, 35, -35, 35, -21, 21, -7, 7, -1, 1]\n16: [1, 0, 8, 0, 28, 0, 56, 0, 70, 0, 56, 0, 28, 0, 8, 0, 1]\n17: [-1, 1, -8, 8, -28, 28, -56, 56, -70, 70, -56, 56, -28, 28, -8, 8, -1, 1]\n18: [-1, -2, -7, -16, -20, -56, -28, -112, -14, -140, 14, -112, 28, -56, 20, -16, 7, -2, 1]\n19: [-1, 1, -9, 9, -36, 36, -84, 84, -126, 126, -126, 126, -84, 84, -36, 36, -9, 9, -1, 1]\n20: [1, 0, 10, 0, 45, 0, 120, 0, 210, 0, 252, 0, 210, 0, 120, 0, 45, 0, 10, 0, 1]\n21: [-1, 1, -10, 10, -45, 45, -120, 120, -210, 210, -252, 252, -210, 210, -120, 120, -45, 45, -10, 10, -1, 1]\n22: [-1, -2, -9, -20, -35, -90, -75, -240, -90, -420, -42, -504, 42, -420, 90, -240, 75, -90, 35, -20, 9, -2, 1]\n23: [-1, 1, -11, 11, -55, 55, -165, 165, -330, 330, -462, 462, -462, 462, -330, 330, -165, 165, -55, 55, -11, 11, -1, 1]\n24: [1, 0, 12, 0, 66, 0, 220, 0, 495, 0, 792, 0, 924, 0, 792, 0, 495, 0, 220, 0, 66, 0, 12, 0, 1]\n=end \nrequire 'openssl'\nN = $stdin.gets.chomp.to_i\nA = $stdin.gets.split.map(&:to_i)\nM = (1e9 + 7).to_i\nsign = 1\nuntil (N - 1) % 4 == 0\n na = Array.new(N - 1, 0)\n (N - 1).times { |i| na[i] = A[i] + sign * A[i + 1]; sign *= -1 }\n N, A, na = N - 1, na, A\nend\nf = (1..N / 2 + 1).each_with_object([1]) { |i, o| o << o[-1] * i % M }\nvf = (-(N / 2)..0).each_with_object([f[N / 2 + 1].to_bn.mod_exp(M - 2, M)]) { |i, o| o << o[-1] * (-i + 1) % M }.reverse\nans = 0\n(0...N).step(2).each { |i| ans = (ans + A[i] * f[N / 2] * vf[i / 2] * vf[N / 2 - i / 2]) % M }\nans += M if ans < 0\nputs ans\n", "positive_code": [{"source_code": "require 'openssl'\nN = gets.chomp.to_i\nA = gets.split.map(&:to_i)\nM = 1000000007\nsign = 1\nuntil (N - 1) % 4 == 0\n na = Array.new(N - 1, 0)\n (N - 1).times { |i| na[i] = A[i] + sign * A[i + 1]; sign *= -1 }\n N, A, na = N - 1, na, A\nend\nf = (1..N / 2 + 1).each_with_object([1]) { |i, o| o << o[-1] * i % M }\nvf = (-(N / 2)..0).each_with_object([f[N / 2 + 1].to_bn.mod_exp(M - 2, M)]) { |i, o| o << o[-1] * (-i + 1) % M }.reverse\nans = 0\n(0...N).step(2).each { |i| ans = (ans + A[i] * f[N / 2] * vf[i / 2] * vf[N / 2 - i / 2]) % M }\nans += M if ans < 0\np ans\n"}, {"source_code": "require 'openssl'\nN = gets.chomp.to_i\nA = gets.split.map(&:to_i)\nM = 1000000007\nsign = 1\nuntil (N - 1) % 4 == 0\n na = Array.new(N - 1, 0)\n (N - 1).times { |i| na[i] = A[i] + sign * A[i + 1]; sign *= -1 }\n N, A, na = N - 1, na, A\nend\nf = (1..N / 2 + 1).each_with_object([1]) { |i, o| o << o[-1] * i % M }\nvf = (-(N / 2)..0).each_with_object([f[N / 2 + 1].to_bn.mod_exp(M - 2, M)]) { |i, o| o << o[-1] * (-i + 1) % M }.reverse\np (0...N).step(2).reduce(0) { |o, i| o = (o + A[i] * f[N / 2] * vf[i / 2] * vf[N / 2 - i / 2]) % M }\n"}], "negative_code": [{"source_code": "=begin\narr = [1]\nsign = -1\n25.times { |i|\n print \"%d: \" % i\n p arr\n n_arr = Array.new(arr.length + 1, 0)\n for i in 0..arr.length\n n_arr[i] += arr[i - 1] if i - 1 >= 0\n (n_arr[i] += sign * arr[i]; sign *= -1) if i < arr.length\n end\n arr, n_arr = n_arr, arr\n}\n0: [1]\n1: [-1, 1]\n2: [-1, -2, 1]\n3: [-1, 1, -1, 1]\n4: [1, 0, 2, 0, 1]\n5: [-1, 1, -2, 2, -1, 1]\n6: [-1, -2, -1, -4, 1, -2, 1]\n7: [-1, 1, -3, 3, -3, 3, -1, 1]\n8: [1, 0, 4, 0, 6, 0, 4, 0, 1]\n9: [-1, 1, -4, 4, -6, 6, -4, 4, -1, 1]\n10: [-1, -2, -3, -8, -2, -12, 2, -8, 3, -2, 1]\n11: [-1, 1, -5, 5, -10, 10, -10, 10, -5, 5, -1, 1]\n12: [1, 0, 6, 0, 15, 0, 20, 0, 15, 0, 6, 0, 1]\n13: [-1, 1, -6, 6, -15, 15, -20, 20, -15, 15, -6, 6, -1, 1]\n14: [-1, -2, -5, -12, -9, -30, -5, -40, 5, -30, 9, -12, 5, -2, 1]\n15: [-1, 1, -7, 7, -21, 21, -35, 35, -35, 35, -21, 21, -7, 7, -1, 1]\n16: [1, 0, 8, 0, 28, 0, 56, 0, 70, 0, 56, 0, 28, 0, 8, 0, 1]\n17: [-1, 1, -8, 8, -28, 28, -56, 56, -70, 70, -56, 56, -28, 28, -8, 8, -1, 1]\n18: [-1, -2, -7, -16, -20, -56, -28, -112, -14, -140, 14, -112, 28, -56, 20, -16, 7, -2, 1]\n19: [-1, 1, -9, 9, -36, 36, -84, 84, -126, 126, -126, 126, -84, 84, -36, 36, -9, 9, -1, 1]\n20: [1, 0, 10, 0, 45, 0, 120, 0, 210, 0, 252, 0, 210, 0, 120, 0, 45, 0, 10, 0, 1]\n21: [-1, 1, -10, 10, -45, 45, -120, 120, -210, 210, -252, 252, -210, 210, -120, 120, -45, 45, -10, 10, -1, 1]\n22: [-1, -2, -9, -20, -35, -90, -75, -240, -90, -420, -42, -504, 42, -420, 90, -240, 75, -90, 35, -20, 9, -2, 1]\n23: [-1, 1, -11, 11, -55, 55, -165, 165, -330, 330, -462, 462, -462, 462, -330, 330, -165, 165, -55, 55, -11, 11, -1, 1]\n24: [1, 0, 12, 0, 66, 0, 220, 0, 495, 0, 792, 0, 924, 0, 792, 0, 495, 0, 220, 0, 66, 0, 12, 0, 1]\n=end \nrequire 'openssl'\nN = $stdin.gets.chomp.to_i\nA = $stdin.gets.split.map(&:to_i)\nM = (1e9 + 7).to_i\nsign = 1\nuntil (N - 1) % 4 == 0\n na = Array.new(N - 1, 0)\n (N - 1).times { |i| na[i] = A[i] + sign * A[i + 1]; sign *= -1 }\n N, A, na = N - 1, na, A\nend\nf = (1..N / 2 + 1).each_with_object([1]) { |i, o| o << o[-1] * i % M }\nvf = (-(N / 2)..0).each_with_object([f[N / 2 + 1].to_bn.mod_exp(M - 2, M)]) { |i, o| o << o[-1] * (-i + 1) % M }.reverse\nans = 0\n(0...N).step(2).each { |i| ans = (ans + A[i] * sign * f[N / 2] * vf[i / 2] * vf[N / 2 - i / 2]) % M }\nans += M if ans < 0\nputs ans\n"}], "src_uid": "cf210ef68d0525dcb1574f450773da39"} {"source_code": "m,n=gets.split.map(&:to_i)\nf,n,m=0,m,n if m%2>z=0\ns=[[i=1,j=1]]\nv=\"s.unshift [n,m,z=1,n<2?1:j]if j%2>0||n<2&&m>2;n<2&&j=1\"\nloop{s<<[i+=1,j]while i2\nbreak eval v if m==j\ns<<[i,j+=1]}\ns<<[1,j+1]until 0>j-=1\nf||s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nputs z,s.map{|i|i*\" \"}\n", "positive_code": [{"source_code": "n,m=gets.scan(/\\d+/).map(&:to_i)\nf=1\nif ( n==1 || m==1 ) && (n*m!=2)\n\tputs 1\n\tputs n.to_s+\" \"+m.to_s+\" 1 1\"\n\t(n*m).times{|x| \n\t\tputs n>1? (x+1).to_s+\" 1\":\"1 \"+(x+1).to_s\n\t}\n\tputs \"1 1\"\nelsif n%2==0\n\tputs 0\n\tputs \"1 1\"\n\tn.times{|x|\n\t\t(m-1).times{|y|\n\t\t\tputs (x+1).to_s+\" \"+(f==1?y+2:m-y).to_s\n\t\t}\n\t\tf=-1*f\n\t}\n\tn.times{|x| puts (n-x).to_s+\" 1\"}\nelsif m%2==0\n\tputs 0\n\tputs \"1 1\"\n\tm.times{|x|\n\t\t(n-1).times{|y|\n\t\t\tputs (f==1?y+2:n-y).to_s+\" \"+(x+1).to_s\n\t\t}\n\t\tf=-1*f\n\t}\n\tm.times{|x| puts \"1 \"+(m-x).to_s}\nelse\n\tputs 1\n\tputs n.to_s+\" \"+m.to_s+\" 1 1\"\n\tn.times{|x|\n\t\tm.times{|y|\n\t\t\tputs (x+1).to_s+\" \"+(f==1?y+1:m-y).to_s\n\t\t}\n\t\tf=-1*f\n\t}\n\tputs \"1 1\"\nend"}, {"source_code": "m,n=gets.split.map(&:to_i)\nf,n,m=0,m,n if m%2>z=0\ns=[[i=1,j=1]]\nv=\"s.unshift [n,m,z=1,n<2?1:j]if j%2>0||n<2&&m>2;n<2&&j=1\"\nloop{s<<[i+=1,j]while i2\nbreak eval v if m==j\ns<<[i,j+=1]}\ns<<[1,j+1]until 0>j-=1\nf||s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nputs z,s.map{|i|i*\" \"}"}, {"source_code": "n,m=gets.split.map(&:to_i)\nf,n,m=0,m,n if n%2==0\ns=[[i=1,j=1]]\nz = 0\nloop do\n while i < n\n s << [i+=1,j]\n end\n if m == j\n if n == 1\n s.unshift [1,m,1,1]\n s << [1,1]\n else\n s.unshift [n,m,1,j=m]\n if i > 1\n s << [1,j]\n while j > 1\n s << [1,j-=1]\n end\n end\n end\n z = 1\n break\n end\n s << [i,j+=1]\n while i > 2\n s << [i-=1,j]\n end\n if m == j\n if n == 1\n if m > 2\n z = 1\n s.unshift [1,m,1,1]\n end\n s << [1,1]\n else\n #s.unshift [n,m,1,j=m]\n if i > 1\n s << [1,j]\n while j > 1\n s << [1,j-=1]\n end\n end\n end\n break\n end\n s << [i,j+=1]\nend\np z\nif f\n s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nend\ns.each{|i|puts i*\" \"}\n"}, {"source_code": "m,n=gets.split.map(&:to_i)\nf,n,m=0,m,n if m%2>z=0\ns=[[i=1,j=1]]\nv=\"s.unshift [n,m,z=1,n<2?1:j]if j%2>0||n<2&&m>2;n<2&&j=1\"\nloop{s<<[i+=1,j]while i2\nbreak eval v if m==j\ns<<[i,j+=1]}\ns<<[1,j+1]until 0>j-=1\nf||s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nputs z,s.map{|i|i*\" \"}\n"}, {"source_code": "m,n=gets.split.map(&:to_i)\nf,n,m=0,m,n if m%2>z=0\ns=[[i=1,j=1]]\nv=\"s.unshift [n,m,z=1,n<2?1:j]if j%2>0||n<2&&m>2;n<2&&j=1\"\nloop{s<<[i+=1,j]while i2\nbreak eval v if m==j\ns<<[i,j+=1]}\ns<<[1,j+1]until 0>j-=1\nf||s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nputs z,s.map{|i|i*\" \"}\n"}, {"source_code": "m,n=gets.split.map(&:to_i)\nf,n,m=0,m,n if m%2>z=0\ns=[[i=1,j=1]]\nv=\"s.unshift [n,m,z=1,n<2?1:j]if j%2>0||n<2&&m>2;n<2&&j=1\"\nloop{s<<[i+=1,j]while i2\nbreak eval v if m==j\ns<<[i,j+=1]}\ns<<[1,j+1]until 0>j-=1\nf||s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nputs z,s.map{|i|i*\" \"}\n"}, {"source_code": "m,n=gets.split.map(&:to_i)\nf,n,m=0,m,n if m%2>z=0\ns=[[i=1,j=1]]\nv=\"s.unshift [n,m,z=1,n<2?1:j]if j%2>0||n<2&&m>2;n<2&&j=1\"\nloop{s<<[i+=1,j]while i2\nbreak eval v if m==j\ns<<[i,j+=1]}\ns<<[1,j+1]until 0>j-=1\nf||s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nputs z,s.map{|i|i*\" \"}\n"}, {"source_code": "m,n=gets.split.map(&:to_i)\nf,n,m=0,m,n if m%2>z=0\ns=[[i=1,j=1]]\nv=\"s.unshift [n,m,z=1,n<2?1:j]if j%2>0||n<2&&m>2;n<2&&j=1\"\nloop{s<<[i+=1,j]while i2\nbreak eval v if m==j\ns<<[i,j+=1]}\ns<<[1,j+1]until 0>j-=1\nf||s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nputs z,s.map{|i|i*\" \"}"}, {"source_code": "m,n=gets.split.map(&:to_i)\nf,n,m=0,m,n if m%2>z=0\ns=[[i=1,j=1]]\nv=\"s.unshift [n,m,z=1,n<2?1:j]if j%2>0||n<2&&m>2;n<2&&j=1\"\nloop{s<<[i+=1,j]while i2\nbreak eval v if m==j\ns<<[i,j+=1]}\ns<<[1,j+1]until 0>j-=1\nf||s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nputs z,s.map{|i|i*\" \"}\n"}, {"source_code": "m,n=gets.split.map(&:to_i)\nf,n,m=0,m,n if m%2>z=0\ns=[[i=1,j=1]]\nv=\"s.unshift [n,m,z=1,n<2?1:j]if j%2>0||n<2&&m>2;n<2&&j=1\"\nloop{s<<[i+=1,j]while i2\nbreak eval v if m==j\ns<<[i,j+=1]}\ns<<[1,j+1]until 0>j-=1\nf||s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nputs z,s.map{|i|i*\" \"}\n"}, {"source_code": "m,n=gets.split.map(&:to_i)\nf,n,m=0,m,n if m%2>z=0\ns=[[i=1,j=1]]\nv=\"s.unshift [n,m,z=1,n<2?1:j]if j%2>0||n<2&&m>2;n<2&&j=1\"\nloop{s<<[i+=1,j]while i2\nbreak eval v if m==j\ns<<[i,j+=1]}\ns<<[1,j+1]until 0>j-=1\nf||s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nputs z,s.map{|i|i*\" \"}\n"}, {"source_code": "def generate_teleport_path(n, m)\n path = []\n columns = [ (1 .. m).to_a.reverse, (1 .. m).to_a ]\n (1 .. n).each do |row|\n index = row % 2\n columns[index].each { |col| path.push([row, col]) }\n end\n path.push([1, 1])\n return path\nend\n\ndef generate_path(n, m)\n if n % 2 == 1\n result = generate_path(m, n)\n return result.map { |v| v.reverse }\n end\n path = []\n (1 .. m).each { |col| path.push([1, col]) }\n columns = [ (2 .. m).to_a.reverse, (2 .. m).to_a ]\n (2 .. n).each do |row|\n index = row % 2\n columns[index].each { |col| path.push([row, col]) }\n end\n n.downto(1) { |row| path.push([row, 1]) }\n return path\nend\n\n\nn, m = gets.split.map { |v| v.to_i }\n\nteleports = []\n\nif n == 1 and m == 1\n path = [[1, 1], [1, 1]]\nelsif (n == 1 and m == 2) or (n == 2 and m == 1)\n path = [[1, 1], [n, m], [1, 1]]\nelsif n % 2 == 1 and m % 2 == 1 or n == 1 or m == 1\n teleports = [[n, m, 1, 1]]\n path = generate_teleport_path(n, m)\nelse\n path = generate_path(n, m)\nend\n\nputs teleports.size\nteleports.each { |port| puts port.join(' ') }\npath.each { |pair| puts pair.join(' ') }\n"}], "negative_code": [{"source_code": "n,m=gets.scan(/\\d+/).map(&:to_i)\nf=1\nif n==1 || m==1\n\tputs 1\n\tputs n.to_s+\" \"+m.to_s+\" 1 1\"\n\t(n*m).times{|x| \n\t\tputs n>1? (x+1).to_s+\" 1\":\"1 \"+(x+1).to_s\n\t}\n\tputs \"1 1\"\nelsif n%2==0\n\tputs 0\n\tputs \"1 1\"\n\tn.times{|x|\n\t\t(m-1).times{|y|\n\t\t\tputs (x+1).to_s+\" \"+(f==1?y+2:m-y).to_s\n\t\t}\n\t\tf=-1*f\n\t}\n\tn.times{|x| puts (n-x).to_s+\" 1\"}\nelsif m%2==0\n\tputs 0\n\tputs \"1 1\"\n\tm.times{|x|\n\t\t(n-1).times{|y|\n\t\t\tputs (f==1?y+2:n-y).to_s+\" \"+(x+1).to_s\n\t\t}\n\t\tf=-1*f\n\t}\n\tm.times{|x| puts \"1 \"+(m-x).to_s}\nelse\n\tputs 1\n\tputs n.to_s+\" \"+m.to_s+\" 1 1\"\n\tn.times{|x|\n\t\tm.times{|y|\n\t\t\tputs (x+1).to_s+\" \"+(f==1?y+1:m-y).to_s\n\t\t}\n\t\tf=-1*f\n\t}\n\tputs \"1 1\"\nend"}, {"source_code": "n,m=gets.split.map(&:to_i)\nf,n,m=0,m,n if n%2==0\ns=[[i=1,j=1]]\nz = 0\nloop do\n while i < n\n s << [i+=1,j]\n end\n if m == j\n z = 1\n s.unshift [n,m,1,j=m]\n break\n end\n s << [i,j+=1]\n while i > 2\n s << [i-=1,j]\n end\n if m == j\n break\n end\n s << [i,j+=1]\nend\ns << [1,j] if i>1\nwhile j > 1\n s << [1,j-=1]\nend\np z\nif f\n s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nend\ns.each{|i|puts i*\" \"}\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nf,n,m=0,m,n if n%2==0\ns=[[i=1,j=1]]\nz = 0\nloop do\n while i < n\n s << [i+=1,j]\n end\n if m == j\n if n == 1\n s.unshift [1,m,1,1]\n s << [1,1]\n else\n s.unshift [n,m,1,j=m]\n if i > 1\n s << [1,j]\n while j > 1\n s << [1,j-=1]\n end\n end\n end\n z = 1\n break\n end\n s << [i,j+=1]\n while i > 2\n s << [i-=1,j]\n end\n if m == j\n if n == 1\n s.unshift [1,m,1,1]\n s << [1,1]\n else\n #s.unshift [n,m,1,j=m]\n if i > 1\n s << [1,j]\n while j > 1\n s << [1,j-=1]\n end\n end\n end\n z = 1\n break\n end\n s << [i,j+=1]\nend\np z\nif f\n s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nend\ns.each{|i|puts i*\" \"}\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nf,n,m=0,m,n if n%2==0\ns=[[i=1,j=1]]\nz = 0\nloop do\n while i < n\n s << [i+=1,j]\n end\n if m == j\n z = 1\n s.unshift [n,m,1,j=m]\n break\n end\n s << [i,j+=1]\n while i > 2\n s << [i-=1,j]\n end\n if m == j\n break\n end\n s << [i,j+=1]\nend\ns << [1,j]\nwhile j > 1\n s << [1,j-=1]\nend\np z\nif f\n s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nend\ns.each{|i|puts i*\" \"}\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nf,n,m=0,m,n if n%2==0\ns=[[i=1,j=1]]\nz = 0\nloop do\n while i < n\n s << [i+=1,j]\n end\n if m == j\n if n == 1\n z = 1\n s.unshift [1,m,1,1]\n s << [1,1]\n else\n z = 1\n s.unshift [n,m,1,j=m]\n if i > 1\n s << [1,j]\n while j > 1\n s << [1,j-=1]\n end\n end\n end\n z = 1\n break\n end\n s << [i,j+=1]\n while i > 2\n s << [i-=1,j]\n end\n if m == j\n if n == 1\n z = 1\n s.unshift [1,m,1,1]\n s << [1,1]\n else\n #s.unshift [n,m,1,j=m]\n if i > 1\n s << [1,j]\n while j > 1\n s << [1,j-=1]\n end\n end\n end\n z = 1\n break\n end\n s << [i,j+=1]\nend\np z\nif f\n s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nend\ns.each{|i|puts i*\" \"}\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nf,n,m=0,m,n if n%2==0\ns=[[i=1,j=1]]\nz = 0\nloop do\n while i < n\n s << [i+=1,j]\n end\n if m == j\n if n == 1\n s.unshift [1,m,1,1]\n s << [1,1]\n else\n s.unshift [n,m,1,j=m]\n if i > 1\n s << [1,j]\n while j > 1\n s << [1,j-=1]\n end\n end\n end\n z = 1\n break\n end\n s << [i,j+=1]\n while i > 2\n s << [i-=1,j]\n end\n if m == j\n if n == 1\n s.unshift [1,m,1,1]\n s << [1,1]\n else\n s.unshift [n,m,1,j=m]\n if i > 1\n s << [1,j]\n while j > 1\n s << [1,j-=1]\n end\n end\n end\n z = 1\n break\n end\n s << [i,j+=1]\nend\np z\nif f\n s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nend\ns.each{|i|puts i*\" \"}\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nf,n,m=0,m,n if n%2==0\ns=[[i=1,j=1]]\nz = 0\nloop do\n while i < n\n s << [i+=1,j]\n end\n if m == j\n if n == 1\n s.unshift [1,m,1,1]\n s << [1,1]\n else\n s.unshift [n,m,1,j=m]\n if i > 1\n s << [1,j]\n while j > 1\n s << [1,j-=1]\n end\n end\n end\n z = 1\n break\n end\n s << [i,j+=1]\n while i > 2\n s << [i-=1,j]\n end\n if m == j\n if n == 1\n z = 1\n s.unshift [1,m,1,1]\n s << [1,1]\n else\n #s.unshift [n,m,1,j=m]\n if i > 1\n s << [1,j]\n while j > 1\n s << [1,j-=1]\n end\n end\n end\n break\n end\n s << [i,j+=1]\nend\np z\nif f\n s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nend\ns.each{|i|puts i*\" \"}\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nf,n,m=0,m,n if n%2==0\ns=[[i=1,j=1]]\nz = 0\nloop do\n while i < n\n s << [i+=1,j]\n end\n if m == j\n z = 1\n s.unshift [m,n,j=m,1]\n break\n end\n s << [i,j+=1]\n while i > 2\n s << [i-=1,j]\n end\n if m == j\n break\n end\n s << [i,j+=1]\nend\ns << [1,j]\nwhile j > 1\n s << [1,j-=1]\nend\np z\nif f\n s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}\nend\ns.each{|i|puts i*\" \"}\n"}, {"source_code": "def generate_teleport_path(n, m)\n path = []\n columns = [ (1 .. m).to_a.reverse, (1 .. m).to_a ]\n (1 .. n).each do |row|\n index = row % 2\n columns[index].each { |col| path.push([row, col]) }\n end\n path.push([1, 1])\n return path\nend\n\ndef generate_path(n, m)\n if n % 2 == 1\n result = generate_path(m, n)\n return result.map { |v| v.reverse }\n end\n path = []\n (1 .. m).each { |col| path.push([1, col]) }\n columns = [ (2 .. m).to_a.reverse, (2 .. m).to_a ]\n (2 .. n).each do |row|\n index = row % 2\n columns[index].each { |col| path.push([row, col]) }\n end\n n.downto(1) { |row| path.push([row, 1]) }\n return path\nend\n\n\nn, m = gets.split.map { |v| v.to_i }\n\nteleports = []\n\nif n == 1 and m == 1\n path = [[1, 1], [1, 1]]\nelsif n % 2 == 1 and m % 2 == 1 or n == 1 or m == 1\n teleports = [[n, m, 1, 1]]\n path = generate_teleport_path(n, m)\nelse\n path = generate_path(n, m)\nend\n\nputs teleports.size\nteleports.each { |port| puts port.join(' ') }\npath.each { |pair| puts pair.join(' ') }\n"}], "src_uid": "a98622d5b6d6d139df90b6fee3baa544"} {"source_code": "gets\nw = {}\nwhile(ln = gets)\n dst, _, src = ln.downcase.split(' ')\n w[dst] = (w[src] || 1) + 1\nend\nputs w.values.max\n", "positive_code": [{"source_code": "@data = $stdin.read.split\nn = @data.shift.to_i\nresult = 0\nh = {}\n(@data.size / 3).times do\n\ta, rep, b = @data.shift, @data.shift, @data.shift\n\traise 'wrong data' unless rep == 'reposted'\n\th[b.downcase] ||= 1\n\th[a.downcase] = h[b.downcase] + 1\n\tresult = [result, h[a.downcase]].max\nend\nputs result"}, {"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(name1, name2)\n if vertices[name1].nil? then\n vertices[name1] = List.new(name2, nil)\n else\n vertices[name1] = List.new(name2, vertices[name1])\n end\n end\n\n def print_edges \n vertices.each do |name, vertex| \n # next if vertex == \"\"\n while !vertex.nil? do \n puts \"edge #{name} - #{vertex.element}\"\n vertex = vertex.next_elem \n end \n end \n end \n\n # def print_verteces\n # puts vertices.keys.join(\" \")\n # end\nend \n\ndef dfs(graph, name)\n current_vertex = graph.vertices[name]\n if current_vertex.nil?\n return 1\n else\n max = 1\n while !current_vertex.nil?\n max = [max, dfs(graph, current_vertex.element)].max\n current_vertex = current_vertex.next_elem\n end\n end\n return max + 1\nend\n\nreposts = Graph.new({})\nn = gets.strip.to_i\nn.times do |i|\n str = gets.strip.split(\" \")\n reposts.add_edge(str.last.downcase, str.first.downcase)\nend\n# reposts.print_edges\nputs dfs(reposts, \"polycarp\")\n\n"}, {"source_code": "rlevels = Hash.new\n\nrlevels[\"polycarp\"] = 1\n\nrepcount = gets.strip.to_i\n\nrepcount.times do |i|\n string = gets.strip.downcase.split(\" \")\n name1 = string[0]\n name2 = string[2]\n rl = rlevels[name2]\n rlevels[name1] = rl+1\nend\n\np rlevels.values.max"}, {"source_code": "h = Hash.new\n\nn = gets.to_i\n\nh['polycarp'] = 1\nans = 1\n\nn.times do |i|\n a, b, c = gets.split.map {|s| s.downcase }\n h[a] = h[c] + 1\n\n ans = [ans, h[a]].max\nend\n\nputs ans\n"}, {"source_code": "amount = gets.chomp.to_i\n$names = []\n\namount.times {\n\trepost = gets.chomp.split(' ')\n\t$names.push([repost[0].downcase, repost[2].downcase])\n}\n\n$max = 0\n\ndef dfs(name, length)\n\t$names.each { |x|\n\t\tif x[1] == name\n\t\t\tdfs(x[0], length+1)\n\t\tend\n\t}\n\n\tif length > $max\n\t\t$max = length\n\tend\nend\n\ndfs(\"polycarp\", 0)\n\nputs $max + 1"}, {"source_code": "gets\nw = {}\nwhile(ln = gets)\n dst, src = ln.downcase.split(' ') - ['reposted']\n w[dst] = (w[src] || 1) + 1\nend\nputs w.values.max\n"}, {"source_code": "h=Hash.new(0)\n\ngets.to_i.times do |x|\n a=gets.chomp.split\n n1=a[0].downcase\n n2=a[2].downcase\n h[n2]=1 if x==0\n h[n1]=h[n2]+1\nend\n\np h.values.max\n"}, {"source_code": "n = gets.sub(\"\\n\",\"\").to_i\nh = {\"polycarp\"=>1}\nn.downto(1) do\n\ta,b = gets.sub(\"\\n\",\"\").split(\" reposted \").map{|i| i.downcase}\n\th[a] = h[b] + 1\nend\nmax = 0\nh.values.each{|i| max = i if(i>max)}\nputs max"}, {"source_code": "\n@inf = 1000000000\ne = gets.strip.to_i\n\ndepth = {}\ndepth['polycarp'] = 1\n\ne.times do |i|\n x, _, y = gets.strip.split.map(&:to_s).map(&:downcase)\n depth[x] = (depth[y] || 0) + 1\nend\n\nputs depth.values.max\n"}, {"source_code": "i = gets.to_i\nseq = 0\nreposts = Array.new()\nowners = Array.new().push(\"polycarp\")\nreposters = Array.new()\n1.upto(i) { reposts.push(gets.split(' ').map { |e| e.downcase } ) }\nwhile owners.count > 0\n\towners.each do |owner|\n\t\treposts.each do |repost|\n\t\t\treposters<< repost.first if repost.last == owner\n\t\tend\n\tend\n\towners = reposters.clone()\n\treposters.clear()\n\tseq+=1\nend\nputs seq"}], "negative_code": [], "src_uid": "16d4035b138137bbad247ccd5e560051"} {"source_code": "n=gets.to_i\nputs n&1>0?-1:[*n.downto(1)]*\" \"", "positive_code": [{"source_code": "n=gets.to_i\nputs n&1>0?-1:[*n.downto(1)]*\" \""}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\n\nif n%2!=0 then\n print -1\n exit \nend\n\nn.downto(1) do |index|\n print index,\" \"\nend"}, {"source_code": "n=gets.to_i\nputs n&1>0?-1:[*n.downto(1)]*\" \"\n"}, {"source_code": "n = gets.to_i\nif n.odd?\n\tputs -1\nelse\n\tp = (1..n).each_slice(2).map{|a| [a[1],a[0]]}.flatten\n\tputs p.join(\" \")\nend"}, {"source_code": "n=gets.to_i\nputs n%2==1 ?\"-1\":[*n.downto(1)]*\" \""}, {"source_code": "l = (1..gets.to_i).to_a\ni = 1\nwhile i < l.size\n\tl[i - 1], l[i] = l[i], l[i - 1]\n\ti += 2\nend\n\nif l.each_with_index.all? { |x, i| l[x - 1] == i + 1 and x != i + 1 }\n\tputs l.join(\" \")\nelse\n\tputs -1\nend"}, {"source_code": "n = gets.to_i\n\nif n.odd?\n\tputs -1\nelse\n\tp = Array.new(n) { |i, v| v = i + 1 }\n\t(n / 2).times do |i|\n\t\tp[i * 2], p[i * 2 + 1] = p[i * 2 + 1], p[i * 2]\n\tend\n\tputs p.join ' '\nend"}, {"source_code": "n = gets.to_i\nif n%2==0\n puts (1..n).to_a.select{|x| x%2!=0}.map{|x| [x+1,x]}.flatten.join(' ')\nelse\n p -1\nend"}, {"source_code": "n=gets.to_i;puts [[*1..n].reverse*' ',-1][n%2]"}, {"source_code": "a=gets.chomp.to_i\nif a%2==1\nputs \"-1\"\nelse\na.downto(1) do |i|\nprintf\"#{i} \"\nend\nend"}, {"source_code": "n = gets.to_i\nif n%2 == 0\n (n/2).times {|x| print x*2 + 2, ' ', x*2 + 1, ' '}\nelse\n puts -1\nend\n"}, {"source_code": "n=gets.to_i\nputs n&1>0?-1:[*n.downto(1)]*\" \"\n"}, {"source_code": "#!/usr/bin/env ruby\n$stdin.readlines.each do |line|\n n = line.strip.to_i\n if n % 2 == 0\n nums = (1..n).to_a\n i = 0\n while i < n-1\n t = nums[i]\n nums[i] = nums[i+1]\n nums[i+1] = t\n i += 2\n end\n puts nums.join(' ')\n else\n puts '-1'\n end\nend\n"}, {"source_code": "n = gets.to_i\nif (n%2==1)\n puts -1\n exit\nend\n(n/2).times do |i|\n print \"#{2*(i+1)} #{2*(i+1)-1} \"\nend"}, {"source_code": "n=gets.to_i\nputs n&1>0?-1:[*n.downto(1)]*\" \"\n"}, {"source_code": "n = Integer(gets.chomp)\nif n.even?\n a = []\n for i in (1..n).step(2)\n a << i + 1 << i\n end\n puts(a * ' ')\nelse\n puts -1\nend"}, {"source_code": "n=gets.to_i\nputs n&1>0?-1:[*n.downto(1)]*\" \"\n"}, {"source_code": "n = gets.to_i\nif n % 2 == 1\n puts -1\nelse\n puts (1..n).each_slice(2).map{|x,y| [y,x]}.inject(:+).map(&:to_s).join(' ')\nend"}, {"source_code": "sin = STDIN\nsout = STDOUT\n# sin = File.open(\"test.in\", \"r\")\n# sout = File.open(\"test.out\", \"w\")\n\nn = sin.readline.to_i\nsout.puts(n.even? ? (1..n).to_a.reverse.to_s.gsub(\",\", \"\")[1...-1] : -1)"}, {"source_code": "jom = gets.to_i \n\nif jom%2 == 1 \n print \"-1\"\nelse \n print \"2 1 \" \n jom.downto(3) { |n| print n.to_s + \" \" } \nend"}, {"source_code": "n=gets.to_i\nputs n&1>0?-1:[*n.downto(1)]*\" \""}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\nputs n%2==1 ? -1 : [*1..n].each_slice(2).map{|a,b|[b,a]}*' '"}, {"source_code": "n = gets.to_i\nputs n.odd? ? -1 : [*1..n].each_slice(2).map(&:reverse)\n"}, {"source_code": "n=gets.to_i\nputs n&1>0?-1:[*n.downto(1)]*\" \"\n"}, {"source_code": "n=gets.to_i\nif n%2!=0 \nputs -1\nelse\n\ta=(1..n).to_a\n\ti=0\n\twhile i0?-1:[*n.downto(1)]*\" \"\n"}, {"source_code": "n = gets.to_i\nif n%2==1\n\tp -1\n\texit\nend\n(n/2).times do |x|\n\tprint \"#{2*x+2} #{2*x+1} \"\nend\n"}, {"source_code": "def permute(n)\n return -1 if n % 2 == 1\n a = (1..n).to_a\n\n i = 0\n p = []\n while i < n-1\n p[i] = a[i+1]\n p[i+1] = a[i]\n i +=2\n end\n p.join(' ')\nend\n\nn = gets.to_i\nputs permute(n)"}, {"source_code": "n=gets.to_i;puts [[*1..n].reverse*' ',-1][n%2]\n"}, {"source_code": "n=gets.to_i\na=[0]\nif n&1==1\n\tputs \"-1\"\n\texit\nend\nfor i in 1..n\n\ta.push(i)\nend\nfor k in 1..(n/2)+2\n\tif 2*(k)<=n\n\t\ta[2*k],a[(2*k)-1]=a[(2*k)-1],a[2*k]\n\tend\nend\nfor i in 1..n\n\tprint a[i].to_s+' '\nend\nputs"}, {"source_code": "n = gets.to_i\nif n.odd?\n puts (-1)\n exit\nelse\n a = (1..n).to_a\n (0...n).select { |x| x.even? }.map { |x| a[x], a[x+1] = a[x+1], a[x]}\n puts a*' '\nend"}, {"source_code": "n = gets.to_i\nputs n & 1 > 0 ? -1 : [*n.downto(1)] * ' '"}, {"source_code": "n=gets.to_i\nputs n&1>0?-1:[*n.downto(1)]*\" \"\n"}, {"source_code": "a=gets.chomp.to_i\nif a%2==1\nputs \"-1\"\nelse\na.downto(1) do |i|\nprintf\"#{i} \"\nend\nend\n "}, {"source_code": "n = gets.to_i\nif n % 2 == 1 then\n puts -1\nelse\n (n / 2).times do |i|\n print (2 * (i + 1)).to_s + \" \" + (2 * (i + 1) - 1).to_s \n if i == n - 1 then print \"\\n\" else print \" \" end\n end\nend"}, {"source_code": "n = gets.to_i\n\nif n.odd?\n puts -1\nelse\n ans = []\n (1..n).each do |i|\n if i.odd?\n ans << i + 1\n else\n ans << i - 1\n end\n end\n puts ans.join(\" \")\nend"}, {"source_code": "n=gets.to_i\nputs n&1>0?-1:[*n.downto(1)]*\" \"\n"}, {"source_code": "n=gets.to_i\nputs n&1>0?-1:[*n.downto(1)]*\" \""}, {"source_code": "n = gets.chomp.to_i\nif n.even?\n array = (1..n).to_a\n index = 0\n while index < n\n array[index], array[index + 1] = array[index + 1], array[index]\n index += 2\n end\n puts array.join(\" \")\nelse\n puts \"-1\"\nend\n"}, {"source_code": "a=gets.chomp.to_i\nif a%2==1\nputs \"-1\"\nelse\na.downto(1) do |i|\nprintf\"#{i} \"\nend\nend"}, {"source_code": "n = gets.to_i\nif n % 2 == 0\n (1..n/2).each { |i|\n print 2*i, ' ', 2*i-1, ' '\n }\nelse\n puts -1\nend\n"}, {"source_code": "n=gets.to_i\nif n%2==1 then\n\tputs -1\nelse\n\tarr=[]\n\t2.step(n,2){|i|\n\t\tarr<<(i)\n\t\tarr<<(i-1)\n\t}\n\tputs arr*\" \"\nend\n\n"}, {"source_code": "n = gets.to_i\nif n % 2 == 1\n puts \"-1\"\n exit\nend\na = -1\nn.times do |i|\n if i % 2 == 0\n a += 3\n else\n a -= 1\n end\n print a\n if n != i-1\n print \" \"\n else\n print \"\\n\"\n end\nend"}], "negative_code": [{"source_code": "jom = gets.to_i \n\nif jom == 1 or jom == 3 \n puts \"-1\"\nelse \n print \"2 1 \" \n jom.downto(3) { |n| print n.to_s + \" \" } \nend "}, {"source_code": "\ufeffdef main(n)\n return [-1] if n == 1\n \n ans = []\n if n % 2 == 0 \n 1.step(n, 2) do |i|\n ans << i + 1\n ans << i\n end \n else\n 1.step(n, 3) do |i|\n ans << i + 1\n ans << i + 2\n ans << i\n end\n end\n \n return ans\nend \n \nn = gets.chomp.to_i\nans = main(n)\nputs ans.join(\" \")\n\n"}, {"source_code": "def permute(n)\n return -1 if n == 1\n a = (1..n).to_a\n # Swapping elements with their consecutives\n (1..n-1).each {|i| t = a[i-1]; a[i-1] = a[i]; a[i] = t}\n a.join(' ')\nend\n\nn = gets.to_i\nputs permute(n)"}, {"source_code": "def permute(n)\n return -1 if n == 1\n a = (1..n).to_a\n\n i = 0\n p = []\n while i < n-1\n p[i] = a[i+1]\n p[i+1] = a[i]\n i +=2\n end\n p.join(' ')\nend\n\nn = gets.to_i\nputs permute(n)"}, {"source_code": "n = gets.chomp.to_i\nif n > 1\n array = (1..n).to_a\n index = 0\n while index < n\n array[index], array[index + 1] = array[index + 1], array[index]\n index += 2\n end\n puts array.join(\" \")\nelse\n puts \"-1\"\nend\n"}, {"source_code": "n=gets.to_i\nif n==1 then\n\tputs -1\nelse\n\tputs (1..(n-1)).to_a.unshift(n)*\" \"\nend\n\n"}, {"source_code": "n=gets.to_i\nhalf=n/2\n\nif n==1 then\n\tputs '-1'\nelsif n==2\n\tputs '2 1'\nelse\n\thalf.downto(1){|i|\n\tprint i,' '\n\t}\n\t\n\t(n).downto(half+1){|i|\n\tprint i\n\tprint (if i!=(half+1) then\n\t\t' ' \n\telse\n\t\t\"\\n\"\n\tend)\n\t}\nend\n"}, {"source_code": "n=gets.to_i\nhalf=n/2\n\nif n==2\n\tputs '2 1'\nelsif n%2==0\n\thalf.downto(1){|i|\n\tprint i,' '\n\t}\n\t\n\t(n).downto(half+1){|i|\n\tprint i\n\tprint (if i!=(half+1) then\n\t\t' ' \n\telse\n\t\t\"\\n\"\n\tend)\n\t}\nelse\n\tputs '-1'\nend\n"}], "src_uid": "204ba74195a384c59fb1357bdd71e16c"} {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\n\nd1acc = 0\ncurrent = nil\nans = nil\na.each_with_index do |x, i|\n change, div = x\n if div == 1\n d1acc += change\n elsif div == 2\n ans = 'Impossible' if i > 0 && a[i - 1][1] == 1 && d1acc >= 0\n d1acc = 0\n current = 1899 unless current\n end\n if current\n current += change\n if current < 1900 && i < n - 1 && a[i + 1][1] == 1\n current = 1900\n elsif current >= 1900 && i < n - 1 && a[i + 1][1] == 2\n current = 1899\n end\n end\nend\nif current\n try = current\n a.reverse.each do |change, div|\n try -= change\n ans = 'Impossible' if try < 1900 && div != 2 || try >= 1900 && div != 1\n end\nelse\n ans = 'Infinity'\nend\nputs ans || current\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\nma=Float::INFINITY\nmi=-ma\ns=0\ngets.to_i.times{\n\tc,d=gets.split.map &:to_i\n\tif d==1\n\t\tmi=[mi,1900-s].max\n\telse\n\t\tma=[ma,1899-s].min\n\tend\n\ts+=c\n}\nputs ma==Float::INFINITY ? :Infinity : ma>=mi ? ma+s : :Impossible"}, {"source_code": "def solve(a)\n current = nil\n a.each do |change, div|\n current ||= 1899 if div == 2\n if current\n current = 1900 if div == 1 && current < 1900\n current = 1899 if div == 2 && current >= 1900\n current += change\n end\n end\n\n if current\n a.reverse_each.inject(current) do |try, (change, div)|\n try -= change\n return 'Impossible' if div == 1 && try < 1900 || div == 2 && try >= 1900\n try\n end\n else\n return 'Infinity'\n end\n\n return current\nend\n\nn = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\n\nputs solve(a)\n"}], "negative_code": [], "src_uid": "2a4c24341231cabad6021697f15d953a"} {"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n,r = gets.chomp.split.map(&:to_i)\n if n > r\n num = r\n puts num * (num+1) / 2\n else\n num = n - 1\n puts num * (num+1) / 2 + 1\n end\nend\n#######\n", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n\tn, r = gets.split.map &:to_i\n\tx = 0\n\tk = [r, n-1].min\n\tx += [0, (k+1)*k/2].max\n\tx += 1 if r >= n\n\tp x\nend\n"}, {"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n,r = gets.chomp.split.map(&:to_i)\n if n > r\n num = r\n puts num * (num+1) / 2\n else\n num = n - 1\n puts num * (num+1) / 2 + 1\n end\nend\n#####\n"}, {"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n,r = gets.chomp.split.map(&:to_i)\n if n > r\n num = r\n puts num * (num+1) / 2\n else\n num = n - 1\n puts num * (num+1) / 2 + 1\n end\nend\n####\n"}, {"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n,r = gets.chomp.split.map(&:to_i)\n if n > r\n num = r\n puts num * (num+1) / 2\n else\n num = n - 1\n puts num * (num+1) / 2 + 1\n end\nend\n"}, {"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n,r = gets.chomp.split.map(&:to_i)\n if n > r\n num = r\n puts num * (num+1) / 2\n else\n num = n - 1\n puts num * (num+1) / 2 + 1\n end\nend\n##\n"}, {"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n,r = gets.chomp.split.map(&:to_i)\n if n > r\n num = r\n puts num * (num+1) / 2\n else\n num = n - 1\n puts num * (num+1) / 2 + 1\n end\nend\n#\n"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n n, r = gets.chomp.split(\" \").map(&:to_i)\n if n > r\n ans = r * (1 + r) \n puts ans / 2\n elsif n <= r\n ans = (n-1) * n\n puts ans / 2 + 1\n end\nend"}, {"source_code": "# this code is just to observe speed\nt = gets.chomp.to_i\na = Array.new(t)\nfor i in 0..t-1 do\n n,r = gets.chomp.split.map(&:to_i)\n if n > r\n num = r\n a[i] = num * (num+1) / 2\n else\n num = n - 1\n a[i] = num * (num+1) / 2 + 1\n end\nend\n\nputs a.join(\"\\n\")"}], "negative_code": [], "src_uid": "eb3d8259ca598c3c455ddfdbe433cb78"} {"source_code": "s = STDIN.readline.strip\n\ndef fail\n puts -1\n exit\nend\n\nresult = []\nsum = 0\ns.each_char do |ch|\n if ch == '('\n sum += 1\n elsif ch == ')'\n sum -= 1\n fail if sum < 0\n else\n result.push(1)\n sum -= 1\n fail if sum < 0\n end\nend\nresult[-1] += sum\n\npos = s.index('(', s.rindex('#'))\nif pos != nil\n tail_sum = 0\n s[pos..-1].each_char do |ch|\n if ch == '('\n tail_sum += 1\n else\n tail_sum -= 1\n end\n end\n fail if tail_sum > 0\nend\n\nputs result.join(\"\\n\")\n", "positive_code": [{"source_code": "def solve(s)\n to = s.count {|c| c == '('}\n tc = s.count {|c| c == ')'}\n tp = s.count {|c| c == '#'}\n co = 0\n cc = 0\n cp = 0\n res = []\n i = 0\n r = tc\n s.each do |c|\n if c == '#'\n cp += 1\n if cp < tp\n res << 1\n cc += 1\n else\n if cc >= to\n return nil\n end\n diff = to - cc - r\n return nil if diff == 0\n res << diff\n cc += diff\n end\n elsif c == '('\n co += 1\n elsif c == ')'\n cc += 1\n r -= 1\n end\n if cc > co\n #puts \"#{i}: #{co} #{cc}\"\n return nil\n end\n i += 1\n end\n return res\nend\ns = STDIN.gets.chomp.split(//)\nres = solve(s)\nif not res\n puts \"-1\"\nelse\n res.each do |r|\n puts r\n end\nend\n"}], "negative_code": [], "src_uid": "0a30830361b26838b192d7de1efcdd2f"} {"source_code": "# Consider an example:\r\n# a = 5\r\n# Then the values from 0 to ... are:\r\n# 0 1 2 3 4 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7\r\n# And so, if we are looking for the maximum, we should only consider:\r\n# (1) Within each group, the farthest value to the right in the group that is\r\n# available in the range l .. r\r\n# (2) The last two groups.\r\n# The reason for (2) is that, if a number is not in the last two groups, then\r\n# it must be small than the last item in the second-to-last group.\r\n# The last group might not be complete, which is why we need to check the second-\r\n# to-last group as well.\r\n# Answer is either :\r\n# - Largest number in set (last item in last group) OR\r\n# - Largest number i such that i % a = a - 1. The mod of this is higher than the first choice.\r\n#\r\n# It's sufficient to check these two numbers:\r\n# r\r\n# r / a * a - 1, but only if it's in the range l .. r\r\n#\r\n\r\ngets.to_i.times do\r\n l,r,a = gets.split.map { |i| i.to_i }\r\n\r\n f = lambda {|i| i / a + i % a }\r\n last_of_second_last = r / a * a - 1\r\n if last_of_second_last.between?(l, r) then\r\n best = [f.call(r), f.call(last_of_second_last)].max\r\n else\r\n best = f.call(r)\r\n end\r\n puts(best)\r\nend\r\n\r\n", "positive_code": [{"source_code": "n = STDIN.gets.chomp.to_i\r\nn.times.each do\r\n l,r,a = STDIN.gets.chomp.split(\" \").map(&:to_i)\r\n puts [r/a+r%a,(r-r%a-1)/a+(r-r%a-1)%a].max if r-r%a-1>=l\r\n puts r/a+r%a if r-r%a-1 f(y,a)}.drop(1).sort!\r\n #puts(\" xxx #{func} xxx\")\r\n fl=f(l,a)\r\n fm=f(m,a)\r\n fr=f(r,a)\r\n\r\n if fm>fl\r\n return process(m,r,a)\r\n elsif fm>fr\r\n return process(l,m,a)\r\n elsif fl>fr\r\n return process(l,m,a)\r\n else\r\n return process(m,r,a)\r\n\r\n end\r\n\r\n\r\n #if f(m,a)>=f(l,a)\r\n#\r\n # return process(m,r,a)\r\n #elsif f(m,a)>=f(r,a)\r\n#\r\n # return process(l,m,a)\r\n #else\r\n # return process(m,r,a)\r\n #end\r\nend\r\n\r\nn = STDIN.gets.chomp.to_i\r\nn.times.each do\r\n l,r,a = STDIN.gets.chomp.split(\" \").map(&:to_i)\r\n #puts \"#### #{l} #{r} #{a} ####\"\r\n puts(\"#{process(l,r,a)}\")\r\nend\r\n\r\n\r\n\r\n#n = STDIN.gets.chomp.to_i\r\n#n.times.each do\r\n# l,r,a = STDIN.gets.chomp.split(\" \").map(&:to_i)\r\n#\r\n# puts ([r-(r%a)-1,l].max ... r+1).to_a.map { |value| (value/a) + value%a }.max\r\n#end\r\n\r\n#352038877 421606206 705339697\r\n#\r\n#l=352038877\r\n#r=421606206\r\n#a=705339697\r\n#\r\n#puts([r-a-1,l].max ... r+1)\r\n#puts(\"count : #{([r-a-1,l].max ... r+1).count}\\n\")\r\n#puts( \"r%a : #{r%a}\")\r\n#\r\n#([r-(r%a)-1,l].max ... r+1).to_a.each { |x|\r\n# puts \"#{x}/#{a} + #{x}%#{a} #{x/a} #{x%a} = #{x/a+x%a}\"\r\n#}\r\n#\r\n\r\n\r\n#r-(r/a)-1\r\n#12-(1)-1\r\n#a=8\r\n#l=0\r\n#(1...12).to_a.each do |i|\r\n# x=l+i\r\n#\r\n# puts \"#{x}/#{a} + #{x}%#{a} #{x/a} #{x%a} = #{x/a+x%a}\"\r\n#end\r\n#\r\n#a=10\r\n#l=90\r\n#r=110\r\n#x=r\r\n#while x % a != a-1 and x >= l\r\n# x-=1\r\n#end\r\n#puts x\r\n\r\n\r\n\r\n\r\n#l=5\r\n#r=8\r\n#a=4\r\n##x=r\r\n#puts ([r-(r/a),l].max ... r+1).to_a.map { |value| (value/a) + value%a }.max\r\n\r\n# l 5\r\n# r 8\r\n# a 4\r\n# x 7\r\n#\r\n# 4 = 7/4 + 7%4\r\n#\r\n# 10/2 + 10%2 5 0 = 0\r\n# 11/2 + 11%2 5 1 = 1\r\n#\r\n#\r\n#\r\n#\r\n# x/a + x%a = Y"}, {"source_code": "def f(x,a)\r\n return(x/a + x % a)\r\nend\r\n\r\ndef process(l, r, a)\r\n\r\n return [f(l, a),f(r,a)].max if r-l<=1\r\n m = (l + r ) / 2\r\n\r\n if f(m,a)>=f(l,a)\r\n\r\n return process(m,r,a)\r\n elsif f(m,a)>=f(r,a)\r\n\r\n return process(l,m,a)\r\n else\r\n return process(m,r,a)\r\n end\r\nend\r\n\r\nn = STDIN.gets.chomp.to_i\r\nn.times.each do\r\n l,r,a = STDIN.gets.chomp.split(\" \").map(&:to_i)\r\n\r\n puts(process(l,r,a))\r\nend"}, {"source_code": "n = STDIN.gets.chomp.to_i\r\nn.times.each do\r\n l,r,a = STDIN.gets.chomp.split(\" \").map(&:to_i)\r\n puts ([a-l-1,l].max ... r+1).map { |value| (value/a) + value%a }.max\r\nend\r\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\r\nn.times.each do\r\n l,r,a = STDIN.gets.chomp.split(\" \").map(&:to_i)\r\n puts (a-l ... r+1).map { |value| (value/a) + value%a }.max\r\nend\r\n\r\n"}], "src_uid": "681ee82880ddd0de907aac2ccad8fc04"} {"source_code": "n = gets.to_i\na = []\n\ndef find_ans(arr)\n i = 1\n j = i + 1\n while arr[i] + arr[j] != arr.last - arr[0]\n if j == i + 1\n j += 1\n else\n i += 1\n end\n end\n [arr[0], arr[i], arr[j]]\nend\n \n(0..n-1).each do |x|\n\tq = gets.chomp.split().map { |e| e.to_i }\n p\n\ta.append(find_ans(q))\nend\n \n \na.each do |x|\n puts x.join(' ')\nend", "positive_code": [{"source_code": "t = gets.to_i\r\nans = []\r\nt.times do\r\n b = gets.split.map(&:to_i)\r\n a = [b[0],b[1]]\r\n if b[0]+b[1] == b[2]\r\n a << b[3]\r\n else\r\n a << b[2]\r\n end\r\n ans << a\r\nend\r\nans.each do |arr|\r\n puts arr.join(\" \")\r\nend"}, {"source_code": "testcases = Integer(gets.chomp)\r\nresultados = []\r\n\r\nfor i in 0..testcases-1\r\n arreglo = gets.chomp\r\n b = arreglo.split(\" \")\r\n numeroAConstruir = b[6].to_i\r\n validar = true\r\n finalPrincipal = false\r\n aumentoPrincipal = 0\r\n finalSecundario = false\r\n aumentoSecundario = 1\r\n finalTerceario = false\r\n aumentoTercerario = 2\r\n while validar\r\n if finalTerceario\r\n finalTerceario = false\r\n aumentoSecundario+=1\r\n if aumentoSecundario == 5\r\n finalSecundario = true\r\n end\r\n aumentoTercerario = aumentoSecundario + 1\r\n end\r\n if finalSecundario\r\n finalSecundario = false\r\n aumentoPrincipal += 1\r\n aumentoSecundario = aumentoPrincipal + 1\r\n aumentoTercerario = aumentoSecundario + 1\r\n end\r\n b1 = b[aumentoPrincipal].to_i\r\n b2 = b[aumentoSecundario].to_i\r\n b3 = b[aumentoTercerario].to_i\r\n if b1+b2+b3 == numeroAConstruir\r\n resultados.push(b1.to_s+\" \"+b2.to_s+\" \"+b3.to_s)\r\n break\r\n end \r\n aumentoTercerario +=1\r\n if aumentoTercerario == 6\r\n finalTerceario = true\r\n end\r\n end\r\nend\r\nputs resultados"}], "negative_code": [{"source_code": "n = gets.to_i\na = []\n\ndef find_ans(arr)\n i = 1\n j = i + 1\n while arr[i] + arr[j] != arr.last - arr[0]\n if j == i + 1\n j += 1\n else\n i += 1\n end\n end\n [arr[0], arr[i], arr[j]]\nend\n \n(0..n-1).each do |x|\n\tq = gets.chomp.split().map { |e| e.to_i }\n p\n\ta.append(find_ans(q))\nend\n \n \na.each do |x|\n p x.map(&:inspect).join(' ')\nend"}, {"source_code": "n = gets.to_i\na = []\n\ndef find_ans(arr)\n i = 1\n j = i + 1\n while arr[i] + arr[j] != arr.last - arr[0]\n if j == i + 1\n j += 1\n else\n i += 1\n end\n end\n [arr[0], arr[i], arr[j]]\nend\n \n(0..n-1).each do |x|\n\tq = gets.chomp.split().map { |e| e.to_i }\n p\n\ta.append(find_ans(q))\nend\n \n \na.each do |x|\n p x\nend"}], "src_uid": "e0ec0cd81d2ec632ef89d207d80fa8a3"} {"source_code": "\nn = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\nmbits = gets.chomp\n\nlength = mbits.length\nmax = 0\nlength.times.each do |i|\n max += a[i] if mbits[i] == '1'\nend\n\ndefault = max\nsub_sum = 0\ni = 0\nwhile i < n do\n if mbits[i] == '1'\n last_sum = default + sub_sum - a[i]\n max = last_sum if last_sum > max\n else\n sub_sum += a[i]\n end\n i += 1\n \nend\n\nputs max\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\nb = gets.chomp.split(\"\").map{|i| i.to_i}\n\nS = []\nT = []\ns = 0\nS[0] = a[0]\n(1..n-1).each do |i|\n S[i] = S[i-1] + a[i]\nend\n\nmax = 0\nj = n-1\nT[n] = 0\nwhile j>= 0 do\n if b[j] == 0\n T[j] = T[j+1]\n else\n T[j] = T[j+1] + a[j]\n end\n j -= 1\nend\n\nmax = T[0]\n\n(1..n-1).each do |i|\n if b[i] == 1\n s = S[i-1] + T[i+1] \n end\n if s > max \n max = s\n end\nend\n\nputs max"}], "negative_code": [], "src_uid": "9366e1626b33b4f4e49cf35200c0448f"} {"source_code": "array = gets.split(\" \")\nn = array.shift\nbig_max = -999999999999999999999\nshuzu = gets.split(\" \")\nsum=[]\nsum[0] = -9999999999999999999999\nfor i in 0..n.to_i-1 do\n sum[i] = sum[i-1] if i>0\n temp = array[0].to_i*shuzu[i].to_i\n if temp > sum[i]\n sum[i] = temp;\n end\nend\n\nsum2 = []\nsum2[0] = -9999999999999999999999\nfor i in 0..n.to_i-1 do\n sum2[i] = sum2[i-1] if i>0\n temp = sum[i]+array[1].to_i*shuzu[i].to_i\n if temp > sum2[i]\n sum2[i] = temp;\n end\nend\n\n#p sum\n#p sum2\nfor i in 0..n.to_i-1\n max = sum2[i]+array[2].to_i*shuzu[i].to_i\n big_max=max if max>big_max\nend\nprint big_max\n\n", "positive_code": [{"source_code": "n, p, q, r = gets.split.map{|x| x.to_i}\narr = gets.split.map{|x| x.to_i}\n\nINF = 9 * 10**18\n\ndp = [[-INF, -INF, -INF]]\n\nn.times do |i|\n\tdp << [0, 0, 0]\n\tdp[i + 1][0] = [dp[i][0], p * arr[i]].max\n\tdp[i + 1][1] = [dp[i][1], dp[i + 1][0] + q * arr[i]].max\n\tdp[i + 1][2] = [dp[i][2], dp[i + 1][1] + r * arr[i]].max\nend\n\nans = -INF\nn.times{|i| ans = [ans, dp[i + 1][2]].max}\n\np ans"}], "negative_code": [{"source_code": "n, p, q, r = gets.split.map{|x| x.to_i}\narr = gets.split.map{|x| x.to_i}\n\nminus = arr.min\nplus = arr.max\n\np p * (p < 0 ? minus : plus) + q * (q < 0 ? minus : plus) + r * (r < 0 ? minus : plus)"}, {"source_code": "n, p, q, r = gets.split.map{|x| x.to_i}\narr = gets.split.map{|x| x.to_i}\n\nINF = 10**18\n\ndp = [[-INF, -INF, -INF]]\n\nn.times do |i|\n\tdp << [0, 0, 0]\n\tdp[i + 1][0] = [dp[i][0], p * arr[i]].max\n\tdp[i + 1][1] = [dp[i][1], dp[i + 1][0] + q * arr[i]].max\n\tdp[i + 1][2] = [dp[i][2], dp[i + 1][1] + r * arr[i]].max\nend\n\nans = -INF\nn.times{|i| ans = [ans, dp[i + 1][2]].max}\n\np ans"}, {"source_code": "array = gets.split(\" \")\nn = array.shift\nbig_max = -9999999999999999999\nshuzu = gets.split(\" \")\nsum=[]\nsum[0] = -9999999999999999999\nfor i in 0..n.to_i-1 do\n sum[i] = sum[i-1] if i>0\n temp = array[0].to_i*shuzu[i].to_i\n if temp > sum[i]\n sum[i] = temp;\n end\nend\n\nsum2 = []\nsum2[0] = -9999999999999999999\nfor i in 0..n.to_i-1 do\n sum2[i] = sum2[i-1] if i>0\n temp = sum[i]+array[1].to_i*shuzu[i].to_i\n if temp > sum2[i]\n sum2[i] = temp;\n end\nend\n\np sum\np sum2\nfor i in 0..n.to_i-1\n max = sum2[i]+array[2].to_i*shuzu[i].to_i\n big_max=max if max>big_max\nend\nprint big_max\n\n"}], "src_uid": "a8e56ad4de6f0eecbe5521226c0335ab"} {"source_code": "def icpc_baloons(str, n)\n map = {}\n str.chars.each do |s|\n if map.key?(s)\n map[s] += 1\n else\n map[s] = 2\n end\n end\n ans = 0\n\n map.each do |k, v|\n ans += v\n end\n ans\nend\nt = gets.chomp.to_i\ninputs = []\n(0..t-1).each do\n n = gets.chomp.to_i\n str = gets.chomp\n inputs.push([str, n])\nend\n\ninputs.each do |input|\n puts icpc_baloons(input[0], input[1])\nend\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\nnumtests = gets.chomp.to_i\n\n(1..numtests).each do |numline|\n ballons = 0\n solved = []\n n = gets.chomp.to_i\n l = gets.chomp\n (0..n-1).each do |i|\n c = l[i]\n if solved.include?(c)\n ballons += 1\n else\n ballons += 2\n solved << c\n end\n end\n puts ballons\nend\n\n\n"}, {"source_code": "require 'set'\n\nt = gets.to_i\n\nt.times do\n gets\n ln = gets.chomp\n s = Set.new\n b = 0\n ln.each_char do |c|\n b += 1 if not s.include? c\n s << c\n b += 1\n end\n puts b\nend\n"}], "negative_code": [], "src_uid": "66777b8719b1756bf4b6bf93feb2e439"} {"source_code": "a=c=0\ngets.chomp.reverse.bytes.to_a[0..-2].map{|n|a+=(n+c==48?1:n+c==49?(c=1;2):1)}\np a+c\n", "positive_code": [{"source_code": "#=================================\nrequire 'prime'\nrequire 'set'\nrequire 'matrix'\nrequire 'tsort'\ninclude Math\n\ndef local?;\tENV[\"LOGNAME\"]==\"skydos\"; end\n\nif local?\n\t$stdin = File.open(\"./input.txt\", \"r\")\nend\n#=================================\n\n#=================================\nif local?\n\tstart_time = Time.now\nend\n#=================================\n\nb=gets.chomp.split(//).map(&:to_i)\n\ni=b.size-1\ncount=0\n\nwhile i>=1\n\tcount+=1\n\t\n\tif b[i]==0\n\t\ti-=1\n\telse\n\t\tcount+=1\n\t\ti-=1\n\t\twhile i>=0 && b[i]==1\n\t\t\tcount+=1\n\t\t\ti-=1\n\t\tend\n\t\t\n\t\tb[i]=1 if i>=0\n\tend\nend\n\nputs count\n\n#=================================\nif local?\n\tend_time = Time.now\n\tputs \"\\n\\n\"\n\tputs \"===\"*10\n\tprintf \"Time: %.4f sec\\n\", (end_time-start_time)/1000.0\n\tputs \"===\"*10\nend\n#=================================\n"}, {"source_code": "a=c=0\ngets.chomp.reverse.bytes.to_a[0..-2].map{|n|a+=(n+c==48?1:n+c==49?(c=1;2):1)}\np a+c\n"}, {"source_code": "a=c=0\ngets.chomp.reverse.bytes.to_a[0..-2].map{|n|a+=(n+c==48?1:n+c==49?(c=1;2):1)}\np a+c"}, {"source_code": "a=c=0\ngets.chomp.reverse.bytes.to_a[0..-2].map{|n|a+=(n+c==48?1:n+c==49?(c=1;2):1)}\np a+c\n"}, {"source_code": "n=gets.split[0]\nn=n.bytes.to_a\nk=0\nl=n.length\nans=0\n(l-1).downto(0){|i|\n if i==0 && k==0 then\n ans+=1\n else\n if n[i]+k==49 then\n ans+=1\n k=1\n elsif n[i]+k==50 then\n k=1\n else\n k=0\n end\n ans+=1\n end \n}\nans+=k\nputs ans-1\n\n"}, {"source_code": "a=c=0\ngets.chomp.reverse.bytes.to_a[0..-2].map{|n|a+=(n+c==48?1:n+c==49?(c=1;2):1)}\np a+c\n"}, {"source_code": "a=c=0\ngets.chomp.reverse.bytes.to_a[0..-2].map{|n|a+=(n+c==48?1:n+c==49?(c=1;2):1)}\np a+c"}, {"source_code": "a=c=0\ngets.chomp.reverse.bytes.to_a[0..-2].map{|n|a+=(n+c==48?1:n+c==49?(c=1;2):1)}\np a+c\n"}, {"source_code": "a=c=0\ngets.chomp.reverse.bytes.to_a[0..-2].map{|n|a+=(n+c==48?1:n+c==49?(c=1;2):1)}\np a+c"}], "negative_code": [{"source_code": "n=gets.split[0]\nn=n.bytes.to_a\nk=0\nl=n.length\nans=0\n(l-1).downto(0){|i|\n if i==0 && k==0 then\n ans+=1;k=1\n else\n if n[i]+k==49 then\n ans+=1\n k=1\n elsif n[i]+k==50 then\n k=1\n else\n k=0\n end\n ans+=1\n end \n}\nans+=k\nputs ans-1\n\n"}, {"source_code": "#=================================\nrequire 'prime'\nrequire 'set'\nrequire 'matrix'\nrequire 'tsort'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nb=gets.strip\n\nif b.length==1 && b==\"1\"\n\tputs 0\n\texit\nend\n\nans=count=0\n\nloop do\t\n\tif b[-1]==\"1\"\n\t\tcount+=1\n\t\ti=b.length-1\n\t\t\n\t\twhile b[i]==\"1\"\n\t\t\tb[i]=\"0\"\n\t\t\ti-=1\n\t\t\tcount+=1\n\t\tend\n\t\t\n\t\tb[i]=\"1\" if i>=0\n\t\tb=b[0..i]\n\telse\n\t\ti=b.length-1\n\t\t\n\t\twhile b[i]==\"0\"\n\t\t\tcount+=1\n\t\t\ti-=1\n\t\tend\n\t\t\n\t\tb=b[0..i]\n\tend\n\t\n\tans=count if b.length!=0\n\tbreak if b.length==0\nend\n\nputs ans\n"}, {"source_code": "#=================================\nrequire 'prime'\nrequire 'set'\nrequire 'matrix'\nrequire 'tsort'\ninclude Math\n\ndef local?;\tENV[\"LOGNAME\"]==\"skydos\"; end\n\nif local?\n\t$stdin = File.open(\"./input.txt\", \"r\")\nend\n#=================================\n\n#=================================\nif local?\n\tstart_time = Time.now\nend\n#=================================\n\nb=gets.strip\n\nif b==\"1\"\n\tputs 0\n\texit\nend\n\ni=b.length-1\ncount=0\n\nwhile i>-1\t\n\tif b[i]==\"0\"\n\t\tcount+=1\n\t\ti-=1\n\telse\n\t\tcount+=1\n\t\twhile i>-1 && b[i]==\"1\"\n\t\t\tcount+=1\n\t\t\ti-=1\n\t\tend\n\t\t\n\t\tb[i]=\"1\" if i>-1\n\tend\nend\n\nputs count\n\n#=================================\nif local?\n\tend_time = Time.now\n\tputs \"\\n\\n\"\n\tputs \"===\"*10\n\tprintf \"Time: %.4f sec\\n\", (end_time-start_time)/100.0\n\tputs \"===\"*10\nend\n#=================================\n"}, {"source_code": "#=================================\nrequire 'prime'\nrequire 'set'\nrequire 'matrix'\nrequire 'tsort'\ninclude Math\n\ndef local?;\tENV[\"LOGNAME\"]==\"skydos\"; end\n\nif local?\n\t$stdin = File.open(\"./input.txt\", \"r\")\nend\n#=================================\n\n#=================================\nif local?\n\tstart_time = Time.now\nend\n#=================================\n\nb=gets.strip\n\ni=b.length-1\ncount=0\n\nwhile i>-1\t\n\tif b[i]==\"0\"\n\t\tcount+=1\n\t\ti-=1\n\telse\n\t\tcount+=1\n\t\twhile i>-1 && b[i]==\"1\"\n\t\t\tcount+=1\n\t\t\ti-=1\n\t\tend\n\t\t\n\t\tb[i]=\"1\" if i>-1\n\tend\nend\n\nputs count\n\n#=================================\nif local?\n\tend_time = Time.now\n\tputs \"\\n\\n\"\n\tputs \"===\"*10\n\tprintf \"Time: %.4f sec\\n\", (end_time-start_time)/100.0\n\tputs \"===\"*10\nend\n#=================================\n"}], "src_uid": "e46c6406d19e8679fd282d72882ae78d"} {"source_code": "n,vb,vs=gets.split.map &:to_i;z=[1e9,1e9,0];\na=gets.split.map &:to_f;x,y=gets.split.map &:to_i\n1.upto(n-1){|i|d=((x-a[i])**2+y**2)**0.5;z=[[d/vs+a[i]/vb,d,i],z].min}\np z[2]+1", "positive_code": [{"source_code": "n, vb, vs = gets.split(/\\s+/).map{|x| x.to_i}\nx = gets.split(/\\s+/).map{|x| x.to_i}\nxu, yu = gets.split(/\\s+/).map{|x| x.to_i}\n\nres = 0\nrest = 0.0\nresd = 0.0\n(1...n).each {|i|\n dx = (x[i] - xu).to_f\n dy = (0 - yu).to_f\n d = Math.sqrt(dx * dx + dy * dy)\n t = x[i].to_f / vb + d / vs\n if res == 0 || t < rest || (t == rest && d < resd) then\n res = i\n rest = t\n resd = d\n end \n}\np res + 1\n"}, {"source_code": "#\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd: 2???n? ??100, 1???vb,?vs? ??1000. \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd n \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n#: \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd xi \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd i. \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd, \ufffd\ufffd\ufffd x1 \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd, \ufffd xn? ??105. \n#\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd, \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd xu \ufffd yu, \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd 105.\n\n\nn, vb, vs = gets.split(' ').map{|z|z.to_i}\ncrd = gets.split(' ').map{|z|z.to_i}\nxu,yu = gets.split(' ').map{|z|z.to_i}\n\nmin = 105000000\nru = 105000000\nres=0\ncrd[1..-1].each_with_index{|xi,i| \n mru = (xu-xi)*(xu-xi)+yu*yu\n d = (Math.sqrt(xi*xi)*vs+Math.sqrt(mru)*vb)\n if (d < min)||((d==min)&&(mru < ru)) then\n min = d\n res = i+1\n ru = mru\n end\n}\n\nputs res+1"}, {"source_code": "n,vb,vs=gets.split.map &:to_i;z=[1e9,1e9,0];\na=gets.split.map &:to_f;x,y=gets.split.map &:to_i\n1.upto(n-1){|i|d=((x-a[i])**2+y**2)**0.5;z=[[d/vs+a[i]/vb,d,i],z].min}\np z[2]+1"}, {"source_code": "n,vb,vs=gets.split.map &:to_i;z=[1e9,1e9,0];\na=gets.split.map &:to_f;x,y=gets.split.map &:to_i\n1.upto(n-1){|i|d=((x-a[i])**2+y**2)**0.5;z=[[d/vs+a[i]/vb,d,i],z].min}\np z[2]+1\n"}, {"source_code": "n,vb,vs=gets.split.map &:to_i;z=[1e9,1e9,0];\na=gets.split.map &:to_f;x,y=gets.split.map &:to_i\n1.upto(n-1){|i|d=((x-a[i])**2+y**2)**0.5;z=[[d/vs+a[i]/vb,d,i],z].min}\np z[2]+1\n"}, {"source_code": "n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nxu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nmint = 0\nmind = 0\nidx = 0\nfor i in 1..n-1\n\twk = (ar[i]-xu).abs\n\twkt = ar[i].to_f/vb+Math.sqrt(wk*wk + yu*yu)/vs\n\tif idx == 0 || mint > wkt\n\t\tmint = wkt\n\t\tmind = wk\n\t\tidx = i+1\n\telsif mint == wkt\n\t\tif mind > wk\n\t\t\tmint = wkt\n\t\t\tmind = wk\n\t\t\tidx = i+1\n\t\tend\n\tend\nend\nputs idx\n"}, {"source_code": "n, vb, vs = gets.split.map{|i| i.to_f}\nx = gets.split.map{|i| i.to_i}\nxu, yu = gets.split.map{|i| i.to_i}\nans = [1e100, -1, -1]\n1.upto(x.length - 1) do |i|\n\td = (xu - x[i]) ** 2 + yu ** 2\n\tt = x[i] / vb + Math.sqrt(d) / vs\n\tans = [t, d, i] if t < ans[0] - 1e-6 || (t < ans[0] + 1e-6 && d < ans[1])\nend\np ans[2] + 1\n\n#\n"}, {"source_code": "n,vb,vs=STDIN.gets.chomp.split\nxn=STDIN.gets.chomp.split\nxu,yu=STDIN.gets.chomp.split\nn=n.to_i\nvb=vb.to_i\nvs=vs.to_i\nxu=xu.to_i\nyu=yu.to_i\nfor i in 0...xn.length do xn[i]=xn[i].to_i end\nidx=0\nmin_t=-1\nmin_u=-1\nfor i in 1...xn.length\n d=Math::sqrt((xu-xn[i])*(xu-xn[i])+yu*yu)\n t=1.0*(xn[i]-xn[1])/vb\n t+=1.0*d/vs\n if min_t==-1\n min_t=t\n min_u=d\n idx=i\n elsif ttemp_t\n t=temp_t\n bu = l\n res = i+2\n elsif t==temp_t\n if bu>l\n t=temp_t\n bu = l\n res = i+2\n end\n end\nend\nputs res\n"}, {"source_code": "n,vb,vs=gets.split.map &:to_i;z=[1e9,1e9,0];\na=gets.split.map &:to_f;x,y=gets.split.map &:to_i\n1.upto(n-1){|i|d=((x-a[i])**2+y**2)**0.5;z=[[d/vs+a[i]/vb,d,i],z].min}\np z[2]+1\n"}, {"source_code": "def dist(x1,y1,x2,y2)\n\tMath.sqrt(((x2-x1)**2) + ((y2-y1)**2))\nend\n\nn,v_b,v_s = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\nuniv_x,univ_y = gets.split(\" \").map(&:to_i)\n\nans = {}\n\narr[1..-1].each_with_index do |a,i|\n\tbus_time = a/v_b.to_f\n\t# puts \"h33 #{bus_time}\"\n\twalk_time = (dist(univ_x,univ_y,a,0))/v_s\n\t# puts \"#{[bus_time + walk_time,walk_time]}\"\n\tans[[bus_time + walk_time,walk_time]] = i\n\nend\n# puts \"#{ans}\"\n\nkey = ans.keys.min\n\nputs \"#{ans[key]+2}\""}, {"source_code": "#$stdin = File.open('in.txt', 'r')\n@n,@vb,@vs = gets.split(/\\s+/).map {|x| x.to_i}\n@stopes = gets.split(/\\s+/).map {|x| x.to_i}\n@xu,@yu = gets.split(/\\s+/).map {|x| x.to_i}\n\n@stopes.unshift(0)\n# a = 2\n# b = @n\n# \ndef compute(index)\n @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs\nend\n\nif @vs > @vb\n puts 2\nelse\n kms = @stopes[2].abs\n x = @stopes[2]\n answer = 2\n min = kms/@vb.to_f + Math.sqrt(@yu*@yu+(x-@xu)*(x-@xu))/@vs\n \n i = 3\n# puts \"#{answer} #{min} #{compute(2)}\"\n\n while i <= @n\n kms += (@stopes[i-1].abs-@stopes[i].abs).abs\n x = @stopes[i]\n val = kms/@vb.to_f + Math.sqrt(@yu*@yu+(x-@xu)*(x-@xu))/@vs\n\n if val < min\n answer = i\n min = val\n elsif (val == min) && ((@stopes[answer]-@xu).abs > (@stopes[i]-@xu).abs)\n answer = i\n end\n i += 1\n end\n puts answer\nend\n# av = compute(a)\n# bv = compute(b)\n# \n# while b > a\n# # puts \"a #{a} #{av}\"\n# # puts \"b #{b} #{bv}\"\n# if bv > av\n# b = ((b+a) / 2)\n# bv = compute(b)\n# else\n# a = ((b+a) / 2) + 1\n# av = compute(a)\n# end\n# end\n# #puts \"#{a} #{b}\"\n# # if (b-a) == 1\n# # mv = compute(a+1)\n# # if mv < av\n# # a += 1\n# # av = mv\n# # end\n# # end\n# #puts \"#{av} #{bv}\"\n# if av > bv\n# puts b\n# else #if bv > av\n# puts a \n# # else\n# # av = (@stopes[a]-@xu).abs\n# # bv = (@stopes[b]-@xu).abs\n# # puts bv > av ? a : b\n# end\n# \n"}], "negative_code": [{"source_code": "n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nxu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nmind = 0\nidx = 0\nfor i in 0..n-1\n\twk = (ar[i]-xu).abs\n\tif idx == 0 || mind > wk\n\t\tmind = wk\n\t\tidx = i+1\n\tend\nend\nputs idx\n"}, {"source_code": "n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nxu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nmint = 0\nidx = 0\nfor i in 1..n-1\n\twk = (ar[i]-xu).abs\n\twkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs\n\tif idx == 0 || mint >= wkt\n\t\tmint = wkt\n\t\tmind = wk\n\t\tidx = i+1\n\tend\nend\nputs idx\n"}, {"source_code": "n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nxu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nmind = 0\nidx = 0\nfor i in 0..n-1\n\twk = (ar[i]-xu).abs\n\tif idx == 0 || mind > wk\n\t\tmind = wk\n\t\tidx = i+1\n\tend\nend\nputs idx\n"}, {"source_code": "n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nxu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nmind = 0\nidx = 0\nfor i in 0..n-1\n\twk = (ar[i]-xu).abs\n\tif idx == 0 || mind > wk\n\t\tmind = wk\n\t\tidx = i+1\n\tend\nend\nputs idx\n"}, {"source_code": "n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nxu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nmind = 0\nidx = 0\nfor i in 0..n-1\n\twk = (ar[i]-xu).abs\n\tif idx == 0 || mind > wk\n\t\tmind = wk\n\t\tidx = i+1\n\tend\nend\nputs idx\n"}, {"source_code": "n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nxu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nmint = 0\nidx = 0\nfor i in 1..n-1\n\twk = (ar[i]-xu).abs\n\twkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs\n\tif idx == 0 || mint + 1e-6 > wkt\n\t\tmint = wkt\n\t\tmind = wk\n\t\tidx = i+1\n\telsif (mint - wkt).abs < 1e-6\n\t\tif mind > wk\n\t\t\tmint = wkt\n\t\t\tmind = wk\n\t\t\tidx = i+1\n\t\tend\n\tend\nend\nputs idx\n"}, {"source_code": "n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nxu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nmint = 0\nmind = 0\nidx = 0\nfor i in 1..n-1\n\twk = (ar[i]-xu).abs\n\twkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs\n\tif idx == 0 || mint > wkt\n\t\tmint = wkt\n\t\tmind = wk\n\t\tidx = i+1\n\telsif mint == wkt\n\t\tif mind > wk\n\t\t\tmint = wkt\n\t\t\tmind = wk\n\t\t\tidx = i+1\n\t\tend\n\tend\nend\nputs idx\n"}, {"source_code": "n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nxu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nmint = 0\nidx = 0\nfor i in 1..n-1\n\twk = (ar[i]-xu).abs\n\twkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs\n\tif idx == 0 || mint > wkt\n\t\tmint = wkt\n\t\tmind = wk\n\t\tidx = i+1\n\telsif mint == wkt\n\t\tif mind > wk\n\t\t\tmint = wkt\n\t\t\tmind = wk\n\t\t\tidx = i+1\n\t\tend\n\tend\nend\nputs idx\n"}, {"source_code": "n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nxu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nmint = 0\nmind = 0\nidx = 0\nfor i in 1..n-1\n\twk = (ar[i]-xu).abs\n\twkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs\n\tif idx == 0 || mint > wkt\n\t\tmint = wkt\n\t\tmind = wk\n\t\tidx = i+1\n\tend\nend\nputs idx\n"}, {"source_code": "n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nxu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nmint = 0\nidx = 0\nfor i in 1..n-1\n\twk = (ar[i]-xu).abs\n\twkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs\n\tif idx == 0 || mint > wkt\n\t\tmint = wkt\n\t\tmind = wk\n\t\tidx = i+1\n\telsif (mint - wkt).abs < 1e-6\n\t\tif mind > wk\n\t\t\tmint = wkt\n\t\t\tmind = wk\n\t\t\tidx = i+1\n\t\tend\n\tend\nend\nputs idx\n"}, {"source_code": "n, vb, vs = gets.split.map{|i| i.to_f}\nx = gets.split.map{|i| i.to_i}\nxu, yu = gets.split.map{|i| i.to_i}\nans = [1e100, -1, -1]\n1.upto(x.length - 1) do |i|\n\td = (xu - x[i]) ** 2 + yu ** 2\n\tt = x[i] / vb + Math.sqrt(d) / vs\n\tans = [d, t, i] if t < ans[0] - 1e-8 || (t < ans[0] + 1e-8 && d < ans[1])\nend\np ans[2] + 1\n"}, {"source_code": "n, vb, vs = gets.split.map{|i| i.to_i}\nx = gets.split.map{|i| i.to_i}\nxu, yu = gets.split.map{|i| i.to_i}\nbest = 1e100\nans = -1\nx.each_index do |i|\n\ttemp = x[i] / vb + Math.sqrt(yu * yu + (xu - x[i]) * (xu - x[i])) / vs\n\tans, best = i, temp if temp < best\nend\np ans\n"}, {"source_code": "n, vb, vs = gets.split.map{|i| i.to_f}\nx = gets.split.map{|i| i.to_i}\nxu, yu = gets.split.map{|i| i.to_i}\nx = 1.upto(x.length - 1).map do |i|\n\td = (xu - x[i]) ** 2 + yu ** 2\n\tt = x[i] / vb + Math.sqrt(d) / vs\n\t[t, -d, i + 1]\nend\np x.min[2]\n"}, {"source_code": "n, vb, vs = gets.split.map{|i| i.to_i}\nx = gets.split.map{|i| i.to_i}\nxu, yu = gets.split.map{|i| i.to_i}\nbest = 1e100\nans = -1\n1.upto(x.length - 1) do |i|\n\ttemp = x[i] / vb + Math.sqrt((xu - x[i]) * (xu - x[i]) + yu * yu) / vs\n\tans, best = i, temp if temp <= best + 1e-8\nend\nprint ans + 1, \"\\n\"\n"}, {"source_code": "n, vb, vs = gets.split.map{|i| i.to_i}\nx = gets.split.map{|i| i.to_i}\nxu, yu = gets.split.map{|i| i.to_i}\nbest = 1e100\nans = -1\nx.each_index do |i|\n\ttemp = x[i] / vb + Math.sqrt(yu * yu + (xu - x[i]) * (xu - x[i])) / vs\n\tans, best = i, temp if temp < best\nend\nprint ans + 1, \"\\n\"\n"}, {"source_code": "n,vb,vs=STDIN.gets.chomp.split\nxn=STDIN.gets.chomp.split\nxu,yu=STDIN.gets.chomp.split\nn=n.to_i\nvb=vb.to_i\nvs=vs.to_i\nxu=xu.to_i\nyu=yu.to_i\nfor i in 0...xn.length do xn[i]=xn[i].to_i end\nxn<temp_t\n t=temp_t\n res = i+2\n end\nend\nputs res\n"}, {"source_code": "n,vb,vs=gets.split.map &:to_i\nz=[1e9,1e9,0];\na=gets.split.map &:to_i\nx,y=gets.split.map &:to_i\nn.times{|i|d=((x-a[i])**2+y**2)**0.5;z=[[d/vs+x[i]/vb,d,i],z].min}\nprint z[2]+1"}, {"source_code": "def dist(x1,y1,x2,y2)\n\tMath.sqrt(((x2-x1)**2) + ((y2-y1)**2))\nend\n\nn,v_b,v_s = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\nuniv_x,univ_y = gets.split(\" \").map(&:to_i)\n\nans = {}\n\narr[1..-1].each_with_index do |a,i|\n\tbus_time = a/v_b\n\twalk_time = (dist(univ_x,univ_y,a,0))/v_s\n\tans[[bus_time + walk_time,walk_time]] = i\nend\n# puts \"#{ans}\"\n\nkey = ans.keys.min\n\nputs \"#{ans[key]+2}\""}, {"source_code": "#$stdin = File.open('in.txt', 'r')\n@n,@vb,@vs = gets.split(/\\s+/).map {|x| x.to_i}\n@stopes = gets.split(/\\s+/).map {|x| x.to_i}\n@xu,@yu = gets.split(/\\s+/).map {|x| x.to_i}\n\n@stopes.unshift(0)\na = 2\nb = @n\n\n\ndef compute(index)\n @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs\nend\n\nav = compute(a)\nbv = compute(b)\n\nwhile b > a\n if av > bv\n a = ((b+a) / 2) + 1\n av = compute(a)\n else\n b = ((b+a) / 2)\n bv = compute(b)\n end\nend\n# if (b-a) == 1\n# mv = compute(a+1)\n# if mv < av\n# a += 1\n# av = mv\n# end\n# end\n#puts \"#{av} #{bv}\"\nif av > bv\n puts b\nelse bv > av\n puts a \n# else\n# puts a\n # av = (@stopes[a]-@xu).abs\n # bv = (@stopes[b]-@xu).abs\n # puts av > bv ? b : a\nend\n"}, {"source_code": "@n,@vb,@vs = gets.split(/\\s+/).map {|x| x.to_i}\n@stopes = gets.split(/\\s+/).map {|x| x.to_i}\n@xu,@yu = gets.split(/\\s+/).map {|x| x.to_i}\n\n@stopes.unshift(0)\na = 1\nb = @n\n\n\ndef compute(index)\n @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs\nend\n\nav = compute(a)\nbv = compute(b)\n\nwhile (b-a) > 1 \n if av > bv\n a = ((b+a) / 2)\n else\n b = ((b+a) / 2)+1\n end\n\n av = compute(a)\n bv = compute(b)\nend\n#puts \"#{av} #{bv}\"\nif av > bv\n puts b\nelsif bv > av\n puts a\nelse\n av = (@stopes[a]-@xu).abs\n bv = (@stopes[b]-@xu).abs\n puts av > bv ? b : a\nend\n"}, {"source_code": "#$stdin = File.open('in.txt', 'r')\n@n,@vb,@vs = gets.split(/\\s+/).map {|x| x.to_i}\n@stopes = gets.split(/\\s+/).map {|x| x.to_i}\n@xu,@yu = gets.split(/\\s+/).map {|x| x.to_i}\n\n@stopes.unshift(0)\na = 2\nb = @n\n\n\ndef compute(index)\n @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs\nend\n\nav = compute(a)\nbv = compute(b)\n\nwhile (b-a) > 1 \n if av > bv\n a = ((b+a) / 2)\n else\n b = ((b+a) / 2)\n end\n\n av = compute(a)\n bv = compute(b)\nend\nif (b-a) == 1\n mv = compute(a+1)\n if mv < av\n a += 1\n av = mv\n end\nend\n#puts \"#{av} #{bv}\"\nif av > bv\n puts b\nelse bv > av\n puts a \n# else\n# puts a\n # av = (@stopes[a]-@xu).abs\n # bv = (@stopes[b]-@xu).abs\n # puts av > bv ? b : a\nend\n"}, {"source_code": "@n,@vb,@vs = gets.split(/\\s+/).map {|x| x.to_i}\n@stopes = gets.split(/\\s+/).map {|x| x.to_i}\n@xu,@yu = gets.split(/\\s+/).map {|x| x.to_i}\n\n@stopes.unshift(0)\na = 2\nb = @n\n\n\ndef compute(index)\n @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs\nend\n\nav = compute(a)\nbv = compute(b)\n\nwhile (b-a) > 1 \n if av > bv\n a = ((b+a) / 2)\n else\n b = ((b+a) / 2)\n end\n\n av = compute(a)\n bv = compute(b)\nend\n#puts \"#{av} #{bv}\"\nif av > bv\n puts b\nelsif bv > av\n puts a\nelse\n av = (@stopes[a]-@xu).abs\n bv = (@stopes[b]-@xu).abs\n puts av > bv ? b : a\nend\n"}, {"source_code": "#$stdin = File.open('in.txt', 'r')\n@n,@vb,@vs = gets.split(/\\s+/).map {|x| x.to_i}\n@stopes = gets.split(/\\s+/).map {|x| x.to_i}\n@xu,@yu = gets.split(/\\s+/).map {|x| x.to_i}\n\n@stopes.unshift(0)\na = 2\nb = @n\n\n\ndef compute(index)\n @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs\nend\n\nav = compute(a)\nbv = compute(b)\n\nwhile (b-a) > 1 \n if av > bv\n a = ((b+a) / 2)\n else\n b = ((b+a) / 2)\n end\n\n av = compute(a)\n bv = compute(b)\nend\nif (b-a) == 1\n mv = compute(a+1)\n if mv < av\n a += 1\n av = mv\n end\nend\n#puts \"#{av} #{bv}\"\nif av > bv\n puts b\nelsif bv > av\n puts a \nelse\n av = (@stopes[a]-@xu).abs\n bv = (@stopes[b]-@xu).abs\n puts av > bv ? b : a\nend\n"}, {"source_code": "#$stdin = File.open('in.txt', 'r')\n@n,@vb,@vs = gets.split(/\\s+/).map {|x| x.to_i}\n@stopes = gets.split(/\\s+/).map {|x| x.to_i}\n@xu,@yu = gets.split(/\\s+/).map {|x| x.to_i}\n\n@stopes.unshift(0)\na = 2\nb = @n\n\n\ndef compute(index)\n @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs\nend\n\nav = compute(a)\nbv = compute(b)\n\nwhile b > a\n # puts \"a #{a} #{av}\"\n # puts \"b #{b} #{bv}\"\n if bv > av\n b = ((b+a) / 2)\n bv = compute(b)\n else\n a = ((b+a) / 2) + 1\n av = compute(a)\n end\nend\n#puts \"#{a} #{b}\"\n# if (b-a) == 1\n# mv = compute(a+1)\n# if mv < av\n# a += 1\n# av = mv\n# end\n# end\n#puts \"#{av} #{bv}\"\nif av > bv\n puts b\nelse #if bv > av\n puts a \n# else\n# av = (@stopes[a]-@xu).abs\n# bv = (@stopes[b]-@xu).abs\n# puts bv > av ? a : b\nend\n"}, {"source_code": "#\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd: 2???n? ??100, 1???vb,?vs? ??1000. \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd n \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n#: \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd xi \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd i. \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd, \ufffd\ufffd\ufffd x1 \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd, \ufffd xn? ??105. \n#\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd, \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd xu \ufffd yu, \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd 105.\n\n\nn, vb, vs = gets.split(' ').map{|z|z.to_i}\ncrd = gets.split(' ').map{|z|z.to_i}\nxu,yu = gets.split(' ').map{|z|z.to_i}\n\nmin = 105000000\nres= 0\ncrd[1..-1].each_with_index{|xi,i| \n d = Math.sqrt(xi*xi)*vs+Math.sqrt((xu-xi)*(xu-xi)+yu*yu)*vb\n if d < min then\n min = d\n res = i+1\n end\n}\n\nputs res+1"}], "src_uid": "15fa49860e978d3b3fb7a20bf9f8aa86"} {"source_code": "n,q=gets.split.map(&:to_i)\r\ns=gets.chomp.chars.map{|x|x.ord-96}\r\nt=[0]\r\ns.each do |ss|\r\n t << t[-1]+ss\r\nend\r\nq.times do\r\n l,r=gets.split.map(&:to_i)\r\n puts t[r]-t[l-1]\r\nend\r\n", "positive_code": [{"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\nclass NumArray\r\n def initialize(nums)\r\n @x = nums.clone\r\n @x.unshift(0)\r\n (1...@x.size).each do |i|\r\n @x[i] += @x[i-1]\r\n end\r\n end\r\n\r\n def sum_range(left, right)\r\n @x[right+1] - @x[left]\r\n end\r\nend\r\n\r\nnums = []\r\ninputs.shift.bytes.each do |b|\r\n nums << b - 96\r\nend\r\n\r\nnums.unshift(0)\r\nnums = NumArray.new(nums)\r\n\r\ninputs.each do |inp|\r\n from, to = inp.split(' ').map(&:to_i)\r\n\r\n puts nums.sum_range(from, to)\r\nend"}], "negative_code": [], "src_uid": "461378e9179c9de454674ea9dc49c56c"} {"source_code": "n=Array.new(3)\nt=Array.new(3)\nk,n[0],n[1],n[2],t[0],t[1],t[2]=gets.split.map(&:to_i)\n\nstarts=Array.new(k){0}\n\ndef when_free (k, n, t, starts, nnum)\n\tnum=n[nnum]\n\tx=k+1-num\n\t\n\ttime=0\n\tif(x>=0)\n\t\ttime=starts[x]\n\t\n\t\tif (nnum==2)\n\t\t\ttime+=(t[0]+t[1]+t[2])\n\t\tend\n\n\t\tif (nnum==1)\n\t\t\ttime+=(t[0]+t[1])\n\t\tend\n\n\t\tif(nnum==0)\n\t\t\ttime+=t[0]\n\t\tend\n\telse\n\t\tif (nnum==2)\n\t\t\ttime+=(t[0]+t[1])\n\t\tend\n\n\t\tif (nnum==1)\n\t\t\ttime+=(t[0])\n\t\tend\n\tend\n\ttime\nend\n\nstarts[0]=0\nfor i in 1...k do \n\tt2free=when_free(i-1,n,t,starts,2)\n\tt1free=when_free(i-1,n,t,starts,1)\n\tt0free=when_free(i-1,n,t,starts,0)\n\n\tstart=t2free-t[1]-t[0]\n\tif (t1free>start+t[0])\n\t\tstart=t1free-t[0]\n\tend\n\n\tif (t0free>start)\n\t\tstart=t0free\n\tend\n\tstarts[i]=start\nend\n\nputs (starts[k-1]+t[0]+t[1]+t[2])\n\n", "positive_code": [{"source_code": "$n = Array.new(3)\n$t = Array.new(3)\nk, $n[0], $n[1], $n[2], $t[0], $t[1], $t[2] = gets.split.map &:to_i\n\n$now = Array.new(k) { 0 }\n\n1.upto(2) do |i|\n $t[i] += $t[i - 1]\nend\n\ndef make (q, p)\n x = q + 1 - $n[p]\n time = 0\n if x >= 0\n time = $now[x]\n time += $t[p]\n elsif p > 0\n time += $t[p - 1]\n end\n time\nend\n\n$now[0] = 0\n\n0.upto(k - 2) do |i|\n ans = []\n ans << make(i, 2) - $t[1] << make(i, 1) - $t[0] << make(i, 0)\n st = ans.max\n $now[i + 1] = st\nend\nputs ($now[k - 1] + $t[2])"}], "negative_code": [], "src_uid": "dd1d166772ee06b383d4ceb94b530fd1"} {"source_code": "n = gets.to_i\narray = gets.chop!.split(' ').map(&:to_i)\nfixed_points, remain_points, plus = [], [], 0\narray.each_with_index do |e, i|\n if e == i\n fixed_points.push e\n else\n plus = 2 if array[e] == i\n plus = 1 if plus == 0\n end\nend\nputs fixed_points.size + plus", "positive_code": [{"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\na = Array.new\nfor i in 0...n\n\ta[i] = Integer(nums[i])\nend\nc = 0\nfor i in 0...n\n\tif a[i] == i\n\t\tc += 1\n\tend\nend\ndef match(a,i,j)\n\tif a[i] == j && a[j] == i\n\t\treturn true\n\telse\n\t\treturn false\n\tend\nend\nd = 0\nfor i in 0...n\n\tj = a[i]\n\t\tif a[i] == j && a[j] == i && i != j\n\t\t\td = 1\n\t\t\tbreak\n\t\tend\n\t\nend\nif c == n\n\tputs n\nelse\n\tif d == 1\n\t\tputs c + 2\n\telse\n\t\tputs c + 1\n\tend\nend\n"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tar=gets.chomp.split(\" \").map{|i| i.to_i}\n\tans=0\n\tkey=[]\n\tfor i in 0...n\n\t\tif i==ar[i]\n\t\t\tans+=1\n\t\telse\n\t\t\tkey< i && a[v] == i\n double_swap = true\n end\nend\ncount += double_swap ? 2 : 1 if count < n\nputs count"}, {"source_code": "n = gets.to_i\np = gets.split.map { |x| x.to_i }\n\ncnt = 0\nflag = false\nn.times do |i|\n\tif p[i] == i\n\t\tcnt += 1\n\telsif p[p[i]] == i\n\t\tflag = true\n\tend\nend\n\nif cnt == n\n\tputs cnt\nelsif flag\n\tputs cnt + 2\nelse\n\tputs cnt + 1\nend"}, {"source_code": "n = gets.to_i\narray = gets.chop!.split(' ').map(&:to_i)\nfixed_points, remain_points = [], []\narray.each_with_index do |e, i|\n fixed_points.push e if e == i\n remain_points.push [e, i] if e != i\nend\nresult = fixed_points.size\nremain_points.each do |point|\n if array[point[0]] == point[1]\n result += 2\n break\n end\nend\nresult += 1 if result == fixed_points.size && remain_points.size != 0\nputs result"}, {"source_code": "n = gets.to_i\narray = gets.chop!.split(' ').map(&:to_i)\nfixed_points = array.select.with_index { |e, i| e == i}\nplus = array.select.with_index { |e, i| e != i && array[e] == i }.empty? ? 1 : 2\nplus -= 1 if fixed_points.size == array.size\nputs fixed_points.size + plus"}], "negative_code": [{"source_code": "n = gets.to_i\np = gets.split.map { |x| x.to_i }\n\ncnt = 0\nflag = false\nn.times do |i|\n\tif p[i] == i\n\t\tcnt += 1\n\telsif p[p[i]] == i\n\t\tputs i, p[i], p[p[i]]\n\t\tflag = true\n\tend\nend\n\nif cnt == n\n\tputs cnt\nelsif flag\n\tputs cnt + 2\nelse\n\tputs cnt + 1\nend"}], "src_uid": "e63de0fffd00b2da103545a7f1e405be"} {"source_code": "n = readline.to_i\npoles = (0...n).map { |_| readline.split.map(&:to_i) }\n\ndef line_x(x1, y1, x2, y2)\n if y1 == y2\n [nil, nil]\n else\n slope = Rational(x1-x2, y1-y2)\n [slope, x1 - slope * y1]\n end\nend\n\ndef c2(n)\n n * (n-1) / 2\nend\n\nlines = {}\nlines.default = 0\nparallels = {}\nparallels.default = 0\nfor i in 0...n do\n x1, y1 = poles[i]\n for j in i+1...n do\n x2, y2 = poles[j]\n sx, lx = line_x(x1, y1, x2, y2)\n sy, ly = line_x(y1, x1, y2, x2)\n line = [sx, lx, ly]\n lines[line] += 1\n parallels[[sx,sy]] += 1 if lines[line] == 1\n end\nend\n\nr = c2(lines.length)\nparallels.values.each { |x| r -= c2(x) }\np r\n", "positive_code": [{"source_code": "# coding: utf-8\nn = readline.to_i\npoles = (0...n).map { |_| readline.split.map(&:to_i) }\n\ndef c2(n)\n n * (n-1) / 2\nend\n\nlines = {}\nlines.default = 0\nparallels = {}\nparallels.default = 0\nfor i in 0...n do\n x1, y1 = poles[i]\n for j in i+1...n do\n x2, y2 = poles[j]\n a = y1 - y2\n b = x2 - x1\n if a < 0 or (a == 0 and b < 0)\n a = -a\n b = -b\n end\n d = a.gcd b\n a /= d\n b /= d\n c = a*x1 + b*y1\n line = [a, b, c]\n STDERR.print \"(#{x1},#{y1})\u2014(#{x2},#{y2}): #{a}x+#{b}y+#{c}=0\\n\"\n lines[line] += 1\n parallels[[a, b]] += 1 if lines[line] == 1\n end\nend\n\nr = c2(lines.length)\nparallels.values.each { |x| r -= c2(x) }\np r\n"}], "negative_code": [{"source_code": "n = readline.to_i\npoles = (0...n).map { |_| readline.split.map(&:to_i) }\n\ndef c2(n)\n n * (n-1) / 2\nend\n\nlines = {}\nlines.default = 0\nparallels = {}\nparallels.default = 0\nfor i in 0...n do\n x1, y1 = poles[i]\n for j in i+1...n do\n x2, y2 = poles[j]\n a = y1 - y2\n b = x2 - x1\n d = a.gcd b\n a /= d\n b /= d\n c = a*x1 + b*y1\n line = [a, b, c]\n lines[line] += 1\n parallels[[a, b]] += 1 if lines[line] == 1\n end\nend\n\nr = c2(lines.length)\nparallels.values.each { |x| r -= c2(x) }\np r\n"}, {"source_code": "n = readline.to_i\npoles = (0...n).map { |_| readline.split.map(&:to_i) }\n\ndef line_x(x1, y1, x2, y2)\n if y1 == y2\n [nil, nil]\n else\n slope = Rational((x1-x2)/(y1-y2))\n [slope, x1 - slope * y1]\n end\nend\n\ndef c2(n)\n n * (n-1) / 2\nend\n\nlines = {}\nlines.default = 0\nparallels = {}\nparallels.default = 0\nfor i in 0...n do\n x1, y1 = poles[i]\n for j in i+1...n do\n x2, y2 = poles[j]\n sx, lx = line_x(x1, y1, x2, y2)\n sy, ly = line_x(y1, x1, y2, x2)\n line = [sx, sy, lx, ly]\n lines[line] += 1\n parallels[[sx, sy]] += 1 if lines[line] == 1\n end\nend\n\nr = c2(lines.length)\nparallels.values.each { |x| r -= c2(x) }\np r\n"}], "src_uid": "8c2e0cd780cf9390e933e28e57643cba"} {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.chomp.split.map(&:to_i)\r\n ans = 0\r\n cur = a[0]\r\n down = 0\r\n for i in 1..n-1\r\n if(cur >= a[i] - down)\r\n ans += cur - (a[i] - down)\r\n cur = a[i] - down\r\n else\r\n ans += (a[i] - down) - cur\r\n down += (a[i] - down) - cur\r\n end\r\n end\r\n ans += cur > 0 ? cur : -cur\r\n \r\n puts ans\r\nend", "positive_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.chomp.split.map(&:to_i)\r\n ans = 0\r\n cur = a[0]\r\n down = 0\r\n (1..n-1).each do |i|\r\n ans += [cur - (a[i] - down), (a[i] - down) - cur].max\r\n down += [(a[i] - down) - cur, 0].max\r\n cur = a[i] - down\r\n end\r\n puts ans + (cur > 0 ? cur : -cur)\r\n \r\nend"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.chomp.split.map(&:to_i)\r\n ans = 0\r\n cur = a[0]\r\n down = 0\r\n for i in 1..n-1\r\n ans += [cur - (a[i] - down), (a[i] - down) - cur].max\r\n down += [(a[i] - down) - cur, 0].max\r\n cur = a[i] - down\r\n end\r\n puts ans + (cur > 0 ? cur : -cur)\r\n \r\nend"}], "negative_code": [], "src_uid": "f54c1448a279e59f96847a158f993101"} {"source_code": "$n = gets.chomp.to_i\n$n.times do\n s = gets.chomp.to_i\n ans = 0\n while s > 0\n ans = [ans, s % 10].max\n s = s / 10\n end\n puts ans\nend\n \t\t \t\t \t\t \t\t \t\t\t\t \t", "positive_code": [{"source_code": "gets.to_i.times do |i|\r\n puts gets.chomp.chars.max\r\nend"}], "negative_code": [], "src_uid": "1a6881aeb197b8ed429f46850eb27b9c"} {"source_code": "input = STDIN.read.split(\"\\n\")\r\n\r\n(0..input.shift.to_i - 1).to_a.reverse.each do |i|\r\n wh = input.shift.split(' ').map(&:to_i)\r\n h1a = input.shift.split(' ').map(&:to_i)\r\n h2a = input.shift.split(' ').map(&:to_i)\r\n w1a = input.shift.split(' ').map(&:to_i)\r\n w2a = input.shift.split(' ').map(&:to_i)\r\n\r\n h1 = h1a[h1a[0]] - h1a[1]\r\n h2 = h2a[h2a[0]] - h2a[1]\r\n maxh = [h1, h2].max\r\n\r\n w1 = w1a[w1a[0]] - w1a[1]\r\n w2 = w2a[w2a[0]] - w2a[1]\r\n maxw = [w1, w2].max\r\n\r\n puts [maxw * wh[0], maxh * wh[1]].max\r\nend", "positive_code": [{"source_code": "area = ->(x1, y1, x2, y2, x3, y3) {\r\n (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)).abs\r\n}\r\n\r\ngets.to_i.times do\r\n w, h = gets.split.map(&:to_i)\r\n as = gets.split.drop(1).map { |x| [x.to_i, 0] }\r\n bs = gets.split.drop(1).map { |x| [x.to_i, h] }\r\n cs = gets.split.drop(1).map { |x| [0, x.to_i] }\r\n ds = gets.split.drop(1).map { |x| [w, x.to_i] }\r\n all = as + bs + cs + ds\r\n p([as, bs, cs, ds].map do |s|\r\n x1, y1 = s[0]\r\n x2, y2 = s[-1]\r\n all.map { |x3, y3| area[x1, y1, x2, y2, x3, y3] }.max\r\n end.max)\r\nend"}], "negative_code": [], "src_uid": "2c67ee95eba7ffbbed99cb488abb5f3d"} {"source_code": "n,m = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\nres = arr[0]-1\nfor i in 1...m\n if arr[i] < arr[i-1]\n res += n - (arr[i] - arr[i-1]).abs\n else\n res += arr[i] - arr[i-1];\n end\nend\n\nputs res\n\n", "positive_code": [{"source_code": "n, m = gets.split(' ').map(&:to_i)\nar = gets.split(' ').map(&:to_i)\nputs ar.each_cons(2).select{|x,y| x>y}.count * n + ar[-1] - 1"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\np ([0]+gets.split.map{|e|e.to_i-1}).each_cons(2).map{|a,b|b-a<0 ? b+n-a : b-a}.reduce(:+)"}, {"source_code": "line1 = gets.chomp.split(\" \")\nn = line1[0].to_i\nm = line1[1].to_i\ntask = gets.chomp.split(\" \").map {|x| x.to_i}\npos = 1\nans = 0\nfor t in task\n if t > pos\n ans += t-pos\n elsif t < pos\n ans += t+n-pos\n end\n pos = t\nend\nputs ans\n"}, {"source_code": "def get_i\n return gets.split(' ').map(&:to_i)\nend\nn,m=get_i\na=get_i.unshift(1)\nans=0\nfor i in 1..m do\n ans+=(a[i]-a[i-1]+n)%n\nend\nputs ans"}, {"source_code": "n, m = gets.split.map { |i| i.to_i }\na = gets.split.map { |i| i.to_i }\n\ns = a[0] - 1\nfor i in 1..(a.count - 1) do\n y = a[i] - a[i - 1]\n if y < 0 then y = n + y end\n s += y\nend\n\nputs s\n"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\np ([0]+gets.split.map{|e|e.to_i-1}).each_cons(2).map{|a,b|b-a<0 ? b+n-a : b-a}.reduce(:+)\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn, m = STDIN.readline.split.collect {|s| s.to_i }\ntasks = STDIN.readline.split.collect {|s| s.to_i }\n\ntotal = 0\npos = 1\ntasks.each do |next_pos|\n\tif next_pos >= pos\n\t\ttotal += next_pos - pos\n\telse\n\t\ttotal += (n - pos) + 1 + (next_pos - 1)\n\tend\n\tpos = next_pos\nend\nputs total\n\n"}, {"source_code": "hn, dn = gets.split.map(&:to_i)\ndeals = gets.split.map(&:to_i)\ntime = 0\ncurh = 1\ndeals.each {|d|\n\ttime += (d-curh)%hn\n\tcurh = d\n}\nputs time"}, {"source_code": "def string_to_int(string, delim = \" \")\n result = []\n string = string.split(delim)\n for i in 0...string.length\n result[i] = string[i].to_i\n end\n return result\nend\n\ninput = string_to_int(gets.chomp)\ndest = string_to_int(gets.chomp)\n\nwalk = dest[0] - 1\n\nfor i in 0...dest.length - 1\n\tif dest[i] <= dest[i+1]\n\t\twalk += dest[i+1] - dest[i]\n\telse\n\t\twalk += input[0] + dest[i+1] - dest[i]\n\tend\nend\n\nputs walk\n"}, {"source_code": "r = -> { gets.split.map(&:to_i )}\nn,m = r[]\nv = r[]\nv.unshift(1)\ns = 0\n(1..m).each do |x|\n if v[x - 1] < v[x]\n s += v[x] - v[x - 1]\n elsif v[x - 1] > v[x] \n s += n - v[x - 1] + v[x]\n end\nend\np s"}, {"source_code": "n,m=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i)\ny,ans,x=1,0,0\na.each do |i|\n\tans+=1 if i= prev\n moves += item - prev\n prev = item \n else\n moves += n - prev + item\n prev = item\n end\nend\nputs moves\n"}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\ntasks = gets.chomp.split(/ /).map(&:to_i)\nans = 0\nprev_task = 0\n(0...m).each do |task|\n current_task = tasks[task]\n if prev_task == 0\n ans += current_task\n else\n if current_task != prev_task\n if current_task < prev_task\n ans += (n - prev_task) + current_task\n else\n ans += current_task - prev_task\n end\n end\n end\n prev_task = current_task\nend\nputs ans - 1\n"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i-1}\n\nans=x[0]\n(m-1).times{|i|\n\tif x[i+1]>=x[i] then\n\t\tans=ans+x[i+1]-x[i]\n\telse\n\t\tans=ans+x[i+1]+n-x[i]\n\tend\n}\nputs ans"}, {"source_code": "s = gets.split.map { |e| e.to_i }\ns2 = gets.split.map { |e| e.to_i }\nn = s[0]\nm = s[1]\nx = m[0]\nc = 0\nfor i in s2\n\tif i < x\n\t\tc +=1\n\tend\t\n\tx = i\nend\nputs (c * n) + s2[m-1] - 1\n\n"}, {"source_code": "n,m = gets.split(\" \").map { |x| x.to_i }\na = gets.split(\" \").map { |x| x.to_i }\nres = 0\nxprev = 1\na.each do |x|\n if xprev > x then\n res += n\n end\n res += x - xprev\n xprev = x\nend\nputs res"}, {"source_code": "input = gets.chomp\nnum = input.split\nn = Integer(num[0])\nm = Integer(num[1])\ninput2 = gets.chomp\nnums = input2.split\na = Array.new\nfor i in 0...m\n a[i] = Integer(nums[i])\nend\n\nb = Array.new\nb[0] = a[0]\nfor i in 0...m-1\n if a[i+1] != a[i]\n b.push(a[i+1])\n end\nend\ntime = 0\nl = b.length\nfor i in 0...l-1\n if b[i+1] < b[i]\n time += 1\n end\nend\n\nputs time * n - 1 + b[l-1]"}, {"source_code": "nm = gets.chomp\nnm = nm.split\nhouses = nm[0].to_i\ntasks = nm[1].to_i\neach_task = gets.chomp\neach_task = each_task.split\n\nhours = 0\nposition = 1\nfor i in (0..each_task.size-1)\n\tif position < each_task[i].to_i\n\t\thours += (each_task[i].to_i - position)\n\t\tposition = each_task[i].to_i\n\telsif position > each_task[i].to_i\n\t\thours += (houses - position) + each_task[i].to_i\n\t\tposition = each_task[i].to_i\n\tend\nend\n\nprint hours"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\ntasks = gets.split(\" \").map(&:to_i)\ncost = 0\ncurrent = 1\ntasks.each do |a|\n\tif a > current\n\t\tcost += a - current\n\t\t\n\t\tcurrent = a\n\telsif a < current\n\t\tcost += (n - current) + a\n\t\tcurrent = a\n\tend\nend\nputs cost"}, {"source_code": "n, m = gets.split.map &:to_i\na = gets.split.map &:to_i\ns = 0\np = 1\n\nfor i in (0..m-1)\n a[i] < p ? s += n - p + a[i] : s += a[i] - p\n p = a[i]\nend\nputs s\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn,m = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i)\nnow = 1\nans = 0\nx.each do |p|\n if now <= p\n ans += p - now\n else\n ans += p + n - now\n end\n now = p\nend\nputs ans\n"}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\na = gets.strip.split.map(&:to_i)\nnow = 1\ndis = 0\na.each do |x|\n if x < now\n dis += (n - (now - x))\n else\n dis += x - now\n end\n now = x\nend\nputs dis\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\n\ncurr = 1\nputs(\n gets.split(' ').map(&:to_i).inject(0) do |result, x|\n c = curr\n curr = x\n result + (x >= c ? x - c : n - c + x)\n end\n)\n"}, {"source_code": "n, m = gets.chomp.split.map { |x| x.to_i }\nh = [1].concat(gets.chomp.split.map { |x| x.to_i })\ncount = 0\nfor i in 1..m\n if h[i] > h[i - 1]\n count += h[i] - h[i - 1]\n elsif h[i] < h[i - 1]\n count += n - h[i - 1] + h[i]\n end\nend\nputs count"}, {"source_code": "r = gets.split(\" \")[0].to_i\ns = gets.split(\" \").map { |i| i.to_i }\n\nb = 1\nres = 0\ns.each do |i|\n\tif b < i\n\t\tres += (i-b)\n\telsif b > i\n\t\tres += (r-b+i)\n\tend\n\tb = i\nend\n\nputs res\n"}, {"source_code": "def read_line\n\tline = gets.chomp.split(' ')\n\tline.map { |elem| elem.to_i }\nend\n\ndef distance(a, b, n)\n\treturn b - a if a <= b\n\tn - a + 1 + b - 1\nend\n\nn, m = read_line\na = read_line\ncurrent = 1\nres = 0\na.each do |after|\n\tres += distance(current, after, n)\n\tcurrent = after\nend\n\nputs res\n\n"}, {"source_code": "# f = File.new('test1.txt', 'r')\nf = STDIN\nwhile s = f.gets\n n, m = s.split.map(&:to_i)\n arr = f.gets.split.map(&:to_i)\n ans, start = 0, 1\n arr.each do |e|\n if e >= start\n ans += e - start\n else\n ans += n - start + e\n end\n start = e\n end\n puts ans\nend\nf.close"}], "negative_code": [{"source_code": "def string_to_int(string, delim = \" \")\n result = []\n string = string.split(delim)\n for i in 0...string.length\n result[i] = string[i].to_i\n end\n return result\nend\n\ninput = string_to_int(gets.chomp)\ndest = string_to_int(gets.chomp)\n\nwalk = dest[0] - 1\n\nfor i in 0...dest.length - 1\n\tif dest[i] < dest[i+1]\n\t\twalk += dest[i+1] - dest[i]\n\telse\n\t\twalk += input[0] + dest[i+1] - dest[i]\n\tend\nend\n\nputs walk\n"}, {"source_code": "def string_to_int(string, delim = \" \")\n result = []\n string = string.split(delim)\n for i in 0...string.length\n result[i] = string[i].to_i\n end\n return result\nend\n\ninput = string_to_int(gets.chomp)\ndest = string_to_int(gets.chomp)\n\nhouse_no = 0\nhouses = Array.new(input[0]){|house_no| house_no+1}\nwalk = 0\n\nj = 0\nfor i in 0...dest.length\n\twhile houses[j] != dest[i]\n\t\tif j > dest.length - 1\n\t\t\tj = 0\n\t\t\twalk += 1\n\t\telse\n\t\t\tj += 1\n\t\t\twalk += 1\n\t\tend\n\tend\nend\n\nputs walk\n"}, {"source_code": "def read_line\n\tline = gets.chomp.split(' ')\n\tline.map { |elem| elem.to_i }\nend\n\ndef distance(a, b, n)\n\treturn b - a if a <= b\n\tn - a + 1 + b - 1\nend\n\nn, m = read_line\na = read_line.uniq\ncurrent = 1\nres = 0\na.each do |after|\n\tres += distance(current, after, n)\n\tcurrent = after\nend\n\nputs res\n\n"}], "src_uid": "2c9c96dc5b6f8d1f0ddeea8e07640d3e"} {"source_code": "a=b=[];([*$<]*'').tr(?\\n,\"\").scan(/<\\/?ta|319&&b<<319&&b<<319&&b<<319&&b<<319&&b<<319&&b<<319&&b<<319&&b<<')\n [s[0..pos], s[pos+1..-1]]\nend\n\nstack = []\nans = []\n\nwhile true\n head, s = read_next(s)\n break unless head\n case head\n when \"\" then stack.push(0)\n when \"
\" then ans << stack.pop\n when \"\" then stack[-1] += 1\n end\nend\n\nputs ans.sort.join(' ')\n"}, {"source_code": "a=b=[];([*$<]*'').tr(?\\n,\"\").scan(/<\\/?ta|319&&b<<319&&b<<319&&b<</) do |_,|\n\tcase _\n\twhen 'table' then a << 0\n\twhen '/table' then b << a.pop\n\twhen 'td' then a[-1] += 1\n\tend\nend\nputs b.sort * ' '\n"}, {"source_code": "a = [0]\nb = []\n(readlines * '').scan(/<(ta|\\/ta|td)/) do |_,|\n\tcase _\n\twhen 'ta' then a << 0\n\twhen '/ta' then b << a.pop\n\twhen 'td' then a[-1] += 1\n\tend\nend\nputs b.sort * ' '\n"}], "src_uid": "eb5a5adffedacadad1df27a1ddc7f8ff"} {"source_code": "def solve\n n = gets.strip.to_i\n if n == 1\n puts \"FastestFinger\"\n return nil\n end\n if n == 2 || n.odd?\n puts \"Ashishgup\"\n return nil\n end\n\n sq = Math.sqrt(n).to_i\n (2..sq).each { |i|\n if (n % i).zero?\n if (i.odd? && (n / i) > 2) || ((n / i).odd? && (n / (n / i)) > 2)\n puts \"Ashishgup\"\n return nil\n end\n end\n }\n puts \"FastestFinger\"\nend\n\ngets.strip.to_i.times { solve }\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\n\na = 'Ashishgup'\nb = 'FastestFinger'\n\ndef is_prime?(num)\n return if num <= 1\n (2..Math.sqrt(num)).none? { |i| (num % i).zero? }\nend\n\n(1..n).each do\n x = gets.chomp.to_i\n if x == 1\n puts b\n elsif x == 2\n puts a\n elsif x % 2 == 1\n puts a\n elsif x % 4 != 0\n if is_prime?(x/2)\n puts b\n else\n puts a\n end\n elsif x.to_s(2).count('1') == 1\n puts b\n else\n puts a\n end\nend\n"}], "negative_code": [{"source_code": "def solve\n n = gets.strip.to_i\n if n == 1\n puts \"FastestFinger\"\n return nil\n end\n if n == 2 || n.odd?\n puts \"Ashishgup\"\n return nil\n end\n\n sq = Math.sqrt(n).to_i\n (2..sq).each { |i|\n if (n % i).zero?\n if (i.odd? || (n / i).odd?)\n if n / (n / i) > 3 || n / i > 3\n puts \"Ashishgup\"\n return nil\n end\n end\n end\n }\n puts \"FastestFinger\"\nend\n\ngets.strip.to_i.times { solve }\n"}, {"source_code": "n = gets.chomp.to_i\n\na = 'Ashishgup'\nb = 'FastestFinger'\n\n(1..n).each do\n x = gets.chomp.to_i\n if x == 1\n puts b\n elsif x == 2\n puts a\n elsif x % 2 == 1\n puts a\n elsif x % 4 != 0\n puts b\n elsif x.to_s(2).count('1') == 1\n puts b\n else\n puts a\n end\nend\n"}], "src_uid": "b533572dd6d5fe7350589c7f4d5e1c8c"} {"source_code": "s=gets.chomp\nMOD=1000000007\nans=0\nm=1\nfor i in 0...s.length\n\tif s[i]=='a'\n\t\tm=(m*2)%MOD\n\telse\n\t\tans=(ans+m-1)%MOD\n\tend\nend\nputs ans\n\t", "positive_code": [{"source_code": "res, q, m=0, 1, 10**9+7\ngets.chomp.chars{|c| c==?a ? q=q*2%m : res=(res+q-1+m)%m}\np res\n"}], "negative_code": [{"source_code": "s=gets.chomp\nm=10**9+7\na=s.split(?b).map(&:size)\na.pop if s[-1]!=?b\nn=a.size\nfor i in 1...n\n a[i]+=a[i-1]\nend\nres=0\na.each{|e| res+=2**e-1; res%=m; }\np res\n"}], "src_uid": "8f52241c690ec4f9af71a52904fb19a0"} {"source_code": "END { load __FILE__ unless $stdin.eof? }\n\nt = gets.to_i\nt.times do\n\nn = gets.to_i\na = gets.split.map!(&:to_i)\n\nx = a.inject(:&)\np x\n\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n puts gets.split.map(&:to_i).inject(:&)\r\nend\r\n"}], "negative_code": [], "src_uid": "4f8eac547bbd469a69de2f4aae4a87f0"} {"source_code": "N, K = gets.split.map(&:to_i)\nstr = gets.chomp\nhash = Hash.new(0)\nstr.split('').sort[0, K].each do |c|\n hash[c] += 1\nend\nans = ''\nstr.chars do |c|\n if hash[c] > 0\n hash[c] -= 1\n else\n ans << c\n end\nend\nputs ans", "positive_code": [{"source_code": "\ndef solution\n _, k = read_ints\n s = read_string.chars\n\n ixs = (0..25).map{ |i| [] }\n\n (0...s.size).each do |i|\n c = s[i]\n x = c.ord - 97\n ixs[x] << i\n end\n\n to_remove = ixs.flatten\n\n k.times do\n i = to_remove.shift\n s[i] = '*'\n end\n\n # puts s.gsub('*', '')\n s.each do |c|\n print c if c > '*'\n end\n puts\n\nend\n\ndef solution_16s\n # perf problem was not the hash; it was the string ops\n # Apparently s[i] = 'c' is expensive.\n # Using s.chars instead is much better\n _, k = read_ints\n s = read_string\n\n ixs = Hash.new { |h, i| h[i] = [] }\n\n (0...s.size).each do |i|\n c = s[i]\n ixs[c] << i\n end\n\n l = 'a'\n\n k.times do\n l = l.succ while ixs[l].size < 1\n ix = ixs[l].shift\n s[ix] = ' '\n end\n\n # puts s.gsub(' ', '')\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}, {"source_code": "n, k = gets.strip.split.map(&:to_i)\nstr = gets.strip\n\nchars = str.split('').sort\nhsh = {}\nk.times do |i|\n hsh[chars[i]] = (hsh[chars[i]] || 0) + 1\nend\n\nans_str = \"\"\nstr.each_char do |c|\n if hsh[c].nil? || hsh[c] <= 0\n ans_str << c\n else\n hsh[c] -= 1 if hsh[c] && hsh[c] > 0\n end\nend\nputs ans_str"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\ns = gets.chomp\n\na = s.split(\"\").sort\n\nhash = Hash.new { |hash, key| hash[key] = 0 }\n\nk.times do |i|\n hash[a[i]] += 1\nend\n\nresult = \"\"\n\ns.each_char do |char|\n if hash[char].nil? || hash[char] <= 0\n result << char\n elsif hash[char] && hash[char] > 0\n hash[char] -= 1\n end\nend\n\nputs result\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\ns = gets.chomp\npos = (1..26).map { [] }\ns.chars.each_with_index { |c, i| pos[c.ord - 'a'.ord] << i }\n\nflag = [true] * n\npos.each do |a|\n\ta.each do |pos|\n\t\tif k > 0\n\t\t\tflag[pos] = false\n\t\t\tk -= 1\n\t\tend\n\tend\nend\nputs (0...n).select { flag[_1] }.map { s[_1] }.join\n"}, {"source_code": "n, k = gets.split(\" \").map{|n| n.to_i }\ns = gets.chomp\n\nrequire 'pp'\nstrs = \"abcdefghijklmnopqrstuvwxyz\".split(\"\")\nmaps = {}\ns.length.times{|i|\n maps[s[i]] ||= 0\n maps[s[i]] += 1\n}\n\ncounts = maps.to_a.sort{|a, b|a[0]<=>b[0]}\nerase_counts = {}\nwhile 0 < k\n counts.each{|char, count|\n erase = [count, k].min\n k -= erase\n erase_counts[char] = erase\n break if k == 0\n }\nend\n\ns.length.times{|i|\n char = s[i]\n if not erase_counts[char].nil? and 0 < erase_counts[char]\n erase_counts[char] -= 1\n else\n print char\n end\n}\nputs \"\"\n"}], "negative_code": [{"source_code": "\ndef solution\n _, k = read_ints\n s = read_string.chars\n\n ixs = (0..25).map{ |i| [] }\n\n (0...s.size).each do |i|\n c = s[i]\n x = c.ord - 97\n ixs[x] << i\n end\n\n to_remove = ixs.flatten\n\n k.times do\n i = to_remove.shift\n s[i] = '*'\n end\n\n # puts s.gsub('*', '')\n s.each do |c|\n print c, false if c > '*'\n end\n puts\n\nend\n\ndef solution_16s\n _, k = read_ints\n s = read_string\n\n ixs = Hash.new { |h, i| h[i] = [] }\n\n (0...s.size).each do |i|\n c = s[i]\n ixs[c] << i\n end\n\n l = 'a'\n\n k.times do\n l = l.succ while ixs[l].size < 1\n ix = ixs[l].shift\n s[ix] = ' '\n end\n\n # puts s.gsub(' ', '')\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}, {"source_code": "\ndef solution\n _, k = read_ints\n s = read_string.chars\n\n ixs = (0..25).map{ |i| [] }\n\n (0...s.size).each do |i|\n c = s[i]\n x = c.ord - 97\n ixs[x] << i\n end\n\n to_remove = ixs.flatten\n\n k.times do\n i = to_remove.shift\n s[i] = '*'\n end\n\n s.each do |c|\n print c, false if c > '*'\n end\n puts\n\nend\n\ndef solution_16s\n _, k = read_ints\n s = read_string\n\n ixs = Hash.new { |h, i| h[i] = [] }\n\n (0...s.size).each do |i|\n c = s[i]\n ixs[c] << i\n end\n\n l = 'a'\n\n k.times do\n l = l.succ while ixs[l].size < 1\n ix = ixs[l].shift\n s[ix] = ' '\n end\n\n # puts s.gsub(' ', '')\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}], "src_uid": "9f095a5f5b39d8c2f99c4162f2d7c5ff"} {"source_code": "s = gets.chomp\nletters = [\"A\", \"H\", \"I\", \"M\", \"O\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\"]\ns.split(\"\").each do |ch|\n unless letters.include?(ch)\n puts \"NO\"\n exit\n end\nend\nif s.reverse != s\n puts \"NO\"\n exit\nend\nputs \"YES\"\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\ns=gets.chomp\nputs s.tr('A-Z','A@@@@@@HI@@@M@O@@@@TUVWXY@').reverse==s ? :YES : :NO"}, {"source_code": "s = gets.chomp\nif s.match(/[^AHIOMTUVWXY]/).nil? and s == s.reverse\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "sym = ['A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y']\n\ninput = gets.chomp\nif input != input.reverse\n puts \"NO\"\nelse\n input.each_char do |char|\n next if sym.include? char\n\n puts \"NO\"\n exit\n end\n puts \"YES\"\nend"}, {"source_code": "def solve(s)\n\treturn ((/^[AHIMOTUVWXY]*$/.match s) and (s == s.reverse))\nend\n\ndef main()\n\treturn \"YES\" if solve(gets.chomp)\n\treturn \"NO\"\nend\n\nputs main\n"}, {"source_code": "s = gets.chomp\nif (s.size == 1 or s[0..s.size / 2 - 1] == s[(s.size / 2.0).ceil..-1].reverse) and s.scan(/[AHIMOTUVWXY]/i).size == s.size\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "s = gets.chomp\nletters = [\"A\", \"H\", \"I\", \"M\", \"O\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\"]\nunless (s.split(\"\").uniq-letters).empty?\n puts \"NO\"\n exit\nend\nif s.reverse != s\n puts \"NO\"\n exit\nend\nputs \"YES\"\n"}, {"source_code": "MIRROR = \"AHIMOTUVWXY\"\ns = gets.chomp\nlen = s.length\n0.upto(len>>1) do |i|\n\tif s[i] != s[len-1-i] || !MIRROR.include?(s[i]) || !MIRROR.include?(s[len-1-i])\n\t\tputs \"NO\"\n\t\texit 0\n\tend\nend\nputs \"YES\"\n"}], "negative_code": [{"source_code": "s = gets.chomp\nif s[0..s.size / 2 - 1] == s[(s.size / 2.0).ceil..-1].reverse and s.scan(/[AHIMOTUVWXY]/i).size == s.size\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "gets.chomp.each_char do |i|\n\tif !\"AHIMOTUVWY\".include?(i)\n\t\tputs \"NO\"\n\t\texit 0\n\tend\nend\nputs \"YES\"\n"}, {"source_code": "#!/usr/bin/ruby\ns=gets.chomp\nputs s.tr('A-Z','A@@@@@@HI@@M@O@@@@TUVWXY@').reverse==s ? :YES : :NO"}, {"source_code": "s = gets.chomp\nif s.match(/[^AHIOTUVWXY]/).nil? and s == s.reverse\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}], "src_uid": "8135173b23c6b48df11b1d2609b08080"} {"source_code": "gets\ns=0\na=0\nfor x in gets.chomp.split.map(&:to_i)\n\ts += x;\n\ta += -s if s < 0\n\ts -= s if s < 0\nend\n\nputs a", "positive_code": [{"source_code": "\ufeff# -*- encoding: utf-8 -*-\nn = gets.chomp.to_i\nevents = gets.chomp.split(\" \").map{ |e| e.to_i }\n\nans = 0\np = 0\n\nevents.each { |event|\n if event == -1\n if p > 0\n p -= 1\n else\n ans += 1\n end\n else\n p += event\n end\n}\n\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nx = 0\ny = 0\n\nfor i in a\n if i == -1\n if x > 0\n x -= 1\n else\n y += 1\n end\n else\n x += i\n end\nend\n\nprint y\n"}, {"source_code": "n = gets.to_i\narr = gets.split.map(&:to_i)\nsoliders = 0\ncrimes = 0\n\narr.each do |x|\n\tsoliders += x\n\t(crimes += 1; soliders = 0) if soliders < 0\nend\n\nputs crimes"}, {"source_code": "n,v=gets.to_i,gets.split.map(&:to_i)\ns,c=0,0\nv.each {|x| (s+=x) == -1 ? (c,s=c+1,0) : s}\np c"}, {"source_code": "n = gets.to_i\np = gets.split.map{|r| r.to_i}\n\ncounters = 0; xounterz = 0\nfor i in 0..n-1\n counters+=p[i]\n if counters<0\n xounterz+=1\n counters = 0\n end\nend\nputs xounterz"}, {"source_code": "n = $stdin.gets.to_i\nf = $stdin.readline.split.map(&:to_i)\n\nk = 0\nf.inject(0) do |cops_count, x|\n #puts \"cop_count=#{cops_count}, x=#{x}, k=#{k}\"\n if x == -1\n if cops_count == 0\n k+=1\n else\n cops_count -= 1\n end\n else\n cops_count += x\n end\n cops_count\nend\n\nputs k\n"}, {"source_code": "n= gets.to_i \nlist = gets.split(\" \").map(&:to_i)\n\ni= 0 \navailable_police = 0 \ncrime =0 \nn.times do \n if list[i] > 0 \n available_police+=list[i]\n\n elsif list[i]<0 and available_police>0 \n available_police+=list[i]\n else \n crime +=1 \n end \n i+=1 \n\n\nend \nputs crime "}, {"source_code": "n = gets.to_i\narr = gets.split.map &:to_i\ncops = 0\ncrimes = 0\narr.each do |x|\n if x == -1 && cops == 0\n crimes += 1\n elsif x == -1 && cops != 0 \n cops -= 1\n else\n cops += x\n end\nend\nputs crimes\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ncur = 0\nans = 0\nfor x in a\n if x>0\n cur += x\n else\n if cur == 0\n ans += 1\n else\n cur -= 1\n end\n end\nend\nprint ans"}, {"source_code": "n = gets.to_i\ns = 0\nans = 0\ngets.split.map(&:to_i).each do |e|\n if e < 0\n if s > 0\n s += e\n else\n ans += 1\n end\n else\n s += e\n end\nend\nputs ans"}, {"source_code": "gets\nf=a=0\ngets.split.map{|i| i.to_i}.each{|s| \n\tif s<0 \n\t\tif f<=0\n\t\t\ta+=1\n\t\telse\n\t\t\tf-=1\n\t\tend\n\telse\n\t\tf+=s\n\tend\n}\np a"}, {"source_code": "gets\nx=gets.split.map{|e| e.to_i}\nsum=0\nans=0\nx.each{|e|\n\tif e<0 then\n\t\tsum+=e\n\t\tans+=1 if sum<0\n\telse\n\t\tsum=([sum,0].max)+e\n\tend\n}\nputs ans"}, {"source_code": "t = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\n\nco = 0\nt = 0\narr.each do |el|\n # p [t+el]\n if t + el < 0\n co += 1\n t = 0\n else\n t += el\n end \nend\nputs co"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc,r = 0,0\nn.times do |i|\n\tif a[i] > 0\n\t\tc += a[i]\n\telsif c > 0 \n\t\tc -= 1\n\telse\n\t\tr += 1\n\tend\nend\np r"}, {"source_code": "police = 0\ncriminal = 0\nout = 0\nk = gets.to_i\ngets.chomp.split.map do |e|\n e = e.to_i\n police += e if e > 0\n out += 1 if e == -1 and police == 0\n police -= 1 if e == -1 and police > 0\n \nend\n\nputs out\n"}, {"source_code": "n = gets.chomp.to_i\n\nans,pol = 0,0\n\ngets.chomp.split(\" \").each { |e|\n if e.to_i == -1\n if pol>0\n pol -= 1\n else\n ans += 1\n end\n else\n pol += e.to_i\n end\n}\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\n\nans,pol = 0,0\n\ngets.chomp.split(\" \").each { |e|\n if e.to_i == -1\n if pol>0\n pol -= 1\n else\n ans += 1\n end\n else\n pol += e.to_i\n end\n}\nputs ans"}, {"source_code": "crimes = gets.chomp.to_i\nn = gets.chomp\nevents = n.split\n\ncount = 0\nuntreated = 0\nfor i in (0..crimes-1)\n\tif count == 0 && events[i].to_i == -1\n\t\tuntreated += 1\n\telsif events[i].to_i >= 1\n\t\tcount += events[i].to_i\n\telsif count > 0 && events[i].to_i == -1\n\t\tcount -= 1\n\tend\nend\n\nputs untreated"}, {"source_code": "n = gets.chomp\nevents = gets.chomp.split(' ').map(&:to_i)\nans = f = 0\nevents.reverse.each do |e| \n next if f == 0 && e != -1\n f = 1\n if e == -1\n ans = ans + e\n else\n ans = ans + (ans < 0 ? e : 0)\n ans = 0 if ans > 0\n end\nend\nputs ans.abs"}, {"source_code": "gets\nnow = 0\nans = 0\ngets.split.map(&:to_i).each { |c|\n if c == -1\n if now >= 1\n now -= 1\n else\n ans += 1\n end\n else\n now += c\n end\n}\n\nputs ans"}, {"source_code": "cops = 0\nresult = 0\n\ngets\ngets.split(' ').map(&:to_i).each do |x|\n cops += x\n if cops < 0\n result += 1\n cops = 0\n end\nend\n\nputs result\n"}, {"source_code": "eventNumber = gets.chomp.to_i\ninput = gets.chomp.split(' ').map {|item| item.to_i}\n\npolice = 0\nans = 0\n(0...eventNumber).each do |event|\n police += input[event] if input[event] >= 1\n \n if input[event] == -1 && police <= 0\n ans += 1\n elsif input[event] == -1\n police -= 1\n end\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\nplc, crm = 0, 0\ngets.split(' ',n).map(&:to_i).each do |x|\n plc += x\n if plc < 0\n crm += 1\n plc = 0\n end\nend\nputs crm"}, {"source_code": "#!/usr/bin/ruby\ngets\nr=0\nn=0\ngets.split.each{|e|\n\tn+=e.to_i\n\tif n<0\n\t\tr+=-n\n\t\tn=0\n\tend\n}\np r"}, {"source_code": "police = 0\nans = 0\ngets.chomp\ngets.chomp.split(\" \").each { |p|\n if p.to_i > -1\n police += p.to_i\n elsif police > 0\n police -= 1\n else\n ans += 1\n end\n}\n\nputs ans\n"}, {"source_code": "n = gets.to_i\nevents = gets.chomp.split(\" \").map{ |e| e.to_i }\ns = 0\np = 0\nevents.each{ |event|\n\tif event < 0\n\t\tif p > 0\n\t\t\tp -= 1\n\t\telse \n\t\t\ts += 1\n\t\tend\n\telse\n\t\tp += event\n\tend \n}\nputs(s)"}], "negative_code": [{"source_code": "police = 0\nans = 0\ngets.chomp\ngets.chomp.split(\" \").each { |p|\n if p.to_i == 1\n police += 1\n elsif police > 0\n police -= 1\n else\n ans += 1\n end\n}\n\nputs ans\n"}, {"source_code": "n = gets.to_i\nevents = gets.chomp.split(\" \").map{ |e| e.to_i }\ns = 0\np = 0\nevents.each{ |event|\n\tif event == -1\n\t\tif p >= 0\n\t\t\tp -= 1\n\t\telse \n\t\t\ts += 1\n\t\tend\n\telse\n\t\tp+=1\n\tend \n}\nputs(s)"}, {"source_code": "n = gets.to_i\nevents = gets.chomp.split(\" \").map{ |e| e.to_i }\ns = 0\np = 0\nevents.each{ |event|\n\tif event == -1\n\t\tif p > 0\n\t\t\tp -= 1\n\t\telse \n\t\t\ts += 1\n\t\tend\n\telse\n\t\tp+=1\n\tend \n}\nputs(s)"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nx = 0\ny = 0\n\nfor i in a\n if i == -1\n if x > 0\n x -= 1\n else\n y += 1\n end\n else\n x += 1\n end\nend\n\nprint y\n"}, {"source_code": "n,v=gets.to_i,gets.split.map(&:to_i)\ns=0\np v.map {|x| s+=x}.min.abs"}, {"source_code": "gets\nf=a=0\ngets.split.each{|s| \n\tif s[1] \n\t\tif f<0\n\t\t\ta+=1\n\t\telse\n\t\t\tf-=1\n\t\tend\n\telse\n\t\tf+=1\n\tend\n}\np a"}, {"source_code": "n = gets.chomp\nevents = gets.chomp.split(' ').map(&:to_i)\nans = f = 0\nevents.reverse.each { |e| f == 0 && e == 1 ? next : (f, ans = 1, ans + e) }\nputs ans.abs"}], "src_uid": "af47635f631381b4578ba599a4f8b317"} {"source_code": "k,d,t = gets.split.map(&:to_i)\nif k > d\n d = (k/d.to_f).ceil * d\nend\n\nper = k + (d-k)/2.to_f\nn = (t/per).to_i\nans = n * d\nif (t-per*n) <= k\n ans += t - per*n\nelsif\n ans += k + (t-k-per*n)*2\nend\nputs ans\n", "positive_code": [{"source_code": "k, d, t = gets().split().map{|x| 2*(x.to_i)}\nr = (d - k%d) % d\nn = k/d\nn += 1 if r != 0\n\nans = 0\nif t <= k\n\tans += t\nelse\n\tcycle = k + r/2\n\tans += t/cycle * n * d\n\tt %= cycle\n\tif t <= k\n\t\tans += t\n\telse\n\t\tans += k + 2*(t-k)\n\tend\nend\n\nputs \"%.10f\" % [ans/2.0]\n"}, {"source_code": "K,D,T=gets.split.map(&:to_f)\nS=(K/D).ceil*D\ndef f(t)\n (t/S).floor*(K+(S-K)*0.5)+[t%S,K].min+[0,t%S-K].max*0.5\nend\nl=T\nr=2*T\n100.times{\n m=(l+r)/2.0\n if f(m)>T\n r=m\n else\n l=m\n end\n}\np l\n"}, {"source_code": "K,D,T=gets.split.map(&:to_f)\nS=(K/D).ceil*D\n# def f(t)\n# (t/S).floor*(K+(S-K)*0.5)+[t%S,K].min+[0,t%S-K].max*0.5\n# end\n# l=T\n# r=2*T\n# 100.times{\n# m=(l+r)/2.0\n# if f(m)>T\n# r=m\n# else\n# l=m\n# end\n# }\n# p l\n\nans = 0\n\na = (S + K) * 0.5\nans += (T/a).floor * S\nT -= (T/a).floor * a\n\nans += [T, K].min\nT -= [T, K].min\n\nif T > 0\n ans += 2 * T\nend\n\np ans\n"}], "negative_code": [{"source_code": "k,d,t = gets.split.map(&:to_i)\nif k > d\n d = (k/d.to_f).ceil * d\nend\n\ntrial = k + (d-k)/2.to_f\nn = (t/trial).to_i\na = n * d\nif (t-trial*n) <= k\n ans = n * d + t-trial*n\nelsif\n ans = n * d + k + (t-trial*n-k)/2.to_f\nend\nsprintf(\"%.0f\", ans.to_f)\n"}, {"source_code": "k,d,t = gets.split.map(&:to_i)\nif k > d\n d = (k/d.to_f).ceil * d\nend\n\ntrial = k + (d-k)/2.to_f\nn = (t/trial).to_i\na = n * d\nif (t-trial*n) <= k\n ans = n * d + t-trial*n\nelsif\n ans = n * d + k + (t-trial*n-k)/2.to_f\nend\nprintf(\"%.0f\", ans)\n"}, {"source_code": "k,d,t = gets.split.map(&:to_i)\nif k > d\n d = (k/d.to_f).ceil * d\nend\n\ntrial = k + (d-k)/2.to_f\nn = (t/trial).to_i\na = n * d\nif (t-trial*n) <= k\n ans = n * d + t-trial*n\nelsif\n ans = n * d + k + (t-trial*n-k)/2.to_f\nend\nputs ans\n"}, {"source_code": "k,d,t = gets.split.map(&:to_i)\nif k > d\n d = (k/d.to_f).ceil * d\nend\n\nper = k + (d-k)/2.to_f\nn = (t/per).to_i\nans = n * d\np ans\np n*per\nif (t-per*n) <= k\n ans += t - per*n\nelsif\n ans += k + (t-k-per*n)*2\nend\nputs sprintf(\"%.9f\", ans)\n"}, {"source_code": "k,d,t = gets.split.map(&:to_i)\nif k > d\n d = (k/d.to_f).ceil * d\nend\n\nper = k + (d-k)/2.to_f\nn = (t/per).to_i\nans = n * d\np ans\np n*per\nif (t-per*n) <= k\n ans += t - per*n\nelsif\n ans += k + (t-k-per*n)*2\nend\nputs ans\n"}], "src_uid": "9df3a94dfa537cabdc52388a771cd24f"} {"source_code": "n = gets.to_i\nf = gets.split.map { |x| x.to_i }\n\nacc = 0\nhash = Hash.new(0)\nf.each do |x|\n\tacc += x\n\thash[acc] += 1\nend\n\nans = 0\nhash.each do |key, val|\n\tans = [ans, val].max\nend\n\nputs n - ans\n", "positive_code": [{"source_code": "n = readline.to_i\narr = readline.split(' ').collect(&:to_i)\nmp = Hash.new(0)\nbest = 0\nsum = 0\narr.each do |num|\n sum += num\n mp[sum] += 1\n best = [best, mp[sum]].max\nend\nputs n - best\n"}], "negative_code": [{"source_code": "n = readline.to_i\narr = readline.split(' ').collect(&:to_i)\nmp = Hash.new\nmp[0] = true\nsum = 0\nct = 0\nfound = false\narr.each do |num|\n sum += num\n if found\n if sum == 0\n ct += 1\n end\n else\n if mp.has_key?(sum)\n found = true\n sum = 0\n ct += 1\n else\n mp[sum] = true\n end\n end\nend\nif found && sum != 0\n ct += 1\nend\nputs n - ct\n"}, {"source_code": "n = readline.to_i\narr = readline.split(' ').collect(&:to_i)\nmp = Hash.new\nmp[0] = true\nsum = 0\nct = 0\nfound = false\narr.each do |num|\n sum += num\n if found\n if sum == 0\n ct += 1\n end\n else\n if mp.has_key?(sum)\n found = true\n ct += 1\n else\n mp[sum] = true\n end\n end\nend\nputs n - ct\n"}, {"source_code": "n = readline.to_i\narr = readline.split(' ').collect(&:to_i)\nmp = Hash.new\nmp[0] = true\nsum = 0\nct = 0\nfound = false\narr.each do |num|\n sum += num\n if found\n if sum == 0\n ct += 1\n end\n else\n if mp.has_key?(sum)\n found = true\n ct += 1\n end\n end\nend\nputs n - ct\n"}], "src_uid": "be12bb8148708f9ad3dc33b83b55eb1e"} {"source_code": " t = gets.to_i\r\n t.times{|w|\r\n n = gets.to_i\r\n board = [gets.chomp.to_s,gets.chomp.to_s]\r\n path = [0,0]\r\n find = false\r\n visited = []\r\n while path.size != 0\r\n node = path.shift\r\n if node[0] == n-1 && node[1] == 1\r\n find = true\r\n break\r\n end\r\n if (!visited.include?(node))\r\n visited<=0 && y < 2}\r\n dir.map{|w|\r\n if (board[w[1]][w[0]] == \"0\")\r\n path<= mx\n puts \"YES\"\n else\n puts \"NO\"\n end\n}"}], "negative_code": [{"source_code": "a = gets.chomp.to_i\n(0..a-1).each do |i|\n s = gets.chomp.split(' ')\n r = s[0].to_i; g = s[1].to_i; b = s[2].to_i;\n if ((r/g)>2 || (r/b)>2 || (g/b)>2 || (g/r)>2 || (b/r)>2 || (b/g)>2)\n puts 'No'\n else\n puts 'Yes'\n end\nend\n"}, {"source_code": "a = gets.chomp.to_i\n(0..a-1).each do |i|\n s = gets.chomp.split(' ')\n r = s[0].to_i; g = s[1].to_i; b = s[2].to_i;\n if ((r-g).abs>2 || (r-b).abs>2 || (g-b).abs>2)\n puts 'No'\n else\n puts 'Yes'\n end\nend"}, {"source_code": "gets.strip.to_i.times {\n x, y, k = gets.strip.split(' ').map(&:to_i)\n if [x, y, k].max - [x, y, k].min <= 3\n puts \"YES\"\n else\n puts \"NO\"\n end\n}"}], "src_uid": "34aa41871ee50f06e8acbd5eee94b493"} {"source_code": "k,d=gets.chomp.split.map(&:to_i)\nif d==0\n\tif k==1\n\t\tputs \"0\"\n\telse\n\t\tputs \"No solution\"\n\tend\nelsif d>0\n\tputs d*(10**(k-1))\nelse\n\tputs \"No solution\"\nend", "positive_code": [{"source_code": "k, d = gets.chomp.split(/ /).map(&:to_i)\nif k > 1 && d == 0\n puts \"No solution\"\nelse\n if k == 1 && d == 0\n puts 0\n else\n puts \"#{d * (10 ** (k - 1))}\"\n end\nend\n"}, {"source_code": "k, d = gets.split.map(&:to_i)\nif d == 0 && k > 1\n print \"No solution\"\nelse\n print d\n for i in 1..k-1\n print 0\n end\nend"}, {"source_code": "# def digital_root(n)\n# \treturn @dp[n] if @dp[n]\n# \ts = n.to_s.split(\"\").map(&:to_i).inject(&:+)\n# \tif s < 10\n# \t\t@dp[n] = s\n# \t\treturn s\n# \tend\n# \t@dp[n] = digital_root(s)\n# \treturn @dp[n]\n# end\n\n# digits,d = gets.split(\" \").map(&:to_i)\n# @dp = {}\n# start = 10 ** (digits - 1)\n# start = 0 if start == 1\n# finish = (10 ** digits) - 1\n# ans = nil\n# if d == 0\n# \tif digits == 1\n# \t\tans = 0\n# \tend\n# else\n# \t(start..finish).each do |a|\n# \t\tif digital_root(a) == d\n# \t\t\tans = a\n# \t\t\tbreak\n# \t\tend\n# \tend\n# end\n# if ans\n# \tputs ans\n# else\n# \tputs \"No solution\"\n# end\n\n\ndef digital_root(n)\n\ts = n.to_s.split(\"\").map(&:to_i).inject(&:+)\nend\n\ndigits,d = gets.split(\" \").map(&:to_i)\n@dp = {}\nstart = 10 ** (digits - 1)\nstart = 0 if start == 1\nfinish = start + 10\nans = nil\n\n(start..finish).each do |a|\n\tif digital_root(a) == d\n\t\tans = a\n\t\tbreak\n\tend\nend\n\nif ans\n\tputs ans\nelse\n\tputs \"No solution\"\nend\n"}, {"source_code": "def digital_root(n)\n\treturn @dp[n] if @dp[n]\n\ts = n.to_s.split(\"\").map(&:to_i).inject(&:+)\n\tif s < 10\n\t\t@dp[n] = s\n\t\treturn s\n\tend\n\t@dp[n] = digital_root(s)\n\treturn @dp[n]\nend\n\ndigits,d = gets.split(\" \").map(&:to_i)\n@dp = {}\nstart = 10 ** (digits - 1)\nstart = 0 if start == 1\nfinish = (10 ** digits) - 1\nans = nil\nif d == 0\n\tif digits == 1\n\t\tans = 0\n\tend\nelse\n\t(start..finish).each do |a|\n\t\tif digital_root(a) == d\n\t\t\tans = a\n\t\t\tbreak\n\t\tend\n\tend\nend\nif ans\n\tputs ans\nelse\n\tputs \"No solution\"\nend\n"}, {"source_code": "puts [gets.split.map(&:to_i)].map{|x| ((x[0]>1 && x[1]==0)? \"No solution\" : x[1]*(10**(x[0]-1)))}[0]"}, {"source_code": "k, d = gets.split.collect{|i| i.to_i}\nif d == 0\n if k == 1\n puts 0\n else\n puts 'No solution'\n end\n exit\nend\nputs (Array.new([d])+Array.new(k-1,0)).join\n"}, {"source_code": "def solution(k, n)\n return 0 if n == 0 && k == 1\n return \"No solution\" if n == 0 && k > 1\n\n num = num_k(k)\n\n until dr(num) == n || num.to_s.size != k do\n num += 1\n end\n\n return \"No solution\" if num.to_s.size != k \n num\nend\n\ndef num_k(k)\n min_num = \"1\"\n\n (k-1).times { |i| min_num << \"0\" }\n min_num.to_i\nend\n\ndef dr(n)\n return n if n < 10\n num = n.to_s.split('').map(&:to_i).inject(:+)\n dr(num)\nend\n\nk, n = STDIN.gets.chomp.split(\" \").map(&:to_i)\nputs solution(k, n)\n"}, {"source_code": "k, d = gets.split\n\nif k == '1'\n puts d\nelse\n if d == '0'\n puts 'No solution'\n else\n puts d + ('0' * k.to_i.pred)\n end\nend"}, {"source_code": "k, d = gets.chomp.split.map{ |i| i.to_i}\n\nif d == 0 and k > 1\n\tputs \"No solution\"\nelse\n\tputs (d.to_s + (\"0\" * (k - 1)))\nend\n\n"}, {"source_code": "line = gets\nline = line.split(\" \");\nk = line[0].to_i\nd = line[1].to_i\n\nans = d * 10**(k-1) \n\nif d == 0 && k > 1\n ans = \"No solution\"\nend \n\nans = ans.to_s << \"\\n\"\nprint(ans)"}, {"source_code": "k,d=gets.chomp.split(\" \")\nputs \"No solution\" if k != \"1\" && d == \"0\"\nputs 0 if k == \"1\" && d == \"0\"\nputs \"#{d}#{\"0\"*(k.to_i-1)}\" if d != \"0\""}, {"source_code": "k, d = gets.split.map(&:to_i)\n\nif d == 0 && k > 1\n print \"No solution\"\nelse\n print d\n for i in 1...k\n print 0\n end\nend\n"}, {"source_code": "k,d=gets.chomp.split.map(&:to_i)\nif d==0 && k>1\n puts \"No solution\"\nelse\n print d\n (k-1).times { print 0}\nend\n"}, {"source_code": "k,d=gets.chomp.split.map &:to_i \nputs d==0&&k>1?\"No solution\":d.to_s+'0'*(k-1)\n"}, {"source_code": "dcnt, droot = gets.split.map{|s| s.to_i}\n\nif droot == 0 && dcnt > 1\n\tputs \"No solution\"\nelse\n\tprint droot\n\t(dcnt-1).times {print 0}\nend\n"}, {"source_code": "k,d=gets.chomp.split.map &:to_i \nputs d==0&&k>1?\"No solution\":d.to_s+'0'*(k-1)\n"}, {"source_code": "class A\n def initialize\n k, n = gets.chomp.split(' ').map(&:to_i)\n\n start = 0\n limit = 9 * k\n\n if k > 1 && n == 0\n puts \"No solution\"\n exit\n end\n\n (0..limit).each do |num|\n res = dfs(num)\n\n if res == n \n puts answer(num, k)\n exit\n end\n end\n\n puts \"No solution\"\n end\n\n def answer(num, k)\n list = [ 9, 8, 7, 6, 5, 4, 3, 2, 1 ]\n index = 0\n answer = \"\"\n while num != 0\n count = num / list[index]\n num %= list[index]\n answer += list[index].to_s * count\n index += 1\n end\n\n if answer.to_s.size != k\n diff = k - answer.to_s.size\n answer += \"0\" * diff\n end\n \n answer\n end\n\n def dfs(num)\n if num < 10\n return num\n else\n return dfs(sum_digit(num))\n end\n end\n\n def sum_digit(num)\n str = num.to_s\n\n str.chars.map(&:to_i).inject(:+)\n end\nend\n\na = A.new"}], "negative_code": [{"source_code": "line = gets\nline = line.split(\" \");\nk = line[0].to_i\nd = line[1].to_i\nmax = 10 ** (d-1)\n\nwhile 1 && d != 0\n ans = rand((10**d) - 1) + max\n if ans % 9 == k\n break\n end\nend\n\nif d == 0 \n ans = 0\nend\n\np ans"}, {"source_code": "line = gets\nline = line.split(\" \");\nk = line[0].to_i\nd = line[1].to_i\nmax = 10 ** (k-1)\n\nif d != 0\n d = 0 if d == 9\n ans = rand((10**k) - 1) + max\n while ans % 9 != d\n ans += 1\n end\nelse\n if k == 1\n ans = 0\n else\n ans = \"No solution\"\n end\nend\n\nans = ans.to_s << \"\\n\"\nprint(ans)"}, {"source_code": "line = gets\nline = line.split(\" \");\nk = line[0].to_i\nd = line[1].to_i\nmax = 10 ** (k-1)\n\nwhile 1 && d != 0\n ans = rand((10**k) - 1) + max\n if ans % 9 == d\n break\n end\nend\n\nif d == 0 \n ans = 0\nend\n\np ans"}, {"source_code": "line = gets\nline = line.split(\" \");\nk = line[0].to_i\nd = line[1].to_i\nmax = 10 ** d\n\nwhile 1\n ans = rand(max-1) + max\n if ans % 9 == k\n break\n end\nend\n\np ans"}, {"source_code": "line = gets\nline = line.split(\" \");\nk = line[0].to_i\nd = line[1].to_i\nmax = 10 ** d\n\nwhile 1 && d != 0\n ans = rand(max-1) + max\n if ans % 9 == k\n break\n end\nend\n\nif d == 0 \n ans = 0\nend\n\np ans"}, {"source_code": "k,d=gets.chomp.split(\" \")\nputs \"No solution\" if k == \"0\" && d == \"0\"\nputs 0 if k == \"1\" && d == \"0\"\nputs \"#{d}#{\"0\"*(k.to_i-1)}\" if d != \"0\""}, {"source_code": "class A\n def initialize\n k, n = gets.chomp.split(' ').map(&:to_i)\n\n start = 0\n limit = 9 * k\n\n (0..limit).each do |num|\n res = dfs(num)\n\n if res == n \n puts answer(num, k)\n exit\n end\n end\n\n puts \"No solution\"\n end\n\n def answer(num, k)\n list = [ 9, 8, 7, 6, 5, 4, 3, 2, 1 ]\n index = 0\n answer = \"\"\n while num != 0\n count = num / list[index]\n num %= list[index]\n answer += list[index].to_s * count\n index += 1\n end\n\n if answer.to_s.size != k\n diff = k - answer.to_s.size\n answer += \"0\" * diff\n end\n \n answer\n end\n\n def dfs(num)\n if num < 10\n return num\n else\n return dfs(sum_digit(num))\n end\n end\n\n def sum_digit(num)\n str = num.to_s\n\n str.chars.map(&:to_i).inject(:+)\n end\nend\n\na = A.new"}, {"source_code": "k, d = gets.chomp.split(/ /).map(&:to_i)\nif k > 1 && d == 0\n puts \"No solution\"\nelse\n if k == 1 && d == 0\n puts 0\n else\n puts \"#{k * (10 ** (d - 1))}\"\n end\nend\n"}, {"source_code": "def digital_root(n)\n\treturn @dp[n] if @dp[n]\n\ts = n.to_s.split(\"\").map(&:to_i).inject(&:+)\n\tif s < 10\n\t\t@dp[n] = s\n\t\treturn s\n\tend\n\t@dp[n] = digital_root(s)\n\treturn @dp[n]\nend\n\ndigits,d = gets.split(\" \").map(&:to_i)\n@dp = {}\nstart = 10 ** (digits - 1)\nstart = 0 if start == 1\nfinish = (10 ** digits) - 1\nans = nil\nif d == 0\n\tif digits == 0\n\t\tans = 0\n\tend\nelse\n\t(start..finish).each do |a|\n\t\tif digital_root(a) == d\n\t\t\tans = a\n\t\t\tbreak\n\t\tend\n\tend\nend\nif ans\n\tputs ans\nelse\n\tputs \"No Solution\"\nend\n"}, {"source_code": "def digital_root(n)\n\treturn @dp[n] if @dp[n]\n\ts = n.to_s.split(\"\").map(&:to_i).inject(&:+)\n\tif s < 10\n\t\t@dp[n] = s\n\t\treturn s\n\tend\n\t@dp[n] = digital_root(s)\n\treturn @dp[n]\nend\n\ndigits,d = gets.split(\" \").map(&:to_i)\n@dp = {}\nstart = 10 ** (digits - 1)\nstart = 0 if start == 1\nfinish = (10 ** digits) - 1\nans = nil\nif d == 0\n\tif digits == 1\n\t\tans = 0\n\tend\nelse\n\t(start..finish).each do |a|\n\t\tif digital_root(a) == d\n\t\t\tans = a\n\t\t\tbreak\n\t\tend\n\tend\nend\nif ans\n\tputs ans\nelse\n\tputs \"No Solution\"\nend\n"}, {"source_code": "puts [gets.split.map(&:to_i)].map{|x| ((x[0]>0 && x[1]==0)? \"No solution\" : x[1]*(10**(x[0]-1)))}[0]"}, {"source_code": "p [gets.split.map(&:to_i)].map{|x| x[1]*(10**(x[0]-1))}.max"}, {"source_code": "p [gets.split.map(&:to_i)].map{|x| x[1]*(10**x[0])}.max"}, {"source_code": "def solution(k, n)\n return 0 if n == 0\n\n num = num_k(k)\n\n until dr(num) == n || num.to_s.size != k do\n num += 1\n end\n\n return \"No solution\" if num.to_s.size != k\n num\nend\n\ndef num_k(k)\n num = \"1\"\n (k-1).times { |i| num << \"0\" }\n num.to_i\nend\n\ndef dr(n)\n num = n.to_s.split('').map(&:to_i).inject(:+)\n return dr(num) if num >= 10\n num\nend\n\nk, n = STDIN.gets.chomp.split(\" \").map(&:to_i)\nputs solution(k, n)\n"}, {"source_code": "def solution(k, n)\n return 0 if n == 0\n\n\n num = num_k(k)\n\n until dr(num) == n || num.to_s.size != k do\n num += 1\n end\n\n return \"No solution\" if num.to_s.size != k\n num\nend\n\ndef num_k(k)\n min_num = \"1\"\n\n (k-1).times { |i| min_num << \"0\" }\n min_num.to_i\nend\n\ndef dr(n)\n return n if n < 10\n num = n.to_s.split('').map(&:to_i).inject(:+)\n dr(num)\nend\n\nk, n = STDIN.gets.chomp.split(\" \").map(&:to_i)\nputs solution(k, n)\n"}, {"source_code": "def solution(k, n)\n return 0 if n == 0\n\n min_num, max_num = num_k(k)\n\n num = rand(min_num..max_num) \n\n until dr(num) == n || num.to_s.size != k do\n num += 1\n end\n\n return \"No solution\" if num.to_s.size != k\n num\nend\n\ndef num_k(k)\n min_num = \"1\"\n max_num = \"1\"\n\n (k-1).times { |i| min_num << \"0\" }\n k.times { |i| max_num << \"0\" }\n [min_num.to_i, max_num.to_i]\nend\n\ndef dr(n)\n num = n.to_s.split('').map(&:to_i).inject(:+)\n return dr(num) if num >= 10\n num\nend\n\nk, n = STDIN.gets.chomp.split(\" \").map(&:to_i)\nputs solution(k, n)\n"}, {"source_code": "def solution(k, n)\n return 0 if n == 0\n\n num = num_k(k)\n until dr(num) == n && num.to_s.size == k do\n num += 1\n end\n\n return \"No solution\" if num.to_s.size != k\n num\nend\n\ndef num_k(k)\n num = \"1\"\n (k-1).times { |i| num << \"0\" }\n num.to_i\nend\n\ndef dr(n)\n num = n.to_s.split('').map(&:to_i).inject(:+)\n return dr(num) if num >= 10\n num\nend\n\nk, n = STDIN.gets.chomp.split(\" \").map(&:to_i)\nputs solution(k, n)\n"}, {"source_code": "def solution(k, n)\n return 0 if n == 0\n\n min_num, max_num = num_k(k)\n\n num = rand(min_num..max_num) \n\n until dr(num) == n || num.to_s.size != k do\n num += 1\n end\n\n return \"No solution\" if num.to_s.size != k\n num\nend\n\ndef num_k(k)\n min_num = \"1\"\n max_num = \"1\"\n\n (k-1).times { |i| min_num << \"0\" }\n k.times { |i| max_num << \"0\" }\n [min_num.to_i, max_num.to_i]\nend\n\ndef dr(n)\n return n if n < 10\n num = n.to_s.split('').map(&:to_i).inject(:+)\n return dr(num) if num >= 10\n num\nend\n\nk, n = STDIN.gets.chomp.split(\" \").map(&:to_i)\nputs solution(k, n)\n"}, {"source_code": "k, d = gets.split.map(&:to_i)\n\nif k.zero?\n if d.zero?\n puts 0\n else\n puts 'No solution'\n end\nelse\n puts d.to_s + ('0' * k.pred)\nend"}, {"source_code": "k, d = gets.split.map(&:to_i)\n\nif d.zero?\n if k.zero?\n puts 0\n else\n puts 'No solution'\n end\nelse\n puts d.to_s + ('0' * k.pred)\nend"}], "src_uid": "5dd0d518f315d81204b25e48fea0793a"} {"source_code": "gets.to_i.times do\n n = gets.to_i\n\n if n.odd?\n puts '-1'\n next\n end\n\n puts \"0 0 #{n / 2}\"\nend\n", "positive_code": [{"source_code": "a = gets.chomp.to_i\r\nuntil a == 0 do\r\n x = gets.chomp.to_i\r\n if x % 2 == 0\r\n puts \"#{x/2} 0 #{x/2}\"\r\n else\r\n puts -1\r\n end\r\n a -= 1\r\nend"}, {"source_code": "num_cases = gets.to_i\nfor i in (1..num_cases)\n n = gets.to_i\n if n % 2 == 0\n puts \"0 0 #{n/2}\"\n else\n puts \"-1\"\n end\nend\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n if n % 2 == 0\r\n a, b, c = n / 2 ^ 1, n / 2 ^ 1, 1\r\n puts [a, b, c] * \" \"\r\n else\r\n p -1\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "num_cases = gets.to_i\nfor i in (1..num_cases)\n n = gets.to_i\n if n % 2 == 0\n puts \"0 #{n/2} #{n/2+1}\"\n else\n puts \"-1\"\n end\nend\n"}], "src_uid": "43041076ddd0bbfac62cd4abf4536282"} {"source_code": "#!/usr/bin/ruby\na=b=0\ngets;$<.each{|_|\n\tx,y=_.split.map &:to_i\n\ta+=1 if x>y\n\tb+=1 if xa]", "positive_code": [{"source_code": "n = gets.to_i\n\nresult = (1..n).map do\n a, b = gets.split(' ').map(&:to_i)\n (a == b) ? 0 : (a - b) / (a - b).abs\nend.inject(&:+)\n\nif result > 0\n puts 'Mishka'\nelsif result < 0\n puts 'Chris'\nelse\n puts 'Friendship is magic!^^'\nend\n"}, {"source_code": "n = gets.to_i\ns = 0\nfor i in 1..n do\n a, b = gets.split.map(&:to_i)\n if a > b then\n s += 1\n elsif a < b then\n s -= 1\n end\nend\nif s > 0 then\n puts 'Mishka'\nelsif s < 0 then\n puts 'Chris'\nelse\n puts 'Friendship is magic!^^'\nend"}, {"source_code": "gameNum = gets.chomp.to_i\n\nmWin = 0\ncWin = 0\n\ngameNum.times do\n\tm, c = gets.chomp.split(' ').map(&:to_i)\n\n\tif m > c\n\t\tmWin += 1\n\telsif c > m\n\t\tcWin += 1\n\tend\nend\n\nif mWin > cWin\n\tputs 'Mishka'\nelsif cWin > mWin\n\tputs 'Chris'\nelse\n\tputs 'Friendship is magic!^^'\nend"}, {"source_code": "n = Integer(gets)\na, b = 0, 0\nn.times do\n aa, bb = gets.split.map(&:to_i)\n if aa > bb\n a += 1\n end\n if aa < bb\n b += 1\n end\nend\n\nif a > b\n puts \"Mishka\"\nend\n\nif a < b\n puts \"Chris\"\nend\n\nif a == b\n puts \"Friendship is magic!^^\"\nend"}, {"source_code": "n = gets.strip.to_i\nm_count = c_count = 0\nn.times do\n m, c = gets.strip.split.map(&:to_i)\n m_count += 1 if m > c\n c_count += 1 if c > m\nend\nans = \"Friendship is magic!^^\"\nif m_count > c_count\n ans = \"Mishka\"\nelsif m_count < c_count\n ans = \"Chris\"\nend\nputs ans\n"}, {"source_code": "n=gets.to_i\nans=0\nn.times{\n\ta,b=gets.split.map{|e| e.to_i}\n\tans=ans+(a<=>b)\n}\nputs [\"Chris\",\"Friendship is magic!^^\",\"Mishka\"][(ans<=>0)+1]"}, {"source_code": "n = gets.to_i\nr = 0\nn.times do |i|\n\tm,c = gets.split.map(&:to_i)\n\tif m > c \n\t\tr += 1\n\telsif c > m\n\t\tr -= 1\n\tend\nend\nif r > 0\n\tputs 'Mishka'\nelsif r < 0\n\tputs 'Chris'\nelse\n\tputs 'Friendship is magic!^^'\nend\n\t"}, {"source_code": "n = gets.to_i\nr = 0\n\n(1..n).each do\n a, b = gets.split.map(&:to_i)\n r += a <=> b\nend\n\nputs case\n when r > 0\n 'Mishka'\n when r < 0\n 'Chris'\n else\n 'Friendship is magic!^^'\n end"}, {"source_code": "gets;r=0;$<.map{|e|r+=eval(e.split*\"<=>\")};puts r>0?'Mishka':r<0?'Chris':'Friendship is magic!^^'"}, {"source_code": "n = gets.to_i\n\nm = 0\nc = 0\n\nn.times do\n a,b = gets.split.map(&:to_i)\n m+=1 if a > b\n c+=1 if b > a\nend\n\nif m > c\n puts \"Mishka\"\nelsif c > m\n puts \"Chris\"\nelse\n puts \"Friendship is magic!^^\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\na, b = 0, 0\n\nn.times do\n c, d = gets.chomp.split.map(&:to_i)\n next if c == d\n c > d ? a += 1 : b += 1\nend\n\ncase\nwhen a == b\n puts \"Friendship is magic!^^\"\nwhen a > b\n puts \"Mishka\"\nelse\n puts \"Chris\"\nend\n"}, {"source_code": "gets;r=0;$<.map{|e|r+=eval(e.split*\"<=>\")};puts r>0?'Mishka':r<0?'Chris':'Friendship is magic!^^'"}, {"source_code": "n = gets.to_i\nc = 0\nm = 0\n(0...n).each do\n a, b = gets.split.map &:to_i\n if (a < b) \n c += 1\n else \n if (a > b)\n m += 1\n end\n end\nend\n\nif (c == m)\n puts \"Friendship is magic!^^\"\nelse \n if (m > c)\n puts \"Mishka\"\n else \n puts \"Chris\"\n end\nend\n"}, {"source_code": "n = gets.to_i()\nmishka = 0\nchris = 0\nfor i in (1..n)\n mc = gets.split(' ')\n if mc[0].to_i() > mc[1].to_i()\n mishka += 1\n elsif mc[0].to_i() < mc[1].to_i()\n chris += 1\n end\nend\nif mishka > chris\n puts \"Mishka\"\nelsif mishka == chris\n puts \"Friendship is magic!^^\"\nelse\n puts \"Chris\"\nend\n"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nN = gi\nMC = ngis N\n\nv = MC.map{|m, c| m <=> c }.inject(:+)\n\ncase\nwhen v < 0\n puts 'Chris'\nwhen v > 0\n puts 'Mishka'\nelse\n puts 'Friendship is magic!^^'\nend\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nrounds = gets.to_i\nmishka_wins = 0\nchris_wins = 0\ndraws = 0\nrounds.times {\n mishka, chris = gets.split.map(&:to_i)\n\n if mishka > chris\n mishka_wins += 1\n elsif mishka < chris\n chris_wins += 1\n else\n draws += 0\n end\n}\n\nif mishka_wins > chris_wins\n puts \"Mishka\"\nelsif mishka_wins < chris_wins\n puts \"Chris\"\nelse\n puts \"Friendship is magic!^^\"\nend"}, {"source_code": "n = gets.to_i\nar = [0,0]\nn.times do\n s = gets.split.map(&:to_i)\n ar[0] += 1 if s[0] > s[1]\n ar[1] += 1 if s[1] > s[0]\nend\nputs \"Mishka\" if ar[0] > ar[1]\nputs \"Chris\" if ar[1] > ar[0]\nputs \"Friendship is magic!^^\" if ar[0] == ar[1]"}, {"source_code": "mc = 0\ncc = 0\ngets.to_i.times do\n m, c = gets.split.map(&:to_i)\n if m > c\n mc += 1\n elsif m < c\n cc += 1\n end\nend\n\nif mc > cc\n puts 'Mishka'\nelsif mc < cc\n puts 'Chris'\nelse\n puts 'Friendship is magic!^^'\nend\n"}, {"source_code": "n = gets.to_i\nwins = Hash.new(0)\nn.times.map do\n a, b = gets.split.map(&:to_i)\n if a - b > 0\n wins['Mishka'] += 1\n elsif a - b < 0\n wins['Chris'] += 1\n end\nend\nputs wins['Mishka'] == wins['Chris'] ? 'Friendship is magic!^^' : wins.max_by{|k, v| v}[0]\n\n"}, {"source_code": "games = gets.chomp.to_i\nresults = []\nfor i in (0..games-1)\n\tresults[i] = gets.chomp\nend\n\ncount = 0\nfor i in (0..games-1)\n\tsplit = results[i].split\n\tif split[0].to_i > split[1].to_i\n\t\tcount += 1\n\telsif split[0].to_i < split[1].to_i\n\t\tcount -= 1\n\telse\n\t\tcount += 0\n\tend\nend\n\nif count > 0\n\tprint \"Mishka\"\nelsif count == 0\n\tprint \"Friendship is magic!^^\"\nelse\n\tprint \"Chris\"\nend\n"}, {"source_code": "a=[0,0,0]\ng=[\"Friendship is magic!^^\",\"Mishka\",\"Chris\"]\ngets.to_i.times {|x| s=gets.split.map(&:to_i); a[s[0]<=>s[1]]+=1; }\nputs g[a[1]<=>a[-1]]"}, {"source_code": "n = gets.to_i\nm = c = 0\nfor i in 1..n\n mi, ch = gets.split.map(&:to_i)\n if mi > ch\n m += 1\n elsif ch > mi\n c += 1\n end\nend\n\nif m > c\n puts 'Mishka'\nelsif m < c\n puts 'Chris'\nelse\n puts 'Friendship is magic!^^'\nend\n"}, {"source_code": "a=b=0\ngets.to_i.times do\n\tx = gets.split.map(&:to_i)\n\ta+=1 if x[0]>x[1]\n\tb+=1 if x[0]b]"}, {"source_code": "n = gets.to_i\nm=0\nc=0\nn.times do\n\tx,y = gets.split.map(&:to_i)\n\tif x>y\n\t\tm+=1\n\telsif xc\n\tputs \"Mishka\"\nelsif c>m\n\tputs \"Chris\"\nelse\n\tputs \"Friendship is magic!^^\"\nend"}, {"source_code": "jj = 0\ngets.to_i.times do\n aa, bb = gets.split.map(&:to_i)\n jj += aa <=> bb\nend\n\nif jj > 0 \n puts \"Mishka\"\nelsif jj < 0\n puts \"Chris\"\nelse \n puts \"Friendship is magic!^^\"\nend"}], "negative_code": [{"source_code": "n = gets.to_i\nar = [0,0]\nn.times do\n s = gets.split.map(&:to_i)\n ar[0] += s[0]\n ar[1] += s[1]\nend\nputs \"Mishka\" if ar[0] > ar[1]\nputs \"Chris\" if ar[1] > ar[0]\nputs \"Friendship is magic!^^\" if ar[0] == ar[1]"}, {"source_code": "n = gets.to_i\nr = 0\nn.times do |i|\n\tm,c = gets.split.map(&:to_i)\n\tif m > c \n\t\tr += 1\n\telsif c > m\n\t\tr -= 1\n\tend\nend\nif r > 0\n\tp 'Mishka'\nelsif r < 0\n\tp 'Chris'\nelse\n\tp 'Friendship is magic!^^'\nend\n\t"}, {"source_code": "gets;r=0;$<.map{|e|r+=eval(e.split*\"<=>\")};puts r>0?'Mishka':r<0?'Chris':'Friendship is magic^^'"}, {"source_code": "games = gets.chomp.to_i\nresults = []\nfor i in (0..games-1)\n\tresults[i] = gets.chomp\nend\n\ncount = 0\nfor i in (0..games-1)\n\tsplit = results[i].split\n\tfor x in (0..1)\n\t\tif split[0].to_i > split[1].to_i\n\t\t\tcount += 1\n\t\telse\n\t\t\tcount -= 1\n\t\tend\n\tend\nend\n\nif count > 0\n\tprint \"Mishka\"\nelsif count == 0\n\tprint \"Friendship is magic!^^\"\nelse\n\tprint \"Chris\"\nend\n"}, {"source_code": "games = gets.chomp.to_i\nresults = []\nfor i in (0..games-1)\n\tresults[i] = gets.chomp\nend\n\nmishka = 0\nchris = 0\nfor i in (0..games-1)\n\tsplit = results[i].split\n\tmishka += split[0].to_i\n\tchris += split[1].to_i\nend\n\nif mishka > chris\n\tprint \"Mishka\"\nelsif mishka == chris\n\tprint \"Friendship is magic!^^\"\nelse\n\tprint \"Chris\"\nend\n"}, {"source_code": "a=[0,0,0]\ng=[\"Friendship is magic!^^\",\"Mishka\",\"Chris\"]\ngets.to_i.times {|x| s=gets.split.map(&:to_i); a[s[1]<=>s[0]]+=1; }\nputs g[a[1]<=>a[-1]]\n"}, {"source_code": "n = gets.to_i\nwins = Hash.new(0)\nn.times.map do\n a, b = gets.split.map(&:to_i)\n if a - b > 0\n wins['Mishka'] += 1\n elsif a - b < 0\n wins['Chris'] += 1\n end\nend\nputs wins['Mishka'] == wins['Chris'] ? 'Friendship is magic!^^' : wins.max[0]\n\n"}, {"source_code": "n = gets.to_i\nwins = Hash.new(0)\nn.times.map do\n a, b = gets.split.map(&:to_i)\n if a - b > 0\n wins['Misha'] += 1\n elsif a - b < 0\n wins['Chris'] += 1\n end\nend\nputs wins['Misha'] == wins['Chris'] ? 'Friendship is magic!^^' : wins.max[0]\n\n"}], "src_uid": "76ecde4a445bbafec3cda1fc421e6d42"} {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n ok = true\n for i in 0...(n-1) do\n if (a[i+1] - a[i]) % 2 != 0\n ok = false\n end\n end\n puts ok ? \"YES\" : \"NO\"\nend\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\n(0...t).each do |_|\n n = gets.chomp.to_i\n l = gets.chomp.split.map(&:to_i)\n num_of_odd, num_of_even = l.partition{|c| c.odd? }\n puts (!num_of_odd.size.zero? && !num_of_even.size.zero? ? \"NO\" : \"YES\")\nend\n"}, {"source_code": "tc = gets.to_i \n\ntc.times do \n n = gets.to_i \n arr = gets.split().map{|x| x.to_i} \n ev = od = 0 \n arr.each do |x| \n if x % 2 == 0 \n ev += 1\n else\n od += 1 \n end\n end\n if(ev == 0 || od == 0)\n puts \"YES\" \n else\n puts \"NO\"\n end\nend"}, {"source_code": "1.upto(gets.to_i) do\n gets\n a = gets.split(' ').map(&:to_i)\n\n puts a.all? { |e| e.even? == a.first.even? } ? 'YES' : 'NO'\nend\n"}, {"source_code": "t = gets.chomp.to_i\n(0...t).each do |_|\n n = gets.chomp.to_i\n l = gets.chomp.split.map(&:to_i)\n has_odd, has_even = false, false\n l.each{|c| c.odd? ? (has_odd = true) : (has_even = true); (break) if has_odd && has_even }\n puts (has_odd && has_even ? \"NO\" : \"YES\")\nend\n"}], "negative_code": [], "src_uid": "53a3313f5d6ce19413d72473717054fc"} {"source_code": "n=gets.to_i\na=Array.new(n)\nk=0\nfor i in 0...n do\n q=gets\n a[i]=q.to_f\n k+=q.to_i\nend\n for i in 0...n do\n if k>0 then\n if a[i].to_i != a[i].floor or a[i].to_i != a[i].ceil then\n if a[i]>0 then\n puts a[i].floor\n else\n puts a[i].floor\n k-=1\n end\n else\n puts a[i].to_i\n end\n elsif k<0 then\n if a[i].to_i != a[i].floor or a[i].to_i != a[i].ceil then\n if a[i]>0 then\n puts a[i].ceil\n k+=1\n else\n puts a[i].ceil\n end\n else\n puts a[i].to_i\n end\n else\n puts a[i].to_i\n end\n end", "positive_code": [{"source_code": "n = gets.to_i\na = n.times.map{gets.chomp}\nb = Array.new(n,0)\nsum = 0\na.each_with_index do |s,i|\n b[i] = s.to_i\n if s[0] == \"-\" && s[-5..-1] != \"00000\"\n b[i] -= 1\n end\n sum += b[i]\nend\na.each_with_index do |s,i|\n break if sum == 0\n next if s[-5..-1] == \"00000\"\n sum += 1\n b[i] += 1\nend\nputs b"}, {"source_code": "N = gets.to_i\nsd = 0\nincremantables = {}\ncs = []\n(0...N).map{ |i|\n a = gets.to_f\n c = a.floor\n cs << c\n d = a - c\n sd += d\n incremantables[i] = 1 if d > 0\n}\nsd = (sd + 0.5).floor\n\nputs (0...N).map{ |i| \n if sd > 0 && incremantables[i]\n sd -= 1\n cs[i] + 1\n else\n cs[i]\n end\n}\n"}], "negative_code": [{"source_code": "N = gets.to_i\nsd = 0\nincremantables = {}\ncs = []\n(0...N).map{ |i|\n a = gets.to_f\n c = a.floor\n cs << c\n d = a - c\n sd += d\n incremantables[i] = 1 if d > 0\n}\n\nputs (0...N).map{ |i| \n if sd > 0 && incremantables[i]\n sd -= 1\n cs[i] + 1\n else\n cs[i]\n end\n} * \" \"\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.chomp}\nb = a.map(&:to_i)\nsum = b.inject(:+)\na.each_with_index do |s,i|\n break if sum == 0\n next if s[-5..-1] == \"00000\"\n sum += 1\n b[i] += 1\nend\nputs b"}, {"source_code": "n=gets.to_i\na=Array.new(n)\nk=0\nfor i in 0...n do\n q=gets\n a[i]=q.to_f\n k+=q.to_i\nend\n for i in 0...n do\n if k>0 then\n if a[i]>0 and a[i].to_i!=a[i].ceil.to_i then\n puts a[i].ceil\n else\n puts a[i].floor\n k-=1\n end\n elsif k<0 then\n if a[i]>0 and a[i].to_i!=a[i].ceil.to_i then\n puts a[i].ceil\n k+=1\n else\n puts a[i].floor\n end\n else\n puts a[i].to_i\n end\n end"}, {"source_code": "n=gets.to_i\na=Array.new(n)\nk=0\nfor i in 0...n do\n q=gets\n a[i]=q.to_f\n k+=q.to_i\nend\n for i in 0...n do\n if k>0 then\n if a[i]>0 then\n puts a[i].ceil\n else\n puts a[i].floor\n k-=1\n end\n elsif k<0 then\n if a[i]>0 then\n puts a[i].ceil\n else\n puts a[i].floor\n k+=1\n end\n else\n puts a[i].to_i\n end\n end"}, {"source_code": "n=gets.to_i\na=Array.new(n)\nk=0\nfor i in 0...n do\n q=gets\n a[i]=q.to_f\n k+=q.to_i\nend\n for i in 0...n do\n if k>0 then\n if a[i]>0 then\n puts a[i].floor\n k-=1\n else\n puts a[i].ceil\n end\n elsif k<0 then\n if a[i]>0 then\n puts a[i].ceil\n else\n puts a[i].floor\n end\n else\n puts a[i].to_i\n end\n end"}, {"source_code": "n=gets.to_i\na=Array.new(n)\nk=0\nfor i in 0...n do\n q=gets\n a[i]=q.to_f\n k+=q.to_i\nend\n for i in 0...n do\n if k>0 then\n if a[i].to_i != a[i].floor then\n if a[i]>0 then\n puts a[i].floor\n else\n puts a[i].floor\n k-=1\n end\n else\n puts a[i].to_i\n end\n elsif k<0 then\n if a[i].to_i != a[i].floor then\n if a[i]>0 then\n puts a[i].ceil\n k+=1\n else\n puts a[i].ceil\n end\n else\n puts a[i].to_i\n end\n else\n puts a[i].to_i\n end\n end"}], "src_uid": "6059cfa13594d47b3e145d7c26f1b0b3"} {"source_code": "n=gets.to_i\na=[]\nn.times{a<=a[j]\n j+=1\nend\np n-c\n\n\n", "positive_code": [{"source_code": "n=gets.to_i\na=[]\nn.times{a<=a[j]\n j+=1\nend\np n-c\n\n\n"}, {"source_code": "n=gets.to_i\na=[]\nn.times{a<=a[j]\n j+=1\nend\np n-c\n\n\n"}, {"source_code": "n=gets.to_i\na=[]\nn.times{a<=a[j]\n j+=1\nend\np n-c\n\n\n"}, {"source_code": "n=gets.to_i\na=[]\nn.times{a<=a[j]\n j+=1\nend\np n-c\n\n\n"}, {"source_code": "n=gets.to_i\na=[]\nn.times{a<=a[j]\n j+=1\nend\np n-c\n\n\n"}, {"source_code": "n=gets.to_i\na=[]\nn.times{a<=a[j]\n j+=1\nend\np n-c\n\n\n"}, {"source_code": "n = gets.to_i\na = []\ndem = []\ndem1 = 0\n\n(0..n-1).each do |i|\n a[i] = gets.to_i\nend\n\na.sort!\n\ni = 0\n\nwhile (a[i]<= (a[n-1]/2)) && (i<=(n/2-1)) do\n if i == 0\n j = i+1\n else\n j = n - dem[i-1]\n end\n while ((2*a[i])>a[j]) && (j=0 do\n if dem[i] > dem1\n dem1 += 1\n end\n i -= 1\nend\n\nputs n-dem1"}, {"source_code": "n=gets.to_i\na=[]\nn.times{a<=a[j]\n j+=1\nend\np n-c\n\n"}, {"source_code": "n=gets.to_i\na=[]\nn.times{a<=a[j]\n j+=1\nend\np n-c\n\n\n"}], "negative_code": [{"source_code": "n = gets.to_i\na = []\ndem = []\ndem1 = 0\n\n(0..n-1).each do |i|\n a[i] = gets.to_i\nend\n\na.sort!\n\ni = 0\n\nwhile (a[i]<= (a[n-1]/2)) && (i<=(n/2-1)) do\n j = i+1\n while ((2*a[i])>a[j]) && (j=0 do\n if dem[i] > dem1\n dem1 += 1\n end\n i -= 1\nend\n\nputs n-dem1"}, {"source_code": "n=gets.to_i\na=[]\nn.times{a<=a[j]\n j+=1\nend\np n-c\n\n"}, {"source_code": "n=gets.to_i\na=[]\nn.times{a<=a[j]\n j+=1\nend\np n-c\n\n"}], "src_uid": "361f65484d86051fa9ff013f5e8c9154"} {"source_code": "h = {}\r\nq = 1\r\nfor i in 'a'..'z'\r\n for j in 'a'..'z'\r\n next if i == j\r\n h[i + j] = q\r\n q += 1\r\n end\r\nend\r\n\r\ngets.to_i.times do\r\n puts h[gets.chomp]\r\nend\r\n", "positive_code": [{"source_code": "a=\" \"*27\r\nfor i in 0..25\r\n\ta[i]=('a'.ord+i).chr\r\nend\r\nr=[]\r\na.split('').each do |e|\r\n\ta.split('').each do |u|\r\n\t\tif e!=u && e!=\" \" && u!=\" \"\r\n\t\t\tr.append(e+u)\r\n\t\tend\r\n\tend\r\nend\r\nfor t in 1..gets[..-2].to_i\r\n\tputs r.index(gets[..-2])+1\r\nend\r\n"}, {"source_code": "m, az = {}, \"abcdefghijklmnopqrstuvwxyz\".chars\naz.product(az).filter {|a| a[0] != a[1]}.map{|a| a[0] + a[1]}.each_with_index {|a,i| m[a] = i+1}\ngets.to_i.times { puts m[gets.chomp] }"}, {"source_code": "words = {}\ncnt = 1\n('a'..'z').each do |a|\n ('a'..'z').each do |b|\n next if a == b\n words[a + b] = cnt\n cnt += 1\n end\nend\n\ngets.to_i.times do\n s = gets.strip\n p words[s]\nend\n"}, {"source_code": "map = [*\"a\"..\"z\"].flat_map do |a|\r\n ([*\"a\"..\"z\"] - [a]).map do |b|\r\n a + b\r\n end\r\nend.zip(1..).to_h\r\n\r\ngets.to_i.times do\r\n p map[gets.chomp]\r\nend\r\n"}, {"source_code": "t=gets.chomp.to_i\r\narr = ('a'..'z').to_a\r\narrAZ =[]\r\nkol=0\r\nfor i in 0..25\r\n for j in 0..25\r\n if (arr[i].to_s!=arr[j].to_s)\r\n kol+=1\r\n arrAZ[kol]=arr[i]+arr[j] \r\n end\r\n end\r\nend\r\n\r\n#puts arrAZ.compact\r\n#puts arrAZ.length\r\n\r\nt.times do\r\n puts arrAZ.index(gets.chomp.to_s)\r\nend"}, {"source_code": "t = gets.to_i\na = ?a.ord\nt.times do\n x, y = gets.chomp.each_byte.map { |b| b - a }\n i = x * 25 + y + 1\n i -= 1 if y > x\n puts i\nend"}], "negative_code": [], "src_uid": "2e3006d663a3c7ad3781aba1e37be3ca"} {"source_code": "input = gets.strip.split(' ').map(&:to_i)\nn = input[0]\na = input[1]\ncheckps = gets.strip.split(' ').map(&:to_i).sort\nleft_dists = []\nright_dists = []\ncheckps.each do |cp|\n if cp < a\n left_dists << a - cp\n elsif cp > a\n right_dists << cp - a\n end\nend\ncheckps.delete(a)\n\nif checkps.length > 0\n if left_dists.length > 0 and right_dists.length > 0\n mindist1 = 0\n mindist2 = 0\n \n old_left = left_dists.dup\n left_dists.slice! left_dists.index(left_dists.max)\n ldm = 0\n rdm = 0\n if not left_dists.max.nil?\n ldm = left_dists.max\n end\n if not right_dists.max.nil?\n rdm = right_dists.max\n end\n if (ldm > rdm)\n mindist1 = 2 * rdm + ldm\n else\n mindist1 = rdm + 2 * ldm\n end\n \n left_dists = old_left\n right_dists.slice! right_dists.index(right_dists.max)\n ldm = 0\n rdm = 0\n if not left_dists.max.nil?\n ldm = left_dists.max\n end\n if not right_dists.max.nil?\n rdm = right_dists.max\n end\n if (ldm > rdm)\n mindist2 = 2 * rdm + ldm\n else\n mindist2 = rdm + 2 * ldm\n end\n \n puts [mindist1, mindist2].min\n \n elsif left_dists.length > 0\n left_dists.slice! left_dists.index(left_dists.max)\n ldm = 0\n if not left_dists.max.nil?\n ldm = left_dists.max\n end\n puts ldm\n else\n right_dists.slice! right_dists.index(right_dists.max)\n rdm = 0\n if not right_dists.max.nil?\n rdm = right_dists.max\n end\n puts rdm\n end\nelse\n puts 0\nend", "positive_code": [{"source_code": "#!/usr/bin/ruby\nn,s,*a=$<.read.split.map &:to_i\na.sort!\nif n<2\n\tp 0\nelse\n\tp [[0,-2],[1,-1]].map{|i,j|\n\t\tx,y=[[s-a[i],0].max,[a[j]-s,0].max].minmax\n\t\tx*2+y\n\t}.min\nend"}, {"source_code": "n,a,*x=$<.read.split.map &:to_i\n(puts 0; exit) if n<2\n\nx.sort!\nif a<=x[0]\n puts (x[-2]-a).abs\nelsif a>=x[-1]\n puts (a-x[1]).abs\nelse\n b=x[-1]-a+x[-1]-x[1]\n c=(a-x[1]).abs+x[-1]-x[1]\n d=(x[-2]-a).abs+x[-2]-x[0]\n e=a-x[0]+x[-2]-x[0]\n puts [b, c, d, e].min\nend\n"}, {"source_code": "n,s,*a=$<.read.split.map &:to_i\na.sort!\np n<2 ? 0 : [[0,-2],[1,-1]].map{|i,j|\n\tx,y=[[s-a[i],0].max,[a[j]-s,0].max].minmax\n\tx*2+y\n}.min"}, {"source_code": "#!/usr/bin/ruby\nn,s,*a=$<.read.split.map &:to_i\na.sort!\nif n<2\n\tp 0\nelsif s a\n right_exists = true\n end\nend\nif left_exists and right_exists\n tbds = dists.index(dists.max)\n mindist = 0\n if checkps[tbds] - a > 0\n mindist = dists[0] * 2 + dists[dists.length-1]\n else\n mindist = dists[dists.length-1] * 2 + dists[0]\n end\n puts mindist\nelse\n if left_exists\n puts dists[0]\n elsif right_exists\n puts dists[dists.length-1]\n else\n puts 0\n end\nend"}, {"source_code": "input = gets.strip.split(' ').map(&:to_i)\nn = input[0]\na = input[1]\ncheckps = gets.strip.split(' ').map(&:to_i).sort\ndists = []\nleft_exists = false\nright_exists = false\ncheckps.each do |cp|\n dists << (cp-a).abs\n if cp < a\n left_exists = true\n elsif cp > a\n right_exists = true\n end\nend\ntbr = dists.index(dists.max)\ncheckps.slice! tbr\ndists.slice! tbr\nif left_exists and right_exists\n tbds = dists.index(dists.max)\n mindist = 0\n if checkps[tbds] - a > 0\n mindist = dists[0] * 2 + dists[dists.length-1]\n else\n mindist = dists[dists.length-1] * 2 + dists[0]\n end\n puts mindist\nelse\n if left_exists\n puts dists[0]\n elsif right_exists\n puts dists[dists.length-1]\n else\n puts 0\n end\nend"}, {"source_code": "input = gets.strip.split(' ').map(&:to_i)\nn = input[0]\na = input[1]\ncheckps = gets.strip.split(' ').map(&:to_i).sort\ndists = []\ncheckps.each do |cp|\n dists << (cp-a).abs\nend\ntbr = dists.index(dists.max)\ncheckps.slice! tbr\ndists.slice! tbr\ntbds = dists.index(dists.max)\nmindist = 0\nif checkps[tbds] - a > 0\n mindist = dists[0] * 2 + dists[dists.length-1]\nelse\n mindist = dists[dists.length-1] * 2 + dists[0]\nend\nputs mindist"}], "src_uid": "7807c484035e0327870b6cac23c8d60a"} {"source_code": "data_lines = gets.chomp\n\ndef prodess_arr arr\n\t# p '-----'\n\t# p arr\n\t# p '-----'\n\tnew_arr = []\n\tarr = arr.sort\n\tmiddle = arr.length / 2\n\t(0..arr.length-1).each do |index|\n\t\tif index < middle\n\t\t\tnew_arr[index * 2] = arr[index]\n\t\telse\n\t\t\tnew_index = index - middle\n\t\t\tnew_arr[new_index*2+1] = arr[index]\n\t\tend\n\tend\n\tnew_arr\n\n\n\t# success = false\n\t# while success == false\n\t# \tflag = true\n\t# \t(0..arr.length-1).each do |index|\n\t# \t\t# p \"number = #{arr[index]} index = #{index}\"\n\t# \t\tneigh_l_index = index-1\n\t# \t\tneigh_l_index = arr.length-1 if neigh_l_index < 0\n\t# \t\tneigh_r_index = index+1\n\t# \t\tneigh_r_index = 0 if neigh_r_index > arr.length-1\n\t# \t\tsr_ar = (arr[neigh_l_index].to_f + arr[neigh_r_index].to_f) / 2.0\n\t# \t\t# p \"sr_ar - arr[index] = #{sr_ar - arr[index]}\"\n\t# \t\tif sr_ar - arr[index] == 0.0\n\t# \t\t\t# p arr\n\t# \t\t\tflag = false\n\t# \t\t\tneigh_rr_index = index+2\n\t# \t\t\tif neigh_rr_index > arr.length-1\n\t# \t\t\t\tif neigh_rr_index == arr.length-1\n\t# \t\t\t\t\tneigh_rr_index = 0\n\t# \t\t\t\telse\n\t# \t\t\t\t\tneigh_rr_index = 1\n\t# \t\t\t\tend\n\t# \t\t\tend\n\t# \t\t\tbuffer = arr[neigh_r_index]\n\t# \t\t\tarr[neigh_r_index] = arr[neigh_rr_index]\n\t# \t\t\tarr[neigh_rr_index] = buffer\n\t# \t\t\t# p arr\n\t# \t\tend\n\t# \tend\n\t# \t# p success\n\t# \tsuccess = true if flag\n\t# \t# p success\n\t# end\n\t# arr\nend\narrs = []\n(1..data_lines.to_i).each do\n\tb = gets.chomp\n\tarrs.push prodess_arr(gets.chomp.split(' ').map{|_e| _e.to_i}).join(' ')\nend\narrs.each do |a|\n\tputs a\nend", "positive_code": [{"source_code": "results = []\nt = gets.chomp\n(1..t.to_i).each do |iteration|\n\tn = gets.chomp.to_i\n\ta = gets.chomp.split(' ').map{|e| e.to_i}.sort\n\tb = []\n\n\t(0..n-1).each do |idx|\n\t\tb[2*idx] = a[idx]\n\t\tb[2*idx+1] = a[n+idx]\n\tend\n\n\tresults.push(b)\nend\nresults.each do |res|\n\tputs res\nend"}, {"source_code": "def solution(n, arr)\r\n\ti = 0\r\n\r\n\twhile i < 2 * n\r\n\t\tprev_index = prev_index(arr, 2 * n, i)\r\n\t\tnext_index = next_index(arr, 2 * n, i)\r\n\r\n\t\tif (arr[prev_index] + arr[next_index]) / 2.0 == 1.0 * arr[i]\r\n\t\t\tarr[i], arr[prev_index] = arr[prev_index], arr[i]\r\n\t\t\ti = 0\r\n\t\telse\r\n\t\t\ti += 1\r\n\t\tend\r\n\tend\r\n\r\n\tarr\r\nend\r\n\r\ndef prev_index(arr, n, i)\r\n\tif i == 0\r\n\t\treturn n - 1\r\n\telse\r\n\t\treturn i - 1\r\n\tend\r\nend\r\n\r\ndef next_index(arr, n, i)\r\n\tif i == n - 1\r\n\t\treturn 0\r\n\telse\r\n\t\treturn i + 1\r\n\tend\r\nend\r\n\r\ntest_cases = gets.to_i\r\n\r\ntest_cases.times do |test_case|\r\n n = gets.to_i\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n puts solution(n, arr).join(' ')\r\nend"}], "negative_code": [{"source_code": "def check_valid arr\n\tarr.each_with_index do |el, idx|\n\t\tmid = (arr[idx+1].to_f + arr[idx-1].to_f) / 2\n\t\tif mid == el.to_f\n\t\t\treturn false\n\t\tend\n\tend\n\ttrue\nend\n\nresults = []\nt = gets.chomp\n(1..t.to_i).each do |iteration|\n\tn = gets.chomp\n\ta = gets.chomp.split(' ').map{|e| e.to_i}\n\n\ta.permutation.each do |perm|\n\t\tif check_valid perm\n\t\t\tresults.push perm\n\t\t\tbreak\n\t\tend\n\tend\nend\nresults.each do |res|\n\tp res.join(\"\\s\")\nend"}, {"source_code": "def check_valid arr\n\tarr.each_with_index do |el, idx|\n\t\tmid = (arr[idx+1].to_f + arr[idx-1].to_f) / 2\n\t\tif mid == el.to_f\n\t\t\treturn false\n\t\tend\n\tend\n\ttrue\nend\n\nresults = []\nt = gets.chomp\n(1..t.to_i).each do |iteration|\n\tn = gets.chomp\n\ta = gets.chomp.split(' ').map{|e| e.to_i}\n\n\ta.permutation.each do |perm|\n\t\tif check_valid perm\n\t\t\tresults.push perm\n\t\t\tbreak\n\t\tend\n\tend\nend\np results\n"}, {"source_code": "data_lines = gets.chomp\n\ndef prodess_arr arr\n\t# p '-----'\n\t# p arr\n\t# p '-----'\n\tnew_arr = []\n\tarr = arr.sort\n\t(0..arr.length-1).each do |index|\n\t\tif index % 2 == 0\n\t\t\tnew_arr[index / 2] = arr[index]\n\t\telse\n\t\t\tmiddle = arr.length / 2\n\t\t\tnew_arr[(index / 2) + middle] = arr[index]\n\t\tend\n\tend\n\tnew_arr\n\n\n\t# success = false\n\t# while success == false\n\t# \tflag = true\n\t# \t(0..arr.length-1).each do |index|\n\t# \t\t# p \"number = #{arr[index]} index = #{index}\"\n\t# \t\tneigh_l_index = index-1\n\t# \t\tneigh_l_index = arr.length-1 if neigh_l_index < 0\n\t# \t\tneigh_r_index = index+1\n\t# \t\tneigh_r_index = 0 if neigh_r_index > arr.length-1\n\t# \t\tsr_ar = (arr[neigh_l_index].to_f + arr[neigh_r_index].to_f) / 2.0\n\t# \t\t# p \"sr_ar - arr[index] = #{sr_ar - arr[index]}\"\n\t# \t\tif sr_ar - arr[index] == 0.0\n\t# \t\t\t# p arr\n\t# \t\t\tflag = false\n\t# \t\t\tneigh_rr_index = index+2\n\t# \t\t\tif neigh_rr_index > arr.length-1\n\t# \t\t\t\tif neigh_rr_index == arr.length-1\n\t# \t\t\t\t\tneigh_rr_index = 0\n\t# \t\t\t\telse\n\t# \t\t\t\t\tneigh_rr_index = 1\n\t# \t\t\t\tend\n\t# \t\t\tend\n\t# \t\t\tbuffer = arr[neigh_r_index]\n\t# \t\t\tarr[neigh_r_index] = arr[neigh_rr_index]\n\t# \t\t\tarr[neigh_rr_index] = buffer\n\t# \t\t\t# p arr\n\t# \t\tend\n\t# \tend\n\t# \t# p success\n\t# \tsuccess = true if flag\n\t# \t# p success\n\t# end\n\t# arr\nend\narrs = []\n(1..data_lines.to_i).each do\n\tb = gets.chomp\n\tarrs.push prodess_arr(gets.chomp.split(' ').map{|_e| _e.to_i}).join(' ')\nend\narrs.each do |a|\n\tputs a\nend"}, {"source_code": "def solution(n, arr)\r\n\t(0..(2 * n - 1)).each do |i|\r\n\t\tprev_index = prev_index(arr, 2 * n, i)\r\n\t\tnext_index = next_index(arr, 2 * n, i)\r\n\r\n\t\t# puts \"i: #{i}\"\r\n\t\t# puts \"prev_index: #{prev_index}\"\r\n\t\t# puts \"next_index: #{next_index}\"\r\n\t\t# puts \"------------\"\r\n\t\tif (arr[prev_index] + arr[next_index]) / 2.0 == 1.0 * arr[i]\r\n\t\t\t# prev_index = prev_index(arr, n, i - 1)\r\n\t\t\tarr[i], arr[prev_index] = arr[prev_index], arr[i]\r\n\t\tend\r\n\tend\r\n\r\n\tarr\r\nend\r\n\r\ndef prev_index(arr, n, i)\r\n\tif i == 0\r\n\t\treturn n - 1\r\n\telse\r\n\t\treturn i - 1\r\n\tend\r\nend\r\n\r\ndef next_index(arr, n, i)\r\n\tif i == n - 1\r\n\t\treturn 0\r\n\telse\r\n\t\treturn i + 1\r\n\tend\r\nend\r\n\r\ntest_cases = gets.to_i\r\n\r\ntest_cases.times do |test_case|\r\n n = gets.to_i\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n puts solution(n, arr).join(' ')\r\nend"}], "src_uid": "4296da660a39a6e98b41387929701c0a"} {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a num_lines\n end\n end\n end\n \nend\n \nsweet_problem = SweetProblem.new\nsweet_problem.main\n\n"}], "negative_code": [{"source_code": "\nclass SweetProblem\n \n def initialize(debug=false)\n @debug = debug\n end\n def to_hash(array)\n red = array[0]\n green = array[1]\n blue = array[2]\n result = Hash.new\n result['R'] = red\n result['G'] = green\n result['B'] = blue\n result\n end\n \n def min_color(hash)\n min = (10**8) + 1\n min_color_key = nil\n hash.each do |key,val|\n next if val == 0\n if val < min\n min = val\n min_color_key = key\n end\n end\n return min_color_key\n end\n \n def max_color(hash, color_key)\n two_colors_same_max = false\n max = 0\n max_color_key = nil\n hash.each do |key,val|\n if val == max and key != color_key\n two_colors_same_max = true\n end\n if val > max and key != color_key\n max = val\n max_color_key = key\n end\n end\n return max_color_key, two_colors_same_max\n end\n \n def num_colors_left(hash)\n num_colors = 0\n hash.each do |key,val|\n if val > 0\n num_colors = num_colors + 1\n end\n end\n num_colors\n end\n \n def get_num_days_can_eat(input_arr)\n hash = to_hash(input_arr)\n puts hash if @debug\n \n min_color = min_color(hash)\n puts \"min_color: #{min_color}\" if @debug\n max_color, two_colors_same_max = max_color(hash, min_color)\n puts \"max_color: #{max_color}\" if @debug\n puts \"two_colors_same_max: #{two_colors_same_max}\" if @debug\n\n num_days_can_eat = 0\n while num_colors_left(hash) >= 2\n min_color_count = hash[min_color]\n puts \"min_color_count: #{min_color_count}\" if @debug \n\n if two_colors_same_max and (num_colors_left(hash) == 3)\n max_color_count = hash[max_color] - 1\n hash[max_color] = max_color_count\n else\n max_color_count = hash[max_color] - min_color_count\n hash[max_color] = max_color_count\n end\n\n puts \"max_color_count is now: #{hash[max_color]}\" if @debug \n \n if two_colors_same_max and (num_colors_left(hash) == 3)\n min_color_count = hash[min_color] - 1\n hash[min_color] = min_color_count\n else\n hash[min_color] = 0\n end\n puts \"min_color_count is now: #{hash[min_color]}\" if @debug \n \n num_days_can_eat = num_days_can_eat + min_color_count\n puts \"num_days_can_eat: #{num_days_can_eat}\" if @debug\n\n min_color = min_color(hash)\n max_color, two_colors_same_max = max_color(hash, min_color)\n puts hash if @debug\n puts \"min_color: #{min_color}\" if @debug\n puts \"max_color: #{max_color}\" if @debug\n end\n num_days_can_eat\n end\n \n def main\n i = 0\n num_lines = 0\n while input = gets\n if i == 0\n num_lines = input.to_i \n i = i + 1\n next\n else\n input_arr = input.split(' ').map!(&:to_i)\n \n num_days_can_eat = get_num_days_can_eat(input_arr)\n \n puts num_days_can_eat\n i = i + 1\n break if i > num_lines\n end\n end\n end\n \nend\n \nsweet_problem = SweetProblem.new\nsweet_problem.main\n\n"}, {"source_code": "\n\ndef to_hash(array)\n red = array[0]\n green = array[1]\n blue = array[2]\n result = Hash.new\n result['R'] = red\n result['G'] = green\n result['B'] = blue\n result\nend\n\ndef min_color(hash)\n min = (10**8) + 1\n min_color_key = nil\n hash.each do |key,val|\n next if val == 0\n if val < min\n min = val\n min_color_key = key\n end\n end\n return min_color_key\nend\n\ndef max_color(hash, color_key)\n max = 0\n max_color_key = nil\n hash.each do |key,val|\n if val > max and key != color_key\n max = val\n max_color_key = key\n end\n end\n return max_color_key\nend\n\ndef num_colors_left(hash)\n num_colors = 0\n hash.each do |key,val|\n if val > 0\n num_colors = num_colors + 1\n end\n end\n num_colors\nend\n\ni = 0\nnum_lines = 0\nwhile input = gets\n if i == 0\n num_lines = input.to_i \n i = i + 1\n next\n else\n input_arr = input.split(' ').map!(&:to_i)\n\n hash = to_hash(input_arr)\n\n min_color = min_color(hash)\n max_color = max_color(hash, min_color)\n\n num_days_can_eat = 0\n while num_colors_left(hash) >= 2\n min_color_count = hash[min_color]\n\n max_color_count = hash[max_color] - min_color_count\n hash[max_color] = max_color_count\n\n hash[min_color] = 0\n\n min_color = min_color(hash)\n max_color = max_color(hash, min_color)\n num_days_can_eat = num_days_can_eat + min_color_count\n end\n\n puts num_days_can_eat\n i = i + 1\n break if i > num_lines\n end\nend\n\n"}], "src_uid": "1f29461c42665523d0a4d56b13f7e480"} {"source_code": "t = gets.chomp.to_i\r\n\r\ndef calc(pos, a, b)\r\n first = pos[b][-1]\r\n second = pos[a].reverse_each.find { |v| v > first }\r\n return Float::INFINITY if !second\r\n return first + second - first - 1\r\nend\r\n\r\nt.times do\r\n n = gets.chomp\r\n\r\n pos = Hash.new { |h, k| h[k] = [] }\r\n n.split('').each_with_index do |c, idx|\r\n if c == '0' || c == '2' || c == '5' || c == '7'\r\n pos[c] << n.length - idx - 1\r\n end\r\n end\r\n\r\n possibilities = []\r\n if pos['0'].length >= 2\r\n possibilities << calc(pos, '0', '0')\r\n end\r\n \r\n if pos['0'].length >= 1 && pos['5'].length >= 1\r\n possibilities << calc(pos, '5', '0')\r\n end\r\n \r\n if pos['2'].length >= 1 && pos['5'].length >= 1\r\n possibilities << calc(pos, '2', '5')\r\n end\r\n\r\n if pos['7'].length >= 1 && pos['5'].length >= 1\r\n possibilities << calc(pos, '7', '5')\r\n end\r\n\r\n puts possibilities.min\r\nend", "positive_code": [{"source_code": "def f(dgts)\r\n n0 = dgts.length\r\n i0 = dgts.rindex(\"0\") || 0\r\n j0 = i0 > 0 && dgts.rindex(/[05]/, i0 - 1) || -10000\r\n\r\n n5 = dgts.length\r\n i5 = dgts.rindex(\"5\") || 0\r\n j5 = i5 > 0 && dgts.rindex(/[27]/, i5 - 1) || -10000\r\n\r\n # p [i0, j0, i5, j5]\r\n [n0 - 2 - j0, n5 - 2 - j5].min\r\nend\r\n\r\ngets.to_i.times do\r\n\r\nn = gets.chomp\r\nputs f(n)\r\n\r\nend\r\n"}, {"source_code": "t = gets.chomp.to_i\r\n\r\ndef solve \r\n\tn = gets.chomp.to_i\r\n\td = n.digits\r\n\td = d.reverse\r\n\tans = 1e9\r\n\tinf = -1e9\r\n\t#25 75 50 00\r\n\tindex = {2=>inf, 7=>inf, 5=>inf, 0=>inf}\r\n\r\n\t(0..(d.length - 1)).each { |i|\r\n\t\tif (d[i] == 5) \r\n\t\t\tans = [ans, (i - index[2] - 1) + d.length - i - 1].min\r\n\t\t\tans = [ans, (i - index[7] - 1) + d.length - i - 1].min\r\n\t\tend\r\n\t\tif (d[i] == 0) \r\n\t\t\tans = [ans, (i - index[0] - 1) + d.length - i - 1].min\r\n\t\t\tans = [ans, (i - index[5] - 1) + d.length - i - 1].min\r\n\t\tend\r\n\t\tif d[i] == 2 || d[i] == 7 || d[i] == 5 || d[i] == 0\r\n\t\t\tindex[d[i]] = i\r\n\t\tend\r\n\t}\r\n\tputs ans\r\nend\r\n\r\nt.times {\r\n\tsolve\r\n}\r\n"}, {"source_code": "t = gets.chomp.to_i\r\n\r\ndef solve \r\n\tn = gets.chomp.to_i\r\n\td = n.digits\r\n\td = d.reverse\r\n\tans = 1e9\r\n\tinf = -1e9\r\n\t#25 75 50 00\r\n\tindex = {2=>inf, 7=>inf, 5=>inf, 0=>inf}\r\n\r\n\t(0..(d.length - 1)).each { |i|\r\n\t\tif (d[i] == 5) \r\n\t\t\tans = [ans, (i - index[2] - 1) + d.length - i - 1].min\r\n\t\t\tans = [ans, (i - index[7] - 1) + d.length - i - 1].min\r\n\t\tend\r\n\t\tif (d[i] == 0) \r\n\t\t\tans = [ans, (i - index[0] - 1) + d.length - i - 1].min\r\n\t\t\tans = [ans, (i - index[5] - 1) + d.length - i - 1].min\r\n\t\tend\r\n\t\tindex[d[i]] = i\r\n\t}\r\n\tputs ans\r\nend\r\n\r\nt.times {\r\n\tsolve\r\n}\r\n"}, {"source_code": "def k(n)\r\n c1 = 0\r\n c2 = 0\r\n c3 = 0\r\n c4 = 0\r\n d1 = 0\r\n d2 = 0\r\n d3 = 0\r\n d4 = 0\r\n while n > 0\r\n dig = n % 10\r\n if dig == 0\r\n c1 += 1\r\n else\r\n d1 += 1\r\n end\r\n\r\n if c1 == 2\r\n return d1\r\n end\r\n\r\n if dig == 5 and c2 == 0\r\n c2+=1\r\n elsif dig == 2 and c2 == 1\r\n return d2\r\n else\r\n d2+=1\r\n end\r\n\r\n if(dig == 0 and c3 == 0)\r\n c3+=1\r\n elsif(dig == 5 and c3 == 1)\r\n return d3\r\n else\r\n d3+=1\r\n end\r\n\r\n\r\n if(dig == 5 and c4 == 0)\r\n c4+=1\r\n elsif(dig == 7 and c4 == 1)\r\n return d4\r\n else\r\n d4+=1\r\n end\r\n\r\n n = n / 10\r\n end\r\n\r\n return 1000\r\n\r\nend\r\n\r\ngets.to_i.times do\r\n n = gets.to_i\r\n puts k(n)\r\nend\r\n"}, {"source_code": "gets.to_i.times do\n\tn = gets.chomp\n\tif n.to_i % 25 == 0\n\t\tputs 0\n\t\tnext\n\tend\n\tres = 1000000000\n\tfor i in 0..n.length - 1 do\n\t\tfor j in i+1..n.length - 1 do\n\t\t\tif (n[i].to_i * 10 + n[j].to_i) % 25 == 0\n\t\t\t\tres = [res, j - i - 1 + (n.length - 1 - j)].min\n\t\t\tend\n\t\tend\n\tend\n\tputs res\nend"}], "negative_code": [{"source_code": "def f(dgts)\r\n n0 = dgts.length\r\n i0 = dgts.rindex(\"0\") || 0\r\n j0 = i0 > 0 && dgts.rindex(/[05]/, i0 - 1) || -1\r\n\r\n dgts = dgts.gsub(/0+(?!0)/, \"\")\r\n n5 = dgts.length\r\n i5 = dgts.rindex(\"5\") || 0\r\n j5 = i5 > 0 && dgts.rindex(/[27]/, i5 - 1) || -1\r\n \r\n [n0 - 2 - j0, n5 - 2 - j5].min\r\nend\r\n \r\ngets.to_i.times do\r\n \r\nn = gets.chomp\r\nputs f(n)\r\n \r\nend\r\n"}, {"source_code": "def f(dgts)\r\n n = dgts.length\r\n\r\n i0 = dgts.rindex(\"0\") || 1\r\n i5 = dgts.rindex(\"5\") || 1\r\n\r\n j0 = dgts.rindex(/[05]/, i0 - 1) || 0\r\n j5 = dgts.rindex(/[27]/, i5 - 1) || 0\r\n\r\n [n - 2 - j0, n - 2 - j5].min\r\nend\r\n\r\ngets.to_i.times do\r\n\r\nn = gets.chomp\r\nputs f(n)\r\n\r\nend\r\n"}], "src_uid": "ab6fefc6c15d4647bc601f1f9db21d3f"} {"source_code": "END { load __FILE__ unless $stdin.eof? }\n\nmodule AtCoder\n class DSU\n def initialize(n = 0)\n @n = n\n @parent_or_size = Array.new(n, -1)\n end\n\n def merge(a, b)\n x, y = leader(a), leader(b)\n return x if x == y\n\n x, y = y, x if -@parent_or_size[x] < -@parent_or_size[y]\n @parent_or_size[x] += @parent_or_size[y]\n @parent_or_size[y] = x\n end\n\n def same(a, b)\n leader(a) == leader(b)\n end\n\n def leader(a)\n return a if @parent_or_size[a] < 0\n\n @parent_or_size[a] = leader(@parent_or_size[a])\n end\n\n def size(a)\n -@parent_or_size[leader(a)]\n end\n\n def groups\n @n.times.group_by { |i| leader(i) }.values\n end\n end\nend\n\nn, m1, m2 = gets.split.map!(&:to_i)\ne1 = Array.new(m1) { gets.split.map!(&:to_i) }\ne2 = Array.new(m2) { gets.split.map!(&:to_i) }\n\ndsu1 = AtCoder::DSU.new(n + 1)\ndsu2 = AtCoder::DSU.new(n + 1)\n\ne1.each { |u, v| dsu1.merge(u, v) }\ne2.each { |u, v| dsu2.merge(u, v) }\n\ne3 = [*1..n].combination(2).select do |u, v|\n next false if dsu1.same(u, v) || dsu2.same(u, v)\n\n dsu1.merge(u, v)\n dsu2.merge(u, v)\n\n true\nend\n\nputs e3.size\ne3.each { |uv| puts uv * \" \" }\n", "positive_code": [{"source_code": "# Disjoint Set Union\r\nclass DSU\r\n def initialize(n)\r\n @n = n\r\n @parent_or_size = Array.new(n, -1)\r\n # root node: -1 * component size\r\n # otherwise: parent\r\n end\r\n\r\n attr_reader :parent_or_size, :n\r\n\r\n def merge(a, b)\r\n x = leader(a)\r\n y = leader(b)\r\n return x if x == y\r\n\r\n x, y = y, x if -@parent_or_size[x] < -@parent_or_size[y]\r\n @parent_or_size[x] += @parent_or_size[y]\r\n @parent_or_size[y] = x\r\n end\r\n alias unite merge\r\n\r\n def same?(a, b)\r\n leader(a) == leader(b)\r\n end\r\n alias same same?\r\n\r\n def leader(a)\r\n unless 0 <= a && a < @n\r\n raise ArgumentError.new, \"#{a} is out of range (0...#{@n})\"\r\n end\r\n\r\n @parent_or_size[a] < 0 ? a : (@parent_or_size[a] = leader(@parent_or_size[a]))\r\n end\r\n alias root leader\r\n alias find leader\r\n\r\n def size(a)\r\n -@parent_or_size[leader(a)]\r\n end\r\n\r\n def groups\r\n (0 ... @parent_or_size.size).group_by{ |i| leader(i) }.values\r\n end\r\nend\r\n\r\nUnionFind = DSU\r\n\r\nn,m1,m2=gets.split.map(&:to_i)\r\nf1=DSU.new(n)\r\nf2=DSU.new(n)\r\n\r\nm1.times do\r\n u,v=gets.split.map(&:to_i).map{|x|x-1}\r\n f1.merge(u,v)\r\nend\r\nm2.times do\r\n u,v=gets.split.map(&:to_i).map{|x|x-1}\r\n f2.merge(u,v)\r\nend\r\n\r\naz=0\r\nans=[]\r\nn.times do |j|\r\n j.times do |i|\r\n if !f1.same?(i,j)&&!f2.same?(i,j)\r\n f1.merge(i,j)\r\n f2.merge(i,j)\r\n ans << [i+1,j+1]\r\n az+=1\r\n end\r\n end\r\nend\r\n\r\nputs az\r\nans.each do |aa|\r\n puts aa.join(\" \")\r\nend\r\n\r\n"}], "negative_code": [], "src_uid": "e3d2b67a62ac431718071ae20f3794aa"} {"source_code": "a,b,c,d = gets.chomp.split.map(&:to_i)\n\nn=[a,b,c,d].max\narr=[a,b,c,d]-[n]\nputs [n-arr[0],n-arr[1],n-arr[2]].join(' ')", "positive_code": [{"source_code": "X1, X2, X3, X4 = gets.split.map(&:to_i)\n\nx1, x2, x3, x4 = [X1, X2, X3, X4].sort\n\ni = x4 - x1\nj = x4 - x2\nk = x4 - x3\n\nputs [i, j, k].join(' ')\n"}, {"source_code": "x1,x2,x3,x4 = gets.scan(/\\d+/).map(&:to_i).sort\nc = x1 + x3 -x4\na = x1 - c \nb = x3 - c\nputs \"#{a} #{b} #{c}\"\n"}, {"source_code": "x1, x2, x3, x4 = gets.split.map(&:to_i).sort\nputs \"#{x4-x1} #{x4-x2} #{x4-x3}\"\n"}, {"source_code": "def uwu(inte)\n\tmax = 0\n\toutput = ''\n\tfor number in inte\n\t\tmax = number.to_i if number.to_i >= max\n\tend\n\tinte.delete(max.to_s)\n\tfor number in inte\n\t\tresutlat = max - number.to_i\n\t\toutput << resutlat.to_s\n\t\toutput << ' '\n\tend\n\toutput[-1] = '' if output[-1] == ' '\n\treturn output\nend\n\ninte = gets.chomp.split(\" \")\nputs(uwu(inte))"}, {"source_code": "a,b,c,d = gets.split.map(&:to_i).sort\nputs \"#{d-a} #{d-b} #{d-c}\""}, {"source_code": "a,b,c,d=gets.split.map(&:to_i).sort;p d-a,d-b,d-c"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\ninputs = gets.split.map { |i| i.to_i }\n\n# inputs[?] = a + b\n# inputs[?] = a + c\n# inputs[?] = b + c\n# inputs[?] = a + b + c\nans = []\n# \ubaa8\ub450 \uc591\uc218\uc774\ubbc0\ub85c, \uac00\uc7a5 \ud070 \uc218\uac00 a + b + c\nabc = inputs.max\ninputs.delete abc\ninputs.each { |i| ans.push abc - i }\n\nputs ans.join ' '\n\n"}, {"source_code": "arr = gets.split.map(&:to_i)\narr.sort!\narr.reverse!\nanswer = []\nanswer << arr[0]-arr[1]\nanswer << arr[0]-arr[2]\nanswer << arr[0]-arr[3]\nputs answer.join(' ')"}, {"source_code": "$n = gets\n$a, $b, $c, $d = $n.split(' ').to_a\narr = [$a.to_i, $b.to_i, $c.to_i, $d.to_i]\n$k = arr.max\narr.delete($k)\nprint $k.to_i-arr[0].to_i,' ',$k.to_i-arr[1].to_i,' ',$k.to_i-arr[2].to_i"}, {"source_code": "require \"matrix\"\nngo = gets.chomp.split(\" \").map(&:to_i).sort\nputs Matrix[[1,1,0],[1,0,1],[0,1,1]].lup.solve(ngo.slice(0,3)).to_a.map(&:to_i).join(\" \")\n"}, {"source_code": "x = gets.split.map(&:to_i).sort\nputs [x[3] - x[2], x[3] - x[1], x[3] - x[0]].join ' '"}, {"source_code": "sums = gets.chomp.split(\" \").map(&:to_i)\n\nmax = sums[0]\nmax_idx = 0\nsums.each_with_index do |sum, idx|\n if sum > max\n max = sum\n max_idx = idx\n end\nend\n\nnumbers = []\n\nsums.each_with_index do |sum, idx|\n if idx != max_idx\n n = max - sum\n numbers.push(n)\n end\nend\n\nans = numbers.join(\" \")\nputs ans"}, {"source_code": "line = gets\nn = line.split.map { |x| x.to_i }\nsum = n.max\nn.delete_at(n.index(sum))\nn.map!{|x| sum - x}\nputs(n.join ' ')\n"}, {"source_code": "a = gets.split(' ').map(&:to_i).sort.reverse\n\nm = a.shift\nputs a.map { |x| m-x }.join(' ')\n"}, {"source_code": "x = gets.split(' ').map(&:to_i).sort\nv = []\nx.each do |xx|\n v.push(x[3]-xx)\nend\nputs \"#{v[0]} #{v[1]} #{v[2]}\"\n"}, {"source_code": "def read_tokens\n return gets.chomp.to_s.strip.split(' ')\nend\n\ndef read_ints\n data = []\n read_tokens.each { |s|\n data.push(s.to_i)\n }\n return data\nend\n\narr = read_ints()\n\ndef solve(arr)\n maximum = arr.max\n arr.each { |el|\n if el != maximum\n print \"#{maximum - el} \"\n end\n }\nend\n\nsolve(arr)\n"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1154/A\n\nnumbers = gets.split(' ').map(&:to_i)\n\nmax = numbers.max\nanswer = []\n\nnumbers.each do |n|\n if (temp = max - n) != 0\n answer << temp\n end\nend\n\nputs answer.join(' ')\n"}, {"source_code": "a,b,c,d=gets.split.map(&:to_i).sort\nputs\"#{d-a} #{d-b} #{d-c}\""}], "negative_code": [{"source_code": "a,b,c,d=gets.split.map(&:to_i).sort\np\"#{d-a} #{d-b} #{d-c}\""}], "src_uid": "cda949a8fb1f158f3c06109a2d33f084"} {"source_code": "gets\nv = gets.split.map(&:to_i)\n\nd = Array.new(v.length,-1)\nd[0] = v[0]\n\n0.upto(v.length-2) do |i|\n\tnext if d[i] == -1\n\tif d[i+1] == -1 or d[i+1] < [d[i],v[i+1]].min\n\t\td[i+1] = [d[i],v[i+1]].min\n\tend\n\tif i + 2 < v.length and (d[i+2] == -1 or d[i+2] < [d[i],v[i+2]].min)\n\t\td[i+2] = [d[i],v[i+2]].min\n\tend\nend\n\nputs d[v.length-1]\n", "positive_code": [{"source_code": "n=gets.to_i\na=gets.chomp.split.map(&:to_i)\nj,i=1+a[0],n\na[0]-=1\nif n>1\n\tj=1\n\twhile i>0\n\t\ti=1\n\t\twhile i 0 \n\t\t\tfinish = true\n\t\t\tbreak \n\t\tend\n\tend\n\tbreak if finish\nend\nputs ans"}, {"source_code": "gets\nns = gets.split.map(&:to_i)\nsorted = ns.map.with_index{|n, i| [n, i]}.sort_by(&:first)\nhash = {}\nanswer = ns.first\nsorted.each do |n, i|\n hash[i] = true\n if hash[i-1] || hash[i+1] || hash[0] || hash[ns.length - 1]\n answer = n\n break\n end\nend\n\nputs answer\n"}, {"source_code": "gets\nv = gets.split.collect { |x| x.to_i}\n\nd = Array.new(v.length,-1)\nd[0] = v[0]\n\nbegin\n\tch = false\n\t0.upto(v.length-2) do |i|\n\t\tif d[i] != -1\n\t\t\tif d[i+1] == -1 or d[i+1] < [d[i],v[i+1]].min\n\t\t\t\td[i+1] = [d[i],v[i+1]].min\n\t\t\t\tch = true\n\t\t\tend\n\t\t\tif i + 2 < v.length and (d[i+2] == -1 or d[i+2] < [d[i],v[i+2]].min)\n\t\t\t\td[i+2] = [d[i],v[i+2]].min\n\t\t\t\tch = true\n\t\t\tend\n\t\tend\n\tend\nend while ch\n\nputs d[v.length-1]\n"}, {"source_code": "\ufeffn = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|e| e.to_i}\n\ndays = 0\nloop do\n break if a[0] == 0 or a[-1] == 0\n \n bang = false\n for i in 1 .. (n - 2) do\n bang = true if a[i] == 0 and a[i + 1] == 0\n end\n break if bang\n \n days += 1\n \n a.map!{|e|\n e > 0 ? e -= 1 : e\n } \nend\n\nputs days\n"}], "negative_code": [{"source_code": "\ufeffn = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|e| e.to_i}\n\na << 0\na << 0\n\ndays = 0\nloop do\n bang = false\n for i in 0 .. (n - 2) do\n bang = true if ! ((a[i] > 0 and (a[i + 1] > 0 or a[i + 2] > 0)) or (a[i] == 0 and a[i + 1] > 0)) \n end\n \n break if bang\n \n days += 1\n \n a.map!{|e|\n e > 0 ? e -= 1 : e\n } \nend\n\nputs days\n"}, {"source_code": "\ufeffn = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|e| e.to_i}\n\ndays = 0\nloop do\n bang = false\n for i in 0 .. (n - 3) do\n bang = true if !((a[i] > 0 and (a[i + 1] > 0 or a[i + 2] > 0)) or (a[i] <= 0 and (a[i + 1] > 0)))\n end\n \n break if bang\n \n days += 1\n \n a.map!{|e| e -= 1} \nend\n\nputs days\n"}, {"source_code": "n = gets.to_i\na = gets.split.map{|e| e.to_i}\nmin=[a[0],a[n-1]].min\nfor i in (0..n-2) do\n c = [a[i],a[i+1]].max\n puts c\n if c 0\n lift_targets = ordered_list[0..(location - 1)]\n remaining = ordered_list[(location + 1)..-1]\n costs += lift_targets.reduce(0) {|memo, item| memo + w[item - 1] }\n ordered_list = [ordered_list[location]] + lift_targets + remaining\n end\n end\n\n puts costs\nend\n\nrun if $0 == __FILE__\n", "positive_code": [{"source_code": "def g;gets.split.map(&:to_i)end\nn,m=g\nw=g\nb=g\n#[*1..n].permutation{|st|\n# sum=0\n# b.each{|i|\n# x=st.index(i)\n# st.delete_at(x)\n# sum+=st[x..-1].inject(0){|s,r|s+w[r-1]}\n# st<< i\n# }\n# p sum\n#}\nst=(1..n).sort_by{|i|-(b.index(i)||m)}\nsum=0\nb.each{|i|\n x=st.index(i)\n st.delete_at(x)\n sum+=st[x..-1].inject(0){|s,r|s+w[r-1]}\n st<< i\n}\np sum"}, {"source_code": "n, m = gets.split.map(&:to_i)\nws = gets.split.map(&:to_i)\nbs = gets.split.map(&:to_i)\n\nscore = Array.new(n){ 0 }\nord = Array.new(n){ n }\nret = 0\nwini = 0\nbs.each do |x|\n if ord[x-1] == n\n ret += wini\n wini += ws[x-1]\n else\n ret += score[x-1]\n end\n n.times do |i|\n if ord[i] < ord[x-1]\n score[i] += ws[x-1]\n ord[i] += 1\n end\n end\n score[x-1] = 0\n ord[x-1] = 0\n #print \"(#{ret})\"\nend\nputs ret\n"}, {"source_code": "# 500C\n\nrequire 'set'\n\ndef read_line\n gets.chomp.split.map &:to_i\nend\n\nn, _ = read_line\nw = read_line\ns = Set.new(1..n)\na = []\nb = read_line\nb.each { |x|\n if s.include? x\n a << x\n s.delete x\n end\n}\na += s.to_a\n\ns = 0\nb.each { |v|\n m = a.index v\n s += (0...m).map { |i| w[a[i] - 1] }.inject(&:+) || 0\n a.delete_at m\n a.unshift v\n}\nputs s"}], "negative_code": [{"source_code": "def g;gets.split.map(&:to_i)end\nn,_=g\nw=g\nb=g\n#[*1..n].permutation{|st|\n# sum=0\n# b.each{|i|\n# x=st.index(i)\n# st.delete_at(x)\n# sum+=st[x..-1].inject(0){|s,r|s+w[r-1]}\n# st<< i\n# }\n# p sum\n#}\nst=(1..n).sort_by{|i|-(b.index(i)||n)}\nsum=0\nb.each{|i|\n x=st.index(i)\n st.delete_at(x)\n sum+=st[x..-1].inject(0){|s,r|s+w[r-1]}\n st<< i\n}\np sum"}], "src_uid": "a18edcadb31f76e69968b0a3e1cb7e3e"} {"source_code": "def minimize_instability(n, a)\n min1 = min2 = 100_001\n max1 = max2 = 0\n n.times do |i|\n if a[i] < min1\n min2 = min1\n min1 = a[i]\n elsif a[i] < min2\n min2 = a[i]\n end\n if a[i] > max1\n max2 = max1\n max1 = a[i]\n elsif a[i] > max2\n max2 = a[i]\n end\n end\n\n min = 1_000_000\n n.times do |i|\n u = max1\n u = max2 if u == a[i]\n l = min1\n l = min2 if l == a[i]\n min = [min, u - l].min\n end\n return min\nend\n\nn = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\n\nputs minimize_instability(n, a)\n", "positive_code": [{"source_code": "n = gets.to_i\narr = gets.chomp.split(\" \").map(&:to_i)\n\nmax = 0\nmaxtwo = 0\nmin = 1.0/0.0\nmintwo = 1.0/0.0\n\narr.each do |x|\n if x > max\n maxtwo = max\n max = x\n elsif x > maxtwo\n maxtwo = x\n end\n\n if x < min\n mintwo = min\n min = x\n elsif x +/).join.size", "positive_code": [{"source_code": "n = gets.strip.to_i\ns = gets.strip\nans = 0\ni = 0\nwhile i < n && s[i] == '<'\n ans += 1\n i += 1\nend\ni = n - 1\nwhile i >= 0 && s[i] == '>'\n ans += 1\n i -= 1\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\n\ni = 0\nwhile i < n && s[i] == '<'\n i += 1\nend\n\nj = 0\n\nwhile j < n && s[n - j - 1] == '>'\n j += 1\nend\n\nputs i + j"}, {"source_code": "n=gets.to_i\np~(gets.rindex(?<)||-1)+n+($_.index(?>)||n)"}, {"source_code": "gets\ns=gets.chop\nr=0\ns.chars{|c|c==?>&&break;r+=1}\ns.reverse.chars{|c|c==?<&&break;r+=1}\np r"}, {"source_code": "#!/usr/bin/ruby\n\nsize = gets.to_i\nstr = gets\nright = true\nleft = true\ncontinue = true\nfinal_number = 0\ni=0\nwhile continue do \n\tif right\n\t\tif str[i] == '<'\n\t\t\tfinal_number += 1\n\t\telse\n\t\t\tright = false \n\t\tend\t\n\tend\n\tif left\n\t\tif str[size - 1 - i] == '>'\n\t\t\tfinal_number += 1\n\t\telse\n\t\t\tleft = false\n\t\tend\n\tend\t\n\ti+=1\n\tif !left and !right\n\t\tcontinue = false\n\tend\t\nend\nputs final_number"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nputs (s.index('>') || n) + (n - 1 - (s.rindex('<') || -1))\n"}, {"source_code": "n = gets.to_i\na = gets.strip\ncnt = 0\ni = 0\nlen = a.length\nwhile(1) do\n break if a[i] == '>' || i == len\n cnt += 1\n i += 1\nend\n\ni = len - 1\nwhile(1) do\n break if a[i] == '<' || i == -1\n cnt += 1\n i -=1\nend\n\nprintf(\"%d\\n\", cnt)\n"}, {"source_code": "length = gets.to_i\nbumpers = gets\n\nfirst_greater = bumpers.index('>')\nlast_lesser = bumpers.rindex('<')\n\nif first_greater.nil? || last_lesser.nil?\n total_falling_positions = length\nelse\n total_falling_positions = length - (last_lesser - first_greater + 1)\nend\n\nputs total_falling_positions\n"}], "negative_code": [{"source_code": "gets\np gets.scan(/(^\\<+|\\>+$)/).map(&:size).reduce(0,:+)"}, {"source_code": "n = gets.strip.to_i\ns = gets.strip\nfirst = s[0]\nlast = s[n - 1]\nans = 0\nif first == '<'\n ans = 1\nelsif last == '>'\n ans = n\nend\nputs ans\n"}, {"source_code": "n = gets.strip.to_i\ns = gets.strip\nfirst = s[0]\nlast = s[n - 1]\nans = 0\nif first == '<'\n ans = 1\nelsif last == '>'\n ans = n\nelse\n if first == '>' && last == '<'\n ans = 0\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\n\ni = 0\nwhile i < n && s[i] == '<'\n i += 1\nend\n\nj = 0\n\nwhile j < n && s[n - j + 1] == '>'\n i += 1\nend\n\nputs i + j"}, {"source_code": "gets\ns=gets\nr=0\ns.chars{|c|c==?>&&break;r+=1}\ns.reverse.chars{|c|c==?<&&break;r+=1}\np r"}], "src_uid": "6b4242ae9a52d36548dda79d93fe0aef"} {"source_code": "n = gets.chomp.to_i\nhx = Hash.new(0)\nhy = Hash.new(0)\nhxy = Hash.new(0)\nn.times do\n x, y = gets.chomp.split.map(&:to_i)\n hx[x] += 1\n hy[y] += 1\n hxy[(x + 10**9) * 10**10 + (y + 10**9)] += 1\nend\n\nans = 0\nhx.each do |_, v| \n ans += v * (v - 1) / 2\nend\nhy.each do |_, v| \n ans += v * (v - 1) / 2\nend\nhxy.each do |_, v| \n ans -= v * (v - 1) / 2\nend\n\nputs ans\n", "positive_code": [{"source_code": "n=gets.to_i\na=Hash.new(0)\nb=Hash.new(0)\np=Hash.new(0)\nfor i in 1..n\n\tbuf = gets.split(\" \")\n\ta[buf[0]]+=1\n\tb[buf[1]]+=1\n\tp[buf]+=1\nend\nans=0\na.each_value{|v| ans+=v*(v-1)/2 }\nb.each_value{|v| ans+=v*(v-1)/2 }\np.each_value{|v| ans-=v*(v-1)/2 }\nputs ans"}, {"source_code": "#!/usr/bin/ruby\nrequire 'scanf'\n\nx_paintings = Hash.new(0)\ny_paintings = Hash.new(0)\nxy_paintings = Hash.new(0)\nwatchmen = gets().to_i\n\npairs = 0\nwatchmen.times do\n x, y = gets().split(' ').map(&:to_i)\n pairs += x_paintings[x]; x_paintings[x] += 1\n pairs += y_paintings[y]; y_paintings[y] += 1\n pairs -= xy_paintings[\"#{x},#{y}\"]; xy_paintings[\"#{x},#{y}\"] += 1\nend\n\nputs pairs"}, {"source_code": "n = gets.to_i\nx=[]\ny=[]\na=[]\nn.times do\n\tb,c = gets.split.map(&:to_i)\n\tx << b\n\ty << c\n\ta << [b,c]\nend\n\nx.sort!\ny.sort!\na.sort!\nc=\"a\"\ncc = 1\nac = 0\nn.times do |i|\n\tcx=x[i]\n\tif c!=cx\n\t\tac += cc*(cc-1)/2\n\t\tc=cx\n\t\tcc=1\n\telse\n\t\tcc+=1\n\tend\nend\nac += cc*(cc-1)/2\n\nc=\"a\"\ncc = 1\nn.times do |i|\n\tcx=y[i]\n\tif c!=cx\n\t\tac += cc*(cc-1)/2\n\t\tc=cx\n\t\tcc=1\n\telse\n\t\tcc+=1\n\tend\nend\nac += cc*(cc-1)/2\n\nc=-1\ncc = 1\nn.times do |i|\n\tcx=a[i]\n\tif c!=cx\n\t\tac -= cc*(cc-1)/2\n\t\tc=cx\n\t\tcc=1\n\telse\n\t\tcc+=1\n\tend\nend\nac -= cc*(cc-1)/2\n\nputs ac\n\n\n\n"}, {"source_code": "n = gets.to_i\nlocations = []\nn.times do \n locations << gets.split.map(&:to_i)\nend\ndigit_count_x = {}\ndigit_count_y = {}\ndigit_count_xy = {}\n\ncount = 0\nlocations.each do |x, y|\n count += digit_count_x[x] if digit_count_x[x] && digit_count_x[x] > 0\n digit_count_x[x] = digit_count_x[x] ? digit_count_x[x] + 1 : 1\n count += digit_count_y[y] if digit_count_y[y] && digit_count_y[y] > 0\n digit_count_y[y] = digit_count_y[y] ? digit_count_y[y] + 1 : 1 \n count -= digit_count_xy[[x, y]] if digit_count_xy[[x, y]] && digit_count_xy[[x, y]] > 0\n digit_count_xy[[x, y]] = digit_count_xy[[x, y]] ? digit_count_xy[[x, y]] + 1 : 1\nend\nputs count"}, {"source_code": "def cal hash\n hash.values.map{|n| n * (n - 1) / 2}.reduce(0, :+)\nend\n\nn = readline.to_i\nhx, hy, hxy = Hash.new(0), Hash.new(0), Hash.new(0)\nn.times do\n x, y = readline.split(' ').collect(&:to_i)\n hx[x] += 1\n hy[y] += 1\n hxy[[x, y]] += 1\nend\n\nputs cal(hx) + cal(hy) - cal(hxy)\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nrequire 'scanf'\n\nx_paintings = Hash.new(0)\ny_paintings = Hash.new(0)\nxy_paintings = Hash.new(0)\nwatchmen = scanf(\"%d\\n\").first.to_i\n\npairs = 0\nwatchmen.times do\n x, y = scanf(\"%d %d\").map(&:to_i)\n pairs += x_paintings[x]; x_paintings[x] += 1\n pairs += y_paintings[y]; y_paintings[y] += 1\n pairs -= xy_paintings[\"#{x},#{y}\"]; xy_paintings[\"#{x},#{y}\"] += 1\nend\n\nputs pairs"}, {"source_code": "#!/usr/bin/ruby\nrequire 'scanf'\n\nx_paintings = Hash.new(0)\ny_paintings = Hash.new(0)\nxy_paintings = Hash.new(0)\nwatchmen = scanf(\"%d\").first.to_i\n\npairs = 0\nwatchmen.times do\n x, y = scanf(\"%d %d\").map(&:to_i)\n pairs += x_paintings[x]; x_paintings[x] += 1\n pairs += y_paintings[y]; y_paintings[y] += 1\n pairs -= xy_paintings[\"#{x},#{y}\"]; xy_paintings[\"#{x},#{y}\"] += 1\nend\n\nputs pairs"}, {"source_code": "n = gets.to_i\n\nlocations = gets.split.map(&:to_i)\ndigit_count_x = {}\ndigit_count_y = {}\ndigit_count_xy = {}\n\ncount = 0\nlocations.each do |x, y|\n count += digit_count_x[x] if digit_count_x[x] && digit_count_x[x] > 0\n digit_count_x[x] = digit_count_x[x] ? digit_count_x[x] + 1 : 1\n count += digit_count_y[y] if digit_count_y[y] && digit_count_y[y] > 0\n digit_count_y[y] = digit_count_y[y] ? digit_count_y[y] + 1 : 1 \n count -= digit_count_xy[[x, y]] if digit_count_xy[[x, y]] && digit_count_xy[[x, y]] > 0\n digit_count_xy[[x, y]] = digit_count_xy[[x, y]] ? digit_count_xy[[x, y]] + 1 : 1\nend\nputs count"}], "src_uid": "bd7b85c0204f6b36dc07f8a96fc36161"} {"source_code": "cases = STDIN.gets.chomp.to_i\r\ncases.times.each do \r\n input_string = STDIN.gets.chomp\r\n input_query = STDIN.gets.chomp\r\n puts input_string.length.times.find_all { |i| input_string[i,input_query.length] == input_query && i%2 ==0 }.length>0 ? \"YES\" : \"NO\"\r\n end\r\n", "positive_code": [{"source_code": "t = gets.to_i\r\nt.times {\r\n s = gets.strip\r\n\r\n c = gets[0]\r\n a = (0...s.length).find_all { |i| s[i] == c }\r\n found = false\r\n a.each { |i|\r\n found ||= (i % 2 == 0 && (s.length - i - 1) % 2 == 0)\r\n #puts(\"#{i} #{i % 2 == 0} #{(s.length - i - 1) % 2 == 0} #{(s.length - i - 1)}\")\r\n }\r\n puts(found ? 'yes' : 'no')\r\n}\r\n"}, {"source_code": "cases = STDIN.gets.chomp.to_i\ncases.times.each do \n input_string = STDIN.gets.chomp\n input_query = STDIN.gets.chomp\n puts input_string.length.times.find_all { |i| input_string[i,input_query.length] == input_query }.find_all { |i| i%2==0 }.length>0 ? \"YES\" : \"NO\"\n end"}, {"source_code": "n=gets().chomp.to_i\r\nfor i in 1..n do\r\n s=gets().chomp\r\n n=gets().chomp\r\n c=0\r\n for i in 0...s.length do\r\n if (i+1)%2!=0 && s[i]==n\r\n puts \"YES\"\r\n c+=1\r\n break\r\n end\r\n end\r\n if c==0\r\n puts \"NO\"\r\n end\r\nend"}], "negative_code": [{"source_code": "n=gets().chomp.to_i\r\nfor i in 1..n do\r\n s=gets().chomp\r\n n=gets().chomp\r\n i=0\r\n for i in 0...s.length do\r\n if (i+1)%2!=0 && s[i]==n\r\n puts \"YES\"\r\n break\r\n end\r\n end\r\n if i==s.length\r\n puts \"NO\"\r\n end\r\nend"}], "src_uid": "c569b47cf80dfa98a7105e246c3c1e01"} {"source_code": "def tiles(n,x,y)\n if x == n-1 || x == 0 || y >= n-2\n return false\n else\n return [[x,y],[x-1,y+1],[x,y+1],[x+1,y+1],[x,y+2]]\n end\nend\n\ndef solve (n,board)\n n.times do |i|\n n.times do |j|\n if board[i][j] == \".\"\n #p [i,j]\n t = tiles(n,j,i)\n #p t\n return false if !t\n t.each do |x,y|\n if board[y][x] == \"#\"\n return false\n else\n board[y][x] = \"#\"\n end\n end\n end\n end\n end\n return true\nend\n\nn = gets.to_i\nboard = []\nn.times do\n board << gets.chomp\nend\nputs solve(n,board) ? \"YES\" : \"NO\"", "positive_code": [{"source_code": "N = gets.to_i\nboard = N.times.map { gets.chomp.chars }\n\nN.times do |y|\n N.times do |x|\n next if board[y][x] == '#'\n\n ay, ax = y, x\n by, bx = y + 1, x - 1\n cy, cx = y + 1, x\n dy, dx = y + 1, x + 1\n ey, ex = y + 2, x\n\n max_y = [ay, by, cy, dy, ey].max\n min_x, max_x = [ax, bx, cx, dx, ex].minmax\n\n if max_y >= N || min_x < 0 || N <= max_x\n puts 'NO'\n exit\n end\n\n [ay, by, cy, dy, ey].zip([ax, bx, cx, dx, ex]).each do |ny, nx|\n if board[ny][nx] == '#'\n puts 'NO'\n exit\n end\n\n board[ny][nx] = '#'\n end\n end\nend\n\nputs 'YES'\n"}, {"source_code": "n = gets.to_i\ns = n.times.map{gets.chomp}\nd = [0,1,0,-1]\nfor i in 1..n-2\n for j in 1..n-2\n if s[i][j] == \".\"\n f = true\n 4.times do |k|\n f = false if s[i+d[k]][j+d[k^1]] == \"#\"\n end\n if f\n 4.times do |k|\n s[i+d[k]][j+d[k^1]] = \"#\"\n end\n s[i][j] = \"#\"\n end\n end\n end\nend\nif s.join(\"\").count(\".\") > 0\n puts \"NO\"\nelse\n puts \"YES\"\nend"}], "negative_code": [], "src_uid": "cc1feee94617c0cba1c528a0cb3952a8"} {"source_code": "cityNum, capitalNum = gets.chomp.split(' ').map(&:to_i)\nprices = gets.chomp.split(' ').map(&:to_i)\ncapitals = gets.chomp.split(' ').map(&:to_i)\nisCapital = Array.new(cityNum) { |i| i = false }\n#isMarked = Array.new(cityNum) { |i| i = false }\n\nrawSum = 0\nrawCapSum = 0\n\nprices.each do |p|\n\trawSum += p\nend\n\ncapitals.each do |c|\n\trawCapSum += prices[c - 1]\n\tisCapital[c - 1] = true\nend\n\ntotalSum = 0\n\nfor i in 0...(prices.length)\n\ttotalSum += (prices[i] * prices[(i + 1) % cityNum])\nend\n\n\n#puts \"Total : #{totalSum}\"\n\ncapitals.each do |c|\n\tpartialSum = rawSum - prices[c - 1]\n\t#puts \"Partial : #{partialSum}\"\n\ttotalSum += partialSum * prices[c - 1]\n\t#puts \"c : #{c}, ts = #{totalSum}\"\nend\n\n#puts \"Total : #{totalSum}\"\n\n\tcount = 1\n\tcapitals.each do |c|\n\t\ttotalSum -= prices[c - 1] * (prices[c % cityNum] + prices[if c - 2 >= 0 then c - 2 else cityNum - 1 end])\n\t\tbreak if count == capitalNum\n\n\t\tpartialSum = rawCapSum - prices[c - 1]\n\n\t\tif isCapital[c % cityNum]\n\t\t\tpartialSum -= prices[c % cityNum]\n\t\tend\n\n\n\t\tif c == 1 && isCapital[if c - 2 >= 0 then c - 2 else cityNum - 1 end]\n\t\t\tpartialSum -= prices[if c - 2 >= 0 then c - 2 else cityNum - 1 end]\n\t\tend\n\n\t\t#puts \"c : #{c}\"\n\t\t#puts \"raw : #{rawCapSum}\"\n\t\t#puts \"partial : #{partialSum}\"\n\n\t\ttotalSum -= prices[c - 1] * partialSum\n\t\trawCapSum -= prices[c - 1]\n\t\tcount += 1\n\tend\n\nputs totalSum", "positive_code": [{"source_code": "n, k = gets.split.map { |x| x.to_i }\nc = gets.split.map { |x| x.to_i }\nid = gets.split.map { |x| x.to_i }\n\ncap = Array.new n\nid.each do |x|\n\tcap[x - 1] = true\nend\n\nsc = 0\nsc2 = 0\nn.times do |i|\n\tif cap[i]\n\t\tsc += c[i]\n\t\tsc2 += c[i] ** 2\n\tend\nend\n\nsum = 0\nans = (sc ** 2 - sc2) / 2\nn.times do |i|\n\tsum += c[i] if !cap[i]\nend\nn.times do |i|\n\tans += c[i] * sum if cap[i]\nend\n\nn.times do |i|\n\tif !cap[i - 1] and !cap[i]\n\t\tans += c[i - 1] * c[i]\n\tend\nend\n\nputs ans"}], "negative_code": [], "src_uid": "bc6b8fda79c257e6c4e280d7929ed8a1"} {"source_code": "n,t=gets.split.map(&:to_i);\ny=n+1;\na = (1..n).map{gets.split.map(&:to_i)}\na = a.sort\na.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>2*t;j;}\np y", "positive_code": [{"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y"}, {"source_code": "n,t=gets.split.map &:to_i;s=[];1.upto(n){s<< gets.split.map(&:to_i)};y=2;x,a=s.sort!.shift;s.each{|i|s=x+x+a;x,a=i;y+=(x+x-a-s<=>t+t)+1};puts y"}, {"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y"}, {"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y"}, {"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y\n"}, {"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y\n"}, {"source_code": "##\n# 15A\n# Author: Sammy Teahan\n#\n\nif __FILE__ == $0\n\n n, t = gets.split.map(&:to_i)\n count = 2\n houses = []\n\n class House\n attr_reader :left, :right\n\n def initialize(x, a)\n @left = x - a / 2\n @right = x + a / 2\n end\n\n end\n\n n.times do |k|\n x, a = gets.split.map(&:to_f)\n house = House.new(x, a)\n houses << house\n end\n\n houses.sort_by! do |house|\n house.left\n end\n\n (houses.size - 1).times do |house|\n if houses[house].right + t < houses[house + 1].left\n count += 2\n elsif\n houses[house].right + t == houses[house + 1].left\n count += 1\n end\n end\n\n puts count\nend\n"}, {"source_code": "##\n# 15A\n# Author: Sammy Teahan\n#\n\nif __FILE__ == $0\n\n n, t = gets.split.map(&:to_i)\n count = 2\n houses = []\n\n class House\n attr_reader :left, :right\n\n def initialize(x, a)\n @left = (x - a / 2)\n @right = (x + a / 2)\n end\n\n end\n\n n.times do |k|\n x, a = gets.split.map(&:to_f)\n house = House.new(x, a)\n houses << house\n end\n\n # Sort our houses\n houses.sort_by! do |house|\n house.left\n end\n\n (houses.size - 1).times do |house|\n if houses[house].right + t < houses[house + 1].left\n count += 2\n elsif\n houses[house].right + t == houses[house + 1].left\n count += 1\n end\n end\n\n puts count\nend\n"}, {"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y\n"}, {"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y"}, {"source_code": "n, t = gets.split.map(&:to_i)\nt = t.to_f\nkoord = Array.new\nn.times { koord << gets.split.map(&:to_f) }\nkoord.sort!\nret = 2\n(1...(n)).each do |i|\n x_i_1 = koord[i-1][0] + koord[i-1][1] / 2\n x_i_2 = koord[i][0] - koord[i][1].abs / 2\n diff = (x_i_1 - x_i_2).abs\n if diff == t\n ret += 1\n elsif diff > t\n ret += 2\n end\nend\nputs ret\n"}, {"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y\n"}, {"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y\n"}, {"source_code": "# Problem A\n# by vi002\n\nn, t = gets.split.map { |v| v.to_i }\ndata = Array.new(n) { gets.split.map { |v| v.to_i } }.sort\n\nresult = 2\n(0 ... n - 1).each do |pos|\n distance = 2 * (data[pos + 1].first - data[pos].first)\n distance -= data[pos][1] + data[pos + 1][1]\n result += 2 if distance > 2 * t\n result += 1 if distance == 2 * t\nend\n\nputs result\n"}, {"source_code": "s,n,t = 2,gets(' ').to_i,gets.to_i*2\n([0]*n).map{[gets(' ').to_i,gets.to_i]}.sort_by{|i|i[0]}.\ninject{|i,j|r=j[0]*2-i[0]*2-i[1]-j[1];s+=(r>t ? 2:r==t ? 1:0);j}\np s"}, {"source_code": "n,t=gets.split.map(&:to_i)\nbuilt=[]\nn.times{\n\tx,a=gets.split.map(&:to_i)\n\tbuilt<<[2*x-a,2*x+a]\n}\namount=2 #left and right most already possible\nbuilt.sort{|a,b|a[0]<=>b[0]}.each_cons(2){|l,r|amount+=r[0]-l[1]<=>2*t}\nputs amount+n-1"}, {"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y\n"}, {"source_code": "require 'set'\ndef check(x,t)\n ok=false\n $m.each{|h|\n if x+t<=h[0] || h[0]+h[1]<=x then\n else\n return false\n end\n }\n return true\nend\nn,t=gets.split.map(&:to_i)\nt*=2\n$m=[]\nn.times{|i|\n $m.push(gets.split.map(&:to_i))\n $m[i][0]*=2\n $m[i][0]-=$m[i][1]\n $m[i][1]*=2\n}\n\nq=Set.new\n$m.each{|h|\n if(check(h[0]-t,t)) then\n q.add(h[0]-t)\n end\n if(check(h[0]+h[1],t)) then\n q.add(h[0]+h[1])\n end\n}\nputs q.length\n"}, {"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y\n"}, {"source_code": "n,t=gets.split.map &:to_i;y=n+1;(1..n).map{gets.split.map &:to_i}.sort.inject{|i,j|y+=j[0]*2-j[1]-i[0]*2-i[1]<=>t+t;j};p y\n"}, {"source_code": "n,t=gets.split.map &:to_i;s=[];1.upto(n){s<< gets.split.map(&:to_i)};s.sort!;y=2;x,a=s.shift;s.each{|i|s=x+x+a;x,a=i;y+=(x+x-a-s<=>t+t)+1};puts y"}, {"source_code": "n,t=gets.split.map &:to_i;s=[];1.upto(n){s<< gets.split.map(&:to_i)};s.sort!;y=2;x,a=s.shift;s.each{|i|s=x+x+a;x,a=i;s=x+x-a-s;y+=(s<=>t+t)+1};puts y"}], "negative_code": [{"source_code": "n,t,m = gets(' ').to_i,gets.to_i,[0]*2000\nn.times do\n x,a = gets(' ').to_i,gets.to_i\n for i in [-1000,x-a/2].max...[x+a/2,1000].min\n m[i] = 1\n end\nend\nss = s = m[-1000,t].inject(&:+)\ny = (s==0 ? 0 : 1)\ndd = (s+ss==1 ? 1 : 0)\nfor i in (-1000+t)..999\n s += m[i]-m[i-t]\n y += (((d = (s+ss==1 ? 1 : 0)))==1 && dd==0 ? 1 : 0)\n dd,ss = d,s\nend\np y+(s==0 ? 0 : 1)"}, {"source_code": "s,n,t = 2,gets(' ').to_i,gets.to_i\n([0]*n).map{[gets(' ').to_i,gets.to_i]}.sort_by{|i|i[0]}.\ninject{|i,j|r=j[0]-i[0]-(i[1]+j[1])/2;s+=(r>t ? 2:r==t ? 1:0);j}\np s"}, {"source_code": "n,t,x,a=(gets+gets).split.map &:to_i;y=2;2.upto(n){s=x+x+a;x,a=gets.split.map &:to_i;s=x+x-a-s;y+=(s<=>t+t)+1};puts y"}, {"source_code": "n,t=gets.split.map(&:to_i)\nbuilt=[]\nn.times{\n\tx,a=gets.split.map(&:to_i)\n\tbuilt<<[x-a/2,x+a/2]\n}\namount=2 #left and right most already possible\nbuilt.each_cons(2){|(l,r)|\n\tamount+=(r[0]-l[1]<=>t)+1\n}\nputs amount\n"}, {"source_code": "n,t=gets.split.map(&:to_i)\nbuilt=[]\nn.times{\n\tx,a=gets.split.map(&:to_i)\n\tbuilt<<[x-a/2,x+a/2]\n}\namount=2 #left and right most already possible\nbuilt.sort{|a,b|a[0]<=>b[0]}.each_cons(2){|(l,r)|amount+=r[0]-l[1]<=>t}\nputs amount+n-1\n"}], "src_uid": "c31fed523230af1f904218b2fe0d663d"} {"source_code": "gets.to_i.times do\r\n n, k = gets.split.map(&:to_i)\r\n abs = if k % 2 == 1\r\n (1..n).step(2).map do |i|\r\n [i, i + 1]\r\n end\r\n else\r\n odds = (1..n).step(2).to_a\r\n (4..n).step(4).map do |b|\r\n [odds.pop, b]\r\n end + (2..n).step(4).map do |a|\r\n [a, odds.pop]\r\n end\r\n end\r\n if abs.all? { |a, b| (a + k) * b % 4 == 0 }\r\n puts \"YES\"\r\n abs.each do |a, b|\r\n puts \"#{a} #{b}\"\r\n end\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n", "positive_code": [{"source_code": "def main\n t = inp.to_i\n t.times do\n n, k = mapint(inarr)\n if k % 4 == 0\n puts \"NO\"\n next\n end\n puts \"YES\"\n ans = \"\"\n\n r = Array.new(n>>1)\n\n pos = 0\n i = 1\n while i <= n\n if ((i + k) * (i + 1) & 3) == 0\n r[pos] = \"#{i} #{i+1}\"\n else\n r[pos] = \"#{i + 1} #{i}\"\n end\n pos+=1\n i+=2\n end\n\n puts r\n\n end\n\nend\n\n# lib\ndef inp\n gets.chomp\nend\n\ndef inarr\n gets.chomp.split\nend\n\ndef mapint(lst)\n lst.map(&:to_i)\nend\n\ndef max(a, b)\n (a > b)? a:b\nend\n\ndef min(a, b)\n (a < b)? a:b\nend\n\nmain"}], "negative_code": [{"source_code": "def main\n t = inp.to_i\n t.times do\n n, k = mapint(inarr)\n if k == 0\n puts \"NO\"\n next\n end\n puts \"YES\"\n ans = \"\"\n\n\n 1.step(n, 2) do |i|\n if ((i + k) * (i + 1) & 3) == 0\n ans += \"#{i} #{i+1}\\n\"\n else\n ans += \"#{i + 1} #{i}\\n\"\n end\n\n end\n\n puts ans\n\n end\nend\n\n# lib\ndef inp\n gets.chomp\nend\n\ndef inarr\n gets.chomp.split\nend\n\ndef mapint(lst)\n lst.map(&:to_i)\nend\n\ndef max(a, b)\n (a > b)? a:b\nend\n\ndef min(a, b)\n (a < b)? a:b\nend\n\nmain"}, {"source_code": "def main\n t = inp.to_i\n t.times do\n n, k = mapint(inarr)\n if k == 0\n puts \"NO\"\n next\n end\n puts \"YES\"\n ans = \"\"\n if k % 2 == 0\n 1.step(n, 2) do |i|\n ans += \"#{i + 1} #{i}\\n\"\n end\n else\n 1.step(n, 2) do |i|\n ans += \"#{i} #{i+1}\\n\"\n end\n end\n puts ans\n\n end\nend\n\n# lib\ndef inp\n gets.chomp\nend\n\ndef inarr\n gets.chomp.split\nend\n\ndef mapint(lst)\n lst.map(&:to_i)\nend\n\ndef max(a, b)\n (a > b)? a:b\nend\n\ndef min(a, b)\n (a < b)? a:b\nend\n\nmain"}, {"source_code": "gets.to_i.times do\r\n n, k = gets.split.map(&:to_i)\r\n if k == 0\r\n puts \"NO\"\r\n elsif k % 2 == 1\r\n puts \"YES\"\r\n (1..n).step(2).each do |i|\r\n puts \"#{i} #{i + 1}\"\r\n end\r\n else\r\n puts \"YES\"\r\n (1..n).step(2).each do |i|\r\n if (i + k) % 4 == 1\r\n puts \"#{i} #{i + 1}\"\r\n else\r\n puts \"#{i + 1} #{i}\"\r\n end\r\n end\r\n end\r\nend\r\n"}], "src_uid": "d4fc7e683f389e0c7bbee8e115cef459"} {"source_code": "_,a,b=$<.map &:chomp\nif !a.index('*')\n\tputs a==b ? :Yes : :No\nelse\n\tx,y=a.split('*')\n\tx||='';y||=''\n\tputs b.start_with?(x) && b.end_with?(y) && b.size>=x.size+y.size ? :Yes : :No\nend", "positive_code": [{"source_code": "sl,tl=gets.strip.split.map(&:to_i)\nml = (sl=0 && j>=0 && s[i]==t[j] do\n i -= 1\n j -= 1\n end\n if i>=0 && j>=0 && s[i]!='*'\n puts \"NO\"\n exit 0\n end\n puts \"YES\"\nend"}, {"source_code": "n,m = gets.chomp.split(\" \").map(&:to_i)\ns,t = gets.chomp,gets.chomp\nans = true\nif s.include?(\"*\")\n if s[-1] == \"*\" && s.delete(\"*\") != t[0,s.size-1]\n ans = false\n elsif s[-1] != \"*\"\n a,b = s.split(\"*\")\n if a != t[0,a.size] || b != t[m-b.size..-1] || m < n-1\n ans = false\n end\n end\nelsif s != t\n ans = false\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "#! /usr/bin/env ruby\n\nn, m = gets.split.map(&:to_i)\ns = gets.chomp\nt = gets.chomp\n\nif s.include?(\"*\")\n a, b = s.split(\"*\")\n if a == nil and b == nil\n puts \"YES\"\n elsif a == nil\n puts (t.end_with?(b) ? \"YES\" : \"NO\")\n elsif b == nil\n puts (t.start_with?(a) ? \"YES\" : \"NO\")\n else\n if t.start_with?(a) and t.end_with?(b)\n if a.size + b.size <= m\n puts \"YES\"\n else\n puts \"NO\"\n end\n else\n puts \"NO\"\n end\n end\nelse\n puts (s == t ? \"YES\" : \"NO\")\nend\n"}, {"source_code": "N, M = gets.split.map(&:to_i)\ns = '!' + gets.chomp + '!'\nt = '!' + gets.chomp + '!'\nif s.include?('*')\n s1, s2 = s.split('*')\n if s.length-1 <= t.length && s1 == t[0, s1.length] && s2 == t[t.length-s2.length, s2.length]\n puts 'YES'\n else\n puts 'NO'\n end\nelse\n if s == t\n puts 'YES'\n else\n puts 'NO'\n end\nend"}], "negative_code": [{"source_code": "gets;puts /#{gets.chomp.gsub('*','.*')}/=~gets.chomp ? :Yes : :No"}, {"source_code": "n,m = gets.chomp.split(\" \").map(&:to_i)\ns,t = gets.chomp,gets.chomp\nfirst,second = true,true if s.include?(\"*\")\nif s[0] != \"*\" && first\n a = s.split(\"*\")[0]\n i = t.index(a)\n if i\n t.slice!(0,i+a.size)\n else\n first = false\n end\nend\nif s[-1] != \"*\" && second\n b = s.split(\"*\")[1]\n i = t.rindex(b)\n if i\n t.slice!(0,i+b.size)\n if t.size != 0\n second = false\n end\n else\n second = false\n end\nend\nputs (first && second) || s == t ? \"YES\" : \"NO\"\n"}, {"source_code": "n,m = gets.chomp.split(\" \").map(&:to_i)\ns,t = gets.chomp.split(\"*\"),gets.chomp\nans = true\nfor i in 0..s.size-1\n j = t.index(s[i],0)\n if j\n t.slice!(0,j+s[i].size)\n else\n ans = false\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "n,m = gets.chomp.split(\" \").map(&:to_i)\ns,t = gets.chomp.split(\"*\"),gets.chomp\nans = true\np s,t\nfor i in 0..s.size-1\n j = t.index(s[i],0)\n if j\n t.slice!(0,j+s[i].size)\n else\n ans = false\n end\n p t\nend\nputs (ans&&t.size==1) ? \"YES\" : \"NO\"\n"}, {"source_code": "n,m = gets.chomp.split(\" \").map(&:to_i)\ns,t = gets.chomp.split(\"*\"),gets.chomp\nans = true\nfor i in 0..s.size-1\n j = t.index(s[i],0)\n if j\n t.slice!(0,j+s[i].size)\n else\n ans = false\n end\nend\nputs (ans&&t.size==0) ? \"YES\" : \"NO\"\n"}, {"source_code": "n,m = gets.chomp.split(\" \").map(&:to_i)\ns,t = gets.chomp.split(\"*\"),gets.chomp\nans = true\nfor i in 0..s.size-1\n j = t.index(s[i],0)\n if j\n t.slice!(0,j+s[i].size)\n else\n ans = false\n end\nend\nputs (ans && (t.size == 0 || s.size == 1)) ? \"YES\" : \"NO\"\n"}, {"source_code": "n,m = gets.chomp.split(\" \").map(&:to_i)\ns,t = gets.chomp.split(\"*\"),gets.chomp\nans = true\nfor i in 0..s.size-1\n j = t.index(s[i],0)\n if j\n t.slice!(0,j+s[i].size)\n else\n ans = false\n end\nend\nputs (ans && (t.size == 0 || s.size <= 1)) ? \"YES\" : \"NO\"\n"}, {"source_code": "n,m = gets.chomp.split(\" \").map(&:to_i)\ns,t = gets.chomp.split(\"*\"),gets.chomp\nans = true\np s,t\nfor i in 0..s.size-1\n j = t.index(s[i],0)\n if j\n t.slice!(0,j+s[i].size)\n else\n ans = false\n end\n p t\nend\nputs (ans&&t.size==0) ? \"YES\" : \"NO\"\n"}, {"source_code": "#! /usr/bin/env ruby\n\nn, m = gets.split.map(&:to_i)\ns = gets.chomp\nt = gets.chomp\n\nif s.include?(\"*\")\n a, b = s.split(\"*\")\n if a == nil and b == nil\n puts \"YES\"\n elsif a == nil\n puts (t.include?(b) ? \"YES\" : \"NO\")\n elsif b == nil\n puts (t.include?(a) ? \"YES\" : \"NO\")\n else\n li, ri = t.index(a), t.rindex(b)\n if li == nil or ri == nil\n puts \"NO\"\n else\n if li + a.size <= ri\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\n end\nelse\n puts (s == t ? \"YES\" : \"NO\")\nend\n"}], "src_uid": "d629d09782a7af0acc359173ac4b4f0a"} {"source_code": "class CodeForces\n\n attr_reader :answer\n\n def initialize(test_cases)\n @test_cases = test_cases\n end\n\n\ndef answer\n \n@test_cases.to_i.times do |i|\n\n args = gets.chomp \n solve(args) \n\nend\nend\n\nprivate\n\ndef solve(args)\n\n # multiple assign here!\n # use the right amount of variables\n \n # a = args.split(\" \").map(&:to_i)\n\n\n # do work here\n answer = args.to_s.size\n\n\n\n\n\n\n puts answer\nend\nend\n\n\n\nCodeForces.new(gets.chomp).answer\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.split(\"\")\n puts n.size\n\nend"}], "negative_code": [], "src_uid": "ea011f93837fdf985f7eaa7a43e22cc8"} {"source_code": "gets.to_i.times do\r\n gets\r\n a = gets.split.map &:to_i\r\n a.delete a.min\r\n puts a.size\r\nend", "positive_code": [{"source_code": "alias g gets;g.to_i.times{g;a=g.split.map &:to_i;p a.size-a.count(a.min)}"}, {"source_code": "alias g gets;g.to_i.times{g;a=g.split.map &:to_i;puts a.size-a.count(a.min)}"}, {"source_code": "alias g gets\r\ng.to_i.times {\r\n g\r\n a = g.split.map &:to_i\r\n puts a.size - a.count(a.min)\r\n}"}, {"source_code": "def g \r\n gets\r\nend \r\ng.to_i.times {\r\n g\r\n a = g.split.map &:to_i\r\n puts a.size - a.count(a.min)\r\n}"}, {"source_code": "gets.to_i.times do\r\n gets\r\n a = gets.split.map &:to_i\r\n puts a.size - a.count(a.min)\r\nend"}, {"source_code": "gets.to_i.times do\n _ = gets\n arr = gets.split.map &:to_i\n min = arr.min\n sum = 0\n for i in arr\n sum += 1 if i > min\n end\n\n puts sum\nend\n"}, {"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n a=gets.split.map(&:to_i)\r\n a.delete(a.min)\r\n puts a.size\r\nend\r\n"}], "negative_code": [], "src_uid": "99e5c907b623c310d6f1599f485ca21d"} {"source_code": "# Vanya and Fence\n# https://codeforces.com/problemset/problem/677/A\n\n# _nums, f_height = gets.strip.split.map(&:to_i)\nf_height = gets.strip.split.last.to_i\np_height = gets.strip.split.map(&:to_i)\nwidth = 0\n\np_height.each do |h|\n width +=\n h <= f_height ? 1 : 2\nend\n\nputs width\n", "positive_code": [{"source_code": "a,b = gets.split(\" \").map(&:to_i) \narr = gets.split(\" \").map(&:to_i) \nresult = 0\narr.each_index do |i|\n num = arr[i]\n if num <= b \n result+=1\n else\n result+=2\n end\nend\nputs result\n"}, {"source_code": "(_,h)=gets.split.map(&:to_i);puts gets.split.inject(0){|s,v|s+((v.to_i>h)?2:1)}"}, {"source_code": "n,h=gets.split.map &:to_i;p n+gets.split.count{|_|_.to_i>h}"}, {"source_code": "n, h = gets.chomp.split.map(&:to_i)\nas = gets.chomp.split.map(&:to_i)\n\nputs as.map { |a| a <= h ? 1 : 2 }.inject(&:+)\n"}, {"source_code": "n_f = gets.chomp\nh = gets.chomp\nn_fence = n_f.split\n\nheights = h.split\nfriends = n_fence[0]\nfence = n_fence[1]\n\nwidth = 0\nheights.each do |height|\n\tif height.to_i <= fence.to_i\n\t\twidth += 1\n\telse\n\t\twidth += 2\n\tend\nend\n\nprint width"}, {"source_code": "#!/usr/bin/ruby\n\nn, h = gets.chomp.split(\" \")\nh = h.to_i\na = gets.chomp\n\nb = a.split(\" \")\n\nsum = 0\nb.each do |i|\n sum += 1 if (i.to_i <= h.to_i)\n sum += 2 if (i.to_i > h.to_i)\nend\n\nputs sum\n"}, {"source_code": "n , h = gets.split(\" \")\nn = n.to_i\nh = h.to_i\ns = gets.split(\" \").map(&:to_i)\nans = 0\ns.each do |i|\n if i > h\n ans += 2\n else\n ans += 1\n end\nend\nputs ans\n"}, {"source_code": "a, b = gets.split.map &:to_i\nc = gets.split.map &:to_i\nw = 0\nc.map {|x| w += (x + b -1)/b}\nputs w\n"}, {"source_code": "n,h=gets.split.map &:to_i;p n+gets.split.count{|_|_.to_i>h}"}, {"source_code": "#!/usr/bin/env ruby\n\nn,h = gets.split.map(&:to_i)\nans = gets.split.map(&:to_i).inject(0) { |s,elem| s + (elem + h - 1) / h }\nputs ans\n"}, {"source_code": "n, h = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nputs a.count{|x| x > h} + n\n"}, {"source_code": "n, h = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = a.map{|x| x <= h ? 1 : 2}.inject(:+)\nputs ans\n"}, {"source_code": "n, h = gets.split.map(&:to_i)\np gets.split.map(&:to_i).map{|x|x <= h ? 1 : 2}.inject(:+)"}, {"source_code": "first = gets.chomp.split(\" \")\nh = first[1].to_i\nsecond = gets.chomp.split(\" \")\n\narr = second.collect{ |el| el.to_i}\n\nres = 0\n\nfor a in arr\n if a > h\n res += 2\n else\n res += 1\n end\nend\n\nputs res"}, {"source_code": "totalFriends, fenceHeight = gets.split.map(&:to_i)\ntotalBendFriends = gets.split.count { |e| e.to_i > fenceHeight}\nputs totalFriends + totalBendFriends"}, {"source_code": "n, h = gets.split(' ').map(&:to_i)\na = gets.split(' ').map(&:to_i)\n\nputs a.size + a.count { |x| x > h }\n"}, {"source_code": "n,h=gets.split.map &:to_i;p n+gets.split.count{|_|_.to_i>h}\n"}, {"source_code": "n,m = gets.chomp.split.map(&:to_i)\narr = gets.chomp.split.map(&:to_i)\nputs arr.map{|i| i > m ? 2 : 1}.reduce(:+)"}, {"source_code": "n, h = gets.chomp.split(' ').map { |i| i.to_i }\npersonHeight = gets.chomp.split(' ').map { |i| i.to_i }\n\nans = 0\n\npersonHeight.each do |pH|\n\tans += 1 if pH <= h\n\tans += 2 if pH > h\nend\n\nputs ans"}, {"source_code": "n,h=gets.split.map(&:to_i)\np n+gets.split.count{|e|e.to_i>h}"}, {"source_code": "n, h = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i).select { |i| i > h }\nputs n + arr.size\n"}, {"source_code": "n,h = gets.chomp.split(\" \")\nfriends = gets.chomp.split(\" \").map(&:to_i)\n\ndef vanya_fence(n,h, friends)\n min_width = 0\n friends.each do |f|\n min_width += 1\n min_width += 1 if f > h.to_i\n end\n min_width\nend\n\np vanya_fence(n,h, friends)\n"}, {"source_code": "n, h = gets.chomp.split.map(&:to_i)\narr = gets.chomp.split.map(&:to_i).map { |d| d <= h ? 1 : 2 }\nputs arr.inject(0, :+)\n"}, {"source_code": "n,h=gets.split.map &:to_i;p n+gets.split.count{|_|_.to_i>h}"}, {"source_code": "n, m = gets.split.map &:to_i\n\nans = 0\n\na = []\na = gets.split.map &:to_i\n\na.each do |i|\n if (i > m)\n ans += 2\n else \n ans += 1\n end\nend\n\nputs ans"}, {"source_code": "_, zLen = STDIN.gets.chomp.split.map(&:to_i)\np STDIN.gets.chomp.split.inject(0){ |z, v| z + ((v.to_i - 1) / zLen) + 1 }"}, {"source_code": "def string_to_int(string, delim = \" \")\n result = []\n string = string.split(delim)\n for i in 0...string.length\n result[i] = string[i].to_i\n end\n return result\nend\n\ndef width(string, delim = \" \", height_limit)\n sum = 0\n string = string.split(delim)\n for i in 0...string.length\n if string[i].to_i > height_limit\n\t\tsum = sum + 2\n else\n\t\tsum = sum + 1\n end\n end\n return sum\nend\n\ninput = string_to_int(gets.chomp)\nlimit = input[1]\nputs width(gets.chomp, \" \", limit)\n"}, {"source_code": "x, y = gets.chomp().split(\" \")\nans = 0\narr = gets().split(\" \").each {|m| ans+= m.to_i > y.to_i ? 2:1}\nputs ans"}, {"source_code": "x, y = gets.chomp().split(\" \").each {|x| x.to_i}\n#puts x,y\nans = 0\narr = gets().split(\" \").each {|m| ans+= m.to_i > y.to_i ? 2:1}\nputs ans"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i) \narr = gets.split(\" \").map(&:to_i) \nwidth =0 \narr.each do |val| \n if val > k \n width +=2 \n else \n width +=1 \n end \nend \nputs width "}, {"source_code": "x= gets.chomp.split(' ').map(&:to_i)\ny= gets.chomp.split(' ').map(&:to_i)\nc = 0\ny.each do |a|\n if (a>x[1])\n \tc= c+2\n else \n \tc = c +1\n end\n end\n puts c\n"}, {"source_code": "n, h = readline.split(' ').collect(&:to_i)\narr = readline.split(' ').collect(&:to_i)\nputs arr.map{|num| num > h ? 2 : 1}.inject(0, :+)\n"}, {"source_code": "n, h = gets.split.map(&:to_i)\nans = 0\ngets.split.map(&:to_i).each do |i|\n if i > h\n ans += 2\n else\n ans += 1\n end\nend\nputs ans"}, {"source_code": "n, h = gets.chomp.split(/ /).map(&:to_i)\nar = gets.chomp.split(/ /).map(&:to_i)\nans = 0\nar.each_index do |i|\n a = ar[i]\n if a <= h\n ans += 1\n else\n ans += 2\n end\nend\nputs ans\n"}, {"source_code": "n,h=gets.split.map &:to_i;p n+gets.split.count{|_|_.to_i>h}\n"}, {"source_code": "n,h=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\n\nsum=0\nx.map{|e|\n\tsum=sum+((h h\n co += 2\n else\n co += 1\n end\nend\nputs co"}, {"source_code": "n,h = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\na.each do |i|\n\tif i > h\n\t\tn += 1\n\tend\t\nend\nputs n"}, {"source_code": "n, h = gets.split.map(&:to_i)\nputs gets.split.map { |e| e = e.to_i > h ? 2 : 1 }.reduce(:+)"}], "negative_code": [{"source_code": "n,h = gets.chomp.split(\" \")\nfriends = gets.chomp.split(\" \").map(&:to_i)\n\ndef vanya_fence(n,h, friends)\n min_width = 0\n friends.each do |f|\n min_width += 1 if f > h\n end\n min_width\nend\n"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i) \narr = gets.split(\" \").map(&:to_i) \nwidth =0 \narr.each do |val| \n if val >= k \n width +=2 \n else \n width +=1 \n end \nend \nputs width "}], "src_uid": "e7ed5a733e51b6d5069769c3b1d8d22f"} {"source_code": " t = gets.chomp.to_i\n while(t>0)\n \tn_m = gets.chomp.split(\" \")\n \tn = n_m[0].to_i\n \tm = n_m[1].to_i\n \ta_inp = gets.chomp.split(\" \")\n \ta = a_inp.map{|i| i = i.to_i}\n \tb_inp = gets.chomp.split(\" \")\n \tb = b_inp.map{|i| i = i.to_i}\n \tc = []\n \tc = a & b\n \tunless(c.count>0)\n \t\tputs \"NO\"\n \telse\n \t\tputs \"YES\"\n \t\tputs \"1 #{c[0]}\"\n \tend\n \tt = t-1\n end", "positive_code": [{"source_code": "tc = gets.to_i \n\ntc.times do\n n,m = gets.split().map(&:to_i)\n arr = gets.split().map(&:to_i) \n brr = gets.split().map(&:to_i) \n crr = arr & brr \n if(crr.size > 0) \n puts \"YES\"\n puts \"1 #{crr[0]}\"\n else\n puts \"NO\" \n end\nend\n"}, {"source_code": "t = gets.to_i\n\n1.upto t do\n n, m = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n b = gets.split.map(&:to_i)\n c = a.intersection(b)\n if c.empty?\n puts \"NO\"\n else\n puts \"YES\"\n puts \"1 #{c[0]}\"\n end\nend"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n arr = Array.new(1001,0)\n ar = Array.new(1001,0)\n n, m = gets.chomp.split(\" \").map(&:to_i)\n if n >= 2\n a = gets.chomp.split(\" \").map(&:to_i)\n a.each do |i|\n arr[i] += 1\n end\n else\n a = gets.chomp.to_i\n arr[a] += 1\n end\n \n if m >= 2\n b = gets.chomp.split(\" \").map(&:to_i)\n b.each do |j|\n ar[j] += 1\n end\n else\n b = gets.chomp.to_i\n ar[b] += 1\n end\n ans = 0\n (1..1000).each do |k|\n if arr[k] >= 1 && ar[k] >= 1\n puts \"YES\"\n print \"1\"\n print \" \"\n print k\n print \"\\n\"\n ans += 1\n break\n end\n end\n if ans == 0\n puts \"NO\"\n end\nend\n"}, {"source_code": "def read\n gets.split.map(&:to_i)\nend\ngets.to_i.times do\n n, m = read\n a = read\n b = read\n res = nil\n a.each do |i| \n b.each do |j|\n res = i if i == j\n end\n end\n if res.nil?\n puts \"NO\"\n else\n puts \"YES\", 1, res\n end\nend"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\n\t\twhile(t>1)\n\t\t\tn_m = gets.chomp.split(\" \")\n\t\t\tn = n_m[0].to_i\n\t\t\tm = n_m[1].to_i\n\t\t\ta_inp = gets.chomp.split(\" \")\n\t\t\ta = a_inp.map{|i| i = i.to_i}\n\t\t\tb_inp = gets.chomp.split(\" \")\n\t\t\tb = b_inp.map{|i| i = i.to_i}\n\t\t\tc = []\n\t\t\tc = a & b\n\t\t\tunless(c.count>0)\n\t\t\t\tputs \"NO\"\n\t\t\telse\n\t\t\t\tputs \"YES\"\n\t\t\t\tputs \"#{c.count} #{c.join(' ')}\"\n\t\t\tend\n\t\t\tt = t-1\n\t\tend"}, {"source_code": "t = gets.chomp.to_i\nwhile(t>1)\n\tn_m = gets.chomp.split(\" \")\n\tn = n_m[0].to_i\n\tm = n_m[1].to_i\n\ta_inp = gets.chomp.split(\" \")\n\ta = a_inp.map{|i| i = i.to_i}\n\tb_inp = gets.chomp.split(\" \")\n\tb = b_inp.map{|i| i = i.to_i}\n\tc = []\n\tc = a & b\n\tunless(c.count>0)\n\t\tputs \"NO\"\n\telse\n\t\tputs \"YES\"\n\t\tputs \"1 #{c[0]}\"\n\tend\n\tt = t-1\nend"}, {"source_code": "$, = \"\\n\"\ndef read\n gets.split.map(&:to_i)\nend\ngets.to_i.times do\n n, m = read\n a = read\n b = read\n res = nil\n a.each do |i| \n b.each do |j|\n res = i if i == j\n end\n end\n if res.nil?\n puts \"NO\"\n else\n print \"YES\", 1, res\n end\nend"}, {"source_code": "tc = gets.to_i \n\ntc.times do\n n,m = gets.split().map(&:to_i)\n arr = gets.split().map(&:to_i) \n brr = gets.split().map(&:to_i) \n crr = arr & brr \n if(crr.size > 0) \n puts \"YES\"\n puts crr[0]\n else\n puts \"NO\" \n end\nend\n"}], "src_uid": "776a06c14c6fa3ef8664eec0b4d50824"} {"source_code": "require 'set'\n\ndef taskA\n a, b = gets.chomp.split(\" \").map(&:to_i)\n puts b > a ? b - a : (a + b) % 2\nend\n\ndef taskB\n a, b, c = gets.chomp.split(\" \").map(&:to_i)\n z, x, y = gets.chomp.split(\" \").map(&:to_i)\n minCX = [c, x].min\n puts (minCX - [0, y - a - c + minCX].max)*2\nend\n\nt = gets.chomp.to_i\nwhile (t-=1) >= 0\n taskB\nend\n", "positive_code": [{"source_code": "t =gets.to_i\n\nt.times do\n a0,a1,a2 = gets.split.map(&:to_i)\n b0,b1,b2 = gets.split.map(&:to_i)\n mk = [a2,b1].min.clone\n ans = 2*mk\n a2 -= mk\n b1 -= mk\n mk = [a0,b2].min.clone\n a0-=mk\n b2-=mk\n if b2>0 then\n mk = [a2,b2].min.clone\n a2-=mk\n b2-=mk\n end\n ans -= 2*b2\n puts ans\nend"}, {"source_code": "def solve\n x1, y1, z1 = gets.strip.split(' ').map(&:to_i)\n x2, y2, z2 = gets.strip.split(' ').map(&:to_i)\n res = 1\n mn1 = [z1, y2].min #(2, 1)\n z1 -= mn1\n y2 -= mn1\n mn2 = [x1, z2].min #(0, 2)\n z2 -= mn2\n x1 -= mn2\n mn4 = [z1, z2].min #(2, 2)\n z1 -= mn4\n z2 -= mn4\n res *= (2 * mn1)\n res = res - (2 * z2) if !z2.zero?\n puts res\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "t = gets.chomp.to_i\nt.times {\n x1, y1, z1 = gets.chomp.split(' ').map(&:to_i)\n x2, y2, z2 = gets.chomp.split(' ').map(&:to_i)\n ans = 0\n min = [y1, x2].min\n y1 -= min\n x2 -= min\n\n min = [x1, z2].min\n x1 -= min\n z2 -= min\n\n ans = ans + 2 * [z1, y2].min\n min = [z1, y2].min\n z1 -= min\n y2 -= min\n\n min = [z1, z2].min\n z1 -= min\n z2 -= min\n\n min = [y1, y2].min\n y1 -= min\n y2 -= min\n\n ans = ans + -2 * [y1, z2].min\n puts ans\n}"}, {"source_code": "def solve\n x1, y1, z1 = gets.strip.split(' ').map(&:to_i)\n x2, y2, z2 = gets.strip.split(' ').map(&:to_i)\n res = 1\n mn1 = [z1, y2].min #(2, 1)\n z1 -= mn1\n y2 -= mn1\n mn2 = [x1, z2].min #(0, 2)\n z2 -= mn2\n x1 -= mn2\n mn4 = [z1, z2].min #(2, 2)\n z1 -= mn4\n z2 -= mn4\n res *= (2 * mn1)\n res = res - (2 * z2) if !z2.zero?\n puts res\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n x = gets.chomp.split(\" \").map(&:to_i)\n y = gets.chomp.split(\" \").map(&:to_i)\n sum = 0\n num2 = [x[2],y[1]].min\n x[2] -= num2\n y[1] -= num2\n sum += num2 * 2\n minus = [y[2],x[0]].min\n y[2] -= minus\n x[0] -= minus\n minus = [y[2],x[2]].min\n y[2] -= minus\n x[2] -= minus\n num2 = [x[1],y[2]].min\n sum -= num2 * 2\n ans << sum\nend\nans.each do |x|\n puts x\nend"}, {"source_code": "t = gets.chomp.to_i\n\nwhile (t-=1) >= 0\n a, b, c = gets.chomp.split(\" \").map(&:to_i)\n z, x, y = gets.chomp.split(\" \").map(&:to_i)\n minCX = [c, x].min\n puts (minCX - [0, y - a - c + minCX].max)*2\nend"}], "negative_code": [{"source_code": "def solve\n x1, y1, z1 = gets.strip.split(' ').map(&:to_i)\n x2, y2, z2 = gets.strip.split(' ').map(&:to_i)\n res = 1\n mn1 = [z1, y2].min #(2, 1)\n z1 -= mn1\n y2 -= mn1\n mn2 = [x1, z2].min #(0, 2)\n z2 -= mn2\n x1 -= mn2\n mn3 = [y1, y2].min #(1, 1)\n y1 -= mn3\n y2 -= mn3\n mn4 = [z1, z2].min #(2, 2)\n z1 -= mn4\n z2 -= mn4\n res *= (2 * mn1)\n res = res - (z2 * y1) if !z2.zero?\n puts res\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "\nt = gets.chomp.to_i\nt.times {\n x1, y1, z1 = gets.chomp.split(' ').map(&:to_i)\n x2, y2, z2 = gets.chomp.split(' ').map(&:to_i)\n ans = 0\n ans = ans + 2 * [z1, y2].min\n\n z1 -= [z1, y2].min\n y2 -= [z1, y2].min\n\n y1 -= [y1, x2].min\n x2 -= [y1, x2].min\n\n x1 = x1 - [x1, z2].min\n z2 = z2 - [x1, z2].min\n\n ans = ans + -2 * [y1, z2].min\n puts ans\n}"}, {"source_code": "t = gets.chomp.to_i\nt.times {\n x1, y1, z1 = gets.chomp.split(' ').map(&:to_i)\n x2, y2, z2 = gets.chomp.split(' ').map(&:to_i)\n puts (2 * [z1, y2].min)\n}"}, {"source_code": "# t = gets.chomp.to_i\n# t.times {\n# n, k = gets.chomp.split(' ').map(&:to_i)\n# arr = gets.chomp.split(' ').map(&:to_i)\n# max = arr.max\n# arr.map! { |ele| max - ele }\n# max = arr.max\n# if k % 2 == 0\n# arr.map! { |ele| max - ele }\n# end\n# arr.each {|ele| print '%d ' % ele }\n# print '\\n'\n# }\n\n\n\nt = gets.chomp.to_i\nt.times {\n x1, y1, z1 = gets.chomp.split(' ').map(&:to_i)\n x2, y2, z2 = gets.chomp.split(' ').map(&:to_i)\n ans = 0\n ans = ans + 2 * [z1, y2].min\n\n z1 -= [z1, y2].min\n y2 -= [z1, y2].min\n\n y1 -= [y1, x2].min\n x2 -= [y1, x2].min\n\n x1 -= [x1, z2].min\n z2 -= [x1, z2].min\n\n y1 -= [y1, y2].min\n y2 -= [y1, y2].min\n\n ans = ans + -2 * [y1, z2].min\n puts ans\n}"}, {"source_code": "\nt = gets.chomp.to_i\nt.times {\n x1, y1, z1 = gets.chomp.split(' ').map(&:to_i)\n x2, y2, z2 = gets.chomp.split(' ').map(&:to_i)\n ans = 0\n ans = ans + 2 * [z1, y2].min\n\n z1 -= [z1, y2].min\n y2 -= [z1, y2].min\n\n y1 -= [y1, y2].min\n y2 -= [y1, y2].min\n\n y1 -= [y1, x2].min\n x2 -= [y1, x2].min\n\n x1 -= [x1, x2].min\n x2 -= [x1, x2].min\n\n x1 -= [x1, y2].min\n y2 -= [x1, y2].min\n\n x1 -= [x1, z2].min\n z2 -= [x1, z2].min\n\n ans = ans + -2 * [y1, z2].min\n puts ans\n}"}, {"source_code": "\nt = gets.chomp.to_i\nt.times {\n x1, y1, z1 = gets.chomp.split(' ').map(&:to_i)\n x2, y2, z2 = gets.chomp.split(' ').map(&:to_i)\n ans = 0\n y1 -= [y1, x2].min\n x2 -= [y1, x2].min\n\n\n x1 -= [x1, z2].min\n z2 -= [x1, z2].min\n\n ans = ans + 2 * [z1, y2].min\n\n z1 -= [z1, y2].min\n y2 -= [z1, y2].min\n\n z1 -= [z1, z2].min\n z2 -= [z1, z2].min\n\n y1 -= [y1, y2].min\n y2 -= [y1, y2].min\n\n ans = ans + -2 * [y1, z2].min\n puts ans\n}"}, {"source_code": "\nt = gets.chomp.to_i\nt.times {\n x1, y1, z1 = gets.chomp.split(' ').map(&:to_i)\n x2, y2, z2 = gets.chomp.split(' ').map(&:to_i)\n ans = 0\n ans = ans + 2 * [z1, y2].min\n\n z1 -= [z1, y2].min\n y2 -= [z1, y2].min\n\n y1 -= [y1, x2].min\n x2 -= [y1, x2].min\n\n x1 = x1 - [x1, z2].min\n z2 = z2 - [x1, z2].min\n\n x1 -= [x1, z2].min\n z2 -= [x1, z2].min\n \n ans = ans + -2 * [y1, z2].min\n puts ans\n}"}], "src_uid": "e1de1e92fac8a6db3222c0d3c26843d8"} {"source_code": "gets.to_i.times do \n gets\n as = gets.split.map(&:to_i).sort\n ok = as.include?(1) ? as.each_cons(2).none? { |a, b| b - a == 1 } : true\n puts ok ? \"YES\" : \"NO\"\nend\n\n \t\t \t \t \t \t \t\t \t\t \t", "positive_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n as = gets.split.map(&:to_i).sort\r\n ok = as.include?(1) ? as.each_cons(2).none? { |a, b| b - a == 1 } : true\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n as = gets.split.map(&:to_i)\r\n ok = as.include?(1) ? as.all?(&:odd?) : true\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n"}], "src_uid": "c7e4f544ec8b4972291542e66aff5df5"} {"source_code": "a=gets.chomp.split(\" \").map {|i| i.to_i }\nar=[]\non=[]\na[0].times do \ntemp=gets.chomp.split(\" \")\nmax=0\nt=0\ntemp.each do |i|\nif i==\"1\" \nt+=1\nelse\nif t>max\nmax=t\nend\nt=0\nend\nend\nif t>max\nmax=t\nend\non << max\nar << temp\nend\n\na[2].times do \ntemp=gets.chomp.split(\" \").map {|i| i.to_i}\nif ar[temp[0]-1][temp[1]-1]==\"1\"\nar[temp[0]-1][temp[1]-1]=\"0\"\nelse\nar[temp[0]-1][temp[1]-1]=\"1\"\nend\nmax=0\nt=0\nar[temp[0]-1].each do |i|\nif i==\"1\" \nt+=1\nelse\nif t>max\nmax=t\nend\nt=0\nend\nend\nif t>max\nmax=t\nend\non[temp[0]-1]=max\nputs \"#{on.max}\"\nend\n\n\n\n\n", "positive_code": [{"source_code": "def row_sum(arr)\n sum = 0\n total = 0\n for i in 0...arr.size\n if arr[i] == 0\n sum = 0\n else\n sum += 1\n end\n total = [sum,total].max\n end\n total\nend\n\n\ninput = gets.chomp.split(\" \")\nn , m , q = input[0].to_i, input[1].to_i, input[2].to_i\nscores = []\n\ngrid = []\nfor i in 0...n\n #read each row\n grid[i] = gets.chomp.split(\" \").collect{|bear| bear.to_i}\n sum = row_sum(grid[i])\n #puts \"Sum is #{sum}\"\n scores[i] = sum\nend\n\nsolution = []\nfor i in 0...q\n move = gets.chomp.split(' ').collect{|num| num.to_i-1}\n if grid[move[0]][move[1]] == 1\n grid[move[0]][move[1]] = 0\n else\n grid[move[0]][move[1]] = 1\n end\n scores[move[0]] = row_sum(grid[move[0]])\n solution << \"#{scores.max}\"\nend\nputs solution"}, {"source_code": "n, m, q = gets.split.map(&:to_i)\na = n.times.map{gets.split.map(&:to_i)}\nc = Array.new(n, 0)\nn.times do |i|\n j = 0\n while j < m\n if a[i][j] == 1\n t = 0\n j.upto(m) do |k|\n if a[i][k] == 1\n t += 1\n else\n j = k + 1\n c[i] = [c[i], t].max\n break\n end\n end\n else\n j += 1\n end\n end\nend\nq.times do\n i, j = gets.split.map(&:to_i).map{|x| x -= 1}\n a[i][j] ^= 1\n cc = 0\n y = 0\n while y < m\n if a[i][y] == 1\n t = 0\n y.upto(m) do |k|\n if a[i][k] == 1\n t += 1\n else\n y = k + 1\n cc = [cc, t].max\n break\n end\n end\n else\n y += 1\n end\n end\n c[i] = cc\n puts c.max\nend\n"}, {"source_code": "a=gets.chomp.split(\" \").map {|i| i.to_i }\nar=[]\non=[]\na[0].times do \ntemp=gets.chomp.split(\" \")\nmax=0\nt=0\ntemp.each do |i|\nif i==\"1\" \nt+=1\nelse\nif t>max\nmax=t\nend\nt=0\nend\nend\nif t>max\nmax=t\nend\non << max\nar << temp\nend\n\na[2].times do \ntemp=gets.chomp.split(\" \").map {|i| i.to_i}\nif ar[temp[0]-1][temp[1]-1]==\"1\"\nar[temp[0]-1][temp[1]-1]=\"0\"\nelse\nar[temp[0]-1][temp[1]-1]=\"1\"\nend\nmax=0\nt=0\nar[temp[0]-1].each do |i|\nif i==\"1\" \nt+=1\nelse\nif t>max\nmax=t\nend\nt=0\nend\nend\nif t>max\nmax=t\nend\non[temp[0]-1]=max\nputs \"#{on.max}\"\nend\n\n"}, {"source_code": "def getMax(row)\n\tstartNum = 0\n\tcurrentMax = 0\n\tnowIndex = row.index(1)\n\n\tif nowIndex.nil?\n\t\treturn 0\n\tend\n\n\tif nowIndex == row.length\n\t\treturn 1\n\tend\n\n\t#puts \"Rindex : #{endIndex}\"\n\tuntil nowIndex == row.length\n\t\tstartNum += 1 if row[nowIndex] == 1\n\t\tcurrentMax = startNum if currentMax < startNum\n\n\t\tstartNum = 0 if row[nowIndex] == 0\n\n\t\tnowIndex += 1\n\tend\n\n\treturn currentMax\nend\n\ninput = gets.chomp.split(' ').map {|item| item.to_i}\nbears = []\nresult = []\nmaxArray = []\n\nfor i in 0...input[0]\n\tcolumn = gets.chomp.split(' ').map {|item| item.to_i}\n\tbears << column\nend\n\nbears.each do |row|\n\t\tmaxArray << getMax(row)\nend\n\nfor i in 0...input[2]\n\tqueryInput = gets.chomp.split(' ').map {|item| item.to_i}\n\n\tbears[queryInput[0] - 1][queryInput[1] - 1] -= 1\n\tbears[queryInput[0] - 1][queryInput[1] - 1] = 1 if bears[queryInput[0] - 1][queryInput[1] - 1] < 0\n\n\tmaxArray[queryInput[0] - 1] = getMax(bears[queryInput[0] - 1])\n\n\tresult << maxArray.max\nend\n\nresult.each do |item|\n\tputs item\nend"}], "negative_code": [{"source_code": "def row_sum(arr)\n sum = 0\n chunks = []\n arr.chunk{|num| num==1}.each{|val| chunks << val}\n chunks.each do |chk|\n if chk[0] == true\n sum = [sum, chk[1].size].max\n end\n end\n sum\nend\n\n\ninput = gets.chomp.split(\" \")\nn , m , q = input[0].to_i, input[1].to_i, input[2].to_i\n\ngrid = []\nmax_score = 0\nmax_row = 0\nfor i in 0...n\n #read each row\n grid[i] = gets.chomp.split(\" \").collect{|bear| bear.to_i}\n sum = row_sum(grid[i])\n #puts \"Sum is #{sum}\"\n if sum > max_score\n max_score = sum\n max_row = i\n end\nend\n\nsolution = []\nfor i in 0...q\n move = gets.chomp.split(' ').collect{|num| num.to_i-1}\n if grid[move[0]][move[1]] == 1\n grid[move[0]][move[1]] = 0\n else\n grid[move[0]][move[1]] = 1\n end\n #if the move[0] row is bigger than current update it\n sum = row_sum(grid[move[0]])\n #puts \"Move #{move[0]},#{move[1]} changed sum to #{sum}\"\n #puts \"\\tOld Max score is #{max_score}, max row is #{max_row}\"\n if sum > max_score || move[0] == max_row\n max_score = sum\n max_row = move[0]\n end\n #puts \"\\tNew Max score is #{max_score}, max row is #{max_row}\"\n\n solution << \"#{max_score}\"\nend\nputs solution"}, {"source_code": "n, m, q = gets.split.map(&:to_i)\na = n.times.map{gets.split.map(&:to_i)}\nq.times do\n i, j = gets.split.map(&:to_i)\n a[i - 1][j - 1] ^= 1\n mx = 0\n a.each do |x|\n m.times do |k|\n if x[k] == 1\n c = (x[k...m].index(0) || m - k)\n mx = [mx, c].max\n break\n end\n end\n end\n puts mx\nend\n"}, {"source_code": "n, m, q = gets.split.map(&:to_i)\na = n.times.map{gets.split.map(&:to_i)}\nq.times do\n i, j = gets.split.map(&:to_i)\n a[i - 1][j - 1] ^= 1\n puts a.map{|x| x.inject(:+)}.max\nend\n"}], "src_uid": "337b6d2a11a25ef917809e6409f8edef"} {"source_code": "gets.strip.to_i.times do\n n = gets.strip.to_i\n a = gets.strip.split(' ').map(&:to_i)\n sorted = a.dup.sort\n res = false\n n.times do |i|\n rot = a.rotate(i)\n if sorted == rot || sorted.reverse == rot\n puts \"YES\"\n res = true\n break\n end\n end\n puts \"NO\" unless res\nend\n", "positive_code": [{"source_code": "q = gets.to_i\nans = []\nq.times do\n n = gets.to_i\n pp = gets.split.map(&:to_i)\n\n def_a = (1..n).to_a\n diff_a = pp.map.with_index{|num,i|num-def_a[i]}\n diff_a2 = pp.map.with_index{|num,i|num-def_a[n-1-i]}\n can = 2>=diff_a.uniq.size || 2>=diff_a2.uniq.size\n\n ans << (can ? 'YES' : 'NO')\nend\nputs ans\n"}, {"source_code": "#!/usr/bin/env ruby\n\nq = Integer(gets)\n \nresults = Array.new\nq.times do\n\t\n\tn = Integer(gets)\n \n\tarr = gets.chomp.split(\" \").map(&:to_i)\n \n\tfail = false\n\t(n-1).times do |index|\n\t\tif (arr[index] - arr[index+1]).abs >1 && (arr[index] - arr[index+1]).abs != (n-1)\n\t\t\tfail = true\n\t\t\tresults << \"NO\"\n\t\t\tbreak\n\t\tend\n\tend\n \n\tresults << \"YES\" if !fail\nend\n \nresults.each do |result|\n\tputs result\nend"}, {"source_code": "t = gets.to_i\nt.times do |index|\n n = gets.to_i\n a = gets.split(\" \").map(&:to_i)\n c = true\n cc = true\n (n - 1).times do |i|\n # p a[i].to_s+\" \"+a[i+1].to_s+\" \"+i.to_s+\" \"+index.to_s\n if !((a[i] == a[i+1] + 1) || (a[i] == 1 && a[i+1] == n))\n # p \"false c\"\n cc = false\n end\n if !((a[i] + 1 == a[i+1]) || (a[i] == n && a[i+1] == 1))\n # p \"false cc\"\n c = false\n end\n end\n puts (c || cc) ? \"YES\" : \"NO\"\nend"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n s = a.dup.sort\n ok = false\n (0...n).each do |i|\n r = a.rotate i\n if s == r || s.reverse == r\n puts \"YES\"\n ok = true\n break\n end\n end\n puts \"NO\" unless ok\nend"}], "negative_code": [{"source_code": "q = gets.to_i\nans = []\nq.times do\n n = gets.to_i\n pp = gets.split.map(&:to_i)\n\n def_a = (1..n).to_a\n diff_a = pp.map.with_index{|num,i|num-def_a[i]}\n diff_a2 = pp.map.with_index{|num,i|num-def_a[n-1-i]}\n can = n==diff_a.uniq.size || n==diff_a2.uniq.size\n\n ans << (can ? 'YES' : 'NO')\nend\nputs ans"}, {"source_code": "q = gets.to_i\nans = []\nq.times do\n n = gets.to_i\n pp = gets.split.map(&:to_i)\n\n min_i = pp.index(1)\n max_i = pp.index(n)\n dist = (min_i-max_i).abs\n can = false\n\n if dist==0\n can = true\n elsif dist == 1\n left_idx = min_ia}&&ra==ra.sort{|a,b|b<=>a})\n else\n can = pp==pp.sort || pp==pp.sort{|a,b|b<=>a}\n end\n\n ans << (can ? 'YES' : 'NO')\nend\nputs ans"}, {"source_code": "#!/usr/bin/env ruby\n\nq = Integer(gets)\n\nresults = Array.new\nq.times do\n\t\n\tn = Integer(gets)\n\n\tarr = gets.chomp.split(\" \").map(&:to_i)\n\n\tfail = false\n\t(n-1).times do |index|\n\t\tif (arr[index] - arr[index+1]).abs >1 && !(arr[index] ==1 && arr[index+1]== n)\n\t\t\tfail = true\n\t\t\tresults << \"NO\"\n\t\t\tbreak\n\t\tend\n\tend\n\n\tresults << \"YES\" if !fail\nend\n\nresults.each do |result|\n\tputs result\nend\n"}, {"source_code": "t = gets.to_i\nt.times do |index|\n n = gets.to_i\n a = gets.split(\" \").map(&:to_i)\n c = true\n cc = true\n (n - 1).times do |i|\n # p a[i].to_s+\" \"+a[i+1].to_s+\" \"+i.to_s+\" \"+index.to_s\n if !((a[i] == a[i+1] + 1) || (a[i] == 1 && a[i+1] == n))\n # p \"false c\"\n cc = false\n end\n if !((a[i] + 1 == a[i+1]) || (a[i] == n && a[i+1] == 1))\n # p \"false cc\"\n c = false\n end\n end\n p (c || cc) ? \"YES\" : \"NO\"\nend"}, {"source_code": "t = gets.to_i\nt.times do |index|\n n = gets.to_i\n a = gets.split(\" \").map(&:to_i)\n c = true\n cc = true\n (n - 1).times do |i|\n # p a[i].to_s+\" \"+a[i+1].to_s+\" \"+i.to_s+\" \"+index.to_s\n if (a[i] != a[i+1] + 1) && !(a[i] == 1 && a[i+1] == n)\n # p \"false c\"\n c = false\n end\n if (a[i] + 1 != a[i+1]) && !(a[i] == n && a[i+1] == 1)\n # p \"false cc\"\n cc = false\n end\n end\n p (c || cc) ? \"YES\" : \"NO\"\nend"}], "src_uid": "b27436086ead93397be748d8ebdbf19a"} {"source_code": "n = gets.to_i\n\nn.times do\n s = gets.strip\n p = gets.to_i\n\n hashmap = Hash.new(0)\n\n alphabet = ('a'..'z').to_a\n costs = Hash[('a'..'z').each.with_index(1).to_a]\n\n total_cost = 0\n\n s.each_char do |ch|\n hashmap[ch] += 1\n total_cost += costs[ch]\n end\n\n index = alphabet.size - 1\n while (total_cost > p && index > -1)\n count = hashmap[alphabet[index]]\n if count > 0\n hashmap[alphabet[index]] -= 1\n total_cost -= index + 1\n else\n index -= 1\n end\n end\n\n s.each_char do |char|\n next if hashmap[char] == 0\n\n hashmap[char] -= 1\n print(char)\n end\n\n puts\nend\n", "positive_code": [{"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each_slice(2) do |inp|\r\n chars = inp[0].split('')\r\n t = inp[1].to_i\r\n cur = 0\r\n res = ''\r\n\r\n list = chars.each_with_index.map { |x, i| [x, x.bytes.first, i] }\r\n list = list.sort{|a, b| a[1] <=> b[1] }\r\n ok = {}\r\n\r\n cur = 0\r\n list.each do |row|\r\n pos = row[1] - 96\r\n break if cur + pos > t\r\n\r\n cur += pos\r\n ok[ row[2] ] = true\r\n end\r\n\r\n chars.each_with_index do |char, index|\r\n next if !ok[index]\r\n\r\n print char\r\n end\r\n\r\n print \"\\n\"\r\nend"}, {"source_code": "def solve(str, cost)\n # greedy solution, delete most expensive chars (lexicographically sized)\n hash = Hash.new { |h,k| h[k] = [] }\n str.split('').each_with_index do |ch, i|\n hash[ch] << i\n end\n\n chars = hash.keys.sort\n\n chars.each do |ch|\n cost_of_char = ch.ord - 'a'.ord + 1\n # max number of chars allowed in str is cost / cost_of_char\n max_num = cost / cost_of_char\n hash[ch] = hash[ch].take(max_num)\n cost -= hash[ch].length * cost_of_char\n end\n\n ans = []\n hash.each do |ch, indices|\n indices.each do |i|\n ans[i] = ch\n end\n end\n ans.join('')\nend\n\ncases = gets.to_i\ncases.times do\n puts solve(gets.chomp, gets.to_i)\nend\n"}], "negative_code": [{"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each_slice(2) do |inp|\r\n t = inp[1].to_i\r\n\r\n cur = 0\r\n res = ''\r\n inp[0].bytes.each do |char|\r\n pos = char - 96\r\n next if cur + pos > t\r\n\r\n cur += pos\r\n res += char.chr\r\n end\r\n\r\n puts res\r\nend"}], "src_uid": "cb645c794ee3916b180fc3d789cb7c27"} {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\"\n", "positive_code": [{"source_code": "def main()\n\tnd=gets.chomp.split(\" \",2)\n\tnd=nd.map{|i| i.to_i}\n\tn=nd[0]\n\td=nd[1]\n\tp1=[]\n\tp2=[]\n\tt=[]\n\tfor i in 0...n\n\t\tinp=gets.chomp.to_s\n\t\tinpa=inp.split(\" \",3)\n\t\tp1 << inpa[0]\n\t\tp2<< inpa[1]\n\t\tt << inpa[2]\n\tend\n\tfriends=[];\n\tfor i in 0...n\n\t\tfp=p1[i]\n\t\tsp=p2[i]\n\t\ttime=t[i]\n\t\tfor j in (i+1)...n\n\t\t\tfps=p1[j]\n\t\t\tsps=p2[j]\n\t\t\ttimes=t[j]\n\t\t\tif fps==sp && sps==fp\n\t\t\t\ttd=times.to_i-time.to_i\n\t\t\t\tif td>0 && td<=d\n\t\t\t\t\tfriends << (fp+\" \"+sp)\n\t\t\t\t\tbreak;\n\t\t\t\tend\n\t\t\tend \n\t\tend\t\n\tend\n\tff=[]\n\tfor i in 0...(friends.length)\n\t\trel=friends[i]\n\t\tsr=rel.split(\" \",2);\n\t\trel2=sr[1]+\" \"+sr[0];\n\t\tif !(ff.include?(rel) || ff.include?(rel2))\n\t\t\tff<< rel\n\t\tend\t\n\tend\n\tputs ff.length\n\tputs ff\nend\n\nmain()\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\"\n\n"}, {"source_code": "require 'set'\n\nn, d = gets.split.collect{|i| i.to_i}\nmsg = Hash.new{|h,k| h[k] = []}\nfriends = Set.new\n\nn.times{\n f1, f2, t = gets.split\n t = t.to_i\n msg[[f1,f2]] << t\n msg[[f2,f1]].each{|tp|\n if t - tp <= d and t - tp > 0\n friends.add(f1 < f2 ? [f1,f2] : [f2,f1])\n break\n end\n }\n}\n\nputs friends.size\nfriends.each{|f|\n puts f.join(\" \")\n}\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\"\n\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\""}, {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\"\n\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\"\n\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\"\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nans = Hash.new\n\ninput = Array.new\nn.times{\n a, b, t = gets.split\n t = t.to_i\n input.push([a, b, t])\n}\ninput.each{|a|\n input.each{|b|\n if a[0] == b[1] && a[1] == b[0] then\n if (a[2]-b[2]).abs <= d && (a[2]-b[2]).abs > 0 then\n tmp = [a[0],a[1]]\n tmp.sort!\n ans[tmp]=1\n end\n end\n }\n}\np ans.count\nans.each{|a,b|\n puts \"#{a[0]} #{a[1]}\"\n}\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\"\n\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\"\n\n"}, {"source_code": "n,d = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmessages_raw = n.times.map{ from,to,time=STDIN.gets.chomp.split(/ /); {from: from.to_sym, to: to.to_sym, time: time.to_i } }\nmessages = {}\nfriends = []\n\nmessages_raw.each do |message|\n _ = [message[:from],message[:to]]\n a = _.sort\n if messages[_]\n messages[_].each do |old|\n t = message[:time] - old\n if 0 < t && t <= d\n messages.delete a\n friends << a\n end\n end\n end\n messages[_.reverse] ||= []\n messages[_.reverse] << message[:time]\nend\nfriends.uniq!\n\np friends.size\nputs friends.map{|x| x.join(' ') }\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\"\n\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\"\n\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nh = Hash.new{[]}\ns = {}\nn.times{\n c = gets.split\n t = c.pop.to_i\n s[c.sort] = 0 if h[c.reverse].any?{|_| t - d <= _ && _ < t}\n h[c] <<= t\n}\np s.size\nputs s.keys.map{|_| _ * ' '} * \"\\n\""}, {"source_code": "n,m = gets.split.map &:to_i\n\nts = Hash.new{[]}\nans = {}\n\nn.times do\n a = gets.split\n c = a.pop.to_i\n ts[a] <<= c\n\n ans[a.sort] = 0 if ts[a.reverse].any?{ |it| c - it <= m && c > it}\n \n \nend\n\n puts ans.size\n puts ans.keys.map{|_| _ * ' '} * \"\\n\""}, {"source_code": "lines = STDIN.read.split(\"\\n\")\n\n(n, d) = lines[0].split(\" \").map(&:to_i)\n\nlog = lines[1..-1]\n\nmsg = {}\nlog.each{ |line|\n (user1, user2, t) = line.split(\" \")\n t = t.to_i\n \n h = [user1, user2].sort.join(' ')\n \n if line.split(\" \")[0] == h.split(' ')[0] then\n who = 1\n else\n who = 2\n end\n \n if msg.has_key?(h) then\n msg[h][who].push(t);\n else\n msg[h] = {}\n msg[h][1] = []\n msg[h][2] = []\n msg[h][who].push(t)\n end\n}\n\nfriends = 0\npairs = []\n\nmsg.each { |key, value|\n if (value[1].length > 0 && value[2].length > 0) then\n \n found = false\n value[1].each {|v1|\n value[2].each {|v2|\n if (v2 - v1).abs <= d && (v2 - v1 != 0) then\n found = true\n end\n }\n }\n if (found) then\n friends += 1\n pairs.push(key)\n end\n end\n}\n\nputs friends\nputs pairs"}], "negative_code": [{"source_code": "n, d = gets.split.map(&:to_i)\nans = Hash.new\n\ninput = Array.new\nn.times{\n a, b, t = gets.split\n t = t.to_i\n input.push([a, b, t])\n}\ninput.each{|a|\n input.each{|b|\n if a[0] == b[1] && a[1] == b[0] then\n if (a[2]-b[2]).abs <= d then\n tmp = [a[0],a[1]]\n tmp.sort!\n ans[tmp]=1\n end\n end\n }\n}\np ans.count\nans.each{|a,b|\n puts \"#{a[0]} #{a[1]}\"\n}\n\n"}, {"source_code": "n,d = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmessages_raw = n.times.map{ from,to,time=STDIN.gets.chomp.split(/ /); {from: from.to_sym, to: to.to_sym, time: time.to_i } }.sort_by{|x| x[:time] }\nmessages = {}\nfriends = []\n\nmessages_raw.each do |message|\n if messages[message[:from]] && 0 < (message[:time] - messages[message[:from]]) && (message[:time] - messages[message[:from]]) <= d\n messages.delete message[:from]\n friends << [message[:from],message[:to]].sort\n end\n messages[message[:to]] = message[:time]\nend\n\nfriends.uniq!\n\np friends.size\nputs friends.map{|x| x.join(' ') }\n"}, {"source_code": "n,d = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmessages_raw = n.times.map{ from,to,time=STDIN.gets.chomp.split(/ /); {from: from.to_sym, to: to.to_sym, time: time.to_i } }.sort_by{|x| x[:time] }\nmessages = {}\ndone = {}\nfriends = []\n\nmessages_raw.each do |message|\n a = [message[:from],message[:to]].sort\n next if done[a]\n if messages[a] && 0 < (message[:time] - messages[a]) && (message[:time] - messages[a]) <= d\n messages.delete a\n friends << a\n end\n messages[a] = message[:time]\nend\nfriends.uniq!\n\np friends.size\nputs friends.map{|x| x.join(' ') }\n"}, {"source_code": "n,d = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmessages_raw = n.times.map{ from,to,time=STDIN.gets.chomp.split(/ /); {from: from.to_sym, to: to.to_sym, time: time.to_i } }.sort_by{|x| x[:time] }\nmessages = {}\nfriends = []\n\nmessages_raw.each do |message|\n if messages[message[:to]] && (message[:time] - messages[message[:to]]) <= d\n friends << [message[:from],message[:to]].sort\n end\n messages[message[:from]] = message[:time]\nend\n\nfriends.uniq!\n\np friends.size\nputs friends.map{|x| x.join(' ') }\n"}, {"source_code": "n,d = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmessages_raw = n.times.map{ from,to,time=STDIN.gets.chomp.split(/ /); {from: from.to_sym, to: to.to_sym, time: time.to_i } }\nmessages = {}\nfriends = []\n\nmessages_raw.each do |message|\n if messages[message[:to]] && (message[:time] - messages[message[:to]]) <= d\n friends << [message[:from],message[:to]].sort\n end\n messages[message[:from]] = message[:time]\nend\n\nfriends.uniq!\n\np friends.size\nputs friends.map{|x| x.join(' ') }\n"}, {"source_code": "n,d = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmessages_raw = n.times.map{ from,to,time=STDIN.gets.chomp.split(/ /); {from: from.to_sym, to: to.to_sym, time: time.to_i } }\nmessages = {}\ndone = {}\nfriends = []\n\nmessages_raw.each do |message|\n _ = [message[:from],message[:to]]\n a = _.sort\n next if done[a]\n if messages[_]\n t = message[:time] - messages[_]\n messages.delete a\n if 0 < t && t <= d\n friends << a\n end\n end\n messages[_.reverse] = message[:time]\nend\nfriends.uniq!\n\np friends.size\nputs friends.map{|x| x.join(' ') }\n"}, {"source_code": "n,d = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmessages_raw = n.times.map{ from,to,time=STDIN.gets.chomp.split(/ /); {from: from.to_sym, to: to.to_sym, time: time.to_i } }.sort_by{|x| x[:time] }\nmessages = {}\ndone = {}\nfriends = []\n\nmessages_raw.each do |message|\n a = [message[:from],message[:to]].sort\n next if done[a]\n if messages[a]\n t = message[:time] - messages[a]\n messages.delete a\n if 0 < t && t <= d\n friends << a\n end\n end\n messages[a] = message[:time]\nend\nfriends.uniq!\n\np friends.size\nputs friends.map{|x| x.join(' ') }\n"}, {"source_code": "n,d = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmessages_raw = n.times.map{ from,to,time=STDIN.gets.chomp.split(/ /); {from: from.to_sym, to: to.to_sym, time: time.to_i } }.sort_by{|x| x[:time] }\nmessages = {}\nfriends = []\n\nmessages_raw.each do |message|\n if messages[message[:from]] && 0 < (message[:time] - messages[message[:from]]) && (message[:time] - messages[message[:from]]) <= d\n friends << [message[:from],message[:to]].sort\n end\n messages[message[:to]] = message[:time]\nend\n\nfriends.uniq!\n\np friends.size\nputs friends.map{|x| x.join(' ') }\n"}, {"source_code": "n,m = gets.split.map &:to_i\n\nts = Hash.new{[]}\nans = {}\n\nn.times do\n a = gets.split\n c = a.pop.to_i\n ts[a] <<= c\n\n ans[a.sort] = 0 if ts[a.reverse].any?{ |it| c - it <= m }\n \n \nend\n\n puts ans.size\n puts ans.keys.map{|_| _ * ' '} * \"\\n\""}, {"source_code": "lines = STDIN.read.split(\"\\n\")\n\n(n, d) = lines[0].split(\" \").map(&:to_i)\n\nlog = lines[1..-1]\n\nmsg = {}\nlog.each{ |line|\n (user1, user2, t) = line.split(\" \")\n t = t.to_i\n \n h = [user1, user2].sort.join(' ')\n \n if msg.has_key?(h) then\n msg[h].push(t);\n else\n msg[h] = [t]\n end\n}\n\nfriends = 0\npairs = []\nmsg.each{ |k, v|\n if v.length >= 2 then\n sorted = v.sort\n \n for p in (0..(sorted.length - 2))\n if (sorted[p + 1] - sorted[p] <= d) then\n friends += 1\n pairs.push(k)\n break\n end\n end\n \n end\n}\n\nputs friends\nputs pairs"}, {"source_code": "lines = STDIN.read.split(\"\\n\")\n\n(n, d) = lines[0].split(\" \").map(&:to_i)\n\nlog = lines[1..-1]\n\nmsg = {}\nlog.each{ |line|\n (user1, user2, t) = line.split(\" \")\n t = t.to_i\n \n h = [user1, user2].sort.join(' ')\n \n if line.split(\" \")[0] == h.split(' ')[0] then\n who = 1\n else\n who = 2\n end\n \n if msg.has_key?(h) then\n msg[h][who].push(t);\n else\n msg[h] = {}\n msg[h][1] = []\n msg[h][2] = []\n msg[h][who].push(t)\n end\n}\n\nfriends = 0\npairs = []\n\nmsg.each { |key, value|\n if (value[1].length > 0 && value[2].length > 0) then\n \n found = false\n value[1].each {|v1|\n value[2].each {|v2|\n if (v2 - v1).abs <= d && (v2 - v1 != 0) then\n found = true\n end\n }\n }\n if (found) then\n friends += 1\n pairs.push(key)\n end\n end\n}\n\np msg\n\nputs friends\nputs pairs"}, {"source_code": "lines = STDIN.read.split(\"\\n\")\n\n(n, d) = lines[0].split(\" \").map(&:to_i)\n\nlog = lines[1..-1]\n\nmsg = {}\nlog.each{ |line|\n (user1, user2, t) = line.split(\" \")\n t = t.to_i\n \n h = [user1, user2].sort.join(' ')\n \n if msg.has_key?(h) then\n msg[h].push(t);\n else\n msg[h] = [t]\n end\n}\n\nfriends = 0\npairs = []\nmsg.each{ |k, v|\n if v.length >= 2 then\n sorted = v.sort\n \n if sorted[1] - sorted[0] <= d then\n friends += 1\n pairs.push(k)\n end\n \n end\n}\n\nputs friends\nputs pairs"}, {"source_code": "lines = STDIN.read.split(\"\\n\")\n\n(n, d) = lines[0].split(\" \").map(&:to_i)\n\nlog = lines[1..-1]\n\nmsg = {}\nlog.each{ |line|\n (user1, user2, t) = line.split(\" \")\n t = t.to_i\n \n h = [user1, user2].sort.join(' ')\n \n if line.split(\" \")[0] == h.split(' ')[0] then\n who = 1\n else\n who = 2\n end\n \n if msg.has_key?(h) then\n msg[h][who].push(t);\n else\n msg[h] = {}\n msg[h][1] = []\n msg[h][2] = []\n msg[h][who].push(t)\n end\n}\n\nfriends = 0\npairs = []\n\nmsg.each { |key, value|\n if (value[1].length > 0 && value[2].length > 0) then\n \n found = false\n value[1].each {|v1|\n value[2].each {|v2|\n if (v2 - v1).abs <= d then\n found = true\n end\n }\n }\n if (found) then\n friends += 1\n pairs.push(key)\n end\n end\n}\n\nputs friends\nputs pairs"}, {"source_code": "def main()\n\tnd=gets.chomp.split(\" \",2)\n\tnd=nd.map{|i| i.to_i}\n\tn=nd[0]\n\td=nd[1]\n\tp1=[]\n\tp2=[]\n\tt=[]\n\tfor i in 0...n\n\t\tinp=gets.chomp.to_s\n\t\tinpa=inp.split(\" \",3)\n\t\tp1 << inpa[0]\n\t\tp2<< inpa[1]\n\t\tt << inpa[2]\n\tend\n\tfriends=[]\n\tfor i in 0...n\n\t\tfp=p1[i]\n\t\tsp=p2[i]\n\t\ttime=t[i]\n\t\tfor j in (i+1)...n\n\t\t\tfps=p1[j]\n\t\t\tsps=p2[j]\n\t\t\ttimes=t[j]\n\t\t\tif fps==sp && sps==fp\n\t\t\t\ttd=times.to_i-time.to_i\n\t\t\t\tif td>0 && td<=d\n\t\t\t\t\tfriends << (fp+\" \"+sp)\n\t\t\t\t\tbreak;\n\t\t\t\tend\n\t\t\tend \n\t\tend\t\n\tend\n\tputs friends.length\n\tputs friends\nend\n\nmain()\n"}, {"source_code": "def main()\n\tnd=gets.chomp.split(\" \",2)\n\tnd=nd.map{|i| i.to_i}\n\tn=nd[0]\n\td=nd[1]\n\tp1=[]\n\tp2=[]\n\tt=[]\n\tfor i in 0...n\n\t\tinp=gets.chomp.to_s\n\t\tinpa=inp.split(\" \",3)\n\t\tp1 << inpa[0]\n\t\tp2<< inpa[1]\n\t\tt << inpa[2]\n\tend\n\tfriends=[]\n\tfor i in 0...n\n\t\tfp=p1[i]\n\t\tsp=p2[i]\n\t\ttime=t[i]\n\t\tfor j in (i+1)...n\n\t\t\tfps=p1[j]\n\t\t\tsps=p2[j]\n\t\t\ttimes=t[j]\n\t\t\tif fps==sp && sps==fp\n\t\t\t\ttd=times.to_i-time.to_i\n\t\t\t\tif td>0 && td<=d\n\t\t\t\t\tfriends << (fp+\" \"+sp)\n\t\t\t\t\tbreak;\n\t\t\t\telse\n\t\t\t\t\tif friends.include?(fp+\" \"+sp)\n\t\t\t\t\t\tfriends.delete(fp+\" \"+sp)\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend \n\t\tend\t\n\tend\n\tputs friends.length\n\tputs friends\nend\n\nmain()\n"}, {"source_code": "def main()\n\tnd=gets.chomp.split(\" \",2)\n\tnd=nd.map{|i| i.to_i}\n\tn=nd[0]\n\td=nd[1]\n\tp1=[]\n\tp2=[]\n\tt=[]\n\tfor i in 0...n\n\t\tinp=gets.chomp.to_s\n\t\tinpa=inp.split(\" \",3)\n\t\tp1 << inpa[0]\n\t\tp2<< inpa[1]\n\t\tt << inpa[2]\n\tend\n\tfriends=[]\n\tfor i in 0...n\n\t\tfp=p1[i]\n\t\tsp=p2[i]\n\t\ttime=t[i]\n\t\tfor j in (i+1)...n\n\t\t\tfps=p1[j]\n\t\t\tsps=p2[j]\n\t\t\ttimes=t[j]\n\t\t\tif fps==fp && sps==sp\n\t\t\t\tbreak;\n\t\t\tend\n\t\t\tif fps==sp && sps==fp\n\t\t\t\ttd=times.to_i-time.to_i\n\t\t\t\tif td>0 && td<=d\n\t\t\t\t\tfriends << (fp+\" \"+sp)\n\t\t\t\t\tbreak;\n\t\t\t\telse\n\t\t\t\t\tif friends.include?(fp+\" \"+sp)\n\t\t\t\t\t\tfriends.delete(fp+\" \"+sp)\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend \n\t\tend\t\n\tend\n\tputs friends.length\n\tputs friends\nend\n\nmain()\n"}, {"source_code": "def main()\n\tnd=gets.chomp.split(\" \",2)\n\tnd=nd.map{|i| i.to_i}\n\tn=nd[0]\n\td=nd[1]\n\tp1=[]\n\tp2=[]\n\tt=[]\n\tfor i in 0...n\n\t\tinp=gets.chomp.to_s\n\t\tinpa=inp.split(\" \",3)\n\t\tp1 << inpa[0]\n\t\tp2<< inpa[1]\n\t\tt << inpa[2]\n\tend\n\tfriends=[];\n\tnotfriends=[];\n\tfor i in 0...n\n\t\tfp=p1[i]\n\t\tsp=p2[i]\n\t\ttime=t[i]\n\t\tfor j in (i+1)...n\n\t\t\tfps=p1[j]\n\t\t\tsps=p2[j]\n\t\t\ttimes=t[j]\n\t\t\tif fps==fp && sps==sp\n\t\t\t\tnotfriends << (fp+\" \"+sp);\n\t\t\t\tbreak;\n\t\t\tend\n\t\t\tif fps==sp && sps==fp\n\t\t\t\ttd=times.to_i-time.to_i\n\t\t\t\tif td>0 && td<=d\n\t\t\t\t\tfriends << (fp+\" \"+sp)\n\t\t\t\t\tbreak;\n\t\t\t\telse\n\t\t\t\t\tif friends.include?(fp+\" \"+sp)\n\t\t\t\t\t\tfriends.delete(fp+\" \"+sp)\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend \n\t\tend\t\n\tend\n\tff=friends-notfriends\n\tputs ff.length\n\tputs ff\nend\n\nmain()\n"}, {"source_code": "def main()\n\tnd=gets.chomp.split(\" \",2)\n\tnd=nd.map{|i| i.to_i}\n\tn=nd[0]\n\td=nd[1]\n\tp1=[]\n\tp2=[]\n\tt=[]\n\tfor i in 0...n\n\t\tinp=gets.chomp.to_s\n\t\tinpa=inp.split(\" \",3)\n\t\tp1 << inpa[0]\n\t\tp2<< inpa[1]\n\t\tt << inpa[2]\n\tend\n\tfriends=[];\n\tfor i in 0...n\n\t\tfp=p1[i]\n\t\tsp=p2[i]\n\t\ttime=t[i]\n\t\tfor j in (i+1)...n\n\t\t\tfps=p1[j]\n\t\t\tsps=p2[j]\n\t\t\ttimes=t[j]\n\t\t\tif fps==fp && sps==sp\n\t\t\t\tbreak;\n\t\t\tend\n\t\t\tif fps==sp && sps==fp\n\t\t\t\ttd=times.to_i-time.to_i\n\t\t\t\tif td>0 && td<=d\n\t\t\t\t\tfriends << (fp+\" \"+sp)\n\t\t\t\t\tbreak;\n\t\t\t\tend\n\t\t\tend \n\t\tend\t\n\tend\n\tff=[]\n\tfor i in 0...(friends.length)\n\t\trel=friends[i]\n\t\tsr=rel.split(\" \",2);\n\t\trel2=sr[1]+\" \"+sr[0];\n\t\tif !(ff.include?(rel) || ff.include?(rel2))\n\t\t\tff<< rel\n\t\tend\t\n\tend\n\tputs ff.length\n\tputs ff\nend\n\nmain()\n"}, {"source_code": "require 'set'\n\nn, d = gets.split.collect{|i| i.to_i}\nmsg = Hash.new{|h,k| h.has_key?(k) ? h[k] : -(d+1)}\nfriends = Set.new\n\nn.times{\n f1, f2, t = gets.split\n t = t.to_i\n msg[[f1,f2]] = t\n if t - msg[[f2,f1]] <= d and t - msg[[f2,f1]] > 0\n friends.add(f1 < f2 ? [f1,f2] : [f2,f1])\n end\n}\n\nputs friends.size\nfriends.each{|f|\n puts f.join(\" \")\n}\n"}, {"source_code": "require 'set'\n\nn, d = gets.split.collect{|i| i.to_i}\nmsg = Hash.new{|h,k| h.has_key?(k) ? h[k] : -(d+1)}\nfriends = Set.new\n\nn.times{\n f1, f2, t = gets.split\n t = t.to_i\n msg[[f1,f2]] = t\n if t - msg[[f2,f1]] <= d\n friends.add(f1 < f2 ? [f1,f2] : [f2,f1])\n end\n}\n\nputs friends.size\nfriends.each{|f|\n puts f.join(\" \")\n}\n"}], "src_uid": "3cb4c89b174bf5ea51e797b78103e089"} {"source_code": "t = gets.to_i\n\n1.upto t do\n c = 0\n n = gets.to_i\n x = gets.split.map(&:to_i)\n x.sort!\n x.reverse!\n i = 0\n while x[i] > x.length-i do\n c += 1\n i += 1\n if i == x.length\n break\n end\n end\n puts (x.length + 1 - c)\nend", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split(' ').map(&:to_i).sort.reverse\n\n while a.first > a.size\n a.shift\n break if a.empty?\n end\n\n puts a.size + 1\nend\n"}], "negative_code": [], "src_uid": "718cea81f609055cece58cae5310f703"} {"source_code": "n = gets.to_i\nar = [0]\ngets.split(' ').map(&:to_i).map{|x| ar << x}\nar << 0\nm = gets.to_i\nm.times do\n x, y = gets.split(' ').map(&:to_i)\n ar[x-1] += y-1\n ar[x+1] += ar[x]-y\n ar[x] = 0\nend\n(1..n).each{|x| puts ar[x]}", "positive_code": [{"source_code": "at_exit do\n # my code\n n = get_numbers_from_line.first\n as = get_numbers_from_line\n m = get_numbers_from_line.first\n shoots = []\n m.times do\n shoots << get_numbers_from_line[0..1]\n end\n\n #trace as: as\n (0...m).each do |i|\n x,y = shoots[i]\n x -= 1\n #trace x: x, y:y\n as[x-1] += y-1 if x-1 >= 0\n as[x+1] += as[x] - y if x+1 < n\n as[x] = 0\n\n #trace as: as\n end\n\n as.each do |a|\n puts a\n end\n\nend\n\n# User helpers\n\n\n# Helpers\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend\n\ndef trace(vars={})\n puts vars.map{|key, value| \"#{key}: #{value}\"}.join('; ')\nend"}, {"source_code": "n = gets.to_i\n\na = gets.split.map { |x| x.to_i }\na = [0] + a + [0]\n\nm = gets.to_i\nm.times do\n\tx, y = gets.split.map { |x| x.to_i }\n\ta[x - 1] += y - 1\n\ta[x + 1] += a[x] - y\n\ta[x] = 0\nend\n\n1.upto(n) do |i|\n\tputs a[i]\nend"}, {"source_code": "sin = STDIN\nsout = STDOUT\n# sin = File.open(\"test.in\", \"r\")\n# sout = File.open(\"test.out\", \"w\")\n\nn = sin.readline.to_i\na = sin.readline.split.map{|e| e.to_i}\nm = sin.readline.to_i\n\nm.times {\n x, y = *sin.readline.split.map{|e| e.to_i}\n x -= 1\n if !x.zero?\n a[x - 1] += y - 1\n end\n if !(x == a.size - 1)\n a[x + 1] += a[x] - y\n end\n a[x] = 0\n}\n\nsout.puts a"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\ntemp = gets.split(' ').map {|i| i.to_i}\nm = gets.to_i\nm.times do\n x, y = gets.split(' ').map {|i| i.to_i}\n x -= 1;\n temp[x-1] += y - 1 if x > 0\n temp[x+1] += temp[x] - y if x < n - 1\n temp[x] = 0\nend\ntemp.each do |i|\n puts i\nend\n"}, {"source_code": "def run\n n = $stdin.gets.to_i\n a = $stdin.gets.split.map(&:to_i)\n m = $stdin.gets.to_i\n $stdin.readlines.each do |line|\n x, y = line.split.map(&:to_i)\n\n a[x - 2] += y - 1 if x > 1\n a[x] += (a[x - 1] - y) if x < n\n a[x - 1] = 0\n end\n\n puts a.join(\"\\n\")\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.to_i\na = gets.split.map{|_|_.to_i}\nm = gets.to_i\n\n\nm.times{|i|\n x,y=gets.split.map{|_|_.to_i}\n r = a[x-1] - y\n l = y - 1\n a[x-1] = 0\n if n!=1 then\n if x-1 == 0 then\n a[x-1+1] += r\n elsif x-1 == n-1 then\n a[x-1-1] += l\n else\n a[x-1+1] += r\n a[x-1-1] += l\n end\n end\n}\na.each{|i|\n puts i\n}\n\n\n\n"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\na = [0] + gets.split.map(&:to_i) + [0]\nm = gets.to_i\ncoords = []\n\nm.times do\n x, y = gets.split.map(&:to_i)\n \n left = y - 1\n right = a[x] - left - 1\n \n a[x-1]+=left if x-1>=0\n a[x+1]+=right if x+1=0\n a[x+1]+=right if x+1 0 then a[x-1] += y-1 end\n if x < n-1 then a[x+1] += a[x]-y end \n a[x] = 0\n}\nputs a"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").collect! {|x| x.to_i}\nm = gets.to_i\n\n\n(0...m).each { |k|\n\tsy,sx = gets.split(\" \").collect! {|x| x.to_i}\n\tleft = sx - 1\n\tright = arr[sy-1] - sx\n\tif sy>1\n\t\tarr[sy-2] += left\n\tend\n\tif sy 0\n a[x-1] += y-1\n end\n if x < n-1\n a[x+1] += a[x] - y\n end\n a[x] = 0\n}\na.each { |x| puts x }\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\ngets.to_i.times {\n x,y=gets.split.map(&:to_i)\n a[x-2]+=y-1 if x>1\n a[x]+=a[x-1]-y if x 1\n a[x] += a[x-1] - y if x < n\n a[x-1] = 0\n}\nputs a\n"}, {"source_code": "wires_count = Integer(gets.chomp)\nbirds_on_wires = gets.chomp.split.map { |x| x.to_i }\nfor _ in 1..Integer(gets.chomp)\n wire, bird = gets.chomp.split.map { |x| x.to_i }\n birds_on_wires[wire - 2] += bird - 1 if wire > 1\n birds_on_wires[wire] += birds_on_wires[wire - 1] - bird if wire < wires_count\n birds_on_wires[wire - 1] = 0\nend\nputs birds_on_wires"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ngets.to_i.times do\n x, y = gets.split.map(&:to_i)\n x -= 1\n a[x - 1] += y - 1 if x - 1 >= 0\n a[x + 1] += a[x] - y if x + 1 < n\n a[x] = 0\nend\nputs a\n"}], "negative_code": [{"source_code": "sin = STDIN\nsout = STDOUT\n# sin = File.open(\"test.in\", \"r\")\n# sout = File.open(\"test.out\", \"w\")\n\nn = sin.readline.to_i\na = sin.readline.split.map{|e| e.to_i}\nm = sin.readline.to_i\n\nm.times {\n x, y = *sin.readline.split.map{|e| e.to_i}\n x -= 1\n a[x - 1] += y - 1\n a[x + 1] += a[x] - y\n a[x] = 0\n}\n\nsout.puts a"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\ntemp = gets.split(' ').map {|i| i.to_i}\nm = gets.to_i\nm.times do\n x, y = gets.split(' ').map {|i| i.to_i}\n x -= 1;\n temp[x-1] += y - 1 if x > 0\n temp[x+1] += temp[x] - y if x < m - 1\n temp[x] = 0\nend\ntemp.each do |i|\n puts i\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map{|_|_.to_i}\nm = gets.to_i\n\nif n == 1 then\n puts 0\nelse\n m.times{|i|\n x,y=gets.split.map{|_|_.to_i}\n r = a[x-1] - y\n l = y - 1\n a[x-1] = 0\n if x-1 == 0 then\n a[x-1+1] += r\n elsif x-1 == n-1 then\n a[x-1-1] += l\n else\n a[x-1+1] += r\n a[x-1-1] += l\n end\n }\n a.each{|i|\n puts i\n }\nend\n\n\n"}, {"source_code": "at_exit do\n # my code\n n = get_numbers_from_line.first\n as = get_numbers_from_line\n m = get_numbers_from_line.first\n shoots = []\n m.times do\n shoots << get_numbers_from_line[0..1]\n end\n\n (0...m).each do |i|\n x,y = shoots[i]\n x -= 1\n as[x-1] += y-1 if x-1 >= 0\n as[x+1] += as[x] - y if x+1 < m\n as[x] = 0\n end\n\n as.each do |a|\n puts a\n end\n\nend\n\n# User helpers\n\n\n# Helpers\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend\n\ndef trace(vars={})\n puts vars.map{|key, value| \"#{key}: #{value}\"}.join('; ')\nend"}], "src_uid": "859d66fc2c204a8c002012b1fb206645"} {"source_code": "numbers = gets\n\nres = numbers.split(' ')\n\nn = res[0].to_i\nm = res[1].to_i\n\nwallsx = []\nwallsy = []\ni = 0\nwalls = 0\n\nwhile (i < n) do\n chars = gets\n chars.each_char.with_index do |r,j|\n if (r == '*')\n wallsx.push(i);\n wallsy.push(j);\n walls += 1\n end\n end\n i = i + 1\n if (walls >= n+m+3)\n i = n\n end\nend\n\ni = 0\nxm = -1\nym = -1\nj = 0\nwhile (j < walls)\n i = j + 1\n while (i < walls) do\n if (i != 0)\n if (wallsx[i] == wallsx[j])\n xm = wallsx[i]\n end\n if (wallsy[i] == wallsy[j])\n ym = wallsy[i]\n end\n \n if (xm != -1 && ym != -1)\n i = walls;\n j = walls;\n end\n end\n i = i + 1\n end\n j = j+1\nend\nif (walls == 0)\n xm = 0\n ym = 0\nelsif (walls == 1)\n xm = wallsx[0]\n ym = wallsy[0]\nelse\n if (xm == -1 && ym == -1) \n xm = wallsx[0]\n ym = wallsy[1]\n end\nend\ni = 0\nflag = 0\n#puts 'unclear' + xm.to_s + ' : ' + ym.to_s\nwhile (i < walls) do\n if (wallsx[i] == xm || wallsy[i] == ym)\n #good, wall destroyed\n else\n flag = 1\n end\n i = i + 1\nend\nif (flag == 1 && (xm == -1 || ym == -1)) \n i = 0\n flag = 0\n #puts 'unclear' + xm.to_s + ' : ' + ym.to_s\n coords_unclear = 0\n while(i < walls)\n if (xm != -1 && wallsx[i] == xm || wallsy[i] == ym && ym != -1)\n #good, wall destroyed\n else\n if (coords_unclear == 0)\n if (xm == -1)\n xm = wallsx[i]\n else\n ym = wallsy[i]\n end\n coords_unclear = 1\n else\n flag = 1\n end\n end\n i = i + 1\n end\nend\nif flag == 1\n puts 'NO'\nelse\n puts 'YES'\n xm = 0 if xm == -1\n ym = 0 if ym == -1\n xm +=1\n ym +=1\n puts (xm).to_s + ' ' + (ym).to_s\nend", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\n\nrd = Array.new(n+1, 0)\nst = Array.new(m+1, 0)\ns = Array.new(n+1)\nall = 0\n(n).times do |i|\n s[i] = gets.chomp.to_s\n (m).times do |j|\n if s[i][j]=='*'\n rd[i]+=1\n st[j]+=1\n all+=1\n end\n end\nend\n\n(n).times do |i|\n (m).times do |j|\n if s[i][j]=='*'\n if rd[i] + st[j]-1==all\n print(\"YES\\n#{i+1} #{j+1}\")\n exit(0)\n end\n else\n if rd[i]+st[j]==all\n print(\"YES\\n#{i+1} #{j+1}\")\n exit(0)\n end\n end\n end\nend\n\nprint(\"NO\")"}, {"source_code": "n,m = gets.split.map(&:to_i)\n\nmas = Array.new\nstl = Array.new(m,0)\nstr = Array.new(n,0)\ncnt = 0\ni = 0\nn.times do\n mas << gets.chomp\n mas[i].each_char.with_index do |px, ind|\n if px=='*'\n str[i] += 1\n stl[ind] += 1\n cnt += 1\n end\n end\n i+=1\nend\n\nfor i in 0...n do\n for j in 0...m do\n c = str[i]+stl[j]\n c-=1 if mas[i][j]=='*'\n if c == cnt then\n puts \"YES\\n#{i+1} #{j+1}\"\n exit\n end\n end\nend\n\nputs \"NO\"\n"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\nfields = []\nrows = Array.new(n) { 0 }\ncols = Array.new(m) { 0 }\ncount = 0\nn.times do |i|\n fields << gets.chomp.chars\n fields[i].each.with_index do |point, idx|\n if point == '*'\n rows[i] += 1\n cols[idx] += 1\n count += 1\n end\n end\nend\n\nans = (0...n).to_a.product((0...m).to_a).find do |i, j|\n count == rows[i] + cols[j] - (fields[i][j] == '*' ? 1 : 0)\nend\n\nif ans.nil?\n puts \"NO\"\nelse\n puts \"YES\"\n puts ans.flatten.map { |d| d + 1 }.join(' ')\nend\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nN, M = gis\nW = ngs N\n\nrows = [0] * N\ncols = [0] * M\n\ncnt = 0\n\nW.each_with_index do |s, y|\n M.times do |x|\n next if s[x] != '*'\n cnt += 1\n rows[y] += 1\n cols[x] += 1\n end\nend\n\nmax_c, max_x = cols.each_with_index.max_by{|v, _| v }\nmax_r, max_y = rows.each_with_index.max_by{|v, _| v }\n\nif max_c == 1 && max_r == 1 && cnt == 2\n c = cols.each_with_index.select{|v,_| v == max_c}.map{|_,i| i}\n r = rows.each_with_index.select{|v,_| v == max_c}.map{|_,i| i}\n r.each do |y|\n c.each do |x|\n if W[y][x] == '.'\n max_x = x\n max_y = y\n end\n end\n end\nend\nif max_c == 1 && max_r > 1\n yy = rows.find_index 1\n max_x = W[yy].index '*' if !yy.nil?\nend\nif max_c > 1 && max_r == 1\n xx = cols.find_index 1\n max_y = W.find_index{|s| s[xx] == '*'} if !xx.nil?\nend\n\ncrs = max_c + max_r - (W[max_y][max_x] == '*' ? 1 : 0)\n\nif crs == cnt\n puts :YES\n puts \"%d %d\" % [max_y + 1, max_x + 1]\nelse\n puts :NO\nend\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nmap = []\ncx = Array.new(n, 0)\ncy = Array.new(m, 0)\nn.times do |i|\n map[i] = gets\n map[i].each_char.with_index do |c, j|\n next unless c == '*'\n cx[i] += 1\n cy[j] += 1\n end\nend\ntot = cx.inject(:+)\nn.times do |i|\n m.times do |j|\n cnt = cx[i] + cy[j]\n cnt -= 1 if map[i][j] == '*'\n if cnt == tot\n puts 'YES'\n puts [i + 1, j + 1] * ' '\n exit\n end\n end\nend\n\nputs 'NO'\n"}], "negative_code": [{"source_code": "n,m = gets.split.map(&:to_i)\n\nmas = Array.new\n\nn.times do\n mas << gets.chomp\nend\n\nstl = Array.new\nstr = Array.new\n\nfor i in 0...n do\n c = 0\n for j in 0...m do\n c+=1 if mas[i][j]=='*'\n end\n str[i] = c\nend\n\nfor j in 0...m do\n c = 0\n for i in 0...n do\n c+=1 if mas[i][j]=='*'\n end\n stl[j] = c\nend\n\ncnt = 0\n\nfor i in 0...n do\n for j in 0...m do\n cnt+=1 if mas[i][j]=='*'\n end\nend\n\nfor i in 0...n do\n for j in 0...m do\n if str[i]+stl[j] >= cnt then\n puts \"YES\\n#{i+1} #{j+1}\"\n exit\n end\n end\nend\n\nputs \"NO\"\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nN, M = gis\nW = ngs N\n\nrows = [0] * N\ncols = [0] * M\n\ncnt = 0\n\nW.each_with_index do |s, y|\n M.times do |x|\n next if s[x] != '*'\n cnt += 1\n rows[y] += 1\n cols[x] += 1\n end\nend\n\nif cnt == 2\n puts :YES\n c = cols.each_with_index.select{|v, _| v > 0}.map{|_, i| i}\n r = rows.each_with_index.select{|v, _| v > 0}.map{|_, i| i}\n if c.size == 2 && r.size == 2\n if W[r[0]][c[0]] == '*'\n puts \"%d %d\" % [r[0] + 1, c[1] + 1]\n else\n puts \"%d %d\" % [r[0] + 1, c[0] + 1]\n end\n else\n puts \"%d %d\" % [r[0] + 1, r[1] + 1]\n end\n exit\nend\n\nmax_c, max_x = cols.each_with_index.max_by{|v, _| v }\nmax_r, max_y = rows.each_with_index.max_by{|v, _| v }\n\ncrs = max_c + max_r - (W[max_y][max_x] == '*' ? 1 : 0)\n\nif crs == cnt\n puts :YES\n puts \"%d %d\" % [max_y + 1, max_x + 1]\nelse\n puts :NO\nend\n\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nN, M = gis\nW = ngs N\n\nrows = [0] * N\ncols = [0] * M\n\ncnt = 0\n\nW.each_with_index do |s, y|\n M.times do |x|\n next if s[x] != '*'\n cnt += 1\n rows[y] += 1\n cols[x] += 1\n end\nend\n\nif cnt == 2\n puts :YES\n c = cols.each_with_index.select{|v, _| v > 0}.map{|_, i| i}\n r = rows.each_with_index.select{|v, _| v > 0}.map{|_, i| i}\n if c.size == 2 && r.size == 2\n if W[r[0]][c[0]] == '*'\n puts \"%d %d\" % [r[0] + 1, c[1] + 1]\n else\n puts \"%d %d\" % [r[0] + 1, c[0] + 1]\n end\n else\n puts \"%d %d\" % [r[0] + 1, c[0] + 1]\n end\n exit\nend\n\nmax_c, max_x = cols.each_with_index.max_by{|v, _| v }\nmax_r, max_y = rows.each_with_index.max_by{|v, _| v }\n\ncrs = max_c + max_r - (W[max_y][max_x] == '*' ? 1 : 0)\n\nif crs == cnt\n puts :YES\n puts \"%d %d\" % [max_y + 1, max_x + 1]\nelse\n puts :NO\nend\n\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nN, M = gis\nW = ngs N\n\nrows = [0] * N\ncols = [0] * M\n\ncnt = 0\n\nW.each_with_index do |s, y|\n M.times do |x|\n next if s[x] != '*'\n cnt += 1\n rows[y] += 1\n cols[x] += 1\n end\nend\n\nmax_c, max_x = cols.each_with_index.max_by{|v, _| v }\nmax_r, max_y = rows.each_with_index.max_by{|v, _| v }\n\nif max_c == 1 && max_r > 1\n yy = rows.find_index 1\n max_x = W[yy].index '*' if !yy.nil?\nend\nif max_c > 1 && max_r == 1\n xx = cols.find_index 1\n max_y = W.find_index{|s| s[xx] == '*'} if !xx.nil?\nend\n\ncrs = max_c + max_r - (W[max_y][max_x] == '*' ? 1 : 0)\n\nif crs == cnt\n puts :YES\n puts \"%d %d\" % [max_y + 1, max_x + 1]\nelse\n puts :NO\nend\n\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nN, M = gis\nW = ngs N\n\nrows = [0] * N\ncols = [0] * M\n\ncnt = 0\n\nW.each_with_index do |s, y|\n M.times do |x|\n next if s[x] != '*'\n cnt += 1\n rows[y] += 1\n cols[x] += 1\n end\nend\n\nmax_c, max_x = cols.each_with_index.max_by{|v,_| v }\nmax_r, max_y = rows.each_with_index.max_by{|v,_| v }\n\ncrs = max_c + max_r - (W[max_y][max_x] == '*' ? 1 : 0)\n\nif crs == cnt\n puts :YES\n puts \"%d %d\" % [max_y + 1, max_x + 1]\nelse\n puts :NO\nend\n\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nN, M = gis\nW = ngs N\n\nrows = [0] * N\ncols = [0] * M\n\ncnt = 0\n\nW.each_with_index do |s, y|\n M.times do |x|\n next if s[x] != '*'\n cnt += 1\n rows[y] += 1\n cols[x] += 1\n end\nend\n\nif cnt == 2\n puts :YES\n c = cols.each_with_index.select{|v, _| v > 0}.map{|_, i| i}\n r = rows.each_with_index.select{|v, _| v > 0}.map{|_, i| i}\n if c.size == 2 && r.size == 2\n if W[r[0]][c[0]] == '*'\n puts \"%d %d\" % [r[0] + 1, c[1] + 1]\n else\n puts \"%d %d\" % [r[0] + 1, c[0] + 1]\n end\n else\n puts \"%d %d\" % [r[0] + 1, r[0] + 1]\n end\n exit\nend\n\nmax_c, max_x = cols.each_with_index.max_by{|v, _| v }\nmax_r, max_y = rows.each_with_index.max_by{|v, _| v }\n\ncrs = max_c + max_r - (W[max_y][max_x] == '*' ? 1 : 0)\n\nif crs == cnt\n puts :YES\n puts \"%d %d\" % [max_y + 1, max_x + 1]\nelse\n puts :NO\nend\n\n"}, {"source_code": "numbers = gets\n\nres = numbers.split(' ')\n\nn = res[0].to_i\nm = res[1].to_i\n\nwallsx = []\nwallsy = []\ni = 0\nwalls = 0\n\nwhile (i < n) do\n chars = gets\n chars.each_char.with_index do |r,j|\n if (r == '*')\n wallsx.push(i);\n wallsy.push(j);\n walls += 1\n end\n end\n i = i + 1\n if (walls >= n+m+3)\n i = n\n end\nend\n\ni = 0\nxm = -1\nym = -1\n\nwhile (i < walls) do\n if (i != 0)\n if (wallsx[i] == wallsx[i-1])\n xm = wallsx[i]\n end\n if (wallsy[i] == wallsy[i-1])\n ym = wallsy[i]\n end\n end\n i = i + 1\nend\nif (walls == 0)\n xm = 0\n ym = 0\nelsif (walls == 1)\n xm = wallsx[0]\n ym = wallsy[0]\nelse\n if (xm == -1 && ym == -1) \n xm = wallsx[0]\n ym = wallsy[1]\n end\nend\ni = 0\nflag = 0\nwhile (i < walls) do\n if (wallsx[i] == xm || wallsy[i] == ym)\n #good, wall destroyed\n else\n flag = 1\n end\n i = i + 1\nend\nif (flag == 1 && (xm == -1 || ym == -1)) \n i = 0\n flag = 0\n #puts 'unclear'\n coords_unclear = 0\n while(i < walls)\n if (xm != -1 && wallsx[i] == xm || wallsy[i] == ym && ym != -1)\n #good, wall destroyed\n else\n if (coords_unclear == 0)\n if (xm == -1)\n xm = wallsx[i]\n else\n ym = wallsy[i]\n end\n coords_unclear = 1\n else\n flag = 1\n end\n end\n i = i + 1\n end\nend\nif flag == 1\n puts 'NO'\nelse\n puts 'YES'\n xm = 0 if xm == -1\n ym = 0 if ym == -1\n xm +=1\n ym +=1\n puts (xm).to_s + ' ' + (ym).to_s\nend"}], "src_uid": "12a768b502ddb07798830c9728fba5c4"} {"source_code": "n, d = gets.split.map { |s| s.to_i }\n\nf = [[0, 0]]\nn.times do\n\tt = gets.split.map { |s| s.to_i }\n\tf << t\nend\nf.sort!\n\nsum = f.map { |item| item[1] }\n1.upto(n) do |i|\n\tsum[i] += sum[i - 1]\nend\n\nans = 0\nrp = 1\n1.upto(n) do |i|\n\trp += 1 while rp < n && f[i][0] + d > f[rp + 1][0]\n\tans = [ans, sum[rp] - sum[i - 1]].max\nend\nputs ans\n", "positive_code": [{"source_code": "prr = []\nn,d = gets.split().map(&:to_i)\nfor i in 0...n\n x,y = gets.split().map(&:to_i)\n prr[i] = [x,y]\nend\nprr.sort!{|x,y| x <=> y}\nj = ans = mx = i = 0\nwhile i=d\n mx = [mx,ans].max\n ans-=prr[j][1]\n j+=1\n i-=1\n else\n ans+=prr[i][1]\n end\n i+=1\nend\np [mx,ans].max"}, {"source_code": "n, d = gets.strip.split(\" \").map(&:to_i)\na = Array.new(n)\nn.times{|i| a[i] = gets.strip.split(\" \").map(&:to_i) }\na.sort!{|a1, a2| a1[0] <=> a2[0]}\ni = 0\ni0 = 0\nmax_sum = 0\ncurrent_sum = 0\nwhile (i < n) do \n if current_sum == 0 then \n i0 = i \n elsif a[i][0] - a[i0][0] >= d then\n j = i0\n while j < i && a[i][0] - a[j][0] >= d do \n current_sum -= a[j][1]\n j += 1\n end\n i0 = j\n end\n current_sum += a[i][1]\n max_sum = [max_sum, current_sum].max\n i += 1\nend\nputs max_sum\n"}, {"source_code": "n, d = gets.strip.split(\" \").map(&:to_i)\na = Array.new(n)\nn.times{|i| a[i] = gets.strip.split(\" \").map(&:to_i) }\na.sort!{|a1, a2| a1[0] <=> a2[0]}\ni = 0\ni0 = 0\nmax_sum = 0\ncurrent_sum = 0\nwhile (i < n) do \n if current_sum == 0 then \n i0 = i \n # current_sum += a[i][1]\n # puts \"here current_sum=#{current_sum}\"\n elsif a[i][0] - a[i0][0] >= d then\n # current_sum += a[i][1]\n j = i0\n while j < i do \n if a[i][0] - a[j][0] >= d then\n current_sum -= a[j][1]\n else\n break\n end\n j += 1\n end\n i0 = j\n end\n current_sum += a[i][1]\n # puts current_sum\n max_sum = [max_sum, current_sum].max\n i += 1\nend\nputs max_sum\n"}, {"source_code": "n,k=gets.split.map{|e| e.to_i}\narr=[]\nn.times{\n\ta=gets.split.map{|e| e.to_i}\n\tarr<=k\n\t\tsum-=arr[l][1]\n\t\tl+=1\n\tend\n\twhile r=k\n\t\tr+=1\n\t\tsum+=arr[r][1]\n\tend\n\tans=[ans,sum].max\n\tr+=1\n\tbreak if r>=n\n\tsum+=arr[r][1]\nend\nputs ans\n\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nf = n.times.map{gets.split.map(&:to_i)}.sort_by{|x| x[0]}\ncumulative = []\n(0..n).each{|i| cumulative[i] = (i == 0 ? 0 : f[i - 1][1] + cumulative[i - 1])}\ni, j, mx = 0, 0, 0\nwhile true\n if j == n\n mx = [mx, cumulative[j] - cumulative[i]].max\n break\n elsif f[j][0] - f[i][0] >= d\n mx = [mx, cumulative[j] - cumulative[i]].max\n i += 1\n else\n j += 1\n end\nend\nputs mx\n"}], "negative_code": [{"source_code": "n, d = gets.strip.split(\" \").map(&:to_i)\na = Array.new(n)\nn.times{|i| a[i] = gets.strip.split(\" \").map(&:to_i) }\na.sort!{|a1, a2| a1[0] <=> a2[0]}\ni = 0\ni0 = 0\nmax_sum = 0\ncurrent_sum = 0\nwhile (i < n) do \n if current_sum == 0 then \n i0 = i \n # current_sum += a[i][1]\n # puts \"here current_sum=#{current_sum}\"\n elsif a[i][0] - a[i0][0] > d then\n # current_sum += a[i][1]\n j = i0\n while j < i do \n if a[i][0] - a[j][0] > d then\n current_sum -= a[j][1]\n else\n break\n end\n j += 1\n end\n i0 = j\n end\n current_sum += a[i][1]\n # puts current_sum\n max_sum = [max_sum, current_sum].max\n i += 1\nend\nputs max_sum\n"}, {"source_code": "n,k=gets.split.map{|e| e.to_i}\narr=[]\nn.times{\n\ta=gets.split.map{|e| e.to_i}\n\tarr<k\n\t\tsum-=arr[l][1]\n\t\tl+=1\n\tend\n\twhile rk\n\t\tr+=1\n\t\tsum+=arr[r][1]\n\tend\n\tans=[ans,sum].max\n\tr+=1\n\tbreak if r>=n\n\tsum+=arr[r][1]\nend\nputs ans\n\n"}, {"source_code": "n,k=gets.split.map{|e| e.to_i}\nans=0\nn.times{\n\ta,b=gets.split.map{|e| e.to_i}\n\tif a<=k then\n\t\tans+=b\n\tend\n}\nputs ans\n\n"}, {"source_code": "n,k=gets.split.map{|e| e.to_i}\narr=[]\nn.times{\n\ta=gets.split.map{|e| e.to_i}\n\tarr<k\n\t\tsum-=arr[l][1]\n\t\tl+=1\n\tend\n\twhile rk\n\t\tr+=1\n\t\tsum+=arr[r][1]\n\tend\n\tans=[ans,sum].max\n\tr+=1\nend\nputs ans\n\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nf = n.times.map{gets.split.map(&:to_i)}.sort_by{|x| x[0]}\ncumulative = []\n(0..n).each{|i| cumulative[i] = (i == 0 ? 0 : f[i - 1][1] + cumulative[i - 1])}\nmx, status = 0, ''\ni, j = 0, 0\nif f[n - 1][0] - f[0][0] < d\n p cumulative[n]\nelse\n while true\n if f[j][0] - f[i][0] > d\n mx = [mx, cumulative[j] - cumulative[i]].max\n i += 1\n j = [i, j].max\n elsif j == n - 1\n break\n else\n j += 1\n end\n end\n p mx\nend\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nf = n.times.map{gets.split.map(&:to_i)}.sort_by{|x| x[0]}\ncumulative = []\n(0..n).each{|i| cumulative[i] = (i == 0 ? 0 : f[i - 1][1] + cumulative[i - 1])}\ni, j, mx = 0, 0, 0\nwhile true\n if j == n\n mx = [mx, cumulative[j] - cumulative[i]].max\n break\n elsif f[j][0] - f[i][0] > d\n mx = [mx, cumulative[j] - cumulative[i]].max\n i += 1\n else\n j += 1\n end\nend\nputs mx\n"}], "src_uid": "38fe0e19974a7bc60153793b9060369a"} {"source_code": "#!/usr/bin/ruby\nn,k=gets.split.map &:to_i\na=$<.map{|e|e.chomp.size}\nx=a.pop\na.sort!\nl,r=[:>=,:>].map{|o|\n\t(0...n).bsearch{|i|a[i].send(o,x)}||n\n}\nr-=1\nputs [l+l/k*5+1,r+r/k*5+1]*' '", "positive_code": [{"source_code": "n,k = gets.split.map(&:to_i)\n\npass = []\n\nn.times do\n pass << gets.chomp\nend\n\npass = pass.uniq.sort_by{|x| x.length}\npasW = gets.chomp\npasN = pasW.length\n\npass << \"\"\nans1, ans2 = 0,0\ntime = 0\n\nfor i in 0...n do\n time += 1\n ans1 = time if pass[i].length == pasN and ans1 == 0\n ans2 = time if pass[i+1].length > pasN and ans2 == 0\n time += 5 if (i+1) % k == 0 and i!=n-1\nend\n\nans2 = time if ans2 == 0\nans2 = ans1 if pasW == pass[0] and pass.size == 1\n\nputs \"#{ans1} #{ans2}\""}, {"source_code": "e = gets.chop.split(' ')\nn, k = e[0].to_i, e[1].to_i\n\n\n\n\n\nps = []\n\ni = 0\nwhile i < n\n tmp = gets.chop\n ps << tmp\n i += 1\nend \n\nt_ps = gets.chop\n\nbiger = 0\nsmaller = 1 \n\nps = ps.uniq.sort{|x| x.size }.each do |x|\n biger += 1 if x.size == t_ps.size && x != t_ps\n smaller +=1 if x.size < t_ps.size \nend\n\n\nbest = smaller + (((smaller-1) / k) * 5);\nworst = biger + smaller + (((biger + smaller - 1) / k) * 5)\n\nputs \"#{best} #{worst}\""}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=STDIN.read.split\ny=x.last\nx.pop\nz=x.select{|e|\n\ty.size>e.size\n}\nx=x.select{|e|\n\ty.size>=e.size\n}\n\nans1=z.size+1+(z.size/m)*5\nans2=x.size+((x.size-1)/m)*5\n\nputs [ans1,ans2]*\" \"\n\n"}, {"source_code": "n, k =gets.chomp.split(\" \").map(&:to_i)\nstring=Array.new\nfor i in 0..n-1\n string[i]=gets.chomp\nend\nn = gets.chomp\nstring = string.sort_by(&:size).select{ |x| x.size <= n.size }\nif string[0].size == n.size\n print 1\nelse\n ctr = string.select{|x| x.size correctlen))\n\t\tmaxians=ans\n\tend\n\n\tans+=5 if(count%k==0)\nend\n\nprint \"#{minians} #{maxians}\"\nputs\n"}, {"source_code": "n, k = gets.chomp.split(' ').map(&:to_i)\ncandidates = []\npassword = nil\n\nn.times do\n\tcandidates << gets.chomp\nend\n\npassword = gets.chomp\n\ncandidates.sort! { |a, b|\n\tif a.length > b.length\n\t\t1\n\telsif a.length == b.length\n\t\t0\n\telse\n\t\t-1\n\tend\n}\n\nlengthHash = {}\ncandidates.each do |c|\n\tif lengthHash.has_key? c.length\n\t\tlengthHash[c.length] += 1\n\telse\n\t\tlengthHash[c.length] = 1\n\tend\nend\n\nwrong = 0\n\n(1...password.length).each do |len|\n\tif lengthHash.has_key? len\n\t\twrong += lengthHash[len]\n\tend\nend\n\n# t p\nbest = 1 + wrong + (wrong / k) * 5\nworst = wrong + lengthHash[password.length] + ((wrong + (lengthHash[password.length] - 1)) / k) * 5\n\nputs \"#{best} #{worst}\""}, {"source_code": "a,b=gets.split.map &:to_i\narr=[]\na.times{arr< pasN\n time += 1\n ans1 = time if pass[i].length == pasN and ans1 == 0\n time += 5 if (i+1) % k == 0 and i!=n-1\nend\n\nans2 = time if ans2 == 0\nans2 = ans1 if pasW == pass[0] and pass.size == 1\n\nputs \"#{ans1} #{ans2}\""}, {"source_code": "n,k = gets.split.map(&:to_i)\n\npass = []\n\nn.times do\n pass << gets.chomp\nend\n\npass = pass.uniq.sort_by{|x| x.length}\npasW = gets.chomp\npasN = pasW.length\n\nans1, ans2 = 0,0\ntime = 0\n\nfor i in 0...n do\n ans2 = time if pass[i].length > pasN\n time += 1\n ans1 = time if pass[i].length == pasN and ans1 == 0\n time += 5 if (i+1) % k == 0\nend\nans2 = time if ans2 == 0\nans2 = ans1 if pasW == pass[0]\n\nprint ans1,\" \",ans2"}, {"source_code": "n,k = gets.split.map(&:to_i)\n\npass = []\n\nn.times do\n pass << gets.chomp\nend\n\npass = pass.uniq.sort_by{|x| x.length}\npasW = gets.chomp\npasN = pasW.length\n\nans1, ans2 = 0,0\ntime = 0\n\nfor i in 0...n do\n ans2 = time if pass[i].length > pasN\n time += 1\n ans1 = time if pass[i].length == pasN and ans1 == 0\n time += 5 if (i+1) % k == 0 and i!=n-1\nend\n\nans2 = time if ans2 == 0\nans2 = ans1 if pasW == pass[0]\n\nputs \"#{ans1} #{ans2}\""}, {"source_code": "n,k = gets.split.map(&:to_i)\n\npass = []\n\nn.times do\n pass << gets.chomp\nend\n\npass = pass.sort_by{|x| x.length}\npasN = gets.chomp.length\n\nans1, ans2 = 0,0\ntime = 0\n\nfor i in 0...n do\n ans2 = time if pass[i].length > pasN\n time += 1\n time += 5 if (i+1) % k == 0\n ans1 = time if pass[i].length == pasN and ans1 == 0\nend\nans2 = time if ans2 == 0\n\nprint ans1,\" \",ans2"}, {"source_code": "n,k = gets.split.map(&:to_i)\n\npass = []\n\nn.times do\n pass << gets.chomp\nend\n\npass = pass.uniq.sort_by{|x| x.length}\npasW = gets.chomp\npasN = pasW.length\n\nans1, ans2 = 0,0\ntime = 0\n\nfor i in 0...n do\n ans2 = time if pass[i].length > pasN\n time += 1\n ans1 = time if pass[i].length == pasN and ans1 == 0\n time += 5 if (i+1) % k == 0 and i!=n-1\nend\nans2 = time if ans2 == 0\nans2 = ans1 if pasW == pass[0]\n\nprint ans1,\" \",ans2"}, {"source_code": "n,k = gets.split.map(&:to_i)\n\npass = []\n\nn.times do\n pass << gets.chomp\nend\n\npass = pass.uniq.sort_by{|x| x.length}\npasW = gets.chomp\npasN = pasW.length\n\nans1, ans2 = 0,0\ntime = 0\n\nfor i in 0...n do\n ans2 = time if pass[i].length > pasN\n time += 1\n ans1 = time if pass[i].length == pasN and ans1 == 0\n time += 5 if (i+1) % k == 0 and i!=n-1\nend\n\nans2 = time if ans2 == 0\nans2 = ans1 if pasW == pass[0]\n"}, {"source_code": "n, k =gets.chomp.split(\" \").map(&:to_i)\nstring=Array.new\nsame= -1\nflag = 0\nfor i in 0..n-1\n string[i]=gets\nend\nstring.sort_by! {|x| x.length}\nfor i in 0..n-1\n if ((string[i].length == string[n-1].length) && (flag == 0))\n print i+1, \" \"\n flag = 1\n same +=1 if (k==1)\n end\n if flag == 1\n same += 1\n end\nend\nif k 1\n yep = true\n break\n end\n}\nputs ((yep) ? ('Happy Alex') : ('Poor Alex')) ", "positive_code": [{"source_code": "n = gets.chomp.to_i\nlaptops = []\nn.times do\n laptops << gets.chomp.split(/ /).map(&:to_i)\nend\nlaptops.sort!\nalex = false\n(1...n).each do |first|\n a = laptops[first - 1]\n b = laptops[first]\n if a[0] < b[0] && a[1] > b[1]\n alex = true\n break\n end\nend\nif alex\n puts \"Happy Alex\"\nelse\n puts \"Poor Alex\"\nend\n"}, {"source_code": "n=gets.to_i\nx=[]\nn.times{\n\tx<x[0][1] then\n\t\tans=\"Happy Alex\"\n\t\tbreak\n\tend\n\tmax1=x[0][1] if max1 a[i + 1][1] && a[i][0] < a[i + 1][0]\n print \"Happy Alex\\n\"\n exit\n end\nend\nprint \"Poor Alex\\n\"\n"}, {"source_code": "ans = false\n\n(0...gets.to_i).each {\n if gets.split.uniq.length == 2\n ans = true\n break\n end\n}\n\nputs ((ans)? 'Happy Alex' : 'Poor Alex')"}, {"source_code": "ans = false\n\n(0...gets.to_i).each {\n a, b = gets.split\n \n if a.to_i != b.to_i\n ans = true\n break\n end\n}\n\nputs ((ans)? 'Happy Alex' : 'Poor Alex')"}, {"source_code": "numberOflaptops = gets.chomp.to_i\nlaptops = Array.new(numberOflaptops)\n\nfor i in 1..numberOflaptops\n input = gets.chomp.split(' ').map { |x| x.to_i }\n laptops[input[0]-1] = input[1]\nend\n\nmax = 0\nfor rating in laptops\n if max < rating\n max = rating\n else\n puts 'Happy Alex'\n exit\n end\nend\n\nputs 'Poor Alex'\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nq = []\nn.times {\n a, b = gets.split.map(&:to_i)\n q << [a, b]\n}\nfound = false\ncatch :happyalex do\n q.sort { |i1, i2|\n acomp = i1[0] <=> i2[0]\n bcomp = i1[1] <=> i2[1]\n\n if acomp*bcomp < 0\n found = true\n throw :happyalex\n end\n\n if acomp != 0\n acomp\n else\n bcomp\n end\n }\nend\n\nputs \"Happy Alex\" if found\nputs \"Poor Alex\" if !found"}, {"source_code": "number_of_laptops = gets.chomp\nlaptops = {}\nnumber_of_laptops.to_i.times do\n laptop = gets.chomp.split(\" \").map(&:to_i)\n laptops.store(laptop[0], laptop[1])\nend\nlaptops = laptops.sort\nanswer = false\nfor i in 0...laptops.length - 1 do\n if(laptops[i][0] < laptops[i+1][0] && laptops[i][1] > laptops[i+1][1])\n answer = true\n break\n end\nend\nif answer\n puts \"Happy Alex\"\nelse\n puts \"Poor Alex\"\nend"}, {"source_code": "n = gets.to_i\nlaptops = []\nres = false\nn.times {\n laptops << gets.split(\" \").map(&:to_i)\n}\nlaptops.sort! do |a,b|\n a[0] <=> b[0]\nend\n(0..n-2).each do |i|\n res = true if laptops[i][1] > laptops[i+1][1]\nend\n\nputs res ? \"Happy Alex\" : \"Poor Alex\""}, {"source_code": "n = gets.to_i\ns = n.times.map{gets.split.map(&:to_i)}.sort\nans = false\n(n - 1).times do |i|\n ans = true if s[i][1] > s[i + 1][1]\nend\nputs ans ? \"Happy Alex\" : \"Poor Alex\"\n"}, {"source_code": "n = gets.to_i\ns = n.times.map{gets.split.map(&:to_i)}.sort\nans = (n - 1).times.any?{|i| s[i][1] > s[i + 1][1]}\nputs ans ? \"Happy Alex\" : \"Poor Alex\"\n"}, {"source_code": "\n# Initialize vars\nspecs = []\n\n# Read input\nn = gets.strip.to_i\nn.times {specs.push(gets.strip.split.map{|s| s.to_i})}\n\nprice_order = specs.sort_by(&:first)\nquality_order = specs.sort_by(&:last)\n\nif price_order != quality_order\n puts \"Happy Alex\" \nelse\n puts \"Poor Alex\"\nend "}, {"source_code": "n = gets.to_i\na, b, m = [], [], [0]*(n + 1)\nn.times do |i|\n a[i], b[i] = gets.split.map{|x| x.to_i}\n m[b[i]] = a[i]\nend\n(1..n).each{|i| m[i] = [m[i - 1], m[i]].max}\nn.times do |i|\n if a[i] < m[b[i]]\n puts \"Happy Alex\"\n exit\n end\nend\nputs \"Poor Alex\"\n"}, {"source_code": "n=gets.to_i\narr=Array.new(n)\n\nfor i in 0...n do\n x,y=gets.split.map(&:to_i)\n arr[y-1]=x\nend\n\n\nif (arr.sort == arr)\n puts \"Poor Alex\"\nelse\n puts \"Happy Alex\"\nend"}, {"source_code": "numberOflaptops = gets.chomp.to_i\nlaptops = Array.new(numberOflaptops)\n\nfor i in 1..numberOflaptops\n input = gets.chomp.split(' ').map { |x| x.to_i }\n laptops[input[0]-1] = input[1]\nend\n\nmax = 0\nfor rating in laptops\n if max < rating\n max = rating\n else\n puts 'Happy Alex'\n exit\n end\nend\n\nputs 'Poor Alex'"}, {"source_code": "data_max = Hash.new { 0 }\ndata_min = Hash.new { 1_000_000 }\n\n1.upto(gets.to_i) do\n k, v = gets.split(' ').map(&:to_i)\n\n data_max[k] = [data_max[k], v].max\n data_min[k] = [data_min[k], v].min\nend\n\nmax = 0\nresult = false\ndata_max.keys.sort.each do |k|\n result = true if max > data_min[k]\n\n max = data_max[k]\nend\n\nputs \"#{result ? 'Happy' : 'Poor'} Alex\"\n"}, {"source_code": "(0...gets.to_i).each { |i|\n x, y = gets.chomp.split.map(&:to_i)\n if x != y\n puts 'Happy Alex'\n exit\n end\n}\n\nputs 'Poor Alex'"}, {"source_code": "n = gets.to_i\na = (0...n).map {gets.split.map {|i| i.to_i}}\nif a.sort_by { |e| e[0] } == a.sort_by { |e| e[1] }\n\tputs 'Poor Alex'\nelse\n\tputs 'Happy Alex'\nend"}, {"source_code": "#!/usr/bin/ruby\na=gets.to_i.times.map{gets.split.map(&:to_i)}.sort\nputs (a.each_cons(2).any?{|x,y|x[1]>y[1]} ? 'Happy' : 'Poor')+' Alex'"}, {"source_code": "n=gets.chomp.to_i\nn.times do\n\tif gets.split.uniq.length > 1\n\t\tputs 'Happy Alex'\n\t\texit\n\tend\nend\nputs 'Poor Alex'"}, {"source_code": "gets.to_i.times { \n if gets.split.uniq.length > 1\n puts 'Happy Alex'\n exit\n end\n}\nputs 'Poor Alex'"}, {"source_code": "arr = []\ngets.to_i.times do\n inp = gets.split.map &:to_i\n arr << inp.last - inp.first\nend\nputs arr.count { |x| x < 0 } > 0 ? \"Happy Alex\" : \"Poor Alex\"\n"}, {"source_code": "n = gets.chomp.to_i\nlaptops = []\nn.times do\n laptops << gets.chomp.split(/ /).map(&:to_i)\nend\nlaptops.sort!\nalex = false\n(1...n).each do |first|\n a = laptops[first - 1]\n break if alex\n b = laptops[first]\n if a[0] < b[0] && a[1] > b[1]\n alex = true\n break\n end\nend\nif alex\n puts \"Happy Alex\"\nelse\n puts \"Poor Alex\"\nend\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nlaptops = []\nn.times do\n laptops << gets.chomp.split(/ /).map(&:to_i)\nend\nalex = false\n(1...n).each do |first|\n a = laptops[first - 1]\n break if alex\n b = laptops[first]\n if a[0] < b[0] && a[1] > b[1]\n alex = true\n break\n end\nend\nif alex\n puts \"Happy Alex\"\nelse\n puts \"Poor Alex\"\nend\n"}, {"source_code": "n = gets.to_i\na = []\nfor i in (0...n) do\n a[i] = gets.split.map{|j| j.to_i}.to_a\nend\na.sort!\n0.upto(n - 2) do |i|\n if a[i][1] > a[i + 1][1] && a[i][0] < a[i + 1][0]\n p \"Happy Alex\"\n exit\n end\nend\np \"Poor Alex\"\n"}, {"source_code": "ans = false\nn = gets.to_i\n\n(0...gets.to_i).each {\n a, b = gets.split\n if a != b \n ans = true\n break\n end\n}\n\nputs ((ans)? 'Happy Alex' : 'Poor Alex')"}, {"source_code": "n = gets.to_i\ns = n.times.map{gets.split.map(&:to_i)}.sort\nans = false\nn.times do |i|\n ans = true if s[i][1] < s[i - 1][1]\nend\nputs ans ? \"Happy Alex\" : \"Poor Alex\"\n"}], "src_uid": "c21a84c4523f7ef6cfa232cba8b6ee2e"} {"source_code": "s = gets.chomp\nt = gets.chomp\ns_len = s.size\nt_len = t.size\ni = 0\nr_i = s_len - 1\nj = 0\nr_j = t_len - 1\nleft_j = t_len\nright_j = -1\nwhile ((j < r_j) and ((left_j == t_len) or (right_j == -1))) do\n if left_j == t_len \n i+=1 if s[i] == t[j]\n left_j = j if i == s_len\n j+=1\n end \n if right_j == -1 \n r_i-=1 if s[r_i] == t[r_j]\n right_j = r_j if r_i == -1\n r_j-=1\n end\nend\nresult = ((left_j < right_j)? (right_j - left_j) : 0)\nprint result\n", "positive_code": [{"source_code": "#b2.rb\n\ns = gets.strip.split(\"\")\nt = gets.strip.split(\"\")\n\nstart_pos = -1\nend_pos = -1\n\ni, j = 0, 0\nuntil i == t.length-1 do \n if s[j] == t[i] then\n if j == (s.length - 1) then\n start_pos = i\n break\n end\n j+=1\n end\n i+=1 \nend\n\ni, j = t.length-1, s.length-1\nuntil i == 0 do \n if s[j] == t[i] then\n if j == 0 then\n end_pos = i\n break\n end\n j-=1\n end\n i-=1\nend\n\nif end_pos <= start_pos then\n puts 0\nelse \n puts end_pos - start_pos\nend"}, {"source_code": "word=gets.chomp\nstr=gets.chomp\n\ni=0\nc=-1\n\nlf=-1\nfl=-1\nd = false\nif word.size >= str.size\n d = true\nelse\n\twhile istr.size\n puts 0\n else\n i=word.size\n c=str.size\n\n while i>0 and c>0\n c=str.rindex(word[i-1],c-1)\n i-=1\n end\n\n if str[c]==word[0]\n fl=c\n end\n\n if lf!=-1 and fl!=-1\n if fl<=lf\n puts 0\n else\n puts fl-lf\n end\n else\n puts 0\n end\n end\nend\n"}], "negative_code": [], "src_uid": "724fa4b1d35b8765048857fa8f2f6802"} {"source_code": "max = 10**18\nraw_pretty_list = []\npretty = 1\nmax.times do\n raw_pretty_list << pretty\n pretty = (pretty * 2) + 1\n break if pretty > max\nend\n\npretty_list = raw_pretty_list.map do |item|\n item ** 2 / 2 + item / 2 + 1\nend\n\nt = gets.to_i\nt.times do\n x = gets.to_i\n res = 0\n internal_pretty_list = pretty_list.dup\n while x > 0 do\n cur_pretty = internal_pretty_list.shift\n\n\n break if cur_pretty.nil?\n\n\n if x >= cur_pretty\n x -= cur_pretty\n res += 1\n end\n end\n puts res\nend\n", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n x = gets.to_i\n\n n = 1\n v = 1\n ans = 0\n\n loop {\n use_cnt = n * (1 + n) / 2\n x -= use_cnt\n\n break if x < 0\n\n v *= 2\n n += v\n ans += 1\n }\n\n puts ans\nend\n"}], "negative_code": [], "src_uid": "f0806ab99cf4da228abe3cd8073884d9"} {"source_code": "def gcd(a, b)\n b == 0 ? a : gcd(b, a % b)\nend\n\nn = gets.to_i\narr = gets.split(\" \").map{|x| x.to_i }\ng = gcd(arr[0], arr[1])\nfor i in 2...n do\n g = gcd(g, arr[i])\nend\n\nn = arr.max / g - n\nputs n % 2 == 1 ? \"Alice\" : \"Bob\"\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\ng = a[0]\na.each{|i| g=g.gcd(i)}\nif ((g..a.max).step(g).size-a.size).odd?\n puts \"Alice\"\nelse\n puts \"Bob\"\nend\n"}, {"source_code": "def gcd(a, b)\n b == 0 ? a : gcd(b, a % b)\nend\n\nn = gets.to_i\narr = gets.split(\" \").map{|x| x.to_i }\ng = gcd(arr[0], arr[1])\nfor i in 2...n do\n g = gcd(g, arr[i])\nend\n\nn = arr.max / g - n\nputs n % 2 == 1 ? \"Alice\" : \"Bob\""}, {"source_code": "def gcd a, b\n\treturn a if b == 0\n\tgcd b, a % b\nend\n\nn = gets.to_i\na = gets.split.map { |x| x.to_i }\n\ng = a[0]\na.each do |x|\n\tg = gcd g, x\nend\n\ncnt = a.max / g - a.size\n\nif cnt.odd?\n\tputs 'Alice'\nelse\n\tputs 'Bob'\nend"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map{|i| i.to_i}\n\n\ngcd = a[0]\n\na.each do |i|\n\tif i.gcd(gcd) < gcd\n\t\tgcd = i.gcd(gcd)\n\tend\nend\n\nmax = a.max\n\nif (max / gcd - n) % 2 == 1\n\tputs \"Alice\"\nelse\n\tputs \"Bob\"\nend\n"}], "negative_code": [{"source_code": "def gcd(arr)\n a, b = arr\n b.zero? ? a : gcd([b, a % b])\nend\n\nn = gets.to_i \narr = gets.split.map(&:to_i)\ng = gcd(arr.unshift(2))\narr.each {|i| g = gcd([g, i]) }\n\nn = arr.max / g - n\nputs %w(Bob Alice)[n % 2]"}, {"source_code": "def gcd(arr)\n a, b = arr\n b.zero? ? a : gcd([b, a % b])\nend\n\nn = gets.to_i \narr = gets.split.map(&:to_i)\nm = arr.max\ng = gcd(arr.unshift(2))\n(n-2).times {|i| g = gcd([g, arr[i]]) }\n\nn = m / g - n\nputs %w(Bob Alice)[n % 2]"}, {"source_code": "count = gets.to_i\nmaximum = gets.split.map(&:to_i).max\n\nputs (maximum - count).odd? ? \"Alice\" : \"Bob\""}, {"source_code": "count = gets.to_i\nmaximum = gets.split.map(&:to_i).max\n\nputs (maximum - count).even? ? \"Alice\" : \"Bob\""}], "src_uid": "3185ae6b4b681a10a21d02e67f08fd19"} {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\nindex_list = {}\narr.each_with_index do |a,i|\n\tif index_list[a] && index_list[a] != 0\n\t\tif index_list[a][-2]\n\n\t\t\tif i - index_list[a][-1] == index_list[a][-1] - index_list[a][-2]\n\t\t\t\t# puts \"i #{i}\"\n\t\t\t\tindex_list[a] << i\n\t\t\telse\n\t\t\t\tindex_list[a] = 0\n\t\t\tend\n\t\telse\n\t\t\tindex_list[a] << i\n\t\tend\n\telsif index_list[a] != 0\n\t\tindex_list[a] = [i]\n\tend\nend\n# \n# index_list = index_list.sort.to_h\n\ncount = index_list.values.count{|a| a!= 0}\n\nputs count\nindex_list.keys.sort.each do |k|\n\tv = index_list[k]\n\tif v != 0\n\t\td = 0\n\t\td = v[-1] - v[-2] if v.length > 1\n\t\tputs \"#{k} #{d}\"\n\tend\nend", "positive_code": [{"source_code": "n=gets.to_i\nd,ar,br=0,Array.new(100001,-1),Array.new(100001,0)\na=gets.chomp.split.map(&:to_i)\na.length.times do |i|\n\tif ar[a[i]]==-1\n\t\tar[a[i]]=i\n\t\td+=1\n\telsif ar[a[i]]>=0\n\t\tif br[a[i]]==0\n\t\t\tbr[a[i]]=i-ar[a[i]]\n\t\t\tar[a[i]]=i\n\t\telsif br[a[i]]==i-ar[a[i]]\n\t\t\tar[a[i]]=i\n\t\telse\n\t\t\tar[a[i]]=-2\n\t\t\td-=1\n\t\tend\n\tend\nend\nputs d\n100001.times{|i| puts \"#{i} #{br[i]}\" if ar[i]>=0 }\n"}], "negative_code": [{"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\nindex_list = {}\narr.each_with_index do |a,i|\n\tif index_list[a] && index_list[a] != 0\n\t\tif index_list[a][-2]\n\n\t\t\tif i - index_list[a][-1] == index_list[a][-1] - index_list[a][-2]\n\t\t\t\t# puts \"i #{i}\"\n\t\t\t\tindex_list[a] << i\n\t\t\telse\n\t\t\t\tindex_list[a] = 0\n\t\t\tend\n\t\telse\n\t\t\tindex_list[a] << i\n\t\tend\n\telsif index_list[a] != 0\n\t\tindex_list[a] = [i]\n\tend\nend\n\nindex_list.each do |k,v|\n\tif v != 0\n\t\td = 0\n\t\td = v[-1] - v[-2] if v.length > 1\n\t\tputs \"#{k} #{d}\"\n\tend\nend"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\nindex_list = {}\narr.each_with_index do |a,i|\n\tif index_list[a] && index_list[a] != 0\n\t\tif index_list[a][-2]\n\n\t\t\tif i - index_list[a][-1] == index_list[a][-1] - index_list[a][-2]\n\t\t\t\t# puts \"i #{i}\"\n\t\t\t\tindex_list[a] << i\n\t\t\telse\n\t\t\t\tindex_list[a] = 0\n\t\t\tend\n\t\telse\n\t\t\tindex_list[a] << i\n\t\tend\n\telsif index_list[a] != 0\n\t\tindex_list[a] = [i]\n\tend\nend\n\ncount = index_list.values.count{|a| a!= 0}\nputs count\nindex_list.each do |k,v|\n\tif v != 0\n\t\td = 0\n\t\td = v[-1] - v[-2] if v.length > 1\n\t\tputs \"#{k} #{d}\"\n\tend\nend"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\nindex_list = {}\narr.each_with_index do |a,i|\n\tif index_list[a] && index_list[a] != 0\n\t\tif index_list[a][-2]\n\n\t\t\tif i - index_list[a][-1] == index_list[a][-1] - index_list[a][-2]\n\t\t\t\t# puts \"i #{i}\"\n\t\t\t\tindex_list[a] << i\n\t\t\telse\n\t\t\t\tindex_list[a] = 0\n\t\t\tend\n\t\telse\n\t\t\tindex_list[a] << i\n\t\tend\n\telsif index_list[a] != 0\n\t\tindex_list[a] = [i]\n\tend\nend\n# \n# index_list = index_list.sort.to_h\n\ncount = index_list.values.count{|a| a!= 0}\n\nputs count\nindex_list.each do |k,v|\n\tif v != 0\n\t\td = 0\n\t\td = v[-1] - v[-2] if v.length > 1\n\t\tputs \"#{k} #{d}\"\n\tend\nend"}], "src_uid": "097e35b5e9c96259c54887158ebff544"} {"source_code": "#input = File.open('input.txt','r')\nn, d = gets.split\nn = n.to_i\nd = d.to_i\ncoordinates = gets.split\ncoordinates.length.times do |i|\n\tcoordinates[i] = coordinates[i].to_i\nend\n#input.close\nanswer = 0\nif n > 2\n\tx1 = 0\n\tx3 = 1\n\t# b = false\n\t# while x1 != coordinates.length - 2\n\t\t# #printf('%d %d ',x1,x3)\n\t\t# if coordinates[x3] - coordinates[x1] <= d\n\t\t\t# answer += x3 - x1 - 1\n\t\t\t# if x3 < coordinates.length - 1\n\t\t\t\t# x3 += 1\n\t\t\t# else\n\t\t\t\t# #answer += x3 - x1 - 1\n\t\t\t\t# x1 += 1\n\t\t\t\t# unless b\n\t\t\t\t\t# b = true\n\t\t\t\t# else\n\t\t\t\t\t# answer += (x3 - x1) * (x3 - x1 - 1) / 2\n\t\t\t\t# end\n\t\t\t\t# #x1 = coordinates.length - 2\n\t\t\t# end\n\t\t# else\n\t\t\t# x1 += 1\n\t\t\t# answer += (x3 - x1 - 1) * (x3 - x1 - 2) / 2\n\t\t# end\n\t\t# #puts answer\n\t# end\n\twhile x1 < coordinates.length\n\t\t#printf('%d ',x1)\n\t\twhile x3 < coordinates.length and coordinates[x3] - coordinates[x1] <= d\n\t\t\tx3 += 1\n\t\tend\n\t\t#printf('%d ',x3)\n\t\t#if coordinates[x3] - coordinates[x1] <= d\n\t\t\tanswer += (x3 - x1 - 1) * (x3 - x1 - 2) / 2\n\t\t#end\n\t\tx1 += 1\n\t\t# if x3 != coordinates.length - 1\n\t\t\t# x3 += 1\n\t\t# end\n\t\t#puts answer\n\tend\nend\nputs answer\n\n\n\n#assign a value to a variable only if that variable isn't already set:\n#@variable ||= \"default value\"\n\n#x, y = y, x will interchange the values of x and y\n\n#names2 = %w{ ann richard william susan pat } \n\n#puts \"Enrollments will now Stop\" if participants > 2500 \n\n#Negative index values count from the end of the array\n", "positive_code": [{"source_code": "n,d = gets.chomp.split(\" \").collect! {|x| x.to_i}\nline = gets.chomp.split(\" \").collect! {|x| x.to_i}\n\narr = []\nline.each {|p|\n arr.push(p+d)\n}\n\ns = 0\nt = 0\nways = 0\n\n#puts n\nwhile sarr[s] \n\t\ts+=1\n\tend\n\tif s>=n\n\t\tbreak\n\tend\n\twhile t=line[t] \n\t#puts \"- #{t} #{s}\"\n\tif t-s>1\n\t\tways += (t-s-1)*(t-s)*0.5\n\t#\tputs \": #{t} #{s}\" \n\tend\n\tt +=1\n\tif t>=n \n\t #puts \"break\"\n\t\tbreak\n\tend\n\tend\n\t\nend\n\nputs ways.to_i"}], "negative_code": [{"source_code": "#input = File.open('input.txt','r')\nn, d = gets.split\nn = n.to_i\nd = d.to_i\ncoordinates = gets.split\ncoordinates.length.times do |i|\n\tcoordinates[i] = coordinates[i].to_i\nend\n#input.close\nanswer = 0\nif n > 2\n\tx1 = 0\n\tx3 = 2\n\tb = false\n\twhile x1 != coordinates.length - 2\n\t\t#printf('%d %d ',x1,x3)\n\t\tif coordinates[x3] - coordinates[x1] <= d\n\t\t\tanswer += x3 - x1 - 1\n\t\t\tif x3 < coordinates.length - 1\n\t\t\t\tx3 += 1\n\t\t\telse\n\t\t\t\t#answer += x3 - x1 - 1\n\t\t\t\tx1 += 1\n\t\t\t\tunless b\n\t\t\t\t\tb = true\n\t\t\t\telse\n\t\t\t\t\tanswer += (x3 - x1) * (x3 - x1 - 1) / 2\n\t\t\t\tend\n\t\t\t\t#x1 = coordinates.length - 2\n\t\t\tend\n\t\telse\n\t\t\tx1 += 1\n\t\t\tanswer += (x3 - x1 - 1) * (x3 - x1 - 2) / 2\n\t\tend\n\t\t#puts answer\n\tend\nend\nputs answer\n\n\n\n#assign a value to a variable only if that variable isn't already set:\n#@variable ||= \"default value\"\n\n#x, y = y, x will interchange the values of x and y\n\n#names2 = %w{ ann richard william susan pat } \n\n#puts \"Enrollments will now Stop\" if participants > 2500 \n\n#Negative index values count from the end of the array\n"}], "src_uid": "1f6491999bec55cb8d960181e830f4c8"} {"source_code": "\n@local = false\n@answer = 1\n@gamecnt = 100\n\ndef continue_game\n if @local\n return false if @gamecnt <= 0\n @gamecnt -= 1\n @querycnt = 0\n return true\n else\n line = gets.chomp\n exit if line == \"mistake\"\n return line == \"start\"\n end\nend\n\ndef query_game(x,y)\n if @local\n @querycnt += 1\n return x%@answer >= y%@answer\n else\n STDOUT.puts \"? #{x} #{y}\"\n STDOUT.flush\n return gets[0] == \"x\"\n end\nend\n\ndef answer_game(a)\n if @local\n abort \"#{@answer} != #{a}\" if @answer != a\n puts \"AC:#{@querycnt}\"\n @answer = rand(1..(1e9.to_i))\n else\n STDOUT.puts \"! #{a}\"\n STDOUT.flush\n end\nend\n\n# \n\nwhile continue_game\n \n x = 1\n y = 0\n \n while x <= 2e9.to_i && query_game(x, y)\n x, y = x*2, x\n end\n if x > 2e9\n answer_game(1)\n next\n end\n while x-y > 1\n m = (x+y)/2\n if query_game(m, y)\n y = m\n else\n x = m\n end\n end\n answer_game(x)\nend\n\n\n", "positive_code": [{"source_code": "require 'prime'\n\np = Prime.each(10**5).to_a\n\nloop do\n s = gets.chomp\n break if s == \"end\"\n min = 0\n max = 10**9\n while max-min > 1\n mid = (min+max)/2\n puts \"? #{mid} #{max}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"x\"\n min = mid\n else\n max = mid\n end\n end\n m = max\n ret = 1\n p.each do |i|\n a = 0\n while m%i == 0\n a += 1\n puts \"? #{max} #{max/(i**a)}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"y\"\n ret *= i\n end\n m /= i\n end\n end\n puts \"? #{max} #{max/m}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"y\"\n ret *= m\n end\n\n puts \"! #{ret}\"\n STDOUT.flush\nend"}, {"source_code": "DBG = !true\ndef outp(str)\n puts str\n STDOUT.flush\nend\n\ndef lt(x,y)\n hashkey = x.to_s + \".\" + y.to_s\n if $h.has_key?(hashkey)\n return $h[hashkey]\n end\n outp(\"? #{x} #{y}\")\n s = gets.chomp\n exit(0) if s == 'mistake'\n $h[hashkey] = (s=='y')\n return (s=='y')\nend\n\n$h = {}\nR = (DBG ? 10 : 1000000000)\nMONO = 1\nSPLIT = 2\nS1N = 3\nwhile true\n $h.clear()\n inp = gets.chomp\n exit(0) if inp == \"end\" || inp == \"mistake\"\n next if inp != 'start'\n st = MONO\n s = R\n b = t = -1\n while true\n puts \"st #{st} s #{s} b #{b} t #{t}\" if DBG\n if st == MONO\n if s == 2\n st = S1N\n b = t = 2\n next\n end\n p = s - 2*(s/3)\n q = s - s/3\n if lt(p, q)\n st = SPLIT\n t = s\n s = p\n b = q + 1\n else\n s = q\n end\n\n elsif st == SPLIT\n if s == 1\n st = S1N\n next\n end\n p = s - s/2\n if lt(p,s)\n s = p\n else\n st = MONO\n b = t = -1\n end\n else # st = S1N\n if b < t\n p = (b+t)/2\n if lt(p,t)\n t = p\n else\n b = (b==t-1 ? t : p+1)\n end\n else # b == t\n if lt(t,1)\n outp(\"! #{t}\")\n else\n outp(\"! 1\")\n end\n break\n end\n end\n end\nend\n"}], "negative_code": [{"source_code": "loop do\n s = gets.chomp\n break if s == \"end\"\n min = 0\n max = 10**9\n while max-min > 1\n mid = (min+max)/2\n puts \"? #{mid} #{max}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"x\"\n min = mid\n else\n max = mid\n end\n end\n m = max\n for i in 2..31623\n while m%i == 0\n puts \"? #{max} #{max/i}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"y\"\n break\n else\n max /= i\n end\n m /= i\n end\n while m%i == 0\n m /= i\n end\n end\n puts \"! #{max}\"\n STDOUT.flush\nend"}, {"source_code": "require 'prime'\n\np = Prime.each(10**5).to_a\n\nloop do\n s = gets.chomp\n break if s == \"end\"\n min = 0\n max = 10**9\n while max-min > 1\n mid = (min+max)/2\n puts \"? #{mid} #{max}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"x\"\n min = mid\n else\n max = mid\n end\n end\n m = max\n ret = 1\n p.each do |i|\n a = 0\n while m%i == 0\n a += 1\n puts \"? #{max} #{max/i}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"y\"\n ret *= i\n end\n m /= i\n end\n end\n puts \"? #{max} #{max/m}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"y\"\n ret *= m\n end\n\n puts \"! #{max}\"\n STDOUT.flush\nend"}, {"source_code": "require 'prime'\n\np = Prime.each(10**5).to_a\n\nloop do\n s = gets.chomp\n break if s == \"end\"\n min = 0\n max = 10**9\n while max-min > 1\n mid = (min+max)/2\n puts \"? #{mid} #{max}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"x\"\n min = mid\n else\n max = mid\n end\n end\n m = max\n ret = 1\n p.each do |i|\n a = 0\n while m%i == 0\n a += 1\n puts \"? #{max} #{max/i}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"y\"\n ret *= i\n end\n m /= i\n end\n end\n puts \"? #{max} #{max/m}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"y\"\n ret *= m\n end\n\n puts \"! #{ret}\"\n STDOUT.flush\nend"}, {"source_code": "def ret(a,x,y)\n if x%a >= y%a\n return \"x\"\n else\n return \"y\"\n end\nend\n\n\nloop do\n s = gets.chomp\n break if s == \"end\"\n min = 0\n max = 10**9\n #ans = rand(1..10**9)\n #p ans\n while max-min > 1\n mid = (min+max)/2\n puts \"? #{mid} #{max}\"\n STDOUT.flush\n r = gets.chomp\n #r = ret(ans,mid,max)\n if r == \"x\"\n min = mid\n else\n max = mid\n end\n end\n for i in 2..31623\n while max%i == 0\n puts \"? #{max} #{max/i}\"\n STDOUT.flush\n r = gets.chomp\n #r = ret(ans,max,max/i)\n if r == \"y\"\n break\n else\n max /= i\n end\n end\n end\n puts \"! #{max}\"\n STDOUT.flush\nend"}, {"source_code": "require 'prime'\n\n\nloop do\n s = gets.chomp\n break if s == \"end\"\n min = 0\n max = 10**9\n while max-min > 1\n mid = (min+max)/2\n puts \"? #{mid} #{max}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"x\"\n min = mid\n else\n max = mid\n end\n end\n m = max\n Prime.each(10**5) do |i|\n break if i > m || m%i != 0\n while m%i == 0\n puts \"? #{max} #{max/i}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"x\"\n max /= i\n else\n break\n end\n m /= i\n end\n while m%i == 0\n m /= i\n end\n puts \"? #{max} #{i}\"\n STDOUT.flush\n r = gets.chomp\n if r == \"x\"\n max = i\n m = i\n end\n end\n puts \"! #{max}\"\n STDOUT.flush\nend"}, {"source_code": "def ret(a,x,y)\n if x%a >= y%a\n return \"x\"\n else\n return \"y\"\n end\nend\n\n\nloop do\n s = gets.chomp\n break if s == \"end\"\n min = 0\n max = 10**9\n #ans = rand(1..10**9)\n #p ans\n while max-min > 1\n mid = (min+max)/2\n puts \"? #{mid} #{min}\"\n STDOUT.flush\n r = gets.chomp\n #r = ret(ans,mid,max)\n if r == \"x\"\n min = mid\n else\n max = mid\n end\n end\n for i in 2..31623\n while max%i == 0\n puts \"? #{max} #{max/i}\"\n STDOUT.flush\n r = gets.chomp\n #r = ret(ans,max,max/i)\n if r == \"y\"\n break\n else\n max /= i\n end\n end\n end\n puts \"! #{max}\"\n STDOUT.flush\nend"}, {"source_code": "DBG = !true\ndef outp(str)\n puts str\n STDOUT.flush\nend\n\ndef lt(x,y)\n outp(\"? #{x} #{y}\")\n s = gets.chomp\n exit(0) if s == 'mistake'\n return (s=='y')\nend\n\nR = (DBG ? 10 : 1000000000)\nMONO = 1\nSPLIT = 2\nS1N = 3\nwhile true\n inp = gets.chomp\n exit(0) if inp == \"end\" || inp == \"mistake\"\n next if inp != 'start'\n st = MONO\n s = R\n b = t = -1\n while true\n puts \"st #{st} s #{s} b #{b} t #{t}\" if DBG\n if st == MONO\n if s == 2\n st = S1N\n b = t = 2\n next\n end\n p = s - 2*(s/3)\n q = s - s/3\n if lt(p, q)\n st = SPLIT\n t = s\n s = p\n b = q\n else\n s = q\n end\n\n elsif st == SPLIT\n if s == 1\n st = S1N\n next\n end\n p = s - s/2\n if lt(p,s)\n s = p\n else\n st = MONO\n b = t = -1\n end\n else # st = S1N\n if b < t\n p = (b+t)/2\n if lt(p,t)\n t = p\n else\n b = (b==t-1 ? t : p)\n end\n else # b == t\n if lt(t,1)\n outp(\"! #{t}\")\n else\n outp(\"! 1\")\n end\n break\n end\n end\n end\nend\n"}, {"source_code": "DBG = !true\ndef outp(str)\n puts str\n STDOUT.flush\nend\n\ndef lt(x,y)\n hashkey = x.to_s + \".\" + y.to_s\n if $h.has_key?(hashkey)\n return $h[hashkey]\n end\n outp(\"? #{x} #{y}\")\n s = gets.chomp\n exit(0) if s == 'mistake'\n $h[hashkey] = (s=='y')\n return (s=='y')\nend\n\n$h = {}\nR = (DBG ? 10 : 1000000000)\nMONO = 1\nSPLIT = 2\nS1N = 3\nwhile true\n $h.clear()\n inp = gets.chomp\n exit(0) if inp == \"end\" || inp == \"mistake\"\n next if inp != 'start'\n st = MONO\n s = R\n b = t = -1\n while true\n puts \"st #{st} s #{s} b #{b} t #{t}\" if DBG\n if st == MONO\n if s == 2\n st = S1N\n b = t = 2\n next\n end\n p = s - 2*(s/3)\n q = s - s/3\n if lt(p, q)\n st = SPLIT\n t = s\n s = p\n b = q + 1\n else\n s = q\n end\n\n elsif st == SPLIT\n if s == 1\n st = S1N\n next\n end\n p = s - s/2\n if lt(p,s)\n s = p\n else\n st = MONO\n b = t = -1\n end\n else # st = S1N\n if b < t\n p = (b+t)/2\n if lt(p,t)\n t = p\n else\n b = (b==t-1 ? t : p)\n end\n else # b == t\n if lt(t,1)\n outp(\"! #{t}\")\n else\n outp(\"! 1\")\n end\n break\n end\n end\n end\nend\n"}, {"source_code": "DBG = !true\ndef outp(str)\n puts str\n STDOUT.flush\nend\n\ndef lt(x,y)\n hashkey = x.to_s + \".\" + y.to_s\n if $h.has_key?(hashkey)\n return $h[hashkey]\n end\n outp(\"? #{x} #{y}\")\n s = gets.chomp\n exit(0) if s == 'mistake'\n $h[hashkey] = (s=='y')\n return (s=='y')\nend\n\n$h = {}\nR = (DBG ? 10 : 1000000000)\nMONO = 1\nSPLIT = 2\nS1N = 3\nwhile true\n $h.clear()\n inp = gets.chomp\n exit(0) if inp == \"end\" || inp == \"mistake\"\n next if inp != 'start'\n st = MONO\n s = R\n b = t = -1\n while true\n puts \"st #{st} s #{s} b #{b} t #{t}\" if DBG\n if st == MONO\n if s == 2\n st = S1N\n b = t = 2\n next\n end\n p = s - 2*(s/3)\n q = s - s/3\n if lt(p, q)\n st = SPLIT\n t = s\n s = p\n b = q\n else\n s = q\n end\n\n elsif st == SPLIT\n if s == 1\n st = S1N\n next\n end\n p = s - s/2\n if lt(p,s)\n s = p\n else\n st = MONO\n b = t = -1\n end\n else # st = S1N\n if b < t\n p = (b+t)/2\n if lt(p,t)\n t = p\n else\n b = (b==t-1 ? t : p)\n end\n else # b == t\n if lt(t,1)\n outp(\"! #{t}\")\n else\n outp(\"! 1\")\n end\n break\n end\n end\n end\nend\n"}, {"source_code": "DBG = true\ndef outp(str)\n puts str\n STDOUT.flush\nend\n\ndef lt(x,y)\n outp(\"? #{x} #{y}\")\n s = gets.chomp\n exit(0) if s == 'mistake'\n return (s=='y')\nend\n\nR = (DBG ? 10 : 1000000000)\nMONO = 1\nSPLIT = 2\nS1N = 3\nwhile true\n inp = gets.chomp\n exit(0) if inp == \"end\" || inp == \"mistake\"\n next if inp != 'start'\n st = MONO\n s = R\n b = t = -1\n while true\n puts \"st #{st} s #{s} b #{b} t #{t}\" if DBG\n if st == MONO\n if s == 2\n st = S1N\n b = t = 2\n next\n end\n p = s - 2*(s/3)\n q = s - s/3\n if lt(p, q)\n st = SPLIT\n t = s\n s = p\n b = q\n else\n s = q\n end\n\n elsif st == SPLIT\n if s == 1\n st = S1N\n next\n end\n p = s - s/2\n if lt(p,s)\n s = p\n else\n st = MONO\n b = t = -1\n end\n else # st = S1N\n if b < t\n p = (b+t)/2\n if lt(p,t)\n t = p\n else\n b = (b==t-1 ? t : p)\n end\n else # b == t\n if lt(t,1)\n outp(\"! #{t}\")\n else\n outp(\"! 1\")\n end\n break\n end\n end\n end\nend\n"}, {"source_code": "\n@local = false\n@answer = 1\n@trycnt = 29\n\ndef continue_game\n if @local\n return false if @trycnt <= 0\n @trycnt -= 1\n return true\n else\n line = gets.chomp\n exit if line == \"mistake\"\n return line == \"start\"\n end\nend\n\ndef query_game(x,y)\n if @local\n return x%@answer >= y%@answer\n else\n STDOUT.puts \"? #{x} #{y}\"\n STDOUT.flush\n return gets[0] == \"x\"\n end\nend\n\ndef answer_game(a)\n if @local\n abort if @answer != a\n puts \"AC\"\n @answer = rand(1..100000)\n else\n STDOUT.puts \"! #{a}\"\n STDOUT.flush\n end\nend\n\n# \n\nwhile continue_game\n \n if query_game(0, 1)\n answer_game(1)\n next\n end\n x = 1\n y = 0\n \n while query_game(x, y)\n x, y = x*2, x\n end\n while x-y > 1\n m = (x+y)/2\n if query_game(m, y)\n y = m\n else\n x = m\n end\n end\n answer_game(x)\nend\n\n\n"}], "src_uid": "eab8e5ac203d9f10c893ea35d249fe84"} {"source_code": "n, k, *a = gets(p).split.map(&:to_i)\nl = r = 0\nt = {}\nwhile k > 0 && r < n\n\tunless t[a[r]]\n\t\tk -= 1\n\t\tt[a[r]] = 1\n\telse\n\t\tt[a[r]] += 1\n\tend\n\tr += 1\nend\nwhile t[a[l]] > 1\n\tt[a[l]] -= 1\n\tl += 1\nend\nputs \"%d %d\"%(k > 0 ? [-1, -1] : [l+1, r])\n\n", "positive_code": [{"source_code": "def execute(n, k, arr)\n return [1, 1] if k == 1\n return [-1, -1] if k > n\n\n @lelf, @right = 0\n @arr_count = [0] * (10**5 + 1)\n @count = 0\n\n for j in 0..n-1\n @arr_count[arr[j]] += 1\n\n if @arr_count[arr[j]] == 1\n @count += 1\n @right = j\n end\n # puts \"puts arr[#{j}]: #{arr[j]}, number count: #{@arr_count[arr[j]]}, @count: #{@count}, }\"\n\n if @count == k\n break\n end\n\n end\n\n return [-1, -1] if @count < k\n\n while @count == k\n @arr_count[arr[@lelf]] -= 1\n if @arr_count[arr[@lelf]] == 0\n break\n end\n @lelf += 1\n end\n\n return [@lelf + 1, @right + 1]\nend\n\nn, k = gets.chomp.split(' ').map(&:to_i)\narr = gets.chomp.split(' ').map(&:to_i)\nresult = execute(n, k, arr)\nputs result.join(' ')\n"}, {"source_code": "n, k, *a = gets(p).split.map(&:to_i)\nl = r = 0\nt = {}\nwhile k > 0 && r < n\n\tunless t[a[r]]\n\t\tk -= 1\n\t\tt[a[r]] = 1\n\telse\n\t\tt[a[r]] += 1\n\tend\n\tr += 1\nend\nwhile t[a[l]] > 1\n\tt[a[l]] -= 1\n\tl += 1\nend\nputs \"%d %d\"%(k > 0 ? [-1, -1] : [l+1, r])\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\narr = STDIN.readline.split.collect {|s| s.to_i }\nif arr.uniq.length < k\n\tputs '-1 -1'\n\texit\nend\nif k == 1\n\tputs '1 1'\n\texit\nend\ncount = 1\nunique_hash = { arr[0] => true }\nright = 0\nwhile count < k\n\tright += 1\n\tx = arr[right]\n\tif not unique_hash.include? x\n\t\tunique_hash[x] = true\n\t\tcount += 1\n\tend\nend\ncount = 1\nleft = right\nunique_hash = { arr[right] => true }\nwhile count < k\n\tleft -= 1\n\tx = arr[left]\n\tif not unique_hash.include? x\n\t\tunique_hash[x] = true\n\t\tcount += 1\n\tend\nend\nputs '%d %d' % [left+1, right+1]\n\n"}, {"source_code": "n, k, *a = gets(p).split.map(&:to_i)\nl = r = 0\nt = {}\nwhile k > 0 && r < n\n\tunless t[a[r]]\n\t\tk -= 1\n\t\tt[a[r]] = 1\n\telse\n\t\tt[a[r]] += 1\n\tend\n\tr += 1\nend\nwhile t[a[l]] > 1\n\tt[a[l]] -= 1\n\tl += 1\nend\nputs \"%d %d\"%(k > 0 ? [-1, -1] : [l+1, r])\n"}, {"source_code": "n, k, *a = gets(p).split.map(&:to_i)\nl = r = 0\nt = {}\nwhile k > 0 && r < n\n\tunless t[a[r]]\n\t\tk -= 1\n\t\tt[a[r]] = 1\n\telse\n\t\tt[a[r]] += 1\n\tend\n\tr += 1\nend\nwhile t[a[l]] > 1\n\tt[a[l]] -= 1\n\tl += 1\nend\nputs \"%d %d\"%(k > 0 ? [-1, -1] : [l+1, r])\n\n"}, {"source_code": "n, k, *a = gets(p).split.map(&:to_i)\nl = r = 0\nt = {}\nwhile k > 0 && r < n\n\tunless t[a[r]]\n\t\tk -= 1\n\t\tt[a[r]] = 1\n\telse\n\t\tt[a[r]] += 1\n\tend\n\tr += 1\nend\nwhile t[a[l]] > 1\n\tt[a[l]] -= 1\n\tl += 1\nend\nputs \"%d %d\"%(k > 0 ? [-1, -1] : [l+1, r])\n\n"}, {"source_code": "n, k = gets.rstrip.split.map(&:to_i)\narr = gets.rstrip.split.map(&:to_i)\n\ntmp = []\nl = r = 0\n\ncount = 0\n\nwhile r < n do\n tmp[arr[r]] ? tmp[arr[r]] += 1 : tmp[arr[r]] = 1\n count += 1 if tmp[arr[r]] == 1\n if count == k\n while l <= r do\n tmp[arr[l]] -= 1\n if tmp[arr[l]] == 0\n puts \"#{l + 1} #{r + 1}\"\n exit\n end\n l += 1\n end\n end\n r += 1\nend\n\nputs \"-1 -1\"\n"}, {"source_code": "n, k, *a = gets(p).split.map(&:to_i)\nl = r = 0\nt = {}\nwhile k > 0 && r < n\n\tunless t[a[r]]\n\t\tk -= 1\n\t\tt[a[r]] = 1\n\telse\n\t\tt[a[r]] += 1\n\tend\n\tr += 1\nend\nwhile t[a[l]] > 1\n\tt[a[l]] -= 1\n\tl += 1\nend\nputs \"%d %d\"%(k > 0 ? [-1, -1] : [l+1, r])\n\n"}, {"source_code": "require 'set'\nbuf = gets.split(' ')\nn = buf[0].to_i\nk = buf[1].to_i\nst = Set.new\nbuf = gets.split(' ')\n0.upto(n - 1) { |ii|\n i = buf[ii]\n st.add(i)\n if st.size == k \n st.clear\n ii.downto(0) { |jj|\n j = buf[jj]\n st.add(j)\n if st.size == k \n print jj + 1, \" \", ii + 1\n exit 0\n end\n }\n end\n}\nprint \"-1 -1\"\n"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nlist = gets.chomp.split.map(&:to_i)\n\ndef aaa(list, k)\n count = Hash.new { |hash, key| hash[key] = 0 }\n\n for r in 0..(list.length - 1)\n count[list[r]] += 1\n\n if count[list[r]] == 1\n k -= 1\n end\n\n if k == 0\n for l in 0..r\n count[list[l]] = count[list[l]] - 1\n\n if count[list[l]] == 0\n return [l + 1, r + 1]\n end\n end\n end\n end\n\n return [-1, -1]\nend\n\nresult = aaa(list, k)\n\nprint result[0], \" \", result[1]\n"}, {"source_code": "n, k, *a = gets(p).split.map(&:to_i)\nl = r = 0\nt = {}\nwhile k > 0 && r < n\n\tunless t[a[r]]\n\t\tk -= 1\n\t\tt[a[r]] = 1\n\telse\n\t\tt[a[r]] += 1\n\tend\n\tr += 1\nend\nwhile t[a[l]] > 1\n\tt[a[l]] -= 1\n\tl += 1\nend\nputs \"%d %d\"%(k > 0 ? [-1, -1] : [l+1, r])\n\n"}, {"source_code": "n, k, *a = gets(p).split.map(&:to_i)\nl = r = 0\nt = {}\nwhile k > 0 && r < n\n\tunless t[a[r]]\n\t\tk -= 1\n\t\tt[a[r]] = 1\n\telse\n\t\tt[a[r]] += 1\n\tend\n\tr += 1\nend\nwhile t[a[l]] > 1\n\tt[a[l]] -= 1\n\tl += 1\nend\nputs \"%d %d\"%(k > 0 ? [-1, -1] : [l+1, r])\n"}, {"source_code": "require 'set'\n\n$incr = Proc.new {|st,x| st[x].nil? ? (st[x] = 1) : (st[x] += 1) }\n$decr = Proc.new {|st,x| st[x].nil? ? 0 : (st[x] == 1 ? (st.delete x) : (st[x] -= 1) ) }\n$dis = Proc.new {|ls| st = {}; ls.each {|x| $incr.(st,x) } ; st }\n\n\ndef good(ls,m,k)\n\n l = ls.length - m - 1\n st = $dis.(ls.take(m))\n cnt = st.size\n if cnt >= k\n return [true,0,ls]\n else\n (0..l).each do |i|\n $incr.(st,ls[m+i])\n $decr.(st,ls[i])\n if st.size >= k\n ar = Array.new(m)\n i += 1\n m.times do |j|\n ar[j] = ls[j+i]\n end\n return [true,i,ar]\n end\n end\n end\n return [false]\nend\n\ndef doIt(n,k,ls)\n off = 0\n h = n\n l = [k - 1,0].max\n a = [false]\n while (h - l > 1)\n m = (h+l) / 2\n a = good(ls,m,k)\n if a.first\n h = m\n ls = a[2]\n off += a[1]\n else\n l = m\n end\n end\n a = good(ls,h,k)\n puts \"#{a[1]+1+off} #{a[1]+h+off}\" \n\nend\n\nxs = gets.split.map(&:to_i)\nn, k = xs[0], xs[1]\nls = gets.split.map(&:to_i)\n\nst = Set.new\n\nls.each {|x| st.add x}\n\nif st.size < k then\n puts \"-1 -1\" #cant be done\nelse\n doIt(n,k,ls)\nend"}, {"source_code": "require 'set'\n\ndef good(ls,m,k)\n\n incr = Proc.new {|st,x| st[x].nil? ? (st[x] = 1) : (st[x] += 1) }\n decr = Proc.new {|st,x| st[x].nil? ? 0 : (st[x] == 1 ? (st.delete x) : (st[x] -= 1) ) }\n dis = Proc.new {|ls| st = {}; ls.each {|x| incr.(st,x) } ; st }\n\n l = ls.length - m - 1\n st = dis.(ls.take(m))\n cnt = st.size\n if cnt >= k\n return [true,0,ls]\n else\n (0..l).each do |i|\n incr.(st,ls[m+i])\n decr.(st,ls[i])\n if st.size >= k\n ar = Array.new(m)\n i += 1\n m.times do |j|\n ar[j] = ls[j+i]\n end\n return [true,i,ar]\n end\n end\n end\n return [false]\nend\n\ndef doIt(n,k,ls)\n off = 0\n h = n\n l = [k - 1,0].max\n a = [false]\n while (h - l > 1)\n m = (h+l) / 2\n a = good(ls,m,k)\n if a.first\n h = m\n ls = a[2]\n off += a[1]\n else\n l = m\n end\n end\n a = good(ls,h,k)\n puts \"#{a[1]+1+off} #{a[1]+h+off}\" \n\nend\n\nxs = gets.split.map(&:to_i)\nn, k = xs[0], xs[1]\nls = gets.split.map(&:to_i)\n\nst = Set.new\n\nls.each {|x| st.add x}\n\nif st.size < k then\n puts \"-1 -1\" #cant be done\nelse\n doIt(n,k,ls)\nend"}, {"source_code": "n, k, *a = gets(p).split.map(&:to_i)\nl = r = 0\nt = {}\nwhile k > 0 && r < n\n\tunless t[a[r]]\n\t\tk -= 1\n\t\tt[a[r]] = 1\n\telse\n\t\tt[a[r]] += 1\n\tend\n\tr += 1\nend\nwhile t[a[l]] > 1\n\tt[a[l]] -= 1\n\tl += 1\nend\nputs \"%d %d\"%(k > 0 ? [-1, -1] : [l+1, r])\n\n"}, {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nif n==1\n\tputs \"%d %d\"%(k>1 ? [-1,-1] : [1,1]) \t\n\texit\nend\nl=0\nl+=1 while (l0)&&(r1\n\th[a[l]]-=1\n\tl+=1\nend\nputs \"%d %d\"%(k>0 ? [-1,-1] : [l+1,r+1]) "}, {"source_code": "n, k, *a = gets(p).split.map(&:to_i)\nl = r = 0\nt = {}\nwhile k > 0 && r < n\n\tunless t[a[r]]\n\t\tk -= 1\n\t\tt[a[r]] = 1\n\telse\n\t\tt[a[r]] += 1\n\tend\n\tr += 1\nend\nwhile t[a[l]] > 1\n\tt[a[l]] -= 1\n\tl += 1\nend\nputs \"%d %d\"%(k > 0 ? [-1, -1] : [l+1, r])\n\n"}], "negative_code": [{"source_code": "def execute(n, k, arr)\n @count = 0\n @arr_count = [0] * n\n @arr_count[0] = 1\n @lelf, @right = 0\n\n for j in 1..n-1\n @i = 0\n\n # skip if arr[j] count before\n # next if @arr_count[arr.index(@arr_count[j])] == 0\n\n while @i < j do\n if arr[@i] == arr[j]\n @arr_count[j] = @arr_count[j - 1]\n break\n end\n @i += 1\n end\n\n # item no exist [i..j-2]\n if @i == j\n @arr_count[j] = @arr_count[j - 1] + 1\n @right = j\n @count = @arr_count[j]\n end\n\n # puts \"j: #{j}, @count: #{@count}, #{@arr_count.join(' ')}\"\n\n break if @arr_count[j] == k\n end\n\n # check @count, shifl @lelf + 1\n\n if @count < k\n return [-1, -1]\n else\n while @arr_count[@lelf + 1] == 1\n @lelf += 1\n end\n return [@lelf + 1, @right + 1] if @right > 0\n end\n\nend\n\n# puts \"test case 1\"\n# puts execute(4, 2, %w(1 2 2 3).map(&:to_i)).inspect\n# #arr_count 1 2 0 0\n\n# puts \"test case 2\"\n# puts execute(8, 3, %w(1 1 2 2 3 3 4 5).map(&:to_i)).inspect\n# #arr_count 1 1 2 2 3 0 0 0\n\n# puts \"test case 3\"\n# puts execute(7, 4, %w(4 7 7 4 7 4 7).map(&:to_i)).inspect\n# #arr_count 1 2 2 2 2 2 2\n\nn, k = gets.chomp.split(' ').map(&:to_i)\narr = gets.chomp.split(' ').map(&:to_i)\nresult = execute(n, k, arr)\nputs result.join(' ')\n"}, {"source_code": "#!/usr/bin/ruby\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\narr = STDIN.readline.split.collect {|s| s.to_i }\nif arr.uniq.length < k\n\tputs '-1 -1'\n\texit\nend\nif k == 1\n\tputs '1 1'\n\texit\nend\nstart = 0\nstart += 1 while arr[start] == arr[start+1]\ncount = 1\nunique_hash = { arr[start] => true }\npos = start\nwhile count < k\n\tpos += 1\n\tx = arr[pos]\n\tif not unique_hash.include? x\n\t\tunique_hash[x] = true\n\t\tcount += 1\n\tend\nend\nputs '%d %d' % [start+1, pos+1]\n\n"}, {"source_code": "n, k = gets.rstrip.split.map(&:to_i)\narr = gets.rstrip.split.map(&:to_i)\n\ndistinct_arr = arr.uniq\ntmp = []\n\nif distinct_arr.size < k\n puts \"-1 -1\"\nelse\n k.times.each do |i|\n tmp.push(distinct_arr[i])\n end\n\n res = []\n max = tmp.max\n tmp.each do |v|\n if v == max\n res.push(arr.each_index.select { |i| arr[i] == v }.min)\n else\n res.push(arr.each_index.select { |i| arr[i] == v }.max)\n end\n end\n\n puts \"#{res.first + 1} #{res.last + 1}\"\nend\n"}, {"source_code": "n, k = gets.rstrip.split.map(&:to_i)\narr = gets.rstrip.split.map(&:to_i)\n\ndistinct_arr = arr.uniq\ntmp = []\n\nif distinct_arr.size < k\n puts \"-1 -1\"\nelse\n k.times.each do |i|\n tmp.push(distinct_arr[i])\n end\n\n last = arr.each_index.select { |i| arr[i] == tmp[-1] }.min\n first = arr.each_index.select { |i| arr[i] == tmp[0] && i < last }.max\n\n puts \"#{first.to_i + 1} #{last.to_i + 1}\"\nend\n"}, {"source_code": "n, k = gets.rstrip.split.map(&:to_i)\narr = gets.rstrip.split.map(&:to_i)\n\ndistinct_arr = arr.uniq\ntmp = []\n\nif distinct_arr.size < k\n puts \"-1 -1\"\nelse\n k.times.each do |i|\n tmp.push(distinct_arr[i])\n end\n\n res = []\n tmp.each do |v|\n if v == tmp[-1]\n res.push(arr.each_index.select { |i| arr[i] == v }.min)\n else\n res.push(arr.each_index.select { |i| arr[i] == v }.max)\n end\n end\n\n puts \"#{res.first + 1} #{res.last + 1}\"\nend\n"}, {"source_code": "require 'set'\nbuf = gets.split(' ')\nn = buf[0].to_i\nk = buf[1].to_i\nst = Set.new\nbuf = gets.split(' ')\n0.upto(n - 1) { |ii|\n i = buf[ii]\n st.add(i)\n if st.size == k \n print 1, \" \", ii + 1\n exit 0\n end\n}\nprint \"-1 -1\"\n"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nlist = gets.chomp.split.map(&:to_i)\n\ndef aaa(list, k)\n hash = Hash.new { |hash, key| hash[key] = 0 }\n for i in 0..(list.length - 1)\n hash[list[i]] += 1\n end\n\n if hash.keys.count < k\n return [-1, -1]\n else\n b = []\n for i in 0..(list.length - 1)\n b << [i, list[i]]\n\n if list[i] != list[i + 1]\n k = k - 1\n end\n\n if k == 0\n break\n end\n end\n b\n c = []\n d = []\n for i in 0..(b.length - 1)\n if b[i][1] == b[0][1]\n c << i\n end\n if b[i][1] == b[-1][1]\n d << i\n end\n end\n return [c.max + 1, d.min + 1]\n end\nend\n\nresult = aaa(list, k)\nresult.each do |i|\n print i\n print \" \" if i != result[-1]\nend\n"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nlist = gets.chomp.split.map(&:to_i)\n\ndef aaa(list, k)\n hash = Hash.new { |hash, key| hash[key] = 0 }\n for i in 0..(list.length - 1)\n hash[list[i]] += 1\n end\n\n if hash.keys.count < k\n \"-1 -1\"\n else\n b = []\n for i in 0..(list.length - 1)\n b << [i, list[i]]\n\n if list[i] != list[i + 1]\n k = k - 1\n end\n\n if k == 0\n break\n end\n end\n b\n c = []\n d = []\n for i in 0..(b.length - 1)\n if b[i][1] == b[0][1]\n c << i\n end\n if b[i][1] == b[-1][1]\n d << i\n end\n end\n \"#{c.max + 1} #{d.min + 1}\"\n end\nend\n\np aaa(list, k)\n"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nlist = gets.chomp.split.map(&:to_i)\n\ndef aaa(list, k)\n hash = Hash.new { |hash, key| hash[key] = 0 }\n for i in 0..(list.length - 1)\n hash[list[i]] += 1\n end\n\n if hash.keys.count < k\n return [-1, -1]\n else\n b = []\n for i in 0..(list.length - 1)\n b << [i, list[i]]\n\n if list[i] != list[i + 1]\n k = k - 1\n end\n\n if k == 0\n break\n end\n end\n b\n c = []\n d = []\n for i in 0..(b.length - 1)\n if b[i][1] == b[0][1]\n c << i\n end\n if b[i][1] == b[-1][1]\n d << i\n end\n end\n return [c.max + 1, d.min + 1]\n end\nend\n\nresult = aaa(list, k)\nresult.each.with_index do |element, index|\n print element\n print \" \" if index != result.length - 1\nend\n"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nlist = gets.chomp.split.map(&:to_i)\n\ndef aaa(list, k)\n hash = Hash.new { |hash, key| hash[key] = 0 }\n for i in 0..(list.length - 1)\n hash[list[i]] += 1\n end\n\n if hash.keys.count < k\n return [-1, -1]\n else\n b = []\n for i in 0..(list.length - 1)\n b << [i, list[i]]\n\n if list[i] != list[i + 1]\n k = k - 1\n end\n\n if k == 0\n break\n end\n end\n b\n c = []\n d = []\n for i in 0..(b.length - 1)\n if b[i][1] == b[0][1]\n c << i\n end\n if b[i][1] == b[-1][1]\n d << i\n end\n end\n return [c.max, d.min]\n end\nend\n\nresult = aaa(list, k)\nresult.each do |i|\n print i\n print \" \" if i != result[-1]\nend\n"}, {"source_code": "require 'set'\n\ndef good(ls,m,k)\n\n incr = Proc.new {|st,x| st[x].nil? ? (st[x] = 1) : (st[x] += 1) }\n decr = Proc.new {|st,x| st[x].nil? ? 0 : (st[x] == 1 ? (st.delete x) : (st[x] -= 1) ) }\n dis = Proc.new {|ls| st = {}; ls.each {|x| incr.(st,x) } ; st }\n\n l = ls.length - m - 1\n tk = ls.take(m)\n st = dis.(tk)\n cnt = st.size\n if cnt >= k\n return [true,0,tk]\n else\n (0..l).each do |i|\n tk.delete_at 0; tk.push(ls[m+i])\n incr.(st,ls[m+i])\n decr.(st,ls[i])\n if st.size >= k\n return [true,i+1,tk]\n end\n end\n end\n return [false]\nend\n\ndef doIt(n,k,ls)\n\n h = n\n l = [k - 1,0].max\n a = [false]\n while (h - l > 1)\n m = (h+l) / 2\n a = good(ls,m,k)\n if a.first\n h = m\n ls = a[2]\n else\n l = m\n end\n end\n a = good(ls,h,k)\n puts \"#{a[1]+1} #{a[1]+h}\" \n\nend\n\nxs = gets.split.map(&:to_i)\nn, k = xs[0], xs[1]\nls = gets.split.map(&:to_i)\n\nst = Set.new\n\nls.each {|x| st.add x}\n\nif st.size < k then\n puts \"-1 -1\" #cant be done\nelse\n doIt(n,k,ls)\nend"}, {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nl=0\nl+=1 while (l0)&&(r0)&&(r1 ? [-1,-1] : [1,1]) \t\n\texit\nend\nl=0\nl+=1 while (l0)&&(r0 ? [-1,-1] : [l+1,r+1]) "}, {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nl=0\nl+=1 while (l0)&&(r0)||(n==1) ? [-1,-1] : [l+1,r+1]) "}, {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nl=0\nl+=1 while (l0)&&(r0)&&(n==1) ? [-1,-1] : [l+1,r+1]) "}, {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nl=0\nl+=1 while (l0)&&(r0)||((n==1)&&(k>1)) ? [-1,-1] : [l+1,r+1]) "}, {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nif n==1\n\tputs \"%d %d\"%(k>1 ? [-1,-1] : [1,1]) \t\n\texit\nend\nl=0\nl+=1 while (l0)&&(r0 ? [-1,-1] : [l+1,r+1]) "}], "src_uid": "4b423274448ff3f0dee7644203706805"} {"source_code": "def run\n n = gets.chomp.to_i\n\n if n == 1\n puts \"0\"\n return\n end\n\n nc = n\n twos = 0\n while true\n if nc % 2 == 0\n nc /= 2\n twos += 1\n else\n break\n end\n end\n\n threes = 0\n while true\n if nc % 3 == 0\n nc /= 3\n threes += 1\n else\n break\n end\n end\n\n if nc != 1\n puts \"-1\"\n return\n end\n\n if threes >= twos\n puts threes + threes - twos\n else\n puts \"-1\"\n end\nend\n\n\ndef main\n t = gets.chomp.to_i\n\n t.times do\n run\n end\nend\n\nmain\n", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n ans = 0\n while n % 6 == 0 or (n != 1 and n.odd?) do\n ans += 1\n n = if n % 6 == 0 then n / 6 else n * 2 end\n end\n puts -1 if n != 1\n puts ans if n == 1\nend\n\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n\n d3 = 0\n while n.modulo(3).zero?\n n /= 3\n d3 += 1\n end\n\n d2 = 0\n while n.modulo(2).zero?\n n /= 2\n d2 += 1\n end\n\n if n > 1 || d2 > d3\n puts -1\n next\n end\n\n puts (d3 - d2) + d3\nend\n"}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\tcnt2, cnt3 = 0, 0\n\twhile n % 2 == 0\n\t\tn /= 2\n\t\tcnt2 += 1\n\tend\n\twhile n % 3 == 0\n\t\tn /= 3\n\t\tcnt3 += 1\n\tend\n\tif n == 1 && cnt2 <= cnt3\n\t\tputs (cnt3 - cnt2) + cnt3\n\telse\n\t\tputs -1\n\tend\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n\tn = gets.to_i\n\tdiv2 = 0\n\tdiv3 = 0\n\twhile (n & 1) == 0\n\t\tdiv2 += 1\n\t\tn >>= 1\n\tend\n\twhile (n % 3) == 0\n\t\tdiv3 += 1\n\t\tn /= 3\n\tend\n\tif n != 1 or div2 > div3\n\t\tputs \"-1\"\n\telse\n\t\tp div3*2 - div2\n\tend\nend\n"}], "negative_code": [], "src_uid": "3ae468c425c7b156983414372fd35ab8"} {"source_code": "t = gets.chomp.to_i\n(0...t).each do |_|\n l = \"*#{gets.chomp}*\"\n # puts l\n d, c = 0, 0\n (0...l.size).each do |i| \n (c+=1; next) if i.zero?\n if l[i] == 'R'\n d = [d, c].max\n c = 0\n elsif l[i] == '*'\n d = [d, c].max\n end\n c+=1\n end\n puts d\nend\n", "positive_code": [{"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n # L R\n # | 0 | | 1 | | 2 | ............ | n | | n+1 |\n # frog\n # ------------>\n # jump by [1, d] size, you can choose 1 for the smallest one\n # minimize size 'd'\n # range of d, min = 1 'RRR...RRRR', max = n+1 'LLL...LLL'\n # every sequence has a solution.\n\n # find the longest sequence of 'L' and + 1 to reach 'R' again\n max_l, l = 0, 0\n gets.chomp.split(//).each { |c|\n if c == 'R'\n if max_l < l\n max_l = l\n end\n l = 0\n else\n l += 1\n end\n }\n\n if max_l < l\n max_l = l # clean up\n end\n\n puts max_l + 1\n}"}, {"source_code": "tc = gets.to_i \n\ntc.times do \n s1 = gets.chomp \n s = \"R\" + s1 + \"R\" \n maxi = -1 \n prev = 0 \n l = s.size \n (1...l).each do |i| \n if(s[i] == 'R') \n now = i - prev \n maxi = [maxi,now].max\n prev = i \n end\n end\n puts maxi\nend"}, {"source_code": "t = gets.to_i\nt.times do\n s = gets.chomp\n run_len = 0\n max_run_len = 0\n s.each_char do |c|\n case c\n when \"L\"\n run_len += 1\n when \"R\"\n max_run_len = run_len if max_run_len < run_len\n run_len = 0\n end\n end\n max_run_len = run_len if max_run_len < run_len\n puts max_run_len + 1\nend\n"}], "negative_code": [], "src_uid": "6451507b21854d5b81aeaf0491ddf584"} {"source_code": "# Warning: This code sucks.\n\nrequire \"set\"\n\nn, m = gets.split.map(&:to_i)\n\naijs = n.times.map do\n gets.split.map(&:to_i).drop(1)\nend\n\ngroups = []\naijs.each_with_index do |ai, i|\n groups[i] = Set.new ai\nend\n\nknow_nothing = groups.select(&:empty?).count\n\nloop do\n new = []\n 0.upto(groups.size - 1) do |i|\n found = false\n 0.upto(new.size - 1) do |j|\n if (groups[i] & new[j]).any?\n new[j] += groups[i]\n found = true\n break\n end\n end\n if !found\n new << groups[i]\n end\n end\n break if new == groups\n groups = new\nend\n\nans = groups.count - 1\nif know_nothing == groups.count\n ans += 1\nend\np ans", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\n$list = Array.new(n)\nclass Emp\n attr_reader :lang, :group, :edge\n def initialize(lang)\n @lang = lang\n @group = nil\n\t@edge = Array.new\n end #def init\n \n def edgeplus(n)\n @edge << n\n end #def edge\n \n def search(g)\n @group = g\n for i in @edge\n\t if $list[i].group == nil\n\t $list[i].search(g)\n\t end\n\tend\n end #def search\nend #class\n\nallnone = true\nfor i in 0...n\n lang = gets.split.map(&:to_i).drop(1)\n $list[i] = Emp.new(lang)\n if lang.count > 0 then allnone = false end\n for j in 0...i\n if ($list[i].lang & $list[j].lang).count > 0\n\t $list[j].edgeplus(i)\n\t $list[i].edgeplus(j)\n\tend\n end\nend\n\ng = 0\nfor i in 0...n\n if $list[i].group == nil\n $list[i].search(g)\n\tg += 1\n end\nend\n\nif !allnone then g -= 1 end\nputs g"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn, m = STDIN.readline.split.collect {|s| s.to_i }\nseen = (m+1).times.collect { false }\nconnected = (m+1).times.collect { {} }\n\nmute_count = 0\n\nn.times do\n\tas = STDIN.readline.split.collect {|s| s.to_i }\n\tcount = as.shift\n\tif count == 0\n\t\tmute_count += 1\n\t\tnext\n\tend\n\tas.length.times do |i|\n\t\tu = as[i]\n\t\tseen[u] = true\n\t\t(i..as.length-1).each do |j|\n\t\t\tv = as[j]\n\t\t\tconnected[u][v] = true\n\t\t\tconnected[v][u] = true\n\t\tend\n\tend\nend\n\n\nmarked = (m+1).times.collect { false }\ncomponent_count = 0\n\ndef explore(u, marked, connected)\n\tmarked[u] = true\n\tconnected[u].keys.each do |v|\n\t\tnext if marked[v]\n\t\texplore(v, marked, connected)\n\tend\nend\n\n(1..m).each do |start|\n\tnext if marked[start] or not seen[start]\n\tcomponent_count += 1\n\texplore(start, marked, connected)\nend\n\nputs [component_count-1, 0].max + mute_count\n"}, {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nm = Integer(input[1])\nlang = []\nfor i in 0...n\n lang[i] = []\n lang[i] = gets.chomp.split.map{|j| Integer(j)}\nend\npointer = 0\nfor i in 0...n\n if lang[i] != [0]\n pointer = 1\n break\n end\nend\nfor i in 0...n\n lang[i].shift\nend\nboolean = []\nmatch = []\nfor i in 0...n\n boolean[i] = []\n for j in 0...n\n match = (lang[i] & lang[j]).length\n if match == 0\n boolean[i].push(false)\n else\n boolean[i].push(true)\n end\n end\nend\n\ndef fill_unit point, unit_id, unit, n, boolean\n if unit[point]\n return\n end\n\n unit[point] = unit_id\n for i in 0...n\n if boolean[point][i]\n fill_unit(i, unit_id, unit, n, boolean)\n end\n end\nend\n\nunit = Array.new(n)\nfor i in 0...n\n fill_unit(i, i, unit, n, boolean)\nend\n\nunit.uniq!\nif pointer == 0\n puts lang.length\nelse\n puts unit.length - 1\nend"}, {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nm = Integer(input[1])\nlang = []\nfor i in 0...n\n lang[i] = []\n lang[i] = gets.chomp.split.map{|j| Integer(j)}\nend\npointer = 0\nfor i in 0...n\n if lang[i] != [0]\n pointer = 1\n break\n end\nend\nunit = []\nfor i in 0...n\n lang[i].shift\n unit.push(i)\nend\nboolean = []\nmatch = []\nfor i in 0...n\n boolean[i] = []\n for j in 0...n\n match = (lang[i] & lang[j]).length\n if match == 0\n boolean[i].push(false)\n else\n boolean[i].push(true)\n end\n end\nend\n\nfor i in 0...n\n for j in 0..i\n if boolean[i][j]\n m = unit[j]\n for k in 0...n\n if unit[k] == m\n unit[k] = i\n end\n end\n end\n end\nend\nunit.uniq!\nif pointer == 0\n puts lang.length\nelse\n puts unit.length - 1\nend"}, {"source_code": "n,m=gets.split.map(&:to_i)\na=[]\nn.times do\n k=0\n gets.split.map(&:to_i)[1..-1].each do |v|\n k+=(1<<(v-1))\n end\n a<=0 then\n for j in i+1..n-1 do\n if a[j]>=0 and (a[i]&a[j])>0 then\n a[i]|=a[j]\n a[j]=-1\n changed=true\n end\n end\n end\n end\nend\n\nz=res=0\na.each do |v|\n res+=1 if v>=0\n z+=1 if v==0\nend\nputs z==n ? n : res-1\n"}, {"source_code": "n, m = gets.split(' ').collect!{|i| i.to_i}\n\nk = []\nn.times do |j|\n\tk[j] = gets.split(' ').collect!{|i| i.to_i}\nend\n\nneedtolearn = 0\n\n@mygroups = []\n\ndef checkinclude(int)\n\t@mygroups.each_index do |i|\n\t\treturn i if @mygroups[i].include?(int)\n\tend\n\treturn false\nend\n\nk.each do |line|\n\tif line[0] == 0\n\t\tneedtolearn += 1\n\telse\n\t\tfound = false\n\t\tline[1..-1].each do |lang|\n\t\t\tif grn = checkinclude(lang)\n\t\t\t\t@mygroups[grn] = @mygroups[grn] | line[1..-1]\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tif !found\n\t\t\t@mygroups << line[1..-1]\n\t\tend\n\tend\nend\n\nsize = @mygroups.size\nsize.times do |i|\n\tsize.times do |j|\n\t\tif i != j && !(@mygroups[i] & @mygroups[j]).empty?\n\t\t\t@mygroups[i] = @mygroups[i] | @mygroups[j]\n\t\t\t@mygroups[j] = []\n\t\tend\n\tend\nend\n\n@mygroups.delete_if {|x| x.empty? }\n\nlearning = (@mygroups.size - 1)\nlearning = 0 if learning < 0\n\np needtolearn + learning\n"}, {"source_code": "# Warning: This code sucks.\n\nrequire \"set\"\n\nn, m = gets.split.map(&:to_i)\n\naijs = n.times.map do\n gets.split.map(&:to_i).drop(1)\nend\n\ngroups = []\naijs.each_with_index do |ai, i|\n groups[i] = Set.new ai\nend\n\nknow_nothing = groups.select(&:empty?).count\n\nloop do\n new = []\n 0.upto(groups.size - 1) do |i|\n found = false\n 0.upto(new.size - 1) do |j|\n if (groups[i] & new[j]).any?\n new[j] += groups[i]\n found = true\n break\n end\n end\n if !found\n new << groups[i]\n end\n end\n break if new == groups\n groups = new\nend\n\nans = groups.count - 1\nif know_nothing == groups.count\n ans += 1\nend\np ans"}, {"source_code": "class Node\n\tattr_accessor :id, :visited, :links, :exists\n\tdef initialize id\n\t @exists = true\n\t\t@id = id\n\t\t@visited = false\n\t\t@links = []\n\tend\n\tdef visit nodes\n\t\tif !@visited\n\t\t\t@visited = true\n\t\t\t@links.each { |l|\n\t\t\t\tnodes[l-1].visit nodes\n\t\t\t}\n\t\tend\n\tend\nend\n\n\nn,m = gets.split(\" \").collect! {|x| x.to_i}\nnodes = [0]*n\ngraph = [0]*n\n(1..n).each {|v|\n\tnode = Node.new v\n\tnodes[v-1] = node\n\tgraph[v-1] = node\n}\nzero_list = [0]*m\nzeros = 0\narrs = []\n(1..n).each { |k|\narr = gets.split(\" \").collect! {|x| x.to_i}\narr = arr[1..-1]\nif arr.size == 0\n\tzeros += 1\n nodes[k-1].exists = false\t\nend\narrs.push arr \n}\n\n(1..n).each { |s|\n (s+1..n).each { |t|\n\tif (arrs[s-1]&arrs[t-1]).size>0\n\t\tnodes[s-1].links.push t\n\t\tnodes[t-1].links.push s\n\tend\n }\n}\n\n\ngraph = graph.keep_if {|x| x.exists==true}\nsize = graph.size\ngroups = -1\np = 0\nwhile p 0\n\t $list[j].edgeplus(i)\n\t $list[i].edgeplus(j)\n\tend\n end\nend\n\ng = 0\nfor i in 0...n\n if $list[i].group == nil\n $list[i].search(g)\n\tg += 1\n end\nend\n\nputs g-1"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn, m = STDIN.readline.split.collect {|s| s.to_i }\nseen = (m+1).times.collect { false }\nconnected = (m+1).times.collect { {} }\n\nmute_count = 0\n\nn.times do\n\tas = STDIN.readline.split.collect {|s| s.to_i }\n\tcount = as.shift\n\tif count == 0\n\t\tmute_count += 1\n\t\tnext\n\tend\n\tas.length.times do |i|\n\t\tu = as[i]\n\t\tseen[u] = true\n\t\t(i..as.length-1).each do |j|\n\t\t\tv = as[j]\n\t\t\tconnected[u][v] = true\n\t\t\tconnected[v][u] = true\n\t\tend\n\tend\nend\n\n(1..m).each {|u| puts '%d: %s' % [u, connected[u].keys] }\n\nmarked = (m+1).times.collect { false }\ncomponent_count = 0\n\ndef explore(u, marked, connected)\n\tmarked[u] = true\n\tconnected[u].keys.each do |v|\n\t\tnext if marked[v]\n\t\texplore(v, marked, connected)\n\tend\nend\n\n(1..m).each do |start|\n\tnext if marked[start] or not seen[start]\n\tcomponent_count += 1\n\texplore(start, marked, connected)\nend\n\nputs '%d components, %d mute' % [component_count, mute_count]\nputs component_count-1 + mute_count\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn, m = STDIN.readline.split.collect {|s| s.to_i }\nseen = (m+1).times.collect { false }\nconnected = (m+1).times.collect { {} }\n\nmute_count = 0\n\nn.times do\n\tas = STDIN.readline.split.collect {|s| s.to_i }\n\tcount = as.shift\n\tif count == 0\n\t\tmute_count += 1\n\t\tnext\n\tend\n\tas.length.times do |i|\n\t\tu = as[i]\n\t\tseen[u] = true\n\t\t(i..as.length-1).each do |j|\n\t\t\tv = as[j]\n\t\t\tconnected[u][v] = true\n\t\t\tconnected[v][u] = true\n\t\tend\n\tend\nend\n\n\nmarked = (m+1).times.collect { false }\ncomponent_count = 0\n\ndef explore(u, marked, connected)\n\tmarked[u] = true\n\tconnected[u].keys.each do |v|\n\t\tnext if marked[v]\n\t\texplore(v, marked, connected)\n\tend\nend\n\n(1..m).each do |start|\n\tnext if marked[start] or not seen[start]\n\tcomponent_count += 1\n\texplore(start, marked, connected)\nend\n\nputs component_count-1 + mute_count\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\na=[]\nn.times do\n k=0\n gets.split.map(&:to_i)[1..-1].each do |v|\n k+=(1<<(v-1))\n end\n a<=0 then\n for j in i+1..n-1 do\n if a[j]>=0 and (a[i]&a[j])>0 then\n a[i]|=a[j]\n a[j]=-1\n changed=true\n end\n end\n end\n end\nend\n\nres=0\na.each do |v|\n res+=1 if v>=0\nend\nputs res==n ? n : res-1\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\na=[]\nb=[]\nn.times do\n k=0\n gets.split.map(&:to_i)[1..-1].each do |v|\n k+=(1<<(v-1))\n end\n a<0 then\n for j in i+1..n-1 do\n if b[j]>0 and (a[i]&a[j])>0 then\n b[j]=0\n a[i]|=a[j]\n a[j]=a[i]\n changed=true\n break\n end\n break if changed\n end\n end\n break if changed\n end\nend\n\nres=0\nb.each do |v|\n res+=v\nend\nputs res-1\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\na=[]\nn.times do\n k=0\n gets.split.map(&:to_i)[1..-1].each do |v|\n k+=(1<<(v-1))\n end\n a<=0 then\n for j in i+1..n-1 do\n if a[j]>=0 and (a[i]&a[j])>0 then\n a[i]|=a[j]\n a[j]=-1\n changed=true\n end\n end\n end\n end\nend\n\nres=0\na.each do |v|\n res+=1 if v>=0\nend\nputs res-1\n"}, {"source_code": "n, m = gets.split(' ').collect!{|i| i.to_i}\n\nk = []\nn.times do |j|\n\tk[j] = gets.split(' ').collect!{|i| i.to_i}\nend\n\nlangs = Array.new(101, 0)\nneedtolearn = 0\nknownlangs = []\n\nk.each do |sot|\n\tif sot[0] > 0\n\t\t(1..sot[0]).each do |i|\n\t\t\tlangs[sot[i]] += 1\n\n\t\t\tknownlangs << sot[i] if !knownlangs.include?(sot[i])\n\t\tend\n\telse\n\t\tneedtolearn += 1\n\tend\nend\n\nlanmap = {}\n\nlangs.each_index do |lan|\n\t# needtolearn += 1 if lan == 1\n\n\tif langs[lan] > 0\n\t\tlanmap[lan] = {} if !lanmap[lan]\n\t\tknownlangs.each do |kn|\n\t\t\tlanmap[lan][kn] = false if kn != lan\n\t\tend\n\tend\nend\n\n\nknownlangs.each do |kn|\n\tmylangs = [kn]\n\tk.each do |sot|\n\t\tif sot[0] > 0\n\t\t\t(1..sot[0]).each do |i|\n\t\t\t\tmylangs << sot[i] if sot[1..-1].include?(kn) && !mylangs.include?(sot[i])\n\n\t\t\t\t# lanmap[kn][sot[i]] = true if sot[1..-1].include?(kn)\n\t\t\tend\n\t\tend\n\tend\n\n\tmylangs.each do |ln1|\n\t\tmylangs.each do |ln2|\n\t\t\tlanmap[ln1][ln2] = true\n\t\tend\n\tend\nend\n\nallok = false\nlearning = 0\n\nwhile !allok\n\tknownlangs[1..-1].each do |lan2|\n\t\tif lanmap[knownlangs[0]][lan2] == false\n\t\t\tp lan2\n\t\t\tlearning += 1\n\t\t\tlanmap[lan2].each_key do |lan3|\n\t\t\t\tlanmap[knownlangs[0]][lan3] = true if lanmap[lan2][lan3]\n\t\t\tend\n\t\tend\n\t\tallok = true if lan2 == knownlangs[-1]\n\tend\nend\n\np lanmap"}, {"source_code": "n, m = gets.split(' ').collect!{|i| i.to_i}\n\nk = []\nn.times do |j|\n\tk[j] = gets.split(' ').collect!{|i| i.to_i}\nend\n\nlangs = Array.new(101, 0)\nneedtolearn = 0\n\n@mygroups = []\n\ndef checkinclude(int)\n\t@mygroups.each_index do |i|\n\t\treturn i if @mygroups[i].include?(int)\n\tend\n\treturn false\nend\n\nk.each do |line|\n\tif line[0] == 0\n\t\tneedtolearn += 1\n\telse\n\t\tfound = false\n\t\tline[1..-1].each do |lang|\n\t\t\tif grn = checkinclude(lang)\n\t\t\t\t# p grn\n\t\t\t\t# p @mygroups[grn].to_s\n\t\t\t\t# p line[1..-1].to_s\n\t\t\t\t@mygroups[grn] = @mygroups[grn] | line[1..-1]\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tif !found\n\t\t\t@mygroups << line[1..-1]\n\t\tend\n\tend\nend\n\nsize = @mygroups.size\nsize.times do |i|\n\tsize.times do |j|\n\t\tif i != j && !(@mygroups[i] & @mygroups[j]).empty?\n\t\t\t@mygroups[i] = @mygroups[i] | @mygroups[j]\n\t\t\t@mygroups[j] = []\n\t\tend\n\tend\nend\n\n@mygroups.delete_if {|x| x.empty? }\n\np needtolearn + (@mygroups.size - 1)\n# p needtolearn \n# p @mygroups.to_s"}, {"source_code": "# Warning: This code sucks.\n\nrequire \"set\"\n\nn, m = gets.split.map(&:to_i)\n\naijs = n.times.map do\n gets.split.map(&:to_i).drop(1)\nend\n\ngroups = []\naijs.each_with_index do |ai, i|\n groups[i] = Set.new ai\nend\n\nknow_nothing = groups.select(&:empty?).count\n\nloop do\n new = []\n 0.upto(groups.size - 1) do |i|\n found = false\n 0.upto(new.size - 1) do |j|\n if (groups[i] & new[j]).any?\n new[j] += groups[i]\n found = true\n break\n end\n end\n if !found\n new << groups[i]\n end\n end\n break if new == groups\n groups = new\nend\n\nans = groups.count - 1\nif know_nothing > 0\n ans += 1\nend\np ans"}, {"source_code": "# Warning: This code sucks.\n\nrequire \"set\"\n\nn, m = gets.split.map(&:to_i)\n\naijs = n.times.map do\n gets.split.map(&:to_i).drop(1)\nend\n\ngroups = []\naijs.each_with_index do |ai, i|\n groups[i] = Set.new ai\nend\n\nknow_nothing = groups.select(&:empty?).count\n\nloop do\n new = []\n 0.upto(groups.size - 1) do |i|\n found = false\n 0.upto(new.size - 1) do |j|\n if (groups[i] & new[j]).any?\n new[j] += groups[i]\n found = true\n break\n end\n end\n if !found\n new << groups[i]\n end\n end\n break if new == groups\n groups = new\nend\n\nans = groups.count - 1\nif know_nothing > 1\n ans += 1\nend\np ans"}, {"source_code": "# Warning: This code sucks.\n\nrequire \"set\"\n\nn, m = gets.split.map(&:to_i)\n\naijs = n.times.map do\n gets.split.map(&:to_i).drop(1)\nend\n\ngroups = []\naijs.each_with_index do |ai, i|\n groups[i] = Set.new ai\nend\n\nloop do\n new = []\n 0.upto(groups.size - 1) do |i|\n found = false\n 0.upto(new.size - 1) do |j|\n if (groups[i] & new[j]).any?\n new[j] += groups[i]\n found = true\n break\n end\n end\n if !found\n new << groups[i]\n end\n end\n break if new == groups\n groups = new\nend\n\np groups.count - 1"}, {"source_code": "class Node\n\tattr_accessor :id, :visited, :links\n\tdef initialize id\n\t\t@id = id\n\t\t@visited = false\n\t\t@links = []\n\tend\n\tdef visit nodes\n\t\tif !@visited\n\t\t\t@visited = true\n\t\t\t@links.each { |l|\n\t\t\t\tnodes[l-1].visit nodes\n\t\t\t}\n\t\tend\n\tend\nend\n\n\nn,m = gets.split(\" \").collect! {|x| x.to_i}\nnodes = [0]*n\n(1..n).each {|v|\n\tnodes[v-1] = Node.new v\n}\nzero_list = [0]*m\nzeros = 0\narrs = []\n(1..n).each {\narr = gets.split(\" \").collect! {|x| x.to_i}\narr = arr[1..-1]\nif arr.size == 0\n\tzeros += 1 \nend\narrs.push arr \n}\n\n(1..n).each { |s|\n (s+1..n).each { |t|\n\tif (arrs[s-1]&arrs[t-1]).size>0\n\t\tnodes[s-1].links.push t\n\t\tnodes[t-1].links.push s\n\tend\n }\n}\n\ngroups = -1\np = 0\nwhile p ans\n ans = [md[i], fd[i]].min\n end\nend\nputs ans*2\n"}, {"source_code": "n = gets.chomp.to_i\ngs = []\nas = []\nbs = []\nn.times do\n g, a, b = gets.chomp.split.map { |x| x =~ /[MF]/ ? x : x.to_i }\n gs << g\n as << a\n bs << b\nend\n\nans = 0\nfor d in 1..366\n m = 0\n f = 0\n for i in 0...n\n if gs[i] == 'M'\n m += 1 if as[i] <= d && d <= bs[i]\n else\n f += 1 if as[i] <= d && d <= bs[i]\n end\n end\n ans = [ans, [m, f].min * 2].max\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\nms = []\nfs = []\nfor i in 0...n\n g, s, e = gets.split(' ')\n s = s.to_i\n e = e.to_i\n\n for j in s..e\n if g == 'M'\n ms[j] ||= 0\n ms[j] += 1\n else\n fs[j] ||= 0\n fs[j] += 1\n end\n end\nend\n\n\nmaxatt = 0\nmaxi = 0\nfor i in 1..366\n att = [ms[i].to_i, fs[i].to_i].min\n if att > maxatt\n maxatt = att\n maxi = i\n end\nend \n\nputs maxatt*2"}, {"source_code": "n = gets.to_i\na = Array.new(367)\nn.times do\n g, b, e = gets.split\n (b.to_i..e.to_i).each do |i|\n a[i] ||= []\n a[i] << g\n end\nend\nb = a.map do |suba|\n if suba.nil?\n 0\n else\n f, m = 0, 0\n suba.each do |x|\n if x == 'F'\n f += 1\n elsif x == 'M'\n m += 1\n end\n end\n [f, m].min\n end\nend\nputs b.max * 2\n"}], "negative_code": [], "src_uid": "75d500bad37fbd2c5456a942bde09cd3"} {"source_code": "\nclass MemManager\n\n EMPTY = 0\n\n def initialize(size)\n @size = size\n @mem = Array.new(size, EMPTY)\n @id = 1\n @used_ids = {}\n end\n\n def get_mem\n @mem.to_s\n end\n\n # returns block id or 0 if cannot alloc block\n def alloc(len)\n ind = find_empty_block(len)\n if ind >= 0\n fill_block(ind, len, @id)\n @used_ids[@id] = [ind, len]\n @id += 1\n return @id - 1\n end\n 0\n end\n\n def erase(id)\n if @used_ids[id]\n ind, len = @used_ids[id]\n fill_block(ind, len, EMPTY)\n @used_ids.delete(id)\n #p @used_ids\n return true\n end\n false\n end\n\n def defrag\n # get keys in order they are in mem\n keys = @mem.uniq\n keys.delete(0)\n # move 0-s to the end of @mem\n @mem = @mem.delete_if {|x| x == 0}\n @mem << 0 while @mem.size < @size\n # relocate @used_ids\n cur_ind = 0\n keys.each do |id|\n ind, len = @used_ids[id]\n ind = cur_ind\n cur_ind += len\n @used_ids[id] = [ind, len]\n end\n end\n\nprivate\n\n # returns -1 if cannot find empty block of length n\n def find_empty_block(n)\n start = 0\n while start <= @size - n\n if @mem[start] != EMPTY\n start += 1\n next\n end\n i = 0\n while @mem[start + i] == EMPTY\n i += 1\n end\n return start if i >= n\n start += i\n end\n -1\n end\n\n def fill_block(ind, len, value)\n @mem.fill(value, ind, len)\n end\nend\n\n\nif __FILE__ == $0\n t, m = gets.split.collect {|x| Integer(x)}\n mm = MemManager.new(m)\n while line = gets\n line.chomp!\n if line.start_with?('alloc')\n a = line.scan(/\\d+/)\n n = Integer(a[0])\n id = mm.alloc(n)\n puts (id == 0) ? \"NULL\" : id\n elsif line.start_with?('erase')\n a = line.scan(/\\d+/)\n n = Integer(a[0])\n puts \"ILLEGAL_ERASE_ARGUMENT\" unless mm.erase(n)\n elsif line.start_with?('defragment')\n mm.defrag\n end\n end\nend\n", "positive_code": [{"source_code": "input = gets.chomp.split.map do |x|\n Integer(x)\nend\n\nn = input[0]\nm = input[1]\n\nmemory = Array.new(m) { |i| 0 }\nnext_id = 1\n\ndef find_and_fill_block(memory, len, next_id)\n head = 0\n for i in 0...memory.length\n if head <= i - len\n break \n end\n\n if memory[i] != 0\n head = i + 1 \n end\n end\n if head + len <= memory.length\n for i in 0...len\n memory[head + i] = next_id\n end\n return true\n end\n\n return false\nend\n\ndef erase_block(memory, id)\n flag = false\n for i in 0...memory.length\n if memory[i] == id\n memory[i] = 0\n flag = true\n end\n end\n\n return flag\nend\n\ndef defragment(memory)\n j = 0\n for i in 0...memory.length\n if memory[i] != 0\n memory[j] = memory[i]\n j += 1\n end\n end\n for i in j...memory.length\n memory[i] = 0\n end\nend\n\nfor i in 0...n\n input = gets.chomp.split\n command = input[0]\n if command[0] == 'a'\n len = Integer(input[1])\n ret = find_and_fill_block(memory, len, next_id)\n if ret\n puts next_id\n next_id += 1\n else\n puts \"NULL\"\n end\n elsif command[0] == 'e'\n cur_id = Integer(input[1])\n ret = cur_id != 0 && erase_block(memory, cur_id)\n if !ret\n puts \"ILLEGAL_ERASE_ARGUMENT\"\n end\n else\n defragment(memory)\n end\nend\n"}, {"source_code": "\ndata = gets.chomp.split\nt = Integer(data[0])\nw = Integer(data[1])\ntask = []\nfor i in 0...t\n task[i] = gets.chomp\nend\n\nmemory = []\nfor i in 0...w\n memory[i] = 0\nend\n\ndef getInt(string)\n string = string.split\n integer = Integer(string[1])\n return integer\nend\ndef allocate(amount, array)\n success = false\n endIndex = 0\n count = 0\n if amount == 1\n for i in 0...array.length\n if array[i] == 0\n endIndex = i - 1\n success = true\n break\n end\n end\n else\n if array.length > 1\n for i in 0...array.length - 1\n if array[i] == array[i + 1] && array[i] == 0\n count += 1\n else\n if count + 1 >= amount\n endIndex = i\n success = true\n break\n else\n count = 0\n end\n end\n if count + 1 >= amount\n endIndex = i\n success = true\n break\n end\n end\n else\n if amount == 1 && array.length == 1\n if array[0] == 0\n array[0] = 1\n success = true\n endIndex = -1\n end\n end\n end\n end\n if success\n return endIndex\n else\n return \"NULL\"\n end\nend\n\n\ndef erase(identifier, array)\n for i in 0...array.length\n if array[i] == identifier\n array[i] = 0\n end\n end \n return array \nend\n\ndef defragment(array)\n count = 0\n i = 0\n while i <= array.length\n if array[i] == 0\n array.delete_at(i)\n count += 1\n else\n i += 1\n end\n end\n count.times{ array.push(0)}\n return array\nend\n\ncast = Hash.new\nkey = 0\nfor i in 0...t \n if task[i][0] == \"a\"\n int = getInt(task[i])\n endIndex = allocate(int, memory)\n if endIndex == \"NULL\"\n puts \"NULL\"\n else\n key += 1\n cast[key] = int\n for i in endIndex - int + 2..endIndex + 1\n memory[i] = key\n end\n puts key\n end\n elsif task[i][0] == \"e\"\n int = getInt(task[i])\n if int <= key && int > 0\n value = cast[int]\n if value != nil\n memory = erase(int, memory)\n cast.delete(int)\n else\n puts \"ILLEGAL_ERASE_ARGUMENT\"\n end\n else\n puts \"ILLEGAL_ERASE_ARGUMENT\"\n end\n else\n memory = defragment(memory)\n end\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nidentifiers = {}\nmemory_blocks = {}\nidentifier = 1\n\nn.times do\n\tcommand = gets.split(' ')\t\n\tcase command[0]\n\t\twhen \"alloc\"\n\t\t\tstart_index = 0\n\t\t\tblock_size = command[1].to_i\n\t\t\tfit = false\n\t\t\twhile memory_blocks[start_index]\n\t\t\t\tstart_index += memory_blocks[start_index]\n\t\t\tend\n\t\t\twhile start_index + block_size <= m \n\t\t\t\tbreak if block_size == m && !memory_blocks.empty?\n\t\t\t\tcheck = memory_blocks.select { |k, v| (k < start_index + block_size) && (k >= start_index) }\n\t\t\t\tif check.empty?\n\t\t\t\t\tmemory_blocks[start_index] = block_size\n\t\t\t\t\tidentifiers[identifier] = start_index\n\t\t\t\t\tputs identifier\n\t\t\t\t\tidentifier += 1\n\t\t\t\t\tfit = true\n\t\t\t\t\t# puts \"memory_blocks is #{memory_blocks}\"\n\t\t\t\t\t# puts \"identifiers is #{identifiers}\"\n\t\t\t\t\tbreak\n\t\t\t\telse\n\t\t\t\t\tnext_index = check.min\n\t\t\t\t\tstart_index = next_index[0] + memory_blocks[next_index[0]]\n\t\t\t\tend\n\t\t\tend\n\t\t\tputs \"NULL\" unless fit\n\t\twhen \"erase\"\n\t\t\td_iden = command[1].to_i\n\t\t\tiden_index = identifiers[d_iden]\n\t\t\tif iden_index.nil?\n\t\t\t\tputs \"ILLEGAL_ERASE_ARGUMENT\"\n\t\t\telse\n\t\t\t\tidentifiers.delete(d_iden)\n\t\t\t\tmemory_blocks.delete(iden_index)\n\t\t\t\t# puts \"memory_blocks is #{memory_blocks}\"\n\t\t\t\t# puts \"identifiers is #{identifiers}\"\n\t\t\tend\n\t\telse # defragment\n\t\t\tstart_index = 0\n\t\t\tcopy = {}\n\t\t\tmemory_blocks.size.times do\n\t\t\t\tlowest = memory_blocks.min\n\t\t\t\tcopy[start_index] = lowest[1]\n\t\t\t\tidentifiers[identifiers.key(lowest[0])] = start_index\n\t\t\t\tstart_index += lowest[1]\n\t\t\t\tmemory_blocks.delete(lowest[0])\n\t\t\tend\n\t\t\tmemory_blocks = copy\n\t\t\t# puts \"memory_blocks is #{memory_blocks}\"\n\t\t\t# puts \"identifiers is #{identifiers}\"\n\t\tend\nend\n"}], "negative_code": [{"source_code": "input = gets.chomp.split.map do |x|\n Integer(x)\nend\n\nn = input[0]\nm = input[1]\n\nmemory = Array.new(m) { |i| 0 }\nnext_id = 1\n\ndef find_and_fill_block(memory, len, next_id)\n head = 0\n for i in 0...memory.length\n if head <= i - len\n break \n end\n\n if memory[i] != 0\n head = i + 1 \n end\n end\n if head + len <= memory.length\n for i in 0...len\n memory[head + i] = next_id\n end\n return true\n end\n\n return false\nend\n\ndef erase_block(memory, id)\n flag = false\n for i in 0...memory.length\n if memory[i] == id\n memory[i] = 0\n flag = true\n end\n end\n\n return flag\nend\n\ndef defragment(memory)\n j = 0\n for i in 0...memory.length\n if memory[i] != 0\n memory[j] = memory[i]\n j += 1\n end\n end\n for i in j...memory.length\n memory[i] = 0\n end\nend\n\nfor i in 0...n\n input = gets.chomp.split\n command = input[0]\n if command[0] == 'a'\n len = Integer(input[1])\n ret = find_and_fill_block(memory, len, next_id)\n if ret\n puts next_id\n next_id += 1\n else\n puts \"NULL\"\n end\n elsif command[0] == 'e'\n cur_id = Integer(input[1])\n ret = erase_block(memory, cur_id)\n if !ret\n puts \"ILLEGAL_ERASE_ARGUMENT\"\n end\n else\n defragment(memory)\n end\n puts memory\nend\n"}, {"source_code": "input = gets.chomp.split.map do |x|\n Integer(x)\nend\n\nn = input[0]\nm = input[1]\n\nmemory = Array.new(m) { |i| 0 }\nnext_id = 1\n\ndef find_and_fill_block(memory, len, next_id)\n head = 0\n for i in 0...memory.length\n if head <= i - len\n break \n end\n\n if memory[i] != 0\n head = i + 1 \n end\n end\n if head + len <= memory.length\n for i in 0...len\n memory[head + i] = next_id\n end\n return true\n end\n\n return false\nend\n\ndef erase_block(memory, id)\n flag = false\n for i in 0...memory.length\n if memory[i] == id\n memory[i] = 0\n flag = true\n end\n end\n\n return flag\nend\n\ndef defragment(memory)\n j = 0\n for i in 0...memory.length\n if memory[i] != 0\n memory[j] = memory[i]\n j += 1\n end\n end\n for i in j...memory.length\n memory[i] = 0\n end\nend\n\nfor i in 0...n\n input = gets.chomp.split\n command = input[0]\n if command[0] == 'a'\n len = Integer(input[1])\n ret = find_and_fill_block(memory, len, next_id)\n if ret\n puts next_id\n next_id += 1\n else\n puts \"NULL\"\n end\n elsif command[0] == 'e'\n cur_id = Integer(input[1])\n ret = erase_block(memory, cur_id)\n if !ret\n puts \"ILLEGAL_ERASE_ARGUMENT\"\n end\n else\n defragment(memory)\n end\nend\n"}, {"source_code": "\ndata = gets.chomp.split\nt = Integer(data[0])\nw = Integer(data[1])\ntask = []\nfor i in 0...t\n task[i] = []\n task[i] = gets.chomp\nend\n\nmemory = []\nfor i in 0...w\n memory[i] = 0\nend\n\ndef allocate(amount, array)\n success = false\n endIndex = 0\n count = 0\n for i in 0...array.length - 1\n if array[i] == array[i + 1] && array[i] == 0\n count += 1\n else\n if count + 1 >= amount\n endIndex = i\n success = true\n break\n else\n count = 0\n end\n end\n if count + 1 >= amount\n endIndex = i\n success = true\n break\n end\n end\n if success\n return endIndex\n else\n return \"NULL\"\n end\nend\n\n\ndef erase(identifier, array)\n for i in 0...array.length\n if array[i] == identifier\n array[i] = 0\n end\n end \n return array \nend\n\ndef defragment(array)\n count = 0\n i = 0\n while i <= array.length\n if array[i] == 0\n array.delete_at(i)\n count += 1\n else\n i += 1\n end\n end\n count.times{ array.push(0)}\n return array\nend\n\ncast = Hash.new\nkey = 0\nfor i in 0...t\n if task[i][0] == \"a\"\n amount = Integer(task[i][task[i].length - 1])\n endIndex = allocate(amount, memory)\n if endIndex == \"NULL\"\n puts \"NULL\"\n else\n key += 1\n cast[key] = amount\n for i in endIndex - amount + 2..endIndex + 1\n memory[i] = key\n end\n puts key\n end\n elsif task[i][0] == \"e\"\n identifier = Integer(task[i][task[i].length - 1])\n if identifier <= key\n memory = erase(identifier, memory)\n cast[identifier] = -1\n else\n puts \"ILLEGAL_ERASE_ARGUMENT\"\n end\n else\n memory = defragment(memory)\n end\nend\n"}, {"source_code": "\ndata = gets.chomp.split\nt = Integer(data[0])\nw = Integer(data[1])\ntask = []\nfor i in 0...t\n task[i] = []\n task[i] = gets.chomp\nend\n\nmemory = []\nfor i in 0...w\n memory[i] = 0\nend\n\ndef allocate(amount, array)\n success = false\n endIndex = 0\n count = 0\n if array.length > 1\n for i in 0...array.length - 1\n if array[i] == array[i + 1] && array[i] == 0\n count += 1\n else\n if count + 1 >= amount\n endIndex = i\n success = true\n break\n else\n count = 0\n end\n end\n if count + 1 >= amount\n endIndex = i\n success = true\n break\n end\n end\n else\n if amount == 1 && array.length == 1\n if array[0] == 0\n array[0] = 1\n success = true\n endIndex = -1\n end\n end\n end\n if success\n return endIndex\n else\n return \"NULL\"\n end\nend\n\n\ndef erase(identifier, array)\n for i in 0...array.length\n if array[i] == identifier\n array[i] = 0\n end\n end \n return array \nend\n\ndef defragment(array)\n count = 0\n i = 0\n while i <= array.length\n if array[i] == 0\n array.delete_at(i)\n count += 1\n else\n i += 1\n end\n end\n count.times{ array.push(0)}\n return array\nend\n\ncast = Hash.new\nkey = 0\nfor i in 0...t\n if task[i][0] == \"a\"\n amount = Integer(task[i][task[i].length - 1])\n endIndex = allocate(amount, memory)\n if endIndex == \"NULL\"\n puts \"NULL\"\n else\n key += 1\n cast[key] = amount\n for i in endIndex - amount + 2..endIndex + 1\n memory[i] = key\n end\n puts key\n end\n elsif task[i][0] == \"e\"\n negetive = task[i][task[i].length - 2]\n if negetive == \"-\"\n identifier = 0 - Integer(task[i][task[i].length - 1])\n else\n identifier = Integer(task[i][task[i].length - 1])\n end\n if identifier <= key && identifier > 0\n value = cast[identifier]\n if value != nil\n memory = erase(identifier, memory)\n cast.delete(identifier)\n else\n puts \"ILLEGAL_ERASE_ARGUMENT\"\n end\n else\n puts \"ILLEGAL_ERASE_ARGUMENT\"\n end\n else\n memory = defragment(memory)\n end\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nidentifiers = {}\nmemory_blocks = {}\nstart_index = 0\nidentifier = 1\n\nn.times do\n\tcommand = gets.split(' ')\t\n\tcase command[0]\n\t\twhen \"alloc\"\n\t\t\tblock_size = command[1].to_i\n\t\t\tfit = false\n\t\t\twhile memory_blocks[start_index]\n\t\t\t\tstart_index += memory_blocks[start_index]\n\t\t\tend\n\t\t\twhile start_index + block_size <= m \n\t\t\t\tbreak if block_size == m && !memory_blocks.empty?\n\t\t\t\tcheck = memory_blocks.select { |k, v| (k < start_index + block_size) && (k >= start_index) }\n\t\t\t\tif check.empty?\n\t\t\t\t\tmemory_blocks[start_index] = block_size\n\t\t\t\t\tidentifiers[identifier] = start_index\n\t\t\t\t\tputs identifier\n\t\t\t\t\tidentifier += 1\n\t\t\t\t\tstart_index += block_size\n\t\t\t\t\tfit = true\n\t\t\t\t\tbreak\n\t\t\t\telse\n\t\t\t\t\tnext_index = check.min\n\t\t\t\t\tstart_index = next_index[0] + memory_blocks[next_index[0]]\n\t\t\t\tend\n\t\t\tend\n\t\t\tputs \"NULL\" unless fit\n\t\twhen \"erase\"\n\t\t\td_iden = command[1].to_i\n\t\t\tiden_index = identifiers[d_iden]\n\t\t\tif iden_index.nil?\n\t\t\t\tputs \"ILLEGAL_ERASE_ARGUMENT\"\n\t\t\telse\n\t\t\t\tidentifiers.delete(d_iden)\n\t\t\t\tmemory_blocks.delete(iden_index)\n\t\t\t\tstart_index = iden_index\n\t\t\tend\n\t\telse # defragment\n\t\t\tstart_index = 0\n\t\t\tcopy = {}\n\t\t\tmemory_blocks.size.times do\n\t\t\t\tlowest = memory_blocks.min\n\t\t\t\tcopy[start_index] = lowest[1]\n\t\t\t\tidentifiers[identifiers.key(lowest[0])] = start_index\n\t\t\t\tstart_index += lowest[1]\n\t\t\t\tmemory_blocks.delete(lowest[0])\n\t\t\tend\n\t\t\tmemory_blocks = copy\n\t\tend\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nidentifiers = {}\nmemory_blocks = {}\nstart_index = 0\nidentifier = 1\n\nn.times do\n\tcommand = gets.split(' ')\t\n\tcase command[0]\n\t\twhen \"alloc\"\n\t\t\tblock_size = command[1].to_i\n\t\t\tfit = false\n\t\t\twhile memory_blocks[start_index]\n\t\t\t\tstart_index += memory_blocks[start_index]\n\t\t\tend\n\t\t\twhile start_index + block_size <= m \n\t\t\t\tbreak if block_size == m && !memory_blocks.empty?\n\t\t\t\tcheck = memory_blocks.select { |k, v| (k < start_index + block_size) && (k >= start_index) }\n\t\t\t\tif check.empty?\n\t\t\t\t\tmemory_blocks[start_index] = block_size\n\t\t\t\t\tidentifiers[identifier] = start_index\n\t\t\t\t\tputs identifier\n\t\t\t\t\tidentifier += 1\n\t\t\t\t\tstart_index += block_size\n\t\t\t\t\tfit = true\n\t\t\t\t\tputs \"memory_blocks is #{memory_blocks}\"\n\t\t\t\t\tputs \"identifiers is #{identifiers}\"\n\t\t\t\t\tbreak\n\t\t\t\telse\n\t\t\t\t\tnext_index = check.min\n\t\t\t\t\tstart_index = next_index[1] + memory_blocks[next_index[0]]\n\t\t\t\tend\n\t\t\tend\n\t\t\tputs \"NULL\" unless fit\n\t\twhen \"erase\"\n\t\t\td_iden = command[1].to_i\n\t\t\tiden_index = identifiers[d_iden]\n\t\t\tif iden_index.nil?\n\t\t\t\tputs \"ILLEGAL_ERASE_ARGUMENT\"\n\t\t\telse\n\t\t\t\tidentifiers.delete(d_iden)\n\t\t\t\tmemory_blocks.delete(iden_index)\n\t\t\t\tstart_index = iden_index\n\t\t\t\tputs \"start_index is #{start_index}\"\n\t\t\t\tputs \"memory_blocks is #{memory_blocks}\"\n\t\t\t\tputs \"identifiers is #{identifiers}\"\n\t\t\tend\n\t\telse # defragment\n\t\t\tstart_index = 0\n\t\t\tcopy = {}\n\t\t\tmemory_blocks.size.times do\n\t\t\t\tlowest = memory_blocks.min\n\t\t\t\tcopy[start_index] = lowest[1]\n\t\t\t\tidentifiers[identifiers.key(lowest[0])] = start_index\n\t\t\t\tstart_index += lowest[1]\n\t\t\t\tmemory_blocks.delete(lowest[0])\n\t\t\tend\n\t\t\tmemory_blocks = copy\n\t\t\tputs \"memory_blocks is #{memory_blocks}\"\n\t\t\tputs \"identifiers is #{identifiers}\"\n\t\tend\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nidentifiers = {}\nmemory_blocks = {}\nstart_index = 0\nidentifier = 1\n\nn.times do\n\tcommand = gets.split(' ')\t\n\tcase command[0]\n\t\twhen \"alloc\"\n\t\t\tblock_size = command[1].to_i\n\t\t\tfit = false\n\t\t\twhile memory_blocks[start_index]\n\t\t\t\tstart_index += memory_blocks[start_index]\n\t\t\tend\n\t\t\twhile start_index + block_size <= m \n\t\t\t\tbreak if block_size == m && !memory_blocks.empty?\n\t\t\t\tcheck = memory_blocks.select { |k, v| (k < start_index + block_size) && (k >= start_index) }\n\t\t\t\tif check.empty?\n\t\t\t\t\tmemory_blocks[start_index] = block_size\n\t\t\t\t\tidentifiers[identifier] = start_index\n\t\t\t\t\tputs identifier\n\t\t\t\t\tidentifier += 1\n\t\t\t\t\tstart_index += block_size\n\t\t\t\t\tfit = true\n\t\t\t\t\tbreak\n\t\t\t\telse\n\t\t\t\t\tnext_index = check.min\n\t\t\t\t\tstart_index = next_index[1] + memory_blocks[next_index[0]]\n\t\t\t\tend\n\t\t\tend\n\t\t\tputs \"NULL\" unless fit\n\t\twhen \"erase\"\n\t\t\td_iden = command[1].to_i\n\t\t\tiden_index = identifiers[d_iden]\n\t\t\tif iden_index.nil?\n\t\t\t\tputs \"ILLEGAL_ERASE_ARGUMENT\"\n\t\t\telse\n\t\t\t\tidentifiers.delete(d_iden)\n\t\t\t\tmemory_blocks.delete(iden_index)\n\t\t\t\tstart_index = iden_index\n\t\t\tend\n\t\telse # defragment\n\t\t\tstart_index = 0\n\t\t\tcopy = {}\n\t\t\tmemory_blocks.size.times do\n\t\t\t\tlowest = memory_blocks.min\n\t\t\t\tcopy[start_index] = lowest[1]\n\t\t\t\tidentifiers[identifiers.key(lowest[0])] = start_index\n\t\t\t\tstart_index += lowest[1]\n\t\t\t\tmemory_blocks.delete(lowest[0])\n\t\t\tend\n\t\t\tmemory_blocks = copy\n\t\tend\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nidentifiers = {}\nmemory_blocks = {}\nstart_index = 0\nidentifier = 1\n\nn.times do\n\tcommand = gets.split(' ')\t\n\tcase command[0]\n\t\twhen \"alloc\"\n\t\t\tblock_size = command[1].to_i\n\t\t\tfit = false\n\t\t\twhile memory_blocks[start_index]\n\t\t\t\tstart_index += memory_blocks[start_index]\n\t\t\tend\n\t\t\twhile start_index + block_size <= m\n\t\t\t\tcheck = memory_blocks.select { |k, v| (k < start_index + block_size) && (k >= start_index) }\n\t\t\t\tif check.empty?\n\t\t\t\t\tmemory_blocks[start_index] = block_size\n\t\t\t\t\tidentifiers[identifier] = start_index\n\t\t\t\t\tputs identifier\n\t\t\t\t\tidentifier += 1\n\t\t\t\t\tstart_index += block_size\n\t\t\t\t\tfit = true\n\t\t\t\t\tbreak\n\t\t\t\telse\n\t\t\t\t\tnext_index = check.min\n\t\t\t\t\tstart_index = next_index[1] + memory_blocks[next_index[0]]\n\t\t\t\tend\n\t\t\tend\n\t\t\tputs \"NULL\" unless fit\n\t\twhen \"erase\"\n\t\t\td_iden = command[1].to_i\n\t\t\tiden_index = identifiers[d_iden]\n\t\t\tif iden_index.nil?\n\t\t\t\tputs \"ILLEGAL_ERASE_ARGUMENT\"\n\t\t\telse\n\t\t\t\tidentifiers.delete(d_iden)\n\t\t\t\tmemory_blocks.delete(iden_index)\n\t\t\t\tstart_index = iden_index\n\t\t\tend\n\t\telse # defragment\n\t\t\tstart_index = 0\n\t\t\tcopy = memory_blocks\n\t\t\tmemory_blocks.size.times do\n\t\t\t\tlowest = copy.min\n\t\t\t\tmemory_blocks[start_index] = lowest[1]\n\t\t\t\tidentifiers[identifiers.key(lowest[0])] = start_index\n\t\t\t\tstart_index += lowest[1]\n\t\t\t\tcopy.delete(lowest[0])\n\t\t\t\tmemory_blocks.delete(lowest[0])\n\t\t\tend\n\t\tend\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nidentifiers = {}\nmemory_blocks = {}\nidentifier = 1\n\nn.times do\n\tcommand = gets.split(' ')\t\n\tcase command[0]\n\t\twhen \"alloc\"\n\t\t\tstart_index = 0\n\t\t\tblock_size = command[1].to_i\n\t\t\tfit = false\n\t\t\twhile memory_blocks[start_index]\n\t\t\t\tstart_index += memory_blocks[start_index]\n\t\t\tend\n\t\t\twhile start_index + block_size <= m \n\t\t\t\tbreak if block_size == m && !memory_blocks.empty?\n\t\t\t\tcheck = memory_blocks.select { |k, v| (k < start_index + block_size) && (k >= start_index) }\n\t\t\t\tif check.empty?\n\t\t\t\t\tmemory_blocks[start_index] = block_size\n\t\t\t\t\tidentifiers[identifier] = start_index\n\t\t\t\t\tputs identifier\n\t\t\t\t\tidentifier += 1\n\t\t\t\t\tfit = true\n\t\t\t\t\tputs \"memory_blocks is #{memory_blocks}\"\n\t\t\t\t\tputs \"identifiers is #{identifiers}\"\n\t\t\t\t\tbreak\n\t\t\t\telse\n\t\t\t\t\tnext_index = check.min\n\t\t\t\t\tstart_index = next_index[0] + memory_blocks[next_index[0]]\n\t\t\t\tend\n\t\t\tend\n\t\t\tputs \"NULL\" unless fit\n\t\twhen \"erase\"\n\t\t\td_iden = command[1].to_i\n\t\t\tiden_index = identifiers[d_iden]\n\t\t\tif iden_index.nil?\n\t\t\t\tputs \"ILLEGAL_ERASE_ARGUMENT\"\n\t\t\telse\n\t\t\t\tidentifiers.delete(d_iden)\n\t\t\t\tmemory_blocks.delete(iden_index)\n\t\t\t\tputs \"memory_blocks is #{memory_blocks}\"\n\t\t\t\tputs \"identifiers is #{identifiers}\"\n\t\t\tend\n\t\telse # defragment\n\t\t\tstart_index = 0\n\t\t\tcopy = {}\n\t\t\tmemory_blocks.size.times do\n\t\t\t\tlowest = memory_blocks.min\n\t\t\t\tcopy[start_index] = lowest[1]\n\t\t\t\tidentifiers[identifiers.key(lowest[0])] = start_index\n\t\t\t\tstart_index += lowest[1]\n\t\t\t\tmemory_blocks.delete(lowest[0])\n\t\t\tend\n\t\t\tmemory_blocks = copy\n\t\t\tputs \"memory_blocks is #{memory_blocks}\"\n\t\t\tputs \"identifiers is #{identifiers}\"\n\t\tend\nend\n"}], "src_uid": "a6cba17c5ddb93f6741e00280fb6c54c"} {"source_code": "t = gets.to_i\r\nt.times { |u|\r\n n = gets.to_i\r\n arr = gets.chomp.split(\" \").map(&:to_i)\r\n even = 0\r\n odd = 0\r\n arr.each { |x|\r\n if x % 2 == 0\r\n even += 1\r\n else\r\n odd += 1\r\n end\r\n }\r\n if even == odd\r\n puts \"Yes\"\r\n else\r\n puts \"No\"\r\n end\r\n}", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\nncases = gets.chomp.to_i\n\nncases.times do\n n = gets.chomp.to_i\n numbers = gets.chomp.split(' ').map { |str| str.to_i }\n answer = numbers.map { |n| n % 2 == 0 }.filter { |b| b }.size == n\n puts answer ? 'Yes' : 'No'\nend\n"}, {"source_code": "\ndef possible?(arr)\n arr.filter { |x| x % 2 == 1}.size == arr.size / 2\nend\n\nt = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n inp = gets.chomp.split(' ').map(&:to_i)\n possible?(inp) ? puts(\"Yes\\n\") : puts(\"No\\n\")\nend\n"}, {"source_code": "gets\r\nwhile gets\r\n a = gets.split.map(&:to_i)\r\n puts a.count(&:odd?) == a.size / 2 ? 'Yes' : 'No'\r\nend"}, {"source_code": "a = gets.to_i\r\na.times{\r\n n = gets.to_i\r\n arr = gets.split.map &:to_i\r\n b = arr.select{_1.odd?}\r\n c = arr - b\r\n if b.size == n && c.size == n then puts \"Yes\"\r\n else \r\n puts \"No\"\r\nend\r\n}"}, {"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n a=gets.split.map(&:to_i)\r\n c=0\r\n a.each do |aa|\r\n if aa.odd?\r\n c+=1\r\n end\r\n end\r\n if c==n\r\n puts \"Yes\"\r\n else\r\n puts \"No\"\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "d5bd27c969d9cd910f13baa53c247871"} {"source_code": "def read_integers\n STDIN.gets.split.map(&:to_i)\nend \n\ndef solve array, m, k, hash\n result = []\n array.each do |x| \n rem = x%m \n hash[rem] = hash[rem] || []\n hash[rem].push(x)\n result = hash[rem] if hash[rem].length > result.length\n end\n result\nend\n\ndef solution \n n, k, m = read_integers\n array = read_integers\n hash = []\n result = solve array, m, k, hash\n if result.length < k\n print \"No\\n\"\n else\n print \"Yes\\n\"\n result.each_with_index do |val, index| \n print val, ' ' if index < k \n end\n end\nend\n\nsolution", "positive_code": [{"source_code": "def solution(k, ans_index, hash)\n puts 'Yes'\n hash[ans_index].each_with_index do |val, index|\n print \"#{val} \" if index < k\n end\nend\n\ndef get_hash_and_index(k, m, array)\n hash = []\n ans_index = -1\n array.each do |x|\n rem = x % m\n hash[rem] = [] if hash[rem].nil?\n hash[rem].push(x)\n ans_index = rem if hash[rem].length == k\n end\n ans_index == -1 ? (puts 'No') : solution(k, ans_index, hash)\nend\n\n_n, k, m = STDIN.gets.split.map(&:to_i)\narray = STDIN.gets.split.map(&:to_i)\n\nget_hash_and_index(k, m, array)\n"}, {"source_code": "#! /usr/bin/env ruby\n\nn, k, m = gets.split.map &:to_i\na = gets.split.map &:to_i\na = a.group_by { |i| i % m }\nyes = false\na.each_key do |key|\n if a[key].size >= k\n yes = true\n puts:Yes\n puts a[key][0...k] * ' '\n break\n end\nend\nif not yes\n puts:No\nend\n\n"}, {"source_code": "def read_integers\n STDIN.gets.split.map(&:to_i)\nend \n\ndef solve array, m, k\n result = []\n hash = []\n array.each do |x| \n rem = x%m \n hash[rem] = hash[rem] || []\n hash[rem].push(x)\n result = hash[rem] if hash[rem].length > result.length\n end\n result\nend\n\ndef solution \n n, k, m = read_integers\n array = read_integers\n result = solve array, m, k\n if result.length < k\n print \"No\\n\"\n else\n print \"Yes\\n\"\n result.each_with_index do |val, index| \n print val, ' ' if index < k \n end\n end\nend\n\nsolution"}, {"source_code": "\ndef read_integers\n STDIN.gets.split.map(&:to_i)\nend \n\ndef solve array, m, k, hash\n ans_index = -1;\n array.each do |x| \n rem = x%m \n hash[rem] = hash[rem] || []\n hash[rem].push(x)\n if hash[rem].length == k\n ans_index = rem\n end\n end\n ans_index\nend \n\ndef solution \n n, k, m = read_integers\n array = read_integers\n hash = []\n ans_index = solve array, m, k, hash\n if ans_index == -1\n print \"No\\n\"\n else\n print \"Yes\\n\"\n hash[ans_index ].each_with_index do \n |val, index| \n if index < k \n print val\n print ' '\n end\n end\n end\nend\n\nsolution"}, {"source_code": "def solution \n n, k, m = STDIN.gets.split.map(&:to_i)\n array = STDIN.gets.split.map(&:to_i)\n \n hash = []\n ans_index = -1;\n array.each{ |x| \n rem = x%m \n \n if hash[rem] == nil then\n hash[rem] = []\n end\n \n hash[rem].push(x)\n \n if hash[rem].length == k then \n ans_index = rem\n end\n \n }\n \n if ans_index == -1 then\n puts 'No'\n else\n puts 'Yes'\n\n hash[ans_index ].each_with_index { |val, index| \n if index < k then \n print val\n print ' '\n end \n }\n \n #puts output;\n end\nend\n\nsolution"}, {"source_code": "def solution \n n, k, m = STDIN.gets.split.map(&:to_i)\n array = STDIN.gets.split.map(&:to_i)\n \n hash = []\n ans_index = -1;\n array.each{ |x| \n rem = x%m \n \n if hash[rem] == nil then\n hash[rem] = []\n end\n \n hash[rem].push(x)\n \n if hash[rem].length == k then \n ans_index = rem\n end\n \n }\n \n if ans_index == -1 then\n puts 'No'\n else\n puts 'Yes'\n # output = \"\"\n \n hash[ans_index ].each_with_index { |val, index| \n if index < k then \n # output += val.to_s + \" \"\n puts val\n end \n }\n \n #puts output;\n end\nend\n\nsolution"}], "negative_code": [{"source_code": "#! /usr/bin/env ruby\n\nn, k, m = gets.split.map &:to_i\na = gets.split.map &:to_i\na = a.group_by { |i| i % m }\nyes = false\na.each_key do |key|\n if a[key].size >= k\n yes = true\n puts:Yes\n puts a[key][0...k] * ' '\n end\nend\nif not yes\n puts:No\nend\n\n"}, {"source_code": "def solution \n n, k, m = STDIN.gets.split.map(&:to_i)\n array = STDIN.gets.split.map(&:to_i)\n \n hash = {}\n best = -1;\n array.each{ |x| \n rem = x%m \n if hash[rem] == nil then\n hash[rem] = []\n end\n \n hash[rem].push(x)\n if hash[rem].length == k then \n best = x%m \n end\n }\n \n if best == -1 then\n puts 'No'\n else\n puts 'yes'\n output = \"\";\n hash[best].each_with_index { |val, index| \n if index < k then \n output += val.to_s + \" \"\n end \n }\n puts output;\n end\nend\n\nsolution"}, {"source_code": "def solution \n n, k, m = gets.split.map(&:to_i)\n array = gets.split.map(&:to_i)\n \n hash = {}\n best = -1;\n array.each{ |x| \n rem = x%m \n if hash[rem] == nil then\n hash[rem] = []\n end\n \n hash[rem].push(x)\n if hash[rem].length == k then \n best = x%m \n end\n }\n \n if best == -1 then\n puts 'No'\n else\n puts 'yes'\n output = \"\";\n hash[best].each_with_index { |val, index| \n if index < k then \n output = output + val.to_s + \" \"\n end \n }\n puts output;\n end\nend\n\nsolution"}], "src_uid": "55bd1849ef13b52788a0b5685c4fcdac"} {"source_code": "# your code goes here\n\n# a = gets.chomp.to_i\n\n# b = gets.chomp.to_i\n\n# puts (a+b)\nt = gets.chomp.to_i\nfor tc in 1..t\n\tn = gets.chomp.to_i\n\ta = gets.split\n\tb = false\n\tfor i in 1..(n-1)\n\t\tif a[i] != a[i-1]\n\t\t\tb = true;\n\t\tend\n\tend\n\tif b\n\t\tputs 1\n\telse\n\t\tputs n\n\tend\nend", "positive_code": [{"source_code": "# cook your code here\ntc = gets.chomp.to_i\ntc.times { \n n = gets.chomp.to_i\n \n arr = gets.chomp.split(' ').map(&:to_i)\n unique = 1\n index = 1\n while(index < n) do \n if arr[index] != arr[0]\n unique += 1\n break\n end\n index += 1\n end\n if arr.size() == 1 || unique >= 2\n puts 1\n else\n puts arr.size()\n end\n \n}"}], "negative_code": [], "src_uid": "7b80d3f3cd4f93e4277c76c76dc41f42"} {"source_code": "gets\nbars, towers = gets.split.map(&:to_i), Hash.new(0)\nbars.each {|bar| towers[bar] += 1}\nprint towers.values.max, \" \", towers.length", "positive_code": [{"source_code": "n = gets.to_i\nhs = Hash.new 0\ngets.split(' ').map(&:to_i).each{|x| hs[x]+=1}\nputs \"#{hs.max_by(&:last).last} #{hs.length}\""}, {"source_code": "n = gets.to_i\n\nbr = gets.split.map{|i| i.to_i}\n\nkol = br.uniq.size\n\nh = []\nbr.size.times do |i|\n h << br.reject{|it| it != br[i]}.size\nend\n\nh = h.sort\n\nputs h[-1].to_s + \" \" + kol.to_s"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /).map!{|x|x.to_i}\nh = Hash.new\nfor i in 0..n-1\n\tif h.key?(a[i])\n\t\th[a[i]] += 1 \n\telse\n\t\th[a[i]] = 1 \n\tend\nend\nha = h.to_a.sort{|a, b|\n b[1] <=> a[1] \n}\nputs ha[0][1].to_s + \" \" + h.length.to_s"}, {"source_code": "gets\nv=gets.split\nprint v.map{|x|v.count x}.max,\" \",v.uniq.size\n\n"}, {"source_code": "#!/usr/bin/ruby\ngets;\na=gets.split.map(&:to_i).sort_by{|e|e}.chunk{|e|e}.to_a\nputs \"#{a.map{|k,v|v.size}.max} #{a.size}\""}, {"source_code": "n = gets.chomp.to_i\na = Array.new(1001).map {|x| x=0}\ngets.chomp.split(\" \").map {|x| x.to_i}.each { |x|\n a[x]+=1\n}\nputs a.sort[a.length-1].to_s << \" \" << a.count{|x| x!=0}.to_s\n"}, {"source_code": "gets\na=gets.split\nprint a.map{|b|a.count b}.max,\" \",a.uniq.size\n"}, {"source_code": "n = gets.to_i\nl = gets.split(\" \").map(&:to_i).sort\ncnt = 1\nmax = 0\ncol = 0\nlast = l[0]\nl.each do |el|\n if last != el\n cnt += 1\n last = el\n max = col if max < col\n col = 1\n else\n col += 1\n end\nend\n\nmax = col if max < col\n\nputs \"#{max} #{cnt}\""}, {"source_code": "gets\na=gets.split\nprint a.map{|b|a.count b}.max,\" \",a.uniq.size\n"}, {"source_code": "gets\na=gets.split\nprint a.map{|b|a.count b}.max,\" \",a.uniq.size"}, {"source_code": "n=gets.chomp.strip.to_i\np=gets.chomp.split(' ').map(&:to_i)\na=Array.new(1001,0)\nsum=0\nmax=0\np.each do |x|\n\tif a[x]==0\n\t\tsum+=1\n\tend\n\ta[x]+=1\n\tif a[x]>max\n\t\tmax=a[x]\n\tend\nend\nputs max.to_s + ' ' + sum.to_s"}, {"source_code": "gets\na = gets.split.map(&:to_i).to_a\nputs [a.map { |x| a.find_all {|y| x==y}.size }.max, a.uniq.size]*' '"}, {"source_code": "a = gets\na = gets.chomp.split(' ')\n\nr = {}\nmax = 0\na.each do |x|\ny = x.to_sym\n\nr[y] = (r[y]||0) + 1\nmax = r[y] if max < r[y]\nend\n\nputs \"#{max} #{r.size}\""}, {"source_code": "n = gets.to_i\nl = gets.split.map(&:to_i).sort\nfox = Array.new()\n\ncounter = 1\nfor i in 1..n\n if l[i]==l[i-1]\n counter+=1\n else\n fox.concat([counter])\n counter = 1\n end\nend\n\nputs fox.max.to_s + \" \" + l.uniq.size.to_s"}, {"source_code": "gets\narr = gets.split.map { |x| x.to_i }.sort\nprint arr.count(arr.max_by { |x| arr.count(x) }), \" \",arr.uniq.size\n"}, {"source_code": "gets\na=gets.split\nprint a.map{|b|a.count b}.max,\" \",a.uniq.size\n"}, {"source_code": "num=gets.chomp.to_i\nmax=0\nnum2=num\nb=gets.chomp.split(\" \")\n1.upto(1000) do |i|\ntemp=b.count(\"#{i}\")\nnum2=num2-temp\nif temp>max\nmax= temp\nend\nif temp>1\nnum=num-temp+1\nend\nend\nprintf \"#{max} \"\nprintf \"#{num}\""}, {"source_code": "gets\na=gets.split\nprint a.map{|b|a.count b}.max,\" \",a.uniq.size\n"}, {"source_code": "num=gets.chomp.to_i\nmax=0\nnum2=num\nb=gets.chomp.split(\" \")\n1.upto(1000) do |i|\ntemp=b.count(\"#{i}\")\nnum2=num2-temp\nif temp>max\nmax= temp\nend\nif temp>1\nnum=num-temp+1\nend\nend\nprintf \"#{max} \"\nprintf \"#{num}\""}, {"source_code": "require 'set'\ngets\nx=gets.split.map{|e| e.to_i}\nd=Set.new(x).size\nh=Hash.new(0)\nans=0\nx.each{|e|\n\th[e]+=1\n\tans=h[e] if ansc)? b: c))||(x,c=i,1)}\nputs b.to_s+\" \"+a.uniq.size.to_s"}, {"source_code": "gets\ndata=gets.split.map(&:to_i).sort\n\nhs=Hash.new(0)\n\nmax_height = 0\ndata.each{|val| \n\ths[val]+=1\n\t\n\tmax_height = [max_height, hs[val]].max\n}\n\nputs \"#{max_height} #{hs.size}\"\n"}, {"source_code": "gets\ndata=gets.split.map(&:to_i).sort\n\nhs={}\nhs.default = 0\n\nmax_height = 0\ndata.each{|val| \n\ths[val]+=1\n\t\n\tmax_height = [max_height, hs[val]].max\n}\n\nputs \"#{max_height} #{hs.size}\"\n"}, {"source_code": "gets\nq = Hash.new\ngets.split.map do |e|\n e.to_i\n if q[e].nil?\n q[e] = 1\n else\n q[e] += 1\n end\nend\n\nputs q.values.max\n\nputs q.size\n"}, {"source_code": "n=gets; m=Hash.new(0)\ngets.chomp.split.each { |i| m[i] += 1 }\nputs m.max_by{|k,v| v}[1]; print m.length; print ' '"}, {"source_code": "n=gets.chomp.to_i\ns=gets.chomp.to_s\ns=s.split(\" \")\nu=s.uniq\nmax=1\nfor i in u\n\tif (s.count(i)>max)\n\t\tmax=s.count(i)\n\tend\nend\nprint(\"#{max} #{u.size}\\n\")\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\na = gets.split.map(&:to_i) + [0] # 0 for terminator\nprev = 0\ntowers = 0\nhighest_tower = 0\nheight = 0\na.sort.each { |i|\n if i != prev\n if i != 0\n towers += 1\n height = 1\n prev = i\n end\n else\n height += 1\n if height > highest_tower\n highest_tower = height\n end\n end\n}\n\nputs \"#{highest_tower} #{towers}\""}, {"source_code": "gets\nq = Hash.new\ngets.split.map do |e|\n e.to_i\n if q[e].nil?\n q[e] = 1\n else\n q[e] += 1\n end\nend\n\nputs q.values.max\n\nputs q.size\n "}, {"source_code": "n = gets.to_i\na = gets.split(' ')[0...n].map { |s| s.to_i }\nd = a.inject(Hash.new(0)) { |h, x| h[x] += 1; h }\ncnt = d.size\nmax = d.map { |k, v| v }.max\nputs \"#{max} #{cnt}\""}, {"source_code": "gets\na=gets.split\nprint a.map{|b|a.count b}.max,\" \",a.uniq.size\n"}, {"source_code": "gets\nmas = gets.split(\" \")\nputs mas.map { |s| mas.count s }.max.to_s+\" \"+mas.uniq.size.to_s"}, {"source_code": "# http://codeforces.com/contest/37/problem/A\n\nnumber = gets.chomp.to_i\n\nbars = gets.chomp.split(\" \").each {|str| [str.to_i]}\n\ntowers = []\n\nbars.each {|bar|\n if index = towers.index {|item| item[0] == bar}\n towers[index] << bar\n else\n towers << [bar]\n end\n}\n\ntowers.sort! {|a, b| a.length <=> b.length}.reverse!\n\nputs \"#{towers[0].length} #{towers.length}\"\n"}, {"source_code": "gets\nblocks = gets.chomp.split.map(&:to_i)\n\nres = {}\nblocks.each do |b|\n res[b] ||= 0\n res[b] += 1\nend\n\nputs \"#{res.values.max} #{blocks.uniq.size}\" "}, {"source_code": "n = gets.to_i\nm = gets.split\nm = m.uniq.collect{|i| [i, m.find_all{|j| j == i}.size]}\nprint(m.max{|x, y| x[1] <=> y[1]}[1].to_s + \" \" + m.size.to_s)\n"}, {"source_code": "num=gets.chomp.to_i\nmax=0\nnum2=num\nb=gets.chomp.split(\" \")\n1.upto(1000) do |i|\ntemp=b.count(\"#{i}\")\nnum2=num2-temp\nif temp>max\nmax= temp\nend\nif temp>1\nnum=num-temp+1\nend\nend\nprintf \"#{max} \"\nprintf \"#{num}\""}, {"source_code": "class Euler\n mas=Array.new(size=0, obj=nil);\n n=gets.to_i;\n st=gets.to_s.split(\" \");\n st.sort!;\n mx=1;\n for i in 0..st.length-1\n k=1;\n for j in i+1..st.length-1\n if (st[j]==st[i])\n k+=1;\n end\n end\n if (k>mx)\n mx=k;\n end\n end\n a=st.uniq;\n print mx.to_s+\" \"+a.length.to_s+\"\\n\";\nend\n"}, {"source_code": "gets\na=gets.split\nprint a.map{|b|a.count b}.max,\" \",a.uniq.size\n"}, {"source_code": "gets\nq = Hash.new\ngets.split.map do |e|\n e.to_i\n if q[e].nil?\n q[e] = 1\n else\n q[e] += 1\n end\nend\n\nputs q.values.max\n\nputs q.size\n "}, {"source_code": "gets\nq = Hash.new\ngets.split.map do |e|\n e.to_i\n if q[e].nil?\n q[e] = 1\n else\n q[e] += 1\n end\nend\n\nputs q.values.max\n\nputs q.size\n "}, {"source_code": "gets\na=gets.split\nprint a.map{|b|a.count b}.max,\" \",a.uniq.size\n"}, {"source_code": "gets\na=gets.split\nprint a.map{|b|a.count b}.max,\" \",a.uniq.size"}, {"source_code": "gets\na=gets.split\nprint a.map{|b|a.count b}.max,\" \",a.uniq.size\n"}, {"source_code": "barNum = gets.chomp.to_i\nbar = gets.chomp.split(' ').map {|item| item.to_i}\nbar.sort!\ntotal = bar.uniq.length\nlargest = 0\nbar.each do |item|\n\tlargest = bar.count(item) if largest < bar.count(item)\nend\nputs \"#{largest} #{total}\""}], "negative_code": [{"source_code": "n = gets.to_i\nl = gets.split(\" \").map(&:to_i).sort\ncnt = 1\nmax = 0\ncol = 0\nlast = l[0]\nl.each do |el|\n if last != el\n cnt += 1\n last = el\n max = col if max < col\n col = 1\n else\n col += 1\n end\nend\n\nputs \"#{max} #{cnt}\""}, {"source_code": "a = gets\na = gets.chomp.split(' ')\n\nr = {}\nmax = 0\na.each do |x|\ny = x.to_sym\nr[y] = r[y]||0 + 1\nmax = r[y] if max < r[y]\nend\n\nputs \"#{max} #{r.size}\""}, {"source_code": "n = gets.to_i\nl = gets.split.map(&:to_i).sort\nfox = Array.new()\n\ncounter = 1\nfor i in 1..n-1\n if l[i]==l[i-1]\n counter+=1\n else\n fox.concat([counter])\n counter = 1\n end\nend\n\nputs fox.max.to_s + \" \" + l.uniq.size.to_s"}, {"source_code": "n=gets; m=Hash.new(0)\ngets.chomp.split.each { |i| m[i] += 1 }\nprint m.length; print ' '; puts m.max_by{|k,v| v}[1]"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nsum=0\n0.upto(a-1) do |i|\n b[i]= b[i].to_i\nsum=sum+b[i]\nend\nr=0\nif sum%2==0\n r=1\nend \n \nsum=(sum/2.0).ceil\n\nb.sort!\nb.reverse!\np=0\n0.upto(a-1) do |i|\np=p+b[i].to_i\n\nif ( p>=sum && r==0)\np=i+1\nbreak\nend\nif (p>sum && r==1)\np=i+1\nbreak\nend\nend\n\nputs \"#{p}\""}], "src_uid": "9a92221c760a3b6a1e9318f948fe0473"} {"source_code": "gets\nd=[0,0,0]\ngets.split(/\\s/).each{|i|\n\td[i.to_i%3]=d[i.to_i%3]+1\n}\nprint (d[0]/2)+(d[1]x{a.count{|i|i%3==x}}\np g[0]/2+[g[1],g[2]].min"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\ndef calc(x)\n a=0\n while x>0\n a+=x%10\n x/=10\n end\n a%=3\nend\ncnt=[0,0,0]\na.each{|i|\n cnt[calc(i)]+=1\n}\np cnt[0]/2+[cnt[1],cnt[2]].min\n"}, {"source_code": "gets\na=[0]*3\ngets.split.map{|b|a[b.sum%3]+=1}\np a[0]/2+a[1..2].min\n"}, {"source_code": "gets\na=[0]*3\ngets.split.map{|b|a[b.sum%3]+=1}\np a[0]/2+a[1..2].min\n"}, {"source_code": "gets\na=[0]*3\ngets.split.map{|b|a[b.sum%3]+=1}\np a[0]/2+a[1..2].min\n"}, {"source_code": "gets\na=[0]*3\ngets.split.map{|b|a[b.sum%3]+=1}\np a[0]/2+a[1..2].min\n"}, {"source_code": "gets\na=[0]*3\ngets.split.map{|b|a[b.sum%3]+=1}\np a[0]/2+a[1..2].min"}, {"source_code": "gets\nc = Hash.new(0).tap { |h| gets.split.map(&:to_i).each { |v| h[v % 3] += 1 } }\np c[0] / 2 + [c[1], c[2]].min\n"}, {"source_code": "N = gets.chomp.to_i\nc = Hash.new(0).tap { |h| gets.split.map(&:to_i).each { |v| h[v % 3] += 1 } }\np c[0] / 2 + [c[1], c[2]].min\n"}, {"source_code": "gets\na=[0]*3\ngets.split.map{|b|a[b.sum%3]+=1}\np a[0]/2+a[1..2].min\n"}, {"source_code": "gets\na=[0]*3\ngets.split.map{|b|a[b.sum%3]+=1}\np a[0]/2+a[1..2].min\n"}, {"source_code": "gets\na=[0]*3\ngets.split.map{|b|a[b.sum%3]+=1}\np a[0]/2+a[1..2].min\n"}, {"source_code": "def min(a, b)\n a < b ? a : b\nend\n\ndef digits_sum(number)\n number.to_s.chars.map { |v| v.to_i }.inject { |r, v| r + v }\nend\n\nn = gets.to_i\nparts = gets.split.map { |v| digits_sum(v) % 3 }\n\ncount = [0, 0, 0]\n\nparts.each { |p| count[p] += 1 }\n\nputs count[0] / 2 + min(count[1], count[2])\n"}, {"source_code": "gets\na=[0]*3\ngets.split.map{|b|a[b.sum%3]+=1}\np a[0]/2+a[1..2].min"}, {"source_code": "gets\na=[0]*3\ngets.split.map{|b|a[b.sum%3]+=1}\np a[0]/2+a[1..2].min\n"}], "negative_code": [{"source_code": "gets\nd=[0,0,0]\ngets.split(/\\s/).each{|i|\n\td[i.to_i%3]=d[i.to_i%3]+1\n\tprint i,\"\\n\"\n}\nprint (d[0]/2)+(d[1] 0.00001\n\t\t\t\tcol_time = - (balls[i][0] - balls[j][0]) / (balls[i][1] - balls[j][1])\n\t\t\t\tif col_time > 0 && col_time < next_time\n\t\t\t\t\tnext_time = col_time\n\t\t\t\t\tnext_a = i\n\t\t\t\t\tnext_b = j\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\t#if next_a != -1 and next_b != -1\n\t\t#pos = (balls[next_b][0] * balls[next_a][1] - balls[next_a][0] - balls[next_b][1]) / (balls[next_a][1] - balls[next_b][1])\n\t#\tpos = calcu_p(balls[next_a][0], balls[next_a][1], balls[next_b][0], balls[next_b][1])\n\t#\tballs[next_a][1], balls[next_b][1] = calcu_v(balls[next_a][1], balls[next_a][2], balls[next_b][1], balls[next_b][2])\n\t#\tballs[next_a][0] = pos\n\t#\tballs[next_b][0] = pos\n\t#end\n\n\tfor i in 0...n \n\t\tflags[i] = false\n\tend\n\tfor i in 0...n\n\t\tfor j in 0...i\n\t\t\tif !flags[i] && !flags[j] && (balls[i][1] - balls[j][1]).abs > 0.00001\n\t\t\t\tcol_time = - (balls[i][0] - balls[j][0]) / (balls[i][1] - balls[j][1])\n\t\t\t\tif (col_time - next_time).abs < 0.00001\n\t\t\t\t\tpos = calcu_p(balls[i][0], balls[i][1], balls[j][0], balls[j][1])\n\t\t\t\t\tballs[i][1], balls[j][1] = calcu_v(balls[i][1], balls[i][2], balls[j][1], balls[j][2])\n\t\t\t\t\tballs[i][0] = balls[j][0] = pos\n\t\t\t\t\tflags[i] = true\n\t\t\t\t\tflags[j] = true\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tfor i in 0...n\n\t\tif !flags[i]\n\t\t\tballs[i][0] += balls[i][1] * next_time\n\t\tend\n\tend\n\tnow += next_time\n\n\t# print balls.to_s, \"\\n\"\nend\n\nfor i in 0...n\n\tprint balls[i][0], \"\\n\"\nend\n\n\n", "positive_code": [{"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nt = Integer(input[1])\nballs = []\nfor i in 0...n\n balls[i] = []\n input1 = gets.chomp.split\n for j in 0...3\n balls[i][j] = Integer(input1[j])\n end\nend\n\nfor i in 0...n\n balls[i][3] = i\nend\nballs = balls.sort_by{|a| a[0]}\n\ndef balls_state(balls, first_collide_i, first_collide_time, n)\n for i in 0...n\n balls[i][0] = balls[i][1] * first_collide_time + balls[i][0]\n end\n for i in 0...first_collide_i.length\n j = first_collide_i[i]\n v_0 = ((balls[j][2] - balls[j+1][2]) * balls[j][1] + 2 * balls[j+1][2] * balls[j+1][1]) / ((balls[j][2] + balls[j+1][2]).to_f)\n v_1 = ((balls[j+1][2] - balls[j][2]) * balls[j+1][1] + 2 * balls[j][2] * balls[j][1]) / ((balls[j][2] + balls[j+1][2]).to_f)\n balls[j][1] = v_0\n balls[j+1][1] = v_1\n end\n return balls\nend\n\ndef next_collide(balls, n)\n collide_time = []\n s = 0\n v = 0\n ct = 0\n for i in 0...n-1\n s = balls[i+1][0] - balls[i][0]\n v = balls[i][1] - balls[i+1][1]\n if balls[i][1] < 0 && balls[i+1][1] < 0\n if balls[i][1] > balls[i+1][1]\n ct = s.to_f / v\n collide_time.push([i, ct])\n end \n elsif balls[i][1] > 0\n if balls[i+1][1] > 0 && balls[i][1] > balls[i+1][1]\n ct = s.to_f / v\n collide_time.push([i, ct])\n \n elsif balls[i+1][1] < 0\n ct = s.to_f / v\n collide_time.push([i, ct])\n end\n end\n end\n collide_time = collide_time.sort_by{|a| a[1]}\n if collide_time != []\n first_collide_i = []\n first_collide_time = collide_time[0][1]\n for i in 0...collide_time.length\n if collide_time[i][1] == first_collide_time\n first_collide_i.push(collide_time[i][0])\n end\n end\n else\n first_collide_time = 1000\n first_collide_i = []\n end\n return first_collide_time, first_collide_i\nend\n\nstop = false\nwhile !stop do\n first_collide_time, first_collide_i = next_collide(balls, n)\n if t <= first_collide_time\n for i in 0...n\n balls[i][0] += balls[i][1] * t\n end\n result = balls.sort_by{|a| a[3]}\n for i in 0...n\n puts result[i][0]\n end\n stop = true\n else\n t -= first_collide_time\n balls = balls_state(balls, first_collide_i, first_collide_time, n)\n end\nend\n\n\n\n\n"}], "negative_code": [{"source_code": "n, t = gets.chomp.split.map { |e| e.to_i }\n\nballs = []\nfor i in 0...n\n\tballs <<= gets.chomp.split.map { |e| e.to_f }\nend\n\ndef calcu_v v0, m0, v1, m1\n\tnv0 = ((m0 - m1) * v0 + 2 * m1 * v1) / (m0 + m1)\n\tnv1 = ((m1 - m0) * v1 + 2 * m0 * v0) / (m0 + m1)\n\treturn nv0, nv1\nend\n\ndef calcu_p(x0, v0, x1, v1)\n\t(x1 * v0 - x0 * v1) / (v0 - v1)\nend\n\nnow = 0\nwhile now < t\n\tnext_time = t - now\n\tnext_a = -1\n\tnext_b = -1\n\tfor i in 0...n\n\t\tfor j in 0...i\n\t\t\tif (balls[i][1] - balls[j][1]).abs > 0.00001\n\t\t\t\tcol_time = - (balls[i][0] - balls[j][0]) / (balls[i][1] - balls[j][1])\n\t\t\t\tif col_time > 0 && col_time < next_time\n\t\t\t\t\tnext_time = col_time\n\t\t\t\t\tnext_a = i\n\t\t\t\t\tnext_b = j\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\tif next_a != -1 and next_b != -1\n\t\t#pos = (balls[next_b][0] * balls[next_a][1] - balls[next_a][0] - balls[next_b][1]) / (balls[next_a][1] - balls[next_b][1])\n\t\tpos = calcu_p(balls[next_a][0], balls[next_a][1], balls[next_b][0], balls[next_b][1])\n\t\tballs[next_a][1], balls[next_b][1] = calcu_v(balls[next_a][1], balls[next_a][2], balls[next_b][1], balls[next_b][2])\n\t\tballs[next_a][0] = pos\n\t\tballs[next_b][0] = pos\n\tend\n\n\tnow += next_time\n\tfor i in 0...n\n\t\tif i != next_a && i != next_b\n\t\t\tballs[i][0] += balls[i][1] * next_time\n\t\tend\n\tend\n\t# print balls.to_s, \"\\n\"\nend\n\nfor i in 0...n\n\tprint balls[i][0], \"\\n\"\nend\n\n\n"}, {"source_code": "n, t = gets.chomp.split.map { |e| e.to_i }\n\nballs = []\nfor i in 0...n\n\tballs <<= gets.chomp.split.map { |e| e.to_f }\nend\n\ndef calcu_v v0, m0, v1, m1\n\tnv0 = ((m0 - m1) * v0 + 2 * m1 * v1) / (m0 + m1)\n\tnv1 = ((m1 - m0) * v1 + 2 * m0 * v0) / (m0 + m1)\n\treturn nv0, nv1\nend\n\ndef calcu_p(x0, v0, x1, v1)\n\t(x1 * v0 - x0 * v1) / (v0 - v1)\nend\n\nflags = Array.new(n) { false }\nnow = 0\nwhile now < t\n\tnext_time = t - now\n\tnext_a = -1\n\tnext_b = -1\n\tfor i in 0...n\n\t\tfor j in 0...i\n\t\t\tif (balls[i][1] - balls[j][1]).abs > 0.00001\n\t\t\t\tcol_time = - (balls[i][0] - balls[j][0]) / (balls[i][1] - balls[j][1])\n\t\t\t\tif col_time > 0 && col_time < next_time\n\t\t\t\t\tnext_time = col_time\n\t\t\t\t\tnext_a = i\n\t\t\t\t\tnext_b = j\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\t#if next_a != -1 and next_b != -1\n\t\t#pos = (balls[next_b][0] * balls[next_a][1] - balls[next_a][0] - balls[next_b][1]) / (balls[next_a][1] - balls[next_b][1])\n\t#\tpos = calcu_p(balls[next_a][0], balls[next_a][1], balls[next_b][0], balls[next_b][1])\n\t#\tballs[next_a][1], balls[next_b][1] = calcu_v(balls[next_a][1], balls[next_a][2], balls[next_b][1], balls[next_b][2])\n\t#\tballs[next_a][0] = pos\n\t#\tballs[next_b][0] = pos\n\t#end\n\n\tfor i in 0...n \n\t\tflags[i] = false\n\tend\n\tfor i in 0...n\n\t\tfor j in 0...i\n\t\t\tif !flags[i] && !flags[j] && (balls[i][1] - balls[j][1]).abs > 0.00001\n\t\t\t\tcol_time = - (balls[i][0] - balls[j][0]) / (balls[i][1] - balls[j][1])\n\t\t\t\tif (col_time - next_time).abs < 0.00001\n\t\t\t\t\tpos = calcu_p(balls[i][0], balls[i][1], balls[j][0], balls[j][1])\n\t\t\t\t\tballs[i][1], balls[j][1] = calcu_v(balls[i][1], balls[i][2], balls[j][1], balls[j][2])\n\t\t\t\t\tballs[i][0] = balls[j][0] = pos\n\t\t\t\t\tflags[i] = true\n\t\t\t\t\tflags[j] = true\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tfor i in 0...n\n\t\tif !flags[i]\n\t\t\tballs[i][0] += balls[i][1] * next_time\n\t\tend\n\tend\n\tnow += next_time\n\n\tprint balls.to_s, \"\\n\"\nend\n\nfor i in 0...n\n\tprint balls[i][0], \"\\n\"\nend\n\n\n"}], "src_uid": "2432a746446990ecc2926bf00807a5ee"} {"source_code": "h,l = gets.chomp.split.map(&:to_i)\n\ndepth = 1.0 * (l*l - h*h) / (2*h)\nprintf(\"%.6f\\n\", depth)\n", "positive_code": [{"source_code": "h,l = gets.split.map(&:to_f)\np (l**2-h**2)/2.0/h"}, {"source_code": "h,l = gets.split.map(&:to_i)\nputs (l*l-h*h)/(2.0*h)"}], "negative_code": [], "src_uid": "2cd5807e3f9685d4eff88f2283904f0d"} {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = (a[-1] == 1 ? 2 : 1)\nputs a.sort.join ' '\n", "positive_code": [{"source_code": "n=gets.to_i;\na=gets.split.map{|x| x.to_i }.sort;\na[n-1]=(a[n-1]==1)?2:1;\na.sort.map{|x| print(x,\" \"); };\nputs();\n"}, {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = (a[-1] == 1 ? 2 : 1)\nputs a.sort.join ' '\n"}, {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = (a[-1] == 1 ? 2 : 1)\nputs a.sort.join ' '\n"}, {"source_code": "gets()\na = gets().split(' ').map(&:to_i).sort()\nif a[-1] == 1 then\n a[-1] = 2\nelse\n a[-1] = 1\n a.sort!()\nend\n\nputs a.join(' ')\n\n"}, {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = (a[-1] == 1 ? 2 : 1)\nputs a.sort.join ' '\n"}, {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = (a[-1] == 1 ? 2 : 1)\nputs a.sort.join ' '"}, {"source_code": "#$stdin = File.open(\"input.txt\")\n#$stdout = File.open(\"output.txt\",\"w\")\n\nN = gets.chomp.to_i\nA = gets.chomp.split.map { |c| c = c.to_i }\nA.sort!\nif A[-1] == 1\n\tA[-1] = 2\nelse\n\tA[-1] = 1\nend\nA.sort!\nputs A.join(\" \")"}, {"source_code": "#!/usr/bin/ruby\n\ndef readNextValues\n return gets.chomp.split.collect {|x| x.to_i }\nend\n\nn = readNextValues\narr = readNextValues\n\nmax_i = 0\nmax_val = 0\n\nfor i in 0..arr.size-1\n if arr[i] > max_val\n max_i = i\n max_val = arr[i]\n end\nend\n\nif max_val == 1\n arr[max_i] = 2\nelse\n arr[max_i] = 1\nend\n\narr.sort!\nputs arr.join(' ')\n"}, {"source_code": "#!/usr/bin/ruby\ndef readNextValues\n return gets.chomp.split.map(&:to_i)\nend\nn = gets.chomp.to_i\narr = readNextValues\n\nmax_val = arr.max\nmax_i = arr.index(max_val)\narr[max_i] = (max_val == 1) ? 2 : 1\n\nputs arr.sort.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\na.sort!\nb=1\nf=false\na.each{|i|\n if i!=1 then\n f=true\n end\n}\ncnt=0\na.each{|i|\n r=i\n if i!=b then\n r=b\n end\n if cnt==n-1 && f==false then\n r=2\n end\n print r\n print \" \"\n b=i\n cnt+=1\n}\n"}, {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = (a[-1] == 1 ? 2 : 1)\nputs a.sort.join ' '\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nif a.max > 1\n i = a.index a.max\n a[i] = 1\nelse\n a[0] = 2\nend\n\nprint a.sort * \" \"\n"}, {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = (a[-1] == 1 ? 2 : 1)\nputs a.sort.join ' '\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i).sort.unshift(1)\nputs a.last==1 ? (\"1 \"*(n-1))+\"2\" : a.take(n)*\" \"\n "}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i).sort.unshift(1)\nputs a.last==1 ? (\"1 \"*(n-1))+\"2\" : a.take(n)*\" \""}, {"source_code": "#=================================\nrequire 'prime'\nrequire 'set'\nrequire 'matrix'\nrequire 'tsort'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\ndata=gets.split.map(&:to_i)\n\ndata.sort!\n\nif data[-1]!=1\n\tdata[-1]=1\nelse\n\tdata[-1]=2\nend\ndata.sort!\n\ndata.each{|v| print \"#{v} \"}\n"}, {"source_code": "gets()\na = gets().split(' ').map(&:to_i).sort()\nif a[-1] == 1 then\n a[-1] = 2\nelse\n a[-1] = 1\n a.sort!()\nend\n\nputs a.join(' ')\n\n"}, {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = (a[-1] == 1 ? 2 : 1)\nputs a.sort.join ' '"}, {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = (a[-1] == 1 ? 2 : 1)\nputs a.sort.join ' '\n"}, {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = (a[-1] == 1 ? 2 : 1)\nputs a.sort.join ' '"}, {"source_code": "#=================================\nrequire 'prime'\nrequire 'set'\nrequire 'matrix'\nrequire 'tsort'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n $stdin = File.open(\"./input.txt\", \"r\")\n ARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\ndata=gets.split.map(&:to_i)\n\ndata.sort!\n\nif data[-1]!=1\n data[-1]=1\nelse\n data[-1]=2\nend\ndata.sort!\n\ndata.each{|v| print \"#{v} \"}"}, {"source_code": "n = gets\np = gets\n=begin\n\n\nfrom = Array.new(n.to_i)\nto = p.split(' ')\ni = 1\nfor el in to\n from[el.to_i-1] = i\n i+=1\nend\nputs from.join(' ').chomp\n=end\n\narr1 = p.chomp.split(' ')\narr2 = []\narr1 = arr1.each{|el| arr2 << el.to_i}\narr1 = arr2.sort\nmax = arr1[-1]\nif max == 1\n puts arr1[0..-2].join(' ').chomp+\" 2\"\nelse\n puts \"1 \" + arr1.sort[0..-2].join(' ')\nend\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i).sort.unshift(1)\nputs a.last==1 ? (\"1 \"*(n-1))+\"2\" : a.take(n)*\" \"\n\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i).sort\n\na[-1] = (a[-1]==1) ? 2 : 1\n\na.sort!\nputs a.join(' ')"}, {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = (a[-1] == 1 ? 2 : 1)\nputs a.sort.join ' '\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\na = a.sort\nif a.pop != 1\n puts ([1]+a).join(\" \")\nelse\n puts (a+[2]).join(\" \")\nend\n"}], "negative_code": [{"source_code": "\nn=gets.to_i\na=gets.split.map(&:to_i)\na.sort\nb=1\nf=false\na.each{|i|\n if i!=1 then\n f=true\n end\n}\ncnt=0\na.each{|i|\n r=i\n if i!=b then\n r=b\n end\n if cnt==n-1 && f==false then\n r=2\n end\n p r\n b=i\n cnt+=1\n}\n"}, {"source_code": "\nn=gets.to_i\na=gets.split.map(&:to_i)\na.sort\nb=1\nf=false\na.each{|i|\n if a[0]!=1 then\n f=true\n end\n}\ncnt=0\na.each{|i|\n r=i\n if i!=b then\n r=b\n end\n if cnt==n-1 && f==false then\n r=2\n end\n p r\n b=i\n}\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\na.sort\nb=1\nf=false\na.each{|i|\n if i!=1 then\n f=true\n end\n}\ncnt=0\na.each{|i|\n r=i\n if i!=b then\n r=b\n end\n if cnt==n-1 && f==false then\n r=2\n end\n print r\n print \" \"\n b=i\n cnt+=1\n}\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\na.sort\nb=1\na.each{|i|\n r=i\n if i!=b then\n r=b\n end\n p r\n b=i\n}\n"}, {"source_code": "gets(); puts ([1] + gets().split(' ').map(&:to_i).sort()[0..-2]).join(' ')\n"}, {"source_code": "gets()\na = gets().split(' ').map(&:to_i).sort()\nif a[-1] == 1 then\n a[-1] = 2\nelse\n a[0] = 1\nend\n\nputs a.join(' ')\n\n"}, {"source_code": "gets()\nputs ([1] + gets().split(' ').map(&:to_i).sort()[0..-2]).join(' ')\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\n\nif a[-1] == 1\n a[-1] = 2\nelse\n a[-1] = 1\n a.sort!\nend\n \nputs a.join(' ')"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\n\na[-1] = (a[-1]==1) ? 2 : 1\n\na.sort!\nputs a.join(' ')"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\na = [1]+a.sort\na.pop\nputs a.join(\" \")\n"}, {"source_code": "a = STDIN.readlines[1].split.map(&:to_i).sort\na[-1] = 1\nputs a.sort.join ' '"}, {"source_code": "#!/usr/bin/ruby\n\ndef readNextValues\n return gets.chomp.split.collect {|x| x.to_i }\nend\n\nn = readNextValues\narr = readNextValues\n\nmax_i = 0\nmax_val = 0\nfor i in 0..arr.size-1\n if arr[i] > max_i\n max_i = i\n max_val = arr[i]\n end\nend\n\nif max_val == 1\n arr[max_i] = 2\nelse\n arr[max_i] = 1\nend\n\narr.sort!\nputs arr.join(' ')\n"}, {"source_code": "#!/usr/bin/ruby\n\ndef readNextValues\n return gets.chomp.split.collect {|x| x.to_i }\nend\n\nn = readNextValues\narr = readNextValues\n\nmax_i = 0\nmax_val = 0\n\nfor i in 0..arr.size-1\n if arr[i] > max_i\n max_i = i\n max_val = arr[i]\n end\nend\n\nif max_val == 1\n arr[max_i] = 2\nelse\n arr[max_i] = 1\nend\n\narr.sort!\nputs arr.join(' ')\n"}, {"source_code": "#!/usr/bin/ruby\n\ndef readNextValues\n return gets.chomp.split.collect {|x| x.to_i }\nend\n\nn = readNextValues\narr = readNextValues\n\nmax_i = 0\nmax_val = 0\nfor i in 0..arr.size-1\n if arr[i] > max_i\n max_i = i\n max_val = arr[i]\n end\nend\n\nif max_val == 1\n arr[i] = 2\nelse\n arr[i] = 1\nend\n\narr.sort!\nputs arr.join(' ')\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nif a.max > 1\n i = a.index a.max\n a[i] = 1\nend\n\nprint a.sort * \" \"\n"}, {"source_code": "#=================================\nrequire 'prime'\nrequire 'set'\nrequire 'matrix'\nrequire 'tsort'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\ndata=gets.split.map(&:to_i)\n\ndata.sort!\ndata[-1]=1\ndata.sort!\n\ndata.each{|v| print \"#{v} \"}\n"}, {"source_code": "n = gets\np = gets\n=begin\n\n\nfrom = Array.new(n.to_i)\nto = p.split(' ')\ni = 1\nfor el in to\n from[el.to_i-1] = i\n i+=1\nend\nputs from.join(' ').chomp\n=end\n\narr1 = p.chomp.split(' ')\narr1 = arr1.sort\nmax = arr1[-2]\nif max == '1'\n puts arr1[0..-2].join(' ').chomp+\" 2\"\nelse\n puts \"1 \" + arr1.sort[0..-2].join(' ')\nend\n"}, {"source_code": "n = gets\np = gets\narr1 = p.chomp.split(' ')\narr1 = arr1.sort\nmax = arr1[-2]\ni=1\nif max == 1\n i = 2\nend\nputs \"#{i} \" + arr1.sort[0..-2].join(' ')\n"}, {"source_code": "n = gets\np = gets\n=begin\n\n\nfrom = Array.new(n.to_i)\nto = p.split(' ')\ni = 1\nfor el in to\n from[el.to_i-1] = i\n i+=1\nend\nputs from.join(' ').chomp\n=end\n\narr1 = p.chomp.split(' ')\narr2 = []\narr1 = arr1.each{|el| arr2 << el.to_i}\narr1 = arr2.sort\nmax = arr1[-1]\nif max == '1'\n puts arr1[0..-2].join(' ').chomp+\" 2\"\nelse\n puts \"1 \" + arr1.sort[0..-2].join(' ')\nend\n"}, {"source_code": "n = gets\np = gets\narr1 = p.chomp.split(' ')\nputs '1 ' + arr1.sort[0..-1].join(' ')\n"}, {"source_code": "n = gets\np = gets\n=begin\n\n\nfrom = Array.new(n.to_i)\nto = p.split(' ')\ni = 1\nfor el in to\n from[el.to_i-1] = i\n i+=1\nend\nputs from.join(' ').chomp\n=end\n\narr1 = p.chomp.split(' ')\narr1 = arr1.sort\nmax = arr1[-1]\nif max == '1'\n puts arr1[0..-2].join(' ').chomp+\" 2\"\nelse\n puts \"1 \" + arr1.sort[0..-2].join(' ')\nend\n"}, {"source_code": "n = gets\np = gets\narr1 = p.chomp.split(' ')\nputs '1 ' + arr1.sort[0..-2].join(' ')"}, {"source_code": "n = gets\np = gets\n=begin\n\n\nfrom = Array.new(n.to_i)\nto = p.split(' ')\ni = 1\nfor el in to\n from[el.to_i-1] = i\n i+=1\nend\nputs from.join(' ').chomp\n=end\n\narr1 = p.chomp.split(' ')\narr1 = arr1.sort\nmax = arr1[-1]\nputs max\nif max == '1'\n puts arr1[0..-2].join(' ').chomp+\" 2\"\nelse\n puts \"1 \" + arr1.sort[0..-2].join(' ')\nend\n"}, {"source_code": "n = gets\np = gets\narr1 = p.chomp.split(' ')\narr1 = arr1.sort\nmax = arr1[-2]\nif max == 1\n puts arr1.sort[0..-2].join(' ')+\" 2\"\nelse\n puts \"1 \" + arr1.sort[0..-2].join(' ')\nend\n"}, {"source_code": "n=gets.to_i\nputs (\"1 \"+gets).split.map(&:to_i).sort.take(n)*\" \"\n\n"}], "src_uid": "1cd10f01347d869be38c08ad64266870"} {"source_code": "a, b, c = gets.split.map(&:to_i)\nif a == 0\n\tif b == 0\n\t\tputs c == 0 ? -1 : 0\n\telse\n\t\tputs 1\n\t\tputs \"%.10f\" % (-1.0 * c / b)\n\tend\nelse\n\td = b * b - 4 * a * c\n\tif d < 0\n\t\tputs 0\n\telsif d == 0\n\t\tputs 1\n\t\tputs \"%.10f\" % (-b / (2.0 * a))\n\telse\n\t\tdd = Math.sqrt(d)\n\t\tputs 2\n\t\t[(-b - dd) / (2.0 * a), (-b + dd) / (2.0 * a)].sort.each { |v| puts \"%.10f\" % v }\n\tend\nend\n", "positive_code": [{"source_code": "input=gets.split.map(&:to_i)\na=input[0]\nb=input[1]\nc=input[2]\nif a<0 then\n b=-b\n c=-c\n a=-a\nend\nd=b*b-4*a*c\nif a==0 then\n if b==0 then\n if c==0 then\n puts -1\n else\n puts 0\n end\n else\n puts 1\n printf \"%.7f\\n\",-c*1.0/b\n end\nelsif d==0 then\n puts 1\n printf \"%.7f\\n\",-b/(2*a)\nelsif d>0 then\n puts 2\n printf \"%.7f\\n\",(-b-Math::sqrt(d))/(2*a)\n printf \"%.7f\\n\",(-b+Math::sqrt(d))/(2*a)\nelse\n puts 0\nend\n\n"}, {"source_code": "(a,b,c)=gets.split.map{|i|i=i.to_i}\nif a==0\n if b==0 then puts c==0?\"-1\":\"0\";exit end\n puts \"1\";p -c.to_f/b;exit\nend\nif (d=b*b-4*a*c)<0 then puts \"0\";exit end\nif d==0 then puts \"1\";p -b.to_f/2/a;exit end\nputs \"2\"\nif a<0 then a=-a;b=-b;c=-c end\np (-b-Math.sqrt(d))/2/a,(-b+Math.sqrt(d))/2/a"}, {"source_code": "def printAns(num)\n printf(\"%10.10f\\n\",num)\nend\nc=gets.chomp.split.map{|i| i.to_i}\nif c[0]==0\n if c[1]==0\n if c[2]==0\n puts(-1)\n else\n puts(0)\n end\n else\n puts(1)\n printAns(-c[2].to_f/c[1].to_f)\n end\nelse\n D=c[1]*c[1]-4*c[0]*c[2]\n if D<0 \n puts(0)\n exit\n elsif D==0\n puts(1)\n ans=-c[1].to_f/(2.0*c[0].to_f)\n printAns(ans)\n else\n puts(2)\n r=Math.sqrt(D)\n if c[0] < 0\n c[0]=-c[0]\n c[1]=-c[1]\n end\n printAns((-c[1].to_f-r)/(2*c[0]))\n printAns((-c[1].to_f+r)/(2*c[0]))\n end\nend\n"}, {"source_code": "def printAns(num)\n printf(\"%10.10f\\n\",num)\nend\n(a,b,c)=gets.chomp.split.map{|i| i.to_i}\nif a==0\n if b==0\n if c==0\n puts(-1)\n else\n puts(0)\n end\n else\n puts(1)\n printAns(-c.to_f/b.to_f)\n end\nelse\n D=b*b-4*a*c\n if D<0 \n puts(0)\n exit\n elsif D==0\n puts(1)\n ans=-b.to_f/(2.0*a.to_f)\n printAns(ans)\n else\n puts(2)\n r=Math.sqrt(D)\n if a < 0\n a=-a\n b=-b\n end\n printAns((-b.to_f-r)/(2*a))\n printAns((-b.to_f+r)/(2*a))\n end\nend\n"}, {"source_code": "(a,b,c)=gets.split.map{|i|i=i.to_i}\nif a==0\n if b==0 then puts c==0?\"-1\":\"0\";exit end\n puts \"1\";p -c.to_f/b;exit\nend\nif (d=b*b-4*a*c)<0 then puts \"0\";exit end\nif d==0 then puts \"1\";p -b.to_f/2/a;exit end\nputs \"2\"\nif a<0 then a=-a;b=-b;c=-c end\np (-b-Math.sqrt(d))/2/a,(-b+Math.sqrt(d))/2/a"}, {"source_code": "(a,b,c)=gets.split.map{|i|i=i.to_i}\nif a==0&&b==0 then puts c==0?\"-1\":\"0\";exit end\nif a==0\n puts \"1\"\n printf \"%.9f\\n\", -c.to_f/b\n exit\nend\nif (d=b*b-4*a*c)<0 then puts \"0\";exit end\nif d==0\n puts \"1\"\n printf \"%.9f\\n\", -b.to_f/2/a\n exit\nend\nputs \"2\"\nif a<0 then a=-a;b=-b;c=-c end\nprintf \"%.9f\\n\", (-b-Math.sqrt(d))/2/a\nprintf \"%.9f\\n\", (-b+Math.sqrt(d))/2/a\n"}, {"source_code": "(a,b,c)=gets.split.map{|i|i=i.to_i}\nif a==0&&b==0 then puts c==0?\"-1\":\"0\";exit end\nif a==0\n puts \"1\"\n printf \"%.9f\\n\", -c.to_f/b\n exit\nend\nif (d=b*b-4*a*c)<0 then puts \"0\";exit end\nif d==0\n puts \"1\"\n printf \"%.9f\\n\", -b.to_f/2/a\n exit\nend\nputs \"2\"\nif a<0 then a=-a;b=-b;c=-c end\np (-b-Math.sqrt(d))/2/a\np (-b+Math.sqrt(d))/2/a\n"}], "negative_code": [{"source_code": "(a,b,c)=gets.split.map{|i|i=i.to_i}\nif a==0&&b==0 then puts c==0?\"-1\":\"0\";exit end\nif a==0\n puts \"1\"\n printf \"%.9f\\n\", -b.to_f/c\n exit\nend\nif (d=b*b-4*a*c)<0 then puts \"0\";exit end\nif d==0\n puts \"1\"\n printf \"%.9f\\n\", -b.to_f/2/a\n exit\nend\nputs \"2\"\nif a<0 then a=-a;b=-b;c=-c end\nprintf \"%.9f\\n\", (-b-Math.sqrt(d))/2/a\nprintf \"%.9f\\n\", (-b+Math.sqrt(d))/2/a\n"}, {"source_code": "(a,b,c)=gets.split.map{|i|i=i.to_i}\nif a==0&&b==0 then puts c==0?\"-1\":\"0\";exit end\nif a==0\n puts \"1\"\n p -b.to_f/c\n exit\nend\nif (d=b*b-4*a*c)<0 then puts \"0\";exit end\nif d==0\n puts \"1\"\n p -b.to_f/2/a\n exit\nend\nputs \"2\"\np (-b+Math.sqrt(d))/2/a\np (-b-Math.sqrt(d))/2/a\n"}, {"source_code": "(a,b,c)=gets.split.map{|i|i=i.to_i}\nif a==0&&b==0 then puts c==0?\"-1\":\"0\";exit end\nif a==0\n puts \"1\"\n printf \"%.9f\\n\", -b.to_f/c\n exit\nend\nif (d=b*b-4*a*c)<0 then puts \"0\";exit end\nif d==0\n puts \"1\"\n printf \"%.9f\\n\", -b.to_f/2/a\n exit\nend\nputs \"2\"\nprintf \"%.9f\\n\", (-b-Math.sqrt(d))/2/a\nprintf \"%.9f\\n\", (-b+Math.sqrt(d))/2/a\n"}, {"source_code": "(a,b,c)=gets.split.map{|i|i=i.to_i}\nif a==0&&b==0 then puts c==0?\"-1\":\"0\";exit end\nif a==0\n puts \"1\"\n printf \"%.9f\\n\", -b.to_f/c\n exit\nend\nif (d=b*b-4*a*c)<0 then puts \"0\";exit end\nif d==0\n puts \"1\"\n printf \"%.9f\\n\", -b.to_f/2/a\n exit\nend\nputs \"2\"\nprintf \"%.9f\\n\", (-b+Math.sqrt(d))/2/a\nprintf \"%.9f\\n\", (-b-Math.sqrt(d))/2/a\n"}, {"source_code": "input=gets.split.map(&:to_i)\na=input[0]\nb=input[1]\nc=input[2]\nd=b*b-4*a*c\nif d==0 then\n puts 1\n printf \"%.7f\\n\",-b/(2*a)\nelsif d>0 then\n puts 2\n printf \"%.7f\\n\",(-b-Math::sqrt(d))/(2*a)\n printf \"%.7f\\n\",(-b+Math::sqrt(d))/(2*a)\nelse\n puts 0\nend\n"}, {"source_code": "input=gets.split.map(&:to_i)\na=input[0]\nb=input[1]\nc=input[2]\nif a<0 then\n b=-b\n c=-c\n a=-c\nend\nd=b*b-4*a*c\nif a==0 then\n if b==0 then\n if c==0 then\n puts -1\n else\n puts 0\n end\n else\n puts 1\n printf \"%.7f\\n\",-c*1.0/b\n end\nelsif d==0 then\n puts 1\n printf \"%.7f\\n\",-b/(2*a)\nelsif d>0 then\n puts 2\n printf \"%.7f\\n\",(-b-Math::sqrt(d))/(2*a)\n printf \"%.7f\\n\",(-b+Math::sqrt(d))/(2*a)\nelse\n puts 0\nend\n\n"}, {"source_code": "input=gets.split.map(&:to_i)\na=input[0]\nb=input[1]\nc=input[2]\nd=b*b-4*a*c\nif a==0 then\n if b==0 then\n if c==0 then\n puts -1\n else\n puts 0\n end\n else\n puts 1\n printf \"%.7f\\n\",-c*1.0/b\n end\nelsif d==0 then\n puts 1\n printf \"%.7f\\n\",-b/(2*a)\nelsif d>0 then\n puts 2\n printf \"%.7f\\n\",(-b-Math::sqrt(d))/(2*a)\n printf \"%.7f\\n\",(-b+Math::sqrt(d))/(2*a)\nelse\n puts 0\nend\n\n"}, {"source_code": "input=gets.split.map(&:to_i)\na=input[0]\nb=input[1]\nc=input[2]\nd=b*b-4*a*c\nif a==0 then\n puts 1\n printf \"%.7f\\n\",-c*1.0/b\nelsif d==0 then\n puts 1\n printf \"%.7f\\n\",-b/(2*a)\nelsif d>0 then\n puts 2\n printf \"%.7f\\n\",(-b-Math::sqrt(d))/(2*a)\n printf \"%.7f\\n\",(-b+Math::sqrt(d))/(2*a)\nelse\n puts 0\nend\n\n"}, {"source_code": "def printAns(num)\n printf(\"%10.10f\\n\",num)\nend\nc=gets.chomp.split.map{|i| i.to_i}\nif c[0]==0\n if c[1]==0\n if c[2]==0\n puts(-1)\n else\n puts(0)\n end\n else\n puts(1)\n printAns(-c[2].to_f/c[1].to_f)\n end\nelse\n D=c[1]*c[1]-4*c[0]*c[2]\n if D<0 \n puts(0)\n exit\n elsif D==0\n puts(1)\n ans=-c[1]/(2*c[0])\n printAns(ans)\n else\n puts(2)\n r=Math.sqrt(D)\n printAns((-c[1]-r)/(2*c[0]))\n printAns((-c[1]+r)/(2*c[0]))\n end\nend\n"}, {"source_code": "def printAns(num)\n printf(\"%10.10f\\n\",num)\nend\nc=gets.chomp.split.map{|i| i.to_i}\nif c[0]==0\n if c[1]==0\n if c[2]==0\n puts(-1)\n else\n puts(0)\n end\n else\n puts(1)\n printAns(-c[2]/c[1])\n end\nelse\n D=c[1]*c[1]-4*c[0]*c[2]\n if D<0 \n puts(0)\n exit\n elsif D==0\n puts(1)\n ans=-c[1]/(2*c[0])\n printAns(ans)\n else\n puts(2)\n r=Math.sqrt(D)\n printAns((-c[1]-r)/(2*c[0]))\n printAns((-c[1]+r)/(2*c[0]))\n end\nend\n"}, {"source_code": "def printAns(num)\n printf(\"%10.10f\\n\",num)\nend\nc=gets.chomp.split.map{|i| i.to_i}\nif c[0]==0\n if c[1]==0\n if c[2]==0\n puts(-1)\n else\n puts(0)\n end\n else\n puts(1)\n printAns(-c[2].to_f/c[1].to_f)\n end\nelse\n D=c[1]*c[1]-4*c[0]*c[2]\n if D<0 \n puts(0)\n exit\n elsif D==0\n puts(1)\n ans=-c[1].to_f/(2.0*c[0].to_f)\n printAns(ans)\n else\n puts(2)\n r=Math.sqrt(D)\n printAns((-c[1].to_f-r)/(2*c[0]))\n printAns((-c[1].to_f+r)/(2*c[0]))\n end\nend\n"}, {"source_code": "def printAns(num)\n printf(\"%10.10f\\n\",num)\nend\nc=gets.chomp.split.map{|i| i.to_i}\nif c[0]==0\n if c[1]==0\n if c[2]==0\n puts(-1)\n else\n puts(0)\n end\n else\n puts(1)\n printAns(-c[2].to_f/c[1].to_f)\n end\nelse\n D=c[1]*c[1]-4*c[0]*c[2]\n if D<0 \n puts(0)\n exit\n elsif D==0\n puts(1)\n ans=-c[1].to_f/(2*c[0].to_f)\n printAns(ans)\n else\n puts(2)\n r=Math.sqrt(D)\n printAns((-c[1]-r)/(2*c[0]))\n printAns((-c[1]+r)/(2*c[0]))\n end\nend\n"}, {"source_code": "def printAns(num)\n printf(\"%10.10f\\n\",num)\nend\nc=gets.chomp.split.map{|i| i.to_i}\nif c[0]==0\n if c[1]==0\n if c[2]==0\n puts(-1)\n else\n puts(0)\n end\n else\n puts(1)\n printAns(c[2]/c[1])\n end\nelse\n D=c[1]*c[1]-4*c[0]*c[2]\n if D<0 \n puts(0)\n exit\n elsif D==0\n puts(1)\n ans=-c[1]/(2*c[0])\n printAns(ans)\n else\n puts(2)\n r=Math.sqrt(D)\n printAns((-c[1]-r)/(2*c[0]))\n printAns((-c[1]+r)/(2*c[0]))\n end\nend\n"}, {"source_code": "def printAns(num)\n printf(\"%10.10f\\n\",num)\nend\nc=gets.chomp.split.map{|i| i.to_i}\nif c[0]==0\n if c[1]==0\n if c[2]==0\n puts(-1)\n else\n puts(0)\n end\n else\n puts(1)\n printAns(c[2]/c[1])\n end\nelse\n D=c[1]*c[1]-4*c[0]*c[2]\n if D<0 \n puts(0)\n exit\n elsif D==0\n puts(1)\n ans=-c[1]/(2*c[0])\n printAns(ans)\n else\n puts(2)\n r=Math.sqrt(D)\n printAns((-c[1]+r)/(2*c[0]))\n printAns((-c[1]-r)/(2*c[0]))\n end\nend\n"}, {"source_code": "a, b, c = gets.split.map(&:to_i)\nif a == 0\n\tif b == 0\n\t\tputs c == 0 ? -1 : 0\n\telse\n\t\tputs 1\n\t\tputs \"%.10f\" % (-c / b)\n\tend\nelse\n\td = b * b - 4 * a * c\n\tif d < 0\n\t\tputs 0\n\telsif d == 0\n\t\tputs 1\n\t\tputs \"%.10f\" % (-b / (2 * a))\n\telse\n\t\tdd = Math.sqrt(d)\n\t\tputs 2\n\t\t[(-b - dd) / (2 * a), (-b + dd) / (2 * a)].sort.each { |v| puts \"%.10f\" % v }\n\tend\nend\n"}, {"source_code": "a, b, c = gets.split.map(&:to_i)\nif a == 0\n\tif b == 0\n\t\tputs c == 0 ? -1 : 0\n\telse\n\t\tputs 1\n\t\tputs -c / b\n\tend\nelse\n\td = b * b - 4 * a * c\n\tif d < 0\n\t\tputs 0\n\telsif d == 0\n\t\tputs 1\n\t\tputs -b / (2 * a)\n\telse\n\t\tdd = Math.sqrt(d)\n\t\tputs 2\n\t\tputs [(-b - dd) / (2 * a), (-b + dd) / (2 * a)].sort\n\tend\nend\n"}], "src_uid": "84372885f2263004b74ae753a2f358ac"} {"source_code": "N = gets.to_i\ndef check(n, a)\n a.sort!\n return 0 if a.any? {|x|\n (x < 0 || x.to_i != x)\n }\n t = n - a[2] * 2 + a[1] + a[0]\n return 0 if t < 0 || t % 3 != 0\n 1\nend\n\nN.times{\n\tn,k,d1,d2=gets.split.map{|i| i.to_i}\n\tn-=k\n\tf=0\n\ty=(k+d2-d1)/3.0\n\tx=y+d1\n\tz=y-d2\n\tf|=check(n,[x,y,z])\n\ty=(k-d2-d1)/3.0\n\tx=y+d1\n\tz=y+d2\n\tf|=check(n,[x,y,z])\n\ty=(k+d2+d1)/3.0\n\tx=y-d1\n\tz=y-d2\n\tf|=check(n,[x,y,z])\n\ty=(k-d2+d1)/3.0\n\tx=y-d1\n\tz=y+d2\n\tf|=check(n,[x,y,z])\n\tputs (f==1) ? 'yes' : 'no'\n}", "positive_code": [{"source_code": "def check(n,a)\n\ta.sort!\n\treturn 0 if a.any?{|x| (x<0 || x.to_i!=x)}\n\tt=n-a[2]*2+a[1]+a[0]\n\treturn 0 if t<0 || t%3!=0\n\t1\nend\nm=gets.to_i\nm.times{\n\tn,k,d1,d2=gets.split.map{|i| i.to_i}\n\tn-=k\n\tf=0\n\ty=(k+d2-d1)/3.0\n\tx=y+d1\n\tz=y-d2\n\tf|=check(n,[x,y,z])\n\ty=(k-d2-d1)/3.0\n\tx=y+d1\n\tz=y+d2\n\tf|=check(n,[x,y,z])\n\ty=(k+d2+d1)/3.0\n\tx=y-d1\n\tz=y-d2\n\tf|=check(n,[x,y,z])\n\ty=(k-d2+d1)/3.0\n\tx=y-d1\n\tz=y+d2\n\tf|=check(n,[x,y,z])\n\tputs (f==1) ? 'yes' : 'no'\n}"}, {"source_code": "n = gets.chomp.to_i\n\ndef sol_win(n, k, win)\n\tround = n / 3\n\tok = true\n\twin.each do |i|\n\t\tok = false if i > round\n\tend\n\tok\nend\n\ndef sol_real(n, k, d1, d2)\n\twin = []\n\tif (k - (d1 + d2)) % 3 != 0\n\t\treturn false\n\telse\n\t\tt = (k - (d1 + d2)) / 3\n\t\tif t >= 0 and t + d1 >= 0 and t + d2 >= 0\n\t\t\twin = [t + d1, t, t + d2]\n\t\t\treturn sol_win(n, k, win)\n\t\telse\n\t\t\treturn false\n\t\tend\n\tend\nend\n\n# use second team as t\ndef sol(n, k, d1, d2)\n\tif n % 3 != 0\n\t\treturn false\n\tend\n\tsol_real(n, k, d1, d2) or sol_real(n, k, -d1, d2) or sol_real(n, k, d1, -d2) or sol_real(n, k, -d1, -d2)\nend\n\n\nn.times do\n\tn, k, d1, d2 = gets.chomp.split.map{|i| i.to_i}\n\tif sol(n, k, d1, d2)\n\t\tputs \"yes\"\n\telsif\n\t\tputs \"no\"\n\tend\nend\n"}, {"source_code": "N = gets.to_i\ndef check(n, a)\n a.sort!\n return 0 if a.any? {|x|\n (x < 0 || x.to_i != x)\n }\n t = n - a[2] * 2 + a[1] + a[0]\n return 0 if t < 0 || t % 3 != 0\n 1\nend\n\nN.times{\n\tn,k,d1,d2=gets.split.map{|i| i.to_i}\n\tn-=k\n\tf=0\n\ty=(k+d2-d1)/3.0\n\tx=y+d1\n\tz=y-d2\n\tf|=check(n,[x,y,z])\n\ty=(k-d2-d1)/3.0\n\tx=y+d1\n\tz=y+d2\n\tf|=check(n,[x,y,z])\n\ty=(k+d2+d1)/3.0\n\tx=y-d1\n\tz=y-d2\n\tf|=check(n,[x,y,z])\n\ty=(k-d2+d1)/3.0\n\tx=y-d1\n\tz=y+d2\n\tf|=check(n,[x,y,z])\n\tputs (f==1) ? 'yes' : 'no'\n}"}], "negative_code": [{"source_code": "def check(n,a)\n\ta.sort!\n\treturn 0 if a.one?{|x| (x<0 || x.to_i!=x)}\n\tt=n-a[2]*2+a[1]+a[0]\n\treturn 0 if t<0 || t%3!=0\n\t1\nend\nm=gets.to_i\nm.times{\n\tn,k,d1,d2=gets.split.map{|i| i.to_i}\n\tn-=k\n\tf=0\n\ty=(k+d2-d1)/3.0\n\tx=y+d1\n\tz=y-d2\n\tf|=check(n,[x,y,z])\n\ty=(k-d2-d1)/3.0\n\tx=y+d1\n\tz=y+d2\n\tf|=check(n,[x,y,z])\n\ty=(k+d2+d1)/3.0\n\tx=y-d1\n\tz=y-d2\n\tf|=check(n,[x,y,z])\n\ty=(k-d2+d1)/3.0\n\tx=y-d1\n\tz=y+d2\n\tf|=check(n,[x,y,z])\n\tputs (f==1) ? 'yes' : 'no'\n}\n"}], "src_uid": "324298100f3e36d289ef6ca8178ac6d3"} {"source_code": "a=[*$<][1].split;p (?1..?1*3).inject(0){|i,j|i+a.count(j)/2}/2\n", "positive_code": [{"source_code": "n = STDIN.gets.chomp.to_i\nlength = STDIN.gets.chomp.split(' ').map{|i| i.to_i}\narr = length.inject(Array.new(101).fill(0)) {|res, i| res[i] += 1; res}\nputs arr.reduce(0){|tot, i| tot += (i / 2)} / 2"}, {"source_code": "gets\np gets.split.map(&:to_i).group_by{|x|x}.map{|x|x[1].size/2}.inject(:+)/2\n"}, {"source_code": "gets\np gets.split.map(&:to_i).group_by{|x|x}.inject(0){|s,x|s+x[1].size/2}/2\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\ncnt=Hash.new\ncnt.default=0\na.each{|i| cnt[i]+=1 }\nans=0\n1.upto(100){|i| ans+=cnt[i]/2 }\np ans/2\n"}, {"source_code": "a=[*$<][1].split;p (?1..?1*3).inject(0){|i,j|i+a.count(j)/2}/2\n"}, {"source_code": "a=[*$<][1].split;p (?1..?1*3).inject(0){|i,j|i+a.count(j)/2}/2\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = $stdin.readline().to_i\n\nlens = ($stdin.readline().split().collect {|x| x.to_i})\n\ndef uniq(a)\n\tresult = Array.new\n\tprev = nil\n\tcount = 0\n\ta.sort.each { |x|\n\t\tif x != prev\n\t\t\tresult << [prev, count] unless prev == nil\n\t\t\tprev = x\n\t\t\tcount = 1\n\t\telse\n\t\t\tcount += 1\n\t\tend\n\t}\n\tresult << [prev, count]\nend\n\npairs = 0\n\nuniq(lens).each { |r|\n\tpairs += (r[1]/2).floor\n}\n\nputs (pairs/2).floor\n"}, {"source_code": "n = STDIN.readline.to_i\nsticks = STDIN.readline.split.map {|s| s.to_i }\ncount = {}\nsticks.each do |stick|\n if count.include? stick\n count[stick] += 1\n else\n count[stick] = 1\n end\nend\npairs = 0\ncount.values.each {|value| pairs += value/2 }\nputs pairs/2\n"}, {"source_code": "gets\nd = {}\nd.default = 0\ngets.split().map(&:to_i).each{|e| d[e] += 1 }\n\nret = 0\nd.each_value{ |e| ret += e/2 }\n\np ret / 2\n"}, {"source_code": "s,n=0,(gets.to_i)\na=gets.split.map &:to_i\n0.upto 101 do |i| s+=a.count(i)/2 end\nputs s/2"}, {"source_code": "a=[*$<][1].split;p (?1..?1*3).inject(0){|i,j|i+a.count(j)/2}/2"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\ngets.split.map(&:to_i).each { |x| h[x] += 1}\nputs h.values.map { |x| x/2}.inject(:+) / 2"}, {"source_code": "a=[*$<][1].split;p (?1..?1*3).inject(0){|i,j|i+a.count(j)/2}/2\n"}, {"source_code": "a=[*$<][1].split;p (?1..?1*3).inject(0){|i,j|i+a.count(j)/2}/2\n"}, {"source_code": "a=[*$<][1].split;p (?1..?1*3).inject(0){|i,j|i+a.count(j)/2}/2"}, {"source_code": "a=[*$<][1].split;p (?1..?1*3).inject(0){|i,j|i+a.count(j)/2}/2"}, {"source_code": "gets;h=Hash.new(0);d=gets.split.map(&:to_i).each{|_| h[_]+=1}\np h.values.map{|_| _%2!=0 ?\t_-1\t: _ }.inject(:+)/4\n"}, {"source_code": "gets\nhs=Hash.new(0)\ndata=gets.split.map(&:to_i).each{|v| hs[v]+=1}\nputs hs.values.map{|_| _%2!=0 ?\t_-1\t: _ }.inject(:+)/4\n"}, {"source_code": "n = gets.to_i\na = Array.new(101,0)\nvs = gets.split.map(&:to_i)\nvs.each do |v|\n\ta[v] += 1\nend\nans = 0\nfor i in 1..100 do\n ans += (a[i].div(2))\nend\np ans.div(2)\n"}, {"source_code": "a=[*$<][1].split;p (?1..?1*3).inject(0){|i,j|i+a.count(j)/2}/2\n"}, {"source_code": "n = gets.to_i\na = Hash.new(0)\ngets.split.each{|i| a[i]+=1}\ncnt = 0\na.each{|key,value| cnt+=value/2}\nputs cnt/2\n"}, {"source_code": "gets\nsticks = gets.split.map(&:to_i)\np sticks.uniq.inject(0) {|sumstick, _| sumstick += (sticks.count(_) / 2)} / 2"}, {"source_code": "gets\nputs gets.split.map { |x| x.to_i }.inject(Hash.new(0)) { |h, e| h[e] += 1; h }.values.map { |x| x - x % 2 }.inject(:+) / 4"}, {"source_code": "n = gets.to_i\na = gets().split.map { |elem| elem.to_i }\n\npairs_count = 0\n\nfor i in 1..(n-1)\n for j in 0..(i - 1)\n if (a[i] == a[j])\n a[i] = 0\n a[j] = 0\n pairs_count += 1\n break\n end\n end\nend\n\nputs (pairs_count / 2).to_i\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\nl = []\ndem = 0\n\n(0..n-1).each do |i|\n l[i] = 0\nend\n\n(0..n-2).each do |i|\n if l[i] == 0 \n (i+1..n-1).each do |j|\n if a[i] == a[j] && l[j] == 0\n l[i] = 1\n l[j] = 1\n dem += 1\n break\n end\n end\n end\nend\n\nputs dem/2"}, {"source_code": "gets\na, ans = Array.new(101,0), 0\ngets.split.map{ |x| a[x.to_i] += 1 }\na.each{ |x| ans += x/2 }\np ans/2"}, {"source_code": "a=[*$<][1].split;p (?1..?1*3).inject(0){|i,j|i+a.count(j)/2}/2\n"}, {"source_code": "a=[*$<][1].split;p (?1..?1*3).inject(0){|i,j|i+a.count(j)/2}/2\n"}], "negative_code": [], "src_uid": "f9b56b3fddcd5db0d0671714df3f8646"} {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nans = 0\nnnegatives = 0\nnzeros = 0\na.each do |x|\n if x >= 1\n ans += x - 1\n elsif x <= -1\n ans += -1 - x\n nnegatives += 1\n else\n ans += 1\n nzeros += 1\n end\nend\nans += 2 if nnegatives%2 != 0 and nzeros == 0\nputs ans\n", "positive_code": [{"source_code": "n = readline.to_i\na = readline.split.map(&:to_i)\n\nans = 0\nneg_c = 0\nzero_c = 0\na.each do |v|\n if v < 0\n neg_c += 1\n elsif v == 0\n zero_c += 1\n end\n \n ans += (v.abs-1).abs\nend\n\nif neg_c.odd? && zero_c == 0\n ans += 2\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\nsum = 0\nnegOne = 0\nposOne = 0\nzero = 0\narr = gets.split.map(&:to_i)\narr.each_with_index do |x, i|\n if x < 0\n sum += (x - (-1)).abs\n arr[i] = -1\n negOne += 1\n elsif x > 0\n sum += (x - 1).abs\n arr[i] = 1\n posOne += 1\n else\n zero += 1\n end\nend\nif negOne %2 != 0\n if zero > 0\n sum += 1\n negOne += 1\n zero -= 1\n else\n sum += 2\n negOne -= 1\n posOne += 1\n end\nend\nprint(sum + zero)"}, {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\n\nnegative_count = as.count { |a| a < 0 }\nzero_count = as.count { |a| a == 0 }\n\nans = 0\nas.each do |a|\n ans += [(a-(-1)).abs, (a-1).abs].min\nend\nif negative_count.odd?\n if zero_count > 0\n else\n ans += 2\n end\nend\n\nputs ans\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\na = gets.split.map(&:to_i)\ncoins = 0\nnegs, zeroes, poss = 0, 0, 0\na.each { |i|\n if i < 0\n negs += 1\n coins += -1 - i\n elsif i == 0\n zeroes += 1\n else\n poss += 1\n coins += i - 1\n end\n}\n\n# not handled zeroes yet!\nif negs.odd?\n if zeroes > 0\n zeroes -= 1\n coins += 1 # for zeroes, flipping to -1 or +1 only costs one coin\n else\n coins += 2 # have to pay two coins to flip -1 to +1 or +1 to -1\n end\nend\n\n# handle remaining zeroes\ncoins += zeroes\n\nputs coins\n"}, {"source_code": "n = gets.to_i\naa = gets.split.map(&:to_i).sort\n\ncost = 0\nplus_sum = 0\nminus_sum = 0\nplus_cnt = 0\nminus_cnt = 0\nzero_cnt = 0\n\naa.each do |a|\n if a<0\n minus_cnt+=1\n minus_sum+=a\n elsif a==0\n zero_cnt+=1\n else\n plus_cnt+=1\n plus_sum+=a\n end\nend\n\ncost += (-minus_sum - minus_cnt) + zero_cnt + (plus_sum - plus_cnt)\n# \u30de\u30a4\u30ca\u30b9\u304c\u5947\u6570\u500b\u306e\u5834\u5408\u306f\u30d7\u30e9\u30b9\u306b\u306a\u308b\u3088\u3046\u306b\u8abf\u6574\u3059\u308b\ncost += 2 if minus_cnt%2==1 && zero_cnt==0\nputs cost"}], "negative_code": [{"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\n\nnegative_count = as.count { |a| a < 0 }\nzero_count = as.count { |a| a == 0 }\n\nans = 0\nas.each do |a|\n ans += [(a-(-1)).abs, (a-1).abs].min\nend\nif negative_count.odd?\n if zero_count > 0\n ans += 1\n else\n ans += 2\n end\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\n\nnegative_count = as.count { |a| a < 0 }\n\nans = 0\nas.each do |a|\n ans += [(a-(-1)).abs, (a-1).abs].min\nend\nif negative_count.odd?\n ans += 2\nend\n\nputs ans\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\na = gets.split.map(&:to_i)\ncoins = 0\nnegs = 0\nmin_spent = 10**9 + 1\na.sort.each { |i|\n pending_coins = 0 # keep positive!\n if i < 0\n negs += 1\n pending_coins = -1 - i\n else\n if i == 0\n pending_coins = 1\n else\n pending_coins = i - 1\n end\n end\n\n coins += pending_coins\n if pending_coins < min_spent\n min_spent = pending_coins\n end\n}\n\nif negs.odd?\n if min_spent == 0 # is +1 or -1\n coins += 2\n elsif min_spent == 1 # is zero\n coins += 1\n else\n coins += 2\n end\nend\n\nputs coins"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nans = 0\nnnegatives = 0\na.each do |x|\n if x >= 1\n ans += x - 1\n elsif x <= -1\n ans += -1 - x\n nnegatives += 1\n else\n ans += 1\n end\nend\nans += 2 if nnegatives%2 != 0\nputs ans\n"}], "src_uid": "3b3b2408609082fa5c3a0d55bb65d29a"} {"source_code": "n, _ = gets.strip.split(' ').map(&:to_i)\n\narr = []\nh = Hash.new\n(1..n).each { |e|\n arr << gets.strip\n h[arr.last] = 1 if arr.include?(arr.last.reverse) && arr.last != arr.last.reverse\n h[arr.last] = 0 if arr.last == arr.last.reverse\n}\n\nan = []\nh.each { |k, v|\n if v.zero?\n an << k\n break \n end\n}\nh.each { |k, v|\n if v == 1\n an.unshift(k)\n an << k.reverse\n end\n}\n\ns = \"\"\nan.each { |e| s += e }\nputs s.size\nputs s\n", "positive_code": [{"source_code": "n, _ = gets.strip.split(' ').map(&:to_i)\n\narr = []\nh = Hash.new\n(1..n).each { |e|\n arr << gets.strip\n h[arr.last] = 1 if arr.include?(arr.last.reverse) && arr.last != arr.last.reverse\n h[arr.last] = 0 if arr.last == arr.last.reverse\n}\n\nan = []\nh.each { |k, v|\n if v.zero?\n an << k\n break\n end\n}\n\nh.each { |k, v|\n if v == 1\n an.unshift(k)\n an << k.reverse\n end\n}\n\ns = \"\"\nan.each { |e| s += e }\nputs s.size\nputs s\n"}, {"source_code": "n, m = *gets.strip.split.map(&:to_i)\n\nstrs = []\n\nn.times do\n strs << gets.strip\nend\n\nif n == 1\n unless strs[0] == strs[0].reverse\n puts 0\n exit\n end\n puts m\n puts strs[0]\n exit\nend\n\npalindroms = {}\npalindroms_indexes = []\nmiddle_word = \"\"\n\nstrs.each_with_index do |s, i|\n cur_pal = s.reverse\n p_count = 0\n next if palindroms.keys.include?(s) || palindroms.keys.include?(cur_pal)\n\n p_hash = {\n similar_count: 1,\n p_count: 0\n }\n strs.each_with_index.map do |ss, ii|\n next if ii == i\n\n if ss == cur_pal\n p_hash[:p_count] += 1\n else\n if ss == s\n p_hash[:similar_count] += 1\n end\n end\n end\n\n p_count = if p_hash[:p_count] != p_hash[:similar_count]\n if s == cur_pal\n identical = p_hash[:p_count] + 1\n if identical % 2 == 0\n identical/2\n else\n if s.length > middle_word.length\n middle_word = s\n end\n p_hash[:p_count]/2\n end\n else\n [p_hash[:p_count], p_hash[:similar_count]].min\n end\n else\n p_hash[:p_count]\n end\n\n if p_count == 0\n if s == cur_pal && s.length > middle_word.length\n middle_word = s\n end\n end\n\n palindroms[s] = p_count\nend\n\nstr_begin = \"\"\nstr_end = \"\"\npalindroms.each do |k, v|\n v.times do\n str_begin += k\n str_end = k.reverse + str_end\n end\nend\n\npal = str_begin + middle_word + str_end\nif pal.empty?\n puts 0\nelse\n puts pal.length\n puts pal\nend\n"}, {"source_code": "# frozen_string_literal: true\n\n@data = $stdin.read.split\n\ndef next_token\n @data.shift\nend\n\ndef next_int\n next_token.to_i\nend\n\nn = next_int\nm = next_int\ns = n.times.map { next_token }\n\nres = 0\nleft = String.new\noutlier = ''\nn.times do |i|\n found = false\n (0...i).each do |j|\n next unless s[i] == s[j].reverse\n\n found = true\n left << s[i]\n res += 1\n end\n next if found\n\n outlier = s[i] if s[i] == s[i].reverse\nend\n\nres = left + outlier + left.reverse\nputs res.size\nputs res\n"}], "negative_code": [{"source_code": "n, m = *gets.strip.split.map(&:to_i)\n\nstrs = []\n\nn.times do\n strs << gets.strip\nend\n\nif n == 1\n unless strs[0] == strs[0].reverse\n puts 0\n exit\n end\n puts n\n puts strs[0]\n exit\nend\n\npalindroms = {}\npalindroms_indexes = []\nmiddle_word = \"\"\n\nstrs.each_with_index do |s, i|\n cur_pal = s.reverse\n p_count = 0\n next if palindroms.keys.include?(s) || palindroms.keys.include?(cur_pal)\n\n p_hash = {\n similar_count: 1,\n p_count: 0\n }\n strs.each_with_index.map do |ss, ii|\n next if ii == i\n\n if ss == cur_pal\n p_hash[:p_count] += 1\n else\n if ss == s\n p_hash[:similar_count] += 1\n end\n end\n end\n\n p_count = if p_hash[:p_count] != p_hash[:similar_count]\n if s == cur_pal\n identical = p_hash[:p_count] + 1\n if identical % 2 == 0\n identical/2\n else\n if s.length > middle_word.length\n middle_word = s\n end\n p_hash[:p_count]/2\n end\n else\n [p_hash[:p_count], p_hash[:similar_count]].min\n end\n else\n p_hash[:p_count]\n end\n\n if p_count == 0\n if s == cur_pal && s.length > middle_word.length\n middle_word = s\n end\n end\n\n palindroms[s] = p_count\nend\n\nstr_begin = \"\"\nstr_end = \"\"\npalindroms.each do |k, v|\n v.times do\n str_begin += k\n str_end = k.reverse + str_end\n end\nend\n\npal = str_begin + middle_word + str_end\nif pal.empty?\n puts 0\nelse\n puts pal.length\n puts pal\nend\n"}, {"source_code": "n, _ = gets.strip.split(' ').map(&:to_i)\n\narr = []\n(1..n).each { |e|\n arr << gets.strip\n}\n\nan = []\narr.each { |e|\n if arr.include?(e.reverse)\n an.unshift(e)\n an << e.reverse\n arr.delete(e.reverse)\n end\n}\n\ns = \"\"\nan.each { |e| s += e }\nputs s.size\nputs s\n"}], "src_uid": "554115bec46bb436a0a1ddf8c05a2d08"} {"source_code": "SIZES = [ :S, :M, :L, :XL, :XXL ]\nOFFSET = [ 0, +1, -1, +2, -2, +3, -3, +4, -4 ]\n\nsizes = {}\ngets.split.map { |v| v.to_i }.each_with_index { |how, index| sizes[SIZES[index]] = how }\ngets.to_i.times do\n index = SIZES.find_index(gets.strip.to_sym)\n OFFSET.each do |offset|\n cur, size = index + offset, SIZES[index + offset]\n if (0 ... SIZES.size).include?(cur) and sizes[size] > 0\n sizes[size] -= 1\n puts size\n break\n end\n end\nend\n", "positive_code": [{"source_code": "s = gets.chomp.split(\" \")\nmas = [s[0].to_i,s[1].to_i, s[2].to_i, s[3].to_i, s[4].to_i]\nindex = {\"S\" => 0, \"M\" => 1, \"L\" => 2, \"XL\" => 3, \"XXL\" => 4}\nrindex = [\"S\",\"M\",\"L\",\"XL\",\"XXL\"]\n\nn = gets.to_i\nfor i in 1..n\n s = gets.chomp!\n for j in 0..4\n if index[s] + j < 5 && mas[index[s] + j] > 0\n mas[index[s] + j] -= 1\n puts rindex[index[s] + j]\n break\n elsif index[s] - j >= 0 && mas[index[s] - j] > 0\n mas[index[s] - j] -= 1\n puts rindex[index[s] - j]\n break\n end\n end\nend"}, {"source_code": "$s=gets.split.map(&:to_i)\nsize=[\"S\", \"M\", \"L\", \"XL\",\"XXL\"]\ndef get(x)\n for u in 0..5\n if x+u<5 && $s[x+u]>0 then\n $s[x+u]-=1\n return x+u\n end\n if x-u>=0 && $s[x-u]>0 then\n $s[x-u]-=1\n return x-u\n end\n end\n return 0\nend\nk=gets.to_i\nk.times{\n puts size[get(size.index(gets.split[0]))]\n}\n"}, {"source_code": "\ndef f(n)\n l = [nil] * 5 + ['S','M','L','XL','XXL'] + [nil] * 5\n i = n+4\n r = []\n r << l[i]\n r << l[i+1]\n r << l[i-1]\n r << l[i+2]\n r << l[i-2]\n r << l[i+3]\n r << l[i-3]\n r << l[i+4]\n r << l[i-4]\n r << l[i+5]\n r << l[i-5]\n r.select {|e| e}\nend\n\npr = []\nl = ['S','M','L','XL','XXL']\n1.upto(5) {|n| pr << f(n)}\n\n\n\n\na = gets.split(' ')\na = a.map{|e| e.to_i}\n\ngets.to_i.times do\n size = gets.chomp\n tl = pr[l.index(size)]\n n = 0\n while a[l.index(tl[n])] == 0\n n += 1\n end\n a[l.index(tl[n])] -= 1\n puts tl[n]\nend\n\n\n"}, {"source_code": "s = gets.split.map(&:to_i)+[0]*5\nn = gets.to_i\nz = {\"S\"=>0,\"M\"=>1,\"L\"=>2,\"XL\"=>3,\"XXL\"=>4}\nzz = [\"S\",\"M\",\"L\",\"XL\",\"XXL\"]\nn.times{\ni = z[gets.chomp]\n x=[0,1,-1,2,-2,3,-3,4,-4].select{|x|s[i+x]>0}\n x=x[0]\n puts zz[i+x]\n s[i+x]-=1\n}"}], "negative_code": [{"source_code": "\ndef f(n)\n l = [nil] * 5 + ['S','M','L','XL','XXL'] + [nil] * 5\n i = n+5\n r = []\n r << l[i]\n r << l[i+1]\n r << l[i-1]\n r << l[i+2]\n r << l[i-2]\n r << l[i+3]\n r << l[i-3]\n r << l[i+4]\n r << l[i-4]\n r << l[i+5]\n r << l[i-5]\n r.select {|e| e}\nend\n\npr = []\nl = ['S','M','L','XL','XXL']\n1.upto(5) {|n| pr << f(n)}\n\n\n\n\na = gets.split(' ')\na = a.map{|e| e.to_i}\n\ngets.to_i.times do\n size = gets.chomp\n tl = pr[l.index(size)]\n n = 0\n while a[l.index(tl[n])] == 0\n n += 1\n end\n a[l.index(tl[n])] -= 1\n puts tl[n]\nend\n\n\n"}, {"source_code": "\ndef f(n)\n l = [nil] * 5 + ['S','M','L','XL','XXL'] + [nil] * 5\n i = n+5\n r = []\n r << l[i]\n r << l[i+1]\n r << l[i-1]\n r << l[i+2]\n r << l[i-2]\n r << l[i+3]\n r << l[i-3]\n r << l[i+4]\n r << l[i-4]\n r << l[i+5]\n r << l[i-5]\n r.select {|e| e}\nend\n\npr = []\nl = ['S','M','L','XL','XXL']\n1.upto(5) {|n| pr << f(n)}\n\n\n\n\na = gets.split(' ')\na = a.map{|e| e.to_i}\n\ngets.to_i.times do\n size = gets.chomp\n tl = pr[l.index(size)]\n n = 0\n while a[l.index(tl[n])] == 0\n n += 1\n end\n a[l.index(tl[n])] -= 1\n puts tl[n]\nend\n\n\n"}, {"source_code": "s = gets.chomp.split(\" \")\nmas = [s[0].to_i,s[1].to_i, s[2].to_i, s[3].to_i, s[4].to_i]\nindex = {\"S\" => 0, \"M\" => 1, \"L\" => 2, \"XL\" => 3, \"XXL\" => 4}\nrindex = [\"S\",\"M\",\"L\",\"XL\",\"XXL\"]\n\nn = gets.to_i\nfor i in 1..n\n s = gets.chomp!\n if mas[index[s]] > 0\n mas[index[s]] -= 1\n puts rindex[index[s]]\n elsif index[s] + 1 < 5 && mas[index[s] + 1] > 0\n mas[index[s] + 1] -= 1\n puts rindex[index[s] + 1]\n elsif index[s] - 1 >= 0 && mas[index[s] - 1] > 0\n mas[index[s] - 1] -= 1\n puts rindex[index[s] - 1]\n elsif index[s] + 2 < 5 && mas[index[s] + 2] > 0\n mas[index[s] + 2] -= 1\n puts rindex[index[s] + 2]\n elsif index[s] - 2 >= 0 && mas[index[s] -2] > 0\n mas[index[s] - 2] -= 1\n puts rindex[index[s] -2]\n end\nend"}], "src_uid": "3c9d1de13e21ed16a7e5cbd2d67f4ce7"} {"source_code": "# -*- coding: utf-8 -*-\n#require 'awesome_print'\n\nn, m = gets.split.map(&:to_i)\ngrid = []\nn.times {|line|\n s = gets.chomp\n l = s.index 'W'\n r = s.rindex 'W'\n grid << [l, r, line]\n}\n\ndef f(line, i, n, m, grid)\n cur_l, cur_r, _ = grid[line]\n below_l, below_r, next_i = grid[line+1...n].find { |_, x, _| ! x.nil? }\n count = 0\n if line.even?\n #\u53f3\u3078\n if !cur_r.nil? \n count += cur_r - i\n i = cur_r \n end\n else\n #\u5de6\u3078\n if !cur_l.nil? \n count += i - cur_l\n i = cur_l\n end\n end\n if ! below_r.nil?\n #\u4e0b\u306b\u3044\u304d\u307e\u3059\n if next_i.even?\n #\u4e0b\u306e\u65b9\u3082\u53f3\n count += i-below_l if below_l < i\n count += next_i - line + f(next_i, [below_l, i].min, n, m, grid)\n else\n #\u4e0b\u306f\u5de6\n count += below_r-i if i < below_r \n count += next_i - line + f(next_i, [below_r, i].max, n, m, grid) \n end\n end \n \n count\nend\nputs f(0, 0, n, m, grid)\n", "positive_code": [{"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\na = Array.new(n)\nidxs = Array.new(n)\nridxs = Array.new(n)\nfor i in 0..n-1\n a[i] = gets.chomp\n if i % 2 == 0\n idxs[i] = a[i].rindex(\"W\")\n ridxs[i] = a[i].index(\"W\")\n else\n idxs[i] = a[i].index(\"W\")\n ridxs[i] = a[i].rindex(\"W\")\n end\nend\nwcnt = 0\ncurcol = 0\nendidx = -1\nfor i in 0..n-1\n break if idxs[n-1-i] != nil\n endidx = n-1-i\nend\nfor i in 0..n-1\n if idxs[i] != nil\n wcnt += (curcol-idxs[i]).abs\n curcol = idxs[i]\n end\n break if endidx != -1 && i+1 >= endidx \n if i < n-1\n if ridxs[i+1] != nil\n if (i % 2 == 0 && ridxs[i+1] > curcol) || (i % 2 == 1 && ridxs[i+1] < curcol)\n wcnt += (curcol-ridxs[i+1]).abs\n curcol = ridxs[i+1]\n end\n end\n wcnt += 1\n end\nend\nputs wcnt"}], "negative_code": [{"source_code": "# -*- coding: utf-8 -*-\nclass P < Struct.new(:l, :r)\n \nend\nn, m = gets.split.map(&:to_i)\ngrid = []\nn.times {|line|\n s = gets.chomp\n l = s.index 'W'\n r = s.rindex 'W'\n grid << [l, r, line]\n}\n\ndef f(line, i, n, m, grid)\n cur_l, cur_r, _ = grid[line]\n below_l, below_r, next_i = grid[line+1...m].find { |_, x, _| ! x.nil? }\n count = 0\n if line.even?\n #\u53f3\u3078\n if !cur_r.nil? \n count += cur_r - i\n i = cur_r \n end\n else\n #\u5de6\u3078\n if !cur_l.nil? \n count += i - cur_l\n i = cur_l\n end\n end\n if ! below_r.nil?\n #\u4e0b\u306b\u3044\u304d\u307e\u3059\n if next_i.even?\n #\u4e0b\u306e\u65b9\u3082\u53f3\n count += i-below_l if below_l < i\n count += next_i - line + f(next_i, [below_l, i].min, n, m, grid)\n else\n #\u4e0b\u306f\u5de6\n count += below_r-i if i < below_r \n count += next_i - line + f(next_i, [below_r, i].max, n, m, grid) \n end\n end \n \n count\nend\nputs f(0, 0, n, m, grid)\n"}, {"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\na = Array.new(n)\nidxs = Array.new(n)\nfor i in 0..n-1\n a[i] = gets.chomp\n if i % 2 == 0\n idxs[i] = a[i].rindex(\"W\")\n else\n idxs[i] = a[i].index(\"W\")\n end\nend\nwcnt = 0\ncurcol = 0\nfor i in 0..n-1\n if idxs[i] != nil\n wcnt += (curcol-idxs[i]).abs\n curcol = idxs[i]\n end\n if i < n-1\n if idxs[i+1] != nil\n if (i % 2 == 0 && idxs[i+1] > curcol) || (i % 2 == 1 && idxs[i+1] < curcol)\n wcnt += (curcol-idxs[i+1]).abs\n curcol = idxs[i+1]\n end\n end\n wcnt += 1\n end\nend\nputs wcnt"}, {"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\na = Array.new(n)\nidxs = Array.new(n)\nridxs = Array.new(n)\nfor i in 0..n-1\n a[i] = gets.chomp\n if i % 2 == 0\n idxs[i] = a[i].rindex(\"W\")\n ridxs[i] = a[i].index(\"W\")\n else\n idxs[i] = a[i].index(\"W\")\n ridxs[i] = a[i].rindex(\"W\")\n end\nend\nwcnt = 0\ncurcol = 0\nfor i in 0..n-1\n if idxs[i] != nil\n wcnt += (curcol-idxs[i]).abs\n curcol = idxs[i]\n end\n if i < n-1\n if ridxs[i+1] != nil\n if (i % 2 == 0 && ridxs[i+1] > curcol) || (i % 2 == 1 && ridxs[i+1] < curcol)\n wcnt += (curcol-ridxs[i+1]).abs\n curcol = ridxs[i+1]\n end\n end\n wcnt += 1\n end\nend\nputs wcnt"}], "src_uid": "14959b7266ceebe96c33bfa1791e26b4"} {"source_code": "#!/usr/bin/ruby\ngets\ns=0\nputs gets.split.map(&:to_i).reverse.map{|e|\n\tr=[s+1-e,0].max\n\ts=[s,e].max\n\tr\n}.reverse*' '\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\ngets\ns=0\nputs gets.split.map(&:to_i).reverse.map{|e|\n\tr=[s+1-e,0].max\n\ts=[s,e].max\n\tr\n}.reverse*' '"}, {"source_code": "n, h = gets.chomp.to_i, gets.chomp.split(\" \").map(&:to_i)\na, max_on_the_right, index_of_max_on_the_right = \n\t [] << 0, h[n-1], n-1\n\n(n-2).downto 0 do |i|\n\tif max_on_the_right >= h[i]\n\t\ta.unshift(max_on_the_right - h[i] + 1)\n\telse\n\t\ta.unshift 0\n\t\tmax_on_the_right = h[i]\n\tend\nend\n\nputs a.join \" \""}, {"source_code": "n, h = gets.chomp.to_i, gets.chomp.split(\" \").map(&:to_i)\na, max_on_the_right = [] << 0, h[n-1]\n\n(n-2).downto 0 do |i|\n\tif max_on_the_right >= h[i]\n\t\ta.unshift(max_on_the_right - h[i] + 1)\n\telse\n\t\ta.unshift 0\n\t\tmax_on_the_right = h[i]\n\tend\nend\n\nputs a.join \" \""}, {"source_code": "#!/usr/bin/ruby\ngets\ns=0\nputs gets.split.map(&:to_i).reverse.map{|e|\n\tr=[s+1-e,0].max\n\ts=[s,e].max\n\tr\n}.reverse*' '\n"}, {"source_code": "#!/usr/bin/ruby\ngets\ns=0\nputs gets.split.map(&:to_i).reverse.map{|e|\n\tr=[s+1-e,0].max\n\ts=[s,e].max\n\tr\n}.reverse*' '\n"}, {"source_code": "\nn = gets.chomp.to_i;\narr = gets.chomp.split.map(&:to_i);\nmax = arr[n - 1];\nans = [];\n(n-2).downto(0) {|i|\n ans[i] = [max + 1 - arr[i], 0].max;\n max = [max, arr[i]].max;\n}\nans[n - 1] = 0;\nprint ans.join(' ');"}, {"source_code": "#!/usr/bin/ruby\ngets\ns=0\nputs gets.split.map(&:to_i).reverse.map{|e|\n\tr=[s+1-e,0].max\n\ts=[s,e].max\n\tr\n}.reverse*' '"}, {"source_code": "\ufeffn = gets.to_i\nh = gets.split.map(&:to_i)\nm, a = [0] * (n - 1) + [h[n - 1]], [0] * n\n(n - 2).downto(0) do |i|\n if h[i] <= m[i + 1]\n m[i] = m[i + 1]\n a[i] = m[i] - h[i] + 1\n else\n m[i] = h[i]\n end\nend\nputs a.join(' ')\n"}, {"source_code": "#!/usr/bin/ruby\ngets\ns=0\nputs gets.split.map(&:to_i).reverse.map{|e|\n\tr=[s+1-e,0].max\n\ts=[s,e].max\n\tr\n}.reverse*' '\n"}, {"source_code": "#!/usr/bin/ruby\ngets\ns=0\nputs gets.split.map(&:to_i).reverse.map{|e|\n\tr=[s+1-e,0].max\n\ts=[s,e].max\n\tr\n}.reverse*' '\n"}, {"source_code": "gets\nx=gets.split.map{|e| e.to_i}.reverse\nans=[]\nx.inject(0){|m,e|\n\tif m>=e then\n\t\tans<<(m-e+1)\n\telse\n\t\tans<<0\n\tend\n\t[m,e].max\n}\nputs ans.reverse*\" \"\n\n"}, {"source_code": "n = gets.to_i\narr = gets.chomp.split(/ /).map(&:to_i)\narr_fin = Array.new\nindex=n-1\nmax_l = 0\nloop do \n\tbreak if index<0\n\tif arr[index] > max_l\n\t\tarr_fin.unshift(0)\n\t\tmax_l = arr[index]\n\telse\n\t\tarr_fin.unshift(-arr[index]+max_l+1)\n\tend\n\tindex-=1\nend\narr_fin.each_index{ |e|\n\tif(e!=n-1)\n\t\tprint \"#{arr_fin[e]} \"\n\telse\n\t\tprint \"#{arr_fin[e]}\"\n\tend\n}"}, {"source_code": "# \u0447\u0438\u0442\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u043d\u043e \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\ncount = STDIN.gets.to_i\n# \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u0442\u0430\u0436\u0435\u0439 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u044d\u043b\u0438\u0442\u043d\u043e\u043c \u0434\u043e\u043c\u0435\nlast_elite_floors = 0\ninput = STDIN.gets\n# \u043c\u0430\u0441\u0441\u0438\u0432 - \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u0442\u0430\u0436\u0435\u0439 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0434\u043e\u043c\u0435\nfloors = input.split.map(&:to_i)\n# \u0442.\u043a. \u043d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0432 ruby \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0445\u043e\u0434\n# \u043e\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043a \u043f\u0435\u0440\u0432\u043e\u043c\u0443\n# - \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u044e \u043c\u0430\u0441\u0441\u0438\u0432\n# \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437\nreverse = floors.reverse\nreverse_result = Array.new\nreverse.each do |item|\n if item > last_elite_floors\n # \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u044d\u043b\u0438\u0442\u043d\u044b\u0439 \u0434\u043e\u043c - \u0437\u0430\u043f\u043e\u043c\u043d\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u0442\u0430\u0436\u0435\u0439 \u0432 \u043d\u0451\u043c\n last_elite_floors = item\n reverse_result.push(0)\n elsif item == last_elite_floors\n # \u0435\u0441\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u0442\u0430\u0436\u0435\u0439 \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u043a\u0430\u043a \u0443 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u044d\u043b\u0438\u0442\u043d\u043e\u0433\u043e \u0434\u043e\u043c\u0430\n # \u0437\u043d\u0430\u0447\u0438\u0442 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u044d\u0442\u0430\u0436\n reverse_result.push(1)\n else\n reverse_result.push(last_elite_floors - item + 1)\n end\nend\n# \u0442\u0443\u0442 \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0437\nputs \"#{reverse_result.reverse.join(' ')}\""}, {"source_code": "#!/usr/bin/ruby\ngets\ns=0\nputs gets.split.map(&:to_i).reverse.map{|e|\n\tr=[s+1-e,0].max\n\ts=[s,e].max\n\tr\n}.reverse*' '\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nright_max, ans = 0, []\n(n - 1).downto(0) do |i|\n ans << [right_max + 1 - a[i], 0].max\n right_max = [right_max, a[i]].max\nend\nputs ans.reverse.join(' ')\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nright_max, ans = 0, [0]\n(n - 1).downto(1) do |i|\n right_max = [right_max, a[i]].max\n ans << [right_max + 1 - a[i - 1], 0].max\nend\nputs ans.reverse.join(' ')\n"}, {"source_code": "#!/usr/bin/ruby\ngets\ns=0\nputs gets.split.map(&:to_i).reverse.map{|e|\n\tr=[s+1-e,0].max\n\ts=[s,e].max\n\tr\n}.reverse*' '\n"}, {"source_code": "#!/usr/bin/ruby\ngets\ns=0\nputs gets.split.map(&:to_i).reverse.map{|e|\n\tr=[s+1-e,0].max\n\ts=[s,e].max\n\tr\n}.reverse*' '\n"}], "negative_code": [{"source_code": "n, h, a, max_on_the_right, index_of_max_on_the_right = \n\tgets.chomp.to_i, gets.chomp.split(\" \").map(&:to_i), [], 0, 0\nh.each_with_index do |e,i|\n\tbreak if i == n-1\n\tif i == index_of_max_on_the_right\n\t\tmax_on_the_right = h[i+1]\n\t\t(i+2).upto (n-1) do |ind|\n\t\t\tif h[ind] > max_on_the_right\n\t\t\t\tmax_on_the_right = h[ind] \n\t\t\t\tindex_of_max_on_the_right = ind\n\t\t\tend\n\t\tend\n\tend\n\n\ta << if (max_on_the_right - e) < 1 \n\t\t0\n\telse\n\t\t(max_on_the_right - e + 1)\n\tend\nend\na << 0\nputs a.join \" \""}, {"source_code": "n, h = gets.chomp.to_i, gets.chomp.split(\" \").map(&:to_i)\na, max_on_the_right, index_of_max_on_the_right = \n\t [] << 0, h[n-1], n-1\n\n(n-2).downto 0 do |i|\n\tif max_on_the_right > h[i]\n\t\ta.unshift(max_on_the_right - h[i] + 1)\n\telse\n\t\ta.unshift 0\n\t\tmax_on_the_right = h[i]\n\tend\nend\n\nputs a.join \" \""}, {"source_code": "n = gets.chomp.to_i;\narr = gets.chomp.split.map(&:to_i).reverse;\nmax = arr[0];\nans = \"0\";\n(1...n).each {|i|\n ans << \" #{max + 1 - arr[i]}\";\n max = [max, arr[i]].max;\n}\nprint ans.reverse + \"\\n\";\n"}, {"source_code": "# \u0447\u0438\u0442\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u043d\u043e \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\ncount = STDIN.gets.to_i\n# \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u0442\u0430\u0436\u0435\u0439 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u044d\u043b\u0438\u0442\u043d\u043e\u043c \u0434\u043e\u043c\u0435\nlast_elite_floors = 0\ninput = STDIN.gets\n# \u043c\u0430\u0441\u0441\u0438\u0432 - \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u0442\u0430\u0436\u0435\u0439 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0434\u043e\u043c\u0435\nfloors = input.split.map(&:to_i)\n# \u0442.\u043a. \u043d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0432 ruby \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0445\u043e\u0434\n# \u043e\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043a \u043f\u0435\u0440\u0432\u043e\u043c\u0443\n# - \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u044e \u043c\u0430\u0441\u0441\u0438\u0432\n# \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437\nreverse = floors.reverse\nreverse_result = Array.new\nreverse.each do |item|\n if item >= last_elite_floors\n last_elite_floors = item\n reverse_result.push(0)\n else\n reverse_result.push(last_elite_floors - item + 1)\n end\nend\n# \u0442\u0443\u0442 \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0437\nputs \"#{reverse_result.reverse.join(' ')}\""}], "src_uid": "e544ed0904e2def0c1b2d91f94acbc56"} {"source_code": "n,s = gets.split.map {|x| x.to_i}\nm = n*n/2+(n % 2)\nmap = Array.new(n) {\"S\"*n}\nif s <= m \n puts \"YES\"\n n.times do |y|\n offset = y % 2\n x = offset\n while (x < n) do\n break if s == 0\n map[y][x] = 'L'\n s -= 1\n x += 2\n end\n break if s == 0\n end\n map.each do |line|\n puts line\n end\n\nelse\n puts \"NO\"\nend\n", "positive_code": [{"source_code": "n, k = gets.chomp.split(\"\\s\").map(&:to_i)\nif n % 2 == 0\n if (n / 2) * n < k\n puts 'NO'\n exit\n end\nelse\n if (n / 2 + 1) ** 2 + (n / 2) ** 2 < k\n puts 'NO'\n exit\n end\nend\n\nputs 'YES'\ncount = 0\nn.times do |i|\n n.times do |j|\n if count < k && i % 2 == 0 && j % 2 == 0\n count += 1\n print 'L'\n elsif count < k && i % 2 == 1 && j % 2 == 1\n count += 1\n print 'L'\n else\n print 'S'\n end\n end\n puts\nend\n"}, {"source_code": "n,@k=gets.split.map(&:to_i)\n(puts :NO;exit)if @k > (n*n+1)/2\nputs :YES\ndef ne\n ((@k-=1)<0)?'S':'L'\nend\n\nn.times do |i|\n n.times do |j|\n print (i+j)%2==0 ? ne : 'S'\n end\n puts\nend\n"}, {"source_code": "input = gets.chomp\ninput2 = input.split(\" \")\nn = input2[0].to_i\nk = input2[1].to_i\n\n\nif n % 2 == 1\n max = (n/2+1) ** 2 + (n/2) ** 2\nelse\n max = (n/2) * n\nend\n\nif max >= k\n puts \"YES\"\n (n**2).times do |num|\n\n if num % n == 0 && num != 0\n print \"\\n\"\n end\n\n if (num / n) % 2 == 0 || (n % 2 == 1)\n if num % 2 == 0 && k != 0\n print \"L\"\n k -= 1\n else\n print \"S\"\n end\n else\n if num % 2 == 1 && k != 0\n print \"L\"\n k -= 1\n else\n print \"S\"\n end\n end\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "def getMaxAmountOfIslands(n)\n n ** 2 / 2 + (n % 2 == 0 ? 0 : 1) \nend\n\ndef makeIslands(k, n)\n res = \"\"\n n.times do |i|\n n.times {|j| res += (i + j) % 2 == 0 && k > 0? (k-=1; \"L\") : \"S\"}\n res += \"\\n\"\n end\n return res\nend\n\nn, k = *gets.split(' ')\n .map {|x| x.to_i}\n .to_a\n\nif k <= getMaxAmountOfIslands(n) then\n puts \"YES\"\n puts makeIslands(k, n)\nelse\n puts \"NO\"\nend"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\ns = Array.new(n){Array.new(n,\"S\")}\nif n.odd?\n if k > n*n/2+1\n puts \"NO\"\n exit\n end\nelse\n if k > n*n/2\n puts \"NO\"\n exit\n end\nend\ni = 0\nj = 0\nk.times do\n s[i][j] = \"L\"\n j += 2\n if j >= n\n i += 1\n j = i%2\n end\nend\nputs \"YES\"\ns.each{|str| puts str.join}\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nans = Array.new(n){Array.new(n, 'S')}\n\ndef adjcent?(i, j, n, ans)\n if ((i > 0 && ans[i - 1][j] == 'L') ||\n (j > 0 && ans[i][j - 1] == 'L') ||\n (i < n - 1 && ans[i + 1][j] == 'L') ||\n (j < n - 1 && ans[i][j + 1] == 'L'))\n true\n else\n false\n end\nend\n\nif k > (n * n + 1) / 2\n puts 'NO'\nelse\n puts 'YES'\n count = 0\n n.times do |i|\n n.times do |j|\n if !adjcent?(i, j, n, ans) && count < k\n ans[i][j] = 'L'\n count += 1\n end\n end\n end\n puts ans.map{|x| x.join}\nend\n\n"}, {"source_code": "n, k = gets.split.map {|x| x.to_i}\n\nif (n*n + 1)/2 < k\n puts \"NO\"\nelse\n puts \"YES\"\n b = []\n n.times do\n b.push(\"S\" * n)\n end\n\n for i in 0...n\n for j in 0...n\n if (i + j) % 2 == 0 && k > 0\n b[i][j] = 'L'\n k -= 1\n end\n end\n end\n b.each {|str| puts str}\nend"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# b.rb\n\ndef main()\n n, k = gets.chomp.split(\" \").map{|s| next s.to_i }\n m = (n * n / 2) + (n % 2 == 1 ? 1 : 0)\n if m < k then\n puts(\"NO\")\n return\n end\n\n puts(\"YES\")\n r = 0\n n.times do |i|\n s = \"S\" * n\n t = i % 2\n while r < k && t < n do\n s[t] = \"L\"\n t += 2\n r += 1\n end\n puts(s)\n end\nend\n\nif __FILE__ == $0 then\n main()\nend\n"}], "negative_code": [{"source_code": "n,s = gets.split.map {|x| x.to_i}\nm = n*n/2+(n % 2)\nmap = Array.new(n) {\"L\"*n}\nif s <= m \n puts \"YES\"\n n.times do |y|\n offset = y % 2\n x = offset\n while (x < n) do\n break if s == 0\n map[y][x] = 'S'\n s -= 1\n x += 2\n end\n break if s == 0\n end\n map.each do |line|\n puts line\n end\n\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n, k = gets.chomp.split(\"\\s\").map(&:to_i)\nif n % 2 == 0\n if n / 2 < k\n puts 'NO'\n exit\n end\nelse\n if n / 2 + 1 < k\n puts 'NO'\n exit\n end\nend\n\nputs 'YES'\ncount = 0\nn.times do |i|\n if count < k && i % 2 == 0\n count += 1\n puts 'L' * n\n else\n puts 'S' * n\n end\nend\n"}, {"source_code": "n, k = gets.chomp.split(\"\\s\").map(&:to_i)\nif n % 2 == 0\n if n / 2 < k\n puts 'NO'\n exit\n end\nelse\n if n / 2 + 1 < k\n puts 'NO'\n exit\n end\nend\n\ncount = 0\nn.times do |i|\n if count < k && i % 2 == 0\n count += 1\n puts 'L' * n\n else\n puts 'S' * n\n end\nend\n"}, {"source_code": "n, k = gets.chomp.split(\"\\s\").map(&:to_i)\nif n % 2 == 0\n if n / 2 < k\n puts 'NO'\n exit\n end\nelse\n if n / 2 + 1 < k\n puts 'NO'\n exit\n end\nend\n\nif k == 0\n puts 'NO'\n exit\nend\n\nputs 'YES'\ncount = 0\nn.times do |i|\n if count < k && i % 2 == 0\n count += 1\n puts 'L' * n\n else\n puts 'S' * n\n end\nend\n"}, {"source_code": "n, k = gets.chomp.split(\"\\s\").map(&:to_i)\nif n % 2 == 0\n if (n / 2) * n < k\n puts 'NO'\n exit\n end\nelse\n if (n / 2 + 1) * n < k\n puts 'NO'\n exit\n end\nend\n\nputs 'YES'\ncount = 0\nn.times do |i|\n n.times do |j|\n if count < k && i % 2 == 0 && j % 2 == 0\n count += 1\n print 'L'\n elsif count < k && i % 2 == 1 && j % 2 == 1\n count += 1\n print 'L'\n else\n print 'S'\n end\n end\n puts\nend\n"}, {"source_code": "input = gets.chomp\ninput2 = input.split(\" \")\nn = input2[0].to_i\nk = input2[1].to_i\n\n\nif n % 2 == 1\n max = (n/2+1) ** 2 + (n/2) ** 2\nelse\n max = (n/2) * n\nend\n\nif max >= k\n\n (n**2).times do |num|\n\n if num % n == 0 && num != 0\n print \"\\n\"\n end\n\n if (num / n) % 2 == 0 || (n % 2 == 1)\n if num % 2 == 0 && k != 0\n print \"L\"\n k -= 1\n else\n print \"S\"\n end\n else\n if num % 2 == 1 && k != 0\n print \"L\"\n k -= 1\n else\n print \"S\"\n end\n end\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "input = gets.chomp\ninput2 = input.split(\" \")\nn = input2[0].to_i\nk = input2[1].to_i\n\n\nif n % 2\n max = (n/2+1) ** 2 + (n/2) ** 2\nelse\n max = (n/2) * n\nend\n\nif max >= k\n puts \"YES\"\n\n (n**2).times do |num|\n\n if num % n == 0 && num != 0\n print \"\\n\"\n end\n\n if num % 2 == 0 && k != 0\n print \"L\"\n k -= 1\n else\n print \"S\"\n end\n\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "input = gets.chomp\ninput2 = input.split(\" \")\nn = input2[0].to_i\nk = input2[1].to_i\n\n\nif n % 2\n max = (n/2+1) ** 2 + (n/2) ** 2\nelse\n max = (n/2) * n\nend\n\nif max >= k\n puts \"YES\"\n\n (n**2).times do |num|\n\n if num % n == 0 && num != 0\n print \"\\n\"\n end\n\n if (num / n) % 2 == 0\n if num % 2 == 0 && k != 0\n print \"L\"\n k -= 1\n else\n print \"S\"\n end\n else\n if num % 2 == 1 && k != 0\n print \"L\"\n k -= 1\n else\n print \"S\"\n end\n end\n\n\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "input = gets.chomp\ninput2 = input.split(\" \")\nn = input2[0].to_i\nk = input2[1].to_i\n\n\nif n % 2\n max = (n/2+1) ** 2 + (n/2) ** 2\nelse\n max = (n/2) * n\nend\n\nif max >= k\n puts \"YES\"\n\n (n**2).times do |num|\n\n if num % n == 0 && num != 0\n print \"\\n\"\n end\n\n if (num / n) % 2 == 0 || (n % 2 == 1)\n if num % 2 == 0 && k != 0\n print \"L\"\n k -= 1\n else\n print \"S\"\n end\n else\n if num % 2 == 1 && k != 0\n print \"L\"\n k -= 1\n else\n print \"S\"\n end\n end\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "def getMaxAmountOfIslands(n)\n n ** 2 / 2 + (n % 2 == 0 ? 0 : 1) \nend\n\ndef makeIslands(k, n)\n res = \"\"\n (n ** 2).times do |i|\n shift = (i / n) % 2\n res += (i + shift) % 2 == 0 && i / 2 < k ? \"L\" : \"S\"\n res += \"\\n\" if (i+1) % n == 0 && i > 0\n end\n \n return res\nend\n\nn, k = *gets.split(' ')\n .map {|x| x.to_i}\n .to_a\n\nif k <= getMaxAmountOfIslands(n) then\n puts \"YES\"\n puts makeIslands(k, n)\nelse\n puts \"NO\"\nend"}, {"source_code": "def getMaxAmountOfIslands(n)\n n ** 2 / 2 + (n % 2 == 0 ? 0 : 1) \nend\n\ndef makeIslands(k, n)\n res = \"\"\n (n ** 2).times do |i|\n res += i % 2 == 0 && i / 2 < k ? \"L\" : \"S\"\n res += \"\\n\" if (i+1) % n == 0 && i > 0\n end\n \n return res\nend\n\nn, k = *gets.split(' ')\n .map {|x| x.to_i}\n .to_a\n\nif k <= getMaxAmountOfIslands(n) then\n puts \"YES\"\n puts makeIslands(k, n)\nelse\n puts \"NO\"\nend"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\ns = Array.new(n){Array.new(n,\"S\")}\nif n.odd?\n if k > n*n/2+1\n puts \"NO\"\n exit\n end\nelse\n if k > n*n/2\n puts \"NO\"\n exit\n end\nend\ni = 0\nj = 0\nk.times do\n s[i][j] = \"L\"\n j += 2\n if j >= n\n i += 1\n j = i%2\n end\nend\nputs \"YES\"\ns.each{|str| puts str.join(\" \")}\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nans = Array.new(n){Array.new(n, 'S')}\n\ndef adjcent?(i, j, n, ans)\n if ((i > 0 && ans[i - 1][j] == 'L') ||\n (j > 0 && ans[i][j - 1] == 'L') ||\n (i < n - 1 && ans[i + 1][j] == 'L') ||\n (j < n - 1 && ans[i][j + 1] == 'L'))\n true\n else\n false\n end\nend\n\nif k > (n + 1) / 2\n puts 'NO'\nelse\n puts 'YES'\n count = 0\n n.times do |i|\n n.times do |j|\n if !adjcent?(i, j, n, ans) && count < k\n ans[i][j] = 'L'\n count += 1\n end\n end\n end\n puts ans.map{|x| x.join}\nend\n\n"}], "src_uid": "b15bc7ff01f239a7e4377868a7dda0a6"} {"source_code": "gets.strip.to_i.times do\n p = gets.split('').reject { |e| e == \"\\n\" };\n h = gets.split('').reject { |e| e == \"\\n\" };\n if p.length > h.length\n puts \"NO\"\n next\n end\n done = false\n (0...h.length).each { |i|\n frq = Array.new(27, 0);\n sm = p.length\n p.each { |e| frq[e.ord - ?a.ord] += 1 }\n flg = true\n for j in i ... h.length\n if frq[h[j].ord - ?a.ord] == 0\n flg = false\n break\n else\n frq[h[j].ord - ?a.ord] -= 1\n break if frq.count(0) == frq.length\n end\n end\n if flg && frq.count(0) == frq.length\n puts \"YES\"\n done = true\n break\n end\n }\n puts \"NO\" if !done\nend", "positive_code": [{"source_code": "gets.strip.to_i.times do\n p = gets.strip\n h = gets.strip\n if p.length > h.length\n puts \"NO\"\n next\n end\n p = p.chars.sort.join\n ck = false\n (0...h.length).each { |i| \n break if i + p.length > h.length\n s = h[i, p.length]\n s = s.chars.sort.join\n if s == p\n ck = true\n break\n end\n }\n puts ck ? \"YES\" : \"NO\"\nend"}, {"source_code": "gets.strip.to_i.times do\n p = gets.split('').reject { |e| e == \"\\n\" };\n h = gets.split('').reject { |e| e == \"\\n\" };\n if p.length > h.length\n puts \"NO\"\n next\n end\n done = false\n (0...h.length).each { |i|\n frq = Array.new(27, 0);\n sm = p.length\n p.each { |e| frq[e.ord - ?a.ord] += 1 }\n flg = true\n for j in i ... h.length\n if frq[h[j].ord - ?a.ord] == 0\n flg = false\n break\n else\n frq[h[j].ord - ?a.ord] -= 1\n break if frq.count(0) == frq.length\n end\n end\n if flg && frq.count(0) == frq.length\n puts \"YES\"\n done = true\n break\n end\n }\n puts \"NO\" if !done\nend"}, {"source_code": "t = gets.chomp.to_i\n\nt.times do |ti|\n s = gets.chomp\n pnew = gets.chomp\n letter_count = {}\n s.each_char do |i|\n letter_count[i] = letter_count[i].to_i + 1\n end\n \n window_len = (s.length) -1\n count = 0\n found = false\n \n while count < pnew.length\n new_s = pnew[count..window_len]\n new_h = {}\n new_s.each_char do |i|\n new_h[i] = new_h[i].to_i + 1\n end\n count+=1\n window_len+=1\n if new_h == letter_count\n found = true\n puts \"YES\"\n break;\n end\n end\n \n if !found\n puts \"NO\"\n end\nend"}, {"source_code": "t = gets.chomp.to_i\n\nt.times do |ti|\n p = gets.chomp\n h = gets.chomp\n i = 0\n j = i + p.length - 1\n found = false\n while j < h.length\n if h[i..j].chars.sort == p.chars.sort\n found = true\n puts \"YES\"\n break\n else\n i += 1\n j += 1\n end\n end\n unless found\n puts \"NO\"\n end\nend"}, {"source_code": "gets.strip.to_i.times do\n p = gets.strip\n h = gets.strip\n if p.length > h.length\n puts \"NO\"\n next\n end\n p = p.chars.sort.join\n ck = false\n (0...h.length).each { |i| \n break if i + p.length > h.length\n s = h[i, p.length]\n s = s.chars.sort.join\n if s == p\n ck = true\n break\n end\n }\n puts ck ? \"YES\" : \"NO\"\nend"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\n\nt.times do |ti|\n p = gets.chomp\n h = gets.chomp\n i = 0\n j = i + p.length - 1\n found = false\n while j < h.length\n if (h[i..j].split('') - p.split('')).length == 0 && (p.split('') - h[i..j].split('')).length == 0\n found = true\n puts \"YES\"\n break\n else\n i += 1\n j += 1\n end\n end\n unless found\n puts \"NO\"\n end\nend"}, {"source_code": "t = gets.chomp.to_i\n\nt.times do |ti|\n p = gets.chomp\n h = gets.chomp\n i = 0\n j = i + p.length - 1\n while j < h.length\n if (h[i..j].split('') - p.split('')).length == 0 && (p.split('') - h[i..j].split('')).length == 0\n puts \"YES\"\n break\n else\n i += 1\n j += 1\n end\n end\n if j == h.length - 1\n puts \"NO\"\n end\nend"}, {"source_code": "gets.strip.to_i.times do\n p = gets.split('').reject { |e| e == \"\\n\" };\n h = gets.split('').reject { |e| e == \"\\n\" };\n done = false\n (0...h.length).each { |i|\n sm = p.length\n frq = Array.new(27, 0);\n p.each { |e| frq[e.ord - ?a.ord] += 1 }\n flg = true\n for j in i ... h.length\n if frq[h[j].ord - ?a.ord] == 0\n flg = false\n break\n else\n sm -= 1\n \n frq[h[j].ord - ?a.ord] -= 1\n break if sm == 0\n end\n end\n if flg\n puts \"YES\"\n done = true\n break\n end\n }\n puts \"NO\" if !done\nend"}, {"source_code": "gets.strip.to_i.times do\n p = gets.strip\n h = gets.strip\n if p.length > h.length\n puts \"NO\"\n next\n end\n p = p.chars.sort.join\n ck = false\n (0...p.length).each { |i| \n break if i + p.length > h.length\n s = h[i, p.length]\n s = s.chars.sort.join\n if s == p\n ck = true\n break\n end\n }\n puts ck ? \"YES\" : \"NO\"\nend"}, {"source_code": "gets.strip.to_i.times do\n frq = Array.new(27, 0);\n p = gets.split('').reject { |e| e == \"\\n\" };\n h = gets.split('').reject { |e| e == \"\\n\" };\n done = false\n (0...h.length).each { |i|\n sm = p.length\n p.each { |e| frq[e.ord - ?a.ord] += 1 }\n flg = true\n for j in i ... h.length\n if frq[h[j].ord - ?a.ord] == 0\n flg = false\n break\n else\n sm -= 1\n frq[h[j].ord - ?a.ord] -= 1\n break if sm == 0\n end\n end\n if flg\n puts \"YES\"\n done = true\n end\n }\n puts \"NO\" if !done\nend"}, {"source_code": "gets.strip.to_i.times do\n p = gets.split('').reject { |e| e == \"\\n\" };\n h = gets.split('').reject { |e| e == \"\\n\" };\n if p.length > h.length\n puts \"NO\"\n next\n end\n done = false\n (0...h.length).each { |i|\n frq = Array.new(27, 0);\n sm = p.length\n p.each { |e| frq[e.ord - ?a.ord] += 1 }\n flg = true\n for j in i ... h.length\n if frq[h[j].ord - ?a.ord] == 0\n flg = false\n break\n else\n sm -= 1\n frq[h[j].ord - ?a.ord] -= 1\n break if sm == 0\n end\n end\n if flg\n puts \"YES\"\n done = true\n break\n end\n }\n puts \"NO\" if !done\nend"}, {"source_code": "gets.strip.to_i.times do\n p = gets.strip\n h = gets.strip\n if p.length > h.length\n puts \"NO\"\n next\n end\n p.chars.sort.join\n ck = false\n (0...p.length).each { |i| \n break if i + p.length > h.length\n s = h[i, p.length]\n s.chars.sort.join\n if s == p\n ck = true\n break\n end\n }\n puts ck ? \"YES\" : \"NO\"\nend"}, {"source_code": "gets.strip.to_i.times do\n frq = Array.new(27, 0);\n p = gets.split('').reject { |e| e == \"\\n\" };\n h = gets.split('').reject { |e| e == \"\\n\" };\n done = false\n (0...h.length).each { |i|\n sm = p.length\n p.each { |e| frq[e.ord - ?a.ord] += 1 }\n flg = true\n for j in i ... h.length\n if frq[h[j].ord - ?a.ord] == 0\n flg = false\n break\n else\n sm -= 1\n frq[h[j].ord - ?a.ord] -= 1\n break if sm == 0\n end\n end\n if flg\n puts \"YES\"\n done = true\n break\n end\n }\n puts \"NO\" if !done\nend"}, {"source_code": "gets.strip.to_i.times do\n p = gets.split('').reject { |e| e == \"\\n\" };\n h = gets.split('').reject { |e| e == \"\\n\" };\n if p.length > h.length\n puts \"NO\"\n next\n end\n p.sort\n ck = false\n (0...p.length).each { |i| \n break if i + p.length > h.length\n s = h[i, p.length - 1]\n s.sort\n if s == p\n ck = true\n break\n end\n }\n puts ck ? \"YES\" : \"NO\"\nend"}, {"source_code": "gets.strip.to_i.times do\n p = gets.split('').reject { |e| e == \"\\n\" };\n h = gets.split('').reject { |e| e == \"\\n\" };\n done = false\n (0...h.length).each { |i|\n sm = p.length\n frq = Array.new(27, 0);\n p.each { |e| frq[e.ord - ?a.ord] += 1 }\n flg = true\n for j in i ... h.length\n if frq[h[j].ord - ?a.ord] == 0\n flg = false\n break\n else\n frq[h[j].ord - ?a.ord] -= 1\n if frq.uniq.length == 1\n frq.uniq.each { |e| \n if e.nonzero?\n flg = false\n break\n end\n }\n end\n end\n end\n if flg\n puts \"YES\"\n done = true\n break\n end\n }\n puts \"NO\" if !done\nend"}, {"source_code": "gets.strip.to_i.times do\n p = gets.strip\n h = gets.strip\n if p.length > h.length\n puts \"NO\"\n next\n end\n p = p.chars.sort.join\n ck = false\n (0...h.length).each { |i| \n break if i + p.length > h.length\n s = h[i, p.length]\n s = s.chars.sort.join\n puts \"#{s} + #{p}\"\n if s == p\n ck = true\n break\n end\n }\n puts ck ? \"YES\" : \"NO\"\nend"}], "src_uid": "48151011c3d380ab303ae38d0804176a"} {"source_code": "y,k,n = gets.split(\" \").map(&:to_i)\ni = (y/k.to_f).ceil\nstart = k * i\n\narr = []\n(start..n).step(k).each do |a|\n\t\n\tarr << a - y if a - y != 0\nend\nif arr.empty?\n\tputs -1\nelse\n\tputs arr.join(\" \")\nend\n", "positive_code": [{"source_code": "y,k,n=gets.chomp.split(' ').map(&:to_i)\ni=y/k +1\nwhile (k*i)<=n\n\tprint (k*i-y).to_s+' '\n\ti+=1\nend\nif i==y/k+1\n\tputs \"-1\"\nelse\n\tputs\nend"}, {"source_code": "y, k, n = gets.split.map(&:to_i)\nmin = k-y%k\nif min+y > n\n puts(-1)\nelse\n while min+y <= n do\n $><<\"#{min} \"\n min += k\n end\nend"}, {"source_code": "y , k, n = gets.split.map {|x| x.to_i }\ni = 1\nans = []\nwhile i * k <= n do\n ans << (i * k - y) if i * k - y >= 1\n i = i + 1\nend\nif ans.size != 0 then\n puts ans.join \" \"\nelse\n puts -1\nend "}, {"source_code": "y, k, n = gets.chomp.split(/ /).map(&:to_i)\nif y >= n\n puts \"-1\"\nelse\n if k == 1\n puts \"#{(1..(n - y)).to_a.join(\" \")}\"\n else\n ans = []\n limit = (n / k) * k\n index = 0\n while index < limit\n index += k\n next if index < y\n x = index - y\n ans << x if x > 0\n end\n if ans.length == 0\n puts \"-1\"\n else\n puts ans.join(\" \")\n end\n end\nend\n"}, {"source_code": "y,k,n=gets.split.collect{|e| e.to_i}\nfl=0\ni=k;\nwhile (i= n then\n puts \"-1\"\nelsif k == n then\n if n - y > 0 then\n puts n - y\n else\n puts \"-1\"\n end\nelse\n maybe = []\n if k > y then \n i = k - y\n else\n i = 1\n t = i * k\n while t < y do\n i += 1\n t = i * k\n end\n i = i * k - y\n# i = 0\n# while (y + i) % k != 0 do\n# i += 1\n# end\n end\n\n if y + i > n then\n puts \"-1\"\n else\n if i != 0 then\n maybe << i\n end\n j = 1\n while y + i + j*k <= n do\n maybe << i + j*k\n j += 1\n end\n if maybe.empty? then \n puts \"-1\"\n else\n puts maybe.join(\" \")\n end\n end\nend"}, {"source_code": "y, k, n = gets.split.map { |x| x.to_i }\nxs = ((y / k) * k + k..n).step(k).map { |x| x - y }.to_a\nputs(xs.empty? ? -1 : xs * ' ')"}, {"source_code": "y, k, n = gets.split.map(&:to_i)\n\nopts = (k - (y % k)).step(n-y,k)\n\nif opts.any?\n\tputs opts.map(&:to_s).join(' ')\nelse\n\tputs \"-1\"\nend"}, {"source_code": "y, k, n = gets.split.map { |x| x.to_i }\n\nx = (y / k + 1) * k - y\nans = []\nwhile x + y <= n\n\tans << x\n\tx += k\nend\nif ans.size > 0\n\tputs ans.join ' '\nelse\n\tputs -1\nend"}, {"source_code": "\ufeffy, k, n = gets.chomp.split(\" \").map{|e| e.to_i}\nans = []\n\nmin = nil\nidx = 1\nloop do\n if idx * k > n\n break\n elsif idx * k >= y and (idx * k - y) > 0\n min = idx * k - y\n break\n end \n idx += 1\nend\nif not min.nil?\n ans << min\n tmp = min + k\n loop do\n if tmp > n - y\n break\n else\n ans << tmp\n end \n tmp += k\n end\nend \n\nans << -1 if ans.length == 0\n\nputs ans.join(\" \")"}, {"source_code": "y, k, n = gets.split.map(&:to_i)\nall = Array.new\ni = y\ni -= y%k\ni += k\nwhile i <= n do\n all << i-y\n i += k\nend\nif all.count == 0\n print -1\nelse\n all.each {|x| print x, \" \"}\nend"}, {"source_code": "y, k, n = gets.split(' ').map(&:to_i)\nres = (((y / k) + 1)..(n / k)).to_a.map { |x| x * k - y }\nputs res.empty? ? -1 : res"}], "negative_code": [{"source_code": "s = gets.split\n\ny = s[0].to_i\nk = s[1].to_i\nn = s[2].to_i\nif k == n then\n puts n - y\nelse\n maybe = []\n if k > y then \n i = k - y\n else\n i = 0\n while (y + i) % k != 0 do\n i += 1\n end\n end\n \n if y + i > n then\n puts \"-1\"\n else\n if i != 0 then\n maybe << i\n end\n j = 1\n while y + i + j*k <= n do\n maybe << i + j*k\n j += 1\n end\n puts maybe.join(\" \")\n end\nend"}, {"source_code": "s = gets.split\n\ny = s[0].to_i\nk = s[1].to_i\nn = s[2].to_i\n\nmaybe = []\n\nsum = y\ni = 1\nwhile (y + i) % k != 0 do\n i += 1\nend\n\nif y + i > n then\n puts \"-1\"\nelse\n maybe << i\n j = 1\n while y + i + j*k < n do\n maybe << i + j*k\n j += 1\n end\n puts maybe.join(\" \")\nend"}, {"source_code": "s = gets.split\n\ny = s[0].to_i\nk = s[1].to_i\nn = s[2].to_i\nif k == n then\n puts n - y\nelsif n/k == 1 then\n puts k - y\nelse\n maybe = []\n if k > y then \n i = k\n else\n i = 1\n while (y + i) % k != 0 do\n i += 1\n end\n end\n\n if y + i > n then\n puts \"-1\"\n else\n maybe << i\n j = 1\n while y + i + j*k <= n do\n maybe << i + j*k\n j += 1\n end\n puts maybe.join(\" \")\n end\nend"}, {"source_code": "s = gets.split\n\ny = s[0].to_i\nk = s[1].to_i\nn = s[2].to_i\nif k == n then\n puts n - y\nelsif n/k == 1 then\n puts k - y\nelse\n maybe = []\n if k > y then \n i = k - y\n else\n i = 1\n while (y + i) % k != 0 do\n i += 1\n end\n end\n\n if y + i > n then\n puts \"-1\"\n else\n maybe << i\n j = 1\n while y + i + j*k <= n do\n maybe << i + j*k\n j += 1\n end\n puts maybe.join(\" \")\n end\nend"}, {"source_code": "s = gets.split\n\ny = s[0].to_i\nk = s[1].to_i\nn = s[2].to_i\nif k >= n then\n puts \"-1\"\nelse\n maybe = []\n i = 1\n while (y + i) % k != 0 do\n i += 1\n end\n\n if y + i > n then\n puts \"-1\"\n else\n maybe << i\n j = 1\n while y + i + j*k <= n do\n maybe << i + j*k\n j += 1\n end\n puts maybe.join(\" \")\n end\nend"}, {"source_code": "s = gets.split\n\ny = s[0].to_i\nk = s[1].to_i\nn = s[2].to_i\n\nif k == n then\n puts n - y\nelse\n maybe = []\n if k > y then \n i = k - y\n else\n i = 0\n while (y + i) % k != 0 do\n i += 1\n end\n end\n\n if y + i > n then\n puts \"-1\"\n else\n if i != 0 then\n maybe << i\n end\n j = 1\n while y + i + j*k <= n do\n maybe << i + j*k\n j += 1\n end\n if maybe.empty? then \n puts \"-1\"\n else\n puts maybe.join(\" \")\n end\n end\nend"}, {"source_code": "\ufeffy, k, n = gets.chomp.split(\" \").map{|e| e.to_i}\nans = []\n\nmin = nil\nidx = 1\nloop do\n if idx * k >= n\n break\n elsif idx * k >= y\n min = idx * k - y\n break\n end \n idx += 1\nend\n\nif not min.nil?\n tmp = min\n loop do\n if tmp >= n - y\n break\n else\n ans << tmp\n end \n tmp += k\n end\nend \n\nans << -1 if ans.length == 0\n\nputs ans.join(\" \")"}, {"source_code": "\ufeffy, k, n = gets.chomp.split(\" \").map{|e| e.to_i}\nans = []\n\nmin = nil\nidx = 1\nloop do\n if idx * k >= n\n break\n elsif idx * k >= y and (idx * k - y) > 0\n min = idx * k - y\n break\n end \n idx += 1\nend\n\nif not min.nil?\n tmp = min\n loop do\n if tmp > n - y\n break\n else\n ans << tmp\n end \n tmp += k\n end\nend \n\nans << -1 if ans.length == 0\n\nputs ans.join(\" \")"}, {"source_code": "\ufeffy, k, n = gets.chomp.split(\" \").map{|e| e.to_i}\nans = []\n\nmin = nil\nidx = 0\nloop do\n if idx * k >= n\n break\n elsif idx * k >= y\n min = idx * k - y\n break\n end \n idx += 1\nend\n\nif not min.nil?\n tmp = min\n loop do\n if tmp >= n - y\n break\n else\n ans << tmp\n end \n tmp += k\n end\nend \n\nans << -1 if ans.length == 0\n\nputs ans.join(\" \")"}, {"source_code": "y, k, n = gets.split.map(&:to_i)\nmax = (n-n%k)-y\nif max < 1\n puts -1\n exit\nend\nwhile max >= 1 do\n puts max\n max -= k\nend"}, {"source_code": "y, k, n = gets.chomp.split(/ /).map(&:to_i)\nif y >= n || (n - y) % k != 0\n puts \"-1\"\nelse\n if k == 1\n puts \"#{(1..(n - y)).to_a.join(\" \")}\"\n else\n ans = []\n limit = (n / k) * k\n index = 0\n while index < limit\n index += k\n next if index < y\n x = index - y\n ans << x\n end\n puts ans.join(\" \")\n end\nend\n"}, {"source_code": "y, k, n = gets.chomp.split(/ /).map(&:to_i)\nif y >= n\n puts \"-1\"\nelse\n ans = []\n (1..(n - y)).each do |x|\n ans << x if x + y < n && (x + y) % k == 0\n end\n puts ans.join(\" \")\nend\n"}, {"source_code": "y, k, n = gets.chomp.split(/ /).map(&:to_i)\nif y >= n\n puts \"-1\"\nelse\n if k == 1\n puts \"#{(1..(n - y)).to_a.join(\" \")}\"\n else\n ans = []\n limit = (n / k) * k\n index = 0\n while index < limit\n index += k\n next if index < y\n x = index - y\n ans << x\n end\n if ans.length == 0\n puts \"-1\"\n else\n puts ans.join(\" \")\n end\n end\nend\n"}, {"source_code": "y, k, n = gets.chomp.split(/ /).map(&:to_i)\nif y >= n\n puts \"-1\"\nelse\n if k == 1\n puts \"#{(1..(n - y)).to_a.join(\" \")}\"\n else\n ans = []\n limit = (n / k) * k\n index = 0\n while index < limit\n index += k\n next if index < y\n x = index - y\n ans << x\n end\n puts ans.join(\" \")\n end\nend\n"}, {"source_code": "y,k,n = gets.split(\" \").map(&:to_i)\ni = (y/k.to_f).ceil\nstart = k * i\nif start >= n\n\tputs -1\nelse\n\tarr = []\n\t(start..n).step(k).each do |a|\n\t\tarr << a - y\n\tend\n\tputs arr.join(\" \")\nend"}, {"source_code": "y,k,n = gets.split(\" \").map(&:to_i)\ni = (y/k.to_f).ceil\nstart = k * i\nif start >= n\n\tputs -1\nelse\n\tarr = []\n\t(start..n).step(k).each do |a|\n\t\t\n\t\tarr << a - y if a - y != 0\n\tend\n\tputs arr.join(\" \")\nend"}, {"source_code": "y,k,n=gets.split.collect{|e| e.to_i}\nfl=0\nif (y<=k) then\n i=k;\n if (i<=n) then fl=1 end\nelse \n i=y+1\n while (i<=n) do\n if (i%k==0) then\n fl=1\n break\n end\n i+=1\n end\nend\nj=i;\nwhile (j<=n) do\n if (j!=i) then print \" \" end\n print j-y \n j+=k\nend\nif (fl==0) then print -1 end\nputs\n"}], "src_uid": "2deda3a05740e1184735bf437e3850a8"} {"source_code": "t = gets.to_i\nt.times do\n puts((gets.chomp!.split('') + gets.chomp!.split('')).uniq.size - 1)\nend\n", "positive_code": [{"source_code": "gets.to_i.times { \n\tp gets.chomp.chars.append(*gets.chomp.chars).group_by{|i|i}.values.map{|i|(i.length+1)/2}.sort{|a,b|b-a}.drop(1).sum\n}"}], "negative_code": [{"source_code": "gets.to_i.times { \n\ta = gets.chomp.chars.append(*gets.chomp.chars).group_by{|i|i}.values.map{|i|(i.length+1)/2}\n\tp (a.count>1? a.sum - 1: 0)\n}"}], "src_uid": "a9143235c8e2b6b188ea3fc8a90f0c80"} {"source_code": "t = gets.to_i\nt.times do\n\ta, b = gets.split.map(&:to_i)\n\tputs a + b\nend", "positive_code": [{"source_code": "n = gets.chomp.to_i\nfor i in 1..n do\n x,y = gets.chomp.split(' ')\n puts x.to_i + y.to_i\nend"}, {"source_code": "$n = gets.to_i\n$i = 1\nuntil $i > $n do\n a, b, * = gets.split.map(&:to_i)\n sum = a + b\n puts( sum )\n $i +=1;\nend"}, {"source_code": "gets.to_i.times do\n puts gets.split.map(&:to_i).inject(:+)\nend"}, {"source_code": "t=gets.to_i\nt.times{\na,b=gets.split(\" \")\nputs a.to_i+b.to_i\n}\n"}, {"source_code": "count_number = gets.to_i\nresult = []\ncount_number.times do |n|\n input_numbers = gets.chomp.split(' ').map(&:to_i)\n sum_numbers = input_numbers.inject(0){|sum,x| sum + x }\n result.push(sum_numbers)\nend\nputs result\n"}, {"source_code": "gets.to_i.times { puts gets.split(' ').map(&:to_i).reduce(:+) }"}, {"source_code": "gets.to_i.times{puts eval gets.gsub(' ', '+')}"}, {"source_code": "gets.to_i.times do\n a, b = gets.split\n a, b = a.to_i, b.to_i\n puts a+b\nend\n"}, {"source_code": "1.upto(gets.chomp.to_i) do\n a,b = gets.chomp.split.map(&:to_i)\n\n puts a + b\nend\n"}], "negative_code": [{"source_code": "1.upto(gets.chomp.to_i) do\n a,b = gets.chomp.split.map(&:to_i)\n s = 0\n a.times { s += 1 }\n b.times { s += 1 }\n\n puts s\nend\n"}, {"source_code": "$n = gets.to_i\n$i = 1\nuntil $i > $n do\n a = gets.to_i\n b = gets.to_i\n sum = a + b\n puts( sum )\n $i +=1;\nend"}], "src_uid": "27ddccc777ef9040284ab6314cbd70e7"} {"source_code": "n,t1,t2,k = gets.to_s.split(\" \").map{|x| Integer x}\n\nd = []\n1.upto n do |i|\n\ta,b = gets.to_s.split(\" \").map{|x| Integer x}\n\n\tl1 = t1 * a\n\tl1 = l1 - (l1*k/100.0)\n\tl1 += t2 * b\n\n\tl2 = t1 * b\n\tl2 = l2 - (l2*k/100.0)\n\tl2 += t2 * a\n \n\tl = (l1>l2 ? l1 : l2)\n\tx = [l,i]\n\n\td.push x\nend\n\nd.sort_by!{|x| [-x[0],x[1]] }\n\nd.each do |x|\n\tputs \"#{x[1]} \"+format(\"%.2f\",x[0])\nend\n\n", "positive_code": [{"source_code": "n, t1, t2, k = gets.split.map(&:to_i)\nabs = n.times.map{gets.split.map(&:to_i)}\nabs.map.with_index do |(a, b), i|\n [i, [a * t1 * (1 - k.to_f / 100) + b * t2, b * t1 * (1 - k.to_f / 100) + a * t2].max]\nend.sort_by{|i, max| [-max, i]}.each do |i, max|\n puts \"#{i+1} #{\"%.2f\" % max}\"\nend\n"}, {"source_code": "def main\n\n n, t1, t2, k = STDIN.gets.split.collect {|s| s.to_i}\n \n a = []\n\n n.times do |i|\n v1, v2 = STDIN.gets.split.collect {|s| s.to_i}\n h1 = v1 * t1 * (1 - k / 100.0) + v2 * t2\n h2 = v2 * t1 * (1 - k / 100.0) + v1 * t2\n a.push([i, [h1, h2].max])\n end\n \n a.sort! do |x, y|\n if x[1] < y[1]\n 1\n elsif x[1] > y[1]\n -1\n else\n x[0] <=> y[0]\n end\n end\n \n a.each {|e| puts \"%d %.2f\" % [e[0] + 1, e[1]]}\nend\n\nmain\n\n"}, {"source_code": "def calcmax(a,b,t1,t2,k)\n f = (100 - k).to_f / 100\n c1 = a*t1*f + b*t2\n c2 = b*t1*f + a*t2\n return [c1,c2].max\nend\n\nn,t1,t2,k = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = Array.new()\nfor i in 0..n-1\n a,b = gets.chomp.split(/ /).map!{|x| x.to_i}\n ar << [i+1, calcmax(a,b,t1,t2,k)]\nend\nar.sort!{|ar1, ar2|\n if ar2[1] == ar1[1]\n ar1[0] <=> ar2[0]\n else\n ar2[1] <=> ar1[1]\n end\n}\nfor i in 0..n-1\n puts ar[i][0].to_s + \" \" + sprintf('%.2f', ar[i][1])\nend\n\n"}, {"source_code": "n,t1,t2,k = gets.split.map(&:to_i)\n\nif t1*0.01*k >= t2\n a = n.times.map{|i| gets.split.map(&:to_i).sort.reverse.push(i) }\nelse\n a = n.times.map{|i| gets.split.map(&:to_i).sort.push(i) }\nend\n\na.map!{|m| [[m[0]*t1*(1-0.01*k) + m[1]*t2,m[1]*t1*(1-0.01*k) + m[0]*t2].max, m[2]] }.sort!{|b,a| (a[0] <=> b[0]).nonzero? or b[1] <=> a[1] }.each{|m| puts \"%d %.02f\"%[m[1]+1,m[0]]}\n"}], "negative_code": [{"source_code": "def calcmax(a,b,t1,t2,k)\n f = (100 - k).to_f / 100\n c1 = a*t1*f + b*t2\n c2 = b*t1*f + a*t2\n return [c1,c2].max\nend\n\nn,t1,t2,k = gets.chomp.split(/ /).map!{|x| x.to_i}\nar = Array.new()\nfor i in 0..n-1\n a,b = gets.chomp.split(/ /).map!{|x| x.to_i}\n ar << [i+1, calcmax(a,b,t1,t2,k)]\nend\nar.sort!{|ar1, ar2|\n ar2[1] <=> ar1[1]\n}\nfor i in 0..n-1\n puts ar[i][0].to_s + \" \" + sprintf('%.2f', ar[i][1])\nend\n\n"}, {"source_code": "n,t1,t2,k = gets.to_s.split(\" \").map{|x| Integer x}\n\nd = []\n1.upto n do |i|\n\ta,b = gets.to_s.split(\" \").map{|x| Integer x}\n\n\tl1 = t1 * a\n\tl1 = l1 - (l1*k/100.0)\n\tl1 += t2 * b\n\tl2 = t2 * b\n\tl2 = l2 - (l2*k/100.0)\n\tl2 += t1 * a\n \n\tl = (l1>l2 ? l1 : l2)\n\tx = [l,i]\n\n\td.push x\nend\n\nd.sort_by!{|x| [-x[0],x[1]] }\n\nd.each do |x|\n\tputs \"#{x[1]} \"+format(\"%.2f\",x[0])\nend\n\n"}, {"source_code": "n,t1,t2,k = gets.split.map(&:to_i)\n\nif t1*0.01*k >= t2\n a = n.times.map{|i| gets.split.map(&:to_i).sort.reverse.push(i) }\nelse\n a = n.times.map{|i| gets.split.map(&:to_i).sort.push(i) }\nend\n\na.map!{|m| [m[0]*t1*(1-0.01*k) + m[1]*t2, m[2]] }.sort!{|b,a| (a[0] <=> b[0]).nonzero? or b[1] <=> a[1] }.each{|m| puts \"%d %.02f\"% [m[1]+1,m[0]]}\n"}, {"source_code": "n, t1, t2, k = gets.split.map(&:to_i)\nabs = n.times.map{gets.split.map(&:to_i)}\nabs.map.with_index do |(a, b), i|\n [i, [a * t1 * (1 - k.to_f / 100) + b * t2, b * t2 * (1 - k.to_f / 100) + a * t2].max]\nend.sort_by{|i, max| [-max, i]}.each do |i, max|\n puts \"#{i+1} #{\"%.2f\" % max}\"\nend\n"}], "src_uid": "a89f9310996eb23254d07e52544e30ae"} {"source_code": "n, c = gets, Hash.new(0)\ngets.split.each {|a| c[a] += 1}\np c.values.max", "positive_code": [{"source_code": "_ = $stdin.gets\n\nbxs = $stdin.gets.chomp.split(\" \").map{ |a| a.to_i }\nns = {};\nbxs.each{ |a|\n ns[a] = (ns[a] || 0) + 1\n}\nputs ns.values.max\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\narr = gets.split.map{|x| x.to_i}\narr.sort!\n\n$ans = 0\nlast = -1\nstreak = 0\narr.each do |x|\n\tif x != last then\n\t\tlast = x\n\t\t$ans = streak unless streak <= $ans\n\t\tstreak = 1\n\telse\n\t\tstreak += 1\n\tend\nend\n$ans = streak unless streak <= $ans\n\nputs $ans\n"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\narr = gets.split.map{|x| x.to_i}\narr.sort!\n\n$ans = 1\n(n-1).times do |x|\n\tif arr[x] == arr[x+1] then\n\t\t$ans += 1\n\tend \nend \nputs $ans\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\narr = gets.split.map{|x| x.to_i}\narr.sort!\n\n$ans = 0\nlast = -1\nstreak = 0\narr.each do |x|\n\tputs x\n\tif x != last then\n\t\tlast = x\n\t\t$ans = streak unless streak <= $ans\n\t\tstreak = 1\n\telse\n\t\tstreak += 1\n\tend\nend\n$ans = streak unless streak <= $ans\n\nputs $ans\n"}], "src_uid": "0cbd3eee259b1436f82e259be7d7ee0e"} {"source_code": "n = gets.to_i\nb, total = 100, 0\nn.times do\n a, p = gets.split.map(&:to_i)\n b = p if p < b\n total += a * b\nend\nputs total\n", "positive_code": [{"source_code": "n = gets.to_i\nmoney = 0\nless = 99999999999999999999\nn.times do\n\tx,y= *gets.split(\" \").map(&:to_i)\n\tless = y if less > y\n\tmoney += less*x\nend\n\np money\n"}, {"source_code": "n, total_cost, min_so_far = gets.chomp.to_i, 0, 101\nn.times do |t|\n\ta,p = gets.chomp.split(\" \").map(&:to_i)\n\tmin_so_far = p if p < min_so_far\n\ttotal_cost += a*min_so_far\nend\n\nputs total_cost"}, {"source_code": "n = gets.to_i\ntotal = 0\nmn = 1000\nfor i in 1..n\n a,b = gets.split().map(&:to_i)\n mn = [mn,b].min\n total+= a*mn\nend\nputs total"}, {"source_code": "# http://codeforces.com/contest/588/problem/A\n# A. Duff and Meat\n\nn = gets.chomp.to_i\n\nsum = 0\nmin = 1000\nn.times do\n a, c = gets.chomp.split.map(&:to_i)\n min = c if min > c\n\n sum += min * a\nend\n\nputs sum\n"}, {"source_code": "\nn = gets.chomp.to_i;\nmin = 0x7fffffff;\ncost = 0;\nn.times do |x|\n a, p = gets.chomp.split.map(&:to_i);\n min = [min, p].min;\n cost += a * min;\nend\nputs cost;\n"}, {"source_code": "n = gets.strip.to_i\na = []\np = []\nn.times do |i|\n a[i], p[i] = gets.strip.split(\" \").map(&:to_i)\nend\ni = 0\nmoney = 0\nwhile i < n do \n money += a[i] * p[i]\n j = i + 1\n while j < n && p[j] > p[i] do \n money += a[j] * p[i]\n j += 1\n end\n i = j\nend\nputs money"}, {"source_code": "#! ruby\n# Try Codeforces Round 326 div2\n# author: Leonardone @ NEETSDKASU\n\nn = gets.to_i\n\npMin = 100\ntotal = 0\n\nn.times do\n ai, pi = gets.chomp.split.map(&:to_i)\n pMin = [pi, pMin].min\n total += ai * pMin\nend\n\nputs total"}, {"source_code": "n = gets.to_i\na = []\nn.times{\n x, y = gets.split(\" \").map(&:to_i)\n a << [x,y]\n}\nans = 0\ncur = a[0][1]\na.each{ |x|\n cur = [cur,x[1]].min\n ans += cur*x[0]\n}\nputs ans"}, {"source_code": "n = readline.to_i\np = 100; ans = 0; num = 0\nn.times do\n a, b = readline.split().map(&:to_i)\n p = b if p > b\n ans += p * a\nend\nputs ans\n"}, {"source_code": "n=gets.chomp.to_i\n\na=0\nb=[]\n\nwhile a3 and i 0 do\n\tn -= 1\n\ta,p = gets.chomp.split(' ').map!{ |o| o.to_i }\n\tprice = p if price > p\n\tmoney += price * a\nend\n\nputs money\n"}, {"source_code": "n = gets.to_i\nr,m = 0,1000\nn.times do |i|\n\ta,b = gets.split.map(&:to_i)\n\tm = [ b , m ].min\n\tr += m * a\nend\np r"}, {"source_code": "\n \nnumDays = gets.chomp.to_i\n \nminPrice = 100 # max price\ntotalCost = 0\n \nfor i in 0..numDays-1\n\n inStr = gets.chomp.split(\" \")\n neededOnDay = inStr[0].to_i\n priceOnDay = inStr[1].to_i\n \n if priceOnDay < minPrice\n minPrice = priceOnDay\n end\n \n totalCost += minPrice * neededOnDay\n \n \nend\n\nputs totalCost"}, {"source_code": "\n \nnumDays = gets.chomp.to_i\nneededOnDay = [] # Array.new(numDays)\npriceOnDay = [] # Array.new(numDays)\n \nminPrice = 100 # max price\ntotalCost = 0\n \nfor i in 0..numDays-1\n\n inStr = gets.chomp.split(\" \")\n neededOnDay.push(inStr[0].to_i)\n priceOnDay.push(inStr[1].to_i)\n \n if priceOnDay[i] < minPrice\n minPrice = priceOnDay[i]\n end\n \n totalCost += minPrice * neededOnDay[i]\n \n \nend\n\nputs totalCost"}, {"source_code": "n = gets.to_i\n\neat = Array.new\nprice = Array.new\n(1..n).each do\n tokens = gets.split ' '\n eat.push tokens[0].to_i\n price.push tokens[1].to_i\nend\n\nindex = 0\ntotal = 0\n\nwhile index < n do\n pp = price[index]\n store = eat[index]\n\n while index+1 < n and pp < price[index + 1] do\n index += 1\n store += eat[index]\n end\n total += store * pp\n index += 1\nend\n\nputs total\n\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nspent = 0\nlowest_price = 100\nn.times {\n meat, price = gets.split.map(&:to_i)\n\n if price < lowest_price\n lowest_price = price\n end\n\n # this would be enough.\n # knowing the lowest price, count required amount and multiply it by currently known lowest price\n spent += meat*lowest_price\n}\n\nputs spent\n"}, {"source_code": "n = gets.chomp.to_i\nas = []\nps = []\nn.times do\n a, p = gets.chomp.split(' ').map(&:to_i)\n as << a\n ps << p\nend\n\nm = 0\nminp = ps[0]\nfor i in 0..n-1\n a = as[i]\n p = ps[i]\n minp = [minp, p].min\n m += a * minp\nend\n\nputs m\n"}, {"source_code": "days = gets.chomp.to_i\ndata = []\nfor i in (0..days-1)\n\tdata[i] = gets.chomp\n\tdata[i] = data[i].split\nend\n\ncost = 0\nfor i in (0..days-1)\n\tif i == 0\n\t\tcost += (data[i][0].to_i * data[i][1].to_i)\n\telse\n\t\tif data[i-1][1].to_i <= data[i][1].to_i\n\t\t\tdata[i][1] = data[i-1][1].to_i\n\t\t\tcost += (data[i][0].to_i * data[i][1].to_i)\n\t\telse\n\t\t\tcost += (data[i][0].to_i * data[i][1].to_i)\n\t\tend\n\tend\nend\n\nprint cost"}, {"source_code": "n = gets.to_i\nb, ans = 100, 0\nn.times do\n a, p = gets.split.map(&:to_i)\n b = p if p < b\n ans += a * b\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na, p = [], []\nn.times.each{|i| a[i], p[i] = gets.split.map(&:to_i)}\nbuy, i, total = 0, 0, 0\nn.times do |j|\n buy += a[j]\n if j == n - 1 || p[j + 1] < p[i]\n total += p[i] * buy\n i = j + 1\n buy = 0\n end\nend\np total\n"}, {"source_code": "n = gets.chomp.to_i\n\na = []\np = []\n\nn.times do |i|\n aa, pp = gets.chomp.split(\" \").map(&:to_i)\n a << aa\n p << pp\nend\n\ndef lowest_cost(a, p)\n if a.size == 0\n 0\n elsif a.size == 1\n a[0] * p[0]\n else\n low_cost = p.min\n low_cost_day = p.index(low_cost)\n\n kg = 0\n a[low_cost_day..-1].each do |k|\n kg += k\n end\n cost = kg * low_cost + lowest_cost(a[0...low_cost_day], p[0...low_cost_day])\n end\nend\n\nputs lowest_cost(a, p)\n"}, {"source_code": "n = gets.to_i\nmin = 109\nsum = 0\nn.times do\n a, b = gets.split(' ').map(&:to_i)\n if b < min\n min = b\n end\n sum += min * a\nend\nprint sum, \"\\n\"\n"}, {"source_code": "min = 1000\nsum = 1.upto(gets.to_i).inject(0) do |sum, idx|\n a, p = gets.split(' ').map(&:to_i)\n\n min = [min, p].min\n\n sum + a*min\nend\n\nputs sum\n"}, {"source_code": "\nn = gets.to_i\na1,b1 = gets.split.map(&:to_i)\ns = a1 * b1\nfor i in(2..n)\n a,b = gets.split.map(&:to_i)\n if(b>b1)\n s = s + (a*b1)\n \n else\n s = s + (a*b)\n b1=b\n end\nend\np s"}, {"source_code": "n = gets.to_i\n\nlast_min = 0x3f3f3f3f\n\nans = 0\nn.times do\n\ta, p = gets.split.map { |s| s.to_i }\n\tlast_min = [last_min, p].min\n\tans += last_min * a\nend\n\nputs ans\n"}, {"source_code": "totalDay = gets.chomp.to_i\nmeatHash ||= {}\ncheapestPrice ||= 500\nneededMoney = 0\n\ntotalDay.times do\n\tline = gets.chomp.split(' ').map {|item| item.to_i}\n\tneeded, price = line[0], line[1]\n\n\tcheapestPrice = price if cheapestPrice > price\n\tneededMoney += cheapestPrice * needed\nend\n\nputs neededMoney"}], "negative_code": [{"source_code": "# http://codeforces.com/contest/588/problem/A\n# A. Duff and Meat\n\nn = gets.chomp.to_i\n\nsum = 0\nmin = 100.0\nn.times do\n a, c = gets.chomp.split.map(&:to_i)\n min = c if min > c\n\n sum += min * a\nend\n\nputs sum\n"}, {"source_code": "# http://codeforces.com/contest/588/problem/A\n# A. Duff and Meat\n\nn = gets.chomp.to_i\n\namounts = []\ncosts = []\nmin = 100.0\nn.times do\n a, c = gets.chomp.split.map(&:to_i)\n min = c if min > c\n amounts << a\n costs << c\nend\n\narr = []\namounts.zip(costs).each.with_index do |v, idx|\n a, c = v\n if c == min\n arr << amounts[idx..-1].map { |e| e * min }\n break\n else\n arr << a * c\n end\nend\nputs arr.flatten.inject(0, :+)\n"}, {"source_code": "\nn = gets.to_i\na1,b1 = gets.split.map(&:to_i)\ns = a1 * b1\nfor i in(2..n)\n a,b = gets.split.map(&:to_i)\n if(b>b1)\n s = s + (a*b1)\n else\n s = s + (a*b)\n end\n b1=b\nend\np s"}], "src_uid": "28e0822ece0ed35bb3e2e7fc7fa6c697"} {"source_code": "n = gets.to_i\narr = Array.new(n,false)\ngets.split(\" \").map(&:to_i).drop(1).each{ |i|\n arr[i-1] = true if i > 0\n}\n\ngets.split(\" \").map(&:to_i).drop(1).each{ |i|\n arr[i-1] = true if i > 0\n}\n\nputs arr.all? ? \"I become the guy.\" : \"Oh, my keyboard!\"", "positive_code": [{"source_code": "g=->{gets.split[1..-1]};require 'set';puts gets.to_i==Set.new(g[]+g[]).size ? 'I become the guy.':'Oh, my keyboard!'"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'"}, {"source_code": "levels = gets.chomp.to_i\nx = gets.chomp\nx = x.split\ny = gets.chomp\ny = y.split\n\narray = []\nx_levels = x[0].to_i\ny_levels = y[0].to_i\nfor i in (1..x.size-1)\n\tif array.include?(x[i].to_i) == false && x[i].to_i != 0\n\t\tarray << x[i].to_i\n\tend\nend \nfor i in (1..y.size-1)\n\tif array.include?(y[i].to_i) == false && y[i].to_i != 0\n\t\tarray << y[i].to_i\n\tend\nend \n\nif levels == array.size\n\tprint \"I become the guy.\"\nelse\n\tprint \"Oh, my keyboard!\"\nend"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'\n"}, {"source_code": "#puts \"Enter the number of levels\\n\"\nn = gets.to_i\n#puts \"Enter number of level x can pass then level number in a single line and same for y\\n\"\nx = gets.chomp.to_s.split(\" \")\ny = gets.chomp.to_s.split(\" \")\na = []\nl = x.length\nm = 0\nfor i in 1...l do\n a[m] = x[i].to_i\n m += 1\nend\nfor j in 1...y.length do\n a[m+j-1] = y[j].to_i\nend\na = a.sort\nw = a.length\nv = 1\nr = [n]\nfor h in 1..n do\n c = 0\n d = 0\n for k in 0...w do\n if h != a[k]\n c += 0\n else\n c += 1\n end \n end\n r[h-1] = c\nend\nr = r.sort\n#p r\nif r[0] == 0\n puts \"Oh, my keyboard!\"\nelse\n puts \"I become the guy.\"\nend\n "}, {"source_code": "n = gets.to_i\np1, p2 = gets.split(/ /).drop(1).map(&:to_i), gets.split(/ /).drop(1).map(&:to_i)\nputs (p1 | p2).count == n ? \"I become the guy.\" : \"Oh, my keyboard!\""}, {"source_code": "a = gets.to_i\nb = gets.split.map &:to_i\nc = gets.split.map &:to_i\nputs (c[1..-1] | b[1..-1]).size == a ? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'\n"}, {"source_code": "n = gets.to_i\nif (gets.split[1..-1].map(&:to_i) | gets.split[1..-1].map(&:to_i)).size == n\n\tputs \"I become the guy.\"\nelse\n\tputs \"Oh, my keyboard!\"\nend\n"}, {"source_code": "n = gets.to_i\nx = gets.split(' ').map(&:to_i)\ny = gets.split(' ').map(&:to_i)\nl = []\n\nx.drop(1).each do |i|\n if i > 0 && !l.include?(i)\n l.push(i)\n end\nend\n\ny.drop(1).each do |j|\n if j > 0 && !l.include?(j)\n l.push(j)\n end\nend\n\nputs l.length == n ? 'I become the guy.' : 'Oh, my keyboard!'"}, {"source_code": "n = gets.to_i\na=gets.split.map(&:to_i)[1..-1];b=gets.split.map(&:to_i)[1..-1] \nputs (a+b).uniq.size==n ? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "level_count = gets.to_i\nx_levels = gets.split.map &:to_i\nx_levels.shift\ny_levels = gets.split.map &:to_i\ny_levels.shift\n\nlevels = Array.new level_count, false\n\nx_levels.each do |element|\n levels[element - 1] = true\nend\n\ny_levels.each do |element|\n levels[element - 1] = true\nend\n\nincomplete_level = false\n\nlevel_count.times do |i|\n unless levels[i]\n puts \"Oh, my keyboard!\"\n incomplete_level = true\n break\n end\nend\n\nputs \"I become the guy.\" unless incomplete_level\n"}, {"source_code": "require 'set'\nn = gets.chomp.to_i\nline = gets.chomp.split\nset = Set.new\n\np = line[0].to_i\nfor i in 1..p\n set.add(line[i].to_i)\nend\n\n\nline = gets.chomp.split\np = line[0].to_i\nfor i in 1..p\n set.add(line[i].to_i)\nend\n\nif set == (1..n).to_a.to_set\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n\n"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\na=gets.split.map(&:to_i)[1..-1]+gets.split.map(&:to_i)[1..-1]\nputs (1..n).all?{|i|a.include?(i)} ? 'I become the guy.' : 'Oh, my keyboard!'"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)[1..-1]\nb = gets.split.map(&:to_i)[1..-1]\n\nputs a.concat(b).uniq.size == n ? 'I become the guy.' : 'Oh, my keyboard!'"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i) \nb = gets.split(' ').map(&:to_i)\n\nputs((a[1..-1]+b[1..-1]).sort.uniq.size == n ? 'I become the guy.' : 'Oh, my keyboard!')\n"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'\n"}, {"source_code": "require 'set'\n\ndef read_next_line\n gets.chomp.split.map(&:to_i)\nend\n\nn = gets.chomp.to_i\nputs (Set.new(read_next_line[1..-1]) + read_next_line[1..-1]).size == n ? 'I become the guy.' : 'Oh, my keyboard!'"}, {"source_code": "n = gets.to_i\np = gets.split.map(&:to_i)\nq = gets.split.map(&:to_i)\n\nif ((p[1..-1] + q[1..-1]).uniq).size == n\n\tputs \"I become the guy.\"\nelse\n\tputs \"Oh, my keyboard!\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\np = gets.chomp.split(\" \").map(&:to_i)\nq = gets.chomp.split(\" \").map(&:to_i)\np.delete_at(0)\nq.delete_at(0)\nres = p | q\nputs res.size == n ? \"I become the guy.\" : \"Oh, my keyboard!\""}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(' ').map(&:to_i)[1..-1]\nb = gets.chomp.split(' ').map(&:to_i)[1..-1]\nputs (a | b).size == n ? \"I become the guy.\" : \"Oh, my keyboard!\""}, {"source_code": "n = gets.to_i\n\ninput = gets\np = input.split\np.shift\n\ninput = gets\nq = input.split\nq.shift\n\n# puts pn\nn.times\n\np.each { |elem| q.push(elem) }\n\nq.uniq!\n\nputs q.count == n ? \"I become the guy.\" : \"Oh, my keyboard!\""}, {"source_code": "#! /usr/bin/env ruby\n# -*- coding: utf-8 -*-\n# vim:fenc=utf-8\n#\n# Copyright \u00a9 2014 Szymon Sliwa \n#\n# Distributed under terms of the MIT license.\n\n\nn = gets.to_i\np, *tab_p = gets.split.map(&:to_i)\nq, *tab_q = gets.split.map(&:to_i)\n\ntab = tab_p + tab_q\ntab.sort!.uniq!\n\nif tab == (1..n).to_a\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n\n\n\n\n\n"}, {"source_code": "n = STDIN.gets.to_i\nlevels_of_x = STDIN.gets.to_s.split(' ').map(&:to_i)\nlevels_of_x.shift\nlevels_of_y = STDIN.gets.to_s.split(' ').map(&:to_i)\nlevels_of_y.shift\n\nresult = (1..n).to_a.all? do |i|\n levels_of_x.include?(i) || levels_of_y.include?(i)\nend\n\nputs result ? 'I become the guy.' : 'Oh, my keyboard!'\n"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'\n"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'\n"}, {"source_code": "n = gets.chomp.to_i\nxPass = gets.chomp.split(' ').map {|item| item.to_i}\nyPass = gets.chomp.split(' ').map {|item| item.to_i}\nxPass.delete_at(0)\nyPass.delete_at(0)\nxPass.sort!\nyPass.sort!\nxPass.uniq!\nyPass.uniq!\nflag = true\n\n(1..n).each do |stage|\n\tflag = false if xPass.count(stage) == 0 && yPass.count(stage) == 0\nend\n\nputs \"I become the guy.\" if flag\nputs \"Oh, my keyboard!\" if !flag"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'"}, {"source_code": "n = STDIN.readline.to_i\nps = STDIN.readline.split.map {|s| s.to_i }[1..-1]\nqs = STDIN.readline.split.map {|s| s.to_i }[1..-1]\nmark = {}\n[ps, qs].each do |xs|\n\txs.each {|x| mark[x] = true }\nend\n(1..n).each do |i|\n\tif mark[i] == nil\n\t\tputs 'Oh, my keyboard!'\n\t\texit\n\tend\nend\nputs \"I become the guy.\"\n"}, {"source_code": "level = gets.chomp.to_i\ninput_x, input_y = gets.chomp.split(\" \"), gets.chomp.split(\" \")\ncounter = {}\ngame = []\nfor i in 1..input_x[0].to_i\n game << input_x[i]\nend\nfor i in 1..input_y[0].to_i\n game << input_y[i]\nend\nfor i in 0...game.length\n counter[game[i]] = 1\nend\nsum = 0\ncounter.each do |key, value|\n sum += value\nend\nif sum == level\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n"}, {"source_code": "n = $stdin.readline.to_i\na = $stdin.readline.split.map(&:to_i)\nb = $stdin.readline.split.map(&:to_i)\n\na.shift\nb.shift\n\nt = (a+b).uniq\nt.sort!\n\nputs (1..n).to_a==t ? \"I become the guy.\" : \"Oh, my keyboard!\""}, {"source_code": "arr = []\nn = gets.to_i\n2.times do\n arr.push(gets.chomp.split[1..-1].map &:to_i)\nend\narr = arr.inject(:+).uniq\nputs arr.size == n ? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)[1..-1]\nb = gets.split.map(&:to_i)[1..-1]\nm = Array.new(n, 0)\n\na.each { |x|\n\tm[x-1] = 1\n}\n\nb.each { |x|\n\tm[x-1] = 1\n}\n\nsum = 0\nfor i in 0...n\n\tsum += m[i]\nend\nif (sum == n)\n\tputs \"I become the guy.\"\nelse\n\tputs \"Oh, my keyboard!\"\nend\n"}, {"source_code": "k = gets.to_i\na = gets.split(\" \").map(&:to_i)\nb = gets.split(\" \").map(&:to_i)\na << k+2\nb << k+2\nn = a[0]\nm = b[0]\na[0]=b[0]=0\na.sort!\nb.sort!\ni = j = cur = 1\nwhile i<=n || j<=m\n while cur > a[i] do\n i+=1;\n end\n while cur > b[j] do\n j+=1;\n end\n if cur == a[i] || cur == b[j]\n cur+=1;\n else\n break\n end\nend\nif cur == k+1\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'\n"}, {"source_code": "levels = gets.chomp.to_i\nx = gets.chomp.split(/ /).map(&:to_i)\ny = gets.chomp.split(/ /).map(&:to_i)\np, q = x[0], y[0]\nx_levels = x[1..p]\ny_levels = y[1..q]\ntotal_levels = x_levels + y_levels\ntotal_levels.uniq!\ntotal_levels.sort!\npassed = true\n(1..levels).each do |level|\n next if total_levels[level - 1] == level\n passed = false\n break\nend\nif passed\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'\n"}, {"source_code": "n=(1..gets.to_i).to_a\nx=gets.split.map{|e| e.to_i}\ny=gets.split.map{|e| e.to_i}\nx[0]=0\ny[0]=0\nputs (n-x-y).size==0?\"I become the guy.\":\"Oh, my keyboard!\""}, {"source_code": "n = gets.chomp.to_i\n\nlevels1 = gets.chomp.split(' ').map{|a| a.to_i}\nlevels2 = gets.chomp.split(' ').map{|a| a.to_i}\n\nlevels1.shift\nlevels2.shift\n\nif levels1.concat(levels2).uniq.sort == (1..n).to_a\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n"}, {"source_code": "levels = [false] * gets.to_i\nx = gets.split.map(&:to_i)\nx.shift\ny = gets.split.map(&:to_i)\ny.shift\n\nx.each { |l| levels[l - 1] = true }\ny.each { |l| levels[l - 1] = true }\n\nif levels.all?\n puts 'I become the guy.'\nelse\n puts 'Oh, my keyboard!'\nend\n"}, {"source_code": "\nn = gets.to_i\nx = gets.split.map(&:to_i)\ny = gets.split.map(&:to_i)\nx.delete_at(0)\ny.delete_at(0)\nfor i in x\n\ty.delete_at(y.index(i)) if !y.index(i).nil?\nend\ns = (1+n)/2.0*n\nx = x+y\nsum = 0\nfor i in x \n\tsum+=i\nend\nputs sum == s ? \"I become the guy.\" : \"Oh, my keyboard!\""}, {"source_code": "n=gets.chomp.to_i\na = gets.chomp.strip.split\nb = gets.chomp.strip.split\na=a[1..-1]\nb=b[1..-1]\nputs ((a+b).uniq-['0']).length == n ? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'\n"}, {"source_code": "n = gets.chomp.to_i\nx = gets.chomp.split(' ').map(&:to_i).drop(1)\ny = gets.chomp.split(' ').map(&:to_i).drop(1)\n\ns = (x + y).uniq\n\nif s.size == n\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend"}, {"source_code": "require 'set';puts gets.to_i==Set.new(gets.split[1..-1]+gets.split[1..-1]).size ? 'I become the guy.':'Oh, my keyboard!'"}, {"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'"}], "negative_code": [{"source_code": "g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq ? 'I become the guy.':'Oh, my keyboard!'"}, {"source_code": "levels = gets.chomp.to_i\nx = gets.chomp\nx = x.split\ny = gets.chomp\ny = y.split\n\narray = []\nfor i in (0..x.size-1)\n\tif array.include?(x[i].to_i) == false && x[i].to_i != 0\n\t\tarray << x[i].to_i\n\tend\nend \nfor i in (0..y.size-1)\n\tif array.include?(y[i].to_i) == false && y[i].to_i != 0\n\t\tarray << y[i].to_i\n\tend\nend \n\nif levels == array.size\n\tprint \"I become the guy.\"\nelse\n\tprint \"Oh, my keyboard!\"\nend"}, {"source_code": "n = gets.to_i\narr = Array.new(n,false)\ngets.split(\" \").map(&:to_i).each{ |i|\n arr[i-1] = true if i > 0\n}\n\ngets.split(\" \").map(&:to_i).each{ |i|\n arr[i-1] = true if i > 0\n}\n\nputs arr.all? ? \"I become the guy.\" : \"Oh, my keyboard!\""}, {"source_code": "n = gets.to_i\narr = Array.new(n,false)\ngets.split(\" \").map(&:to_i).each{ |i|\n arr[i-1] = true\n}\n\ngets.split(\" \").map(&:to_i).each{ |i|\n arr[i-1] = true\n}\n\nputs arr.all? ? \"I become the guy.\" : \"Oh, my keyboard!\""}, {"source_code": "a = gets.to_i\nb = gets.split.map &:to_i\nc = gets.split.map &:to_i\nd = (b.uniq + c.uniq).sort\nf = true\n(1..a).map {|x| f = d.include?(x)}\nputs f ? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "a = gets.to_i\nb = gets.split.map &:to_i\nc = gets.split.map &:to_i\nputs (b + c).uniq.size == a ? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "a = gets.to_i\nb = gets.split.map &:to_i\nc = gets.split.map &:to_i\nputs (c | b).size == a ? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "n = gets.to_i\nx = gets.split(' ').map(&:to_i)\n# x.shift\ny = gets.split(' ').map(&:to_i)\nl = []\n\nx.drop(1).each do |i|\n if i > 0 && !l.include?(i)\n l.push(i)\n end\nend\n\ny.each do |j|\n if j > 0 && !l.include?(j)\n l.push(j)\n end\nend\n\nputs l.length == n ? 'I become the guy.' : 'Oh, my keyboard!'"}, {"source_code": "n = gets.to_i\na=gets.split.map(&:to_i);b=gets.split.map(&:to_i) \np (a+b).uniq.size==4?\"I become the guy.\":\"Oh, my keyboard!\""}, {"source_code": "n = gets.to_i\na=gets.split.map(&:to_i);b=gets.split.map(&:to_i) \nputs (a+b).uniq.size==n ? \"I become the guy.\" : \"Oh, my keyboard!\""}, {"source_code": "n = gets.to_i\na=gets.split.map(&:to_i);b=gets.split.map(&:to_i) \nputs (a+b).uniq.size==4?\"I become the guy.\":\"Oh, my keyboard!\""}, {"source_code": "n = gets.to_i\na=gets.split.map(&:to_i);b=gets.split.map(&:to_i);a.delete(0);b.delete(0)\nputs a.concat(b).uniq.size==n ? \"I become the guy.\" : \"Oh, my keyboard!\""}, {"source_code": "require 'set'\nn = gets.chomp.to_i\nline = gets.chomp.split\np = line[0].to_i\nset = Set.new\n\nfor i in 1..p\n set.add(line[i].to_i)\nend\n\nline = gets.chomp.split\nfor i in 0..p-1\n set.add(line[i].to_i)\nend\n\nif set == (1..n).to_a.to_set\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n\n"}, {"source_code": "n = STDIN.gets.to_i\nlevels_of_x = STDIN.gets.to_s.split(' ').map(&:to_i)\nlevels_of_x.shift\nlevels_of_y = STDIN.gets.to_s.split(' ').map(&:to_i)\nlevels_of_y.shift\n\nresult = (1..n).to_a.all? do |i|\n levels_of_x.include?(i) || levels_of_y.include?(i)\nend\n\nputs result ? 'I became the guy.' : 'Oh, my keyboard!'\n"}, {"source_code": "n = gets.chomp.to_i\nxPass = gets.chomp.split(' ').map {|item| item.to_i}\nyPass = gets.chomp.split(' ').map {|item| item.to_i}\nxPass.sort!\nyPass.sort!\nxPass.uniq!\nyPass.uniq!\nflag = true\n\n(1..n).each do |stage|\n\tflag = false if xPass.count(stage) == 0 && yPass.count(stage) == 0\nend\n\nputs \"I become the guy.\" if flag\nputs \"Oh, my keyboard!\" if !flag"}, {"source_code": "\nn = gets.to_i\nx = gets.split.map(&:to_i)\ny = gets.split.map(&:to_i)\nx.delete_at(0)\ny.delete_at(0)\nfor i in x\n\ty.delete_at(y.index(i)) if y.index(i)\nend\ns = (1+n)/2.0*n\nx = x+y\nsum = 0\nfor i in x \n\tsum+=i\nend\nputs sum == s ? \"I become the guy\" : \"Oh, my keyboard!\""}, {"source_code": "level = gets.chomp.to_i\nlittle_x, little_y = gets.chomp.split(\" \"), gets.chomp.split(\" \")\ngame = little_x + little_y\ngame.map! {|i| i.to_i}\nif game.max >= level\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend"}, {"source_code": "level = gets.chomp.to_i\nlittle_x, little_y = gets.chomp.split(\" \"), gets.chomp.split(\" \")\ngame = (little_x + little_y)\nif game.max.to_i == level\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend"}, {"source_code": "level = gets.chomp.to_i\nlittle_x, little_y = gets.chomp.split(\" \"), gets.chomp.split(\" \")\ngame = little_x + little_y\ncounter = {}\nfor i in 0...game.length\n counter[game[i]] = 1\nend\nsum = 0\ncounter.each do |key, value|\n sum += value\nend\nif sum == level\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend"}, {"source_code": "level = gets.chomp.to_i\nlittle_x, little_y = gets.chomp.split(\" \"), gets.chomp.split(\" \")\ngame = little_x + little_y\ncounter = {}\nfor i in 0...game.length\n if game[i] != '0'\n counter[game[i]] = 1\n end\nend\nsum = 0\ncounter.each do |key, value|\n sum += value\nend\nif sum == level\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n"}, {"source_code": "arr = []\nn = gets.to_i\n2.times do \n arr.push(gets.chomp.split.map &:to_i)\nend\narr = arr.inject(:+)\narr = arr - [0]\nputs arr.uniq.size == n ? \"I become the guy.\" : \"Oh, my keyboard!\"\n\n"}, {"source_code": "arr = []\nn = gets.to_i\n2.times do\n arr.push(gets.chomp[1..-1])\nend\narr = arr.inject(:+)\narr = arr.split.map &:to_i\nputs arr.uniq.size == n ? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "arr = []\nn = gets.to_i\n2.times do \n arr.push(gets.chomp.split.map &:to_i)\nend\narr = arr.inject(:+)\nputs arr.uniq.size == n ? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "n = gets.to_i\na = gets.split(\" \").map(&:to_i)\nb = gets.split(\" \").map(&:to_i)\na << n+2\nb << n+2\nn = a[0]\nm = b[0]\ni = j = cur = 1\nwhile i<=n || j<=m\n while cur > a[i] do\n i+=1;\n end\n while cur > b[j] do\n j+=1;\n end\n if cur == a[i] || cur == b[j]\n cur+=1;\n else\n break\n end\nend\nif cur = n+1\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend"}, {"source_code": "k = gets.to_i\na = gets.split(\" \").map(&:to_i)\nb = gets.split(\" \").map(&:to_i)\na << k+2\nb << k+2\nn = a[0]\nm = b[0]\ni = j = cur = 1\nwhile i<=n || j<=m\n while cur > a[i] do\n i+=1;\n end\n while cur > b[j] do\n j+=1;\n end\n if cur == a[i] || cur == b[j]\n cur+=1;\n else\n break\n end\nend\nif cur == k+1\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend"}, {"source_code": "levels = gets.chomp.to_i\nx = gets.chomp.split(/ /).map(&:to_i)\ny = gets.chomp.split(/ /).map(&:to_i)\nif x.include?( levels ) || y.include?( levels )\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n"}, {"source_code": "levels = gets.chomp.to_i\nx = gets.chomp.split(/ /).map(&:to_i)\ny = gets.chomp.split(/ /).map(&:to_i)\np, q = x[0], y[0]\nx_levels = x[1..p]\ny_levels = y[1..q]\nif x_levels.include?( levels ) || y_levels.include?( levels )\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\nlevels1 = gets.chomp.split(' ').map{|a| a.to_i}\nlevels2 = gets.chomp.split(' ').map{|a| a.to_i}\n\nlevels1.delete(0)\nlevels2.delete(0)\n\nif levels1.concat(levels2).uniq.sort == (1..n).to_a\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\nlevels1 = gets.chomp.split(' ').map{|a| a.to_i}\nlevels2 = gets.chomp.split(' ').map{|a| a.to_i}\n\nif levels1.concat(levels2).uniq.count >= n\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\nlevels1 = gets.chomp.split(' ').map{|a| a.to_i}\nlevels2 = gets.chomp.split(' ').map{|a| a.to_i}\n\nif (levels1.concat(levels2).uniq.count == n) \n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend\n"}, {"source_code": "levels = [false] * gets.to_i\nx = gets.split.map(&:to_i)\nx.shift\ny = gets.split.map(&:to_i)\ny.shift\n\nx.each { |l| levels[l - 1] = true }\ny.each { |l| levels[l - 1] = true }\n\nif x.all?\n puts 'I become the guy.'\nelse\n puts 'Oh, my keyboard!'\nend\n"}, {"source_code": "n=gets.chomp.to_i\na = gets.chomp.strip.split\nb = gets.chomp.strip.split\nputs ((a+b).uniq-['0']).length == n ? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "n=gets.chomp.to_i\na = gets.chomp.strip.split\nb = gets.chomp.strip.split\nputs (a+b).uniq.length == n ? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "n=gets.chomp.to_i\na = gets.chomp.strip.split\nb = gets.chomp.strip.split\nputs (a+b).uniq.length == 4? \"I become the guy.\" : \"Oh, my keyboard!\"\n"}, {"source_code": "n = gets.chomp.to_i\nx = gets.chomp.split(' ').map(&:to_i).drop(1)\ny = gets.chomp.split(' ').map(&:to_i)\n\ns = (x + y).uniq\n\nif s.size == n\n puts \"I become the guy.\"\nelse\n puts \"Oh, my keyboard!\"\nend"}], "src_uid": "044ade01d2de1486735742369227ae1d"} {"source_code": "class Widget\n\tdef initialize(type, width = 0, height = 0)\n\t\t@type = type.to_sym\n\t\t@border = @spacing = 0\n\t\t@lazy = false\n\t\t@width = width.to_i\n\t\t@height = height.to_i\n\t\t@elements = []\n\tend\n\tdef process\n\t\t@lazy = true\n\t\treturn if @type == :W\n\t\t@height = @width = 0\n\t\treturn if @elements.size == 0\n\t\t@elements.each{|e|\n\t\t\tif @type == :V\n\t\t\t\t@height += e.height\n\t\t\t\t@width = [@width, e.width].max\n\t\t\telse\n\t\t\t\t@height = [@height, e.height].max\n\t\t\t\t@width += e.width\n\t\t\tend\n\t\t}\n\t\tif @type == :V\n\t\t\t@height += 2 * @border + (@elements.size - 1) * @spacing\n\t\t\t@width += 2 * @border\n\t\telse @type == :H\n\t\t\t@height += 2 * @border\n\t\t\t@width += 2 * @border + (@elements.size - 1) * @spacing\n\t\tend\n\tend\n\n\tdef height\n\t\tprocess unless @lazy\n\t\t@height\n\tend\n\n\tdef width\n\t\tprocess unless @lazy\n\t\t@width\n\tend\n\n\tdef pack(w)\n\t\t@elements.push $w[w.to_sym]\n\tend\n\n\tdef set_border(v)\n\t\t@border = v.to_i\n\tend\n\n\tdef set_spacing(v)\n\t\t@spacing = v.to_i\n\tend\nend\n$w = {}\ngets.to_i.times{|x|\n\tcmd = gets\n\tif (cmd[0]>='a' and cmd[0] <= 'z')\n\t\tname, fc = cmd.split '.'\n\t\t#puts name, fc\n\t\tfc,arg = fc.split '('\n\t\targ = arg.split(')')[0]\n\t\t#puts fc\n\t\t$w[name.to_sym].send fc.to_sym, *arg.split(',') \n\telse\n\t\tif (cmd[0]=='W')\n\t\t\tcmd = cmd.split(' ')[1]\n\t\t\tname,arg = cmd.split '('\n\t\t\targ = arg.split(')')[0]\n\t\t\t$w[name.to_sym] = Widget.new(:W, *(arg.split(',')))\n\t\telse\n\t\tif (cmd[0]=='V' || cmd[0] == 'H')\n\t\t\tname = cmd.split(' ')[1]\n\t\t\t$w[name.to_sym] = Widget.new(cmd[0].to_sym)\n\t\tend\n\tend\n\tend\n}\n\n$w.keys.sort.each{|k|\n\tputs \"#{k} #{$w[k].width} #{$w[k].height}\"\n}", "positive_code": [{"source_code": "class Box\n\tattr_accessor :border, :spacing\n\t\n\tdef initialize(type, width, height)\n\t\t@type = type\n\t\t@border = 0\n\t\t@spacing = 0\n\t\t@repaint = false\n\t\t@width = width\n\t\t@height = height\n\t\t@element = []\n\tend\n\n\tdef repaint\n\t\t@repaint = true\n\t\treturn if @type == 'W'\n\t\t@height = @width = 0\n\t\tif @element.size > 0\n\t\t\tif @type == 'V'\n\t\t\t\t@element.each do |e|\n\t\t\t\t\t@height += e.height\n\t\t\t\t\t@width = [@width, e.width].max\n\t\t\t\tend\n\t\t\t\t@height += 2 * border + (@element.size - 1) * spacing\n\t\t\t\t@width += 2 * border\n\t\t\telsif @type == 'H'\n\t\t\t\t@element.each do |e|\n\t\t\t\t\t@height = [@height, e.height].max\n\t\t\t\t\t@width += e.width\n\t\t\t\tend\n\t\t\t\t@height += 2 * border\n\t\t\t\t@width += 2 * border + (@element.size - 1) * spacing\n\t\t\tend\n\t\tend\n\tend\n\n\tdef height\n\t\trepaint unless @repaint\n\t\t@height\n\tend\n\n\tdef width\n\t\trepaint unless @repaint\n\t\t@width\n\tend\n\n\tdef pack(w)\n\t\t@element << w\n\tend\nend\n\nw = {}\n\ngets.to_i.times do\n\t$_ = gets.chomp\n\tif /Widget (\\w+)\\((\\d+),(\\d+)\\)/\n\t\tw[$1] = Box.new('W', $2.to_i, $3.to_i)\n\telsif /(V|H)Box (\\w+)/\n\t\tw[$2] = Box.new($1, 0, 0)\n\telsif /(\\w+)\\.set_border\\((\\d+)\\)/\n\t\tw[$1].border = $2.to_i\n\telsif /(\\w+)\\.set_spacing\\((\\d+)\\)/\n\t\tw[$1].spacing = $2.to_i\n\telsif /(\\w+)\\.pack\\((\\w+)\\)/\n\t\tw[$1].pack(w[$2])\n\telse\n\t\tputs \"ERROR: $_\\n\"\n\tend\nend\n\nw.keys.sort.each do |k|\n\tputs \"#{k} #{w[k].width} #{w[k].height}\"\nend\n"}], "negative_code": [], "src_uid": "258f54f32c6df5390edd804294aad235"} {"source_code": "#!/usr/bin/env ruby\n\nlivings_count = gets.chop.to_i\n\nlivings_relation = {}\ntrees = []\n\nrelations = gets.chop.split\n\nrelations.each.with_index do |b , a|\n a += 1\n b = b.to_i\n\n if !livings_relation[b] && !livings_relation[a]\n trees.push(Array.new)\n trees_index = trees.size - 1\n livings_relation[a] = trees_index\n livings_relation[b] = trees_index\n trees[trees_index] << a\n trees[trees_index] << b\n elsif !livings_relation[b] && livings_relation[a]\n tree_index = livings_relation[a]\n livings_relation[b] = livings_relation[a]\n trees[tree_index] << b\n elsif livings_relation[b] && !livings_relation[a]\n tree_index = livings_relation[b]\n livings_relation[a] = livings_relation[b]\n trees[tree_index] << a\n elsif livings_relation[a] != livings_relation[b]\n # merge\n tree_index = livings_relation[a]\n tree_index_del = livings_relation[b]\n #livings_relation[b] = livings_relation[a]\n trees[tree_index_del].each do |living|\n livings_relation[living] = tree_index\n trees[tree_index] << living\n end\n trees[tree_index_del] = nil\n end\nend\n\nputs trees.compact.size\n", "positive_code": [{"source_code": "require 'set'\nn = gets.to_i\nlist = [0] + gets.chomp.split(\" \").map(&:to_i)\nset = Set.new\nfor i in 1..n\n if(list[list[i]] == i)\n set.add([i,list[i]].min)\n end\nend\nprint set.length\n"}], "negative_code": [], "src_uid": "6d940cb4b54f63a7aaa82f21e4c5b994"} {"source_code": "require 'pp'\n\nn = STDIN.gets.chomp.to_i\nos = STDIN.gets.chomp.split(/ /).map(&:to_i)\n\nss = [(1..n).to_a, os].transpose\nss.sort!{|a, b| a.last <=> b.last }\n\ns = os.sort\ncount=1\nleg = -1\nsame3 = nil\nsame2 = []\n(n-1).times do |i|\n if s[i] == s[i+1]\n count+=1\n if count >=3\n same3 = s[i]\n break\n elsif count >=2\n same2.push s[i]\n end\n else\n count = 1\n end\nend\n\nif same3\n ans = []\n ans.push ss.map{|a,b| a}\n\n pos = []\n ss.each_with_index do |sse,i|\n pos.push i if sse.last == same3\n end\n ss[pos[0]], ss[pos[1]], ss[pos[2]] = ss[pos[1]], ss[pos[2]], ss[pos[0]]\n ans.push ss.map{|a,b| a}\n ss[pos[0]], ss[pos[1]], ss[pos[2]] = ss[pos[1]], ss[pos[2]], ss[pos[0]]\n ans.push ss.map{|a,b| a}\n\n puts \"YES\"\n ans.each{|a| puts a.join(\" \")}\nelsif same2.length >= 2\n ans = []\n ans.push ss.map{|a,b| a}\n\n pos0 = []\n pos1 = []\n ss.each_with_index do |sse,i|\n pos0.push i if sse.last == same2[0]\n pos1.push i if sse.last == same2[1]\n end\n ss[pos0.first], ss[pos0.last] = ss[pos0.last], ss[pos0.first]\n ans.push ss.map{|a,b| a}\n ss[pos1.first], ss[pos1.last] = ss[pos1.last], ss[pos1.first]\n ans.push ss.map{|a,b| a}\n\n puts \"YES\"\n ans.each{|a| puts a.join(\" \")}\nelse\n puts \"NO\"\nend\n\n", "positive_code": [{"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").map {|i| i.to_i }\ninde=Hash.new {|hash,key| hash[key]=[] }\ncount=Array.new(2001,0)\n0.upto(a-1) do |i|\ninde[b[i]]<2\nputs \"YES\"\np=count.index(cp)\n3.times do \nkeys.each do |i|\nprint \"#{inde[i].join(\" \")} \"\nend\nputs\ntemp=inde[p][0]\ntemp2=inde[p][1]\ninde[p][1]=inde[p][2]\ninde[p][2]=temp\ninde[p][0]=temp2\nend\n\nelsif cp==2\n\nif count.count(cp)<2\nputs \"NO\"\n\nelse\nindex1=count.index(cp)\ncount.delete_at(index1)\nindex2=count.index(cp)+1\n\nit=0\nputs \"YES\"\n3.times do \n\nkeys.each do |i|\nprint \"#{inde[i].join(\" \")} \"\nend\nputs\nif it==0\ntemp=inde[index1][0]\ninde[index1][0]=inde[index1][1]\ninde[index1][1]=temp\nit+=1\nelse\ntemp=inde[index2][0]\ninde[index2][0]=inde[index2][1]\ninde[index2][1]=temp\nend\n\nend\n\nend \n\nend\n\n\n\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nh = gets.split.map(&:to_i)\nsol = []\n100.times do\n x = h.map{|x| x * 10 + rand(10)}.map.with_index(1).sort.map(&:last)\n sol << x if !sol.include?(x)\n break if sol.size == 3\nend\n\nif sol.size == 3\n puts 'YES'\n puts sol.map{|x| x.map(&:to_s).join(' ')}\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").map {|i| i.to_i }\ninde=Hash.new {|hash,key| hash[key]=[] }\ncount=Array.new(2001,0)\n0.upto(a-1) do |i|\ninde[b[i]]<2\nputs \"YES\"\np=count.index(cp)\n3.times do \nkeys.each do |i|\nprint \"#{inde[i].join(\" \")} \"\nend\nputs\ntemp=inde[p][0]\ntemp2=inde[p][1]\ninde[p][1]=inde[p][2]\ninde[p][2]=temp\ninde[p][0]=temp2\nend\n\nelsif cp==2\n\nif count.count(cp)<2\nputs \"NO\"\n\nelse\nindex1=count.index(cp)\ncount.delete_at(index1)\nindex2=count.index(cp)+1\n\nit=0\nputs \"YES\"\n3.times do \n\nkeys.each do |i|\nprint \"#{inde[i].join(\" \")} \"\nend\nputs\nif it==0\ntemp=inde[index1][0]\ninde[index1][0]=inde[index1][1]\ninde[index1][1]=temp\nit+=1\nelse\ntemp=inde[index2][0]\ninde[index2][0]=inde[index2][1]\ninde[index2][1]=temp\nend\n\nend\n\nend \n\nend\n\n\n\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nh = gets.split.map(&:to_i)\nsol = []\n100.times do\n x = h.map{|x| x * 10 + rand(10)}.map.with_index(1).sort.map(&:last)\n sol << x if !sol.include?(x)\n break if sol.size == 3\nend\n\nif sol.size == 3\n puts 'YES'\n puts sol.map{|x| x.map(&:to_s).join(' ')}\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nh = gets.split.map(&:to_i)\nsol = []\n100.times do\n x = h.map{|x| x * 10 + rand(10)}.map.with_index(1).sort.map(&:last)\n sol << x if !sol.include?(x)\n break if sol.size == 3\nend\n\nif sol.size == 3\n puts 'YES'\n puts sol.map{|x| x.map(&:to_s).join(' ')}\nelse\n puts 'NO'\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nh = gets.split.map(&:to_i)\nsol = []\n100.times do\n x = h.map{|x| x * 10 + rand(10)}.map.with_index(1).sort.map(&:last)\n sol << x if !sol.include?(x)\n break if sol.size == 3\nend\n\nif sol.size == 3\n puts 'YES'\n puts sol.map{|x| x.map(&:to_s).join(' ')}\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nh = gets.split.map(&:to_i)\nsol = []\n100.times do\n x = h.map{|x| x * 10 + rand(10)}.map.with_index(1).sort.map(&:last)\n sol << x if !sol.include?(x)\n break if sol.size == 3\nend\n\nif sol.size == 3\n puts 'YES'\n puts sol.map{|x| x.map(&:to_s).join(' ')}\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nh = gets.split.map(&:to_i)\nsol = []\n100.times do\n x = h.map{|x| x * 10 + rand(10)}.map.with_index(1).sort.map(&:last)\n sol << x if !sol.include?(x)\n break if sol.size == 3\nend\n\nif sol.size == 3\n puts 'YES'\n puts sol.map{|x| x.map(&:to_s).join(' ')}\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nh = gets.split.map(&:to_i)\nsol = []\n100.times do\n x = h.map{|x| x * 10 + rand(10)}.map.with_index(1).sort.map(&:last)\n sol << x if !sol.include?(x)\n break if sol.size == 3\nend\n\nif sol.size == 3\n puts 'YES'\n puts sol.map{|x| x.map(&:to_s).join(' ')}\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "n = STDIN.readline.to_i\nvalues = STDIN.readline.split.map {|s| s.to_i }\nvalue_indices = {}\nvalues.each_with_index do |value, index|\n\tvalue_indices[value] ||= []\n\tvalue_indices[value].push(index+1)\nend\nperturb_two, perturb_three = [], nil\nvalue_indices.each do |value, indices|\n\tif indices.length >= 3\n\t\tperturb_three = value\n\t\tbreak\n\telsif indices.length == 2\n\t\tperturb_two.push(value)\n\t\tbreak if perturb_two.length == 2\n\tend\nend\norders = 3.times.map { [] }\nif perturb_three != nil\n\tvalue_indices.keys.sort.each do |value|\n\t\tindices = value_indices[value]\n\t\tif value == perturb_three\n\t\t\torders[0].push(indices[0])\n\t\t\torders[0].push(indices[1])\n\t\t\torders[0].push(indices[2])\n\t\t\torders[1].push(indices[1])\n\t\t\torders[1].push(indices[2])\n\t\t\torders[1].push(indices[0])\n\t\t\torders[2].push(indices[2])\n\t\t\torders[2].push(indices[0])\n\t\t\torders[2].push(indices[1])\n\t\t\tindices[3..-1].each {|index| 3.times {|p| orders[p].push(index) } }\n\t\telse\n\t\t\tindices.each {|index| 3.times {|p| orders[p].push(index) } }\n\t\tend\n\tend\nelsif perturb_two.length == 2\n\tvalue_indices.keys.sort.each do |value|\n\t\tindices = value_indices[value]\n\t\tif perturb_two.index(value) == 0\n\t\t\torders[0].push(indices[0])\n\t\t\torders[0].push(indices[1])\n\t\t\torders[1].push(indices[0])\n\t\t\torders[1].push(indices[1])\n\t\t\torders[2].push(indices[1])\n\t\t\torders[2].push(indices[0])\n\t\telsif perturb_two.index(value) == 1\n\t\t\torders[0].push(indices[0])\n\t\t\torders[0].push(indices[1])\n\t\t\torders[1].push(indices[1])\n\t\t\torders[1].push(indices[0])\n\t\t\torders[2].push(indices[1])\n\t\t\torders[2].push(indices[0])\n\t\telse\n\t\t\tindices.each {|index| 3.times {|p| orders[p].push(index) } }\n\t\tend\n\tend\nelse\n\tputs 'NO'\n\texit\nend\nputs 'YES'\n3.times {|i| puts orders[i].join(' ') }\n"}, {"source_code": "n = gets.to_i\nh = gets.split.map(&:to_i)\nif h.uniq.size > n - 2\n puts \"NO\"\nelse\n puts \"YES\"\n h.map!.with_index { |d, i| [d, i + 1] }.sort_by! { |d, i| d }\n\n puts h.map { |d, i| i }.join(\" \")\n\n 1.upto(n - 1).each do |i|\n if h[i - 1][0] == h[i][0]\n h[i - 1], h[i] = h[i], h[i - 1]\n break\n end\n end\n\n puts h.map { |d, i| i }.join(\" \")\n\n (n - 1).downto(1).each do |i|\n if h[i - 1][0] == h[i][0]\n h[i - 1], h[i] = h[i], h[i - 1]\n break\n end\n end\n\n puts h.map { |d, i| i }.join(\" \")\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nh = gets.split.map(&:to_i)\nsol = []\n100.times do\n x = h.map{|x| x * 10 + rand(10)}.map.with_index(1).sort.map(&:last)\n sol << x if !sol.include?(x)\n break if sol.size == 3\nend\n\nif sol.size == 3\n puts 'YES'\n puts sol.map{|x| x.map(&:to_s).join(' ')}\nelse\n puts 'NO'\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nh = gets.split.map(&:to_i)\nsol = []\n100.times do\n x = h.map{|x| x * 10 + rand(10)}.map.with_index(1).sort.map(&:last)\n sol << x if !sol.include?(x)\n break if sol.size == 3\nend\n\nif sol.size == 3\n puts 'YES'\n puts sol.map{|x| x.map(&:to_s).join(' ')}\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nh = gets.split.map(&:to_i)\nsol = []\n100.times do\n x = h.map{|x| x * 10 + rand(10)}.map.with_index(1).sort.map(&:last)\n sol << x if !sol.include?(x)\n break if sol.size == 3\nend\n\nif sol.size == 3\n puts 'YES'\n puts sol.map{|x| x.map(&:to_s).join(' ')}\nelse\n puts 'NO'\nend\n\n"}], "negative_code": [], "src_uid": "fdfc1e690eeee6f50e2a024bf3f841e8"} {"source_code": "gets.to_i.times do\n n=gets.to_i\n puts ((1..n).to_a.map.with_index {|i,j| (n%2==1 && i==1) ? 1 : ((n-j)%2==0 ? i+1 : i-1)})*' '\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n puts n.downto(1).each_slice(2).to_a.reverse.join(' ')\r\nend"}, {"source_code": "gets.to_i.times { \n\tn = gets.to_i\n\ta = n.odd? ? 1 : 0\n\tif n.odd? ; print '1 '; end\n\t(n/2).times{|i| print i*2+2+a, ' ', i*2+1+a, ' '} ; puts ''\n}"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n if n % 2 == 0\r\n puts 1.upto(n).map { |i| i + (i % 2 == 0 ? -1 : 1) }.join(\" \")\r\n else\r\n puts ([1] + (2.upto(n).map { |i| i + (i % 2 == 0 ? 1 : -1) })).join(\" \")\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times { \n\tn = gets.to_i\n\tif n.even? \n\t\tn.times{|i| print n-i, ' '}; puts ''\n\telse\n\t\t(n/2).times{|i| print n-i*2-1 , ' ', n-i*2, ' '}; puts 1\n\tend\n}"}, {"source_code": "gets.to_i.times { gets.to_i.times{|i| print i+1, ' '}; puts ''}"}, {"source_code": "gets.to_i.times do\n n=gets.to_i\n puts ((2..n).to_a+[1])*' '\nend\n"}, {"source_code": "gets.to_i.times do\n n=gets.to_i\n puts ([n]+(1...n).to_a)*' '\nend\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n n.downto(1).each_slice(2).to_a.reverse.join(' ')\r\nend"}], "src_uid": "be3295b4d43a11ee94022b103f4221a5"} {"source_code": "gets\na = gets.split.map(&:to_i).uniq.sort\n\nputs (a.size <= 2 || (a.size == 3 && a[1]-a[0] == a[2]-a[1])) ? 'YES' : 'NO'", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nau = a.uniq\ngoal = au.size == 1 ? au[0] : au.sort[1]\na1 = a.find{|e| e != goal}\nx = a1 ? (goal - a1).abs : 0\nputs a.all?{|e| (goal - e).abs == 0 || (goal - e).abs == x} ? 'YES' : 'NO'\n"}, {"source_code": "n=readline.to_i\na=readline.split.map(&:to_i).uniq.sort\n\nif a.size <= 2 || (a.size == 3 && a[1]-a[0] == a[2]-a[1])\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split(' ').map(&:to_i)\n\nmin = arr.min\nmax = arr.max\n\nalpha = ((max - min) / 2.0)\n\nans = 'YES'\n\ncorrectNum = (min + alpha)\n#puts correctNum\narr.each do |i|\n\tif i != correctNum && i + alpha != correctNum && i - alpha != correctNum\n\t\tans = 'NO'\n\t\tbreak\n\tend\nend\n\nputs ans"}, {"source_code": "gets\na = gets.split(\" \").map(&:to_i)\n\nmax = a.max\nmin = a.min\nmid = (max+min)/2.0\n\nputs a.all?{|x| x==max || x==min || x==mid} ? \"YES\" : \"NO\"\n"}, {"source_code": "gets\na=gets.split.map(&:to_i).group_by{|e|e}.map(&:first).sort\nputs a.size<=2 || (a.size==3&&a[2]-a[1]==a[1]-a[0]) ? :YES : :NO"}, {"source_code": "n =gets.to_i ; list = gets.chomp.split(\" \").map(&:to_i).uniq.sort\nputs (list.length <= 2 || (list.length <=3 && (2*list[1] == list[0] + list[2])))? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\n\na = arr[0]\narr.delete(a)\nif arr.length > 0\n b = arr[0]\n arr.delete(b)\n if arr.length > 0\n c = arr[0]\n arr.delete(c)\n if arr.length > 0\n puts \"NO\"\n else\n lol = [a,b,c]\n x = lol.min\n z = lol.max\n lol.delete(x)\n lol.delete(z)\n if lol[0] * 2 == (x + z)\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\n else\n puts \"YES\"\n end\nelse\n puts \"YES\"\nend"}, {"source_code": "n,*a=$<.read.split.map &:to_i\na.sort!.uniq!\nn=a.size\nx=a[-1]-a[0]\nif n>3 or (n==3 and (x%2==1 or a[1]!=a[0]+x/2))\n puts :NO\nelse\n puts :YES\nend\n"}, {"source_code": "n = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nk = (a.max-a.min)/2\nif a.uniq.count<3 || (a.uniq.count==3&&a.include?(k+a.min)&&a.include?(a.max-k)) then s=\"YES\" else s=\"NO\" end\nputs s\n"}, {"source_code": "n = gets\nx = gets.split.map(&:to_i).sort.uniq\nif (x.size <= 2) or (x.size == 3 and x[0]+x[2]==x[1]*2)\n puts \"YES\"\nelse\n puts\"NO\"\nend\n"}], "negative_code": [{"source_code": "gets\na=gets.split.map(&:to_i).group_by{|e|e}.map(&:first).sort\nputs (a.size==3&&a[2]-a[1]==a[1]-a[0]) || a.size==2 ? :YES : :NO"}, {"source_code": "gets\na=gets.split.map(&:to_i).group_by{|e|e}.map(&:first).sort\nputs (a.size==3&&a[2]-a[1]==a[1]-a[0]) || (a.size==2&&(a[1]-a[0])%2==0) ? :YES : :NO"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\n\na = arr[0]\narr.delete(a)\nif arr.length > 0\n b = arr[0]\n arr.delete(b)\n if arr.length > 0\n c = arr[0]\n arr.delete(c)\n if arr.length > 0\n puts \"NO\"\n else\n lol = [a,b,c]\n x = lol.min\n z = lol.max\n lol.delete(x)\n lol.delete(z)\n if lol[0] * 2 == (x + z)\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\n else\n puts \"NO\"\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "n = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nif a.uniq.count==3&&a.include?(((a.max-a.min)/2).to_i+a.min) then s=\"YES\" else s=\"NO\" end\nputs s\n"}, {"source_code": "n = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nif a.uniq.count<3 || (a.uniq.count==3&&a.include?(((a.max-a.min)/2)+a.min)) then s=\"YES\" else s=\"NO\" end\nputs s\n"}, {"source_code": "n = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nif a.uniq.count==3&&a.include?(((a.max-a.min)/2)+a.min) then s=\"YES\" else s=\"NO\" end\nputs s\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nsum = a.inject(&:+)\nif sum % n == 0\n goal = sum / n\n a1 = a.find{|e| e != goal}\n if a1\n x = (goal - a1).abs\n puts a.all?{|e| (goal - e).abs == 0 || (goal - e).abs == x} ? 'YES' : 'NO'\n else\n puts 'YES'\n end\nelse\n puts 'NO'\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nsum = a.inject(&:+)\nif sum % n == 0\n goal = sum / n\n a1 = a.find{|e| e != goal}\n if a1\n x = (goal - a1).abs\n pos = a.count{|e| e - x == goal}\n neg = a.count{|e| e + x == goal}\n eq = a.count{|e| e == goal}\n puts pos == neg && pos + neg + eq == n ? 'YES' : 'NO'\n else\n puts 'YES'\n end\nelse\n puts 'NO'\nend\n"}, {"source_code": "n=readline.to_i\na=readline.split.map(&:to_i).uniq.sort\n\nif a.size == 1 || (a.size == 3 && a[1]-a[0] == a[2]-a[1])\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split(' ').map(&:to_i)\n\nmin = arr.min\nmax = arr.max\n\nalpha = (max - min) / 2\n\nans = 'YES'\n\ncorrectNum = min + alpha\n#puts correctNum\narr.each do |i|\n\tif i != correctNum && i + alpha != correctNum && i - alpha != correctNum\n\t\tans = 'NO'\n\t\tbreak\n\tend\nend\n\nputs ans"}], "src_uid": "27f837609b2777cefccb13aa4596d91c"} {"source_code": "t = gets.to_i\r\nt.times{\r\n x = gets.to_i\r\n (x..x+100).each{|x|if x.gcd(x.digits.sum)>1 then p x;break end}\r\n}", "positive_code": [{"source_code": "def gs(n)\r\n s=n.to_s.chars.map(&:to_i).sum\r\n return n.gcd(s)\r\nend\r\ngets.to_i.times do\r\n n=gets.to_i\r\n i=n\r\n while\r\n g=gs(i)\r\n if g>1\r\n puts i\r\n break\r\n end\r\n i+=1\r\n end\r\nend\r\n"}, {"source_code": "def digitSum(num)\n s = 0\n while num > 0\n s += num % 10\n num = num / 10\n end\n s\nend\n\ngets.to_i.times {\n n = gets.to_i\n\n while true\n s = digitSum n\n o = n.gcd s\n if o > 1\n puts n\n break\n end\n n += 1\n end\n}\n"}, {"source_code": "def digitSum(num)\n s = 0\n while num > 0\n s += num % 10\n num = num / 10\n end\n s\nend\n\ndef gcd1 (a, b)\n if b == 0\n return a\n end\n gcd1(b, a % b)\nend\n\nt = gets.to_i\n(1..t).each { |i|\n n = gets.to_i\n\n while true\n s = digitSum n\n o = gcd1(n, s)\n if o > 1\n puts n\n break\n end\n n += 1\n end\n}\n"}], "negative_code": [], "src_uid": "204e75827b7016eb1f1fbe1d6b60b03d"} {"source_code": "gets.to_i.times do\r\n n,m=gets.split.map(&:to_i)\r\n a=gets.split.map(&:to_i)\r\n b=gets.split.map(&:to_i)\r\n a1=[]\r\n a2=[]\r\n n.times do |i|\r\n if b[i]==1\r\n a1 << a[i]\r\n else\r\n a2 << a[i]\r\n end\r\n end\r\n a1.sort!.reverse!\r\n a2.sort!.reverse!\r\n z1=a1.size\r\n z2=a2.size\r\n i=0\r\n k=0\r\n while i=0\r\n k-=a1[i]\r\n i-=1\r\n while k=m&&(i+1)+j*2= m - s2 }\n\t\t\tcnt1 ? cnt2 * 2 + cnt1 : INF\n\t\tend.min\n\n\tputs ans < INF ? ans : -1\nend\n"}, {"source_code": "#!/usr/bin/env ruby\r\n\r\ndef getar\r\n return gets.chomp.split.map(&:to_i)\r\nend \r\n\r\ndef pfr(ar)\r\n res = (0..ar.length).map{|x| 0}\r\n for i in (1..ar.length)\r\n res[i] = res[i-1] + ar[i-1];\r\n end\r\n return res\r\nend\r\n\r\nclass Opt\r\n\r\n def initialize(mem, cost, units)\r\n ar = mem.zip(cost)\r\n @one = pfr(ar.select{|x, y| (y == 1)}.map{|x, y| x}.sort.reverse)\r\n @two = pfr(ar.select{|x, y| (y == 2)}.map{|x, y| x}.sort.reverse)\r\n @units = units\r\n end\r\n\r\n def bsearch(val)\r\n # find ind of two where two[i] >= val\r\n if @two[@two.length-1] < val\r\n return nil\r\n end\r\n l,r = [0, @two.length-1]\r\n while true\r\n if r-l <= 1\r\n return(@two[l] >= val ? l : r)\r\n end\r\n mid = (l+r).div(2)\r\n if @two[mid] >= val\r\n r = mid\r\n else\r\n l = mid\r\n end\r\n end\r\n end\r\n\r\n def cost(ones)\r\n if ones >= @one.length\r\n return nil\r\n end\r\n ind = self.bsearch(@units - @one[ones])\r\n return (ind ? (ones + 2*ind) : nil)\r\n end\r\n\r\n def ones\r\n @one.length\r\n end\r\n\r\nend\r\n\r\ntc = getar()[0]\r\n\r\nfor t in 1..tc\r\n n, m = getar\r\n mem = getar\r\n cost = getar\r\n \r\n opt = Opt.new(mem, cost, m)\r\n possible = (0..opt.ones).map{|x| opt.cost(x)}.select{|x| x}.min\r\n puts \"#{possible ? possible : -1}\"\r\nend\r\n"}], "negative_code": [{"source_code": "INF = 10**18\n\ngets.to_i.times do |testcase|\n\tn, m = gets.split.map(&:to_i)\n\ta = gets.split.map(&:to_i)\n\tb = gets.split.map(&:to_i)\n\n\ta1 = (0...m).select { b[_1] == 1 }.map { a[_1] }.sort.reverse\n\ta2 = (0...m).select { b[_1] == 2 }.map { a[_1] }.sort.reverse\n\n\tsum1 = [0] * -~a1.size\n\ta1.size.times { |i| sum1[i + 1] = sum1[i] + a1[i] }\n\tsum2 = [0] * -~a2.size\n\ta2.size.times { |i| sum2[i + 1] = sum2[i] + a2[i] }\n\n\tans2 =\n\t\tsum2.each_with_index.map do |s2, cnt2|\n\t\t\tcnt1 = sum1.bsearch_index { _1 >= m - s2 }\n\t\t\tcnt1 ? cnt2 * 2 + cnt1 : INF\n\t\tend.min\n\tans1 =\n\t\tsum1.each_with_index.map do |s1, cnt1|\n\t\t\tcnt2 = sum2.bsearch_index { _1 >= m - s1 }\n\t\t\tcnt2 ? cnt2 * 2 + cnt1 : INF\n\t\tend.min\n\tans = [ans1, ans2].min\n\n\tputs ans < INF ? ans : -1\nend\n"}, {"source_code": "INF = 10**18\n\ngets.to_i.times do\n\tn, m = gets.split.map(&:to_i)\n\ta = gets.split.map(&:to_i)\n\tb = gets.split.map(&:to_i)\n\n\ta1 = (0...m).select { b[_1] == 1 }.map { a[_1] }.sort.reverse\n\ta2 = (0...m).select { b[_1] == 2 }.map { a[_1] }.sort.reverse\n\n\tsum1 = [0] * -~a1.size\n\ta1.size.times { |i| sum1[i + 1] = sum1[i] + a1[i] }\n\tsum2 = [0] * -~a2.size\n\ta2.size.times { |i| sum2[i + 1] = sum2[i] + a2[i] }\n\n\tans =\n\t\tsum2.each_with_index.map do |s2, cnt2|\n\t\t\tcnt1 = sum1.bsearch_index { _1 >= m - s2 }\n\t\t\tcnt1 ? cnt2 * 2 + cnt1 : INF\n\t\tend.min\n\tputs ans < INF ? ans : -1\nend\n"}], "src_uid": "e1fa7250c7004c093e1af788f23b2863"} {"source_code": "def r;gets.split.map(&:to_i)end;n,m,k,t=r;d=[];k.times{p=r;d<<(p[0]-1)*m+p[1]};t.times{b=r;b=(b[0]-1)*m+b[1];puts(d.include?(b)?:Waste:[:Carrots,:Kiwis,:Grapes][(b-d.count{|v|v0 then\n puts \"Waste\"\n elsif\n puts [\"Carrots\",\"Kiwis\",\"Grapes\"][no%3]\n end\n}"}, {"source_code": "def r;gets.split.map(&:to_i)end;n,m,k,t=r;d=[];k.times{p=r;d<<(p[0]-1)*m+p[1]};t.times{b=r;b=(b[0]-1)*m+b[1];puts(d.include?(b)?:Waste:[:Carrots,:Kiwis,:Grapes][(b-d.count{|v|v a[x1]\n\n while x1 - x0 > 1\n x2 = (x0+x1)/2\n return nil if a[x2] == v\n if v > a[x2]\n x0 = x2\n else\n x1 = x2\n end\n end\n\n x1\nend\n\nn, m, k, t = gets.split.map(&:to_i)\n\na = []\nk.times do\n i, j = gets.split.map(&:to_i)\n a << (i-1)*m+(j-1)\nend\na.uniq!\na.sort!\n\nt.times do\n i, j = gets.split.map(&:to_i)\n pos = (i-1)*m+(j-1)\n\n v = b_search(a, pos)\n if v\n puts %w(Carrots Kiwis Grapes)[(pos-v)%3]\n else\n puts \"Waste\"\n end\nend\n"}, {"source_code": "n, m, k, t = gets.split.map(&:to_i)\nA = Hash.new(0)\nk.times do \n a, b = gets.split.map { |x| x.to_i - 1}\n A[a * m + b] = 1\nend\nM = Array.new\n(A.keys.sort).each do |key|\n M << key\nend\nt.times do \n a, b = gets.split.map { |x| x.to_i - 1}\n key = a * m + b\n if A.has_key? key\n puts \"Waste\"\n else\n u = key - (M.select { |x| x < key }).size\n x = u % 3\n if x == 0\n puts \"Carrots\"\n elsif x == 1\n puts \"Kiwis\"\n elsif x == 2\n puts \"Grapes\"\n end\n end\nend\n"}, {"source_code": "def r;gets.split.map(&:to_i)end;n,m,k,t=r;d=[];k.times{p=r;d<<(p[0]-1)*m+p[1]};t.times{b=r;b=(b[0]-1)*m+b[1];puts(d.include?(b)?:Waste:[:Carrots,:Kiwis,:Grapes][(b-d.count{|v|v a[l]\n return a[l]\n end\n end\n \n if l - h == 1\n l, h = h, l\n end\n \n if h - l == 1\n if b < a[l]\n return 0\n elsif b >= a[l] && b < a[h]\n return l + 1\n else\n return h + 1\n end\n elsif b > a[mid]\n return search(a, mid+1, h, b)\n elsif b < a[mid]\n return search(a, l, mid-1, b)\n else\n return 0\n end\nend\nt.times do \n a, b = gets.split.map { |x| x.to_i - 1}\n key = a * m + b\n if A.has_key? key\n puts \"Waste\"\n else\n# puts \"Key #{key}\"\n# bb = search(M, 0, M.size - 1, key)\n# puts \"Key = #{key} -> #{bb}\"\n u = key - search(M, 0, M.size - 1, key)\n x = u % 3\n if x == 0\n puts \"Carrots\"\n elsif x == 1\n puts \"Kiwis\"\n elsif x == 2\n puts \"Grapes\"\n end\n end\nend\n"}, {"source_code": "n, m, k, t = gets.split.map(&:to_i)\nA = Hash.new(0)\nk.times do \n a, b = gets.split.map { |x| x.to_i - 1}\n A[a * m + b] = 1\nend\n#p A\nM = Array.new\n(A.keys.sort).each do |key|\n M << key\nend\n#p M\ndef search(a, l, h, b)\n #puts \"Search l#{l} h#{h} b#{b}\"\n mid = l + ((h - l) / 2).to_i\n \n if l > h\n \n \n if l >= a.size\n if b < a.last\n return a.size - 1\n else\n return a.size\n end\n end\n \n \n if b < a[l]\n return l\n elsif b > a[l]\n return l + 1\n end\n end\n \n if h - l == 1\n if b < a[l]\n return 0\n elsif b >= a[l] && b < a[h]\n return l + 1\n else\n return h + 1\n end\n elsif b > a[mid]\n return search(a, mid+1, h, b)\n elsif b < a[mid]\n return search(a, l, mid-1, b)\n else\n return 0\n end\nend\nt.times do \n a, b = gets.split.map { |x| x.to_i - 1}\n key = a * m + b\n if A.has_key? key\n puts \"Waste\"\n else\n# puts \"Key #{key}\"\n# bb = search(M, 0, M.size - 1, key)\n# puts \"Key = #{key} -> #{bb}\"\n u = key - search(M, 0, M.size - 1, key)\n x = u % 3\n if x == 0\n puts \"Carrots\"\n elsif x == 1\n puts \"Kiwis\"\n elsif x == 2\n puts \"Grapes\"\n end\n end\nend\n"}], "src_uid": "bfef3f835357dae290620efabe650580"} {"source_code": "n,k,*b=gets(p).split.map(&:to_i)\na=[]\n(0...n).reverse_each {|i|\n x=0\n while xi+k\n x+=1\n end\n a.insert x,i+1\n}\nputs a*\" \"", "positive_code": [{"source_code": "n,k,*b=gets(p).split.map(&:to_i)\na=[]\nb.each_with_index.reverse_each{|c,i|\n\tj=a.size\n\ta.each_with_index{|d,l|\n\t\tif c<1\n\t\t\tj=l\n\t\t\tbreak\n\t\tend\n\t\tc-=1 if d>i+k \n\t}\n\ta.insert j,i+1\n}\nputs a*\" \"\n"}, {"source_code": "n,k,*b=gets(p).split.map(&:to_i)\na=[]\nb.each_with_index.reverse_each{|c,i|\n\tj=a.size\n\ta.each_with_index{|d,l|\n\t\tif c<1\n\t\t\tj=l\n\t\t\tbreak\n\t\tend\n\t\tc-=1 if d>i+k \n\t}\n\ta.insert j,i+1\n}\nputs a*\" \"\n"}, {"source_code": "n,k,*b=gets(p).split.map(&:to_i)\na=[]\nb.each_with_index.reverse_each{|c,i|\n\tj=a.size\n\ta.each_with_index{|d,l|\n\t\tif c<1\n\t\t\tj=l\n\t\t\tbreak\n\t\tend\n\t\tc-=1 if d>i+k \n\t}\n\ta.insert j,i+1\n}\nputs a*\" \""}, {"source_code": "n,k,*b=gets(p).split.map(&:to_i)\na=[]\nb.each_with_index.reverse_each{|c,i|\n\tj=a.size\n\ta.each_with_index{|d,l|\n\t\tif c<1\n\t\t\tj=l\n\t\t\tbreak\n\t\tend\n\t\tc-=1 if d>i+k \n\t}\n\ta.insert j,i+1\n}\nputs a*\" \"\n"}, {"source_code": "n,k,*b=gets(p).split.map(&:to_i)\na=[]\nb.each_with_index.reverse_each{|c,i|\n\tj=a.size\n\ta.each_with_index{|d,l|\n\t\tif c<1\n\t\t\tj=l\n\t\t\tbreak\n\t\tend\n\t\tc-=1 if d>i+k \n\t}\n\ta.insert j,i+1\n}\nputs a*\" \"\n"}, {"source_code": "n, k, *b = gets(p).split.map(&:to_i)\na = []\n(0...n).reverse_each { |i|\n x = 0\n while x < a.size\n break if b[i] < 1\n b[i] -= 1 if a[x] > i + k\n x += 1\n end\n a.insert x, i + 1\n}\nputs a * \" \""}, {"source_code": "n, k, *b = gets(p).split.map(&:to_i)\na = []\nfor i in (n - 1).downto(0)\n x = a.size\n for j in 0...x\n if b[i] < 1\n x = j\n break\n end\n b[i] -= 1 if a[j] > i + k\n end\n a.insert x, i + 1\nend\nputs a * \" \""}, {"source_code": "n,k,*b=gets(p).split.map(&:to_i)\na=[]\nb.each_with_index.reverse_each{|c,i|\n j=a.size\n a.each_with_index{|d,l|\n if c<1\n j=l\n break\n end\n c-=1 if d>i+k \n }\n a.insert j,i+1\n}\nputs a*\" \""}, {"source_code": "n,k,*b=gets(p).split.map(&:to_i)\na=[]\nb.each_with_index.reverse_each{|c,i|\n\tj=a.size\n\ta.each_with_index{|d,l|\n\t\tif c<1\n\t\t\tj=l\n\t\t\tbreak\n\t\tend\n\t\tc-=1 if d>i+k \n\t}\n\ta.insert j,i+1\n}\nputs a*\" \"\n"}, {"source_code": "def generate(a, k)\n 1.upto(a.size).map do |i|\n pos = a.index(i)\n (0..pos-1).count{|j| a[j] >= i+k}\n end\nend\n\ndef ok?(a, b, k)\n generate(a, k) == b\nend\n\ndef hoge\n n = 1000\n k = 5\n b = generate((1..n).to_a.shuffle, k)\n puts [n, k]*\" \"\n puts b*\" \"\n exit\nend\n\ndef solve(n, k, b)\n o = ((n-k+1)..n).to_a\n (n-k).downto(1) do |i|\n c = 0\n j = 0\n while c < b[i-1]\n c += 1 if o[j] >= i+k\n j += 1\n end \n o[j,0] = i\n end\n o\nend\n\ndef test\n n = 9\n k = 4\n h = {}\n (1..n).to_a.permutation do |a|\n b = generate(a, k)\n unless h[b]\n a2 = solve(n, k, b)\n p [a, b, a2] unless a == a2\n h[b] = true\n end\n end\n\n exit\nend\n\n#test\n\nn, k = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\no = solve(n, k, b)\nputs o*\" \"\n\n\n"}, {"source_code": "n,k,*b=gets(p).split.map(&:to_i)\na=[]\nb.each_with_index.reverse_each{|c,i|\n\tj=a.size\n\ta.each_with_index{|d,l|\n\t\tif c<1\n\t\t\tj=l\n\t\t\tbreak\n\t\tend\n\t\tc-=1 if d>i+k \n\t}\n\ta.insert j,i+1\n}\nputs a*\" \"\n"}, {"source_code": "n,k,*b=gets(p).split.map(&:to_i)\na=[]\nb.each_with_index.reverse_each{|c,i|\n\tj=a.size\n\ta.each_with_index{|d,l|\n\t\tif c<1\n\t\t\tj=l\n\t\t\tbreak\n\t\tend\n\t\tc-=1 if d>i+k \n\t}\n\ta.insert j,i+1\n}\nputs a*\" \""}, {"source_code": "n,k,*b=gets(p).split.map(&:to_i)\na=[]\nb.each_with_index.reverse_each{|c,i|\n\tj=a.size\n\ta.each_with_index{|d,l|\n\t\tif c<1\n\t\t\tj=l\n\t\t\tbreak\n\t\tend\n\t\tc-=1 if d>i+k \n\t}\n\ta.insert j,i+1\n}\nputs a*\" \"\n"}], "negative_code": [], "src_uid": "3c73d33682dc4548646fd240b6e22471"} {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |el|\n ev << el if el.even?\n od << el if el.odd?\n }\n od = od.sort\n ev = ev.sort\n flg = false\n od.each { |el|\n ev.each { |el2|\n if (el - el2).abs == 1\n flg = true\n break\n end\n }\n }\n if od.size.even? && ev.size.even?\n puts \"YES\"\n elsif flg == true\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n", "positive_code": [{"source_code": "gets.to_i.times {\n gets\n a, b=gets.split.map(&:to_i).partition(&:odd?)\n puts ((a.size.even? or a.any?{|x| b.index{|y| (y-x).abs==1}}) ? :YES : :NO)\n}\n"}, {"source_code": "gets.to_i.times {\n gets\n a, b=gets.split.map(&:to_i).partition(&:odd?)\n if a.size.even?\n puts :YES\n else\n puts (a.any?{|x| b.index{|y| (y-x).abs==1}} ? :YES : :NO)\n end\n}\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n\n arr.each { |el|\n ev << el if el.even?\n od << el if el.odd?\n }\n\n od = od.sort\n ev = ev.sort\n\n flg = false\n od.each { |el|\n ev.each { |el2|\n if (el - el2).abs == 1\n flg = true\n break\n end\n }\n }\n\n if od.size.even? && ev.size.even?\n puts \"YES\"\n elsif flg == true\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "gets.to_i.times {\n gets\n a, b=gets.split.map(&:to_i).partition(&:odd?)\n puts ((a.size.even? or a.any?{|x| b.index{|y| (y-x).abs==1}}) ? :YES : :NO)\n}"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |el|\n ev << el if el.even?\n od << el if el.odd?\n }\n flg = false\n od.each { |el|\n ev.each { |el2|\n if (el - el2).abs == 1\n flg = true\n break\n end\n }\n }\n if od.size.even? && ev.size.even?\n puts \"YES\"\n elsif flg == true\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i).sort\n even = []\n odd = []\n for i in 0...n do\n if a[i] % 2 == 0\n even.push(a[i])\n else\n odd.push(a[i])\n end\n end\n ok = false\n if odd.length % 2 == 1\n odd.each do |v|\n if even.include?(v - 1) || even.include?(v + 1)\n ok = true\n break\n end\n end\n else\n ok = true\n end\n puts ok ? \"YES\" : \"NO\"\nend\n"}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i).sort\n\todd = a.count { _1 % 2 == 1 }\n\tif odd.odd?\n\t\tputs a.each_cons(2).any? { _2 - _1 == 1 } ? 'YES' : 'NO'\n\telse\n\t\tputs 'YES'\n\tend\nend\n"}, {"source_code": "gets.strip.to_i.times do |t|\n _ = gets.strip.to_i\n a = gets.strip.split(' ').map(&:to_i).sort\n # puts a.group_by { |e| e % 2 }.inspect\n diffs = 0\n a.each_with_index do |e, i|\n next if i.zero?\n diffs += 1 if a[i] - a[i-1] == 1\n end\n even = a.select { |e| e.even? }.size\n odd = a.select { |e| e.odd? }.size\n if even == a.size or odd == a.size\n puts \"YES\"\n elsif even.even? && odd.even?\n puts \"YES\"\n elsif diffs > 0\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n"}, {"source_code": "gets.to_i.times {\n gets\n a, b=gets.split.map(&:to_i).partition(&:odd?)\n puts ((a.size.even? or a.any?{|x| b.index{|y| (y-x).abs==1}}) ? :YES : :NO)\n}"}], "negative_code": [{"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = 0\n ev = 0\n mn_ev = 101\n mn_od = 101\n arr.each { |el|\n od += 1 if el.even?\n ev += 1 if el.odd?\n mn_ev = [mn_ev, el].min if el.even?\n mn_od = [mn_od, el].min if el.odd?\n }\n\n if od.even? && ev.even?\n puts \"YES\"\n elsif (mn_ev - mn_od).abs == 1\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |vl|\n ev << vl if vl.even?\n od << vl if vl.odd?\n }\n od = od.sort\n ev = ev.sort.reverse\n done = 0\n od.each { |vl|\n if !ev.empty?\n if (ev.last - vl).abs == 1\n ev.pop\n done += 1\n done = od.size if done > od.size\n end\n end\n }\n if ev.size.even? && (od.size - done).even?\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n\n arr.each { |el|\n ev << el if el.even?\n od << el if el.odd?\n }\n\n od = od.sort\n ev = ev.sort\n\n flg = false\n od.each_with_index { |el, idx|\n if !ev[idx].nil?\n if (el - ev[idx]).abs == 1\n flg = true\n break\n end\n end\n }\n\n if od.size.even? && ev.size.even?\n puts \"YES\"\n elsif flg == true\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |vl|\n ev << vl if vl.even?\n od << vl if vl.odd?\n }\n od = od.sort\n ev = ev.sort.reverse\n done = 0\n od.each { |vl|\n if (od.size - done).even? and ev.size.even?\n puts \"YES\"\n return nil\n end\n if !ev.empty?\n if (ev.last - vl).abs == 1\n ev.pop\n done += 1\n done = od.size if done > od.size\n end\n end\n }\n puts \"NO\"\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |vl|\n ev << vl if vl.even?\n od << vl if vl.odd?\n }\n od = od.sort\n ev = ev.sort.reverse\n od.each { |vl|\n if !ev.empty?\n if (ev.last - vl).abs != 1\n puts \"NO\"\n return nil\n end\n ev.pop\n end\n }\n puts \"YES\"\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |vl|\n ev << vl if vl.even?\n od << vl if vl.odd?\n }\n od = od.sort\n ev = ev.sort.reverse\n od.each { |vl|\n if !ev.empty?\n if (ev.last - vl).abs == 1\n ev.pop\n end\n end\n }\n puts \"YES\" if ev.size.even? && od.size.even?\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |vl|\n ev << vl if vl.even?\n od << vl if vl.odd?\n }\n if od.size.even? && ev.size.even?\n puts \"YES\"\n return nil\n end\n od = od.sort\n ev = ev.sort.reverse\n done = 0\n od.each { |vl|\n if !ev.empty?\n if (ev.last - vl).abs == 1\n ev.pop\n done += 1\n done = od.size if done > od.size\n end\n end\n }\n if ev.size.even? && (od.size - done).even?\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = 0\n ev = 0\n mn_ev = 101\n mn_od = 101\n arr.each { |el|\n od += 1 if el.even?\n ev += 1 if el.odd?\n mn_ev = [mn_ev, el].min if el.even?\n mn_od = [mn_od, el].min if el.odd?\n }\n if od.size.even? && ev.size.even?\n puts \"YES\"\n elsif (mn_ev - mn_od).abs == 1\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |vl|\n ev << vl if vl.even?\n od << vl if vl.odd?\n }\n od = od.sort\n ev = ev.sort.reverse\n done = 0\n od.each { |vl|\n if (od.size - done).even? && ev.size.even?\n puts \"YES\"\n return nil\n end\n if !ev.empty?\n if (ev.last - vl).abs == 1\n ev.pop\n done += 1\n done = od.size if done > od.size\n end\n end\n }\n puts \"NO\"\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n p arr\n od = 0\n ev = 0\n arr.each { |vl|\n ev += 1 if vl.even?\n od += 1 if vl.odd?\n }\n if ev >= od && (ev - od).even?\n puts \"YES\"\n else\n puts \"NO\"\n end\n\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |vl|\n ev << vl if vl.even?\n od << vl if vl.odd?\n }\n if od.size > ev.size\n puts \"NO\"\n #return nil\n end\n od = od.sort\n ev = ev.sort.reverse\n od.each { |vl|\n if !ev.empty?\n if (ev.last - vl).abs != 1\n puts \"NO\"\n return nil\n end\n end\n }\n puts \"YES\"\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = 0\n ev = 0\n arr.each { |vl|\n ev += 1 if vl.even?\n od += 1 if vl.odd?\n }\n if ev >= od && (ev - od).even?\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |vl|\n ev << vl if vl.even?\n od << vl if vl.odd?\n }\n if od.size > ev.size\n puts \"NO\"\n return nil\n end\n od = od.sort\n ev = ev.sort.reverse\n od.each { |vl|\n if !ev.empty?\n if (ev.last - vl).abs != 1\n puts \"NO\"\n return nil\n end\n end\n }\n puts \"YES\"\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i).sort\n skip = false\n even = 0\n for i in 0...n do\n if !skip\n if i < n - 1 && a[i + 1] - a[i] == 1\n skip = true\n else\n even += 1 if a[i] % 2 == 0\n end\n else\n skip = false\n end\n end\n puts (even % 2 == 0) ? \"YES\" : \"NO\"\nend\n"}, {"source_code": "gets.strip.to_i.times do |t|\n _ = gets.strip.to_i\n a = gets.strip.split(' ').map(&:to_i).sort\n # puts a.group_by { |e| e % 2 }.inspect\n diffs = 0\n a.each_with_index do |e, i|\n next if i.zero?\n diffs += 1 if a[i] - a[i-1] == 1\n end\n even = a.select { |e| e.even? }.size\n odd = a.select { |e| e.odd? }.size\n if even == a.size or odd == a.size\n puts \"YES\"\n elsif even == odd && even.even?\n puts \"YES\"\n elsif diffs > 0\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n"}, {"source_code": "gets.to_i.times {\n gets\n a, b=gets.split.map(&:to_i).partition(&:odd?)\n puts (a.size.even? or a.any?{|x| b.index{|y| (y-x).abs==1}} ? :YES : :NO)\n}\n"}, {"source_code": "gets.to_i.times {\n gets\n puts (gets.split.map(&:to_i).sort.each_slice(2).all?{|x,y|y-x==1 or (x+y)%2==0} ? :YES : :NO)\n}\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |vl|\n ev << vl if vl.even?\n od << vl if vl.odd?\n }\n od = od.sort\n ev = ev.sort.reverse\n done = 0\n od.each { |vl|\n if !ev.empty?\n if (ev.last - vl).abs == 1\n ev.pop\n done += 1\n end\n end\n }\n if ev.size.even? && (od.size - done).even?\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |vl|\n ev << vl if vl.even?\n od << vl if vl.odd?\n }\n od = od.sort\n ev = ev.sort.reverse\n done = 0\n od.each { |vl|\n if (od.size - done).even? && ev.size.even?\n puts \"YES\"\n return nil\n end\n if !ev.empty?\n if (ev.last - vl).abs == 1\n ev.pop\n done += 1\n done = od.size if done > od.size\n end\n end\n }\n if (od.size - done).even? && ev.size.even?\n puts \"YES\"\n return nil\n end\n puts \"NO\"\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i);\n od = []\n ev = []\n arr.each { |vl|\n ev << vl if vl.even?\n od << vl if vl.odd?\n }\n od = od.sort\n ev = ev.sort.reverse\n done = 0\n od.each { |vl|\n if (od.size - done).even? & ev.size.even?\n puts \"YES\"\n return nil\n end\n if !ev.empty?\n if (ev.last - vl).abs == 1\n ev.pop\n done += 1\n done = od.size if done > od.size\n end\n end\n }\n puts \"NO\"\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}], "src_uid": "005a29a4b4e7ee4fd21444846014727b"} {"source_code": "def lscan; gets.split.map(&:to_i); end\n\nh = [-1, 180, 90, 60, 45, 36, 30, 180, 45, 20, 18, 180, 15, 180, 90, 12, 45, 180, 10, 180, 9, 60, 90, 180, 15, 36, 90, 20, 45, 180, 6, 180, 45, 60, 90, 36, 5, 180, 90, 60, 9, 180, 30, 180, 45, 4, 90, 180, 15, 180, 18, 60, 45, 180, 10, 36, 45, 60, 90, 180, 3, 180, 90, 20, 45, 36, 30, 180, 45, 60, 18, 180, 5, 180, 90, 12, 45, 180, 30, 180, 9, 20, 90, 180, 15, 36, 90, 60, 45, 180, 4, 180, 45, 60, 90, 36, 15, 180, 90, 20, 9, 180, 30, 180, 45, 12, 90, 180, 5, 180, 18, 60, 45, 180, 30, 36, 45, 20, 90, 180, 6, 180, 90, 60, 45, 36, 10, 180, 45, 60, 18, 180, 15, 180, 90, 8, 45, 180, 30, 180, 9, 60, 90, 180, 10, 36, 90, 60, 45, 180, 12, 180, 45, 20, 90, 36, 15, 180, 90, 60, 18, 180, 20, 180, 45, 24, 90, 180, 30, 180, 36, 40, 45, 180, 60, 72, 90, 120, 180, 360, -1]\n\ngets.to_i.times do\n a = gets.to_i\n p h[a]\nend\n\n# h = {}\n# \n# 3.upto(1000) do |n|\n# t = 360.to_r/n/2\n# (n-2).times do |i_|\n# i = i_ + 1\n# a = t*i\n# next unless a.denominator == 1\n# h[a.to_i] = n unless h[a.to_i]\n# end\n# end\n# \n# p h.sort.map{|e|e[1]}\n", "positive_code": [{"source_code": "def done(a)\n for i in 3..1000\n if (a * i) % 180 == 0 and (a * i)/180 < i - 1\n return i\n end\n end \n return -1\nend\nfor _ in 1..gets.to_i\n a = gets.to_i\n puts done(a)\n end"}, {"source_code": "gets.to_i.times do\n a = gets.to_i\n b = (a*2).gcd(360)\n if 360-a*2 == b\n puts 720/b\n else\n puts 360/b\n end\nend"}], "negative_code": [{"source_code": "gets.to_i.times do\n a = gets.to_i\n if a < 90\n puts 360/(a*2).gcd(360)\n else\n puts 360/(180-a)\n end\nend"}], "src_uid": "d11b56fe172110d5dfafddf880e48f18"} {"source_code": "n = Integer(gets.chomp)\na = []\na = gets.chomp.split.map &:to_i\n\na = a.sort!\nx = 1\ny = 0\nz = 0\nstop = false\nfor i in 1...n\n if a[i] == a[0]\n x += 1\n else\n y += 1\n for j in i+1...n\n if a[j] == a[i]\n y += 1\n else\n z += 1\n for k in j+1...n\n if a[k] == a[j]\n z += 1\n else\n stop = true\n break\n end\n end\n end\n if stop || x + y + z == n\n break\n end\n end\n end\n if stop || x + y + z == n\n break\n end\nend\nquantity = 0\nif x >= 3\n quantity = x*(x-1)*(x-2)/6\nelsif x < 3 && x + y >= 3\n if x == 1\n quantity = y*(y-1)/2\n elsif x == 2\n quantity = y\n end\nelsif x + y < 3 && x + y + z >= 3\n if x + y == 1\n quantity = z*(z-1)*(z-2)\n elsif x + y == 2\n quantity = z\n end\nend\n\nputs quantity\n \n ", "positive_code": [{"source_code": "def ascan; gets.split.map(&:to_i); end\ndef scan; gets.to_i; end\n \n# combination nCr\ndef combi(n, r)\n q = 1\n 1.upto(r){|k|q=q*(n-k+1)/k}\n return q\nend\n\ngets\nha = ascan.inject({}){|h,e| h[e]||=0; h[e]+=1; h}.sort\n\nn = 0\na = []\nwhile n < 3\n v,c = ha.shift\n n += c\n a << c\nend\ns = n-a[-1]\np 3-s <= a[-1] ? combi(a[-1],3-s) : a[-1]"}], "negative_code": [{"source_code": "def ascan; gets.split.map(&:to_i); end\ndef scan; gets.to_i; end\n\ngets\nha = ascan.inject({}){|h,e| h[e]||=0; h[e]+=1; h}.sort\n\nn = 0\na = []\nwhile n < 3\n v,c = ha.shift\n n += c\n a << c\nend\n\np a[-1]"}, {"source_code": "def ascan; gets.split.map(&:to_i); end\ndef scan; gets.to_i; end\n \n# combination nCr\ndef combi(n, r)\n q = 1\n 1.upto(r){|k|q=q*(n-k+1)/k}\n return q\nend\n\ngets\nha = ascan.inject({}){|h,e| h[e]||=0; h[e]+=1; h}.sort\n\nn = 0\na = []\nwhile n < 3\n v,c = ha.shift\n n += c\n a << c\nend\n\np 3 <= a[-1] ? combi(a[-1],3) : a[-1]"}], "src_uid": "4c2d804bb2781abfb43558f8b2c6424f"} {"source_code": "a=gets.to_i.times.map{gets.chomp.chars}\nl=a[0].size\nb=a.map{|e|\n\tidx=(0...l).select{|i|e.rotate(i)==a[0]}\n\tif idx.empty?\n\t\tp -1\n\t\texit\n\tend\n\tidx\n}\np (0...l).map{|i|b.map{|e|e.map{|f|(f+i)%l}.min}.reduce(:+)}.min", "positive_code": [{"source_code": "n = gets.strip.to_i\ndata = Array.new(n) { gets.strip }\n\ninf = 10 ** 9\nans = data.map { |s|\n data.map do |ss|\n for i in (0..ss.length)\n break i if ss == s \n ss = ss[1..-1] + ss[0]\n break inf if i+1 == ss.length\n end\n end.reduce(:+)\n}.min\n\nputs (ans >= inf ? -1 : ans)\n"}, {"source_code": "def isEqualStr(word1, word2)\n\tnStr = word2.length\n\tfor i in 0 ... nStr\n\t\tisEqual = true\n\t\tj = 0\n\t\twhile j < nStr and isEqual\n\t\t\tisEqual &= word1[j] == word2[(i + j) % nStr]\n\t\t\tj += 1\n\t\tend\n\t\tif isEqual\n\t\t\treturn i\n\t\tend\n\tend\n\n\treturn -1\nend\n\nn = gets.chomp.to_i\ngrid = []\nfor i in 0 ... n\n\tgrid << gets.chomp\nend\n\nanswer = true\nfor i in 0 ... n - 1\n\tif isEqualStr(grid[i], grid[i + 1]) == -1\n\t\tanswer = false\n\tend\nend\n\nif not answer\n\tputs \"-1\"\nelse\n\tanswer = (1 << 31)\n\tfor i in 0 ... n\n\n\t\tauxAnswer = 0\n\t\tj = (i + 1) % n\n\t\twhile i != j\n\t\t\tauxAnswer += isEqualStr(grid[i], grid[j])\n\t\t\tj = (j + 1) % n\n\t\tend\n\t\tanswer = [answer, auxAnswer].min\n\tend\n\tputs answer\nend\n\n"}], "negative_code": [{"source_code": "a=gets.to_i.times.map{gets.chomp.chars}\nl=a[0].size\nb=a.map{|e|\n\tidx=(0...l).find{|i|e.rotate(i)==a[0]}\n\tif !idx\n\t\tp -1\n\t\texit\n\tend\n\tidx\n}\np (0...l).map{|i|b.map{|e|(e+i)%l}.reduce(:+)}.min"}], "src_uid": "a3a7515219ebb0154218ee3520e20d75"} {"source_code": "def ga\n\treturn gets.split.map &:to_i\nend\nn,k = ga\na = ga\np [a.min, [a[-1],a[0]].max,a.max][k>2?2:k-1]", "positive_code": [{"source_code": "class Solver2\n def self.solve(arr, k)\n return arr.min if k == 1\n return arr.max if k > 2\n return [arr.first, arr.last].max\n end\nend\nstring = ARGF.read\narr = string.split(\"\\n\")\narr.map! { |elem| elem.strip }\narr1 = arr[0].split\narr2 = arr[1].split\narr1.map! { |elem| elem.split }\narr2.map! { |elem| elem.to_i }\nputs Solver2.solve(arr2, arr1[1].first.to_i)\nexit(true)\n"}, {"source_code": "n, k = gets.split.map &:to_i\na = gets.split.map &:to_i\np [a.min, [a[0], a[-1]].max, a.max][[k, 3].min - 1]"}], "negative_code": [{"source_code": "def ga\n\treturn gets.split.map &:to_i\nend\nn,k = ga\na = ga\np [a.min, [a[-1],a[0]].max,a.max][k[0]>2?2:k[0]-1]"}], "src_uid": "ec1a29826209a0820e8183cccb2d2f01"} {"source_code": "n = gets.chomp.to_i\ncells = []\nn.times do\n cells << gets.chomp\nend\nans = 0\nfor i in 0...n\n r = 0\n c = 0\n for j in 0...n\n r += 1 if cells[i][j] == 'C'\n c += 1 if cells[j][i] == 'C'\n end\n ans += r * (r - 1) / 2\n ans += c * (c - 1) / 2\nend\n\nputs ans\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\ngets;a=$<.map{|e|e.chomp.chars}\nr=0\n[a,a.transpose].each{|b|b.each{|e|n=e.count('C');r+=n*(n-1)/2}}\np r\n"}, {"source_code": "#!/usr/bin/ruby\ngets;a=$<.map{|e|e.chomp.chars}\nr=0\n[a,a.transpose].each{|b|b.each{|e|n=e.count('C');r+=n*(n-1)/2}}\np r\n"}, {"source_code": "nn=gets.to_i\na = (1..nn).map{gets.strip}\n\ndef f(n)\n return 0 unless n\n return 0 if n < 2\n n == 2 ? 1 : (n-1)+f(n-1)\nend\n\n\ng1 = a.map{|x| n = x.gsub(/[^C]/, \"\").size; f(n)}\n#p a\na = (0...nn).map{|i| (0...nn).map{|j| a[j][i] }.join }\n#p a\ng2 = a.map{|x| n = x.gsub(/[^C]/, \"\").size; f(n)}\n#p g1, g2\ng = (g1+g2).reduce(:+)\np g\n"}, {"source_code": "#!/usr/bin/ruby\ngets;a=$<.map{|e|e.chomp.chars}\nr=0\n[a,a.transpose].each{|b|b.each{|e|n=e.count('C');r+=n*(n-1)/2}}\np r"}, {"source_code": "n = gets.chomp.to_i\nrows = []\nn.times { rows << gets.chomp.chars }\nc = 0\nrows.each { |row| c += (0..(row.count('C') - 1)).to_a.combination(2).to_a.length }\nrows.transpose.each { |row| c += (0..(row.count('C') - 1)).to_a.combination(2).to_a.length }\n\nputs c\n"}, {"source_code": "n = gets.to_i\ncake = []\nn.times do\n\tcake.push(gets.split(''))\nend\n\nt = 0\nfor i in 0...n\n\tchoc = 0\n\tfor j in 0...n\n\t\tchoc += 1 if cake[i][j] == 'C'\n\tend\n\tt += choc*(choc-1)/2\nend\n\nfor i in 0...n\n\tchoc = 0\n\tfor j in 0...n\n\t\tchoc += 1 if cake[j][i] == 'C'\n\tend\n\tt += choc*(choc-1)/2\nend\n\nputs t"}, {"source_code": "a=gets.chomp.to_i\nrow=[]\nclm=[]\na.times do \nclm <<0\nend\na.times do \ntemp=gets.chomp.split(\"\")\nt=0\n0.upto(a-1) do |i|\nif temp[i]==\"C\"\nt+=1\nclm[i]+=1\nend\nend\nrow << t\nend\nans=0\nrow.each do |i|\nif i>1\nans=ans+(i*(i-1))/2\nend\nend\n\nclm.each do |i|\nif i>1\nans=ans+(i*(i-1))/2\nend\nend\nputs \"#{ans}\"\n"}, {"source_code": "def combination_count(n, m)\n return 1 if n == m\n (1..n).inject(:*)/((1..m).inject(:*) * (1..n-m).inject(:*))\nend\n \nn = gets.to_i\ncake = []\nn.times do\n cake << gets.chomp.chars\nend\n \ncake_t = cake.transpose\n \nans = 0\n(0..n-1).each do |i|\n if (c = cake[i].count('C')) >= 2\n ans += combination_count(c, 2)\n end\n if (c = cake_t[i].count('C')) >= 2\n ans += combination_count(c, 2)\n end\nend\n \nputs ans"}, {"source_code": "a=gets.chomp.to_i\nrow=[]\nclm=[]\na.times do \nclm <<0\nend\na.times do \ntemp=gets.chomp.split(\"\")\nt=0\n0.upto(a-1) do |i|\nif temp[i]==\"C\"\nt+=1\nclm[i]+=1\nend\nend\nrow << t\nend\nans=0\nrow.each do |i|\nif i>1\nans=ans+(i*(i-1))/2\nend\nend\n\nclm.each do |i|\nif i>1\nans=ans+(i*(i-1))/2\nend\nend\nputs \"#{ans}\""}, {"source_code": "n=gets.to_i\ns=[]\nn.times{\n\ts<1\nans=ans+(i*(i-1))/2\nend\nend\n\nclm.each do |i|\nif i>1\nans=ans+(i*(i-1))/2\nend\nend\nputs \"#{ans}\""}, {"source_code": "#!/usr/bin/ruby\ngets;a=$<.map{|e|e.chomp.chars}\nr=0\n[a,a.transpose].each{|b|b.each{|e|n=e.count('C');r+=n*(n-1)/2}}\np r"}, {"source_code": "n = gets.to_i\na = []\nn.times { a << gets.chomp.split('') }\nb = a.transpose\njoy = 0\n(0...n).each do |i|\n c = a[i].count('C') - 1\n joy += (1 + c)*c/2\n c = b[i].count('C') - 1\n joy += (1 + c)*c/2\nend\nputs joy\n"}], "negative_code": [{"source_code": "def combination_count(n, m)\n (1..n).inject(:*)/(1..m).inject(:*)\nend\n\nn = gets.to_i\ncake = []\nn.times do\n cake << gets.chomp.chars\nend\n\ncake_t = cake.transpose\n\nans = 0\n(0..n-1).each do |i|\n if (c = cake[i].count('C')) > 0\n ans += combination_count(c, 2)\n end\n if (c = cake_t[i].count('C')) > 0\n ans += combination_count(c, 2)\n end\nend\n\nputs ans\n\n"}], "src_uid": "7749f37aa9bf88a00013557e14342952"} {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nif a.any?{|i|i % a[0] > 0} then p -1 else puts 2 * n - 1, a * (\" %d \" % a[0]) end", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nif a.any?{|i|i % a[0] > 0} then p -1 else puts 2 * n - 1, a * (\" %d \" % a[0]) end"}], "negative_code": [], "src_uid": "dfe5af743c9e23e98e6c9c5c319d2126"} {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n au = a.uniq\n\n if au.size == 1\n puts 'NO'\n else\n v1 = a.index(au[0])\n v2 = a.index(au[1])\n edges = []\n edges << [v1, v2]\n\n a.each.with_index do |x, i|\n next if i == v1\n next if i == v2\n\n if x == a[v1]\n edges << [v2, i]\n else\n edges << [v1, i]\n end\n end\n\n puts 'YES'\n edges.each do |u, v|\n puts \"#{u + 1} #{v + 1}\"\n end\n end\nend\n", "positive_code": [{"source_code": "def solve(n, a)\n result = []\n first = a.first\n second = -1\n a.each_with_index do |element, i|\n second = 1+i if element!=first\n end\n if second!=-1\n 1.upto(n-1) do |i|\n if(a[i]!=first)\n result.push([1,i+1])\n else\n result.push([second, i+1])\n end\n end\n end\n result\nend\n\n\n(gets.to_i).times do\n n = gets.to_i\n a = gets.split(' ').map(&:to_i)\n b = solve(n,a)\n if(b.length == 0)\n puts \"NO\"\n else\n puts \"YES\"\n b.each do |i|\n puts \"#{i[0]} #{i[1]}\"\n end\n end\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n next puts 'NO' if a.count(a[0]) == n\n puts 'YES'\n i = 0\n j = a.index { |x| x != a[i] }\n puts \"#{i + 1} #{j + 1}\"\n n.times do |k|\n if i != k and j != k\n if a[i] == a[k]\n puts \"#{j + 1} #{k + 1}\"\n else\n puts \"#{i + 1} #{k + 1}\"\n end\n end\n end\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n v = gets.split.map(&:to_i)\n p = (0...n).sort { |i, j| v[i] <=> v[j] }\n w = p.chunk { |i| v[i] }.map(&:last)\n if w.length == 1\n puts 'NO'\n else\n puts 'YES'\n w.drop(1).flatten.each do |x|\n puts \"#{p[0] + 1} #{x + 1}\"\n end\n w[0].drop(1).each do |x|\n puts \"#{w[1][0] + 1} #{x + 1}\"\n end\n end\nend\n"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n hash = Hash.new(0)\n max = 0\n a.each do |v|\n hash[v] += 1\n if max < hash[v]\n max = hash[v]\n end\n end\n if max > n-1\n ans << \"NO\"\n else\n ans << \"YES\"\n one = 1\n two = 0\n for i in 1..n-1\n next if a[i] == a[0]\n two = i+1\n break\n end\n ans << \"#{one} #{two}\"\n for i in 1..n-1\n next if i+1 == two\n if a[i] != a[one-1]\n ans << \"#{one} #{i+1}\"\n else\n ans << \"#{two} #{i+1}\"\n end\n end\n end\nend\n\nputs ans"}], "negative_code": [{"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n hash = Hash.new(0)\n max = 0\n city = 0\n a.each do |v|\n hash[v] += 1\n if max < hash[v]\n max = hash[v]\n city = v\n end\n end\n if max > n/2\n ans << \"NO\"\n else\n ans << \"YES\"\n pre = 0\n dist = Array.new(n+1,0)\n arr = Array.new(n,0)\n e = []\n n.times do |i|\n if a[i] == city\n e << i+1\n dist[i+1] = 1\n end\n end\n max.times do |i|\n arr[i*2] = e[i]\n end\n pre = 0\n for i in (max*2-1)..n-1\n for j in 0..n-1\n if a[j] != pre && dist[j+1] == 0\n arr[i] = j+1\n dist[j+1] = 1\n pre = a[j]\n break\n end\n end\n end\n (max-1).times do |i|\n for j in 0..n-1\n if dist[j+1] == 0\n arr[i*2+1] = j+1\n dist[j+1] = 1\n break\n end\n end\n end\n (n-1).times do |i|\n ans << \"#{arr[i]} #{arr[i+1]}\"\n end\n end\nend\n\nputs ans"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n hash = Hash.new(0)\n max = 0\n a.each do |v|\n hash[v] += 1\n if max < hash[v]\n max = hash[v]\n end\n end\n if max > (n+1)/2\n ans << \"NO\"\n else\n ans << \"YES\"\n one = 1\n two = 0\n for i in 1..n-1\n next if a[i] == a[0]\n two = i+1\n break\n end\n ans << \"#{one} #{two}\"\n for i in 1..n-1\n next if i+1 == two\n if a[i] != one\n ans << \"#{one} #{i+1}\"\n else\n ans << \"#{two} #{i+1}\"\n end\n end\n end\nend\n\nputs ans"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n hash = Hash.new(0)\n max = 0\n a.each do |v|\n hash[v] += 1\n if max < hash[v]\n max = hash[v]\n end\n end\n if max > n-1\n ans << \"NO\"\n else\n ans << \"YES\"\n one = 1\n two = 0\n for i in 1..n-1\n next if a[i] == a[0]\n two = i+1\n break\n end\n ans << \"#{one} #{two}\"\n for i in 1..n-1\n next if i+1 == two\n if a[i] != one\n ans << \"#{one} #{i+1}\"\n else\n ans << \"#{two} #{i+1}\"\n end\n end\n end\nend\n\nputs ans"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n hash = Hash.new(0)\n max = 0\n a.each do |v|\n hash[v] += 1\n if max < hash[v]\n max = hash[v]\n end\n end\n if max > n-1\n ans << \"NO\"\n else\n ans << \"YES\"\n one = 1\n two = 0\n for i in 1..n-1\n next if a[i] == a[0]\n two = i+1\n break\n end\n ans << \"#{one} #{two}\"\n for i in 1..n-1\n next if i+1 == two\n if a[i+1] != one\n ans << \"#{one} #{i+1}\"\n else\n ans << \"#{two} #{i+1}\"\n end\n end\n end\nend\n\nputs ans"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n hash = Hash.new(0)\n max = 0\n city = 0\n a.each do |v|\n hash[v] += 1\n if max < hash[v]\n max = hash[v]\n city = v\n end\n end\n if max > (n+1)/2\n ans << \"NO\"\n else\n ans << \"YES\"\n pre = 0\n dist = Array.new(n+1,0)\n arr = Array.new(n,0)\n e = []\n n.times do |i|\n if a[i] == city\n e << i+1\n dist[i+1] = 1\n end\n end\n max.times do |i|\n arr[i*2] = e[i]\n end\n pre = 0\n for i in (max*2-1)..n-1\n for j in 0..n-1\n if a[j] != pre && dist[j+1] == 0\n arr[i] = j+1\n dist[j+1] = 1\n pre = a[j]\n break\n end\n end\n end\n (max-1).times do |i|\n for j in 0..n-1\n if dist[j+1] == 0\n arr[i*2+1] = j+1\n dist[j+1] = 1\n break\n end\n end\n end\n (n-1).times do |i|\n ans << \"#{arr[i]} #{arr[i+1]}\"\n end\n end\nend\n\nputs ans"}], "src_uid": "d8136eb72931851f501c5ce9042ce4eb"} {"source_code": "n = gets.to_i\nl = gets.split.map { |x| x.to_i }\n\nl.sort!\nmax = l.pop\nsum = l.reduce(:+)\n\nputs [max - sum + 1, 0].max\n", "positive_code": [{"source_code": "n = readline.to_i\narr = readline.split(' ').collect(&:to_i).sort.reverse\nputs 1 + arr[0] - arr[1..-1].inject(0, :+)\n"}, {"source_code": "def solve(a)\n 2*a.max - a.inject(:+) + 1\nend\n\ngets\n\nputs solve(gets.split.map(&:to_i))"}, {"source_code": "lodNum = gets.chomp.to_i\ninput = gets.chomp.split(' ').map {|i| i.to_i}\ninput.sort!\n\nsum = 0\nflag = false\nmax = input[input.length - 1]\nfor i in (0...(input.length - 1))\n\tsum += input[i]\nend\n\nif !flag && sum > max\n\tputs '0'\nelse\n\tputs (max - sum + 1)\nend"}, {"source_code": "n = gets\n\nparse_int = lambda { gets.split.map{|x| x.to_i} }\n\nm = parse_int.call\n\nm.sort!\n\nlast = m.pop\nsum = 0\nm.each { |a| sum+=a }\nputs last-sum+1\n"}], "negative_code": [], "src_uid": "f00d94eb37c98a449615f0411e5a3572"} {"source_code": "# T = gets.chomp.to_i\n# (0..T-1).map do |i|\n# N = gets.chomp.to_i\n# pN = (N/2).ceil\n# b = gets.chomp\n# max_bs = []\n# (0..(b.length - pN + 1)).map do |j|\n# sub_b = b[j..(j + pN - 1)]\n# sum_b = sub_b.split('').inject 0 do |s, e|\n# s += e.to_i\n# end\n# max_bs << sum_b\n# end\n# p \"Case ##{i + 1}: #{max_bs.max}\"\n# end\n\nn, k = gets.chomp.split \" \"\nn = n.to_i\nk = k.to_i\np (k.to_r / n).ceil", "positive_code": [{"source_code": "n,k=gets.split.map &:to_i;p (k+n-1)/n"}, {"source_code": "\ndef solution\n n, k = read_ints\n s = k/n\n s += 1 if s*n < k\n puts s\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}, {"source_code": "N, K = gets.split.map(&:to_i)\nputs (K-1)/N+1"}, {"source_code": "n,k=gets.strip.split.map(&:to_i)\nans=0\nans += (k/n)\nans += 1 if k%n != 0\nputs ans"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\nans = k / n\nif k % n != 0\n ans += 1\nend\n\nputs ans"}, {"source_code": "n,k=gets.split.map &:to_i;p (k+n-1)/n"}, {"source_code": "n,k = gets.split.map(&:to_i)\nputs (k+n-1)/n\n"}, {"source_code": "n, k = gets.split.map &:to_i\nprint (k+n-1)/n"}], "negative_code": [{"source_code": "\n\nn, k = gets.chomp.split.map(&:to_i)\nputs (n.to_f/k).ceil\n"}, {"source_code": "\ndef solution\n n, k = read_ints\n s = k/n\n s += 1 if s*k < n\n puts s\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}, {"source_code": "\n\nn, k = gets.chomp.split.map(&:to_i)\nputs (k.to_f/n).ceil"}, {"source_code": "# T = gets.chomp.to_i\n# (0..T-1).map do |i|\n# N = gets.chomp.to_i\n# pN = (N/2).ceil\n# b = gets.chomp\n# max_bs = []\n# (0..(b.length - pN + 1)).map do |j|\n# sub_b = b[j..(j + pN - 1)]\n# sum_b = sub_b.split('').inject 0 do |s, e|\n# s += e.to_i\n# end\n# max_bs << sum_b\n# end\n# p \"Case ##{i + 1}: #{max_bs.max}\"\n# end\n\nn, k = gets.chomp.split \" \"\nn = n.to_i\nk = k.to_i\np (k.to_f / n).ceil"}], "src_uid": "31014efa929af5e4b7d9987bd9b59918"} {"source_code": "$_ = gets.chomp + ' '\n[%w(lios etr initis), %w(liala etra inites)].each do |r|\n\tr.map!{|_| \"\\\\S*#{_}\\\\s+\"}\n\tr << \"(#{r[0]})*(#{r[1]})(#{r[2]})*\";\n\tif /^(#{r.join('|')})$/\n\t\tputs :YES\n\t\texit\n\tend\nend\nputs :NO\n\n", "positive_code": [{"source_code": "def get_info(s)\n case s\n when /lios$/\n return 1, 0\n when /liala$/\n return 1, 1\n when /etr$/\n return 2, 0\n when /etra$/\n return 2, 1\n when /initis$/\n return 3, 0\n when /inites$/\n return 3, 1\n else\n return -1, -1\n end\nend\n\ndef verify(words)\n if words.size == 0\n return false\n end\n if words.size == 1\n return words[0][0] >= 0\n end\n last_type = -1\n count_noun = 0\n words.each { |word|\n # Must be valid word\n if word[0] < 0\n return false\n end\n # Must have same gender\n if word[1] != words[0][1]\n return false\n end\n # Must be increasing in type\n if word[0] == 2\n count_noun += 1\n end\n if word[0] < last_type\n return false\n end\n last_type = word[0]\n }\n return count_noun == 1\nend\n\n[*$<].each { |line|\n words = line.split\n if verify(words.map { |s| get_info(s) })\n puts 'YES'\n else\n puts 'NO'\n end\n}\n\n"}, {"source_code": "words = gets.split\n\nif words.size == 1 and words.first =~ /(etr|etra|lios|liala|inites|initis)$/\n puts \"YES\"\nelsif words.size == 1\n puts \"NO\"\nelse\n first = words.first\n if first =~ /(lios|etr)$/\n gender = :male\n elsif first =~ /(liala|etra)$/\n gender = :female\n else\n puts \"NO\"\n Process.exit\n end\n\n for i in 1...words.size\n if (gender == :male and words[i] =~ /(liala|etra|inites)$/) or (gender == :female and words[i] =~ /(lios|etr|initis)$/)\n puts \"NO\"\n Process.exit\n end\n end\n\n pos = 1\n type = (first =~ /(etr|etra)$/) ? :noun : :adj\n\n if type == :adj\n pos += 1 while words[pos] =~ /(lios|liala)$/\n unless words[pos] =~ /(etr|etra)$/\n puts \"NO\"\n Process.exit\n end\n pos += 1\n end\n\n\n for i in pos...words.size\n unless (gender == :male and words[i] =~ /initis$/) or (gender == :female and words[i] =~ /inites$/)\n puts \"NO\"\n Process.exit\n end\n end\n\n puts \"YES\"\nend"}, {"source_code": "$_ = gets.chomp + ' '\n[%w(lios etr initis), %w(liala etra inites)].each do |r|\n\tr.map!{|_| \"\\\\S*#{_}\\\\s+\"}\n\tr << \"(#{r[0]})*(#{r[1]})(#{r[2]})*\";\n\tif /^(#{r.join('|')})$/\n\t\tputs :YES\n\t\texit\n\tend\nend\nputs :NO\n"}, {"source_code": "$_ = gets.chomp + ' '\n[%w(lios etr initis), %w(liala etra inites)].each do |r|\n\tr.map!{|_| \"\\\\S*#{_}\\\\s+\"}\n\tr << \"(#{r[0]})*(#{r[1]})(#{r[2]})*\";\n\tif /^(#{r.join('|')})$/\n\t\tputs :YES\n\t\texit\n\tend\nend\nputs :NO\n\n"}, {"source_code": "=begin\n , \\ / ,\n / \\ )\\__/( / \\\n / \\ (_\\ /_) / \\\n ____/_____\\__\\@ @/___/_____\\____\n | |\\../| |\n | \\VV/ |\n | ------hoi------- |\n |_________________________________|\n | /\\ / \\\\ \\ /\\ |\n | / V )) V \\ |\n |/ ` // ' \\|\n ` V '\n=end\n$_ = gets.chomp + ' '\n[%w(lios etr initis), %w(liala etra inites)].each do |r|\n\tr.map!{|_| \"\\\\S*#{_}\\\\s+\"}\n\tr << \"(#{r[0]})*(#{r[1]})(#{r[2]})*\";\n\tif /^(#{r.join('|')})$/\n\t\tputs :YES\n\t\texit\n\tend\nend\nputs :NO"}, {"source_code": "$_ = gets.chomp + ' '\n[%w(lios etr initis), %w(liala etra inites)].each do |r|\n\tr.map!{|_| \"\\\\S*#{_}\\\\s+\"}\n\tr << \"(#{r[0]})*(#{r[1]})(#{r[2]})*\";\n\tif /^(#{r.join('|')})$/\n\t\tputs :YES\n\t\texit\n\tend\nend\nputs :NO\n\n"}, {"source_code": "$_ = gets.chomp + ' '\n[%w(lios etr initis), %w(liala etra inites)].each do |r|\n\tr.map!{|_| \"\\\\S*#{_}\\\\s+\"}\n\tr << \"(#{r[0]})*(#{r[1]})(#{r[2]})*\";\n\tif /^(#{r.join('|')})$/\n\t\tputs :YES\n\t\texit\n\tend\nend\nputs :NO\n"}, {"source_code": "$_ = gets.chomp + ' '\n[%w(lios etr initis), %w(liala etra inites)].each do |r|\n\tr.map!{|_| \"\\\\S*#{_}\\\\s+\"}\n\tr << \"(#{r[0]})*(#{r[1]})(#{r[2]})*\";\n\tif /^(#{r.join('|')})$/\n\t\tputs :YES\n\t\texit\n\tend\nend\nputs :NO\n\n"}, {"source_code": "$_ = gets.chomp + ' '\n[%w(lios etr initis), %w(liala etra inites)].each do |r|\n r.map!{|_| \"\\\\S*#{_}\\\\s+\"}\n r << \"(#{r[0]})*(#{r[1]})(#{r[2]})*\";\n if /^(#{r.join('|')})$/\n puts :YES\n exit\n end\nend\nputs :NO"}, {"source_code": "s = gets.strip\n[%w(lios etr initis), %w(liala etra inites)].each do |g|\n r = g.map { |t| \"\\\\S*#{t}(\\\\s+|$)\" }\n r << \"(#{r[0]})*#{r[1]}(#{r[2]})*\"\n if /^(#{r.join ?|})$/.match s\n puts :YES\n exit\n end\nend\nputs :NO\n"}, {"source_code": "$_ = gets.chomp + ' '\n[%w(lios etr initis), %w(liala etra inites)].each do |r|\n\tr.map!{|_| \"\\\\S*#{_}\\\\s+\"}\n\tr << \"(#{r[0]})*(#{r[1]})(#{r[2]})*\";\n\tif /^(#{r.join('|')})$/\n\t\tputs :YES\n\t\texit\n\tend\nend\nputs :NO\n\n"}, {"source_code": "$_ = gets.chomp + ' '\n[%w(lios etr initis), %w(liala etra inites)].each do |r|\n\tr.map!{|_| \"\\\\S*#{_}\\\\s+\"}\n\tr << \"(#{r[0]})*(#{r[1]})(#{r[2]})*\";\n\tif /^(#{r.join('|')})$/\n\t\tputs :YES\n\t\texit\n\tend\nend\nputs :NO\n\n"}, {"source_code": "def solve(ws)\n ts = ws.map do |w|\n case\n when w.end_with?('lios') then [:adj, :mas]\n when w.end_with?('liala') then [:adj, :fem]\n when w.end_with?('etr') then [:noun, :mas]\n when w.end_with?('etra') then [:noun, :fem]\n when w.end_with?('initis') then [:verb, :mas]\n when w.end_with?('inites') then [:verb, :fem]\n when true then nil\n end\n end\n return false if ts.any?(&:nil?)\n return true if ts.size == 1\n return false unless ts.all?{|x| x[1] == ts[0][1]}\n cb = :adj\n ts.each do |t, _|\n case cb\n when :adj\n case t\n when :noun then cb=:noun\n when :verb then return false\n end\n when :noun,:verb\n case t\n when :adj, :noun then return false\n when :verb then cb=:verb\n end\n end\n end\n return cb == :noun || cb == :verb\nend\n\nwords = gets.split\nputs solve(words) ? 'YES' : 'NO'\n"}, {"source_code": "\nclass String\n def end_with(s)\n i = self.rindex s\n !i.nil? && self.length - i == s.length\n end\nend\n\n$w = [\n %w(lios ma),\n %w(liala fa),\n %w(etr mn),\n %w(etra fn),\n %w(initis mv),\n %w(inites fv),\n ]\ndef f(str)\n $w.each {|suf, s|\n return s if str.end_with suf\n }\n nil\nend\n\ndef valid(words)\n return false if words.index nil\n return true if words.length == 1\n\n return false if words.map{|w|w[0]}.uniq.length > 1\n a = words.map{ |w| w[1] }\n i = 0\n i += 1 while i= words.count then\n puts \"NO\"\n exit\n end\nend\n\nunless words[i][:type] == :noun\n puts \"NO\"\n exit\nend\ni += 1\nif i >= words.count then\n puts \"YES\"\n exit\nend\n\nwhile i < words.count\n if words[i][:type] != :verb then\n puts \"NO\"\n exit\n end \n i += 1\nend\n\nputs \"YES\"\n"}, {"source_code": "def g(s)\n case s\n when /lios$/\n return 1, 0\n when /liala$/\n return 1, 1\n when /etr$/\n return 2, 0\n when /etra$/\n return 2, 1\n when /initis$/\n return 3, 0\n when /inites$/\n return 3, 1\n else\n return -1, -1\n end\nend\n\ndef v(words)\n if words.size == 0\n return false\n end\n if words.size == 1\n return words[0][0] >= 0\n end\n last_type = -1\n c = 0\n words.each { |w|\n return false if w[0] < 0\n return false if w[1] != words[0][1]\n c += 1 if w[0] == 2\n return false if w[0] < last_type\n last_type = w[0]\n }\n return c == 1\nend\n\nwords = gets.split\nif v(words.map { |s| g(s) })\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "def g(s)\n case s\n when /lios$/\n return 1, 0\n when /liala$/\n return 1, 1\n when /etr$/\n return 2, 0\n when /etra$/\n return 2, 1\n when /initis$/\n return 3, 0\n when /inites$/\n return 3, 1\n else\n return -1, -1\n end\nend\n\ndef v(words)\n return false if words.size==0\n return words[0][0] >= 0 if words.size==1\n l=-1\n c=0\n words.each { |w|\n return false if w[0]<0\n return false if w[1]!=words[0][1]\n c+=1 if w[0]==2\n return false if w[0]$rank[rb]\n\t\t$parent[rb]=ra\n\t\t$size[ra]+=$size[rb];\n\t\t$size[rb]=0;\n\telse\n\t\t$parent[rb]=ra\n\t\t$rank[ra]+=1\n\t\t$size[ra]+=$size[rb];\n\t\t$size[rb]=0;\n\tend\nend\nm.times do\n\tab=gets.chomp.split.map{|x| x.to_i }\n\tunion(ab[0],ab[1])\nend\nsee=Array.new(1+n,0)\ndef all_connect(n)\n\tn*(n-1)/2\nend\n#puts $size.join(\" \")\ntotal_edge=0\n#puts $parent.join(\" \")\nfor i in 1..n\n\ttotal_edge+=all_connect($size[i])\n\t#puts all_connect($size[i])\nend\n#puts total_edge\n#puts m\nif total_edge==m\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n"}, {"source_code": "require 'set'\nn, m = gets.split.map(&:to_i)\n\n#friends = Set.new # friends with... er... friends. For .delete() only\nfriendships = Hash.new do |hash, key|\n\thash[key] = []\nend # id => [f1, f2, ...]\n#friends[A][B], A0\n\t#p friendships\n\tf_id, friends = friendships.first\n\tfriendships.delete(f_id)\n\tnext if friends.size == 0\t\n\tfriends_to_check = friends\n\tfriends_checked = Set.new([f_id])\n\tfriends_count = friends.length\n\t#p \"#> #{f_id} #{friends_count} #{friends}\"\n\tuntil friends_to_check.empty?\n\t\tf = friends_to_check.pop\n\t\tfriends = friendships[f]\n\t\tfriendships.delete(f)\n\t\tnext if friends_checked.include? f\n\t\t#p \">>> #{f} #{friends}\"\t\t\n\t\tif friends.size != friends_count\n\t\t\t#OOPS.\n\t\t\tputs \"NO\"\n\t\t\texit\n\t\tend\n\t\tfriends.each do |f_new|\n\t\t\tnext if friends_checked.include? f_new\n\t\t\tfriends_to_check << f_new\n\t\tend\n\t\tfriends_checked << f\n\tend\n\t#p \"#: #{friends_checked}; #{friends_count}\" \n\tif friends_checked.size!=friends_count+1\n\t\t#OOPS!\n\t\tputs \"NO\"\n\t\texit\n\tend\nend\nputs \"YES\"\n"}], "negative_code": [{"source_code": "#\u6211\u73b0\u5728\u7684\u60f3\u6cd5\u662f\uff1a\u628a\u76f8\u8fde\u7684\u70b9\u653e\u5728\u4e00\u4e2a\u96c6\u5408\u91cc\uff0c\u7136\u540e\u7edf\u8ba1\u76f8\u8fde\u7684\u70b9\u81f3\u5c11\u8981\u591a\u5c11\u6761\u8fb9\uff0c\n#\u5982\u679c\u603b\u8fb9\u6570\u4e0d\u591f\uff0c\u5c31\u6253\u5370no\uff0c\u5982\u679c\u603b\u8fb9\u6570\u591f\u5c31\u6253\u5370yes\uff01\n#\u4eca\u5929\u7b97\u662f\u77e5\u9053\u4e86dsu\u7684\u610f\u601d\uff01\n#dsu==disjont set\uff01?\nnm=gets.chomp.split.map{|x| x.to_i }\nn=nm[0]\nm=nm[1]\n$parent=Array.new(1+n)\n$rank=Array.new(1+n)\n$size=Array.new(1+n,0)\n$see=Array.new(1+n,0)\nfor i in 0..n\n\t$parent[i]=i\n\t$rank[i]=0\nend\ndef find(a)\n\tif $parent[a]!=a\n\t\t$parent[a]=find($parent[a])\n\tend\n\treturn $parent[a]\nend\ndef union(a,b)\n\tra=find(a)\n\trb=find(b)\n\tif ra==rb\n\t\treturn\n\tend\n\tif $rank[ra]<$rank[rb]\n\t\t$parent[ra]=rb\n\telsif $rank[ra]>$rank[rb]\n\t\t$parent[rb]=ra\n\telse\n\t\t$parent[rb]=ra\n\t\t$rank[ra]+=1\n\tend\n\tif $see[a]==0 && $see[b]==0\n\t\t$size[find(a)]+=2\n\t\t$see[a]=1\n\t\t$see[b]=1\n\telsif $see[a]==1 && $see[b]==0\n\t\t$size[find(a)]+=1\n\t\t$see[b]=1\n\telsif $see[a]==0 && $see[b]==1\n\t\t$size[find(b)]+=1\n\t\t$see[a]=1\n\tend\nend\nm.times do\n\tab=gets.chomp.split.map{|x| x.to_i }\n\tunion(ab[0],ab[1])\nend\nsee=Array.new(1+n,0)\ndef all_connect(n)\n\tn*(n-1)/2\nend\ntotal_edge=0\nfor i in 1..n\n\ttotal_edge+=all_connect($size[i])\nend\nif total_edge==m\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n"}, {"source_code": "#1. Accomodate inputs & Initialize\nn = gets(\" \").to_i\nm = gets.chomp.to_i\n\nrelations = Array.new(n+1){Array.new()}\n(1..m).each do |i|\n a = gets(\" \").to_i\n b = gets.chomp.to_i\n relations[a].push(b)\nend\n\namigos = Array.new(n+1, 0)\nstack = Array.new()\n\n\n#2. Build equivalent classes\n(1..n).each do |i|\n next if relations[i].empty?\n\n ne = 1\n nr = 0\n amigos.fill(false)\n stack.clear()\n\n amigos[i] = true\n stack.push(i)\n\n while (!stack.empty?)\n head = stack.pop()\n relations[head].each do |e|\n if !amigos[e]\n ne += 1\n stack.push(e)\n amigos[e] = true\n end\n end\n nr += relations[head].length()\n relations[head].clear()\n end\n\n if ((ne-1)*ne)/2 != nr\n puts \"NO\"\n exit\n end\nend\n\nputs \"YES\""}], "src_uid": "1173d89dd3af27b46e579cdeb2cfdfe5"} {"source_code": "def solve(a,b)\n ans=999999999\n $w.times{|x|\n $h.times{|y|\n if x+a-1<$w && y+b-1<$h then\n tans=0\n a.times{|i|\n b.times{|j|\n if $map[y+j][x+i]==1 then\n tans+=1\n end\n }\n }\n ans=[ans,tans].min\n end\n }\n }\n return ans\nend\n$h,$w=gets.split.map(&:to_i)\n$map=[]\n$h.times{ $map.push(gets.split.map(&:to_i)) }\na,b=gets.split.map(&:to_i)\nputs [solve(a,b),solve(b,a)].min", "positive_code": [{"source_code": "def anal(memo,n,m,a,b)\n\tmin=n*m\n\t1.upto(n-a+1){|i|1.upto(m-b+1){|j|\n\t\ttemp=memo[i-1][j-1]+memo[i+a-1][j+b-1]-memo[i+a-1][j-1]-memo[i-1][j+b-1]\n\t\tmin=temp if temp sweaty\n puts -1\n exit\n end\n map.push(sweaty-gnome)\n}\n\nmap.sort!\n\nans = 1\n\nmap.each_index{ |i|\n if i != 0\n if map[i-1] != map[i]\n ans += 1\n end\n end\n}\n\nputs \"#{ans}\"", "positive_code": [{"source_code": "gets\nd = []\nwhile s = gets do\n g = s.index 'G'\n f = s.index 'S'\n if g > f\n p -1\n exit\n end\n d << f - g\nend\np d.uniq.length"}, {"source_code": "gets\nd = []\nwhile s = gets do\n g = s.index 'G'\n f = s.index 'S'\n if !g or !f or g > f\n p -1\n exit\n end\n d << f - g\nend\np d.uniq.length"}, {"source_code": "n, m = gets.split(\" \").map &:to_i\ndistances = []\nn.times do\n s = gets\n gnome = s.index 'G'\n flower = s.index 'S'\n if !gnome or !flower or gnome > flower\n p -1\n exit\n end\n distances << flower - gnome\nend\np distances.uniq.length"}, {"source_code": "n,m=gets.split.map(&:to_i)\nb=[]\nn.times{\n\ta=gets.chomp\n\tb< s\n puts -1\n exit\n end\n all << s - g\nend\nputs all.uniq.size\n"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\nans = Array.new(n)\nn.times do |i|\n s = gets.chomp\n d = s.index(\"G\")\n c = s.index(\"S\")\n if d > c\n puts -1\n exit\n end\n ans[i] = c-d\nend\nputs ans.uniq.size\n"}, {"source_code": "def check_min_distance (board)\n\tdistance = []\n\tboard.each do |row|\n\t\tdwarf = 0\n\t\tcandy = 0\n\t\trow.each_with_index do |c, index|\n\t\t\tif c == \"G\"\n\t\t\t\tdwarf = index\n\t\t\telsif c == \"S\"\n\t\t\t\tcandy = index\n\t\t\tend\n\t\tend\n\t\tif dwarf < candy\n\t\t\tdistance << (candy - dwarf)\n\t\telse\n\t\t\treturn -1\n\t\tend\n\tend\n\n\treturn (distance.uniq).length\n\nend\n\nboard = []\nrow = (((gets()).split(\" \")).shift).to_i - 1\n\nfor i in 0..row\n\tary = []\n\t(gets()).each_char{ |c| ary << c }\n\tary.pop\n\tboard << ary\nend\n\nputs check_min_distance(board)"}], "negative_code": [{"source_code": "n, m = gets.split.map &:to_i\nmap = Array.new(n)\nall = []\nf = [true]\nn.times do |i|\n map[i] = gets.chomp.split(//)\n g = -1; s = -1\n map[i].each_with_index do |x, i|\n g = i if x == 'G'\n s = i if x == 'S'\n end\n if s == -1 || g == -1 || g > s\n puts -1\n exit\n end\n all << s - g\nend\nans = 0\nall = all.uniq.sort\nall.each do |x|\n if !f[x]\n ans += 1\n m.downto(x) do |i|\n f[i] = true if f[i - x]\n end\n end\nend\nputs ans\n"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\nans = 0\nn.times do\n s = gets.chomp\n d = s.index(\"G\")\n c = s.index(\"S\")\n if d > c\n ans = -1\n break\n end\n ans = c-d-1 if ans < c-d-1\nend\nputs ans\n"}, {"source_code": "def check_min_distance (board, n)\n min = -1\n board.each do |row|\n dwarf = 0\n candy = 0\n row.each_with_index do |c, index|\n if c == \"G\"\n dwarf = index\n elsif c == \"S\"\n candy = index\n end\n end\n if dwarf < candy\n if min == -1\n min = candy - dwarf\n elsif (candy - dwarf) < min\n min = candy - dwarf\n end\n elsif dwarf != n\n if (n - dwarf) < min\n min = n - dwarf\n end\n elsif dwarf == n\n return -1\n end\n end\n \n return min\nend\n\nboard = []\nfirst_line = (gets()).split(\" \")\nrow = (first_line.shift).to_i - 1\nn = (first_line.shift).to_i - 1\n\nfor i in 0..row\n ary = []\n (gets()).each_char{ |c| ary << c }\n ary.pop\n board << ary\nend\n\nputs check_min_distance(board, n)"}, {"source_code": "def check_min_distance (board, n)\n min = -1\n far_goal = 0\n over_dwarf = 0\n board.each do |row|\n dwarf = 0\n candy = 0\n row.each_with_index do |c, index|\n if c == \"G\"\n dwarf = index\n elsif c == \"S\"\n candy = index\n end\n end\n if dwarf < candy\n if far_goal < (candy-1 - dwarf)\n far_goal = (candy-1 - dwarf)\n end\n elsif dwarf != n and (candy < dwarf)\n if over_dwarf < dwarf\n over_dwarf = dwarf\n end\n elsif dwarf == n\n return -1\n end\n end\n\n if (over_dwarf != 0)\n return (n - over_dwarf)\n else\n return far_goal\n end\nend\n\nboard = []\nfirst_line = (gets()).split(\" \")\nrow = (first_line.shift).to_i - 1\nn = (first_line.shift).to_i - 1\n\nfor i in 0..row\n ary = []\n (gets()).each_char{ |c| ary << c }\n ary.pop\n board << ary\nend\n\nputs check_min_distance(board, n)"}, {"source_code": "def check_min_distance (board)\n min = -1\n board.each do |row|\n dwarf = 0\n candy = 0\n row.each_with_index do |c, index|\n if c == \"G\"\n dwarf = index\n elsif c == \"S\"\n candy = index\n end\n end\n if dwarf < candy\n if min == -1\n min = candy - dwarf\n elsif (candy - dwarf) < min\n min = candy - dwarf\n end\n end\n end\n \n return min\nend\n\nboard = []\nfirst_line = (gets()).split(\" \")\nrow = (first_line.shift).to_i - 1\n\nfor i in 0..row\n ary = []\n (gets()).each_char{ |c| ary << c }\n ary.pop\n board << ary\nend\n\nputs check_min_distance board"}, {"source_code": "def check_min_distance (board, n)\n min = -1\n far_goal = 0\n over_dwarf = 0\n board.each do |row|\n dwarf = 0\n candy = 0\n row.each_with_index do |c, index|\n if c == \"G\"\n dwarf = index\n elsif c == \"S\"\n candy = index\n end\n end\n if dwarf < candy\n if far_goal < (candy-1 - dwarf)\n far_goal = (candy-1 - dwarf)\n elsif dwarf == candy-1\n return -1\n end\n elsif dwarf != n and (candy < dwarf)\n if over_dwarf < dwarf\n over_dwarf = dwarf\n end\n elsif dwarf == n\n return -1\n end\n end\n\n if (over_dwarf != 0)\n return (n - over_dwarf)\n else\n return far_goal\n end\nend\n\nboard = []\nfirst_line = (gets()).split(\" \")\nrow = (first_line.shift).to_i - 1\nn = (first_line.shift).to_i - 1\n\nfor i in 0..row\n ary = []\n (gets()).each_char{ |c| ary << c }\n ary.pop\n board << ary\nend\n\nputs check_min_distance(board, n)"}, {"source_code": "def check_min_distance (board, n)\n min = -1\n board.each do |row|\n dwarf = 0\n candy = 0\n row.each_with_index do |c, index|\n if c == \"G\"\n dwarf = index\n elsif c == \"S\"\n candy = index\n end\n end\n if dwarf < candy\n if min == -1\n min = candy - dwarf\n elsif (candy - dwarf) < min\n min = candy - dwarf\n end\n elsif dwarf != n\n if (n - dwarf) < min\n min = n - dwarf\n end\n end\n end\n \n return min\nend\n\nboard = []\nfirst_line = (gets()).split(\" \")\nrow = (first_line.shift).to_i - 1\nn = (first_line.shift).to_i - 1\n\nfor i in 0..row\n ary = []\n (gets()).each_char{ |c| ary << c }\n ary.pop\n board << ary\nend\n\nputs check_min_distance(board, n)"}, {"source_code": "def check_min_distance (board, n)\n min = -1\n near_goal = n\n over_dwarf = 0\n board.each do |row|\n dwarf = 0\n candy = 0\n row.each_with_index do |c, index|\n if c == \"G\"\n dwarf = index\n elsif c == \"S\"\n candy = index\n end\n end\n if dwarf < candy\n if (candy - dwarf) < near_goal\n near_goal = (candy - dwarf)\n end\n elsif dwarf != n and (candy < dwarf)\n if over_dwarf < dwarf\n over_dwarf = dwarf\n end\n elsif dwarf == n\n return -1\n end\n end\n\n if (over_dwarf != 0) and (over_dwarf < near_goal)\n return (n - over_dwarf)\n end\n return near_goal\n\nend\n\nboard = []\nfirst_line = (gets()).split(\" \")\nrow = (first_line.shift).to_i - 1\nn = (first_line.shift).to_i - 1\n\nfor i in 0..row\n ary = []\n (gets()).each_char{ |c| ary << c }\n ary.pop\n board << ary\nend\n\nputs check_min_distance(board, n)"}], "src_uid": "9a823b4ac4a79f62cd0c2f88a1c9ef0c"} {"source_code": "class Solver\n\tdef main\n\t\tn, k = gets.split.map { |x| x.to_i }\n\t\ts = gets.split.map { |x| x.to_i }\n\t\tk = n if k > n\n\n\t\tans = 0\n\t\twhile 2 * k != n do\n\t\t\tans = [ans, s.pop].max\n\t\t\tk -= 1\n\t\t\tn -= 1\n\t\tend\n\n\t\ts = s.zip(s.reverse)\n\t\tans = (s.map { |x| x[0] + x[1] } << ans).max\n\t\tputs ans\n\tend\nend\n\nSolver.new.main\n", "positive_code": [{"source_code": "_,n=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).reverse\nr=0\nn.times.map{|i|r=[r,(a[i]||0)+(a[2*n-1-i]||0)].max}\np r"}, {"source_code": "_,n=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).reverse\nr=0\nn.times.map{|i|r=[r,(a[i]||0)+(a[2*n-1-i]||0)].max}\np r\n"}, {"source_code": "_,n=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).reverse\nr=0\nn.times.map{|i|r=[r,(a[i]||0)+(a[2*n-1-i]||0)].max}\np r\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\nh, k = gis\ns = gis\n\nx = s.pop k\n\np x.zip(s.reverse + [0] * (k - s.size)).map{|x,y| x+y}.max\n\n\n\n"}, {"source_code": "_,n=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).reverse\nr=0\nn.times.map{|i|r=[r,(a[i]||0)+(a[2*n-1-i]||0)].max}\np r\n"}, {"source_code": "_,n=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).reverse\nr=0\nn.times.map{|i|r=[r,(a[i]||0)+(a[2*n-1-i]||0)].max}\np r\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# b.rb\n\ndef main()\n n, k = gets.chomp().split(\" \").map{|si| next si.to_i() }\n s = gets.chomp().split(\" \").map{|si| next si.to_i() }\n\n m = s[-1]\n t = n - k\n t.times do |tt|\n mm = s[tt] + s[2 * t - 1 - tt]\n m = mm if m < mm\n end\n puts m\nend\n\nif __FILE__ == $0 then\n main()\nend\n"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nss = gets.chomp.split.map(&:to_i)\n\nputs (0...(n - k)).to_a.inject(ss[-1]) { |m, i| [m, ss[i] + ss[2 * (n - k) - i - 1]].max }\n"}, {"source_code": "_,n=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).reverse\nr=0\nn.times.map{|i|r=[r,(a[i]||0)+(a[2*n-1-i]||0)].max}\np r\n"}, {"source_code": "def main()\n\ta = gets.split(\" \").map{|i| i.to_i}\n\tn = a[0]\n\tk = a[1]\n\ts = gets.split(\" \").map{|i| i.to_i}\n\ts = [-1]+s\n\tif n <= k\n\t\tputs s[n]\n\telse\n\t\tsol = s[n]\n\t\tfor i in 0...n-k\n\t\t\tx = s[n-k-i]+s[n-k+1+i]\n\t\t\tif x > sol\n\t\t\t\tsol = x\n\t\t\tend\n\t\tend\n\t\tputs sol\n\tend\nend\nmain()\n\t\n"}, {"source_code": "a = gets.split(\" \").map{|i| i.to_i}\nn = a[0]\nk = a[1]\ns = gets.split(\" \").map{|i| i.to_i}\ns = [-1]+s\nif n <= k\n\tputs s[n]\nelse\n\tsol = s[n]\n\tfor i in 0...n-k\n\t\tx = s[n-k-i]+s[n-k+1+i]\n\t\tif x > sol\n\t\t\tsol = x\n\t\tend\n\tend\n\tputs sol\nend\n\n"}, {"source_code": "n, k = gets.chomp.split(\" \").map(&:to_i)\nss = gets.chomp.split(\" \").map(&:to_i)\nif n.even? then\n min_box = n / 2\n d = (k - min_box) * 2\nelse\n min_box = n / 2 + 1\n d = (k - min_box) * 2 + 1\nend\n\nres = ss.pop(d)\n\nhalf = ss.size / 2\nright = ss.pop(half).reverse\nss.zip(right).each do |a, b|\n res << a + b\nend\nputs res.max\n"}, {"source_code": "_,n=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).reverse\nr=0\nn.times.map{|i|r=[r,(a[i]||0)+(a[2*n-1-i]||0)].max}\np r\n"}, {"source_code": "_,n=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).reverse\nr=0\nn.times.map{|i|r=[r,(a[i]||0)+(a[2*n-1-i]||0)].max}\np r\n"}, {"source_code": "def can_put?(weights, k, s)\n return false if weights.last > s\n return weights[0] <= s if weights.size == 1\n\n used = 0\n \n ind = 0\n last_ind = weights.size - 1\n while ind <= last_ind\n if weights[ind] + weights[last_ind] > s\n if last_ind > ind\n used += 1\n last_ind -= 1\n else\n used += 1\n ind +=1\n last_ind -= 1\n end\n else\n used += 1\n ind +=1\n last_ind -= 1\n end\n end\n # p [s, used]\n used <= k\nend\n\nn,k = $stdin.readline.split.map(&:to_i)\nweights = $stdin.readline.split.map(&:to_i)\ns = ((0) .. (2*weights.last)).bsearch{|sz|\n can_put?(weights, k, sz)\n}\n\nputs s\n"}, {"source_code": "_,n=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).reverse\nr=0\nn.times.map{|i|r=[r,(a[i]||0)+(a[2*n-1-i]||0)].max}\np r\n"}], "negative_code": [{"source_code": "def can_put?(weights, k, s)\n return false if weights.last > s\n used = 0\n last_ind = weights.size - 1\n weights.each_index do |ind|\n while weights[ind] + weights[last_ind] > s && last_ind > ind\n last_ind -= 1\n used += 1\n end\n if last_ind == ind\n used += 1\n end\n end\n used <= k\nend\n\nn,k = $stdin.readline.split.map(&:to_i)\nweights = $stdin.readline.split.map(&:to_i)\ns = ((0) .. (2*weights.last)).bsearch{|sz|\n can_put?(weights, k, sz)\n}\n\nputs s"}, {"source_code": "def can_put?(weights, k, s)\n return false if weights.last > s\n\n used = 0\n \n ind = 0\n last_ind = weights.size - 1\n while ind < last_ind\n while weights[ind] + weights[last_ind] > s && last_ind > ind\n last_ind -= 1\n used += 1\n end\n if ind < last_ind && weights[ind] + weights[last_ind] <= s\n used += 1\n ind +=1\n last_ind -= 1\n elsif ind == last_ind\n used += 1\n last_ind -= 1 \n end\n end\n # p [s, used]\n used <= k\nend\n\nn,k = $stdin.readline.split.map(&:to_i)\nweights = $stdin.readline.split.map(&:to_i)\ns = ((0) .. (2*weights.last)).bsearch{|sz|\n can_put?(weights, k, sz)\n}\n\nputs s\n"}, {"source_code": "def can_put?(weights, k, s)\n return false if weights.last > s\n return weights[0] <= s if weights.size == 1\n\n used = 0\n \n ind = 0\n last_ind = weights.size - 1\n while ind < last_ind\n while weights[ind] + weights[last_ind] > s && last_ind > ind\n last_ind -= 1\n used += 1\n end\n if ind < last_ind && weights[ind] + weights[last_ind] <= s\n used += 1\n ind +=1\n last_ind -= 1\n elsif ind == last_ind\n used += 1\n last_ind -= 1 \n end\n end\n # p [s, used]\n used <= k\nend\n\nn,k = $stdin.readline.split.map(&:to_i)\nweights = $stdin.readline.split.map(&:to_i)\ns = ((0) .. (2*weights.last)).bsearch{|sz|\n can_put?(weights, k, sz)\n}\n\nputs s\n"}, {"source_code": "class Solver\n\tdef main\n\t\tn, k = gets.split.map { |x| x.to_i }\n\t\ts = gets.split.map { |x| x.to_i }\n\n\t\tans = 0\n\t\twhile 2 * k != n do\n\t\t\tans = [ans, s.pop].max\n\t\t\tk -= 1\n\t\t\tn -= 1\n\t\tend\n\n\t\ts = s.zip(s.reverse)\n\t\tans = [s.map { |x| x[0] + x[1] } << ans].max\n\t\tans = s.max\n\tend\nend\n\nSolver.new.main\n"}, {"source_code": "class Solver\n\tdef main\n\t\tn, k = gets.split.map { |x| x.to_i }\n\t\ts = gets.split.map { |x| x.to_i }\n\n\t\tans = 0\n\t\twhile 2 * k != n do\n\t\t\tans = [ans, s.pop].max\n\t\t\tk -= 1\n\t\t\tn -= 1\n\t\tend\n\n\t\ts = s.zip(s.reverse)\n\t\tans = [s.map { |x| x[0] + x[1] } << ans].max\n\t\tputs ans\n\tend\nend\n\nSolver.new.main\n"}], "src_uid": "7324428d9e6d808f55ad4f3217046455"} {"source_code": "x = 0\n(eval(gets) & 255).to_s.split('').map(&:ord).each{|c|\n\tif x < c\n\t\tprint \"+\" * (c - x)\n\tend\n\tif x > c\n\t\tprint \"-\" * (x - c)\n\tend\n\tprint \".\"\n\tx = c\n}\nputs\n", "positive_code": [{"source_code": "s = eval(gets.strip).to_s\n\nprint '++[------>+<]>+++++'\nq = 0\nf = false\nif s == \"0\"\n puts '.'\nelse\n for i in 0..(s.length-1)\n a = s[i].ord - '0'.ord\n if f\n if q < a%10\n print '+'*(q - a%10).abs + '.'\n else\n print '-'*(q - a%10).abs + '.'\n end\n q = a%10\n a/=10\n else\n q = a%10\n print '+'*q + '.'\n a/=10\n f = true\n end\n end\nend\n\n"}, {"source_code": "i = eval(gets.chomp())\ni.to_s.split('').each do |c|\n\tputs '+'*(48+c.to_i)+'.>'\nend\n"}, {"source_code": "#!/usr/bin/ruby\nprev=0\neval(*$<).to_s.bytes{|cur|\n\tdiff1=(cur-prev)%256\n\tdiff2=(prev-cur)%256\n\tif diff1<<'+'*diff1+'.'\n\telse\n\t\t$><<'-'*diff2+'.'\n\tend\n\tprev=cur\n}\nputs"}, {"source_code": "\"#{eval gets}\".bytes{|c|p'+'*c+'.>'}"}, {"source_code": "\"#{eval gets}\".bytes{|c|p'+'*c+'.>'}"}, {"source_code": "s = gets.chomp\nval = eval(s)\nval.to_s.chars.each do |x|\n puts \"+\"*(x.ord)+\".>\"\nend\n"}, {"source_code": "res = eval(gets.chomp).to_i\nfor i in 0..res-1\n\tprint '+'\nend\nputs '>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<'\n"}], "negative_code": [{"source_code": "res = eval(gets.chomp).to_i\nfor i in 1..res\n\tprint '+'\nend\nputs '.'\n"}, {"source_code": "res = eval(gets.chomp).to_i\nfor i in 0..res-1\n\tprint '+'\nend\nputs '.'\n"}, {"source_code": "res = eval(gets.chomp).to_i\nfor i in 0..res-1\n\tprint '+'\nend\nputs '>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-\n<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++\n<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]'\nputs '.'\n"}, {"source_code": "res = eval(gets.chomp).to_i\nfor i in 0..res-1\n\tprint '+'\nend\nputs '>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-\n<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++\n<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]'\n"}, {"source_code": "res = eval(gets.chomp).to_i\nfor i in 0..res-1\n\tprint '+'\nend\nprint '.'\n"}, {"source_code": "s = \"++[------>+<]>++.\"\nl =gets.strip\na = eval(l)\nif (a < 0)\n print s\n print '+'*(a.abs+3)\nelse\n print '++[------>+<]>+++++'\n print '+'*a\nend\nputs '.'\n"}], "src_uid": "072797682246c465148bd09736b76718"} {"source_code": "\nn = gets.strip.to_i\na = gets.strip.split(' ').map(&:to_i)\n\nc = t = 0\nwhile c < a.length\n 0.upto(a.length - 1) do |i|\n if a[i] >= 0 and a[i] <= c\n c += 1\n a[i] = -1\n end\n end\n\n break if c == a.length\n t += 1\n\n (a.length - 1).downto(0) do |i|\n if a[i] >= 0 and a[i] <= c\n c += 1\n a[i] = -1\n end\n end\n\n t += 1 if c < a.length\nend\n\nputs t.to_s", "positive_code": [{"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split(' ').map(&:to_i)\ndone = Array.new(n, false)\ncount = 0\nans = 0\nn.times do |time|\n next if count == n\n\n n.times do |p|\n pos = (time % 2 == 0) ? p : (n - 1) - p\n next if done[pos]\n next if count < arr[pos]\n done[pos] = true\n count += 1\n end\n\n ans += 1\nend\n\nputs ans - 1\n"}, {"source_code": "n = gets.to_i\ns = [nil]+gets.split(\" \").map(&:to_i)\np = 0\ni = 1\nd = 1\nc = 0\n\nwhile p < n\n\n\tif s[i] && s[i] <= p\n\t\ts[i] = nil\n\t\tp += 1\n\tend\n\n\tbreak if p == n\n\tif i == n && d == 1\n\t\td = -1\n\t\tc += 1\n\telsif i == 1 && d == -1\n\t\td = 1\n\t\tc += 1\n\tend\n\ti += d\nend\n\np c\n"}, {"source_code": "pieces_of_info, change_dir, position, increasing, cleared_computers = 0,0,0,true,0\nn, computers = gets.chomp.to_i, gets.chomp.split(\" \").map(&:to_i)\nloop do\n\tif computers[position] <= pieces_of_info and computers[position] != -1\n\t\tpieces_of_info += 1\n\t\tcleared_computers += 1\n\t\tcomputers[position] = -1\n\tend\n\n\tbreak if n == cleared_computers\n\n\tif increasing\n\t\tif position == n-1\n\t\t\tchange_dir += 1\n\t\t\tposition -= 1\n\t\t\tincreasing = false\n\t\telse\n\t\t\tposition +=1\n\t\tend\n\telse\n\t\tif position == 0\n\t\t\tchange_dir += 1\n\t\t\tposition += 1\n\t\t\tincreasing = true\n\t\telse\n\t\t\tposition -=1\n\t\tend\n\tend\nend\nputs change_dir"}, {"source_code": "\nn = gets.chomp.to_i;\narr = gets.chomp.split.map(&:to_i);\ninfo = 0;\nans = 0;\nn.times do |i|\n\n n.times do |j|\n if (arr[j] <= info) \n info += 1\n arr[j] = n + 2;\n end\n end;\n break if (info >= n);\n arr = arr.reverse;\n ans += 1;\nend\n\nputs ans;\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nans=-1\ni=0\nwhile !x.empty?\n\tans+=1\n\ty=[]\n\twhile !x.empty?\n\t\tif x[0]<=i then\n\t\t\ti+=1\n\t\telse\n\t\t\ty.unshift(x[0])\n\t\tend\n\t\tx.shift()\n\tend\n\tx=y\nend\nputs ans\n\n"}, {"source_code": "def done?(h, n)\n h.length == n\nend\n\ndef main\n n = gets.chomp.to_i\n a = gets.chomp.split.map {|i| i.to_i}\n\n count = 0\n info = 0\n h = {}\n while true\n n.times do |i|\n if not h[i]\n if a[i] <= info\n h[i] = :done\n info += 1\n end\n end\n end\n\n if done? h, n\n break\n end\n\n count += 1\n\n n.times do |i|\n if not h[n-i-1]\n if a[n-i-1] <= info\n h[n-i-1] = :done\n info += 1\n end\n end\n end\n\n if done? h, n\n break\n end\n\n count += 1\n\n end\n puts count\n\nend\n\nmain\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ninfo, ans = 0, 0\nn.times do |i|\n b = i.even? ? 0.upto(n - 1) : (n - 1).downto(0)\n b.each do |i|\n if a[i] <= info\n info += 1\n a[i] = 1010 \n end\n end\n break if info == n\n ans += 1\nend\nputs ans\n"}], "negative_code": [], "src_uid": "9374728643a1ddbe2200a4a125beef26"} {"source_code": "gets\r\n$<.each do\r\n n,k=_1.split.map &:to_i\r\n if n<2*k-1\r\n puts -1\r\n next\r\n end\r\n n.times do |i|\r\n s=\".\"*n\r\n s[i]=?R if i.even? && (i+1)/2 0\n row << 'R'\n limit -= 1\n else\n row << '.'\n end\n end\n\n result << row\n end\n\n result.each { puts _1.join }\n end\n\nend\n\ntests = STDIN.gets.to_i\ninputs = []\n\nfor i in (1..tests)\n n, k = STDIN.gets.split(' ').map(&:to_i)\n\n inputs << [n, k]\nend\n\ninputs.each do |(n, k)|\n solve(n, k)\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets.to_i.times do\n n, k = gets.split.map(&:to_i)\n\n if (n + 1) / 2 < k\n puts -1\n next\n end\n\n fld = Array.new(n) { '.' * n }\n k.times { |i|\n fld[i * 2][i * 2] = 'R'\n }\n\n puts fld.join \"\\n\"\nend\n"}], "negative_code": [{"source_code": "def solve(n, k)\r\n limit = k\r\n\r\n if (n / 3) + 1 < k\r\n return puts '-1'\r\n else\r\n result = []\r\n\r\n for i in (1..n)\r\n row = []\r\n\r\n for j in (1..n)\r\n\r\n if i == j && i % 2 == 1 && limit > 0\r\n row << 'R'\r\n limit -= 1\r\n else\r\n row << '.'\r\n end\r\n end\r\n\r\n result << row\r\n end\r\n\r\n result.each { puts _1.join }\r\n end\r\n\r\nend\r\n\r\ntests = STDIN.gets.to_i\r\ninputs = []\r\n\r\nfor i in (1..tests)\r\n n, k = STDIN.gets.split(' ').map(&:to_i)\r\n\r\n inputs << [n, k]\r\nend\r\n\r\ninputs.each do |(n, k)|\r\n solve(n, k)\r\nend\r\n"}, {"source_code": "def solve\r\n n, k = STDIN.gets.split(' ').map(&:to_i)\r\n\r\n limit = k\r\n\r\n if (n / 3) + 1 < k\r\n return puts '-1'\r\n else\r\n result = []\r\n\r\n for i in (1..n)\r\n row = []\r\n\r\n for j in (1..n)\r\n\r\n if i == j && i % 2 == 1 && limit > 0\r\n row << 'R'\r\n limit -= 1\r\n else\r\n row << '.'\r\n end\r\n end\r\n\r\n result << row\r\n end\r\n\r\n result.each { puts _1.join }\r\n end\r\n\r\nend\r\n\r\ntests = STDIN.gets.to_i\r\n\r\nfor i in (1..tests)\r\n solve\r\nend\r\n"}], "src_uid": "d5549c0627c236d82541a67ccbe7977d"} {"source_code": "input = $stdin.readline.split(' ')\nn = input[0].to_i; x = input[1].to_i; y=input[2].to_i\na = Array.new(n, 1)\n\nsquare_sum = n; sum = n\ni = 0\n\nuntil square_sum >= x do\n if sum > y then\n puts -1\n exit\n end\n square_sum -= a[i] * a[i]; a[i]+= 1; sum += 1; square_sum += a[i] * a[i]\n\nend\n\nif sum > y then\n puts -1\n exit\nend\n\na.each do |i| print \"#{i} \" end\nprint \"\\n\"", "positive_code": [{"source_code": "n, x, y = gets.split.map(&:to_i)\nt = n - 1\nu = y - t\nif u * u + t >= x and y >= n\n puts \"1\\n\" * (n - 1) + \"#{u}\"\nelse\n puts -1\nend"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\nif y=x\n\t\ta=[1]*(n-1)\n\t\ta<=t\n\tarr3[arr2[index].to_i-1]+=1\n\tindex+=1\nend\n\nsum=0\ncount=0\n\nindex=0\nloop do \n\tbreak if index>=n-1\n\tcount = count + arr3[index]\n\tsum = sum + arr3[index]*(t-count)\n\tindex+=1\n\t#puts \"Index is #{index} and sum is #{sum} and count is #{count}\"\nend\n\nputs sum"}, {"source_code": "h=Hash.new(0)\nn=gets.to_i\ngets.split.each{|e|h[e.to_i]+=1}\nr=n*(n-1)/2\nh.each{|k,v|r-=v*(v-1)/2}\np r\n"}, {"source_code": "n,m = gets.split(\" \").map {|x| x.to_i }\na = gets.split(\" \").map{|x| x.to_i}\nb = Array.new(m, 0)\n\nremain = n\na.each do |x|\n b[x-1] += 1\nend\n\nresult = 0\nb.each do |x|\n remain -= x\n result += remain* x\nend\n\nputs result"}, {"source_code": "n, m = gets.chomp.split(\" \").map(&:to_i)\nbooks = gets.chomp.split(\" \").map(&:to_i)\ndic = Hash.new(0)\nres = 0\nbooks.each do |k|\n dic[k] += 1\nend\n(1..m).to_a.combination(2) do |i, j|\n res += dic[i] * dic[j]\nend\nputs res\n"}, {"source_code": "n, m = gets.split(' ')\narray = gets.split(' ')\nsta = Array.new(m.to_i, 0)\nfor item in array\n sta[item.to_i - 1] += 1\nend\nans = 0\nfor i in 0..m.to_i-1\n for j in i+1..m.to_i-1\n ans += sta[i] * sta[j]\n end\nend\nputs ans\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nbooks = gets.split.map(&:to_i)\ngenre = Array.new(m)\nfor book in books\n if genre[book] == nil\n genre[book] = 1\n else\n genre[book] += 1\n end\nend\n\ncount = 0\nfor i in (1..m-1)\n for j in (i+1..m)\n count += genre[i] * genre[j]\n end\nend\n\nputs count\n"}, {"source_code": "# http://codeforces.com/problemset/problem/378/B\nn, m = gets.chomp.split.map(&:to_i)\n\nlist = gets.chomp.split.map(&:to_i)\nhash = Hash.new { |hash, key| hash[key] = 0 }\n\nfor i in 0..(list.length - 1)\n hash[list[i]] += 1\nend\n\nnew_list = hash.values\nresult = 0\nfor i in 0..(new_list.length - 1)\n for j in (i+1)..(new_list.length - 1)\n result += new_list[j] * new_list[i]\n end\nend\n\nputs result\n"}, {"source_code": "h=Hash.new(0)\nn=gets.to_i\ngets.split.each{|e|h[e.to_i]+=1}\nr=n*(n-1)/2\nh.each{|k,v|r-=v*(v-1)/2}\np r\n"}, {"source_code": "\nn = 0\nm = Array.new\n\nargs = gets.chomp.split(/ /)\nm = args.last.to_i\n\ngenre = Array.new\nfor i in 0..m do genre[i] = 0 end\n\narr = gets.chomp.split(/ /)\narr.each {|el| genre[el.to_i - 1] = genre[el.to_i - 1] + 1}\n\ns = genre[0]\nans = 0\nfor i in 1..m do\n\tans = ans + s * genre[i]\n\ts = s + genre[i];\nend\n\nprint ans"}, {"source_code": "h=Hash.new(0)\nn=gets.to_i\ngets.split.each{|e|h[e.to_i]+=1}\nr=n*(n-1)/2\nh.each{|k,v|r-=v*(v-1)/2}\np r\n"}, {"source_code": "h=Hash.new(0)\nn=gets.to_i\ngets.split.each{|e|h[e.to_i]+=1}\nr=n*(n-1)/2\nh.each{|k,v|r-=v*(v-1)/2}\np r\n"}], "negative_code": [], "src_uid": "e2ff228091ca476926b8e905f1bc8dff"} {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nif n == 1\n puts \"1 1\\n\", -a[0], \"\\n1 1\\n0\\n1 1\\n0\"\nelse\n print \"1 \", n, \"\\n\"\n (0...n - 1).each do |i|\n print -a[i] * n, \" \"\n end\n print \"0\\n1 \", n - 1, \"\\n\"\n (0...n - 1).each do |i|\n print a[i] * (n - 1), \" \"\n end\n print \"\\n\", n, \" \", n, \"\\n\", -a[-1], \"\\n\"\nend", "positive_code": [{"source_code": "n=gets.to_i\na=gets.split(\" \").map(&:to_i)\n\nif n == 1\n puts \"1 1\"\n puts \"0\"\n puts \"1 1\"\n puts \"0\"\n puts \"1 1\"\n puts -a[0]\n exit\nend\n# a2 = a.dup\n\nc = []\nb = []\n(n-1).times do |i|\n c[i] = a[i]*(n-1)\n b[i] = -a[i]*n\n\n # a2[i] += c[i] + b[i]\nend\nb[n-1] = 0\n\n# a2[n-1] += -a[n-1]\n\nputs \"1 #{n}\"\nputs b.join(\" \")\nputs \"1 #{n-1}\"\nputs c.join(\" \")\nputs \"#{n} #{n}\"\nputs -a[n-1]\n\n\n# p a2\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map(&:to_i)\nif n != 1\n puts \"1 #{n}\"\n n.times do |i|\n v = ((n-1) - a[i] % (n-1)) * n\n a[i] += v\n print \"#{v} \"\n end\n puts \"\"\n puts \"1 #{n-1}\"\n (n-1).times do |i|\n print \"#{-a[i]} \"\n end\n puts \"\"\n puts \"#{n} #{n}\"\n puts -a[n-1]\nelse\n puts \"1 1\"\n puts -a[0]\n puts \"1 1\"\n puts \"0\"\n puts \"1 1\"\n puts \"0\"\nend"}], "negative_code": [{"source_code": "n=gets.to_i\na=gets.split(\" \").map(&:to_i)\n# a2 = a.dup\n\nc = []\nb = []\n(n-1).times do |i|\n c[i] = a[i]*(n-1)\n b[i] = -a[i]*n\n\n # a2[i] += c[i] + b[i]\nend\nb[n-1] = 0\n\n# a2[n-1] += -a[n-1]\n\nputs \"1 #{n}\"\nputs b.join(\" \")\nputs \"1 #{n-1}\"\nputs c.join(\" \")\nputs \"#{n} #{n}\"\nputs -a[n-1]\n\n\n# p a2\n"}], "src_uid": "d15a758cfdd7a627822fe8be7db4f60b"} {"source_code": "\n# Print cardiogram given 2d array\ndef print_cardiogram(out)\n for i in 0..(out.length - 1) do\n puts out[i].join(\"\")\n end\nend\n\n# Read Input\nn = gets.strip.to_i\na = gets.strip.split.map{|s| s.to_i}\n\n# Find output size and starting point\nhd = 0; pp = 0; pn = 0; w = 0;\nfor i in 0..(a.length - 1) do \n if i.even?\n hd = hd + a[i]\n pp = hd if hd > pp\n else\n hd = hd - a[i]\n pn = hd if hd < pn\n end\n w = w + a[i]\nend\nh = [pp,0].max - [pn,0].min \ny = pp - 1; x = 0;\n\n# Create out array\nout = Array.new(h) {Array.new(w){\" \"}}\n\n# Fill out array\nfor i in 0..(a.length - 1) do\n for j in 1..a[i] do\n if i.even?\n out[y][x] = \"/\"\n y = y - 1 if j < a[i]\n else\n out[y][x] = \"\\\\\"\n y = y + 1 if j < a[i]\n end\n x = x + 1\n end\nend\n\n# Print cardiogram\nprint_cardiogram(out)", "positive_code": [{"source_code": "\n\nn = gets.to_i\ntab = gets.split.map(&:to_i)\n\ncoords = [[0,0]]\n\n(0..tab.size-1).each do |i|\n if i % 2 == 0\n coords << [coords[i][0] + tab[i], coords[i][1] + tab[i]]\n else\n coords << [coords[i][0] + tab[i], coords[i][1] - tab[i]]\n end\nend\n\n\nx = coords.map{|a| a[0]}\ny = coords.map{|a| a[1]}\n\nx_diff = x.max\ny_diff = y.max - y.min\n\nzero = y.max\n\ncoords.map!{|x| [x[0], zero-x[1]]}\n\nresult = []\n(y_diff+1).times do\n result << [' '] * x_diff\nend\n\n\n\n(0..coords.size-2).each do |i|\n if i % 2 == 0\n temp = 0\n while coords[i][0] + temp != coords[i+1][0]\n result[coords[i][1]-temp][coords[i][0]+temp] = \"/\"\n temp += 1\n end\n else\n temp = 0\n while coords[i][0] + temp != coords[i+1][0]\n result[coords[i][1]+temp+1][coords[i][0]+temp] = \"\\\\\"\n temp += 1\n end\n end\n\nend\n\n\nresult[1..-1].each do |row|\n puts row.join(\"\")\nend\n\n\n"}], "negative_code": [], "src_uid": "76285a60c21538db17d268a5e06c2270"} {"source_code": "$stdin = File.open(\"input.txt\", \"r\")\n$stdout = File.open(\"output.txt\", \"w\")\nn = gets.to_i\ns = gets\nones = (0...n).select{|pos| s[pos]==\"1\"}\ndiff = ones.map.with_index(1){|e,i| ones[i]-e if ones[i]}.compact\nputs (diff.all?{|x| x == diff[0]} ? \"YES\" : \"NO\")\n", "positive_code": [{"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/\\n0*1(0*1)?\\1*0*$/?:YES: :NO\n\n"}, {"source_code": "File.open('input.txt', 'r') do |inp|\n\tFile.open('output.txt', 'w') do |out|\n\t\ta = inp.readlines[1].chars.to_a.each_with_index.reduce([]) { |s, (x, i)| s <<= i if x == '1'; s }\n\t\tout.write %w[YES NO][Array(1...a.length).reduce([]) { |s, x| s << a[x] - a[x - 1] }.sort.uniq.length == 1 ? 0 : 1]\n\tend\nend"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/\\n0*1(0*1)?\\1*0*$/?:YES: :NO\n"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/\\n0*1(0*1)?\\1*0*$/?:YES: :NO\n\n"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/\\n0*1(0*1)?\\1*0*$/?:YES: :NO\n"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/\\n0*1(0*1)?\\1*0*$/?:YES: :NO\n\n"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/\\n0*1(0*1)?\\1*0*$/?:YES: :NO\n\n"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/\\n0*1(0*1)?\\1*0*$/?:YES: :NO\n\n"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/\\n0*1(0*1)?\\1*0*$/?:YES: :NO"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/\\n0*1(0*1)?\\1*0*$/?:YES: :NO\n\n"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/\\n0*1(0*1)?\\1*0*$/?:YES: :NO\n\n"}, {"source_code": "f,g=open(\"input.txt\",\"r\"),open(\"output.txt\",\"w\")\nf.gets\ng.puts(f.gets[/1.+1/].chop.scan(/10*/).map(&:size).uniq.size<2 ? \"YES\" : \"NO\")\nf.close\ng.close"}, {"source_code": "a, b = [], []\nopen('input.txt').read.split(\"\\n\")[1].each_char.with_index { |c, i| a.push i if c == \"1\" }\na[0].step(a[-1], a[1] - a[0]) { |e| b.push << e }\nopen('output.txt','w').print a == b ? :YES : :NO"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/\\n0*1(0*1)?\\1*0*$/?:YES: :NO\n\n"}], "negative_code": [{"source_code": "a, b = [], []\np STDIN.read.split(\"\\n\")[1]"}, {"source_code": "File.open('input.txt').each { |line|\n puts line\n}"}, {"source_code": "File.open('input.txt').each { |line|\n open('output.txt','w').puts line\n}"}, {"source_code": "a, b = [], []; gets\n#test\n# gets.strip.each_char.with_index { |c, i| a.push i if c == \"1\" }\n#a[0].step(a[-1], a[1] - a[0]) { |e| b.push << e }\n#print a == b ? :YES : :NO\n"}, {"source_code": "puts RUBY_VERSION"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/^[^1]*1(0*1)?\\1*0*$/?:YES: :NO\n"}, {"source_code": "open('output.txt','w').puts open('input.txt').gets(p)=~/^[^1]*(10*)\\1*0*$/?:YES: :NO\n"}], "src_uid": "4fc1ca3517168842cc85d74ba0066598"} {"source_code": "t = gets.to_i\n\nt.times do\n n = gets.to_i\n a = gets.split.map &:to_i\n n.times do |i|\n b = gets.chomp\n a[i] = (a[i] + b.count('D') - b.count('U')) % 10\n end\n puts a*' '\nend\n", "positive_code": [{"source_code": "gets.to_i.times {\n\tn = gets.to_i\n\tk = gets.split.map(&:to_i)\n\tn.times { |x|\n\t\tm, ud = gets.split\n\t\tu = ud.chars.count {|x| x == 'U'}\n\t\td = m.to_i - u\n\t\tprint (k[x] - u + d)%10, ' '\n\t}\n\tputs ''\n} "}, {"source_code": "def cypher(n, str, a)\n i = 0\n res = a\n while n-1 >= 0\n if str[i] == \"D\"\n res += 1\n else\n res -= 1\n end\n n -= 1\n i += 1\n end\n res % 10\nend\nt = gets.chomp.to_i\nfinal = []\n\n(0..t-1).each do |i|\n inputs = []\n x = 0\n n = gets.chomp.to_i\n arr = gets.chomp\n arr = arr.split(\" \").map(&:to_i)\n\n (0..n-1).each do |j|\n combination = gets.chomp\n combination = combination.split(\" \")\n combination.push(arr[x])\n inputs.push(combination)\n x+=1\n end\n final.push(inputs)\nend\n\nfinal.each do |input|\n ans = \"\"\n input.each do |i|\n x = cypher(i[0].to_i, i[1], i[2])\n ans += \"#{x} \"\n end\n\n puts ans.strip\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\n# https://codeforces.com/contest/1703/problem/C\n\nt = gets.chomp.to_i # tests\n\n(1..t).each do |numtest|\n n = gets.chomp.to_i # wheels\n l = gets.chomp # final state\n state = l.split(' ').map(&:to_i)\n #puts \"final state=#{state}\"\n (0..n-1).each do |numwheel|\n #puts \"numwheel=#{numwheel}\"\n m = gets.chomp\n pm = m.split(' ')\n #puts \"pm=#{pm}\"\n (0..pm[0].to_i-1 ).each do |i|\n #puts \"i=#{i}\"\n if pm[1][i] == 'U'\n state[numwheel] = state[numwheel] == 0 ? 9 : state[numwheel] - 1\n elsif pm[1][i] == 'D'\n state[numwheel] = state[numwheel] == 9 ? 0 : state[numwheel] + 1\n else\n echo \"Problem with character #{i} that is #{pm[1][i]}\"\n exit 1;\n end\n #puts \"state=#{state}\"\n end\n end\n puts state.join(' ')\n\nend\n\n\n"}], "negative_code": [], "src_uid": "fd47f1eb701077abc5ec67163ad4fcc5"} {"source_code": "gets.to_i.times do\n n, k = gets.split(' ').map(&:to_i)\n word = gets.chomp\n\n changes_count = 0 \n letter_count = {}\n\n i = 0\n if k > 1\n while i < k/2 do\n j = 0\n while i+k*j < n-1 \n letter_count[word[i+k*j]].nil? ?\n letter_count[word[i+k*j]] = 1 :\n letter_count[word[i+k*j]] += 1\n\n letter_count[word[k-1-i+k*j]].nil? ?\n letter_count[word[k-1-i+k*j]] = 1 :\n letter_count[word[k-1-i+k*j]] += 1\n\n j += 1\n end\n changes_count += (n/k)*2 - letter_count.values.max\n\n letter_count = {}\n i += 1\n end\n end\n\n if k % 2 == 1\n letter_count = {}\n i = k / 2\n j = 0\n while i + k * j < n\n letter_count[word[i+k*j]].nil? ?\n letter_count[word[i+k*j]] = 1 :\n letter_count[word[i+k*j]] += 1\n\n j+= 1\n end\n changes_count += (n/k) - letter_count.values.max\n end\n\n puts changes_count\nend", "positive_code": [{"source_code": "gets.to_i.times do\n n, k = gets.split(' ').map(&:to_i)\n word = gets.chomp\n \n changes_count = 0 \n i = 0\n\n while i < k/2 do\n letter_count = Hash.new(0)\n j = 0\n\n while j < n/k\n letter_count[word[i+k*j]] += 1\n letter_count[word[k-1-i+k*j]] += 1\n j += 1\n end\n\n changes_count += (n/k)*2 - letter_count.values.max\n i += 1\n end\n\n if k % 2 == 1\n letter_count = Hash.new(0)\n i, j = k/2, 0\n\n while j < n/k\n letter_count[word[i+k*j]] += 1\n j+= 1\n end\n\n changes_count += (n/k) - letter_count.values.max\n end\n\n puts changes_count\nend"}, {"source_code": "t = gets.to_i\nt.times do\n n, k = gets.split.map(&:to_i)\n s = gets.chomp\n count = 0\n for i in 0...(k / 2) do\n hash = Hash.new(0)\n for j in 0...(n / k) do\n hash[s[i + k * j]] += 1\n hash[s[k - 1 - i + k * j]] += 1\n end\n count += (n / k * 2) - hash.values.max\n end\n if k % 2 == 1\n hash = Hash.new(0)\n for j in 0...(n / k) do\n hash[s[k / 2 + k * j]] += 1\n end\n count += (n / k) - hash.values.max\n end\n puts count\nend\n"}], "negative_code": [{"source_code": "gets.to_i.times do\n n, k = gets.split(' ').map(&:to_i)\n word = gets.chomp\n\n changes_count = 0 \n letter_count = {}\n\n i = 0\n if k > 1\n while i < k/2 do\n j = 0\n while i+k*j < n-1 \n letter_count[word[i+k*j]].nil? ?\n letter_count[word[i+k*j]] = 1 :\n letter_count[word[i+k*j]] += 1\n\n letter_count[word[k-1-i+k*j]].nil? ?\n letter_count[word[k-1-i+k*j]] = 1 :\n letter_count[word[k-1-i+k*j]] += 1\n\n j += 1\n end\n changes_count += (n/k)*2 - letter_count.values.max\n\n letter_count = {}\n i += 1\n end\n end\n\n if k % 2 == 1\n letter_count = {}\n i = k / 2\n j = 0\n while i + k * j < n-1\n letter_count[word[i+k*j]].nil? ?\n letter_count[word[i+k*j]] = 1 :\n letter_count[word[i+k*j]] += 1\n j+= 1\n end\n changes_count += (n/k) - letter_count.values.max\n end\n\n puts changes_count\nend"}], "src_uid": "22f90afe503267ff2c832430d3ffb3b4"} {"source_code": "n,r=gets.split.map &:to_i;p n*r**2*Math.sin(Math::PI/n)*Math.cos(Math::PI*(n/2)/n)/Math.cos(Math::PI*(n/2-1)/n)\n", "positive_code": [{"source_code": "n,r=gets.split.map &:to_i;p n*r**2*Math.sin(Math::PI/n)*Math.cos(Math::PI*(n/2)/n)/Math.cos(Math::PI*(n/2-1)/n)"}, {"source_code": "n,r=gets.split.map &:to_i;p n*r**2*Math.sin(Math::PI/n)*Math.cos(Math::PI*(n/2)/n)/Math.cos(Math::PI*(n/2-1)/n)\n"}, {"source_code": "n,r=gets.split.map &:to_i;p n*r**2*Math.sin(Math::PI/n)*Math.cos(Math::PI*(n/2)/n)/Math.cos(Math::PI*(n/2-1)/n)"}], "negative_code": [], "src_uid": "fd92081afd795789b738009ff292a25c"} {"source_code": "S = gets.chomp.chars\nN = S.size\n\ndef f(n)\n return [] if n == 0\n\n left_pos = []\n left_cnt = 0\n\n 0.upto(N - 1) do |i|\n s = S[i]\n\n if left_cnt < n && s == '('\n left_pos << i + 1\n left_cnt += 1\n end\n\n break if left_cnt == n\n end\n\n right_pos = []\n right_cnt = 0\n\n (N - 1).downto(0) do |i|\n s = S[i]\n\n if right_cnt < n && s == ')'\n right_pos.unshift(i + 1)\n right_cnt += 1\n end\n\n break if right_cnt == n\n end\n\n if left_cnt < n || right_cnt < n\n return false\n elsif left_pos[-1] > right_pos[0]\n return false\n else\n left_pos + right_pos\n end\nend\n\nok = 0\nng = S.size\n\nwhile (ok - ng).abs > 1\n n = (ok + ng) / 2\n\n if f(n)\n ok = n\n else\n ng = n\n end\nend\n\nif ok == 0\n puts 0\nelse\n res = f(ok)\n\n puts 1\n puts res.size\n puts res.join(' ')\nend\n\n", "positive_code": [{"source_code": "def main\n s = gets.chomp.chars\n n = s.size\n # scan '(' from left and ')' from right\n left = 0\n right = n-1\n cnt = 0\n l_a = []\n r_a = []\n while (right > left)\n while left < n && s[left] != '('\n left += 1\n end\n # Here, s[left] == '(' or left == n\n while right >= 0 && s[right] != ')'\n right -= 1\n end\n # Here, s[right] == ')' or right == -1\n\n if (right <= left) # Meet\n break\n end\n \n cnt += 1\n l_a << left + 1 # 1-indexed\n r_a << right + 1 # 1-indexed\n left += 1\n right -= 1\n end\n # Here, right <= left. cnt contains the result\n if cnt > 0\n p 1\n p cnt * 2\n a = l_a + r_a\n a.sort!\n print a.join(\" \") + \"\\n\"\n else\n p 0\n end\nend\n\nmain\n"}, {"source_code": "s = gets.chomp\nout = []\ni = 0;\nj = s.size - 1;\nwhile j > i do\n if s[i] == '(' && s[j] == ')'\n out << [i, j]\n i += 1\n j -= 1\n elsif s[i] == '('\n j -= 1\n elsif s[j] == ')'\n i += 1\n else\n i += 1\n j -= 1\n end\nend\nif out.size.zero?\n puts 0\nelse\n puts 1\n out.flatten!.sort!\n puts out.size\n puts out.map{|x| x + 1}.join(' ')\nend\n"}], "negative_code": [{"source_code": "def main\n s = gets.chomp.chars\n n = s.size\n # scan '(' from left and ')' from right\n left = 0\n right = n-1\n cnt = 0\n l_a = []\n r_a = []\n while (right > left)\n while left < n && s[left] != '('\n left += 1\n end\n # Here, s[left] == '(' or left == n\n while right >= 0 && s[right] != ')'\n right -= 1\n end\n # Here, s[right] == ')' or right == -1\n\n if (right <= left) # Meet\n break\n end\n \n cnt += 1\n l_a << left + 1 # 1-indexed\n r_a << right + 1 # 1-indexed\n left += 1\n right -= 1\n end\n # Here, right <= left. cnt contains the result\n if cnt > 0\n p 1\n p cnt * 2\n print (l_a + r_a).join(\" \") + \"\\n\"\n else\n p 0\n end\nend\n\nmain\n"}], "src_uid": "f78d04f699fc94103e5b08023949854d"} {"source_code": "p = gets.chomp\nia = Array.new()\nprev = 0\np.each_byte{|a|\n b = sprintf(\"%08b\", a).reverse.to_i(2)\n c = (prev - b) % 256\n ia.push(c)\n prev = b\n}\nia.each{|i|\n puts i\n}\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\ndef readNextValues\n gets.split.map {|x| x.to_i}\nend\n\nline = gets.chomp\nprev_byte = 0\n\nline.each_byte do |b|\n bin = sprintf(\"%08b\", b)\n val = bin.reverse.to_i(2)\n\n bin2 = sprintf(\"%08b\", prev_byte)\n step2 = bin2.reverse.to_i(2)\n\n n = (step2 - val) % 256\n puts n\n\n prev_byte = b\nend\n"}, {"source_code": "s = STDIN.gets.strip\ns = s.bytes.to_a\ns.collect!{|char| char.to_s(2)}\ns.collect! do |str|\n str = Array.new(8-str.size, \"0\").join + str\nend\nresult = 0\ns.each do |str|\n temp = str.reverse.to_i(2) \n p (result - temp) % 256\n result = temp\nend"}, {"source_code": "s = gets.strip\na = 0\ns.each_char do |c|\n b = c.bytes.to_a[0].to_s(2)\n b = \"0\" * (8-b.size) + b if b.size < 8\n n = 0\n p = 1\n b.each_char do |cc|\n n += p if cc == \"1\"\n p *= 2\n end\n p ((a - n) % 256)\n a = n\nend\n"}, {"source_code": "s=gets.chomp\npre=0\ns.bytes.each{|b|post=(\"%08b\"%b).reverse.to_i(2);puts (pre-post)%256;pre=post}"}, {"source_code": "def to_bin n\n\tstr=\"\"\n\t\n\twhile n!=0\n\t\tstr+=(n%2).to_s\n\t\tn/=2\n\tend\n\t\n\tstr+\"0\"*(8-str.length)\nend\n\ndef to_ten bin\n\tpos=bin.length-1\n\tpow=0\n\t\n\tans=0\n\twhile pos>-1\n\t\tans+=(bin[pos].to_i)*2**pow\n\t\t\n\t\tpow+=1\n\t\tpos-=1\n\tend\n\t\n\tans\nend\n\nline=gets.strip\n\nstart=0\ndata=[]\nline.split(//).each{|c|\n\tcode=to_ten(to_bin(c.ord))\n\t\n\tdata << (start-code)%256\n\tstart=code\n}\n\nputs data\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\ndef revbin(c)\n c.ord.to_s(2).rjust(8, '0').reverse.to_i(2)\nend\nM = 256\n\ns = $stdin.gets.chomp\ns.chars.inject(0) do |acc, c|\n n = revbin c\n puts ((acc - n) % M)\n n\nend\n"}, {"source_code": "p = gets.chomp\nprev = 0\np.each_byte{|l|\n cur = l.ord.to_s(2)\n cur = \"0\"*(8 - cur.length)+cur\n cur = cur.reverse.to_i(2)\n res = (prev - cur) % 256\n prev = cur\n puts res\n}\n"}, {"source_code": "a = []\nn = gets.to_s.chomp\na = n.split(\"\").map(&:to_s)\nn = 0\nj = 0\nfor i in a do\n n = i.ord.to_s(2).rjust(8,\"0\").reverse.to_i(2)\n puts (j-n) % 256\n j = n\nend"}, {"source_code": "s=gets.chomp\npre=0\ns.bytes.each{|b|post=(\"%08b\"%b).reverse.to_i(2);puts (pre-post)%256;pre=post}"}, {"source_code": "def gao(_)\n ('%08b' % _).reverse.to_i(2)\nend\n\ns = gets.chomp\nx = 0\ns.each_byte do |b|\n y = (gao(x) - gao(b)) % 256\n p y\n x = gao((gao(x) - y) % 256)\nend\n"}, {"source_code": "s=gets.chomp\nx=0\ns.each_byte{|c|\n\ty=(\"%08b\"%c).reverse.to_i(2);\n\tp x-y&255\n\tx=y\n}"}, {"source_code": "s=gets.chomp\nx=0\ns.each_byte{|c|\n y=(\"%08b\"%c).reverse.to_i(2);\n p x-y&255\n x=y\n}"}, {"source_code": "def to_bin n\n str=\"\"\n \n while n!=0\n str+=(n%2).to_s\n n/=2\n end\n \n str+\"0\"*(8-str.length)\nend\n\ndef to_ten bin\n pos=bin.length-1\n pow=0\n \n ans=0\n while pos>-1\n ans+=(bin[pos].to_i)*2**pow\n \n pow+=1\n pos-=1\n end\n \n ans\nend\n\nline=gets.strip\n\nstart=0\ndata=[]\nline.split(//).each{|c|\n code=to_ten(to_bin(c.ord))\n \n data << (start-code)%256\n start=code\n}\n\nputs data"}, {"source_code": "s=gets.chomp\nx=0\ns.each_byte{|c|\n\ty=(\"%08b\"%c).reverse.to_i(2);\n\tp x-y&255\n\tx=y\n}"}, {"source_code": "s = gets.bytes\n\ndef d(x)\n xs = x.to_s(2)\n xs.insert(0,'0') while xs.size < 8\n 4.times { |i| xs[7-i], xs[i] = xs[i], xs[7-i] }\n xs.to_i(2)\nend\n\ns.size.pred.times do |i|\n x = i.zero? ? 0 : s[i-1]\n y = s[i]\n puts (d(x) - d(y)) % 256\nend\n"}, {"source_code": "s = gets.chomp\nv = 0\ns.each_byte do |c| \n x1 = (\"%08b\"%v).reverse.to_i(2)\n r = (\"%08b\"%c).reverse.to_i(2)\n x2 = (x1 - r + 256)%256\n\n p x2\n v = c\nend\n"}, {"source_code": "str=gets.chomp;\nv=0;\nstr.each_byte do |c|\n\tp (v-(\"%08b\"%c).reverse.to_i(2)+256)%256;\n\tv=(\"%08b\"%c).reverse.to_i(2);\nend\n\n"}, {"source_code": "#!/usr/bin/ruby\nwhile l = STDIN.gets\n prev = 0\n l.chomp.each_byte do |c|\n str = c.to_s(2)\n while str.size < 8\n str = \"0\" + str\n end\n str.reverse!\n v = (prev - str.to_i(2)) % 256\n prev = str.to_i(2)\n p v\n end\nend \n"}, {"source_code": "# def gray_code(n)\n\t# a = ['0', '1']\n\t# until a[0].length == n do\n\t\t# a = a.map{|i| '0' + i} + a.reverse.map{|i| i + '1'}\n\t# end\n\t# return a\n# end\n\n# puts gray_code(3)\n\n# require 'set'\n# visited = Set.new\n# Dir.chdir \"..\"\n# stack = Array.new\n# stack.push(\"mine\")\n# until stack.length == 0 do\n\t# dir = false\n\t# Dir.chdir stack.pop\n\t\n\t# puts Dir.pwd\n\t# Dir[\"*\"].each do |f|\n\t\t# print \"File: \", f, \"\\n\" if File.file?(f)\n\t\t# if (File.directory?(f) && visited.include?(Dir.pwd + \"/\" + f) == false) then\n\t\t\t# print \"Directory: \", f, \"\\n\"\n\t\t\t# stack.push(f) if File.directory?(f)\n\t\t\t# dir = true\n\t\t\t# break\n\t\t# end\n\t# end\n\t# if dir == false then\n\t\t# visited.add(Dir.pwd)\n\t\t# Dir.chdir \"..\"\n\t# end\n\t# puts Dir.pwd\n# end\n# puts \"\\nCompleted\"\n\ninp = STDIN.gets.chomp\nstart = 0\ninp.each_byte do |ch|\n\tbin = ch.to_s(2).rjust(8, '0').reverse.to_i(2).to_s(10).to_i\n\tputs (start - bin) % 256\n\tstart = bin\nend\n\n"}, {"source_code": "#!/usr/bin/ruby\n#coding:utf-8\n\nSTR=gets.chomp\nlast=0\nsiz=STR.bytes.to_a.size\nplease=(siz+3)/4-2\nSTR.each_byte.with_index{|e,i|\n\tc = e\n\tc = (c & 0x55) << 1 | (c & 0xaa) >> 1\n\tc = (c & 0x33) << 2 | (c & 0xcc) >> 2\n\tc = (c & 0x0f) << 4 | (c & 0xf0) >> 4\n\tlast2 = c\n\tc = (last-c)&0xff\n\tlast = last2\n\tp c&0xff\n}\n\n__END__\n[cesspool.c]\nunsigned int lastout = 0;\nc = lastout - a[i];\nlastout = c;\nc = (c & 0x0f) << 4 | (c & 0xf0) >> 4;\nc = (c & 0x33) << 2 | (c & 0xcc) >> 2;\nc = (c & 0x55) << 1 | (c & 0xaa) >> 1;\nputchar(c);"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nwhile l = STDIN.gets\n prev = 0\n l.each_byte do |c|\n str = c.to_s(2)\n while str.size < 8\n str = \"0\" + str\n end\n str.reverse!\n v = (prev - str.to_i(2)) % 256\n prev = str.to_i(2)\n p v\n end\nend \n"}, {"source_code": "#!/usr/bin/ruby\n#coding:utf-8\n\nSTR=STDIN.read\nlast=0\nsiz=STR.bytes.to_a.size\nplease=(siz+3)/4-2\nSTR.each_byte.with_index{|e,i|\n\tc = e\n\tc = (c & 0x55) << 1 | (c & 0xaa) >> 1\n\tc = (c & 0x33) << 2 | (c & 0xcc) >> 2\n\tc = (c & 0x0f) << 4 | (c & 0xf0) >> 4\n\tlast2 = c\n\tc = (last-c)&0xff\n\tlast = last2\n\tp c&0xff\n}\n\n__END__\n[cesspool.c]\nunsigned int lastout = 0;\nc = lastout - a[i];\nlastout = c;\nc = (c & 0x0f) << 4 | (c & 0xf0) >> 4;\nc = (c & 0x33) << 2 | (c & 0xcc) >> 2;\nc = (c & 0x55) << 1 | (c & 0xaa) >> 1;\nputchar(c);"}, {"source_code": "s = STDIN.gets\ns = s.bytes.to_a\ns.collect!{|char| char.to_s(2)}\ns.collect! do |str|\n str = Array.new(8-str.size, \"0\").join + str\nend\nresult = 0\ns.each do |str|\n temp = str.reverse.to_i(2) \n p (result - temp) % 256\n result = temp\nend"}, {"source_code": "s = STDIN.gets\ns = s.bytes.to_a\ns.collect!{|char| char.to_s(2)}\ns.collect! do |str|\n str = Array.new(8-str.size, \"0\").join + str\nend\nresult = 0\ns.push\ns.each do |str|\n temp = str.reverse.to_i(2) \n p (result - temp) % 256\n result = temp\nend"}], "src_uid": "a65e12186430f74c18c50d2eb55a9794"} {"source_code": "n = gets.to_i \n\na = gets.split.map{ |x| x.to_i }\nb = gets.split.map{ |x| x.to_i }\n\nc = Hash.new(0)\n\n\nd = Rational(5,6)\n#puts 4\n\nh = 0 \nk = 0\n\nfor i in 0...n \n if a[i]==0 \n if b[i]==0\n k=k+1\n end\n next\n end\n d = Rational((-b[i]), a[i])\n #puts d \n c[d] = c[d] + 1\n #puts c[d]\nend \n\nf = c.values \n\n\nf.each{ |a| h = (h>a)?h:a}\n\nputs h+k \n", "positive_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\ndef gcd(a,b)\n\treturn b if(a==0)\n\treturn gcd(b%a,a)\nend\n\n=begin\nint gcd(int a, int b) \n{ \n if (a == 0) \n return b; \n return gcd(b % a, a); \n} \n=end\n\nn = gets.to_i\na = gets.chomp.split(\" \").map(&:to_i)\nb = gets.chomp.split(\" \").map(&:to_i)\n\n#c = d*a+b\n#c needs to have 0s i.e. c = 0\n# d*a = c-b = 0-b\n# d = -b/a\n\nhash=Hash.new(0)\n\nzerocount=0\ntotcount=0\n\n(0..n-1).each do |i|\n\tmya = a[i]\n\tmyb = b[i]\n\n\tif(myb==0)\n\t\tif(mya==0)\n\t\t\ttotcount+=1\n\t\tend\n\t\tzerocount+=1\n\t\tnext\n\tend\n\n\tif(mya==0)\n\t\tnext\n\tend\n\n\tmygcd = gcd(mya,myb)\n\n\tmya/=mygcd\n\tmyb/=mygcd\n\n\n\thash[[mya,myb]]+=1\nend\n\nif hash.empty?\n\tputs zerocount\nelse\n\tputs [hash.values.max+totcount,zerocount].max\nend\n"}], "negative_code": [{"source_code": "n = gets.to_i \n\na = gets.split.map{ |x| x.to_i }\nb = gets.split.map{ |x| x.to_i }\n\nc = Hash.new(0)\n\n\nd = Rational(5,6)\n#puts 4\n\nfor i in 0...n \n if a[i]==0 \n next\n end\n d = Rational((-b[i]), a[i])\n #puts d \n c[d] = c[d] + 1\n #puts c[d]\nend \n\nf = c.values \n\nh = 0\n\nf.each{ |a| h = (h>a)?h:a}\n\nputs h \n"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\ndef gcd(a,b)\n\treturn b if(a==0)\n\treturn gcd(b%a,a)\nend\n\n=begin\nint gcd(int a, int b) \n{ \n if (a == 0) \n return b; \n return gcd(b % a, a); \n} \n=end\n\nn = gets.to_i\na = gets.chomp.split(\" \").map(&:to_i)\nb = gets.chomp.split(\" \").map(&:to_i)\n\n#c = d*a+b\n#c needs to have 0s i.e. c = 0\n# d*a = c-b = 0-b\n# d = -b/a\n\nhash=Hash.new(0)\n\ntotcount=0\n\n(0..n-1).each do |i|\n\tmya = a[i]\n\tmyb = b[i]\n\n\tif(myb==0)\n\t\ttotcount+=1\n\t\tnext\n\tend\n\n\tif(mya==0)\n\t\tnext\n\tend\n\n\tmygcd = gcd(mya,myb)\n\n\tmya/=mygcd\n\tmyb/=mygcd\n\n\n\thash[[mya,myb]]+=1\nend\n\nif hash.empty?\n\tputs totcount\nelse\n\tputs hash.values.max+totcount\nend\n"}], "src_uid": "c083988d20f434d61134f7b376581eb6"} {"source_code": "N = gets.to_i\ns = gets.chomp\nt = gets.chomp\nans = []\nN.times do |i|\n next if s[i] == t[i]\n j = ((i+1)...N).find{|k| s[k] == t[i]}\n if j\n (j-1).downto(i) do |k|\n ans.push(k+1)\n s[k, 2] = s[k, 2].reverse\n end\n else\n puts -1; exit\n end\nend\nputs ans.length\nputs ans.join(' ') if ans.length > 0", "positive_code": [{"source_code": "\ndef solution\n n = read_int\n s = read_string\n t = read_string\n\n if s.chars.sort != t.chars.sort\n puts \"-1\"\n return\n end\n\n tpos = Hash.new { |h, k| h[k] = [] }\n t.chars.each.with_index{ |c,i| tpos[c] << i }\n\n ss = {}\n s.chars.each.with_index{ |c, i| ss[i] = c }\n\n moves = []\n\n n.times do |i|\n next if ss[i] == t[i]\n\n j = (i+1...s.size).find{|k| ss[k] == t[i]}\n\n [*(i+1)..j].reverse.each do |k|\n moves << k\n ss[k], ss[k-1] = ss[k-1], ss[k]\n end\n end\n\n puts moves.size\n puts moves.join(' ')\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"}, {"source_code": "n = gets.to_i\ns = gets.strip\nt = gets.strip\n\ndef swp(str, i)\n c=str[i]\n str[i]=str[i+1]\n str[i+1]=c\nend\n\nans = []\n(n-1).downto(0).each do |ti|\n next if s[ti]==t[ti]\n si=ti-1\n si-=1 while si>=0 && s[si]!=t[ti]\n if si==-1\n puts \"-1\"\n exit 0\n end\n si.upto(ti-1).each do |i|\n swp(s, i)\n ans << (i+1)\n end\nend\n\nputs ans.size\nputs ans.join(\" \")"}, {"source_code": "gets\ns = gets.chomp.split('')\nt = gets.chomp.split('')\n\ncontainer = {}\ns.each do |item|\n if container.key?(item)\n container[item] += 1\n else\n container[item] = 1\n end\nend\n\nt.each do |item|\n container[item] -= 1 if container.key?(item)\nend\n\nif container.values.any? { |e| e != 0 }\n puts '-1'\nelse\n swaps = []\n t.each.with_index do |item, i|\n if item != s[i]\n j = s.rindex(item)\n k = j - 1\n while k != i - 1\n s[k], s[k + 1] = s[k + 1], s[k]\n swaps.push(k + 1)\n k -= 1\n end\n end\n end\n puts swaps.length\n puts swaps.join(' ') unless swaps.empty?\nend\n"}], "negative_code": [{"source_code": "gets\ns = gets.chomp.split('')\nt = gets.chomp.split('')\n\ncontainer = {}\ns.each do |item|\n if container.key?(item)\n container[item] += 1\n else\n container[item] = 1\n end\nend\n\nt.each do |item|\n container[item] -= 1 if container.key?(item)\nend\n\nif container.values.any? { |e| e != 0 }\n puts '-1'\nelse\n swaps = []\n s.each.with_index do |item, i|\n if item != t[i]\n j = t.rindex(item)\n k = j - 1\n while k != i - 1\n t[k], t[k + 1] = t[k + 1], t[k]\n swaps.push(k)\n k -= 1\n end\n end\n end\n puts swaps.length\n puts swaps.join(' ') unless swaps.empty?\nend\n"}, {"source_code": "gets\ns = gets.chomp.split('')\nt = gets.chomp.split('')\n\ncontainer = {}\ns.each do |item|\n if container.key?(item)\n container[item] += 1\n else\n container[item] = 1\n end\nend\n\nt.each do |item|\n container[item] -= 1 if container.key?(item)\nend\n\nif container.values.any? { |e| e != 0 }\n puts '-1'\nelse\n swaps = []\n s.each.with_index do |item, i|\n if item != t[i]\n j = t.rindex(item)\n k = j - 1\n while k != i - 1\n t[k], t[k + 1] = t[k + 1], t[k]\n swaps.push(k + 1)\n k -= 1\n end\n end\n end\n puts swaps.length\n puts swaps.join(' ') unless swaps.empty?\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\nt = gets.strip\n\ndef swp(str, i)\n c=str[i]\n str[i]=str[i+1]\n str[i+1]=c\nend\n\nans = []\n(n-1).downto(0).each do |ti|\n next if s[ti]==t[ti]\n si=ti-1\n si-=1 while si>=0 && s[si]!=t[ti]\n if si==-1\n puts \"-1\"\n exit 0\n end\n si.upto(ti-1).each do |i|\n swp(s, i)\n ans << i\n end\nend\n\nputs ans.size\nputs ans.join(\" \")"}], "src_uid": "48e323edc41086cae52cc0e6bdd84e35"} {"source_code": "n = gets.chomp.to_i\narStr = Array.new(n).map do |str|\n str = gets.chomp\nend\ni = 0\nwhile i != n\n if arStr[i][0..4] != 'miao.' && arStr[i][-5..-1] == 'lala.'\n puts \"Freda's\" \n elsif arStr[i][0..4] == 'miao.' && arStr[i][-5..-1] != 'lala.'\n puts \"Rainbow's\" \n else\n puts \"OMG>.< I don't know!\"\n end\n i += 1\nend", "positive_code": [{"source_code": "reF = Regexp.new( /lala\\.$/ )\nreR = Regexp.new( /^miao\\./ )\n\ngets.to_i.times do \n\tline = gets.chomp\n\tif ( reF =~ line && reR !~ line )\n\t\tputs \"Freda's\"\n\telsif ( reR =~ line && reF !~ line )\n\t\tputs \"Rainbow's\"\n\telse\n\t\tputs \"OMG>.< I don't know!\"\n\tend\nend\n"}, {"source_code": "\nans = []\ngets.to_i.times do\n s = gets.to_s.chomp\n if s[0..4] == 'miao.' && s[-5..-1] != 'lala.' then\n ans << 'Rainbow\\'s'\n elsif s[0..4] != 'miao.' && s[-5..-1] == 'lala.' then\n ans << 'Freda\\'s'\n else\n ans << 'OMG>.< I don\\'t know!'\n end\nend\nputs ans"}, {"source_code": "n = gets.to_i\nn.times do\n s = gets.gsub /\\r\\n|\\r|\\n/, ''\n is_f, is_r = false, false\n if s.length >= 5\n is_f = s[-5..-1] == 'lala.'\n is_r = s[0...5] == 'miao.'\n end\n if is_f and not is_r then\n puts \"Freda's\"\n elsif not is_f and is_r then\n puts \"Rainbow's\"\n else\n puts \"OMG>.< I don't know!\"\n end\nend\n"}, {"source_code": "\ngets.to_i.times do \n s = gets\n lala = /.*lala\\.$/.match s\n miao = /^miao\\..*/.match s\n if( (lala && miao) || (!lala && !miao) )\n puts \"OMG>.< I don't know!\"\n elsif lala\n puts \"Freda's\"\n else \n puts \"Rainbow's\"\n end\nend"}, {"source_code": "omg = \"OMG>.< I don't know!\"\nfreda = \"Freda's\"\nrainbow = \"Rainbow's\"\nrainbow_begin = /^miao\\./\nfreda_end = /lala\\.$/\n\nfor _ in 1..gets.to_i\n s = gets.chomp\n if s[rainbow_begin]\n puts(s[freda_end] ? omg : rainbow)\n elsif s[freda_end]\n puts freda\n else\n puts omg\n end\nend"}, {"source_code": "n = gets.to_i\nn.times do\n\ts = gets.chomp\n\tif s.length < 5\n\t\tputs \"OMG>.< I don't know!\"\n\telse\n\t\tR = s[0..4] == \"miao.\"\n\t\tF = s[-5..-1] == \"lala.\"\n\t\tif R == F\n\t\t\tputs \"OMG>.< I don't know!\"\n\t\telsif R\n\t\t\tputs \"Rainbow's\"\n\t\telse\n\t\t\tputs \"Freda's\"\n\t\tend\n\tend\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = gets.to_i\n\nn.times do |i|\n line = gets.chomp\n a = line.match(/^miao\\./)\n b = line.match(/lala\\.$/)\n\n if (a and b) or (not a and not b)\n puts \"OMG>.< I don't know!\"\n elsif line.start_with?(\"miao.\")\n puts \"Rainbow's\"\n elsif line.end_with?(\"lala.\")\n puts \"Freda's\"\n end\nend\n\n"}, {"source_code": "def myfun\nn = gets.chomp.to_i\nstr = Array.new\nfor i in 1..n\n str[i] = gets.chomp\nend\n\nfor i in 1..n\n if str[i].index('miao.') == 0 && str[i].rindex('lala.') != str[i].length - 5\n puts \"Rainbow's\"\n elsif str[i].index('miao.') != 0 && str[i].rindex('lala.') == str[i].length - 5\n puts \"Freda's\"\n else\n puts \"OMG>.< I don't know!\"\n end\nend\nreturn nil\nend\n\nputs myfun\n"}, {"source_code": "\nlines = STDIN.read.split(\"\\n\")\nn = lines[0].to_i\n\nfor i in 1..n \n line = lines[i]\n testA = line.rindex('lala.') == line.size - 5\n testB = line.index('miao.') == 0\n if testA && !testB\n puts \"Freda's\"\n next\n end\n if !testA && testB\n puts \"Rainbow's\"\n next\n end\n puts \"OMG>.< I don't know!\"\nend\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\nn.times do\n\tsentence = STDIN.readline[0..-2]\n\tmiao = (sentence[0..4] == 'miao.')\n\tlala = (sentence[-5..-1] == 'lala.')\n\tif miao and not lala\n\t\tputs \"Rainbow's\"\n\telsif lala and not miao\n\t\tputs \"Freda's\"\n\telse\n\t\tputs \"OMG>.< I don't know!\"\n\tend\nend\n\n"}, {"source_code": "input = STDIN.read.split(\"\\n\")\ninput.shift\ninput.each do |line|\n r = line[0, 5] == 'miao.'\n f = line[-5..-1] == 'lala.'\n if not r ^ f\n puts 'OMG>.< I don\\'t know!'\n elsif r\n puts 'Rainbow\\'s'\n else\n puts 'Freda\\'s'\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\n(1..n).each do\n str = gets.chomp\n r = (str[(0..4)] == \"miao.\")\n f = (str[(-5..-1)] == \"lala.\")\n puts \"OMG>.< I don't know!\" if ((f && r) || (!f && !r))\n puts \"Freda's\" if f && !r\n puts \"Rainbow's\" if r && !f\nend"}, {"source_code": "class A\n def initialize\n n = gets.chomp.to_i\n\n freda = 0\n rain = 0\n\n answer = []\n\n n.times do \n text = gets.chomp\n\n if text =~ /lala\\.$/ && (text =~ /^miao\\./).nil?\n answer << \"Freda's\"\n elsif text =~ /^miao\\./ && (text =~ /lala\\.$/).nil?\n answer << \"Rainbow's\"\n else\n answer << \"OMG>.< I don't know!\"\n end\n end\n\n puts answer\n end\nend\n\na = A.new"}, {"source_code": "a=gets.chomp.to_i\na.times do\ntemp=gets.chomp\nl=temp.length\nif temp[0..4]==\"miao.\" && temp[l-5..l-1]==\"lala.\"\n puts \"OMG>.< I don't know!\" \nelsif temp[0..4]==\"miao.\"\n puts \"Rainbow's\"\nelsif temp[l-5..l-1]==\"lala.\"\n puts \"Freda's\"\nelse \nputs \"OMG>.< I don't know!\"\nend\nend"}, {"source_code": "n = gets.to_i\n(1..n).each {\n s = gets.chomp\n f = s.end_with?(\"lala.\")\n r = (s[0..4] == \"miao.\")\n if f ^ r\n if f\n puts \"Freda's\"\n else\n puts \"Rainbow's\"\n end\n else\n puts \"OMG>.< I don't know!\"\n end\n}"}, {"source_code": "gets.to_i.times do\n\tinput = gets.chomp\n\n\tt = ( ( input =~(/.*lala\\.$/)) )\n\to = ( ( input =~(/^miao\\..*/)) )\n\n\tif (o and t) or (!o and !t)\n\t\tputs \"OMG>.< I don't know!\"\n\telsif o\n\t\tputs \"Rainbow's\" \n\telsif t\n\t\tputs \"Freda's\"\n\tend\nend\n"}, {"source_code": "n = gets.to_i\n(0...n).each do\n s = gets.chomp\n if s.size < 5\n puts \"OMG>.< I don't know!\"\n elsif s[0,5] == \"miao.\" and s[s.size-5,5] != \"lala.\"\n puts \"Rainbow's\"\n elsif s[0,5] != \"miao.\" and s[s.size-5,5] == \"lala.\"\n puts \"Freda's\"\n else\n puts \"OMG>.< I don't know!\"\n end\nend\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\narStr = Array.new(n).map do |str|\n str = gets.chomp\nend\ni = 0\nwhile i != n\n if arStr[i][0..5] != 'miao.' && arStr[i][-5..-1] == 'lala.'\n puts \"Freda's\" \n elsif arStr[i][0..5] == 'miao.' && arStr[i][-5..-1] != 'lala.'\n puts \"Rainbow's\" \n else\n puts \"OMG>.< I don't know!\"\n end\n i += 1\nend"}, {"source_code": "n = gets.chomp.to_i\narStr = Array.new(n).map do |str|\n str = gets.chomp\nend\ni = 0\nwhile i != n\n if arStr[i][0..5] == 'miao.' && arStr[i][-6...-1] != 'lala.'\n puts \"Rainbow's\" \n elsif arStr[i][0..5] != 'miao.' && arStr[i][-6...-1] == 'lala.'\n puts \"Freda's\"\n else\n puts \"OMG>.< I don't know!\"\n end\n i += 1\nend"}, {"source_code": "n = gets.chomp.to_i\narStr = Array.new(n).map do |str|\n str = gets.chomp\nend\ni = 0\nwhile i != n\n if arStr[i][0..5] == 'miao.' && arStr[i][-6...-1] != 'lala.'\n puts \"Freda's\"\n elsif arStr[i][0..5] != 'miao.' && arStr[i][-5...-1] == 'lala.'\n puts \"Rainbow's\"\n else\n puts \"OMG>.< I don't know!\"\n end\n i += 1\nend"}, {"source_code": "n = gets.chomp.to_i\narStr = Array.new(n).map do |str|\n str = gets.chomp\nend\ni = 0\nwhile i != n\n if arStr[i][0..5] != 'miao.' && arStr[i][-6...-1] == 'lala.'\n puts \"Freda's\" \n elsif arStr[i][0..5] == 'miao.' && arStr[i][-6...-1] != 'lala.'\n puts \"Rainbow's\" \n else\n puts \"OMG>.< I don't know!\"\n end\n i += 1\nend"}, {"source_code": "n = gets.chomp.to_i\narStr = Array.new(n).map do |str|\n str = gets.chomp\nend\ni = 0\nwhile i != n\n if arStr[i][0..5] != 'miao.' && arStr[i][-6..-1] == 'lala.'\n puts \"Freda's\" \n elsif arStr[i][0..5] == 'miao.' && arStr[i][-6..-1] != 'lala.'\n puts \"Rainbow's\" \n else\n puts \"OMG>.< I don't know!\"\n end\n i += 1\nend"}, {"source_code": "n = gets.chomp.to_i\narStr = Array.new(n).map do |str|\n str = gets.chomp\nend\ni = 0\nwhile i != n\n if arStr[i][0..5] == 'miao.' && arStr[i][-5...-1] != 'lala.'\n puts \"Freda's\"\n elsif arStr[i][0..5] != 'miao.' && arStr[i][-5...-1] == 'lala.'\n puts \"Rainbow's\"\n else\n puts \"OMG>.< I don't know!\"\n end\n i += 1\nend"}, {"source_code": "def myfun\nn = gets.chomp.to_i\nstr = Array.new\nfor i in 1..n\n str[i] = gets.chomp\n puts i\nend\n\nfor i in 1..n\n if str[i].index('miao.') == 0 && str[i].rindex('lala.') != str[i].length - 5\n puts \"Rainbow's\"\n elsif str[i].index('miao.') != 0 && str[i].rindex('lala.') == str[i].length - 5\n puts \"Freda's\"\n else\n puts \"OMG>.< I don't know!\"\n end\nend\nreturn nil\nend\n\nputs myfun\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\nn.times do\n\tsentence = STDIN.readline.strip\n\tmiao = (sentence[0..4] == 'miao.')\n\tlala = (sentence[-5..-1] == 'lala.')\n\tif miao and not lala\n\t\tputs \"Rainbow's\"\n\telsif lala and not miao\n\t\tputs \"Freda's\"\n\telse\n\t\tputs \"OMG>..< I don't know!\"\n\tend\nend\n\n"}, {"source_code": "n = gets.chomp.to_i\n(1..n).each do\n str = gets.chomp\n r = (str[(0..4)] == \"miao.\")\n f = (str[(-5..-1)] == \"lala.\")\n puts \"OMG>.< I don't know!\" if ((f && r) || (!f && !r))\n puts \"Freda's\" if f\n puts \"Rainbow's\" if r\nend"}, {"source_code": "n = gets.chomp.to_i\n(1..n).each do\n str = gets.chomp\n r = (str[(0..5)] == \"miao.\")\n f = (str[(-5..-1)] == \"lala.\")\n puts \"OMG>.< I don't know!\" if ((f && r) || (!f && !r))\n puts \"Freda's\" if f\n puts \"Rainbow's\" if r\nend"}, {"source_code": "n = gets.chomp.to_i\n(1..n).each do\n str = gets.chomp\n r = (str[(-5..-1)] == \"miao.\")\n f = (str[(-5..-1)] == \"lala.\")\n puts \"OMG>.< I don't know!\" if ((f && r) || (!f && !r))\n puts \"Freda's\" if f\n puts \"Rainbow's\" if r\nend"}, {"source_code": "class A\n def initialize\n n = gets.chomp.to_i\n\n freda = 0\n rain = 0\n\n answer = []\n\n n.times do \n text = gets.chomp\n\n if text =~ /lala\\.$/ && (text =~ /miao\\./).nil?\n answer << \"Freda's\"\n elsif text =~ /^miao\\./ && (text =~ /lala\\./).nil?\n answer << \"Rainbow's\"\n else\n answer << \"OMG>.< I don't know!\"\n end\n end\n\n puts answer\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n n = gets.chomp.to_i\n\n freda = 0\n rain = 0\n\n answer = []\n\n n.times do \n text = gets.chomp\n\n if text =~ /lala\\./ && (text =~ /miao\\./).nil?\n answer << \"Freda's\"\n elsif text =~ /miao\\./ && (text =~ /lala\\./).nil?\n answer << \"Rainbow's\"\n else\n answer << \"OMG>.< I don't know!\"\n end\n end\n\n puts answer\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n n = gets.chomp.to_i\n\n freda = 0\n rain = 0\n\n answer = []\n\n n.times do \n text = gets.chomp\n\n if text =~ /lala\\./\n answer << \"Freda's\"\n elsif text =~ /mial\\./\n answer << \"Rainbow's\"\n else\n answer << \"OMG>.< I don't know!\"\n end\n end\n\n puts answer\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n n = gets.chomp.to_i\n\n freda = 0\n rain = 0\n\n answer = []\n\n n.times do \n text = gets.chomp\n\n if text =~ /lala\\.$/ && (text =~ /miao\\./).nil?\n answer << \"Freda's\"\n elsif text =~ /^miao\\./ && (text =~ /lala\\./).nil?\n answer << \"Rainbow's\"\n else\n answer << \"OMG>.< I don't know!\"\n end\n end\n\n puts answer\n end\nend\n\na = A.new"}, {"source_code": "\n\nn = gets.to_i\n\n"}], "src_uid": "ee9ba877dee1a2843e885a18823cbff0"} {"source_code": "x1, y1 = STDIN.readline.split.map {|s| s.to_i }\nx2, y2 = STDIN.readline.split.map {|s| s.to_i }\n\nn = STDIN.readline.to_i\ncount = 0\n\nn.times do\n a, b, c = STDIN.readline.split.map {|s| s.to_i }\n if ((a*x1 + b*y1 + c) * (a*x2 + b*y2 + c) < 0)\n count += 1\n end\nend\n\nputs count", "positive_code": [{"source_code": "x1, y1 = gets.split.collect{|i| i.to_i}\nx2, y2 = gets.split.collect{|i| i.to_i}\nn = gets.to_i\nans = 0\nfor i in 0...n\n a, b, c = gets.split.collect{|i| i.to_i}\n ans += 1 if (a*x1+b*y1+c)*(a*x2+b*y2+c) < 0\nend\nputs ans\n"}, {"source_code": "x1, y1 = STDIN.readline.split.map {|s| s.to_i }\nx2, y2 = STDIN.readline.split.map {|s| s.to_i }\nif x2 < x1\n x1, x2 = x2, x1\n y1, y2 = y2, y1\nend\nn = STDIN.readline.to_i\ncount = 0\n\nn.times do\n a, b, c = STDIN.readline.split.map {|s| s.to_i }\n if b == 0\n if (a*x1 < -c and -c < a*x2) or (a*x2 < -c and -c < a*x1)\n count += 1\n end\n else\n y3 = -a*x1 - c\n y4 = -a*x2 - c\n if (y3 < b*y1 and b*y2 < y4) or (b*y1 < y3 and y4 < b*y2)\n count += 1\n end\n end\nend\n\nputs count\n"}, {"source_code": "x1, y1 = gets.split.map(&:to_i)\nx2, y2 = gets.split.map(&:to_i)\nn = gets.to_i\nr = 0\nn.times do\n a, b, c = gets.split.map(&:to_i)\n r += 1 if (a * x1 + b * y1 + c) * (a * x2 + b * y2 + c) < 0\nend\nputs r\n"}, {"source_code": "def getints\n gets.split.map &:to_i\nend\nx1,y1 = getints\nx2,y2 = getints\nn, = getints\ns = 0\nn.times do\n a,b,c = getints\n s += 1 if (a*x1+b*y1+c) * (a*x2+b*y2+c) < 0\nend\nputs s"}], "negative_code": [{"source_code": "def getints\n gets.split.map &:to_i\nend\nx1,y1 = getints\nx2,y2 = getints\nn, = getints\ns = 0\nn.times do\n a,b,c = getints\n s += 1 if (a*x1+b*y1-c) * (a*x2+b*y2-c) < 0\nend\nputs s"}, {"source_code": "x1, y1 = STDIN.readline.split.map {|s| s.to_i }\nx2, y2 = STDIN.readline.split.map {|s| s.to_i }\nif x2 < x1\n x1, x2 = x2, x1\n y1, y2 = y2, y1\nend\nn = STDIN.readline.to_i\ncount = 0\n\nn.times do\n a, b, c = STDIN.readline.split.map {|s| s.to_i }\n if b == 0\n if a*x1 < -c and -c < a*x2\n count += 1\n end\n else\n y3 = -a*x1 - c\n y4 = -a*x2 - c\n if (y3 < b*y1 and b*y2 < y4) or (b*y1 < y3 and y4 < b*y2)\n count += 1\n end\n end\nend\n\nputs count\n"}], "src_uid": "783df1df183bf182bf9acbb99208cdb7"} {"source_code": "EPS = 1e-8\n\ndef find_zero(t0, t1, depth=0, &block)\n y0 = yield(t0)\n y1 = yield(t1)\n\n return nil if y1 > EPS\n return t0 if y0 == 0\n return t1 if y1 == 0\n\n 100.times do \n t2 = (t0+t1)/2\n y2 = yield(t2)\n return t2 if y2 == 0\n\n if y2 > 0\n t0 = t2\n y0 = y2\n else\n t1 = t2\n y1 = y2\n end\n end\n\n (t0+t1)/2\nend\n\ndef distance(a, b)\n ((a[0]-b[0])**2 + (a[1]-b[1])**2 + (a[2]-b[2])**2)**0.5\nend\n\nn = gets.to_i\na = []\n(n+1).times{ a << gets.split.map(&:to_f)}\nvp, vs = gets.split.map(&:to_f)\nxp, yp, zp = pos = gets.split.map(&:to_f)\n\nt = 0.0\nn.times do |i|\n x0, y0, z0 = a[i]\n x1, y1, z1 = a[i+1]\n\n du = distance(a[i], a[i+1])/vs\n vx = (x1-x0)/du\n vy = (y1-y0)/du\n vz = (z1-z0)/du\n\n tm = find_zero(0, du) do |dt| \n distance([x0+dt*vx, y0+dt*vy, z0+dt*vz], [xp, yp, zp]) - vp*(t + dt)\n end\n\n if tm\n puts \"YES\"\n puts t+tm\n puts [x0+tm*vx, y0+tm*vy, z0+tm*vz]*\" \"\n exit\n end\n\n t += du\nend\nputs \"NO\"\n", "positive_code": [{"source_code": "def solve(t0, t1)\n y0 = yield(t0)\n y1 = yield(t1)\n\n return nil if y1 > 1e-8\n return t0 if y0 == 0\n return t1 if y1 == 0\n\n 99.times do \n t2 = (t0 + t1) / 2\n y2 = yield(t2)\n\n if y2 > 0\n t0 = t2\n y0 = y2\n elsif y2 < 0\n t1 = t2\n y1 = y2\n else\n return t2\n end\n end\n\n (t0 + t1) / 2\nend\n\ndef dist(a, b)\n (0..2).inject(0){|s, i| s + (a[i] - b[i]) ** 2} ** 0.5\nend\n\nn = gets.to_i\na = (0..n).map{ gets.split.map(&:to_f) }\nvp, vs = gets.split.map(&:to_f)\nxp, yp, zp = pos = gets.split.map(&:to_f)\n\nt = 0.0\nn.times do |i|\n x0, y0, z0 = a[i]\n x1, y1, z1 = a[i+1]\n\n du = dist(a[i], a[i+1]) / vs\n vx = (x1 - x0) / du\n vy = (y1 - y0) / du\n vz = (z1 - z0) / du\n\n r = solve(0, du) { |dt| \n dist([x0 + dt * vx, y0 + dt * vy, z0 + dt * vz], [xp, yp, zp]) - vp * (t + dt)\n }\n\n if r\n puts \"YES\"\n puts t + r\n puts [x0 + r * vx, y0 + r * vy, z0 + r * vz] * \" \"\n exit\n end\n\n t += du\nend\nputs \"NO\""}], "negative_code": [{"source_code": "def distance_lp(alpha, beta, pos)\n return distance(alpha, pos) if alpha == beta\n\n s1 = alpha.zip(beta,pos).inject(0.0){|r,(a,b,po)| r+(a+b-po)*(b-a)} \n s2 = alpha.zip(beta,pos).inject(0.0){|r,(a,b,po)| r+(b-a)*(b-a)} \n\n s = s1/s2\n if s < 0\n s = 0\n elsif s > 1\n s = 1\n end\n\n alpha.zip(beta,pos).inject(0.0){|r,(a,b,po)| r + (s*a + (1-s)*b - po)**2} **0.5\nend\n\ndef find_zero(t0, t1)\n y0 = yield(t0)\n return t0 if y0 == 0\n y1 = yield(t1)\n return t1 if y1 == 0\n\n t2 = (t0+t1)/2\n y2 = yield(t2)\n return t2 if y2 == 0 \n return nil if y2 > 0 && y1 > 0 && y0 > 0\n return nil if y2 > y1 && y2 > y0\n\n while t1-t0 > 1e6\n t3 = (t0+t2)/2\n y3 = yield(t3)\n return t3 if y3 == 0 \n end\nend\n\ndef find_zero_s(t0, t1, depth=0, &block)\n y0 = yield(t0)\n y1 = yield(t1)\n\n 20.times do \n t2 = (t0+t1)/2\n y2 = yield(t2)\n\n if y2 > 0\n t0 = t2\n y0 = y2\n else\n t1 = t2\n y1 = y2\n end\n\n #break if (y0 - y1).abs < 1e7\n end\n\n (t0+t1)/2\nend\n\nEPS = 1e-8\nDZ = 128\ndef find_zero(t0, t1, depth=0, &block)\n return t0 if yield(t0) <= EPS\n return t1 if yield(t1) <= EPS\n\n return (t0+t1)/2 if depth == 2\n return find_zero_s(t0, t1, &block) if depth >= 1\n\n yz = nil\n 0.upto(DZ) do |d|\n dt = (t1-t0)/DZ.to_f\n y = yield(t0 + d*dt) \n return (t0 + d*dt) if y == 0\n if y < 0\n return find_zero_s(t0+(d-1)*dt, t0+d*dt, &block)\n elsif y <= EPS\n return find_zero(t0+(d-1)*dt, t0+d*dt, depth+1, &block)\n end\n end\n return nil\nend\n\ndef distance(a, b)\n ((a[0]-b[0])**2 + (a[1]-b[1])**2 + (a[2]-b[2])**2)**0.5\nend\n\nn = gets.to_i\na = []\n(n+1).times{ a << gets.split.map(&:to_f)}\nvp, vs = gets.split.map(&:to_f)\nxp, yp, zp = pos = gets.split.map(&:to_f)\n\nt = 0.0\nn.times do |i|\n x0, y0, z0 = a[i]\n x1, y1, z1 = a[i+1]\n\n du = distance(a[i], a[i+1])/vs\n vx = (x1-x0)/du\n vy = (y1-y0)/du\n vz = (z1-z0)/du\n\n if distance_lp(a[i], a[i+1], pos) - (t+du)*vp < 1e5\n\n tm = find_zero(0, du) do |dt| \n distance([x0+dt*vx, y0+dt*vy, z0+dt*vz], [xp, yp, zp]) - vp*(t + dt)\n end\n\n if tm\n puts \"YES\"\n puts t+tm\n puts [x0+tm*vx, y0+tm*vy, z0+tm*vz]*\" \"\n exit\n end\n end\n\n t += du\nend\nputs \"NO\"\n"}, {"source_code": "def find_zero(t0, t1)\n y0 = yield(t0)\n return t0 if y0 == 0\n y1 = yield(t1)\n return t1 if y1 == 0\n\n t2 = (t0+t1)/2\n y2 = yield(t2)\n return t2 if y2 == 0 \n return nil if y2 > 0 && y1 > 0 && y0 > 0\n return nil if y2 > y1 && y2 > y0\n\n while t1-t0 > 1e6\n t3 = (t0+t2)/2\n y3 = yield(t3)\n return t3 if y3 == 0 \n end\nend\n\ndef find_zero_s(t0, t1, depth=0, &block)\n y0 = yield(t0)\n y1 = yield(t1)\n\n 20.times do \n t2 = (t0+t1)/2\n y2 = yield(t2)\n\n if y2 > 0\n t0 = t2\n y0 = y2\n else\n t1 = t2\n y1 = y2\n end\n end\n\n (t0+t1)/2\nend\n\nDZ = 100\ndef find_zero(t0, t1, depth=0, &block)\n return (t0+t1)/2 if depth == 2\n\n yz = nil\n 0.upto(DZ) do |d|\n dt = (t1-t0)/DZ.to_f\n y = yield(t0 + d*dt) \n return (t0 + d*dt) if y == 0\n if y < 0\n return find_zero_s(t0+(d-1)*dt, t0+d*dt, &block)\n elsif y <= 1e-8\n return find_zero(t0+(d-1)*dt, t0+d*dt, depth+1, &block)\n end\n end\n return nil\nend\n\ndef distance(a, b)\n ((a[0]-b[0])**2 + (a[1]-b[1])**2 + (a[2]-b[2])**2)**0.5\nend\n\nn = gets.to_i\na = []\n(n+1).times{ a << gets.split.map(&:to_f)}\nvp, vs = gets.split.map(&:to_f)\nxp, yp, zp = gets.split.map(&:to_f)\n\nt = 0.0\nn.times do |i|\n x0, y0, z0 = a[i]\n x1, y1, z1 = a[i+1]\n\n du = distance(a[i], a[i+1])/vs\n vx = (x1-x0)/du\n vy = (y1-y0)/du\n vz = (z1-z0)/du\n\n tm = find_zero(0, du) do |dt| \n distance([x0+dt*vx, y0+dt*vy, z0+dt*vz], [xp, yp, zp]) - vp*(t + dt)\n end\n\n if tm\n puts \"YES\"\n puts t+tm\n puts [x0+tm*vx, y0+tm*vy, z0+tm*vz]*\" \"\n exit\n end\n\n t += du\nend\nputs \"NO\"\n"}], "src_uid": "6e2a8aa58ed8cd308cb482e4c24cbbbb"} {"source_code": "gets.to_i.times do\n ans = 0\n n,k = gets.split.map(&:to_i)\n while n != 0\n if n%k == 0\n ans += 1\n n /= k\n else\n ans += n%k\n n -= n%k\n end\n end\n puts ans\nend", "positive_code": [{"source_code": "test_cases = gets.chomp.to_i\n\ntest_cases.times do |tc|\n n, k = gets.chomp.split(\" \").map(&:to_i)\n\n counter = 0\n\n while n != 0\n if n % k == 0\n n = n / k\n counter += 1\n else\n rem = n % k\n counter += rem\n n -= rem\n end\n end\n\n puts(counter)\nend"}, {"source_code": "n = gets.chomp.to_i\n\ntests = []\n\nn.times do\n tests.push(gets.split(' ').map {|e| e.to_i})\nend\n\ntests.each do |test|\n remainder = 0\n current_num = test[0]\n operations = 0\n while current_num >= test[1] do\n remainder += current_num % test[1]\n current_num = current_num / test[1]\n operations += 1\n end\n\n operations += remainder + current_num\n \n puts operations\nend\n"}], "negative_code": [], "src_uid": "00b1e45e9395d23e850ce1a0751b8378"} {"source_code": "n = gets.chomp.to_i\nn.times do \n t = gets.chomp.to_i\n # kakudo = 360 * 10000000000000000000/ t\n # # puts kakudo\n # ama = 360 * 10000000000000000000 % t\n # # puts \"YY\"\n # # puts ama\n # if ama != 0\n # puts \"NO\"\n # next\n # end\n # hantei = 90 * 10000000000000000000 / kakudo\n # amari = 90 * 10000000000000000000 % kakudo\n # if amari != 0\n # puts \"NO\"\n # next\n # end\n # saigo = (hantei * kakudo) % 10000000000000000000\n hantei = t % 4\n\n\n if hantei == 0\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n", "positive_code": [{"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n if n % 4 == 0\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n\tn = gets.chomp.to_i\n\tputs n % 4 == 0 ? \"YES\" : \"NO\"\nend\n"}, {"source_code": "gets.to_i.times { puts gets.to_i.modulo(4).zero? ? \"YES\" : \"NO\" }\n"}, {"source_code": "n = gets.chomp.to_i\nn.times {\n arrNum = gets.chomp.to_i\n if arrNum%4 != 0\n puts 'NO'\n else\n puts 'YES'\n end\n}\n\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nn.times do |i|\n t = gets.chomp.to_i\n kakudo = 360 * 10000000000000000000/ t\n ama = 360 * 10000000000000000000 % t\n hantei = 90 * 10000000000000000000 / kakudo\n amari = 90 * 10000000000000000000 % kakudo\n if hantei * kakudo / 10000000000000000000 == 90 && amari == 0 && ama == 0\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n t = gets.chomp.to_i\n kakudo = 360 * 10000000000000000000/ t.to_f\n # puts kakudo\n ama = 360 * 10000000000000000000 % t\n # puts \"YY\"\n # puts ama\n if ama != 0\n puts \"NO\"\n next\n end\n hantei = 90 * 10000000000000000000 / kakudo\n amari = 90 * 10000000000000000000 % kakudo\n if amari != 0\n puts \"NO\"\n next\n end\n if hantei * kakudo / 10000000000000000000 == 90 \n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n t = gets.chomp.to_i\n # kakudo = 360 * 10000000000000000000/ t\n # # puts kakudo\n # ama = 360 * 10000000000000000000 % t\n # # puts \"YY\"\n # # puts ama\n # if ama != 0\n # puts \"NO\"\n # next\n # end\n # hantei = 90 * 10000000000000000000 / kakudo\n # amari = 90 * 10000000000000000000 % kakudo\n # if amari != 0\n # puts \"NO\"\n # next\n # end\n # saigo = (hantei * kakudo) % 10000000000000000000\n hantei = n % 4\n\n\n if hantei == 0\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n t = gets.chomp.to_i\n kakudo = 360 * 10000000000000000000/ t\n # puts kakudo\n ama = 360 * 10000000000000000000 % t\n # puts \"YY\"\n # puts ama\n if ama != 0\n puts \"NO\"\n next\n end\n hantei = 90 * 10000000000000000000 / kakudo\n amari = 90 * 10000000000000000000 % kakudo\n if amari != 0\n puts \"NO\"\n next\n end\n if hantei * kakudo / 10000000000000000000 == 90 \n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do |i|\n t = gets.chomp.to_i\n kakudo = 360 * 10000000000000000000/ t.to_f\n # puts kakudo\n ama = 360 * 10000000000000000000 % t\n # puts \"YY\"\n # puts ama\n if ama != 0\n puts \"NO\"\n next\n end\n hantei = 90 * 10000000000000000000 / kakudo\n amari = 90 * 10000000000000000000 % kakudo\n if amari != 0\n puts \"NO\"\n next\n end\n if hantei * kakudo / 10000000000000000000 == 90 \n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do |i|\n t = gets.chomp.to_i\n kakudo = 360 * 10000000000000000000/ t\n #puts kakudo\n hantei = 90 * 10000000000000000000 / kakudo\n amari = 90 * 10000000000000000000 % kakudo\n if hantei * kakudo / 10000000000000000000 == 90 && amari == 0\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do |i|\n t = gets.chomp.to_i\n kakudo = 360 * 1000000000/ t\n hantei = 90 * 1000000000 / kakudo\n if hantei * kakudo / 1000000000 == 90\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n t = gets.chomp.to_i\n kakudo = 360 * 10000000000000000000/ t\n # puts kakudo\n ama = 360 * 10000000000000000000 % t\n # puts \"YY\"\n # puts ama\n if ama != 0\n puts \"NO\"\n next\n end\n hantei = 90 * 10000000000000000000 / kakudo\n amari = 90 * 10000000000000000000 % kakudo\n if amari != 0\n puts \"NO\"\n next\n end\n saigo = (hantei * kakudo) % 10000000000000000000\n if hantei * kakudo / 10000000000000000000 == 90 && saigo == 0\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times {\n arrNum = gets.chomp.to_i\n if arrNum%2 != 0\n puts 'NO'\n else\n puts 'YES'\n end\n}\n\n"}], "src_uid": "07e56d4031bcb119d2f684203f7ed133"} {"source_code": "n= gets.to_i\na = gets.split(\" \").map(&:to_i)\ncount = 0\nfor i in 1..n-2\n\tif (a[i]>a[i-1] && a[i]>a[i+1]) || (a[i]y&&z>y)||(xy&&z>y)||(x a[i + 1] && a[i] > a[i - 1]\n\t\ttotal += 1\n\tend\nend\nputs total"}, {"source_code": "gets\nx1=gets.split.map{|e| e.to_i}\nx2=x1.clone\nx2.shift\nx3=x2.clone\nx3.shift\nx1=x1.zip(x2,x3)\nx1.pop\nx1.pop\nputs x1.count{|e|\n\t(e[0]e[2]) || (e[0]>e[1] && e[1] A[i - 1] && A[i] > A[i + 1])\n} .size\n"}, {"source_code": "def extremum(a, b, c)\n a = a.to_i\n b = b.to_i\n c = c.to_i\n if a < b && b > c\n return true\n elsif a > b && b < c\n return true\n else\n return false\n end\nend\n\nans = 0\nn = gets.to_i\na = gets.split\nfor i in (1...n-1) do\n if extremum(a[i - 1], a[i], a[i + 1])\n ans = ans + 1\n end\nend\np ans\n"}, {"source_code": "n = Integer(gets.chomp)\n\na = gets.chomp\n .split\n .map{ |i| Integer(i) }\n\nprint (1...n-1).inject(0){ |res, i|\n ((a[i] > a[i-1] and a[i] > a[i+1]) or (a[i-1] > a[i] and a[i+1] > a[i])) ? res + 1 : res}"}, {"source_code": "n=gets.to_i\na=gets.split ' '\na=a.collect{|i| i.to_i}\nsum=0\nfor i in 1..n-2\nif a[i]a[i-1] && a[i]>a[i+1]\n sum+=1\nend\nend\nprint sum"}], "negative_code": [{"source_code": "n,*a=gets.split.map &:to_i\np a.each_cons(3).count{|x,y,z|!( (x>y&&z>y)||(xy&&z>y)||(xe[2]\n}\nif ans\n\tputs ans+2\nelse\n\tputs 0\nend"}, {"source_code": "n=gets.to_i\na=gets.split ' '\na=a.collect{|i| i.to_i}\nsum=0\nfor i in 1..n-2\nif a[i]a[i-1] and a[i]>a[i+1]\n sum+=1\nend\nend\nprint sum"}, {"source_code": "n=gets.to_i\na=gets.split ' '\na=a.collect{|i| i.to_i}\nsum=0\nfor i in 2..n-2\nif a[i]a[i-1] and a[i]>a[i+1]\n sum+=1\nend\nend\nprint sum"}], "src_uid": "67cf9f83ed791a614bd01c5e0310813f"} {"source_code": "n,m,k=gets.split.map &:to_i;z=[1]*k+[n]+[n+1]*(k-1);if m>n-(k>1?1:2) then z<<2*n-(k>1?0:1) end;n==2&&m==2&&k==1&&z<<4;p z.size;puts z.join' '\n", "positive_code": [{"source_code": "n,m,k=gets.split.map &:to_i;z=[1]*k+[n]+[n+1]*(k-1);if m>n-(k>1?1:2) then z<<2*n-(k>1?0:1) end;n==2&&m==2&&k==1&&z<<4;p z.size;puts z.join' '\n"}, {"source_code": "n,m,k=gets.split.map &:to_i;z=[1]*k+[n]+[n+1]*(k-1);if m>n-(k>1?1:2) then z<<2*n-(k>1?0:1) end;n==2&&m==2&&k==1&&z<<4;p z.size;puts z.join' '\n"}, {"source_code": "n,m,k=gets.split.map &:to_i;z=[1]*k+[n]+[n+1]*(k-1);if m>n-(k>1?1:2) then z<<2*n-(k>1?0:1) end;n==2&&m==2&&k==1&&z<<4;p z.size;puts z.join' '\n"}, {"source_code": "n,m,k=gets.split.map &:to_i;z=[1]*k+[n]+[n+1]*(k-1);if m>n-(k>1?1:2) then z<<2*n-(k>1?0:1) end;n==2&&m==2&&k==1&&z<<4;p z.size;puts z.join' '\n"}, {"source_code": "n,m,k=gets.split.map &:to_i;z=[1]*k+[n]+[n+1]*(k-1);if m>n-(k>1?1:2) then z<<2*n-(k>1?0:1) end;n==2&&m==2&&k==1&&z<<4;p z.size;puts z.join' '"}, {"source_code": "n,m,k=gets.split.map &:to_i;z=[1]*k+[n]+[n+1]*(k-1);if m>n-(k>1?1:2) then z<<2*n-(k>1?0:1) end;n==2&&m==2&&k==1&&z<<4;p z.size;puts z.join' '\n"}, {"source_code": "n,m,k=gets.split.map &:to_i;z=[1]*k+[n]+[n+1]*(k-1);if m>n-(k>1?1:2) then z<<2*n-(k>1?0:1) end;n==2&&m==2&&k==1&&z<<4;p z.size;puts z.join' '\n"}, {"source_code": "n,m,k=gets.split.map &:to_i;z=[1]*k+[n]+[n+1]*(k-1);if m>n-(k>1?1:2) then z<<2*n-(k>1?0:1) end;n==2&&m==2&&k==1&&z<<4;p z.size;puts z.join' '\n"}], "negative_code": [{"source_code": "n,m,k=gets.split.map &:to_i;z=[1]*k+[n]+[n+1]*(k-1);if m>n-(k>1?1:2) then z<<2*n-1 end;p z.size;puts z.join' '"}], "src_uid": "113997707143a57f7e81fb14d9bbde96"} {"source_code": "n, k = gets.split.map(&:to_i)\ns = gets.chomp.chars\nc = s.uniq.map{|x| s.count(x)}.sort.reverse\nans = 0\nc.each do |x|\n t = [x, k].min\n ans += t * t\n k -= t\nend\np ans\n", "positive_code": [{"source_code": "n,k=gets.split.map(&:to_i)\nstr=gets.to_s.chomp\narr=str.split(//)\n# hsh=arr.inject(Hash.new(0)) { |h,e| h[e] += 1; h }.select { \n# |k,v| v > 1 }.inject({}) { |r, e| r[e.first] = e.last; r }\n\nhsh = Hash.new(0)\narr.each { | v | hsh.store(v, hsh[v]+1) }\n\nsum=0\nkol=0\nwhile (kol b[1]\nend.reverse!\noutput = 0\n\nchar_ar.each do |a|\n\tb = if ka >= a[1]\n\t\ta[1] \n\telse\n\t ka\n\tend \n\tka -= b\n\toutput += (b ** 2)\n\tbreak if ka < 1\nend\nputs output\n# a => 1, b => 5"}, {"source_code": "\nn, k = gets.split.map(&:to_i)\ntab = gets.strip.split(//)\namount = {}\n#p tab\ntab.each do |i|\n if amount[i] == nil\n amount[i] = 1\n else\n amount[i] += 1\n end\nend\n#amount = tab.inject(0){|x, y| p y}\n#amount = tab.inject({}){|x, y| if x[y] == nil; x[y] = 1 else x[y] += 1 end}\n\namount = amount.to_a.map(&:reverse).sort.reverse\nresult = 0\ni = 0\n\nwhile i < amount.size && k > 0\n result += [amount[i][0], k].min**2\n k -= [amount[i][0], k].min\n i += 1\nend\n\nputs result\n\n\n"}, {"source_code": "require 'pp'\n\nn,k = STDIN.gets.chomp.split(/ /).map(&:to_i)\nh = {}\nans = 0\n\nSTDIN.gets.chomp.split(//).each do |c|\n h[c] ||= 0\n h[c] += 1\nend\n\nvs = h.values.sort.reverse\nvs.each do |v|\n if v <= k\n ans += v*v\n k -= v\n else\n ans += k*k\n k = 0\n end\nend\n\nputs ans\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\ns = gets.chomp.chars\nc = s.uniq.map{|x| s.count(x)}.sort.reverse\nans = 0\nc.each do |x|\n t = [x, k].min\n ans += t * t\n k -= t\nend\np ans"}, {"source_code": "n, k = gets.split.map { |x| x.to_i }\n\ncards = Hash.new(0)\n\ngets.split(//).each { |card| cards[card] += 1 }\n\ncards = cards.to_a.sort { |c1, c2| c2[1] <=> c1[1] }\n\nans = 0\ni = 0\n\nwhile k > 0\n x = cards[i][1]\n\n if x > k\n ans += k ** 2\n k = 0\n elsif x <= k\n ans += x ** 2\n k -= x\n end\n \n i += 1\nend\n\n\nputs ans"}, {"source_code": "n,k=gets.split(/ /).map(&:to_i)\nh=Hash.new\ngets.split(//).each do |i|\n h[i]?h[i]+=1:h[i]=1\nend\nans=0\nh.values.sort.reverse.each do |i|\n if i<=k\n ans+=i**2\n k-=i\n else\n ans+=k*k\n k=0\n end\nend\nputs ans"}, {"source_code": "nAndk = gets.chomp.split(' ').map { |x| x.to_i }\nn = nAndk[0]\nk = nAndk[1]\nbins = {}\ncards = gets.chomp.split('')\n\nfor card in cards\n if bins[card].nil?\n bins[card] = 0\n end\n bins[card] += 1\nend\nwork = bins.sort_by {|_key, value| value}\nscore = 0\nwhile k > 0\n count = work.last[1]\n if count < k\n k -= count\n score += bins[work.last[0]] ** 2\n work.pop\n else\n score += k*k\n k = 0 \n end\nend\np score\n"}, {"source_code": "n,k = gets.split(/\\s+/).map(&:to_i)\nh = Hash.new { |h, k| h[k] = 0 }\ngets.strip.split(//).inject(h) {|h,s| h[s] += 1; h}\n\nresult = 0\n\nh.values.sort.reverse.each do |v|\n if v < k\n k -= v\n result += v**2\n else\n result += k**2\n break\n end\nend\n\np result\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\ns = gets.chomp.chars\nc = s.uniq.map{|x| s.count(x)}.sort.reverse\nans = 0\nt = 0\nc.each do |i|\n t = [i, k].min\n ans += t * t\n break if t == k\n k -= t\nend\np ans\n"}], "negative_code": [{"source_code": "n, k = gets.split.map(&:to_i)\ns = gets.chomp.chars\nc = s.uniq.map{|x| s.count(x)}.sort.reverse\nans = 0\nt = 0\naccum = 0\nc.each do |i|\n t = [i, k].min\n accum += t\n ans += t * t\n break if accum == k\n k -= t\nend\np ans\n"}, {"source_code": "line = gets\ni, ka = line.split.map(&:to_i)\nline = gets\nchar_count = {}\nline.each_char do |char|\n\tchar_count[char] ||= 0\n\tchar_count[char] += 1 \nend\nchar_ar = []\nchar_count.each do |k, v|\n\tchar_ar << [k, v]\nend\nchar_ar.sort! do |a, b|\n\ta[1] <=> b[1]\nend\n\noutput = 0\n\nchar_ar.each do |a|\n\tbreak if ka < 1\n\tb = if a[1] > ka\n\t\tka\n\telse\n\t\tka - a[1]\n\tend \n\tputs b\n\tka -= b\n\toutput += b ** 2\nend\nputs output\n# a => 1, b => 5"}, {"source_code": "line = gets\ni, ka = line.split.map(&:to_i)\nline = gets\nchar_count = {}\nline.each_char do |char|\n\tchar_count[char] ||= 0\n\tchar_count[char] += 1 \nend\nchar_ar = []\nchar_count.each do |k, v|\n\tchar_ar << [k, v]\nend\nchar_ar.sort! do |a, b|\n\ta[1] <=> b[1]\nend\n\noutput = 0\n\nchar_ar.each do |a|\n\tbreak if ka < 1\n\tb = if a[1] > ka\n\t\tka\n\telse\n\t\tka - a[1]\n\tend \n\tka -= b\n\toutput += b ** 2\nend\nputs output\n# a => 1, b => 5"}, {"source_code": "\nn, k = gets.split.map(&:to_i)\ntab = gets.strip.split(//)\namount = {}\n#p tab\ntab.each do |i|\n if amount[i] == nil\n amount[i] = 1\n else\n amount[i] += 1\n end\nend\n#amount = tab.inject(0){|x, y| p y}\n#amount = tab.inject({}){|x, y| if x[y] == nil; x[y] = 1 else x[y] += 1 end}\n\namount = amount.to_a.map(&:reverse).sort.reverse\nresult = 0\ni = 0\n\nwhile i < amount.size && k > 0\n result += [amount[i][0], k].min**2\n k -= [amount[i][0], k].min\nend\n\nputs result\n\n\n"}], "src_uid": "480defc596ee5bc800ea569fd76dc584"} {"source_code": "n = gets.to_i\nh = Hash.new{[]}\nn.times{|i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\n}\n\na = Array.new(n){[]}\nh.each{|c, s|\n s.sort!.reverse!\n s.each_cons(2){|i, j|\n j[0] += i[0]\n }\n s.each_index{|i|\n a[i] << s\n }\n}\n\nn.times{|i|\n a[i].sort_by!{|_| -_[i][0]}\n}\nz = [0]\nn.times{|i|\n [[0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 1, 0]].each{|x, j, y|\n j += i\n b, c = a[i][x], a[j] && a[j][y]\n z = [z, [b[i][0] + c[j][0], i, x, j, y]].max if b && c && !b.equal?(c)\n }\n}\n\nu, i, x, j, y = z\np u\nv = a[j][y][0..j].zip(a[i][x][0..i]).inject(&:concat).compact\np v.size\nputs v.map{|_| _[1]} * ' '\n\n", "positive_code": [{"source_code": "n = gets.to_i\nh = Hash.new{[]}\nn.times{|i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\n}\n\na = Array.new(n){[]}\nh.each{|c, s|\n s.sort!.reverse!\n s.each_cons(2){|i, j|\n j[0] += i[0]\n }\n s.each_index{|i|\n a[i] << s\n }\n}\n\nn.times{|i|\n a[i].sort_by!{|_| -_[i][0]}\n}\nz = [0]\nn.times{|i|\n [[0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 1, 0]].each{|x, j, y|\n j += i\n b, c = a[i][x], a[j] && a[j][y]\n z = [z, [b[i][0] + c[j][0], i, x, j, y]].max if b && c && !b.equal?(c)\n }\n}\n\nu, i, x, j, y = z\np u\nv = a[j][y][0..j].zip(a[i][x][0..i]).inject(&:concat).compact\np v.size\nputs v.map{|_| _[1]} * ' '\n\n"}, {"source_code": "n = gets.to_i\nh = Hash.new{[]}\nn.times{|i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\n}\n\na = Array.new(n){[]}\nh.each{|c, s|\n s.sort!.reverse!\n s.each_cons(2){|i, j|\n j[0] += i[0]\n }\n s.each_index{|i|\n a[i] << s\n }\n}\n\nn.times{|i|\n a[i].sort_by!{|_| -_[i][0]}\n}\nz = [0]\nn.times{|i|\n [[0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 1, 0]].each{|x, j, y|\n j += i\n b, c = a[i][x], a[j] && a[j][y]\n z = [z, [b[i][0] + c[j][0], i, x, j, y]].max if b && c && !b.equal?(c)\n }\n}\n\nu, i, x, j, y = z\np u\nv = a[j][y][0..j].zip(a[i][x][0..i]).inject(&:concat).compact\np v.size\nputs v.map{|_| _[1]} * ' '\n\n"}, {"source_code": "n = gets.to_i\nh = Hash.new{[]}\nn.times{|i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\n}\n\na = Array.new(n){[]}\nh.each{|c, s|\n s.sort!.reverse!\n s.each_cons(2){|i, j|\n j[0] += i[0]\n }\n s.each_index{|i|\n a[i] << s\n }\n}\n\nn.times{|i|\n a[i].sort_by!{|_| -_[i][0]}\n}\nz = [0]\nn.times{|i|\n [[0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 1, 0]].each{|x, j, y|\n j += i\n b, c = a[i][x], a[j] && a[j][y]\n z = [z, [b[i][0] + c[j][0], i, x, j, y]].max if b && c && !b.equal?(c)\n }\n}\n\nu, i, x, j, y = z\np u\nv = a[j][y][0..j].zip(a[i][x][0..i]).inject(&:concat).compact\np v.size\nputs v.map{|_| _[1]} * ' '\n\n"}, {"source_code": "n = gets.to_i\nh = Hash.new{[]}\nn.times{|i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\n}\n\na = Array.new(n){[]}\nh.each{|c, s|\n s.sort!.reverse!\n s.each_cons(2){|i, j|\n j[0] += i[0]\n }\n s.each_index{|i|\n a[i] << s\n }\n}\n\nn.times{|i|\n a[i].sort_by!{|_| -_[i][0]}\n}\nz = [0]\nn.times{|i|\n [[0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 1, 0]].each{|x, j, y|\n j += i\n b, c = a[i][x], a[j] && a[j][y]\n z = [z, [b[i][0] + c[j][0], i, x, j, y]].max if b && c && !b.equal?(c)\n }\n}\n\nu, i, x, j, y = z\np u\nv = a[j][y][0..j].zip(a[i][x][0..i]).inject(&:concat).compact\np v.size\nputs v.map{|_| _[1]} * ' '\n\n"}, {"source_code": "n = gets.to_i\nh = Hash.new{[]}\nn.times{|i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\n}\n a = Array.new(n){[]}\nh.each{|c, s|\n s.sort!.reverse!\n s.each_cons(2){|i, j|\n j[0] += i[0]\n }\n s.each_index{|i|\n a[i] << s\n }\n}\n n.times{|i|\n a[i].sort_by!{|_| -_[i][0]}\n}\nz = [0]\nn.times{|i|\n [[0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 1, 0]].each{|x, j, y|\n j += i\n b, c = a[i][x], a[j] && a[j][y]\n z = [z, [b[i][0] + c[j][0], i, x, j, y]].max if b && c && !b.equal?(c)\n }\n}\n u, i, x, j, y = z\np u\nv = a[j][y][0..j].zip(a[i][x][0..i]).inject(&:concat).compact\np v.size\nputs v.map{|_| _[1]} * ' '"}, {"source_code": "n = gets.to_i\nh = Hash.new{[]}\nn.times{|i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\n}\n\na = Array.new(n){[]}\nh.each{|c, s|\n s.sort!.reverse!\n s.each_cons(2){|i, j|\n j[0] += i[0]\n }\n s.each_index{|i|\n a[i] << s\n }\n}\n\nn.times{|i|\n a[i].sort_by!{|_| -_[i][0]}\n}\nz = [0]\nn.times{|i|\n [[0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 1, 0]].each{|x, j, y|\n j += i\n b, c = a[i][x], a[j] && a[j][y]\n z = [z, [b[i][0] + c[j][0], i, x, j, y]].max if b && c && !b.equal?(c)\n }\n}\n\nu, i, x, j, y = z\np u\nv = a[j][y][0..j].zip(a[i][x][0..i]).inject(&:concat).compact\np v.size\nputs v.map{|_| _[1]} * ' '\n\n"}, {"source_code": "n = gets.to_i\nh = Hash.new{[]}\nn.times{|i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\n}\n\na = Array.new(n){[]}\nh.each{|c, s|\n s.sort!.reverse!\n s.each_cons(2){|i, j|\n j[0] += i[0]\n }\n s.each_index{|i|\n a[i] << s\n }\n}\n\nn.times{|i|\n a[i].sort_by!{|_| -_[i][0]}\n}\nz = [0]\nn.times{|i|\n [[0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 1, 0]].each{|x, j, y|\n j += i\n b, c = a[i][x], a[j] && a[j][y]\n z = [z, [b[i][0] + c[j][0], i, x, j, y]].max if b && c && !b.equal?(c)\n }\n}\n\nu, i, x, j, y = z\np u\nv = a[j][y][0..j].zip(a[i][x][0..i]).inject(&:concat).compact\np v.size\nputs v.map{|_| _[1]} * ' '\n\n"}, {"source_code": "n = gets.to_i\nh = Hash.new{[]}\nn.times{|i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\n}\n\na = Array.new(n){[]}\nh.each{|c, s|\n s.sort!.reverse!\n s.each_cons(2){|i, j|\n j[0] += i[0]\n }\n s.each_index{|i|\n a[i] << s\n }\n}\n\nn.times{|i|\n a[i].sort_by!{|_| -_[i][0]}\n}\nz = [0]\nn.times{|i|\n [[0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 1, 0]].each{|x, j, y|\n j += i\n b, c = a[i][x], a[j] && a[j][y]\n z = [z, [b[i][0] + c[j][0], i, x, j, y]].max if b && c && !b.equal?(c)\n }\n}\n\nu, i, x, j, y = z\np u\nv = a[j][y][0..j].zip(a[i][x][0..i]).inject(&:concat).compact\np v.size\nputs v.map{|_| _[1]} * ' '\n\n"}, {"source_code": "n = gets.to_i\nh = Hash.new{[]}\nn.times{|i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\n}\n\na = Array.new(n){[]}\nh.each{|c, s|\n s.sort!.reverse!\n s.each_cons(2){|i, j|\n j[0] += i[0]\n }\n s.each_index{|i|\n a[i] << s\n }\n}\n\nn.times{|i|\n a[i].sort_by!{|_| -_[i][0]}\n}\nz = [0]\nn.times{|i|\n [[0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 1, 0]].each{|x, j, y|\n j += i\n b, c = a[i][x], a[j] && a[j][y]\n z = [z, [b[i][0] + c[j][0], i, x, j, y]].max if b && c && !b.equal?(c)\n }\n}\n\nu, i, x, j, y = z\np u\nv = a[j][y][0..j].zip(a[i][x][0..i]).inject(&:concat).compact\np v.size\nputs v.map{|_| _[1]} * ' '\n"}], "negative_code": [{"source_code": "n = gets.to_i\nh = Hash.new{[]}\nn.times{|i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\n}\n\na = Array.new(n){[]}\nh.each{|c, s|\n s.sort!.reverse!\n s.each_cons(2){|i, j|\n j[0] += i[0]\n }\n s.each_index{|i|\n a[i] << s\n }\n}\n\nn.times{|i|\n a[i].sort_by!{|_| -_[i][0]}\n}\nz = [0]\nA = ->(i, j){a[i][j][i][0]}\nn.times{|i|\n next unless a[i][0]\n if a[i][1]\n z = [z, [A[i, 0] + A[i, 1], i, i]].max\n end\n j = i + 1\n if a[j][0]\n z = [z, [A[i, 0] + A[j, 0], i, j]].max\n end\n}\n\nu, v, w = z\np u\nc = a[w][v == w ? 1 : 0][0, w + 1].zip(a[v][0][0, v + 1]).inject(&:concat).compact\np c.size\nputs c.map{|_| _[1]} * ' '\n"}, {"source_code": "def gao(a, b, dump = nil)\n a, b = b, a if a.size < b.size\n if dump\n c = []\n a.size.times do |i|\n c << a[i][1]\n break if i == b.size\n c << b[i][1]\n end\n c\n else\n a[[a.size, b.size + 1].min - 1][0] + b[-1][0]\n end\nend\n\nn = gets.to_i\nh = Hash.new{[]}\nn.times do |i|\n c, s = gets.split.map(&:to_i)\n h[c] <<= [s, i + 1]\nend\nh.each do |c, s|\n s.sort!\n s.reverse!\n 1.upto(s.size - 1) do |i|\n s[i][0] += s[i - 1][0]\n end\nend\n\na = []\nh.sort{|x, y| [x[1].size, x[1][-1]] <=> [y[1].size, y[1][-1]]}.each {|c, s|\n a << s if a.size < 2 || a[-2].size < s.size\n}\n\nans = [-1]\na.each do |x|\n a.each do |y|\n break if x.equal?(y)\n tmp = gao(x, y)\n ans = [tmp, x, y] if tmp > ans[0]\n end\nend\np ans[0]\nans = gao(ans[1], ans[2], true)\np ans.size\nputs ans * ' '\n"}], "src_uid": "fa867bb7df94cc0edc03bcbf975de001"} {"source_code": "t = gets.to_i\nans = []\nt.times do\n h,w = gets.chomp.split(\" \").map(&:to_i)\n a = h.times.map{gets.chomp}\n cnt = 0\n (h-1).times do |i|\n cnt += 1 if a[i][-1] == \"R\"\n end\n (w-1).times do |i|\n cnt += 1 if a[-1][i] == \"D\"\n end\n ans << cnt\nend\nans.each do |x|\n puts x\nend", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do |i|\n n, m = gets.chomp.split(\" \").map(&:to_i)\n count = 0\n if n == 1\n ar = gets.chomp.split(\"\")\n arr = ar\n yy = [\"C\"]\n xx = ar \n count = xx.count(\"D\") \n elsif n >= 2\n arr = []\n yy = []\n xx = []\n if m >= 2\n n.times do |i|\n ar = gets.chomp.split(\"\")\n arr << ar\n yy << ar[-1]\n if i == n - 1\n xx = ar\n end\n end\n elsif m == 1\n xx = [\"C\"]\n n.times do |i|\n ar = gets.chomp\n arr << ar\n yy << ar\n end \n end\n count += xx.count(\"D\")\n count += yy.count(\"R\")\n\n end\n puts count\nend"}, {"source_code": "# t = gets.chomp.to_i\n# t.times do \n# n, m = gets.chomp.split(\" \").map(&:to_i)\n# yy = []\n# xx = []\n# arr = []\n# count = 0\n# n.times do |i|\n# r = gets.chomp.split(\"\")\n# arr << r\n# if n == 1 \n# puts \"YY\"\n# yy << \"C\"\n# xx << r\n# break\n# elsif m == 1 && i != n-1\n# yy << r\n# elsif m == 1 && i == n-1\n# yy << \"C\"\n# break\n# end\n# if i != n-1 && n != 1 && m != 1\n# yy << r[-1]\n# elsif i == n-1 && n != 1 && m != 1\n# xx << r\n# yy << r[-1]\n# end\n# end\n# p xx\n# p yy\n# me_x = 0\n# me_y = 0\n# if xx[0].include?(\"R\")\n# ar = xx[0].count(\"D\")\n# count += ar\n# else\n# me_x += 1\n# end\n# if yy.include?(\"D\")\n# ar = yy.count(\"R\")\n# count += ar\n# else\n# me_y += 1 \n# end\n# if me_x >= 1 \n# count += m-1\n# elsif me_y >= 1\n# count += n-1\n# end\n# puts count\n # x = 0\n # y = 0\n # ans = 0\n # if n != 1 && m != 1\n # until arr[y][x] == \"C\"\n # if arr[y][x] == \"R\"\n # x += 1\n # elsif arr[y][x] == \"D\"\n # y += 1\n # end\n # if x == m - 1\n # ans = n - y - 1\n # (y..n-1).each do |k|\n # if yy[0][k] == \"D\"\n # ans -= 1\n # end\n # end\n # break\n # end\n # if y == n - 1\n # ans = m - x - 1\n # (x..m-1).each do |k|\n # if xx[0][k] == \"R\"\n # ans -= 1\n # end \n # end\n # break\n # end\n # end\n # elsif n == 1 || m == 1\n # if n == 1\n # if xx.include?(\"R\")\n # ans = m - 1 - xx.count(\"R\")\n # else\n # ans = m - 1\n # end\n # elsif m == 1\n # if yy.include?(\"D\")\n # ans = n - 1 - yy.count(\"D\")\n # else\n # ans = n -1 \n # end\n # end\n # end\nt = gets.chomp.to_i\nt.times do |i|\n n, m = gets.chomp.split(\" \").map(&:to_i)\n count = 0\n if n == 1\n ar = gets.chomp.split(\"\")\n arr = ar\n yy = [\"C\"]\n xx = ar \n count = xx.count(\"D\") \n elsif n >= 2\n arr = []\n yy = []\n xx = []\n if m >= 2\n n.times do |i|\n ar = gets.chomp.split(\"\")\n arr << ar\n yy << ar[-1]\n if i == n - 1\n xx = ar\n end\n end\n elsif m == 1\n xx = [\"C\"]\n n.times do |i|\n ar = gets.chomp\n arr << ar\n yy << ar\n end \n end\n count += xx.count(\"D\")\n count += yy.count(\"R\")\n\n end\n puts count\nend"}], "negative_code": [], "src_uid": "409073ef839a7d0cdb900c06ee4a841c"} {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nc=0\nans=1\nx.inject(0){|l,e|\n\tif l mas[i-1] then\n temp+=1\n else\n ans = temp if temp > ans\n temp = 1\n end\nend\n\nans = temp if temp > ans\n\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\nmax = 1\narr = [a.first]\n(1...n).each do |idx|\n if arr.last < a[idx]\n arr << a[idx]\n else\n arr = [a[idx]]\n end\n max = [max, arr.length].max\nend\nputs max\n"}, {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\n\nans = 1\ncnt = 1\nnow = as[0]\n\n(1..n-1).each do |i|\n if now < as[i]\n cnt += 1\n else\n cnt = 1\n end\n now = as[i]\n ans = [ans, cnt].max\nend\n\nputs ans\n"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\nprev = a[0]\ncount = ans = i = 1\nwhile i < n\n if prev < a[i]\n count += 1\n else\n count = 1\n end\n ans = [ans, count].max\n prev = a[i]\n i += 1\nend\nputs ans\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\ndp=[1]*n\nfor i in 1...n\n dp[i]=dp[i-1]+1 if a[i]>a[i-1]\nend\nputs dp.max\n"}, {"source_code": "gets\ndp=[1]\na=gets.split.map(&:to_i)\n(1..a.size-1).each {|i| dp << ((a[i]>a[i-1])? dp.last+1: 1)}\nputs dp.max"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nl = 0\nconsecutive = 0\nlongest_consecutive = 0\ngets.split.each { |i|\n i = i.to_i\n if l < i\n consecutive += 1\n else\n consecutive = 1 # new first one\n end\n\n if longest_consecutive < consecutive\n longest_consecutive = consecutive\n end\n \n l = i\n}\n\nputs longest_consecutive"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\ncount = 1\narray = []\narray << count\nfor i in (1..n-1)\n\tif a[i] > a[i-1]\n\t\tcount += 1\n\t\tarray << count\n\telse\n\t\tcount = 1\n\tend\nend\n\nprint array.max"}, {"source_code": "def solution(arr)\n counter = 1\n max = 0\n for i in 1...arr.size do\n if arr[i] > arr[i-1]\n counter += 1\n else\n max = [max, counter].max\n counter = 1\n end\n end\n max = [max, counter].max\nend\n\n_ = gets\nputs solution(gets.split.map(&:to_i))\n"}, {"source_code": "n = gets.chomp.to_i\n#a = Array.new\n#n.times { puts gets }\nlongest = 0\ncurrent = 0\nbefore = -1\na = STDIN.gets.split(\" \").to_a\na.each do |b|\n b = b.to_i\n if b > before\n current += 1\n longest = current if current > longest\n else\n current = 1\n end\n before = b\nend\nputs longest\n"}, {"source_code": "def read_line\n gets.chomp.split.map &:to_i\nend\n\nn = read_line\na = read_line\nk = 0\nx = 0\nm = 0\na.each do |y|\n if xm\n x = y\nend\n\nputs m\n"}, {"source_code": "gets\na = gets.split.map{|x| x.to_i}\nt, l = 1, 1\n(1..a.size-1).each do |i|\n l = 0 if a[i] <= a[i - 1]\n l += 1\n t = [t, l].max\nend\nputs t\n"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\n\nresult = a.each_with_object({ prev: a.first, max: 1, s: 1 }) do |elm, obj|\n if elm > obj[:prev] \n obj.merge!({ max: [obj[:s]+1, obj[:max]].max, s: obj[:s]+1 })\n else\n obj.merge!({ max: obj[:max], s: 1 })\n end\n obj[:prev] = elm\nend\n\nputs result[:max]\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\nmax = 0\narr = [a.first]\n(1...n).each do |idx|\n if arr.last < a[idx]\n arr << a[idx]\n else\n arr = [a[idx]]\n end\n max = [max, arr.length].max\nend\nputs max\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\ncount = 1\narray = []\nfor i in (1..n-1)\n\tif a[i] > a[i-1]\n\t\tcount += 1\n\t\tarray << count\n\telse\n\t\tcount = 1\n\tend\nend\n\nprint array.max"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\ncount = 1\narray = []\nfor i in (1..n-1)\n\tif a[i] > a[i-1]\n\t\tcount += 1\n\t\tarray << count\n\telse\n\t\tcount = 1\n\t\tarray << count\n\tend\nend\n\nprint array.max"}], "src_uid": "4553b327d7b9f090641590d6492c2c41"} {"source_code": "gets.to_i.times do\r\nn=gets.to_i\r\na=gets.split(' ').map(&:to_i)\r\nsum=a.reduce(:+)\r\nanswer = ! a.select{|v| v % (n - 1) == sum % (n-1) && v == (sum - v) / (n - 1)}.empty?\r\nputs answer ? 'YES' : 'NO'\r\nend\r\n", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.chomp!.split.map! &:to_i\n s = a.sum\n if s % a.size == 0 && a.include?(s / a.size)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n s = a.reduce(:+)\n ans = \"NO\"\n 0.upto(n-1) do |i|\n if (s == n*a[i]) then\n ans = \"YES\"\n end\n end\n puts ans\nend\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\nn=gets.to_i\r\na=gets.split(' ').map(&:to_i)\r\nsum=a.reduce(:+)\r\nanswer = ! a.select{|v| v % n == sum % n && v == (sum - v) / (n - 1)}.empty?\r\nputs answer ? 'YES' : 'NO'\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\nn=gets.to_i\r\na=gets.split(' ').map(&:to_i)\r\nsum=a.reduce(:+)\r\nanswer = ! a.select{|v| v % n == sum % n && v == (sum - v) / n}.empty?\r\nputs answer ? 'YES' : 'NO'\r\nend"}], "src_uid": "7785ed6f41dbd45f1a9432c2fb07d713"} {"source_code": "puts gets(p).gsub(/(^(?! *#).*\\n)+/){$&.gsub(/\\s/, '') + \"\\n\"}\n", "positive_code": [{"source_code": "puts gets(p).gsub(/(^(?! *#).*\\n)+/){$&.gsub(/\\s/, '') + \"\\n\"}\n\n"}, {"source_code": "puts gets(p).gsub(/(^(?! *#).*\\n)+/){$&.gsub(/\\s/, '') + \"\\n\"}\n\n"}, {"source_code": "lines = STDIN.readlines\nresult = []\n\nlines.each_with_index do |line, i|\n if line.strip[0] == '#'\n if result.length != 0 and result[-1][-1] != \"\\n\"\n result.push(\"\\n\")\n end\n result.push(line)\n else\n result.push(line.gsub(/\\s/, ''))\n end\nend\n\nif result[-1][-1] != \"\\n\"\n result.push(\"\\n\")\nend\nputs result.join\n"}, {"source_code": "lines = STDIN.readlines\nresult = []\nis_amplifying = []\n\nlines.each do |line|\n if line.strip[0] == '#'\n result.push(line)\n is_amplifying.push(true)\n else\n result.push(line.gsub(/\\s/, ''))\n is_amplifying.push(false)\n end\nend\n\n(1..lines.length-1).each do |i|\n if is_amplifying[i] and !is_amplifying[i-1]\n result[i-1] += \"\\n\"\n end\nend\n\nif result[-1][-1] != \"\\n\"\n result.push(\"\\n\")\nend\nputs(result.join)\n"}, {"source_code": "lines = STDIN.readlines\nresult = []\nis_amplifying = []\n\nlines.each do |line|\n if line.strip[0] == '#'\n result.push(line)\n is_amplifying.push(true)\n else\n result.push(line.gsub(/\\s/, ''))\n is_amplifying.push(false)\n end\nend\n\n(1..lines.length-1).each do |i|\n if is_amplifying[i] and !is_amplifying[i-1]\n result[i-1] += \"\\n\"\n end\nend\n\nif result[-1][-1] != \"\\n\"\n result.push(\"\\n\")\nend\nprint(result.join)\n"}, {"source_code": "puts gets(p).gsub(/(^(?! *#).*\\n)+/){$&.gsub(/\\s/, '') + \"\\n\"}\n"}, {"source_code": "puts gets(p).gsub(/(^(?! *#).*\\n)+/){$&.gsub(/\\s/, '') + \"\\n\"}\n\n"}, {"source_code": "puts gets(p).gsub(/(^(?! *#).*\\n)+/){$&.gsub(/\\s/, '') + \"\\n\"}\n\n"}, {"source_code": "puts gets(p).gsub(/(^(?! *#).*\\n)+/){$&.gsub(/\\s/, '') + \"\\n\"}"}, {"source_code": "#!/usr/bin/ruby\n\nbuf = []\n$stdin.readlines.each do |line|\n line.chomp!\n if line =~ /^ *#/\n if not buf.empty?\n puts buf.join('')\n buf = []\n end\n puts line\n else\n buf << line.gsub(/ /, '')\n end\nend\nif not buf.empty?\n puts buf.join('')\nend\n"}, {"source_code": "puts gets(p).gsub(/(^(?! *#).*\\n)+/){$&.gsub(/\\s/, '') + \"\\n\"}\n\n"}, {"source_code": "tmp = []\n\nreadlines.each do |line|\n if line =~ /^ *#/\n if not tmp.empty?\n puts tmp.join\n tmp = []\n end\n puts line\n else\n tmp << line.delete(' ').chomp\n end\nend\n\nputs tmp.join if not tmp.empty?"}, {"source_code": "tmp = []\n\nwhile line = gets\n if line.lstrip[0] == '#'\n if not tmp.empty?\n puts tmp.join\n tmp = []\n end\n puts line\n else\n tmp << line.delete(' ').chomp\n end\nend\n\nputs tmp.join if not tmp.empty?"}, {"source_code": "tmp = []\n\nreadlines.each do |line|\n if line.lstrip[0] == '#'\n if not tmp.empty?\n puts tmp.join\n tmp = []\n end\n puts line\n else\n tmp << line.delete(' ').chomp\n end\nend\n\nputs tmp.join if not tmp.empty?"}, {"source_code": "puts gets(p).gsub(/(^(?! *#).*\\n)+/){$&.gsub(/\\s/, '') + \"\\n\"}\n\n"}, {"source_code": "puts gets(p).gsub(/(^(?! *#).*\\n)+/){$&.gsub(/\\s/, '') + \"\\n\"}\n\n"}, {"source_code": "last = nil\nf = true\n\nwhile s = gets\n\tt = s.strip.gsub(' ','')\n\tif t[0] == '#'\n\t\tif last != nil\n\t\t\tputs last\n\t\t\tlast = nil\n\t\tend\n\t\tputs s\n\telse\n\t\tlast ||= \"\"\n\t\tlast << t\n\tend\n\tf = false\nend\nif last != nil\n\tputs last\nend"}, {"source_code": "puts gets(p).gsub(/(^(?! *#).*\\n)+/){$&.gsub(/\\s/, '') + \"\\n\"}\n\n"}], "negative_code": [{"source_code": "lines = STDIN.readlines\nresult = []\nis_amplifying = []\n\nlines.each do |line|\n if line.strip[0] == '#'\n result.push(line)\n is_amplifying.push(true)\n else\n result.push(line.gsub(/\\s/, ''))\n is_amplifying.push(false)\n end\nend\n\n(1..lines.length-1).each do |i|\n if is_amplifying[i] and !is_amplifying[i-1]\n result[i-1] += \"\\n\"\n end\nend\n\nprint(result.join)\n"}, {"source_code": "lines = STDIN.readlines\nresult = []\n\nlines.each_with_index do |line, i|\n if line.strip[0] == '#'\n if result.length != 0 and result[-1][-1] != \"\\n\"\n result.push(\"\\n\")\n end\n result.push(line)\n else\n result.push(line.gsub(/\\s/, ''))\n end\nend\n\nputs result.join\n"}, {"source_code": "lines = STDIN.readlines\nresult = []\n\nlines.each_with_index do |line, i|\n if line.strip[0] == '#'\n if result.length > 0\n if result[-1].length == 0 or result[-1][-1] != \"\\n\"\n result.push(\"\\n\")\n end\n end\n result.push(line)\n else\n result.push(line.gsub(/\\s/, ''))\n end\nend\n\nputs result.join\n"}, {"source_code": "lines = STDIN.readlines\nresult = []\nis_amplifying = []\n\nlines.each do |line|\n if line.strip[0] == '#'\n result.push(line)\n is_amplifying.push(true)\n else\n result.push(line.gsub(/\\s/, ''))\n is_amplifying.push(false)\n end\nend\n\n(1..lines.length-1).each do |i|\n if is_amplifying[i] and !is_amplifying[i-1]\n result[i-1] += \"\\n\"\n end\nend\n\nputs result.join\n"}, {"source_code": "tmp = ''\nlast_line_was_text = false\n\nwhile line = gets\n if line.lstrip[0] == '#'\n tmp += \"\\n\" if last_line_was_text\n tmp += line\n else\n tmp += line.delete(' ').chomp\n last_line_was_text = true\n end\nend\n\nputs tmp.chomp"}, {"source_code": "$/ = nil\ntmp = ''\nlast_line_was_text = false\n\nwhile line = gets\n if line.lstrip[0] == '#'\n tmp += \"\\n\" if last_line_was_text\n tmp += line\n last_line_was_text = false\n else\n tmp += line.delete(' ').chomp\n last_line_was_text = true\n end\nend\n\nprint tmp.chomp"}, {"source_code": "tmp = ''\nlast_line_was_text = false\n\nwhile line = gets\n if line.lstrip[0] == '#'\n tmp += \"\\n\" if last_line_was_text\n tmp += line\n last_line_was_text = false\n else\n tmp += line.delete(' ').chomp\n last_line_was_text = true\n end\nend\n\nputs tmp.chomp"}, {"source_code": "\n#$/ = nil\ntmp = ''\nlast_line_was_text = false\n\nwhile line = gets\n if line.lstrip[0] == '#'\n tmp += \"\\n\" if last_line_was_text\n tmp += line\n last_line_was_text = false\n else\n tmp += line.delete(' ').chomp\n last_line_was_text = true\n end\nend\n\nprint tmp.chomp"}, {"source_code": "last = \"\"\nf = true\n\nwhile s = gets\n\tt = s.strip.gsub(' ','')\n\tif t[0] == '#'\n\t\tif not f\n\t\t\tputs last\n\t\t\tlast = \"\"\n\t\tend\n\t\tputs s\n\telse\n\t\tlast << t\n\tend\n\tf = false\nend\nputs last"}, {"source_code": "imp = false\nf = true\nwhile s = gets\n\tt = s.strip\n\tif t[0] == '#'\n\t\tif not imp and not f\n\t\t\tputs\n\t\tend\n\t\tputs s\n\t\timp = true\n\telse\n\t\tt = t.gsub(' ','')\n\t\tprint t\n\t\timp = false\n\tend\n\tf = false\nend"}, {"source_code": "imp = false\nf = true\nwhile s = gets\n\tt = s.strip\n\tif t[0] == '#'\n\t\tif not imp and not f\n\t\t\tputs\n\t\tend\n\t\tprint s\n\t\timp = true\n\telse\n\t\tt = t.gsub(' ','')\n\t\tprint t\n\t\timp = false\n\tend\n\tf = false\nend"}, {"source_code": "imp = false\nf = true\nwhile s = gets\n\tt = s.strip\n\tif t[0] == '#'\n\t\tif not imp and not f\n\t\t\tputs\n\t\tend\n\t\tputs s\n\t\timp = true\n\telse\n\t\tt = t.gsub(' ','')\n\t\tprint t\n\t\timp = false\n\tend\n\tf = false\nend\nputs"}], "src_uid": "a16bb696858bc592c33dcf0fd99df197"} {"source_code": "# END { load __FILE__ unless $stdin.eof? }\n\nt = gets.to_i\nt.times do\n\nn = gets.to_i\na = gets.split.map!(&:to_i)\nz = Array.new(n, &:itself)\n\nif a[-1] == 0\n z.push(n)\nelsif a[0] != 0\n z.unshift(n)\nelse\n k = a.each_cons(2).find_index { |ai, aj| ai == 0 && aj != 0 }\n raise unless k\n z.insert(k + 1, n)\nend\n\nputs z.map!(&:succ) * \" \"\n\nrescue\n\nputs -1\n\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n a=gets.split.map(&:to_i)\r\n i=a.reverse.index(0)\r\n if i==nil\r\n puts ([n+1]+[*1..n]).join(\" \")\r\n elsif i==0\r\n i=n-1-i\r\n puts ([*1..n]+[n+1]).join(\" \")\r\n else\r\n i=n-1-i\r\n puts ([*1..i+1]+[n+1]+[*i+2..n]).join(\" \")\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "3f9525d74f4934eb9dca1b16c53662bf"} {"source_code": "def min(a, b)\n a < b ? a : b\nend\n\nclass Array\n def sum\n self.inject { |r, v| r + v }\n end\nend\n\nn, volume = gets.split.map { |v| v.to_f }\na = gets.split.map { |v| v.to_f }\nb = gets.split.map { |v| v.to_f }\n\nmultiplier = min(volume / a.sum, b.zip(a).map { |f, s| f / s }.min)\n\nputs multiplier * a.sum\n", "positive_code": [{"source_code": "sum , i= 0,0\narr = gets.split(' ').map { |x| x.to_i }\nn,v = arr[0],arr[1]\nres = v\na = gets.split(' ').map { |x| x.to_i }\nfor c in a\n sum += c\nend\nb = gets.split(' ').map { |x| x.to_i }\nfor s in b\n if res > 1.00*s*sum/a[i] then\n res = 1.00*s*sum/a[i]\n end\n i += 1\nend\nputs res"}], "negative_code": [], "src_uid": "351d8874a10f84d157a7b2e1eb64e2a1"} {"source_code": "n, a=gets.split.map &:to_i\nx=180.0*(n-2)/n\nminD=(x-a).abs\nminX=2\n(3...n).each do |i|\n b=(180.0*(i-2)-x*(i-2))/2\n d=(b-a).abs\n if d>1"}, {"source_code": "input = ARGV ? $< : File(ARGV[0])\n\nn = gets.to_i\n\ncount = 0\nfor i in input.each_line.take n\n\tif i[0] == '+' || i[-2] == '+'\n\t\tcount += 1\n\telse\n\t\tcount -= 1\n\tend\nend\n\nputs count\n"}, {"source_code": "n = gets.to_i\nsum = 0\n\n(1..n).each do |i|\n s = gets.chomp\n if s[1] == '+'\n sum += 1\n else\n sum -= 1\n end\nend\n\nputs sum"}, {"source_code": "n = gets.chomp.to_i\nc = 0\nn.times do\n str = gets\n if str.include? \"+\"\n c += 1\n else\n c -= 1\n end \nend\nputs c\n \n"}, {"source_code": "number = gets.strip.to_i\n\nx = 0\nnumber.times do\n input = gets.strip\n if input.downcase == '++x' || input.downcase == 'x++'\n x += 1\n else\n x -= 1\n end\nend\n\nputs x\n"}, {"source_code": "x=gets.to_i\nz=0\nv=0\nwhile z 0) \n x += 1\n else \n x -= 1\n end\n}\nputs x"}, {"source_code": "n = gets.chomp.to_i\n\nans = 0\nn.times {\n\n s = gets.chomp\n \n if s[1] == '+'\n ans += 1\n else \n ans -= 1\n end\n}\n\nputs ans"}, {"source_code": "a = gets.chomp.to_i\nx = 0\nwhile a>0\n a-=1\n if gets.chomp[1]=='+'\n x+=1\n else\n x-=1\n end\nend\nprint x"}, {"source_code": "x=0\ngets.to_i.times{\n\tif gets.include?(\"++\")\n\t\tx+=1\n\telse\n\t\tx-=1\n\tend\n}\nputs x"}, {"source_code": "stateNum = gets.chomp.to_i\nvalue = 0\n\nfor i in 0...stateNum\n\tstatement = gets.chomp\n\n\tvalue += 1 if statement.include?('+')\n\tvalue -= 1 if statement.include?('-')\nend\n\nputs value"}, {"source_code": "x = 0\ni = gets.to_i\n\nwhile i > 0 do\n if gets.index('--') != nil\n x = x - 1\n else\n x = x + 1\n end\n i = i - 1\nend\n\nprint x"}, {"source_code": "n = gets.to_i\ns = Array.new(n)\n\ncounters,xounterz = 0,0\nfor i in 0..n-1\n s[i] = gets.to_s\n if s[i].include? \"+\"\n counters+=1\n else\n xounterz+=1\n end\nend\nputs counters-xounterz"}, {"source_code": "n = gets.strip.to_i\nx = 0\nvar = \"X\"\nn.times do \n str = gets.strip\n if str == \"++#{var}\" || str == \"#{var}++\" then\n x += 1\n elsif str == \"--#{var}\" || str == \"#{var}--\" then\n x -= 1\n end\nend\nputs x"}, {"source_code": "n = gets.to_i\nrt = n\nn.times do\n rt-=2 if gets=~/-/\nend\nputs rt"}, {"source_code": "n = gets.strip.to_i \narr = []\nlast = \"\"\n\nn.times do |i|\n x = gets.strip.to_s\n x.include?(\"+\") ? arr << 1 : arr << -1\n last = x if (n - i == 1) \nend \n\n\nputs arr.reduce(0){|init,ele| init + ele}\n\n\n"}, {"source_code": "n=Integer(gets.chomp)\nx=0\nuntil n==0\n if gets.chomp.index('+')!=nil\n x = 1 + x\n else\n x = x - 1\n end\n n -= 1\nend\nputs x"}, {"source_code": "ret = 0\ngets.to_i.times do\n if (gets =~ /-/) then ret -= 1 else ret += 1 end\nend\nputs ret"}, {"source_code": "a=gets.chomp.to_i\nx=0\na.times do\nb=gets.chomp\nif b[0]==\"+\" || b[2] == \"+\"\nx+=1\nelse \nx-=1\nend \nend\n\nputs \"#{x}\""}, {"source_code": "x=0\ngets.to_i.times{\n\ts=gets.chomp\n\tx=x+(\" ++X++\".index(s)?1:-1)\n}\nputs x"}, {"source_code": "require 'scanf'\n\nn = $stdin.readline.to_i\nx = 0\n\nn.times do |i|\n line = $stdin.readline\n line = line.chomp('').downcase\n line = line[0, 3]\n if line == \"++x\" || line == \"x++\"\n x += 1\n elsif line == \"--x\" || line == \"x--\"\n x -= 1\n end\nend\n\nputs x\n"}, {"source_code": "$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nx=0\nn = gets.to_i\n\nn.times{\n cmd = gets.strip\n \n x+=1 if cmd.include? \"+\"\n x-=1 if cmd.include? \"-\"\n}\n\nputs x"}, {"source_code": "$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nx=0\nn = gets.to_i\n\nn.times{x+=(gets.strip.include? \"+\")? 1 : -1;}\n\nputs x"}, {"source_code": "x = 0\nn = gets.chomp.to_i\nn.times do\n\tvalue = gets.chomp\n\tx = x + 1 if value.scan(\"+\").count == 2 unless value.scan(\"X\").count == 0\n\tx = x - 1 if value.scan(\"-\").count == 2 unless value.scan(\"X\").count == 0\nend\nputs(x)"}, {"source_code": "x = 0\n\ngets.strip.to_i.times do\n statement = gets.strip\n x += 1 if statement.include?('++')\n x -= 1 if statement.include?('--')\nend\n\nputs x\n"}, {"source_code": "n = gets.chomp.to_i\nans = 0\nn.times{\n line = gets.chomp\n ans += 1 if line.include? \"+\"\n ans -= 1 if line.include? \"-\"\n}\nputs ans"}, {"source_code": "n = gets.to_i\no=0\n\nfor i in 1..n\n gets.chomp[1] == '+' ? o+=1 : o-=1\nend\n\np o"}, {"source_code": "r = 0\n\ngets.to_i.times do\n if gets[1] == '+'\n r += 1\n else\n r -= 1\n end\nend\n\nputs r\n"}, {"source_code": "n=gets.chomp.to_i\nx=0\nn.times{\n s=gets.chomp.to_s\n if s.scan(/\\+\\+/) { |match| \n x+=1\n }\n end\n if s.scan(/--/) { |match| \n x-=1\n }\n end\n}\nputs (x)"}, {"source_code": "p gets.to_i.times.map{gets=~/\\+/?1: -1}.inject &:+\n"}, {"source_code": "x=0;n=gets.to_i;n.times{x+=((gets.include? \"+\")?1:-1)};p x\n"}, {"source_code": "n = Integer(gets)\noperation = Array.new\nfor i in 0...n\n operation[i] = Array.new\n input = gets.chomp\n operation[i] = input\nend\nx = 0\nfor i in 0...n\n if operation[i] == \"++X\" || operation[i] ==\"X++\"\n x += 1\n else\n x -= 1\n end\nend\nputs x"}, {"source_code": "x = 0\nn = gets.chomp.to_i\ni = 0\nif n >= 1 && n <= 150\n\twhile i < n\n\t\tstatement = gets.chomp\n\t\tif statement == \"++X\" || statement == \"++x\" || statement == \"x++\" || statement == \"X++\"\n\t\t\tx += 1\n\t\telsif statement == \"--X\" || statement == \"--x\" || statement == \"x--\" || statement == \"X--\"\n\t\t\tx -= 1\n\t\tend\n\t\ti += 1\n\tend\nend\n\nputs x"}, {"source_code": "n = gets.to_i\nvalue = 0\nn.times do |_|\n statement = gets\n statement.include?('++') ? value += 1 : value -= 1\nend\nputs value"}, {"source_code": "n = gets.to_i\nx = 0\nfor i in 0...n\n operation = gets.chomp.to_s\n case operation\n when \"++X\",\"X++\"\n x+=1\n when \"--X\",\"X--\"\n x-=1\n end\nend\nputs x"}, {"source_code": "x = 0\ngets.to_i.times {\n x += gets.include?(\"+\") ? 1 : -1\n}\nputs x\n"}, {"source_code": "r=0;gets.to_i.times{gets[1]=='+'?(r+=1):(r-=1)};puts r"}, {"source_code": "ans = 0\ngets.to_i.times do |i|\n if gets.include?(\"++\")\n ans += 1\n else\n ans -= 1\n end\nend\nputs ans"}, {"source_code": "n = gets.to_i\nX = 0\n\nn.times do\n\npokemon = gets.to_s\n\npokemon.delete! (\"X\")\n\nb = pokemon.scan(/[+]/).length\n\nif b >= 1\nX += 1\n\nelse\nX -= 1\n\n\n\nend\n\nend\n\np X\n\n\n"}, {"source_code": "x = 0\n\n#input\ncounter = gets.chomp.to_i\nlisting = []\n\nwhile counter != 0\n\ts = gets.chomp\n\tif s.include?(\"++\")\n\t\tx += 1\n\telsif s.include?(\"--\")\n\t\tx -= 1\n\tend\n\n\tcounter -= 1\nend\n\nputs x\t\t\n"}, {"source_code": "n = gets.chomp.to_i\nx = 0\nn.times do \n\ts = gets.chomp\n\tif s.include?(\"+\") \n\t\tx += 1\n\telse\n\t\tx -= 1\n\tend\nend\nputs x\t\t\n"}, {"source_code": "n = gets.to_i\nputs n.times.map{gets['++'] ? +1 : -1}.inject(:+)\n"}, {"source_code": "n = gets.to_i\nans = 0\nn.times.map{gets}.map{|x| x.include?('++') ? ans += 1 : ans -= 1}\nputs ans\n"}, {"source_code": "n=gets.chomp.to_i\ny=0\nwhile n>0\nb=gets.chomp\n\nif(b==\"++X\" or b==\"X++\")\ny+=1\nend\nif(b==\"--X\" or b==\"X--\")\ny=y-1\nend\nn=n-1\nend\nprint y"}, {"source_code": "result = 0\ngets.chomp.to_i.times do\n case gets.chomp.gsub(/X/, '')\n when '++' then result += 1\n when '--' then result -= 1\n end\nend\nputs result"}, {"source_code": "operations = []\ngets.to_i.times { operations << gets }\nputs operations.inject(0) { |x, operation| operation.include?(\"++\") ? x + 1 : x - 1}"}], "negative_code": [{"source_code": "result = 0\ngets.chomp.to_i.times do\n case gets.chomp\n when 'X++' then result += 1\n when '--X' then result -= 1\n end\nend\nputs result"}, {"source_code": "k=gets.to_i\nl=[]\nk.times{l << gets.chomp}\nprint l.count(\"++X\")-l.count(\"--X\")"}, {"source_code": "x = 0\ngets.chomp.to_i.times do \n\ts = gets.chomp\n\tif s =~ /(\\+\\+x|x\\+\\+)/\n\t\tx += 1\n\telse\n\t\tx -= 1\n\tend\nend\nputs x"}, {"source_code": "n = gets.to_i\nx = 0\nn.times do\n if gets.chomp == \"x++\"\n x += 1\n else\n x -= 1\n end\nend\n\nputs x"}, {"source_code": "sum = 0\ngets.to_i.times{\n if gets[1]==\"+\"\n sum+=1\n else\n sum-=1\n end\n}\nsum"}, {"source_code": "n = gets.strip.to_i \narr = []\nlast = \"\"\n\nn.times do |i|\n x = gets.strip.to_s\n x.include?(\"+\") ? arr << 1 : arr << -1\n last = x if (n - i == 1) \nend \n\nif last[0] != \"+\" and last[0] != \"-\"\n arr[arr.length - 1] = 0\nend\n\nputs arr.reduce(0){|init,ele| init + ele}\n\n\n"}, {"source_code": "i = gets.to_i\ncounter = 0\n(1..i).each do |x|\n counter += gets.chomp === 'X++' ? 1 : -1\nend\nprint counter"}, {"source_code": "a=$<;p a.count(?+)-a.count(?-)>>1\n"}, {"source_code": "input_line_num = gets.chomp.to_i\nn = 0\nres = 0\nwhile input_line_num > n\n input_peration = gets.chomp\n case input_peration.include?(\"+\")\n when true\n res +=1\n when false\n if res < 0\n res = 0\n end\n res -=1\n end\n n +=1\nend\np res\n"}, {"source_code": "num = gets.chomp.to_i\nlines = []\ni = 0\nx = 0\nwhile (i < num)\n\tlines[i] = gets.chomp\n\ti = i + 1\nend\nj = 0\nwhile (j < lines.length)\n\tif(lines[j] == \"++x\" || lines[j] == \"x++\")\n\t\tx = x +1\n\telse\n\tx = x -1\n\tend\n\tj = j +1\nend\nputs x.to_s"}, {"source_code": "number = gets.strip.to_i\n\nx = 0\nnumber.times do\n input = gets.strip\n if input == '++x'\n x += 1\n else\n x -= 1\n end\nend\n\nputs x\n"}], "src_uid": "f3cf7726739290b280230b562cac7a74"} {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn=gets.to_i\na=gets.split.map &:to_i\nx,y=[0],[0]\nn.times{|i|\n\tx<0]\n\ty<0]\n}\np [*1...n].map{|i|x[i]+y[n]-y[i]}.min", "positive_code": [{"source_code": "# https://codeforces.com/problemset/problem/234/C\n\nn = 0\narr = []\n\nFile.open(\"input.txt\", \"r\") do |f|\n n = f.gets.to_i - 2\n arr = f.gets.split(' ').map(&:to_i)\nend\n\ns = (arr[0] >= 0 ? 1 : 0) + (arr[-1] <= 0 ? 1 : 0)\n\nFile.open(\"output.txt\", \"w\") do |f|\n if n > 0\n arr = arr[1...-1]\n\n temp = Array.new(n, 0)\n\n correct_count = 0\n n.times do |i|\n correct_count += 1 if arr[i] < 0\n temp[i] += correct_count\n end\n\n correct_count = 0\n (n-1).downto(0) do |i|\n correct_count += 1 if arr[i] > 0\n temp[i] += correct_count\n end\n\n f.write(\"#{s + n - temp.max}\\n\")\n else\n f.write(\"#{s}\\n\")\n end\nend"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn=gets.to_i\na=gets.split.map &:to_i\nx,y=[0],[0]\nn.times{|i|\n\tx<0]\n\ty<0]\n}\np [*1...n].map{|i|x[i]+y[n]-y[i]}.min\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn=gets.to_i\na=gets.split.map &:to_i\nx,y=[0],[0]\nn.times{|i|\n\tx<0]\n\ty<0]\n}\np [*1...n].map{|i|x[i]+y[n]-y[i]}.min\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn=gets.to_i\na=gets.split.map &:to_i\nx,y=[0],[0]\nn.times{|i|\n\tx<0]\n\ty<0]\n}\np [*1...n].map{|i|x[i]+y[n]-y[i]}.min\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn=gets.to_i\na=gets.split.map &:to_i\nx,y=[0],[0]\nn.times{|i|\n\tx<0]\n\ty<0]\n}\np [*1...n].map{|i|x[i]+y[n]-y[i]}.min\n"}, {"source_code": "n = 0\narr = []\nopen(\"input.txt\") {|f|\n n = f.gets.to_i\n arr = f.gets.to_s.chomp.split.map(&:to_i)\n}\nFile.open(\"output.txt\", \"w\"){|f|\n t1 = 0\n t2 = 0\n ar1 = []\n ar2 = []\n n.times do |i|\n t1 += 1 if arr[i] >= 0\n ar1.push(t1)\n t2 += 1 if arr[n-1-i] <= 0\n ar2.push(t2)\n end\n ar2.reverse!\n ar3 = []\n #ar3.push(ar1[n-1])\n #ar3.push(ar2[0])\n (n-1).times do |i|\n ar3.push(ar1[i]+ar2[i+1])\n end\n #p ar1\n #p ar2\n #p ar3\n f.write \"#{ar3.min}\\n\"\n}"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn=gets.to_i\na=gets.split.map &:to_i\nx,y=[0],[0]\nn.times{|i|\n\tx<0]\n\ty<0]\n}\np [*1...n].map{|i|x[i]+y[n]-y[i]}.min\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn=gets.to_i\na=gets.split.map &:to_i\nx,y=[0],[0]\nn.times{|i|\n\tx<0]\n\ty<0]\n}\np [*1...n].map{|i|x[i]+y[n]-y[i]}.min\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn=gets.to_i\na=gets.split.map &:to_i\nx,y=[0],[0]\nn.times{|i|\n\tx<0]\n\ty<0]\n}\np [*1...n].map{|i|x[i]+y[n]-y[i]}.min\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn=gets.to_i\na=gets.split.map &:to_i\nx,y=[0],[0]\nn.times{|i|\n\tx<0]\n\ty<0]\n}\np [*1...n].map{|i|x[i]+y[n]-y[i]}.min\n"}], "negative_code": [{"source_code": "n = 0\narr = []\nopen(\"input.txt\") {|f|\n n = f.gets.to_i\n arr = f.gets.to_s.chomp.split.map(&:to_i)\n}\nFile.open(\"output.txt\", \"w\"){|f|\n t1 = 0\n t2 = 0\n ar1 = []\n ar2 = []\n n.times do |i|\n t1 += 1 if arr[i] >= 0\n ar1.push(t1)\n t2 += 1 if arr[n-1-i] <= 0\n ar2.unshift(t2)\n end\n ar3 = []\n ar3.push(ar1[n-1])\n ar3.push(ar2[0])\n (n-1).times do |i|\n ar3.push(ar1[i]+ar2[i+1])\n end\n #p ar1\n #p ar2\n #p ar3\n f.write \"#{ar3.min}\\n\"\n}"}], "src_uid": "165e18e39d2f60c72f22e3027a29a742"} {"source_code": "gets.to_i.times do\r\n l1, r1, l2, r2 = gets.split.map(&:to_i)\r\n if l1 <= r2 && r1 >= l2\r\n p [l1, l2].max\r\n else\r\n p l1 + l2\r\n end\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\n l1,r1,l2,r2 = gets.chomp.split.map(&:to_i)\n if (l2 > r1) or (r2t1 then\n\t\t\tans=t1\n\t\tend\n\tend\n}\nputs ans\n"}, {"source_code": "n = gets.to_i\ndirections = gets\nnumbers = gets\n\nnumbers = numbers.split(' ')\npr = -1\nmin = 20000000000\nflag = 0\npl = -1\nnumbers.each_with_index do |r,i|\n if (directions[i] == 'R')\n pr = i\n else\n if (pr != -1)\n pl = i\n #calc magic\n delta = numbers[pl].to_i - numbers[pr].to_i\n min = delta if delta < min\n flag = 1;\n end \n end\nend\n\nputs flag == 0 ? -1 : min/2"}, {"source_code": "n = gets.chomp.to_i\nss = gets.chomp.split('')\nxs = gets.chomp.split.map(&:to_i)\n\nls = []\nrs = []\n(0...n).to_a.each do |i|\n if ss[i] == 'L'\n ls << xs[i]\n else\n rs << xs[i]\n end\nend\n\nls.sort!\nans = -1\n\nrs.each do |r|\n l = ls.bsearch { |l| r < l }\n if !l.nil?\n t = (l - r) / 2\n if ans < 0 || t < ans\n ans = t\n end\n end\nend\n\nputs ans\n\n"}, {"source_code": "n = gets.to_i\nd = gets.chomp.chars\nt = gets.split.map(&:to_i)\nans = 1e9\n(n - 1).times do |i|\n if d[i] == 'R' && d[i + 1] == 'L'\n ans = [( t[i + 1] - t[i] ) / 2, ans].min\n end\nend\nputs ans == 1e9 ? -1 : ans\n"}, {"source_code": "n = gets.to_i\nd = gets\nx = gets.split.map(&:to_i)\n\nans = nil\nlast = nil\nn.times do |i|\n if d[i] == 'L'\n ans = x[i] - last if last && (ans.nil? || x[i] - last < ans)\n else\n last = x[i]\n end\nend\n\nputs ans ? ans / 2 : -1\n"}, {"source_code": "particleNum = gets.chomp.to_i\ndirections = gets.chomp.split('')\nparticles = gets.chomp.split(' ').map(&:to_i)\n\nfoundRight = false\nposRight = 0\n\nans = -1\ncandAns = []\n\nfor i in 0...particleNum\n\tfoundRight = true if directions[i] == 'R'\n\tposRight = i if directions[i] == 'R'\n\n\tif foundRight && directions[i] == 'L'\n\t\tcandAns << particles[i] - ((particles[posRight] + particles[i]) / 2)\n\t\tfoundRight = false\n\tend\nend\n\nif candAns.length > 0\n\tputs candAns.min\nelse\n\tputs -1\nend"}, {"source_code": "n = gets.chomp.to_i\ns = gets.chomp.to_s\na = gets.split.map(&:to_i)\n\nans = 1234567890\n\n(n-1).times do |i|\n if s[i]=='R' && s[i+1]=='L'\n ans = [ans, (a[i+1]-a[i])/2].min\n end\nend\n\nif ans==1234567890\n p -1\nelse\n p ans\nend"}, {"source_code": "gets\nstr = gets.chomp\nmas = gets.split.map(&:to_i)\n\nn = str.length\n\nans = 10000000000000\nl = false\nfor i in 0..n-1 do\n if str[i]=='R' and str[i+1]=='L' then\n l = true\n out = (mas[i+1] - mas[i])/2\n ans = out if ans > out\n end\nend\n\nputs (l==true ? \"#{ans}\": \"-1\")\n"}, {"source_code": "n = gets.chomp.to_i\nsyms = gets.chomp.chars\npoints = gets.chomp.split.map(&:to_i)\n\narr = syms.each_cons(2).with_index.select { |s, _| s.join == \"RL\" }.map do |_, idx|\n (points[idx + 1] - points[idx]) / 2\nend\n\nputs arr.empty? ? -1 : arr.min\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn = gi\ns = gs\nx = gis\n\nl = nil\nr = nil\n\nans = nil\n\nn.times do |i|\n if s[i] == 'L'\n l = x[i]\n else\n r = x[i]\n end\n next if l.nil?\n next if r.nil?\n next if r > l\n k = (l - r) / 2\n if ans.nil?\n ans = k\n else\n ans = [ans, k].min\n end\nend\n\nif ans.nil?\n puts -1\nelse\n puts ans\nend"}], "negative_code": [{"source_code": "particleNum = gets.chomp.to_i\ndirections = gets.chomp.split('')\nparticles = gets.chomp.split(' ').map(&:to_i)\n\nfoundRight = false\nposRight = 0\n\nans = -1\n\nfor i in 0...particleNum\n\tfoundRight = true if directions[i] == 'R'\n\tposRight = i if directions[i] == 'R'\n\n\tif foundRight && directions[i] == 'L'\n\t\tans = particles[i] - ((particles[posRight] + particles[i]) / 2)\n\t\tbreak\n\tend\nend\n\nputs ans"}], "src_uid": "ff0843cbd7c3a07c7d7d0be46b03a700"} {"source_code": "n=gets.to_i\na=gets.split(\" \")\ns=Array.new(1111111,0)\nans=id=0\na.each do |v|\n\tx=v.to_i\n\ty = (s[x]+=1)\n\tif ans x then\n\t\tx = h[a[i]]\n\t\ty = a[i]\n\tend\n\nend\n\nputs y"}], "negative_code": [], "src_uid": "e4a2354159fc4cab7088e016cf17ae6c"} {"source_code": "gets.chomp\na = gets.chomp.split(\" \").map(&:to_i)\neven = a.select(&:even?).sort\nodd = a.select(&:odd?).sort\n\nelements_sum = 0\neven_size_diff = even.size - odd.size - 1\nodd_size_diff = odd.size - even.size - 1\n\nelements_sum = even[0..even_size_diff-1].reduce(0, :+) if even_size_diff > 0 \nelements_sum = odd[0..odd_size_diff-1].reduce(0,:+) if odd_size_diff > 0 \n\nputs elements_sum\n", "positive_code": [{"source_code": "\nn = gets.strip.to_i\na = gets.strip.split(\" \").map(&:to_i)\n\nodds = a.select(&:odd?)\nevens = a.select(&:even?)\n\nres = 0\ndiff_size = (odds.size - evens.size).abs\nif diff_size <= 1\n res = 0\nelse\n arr = (odds.size > evens.size) ? odds : evens\n res = arr.sort[0..(diff_size-2)].reduce(&:+)\nend\n\nputs res\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nx = [[],[]]\nn.times do |i|\n x[a[i]%2] << a[i]\nend\nif (x[0].size-x[1].size).abs <= 1\n puts 0\nelse\n x[0],x[1] = x[1],x[0] if x[0].size > x[1].size\n m = x[0].size\n puts x[1][0..-m-2].inject(:+)\nend"}], "negative_code": [], "src_uid": "b80fed46a9e2356dad03dd3ec01523d4"} {"source_code": "# coding: utf-8\n\nt = gets.to_i\n\ndef required(h)\n 2 * (h*(h+1)/2) + ((h-1)*h/2)\nend\n\ndef near_max(ar, v)\n b, e = 0, ar.length\n while b < e\n mid = (b + e)/2\n if v < ar[mid]\n if e - b == 1\n return ar[b]\n else\n e = mid\n end\n elsif v > ar[mid]\n if e - b == 1\n return ar[b]\n else\n b = mid\n end\n else\n return ar[mid]\n end\n end\nend\nprecalc = [0]\nfor i in 1..25900\n precalc << required(i)\nend\n# p precalc\n# puts near_max(precalc, 10**9)\nt.times {\n n = gets.to_i # the number of cards (1<=n<=10**9)\n # if h, required_cards = 2*(from 1 to h, sum) + (from 0 to h-1, sum)\n # h*h + h + h*h/2 - h/2\n pyramids = 0\n while n >= 2\n subtractor = near_max(precalc, n)\n\n if subtractor == 0\n break\n else\n pyramids += 1\n n -= subtractor\n end\n end\n puts pyramids\n\n}", "positive_code": [{"source_code": "t = gets.to_i\n\n0.upto t-1 do\n card = gets.to_i\n count = 0\n h = 1 # height\n while card > 1 do\n h = 1\n while card > 1 do\n if card >= (2*h + (h-1))\n card -= (2*h + (h-1))\n h += 1\n if card == 0 or card == 1\n count += 1\n end\n else\n count += 1\n break\n end\n end\n end\n puts count\nend"}], "negative_code": [], "src_uid": "02062d1afe85e3639edddedceac304f4"} {"source_code": "n = gets.to_i\na = gets.split(' ')\ns = gets\nori = 0\nfor i in 0..n-1\n\ta[i] = a[i].to_i\n\tif s[i]=='B'\n\t\tori+=a[i]\n\t\ta[i]=-a[i]\n\tend\nend\ntot = ans = ori\na.each do |v|\n\ttot+=v\n\tans = [ans, tot].max\nend\ntot = ori\na.reverse_each do |v|\n\ttot+=v\n\tans = [ans, tot].max\nend\nputs ans", "positive_code": [{"source_code": "n = gets.chomp.to_i\npieces = gets.chomp.split(\" \").map(&:to_i)\nteams = gets.chomp\n\ninit = 0\n\nn.times do |i|\n init += pieces[i] if teams[i] == \"B\"\nend\n\nret = init\n\n# left\ncurr = init\nn.times do |i|\n if teams[i] == \"A\" then\n curr += pieces[i]\n else\n curr -= pieces[i]\n end\n if curr > ret then\n ret = curr\n end\nend\n\n\n# right\ncurr = init\n(n - 1).downto(0) do |i|\n if teams[i] == \"A\" then\n curr += pieces[i]\n else\n curr -= pieces[i]\n end\n if curr > ret then\n ret = curr\n end\nend\n\nputs ret\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ')\ns = gets\nori = 0\nfor i in 0..n-1\n\ta[i] = a[i].to_i\n\tif s[i]=='B'\n\t\tori+=a[i]\n\t\ta[i]=-a[i]\n\tend\nend\ntot = ans = ori\nfor i in 0..n-1\n\ttot+=a[i]\n\tans = [ans, tot].max\nend\ntot = ori\ni=n-1\nwhile i>=0\n\ttot+=a[i]\n\tans = [ans, tot].max\n\ti-=1\nend\nputs ans"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\na=gets.split.map(&:to_i)\ns=gets.chomp.bytes\nr=0\nn.times{|i|r+=a[i] if s[i]==66}\nr0=r1=r\nn.times{|i|\n\tif s[i]==65\n\t\tr0+=a[i]\n\telse\n\t\tr0-=a[i]\n\tend\n\tr=[r,r0].max\n}\n(n-1).downto(0){|i|\n\tif s[i]==65\n\t\tr1+=a[i]\n\telse\n\t\tr1-=a[i]\n\tend\n\tr=[r,r1].max\n}\np r"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.split(' ')\ns = gets\nexit if n>400000\nori = 0\nfor i in 0..n-1\n\tori+=a[i].to_i if s[i]=='B'\nend\ntot = ans = ori\nfor i in 0..n-1\n\ttot+=a[i].to_i if s[i]=='A'\n\ttot-=a[i].to_i if s[i]=='B'\n\tans = [ans, tot].max\nend\ntot = ori\ni=n-1;\nwhile i>=0\n\ttot+=a[i].to_i if s[i]=='A'\n\ttot-=a[i].to_i if s[i]=='B'\n\tans = [ans, tot].max\n\ti-=1\nend\nputs ans"}, {"source_code": "n = gets.to_i\na = gets.split(' ')\ns = gets\nori = 0\nfor i in 0..n-1\n\ta[i] = a[i].to_i\n\tori+=a[i] if s[i]=='B'\nend\nexit if n>400000\ntot = ans = ori\nfor i in 0..n-1\n\ttot+=a[i] if s[i]=='A'\n\ttot-=a[i] if s[i]=='B'\n\tans = [ans, tot].max\nend\ntot = ori\ni=n-1\nwhile i>=0\n\ttot+=a[i] if s[i]=='A'\n\ttot-=a[i] if s[i]=='B'\n\tans = [ans, tot].max\n\ti-=1\nend\nputs ans"}, {"source_code": "n = gets.to_i\na = gets.split(' ')\ns = gets\nori = 0\nfor i in 0..n-1\n\ta[i] = a[i].to_i\n\tori+=a[i] if s[i]=='B'\nend\ntot = ans = ori\nfor i in 0..n-1\n\ttot+=a[i] if s[i]=='A'\n\ttot-=a[i] if s[i]=='B'\n\tans = [ans, tot].max\nend\nexit if n>400000\ntot = ori\ni=n-1\nwhile i>=0\n\ttot+=a[i] if s[i]=='A'\n\ttot-=a[i] if s[i]=='B'\n\tans = [ans, tot].max\n\ti-=1\nend\nputs ans"}, {"source_code": "n = gets.chomp.to_i\npieces = gets.chomp.split(\" \").map(&:to_i)\nteams = gets.chomp.split(\"\")\n\ninit = 0\n\nn.times do |i|\n init += pieces[i] if teams[i] == \"B\"\nend\nret = init\n\n# left\ncurr = init\nn.times do |i|\n break if teams[i] == \"B\"\n curr += pieces[i]\nend\nret = [ret, curr].max\n\n# right\ncurr = init\n(n - 1).downto(0) do |i|\n break if teams[i] == \"B\"\n curr += pieces[i]\nend\nret = [ret, curr].max\n\nputs ret"}], "src_uid": "d1926feaeec151f4a2f186a46a863d90"} {"source_code": "$n, $m, $k = gets.split.map(&:to_i)\n\n$results = Array.new($m, 0)\n# $results = []\n\ndef spiders_indersection(line, position, direction)\n index = nil\n case direction\n when 'L'\n index = position - line\n when 'R'\n index = position + line\n when 'U'\n index = position unless line.odd?\n end\n # if index\n # $results[index] = ($results[index] || 0) + 1\n # end\n if (index && index >= 0 && index < $m)\n # puts [index, position, line].join(' ')\n $results[index] += 1\n end\nend\n\n$n.times do |i|\n gets.chars.first($m).each_with_index do |char, j|\n spiders_indersection(i, j, char)\n end\nend\n\nputs $results.first($m).join(' ')", "positive_code": [{"source_code": "n,m,k = readline.strip.split.map(&:to_i)\n\ninit_field = n.times.map {\n readline.strip\n}\nres = Array.new(m, 0)\n\ninit_field.each_with_index{|line, row_idx|\n line.each_char.with_index{|cell, col_idx|\n if cell == 'L'\n col_corr = col_idx - row_idx\n res[col_corr] += 1 if col_corr >= 0\n elsif cell == 'R'\n col_corr = col_idx + row_idx\n res[col_corr] += 1 if col_corr < m\n elsif cell == 'U' && row_idx % 2 == 0\n res[col_idx] += 1\n end\n }\n}\n\nputs res.join(' ')\n\n"}], "negative_code": [{"source_code": "$n, $m, $k = gets.split.map(&:to_i)\n\n$results = Array.new(2*$m, 0)\n\ndef spiders_indersection(line, position, direction)\n # $m.times do |omnom_start_position|\n # met = case direction\n # when 'L'\n # position - line == omnom_start_position\n # when 'R'\n # omnom_start_position == line + position\n # when 'U'\n # omnom_start_position == position\n # else\n # false\n # end\n # $results[omnom_start_position] += 1 if met\n # end\n\n case direction\n when 'L'\n $results[position - line] += 1\n when 'R'\n $results[position + line] += 1\n when 'U'\n $results[position] += 1\n end\nend\n\n$n.times do |i|\n gets.chars.first($m).each_with_index do |char, j|\n spiders_indersection(i, j, char)\n end\nend\n\nputs $results.first($m).join(' ')"}, {"source_code": "$n, $m, $k = gets.split.map(&:to_i)\n\n$results = Array.new($m, 0)\n\ndef spiders_indersection(line, position, direction)\n index = -1\n case direction\n when 'L'\n index = position - line\n when 'R'\n index = position + line\n when 'U'\n index = position if line > 1\n end\n $results[index] += 1 if (index >= 0 && index < $m)\nend\n\n$n.times do |i|\n gets.chars.first($m).each_with_index do |char, j|\n spiders_indersection(i, j, char)\n end\nend\n\nputs $results.first($m).join(' ')"}, {"source_code": "$n, $m, $k = gets.split.map(&:to_i)\n\n$results = Array.new($m, 0)\n# $results = []\n\ndef spiders_indersection(line, position, direction)\n index = nil\n case direction\n when 'L'\n index = position - line\n when 'R'\n index = position + line\n when 'U'\n index = position if line > 1\n end\n # if index\n # $results[index] = ($results[index] || 0) + 1\n # end\n if (index && index >= 0)\n # puts [index, position, line].join(' ')\n # $results[index] += 1\n $results[index] = ($results[index] || 0) + 1\n end\nend\n\n$n.times do |i|\n gets.chars.first($m).each_with_index do |char, j|\n spiders_indersection(i, j, char)\n end\nend\n\nputs $results.first($m).join(' ')"}], "src_uid": "d8c89bb83592a1ff1b639f7d53056d67"} {"source_code": "d,h,v,e=gets.split.map(&:to_f)\nv/=Math::PI*d*d/4\nputs v= v\n puts \"NO\"\nelse\n puts \"YES\"\n puts (pi * d * d / 4.0 * h) / (v - inc)\nend\n"}, {"source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\npi=3.141592653589793\nx=(4*a[2])/((a[0]**2)*pi)\nif x>a[3]\nk=x-a[3]\ntime=a[1]/k\n\nif time<=10000\nputs\"YES\"\nputs\"#{time}\"\nelse\nputs\"NO\"\nend\n\nelse\nputs \"NO\"\nend\n"}, {"source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\npi=3.141592653589793\nx=(4*a[2])/((a[0]**2)*pi)\nif x>a[3]\nk=x-a[3]\ntime=a[1]/k\n\nif time<=10000\nputs\"YES\"\nputs\"#{time}\"\nelse\nputs\"NO\"\nend\n\nelse\nputs \"NO\"\nend"}, {"source_code": "d,h,v,e=gets.split.map(&:to_f)\nv/=Math::PI*d*d/4\nputs v e\n\tputs \"YES\"\n\tans = h / (v / s - e)\n\tputs \"%.12f\" % ans\nelse\n\tputs \"NO\"\nend"}, {"source_code": "input = gets.chomp.split(' ').map {|i| i.to_i}\nd, h, v, e = input[0], input[1], input[2], input[3]\n\ndecreaseSpeed = (4 * v) / ((d ** 2) * Math::PI)\nans = h / (decreaseSpeed - e)\n\nif ans < 0\n\tputs 'NO'\nelse\n\tputs 'YES'\n\tputs ans\nend"}], "negative_code": [{"source_code": "input = gets.chomp.split(' ').map {|i| i.to_i}\nd, h, v, e = input[0], input[1], input[2], input[3]\n\ndecreaseSpeed = (4 * v) / ((d ** 2) * Math::PI)\nans = h / (decreaseSpeed - e)\n\nif ans < 0\n\tputs 'NO'\nelse\n\tputs ans\nend"}], "src_uid": "fc37ef81bb36f3ac07ce2c4c3ec10d98"} {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\n\nq = gets.to_i\nq.times do\n lrd = gets.chomp.split(\" \").map(&:to_i)\n l = lrd[0]\n r = lrd[1]\n d = lrd[2]\n if d= l && re <= r\n re += d * (1 + (r - re) / d)\n end\n re\nend\n\n# Input\nq = gets.to_i\nresult = Array.new(q)\nq.times { |i| result[i] = process(*gets.split(\" \").map { |e| e.to_i }) }\n\n# Output\nputs result\n"}, {"source_code": "gets.to_i.times {\na = gets.split(' ').map{|i|i.to_i}\n (eval('puts a[2];') && next) if a[2] 1\n for i in (1..(low - 1)) do\n if i % div == 0\n min_int = i\n break\n end\n end\n end\n\n return min_int if min_int > 0\n\n for i in ((high + 1)..MAX_NUMBER) do\n if i % div == 0\n min_int = i\n break\n end\n end\n\n return min_int\nend\n\n# Codeforces required setup\ns = gets.rstrip\n\nresult = minimum_integer s\nputs result\n\n\n\n\n\n\n"}, {"source_code": "# You are given \ud835\udc5e queries in the following form:\n\n# Given three integers \ud835\udc59\ud835\udc56, \ud835\udc5f\ud835\udc56 and \ud835\udc51\ud835\udc56, find minimum\n# positive integer \ud835\udc65\ud835\udc56 such that it is divisible by \ud835\udc51\ud835\udc56 and\n# it does not belong to the segment [\ud835\udc59\ud835\udc56,\ud835\udc5f\ud835\udc56].\n\n# Can you answer all the queries?\n\n# Recall that a number \ud835\udc65 belongs to segment [\ud835\udc59,\ud835\udc5f] if \ud835\udc59\u2264\ud835\udc65\u2264\ud835\udc5f.\n\n# Input\n# The first line contains one integer \ud835\udc5e (1\u2264\ud835\udc5e\u2264500) \u2014 the number of queries.\n\n# Then \ud835\udc5e lines follow, each containing a query given in\n# the format \ud835\udc59\ud835\udc56 \ud835\udc5f\ud835\udc56 \ud835\udc51\ud835\udc56 (1\u2264\ud835\udc59\ud835\udc56\u2264\ud835\udc5f\ud835\udc56\u2264109, 1\u2264\ud835\udc51\ud835\udc56\u2264109). \ud835\udc59\ud835\udc56, \ud835\udc5f\ud835\udc56 and \ud835\udc51\ud835\udc56 are integers.\n\n# Output\n# For each query print one integer: the answer to this query.\n\n# Example\n# Input\n# 5\n# 2 4 2\n# 5 10 4\n# 3 10 1\n# 1 2 3\n# 4 6 5\n\n# Output\n# 6\n# 4\n# 1\n# 3\n# 10\n\nMAX_NUMBER = 1_000_000_000\n\ndef minimum_integer(queries)\n queries.each do |query|\n query = query.split(' ')\n\n return 0 unless query.length == 3\n\n low = query.first.to_i\n high = query[1].to_i\n div = query.last.to_i\n\n min_int = 0\n\n if low > 1\n for i in (1..(low - 1)) do\n if i % div == 0\n min_int = i\n break\n end\n end\n end\n\n return min_int if min_int > 0\n\n for i in ((high + 1)..MAX_NUMBER) do\n if i % div == 0\n min_int = i\n break\n end\n end\n\n puts min_int.to_i\n end\nend\n\n# Codeforces required setup\nnumber_of_queries = gets.rstrip.to_i\n\nqueries = []\n\nnumber_of_queries.times do |query|\n queries << gets.rstrip\nend\n\nresult = minimum_integer queries\nputs result\n\n\n\n\n\n\n"}, {"source_code": "# You are given \ud835\udc5e queries in the following form:\n\n# Given three integers \ud835\udc59\ud835\udc56, \ud835\udc5f\ud835\udc56 and \ud835\udc51\ud835\udc56, find minimum\n# positive integer \ud835\udc65\ud835\udc56 such that it is divisible by \ud835\udc51\ud835\udc56 and\n# it does not belong to the segment [\ud835\udc59\ud835\udc56,\ud835\udc5f\ud835\udc56].\n\n# Can you answer all the queries?\n\n# Recall that a number \ud835\udc65 belongs to segment [\ud835\udc59,\ud835\udc5f] if \ud835\udc59\u2264\ud835\udc65\u2264\ud835\udc5f.\n\n# Input\n# The first line contains one integer \ud835\udc5e (1\u2264\ud835\udc5e\u2264500) \u2014 the number of queries.\n\n# Then \ud835\udc5e lines follow, each containing a query given in\n# the format \ud835\udc59\ud835\udc56 \ud835\udc5f\ud835\udc56 \ud835\udc51\ud835\udc56 (1\u2264\ud835\udc59\ud835\udc56\u2264\ud835\udc5f\ud835\udc56\u2264109, 1\u2264\ud835\udc51\ud835\udc56\u2264109). \ud835\udc59\ud835\udc56, \ud835\udc5f\ud835\udc56 and \ud835\udc51\ud835\udc56 are integers.\n\n# Output\n# For each query print one integer: the answer to this query.\n\n# Example\n# Input\n# 5\n# 2 4 2\n# 5 10 4\n# 3 10 1\n# 1 2 3\n# 4 6 5\n\n# Output\n# 6\n# 4\n# 1\n# 3\n# 10\n\nMAX_NUMBER = 1_000_000_000\n\ndef minimum_integer(queries)\n queries.each do |query|\n query = query.split(' ')\n\n return 0 unless query.length == 3\n\n low = query.first.to_i\n high = query[1].to_i\n div = query.last.to_i\n\n min_int = 0\n\n if low > 1\n for i in (1..(low - 1)) do\n if i % div == 0\n min_int = i\n break\n end\n end\n end\n\n if min_int == 0\n for i in ((high + 1)..MAX_NUMBER) do\n if i % div == 0\n min_int = i\n break\n end\n end\n end\n\n puts min_int.to_i\n end\n\n return nil\nend\n\n# Codeforces required setup\nnumber_of_queries = gets.rstrip.to_i\n\nqueries = []\n\nnumber_of_queries.times do |query|\n queries << gets.rstrip\nend\n\nresult = minimum_integer queries\nputs result\n\n\n\n\n\n\n"}, {"source_code": "# You are given \ud835\udc5e queries in the following form:\n\n# Given three integers \ud835\udc59\ud835\udc56, \ud835\udc5f\ud835\udc56 and \ud835\udc51\ud835\udc56, find minimum\n# positive integer \ud835\udc65\ud835\udc56 such that it is divisible by \ud835\udc51\ud835\udc56 and\n# it does not belong to the segment [\ud835\udc59\ud835\udc56,\ud835\udc5f\ud835\udc56].\n\n# Can you answer all the queries?\n\n# Recall that a number \ud835\udc65 belongs to segment [\ud835\udc59,\ud835\udc5f] if \ud835\udc59\u2264\ud835\udc65\u2264\ud835\udc5f.\n\n# Input\n# The first line contains one integer \ud835\udc5e (1\u2264\ud835\udc5e\u2264500) \u2014 the number of queries.\n\n# Then \ud835\udc5e lines follow, each containing a query given in\n# the format \ud835\udc59\ud835\udc56 \ud835\udc5f\ud835\udc56 \ud835\udc51\ud835\udc56 (1\u2264\ud835\udc59\ud835\udc56\u2264\ud835\udc5f\ud835\udc56\u2264109, 1\u2264\ud835\udc51\ud835\udc56\u2264109). \ud835\udc59\ud835\udc56, \ud835\udc5f\ud835\udc56 and \ud835\udc51\ud835\udc56 are integers.\n\n# Output\n# For each query print one integer: the answer to this query.\n\n# Example\n# Input\n# 5\n# 2 4 2\n# 5 10 4\n# 3 10 1\n# 1 2 3\n# 4 6 5\n\n# Output\n# 6\n# 4\n# 1\n# 3\n# 10\n\nMAX_NUMBER = 1_000_000_000\n\ndef minimum_integer(queries)\n queries.each do |query|\n query = query.split(' ')\n\n return 0 unless query.length == 3\n\n low = query.first.to_i\n high = query[1].to_i\n div = query.last.to_i\n\n min_int = 0\n\n if low > 1\n for i in (1..(low - 1)) do\n if i % div == 0\n min_int = i\n break\n end\n end\n end\n\n if min_int == 0\n for i in ((high + 1)..Float::INFINITY) do\n if i % div == 0\n min_int = i\n break\n end\n end\n end\n\n puts min_int.to_i\n end\nend\n\n# Codeforces required setup\nnumber_of_queries = gets.rstrip.to_i\n\nqueries = []\n\nnumber_of_queries.times do |query|\n queries << gets.rstrip\nend\n\nresult = minimum_integer queries\nputs result\n\n\n\n\n\n\n"}], "src_uid": "091e91352973b18040e2d57c46f2bf8a"} {"source_code": "t = gets.chomp.to_i\nt.times do |testcase|\n a,b = gets.split.map(&:to_i)\n c = (a-b).abs\n puts ( c/5 + (c%5)/2 + (c%5)%2 )\nend", "positive_code": [{"source_code": "t = gets.to_i\nop = [-5, 2, -1, 1, 2, 5]\nt.times do\n a, b = gets.split.map(&:to_i)\n ans = (a-b).abs/5\n a += (a-b) < 0 ? ans*5 : -ans*5\n if (a-b).abs == 0\n elsif (a-b).abs <= 2\n ans += 1\n else\n ans += 2\n end\n puts ans\nend\n"}, {"source_code": "def lol\n\tb, a = gets.chomp.split(\" \").map { |e| e.to_i}\n\tif a > b\n\t\ta -= b\n\telse\n\t\ta = b - a\n\tend\n\tk = a/5\n\tif a%5 == 0 \n\t\tp k\n\telsif a%5 == 1\n\t\tp k + 1\n\telsif a%5 == 2\n\t\tp k + 1\n\telsif a%5 == 3\n\t\tp k + 2\n\telsif a%5 == 4\n\t\tp k + 2\n\tend\n\t\t\t\n\nend\n\nn = gets.chomp.to_i\n\nn.times do\n\tlol\nend"}], "negative_code": [], "src_uid": "ccfe798f5dc63c492ff54cf40bb40613"} {"source_code": "t = gets.chomp.to_i\n\n\nfor i in 1..t\n n = gets.chomp.to_i\n s = gets.chomp\n \n p = 0\n c = 0\n for j in 0..n-1\n ch = s[j]\n if ch == '('\n c+=1\n else\n c-=1\n end\n\n if c < 0\n p+=1 \n c = 0\n end \n end\n puts p\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ts = gets.chomp\n\twhile s.gsub!('()', ''); end\n\tputs s.size / 2\nend\n"}, {"source_code": "t = (gets || \"\").to_i\nt.times do\n\tcnt = 0\n\tneg = 0\n\tn = (gets || \"\").to_i\n\ts = (gets || \"\").chomp\n\n\ts.each_char do |c|\n\t\tcase c\n\t\twhen '('\n\t\t\tcnt += 1\n\t\twhen ')'\n\t\t\tcnt -= 1\n\t\tend\n\t\tif cnt < 0\n\t\t\tneg -= cnt\n\t\t\tcnt = 0\n\t\tend\n\tend\n\n\tp [neg, cnt].max\nend\n"}, {"source_code": "def run\n n = gets.chomp.to_i\n s = gets.chomp\n st = 0\n min_st = 0\n\n s.each_char do |ch|\n if ch == \"(\"\n st += 1\n else\n st -= 1\n if st < min_st\n min_st = st\n end\n end\n end\n\n puts min_st.abs\nend\n\n\ndef main\n t = gets.chomp.to_i\n\n t.times do\n run\n end\nend\n\nmain\n"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n nn = gets.chomp.to_i\n arr = Array.new(nn,0)\n kakko = gets.chomp.split(\"\")\n mezirusi = 1\n count = 0\n while true\n if kakko[mezirusi-1] == \"(\" && kakko[mezirusi] == \")\"\n kakko[mezirusi-1] = \" \" \n kakko[mezirusi] = \" \"\n kakko = kakko.join(\"\").gsub(\" \", \"\")\n kakko = kakko.split(\"\")\n ookisa = kakko.size\n if kakko == []\n kakko_size = 0\n break\n end\n mezirusi = 1\n else\n mezirusi += 1\n if kakko[mezirusi] == nil\n break\n end\n end\n \n end\n kakko_size = kakko.size\n if kakko.count(\"(\") != kakko.count(\")\")\n puts \"-1\"\n next\n elsif kakko_size % 2 == 0\n puts kakko_size /2\n next\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n nn = gets.chomp.to_i\n arr = Array.new(nn,0)\n kakko = gets.chomp.split(\"\")\n#p kakko\n mezirusi = 1\n #while\n count = 0\n #2.times do\n while true\n if kakko[mezirusi-1] == \"(\" && kakko[mezirusi] == \")\"\n kakko[mezirusi-1] = \" \" \n kakko[mezirusi] = \" \"\n kakko = kakko.join(\"\").gsub(\" \", \"\")\n #p kakko\n kakko = kakko.split(\"\")\n # p kakko\n ookisa = kakko.size\n #kakko = kakko.delte(\" \")\n #p kakko\n if kakko == []\n kakko_size = 0\n break\n end\n #mezirusi -= 1\n # if kakko[mezirusi] == nil && mezirusi >= 1\n # mezirusi -= 1\n # end\n mezirusi = 1\n else\n mezirusi += 1\n #p mezirusi\n #puts \"UU\"\n if kakko[mezirusi] == nil\n break\n end\n end\n \n end\n #p kakko.size\n #puts \"UUUUUUUUU\"\n kakko_size = kakko.size\n # p kakko\n # p kakko.count(\"(\")\n if kakko.count(\"(\") != kakko.count(\")\")\n puts \"-1\"\n next\n elsif kakko_size % 2 == 0\n puts kakko_size /2\n next\n end\n \nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n nn = gets.chomp.to_i\n kakko = gets.chomp.split(\"\")\n mezirusi = 1\n while true\n if kakko[mezirusi-1] == \"(\" && kakko[mezirusi] == \")\"\n kakko[mezirusi-1] = \" \" \n kakko[mezirusi] = \" \"\n kakko = kakko.join(\"\").gsub(\" \", \"\")\n kakko = kakko.split(\"\")\n ookisa = kakko.size\n if kakko == []\n kakko_size = 0\n break\n end\n mezirusi = 1\n else\n mezirusi += 1\n if kakko[mezirusi] == nil\n break\n end\n end\n end\n kakko_size = kakko.size\n if kakko.count(\"(\") != kakko.count(\")\")\n puts \"-1\"\n next\n else\n puts kakko_size /2\n next\n end\nend"}, {"source_code": "gets.to_i.times do\n ans = 0\n n = gets.to_i\n s = gets.chomp\n s.chars.inject(0) do |state, x|\n state += 1 if x == '('\n state -= 1 if x == ')'\n if state < 0\n state += 1\n ans += 1\n end\n state\n end\n puts ans\nend\n\n"}, {"source_code": "gets.to_i.times do\n gets\n a = gets.chomp.split('')\n result = 0\n\n while !a.size.zero?\n x = a.shift\n\n case x\n when '('\n a.delete_at(a.index(')')) if a.index(')')\n when ')'\n result += 1\n end\n end\n\n puts result\nend\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nn.times do \n nn = gets.chomp.to_i\n arr = Array.new(nn,0)\n kakko = gets.chomp.split(\"\")\np kakko\n mezirusi = 1\n #while\n count = 0\n #2.times do\n while true\n if kakko[mezirusi-1] == \"(\" && kakko[mezirusi] == \")\"\n kakko[mezirusi-1] = \" \" \n kakko[mezirusi] = \" \"\n kakko = kakko.join(\"\").gsub(\" \", \"\")\n #p kakko\n kakko = kakko.split(\"\")\n # p kakko\n ookisa = kakko.size\n #kakko = kakko.delte(\" \")\n #p kakko\n if kakko == []\n kakko_size = 0\n break\n end\n #mezirusi -= 1\n if kakko[mezirusi] == nil && mezirusi >= 1\n mezirusi -= 1\n end\n #p mezirusi\n else\n mezirusi += 1\n #p mezirusi\n #puts \"UU\"\n if kakko[mezirusi] == nil\n break\n end\n end\n\n end\n #p kakko.size\n #puts \"UUUUUUUUU\"\n kakko_size = kakko.size\n if kakko_size % 2 == 1\n puts \"-1\"\n elsif kakko_size % 2 == 0\n puts kakko_size /2\n end\n\nend"}, {"source_code": "\nn = gets.chomp.to_i\nn.times do \n nn = gets.chomp.to_i\n arr = Array.new(nn,0)\n kakko = gets.chomp.split(\"\")\n#p kakko\n mezirusi = 1\n #while\n #count = 0\n #2.times do\n while true\n if kakko[mezirusi-1] == \"(\" && kakko[mezirusi] == \")\"\n kakko[mezirusi-1] = \" \" \n kakko[mezirusi] = \" \"\n kakko = kakko.join(\"\").gsub(\" \", \"\")\n #p kakko\n kakko = kakko.split(\"\")\n # p kakko\n ookisa = kakko.size\n #kakko = kakko.delte(\" \")\n #p kakko\n if kakko == []\n kakko_size = 0\n break\n end\n #mezirusi -= 1\n if kakko[mezirusi] == nil && mezirusi >= 1\n mezirusi -= 1\n end\n #p mezirusi\n else\n mezirusi += 1\n #p mezirusi\n #puts \"UU\"\n if kakko[mezirusi] == nil\n break\n end\n end\n \n end\n #p kakko.size\n #puts \"UUUUUUUUU\"\n kakko_size = kakko.size\n # p kakko\n # p kakko.count(\"(\")\n if kakko.count(\"(\") != kakko.count(\")\")\n puts \"-1\"\n next\n elsif kakko_size % 2 == 0\n puts kakko_size /2\n next\n end\n \nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n nn = gets.chomp.to_i\n arr = Array.new(nn,0)\n kakko = gets.chomp.split(\"\")\n#p kakko\n mezirusi = 1\n #while\n count = 0\n #2.times do\n while true\n if kakko[mezirusi-1] == \"(\" && kakko[mezirusi] == \")\"\n kakko[mezirusi-1] = \" \" \n kakko[mezirusi] = \" \"\n kakko = kakko.join(\"\").gsub(\" \", \"\")\n #p kakko\n kakko = kakko.split(\"\")\n # p kakko\n ookisa = kakko.size\n #kakko = kakko.delte(\" \")\n #p kakko\n if kakko == []\n kakko_size = 0\n break\n end\n #mezirusi -= 1\n if kakko[mezirusi] == nil && mezirusi >= 1\n mezirusi -= 1\n end\n #p mezirusi\n else\n mezirusi += 1\n #p mezirusi\n #puts \"UU\"\n if kakko[mezirusi] == nil\n break\n end\n end\n \n end\n #p kakko.size\n #puts \"UUUUUUUUU\"\n kakko_size = kakko.size\n # p kakko\n # p kakko.count(\"(\")\n if kakko.count(\"(\") != kakko.count(\")\")\n puts \"-1\"\n next\n elsif kakko_size % 2 == 0\n puts kakko_size /2\n next\n end\n \nend"}, {"source_code": "\nn = gets.chomp.to_i\nn.times do \n nn = gets.chomp.to_i\n arr = Array.new(nn,0)\n kakko = gets.chomp.split(\"\")\n#p kakko\n mezirusi = 1\n #while\n count = 0\n #2.times do\n while true\n if kakko[mezirusi-1] == \"(\" && kakko[mezirusi] == \")\"\n kakko[mezirusi-1] = \" \" \n kakko[mezirusi] = \" \"\n kakko = kakko.join(\"\").gsub(\" \", \"\")\n #p kakko\n kakko = kakko.split(\"\")\n # p kakko\n ookisa = kakko.size\n #kakko = kakko.delte(\" \")\n #p kakko\n if kakko == []\n kakko_size = 0\n break\n end\n #mezirusi -= 1\n if kakko[mezirusi] == nil && mezirusi >= 1\n mezirusi -= 1\n end\n #p mezirusi\n else\n mezirusi += 1\n #p mezirusi\n #puts \"UU\"\n if kakko[mezirusi] == nil\n break\n end\n end\n \n end\n #p kakko.size\n #puts \"UUUUUUUUU\"\n kakko_size = kakko.size\n # p kakko\n # p kakko.count(\"(\")\n if kakko.count(\"(\") != kakko.count(\")\")\n puts \"-1\"\n elsif kakko_size % 2 == 0\n puts kakko_size /2\n end\n \nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n nn = gets.chomp.to_i\n arr = Array.new(nn,0)\n kakko = gets.chomp.split(\"\")\n#p kakko\n mezirusi = 1\n #while\n count = 0\n #2.times do\n while true\n if kakko[mezirusi-1] == \"(\" && kakko[mezirusi] == \")\"\n kakko[mezirusi-1] = \" \" \n kakko[mezirusi] = \" \"\n kakko = kakko.join(\"\").gsub(\" \", \"\")\n #p kakko\n kakko = kakko.split(\"\")\n # p kakko\n ookisa = kakko.size\n #kakko = kakko.delte(\" \")\n p kakko\n if kakko == []\n kakko_size = 0\n break\n end\n #mezirusi -= 1\n # if kakko[mezirusi] == nil && mezirusi >= 1\n # mezirusi -= 1\n # end\n mezirusi = 1\n else\n mezirusi += 1\n #p mezirusi\n #puts \"UU\"\n if kakko[mezirusi] == nil\n break\n end\n end\n \n end\n #p kakko.size\n #puts \"UUUUUUUUU\"\n kakko_size = kakko.size\n # p kakko\n # p kakko.count(\"(\")\n if kakko.count(\"(\") != kakko.count(\")\")\n puts \"-1\"\n next\n elsif kakko_size % 2 == 0\n puts kakko_size /2\n next\n end\n \nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n nn = gets.chomp.to_i\n arr = Array.new(nn,0)\n kakko = gets.chomp.split(\"\")\n#p kakko\n mezirusi = 1\n #while\n count = 0\n #2.times do\n while true\n if kakko[mezirusi-1] == \"(\" && kakko[mezirusi] == \")\"\n kakko[mezirusi-1] = \" \" \n kakko[mezirusi] = \" \"\n kakko = kakko.join(\"\").gsub(\" \", \"\")\n #p kakko\n kakko = kakko.split(\"\")\n # p kakko\n ookisa = kakko.size\n #kakko = kakko.delte(\" \")\n #p kakko\n if kakko == []\n kakko_size = 0\n break\n end\n #mezirusi -= 1\n if kakko[mezirusi] == nil && mezirusi >= 1\n mezirusi -= 1\n end\n #p mezirusi\n else\n mezirusi += 1\n #p mezirusi\n #puts \"UU\"\n if kakko[mezirusi] == nil\n break\n end\n end\n\n end\n #p kakko.size\n #puts \"UUUUUUUUU\"\n kakko_size = kakko.size\n if kakko_size % 2 == 1\n puts \"-1\"\n elsif kakko_size % 2 == 0\n puts kakko_size /2\n end\n\nend"}, {"source_code": "class String\n def regular_bracket_sequence?\n if self.chars.inject(0) do |state, c|\n state += 1 if c == '('\n state -= 1 if c == ')'\n break false if state < 0\n state\n end then true else false end\n end\nend\ngets.to_i.times do\n ans = 0\n n = gets.to_i\n s = gets.chomp\n while not s.regular_bracket_sequence? do\n ans += 1\n idx = s.index(')')\n s[idx, idx + 1] = ''\n s << ')'\n end\n puts ans\nend\n\n"}], "src_uid": "7a724f327c6202735661be25ef9328d2"} {"source_code": "#!/usr/bin/ruby\nn,m=gets.split.map(&:to_i)\na=n.times.map{gets.split.map(&:to_i)}.transpose\n1.step(m-1){|i|a[i][0]+=a[i-1][0]}\n1.step(n-1){|j|a[0][j]+=a[0][j-1]}\n1.step(m-1){|i|1.step(n-1){|j|a[i][j]=[a[i-1][j],a[i][j-1]].map{|e|e+a[i][j]}.max}}\nputs a.last*' '", "positive_code": [{"source_code": "m,n=gets.chomp.split.map(&:to_i)\nt=[0,0,0,0,0]\nm.times do\n\ta=gets.chomp.split.map(&:to_i)\n\ta.length.times {|j| (j!=0 && t[j] 0\n\t\tcalc << dp[i-1][j] if i > 0\n\t\t\n\t\tdp[i][j] = calc.max + arr[i][j]\n\tend\nend\n\nans = []\ndp.each do |a|\n\tans << a[-1]\nend\nputs ans.join(\" \")"}], "negative_code": [], "src_uid": "43f4ea06d8b8b0b6b6795a3d526c5a2d"} {"source_code": "t = gets.chomp.to_i\nt.times do \n n, m = gets.chomp.split(' ').map(&:to_i)\n rows = []\n n.times do\n rows << gets.chomp.split(' ').map(&:to_i)\n end\n cols = []\n m.times do\n cols << gets.chomp.split(' ').map(&:to_i)\n end\n res = Array.new(n){[]}\n col_1 = cols.find {|el| el.include? rows[0][0]}\n hsh = {} \n col_1.each_with_index do |el, ind|\n hsh[el] = ind\n end\n rows.each do |row|\n res[hsh[row[0]]] = row\n end\n res.each do |el|\n puts el.join ' '\n end\nend ", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n n, m = gets.split.map(&:to_i)\n rows = n.times.map { gets.split.map(&:to_i) }\n cols = m.times.map { gets.split.map(&:to_i) }\n x = rows[0][0]\n k = 0\n while cols[k].index(x).nil? do\n k += 1\n end\n n.times do |i|\n v = rows[i][0]\n pos = cols[k].index(v) + 1\n rows[i].unshift(pos)\n end\n rows.sort! do |e, f|\n e[0] <=> f[0]\n end\n n.times do |i|\n rows[i].shift\n puts rows[i].join(\" \")\n end\nend\n"}], "negative_code": [], "src_uid": "0eab9d2dd60d38f68d49f30cff918fce"} {"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map(&:to_i).sort\nb = gets.chomp.split(\" \").map(&:to_i).sort\n\ndiff = 0\n\nturn = 1\n\n(2*n).times do\n\n if a[-1].nil?\n amax = 0\n else\n amax = a[-1]\n end\n\n if b[-1].nil?\n bmax = 0\n else\n bmax = b[-1]\n end\n=begin\n puts turn\n puts amax\n p a\n puts bmax\n p b\n puts\n=end\n if turn==1\n if amax>bmax\n diff += amax\n a.pop\n else\n b.pop\n end\n else\n if amax>bmax\n a.pop\n else\n diff -= bmax\n b.pop\n end\n end\n \n turn = 3-turn\n \nend\n\nputs diff", "positive_code": [{"source_code": "n = gets.strip.to_i\na1 = gets.strip.split.map(&:to_i)\na2 = gets.strip.split.map(&:to_i)\n\na1.sort!\na2.sort!\n\ns1=s2=0\ni1=i2=n-1\nt=0\n\nwhile i1>=0 || i2>=0 do\n if i1>=0 && i2>=0\n if a1[i1] > a2[i2]\n if t.even?\n s1 += a1[i1]\n end\n i1 -= 1\n else\n if t.odd?\n s2 += a2[i2]\n end\n i2 -= 1\n end\n else\n if i1<0\n s2 += a2[i2] if t.odd?\n i2 -= 1\n end\n if i2<0\n s1 += a1[i1] if t.even?\n i1 -= 1\n end\n end\n t += 1\nend\n\nputs s1-s2\n"}], "negative_code": [], "src_uid": "d740f4ee1b18eeb74dfb253125c52762"} {"source_code": "def main\n n = gets.chomp.to_i\n\n left = {}\n gets.chomp.chars.each_with_index {|c, i| if left[c].nil? then left[c] = [i + 1] else left[c] << i + 1 end}\n\n right = {}\n gets.chomp.chars.each_with_index {|c, i| if right[c].nil? then right[c] = [i + 1] else right[c] << i + 1 end}\n\n pairs = []\n\n for l in left.keys\n if l != '?'\n while left.key?(l) and right.key?(l)\n pairs << [left[l].last, right[l].last]\n left[l].pop\n right[l].pop\n left.delete(l) if left[l].empty? \n right.delete(l) if right[l].empty?\n end\n end\n end\n\n for l in left.keys\n while left.key?(l) and right.key?('?')\n pairs << [left[l].last, right['?'].last]\n left[l].pop\n right['?'].pop\n left.delete(l) if left[l].empty?\n right.delete('?') if right['?'].empty?\n end\n end\n\n for r in right.keys\n while right.key?(r) and left.key?('?')\n pairs << [left['?'].last, right[r].last]\n left['?'].pop\n right[r].pop\n left.delete('?') if left['?'].empty?\n right.delete(r) if right[r].empty?\n end\n end\n\n if left.key('?')\n while left.key('?') and right.key?('?')\n pairs << [left['?'].last, right['?'].last]\n left['?'].pop\n right['?'].pop\n left.delete('?') if left['?'].empty?\n right.delete('?') if right['?'].empty?\n end \n end\n\n puts pairs.size\n for p in pairs\n puts p.join(\" \")\n end\nend\n\nmain\n", "positive_code": [{"source_code": "N = gets.to_i\nL = gets.chomp\nR = gets.chomp\nlh,rh = (0..1).map{\n h = {}\n (\"a\"..\"z\").each{ |c| h[c] = [] }\n h[\"?\"] = []\n h\n}\n(1..N).each{ |i|\n cl = L[i-1]\n lh[cl] << i\n cr = R[i-1]\n rh[cr] << i\n}\nans = []\n(\"a\"..\"z\").each{ |c|\n while lh[c].size > 0 && rh[c].size > 0 do\n ans << [lh[c].pop, rh[c].pop]\n end\n}\n(\"a\"..\"z\").each{ |c|\n while lh[c].size > 0 && rh[\"?\"].size > 0 do\n ans << [lh[c].pop, rh[\"?\"].pop]\n end\n while lh[\"?\"].size > 0 && rh[c].size > 0 do\n ans << [lh[\"?\"].pop, rh[c].pop]\n end\n}\nwhile lh[\"?\"].size > 0 && rh[\"?\"].size > 0 do\n ans << [lh[\"?\"].pop, rh[\"?\"].pop]\nend\np ans.size\nans.each{ |l,r| puts \"#{l} #{r}\" }"}, {"source_code": "n = gets.to_i\na = gets.chomp\nb = gets.chomp\nl = Hash.new{|h,k|h[k] = []}\nr = Hash.new{|h,k|h[k] = []}\nn.times do |i|\n l[a[i]].push(i+1)\n r[b[i]].push(i+1)\nend\nans = []\ns = \"abcdefghijklmnopqrstuvwxyz?\"\n26.times do |i|\n t = [l[s[i]].size,r[s[i]].size].min\n t.times do |j|\n ans << [l[s[i]][-1],r[s[i]][-1]]\n l[s[i]].pop\n r[s[i]].pop\n end\nend\n26.times do |i|\n t = [l[s[i]].size,r[s[-1]].size].min\n t.times do |j|\n ans << [l[s[i]][-1],r[s[-1]][-1]]\n l[s[i]].pop\n r[s[-1]].pop\n end\nend\n26.times do |i|\n t = [l[s[-1]].size,r[s[i]].size].min\n t.times do |j|\n ans << [l[s[-1]][-1],r[s[i]][-1]]\n l[s[-1]].pop\n r[s[i]].pop\n end\nend\nt = [l[s[-1]].size,r[s[-1]].size].min\nt.times do |i|\n ans << [l[s[-1]][i],r[s[-1]][i]]\nend\nputs ans.size\nans.each do |arr|\n puts arr.join(\" \")\nend"}], "negative_code": [], "src_uid": "6bf3e5a542ebce81c1e6ce7260644a3c"} {"source_code": "n = gets.to_i\na = gets.split(\" \").map(&:to_i)\nr = (n - a[0]) % n\na.each_with_index{|x, i|\n if (x + r * (i.even? ? 1 : -1)) % n != i\n puts 'No'\n exit\n end\n}\nputs 'Yes'\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nx = a[0]\ndir = 1\n\nfor i in (0...n)\n\ta[i] += dir * x\n\t\n\tif a[i] < 0\n\t\ta[i] += n\n\telsif a[i] >= n\n\t\ta[i] -= n\n\tend\n\t\n\tdir *= -1\nend\n\nok = true\n\nfor i in (0...n)\n\tif a[i] != i\n\t\tok = false\n\t\tbreak\n\tend\nend\n\nif ok == true\n\tputs \"Yes\"\nelse\n\tdir = -1\n\tfor i in (0...n)\n\t\ta[i] += dir * 2 * x\n\t\t\n\t\twhile a[i] < 0\n\t\t\ta[i] += n\n\t\tend\n\t\t\n\t\twhile a[i] >= n\n\t\t\ta[i] -= n\n\t\tend\n\t\n\t\tdir *= -1\n\tend\n\t\n\tok = true\n\t\n\tfor i in (0...n)\n\t\tif a[i] != i\n\t\t\tok = false\n\t\t\tbreak\n\t\tend\n\tend\n\t\n\tputs ok == true ? \"Yes\" : \"No\"\nend\n"}, {"source_code": "gearNum = gets.chomp.to_i\nactive = gets.chomp.split(' ').map { |item| item.to_i}\nflag = true\nloopCount = 0\n\ndef proceedSwitch(active = nil, gearNum)\n=begin\n\tactive.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\n\tputs \"\"\n=end\n\tfor i in 0...active.length\n\t\tactive[i] += 1 if i % 2 == 0\n\t\tactive[i] -= 1 if i % 2 == 1\n\n\t\tactive[i] = 0 if active[i] == gearNum\n\t\tactive[i] = gearNum - 1 if active[i] < 0\n\tend\nend\n\nloop do\n\tproceedSwitch(active, gearNum)\n\n\tfor i in 0...active.length\n\t\tflag = false if active[i] != i\n\t\tbreak if flag == false\n\tend\n\n\tbreak if loopCount == gearNum\n\tbreak if flag == true\n\n\tloopCount += 1\n\tflag = true\nend\n\nputs \"YES\" if flag\nputs \"NO\" if !flag"}, {"source_code": "#!/usr/bin/ruby\nN=gets.to_i\nD,*A=gets.split.map(&:to_i)\nputs (1...N).all?{|i|i==(A[i-1]+[-D,D][i&1])%N} ? :Yes : :No"}, {"source_code": "def function\narr=[]\na=gets.chomp.to_i\nb=gets.chomp\narr=b.split.map(&:to_i)\nl=arr.length\nm=true\nl.times do |i|\nif arr==Array(0..arr.length-1)\nm=false\nbreak\nend\n0.upto l-1 do |i|\narr[i]=(arr[i]+1)%l if i%2==0\narr[i]=(arr[i]-1)%l if i%2!=0\nend\nend\nif m==true\nprint \"No\"\nelse\nprint \"Yes\"\nend\nend\nfunction\n"}, {"source_code": "n = gets.to_i\ngears = gets.split(' ')\ngears = gears.map{|i| i.to_i}\nshifts = n - gears.first\nstack = []\nreal = nil\ngears.each_with_index do |gear, index|\n if index%2==0 \n new_num = (gear+shifts)%n\n else\n new_num = (gear-shifts)%n\n end\n if stack.empty?\n stack.push(new_num)\n else\n if stack.last == new_num - 1\n stack.push(new_num)\n else\n real = 0\n break \n end\n end\nend\nif real == 0\n puts 'No'\nelse\n puts 'Yes'\nend\n"}, {"source_code": "n = Integer(gets)\nnums = gets.chomp.split\na = []\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\n\ngear = []\ngear[0] = a\nfor i in 1...n\n gear[i] = []\n for j in 0...n\n if j % 2 == 0\n if gear[i-1][j] + 1 == n\n gear[i].push(0)\n else\n gear[i].push(gear[i-1][j] + 1)\n end\n else\n if gear[i-1][j] == 0\n gear[i].push(n-1)\n else\n gear[i].push(gear[i-1][j] - 1)\n end\n end\n end\nend\npointer = 0\nfor i in 0...n\n for j in 0...n-1\n if gear[i][j + 1] > gear[i][j]\n pointer = 1\n else\n pointer = 0\n break\n end\n end\n if pointer == 1\n break\n end\nend\nif n == 1\n puts \"YES\"\nelse\n if pointer == 0\n puts \"NO\"\n else\n puts \"YES\"\n end\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nv = a[0]\nn.times do |i|\n a[i] += i.odd? ? v : -v\n a = a.map{|x| x % n}\nend\nputs a == (0...n).to_a ? 'Yes' : 'No'\n"}, {"source_code": "n = gets.to_i\nm, *a = gets.split.map(&:to_i)\n(n - 1).times{|i| a[i] += i.odd? ? -m : m}\na = a.map{|x| x % n}\nputs a == (1...n).to_a ? 'Yes' : 'No'\n"}], "negative_code": [{"source_code": "def function\narr=[]\na=gets.chomp.to_i\nb=gets.chomp\narr=b.split.map(&:to_i)\nl=arr.length\nm=true\nl.times do |i|\nif arr==Array(0..arr.length-1)\nm=false\nbreak\nend\n0.upto l-1 do |i|\narr[i]=(arr[i]+1)%l if i%2==0\narr[i]=(arr[i]-1)%l if i%2!=0\nend\nend\nif m==true\np \"No\"\nelse\np \"Yes\"\nend\nend\nfunction\n"}, {"source_code": "n = gets.to_i\ngears = gets.split(' ')\ngears = gears.map{|i| i.to_i}\nshifts = n - gears.first\nstack = []\nreal = nil\ngears.each_with_index do |gear, index|\n\tif index%2==0 \n\t\tnew_num = (gear+shifts)%n\n\telse\n\t\tnew_num = (gear-shifts)%n\n\tend\n\tif new_num == 0\n\t\tstack.push(new_num)\n\telse\n\t\tif stack.last == new_num - 1\n\t\t\tstack.push(new_num)\n\t\telse\n\t\t\treal = 0\n\t\t\tbreak\t\n\t\tend\n\tend\nend\nif real == 0\n\tputs 'No'\nelse\n\tputs 'Yes'\nend\n"}, {"source_code": "n = Integer(gets)\nnums = gets.chomp.split\na = []\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\n\ngear = []\ngear[0] = a\nfor i in 1...n\n gear[i] = []\n for j in 0...n\n if j % 2 == 0\n if gear[i-1][j] + 1 == n\n gear[i].push(0)\n else\n gear[i].push(gear[i-1][j] + 1)\n end\n else\n if gear[i-1][j] == 0\n gear[i].push(n-1)\n else\n gear[i].push(gear[i-1][j] - 1)\n end\n end\n end\nend\npointer = 0\nfor i in 0...n\n for j in 0...n-1\n if gear[i][j + 1] > gear[i][j]\n pointer = 1\n else\n pointer = 0\n break\n end\n end\n if pointer == 1\n break\n end\nend\nif pointer == 0\n puts \"NO\"\nelse\n puts \"YES\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nans = false\nv = a[0]\nn.times do |i|\n a[i] += i.odd? ? v : -v\n a = a.map{|x| x % n}\n ans = true if a == (0...n).to_a\nend\nputs ans ? 'Yes' : 'No'\n"}], "src_uid": "6c65ca365352380052b0c9d693e6d161"} {"source_code": "def debug(var)\n\tp \"debug #{var}\" if ARGV[0]==\"LOCAL_DEV\"\nend\n\nQ=STDIN.gets.to_i\nQ.times do\n\tn=STDIN.gets.to_i\n\tn.times do\n\t\tprint \"1 \"\n\tend\n\tprint \"\\n\"\nend\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\nn.times do\n arr = []\n count = 0\n t = gets.chomp.to_i\n 1.upto(t-1) do |i|\n arr << 1\n count += 1\n end\n arr << t - count\n puts arr.join(\" \")\nend"}], "negative_code": [{"source_code": "def debug(var)\n\tp \"debug #{var}\" if ARGV[0]==\"LOCAL_DEV\"\nend\n\nQ=STDIN.gets.to_i\nQ.times do\n\tn=STDIN.gets.to_i\n\tn.times do\n\t\tprint \"1 \"\n\tend\n\tprint '\\n'\nend\n"}], "src_uid": "da2ac80c2ad6abae676d60a506eb05fc"} {"source_code": "class Summand\n attr_accessor :coeff, :incr\nend\n\nclass Solution\n def initialize()\n @summands = []\n @a = 0\n end\n\n def parse_summand(s)\n match_data = /^(\\+|-)?([0-9]*)\\*?(a\\+\\+|\\+\\+a)/.match(s)\n sign = match_data[1].nil?? '+' : match_data[1]\n coeff = match_data[2].empty?? 1 : match_data[2].to_i\n coeff = -coeff if sign == '-'\n incr = match_data[3] == 'a++' ? 0 : 1 # 0 - post, 1 - pre\n\n summand = Summand.new\n summand.coeff = coeff\n summand.incr = incr\n @summands << summand\n\n s[match_data[0].size..-1]\n end\n\n def solve()\n @a = gets.to_i\n s = gets.chomp\n while not s.empty?\n s = parse_summand(s)\n end\n @summands.sort_by!{|s| s.coeff}\n\n result = 0\n a = @a\n @summands.each do |s|\n a += s.incr\n result += s.coeff * a\n a += (1 - s.incr)\n end\n puts result\n end\nend\n\nsolution = Solution.new\nsolution.solve()\n", "positive_code": [{"source_code": "a = gets.to_i\ngets.scan(/([+-])?(?:(\\d*)\\*)?(a\\+\\+|\\+\\+a)/){$* << [(($1 || '+') + ($2 || '1')).to_i, $3]}\ns = 0\n$*.sort.each do |c, d|\n\tif d == 'a++'\n\t\ts += c * a\n\telse\n\t\ts += c * (a + 1)\n\tend\n\ta += 1\nend\np s\n"}, {"source_code": "a = gets.to_i\ngets.scan(/([+-])?(?:(\\d*)\\*)?(a\\+\\+|\\+\\+a)/){$* << [(($1 || '+') + ($2 || '1')).to_i, $3]}\ns = 0\n$*.sort.each do |c, d|\n\tif d == 'a++'\n\t\ts += c * a\n\telse\n\t\ts += c * (a + 1)\n\tend\n\ta += 1\nend\np s\n\n"}, {"source_code": "a = gets.to_i\ngets.scan(/([+-])?(?:(\\d*)\\*)?(a\\+\\+|\\+\\+a)/){$* << [(($1 || '+') + ($2 || '1')).to_i, $3]}\ns = 0\n$*.sort.each do |c, d|\n\tif d == 'a++'\n\t\ts += c * a\n\telse\n\t\ts += c * (a + 1)\n\tend\n\ta += 1\nend\np s\n\n"}, {"source_code": "a = gets.to_i\ngets.scan(/([+-])?(?:(\\d*)\\*)?(a\\+\\+|\\+\\+a)/){$* << [(($1 || '+') + ($2 || '1')).to_i, $3]}\ns = 0\n$*.sort.each do |c, d|\n if d == 'a++'\n s += c * a\n else\n s += c * (a + 1)\n end\n a += 1\nend\np s"}, {"source_code": "a = gets.to_i\ngets.scan(/([+-])?(?:(\\d*)\\*)?(a\\+\\+|\\+\\+a)/){$* << [(($1 || '+') + ($2 || '1')).to_i, $3]}\ns = 0\n$*.sort.each do |c, d|\n\tif d == 'a++'\n\t\ts += c * a\n\telse\n\t\ts += c * (a + 1)\n\tend\n\ta += 1\nend\np s\n\n"}, {"source_code": "a = gets.to_i\ngets.scan(/([+-])?(?:(\\d*)\\*)?(a\\+\\+|\\+\\+a)/){$* << [(($1 || '+') + ($2 || '1')).to_i, $3]}\ns = 0\n$*.sort.each do |c, d|\n\tif d == 'a++'\n\t\ts += c * a\n\telse\n\t\ts += c * (a + 1)\n\tend\n\ta += 1\nend\np s\n\n"}, {"source_code": "a = gets.to_i\ngets.scan(/([+-])?(?:(\\d*)\\*)?(a\\+\\+|\\+\\+a)/){$* << [(($1 || '+') + ($2 || '1')).to_i, $3]}\ns = 0\n$*.sort.each do |c, d|\n\tif d == 'a++'\n\t\ts += c * a\n\telse\n\t\ts += c * (a + 1)\n\tend\n\ta += 1\nend\np s\n\n"}, {"source_code": "a = gets.to_i\ngets.scan(/([+-])?(?:(\\d*)\\*)?(a\\+\\+|\\+\\+a)/){$* << [(($1 || '+') + ($2 || '1')).to_i, $3]}\ns = 0\n$*.sort.each do |c, d|\n\tif d == 'a++'\n\t\ts += c * a\n\telse\n\t\ts += c * (a + 1)\n\tend\n\ta += 1\nend\np s\n\n"}, {"source_code": "a = gets.to_i\ngets.scan(/([+-])?(?:(\\d*)\\*)?(a\\+\\+|\\+\\+a)/){$* << [(($1 || '+') + ($2 || '1')).to_i, $3]}\ns = 0\n$*.sort.each do |c, d|\n\tif d == 'a++'\n\t\ts += c * a\n\telse\n\t\ts += c * (a + 1)\n\tend\n\ta += 1\nend\np s\n"}, {"source_code": "a = gets.to_i\ngets.scan(/([+-])?(?:(\\d*)\\*)?(a\\+\\+|\\+\\+a)/){$* << [(($1 || '+') + ($2 || '1')).to_i, $3]}\ns = 0\n$*.sort.each do |c, d|\n\tif d == 'a++'\n\t\ts += c * a\n\telse\n\t\ts += c * (a + 1)\n\tend\n\ta += 1\nend\np s\n\n"}, {"source_code": "a = gets.to_i\ngets.scan(/([+-])?(?:(\\d*)\\*)?(a\\+\\+|\\+\\+a)/){$* << [(($1 || '+') + ($2 || '1')).to_i, $3]}\ns = 0\n$*.sort.each do |c, d|\n\tif d == 'a++'\n\t\ts += c * a\n\telse\n\t\ts += c * (a + 1)\n\tend\n\ta += 1\nend\np s\n\n"}], "negative_code": [], "src_uid": "766196c156234cc169206dbb7a932fc7"} {"source_code": "n = gets.to_i\nary = gets.strip.split.map(&:to_i)\n\nif n==1\n puts 1\n exit\nend\n\nhsh = {}\n0.upto(n-1).each do |i|\n x = ary[i]\n if hsh[x].nil?\n hsh[x]=i\n else\n hsh[x]=-1\n end\nend\npossible = {}\nto_delete = 0\nmaxai = ((10**9) + 0)\n\n0.upto(n-1).each do |i|\n x = ary[i]\n if possible[x].nil?\n tp = 2\n while true do\n if x < tp\n rem = tp - x\n if rem > maxai\n possible[x] = false\n break\n end\n hsh_rem = hsh[rem]\n if hsh_rem!=nil && (hsh_rem==-1 || hsh_rem!=i)\n possible[x] = true\n break\n end\n end\n tp = (tp << 1)\n end\n end\n to_delete += 1 if possible[x] == false\nend\n\nputs to_delete", "positive_code": [{"source_code": "require 'set'\n\nn = gets.chomp.to_i\na = gets.chomp.split().map(&:to_i)\n\nx = 1\nz = []\nwhile (x<= 1e10)\n\tz << x\n\tx *= 2\nend\n\nmap_a = {}\na.each do |x|\n\tmap_a[x] ||= 0\n\tmap_a[x] += 1\nend\n\nac = 0\na.each do |i|\n\tflag = 1\n\tz.each do |j|\n\t\tif ((j-i == i) && map_a[i] && (map_a[i] >= 2)) || ((j-i != i) && map_a[j-i] && (map_a[j-i] >= 1))\n\t\t\tflag = 0\n\t\tend\n\tend\n\tac += flag\nend\n\nprint ac"}, {"source_code": "POWERS = (0..31).map { |i| 2**i }\n\ndef is_good(arr)\n elem_indices = Hash.new { |h, k| h[k] = [] }\n\n arr.each_with_index do |x, i|\n elem_indices[x] << i\n end\n\n count_to_remove = 0\n\n arr.each_with_index do |x, i|\n\n good = POWERS.any? { |pow|\n complement = pow - x\n complement > 0 && elem_indices[complement].any? { |j| j != i }\n }\n\n count_to_remove += 1 unless good\n\n end\n\n count_to_remove\n\nend\n\ngets\narr = gets.split.map(&:to_i)\n\nputs(is_good(arr))"}], "negative_code": [{"source_code": "require 'set'\n\nn = gets.chomp.to_i\na = gets.chomp.split().map(&:to_i)\n\nx = 1\nz = []\nwhile (x<= 1e9)\n\tz << x\n\tx *= 2\nend\n\nmap_a = {}\na.each do |x|\n\tmap_a[x] ||= 0\n\tmap_a[x] += 1\nend\n\nac = 0\na.each do |i|\n\tflag = 1\n\tz.each do |j|\n\t\tif ((j-i == i) && map_a[i] && (map_a[i] >= 2)) || ((j-i != i) && map_a[j-i] && (map_a[j-i] >= 1))\n\t\t\tflag = 0\n\t\tend\n\tend\n\tac += flag\nend\n\nprint ac"}], "src_uid": "ed308777f7122ca6279b522acd3e58f9"} {"source_code": "n, k = gets.split.map(&:to_i)\ndata = gets.split.map(&:to_i)\n\nmin = data.min\nif data.all? { |i| i % k == min % k }\n puts data.map { |i| (i - min) / k }.reduce(0, :+)\nelse\n puts -1\nend\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\nn,k,*a=$<.read.split.map(&:to_i)\nm=a.min\na=a.map{|e|e-m}\nif a.all?{|e|e%k==0}\n\tp a.reduce(0){|s,e|s+e/k}\nelse\n\tp -1\nend"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn, k = gets.strip.split.map &:to_i\na = gets.strip.split.map &:to_i\n\nminval = a.min\n\ncnt = 0\n\na.each do |e|\n d = e - minval\n if d % k != 0\n puts -1\n exit\n end\n cnt += d / k\nend\n\nputs cnt\n\n"}, {"source_code": "n, k, *aa = $<.read.split.map(&:to_i)\nb = aa.min\naa = aa.map {|a| a -= b}\np (aa.all? {|a| a % k == 0}) ? aa.inject(:+) / k : -1\n"}], "negative_code": [], "src_uid": "9e71b4117a24b906dbc16e6a6d110f50"} {"source_code": "ss = gets.chomp\nif ss.slice(ss.length-1) == \".\"\n puts \"NO\"\n exit\nend\ns = ss.split(\".\")\nret = []\npp = \"\"\nfor i in 0..s.length-1\n if s[i].length <= 0\n ret = nil\n break\n end\n if i == 0\n if s[i].length > 8\n ret = nil\n break\n end\n pp = s[i]\n elsif i == s.length-1\n if s[i].length > 3\n ret = nil\n break\n end\n ret << pp + \".\" + s[i]\n else\n if s[i].length > 11 || s[i].length <= 1\n ret = nil\n break\n end\n if s[i].length == 2\n ret << pp + \".\" + s[i].slice(0,1)\n pp = s[i].slice(1,1)\n elsif s[i].length == 3\n ret << pp + \".\" + s[i].slice(0,2)\n pp = s[i].slice(2,1)\n else\n ret << pp + \".\" + s[i].slice(0,3)\n pp = s[i].slice(3,s[i].length-3)\n end\n end\nend\n\nif ret == nil || ret.length == 0\n puts \"NO\"\nelse\n puts \"YES\"\n for i in 0..ret.length-1\n puts ret[i]\n end\nend\n\n\n", "positive_code": [{"source_code": "s = gets.chop\na = (s + '_' * 8).split('.')\nif s[-1] != '.' && a.size > 1 && (1..8).cover?(a[0].size) && a[1..-1].all?{|_| (2..11).cover?(_.size)}\n puts :YES\n (1...a.size).each do |i|\n n = [1, a[i].size - 8].max\n puts \"#{a[i - 1]}.#{a[i].slice!(0, n)}\"\n end\nelse\n puts :NO\nend\n"}], "negative_code": [{"source_code": "s = gets.chomp.split(\".\")\nret = []\npp = \"\"\nfor i in 0..s.length-1\n if s[i].length <= 0\n ret = nil\n break\n end\n if i == 0\n if s[i].length > 8\n ret = nil\n break\n end\n pp = s[i]\n elsif i == s.length-1\n if s[i].length > 3\n ret = nil\n break\n end\n ret << pp + \".\" + s[i]\n else\n if s[i].length > 11 || s[i].length <= 1\n ret = nil\n break\n end\n if s[i].length == 2\n ret << pp + \".\" + s[i].slice(0,1)\n pp = s[i].slice(1,1)\n elsif s[i].length == 3\n ret << pp + \".\" + s[i].slice(0,2)\n pp = s[i].slice(2,1)\n else\n ret << pp + \".\" + s[i].slice(0,3)\n pp = s[i].slice(3,s[i].length-3)\n end\n end\nend\n\nif ret == nil\n puts \"NO\"\nelse\n puts \"YES\"\n for i in 0..ret.length-1\n puts ret[i]\n end\nend\n\n\n"}, {"source_code": "ss = gets.chomp\nif ss.slice(ss.length-1) == \".\"\n puts \"NO\"\n exit\nend\ns = ss.split(\".\")\nret = []\npp = \"\"\nfor i in 0..s.length-1\n if s[i].length <= 0\n ret = nil\n break\n end\n if i == 0\n if s[i].length > 8\n ret = nil\n break\n end\n pp = s[i]\n elsif i == s.length-1\n if s[i].length > 3\n ret = nil\n break\n end\n ret << pp + \".\" + s[i]\n else\n if s[i].length > 11 || s[i].length <= 1\n ret = nil\n break\n end\n if s[i].length == 2\n ret << pp + \".\" + s[i].slice(0,1)\n pp = s[i].slice(1,1)\n elsif s[i].length == 3\n ret << pp + \".\" + s[i].slice(0,2)\n pp = s[i].slice(2,1)\n else\n ret << pp + \".\" + s[i].slice(0,3)\n pp = s[i].slice(3,s[i].length-3)\n end\n end\nend\n\nif ret == nil\n puts \"NO\"\nelse\n puts \"YES\"\n for i in 0..ret.length-1\n puts ret[i]\n end\nend\n\n\n"}, {"source_code": "s = gets.chop\na = (s + '_' * 8).split('.')\nif s[0] != '.' && s[-1] != '.' && a.size > 1 && a[1..-1].all?{|_| (2..11).cover?(_.size)}\n puts :YES\n (1...a.size).each do |i|\n n = [1, a[i].size - 8].max\n puts \"#{a[i - 1]}.#{a[i].slice!(0, n)}\"\n end\nelse\n puts :NO\nend\n"}], "src_uid": "9c30697e71102ae10c55c14d9c1db006"} {"source_code": "def doubler(a)\n k = 0\n while a % 2 == 0\n k += 1\n a /= 2\n end\n return k\nend\n\nn = gets.chomp.to_i\narr = gets.chomp.split(\" \")\n\n\narr.each_index do |i|\n arr[i] = arr[i].to_i\nend\n\n\nmaxD = 0\narr.each_index do |i|\n maxD = doubler(arr[i]) if i == 0\n maxD = doubler(arr[i]) if arr[i] % (2 ** maxD) == 0\n\nend\nk = 0\narr.each{ |iM|\n k += 1 if iM % (2 ** maxD) == 0\n}\n\nputs \"#{2 ** maxD} #{k}\"", "positive_code": [{"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\na = gets.split.map(&:to_i)\npow2 = [1]\ni = 0\nret = 1\nret2 = 0\nwhile pow2.max < a.max do\n pow2[i] = 2**(i+1)\n i += 1\nend\nfor i in 0..pow2.length-1\n for j in 0..n-1\n if a[j] % pow2[i] == 0 and pow2[i] > ret then ret = pow2[i] end\n end\nend\nfor i in 0..n-1\n if a[i] % ret == 0 then ret2 += 1 end\nend\nprintf \"%d %d\", ret, ret2\nputs\n"}], "negative_code": [], "src_uid": "c4fe684387076927e6d177b5178db746"} {"source_code": "n,x=gets.split.map(&:to_i); x-=1\na=gets.split.map(&:to_i)\n\nmin=a.min\na.map! {|i| i-min}\n\ncount=min*n\nwhile a[x]>0\n a[x]-=1\n x-=1\n count+=1\nend\n\na[x]=count\n\nputs a*' '\n\n", "positive_code": [{"source_code": "n,x=gets.split.map(&:to_i); x-=1\na=gets.split.map(&:to_i)\n\nmin=a.min\na.map! {|i| i-min}\n\ncount=min*n\nwhile a[x]>0\n a[x]-=1\n x-=1\n count+=1\nend\n\na[x]=count\n\nputs a*' '\n\n"}, {"source_code": "infile = STDIN\nn, end_index = infile.readline.split.map(&:to_i); end_index -= 1\na = infile.readline.split.map(&:to_i)\nt = a.min\na.map! { |i| i-t }\nc = 0\nwhile a[end_index] > 0 do\n a[end_index] -= 1\n end_index -= 1\n end_index = n-1 if end_index < 0\n c += 1\nend # c changes\na[end_index] = c + n*t\nputs a*' '"}, {"source_code": "infile = STDIN\nn, end_index = infile.readline.split.map(&:to_i); end_index -= 1\na = infile.readline.split.map(&:to_i)\nt = a.min\na.map! { |i| i-t }\nc = 0\nwhile a[end_index] > 0 do\n a[end_index] -= 1\n end_index -= 1\n end_index = n-1 if end_index < 0\n c += 1\nend\na[end_index] = c + n*t\nputs a*' '"}, {"source_code": "infile = STDIN\nn, end_index = infile.readline.split.map(&:to_i); end_index -= 1\na = infile.readline.split.map(&:to_i)\n\ntemp = end_index.downto(end_index-n+1).map { |i| a[i] }\nbegin_index = end_index - temp.index(temp.min)\nbegin_index = n + begin_index if begin_index < 0\nt = a[begin_index]\na.map! { |i| i-t } # n changes\nc = 0\nwhile end_index != begin_index do\n a[end_index] -= 1\n end_index -= 1\n end_index = n-1 if end_index < 0\n c += 1\nend # c changes\na[begin_index] = c + n*t\nputs a*' '"}, {"source_code": "n,x=gets.split.map(&:to_i); x-=1\na=gets.split.map(&:to_i)\n\nmin=a.min\na.map! {|i| i-min}\n\ncount=min*n\nwhile a[x]>0\n a[x]-=1\n x-=1\n count+=1\nend\n\na[x]=count\n\nputs a*' '\n\n"}, {"source_code": "n,x=gets.split.map(&:to_i); x-=1\na=gets.split.map(&:to_i)\n\nmin=a.min\na.map! {|i| i-min}\n\ncount=min*n\nwhile a[x]>0\n a[x]-=1\n x-=1\n count+=1\nend\n\na[x]=count\n\nputs a*' '\n\n"}, {"source_code": "n,x=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nm=2000000000\nk=-1\nx-=1\nfor i in 0..n-1 do\n t=(x-i+n)%n\n if m > a[t] then\n k=t\n m=a[t]\n end\nend\n\nfor i in 0..n-1 do\n a[i] = i==k ? m*n : a[i]-m\nend\nt=(n+x-k)%n\nfor i in 1..t do\n a[(k+i)%n]-=1\n a[k]+=1\nend\n\nputs a*' '\n"}, {"source_code": "n,x=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nm=2000000000\nk=-1\nx-=1\nfor i in 0..n-1 do\n t=(x-i+n)%n\n if m > a[t] then\n k=t\n m=a[t]\n end\nend\n\nfor i in 0..n-1 do\n a[i] = i==k ? m*n : a[i]-m\nend\nt=(n+x-k)%n\nfor i in 1..t do\n a[(k+i)%n]-=1\n a[k]+=1\nend\n\na.each do |v|\n print \"#{v} \"\nend\nputs\n"}, {"source_code": "n,x=gets.split.map(&:to_i); x-=1\na=gets.split.map(&:to_i)\n\nmin=a.min\na.map! {|i| i-min}\n\ncount=min*n\nwhile a[x]>0\n a[x]-=1\n x-=1\n count+=1\nend\n\na[x]=count\n\nputs a*' '\n\n"}, {"source_code": "n,x=gets.split.map(&:to_i); x-=1\na=gets.split.map(&:to_i)\n\nmin=a.min\na.map! {|i| i-min}\n\ncount=min*n\nwhile a[x]>0\n a[x]-=1\n x-=1\n count+=1\nend\n\na[x]=count\n\na.each {|v| print v,' '}\n"}, {"source_code": "n,x=gets.split.map(&:to_i); x-=1\na=gets.split.map(&:to_i)\n\nmin=a.min\na.map! {|i| i-min}\n\ncount=min*n\nwhile a[x]>0\n a[x]-=1\n x-=1\n count+=1\nend\n\na[x]=count\n\nputs a*' '\n"}, {"source_code": "n,x=gets.split.map(&:to_i)\nx-=1\n\na=gets.split.map(&:to_i)\n\nmin=a.min\na.length.times {|i| a[i]-=min}\n\ncount=min*n\nwhile a[x]>0\n a[x]-=1\n x-=1\n count+=1\nend\n\na[x]=count\n\na.each {|v| print \"#{v} \"}\n"}, {"source_code": "n,x=gets.split.map(&:to_i); x-=1\na=gets.split.map(&:to_i)\n\nmin=a.min\na.map! {|i| i-min}\n\ncount=min*n\nwhile a[x]>0\n a[x]-=1\n x-=1\n count+=1\nend\n\na[x]=count\n\nputs a*' '\n\n"}, {"source_code": "n,x=gets.split.map(&:to_i); x-=1\na=gets.split.map(&:to_i)\n\nmin=a.min\na.map! {|i| i-min}\n\ncount=min*n\nwhile a[x]>0\n a[x]-=1\n x-=1\n count+=1\nend\n\na[x]=count\n\nputs a*' '\n\n"}, {"source_code": "BEGIN{\ndef main()\n\tn, x = gets.split.map(&:to_i)\n\ta = gets.split.map(&:to_i)\n\tx -= 1\n\tm = a.min\n\ta.each_with_index do |v,i|\n\t\ta[i] -= m\n\tend\n\tsum = 0\n\trx = x\n\twhile a[x] != 0 do\n\t\ta[x] -= 1\n\t\tsum += 1\n\t\tx -= 1\n\tend\n\ta[x] = m * n + sum\n\ta.each do |p|\n\t\tprint p,' '\n\tend\n\tputs\nend\n1.times do\n\tmain()\nend\n}\n"}, {"source_code": "n,x=gets.split.map(&:to_i); x-=1\na=gets.split.map(&:to_i)\n\nmin=a.min\na.map! {|i| i-min}\n\ncount=min*n\nwhile a[x]>0\n a[x]-=1\n x-=1\n count+=1\nend\n\na[x]=count\n\nputs a*' '\n\n"}], "negative_code": [{"source_code": "n,x=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nm=a.min\nk=a.index{|v| v==m}\nk=x-1 if a[x-1]==a[k]\n\nif n==48 && x==34 then\n for i in 20..n-1 do\n print \"#{a[i]} \"\n end\nend\n\nfor i in 0..n-1 do\n a[i] = i==k ? m*n : a[i]-m\nend\nt=(n+x-1-k)%n;\na[k]+=t\nfor i in 1..t do\n a[(i+k)%n]-=1\nend\na.each do |v|\n print \"#{v} \"\nend\nputs\n"}, {"source_code": "n,x=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nm=a.min\nk=a.index{|v| v==m}\nif m > 0 then\n for i in 0..n-1 do\n if i==k then\n print \"#{m*n} \"\n else\n print \"#{a[i]-m} \"\n end\n end\nelse\n a[(k+1)%n]-=1\n a[k]=1;\n a.each do |v|\n print \"#{v} \"\n end\nend\nputs\n"}, {"source_code": "n,x=gets.split.map(&:to_i)\nx-=1\n\na=gets.split.map(&:to_i)\n\nmin=a.min\nstart=a.index(min)\n\nif a[start]==a[x]\n if startstart && (start+1..x)===i\n a[i]-=1\n end\n \n if xstart)\n a[i]-=1\n end\nend\n\na[start]=min*n\n\nif(x>start)\n a[start]+=x-start\nelsif(xstart && (start+1..x)===i\n a[i]-=1\n end\n \n if xstart)\n a[i]-=1\n end\nend\n\na[start]=min*n\n\nif(x>start)\n a[start]+=x-start\nelsif(xstart && (start+1..x)===i\n a[i]-=1\n end\n \n if xstart)\n a[i]-=1\n end\nend\n\na[start]=min*n\n\nif(x>start)\n a[start]+=x-start\nelsif(x 1\n\n\tfor i in 0..(indexes.count - 1)\n\n\t\tif indexes[(i+1)].to_i - indexes[i].to_i > 1\n\n\t\t\t#there is space for a new index\n\t\t\tresult = indexes[i].to_i + 1\n\t\t\tbreak;\n\n\t\tend\n\tend\n\nelse\n\n\tif indexes[0].to_i == 1\n\n\t\t#first index is not available, next availble will be first index + 1\n\t\tresult = indexes[(indexes.count - 1)].to_i + 1;\n\n\telse\n\n\t\t#first index is available\n\t\tresult = 1\n\tend\n\nend\n\nif result == -1\n\n\t#no available space was found, check for minimum value\n\n\tif indexes[0].to_i == 1\n\n\t\t#first index is one, if no space was found in the chain, then next available is max value + 1\n\t\tresult = indexes[(indexes.count - 1)].to_i + 1;\n\n\telse\n\n\t\t#first index is not equal to 1 so 1 is available\n\t\tresult = 1\n\tend\n\nend\n\n\n\nputs result\n\n"}, {"source_code": "n = -1\nindexes = []\nchars = []\n\nARGF.each_with_index do |line, i|\n\n\t#read number of indexes provided\n\tn = line if i == 0\n\n\t#read indexes\n\tchars = line.split(' ') if i == 1\n\n\nend\n\n#transfer characters to array of integers\n\nchars.each do |c|\n\tindexes.push(c.to_i)\nend\n\n#sort indexes\n\nindexes = indexes.sort\n\nresult = -1\n\nif indexes.count > 1\n\n\tfor i in 0..(indexes.count - 1)\n\n\t\tif indexes[( i+ 1)].to_i - indexes[i].to_i > 1\n\n\t\t\t#there is space for a new index\n\t\t\tresult = indexes[i].to_i + 1\n\t\t\tbreak;\n\n\t\tend\n\tend\n\nelse\n\n\tif indexes[0].to_i == 1\n\n\t\t#first index is not available, next availble will be first index + 1\n\t\tresult = indexes[(indexes.count - 1)].to_i + 1;\n\n\telse\n\n\t\t#first index is available\n\t\tresult = 1\n\tend\n\nend\n\nif result == -1\n\n\t#no available space was found, check for minimum value\n\n\tif indexes[0].to_i == 1\n\n\t\t#first index is one, if no space was found in the chain, then next available is max value + 1\n\t\tresult = indexes[(indexes.count - 1)].to_i + 1;\n\n\telse\n\n\t\t#first index is not equal to 1 so 1 is available\n\t\tresult = 1\n\tend\n\nend\n\n\n\nputs result\n\n"}, {"source_code": "n = gets.to_i\n\nnums = gets.split.map{|i| i.to_i}\n\nt = true\ni = 1\nwhile t && i <= n do\n if !nums.delete(i) then\n result = i\n t = false\n end\n i += 1\nend\n\nif t then\n result = n + 1\nend\n\nputs result"}, {"source_code": "#!/usr/bin/ruby\ngets;p ([*1..3001]-gets.split.map(&:to_i))[0]"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]\n"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]\n"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]"}, {"source_code": "n=gets.to_i\na=Array.new(n+1,0)\ngets.chomp.split.map(&:to_i).each {|x| a[x]=1}\nfor i in 1..n\n\tif a[i]==0\n\t\tputs i\n\t\texit\n\tend\nend\nputs n+1\n\n"}, {"source_code": "s = (1..3001).to_a\nn = gets.to_i\na = gets.split.map{|r| r.to_i}\ns = s - a\nputs s[0]\n"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]\n"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]\n"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]"}, {"source_code": "gets\np ((1..1e5).to_a-gets.split.map(&:to_i)).min\n"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tstin=gets.chomp.split(\" \",n)\n\tstin=stin.map{|i| i.to_i}\n\tstin=stin.sort()\n\tj=1;f=0;\n\tfor i in 0...(stin.length)\n\t\tif stin[i]==j\t\n\t\t\tj+=1;\n\t\telse\n\t\t\tf=1;\n\t\t\tputs j\n\t\t\tbreak;\n\t\tend\n\tend\n\tif f==0\n\t\tputs j\n\tend\nend\nmain\n"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]\n"}, {"source_code": "n = gets.to_i\na = gets.split(\" \").map(&:to_i)\na.sort!\nans = nil\n\na.each_with_index do |x,i|\n\tif x != i + 1\n\t\tans = i + 1\n\t\tbreak\n\tend\nend\n\nans = a[-1] + 1 unless ans\nputs ans\n"}, {"source_code": "gets\nputs ((1..3001).to_a - gets.chomp.split.map(&:to_i))[0]"}, {"source_code": "gets\np ((1..3001).to_a - gets.split.map(&:to_i)).min"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]\n"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]\n"}, {"source_code": "gets;p ((1..3002).to_a-gets.split.map(&:to_i))[0]\n"}], "negative_code": [{"source_code": "n = -1\nindexes = []\n\nARGF.each_with_index do |line, i|\n\n\t#read number of indexes provided\n\tn = line if i == 0\n\n\t#read indexes\n\tindexes = line.split(' ') if i == 1\n\n\nend\n\n#sort indexes\nindexes = indexes.sort\n\nresult = -1\n\nif indexes.count > 1\n\n\t0.upto(indexes.count-1) do |i|\n\n\t\tif indexes[i+1].to_i - indexes[i].to_i > 1\n\n\t\t\t#there is space for a new index\n\t\t\tresult = indexes[i].to_i + 1\n\t\t\tbreak;\n\n\t\tend\n\tend\n\nelse\n\n\tif indexes[0].to_i > 1\n\n\t\t#first index is available\n\t\tresult = 1\n\n\telse\n\n\t\t#first element is equal to 1, assign next to 2\n\t\tresult = 2\n\tend\n\nend\n\nif result == -1\n\n\t#no available space was found, check for minimum value\n\n\tif indexes[0].to_i == 1\n\n\t\t#first index is one, if no space was found in the chain, then next available is max value + 1\n\t\tresult = indexes[indexes.count -1].to_i + 1;\n\n\telse\n\n\t\t#first index is not equal to 1 so 1 is available\n\t\tresult = 1\n\tend\n\nend\n\n\nputs result\n\n"}, {"source_code": "n = -1\nindexes = []\n\nARGF.each_with_index do |line, i|\n\n\t#read number of indexes provided\n\tn = line if i == 0\n\n\t#read indexes\n\tindexes = line.split(' ') if i == 1\n\n\nend\n\n#sort indexes\nindexes = indexes.sort\n\nresult = -1\n\nif indexes.count > 1\n\n\t0.upto(indexes.count-1) do |i|\n\n\t\tif indexes[i+1].to_i - indexes[i].to_i > 1\n\n\t\t\t#there is space for a new index\n\t\t\tresult = indexes[i].to_i + 1\n\t\t\tbreak;\n\n\t\tend\n\tend\n\nelse\n\n\tif indexes[0].to_i == 1\n\n\t\t#first index is not available, next availble will be first index + 1\n\t\tresult = indexes[indexes.count -1].to_i + 1;\n\n\telse\n\n\t\t#first index is available\n\t\tresult = 1\n\tend\n\nend\n\nif result == -1\n\n\t#no available space was found, check for minimum value\n\n\tif indexes[0].to_i == 1\n\n\t\t#first index is one, if no space was found in the chain, then next available is max value + 1\n\t\tresult = indexes[indexes.count -1].to_i + 1;\n\n\telse\n\n\t\t#first index is not equal to 1 so 1 is available\n\t\tresult = 1\n\tend\n\nend\n\n\nputs result\n\n"}, {"source_code": "n = -1\nindexes = []\n\nARGF.each_with_index do |line, i|\n\n\t#read number of indexes provided\n\tn = line if i == 0\n\n\t#read indexes\n\tindexes = line.split(' ') if i == 1\n\n\nend\n\n#sort indexes\nindexes = indexes.sort\n\nresult = -1\n\nif indexes.count > 1\n\n\t0.upto(indexes.count) do |i|\n\n\t\tif indexes[i+1].to_i - indexes[i].to_i > 1\n\n\t\t\t#there is space for a new index\n\t\t\tresult = indexes[i].to_i + 1\n\t\t\tbreak;\n\n\t\tend\n\tend\n\nelse\n\n\tif indexes[0].to_i == 1\n\n\t\t#first index is not available, next availble will be first index + 1\n\t\tresult = indexes[indexes.count -1].to_i + 1;\n\n\telse\n\n\t\t#first index is available\n\t\tresult = 1\n\tend\n\nend\n\nif result == -1\n\n\t#no available space was found, check for minimum value\n\n\tif indexes[0].to_i == 1\n\n\t\t#first index is one, if no space was found in the chain, then next available is max value + 1\n\t\tresult = indexes[indexes.count -1].to_i + 1;\n\n\telse\n\n\t\t#first index is not equal to 1 so 1 is available\n\t\tresult = 1\n\tend\n\nend\n\n\nputs result\n\n"}, {"source_code": "n = -1\nindexes = []\n\nARGF.each_with_index do |line, i|\n\n\t#read number of indexes provided\n\tn = line if i == 0\n\n\t#read indexes\n\tindexes = line.split(' ') if i == 1\n\n\nend\n\n#sort indexes\nindexes = indexes.sort\n\nresult = -1\n\nif indexes.count > 1\n\n\t0.upto((indexes.count-1)) do |i|\n\n\t\tif indexes[(i+1)].to_i - indexes[i].to_i > 1\n\n\t\t\t#there is space for a new index\n\t\t\tresult = indexes[i].to_i + 1\n\t\t\tbreak;\n\n\t\tend\n\tend\n\nelse\n\n\tif indexes[0].to_i == 1\n\n\t\t#first index is not available, next availble will be first index + 1\n\t\tresult = indexes[(indexes.count - 1)].to_i + 1;\n\n\telse\n\n\t\t#first index is available\n\t\tresult = 1\n\tend\n\nend\n\nif result == -1\n\n\t#no available space was found, check for minimum value\n\n\tif indexes[0].to_i == 1\n\n\t\t#first index is one, if no space was found in the chain, then next available is max value + 1\n\t\tresult = indexes[(indexes.count - 1)].to_i + 1;\n\n\telse\n\n\t\t#first index is not equal to 1 so 1 is available\n\t\tresult = 1\n\tend\n\nend\n\n\n\nputs result\n\n"}, {"source_code": "gets;p ((1..3000).to_a-gets.split.map(&:to_i))[0]"}, {"source_code": "n=gets.to_i\na=Array.new(n+1,0)\ngets.chomp.split.map(&:to_i).each {|x| a[x]=1}\nprint a\nputs\nfor i in 1..n\n\tif a[i]==0\n\t\tputs i\n\t\texit\n\tend\nend\nputs n+1\n\n"}, {"source_code": "n=gets.to_i\nb=Array.new(n,1)\nn.times { |i| b[i]=i+1}\na=gets.chomp.split.map(&:to_i).sort\nn.times do |i|\n\tif a[i]!=b[i]\n\t\tputs b[i]\n\t\tbreak\n\tend\nend\n\n"}, {"source_code": "s = (1..3000).to_a\nn = gets.to_i\na = gets.split.map{|r| r.to_i}\ns = s - a\nputs s[0]\n"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tstin=gets.chomp.split(\" \",n)\n\tstin=stin.map{|i| i.to_i}\n\tstin=stin.sort()\n\tj=1;\n\tfor i in 0...(stin.length)\n\t\tif stin[i]==j\t\n\t\t\tj+=1;\n\t\telse\n\t\t\tputs j\n\t\t\tbreak;\n\t\tend\n\tend\nend\nmain\n"}, {"source_code": "gets\nnums = gets.chomp.split.map(&:to_i)\n\nputs ((1..3000).to_a - nums)[0]"}, {"source_code": "gets\nnums = gets.chomp.split.map(&:to_i)[0..2999]\n\nputs ((1..3000).to_a - nums)[0]"}], "src_uid": "5e449867d9fcecc84333b81eac9b5d92"} {"source_code": "def solve(n, k1, k2, w, b)\r\n w_o = (k1 + 1) / 2 + k2 / 2\r\n w_e = k1 / 2 + (k2 + 1) / 2\r\n\r\n k3, k4 = n - k1, n - k2\r\n b_o = (k3 + 1) / 2 + k4 / 2\r\n b_e = k3 / 2 + (k4 + 1) / 2\r\n\r\n w <= min(w_o, w_e) && b <= min(b_o, b_e)\r\n #(w_o == w_e and b_o == b_e and w <= w_o and b <= b_o)\r\nend\r\n\r\ndef main\r\n t = int\r\n t.times do\r\n n, k1, k2 = ints\r\n w, b = ints\r\n yesno solve(n, k1, k2, w, b)\r\n end\r\nend\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\nYESNO = %w(NO YES)\r\nINF = 10**9\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts YESNO[1] end\r\ndef no; puts YESNO[0] end\r\ndef yesno t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, k1, k2 = gets.split(' ').map(&:to_i)\r\n w, b = gets.split(' ').map(&:to_i)\r\n \r\n white_count = [k1, k2].min + ((k1-k2).abs / 2)\r\n left_w_c = (k1-k2).abs % 2 # this may be 1 or 0\r\n \r\n black_count = [n-k1, n-k2].min + (((n-k1) - (n-k2)).abs / 2)\r\n left_b_c = ((n-k1) - (n-k2)).abs % 2 # this may be 1 or 0\r\n \r\n puts white_count >= w && black_count >= b ? 'YES' : 'NO'\r\nend"}], "negative_code": [], "src_uid": "26354d2628f26eb2eff9432bd46400d5"} {"source_code": "t = gets.to_i\nt.times do\n played = 0\n cleared = 0\n ok = true\n n = gets.to_i\n n.times do\n p, c = gets.split.map(&:to_i)\n ok = false if p < c\n ok = false if p < played\n ok = false if c < cleared\n ok = false if (p - played) < (c - cleared)\n played = p\n cleared = c\n end\n puts ok ? \"YES\" : \"NO\"\nend\n", "positive_code": [{"source_code": "def run\n n = gets.chomp.to_i\n pp, pc = *[0, 0]\n\n a = []\n\n n.times do\n v = gets.chomp.split(\" \").map(&:to_i)\n a.push(v)\n end\n\n a.each do |p, c|\n if p >= pp && c >= pc && (p - pp) >= (c - pc)\n pp = p\n pc = c\n else\n puts 'no'\n return\n end\n end\n\n puts 'yes'\nend\n\n\ndef main\n t = gets.chomp.to_i\n\n t.times do\n run\n end\nend\n\nmain\n"}, {"source_code": "n = STDIN.gets.to_i\nn.times do |i|\n j = STDIN.gets.to_i\n sets = []\n j.times do\n match = STDIN.gets.strip.match(/(\\d+) (\\d+)/)\n sets << [match[1].to_i, match[2].to_i]\n end\n r = 0\n c = 0\n skip = false\n for a, b in sets do\n if (a < r) or (b < c) or (b > a) or ((a == r) and (b > c)) or ((a - r) < (b - c))\n puts 'NO'\n skip = true\n break\n else\n r = a\n c = b\n end\n end\n puts 'YES' unless skip\nend"}, {"source_code": "gets.to_i.times do\n prev = [0, 0]\n ok = true\n\n gets.to_i.times do\n a = gets.split(' ').map(&:to_i)\n\n ok &&= (a.last - prev.last) >= 0\n ok &&= (a.first - prev.first) >= (a.last - prev.last)\n\n prev = a\n end\n\n puts ok ? 'YES' : 'NO'\nend\n"}, {"source_code": "t = gets.chomp.to_i\nwhile t>0 do\n n = gets.chomp.to_i\n las_a = 0\n las_b = 0\n ok = true\n for i in 1..n do\n tmp = gets.chomp.split(\" \")\n a = tmp[0].to_i\n b = tmp[1].to_i\n if b-las_b>a-las_a or b a)\n puts 'NO'\n skip = true\n break\n else\n p = a\n c = b\n end\n end\n puts 'YES' unless skip\nend"}, {"source_code": "t = gets.to_i\nt.times do\n played = 0\n cleared = 0\n ok = true\n n = gets.to_i\n n.times do\n p, c = gets.split.map(&:to_i)\n ok = false if p < c\n ok = false if p < played\n ok = false if c < cleared\n played = p\n cleared = c\n end\n puts ok ? \"YES\" : \"NO\"\nend\n"}], "src_uid": "714834defd0390659f6ed5bc3024f613"} {"source_code": "1.upto(gets.chomp.to_i) do\n x,y = gets.chomp.split.map(&:to_i)\n a,b = gets.chomp.split.map(&:to_i)\n\n x,y = y,x if x > y\n puts [a*x + a*y, b*x + a*(y-x)].min\nend\n", "positive_code": [{"source_code": "gets.to_i.times {\n x, y=gets.split.map &:to_i\n a, b=gets.split.map &:to_i\n \n s=x.abs\n t=y.abs\n puts [s*a+t*a, s*b+(y-x).abs*a, t*b+(x-y).abs*a].min\n}\n"}, {"source_code": "g = gets.chomp.to_i\ng.times{|w|\nx,y = gets.split(\" \").map{|x|x.to_i}\na,b = gets.split(\" \").map{|x|x.to_i}\nall = []\n\nx1=0\ny1=0\n\nx1+=x\ny1+=y\n\nz=0\n#method 1\nloop do\nif (x==0 && y==0)\nbreak \nelse\n\nif (x > 0 && y > 0)\nhh=[]\nhh.push(x)\nhh.push(y)\nz+=(hh.min*b)\nx-=hh.min\ny-=hh.min\n\nif (x!=0)\nz+=x*a\nx-=x\nend\nif (y!=0)\nz+=y*a\ny-=y\nend\nend\n\n\nif (x < 0 && y < 0)\nhh=[]\nhh.push(x)\nhh.push(y)\nz+=(hh.max.abs*b)\nx+=hh.max.abs\ny+=hh.max.abs\n\nif (x!=0)\nz+=x.abs*a\nx+=x.abs\nend\nif (y!=0)\nz+=y.abs*a\ny+=y.abs\nend\nend\n\nif (x<0)\nz+=x.abs*a\nx+=x.abs\nend\nif (x>0)\nz+=x*a\nx-=x\nend\nif (y<0)\nz+=y.abs*a\ny+=y.abs\nend\nif (y>0)\nz+=y*a\ny-=y\nend\n\nend\nend\nall.push(z)\n\nz=0\nx=x1\ny=y1\nloop do\nif (x==0 && y==0)\nbreak \nelse\n\nif (x<0)\nz+=x.abs*a\nx+=x.abs\nend\nif (x>0)\nz+=x*a\nx-=x\nend\nif (y<0)\nz+=y.abs*a\ny+=y.abs\nend\nif (y>0)\nz+=y*a\ny-=y\nend\n\nend\nend\nall.push(z)\n\n\nputs all.min\n}\n\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n\tx,y = gets.chomp.split(\" \").map(&:to_i)\n\ta, b = gets.chomp.split(\" \").map(&:to_i)\n\tif 2 * a < b then\n\t\tputs a * (x + y)\n\telse\n\t\tdiff = (x - y).abs\n\t\tputs ([x,y].max - diff) * b + a * diff\n\tend\nend\n\n"}, {"source_code": "1.upto(gets.to_i) do\n x, y = gets.split(' ').map(&:to_i)\n a, b = gets.split(' ').map(&:to_i)\n\n puts [\n [x, y].min * b + (x - y).abs * a,\n x * a + y * a\n ].min\nend\n"}, {"source_code": "def solution\n x, y = gets.split.map(&:to_i)\n a, b = gets.split.map(&:to_i)\n\n return 0 if x == 0 && y == 0\n\n if b > 2 * a\n return (x + y) * a\n end\n\n min = [x, y].min\n max = [x, y].max\n min * b + (max - min) * a\nend\n\nt = gets.to_i\nt.times do\n p solution\nend\n"}, {"source_code": "file = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nt = file.gets.chomp.to_i\nt.times do\n x, y = file.gets.chomp.split.map(&:to_i)\n a, b = file.gets.chomp.split.map(&:to_i)\n\n if a == 0 || b == 0\n puts 0\n next\n end\n\n if x==y\n puts [x*b, a*2*x].min\n elsif x > y\n c=a*(x-y)+b*y\n d=a*(x-y)+2*a*y\n puts [c,d].min\n else\n c=a*(y-x)+b*x;\n d=a*(y-x)+2*a*x;\n puts [c,d].min\n end\nend"}, {"source_code": "def run\n x, y = gets.chomp.split(\" \").map(&:to_i)\n a, b = gets.chomp.split(\" \").map(&:to_i)\n\n r = if a * 2 < b || x == 0 || y == 0\n (x + y) * a\n else\n (x - y).abs * a + [x, y].min * b\n end\n puts r\nend\n\n\ndef main\n t = gets.chomp.to_i\n\n t.times do\n run\n end\nend\n\nmain\n"}], "negative_code": [{"source_code": "file = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nt = file.gets.chomp.to_i\nt.times do\n x, y = file.gets.chomp.split.map(&:to_i)\n a, b = file.gets.chomp.split.map(&:to_i)\n res = 0\n\n if x==y\n res+= [x*b, a*2*x].min\n else\n d = (x-y).abs\n res += d * a\n res += ([x,y].max-d)*b\n end\n puts res\nend"}, {"source_code": "file = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nt = file.gets.chomp.to_i\nt.times do\n x, y = file.gets.chomp.split.map(&:to_i)\n a, b = file.gets.chomp.split.map(&:to_i)\n\n\n if x==y\n puts [x*b, a*2*x].min\n else\n res = 0\n d = (x-y).abs\n res += d * a\n res += ([x,y].max-d)*b\n res2 = (d*a) +(b*[x,y].max)\n puts [res, res2].min\n end\nend"}, {"source_code": "file = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nt = file.gets.chomp.to_i\nt.times do\n x, y = file.gets.chomp.split.map(&:to_i)\n a, b = file.gets.chomp.split.map(&:to_i)\n\n if a == 0 || b == 0\n puts 0\n next\n end\n\n if x==y\n puts [x*b, a*2*x].min\n else\n res = 0\n d = (x-y).abs\n res += d * a\n res += ([x,y].max-d)*b\n res2 = (d*a) +(b*[x,y].max)\n # puts \"#{[res, res2]}\"\n puts [res, res2].min\n end\nend"}, {"source_code": "file = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nt = file.gets.chomp.to_i\nt.times do\n x, y = file.gets.chomp.split.map(&:to_i)\n a, b = file.gets.chomp.split.map(&:to_i)\n\n if a == 0 || b == 0\n puts 0\n next\n end\n\n if x==y\n puts [x*b, a*2*x].min\n else\n d = (x-y).abs\n\n res = (d*a) + ([x,y].max-d)*b\n\n # res2 = (d*a) +(b*[x,y].max)\n # puts \"#{[res, res2]}\"\n # puts [res, res2].min\n puts res\n end\nend"}, {"source_code": "g = gets.chomp.to_i\ng.times{|w|\nx,y = gets.split(\" \").map{|x|x.to_i}\na,b = gets.split(\" \").map{|x|x.to_i}\nall = []\n\nz=0\n#method 1\nloop do\nif (x==0 && y==0)\nbreak \nelse\n\nif (x > 0 && y > 0)\nhh=[]\nhh.push(x)\nhh.push(y)\nz+=(hh.min*b)\nx-=hh.min\ny-=hh.min\n\nif (x!=0)\nz+=x*a\nx-=x\nend\nif (y!=0)\nz+=y*a\ny-=y\nend\nend\n\n\nif (x < 0 && y < 0)\nhh=[]\nhh.push(x)\nhh.push(y)\nz+=(hh.max*b)\nx+=hh.max.abs\ny+=hh.max.abs\n\nif (x!=0)\nz+=x.abs*a\nx+=x.abs\nend\nif (y!=0)\nz+=y.abs*a\ny+=y.abs\nend\nend\n\nif (x<0)\nz+=x.abs*a\nx+=x.abs\nend\nif (x>0)\nz+=x*a\nx-=x\nend\nif (y<0)\nz+=y.abs*a\ny+=y.abs\nend\nif (y>0)\nz+=y*a\ny-=y\nend\n\nend\nend\n\n\n\nputs z\n}\n\n"}, {"source_code": "g = gets.chomp.to_i\ng.times{|w|\nx,y = gets.split(\" \").map{|x|x.to_i}\na,b = gets.split(\" \").map{|x|x.to_i}\nall = []\n\nz=0\n#method 1\nloop do\nif (x==0 && y==0)\nbreak \nelse\n\nif (x > 0 && y > 0)\nhh=[]\nhh.push(x)\nhh.push(y)\nz+=(hh.min*b)\nx-=hh.min\ny-=hh.min\n\nif (x!=0)\nz+=x*a\nx-=x\nend\nif (y!=0)\nz+=y*a\ny-=y\nend\nend\n\n\nif (x < 0 && y < 0)\nhh=[]\nhh.push(x)\nhh.push(y)\nz+=(hh.max.abs*b)\nx+=hh.max.abs\ny+=hh.max.abs\n\nif (x!=0)\nz+=x.abs*a\nx+=x.abs\nend\nif (y!=0)\nz+=y.abs*a\ny+=y.abs\nend\nend\n\nif (x<0)\nz+=x.abs*a\nx+=x.abs\nend\nif (x>0)\nz+=x*a\nx-=x\nend\nif (y<0)\nz+=y.abs*a\ny+=y.abs\nend\nif (y>0)\nz+=y*a\ny-=y\nend\n\nend\nend\n\n\n\nputs z\n}\n\n"}, {"source_code": "g = gets.chomp.to_i\ng.times{|w|\nx,y = gets.split(\" \").map{|x|x.to_i}\na,b = gets.split(\" \").map{|x|x.to_i}\nall = []\n\nz=0\n#method 1\nif (x==0 && y==0)\n \nelse\n\nif (x > 0 && y > 0)\nhh=[]\nhh.push(x)\nhh.push(y)\nz+=(hh.min*b)\nx-=hh.min\ny-=hh.min\n\nif (x!=0)\nz+=x*a\nx-=x\nend\nif (y!=0)\nz+=y*a\ny-=y\nend\nend\n\n\nif (x < 0 && y < 0)\nhh=[]\nhh.push(x)\nhh.push(y)\nz+=(hh.max*b)\nx+=hh.max\ny+=hh.max\n\nif (x!=0)\nz+=x.abs*a\nx+=x\nend\nif (y!=0)\nz+=y.abs*a\ny+=y\nend\nend\n\n\nend\nputs z\n}\n\n"}, {"source_code": "g = gets.chomp.to_i\ng.times{|w|\nx,y = gets.split(\" \").map{|x|x.to_i}\na,b = gets.split(\" \").map{|x|x.to_i}\nall = []\n\nz=0\n#method 1\nloop do\nif (x==0 && y==0)\nbreak \nelse\n\nif (x > 0 && y > 0)\nhh=[]\nhh.push(x)\nhh.push(y)\nz+=(hh.min*b)\nx-=hh.min\ny-=hh.min\n\nif (x!=0)\nz+=x*a\nx-=x\nend\nif (y!=0)\nz+=y*a\ny-=y\nend\nend\n\n\nif (x < 0 && y < 0)\nhh=[]\nhh.push(x)\nhh.push(y)\nz+=(hh.max*b)\nx+=hh.max\ny+=hh.max\n\nif (x!=0)\nz+=x.abs*a\nx+=x\nend\nif (y!=0)\nz+=y.abs*a\ny+=y\nend\nend\n\nif (x<0)\nz+=x.abs*a\nx+=x.abs\nend\nif (x>0)\nz+=x*a\nx-=x\nend\nif (y<0)\nz+=y.abs*a\ny+=y.abs\nend\nif (y>0)\nz+=y*a\ny-=y\nend\n\nend\nend\n\n\n\nputs z\n}\n\n"}], "src_uid": "edf394051c6b35f593abd4c34b091eae"} {"source_code": "def sum(arr)\n ret = 0\n arr.each do |i|\n ret += i\n end\n return ret\nend\n\nn = gets.to_i\na = gets.split.map {|i| i.to_i}\nb = gets.split.map {|i| i.to_i}.sort\nif sum(a) <= sum(b.last(2)) then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend", "positive_code": [{"source_code": "gets\na=gets.split.map{|e| e.to_i}\nb=gets.split.map{|e| e.to_i}.sort.reverse\nif b[0]+b[1]-a.inject(0){|sum,e| sum+e}<0 then\nputs \"NO\"\nelse\nputs \"YES\"\nend"}, {"source_code": "n = Integer(gets.chomp)\n\nvolume_line = gets.chomp.split(\" \").to_a.map{ |i| Integer(i) }\nvalue = volume_line.inject(0){ |v, i| v + i }\n\ncups_line = gets.chomp.split(\" \").to_a.map{ |i| Integer(i) }.sort.reverse\n\nprint (value <= cups_line[0] + cups_line[1]) ? \"YES\" : \"NO\""}, {"source_code": "n = gets\nn = n.to_i\n\narr = Array.new(n){Array.new(2){0}}\n\ns = gets\ns.split(\" \").map(&:to_i).each.with_index do |v, index|\n arr[index][0] = v\nend\n\ns = gets\ns.split(\" \").map(&:to_i).each.with_index do |v, index|\n arr[index][1] = v\nend\n\n\nfirst_max = -Float::INFINITY\nsecond_max = -Float::INFINITY\n\nsum_volumes = 0\n\n\narr.each do |v,c|\n sum_volumes += v\n if c >= first_max\n second_max = first_max\n first_max = c\n elsif c > second_max\n second_max = c\n end\nend\n\n\nif sum_volumes <= (first_max + second_max )\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).inject(:+)\nb = gets.split.map(&:to_i).sort\nputs a <= b[-1] + b[-2] ? \"YES\" : \"NO\""}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nb = gets.split.map &:to_i\nputs a.inject(0){|s, x| s + x} <= b.sort[-2] + b.sort[-1] ? 'YES' : 'NO'"}, {"source_code": "n= gets.to_i\n\nremaining = gets.split(\" \").map(&:to_i).inject(0, :+)\ncapacities = gets.split(\" \").map(&:to_i)\nmax1 = capacities.max\ncapacities.delete_at capacities.index(max1)\nmax2 = capacities.max\n\nif max1+max2 >= remaining\n\tprint('YES')\nelse\n\tprint('NO')\nend\n"}, {"source_code": "n= gets.to_i\n\nremaining = gets.split(\" \").map(&:to_i).inject(0, :+)\ncapacities = gets.split(\" \").map(&:to_i)\nmax1 = capacities.max\ncapacities.delete_at capacities.index(max1)\nmax2 = capacities.max\n\nif max1+max2 >= remaining\n\tprint('YES')\nelse\n\tprint('NO')\nend\n"}, {"source_code": "gets\na=gets.split.map(&:to_i).reduce :+\nb=gets.split.map(&:to_i).sort[-2..-1].reduce :+\nputs a<=b ? :YES : :NO"}, {"source_code": "def solve(n, cans, sizes)\n total = cans.inject(:+)\n free = sizes.sort.reverse.first(2).inject(:+)\n free >= total ? \"YES\" : \"NO\"\nend\n\nputs solve(gets.strip.to_i, gets.strip.split.map(&:to_i), gets.strip.split.map(&:to_i))"}, {"source_code": "n = gets.chomp.to_i\n$a = gets.chomp.split.map(&:to_i)\n$b = gets.chomp.split.map(&:to_i)\n\ndef solve\n $b.sort_by! { |x| x }\n if ($a.inject(0, :+) <= $b[-2..-1].inject(0, :+))\n return \"YES\"\n end\n return \"NO\"\nend\n\nprint solve"}], "negative_code": [], "src_uid": "88390110e4955c521867864a6f3042a0"} {"source_code": "# coding: utf-8\n\n# bogosort \uc815\ub82c\uc774 \uc544\ub2c8\ub780 \uac70\uc8e0.\n# i < j \uc778 \uc778\ub371\uc2a4 \ud398\uc5b4\uc5d0 \ub300\ud558\uc5ec i - ai != j - aj\n# \uc608\ub97c \ub4e4\uc5b4 a = [1, 1, 3, 5] \uc5d0 \ub300\ud574\uc11c\n# (1, 2) \ub294 1 - 1 != 2 - 1 \ub85c \ub9cc\uc871\uc774\uc9c0\ub9cc (1, 3)\uc740 1 - 1 == 3 - 3\uc774\ubbc0\ub85c\n# \uc131\ub9bd\ud558\uc9c0 \uc54a\uc74c.\n# \ubc30\uc5f4\uc758 \ucd5c\uc18c \ud06c\uae30\ub294 1\n\ndef bogosort(a)\n ar = a.sort.reverse\n return ar\nend\n\nt = gets.to_i\nt.times {\n n = gets.to_i\n a = gets.split.map(&:to_i)\n puts bogosort(a).join(' ')\n}", "positive_code": [{"source_code": " gets.to_i.times do\n gets\n puts gets.split.map(&:to_i).sort.reverse.join(' ')\n end\n"}, {"source_code": "t = gets.chomp.to_i\n(0...t).each do |_|\n n = gets.chomp.to_i\n l = gets.chomp.split.map(&:to_i)\n #r = []\n r = l.sort.reverse\n print r.join(' ')\n puts\nend\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n puts a.sort.reverse.join(' ')\nend\n"}, {"source_code": "t = gets.chomp.to_i\n(0...t).each do |_|\n n = gets.chomp.to_i\n print gets.chomp.split.map(&:to_i).sort.reverse.join(' ')\n puts\nend"}], "negative_code": [{"source_code": " gets.to_i.times do\n gets\n puts gets.split.sort.reverse.join(' ')\n end\n"}, {"source_code": "def check(a)\n (0...a.size).each do |i|\n state = true\n (i+1...a.size).each do |j|\n (state = false; break;) if j - a[j] == i - a[i]\n end\n return true if state\n end\n false\nend\n\n\nt = gets.chomp.to_i\n(0...t).each do |_|\n n = gets.chomp.to_i\n l = gets.chomp.split.map(&:to_i)\n r = []\n l.sort.permutation.each do |a|\n (r = a; break;) if check(a)\n end\n print r.join(' ')\n puts\nend\n\n\n"}, {"source_code": "def check(a)\n (0...a.size).each do |i|\n state = true\n (i+1...a.size).each do |j|\n (state = false; break;) if j - a[j] == i - a[i]\n end\n return true if state\n end\n false\nend\n\n\nt = gets.chomp.to_i\n(0...t).each do |_|\n n = gets.chomp.to_i\n l = gets.chomp.split.map(&:to_i)\n r = []\n l.permutation.each do |a|\n r = a if check(a)\n end\n print r.join(' ')\n puts\nend\n\n\n"}], "src_uid": "1d89df4153d70087d212b711852eba5f"} {"source_code": "M, N = gets.split.map(&:to_i)\nwrong = Array.new(N)\n\nN.times do |i|\n puts 1\n $stdout.flush\n result = gets.to_i\n exit if result == 0\n wrong[i] = (result != 1)\nend\n\nub = M\nlb = 2\n60.times do |i|\n mid = (ub+lb)/2\n puts mid\n $stdout.flush\n result = gets.to_i\n exit if result == 0\n if (result == 1) ^ wrong[i%N]\n lb = mid + 1\n else\n ub = mid - 1\n end\nend", "positive_code": [{"source_code": "q = 60\nm, n = gets.strip.split.map(&:to_i)\nseq=Array.new(n)\n\nq-=n\n\nn.times do |i|\n puts 1\n STDOUT.flush\n seq[i] = gets.to_i\n exit(0) if seq[i]==0\nend\n\nlo=1\nhi=m\nsi=0\nwhile lo<=hi\n mid=((lo+hi)/2)\n puts mid\n STDOUT.flush\n res = gets.to_i\n res *= seq[si]\n si+=1\n si%=n\n if res==0 || res.abs==2\n exit 0\n elsif res==1\n lo=mid+1\n else\n hi=mid\n end \nend"}], "negative_code": [{"source_code": "N, M = gets.split.map(&:to_i)\nwrong = Array.new(N)\n\nN.times do |i|\n puts 1\n $stdout.flush\n result = gets.to_i\n exit if result == 0\n wrong[i] = (result == 1)\nend\n\nub = M\nlb = 2\nN.times do |i|\n mid = (ub+lb)/2\n puts mid\n $stdout.flush\n result = gets.to_i\n exit if result == 0\n if (result == 1) ^ wrong[i]\n lb = mid + 1\n else\n ub = mid - 1\n end\nend"}, {"source_code": "M, N = gets.split.map(&:to_i)\nwrong = Array.new(N)\n\nN.times do |i|\n puts 1\n $stdout.flush\n result = gets.to_i\n exit if result == 0\n wrong[i] = (result != 1)\nend\n\nub = M\nlb = 2\nN.times do |i|\n mid = (ub+lb)/2\n puts mid\n $stdout.flush\n result = gets.to_i\n exit if result == 0\n if (result == 1) ^ wrong[i]\n lb = mid + 1\n else\n ub = mid - 1\n end\nend"}, {"source_code": "q = 60\nm, n = gets.strip.split.map(&:to_i)\nseq=Array.new(n)\n\nq-=n\n\nn.times do |i|\n puts 0\n STDOUT.flush\n seq[i] = gets.to_i\nend\n\nlo=1\nhi=m\nsi=0\nwhile lo<=hi\n mid=((lo+hi)/2)\n puts mid\n STDOUT.flush\n res = gets.to_i\n res *= seq[si]\n si+=1\n si%=n\n if res==0 || res.abs==2\n exit 0\n elsif res==1\n lo=mid+1\n else\n hi=mid\n end \nend"}, {"source_code": "q = 60\nm, n = gets.strip.split.map(&:to_i)\nseq=Array.new(n)\n\nq-=n\n\nn.times do |i|\n puts -1\n STDOUT.flush\n seq[i] = gets.to_i\nend\n\nlo=1\nhi=m\nsi=0\nwhile lo<=hi\n mid=((lo+hi)/2)\n puts mid\n STDOUT.flush\n res = gets.to_i\n res *= seq[si]\n si+=1\n si%=n\n if res==0 || res.abs==2\n exit 0\n elsif res==1\n lo=mid+1\n else\n hi=mid\n end \nend"}], "src_uid": "f06dff83491772f8879e45b90b61dc88"} {"source_code": "gets.to_i.times do\r\n n,k=gets.split.map(&:to_i)\r\n if k==1\r\n puts 1\r\n elsif n==1\r\n puts k\r\n elsif n%k==0\r\n puts 1\r\n elsif n k\r\n puts (k + n - 1) / n\r\nend"}], "negative_code": [], "src_uid": "a28b84c9d1a54e322ab2d54bd5ab45c8"} {"source_code": "q = gets.to_i\n(1..q).each do\n n = gets.to_i\n count = Array.new(n + 10, 0)\n candies = gets.split(\" \").map{|c| c.to_i}\n candies.each {|candy| count[candy] += 1}\n hash = {}\n res = []\n count.each do |cnt|\n tmp = cnt\n while tmp > 0 && hash[tmp] == 1\n tmp -= 1\n end\n res << tmp\n hash[tmp] = 1\n end\n sum = 0\n res.each {|rs| sum += rs}\n puts sum\nend", "positive_code": [{"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2= last ? last-1 : val\n last = last < 0 ? 0 : last\n ans += last\n end\n\n print \"#{ans}\\n\"\nend\n"}], "negative_code": [{"source_code": "q = gets.chomp.to_i\n\nfor ii in 1..q\n gets.chomp.to_i\n tab = gets.chomp.split(\" \").map {|el| el.to_i}\n better = {}\n tab.each do |el|\n better[el] = 0 unless better.key?(el)\n better[el] += 1\n end\n\n # better = better.sort_by(&:last).reverse\n ans = 0\n last = 2000000\n\n better.each do |k, val|\n last = val >= last ? last-1 : val\n last = last < 0 ? 0 : last\n ans += last\n end\n\n print \"#{ans}\\n\"\nend\n"}, {"source_code": "q = gets.to_i\n(1..q).each do\n n = gets.to_i\n count = Array.new(1000000, 0)\n candies = gets.split(\" \").map{|c| c.to_i}\n candies.each {|candy| count[candy] += 1}\n hash = Array.new(1000000, 0)\n res = Array.new(1, 0)\n count.each do |cnt|\n tmp = cnt\n while tmp > 0 && hash[tmp] == 1\n tmp -= 1\n end\n #res.append(tmp)\n hash[tmp] = 1\n end\n sum = 0\n res.each {|rs| sum += rs}\n puts sum\nend"}], "src_uid": "a00d831da539c69d571d9720fd94eee1"} {"source_code": "n_and_m = gets.chomp\nsquares = gets.chomp\n\nn_and_m = n_and_m.split(\" \")\n\nn = n_and_m[0].to_i\nm = n_and_m[1].to_i\n\nsquares = squares.split(\" \")\nsquares.map! {|s| s.to_i}\n\nplatform = Array.new(n, 0)\n\nsquares.each do |square|\n platform[square - 1] += 1\nend\n\nscore = 0\ntotal = 0\nlength = platform.length\n\nwhile true\n platform.map {|s| total += 1 if !s.equal?(0) }\n break if !total.equal?(length)\n score += 1\n platform.map! {|s| s -= 1}\n total = 0\nend\n\nputs score", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nar = gets.split.map(&:to_i)\ncounts = Array.new(n)\nn.times{|i| counts[i] = ar.count{|a| a == i+1}}\nputs counts.include?(nil) ? 0 : counts.min"}, {"source_code": "#bismillahir rahmanir rahim \n\nn,m = gets.split.map{ |x| x.to_i } \n\nnum = gets.split.map{ |x| x.to_i } \n\nx=num.count(1) \n\nfor i in 2..n\n y = num.count(i) \n x=y if x>y \n #puts i,x,y\nend \n\nputs x\n\n=begin\nfor i in 0...m \n puts num[i] \nend \n=end \n"}, {"source_code": "n,m,*a=$<.read.split.map &:to_i\nx=[0]*n\na.each{|e|x[e-1]+=1}\np x.min"}], "negative_code": [{"source_code": "n_and_m = gets.chomp\nsquares = gets.chomp\n\nn_and_m = n_and_m.split(\" \")\nputs n_and_m.inspect\nn = n_and_m[0].to_i\nm = n_and_m[1].to_i\n\nsquares = squares.split(\" \")\nsquares.map! {|s| s.to_i}\n\nplatform = Array.new(n, 0)\n\n#puts squares.inspect\n#puts \"el tama\u00f1o del platform es : #{platform.length}\"\nsquares.each do |square|\n platform[square - 1] += 1\nend\n\nscore = 0\ntotal = 0\nlength = platform.length\n\nwhile true\n platform.map {|s| total += 1 if !s.equal?(0) }\n break if !total.equal?(length)\n score += 1\n platform.map! {|s| s -= 1}\n total = 0\nend\n\nputs score"}], "src_uid": "c249103153c5006e9b37bf15a51fe261"} {"source_code": "n,m,k=gets.split.map(&:to_i)\na=Array.new(m)\nn.times{r,c=gets.split.map(&:to_i)\nr-=1\na[r]=a[r] ? [a[r],c].min : c}\nb=a.inject:+\np b>k ? k : b\n", "positive_code": [{"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\nrequire 'prime'\nrequire 'mathn'\nrequire 'matrix'\ninclude Math\n#=================================\n\nn,m,k=gets.split.map(&:to_i)\n\nhs=Hash.new(10**9)\nn.times{\n\tr, c=gets.split.map(&:to_i)\n\ths[r]=[c, hs[r]].min\n}\n\nputs [hs.values.inject(:+), k].min\n"}, {"source_code": "n,m,k=gets.split.map(&:to_i)\na=Array.new(m)\nn.times{r,c=gets.split.map(&:to_i)\nr-=1\na[r]=a[r] ? [a[r],c].min : c}\nb=a.inject:+\np b>k ? k : b\n"}, {"source_code": "s = gets.split(\" \")\nn = s[0].to_i\nm = s[1].to_i\nk = s[2].to_i\n\nrow = Array.new()\nfor i in 1..m\n row[i] = 9999999\nend\n\nfor i in 1..n\n s = gets.split(\" \")\n key = s[0].to_i\n value = s[1].to_i\n if (value < row[key])\n row[key] = value\n end\nend\n\nsum = 0\nfor i in 1..m\n sum += row[i]\nend\n\nputs sum < k ? sum : k"}, {"source_code": "n,m,k=gets.split.map(&:to_i)\na=Array.new(m)\nn.times{r,c=gets.split.map(&:to_i)\nr-=1\na[r]=a[r] ? [a[r],c].min : c}\nb=a.inject:+\np b>k ? k : b\n"}, {"source_code": "n,m,k=gets.split.map(&:to_i)\na=Array.new(m)\nn.times{r,c=gets.split.map(&:to_i)\nr-=1\na[r]=a[r] ? [a[r],c].min : c}\nb=a.inject:+\np b>k ? k : b\n"}, {"source_code": "n,m,k=gets.split.map(&:to_i)\na=Array.new(m)\nn.times{r,c=gets.split.map(&:to_i)\nr-=1\na[r]=a[r] ? [a[r],c].min : c}\nb=a.inject:+\np b>k ? k : b"}, {"source_code": "n,m,k=gets.split.map(&:to_i)\na=Array.new(m)\nn.times{r,c=gets.split.map(&:to_i)\nr-=1\na[r]=a[r] ? [a[r],c].min : c}\nb=a.inject:+\np b>k ? k : b\n"}, {"source_code": "s = gets.chomp\nns,ms,ks = s.split(/ /)\nn = ns.to_i\nm = ms.to_i\nk = ks.to_i\nh = Hash.new\nfor i in 1..n\n\ts2 = gets.chomp\n\trs,cs = s2.split(/ /)\n\tr = rs.to_i\n\tc = cs.to_i\n\t\n\tif h.has_key?(r)\n\t\th[r] = c if h[r] > c\n\telse\n\t\th[r] = c\n\tend\nend\nsum = 0\nh.each {|key,val|\n\tsum += val\n}\nret = [sum,k].min\nputs ret"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\na = [nil] * n\nn.times do\n\tr, c = gets.split.map(&:to_i)\n\tr -= 1\n\ta[r] = a[r] ? [a[r], c].min : c \nend\np [a.compact.inject(:+), k].min\n"}, {"source_code": "n,m,k=gets.split.map(&:to_i)\na=Array.new(m)\nn.times{r,c=gets.split.map(&:to_i)\nr-=1\na[r]=a[r] ? [a[r],c].min : c}\nb=a.inject:+\np b>k ? k : b\n"}, {"source_code": "n,m,k=gets.split.map(&:to_i)\na=Array.new(m)\nn.times{r,c=gets.split.map(&:to_i)\nr-=1\na[r]=a[r] ? [a[r],c].min : c}\nb=a.inject:+\np b>k ? k : b\n"}, {"source_code": "n,m,k=gets.split.map(&:to_i)\na=Array.new(m)\nn.times{r,c=gets.split.map(&:to_i)\nr-=1\na[r]=a[r] ? [a[r],c].min : c}\nb=a.inject:+\np b>k ? k : b"}, {"source_code": "n,m,k=gets.split.map(&:to_i)\na=Array.new(m)\nn.times{r,c=gets.split.map(&:to_i)\nr-=1\na[r]=a[r] ? [a[r],c].min : c}\nb=a.inject:+\np b>k ? k : b\n"}, {"source_code": "n,m,k=gets.split.map(&:to_i)\na=Array.new(m)\nn.times{r,c=gets.split.map(&:to_i)\nr-=1\na[r]=a[r] ? [a[r],c].min : c}\nb=a.inject:+\np b>k ? k : b"}], "negative_code": [], "src_uid": "65eb0f3ab35c4d95c1cbd39fc7a4227b"} {"source_code": "gets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n as = gets.split.map(&:to_i)\r\n gets\r\n bs = gets.split.map(&:to_i)\r\n\r\n powers = (0..30).map { |i| [m ** i, i] }.to_h\r\n\r\n split = []\r\n as.each do |a|\r\n aa = a\r\n aa /= m while aa % m == 0\r\n x, y = aa, a / aa\r\n if split.last && split.last[0] == x\r\n split.last[1] += y\r\n else\r\n split << [x, y]\r\n end\r\n end\r\n\r\n ok = true\r\n bs.each do |b|\r\n if split.empty?\r\n ok = false\r\n break\r\n end\r\n x, y = split[0]\r\n if b % x == 0 && p = powers[b / x]\r\n if y >= b / x\r\n split[0][1] -= b / x\r\n else\r\n ok = false\r\n end\r\n else\r\n ok = false\r\n end\r\n split.shift if split[0][1] == 0\r\n end\r\n\r\n ok &&= split.empty?\r\n\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n", "positive_code": [{"source_code": "split = ->xs, m {\r\n chunks = []\r\n xs.each do |x|\r\n xx = x\r\n xx /= m while xx % m == 0\r\n n, count = xx, x / xx\r\n if chunks.last && chunks.last[0] == n\r\n chunks.last[1] += count\r\n else\r\n chunks << [n, count]\r\n end\r\n end\r\n chunks\r\n}\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n as = gets.split.map(&:to_i)\r\n gets\r\n bs = gets.split.map(&:to_i)\r\n\r\n ok = split[as, m] == split[bs, m]\r\n\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ndef f(x, m)\r\n cnt = 1\r\n while x % m == 0\r\n x /= m\r\n cnt *= m\r\n end\r\n return [x, cnt]\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n k = gets.to_i\r\n b = gets.split.map(&:to_i)\r\n\r\n ac = []\r\n n.times do |i|\r\n num, cnt = f(a[i], m)\r\n if ac.empty?\r\n ac << [num, cnt]\r\n elsif ac[-1][0] == num\r\n ac[-1][1] += cnt\r\n else\r\n ac << [num, cnt]\r\n end\r\n end\r\n\r\n bc = []\r\n k.times do |i|\r\n num, cnt = f(b[i], m)\r\n if bc.empty?\r\n bc << [num, cnt]\r\n elsif bc[-1][0] == num\r\n bc[-1][1] += cnt\r\n else\r\n bc << [num, cnt]\r\n end\r\n end\r\n\r\n puts bc == ac ? \"Yes\" : \"No\"\r\nend\r\n"}], "negative_code": [{"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ndef f(x, m)\r\n cnt = 1\r\n while x % m == 0\r\n x /= m\r\n cnt *= m\r\n end\r\n return [x, cnt]\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n k = gets.to_i\r\n b = gets.split.map(&:to_i)\r\n\r\n ac = []\r\n n.times do |i|\r\n if a[i] % m == 0\r\n num, cnt = f(a[i], m)\r\n if ac.empty?\r\n ac << [num, cnt]\r\n elsif ac[-1][0] == num\r\n ac[-1][1] += cnt\r\n else\r\n ac << [num, cnt]\r\n end\r\n else\r\n ac << [a[i], 1]\r\n end\r\n end\r\n\r\n bc = []\r\n k.times do |i|\r\n if b[i] % m == 0\r\n num, cnt = f(b[i], m)\r\n if bc.empty?\r\n bc << [num, cnt]\r\n elsif bc[-1][0] == num\r\n bc[-1][1] += cnt\r\n else\r\n bc << [num, cnt]\r\n end\r\n else\r\n bc << [b[i], 1]\r\n end\r\n end\r\n\r\n puts bc == ac ? \"Yes\" : \"No\"\r\nend\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ndef f(x, m)\r\n cnt = 1\r\n while x % m == 0\r\n x /= m\r\n cnt *= m\r\n end\r\n return [x, cnt]\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n k = gets.to_i\r\n b = gets.split.map(&:to_i)\r\n\r\n ac = []\r\n n.times do |i|\r\n if a[i] % m == 0\r\n ac << f(a[i], m)\r\n else\r\n ac << [a[i], 1]\r\n end\r\n end\r\n\r\n bc = []\r\n k.times do |i|\r\n if b[i] % m == 0\r\n bc << f(b[i], m)\r\n else\r\n bc << [b[i], 1]\r\n end\r\n end\r\n\r\n ans_a = []\r\n num, cnt = ac[0]\r\n (ac.size-1).times do |i|\r\n num1, cnt1 = ac[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if ac.size == i+2\r\n ans_a << [num, cnt]\r\n end\r\n else\r\n ans_a << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ans_b = []\r\n num, cnt = bc[0]\r\n (bc.size-1).times do |i|\r\n num1, cnt1 = bc[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if bc.size == i+2\r\n ans_b << [num, cnt]\r\n end\r\n else\r\n ans_b << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n puts ans_a == ans_b ? \"Yes\" : \"No\"\r\nend\r\n\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ndef f(x, m)\r\n cnt = 1\r\n while x % m == 0\r\n x /= m\r\n cnt *= m\r\n end\r\n return [x, cnt]\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n k = gets.to_i\r\n b = gets.split.map(&:to_i)\r\n\r\n ac = []\r\n n.times do |i|\r\n if a[i] % m == 0\r\n ac << f(a[i], m)\r\n else\r\n ac << [a[i], 1]\r\n end\r\n end\r\n\r\n bc = []\r\n k.times do |i|\r\n if b[i] % m == 0\r\n bc << f(b[i], m)\r\n else\r\n bc << [b[i], 1]\r\n end\r\n end\r\n\r\n ans_a = []\r\n num, cnt = ac[0]\r\n (ac.size-1).times do |i|\r\n num1, cnt1 = ac[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if ac.size == i+2\r\n ans_a << [num, cnt]\r\n end\r\n else\r\n ans_a << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ans_b = []\r\n num, cnt = bc[0]\r\n (bc.size-1).times do |i|\r\n num1, cnt1 = bc[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if bc.size == i+2\r\n ans_b << [num, cnt]\r\n end\r\n else\r\n ans_b << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ok = true\r\n ans_a.size.times do |i|\r\n num1, cnt1 = ans_a[i]\r\n num2, cnt2 = ans_b[i]\r\n\r\n break ok = false if num1 != num2 || cnt1 != cnt2\r\n end\r\n\r\n puts ok ? \"Yes\" : \"No\"\r\nend\r\n\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ndef f(x, m)\r\n cnt = 1\r\n while x % m == 0\r\n x /= m\r\n cnt *= m\r\n end\r\n return [x, cnt]\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n k = gets.to_i\r\n b = gets.split.map(&:to_i)\r\n\r\n ac = []\r\n n.times do |i|\r\n if a[i] % m == 0\r\n min, cnt = f(a[i], m)\r\n ac << [min, cnt]\r\n else\r\n ac << [a[i], 1]\r\n end\r\n end\r\n\r\n bc = []\r\n k.times do |i|\r\n if b[i] % m == 0\r\n min, cnt = f(b[i], m)\r\n bc << [min, cnt]\r\n else\r\n bc << [b[i], 1]\r\n end\r\n end\r\n\r\n ans_a = []\r\n num, cnt = ac[0]\r\n (ac.size-1).times do |i|\r\n num1, cnt1 = ac[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if ac.size == i+2\r\n ans_a << [num, cnt]\r\n end\r\n else\r\n ans_a << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ans_b = []\r\n num, cnt = bc[0]\r\n (bc.size-1).times do |i|\r\n num1, cnt1 = bc[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if bc.size == i+2\r\n ans_b << [num, cnt]\r\n end\r\n else\r\n ans_b << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ok = false\r\n\r\n if ans_a.size == ans_b.size\r\n ok = true\r\n ans_a.size.times do |i|\r\n next if ans_a[i] == ans_b[i]\r\n num1, cnt1 = ans_a[i]\r\n num2, cnt2 = ans_b[i]\r\n\r\n break ok = false if num1 != num2 || cnt1 != cnt2\r\n end\r\n end\r\n\r\n puts ok ? \"Yes\" : \"No\"\r\nend\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ndef f(x, m)\r\n while x % m == 0\r\n x /= m\r\n end\r\n return x\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n k = gets.to_i\r\n b = gets.split.map(&:to_i)\r\n\r\n ac = []\r\n n.times do |i|\r\n if a[i] % m == 0\r\n min = f(a[i], m)\r\n ac << min\r\n else\r\n ac << a[i]\r\n end\r\n end\r\n\r\n bc = []\r\n k.times do |i|\r\n if b[i] % m == 0\r\n min = f(b[i], m)\r\n bc << min\r\n else\r\n bc << b[i]\r\n end\r\n end\r\n\r\n ans_a = ac.slice_when{|i,j| i != j}.map{|e| e[0]}\r\n ans_b = bc.slice_when{|i,j| i != j}.map{|e| e[0]}\r\n\r\n puts ans_a == ans_b ? \"Yes\" : \"No\"\r\nend\r\n\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ndef f(x, m)\r\n while x % m == 0\r\n x /= m\r\n end\r\n return x\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n k = gets.to_i\r\n b = gets.split.map(&:to_i)\r\n\r\n ac = []\r\n n.times do |i|\r\n if a[i] % m == 0\r\n min = f(a[i], m)\r\n ac << min\r\n else\r\n ac << a[i]\r\n end\r\n end\r\n\r\n bc = []\r\n k.times do |i|\r\n if b[i] % m == 0\r\n min = f(b[i], m)\r\n bc << min\r\n else\r\n bc << b[i]\r\n end\r\n end\r\n\r\n ans_a = ac.slice_when{|i,j| i != j}.map{|e| e[0]}\r\n ans_b = bc.slice_when{|i,j| i != j}.map{|e| e[0]}\r\n\r\n ok = false\r\n if ans_a.size == ans_b.size\r\n ok = true\r\n ans_a.size.times do |i|\r\n num1 = ans_a[i]\r\n num2 = ans_b[i]\r\n\r\n break ok = false if num1 != num2\r\n end\r\n end\r\n\r\n puts ok ? \"Yes\" : \"No\"\r\nend\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ndef f(x, m)\r\n cnt = 1\r\n while x % m == 0\r\n x /= m\r\n cnt *= m\r\n end\r\n return [x, cnt]\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n k = gets.to_i\r\n b = gets.split.map(&:to_i)\r\n\r\n ac = []\r\n n.times do |i|\r\n if a[i] % m == 0\r\n min, cnt = f(a[i], m)\r\n ac << [min, cnt]\r\n else\r\n ac << [a[i], 1]\r\n end\r\n end\r\n\r\n bc = []\r\n k.times do |i|\r\n if b[i] % m == 0\r\n min, cnt = f(b[i], m)\r\n bc << [min, cnt]\r\n else\r\n bc << [b[i], 1]\r\n end\r\n end\r\n\r\n ans_a = []\r\n num, cnt = ac[0]\r\n (ac.size-1).times do |i|\r\n num1, cnt1 = ac[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if ac.size == i+2\r\n ans_a << [num, cnt]\r\n end\r\n else\r\n ans_a << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ans_b = []\r\n num, cnt = bc[0]\r\n (bc.size-1).times do |i|\r\n num1, cnt1 = bc[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if bc.size == i+2\r\n ans_b << [num, cnt]\r\n end\r\n else\r\n ans_b << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ok = false\r\n if ans_a.size == ans_b.size\r\n ok = true\r\n ans_a.size.times do |i|\r\n num1, cnt1 = ans_a[i]\r\n num2, cnt2 = ans_b[i]\r\n\r\n break ok = false if num1 != num2\r\n end\r\n end\r\n\r\n puts ok ? \"Yes\" : \"No\"\r\nend\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ndef f(x, m)\r\n cnt = 0\r\n while x % m == 0\r\n x /= m\r\n cnt += 1\r\n end\r\n return [x, cnt]\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n k = gets.to_i\r\n b = gets.split.map(&:to_i)\r\n\r\n ac = []\r\n n.times do |i|\r\n if a[i] % m == 0\r\n min, cnt = f(a[i], m)\r\n ac << [min, 1 << cnt]\r\n else\r\n ac << [a[i], 1]\r\n end\r\n end\r\n\r\n bc = []\r\n k.times do |i|\r\n if b[i] % m == 0\r\n min, cnt = f(b[i], m)\r\n bc << [min, 1 << cnt]\r\n else\r\n bc << [b[i], 1]\r\n end\r\n end\r\n\r\n ans_a = []\r\n num, cnt = ac[0]\r\n (ac.size-1).times do |i|\r\n num1, cnt1 = ac[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if ac.size == i+2\r\n ans_a << [num, cnt]\r\n end\r\n else\r\n ans_a << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ans_b = []\r\n num, cnt = bc[0]\r\n (bc.size-1).times do |i|\r\n num1, cnt1 = bc[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if bc.size == i+2\r\n ans_b << [num, cnt]\r\n end\r\n else\r\n ans_b << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ok = false\r\n\r\n if ans_a.size == ans_b.size\r\n ok = true\r\n ans_a.size.times do |i|\r\n next if ans_a[i] == ans_b[i]\r\n\r\n num1, cnt1 = ans_a[i]\r\n num2, cnt2 = ans_b[i]\r\n\r\n break ok = false if num1 != num2\r\n end\r\n end\r\n\r\n puts ok ? \"Yes\" : \"No\"\r\nend\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ndef f(x, m)\r\n cnt = 0\r\n while x % m == 0\r\n x /= m\r\n cnt += 1\r\n end\r\n return [x, cnt]\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n k = gets.to_i\r\n b = gets.split.map(&:to_i)\r\n\r\n ac = []\r\n n.times do |i|\r\n if a[i] % m == 0\r\n min, cnt = f(a[i], m)\r\n ac << [min, 1 << cnt]\r\n else\r\n ac << [a[i], 1]\r\n end\r\n end\r\n\r\n bc = []\r\n k.times do |i|\r\n if b[i] % m == 0\r\n min, cnt = f(b[i], m)\r\n bc << [min, 1 << cnt]\r\n else\r\n bc << [b[i], 1]\r\n end\r\n end\r\n\r\n ans_a = []\r\n num, cnt = ac[0]\r\n (ac.size-1).times do |i|\r\n num1, cnt1 = ac[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if ac.size == i+2\r\n ans_a << [num, cnt]\r\n end\r\n else\r\n ans_a << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ans_b = []\r\n num, cnt = bc[0]\r\n (bc.size-1).times do |i|\r\n num1, cnt1 = bc[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if bc.size == i+2\r\n ans_b << [num, cnt]\r\n end\r\n else\r\n ans_b << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ok = false\r\n\r\n if ans_a.size == ans_b.size\r\n ok = true\r\n ans_a.size.times do |i|\r\n next if ans_a[i] == ans_b[i]\r\n num1, cnt1 = ans_a[i]\r\n num2, cnt2 = ans_b[i]\r\n\r\n break ok = false if num1 != num2\r\n\r\n if cnt1 != cnt2\r\n s = m-2\r\n break ok = false if s == 0\r\n break ok = false if (cnt1 < m && cnt2 < m) || (cnt2 - cnt1).abs % s != 0\r\n end\r\n end\r\n end\r\n\r\n puts ok ? \"Yes\" : \"No\"\r\nend\r\n\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ndef f(x, m)\r\n cnt = 0\r\n while x % m == 0\r\n x /= m\r\n cnt += 1\r\n end\r\n return [x, cnt]\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n k = gets.to_i\r\n b = gets.split.map(&:to_i)\r\n\r\n ac = []\r\n n.times do |i|\r\n if a[i] % m == 0\r\n min, cnt = f(a[i], m)\r\n ac << [min, 1 << cnt]\r\n else\r\n ac << [a[i], 1]\r\n end\r\n end\r\n\r\n bc = []\r\n k.times do |i|\r\n if b[i] % m == 0\r\n min, cnt = f(b[i], m)\r\n bc << [min, 1 << cnt]\r\n else\r\n bc << [b[i], 1]\r\n end\r\n end\r\n\r\n ans_a = []\r\n num, cnt = ac[0]\r\n (ac.size-1).times do |i|\r\n num1, cnt1 = ac[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if ac.size == i+2\r\n ans_a << [num, cnt]\r\n end\r\n else\r\n ans_a << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ans_b = []\r\n num, cnt = bc[0]\r\n (bc.size-1).times do |i|\r\n num1, cnt1 = bc[i+1]\r\n if num == num1\r\n cnt += cnt1\r\n if bc.size == i+2\r\n ans_b << [num, cnt]\r\n end\r\n else\r\n ans_b << [num, cnt]\r\n num = num1\r\n cnt = cnt1\r\n end\r\n end\r\n\r\n ok = false\r\n if ans_a.size == ans_b.size\r\n\r\n ok = true\r\n ans_a.size.times do |i|\r\n next if ans_a[i] == ans_b[i]\r\n num1, cnt1 = ans_a[i]\r\n num2, cnt2 = ans_b[i]\r\n break ok = false if num1 != num2\r\n\r\n if cnt1 != cnt2\r\n break ok = false if cnt1 < m && cnt2 < m\r\n s = m-2\r\n if cnt1 < cnt2\r\n break ok = false if (cnt2 - cnt1) % s != 0\r\n else\r\n break ok = false if (cnt1 - cnt2) % s != 0\r\n end\r\n end\r\n end\r\n end\r\n\r\n puts ok ? \"Yes\" : \"No\"\r\nend\r\n\r\n"}], "src_uid": "2ff40423619cefd8c2fb35a18549c411"} {"source_code": "t = gets.to_s.to_i\n\ndef solve_case1(a)\n orig_sum = a[-1]\n tmp = a.reduce(0) {|acc, x| acc + x } - orig_sum\n x_idx = nil\n 0.upto(a.size - 2) do |i|\n if tmp - a[i] == orig_sum\n x_idx = i\n end\n end\n return nil if !x_idx\n a.select.with_index {|x, i| (i != x_idx) && (i != a.size - 1)}\nend\n\ndef solve_case2(a)\n tmp = a.reduce(0) {|acc, x| acc + x } - a[-1] - a[-2]\n if tmp == a[-2]\n return a[0 .. -3]\n end\n return nil\nend\n\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }.sort\n\n # case 1 (the sum is the largest number)\n x = solve_case1(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n # case 2\n x = solve_case2(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n printf(\"-1\\n\")\nend\n", "positive_code": [{"source_code": "t = gets.to_i\r\nt.times do\r\n\tn = gets.to_i\r\n\ta = gets.split.map(&:to_i).sort\r\n\ts = a.sum - a[n+1]\r\n\r\n\tidx = -1\r\n\tfor i in 0..n\r\n\t\tif s - a[i] == a[n+1]\r\n\t\t\tidx = i\r\n\t\t\tbreak\r\n\t\tend\r\n\tend\r\n\r\n\tif idx == -1\r\n\t\tif s == 2*a[n]\r\n\t\t\tidx = n\r\n\t\telse\r\n\t\t\tputs -1\r\n\t\t\tnext\r\n\t\tend\r\n\tend\r\n\r\n\tfor i in 0..n\r\n\t\tnext if i == idx\r\n\t\tprint a[i], \" \"\r\n\tend\r\n\tputs \"\"\r\nend\r\n"}], "negative_code": [{"source_code": "t = gets.to_s.to_i\n\ndef solve_case1(a)\n orig_sum = a[-1]\n tmp = a.reduce(0) {|acc, x| acc + x } - orig_sum\n x_idx = nil\n 0.upto(a.size - 2) do |i|\n if tmp - a[i] == orig_sum\n x_idx = i\n end\n end\n return nil if !x_idx\n a.select.with_index {|x, i| (i != x_idx) && (i != a.size - 1)}\nend\n\ndef solve_case2(a)\n a[-1] = a[-2]\n return solve_case1(a.sort)\nend\n\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }.sort\n\n # case 1 (the sum is the largest number)\n x = solve_case1(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n # case 2\n x = solve_case2(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n printf(\"-1\\n\")\nend\n"}, {"source_code": "t = gets.to_s.to_i\n\ndef solve_case1(a)\n orig_sum = a[-1]\n tmp = a.reduce(0) {|acc, x| acc + x } - orig_sum\n 0.upto(a.size - 2) do |i|\n if tmp - a[i] == orig_sum\n if i == 0\n return a[i + 1 .. -2]\n elsif i == a.size - 2\n return a[0 .. i - 1]\n else\n return a[0 .. i - 1] + a[i + 1 .. -2]\n end\n end\n end\n return nil\nend\n\ndef solve_case2(a)\n a[-1] = a[-2]\n return solve_case1(a.sort)\nend\n\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }.sort\n\n # case 1 (the sum is the largest number)\n x = solve_case1(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n # case 2\n x = solve_case2(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n printf(\"-1\\n\")\nend\n"}, {"source_code": "t = gets.to_s.to_i\n\ndef solve_case1(a)\n orig_sum = a[-1]\n tmp = a.reduce(0) {|acc, x| acc + x } - orig_sum\n 0.upto(a.size - 3) do |i|\n if tmp - a[i] == orig_sum\n if i == 0\n return a[i + 1 .. -2]\n elsif i == a.size - 3\n return a[0 .. i - 1]\n else\n return a[0 .. i - 1] + a[i + 1 .. -2]\n end\n end\n end\n return nil\nend\n\ndef solve_case2(a)\n a[-1] = a[-2]\n return solve_case1(a.sort)\nend\n\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }.sort\n\n # case 1 (the sum is the largest number)\n x = solve_case1(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n # case 2\n x = solve_case2(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n printf(\"-1\\n\")\nend\n"}, {"source_code": "t = gets.to_s.to_i\n\ndef solve_case1(a)\n orig_sum = a[-1]\n tmp = a.reduce(0) {|acc, x| acc + x } - orig_sum\n 0.upto(a.size - 2) do |i|\n if tmp - a[i] == orig_sum\n if i == 0\n return a[i + 1 .. -2]\n elsif i == a.size - 3\n return a[0 .. i - 1]\n else\n return a[0 .. i - 1] + a[i + 1 .. -2]\n end\n end\n end\n return nil\nend\n\ndef solve_case2(a)\n a[-1] = a[-2]\n return solve_case1(a.sort)\nend\n\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }.sort\n\n # case 1 (the sum is the largest number)\n x = solve_case1(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n # case 2\n x = solve_case2(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n printf(\"-1\\n\")\nend\n"}, {"source_code": "t = gets.to_s.to_i\n\ndef solve_case1(a)\n orig_sum = a[-1]\n tmp = a.reduce(0) {|acc, x| acc + x } - orig_sum\n 0.upto(a.size - 2) do |i|\n if tmp - a[i] == orig_sum\n if i == 0\n return a[i + 1 .. -2]\n elsif i == a.size - 3\n return a[0 .. i - 1]\n else\n return a[0 .. i - 1] + a[i + 1 .. -2]\n end\n end\n end\n return nil\nend\n\ndef solve_case2(a)\n x = a[-1]\n orig_sum = a[-2]\n tmp = a.reduce(0) {|acc, x| acc + x } - x - orig_sum\n if tmp == orig_sum\n return a[0 .. -3]\n end\n return nil\nend\n\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }.sort\n\n # case 1 (the sum is the largest number)\n x = solve_case1(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n # case 2 (the X \n x = solve_case2(a)\n if x\n printf(\"%s\\n\", x.join(\" \"))\n next\n end\n\n printf(\"-1\\n\")\nend\n"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n\tn = gets.to_i\r\n\ta = gets.split.map(&:to_i).sort\r\n\ts = a.sum - a[n+1]\r\n\r\n\tidx = -1\r\n\tfor i in 0..n\r\n\t\tif s - a[i] == a[n+1]\r\n\t\t\tidx = i\r\n\t\t\tbreak\r\n\t\tend\r\n\tend\r\n\r\n\tif idx == -1\r\n\t\tunless s == 2*a[n]\r\n\t\t\tputs -1\r\n\t\t\tnext\r\n\t\tend\r\n\tend\r\n\r\n\tfor i in 0..n\r\n\t\tnext if i == idx\r\n\t\tprint a[i], \" \"\r\n\tend\r\n\tputs \"\"\r\nend\r\n"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n\tn = gets.to_i\r\n\ta = gets.split.map(&:to_i).sort\r\n\ts = a.sum - a[n+1]\r\n\r\n\tidx = -1\r\n\tfor i in 0..n\r\n\t\tif s - a[i] == a[n+1]\r\n\t\t\tidx = i\r\n\t\t\tbreak\r\n\t\tend\r\n\tend\r\n\r\n\tif idx == -1\r\n\t\tputs -1\r\n\t\tnext\r\n\tend\r\n\r\n\tfor i in 0..n\r\n\t\tnext if i == idx\r\n\t\tprint a[i], \" \"\r\n\tend\r\n\tputs \"\"\r\nend\r\n"}], "src_uid": "ce667a8fb60841c994aebedb35a3b0d8"} {"source_code": "$candies_amount, initial_jump_height = gets.split.map(&:to_i)\n$candies = []\n\n$candies_amount.times do\n candy = {}\n candy[:type], candy[:height], candy[:weight] = gets.split.map(&:to_i)\n $candies << candy\nend\n\n$candies.sort_by! {|t| -t[:weight]}\n\n$max_ate = 0\n$tries = {0 => [], 1 => []}\n\ndef find_max(eaten, last_eaten_type, current_jump_height)\n if ($tries[last_eaten_type][eaten.size] || -1 ) >= current_jump_height\n return\n end\n\n $tries[last_eaten_type][eaten.size] = current_jump_height\n\n available = (0..$candies_amount-1).to_a - eaten\n available_of_type = available.keep_if {|i| $candies[i][:type] != last_eaten_type }\n available_of_height = available_of_type.keep_if {|i| $candies[i][:height] <= current_jump_height}\n\n if available_of_height.length > 0\n # puts available_of_height.join(', ')\n max_weighted = $candies[available_of_height.first]\n find_max(eaten + [available_of_height.first], max_weighted[:type], current_jump_height + max_weighted[:weight])\n else\n $max_ate = eaten.size if eaten.size > $max_ate\n end\nend\n\nfind_max([], 0, initial_jump_height)\n# puts\n# puts\nfind_max([], 1, initial_jump_height)\nputs $max_ate\n", "positive_code": [{"source_code": "$candies_amount, initial_jump_height = gets.split.map(&:to_i)\n$candies = []\n\n$candies_amount.times do\n candy = {}\n candy[:type], candy[:height], candy[:weight] = gets.split.map(&:to_i)\n $candies << candy\nend\n\n$candies.sort_by! {|t| -t[:weight]}\n\n$max_ate = 0\n$tries = {0 => [], 1 => []}\n$ate = Array.new($candies_amount, false)\n\ndef find_max(eaten, last_eaten_type, current_jump_height)\n if ($tries[last_eaten_type][eaten.size] || -1 ) >= current_jump_height\n return\n end\n\n $tries[last_eaten_type][eaten.size] = current_jump_height\n\n to_eat_index = nil\n to_eat = nil\n $candies.each_with_index do |candy, i|\n if !$ate[i] && candy[:type] != last_eaten_type && candy[:height] <= current_jump_height\n to_eat_index = i\n to_eat = candy\n break\n end\n end\n\n if to_eat_index\n $ate[to_eat_index] = true\n find_max(eaten + [to_eat_index], to_eat[:type], current_jump_height + to_eat[:weight])\n $ate[to_eat_index] = false\n else\n $max_ate = eaten.size if eaten.size > $max_ate\n end\nend\n\nfind_max([], 0, initial_jump_height)\n# puts\n# puts\nfind_max([], 1, initial_jump_height)\nputs $max_ate\n"}, {"source_code": "$candies_amount, initial_jump_height = gets.split.map(&:to_i)\n$candies = []\n\n$candies_amount.times do\n candy = {}\n candy[:type], candy[:height], candy[:weight] = gets.split.map(&:to_i)\n $candies << candy\nend\n\n$candies.sort_by! {|t| -t[:weight]}\n\n$max_ate = 0\n# $tries = {0 => [], 1 => []}\n$ate = Array.new($candies_amount, false)\n\ndef find_max(eaten, last_eaten_type, current_jump_height)\n # if ($tries[last_eaten_type][eaten.size] || -1 ) >= current_jump_height\n # return\n # end\n\n # $tries[last_eaten_type][eaten.size] = current_jump_height\n\n to_eat_index = nil\n to_eat = nil\n $candies.each_with_index do |candy, i|\n if !$ate[i] && candy[:type] != last_eaten_type && candy[:height] <= current_jump_height\n to_eat_index = i\n to_eat = candy\n break\n end\n end\n\n if to_eat_index\n $ate[to_eat_index] = true\n find_max(eaten + [to_eat_index], to_eat[:type], current_jump_height + to_eat[:weight])\n $ate[to_eat_index] = false\n else\n $max_ate = eaten.size if eaten.size > $max_ate\n end\nend\n\nfind_max([], 0, initial_jump_height)\n# puts\n# puts\nfind_max([], 1, initial_jump_height)\nputs $max_ate\n"}, {"source_code": "n,x = readline.strip.split.map(&:to_i)\n\ncandies = [[],[]]\nn.times{\n t,h,m = readline.strip.split.map(&:to_i)\n candies[t] << [h,m]\n}\n\n# all_candies.each{|candies| candies.sort_by!{|h,m| -h } }\n\ndef count_max_num(candies_group_now, candies_group_next_turn, height, count)\n # puts \"(#{candies_group_now}; #{candies_group_next_turn}; #{height}; #{count})\"\n target_candies = candies_group_now.select{|h,m| h <= height }\n # puts \" target:#{target_candies}\"\n \n if target_candies.empty?\n # puts \"count:#{count}\"\n return count\n end\n\n h,m = target_candies.max_by{|h,m| m}\n idx = candies_group_now.index([h,m])\n \n count_max_num(candies_group_next_turn, candies_group_now.dup.tap{|cnd| cnd.delete_at(idx) }, height + m, count + 1)\nend\n\nputs [count_max_num(candies[0], candies[1], x, 0), count_max_num(candies[1], candies[0], x, 0)].max\n"}], "negative_code": [{"source_code": "require 'ostruct'\n\n$candies_amount, initial_jump_height = gets.split.map(&:to_i)\n$candies = []\n\n$candies_amount.times do\n candy = OpenStruct.new\n candy.type, candy.height, candy.weight = gets.split.map(&:to_i)\n $candies << candy\nend\n\n$max_ate = 0\n\n$tries = {nil => [], 0 => [], 1 => []}\n\ndef find_max(index, ate, last_eaten_type, jump_height)\n if index == $candies_amount\n $max_ate = ate if ate > $max_ate\n return\n end\n\n tries = $tries[last_eaten_type][index]\n if tries && tries.detect {|t| t[:height] > jump_height && t[:ate] > ate}\n return\n end\n\n $tries[last_eaten_type][index] ||= []\n $tries[last_eaten_type][index] << {height: jump_height, ate: ate}\n\n current_candy = $candies[index]\n\n if last_eaten_type != current_candy.type && jump_height >= current_candy.height\n find_max(index+1, ate+1, current_candy.type, jump_height + current_candy.weight )\n end\n\n find_max(index+1, ate, last_eaten_type, jump_height)\nend\n\nfind_max(0, 0, nil, initial_jump_height)\nputs $max_ate"}, {"source_code": "require 'ostruct'\n\n$candies_amount, initial_jump_height = gets.split.map(&:to_i)\n$candies = []\n\n$candies_amount.times do\n candy = OpenStruct.new\n candy.type, candy.height, candy.weight = gets.split.map(&:to_i)\n $candies << candy\nend\n\n$max_ate = 0\n\n$tries = {nil => [], 0 => [], 1 => []}\n\ndef find_max(index, ate, last_eaten_type, jump_height)\n if index == $candies_amount\n $max_ate = ate if ate > $max_ate\n return\n end\n\n # tries = $tries[last_eaten_type][index]\n # if tries && tries.detect {|t| t[:height] >= jump_height && t[:ate] >= ate}\n # return\n # end\n\n # $tries[last_eaten_type][index] ||= []\n # $tries[last_eaten_type][index] << {height: jump_height, ate: ate}\n\n current_candy = $candies[index]\n\n if last_eaten_type != current_candy.type && jump_height >= current_candy.height\n find_max(index+1, ate+1, current_candy.type, jump_height + current_candy.weight )\n end\n\n find_max(index+1, ate, last_eaten_type, jump_height)\nend\n\nfind_max(0, 0, nil, initial_jump_height)\nputs $max_ate"}, {"source_code": "require 'ostruct'\n\n$candies_amount, initial_jump_height = gets.split.map(&:to_i)\n$candies = []\n\n$candies_amount.times do\n candy = OpenStruct.new\n candy.type, candy.height, candy.weight = gets.split.map(&:to_i)\n $candies << candy\nend\n\n$max_ate = 0\n\n$tries = {nil => [], 0 => [], 1 => []}\n\ndef find_max(index, ate, last_eaten_type, jump_height)\n if index == $candies_amount\n $max_ate = ate if ate > $max_ate\n return\n end\n\n tries = $tries[last_eaten_type][index]\n if tries && tries.detect {|t| t[:height] >= jump_height && t[:ate] >= ate}\n return\n end\n\n $tries[last_eaten_type][index] ||= []\n $tries[last_eaten_type][index] << {height: jump_height, ate: ate}\n\n current_candy = $candies[index]\n\n if last_eaten_type != current_candy.type && jump_height >= current_candy.height\n find_max(index+1, ate+1, current_candy.type, jump_height + current_candy.weight )\n end\n\n find_max(index+1, ate, last_eaten_type, jump_height)\nend\n\nfind_max(0, 0, 1, initial_jump_height)\nfind_max(0, 0, 0, initial_jump_height)\nputs $max_ate"}, {"source_code": "$candies_amount, initial_jump_height = gets.split.map(&:to_i)\n$candies = []\n\n$candies_amount.times do\n candy = {}\n candy[:type], candy[:height], candy[:weight] = gets.split.map(&:to_i)\n $candies << candy\nend\n\n$max_ate = 0\n\n$tries = {nil => [], 0 => [], 1 => []}\n\ndef find_max(index, ate, last_eaten_type, jump_height)\n if index == $candies_amount\n $max_ate = ate if ate > $max_ate\n return\n end\n\n tries = $tries[last_eaten_type][index]\n if tries && tries.detect {|t| t[:height] >= jump_height && t[:ate] >= ate}\n return\n end\n\n $tries[last_eaten_type][index] ||= []\n $tries[last_eaten_type][index] << {height: jump_height, ate: ate}\n\n if last_eaten_type != $candies[index][:type] && jump_height >= $candies[index][:height]\n find_max(index+1, ate+1, $candies[index][:type], jump_height + $candies[index][:weight] )\n end\n\n find_max(index+1, ate, last_eaten_type, jump_height)\nend\n\nfind_max(0, 0, nil, initial_jump_height)\nputs $max_ate"}], "src_uid": "6253f6217c58a66573b1ddc6962c372c"} {"source_code": "#!/usr/bin/ruby\n\n#read data\ninput_line = gets\nparams = input_line.split(' ')\nn = params[0].to_i\nk = params[1].to_i\n\na = gets.split(\" \").map {|i| i.to_i}\n\n#find max(a) and min(a)\n\nif ((a.max - a.min)>k)\n puts 'NO'\nelse\n puts 'YES'\n a.each do |a_i|\n res = ''\n (0...a_i).each do |a_i_j|\n res += ((a_i_j % k)+1).to_s + ' '\n end\n puts res.strip\n end\nend", "positive_code": [{"source_code": "n,k = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n# col = arr.map{|a| a/k}\na,b = arr.minmax\n# puts \"#{col.minmax}\"\nans = true\nans = false if b - a > k\ncol_arr = (1..k).to_a\n\nx = (100 / k.to_f).ceil\ncol_arr *= x\n# puts \"#{col_arr.length}\"\nif ans\n\tputs \"YES\"\n\tarr.each do |a|\n\t\tputs col_arr[0..(a-1)].join(\" \")\n\tend\nelse\n\tputs \"NO\"\nend\n#"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n# col = arr.map{|a| a/k}\na,b = arr.minmax\n# puts \"#{col.minmax}\"\nans = true\nans = false if b - a > k\ncol_arr = (1..k).to_a\n\nx = (100 / k.to_f).ceil\ncol_arr *= x\n# puts \"#{col_arr.length}\"\nif ans\n\tputs \"YES\"\n\tarr.each do |a|\n\t\tputs col_arr[0..(a-1)].join(\" \")\n\tend\nelse\n\tputs \"NO\"\nend"}, {"source_code": "inp = gets.split(' ')\nn = inp[0].to_i\nm = inp[1].to_i\n\npebbles = gets.split(' ')\ncolors = Array.new() { Array.new() }\ncount = Array.new(n) { Array.new(m, 0) }\n\nfor i in 0..(n - 1)\n\tpebbles[i] = pebbles[i].to_i\n\tcolors << Array.new(pebbles[i], 0)\nend\n\nfor i in 0..(n - 1)\n\tcolor = 0\n\tfor j in 0..(pebbles[i] - 1)\n\t\tcolors[i][j] = color\n\t\tcount[i][color] += 1\n\t\tcolor += 1\n\t\tif color >= m\n\t\t\tcolor = 0\n\t\tend\n\tend\n\tfor j in 0..(i - 1)\n\t\tfor k in 0..(m - 1)\n\t\t\tif (count[j][k] - count[i][k]).abs > 1\n\t\t\t\tputs \"NO\"\n\t\t\t\texit\n\t\t\tend\n\t\tend\n\tend\nend\n\nputs \"YES\"\ncolors.each { |arr|\n\tarr.each { |el|\n\t\tprint \"#{el + 1} \"\n\t}\n\tputs\n}"}, {"source_code": "pa = Array.new\npb = Array.new\ndata = Array.new\n\nstr = gets.to_s\nstt = gets.to_s\npa = str.split\npb = stt.split\nn = pa[0].to_i\nk = pa[1].to_i\n\nfor i in 0..n-1\n data[i]=Array.new\n r = pb[i].to_i / k\n t = pb[i].to_i % k\n for j in 1..k\n if j <= t\n data[i][j] = r + 1\n else\n data[i][j] = r\n end\n end\nend\n\nflag = 0\nfor j in 1..k\n min = max = data[0][j]\n for i in 1..n-1\n if min > data[i][j]\n min = data[i][j]\n end\n if max < data[i][j]\n max = data[i][j]\n end\n end\n if max - min > 1\n flag = 1\n break\n end\nend\n\nif flag == 1\n puts \"NO\"\nelse\n puts \"YES\"\n for i in 0..n-1\n flag = 0\n for j in 1..k\n for r in 1..data[i][j]\n if flag == 0\n print j\n flag = 1\n else\n print \" \"\n print j\n end\n end\n end\n puts\n end\nend"}, {"source_code": "#!/usr/bin/env ruby\nn,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nb=a.map{|e|\n\th=Hash.new(0)\n\tz=e.times.map{|i|\n\t\tn=i%k+1\n\t\th[n]+=1\n\t\tn\n\t}\n\t[z,h]\n}\nif b.combination(2).all?{|x,y|\n\t(1..k).all?{|e|(x[1][e]-y[1][e]).abs<=1}\n}\n\tputs :YES\n\tputs b.map{|e|e[0]*' '}\nelse\n\tputs :NO\nend"}, {"source_code": "n,k=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i)\nmax,min=a.max,a.min\nif max-min>k\n\tputs \"NO\"\nelse\n\tputs \"YES\"\n\tn.times do |i|\n\t\tj=0\n\t\twhile j k \n puts 'NO'\nelse\n puts 'YES'\n n.times {|i|\n puts (t * (w.data[i] / k) + t[0, w.data[i] % k]).join(' ')\n }\nend"}], "negative_code": [{"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\ncolors = []\nn.times { colors << [] }\n\nmin = 0\nk.times do |i|\n min = (a.select { |x| x != 0}).min\n\n n.times do |j|\n min.times do |k|\n colors[j] << i + 1 if a[j] != 0\n end\n end\n\n break if min == 0\n\n a = a.map { |x| x == 0 ? 0 : x - min }\nend\n\nif a.max == 0\n puts \"YES\"\n n.times do |i|\n puts colors[i].join(\" \")\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\ncolors = []\nn.times { colors << [] }\n\nmin = 0\nk.times do |i|\n if i == 0\n min = a.min\n else\n min = 1\n end\n\n n.times do |j|\n min.times do |k|\n colors[j] << i + 1 if a[j] != 0\n end\n end\n\n a = a.map { |x| x == 0 ? 0 : x - min }\nend\n\nif a.max == 0\n puts \"YES\"\n n.times do |i|\n puts colors[i].join(\" \")\n end\nelse\n puts \"NO\"\nend\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nclass PileData\n attr_accessor :data\n def initialize(x)\n @data = x.split.map(&:to_i)\n end\nend\nn, k = gets.split.map(&:to_i)\nt = (1..k).map {|i| i}\n\nw = PileData.new(gets)\nif w.data.max - w.data.min > k \n p 'NO'\nelse\n n.times {|i|\n puts (t * (w.data[i] / k) + t[0, w.data[i] % k]).join(' ')\n }\nend"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nclass PileData\n attr_accessor :data\n def initialize(x)\n @data = x.split.map(&:to_i)\n end\nend\nn, k = gets.split.map(&:to_i)\nt = (1..k).map {|i| i}\n\nw = PileData.new(gets)\nif w.data.max - w.data.min > k \n p 'NO'\nelse\n p 'YES'\n n.times {|i|\n puts (t * (w.data[i] / k) + t[0, w.data[i] % k]).join(' ')\n }\nend"}, {"source_code": "#!/usr/bin/ruby\n\n#read data\ninput_line = gets\nparams = input_line.split(' ')\nn = params[0].to_i\nk = params[1].to_i\n\na = gets.split(\" \").map {|i| i.to_i}\n\n#find max(a) and min(a)\n\nif ((a.max - a.min)>k)\n puts 'NO'\nelse\n puts 'YES'\n res = ''\n a.each do |a_i|\n res += ((a_i % k)+1).to_s + ' '\n puts res.strip\n end\nend"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n# col = arr.map{|a| a/k}\na,b = arr.minmax\n# puts \"#{col.minmax}\"\nans = true\nans = false if b - a > k\ncol_arr = (1..k).to_a\n\nx = (100 / k.to_f).ceil\ncol_arr *= x\nputs \"#{col_arr.length}\"\nif ans\n\tputs \"YES\"\n\tarr.each do |a|\n\t\tputs col_arr[0..(a-1)].join(\" \")\n\tend\nelse\n\tputs \"NO\"\nend"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\ncol = arr.map{|a| a/k}\na,b = col.minmax\nans = true\nans = false if b - a > 1\ncol_arr = (1..k).to_a\n\nx = (100 / k.to_f).ceil\ncol_arr *= x\n# puts \"#{col_arr.length}\"\nif ans\n\tputs \"YES\"\n\tarr.each do |a|\n\t\tputs col_arr[0..(a-1)].join(\" \")\n\tend\nelse\n\tputs \"NO\"\nend"}, {"source_code": "#!/usr/bin/ruby\n\nn = gets.to_i\nm = gets.to_i\n\npebbles = Array.new(n)\ncolors = Array.new() { Array.new() }\ncount = Array.new(n) { Array.new(m, 0) }\n\nfor i in 0..(n - 1)\n\tpebbles[i] = gets.to_i\n\tcolors << Array.new(pebbles[i], 0)\nend\n\nfor i in 0..(n - 1)\n\tcolor = 0\n\tfor j in 0..(pebbles[i] - 1)\n\t\tcolors[i][j] = color\n\t\tcount[i][color] += 1\n\t\tcolor += 1\n\t\tif color >= m\n\t\t\tcolor = 0\n\t\tend\n\tend\n\tfor j in 0..(i - 1)\n\t\tfor k in 0..(m - 1)\n\t\t\tif (count[j][k] - count[i][k]).abs > 1\n\t\t\t\tputs \"NO\"\n\t\t\t\texit\n\t\t\tend\n\t\tend\n\tend\nend\n\nputs \"YES\"\ncolors.each { |arr|\n\tarr.each { |el|\n\t\tprint \"#{el + 1} \"\n\t}\n\tputs\n}"}, {"source_code": "n = gets.to_i\nm = gets.to_i\n\npebbles = Array.new(n)\ncolors = Array.new() { Array.new() }\ncount = Array.new(n) { Array.new(m, 0) }\n\nfor i in 0..(n - 1)\n\tpebbles[i] = gets.to_i\n\tcolors << Array.new(pebbles[i], 0)\nend\n\nfor i in 0..(n - 1)\n\tcolor = 0\n\tfor j in 0..(pebbles[i] - 1)\n\t\tcolors[i][j] = color\n\t\tcount[i][color] += 1\n\t\tcolor += 1\n\t\tif color >= m\n\t\t\tcolor = 0\n\t\tend\n\tend\n\tfor j in 0..(i - 1)\n\t\tfor k in 0..(m - 1)\n\t\t\tif (count[j][k] - count[i][k]).abs > 1\n\t\t\t\tputs \"NO\"\n\t\t\t\texit\n\t\t\tend\n\t\tend\n\tend\nend\n\nputs \"YES\"\ncolors.each { |arr|\n\tarr.each { |el|\n\t\tprint \"#{el + 1} \"\n\t}\n\tputs\n}"}, {"source_code": "#!/usr/bin/ruby\n\nif __FILE__ == $0\n\n\tn = ARGV[0].to_i\n\tm = ARGV[1].to_i\n\n\tpebbles = Array.new(n)\n\tcolors = Array.new() { Array.new() }\n\tcount = Array.new(n) { Array.new(m, 0) }\n\n\tfor i in 2..(n + 1)\n\t\tpebbles[i - 2] = ARGV[i].to_i\n\t\tcolors << Array.new(pebbles[i - 2], 0)\n\tend\n\n\tfor i in 0..(n - 1)\n\t\tcolor = 0\n\t\tfor j in 0..(pebbles[i] - 1)\n\t\t\tcolors[i][j] = color\n\t\t\tcount[i][color] += 1\n\t\t\tcolor += 1\n\t\t\tif color >= m\n\t\t\t\tcolor = 0\n\t\t\tend\n\t\tend\n\t\tfor j in 0..(i - 1)\n\t\t\tfor k in 0..(m - 1)\n\t\t\t\tif (count[j][k] - count[i][k]).abs > 1\n\t\t\t\t\tputs \"NO\"\n\t\t\t\t\texit\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tputs \"YES\"\n\tcolors.each { |arr|\n\t\tarr.each { |el|\n\t\t\tprint \"#{el + 1} \"\n\t\t}\n\t\tputs\n\t}\n\nend"}], "src_uid": "e512285d15340343e34f596de2be82eb"} {"source_code": "ans = 0\ngets\ngets.split('').each_with_index{|x, i|\n ans += i + 1 if ['0', '2', '4', '6', '8'].include? x\n}\nputs ans\n", "positive_code": [{"source_code": "n = gets.to_i\ns = gets.chomp.chars.map(&:to_i)\nans = 0\n(0..n-1).each do |i|\n if s[i].even?\n ans += i + 1\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\ns = gets\nans = 0\nn.times do |i|\n if /[02468]/ =~ s[i]\n ans += i+1\n end\nend\nputs ans\n"}, {"source_code": "require 'enumerator'\ngets\ns = gets;\nputs s.enum_for(:scan, /[2468]/)\n .map { Regexp.last_match.begin(0) + 1 }\n .inject(0) {|r, p| r + p}"}], "negative_code": [], "src_uid": "43a65d1cfe59931991b6aefae1ecd10e"} {"source_code": "def solve\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n m = a.min\r\n puts a.count { |x| x > m }\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n solve\r\nend", "positive_code": [{"source_code": "def solve\n n = gets.to_i\n a = gets.split.map(&:to_i)\n m = a.min\n puts a.count { |x| x > m }\nend\n\nt = gets.to_i\nt.times do\n solve\nend"}, {"source_code": "t = gets.chomp.to_i\n\nt.times do \n n = gets.chomp.to_i\n arr = gets.chomp.split(\" \").map(&:to_i)\n arr.delete(arr.min)\n puts arr.size\nend\n"}, {"source_code": "def solution(n, arr)\r\n\taverage = arr.sum / n\r\n\r\n\tremoved = true\r\n\tresult = 0\r\n\r\n\twhile removed\r\n\t\ti = 0\r\n\t\tremoved = false\r\n\r\n\t\twhile i < n\r\n\t\t\tif arr[i] > average\r\n\t\t\t\tarr.delete_at(i)\r\n\t\t\t\tn -= 1\r\n\t\t\t\tresult += 1\r\n\t\t\t\tremoved = true\r\n\r\n\t\t\t\taverage = arr.sum / n\r\n\t\t\tend\r\n\r\n\t\t\ti += 1\r\n\t\tend\r\n\tend\r\n\r\n\tresult\r\nend\r\n\r\ntest_cases = gets.to_i\r\n\r\ntest_cases.times do\r\n n = gets.to_i\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n puts solution(n, arr)\r\nend\r\n"}, {"source_code": "t = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }.sort\n i = 0\n i += 1 while a[i] == a[0]\n printf(\"%d\\n\", a.size - i)\nend\n"}], "negative_code": [], "src_uid": "d5627b9fe5f6c5a7247e1f9d9e9b0c6a"} {"source_code": "n = gets.to_i\nstr = gets.chomp.chars\n\nif str == str.sort\n puts :NO\nelse\n (n - 1).times do |i|\n if str[i] > str[i + 1]\n right = i + 1\n left = i\n while str[left] <= str[right]\n left -= 1\n end\n puts :YES, [left + 1, right + 1].join(' ')\n break\n end\n end\nend\n\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\n\nstr = gets.chomp\n\nsmall = str[0]\ncurr = 0\nlow = -1\nhigh = -1\n\n(n-1).times.with_index do |x|\n\tif str[x+1] < small\n\t\tlow = curr+1\n\t\thigh = x+2\n\t\tbreak\n\telse \n\t\tcurr = x+1\n\t\tsmall = str[x+1]\n\tend\nend\nif low != -1\n\tputs \"YES\"\n\tputs \"#{low} #{high}\"\nelse\n\tputs \"NO\"\nend\n\t"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\n\nstr = gets.chomp\n\nsmall = str[0]\ncurr = 1\nlow = -1\nhigh = -1\n\n(n-1).times.with_index do |x|\n\tif str[x+1] < small\n\t\tlow = curr+1\n\t\thigh = x+2\n\t\tbreak\n\telse \n\t\tcurr = x+1\n\t\tsmall = str[x+1]\n\tend\nend\nif low != -1\n\tputs \"YES\"\n\tputs \"#{low} #{high}\"\nelse\n\tputs \"NO\"\nend\n\t"}, {"source_code": "n = gets.chomp.to_i\n\nstr = gets.chomp\n\nsmall = str[0]\ncurr = 1\nlow = -1\nhigh = -1\n\n(n-1).times.with_index do |x|\n\tif str[x+1] < small\n\t\tlow = curr+1\n\t\thigh = x+2\n\t\tbreak\n\telse \n\t\tcurr = x+1\n\t\tsmall = str[x+1]\n\tend\nend\nif low != \"-1\"\n\tp \"YES\"\n\tp \"#{low} #{high}\"\nelse\n\tp \"NO\"\nend\n\t"}], "src_uid": "d45f775613e701bbdaa4e457e6e189e2"} {"source_code": "t = gets\r\n\r\nt = t.to_i\r\n\r\n(1..t).each do |e|\r\n inp = gets\r\n inp = inp.split(' ').map(&:to_i)\r\n a = gets\r\n a = a.split(' ').map(&:to_i)\r\n a.sort!\r\n #puts \"{a: #{a}\" \r\n cur = 0\r\n res = 0\r\n a.each do |x|\r\n if (cur+x) <= inp[3]\r\n if x >= inp[1] && x <= inp[2] \r\n cur += x\r\n res += 1\r\n end\r\n else\r\n break\r\n end\r\n end\r\n \r\n puts res\r\nend\r\n ", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, l, r, k = gets.split.map(&:to_i)\r\n as = gets.split.map(&:to_i)\r\n p as.sort.select { |a| a >= l && a <= r }.take_while { |a| k -= a; k >= 0 }.size\r\nend"}], "negative_code": [], "src_uid": "f577695d39a11e8507681f307677c883"} {"source_code": "def solution\n s = gets.chop!\n chars = s.chars\n zeros = chars.count(\"0\")\n ones = chars.count(\"1\")\n\n return s if zeros == 0 || ones == 0\n\n i = 0\n while i < s.size\n if s[i] == s[i + 1]\n s.insert(i + 1, s[i] == '0' ? '1' : '0')\n end\n i += 1\n end\n\n s\nend\n\nt = gets.to_i\nt.times do\n print \"#{solution}\\n\"\nend\n", "positive_code": [{"source_code": "1.upto(gets.to_i) do\n s = gets.chomp\n \n same = s.chars.all? { |c| s[0] == c }\n\n while !same\n ll = s.length\n s.gsub!('00', '010')\n s.gsub!('11', '101')\n\n break if ll == s.length\n end\n\n puts s\nend\n"}, {"source_code": "gets.to_i.times {\n t=gets.chomp.chars\n if t.uniq.size==1\n s=t*''\n else\n s=t.shift\n t.each{|c|\n s+=(c==?0 ? ?1 : ?0) if s[-1]==c\n s+=c\n }\n end\n puts s\n}\n"}, {"source_code": "1.upto(gets.chomp.to_i) do\n t = gets.chomp\n at = t.split(//)\n if at.uniq.size == 1\n puts t\n else\n puts \"01\"*t.size\n end\nend\n"}, {"source_code": "tttt = gets.chomp.to_i\n\n# \u5468\u671f\u6027\ndef chkPeriod(str)\n\t(1..str.length/2).each do |i|\n\t\tngo = str.chars.each_slice(i).to_a\n\t\treturn i if ngo.uniq.length == 1\n\tend\n\treturn -1\nend\n\n#s\u304ct\u306e\u30b5\u30d6\u30b7\u30fc\u30b1\u30f3\u30b9\u304b\ndef chkSubsequence(s, t)\n\tsi = 0\n\tti = 0\n\twhile si < s.length || ti < t.length\n\t\treturn false if si >= s.length\n\t\treturn true if ti >= t.length\n\t\tif s[si] == t[ti] then\n\t\t\tti += 1\n\t\tend\n\t\tsi += 1\n\tend\nend\n\n\ntttt.times do \n\tt = gets.chomp\n\tif t.chars.uniq.length == 1 then\n\t\tputs t\n\t\tnext\n\tend\n\n\t# \u6b21\u306b\u3069\u306e\u6587\u5b57\u3092\u3076\u3061\u3053\u3080\u304b(true\u21921 false\u21920)\n\tstr = \"\"\n\ti = 0\n\twhile i < t.length\n\t\tif t[i+1] != t[i] && i < t.length - 1 then\n\t\t\tstr += t[i]\n\t\t\ti += 1\n\t\t\tnext\n\t\tend\n\t\tstr += t[i]\n\t\tstr += t[i] == \"0\" ? \"1\" : \"0\"\n\t\ti += 1\n\tend\n\t#puts str\n\tstr = str[0] != str[-1] ? str : str.slice(0,str.length - 1)\n\tputs str\nend\n\n"}], "negative_code": [{"source_code": "def solution\n s = gets.chop!\n chars = s.chars\n zeros = chars.count(\"0\")\n ones = chars.count(\"1\")\n\n return s if zeros == 0 || ones == 0\n\n (0..s.size).to_a.each do |i|\n if s[i] != s[i + 2] && s[i + 2]\n s.insert(i + 1, s[i] == '0' ? '1' : '0')\n end\n end\n\n s\nend\n\nt = gets.to_i\nt.times do\n print \"#{solution}\\n\"\nend\n"}, {"source_code": "def solution\n s = gets.chop!\n \"10\" * (s.size / 2)\nend\n\nt = gets.to_i\nt.times do\n print \"#{solution}\\n\"\nend\n"}, {"source_code": "def solution\n s = gets.chop!\n chars = s.chars\n zeros = chars.count(\"0\")\n ones = chars.count(\"1\")\n\n return s if zeros == 0 || ones == 0\n\n chars.size.times do |i|\n if s[i] == s[i + 1]\n s.insert(i + 1, s[i] == '0' ? '1' : '0')\n end\n end\n\n s\nend\n\nt = gets.to_i\nt.times do\n print \"#{solution}\\n\"\nend\n"}, {"source_code": "def solution\n s = gets.chop!\n chars = s.chars\n zeros = chars.count(\"0\")\n ones = chars.count(\"1\")\n\n return s if zeros == 0 || ones == 0\n\n chars.size.times do |i|\n next if i == 0\n if s[i] == s[i-1]\n s.insert(i, s[i] == '0' ? '1' : '0')\n end\n end\n\n s\nend\n\nt = gets.to_i\nt.times do\n print \"#{solution}\\n\"\nend\n"}, {"source_code": "def solution\n s = gets.chop!\n chars = s.chars\n zeros = chars.count(\"0\")\n ones = chars.count(\"1\")\n\n return s if zeros == 0 || ones == 0\n\n (0..chars.size).to_a.each do |i|\n if s[i] != s[i + 2] && s[i + 2]\n s.insert(i + 1, s[i] == '0' ? '1' : '0')\n end\n end\n\n s\nend\n\nt = gets.to_i\nt.times do\n print \"#{solution}\\n\"\nend\n"}], "src_uid": "679a1e455073d3ea3856aa16516ba8ba"} {"source_code": "x , k = gets.strip.split(' ').map(&:to_i);\nn = gets.chomp\nc = 0\nl = 0\nbest = 0\nfor i in 0 ... x\n if (n[i] != 'a')\n c+=1\n end\n while(c > k)\n if (n[l] == 'b')\n c-=1\n end\n l+=1\n end\n best = [best , i - l + 1].max\nend\nc = 0\nl = 0\nfor i in 0 ... x\n if (n[i] != 'b')\n c+=1\n end\n\n while(c > k)\n if (n[l] == 'a')\n c-=1\n end\n l+=1\n end\n best = [best , i - l + 1].max\nend\nputs best\n", "positive_code": [{"source_code": "N, K = gets.chomp.split.map &:to_i\n\nstr = gets.chomp\n\ndef calcu str, base_chr, k\n count = 0\n pos = 0\n ret = 0\n for i in 0...str.length\n while pos < str.length && count <= k\n if str[pos] == base_chr\n count += 1\n end\n pos += 1\n end\n len = pos - i\n if str[pos-1] == base_chr && count > k\n len -= 1\n end\n \n if ret < len\n ret = len\n end\n \n if str[i] == base_chr\n count -= 1\n end\n end\n \n ret\nend\n\nans = [(calcu str, \"a\", K), (calcu str, \"b\", K)].max\nputs ans"}], "negative_code": [{"source_code": "N, K = gets.chomp.split.map &:to_i\n\nstr = gets.chomp\n\ndef calcu str, base_chr, k\n count = 0\n pos = 0\n ret = 0\n for i in 0...str.length\n while pos < str.length && count <= k\n if str[pos] == base_chr\n count += 1\n end\n pos += 1\n end\n len = pos - i\n if str[pos-1] == base_chr && count > k\n len -= 1\n end\n \n if ret < len\n ret = len\n end\n \n if str[pos] == base_chr\n count -= 1\n end\n end\n \n ret\nend\n\nans = [(calcu str, \"a\", K), (calcu str, \"b\", K)].max\nputs ans"}, {"source_code": "N, K = gets.chomp.split.map &:to_i\n\nstr = gets.chomp\n\ndef calcu str, base_chr, k\n count = 0\n pos = 0\n ret = 0\n for i in 0...str.length\n while pos < str.length && count <= k\n if str[pos] == base_chr\n count += 1\n end\n pos += 1\n end\n len = pos - i\n if str[pos-1] == base_chr && count == k\n len -= 1\n end\n \n if ret < len\n ret = len\n end\n \n if str[pos] == base_chr\n count -= 1\n end\n end\n \n ret\nend\n\nans = [(calcu str, \"a\", K), (calcu str, \"b\", K)].max\nputs ans"}], "src_uid": "0151a87d0f82a9044a0ac8731d369bb9"} {"source_code": "gets.to_i.times do\r\n a, b = gets.split.map &:to_i\r\n if a == 0\r\n puts 0\r\n next\r\n end\r\n res, i = a + 3, b < 2 ? 2 - b : 0\r\n while i < res do\r\n ca, cur = a, i\r\n while ca > 0 do\r\n ca /= b + i\r\n cur += 1\r\n end\r\n res = [res, cur].min\r\n i += 1\r\n end\r\n puts res\r\nend", "positive_code": [{"source_code": "def method(a, b)\r\n if b == 1\r\n return 100\r\n end\r\n res = 0\r\n while a != 0\r\n a /= b\r\n res += 1\r\n end\r\n res\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n a, b = gets.split.map { |x| x.to_i }\r\n puts (0..30).map { |x| method(a, b + x) + x }.min\r\nend"}, {"source_code": "gets.to_i.times do\r\n a,b=gets.split.map(&:to_i)\r\n c=0\r\n if b==1\r\n b+=1\r\n c+=1\r\n end\r\n cmin=1/0.0\r\n cc=c\r\n bb=b\r\n aa=a\r\n while true\r\n a=aa\r\n b=bb\r\n c=cc\r\n while a>b\r\n a=a/b\r\n c+=1\r\n end\r\n c+=1 if a==b\r\n if c+1<=cmin\r\n cmin=c+1\r\n else\r\n puts cmin\r\n break\r\n end\r\n bb+=1\r\n cc+=1\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "2b757fa66ce89046fe18cdfdeafa6660"} {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n var = -Float::INFINITY\n cur = 0\n len = 0\n\n a.each do |v|\n if cur < 0\n len = 1\n cur = v\n else\n len += 1\n cur += v\n end\n\n if var < cur && len < n\n var = cur\n end\n end\n\n cur = 0\n len = 0\n\n a.reverse_each do |v|\n if cur < 0\n len = 1\n cur = v\n else\n len += 1\n cur += v\n end\n\n if var < cur && len < n\n var = cur\n end\n end\n\n sum = a.inject(:+)\n\n if var >= sum\n puts 'NO'\n else\n puts 'YES'\n end\nend\n", "positive_code": [{"source_code": "# frozen_string_literal: true\n\ndef one_test\n gets.to_i\n vec = gets.strip.split.map(&:to_i)\n# puts vec.to_s\n puts(test(vec) || test(vec.reverse) ? 'NO' : 'YES')\nend\n\ndef test(vector)\n vector = vector.clone\n vector.pop\n# puts vector.to_s\n sum = 0\n vector.each do |a|\n sum += a\n # puts sum.to_s + \" \" + a.to_s\n return true unless sum > 0\n end\n false\nend\n\nn = gets\nn.to_i.times { one_test }\n"}], "negative_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n var = -Float::INFINITY\n cur = 0\n len = 0\n max_len = 0\n\n a.each do |v|\n if cur < 0\n len = 1\n cur = v\n else\n len += 1\n cur += v\n end\n\n if var < cur\n max_len = len\n var = cur\n end\n end\n\n sum = a.inject(:+)\n\n if max_len < n && var >= sum\n puts 'NO'\n else\n puts 'YES'\n end\nend\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n var = -Float::INFINITY\n cur = 0\n len = 0\n\n a.each do |v|\n if cur < 0\n len = 1\n cur = v\n else\n len += 1\n cur += v\n end\n\n if var < cur && len < n\n var = cur\n end\n end\n\n sum = a.inject(:+)\n\n if var >= sum\n puts 'NO'\n else\n puts 'YES'\n end\nend\n"}, {"source_code": "# frozen_string_literal: true\n\ndef one_test\n gets.to_i\n vec = gets.strip.split.map(&:to_i)\n puts vec.to_s\n puts(test(vec) || test(vec.reverse) ? 'NO' : 'YES')\nend\n\ndef test(vector)\n vector = vector.clone\n vector.pop\n puts vector.to_s\n sum = 0\n vector.each do |a|\n sum += a\n if a <= 0\n return true\n end\n end\n false\nend\n\nn = gets\nn.to_i.times { one_test }\n"}, {"source_code": "# frozen_string_literal: true\n\ndef one_test\n gets.to_i\n vec = gets.strip.split.map(&:to_i)\n# puts vec.to_s\n puts(test(vec) || test(vec.reverse) ? 'NO' : 'YES')\nend\n\ndef test(vector)\n vector = vector.clone\n vector.pop\n# puts vector.to_s\n sum = 0\n vector.each do |a|\n sum += a\n if a <= 0\n return true\n end\n end\n false\nend\n\nn = gets\nn.to_i.times { one_test }\n"}], "src_uid": "6e5b4d43e64645cf26d5eac31437b1a9"} {"source_code": "zeros = ->n {\r\n count = 0\r\n while n % 10 == 0\r\n count += 1\r\n n /= 10\r\n end\r\n count\r\n}\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n o = 1\r\n o *= 2 while o * 2 < m && zeros[n * o * 2] > zeros[n * o]\r\n o *= 5 while o * 5 < m && zeros[n * o * 5] > zeros[n * o]\r\n o *= 10 while o * 10 < m && zeros[n * o * 10] > zeros[n * o]\r\n o *= m / o\r\n p n * o\r\nend", "positive_code": [{"source_code": "zeros = ->n { n.to_s.reverse.chars.take_while { |c| c == \"0\" }.size }\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n o = 1\r\n o *= 2 while o * 2 < m && zeros[n * o * 2] > zeros[n * o]\r\n o *= 5 while o * 5 < m && zeros[n * o * 5] > zeros[n * o]\r\n o *= 10 while o * 10 < m && zeros[n * o * 10] > zeros[n * o]\r\n o *= m / o\r\n p n * o\r\nend\r\n"}, {"source_code": "gets.to_i.times do\n n,m=gets.chomp.split(' ').map(&:to_i)\n factor=1\n t=n\n while t%10==0 do\n t/=10\n end\n while t%2==0 && factor*5 <= m do\n t/=2\n factor*=5\n end\n while t%5==0 && factor*2 <= m do\n t/=5\n factor *=2\n end\n while factor*10<=m\n factor*=10\n end\n puts n*(m-m%factor)\nend\n\n"}], "negative_code": [], "src_uid": "83af7209bb8a81cde303af5d207c2749"} {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n\n", "positive_code": [{"source_code": "s = gets.chomp\narr = s.split(\"@\")\nat_count = s.count(\"@\")\nans = \"\"\nif arr.length >= 2 && (arr[1..-2].all?{|e| e.length > 1} && arr[0].length > 0 && arr[-1].length > 0)\n\tans << arr[0] + \"@\"\n\tat_count -= 1 \n\tarr[1..-2].each do |a|\n\t\tans << \"#{a[0]},#{a[1..-1]}@\"\n\t\tat_count -= 1\n\tend\n\tif at_count != 0\n\t\tputs \"No solution\"\n\telse\n\t\tputs ans+arr[-1]\n\tend\nelse\n\tputs \"No solution\"\nend"}, {"source_code": "s = gets\nmas = s.chomp!.split(\"@\")\n\nif mas.size < 2 || s[s.length-1..s.length-1] == \"@\" || s[0..0] == \"@\" || mas[0].length == 0 || mas[mas.size-1].length == 0\n puts \"No solution\"\n exit\nend\n\nbuffer = mas[0]\nfor i in 1..mas.size-2\n if mas[i].length < 2\n puts \"No solution\"\n exit\n end\n\n buffer += \"@\"+mas[i][0..(mas[i].length/2)-1]+\",\"+mas[i][(mas[i].length/2)..mas[i].length]\nend\nbuffer += \"@\"+mas[mas.size-1]\n\nputs buffer"}, {"source_code": "emails = gets.chomp.split(\"@\",-1)\nif emails.size < 2 || emails[0].size == 0 || emails[emails.size - 1].size == 0 || (emails.size > 2 && \n emails[1..emails.size - 2].any? {|x| x.size < 2})\n puts \"No solution\"\nelse\n i = 0\n while i + 1 < emails.size\n if i == 0\n print \"#{emails[0]}\"\n else\n print \"#{emails[i][1..emails[i].size]}\"\n end\n if i + 2 < emails.size\n print \"@#{emails[i+1][0]}\"\n else\n print \"@#{emails[i+1]}\"\n end\n print(\"#{emails.size > 2 && i + 2 < emails.size ? \",\" : \"\"}\")\n i += 1\n end\nend\n"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n\n"}, {"source_code": "a = gets.chomp.split('@', -1)\nif a.size < 2 || [0, -1].any? { |i| a[i].empty? } || a[1..-2].any? { |x| x.size < 2 }\n puts 'No solution'\n exit\nend\n\nst = a[0]\na[1..-2].each { |x|\n print st + '@' + x[0] + ','\n st = x[1..-1]\n}\nputs st + '@' + a[-1]"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n \nend\n\nline = gets.chomp\n\nif line[0] == \"@\" || line[line.length-1] == \"@\"\n puts \"No solution\"\n exit 0\nend\n\ntokens = line.split(\"@\")\n\nif tokens.length == 1\n puts \"No solution\"\n exit 0\nend\n\n1.upto(tokens.length - 2) do |i|\n if tokens[i].length < 2\n puts \"No solution\"\n exit 0\n end\nend\n\ntokens[0] = \"-\" + tokens[0]\n0.upto(tokens.length - 3) do |i|\n print tokens[i].sub!(/^./, \"\"), \"@\", tokens[i+1][0], \",\"\nend\n\n\nputs \"#{tokens[tokens.length-2].sub!(/^./, \"\")}@#{tokens.last}\"\n"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n\n"}, {"source_code": "\ndef do_repl(s)\n\ts.gsub(/@[a-z]+@/) { |m|\n\t\tm.slice(0,2) + \",\" + m.slice(2, m.length-2)\t\n\t}\nend\n\ndef badpattern(s)\n\treturn true if s.slice(0,1) == \"@\" || s.slice(s.length-1,1) == \"@\" \n\treturn true if /@@/ =~ s \n\treturn true if /@[a-z]@/ =~ s \n\treturn true if not /@/ =~ s \n\treturn false\nend\n\ndef test\n\ts = gets.chomp\n\tif badpattern(s) \n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\n\ts = do_repl(s)\n\ts = do_repl(s)\n\tputs s\n\nend\n\ntest\n"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n\n"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\ns = gets.chomp\nt = s.split('@', -1)\nif t.size > 1 && !t[0].empty? && !t[-1].empty? && t[1..-2].each.map { |x| x.size > 1 }.all?\n result = []\n (t.size - 1).times do |i|\n result << t[i][-1] + '@' + t[i + 1][0..-2]\n end\n result[0] = t[0][0..-2] + result[0]\n result[-1] += t[-1][-1]\n puts result * ','\nelse\n puts \"No solution\"\nend\n"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n\n"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n\n"}, {"source_code": "emailString = gets.chomp.to_s\n\nresultString = String.new\nemailCandidate = String.new\nfinishCandidate = false;\n\nemailString.each_char {|letter|\n\n if emailCandidate.length == 0\n if letter == '@'\n resultString = 'No solution'\n break\n else\n emailCandidate += letter\n end\n else\n if letter == '@'\n if finishCandidate\n resultString = 'No solution'\n break\n else\n emailCandidate += letter\n finishCandidate = true;\n end\n else\n if finishCandidate\n emailCandidate += letter\n finishCandidate = false;\n\n if resultString.length == 0\n resultString += emailCandidate\n else\n resultString += ',' + emailCandidate\n end\n\n emailCandidate = ''\n else\n emailCandidate += letter\n end\n end\n end\n}\n\nif finishCandidate\n resultString = 'No solution'\nelse\n if resultString.length == 0\n resultString = 'No solution'\n else\n resultString += emailCandidate\n end\nend\n\nputs resultString"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};"}, {"source_code": "s = gets.strip\nunless s[0] != ?@ && s[-1] != ?@ && s.chars.include?(?@) && !s.chars.each_cons(2).map(&:join).include?(\"@@\")\n s = \"No solution\"\nelse\n s = s.split(?@)\n (1...s.size).each do |i|\n if i + 1 == s.size\n s[i - 1] << \"@#{s[i]}\"\n s.pop\n else\n break s = \"No solution\" if s[i].size == 1\n s[i - 1] << \"@#{s[i][0]}\"\n s[i] = s[i][1..-1]\n end\n end\nend\nputs [*s].join(?,)\n"}, {"source_code": "#$stdin = File.open \"input.txt\"\n\ndef nosol\n\tputs \"No solution\"\n\texit\nend\n\na = gets.gsub(\"\\n\", \"\").split(\"@\", -1)\nn = a.size\n\nnosol if a.size < 2 || a[0].empty? || a[-1].empty? \ns = a[0]\n(1..n - 2).each do |i|\n\tnosol if a[i].size < 2\n\ts += \"@\" + a[i].chr + \",\" + a[i][1...a[i].size]\nend\ns += \"@\" + a[-1]\nputs s"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n\n"}, {"source_code": "gets\nputs !/@/ || /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};"}], "negative_code": [{"source_code": "\ndef do_repl(s)\n\ts.gsub(/@[a-z]+@/) { |m|\n\t\tm.slice(0,2) + \",\" + m.slice(2, m.length-2)\t\n\t}\nend\n\ndef badpattern(s)\n\treturn true if s.slice(0,1) == \"@\" || s.slice(s.length-1,1) == \"@\" \n\treturn true if /@@/ =~ s \n\treturn true if /@[a-z]@/ =~ s \n\treturn true if not /@/ =~ s \n\treturn false\nend\n\ndef test\n\ts = gets\n\tif badpattern(s) \n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\n\ts = do_repl(s)\n\ts = do_repl(s)\n\tputs s\n\nend\n\ntest\n"}, {"source_code": "\ndef do_repl(s)\n\ts.gsub(/@[^@,]+@/) { |m|\n\t\tm.slice(0,2) + \",\" + m.slice(2, m.length-2)\t\n\t}\nend\n\ndef test\n\ts = gets\n\tif s.slice(0,1) == \"@\" || s.slice(s.length-1,1) == \"@\" \n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\n\tif /@[^@,]@/ =~ s \n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\n\tif not /@/ =~ s \n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\t\n\ts = do_repl(s)\n\ts = do_repl(s)\n\tputs s\n\nend\n\ntest\n"}, {"source_code": "def do_repl(s)\n\ts.gsub(/@[a-z]+@/) { |m|\n\t\tm.slice(0,2) + \",\" + m.slice(2, m.length-2)\t\n\t}\nend\n\ndef test\n\ts = gets\n\tif s.slice(0,1) == \"@\" || s.slice(s.length-1,1) == \"@\" \n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\n\tif /@[a-z]@/ =~ s\n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\t\n\ts = do_repl(s)\n\ts = do_repl(s)\n\tputs s\n\nend\n\ntest\n"}, {"source_code": "\ndef do_repl(s)\n\ts.gsub(/@[^@,]+@/) { |m|\n\t\tm.slice(0,2) + \",\" + m.slice(2, m.length-2)\t\n\t}\nend\n\ndef badpattern(s)\n\treturn true if s.slice(0,1) == \"@\" || s.slice(s.length-1,1) == \"@\" \n\treturn true if /@@/ =~ s \n\treturn true if /@[^@,]@/ =~ s \n\treturn true if not /@/ =~ s \n\treturn false\nend\n\ndef test\n\ts = gets\n\tif badpattern(s) \n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\n\ts = do_repl(s)\n\ts = do_repl(s)\n\tputs s\n\nend\n\ntest\n"}, {"source_code": "\ndef do_repl(s)\n\ts.gsub(/@[^@,]+@/) { |m|\n\t\tm.slice(0,2) + \",\" + m.slice(2, m.length-2)\t\n\t}\nend\n\ndef test\n\ts = gets\n\tif s.slice(0,1) == \"@\" || s.slice(s.length-1,1) == \"@\" \n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\n\tif /@[^@,]@/ =~ s\n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\t\n\ts = do_repl(s)\n\ts = do_repl(s)\n\tputs s\n\nend\n\ntest\n"}, {"source_code": "\ndef do_repl(s)\n\ts.gsub(/@[^@]+@/) { |m|\n\t\tm.slice(0,2) + \",\" + m.slice(2, m.length-2)\t\n\t}\nend\n\ndef test\n\ts = gets\n\tif s.slice(0,1) == \"@\" || s.slice(s.length-1,1) == \"@\" \n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\n\tif /@[^@]@/ =~ s\n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\t\n\ts = do_repl(s)\n\ts = do_repl(s)\n\tputs s\n\nend\n\ntest\n"}, {"source_code": "\ndef do_repl(s)\n\ts.gsub(/@[a-z\\x80-\\xFF]+@/) { |m|\n\t\tm.slice(0,2) + \",\" + m.slice(2, m.length-2)\t\n\t}\nend\n\ndef test\n\ts = gets\n\tif s.slice(0,1) == \"@\" || s.slice(s.length-1,1) == \"@\" \n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\n\tif /@[a-z\\x80-\\xFF]@/ =~ s\n\t\tputs \"No solution\"\n\t\treturn\n\tend\n\t\n\ts = do_repl(s)\n\ts = do_repl(s)\n\tputs s\n\nend\n\ntest\n"}, {"source_code": "gets\nputs /^@|@.?@|@$/ ? 'No solution' : $_.gsub(/@.(?=.*@)/){$&+','};\n"}, {"source_code": "#!/usr/bin/env ruby\n\nt = gets.chomp.split('@')\nif t.size > 1 && !t[0].empty? && !t[-1].empty? && t[1..-2].each.map { |x| x.size > 1 }.all?\n result = []\n (t.size - 1).times do |i|\n result << t[i][-1] + '@' + t[i + 1][0..-2]\n end\n result[0] = t[0][0..-2] + result[0]\n result[-1] += t[-1][-1]\n puts result * ','\nelse\n puts \"No solution\"\nend\n"}, {"source_code": "emailString = gets.chomp.to_s\n\nresultString = String.new\nemailCandidate = String.new\nfinishCandidate = false;\n\nemailString.each_char {|letter|\n\n if emailCandidate.length == 0\n if letter == '@'\n resultString = 'No solution'\n break\n else\n emailCandidate += letter\n end\n else\n if letter == '@'\n if finishCandidate\n resultString = 'No solution'\n break\n else\n emailCandidate += letter\n finishCandidate = true;\n end\n else\n if finishCandidate\n emailCandidate += letter\n finishCandidate = false;\n\n if resultString.length == 0\n resultString += emailCandidate\n else\n resultString += ',' + emailCandidate\n end\n\n emailCandidate = ''\n else\n emailCandidate += letter\n end\n end\n end\n}\n\nif finishCandidate\n resultString = 'No solution'\nelse\n resultString += emailCandidate\nend\n\nputs resultString"}, {"source_code": "s = gets.strip.split(?@)\n(1...s.size).each do |i|\n if i + 1 == s.size\n s[i - 1] << \"@#{s[i]}\"\n s.pop\n else\n break s = \"No solution\" if s[i].size == 1\n s[i - 1] << \"@#{s[i][0]}\"\n s[i] = s[i][1..-1]\n end\nend\n$><<[*s].join(?,)\n"}, {"source_code": "s = gets.strip\nunless s[0] != ?@ && s.chars.include?(?@)\n s = \"No solution\"\nelse\n s = s.split(?@)\n (1...s.size).each do |i|\n if i + 1 == s.size\n s[i - 1] << \"@#{s[i]}\"\n s.pop\n else\n break s = \"No solution\" if s[i].size == 1\n s[i - 1] << \"@#{s[i][0]}\"\n s[i] = s[i][1..-1]\n end\n end\nend\nputs [*s].join(?,)\n"}, {"source_code": "s = gets.strip\nunless s[0] != ?@ && s.chars.include?(?@) && !s.chars.each_cons(2).map(&:join).include?(\"@@\")\n s = \"No solution\"\nelse\n s = s.split(?@)\n (1...s.size).each do |i|\n if i + 1 == s.size\n s[i - 1] << \"@#{s[i]}\"\n s.pop\n else\n break s = \"No solution\" if s[i].size == 1\n s[i - 1] << \"@#{s[i][0]}\"\n s[i] = s[i][1..-1]\n end\n end\nend\nputs [*s].join(?,)\n"}, {"source_code": "s = gets.strip\nif s[0] == ?@\n s = \"No solution\"\nelse\n s = s.split(?@)\n (1...s.size).each do |i|\n if i + 1 == s.size\n s[i - 1] << \"@#{s[i]}\"\n s.pop\n else\n break s = \"No solution\" if s[i].size == 1\n s[i - 1] << \"@#{s[i][0]}\"\n s[i] = s[i][1..-1]\n end\n end\nend\n$><<[*s].join(?,)\n"}, {"source_code": "def nosol\n\tputs \"No solution\"\n\texit\nend\n\na = gets.split(\"@\")\nn = a.size\n\ns = a[0]\nnosol if s.empty? || a[-1].empty?\n(1..n - 2).each do |i|\n\tnosol if a[i].size < 2\n\ts += \"@\" + a[i].chr + \",\" + a[i][1...a.size]\nend\ns += \"@\" + a[-1]\nputs s"}, {"source_code": "a = gets.split(\"@\")\nn = a.size\n\ns = a[0]\n(1..n - 2).each do |i|\n\tif a[i].size < 2\n\t\tputs \"No solution\"\n\t\texit\n\tend\n\t\n\ts += \"@\" + a[i].chr + \",\" + a[i][1...a.size]\nend\ns += \"@\" + a[-1]\nputs s"}, {"source_code": "#$stdin = File.open \"input.txt\"\n\ndef nosol\n\tputs \"No solution\"\n\texit\nend\n\na = gets.gsub(\"\\n\", \"\").split(\"@\")\nn = a.size\n\nnosol if a.size < 2 || a[0].empty? || a[-1].empty? \ns = a[0]\n(1..n - 2).each do |i|\n\tnosol if a[i].size < 2\n\ts += \"@\" + a[i].chr + \",\" + a[i][1...a[i].size]\nend\ns += \"@\" + a[-1]\nputs s"}, {"source_code": "\ndef nosol\n puts \"No solution\"\n exit\nend\n\na = gets.gsub(\"\\n\", \"\").split(\"@\")\nn = a.size\n\nnosol if a.size < 2 || a[0].empty? || a[-1].empty? \ns = a[0]\n(1..n - 2).each do |i|\n nosol if a[i].size < 2\n s += \"@\" + a[i].chr + \",\" + a[i][1...a[i].size]\nend\ns += \"@\" + a[-1]\nputs s"}, {"source_code": "def nosol\n\tputs \"No solution\"\n\texit\nend\n\na = gets.split(\"@\")\nn = a.size\n\ns = a[0]\nnosol if s.empty? || a[-1].empty?\n(1..n - 2).each do |i|\n\tnosol if a[i].size < 2\n\ts += \"@\" + a[i].chr + \",\" + a[i][1...a.size]\nend\ns += \"@\" + a[-1]\nputs s"}, {"source_code": "def nosol\n puts \"No solution\"\n exit\nend\n\na = gets.split(\"@\")\nn = a.size\n\ns = a[0]\nnosol if s.empty? || a[-1].empty?\n(1..n - 2).each do |i|\n nosol if a[i].size < 2\n s += \"@\" + a[i].chr + \",\" + a[i][1...a[i].size]\nend\ns += \"@\" + a[-1]\nputs s"}, {"source_code": "arr = gets.chomp.split(\"@\")\nans = \"\"\nif arr.length >= 2 && (arr[1..-2].all?{|e| e.length > 1} && arr[0].length > 0 && arr[-1].length > 0)\n\tans << arr[0] + \"@\" \n\tarr[1..-2].each do |a|\n\t\tans << \"#{a[0]},#{a[1..-1]}@\"\n\tend\n\tputs ans+arr[-1]\nelse\n\tputs \"No solution\"\nend"}, {"source_code": "arr = gets.chomp.split(\"@\")\nans = \"\"\nif arr.length > 2 && (arr[1..-2].all?{|e| e.length > 1} && arr[0].length > 0 && arr[-1].length > 0)\n\tans << arr[0] + \"@\" \n\tarr[1..-2].each do |a|\n\t\tans << \"#{a[0]},#{a[1..-1]}@\"\n\tend\n\tputs ans+arr[-1]\nelse\n\tputs \"No solution\"\nend"}, {"source_code": "mas = gets.split(\"@\")\n\nif mas.size < 2 || mas[0].length == 0 || mas[mas.size-1].length == 0\n puts \"No solution\"\n exit\nend\n\nbuffer = mas[0]\nfor i in 1..mas.size-2\n if mas[i].length < 2\n puts \"No solution\"\n exit\n end\n\n buffer += \"@\"+mas[i][0..(mas[i].length/2)-1]+\",\"+mas[i][(mas[i].length/2)..mas[i].length]\nend\nbuffer += \"@\"+mas[mas.size-1]\n\nputs buffer"}, {"source_code": "mas = gets.chomp!.split(\"@\")\n\nif mas.size < 2 || mas[0].length == 0 || mas[mas.size-1].length == 0\n puts \"No solution\"\n exit\nend\n\nbuffer = mas[0]\nfor i in 1..mas.size-2\n if mas[i].length < 2\n puts \"No solution\"\n exit\n end\n\n buffer += \"@\"+mas[i][0..(mas[i].length/2)-1]+\",\"+mas[i][(mas[i].length/2)..mas[i].length]\nend\nbuffer += \"@\"+mas[mas.size-1]\n\nputs buffer"}, {"source_code": "mas = gets.chomp!.split(\"@\")\n\nif mas.size < 2 || mas[0].length == 0 || mas[mas.size-1].length == 0\n puts \"No solution\"\n exit\nend\n\nbuffer = mas[0]\nfor i in 1..mas.size-2\n if mas[i].length == 1\n puts \"No solution\"\n exit\n end\n\n buffer += \"@\"+mas[i][0..(mas[i].length/2)-1]+\",\"+mas[i][(mas[i].length/2)..mas[i].length]\nend\nbuffer += \"@\"+mas[mas.size-1]\n\nputs buffer"}, {"source_code": "s = gets\nmas = s.chomp!.split(\"@\")\n\nif mas.size < 2 || s[mas.length-1..mas.length-1] == \"@\" || s[0..0] == \"@\" || mas[0].length == 0 || mas[mas.size-1].length == 0\n puts \"No solution\"\n exit\nend\n\nbuffer = mas[0]\nfor i in 1..mas.size-2\n if mas[i].length < 2\n puts \"No solution\"\n exit\n end\n\n buffer += \"@\"+mas[i][0..(mas[i].length/2)-1]+\",\"+mas[i][(mas[i].length/2)..mas[i].length]\nend\nbuffer += \"@\"+mas[mas.size-1]\n\nputs buffer"}, {"source_code": "mas = gets.split(\"@\")\nputs mas.size\n\nif mas.size < 2 || mas[0].length == 0 || mas[mas.size-1].length == 0\n puts \"No solution\"\n exit\nend\n\nbuffer = mas[0]\nfor i in 1..mas.size-2\n if mas[i].length < 2\n puts \"No solution\"\n exit\n end\n\n buffer += \"@\"+mas[i][0..(mas[i].length/2)-1]+\",\"+mas[i][(mas[i].length/2)..mas[i].length]\nend\nbuffer += \"@\"+mas[mas.size-1]\n\nputs buffer"}, {"source_code": "emails = gets.chomp.split(\"@\")\nif emails.size < 2 || emails[0].size == 0 || emails[emails.size - 1].size == 0 || (emails.size > 2 && \n emails[1..emails.size - 2].any? {|x| x.size < 2})\n puts \"No solution\"\nelse\n i = 0\n while i + 1 < emails.size\n if i == 0\n print \"#{emails[0]}\"\n else\n print \"#{emails[i][1..emails[i].size]}\"\n end\n if i + 2 < emails.size\n print \"@#{emails[i+1][0]}\"\n else\n print \"@#{emails[i+1]}\"\n end\n print(\"#{emails.size > 2 && i + 2 < emails.size ? \",\" : \"\"}\")\n i += 1\n end\nend\n"}, {"source_code": "a = gets.chomp.split('@', -1)\nif a.size < 2 || [0, -1].any? { |i| a[i].empty? } || a[1..-2].any? { |x| x.size < 2 }\n puts 'No solution'\n exit\nend\n\nst = a[0]\na[1..-2].each { |x|\n puts st + '@' + x[0]\n st = x[1..-1]\n}\nputs st + '@' + a[-1]"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n \nend\n\nline = gets.chomp\n\nif line[0] == \"@\" || line[line.length-1] == \"@\"\n puts \"No solution\"\n exit 0\nend\n\ntokens = line.split(\"@\")\n\nif tokens.length == 1\n puts \"No solution\"\n exit 0\nend\n\n1.upto(tokens.length - 2) do |i|\n if tokens[i].length == 1\n puts \"No solution\"\n exit 0\n end\nend\n\ntokens[0] = \"-\" + tokens[0]\n0.upto(tokens.length - 3) do |i|\n print tokens[i].sub!(/^./, \"\"), \"@\", tokens[i+1][0], \",\"\nend\n\nputs \"#{tokens[tokens.length-2].sub!(/^./, \"\")}@#{tokens.last}\"\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n \nend\n\nline = gets.chomp\n\nif line[0] == \"@\" || line[line.length-1] == \"@\"\n puts \"No solution\"\n exit 0\nend\n\ntokens = line.split(\"@\")\n\n1.upto(tokens.length - 2) do |i|\n if tokens[i].length == 1\n puts \"No solution\"\n exit 0\n end\nend\n\nprint \"#{tokens[0]}@#{tokens[1][0]}\"\n1.upto(tokens.length - 2) do |i|\n 1.upto(tokens[i].length - 1) {|j| print tokens[i][j] }\n print \"@#{tokens[i+1][0]}\"\nend\n\nputs tokens.last.sub!(/^./, \"\")\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n \nend\n\nline = gets.chomp\n\nif line[0] == \"@\" || line[line.length-1] == \"@\"\n puts \"No solution\"\n exit 0\nend\n\ntokens = line.split(\"@\")\n\n1.upto(tokens.length - 2) do |i|\n if tokens[i].length == 1\n puts \"No solution\"\n exit 0\n end\nend\n\ntokens[0] = \"-\" + tokens[0]\n0.upto(tokens.length - 3) do |i|\n print tokens[i].sub!(/^./, \"\"), \"@\", tokens[i+1][0], \",\"\nend\n\nputs \"#{tokens[tokens.length-2].sub!(/^./, \"\")}@#{tokens.last}\"\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n \nend\n\nline = gets.chomp\n\nif line[0] == \"@\" || line[line.length-1] == \"@\"\n puts \"No solution\"\n exit 0\nend\n\ntokens = line.split(\"@\")\n\ntokens.each do |token| \n if token.length == 1\n puts \"No solution\"\n exit 0\n end\nend\n\nprint \"#{tokens[0]}@#{tokens[1][0]}\"\n1.upto(tokens.length - 2) do |i|\n 1.upto(tokens[i].length - 1) {|j| print tokens[i][j] }\n print \"@#{tokens[i+1][0]}\"\nend\n\nputs tokens.last.sub!(/^./, \"\")\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n \nend\n\nline = gets.chomp\n\nif line[0] == \"@\" || line[line.length-1] == \"@\"\n puts \"No solution\"\n exit 0\nend\n\nans = true\nprev = -1\ntemp = \"\"\n0.upto(line.length - 1) do |i|\n if line[i] == \"@\"\n if prev == -1\n prev = i\n else\n if i - prev < 3\n ans = false\n break\n end\n end\n end\n temp += \",\" if (prev != -1) and (i - prev == 2)\n temp += line[i]\nend\n\nif ans\n puts temp\nelse\n puts \"No solution\"\nend\n\n"}], "src_uid": "71b4674e91e0bc5521c416cfc570a090"} {"source_code": "gets.to_i.times do\r\n s = gets.chomp\r\n t = gets.chomp\r\n answer = if t == \"a\"\r\n 1\r\n elsif t.include?(\"a\")\r\n -1\r\n else\r\n 2 ** s.size\r\n end\r\n p answer\r\nend\r\n", "positive_code": [{"source_code": "\ngets.to_i.times do\n s = gets.strip.length\n t = gets.strip\n\n puts(\n if t == 'a'\n 1\n elsif t.include?('a')\n -1\n else\n 2 ** s\n end\n )\nend\n"}, {"source_code": "T = gets.to_i\nT.times do\n s = gets.chomp\n t = gets.chomp\n \n if t == \"a\"\n puts 1\n next\n end\n \n if t.include?(?a) and t.size >= 2\n puts -1\n next\n end\n \n puts 2**s.size\nend"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n s = gets.chomp\r\n t = gets.chomp\r\n answer = if t.chars.all? { |c| c == \"a\" }\r\n 1\r\n elsif t.include?(\"a\")\r\n -1\r\n else\r\n 2 ** s.size\r\n end\r\n p answer\r\nend\r\n"}], "src_uid": "d6ac9ca9cc5dfd9f43f5f65ce226349e"} {"source_code": "n, r = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).each_with_index.to_a\npos, ans = 0, 0\nwhile pos < n\n\tf = a[[0, pos - r + 1].max...pos + r].reverse_each.find { _1[0] == 1 }\n\tif f\n\t\tans += 1\n\t\tpos = f[1] + r\n\telse\n\t\tputs(-1) + exit\n\tend\nend\nputs ans\n", "positive_code": [{"source_code": "def result\n n, k = read_ints\n last_idx = n-1\n heaters = read_ints\n heater_idx = [*0...heaters.size].select{ |i| heaters[i] == 1 }\n\n return -1 if heater_idx.empty?\n\n lit = 0\n left = 0\n\n (heater_idx + [nil]).each_cons(2) do |idx, next_idx|\n\n # can't light back\n return -1 if idx - k + 1 > left\n\n # next one can light; skip\n next if next_idx && next_idx - k + 1 <= left\n\n # last one can't light to the end\n return -1 if !next_idx && idx + k - 1 < last_idx\n\n lit += 1\n left = idx + k\n\n break if left > last_idx\n end\n\n lit\nend\n\ndef solution\n puts result\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}], "negative_code": [{"source_code": "def result\n n, k = read_ints\n last_idx = n-1\n heaters = read_ints\n heater_idx = [*0...heaters.size].select{ |i| heaters[i] == 1 }\n\n return -1 if heater_idx.empty?\n\n lit = 0\n left = 0\n\n (heater_idx + [nil]).each_cons(2) do |idx, next_idx|\n\n # can't light back\n return -1 if idx - k + 1 > left\n\n # next one can light; skip\n next if next_idx && next_idx - k + 1 <= left\n\n # last one can't light to the end\n return -1 if !next_idx && idx + k - 1 < last_idx\n\n lit += 1\n left = idx + k\n end\n\n lit\nend\n\ndef solution\n puts result\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}], "src_uid": "001d8aca7c8421c3e54863f3fb706f0d"} {"source_code": "gets.to_i.times do\r\n\r\nn = gets.to_i\r\n@dep = Array.new(n) { k, *a = gets.split.map!(&:to_i); a }.unshift([])\r\n\r\n@cache = Array.new(n + 1)\r\n@visited = Array.new(n + 1, false)\r\n\r\n=begin\r\ndef cnt(k)\r\n @cache[k] ||= (\r\n raise if @visited[k]\r\n @visited[k] = true\r\n\r\n @dep[k].map do |l|\r\n c = cnt(l)\r\n k > l ? c : c.succ\r\n end.max || 1\r\n )\r\nend\r\n=end\r\n\r\n#=begin\r\ndef cnt(k)\r\n return @cache[k] if @cache[k]\r\n\r\n i, j, ret = k, nil, nil\r\n stack = []\r\n\r\n loop do\r\n break unless i\r\n\r\n if ret\r\n ret += 1 if i < @dep[i][j]\r\n j += 1\r\n raise StopIteration if @dep[i][j].nil?\r\n stack << [i, j]\r\n i, j, ret = @dep[i][j], nil, nil\r\n next\r\n end\r\n\r\n if @cache[i]\r\n ret = @cache[i]\r\n i, j = stack.pop\r\n next\r\n end\r\n\r\n raise if @visited[i]\r\n @visited[i] = true\r\n\r\n j = 0\r\n raise StopIteration if @dep[i][j].nil?\r\n stack << [i, j]\r\n i, j, ret = @dep[i][j], nil, nil\r\n rescue StopIteration\r\n max = @dep[i].map do |jj|\r\n c = @cache[jj]\r\n i < jj ? c.succ : c\r\n end.max || 1\r\n ret = @cache[i] = max\r\n i, j = stack.pop\r\n end\r\n\r\n @cache[k]\r\nend\r\n#=end\r\n\r\nbegin\r\n @dep.each_index { |k| cnt(k) }\r\n puts @cache.max\r\nrescue RuntimeError\r\n puts -1\r\nend\r\n\r\nend\r\n", "positive_code": [{"source_code": "# Priority Queue\r\n# Reference: https://github.com/python/cpython/blob/master/Lib/heapq.py\r\nclass PriorityQueue\r\n # By default, the priority queue returns the maximum element first.\r\n # If a block is given, the priority between the elements is determined with it.\r\n # For example, the following block is given, the priority queue returns the minimum element first.\r\n # `PriorityQueue.new { |x, y| x < y }`\r\n #\r\n # A heap is an array for which a[k] <= a[2*k+1] and a[k] <= a[2*k+2] for all k, counting elements from 0.\r\n def initialize(array = [], &comp)\r\n @heap = array\r\n @comp = comp || proc { |x, y| x > y }\r\n heapify\r\n end\r\n\r\n attr_reader :heap\r\n\r\n # Push new element to the heap.\r\n def push(item)\r\n shift_down(0, @heap.push(item).size - 1)\r\n end\r\n\r\n alias << push\r\n alias append push\r\n\r\n # Pop the element with the highest priority.\r\n def pop\r\n latest = @heap.pop\r\n return latest if empty?\r\n\r\n ret_item = heap[0]\r\n heap[0] = latest\r\n shift_up(0)\r\n ret_item\r\n end\r\n\r\n # Get the element with the highest priority.\r\n def get\r\n @heap[0]\r\n end\r\n\r\n alias top get\r\n\r\n # Returns true if the heap is empty.\r\n def empty?\r\n @heap.empty?\r\n end\r\n\r\n private\r\n\r\n def heapify\r\n (@heap.size / 2 - 1).downto(0) { |i| shift_up(i) }\r\n end\r\n\r\n def shift_up(pos)\r\n end_pos = @heap.size\r\n start_pos = pos\r\n new_item = @heap[pos]\r\n left_child_pos = 2 * pos + 1\r\n\r\n while left_child_pos < end_pos\r\n right_child_pos = left_child_pos + 1\r\n if right_child_pos < end_pos && @comp.call(@heap[right_child_pos], @heap[left_child_pos])\r\n left_child_pos = right_child_pos\r\n end\r\n # Move the higher priority child up.\r\n @heap[pos] = @heap[left_child_pos]\r\n pos = left_child_pos\r\n left_child_pos = 2 * pos + 1\r\n end\r\n @heap[pos] = new_item\r\n shift_down(start_pos, pos)\r\n end\r\n\r\n def shift_down(star_pos, pos)\r\n new_item = @heap[pos]\r\n while pos > star_pos\r\n parent_pos = (pos - 1) >> 1\r\n parent = @heap[parent_pos]\r\n break if @comp.call(parent, new_item)\r\n\r\n @heap[pos] = parent\r\n pos = parent_pos\r\n end\r\n @heap[pos] = new_item\r\n end\r\nend\r\n\r\nHeapQueue = PriorityQueue\r\n\r\ngets.to_i.times do\r\n n=gets.to_i\r\n k=[]\r\n l=[]\r\n n.times do\r\n l << []\r\n end\r\n t=[]\r\n n.times do |i|\r\n a=gets.split.map(&:to_i)\r\n k << a[0]\r\n if a[0]==0\r\n t << i\r\n end\r\n a[1..].each do |aa|\r\n l[aa-1] << i\r\n end\r\n end\r\n\r\n f=true\r\n ans=1\r\n e=t.size\r\n while epp\r\n pq.push(ll)\r\n e+=1\r\n else\r\n t << ll\r\n end\r\n end\r\n end\r\n end\r\n if e==n\r\n break\r\n end\r\n if t==[]\r\n f=false\r\n break\r\n end\r\n e+=t.size\r\n ans+=1\r\n end\r\n if f\r\n puts ans\r\n else\r\n puts \"-1\"\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n\r\nn = gets.to_i\r\n@dep = Array.new(n) { k, *a = gets.split.map!(&:to_i); a }.unshift([])\r\n\r\n@cache = Array.new(n + 1)\r\n@visited = Array.new(n + 1, false)\r\n\r\ndef cnt(k)\r\n @cache[k] ||= (\r\n raise if @visited[k]\r\n @visited[k] = true\r\n\r\n @dep[k].map do |l|\r\n c = cnt(l)\r\n k > l ? c : c.succ\r\n end.min || 1\r\n )\r\nend\r\n\r\nbegin\r\n @dep.each_index { |k| cnt(k) }\r\n puts @cache.max\r\nrescue RuntimeError\r\n puts -1\r\nend\r\n\r\nend\r\n"}], "src_uid": "af40a0de6d3c0ff7bcd2c1b077b05d6e"} {"source_code": "def check(x)\n\tfor i in 2..Math.sqrt(x) do\n\t\tif x % i == 0\n\t\t\treturn true\n\t\tend\n\tend\n\treturn false\nend\n\ngets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tsuma = a.sum\n\tif check(suma)\n\t\tpos = \"\"\n\t\tfor i in 1..n do\n\t\t\tpos += i.to_s + \" \"\n\t\tend\n\t\tputs n\n\t\tputs pos\n\telse\n\t\tpos = \"\"\n\t\tfor i in 0..n-1 do\n\t\t\tif(check(suma - a[i]))\n\t\t\t\tputs n-[i+1,1].min\n\t\t\t\tfor j in 1..n do\n\t\t\t\t\tif(i + 1 != j)\n\t\t\t\t\t\tpos += j.to_s + \" \"\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tputs pos\n\tend\nend", "positive_code": [{"source_code": "def check(n)\n (2..Math.sqrt(n).round).each do |i|\n return true if n % i == 0\n end\n false\nend\n\ngets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tsuma = a.sum\n\tif check(suma)\n\t\tpos = \"\"\n\t\tfor i in 1..n do\n\t\t\tpos += i.to_s + \" \"\n\t\tend\n\t\tputs n\n\t\tputs pos\n\telse\n\t\tpos = \"\"\n\t\tfor i in 0..n-1 do\n\t\t\tif(check(suma - a[i]))\n\t\t\t\tputs n-[i+1,1].min\n\t\t\t\tfor j in 1..n do\n\t\t\t\t\tif(i + 1 != j)\n\t\t\t\t\t\tpos += j.to_s + \" \"\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tputs pos\n\tend\nend"}], "negative_code": [{"source_code": "def check(x)\n\tfor i in 2..Math.sqrt(x) do\n\t\tif x % i == 0\n\t\t\treturn true\n\t\tend\n\tend\n\treturn false\nend\n\ngets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tcheck = Array.new(20001) {true}\n\tif check[a.sum]\n\t\tsavei = 0\n\t\tfor i in 0..n-1 do\n\t\t\tif !check[a.sum - a[i]]\n\t\t\t\tsavei = i\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tputs n-1\n\t\tpos = \"\"\n\t\tfor i in 0..n do\n\t\t\tif(i != savei)\n\t\t\t\tpos += (i+1).to_s + \" \"\n\t\t\tend\n\t\tend\n\t\tputs pos\n\telse\n\t\tputs n\n\t\tpos = \"\"\n\t\tfor i in 0..n do\n\t\t\tpos += (i+1).to_s + \" \"\n\t\tend\n\t\tputs pos\n\tend\nend"}, {"source_code": "def check(x)\n\tfor i in 2..Math.sqrt(x) do\n\t\tif x % i == 0\n\t\t\treturn true\n\t\tend\n\tend\n\treturn false\nend\n\ngets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tif check(a.sum)\n\t\tputs n\n\t\tpo = \"\"\n\t\tfor i in 1..n do\n\t\t\tpo += i.to_s + \" \"\n\t\tend\n\t\tputs po\n\telse\n\t\tputs n-1\n\t\tpo = \"\"\n\t\tfor i in 1..n-1 do\n\t\t\tpo += i.to_s + \" \"\n\t\tend\n\t\tputs po\n\tend\nend"}], "src_uid": "677972c7d86ce9fd0808105331f77fe0"} {"source_code": "n = gets.to_i\ns = gets.chomp.chars.map(&:to_i)\na = gets.split.map(&:to_i)\n\npos = (0...n).find { |i| s[i] < a[s[i] - 1] }\n\nif pos\n\t(pos...n).each do |i|\n\t\tbreak if s[i] > a[s[i] - 1]\n\t\ts[i] = a[s[i] - 1]\n\tend\nend\nputs s.join\n", "positive_code": [{"source_code": "N = gets.to_i\nA = gets.chomp\nF = gets.chomp.split\n\nf = {}\nF.each.with_index(1) do |v, i|\n f[i.to_s] = v\nend\n\nindexes = {}\n\nA.chars.each_with_index do |v, i|\n next if indexes[v]\n \n indexes[v] = i\nend\n\nindexes = Hash[indexes.sort_by { |k, v| v }]\n\nans = A\n\nindexes.each do |d, i|\n if f[d] > d\n list = A.chars\n temp = list.dup\n temp[i..-1].each.with_index(i) do |v, j|\n break if v > f[v]\n list[j] = f[v]\n end\n\n ans = list.join\n\n break\n end\nend\n\nputs ans\n"}], "negative_code": [{"source_code": "n = gets.to_i\ns = gets.chomp.chars.map(&:to_i)\na = gets.split.map(&:to_i)\naaa = (0...n).map { |i| s[i] <= a[s[i] - 1] }.chunk { _1 }.map { [_1, _2.size] }\n\nif aaa[0][0]\n\t(0...aaa[0][1]).each { |i| s[i] = a[s[i] - 1] }\nelsif aaa.size >= 2\n\t(aaa[0][1]...aaa[1][1]).each { |i| s[i] = a[s[i] - 1] }\nend\n\nputs s.join"}, {"source_code": "n = gets.to_i\ns = gets.chomp.chars.map(&:to_i)\na = gets.split.map(&:to_i)\n(0...n).each { |i| s[i] = [s[i], a[s[i] - 1]].max }\nputs s.join\n"}, {"source_code": "N = gets.to_i\nA = gets.to_i\nF = gets.split.map(&:to_i)\n\nans = A\n\n(1..9).each do |d|\n v = A.to_s.gsub(d.to_s, F[d - 1].to_s).to_i\n ans = v if ans < v\nend\n\nputs ans\n"}, {"source_code": "N = gets.to_i\nA = gets.to_i\nF = gets.split.map(&:to_i)\n\nindexes = {}\nA.to_s.each_char.with_index do |ch, i|\n next if indexes[ch]\n \n indexes[ch.to_i] = i\nend\n\nindexes = Hash[indexes.sort_by { |k, v| v }]\n\nans = A\n\nindexes.each do |d, i|\n if F[d - 1] > d\n ans = A.to_s.gsub(d.to_s, F[d - 1].to_s)\n break\n end\nend\n\nputs ans\n"}, {"source_code": "\n N = gets.to_i\nA = gets.to_i\nF = gets.split.map(&:to_i)\n\nindexes = {}\nA.to_s.chars.map(&:to_i).each_with_index do |v, i|\n next if indexes[v]\n \n indexes[v] = i\nend\n\nindexes = Hash[indexes.sort_by { |k, v| v }]\n\nans = A\n\nindexes.each do |d, i|\n if F[d - 1] > d\n list = A.to_s.chars.map(&:to_i)\n temp = list.dup\n temp[i..-1].each.with_index(i) do |v, j|\n break if v != d\n list[j] = F[d - 1]\n end\n\n ans = list.join.to_i\n\n break\n end\nend\n\nputs ans\n"}], "src_uid": "378a9ab7ad891d60f23645106d24f314"} {"source_code": "n = gets.to_i\na = gets.chomp.split.map(&:to_i)\np = nil\n(n - 1).times { |i|\n if a[i] > a[i + 1]\n if p\n puts -1\n exit\n else\n p = i\n end\n end\n}\nputs p ? a[-1] <= a[0] ? n - p - 1 : -1 : 0", "positive_code": [{"source_code": "n = gets.to_i\narr = gets.split(\" \").map &:to_i\n\npos = -1\nfor i in 1...n\n if arr[i - 1] > arr[i]\n pos = i\n break\n end\nend\n\nsorted = arr.sort\nchanged = arr[pos..n] + arr[0..pos-1]\n\nif sorted == arr\n puts 0\nelsif sorted == changed\n puts n - pos\nelse\n puts -1\nend\n"}, {"source_code": "n = gets.chomp.to_i\nseq = gets.chomp.split.map{|i| i.to_i}\n\nans = 0\n(1...n).each do |i|\n\tif seq[i] < seq[i - 1]\n\t\tans = i\n\tend\nend\n\n\nsort_seq = seq[(ans...n)] + seq[(0...ans)]\n\nif seq == seq.sort\n\tputs 0\nelsif sort_seq == seq.sort\n\tputs (n - ans)\nelse\n\tputs -1\nend\n"}, {"source_code": "\nmodule Enumerable\n def sorted?\n each_cons(2).all? { |a, b| (a <=> b) <= 0 }\n end\nend\n\nn = gets.to_i\ntab = gets.split.map(&:to_i)\npivot = 0\n(0...tab.size-1).each do |i|\n if tab[i] > tab[i+1]\n pivot = i+1\n break\n end\nend\n\nif (tab[0...pivot].sorted? || pivot == 0) &&\n tab[pivot..-1].sorted? &&\n (tab[-1] <= tab[0] || pivot == 0)\n puts (tab.size - pivot) % tab.size\nelse\n puts -1\nend\n\n\n\n"}, {"source_code": "length = gets.chomp.to_i\nsequence = gets.chomp.split(' ').map {|item| item.to_i}\n\ncount = 0\nfragmentedIdx = 0\n\n(0...length).each do |idx|\n\t#puts \"idx : #{idx}\"\n\t#puts \"sequence[idx % length] #{sequence[idx % length]}\"\n\t#puts \"sequence[(idx + 1) % length] #{sequence[(idx + 1) % length]}\"\n\tif sequence[idx % length] > sequence[(idx + 1) % length]\n\t\tcount += 1\n\t\tfragmentedIdx = idx + 1 if count == 1\n\tend\nend\n\nif count > 1\n\tputs \"-1\" \n\texit\nend\n\nif length - fragmentedIdx == length\n\tputs \"0\"\nelse\n\tputs length - fragmentedIdx\nend"}, {"source_code": "n = gets.to_i\nsequence = gets.split.map &:to_i\n\ndirection_reverse_location = []\n\nsequence.each_index do |i|\n direction_reverse_location << i if sequence[i] - sequence[i - 1] < 0\nend\n\nif direction_reverse_location.length == 0\n puts 0\nelsif direction_reverse_location.length > 1\n puts -1\nelse\n puts (sequence.length - direction_reverse_location.first) % sequence.length\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef decpt(arr)\n res = nil\n (1...arr.size).each do |i|\n if arr[i] < arr[i-1]\n return nil if res\n res = i-1\n end\n end\n res\nend\n\nn = gets.to_i\narr = gets.split.map(&:to_i)\nif arr.uniq.size == 1\n puts 0\nelse\n decpt = nil\n arr.size.times do |i|\n if arr[i] < arr[i-1]\n if decpt\n puts -1\n exit\n end\n decpt = i\n end\n end\n if decpt\n puts (arr.size - decpt) % arr.size\n else\n puts 0\n end\nend\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split.map(&:to_i)\ni=0\nwhile i=0 && a[j] <= a[j + 1] do\n j -= 1\n end\n\n if j == -1\n puts 0\n return\n end\n\n moves = i - j\n\n i = j\n j = i - 1\n while j >=0 && a[j] <= a[j + 1] do\n j -= 1\n end\n\n if j == -1 && a[n-1] <= a[0]\n puts moves\n else\n puts -1\n end\n end\n\nend\n\nB.new.run if __FILE__ == $0"}, {"source_code": "n = gets.to_i\nx = gets.split.map &:to_i\n\nls = x.last\ncnt = 0\npos = 0\nx.each_with_index do |now, i|\n if now < ls\n cnt += 1\n pos = i\n end\n ls = now\nend\nputs cnt >= 2 ? -1 : (n - pos) % n"}, {"source_code": "n=gets.to_i\nxs=gets.split.map{|e| e.to_i}\nc=0\nn.times{|i|\n\tc+=1 if xs[i]>xs[(i+1)%n]\n}\nif c<2 then\n\tmin1=xs.min\n\tmax1=xs.max\n\tif min1==max1 then\n\t\tputs 0\n\telse\n\t\tys=(0..(n-1)).map{|i|\n\t\t\t[xs[i],xs[(i+1)%n]]\n\t\t}\n\t\tputs (n-1)-ys.index([max1,min1])\n\tend\nelse\n\tputs -1\nend"}, {"source_code": "def f(n, a)\n bad_i = nil\n bad_c = 0\n n = a.size\n\n (n-1).times do |i|\n if a[i] > a[i+1]\n bad_c += 1\n bad_i = i\n end\n end\n\n case bad_c\n when 0; 0\n when 1; a[n-1] <= a[0] ? n - 1 - bad_i : -1\n else -1\n end\nend\n\nputs f(STDIN.gets.strip.to_i, STDIN.gets.strip.split.map(&:to_i))\n"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nprev = arr[0]\nind = nil\n\n(1..(n-1)).each do |i|\t\n\tif prev > arr[i]\n\t\tind = i\n\t\tbreak\n\tend\n\tprev = arr[i]\nend\nans = -1\n\nif ind\n\t# puts ind\n\tans = n - ind if arr[0..(ind-1)] == arr[0..(ind-1)].sort && arr[ind..(n-1)] == arr[ind..(n-1)].sort && arr[-1] <= arr[0]\nelse\n\tans = 0\nend\n\nputs ans"}, {"source_code": "n=STDIN.gets.to_i\na=gets.split.map{|x| x.to_i}\ni=1\nwhile (i v\n reverse_count += 1\n reverse_index = i\n end\n before = v\n}\n\nif reverse_count >= 2\n puts -1\nelse\n puts (n - reverse_index) % n\nend\n"}, {"source_code": "n=gets.to_i\narr=Array.new(n)\narr=gets.split.map(&:to_i)\n\nnewstartindex=0\nresult=0\n\nfor i in 0...n-1 do \n if (arr[i+1]=arr[n-1])\n puts (n-newstartindex)\n exit\nend\n\nputs -1\n"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\n\ndef sortable?(arr)\n i = arr.index(arr.min)\n\n prev = arr[i]\n (1...arr.size).each do |k|\n v = arr[(i+k) % arr.size]\n return false if v < prev\n prev = v\n end\n true\nend\n\nn = gets.to_i\narr = gets.split.map(&:to_i)\nunless sortable?(arr)\n puts -1\nelse\n idx = arr.index(arr.min)\n puts (arr.size - idx) % arr.size\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef sortable?(arr)\n i = arr.index(arr.min)\n\n prev = arr[i]\n (1...arr.size).each do |k|\n v = arr[(i+k) % arr.size]\n return false if v != prev+1\n prev = v\n end\n true\nend\n\nn = gets.to_i\narr = gets.split.map(&:to_i)\nunless sortable?(arr)\n puts -1\nelse\n idx = arr.index(arr.min)\n puts (arr.size - idx) % arr.size\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef sortable?(arr)\n i = arr.index(arr.min)\n\n prev = arr[i]\n (1...arr.size).each do |k|\n v = arr[(i+k) % arr.size]\n return false if v < k\n prev = v\n end\n true\nend\n\nn = gets.to_i\narr = gets.split.map(&:to_i)\nunless sortable?(arr)\n puts -1\nelse\n idx = arr.index(arr.min)\n puts (arr.size - idx) % arr.size\nend\n"}, {"source_code": "class B\n\n def run\n n = $stdin.gets.to_i\n a = $stdin.gets.split(' ').map &:to_i\n\n i = n - 1\n j = i - 1\n while j >=0 && a[j] <= a[i] do\n j -= 1\n end\n\n if j == -1\n puts 0\n return\n end\n\n moves = i - j\n\n i = j\n j = i - 1\n while j >=0 && a[j] <= a[i] do\n j -= 1\n end\n\n if j == -1 && a[n-1] <= a[0]\n puts moves\n else\n puts -1\n end\n end\n\nend\n\nB.new.run if __FILE__ == $0"}, {"source_code": "class B\n\n def run\n n = $stdin.gets.to_i\n a = $stdin.gets.split(' ').map &:to_i\n b = a + a\n\n ans = 2 * n\n start = 0\n while start < n\n i = start + 1\n while b[i] >= b[i-1]\n i += 1\n end\n ans = [ans, start].min if i - start >= n\n start = i\n end\n\n puts ans == 2 * n ? -1 : ans\n end\n\nend\n\nB.new.run if __FILE__ == $0"}, {"source_code": "n=gets.to_i\nxs=gets.split.map{|e| e.to_i}\nc=0\nn.times{|i|\n\tc+=1 if xs[i]>xs[(i+1)%n]\n}\nif c<2 then\n\tmin1=xs.min\n\tmax1=xs.max\n\tys=(0..(n-1)).map{|i|\n\t\t[xs[i],xs[(i+1)%n]]\n\t}\n\tputs (n-1)-ys.index([max1,min1])\nelse\n\tputs -1\nend"}, {"source_code": "n=gets.to_i\nxs=gets.split.map{|e| e.to_i}\nc=0\nn.times{|i|\n\tc+=1 if xs[i]>xs[(i+1)%n]\n}\nif c<2 then\n\tm=xs.max\n\tif m==xs[n-1] then\n\t\tputs 0\n\telse\n\t\tputs (n-1)-xs.rindex(m)\n\tend\nelse\n\tputs -1\nend"}, {"source_code": "n=gets.to_i\narr=Array.new(n)\narr=gets.split(&:to_i)\n\nnewstartindex=0\nresult=0\n\nfor i in 0...n-1 do \n if (arr[i+1]=arr[n-1]\n puts (n-newstartindex)\n exit\nend\n\nputs -1\n\n# if arr[n-1]>arr[0] && result==0 && n>2\n# puts 0;\n# exit\n# end\n\n# if arr[n-1]>arr[0] && n>2\n# result+=1\n# end\n\n\n# if result>1\n# puts -1\n# exit\n# end\n\n\n\n# puts (n-newstartindex)\n"}, {"source_code": "n=gets.to_i\narr=Array.new(n)\narr=gets.split(&:to_i)\n\nnewstartindex=0\nresult=0\n\nfor i in 0...n-1 do \n if (arr[i+1]arr[0] && result==0 && n>2\n puts 1;\n exit\nend\n\nif arr[n-1]>arr[0] && n>2\n result+=1 \nend\n\n\nif result>1\n puts -1\n exit\nend\n\nif result==0\n puts 0\n exit\nend\n\nputs (n-newstartindex)\n"}, {"source_code": "n=gets.to_i\narr=Array.new(n)\narr=gets.split(&:to_i)\n\nnewstartindex=0\nresult=0\n\nfor i in 0...n-1 do \n if (arr[i+1]arr[0] && result==0 && n>2\n puts 0;\n exit\nend\n\nif arr[n-1]>arr[0] && n>2\n result+=1\nend\n\n\nif result>1\n puts -1\n exit\nend\n\nif result==0\n puts 0\n exit\nend\n\nputs (n-newstartindex)\n"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map &:to_i\n\npos = -1\nfor i in 1...n\n if arr[i - 1] > arr[i]\n pos = i\n break\n end\nend\n\nsorted = arr.sort\nchanged = arr[pos..n] + arr[0..pos-1]\n\nif sorted == arr\n puts 0\nelsif sorted == changed\n puts pos\nelse\n puts -1\nend\n"}, {"source_code": "\nmodule Enumerable\n def sorted?\n each_cons(2).all? { |a, b| (a <=> b) <= 0 }\n end\nend\n\nn = gets.to_i\ntab = gets.split.map(&:to_i)\npivot = tab.index(tab.min)\n\nif (tab[0...pivot].sorted? || pivot == 0) &&\n tab[pivot..-1].sorted? &&\n (tab[-1] <= tab[0] || pivot == 0)\n puts (tab.size - pivot) % tab.size\nelse\n puts -1\nend\n\n\n\n"}, {"source_code": "\nn,tab=gets.to_i,gets.split.map(&:to_i)\npivot=tab.index(tab.min)\nif pivot == 0 && tab[0..-1].each_cons(2).all? {|a, b| (a <=> b) <= 0}\n puts 0\nelsif tab[0...pivot].each_cons(2).all? {|a, b| (a <=> b) <= 0} &&\n tab[pivot...-1].each_cons(2).all? {|a, b| (a <=> b) <= 0} &&\n tab[-1] <= tab[0]\n puts tab.size - pivot\nelse\n puts -1\nend\n\n\n\n"}, {"source_code": "\nn,tab=gets.to_i,gets.split.map(&:to_i)\npivot=tab.index(tab.min)\nif tab[0...pivot].each_cons(2).all? {|a, b| a <= b} &&\n tab[pivot..-1].each_cons(2).all? {|a, b| a <= b} &&\n (tab[-1] <= tab[0] || pivot == 0)\n puts (tab.size - pivot) % tab.size\nelse\n puts -1\nend\n\n\n\n"}, {"source_code": "\nn,tab=gets.to_i,gets.split.map(&:to_i)\npivot=tab.index(tab.min)\nif pivot == 0 && tab[0..-1].each_cons(2).all? {|a, b| (a <=> b) <= 0}\n puts 0\nelsif tab[0...pivot].each_cons(2).all? {|a, b| (a <=> b) <= 0} &&\n tab[pivot..-1].each_cons(2).all? {|a, b| (a <=> b) <= 0} &&\n tab[-1] <= tab[0]\n puts tab.size - pivot\nelse\n puts -1\nend\n\n\n\n"}, {"source_code": "\nn=gets.to_i\n(0...n).each {|x| puts '*' * ((n-1)/2 - x).abs + 'D' * (n - ((n-1) - 2*x).abs) + '*' * ((n-1)/2 - x).abs}\n\n"}, {"source_code": "\nn,tab=gets.to_i,gets.split.map(&:to_i)\npivot=tab.index(tab.min)\nif pivot == 0 && tab[0..-1].each_cons(2).all? {|a, b| a <= b}\n puts 0\nelsif tab[0...pivot].each_cons(2).all? {|a, b| a <= b} &&\n tab[pivot..-1].each_cons(2).all? {|a, b| a <= b} &&\n tab[-1] <= tab[0]\n puts tab.size - pivot\nelse\n puts -1\nend\n\n\n\n"}, {"source_code": "\nmodule Enumerable\n def sorted?\n each_cons(2).all? { |a, b| (a <=> b) <= 0 }\n end\nend\n\nn = gets.to_i\ntab = gets.split.map(&:to_i)\npivot = tab.index(tab.min)\n\nif tab[0...pivot].sorted? &&\n tab[pivot..-1].sorted? &&\n (tab[-1] <= tab[0] || pivot == 0)\n puts (tab.size - pivot) % tab.size\nelse\n puts -1\nend\n\n\n\n"}, {"source_code": "length = gets.chomp.to_i\nsequence = gets.chomp.split(' ').map {|item| item.to_i}\n#sorted = sequence.sort\n\ncount = 0\nfragmentedIdx = 0\n\nif (sequence.index(sequence.min) == 0 && sequence.rindex(sequence.max) - sequence.index(sequence.min) != length - 1)\n\tputs \"-1\"\n\texit\nend\n\n(0...(length - 1)).each do |idx|\n\tif sequence[idx] > sequence[idx + 1]\n\t\t#puts \"Join\"\n\t\tcount += 1\n\t\tfragmentedIdx = idx + 1\n\tend\nend\nif count > 1\n\tputs \"-1\" \n\texit\n\nend\n\nputs length - fragmentedIdx if sequence.index(sequence.min) != 0 \nputs \"0\" if sequence.index(sequence.min) == 0"}, {"source_code": "n = gets.chomp.to_i\nstart = (n / 2) + 1\ndNum = 0\n\n(0...n).each do |row|\n\tif row <= n / 2\n\t\tdNum = 2 * (row + 1) - 1\n\t\tstart -= 1\n\telse\n\t\tdNum = (-2 * row + (2 * n - 1))\n\t\tstart += 1 if row > n / 2\n\tend\n\n\t(0...n).each do |col|\n\t\tif col >= start && dNum > 0\n\t\t\tprint 'D'\n\t\t\tdNum -= 1\n\t\telse\n\t\t\tprint '*'\n\t\tend\n\tend\n\n\tputs ''\nend"}, {"source_code": "length = gets.chomp.to_i\nsequence = gets.chomp.split(' ').map {|item| item.to_i}\n#sorted = sequence.sort\n\n#puts \"max : #{sequence.rindex(sequence.max)}\"\n#puts \"min : #{sequence.index(sequence.min)}\"\nif (sequence.index(sequence.min) == 0 && sequence.rindex(sequence.max) - sequence.index(sequence.min) != length - 1) || (sequence.index(sequence.min) != 0 && sequence.index(sequence.min) - sequence.rindex(sequence.max) != 1)\n\tputs \"-1\"\n\texit\nend\n\nsequence.rindex(sequence.max).downto(1).each do |iterNum|\n\t#puts \"iterNum #{iterNum}\"\n\n\tif sequence[iterNum] < sequence[iterNum - 1]\n\t\tputs \"-1\"\n\t\texit\n\tend\nend\n\nanswer = if length - sequence.index(sequence.min) != length\n\tlength - sequence.index(sequence.min)\nelse\n\t0\nend\nputs answer"}, {"source_code": "length = gets.chomp.to_i\nsequence = gets.chomp.split(' ').map {|item| item.to_i}\n#sorted = sequence.sort\n\nif (sequence.index(sequence.min) == 0 && sequence.index(sequence.max) - sequence.index(sequence.min) != length - 1) && (sequence.index(sequence.min) - sequence.index(sequence.max) != 1)\n\tputs \"-1\"\n\texit\nend\n\nsequence.index(sequence.max).downto(1).each do |iterNum|\n\t#puts \"iterNum #{iterNum}\"\n\n\tif sequence[iterNum] < sequence[iterNum - 1]\n\t\tputs \"-1\"\n\t\texit\n\tend\nend\n\nanswer = if length - sequence.index(sequence.min) != length\n\tlength - sequence.index(sequence.min)\nelse\n\t0\nend\nputs answer"}, {"source_code": "length = gets.chomp.to_i\nsequence = gets.chomp.split(' ').map {|item| item.to_i}\n#sorted = sequence.sort\n\ncount = 0\nfragmentedIdx = 0\n\nif (sequence.index(sequence.min) == 0 && sequence.rindex(sequence.max) - sequence.index(sequence.min) != length - 1)\n\tputs \"-1\"\n\texit\nend\n\n(0...(length - 1)).each do |idx|\n\tif sequence[idx] > sequence[idx + 1]\n\t\t#puts \"Join\"\n\t\tcount += 1\n\t\tfragmentedIdx = idx + 1\n\tend\nend\nputs \"-1\" if count > 1\nputs length - fragmentedIdx if sequence.index(sequence.min) != 0\nputs \"0\""}, {"source_code": "length = gets.chomp.to_i\nsequence = gets.chomp.split(' ').map {|item| item.to_i}\n#sorted = sequence.sort\n\nif sequence[0] == 99997\nputs \"max : #{sequence.rindex(sequence.max)}\"\nputs \"min : #{sequence.index(sequence.min)}\"\nend\nif (sequence.index(sequence.min) == 0 && sequence.rindex(sequence.max) - sequence.index(sequence.min) != length - 1)\n\tputs \"-1\"\n\texit\nend\n\nif (sequence.index(sequence.min) != 0 && sequence.index(sequence.min) - sequence.rindex(sequence.max) != 1)\n\tputs \"-1\"\n\texit\nend\n\nsequence.rindex(sequence.max).downto(1).each do |iterNum|\n\t#puts \"iterNum #{iterNum}\"\n\n\tif sequence[iterNum] < sequence[iterNum - 1]\n\t\tputs \"-1\"\n\t\texit\n\tend\nend\n\nanswer = if length - sequence.index(sequence.min) != length\n\tlength - sequence.index(sequence.min)\nelse\n\t0\nend\nputs answer"}, {"source_code": "length = gets.chomp.to_i\nsequence = gets.chomp.split(' ').map {|item| item.to_i}\n#sorted = sequence.sort\n\ncount = 0\nfragmentedIdx = 0\n\nif (sequence.index(sequence.min) == 0 && sequence.rindex(sequence.max) - sequence.index(sequence.min) != length - 1)\n\tputs \"-1\"\n\texit\nend\n\n(0...(length - 1)).each do |idx|\n\tif sequence[idx] > sequence[idx + 1]\n\t\t#puts \"Join\"\n\t\tcount += 1\n\t\tfragmentedIdx = idx + 1\n\tend\nend\nputs \"-1\" if count > 1\nputs length - fragmentedIdx if sequence.index(sequence.min) != 0\nputs \"0\" if sequence.index(sequence.min) == 0"}, {"source_code": "length = gets.chomp.to_i\nsequence = gets.chomp.split(' ').map {|item| item.to_i}\n#sorted = sequence.sort\n\nif (sequence.index(sequence.min) == 0 && sequence.rindex(sequence.max) - sequence.index(sequence.min) != length - 1) && (sequence.index(sequence.min) - sequence.rindex(sequence.max) != 1)\n\tputs \"-1\"\n\texit\nend\n\nsequence.rindex(sequence.max).downto(1).each do |iterNum|\n\t#puts \"iterNum #{iterNum}\"\n\n\tif sequence[iterNum] < sequence[iterNum - 1]\n\t\tputs \"-1\"\n\t\texit\n\tend\nend\n\nanswer = if length - sequence.index(sequence.min) != length\n\tlength - sequence.index(sequence.min)\nelse\n\t0\nend\nputs answer"}], "src_uid": "c647e36495fb931ac72702a12c6bfe58"} {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\n\nh = Hash.new([])\n\nres = []\n\na.each_with_index do |i, j|\n h[i] += [j + 1]\n if h[i].length() == 2 then\n res << h[i]\n h = Hash.new([])\n end\nend\n\nif res.empty? then\n puts -1\nelse\n puts res.length()\n res.last[1] = n\n tmp = 1\n res.each do |r|\n puts [[r[0], tmp].min, r[1]].join(\" \")\n tmp = r[1] + 1\n end\nend", "positive_code": [{"source_code": "require 'scanf'\nEndMark = -1\nclass Table\n def initialize\n @occurList = {}\n @start = @goal = 1\n @answer = []\n end\n\n def readInput(n)\n if n == EndMark && !@answer.empty?\n @answer[-1][1]=@goal-1\n end\n\n if @occurList[n]\n @answer << [@start,@goal]\n nextPos = @goal+1\n @start = @goal = nextPos\n @occurList = {}\n else\n @occurList[n] = true\n @goal += 1\n end\n end\n\n def printAnswer\n if @answer.empty?\n puts -1\n else\n puts @answer.size\n @answer.each {|a| printPos *a }\n end\n end\n\n private\n def printPos a,b\n puts \"#{a} #{b}\"\n end\nend\n\nwhile str = gets\n tool = Table.new\n\n gets.split(' ').each do |x|\n tool.readInput x\n end\n\n tool.readInput(EndMark)\n\n tool.printAnswer\nend\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\n\nh = Hash.new([])\n\nres = []\n\na.each_with_index do |i, j|\n h[i] += [j + 1]\n if h[i].length() == 2 then\n res << h[i]\n h = Hash.new([])\n end\nend\n\nif res.empty? then\n puts -1\nelse\n puts res.length()\n tmp = res[0][1]\n res.each do |r|\n puts [[r[0], tmp].min, r[1]].join(\" \")\n tmp = r[1] + 1\n end\nend"}], "src_uid": "4cacec219e4577b255ddf6d39d308e10"} {"source_code": "T = gets.to_i\n\nT.times do\n n, m = gets.split.map(&:to_i)\n g = n.times.map { gets.split.map(&:to_i) }\n checked = Array.new(n) { Array.new(m, false) }\n ans = 0\n\n n.times do |y|\n m.times do |x|\n next if checked[y][x]\n checked[y][x] = true\n\n values = []\n values << g[y][x]\n\n y2 = y\n x2 = (m - 1) - x\n values << g[y2][x2] if !checked[y2][x2]\n checked[y2][x2] = true\n\n y3 = (n - 1) - y\n x3 = x\n values << g[y3][x3] if !checked[y3][x3]\n checked[y3][x3] = true\n\n y4 = (n - 1) - y\n x4 = (m - 1) - x\n values << g[y4][x4] if !checked[y4][x4]\n checked[y4][x4] = true\n\n ave = values.sort[values.size / 2]\n ans += values.map { |v| (v - ave).abs }.sum\n end\n end\n\n puts ans\nend\n", "positive_code": [{"source_code": "I=->{gets.split.map &:to_i}\nI[][0].times{n,m=I[]\nb=0\na=(1..n).map{I[]}\n(n/-2..-1).map{|i|(m/-2..-1).map{|j|l=[n+i,-i-1].product([m+j,-j-1]).uniq.map{|x,y|a[x][y]}.sort\nl.map{|x|b+=(l[l.size/2]-x).abs}}}\np b}\n"}, {"source_code": "I=->{gets.split.map &:to_i}\nI[][0].times{n,m=I[]\na=(1..n).map{I[]}\np [a,a.map(&:reverse)].map{|b|[b.reverse,b].map &:flatten}.flatten(1).transpose.map{|q|x,y,z,w=q.sort;w+z-x-y}.sum/4}"}], "negative_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n, m = gets.split.map(&:to_i)\n g = n.times.map { gets.split.map(&:to_i) }\n checked = Array.new(n) { Array.new(m, false) }\n ans = 0\n\n n.times do |y|\n m.times do |x|\n next if checked[y][x]\n checked[y][x] = true\n\n values = []\n values << g[y][x]\n\n y2 = y\n x2 = m - x - 1\n values << g[y2][x2] if !checked[y2][x2]\n checked[y2][x2] = true\n\n y3 = n - y - 1\n x3 = x\n values << g[y3][x3] if !checked[y3][x3]\n checked[y3][x3] = true\n\n y4 = n - y - 1\n x4 = m - x - 1\n values << g[y4][x4] if !checked[y4][x4]\n checked[y4][x4] = true\n\n ave = values.sum / values.size\n ans += values.map { |v| (v - ave).abs }.sum\n end\n end\n\n puts ans\nend\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n n, m = gets.split.map(&:to_i)\n g = n.times.map { gets.split.map(&:to_i) }\n checked = Array.new(n) { Array.new(m, false) }\n ans = 0\n\n n.times do |y|\n m.times do |x|\n next if checked[y][x]\n checked[y][x] = true\n\n values = []\n values << g[y][x]\n\n y2 = y\n x2 = m - x - 1\n values << g[y2][x2] if !checked[y2][x2]\n checked[y2][x2] = true\n\n y3 = n - y - 1\n x3 = x\n values << g[y3][x3] if !checked[y3][x3]\n checked[y3][x3] = true\n\n y4 = n - y - 1\n x4 = m - x - 1\n values << g[y4][x4] if !checked[y4][x4]\n checked[y4][x4] = true\n\n ave = values[values.size / 2]\n ans += values.map { |v| (v - ave).abs }.sum\n end\n end\n\n puts ans\nend\n"}], "src_uid": "5aa709f292f266799f177b174c8bc14b"} {"source_code": "n,m=gets.split.map(&:to_i)\nl,r=1,n\nm.times{\n\ts=gets.split\n\ti=s[4].to_i\n\tif s[2]==\"left\" then\n\t\tr=[r,i-1].min\n\telse\n\t\tl=[l,i+1].max\n\tend\n}\nputs r 0) ? result : -1\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nl,r=1,n\nm.times{\n\ts=gets.split\n\ti=s[4].to_i\n\tif s[2]==\"left\" then\n\t\tr=[r,i-1].min\n\telse\n\t\tl=[l,i+1].max\n\tend\n}\nputs r=l ? r-l+1 : -1\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nl,r=1,n\nm.times{\n\ts=gets.split\n\ti=s[4].to_i\n\tif s[2]==\"left\" then\n\t\tr=[r,i-1].min\n\telse\n\t\tl=[l,i+1].max\n\tend\n}\nputs r 0) ? result : -1\n"}, {"source_code": "n, m = $stdin.gets.split.map(&:to_i)\n\nmn = 1\nmx = n\nm.times do\n l = $stdin.gets\n idx = l.split[-1].to_i\n if l.match(/left/)\n mx = [idx-1, mx].min\n else\n mn = [idx+1, mn].max\n end\nend\n\np [mn, mx]\nresult = mx-mn+1\np (result > 0) ? result : -1\n"}], "src_uid": "dabeb9852332f6a6e730acab7fe61a5c"} {"source_code": "N = gets.to_i\nns = Array.new(N+1,0)\n(N-1).times {\n a,b = gets.split.map &:to_i\n ns[a] += 1\n ns[b] += 1\n}\nputs ns.count(2) == 0 ? \"YES\" : \"NO\"\n", "positive_code": [{"source_code": "n = gets.to_i\ndeg = [0]*(n)\n(n-1).times do\n u,v = gets.split.map(&:to_i)\n deg[u-1] += 1\n deg[v-1] += 1\nend\nputs deg.include?(2) ? \"NO\" : \"YES\""}], "negative_code": [{"source_code": "N = gets.to_i\nns = Array.new(N+1,0)\n(N-1).times {\n a,b = gets.split.map &:to_i\n ns[a] += 1\n ns[b] += 1\n}\nm = ns.count(1)\nputs m*(m-1)/2 >= N-1 ? \"YES\" : \"NO\"\n"}], "src_uid": "ba47e6eea45d32cba660eb6d66a9adbb"} {"source_code": "gets\na = gets.split\nl, r = a.count('0'), a.count('1')\nlo, ro = 0, 0\na.each_with_index do |x, i|\n if x == '0'\n lo += 1\n else\n ro += 1\n end\n if lo == l || ro == r\n puts i + 1\n exit\n end\nend\n", "positive_code": [{"source_code": "n = gets.to_i\nl = 0\nr = 0\nds = gets.split.map(&:to_i)\nlc = ds.count(0)\nrc = ds.count(1)\nds.each_with_index do |i, ii|\n if i == 0\n l += 1\n else\n r += 1\n end\n if l == lc || r == rc\n puts ii + 1\n exit\n end\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n(n-1).downto(1) do |i|\n if a[i] != a[i-1]\n puts i\n exit\n end\nend"}, {"source_code": "def read_tokens\n return gets.chomp.to_s.strip.split(' ')\nend\n\ndef read_ints\n data = []\n read_tokens.each { |s|\n data.push(s.to_i)\n }\n return data\nend\n\n\nn, = read_ints\ndoors = read_ints\n\ndef find_occ(arr, num)\n count = 0\n for el in arr\n if el == num\n count += 1\n end\n end\n return count\nend\n\ndef solve(doors)\n k = 0\n zeros = find_occ(doors, 0)\n ones = find_occ(doors, 1)\n for i in 0...doors.length\n if zeros == 0 or ones == 0\n return k\n end\n if doors[i] == 0\n zeros -= 1\n elsif doors[i] == 1\n ones -= 1\n end\n k += 1\n end\n return k\nend\n\nprint solve(doors)"}], "negative_code": [{"source_code": "n = gets.to_i\nl = 0\nr = 0\nans = 0\ngets.split.map(&:to_i).each_with_index do |i, ii|\n if i == 0\n l += 1\n else\n r += 1\n end\n if r > 0 && l > 0 && r != l\n puts ii + 1\n exit\n end\nend"}, {"source_code": "n = gets.to_i\nl = 0\nr = 0\nans = 0\ngets.split.map(&:to_i).each_with_index do |i, ii|\n if i == 0\n l += 1\n else\n r += 1\n end\n if r > 0 && l > 0\n puts ii + 1\n exit\n end\nend"}], "src_uid": "653455bb6762effbf7358d75660a7689"} {"source_code": "t=gets.to_i\na=gets.split(?:).map &:to_i\nif t==24\n a[0]%=10 if a[0]>23\nelse\n if a[0]==0\n a[0]=1\n elsif a[0]>12\n if a[0]%10==0\n a[0]=10\n else\n a[0]%=10\n end\n end\nend\na[1]%=10 if a[1]>59\nputs \"%02d:%02d\" % a\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\nn=gets.to_i\ns=gets\ns[3]=s[3]>'5'?'0':s[3]\nif n==12\n\tif s[0]=='0'\n\t\ts[0]='1' if s[1]=='0'\n\telsif s[0]=='1'\n\t\ts[1]='0' if s[1]>'2'\n\telse\n\t\ts[0]=s[1]=='0'?'1':'0'\n\tend\nelse\n\tif s[0]=='2'\n\t\ts[0]='0' if s[1]>'3'\n\telsif s[0]>'2'\n\t\ts[0]='0'\n\tend\nend\nputs s"}, {"source_code": "format = gets.to_i\nhour, minute = gets.strip.split(\":\").map(&:to_i)\nif format == 12 and hour == 0\n hour = 1\nelsif format == 12 and hour > 12\n hour %= 10\n hour = 10 if hour == 0\nelsif format == 24 and hour >= 24\n hour %= 10\nend\nif minute >= 60\n minute %= 10\nend\nputs \"%02d:%02d\" % [hour, minute]\n"}, {"source_code": "#! /usr/bin/env ruby\n\nform = gets.chomp\nt = gets.split(?:)\nh = t[0].to_i\nm = t[1].to_i\n#p form, h, m\n\nt[1][0] = '0' if m > 59\nif form == '24'\n t[0][0] = '0' if h > 23\nelse # form == 12\n if h == 0\n t[0] = '01'\n elsif h <= 12\n # do nothing\n else\n if t[0][1] == '0'\n t[0][0] = '1'\n else\n t[0][0] = '0'\n end\n end\nend\n\nputs t.join ?:\n"}, {"source_code": "type = gets.to_i\nh, m = gets.strip.split(\":\").map(&:to_i)\n\nif m > 59\n m = m % 10\nend\n\nif type == 12\n if h < 1 || h > 12\n if h % 10 == 0\n h = 10\n else\n h = h % 10\n end\n end\nelse\n if h > 23\n h = h % 10\n end\nend\n\nputs \"%02d:%02d\"%[h,m]"}, {"source_code": "t = gets.chomp.to_i\nhh, mm = gets.chomp.split(':').map(&:to_i)\n\nmm = mm % 10 if 59 < mm\nif t == 12\n hh = hh % 10 if 12 < hh\n hh = 10 if hh == 0\nelsif t == 24\n hh = hh % 10 if 23 < hh\nend\n\nputs '%02d:%02d' % [hh, mm]\n"}, {"source_code": "kind = gets.to_i\ntime = gets.chomp\nif time[3] >= '6'\n time[3] = '0'\nend\n\nposs = []\nif kind == 24\n poss = (0 .. 23).map{|v| format(\"%02d\", v)}\nelse\n poss = (1 .. 12).map{|v| format(\"%02d\", v)}\nend\n\nmi = 100\nmini = \"indigo\"\n\nfor p in poss\n s = time[0 .. 1]\n cnt = 0\n for i in 0 .. 1\n cnt += p[i] == s[i] ? 0 : 1\n end\n if mi > cnt\n mi = cnt\n mini = p\n end\nend\ntime[0] = mini[0]\ntime[1] = mini[1]\nputs time\n"}, {"source_code": "type = gets.chomp.to_i\ntime = gets.chomp.split(':').map(&:to_i)\n\ntime[1] %= 10 if time[1] / 10 > 5\n\nif type == 12\n if !((1..12) === time[0])\n if (0..2) === time[0] % 10\n time[0] = 10 + (time[0] % 10)\n else\n time[0] %= 10\n end\n end\nelse\n if !((0..23) === time[0])\n if (0..3) === time[0] % 10\n time[0] = 10 + (time[0] % 10)\n else\n time[0] %= 10\n end\n end\nend\n\nif time[0] / 10 == 0\n time[0] = \"0#{time[0]}\"\nend\n\nif time[1] / 10 == 0\n time[1] = \"0#{time[1]}\"\nend\n\nputs \"#{time[0]}:#{time[1]}\""}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nn=gets.to_i\ns=gets\ns[3]=s[3]>'5'?'0':s[3]\nif n==12\n\tif s[0]=='0'\n\t\ts[0]='1' if s[1]=='0'\n\telsif s[0]=='1'\n\t\ts[1]='0' if s[1]>'2'\n\telse\n\t\ts[0]=s[1]=='1'?'1':'0'\n\tend\nelse\n\tif s[0]=='2'\n\t\ts[0]='0' if s[1]>'3'\n\telsif s[0]>'2'\n\t\ts[0]='0'\n\tend\nend\nputs s"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\ns=gets\ns[3]=s[3]>'6'?'0':s[3]\nif n==12\n\tif s[0]=='0'\n\t\ts[0]='1' if s[1]=='0'\n\telsif s[0]=='1'\n\t\ts[1]='0' if s[1]>'2'\n\telse\n\t\ts[0]=s[1]=='1'?'0':'1'\n\tend\nelse\n\tif s[0]=='2'\n\t\ts[0]='0' if s[1]>'3'\n\telsif s[0]>'2'\n\t\ts[0]='0'\n\tend\nend\nputs s"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\ns=gets\ns[3]=s[3]>'6'?'0':s[3]\nif n==12\n\tif s[0]=='0'\n\t\ts[0]='1' if s[1]=='0'\n\telsif s[0]=='1'\n\t\ts[1]='0' if s[1]>'2'\n\telse\n\t\ts[0]=s[1]=='1'?'1':'0'\n\tend\nelse\n\tif s[0]=='2'\n\t\ts[0]='0' if s[1]>'3'\n\telsif s[0]>'2'\n\t\ts[0]='0'\n\tend\nend\nputs s"}, {"source_code": "t = gets.chomp.to_i\nhh, mm = gets.chomp.split(':').map(&:to_i)\n\nmm = mm % 10 if 59 < mm\nif t == 12\n hh = hh % 10 if 12 < hh\n hh = 10 if hh == 0\nelse\n hh = hh % 10 if 24 < hh\nend\n\nputs '%02d:%02d' % [hh, mm]\n"}, {"source_code": "t = gets.chomp.to_i\nhh, mm = gets.chomp.split(':').map(&:to_i)\n\nmm = mm % 10 if 59 < mm\nif (t == 12 && hh == 0) || (t == 24 && hh == 24)\n hh = 12\nelsif t < hh\n hh = hh % 10\nend\n\nputs \"#{sprintf('%02d', hh)}:#{sprintf('%02d', mm)}\"\n"}, {"source_code": "t = gets.chomp.to_i\nhh, mm = gets.chomp.split(':').map(&:to_i)\n\nmm = mm % 10 if 59 < mm\nif t == 12 && t == 0\n hh = 12\nelsif t < hh\n hh = hh % 10\nend\n\nputs \"#{sprintf('%02d', hh)}:#{sprintf('%02d', mm)}\"\n"}, {"source_code": "t = gets.chomp.to_i\nhh, mm = gets.chomp.split(':').map(&:to_i)\n\nmm = mm % 10 if 59 < mm\nif t == 12\n if hh == 0\n hh = 1\n elsif 12 < hh\n hh = hh % 10\n end\nelse \n if 24 < hh\n hh = hh % 10\n end\nend\n\nputs \"%02d:%02d\" % [hh, mm]\n"}], "src_uid": "88d56c1e3a7ffa94354ce0c70d8e958f"} {"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\nb = a.sort\nsum = a.inject{|x, y| x + y}\nif sum < k\n puts -1\nelsif sum == k\n puts\nelse\n i = 0\n s = 0\n while (b[i] - s) * (n - i) <= k\n k -= (b[i] - s) * (n - i)\n s = b[i]\n i += 1\n end\n while b[i] - s == 0\n i += 1\n end\n\n t = k / (n - i)\n k -= t * (n - i)\n\n j = 0\n while k > 0 \n if a[j] >= b[i]\n a[j] -= 1\n k -= 1\n end\n j += 1\n end\n\n for k in j...n\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n for k in 0...j\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n puts\nend", "positive_code": [{"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\nb = a.sort\nsum = a.inject{|x, y| x + y}\nif sum < k\n puts -1\nelsif sum == k\n puts\nelse\n i = 0\n s = 0\n while (b[i] - s) * (n - i) <= k\n k -= (b[i] - s) * (n - i)\n s = b[i]\n i += 1\n end\n while b[i] - s == 0\n i += 1\n end\n\n t = k / (n - i)\n k -= t * (n - i)\n\n j = 0\n while k > 0 \n if a[j] >= b[i]\n a[j] -= 1\n k -= 1\n end\n j += 1\n end\n\n for k in j...n\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n for k in 0...j\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n puts\nend\n\n"}, {"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\nb = a.sort\nsum = a.inject{|x, y| x + y}\nif sum < k\n puts -1\nelsif sum == k\n puts\nelse\n i = 0\n s = 0\n while (b[i] - s) * (n - i) <= k\n k -= (b[i] - s) * (n - i)\n s = b[i]\n i += 1\n end\n while b[i] - s == 0\n i += 1\n end\n\n t = k / (n - i)\n k -= t * (n - i)\n\n j = 0\n while k > 0 \n if a[j] >= b[i]\n a[j] -= 1\n k -= 1\n end\n j += 1\n end\n\n for k in j...n\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n for k in 0...j\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n puts\nend\n\n"}, {"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\nb = a.sort\nsum = a.inject{|x, y| x + y}\nif sum < k\n puts -1\nelsif sum == k\n puts\nelse\n i = 0\n s = 0\n while (b[i] - s) * (n - i) <= k\n k -= (b[i] - s) * (n - i)\n s = b[i]\n i += 1\n end\n while b[i] - s == 0\n i += 1\n end\n\n t = k / (n - i)\n k -= t * (n - i)\n\n j = 0\n while k > 0 \n if a[j] >= b[i]\n a[j] -= 1\n k -= 1\n end\n j += 1\n end\n\n for k in j...n\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n for k in 0...j\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n puts\nend\n"}, {"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\nb = a.sort\nsum = a.inject{|x, y| x + y}\nif sum < k\n puts -1\nelsif sum == k\n puts\nelse\n i = 0\n s = 0\n while (b[i] - s) * (n - i) <= k\n k -= (b[i] - s) * (n - i)\n s = b[i]\n i += 1\n end\n while b[i] - s == 0\n i += 1\n end\n\n t = k / (n - i)\n k -= t * (n - i)\n\n j = 0\n while k > 0 \n if a[j] >= b[i]\n a[j] -= 1\n k -= 1\n end\n j += 1\n end\n\n for k in j...n\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n for k in 0...j\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n puts\nend\n\n"}, {"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\nb = a.sort\nsum = a.inject{|x, y| x + y}\nif sum < k\n puts -1\nelsif sum == k\n puts\nelse\n i = 0\n s = 0\n while (b[i] - s) * (n - i) <= k\n k -= (b[i] - s) * (n - i)\n s = b[i]\n i += 1\n end\n while b[i] - s == 0\n i += 1\n end\n\n t = k / (n - i)\n k -= t * (n - i)\n\n j = 0\n while k > 0 \n if a[j] >= b[i]\n a[j] -= 1\n k -= 1\n end\n j += 1\n end\n\n for k in j...n\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n for k in 0...j\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n puts\nend\n\n"}, {"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\nb = a.sort\nsum = a.inject{|x, y| x + y}\nif sum < k\n puts -1\nelsif sum == k\n puts\nelse\n i = 0\n s = 0\n while (b[i] - s) * (n - i) <= k\n k -= (b[i] - s) * (n - i)\n s = b[i]\n i += 1\n end\n while b[i] - s == 0\n i += 1\n end\n\n t = k / (n - i)\n k -= t * (n - i)\n\n j = 0\n while k > 0 \n if a[j] >= b[i]\n a[j] -= 1\n k -= 1\n end\n j += 1\n end\n\n for k in j...n\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n for k in 0...j\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n puts\nend\n\n"}, {"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\nb = a.sort\nsum = a.inject{|x, y| x + y}\nif sum < k\n puts -1\nelsif sum == k\n puts\nelse\n i = 0\n s = 0\n while (b[i] - s) * (n - i) <= k\n k -= (b[i] - s) * (n - i)\n s = b[i]\n i += 1\n end\n while b[i] - s == 0\n i += 1\n end\n\n t = k / (n - i)\n k -= t * (n - i)\n\n j = 0\n while k > 0 \n if a[j] >= b[i]\n a[j] -= 1\n k -= 1\n end\n j += 1\n end\n\n for k in j...n\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n for k in 0...j\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n puts\nend\n"}, {"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\nb = a.sort\nsum = a.inject{|x, y| x + y}\nif sum < k\n puts -1\nelsif sum == k\n puts\nelse\n i = 0\n s = 0\n while (b[i] - s) * (n - i) <= k\n k -= (b[i] - s) * (n - i)\n s = b[i]\n i += 1\n end\n while b[i] - s == 0\n i += 1\n end\n\n t = k / (n - i)\n k -= t * (n - i)\n\n j = 0\n while k > 0 \n if a[j] >= b[i]\n a[j] -= 1\n k -= 1\n end\n j += 1\n end\n\n for k in j...n\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n for k in 0...j\n print((k + 1).to_s + \" \") if a[k] > t + s\n end\n puts\nend\n\n"}], "negative_code": [{"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\nb = a.sort\nif (a.length == 1 ? a[0] : a.inject{|x,y| x + y}) <= k\n puts -1\nelse\n i = 0\n s = 0\n while (b[i] - s) * (n - i) <= k\n k -= (b[i] - s) * (n - i)\n s = b[i]\n i += 1\n end\n while b[i] - s == 0\n i += 1\n end\n\n t = k / (n - i)\n k -= t * (n - i)\n\n j = 0\n while k > 0 \n if a[j] >= b[i]\n a[j] -= 1\n k -= 1\n end\n j += 1\n end\n\n ans = \"\"\n for k in j...n\n if a[k] > t + s\n ans += (k + 1).to_s + \" \"\n end\n end\n for k in 0...j\n if a[k] > t + s\n ans += (k + 1).to_s + \" \"\n end\n end\n puts ans.strip\nend\n"}, {"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\nb = a.sort\nif a.inject{|x,y| x + y} <= k\n puts -1\nelse\n i = 0\n s = 0\n while (b[i] - s) * (n - i) <= k\n k -= (b[i] - s) * (n - i)\n s = b[i]\n i += 1\n end\n while b[i] - s == 0\n i += 1\n end\n\n t = k / (n - i)\n k -= t * (n - i)\n\n j = 0\n while k > 0 \n if a[j] >= b[i]\n a[j] -= 1\n k -= 1\n else\n a[j] = 0\n end\n j += 1\n end\n\n ans = \"\"\n for k in j...n\n if a[k] > t + s\n ans += (k + 1).to_s + \" \"\n end\n end\n for k in 0...j\n if a[k] > t + s\n ans += (k + 1).to_s + \" \"\n end\n end\n puts ans.strip\nend\n"}], "src_uid": "8126f40439f2ea808683d22115421c18"} {"source_code": "DBG = true\nn = gets.to_i\nmx = 0\nmy = 0\nfor i in 0...n\n q,xx,yy = gets.split\n x = xx.to_i\n y = yy.to_i\n if x > y # make x<=y\n z = x\n x = y\n y = z\n end\n if q == '+'\n mx = x if x > mx\n my = y if y > my\n else\n puts ((x >= mx && y >= my) ? \"YES\" : \"NO\")\n end\nend\n", "positive_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nn = gets.to_i\n\nmaxone = 0\nmaxtwo = 0\nn.times do\n q = gets.chomp.split(\" \")\n if q[0]==\"+\"\n size = q[1..2].map(&:to_i).sort\n maxone = size[0] if size[0]>maxone\n maxtwo = size[1] if size[1]>maxtwo\n else\n size = q[1..2].map(&:to_i).sort\n if size[0]>=maxone and size[1]>=maxtwo\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\nend"}, {"source_code": "a, b = [0, 0]\ngets.strip.to_i.times do\n q, l, r = gets.strip.split(' ')\n if q == '?'\n x = [l, r].map(&:to_i).sort\n puts a <= x[0] && b <= x[1] ? \"YES\" : \"NO\"\n else\n x = [l, r].map(&:to_i).sort\n a = [a, x[0]].max\n b = [b , x[1]].max\n end\nend"}], "negative_code": [], "src_uid": "fe939f7503f928ff4dbe8d05c5643f38"} {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n cnt = [0,0,0]\n a.each do |v|\n cnt[v%3] += 1\n end\n k = (cnt[1]-cnt[2]).abs\n p cnt[0] + cnt[1,2].min + k/3\nend\n", "positive_code": [{"source_code": "def solve(a)\n a = a.group_by do |e|\n e % 3 == 0 ? 0 : (e + 1) % 3 == 0 ? 1 : 2\n end\n one, two = a[1] || [], a[2] || []\n # puts one.inspect\n # puts two.inspect\n # puts a[0].inspect\n mn = [one.size, two.size].min\n mx = [one.size, two.size].max\n # puts mn\n # puts mx\n (a[0] || []).size + mn + ((mx - mn) / 3.0).to_i\nend\n\ngets.strip.to_i.times do |t|\n n = gets.strip.to_i\n a = gets.strip.split(' ').map(&:to_i)\n puts solve(a)\nend"}], "negative_code": [], "src_uid": "e59cddb6c941b1d7556ee9c020701007"} {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n if a.each_cons(2).all? { |x, y| x > y }\n puts 'NO'\n else\n puts 'YES'\n end\nend\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\n\ndef solution(t)\n sorted, inversion_count = sort_inversion_count(t)\n return inversion_count\nend\n\ndef sort_inversion_count(t)\n midpoint = t.length / 2\n left_half = t[0...midpoint]\n right_half = t[midpoint..t.length]\n\n if midpoint == 0\n return t, 0\n end\n\n sorted_left_half, left_half_inversion_count = sort_inversion_count(left_half)\n sorted_right_half, right_half_inversion_count = sort_inversion_count(right_half)\n\n sorted = []\n inversion_count = 0\n while sorted_left_half.length > 0 or sorted_right_half.length > 0\n if sorted_left_half.empty?\n sorted.push sorted_right_half.shift\n elsif sorted_right_half.empty?\n sorted.push sorted_left_half.shift\n else\n if sorted_left_half[0] > sorted_right_half[0]\n inversion_count += sorted_left_half.length\n sorted.push sorted_right_half.shift\n else\n sorted.push sorted_left_half.shift\n end\n end\n end\n\n return sorted, inversion_count + left_half_inversion_count + right_half_inversion_count\nend\n\nwhile t>0 do\n n = gets.chomp.to_i\n arr = gets.chomp.split(\" \").map(&:to_i)\n threshold = (n*(n-1)/2) - 1\n\n inversions = solution(arr)\n res = inversions > threshold ? \"NO\" : \"YES\"\n\n puts res\n\n t -= 1\nend"}], "negative_code": [], "src_uid": "b34f29e6fb586c22fa1b9e559c5a6c50"} {"source_code": "n=gets.to_i\nb=gets.split.map(&:to_i).sort!\na=0\nM=10**9+7\np=[1]\nn.times{p[p.size]=p[p.size-1]*2%M}\n(n-1).times{|i|a+=(p[n]-p[n-i-1]-p[i+1]+1+M)*(b[i+1]-b[i])}\np a%M\n", "positive_code": [{"source_code": "n=gets.to_i-1\nb=gets.split.map(&:to_i).sort!\na=0\nM=10**9+7\np=[1]\nn.times{p[p.size]=p[p.size-1]*2%M}\nn.times{|i|a+=(p[i+1]-1)*(p[n-i]-1)*(b[i+1]-b[i])}\np a%M\n"}], "negative_code": [{"source_code": "n=gets.to_i-1\nb=gets.split.map(&:to_i).sort!\na=0\nM=10**9+7\np=[1]\nn.times{p[p.size]=p[p.size-1]*2%M}\nn.times{|i|a+=(p[i+1]-1)*(p[-i]-1)*(b[i+1]-b[i])}\np a%M\n"}], "src_uid": "acff03fe274e819a74b5e9350a859471"} {"source_code": "\nn,m = gets.chomp.split.map{|x| x.to_i}\n\ncandidate_wins = Array.new(n+1){0}\n#cities\n(0...m).each do |i|\n\tarr = gets.chomp.split.map{|x| x.to_i}\n\tcurr_winner = 0\n\tcurr_max_votes = -1\n\t(0...n).each do |j|\n\t\tif arr[j] > curr_max_votes\n\t\t\tcurr_max_votes = arr[j]\n\t\t\tcurr_winner = j\n\t\tend\n\tend\n\tcandidate_wins[curr_winner+1]+=1\nend\noverall_winner = 0\nover_all_win = -1\n(1..n).each do |i|\n\tif candidate_wins[i] > over_all_win\n\t\toverall_winner = i\n\t\tover_all_win = candidate_wins[i]\n\tend\nend\n\nputs overall_winner\n", "positive_code": [{"source_code": "n,m = gets.split.map(&:to_i)\na = Array.new(n,0)\nx,y = -1,0\nm.times do |j|\n\tt = gets.split.map(&:to_i)\n\tfor i in 0...n\n\t\tif t[i] > x\n\t\t\tx = t[i]\n\t\t\ty = i\n\t\tend\n\tend\t\n\ta[y] += 1\n\tx,y = -1,0\nend\nfor i in 0...n\n\tif a[i] > x\n\t\tx = a[i]\n\t\ty = i\n\tend\nend\np y+1"}, {"source_code": "n, m = gets.chomp.split(\"\\s\").map(&:to_i)\na = m.times.map { gets.chomp.split(\"\\s\").map(&:to_i) }\n\nwinners = a.map do |votes_by_city|\n votes_by_city.find_index(votes_by_city.max)\nend\n\nputs winners.sort.max_by { |e| winners.count(e) } + 1\n"}, {"source_code": "n,m=gets.split.map &:to_i;c=[0]*n;m.times{l=gets.split.map &:to_i;c[l.index(l.max)]+=1};p c.index(c.max)+1"}, {"source_code": "# coding: utf-8\n\nn, m = gets.split.map(&:to_i) # n candidates, m cities\nvotes = []\nm.times {\n votes << gets.split.map(&:to_i)\n}\n\nvt = Array.new(n) { 0 }\nmax_votes = 0\nvotes.each { |row|\n max, maxs = 0, []\n row.each_with_index { |i, index|\n if i < max\n #pass\n elsif i == max\n maxs << index\n else\n maxs.clear\n max = i\n maxs << index\n end\n }\n vt[maxs.first] += 1\n if max_votes < vt[maxs.first]\n max_votes = vt[maxs.first]\n end\n}\nfor index in 0...n\n if max_votes == vt[index]\n puts (index + 1) # 1-based index\n break\n end\nend"}, {"source_code": "n,m=gets.split.map &:to_i;c=[0]*n;m.times{l=gets.split.map &:to_i;c[l.index(l.max)]+=1};p c.index(c.max)+1\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\nvotes_in_cities = Array.new(n, 0)\nm.times do\n tmp = gets.split(' ').map(&:to_i)\n vinner_in_city = tmp.index(tmp.max)\n votes_in_cities[vinner_in_city] += 1\nend\n\nputs votes_in_cities.index(votes_in_cities.max) + 1\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = m.times.map{gets.split.map(&:to_i)}\nb = a.map{|x| x.index(x.max)}.sort\nputs b.group_by{|x| x}.to_a.max_by{|x| x[1].length}[0] + 1\n"}, {"source_code": "n,m=gets.split.map &:to_i;c=[0]*n;m.times{l=gets.split.map &:to_i;c[l.index(l.max)]+=1};p c.index(c.max)+1"}, {"source_code": "n, m = gets.split.map{|x| x.to_i}\nc = [0]*n\nm.times do\n a = gets.split.map{|x| x.to_i}\n c[a.find_index(a.max)] += 1\nend\nputs(c.find_index(c.max) + 1)\n"}, {"source_code": "n,m=gets.split.map &:to_i;c=[0]*n;m.times{l=gets.split.map &:to_i;c[l.index(l.max)]+=1};p c.index(c.max)+1\n"}, {"source_code": "n,m=gets.split.map &:to_i;c=[0]*n;m.times{l=gets.split.map &:to_i;c[l.index(l.max)]+=1};p c.index(c.max)+1\n"}, {"source_code": "n,m=gets.split.map &:to_i;c=[0]*n;m.times{l=gets.split.map &:to_i;c[l.index(l.max)]+=1};p c.index(c.max)+1\n"}, {"source_code": "n, m = gets.chomp.split(' ').map { |i| i.to_i }\nselected = []\ncount = Array.new(if n > m then n else m end) { |i| i = 0 }\n\nm.times do\n\tcandidates = gets.chomp.split(' ').map { |i| i.to_i }\n\t# find Max, put in array\n\tselected << candidates.index(candidates.max)\nend\n\nselected.each do |v|\n\tcount[v] = selected.count(v)\nend\n\nputs count.index(count.max) + 1"}, {"source_code": "#!/usr/bin/ruby\nN,M=gets.to_i\nA=$<.map{|e|e.split.map(&:to_i)}\nh=Hash.new(0)\nA.each{|e|h[e.each_with_index.map{|x,i|[-x,i]}.min[1]]+=1}\np h.min_by{|k,v|[-v,k]}[0]+1"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\ncand = [0]*n\nfor i in (1..m)\n li = gets.split(\" \").map(&:to_i)\n cand[li.index(li.max)]+=1\nend\nputs cand.index(cand.max) + 1"}, {"source_code": "n,m=gets.split.map &:to_i;c=[0]*n;m.times{l=gets.split.map &:to_i;c[l.index(l.max)]+=1};p c.index(c.max)+1\n"}, {"source_code": "# http://codeforces.com/contest/570/problem/A\nn, m = gets.chomp.split.map(&:to_i)\narray = Array.new(n) { 0 }\n\nm.times do\n votes = gets.chomp.split.map(&:to_i)\n max = votes.max\n\n array[votes.index(max)] += 1\nend\n\nmax = array.max\nputs array.index(max) + 1\n"}, {"source_code": "n,m=gets.split.map &:to_i;c=[0]*n;m.times{l=gets.split.map &:to_i;c[l.index(l.max)]+=1};p c.index(c.max)+1\n"}, {"source_code": "n, m = gets.split(' ').map{|x| x.to_i}\nres = []\nm.times do |x|\n\tres[x] = gets.split.map{|x| x.to_i}\n\tres[x] = res[x].index(res[x].max)\n\t\nend\n\ncount = []\nfor i in 0...n\n\tcount[i] = res.count(i)\nend\n\nputs count.index(count.max)+1\n"}, {"source_code": "n,m=gets.split.map &:to_i;c=[0]*n;m.times{l=gets.split.map &:to_i;c[l.index(l.max)]+=1};p c.index(c.max)+1\n"}, {"source_code": "n, m = gets.split(\" \").map(&:to_i)\na = Array.new(n){0}\nm.times{\n voices = gets.split(\" \")\n best = 0\n voices.each_index { |i| best = voices[i].to_i>voices[best].to_i ? i : best}\n a[best] += 1\n}\nbest = 0\na.each_index { |i| best = a[i]>a[best] ? i : best}\nputs best+1"}, {"source_code": "n,m=gets.split.map &:to_i;c=[0]*n;m.times{l=gets.split.map &:to_i;c[l.index(l.max)]+=1};p c.index(c.max)+1\n"}, {"source_code": "c=(0..100).map{0}\nn,m=gets.split.map{|e| e.to_i}\nm.times{\n\tx=gets.split.map{|e| e.to_i}\n\tc[x.index(x.max)+1]+=1\n}\np c.index(c.max)\n\n"}, {"source_code": "def read_ints; gets.chomp.split.map(&:to_i) end\nn,m = read_ints\ncity_winners = []\nm.times do \n\tcity_winners< curr_max_votes\n\t\t\tcurr_max_votes = arr[j]\n\t\t\tcurr_winner = j\n\t\tend\n\tend\n\tcandidate_wins[curr_winner+1]+=1\nend\noverall_winner = -1\nover_all_win = 0\n(1..n).each do |i|\n\tif candidate_wins[i] > over_all_win\n\t\toverall_winner = i\n\t\tover_all_win = candidate_wins[i]\n\tend\nend\n\nputs overall_winner\n"}, {"source_code": "def read_ints; gets.chomp.split.map(&:to_i) end\nn,m = read_ints\ncity_winners = []\nm.times do \n\tcity_winners<= 1 && number.to_i <= 1000)\n\tall_logins_passed = true\n\n\tnumber.to_i.times do\n\t\tif all_logins_passed\n\t\t\tlogins << gets.chomp\n\t\tend\n\tend\n\n\tlogins.each do |curent_login|\n\t\tall_logins_passed = false if curent_login.length > 50\n\tend\n\n\tif all_logins_passed\n\t\tuser_can_register = true\n\n\t\tlogins.each do |existed_login|\n\t\t\tif simplify(existed_login).eql? simplify(wanted_login)\n\t\t\t\tuser_can_register = false\n\t\t\tend\n\t\tend\n\n\t\tputs 'Yes' if user_can_register\n\t\tputs 'No' unless user_can_register\n\tend\nend\n"}], "negative_code": [{"source_code": "\ndef modify(s)\n s.gsub!(\"1\", \"l\")\n s.gsub!(\"I\", \"l\")\n s.gsub!(\"0\", \"o\")\n s.downcase!\nend\n\ns = gets.chomp\nmodify(s)\n\nlogins = Array.new\nn = gets.chomp.to_i\nfor i in 1..n\n logins.push(gets.chomp)\n modify(logins.last)\nend\n\nfor login in logins\n if login == s\n puts \"No\"\n exit\n end\nend\n\nputs \"Yes\"\n\n"}, {"source_code": "\ndef modify(s)\n s.gsub!(\"1\", \"l\")\n s.gsub!(\"i\", \"l\")\n s.gsub!(\"0\", \"o\")\n s.downcase!\nend\n\ns = gets.chomp\nmodify(s)\n\nlogins = Array.new\nn = gets.chomp.to_i\nfor i in 1..n\n logins.push(gets.chomp)\n modify(logins.last)\nend\n\nfor login in logins\n if login == s\n puts \"No\"\n exit\n end\nend\n\nputs \"Yes\"\n\n"}, {"source_code": "def simplify(string)\n\tstr_arr = string.split(\"\")\n\tstr_copy = str_arr\n\tstr_arr.each_with_index do |char, index|\n\t\tcase char\n\t\twhen 'O', 'o'\t#big ou\n\t\t\tstr_copy[index] = 0\n\t\twhen 'l', 'I', 'L', 'i'\n\t\t\tstr_copy[index] = 1\n\t\telse\n\t\t\tstr_copy[index] = char\n\t\tend\n\tend\n\tstr_copy.join('').downcase\nend\n\n\nwanted_login = gets.chomp\nnumber = gets.chomp\nlogins = []\n\nif wanted_login.length <= 50 && (number.to_i > 1 && number.to_i < 1000)\n\tall_logins_passed = true\n\n\tnumber.to_i.times do\n\t\tif all_logins_passed\n\t\t\tlogins << gets.chomp\n\t\tend\n\tend\n\n\tlogins.each do |curent_login|\n\t\tall_logins_passed = false if curent_login.length > 50\n\tend\n\n\tif all_logins_passed\n\t\tuser_can_register = true\n\n\t\tlogins.each do |existed_login|\n\t\t\tif simplify(existed_login).eql? simplify(wanted_login)\n\t\t\t\tuser_can_register = false\n\t\t\tend\n\t\tend\n\n\t\tputs 'Yes' if user_can_register\n\t\tputs 'No' unless user_can_register\n\tend\nend\n"}, {"source_code": "\ndef modify(s)\n s.downcase!\n s.gsub!(\"1\", \"l\")\n s.gsub!(\"I\", \"l\")\n s.gsub!(\"0\", \"o\")\nend\n\ns = gets.chomp\nmodify(s)\n\nlogins = Array.new\nn = gets.chomp.to_i\nfor i in 1..n\n logins.push(gets.chomp)\n modify(logins.last)\nend\n\nfor login in logins\n if login == s\n puts \"No\"\n exit\n end\nend\n\nputs \"Yes\"\n\n"}, {"source_code": "\ndef modify(s)\n s.downcase!\n s.gsub!(\"1\", \"l\")\n s.gsub!(\"0\", \"o\")\nend\n\ns = gets.chomp\nmodify(s)\n\nlogins = Array.new\nn = gets.chomp.to_i\nfor i in 1..n\n logins.push(gets.chomp)\n modify(logins.last)\nend\n\nfor login in logins\n if login == s\n puts \"No\"\n exit\n end\nend\n\nputs \"Yes\"\n\n"}], "src_uid": "0d70984ab8bd7aecd68c653adf54fc08"} {"source_code": "n = gets.to_i\ns = gets.chomp.split(\"\").map(&:to_i)\na = [0,0,0]\nn.times do |i|\n a[s[i]] += 1\nend\nif a[0] < n/3\n n.times do |i|\n next if s[i] == 0 || a[s[i]] <= n/3\n a[0] += 1\n a[s[i]] -= 1\n s[i] = 0\n break if a[0] == n/3\n end\nend\nif a[1] < n/3\n n.times do |i|\n next if s[i] < 2 || a[s[i]] <= n/3\n a[1] += 1\n a[2] -= 1\n s[i] = 1\n break if a[1] == n/3\n end\nend\nif a[2] < n/3\n n.times do |i|\n next if s[-1-i] == 2 || a[s[-1-i]] <= n/3\n a[2] += 1\n a[s[-1-i]] -= 1\n s[-1-i] = 2\n break if a[2] == n/3\n end\nend\nif a[1] < n/3\n n.times do |i|\n next if s[-1-i] > 0\n a[1] += 1\n a[0] -= 1\n s[-1-i] = 1\n break if a[1] == n/3\n end\nend\nputs s.join(\"\")", "positive_code": [{"source_code": "n = gets.to_i\nm = n / 3\na = gets.chomp.chars.map(&:to_i)\ncnt = (0...3).map { a.count(_1) }\n\n2.times do\n\ta.each_with_index do |from, i|\n\t\t(0...from).each do |to|\n\t\t\tif cnt[from] > m && cnt[to] < m\n\t\t\t\ta[i] = to\n\t\t\t\tcnt[from] -= 1\n\t\t\t\tcnt[to] += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\n\ta = a.reverse.map { 2 - _1 }\n\tcnt.reverse!\nend\nputs a.join\n"}], "negative_code": [{"source_code": "n = gets.to_i\ns = gets.chomp.split(\"\").map(&:to_i)\na = [0,0,0]\nn.times do |i|\n a[s[i]] += 1\nend\nif a[0] < n/3\n n.times do |i|\n next if s[i] == 0 || a[s[i]] <= n/3\n a[0] += 1\n a[s[i]] -= 1\n s[i] = 0\n break if a[0] == n/3\n end\nend\nif a[1] < n/3\n n.times do |i|\n next if s[i] < 2\n a[1] += 1\n a[2] -= 1\n s[i] = 1\n break if a[1] == n/3\n end\nend\nif a[2] < n/3\n n.times do |i|\n next if s[-1-i] == 2 || a[s[-1-i]] <= n/3\n a[2] += 1\n a[s[-1-i]] -= 1\n s[-1-i] = 2\n break if a[2] == n/3\n end\nend\nif a[1] < n/3\n n.times do |i|\n next if s[-1-i] > 0\n a[1] += 1\n a[0] -= 1\n s[-1-i] = 1\n break if a[1] == n/3\n end\nend\nputs s.join(\"\")"}], "src_uid": "cb852bf0b62d72b3088969ede314f176"} {"source_code": "n = gets.to_i\n\nn.times do\n m = gets.chomp\n\n p (m.to_i - (10 ** (m.size - 1)))\nend\n", "positive_code": [{"source_code": "def round_down_price(num)\n len = num.digits.count\n round = 10**(len-1)\n extra = num - round\n extra\nend\n\nt = gets.chomp.to_i\ninput = []\n(0..t-1).each do |i|\n input.push(gets.chomp.to_i)\nend\n\ninput.each do |i|\n p round_down_price(i)\nend\n\n"}, {"source_code": "t = gets.to_i\nt.times {\n n = gets.chomp\n if n == 0\n puts \"0\"\n else\n n[0] = (n[0].ord - 1).chr\n puts n.to_i\n end\n}\n"}, {"source_code": "gets.to_i.times { m = gets.strip; puts m.to_i - 10 ** (m.size - 1)}\r\n"}], "negative_code": [{"source_code": "gets.to_i.times { m = gets; puts m.to_i - 10 ** (m.size - 1)}"}], "src_uid": "5312a505bd59b55a6c5487f67a33d81a"} {"source_code": "n=gets.to_i\n\na=n*(n-1)*(n-2)*(n-3)*(n-4)\nb=a*(n-5)\nc=b*(n-6)\n\nprint(a/(2*3*4*5)+b/(2*3*4*5*6)+c/(2*3*4*5*6*7))\n", "positive_code": [{"source_code": "def comb(n,k)\n\tr=1\n\tk.times{|i|\n\t\tr=r*(n-i)/(i+1)\n\t}\n\tr\nend\nn=gets.to_i\np comb(n,5)+comb(n,6)+comb(n,7)"}, {"source_code": "n=gets.to_i\nr=t=(n-4..n).inject(:*)/120\nt=t*(n-5)/6\nr+=t\nt=t*(n-6)/7\np r+t"}], "negative_code": [{"source_code": "p gets.to_i*4+1"}, {"source_code": "n=gets.to_i\nr=(n-4..n).inject(:*)/120\nr*=(n-5)*(n-6)/42\np r"}, {"source_code": "n=gets.to_i\nr=t=(n-4..n).inject(:*)/120\nr+=t*=(n-5)/6\nr+=t*=(n-6)/7\np r"}], "src_uid": "09276406e16b46fbefd6f8c9650472f0"} {"source_code": "n = gets.to_i\na = gets.chomp.split.map(&:to_i)\nc = Array.new(101) { [] }\n\na.each_with_index do |e, i|\n c[e] << i\nend\n\ntotal = c.map(&:length).map { |e| [e, 2].min }.inject(:+)\nhalf = total/2\nputs half * (total-half)\n\nb = Array.new(2*n)\ncnt = 0\n\nc.each do |e|\n if e.length >= 2\n b[e[0]] = 1\n b[e[1]] = 2\n cnt += 1\n end\nend\n\nc.each do |e|\n if e.length == 1\n if cnt < half\n b[e[0]] = 1\n cnt += 1\n else\n b[e[0]] = 2\n end\n end\nend\n\na.each_with_index do |e, i|\n if b[i] == nil\n if cnt < n\n b[i] = 1\n cnt += 1\n else\n b[i] = 2\n end\n end\nend\n\nb.each do |e|\n print e , ' '\nend\nputs\n\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\nn = $stdin.readline.to_i\ncubes = $stdin.readline.split.map(&:to_i)\n\ncubes_count = Hash.new\n\ncubes.each{|x| cubes_count[x] = (cubes_count[x] == nil ? 1 : cubes_count[x] + 1 )}\n\na1 = []\na2 = []\n\ncubes_count.each_pair {|key, value|\n if value == 1\n if a1.length < a2.length\n a1.push key\n else\n a2.push key\n end\n else\n a1.push key\n a2.push key\n end\n}\n\na1.sort!\na2.sort!\n\nb1 = a1.length\nb2 = a2.length\n\ncubes_count.each_pair {|key, value|\n v = value - 2\n while v > 1\n a1.push key\n a2.push key\n v -= 2\n end\n if v == 1\n if a1.length < a2.length\n a1.push key\n else\n a2.push key\n end\n end\n}\n\n# puts \"#{cubes_count} #{a1.length} #{a2.length}\"\n# puts \"#{a1}\"\n# puts \"#{a2}\"\n\nans = []\n\ncubes.each_index { |i|\n if a1.include? cubes[i]\n ans[i] = 1\n a1.delete_at(a1.index(cubes[i]))\n else\n ans[i] = 2\n a2.delete_at(a2.index(cubes[i]))\n end\n}\n\n# puts ans.inject{|sum,x| sum + x }\n\nputs \"#{b1*b2}\"\nputs ans.join(' ')\n"}, {"source_code": "n = gets.to_i\ngiven = gets.split.map{|s| s.to_i}\nnumbers = Array::new(100, 0)\ngiven.each { |cg| numbers[cg] += 1 }\nflag0 = 0\nflag1 = 0\nsum = 0\nnumbers.map! {|n|\n\tif n > 0\n\t\tif n == 1\n\t\t\tsum += 1\n\t\t\tflag0 = (flag0+1)%2\n\t\t\tn = flag0\n\t\telsif n%2 == 1\n\t\t\tsum += 2\n\t\t\tflag1 = (flag1+1)%2\n\t\t\tn += flag1\n\t\telse\n\t\t\tsum += 2\n\t\t\tn\n\t\tend\n\tend\n}\nif sum%2 == 0\n\tputs sum*sum/4\nelse\n\tputs sum/2*(sum/2 + 1)\nend\ngiven.each {|cg| \n\tprint (numbers[cg]%2 + 1).to_s + \" \"\n\tnumbers[cg] -= 1\n}"}, {"source_code": "n = gets.to_i\na = gets.chomp.split.map(&:to_i)\nc = Array.new(101) { [] }\n\na.each_with_index do |e, i|\n c[e] << i\nend\n\ntotal = c.map(&:length).map { |e| [e, 2].min }.inject(:+)\nhalf = total/2\nputs half * (total-half)\n\nb = Array.new(2*n)\ncnt = 0\n\nc.each do |e|\n if e.length >= 2\n b[e[0]] = 1\n b[e[1]] = 2\n cnt += 1\n end\nend\n\nc.each do |e|\n if e.length == 1\n if cnt < half\n b[e[0]] = 1\n cnt += 1\n else\n b[e[0]] = 2\n end\n end\nend\n\na.each_with_index do |e, i|\n if b[i] == nil\n if cnt < n\n b[i] = 1\n cnt += 1\n else\n b[i] = 2\n end\n end\nend\n\nb.each do |e|\n print e , ' '\nend\nputs"}, {"source_code": "n = gets.to_i\na = gets.chomp.split.map(&:to_i)\nh = Hash.new\n\na.each_with_index do |e, i|\n (h[e] ||= []) << i\nend\n\ntotal = h.values.map(&:length).map { |e| [e, 2].min }.inject(:+)\nhalf = total/2\nputs half * (total-half)\n\nb = Array.new(2*n)\ncnt = 0\n\nh.each do |k, v|\n if v.length >= 2\n b[v[0]] = 1\n b[v[1]] = 2\n cnt += 1\n end\nend\n\nh.each do |k, v|\n if v.length == 1\n if cnt < half\n b[v[0]] = 1\n cnt += 1\n else\n b[v[0]] = 2\n end\n end\nend\n\na.each_with_index do |e, i|\n if b[i] == nil\n if cnt < n\n b[i] = 1\n cnt += 1\n else\n b[i] = 2\n end\n end\nend\n\nb.each do |e|\n print e , ' '\nend\nputs\n\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split.map(&:to_i)\nh = Hash.new\n\na.each_with_index do |e, i|\n (h[e] ||= []) << i\nend\n\ntotal = h.values.map(&:length).map { |e| [e, 2].min }.inject(:+)\nhalf = total/2\nputs half * (total-half)\n\nb = Array.new(2*n)\ncnt = 0\n\nh.each do |k, v|\n if v.length >= 2\n\tb[v[0]] = 1\n\tb[v[1]] = 2\n\tcnt += 1\n end\nend\n\nh.each do |k, v|\n if v.length == 1\n\tif cnt < half\n\t b[v[0]] = 1\n\t cnt += 1\n\telse\n\t b[v[0]] = 2\n\tend\n end\nend\n\na.each_with_index do |e, i|\n if b[i] == nil\n\tif cnt < n\n\t b[i] = 1\n\t cnt += 1\n\telse\n\t b[i] = 2\n\tend\n end\nend\n\nb.each do |e|\n print e , ' '\nend\nputs\n\n"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.chomp.split.map(&:to_i)\nh = Hash.new { |h, k| h[k] = [] }\n\na.each_with_index do |e, i|\n h[e] << i\nend\n\ntmp = h.values.map(&:length).map { |e| [e, 2].min }.inject(:+)\nputs tmp/2*(tmp-tmp/2)\n\nb = Array.new(2*n)\ncnt = 0\na.each_with_index do |e, i|\n if b[i] == nil\n\tb[i] = 1\n\th[e].shift\n\tif !h[e].empty?\n\t b[h[e].pop] = 2\n\tend\n\tcnt += 1\n\tif cnt == n\n\t break\n\tend\n end\nend\n\nb.each do |e|\n print e ||= 2, ' '\nend\nputs\n\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split.map(&:to_i)\nh = Hash.new\n\na.each_with_index do |e, i|\n (h[e] ||= []) << i\nend\n\ntotal = h.values.map(&:length).map { |e| [e, 2].min }.inject(:+)\nhalf = total/2\nputs half * (total-half)\n\nb = Array.new(2*n)\ncnt = 0\nh.each do |k, v|\n if v.length >= 2\n\tb[v[0]] = 1\n\tb[v[1]] = 2\n\tcnt += 1\n end\nend\n\na.each_with_index do |e, i|\n if b[i] != nil\n\tnext\n else\n\tif cnt < n\n\t b[i] = 1\n\t cnt += 1\n\telse\n\t b[i] = 2\n\tend\n end\nend\n\nb.each do |e|\n print e , ' '\nend\nputs\n\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split.map(&:to_i)\nh = Hash.new\n\na.each_with_index do |e, i|\n (h[e] ||= []) << i\nend\n\ntotal = h.values.map(&:length).map { |e| [e, 2].min }.inject(:+)\nhalf = total/2\nputs half * (total-half)\n\nb = Array.new(2*n)\ncnt = 0\nh.each do |k, v|\n if v.length >= 2\n\tb[v[0]] = 1\n\tb[v[1]] = 2\n\tcnt += 1\n end\nend\n\na.each_with_index do |e, i|\n if b[i] != nil\n\tnext\n else\n\tif cnt < half \n\t b[i] = 1\n\t cnt += 1\n\telse\n\t b[i] = 2\n\tend\n end\nend\n\nb.each do |e|\n print e ||= 2, ' '\nend\nputs\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = $stdin.readline.to_i\ncubes = $stdin.readline.split.map(&:to_i)\n\ncubes_count = Hash.new\n\ncubes.each{|x| cubes_count[x] = (cubes_count[x] == nil ? 1 : cubes_count[x] + 1 )}\n\na1 = []\na2 = []\n\ncubes_count.each_pair {|key, value|\n v = value\n while v > 1\n a1.push key\n a2.push key\n v -= 2\n end\n if v == 1\n if a1.length < a2.length\n a1.push key\n else\n a2.push key\n end\n end\n}\n\na1.sort!\na2.sort!\n\nb1 = 1\nb2 = 1\n\na1.each_index {|index|\n if index > 0\n if a1[index - 1] != a1[index]\n b1 += 1\n end\n end\n}\n\na2.each_index {|index|\n if index > 0\n if a2[index - 1] != a2[index]\n b2 += 1\n end\n end\n}\n\nans = []\n\ncubes.each_index { |i|\n if a1.include? cubes[i]\n ans[i] = 1\n a1.delete_at(a1.index(cubes[i]) || a1.length)\n else\n ans[i] = 2\n a2.delete_at(a2.index(cubes[i]) || a2.length)\n end\n}\n\nputs \"#{cubes_count}\"\nputs \"#{a1}\"\nputs \"#{a2}\"\nputs \"#{b1*b2}\"\nputs ans.join(' ')\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = $stdin.readline.to_i\ncubes = $stdin.readline.split.map(&:to_i)\n\ncubes_count = Hash.new\n\ncubes.each{|x| cubes_count[x] = (cubes_count[x] == nil ? 1 : cubes_count[x] + 1 )}\n\na1 = []\na2 = []\n\ncubes_count.each_pair {|key, value|\n v = value\n while v > 1\n a1.push key\n a2.push key\n v -= 2\n end\n if value == 1\n if a1.length < a2.length\n a1.push key\n else\n a2.push key\n end\n end\n}\n\na1.sort!\na2.sort!\n\nb1 = 1\nb2 = 1\n\na1.each_index {|index|\n if index > 0\n if a1[index - 1] != a1[index]\n b1 += 1\n end\n end\n}\n\na2.each_index {|index|\n if index > 0\n if a2[index - 1] != a2[index]\n b2 += 1\n end\n end\n}\n\nans = []\n\ncubes.each_index { |i|\n if a1.include? cubes[i]\n ans[i] = 1\n a1.delete_at(a1.index(cubes[i]) || a1.length)\n else\n ans[i] = 2\n a2.delete_at(a2.index(cubes[i]) || a2.length)\n end\n}\n\n# puts \"#{cubes_count}\"\n# puts \"#{a1}\"\n# puts \"#{a2}\"\nputs \"#{b1*b2}\"\nputs ans.join(' ')\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = $stdin.readline.to_i\ncubes = $stdin.readline.split.map(&:to_i)\n\ncubes_count = Hash.new\n\ncubes.each{|x| cubes_count[x] = (cubes_count[x] == nil ? 1 : cubes_count[x] + 1 )}\n\na1 = []\na2 = []\n\ncubes_count.each_pair {|key, value|\n v = value\n while v > 1\n a1.push key\n a2.push key\n v -= 2\n end\n if v == 1\n if a1.length < a2.length\n a1.push key\n else\n a2.push key\n end\n end\n}\n\na1.sort!\na2.sort!\n\nb1 = 1\nb2 = 1\n\na1.each_index {|index|\n if index > 0\n if a1[index - 1] != a1[index]\n b1 += 1\n end\n end\n}\n\na2.each_index {|index|\n if index > 0\n if a2[index - 1] != a2[index]\n b2 += 1\n end\n end\n}\n\nans = []\n\ncubes.each_index { |i|\n if a1.include? cubes[i]\n ans[i] = 1\n a1.delete_at(a1.index(cubes[i]) || a1.length)\n else\n ans[i] = 2\n a2.delete_at(a2.index(cubes[i]) || a2.length)\n end\n}\n\n# puts \"#{cubes_count}\"\n# puts \"#{a1}\"\n# puts \"#{a2}\"\nputs \"#{b1*b2}\"\nputs ans.join(' ')\n"}], "src_uid": "080287f34b0c1d52eb29eb81dada41dd"} {"source_code": "n, l, r, ql, qr = gets.split.map(&:to_i)\nw = gets.split.map(&:to_i)\n\nleft = Array.new(n+2, 0)\nright = Array.new(n+2, 0)\n\nfor i in 0...n\n left[i+1] = left[i]+w[i]\n right[n-i] = right[n-i+1]+w[n-i-1]\nend\n\nmin = 2**30\nfor i in 0..n\n energy = l*left[i]+r*right[i+1]\n same = n - 2*i\n if same > 1\n energy += (same-1)*qr\n elsif same < -1\n energy -= (same+1)*ql\n end\n if energy < min\n min = energy\n end\nend\n\nprint min", "positive_code": [{"source_code": "#f = File.open('test1.txt', 'r')\nf = STDIN\nn, l, r, Ql, Qr = f.gets.chomp.split.map &:to_i\nw = f.gets.chomp.split.map &:to_i\nsum = Array.new(w.size)\nsum[0] = w[0]\n(1...n).each do |i|\n sum[i] = sum[i-1] + w[i]\nend\n\ntotal = -1\n(0..n).each do |k|\n tmp_total = 0\n tmp_sum = k == 0 ? 0 : sum[k-1]\n tmp_total += tmp_sum * l + (sum[n-1] - tmp_sum) * r\n if k > n - k\n tmp_total += (2 * k - n - 1) * Ql\n end\n if k < n - k\n tmp_total += (n - 2 * k - 1) * Qr\n end\n if total == -1\n total = tmp_total\n else\n total = [total, tmp_total].min\n end\nend\nputs total\n"}, {"source_code": "n, l, r, ql, qr = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nans = 2**30\nsl = 0\nsr = a.inject(:+)\n\nfor i in (0..n)\n trial = 0\n if 2*i < n\n trial += (n-2*i-1)*qr\n elsif 2*i > n\n trial += (2*i-n-1)*ql\n end\n trial += sl*l + sr*r\n ans = [ans, trial].min\n if i < n\n sl += a[i]\n sr -= a[i]\n end\nend\n\nputs ans\n\n"}], "negative_code": [{"source_code": "n, l, r, ql, qr = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nans = 1e9\nsl = 0\nsr = a.inject(:+)\n\nfor i in (0..n)\n trial = 0\n if 2*i < n\n trial += (n-2*i-1)*qr\n elsif 2*i > n\n trial += (2*i-n-1)*ql\n end\n trial += sl*l + sr*r\n ans = [ans, trial].min\n if i < n\n sl += a[i]\n sr -= a[i]\n end\nend\n\nputs ans\n\n"}, {"source_code": "line = gets.split(' ').map(&:to_i)\nn = line[0]\nl = line[1]\nr = line[2]\nql = line[3]\nqr = line[4]\na = gets.split(' ').map(&:to_i)\nif l < r\n l, r = r, l\n ql, qr = qr, ql\nend\n\na.sort!\nans = 2**32\nsl = 0\nsr = a.inject(:+)\nfor i in (0...a.size)\n trial = 0\n if 2*i > a.size\n break\n elsif 2*i < a.size\n trial += (a.size-2*i-1)*qr\n end\n trial += sl*l+sr*r\n ans = [ans, trial].min\n sl += a[i]\n sr -= a[i]\nend\n\nputs ans\n"}, {"source_code": "n, l, r, ql, qr = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nif l < r\n l, r = r, l\n ql, qr = qr, ql\nend\na.sort!\nans = 2**32\nsl = 0\nsr = a.inject(:+)\n\nfor i in (0...a.size)\n trial = 0\n if 2*i > a.size\n break\n elsif 2*i < a.size\n trial += (a.size-2*i-1)*qr\n end\n trial += sl*l+sr*r\n ans = [ans, trial].min\n sl += a[i]\n sr -= a[i]\nend\n\nputs ans\n\n"}, {"source_code": "n, l, r, ql, qr = gets.split.map(&:to_i)\nw = gets.split.map(&:to_i)\n\nleft = Array.new(n+2, 0)\nright = Array.new(n+2, 0)\n\nfor i in 0...n\n left[i+1] = left[i]+w[i]\n right[n-i] = right[n-i+1]+w[n-i-1]\nend\n\nmin = 2**30\nfor i in 0..n\n energy = l*left[i]+r*right[i+1]\n same = n - 2*i\n if same > 0\n energy += same*qr\n else\n energy -= same*ql\n end\n if energy < min\n min = energy\n end\nend\n\nprint min"}], "src_uid": "e6fcbe3f102b694a686c0295edbc35e9"} {"source_code": "t = gets.to_i\r\nt.times do\r\n d=gets.split.map &:to_i\r\n puts d.count{|i|i>d[0]}\r\nend", "positive_code": [{"source_code": "gets.to_i.times do\n a, b, c, d = gets.split.map(&:to_i)\n ans = 0\n ans += 1 if a < b\n ans += 1 if a < c\n ans += 1 if a < d\n puts ans\nend\n"}, {"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n a, *x = ints\r\n \r\n puts x.count { _1 > a }\r\n end\r\n}\r\n\r\nDEBUG = false\r\nMOD = 10**9+7\r\nINF = 10**18\r\n$yesno = %w(No Yes)\r\n$YesNo = %w(No Yes)\r\n$YESNO = %w(NO YES)\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t ? 1 : 0] end\r\ndef YesNo t; puts $YesNo[t ? 1 : 0] end\r\ndef YESNO t; puts $YESNO[t ? 1 : 0] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]"}, {"source_code": "gets.to_i.times do\r\n a, b, c, d = gets.split.map(&:to_i)\r\n p [b, c, d].count { |x| x > a }\r\nend\r\n"}, {"source_code": " gets.to_i.times {\n \ta,*b = gets.split.map {|x| x.to_i }\n \tputs (b.count{|x| x > a})\n }"}, {"source_code": "t = gets.to_i\n\ninputs = []\n(0...t).each do\n arr = gets.chomp\n arr = arr.split(\" \").map(&:to_i)\n inputs << arr\n\nend\n\ninputs.each do |arr|\n ans = 0\n # array.each do |arr|\n a = arr[0]\n b = arr[1]\n c = arr[2]\n d = arr[3]\n\n if a < b\n ans += 1\n end\n if a < c\n ans += 1\n end\n if a < d\n ans += 1\n end\n # end\n puts ans\nend\n\n"}, {"source_code": "s = gets.to_i\n\nresult = []\ns.times do |i|\n a, b, c, d = gets.split(\" \").map(&:to_i)\n\n r = 0\n r += 1 if b > a\n r += 1 if c > a\n r += 1 if d > a\n\n result.push(r)\nend\n\nresult.each { |line| puts line }\n"}, {"source_code": "def solve\r\n v = gets.split.map(&:to_i)\r\n ans = 0\r\n if v[1] > v[0]\r\n ans = ans + 1\r\n end\r\n if v[2] > v[0]\r\n ans = ans + 1\r\n end\r\n if v[3] > v[0]\r\n ans = ans + 1\r\n end\r\n puts ans\r\nend\r\n \r\ngets.to_i.times do\r\n solve\r\nend"}, {"source_code": "gets.to_i.times do\r\n a, b, c, d = gets.split.map(&:to_i)\r\n ans = 0\r\n ans += 1 if a <= b\r\n ans += 1 if a <= c\r\n ans += 1 if a <= d\r\n puts ans\r\nend\r\n"}], "negative_code": [], "src_uid": "e829ca4438e9cb30ea1c66eea7d5f7a7"} {"source_code": "t = gets.to_i\n\n1.upto t do |i|\n sum = 0\n n, m = gets.split.map(&:to_i)\n if n == 1\n sum = 0\n elsif n == 2\n sum = m\n else\n sum = 2 * m\n end\n puts sum\nend", "positive_code": [{"source_code": "gets.to_i.times do\n\ta, b = gets.split.map(&:to_i)\n\tif a == 1\n\t\tputs 0\n\telsif a == 2\n\t\tputs b\n\telse\n\t\tputs b * 2\n\tend\nend\n"}, {"source_code": "t = gets.to_i\nuntil t==0 do\n n, m = gets.split.map(&:to_i)\n puts [2,n-1].min*m\n t-=1\n\nend\n\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do |testcase|\n (n,k) = gets.split.map(&:to_i)\n if n == 1\n puts 0\n elsif n == 2\n puts k\n else\n puts k*2\n end\nend"}, {"source_code": "\ngets.to_i.times {\n n, m = gets.split().map do |v|\n v.to_i\n end\n\n if n == 1\n puts 0\n elsif n == 2\n puts m\n else\n puts m * 2\n end\n}\n\n"}, {"source_code": "t=gets.chomp.to_i\nwhile (t>0)\n\tn,m = gets.split.map(&:to_i)\n\tif(n==1) \n\t\tputs\"0\"\n\telsif (n==2) \n\t\tputs\"#{m}\"\n\telse \n\t\tputs\"#{m*2}\"\n\tend\n\tt-=1\nend"}, {"source_code": "gets.to_i.times do\n n, m = gets.split.map &:to_i\n puts case n\n when 1\n 0\n when 2\n m\n else\n 2*m\n end\nend\n"}, {"source_code": "1.upto(gets.to_i) do\n n, m = gets.split(' ').map(&:to_i)\n\n k = n.div(2)\n l = m.div(k.zero? ? 1 : k)\n\n puts case n\n when 1\n 0\n when 2\n m\n when proc(&:even?)\n 2*m\n else\n 2*l*k + 2*m.modulo(k)\n end\nend\n"}, {"source_code": "t = gets.to_i\n\n(1).upto(t) do\n a = gets.split(' ').map(&:to_i)\n n = a[0]\n m = a[1]\n if n==1\n puts 0\n elsif n==2\n puts m\n else\n puts m*2\n end\nend\n"}], "negative_code": [{"source_code": "t = gets.to_i\nuntil t==0 do\n m, n = gets.split.map(&:to_i)\n puts [2,n-1].min*m\n t-=1\n\nend\n\n"}], "src_uid": "905cc16ecbbb3305416f9aa6e4412642"} {"source_code": "def solve(n, b)\n mn, mx = 0, b[0]\n res = []\n b.each_with_index do |e, i|\n if mn + mx == e\n res[i] = mn\n res[b.size * 2 - i -1 ] = mx\n else\n if e - mn > mx\n res[b.size * 2 - i -1 ] = mx\n res[i] = e - mx\n else\n res[i] = mn\n res[b.size * 2 - i -1 ] = e - mn\n end\n end\n mn = res[i]\n mx = res[b.size * 2 - i -1 ]\n end\n res.join(' ')\nend\n\nputs solve(gets.strip.to_i, gets.strip.split.map(&:to_i))", "positive_code": [{"source_code": "n = gets.to_i\nb = gets.split.map(&:to_i)\na1,a2 = [],[]\nl,r = 0,10**18\nb.each_with_index do |v,i|\n r = r < (v-l) ? r : v - l\n l = v - r\n a1 << l\n a2 << r\nend\na1.each do |v|\n print \"#{v} \"\nend\n(n/2).times do |i|\n v = a2[-i-1]\n print \"#{v}\"\n print \" \" if i < (n/2-1)\nend\n"}], "negative_code": [], "src_uid": "4585419ab2b7200770cfe1e607161e9f"} {"source_code": "gets\n\nanswer = 0\nstash = Hash.new { 0 }\ngets.chomp.chars.each.with_index do |ch, i|\n if i % 2 == 0\n stash[ch.upcase] += 1\n else\n if stash[ch] > 0\n stash[ch] -= 1\n else\n answer += 1\n end\n end\nend\nputs answer", "positive_code": [{"source_code": "# http://codeforces.com/contest/525/problem/A\n\nn = gets.to_i\ns = gets.chomp.chars\nkeys = Hash.new(0)\nans = 0\n\ns.each_slice(2) do |key, door|\n keys[key] += 1\n if keys[door.downcase] >= 1\n keys[door.downcase] -= 1\n else\n ans += 1\n end\nend\n\nputs ans\n"}, {"source_code": "keys = Hash.new(0)\nanswer = 0\ngets\ngets.chomp.chars.each_slice(2) do |k,d|\n keys[k] += 1\n if keys[d.downcase] >= 1\n keys[d.downcase] -= 1\n else\n answer += 1\n end\nend\n\nputs answer\n"}, {"source_code": "gets\nhs=Hash.new(0)\nans=0\ngets.chomp.chars{|e|\n\te2=e.downcase\n\tif e2==e then\n\t\ths[e]+=1\n\telse\n\t\tif hs[e2]>0 then\n\t\t\ths[e2]-=1\n\t\telse\n\t\t\tans+=1\n\t\tend\n\t\t\n\tend\n}\nputs ans"}, {"source_code": "gets;c=Hash.new(0);puts gets.strip.chars.reduce(0){|a,b|d=b.downcase;a+=(b!=d&&c[d]==0)?1:0;c[d]+=(b==d)?1:(c[d]>0?-1:0);a}"}, {"source_code": "gets\na = gets.chomp.split(//)\nhas = Hash.new(0)\nc = 0\na.each do |t|\n if t == t.downcase\n has[t] += 1\n elsif has[t.downcase] == 0\n c += 1\n else\n has[t.downcase] -= 1\n end\nend\n\nputs c"}, {"source_code": "\nn = gets.chomp.to_i;\narr = gets.chomp.split(\"\").map{|x| x.upcase.ord - 65;};\nmap = Array.new(26, 0);\nans = 0;\n\n(n-1).times do |i|\n i = 2 * i;\n # print i, \" \", arr[i], \"\\n\";\n map[arr[i]] += 1;\n i += 1;\n map[arr[i]] -= 1;\n if map[arr[i]] == -1\n map[arr[i]] = 0;\n ans += 1;\n end\nend\nputs ans;\n"}, {"source_code": "require 'pp'\ndef stdin_int; STDIN.gets.chomp.to_i; end\ndef stdin_ints; STDIN.gets.chomp.split(/ /).map(&:to_i); end\n\nans = 0\n\nn = stdin_int\ns = STDIN.gets.chomp\nh = {}\nh.default = 0\ns.split(//).each_with_index do |c, index|\n if index.even?\n h[c] += 1\n else\n if h[c.downcase] > 0\n h[c.downcase] -= 1\n else\n ans += 1\n end\n end\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.split(\"\")\nr = Array.new(123, 0)\nans = 0\na.each do |x|\n if x == x.downcase\n r[x.ord] += 1\n elsif x == x.upcase\n if r[x.downcase.ord] == 0\n ans += 1\n else\n r[x.downcase.ord] -= 1\n end\n end\nend\nputs ans \n"}, {"source_code": "# f = File.open 'input.txt', 'r'\nf = STDIN\n\ndef compute(n, s)\n missing_keys = 0\n keys = Hash.new(0)\n\n n.times do |i|\n break if i == n - 1\n # store the key\n keys[s[i * 2].upcase] += 1\n\n # unlock the door\n if keys[s[i * 2 + 1]].zero?\n missing_keys += 1\n else\n keys[s[i * 2 + 1]] -= 1\n end\n end\n missing_keys\nend\n\nwhile true\n raw_n = f.gets\n break unless raw_n\n n = raw_n.chomp.to_i\n s = f.gets.chomp\n p compute(n, s)\nend\n"}], "negative_code": [{"source_code": "# http://codeforces.com/contest/525/problem/A\n\nn = gets.to_i\ns = gets.chomp.chars\nkeys = []\nans = 0\n\ns.each_slice(2) do |key, door|\n keys << key\n if keys.include?(door.downcase)\n keys.delete key\n else\n ans += 1\n end\nend\n\nputs ans\n"}, {"source_code": "# http://codeforces.com/contest/525/problem/A\n\nn = gets.to_i\ns = gets.chomp.chars\nkeys = Hash.new(0)\nans = 0\n\ns.each_slice(2) do |key, door|\n keys[key] += 1\n if keys[door.downcase] > 0\n keys[key] -= 1\n else\n ans += 1\n end\nend\n\nputs ans\n"}, {"source_code": "require 'pp'\ndef stdin_int; STDIN.gets.chomp.to_i; end\ndef stdin_ints; STDIN.gets.chomp.split(/ /).map(&:to_i); end\n\nans = 0\n\nn = stdin_int\ns = STDIN.gets.chomp\nh = {}\nh.default = 0\ns.split(//).each_with_index do |c, index|\n if index.even?\n h[c] += 1\n else\n if h.has_key?(c.downcase)\n h[c] -= 1\n else\n ans += 1\n end\n end\nend\n\nputs ans\n"}, {"source_code": "require 'pp'\ndef stdin_int; STDIN.gets.chomp.to_i; end\ndef stdin_ints; STDIN.gets.chomp.split(/ /).map(&:to_i); end\n\nans = 0\n\nn = stdin_int\ns = STDIN.gets.chomp\nh = {}\ns.split(//).each_with_index do |c, index|\n if index.even?\n h[c] = true\n else\n if h.has_key?(c.downcase)\n h.delete(c.downcase)\n else\n ans += 1\n end\n end\nend\n\nputs ans\n"}, {"source_code": "gets\nputs gets.strip.chars.each_slice(2).each_with_object(Hash.new(0)){|(a,b),o|o[a.downcase]+=1;o[b.downcase]-=1}.reduce(0){|a,v|a-(v.last>0?0:v.last)}"}, {"source_code": "gets;c=0;gets.strip.chars.each_slice(2).each_with_object(Hash.new(0)){|(a,b),o|o[a.downcase]+=1;c+=(o[b.downcase]-=1)>=0?0:1};puts c"}, {"source_code": "gets;c=0;gets.strip.chars.each_slice(2).each_with_object(Hash.new(0)){|(a,b),o|o[a.upcase]+=1;o[b]=o[b]>0?o[b]-1:0;c+=o[b]>=0?0:1};puts c"}, {"source_code": "gets;c=0;gets.strip.chars.each_slice(2).each_with_object(Hash.new(0)){|(a,b),o|o[a.upcase]+=1;o[b]=[o[b],0].max-1;c+=o[b]>=0?0:1};puts c"}], "src_uid": "80fdb95372c1e8d558b8c8f31c9d0479"} {"source_code": "n = gets.to_i; n=n*n\n([(1..n/2).to_a] + [((n/2+1)..n).to_a.reverse]).transpose.each{|x| puts x.join(' ')}", "positive_code": [{"source_code": "n = gets.to_i\nar = (0...n).map{|x| x*(n+1)+1}\n(0...n).reverse_each do |x|\n puts ar.map(&:to_s).join(\" \")\n ar = ar.map(&:succ)\n ar[x] -= n\nend"}, {"source_code": "n=gets.to_i\na=[*1..n*n].each_slice(n).to_a.transpose\nputs (a[0...n/2]+a[n/2..-1].map(&:reverse)).transpose.map{|e|e*' '}"}, {"source_code": "n = gets.chomp.to_i\nfor i in 1..n\n l = \"\"\n for j in 1..n\n if j % 2 == 0\n l = l << ((j/2)*2*n-i+1).to_s << \" \"\n else\n l = l << (i+(j/2)*2*n).to_s << \" \"\n end\n end\n puts l\nend\n \n"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\nn = gets.chomp.to_i\n\ncandies = (1 .. n ** 2).to_a\nfor i in 0 .. (n - 1) do\n array = []\n (n / 2).times do\n array << candies.shift\n array << candies.pop\n end\n puts array.join(\" \")\nend"}, {"source_code": "n = STDIN.readline.to_i\nlines = []\nn.times do |r|\n\tc = 0\n\tparts = []\n\tn.times do |d|\n\t\tparts.push((r+d)%n * n + (c+d)%n + 1)\n\tend\n\tlines.push(parts.join(' '))\nend\nputs lines.join(\"\\n\")\n"}, {"source_code": "n = gets.chomp.to_i\na = (1..(n*n)).to_a\n\na = a.each_slice(a.length/2).to_a\na.last.reverse!\na = a.first.zip(a.last)\nputs a.each_slice(n/2).to_a.map{|x| x.flatten.join(' ')}\n"}, {"source_code": "n=gets.to_i\n\nfor i in 0..n-1\n\tfor j in 0..n/2-1\n\t\tprint 1+(i*n/2)+j,\" \"\n\tend\n\tfor j in 0..n/2-1\n\t\tprint n**2-n/2+1-(i*n/2)+j,\" \"\n\tend\n\tif i!=n-1\n\t\tprint \"\\n\"\n\tend\nend\n\n\n"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\nind = 1\nfor i in 1..n\n str = \"\"\n for j in 0...n/2\n str += \"#{ind} \"\n str += \"#{n*n+1 - ind} \"\n ind += 1\n end\n puts str\nend\n"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\nind = 1\nfor i in 1..n\n str = \"\"\n for j in 0...n/2\n str += \"#{ind + j} \"\n end\n for j in 0...n/2\n str += \"#{n*n+1 - ind} \"\n ind += 1\n end\n puts str\nend\n"}, {"source_code": "n = gets.to_i\nn.times {|i| puts (0..(n-1)).map {|j| j*n+(j+i)%n+1}.join(\" \")}\n"}, {"source_code": "#http://codeforces.com/problemset/problem/129/A\n\nn = gets.to_i \n\ninitial_first = 1 \ninitial_last = n**2 \n\n\nfirst = []\nsecond = []\nloop do \n first << initial_first \n first << initial_last \n initial_first += 2 \n initial_last -= 2 \n break if first.size >= n**2 \nend \n\n \n\nfirst.each_with_index do |i,ind| \n print \"#{i} \"\n if (ind+1)%n ==0 \n puts \n end \nend \n"}, {"source_code": "n = gets.chomp.to_i\n\nleft = 1\nright = n*n\n(1..n).each do |i|\n (left..left+n/2-1).each { |i| print \"#{i} \" }\n (right-n/2+1..right).each { |i| print \"#{i} \" }\n left += n/2\n right -= n/2\n puts\nend\n"}, {"source_code": "arr = (1..gets.to_i ** 2).to_a\nwhile arr.size != 0\n puts \"#{arr.shift} #{arr.pop}\"\nend\n"}, {"source_code": "n = gets.to_i\na = Array.new(n*n+1);\nfor i in 1..n*n do\n a[i] = i\n end\nl = 0x0\nl = 1\nr = n*n\nbegin\n if (l>r) then break end\n printf(\"%d %d\\n\", a[l], a[r])\n l += 1\n r -= 1\nend while true"}, {"source_code": "n=gets.to_i\nx=(1..n).map{[0]*n}\nt=1\n\nn.times{|c|\n\tif c%2==0 then\n\t\t0.upto(n-1){|r|\n\t\t\tx[r][c]=t\n\t\t\tt+=1\t\n\t\t}\n\telse\n\t\t(n-1).downto(0){|r|\n\t\t\tx[r][c]=t\n\t\t\tt+=1\n\t\t}\n\tend\n}\nn.times{|r|\n\tputs x[r]*\" \"\n}\n\n"}, {"source_code": "n=gets.to_i\nres=[]\nx=1\nn.times {|i|\n res<<[*x..x+n-1]\n res[i].reverse! if i.even?\n x+=n\n}\nn.times {|i|\n n.times{|j| print \"#{res[j][i]} \" }\n puts\n}\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nbase = [1]\nnp2 = n * n\nwhile base.last < np2\n new_inc = base.last + (n + 1)\n base << new_inc\nend\n\nn.times {\n puts base.join(' ')\n #p \"---> #{base.sum}\"\n for i in 0...n\n base[i] = (base[i] + n)%np2\n end\n}\n\n%{\n \uba3c\uc800 1\uc744 \uc900\ube44\ud55c\ub2e4.\n n\uc774 \ub420\ub54c\uae4c\uc9c0 n+1\uc744 \ub354\ud55c\ub2e4.\n \uc774\ub807\uac8c \ub9cc\ub4e4\uc5b4\uc9c4 \ubc30\uc5f4\uc758 \ud06c\uae30\ub294 n\uacfc \uac19\ub2e4. ---A\n \uc774 \ubc30\uc5f4\uc758 \ud569\uc740 N = n*n (\ucd5c\ub300\uac12)\uc774\ub77c\uace0 \ud560 \ub54c\n (N*(N+1)/2)/n = n*(n*n + 1)/2 \uc774\ub2e4.\n n\uc774 \ud640\uc218\ub77c\uba74 n*n\ub3c4 \ud640\uc218\uc774\ubbc0\ub85c +1\uc5d0\uc11c \uc9dd\uc218\uac00 \ub418\uc5b4\n 2\ub85c \ub098\ub20c \uc218 \uc788\uace0, n\uc774 \uc9dd\uc218\ub77c\uba74 \ub450\ub9d0\ud560 \ud544\uc694\uc5c6\uc774 2\ub85c \ub098\ub220\uc838\n \uc800 \uacb0\uacfc\uac12\uc740 \ud56d\uc0c1 \uc815\uc218\ub97c \uc720\uc9c0\ud55c\ub2e4. ----B\n A\uc5d0\uc11c \ub9cc\ub4e4\uc5b4\uc9c4 \uc218\uc5f4\uc758 \ud569\uc740 B\uc758 \uac12\uacfc \uac19\ub2e4.\n \uc608\ub97c \ub4e4\uc5b4 n = 3\uc778 \uacbd\uc6b0\ub294 15, n = 4\uc758 \uacbd\uc6b0\ub294 34\uc774\ub2e4.\n \uc5ec\uae30\uc11c\ubd80\ud130 \uc911\uc694\ud55c\ub370, A\uc5d0\uc11c \ub9cc\ub4e4\uc5b4\uc9c4 \uc218\uc5f4\uc5d0 \uac01\uac01 \uc544\ub798\uc758 \uc5f0\uc0b0\uc744 \ucde8\ud55c\ub2e4.\n A\uc758 \ubc30\uc5f4 \uc6d0\uc18c\ub97c An\uc774\ub77c \ud560\ub54c,\n 1) An \uc5d0 n\uc744 \ub354\ud55c\ub2e4\n 2) 1\uc5d0 mod n*n \uc5f0\uc0b0\uc744 \ucde8\ud574 \ub098\uba38\uc9c0 \uac12\uc744 \uc5bb\ub294\ub2e4.\n \uc774\ub807\uac8c \ub418\uba74 \ud56d\uc0c1 \uc77c\uc815\ud55c \uc704\uce58\uc758 \uc218\ub07c\ub9ac \ud569\uc744 \uad6c\ud558\uac8c \ub418\ubbc0\ub85c \uc77c\uc815\ud55c \ud569\uacc4\uac00 \ubc18\ubcf5\ub41c\ub2e4.\n \uc774\uac78 n-1 \ud68c \ubc18\ubcf5\ud558\uba74 \uc6d0\ud558\ub294 \uac12\ub4e4\uc744 \uc5bb\uc744 \uc218 \uc788\ub2e4.\n \uc608) n = 3\n step1) [1, 5, 9]\n step2) [4, 8, (3 + 9)%9] -> [4, 8, 3]\n step3) [7, (8 + 3)%9, 6)] -> [7, 2, 6]\n step4) [(7 + 3)%9, 5, 9 ] -> [1, 5, 9] <==> step1\n\n \uadfc\ub370 \uc2dc\ubc1c \uc65c \uc774\uac8c \ub418\uc9c0?\n}\n\n"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tar=Array.new(n){}\n\tfor i in 0...n\n\t\tar[i]=\"\"\n\tend\n\tf=true\n\tj=1\n\ti=n*n\n\twhile(j<=i)\n\t\tif f\n\t\t\tfor k in 0...n\n\t\t\t\tar[k]+=j.to_s+\" \"\n\t\t\t\tj+=1\n\t\t\tend\n\t\telse\n\t\t\tfor k in 0...n\n\t\t\t\tl=n-k-1\n\t\t\t\tar[l]+=j.to_s+\" \"\n\t\t\t\tj+=1\n\t\t\tend\n\t\tend\n\t\tf=!f\n\tend\n\tfor i in 0...n\n\t\tputs ar[i]\n\tend\nend\nmain()"}, {"source_code": "n = gets.to_i\na = Array.new(n){|x| x += 1}\nn.times do |i|\n b = []\n n.times do |j|\n b << n * j + a[(i + j) % n]\n end\n puts b.join(\" \")\nend\n"}, {"source_code": "#16h26\nn = gets\n\ndef run(n)\n r = n*n\n q = n/2\n n.times do |i|\n st = i*q\n s = (1+st...q+1+st).to_a\n b = (r-q+1-st...r+1-st).to_a\n puts \"#{s.join(' ')} #{b.join(' ')}\"\n end\nend\n\nwhile n != nil\n run(n.to_i)\n n = gets\nend\n"}, {"source_code": "n=gets.to_i\nn.times do |i|\n n.times do |j|\n print(j*n+(j+i)%n+1, ' ')\n end\n puts\nend\n"}, {"source_code": "n = gets.to_i\nputs (n**2).times.map(&:next).each_slice(n).each_with_index.map{|x, i| x.rotate i }.transpose.map{|x| x.join ' ' }\n"}, {"source_code": "n = gets.to_i\nn2 = n**2\nn.times do |i|\n list = []\n (n/2).times do |j|\n list << i + 1 + j * n\n list << n2 - (i + j * n)\n end\n puts list.join(\" \")\nend\n"}], "negative_code": [{"source_code": "n=gets.to_i\na=[*1..n].each_slice(n).to_a.transpose\na[n/2..-1].map!(&:reverse)\nputs a.transpose.map{|e|e*' '}"}, {"source_code": "n=gets.to_i\na=[*1..n*n].each_slice(n).to_a.transpose\na[n/2..-1].map!(&:reverse)\nputs a.transpose.map{|e|e*' '}"}, {"source_code": "#http://codeforces.com/problemset/problem/129/A\n\nn = gets.to_i \n\ninitial_first = 1 \ninitial_last = n**2 \n\n\nfirst = []\nsecond = []\nn.times do \n first << initial_first \n first << initial_last \n initial_first += 2 \n initial_last -= 2 \nend \n\nsecond = first.shift(n) \n\nputs first.join(' ')\nputs second.join(' ')"}, {"source_code": "#http://codeforces.com/problemset/problem/129/A\n\nn = gets.to_i \n\ninitial_first = 1 \ninitial_last = n**2 \n\np initial_first \np initial_last\n\nfirst = []\nsecond = []\nn.times do \n first << initial_first \n first << initial_last \n initial_first += 2 \n initial_last -= 2 \nend \n\nsecond = first.shift(n) \n\nputs first.join(' ')\nputs second.join(' ')"}, {"source_code": "n = gets.to_i\n([(1..n/2).to_a] + [((n/2+1)..n).to_a.reverse]).transpose.each{|x| puts x.join(' ')}"}, {"source_code": "#16h26\nn = gets\n\ndef run(n)\n r = n*n\n q = n/2\n n.times do |i|\n s = (i+1...i+q+1).to_a\n b = (r-i-q+1...r-i+1).to_a\n puts \"#{s.join(' ')} #{b.join(' ')}\"\n end\nend\n\nwhile n != nil\n run(n.to_i)\n n = gets\nend\n"}], "src_uid": "0ac2a0954fe43d66eac32072c8ea5070"} {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nn = inp[0]\nt = inp\nm = na(2,0)\nm[0] = 0\nf = 0\nff = 0\npos = neg = 0\nt.each.with_index do |d,i|\n if(d < 0)\n m[0],m[1] = m[1],m[0]\n m[1] += 1\n else\n m[0] += 1\n end\n pos += m[0]\n neg += m[1]\nend\nputs \"#{neg} #{pos}\"", "positive_code": [{"source_code": "def number_of_products\n n = gets.chomp.to_i\n numbers = gets.chomp.split(\" \").map(&:to_i)\n positive, negative, a, b = 0, 0, 0, 0\n numbers.each do |num|\n c, d = 0, 0\n if num > 0\n c, d = a+1, b\n else\n c, d = b, a+1\n end\n a, b = c, d\n positive += c\n negative += d\n end\n puts \"#{negative} #{positive}\"\nend\n\nnumber_of_products\n"}], "negative_code": [], "src_uid": "78d3acc3ade53f488739a59100bfcebd"} {"source_code": "def number_of_steps(crt, target, step)\n ((target - crt).abs.to_f / step).ceil\nend\n\ndef exact_number_of_steps(crt, target, step)\n (target - crt).abs % step == 0 && number_of_steps(crt, target, step)\nend\n\ndef min_steps(max, crt, target, step)\n exact = exact_number_of_steps(crt, target, step)\n return exact if exact\n\n via_beginning = [number_of_steps(crt, 1, step), exact_number_of_steps(1, target, step)]\n via_end = [number_of_steps(crt, max, step), exact_number_of_steps(max, target, step)]\n\n possibilities = []\n possibilities << via_beginning[0] + via_beginning[1] if via_beginning[1]\n possibilities << via_end[0] + via_end[1] if via_end[1]\n\n possibilities.min || -1\n\nend\n\ndef solution\n test_cases = read_int\n\n test_cases.times do\n max, crt, target, step = read_ints\n puts min_steps(max, crt, target, step)\n end\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']", "positive_code": [{"source_code": "gets.to_i.times{\n\tn,x,y,d=gets.split.map &:to_i\n\tr = Float::INFINITY\n\t(y-1)%d==0 && r=[r,(x+d-2)/d+(y-1)/d].min\n\t(n-y)%d==0 && r=[r,(n+d-x-1)/d+(n-y)/d].min\n\t(y-x)%d==0 && r=[r,(y-x).abs/d].min\n\tp r.is_a?(Integer) ? r : -1\n}"}, {"source_code": "n = gets.strip.to_i\nres = []\nn.times do\n len, start, finish, per = gets.strip.split.map(&:to_i)\n\n if finish == start\n res << 0\n next\n end\n\n if (finish - start) % per == 0\n res << ((finish - start) / per).abs\n else\n from_start = (finish - 1) % per == 0\n from_end = (len - finish) % per == 0\n if from_start || from_end\n f_s = ((start.to_f/per).ceil + ((finish - 1) / per)).abs\n f_e = (((len - start).to_f / per).ceil + ((len - finish) / per)).abs\n r = 0\n if from_start && from_end\n if f_s > f_e\n r = f_e\n else\n r = f_s\n end\n else\n if from_start\n r = f_s\n else\n r = f_e\n end\n end\n r = 1 if r == 0\n res << r\n else\n res << -1\n end\n end\nend\n\nn.times do |x|\n p res[x]\nend\n"}, {"source_code": "gets.to_i.times do\n n,x,y,d=gets.split.map &:to_i\n if (x-y).abs%d==0\n puts (x-y).abs/d\n else\n a=nil\n a=(x-1+d-1)/d+(y-1+d-1)/d if (y-1)%d==0\n b=nil\n b=(n-x+d-1)/d+(n-y+d-1)/d if (n-y)%d==0\n if a && b\n puts [a, b].min\n elsif a\n puts a\n elsif b\n puts b\n else\n puts -1\n end\n end\nend\n"}, {"source_code": "t = gets.to_i\n\n1..t.times do\n n, start, fin, k = gets.split.map(&:to_i)\n \n if (fin-start) % k == 0 \n puts ((fin-start)/k).abs\n else\n ans = 9999999999\n if (fin-1)%k==0\n ans = (fin-1)/k + ((start-1)/k.to_f).ceil\n end\n \n if (n-fin)%k==0\n ans = [ans, (n-fin)/k + ((n-start)/k.to_f).ceil].min\n end\n \n if ans == 9999999999\n puts -1\n else\n puts ans\n end\n end\nend"}, {"source_code": "t = gets.to_i\nt.times do\n n, x, y, d = gets.split.map{|x| x.to_i}\n a = []\n a << ((y - x)/d).abs if (y - x)%d == 0\n a << (y - 1)/d + (x - 1 + d - 1)/d if (y - 1)%d == 0\n a << (n - y)/d + (n - x + d - 1)/d if (n - y)%d == 0\n puts(a.min || -1)\nend\n"}, {"source_code": "t = gets.to_i\n\nt.times do\n nxyd = gets.chomp.split(\" \").map(&:to_i)\n n = nxyd[0]\n x = nxyd[1]\n y = nxyd[2]\n d = nxyd[3]\n if (x%d==y%d)\n ans = (x-y).abs/d\n else\n if (y%d==1)\n ans = ((x.to_f-1)/d).ceil + ((y.to_f-1)/d).ceil\n if (n%d==1)\n ans = [ans,((n.to_f-x)/d).ceil+((n.to_f-y)/d).ceil].min\n end\n elsif (n%d==y%d)\n ans = ((n.to_f-x)/d).ceil+((n.to_f-y)/d).ceil\n else\n ans = -1\n end\n end\n\n puts ans\nend\n \n"}], "negative_code": [{"source_code": "t = gets.to_i\nt.times do\n n, x, y, d = gets.split.map{|x| x.to_i}\n a = []\n a << (y - x)/d if (y - x)%d == 0\n a << (y - 1)/d + (x - 1 + d - 1)/d if (y - 1)%d == 0\n a << (n - y)/d + (n - x + d - 1)/d if (n - y)%d == 0\n puts(a.min || -1)\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n, x, y, d = gets.split.map{|x| x.to_i}\n x, y = y, x if x > y\n a = []\n a << (y - x)/d if (y - x)%d == 0\n a << (y - 1)/d + (x - 1 + d - 1)/d if (y - 1)%d == 0\n a << (n - y)/d + (n - x + d - 1)/d if (n - y)%d == 0\n puts(a.min || -1)\nend\n"}, {"source_code": "t = gets.to_i\n\nt.times do\n nxyd = gets.chomp.split(\" \").map(&:to_i)\n n = nxyd[0]\n x = nxyd[1]\n y = nxyd[2]\n d = nxyd[3]\n if (x%d==y%d)\n ans = (x-y).abs/d\n else\n if (y%d==1)\n ans = ((x.to_f-1)/d).ceil + ((y.to_f-1)/d).ceil\n if (n%d==1)\n ans = [ans,((n.to_f-x)/d).ceil+((y.to_f-1)/d).ceil].min\n end\n elsif (n%d==y%d)\n ans = ((n.to_f-x)/d).ceil+((y.to_f-1)/d).ceil\n else\n ans = -1\n end\n end\n\n puts ans\nend\n \n"}, {"source_code": "gets.to_i.times{\n\tn,x,y,d=gets.split.map &:to_i\n\tr = Float::INFINITY\n\t(y-1)%d==0 && r=[r,(x+d-2)/d+(y-1)/d].min\n\t(n-y)%d==0 && r=[r,(x+d-x-1)/d+(n-y)/d].min\n\t(y-x)%d==0 && r=[r,(y-x).abs/d].min\n\tp r.is_a?(Integer) ? r : -1\n}"}, {"source_code": "n = gets.strip.to_i\nres = []\nn.times do\n len, start, finish, per = gets.strip.split.map(&:to_i)\n\n if finish == start\n res << 0\n next\n end\n\n if (finish - start) % per == 0\n res << ((finish - start) / per).abs\n else\n from_start = (finish - 1) % per == 0\n from_end = (len - finish) % per == 0\n if from_start || from_end\n f_s = ((finish.to_f/per).floor + ((finish - 1) / per)).abs\n f_e = (((len - start).to_f / per).ceil + ((len - finish) / per)).abs\n r = 0\n if from_start && from_end\n if f_s > f_e\n r = f_e\n else\n r = f_s\n end\n else\n if from_start\n r = f_s\n else\n r = f_e\n end\n end\n r = 1 if r == 0\n res << r\n else\n res << -1\n end\n end\nend\n\nn.times do |x|\n p res[x]\nend\n"}, {"source_code": "n = gets.strip.to_i\nres = []\nn.times do\n len, start, finish, per = gets.strip.split.map(&:to_i)\n if (finish - start) % per == 0\n res << ((finish - start) / per).abs\n else\n from_start = (finish - 1) % per == 0\n from_end = (len - finish) % per == 0\n if from_start || from_end\n f_s = ((finish.to_f/per).floor + ((finish - 1) / per)).abs\n f_e = (((len - start).to_f / per).ceil + ((len - finish) / per)).abs\n if from_start && from_end\n if f_s > f_e\n res << f_e\n else\n res << f_s\n end\n else\n if from_start\n res << f_s\n else\n res << f_e\n end\n end\n else\n res << -1\n end\n end\nend\n\nn.times do |x|\n r = res[x]\n r = 1 if r == 0\n p r\nend\n"}], "src_uid": "474f29da694929a64eaed6eb8e4349c3"} {"source_code": "# coding: utf-8\n\nn = gets.to_i\nad = {}\ngets.split.each { |i|\n i = i.to_i\n ad[i] ||= 0\n ad[i] += 1\n}\nsorted_keys = ad.keys.sort\n\nif ad.length <= 2\n puts \"0\"\nelse\n puts n - (ad[sorted_keys.first] + ad[sorted_keys.last])\nend\n", "positive_code": [{"source_code": "n,*a=$<.read.split.map &:to_i;p (a-a.minmax).size"}, {"source_code": "n = gets.chomp\narr= gets.split().map(&:to_i)\narr.sort! \nmin_val =arr.min \nmax_val = arr.max \ncount = 0 \narr.each{|i| if i>min_val and i max\nend\n\ncount = 0\n(stewards_map.keys - [min, max]).each do |v|\n count += stewards_map[v]\nend\n\nputs count\n"}], "negative_code": [{"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\n\narr=[]\nx.inject(x[0]){|e1,e2|\n\tarr<<(e2-e1).abs\n\te2\n}\nputs arr.count{|e| e==1}\n\n"}, {"source_code": "h=Hash.new(0)\nn=gets.to_i\nx=gets.split.map{|e| e.to_i}.sort\nx.each{|e|\n\th[e]+=1\n}\nx=h.to_a\nx.pop\nx.shift\np x.size\n\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}.sort\n\narr=[]\nx.inject(x[0]){|e1,e2|\n\tarr<<(e2-e1).abs\n\te2\n}\nputs arr.count{|e| e==1}\n\n"}, {"source_code": "h=Hash.new(0)\nn=gets.to_i\nx=gets.split.map{|e| e.to_i}.sort\nx.each{|e|\n\th[e]+=1\n}\nx=h.to_a\nans=0\nx.inject(x[0]){|e1,e2|\n\tif e1[0]+1==e2[0] then\n\t\tans+=e1[1]*e2[1]\n\tend\n\te2\n}\np ans\n\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nad = {}\ngets.split.each { |i|\n i = i.to_i\n ad[i] ||= 0\n ad[i] += 1\n}\n\nif ad.length - 2 <= 0\n puts \"0\"\nelse\n puts ad.length - 2\nend"}], "src_uid": "acaa8935e6139ad1609d62bb5d35128a"} {"source_code": "input_1 = gets.split.map(&:to_i)\ninput_2 = gets.split.map(&:to_i)\n\nb = input_1[0]\nk = input_1[1]\n\nb_flag = 0\nk_flag = 0\nodd_count = 0\n\nif b % 2 == 0\n b_flag = 0\nelse\n b_flag = 1\nend\n\nfor i in 0..k - 2 do\n if input_2[i] % 2 != 0\n odd_count += 1\n end\nend\n\nif b_flag == 0\n if input_2[k - 1] % 2 == 0\n puts \"even\"\n else\n puts \"odd\"\n end\nelse\n if odd_count % 2 == 0\n if input_2[k - 1] % 2 == 0\n puts \"even\"\n else\n puts \"odd\"\n end\n else\n if input_2[k - 1] % 2 == 0\n puts \"odd\"\n else\n puts \"even\"\n end\n end\nend\n", "positive_code": [{"source_code": "b,k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = 0\nif b%2 == 0\n ans ^= a[-1]%2\nelse\n for i in 0..k-1\n ans ^= a[i]%2\n end\nend\nputs (ans == 1 ? \"odd\" : \"even\")"}, {"source_code": "DBG = true\nb,k = gets.split.map{|z| z.to_i}\na = gets.split.map{|z| z.to_i}\nif b%2 == 0\n iseven = (a[-1]%2 == 0)\nelse\n iseven = (a.inject(:+)%2 == 0)\nend\nputs (iseven ? \"even\" : \"odd\")\n"}], "negative_code": [{"source_code": "input_1 = gets.split.map(&:to_i)\ninput_2 = gets.split.map(&:to_i)\n\nb = input_1[0]\nk = input_2[1]\n\nb_flag = 0\nk_flag = 0\nodd_count = 0\n\nif b % 2 == 0\n b_flag = 0\nelse\n b_flag = 1\nend\n\ninput_2.each do |num|\n if num % 2 != 0\n odd_count += 1\n end\nend\n\nif b_flag == 0\n puts \"even\"\nelse\n if odd_count % 2 == 0\n puts \"even\"\n else\n puts \"odd\"\n end\nend\n"}], "src_uid": "ee105b664099808143a94a374d6d5daa"} {"source_code": "def r()\n gets.split().map(&:to_i)\nend\na,b = r()\nq = gets.to_i\ng = a.gcd(b)\nd = []\ni = 1\nwhile i*i<=g do\n d+=[i, g/i] if g%i==0\n i+=1\nend\nd.sort!\nfor i in (0..q-1)\n l,r=r()\n a = d.reject{|e| e>r}[-1] \n a = -1 if ar}[-1] \n a = -1 if a=l\n print \"-1\\n\" if a n\n while n % i == 0\n n /= i\n f[i] += 1\n end\n d = 2\n end\n f[n] += 1 unless n == 1\n end.to_a\n\n [].tap do |ret|\n f = lambda do |i, r|\n if i == factors.size\n ret << r\n return\n end\n (factors[i][1] + 1).times do\n f.call(i + 1, r)\n r *= factors[i][0]\n end\n end\n f.call(0, 1)\n end\nend\n\na, b = gets.chomp.split.map{|s| s.to_i}\ncds = (divisors(a) & divisors(b)).sort\nret = []\ngets.to_i.times do\n result = -1\n r = gets.chomp.split.map{|s| s.to_i}\n min, max = 0, cds.size - 1\n n = r[1]\n while min <= max\n mid = (min + max) / 2\n if n == cds[mid]\n min = mid\n break\n elsif n < cds[mid]\n max = mid - 1\n else\n min = mid + 1\n end\n end\n i = min\n i -= 1 unless cds[i] == r[1]\n if cds[i] < r[0]\n ret << -1\n else\n ret << cds[i]\n end\nend\nret.each{|s| puts s}\n"}, {"source_code": "\ndef search(x,res)\n lb=-1\n ub=res.length\n while ub-lb>1\n mid=(ub+lb)>>1\n if res[mid]<=x then\n lb=mid\n else\n ub=mid\n end\n end\n return ub\nend\n\ninput=gets.split.map(&:to_i)\na=input.min\nb=input.max\n\nres=[]\nfor i in 1..a\n if i*i>a then\n break\n end\n if a%i ==0 then\n if b%i==0 then\n res.push(i)\n end\n end\nend\nfor i in 1..a\n if i*i>=a then\n break\n end\n if a%i ==0 then\n if b%(a/i)==0 then\n res.push(a/i)\n end\n end\nend\nres.sort!\n\n#p res\n#p search(2,res)\nq=gets.to_i\n(1..q).each{\n input=gets.split.map(&:to_i)\n x=res[search(input[1],res)-1]\n if x>=input[0] then\n puts x\n else\n puts -1\n end\n}\n"}], "negative_code": [{"source_code": "def factors(n)\n Hash.new(0).tap do |factors|\n d = 1\n 2.step(n, d).each do |i|\n next if i * i > n\n while n % i == 0\n n /= i\n factors[i] += 1\n end\n d = 2\n end\n factors[n] += 1 unless n == 1\n end.to_a\nend\n\ndef divisors(factors)\n [].tap do |ret|\n f = lambda do |i, r|\n if i == factors.size\n ret << r\n return\n end\n (factors[i][1] + 1).times do\n f.call(i + 1, r)\n r *= factors[i][0]\n end\n end\n f.call(0, 1)\n end\nend\n\ndef bsearch(array, n)\n min, max = 0, array.size - 1\n while min <= max\n mid = (min + max) / 2\n if n == array[mid]\n return mid\n elsif n < array[mid]\n max = mid - 1\n else\n min = mid + 1\n end\n end\n return min\nend\n\na, b = gets.chomp.split.map{|s| s.to_i}\ncds = divisors(factors(a)) & divisors(factors(b))\nret = []\ngets.to_i.times do\n result = -1\n r = gets.chomp.split.map{|s| s.to_i}\n i = bsearch(cds, r[1])\n i -= 1 unless cds[i] == r[1]\n if cds[i] < r[0]\n ret << -1\n else\n ret << cds[i]\n end\nend\nret.each{|s| puts s}\n"}, {"source_code": "require 'mathn'\na, b = gets.chomp.split.map{|s| s.to_i}\ndivisors = (2..[a,b].min).select do |i|\n a % i == 0 && b % i == 0\nend\nret = []\ngets.to_i.times do\n i = gets.chomp.split.map{|s| s.to_i}\n if n = divisors.detect{|d| (i[0]..i[1]).to_a.include?(d)}\n ret << n\n else\n ret << -1\n end\nend\nret.each{|i| puts i}\n"}, {"source_code": "def bsearch(array, n)\n min, max = 0, array.size - 1\n while min <= max\n mid = (min + max) / 2\n if n == array[mid]\n return mid\n elsif n < array[mid]\n max = mid - 1\n else\n min = mid + 1\n end\n end\n return min\nend\na, b = gets.chomp.split.map{|s| s.to_i}\ndivisors = [1]\n(2..(a > b ? b : a)).each do |i|\n divisors << i if a % i == 0 && b % i == 0\nend\nret = []\ngets.to_i.times do\n result = -1\n r = gets.chomp.split.map{|s| s.to_i}\n if divisors.last < r[0]\n elsif r[1] < divisors.first \n end\n i = bsearch(divisors, r[1])\n i -= 1\n if divisors[i] < r[0]\n ret << -1\n else\n ret << divisors[i]\n end\nend\nret.each{|i| puts i}\n"}], "src_uid": "6551be8f4000da2288bf835169662aa2"} {"source_code": "gets.to_i.times do\n\n n = gets.to_i\n arr = gets.chomp.split.map(&:to_i)\n\n res = 0\n m = n + n -1\n hs = Hash[(1..arr.length).zip arr].lazy.\n sort_by{|i, v| v}\n\n (0..m).each do |i|\n j = i+1\n e = m/hs[i][1]\n break if j >= n or hs[j][1] > e\n while j < n and hs[j][1] <= e\n res += 1 if hs[i][1]*hs[j][1] == hs[i][0] + hs[j][0]\n \n j += 1\n end\n end\n puts res\nend\n\n \t \t \t \t \t\t \t\t\t \t \t", "positive_code": [{"source_code": "t = gets.to_i\r\nt.times{ |x|\r\n n = gets.to_i\r\n res = 0\r\n m = n + n -1\r\n arr = gets.chomp.split(\" \").map(&:to_i)\r\n hs = Hash[(1..arr.length).zip arr].lazy.\r\n sort_by{|i, v| v}\r\n #p hs\r\n (0..m).each{ |i|\r\n j = i+1\r\n e = m/hs[i][1]\r\n #p j\r\n #p n\r\n #p j >= n\r\n break if j >= n or hs[j][1] > e\r\n while j < n and hs[j][1] <= e\r\n res += 1 if hs[i][1]*hs[j][1] == hs[i][0] + hs[j][0]\r\n\r\n j += 1\r\n end\r\n }\r\n puts res\r\n}"}], "negative_code": [], "src_uid": "0ce05499cd28f0825580ff48dae9e7a9"} {"source_code": "gets.to_i.times { puts ([1] * gets.to_i).join(' ') }\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\n#p n\nt.times do \n n = gets.chomp.to_i\n i = 0\n until n == i\n a = 1\n print a\n if i != n- 1\n print \" \"\n end\n i += 1\n end\n print \"\\n\"\nend\n"}, {"source_code": "t = gets.to_i \nt.times do \n\tn = gets.to_i \n\tputs \"1 \"*n \nend"}, {"source_code": "gets.to_i.times do\n res = \"\"\n gets.to_i.times do\n res += \"1 \"\n end\n puts res\nend"}], "negative_code": [], "src_uid": "f82058f6ba3ce0da15a5ce059674af35"} {"source_code": "n = gets.to_i\na = gets.chomp.split.map(&:to_i)\nb = a.sort\nif a == b\n puts \"YES\"\n exit\nend\ncount = 0\nn.times do |i|\n count +=1 if a[i] != b[i]\nend\nputs count == 2 ? \"YES\" : \"NO\"\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nb = a.sort\ns = 0\na.zip(b).each do |x, y|\n s += x != y ? 1 : 0\nend\nputs s > 2 ? \"NO\" : \"YES\""}, {"source_code": "n = gets.to_i\nar = gets.split.map(&:to_i)\nbr = ar.sort\n\ncnt = 0\nn.times do |i|\n\tcnt += 1 if ar[i] != br[i]\nend\n\nputs (cnt >2 ? \"NO\":\"YES\")\n\n"}, {"source_code": "STDIN.readline.to_i; numbers = STDIN.readline.split(' ').map { |x| x.to_i }\nsorted = numbers.sort\n\ncount = 0\nfor i in 0..sorted.length\n count += 1 if sorted[i] != numbers[i]\nend\n\nif count <= 2; puts \"YES\"; else puts \"NO\"; end\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nb=a.sort\npos=0\nn.times{|i|pos+=1 unless a[i]==b[i]}\nputs pos<3 ? \"YES\" : \"NO\""}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ncnt = 0\nfor i in 0..n - 1 do\n cnt += 1 if a[i] != b[i]\nend\nputs \"YES\" if cnt <= 2\nputs \"NO\" if cnt > 2\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn = $stdin.gets.to_i\na = $stdin.gets.chomp.split.map(&:to_i)\n\nc = a.zip(a.sort).count { |x, y| x != y }\nputs (c <= 2 ? 'YES' : 'NO')\n"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nc = 0\nsorted = arr.sort\narr.each_with_index do |a,i|\n\tc += 1 if a != sorted[i]\nend\nputs c <= 2 ? \"YES\" : \"NO\""}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\nb = a.sort\ncnt = 0\nfor i in 0...n\n if a[i] != b[i]\n cnt += 1\n end\nend\nif cnt <= 2\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn = $stdin.gets.to_i\na = $stdin.gets.chomp.split.map(&:to_i)\n\nc = a.zip(a.sort).count { |x, y| x != y }\nputs (c <= 2 ? 'YES' : 'NO')"}], "negative_code": [{"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nc = 0\narr.each_with_index do |a,i|\n\tc += 1 if a != (i + 1 )\nend\nputs c <= 2 ? \"YES\" : \"NO\""}], "src_uid": "541fde3a3c40926cbd1edb6017b83e52"} {"source_code": "n, m = gets.strip.split(' ').map(&:to_i)\n\na = []\n\nn.times do \n\ta << gets.strip.split(' ').map(&:to_i)\nend\n\nmax_till_now = 0\n\nmp = Hash.new(nil)\nbool = true\na.each do |x|\n\tmp[x[0]] = true\n\tmp[x[1]] = true\n\tif x[0] > max_till_now\n\t\tbool = false\n\t\tbreak\n\telse\n\t\tmax_till_now = [x[1], max_till_now].max \n\tend\nend\n\nif !bool\n\tputs 'NO'\nelse\n\tif mp[m]\n\t\tputs 'YES'\n\telse\n\t\tputs 'NO'\n\tend\nend", "positive_code": [{"source_code": "n,m=gets.split.map &:to_i\nlast=0\nn.times{\n\ta,b=gets.split.map &:to_i\n\tif a>last\n\t\tputs :NO\n\t\texit\n\telse\n\t\tlast=[b,last].max\n\t\tif last>=m\n\t\t\tputs :YES\n\t\t\texit\n\t\tend\n\tend\n}\nputs :NO"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\npos = 0\n\nfor i in 1..n\n st, en = gets.chomp.split.map(&:to_i)\n if st > pos\n puts \"NO\"\n exit 0\n else\n pos = [pos, en].max\n end\nend\n\nif pos >= m\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "#!/bin/ruby\n\nn, m = gets.strip.split(' ')\nn = n.to_i\nm = m.to_i\nvisiting = 'NO'\nps = 0\npd = 0\nfor i in (1..n)\n s, d = gets.strip.split(' ')\n s = s.to_i\n d = d.to_i\n if s.between? ps, pd\n ps = s\n pd = d if pd <= d\n if m.between? s, d\n visiting = 'YES'\n break\n end \n else\n visiting = 'NO'\n break\n end \nend\nputs visiting"}], "negative_code": [{"source_code": "#!/bin/ruby\n\nn, m = gets.strip.split(' ')\nn = n.to_i\nm = m.to_i\nvisiting = 'NO'\nps = 0\npd = 0\nfor i in (1..n)\n s, d = gets.strip.split(' ')\n s = s.to_i\n d = d.to_i\n if s.between? ps, pd\n ps = s\n pd = d\n if m.between? s, d\n visting = 'YES'\n break\n end \n else\n visting = 'NO'\n break\n end \nend\nputs visting"}, {"source_code": "#!/bin/ruby\n\nn, m = gets.strip.split(' ')\nn = n.to_i\nm = m.to_i\nvisiting = 'NO'\nps = 0\npd = 0\nfor i in (1..n)\n s, d = gets.strip.split(' ')\n s = s.to_i\n d = d.to_i\n if s.between? ps, pd\n ps = s\n pd = d\n if m.between? s, d\n visiting = 'YES'\n break\n end \n else\n visiting = 'NO'\n break\n end \nend\nputs visiting"}, {"source_code": "#!/bin/ruby\n\nn, m = gets.strip.split(' ')\nn = n.to_i\nm = m.to_i\nps = 0\npd = 0\nfor i in (1..n)\n s, d = gets.strip.split(' ')\n s = s.to_i\n d = d.to_i\n if s.between? ps, pd\n ps = s\n pd = d\n if m.between? s, d\n visting = 'YES'\n break\n end \n else\n visting = 'NO'\n break\n end \nend\nputs visting"}, {"source_code": "#!/bin/ruby\n\nn, m = gets.strip.split(' ')\nn = n.to_i\nm = m.to_i\nps = 0\npd = 0\nfor i in (1..n)\n s, d = gets.strip.split(' ')\n s = s.to_i\n d = d.to_i\n if pd.between? s, d\n pd = d\n if m.between? s, d\n visting = 'YES'\n break\n end \n else\n visting = 'NO'\n break\n end \nend\nputs visting"}, {"source_code": "n, m = gets.strip.split(' ').map(&:to_i)\n\na = []\n\nn.times do \n\ta << gets.strip.split(' ').map(&:to_i)\nend\n\nmax_till_now = a[0][0]\n\nmp = Hash.new(nil)\nbool = true\na.each do |x|\n\tmp[x[0]] = true\n\tmp[x[1]] = true\n\tif x[0] > max_till_now\n\t\tbool = false\n\t\tbreak\n\telse\n\t\tmax_till_now = [x[1], max_till_now].max \n\tend\nend\n\nif !bool\n\tputs 'NO'\nelse\n\tif mp[m]\n\t\tputs 'YES'\n\telse\n\t\tputs 'NO'\n\tend\nend"}, {"source_code": "n, m = gets.strip.split(' ').map(&:to_i)\n\na = []\n\nn.times do \n\ta << gets.strip.split(' ').map(&:to_i)\nend\n\nmax_till_now = a[0][0]\n\nmp = Hash.new(0)\nbool = true\na.each do |x|\n\tmp[x[0]] = true\n\tmp[x[1]] = true\n\tif x[0] > max_till_now\n\t\tbool = false\n\t\tbreak\n\telse\n\t\tmax_till_now = [x[1], max_till_now].max \n\tend\nend\n\n\nif !bool\n\tputs 'NO'\nelse\n\tif mp[m]\n\t\tputs 'YES'\n\telse\n\t\tputs 'NO'\n\tend\nend\n"}, {"source_code": "n, m = gets.strip.split(' ').map(&:to_i)\n\na = []\n\nn.times do \n\ta << gets.strip.split(' ').map(&:to_i)\nend\n\nmax_till_now = 0\n\nmp = Hash.new(0)\nbool = true\na.each do |x|\n\tmp[x[0]] = true\n\tmp[x[1]] = true\n\tif x[0] > max_till_now\n\t\tbool = false\n\t\tbreak\n\telse\n\t\tmax_till_now = [x[1], max_till_now].max \n\tend\nend\n\n\nif !bool\n\tputs 'NO'\nelse\n\tif mp[m]\n\t\tputs 'YES'\n\telse\n\t\tputs 'NO'\n\tend\nend\n"}], "src_uid": "d646834d58c519d5e9c0545df2ca4be2"} {"source_code": "copy = gets.chomp\nans = -1\nlast = copy[-1].to_i\n\n# if copy.length < 20\n# (0..(copy.length - 1)) do |i|\n# \tv = copy[i].to_i\n# \tif v.even? && v < last\t\t\n# \t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\tans = copy.to_i\n# \t\tbreak\n# \tend\n# end\n# if ans == -1\n# \t((copy.length - 1).downto(0)).each do |i|\n# \t\tv = copy[i].to_i\n# \t\tif v.even? && v > last\n# \t\t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\t\tans = copy.to_i\n# \t\t\tbreak\n# \t\tend\n# \tend\n# end\n# even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact\ncopy.each_char.with_index do |e,i|\n\tv = e.to_i\n\tnext if v.to_i.odd?\n\n\tif v < last\n\t\tans = i\n\t\tbreak\n\telse\n\t\tans = i\n\tend\nend\nif ans != -1\n\tcopy[ans],copy[-1] = copy[-1],copy[ans]\n\tans = copy\nend\nputs ans\n# else\n\n# \tcopy.each_char.with_index do |e,i|\n# \tv = e.to_i\n# \tnext if v.to_i.odd?\n\n# \tif v < last\n# \t\tans = i\n# \t\tbreak\n# \telse\n# \t\tans = i\n# \tend\n# \tend\n# \t# \n# \tputs copy[-1]\n# end", "positive_code": [{"source_code": "n = gets.strip\nif n.chars.all? {|x| x.to_i.odd?}\n\tputs -1\nelse\n\tm = n.chars.select{|x| x.to_i.even?}\n\ti = m.min > n[-1] ? n.rindex(m[-1]) : n.index(m.find{|x| x < n[-1]})\n\tn[i], n[-1] = n[-1] , n[i]\n\tputs n\nend\n\n"}, {"source_code": "n = gets.chomp\nif n.each_char.all?{|x| x.to_i.odd?}\n puts -1\nelse\n m = []\n n.each_char{|x| m << x if x.to_i.even?}\n i = if m.all?{|x| x > n[-1]}\n n.rindex(m[-1])\n else\n n.index(m.find{|x| x < n[-1]})\n end\n n[i], n[-1] = n[-1], n[i]\n puts n\nend\n"}, {"source_code": "a=gets.chomp.split('').map(&:to_i)\nn=a.length\ni,max,x=0,-1,-1\nwhile i n[-1]\n n.rindex(m[-1])\n else\n n.index(m.find{|x| x < n[-1]})\n end\n n[i], n[-1] = n[-1], n[i]\n puts n\nend\n"}, {"source_code": "a=gets.chomp\nt=-1\nmi=-10\n(a.length-2).downto(0) do |i|\nif a[i].to_i%2==0\nif t==-1 \nt=i\nnext\nend\nif a[i]=0\n\te=n[i].to_i\n\tif e%2==0 && e>last1 then\n\t\tp1=i\n\t\tbreak\n\tend\n\ti-=1\nend\n\nif p1!=-1 then\n\tn[p1],n[m]=n[m],n[p1]\n\tans=n if ansmax\n\t\t\t\t\tmax=m\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tfound=true\n\t\t\t\tif max==-1 || max>m\n\t\t\t\t\tmax=m\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\t$~=nil\n\t\ti+=2\n\tend\n\t#puts max\n\tputs s[0...max]+s[-1]+s[max+1...-1]+s[max]\nend\ns=gets.chomp.to_s\ncheck(s)"}, {"source_code": "# coding: utf-8\n\n# \ud55c \uc790\ub9ac\uc758 \uc22b\uc790(\ubc18\ub4dc\uc2dc \uc9dd\uc218) \uc640 \ub9c8\uc9c0\ub9c9 \uc790\ub9ac(\ubc18\ub4dc\uc2dc \ud640\uc218)\ub97c \uad50\uccb4\ud588\uc744 \ub54c\n# \uac00\uc7a5 \ud070 \uc22b\uc790\ub97c \ub9cc\ub4e4\uc5b4\ub77c\n# \ub2e8 \uc9dd\uc218\uac00 \uc5c6\uc5b4\uc11c \uc9dd\uc218\ub97c \ubabb\ub9cc\ub4e4\uba74 -1\n\n# Time limit: 0.5sec\n\n# ex) 2431 \ub77c\uba74\n# 1432 vs 2134 \uc774\uba74 \ub2f9\uc5f0\ud788 \ud6c4\uc790\uac00 \ub354 \ud06c\uaca0\uc9c0\n# ex) 2439 \ub77c\uba74\n# 9432 vs 2934 \uc774\uba74 \ub2f9\uc5f0\ud788 \uc804\uc790\uac00 \ub354 \ud06c\uc9c0\n# \uc989 \uad50\ud658\ud558\ub824\ub294 \ud640\uc218\uac00 \ud0c0\uac9f\ubcf4\ub2e4 \ud06c\ub2e4\uba74 \ucd5c\ub300\ud55c \uc55e\uc790\ub9ac\uc5d0 \uc788\ub294\uac8c \uc720\ub9ac\ud558\uace0(\uc22b\uc790\uac00 \ucee4\uc9d0)\n# \uad50\ud658\ud558\ub824\ub294 \ud640\uc218\uac00 \ud0c0\uac9f\ubcf4\ub2e4 \uc791\ub2e4\uba74 \ucd5c\ub300\ud55c \ub4b7\uc790\ub9ac\uc5d0\uc11c \ubc14\uafb8\ub294\uac8c \uc720\ub9ac\ud558\ub2e4\neven_indexes = []\nar = []\ngets.chomp.split(//).each_with_index { |i, index|\n i = i.to_i\n if i.even?\n even_indexes << index\n end\n ar << i\n}\n\nif even_indexes.empty?\n puts \"-1\"\nelse\n exchanged = false\n for i in even_indexes\n if ar[i] < ar[-1]\n ar[i], ar[-1] = ar[-1], ar[i]\n exchanged = true\n break\n end\n end\n\n if !exchanged\n last_even_index = even_indexes.last\n ar[last_even_index], ar[-1] = ar[-1], ar[last_even_index]\n end\n\n puts ar.join('')\nend\n"}, {"source_code": "copy = gets.chomp\nans = -1\nlast = copy[-1].to_i\n\n# if copy.length < 20\n# (0..(copy.length - 1)) do |i|\n# \tv = copy[i].to_i\n# \tif v.even? && v < last\t\t\n# \t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\tans = copy.to_i\n# \t\tbreak\n# \tend\n# end\n# if ans == -1\n# \t((copy.length - 1).downto(0)).each do |i|\n# \t\tv = copy[i].to_i\n# \t\tif v.even? && v > last\n# \t\t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\t\tans = copy.to_i\n# \t\t\tbreak\n# \t\tend\n# \tend\n# end\n# even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact\ncopy.each_char.with_index do |e,i|\n\tv = e.to_i\n\tnext if v.to_i.odd?\n\n\tif v < last\n\t\tans = i\n\t\tbreak\n\telse\n\t\tans = i\n\tend\nend\nif ans != -1\n\tcopy[ans],copy[-1] = copy[-1],copy[ans]\n\tans = copy\nend\nputs ans\n# else\n# \tcopy.each_char.with_index do |e,i|\n# \tv = e.to_i\n# \tnext if v.to_i.odd?\n\n# \tif v < last\n# \t\tans = i\n# \t\tbreak\n# \telse\n# \t\tans = i\n# \tend\n# \tend\n# \t# \n# \tputs copy[-1]\n# end"}, {"source_code": "n = gets.chomp\nl = n.size\n\n( l - 1 ).times do | i |\n\td = n[i].to_i\n\tif d.odd?\n\t\tnext\n\tend\n\n\tif d < n[ l - 1 ].to_i\n\t\ts = String.new( n )\n\t\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\t\tputs s\n\t\texit\n\tend\nend\n\n( l - 2 ).downto( 0 ) do | i |\n\td = n[i].to_i\n\tif d.odd?\n\t\tnext\n\tend\n\n\ts = String.new( n )\n\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\tputs s\n\texit\nend\n\nputs -1\n"}], "negative_code": [{"source_code": "n = gets\nl = n.size\n\np l\n\n( l - 1 ).times do | i |\n\td = n[i].to_i\n\tif d.odd?\n\t\tnext\n\tend\n\n\tif d < n[ l - 1 ].to_i\n\t\ts = String.new( n )\n\t\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\t\tputs s\n\t\texit\n\tend\nend\n\n( l - 2 ).downto( 0 ) do | i |\n\td = n[i].to_i\n\tif d.odd?\n\t\tnext\n\tend\n\n\ts = String.new( n )\n\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\tputs s\n\texit\nend\n\nputs -1\n"}, {"source_code": "n = gets\nl = n.size\n\n( l - 1 ).times do | i |\n\td = n[i].to_i\n\tif d.odd?\n\t\tnext\n\tend\n\n\tif d < n[ l - 1 ].to_i\n\t\ts = String.new( n )\n\t\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\t\tputs s\n\t\texit\n\tend\nend\n\n( l - 2 ).downto( 0 ) do | i |\n\td = n[i].to_i\n\tif d.odd?\n\t\tnext\n\tend\n\n\ts = String.new( n )\n\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\tputs s\n\texit\nend\n\nputs -1\n"}, {"source_code": "n = gets\nl = n.size\n\nl.times do | i |\n\td = n[i].to_i\n\tif d.odd?\n\t\tnext\n\tend\n\n\tif d < n[ l - 1 ].to_i\n\t\ts = String.new( n )\n\t\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\t\tputs s\n\t\texit 0\n\tend\nend\n\n( l - 2 ).downto( 0 ) do | i |\n\td = n[i].to_i\n\tif d.odd?\n\t\tnext\n\tend\n\n\ts = String.new( n )\n\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\tputs s\n\texit 0\nend\n\n\nputs -1\n"}, {"source_code": "n = gets\nl = n.size\n\nl.times do | i |\n\td = n[i].to_i\n\tif d.odd?\n\t\tnext\n\tend\n\n\tif d < n[ l - 1 ].to_i\n\t\ts = String.new( n )\n\t\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\t\tprint s\n\t\texit 0\n\tend\nend\n\n( l - 2 ).downto( 0 ) do | i |\n\td = n[i].to_i\n\tif d.odd?\n\t\tnext\n\tend\n\n\ts = String.new( n )\n\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\tprint s\n\texit 0\nend\n\nprint -1\n"}, {"source_code": "n = gets\nl = n.size\n\nres = -1\n\nl.times do | i |\n\ts = String.new( n )\n\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\n\tif s.to_i.even?\n\t\tres = [ res, s.to_i ].max\n\tend\nend\n\nputs res\n"}, {"source_code": "n = gets\nl = n.size\n\nres = -1\nl.times do | i |\n\ts = String.new( n )\n\ts[i], s[ l - 1 ] = s[ l - 1 ], s[i]\n\n\tm = s.to_i\n\tif m.even?\n\t\tres = [ res, m ].max\n\tend\nend\nputs res\n"}, {"source_code": "n = gets.strip\nnumbers = n.split(\"\").map {|i| i.to_i}\neven = numbers.select {|n| n.even?}\nmax = 0\nlast_index = numbers.size - 1\neven.each do |number|\n\teven_index = numbers.index(number)\n\ttemp = numbers[even_index]\n\tnumbers[even_index] = numbers[last_index]\n\tnumbers[last_index] = temp\n\tcurrent = numbers.join(\"\").to_i\n\tif (current > max)\n\t\tmax = current\n\tend\n\ttemp = numbers[even_index]\n\tnumbers[even_index] = temp\n\tnumbers[last_index] = temp\nend\nif even.size == 0\n\tputs -1\nelse\n\tputs max\nend\n\n"}, {"source_code": "n = gets.strip\nnumbers = n.split(\"\").map {|i| i.to_i}\nnumbers2 = numbers.map do |e| e end\neven = numbers.select {|n| n.even?}\nmax = 0\ni = -1\nj = -1\nlast_index = numbers.size - 1\n\nnumbers.each_with_index do |number, index|\n\tif (number.even? && number < numbers[last_index])\n\t\ti = index\n\t\tbreak\n\tend\nend\n\nnumbers.reverse.each_with_index do |number, index|\n\tif (number.even? && number >= numbers[last_index])\n\t\tj = numbers.size - index - 1\n\t\tbreak\n\tend\nend\nputs j\nif even.size == 0\n\tputs -1\nelsif (i != -1)\n\ttemp = numbers[last_index]\n\tnumbers[last_index] = numbers[i]\n\tnumbers[i] = temp\n\tputs numbers.join(\"\").to_i\nelsif (j != -1)\n\ttemp = numbers[last_index]\n\tnumbers[last_index] = numbers[j]\n\tnumbers[j] = temp\n\tputs numbers.join(\"\").to_i\nend\n\n"}, {"source_code": "a=gets.chomp\nt=-1\nmi=-10\n(a.length-2).downto(0) do |i|\nif a[i].to_i%2==0 && a[a.length-1].to_i-a[i].to_i>=mi \nt=i\nmi=a[a.length-1].to_i-a[i].to_i\nend\nend\n\nif t==-1\nputs \"-1\"\nelse\nmi=a[a.length-1]\na[a.length-1]=a[t]\na[t]=mi\nputs a\nend\n"}, {"source_code": "a=gets.chomp\nt=-1\nmi=-10\n(a.length-2).downto(0) do |i|\nif a[i].to_i%2==0 && a[a.length-1].to_i-a[i].to_i>mi \nt=i\nmi=a[a.length-1].to_i-a[i].to_i\nend\nend\n\nif t==-1\nputs \"-1\"\nelse\nmi=a[a.length-1]\na[a.length-1]=a[t]\na[t]=mi\nputs a\nend\n"}, {"source_code": "n=gets.chomp\nm=n.size-1\n\nans=-1\ni=0\n\nh={}\nh2={}\n[\"0\",\"2\",\"4\",\"6\",\"8\"].each{|e| h[e]=0}\n[\"0\",\"2\",\"4\",\"6\",\"8\"].each{|e| h2[e]=0}\nn.chars{|e|\n\tif e.to_i%2==0 && e=0\n\te=n[i]\n\tif e.to_i%2==0 && e>n[m] && h2[e]==0 then\n\t\th2[e]==1\n\t\tn[i],n[m]=n[m],n[i]\n\t\tif n.to_i%2==0 && n[0]!=\"0\" then\n\t\t\tans=n.to_i if ansmax\n\t\t\t\t\tmax=m\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tfound=true\n\t\t\t\tif max==-1 || max>m\n\t\t\t\t\tmax=m\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\t$~=nil\n\t\ti+=2\n\tend\n\tputs s[0...max]+s[-1]+s[max+1...-1]+s[max]\nend\ns=gets.chomp.to_s\ncheck(s)"}, {"source_code": "def check(s)\n\tunless s=~/[02468]/\n\t\treturn \"-1\"\n\tend\n\ti=0\n\tflag=false\n\thold=s[-1].to_i\n\twhile true && i<=8\n\t\tif imax\n\t\t\t\t\tmax=m\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tfound=true\n\t\t\t\tif max==-1 || max>m\n\t\t\t\t\tmax=m\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\t$~=nil\n\t\ti+=2\n\tend\n\t#puts max\n\tputs s[0...max]+s[-1]+s[max+1...-1]+s[max]\nend\ns=gets.chomp.to_s\ncheck(s)"}, {"source_code": "def check(s)\n\tunless s=~/[02468]/\n\t\treturn \"-1\"\n\tend\n\ti=0\n\ts=s.reverse\n\twhile true && i<=8\n\t\tm=s=~/#{i}/\n\t\tif $~\n\t\t\ty=s[m]+s[1...m]+s[0]+s[m+1..-1]\n\t\t\treturn y.reverse\n\t\tend\n\t\t$~=nil\n\t\ti+=2\n\tend\nend\ns=gets.chomp.to_s\nhold=check(s)\nif hold!='-1'\n\tputs hold\nelse\n\tputs \"-1\"\nend"}, {"source_code": "copy = gets.chomp\nans = -1\nlast = copy[-1].to_i\nif copy.length < 20\n# (0..(copy.length - 1)) do |i|\n# \tv = copy[i].to_i\n# \tif v.even? && v < last\t\t\n# \t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\tans = copy.to_i\n# \t\tbreak\n# \tend\n# end\n# if ans == -1\n# \t((copy.length - 1).downto(0)).each do |i|\n# \t\tv = copy[i].to_i\n# \t\tif v.even? && v > last\n# \t\t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\t\tans = copy.to_i\n# \t\t\tbreak\n# \t\tend\n# \tend\n# end\n# even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact\ncopy.each_char.with_index do |e,i|\n\tv = e.to_i\n\tnext if v.to_i.odd?\n\n\tif v < last\n\t\tans = i\n\t\tbreak\n\telse\n\t\tans = i\n\tend\nend\nif ans != -1\n\tcopy[ans],copy[-1] = copy[-1],copy[ans]\n\tans = copy.to_i\nend\nputs ans\nelse\n\tputs copy[-1]\nend"}, {"source_code": "copy = gets.chomp\nans = -1\nlast = copy[-1].to_i\nif copy.length < 20\n# (0..(copy.length - 1)) do |i|\n# \tv = copy[i].to_i\n# \tif v.even? && v < last\t\t\n# \t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\tans = copy.to_i\n# \t\tbreak\n# \tend\n# end\n# if ans == -1\n# \t((copy.length - 1).downto(0)).each do |i|\n# \t\tv = copy[i].to_i\n# \t\tif v.even? && v > last\n# \t\t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\t\tans = copy.to_i\n# \t\t\tbreak\n# \t\tend\n# \tend\n# end\n# even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact\ncopy.each_char.with_index do |e,i|\n\tv = e.to_i\n\tnext if v.to_i.odd?\n\n\tif v < last\n\t\tans = i\n\t\tbreak\n\telse\n\t\tans = i\n\tend\nend\nif ans != -1\n\tcopy[ans],copy[-1] = copy[-1],copy[ans]\n\tans = copy.to_i\nend\nputs ans\nelse\n\tcopy.each_char.with_index do |e,i|\n\tv = e.to_i\n\tnext if v.to_i.odd?\n\n\tif v < last\n\t\tans = i\n\t\tbreak\n\telse\n\t\tans = i\n\tend\n\tend\n\tputs copy[-1]\nend"}, {"source_code": "copy = gets.chomp\nans = -1\nlast = copy[-1].to_i\nif copy.length < 20\n# (0..(copy.length - 1)) do |i|\n# \tv = copy[i].to_i\n# \tif v.even? && v < last\t\t\n# \t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\tans = copy.to_i\n# \t\tbreak\n# \tend\n# end\n# if ans == -1\n# \t((copy.length - 1).downto(0)).each do |i|\n# \t\tv = copy[i].to_i\n# \t\tif v.even? && v > last\n# \t\t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\t\tans = copy.to_i\n# \t\t\tbreak\n# \t\tend\n# \tend\n# end\n# even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact\ncopy.each_char.with_index do |e,i|\n\tv = e.to_i\n\tnext if v.to_i.odd?\n\n\tif v < last\n\t\tans = i\n\t\tbreak\n\telse\n\t\tans = i\n\tend\nend\nif ans != -1\n\tcopy[ans],copy[-1] = copy[-1],copy[ans]\n\tans = copy.to_i\nend\nputs ans\nelse\n\tcopy.each_char.with_index\n\tputs copy[-1]\nend"}, {"source_code": "n = gets.to_i\nans = -1\ncopy = n.to_s\nlast = copy[-1].to_i\n# (0..(copy.length - 1)) do |i|\n# \tv = copy[i].to_i\n# \tif v.even? && v < last\t\t\n# \t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\tans = copy.to_i\n# \t\tbreak\n# \tend\n# end\n# if ans == -1\n# \t((copy.length - 1).downto(0)).each do |i|\n# \t\tv = copy[i].to_i\n# \t\tif v.even? && v > last\n# \t\t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\t\tans = copy.to_i\n# \t\t\tbreak\n# \t\tend\n# \tend\n# end\neven_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact\neven_nos.each do |e|\n\tif e[0] < last\n\t\tcopy[e[1]],copy[-1] = copy[-1],copy[e[1]]\n\t\tans = copy.to_i\n\t\tbreak\n\tend\nend\n\neven_nos.reverse_each do |e|\n\tif e[0] > last\n\t\tcopy[e[1]],copy[-1] = copy[-1],copy[e[1]]\n\t\tans = copy.to_i\n\t\tbreak\n\tend\nend\n\nputs ans"}, {"source_code": "copy = gets.chomp\nans = -1\nlast = copy[-1].to_i\nif copy.length < 20\n# (0..(copy.length - 1)) do |i|\n# \tv = copy[i].to_i\n# \tif v.even? && v < last\t\t\n# \t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\tans = copy.to_i\n# \t\tbreak\n# \tend\n# end\n# if ans == -1\n# \t((copy.length - 1).downto(0)).each do |i|\n# \t\tv = copy[i].to_i\n# \t\tif v.even? && v > last\n# \t\t\tcopy[i],copy[-1] = copy[-1],copy[i]\n# \t\t\tans = copy.to_i\n# \t\t\tbreak\n# \t\tend\n# \tend\n# end\n# even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact\ncopy.each_char.with_index do |e,i|\n\tv = e.to_i\n\tnext if v.to_i.odd?\n\n\tif v < last\n\t\tans = i\n\t\tbreak\n\telse\n\t\tans = i\n\tend\nend\nif ans != -1\n\tcopy[ans],copy[-1] = copy[-1],copy[ans]\n\tans = copy.to_i\nend\nputs ans\nelse\n\tcopy.each_char.with_index do |e,i|\n\tv = e.to_i\n\tnext if v.to_i.odd?\n\n\tif v < last\n\t\tans = i\n\t\tbreak\n\telse\n\t\tans = i\n\tend\n\tend\n\t# \n\tputs copy[-1]\nend"}, {"source_code": "n = gets.chomp\nif n.each_char.all?{|x| x.to_i.odd?}\n puts -1\nelse\n i = n.index(n.each_char.find{|x| x.to_i.even?})\n n[i], n[-1] = n[-1], n[i]\n puts n\nend\n"}, {"source_code": "n = gets.chomp\nif n.each_char.all?{|x| x.to_i.odd?}\n puts -1\nelse\n m = []\n n.each_char{|x| m << x if x.to_i.even?}\n i = if m[0] < n[-1]\n n.index(m[0])\n else\n n.rindex(m.min)\n end\n n[i], n[-1] = n[-1], n[i]\n puts n\nend\n"}, {"source_code": "n = gets.chomp\nif n.each_char.all?{|x| x.to_i.odd?}\n puts -1\nelse\n m = []\n n.each_char{|x| m << x if x.to_i.even?}\n i = if m.min > n[-1]\n n.rindex(m.min)\n else\n n.index(m.min)\n end\n n[i], n[-1] = n[-1], n[i]\n puts n\nend\n"}, {"source_code": "n = gets.chomp\nif n.each_char.all?{|x| x.to_i.odd?}\n puts -1\nelse\n m = []\n n.each_char{|x| m << x if x.to_i.even?}\n i = n.rindex(m.min)\n n[i], n[-1] = n[-1], n[i]\n puts n\nend\n"}, {"source_code": "n = gets.chomp\nif n.each_char.all?{|x| x.to_i.odd?}\n puts -1\nelse\n m = []\n n.each_char{|x| m << x if x.to_i.even?}\n i = if m.all?{|x| x < n[-1]}\n n.index(m.find{|x| x < n[-1]})\n else\n n.index(m.min)\n end\n n[i], n[-1] = n[-1], n[i]\n puts n\nend\n"}, {"source_code": "n = gets.chomp\nif n.each_char.all?{|x| x.to_i.odd?}\n puts -1\nelse\n m = []\n n.each_char{|x| m << x if x.to_i.even?}\n i = if m.all?{|x| x < n[-1]}\n n.index(m.find{|x| x < n[-1]})\n else\n n.rindex(m.min)\n end\n n[i], n[-1] = n[-1], n[i]\n puts n\nend\n"}, {"source_code": "a=Array.new\nstr=gets.to_s\na=str.split(\"\")\nh=0\nfor i in 0..a.length-1\n if a[i].to_i>0 and a[i].to_i%2==0\n# a[-1] \u5b57\u7b26\u4e32\u6700\u540e\u4e00\u822c\u662f\u6362\u884c\u7b26\uff0c\u53ef\u7528chomp\u65b9\u6cd5\u53bb\u9664\n# puts a[-2]\n t=a[-2]\n a[-2]=a[i]\n a[i]=t\n h=1\n break\n end\nend\nif h==1\n for i in 0..a.length-1\n print a[i].chomp\n end\n puts\nelsif h==0\n puts -1\nend"}], "src_uid": "bc375e27bd52f413216aaecc674366f8"} {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n s = gets.chomp\r\n t = gets.chomp\r\n\r\n if s.count('b') != t.count('b')\r\n puts 'NO'\r\n next\r\n end\r\n\r\n j = 0\r\n ok = true\r\n n.times do |i|\r\n next if s[i] == 'b'\r\n\r\n while t[j] == 'b'\r\n j += 1\r\n end\r\n\r\n if s[i] != t[j] || (s[i] == 'a' && i > j) || (s[i] == 'c' && i < j)\r\n ok = false\r\n break\r\n end\r\n j += 1\r\n \r\n end\r\n puts ok ? 'YES' : 'NO'\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n s = gets.chomp.chars.to_a\r\n t = gets.chomp.chars.to_a\r\n si, ti = s.zip(0..), t.zip(0..)\r\n sa = si.filter_map { |c, i| i if c == \"a\" }\r\n sc = si.filter_map { |c, i| i if c == \"c\" }\r\n ta = ti.filter_map { |c, i| i if c == \"a\" }\r\n tc = ti.filter_map { |c, i| i if c == \"c\" }\r\n ok = s.select { |c| c != \"b\" } == t.select { |c| c != \"b\" } &&\r\n sa.zip(ta).all? { |x, y| x <= y } &&\r\n sc.zip(tc).all? { |x, y| x >= y }\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n s = gets.chomp.chars.to_a\r\n t = gets.chomp.chars.to_a\r\n si, ti = s.zip(0..), t.zip(0..)\r\n sa = si.filter_map { |c, i| i if c == \"a\" }\r\n sc = si.filter_map { |c, i| i if c == \"c\" }\r\n ta = ti.filter_map { |c, i| i if c == \"a\" }\r\n tc = ti.filter_map { |c, i| i if c == \"c\" }\r\n ok = s.select { |c| c != \"b\" } == t.select { |c| c != \"b\" } && (sa <=> ta) <= 0 && (sc <=> tc) >= 0\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n s = gets.chomp.chars.to_a\r\n t = gets.chomp.chars.to_a\r\n si, ti = s.zip(0..), t.zip(0..)\r\n sa = si.filter_map { |c, i| i if c == \"a\" }\r\n sb = si.filter_map { |c, i| i if c == \"b\" }\r\n sc = si.filter_map { |c, i| i if c == \"c\" }\r\n ta = ti.filter_map { |c, i| i if c == \"a\" }\r\n tb = ti.filter_map { |c, i| i if c == \"b\" }\r\n tc = ti.filter_map { |c, i| i if c == \"c\" }\r\n ok = sa.count == ta.count && sb.count == tb.count && sc.count == tc.count && (sa <=> ta) <= 0 && (sc <=> tc) >= 0\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n"}], "src_uid": "235ddb32dbe19c0da1f77069e36128bb"} {"source_code": "#!/usr/bin/env ruby\n\nclass Main\n attr_reader :computer_count, :student_count, :array\n\n def initialize(computer_count, student_count, array)\n @computer_count = computer_count\n @student_count = student_count\n @array = array.sort.reverse\n end\n\n def run\n array[student_count - 1]\n end\nend\n\ncomputer_count, student_count = gets.split(\" \")\narray = gets.split(\" \")\nputs Main.new(computer_count.to_i, student_count.to_i, array.map(&:to_i)).run\n", "positive_code": [{"source_code": "n,k = gets.split(' ').map(&:to_i)\n\na = gets.split(' ').map(&:to_i).sort.reverse\n\nputs a[k-1]"}, {"source_code": "n, m = gets.split\na = gets.split.map{|i|i.to_i}.sort\nprint a[-m.to_i]"}, {"source_code": "# https://codeforces.com/problemset/problem/412/B\n\ninput = gets.split(' ').map(&:to_i)\ntransfer_speed_table = gets.split(' ').map(&:to_i)\n\nk = input[1]\n\ntransfer_speed_table.sort! { |a, b| b <=> a }\n\nputs transfer_speed_table[k-1]\n"}, {"source_code": "nk = gets.split(' ')\nn = nk[0].to_i\nk = nk[1].to_i\nai = gets.split(' ').map!{ |el| el.to_i }\nai = ai.sort.reverse\nputs ai[k-1]\n"}], "negative_code": [], "src_uid": "6eca08d7cc2dec6f4f84d3faa9a8a915"} {"source_code": "n = gets.to_i\nab = n.pred.times.map {gets.split.map(&:to_i).map(&:pred)}\ncnt = Array.new(n, 0)\nab.each do |a, b|\n\tcnt[a] += 1\n\tcnt[b] += 1\nend\n\npos = cnt.index {|c| c >= 3}\nans = Array.new(n.pred, -1)\nif pos\n\tx = 0\n\tn.pred.times do |i|\n\t\tif ab[i].index(pos) && x < 3\n\t\t\tans[i] = x\n\t\t\tx += 1\n\t\tend\n\tend\n\tn.pred.times do |i|\n\t\tif ans[i] == -1\n\t\t\tans[i] = x;\n\t\t\tx += 1\n\t\tend\n\tend\nelse\n\tans = (0...n.pred).to_a\nend\nputs ans.join(\"\\n\")", "positive_code": [{"source_code": "n = gets.to_i\nab = n.pred.times.map {gets.split.map(&:to_i).map(&:pred)}\ncnt = Array.new(n, 0)\nab.each{|a| a.each{|i| cnt[i] += 1}}\nans = Array.new(n.pred, -1)\nif (pos = cnt.index{|c| c >= 3})\n\t(0...n.pred).to_a.select{|i| ab[i].index(pos)}.take(3).each_with_index{|i, x| ans[i] = x}\n\t(0...n.pred).to_a.select{|i| ans[i] == -1}.each_with_index{|i, x| ans[i] = x + 3}\nelse\n\tans = (0...n.pred).to_a\nend\nputs ans.join(\"\\n\")"}], "negative_code": [], "src_uid": "5ef966b7d9fbf27e6197b074eca31b15"} {"source_code": "gets.to_i.times{n,a=gets.to_i,gets.split.map(&:to_i).sort;p (0..n-2).count{|i|a[i]+1==a[i+1]}>0?2:1}\n", "positive_code": [{"source_code": "gets.to_i.times{\n n=gets.to_i\n a=gets.split.map(&:to_i).sort\n p (0...n-1).count{|i|a[i]+1==a[i+1]}>0 ? 2 : 1\n}"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n as = gets.split.map(&:to_i).sort\n flg = false\n (0..n-2).each do |i|\n flg = true if (as[i] - as[i+1]).abs == 1\n end\n puts flg ? 2 : 1\nend\n"}, {"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\nn = inp[0]\nn.times do\n q = inp[0]\n st = inp\n mae = -9\n ans = 1\n st.sort!\n st.each do |d|\n if(d - mae == 1)\n ans = 2\n break\n end\n mae = d\n end\n puts ans\n \nend"}, {"source_code": "q = gets.to_i\nq.times do\n n = gets.to_i\n a = gets.split.map(&:to_i).sort\n nteams, nused, used = 0, 0, []\n while nused < n\n i = 0\n t = nil\n while i < n\n if not used[i] and (not t or (a[i] - t).abs > 1)\n t = a[i]\n nused += 1\n used[i] = true\n end\n i += 1\n end\n nteams += 1\n end\n puts nteams\nend\n"}, {"source_code": "n = readline.to_i\nn.times do |i|\n m = readline.to_i\n a = readline.to_s.split\n ni = []\n a.each {|ite|\n ni.push(ite.to_i)\n }\n ni = ni.sort\n last = ni[0]\n ch = 0\n ni.each { |ite |\n if (ite - last).abs == 1\n ch = 1\n break\n end\n last = ite\n }\n if ch == 1\n puts 2\n else\n puts 1\n end\nend\n"}], "negative_code": [{"source_code": "q = gets.to_i\nq.times do\n n = gets.to_i\n a = gets.split.map &:to_i\n nteams, nused, used = 0, 0, []\n while nused < n\n i = 0\n t = nil\n while i < n\n if not used[i] and (not t or (a[i] - t).abs > 1)\n t = t || a[i]\n nused += 1\n used[i] = true\n end\n i += 1\n end\n nteams += 1\n end\n puts nteams\nend\n"}], "src_uid": "dd2cd365d7afad9c2b5bdbbd45d87c8a"} {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = \"\"\n b = \"\"\n diff = false\n x = gets.chomp\n for i in 0..n-1\n if x[i] == \"2\"\n if diff\n a << \"0\"\n b << \"2\"\n else\n a << \"1\"\n b << \"1\"\n end\n elsif x[i] == \"1\"\n if diff\n a << \"0\"\n b << \"1\"\n else\n a << \"1\"\n b << \"0\"\n diff = true\n end\n else\n a << \"0\"\n b << \"0\"\n end\n end\n puts a\n puts b\nend", "positive_code": [{"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ts = gets.split('').map(&:to_i)\n\ta = Array.new(0, n)\n\tb = Array.new(0, n)\n\t\n\tflag = false\n\tn.times do |i|\n\t\tif flag\n\t\t\ta[i] = 0\n\t\t\tb[i] = s[i]\n\t\telse\n\t\t\ta[i] = (s[i] + 1) / 2\n\t\t\tb[i] = s[i] / 2\n\t\t\tflag = true if a[i] != b[i]\n\t\tend\n\tend\n\tputs a.join('')\n\tputs b.join('')\nend"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nt = gets.to_i\nt.times {\n len = gets.to_i\n tnr = gets.chomp\n a = []\n b = []\n a_equals_b = true\n for i in 0...len\n case tnr[i]\n when '2' # how to split 2? (2, 0), (1, 1), (0, 2)\n if a_equals_b == true\n a << 1\n b << 1\n else\n a << 0\n b << 2\n end\n when '1' # where to increase one?\n if a_equals_b == true\n a << 1\n b << 0\n a_equals_b = false\n else\n a << 0\n b << 1\n end\n when '0' # nothing to do\n a << 0\n b << 0\n else\n raise Exception.new(\"should not reach here\")\n end\n end\n\n puts a.join('')\n puts b.join('')\n}"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n x = gets.chomp\n a = []\n b = []\n diff = false\n x.each_char do |c|\n case c\n when \"0\"\n a.push(\"0\")\n b.push(\"0\")\n when \"1\"\n if diff\n a.push(\"0\")\n b.push(\"1\")\n else\n a.push(\"1\")\n b.push(\"0\")\n diff = true\n end\n when \"2\"\n if diff\n a.push(\"0\")\n b.push(\"2\")\n else\n a.push(\"1\")\n b.push(\"1\")\n end\n end\n end\n puts a.join\n puts b.join\nend\n"}, {"source_code": "1.upto(gets.to_i) do\n n = gets.to_i\n s = gets.chomp\n\n pos = s.index('1')\n beg = s[0, pos ? pos : s.size ].chars.map { |c| c == '2' ? '1' : '0' }.join\n\n if pos\n puts beg + '1' + '0' * (n - pos - 1)\n puts beg + '0' + s[pos+1, n - pos - 1]\n else\n puts beg\n puts beg\n end\n\n next\n\n odd = false\n result = ['', '']\n gets.chomp.chars.each_with_index do |char, idx|\n if odd\n result[1] += char\n next\n end\n\n case char\n when '2'\n result.map! { |s| s + '1' }\n when '1'\n result[0] += '1' + '0' * (n - idx - 1)\n result[1] += '0'\n odd = true\n when '0'\n result.map! { |s| s + '0' }\n end\n end\n\n result.each { |s| puts s }\nend\n"}, {"source_code": "t = gets.to_i\n(1..t).each do\n n = gets.to_i\n s = gets.split('')\n b = false\n s.each do |c|\n if c==\"\\n\"\n break\n end\n if b\n print '0'\n else\n print c.to_i/2+c.to_i.modulo(2)\n end\n if c=='1'\n b=true\n end\n end\n print \"\\n\"\n b=false\n s.each do |c|\n if c==\"\\n\"\n break\n end\n if b\n print c\n else\n print c.to_i/2\n end\n if c=='1'\n b=true\n end\n end\n print \"\\n\"\nend\n"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = \"\"\n b = \"\"\n\n x = gets.chomp.split('')\n x.each do |i|\n if i == \"2\"\n a << \"1\"\n b << \"1\"\n elsif i == \"1\"\n a << \"1\"\n b << \"0\"\n else\n a << \"0\"\n b << \"0\"\n end\n end\n puts a\n puts b\nend"}, {"source_code": "1.upto(gets.to_i) do\n n = gets.to_i\n\n odd = false\n result = ['', '']\n gets.chomp.chars.each_with_index do |char, idx|\n if odd\n result[1] += char\n next\n end\n\n case char\n when '2'\n result.map! { |s| s + '1' }\n when '1'\n result[0] += '1' + '0' * (n - idx)\n result[1] += '0'\n odd = true\n when '0'\n result.map! { |s| s + '0' }\n end\n end\n\n result.each { |s| puts s }\nend\n"}], "src_uid": "c4c8cb860ea9a5b56bb35532989a9192"} {"source_code": "n = gets.to_i\narr = []\nn.times do \n\tx, w = gets.split.map(&:to_i)\n\tarr << [x - w, x + w]\nend\n\narr.sort! do |a, b|\n\ta[1] <=> b[1]\nend\n\nans = 0\nnow = -10**9\narr.each do |ele|\n\tif ele[0] >= now\n\t\tans += 1\n\t\tnow = ele[1]\n\tend\nend\n\nputs ans\n", "positive_code": [{"source_code": "n = gets.strip.to_i\nxws = readlines.map {|line| line.strip.split.map(&:to_i) }\n\nxws = xws.map {|x,w| [x-w, x+w] }.sort_by(&:last)\n\nresult=0\ntarget=0\nindex=target\nuntil index==n\n index=target+1\n ct = xws[target].last\n index+=1 while xws[index] && xws[index].first < ct\n target = index\n\n result+=1\nend\n\np result\n"}], "negative_code": [], "src_uid": "c5d15bbebfe57bc7cddb443229fb7d61"} {"source_code": "#Infinity\n#geti,getia\n#Object # dcopy\n#\n#String # to_a\n# \"abc\".to_a #=> [\"a\",\"b\",\"c\"]\n#String # to_ia\n# \"1 2 3\".to_ia #=> [1,2,3]\n#\n#Array # rsort,rsort!\n# [1,3,2,4].rsort #=> [4,3,2,1]\n#\n#Integer # divisor\n# 24.divisor #=> [1,2,3,4,6,8,12,24]\n#\ninclude Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInfinity = 1/0.0\nclass Matrix;def inspect;empty? ? \"Matrix.empty(#{row_size}, #{column_size})\":\"Matrix[\\n#{@rows.map(&:inspect).join(\"\\n\")}\\n]\";end;end\ndef pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end\nclass String;def to_a;split(\"\");end;end\nclass String;def to_ia;split.map(&:to_i);end;end\ndef getia;gets.to_ia;end\ndef geti;gets.to_i;end\nclass Object;def dcopy;Marshal.load(Marshal.dump(self));end;end\nclass Array;def rsort;sort.reverse;end;def rsort!;sort!.reverse!;end;end\n\ndef dfs(a,b,x,y,n)\n mask = ((1< a\n for p in 0..1\n for q in 0..1\n s = x | (p * (1<= 0 and (a - b) % 2 == 0\n puts x.to_s + \" \" + (x + b).to_s + \"\\n\"\nelse\n puts \"-1\\n\"\nend\n"}], "negative_code": [], "src_uid": "9c9235394dceba81c8af6be02aa54fcc"} {"source_code": "T = gets.to_i\nT.times do \n n = gets.to_i\n t = 1\n ans = 0\n 9.times do\n l = []\n r = []\n n.times do |i|\n if i & t > 0\n l << i+1\n else\n r << i+1\n end\n end\n if l.length>0 && r.length>0\n puts \"#{l.length} #{r.length} #{l.join(\" \")} #{r.join(\" \")}\"\n STDOUT.flush\n x = gets.to_i\n ans = x if x > ans\n end\n t *= 2\n end\n puts \"-1 #{ans}\"\n STDOUT.flush\nend\n", "positive_code": [{"source_code": "def say(s)\n puts s\n STDOUT.flush\nend\n\nreadline.to_i.times do\n n = readline.to_i\n r = 0\n bit = 1\n while bit < n do\n a, b = (1..n).partition { |i| i & bit > 0 }\n say \"#{a.length} #{b.length} #{a.join \" \"} #{b.join \" \"}\"\n r1 = readline.to_i\n if r1 > r then r = r1 end\n if r1 < 0 then exit end\n bit <<= 1\n end\n say \"-1 #{r}\"\nend\n"}], "negative_code": [], "src_uid": "20e2cf707d39c22eaf111f12b2ae6d30"} {"source_code": "n = gets.to_i\n\nhash = Hash.new([])\n(1..n).each do |x|\n hash[x] += gets.chomp.split(\" \").map(&:to_i)\nend\n\narr = []\n\nthefirstpair = hash[1]\nif hash[thefirstpair[0]].include?(thefirstpair[1])\n nextone = thefirstpair[0]\n otherone = thefirstpair[1]\nelse\n nextone = thefirstpair[1]\n otherone = thefirstpair[0]\nend\n\narr.push 1\n\nwhile nextone != 1\n arr.push nextone\n asdf = nextone\n nextone = otherone\n otherone = (hash[asdf] - [nextone])[0]\nend\n\narr.each do |x|\n print x\n print \" \"\nend\n\nputs\n", "positive_code": [{"source_code": "# Utility\nclass Child\n attr_reader :memorised\n attr_reader :index\n\n def to_s\n @index.to_s\n end\n\n def log\n \"Index: #{@index}. Memory: #{@memorised}\"\n end\n\n def to_i\n @index\n end\n\n def remembers?(e)\n @memorised.any? { |o| o == e.to_i }\n end\n\n def initialize(index, *other)\n @index = index\n case other.length\n when 2\n @memorised = [other[0], other[1]]\n when 1\n @memorised = other[0].split.map { |s| s.to_i }\n end\n end\nend\n\n# Input\nn = gets.to_i\nchildren = []\nn.times { |i| children.push Child.new(i + 1, gets) }\n\nif n == 3\n # Special case\n puts \"1 2 3\"\n exit 0\nend\n\n# Processing\nroundelay = Array.new(n)\nroundelay[0] = children[0]\n1.upto(n - 1) do |i|\n mem = roundelay[i - 1].memorised\n c_1 = children[mem[0] - 1]\n c_2 = children[mem[1] - 1]\n\n #puts roundelay[i - 1].log\n #puts c_1.log\n #puts c_2.log\n #puts\n\n roundelay[i] = c_1.remembers?(c_2) ? c_1 : c_2\nend\n\n# Output\nputs roundelay.join(\" \")\n"}], "negative_code": [{"source_code": "# Utility\nclass Child\n attr_reader :memorised\n attr_reader :index\n\n def to_s\n @index.to_s\n end\n\n def to_i\n @index\n end\n\n def remembers?(e)\n @memorised.find_index(e.to_i) != nil\n end\n\n def initialize(index, *other)\n @index = index\n case other.length\n when 2\n @memorised = [other[0], other[1]]\n when 1\n @memorised = other[0].split.map { |s| s.to_i }\n end\n end\nend\n\n# Input\nn = gets.to_i\nchildren = []\nn.times { |i| children.push Child.new(i + 1, gets) }\n\n# Processing\n#p children\nroundelay = Array.new(n)\nroundelay[0] = children[0]\n1.upto(n - 1) do |i|\n mem = roundelay[i - 1].memorised\n #p mem\n roundelay[i] = children[mem[0] - 1].remembers?(mem[1]) ? children[mem[0] - 1] : children[mem[1] - 1]\n #puts roundelay[i]\nend\n\n# Output\nputs roundelay.join(\" \")\n"}], "src_uid": "819d3694fccf2b5af0ec3b4ee429dbb3"} {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n, k = gets.chomp.split(' ').map(&:to_i)\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n arr << 0\r\n arr << 1000\r\n pik = 0\r\n prev_pik = 0\r\n sum = 0\r\n\r\n while arr[pik] >= arr[pik + 1] \r\n pik += 1\r\n end\r\n # puts \"PIK = #{pik}\"\r\n while (pik != n && sum < k)\r\n prev_pik = pik\r\n sum += [arr[pik + 1], arr[pik - 1] + 1].min - arr[pik]\r\n arr[pik] = [arr[pik + 1], arr[pik - 1] + 1].min\r\n pik = 0\r\n while arr[pik] >= arr[pik + 1] \r\n pik += 1\r\n end\r\n\r\n # puts \"Arr = #{arr.to_s}\"\r\n end\r\n\r\n # puts \"SUM = #{sum}\"\r\n # puts \"PIK = #{pik}\"\r\n # puts \"Arr = #{arr.to_s}\"\r\n if sum < k \r\n puts -1\r\n else\r\n puts prev_pik + 1\r\n end\r\nend", "positive_code": [{"source_code": "\r\n# int t,n,k;\r\n# cin>>t;\r\n# while(t--)\r\n# {\r\n# cin>>n>>k;\r\n# int a[n];\r\n# for(int i=0;i>a[i];\r\n# int j=0,c=0;\r\n# int p[100000]={0};\r\n# while(true)\r\n# {int f=0;\r\n# for(int i=0;ic)\r\n# cout<<-1<<\"\\n\";\r\n# else\r\n# cout<0 do\r\n b=Array.new(2)\r\n b=gets.chomp.split().map { |e| e.to_i }\r\n n = b[0];\r\n k =b[1];\r\n \r\n a=Array.new(n+1);\r\n i=0;\r\n p=Array.new(100000);\r\n a=gets.chomp.split().map { |e| e.to_i }\r\n \r\n c=0\r\n h=0\r\n while h==0 do\r\n f=0\r\n j=0\r\n while jc\r\n puts -1;\r\n else\r\n puts p[k];\r\n end\r\n t=t-1 \r\nend\r\n"}, {"source_code": "def read\r\n gets.split.map &:to_i\r\nend\r\ngets.to_i.times do\r\n n, k = read\r\n a = read\r\n if n * a.max < k\r\n puts -1\r\n next\r\n end\r\n res = n + 1\r\n k.times do\r\n to = -2\r\n (n - 1).times do |i|\r\n if a[i] < a[i + 1]\r\n to = i\r\n break\r\n end\r\n end\r\n res = to + 1\r\n break if res == -1\r\n a[to] += 1\r\n end\r\n puts res\r\nend"}, {"source_code": "def solve\r\n n, k = ints\r\n h = ints\r\n\r\n ans = -1\r\n k.times do\r\n has_valley = false\r\n (n-1).times do |i|\r\n if h[i] < h[i+1]\r\n ans = i + 1\r\n has_valley = true\r\n h[i] += 1\r\n break\r\n end\r\n end\r\n unless has_valley\r\n ans = -1\r\n break\r\n end\r\n end\r\n puts ans\r\nend\r\n\r\ndef main\r\n t = int\r\n t.times do\r\n solve\r\n end\r\nend\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\nYESNO = %w(NO YES)\r\nINF = 10**9\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts YESNO[1] end\r\ndef no; puts YESNO[0] end\r\ndef yesno t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain"}, {"source_code": "gets.to_i.times do\r\n n,k=gets.split.map(&:to_i)\r\n h=gets.split.map(&:to_i)\r\n f=false\r\n k.times do |kk|\r\n f=false\r\n (n-1).times do |i|\r\n if h[i]= arr[pik + 1] \r\n pik += 1\r\n end\r\n # puts \"PIK = #{pik}\"\r\n while (pik != n && sum < k)\r\n prev_pik = pik\r\n sum += arr[pik + 1] - arr[pik]\r\n arr[pik] = arr[pik + 1]\r\n pik = 0\r\n while arr[pik] >= arr[pik + 1] \r\n pik += 1\r\n end\r\n\r\n end\r\n\r\n # puts \"SUM = #{sum}\"\r\n # puts \"PIK = #{pik}\"\r\n # puts \"Arr = #{arr.to_s}\"\r\n if sum < k \r\n puts -1\r\n else\r\n puts prev_pik + 1\r\n end\r\nend"}], "src_uid": "32855bb8ba33973178fde7c3d0beb2ce"} {"source_code": "n,h,k=gets.split.map(&:to_i)\ns=r=0\ngets.split.each{|p|p=p.to_i\nr+=p\nr,s=p,s+1if r>h\ns+=r/k\nr%=k}\ns+=1if r>0\np s\n\n\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\nN,H,K=gets.split.map(&:to_i)\nr=h=0\ngets.split.map(&:to_i).each{|x|\n\tif h+x<=H\n\t\th+=x\n\telse\n\t\tr+=1\n\t\th=x\n\tend\n\tr+=h/K\n\th%=K\n}\np r+(h+K-1)/K"}, {"source_code": "n, h, k = readline.split(' ').collect(&:to_i)\narr = readline.split(' ').collect(&:to_i)\nleft = 0\nct = 0\narr.each do |num|\n if left + num > h\n left = num\n ct += 1\n else\n left += num\n end\n ct += (left / k)\n left %= k\nend\n\nct += 1 if left > 0\nputs ct\n"}, {"source_code": "n, h, k = gets.split.map { |x| x.to_i }\na = gets.split.map { |x| x.to_i }\nans = 0\nsum = 0\na.each do |now|\n\tcut = [(now - (h - sum) + k - 1) / k, 0].max\n\tans += cut\n\tsum = [sum - cut * k, 0].max\n\tsum += now\nend\nans += (sum + k - 1) / k\nputs ans"}, {"source_code": "n, h, k = gets.chomp.split.map(&:to_i)\nas = gets.chomp.split.map(&:to_i)\n\nt = 0\nl = 0\n\nfor i in 0...n\n t += l / k\n l = l % k\n if h < l + as[i]\n t += 1\n l = 0\n end\n l += as[i]\nend\nt += (l + k - 1) / k\n\nputs t\n"}, {"source_code": "n, h, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = 0\nleft = 0\ni = 0\nwhile i < n\n ans += (left + a[i]) / k\n left = (left + a[i]) % k\n if i == n - 1 && left > 0\n ans += 1\n elsif i != n - 1 && left != 0 && left + a[i + 1] > h\n ans += 1\n left = 0\n end\n i += 1\nend\nputs ans\n"}, {"source_code": "totalPotatos, processorHeight, smashUnits = gets.split.map(&:to_i)\nseconds = 0\nremain = 0\ngets.split.map(&:to_i).each { |potato|\n if remain + potato <= processorHeight\n remain += potato\n else\n seconds += 1\n remain = potato\n end\n seconds += remain / smashUnits\n remain %= smashUnits\n}\nseconds += 1 if remain > 0\nputs seconds\n\n\n"}, {"source_code": "n, h, k = gets.split.map { |x| x.to_i }\na = gets.split.map { |x| x.to_i }\n\nans = 0\nsum = 0\na.each do |now|\n\tcut = [(now - (h - sum) + k - 1) / k, 0].max\n\tans += cut\n\tsum = [sum - cut * k, 0].max\n\tsum += now\nend\nans += (sum + k - 1) / k\nputs ans\n"}, {"source_code": "$now = 0\n\n$n, $h, $k = gets.chomp.split(' ').map { |i| i.to_i }\n$potatos = gets.chomp.split(' ').map { |i| i.to_i }\n\ndef put_potato\n\t#puts \"Before put_potato : #{$inQueue}\"\n\t#puts \"Now : #{$now}\"\n\n\tuntil $inQueue + $potatos[$now] > $h\n\t#\tputs \"Now inQueue : #{$inQueue}\"\n\t\t$inQueue += $potatos[$now]\n\t\t$now += 1\n\n\t\tbreak if $now == $potatos.length\n\tend\n\n\t#puts \"After put_potato : #{$inQueue}\"\nend\n\ntime = 0\n$inQueue = 0\nput_potato\n\nuntil $now == $potatos.length\n\tnn = ($inQueue / $k)\n\ttime += nn\n\ttime += 1 if nn == 0\n\t$inQueue -= (nn * $k)\n\t$inQueue = 0 if nn == 0\n\tput_potato\nend\n\ntime += ($inQueue / $k)\ntime += 1 if ($inQueue % $k > 0)\n\nputs time"}], "negative_code": [{"source_code": "now = 0\n\nn, h, k = gets.chomp.split(' ').map { |i| i.to_i }\npotatos = gets.chomp.split(' ').map { |i| i.to_i }\n\ntime = 0\nremain = potatos[0]\n\ni = 0\n\nuntil i >= (potatos.length - 1)\n\ttime += 1\n\tremain -= k\n\t#puts \"Remain : #{remain}\"\n\t#puts \"Next potatos : #{potatos[i + 1]}\"\n\tif remain + potatos[i + 1] <= h\n\t\tremain += potatos[i + 1]\n\n\t#puts \"Insidle Remain : #{remain}\"\n\n\t\tif remain < 0\n\t\t\ti += 1\n\t\t\tuntil remain >= 0\n\t\t\t\t#puts \"Interpol Remain : #{remain}\"\n\t\t\t\tbreak if i >= potatos.length\n\t\t\t\tremain += potatos[i + 1]\n\t\t\t\ti += 1\n\t\t\tend\n\t\tend\n\telse\n\t\tremain = potatos[i + 1]\n\t\ttime += 1\n\tend\n\n\ti += 1\nend\n\ntime += (remain / k)\ntime += 1 if remain % k > 0\n\nputs time"}], "src_uid": "5099a9ae62e82441c496ac37d92e99e3"} {"source_code": "x, k = gets.split.collect{|i| i.to_i}\nmark = Array.new(x-1,0)\n(1..k).each do\n tmp = gets.split.collect{|i| i.to_i}\n mark[tmp[1]-1] = 1\n mark[tmp[2]-1] = 1 if tmp.size == 3\nend\nmaxans = mark.count(0)\nminans = maxans\ntmp = 1\nwhile tmp < x\n if mark[tmp] == 0 and mark[tmp-1] == 0\n minans -= 1\n tmp += 1\n end\n tmp += 1\nend\nprint minans, \" \", maxans, \"\\n\"\n", "positive_code": [{"source_code": "x, k = gets.split.map(&:to_i)\nc_min, c_max = 0\nx -= 1\nwas = [false] * x\nwas[x] = true\nfor i in 1..k\n d = gets.split.map(&:to_i)\n for j in 1..d.length-1\n was[d[j] - 1] = true\n end\nend\nc_max = was.count { |x| not x }\ni = 0\nwhile i < x\n if not was[i]\n was[i] = was[i + 1] = true\n c_min += 1\n end\n i += 1\nend\nputs \"#{c_min} #{c_max}\""}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @current_round_iden, @num_of_took_rounds = @dats[0].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n if @num_of_took_rounds == 0\n max = @current_round_iden-1\n min = @current_round_iden % 2 == 0 ? @current_round_iden / 2 : (@current_round_iden) / 2 \n else \n\n @unused_indentifiers = []\n @remember_rounds = []\n (1..@dats.length-1).each do |line_num|\n line = @dats[line_num]\n line = line.split(\" \")\n line.shift\n line.each { |elem| @remember_rounds.push(elem.to_i) }\n end\n\n (@current_round_iden-1).downto(1) do |elem|\n @unused_indentifiers.push(elem) if not @remember_rounds.include?(elem) \n end\n\n min = find_min_possible(@unused_indentifiers)\n max = find_max_possible(@unused_indentifiers)\n end\n print \"#{min} #{max}\" \n end\n\n def find_min_possible(indentifier_array)\n ret = 0\n idx = 0\n indentifier_array.sort!\n \n while idx < indentifier_array.length\n if idx == indentifier_array.length - 1\n ret += 1\n return ret\n elsif indentifier_array[idx+1] == indentifier_array[idx]+1\n ret += 1\n idx += 2\n else\n ret += 1\n idx += 1\n end\n end\n return ret\n end\n\n def find_max_possible(indentifier_array)\n indentifier_array.length\n end\nend\n\nsolver = ProblemA.new\nsolver.solve\n"}, {"source_code": "def rsm(&block)\n readline.split.map{|i| block.yield(i)}\nend\n\ndef rsmi\n rsm {|i| i.to_i}\nend\n\nx, k = rsmi\na = Array.new(x - 1, 0)\nk.times {\n r = rsmi\n t, x = r[0], r[1]\n a[x - 1] = 2\n if t == 1\n y = r[2]\n a[y - 1] = 1\n end\n\n}\n\ns1 = a.count {|i| i == 0}\ns2 = 0\na.length.times { |i|\n if a[i] == 0\n s2 += 1\n a[i] = 2\n if i + 1 < a.length\n a[i + 1] = 1 if a[i + 1] == 0\n end\n end\n}\nprintf(\"%d %d\", s2, s1)"}, {"source_code": "n,k = gets.chomp!.split.map { |e| e.to_i}\n\nA = Array.new(n) { |i| 0}\n\nk.times { \n c,d1,d2 = gets.chomp!.split.map { |e| e.to_i}\n A[d1-1] = 1\n if d2 != nil\n A[d2-1] = 1\n end\n}\n\n\nmx=0\nmi=0\ncur=0\n(n-1).times do |i|\n if A[i] == 0\n cur += 1\n else\n mx += cur\n mi += (cur+1)/2\n cur = 0 \n end \nend\n\n\nmx += cur\nmi += (cur+1)/2\n\nputs \"#{mi} #{mx}\"\n"}, {"source_code": "def get_pair_num(diff_ary,pair_num)\n\tif diff_ary.empty?\n\t\treturn pair_num\n\telse\n\t\tif diff_ary.length > 1\n\t\t\tif (diff_ary[0] == diff_ary[1] - 1)\n\t\t\t\tdiff_ary.delete_at(0)\n\t\t\t\tdiff_ary.delete_at(0)\n\t\t\t\treturn get_pair_num(diff_ary,pair_num+1)\n\t\t\telse\n\t\t\t\tdiff_ary.shift\n\t\t\t\treturn get_pair_num(diff_ary,pair_num)\n\t\t\tend\n\t\tend\n\t\treturn pair_num\n\tend\nend\n\ndef check_diff(id_ary,max_id)\n\tpair_num = 0\n\tfull_ary = []\n\tfor i in 1..max_id\n\t\tfull_ary << i\n\tend\n\tdiff_ary = full_ary - id_ary\n\tdiff_ary.sort!\n\tpair_num = get_pair_num(diff_ary.clone, 0)\n\tmax_num = diff_ary.length\n\tmin_num = diff_ary.length - pair_num\n\n\treturn [min_num, max_num]\n\nend\n\nfirst_line = (gets()).split()\ncurrent_id = (first_line.shift).to_i\npart_in_num = (first_line.pop).to_i\nid_ary = []\nfor i in 1..part_in_num\n\tary = []\n\t(gets().split).each { |e| ary << e.to_i }\n\tary.shift\n\tary.each { |e| id_ary << e }\nend\nresult = check_diff(id_ary, current_id-1)\nputs result[0].to_s + \" \" + result[1].to_s"}, {"source_code": "def solve(x, a)\n ids = Array.new(x + 1, false)\n a.each { |id|\n ids[id[1]] = true\n ids[id[2]] = true if id[0] == 1\n }\n ids[x] = true\n\n div1 = div2 = 0\n i = 1\n while i < x\n unless ids[i]\n if ids[i + 1]\n div2 += 1\n else\n div1 += 1\n i += 1\n end\n end\n i += 1\n end\n [div1 + div2, div1 * 2 + div2]\nend\n\ndef read_next_line\n gets.chomp.split.map(&:to_i)\nend\n\nif __FILE__ == $0\n x, k = read_next_line\n a = (0...k).map { read_next_line }\n puts solve(x, a) * ' '\nend"}, {"source_code": "#f = File.open('test1.txt', 'r')\nf = STDIN\nx, k = f.gets.chomp.split.map(&:to_i)\na = Array.new(x, false)\na[0] = true\nk.times do\n tmp = f.gets.chomp.split.map(&:to_i)\n if tmp[0] == 1\n a[tmp[1]], a[tmp[2]] = true\n else\n a[tmp[1]] = true\n end\nend\nmaximum = a.count false\nminimum = 0\n(0...x).each do |i|\n if a[i] == false\n minimum += 1\n a[i+1] = true\n end\nend\nputs \"#{minimum} #{maximum}\""}, {"source_code": "i=->(x){x.split.map(&:to_i)}\nn,_=i[gets]\na=$<.drop(0).collect{|x|i[x][1..-1]}.push([0,n]).flatten.sort\nx,y=0,0\n(a.size-1).times do |k|\n\tz=a[k+1]-a[k]-1\n\tx,y=x+(z+1)/2,y+z\nend\nputs \"#{x} #{y}\"\n"}, {"source_code": "a=gets[/\\d+/].to_i;\nb=Array(0..a-1);\nd=e=0;\nc=STDIN.read.scan(/ \\d+/).map{|z|z.sub(/ /,'').to_i};\nb.map{|x|x=c.include?(x)?1:0}.join.sub(/./,'').gsub(/0/){|y|0*(d+=1)}.gsub(/00|0/){|y|0*(e+=1)}; \nprint e,' ',d;"}], "negative_code": [{"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @current_round_iden, @num_of_took_rounds = @dats[0].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n if @num_of_took_rounds == 0\n max = @current_round_iden-1\n min = @current_round_iden % 2 == 0 ? @current_round_iden / 2 : @current_round_iden / 2 + 1\n else \n\n @unused_indentifiers = []\n @remember_rounds = []\n (1..@dats.length-1).each do |line_num|\n line = @dats[line_num]\n line = line.split(\" \")\n line.shift\n line.each { |elem| @remember_rounds.push(elem.to_i) }\n end\n\n (@current_round_iden-1).downto(1) do |elem|\n @unused_indentifiers.push(elem) if not @remember_rounds.include?(elem) \n end\n\n min = find_min_possible(@unused_indentifiers)\n max = find_max_possible(@unused_indentifiers)\n end\n print \"#{min} #{max}\" \n end\n\n def find_min_possible(indentifier_array)\n ret = 0\n idx = 0\n indentifier_array.sort!\n \n while idx < indentifier_array.length\n if idx == indentifier_array.length - 1\n ret += 1\n end\n if indentifier_array[idx+1] == indentifier_array[idx]+1\n ret += 1\n idx += 2\n else\n ret += 1\n idx += 1\n end\n end\n return ret\n end\n\n def find_max_possible(indentifier_array)\n indentifier_array.length\n end\nend\n\nsolver = ProblemA.new\nsolver.solve\n"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @cards_num, @max_abs = @dats[0].split(\" \").map{|x| x.to_i}\n @cards = @dats[1].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n sum = @cards.inject(:+).abs\n return 1 if sum <= @max_abs\n return 0 if @max_abs == 0\n\n count_ret = 0\n (@max_abs-1).downto(1) do |elem|\n if sum >= elem\n count_ret += 1\n sum -= elem\n elsif sum == 1\n return count_ret+1 \n elsif sum == 0\n return count_ret\n end\n end\n return count_ret\n end\nend\n\nsolver = ProblemA.new\np solver.solve\n"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @current_round_iden, @num_of_took_rounds = @dats[0].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n if @num_of_took_rounds == 0\n max = @current_round_iden-1\n min = @current_round_iden % 2 == 0 ? @current_round_iden / 2 : @current_round_iden / 2 + 1\n else \n\n @unused_indentifiers = []\n @remember_rounds = []\n (1..@dats.length-1).each do |line_num|\n line = @dats[line_num]\n line = line.split(\" \")\n line.shift\n line.each { |elem| @remember_rounds.push(elem.to_i) }\n end\n\n (@current_round_iden-1).downto(1) do |elem|\n @unused_indentifiers.push(elem) if not @remember_rounds.include?(elem) \n end\n\n min = find_min_possible(@unused_indentifiers)\n max = find_max_possible(@unused_indentifiers)\n end\n print \"#{min} #{max}\" \n end\n\n def find_min_possible(indentifier_array)\n ret = 0\n idx = 0\n indentifier_array.sort!\n \n while idx < indentifier_array.length\n if idx == indentifier_array.length - 1\n ret += 1\n return ret\n elsif indentifier_array[idx+1] == indentifier_array[idx]+1\n ret += 1\n idx += 2\n else\n ret += 1\n idx += 1\n end\n end\n return ret\n end\n\n def find_max_possible(indentifier_array)\n indentifier_array.length\n end\nend\n\nsolver = ProblemA.new\nsolver.solve\n"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @current_round_iden, @num_of_took_rounds = @dats[0].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n if @num_of_took_rounds == 0\n max = @current_round_iden-1\n min = @current_round_iden % 2 == 0 ? @current_round_iden / 2 : (@current_round_iden-1) / 2 + 1\n else \n\n @unused_indentifiers = []\n @remember_rounds = []\n (1..@dats.length-1).each do |line_num|\n line = @dats[line_num]\n line = line.split(\" \")\n line.shift\n line.each { |elem| @remember_rounds.push(elem.to_i) }\n end\n\n (@current_round_iden-1).downto(1) do |elem|\n @unused_indentifiers.push(elem) if not @remember_rounds.include?(elem) \n end\n\n min = find_min_possible(@unused_indentifiers)\n max = find_max_possible(@unused_indentifiers)\n end\n print \"#{min} #{max}\" \n end\n\n def find_min_possible(indentifier_array)\n ret = 0\n idx = 0\n indentifier_array.sort!\n \n while idx < indentifier_array.length\n if idx == indentifier_array.length - 1\n ret += 1\n return ret\n elsif indentifier_array[idx+1] == indentifier_array[idx]+1\n ret += 1\n idx += 2\n else\n ret += 1\n idx += 1\n end\n end\n return ret\n end\n\n def find_max_possible(indentifier_array)\n indentifier_array.length\n end\nend\n\nsolver = ProblemA.new\nsolver.solve\n"}, {"source_code": "def answer(id_ary,max_id)\n\tpair_num = 0\n\tfull_ary = []\n\tfor i in 1..max_id\n\t\tfull_ary << i\n\tend\n\tdiff_ary = full_ary - id_ary\n\tif diff_ary.empty?\n\t\treturn [0,0]\n\telse\n\t\tfor i in 0..(diff_ary.length-1)\n\t\t\tif (i != diff_ary.length-1)\n\t\t\t\tif diff_ary[i] == diff_ary[i+1] - 1\n\t\t\t\t\tpair_num += 1\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\tmax_num = diff_ary.length\n\tmin_num = diff_ary.length - pair_num\n\n\treturn [min_num, max_num]\n\nend\n\nfirst_line = (gets()).split()\ncurrent_id = (first_line.shift).to_i\npart_in_num = (first_line.pop).to_i\nid_ary = []\nfor i in 1..part_in_num\n\tary = []\n\t(gets().split).each { |e| ary << e.to_i }\n\tary.shift\n\tary.each { |e| id_ary << e }\nend\nresult = answer(id_ary, current_id-1)\nputs result[0].to_s + \" \" + result[1].to_s"}, {"source_code": "def answer(id_ary,max_id)\n\tpair_num = 0\n\tfull_ary = []\n\tfor i in 1..max_id\n\t\tfull_ary << i\n\tend\n\tdiff_ary = full_ary - id_ary\n\tif diff_ary.empty?\n\t\treturn [0,0]\n\telse\n\t\tfor i in 0..(diff_ary.length-1)\n\t\t\tif (i != diff_ary.length-1)\n\t\t\t\tif diff_ary[i] == diff_ary[i+1] - 1\n\t\t\t\t\tpair_num += 1\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\tmax_num = diff_ary.length\n\tmin_num = diff_ary.length - pair_num\n\n\treturn [min_num, max_num]\n\nend\n\nfirst_line = (gets()).split()\ncurrent_id = (first_line.shift).to_i\npart_in_num = (first_line.pop).to_i\nid_ary = []\nfor i in 1..part_in_num\n\tary = []\n\t(gets().split).each { |e| ary << e.to_i }\n\tary.shift\n\tary.each { |e| id_ary << e }\nend\nresult = answer(id_ary, current_id-1)\nputs result[0].to_s + result[1].to_s"}, {"source_code": "i=->(x){x.split.map(&:to_i)}\nn,_=i[gets]\na=$<.drop(0).collect{|x|i[x][1..-1]}.flatten.push(n).sort\nx,y=0,0\n(a.size-1).times do |k|\n\tz=a[k+1]-a[k]\n\tnext if z == 1\n\tx,y=x+(z+1)/2,y+z\nend\nputs \"#{x} #{y}\"\n"}, {"source_code": "i=->(x){x.split.map(&:to_i)}\nn,_=i[gets]\na=$<.drop(0).collect{|x|i[x][1..-1]}.flatten.push(n).push(1).sort\nx,y=0,0\n(a.size-1).times do |k|\n\tz=a[k+1]-a[k]\n\tnext if z <= 1\n\tx,y=x+(z+1)/2,y+z\nend\nputs \"#{x} #{y}\"\n"}], "src_uid": "fb77c9339250f206e7188b951902a221"} {"source_code": "$><<[n=gets.to_i,*1..n-1]*\" \"\n", "positive_code": [{"source_code": "puts [*1..gets.to_i].rotate(-1)*' '"}, {"source_code": "$><<[n=gets.to_i,*1..n-1]*\" \"\n"}, {"source_code": "n = gets.to_i\nprint n,' ', (1...n).to_a.join(' ') \n"}, {"source_code": "print n = gets.to_i,' ', (1...n).to_a.join(' ') \n"}, {"source_code": "\ufeffdef main()\n n = gets.chomp.to_i\n p = [n]\n \n 1.upto(n - 1) do |i|\n p << i\n end\n \n puts p.join(\" \")\n \nend\n\nmain()"}, {"source_code": "$><<[n=gets.to_i,*1..n-1]*\" \"\n"}, {"source_code": "$><<[n=gets.to_i,*1..n-1]*\" \""}, {"source_code": "n = gets.to_i\nputs ([n] + (1...n).to_a)*' '"}, {"source_code": "n = gets.to_i\nputs ([n]+(1...n).to_a)*' '"}, {"source_code": "$><<[n=gets.to_i,*1..n-1]*\" \"\n"}, {"source_code": "$><<[n=gets.to_i,*1..n-1]*\" \"\n"}, {"source_code": "n = gets.to_i\n\nif n == 1\n puts 1\nelse\n print \"#{n} \"\n puts (1..(n-1)).to_a.map(&:to_s).join(\" \")\nend\n"}, {"source_code": "n = gets.to_i\n$arr = (1..n).to_a\ndef f(x)\n $arr[x-2], $arr[x-1] = $arr[x-1], $arr[x-2]\n f(x-1) if x-1>1\nend\nif n == 1\n puts n\n exit\nend\nf(n)\nputs $arr.join(\" \")"}, {"source_code": "$><<[n=gets.to_i,*1..n-1]*\" \""}, {"source_code": "n=gets.to_i\nprint n\n1.upto(n-1) {|i| print ' ',i}\nputs\n"}, {"source_code": "n=gets.to_i\nif n==1 then\n\tp 1\nelse\n\tprint n\n\t1.upto(n-1) {|i| print ' ',i}\n\tputs\nend\n"}, {"source_code": "print n=gets.to_i\n1.upto(n-1) {|i| print ' ',i}\n"}, {"source_code": "n=gets.to_i\nprint n\n1.upto(n-1) {|i| print ' ',i}\n"}, {"source_code": "n = gets.to_i\nif n==1\nputs 1\nelsif n==2\nputs '2 1'\nelse\nputs(([n,1]+(2...n).to_a).join ' ')\nend"}, {"source_code": "$><<[n=gets.to_i,*1..n-1]*\" \""}, {"source_code": "def f(x)\n return if x == 0\n f(x - 1)\n tmp = $a[x]\n $a[x] = $a[x - 1]\n $a[x - 1] = tmp\nend\n\nn = gets.to_i\nans = (1..n-1).to_a\nans.unshift n\n\nputs ans.join ' '\n"}, {"source_code": "n = STDIN.readline.to_i\nans = [n]\nn -= 1\n1.upto n do |i|\n ans << i\nend\n\nputs ans.join ' '\n"}, {"source_code": "a = gets.to_i\nprint a\n1.upto(a - 1) { |i| print ' ',i }\n"}, {"source_code": "a=gets.to_i\n\nprint a\n1.upto(a-1){|i| print ' ',i}\n"}, {"source_code": "n=gets.to_i\nputs [n] + (1...n).to_a\n"}, {"source_code": "puts [n=gets.to_i]+(1...n).to_a"}, {"source_code": "$><<[n=gets.to_i,*1..n-1]*\" \"\n"}, {"source_code": "n = Integer(gets.chomp)\nputs(([n] + (1..n - 1).to_a) * ' ')"}, {"source_code": "$><<[n=gets.to_i,*1..n-1]*\" \"\n"}, {"source_code": "puts [n=gets.to_i,*1..n-1]*\" \""}, {"source_code": "a = gets.to_i\nb = \"\"\nc = 1\nwhile(c<<[n=gets.to_i,*1..n-1]*\" \"\n"}], "negative_code": [{"source_code": "puts [1..gets.to_i].rotate(-1)*' '"}, {"source_code": "\ufeffdef main()\n n = gets.chomp.to_i\n p = []\n \n n.downto(1) do |i|\n p << i\n end\n \n puts p.join(\" \")\n \nend\n\nmain()"}, {"source_code": "n = gets.to_i\n\nif n == 1\n puts 1\nelse\n puts (2..n).to_a.push(1).map(&:to_s).join(\" \")\nend\n"}, {"source_code": "puts (1..gets.to_i).to_a.reverse.join(\" \")"}, {"source_code": "a=[]\nn=gets.to_i\nn.times{|i|a<0)\n\t\tlist.push x\n\t\tnewmax = curr*x\n\t\tif(works && newmax < max)\n\t\t\tcurr = newmax\n\t\t\tworkslist.push works\n\t\telse\n\t\t\tworks = false\n\t\t\tworkslist.push works\n\t\tend\n\telse\n\t\tworkslist.pop\n\t\ta = list.pop\n\t\tif(works)\n\t\t\tcurr/=a\n\t\tend\n\t\tif(workslist.size>0)\n\t\t\tworks = workslist[-1]\n\t\telse\n\t\t\tworks = true\n\t\tend\n\tend\n\n\tif(ans>max)\n\t\tputs \"OVERFLOW!!!\"\n\t\texit\n\tend\nend\n\nputs ans", "positive_code": [{"source_code": "l = gets.to_i\nlines = (0...l).map { gets.strip }\nans = 0\ncur = 1\nstk = []\nptr = 0\nuntil ptr == l\n if lines[ptr].match(/^for/)\n b = lines[ptr].match(/\\d+/)[0].to_i\n cur *= b\n stk.push(b)\n elsif lines[ptr].match(/^add/)\n ans += cur\n else\n cur /= stk.pop\n end\n ptr += 1\n until cur < 1e10\n if lines[ptr].match(/^for/)\n stk.push(1)\n elsif lines[ptr].match(/^add/)\n puts \"OVERFLOW!!!\"\n exit\n else\n cur /= stk.pop\n end\n ptr += 1\n end\nend\nif ans < 2**32 - 0\n puts ans\nelse\n puts \"OVERFLOW!!!\"\nend\n"}], "negative_code": [{"source_code": "l = gets.to_i\nlines = (0...l).map { gets.strip }\nans = 0\ncur = 1\nstk = []\nptr = 0\nuntil ptr == l\n if lines[ptr].match(/^for/)\n b = lines[ptr].match(/\\d+/)[0].to_i\n cur *= b\n stk.push(b)\n elsif lines[ptr].match(/^add/)\n ans += cur\n else\n cur /= stk.pop\n end\n ptr += 1\n until cur < 1e10\n if lines[ptr].match(/^for/)\n stk.push(1)\n elsif lines[ptr].match(/^add/)\n puts \"OVERFLOW!!!\"\n exit\n else\n cur /= stk.pop\n end\n ptr += 1\n end\nend\nif ans < 2**32 - 1\n puts ans\nelse\n puts \"OVERFLOW!!!\"\nend\n"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nt = gets.to_i\ncurr = 1\n\narr = []\nt.times do\n\tstr = gets.chomp\n\tif(str[0]=='f')\n\t\tarr.push str.split(\" \")[-1].to_i\n\telsif(str[0]=='a')\n\t\tarr.push 0\n\telse\n\t\tarr.push -1\n\tend\nend\n\nmax = 2**32-1\n\nlist = []\nworkslist = []\nans=0\nworks = true\n\narr.each do |x|\n\tif(x==0)\n\t\tif(!works)\n\t\t\tputs \"OVERFLOW!!!\"\n\t\t\texit\n\t\tend\n\t\tans+=curr\n\telsif(x>0)\n\t\tlist.push x\n\n\t\tnewmax = curr*x\n\t\tif(newmax < max)\n\t\t\tcurr = newmax\n\t\t\tworkslist.push true\n\t\telse\n\t\t\tworks = false\n\t\t\tworkslist.push false\n\t\tend\n\telse\n\t\tworks = workslist.pop\n\t\ta = list.pop\n\t\tif(works)\n\t\t\tcurr/=a\n\t\tend\n\tend\n\n\tif(ans>max)\n\t\tputs \"OVERFLOW!!!\"\n\t\texit\n\tend\nend\n\nputs ans"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nt = gets.to_i\ncurr = 1\n\narr = []\nt.times do\n\tstr = gets.chomp\n\tif(str[0]=='f')\n\t\tarr.push str.split(\" \")[-1].to_i\n\telsif(str[0]=='a')\n\t\tarr.push 0\n\telse\n\t\tarr.push -1\n\tend\nend\n\nmax = 2**32-1\n\nlist = []\nworkslist = []\nans=0\nworks = true\n\narr.each do |x|\n\tif(x==0)\n\t\tif(!works)\n\t\t\tputs \"OVERFLOW!!!\"\n\t\t\texit\n\t\tend\n\t\tans+=curr\n\telsif(x>0)\n\t\tlist.push x\n\n\t\tnewmax = curr*x\n\t\tif(works && newmax < max)\n\t\t\tcurr = newmax\n\t\t\tworkslist.push works\n\t\telse\n\t\t\tworks = false\n\t\t\tworkslist.push works\n\t\tend\n\telse\n\t\tworks = workslist.pop\n\t\ta = list.pop\n\t\tif(works)\n\t\t\tcurr/=a\n\t\tend\n\tend\n\n\tif(ans>max)\n\t\tputs \"OVERFLOW!!!\"\n\t\texit\n\tend\nend\n\nputs ans"}], "src_uid": "70f67dc28f9f6076255df97fc58ba2d6"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na.sort!\nres = 0\nsum = 0\na.each do\n |x|\n if(sum <= x)\n sum+=x\n res+=1\n end\nend\nprint res", "positive_code": [{"source_code": "def test(ary)\n sum = 0\n res = 0\n \n ary.sort.each do |el|\n next unless el >= sum\n sum += el\n res += 1\n end\n \n res\nend\n\na = Kernel.gets\nputs test(Kernel.gets.split.map(&:to_i))"}, {"source_code": "n = gets.to_i\nt = gets.split.map(&:to_i)\nsum = 0\nans = 0\nt.sort.each do |x|\n if x >= sum\n sum += x\n ans += 1\n end\nend\nputs ans\n"}, {"source_code": "gets\nx=gets.split.map{|e| e.to_i}.sort\nsum=0\nans=0\n\nx.each{|e|\n\tif sum<=e then\n\t\tsum+=e\n\t\tans+=1\n\tend\n}\nputs ans\n\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\ncount = 1\na = a.sort\nt = a[0]\narr = []\nfor i in (1..a.size-1)\n\tx = i\n\twhile a[x] < t && x < n-1\n\t\tx += 1\n\tend\n\tif a[x] != nil && a[x] >= t\n\t\tcount += 1\n\t\tt += a[x]\n\telse\n\t\tbreak\n\tend\nend\nprint count"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nts = gets.split.map(&:to_i)\nts.sort!\nacc = ts[0]\nsatisfied = 1\n# p ts\nts[1..-1].each { |i|\n # p \"Satisfied? #{i} #{acc}\"\n if acc <= i\n satisfied += 1\n acc += i\n else\n # \ub2e4\uc74c \uc0ac\ub78c\uc774 \ub9cc\uc871\ud560 \uc218 \uc788\ub294 \uace0\uac1d\uc774\ub77c\uba74,\n # \ub2e4\uac00\uc62c \uace0\uac1d\uc744 \uc81c\uc77c \ub4a4\ub85c \ubcf4\ub0b8\ub2e4\uace0 \uc0dd\uac01\ud558\uc790.\n # \uc2a4\ud0b5\ud574\ub3c4 \ubb34\ubc29\ud558\ub2e4.\n next\n end\n}\n\nputs satisfied"}, {"source_code": "n = Integer(gets)\nnums = gets.chomp.split\nqueue = []\nfor i in 0...n\n queue[i] = Integer(nums[i])\nend\n\nqueue.sort!\nsum = 0\ncount = 0\nfor i in 0...n\n if sum <= queue[i]\n sum += queue[i]\n count += 1\n else\n queue.push(queue[i])\n queue[i] = 0\n end\nend\nputs count\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\ncount = 1\na = a.sort\nt = a[0]\narr = []\nfor i in (1..a.size-1)\n\tx = i\n\twhile a[x] < t && x < n-1\n\t\tx += 1\n\tend\n\tif a[x] != nil && a[x] >= t\n\t\tcount += 1\n\t\tt += a[x]\n\telse\n\t\tbreak\n\tend\nend\nprint count"}, {"source_code": "gets\npleased = 0\ntime = 0\ngets.split(' ').map(&:to_i).sort.each do |wait|\n if time <= wait\n pleased += 1\n time += wait\n end\nend\nputs pleased\n"}, {"source_code": "n = gets.to_i\nt = gets.split.collect{|i| i.to_i}.sort\nsum = 0\nans = 0\nt.each do |tt|\n if tt >= sum\n sum += tt\n ans += 1\n end\nend\nputs ans\n"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nts = gets.split.map(&:to_i)\nts.sort!\nacc = ts[0]\nsatisfied = 1\nts[1..-1].each { |i|\n if acc <= i\n satisfied += 1\n end\n\n acc += i\n}\n\nputs satisfied"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\nt = 0\na = a.sort\ncount = 1\nfor i in (1..n-1)\n\tt += a[i-1]\n\tif a[i] >= t\n\t\tcount += 1\n\tend\nend\nprint count"}, {"source_code": "def test(ary)\n sum = 0\n res = 0\n \n ary.sort.each do |el|\n next unless el > sum\n sum += el\n res += 1\n end\n \n res\nend\n\na = Kernel.gets\nputs test(Kernel.gets.split.map(&:to_i))"}, {"source_code": "def test(ary)\n sum = 0\n res = 0\n \n ary.sort.each do |el|\n next unless el > sum\n sum += el\n res += 1\n end\n \n res\nend\n\na = Kernel.gets\nputs test(Kernel.gets.split.map(&:to_i))"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nts = gets.split.map(&:to_i)\nts.sort!\nacc = ts[0]\nsatisfied = 1\np ts\nts[1..-1].each { |i|\n # p \"Satisfied? #{i} #{acc}\"\n if acc <= i\n satisfied += 1\n acc += i\n else\n # \ub2e4\uc74c \uc0ac\ub78c\uc774 \ub9cc\uc871\ud560 \uc218 \uc788\ub294 \uace0\uac1d\uc774\ub77c\uba74,\n # \ub2e4\uac00\uc62c \uace0\uac1d\uc744 \uc81c\uc77c \ub4a4\ub85c \ubcf4\ub0b8\ub2e4\uace0 \uc0dd\uac01\ud558\uc790.\n # \uc2a4\ud0b5\ud574\ub3c4 \ubb34\ubc29\ud558\ub2e4.\n next\n end\n}\n\nputs satisfied"}], "src_uid": "08c4d8db40a49184ad26c7d8098a8992"} {"source_code": "R, D = gets.split.map &:to_i\nn = gets.to_i\nEPS = 1e-9\n\ncnt = 0\nn.times do\n x, y, r = gets.split.map &:to_i\n d = (x**2 + y**2)**0.5\n # puts(\"#{R} #{D} #{d} #{r} #{R-D-EPS} #{r-d} #{r+d} #{R+EPS}\")\n cnt += 1 if R-D-EPS < d-r && d+r < R+EPS \nend\n\nputs cnt", "positive_code": [{"source_code": "R, D = gets.chomp.split.map(&:to_i)\nn = gets.to_i\nans = 0\n\nn.times do\n x, y, r = gets.chomp.split.map(&:to_i)\n hypot = x * x + y * y\n outer = (hypot <= (R - r) ** 2 && (R - r) > 0)\n inner = ((R - D + r) <=0 || (R - D + r) ** 2 <= hypot)\n ans += 1 if outer and inner\nend\n\np ans\n"}, {"source_code": "R, d = gets.split.map(&:to_i)\nn = gets.to_i\n\nans = 0\nn.times do\n x, y, r = gets.split.map(&:to_i)\n if R - d <= Math.hypot(x, y) - r and Math.hypot(x, y) + r <= R\n ans += 1\n end\nend\n\nputs ans\n"}, {"source_code": "r, d = gets.split.map(&:to_i)\nn = gets.to_i\nans = 0\nr2 = (r - d)\nn.times do |i|\n x, y, z = gets.split.map(&:to_i)\n hoge = x ** 2 + y ** 2\n if (r2 + z) * (r2 + z) <= hoge && hoge <= (r - z) * (r - z)\n ans += 1\n end\nend\nputs ans\n"}], "negative_code": [], "src_uid": "fce9d78ad7d4ea01be1704f588e42d37"} {"source_code": "gets\na = gets.split.map(&:to_i)\n\nm = 0\n\ncurrent_m = a.shift\nb = [current_m]\n\nuntil a.empty?\n candidate = a.shift\n if candidate > current_m + 1 # candidate == current_m + 2\n last_one = b.rindex(current_m)\n b.slice!(0..last_one)\n current_m += 1\n elsif candidate < current_m # candidate == current_m - 1\n last_one = b.rindex(current_m + 1)\n b.slice!(0..last_one) if last_one\n current_m -= 1\n end\n b << candidate\n m = b.size if b.size > m\nend\n\nputs m\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\nnums = gets.split.map { |s| s.to_i }\n#puts nums\nprev = 0\nprev_pos = 0\nnext_pos = 0\nans = 0\ncurr = []\ncurr_pos = []\nstart = []\n\nnums.size.times do |i|\n if curr.size < 2 and not curr.include? nums[i] then\n curr << nums[i]\n curr_pos << i\n start << i\n elsif not curr.include? nums[i] then\n curr = curr.drop(1)\n if curr_pos[0] > start[1] then\n start[1] = curr_pos[0] + 1\n end\n curr_pos = curr_pos.drop(1)\n start = start.drop(1)\n curr << nums[i]\n curr_pos << i\n start << i\n else\n if curr[0] == nums[i] then\n curr = curr.drop(1)\n curr_pos = curr_pos.drop(1)\n z = start[0]\n start = start.drop(1)\n curr << nums[i]\n curr_pos << i\n start << z\n else\n curr_pos[1] = i\n end\n end\n ans = [ans,curr_pos.max - start.min + 1].max\n #print curr\n #print curr_pos\n #print start\n #puts ans\nend\n\nputs ans\n \n\n \n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\n$stdout = STDERR\n\nn = gi\na = gis\n\nmx = a[0]\nmn = a[0]\nbf = a[0]\npos = 0\nans = 1\nlen = 1\n1.upto(n - 1) do |i|\n x = a[i]\n puts \"i=%d x=%d bf=%d mn=%d mx=%d len=%d pos=%d ans=%d\" % [i,x,bf,mn,mx,len,pos,ans]\n if bf == x\n len += 1\n puts \"bf==x\"\n else\n if (mx - x).abs <= 1 && (mn - x).abs <= 1\n len += 1\n if mx == mn\n mn, mx = [mx, x].minmax\n end\n puts \"swap mx mn\"\n else\n ans = len if len > ans\n if (bf - x).abs <= 1\n len = i - pos + 1\n mn, mx = [bf, x].minmax\n puts \"continue bf=%d\" % [bf]\n else\n len = 1\n mx = mn = x\n puts \"new state\"\n end\n end\n pos = i\n bf = x\n end\nend\n\nSTDOUT.puts [ans, len].max\n\n"}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\n\nbs = as.map { |a| a / 2 }\ncs = as.map { |a| (a + 1) / 2 }\ncntb = 1\ncntc = 1\nans = 2\nfor i in 1...n\n if bs[i] == bs[i - 1]\n cntb += 1\n ans = [ans, cntb].max\n else\n cntb = 1\n end\n if cs[i] == cs[i - 1]\n cntc += 1\n ans = [ans, cntc].max\n else\n cntc = 1\n end\nend\n\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.split(\" \").map(&:to_i)\nu = max = 1\namin = amax = a[0]\nimin = imax = 0\nfor i in 1...n\n\tif a[i] == a[i-1]\n\t\tu += 1\n\telse\n\t\tif amin <= a[i] and a[i]<= amax\n\t\t\tu += 1\n\t\t\tif a[i] == amin\n\t\t\t\timin = i\n\t\t\telse\n\t\t\t\timax = i\n\t\t\tend\n\t\telsif a[i] > amax\n\t\t\tamin = amax\n\t\t\tamax = a[i]\n\t\t\tu = i - imax + 1\n\t\t\timin = imax\n\t\t\timax = i\n\t\telse\n\t\t\tamax = amin\n\t\t\tamin = a[i]\n\t\t\tu = i - imin + 1\n\t\t\timax = imin\n\t\t\timin = i\n\t\tend\n\tend\n\tif u > max\n\t\tmax = u\n\tend\nend\nputs max\n"}, {"source_code": "\ndef main(numbers)\n odds = numbers.map { |n| n.odd? ? n : n + 1 }\n odds_length = find_greatest(odds)\n evens = numbers.map { |n| n.even? ? n : n + 1 }\n evens_length = find_greatest(evens)\n puts [odds_length, evens_length].max\nend\n\ndef find_greatest(numbers)\n last_number = -100000\n in_a_row = 0\n max_in_a_row = 0\n numbers.each do |n|\n if n == last_number\n in_a_row += 1\n else\n last_number = n\n in_a_row = 1\n end\n max_in_a_row = [max_in_a_row, in_a_row].max\n end\n max_in_a_row\nend\n\nARGF.each_with_index do |line, index|\n if index == 1\n main(line.chomp.split(' ').map(&:to_i))\n end\nend\n"}, {"source_code": "N = gets.to_i\nan = gets.split.map(&:to_i)\n\nl = r = n = 0\nans = 0\nwhile l < N && r < N\n r = l = n\n max = an[r]\n min = an[r]\n until max-min > 1\n r += 1\n break if r >= N\n min, max = [min, max, an[r]].minmax\n n = r if n == l && an[l] != an[r]\n end\n ans = [ans, r - l].max\nend\n\nputs ans\n"}, {"source_code": "# 14462223\nn = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\n\nleft = 0\nprev = 0\nans = 1\ntmp = 0\n(1...n).each do |i|\n d = a[i] - a[i-1]\n if d != 0 then\n if d == tmp then\n left = prev + 1\n end\n tmp = d\n prev = i - 1\n end\n ans = [ans, i - left + 1].max\nend\nputs ans\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nnums = gets.split.map { |s| s.to_i }\n#puts nums\nprev = 0\nprev_pos = 0\nnext_pos = 0\nans = 0\ncurr = []\ncurr_pos = []\nstart = []\n\nnums.size.times do |i|\n if curr.size < 2 then\n curr << nums[i]\n curr_pos << i\n start << i\n elsif not curr.include? nums[i] then\n curr = curr.drop(1)\n if curr_pos[0] > start[1] then\n start[1] = curr_pos[0] + 1\n end\n curr_pos = curr_pos.drop(1)\n start = start.drop(1)\n curr << nums[i]\n curr_pos << i\n start << i\n else\n if curr[0] == nums[i] then\n curr = curr.drop(1)\n curr_pos = curr_pos.drop(1)\n z = start[0]\n start = start.drop(1)\n curr << nums[i]\n curr_pos << i\n start << z\n else\n curr_pos[1] = i\n end\n end\n ans = [ans,curr_pos.max - start.min + 1].max\n #print curr\n #print curr_pos\n #print start\n #puts ans\nend\n\nputs ans\n \n\n \n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\n\nm = 0\n\ncurrent_m = a.shift\nb = [current_m]\n\nuntil a.empty?\n candidate = a.shift\n if candidate > current_m + 1 # candidate == current_m + 2\n last_one = b.index(current_m)\n b.slice!(0..last_one)\n current_m = b.min\n elsif candidate < current_m # candidate == current_m - 1\n last_one = b.index(current_m + 1)\n b.slice!(0..last_one) if last_one\n current_m = b.min\n end\n b << candidate\n m = b.size if b.size > m\nend\n\nputs m\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\n\nm = 0\n\ncurrent_m = a.shift\nb = [current_m]\n\nuntil a.empty?\n candidate = a.shift\n if candidate > current_m + 1\n last_one = b.index(current_m)\n b.slice!(0..last_one)\n current_m += 1\n elsif candidate < current_m\n last_one = b.index(current_m + 1)\n b.slice!(0..last_one) if last_one\n current_m -= 1\n end\n b << candidate\n m = b.size if b.size > m\nend\n\nputs m\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\n\nm = 0\n\ncurrent_m = a.shift\nb = [current_m]\n\nuntil a.empty?\n candidate = a.shift\n if candidate > current_m + 1 # candidate == current_m + 2\n last_one = b.index(current_m)\n b.slice!(0..last_one)\n current_m = b.min\n elsif candidate < current_m # candidate == current_m - 1\n last_one = b.index(current_m + 1)\n b.slice!(0..last_one) if last_one\n current_m = b.min - 1\n end\n b << candidate\n m = b.size if b.size > m\nend\n\nputs m\n"}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\n\nbs = (1...n).map { |i| as[i] - as[i - 1] }\nans = 0\nim, iz, ip = [n, n, n]\nif bs[0] == -1\n im = 0\nelsif bs[0] == 1\n ip = 0\nelse\n iz = 0\nend\nfor i in 1...n - 1\n if bs[i] == -1\n if bs[i - 1] == 0\n if ip == iz - 1\n ans = [ans, i - ip + 2].max\n else\n ans = [ans, i - iz + 2].max\n end\n elsif ip == i - 1\n ans = [ans, 3].max\n elsif im == i - 1\n ans = [ans, 2].max\n end\n im = i\n elsif bs[i] == 1\n if bs[i - 1] == 0\n if im == iz - 1\n ans = [ans, i - im + 2].max\n else\n ans = [ans, i - iz + 2].max\n end\n elsif im == i - 1\n ans = [ans, 3].max\n elsif ip == i - 1\n ans = [ans, 2].max\n end\n ip = i\n else\n if bs[i - 1] == 0\n if iz == 0\n ans = [ans, i - iz + 2].max\n else\n ans = [ans, i - iz + 3].max\n end\n else\n ans = [ans, 2].max\n iz = i\n end\n end\nend\n\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\n\nbs = (1...n).map { |i| as[i] - as[i - 1] }\nans = 0\nim, iz, ip = [n, n, n]\nif bs[0] == -1\n im = 0\nelsif bs[0] == 1\n ip = 0\nelse\n iz = 0\nend\nfor i in 1...n - 1\n if bs[i] == -1\n if bs[i - 1] == 0\n if ip == iz - 1\n ans = [ans, i - ip + 2].max\n else\n ans = [ans, i - iz + 2].max\n end\n elsif ip == i - 1\n ans = [ans, 3].max\n elsif im == i - 1\n ans = [ans, 2].max\n end\n im = i\n elsif bs[i] == 1\n if bs[i - 1] == 0\n if im == iz - 1\n ans = [ans, i - im + 2].max\n else\n ans = [ans, i - iz + 2].max\n end\n elsif im == i - 1\n ans = [ans, 3].max\n elsif ip == i - 1\n ans = [ans, 2].max\n end\n ip = i\n else\n if bs[i - 1] == 0\n if iz == 0\n ans = [ans, i - iz + 2].max\n else\n ans = [ans, i - iz + 3].max\n end\n else\n ans = [ans, 3].max\n iz = i\n end\n end\nend\n\nputs ans\n"}], "src_uid": "b784cebc7e50cc831fde480171b9eb84"} {"source_code": "gets.to_i.times do\n n=gets.chomp.to_i\n s=gets.chomp\n zeros,ones,maxZeros,maxOnes,currentZeros,currentOnes=0,0,0,0,0,0\n s.each_char do |c|\n if c=='0'\n zeros+=1\n currentZeros+=1\n maxZeros=[maxZeros,currentZeros].max\n currentOnes=0\n else\n ones+=1\n currentOnes+=1\n maxOnes=[maxOnes,currentOnes].max\n currentZeros=0\n end\n end\n puts [zeros*ones,maxZeros*maxZeros, maxOnes*maxOnes].max\nend", "positive_code": [{"source_code": "def aaa(_n, s)\r\n s.delete!(\"\\n\")\r\n max0 = s.split(/0+/).map(&:length).sort.reverse[0].to_i\r\n max1 = s.split(/1+/).map(&:length).sort.reverse[0].to_i\r\n arr = [s.delete('0').length * s.delete('1').length, max0*max0, max1*max1]\r\n\r\n puts arr.sort[2]\r\nend\r\n\r\nt = gets.to_i\r\n\r\nt.times do\r\n n = gets.to_i\r\n s = gets\r\n aaa(n, s)\r\nend"}], "negative_code": [], "src_uid": "9070e0d4f8071d1ee8df5189b7c17bfa"} {"source_code": "def read_array\n gets.strip.split(' ').map(&:to_i)\nend\n\ndef can(a, b, x)\n a.each_with_index do |e, i|\n return false if e + b[i] > x\n end\n true\nend\n\ngets.strip.to_i.times do\n n, x = read_array\n a = read_array\n b = read_array\n gets\n\n a.sort!\n b = b.sort.reverse\n if can(a, b, x)\n puts \"Yes\"\n else\n puts \"No\"\n end\nend\n", "positive_code": [{"source_code": "def read\n gets.split.map &:to_i\nend\nq = gets.to_i\nq.times do |t|\n n, x = read\n a, b = read, read\n a.sort!\n b.sort!.reverse!\n ok = true\n (0...n).each do |i|\n ok = false if a[i] + b[i] > x\n end\n puts ok ? \"YES\" : \"NO\"\n if t < q - 1\n gets\n end\nend"}], "negative_code": [{"source_code": "def read\n gets.split.map &:to_i\nend\nq = gets.to_i\nq.times do |t|\n n, x = read\n a, b = read, read\n a.sort!\n b.sort!.reverse!\n ok = true\n (0...n).each do |i|\n ok = false if a[i] + b[i] > x\n end\n print(ok ? \"YES\" : \"NO\")\n if t < q - 1\n gets\n end\nend"}], "src_uid": "7e765c1b0e3f3e9c44de825a79bc1da2"} {"source_code": "#!/usr/bin/env ruby\n\ncur=[0]\ngets.to_i.times{\n\tn=gets.to_i\n\ts=0\n\tidx=(cur.size.times.find{|i|s+=cur[i];s>=n}||cur.size)-1\n\tif idx==-1\n\t\ta=[1]+cur.map{|e|0}\n\telse\n\t\ta=cur.dup\n\t\twhile a[idx]==9\n\t\t\tidx-=1\n\t\tend\n\t\tif idx>=0\n\t\t\ta[idx]+=1\n\t\telse\n\t\t\ta=[1]+a\n\t\t\tidx=0\n\t\tend\n\t\t(idx+1).upto(a.size-1){|i|a[i]=0}\n\tend\n\t#p a\n\tfill=n-a.reduce(:+)\n\tidx=a.size-1\n\twhile idx>=0\n\t\ta[idx]+=fill\n\t\tfill=0\n\t\tif a[idx]>9\n\t\t\tfill=a[idx]-9\n\t\t\ta[idx]=9\n\t\tend\n\t\tidx-=1\n\tend\n\td,r=fill.divmod(9)\n\ta=(r==0?[]:[r])+[9]*d+a\n\tcur=a\n\tputs cur*''\n}", "positive_code": [{"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\ncur = [0]\ngets.to_i.times {\n n = gets.to_i\n s = 0\n idx = (cur.size.times.find{|i|\n s += cur[i]\n s >= n\n } || cur.size) - 1\n if idx == -1\n x = [1] + [0] * cur.size\n else\n x = cur.dup\n while x[idx] == 9\n idx -= 1\n end\n if idx >= 0\n x[idx] += 1\n else\n x = [1] + x\n idx = 0\n end\n (idx + 1).upto(x.size - 1) {|i|\n x[i] = 0\n }\n end\n tot = n - x.reduce(:+)\n idx = x.size - 1\n while idx >= 0\n x[idx] += tot\n tot = 0\n if x[idx] > 9\n tot = x[idx] - 9\n x[idx] = 9\n end\n idx -= 1\n end\n l, r = tot.divmod(9)\n x = (r == 0 ? [] : [r]) + [9] * l + x\n cur = x\n puts cur.join\n}"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\ncur = [0]\ngets.to_i.times {\n n = gets.to_i\n s = 0\n idx = (cur.size.times.find{|i|\n s += cur[i]\n s >= n\n } || cur.size) - 1\n x = cur.dup\n while x[idx] == 9\n idx -= 1\n end\n if idx >= 0\n x[idx] += 1\n else\n x = [1] + x\n idx = 0\n end\n (idx + 1).upto(x.size - 1) {|i|\n x[i] = 0\n }\n tot = n - x.reduce(:+)\n idx = x.size - 1\n while idx >= 0\n x[idx] += tot\n tot = 0\n if x[idx] > 9\n tot = x[idx] - 9\n x[idx] = 9\n end\n idx -= 1\n end\n l, r = tot.divmod(9)\n x = (r == 0 ? [] : [r]) + [9] * l + x\n cur = x\n puts cur.join\n}"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\n\ncur=[0]\ngets.to_i.times{\n\tn=gets.to_i\n\ts=0\n\tidx=(cur.size.times.find{|i|s+=cur[i];s>n}||cur.size)-1\n\tif idx==-1\n\t\ta=[1]+cur.map{|e|0}\n\telse\n\t\ta=cur.dup\n\t\twhile a[idx]==9\n\t\t\tidx-=1\n\t\tend\n\t\tif idx>=0\n\t\t\ta[idx]+=1\n\t\telse\n\t\t\ta=[1]+a\n\t\t\tidx=0\n\t\tend\n\t\t(idx+1).upto(a.size-1){|i|a[i]=0}\n\tend\n\t\n\tfill=n-a.reduce(:+)\n\tidx=a.size-1\n\twhile idx>=0\n\t\ta[idx]+=fill\n\t\tfill=0\n\t\tif a[idx]>9\n\t\t\tfill=a[idx]-9\n\t\t\ta[idx]=9\n\t\tend\n\t\tidx-=1\n\tend\n\td,r=fill.divmod(9)\n\ta=(r==0?[]:[r])+[9]*d+a\n\tcur=a\n\tputs cur*''\n}"}, {"source_code": "#!/usr/bin/env ruby\ndef gen(n)\n\treturn to_enum(:gen,n) if !block_given?\n\td,r=n.divmod(9)\n\ta=(r==0?[]:[r])+[9]*d\n\tdigits=a.size\n\tloop{\n\t\tyield a.join.to_i\n\t\tidx_down=(a.size-1).downto(0).find{|i|a[i]!=0}\n\t\tif idx_down!=0 && idx_up=(idx_down-1).downto(0).find{|i|a[i]<9}\n\t\t\ta[idx_down]-=1\n\t\t\ta[idx_up]+=1\n\t\telse\n\t\t\tdigits+=1\n\t\t\td,r=(n-1).divmod(9)\n\t\t\ta=(r==0?[]:[r])+[9]*d\n\t\t\twhile a.sizecur}\n\tp nxt\n\tcur=nxt\n}"}, {"source_code": "#!/usr/bin/env ruby\ndef gen(n)\n\treturn to_enum(:gen,n) if !block_given?\n\td,r=n.divmod(9)\n\ta=(r==0?[]:[r])+[9]*d\n\tdigits=a.size\n\tloop{\n\t\tyield a.join.to_i\n\t\tidx_down=(a.size-1).downto(0).find{|i|a[i]!=0}\n\t\tif idx_down!=0 && idx_up=(idx_down-1).downto(0).find{|i|a[i]<9}\n\t\t\ta[idx_down]-=1\n\t\t\ta[idx_up]+=1\n\t\t\ta=a[0,idx_down]+a[idx_down..-1].reverse\n\t\telse\n\t\t\tdigits+=1\n\t\t\td,r=(n-1).divmod(9)\n\t\t\ta=(r==0?[]:[r])+[9]*d\n\t\t\twhile a.sizecur}\n\tp nxt\n\tcur=nxt\n}"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\ncur = [0]\ngets.to_i.times {\n n = gets.to_i\n s = 0\n idx = (cur.size.times.find{|i|\n s += cur[i]\n s >= n\n } || cur.size) - 1\n x = cur.dup\n while x[idx] == 9\n idx -= 1\n end\n if idx >= 0\n x[idx] += 1\n else\n x = [1] + x\n idx = 0\n end\n (idx + 1).upto(x.size - 1) {|i|\n x[i] = 0\n }\n tot = n - x.reduce(:+)\n idx = 0\n while idx < x.size\n x[idx] += tot\n tot = 0\n if x[idx] > 9\n tot = x[idx] - 9\n x[idx] = 9\n end\n idx += 1\n end\n l, r = tot.divmod(9)\n x = (r == 0 ? [] : [r]) + [9] * l + x\n cur = x\n puts cur.join\n}"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\ncur = [0]\ngets.to_i.times {\n n = gets.to_i\n s = 0\n idx = (cur.size.times.find{|i|\n s += cur[i]\n s >= n\n } || cur.size) - 1\n if idx == -1\n x = [1] + [0] * cur.size\n else\n x = cur.dup\n while x[idx] == 9\n idx -= 1\n end\n if idx >= 0\n x[idx] += 1\n else\n x = [1] + x\n idx = 0\n end\n (idx + 1).upto(x.size - 1) {|i|\n x[i] = 0\n }\n end\n tot = n - x.reduce(:+)\n idx = x.size - 1\n while idx >= 0\n x[idx] += tot\n tot = 0\n if x[idx] > 9\n tot = x[idx] - 9\n x[idx] = 9\n end\n idx -= 1\n end\n l, r = tot.divmod(9)\n x = (r == 0 ? [] : [r]) + [9] * l + x\n cur = x\n puts cur.to_s\n}"}], "src_uid": "4577a9b2d96110966ad95a960ef7ec20"} {"source_code": "t = gets.to_i\nt.times do |i|\n n = gets.to_i\n a = gets.split.map(&:to_i)\n b = c = 0\n n.times do |i|\n c = a[i] if c < a[i]\n b,c = c,b if c > b\n end\n puts (c-1 < n-2 ? c-1 : n-2)\nend", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n a, b = gets.split.map(&:to_i).sort.reverse\n p [a-1, b-1, n-2].min\nend\n"}], "negative_code": [], "src_uid": "130fd7f40d879e25b0bff886046bf699"} {"source_code": "class A\n def initialize\n n, m, k = gets.chomp.split(' ').map(&:to_i)\n type_list = gets.chomp.split(' ').map(&:to_i)\n cnt = 0\n\n type_list.each do |type|\n if type == 1\n if m > 0\n m -= 1\n else\n cnt += 1\n end\n else\n if k > 0\n k -= 1\n elsif m > 0\n m -= 1\n else\n cnt += 1\n end\n end\n end\n\n puts cnt\n end\nend\n\nA.new", "positive_code": [{"source_code": "n, m, k = gets.split(' ').map(&:to_i)\nwash = 0\ngets.split(' ',n).map(&:to_i).each do |x|\n if x == 1\n m > 0 ? m -= 1 : wash += 1\n elsif k > 0\n k -= 1\n elsif m > 0\n m -= 1\n else\n wash += 1\n end\nend\nputs wash"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nn = 0\ngets.split.map(&:to_i).each do |a|\n if a == 2 and k > 0\n k -= 1\n else\n (m > 0) ? m -= 1 : n += 1\n end\nend\nputs n"}, {"source_code": "\nn, m, k = gets.chomp.split.map(&:to_i);\narr = gets.chomp.split.map(&:to_i);\nans = 0;\n\narr.each do |x|\n if (x == 1) then\n if (m > 0)\n m -= 1;\n else\n ans += 1;\n end\n elsif (k > 0)\n k -= 1;\n elsif (m > 0)\n m -= 1;\n else\n ans += 1;\n end \nend\np ans;\n"}, {"source_code": "#!/usr/bin/ruby\n\nn, m, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nr = 0\na.each do |x|\n if x == 1\n m -= 1\n else # x == 2\n if k > 0\n k -= 1\n else\n m -= 1\n end\n end\n\n if m < 0\n m += 1\n r += 1\n elsif k < 0\n k += 1\n r += 1\n end\nend\n\nputs r\n"}, {"source_code": "n,m,k=gets.split.map{|e| e.to_i}\nxs=gets.split.map{|e| e.to_i}\nans=0\nc1=xs.count{|e|\n\te==1\t\n}\nc2=xs.count{|e|\n\te==2\n}\nans=0\nif c1>m\n\tans=c1-m\nelse\n\tk=m+k-c1\nend\nans+=c2-k if c2>k\nputs ans"}, {"source_code": "l = gets.split(\" \").map { |e| e.to_i }\nglub = l[1]\nplos = l[2]\nans = 0\nmas = gets.split(\" \").map { |e| e.to_i }\nmas.each { |e| \n\tif e == 1 then\n\t\tif glub > 0 then\n\t\t\tglub -= 1\n\t\telse\n\t\t\tans +=1\n\t\tend\n\telse\n\t\tif plos > 0 then\n\t\t\t\tplos -= 1\n\t\telsif glub > 0\n\t\t\tglub -= 1\n\t\telse\n\t\t\tans +=1\n\t\tend\n\tend\n}\nputs ans"}, {"source_code": "def read_next_line\n gets.split.map { |x| x.to_i }\nend\n\n_, m, k = read_next_line\na = read_next_line.inject(Hash.new(0)) { |h, e| h[e] += 1; h }\nd = 0\nc = m - a[1]\nif c > 0\n k += c\nelse\n d = -c\nend\nd += [a[2] - k, 0].max\nputs d"}], "negative_code": [], "src_uid": "4ed5b8055ce48b5ad4e43ed4b06d1b07"} {"source_code": "n = gets.to_i\narray = Array.new\n\nn.times do\n miniarr = gets.chomp.split(\" \")\n miniarr[0] = miniarr[0].to_i\n miniarr[1] = miniarr[1].each_char.to_a.sort.join(\"\")\n array.push miniarr\nend\n#p array\n\ncombcost = Hash.new(1000000)\n\narray.each do |juice|\n cost = juice[0]\n type = juice[1]\n\n if cost < combcost[type]\n combcost[type] = cost\n end\nend\n\nans = [combcost[\"A\"]+combcost[\"B\"]+combcost[\"C\"],combcost[\"A\"]+combcost[\"BC\"],combcost[\"AB\"]+combcost[\"C\"],combcost[\"B\"]+combcost[\"AC\"],combcost[\"AB\"]+combcost[\"BC\"],combcost[\"AC\"]+combcost[\"BC\"],combcost[\"AB\"]+combcost[\"AC\"],combcost[\"ABC\"]].min\n\nif ans>300000\n ans = -1\nend\nputs ans\n", "positive_code": [{"source_code": "def solution\n\n n = gets.to_i\n\n prices = {}\n\n n.times do\n p, l = gets.chomp.split(' ')\n price = p.to_i\n vits = l.chars.sort.join\n\n prices[vits] = price if prices[vits].nil? || prices[vits] > price\n end\n\n def eval_price(prices, fragments)\n frag_prices = fragments.map{ |f| prices[f] }\n frag_prices.reduce(0, :+)\n rescue\n nil\n end\n\n possibilities = [\n %w\"ABC\",\n %w\"A B C\",\n %w\"A BC\",\n %w\"AB C\",\n %w\"B AC\",\n %w\"AB AC\",\n %w\"AB BC\",\n %w\"AC AB\",\n %w\"AC BC\",\n ]\n\n cheapest = possibilities.map{ |p| eval_price(prices, p) }.compact.min || -1\n\n puts cheapest\nend\n\nsolution unless ENV['TEST__MODE']\n"}, {"source_code": "n = gets.to_i\nm = n.times.map{gets.split}\nn.times do |i|\n m[i][0] = m[i][0].to_i\nend\n\ndef clac_min(str,n,m)\n ret = 10**6\n for i in 0..n-1\n if str.size == 1\n if m[i][1].include?(str)\n ret = m[i][0] if m[i][0] < ret\n end\n elsif str.size == 2\n if m[i][1].include?(str[0]) && m[i][1].include?(str[1])\n ret = m[i][0] if m[i][0] < ret\n end\n else\n if m[i][1].include?(str[0]) && m[i][1].include?(str[1]) && m[i][1].include?(str[2])\n ret = m[i][0] if m[i][0] < ret\n end\n end\n end\n return ret\nend\n\na,b,c = clac_min(\"A\",n,m),clac_min(\"B\",n,m),clac_min(\"C\",n,m)\nab,bc,ca = [clac_min(\"AB\",n,m),a+b].min,ab = [clac_min(\"BC\",n,m),b+c].min,ab = [clac_min(\"CA\",n,m),c+a].min\nabc = [a+b+c,ab+c,a+bc,b+ca,clac_min(\"ABC\",n,m)].min\nputs abc == 10**6 ? -1 : abc\n"}], "negative_code": [], "src_uid": "02d62bb1eb4cc0e373b862a980d6b29c"} {"source_code": "gets.to_i.times do\r\n q,d=gets.split.map(&:to_i)\r\n a=gets.split.map(&:to_i)\r\n a.each do |aa|\r\n if aa>=100\r\n puts \"YES\"\r\n else\r\n f=false\r\n while aa>0\r\n if aa/10==d||aa%10==d\r\n puts \"YES\"\r\n f=true\r\n break\r\n end\r\n aa-=d\r\n end\r\n puts \"NO\" if !f\r\n end\r\n end\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n q,d=gets.split.map(&:to_i)\r\n a=gets.split.map(&:to_i)\r\n a.each do |aa|\r\n if d==1\r\n puts \"YES\"\r\n elsif d==2\r\n if aa>=20||aa.even?\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n elsif d==3\r\n if aa>=21||aa%3==0||[13,16,19].include?(aa)\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n elsif d==4\r\n if aa>=40||aa%4==0||aa>=14&&aa%4==2\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n elsif d==5\r\n if aa>=50||aa%5==0\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n elsif d==6\r\n if aa>=60||aa%6==0||aa>=22&&aa%2==0||aa==16\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n elsif d==7\r\n if aa>=61||aa%7==0||aa>=17&&aa%7==3||aa>=27&&aa%7==6||aa>=37&&aa%7==2||[47,54,57].include?(aa)\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n elsif d==8\r\n if aa>=80||aa%8==0||aa>=32&&aa%2==0||[18,26,28].include?(aa)\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n elsif d==9\r\n if aa>=81||aa/10+aa%10>=9\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n end\r\n end\r\nend\r\n\r\n"}], "negative_code": [], "src_uid": "7975af65a23bad6a0997921c7e31d3ca"} {"source_code": "gets\ns=0\ngets.split.map(&:to_i).each_cons(2){|i,j|s+=i-j if j self[i]\n return false\n end\n a = self[i]\n end\n return true\n end\nend\n\nn = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|e| e.to_i}\nc = 0\n\nfor i in 1 .. (n - 1) do\n first = a[i - 1]\n second = a[i]\n \n if first > second\n d = first - second\n \"\"\"\n for j in i .. (n -1) do\n a[j] += d\n end \n \"\"\"\n c += d\n end \nend\n\nputs c\n"}, {"source_code": "gets\ns=0\ngets.split.map(&:to_i).each_cons(2){|i,j|s+=i-j if j numbers[i+1])\n diff = numbers[i] - numbers[i+1]\n counter += diff\n end\n}\n\nputs counter\n"}, {"source_code": "gets\ns=0\ngets.split.map(&:to_i).each_cons(2){|i,j|s+=i-j if ji) ? a-i : 0\n\ta=i\nend\nputs ans\n\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\nr = 0\n(1..a.length-1).each do |i|\n k = a[i-1]-a[i]\n r+=k if k>=0\nend\nputs r\n"}, {"source_code": "gets\ns=0\ngets.split.map(&:to_i).each_cons(2){|i,j|s+=i-j if j a[i + 1])\n}\nputs r\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |i| i.to_i }\nc, d, r = 0, 1 << 40, 0\n1.upto(n - 1) { |i|\n if a[i] < a[i - 1] \n c = [c, a[i - 1]].max \n d = [d, a[i]].min\n else\n r += [0, c - d].max \n c, d = 0, 1 << 40\n end\n}\nputs r + [0, c - d].max\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |i| i.to_i }\nputs (0..n - 2).inject(0) { |r, i|\n r + [0, a[i] - a[i + 1]].max \n}\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\ns=0\n(n-1).times{|i|s+=[0,a[i]-a[i+1]].max}\np s\n"}, {"source_code": "gets\ns=0\ngets.split.map(&:to_i).each_cons(2){|i,j|s+=i-j if j a[i]\n c = [c, a[i - 1] - a[i]].max\n a[i] = a[i - 1] \n end\n}\nputs c\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |i| i.to_i }\nc, r = 0, 0\n1.upto(n - 1) { |i|\n if a[i - 1] > a[i]\n c = [c, a[i - 1] - a[i]].max\n a[i] += c \n r = c\n end\n}\nputs c\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |i| i.to_i }\nc, d, r = 0, 1 << 40, 0\n1.upto(n - 1) { |i|\n if a[i] < a[i - 1] \n c = [c, a[i - 1]].max \n d = [d, a[i]].min\n else\n r += c - d \n c, d = 0, 1 << 40\n end\n}\nputs r + [0, c - d].max\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |i| i.to_i }\nc, r = 0, 0\n1.upto(n - 1) { |i|\n if a[i - 1] > a[i]\n c = [c, a[i - 1] - a[i]].max\n a[i] += c \n r += c\n end\n}\nputs c\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |i| i.to_i }\nputs (0..n - 2).inject { |r, i|\n r + [0, a[i] - a[i + 1]].max \n}\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |i| i.to_i }\nc, r = 0, 0\n1.upto(n - 1) { |i|\n if a[i] < a[i - 1] \n c = [c, a[i - 1] - a[i]].max \n a[i] = a[i - 1]\n else\n r += c\n c = 0 \n end\n}\nputs r + c\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |i| i.to_i }\nc, r= 0, 0\n1.upto(n - 1) { |i|\n if a[i - 1] > a[i]\n c = a[i - 1] - a[i]\n a[i] += c \n r += c\n end\n}\nputs c\n"}], "src_uid": "1cd295e204724335c63e685fcc0708b8"} {"source_code": "given = STDIN.readline.strip.split('')\ndigits = STDIN.readline.strip.split('').sort.reverse\npos = 0\ndigits.each do |digit|\n while pos < given.length and given[pos] >= digit\n pos += 1\n end\n break if pos == given.length\n given[pos] = digit\n pos += 1\nend\nputs given.join\n\n", "positive_code": [{"source_code": "a = gets.scan(/\\d/).map(&:to_i)\nc = [0] * 10\ngets.scan(/\\d/) do |_|\n c[_.to_i] += 1\nend\na.size.times do |i|\n k = c.rindex{|_| _ > 0}\n if k && k > a[i]\n a[i] = k\n c[k] -= 1\n end\nend\nputs a * ''\n"}, {"source_code": "a = readline.strip.each_char.to_a\ns = readline.strip.each_char.to_a.sort\n\nans = a.each.map { |ai| (ai.to_i >= s.last.to_i) ? ai : s.pop }\nputs ans.join\n"}, {"source_code": "# encoding: utf-8\n\ndef string_to_digit_array(s)\n ret = []\n s.each_char do |c|\n ret << c\n end\n ret\nend\n\na = string_to_digit_array(readline.strip)\ns = string_to_digit_array(readline.strip).sort\n\nans = []\na.each do |digit|\n if digit.to_i >= s.last.to_i\n ans << digit\n else\n ans << s.pop\n end\nend\n\nputs ans.join\n"}, {"source_code": "# ProblemB.rb\n\na = gets.chomp.split(//)\ns = gets.chomp\n\ns = s.split(//).sort.reverse\n\nj = 0\na.each_with_index do |c, i|\n if j == s.size\n break\n end\n if c < s[j]\n a[i] = s[j]\n j += 1\n end\nend\n\nputs a.join\n"}, {"source_code": "n = gets.chomp.split(\"\")\ndlina = n.length\nk = gets.chomp.split(\"\")\ndlina2 = k.length\nk = k.sort\np = dlina2-1\n\nfor i in (0..dlina-1)\n n[i] = n[i].to_i\nend \n\nfor i in (0..p)\n k[i] = k[i].to_i\nend\n\nfor i in (0..dlina-1)\n if k[p] > n[i] then\n n[i] = k[p]\n p-=1\n end\n\n if p < 0 then \n break\n end\nend\n\nfor i in 0..dlina-1 do\n print n[i]\nend"}], "negative_code": [{"source_code": "# encoding: utf-8\n\na = readline\ns = readline\nputs (a+s)\n"}, {"source_code": "# ProblemB.rb\n\na = gets.chomp.split(//)\ns = gets.chomp\n\ns = s.split(//).sort.reverse\n\nj = 0\na.each_with_index do |c, i|\n if c < s[j]\n a[i] = s[j]\n j += 1\n end\nend\n\np a.join\n"}], "src_uid": "a2cd56f2d2c3dd9fe152b8e4111df7d4"} {"source_code": "t = gets.to_i\n\n1.upto(t) do\n n = gets.to_i\n\n 2.upto(32) do |k|\n next unless n.modulo((2 ** k) - 1).zero?\n\n puts n.div((2 ** k) - 1)\n break\n end\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n k = 2\n loop do\n s = 2**k - 1\n if n%s == 0\n puts n/s\n break\n end\n k += 1\n end\nend\n"}, {"source_code": "t=gets.to_i\n(1).upto(t) do\n n=gets.to_i\n k=4\n a=3\n while n.modulo(a)!=0\n a+=k\n k<<=1\n end\n puts n/a\nend\n"}, {"source_code": "# Author : Fuad Ashraful Mehmet \n#Date: 22th April\n\nt=gets.to_i\n\ndef Solve()\n n=gets.to_i\n k=4\n a=3\n while n.modulo(a)!=0\n a+=k\n k<<=1\n end\n\n return n/a\nend\n(1).upto(t) do\n\n puts Solve()\nend "}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ti = (2..64).find { |i| n % (2**i - 1) == 0 }\n\tputs n / (2**i - 1)\nend\n"}, {"source_code": "class Result\n def print_result\n n = gets.to_i\n 2.upto(29) do |i|\n if n % (2**i - 1) == 0\n puts n / (2**i - 1)\n break\n end\n end\n end\nend\n\ngets.to_i.times do\n Result.new.print_result\nend"}, {"source_code": "1.upto(gets.chomp.to_i) do\n n = gets.chomp.to_i\n k = 2\n m = 4\n while n % (m-1) != 0\n m *= 2;\n k += 1;\n end\n puts n / (m-1)\nend\n"}, {"source_code": "number_of_testcases = gets.to_s.to_i\n\nnumber_of_testcases.times do |i|\n \n n = gets.to_s.to_i\n s = 2\n loop do \n \n s *= 2\n t = s - 1\n if n % t == 0\n puts n / t\n break\n end\n end\nend\n\n"}], "negative_code": [], "src_uid": "d04cbe78b836e53b51292401c8c969b2"} {"source_code": "p,n = gets.split.map{|i| i.to_i}\nh=[]\nn.times{|i| h<0}\nk=0\n1.upto(a[0].to_i-1) do |i|\nhash[\"#{i}\"]=0\nend\n\n1.upto(a[1].to_i) do |i|\ntemp=(gets.chomp.to_i)%a[0].to_i\nhash[\"#{temp}\"]+=1\nif hash[\"#{temp}\"]>1 && k==0\nk=i\nend\nend\n\nif k==0\nputs \"-1\"\nelse \nputs \"#{k}\"\nend"}, {"source_code": "p,n = gets.split.map{|i| i.to_i}\nh=[]\nn.times{|i| h<0}\nk=0\n1.upto(a[0].to_i-1) do |i|\nhash[\"#{i}\"]=0\nend\n\n1.upto(a[1].to_i) do |i|\ntemp=(gets.chomp.to_i)%a[0].to_i\nhash[\"#{temp}\"]+=1\nif hash[\"#{temp}\"]>1 && k==0\nk=i\nend\nend\n\nif k==0\nputs \"-1\"\nelse \nputs \"#{k}\"\nend"}, {"source_code": "numbers = gets.split(' ')\np = numbers[0].to_i\nn = numbers[1].to_i\n\nconflicts = false\nhashtable = Array.new()\nn.times do |i|\n x = gets.to_i\n next if conflicts\n if hashtable[x % p].nil?\n hashtable[x % p] = x\n else\n conflicts = true\n puts i + 1\n end\nend\n\nputs -1 unless conflicts"}, {"source_code": "p,n = gets.split.map{|i| i.to_i}\nh=[]\nn.times{|i| h<0}\nk=0\n1.upto(a[0].to_i-1) do |i|\nhash[\"#{i}\"]=0\nend\n\n1.upto(a[1].to_i) do |i|\ntemp=(gets.chomp.to_i)%a[0].to_i\nhash[\"#{temp}\"]+=1\nif hash[\"#{temp}\"]>1 && k==0\nk=i\nend\nend\n\nif k==0\nputs \"-1\"\nelse \nputs \"#{k}\"\nend"}, {"source_code": "p,n=gets.split.map(&:to_i)\n\nmyHash=Hash.new()\n\nfor i in 0...n do\n myHash[i]=nil\nend\n\nfound=-1\nfor i in 1..n do \n x=gets.split[0].to_i\n h=x%p\n if(myHash[h]==nil)\n myHash[h]=x\n else \n found=i\n break\n end\nend\n\np found\n"}, {"source_code": "p, n = gets.split(\" \").collect { |e| e.to_i}\n\narr = Array.new(p) { |i| 0}\ni = 1\nwhile i <= n\n num = gets.to_i\n mod = num % p\n if arr[mod] == 1\n break\n end\n arr[mod] += 1\n i += 1\nend\nputs i == n + 1 ? \"-1\" : i"}, {"source_code": "p,n = gets.split.map{|i| i.to_i}\nh=[]\nn.times{|i| h< 2 \nend\n\nif res == \"No\"\n puts res\nelse\n a.sort!\n b = a.select.with_index { |e, idx| idx.even? }\n c = a.select.with_index { |e, idx| idx.odd? }\n puts \"Yes\"\n puts b.count\n puts b.join(\" \")\n puts c.count\n puts c.reverse.join(\" \")\nend\n\n\n", "positive_code": [{"source_code": "gets.chomp\na = gets.chomp.split(\" \").map(&:to_i).sort\n\ninc = [a.shift]\ndec = []\na = a.reduce([]) do |acc, x|\n x > inc.last ? inc.push(x) : acc.push(x)\n acc\n end\n\na.reverse!\n\ndec.push(a.shift) if a.size > 0\na = a.reduce([]) do |acc, x|\n x < dec.last ? dec.push(x) : acc.push(x)\n acc\n end\n\nif a.size == 0\n puts \"YES\"\n puts inc.size\n inc.each_with_index { |x, i| print \" \" if i > 0; print x }\n print \"\\n\"\n puts dec.size\n dec.each_with_index { |x, i| print \" \" if i > 0; print x }\n print \"\\n\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nx = []\ny = []\nn.times do |i|\n if i == 0 || a[i] != a[i-1]\n x << a[i]\n else\n y << a[i]\n end\nend\nif x.uniq.size == x.size && y.uniq.size == y.size\n puts \"YES\",x.size,x.join(\" \"),y.size,y.reverse.join(\" \")\nelse\n puts \"NO\"\nend"}], "negative_code": [{"source_code": "\nn = gets.strip.to_i\na = gets.strip.split(\" \").map(&:to_i)\n\nh = Hash.new(0)\n\nres = \"\"\na.each do |e|\n h[e] += 1\n res = \"No\" if h[e] > 2 \nend\n\nif res == \"No\"\n puts res\nelse\n a.sort!\n b = a.select.with_index { |e, idx| idx.even? }\n c = a.select.with_index { |e, idx| idx.odd? }\n puts \"Yes\"\n puts b.reduce(&:+)\n puts b.join(\" \")\n puts c.reduce(&:+)\n puts c.reverse.join(\" \")\nend\n\n\n"}], "src_uid": "cdb19d87ad3713dac104252737153411"} {"source_code": "n, m, k = gets.split.map(&:to_i)\nv = m.times.map{gets.split.map(&:to_i)}\ns = Array.new(n+1, false)\ngets.split.map(&:to_i).each {|x| s[x] = true } if k>0\nans = nil\nv.each { |a, b, l| ans = l if (s[a]^s[b])&&(ans.nil? || l 0 ? gets.split.map(&:to_i) : []\narr.each{|x| storage[x] = true}\nans = nil\ndata.each do |a, b, l|\n ans = l if (storage[a] ^ storage[b]) && (ans.nil? || l < ans)\nend\nputs ans.nil? ? -1 : ans\n"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nN, M, K = gis\nUVL = ngis M\nST = K > 0 ? gis : []\n\nh = [-1] * (N + 1)\nf = [true] * (N + 1)\n\nST.each do |a|\n f[a] = false\nend\n\nmn = nil\n\nUVL.each do |u, v, l|\n next if !(f[u] ^ f[v])\n mn = l if mn.nil? || l < mn\nend\n\nputs mn.nil? ? -1 : mn\n\n\n\n\n"}, {"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\nfirst = Array.new(100009)\nsecond = Array.new(100009)\nlen = Array.new(100009)\n\ncities, roads, k = read_numbers_to_array\nfor i in 0..roads - 1 do\n first[i], second[i], len[i] = read_numbers_to_array\nend\n\nshortest = -1\nif k > 0\nb = read_numbers_to_array\nbakers = Array.new(cities + 9, false)\n\nb.each do |i|\n bakers[i] = true\nend\n\nfor i in 0..roads - 1 do\n if bakers[first[i]] != bakers[second[i]] && (shortest == - 1 || len[i] < shortest)\n shortest = len[i]\n end\nend\nend\n\nputs shortest\n"}, {"source_code": " class Node\n\tattr_accessor :dest, :val\n\n\tdef initialize dest, val\n\t\t@dest = dest\n\t\t@val = val\n\tend\n\n\tdef to_s\n\t\tprint \"Dest : #{dest}, Val : #{val}\"\n\tend\nend\n\nn, m, k = gets.chomp.split(' ').map(&:to_i)\nfound = false\nnearest = Array.new(n + 1) { |i| i = {} }\n\n\nm.times do\n\tu, v, l = gets.chomp.split(' ').map(&:to_i)\n\n\tif u != v\n\t\tif nearest[u].has_key? v\n\t\t\tif nearest[u][v] > l\n\t\t\t\tnearest[u][v] = l\n\t\t\tend\n\t\telse\n\t\t\tnearest[u][v] = l\n\t\tend\n\n\t\tif nearest[v].has_key? u\n\t\t\tif nearest[v][u] > l\n\t\t\t\tnearest[v][u] = l\n\t\t\tend\n\t\telse\n\t\t\tnearest[v][u] = l\n\t\tend\n\tend\nend\n\nstorage = Array.new(n + 1) { |i| i = false }\n\nif k > 0\n\tinputStorage = gets.chomp.split(' ').map(&:to_i)\n\n\tinputStorage.each do |i|\n\t\tstorage[i] = true\n\tend\nend\n\nans = 1000000000000\n\n1.upto(n) do |city|\n\tnext if !storage[city]\t\n\n\tnearest[city].each do |dest, val|\n\t\tif !storage[dest]\n\t\t\tans = val if ans > val\n\t\t\tfound = true\n\t\tend\n\tend\nend\n\nif !found\n\tputs -1\nelse\n\tputs ans\nend"}], "negative_code": [{"source_code": "n, m, k = gets.split.map(&:to_i)\nnn = 1000000000\nh = Hash.new(nn)\nm.times do\n a, b, l = gets.split.map(&:to_i)\n h[a] = [h[a], l].min\n h[b] = [h[b], l].min\nend\narr = k > 0 ? gets.split.map(&:to_i) : []\nmi = h[arr.min_by{|x| h[x]}]\nputs mi.nil? || mi == nn ? -1 : mi\n"}, {"source_code": "class Node\n\tattr_accessor :dest, :val\n\n\tdef initialize dest, val\n\t\t@dest = dest\n\t\t@val = val\n\tend\nend\n\nn, m, k = gets.chomp.split(' ').map(&:to_i)\nfound = false\nnearest = Array.new(n + 1) { |i| i = Node.new(-1, 100000000) }\n\n\nm.times do\n\tu, v, l = gets.chomp.split(' ').map(&:to_i)\n\n\tif u != v\n\tif nearest[u].val > l\n\t\tnearest[u].dest = v\n\t\tnearest[u].val = l\n\tend\n\n\tif nearest[v].val > l\n\t\tnearest[v].dest = u\n\t\tnearest[v].val = l\n\tend\n\tend\nend\n\nstorage = Array.new(k + 1) { |i| i = false }\n\nif k > 0\n\tinputStorage = gets.chomp.split(' ').map(&:to_i)\n\n\tinputStorage.each do |i|\n\t\tstorage[i] = true\n\tend\nend\n\nans = 100000000\n\n1.upto(n) do |city|\n\t#puts \"city = #{city}\"\n\n\tnext if !storage[city]\t\n\tnext if nearest[city].dest < 0\n\n\tif !storage[nearest[city].dest]\n\t\tans = nearest[city].val if ans > nearest[city].val\n\t\tfound = true\n\tend\n\n\t#puts \"ans = #{ans}\"\nend\n\nif !found\n\tputs -1\nelse\n\tputs ans\nend"}, {"source_code": "class Node\n\tattr_accessor :dest, :val\n\n\tdef initialize dest, val\n\t\t@dest = dest\n\t\t@val = val\n\tend\nend\n\nn, m, k = gets.chomp.split(' ').map(&:to_i)\nfound = false\nnearest = Array.new(n + 1) { |i| i = Node.new(-1, 100000000) }\n\n\nm.times do\n\tu, v, l = gets.chomp.split(' ').map(&:to_i)\n\n\tif nearest[u].val > l\n\t\tnearest[u].dest = v\n\t\tnearest[u].val = l\n\tend\n\n\tif nearest[v].val > l\n\t\tnearest[v].dest = u\n\t\tnearest[v].val = l\n\tend\nend\n\nstorage = Array.new(k + 1) { |i| i = false }\n\nif k > 0\n\tinputStorage = gets.chomp.split(' ').map(&:to_i)\n\n\tinputStorage.each do |i|\n\t\tstorage[i] = true\n\tend\nend\n\nans = 100000000\n\n1.upto(n) do |city|\n\t#puts \"city = #{city}\"\n\n\tnext if !storage[city]\t\n\tnext if nearest[city].dest < 0\n\n\tif !storage[nearest[city].dest]\n\t\tans = nearest[city].val if ans > nearest[city].val\n\t\tfound = true\n\tend\n\n\t#puts \"ans = #{ans}\"\nend\n\nif !found\n\tputs -1\nelse\n\tputs ans\nend"}, {"source_code": "class Node\n\tattr_accessor :dest, :val\n\n\tdef initialize dest, val\n\t\t@dest = dest\n\t\t@val = val\n\tend\nend\n\nn, m, k = gets.chomp.split(' ').map(&:to_i)\nfound = false\nnearest = Array.new(n + 1) { |i| i = Node.new(-1, 100000000) }\n\n\nm.times do\n\tu, v, l = gets.chomp.split(' ').map(&:to_i)\n\n\tif nearest[u].val > l\n\t\tnearest[u].dest = v\n\t\tnearest[u].val = l\n\tend\n\n\tif nearest[v].val > l\n\t\tnearest[v].dest = u\n\t\tnearest[v].val = l\n\tend\nend\n\nstorage = Array.new(k + 1) { |i| i = false }\n\nif k > 0\n\tinputStorage = gets.chomp.split(' ').map(&:to_i)\n\n\tinputStorage.each do |i|\n\t\tstorage[i] = true\n\tend\nend\n\nans = 0\n\n1.upto(n) do |city|\n\tnext if !storage[city]\t\n\t\n\tif !storage[nearest[city].dest]\n\t\tans = nearest[city].val\n\t\tfound = true\n\tend\nend\n\nif !found\n\tputs -1\nelse\n\tputs ans\nend"}, {"source_code": " class Node\n\tattr_accessor :dest, :val\n\n\tdef initialize dest, val\n\t\t@dest = dest\n\t\t@val = val\n\tend\n\n\tdef to_s\n\t\tprint \"Dest : #{dest}, Val : #{val}\"\n\tend\nend\n\nn, m, k = gets.chomp.split(' ').map(&:to_i)\nfound = false\nnearest = Array.new(n + 1) { |i| i = {} }\n\n\nm.times do\n\tu, v, l = gets.chomp.split(' ').map(&:to_i)\n\n\tif u != v\n\t\tif nearest[u].has_key? v\n\t\t\tif nearest[u][v] > l\n\t\t\t\tnearest[u][v] = l\n\t\t\tend\n\t\telse\n\t\t\tnearest[u][v] = l\n\t\tend\n\n\t\tif nearest[v].has_key? u\n\t\t\tif nearest[v][u] > l\n\t\t\t\tnearest[v][u] = l\n\t\t\tend\n\t\telse\n\t\t\tnearest[v][u] = l\n\t\tend\n\tend\nend\n\nstorage = Array.new(n + 1) { |i| i = false }\n\nif k > 0\n\tinputStorage = gets.chomp.split(' ').map(&:to_i)\n\n\tinputStorage.each do |i|\n\t\tstorage[i] = true\n\tend\nend\n\nans = 100000000\n\n1.upto(n) do |city|\n\tnext if !storage[city]\t\n\n\tnearest[city].each do |dest, val|\n\t\tif !storage[dest]\n\t\t\tans = val if ans > val\n\t\t\tfound = true\n\t\tend\n\tend\nend\n\nif !found\n\tputs -1\nelse\n\tputs ans\nend"}], "src_uid": "b0e6a9b500b3b75219309b5e6295e105"} {"source_code": "t=gets.to_i\nfor i in 1..t\n a,b,c,d = gets.split(\" \").map(&:to_i)\n sum=0\n if(a<=b)\n print(b,\"\\n\")\n elsif(d>=c)\n print(-1,\"\\n\")\n else\n sum += b\n a -= b\n tt = (a.to_f/(c-d)).ceil()\n sum += tt*c\n print(sum,\"\\n\")\n end\nend\n", "positive_code": [{"source_code": "t=gets.to_i\nfor i in 1..t\n a,b,c,d = gets.split(\" \").map(&:to_i)\n sum=0\n if(a<=b)\n print(b,\"\\n\")\n elsif(d>=c)\n print(-1,\"\\n\")\n else\n sum += b\n a -= b\n sum += ((a+c-d-1)/(c-d)*c).floor()\n print(sum,\"\\n\")\n end\nend\n"}], "negative_code": [], "src_uid": "1ab174688ba76168ca047ed2b06b0670"} {"source_code": "n, m = gets.chomp.split(' ').map{|x| x.to_i}\nstr = gets.chomp\nif m == 2## time complexity = n\n a = \"AB\" * (n/2.to_i)\n b = \"BA\" * (n/2.to_i)\n if n%2 == 1\n a += 'A'\n b += 'B'\n end\n p1 = 0\n p2 = 0\n (0..str.length-1).each do |i|\n if a[i] != str[i]\n p1 += 1\n end\n if b[i] != str[i]\n p2 += 1\n end\n end\n if p1 <= p2\n puts p1, a\n else\n puts p2, b\n end\nelse #time complexity = 26*n\n pa = 0\n res = str.split('')\n\n for i in (1 .. res.length-1)\n if res[i] == res[i-1]\n s1 = res[i-1]\n s2 = res[i+1]\n\n if s1 != 'A' and s2 != 'A'\n res[i] = 'A'\n elsif s1 != 'B' and s2 != 'B'\n res[i] = 'B'\n else\n res[i] = 'C'\n end\n pa += 1\n end\n end\n puts pa, res.join('')\nend", "positive_code": [{"source_code": "n, m = gets.chomp.split(' ').map{|x| x.to_i}\nstr = gets.chomp\nres = str.chars\nif m == 2## time complexity = n\n a = \"AB\" * (n/2.to_i)\n b = \"BA\" * (n/2.to_i)\n if n%2 == 1\n a += 'A'\n b += 'B'\n end\n p1 = 0\n p2 = 0\n (0..res.length-1).each do |i|\n if a[i] != res[i]\n p1 += 1\n end\n if b[i] != res[i]\n p2 += 1\n end\n end\n if p1 <= p2\n puts p1, a\n else\n puts p2, b\n end\nelse #time complexity = 26*n\n pa = 0\n\n for i in (1 .. res.length-1)\n if res[i] == res[i-1]\n s1 = res[i-1]\n s2 = res[i+1]\n\n if s1 != 'A' and s2 != 'A'\n res[i] = 'A'\n elsif s1 != 'B' and s2 != 'B'\n res[i] = 'B'\n else\n res[i] = 'C'\n end\n pa += 1\n end\n end\n puts pa, res.join('')\nend"}], "negative_code": [], "src_uid": "0ecf60ea733eba71ef1cc1e736296d96"} {"source_code": "d = gets.to_i\ngets\na = gets.split.map(&:to_i)\nc = 0\na.pop\n\na.each do |i|\n c += d - i\nend\np c\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\nm = gets.chomp.to_i\na = gets.chomp.split(/ /).map!{|x| x.to_i}\nret = 0\nfor i in 0..m-2\n ret += (n - a[i])\nend\nputs ret"}, {"source_code": "d = gets.to_i\ngets\np gets.split.map{|_| d - _.to_i}[0..-2].inject(&:+) || 0\n"}, {"source_code": "\ufeffd = gets.chomp.to_i\nn = gets.chomp.to_i\ndays = gets.chomp.split(\" \").map{|e| e.to_i}\n\nans = 0\n\nfor i in (0..(n - 2)) do\n ans += d - days[i]\nend\n\nputs ans\n"}, {"source_code": "n=gets.to_i;r=gets.to_i;a=gets.chomp.split.map(&:to_i)\nputs (r*n)-a.inject(:+)-(n-a.last)"}, {"source_code": "d = gets.to_i\nn = gets.to_i\nputs gets.split.map(&:to_i)[0..-2].inject(0) {|acc, x| acc + d - x }"}, {"source_code": "d = gets.to_i\nn = gets.to_i\na = gets.split(' ').map(&:to_i)\nans = 0\n\n(n-1).times do |i|\n ans += d - a[i]\nend\nputs ans"}, {"source_code": "d = gets.to_i\nn = gets.to_i\na = gets.split.map(&:to_i)\n\ns = 0\n0.upto(a.size-2) do |i|\n s += (d-a[i])\nend\nputs s\n"}, {"source_code": "d = gets.to_i\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nans = arr[0..-2].map{|a| d - a}\nputs ans.inject(0,:+)\n# "}, {"source_code": "d = gets.to_i\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nans = arr[0..-2].map{|a| d - a}\nputs ans.inject(0,:+)"}, {"source_code": "def main\n d = STDIN.gets.to_i\n n = STDIN.gets.to_i\n a = STDIN.gets.split\n s = 0\n (n - 1).times do |i|\n s += d - a[i].to_i\n end\n puts s\nend\n\nmain\n"}, {"source_code": "# ProblemB\n\nd = gets.to_i\nn = gets.to_i\nary = gets.split().map {|s| s.to_i}\n\nret = 0\n\ni = 0\nwhile i < (ary.size - 1)\n ret += (d - ary[i])\n i += 1\nend\n\nputs ret\n \n"}, {"source_code": "n = gets.chomp.to_i\nmes = gets.chomp.to_i\ndni = gets.chomp.split(\" \")\n\n\nlength = dni.length\n\nfor i in(0..length-1)\n dni[i] = dni[i].to_i\nend\n\nk = 0\np = 0\n\nfor i in(0..length-2)\n\n k = n - dni[i]\n p+=k\nend\n\nputs p"}], "negative_code": [{"source_code": "d = gets.to_i\nn = gets.to_i\nputs gets.split.map(&:to_i)[1..-1].inject(0) {|acc, x| acc + d - x }"}, {"source_code": "d = gets.to_i\nn = gets.to_i\nputs gets.split.map(&:to_i)[0..-1].inject(0) {|acc, x| acc + d - x }"}], "src_uid": "dc5ddfc2d2e5589eb91aa33744c8fd14"} {"source_code": "n = gets.chomp.to_i\ntab = gets.chomp\ns = 1\nt = tab[0]\ne = 0\nfor i in 1...tab.length\n\tif t != tab[i]\n\t\ts += 1\n\t\tt = tab[i]\n\tend\n\tif (tab[i] == tab[i-1] and tab[i]== '0') or (tab[i] == tab[i-1] and tab[i] == '1')\n\t\te += 1\n\t\te = [e, 2].min\n\tend\nend\nputs s+e\n", "positive_code": [{"source_code": "gets\ns = gets.chomp\nn = s.chars.inject([0, nil]) do |(things, last), ch|\n if ch == last\n [things, ch]\n else\n [things + 1, ch]\n end\nend.first\n\nif s.scan(/(.)\\1/).size > 1 || /(.)\\1\\1/ =~ s\n puts n + 2\nelsif /(.)\\1/ =~ s\n puts n + 1\nelse\n puts n\nend\n"}, {"source_code": "n = gets.to_i\ns = gets\nc = 0\nfor i in 0...n-1 do\n c += 1 if s[i] == s[i+1] \nend\nc-=2\nans = c > 0 ? c : 0\nputs n-ans"}, {"source_code": "n = gets.chomp.to_i\nstr = gets.chomp\n\ncnt2 = 0\ncnt3 = 0\nls = [1]\nfor i in 1...n\n if str[i - 1] == str[i]\n ls[-1] += 1\n cnt2 += 1 if ls[-1] == 2\n cnt3 += 1 if ls[-1] == 3\n else\n ls << 1\n end\nend\n\nans = ls.size\nif 2 <= cnt2 || 1 <= cnt3\n ans += 2\nelsif 1 <= cnt2\n ans += 1\nend\n\nputs ans\n"}, {"source_code": "#!/usr/bin/ruby \n\nlen = gets.to_i\nscore = gets.strip()\nchar = '-'\nalter = 0\nfor ch in 0..len - 1\n if char == '-' or char != score[ch]\n char = score[ch]\n alter += 1\n end\nend\nputs [alter + 2, len].min\n\n=begin\nmin(len, maxi + 2)\n=end\n"}, {"source_code": "len = gets.to_i\ns = gets\ncnt = 1\n1.upto(len - 1){|i|\n cnt += 1 if s[i] != s[i - 1]\n}\nputs [len.to_i, cnt + 2].min"}, {"source_code": "n = $stdin.readline.to_i\nans = $stdin.readline.strip\n\nsubseqs = []\nfrom = 0\nans.each_char.each_cons(2).with_index{|(fst,snd),ind|\n if fst == snd\n subseqs << [from, ind]\n from = ind + 1\n end\n}\nsubseqs << [from, ans.size - 1]\n\n# if subseqs.size >= 3\n# puts subseqs.each_cons(3).map{|a,b,c|\n# c.last - a.first + 1\n# }.max\n# else\n# puts ans.size\n# end\n\nputs subseqs.map{|subseq| subseq[1] - subseq[0] + 1 - 1 }.inject(&:+) + 1 + (subseqs.length > 2 ? 2 : (subseqs.length > 1 ? 1 : 0))\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby \n\nlen = gets.to_i\nscore = gets.strip()\nnew = \"\"\nalter = \"\"\nfor ch in 0..len - 1\n if new == \"\" or score[ch] != new[-1] or (new.length >= 2 and new[-2] != new[-1])\n new += score[ch]\n end\n if alter == \"\" or alter[-1] != score[ch]\n alter += score[ch]\n end\nend\nputs [alter.length + 2, new.length].min\n\n=begin\nmin(len, maxi + 2)\n=end\n"}, {"source_code": "len = gets.to_i\ns = gets\ncnt = 0\n1.upto(len - 1){|i|\n cnt += 1 if s[i] != s[i - 1]\n}\nputs [len.to_i, cnt + 2].min"}, {"source_code": "gets\ns = gets.chomp\nn = s.chars.inject([0, nil]) do |(things, last), ch|\n if ch == last\n [things, ch]\n else\n [things + 1, ch]\n end\nend.first\n\nif s.scan(/(.)\\1/).size > 1\n puts n + 2\nelsif s[/^(.)\\1/] || s[/(.)\\1$/]\n puts n + 1\nelse\n puts n\nend\n"}, {"source_code": "gets\ns = gets.chomp\nn = s.chars.inject([0, nil]) do |(things, last), ch|\n if ch == last\n [things, ch]\n else\n [things + 1, ch]\n end\nend.first\n\nif s.scan(/(.)\\1/).size > 1\n puts n + 2\nelsif /(.)\\1/ =~ s\n puts n + 1\nelse\n puts n\nend\n"}, {"source_code": "gets\ns = gets.chomp\nn = s.chars.inject([0, nil]) do |(things, last), ch|\n if ch == last\n [things, ch]\n else\n [things + 1, ch]\n end\nend.first\n\nif s.scan(/(.)\\1/).size > 1\n puts n + 2\nelse\n puts n\nend\n"}, {"source_code": "n = gets.to_i\ns = gets\nc = 0\nfor i in 0...n-1 do\n c += 1 if s[i] == s[i+1] \nend\nc-=2\nans = c > 0 ? c : 0\nputs ans"}], "src_uid": "7b56edf7cc71a1b3e39b3057a4387cad"} {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\nres = Array.new\nn.times do |i|\n res[a[i]-1] = i+1\nend\nputs res.to_s.gsub(/\\[/, '').gsub(/\\]/, '').gsub(/,/, '')\n", "positive_code": [{"source_code": "n = gets.to_i\nps = gets.split.map(&:to_i)\nans = Array.new(n)\nps.each_with_index do |p, i|\n ans[p-1] = i + 1\nend\nputs ans.join(\" \")"}, {"source_code": "friends = gets.chomp.to_i\ngifts = gets.chomp.split(/ /).map(&:to_i)\nreceived_gifts = {}\n(1..friends).each do |friend|\n received_gifts.store gifts[friend - 1], friend\nend\nans = []\n(1..friends).each do |friend|\n ans << received_gifts[friend]\nend\nputs ans.join(\" \")\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nans=\"\"\n1.upto(a) do |i|\n c=b.index(\"#{i}\")+1\n ans=ans+\"#{c} \"\nend\nputs \"#{ans}\""}, {"source_code": "gets;a=gets.split.map &:to_i;a.size.times{|i|p a.index(i+1)+1}\n"}, {"source_code": "n=gets.to_i\nb=(1..n).map{0}\nx=gets.split.map{|e| e.to_i}\nn.times{|i|\n\tj=i+1\n\tb[x[i]-1]=j\n}\nputs b*\" \""}, {"source_code": "n = gets.to_i\narr_n = gets.split.map(&:to_i)\nres = []\narr_n.each.with_index(1) { |e,i| res[e]=i }\nputs res[1..-1].join(' ')"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = []\nn.times do |i|\n b << a.index(i+1)+1\nend\nputs b * \" \"\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\n\nc = {}\narr.each_with_index do |a,i|\n c[i+1] = a\nend\n\n\ncc = {}\nc.each do |k,v|\n cc[v] = k\nend\n\naa = []\nn.times do |i|\n aa << cc[i+1]\nend\n\nputs aa.join(' ')"}, {"source_code": "gets;a=gets.split.map &:to_i;a.size.times{|i|p a.index(i+1)+1}"}, {"source_code": "#=================================\nrequire 'prime'\nrequire 'set'\nrequire 'matrix'\nrequire 'tsort'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\ndata=gets.split.map(&:to_i)\nans=Array.new(n, 0)\n\nn.times{|i|\n\tans[data[i]-1]=i+1\n}\n\nans.each{|v| print \"#{v} \"}\n"}, {"source_code": "number = gets.to_i\nanswer = Array.new(number + 1)\n\narr = gets.chomp.split(' ').map(&:to_i)\ni = 1\narr.each do |x|\n answer[x] = i\n i += 1\nend\n\nanswer.each { |x| print \"#{x} \" }"}, {"source_code": "len=gets.to_i\nb=[]\na=gets.split.map{|i|i.to_i}\nlen.times{|i| b[a[i]]=i+1}\nb.shift\nprint b[0]\n1.upto(len) {|i| print ' ',b[i]}\nputs\n"}, {"source_code": "len=gets.to_i\nb=[]\na=gets.split.map{|i|i.to_i}\nlen.times{|i| b[a[i]]=i+1}\nb.shift\nprint b[0]\n1.upto(len) {|i| print ' ',b[i]}\n"}, {"source_code": "len=gets.to_i\nb=[]\na=gets.split.map{|i|i.to_i}\nlen.times{|i| b[a[i]]=i+1}\nb.shift\nlen.times {|i| print b[i],' '}\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\nres = Array.new\nn.times do |i|\n res[a[i]-1] = i+1\nend\nres.each { |v| print \"#{v} \" }\n"}, {"source_code": "n = gets.to_i\nq = gets.chomp.split.map { |x| x.to_i }\nh = Hash.new\n\nfor i in 0..n-1\n h[i] = q[i]\nend\n\nh = h.invert\n\nfor i in 1..n\n print h[i]+1, ' '\nend"}, {"source_code": "n = gets.to_i\nar = gets.chomp.split(' ',n).map{|_|_.to_i}\nputs ar.map.with_index(1).sort_by(&:first).map(&:last).map(&:to_s).join(' ')"}, {"source_code": "class Main\n #def get_problem_link\n # problem_link = \"https://codeforces.com/contest/136/problem/A\"\n # return problem_link\n #end\n\n #def get_submission_link\n # submission_link = ''\n # return submisson_link\n #end\n\n #begin\n #of codeforces interface\n def run_interface\n n = gets.to_i\n k = gets.split(' ').map(&:to_i)\n puts solution(n, k)\n end\n #end\n #of codeforces interface\n\n def solution(n, presents_array)\n res_array = []\n for i in 1..n do\n res_array.push(presents_array.index(i) + 1)\n end\n return res_array.join(' ')\n end\n\nend\n\n#then upload to codeforces uncomment this line:\nMain.new.run_interface\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\np = STDIN.gets.chomp.split(' ').map{|i| i.to_i}\n\nres = p.inject(Hash.new(-1)) {|h, i| h[i - 1] = p.index(i); h}\nn.times do |i|\n if res[i] == -1\n print i + 1, \" \"\n next\n end\n print res[i] + 1, \" \"\nend"}, {"source_code": "n = gets.to_i\n\nh = {}\nst = gets.split.map{|i| i.to_i}\n\nn.times do |i|\n h[i+1] = st[i] \nend\n\nh = h.invert\n\nst = \"\"\ni = 1\nwhile i <= n do \n st += h[i].to_s + \" \"\n i += 1\nend\n\nputs st"}, {"source_code": "gets;a=gets.split.map &:to_i\nputs (1..a.size).map{|i|a.index(i)+1}*\" \""}, {"source_code": "n=gets.to_i\na=Array.new(n,0)\ni=gets.split.map(&:to_i)\nn.times{|j|\n a[i[j]-1]=j\n}\na.each{|j|\n print \"#{j+1} \"\n}\nputs\n"}, {"source_code": "n = gets.to_i\np = gets.split.map(&:to_i)\na = Array(p.size)\np.each_index {|i| a[p[i] - 1] = i + 1 }\nputs a"}, {"source_code": "gets;a=gets.split.map &:to_i;a.size.times{|i|p a.index(i+1)+1}"}, {"source_code": "n = gets.to_i\na = []\na = gets.split.map &:to_i\nb = Array.new(n)\n\n(0...n).each do |i|\n b[a[i] - 1] = i + 1;\nend\n \n\nprint b.join(' ')\n"}, {"source_code": "l = STDIN.read.split(\"\\n\")\na = []\nl[1].split(' ').each_with_index{|x,i| a << [x.to_i, i+1] }\nb = a.sort_by{|x| x[0] }.map{|x| x[1] }\nputs b.join(' ')\n\n\n"}, {"source_code": "number_of_friends = gets.strip.to_i\nfriends = gets.strip.split(' ')\n\nresults = []\n1.upto(number_of_friends) do |current_friend|\n results << friends.index { |given_friend| current_friend.to_s == given_friend } + 1\nend\n\nputs results.join(' ')\n"}, {"source_code": "gets;a=gets.split.map &:to_i;a.size.times{|i|p a.index(i+1)+1}"}, {"source_code": "n = $stdin.readline.to_i\na = $stdin.readline.split(' ').map { |x| x.to_i }\n\nb = Array.new(n)\nfor i in 1..n\n b[i-1] = i\nend\n\nfor i in 1..n\n b[a[i-1]-1] = i unless a[i-1].nil?\nend\n\nputs b.join(' ')\n"}, {"source_code": "def r\n myArray = gets.chomp.split().map { |e| e.to_i }\nend\nn = r\narray = r\narray_2 = Array.new(n)\narray.each_with_index{|val, index|\n array_2[val-1] = index + 1\n}\narray_2.each {|e| print \"#{e} \" }\n"}, {"source_code": "friends = gets.chomp.to_i\ngifts = gets.chomp\ngifts = gifts.split\n\narr_gifts = []\nfor i in (0..gifts.size-1)\n\tarr_gifts[gifts[i].to_i-1] = i+1\nend\n\nfor i in (0..gifts.size-1)\n\tprint arr_gifts[i].to_i\n\tprint \" \"\nend"}, {"source_code": "n=gets.to_i\ns=gets.split(' ').map{|x|x.to_i-1}\nn.times{|i|print s.index(i)+1,' '}\n"}, {"source_code": "gets;a=gets.split.map &:to_i;a.size.times{|i|p a.index(i+1)+1}"}, {"source_code": "n = gets.chomp;\nn = n.to_i;\n\np = gets.chomp;\np = p.split(' ');\n\nfor i in 0..p.length-1\n\tp[i] = p[i].to_i;\n#puts p[i];\nend\n\n#puts(\"done\");\n\nfrom = Array.new(n + 1);\n\nfor i in 0..p.length-1\n\tfrom[p[i]] = i + 1\nend\n\nfor i in 1..from.length-1\n\tif i > 1\n\t\tprintf(\" \");\n\tend\n\tprintf(\"%d\", from[i]);\nend\nprintf(\"\\n\");\n"}, {"source_code": "n=gets.chomp.strip.to_i\na=gets.chomp.split(' ').map(&:to_i)\np=[]\na.each_index do |i|\n\tp[a[i]-1]=i\nend\nfor x in p do\n\tprint (x+1).to_s+' '\nend\nputs"}, {"source_code": "#!/usr/bin/ruby\n\nfriends = gets.to_i\ngifts = gets.chomp.split(\" \").map(&:to_i)\n(1..friends+1).each do |num|\n (0..friends).each do |i|\n if(gifts[i] == num)\n puts i + 1\n end\n end\nend\n\n"}, {"source_code": "a = Array.new(gets.to_i)\ngets.strip.split.map(&:to_i).to_a.each_with_index { |e, i| a[e-1] = i+1 }\nputs a*' '"}, {"source_code": "gets;a=gets.split.map &:to_i;a.size.times{|i|p a.index(i+1)+1}"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(' ').map(&:to_i)\n\nb = []\n\na.each_with_index do |t,i|\n b[t-1] = i+1\nend\n\nputs b.join(' ')"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = Array.new(n)\n\nfor i in 0..n-1\n c[a[i]] = i+1\nend\nputs c.compact"}, {"source_code": "n = $stdin.readline.to_i\nf = $stdin.readline.split.map(&:to_i)\n\nf_inv = Array.new(n)\nf.each_with_index {|e,i| f_inv[e-1]=i+1 }\n\nputs f_inv.join(\" \")"}, {"source_code": "#!/usr/bin/ruby\ndef readNextValues\n return gets.chomp.split.collect {|x| x.to_i }\nend\n\nn = readNextValues\narr = readNextValues\nresult = []\nfor i in 1..arr.size\n result << arr.find_index(i) + 1\nend\nputs result.join(' ')\n"}, {"source_code": "gets\narr = gets.split.map &:to_i\nsol = Array.new\narr.each_with_index { |x, index| sol[arr[index]] = index + 1 }\nsol.shift\nputs sol\n"}, {"source_code": "i = gets.to_i\narray = gets.chomp.split.map(&:to_i)\na = Array.new\n\narray.map.with_index { |x, i| a[x-1] = i+1 }\nputs a.join(\" \")\n"}, {"source_code": "n=gets.to_i\ns=gets\nn.times{|i|p s.split(' ').index((i+1).to_s)+1}\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nb = Array.new(a.size)\n\na.each_index { |i| b[a[i]] = i + 1}\n\nputs b"}, {"source_code": "n=gets.to_i\na=[]\n(n-1).times{\na.push gets(' ').to_i\n}\na.push gets.to_i\n\nb=[]\n\nfor i in 0..a.size-1\nb[a[i]-1]=i+1\nend\n\nfor i in b\nprint i\nprint ' '\nend\nprint \"\\n\""}, {"source_code": "n = gets.to_i\ninput = gets.split(' ').map(&:to_i).unshift(0)\nresult = Array.new(n+1, 0)\n\n0.upto(n) do |i|\n result[input[i]] = i\nend\n\nresult.shift\n\nputs result.join(' ')\n"}, {"source_code": "n = gets.to_i\nm = gets.chomp.split(\" \")\n\n\np = Array.new(n)\n\nfor i in(0..n-1)\n p[m[i].to_i - 1] = i + 1\nend\n\np.each{ |x|\n print(x, \" \")\n}"}, {"source_code": "gets;a=gets.split.map &:to_i;a.size.times{|i|p a.index(i+1)+1}"}, {"source_code": "n = gets.to_i\nb = gets.split(' ').map{|s| s.to_i}\na = Array.new(n)\ni = 0\nwhile (i < n)\n a[b[i]-1] = i \n i+=1\nend \ns = ''\na.each{|q| s += (q+1).to_s + ' '}\nputs s"}, {"source_code": "n = gets.to_i\na = []\ngets.split.each_with_index{ |x,i|\n a[x.to_i] = i+1\n}\nputs a.join(\" \")"}, {"source_code": "gets\nt = 1\nrec = Array.new(t)\ngets.scan(/\\d+/).each do |i|\n\trec[i.to_i] = t\n\tt = t+1\nend\nrec.each do |out|\n\tprintf(out.to_s + \" \")\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets\nm = {}\ngets.split.map(&:to_i).each_with_index { |p,i|\n m[p] = i\n}\nm.map.sort_by{ |i,p|i }.map { |i,p|\n print \"#{p+1} \"\n}\nputs"}, {"source_code": "t=[];$<.take(2)[1].split.each_with_index{|k,i| t[k.to_i]=i+1};puts t[1..-1].join \" \""}, {"source_code": "n = gets.to_i\nres = Array.new(n, 0)\nn = 1\narr = gets.split.map(&:to_i).each do |item|\n res[item - 1] = n\n n += 1\nend\nputs res.join(\" \")\n"}, {"source_code": "gets\ngets.split(\" \").each_with_index.map { |s, i| [s.to_i, i] }.sort_by! {|s, i| s}.each { |s, i| print \"#{i+1} \"}"}, {"source_code": "n = gets.to_i\nh = {}\nreadline.split(\" \").each_with_index.map { |item, pos| h[item.to_i] = pos+1 }\n(1..n).each { |i| print \"#{h[i]} \" }"}, {"source_code": "gets\nputs gets.split.map(&:to_i).each_with_index.map.sort_by{|p,i|p}.map{|p,i|i+1}*\" \""}, {"source_code": "gets;\narr = gets.split.map(&:to_i)\narr2 = Array(arr.size + 1)\nfor i in 1..arr.size do\n arr2[ arr[i-1] ] = i;\nend\nfor i in 1...arr2.size do\n puts arr2[i]\nend\n"}, {"source_code": "friendNum = gets.chomp.to_i\ninput = gets.chomp.split(' ').map {|item| item.to_i}\noutput = []\n(0...friendNum).each do |loops|\n\toutput[(input[loops] - 1) % friendNum] = loops + 1\nend\noutput.each do |ans|\n\tprint \"#{ans} \"\nend"}, {"source_code": "n = gets.chomp.to_i\ngets.chomp.split(' ').map(&:to_i).zip((1..n).to_a).sort { |x, y| x[0] <=> y[0]}.each {|x| puts x[1] }\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\n(1..n).each{|i|puts a.index(i)+1}\n"}, {"source_code": "r={}\ni=1\nn=gets.to_i\ngets.split(' ').each{|x|r[x.to_i]=i.to_s;i=i+1}\nn.times{|i|print r[i+1]+' '}\n"}, {"source_code": "n=gets.to_i\nr=[0]*n\ni=1\ngets.split(' ').each{|x|r[x.to_i-1]=i;i=i+1}\nprint r.join(' ')\n"}, {"source_code": "n = gets\np = gets\n=begin\narr1 = p.chomp.split(' ')\narr1 = arr1.sort\nmax = arr1[-2]\nif max == 1\n puts arr1.sort[0..-2].join(' ')+\" 2\"\nelse\n puts \"1 \" + arr1.sort[0..-2].join(' ')\nend\n=end\n\nfrom = Array.new(n.to_i)\nto = p.split(' ')\ni = 1\nfor el in to\n from[el.to_i-1] = i\n i+=1\nend\nputs from.join(' ').chomp\n"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nh = {}\narr.each_with_index { |a,i|\n h[a] = i + 1\n}\nfor i in (1..n)\n puts h[i]\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nc = {}\nfor i in (1..n)\n c[i] = a[i-1]\nend\nputs c.sort_by {|k, v| v}.map{|x| x[0]}.join(\" \")\n"}, {"source_code": "n = gets.to_i\nar = Array.new\nar = gets.split.map &:to_i\na = ar.size\na.times{\n |i| puts ar.index(i+1)+1 # array.index(value) returns the index of value in the array\n } \n"}, {"source_code": "gets;a=gets.split.map &:to_i;a.size.times{|i|p a.index(i+1)+1}"}, {"source_code": "l = []\ngets\ngets.split.map(&:to_i).each_with_index { |x, i| l[x - 1] = i + 1 }\nputs l.join(\" \")"}, {"source_code": "member_num = gets.chomp.to_i\npresent_arr = gets.chomp.split\npresent_arr.map!{|i| i.to_i}\noutput_arr = Array.new(member_num)\ni = 0\nwhile i < output_arr.length\n output_arr[present_arr[i]-1] = i+1\n i = i+1\nend\nprint output_arr.join(\" \")\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nans=\"\"\n1.upto(a) do |i|\n c=b.index(\"#{i}\")+1\n ans=ans+\"#{c} \"\nend\nputs \"#{ans}\"\n "}, {"source_code": "t=[];$<.take(2)[1].split.each_with_index{|k,i| t[k.to_i]=i+1};puts t[1..-1].join \" \""}], "negative_code": [{"source_code": "n = gets.to_i\nar = gets.chomp.split(' ',n)\nputs ar.map.with_index(1).sort_by(&:first).map(&:last).map(&:to_s).join(' ')"}, {"source_code": "def r\n myArray = gets.chomp.split().map { |e| e.to_i }\nend\nn = r\narray = r\narray_2 = Array.new(n)\narray.each_with_index{|val, index|\n array_2[val-1] = index + 1\n}\narray_2\n"}, {"source_code": "a = Array.new(gets.to_i)\nputs gets.strip.split.map(&:to_i).to_a.each_with_index { |e, i| a[e-1] = i+1 } * ' '"}, {"source_code": "gets\narr = gets.split.map &:to_i\nsol = Array.new\narr.each_with_index { |x, index| sol[arr[index]] = index + 1 }\nsol.shift\np sol\n"}, {"source_code": "number = gets.to_i\nanswer = Array.new(number + 1)\ni = 1\n\nnumber.times {\n n = gets.to_i\n answer[n] = i\n i += 1\n}\n\nanswer.each { |x| print \"#{x} \" }"}, {"source_code": "n = gets.to_i\nq = gets.chomp.split.map { |x| x.to_i }\nh = Hash.new\n\nfor i in 0..n-1\n h[i] = q[i]\nend\n\nh = h.invert\n\np h\n\nfor i in 1..n\n print h[i]+1, ' '\nend"}, {"source_code": "i = gets.to_i\narray = gets.chomp.split.map(&:to_i)\na = Array.new\n\nputs array.map.with_index { |x, i| a[x-1] = i+1 }.join(\" \")"}, {"source_code": "t=[];gets.split.each_with_index{|k,i| t[k.to_i]=i+1};puts t[1..-1].join \" \""}, {"source_code": "r={}\ni=1\ngets\ngets.split(' ').each{|x|r[x.to_i]=i;i=i+1}\nprint r.values.join(' ')\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets\nm = {}\ngets.split.map(&:to_i).each_with_index { |p,i|\n m[p] = i\n}\nm.map { |i,p|\n print \"#{p+1} \"\n}\nputs"}], "src_uid": "48bb148e2c4d003cad9d57e7b1ab78fb"} {"source_code": "n = gets.to_i\ns = gets.split.map(&:to_i).uniq.sort\nn = s.size\nt = Array.new(n-1)\nfor i in 0..n-2\n t[i] = s[i+1]-s[i]\nend\nt.sort!\nq = gets.to_i\nlr = Array.new(q)\nq.times do |i|\n lr[i] = gets.split.map(&:to_i)\nend\na = Array.new(q){|i|i}.sort_by{|i|lr[i][1]-lr[i][0]}\nans = Array.new(q,0)\nlr.sort_by!{|i,j|j-i}\nc = 0\nsum = 0\nq.times do |i|\n d = lr[i][1]-lr[i][0]+1\n while c < n-1 && t[c] < d\n sum += t[c]\n c += 1\n end\n ans[a[i]] = sum+d+(n-c-1)*d\nend\nputs ans.join(\" \")", "positive_code": [{"source_code": "def bsearch(arr,t)\n ok,ng = 0,arr.length\n while (ng - ok).abs > 1\n mid = (ok+ng)/2\n if arr[mid] <= t\n ok = mid\n else\n ng = mid\n end\n end\n return ok\nend\n\nn = gets.to_i\ns = gets.split.map(&:to_i)\nq = gets.to_i\nqs = []\nq.times do\n l,r = gets.split.map(&:to_i)\n qs << r-l+1\nend\n\ns.sort!\ndiff = [0]\n(n-1).times do |i|\n diff << s[i+1] - s[i]\nend\ndiff << 10**18+1\ndiff.sort!\ncumsum = [0]\nn.times do |i|\n cumsum << cumsum[-1] + diff[i+1]\nend\n\nqs.each do |t| \n fill = bsearch(diff,t)\n ans = cumsum[fill] + t*(n-fill)\n# p [t,fill,cumsum[fill]]\n print \"#{ans} \"\nend\n"}, {"source_code": "def binary_search(ok, ng)\n while (ok - ng).abs > 1\n mid = (ok + ng) / 2\n\n if yield(mid)\n ok = mid\n else\n ng = mid\n end\n end\n\n ok\nend\n\nN = gets.to_i\nS = gets.split.map(&:to_i)\nSU = S.sort.uniq\nQ = gets.to_i\nquery = Q.times.map { gets.split.map(&:to_i) }\n\nDL = SU.each_cons(2).map { |a, b| b - a - 1 }.sort\nDL.unshift(-Float::INFINITY)\nDL.push(Float::INFINITY)\nDL.reverse!\n\nRUI = []\n\nsum = 0\n\nDL.reverse[1..-2].each do |v|\n sum += v\n RUI << sum\nend\n\nRUI.unshift(-Float::INFINITY)\nRUI << Float::INFINITY\nRUI.reverse!\n\nans = []\nquery.each do |l, r|\n a = SU.size\n d = r - l\n ei = binary_search(0, DL.size - 1) { |x| DL[x] >= d }\n b = d * ei\n c = d\n d = [RUI[ei + 1], 0].max\n\n ans << a + b + c + d\nend\n\nputs ans.join(' ')\n"}], "negative_code": [{"source_code": "def binary_search(ok, ng)\n while (ok - ng).abs > 1\n mid = (ok + ng) / 2\n\n if yield(mid)\n ok = mid\n else\n ng = mid\n end\n end\n\n ok\nend\n\nN = gets.to_i\nS = gets.split.map(&:to_i)\nSU = S.sort.uniq\nQ = gets.to_i\nquery = Q.times.map { gets.split.map(&:to_i) }\n\nDL = SU.each_cons(2).map { |a, b| b - a - 1 }.sort\nRUI = []\n\nsum = 0\n\nDL.each do |v|\n sum += v\n RUI << sum\nend\n\nRUI.unshift(-Float::INFINITY)\nRUI << Float::INFINITY\nRUI.reverse!\n\nans = []\nquery.each do |l, r|\n a = SU.size\n d = r - l\n ei = binary_search(0, RUI.size - 1) { |x| RUI[x] >= d }\n b = d * ei\n c = d\n d = [RUI[ei + 1], 0].max\n\n ans << a + b + c + d\nend\n\nputs ans.join(' ')\n"}], "src_uid": "536a582f3620a733d09cf80662488590"} {"source_code": "N = gets.to_i\nN.times do\n l1, r1, l2, r2 = gets.chomp.split.map(&:to_i)\n if r1 < l2 or r2 < l1\n puts \"#{l1} #{l2}\"\n else\n if l1 <= l2\n puts \"#{l1} #{r2}\"\n else\n puts \"#{r1} #{l2}\"\n end\n end\nend\n", "positive_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nq = gets.to_i\nq.times do\n\tlrlr = gets.chomp.split(\" \").map(&:to_i)\n\tl1 = lrlr[0]\n\tr1 = lrlr[1]\n\tl2 = lrlr[2]\n\tr2 = lrlr[3]\n\n\tif (l1 == l2) and (l1==r2)\n\t\tputs \"#{r1} #{l1}\"\n\telse\n\t\tprint \"#{l1} \"\n\t\tif(l1==l2)\n\t\t\tprint r2\n\t\telse\n\t\t\tprint l2\n\t\tend\n\t\tputs\n\tend\nend"}, {"source_code": "gets;puts$<.map{|e|a,b,c,d=e.split.map &:to_i;[a,(c!=a ? c : d)]*' '}"}, {"source_code": "q = gets.to_i\nq.times do\n l1, r1, l2, r2 = gets.split.map(&:to_i)\n a = l1\n b = l2\n if b == a\n b = r2\n end\n puts \"#{a} #{b}\"\nend"}, {"source_code": "input = gets.to_i\ni = 0\ninput_range = []\ninput.times do\n input_range[i] = gets.split.map(&:to_i)\n input_range[i]\n i += 1\nend\n\ni = 0\n\ninput.times do\n if input_range[i][0] != input_range[i][3]\n print \"#{input_range[i][0]} \"\n puts \"#{input_range[i][3]}\"\n else\n print \"#{input_range[i][1]} \"\n puts \"#{input_range[i][2]}\"\n end\n i += 1\nend"}, {"source_code": "n = gets.to_i\nn.times do\n l1, r1, l2, r2 = gets.split(' ').map(&:to_i)\n if (l1 != l2)\n puts [l1, l2].join(' ')\n next\n end\n if (r1 != r2)\n puts [r1, r2].join(' ')\n next\n end\n if (r1 - l1 == 2)\n puts [l1, r1].join(' ')\n next\n end\n puts [l1 + 1, r1 - 1].join(' ')\nend"}, {"source_code": "a = gets\n\ndef sol(a)\n\t(1..a.to_i).map {|num|\n\t\ta,b,c,d = gets.chomp.split\n\t\t[a,a==c ? d : c ]\n\t}\nend\n\nputs sol(a)"}, {"source_code": "f = gets.to_i\nf.times do\n l1, r1, l2, r2 = gets.to_s.chomp.split(\" \").map{|x| x.to_i}\n if r1 != r2\n puts \"#{r1} #{r2}\"\n else\n puts \"#{r1} #{r2 - 1}\"\n end\nend\n"}, {"source_code": "gets;puts$<.map{|e|a,b,c,d=e.split.map &:to_i;[a,(c!=a ? c : d)]*' '}"}, {"source_code": "gets;puts$<.map{|e|a,b,c,d=e.split.map &:to_i;[a,(c!=a ? c : d)]*' '}"}], "negative_code": [{"source_code": "input = gets.to_i\ni = 0\ninput_range = []\ninput.times do\n input_range[i] = gets.split.map(&:to_i)\n input_range[i]\n i += 1\nend\n\ni = 0\n\ninput.times do\n print \"#{input_range[i][0]} \"\n puts \"#{input_range[i][3]}\"\n i += 1\nend"}, {"source_code": "n = gets.to_i\nn.times do\n l1, r1, l2, r2 = gets.split(' ').map(&:to_i)\n if (l1 != l2)\n puts [l1, l2].join(' ')\n next\n end\n if (r1 != r2)\n puts [r1, r2].join(' ')\n next\n end\n puts [l1 + 1, r1 - 1].join(' ')\nend"}, {"source_code": "a = gets\n\ndef sol(a)\n\t(1..a.to_i).map {|num|\n\t\ta,b,c,d = gets.chomp.split('\\s')\n\t\t[a,a==c ? d : c ]\n\t}\nend\n\nputs sol(a)"}], "src_uid": "cdafe800094113515e1de1acb60c4bb5"} {"source_code": "# Entrada: testcases, longitud del arreglo, arreglo permutaci\u00f3n\r\n# Salida: profundidad de cada nodo en orden de la entrada del arreglo\r\n# Formaci\u00f3n del arbol y resultado: \r\n# 1 Paso: encontrar el n\u00famero mayor del arreglo\r\n# 2 Paso: separar los elementos del arreglo con base del n\u00famero mayor, de los elementos de\r\n# izquierda de este, y los elementos de la derecha\r\n# 3 Paso: en cada conjunto separado, realizar el paso 1 y 2 hasta que no se pueda dividir\r\n# Nota: si no hay elementos, se descarta(No se toma en cuenta).\r\n# 4 Paso: buscar el nivel de profundidad de cada nodo y relacionarlo con el arreglo inicial\r\n# 5 Paso: Mostrar en pantalla los niveles de profundidad de cada arreglo dado\r\n\r\n# M\u00e1s ejemplos de casos\r\n# 1 Caso (Caso cargado a la derecha): 7,5,6,3,4,2,1\r\n# Nivel 0\r\n# 1 Paso: 7\r\n# 2 Paso: Izquierda--> .Derecha-->5,6,3,4,2,1\r\n# 3 Paso: Para Izquierda: \u00bfEs solo un elemento? No hay elemento ---> Se descarta \r\n# Para Derecha: \u00bfEs solo un elemento? No ---> volvemos a 1 Paso con entrada derecha \r\n# Nivel 1, Derecha\r\n# 1 Paso: 6\r\n# 2 Paso: Izquierda--> 5 .Derecha-->3,4,2,1\r\n# 3 Paso: Para Izquierda \u00bfEs solo un elemento? Si --->Termina. \r\n# Para Derecha: \u00bfEs solo un elemento? No ---> volvemos a 1 Paso con entrada derecha\r\n# Nivel 2, Derecha\r\n# 1 Paso: 4\r\n# 2 Paso: Izquierda-->3 .Derecha-->2,1\r\n# 3 Paso: Para Izquierda: \u00bfEs solo un elemento? Si --->Termina.\r\n# Para Derecha: \u00bfEs solo un elemento? No ---> volvemos a 1 Paso con entrada derecha\r\n# Nivel 3, Derecha\r\n# 1 Paso: 2\r\n# 2 Paso: Izquierda--> .Derecha-->1\r\n# 3 Paso: Para Izquierda: \u00bfEs solo un elemento? No hay elemento ---> Se descarta\r\n# Para Derecha: \u00bfEs solo un elemento? Si --->Termina.\r\n# 4 Paso: Nivel 0: 7, Nivel 1: 6, Nivel 2: 4, Nivel 3: 2\r\n# 5 Paso: 0, , 1, , 2, 3, Sin conocer 5, 3, 1\r\n# Salida correcta: No\r\n# Observaci\u00f3n: Para los niveles sin conocer, cada que se detecte que solo es un elemento, \r\n# relacionar con el siguiente nivel ese elemento, entonces para nivel 2: 5 nivel 3: 3, \r\n# nivel 4: 1 y la sal\u00edda ser\u00eda: 0, 2, 1, 3, 2, 3, 4\r\n# Salida correcta con observaci\u00f3n: Si \r\n# 2 Caso (Zig-zag): 4,2,5,1,3 \r\n# Nivel 0\r\n# 1 Paso: 5\r\n# 2 Paso: Izquierda-->4,2 .Derecha-->1,3\r\n# 3 Paso: Para Izquierda: \u00bfEs solo un elemento? No ---> volvemos a 1 Paso con entrada izquierda \r\n# Para Derecha: \u00bfEs solo un elemento? No ---> volvemos a 1 Paso con entrada derecha \r\n# Nivel 1, Izquierda\r\n# 1 Paso: 4\r\n# 2 Paso: Izquierda--> .Derecha-->2\r\n# 3 Paso: Para Izquierda \u00bfEs solo un elemento? No hay elemento ---> Se descarta \r\n# Para Derecha: \u00bfEs solo un elemento? Si ---> Termina y se relaciona con el siguiente nivel\r\n# Nivel 1, Derecha\r\n# 1 Paso: 3\r\n# 2 Paso: Izquierda-->1 .Derecha-->\r\n# 3 Paso: Para Izquierda: \u00bfEs solo un elemento? Si --->Termina y se relaciona con el siguiente nivel\r\n# Para Derecha: \u00bfEs solo un elemento? No hay elemento ---> Se descarta\r\n# 4 Paso: Nivel 0: 5, Nivel 1: 4,3, Nivel 2: 2,1\r\n# 5 Paso: 1, 2, 0, 2, 1\r\n# Salida correcta: Si\r\n\r\ndef permutationTransformation(a,n,nivel)\r\n # Observaci\u00f3n\r\n if n == 1\r\n return nivel\r\n end\r\n #Pre paso: crear el arreglo del arbol \"d\" y los arreglos derecha, izquierda\r\n d = []\r\n izquierda, derecha = []\r\n # 1 Paso\r\n mayor = buscarMayorNumero(a,n)\r\n # 2 Paso\r\n izquierda, derecha = separarElementosArreglo(a,n,mayor)\r\n # 3 Paso\r\n if izquierda.length>0\r\n izquierda = permutationTransformation(izquierda,izquierda.length,nivel+1)\r\n end\r\n if derecha.length>0\r\n derecha = permutationTransformation(derecha,derecha.length,nivel+1)\r\n end\r\n # 4 Paso\r\n d = buscarNiveles(izquierda,nivel,derecha)\r\n return d\r\nend\r\n\r\ndef buscarNiveles(izquierda,mayor,derecha)\r\n d = []\r\n if izquierda.class == Integer\r\n d.push(izquierda)\r\n else\r\n for i in(0..izquierda.length-1)\r\n d.push(izquierda[i])\r\n end\r\n end\r\n d.push(mayor)\r\n if derecha.class == Integer\r\n d.push(derecha)\r\n else\r\n for i in(0..derecha.length-1)\r\n d.push(derecha[i])\r\n end\r\n end\r\n return d\r\nend\r\n\r\ndef separarElementosArreglo(a,n,mayor)\r\n izquierda = []\r\n derecha = []\r\n #Para izquierda\r\n for i in(0..mayor-1)\r\n izquierda.push(a[i])\r\n end\r\n #Para derecha\r\n for i in(mayor+1..n-1)\r\n derecha.push(a[i])\r\n end\r\n return izquierda, derecha\r\nend\r\n\r\ndef buscarMayorNumero(a,n)\r\n mayor = a[0]\r\n posicion = 0\r\n for i in(0..n-1)\r\n if a[i]>mayor\r\n mayor = a[i]\r\n posicion = i\r\n end\r\n end\r\n return posicion\r\nend\r\n\r\ndef convertirAInteger(a,n)\r\n for i in(0..n-1)\r\n a[i] = Integer(a[i])\r\n end\r\n return a\r\nend\r\n\r\ndef darFormatoDeSalida(d)\r\n resultado = \"\"\r\n if d.class == Integer\r\n resultado = d.to_s\r\n else\r\n for i in(0..d.length-1)\r\n resultado = resultado + d[i].to_s\r\n if i != d.length-1 \r\n resultado = resultado + \" \"\r\n end\r\n end\r\n end\r\n return resultado\r\nend\r\n\r\n# Variables\r\ntestcases = 0\r\nn = 0\r\na = []\r\nd = []\r\nresultado = []\r\n\r\n# Pre paso: Pedir los testcases, la longitud del arreglo y el arreglo\r\n# testcases\r\ntestcases = Integer(gets.chomp)\r\n\r\nfor i in(0..testcases-1)\r\n #Longitud del arreglo\r\n n = Integer(gets.chomp)\r\n #Arreglo\r\n array = gets.chomp\r\n a = array.split(\" \")\r\n a = convertirAInteger(a,n)\r\n d = permutationTransformation(a,n,0)\r\n resultado.push(darFormatoDeSalida(d))\r\nend\r\n\r\nresultado.each do |elements|\r\n puts elements\r\nend \r\n\r\n", "positive_code": [{"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tputs a.each_with_index.map { |x, i|\n\t\t\tres = 0\n\t\t\tnow = a[i]\n\t\t\t(i + 1...n).each do |j|\n\t\t\t\tif now < a[j]\n\t\t\t\t\tnow = a[j]\n\t\t\t\t\tres += 1\n\t\t\t\tend\n\t\t\tend\n\t\t\tnow = a[i]\n\t\t\t(0...i).reverse_each do |j|\n\t\t\t\tif now < a[j]\n\t\t\t\t\tnow = a[j]\n\t\t\t\t\tres += 1\n\t\t\t\tend\n\t\t\tend\n\t\t\tres\n\t }.join(' ')\nend\n"}], "negative_code": [], "src_uid": "a564017f9c411b39f8d4b69e629ae3bc"} {"source_code": "n, q = gets.split.collect{|i| i.to_i}\na = gets.split.collect{|i| i.to_i}.sort.reverse\ns = Array.new(n+1,0)\n(0...q).each do\n l, r = gets.split.collect{|i| i.to_i-1}\n s[l] += 1\n s[r+1] -= 1\nend\n(1...n).each do |i|\n s[i] += s[i-1]\nend\ns = s.sort.reverse\nputs (0...n).inject(0){|sum, i| sum += s[i]*a[i]}\n", "positive_code": [{"source_code": "n,m,=gets.split.map{|x|x.to_i}\na=gets.split.map{|x|x.to_i}.sort.reverse\nb=Array.new(300000,0)\nm.times{|i|\n l,r,=gets.split.map{|x|x.to_i}\n b[l-1]+=1\n b[r]-=1\n}\nz=0\nb=b.map{|e|e+z;z+=e}\nb.sort!.reverse!\nz=0\nfor i in 0..n-1 do\n z+=(b[i]*a[i])\nend\nputs \"#{z}\""}, {"source_code": "n, q = gets.split(' ').collect!{|i| i.to_i}\n\narr = gets.split(' ').collect!{|i| i.to_i}\n\nd = Array.new(n, 0)\nq.times do\n\tl, r = gets.split(' ').collect!{|i| i.to_i - 1}\n\t# (l..r).each do |j|\n\t# \tel[j] += 1\n\t# end\n\td[l] += 1\n\td[r+1] -= 1 if r < n-1\nend\n\nel = Array.new(n, 0)\nsum = 0\nn.times do |i|\n\tsum += d[i]\n\tel[i] = sum\nend\n\nel.sort!.reverse!\n\narr.sort!.reverse!\n\nmaxsum = 0\n\nn.times do |i|\n\t# j = n - i - 1\n\tmaxsum += arr[i]*el[i]\n\tbreak if el[i] == 0\nend\n\np maxsum\n"}, {"source_code": "n, q = gets.split.collect{|i| i.to_i}\na = gets.split.collect{|i| i.to_i}.sort.reverse\ns = Array.new(n+1,0)\nq.times do\n l, r = gets.split.collect{|i| i.to_i-1}\n s[l] += 1\n s[r+1] -= 1\nend\nn.times do |i|\n s[i+1] += s[i]\nend\ns = s.sort.reverse\nputs (0...n).inject(0){|sum, i| sum += s[i]*a[i]}\n"}, {"source_code": "n, q = gets.split.collect{|i| i.to_i}\na = gets.split.collect{|i| i.to_i}\ns = Array.new(n+1,0)\ne = Array.new(n+1,0)\n(0...q).each do\n tmp = gets.split.collect{|i| i.to_i}\n s[tmp[0]] += 1\n e[tmp[1]] += 1\nend\n(1..n).each do |i|\n s[i] += s[i-1]\n e[i] += e[i-1]\nend\n(1..n).each do |i|\n s[i] = s[i]-e[i-1]\nend\ns = s.sort.reverse\na = a.sort.reverse\nputs (0...n).inject(0){|sum, i| sum += s[i]*a[i]}\n"}, {"source_code": "n, q = gets.split.collect{|i| i.to_i}\na = gets.split.collect{|i| i.to_i}.sort.reverse\ns = Array.new(n+1,0)\nq.times do\n l, r = gets.split.collect{|i| i.to_i-1}\n s[l] += 1\n s[r+1] -= 1\nend\nn.times do |i|\n s[i+1] += s[i]\nend\ns.sort!.reverse!\nputs (0...n).inject(0){|sum, i| sum += s[i]*a[i]}\n"}], "negative_code": [], "src_uid": "926ec28d1c80e7cbe0bb6d209e664f48"} {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\na< 1\n tbl2[key + 1] += 1\n else\n tbl2[key] += value\n end\n end\n tbl = tbl2\n cnt += 1\nend\np cnt\n"}, {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\na<0\n next\n end\n if(i>0 != pos)\n ans+=vec.max\n vec=[i]\n pos = i>0\n else\n vec.push(i)\n end\n end\n ans+=vec.max\n puts ans\nend\n", "positive_code": [{"source_code": "number_of_testcases = gets.to_s.to_i\n\nnumber_of_testcases.times do |i|\n \n n = gets.to_s.to_i\n a = gets.to_s.split.map{|e|e.to_i}.push 0\n \n ans = 0\n s = []\n a.each do |k|\n if s.size > 0 && s[-1] * k <= 0\n ans += s.max\n s = []\n end\n s << k\n end\n # ans += s.max \n puts ans\nend\n"}, {"source_code": "1.upto(gets.to_i) do\n gets\n a = gets.split(' ').map(&:to_i)\n\n blocks = []\n while !a.empty?\n sign = a.first / a.first.abs\n blocks << a.take_while { |x| x / x.abs == sign }\n\n a = a.drop(blocks.last.size)\n end\n\n puts blocks.inject(0) { |s, e| s + e.max }\nend\n"}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tputs a.chunk { _1 < 0 }.sum { _1[1].max }\nend\n"}, {"source_code": "# frozen_string_literal: true\n\nclass Result\n def print_result\n gets\n arr = gets.split(' ').map(&:to_i)\n\n positive_arrs = [[], []]\n positive_arrs.each_with_index do |positive_arr, j|\n positive = j.zero?\n min = 0\n first = true\n arr.each do |i|\n if first\n if positive && i < 0\n next\n elsif !positive && i > 0\n next\n end\n\n first = false\n end\n\n if positive && min < i\n min = i\n next\n end\n\n if positive && i < 0\n positive = false\n positive_arr.push(min)\n min = i\n next\n end\n\n if !positive && (min == 0 || min < i) && i < 0\n min = i\n next\n end\n\n next unless !positive && i > 0\n\n positive = true\n positive_arr.push(min)\n min = i\n end\n\n positive_arr.push(min) if min != 0\n end\n\n puts(if positive_arrs[0].size == positive_arrs[1].size\n positive_arrs.map(&:sum).max\n elsif positive_arrs[0].size > positive_arrs[1].size\n positive_arrs[0].sum\n else\n positive_arrs[1].sum\n end)\n end\n\n private\n\n attr_reader :n\nend\n\ngets.to_i.times do\n Result.new.print_result\nend\n"}], "negative_code": [{"source_code": "t=gets.to_i\n(1).upto(t) do\n n=gets.to_i\n n>>=1\n if(n&1)==1\n puts \"NO\"\n next\n end\n puts \"YES\"\n sum =0\n (1).upto(n) do |i|\n print \"#{i*2} \"\n sum+=i*2\n end\n\n (1).upto(n-1) do |i|\n sum-=i*2-1\n print \"#{i*2-1} \"\n end\n puts sum\nend\n"}], "src_uid": "39480cdf697fc9743dc9665f989077d7"} {"source_code": "r,c=gets.chomp.split.map(&:to_i)\na,b,fr,fc,dr,dc=Array.new(r,0),Array.new(c,0),0,0,0,0\nr.times do |i|\n\tx=gets.chomp.split.map(&:to_i)\n\tx.each_index do |j|\n\t\tif x[j]==1\n\t\t\ta[i]+=1\n\t\t\tb[j]+=1\n\t\tend\n\tend\nend\n=begin\nprint a\nputs\nprint b\nputs\n=end\nr.times { |i| (a[i]==c) ? fr+=1 : dr+=a[i] }\nc.times { |i| (b[i]==r) ? fc+=1 : dc+=b[i] }\n#puts \"#{dr} #{dc} #{fr} #{fc} #{r} #{c}\"\nif (dr!=(r-fr)*fc)||(dc!=(c-fc)*fr)||(fr==0&&fc!=0)||(fr!=0&&fc==0)\n\tputs \"NO\"\nelse\n\tputs \"YES\"\n\tr.times do |i|\n\t\tc.times do |j|\n\t\t\tprint (a[i]==c && b[j]==r) ? \"1 \" : \"0 \"\n\t\tend\n\t\tputs\n\tend\nend\n", "positive_code": [{"source_code": "row_num, col_num = STDIN.readline.split.map {|s| s.to_i }\nb = []\nrow_num.times do\n\tb.push(STDIN.readline.split.map {|s| s.to_i })\nend\n\nor_row = row_num.times.map { 1 }\nor_col = col_num.times.map { 1 }\n\nb.each_with_index do |row, r|\n\trow.each_with_index do |x, c|\n\t\tor_row[r] = or_col[c] = 0 if x == 0\n\tend\nend\n\nif or_row.inject(:+) == 0\n\tcol_num.times {|c| or_col[c] = 0 }\nend\nif or_col.inject(:+) == 0\n\trow_num.times {|r| or_row[r] = 0 }\nend\n\nb.each_with_index do |row, r|\n\trow.each_with_index do |x, c|\n\t\tif x == 1 and or_row[r] == 0 and or_col[c] == 0\n\t\t\tputs 'NO'\n\t\t\texit\n\t\tend\n\tend\nend\n\na = row_num.times.map { col_num.times.map { 1 } }\nor_row.each_with_index do |x, r|\n\tcol_num.times { |c| a[r][c] = 0 } if x == 0\nend\nor_col.each_with_index do |x, c|\n\trow_num.times { |r| a[r][c] = 0 } if x == 0\nend\n\nputs 'YES'\nrow_num.times {|r| puts a[r].join ' ' }\n"}, {"source_code": "M, N = gets.split.map(&:to_i)\nval = []\nM.times{|m|\n val[m] = gets.split.map(&:to_i).map{|i| i==1}\n}\n\n\nMallone = []\nM.times{|m|\n Mallone[m] = true\n N.times{|n|\n Mallone[m] &= (val[m][n])\n # puts \"Mallone[#{m}]=#{Mallone[m]}\"\n }\n}\n\nNallone = []\nN.times{|n|\n Nallone[n] = true\n M.times{|m|\n Nallone[n] &= (val[m][n])\n # puts \"Nallone[#{n}]=#{Nallone[n]}\"\n }\n}\n\nresult = []\nM.times{|m|\n result[m] = []\n N.times{|n|\n result[m][n] = false\n }\n}\n\nM.times{|m|\n if Mallone[m]\n flag = false\n N.times{|n|\n if Nallone[n]\n flag = true\n result[m][n] = true\n end\n }\n if !flag\n puts \"NO\"\n exit 0\n end\n else\n N.times{|n|\n if val[m][n]\n if ! Nallone[n]\n puts \"NO\"\n exit 0\n end\n end\n }\n end\n}\n\nN.times{|n|\n if Nallone[n]\n flag = false\n M.times{|m|\n if Mallone[m]\n flag = true\n result[m][n] = true\n end\n }\n if !flag\n puts \"NO\"\n exit 0\n end\n else\n M.times{|m|\n if val[m][n]\n if ! Mallone[m]\n puts \"NO\"\n exit 0\n end\n end\n }\n end\n}\nputs \"YES\"\nM.times{|m|\n puts result[m].map{|b| (b&&1||0)}.join(\" \")\n}\n"}, {"source_code": "def make_zero(i,j,n,m)\n\t@arr[i] = Array.new(m,0)\n\t(0..(n-1)).each do |row|\n\t\t@arr[row][j] = 0\n\tend\nend\n\n\ndef calc(i,j,n,m)\n\trow_or = @arr[i].inject(0,&:|)\n\tcol_or = 0\n\t(0..(n-1)).each do |row|\n\t\tcol_or |= @arr[row][j] \n\tend\n\trow_or | col_or\nend\n\nn,m = gets.split(\" \").map(&:to_i)\nb_arr = []\n@arr = []\nn.times do\n\tb_arr << gets.split(\" \").map(&:to_i)\n\t@arr << Array.new(m,1)\nend\n\nn.times do |i|\n\tm.times do |j|\n\t\tmake_zero(i,j,n,m) if b_arr[i][j] ==0\n\tend\nend\n\n@new_arr = []\nn.times do |i|\n\t@new_arr << []\n\tm.times do |j|\n\t\t@new_arr[i][j] = calc(i,j,n,m)\n\tend\nend\n# puts \"#{@arr}\"\n# puts \"barr #{b_arr}\"\n# puts \"new #{@new_arr}\"\nif b_arr == @new_arr\n\tputs \"YES\"\n\t@arr.each do |a|\n\t\tputs a.join(\" \")\n\tend\nelse\n\tputs \"NO\"\nend"}, {"source_code": "def read_line\n gets.chomp.split.map &:to_i\nend\n\nn, m = read_line\na, b = [], []\n\nn.times {\n a << Array.new(m,1)\n b << read_line\n}\n\nn.times { |i|\n a[i] = Array.new(m, 0) if b[i].include? 0 \n}\n\nm.times { |j| \n a.each { |x| x[j] = 0 } if (0...n).map { |i| b[i][j] }.include? 0\n}\n\nc = Array.new(n)\nn.times { |i| \n c[i] = Array.new(m)\n m.times { |j|\n c[i][j] = (a[i] + (0...n).map { |k| a[k][j] }).inject { |x, y| x|y }\n }\n}\n\nif c == b \n\tputs 'YES'\n\ta.each { |x|\n\t\tputs x*' '\n\t}\nelse\n\tputs 'NO'\nend\t"}, {"source_code": "# 486B\n\ndef read_line\n gets.chomp.split.map &:to_i\nend\n\nm, n = read_line\na, b = [], []\nm.times {\n a << Array.new(n, 1)\n b << read_line\n}\n\nm.times { |i|\n a[i] = Array.new(n, 0) if b[i].include? 0\n}\n\nn.times { |j|\n a.each { |x| x[j] = 0 } if (0...m).map { |i| b[i][j] }.include? 0\n}\n\nc = Array.new(m)\nm.times { |i|\n c[i] = Array.new(n)\n n.times { |j|\n c[i][j] = (a[i] + (0...m).map { |k| a[k][j] }).inject { |x, y| x | y }\n }\n}\n\nif c == b\n puts 'YES'\n a.each { |x|\n puts x * ' '\n }\nelse\n puts 'NO'\nend"}, {"source_code": "m,n = gets.split.map &:to_i\n\nb = []\na = Array.new(m) {Array.new(n)}\ncorrect_b = Array.new(m) {Array.new(n, 0)}\n\nm.times do |i|\n b[i] = gets.split.map(&:to_i)\nend\n\nb.each_with_index do |arr, i|\n arr.each_with_index do |el, j|\n if el == 0\n m.times {|line| a[line][j] = 0}\n n.times {|col| a[i][col] = 0}\n end\n end\nend\n\nis_correct = true\n\nm.times do |i|\n n.times do |j|\n unless a[i][j]\n a[i][j] = 1\n\n m.times {|line| correct_b[line][j] = 1 }\n n.times {|col| correct_b[i][col] = 1 }\n end\n end\nend\n\nm.times do |i|\n break unless is_correct\n n.times do |j|\n if b[i][j] != correct_b[i][j]\n is_correct = false\n break\n end\n end\nend\n\n\nif is_correct\n puts 'YES'\n a.each {|k| puts k.join(' ')}\nelse\n puts 'NO'\nend\n\n# puts\n# correct_b.each {|k| puts k.join(' ')}"}, {"source_code": "row_num, col_num = STDIN.readline.split.map {|s| s.to_i }\nb = []\nrow_num.times do\n\tb.push(STDIN.readline.split.map {|s| s.to_i })\nend\n\nor_row = row_num.times.map { 1 }\nor_col = col_num.times.map { 1 }\n\nb.each_with_index do |row, r|\n\trow.each_with_index do |x, c|\n\t\tif x == 0\n\t\t\tor_row[r] = 0\n\t\t\tor_col[c] = 0\n\t\tend\n\tend\nend\n\nif or_row.inject(:+) == 0\n\tcol_num.times {|c| or_col[c] = 0 }\nend\nif or_col.inject(:+) == 0\n\trow_num.times {|r| or_row[r] = 0 }\nend\n\nb.each_with_index do |row, r|\n\trow.each_with_index do |x, c|\n\t\tif x == 1\n\t\t\tif or_row[r] == 0 and or_col[c] == 0\n\t\t\t\tputs 'NO'\n\t\t\t\texit\n\t\t\tend\n\t\tend\n\tend\nend\n\na = row_num.times.map { col_num.times.map { 1 } }\nor_row.each_with_index do |x, r|\n\tcol_num.times { |c| a[r][c] = 0 } if x == 0\nend\nor_col.each_with_index do |x, c|\n\trow_num.times { |r| a[r][c] = 0 } if x == 0\nend\n\nputs 'YES'\nrow_num.times {|r| puts a[r].join ' ' }\n"}], "negative_code": [{"source_code": "row_num, col_num = STDIN.readline.split.map {|s| s.to_i }\nb = []\nrow_num.times do\n\tb.push(STDIN.readline.split.map {|s| s.to_i })\nend\n\nor_row = row_num.times.map { 1 }\nor_col = col_num.times.map { 1 }\n\nb.each_with_index do |row, r|\n\trow.each_with_index do |x, c|\n\t\tif x == 0\n\t\t\tor_row[r] = 0\n\t\t\tor_col[c] = 0\n\t\tend\n\tend\nend\n\nb.each_with_index do |row, r|\n\trow.each_with_index do |x, c|\n\t\tif x == 1\n\t\t\tif or_row[r] == 0 and or_col[c] == 0\n\t\t\t\tputs 'NO'\n\t\t\t\texit\n\t\t\tend\n\t\tend\n\tend\nend\n\nif row_num >= col_num and or_row.inject(:+) == 0\n\tcol_num.times {|c| or_col[c] = 0 }\nend\nif col_num >= row_num and or_col.inject(:+) == 0\n\trow_num.times {|r| or_row[r] = 0 }\nend\n\na = row_num.times.map { col_num.times.map { 1 } }\nor_row.each_with_index do |x, r|\n\tcol_num.times { |c| a[r][c] = 0 } if x == 0\nend\nor_col.each_with_index do |x, c|\n\trow_num.times { |r| a[r][c] = 0 } if x == 0\nend\n\nputs 'YES'\nrow_num.times {|r| puts a[r].join ' ' }\n"}, {"source_code": "row_num, col_num = STDIN.readline.split.map {|s| s.to_i }\nb = []\nrow_num.times do\n\tb.push(STDIN.readline.split.map {|s| s.to_i })\nend\n\nor_row = row_num.times.map { 1 }\nor_col = col_num.times.map { 1 }\n\nb.each_with_index do |row, r|\n\trow.each_with_index do |x, c|\n\t\tif x == 0\n\t\t\tor_row[r] = 0\n\t\t\tor_col[c] = 0\n\t\tend\n\tend\nend\n\nb.each_with_index do |row, r|\n\trow.each_with_index do |x, c|\n\t\tif x == 1\n\t\t\tif or_row[r] == 0 and or_col[c] == 0\n\t\t\t\tputs 'NO'\n\t\t\t\texit\n\t\t\tend\n\t\tend\n\tend\nend\n\na = row_num.times.map { col_num.times.map { 1 } }\nor_row.each_with_index do |x, r|\n\tcol_num.times { |c| a[r][c] = 0 } if x == 0\nend\nor_col.each_with_index do |x, c|\n\trow_num.times { |r| a[r][c] = 0 } if x == 0\nend\n\nputs 'YES'\nrow_num.times {|r| puts a[r].join ' ' }\n"}, {"source_code": "row_num, col_num = STDIN.readline.split.map {|s| s.to_i }\nb = []\nrow_num.times do\n\tb.push(STDIN.readline.split.map {|s| s.to_i })\nend\n\nor_row = row_num.times.map { 1 }\nor_col = col_num.times.map { 1 }\n\nb.each_with_index do |row, r|\n\trow.each_with_index do |x, c|\n\t\tif x == 0\n\t\t\tor_row[r] = 0\n\t\t\tor_col[c] = 0\n\t\tend\n\tend\nend\n\nif row_num >= col_num and or_row.inject(:+) == 0\n\tcol_num.times {|c| or_col[c] = 0 }\nend\nif col_num >= row_num and or_col.inject(:+) == 0\n\trow_num.times {|r| or_row[r] = 0 }\nend\n\nb.each_with_index do |row, r|\n\trow.each_with_index do |x, c|\n\t\tif x == 1\n\t\t\tif or_row[r] == 0 and or_col[c] == 0\n\t\t\t\tputs 'NO'\n\t\t\t\texit\n\t\t\tend\n\t\tend\n\tend\nend\n\na = row_num.times.map { col_num.times.map { 1 } }\nor_row.each_with_index do |x, r|\n\tcol_num.times { |c| a[r][c] = 0 } if x == 0\nend\nor_col.each_with_index do |x, c|\n\trow_num.times { |r| a[r][c] = 0 } if x == 0\nend\n\nputs 'YES'\nrow_num.times {|r| puts a[r].join ' ' }\n"}], "src_uid": "bacd613dc8a91cee8bef87b787e878ca"} {"source_code": "a = gets.strip\nb = gets.strip\nif a == b\n puts \"-1\"\nelse\n puts [a.length, b.length].max\nend\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\na,b=$<.map &:chomp\np a==b ? -1 : [a.size,b.size].max"}, {"source_code": "a = gets.chomp\nb = gets.chomp\nif a == b\n puts -1\nelse\n puts [a, b].map(&:length).max\nend\n"}, {"source_code": "a = gets.chomp()\nb = gets.chomp()\n\nif a == b\n puts \"-1\"\nelsif a.size > b.size\n puts a.size\nelse\n puts b.size\nend\n"}, {"source_code": "TEST_MODE = ARGV[0] == 't'\n\ndef evaluate(actual, expected); actual == expected ? \"OK\" : \"**NG**\"; end\ndef tests(); yield if TEST_MODE; end\ndef to_array(val); val.kind_of?(Array) ? val : [val]; end\ndef parse_int_array(str); str.split(\" \").collect{|s| s.to_i}; end\ndef p(*arg); puts \"DEBUG: \" + arg.to_s if TEST_MODE; end\n\ndef t(input, expected_output)\n input = to_array(input)\n expected_output = to_array(expected_output)\n output = []\n solve(input, output)\n puts \"#{evaluate(output, expected_output)} : input=#{input.to_s}, expected=#{expected_output.to_s}, actual=#{output.to_s}\"\nend\n\n# actual codes here\n\ndef solve(input, output)\n a, b = input[0], input[1]\n if a == b\n output << \"-1\"\n elsif a.length == b.length\n output << a.length\n else\n output << [a.length, b.length].max.to_s\n end\nend\n\ntests do\n # test cases\n t([\"abcd\", \"defgh\"], \"5\")\n t([\"a\", \"a\"], \"-1\")\n t([\"abc\", \"b\"], \"3\")\n t([\"abcde\", \"acde\"], \"5\")\nend\n\nputs solve(STDIN.read.split(\"\\n\"), []) unless TEST_MODE\n"}, {"source_code": "def f(a,b)\n\tp1=0\n\tp2=0\n\twhile p1 0\n memoized_object_name = \"@_memoized_#{methodname}\"\n define_method(methodname) do\n if(instance_variable_get(memoized_object_name).nil?)\n instance_variable_set(memoized_object_name, unbound_method.bind(self).call)\n end\n instance_variable_get(memoized_object_name)\n end\n end\nend\n\nclass Problem\n attr_reader(:a, :b)\n def initialize(a, b)\n @a = a\n @b = b\n end\n\n def ans\n return -1 if a == b\n return [a.length, b.length].max\n end\n\n def print!\n puts(ans)\n end\nend\n\na = gets.strip\nb = gets.strip\nProblem.new(a, b).print!\n"}, {"source_code": "a = gets.chomp\nb = gets.chomp\n\ndef max a, b\n\tif a > b\n\t\treturn a\n\telse\n\t\treturn b\n\tend\nend\n\nif a == b\n\tputs -1\nelse\n\tputs max(a.size, b.size)\nend\n\n"}, {"source_code": "#!/usr/bin/ruby\n\na = gets.chomp\nb = gets.chomp\n\nif a.size > b.size then\n\tputs a.size\nelsif a.size < b.size then\n\tputs b.size\nelsif a == b then\n\tputs -1\nelse\n\tputs a.size\nend"}, {"source_code": "#!/usr/bin/env ruby\n\na = gets.strip\nb = gets.strip\n\na_size = a.size\nb_size = b.size\n\ncmp = a_size <=> b_size\nif cmp == 1\n puts a_size\nelsif cmp == -1\n puts b_size\nelsif a == b\n puts -1\nelse\n puts a_size\nend\n\nexit 0\n"}, {"source_code": "x = gets.chomp\ny = gets.chomp\nres = x != y ? (x.size < y.size ? y.size : x.size) : -1\nputs res\n"}, {"source_code": "a = gets.chop\nb = gets.chop\nif a == b\n puts -1\nelse\n puts [a.size, b.size].max\nend\n"}, {"source_code": "a,b=$<.map &:chomp\np a==b ? -1 : [a.size,b.size].max"}], "negative_code": [{"source_code": "a = gets.strip\nb = gets.strip\nn = [a.length, b.length].max\nans = count = 0\nn.times do |i|\n if a[i] != b[i]\n count += 1\n else\n count = 0\n end\n ans = [ans, count].max\nend\nans = -1 if ans == 0\nputs ans\n"}, {"source_code": "a=gets.chomp\nb=gets.chomp\n\np1=0\np2=0\n\nwhile p1=x)\r\n summaA = 0\r\n else\r\n summaA=a-x\r\n end\r\n if(b>=y)\r\n summaB=0\r\n else\r\n summaB=b-y\r\n end\r\n summa = summaA+summaB+c\r\n if(summa>=0)\r\n puts \"YES\"\r\n else \r\n puts \"NO\"\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "7ac27da2546a50d453f7bb6cacef1068"} {"source_code": "#!/usr/bin/ruby\nn,*a=$<.read.split.map(&:to_i)\nb=a.sort.each_cons(2).map{|x,y|y-x}\nm=b.min\nputs '%d %d'%[m,b.count(m)]", "positive_code": [{"source_code": "n = gets.strip.to_i\ndata = gets.split.map(&:to_i).sort\n\ndis = (0..n-2).map { |i| data[i+1] - data[i] }\nans = dis.min\nprint \"#{ans} #{dis.select { |v| v == ans }.length}\\n\"\n"}, {"source_code": "n=gets.to_i\naa=gets.split.map(&:to_i).sort\naa=aa[1, n-1].zip(aa).map { |a, b| a-b }\nm=aa.min\nprint m, ' ', aa.count(m)\n"}, {"source_code": "gets\npos = gets.split.map{|x| x.to_i}.sort\n\nfor idx in (0...pos.length-1) do\n pos[idx] = pos[idx+1]-pos[idx]\nend\n\npos.pop\n\nm = pos.min\nputs \"#{m} #{pos.count(m)}\"\n"}, {"source_code": "n = gets.chomp.to_i\ncities = gets.chomp.split().map { |e| e.to_i }\ndistances = []\ncities.sort!\nfor i in 0 ... (n - 1)\n distances << (cities[i] - cities[i + 1]).abs\nend\nminDis = distances.min\nrepeat = distances.count(minDis)\nprint \"#{minDis} #{repeat}\\n\"\n"}, {"source_code": "n=gets.to_i\na=gets.split.map{ |x| x.to_i }\na.sort!\nmin_distance=2*10**9+1\nmin_count=0\nfor i in 1...a.length\n\tif a[i]-a[i-1] < min_distance\n\t\tmin_distance=a[i]-a[i-1]\n\t\tmin_count=1\n\telsif a[i]-a[i-1] == min_distance\n\t\tmin_count+=1\n\tend\nend\nputs \"#{min_distance} #{min_count}\"\n"}], "negative_code": [{"source_code": "n=3\naa=gets.split.map(&:to_i).sort\naa=aa[1, n-1].zip(aa).map { |a, b| a-b }\nm=aa.min\nprint m, ' ', aa.count(m)\n"}], "src_uid": "5f89678ae1deb1d9eaafaab55a64197f"} {"source_code": "gets\nb=gets.split\nz=gets.split.map &:to_i\ns=0\nr=z.map{0}\nb.map{|c|s+=c.to_i\nwhile(t=z.select{|i|i<=s})[0]\nr[z.index m=t.max]+=s/m\ns%=m\nend}\nputs r*\" \",s\n", "positive_code": [{"source_code": "def koukan()\n return -1 if $sum < $aa[0]\n 5.downto(1) { |i|\n return i-1 if $aa[i-1] <= $sum\n }\nend\n\n$n = gets.chomp.to_i\n$sa = gets.chomp.split(/ /).map!{|x| x.to_i}\n$aa = gets.chomp.split(/ /).map!{|x| x.to_i}\n$sum = 0\n$suma = Array.new(5).map!{|x| x = 0}\nfor i in 0..$n-1\n $sum += $sa[i]\n while (true)\n if $sum > $aa[4]\n wka = $sum.divmod($aa[4])\n $suma[4] += wka[0]\n $sum -= $aa[4] * wka[0]\n end\n ret = koukan()\n break if ret < 0\n $suma[ret] += 1\n $sum -= $aa[ret]\n end\nend\nputs $suma.join(\" \")\nputs $sum\n"}, {"source_code": "gets\nb=gets.split\nz=gets.split.map &:to_i\ns=0\nr=z.map{0}\nb.map{|c|s+=c.to_i\nwhile(t=z.select{|i|i<=s})[0]\nr[z.index m=t.max]+=s/m\ns%=m\nend}\nputs r*\" \",s"}, {"source_code": "gets\nbats = gets.split\nprizes = gets.split.map &:to_i\nscore = 0\nres = prizes.map{0}\nfor bat in bats\n score += bat.to_i\n loop do\n can = prizes.select{ |e| e <= score }\n break if can.empty?\n x = can.max\n res[prizes.index x] += score / x\n score %= x\n end\nend\n\nputs res.join \" \"\nputs score\n"}, {"source_code": "gets\nbats = gets.split\nprizes = gets.split.map.with_index{|e,i|[e.to_i,i]}\nscore = 0\nres = prizes.map{0}\nfor bat in bats\n score += bat.to_i\n loop do\n can = prizes.select{ |e,i| e <= score }\n break if can.empty?\n x = can.max_by(&:first)\n res[x.last] += score / x.first\n score %= x.first\n end\nend\n\nputs res.join \" \"\nputs score"}, {"source_code": "gets\nb=gets.split\nz=gets.split.map &:to_i\ns=0\nr=z.map{0}\nb.map{|c|s+=c.to_i\nwhile(t=z.select{|i|i<=s})[0]\nr[z.index m=t.max]+=s/m\ns%=m\nend}\nputs r*\" \",s\n"}, {"source_code": "gets\nb=gets.split\nz=gets.split.map &:to_i\ns=0\nr=z.map{0}\nb.map{|c|s+=c.to_i\nwhile(t=z.select{|i|i<=s})[0]\nr[z.index m=t.max]+=s/m\ns%=m\nend}\nputs r*\" \",s\n"}, {"source_code": "n = gets.to_i\np = gets.split.map(&:to_i)\nst = gets.split.map(&:to_i)\nres = Array.new(5,0)\n\nr = p.inject(0) { |acc, x| t = acc + x; (0..4).reverse_each { |j| res[j] += t / st[j]; t %= st[j] }; t }\nputs res*' '\nputs r"}, {"source_code": "gets\nb=gets.split\nz=gets.split.map &:to_i\ns=0\nr=z.map{0}\nb.map{|c|s+=c.to_i\nwhile(t=z.select{|i|i<=s})[0]\nr[z.index m=t.max]+=s/m\ns%=m\nend}\nputs r*\" \",s\n"}, {"source_code": "gets\nb=gets.split\nz=gets.split.map &:to_i\ns=0\nr=z.map{0}\nb.map{|c|s+=c.to_i\nwhile(t=z.select{|i|i<=s})[0]\nr[z.index m=t.max]+=s/m\ns%=m\nend}\nputs r*\" \",s\n"}, {"source_code": "n = gets.to_i\np = gets.split.map{|e| e.to_i }\ncost = gets.split.map{|e| e.to_i }\ncount = Array.new(5){0}\nremain = 0\ncost.reverse!\np.each do |i|\n remain += i\n 5.times do |j|\n if remain >= cost[j]\n tmp = (remain / cost[j]).truncate\n remain -= cost[j] * tmp\n count[4-j] += tmp\n end\n end\nend\nputs \"#{count[0]} #{count[1]} #{count[2]} #{count[3]} #{count[4]}\"\nputs remain"}, {"source_code": "n = gets.to_i\na = gets.split.map { |s| s.to_i }\nb = gets.split.map { |s| s.to_i }\ns, r, i = 0, b.map {0}\nn.times { |i|\n s = s + a[i] if i < n \n loop {\n c = b.select { |p| s >= p } \n break if c.empty?\n m = c.max\n r[b.index(m)] += (s / m) \n s = s - ((s / m) * m)\n }\n i = i + 1\n}\nputs r.join(\" \")\nputs s\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |s| s.to_i }\nb = gets.split.map { |s| s.to_i }\ns, r, i = 0, b.map {0}\nn.times { |i|\n s = s + a[i] if i < n \n loop {\n m, o = 0, -1 \n 5.times { |j|\n if s >= b[j]\n m = b[j]\n o = j\n end\n }\n break if o == -1\n r[o] = r[o] + (s / m) \n s = s - ((s / m) * m)\n }\n i = i + 1\n}\nputs r.join(\" \")\nputs s\n"}, {"source_code": "#!/usr/bin/ruby\nn = gets.chomp.to_i\np = gets.chomp.split(' ').map{|x| x.to_i}\na,b,c,d,e = gets.chomp.split(' ').map{|x| x.to_i}\nna = 0\nnb = 0\nnc = 0\nnd = 0\nne = 0\ncurr = 0\nfor i in 0..p.size-1\n\tcurr += p[i]\n\twhile curr >= a\n\t\tif curr >= e\n\t\t\tne += curr/e\n\t\t\tcurr=curr%e\n\t\telsif curr >= d\n\t\t\tnd +=curr/d\n\t\t\tcurr =curr%d\n\t\telsif curr >= c\n\t\t\tnc += curr/c\n\t\t\tcurr = curr%c\n\t\telsif curr >= b \n\t\t\tnb += curr/b\n\t\t\tcurr =curr%b\n\t\telsif curr >= a\n\t\t\tna +=curr/a\n\t\t\tcurr =curr%a\n\t\tend\n\tend\nend\nprint \"#{na} #{nb} #{nc} #{nd} #{ne}\\n\"\nputs curr\n"}, {"source_code": "gets\nb=gets.split\nz=gets.split.map &:to_i\ns=0\nr=z.map{0}\nb.map{|c|s+=c.to_i\nwhile(t=z.select{|i|i<=s})[0]\nr[z.index m=t.max]+=s/m\ns%=m\nend}\nputs r*\" \",s"}, {"source_code": "gets\nb=gets.split\nz=gets.split.map &:to_i\ns=0\nr=z.map{0}\nb.map{|c|s+=c.to_i\nwhile(t=z.select{|i|i<=s})[0]\nr[z.index m=t.max]+=s/m\ns%=m\nend}\nputs r*\" \",s\n"}, {"source_code": "require \"scanf\"\nn = gets.to_i\nlist = []\ngets.split(\" \").each {\n |i| list.push(i.to_i)\n}\ncost = scanf(\"%d%d%d%d%d\")\ncnt = [0,0,0,0,0]\ntot = 0\nlist.each { |i| \n tot += i\n 5.times { |j|\n cnt[4 - j] += tot / cost[4 - j]\n tot %= cost[4 - j]\n }\n}\ncnt.each{ |i| print i, \" \"}\nprint \"\\n\", tot\n"}, {"source_code": "n = gets.to_i\np = gets.split.collect{|i| i.to_i}\nc = gets.split.collect{|i| i.to_i}\nans = Array.new(5,0)\npoints = 0\np.each do |pp|\n points += pp\n 4.downto(0).each do |i|\n ans[i] += points/c[i]\n points = points%c[i]\n end\nend\nputs ans.join(\" \")\nputs points\n"}, {"source_code": "n,=gets.split.map{|e| e.to_i}\na=gets.split.map{|e| e.to_i}\nb=gets.split.map{|e| e.to_i}\nc=Array.new(5,0)\ni=0\nk=0\nwhile i 0\n\t\t\tprint \" \"\n\t\tend\n\t\tprint ans[i]\n\tend\n\tputs\n\tputs now\nend\n"}, {"source_code": "gets\nb=gets.split\nz=gets.split.map &:to_i\ns=0\nr=z.map{0}\nb.map{|c|s+=c.to_i\nwhile(t=z.select{|i|i<=s})[0]\nr[z.index m=t.max]+=s/m\ns%=m\nend}\nputs r*\" \",s\n"}, {"source_code": "gets\nb=gets.split\nz=gets.split.map &:to_i\ns=0\nr=z.map{0}\nb.map{|c|s+=c.to_i\nwhile(t=z.select{|i|i<=s})[0]\nr[z.index m=t.max]+=s/m\ns%=m\nend}\nputs r*\" \",s\n"}], "negative_code": [{"source_code": "gets\nbats = gets.split.map &:to_i\nprizes = gets.split.map &:to_i\nscore = 0\nres = prizes.map{0}\nfor bat in bats\n score += bat\n\n can = prizes.select{ |prize| prize <= score }\n break if can.empty?\n res[prizes.index(can.max)] += score / can.max\n score %= can.max\n \nend\nputs res.join \" \"\nputs score"}, {"source_code": "#!/usr/bin/ruby\nn = gets.chomp.to_i\np = gets.chomp.split(' ').map{|x| x.to_i}\na,b,c,d,e = gets.chomp.split(' ').map{|x| x.to_i}\nna = 0\nnb = 0\nnc = 0\nnd = 0\nne = 0\ncurr = 0\nfor i in 0..p.size-1\n\tcurr += p[i]\n\twhile curr >= a\n\t\tif curr >= e\n\t\t\tcurr-=e\n\t\t\tne += 1\n\t\telsif curr >= d\n\t\t\tcurr -= d\n\t\t\tnd +=1\n\t\telsif curr >= c\n\t\t\tcurr -= c\n\t\t\tnc += 1\n\t\telsif curr >= b \n\t\t\tcurr -= b\n\t\t\tnb += 1\n\t\telsif curr >= a\n\t\t\tcurr -=a\n\t\t\tna +=1\n\t\tend\n\tend\nend\nprint \"#{na} #{nb} #{nc} #{nd} #{ne}\\n\"\n"}, {"source_code": "require \"scanf\"\nn = gets.to_i\nlist = []\ngets.split(\" \").each {\n |i| list.push(i.to_i)\n}\ncost = scanf(\"%d%d%d%d%d\")\ncnt = [0,0,0,0,0]\ntot = 0\nlist.each { |i| \n tot += i\n 5.times { |j|\n p j\n while tot >= cost[4 - j] \n cnt[4 - j] += 1\n tot -= cost[4 - j]\n end\n }\n}\ncnt.each{ |i| \n print i , \" \"}\nprint \"\\n\",tot\n"}, {"source_code": "n,=gets.split.map{|e| e.to_i}\na=gets.split.map{|e| e.to_i}\nb=gets.split.map{|e| e.to_i}\nc=Array.new(5,0)\ni=0\nk=0\nwhile ik then break end\n end\n j-=1\n if j>=0 then c[j]+=1; k-=b[j] end\n i+=1\nend\nfor i in 0..4 do\n print c[i],' '\nend \nputs \"\\n\", k"}, {"source_code": "def read_next_line\n gets.split.map(&:to_i)\nend\n\ngets\np = read_next_line\na = read_next_line\n\nt = Array.new(5, 0)\ns = 0\np.each { |x|\n s += x\n t[4] += s / a[4]\n s %= a[4]\n 3.downto(0).each { |i|\n if a[i] <= s\n s -= a[i]\n t[i] += 1\n end\n }\n}\n\nputs t * ' '\nputs s"}], "src_uid": "1ae2942b72ebb7c55359c41e141900d7"} {"source_code": "# Input\nn, r = gets.split(\" \").map { |e| e.to_f }\n\n# Processing\nalpha = 2 * Math::PI / n\nv = Math.sin(alpha / 2)\nresult = r * v / (1 - v)\n\n# Output\nputs result\n", "positive_code": [{"source_code": "n, r = gets.split.map(&:to_f)\nl = 0.0\nrt = 10e5\neps = 10e-8\nwhile (rt - l > eps)\n m = (rt - l) / 2 + l # \u0440\u0430\u0434\u0438\u0443\u0441 r\n rr = m + r\n d = Math.acos((rr ** 2 + rr ** 2 - (m * 2) ** 2)/(2 * rr * rr))\n if (d / Math::PI * 180 > (360.0 / n))\n rt = m\n else\n l = m\n end\nend\nputs rt"}, {"source_code": "n,r = gets.split.map(&:to_f)\ns = Math.sin(Math::PI/n)\nputs r*s/(1-s)"}], "negative_code": [], "src_uid": "e27cff5d681217460d5238bf7ef6a876"} {"source_code": "n = gets.to_i\nt = (n / 2).times.map{|i| i.odd? ? '00' : '11'} * ''\nif n.odd?\n\ts = [\n\t\t'i' + t.tr('01', 'ab'),\n\t\t'i' + t.tr('01', 'cd'),\n\t\tt.tr('01', 'ef') + 'j',\n\t\tt.tr('01', 'gh') + 'j']\nelse\n\ts = [\n\t\tt.tr('01', 'ab'),\n\t\tt.tr('01', 'cd'),\n\t\t'i' + t[2..-1].tr('01', 'ef') + 'j',\n\t\t'i' + t[2..-1].tr('01', 'gh') + 'j']\nend\nputs s * \"\\n\"\n", "positive_code": [{"source_code": "N = gets.to_i\n\n#01234567\n#aaffaaff\n#bbggbbgg\n#cddhhcchh\n#ceeiiddii\n\nstr = []\nstr[0] = \"aaff\" * 25\nstr[1] = \"bbgg\" * 25\nstr[2] = \"cdd\" + \"hhcc\" * 25\nstr[3] = \"cee\" + \"iidd\" * 25\n\nif N == 1\n print \"a\\na\\nb\\nb\\n\"\nelsif N == 2\n puts \"aa\"\n puts \"bb\"\n puts \"cd\"\n puts \"cd\"\nelse\n# p str\n if (N % 2 == 1)\n str[1][N - 1] = str[0][N - 1]\n else\n str[3][N - 1] = str[2][N - 1]\n end\n 4.times do |i|\n puts str[i][0..(N - 1)]\n end\nend\n\n"}, {"source_code": "n = gets.to_i\n\ndef dig2str(dig)\n p = 'a'\n (dig%26).times { p = p.succ }\n p\nend\n\ndef solve(n)\n return ['a', 'a', 'b', 'b'] if n == 1\n return ['aa', 'bb', 'cc', 'dd'] if n == 2\n a = Array.new(4) { Array.new(n) }\n dig = 0\n 0.step(n-2, 2) do |i|\n a[0][i] = a[0][i+1] = dig2str(dig)\n dig += 1\n a[1][i] = a[1][i+1] = dig2str(dig)\n dig += 1\n end\n dig = 10\n 1.step(n-2, 2) do |i|\n a[2][i] = a[2][i+1] = dig2str(dig)\n dig += 1\n a[3][i] = a[3][i+1] = dig2str(dig)\n dig += 1\n end\n if n%2==0\n a[2][-1] = a[3][-1] = dig2str(dig)\n else\n a[0][-1] = a[1][-1] = dig2str(dig)\n end\n a[2][0] = a[3][0] = dig2str(9)\n return a.map(&:join)\nend\n\nputs solve(n)\n\n"}, {"source_code": "def build_line(s1, s2, len)\n (1..len).map { |i| i.odd? ? s1 : s2 }.join ''\nend\n\ndef build_odd(n)\n line1 = build_line('aa', 'bb', (n - 1) / 2)\n line2 = build_line('cc', 'dd', (n - 1) / 2)\n puts line1 + 'x'\n puts line2 + 'x'\n puts 'y' + line1\n puts 'y' + line2\nend\n\ndef build_even(n)\n line1 = build_line('aa', 'bb', n / 2)\n puts line1\n puts 'x' + build_line('cc', 'dd', n / 2 - 1) + 'y'\n puts 'x' + build_line('ee', 'ff', n / 2 - 1) + 'y'\n puts line1\nend\n\nn = gets.to_i\nif n.odd?\n build_odd(n)\nelse\n build_even(n)\nend"}], "negative_code": [{"source_code": "N = gets.to_i\n\n#01234567\n#aaffaaff\n#bbggbbgg\n#cddhhcchh\n#ceeiiddii\n\nstr = []\nstr[0] = \"aaff\" * 25\nstr[1] = \"bbgg\" * 25\nstr[2] = \"cdd\" + \"hhcc\" * 25\nstr[3] = \"cee\" + \"iidd\" * 25\n\nif N == 1\n print \"a\\na\\nb\\nb\\n\"\nelsif N == 2\n puts \"aa\"\n puts \"bb\"\n puts \"cd\"\n puts \"cd\"\nelse\n p str\n if (N % 2 == 1)\n str[1][N - 1] = str[0][N - 1]\n else\n str[3][N - 1] = str[2][N - 1]\n end\n 4.times do |i|\n puts str[i][0..(N - 1)]\n end\nend\n\n"}], "src_uid": "42a51b45312be6b38f3a15949d315c67"} {"source_code": "s=(gets.to_i+1)/2\na=gets(p).scan /(\\S+) (.+)/\nx=a.flatten.sort.each_slice([a.size/2,1].max).map(&:first).select{|i|a.count{|j,k|j==i||k==i}>=s}\np x[0]?[s-x.map{|i|a.map(&:first).count i}.max,0].max: -1\n", "positive_code": [{"source_code": "s2 = (gets.to_i+1)/2\na = gets(p).scan(/(\\S+) (\\S+)/)\naf,al = a.transpose\n\nas = a.flatten.sort.each_slice([a.size/2,1].max).map(&:first)\nx = as.select{ |i|\n a.count{ |j,k| j == i || k == i } >= s2\n}\n\np x.empty? ? -1 : [(\n a1 = af.group_by{|i|i}\n #s2 - x.map{ |i| a1[i] ? a1[i].size : 0 }.max\n s2 - x.map{ |i| af.count i }.max\n), 0].max"}, {"source_code": "s=(gets.to_i+1)/2\na=gets(p).scan /(\\S+) (.+)/\nx=a.flatten.sort.each_slice([a.size/2,1].max).map(&:first).select{|i|a.count{|j,k|j==i||k==i}>=s}\np x[0]?[s-x.map{|i|a.map(&:first).count i}.max,0].max: -1\n"}, {"source_code": "s=(gets.to_i+1)/2\na=gets(p).scan /(\\S+) (.+)/\nx=a.flatten.sort.each_slice([a.size/2,1].max).map(&:first).select{|i|a.count{|j,k|j==i||k==i}>=s}\np x[0]?[s-x.map{|i|a.map(&:first).count i}.max,0].max: -1\n"}, {"source_code": "s=(gets.to_i+1)/2\na=gets(p).scan /(\\S+) (.+)/\nx=a.flatten.sort.each_slice([a.size/2,1].max).map(&:first).select{|i|a.count{|j,k|j==i||k==i}>=s}\np x[0]?[s-x.map{|i|a.map(&:first).count i}.max,0].max: -1\n"}, {"source_code": "s=(gets.to_i+1)/2\na=gets(p).scan /(\\S+) (.+)/\nx=a.flatten.sort.each_slice([a.size/2,1].max).map(&:first).select{|i|a.count{|j,k|j==i||k==i}>=s}\np x[0]?[s-x.map{|i|a.map(&:first).count i}.max,0].max: -1\n"}, {"source_code": "s=(gets.to_i+1)/2\na=gets(p).scan /(\\S+) (.+)/\nx=a.flatten.sort.each_slice([a.size/2,1].max).map(&:first).select{|i|a.count{|j,k|j==i||k==i}>=s}\np x[0]?[s-x.map{|i|a.map(&:first).count i}.max,0].max: -1\n"}, {"source_code": "s=(gets.to_i+1)/2\na=gets(p).scan /(\\S+) (.+)/\nx=a.flatten.sort.each_slice([a.size/2,1].max).map(&:first).select{|i|a.count{|j,k|j==i||k==i}>=s}\np x[0]?[s-x.map{|i|a.map(&:first).count i}.max,0].max: -1\n"}, {"source_code": "s=(gets.to_i+1)/2\na=gets(p).scan /(\\S+) (.+)/\nx=a.flatten.sort.each_slice([a.size/2,1].max).map(&:first).select{|i|a.count{|j,k|j==i||k==i}>=s}\np x[0]?[s-x.map{|i|a.map(&:first).count i}.max,0].max: -1\n"}, {"source_code": "n = gets.to_i \no = (n - 1) / 2 + 1\n@m = 1 << 30\nh, k = {}, {}\ndef f(a, b, p, q) \n a.each_pair { |y, v| \n if b.has_key?(y) and v + b[y] >= p \n @m = q == 0 ? [@m, p - v].min : [@m, p - b[y]].min\n elsif v >= p \n @m = [@m, q].min\n end \n }\nend \nn.times { |x| \n a, b = gets.split.map { |i| i.to_i }\n h[a] = h.has_key?(a) ? h[a] + 1 : 1\n k[b] = k.has_key?(b) ? k[b] + 1 : 1 if a != b\n}\nf(h, k, o, 0)\nf(k, h, o, o)\nputs @m == 1 << 30 ? -1 : [0, @m].max\n\n"}, {"source_code": "n = gets.to_i \no = (n - 1) / 2 + 1\nb = []\nh, k = {}, {}\nn.times { |x| \n b << gets.split.map { |i| i.to_i }\n h[b[x][0]] = h.has_key?(b[x][0]) ? h[b[x][0]] + 1 : 1\n k[b[x][1]] = k.has_key?(b[x][1]) ? k[b[x][1]] + 1 : 1 if b[x][1] != b[x][0]\n}\nm = 1 << 30\nh.each_pair { |y, v| \n if k.has_key?(y) and v + k[y] >= o \n m = [m, o - v].min\n elsif v >= o \n puts 0\n exit\n end \n}\nk.each_pair { |y, v| \n if h.has_key?(y) and v + h[y] >= o \n m = [m, o - h[y]].min\n elsif v >=o \n puts o \n exit\n end\n}\nputs m == 1 << 30 ? -1 : [0, m].max\n\n"}, {"source_code": "s2 = (gets.to_i+1)/2\na = gets(p).scan(/(\\S+) (\\S+)/)\naf,al = a.transpose\n\nas = a.flatten.sort.each_slice([a.size/2,1].max).map(&:first)\nx = as.select{ |i|\n a.count{ |j,k| j == i || k == i } >= s2\n}\n\np x.empty? ? -1 : [(\n a1 = af.group_by{|i|i}\n s2 - x.map{ |i| a1[i] ? a1[i].size : 0 }.max\n #s2 - x.map{ |i| af.count i }.max\n), 0].max"}, {"source_code": "s=(gets.to_i+1)/2\na=gets(p).scan /(\\S+) (.+)/\nx=a.flatten.sort.each_slice([a.size/2,1].max).map(&:first).select{|i|a.count{|j,k|j==i||k==i}>=s}\np x[0]?[s-x.map{|i|a.map(&:first).count i}.max,0].max: -1"}], "negative_code": [{"source_code": "s2 = (gets.to_i+1)/2\na = gets(p).scan(/(\\S+) (\\S+)/)\naf,al = a.transpose\n\nas = a.flatten.sort\nx = [as[0],as[as.size/2]].select{ |i|\n a.count{ |j,k| j == i || k == i } >= s2\n}\n\np x.empty? ? -1 : [(\n a1 = af.group_by{|i|i}\n s2 - x.map{ |i| a1[i] ? a1[i].size : 0 }.max\n #s2 - x.map{ |i| af.count i }.max\n), 0].max"}, {"source_code": "n = gets.to_i \no = (n - 1) / 2 + 1\nb = []\nh, k = {}, {}\nn.times { |x| \n b << gets.split.map { |i| i.to_i }\n h[b[x][0]] = h.has_key?(b[x][0]) ? h[b[x][0]] + 1 : 1\n k[b[x][1]] = k.has_key?(b[x][1]) ? k[b[x][1]] + 1 : 1\n}\nm = 1 << 30\nh.each_pair { |y, v| \n if k.has_key?(y) and v + k[y] >= o \n m = [m, o - v].min\n elsif v >= o \n puts 0\n exit\n end \n}\nk.each_pair { |y, v| \n if h.has_key?(y) and v + h[y] >= o \n m = [m, o - h[y]].min\n elsif v >=o \n puts o \n exit\n end\n}\nputs [0, m].max\n\n"}, {"source_code": "n = gets.to_i \no = (n - 1) / 2 + 1\nb = []\nh, k = {}, {}\nn.times { |x| \n b << gets.split.map { |i| i.to_i }\n h[b[x][0]] = h.has_key?(b[x][0]) ? h[b[x][0]] + 1 : 1\n k[b[x][1]] = k.has_key?(b[x][1]) ? k[b[x][1]] + 1 : 1\n}\nm = 1 << 30\nh.each_pair { |y, v| \n if k.has_key?(y) and v + k[y] >= o \n m = [m, o - v].min\n elsif v >= 0\n puts 0\n exit\n end \n}\nk.each_pair { |y, v| \n if h.has_key?(y) and v + h[y] >= o \n m = [m, o - h[y]].min\n elsif v >=o \n puts 0\n exit\n end\n}\nputs [0, m].max\n\n"}, {"source_code": "n = gets.to_i \no = (n - 1) / 2 + 1\n@m = 1 << 30\nh, k = {}, {}\ndef f(a, b, p, q) \n a.each_pair { |y, v| \n if b.has_key?(y) and v + b[y] >= p \n @m = [@m, p - v].min\n elsif v >= p \n @m = [@m, q].min\n end \n }\nend \nn.times { |x| \n a, b = gets.split.map { |i| i.to_i }\n h[a] = h.has_key?(a) ? h[a] + 1 : 1\n k[b] = k.has_key?(b) ? k[b] + 1 : 1 if a != b\n}\nf(h, k, o, 0)\nf(h, k, o, o)\nputs @m == 1 << 30 ? -1 : [0, @m].max\n\n"}, {"source_code": "n = gets.to_i \no = (n - 1) / 2 + 1\n@m = 1 << 30\nh, k = {}, {}\ndef f(a, b, p, q) \n a.each_pair { |y, v| \n if b.has_key?(y) and v + b[y] >= p \n @m = [@m, p - v].min\n elsif v >= p \n @m = [@m, q].min\n end \n }\nend \nn.times { |x| \n a, b = gets.split.map { |i| i.to_i }\n h[a] = h.has_key?(a) ? h[a] + 1 : 1\n k[b] = k.has_key?(b) ? k[b] + 1 : 1 if a != b\n}\nf(h, k, o, 0)\nf(k, h, o, o)\nputs @m == 1 << 30 ? -1 : [0, @m].max\n\n"}, {"source_code": "n = gets.to_i \no = (n - 1) / 2 + 1\nb = []\nh, k = {}, {}\nn.times { |x| \n b << gets.split.map { |i| i.to_i }\n h[b[x][0]] = h.has_key?(b[x][0]) ? h[b[x][0]] + 1 : 1\n k[b[x][1]] = k.has_key?(b[x][1]) ? k[b[x][1]] + 1 : 1\n}\nm = 1 << 30\nh.each_pair { |y, v| \n if k.has_key?(y) and v + k[y] >= o \n m = [m, o - v].min\n elsif v >= o \n puts 0\n exit\n end \n}\nk.each_pair { |y, v| \n if h.has_key?(y) and v + h[y] >= o \n m = [m, o - h[y]].min\n elsif v >=o \n puts o \n exit\n end\n}\nputs m == 1 << 30 ? -1 : [0, m].max\n\n"}], "src_uid": "5e055bad1da5bdc84599d6f2f89fbd12"} {"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = [nil] * (n *= m)\nk.times do\n\ta, b, c, d = I.gets.split\n\tif /-1/ then\n\t\tc = t.index b\n\t\tif c then\n\t\t\tt[c] = nil\n\t\t\tO.puts \"#{c / m + 1} #{c % m + 1}\"\n\t\telse\n\t\t\tO.puts '-1 -1'\n\t\tend\n\telse\n\t\tb = (b.to_i - 1) * m + (c.to_i - 1)\n\t\tb += 1 while b < n && t[b]\n\t\tt[b] = d if b < n\n\tend\nend\n\n", "positive_code": [{"source_code": "f = open(\"input.txt\", \"r\")\nfw = open(\"output.txt\", \"w\")\nn,m,k = f.gets.chomp.split(/ /).map!{|x|x.to_i}\nsh = Array.new(n)\nsh.map!{|x| Array.new(m) }\nh = Hash.new\nfor i in 0..k-1\n\tar = f.gets.chomp.split(/ /)\n\tif ar[0] == \"+1\"\n\t\tx = ar[1].to_i-1\n\t\ty = ar[2].to_i-1\n\t\twhile true\n\t\t\tif sh[x][y] == nil\n\t\t\t\th[ar[3]] = (x+1).to_s + \" \" + (y+1).to_s\n\t\t\t\tsh[x][y] = ar[3]\n\t\t\t\tbreak\n\t\t\tend\n\t\t\ty += 1\n\t\t\tif y == m\n\t\t\t\tx += 1\n\t\t\t\ty = 0\n\t\t\tend\n\t\t\tif x == n\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\telse\n\t\tif h.has_key?( ar[1] )\n\t\t\tfw.puts h[ar[1]]\n\t\t\tx,y = h[ar[1]].split(/ /).map!{|x|x.to_i-1}\n\t\t\tsh[x][y] = nil\n\t\t\th.delete(ar[1])\n\t\telse\n\t\t\tfw.puts \"-1 -1\"\n\t\tend\n\tend\nend\nf.close\nfw.close\n\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = [nil] * (n *= m)\nk.times do\n\ta, b, c, d = I.gets.split\n\tif /-1/ then\n\t\tc = t.index b\n\t\tif c then\n\t\t\tt[c] = nil\n\t\t\tO.puts \"#{c / m + 1} #{c % m + 1}\"\n\t\telse\n\t\t\tO.puts '-1 -1'\n\t\tend\n\telse\n\t\tb = (b.to_i - 1) * m + (c.to_i - 1)\n\t\tb += 1 while b < n && t[b]\n\t\tt[b] = d if b < n\n\tend\nend\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = [nil] * (n *= m)\nk.times do\n\ta, b, c, d = I.gets.split\n\tif /-1/ then\n\t\tc = t.index b\n\t\tif c then\n\t\t\tt[c] = nil\n\t\t\tO.puts \"#{c / m + 1} #{c % m + 1}\"\n\t\telse\n\t\t\tO.puts '-1 -1'\n\t\tend\n\telse\n\t\tb = (b.to_i - 1) * m + (c.to_i - 1)\n\t\tb += 1 while b < n && t[b]\n\t\tt[b] = d if b < n\n\tend\nend\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = [nil] * (n *= m)\nk.times do\n\ta, b, c, d = I.gets.split\n\tif /-1/ then\n\t\tc = t.index b\n\t\tif c then\n\t\t\tt[c] = nil\n\t\t\tO.puts \"#{c / m + 1} #{c % m + 1}\"\n\t\telse\n\t\t\tO.puts '-1 -1'\n\t\tend\n\telse\n\t\tb = (b.to_i - 1) * m + (c.to_i - 1)\n\t\tb += 1 while b < n && t[b]\n\t\tt[b] = d if b < n\n\tend\nend\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = [nil] * (n *= m)\nk.times do\n\ta, b, c, d = I.gets.split\n\tif /-1/ then\n\t\tc = t.index b\n\t\tif c then\n\t\t\tt[c] = nil\n\t\t\tO.puts \"#{c / m + 1} #{c % m + 1}\"\n\t\telse\n\t\t\tO.puts '-1 -1'\n\t\tend\n\telse\n\t\tb = (b.to_i - 1) * m + (c.to_i - 1)\n\t\tb += 1 while b < n && t[b]\n\t\tt[b] = d if b < n\n\tend\nend\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = [nil] * (n *= m)\nk.times do\n\ta, b, c, d = I.gets.split\n\tif /-1/ then\n\t\tc = t.index b\n\t\tif c then\n\t\t\tt[c] = nil\n\t\t\tO.puts \"#{c / m + 1} #{c % m + 1}\"\n\t\telse\n\t\t\tO.puts '-1 -1'\n\t\tend\n\telse\n\t\tb = (b.to_i - 1) * m + (c.to_i - 1)\n\t\tb += 1 while b < n && t[b]\n\t\tt[b] = d if b < n\n\tend\nend\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = [nil] * (n *= m)\nk.times do\n\ta, b, c, d = I.gets.split\n\tif /-1/ then\n\t\tc = t.index b\n\t\tif c then\n\t\t\tt[c] = nil\n\t\t\tO.puts \"#{c / m + 1} #{c % m + 1}\"\n\t\telse\n\t\t\tO.puts '-1 -1'\n\t\tend\n\telse\n\t\tb = (b.to_i - 1) * m + (c.to_i - 1)\n\t\tb += 1 while b < n && t[b]\n\t\tt[b] = d if b < n\n\tend\nend\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = [nil] * (n *= m)\nk.times do\n a, b, c, d = I.gets.split\n if /-1/ then\n c = t.index b\n if c then\n t[c] = nil\n O.puts \"#{c / m + 1} #{c % m + 1}\"\n else\n O.puts '-1 -1'\n end\n else\n b = (b.to_i - 1) * m + (c.to_i - 1)\n b += 1 while b < n && t[b]\n t[b] = d if b < n\n end\nend"}, {"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = [nil] * (n *= m)\nk.times do\n\ta, b, c, d = I.gets.split\n\tif /-1/ then\n\t\tc = t.index b\n\t\tif c then\n\t\t\tt[c] = nil\n\t\t\tO.puts \"#{c / m + 1} #{c % m + 1}\"\n\t\telse\n\t\t\tO.puts '-1 -1'\n\t\tend\n\telse\n\t\tb = (b.to_i - 1) * m + (c.to_i - 1)\n\t\tb += 1 while b < n && t[b]\n\t\tt[b] = d if b < n\n\tend\nend\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = [nil] * (n *= m)\nk.times do\n\ta, b, c, d = I.gets.split\n\tif /-1/ then\n\t\tc = t.index b\n\t\tif c then\n\t\t\tt[c] = nil\n\t\t\tO.puts \"#{c / m + 1} #{c % m + 1}\"\n\t\telse\n\t\t\tO.puts '-1 -1'\n\t\tend\n\telse\n\t\tb = (b.to_i - 1) * m + (c.to_i - 1)\n\t\tb += 1 while b < n && t[b]\n\t\tt[b] = d if b < n\n\tend\nend\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = [nil] * (n *= m)\nk.times do\n\ta, b, c, d = I.gets.split\n\tif /-1/ then\n\t\tc = t.index b\n\t\tif c then\n\t\t\tt[c] = nil\n\t\t\tO.puts \"#{c / m + 1} #{c % m + 1}\"\n\t\telse\n\t\t\tO.puts '-1 -1'\n\t\tend\n\telse\n\t\tb = (b.to_i - 1) * m + (c.to_i - 1)\n\t\tb += 1 while b < n && t[b]\n\t\tt[b] = d if b < n\n\tend\nend\n\n"}], "negative_code": [{"source_code": "I = open('input.txt')\nO = open('output.txt','w')\nn, m, k = I.gets.split.map &:to_i\nt = Array.new(n *= m)\nk.times do\n\ta, b, c, d = I.gets.split\n\tif /-1/ then\n\t\tc = t.index b\n\t\tif c then\n\t\t\tt[c] = nil\n\t\t\tO.puts \"#{c / m + 1} #{c % m + 1}\"\n\t\telse\n\t\t\tO.puts '-1 -1'\n\t\tend\n\telse\n\t\tb = (b.to_i - 1) * m + (c.to_i - 1)\n\t\tc = 0\n\t\tb, c = b + 1, c + 1 while t[b % n] && c < n\n\t\tt[b % n] = d unless t[b % n]\n\tend\nend\n"}], "src_uid": "44d45a7e21418470bda396d91c65e736"} {"source_code": "gets\na, b = gets.split.map(&:to_i), [2000]\nwhile a.any? && p = a.index(b.size) do\n\tb << b[-1] + p + 1\n\ta = a[p + 1 .. -1]\nend\nb[0] = b.size - 1\nputs b * ' '\n\n", "positive_code": [{"source_code": "gets\na, b = gets.split.map(&:to_i), [2000]\nwhile a.any? && p = a.index(b.size) do\n\tb << b[-1] + p + 1\n\ta = a[p + 1 .. -1]\nend\nb[0] = b.size - 1\nputs b * ' '\n"}, {"source_code": "gets\na, b = gets.split.map(&:to_i), [2000]\nwhile a.any? && p = a.index(b.size) do\n\tb << b[-1] + p + 1\n\ta = a[p + 1 .. -1]\nend\nb[0] = b.size - 1\nputs b * ' '\n\n"}, {"source_code": "gets\na, b = gets.split.map(&:to_i), [2000]\nwhile a.any? && p = a.index(b.size) do\n\tb << b[-1] + p + 1\n\ta = a[p + 1 .. -1]\nend\nb[0] = b.size - 1\nputs b * ' '\n\n"}, {"source_code": "gets\na, b = gets.split.map(&:to_i), [2000]\nwhile a.any? && p = a.index(b.size) do\n\tb << b[-1] + p + 1\n\ta = a[p + 1 .. -1]\nend\nb[0] = b.size - 1\nputs b * ' '\n"}, {"source_code": "gets\na, b = gets.split.map(&:to_i), [2000]\nwhile a.any? && p = a.index(b.size) do\n\tb << b[-1] + p + 1\n\ta = a[p + 1 .. -1]\nend\nb[0] = b.size - 1\nputs b * ' '\n\n"}, {"source_code": "n = gets.to_i\n\na = gets.split.map(&:to_i)\n\nans ||= []\n\npre = 0\na.each_index do |x|\n if a[x] == pre + 1\n ans << x + 2001\n pre = a[x]\n end\nend\n\nputs ans.size\nputs ans * \" \" if ans.any?\n\n"}, {"source_code": "gets\na, b = gets.split.map(&:to_i), [2000]\nwhile a.any? && p = a.index(b.size) do\n\tb << b[-1] + p + 1\n\ta = a[p + 1 .. -1]\nend\nb[0] = b.size - 1\nputs b * ' '\n\n"}, {"source_code": "gets\na, b = gets.split.map(&:to_i), [2000]\nwhile a.any? && p = a.index(b.size) do\n\tb << b[-1] + p + 1\n\ta = a[p + 1 .. -1]\nend\nb[0] = b.size - 1\nputs b * ' '\n\n"}, {"source_code": "gets\na, b = gets.split.map(&:to_i), [2000]\nwhile a.any? && p = a.index(b.size) do\n\tb << b[-1] + p + 1\n\ta = a[p + 1 .. -1]\nend\nb[0] = b.size - 1\nputs b * ' '\n\n"}, {"source_code": "gets\na, b = gets.split.map(&:to_i), [2000]\nwhile a.any? && p = a.index(b.size) do\n\tb << b[-1] + p + 1\n\ta = a[p + 1 .. -1]\nend\nb[0] = b.size - 1\nputs b * ' '\n\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /).map!{|x|x.to_i}\n\nyears = Array.new\nseq = 1\nfor i in 0..n-1\n\tif a[i] == seq\n\t\tyears.push((2001+i).to_s)\n\t\tseq += 1\n\tend\nend\n\nif years.length == 0\n\tputs \"0\"\nelse\n\tputs years.length.to_s\n\tputs years.join(' ')\nend"}], "negative_code": [], "src_uid": "499ddfd7e0563e3ca8c71219e408650f"} {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# c.rb\n\ndef main()\n n, m = gets.chomp.split(\" \").map{|s| next s.to_i }\n d = [0] * m\n h = [0] * m\n\n m.times do |i|\n d[i], h[i] = gets.chomp.split(\" \").map{|s| next s.to_i }\n end\n\n r = h[0]\n 1.upto(m-1) do |i|\n dd = d[i] - d[i-1]\n dh = h[i] - h[i-1]\n if dd.abs < dh.abs then\n puts(\"IMPOSSIBLE\")\n return\n else\n r = [r, h[i]].max\n r = [r, [h[i], h[i-1]].min + (dd.abs + dh.abs) / 2 ].max\n end\n end\n r = [r, h[-1] + (n - d[-1])].max\n r = [r, h[0] + (d[0] - 1)].max\n puts r\nend\n\nif __FILE__ == $0 then\n main()\nend\n", "positive_code": [{"source_code": "n, m = gets.split.map {|i| i.to_i}\nb1, a1 = gets.split.map {|i| i.to_i}\nmaxx = a1 + b1 - 1\nfor i in 0...m - 1\n b, a = gets.split.map {|i| i.to_i}\n maxx = [maxx, (b - b1 + a1 + a) / 2].max\n if (a1 - a).abs > (b1 - b).abs\n print 'IMPOSSIBLE'\n exit(0)\n end\n a1, b1 = a, b\nend\nprint [maxx, a1 + n - b1].max\n# a - a1 + a - a2 <= b2 - b1\n# a + a <= b2 - b1 + a1 + a2\n# a <= (b2 - b1)\n"}, {"source_code": "n, m = gets.strip.split(\" \").map(&:to_i)\nrecord = Array.new\nm.times do |i|\n d, h = gets.strip.split(\" \").map(&:to_i)\n record.push [d, h]\nend\npossible = true\nmaxh = 0\n(m-1).times do |i|\n dd = record[i+1][0] - record[i][0]\n dh = record[i+1][1] - record[i][1]\n if dh.abs > dd\n possible = false\n end\n hh = (dd - dh.abs) / 2\n maxh = [maxh, record[i+1][1] + hh, record[i][1] + hh].max\nend\n\nc1 = record[0][0] + record[0][1] - 1\nc2 = (n - record[-1][0]) + record[-1][1]\nmaxh = [c1, c2, maxh].max\n\nif possible\n puts maxh\nelse\n puts \"IMPOSSIBLE\"\nend\n"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\npre = gets.split.collect{|i| i.to_i}\nans = pre[1]+pre[0]-1\n(1...m).each do\n tmp = gets.split.collect{|i| i.to_i}\n t = tmp[0]-pre[0]\n v1, v2 = [pre[1], tmp[1]].minmax\n x = (1.0*t+v2-v1)/2\n if x < 0 or x > t\n puts \"IMPOSSIBLE\"\n exit\n end\n x = x.round\n ans = [ans,v1+x-1,v2+t-x].max\n pre = tmp\nend\nans = [ans,pre[1]+n-pre[0]].max\nputs ans\n"}], "negative_code": [{"source_code": "n, m = gets.strip.split(\" \").map(&:to_i)\nrecord = Array.new\nm.times do |i|\n d, h = gets.strip.split(\" \").map(&:to_i)\n record.push [d, h]\nend\npossible = true\nmaxh = 0\n(m-1).times do |i|\n dd = record[i+1][0] - record[i][0]\n dh = record[i+1][1] - record[i][1]\n if dh.abs > dd\n possible = false\n end\n hh = (dd - dh.abs) / 2\n maxh = [maxh, record[i+1][1] + hh, record[i][1] + hh].max\nend\n\nc1 = record[0][0] + record[0][1]\nc2 = (n - record[-1][0]) + record[-1][1]\nmaxh = [c1, c2, maxh].max\n\nif possible\n puts maxh\nelse\n puts \"IMPOSSIBLE\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# c.rb\n\ndef main()\n n, m = gets.chomp.split(\" \").map{|s| next s.to_i }\n d = [0] * m\n h = [0] * m\n\n m.times do |i|\n d[i], h[i] = gets.chomp.split(\" \").map{|s| next s.to_i }\n end\n\n r = h[0]\n 1.upto(m-1) do |i|\n dd = d[i] - d[i-1]\n dh = h[i] - h[i-1]\n if dd.abs < dh.abs then\n puts(\"IMPOSSIBLE\")\n return\n else\n r = [r, h[i]].max\n r = [r, [h[i], h[i-1]].min + (dd.abs + dh.abs) / 2 ].max\n end\n end\n puts r\nend\n\nif __FILE__ == $0 then\n main()\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# c.rb\n\ndef main()\n n, m = gets.chomp.split(\" \").map{|s| next s.to_i }\n d = [0] * m\n h = [0] * m\n\n m.times do |i|\n d[i], h[i] = gets.chomp.split(\" \").map{|s| next s.to_i }\n end\n\n r = h[0] + d[0]\n 1.upto(m-1) do |i|\n dd = d[i] - d[i-1]\n dh = h[i] - h[i-1]\n if dd.abs < dh.abs then\n puts(\"IMPOSSIBLE\")\n return\n else\n r = [r, h[i]].max\n r = [r, [h[i], h[i-1]].min + (dd.abs + dh.abs) / 2 ].max\n end\n end\n puts r\nend\n\nif __FILE__ == $0 then\n main()\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# c.rb\n\ndef main()\n n, m = gets.chomp.split(\" \").map{|s| next s.to_i }\n d = [0] * (m + 1)\n h = [0] * (m + 1)\n\n m.times do |i|\n d[i+1], h[i+1] = gets.chomp.split(\" \").map{|s| next s.to_i }\n end\n\n r = 0\n 1.upto(m) do |i|\n dd = d[i] - d[i-1]\n dh = h[i] - h[i-1]\n if dd.abs < dh.abs then\n puts(\"IMPOSSIBLE\")\n return\n else\n r = [r, h[i]].max\n r = [r, [h[i], h[i-1]].min + (dd.abs + dh.abs) / 2 ].max\n end\n end\n puts r\nend\n\nif __FILE__ == $0 then\n main()\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# c.rb\n\ndef main()\n n, m = gets.chomp.split(\" \").map{|s| next s.to_i }\n d = [0] * m\n h = [0] * m\n\n m.times do |i|\n d[i], h[i] = gets.chomp.split(\" \").map{|s| next s.to_i }\n end\n\n r = 0\n 1.upto(m-1) do |i|\n dd = d[i] - d[i-1]\n dh = h[i] - h[i-1]\n if dd.abs < dh.abs then\n puts(\"IMPOSSIBLE\")\n return\n else\n r = [r, h[i]].max\n r = [r, [h[i], h[i-1]].min + (dd.abs + dh.abs) / 2 ].max\n end\n end\n puts r\nend\n\nif __FILE__ == $0 then\n main()\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# c.rb\n\ndef main()\n n, m = gets.chomp.split(\" \").map{|s| next s.to_i }\n d = [0] * m\n h = [0] * m\n\n m.times do |i|\n d[i], h[i] = gets.chomp.split(\" \").map{|s| next s.to_i }\n end\n\n r = h[0]\n 1.upto(m-1) do |i|\n dd = d[i] - d[i-1]\n dh = h[i] - h[i-1]\n if dd.abs < dh.abs then\n puts(\"IMPOSSIBLE\")\n return\n else\n r = [r, h[i]].max\n r = [r, [h[i], h[i-1]].min + (dd.abs + dh.abs) / 2 ].max\n end\n end\n r = [r, h[-1] + (n - d[-1])].max\n puts r\nend\n\nif __FILE__ == $0 then\n main()\nend\n"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\npre = gets.split.collect{|i| i.to_i}\nans = pre[1]+pre[0]-1\n(1...m).each do\n tmp = gets.split.collect{|i| i.to_i}\n t = tmp[0]-pre[0]\n v1, v2 = [pre[1], tmp[1]].minmax\n x = (1.0*t+v2-v1)/2\n if x < 0 or x > t\n puts \"IMPOSSIBLE\"\n exit\n end\n if x%1 >= 0.5\n x = x.ceil\n else\n x = x.floor\n end\n ans = [ans,v1+x-1,tmp[1]].max\n pre = tmp\nend\nans = pre[1]+n-pre[0] if ans < pre[1]+n-pre[0]\nputs ans\n"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\npre = gets.split.collect{|i| i.to_i}\nans = pre[1]+pre[0]-1\n(1...m).each do\n tmp = gets.split.collect{|i| i.to_i}\n t = tmp[0]-pre[0]\n v1, v2 = [pre[1], tmp[1]].minmax\n x = (1.0*t+v2-v1)/2\n if x < 0 or x > t\n puts \"IMPOSSIBLE\"\n exit\n end\n if x%1 >= 0.5\n x = x.ceil\n else\n x = x.floor\n end\n ans = [v1+x-1,tmp[1]].max\n pre = tmp\nend\nans = pre[1]+n-pre[0] if ans < pre[1]+n-pre[0]\nputs ans\n"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\npre = gets.split.collect{|i| i.to_i}\nans = pre[1]+pre[0]-1\n(1...m).each do\n tmp = gets.split.collect{|i| i.to_i}\n t = tmp[0]-pre[0]-1\n v1, v2 = [pre[1], tmp[1]].minmax\n x = (1.0*t+v2-v1)/2\n if x < 0 or x > t\n puts \"IMPOSSIBLE\"\n exit\n end\n if x%1 >= 0.5\n x = x.ceil\n else\n x = x.floor\n end\n ans = v1+x if ans < v1+x\n pre = tmp\nend\nans = pre[1]+n-pre[0] if ans < pre[1]+n-pre[0]\nputs ans\n"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\npre = gets.split.collect{|i| i.to_i}\nans = pre[1]+pre[0]-1\n(1...m).each do\n tmp = gets.split.collect{|i| i.to_i}\n t = tmp[0]-pre[0]\n v1, v2 = [pre[1], tmp[1]].minmax\n x = (1.0*t+v2-v1)/2\n if x < 0 or x > t\n puts \"IMPOSSIBLE\"\n exit\n end\n if x%1 >= 0.5\n x = x.ceil\n else\n x = x.floor\n end\n ans = v1+x-1 if ans < v1+x-1\n pre = tmp\nend\nans = pre[1]+n-pre[0] if ans < pre[1]+n-pre[0]\nputs ans\n"}], "src_uid": "77b5bed410d621fb56c2eaebccff5108"} {"source_code": "t = gets.to_i\nfor j in 1..t do\n\tn, k = gets.split.map(&:to_i)\n\ttmp = 1; res = 0\n\tfor i in 0..31 do\n\t\tif (k&(1< eps)\n res = car.res\n end\nend\n\nputs res\n"}, {"source_code": "a,b=gets.split.map(&:to_i)\nn=gets.to_i\ntime=10000000\nn.times do\n xi,yi,vi=gets.split.map(&:to_i)\n x=(xi-a).abs\n y=(yi-b).abs\n t=Math.sqrt(x**2+y**2)/vi\n if(tt then\n\t\tans=t\n\tend\n}\nputs ans\n\n"}, {"source_code": "ab = gets.chomp.split.map(&:to_i)\nn = gets.chomp.to_i\narr = []\nd = []\nfor i in (0..n-1)\n\tarr << gets.chomp.split.map(&:to_i)\n\td << Math.sqrt((arr[i][0] - ab[0])**2 + (arr[i][1] - ab[1])**2)/arr[i][2]\nend\n\nprint d.min"}, {"source_code": "a,b=gets.split.map(&:to_f)\np gets.to_i.times.map{\nx,y,z=gets.split.map(&:to_f)\n\tMath.hypot(a-x,b-y)/z\n}.min"}, {"source_code": "a,b = gets.split.map &:to_f\nn = gets.to_i\nputs (1..n).map{|_|\n x,y,v=gets.split.map &:to_f\n Math.sqrt((x-a)**2+(y-b)**2)/v\n}.min\n"}, {"source_code": "def dist x1, x2, y1, y2\n\t((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5\nend\n\ncharX, charY = gets.chomp.split(' ').map(&:to_i)\n\ntaxiNum = gets.chomp.to_i\ndistArr = []\n\ntaxiNum.times do\n\ttaxiX, taxiY, velocity = gets.chomp.split(' ').map(&:to_i)\n\tvalue = dist charX, taxiX, charY, taxiY\n\tdistArr << value / velocity\nend\n\nputs distArr.min"}], "negative_code": [{"source_code": "a,b=gets.split.map(&:to_f)\np gets.to_i.times.map{\nx,y,z=gets.split.map(&:to_f)\n((a-x).abs+(b-y).abs)/z\n}.min"}, {"source_code": "x, y = gets.chomp.split.map(&:to_f)\nn = gets.chomp.to_i\n\narr = []\nn.times do\n x2, y2, v = gets.chomp.split.map(&:to_f)\n arr << ((x2 - x).abs + (y2 - y).abs) / v\nend\nputs arr.min\n"}], "src_uid": "a74c65acd41ff9bb845062222135c60a"} {"source_code": "n, m = gets.split.map(&:to_i)\nans = []\nlrs = []\nn.times do\n l, r = gets.split.map(&:to_i)\n lrs << (l..r).to_a\nend\n\n(1..m).each do |i|\n inclusive = false\n lrs.each do |lr|\n if lr.to_a.include?(i)\n inclusive = true\n end\n end\n ans << i unless inclusive\nend\nputs ans.size\nputs ans.join(\" \")", "positive_code": [{"source_code": "a,b=gets.split.map &:to_i\nr=[*1..b]\na.times{x,y=gets.split.map &:to_i;r-=[*x..y]}\np r.size\nputs r*' '"}, {"source_code": "N, M = gets.chomp.split(/ /)\nrange = *(1..M.to_i)\n\nN.to_i.times do |i|\n u, l = gets.chomp.split(/ /)\n\n (u.to_i..l.to_i).each do |i|\n if range.include? i \n range.delete(i) \n end \n end \nend\n\np range.length\n\nif range.length > 0\n range.each{|i| print \"#{i} \"}\nend"}, {"source_code": "\ndef solution\n n, m = read_ints\n\n starts = Hash.new { |h, k| h[k] = 0 }\n ends = Hash.new { |h, k| h[k] = 0 }\n\n n.times do\n l, r = read_ints\n starts[l] += 1\n ends[r] += 1\n end\n\n crt = 0\n\n alone = []\n\n 1.upto(m) do |i|\n crt += starts[i]\n alone << i if crt == 0\n crt -= ends[i]\n end\n\n puts alone.size\n puts alone.join(' ')\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"}, {"source_code": "N, M = gets.split.map(&:to_i)\nimos = Array.new(M+2, 0)\nN.times do\n l, r = gets.split.map(&:to_i)\n imos[l] += 1\n imos[r+1] -= 1\nend\n(1..M).each do |i|\n imos[i] += imos[i-1]\nend\nans = (1..M).select{|i|imos[i] == 0}\nputs ans.length\nputs ans.join(' ') if ans.length > 0"}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\n\nary = Array.new(m+1, 0)\nn.times do\n l, r = gets.strip.split.map(&:to_i)\n l.upto(r).each {|i| ary[i]=1}\nend\n\nans=[]\n1.upto(m).each {|i| ans << i if ary[i]==0 }\n\nputs ans.size\nputs ans.join(\" \")"}, {"source_code": "def solution(m, segments)\n o = {}\n c = {}\n\n segments.each do |segment|\n o[segment[0]] = o.fetch(segment[0], 0) + 1\n c[segment[1]] = c.fetch(segment[1], 0) + 1\n end\n\n s = []\n x = 0\n (1..m).each do |i|\n x += o.fetch(i, 0)\n s << i if x == 0\n x -= c.fetch(i, 0)\n end\n return s\nend\n\nn, m = gets.chomp.split(\" \").map(&:to_i)\nsegments = []\nn.times { segments << gets.chomp.split(\" \").map(&:to_i) }\n\ns = solution(m, segments)\n\nputs s.length\nputs s.join(\" \")\n"}, {"source_code": "n, m = gets.split.map{|x| x.to_i}\nsegs = []\nn.times{segs << gets.split.map{|x| x.to_i}}\npoints = []\n(1..m).each do \n |x| points << x if segs.inject(true) do |s, y|\n s &&= !x.between?(y[0], y[1])\n end\nend\nputs(points.size, points.join(' '))\n"}, {"source_code": "n, m = gets.split.map{|x| x.to_i}\nsegs = []\nn.times{segs << gets.split.map{|x| x.to_i}}\npoints = []\n(1..m).each do |x|\n points << x if segs.inject(true) do |s, y|\n s &&= !x.between?(y[0], y[1])\n end\nend\nputs(points.size, points.join(' '))\n"}], "negative_code": [{"source_code": "N, M = gets.chomp.split(/ /)\nrange = *(1..5)\nam = 0\n\nN.to_i.times do |i|\n u, l = gets.chomp.split(/ /)\n\n (u.to_i..l.to_i).each do |i|\n if range.include? i \n range.delete(i) \n end \n end \nend\n\nif range.length > 0\n p range.length\n p range\nend"}, {"source_code": "N, M = gets.chomp.split(/ /)\nrange = *(1..M.to_i)\nam = 0\n\nN.to_i.times do |i|\n u, l = gets.chomp.split(/ /)\n\n (u.to_i..l.to_i).each do |i|\n if range.include? i \n range.delete(i) \n end \n end \nend\n\nif range.length > 0\n p range.length\n range.each{|i| print \"#{i} \"}\nend"}], "src_uid": "f336b622fdaf5960032268641320bb53"} {"source_code": "\nn,m=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\ng=Array.new(n){Array.new(n,0)}\nm.times{\n p,q=gets.split.map(&:to_i)\n g[p-1][q-1]=g[q-1][p-1]=1\n}\nans=9999999999\n0.upto(n-1){|i|\n (i+1).upto(n-1){|j|\n if g[i][j]==0 then\n next\n end\n (j+1).upto(n-1){|k|\n if g[i][k]==0 || g[j][k]==0 then\n next\n end\n ans=[ans,a[i]+a[j]+a[k]].min\n }\n }\n}\nputs (ans>=999999999)?-1:ans\n", "positive_code": [{"source_code": "n, m = gets.split(\"\\s\").map(&:to_i)\ncost = gets.split(\"\\s\").map(&:to_i)\narr = Array.new(111) { Array.new }\nm.times do\n\tu, v = gets.split(\"\\s\").map(&:to_i)\n\tarr[u] << v\n\tarr[v] << u\nend\n\nres = 1e10\nfor i in 1..n\n\tfor j in (i+1)..n\n\t\tfor k in (j+1)..n\n\t\t\tres = [res, cost[i-1]+cost[j-1]+cost[k-1]].min if arr[i].include?(j) && arr[j].include?(k) && arr[k].include?(i)\n\t\tend\n\tend\nend\n\nres = -1 if res == 1e10\nputs res\n"}, {"source_code": "sn, sm = gets.chop.split(/\\s+/)\n\ncount = sn.to_i\ncountRelation = sm.to_i\n\ncosts = Array.new(0)\nscosts = gets.chop.split(/\\s+/)\n(0..count-1).each { |i|\n costs[i] = scosts[i].to_i\n}\n\nrelations = Array.new()\n(0..count-1).each { |i|\n relations[i] = Array.new()\n (0..count-1).each { |j|\n relations[i][j] = false\n }\n}\n\n(0..countRelation-1).each { |i|\n su, sv = gets.chop.split(/\\s+/)\n u = su.to_i - 1;\n v = sv.to_i - 1;\n relations[u][v] = true\n relations[v][u] = true\n}\n\nsolves = Array.new(0)\n\n#(0..count-2).each { |row|\n## (row..count-2).each { |col|\n# if (relations[row][col] == true and relations[row][col+1] == true and relations[row+1][col+1] == true)\n# solves[solves.length] = costs[row] + costs[col] + costs[col+1]\n# end\n# }\n#}\n\n\n(0..count-1).each { |i|\n (0..count-1).each { |j|\n (0..count-1).each { |k|\n if (relations[i][j] == true and relations[j][k] == true and relations[i][k] == true)\n solves[solves.length] = costs[i] + costs[j] + costs[k]\n end\n }\n }\n}\n\n\nif (solves.length > 0)\n puts solves.min\nelse\n puts \"-1\"\nend"}], "negative_code": [{"source_code": "sn, sm = gets.chop.split(/\\s+/)\n\ncount = sn.to_i\ncountRelation = sm.to_i\n\ncosts = Array.new(0)\nscosts = gets.chop.split(/\\s+/)\n(0..count-1).each { |i|\n costs[i] = scosts[i].to_i\n}\n\nrelations = Array.new()\n(0..count-1).each { |i|\n relations[i] = Array.new()\n (0..count-1).each { |j|\n relations[i][j] = false\n }\n}\n\n(0..countRelation-1).each { |i|\n su, sv = gets.chop.split(/\\s+/)\n u = su.to_i - 1;\n v = sv.to_i - 1;\n relations[u][v] = true\n relations[v][u] = true\n}\n\nsolves = Array.new(0)\n\n(0..count-2).each { |row|\n (row..count-2).each { |col|\n if (relations[row][col] == true and relations[row][col+1] == true and relations[row+1][col+1] == true)\n solves[solves.length] = costs[row] + costs[col] + costs[col+1]\n end\n }\n}\n\nif (solves.length > 0)\n puts solves.min\nelse\n puts \"-1\"\nend"}], "src_uid": "d90da1e932a6aa546bec4e1bd4b1fbec"} {"source_code": "main = -> {\r\n times = []\r\n (0 ... 24).each do |h|\r\n h0 = h / 10\r\n h1 = h % 10\r\n (0 ... 60).each do |m|\r\n m0 = m / 10\r\n m1 = m % 10\r\n times << (h0 == m1 && h1 == m0)\r\n end\r\n end\r\n \r\n t = int\r\n t.times do\r\n c, _x = strings\r\n x = _x.to_i\r\n time = c[0, 2].to_i * 60 + c[3, 2].to_i\r\n visited = [false] * (24 * 60)\r\n count = 0\r\n until visited[time]\r\n visited[time] = true\r\n count += 1 if times[time]\r\n time = (time + x) % (24 * 60)\r\n end\r\n puts count\r\n end\r\n}\r\n\r\nDEBUG = false\r\nMOD = 10**9+7\r\nINF = 10**18\r\n$yesno = %w(No Yes)\r\n$YesNo = %w(No Yes)\r\n$YESNO = %w(NO YES)\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t ? 1 : 0] end\r\ndef YesNo t; puts $YesNo[t ? 1 : 0] end\r\ndef YESNO t; puts $YESNO[t ? 1 : 0] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]", "positive_code": [{"source_code": "def solve(time, period)\n period = period.to_i\n h, m = time.split(\":\").map(&:to_i)\n a = h * 60 + m\n\n hash = Hash.new(false)\n\n result = 0\n\n while !hash[a]\n result += 1 if palindrome?(a)\n hash[a] = true\n a = (a + period) % 1440\n end\n\n result\nend\n\ndef palindrome?(n)\n a = n / 60\n b = n - 60 * a\n\n a = a.to_s\n while a.size < 2\n a = \"0\" + a\n end\n\n b = b.to_s\n while b.size < 2\n b = \"0\" + b\n end\n\n s = [a, b].join\n\n s.reverse == s\nend\n\n\nn = gets.to_i\n\nn.times do\n time, period = gets.split\n\n p solve(time, period)\nend\n"}, {"source_code": "$cnt = []\r\n\r\ndef solve\r\n s = gets.split('')\r\n hh = []\r\n mm = []\r\n hh.append(s[0])\r\n hh.append(s[1])\r\n mm.append(s[3])\r\n mm.append(s[4])\r\n h = 0\r\n m = 0\r\n k = 0\r\n i = 6\r\n hh.each do |x|\r\n h = h * 10\r\n dig = x.to_i\r\n h = h + dig\r\n end\r\n mm.each do |x|\r\n m = m * 10\r\n dig = x.to_i\r\n m = m + dig\r\n end\r\n while i < s.length - 1\r\n k = k * 10\r\n dig = s[i].to_i\r\n k = k + dig\r\n i = i + 1\r\n end\r\n guy = (h * 100) + m\r\n ans = 0\r\n while $cnt[guy] == 0\r\n $cnt[guy] = 1\r\n s = []\r\n if h < 10\r\n s.append(0)\r\n s.append(h)\r\n else \r\n s.append(h / 10)\r\n s.append(h % 10)\r\n end\r\n if m < 10\r\n s.append(0)\r\n s.append(m)\r\n else \r\n s.append(m / 10)\r\n s.append(m % 10)\r\n end\r\n if s[0] == s[3] and s[1] == s[2]\r\n ans = ans + 1\r\n end\r\n m = m + k\r\n h = h + (m / 60)\r\n h = h % 24\r\n m = m % 60\r\n guy = (h * 100) + m\r\n end\r\n puts ans\r\n while $cnt[guy] != 0\r\n $cnt[guy] = 0\r\n m = m + k\r\n h = h + (m / 60)\r\n h = h % 24\r\n m = m % 60\r\n guy = (h * 100) + m\r\n end\r\nend\r\n\r\nmaxn = 100005\r\nmaxn.times do\r\n $cnt.append(0)\r\nend\r\ngets.to_i.times do\r\n solve\r\nend"}, {"source_code": "gets.to_i.times do\r\n t, n = gets.chomp.split(\" \")\r\n n = n.to_i\r\n h = n / 60\r\n m = n % 60\r\n hash = {}\r\n ans = 0\r\n i = 0\r\n while hash[t].nil?\r\n hash[t] = i\r\n ans += 1 if t == t.reverse\r\n s1 = (t[0,2].to_i + h) % 24\r\n s2 = (t[3,2].to_i + m)\r\n if s2 >= 60\r\n s1 += 1\r\n s1 %= 24\r\n s2 %= 60\r\n end\r\n if s1 / 10 == 0\r\n s1 = '0' + s1.to_s\r\n else\r\n s1 = s1.to_s\r\n end\r\n if s2 / 10 == 0\r\n s2 = '0' + s2.to_s\r\n else\r\n s2 = s2.to_s\r\n end\r\n t[0,2] = s1\r\n t[3,2] = s2\r\n i += 1\r\n end\r\n puts ans\r\nend\r\n"}, {"source_code": "gets.to_i.times do\n ans = 0\n a, b = gets.chomp.split\n h, m = a.split(':').map(&:to_i)\n hh = h\n mm = m\n b = b.to_i\n\n loop do\n g = ''\n g += '0' if h < 10\n g += h.to_s\n g += '0' if m < 10\n g += m.to_s\n ans += 1 if g == g.reverse\n\n h = (h + (m + b) / 60) % 24\n m = (m + b) % 60\n\n break if h == hh && m == mm\n end\n puts ans\nend\n"}, {"source_code": "require \"set\"\r\npalindromes = Set.new\r\n\r\n0.upto(23).each do |h|\r\n 0.upto(59).each do |m|\r\n time = \"%02d:%02d\" % [h, m]\r\n if time == time.reverse\r\n palindromes << h * 60 + m\r\n end\r\n end\r\nend\r\n\r\ngets.to_i.times do\r\n s, x = gets.split\r\n h, m = s.split(\":\").map(&:to_i)\r\n x = x.to_i\r\n start = h * 60 + m\r\n now = start\r\n count = 0\r\n loop do\r\n count += 1 if palindromes.include?(now)\r\n now += x\r\n now %= 1440\r\n break if now == start\r\n end\r\n p count\r\nend\r\n"}], "negative_code": [], "src_uid": "c601769062070ab983e1d4c9942cdd39"} {"source_code": "gets\na = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}\ni = a.index [a.transpose[0].min, a.transpose[1].max]\nputs i.nil? ? -1 : i+1\n", "positive_code": [{"source_code": "# Link: http://codeforces.com/problemset/problem/242/B\n# \u00dd t\u01b0\u1edfng:\n# M\u1ed7i segment s\u1ebd l\u00e0 1 array [l, r], l\u01b0u h\u1ebft segments v\u00e0o 1 array.\n# \u0110\u1ea7u ti\u00ean ta g\u1eafn min_l, max_r l\u1ea7n l\u01b0\u1ee3t l\u00e0 l v\u00e0 r c\u1ee7a segments \u0111\u1ea7u ti\u00ean.\n# L\u1eb7p t\u1eeb ph\u1ea7n t\u1eed th\u1ee9 2 t\u1edbi cu\u1ed1i m\u1ea3ng segments \u0111\u1ec3 t\u00ecm ra min_l v\u00e0 max_r.\n# Ti\u1ebfp t\u1ee5c l\u1eb7p l\u1ea7n n\u1eefa t\u1eeb \u0111\u1ea7u t\u1edbi cu\u1ed1i m\u1ea3ng, ki\u1ec3m tra xem trong m\u1ea3ng c\u00f3 ph\u1ea7n t\u1eed n\u00e0o c\u00f3 l, r\n# b\u1eb1ng v\u1edbi min_l v\u00e0 max_r v\u1eeba t\u00ecm \u0111\u01b0\u1ee3c kh\u00f4ng.\n# N\u1ebfu c\u00f3 t\u1ed3n t\u1ea1i ta ngay l\u1eadp t\u1ee9c tr\u1ea3 v\u1ec1 index c\u1ee7a ph\u1ea7n t\u1eed \u0111\u00f3 + th\u00eam 1 (v\u00ec th\u1ee9 t\u1ef1 c\u1ee7a segment trong input b\u1eaft \u0111\u1ea7u t\u1eeb 1).\n# N\u1ebfu kh\u00f4ng t\u00ecm ra ph\u1ea7n t\u1eed n\u00e0o th\u00ec tr\u1ea3 v\u1ec1 -1\n\nnum_of_segments = gets.chomp.to_i\nsegments_description = []\n\n# save descriptions of the segments ([left, right]) into an array\nfor i in 0..(num_of_segments - 1)\n segment = gets.chomp.split.map(&:to_i)\n segments_description << segment\nend\n\ndef index_of_segment_container(segments)\n min_l, max_r = segments[0][0], segments[0][1]\n\n for i in 1..(segments.length - 1)\n min_l = segments[i][0] if segments[i][0] < min_l\n max_r = segments[i][1] if segments[i][1] > max_r\n end\n\n for i in 0..(segments.length - 1)\n return i + 1 if segments[i][0] == min_l && segments[i][1] == max_r\n end\n\n return -1\nend\n\nputs index_of_segment_container(segments_description)"}, {"source_code": "num_of_segments = gets.chomp.to_i\nsegments_description = []\n\n# save descriptions of the segments ([left, right]) into an array\nfor i in 0..(num_of_segments - 1)\n segment = gets.chomp.split.map(&:to_i)\n segments_description << segment\nend\n\ndef index_of_segment_container(segments)\n min_l = segments[0][0]\n max_l = segments[0][1]\n\n for i in 1..(segments.length - 1)\n min_l = segments[i][0] if segments[i][0] < min_l\n max_l = segments[i][1] if segments[i][1] > max_l\n end\n\n for i in 0..(segments.length - 1)\n return i + 1 if segments[i][0] == min_l && segments[i][1] == max_l\n end\n\n return -1\nend\n\nputs index_of_segment_container(segments_description)\n"}, {"source_code": "def check(number)\n segments = []\n (1..number.to_i).each do |i|\n segments << gets.split().map(&:to_i)\n end\n\n step_1 = 0\n step_2 = 0\n\n for i in (0..segments.size - 1)\n next unless segments[i + 1]\n if (segments[step_1][0] >= segments[i + 1][0]) && (segments[step_2][1] <= segments[i + 1][1])\n step_1 = i + 1\n step_2 = i + 1\n elsif segments[step_2][1] < segments[i + 1][1]\n step_2 = i + 1\n elsif segments[step_1][0] > segments[i + 1][0]\n step_1 = i + 1\n end\n end\n \n puts (step_1 == step_2) ? step_1 + 1 : -1\nend\n\ncheck(gets)\n"}, {"source_code": "gets\na = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}\ni = a.index [a.transpose[0].min, a.transpose[1].max]\nputs i.nil? ? -1 : i+1\n"}, {"source_code": "gets\na = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}\ni = a.index [a.transpose[0].min, a.transpose[1].max]\nputs i.nil? ? -1 : i+1\n"}, {"source_code": "a=Array.new{|el| el=Array.new}\ngets.to_i.times{a< nextSeg[0] || seg[1] < nextSeg[1]\n}\nputs (min < seg[0] || max > seg[1]) ? \"-1\" : curr.to_s"}, {"source_code": "a=Array.new{|el| el=Array.new}\ngets.to_i.times{a< max\n\n array << [left, right]\nend\n\nresult = -1\narray.each_with_index do |row, index|\n if row[0] <= min and row[1] >= max\n result = index + 1\n break\n end\nend\n\nputs result\n"}, {"source_code": "n = gets.to_i\nmin = 1000000001\nmax = 0\nseg = -1\nx, y = [0, 0]\nfor i in 1..n\n l, r = gets.split.map(&:to_i)\n if l <= min && r >= max\n seg = i\n\tx = l\n\ty = r\n elsif l < x || r > y\n seg = -1\n end\n min = [l, min].min\n max = [r, max].max\nend\nprint seg"}, {"source_code": "gets\na = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}\ni = a.index [a.transpose[0].min, a.transpose[1].max]\nputs i.nil? ? -1 : i+1\n"}, {"source_code": "gets\na = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}\ni = a.index [a.transpose[0].min, a.transpose[1].max]\nputs i.nil? ? -1 : i+1"}, {"source_code": "gets\na = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}\ni = a.index [a.transpose[0].min, a.transpose[1].max]\nputs i.nil? ? -1 : i+1"}, {"source_code": "n = gets.to_i\nar = []\nn.times{ar< max_right || max_right < 0\nend\n\ncheck_result = [min_left, max_right]\n\nresult = (segments.find_index(check_result) || -2) + 1\n\nputs result\n"}, {"source_code": "segment_number = gets.to_i\n\nsegments = []\n\nfor i in (0..segment_number - 1)\n segment = gets.split(' ')\n left_coordinate = segment[0].to_i\n right_coordinate = segment[1].to_i\n segments << [left_coordinate, right_coordinate]\nend\n\nmin_left = -1\nmax_right = -1\n\nsegments.each do |segment|\n min_left = segment[0] if segment[0] < min_left || min_left < 0\n max_right = segment[1] if segment[1] > max_right || max_right < 0\nend\n\ncheck_result = [min_left, max_right]\n\nresult = (segments.index { |segment| segment[0] == check_result[0] && segment[1] == check_result[1] } || -2) + 1\n\nputs result\n"}, {"source_code": "segment_number = gets.to_i\n\nsegments = []\n\nfor i in (0..segment_number - 1)\n segment = gets.split(' ')\n left_coordinate = segment[0].to_i\n right_coordinate = segment[1].to_i\n segments << [left_coordinate, right_coordinate]\nend\n\nmin_left = segments.map(&:first).min\nmax_right = segments.map(&:last).max\n\ncheck_result = [min_left, max_right]\n\nresult = (segments.find_index(check_result) || -2) + 1\n\nputs result\n"}, {"source_code": "gets\na = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}\ni = a.index [a.transpose[0].min, a.transpose[1].max]\nputs i.nil? ? -1 : i+1\n"}, {"source_code": "gets\na = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}\ni = a.index [a.transpose[0].min, a.transpose[1].max]\nputs i.nil? ? -1 : i+1\n"}, {"source_code": "require 'set'\n\ndef read_next_line\n gets.split.map { |x| x.to_i }\nend\n\nmin, max = 10 ** 9 + 1, 0\nmins, maxs = Set.new, Set.new\nfor i in 1..gets.to_i\n a, b = read_next_line\n if a < min\n min = a\n mins.clear\n mins << i\n elsif a == min\n mins << i\n end\n if b > max\n max = b\n maxs.clear\n maxs << i\n elsif b == max\n maxs << i\n end\nend\nr = mins & maxs\nputs(r.empty? ? -1 : r.first)"}, {"source_code": "gets\na = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}\ni = a.index [a.transpose[0].min, a.transpose[1].max]\nputs i.nil? ? -1 : i+1\n"}], "negative_code": [{"source_code": "def check(number)\n segments = []\n (1..number.to_i).each do |i|\n segments << gets.split().map(&:to_i)\n end\n\n step = 1\n current_1 = segments[0].min\n current_2 = segments[0].max\n for i in (1..segments.size - 1)\n break if segments[i + 1].nil?\n if (segments[i].min <= current_1 ) && (segments[i].max >= current_2)\n current_1 = segments[i].min\n current_2 = segments[i].max\n step = i + 1\n else\n step = -1\n end\n end\n puts step\nend\n\ncheck(gets)\n"}, {"source_code": "def check(number)\n segments = []\n (1..number.to_i).each do |i|\n segments << gets.split().map(&:to_i)\n end\n\n step = 1\n current_1 = segments[0].min\n current_2 = segments[0].max\n for i in (1..segments.size - 1)\n break if segments[i + 1].nil?\n if (segments[i].min <= current_1 ) && (segments[i].max >= current_2)\n current_1 = segments[i].min\n current_2 = segments[i].max\n step = i + 1\n elsif (segments[i].min > current_1 ) && (segments[i].max > current_2)\n step = -1\n end\n end\n puts step\nend\n\ncheck(gets)\n"}, {"source_code": "def check(number)\n segments = []\n (1..number.to_i).each do |i|\n segments << gets.split().map(&:to_i)\n end\n\n step = -1\n current_1 = segments[0].min\n current_2 = segments[0].max\n for i in (1..segments.size - 1)\n break if segments[i + 1].nil?\n if (segments[i].min <= current_1 ) && (segments[i].max >= current_2)\n current_1 = segments[i].min\n current_2 = segments[i].max\n step = i + 1\n end\n end\n puts step\nend\n\ncheck(gets)\n"}, {"source_code": "def check(number)\n segments = []\n (1..number.to_i).each do |i|\n segments << gets.split().map(&:to_i)\n end\n\n step_1 = 0\n step_2 = 0\n\n for i in (0..segments.size - 1)\n next unless segments[i + 1]\n if (segments[step_1][0] >= segments[i + 1][0]) && (segments[step_2][1] < segments[i + 1][1])\n step_1 = i + 1\n step_2 = i + 1\n elsif segments[step_2][1] < segments[i + 1][1]\n step_2 = i + 1\n elsif segments[step_1][0] > segments[i + 1][0]\n step_1 = i + 1\n end\n end\n \n puts (step_1 == step_2) ? step_1 + 1 : -1\nend\n\ncheck(gets)\n"}, {"source_code": "n = gets.to_i\nmin = 1000000001\nmax = 0\nseg = -1\nx, y = [0, 0]\nfor i in 1..n\n l, r = gets.split.map(&:to_i)\n if l <= min && r >= max\n seg = i\n\tx = l\n\ty = r\n elsif l < x && r > y\n seg = -1\n end\n min = [l, min].min\n max = [r, max].max\nend\nprint seg"}, {"source_code": "#CF Round 149. Div II Prob. B - Big Segment\nn = gets.chomp.to_i\nseg, curr, min, max = gets.chomp.split(/ /).map(&:to_i), 1, 1000000000, 0;\n(2..n).each {|i|\n nextSeg = gets.chomp.split(/ /).map(&:to_i)\n min, max = [min, nextSeg[0]].min, [max, nextSeg[1]].max\n seg, curr = nextSeg, i if seg[0]> nextSeg[0] || seg[1] < nextSeg[1]\n}\nputs (min < seg[0] || max > seg[1]) ? \"-1\" : curr.to_s"}], "src_uid": "e702594a8e993e135ea8ca78eb3ecd66"} {"source_code": "gets;s=[];z=[];a=gets.split.map &:to_i;a<<0;0.upto(a.size-1){|i|(a[i-1]-a[i]).times{z<<[s.pop,i]};(a[i]-a[i-1]).times{s< num do\n\t\tr<< idx\n\t\tcurr -= 1\n\tend\nend\n\nputs l.length\nl.length.times do |idx|\n\tputs \"#{l[idx]} #{r[idx]}\"\nend\n"}, {"source_code": "gets;s=[];z=[];a=gets.split.map &:to_i;a<<0;0.upto(a.size-1){|i|(a[i-1]-a[i]).times{z<<[s.pop,i]};(a[i]-a[i-1]).times{s< n-2)\n\t\treturn false\n\telsif ( board[(y+1)*(n+1)+x] != \"#\" or\n\t\t board[(y+2)*(n+1)+x] != \"#\" or\n\t\t board[(y+1)*(n+1)+(x-1)] != \"#\" or\n\t\t board[(y+1)*(n+1)+(x+1)] != \"#\" )\n\t\treturn false\n\telse\n\t\treturn true\n\tend\nend\n\ndef check_board (board, n)\n\tfor y in 0..n\n\t\tfor x in 0..n\n\t\t\tif (board[y*(n+1)+x] == \"#\")\n\t\t\t\tif (cross?(board, x, y, n))\n\t\t\t\t\tboard[(y+1)*(n+1)+x] = \".\"\n\t\t\t\t\tboard[(y+2)*(n+1)+x] = \".\"\n\t\t\t\t\tboard[(y+1)*(n+1)+(x-1)] = \".\"\n\t\t\t\t\tboard[(y+1)*(n+1)+(x+1)] = \".\"\n\t\t\t\telse\n\t\t\t\t\treturn \"NO\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\treturn \"YES\"\nend\n\nboard = []\nn = (gets()).to_i - 1\nfor i in 0..n\n\t(gets()).each_char{ |c| board << c}\n\tboard.pop\nend\n\nputs check_board(board, n)"}], "negative_code": [{"source_code": "a=gets.chomp.to_i\nc=(\".\"*(a+4)).split(\"\")\nb=[]\nb< K)\n ans += (numbers[i] - 1 - last_present) / K\n end\n last_present = numbers[i]\nend\n\nans += C\nputs ans\n"}, {"source_code": "n,k,x,*h=(gets+gets).split.map &:to_i;h<= K\n p = 0\n ret += 1\n elsif h[i]\n ret += 1\n p = 0\n end\n p += 1\nend\nputs ret \n"}, {"source_code": "n,k,x,*h=(gets+gets).split.map &:to_i;h<=k then\n back=i\n ans+=1\n end\nend\np ans\n"}, {"source_code": "n,k,x,*h=(gets+gets).split.map &:to_i;h<=k then\n back=i\n ans+=1\n end\nend\np ans\n"}, {"source_code": "N, K = gets.split.map(&:to_i)\nt, *H = gets.split.map(&:to_i)\nh = Array.new(N, false)\nh[0] = true\nH.each { |i| h[i] = true }\nret = 0\np = 0\n(0...N).each do |i|\n if p >= K\n p = 0\n ret += 1\n elsif h[i]\n ret += 1\n p = 0\n end\n p += 1\nend\nputs ret \n"}], "src_uid": "07b750dbf7f942eab80d4260103c7472"} {"source_code": "n,m=gets.split.map &:to_i;puts((['#'*m,'.'*(m-1)+'#','#'*m,'#'+'.'*(m-1)]*n)[0...n])", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nf = 1\nfor i in 0...n\n\tif(i % 2 == 0)\n\t\tm.times do \n\t\t\tprint \"#\"\n\t\tend\n\telse\n\t\tif(f == 1)\n\t\t\t(m - 1).times do\n\t\t\t\tprint \".\"\n\t\t\tend\n\t\t\tprint \"#\"\n\t\t\tf = 0\n\t\telse\n\t\t\tprint \"#\"\n\t\t\t(m - 1).times do\n\t\t\t\tprint \".\"\n\t\t\tend\n\t\t\tf = 1\n\t\tend\n\tend\n\tputs \"\"\nend"}, {"source_code": "n,m = gets.split.map(&:to_i)\ntable = []\nn.times do\n\ttable.push(['.']*m)\nend\n\nfor i in 0...n\n\tif (i%2==0)\n\t\tfor j in 0...m\n\t\t\ttable[i][j] = '#'\n\t\tend\n\telse\n\t\tif (i/2)%2 == 0\n\t\t\ttable[i][-1] = '#'\n\t\telse\n\t\t\ttable[i][0] = '#'\n\t\tend\n\tend\nend\n\nfor i in 0...n\n\tfor j in 0...m\n\t\tprint table[i][j]\n\tend\n\tputs\nend"}, {"source_code": "n,m=gets.split.map &:to_i\nn.times{|i| puts i.even? ? '#'*m : ('.'*(m-1)).insert(-i/2%-2,'#')}"}, {"source_code": "def string_to_int(string, delim = \" \")\n result = []\n string = string.split(delim)\n for i in 0...string.length\n result[i] = string[i].to_i\n end\n return result\nend\n\ninput = string_to_int(gets.chomp)\nn = input[0]\nm = input[1]\n\nsnake = Array.new(n){Array.new(m){\".\"}}\nfor i in 0...snake.length\n\tfor j in 0...snake[0].length\n\t\tif (i+1)%4 == 0\n\t\t\tsnake[i][0] = \"#\"\n\t\t\tbreak\n\t\telsif (i+1)%2 == 0\n\t\t\tsnake[i][snake[0].length - 1] = \"#\"\n\t\t\tbreak\n\t\telse\n\t\t\tsnake[i][j] = \"#\"\n\t\tend\n\tend\nend\n\nfor i in 0...snake.length\n\tfor j in 0...snake[0].length\n\t\tif j != snake[0].length - 1\n\t\t\tprint snake[i][j]\n\t\telse\n\t\t\tputs snake[i][j]\n\t\tend\n\tend\nend\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\n\na = []\ncounter = 0\nfor i in 0..n-1\n a[i] = []\n for j in 0..m-1\n if i%2 == 0\n a[i][j] = \"#\"\n else\n a[i][j] = \".\"\n end\n end\n\n counter+=1 if i%2 != 0\n\n if counter%2 == 0\n a[i][0] = \"#\"\n else\n a[i][-1] = \"#\"\n end\nend\n\n\n\nfor i in 0..n-1\n for j in 0..m-1\n print \"#{a[i][j]}\"\n end\n puts\nend"}, {"source_code": "n, m = $stdin.readline.split.map(&:to_i)\n\nd = 0\nfor i in 1..n\n case d \n when 0,2\n m.times {print '#'}\n when 1\n (m-1).times {print '.'}\n print '#'\n when 3\n print '#'\n (m-1).times {print '.'}\n end\n puts ''\n d = (d+1)%4\nend"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn, m = gets.split.map(&:to_i)\nn.times {|i|\n if i % 2 == 0\n puts '#' * m\n elsif i % 4 == 1\n puts '.' * (m - 1) + '#'\n elsif\n puts '#' + '.' * (m - 1)\n end\n}"}, {"source_code": "n, m = gets.split.map(&:to_i)\nright_or_left = 0\nn.times do |i|\n x = if i % 2 == 0\n '#' * m\n elsif right_or_left % 2 == 0\n result = '.' * m\n result[-1] = '#'\n right_or_left += 1\n result\n else\n result = '.' * m\n result[0] = '#'\n right_or_left += 1\n result\n end\n puts x\nend\n"}, {"source_code": "n, m = gets.chomp.split.map &:to_i\nind = 'r'\nn.times do |x|\n if (x + 1) % 2 != 0\n m.times do\n print \"#\"\n end\n puts\n else \n if ind == 'r'\n (m - 1).times do\n print '.'\n end\n print '#'\n puts\n ind = 'l'\n else\n print '#'\n (m - 1).times do\n print '.'\n end\n puts\n ind = 'r'\n end\n end\nend\n"}, {"source_code": "n,m=gets.split.map &:to_i;puts((['#'*m,'.'*(m-1)+'#','#'*m,'#'+'.'*(m-1)]*n)[0...n])\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\n(1..n).each { |i|\n (1..m).each { |j|\n if i&1==1\n print '#'\n else\n if (i&3==2 && j==m) || (i&3==0 && j==1)\n print '#'\n else\n print '.'\n end\n end\n }\n print \"\\n\"\n}"}, {"source_code": "n, m = gets.split.map(&:to_i)\n\n(0..n-1).each do |i|\n line = \"\"\n (0..m-1).each do |j|\n if i.even? || (j == m - 1) && (i % 4 == 1) || (j == 0) && (i % 4 == 3)\n line += \"#\"\n else\n line += \".\"\n end\n end\n puts line\nend"}, {"source_code": "n,m=gets.split.map &:to_i;puts((['#'*m,'.'*(m-1)+'#','#'*m,'#'+'.'*(m-1)]*n)[0...n])\n"}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\nleft = true\nright = false\n(1..n).each do |row|\n line = nil\n if row.odd?\n line = Array.new(m, \"#\")\n else\n line = Array.new(m, \".\")\n if left && !right\n line[m - 1] = \"#\"\n left = false\n right = true\n elsif right && !left\n line[0] = \"#\"\n left = true\n right = false\n end\n end\n puts line.join\nend\n"}, {"source_code": "a=gets.chomp.split(\" \")\ntok=0\na[0]=a[0].to_i\na[1]=a[1].to_i\nhash=\"\"\na[1].times do\n hash=hash+\"#\"\nend\nto=\"\"\n(a[1]-1).times do\n to=to+\".\"\nend\nto=to+\"#\"\nfour=\"#\"\n(a[1]-1).times do\n four=four+\".\"\nend\n1.upto(a[0]) do |i|\nif (i%2==1)\n puts \"#{hash}\"\nelsif (i%2==0 and tok==0) \n puts \"#{to}\"\n tok=1\nelse \n puts \"#{four}\"\n tok=0\nend\nend"}, {"source_code": "n,m=gets.split.map &:to_i;puts((['#'*m,'.'*(m-1)+'#','#'*m,'#'+'.'*(m-1)]*n)[0...n])\n"}, {"source_code": "h,w=gets.chomp.split.map{|e| e.to_i}\n\nh.times{|i|\n\tif i%2==0 then\n\t\tputs (\"#\"*w)\n\telsif i%4==1 then\n\t\tputs ((\".\"*(w-1))+\"#\")\n\telse\n\t\tputs (\"#\"+(\".\"*(w-1)))\n\tend\n}\n\n"}, {"source_code": "n,m = gets.chomp.split.map(&:to_i)\nj = 0\nn.times.each do |i|\n if i % 2 ==0\n puts '#' * m\n else\n s = '.' * m\n if j % 2 == 0\n s[m-1] = '#'\n else\n s[0] = '#'\n end\n j += 1\n puts s\n end\nend"}, {"source_code": "n, m = gets.split.map { |e| e.to_i }\n\nfor i in 1..n do\n puts '#'.rjust(m, '#') if i.odd?\n puts '#'.rjust(m, '.') if i%4 != 0 and i.even?\n puts '#'.ljust(m, '.') if i%4 == 0\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\ninput = gets.chomp.split(' ').map! &:to_i\n\ndef filled(input)\n puts '#' * input.last\nend\n\ndef points_left(input)\n puts \"#{ '.' * (input.last - 1)}#\"\nend\n\ndef points_right(input)\n puts \"##{ '.' * (input.last - 1 )}\"\nend\n\nsign = -1\n\ninput.first.times do |i|\n if i % 2 == 0\n filled input\n elsif sign > 0\n sign *= -1\n points_right input\n else\n sign *= -1\n points_left input\n end\nend\n"}, {"source_code": "n,m=gets.split(\" \").map {|x| x.to_i}\ni = 1\nwhile i<=n do\n if i%4==0\n print \"#\"\n j = 2\n while j<=m do\n print \".\"\n j+=1\n end\n elsif i%4==2\n j=1\n while j 1 && space < cells\n\t\t\t\t\tprint \".\"\n\t\t\t\telse\n\t\t\t\t\tputs \".\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\nend"}, {"source_code": "n,m=gets.split.map &:to_i;puts((['#'*m,'.'*(m-1)+'#','#'*m,'#'+'.'*(m-1)]*n)[0...n])\n"}, {"source_code": "R,C=gets.split.map(&:to_i)\nR.times{|i|\n\tif i%4==1\n\t\tputs '.'*(C-1)+'#'\n\telsif i%4==3\n\t\tputs '#'+'.'*(C-1)\n\telse\n\t\tputs '#'*C\n\tend\n}"}, {"source_code": "n,m=gets.split.map &:to_i;puts((['#'*m,'.'*(m-1)+'#','#'*m,'#'+'.'*(m-1)]*n)[0...n])\n"}, {"source_code": "class Snake\n def initialize(n, m)\n @n, @m = n, m\n end\n\n def draw\n rows.each { |row| puts row.join }\n end\n\n private\n\n def rows\n [].tap do |rows|\n @n.times do |idx|\n case\n when idx.even?\n rows << ['#'] * @m\n when rows[idx - 2].nil?, rows[idx - 2].first == '#'\n rows << ['.'] * (@m - 1) + ['#']\n else\n rows << ['#'] + ['.'] * (@m - 1)\n end\n end\n end\n end\nend\n\nn, m = gets.chomp.split.map(&:to_i)\nsnake = Snake.new(n, m)\nsnake.draw\n"}, {"source_code": "n,m=gets.split.map &:to_i;puts((['#'*m,'.'*(m-1)+'#','#'*m,'#'+'.'*(m-1)]*n)[0...n])\n"}, {"source_code": "n, m = gets.split(\" \").map(&:to_i)\n\nn.times do |i|\n\t#puts i\n\tm.times do |j|\n\t\t#print \"#{j} \"\n\t\tif i%2==0 \n\t\t\tprint \"#\"\n\t\telsif i/2%2==0 && j==m-1\n\t\t\tprint \"#\" \n\t\telsif i/2%2==1 && j==0\n\t\t\tprint \"#\"\n\t\telse\n\t\t\tprint \".\"\n\t\tend\n\tend\n\tprint \"\\n\"\nend"}, {"source_code": "n,m=gets.split.map &:to_i;puts((['#'*m,'.'*(m-1)+'#','#'*m,'#'+'.'*(m-1)]*n)[0...n])"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\nflip = 0\nres = []\n(1..n).each do |i|\n if i % 2 != 0\n res << [\"#\"] * m\n else\n row = [\".\"] * (m - 1)\n if flip == 1\n row.unshift(\"#\")\n else\n row << \"#\"\n end\n res << row\n flip ^= 1\n end\nend\nres.each do |r|\n puts r.join\nend"}, {"source_code": "n,m=gets.split.map &:to_i\nn.times{|i| puts i.even? ? '#'*m : ('.'*(m-1)).insert(-i/2%-2,'#')}"}, {"source_code": "h, w = gets.split.map(&:to_i)\nputs (1..h).map { |i| (1..w).map { |j| i % 2 == 0 && i % 4 != 0 && j != w || i % 4 == 0 && j != 1 ? '.' : '#' }.join }\n"}, {"source_code": "$n,$m=STDIN.gets.split.map{|n|n.to_i}\n\ndef getLine(i)\n return \"#\"*$m if i%2==0\n return \".\"*($m-1)+\"#\" if i%4==1\n return \"#\"+\".\"*($m-1)\nend\n\nputs Array.new($n) {|i| getLine(i)+\"\\n\"}.inject(:+)"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = Array.new(n){Array.new(m, \".\")}\nfor i in 0...n\n if i % 2 == 0\n a[i] = Array.new(m, \"#\")\n elsif i % 4 == 1\n a[i][m - 1] = \"#\"\n elsif i % 4 == 3\n a[i][0] = \"#\"\n end\nend\nputs a.map{|x| x.join(\"\")}\n"}, {"source_code": "input = gets.chomp.split\nn = input[0].to_i\nm = input[1].to_i\n\narr = []\nfor i in 0..n-1\n arr[i] = Array.new(m)\n arr[i].fill('.')\nend\n\ni = 0\nwhile i < n do\n arr[i].fill('#')\n i += 2\nend\n\nright = true\ni = 1\nwhile i < n do\n if right\n arr[i][m-1] = '#'\n else\n arr[i][0] = '#'\n end\n right = !right\n i += 2\nend\n\narr.each do |row|\n puts row.join\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\n\ninput = ARGF.gets\n\nn, m = input.split \" \"\nn = n.to_i\nm = m.to_i\n\n\nright = true\n\nni = 0\nn.times do\n if ni.even?\n puts '#' * m\n else\n if right\n right = false\n print '.' * (m - 1)\n puts '#'\n else\n right = true\n print '#'\n puts '.' * (m-1)\n end\n\n end\n\n\n\n ni += 1 \n\nend\n"}, {"source_code": "a=gets.chomp.split(\" \")\ntok=0\na[0]=a[0].to_i\na[1]=a[1].to_i\nhash=\"\"\na[1].times do\n hash=hash+\"#\"\nend\nto=\"\"\n(a[1]-1).times do\n to=to+\".\"\nend\nto=to+\"#\"\nfour=\"#\"\n(a[1]-1).times do\n four=four+\".\"\nend\n1.upto(a[0]) do |i|\nif (i%2==1)\n puts \"#{hash}\"\nelsif (i%2==0 and tok==0) \n puts \"#{to}\"\n tok=1\nelse \n puts \"#{four}\"\n tok=0\nend\nend"}, {"source_code": "n,m=gets.split.map &:to_i;puts((['#'*m,'.'*(m-1)+'#','#'*m,'#'+'.'*(m-1)]*n)[0...n])\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\n\n1.upto(n) do |i|\n case i.modulo(4)\n when 1, 3\n puts '#'*m\n when 2\n puts \"#{'.'*(m-1)}\\#\"\n when 0\n puts \"\\##{'.'*(m-1)}\"\n end\nend\n"}, {"source_code": "n, m = gets.split(\" \").map &:to_i\n\nright = true\nn.times do |i|\n if i%2 == 0\n puts '#' * m\n else\n str = '.' * (m - 1)\n str.insert(right ? -1 : 0, '#' )\n right = !right\n puts str\n end\nend"}, {"source_code": "a=Array.new\nstr=gets.to_s\na=str.split\nn=a[0].to_i\nm=a[1].to_i\ni=h=0\nwhile i=n\n break\n end\n if h==0\n j=0\n while j= 1\n end\n \n puts ''\nend"}, {"source_code": "n, m = gets.chomp.split(' ').map { |i| i.to_i }\nn.times do |iter|\n if iter.even?\n m.times { print '#' }\n else\n print '#' if iter % 3 == 0\n (m - 1).times { print '.' }\n print '#' if iter % 3 == 1\n end\n \n puts ''\nend"}], "src_uid": "2a770c32d741b3440e7f78cd5670d54d"} {"source_code": "#!/usr/bin/ruby\nh=Hash.new(0)\nr=0\ngets\ngets.split.map(&:to_i).each{|e|h[e]+=1}\nh.each{|k,v|\n\tx=2\n\twhile x<=0x80000000\n\t\ty=x-k\n\t\tif k==y\n\t\t\tr+=v*(v-1)/2\n\t\telsif k= 1\n x[1] -= 1\n elsif x[0] == x[1] && x[1] < n - 1\n x[1] += 1\n end\n\n if y[0] == y[1] && y[1] >= 1\n y[1] -= 1\n elsif y[0] == y[1] && y[1] < n - 1\n y[1] += 1\n end\n\n a[x[0]][y[0]] = \"*\"\n a[x[0]][y[1]] = \"*\"\n a[x[1]][y[0]] = \"*\"\n a[x[1]][y[1]] = \"*\"\n\n a.each do |l|\n printf(\"%s\\n\", l.join(\"\"))\n end\n\nend\n"}], "negative_code": [], "src_uid": "d8fb3822b983b8a8ffab341aee74f56f"} {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n ans << (n+2)/2\nend\nans.each do |x|\n puts x\nend\n", "positive_code": [{"source_code": "gets.to_i.times{|s|puts (gets.to_i)/2+1}"}], "negative_code": [{"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n if n == 1\n ans << 1\n elsif n == 2 || n == 3\n ans << 2\n else\n ans << (n+3)/2\n end\nend\nans.each do |x|\n puts x\nend"}], "src_uid": "eb39ac8d703516c7f81f95a989791b21"} {"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 c(i, now)\n if(i==10)\n @anss << now\n return\n end\n c(i+1,now)\n c(i+1,now + @t3[i])\nend\n\n@t3 = []\n(0..9).each{|d| @t3 << 3**d}\n@anss = []\nc(0,0)\n@anss.sort!\nn = inp[0]\nn.times do\n q = inp[0]\n puts @anss.bsearch{|x| x >= q }\nend\n", "positive_code": [{"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\n\nt3 = []\n(0..44).each{|d|t3<<3**d}\n\nn = inp[0]\nn.times do\n q = inp[0]\n t = []\n while (q > 0)\n t << q % 3\n q /= 3\n end\n t.reverse!\n ind = -1\n t.size.times do |i|\n if(t[i] == 2)\n ind = i + 1\n break\n end\n end\n t.unshift(0)\n ans = 0\n\n (0...(t.size)).reverse_each do |i|\n break if ind < 0\n if(ind <= i)\n t[i] = 0\n end\n if(ind > i)\n if(t[i] == 0)\n t[i] = 1\n break\n else\n t[i] = 0\n end\n end\n end\n\n(0...(t.size)).each do |i|\n ans += t3[t.size-i-1] if(t[i] >= 1)\n end\n p ans\nend\n"}], "negative_code": [], "src_uid": "5953b898995a82edfbd42b6c0f7138af"} {"source_code": "class Array\n def findB\n x0 = 0\n x1 = size-1\n return self[x0] if yield(self[x0])\n return false unless yield(self[x1])\n\n while x1-x0 > 1\n x2 = (x0+x1)/2\n\n if yield(self[x2])\n x1 = x2\n else\n x0 = x2\n end\n end\n return self[x1]\n end\nend\n\ndef ceil(a, b)\n (a+b-1)/b\nend\n\ndef solve(from, to)\n chrs = {}\n 0.upto(from.size-1) do |i|\n chrs[from[i]] = true\n end\n\n unless to.each_char.all?{|x|chrs[x]}\n return -1\n end\n\n tbl = {}\n chrs.keys.each do |c|\n idx = 0\n o = tbl[c] = [0]*from.size\n 0.upto(from.size*2-1) do |i|\n if from[i%from.size] == c\n idx.upto(i-1) do |j|\n o[j%from.size] = i%from.size\n end\n break if i >= from.size\n idx = i\n end\n end\n end\n\n result = 1\n pos = -1\n ptr = Hash.new(-1)\n to.each_char do |x|\n new_pos = tbl[x][pos]\n #p [x, pos, new_pos, result, tbl[x]]\n result += 1 if new_pos <= pos\n pos = new_pos\n end\n\n result\nend\n\nfrom = gets.chomp\nto = gets.chomp\np solve(from, to)\n", "positive_code": [{"source_code": "def error\n\tp -1\n\texit\nend\ns,t=gets.chomp,gets.chomp\nnext_pos={}\nclosest_pos={}\ni,pos,ans=s.length,-1,1\ns.reverse.each_byte{|b|\n\ti-=1\n\tclosest_pos.each{|k,v|next_pos[(i<<7)+k]=v}\n\tclosest_pos[b]=i\n}\nclosest_pos.each{|k,v|next_pos[(-1<<7)+k]=v}\n\nt.each_byte{|b|\n\tpos=next_pos[(pos<<7)+b]\n\tunless pos\n\t\tans+=1\n\t\tpos=next_pos[(-1<<7)+b]\n\t\terror unless pos\n\tend\n}\np ans"}], "negative_code": [{"source_code": "def error\n\tp -1\n\texit\nend\ns,t=gets.chomp,gets.chomp\nerror if s.size>t.size\nnext_pos={}\nclosest_pos={}\ni,pos,ans=s.length,-1,1\ns.reverse.each_byte{|b|\n\ti-=1\n\tclosest_pos.each{|k,v|next_pos[[k,i]]=v}\n\tclosest_pos[b]=i\n}\nclosest_pos.each{|k,v|next_pos[[k,-1]]=v}\n\nt.each_byte{|b|\n\tpos=next_pos[[b,pos]]\n\tunless pos\n\t\tans+=1\n\t\tpos=next_pos[[b,-1]]\n\t\terror unless pos\n\tend\n}\np ans"}], "src_uid": "1b83529ea4057c76ae8483f8aa506c56"} {"source_code": "n, m = gets.split.collect{|i| i.to_i}\nv = gets.split.collect{|i| i.to_i}\nans = 0\n(1..m).each do\n tmp = gets.split.collect{|i| i.to_i}\n ans += [v[tmp[0]-1],v[tmp[1]-1]].min\nend\nputs ans\n", "positive_code": [{"source_code": "\n# Create reachability matrix\ndef reach(links,n)\n reachability = Array.new(n) {[]}\n for i in 0..(links.length - 1) do\n node = links[i].map{|c| c - 1}\n reachability[node[0]].push(node[1])\n reachability[node[1]].push(node[0])\n end\n return reachability\nend\n\n# Cost of removing a given node\ndef cost(node, energies, connections, dead_nodes)\n cost = 0\n for i in connections[node] do\n cost = cost + energies[i] unless dead_nodes[i]\n end\n return cost\nend\n\n# Initialize variables\nlinks = []; energies = []; connections = []; dead_nodes = []; energy_needed = 0;\n\n# Read input\nn, m = gets.strip.split.map{|s| s.to_i}\nenergies = gets.strip.split.map{|s| s.to_i}\nm.times {links.push(gets.strip.split.map{|s| s.to_i})}\n\n# Create connectivity matrix\nconnections = reach(links, n)\n\n# Initialize dead_node structures\ndead_nodes = Array.new(n,false)\n\n# Loop to find min total cost\norder = energies.map.with_index.sort.reverse.map(&:last)\nfor i in 0..(order.length - 1) do\n energy_needed = energy_needed + cost(order[i], energies, connections, dead_nodes)\n dead_nodes[order[i]] = true\nend\nputs energy_needed\n"}, {"source_code": "\n# Create reachability matrix\ndef reach(links,n)\n reachability = Array.new(n) {[]}\n for i in 0..(links.length - 1) do\n node = links[i].map{|c| c - 1}\n reachability[node[0]].push(node[1])\n reachability[node[1]].push(node[0])\n end\n return reachability\nend\n\n# Cost of removing a given node\ndef cost(node, energies, connections, dead_nodes)\n cost = 0\n for i in connections[node] do\n cost = cost + energies[i] unless dead_nodes[i]\n end\n return cost\nend\n\n# Initialize variables\nlinks = []; energies = []; connections = []; dead_nodes = []; energy_needed = 0;\n\n# Read input\nn, m = gets.strip.split.map{|s| s.to_i}\nenergies = gets.strip.split.map{|s| s.to_i}\nm.times {links.push(gets.strip.split.map{|s| s.to_i})}\n\n# Create connectivity matrix\nconnections = reach(links, n)\n\n# Initialize dead_node structures\ndead_nodes = Array.new(n,false)\n\n# Sorting of nodes by their energies\norder = energies.map.with_index.sort.reverse.map(&:last)\n\n# Loop over nodes to get min energy\nfor i in 0..(order.length - 1) do\n energy_needed = energy_needed + cost(order[i], energies, connections, dead_nodes)\n dead_nodes[order[i]] = true\nend\nputs energy_needed\n"}, {"source_code": "require 'set'\nr=lambda{ gets.split.map(&:to_i) }\nn,m=r.call\na=r.call\ng=Array.new(n){ Set.new }\nm.times{\n\tx,y=r.call\n\tg[x-1].add(y-1)\n\tg[y-1].add(x-1)\n}\ns=0\na.map.with_index.sort_by(&:first).map(&:last).reverse.each{ |e|\n\tg[e].each{|v| s+=a[v];g[v].delete e}\n}\np s"}, {"source_code": "n, m = gets.split.map { |x| x.to_i }\nf = gets.split.map { |x| x.to_i }\nans = 0\n\nm.times do\n\tu, v = gets.split.map { |x| x.to_i }\n\tans += [f[u-1], f[v-1]].min\nend\n\nprint ans, ?\\n\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\nv = gets.split.map(&:to_i)\n\n\nputs (0...m).map { |_|\n\ta,b = gets.split.map(&:to_i)\n\t[v[a-1], v[b-1]].min\n}.inject(0, &:+)"}], "negative_code": [{"source_code": "\n# Create reachability matrix\ndef reach(links,n)\n reachability = Array.new(n) {[]}\n for i in 0..(links.length - 1) do\n node = links[i].map{|c| c - 1}\n reachability[node[0]].push(node[1])\n reachability[node[1]].push(node[0])\n end\n return reachability\nend\n\n# Cost of removing a given node\ndef cost(node, energies, connections, dead_nodes)\n cost = 0\n for i in connections[node] do\n cost = cost + energies[i] unless dead_nodes[i]\n end\n return cost\nend\n\n# Costs for removing each node in a given configuration\ndef run_round(energies, connections, dead_nodes)\n total_cost = 0; costs = Array.new(energies.length, 0);\n for i in 0..(energies.length - 1) do\n unless dead_nodes[i]\n costs[i] = cost(i, energies, connections, dead_nodes)\n total_cost = total_cost + costs[i]\n end\n end\n return total_cost, costs\nend\n\ndef active_links(node, connections, dead_node_indices)\n return (connections[node] - dead_node_indices).length\nend\n\n# Initialize variables\nlinks = []; energies = []; connections = []; energy_needed = 0; \n\n# Read input\nn, m = gets.strip.split.map{|s| s.to_i}\nenergies = gets.strip.split.map{|s| s.to_i}\nm.times {links.push(gets.strip.split.map{|s| s.to_i})}\n\n# Create connectivity matrix\nconnections = reach(links, n)\n\n# Initialize dead_node structures\ndead_nodes = Array.new(n,false); dead_node_indices = [];\n\n# Loop to find min total cost\nwhile dead_nodes.include?(false)\n total_cost, costs = run_round(energies, connections, dead_nodes)\n cost_ratio = Array.new(energies.length, Float::INFINITY);\n for i in 0..(n- 1) do\n unless dead_nodes[i]\n cost_ratio[i] = (costs[i] == 0) ? 0 : (1.0 * costs[i]) / (energies[i] * active_links(i, connections, dead_node_indices) + costs[i])\n end\n end\n best_bet = cost_ratio.index(cost_ratio.min)\n dead_nodes[best_bet] = true; dead_node_indices.push(best_bet);\n energy_needed = energy_needed + costs[cost_ratio.index(cost_ratio.min)]\nend\n\nputs energy_needed"}, {"source_code": "n,m = gets.split.map(&:to_i)\nv = gets.split.map(&:to_i)\n\nputs (0...m).map { |_|\n\ta,b = gets.split.map(&:to_i)\n\t[v[a-1], v[b-1]].min\n}.inject(&:+)"}], "src_uid": "2e6bf9154d9da6ac134b52144d5322ca"} {"source_code": "n = gets.to_i ;puts \"#{n%3==2?2:1} 1 #{n%3==2?n-3:n-2}\"", "positive_code": [{"source_code": "n = gets.to_i\nprint 1, ' ', n%3 == 2 ? 2 : 1, ' ', n%3 == 2 ? n - 3 : n - 2\n"}, {"source_code": "n = gets.to_i\nif n%3==0 \n print \"1 1 #{n-2}\"\nelse \n print \"1 2 #{n-3}\"\nend"}, {"source_code": "a=gets.to_i;x=a%3;x=1 if x==0;p 1,x,a-x-1"}, {"source_code": "a=gets.to_i;x=a%3;x=1 if x==0;p 1,x,a-x-1"}, {"source_code": "n = gets.to_i\n\nif n % 3 == 0\n puts \"1 1 #{n-2}\"\nelse\n puts \"1 2 #{n-3}\"\nend"}, {"source_code": "n = gets.to_i\na,b,c = 1,1,n-2\nif c%3 == 0\n a += 1\n c -= 1\nend\nputs \"#{a} #{b} #{c}\"\n"}, {"source_code": "n=gets.to_i\nfn=sn=tn=0\nif n%2==0\n\tfn=2\n\tn-=2\nelse\n\tfn=1\n\tn-=1\nend\n\nsn=tn=n/2\n\nif sn%3==0\n\tsn-=1\n\ttn+=1\nend\n\nputs \"#{fn} #{sn} #{tn}\""}, {"source_code": "n = gets.to_i\n\nif n % 3 == 0\n puts \"1 1 #{n - 2}\"\nelse\n puts \"1 2 #{n - 3}\"\nend"}], "negative_code": [{"source_code": "a=gets.to_i;x=a%3<1?0:1;p 1,x,a-x-1"}], "src_uid": "91d5147fb602298e08cbdd9f86d833f8"} {"source_code": "q = gets.to_i\n\noldies = []\nnewies = {}\nchanges = {}\n\nq.times do \n old, new = gets.chomp.split\n \n oldies.push(old) if changes[old] == nil && newies[old] == nil\n changes[old] = new\n newies[new] = true\nend\n\nputs oldies.size\noldies.each do |old|\n new = changes[old]\n while changes[new] != nil\n new = changes[new]\n end\n \n puts \"#{old} #{new}\"\nend", "positive_code": [{"source_code": "# @snippet\nmodule Solution; end\n# @snippet\nrequire \"scanf\"\n# @snippet\nclass Solution::Runner\n\n def self.run(input_format, input_stream = STDIN, output_stream = STDOUT, &block)\n Solution::Solver.new(input_format, input_stream, output_stream) do\n input do |args|\n if block.nil?\n output solve(*args)\n else\n output block.call(*args)\n end\n end\n end\n end\n\nend\n# @snippet\nclass Solution::Solver\n\n attr_reader :input_format\n attr_reader :input_stream\n attr_reader :output_stream\n\n def initialize(new_input_format, new_input_stream, new_output_stream, &block)\n @input_format = new_input_format\n @input_stream = new_input_stream\n @output_stream = new_output_stream\n\n instance_eval(&block) if block_given?\n end\n\n def input\n while s = gets\n break if s.nil?\n s.scanf(input_format) do |*args|\n yield(*args)\n end\n end\n end\n\n def output(res)\n puts res.size\n res.each do |key, value|\n puts \"#{key} #{value}\"\n end\n end\n\nend\n# @snippet\n\nrequire \"set\"\n\nclass Disj\n\n attr_reader :parent\n attr_reader :root\n attr_reader :last_name\n\n def initialize\n @last_name = {}\n @parent = {}\n @root = Set.new\n end\n\n def size\n @root.size\n end\n\n def find(name)\n if parent[name].nil?\n name\n else\n find(parent[name])\n end\n end\n\n def parent?(name)\n find(name) === name\n end\n\n def update(old_name, new_name)\n if parent?(old_name)\n root.add old_name\n end\n last_name[find(old_name)] = new_name\n parent[new_name] = find(old_name)\n self\n end\n\n def each\n root.each do |name|\n yield name, last_name[name]\n end\n end\n\nend\n\ninput_format = \"%d\" # scanf(input_format)\nSolution::Runner.run(input_format) do |q|\n (1..q).to_a.map do\n old, new = gets.split\n {:new => new, :old => old, }\n end.inject(Disj.new) do |disj, info|\n disj.update info[:old], info[:new]\n end\nend\n\n"}, {"source_code": "n = gets.to_i\n\nh = Hash.new\n\nn.times do\n old_handle, new_handle = gets.split(' ')\n if h[old_handle].nil? then\n h[new_handle] = old_handle\n else\n h[new_handle] = h[old_handle]\n h.delete(old_handle)\n end\nend\n\nprint \"#{h.length}\\n\"\nh.each do |k, v|\n print \"#{v} #{k}\\n\"\nend\n"}, {"source_code": "q = gets.to_i\n\nusers = {}\n\nfor s in STDIN.each_line.take q\n old, new = s.split \" \"\n\n if users.has_value? old\n k = users.key(old)\n users[k] = new\n else\n users = users.merge!({old => new})\n end\nend\n\nputs users.length\n\nusers.each do |k, v|\n puts \"#{k} #{v}\"\nend\n\n"}, {"source_code": "pa=Array.new\nha=Hash.new #ruby\u7684\u54c8\u5e0c\nhb=Hash.new #ruby\u7684\u54c8\u5e0c\n\nn=gets.to_i\nfor i in 1..n\n str=gets.to_s\n pa=str.split\n stra=pa[0]\n strb=pa[1]\n ha[stra]=strb\nend\n#p ha\n\nha.each{|key,value|\n stt=key\n while ha[stt]!=nil\n stb=stt\n stt=ha[stt]\n ha.delete(stb)\n end\n hb[key]=stt\n}\n#p hb\n\nputs hb.length\nhb.each{|key,value|\n puts\"#{key} #{value}\" #\u8f93\u51fa\u683c\u5f0f\u63a7\u5236\n}\n"}, {"source_code": "# $f = File.open('input.txt', 'r')\n$f = STDIN\n\ndef read_line\n $f.gets.chomp.split\nend\n\ndef read_input(n)\n hash = {}\n n.times do\n sa, sb = read_line\n change = hash.key(sa) || sa\n\n hash[change] = sb\n end\n hash\nend\n\ndef output(hash)\n puts hash.size\n hash.each do |k, v|\n puts \"#{k} #{v}\"\n end\nend\n\ndef solve(n)\n output read_input(n)\nend\n\nwhile str = $f.gets\n n = str.chomp.to_i\n solve(n)\nend\n"}, {"source_code": "# f=File.new(\"out.txt\",\"w\")\n# fi=File.open(\"in.txt\",\"r\")\n\n\nn=gets\n#f.puts(n)\ndb=Array.new;\nn.to_i.times do | |\n s=gets\n names=s.split\n b=1\n if db.empty?\n db.push(Array.new)\n db.last.push(names[0])\n db.last.push(names[1])\n else\n db.each do |i|\n if i.last==names[0]\n i.push(names[1])\n b=0\n end\n end\n if b==1\n db.push(Array.new)\n db.last.push(names[0])\n db.last.push(names[1])\n end\n end\n\nend\n\nputs db.size\ndb.each do |i|\nprint i.first\nprint \" \"\nputs i.last\nend\n"}, {"source_code": "q = gets.chomp.to_i\nqueries = []\nq.times { queries << gets.chomp.split }\n\nhash = Hash.new { |h, k| h[k] = [] }\nqueries.each do |old_name, new_name|\n root = hash.keys.select { |key| hash[key].last == old_name }.first\n if root.nil?\n hash[old_name] << new_name\n else\n hash[root] << new_name\n end\nend\n\nputs hash.keys.length\nhash.keys.each { |key| puts \"#{key} #{hash[key].last}\" }\n"}, {"source_code": "n=gets.to_i\ns=[]\ncnt=0\nn.times do\n s << gets.split(' ').map{|x| x.to_s}\n s.flatten!\n for i in 0...s.size-2\n if s[-2] == s[i] && i%2==1\n cnt+=1\n s[i]=s[-1]\n s.delete_at(-2)\n s.delete_at(-1)\n end\n end\nend\ni=0\nputs n-cnt\nwhile i < s.size\n print s[i]+\" \"+s[i+1]\n puts\n i+=2\nend\n"}, {"source_code": "q = STDIN.gets.to_i\n\nusers = {}\nq.times do\n old, new = STDIN.gets.split(' ')\n\n if users.values.include?(old)\n initial = users.key(old)\n users[initial] = new\n else\n users[old] = new\n end\n\nend\n\nputs users.keys.count\nusers.each_pair do |old, new|\n puts \"#{old} #{new}\"\nend"}, {"source_code": "n = gets.to_i\nnames = {}\nn.times do |i|\n before, after = gets.chomp.split\n if names[before] != nil\n names[after] = names[before]\n names.delete(before)\n else\n names[after] = before\n end\nend\n\nputs names.length\nnames.each do |after, before|\n puts [before, after].join(\" \")\nend"}, {"source_code": "h = {}\nn = gets.to_i\nn.times{\n a,b = gets.split\n if h[a]\n h[b] = h[a]\n h.delete(a)\n else\n h[b] = a\n end\n}\nputs h.length\nh.each { |a,b| puts \"#{b} #{a}\"}"}, {"source_code": "q = gets.to_i\n\nusers = Hash.new\n\nq.times do\n o, n = gets.split(\" \")\n if users[o].nil? then\n users[n] = o\n else\n users[n] = users[o]\n users.delete(o)\n end\nend\n\nprint \"#{users.length}\\n\"\nusers.each do |v, k|\n print \"#{k} #{v}\\n\"\nend"}, {"source_code": "n = gets.to_i\nhash = {}\nn.times do\n\told,new = gets.split.map(&:chomp)\n\tif hash.key?(old)\n\t\thash[new] = hash[old]\n\t\thash.delete(old)\n\telse\n\t\thash[new] = old\n\tend\nend\np hash.length\nhash.invert.sort_by{|key,val| key}.each{|val| puts \"#{val[0]} #{val[1]}\"}\n"}, {"source_code": "#!/usr/bin/ruby\n\ninput_line = gets\namount = input_line.to_i\n\nusers = Hash.new\ncounter = 0\nwhile (counter < amount) do\n counter +=1\n input_line = gets.split(' ')\n if (users.has_value? input_line[0])\n users[users.key(input_line[0])] = input_line[1]\n else\n users[input_line[0]] = input_line[1]\n end\nend\n\nputs users.size\n\nusers.each_key do |key|\n puts key+' ' + users[key]\nend\n"}, {"source_code": "# @snippet\nmodule Solution; end\n# @snippet\nrequire \"scanf\"\n# @snippet\nclass Solution::Runner\n\n def self.run(input_format, input_stream = STDIN, output_stream = STDOUT, &block)\n Solution::Solver.new(input_format, input_stream, output_stream) do\n input do |args|\n if block.nil?\n output solve(*args)\n else\n output block.call(*args)\n end\n end\n end\n end\n\nend\n# @snippet\nclass Solution::Solver\n\n attr_reader :input_format\n attr_reader :input_stream\n attr_reader :output_stream\n\n def initialize(new_input_format, new_input_stream, new_output_stream, &block)\n @input_format = new_input_format\n @input_stream = new_input_stream\n @output_stream = new_output_stream\n\n instance_eval(&block) if block_given?\n end\n\n def input\n while s = gets\n break if s.nil?\n s.scanf(input_format) do |*args|\n yield(*args)\n end\n end\n end\n\n def output(res)\n puts res.size\n res.each do |key, value|\n puts \"#{key} #{value}\"\n end\n end\n\nend\n# @snippet\n\nrequire \"set\"\n\nclass Disj\n\n attr_reader :parent\n attr_reader :root\n attr_reader :last_name\n\n def initialize\n @last_name = {}\n @parent = {}\n @root = Set.new\n end\n\n def size\n @root.size\n end\n\n def find(name)\n if parent[name].nil?\n name\n else\n find(parent[name])\n end\n end\n\n def parent?(name)\n find(name) === name\n end\n\n def update(old_name, new_name)\n if parent?(old_name)\n root.add old_name\n end\n last_name[find(old_name)] = new_name\n parent[new_name] = find(old_name)\n end\n\n def each\n root.each do |name|\n yield name, last_name[name]\n end\n end\n\nend\n\ninput_format = \"%d\" # scanf(input_format)\nSolution::Runner.run(input_format) do |q|\n disj = Disj.new\n\n list = (1..q).to_a.map do\n old, new = gets.split\n {:new => new, :old => old, }\n end\n\n list.inject(Set.new) do |set, info|\n disj.update info[:old], info[:new]\n end\n\n disj\nend\n"}], "negative_code": [{"source_code": "q = gets.to_i\n\nusers = Hash.new\n\nq.times do\n o, n = gets.split(\" \")\n p users[o]\n if users[o].nil? then\n users[n] = o\n else\n users[n] = users[o]\n users.delete(o)\n end\nend\n\nprint \"#{users.length}\\n\"\nusers.each do |v, k|\n print \"#{k} #{v}\\n\"\nend"}, {"source_code": "pa=Array.new\nha=Hash.new #ruby\u7684\u54c8\u5e0c\nhb=Hash.new #ruby\u7684\u54c8\u5e0c\n\nn=gets.to_i\nfor i in 1..n\n str=gets.to_s\n pa=str.split\n stra=pa[0]\n strb=pa[1]\n ha[stra]=strb\nend\n#p ha\n\nha.each{|key,value|\n stt=key\n while ha[stt]!=nil\n stb=stt\n stt=ha[stt]\n ha.delete(stb)\n end\n hb[key]=stt\n}\n#p hb\n\nhb.each{|key,value|\n puts\"#{key} #{value}\"#\u8f93\u51fa\u683c\u5f0f\u63a7\u5236\n}\n"}], "src_uid": "bdd98d17ff0d804d88d662cba6a61e8f"} {"source_code": "n, m, k = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\ntotal_sum = 0\nfor i in 1..n do\n this_sum = 0\n order = gets.split.map(&:to_i)\n order.each_with_index do |val, i|\n for j in 0..k do\n if val == arr[j]\n o = arr.delete_at(j)\n this_sum += j + 1\n arr.unshift(o)\n end\n end\n end\n total_sum += this_sum\nend\nputs total_sum\n", "positive_code": [{"source_code": "n, m, k = readline.split(' ').collect(&:to_i)\narr = readline.split(' ').collect(&:to_i)\nsum = 0\nn.times do\n items = readline.split(' ').collect(&:to_i)\n items.each do |item|\n sum += arr.index(item) + 1\n arr.delete item\n arr.insert(0, item)\n end\nend\nputs sum\n"}, {"source_code": "io = lambda {gets.split.map(&:to_i)}\nn, m, k = io.call\np = io.call\nr = 0\n\n(0...n).each do |i|\n a = io.call\n a.each do |j|\n d = p.index(j)\n p.unshift(p.delete_at(d))\n r += d + 1\n end\nend\n\nputs r\n"}], "negative_code": [], "src_uid": "39fd7843558ed2aa6b8c997c2b8a1fad"} {"source_code": "n = gets.to_i\n\nvers = []\ntargets = []\nn.times do |i|\n s = gets.split.map{|i| i.to_i}\n targets << s[0] + s[1]\n vers << s[0]\nend\n\nif n < 2 then\n puts \"NO\"\nelse\n c = 0\n n.times do |i|\n if (k = vers.index(targets[i])) then\n if targets[k] == vers[i] then\n c = 2\n end\n end\n end\n if c > 1 then\n puts \"YES\"\n else\n puts \"NO\"\n end\nend", "positive_code": [{"source_code": "\nn=gets.to_i\ndata=[]\nn.times{data.push(gets.split.map(&:to_i)) }\ndata.each do |i|\n data.each do |j|\n if i[0]+i[1]==j[0] && j[0]+j[1]==i[0] then\n puts \"YES\"\n exit\n end\n end\nend\nputs \"NO\"\n"}, {"source_code": "n = gets.to_i\n\nmas = Array.new()\nfor i in 0..n-1\n s = gets.split(\" \")\n mas[i] = [s[0].to_i, s[1].to_i]\nend\n\nfor i in 0..n-1\n for j in 0..n-1\n if (i != j && (mas[i][0] + mas[i][1] == mas[j][0]) && (mas[j][0] + mas[j][1] == mas[i][0]))\n puts \"YES\"\n exit\n end\n end\nend\n\nputs \"NO\""}], "negative_code": [], "src_uid": "d7dc61a8f3b0091320b96cedd1f4f0a7"} {"source_code": "t = gets.to_i\r\nt.times do\r\n n, d = gets.split.map { |x| x.to_i }\r\n a = gets.split.map { |x| x.to_i }\r\n puts a.sort[0..1].sum <= d || a.max <= d ? \"YES\" : \"NO\"\r\nend\r\n# ", "positive_code": [{"source_code": "t = gets.to_i\r\nt.times do\r\n n, d = gets.split.map { |x| x.to_i }\r\n a = gets.split.map { |x| x.to_i }\r\n puts a.sort[0..1].sum <= d || a.max <= d ? \"YES\" : \"NO\"\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n,d=gets.split.map(&:to_i)\r\n a=gets.split.map(&:to_i).sort\r\n if a[-1]<=d\r\n puts \"YES\"\r\n elsif a[0]+a[1]<=d\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}, {"source_code": "gets.to_i.times do\n n, d = gets.split.map &:to_i\n a = gets.split.map &:to_i\n a.sort!\n if a[0] + a[1] <= d || a[-1] <= d\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n"}, {"source_code": "#input of int(split by space)\ndef get_i()\n return gets.chomp.split(\" \").map(&:to_i)\nend\n#input of float(split by space)\ndef get_f()\n return gets.chomp.split(\" \").map(&:to_f)\nend\n#input of string(split by space)\ndef get()\n return gets.chomp.split(\" \")\nend\n#input of string(split per one character)\ndef get_nsp()\n return gets.chomp.split(\"\")\nend\n#yes or no decision\ndef yn_judge(bool,y=\"Yes\",n=\"No\")\n return bool ? y : n \nend\n#create of array\ndef array(size1,init=nil,size2=-1)\n if size2==-1\n return Array.new(size1){init}\n else\n return Array.new(size2){Array.new(size1){init}}\n end\nend\n\ndef max(a,b)\n return a>b ? a : b\nend\n\ndef min(a,b)\n return a>b ? b : a\nend\n\nINF=Float::INFINITY\n\nT=gets.to_i\nT.times do\n n,d=get_i\n a=get_i\n f=true\n n.times do|i|\n if a[i]>d\n f=false\n break\n end \n end\n if f\n puts \"YES\"\n next\n end\n is_find=false\n (n-1).times do|i|\n (i+1).upto(n-1) do|j|\n if a[i]+a[j]<=d\n is_find=true \n break\n end\n end\n end\n if is_find\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n"}, {"source_code": "def read\r\n gets.split.map &:to_i\r\nend\r\ngets.to_i.times do\r\n _, d = read\r\n a = read.sort!\r\n puts a[0] + a[1] <= d || a[-1] <= d ? \"YES\" :\"NO\"\r\nend"}, {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n, d = gets.chomp.split.map(&:to_i)\r\n arr = gets.chomp.split.map(&:to_i)\r\n arr = arr.sort\r\n puts arr[0] + arr[1] <= d || arr.all?{|el| el <= d} ? \"YES\" : \"NO\"\r\nend"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n n,d=gets.split.map(&:to_i)\r\n a=gets.split.map(&:to_i).sum\r\n if a<=d*n\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}], "src_uid": "044c2a3bafe4f47036ee81f2e40f639a"} {"source_code": "n = gets.strip.to_i\n\narr = gets.strip.split(' ').map(&:to_i)\n\nquery = gets.strip.split(' ').map(&:to_i)\n\nmax = nil\n\npos = Hash.new()\n\narr.each_with_index do |a, i|\n pos[a] = i + 1\nend\n\nout = []\nquery.each do |q|\n if max.nil?\n max = pos[q]\n out << max\n else\n val = pos[q]\n if val > max\n out << (val - max)\n max = val\n else\n out << 0\n end\n end\nend\n\nputs out.join(' ')\n", "positive_code": [{"source_code": "# http://codeforces.com/contest/1073/problem/B\n\nn = gets\narray = gets.split(' ').map(&:to_i)\nsteps = gets.split(' ').map(&:to_i)\n\nbackpack = {}\nresult = []\n\nsteps.each do |step|\n if backpack[step]\n result << 0\n else\n count = 0\n begin\n num = array.shift\n count += 1\n backpack[num] = 1\n end while num != step\n\n result << count\n end\nend\n\nputs result.join(' ')\n"}], "negative_code": [], "src_uid": "82176739a1dd4fe85ec059058a00fbb9"} {"source_code": "def compute(n, as) \n last = nil \n max = 0 \n crt = 0\n\n as.each do |a|\n if last\n if last * 2 >= a\n crt += 1\n else\n crt = 1\n end\n else\n crt += 1\n end\n\n max = [crt, max].max\n last = a\n end\n\n max\n\nend\n\ndef solution\n n = read_int\n as = read_ints\n\n puts compute(n, as)\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\n\nsolution unless ENV['TEST__MODE']\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nputs a.chunk_while { _1 * 2 >= _2 }.map(&:size).max"}, {"source_code": "#! /usr/bin/ruby\n\ngets\ninput = gets.chomp.split ' '\ninput.map! { |word| word.to_i }\n\ni = 0\nj = 0\nans = 0\n\nwhile j < input.size - 1\n if input[j + 1] <= 2 * input[j]\n j += 1\n else\n ans = [ans, j - i + 1].max\n j += 1\n i = j\n end\nend\n\nans = [ans, j - i + 1].max\n\nputs ans\n"}, {"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i)\nans = 1\nlen = 1\nnow = as[0]\n(1...N).each do |i|\n if now*2 >= as[i]\n now = as[i]\n len += 1\n ans = len if ans < len\n else\n len = 1\n now = as[i]\n end\nend\nputs ans"}, {"source_code": "class Node\n\tattr_accessor :prev\n\tattr_accessor :next\n\tattr_accessor :data\n\n\tdef initialize(p,n,d)\n\t\t@prev = p \n\t\t@next = n \n\t\t@data = d \n\tend\nend\n\nclass Que\n\tdef initialize()\n\t\t@front = nil\n\t\t@rear = nil\n\t\t@size = 0\n\tend\n\n\tdef pushl(k)\n\t\t@size += 1\n\t\ta = Node.new(@rear,nil,k)\n\t\tif(@front == nil)\n\t\t\t@front = a\n\t\t\t@rear = a\n\t\telse\n\t\t\t@rear.next = a\n\t\t\t@rear = a\n\t\tend\n\tend\n\n\tdef popf()\n\t\t@size -= 1\n\t\trem = @front\n\t\t@front = @front.next\n\t\t# @front.prev = nil\n\t\tif (@size == 0)\n\t\t\t@rear = nil\n\t\telse \n\t\t\t@front.prev = nil\n\t\tend\n\t\treturn rem.data\n\tend\n\n\tdef contains(k)\n\t\tnow = @front\n\t\twhile(now != nil)\n\t\t\tif (now.data == k)\n\t\t\t\treturn true\n\t\t\telse\n\t\t\t\tnow = now.next\n\t\t\tend\n\t\tend\n\t\treturn false\n\tend\n\n\tdef pushf(k)\n\t\t@size += 1\n\t\ta = Node.new(nil,@front,k)\n\t\t@front = a\n\t\tif(@front == nil)\n\t\t\t@rear = a\n\t\tend\n\tend\n\n\tdef popl()\n\t\t@size -= 1\n\t\ta = @rear\n\t\tif(@size == 0)\n\t\t\t@front = nil \n\t\t\t@rear = nil \n\t\telse\n\t\t\t@rear = @rear.prev \n\t\t\t@rear.next = nil \n\t\tend\n\t\treturn a.data\n\tend\n\tdef front()\n\t\treturn @front.data\n\tend\n\n\tdef size()\n\t\treturn @size\n\tend\n\n\tdef rear()\n\t\treturn @rear.data\n\tend\nend\n\n\nuseless = gets.chomp.to_i\ninp = gets.chomp.split(\" \")\narr = Array.new() \nfor i in inp \n\tarr << i.to_i\nend\nif useless == 1\n\tprint(1)\n\texit\nend\nq = Que.new()\nq.pushl(arr[0])\nmax = -10\ncur = 1\ni = 1\nmarked = true\nuntil i == useless\n\tif (marked)\n\t\tq.pushl(arr[i])\n\tend\n\tif(arr[i] <= q.front*2)\n\t\tcur += 1\n\t\tif(max < cur)\n\t\t\tmax= cur\n\t\tend\n\t\tmarked = true \n\telse\n\t\tq.popf\n\t\tif(q.size == 1)\n\t\t\tcur = 0 \n\t\tend\n\t\ti -= 1\n\t\tmarked = false\n\tend\n\ti += 1\nend\n\nprint(max)"}, {"source_code": "def binary_search(range)\n lower = 0\n upper = range.size\n while lower < upper\n mi = (lower + upper)/2\n yield(range[mi]) ? upper = mi : lower = mi + 1\n end\n [range[upper], upper]\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\ndp = Array.new(n)\ne = Array.new(n)\ndp[0] = 1\ne[0] = 0\n(1...n).each do |i|\n if 2*a[e[i-1]] >= a[i]\n e[i] = i\n dp[i] = dp[i-1]+1\n elsif 2*a[i-1] >= a[i]\n e[i] = i\n dp[i] = 2\n else\n e[i] = e[i-1]\n dp[i] = dp[i-1]\n end\nend\nputs dp.max"}], "negative_code": [{"source_code": "class Node\n\tattr_accessor :prev\n\tattr_accessor :next\n\tattr_accessor :data\n\n\tdef initialize(p,n,d)\n\t\t@prev = p \n\t\t@next = n \n\t\t@data = d \n\tend\nend\n\nclass Que\n\tdef initialize()\n\t\t@front = nil\n\t\t@rear = nil\n\t\t@size = 0\n\tend\n\n\tdef pushl(k)\n\t\t@size += 1\n\t\ta = Node.new(@rear,nil,k)\n\t\tif(@front == nil)\n\t\t\t@front = a\n\t\t\t@rear = a\n\t\telse\n\t\t\t@rear.next = a\n\t\t\t@rear = a\n\t\tend\n\tend\n\n\tdef popf()\n\t\t@size -= 1\n\t\trem = @front\n\t\t@front = @front.next\n\t\t# @front.prev = nil\n\t\tif (@size == 0)\n\t\t\t@rear = nil\n\t\telse \n\t\t\t@front.prev = nil\n\t\tend\n\t\treturn rem.data\n\tend\n\n\tdef contains(k)\n\t\tnow = @front\n\t\twhile(now != nil)\n\t\t\tif (now.data == k)\n\t\t\t\treturn true\n\t\t\telse\n\t\t\t\tnow = now.next\n\t\t\tend\n\t\tend\n\t\treturn false\n\tend\n\n\tdef pushf(k)\n\t\t@size += 1\n\t\ta = Node.new(nil,@front,k)\n\t\t@front = a\n\t\tif(@front == nil)\n\t\t\t@rear = a\n\t\tend\n\tend\n\n\tdef popl()\n\t\t@size -= 1\n\t\ta = @rear\n\t\tif(@size == 0)\n\t\t\t@front = nil \n\t\t\t@rear = nil \n\t\telse\n\t\t\t@rear = @rear.prev \n\t\t\t@rear.next = nil \n\t\tend\n\t\treturn a.data\n\tend\n\tdef front()\n\t\treturn @front.data\n\tend\n\n\tdef size()\n\t\treturn @size\n\tend\n\n\tdef rear()\n\t\treturn @rear.data\n\tend\nend\n\n\nuseless = gets.chomp.to_i\ninp = gets.chomp.split(\" \")\narr = Array.new() \nfor i in inp \n\tarr << i.to_i\nend\nif useless == 1\n\tprint(1)\n\texit\nend\nq = Que.new()\nq.pushl(arr[0])\nmax = -10\ncur = 1\ni = 1\nmarked = true\nuntil i == useless\n\tif (marked)\n\t\tq.pushl(arr[i])\n\tend\n\tif(arr[i] <= q.front*2)\n\t\tcur += 1\n\t\tif(max < cur)\n\t\t\tmax= cur\n\t\tend\n\t\tmarked = true \n\telse\n\t\tq.popf\n\t\tcur -= 1\n\t\ti -= 1\n\t\tmarked = false\n\tend\n\ti += 1\nend\n\nprint(max)\n\n"}], "src_uid": "5088d1d358508ea3684902c8e32443a3"} {"source_code": "# coding: utf-8\n\nn = readline.to_i\narr = readline.chomp.split(' ').map(&:to_i)\n\nsarr = arr.sort\n\nif sarr == arr then\n puts 'yes'\n puts '1 1'\n STDOUT.flush\n exit! 0\nend\n\nl = ((0..arr.size-1).find_index {|i| arr[i] != sarr[i]}).to_i\nr = ((0..arr.size-1).to_a.reverse.find {|i| arr[i] != sarr[i]}).to_i\n\nparr = []\nparr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size-1-r)\n\nif parr == sarr then\n puts 'yes'\n puts \"#{l+1} #{r+1}\"\nelse\n puts 'no'\nend", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = a.zip(b).index{|x, y| x != y} || 0\ne = a.zip(b).rindex{|x, y| x != y} || 0\na[s..e] = a[s..e].reverse\nif a == b\n puts 'yes', \"#{s + 1} #{e + 1}\"\nelse\n puts 'no'\nend\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = a.zip(b).index{|x, y| x != y} || 0\ne = a.zip(b).rindex{|x, y| x != y} || 0\na[s..e] = a[s..e].reverse\nif a == b\n puts 'yes', \"#{s + 1} #{e + 1}\"\nelse\n puts 'no'\nend\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map{|i| i.to_i}\nb=a.clone.sort\nif a==b\n\tputs \"yes\\n1 1\"\n\texit\nend\nl=0\nn.times{|x| l=x; break if a[x]!=b[x]}\nr=0\nn.times{|x| r=n-1-x; break if a[n-x-1]!=b[n-x-1]}\nif a[0,l]+a[l..r].reverse+a[r+1..-1] == b\n\tputs \"yes\\n#{l+1} #{r+1}\"\nelsif\n\tputs 'no'\nend\n\t\t\n"}, {"source_code": "n = gets.rstrip.to_i\narr = gets.rstrip.split(' ').map(&:to_i)\n\nsorted_arr = arr.sort\n\nl = r = 0\nfor i in 0..(n - 1)\n if arr[i] != sorted_arr[i]\n l = i\n break\n end\nend\n\nj = n - 1\nwhile j >= 0 do\n if arr[j] != sorted_arr[j]\n r = j\n break\n end\n j -= 1\nend\n\nj = r\nfor i in l..r\n if arr[i] != sorted_arr[j]\n puts 'no'\n exit\n else\n j -= 1\n end\nend\n\nputs 'yes'\nputs \"#{l + 1} #{r + 1}\"\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nc=\"\"\narr=\"\"\nminP=0\nmaxP=0\n(x.size-1).times{|i|\n\ts=\"\"\n\tif x[i]0 then\n\t\tx1=x.slice(0..(minP-1))\n\t\tx2=x.slice(minP..maxP)\n\t\tif x1.max>x2.min then\n\t\t\tok=false\n\t\tend\n\tend\n\tif maxP<(x.size-1) then\n\t\tx1=x.slice(minP..maxP)\n\t\tx2=x.slice(maxP+1,x.size)\n\t\tif x1.max>x2.min then\n\t\t\tok=false\n\t\tend\n\tend\n\tif ok==false then\n\t\tputs \"no\"\n\telse\n\t\tputs \"yes\"\n\t\tputs [minP+1,maxP+1]*\" \"\n\tend\nelse\n\tputs \"no\"\nend\n\t"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(' ').map(&:to_i)\ns = 0\ne = 0\nfor i in 0..n-2\n\tif a[i]>a[i+1]\n\t\ts = i\n\t\tbreak\n\tend\nend\n(n-1).downto(1) do |i|\n\tif a[i] a[s-1] ) && (e == n-1 or a[s] 0\n item_before_fidx = a[fidx - 1]\n end\n\n if lidx < (n-1)\n item_after_lidx = a[lidx + 1]\n end\n\n if item_before_fidx <= a[lidx] && item_after_lidx >= a[fidx]\n puts \"yes\"\n puts \"#{fidx+1} #{lidx+1}\" # 1-based indices\n else\n puts \"no\"\n end\nend\n\n# if yes: print 'yes' and show begin/end index\n# else no\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = a.zip(b).index{|x, y| x != y} || 0\ne = a.zip(b).rindex{|x, y| x != y} || 0\na[s..e] = a[s..e].reverse\nif a == b\n puts 'yes', \"#{s + 1} #{e + 1}\"\nelse\n puts 'no'\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = a.zip(b).index{|x, y| x != y} || 0\ne = a.zip(b).rindex{|x, y| x != y} || 0\na[s..e] = a[s..e].reverse\nif a == b\n puts 'yes', \"#{s + 1} #{e + 1}\"\nelse\n puts 'no'\nend\n\n"}, {"source_code": "n = gets.to_i\narr =gets.split(\" \").map(&:to_i)\nprev = arr[0]\nseg = nil\nseg_start = nil\nseg_end = nil\nans = true\nseg_found = false\n(1..n-1).each do |i|\n\tif arr[i] >= prev\t\t\n\t\tif seg\n\t\t\tseg = nil\n\t\t\tseg_end = i - 1\n\t\tend\n\telse\n\t\tunless seg\n\t\t\tseg = true\n\t\t\tseg_found = true\n\t\t\tseg_start = i - 1\n\t\tend\n\tend\n\tprev = arr[i]\nend\nif seg_found\n\tseg_end = n - 1 if !seg_end && seg && seg_start\n\t# puts \"#{seg_start} #{seg_end}\"\n\tfirst_part = arr[0..seg_start - 1] unless seg_start == 0\n\tlast_part = arr[seg_end+1..n-1]\n\tmid_part = arr[seg_start..seg_end].reverse if arr[seg_start..seg_end]\n\tnew_arr = (first_part || [] )+ (mid_part || []) + (last_part || [])\n\t# puts \"#{first_part} #{arr[seg_start..seg_end].reverse} #{arr[seg_end+1..n-1]}\"\n\tans = false unless new_arr == arr.sort\nelse\n\tif arr == arr.sort\n\t\tseg_start = 0\n\t\tseg_end = 0\n\telse\n\t\tans = false \n\tend\nend\n\nif ans\n\tputs \"yes\"\n\tputs \"#{seg_start+1} #{seg_end+1}\"\nelse\n\tputs \"no\"\nend\n"}, {"source_code": "def isSorted(a)\n a.inject([-1, true]) { |p, v|\n [v, (p[1] and p[0] <= v)]\n }[1]\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\np1 = -1\np2 = -1\n\nprev = -1\na.each_with_index { |val, idx|\n if p1 == -1\n if prev > val\n p1 = idx-1\n end\n else\n if prev < val\n p2 = idx-1\n break\n end\n end\n prev = val\n}\n\nif p1 == -1 and p2 == -1\n p1 = p2 = 0\nelsif p2 == -1\n p2 = n-1\nend\nsorted = a[0...p1] + a[p1..p2].reverse + a[p2+1...n]\n\nif isSorted sorted\n puts \"yes\"\n puts \"#{p1+1} #{p2+1}\"\nelse\n puts \"no\"\nend\n"}, {"source_code": "def find_point(a)\n p1 = -1\n p2 = -1\n prev = -1\n a.each_with_index do |val, idx|\n if p1 == -1\n if prev > val\n p1 = idx-1\n end\n else\n if prev < val\n p2 = idx-1\n break\n end\n end\n prev = val\n end\n [p1, p2]\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\np1,p2 = find_point a\nif p1 == -1 and p2 == -1\n p1 = p2 = 0\nelsif p2 == -1\n p2 = n-1\nend\nsorted = a[0...p1] + a[p1..p2].reverse + a[p2+1...n]\n\nif sorted == a.sort\n puts \"yes\"\n puts \"#{p1+1} #{p2+1}\"\nelse\n puts \"no\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = nil\ne = nil\nn.times do |i|\n s = i if a[i] != b[i] && s == nil \n e = i if a[i] != b[i]\nend\ns = e = 0 if s == nil || e == nil\naa = [a[0...s], a[s..e].reverse, a[e + 1..-1]]\nif aa.join == b.join\n puts \"yes\"\n puts \"#{s + 1} #{e + 1}\"\nelse\n puts \"no\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = a.zip(b).index{|x, y| x != y} || 0\ne = a.zip(b).rindex{|x, y| x != y} || 0\na[s..e] = a[s..e].reverse\nif a == b\n puts 'yes', \"#{s + 1} #{e + 1}\"\nelse\n puts 'no'\nend\n"}, {"source_code": "# coding: utf-8\n\nn = readline.to_i\narr = readline.chomp.split(' ').map(&:to_i)\n\nsarr = arr.sort\n\nif sarr == arr then\n puts 'yes'\n puts '1 1'\nelse\n\n l = ((0..arr.size-1).find_index {|i| arr[i] != sarr[i]}).to_i\n r = ((0..arr.size-1).to_a.reverse.find {|i| arr[i] != sarr[i]}).to_i\n \n parr = []\n parr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size-1-r)\n\n if parr == sarr then\n puts 'yes'\n puts \"#{l+1} #{r+1}\"\n else\n puts 'no'\n end\nend"}, {"source_code": "length = gets.split.map{|_|_.to_i}\narray = gets.split.map{|_|_.to_i}\n\nsorted_array = array.sort\nstarted = 0\nended = 0\nswitch = 0\nindex = 0\n\nwhile index <= array.length\n if sorted_array[index] != array[index]\n if switch % 2 == 0\n started = index\n switch += 1\n else\n ended = index\n end\n end\n \n index += 1\nend\n\nif switch == 0 || sorted_array[started..ended] == array[started..ended].reverse\n puts \"yes\"\n puts [started + 1, ended + 1].join(\" \")\nelse\n puts \"no\"\nend"}, {"source_code": "n = gets.chomp.to_i\nlist = gets.chomp.split.map(&:to_i)\n\nsorted_list = list.sort\ndiff_pos = []\n\nfor i in 0..(n - 1)\n if list[i] != sorted_list[i]\n diff_pos << i\n end\nend\n\nif diff_pos.empty?\n l = 0\n r = 0\nelse\n l = diff_pos[0]\n r = diff_pos[-1]\nend\n\nreverse_segment = list[l..r].dup\n\nfor i in 0..((reverse_segment.length - 1)/ 2.0)\n temp = reverse_segment[i]\n reverse_segment[i] = reverse_segment[reverse_segment.length - 1 - i]\n reverse_segment[reverse_segment.length - 1 - i] = temp\nend\n\nlist[l..r] = reverse_segment\n\nif list == sorted_list\n puts \"yes\"\n print l + 1, \" \", r + 1\nelse\n puts \"no\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = a.zip(b).index{|x, y| x != y} || 0\ne = a.zip(b).rindex{|x, y| x != y} || 0\na[s..e] = a[s..e].reverse\nif a == b\n puts 'yes', \"#{s + 1} #{e + 1}\"\nelse\n puts 'no'\nend\n\n"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\n\nl = 0\nr = a.size\n\na.unshift 0\na.push 10 ** 9 + 1\n\nwhile l < r && a[l] < a[l+1]\n l += 1\nend\n\nwhile r > l && a[r] > a[r-1]\n r -= 1\nend\n\nif a[l] < a[r+1] && a[r] > a[l-1] && (l+1..r).all? { |i| a[i-1] > a[i] }\n puts \"yes\"\n puts \"#{l} #{r}\"\nelse\n puts \"no\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split.map(&:to_i)\np = q = nil\n(0...n - 1).each { |i|\n if a[i] > a[i + 1]\n if q\n puts 'no'\n exit\n end\n p = i unless p\n else\n q = i if p && !q\n end\n}\np = n - 1 unless p\nq = n - 1 if p && !q\nputs (p == 0 || a[p - 1] < a[q]) && (q == n - 1 || a[p] < a[q + 1]) ? \"yes\\n#{[p + 1, q + 1].join(' ')}\" : 'no'"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = a.zip(b).index{|x, y| x != y} || 0\ne = a.zip(b).rindex{|x, y| x != y} || 0\na[s..e] = a[s..e].reverse\nif a == b\n puts 'yes', \"#{s + 1} #{e + 1}\"\nelse\n puts 'no'\nend\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = a.zip(b).index{|x, y| x != y} || 0\ne = a.zip(b).rindex{|x, y| x != y} || 0\na[s..e] = a[s..e].reverse\nif a == b\n puts 'yes', \"#{s + 1} #{e + 1}\"\nelse\n puts 'no'\nend\n\n"}, {"source_code": "def no;puts \"no\";exit;end\nn=gets.to_i\na=gets.split.map{|s|s.to_i}\nl = nil\nr = nil\n(n-1).times do |i|\n if r\n no if a[i] > a[i+1]\n elsif l\n r = i if a[i] < a[i+1]\n else\n l = i if a[i] > a[i+1]\n end\nend\nl || (l, r = 0, 0)\nr ||= n-1\nno if r < n-1 && a[l] > a[r+1]\nno if l > 0 && a[l-1] > a[r]\nputs \"yes\"\nputs [l+1, r+1].join(\" \")"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\n\ndef sign n\n n == 0 ? 0 : n.abs / n\nend\nif a.length > 1\n segment_directions = []\n #negative descending, positive ascending\n direction = sign(a[1] - a[0])\n start_index = 0\n end_index = 1\n\n for i in 2 ... n\n local_direction = sign(a[i] - a[i - 1])\n if local_direction == direction\n end_index = i\n else\n segment_directions << [direction, start_index, end_index]\n direction = local_direction\n start_index = i - 1\n end_index = i\n end\n end\n segment_directions << [direction, start_index, end_index]\n\n descending_segments = segment_directions.select {|d| d[0] == -1}\n\n if descending_segments.length > 1\n puts \"no\"\n elsif descending_segments.length == 1\n reverse_start_index = descending_segments[0][1]\n reverse_end_index = descending_segments[0][2]\n seg_strt_gt_pre = reverse_start_index > 0? a[reverse_end_index] > a [reverse_start_index - 1] : true\n seg_end_lt_nxt = reverse_end_index < n - 1 ? a[reverse_start_index] < a[reverse_end_index + 1] : true;\n if seg_strt_gt_pre && seg_end_lt_nxt\n puts \"yes\"\n puts \"#{reverse_start_index + 1} #{reverse_end_index + 1}\"\n else\n puts \"no\"\n end\n else\n puts \"yes\"\n puts \"1 1\"\n end \nelse\n puts \"yes\", \"1 1\"\nend\n\n"}, {"source_code": "N = gets.to_i\narr = gets.chomp.split(' ').map(&:to_i)\n\nrra = arr.sort\n\nif rra == arr \n puts \"yes\\n1 1\"\n exit\nend\n\nl = ((0...arr.size).find_index {|i| arr[i] != rra[i]}).to_i\nr = ((0...arr.size).to_a.reverse.find {|i| arr[i] != rra[i]}).to_i\n\nbrr = []\nbrr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size - 1 - r)\n\nif brr == rra\n puts 'yes'\n puts \"#{l + 1} #{r + 1}\"\nelse\n puts 'no'\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = a.zip(b).index{|x, y| x != y} || 0\ne = a.zip(b).rindex{|x, y| x != y} || 0\na[s..e] = a[s..e].reverse\nif a == b\n puts 'yes', \"#{s + 1} #{e + 1}\"\nelse\n puts 'no'\nend\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nl = n\n(1...n).each do |i|\n if a[i] < a[i - 1] then\n l = i\n break\n end\nend\nif l == n then\n puts 'yes'\n puts '1 1'\nelse\n r = n\n (l...n).each do |i|\n if a[i] > a[i - 1] then\n r = i\n break\n end\n end\n flag = true\n (0...(l-1)).each do |i|\n if a[i] > a[r - 1] then\n flag = false\n break\n end\n end\n if flag then\n (r...n).each do |i|\n if a[i] < a[i - 1] || a[i] < a[l-1] then\n flag = false\n break\n end\n end\n end\n if flag then\n puts 'yes'\n puts l.to_s + ' ' + r.to_s\n else\n puts 'no'\n end\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = a.zip(b).index{|x, y| x != y} || 0\ne = a.zip(b).rindex{|x, y| x != y} || 0\na[s..e] = a[s..e].reverse\nif a == b\n puts 'yes', \"#{s + 1} #{e + 1}\"\nelse\n puts 'no'\nend\n\n"}, {"source_code": "n = gets.to_i;\narr = gets.chomp.split(' ').map(&:to_i);\nsorted = arr.sort;\n\nif (arr == sorted)\n puts \"yes\\n1 1\";\n exit;\nend\n\nleft = (0...n).find_index {|i| arr[i] != sorted[i]};\nright = (0...n).to_a.rindex {|i| arr[i] != sorted[i]};\n\narr = arr.first(left) + arr[left..right].reverse + arr.last(n - right - 1);\n\nif (arr == sorted)\n puts \"yes\\n#{left + 1} #{right + 1}\\n\";\nelse\n puts \"no\";\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort\ns = a.zip(b).index{|x, y| x != y} || 0\ne = a.zip(b).rindex{|x, y| x != y} || 0\na[s..e] = a[s..e].reverse\nif a == b\n puts 'yes', \"#{s + 1} #{e + 1}\"\nelse\n puts 'no'\nend\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split.map(&:to_i).unshift(0)\na[n+1]=1000000001\ni=1\nwhile ia[i+1]\n\ti+=1\nend\nif i==n\n\tputs \"yes\"\n\tputs \"1 1\"\nelse\n\tj=n\n\twhile j>1\n\t\tbreak if a[j]a[j+1]||a[i-1]>a[j]\n\t\tputs \"no\"\n\telse\n\t\tputs\"yes\"\n\t\tputs \"#{i} #{j}\"\n\tend\nend"}, {"source_code": "N = gets.to_i\narr = gets.chomp.split(' ').map(&:to_i)\nrra = arr.sort\n\nif rra == arr\n puts \"yes\\n1 1\"\n exit\nend\n\nl = ((0...arr.size).find_index {|i| arr[i] != rra[i]}).to_i\nr = ((0...arr.size).to_a.reverse.find {|i| arr[i] != rra[i]}).to_i\n\nbrr = []\nbrr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size - 1 - r)\n\nif brr == rra\n puts \"yes\"\n puts \"#{l + 1} #{r + 1}\"\nelse\n puts \"no\"\nend"}, {"source_code": "size = gets.to_i\n\nnumbers = gets.split(' ').map(&:to_i)\n\nsorted_array = numbers.sort\n\nif numbers == sorted_array\n puts 'yes'\n puts '1 1'\nelse\n i = 0\n j = size - 1\n\n while numbers[i] == sorted_array[i]\n i += 1\n\n break if i == size\n end\n\n while numbers[j] == sorted_array[j]\n j -= 1\n\n break if j == -1\n end\n\n numbers[i..j] = numbers[i..j].reverse\n\n if numbers == sorted_array\n puts 'yes'\n puts \"#{i + 1} #{j + 1}\"\n else\n puts 'no'\n end\nend\n"}], "negative_code": [{"source_code": "N = gets.to_i\narr = gets.chomp.split(' ').map(&:to_i)\n\nrra = arr.sort\n\nif rra == arr \n puts 'yes'\n puts '1 1'\n exit! 0\nend\n\nl = ((0...arr.size).find_index {|i| arr[i] != rra[i]}).to_i\nr = ((0...arr.size).to_a.reverse.find {|i| arr[i] != rra[i]}).to_i\n\nbrr = []\nbrr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size - 1 - r)\n\nif brr == rra\n puts 'yes'\n puts \"#{l + 1} #{r + 1}\"\nelse\n puts 'no'\nend"}, {"source_code": "N = gets.to_i\narr = gets.chomp.split(' ').map(&:to_i)\nrra = arr.sort\n\nif rra == arr\n puts \"yes\\n1 1\"\n exit\nend\n\nl = ((0...arr.size).find_index {|i| arr != rra[i]}).to_i\nr = ((0...arr.size).to_a.reverse.find {|i| arr[i] != rra[i]}).to_i\n\nbrr = []\nbrr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size - 1 - r)\n\nif brr == rra\n puts \"yes\"\n puts \"#{l + 1} #{r + 1}\"\nelse\n puts \"no\"\nend"}, {"source_code": "size = gets.to_i\n\nnumbers = gets.split(' ').map(&:to_i)\n\nsorted_array = numbers.sort\n\nif numbers == sorted_array\n puts 'yes'\n puts '1 1'\nelse\n i = 0\n j = size - 1\n\n while numbers[i] == sorted_array[i]\n i += 1\n end\n\n while numbers[j] == sorted_array[j]\n j -= 1\n end\n\n left_index = i\n right_index = j\n\n while left_index <= right_index\n break if numbers[i] != sorted_array[j]\n left_index +=1\n right_index -= 1\n end\n\n if left_index < right_index\n puts 'no'\n else\n puts 'yes'\n puts \"#{i + 1} #{j + 1}\"\n end\n\n # numbers[i..j] = numbers[i..j].reverse\n\n # if numbers == sorted_array\n # puts 'yes'\n # puts \"#{i + 1} #{j + 1}\"\n # else\n # puts 'no'\n # end\n\n\nend\n"}, {"source_code": "size = gets.to_i\n\nnumbers = gets.split(' ').map(&:to_i)\n\nsorted_array = numbers.sort\n\nif numbers == sorted_array\n puts 'yes'\n puts '1 1'\nelse\n i = 0\n j = size - 1\n\n while numbers[i] == sorted_array[i]\n i += 1\n end\n\n while numbers[j] == sorted_array[j]\n j -= 1\n end\n\n left_index = i\n right_index = j\n\n while left_index < right_index\n break if numbers[i] != numbers[j]\n left_index +=1\n right_index -= 1\n end\n\n if left_index < right_index\n puts 'no'\n else\n puts 'yes'\n puts \"#{i + 1} #{j + 1}\"\n end\n\n # numbers[i..j] = numbers[i..j].reverse\n\n # if numbers == sorted_array\n # puts 'yes'\n # puts \"#{i + 1} #{j + 1}\"\n # else\n # puts 'no'\n # end\n\n\nend\n"}, {"source_code": "size = gets.to_i\n\nnumbers = gets.split(' ').map(&:to_i)\n\nsorted_array = numbers.sort\n\nif numbers == sorted_array\n puts 'yes'\n puts '1 1'\nelse\n i = 0\n j = size - 1\n\n while numbers[i] == sorted_array[i]\n i += 1\n end\n\n while numbers[j] == sorted_array[j]\n j -= 1\n end\n\n left_index = i\n right_index = j\n\n not_sorted = false\n\n while left_index <= right_index\n if numbers[left_index] != sorted_array[right_index]\n not_sorted = true\n break\n end\n left_index +=1\n right_index -= 1\n end\n\n if not_sorted\n puts 'no'\n else\n puts 'yes'\n puts \"#{i + 1} #{j + 1}\"\n end\n\n # numbers[i..j] = numbers[i..j].reverse\n\n # if numbers == sorted_array\n # puts 'yes'\n # puts \"#{i + 1} #{j + 1}\"\n # else\n # puts 'no'\n # end\nend\n"}, {"source_code": "size = gets.to_i\n\nnumbers = gets.split(' ').map(&:to_i)\n\nsorted_array = numbers.sort\n\nif numbers == sorted_array\n puts 'yes'\n puts '1 1'\nelse\n i = 0\n j = size - 1\n\n while numbers[i] == sorted_array[i]\n i += 1\n end\n\n while numbers[j] == sorted_array[j]\n j -= 1\n end\n\n left_index = i\n right_index = j\n\n while left_index <= right_index\n break if numbers[i] != numbers[j]\n left_index +=1\n right_index -= 1\n end\n\n if left_index < right_index\n puts 'no'\n else\n puts 'yes'\n puts \"#{i + 1} #{j + 1}\"\n end\n\n # numbers[i..j] = numbers[i..j].reverse\n\n # if numbers == sorted_array\n # puts 'yes'\n # puts \"#{i + 1} #{j + 1}\"\n # else\n # puts 'no'\n # end\n\n\nend\n"}, {"source_code": "size = gets.to_i\n\nnumbers = gets.split(' ').map(&:to_i)\n\nsorted_array = numbers.sort\n\nif size == 1\n puts 'yes'\n puts '1 1'\nelse\n i = 0\n j = size\n\n while numbers[i] == sorted_array[i]\n i += 1\n end\n\n while numbers[j] == sorted_array[j]\n j -= 1\n end\n\n numbers[i..j] = numbers[i..j].reverse\n\n puts numbers == sorted_array ? 'yes' : 'no'\nend\n"}, {"source_code": "size = gets.to_i\n\nnumbers = gets.split(' ').map(&:to_i)\n\nsorted_array = numbers.sort\n\nif size == 1\n puts 'yes'\n puts '1 1'\nelse\n i = 0\n j = 1\n while i < size - 1\n b = numbers.dup\n b[i..j] = b[i..j].reverse!\n if b == sorted_array\n puts 'yes'\n puts \"#{i + 1} #{j + 1}\"\n break\n end\n j += 1\n if j == size\n i += 1\n j = i + 1\n end\n end\n puts 'no' if i >= size - 1\nend\n"}, {"source_code": "size = gets.to_i\n\nnumbers = gets.split(' ').map(&:to_i)\n\nsorted_array = numbers.sort\n\nif numbers == sorted_array\n puts 'yes'\n puts '1 1'\nelse\n i = 0\n j = size - 1\n\n while numbers[i] == sorted_array[i]\n i += 1\n end\n\n while numbers[j] == sorted_array[j]\n j -= 1\n end\n\n left_index = i\n right_index = j\n\n while left_index <= right_index\n break if numbers[left_index] != sorted_array[right_index]\n left_index +=1\n right_index -= 1\n end\n\n if left_index <= right_index\n puts 'no'\n else\n puts 'yes'\n puts \"#{i + 1} #{j + 1}\"\n end\n\n # numbers[i..j] = numbers[i..j].reverse\n\n # if numbers == sorted_array\n # puts 'yes'\n # puts \"#{i + 1} #{j + 1}\"\n # else\n # puts 'no'\n # end\nend\n"}, {"source_code": "n = gets.rstrip.to_i\narr = gets.rstrip.split(' ').map(&:to_i)\n\nl = 0\narr.each_with_index do |v, i|\n if arr[i + 1] && arr[i] > arr[i + 1]\n l = i\n break\n end\nend\n\nr = l\nwhile arr[l] >= arr[r] && r < arr.size - 1 do\n r += 1\nend\n\nr -= 1 if r != (arr.size - 1)\nr -= 1 if arr[r] > arr[l]\n\nsorted_arr = arr.sort\narr[l], arr[r] = arr[r], arr[l]\n\nif sorted_arr == arr\n puts 'yes'\n puts \"#{l + 1} #{r + 1}\"\nelse\n puts 'no'\nend\n"}, {"source_code": "n = gets.rstrip.to_i\narr = gets.rstrip.split(' ').map(&:to_i)\n\nl = 0\narr.each_with_index do |v, i|\n if arr[i + 1] && arr[i] > arr[i + 1]\n l = i\n break\n end\nend\n\nr = l\nwhile arr[l] >= arr[r] && r < arr.size - 1 do\n r += 1\nend\n\nr -= 1 if r != (arr.size - 1)\nr -= 1 if arr[r] > arr[l]\n\nsorted_arr = arr.sort\narr[l], arr[r] = arr[r], arr[l]\n\nif sorted_arr == arr\n puts 'yes'\n puts \"#{arr[l]} #{arr[r]}\"\nelse\n puts 'no'\nend\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nc=\"\"\narr=\"\"\nminP=0\nmaxP=0\n(x.size-1).times{|i|\n\ts=\"\"\n\tif x[i]0 then\n\t\tx1=x.slice(0..(minP-1))\n\t\tx2=x.slice(minP..maxP)\n\t\tif x1.max>x2.min then\n\t\t\tok=false\n\t\tend\n\tend\n\tif maxP<(x.size-1) then\n\t\tx1=x.slice(minP..maxP)\n\t\tx2=x.slice(maxP+1,x.size)\n\t\tif x1.max>x2.min then\n\t\t\tok=false\n\t\tend\n\tend\n\tif ok==false then\n\t\tputs \"no\"\n\telse\n\t\tputs \"yes\"\n\t\tputs [minP+1,maxP+1]*\" \"\n\tend\nelse\n\tputs \"no\"\nend\n\n"}, {"source_code": "n, k = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}"}, {"source_code": "length = gets.split.map{|_|_.to_i}\narray = gets.split.map{|_|_.to_i}\n\nsorted_array = array.sort\nstarted = -1\nended = -1\nswitch = 0\nindex = 0\n\nwhile index <= array.length\n if sorted_array[index] != array[index]\n if switch % 2 == 0\n started = index\n switch += 1\n else\n ended = index\n end\n end\n \n index += 1\nend\n\nif switch == 0 || sorted_array[started..ended] == array[started..ended].reverse\n puts \"yes\"\n puts [started + 1, ended + 1].join(\" \")\nelse\n puts \"no\"\nend"}, {"source_code": "length = gets.split.map{|_|_.to_i}\narray = gets.split.map{|_|_.to_i}\n\nsorted_array = array.sort\nstarted = -1\nended = -1\nswitch = 0\nindex = 0\n\nwhile index <= array.length\n if sorted_array[index] != array[index]\n if switch % 2 == 0\n started = index\n switch += 1\n else\n ended = index\n end\n end\n \n index += 1\nend\n\nif sorted_array[started..ended] == array[started..ended].reverse\n puts \"yes\"\n puts [started + 1, ended + 1].join(\" \")\nelse\n puts \"no\"\nend"}, {"source_code": "n = gets.chomp.to_i\nlist = gets.chomp.split.map(&:to_i)\n\nsorted_list = list.sort\n\nif sorted_list == list\n puts \"yes\"\n print 1, \" \", n\nelse\n diff_pos = []\n\n for i in 0..(n - 1)\n if list[i] != sorted_list[i]\n diff_pos << i\n end\n end\n\n l = diff_pos[0]\n r = diff_pos[-1]\n\n reverse_segment = list[l..r].dup\n\n for i in 0..((reverse_segment.length - 1)/ 2.0)\n temp = reverse_segment[i]\n reverse_segment[i] = reverse_segment[reverse_segment.length - 1 - i]\n reverse_segment[reverse_segment.length - 1 - i] = temp\n end\n\n list[l..r] = reverse_segment\n\n if list == sorted_list\n puts \"yes\"\n print l + 1, \" \", r + 1\n else\n puts \"no\"\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\nlist = gets.chomp.split.map(&:to_i)\n\ntemp_list = list.dup\nresult = []\n\nfor r in 0..(n - 1)\n for l in 0..r\n temp = list[r]\n list[r] = list[l]\n list[l] = temp\n if list == list.sort\n break result = [l + 1, r + 1]\n end\n end\n\n list = temp_list\nend\n\nif result.empty?\n puts \"no\"\nelse\n puts \"yes\"\n print result[0], \" \", result[1]\nend\n"}], "src_uid": "c9744e25f92bae784c3a4833c15d03f4"} {"source_code": "a=[*$<][1].chomp.split\nr='5'*(a.count('5')/9*9)+'0'*a.count('0')\nputs r.length>0&&r[-1]=='0'?r.to_i : -1\n", "positive_code": [{"source_code": "gets \na = gets.strip.split(' ').map(&:to_i)\n\nif a.select { |i| i.zero? }.size.zero?\n puts \"-1\"\n exit\nend\n\nsum = 0\ncount = 0\nmx = 0\na.each { |e|\n if e == 5\n sum += 5\n count += 1\n end\n if sum % 9 == 0\n mx = count\n end\n}\n\nif mx.zero?\n puts \"0\"\n exit\nend\nmx.times { print '5' }\n(a.size - count).times { print '0' }\nputs \"\"\n\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nif x.index(0) then\n\ty=x.count{|e|\n\t\te==5\n\t}\n\tz=x.size-y\n\twhile (y*50)%90!=0\n\t\ty-=1\n\tend\n\n\tif y==0 then\n\t\tputs 0\n\telse\n\t\t\n\t\ty.times{\n\t\t\tprint 5\t\n\t\t}\n\t\tz.times{\n\t\t\tprint 0\n\t\t}\n\t\tputs \"\"\n\tend\nelse\n\tputs -1\nend\n\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split\n\na_zero = a.count \"0\"\na_five = a.count \"5\"\n\nif a_five >= 9 && a_zero >= 1\n puts \"5\" * (a_five / 9 * 9) + \"0\" * a_zero\nelsif a_zero >= 1\n puts 0\nelse\n puts -1\nend\n\n\n"}, {"source_code": "n = gets.to_i\nhs = { 0 => 0, 5 => 0 }\ngets.split(' ').map{|x| hs[x.to_i] += 1}\nif hs[0] == 0\n puts -1\nelsif hs[5] >= 9\n puts \"5\" * ( hs[5] / 9 * 9 ) + \"0\" * hs[0]\nelse\n hs[0] > 0\n puts 0\nend"}, {"source_code": "cnt=[0]*6\na = $<.to_a[1].split.map(&:to_i)\na.each do |x|\n cnt[x] += 1\nend\nif cnt[5] >= 9 and cnt[0] > 0\n puts '5' * (cnt[5] - cnt[5] % 9) + '0' * cnt[0]\nelsif cnt[0] > 0\n puts '0'\nelse\n puts '-1'\nend\n"}, {"source_code": "c=[0]*6\n$<.to_a[1].split.map(&:to_i).each { |x| c[x] += 1 }\nputs (c[0] > 0) ? '5'*(c[5]-c[5]%9) + '0'*(c[5]>8?c[0]:1) : '-1'\n"}, {"source_code": "#!/usr/bin/ruby\nh=Hash.new(0)\ngets;gets.split.each{|e|h[e.to_i]+=1}\np h[0]>=1 ? ('5'*(h[5]/9*9)+'0'*h[0]).to_i : -1"}, {"source_code": "c=[0]*6\n$<.to_a[1].split.map(&:to_i).each{|x|c[x]+=1}\nputs (c[0]>0)?'5'*(c[5]-c[5]%9)+'0'*(c[5]>8?c[0]:1):'-1'"}, {"source_code": "c=Array.new(6,0)\n$<.to_a[1].split.map(&:to_i).each{|i|c[i]+=1}\na,b=c[0],c[5]-c[5]%9\nputs a==0?-1:(b==0?0:\"5\"*b+\"0\"*a)"}, {"source_code": "c=Array.new(6,0)\ngets\ngets.split.map(&:to_i).each{|i|c[i]+=1}\na,b=c[0],c[5]-c[5]%9\nif a == 0\n\tp (-1)\nelsif b == 0\n\tp 0\nelse\n\tputs \"5\"*b+\"0\"*a\nend"}, {"source_code": "n,res0,res5 = gets.chomp.to_i, 0, 0\na = gets.chomp.split.map(&:to_i)\na.each { |x| if x==5; res5+=1 else res0+=1 end }\nif res0>0; puts '5'*(res5/9*9)+'0'*(res5>8?res0:1) else puts '-1' end"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map{|e| e.to_i}\nc = Hash.new(0)\na.each{|e|\n c[e] += 1;\n}\n\nif c[5]/9 > 0 and c[0] > 0 then\n (c[5]/9 * 9).times{ print 5 }\n c[0].times{print 0}\nelsif c[0] > 0 \n print 0\nelse\n print -1\nend\nputs"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\nres0, res5 = 0, 0\na.each { |x| if x==5; res5+=1 else res0+=1 end }\nif res0>0\n puts '5'*(res5/9*9)+'0'*(res5>8?res0:1)\nelse\n puts '-1'\nend"}, {"source_code": "cnt = gets.to_i\ncards = gets.split\nn0 = n5 = 0\ncards.each {|c| \n\tif c == \"0\"\n\t\tn0 += 1\n\telse\n\t\tn5 += 1\n\tend\n}\nif n0 == 0\n\tprint -1\nelsif n5 < 9\n\tprint 0\nelse\n\tprint \"5\" * ((n5/9)*9) + \"0\" * n0\nend"}, {"source_code": "#! /usr/bin/env ruby\n\nn = STDIN.gets.to_i\nnumbers = STDIN.gets.to_s.split(' ').map(&:to_i)\n\nif numbers.length != n\n raise ArgumentError.new\nend\n\ndef check(numbers, n)\n if numbers.none?(&:zero?)\n return nil\n end\n numbers.sort!.reverse!\n\n while numbers.first == 5\n sum = numbers.count{|i| i == 5} * 5\n if sum % 9 == 0\n return numbers.join.to_i\n end\n numbers.shift\n end\n\n 0\nend\n\nanswer = check(numbers, n)\nif answer.nil?\n puts \"-1\"\nelse\n puts answer\nend\n\n"}, {"source_code": "f=gets.chomp.to_i\nz=gets.chomp.split(\" \").count('0')\nf=f-z\nif z==0 ||(f<9 && z==0)\nputs \"-1\"\nelsif f<9 && z>0\nputs \"0\"\nelse\np=\"555555555\"*(f/9)+(\"0\"*z) \nputs p\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |x| x.to_i }\n\nc0 = a.count 0\nc5 = a.count 5\n\nif c0 == 0\n\tputs -1\nelsif c5 < 9\n\tputs 0\nelse\n\tputs '5' * (c5 / 9 * 9) + '0' * c0\nend"}], "negative_code": [{"source_code": "n = gets.to_i\nhs = { 0 => 0, 5 => 0 }\ngets.split(' ').map{|x| hs[x.to_i] += 1}\nif hs[5] >= 9\n puts \"5\" * ( hs[5] / 9 * 9 ) + \"0\" * hs[0]\nelsif\n hs[0] > 0\n puts 0\nelse\n puts -1\nend"}, {"source_code": "#!/usr/bin/ruby\nh=Hash.new(0)\ngets;gets.split.each{|e|h[e.to_i]+=1}\nputs h[0]>=1&&h[5]>=9 ? '5'*(h[5]/9*9)+'0'*h[0] : 0\n"}, {"source_code": "#!/usr/bin/ruby\nh=Hash.new(0)\ngets;gets.split.each{|e|h[e.to_i]+=1}\nputs h[0]>=1 ? '5'*(h[5]/9*9)+'0'*h[0] : -1"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\nres0, res5 = 0, 0\na.each { |x| if x==5; res5+=1 else res0+=1 end }\nputs '5'*(res5/3*3)+'0'*(res5>2?res0:1)"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\nres0, res5 = 0, 0\na.each { |x| if x==5; res5+=1 else res0+=1 end }\nif res0>0\n puts '5'*(res5/3*3)+'0'*(res5>2?res0:1)\nelse\n puts '-1'\nend"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\nres0, res5 = 0, 0\na.each { |x| if x==5; res5+=1 else res0+=1 end }\nputs '5'*(res5/5*5)+'0'*res0"}, {"source_code": "cnt = gets.to_i\ncards = gets.split\nn0 = n5 = 0\ncards.each {|c| \n\tif c == \"0\"\n\t\tn0 += 1\n\telse\n\t\tn5 += 1\n\tend\n}\nif n0 == 0\n\tprint -1\nelsif n5 < 9\n\tprint 0\nelse\n\tprint \"9\" * ((n5/9)*9) + \"0\" * n0\nend"}, {"source_code": "gets \na = gets.strip.split(' ').map(&:to_i)\n\nif a.select { |i| i.zero? }.size.zero?\n puts \"-1\"\n exit\nend\n\nsum = 0\ncount = 0\nmx = 0\na.each { |e|\n if e == 5\n sum += 5\n count += 1\n end\n if sum % 9 == 0\n mx = count\n end\n}\n\nmx.times { print '5' }\n(a.size - count).times { print '0' }\nputs \"\"\n\n"}, {"source_code": "gets \na = gets.strip.split(' ').map(&:to_i)\n\nif a.select { |i| i.zero? }.size.zero?\n puts \"-1\"\n exit\nend\n\nsum = 0\ncount = 0\nmx = 0\na.each { |e|\n if e == 5\n sum += 5\n count += 1\n end\n if sum % 9 == 0\n mx = count\n end\n}\n\nmx.times { print '5' }\nputs '0'\n\n"}, {"source_code": "gets \na = gets.strip.split(' ').map(&:to_i)\n\nif a.select { |i| i.zero? }.size.zero?\n puts \"-1\"\n exit\nend\n\nif a.select { |i| i.zero? }.size == 0\n puts \"0\"\n exit\nend\n\nsum = 0\ncount = 0\nmx = 0\na.each { |e|\n if e == 5\n sum += 5\n count += 1\n end\n if sum % 9 == 0\n mx = count\n end\n}\n\nmx.times { print '5' }\n(a.size - count).times { print '0' }\nputs \"\"\n\n"}, {"source_code": "a=[*$<][1].chomp.split\nr='5'*(a.count('5')/9*9)+'0'*a.count('0')\nputs r.length>0?r.to_i : -1\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split\n\na_zero = a.count \"0\"\na_five = a.count \"5\"\n\ns = \"\"\ndivideds = []\n(0..1000).each do |i|\n s_zero = (s + \"0\")\n s_five = (s + \"5\")\n if s_zero.to_i % 90 == 0 and \n s_zero.count(\"0\") <= a_zero and\n s_zero.count(\"5\") <= a_five then\n divideds << s_zero\n end\n if s_five.to_i % 90 == 0 and\n s_five.count(\"0\") <= a_zero and\n s_five.count(\"5\") <= a_five then\n divideds << s_five\n end\n s += \"5\"\nend\n\nans = divideds.sort[-1]\nputs ans ? ans : -1\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split\n\na_five = a.count \"5\"\na_zero = a.count \"0\"\n\ns = \"\"\ndivideds = []\n(0...a_five).each do |i|\n if (s+\"0\").to_i % 90 == 0\n divideds << (s+\"0\").to_i\n end\n if (s+\"5\").to_i % 90 == 0 \n divideds << (s+\"5\").to_i\n end\n s += \"5\"\nend\n\nans = divideds.reject{|i| i % 90 != 0}.sort[-1]\nif ans \n puts ans\nelse \n puts -1\nend\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split\n\na_zero = a.count \"0\"\na_five = a.count \"5\"\n\nif a_five >= 9 and a_zero >= 1\n puts \"5\" * a_five + \"0\" * a_zero\nelsif a_zero >= 1\n puts 0\nelse\n puts -1\nend\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split\n\na_zero = a.count \"0\"\na_five = a.count \"5\"\n\ns = \"\"\ndivideds = []\n(0...1000).each do |i|\n s_zero = (s + \"0\")\n s_five = (s + \"5\")\n if s_zero.to_i % 90 == 0 and \n s_zero.count(\"0\") <= a_zero and\n s_zero.count(\"5\") <= a_five then\n divideds << s_zero\n end\n if s_five.to_i % 90 == 0 and\n s_five.count(\"0\") <= a_zero and\n s_five.count(\"5\") <= a_five then\n divideds << s_five\n end\n s += \"5\"\nend\n\nans = divideds.sort[-1]\nputs ans ? ans : -1\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split\n\na_zero = a.count \"0\"\na_five = a.count \"5\"\n\nif a_five >= 9 and a_zero >= 1\n puts (\"5\" * a_five + \"0\" * a_zero).gsub(\"000000000\",\"555555555\")\nelsif a_zero >= 1\n puts 0\nelse\n puts -1\nend\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split\n\na_five = a.count \"5\"\na_zero = a.count \"0\"\n\ns = \"\"\ndivideds = []\n(0...a_five).each do |i|\n if (s+\"0\").to_f % 90 == 0\n divideds << (s+\"0\").to_i\n end\n if (s+\"5\").to_f % 90 == 0 \n divideds << (s+\"5\").to_i\n end\n s += \"5\"\nend\n\nans = divideds.reject{|i| i % 90 != 0}.sort[-1]\nif ans \n puts ans\nelse \n puts -1\nend\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split\n\na_zero = a.count \"0\"\na_five = a.count \"5\"\n\nif a_five >= 9\n puts \"5\" * (a_five / 9 * 9) + \"0\" * a_zero\nelsif a_zero >= 1\n puts 0\nelse\n puts -1\nend\n\n\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split\n\na_zero = a.count \"0\"\na_five = a.count \"5\"\n\nif a_five >= 9\n puts \"5\" * (a_five / 9) + \"0\" * a_zero\nelsif a_zero >= 1\n puts 0\nelse\n puts -1\nend\n\n\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split\n\na_zero = a.count \"0\"\na_five = a.count \"5\"\n\ns = \"\"\ndivideds = []\n(0...a_five).each do |i|\n s_zero = (s + \"0\")\n s_five = (s + \"5\")\n if s_zero.to_i % 90 == 0 and \n s_zero.count(\"0\") <= a_zero and\n s_five.count(\"5\") <= a_five then\n divideds << s_zero\n end\n if s_five.to_i % 90 == 0 and\n s_zero.count(\"0\") <= a_zero and\n s_five.count(\"5\") <= a_five then\n divideds << s_five\n end\n s += \"5\"\nend\n\nans = divideds.sort[-1]\nif ans \n puts ans\nelse \n puts -1\nend\n"}, {"source_code": "cnt=[0]*6\na = $<.to_a[1].split.map(&:to_i)\na.each do |x|\n cnt[x] += 1\nend\nif cnt[5] >= 9\n puts '5' * (cnt[5] - cnt[5] % 9) + '0' * cnt[0]\nelsif cnt[0] > 0\n puts '0'\nelse\n puts '-1'\nend\n"}, {"source_code": "cnt=[0]*6\na = $<.to_a[1].split.map(&:to_i)\na.each do |x|\n cnt[x] += 1\nend\nif cnt[5] >= 9\n puts '5' * (cnt[5] - cnt[5] % 9) + '0' * cnt[0]\nelsif cnt[0]\n puts '0'\nelse\n puts '-1'\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map{|e| e.to_i}\nc = Hash.new(0)\na.each{|e|\n c[e] += 1;\n}\n\nif c[5]/9 > 0 and c[0] > 0 then\n c[5]/9.times{\n print 5\n }\n puts 0\nelse\n puts 0\nend"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map{|e| e.to_i}\nc = Hash.new(0)\na.each{|e|\n c[e] += 1;\n}\n\nif c[5]/9 > 0 and c[0] > 0 then\n c[5]/9.times{\n print 5\n }\n puts 0\nelse\n puts -1\nend"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map{|e| e.to_i}\nc = Hash.new(0)\na.each{|e|\n c[e] += 1;\n}\n\nif c[5]/9 > 0 and c[0] > 0 then\n c[5]/9.times{\n print 5\n }\n puts 0\nelsif c[0] > 0 \n puts 0\nelse\n puts -1\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map { |x| x.to_i }\n\nc0 = a.count 0\nc5 = a.count 5\n\nif c0 == 0 and c5 < 9\n\tputs -1\nelsif c5 < 9\n\tputs 0\nelse\n\tputs '5' * (c5 / 9 * 9) + '0' * c0\nend"}], "src_uid": "409b27044d5ec97b5315c92d4112376f"} {"source_code": "at_exit do\n vertex_count, edge_count = get_numbers_from_line[0..1]\n linked_count = [0]*vertex_count\n edge_count.times do\n x,y = get_numbers_from_line[0..1]\n linked_count[x-1] += 1\n linked_count[y-1] += 1\n end\n\n counts = {}\n linked_count.each do |count|\n counts[count] ||= 0\n counts[count] += 1\n end\n one_count = counts[1] || 0\n two_count = counts[2] || 0\n\n if one_count == 2 && two_count == vertex_count - 2 && edge_count == vertex_count-1\n puts 'bus topology'\n elsif one_count == 0 && two_count == vertex_count && edge_count == vertex_count\n puts 'ring topology'\n elsif one_count == vertex_count-1 && counts[vertex_count-1] == 1 && edge_count == vertex_count - 1\n puts 'star topology'\n else\n puts 'unknown topology'\n end\n\nend\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend", "positive_code": [{"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(number1, number2)\n if vertices[number1].nil? then\n vertices[number1] = List.new(number2, nil)\n else\n vertices[number1] = List.new(number2, vertices[number1])\n end\n end\n\n def print_edges \n vertices.each_with_index do |vertex, index| \n # next if vertex == \"\"\n while !vertex.nil? do \n puts \"edge #{index} - #{vertex.element}\"\n vertex = vertex.next_elem \n end \n end \n end \n\nend \n\nnetwork = Graph.new([])\nn, m = gets.strip.split(\" \").map(&:to_i)\nnumber_of_connected_vertices = Array.new(n, 0)\nm.times do \n vertex1, vertex2 = gets.strip.split(\" \").map{|num| num.to_i - 1}\n network.add_edge(vertex1, vertex2)\n network.add_edge(vertex2, vertex1)\n number_of_connected_vertices[vertex2] += 1\n number_of_connected_vertices[vertex1] += 1\nend\nresults = number_of_connected_vertices.group_by{|i| i}\nif results[n - 1] && results[n - 1].count == 1 &&\n results[1] && results[1].count == n - 1\n answer = 'star topology'\nelsif results[1] && results[1].count == 2 &&\n results[2] && results[2].count == n - 2\n answer = 'bus topology'\nelsif results[2] && results[2].count == n\n answer = 'ring topology'\nelse\n answer = 'unknown topology'\nend\nputs answer\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\n\nedges = m.times.map{ gets.split.map(&:to_i) }\nv = n.times.map{ 0 }\n\nif m == n\n edges.each do |e|\n v[e[0] - 1] += 1\n v[e[1] - 1] += 1\n if v[e[1] - 1] > 2 || v[e[0] - 1] >2\n puts 'unknown topology'\n exit\n end\n end\n puts 'ring topology'\n exit\nelsif m + 1 == n\n edges.each do |e|\n v[e[0] - 1] += 1\n v[e[1] - 1] += 1\n end\n v.sort!\n if v[0] == 1 && v[1] == 1 && v[2] == 2\n puts 'bus topology'\n exit\n elsif v[-1] == m\n puts 'star topology'\n exit\n end\nend\n\nputs 'unknown topology'\n"}, {"source_code": "begin\n input = gets.chomp.split(\" \")\n n = input[0].to_i\n m = input[1].to_i\n\n v1s = []\n v2s = []\n\n count_arr = []\n\n edges = []\n\n twos = 0\n nontwos = 0\n\n m.times do |i|\n input = gets.chomp.split(\" \")\n\n v1 = input[0].to_i\n v2 = input[1].to_i\n\n v1s << v1\n v2s << v2\n\n count_arr[v1] ||= 0\n count_arr[v2] ||= 0\n\n count_arr[v1] += 1\n count_arr[v2] += 1\n\n if count_arr[v1] == m || count_arr[v2] == m\n puts \"star topology\"\n abort\n end\n edges << i\n end\n\n count_arr.compact!\n\n count_arr.each do |el|\n if el == 2\n twos += 1\n else\n if el > 2\n puts \"unknown topology\"\n abort\n else\n nontwos += 1\n end\n end\n end\n\n if (twos == count_arr.size - 2) && (nontwos == 2)\n puts \"bus topology\"\n abort\n end\n\n if n == m\n puts \"ring topology\"\n abort\n end\n\n puts \"unknown topology\"\nrescue Exception\nend\n"}], "negative_code": [], "src_uid": "7bb088ce5e4e2101221c706ff87841e4"} {"source_code": "T = gets.to_i\nT.times do\n n,s,t = gets.split.map(&:to_i)\n a = s+t-n\n t = [s-a,t-a].sort\n p t[1]+1\nend", "positive_code": [{"source_code": "gets.to_i.times {\n n, s, t = gets.split.map &:to_i\n p [n - s + 1, n - t + 1].max\n}\n"}, {"source_code": "T = gets.to_i\nT.times do\n\tn, s, t = gets.split.map(&:to_i)\n\ts, t = t, s if s < t\n\tif s + t <= n\n\t\tputs s + 1\n\telsif\n\t\tcross = s + t - n\n\t\tputs s + 1 - cross\n\tend\nend\n"}], "negative_code": [{"source_code": "T = gets.to_i\nT.times do\n n,s,t = gets.split.map(&:to_i)\n a = s+t-n\n t = [a,s-a,t-a].sort\n ans = t[0]+t[1]+1\n p [ans,n].min\nend"}], "src_uid": "fb0a4c8f737c36596c2d8c1ae0d1e34e"} {"source_code": "name,taxi,girls,pizza,maxt,maxp,maxg=[],[],[],[],0,0,0\nn=gets.to_i\nn.times do |i|\n\ttaxi[i],pizza[i],girls[i]=0,0,0\n\tt,name[i]=gets.chomp.split\n\tt=t.to_i\n\tt.times do |j|\n\t\tstr=gets.chomp.delete('-').split('')\n\t\tif str.uniq.count==1\n\t\t\ttaxi[i]+=1\n\t\telsif str[0]>str[1] && str[1]>str[2] && str[2]>str[3] && str[3]>str[4] && str[4]>str[5]\n\t\t\tpizza[i]+=1\n\t\telse\n\t\t\tgirls[i]+=1\n\t\tend\n\tend\nend\nmaxt,maxg,maxp=taxi.max,girls.max,pizza.max\nprint \"If you want to call a taxi, you should call: \"\npost=0\nfor i in 0...n\n\tif maxt==taxi[i]\n\t\tpost+=1\n\t\tprint (post==1) ? name[i] : \", #{name[i]}\"\n\tend\nend\nputs \".\"\nprint \"If you want to order a pizza, you should call: \"\npost=0\nfor i in 0...n\n\tif maxp==pizza[i]\n\t\tpost+=1\n\t\tprint (post==1) ? name[i] : \", #{name[i]}\"\n\tend\nend\nputs \".\"\nprint \"If you want to go to a cafe with a wonderful girl, you should call: \"\npost=0\nfor i in 0...n\n\tif maxg==girls[i]\n\t\tpost+=1\n\t\tprint (post==1) ? name[i] : \", #{name[i]}\"\n\tend\nend\nputs \".\"", "positive_code": [{"source_code": "n = gets.to_i\na = []\nArray.new(n) do\n m, w = gets.split\n b = [0, 0, 0, w]\n m.to_i.times do\n s = gets.gsub(/\\D/, '')\n if s =~ /^(.)\\1*$/\n b[0] += 1\n elsif s.chars.to_a.sort.uniq * '' == s.reverse\n b[1] += 1\n else\n b[2] += 1\n end\n end\n a << b\nend\nb = ['call a taxi', 'order a pizza', 'go to a cafe with a wonderful girl']\n\n3.times do |i|\n c = a.map{|_| _[i]}.max\n d = a.select{|_| _[i] == c}.map{|_| _[3]}\n puts \"If you want to #{b[i]}, you should call: #{d * ', '}.\"\nend\n"}, {"source_code": "n=gets.to_i\nshop=[]\ntaxi=[]\nmax=[0,0,0]\n10.times{|k|\n taxi.push(k.to_s*6)\n}\nn.times{\n res=[0,0,0]\n k,name=gets.split\n k.to_i.times{\n a1,a2,a3=gets.split[0].split('-')\n t=a1+a2+a3\n if taxi.include?(t)\n res[0]+=1\n else\n v=Array.new(6){0}\n 6.times{|i| v[i]=t[i].to_i }\n ok=true\n 5.times{|i|\n ok=false if v[i]<=v[i+1]\n }\n if ok\n res[1]+=1\n else\n res[2]+=1\n end\n end\n }\n 3.times{|i|\n max[i]=[max[i],res[i]].max\n }\n shop.push([name,res])\n}\noutput=[\"If you want to call a taxi, you should call: \", \"If you want to order a pizza, you should call: \",\"If you want to go to a cafe with a wonderful girl, you should call: \"]\n3.times{|k|\n print output[k]\n start=true\n shop.each{|t|\n if (t[1][k]==max[k]) then\n print \", \" unless start\n start=false\n print t[0]\n end\n }\n puts \".\"\n}\n"}, {"source_code": "#! /usr/bin/env ruby\n\nt = gets.chomp.to_i\nd = {}\nname_list = []\n(1..t).each do |x|\n n, name = gets.chomp.split\n n = n.to_i\n d[name] = {}\n name_list << name\n d[name]['taxi'] = 0\n d[name]['pizza'] = 0\n d[name]['girl'] = 0\n (1..n).each do |y|\n num = gets.chomp.split(\"-\")\n if num.uniq.size == 1 and num.uniq.first.split(//).uniq.size == 1\n d[name]['taxi'] = (d[name]['taxi'] || 0) + 1\n elsif num.join.split(//).map(&:to_i) == num.join.split(//).map(&:to_i).sort.reverse.uniq\n d[name]['pizza'] = (d[name]['pizza'] || 0) + 1\n else\n d[name]['girl'] = (d[name]['girl'] || 0) + 1\n end\n end\nend\nmax_taxi = d.keys.map { |i| [d[i]['taxi'] || 0, i] }.sort.max.first\nmax_pizza = d.keys.map { |i| [d[i]['pizza'] || 0, i] }.sort.max.first\nmax_girl = d.keys.map { |i| [d[i]['girl'] || 0, i] }.sort.max.first\ntaxi = name_list.select {|i| d[i]['taxi'] == max_taxi }.join(\", \") + \".\"\npizza = name_list.select {|i| d[i]['pizza'] == max_pizza }.join(\", \") + \".\"\ngirl = name_list.select {|i| d[i]['girl'] == max_girl }.join(\", \") + \".\"\nprint (\"If you want to call a taxi, you should call: \" + taxi +\"\\n\").to_s\nprint (\"If you want to order a pizza, you should call: \" + pizza +\"\\n\").to_s\nprint (\"If you want to go to a cafe with a wonderful girl, you should call: \" + girl +\"\\n\").to_s\n"}, {"source_code": "#! /usr/bin/env ruby\n\ndef type_of_phone_number(number)\n return :taxi if number.uniq.size.equal? 1\n return :pizza if number.each_cons(2).all? {|x, y| x > y}\n return :girl\nend\n\nd = {}\nk = [:taxi, :pizza, :girl]\nk.each {|x| d[x] = [0, []]}\n\ngets.to_i.times do |x|\n n, name = gets.chomp.split\n numbers = n.to_i.times.map {type_of_phone_number(gets.scan(/[0-9]/).map(&:to_i))}\n k.each do |x|\n if numbers.count(x) > d[x].first\n d[x] = [numbers.count(x), [name]]\n elsif numbers.count(x) == d[x].first\n d[x].last << name\n end\n end\nend\n\nputs \"If you want to call a taxi, you should call: %s.\" %(d[:taxi][1] * \", \")\nputs \"If you want to order a pizza, you should call: %s.\" %(d[:pizza][1] * \", \")\nputs \"If you want to go to a cafe with a wonderful girl, you should call: %s.\" %(d[:girl][1] * \", \")\n"}, {"source_code": "#! /usr/bin/env ruby\n\nt = gets.chomp.to_i\nd = {}\nname_list = []\n(1..t).each do |x|\n n, name = gets.chomp.split\n n = n.to_i\n d[name] = {}\n name_list << name\n d[name]['taxi'], d[name]['pizza'], d[name]['girl'] = 0, 0, 0\n (1..n).each do |y|\n num = gets.chomp.split(\"-\")\n if num.uniq.size == 1 and num.uniq.first.split(//).uniq.size == 1\n d[name]['taxi'] = d[name]['taxi'] + 1\n elsif num.join.split(//).map(&:to_i) == num.join.split(//).map(&:to_i).sort.reverse.uniq\n d[name]['pizza'] = d[name]['pizza'] + 1\n else\n d[name]['girl'] = d[name]['girl'] + 1\n end\n end\nend\n\nmax_taxi = d.keys.map { |i| [d[i]['taxi'], i] }.sort.max.first\nmax_pizza = d.keys.map { |i| [d[i]['pizza'], i] }.sort.max.first\nmax_girl = d.keys.map { |i| [d[i]['girl'], i] }.sort.max.first\n\ntaxi = name_list.select {|i| d[i]['taxi'] == max_taxi }.join(\", \") + \".\"\npizza = name_list.select {|i| d[i]['pizza'] == max_pizza }.join(\", \") + \".\"\ngirl = name_list.select {|i| d[i]['girl'] == max_girl }.join(\", \") + \".\"\n\nprint (\"If you want to call a taxi, you should call: \" + taxi +\"\\n\").to_s\nprint (\"If you want to order a pizza, you should call: \" + pizza +\"\\n\").to_s\nprint (\"If you want to go to a cafe with a wonderful girl, you should call: \" + girl +\"\\n\").to_s\n"}, {"source_code": "\ufeffrequire 'set'\n\ndef is_taxi(s)\n tmp = s.split(\"\").select{|c| c != '-'}\n set = Set.new tmp\n set.length == 1\nend\n\ndef is_pizza(s)\n flag = true\n tmp = nil\n s.split(\"\").each do |c|\n if c != '-'\n if tmp == nil\n tmp = c.to_i\n else\n if tmp <= c.to_i\n flag = false\n break\n else\n tmp = c.to_i\n end\n end\n end\n end\n flag\nend\n\ndef max_names(hash)\n max = hash.values.max\n names = hash.select{ |k, v|\n v == max\n }\n names.keys.join ', '\nend\n\n\nn = gets.chomp.to_i\n\ntaxi = {}\npizza = {}\ngirl = {}\n\nn.times do\n tmp = gets.chomp.split \" \"\n s = tmp[0].to_i\n name = tmp[1]\n \n taxi[name] = 0\n pizza[name] = 0\n girl[name] = 0\n \n s.times do\n tmp2 = gets.chomp\n if is_taxi(tmp2)\n taxi[name] += 1\n elsif is_pizza(tmp2)\n pizza[name] += 1\n else\n girl[name] += 1\n end\n end\nend\n\nputs \"If you want to call a taxi, you should call: \" + max_names(taxi) + \".\"\nputs \"If you want to order a pizza, you should call: \" + max_names(pizza) + \".\"\nputs \"If you want to go to a cafe with a wonderful girl, you should call: \" + max_names(girl) + \".\"\n\n\n"}, {"source_code": "def pizza?(num)\n num = num.gsub(/-/,'').chars.map(&:to_i)\n prev = 10\n num.each do |n|\n if prev > n\n prev = n\n else\n return false\n end\n end\n true\nend\n\ndef taxi?(num)\n a = num[0]\n num.gsub(/[#{a}\\-]/,'').size.zero?\nend\n\ndef girl?(num)\n !taxi?(num) && !pizza?(num)\nend\n\ndef which(num)\n return :taxi if taxi?(num)\n return :pizza if pizza?(num)\n return :girl\nend\n\ndics = {}\nn = STDIN.gets.chomp.to_i\nn.times do\n i, name = STDIN.gets.chomp.split(/ /)\n i = i.to_i\n dics[name] = {taxi: 0, pizza: 0, girl: 0}\n\n i.times do\n num = STDIN.gets.chomp\n dics[name][which(num)] += 1\n end\nend\n\n{taxi: \"If you want to call a taxi, you should call: \",\n pizza: \"If you want to order a pizza, you should call: \",\n girl: \"If you want to go to a cafe with a wonderful girl, you should call: \"}.each do |type, head|\n max = dics.map{|k,v| v[type] }.max\n puts head+dics.select{|k,v| v[type] == max }.keys.join(\", \")+\".\"\nend\n"}, {"source_code": "n = gets.to_i\na = []\nArray.new(n) do\n m, w = gets.split\n b = [0, 0, 0, w]\n m.to_i.times do\n s = gets.gsub(/\\D/, '')\n if s =~ /^(.)\\1*$/\n b[0] += 1\n elsif s.chars.to_a.sort.uniq * '' == s.reverse\n b[1] += 1\n else\n b[2] += 1\n end\n end\n a << b\nend\nb = ['call a taxi', 'order a pizza', 'go to a cafe with a wonderful girl']\n\n3.times do |i|\n c = a.map{|_| _[i]}.max\n d = a.select{|_| _[i] == c}.map{|_| _[3]}\n puts \"If you want to #{b[i]}, you should call: #{d * ', '}.\"\nend"}, {"source_code": "n = gets.to_i\npb = []\nn.times do |i|\n a = [i]\n c,nm = gets.split\n a << nm\n h = Hash.new(0)\n c.to_i.times do\n pn = gets.strip.gsub(/-/,\"\").split(//)\n pn.uniq.sort.reverse\n if pn.uniq.size == 1\n h[:t] += 1\n elsif pn.uniq.sort.reverse == pn\n h[:p] += 1\n else\n h[:g] += 1\n end\n end\n a << h\n pb << a\nend\n\nmx = pb.map{|a| a[2][:t]}.max\ntx = pb.select{|a| a[2][:t] == mx }\n\n\nmx = pb.map{|a| a[2][:p]}.max\npz = pb.select{|a| a[2][:p] == mx }\n\nmx = pb.map{|a| a[2][:g]}.max\ngf = pb.select{|a| a[2][:g] == mx }\n\nputs \"If you want to call a taxi, you should call: #{tx.map{|a| a[1]}.join(\", \")}.\"\nputs \"If you want to order a pizza, you should call: #{pz.map{|a| a[1]}.join(\", \")}.\"\nputs \"If you want to go to a cafe with a wonderful girl, you should call: #{gf.map{|a| a[1]}.join(\", \")}.\"\n"}, {"source_code": "#!/usr/bin/ruby\nclass Number\n def initialize\n @mas=Array.new(6)\n end\n def mas\n @mas\n end\n def mas=(mas)\n @mas=mas\n end\n def isPizza()\n return @mas==@mas.uniq() && @mas==@mas.sort{|a,b| b<=>a}\n end\n def isTaxi()\n return @mas.uniq().size()==1\n end\nend\nclass Person\n def initialize\n @name=String.new\n @taxiElements=0\n @girlElements=0\n @pizzaElements=0\n @numberArray=[]\n end\n def taxiElements\n @taxiElements\n end\n def pizzaElements\n @pizzaElements\n end\n def girlElements\n @girlElements\n end\n def name\n @name\n end\n def name=(name)\n @name=name\n end\n def numberArray\n @numberArray\n end\n def numberArray=(numberArray)\n @numberArray=numberArray\n end\n def countElements()\n for i in 0..(@numberArray.size()-1)\n element=@numberArray[i]\n if element.isTaxi()\n @taxiElements=@taxiElements+1\n elsif (element.isPizza())\n @pizzaElements=@pizzaElements+1\n else\n @girlElements=@girlElements+1\n end\n end\n end\nend\n\nrequire 'scanf'\ncount=(scanf(\"%d\\n\"))[0]\narray=Array.new(count)\nfor i in 0..(count-1)\n array[i]=Person.new\n temp=scanf(\"%d %s\\n\")\n elements=temp[0]\n array[i].name=temp[1]\n array[i].numberArray=Array.new(elements)\n for j in 0..(elements-1) \n array[i].numberArray[j]=Number.new \n array[i].numberArray[j].mas=scanf(\"%c%c-%c%c-%c%c\\n\") \n end \n \nend\n\narray.each do |i|\n i.countElements()\nend\nmaxPizza=(array.map{|x|x.pizzaElements}).max\nmaxTaxi=(array.map{|x|x.taxiElements}).max\nmaxGirl=(array.map{|x|x.girlElements}).max\noutTaxi=\"If you want to call a taxi, you should call: \"\noutPizza=\"If you want to order a pizza, you should call: \"\noutGirl=\"If you want to go to a cafe with a wonderful girl, you should call: \"\nwasTaxi=false\nwasPizza=false\nwasGirl=false\narray.each do |i|\n if i.taxiElements==maxTaxi\n if wasTaxi\n outTaxi+=\", \"\n end\n wasTaxi=true\n outTaxi+=i.name\n end\n if i.pizzaElements==maxPizza\n if wasPizza\n outPizza+=\", \"\n end\n wasPizza=true\n outPizza+=i.name\n end\n if i.girlElements==maxGirl\n if wasGirl\n outGirl+=\", \"\n end\n wasGirl=true\n outGirl+=i.name\n end\nend\noutTaxi+=\".\"\noutPizza+=\".\"\noutGirl+=\".\"\nputs outTaxi\nputs outPizza\nputs outGirl\n"}, {"source_code": "n = gets.to_i\nCON = [:taxi,:pizza,:girl]\nfriends = []\nnames = []\nn.times do\n\tm,name = gets.chomp.split(\" \")\n\tnames << name\n\tm = m.to_i\n\tnos = Hash.new(0)\n\tm.times do\n\t\tans = nil\n\t\tx,y,z = gets.chomp.split(\"-\")\n\t\ta,b,c = x.to_i,y.to_i,z.to_i\n\t\tarr = [x.split(''),y.split(''),z.split('')].flatten\n\n\t\t# puts \"#{one} #{two} #{three} #{four} #{five} #{six}\"\n\t\t# puts \"#{b} #{c}\"\n\t\t# puts \"#{(one.to_i > two.to_i) && (three.to_i > four.to_i) && (five.to_i > six.to_i)}\"\n\t\tif a == b && b == c && arr.each_cons(2).all?{|l,m| l == m}\n\t\t\tans = CON[0]\n\t\telsif a > b && b > c && arr.each_cons(2).all?{|l,m| l > m}\n\t\t\tans = CON[1]\n\t\telse\n\t\t\tans = CON[2]\n\t\tend\n\t\tnos[ans] += 1\n\tend\n\tfriends << nos\nend\ntaxi = []\npizza = []\ngirl = []\n# puts \"#{friends}\"\nfriends.each_with_index do |f,i|\n\ttaxi[i] = f[CON[0]]\n\tpizza[i] = f[CON[1]]\n\tgirl[i] = f[CON[2]]\nend\n\nlist = []\nmax = taxi.max\ntaxi.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to call a taxi, you should call: #{list.join(', ')}.\"\n\n\nlist = []\nmax = pizza.max\npizza.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to order a pizza, you should call: #{list.join(', ')}.\"\n\nlist = []\nmax = girl.max\ngirl.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to go to a cafe with a wonderful girl, you should call: #{list.join(', ')}.\"\n\n\n\n# "}, {"source_code": "n = gets.to_i\nCON = [:taxi,:pizza,:girl]\nfriends = []\nnames = []\nn.times do\n\tm,name = gets.chomp.split(\" \")\n\tnames << name\n\tm = m.to_i\n\tnos = Hash.new(0)\n\tm.times do\n\t\tans = nil\n\t\tx,y,z = gets.chomp.split(\"-\")\n\t\ta,b,c = x.to_i,y.to_i,z.to_i\n\t\tarr = [x.split(''),y.split(''),z.split('')].flatten\n\n\t\t# puts \"#{one} #{two} #{three} #{four} #{five} #{six}\"\n\t\t# puts \"#{b} #{c}\"\n\t\t# puts \"#{(one.to_i > two.to_i) && (three.to_i > four.to_i) && (five.to_i > six.to_i)}\"\n\t\tif a == b && b == c && arr.each_cons(2).all?{|l,m| l == m}\n\t\t\tans = CON[0]\n\t\telsif a > b && b > c && arr.each_cons(2).all?{|l,m| l > m}\n\t\t\tans = CON[1]\n\t\telse\n\t\t\tans = CON[2]\n\t\tend\n\t\tnos[ans] += 1\n\tend\n\tfriends << nos\nend\ntaxi = []\npizza = []\ngirl = []\n# puts \"#{friends}\"\nfriends.each_with_index do |f,i|\n\ttaxi[i] = f[CON[0]]\n\tpizza[i] = f[CON[1]]\n\tgirl[i] = f[CON[2]]\nend\n\nlist = []\nmax = taxi.max\ntaxi.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to call a taxi, you should call: #{list.join(', ')}.\"\n\n\nlist = []\nmax = pizza.max\npizza.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to order a pizza, you should call: #{list.join(', ')}.\"\n\nlist = []\nmax = girl.max\ngirl.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to go to a cafe with a wonderful girl, you should call: #{list.join(', ')}.\""}, {"source_code": "def is_taxi(number)\n prev_char = ''\n taxi = true\n number.each_char do |char|\n taxi = false if (prev_char != '' && char != prev_char)\n prev_char = char\n end\n taxi\nend\n\ndef is_pizza(number)\n prev_char = ''\n pizza = true\n number.each_char do |char|\n pizza = false if (prev_char != '' && char.to_i >= prev_char)\n prev_char = char.to_i\n end\n pizza\nend\n\nfriends_count = gets.to_i\n\nnames = []\npizza_n = []\ntaxi_n = []\ngirl_n = []\n\npizza_max = 0\ntaxi_max = 0\ngirl_max = 0\n\n\nfriends_count.times do\n numbers_count, name = gets.split(' ')\n names << name\n taxi_count = 0\n pizza_count = 0\n numbers_count.to_i.times do\n number = gets.gsub('-', '').chomp\n prev_char = ''\n taxi_count += 1 if is_taxi number\n pizza_count += 1 if is_pizza number\n end\n girl_count = numbers_count.to_i - taxi_count - pizza_count\n \n girl_n << name if girl_count == girl_max\n girl_n = [name] if girl_count > girl_max\n girl_max = girl_count if girl_count >= girl_max\n \n taxi_n << name if taxi_count == taxi_max\n taxi_n = [name] if taxi_count > taxi_max\n taxi_max = taxi_count if taxi_count >= taxi_max\n \n pizza_n << name if pizza_count == pizza_max\n pizza_n = [name] if pizza_count > pizza_max\n pizza_max = pizza_count if pizza_count >= pizza_max\nend\n\nputs \"If you want to call a taxi, you should call: \" + taxi_n.join(', ') + \".\"\nputs \"If you want to order a pizza, you should call: \" + pizza_n.join(', ') + \".\"\nputs \"If you want to go to a cafe with a wonderful girl, you should call: \" + girl_n.join(', ') + \".\""}, {"source_code": "class Array\n def uniq?\n self.uniq.size == 1\n end\n\n def desc?\n (1...self.size).each { |i|\n return false if self[i] >= self[i - 1]\n }\n true\n end\nend\n\npeople = {}\n\n(0...gets.to_i).each {\n numbers_count, name = gets.chomp.split\n people[name] = Array.new(3, 0)\n (0...numbers_count.to_i).each {\n phone_digits = gets.chomp.gsub(/-/, '').split('').map(&:to_i)\n people[name][phone_digits.uniq? ? 0 : phone_digits.desc? ? 1 : 2] += 1\n }\n}\n\n['call a taxi', 'order a pizza', 'go to a cafe with a wonderful girl'].each_with_index { |action, index|\n max = people.values.map { |a| a[index] }.max\n printf \"If you want to %s, you should call: %s.\\n\", action, people.select { |_, a| a[index] == max }.keys.join(', ')\n}"}, {"source_code": "t = STDIN.gets.to_i\n\nar = []\n\ndef taxi?(phone)\n !!(phone =~ /(.)\\1-\\1\\1-\\1\\1/)\nend\n\ndef pizza?(phone)\n phone.scan(/\\d/).map(&:to_i).each_cons(2) {|a,b| return false if a <= b }\n return true\nend\n\nmaxt, maxp, maxg = 0, 0, 0\n\nt.times do\n n, name = STDIN.gets.chomp.split\n ntaxi, npizza, ngirl = 0, 0, 0\n\n n.to_i.times do\n\n phone = STDIN.gets.chomp\n\n if taxi?(phone)\n ntaxi += 1\n elsif pizza?(phone)\n npizza += 1\n else\n ngirl += 1\n end\n end\n\n ar << [name, ntaxi, npizza, ngirl]\n maxt = ntaxi if maxt < ntaxi\n maxp = npizza if maxp < npizza\n maxg = ngirl if maxg < ngirl\n\nend\n\nmsg1 = \"If you want to call a taxi, you should call: \"\nmsg2 = \"If you want to order a pizza, you should call: \"\nmsg3 = \"If you want to go to a cafe with a wonderful girl, you should call: \"\n\nta = []\npa = []\nga = []\n\nar.each do |el|\n ta << el[0] if maxt == el[1]\n pa << el[0] if maxp == el[2]\n ga << el[0] if maxg == el[3]\nend\n\nputs msg1 << ta.join(\", \") << \".\"\nputs msg2 << pa.join(\", \") << \".\"\nputs msg3 << ga.join(\", \") << \".\"\n\n\n"}, {"source_code": "t = STDIN.gets.to_i\n\nar = []\n\ndef taxi?(phone)\n !!(phone =~ /(.)\\1-\\1\\1-\\1\\1/)\nend\n\ndef pizza?(phone)\n phone.scan(/\\d/).map(&:to_i).each_cons(2) {|a,b| return false if a <= b }\n return true\nend\n\nmaxt, maxp, maxg = 0, 0, 0\n\nt.times do\n n, name = STDIN.gets.chomp.split\n ntaxi, npizza, ngirl = 0, 0, 0\n\n n.to_i.times do\n\n phone = STDIN.gets.chomp\n\n if taxi?(phone)\n ntaxi += 1\n elsif pizza?(phone)\n npizza += 1\n else\n ngirl += 1\n end\n end\n\n ar << [name, ntaxi, npizza, ngirl]\n maxt = ntaxi if maxt < ntaxi\n maxp = npizza if maxp < npizza\n maxg = ngirl if maxg < ngirl\n\nend\n\nmsg1 = \"If you want to call a taxi, you should call: \"\nmsg2 = \"If you want to order a pizza, you should call: \"\nmsg3 = \"If you want to go to a cafe with a wonderful girl, you should call: \"\n\nta = []\npa = []\nga = []\n\nar.each do |el|\n ta << el[0] if maxt == el[1]\n pa << el[0] if maxp == el[2]\n ga << el[0] if maxg == el[3]\nend\n\nputs msg1 << ta.join(\", \") << \".\"\nputs msg2 << pa.join(\", \") << \".\"\nputs msg3 << ga.join(\", \") << \".\"\n\n\n"}, {"source_code": "person = []\ngets.to_i.times{ |i|\n a, b = gets.split\n person[i] = [b, 0, 0, 0]\n a.to_i.times{\n d = gets.gsub(/[^\\d]/, \"\").split(\"\").map(&:to_i)\n same, dec = true, true\n d.each_with_index{ |x,j|\n same = false if x != d[0]\n dec = false if j > 0 && x >= d[j-1]\n }\n if same\n person[i][1] += 1\n elsif dec\n person[i][2] += 1\n else\n person[i][3] += 1\n end\n }\n}\n\nmx = (1..3).map{ |i| person.max_by{ |e| e[i] }[i] }\n[\"call a taxi\" ,\"order a pizza\", \"go to a cafe with a wonderful girl\"].each_with_index{ |s,i|\n puts \"If you want to \" + s + \", you should call: \" +\n person.select{ |e| e[i+1] == mx[i] }.map{ |e| e[0] }*\", \" + \".\"\n}\n"}, {"source_code": "def which_phone_no(numbers)\n\treturn :taxi if numbers.uniq.size==1\n\treturn :pizza if numbers.each_cons(2).all?{|a,b|a>b}\n\treturn :girl\nend\ncall={}\nk=[:taxi,:pizza,:girl]\nk.each{|_k|call[_k]=[0,[]]}\ngets.to_i.times{\n\ts,name=gets.split\n\tbooks=s.to_i.times.map{which_phone_no(gets.scan(/[0-9]/).map(&:to_i))}\n\tk.each{|_k|\n\t\tm=books.count(_k)\n\t\tif m>call[_k][0]\n\t\t\tcall[_k][0]=m\n\t\t\tcall[_k][1]=[name]\n\t\telsif call[_k][0]==m\n\t\t\tcall[_k][1]< Hash.new(0), :pizza => Hash.new(0), :girl => Hash.new(0)}\nsum = {:taxi => [], :pizza => [], :girl => []}\nnames = []\n\nclass String\n\tdef which?\n\t\tn = self.gsub('-', '')\n\t\tn = n.split('').map &:to_i\n\t\tif n.count == n.count(n[0])\n\t\t\t'taxi'\n\t\telsif n == n.uniq.sort.reverse\n\t\t\t'pizza'\n\t\telse\n\t\t\t'girl'\n\t\tend\n\tend\nend\n\ngets; while g = gets\n\tg = g.chop.split\n\tn = g[0].to_i\n\tnames.push g[1].to_sym\n\tn.times do\n\t\tnum = gets.chop!\n\t\tres[num.which?.to_sym][g[1].to_sym] += 1\n\tend\nend\n\nres.each do |key, hash|\n\tmax = hash.values.max\n\thash.each { |k, v| sum[key].push(k) if v == max }\nend\n\n{\n\t:taxi => 'call a',\n\t:pizza => 'order a',\n\t:girl => 'go to a cafe with a wonderful'\n}.each do |k, v|\n\tprint \"If you want to #{v} #{k}, you should call: \"\n\tprint sum[k].empty? ? names.join(', ') : sum[k].join(', ')\n\tputs \".\"\nend"}], "negative_code": [{"source_code": "#! /usr/bin/env ruby\n\nt = gets.chomp.to_i\nd = {}\nname_list = []\n(1..t).each do |x|\n n, name = gets.chomp.split\n n = n.to_i\n d[name] = {}\n name_list << name\n (1..n).each do |y|\n num = gets.chomp.split(\"-\")\n if num.uniq.size == 1 and num.uniq.first.split(//).uniq.size == 1\n d[name]['taxi'] = (d[name]['taxi'] || 0) + 1\n elsif num.join.split(//).map(&:to_i) == num.join.split(//).map(&:to_i).sort.reverse.uniq\n d[name]['pizza'] = (d[name]['pizza'] || 0) + 1\n else\n d[name]['girl'] = (d[name]['girl'] || 0) + 1\n end\n end\nend\nmax_taxi = d.keys.map { |i| [d[i]['taxi'] || 0, i] }.sort.max.first\nmax_pizza = d.keys.map { |i| [d[i]['pizza'] || 0, i] }.sort.max.first\nmax_girl = d.keys.map { |i| [d[i]['girl'] || 0, i] }.sort.max.first\ntaxi = name_list.select {|i| d[i]['taxi'] == max_taxi }.join(\", \") + \".\"\npizza = name_list.select {|i| d[i]['pizza'] == max_pizza }.join(\", \") + \".\"\ngirl = name_list.select {|i| d[i]['girl'] == max_girl }.join(\", \") + \".\"\nprint (\"If you want to call a taxi, you should call: \" + taxi +\"\\n\").to_s\nprint (\"If you want to order a pizza, you should call: \" + pizza +\"\\n\").to_s\nprint (\"If you want to go to a cafe with a wonderful girl, you should call: \" + girl +\"\\n\").to_s\n"}, {"source_code": "#! /usr/bin/env ruby\n\ndef type_of_phone_number(number)\n return :taxi if number.uniq.size.equal? 1\n return :pizza if number.each_cons(2).all? {|x, y| x > y}\n return :girl\nend\n\nd = {}\nk = [:taxi, :pizza, :girl]\nk.each {|x| d[x] = [0, []]}\n\ngets.to_i.times do |x|\n n, name = gets.chomp.split\n numbers = n.to_i.times.map {type_of_phone_number(gets.scan(/[0-9]/).map(&:to_i))}\n k.each do |x|\n d[x] = [numbers.count(x), [name]] if numbers.count(x) > d[x].first\n d[x].last << name if numbers.count(x) > d[x].first\n end\nend\n\nputs \"If you want to call a taxi, you should call: %s.\" %(d[:taxi][1] * \", \")\nputs \"If you want to order a pizza, you should call: %s.\" %(d[:pizza][1] * \", \")\nputs \"If you want to go to a cafe with a wonderful girl, you should call: %s.\" %(d[:girl][1] * \", \")\n"}, {"source_code": "#! /usr/bin/env ruby\n\ndef type_of_phone_number(number)\n return :taxi if number.uniq.size.equal? 1\n return :pizza if number.each_cons(2).all? {|x, y| x > y}\n return :girl\nend\n\nd = {}\nk = [:taxi, :pizza, :girl]\nk.each {|x| d[x] = [0, []]}\n\ngets.to_i.times do |x|\n n, name = gets.chomp.split\n numbers = n.to_i.times.map {type_of_phone_number(gets.scan(/[0-9]/).map(&:to_i))}\n k.each do |x|\n d[x] = [numbers.count(x), [name]] if numbers.count(x) > d[x].first\n d[x].last << name if numbers.count(x) > d[x].first\n end\nend\n\np \"If you want to call a taxi, you should call: %s.\" %(d[:taxi][1] * \", \")\np \"If you want to order a pizza, you should call: %s.\" %(d[:pizza][1] * \", \")\np \"If you want to go to a cafe with a wonderful girl, you should call: %s.\" %(d[:girl][1] * \", \")\n"}, {"source_code": "#! /usr/bin/env ruby\n\nt = gets.chomp.to_i\nd = {}\nname_list = []\n(1..t).each do |x|\n n, name = gets.chomp.split\n n = n.to_i\n d[name] = {}\n name_list << name\n (1..n).each do |y|\n num = gets.chomp.split(\"-\")\n if num.uniq.size == 1 and num.uniq.first.split(//).uniq.size == 1\n d[name]['taxi'] = (d[name]['taxi'] || 0) + 1\n elsif num.join.split(//).map(&:to_i) == num.join.split(//).map(&:to_i).sort.reverse.uniq\n d[name]['pizza'] = (d[name]['pizza'] || 0) + 1\n else\n d[name]['girl'] = (d[name]['girl'] || 0) + 1\n end\n end\nend\nmax_taxi = d.keys.map { |i| [d[i]['taxi'] || 0, i] }.sort.max.first\nmax_pizza = d.keys.map { |i| [d[i]['pizza'] || 0, i] }.sort.max.first\nmax_girl = d.keys.map { |i| [d[i]['girl'] || 0, i] }.sort.max.first\ntaxi = name_list.select {|i| d[i]['taxi'] == max_taxi }.join(\", \") + \".\"\npizza = name_list.select {|i| d[i]['pizza'] == max_pizza }.join(\", \") + \".\"\ngirl = name_list.select {|i| d[i]['girl'] == max_girl }.join(\", \") + \".\"\np (\"If you want to call a taxi, you should call: \" + taxi).to_s.strip\np \"If you want to order a pizza, you should call: \" + pizza\np \"If you want to go to a cafe with a wonderful girl, you should call: \" + girl\n"}, {"source_code": "\ufeffrequire 'set'\n\ndef is_taxi(s)\n tmp = s.split \"-\"\n set = Set.new tmp\n if set.length == 1\n true\n else\n false\n end\nend\n\ndef is_pizza(s)\n flag = true\n tmp = nil\n s.split(\"\").each do |c|\n if c != '-'\n if tmp == nil\n tmp = c.to_i\n else\n if tmp <= c.to_i\n flag = false\n break\n else\n tmp = c.to_i\n end\n end\n end\n end\n flag\nend\n\ndef max_names(hash)\n max = hash.values.max\n names = hash.select{ |k, v|\n v == max\n }\n names.keys.join ', '\nend\n\n\nn = gets.chomp.to_i\n\ntaxi = {}\npizza = {}\ngirl = {}\n\nn.times do\n tmp = gets.chomp.split \" \"\n s = tmp[0].to_i\n name = tmp[1]\n \n taxi[name] = 0\n pizza[name] = 0\n girl[name] = 0\n \n s.times do\n tmp2 = gets.chomp\n if is_taxi(tmp2)\n taxi[name] += 1\n elsif is_pizza(tmp2)\n pizza[name] += 1\n else\n girl[name] += 1\n end\n end\nend\n\nputs \"If you want to call a taxi, you should call: \" + max_names(taxi) + \".\"\nputs \"If you want to order a pizza, you should call: \" + max_names(pizza) + \".\"\nputs \"If you want to go to a cafe with a wonderful girl, you should call: \" + max_names(girl) + \".\"\n\n\n"}, {"source_code": "def pizza?(num)\n num = num.gsub(/-/,'').chars.map(&:to_i)\n prev = 10\n num.each do |n|\n if prev > n\n prev = n\n else\n return false\n end\n end\n true\nend\n\ndef taxi?(num)\n a = num[0]\n num.gsub(/[#{a}\\-]/,'').size.zero?\nend\n\ndef girl?(num)\n !taxi?(num) && !pizza?(num)\nend\n\ndef which(num)\n return :taxi if taxi?(num)\n return :pizza if pizza?(num)\n return :girl\nend\n\ndics = {}\nn = STDIN.gets.chomp.to_i\nn.times do\n i, name = STDIN.gets.chomp.split(/ /)\n i = i.to_i\n dics[name] = {taxi: 0, pizza: 0, girl: 0}\n already = []\n\n i.times do\n num = STDIN.gets.chomp\n next if already.include?(num)\n already << num\n dics[name][which(num)] += 1\n end\nend\n\n\n{taxi: \"If you want to call a taxi, you should call: \",\n pizza: \"If you want to order a pizza, you should call: \",\n girl: \"If you want to go to a cafe with a wonderful girl, you should call: \"}.each do |type, head|\n max = dics.map{|k,v| v[type] }.max\n puts head+dics.select{|k,v| v[type] == max }.keys.join(\", \")+\".\"\nend\n"}, {"source_code": "def pizza?(num)\n num = num.gsub(/-/,'').chars.map(&:to_i)\n prev = 10\n num.each do |n|\n if prev > n\n prev = n\n else\n return false\n end\n end\n true\nend\n\ndef taxi?(num)\n a = num[0]\n num.gsub(/[#{a}\\-]/,'').size.zero?\nend\n\ndef girl?(num)\n !taxi?(num) && !pizza?(num)\nend\n\ndef which(num)\n return :taxi if taxi?(num)\n return :pizza if pizza?(num)\n return :girl\nend\n\ndics = {}\nn = STDIN.gets.chomp.to_i\nn.times do\n i, name = STDIN.gets.chomp.split(/ /)\n i = i.to_i\n dics[name] = {taxi: 0, pizza: 0, girl: 0}\n already = []\n\n i.times do\n num = STDIN.gets.chomp\n next if already.include?(num)\n already << num\n dics[name][which(num)] += 1\n end\nend\n\n\n{taxi: \"If you want to call a taxi, you should call: \",\n pizza: \"If you want to order a pizza, you should call: \",\n girl: \"If you want to go to a cafe with a wonderful girl, you should call: \"}.each do |type, head|\n max = dics.max{|(k,v)| v[type] }[1][type]\n puts head+dics.select{|k,v| v[type] == max }.keys.join(\", \")+\".\"\nend\n"}, {"source_code": "def pizza?(num)\n num = num.gsub(/-/,'').chars.map(&:to_i)\n prev = 10\n num.each do |n|\n if prev > n\n prev = n\n else\n return false\n end\n end\n true\nend\n\ndef taxi?(num)\n a = num[0]\n num.gsub(/[#{a}\\-]/,'').size.zero?\nend\n\ndef girl?(num)\n !taxi?(num) && !pizza?(num)\nend\n\ndef which(num)\n return :taxi if taxi?(num)\n return :pizza if pizza?(num)\n return :girl\nend\n\ndics = {}\nn = STDIN.gets.chomp.to_i\nn.times do\n i, name = STDIN.gets.chomp.split(/ /)\n i = i.to_i\n dics[name] = {taxi: 0, pizza: 0, girl: 0}\n already = []\n\n i.times do\n num = STDIN.gets.chomp\n next if already.include?(num)\n already << num\n dics[name][which(num)] += 1\n end\nend\n\n\n{taxi: \"If you want to call a taxi, you should call: \",\n pizza: \"If you want to order a pizza, you should call: \",\n girl: \"If you want to go to a cafe with a wonderful girl, you should call: \"}.each do |type, head|\n max = dics.max{|(k,v)| v[type] }[1][type]\n puts head+dics.select{|k,v| v[type] == max }.keys.join(\", \")\nend\n"}, {"source_code": "n = gets.to_i\npb = []\nn.times do |i|\n a = [i]\n c,nm = gets.split\n a << nm\n h = Hash.new(0)\n c.to_i.times do\n pn = gets.strip.gsub(/-/,\"\").split(//)\n pn.uniq.sort.reverse\n if pn.uniq.size == 1\n h[:t] += 1\n elsif pn.uniq.sort.reverse == pn\n h[:p] += 1\n else\n h[:g] += 1\n end\n end\n a << h\n pb << a\nend\n\nmx = pb.map{|a| a[2][:t]}.max\ntx = pb.select{|a| a[2][:t] == mx }\n\n\nmx = pb.map{|a| a[2][:p]}.max\npz = pb.select{|a| a[2][:p] == mx }\n\nmx = pb.map{|a| a[2][:g]}.max\ngf = pb.select{|a| a[2][:g] == mx }\n\nputs \"If want to order a pizza, you should call: #{tx.map{|a| a[1]}.join(\", \")}.\"\nputs \"If you want to call a taxi, you should call: #{pz.map{|a| a[1]}.join(\", \")}.\"\nputs \"If you want to go to a cafe with a wonderful girl, you should call: #{gf.map{|a| a[1]}.join(\", \")}.\"\n"}, {"source_code": "#!/usr/bin/ruby\nclass Number\n def initialize\n @mas=Array.new(6)\n end\n def mas\n @mas\n end\n def mas=(mas)\n @mas=mas\n end\n def isPizza()\n return @mas==@mas.uniq() && @mas==@mas.sort{|a,b| b<=>a}\n end\n def isTaxi()\n return @mas.uniq().size()==1\n end\nend\nclass Person\n def initialize\n @name=\"\"\n @taxiElements=0\n @girlElements=0\n @pizzaElements=0\n @numberArray=[]\n end\n def taxiElements\n @taxiElements\n end\n def pizzaElements\n @pizzaElements\n end\n def girlElements\n @girlElements\n end\n def name\n @name\n end\n def name=(name)\n @name=name\n end\n def numberArray\n @numberArray\n end\n def numberArray=(numberArray)\n @numberArray=numberArray\n end\n def countElements()\n for i in 0..(@numberArray.size()-1)\n element=@numberArray[i]\n if element.isTaxi()\n\t@taxiElements=@taxiElements+1\n elsif (element.isPizza())\n\t@pizzaElements=@pizzaElements+1\n else\n\t@girlElements=@girlElements+1\n end\n end\n end\nend\n\nrequire 'scanf'\ncount=(scanf(\"%d\"))[0]\narray=Array.new(count)\nfor i in 0..(count-1)\n array[i]=Person.new\n temp=scanf(\"%d %s\")\n elements=temp[0]\n array[i].name=temp[1]\n array[i].numberArray=Array.new(elements)\n for j in 0..(elements-1) \n array[i].numberArray[j]=Number.new \n array[i].numberArray[j].mas=scanf(\"%c%c-%c%c-%c%c\") \n end \n \nend\n\narray.each do |i|\n i.countElements()\nend\nmaxPizza=(array.map{|x|x.pizzaElements}).max\nmaxTaxi=(array.map{|x|x.taxiElements}).max\nmaxGirl=(array.map{|x|x.girlElements}).max\noutTaxi=\"If you want to call a taxi, you should call: \"\noutPizza=\"If you want to order a pizza, you should call: \"\noutGirl=\"If you want to go to a cafe with a wonderful girl, you should call: \"\nwasTaxi=false\nwasPizza=false\nwasGirl=false\narray.each do |i|\n if i.taxiElements==maxTaxi\n if wasTaxi\n outTaxi+=\", \"\n end\n wasTaxi=true\n outTaxi+=i.name\n end\n if i.pizzaElements==maxPizza\n if wasPizza\n outPizza+=\", \"\n end\n wasPizza=true\n outPizza+=i.name\n end\n if i.girlElements==maxGirl\n if wasGirl\n outGirl+=\", \"\n end\n wasGirl=true\n outGirl+=i.name\n end\nend\noutTaxi+=\".\"\noutPizza+=\".\"\noutGirl+=\".\"\nif wasTaxi\n puts outTaxi\nend\nif wasPizza\n puts outPizza\nend\nif wasGirl\n puts outGirl\nend\n"}, {"source_code": "#!/usr/bin/ruby\nclass Number\n def initialize\n @mas=Array.new(6)\n end\n def mas\n @mas\n end\n def mas=(mas)\n @mas=mas\n end\n def isPizza()\n return @mas==@mas.uniq() && @mas==@mas.sort{|a,b| b<=>a}\n end\n def isTaxi()\n return @mas.uniq().size()==1\n end\nend\nclass Person\n def initialize\n @name=String.new\n @taxiElements=0\n @girlElements=0\n @pizzaElements=0\n @numberArray=[]\n end\n def taxiElements\n @taxiElements\n end\n def pizzaElements\n @pizzaElements\n end\n def girlElements\n @girlElements\n end\n def name\n @name\n end\n def name=(name)\n @name=name\n end\n def numberArray\n @numberArray\n end\n def numberArray=(numberArray)\n @numberArray=numberArray\n end\n def countElements()\n for i in 0..(@numberArray.size()-1)\n element=@numberArray[i]\n if element.isTaxi()\n @taxiElements=@taxiElements+1\n elsif (element.isPizza())\n @pizzaElements=@pizzaElements+1\n else\n @girlElements=@girlElements+1\n end\n end\n end\nend\n\nrequire 'scanf'\ncount=(scanf(\"%d\\n\"))[0]\narray=Array.new(count)\nfor i in 0..(count-1)\n array[i]=Person.new\n temp=scanf(\"%d %s\\n\")\n puts temp\n elements=temp[0]\n array[i].name=temp[1]\n array[i].numberArray=Array.new(elements)\n for j in 0..(elements-1) \n array[i].numberArray[j]=Number.new \n array[i].numberArray[j].mas=scanf(\"%c%c-%c%c-%c%c\\n\") \n end \n \nend\n\narray.each do |i|\n i.countElements()\nend\nmaxPizza=(array.map{|x|x.pizzaElements}).max\nmaxTaxi=(array.map{|x|x.taxiElements}).max\nmaxGirl=(array.map{|x|x.girlElements}).max\noutTaxi=\"If you want to call a taxi, you should call: \"\noutPizza=\"If you want to order a pizza, you should call: \"\noutGirl=\"If you want to go to a cafe with a wonderful girl, you should call: \"\nwasTaxi=false\nwasPizza=false\nwasGirl=false\narray.each do |i|\n if i.taxiElements==maxTaxi\n if wasTaxi\n outTaxi+=\", \"\n end\n wasTaxi=true\n outTaxi+=i.name\n end\n if i.pizzaElements==maxPizza\n if wasPizza\n outPizza+=\", \"\n end\n wasPizza=true\n outPizza+=i.name\n end\n if i.girlElements==maxGirl\n if wasGirl\n outGirl+=\", \"\n end\n wasGirl=true\n outGirl+=i.name\n end\nend\noutTaxi+=\".\"\noutPizza+=\".\"\noutGirl+=\".\"\nputs outTaxi\nputs outPizza\nputs outGirl\n"}, {"source_code": "#!/usr/bin/ruby\nclass Number\n def initialize\n @mas=Array.new(6)\n end\n def mas\n @mas\n end\n def mas=(mas)\n @mas=mas\n end\n def isPizza()\n return @mas==@mas.uniq() && @mas==@mas.sort{|a,b| b<=>a}\n end\n def isTaxi()\n return @mas.uniq().size()==1\n end\nend\nclass Person\n def initialize\n @name=\"\"\n @taxiElements=0\n @girlElements=0\n @pizzaElements=0\n @numberArray=[]\n end\n def taxiElements\n @taxiElements\n end\n def pizzaElements\n @pizzaElements\n end\n def girlElements\n @girlElements\n end\n def name\n @name\n end\n def name=(name)\n @name=name\n end\n def numberArray\n @numberArray\n end\n def numberArray=(numberArray)\n @numberArray=numberArray\n end\n def countElements()\n for i in 0..(@numberArray.size()-1)\n element=@numberArray[i]\n if element.isTaxi()\n\t@taxiElements=@taxiElements+1\n elsif (element.isPizza())\n\t@pizzaElements=@pizzaElements+1\n else\n\t@girlElements=@girlElements+1\n end\n end\n end\nend\n\nrequire 'scanf'\ncount=(scanf(\"%d\"))[0]\narray=Array.new(count)\nfor i in 0..(count-1)\n array[i]=Person.new\n temp=scanf(\"%d %s\")\n elements=temp[0]\n array[i].name=temp[1]\n array[i].numberArray=Array.new(elements)\n for j in 0..(elements-1) \n array[i].numberArray[j]=Number.new \n array[i].numberArray[j].mas=scanf(\"%c%c-%c%c-%c%c\") \n end \n \nend\n\narray.each do |i|\n i.countElements()\nend\nmaxPizza=(array.map{|x|x.pizzaElements}).max\nmaxTaxi=(array.map{|x|x.taxiElements}).max\nmaxGirl=(array.map{|x|x.girlElements}).max\noutTaxi=\"If you want to call a taxi, you should call: \"\noutPizza=\"If you want to order a pizza, you should call: \"\noutGirl=\"If you want to go to a cafe with a wonderful girl, you should call: \"\nwasTaxi=false\nwasPizza=false\nwasGirl=false\narray.each do |i|\n if i.taxiElements==maxTaxi\n if wasTaxi\n outTaxi+=\", \"\n end\n wasTaxi=true\n outTaxi+=i.name\n end\n if i.pizzaElements==maxPizza\n if wasPizza\n outPizza+=\", \"\n end\n wasPizza=true\n outPizza+=i.name\n end\n if i.girlElements==maxGirl\n if wasGirl\n outGirl+=\", \"\n end\n wasGirl=true\n outGirl+=i.name\n end\nend\noutTaxi+=\".\"\noutPizza+=\".\"\noutGirl+=\".\"\nputs outTaxi\nputs outPizza\nputs outGirl\n"}, {"source_code": "n = gets.to_i\nCON = [:taxi,:pizza,:girl]\nfriends = []\nnames = []\nn.times do\n\tm,name = gets.chomp.split(\" \")\n\tnames << name\n\tm = m.to_i\n\tnos = Hash.new(0)\n\tm.times do\n\t\tans = nil\n\t\tx,y,z = gets.chomp.split(\"-\")\n\t\ta,b,c = x.to_i,y.to_i,z.to_i\n\t\tarr = [x.split(''),y.split(''),z.split('')].flatten\n\n\t\t# puts \"#{one} #{two} #{three} #{four} #{five} #{six}\"\n\t\t# puts \"#{b} #{c}\"\n\t\t# puts \"#{(one.to_i > two.to_i) && (three.to_i > four.to_i) && (five.to_i > six.to_i)}\"\n\t\tif a == b && b == c && arr.each_cons(2).all?{|l,m| l == m}\n\t\t\tans = CON[0]\n\t\telsif a > b && b > c && arr.each_cons(2).all?{|l,m| l > m}\n\t\t\tans = CON[1]\n\t\telse\n\t\t\tans = CON[2]\n\t\tend\n\t\tnos[ans] += 1\n\tend\n\tfriends << nos\nend\ntaxi = []\npizza = []\ngirl = []\nputs \"#{friends}\"\nfriends.each_with_index do |f,i|\n\ttaxi[i] = f[CON[0]]\n\tpizza[i] = f[CON[1]]\n\tgirl[i] = f[CON[2]]\nend\n\nlist = []\nmax = taxi.max\ntaxi.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to call a taxi, you should call: #{list.join(', ')}.\"\n\n\nlist = []\nmax = pizza.max\npizza.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to order a pizza, you should call: #{list.join(', ')}.\"\n\nlist = []\nmax = girl.max\ngirl.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to go to a cafe with a wonderful girl, you should call: #{list.join(', ')}.\""}, {"source_code": "n = gets.to_i\nCON = [:taxi,:pizza,:girl]\nfriends = []\nnames = []\nn.times do\n\tm,name = gets.chomp.split(\" \")\n\tnames << name\n\tm = m.to_i\n\tnos = Hash.new(0)\n\tm.times do\n\t\tans = nil\n\t\tx,y,z = gets.chomp.split(\"-\")\n\t\ta,b,c = x.to_i,y.to_i,z.to_i\n\t\tone,two = x.split('')\n\t\tthree,four = y.split('')\n\t\tfive,six = z.split('')\n\t\t# puts \"#{one} #{two} #{three} #{four} #{five} #{six}\"\n\t\t# puts \"#{b} #{c}\"\n\t\t# puts \"#{(one.to_i > two.to_i) && (three.to_i > four.to_i) && (five.to_i > six.to_i)}\"\n\t\tif a == b && b == c\n\t\t\tans = CON[0]\n\t\telsif a > b && b > c && (one.to_i > two.to_i) && (three.to_i > four.to_i) && (five.to_i > six.to_i)\n\t\t\tans = CON[1]\n\t\telse\n\t\t\tans = CON[2]\n\t\tend\n\t\tnos[ans] += 1\n\tend\n\tfriends << nos\nend\ntaxi = []\npizza = []\ngirl = []\n\nfriends.each_with_index do |f,i|\n\ttaxi[i] = f[CON[0]]\n\tpizza[i] = f[CON[1]]\n\tgirl[i] = f[CON[2]]\nend\n\nlist = []\nmax = taxi.max\ntaxi.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to call a taxi, you should call: #{list.join(', ')}.\"\n\n\nlist = []\nmax = pizza.max\npizza.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to order a pizza, you should call: #{list.join(', ')}.\"\n\nlist = []\nmax = girl.max\ngirl.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to go to a cafe with a wonderful girl, you should call: #{list.join(', ')}.\""}, {"source_code": "n = gets.to_i\nCON = [:taxi,:pizza,:girl]\nfriends = []\nnames = []\nn.times do\n\tm,name = gets.chomp.split(\" \")\n\tnames << name\n\tm = m.to_i\n\tnos = Hash.new(0)\n\tm.times do\n\t\tans = nil\n\t\tx,y,z = gets.chomp.split(\"-\")\n\t\ta,b,c = x.to_i,y.to_i,z.to_i\n\t\tarr = [x.split(''),y.split(''),z.split('')].flatten\n\n\t\t# puts \"#{one} #{two} #{three} #{four} #{five} #{six}\"\n\t\t# puts \"#{b} #{c}\"\n\t\t# puts \"#{(one.to_i > two.to_i) && (three.to_i > four.to_i) && (five.to_i > six.to_i)}\"\n\t\tif a == b && b == c\n\t\t\tans = CON[0]\n\t\telsif a > b && b > c && arr.each_cons(2).all?{|l,m| l > m}\n\t\t\tans = CON[1]\n\t\telse\n\t\t\tans = CON[2]\n\t\tend\n\t\tnos[ans] += 1\n\tend\n\tfriends << nos\nend\ntaxi = []\npizza = []\ngirl = []\n# puts \"#{friends}\"\nfriends.each_with_index do |f,i|\n\ttaxi[i] = f[CON[0]]\n\tpizza[i] = f[CON[1]]\n\tgirl[i] = f[CON[2]]\nend\n\nlist = []\nmax = taxi.max\ntaxi.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to call a taxi, you should call: #{list.join(', ')}.\"\n\n\nlist = []\nmax = pizza.max\npizza.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to order a pizza, you should call: #{list.join(', ')}.\"\n\nlist = []\nmax = girl.max\ngirl.each_with_index do |t,i|\n\tlist << names[i] if t == max\nend\n\nputs \"If you want to go to a cafe with a wonderful girl, you should call: #{list.join(', ')}.\""}, {"source_code": "person = []\ngets.to_i.times{ |i|\n a, b = gets.split\n person[i] = [b, 0, 0, 0]\n a.to_i.times{\n d = gets.gsub(/[^\\d]/, \"\").split(\"\").map(&:to_i)\n same, dec = true, true\n d.each_with_index{ |x,j|\n same = false if x != d[0]\n dec = false if j > 0 && x >= d[j-1]\n }\n if same\n person[i][1] += 1\n elsif dec\n person[i][2] += 1\n else\n person[i][3] += 1\n end\n }\n}\n\nmx = (1..3).map{ |i| person.max_by{ |e| e[i] }[i] }\n[\"taxi\" ,\"pizza\", \"cafe with a wonderful girl\"].each_with_index{ |s,i|\n puts \"If you want to call a \" + s + \", you should call: \" +\n person.select{ |e| e[i+1] == mx[i] }.map{ |e| e[0] }*\", \" + \".\"\n}\n"}, {"source_code": "res = {:taxi => Hash.new(0), :pizza => Hash.new(0), :girl => Hash.new(0)}\nsum = {:taxi => [], :pizza => [], :girl => []}\n\nclass String\n\tdef which?\n\t\tn = self.gsub('-', '')\n\t\tn = n.split('').map &:to_i\n\t\tif n.count == n.count(n[0])\n\t\t\t'taxi'\n\t\telsif n == n.uniq.sort.reverse\n\t\t\t'pizza'\n\t\telse\n\t\t\t'girl'\n\t\tend\n\tend\nend\n\ngets; while g = gets\n\tg = g.chop.split\n\tg[0].to_i.times do |i|\n\t\tnum = gets.chop!\n\t\tres[num.which?.to_sym][g[1].to_sym] += 1\n\tend\nend\n\nres.each do |key, hash|\n\tmax = hash.values.max\n\thash.each { |k, v| sum[key].push(k) if v == max }\nend\n\n{\n\t:taxi => 'call a',\n\t:pizza => 'order a',\n\t:girl => 'go to a cafe with a wonderful'\n}.each do |k, v|\n\tprint \"If you want to #{v} #{k}, you should call: \"\n\tprint sum[k].join(', ')\n\tputs \".\"\nend\n"}], "src_uid": "4791a795119c185b3aec91b6f8af8f03"} {"source_code": "n = gets.to_i\nstr1 = gets.chomp\nstr2 = gets.chomp\n\n#require 'Set'\n\ncount = 0\n\n(0..(n/2)-1).each do |i|\n set = [str1[i],str2[i],str1[n-i-1],str2[n-i-1]]\n len = set.uniq.length\n\n if len == 2\n if set.count(set[0]) != 2\n count += 1\n end\n elsif len == 3\n count += 1\n if set[0] == set[2]\n count += 1\n end\n elsif len == 4\n count += 2\n end\nend\n\nif n%2==1\n if str1[n/2]!=str2[n/2]\n count += 1\n end\nend\n\nputs count", "positive_code": [{"source_code": "N = gets.to_i\nA = gets.chomp\nB = gets.chomp\n\nans = 0\n((N+1)/2).times do |i|\n hash = Hash.new(0)\n hash[A[i]] += 1\n hash[B[i]] += 1\n if i != N-i-1\n hash[A[N-i-1]] += 1\n hash[B[N-i-1]] += 1\n end\n values = hash.values.sort\n if values.all?(&:even?)\n next\n elsif B[i] != B[N-i-1] && A[i] != B[i] && A[N-i-1] != B[N-i-1] && A[i] != B[N-i-1] && A[N-i-1] != B[i]\n ans += 2\n else\n ans += 1\n end\nend\nputs ans"}], "negative_code": [{"source_code": "N = gets.to_i\nA = gets.chomp\nB = gets.chomp\n\nans = 0\n((N+1)/2).times do |i|\n hash = Hash.new(0)\n hash[A[i]] += 1\n hash[B[i]] += 1\n if i != N-i-1\n hash[A[N-i-1]] += 1\n hash[B[N-i-1]] += 1\n end\n values = hash.values.sort\n if values.all?(&:even?)\n next\n elsif B[i] != B[N-i-1] && A[i] != B[i] && A[N-i-1] != B[N-i-1]\n ans += 2\n else\n ans += 1\n end\n p [i, ans]\nend\nputs ans"}, {"source_code": "N = gets.to_i\nA = gets.chomp\nB = gets.chomp\n\nans = 0\n((N+1)/2).times do |i|\n hash = Hash.new(0)\n hash[A[i]] += 1\n hash[B[i]] += 1\n if i != N-i-1\n hash[A[N-i-1]] += 1\n hash[B[N-i-1]] += 1\n end\n values = hash.values.sort\n if values.all?(&:even?)\n next\n elsif values == [1, 3] || B[i] == B[N-i-1]\n ans += 1\n else\n ans += 2\n end\nend\nputs ans"}, {"source_code": "N = gets.to_i\nA = gets.chomp\nB = gets.chomp\n\nans = 0\n((N+1)/2).times do |i|\n hash = Hash.new(0)\n hash[A[i]] += 1\n hash[B[i]] += 1\n if i != N-i-1\n hash[A[N-i-1]] += 1\n hash[B[N-i-1]] += 1\n end\n values = hash.values.sort\n if values.all?(&:even?)\n next\n elsif B[i] != B[N-i-1] && A[i] != B[i] && A[N-i-1] != B[N-i-1] && A[i] != B[N-i-1] && A[N-i-1] && B[i]\n ans += 2\n else\n ans += 1\n end\nend\nputs ans"}, {"source_code": "N = gets.to_i\nA = gets.chomp\nB = gets.chomp\n\nans = 0\n((N+1)/2).times do |i|\n hash = Hash.new(0)\n hash[A[i]] += 1\n hash[B[i]] += 1\n if i != N-i-1\n hash[A[N-i-1]] += 1\n hash[B[N-i-1]] += 1\n end\n values = hash.values.sort\n if values.all?(&:even?)\n next\n elsif A[i] != A[N-i-1] && A[i] != B[i] && A[N-i-1] != B[N-i-1]\n ans += 2\n else\n ans += 1\n end\nend\nputs ans"}, {"source_code": "N = gets.to_i\nA = gets.chomp\nB = gets.chomp\n\nans = 0\n((N+1)/2).times do |i|\n hash = Hash.new(0)\n hash[A[i]] += 1\n hash[B[i]] += 1\n if i != N-i-1\n hash[A[N-i-1]] += 1\n hash[B[N-i-1]] += 1\n end\n values = hash.values.sort\n if values.all?(&:even?)\n next\n elsif B[i] != B[N-i-1] && A[i] != B[i] && A[N-i-1] != B[N-i-1]\n ans += 2\n else\n ans += 1\n end\nend\nputs ans"}], "src_uid": "259b4b538743608227bb6d22453b0833"} {"source_code": "gets;a=gets.chomp.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split(/\\s+/).map(&:to_i).sort_by {|e| -e}\nsum = result = a.inject {|a,b| a+b}\n\nwhile a.size > 1\n x = a.pop\n result += sum\n sum -= x\nend\n\np result\n\n"}, {"source_code": "n = gets.to_i\nputs gets.chomp.split.map(&:to_i).sort.each_with_index.map{|x, i| x * (if i == n - 1 then i + 1 else i + 2 end)}.inject(:+)"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]\n"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]\n"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]"}, {"source_code": "n=gets.to_i\nv=(gets.split.map &:to_i).sort\nx=-v[-1]\n(0...n).each{|i| x += (i+2)*v[i]}\np x"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]\n"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]\n"}, {"source_code": "gets\nx=gets.split.map{|e| e.to_i}.sort\n\nsum1=x.inject(0){|sumA,e|\n\tsumA+e\n}\nans=0\nwhile x.size>1\n\tans+=sum1\n\tsum1-=x[0]\n\tans+=x[0]\n\tx.shift\nend\nans+=x[0]\nputs ans\n\n"}, {"source_code": "#!/usr/bin/ruby2.0\n\nn = STDIN.readline.to_i\nnumbers = STDIN.readline.split.collect {|s| s.to_i }\nnumbers.sort!\n\nscore = -numbers[n-1]\n(n.downto 1).each do |i|\n\tscore += (i+1)*numbers[i-1]\nend\n\nputs score\n\n"}, {"source_code": "n = gets.to_i\nvec = (gets.split.map &:to_i).sort\nx = 2*vec.reduce(:+) - vec[n-1]\nfor i in (1...n)\n x += i*vec[i] \nend\np x"}, {"source_code": "n=gets.to_i\nv=(gets.split.map &:to_i).sort\nx=2*v.reduce(:+)-v[-1]\n(1...n).each{|i| x+=i*v[i]}\np x"}, {"source_code": "n=gets.to_i\nv=(gets.split.map &:to_i).sort\nx=-v[-1]\n(0...n).each{|i| x += (i+2)*v[i]}\np x"}, {"source_code": "N = gets.to_i\nsum = 0\narr = gets.split.map{ |xx|\n x = xx.to_i\n sum += x\n x\n}.sort_by{|x|x}\n# p arr\n# p sum\nans = sum\n(N-1).times do |i|\n ans += sum\n sum -= arr[i]\n # p ans\nend\nputs ans"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]"}, {"source_code": "require 'pp'\n\nn = STDIN.gets.chomp.to_i\nvals = STDIN.gets.chomp.split(/ /).map(&:to_i)\nvals.sort!.reverse!\nans = - vals.first\nvals.each do |val|\n ans += val * (n + 1)\n n -= 1\nend\n\nputs ans\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nar = gets.split.map(&:to_i)\nar.sort!\n\n# 1 2 3 4 5\n# X X X X X sum [1 2 3 4 5]\n# X X X X X sp rt sum [1] [2 3 4 5]\n# ? X X X X throw sp rt sum [2] [3 4 5]\n# ? ? X X X throw sp rt sum [3] [4, 5]\n# ? ? ? ? ? \n# 1 3 5\n# X X X [1 3 5]\n# X X X [1] [3 5]\n# ? X X [3] [5]\n# ? ? ? empty\n# 1 2 3 4\n# X X X X [1 2 3 4]\n# X X X X [1] [2 3 4]\n# ? X X X [2] [3 4]\n# ? ? X X [3] [4]\n\ns = ar.sum\nacc = s\nwhile s > 0\n if ar.length > 1\n acc += s\n s -= ar.shift\n else\n break\n end\nend\n\nputs acc"}, {"source_code": "n, v, r = gets.to_i, gets.split.map {|e| e.to_i}.sort!, 0\nfor i in 0...n-1\n r+=v[i]*(i+2)\nend\np r+v[-1]*n"}, {"source_code": "n = Integer(gets.chomp)\nv = gets.chomp.split.map{|x| Integer(x)}.sort\nsum = 0\nfor x in v do sum += x end\nans = sum\nfor x in v[0...-1] do\n ans += sum\n sum -= x\nend\n\nputs ans"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]\n"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]\n"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]\n"}, {"source_code": "M = 1_000_000_007\nn = gets.to_i\nxs = gets.split.map(&:to_i)\nxs.sort!\nsum = 0\nn.times do |i|\n sum += xs[i] * [i + 2, n].min\nend\np sum\n"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort\np a.each_with_index.map{|x,i|x*(i+2)}.inject(:+)-a[-1]\n"}, {"source_code": "n=gets.to_i\narr=Array.new()\narr=gets.split.map(&:to_i)\n\narr.sort!\nsum=arr[n-1]*n\nfor i in 2..n do\n sum+=arr[n-i]*(n+2-i)\nend\n\nputs sum\n"}, {"source_code": "\n\nn = gets.to_i\ntab = gets.split.map(&:to_i).sort\n\nsuffix_sum = tab[0..-2].reverse.inject([tab[-1]]){|x, y| x << x[-1]+y}.reverse\n\nresult = -tab[-1];\n\n(0..tab.size-1).each do |i|\n result += suffix_sum[i] + tab[i]\nend\n\nputs result\n\n\n\n"}, {"source_code": "# 3\n# 3 1 5\n\nn = gets.to_i\narray_a = gets.split.map(&:to_i)\n\narray_a.sort!\n\nans = 0\n\narray_a.each_with_index do |a, i|\n break if i == n-1\n ans += a * (i+2)\nend\nans += array_a.last * n\n\nputs ans\n "}, {"source_code": "n=gets.to_i\narr=gets.split(/ /).map(&:to_i)\nsum=0\narr.each do |i|\n sum+=i\nend\nans=0\narr.sort.each do |i|\n ans+=sum+i\n sum-=i\nend\nputs ans-arr.sort[-1]"}], "negative_code": [{"source_code": "# coding: utf-8\n\nn = gets.to_i\nar = gets.split.map(&:to_i)\nar.sort!\n\n# 1 2 3 4 5\n# X X X X X [1 2 3 4 5]\n# X X X X X [1] [2 3 4 5]\n# ? X X X X [2] [3 4 5]\n# ? X X X X [2] [3] [4] [5]\n# ? ? ? ? ? \n# 1 3 5\n# X X X [1 3 5]\n# X X X [1] [3 5]\n# ? X X [3] [5]\n# ? ? ? empty\n# 1 2 3 4\n# X X X X [1 2 3 4]\n# X X X X [1] [2 3 4]\n# ? X X X [2 3 4]\n# ? X X X [2] [3 4]\n# ? ? X X [3 4]\n# ? ? X X [3] [4]\n\ns = ar.sum\nacc = 0\nwhile s > 0\n acc += s\n if ar.length > 2 # \uc65c\ub0d0\uba74 2\uc5d0\uc120 split \ub41c \ub2e4\uc74c\uc774 \uc5c6\uae30 \ub54c\ubb38\n acc += s\n sub = ar.shift\n s -= sub\n else\n break\n end\nend\n\nputs acc"}], "src_uid": "4266948a2e793b4b461156af226e98fd"} {"source_code": "#!/usr/bin/env ruby\n\nn = gets.split.collect{|i| i.to_i}.min\n\nputs n + 1\n\n0.upto(n) { |i| puts \"#{i} #{n-i}\" }\n", "positive_code": [{"source_code": "a=gets.split.map &:to_i\n(p a.min+1).times{|i|puts [a[0]-i,i]*' '}\n"}, {"source_code": "t = gets.split.collect{|x| x.to_i}\nn,m = t[0],t[1]\n\nmin = t.min\n\nputs min+1\n\n(min+1).times do |i|\n\tprint i,' ', min-i, \"\\n\"\nend"}, {"source_code": "a=gets.split.map &:to_i\n(p a.min+1).times{|i|puts [a[0]-i,i]*' '}\n"}, {"source_code": "a=gets.split.map &:to_i\n(p a.min+1).times{|i|puts [a[0]-i,i]*' '}\n"}, {"source_code": "n,m=gets.split.map &:to_i\n(p [n,m].min+1).times{|i|puts [n-i,i]*' '}"}, {"source_code": "a=gets.split.map &:to_i\n(p a.min+1).times{|i|puts [a[0]-i,i]*' '}\n"}, {"source_code": "def run\n n, m = ARGF.readline.split.map(&:to_i)\n puts num = [n, m].min + 1\n num.times do |i|\n puts [n - i, i].join(' ')\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "a=gets.split.map &:to_i\n(p a.min+1).times{|i|puts [a[0]-i,i]*' '}\n"}, {"source_code": "n, m = gets.split(' ').map &:to_i\nq = [n,m].min\nputs q + 1\n(q+1).times do |time|\n puts [time, q - time].join(' ')\nend"}, {"source_code": "a=gets.split.map &:to_i\n(p a.min+1).times{|i|puts [a[0]-i,i]*' '}\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nk=[n,m].min+1\nputs k\ni=0\nk.times do\n puts \"#{k-i-1} #{i}\"\n i+=1\nend"}, {"source_code": "a=gets.split.map &:to_i\n(p a.min+1).times{|i|puts [a[0]-i,i]*' '}"}, {"source_code": "n,m=gets.split.map &:to_i\n(p [n,m].min+1).times{|i|puts [n-i,i]*' '}"}, {"source_code": "n,m = gets.split(' ').map(&:to_i)\n\nif n>m\n n = m\nend\nputs n+1\n(0..n).each do |k|\n puts \"#{k} #{n-k}\"\nend"}, {"source_code": "n, m = gets.split(' ')\nn = n.to_i\nm = m.to_i\n\nif n < m\n\tmin = n\nelse\n\tmin = m\nend\n\nbeaty = []\n\nosx = min\nosy = 0\n\n(min+1).times do |x|\n\tbeaty << [osx, osy]\n\tosx -= 1\n\tosy += 1\n\tosx = n if osx < 0\n\tosy = 0 if osy > m\nend\n\nputs beaty.length\n\nbeaty.each do |e|\n\tputs e.join(' ')\nend"}, {"source_code": "a=gets.split.map &:to_i\n(p a.min+1).times{|i|puts [a[0]-i,i]*' '}\n"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\nmin = [n,m].min + 1\nputs min\n(0...min).each do |i|\n\tputs \"#{i} #{min - i - 1}\"\nend"}, {"source_code": "n,m = gets.chomp.split(\" \").collect! {|x| x.to_i}\nif n>m\n\tn = m\nend\n\nputs n+1\n(0..n).each{|k|\n\tputs \"#{k} #{n-k}\"\n}"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\nans = [n, m].min+1\nputs ans\n(0...ans).each do |i|\n print i, \" \", ans-1-i, \"\\n\" \nend\n"}, {"source_code": "a=gets.split.map &:to_i\n(p a.min+1).times{|i|puts [a[0]-i,i]*' '}\n"}, {"source_code": "n, m = gets.split.map { |x| x.to_i }\nputs [n, m].min + 1\nm.downto([0, m - n].max).each { |y| puts \"#{m - y} #{y}\" }"}], "negative_code": [{"source_code": "n,m=gets.split(&:to_i)\nk=[n,m].min.to_i+1\nputs k\ni=0\nk.times do\n puts \"#{i} #{i}\"\n i+=1\nend\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nn+=1\nm+=1\nif n n\n\tosy = 0 if osy > m\nend\n\nputs beaty.length\n\nbeaty.each do |e|\n\tputs e.join(' ')\nend"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\nmin = [n,m].min + 1\nputs min\n(0...min).each do |i|\n\tputs \"#{i} #{min - i}\"\nend"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.split.collect{|i| i.to_i}.min\n\nputs n + 1\n\nputs \"0 1\"\nputs \"1 0\"\n\n2.upto(n) { |i| puts \"#{i} #{i}\" }\n"}], "src_uid": "0e99f4a49b408cc8874a6d5ec4167acb"} {"source_code": "s, p = gets.chomp.unpack(\"C*\"), gets.chomp.unpack(\"C*\")\nn, m = s.length, p.length\n\ncnt = Array.new(256,0)\na = \"abcdefghijklmnopqrstuvwxyz?\".unpack(\"C*\")\n\nif n < m\n p 0\n exit\nend\n\nfor i in 0...m\n cnt[s[i]] += 1\n cnt[p[i]] -= 1\nend\n\nans = 0\nfor i in m..n\n tmp = cnt[a[26]]\n for j in 0..25\n tmp -= cnt[a[j]].abs\n end\n ans += 1 if tmp >= 0\n break if i == n\n cnt[s[i]] += 1\n cnt[s[i-m]] -= 1\nend\np ans", "positive_code": [{"source_code": "a=gets.split[0].bytes.to_a\nb=gets.split[0].bytes.to_a\ncntb=Array.new(256,0)\nif a.lengthcntb[i] then\n ok=false\n break\n end\nend\nans+=1 if ok\nfor i in 1..a.length-b.length\n cnta[a[i-1]]-=1\n cnta[a[i+b.length-1]]+=1\n ok=true\n for i in 97..122\n if cnta[i]>cntb[i] then\n ok=false\n break\n end\n end\n ans+=1 if ok\nend\np ans\n"}], "negative_code": [], "src_uid": "9ed2a081b65df66629fcf0d4fc0bb02c"} {"source_code": "n, m = gets.split.map &:to_i\nr = false\nif n > m \n n, m = m, n\n r = true\nend\n\nans = []\nif n == 0\n ans << [0, 1] << [0, m] << [0, 0] << [0, m - 1]\nelsif Math.hypot(n, m) * 2 + m > Math.hypot(n, m) + Math.hypot(m, n - 1) * 2\n ans << [0, 0] << [n, m] << [n, 0] << [0, m]\nelse\n ans << [1, 0] << [n, m] << [0, 0] << [n - 1, m]\nend\n\nans.each{|i|\n if !r\n puts i * ' '\n else\n puts i.reverse * ' '\n end\n}", "positive_code": [{"source_code": "\nn, m = gets.split.map(&:to_i)\nif n == 0 && m == 0\n puts \"0 0\", \"0 0\", \"0 0\", \"0 0\"\nelsif n == 0\n puts \"0 1\", \"0 #{m}\", \"0 0\", \"0 #{m - 1}\"\nelsif m == 0\n puts \"1 0\", \"#{n} 0\", \"0 0\", \"#{n - 1} 0\"\nelse\n bigdiag = Math.sqrt(n * n + m * m)\n ndiag = Math.sqrt((n - 1) * (n - 1) + m * m)\n mdiag = Math.sqrt(n * n + (m - 1) * (m - 1))\n\n if n > m\n ans1 = [n + 2 * bigdiag, [\"0 0\", \"#{n} #{m}\", \"0 #{m}\", \"#{n} 0\"]]\n else\n ans1 = [m + 2 * bigdiag, [\"0 0\", \"#{n} #{m}\", \"#{n} 0\", \"0 #{m}\"]]\n end\n\n if n <= 2 || m <= 2\n puts ans1[1]\n else\n ans2 = [mdiag + ndiag + bigdiag, [\"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"]]\n ans3 = [ndiag + ndiag + bigdiag, [\"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n - 1} #{m}\"]]\n ans4 = [mdiag + mdiag + bigdiag, [\"0 1\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"]]\n\n\n answers = [ans1, ans2, ans3, ans4].sort\n puts answers[-1][1]\n end\nend\n"}, {"source_code": "# Created by Alex\nn, m = gets.split.map{|i| i.to_i}\nif n == 1 && m == 1\n puts '1 1', '0 0', '1 0', '0 1'\n exit 0\nend\nif n == 0\n puts '0 1', \"0 #{m}\", '0 0', \"0 #{m - 1}\"\n exit 0\nend\nif m == 0\n puts '1 0', \"#{n} 0\", '0 0', \"#{n - 1} 0\"\n exit 0\nend\na1 = Math.hypot(n, m) + 2 * [Math.hypot(n - 1, m), Math.hypot(n, m - 1)].max\na2 = Math.hypot(n, m) * 2 + [n, m].max\nif a2 > a1\n if n > m\n puts '0 0', \"#{n} #{m}\", \"0 #{m}\", \"#{n} 0\"\n else\n puts '0 0', \"#{n} #{m}\", \"#{n} 0\", \"0 #{m}\"\n end\nelse\n if Math.hypot(n - 1, m) > Math.hypot(n, m - 1)\n puts '1 0', \"#{n} #{m}\", '0 0', \"#{n - 1} #{m}\"\n else\n puts '0 1', \"#{n} #{m}\", '0 0', \"#{n} #{m - 1}\"\n end\nend"}, {"source_code": "def dist(a, b)\n dx = a[0]-b[0]\n dy = a[1]-b[1]\n Math.sqrt(dx*dx+dy*dy)\nend\n\ndef len(arr)\n dist(arr[0],arr[1]) + dist(arr[1],arr[2]) + dist(arr[2],arr[3])\nend\n\nn, m = gets.strip.split(\" \").map{|x| x.to_i}\n\nif n == 0\n puts \"0 1\"\n puts \"0 #{m}\"\n puts \"0 0\"\n puts \"0 #{m-1}\"\n exit\nend\nif m == 0\n puts \"1 0\"\n puts \"#{n} 0\"\n puts \"0 0\"\n puts \"#{n-1} 0\"\n exit\nend\n\ncandidates = []\n\ncandidates.push [\n [n, m-1],\n [0, 0],\n [n, m],\n [0, 1]\n]\ncandidates.push [\n [n-1, m],\n [0, 0],\n [n, m],\n [1, 0]\n]\ncandidates.push [\n [0, 0],\n [n, m],\n [n, 0],\n [0, m]\n]\ncandidates.push [\n [0, 0],\n [n, m],\n [0, m],\n [n, 0]\n]\n\ncandidates.sort!{|a, b| -(len(a)<=>len(b))}\n\nputs candidates.first.map{|x| x.join(\" \")}\n"}, {"source_code": "n,m=gets.split.map{|i| i.to_i}\nr=false\nif n>m\n\tn,m=m,n\n\tr=true\nend\n\na=[]\nif n==0\n\ta<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]\nelsif Math.sqrt(n**2+m**2)*2+m>(Math.sqrt(n**2+m**2)+2*Math.sqrt(m**2+(n-1)**2))\n\ta<<[0,0]<<[n,m]<<[n,0]<<[0,m]\nelsif \n\ta<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]\nend\na.each{|i| \n\tif !r \n\t\tputs i*' '\n\telse\n\t\tputs i.reverse*' '\n\tend}"}, {"source_code": "n,m = gets.split.map(&:to_i)\ncandidates = (0..n).to_a.product((0..m).to_a).select { |p|\n [p[0]+p[1], p[0]+m-p[1], n-p[0]+p[1], n-p[0]+m-p[1]].min <= 1\n}\nanswer = candidates.permutation(4).max_by { |pl|\n x1 = (Math.hypot(pl[0][0] - pl[1][0], pl[0][1] - pl[1][1]))\n x2 = (Math.hypot(pl[1][0] - pl[2][0], pl[1][1] - pl[2][1]))\n x3 = (Math.hypot(pl[2][0] - pl[3][0], pl[2][1] - pl[3][1]))\n x1 + x2 + x3\n}\nanswer.each { |p|\n puts \"#{p[0]} #{p[1]}\"\n}"}], "negative_code": [{"source_code": "n,m=gets.split.map{|i| i.to_i}\nn,m=m,n if n>m\nputs \"0 1\"\nputs \"#{n} #{m}\"\nputs \"0 0\"\nputs \"#{n} #{m-1}\""}, {"source_code": "n,m=gets.split.map{|i| i.to_i}\nr=false\nif n>m\n\tn,m=m,n\n\tr=true\nend\nif n==m&&n<=2\n\tputs \"#{n} #{m}\\n0 0\\n#{n} 0\\n0 #{m}\\n\"\n\texit\nend\na=[]\nif n==0\n\ta<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]\nelse \n\ta<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]\nend\na.each{|i| \n\tif !r \n\t\tputs i*' '\n\telse\n\t\tputs i.reverse*' '\n\tend}"}, {"source_code": "n,m=gets.split.map{|i| i.to_i}\nn,m=m,n if n>m\nputs \"0 0\"\nputs \"#{n} #{m}\"\nputs \"0 1\"\nputs \"#{n} #{m-1}\""}, {"source_code": "n,m=gets.split.map{|i| i.to_i}\nr=false\nif n>m\n\tn,m=m,n\n\tr=true\nend\nif n==m\n\tputs \"#{n} #{m}\\n0 0\\n#{n} 0\\n0 #{m}\\n\"\n\texit\nend\na=[]\nif n==0\n\ta<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]\nelse \n\ta<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]\nend\na.each{|i| \n\tif !r \n\t\tputs i*' '\n\telse\n\t\tputs i.reverse*' '\n\tend}"}, {"source_code": "n,m=gets.split.map{|i| i.to_i}\nn,m=m,n if n>m\nif n+m==2\n\tputs \"1 1\\n0 0\\n1 0\\n0 1\\n\"\n\texit\nend\n\nputs \"0 1\"\nputs \"#{n} #{m}\"\nputs \"0 0\"\nputs \"#{n} #{m-1}\""}, {"source_code": "n,m=gets.split.map{|i| i.to_i}\nn,m=m,n if n>m\nif n+m==2\n\tputs \"0 1\\n1 1\\n0 0\\n1 0\\n\"\n\texit\nend\n\nputs \"0 1\"\nputs \"#{n} #{m}\"\nputs \"0 0\"\nputs \"#{n} #{m-1}\""}, {"source_code": "n,m=gets.split.map{|i| i.to_i}\nr=false\nif n>m\n\tn,m=m,n\n\tr=true\nend\nif n==m&&n<4\n\tputs \"#{n} #{m}\\n0 0\\n#{n} 0\\n0 #{m}\\n\"\n\texit\nend\na=[]\nif n==0\n\ta<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]\nelse \n\ta<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]\nend\na.each{|i| \n\tif !r \n\t\tputs i*' '\n\telse\n\t\tputs i.reverse*' '\n\tend}"}, {"source_code": "n,m=gets.split.map{|i| i.to_i}\nr=false\nif n>m\n\tn,m=m,n\n\tr=true\nend\nif n+m==2\n\tputs \"1 1\\n0 0\\n1 0\\n0 1\\n\"\n\texit\nend\na=[]\nif n==0\n\ta<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]\nelse \n\ta<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]\nend\na.each{|i| \n\tif !r \n\t\tputs i*' '\n\telse\n\t\tputs i.reverse*' '\n\tend}"}, {"source_code": "n,m=gets.split.map{|i| i.to_i}\nr=false\nif n>m\n\tn,m=m,n\n\tr=true\nend\nif n+m==2\n\tputs \"1 1\\n0 0\\n1 0\\n0 1\\n\"\n\texit\nend\na=[]\nputs r\nif n==0\n\ta<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]\nelse \n\ta<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]\nend\na.each{|i| \n\tif !r \n\t\tputs i*' '\n\telse\n\t\tputs i.reverse*' '\n\tend}"}, {"source_code": "n,m=gets.split.map{|i| i.to_i}\nr=false\nif n>m\n\tn,m=m,n\n\tr=true\nend\nif n+m==2\n\tputs \"1 1\\n0 0\\n1 0\\n0 1\\n\"\n\texit\nend\na=[]\nif n==0\n\ta<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]\nelse \n\ta<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]\nend\na.each{|i| \n\tif r \n\t\tputs i*' '\n\telse\n\t\tputs i.reverse*' '\n\tend}"}, {"source_code": "n,m = gets.split.map(&:to_i)\ncandidates = (0..n).to_a.product((0..m).to_a).select { |p|\n [p[0]+p[1], p[0]+m-p[1], n-p[0]+p[1], n-p[0]+m-p[1]].min <= 1\n}\nanswer = candidates.permutation(4).max_by { |pl|\n Math.hypot(pl[0][0] - pl[1][0], pl[0][1] - pl[1][1])\n + Math.hypot(pl[1][0] - pl[2][0], pl[1][1] - pl[2][1])\n + Math.hypot(pl[2][0] - pl[3][0], pl[2][1] - pl[3][1])\n}\nanswer.each { |p|\n puts \"#{p[0]} #{p[1]}\"\n}"}, {"source_code": "\nn, m = gets.split.map(&:to_i)\nif n == 0 && m == 0\n puts \"0 0\", \"0 0\", \"0 0\", \"0 0\"\nelsif n == 0\n puts \"0 1\", \"0 #{m}\", \"0 0\", \"0 #{m - 1}\"\nelsif m == 0\n puts \"1 0\", \"#{n} 0\", \"0 0\", \"#{n - 1} 0\"\nelsif n > m\n puts \"0 0\", \"#{n} #{m}\", \"0 #{m}\", \"#{n} 0\"\nelse\n puts \"0 0\", \"#{n} #{m}\", \"#{n} 0\", \"0 #{m}\"\nend\n"}, {"source_code": "\nn, m = gets.split.map(&:to_i)\nif n == 0 && m == 0\n puts \"0 0\", \"0 0\", \"0 0\", \"0 0\"\nelsif n == 0\n puts \"0 0\", \"0 #{m}\", \"0 1\", \"0 #{m - 1}\"\nelsif m == 0\n puts \"0 0\", \"#{n} 0\", \"1 0\", \"#{n - 1} 0\"\nelsif n > m\n puts \"0 0\", \"#{n} #{m}\", \"0 #{m}\", \"#{n} 0\"\nelse\n puts \"0 0\", \"#{n} #{m}\", \"#{n} 0\", \"0 #{m}\"\nend\n"}, {"source_code": "\nn, m = gets.split.map(&:to_i)\nif n == 0 && m == 0\n puts \"0 0\", \"0 0\", \"0 0\", \"0 0\"\nelsif n == 0\n puts \"0 1\", \"0 #{m}\", \"0 0\", \"0 #{m - 1}\"\nelsif m == 0\n puts \"1 0\", \"#{n} 0\", \"0 0\", \"#{n - 1} 0\"\nelse\n bigdiag = Math.sqrt(n * n + m * m)\n ndiag = Math.sqrt((n - 1) * (n - 1) + m * m)\n mdiag = Math.sqrt(n * n + (m - 1) * (m - 1))\n\n if n > m\n ans1 = [2 * n + bigdiag, [\"0 0\", \"#{n} #{m}\", \"0 #{m}\", \"#{n} 0\"]]\n else\n ans1 = [2 * m + bigdiag, [\"0 0\", \"#{n} #{m}\", \"#{n} 0\", \"0 #{m}\"]]\n end\n\n if n == 1 || m == 1\n puts ans1[1]\n else\n ans2 = [mdiag + ndiag + bigdiag, [\"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"]]\n ans3 = [ndiag + ndiag + bigdiag, [\"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n - 1} #{m}\"]]\n ans4 = [mdiag + mdiag + bigdiag, [\"0 1\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"]]\n\n answers = [ans1, ans2, ans3, ans4].sort\n puts answers[-1][1]\n end\nend\n"}, {"source_code": "\nn, m = gets.split.map(&:to_i)\nif n == 0 && m == 0\n puts \"0 0\", \"0 0\", \"0 0\", \"0 0\"\nelsif n == 0\n puts \"0 1\", \"0 #{m}\", \"0 0\", \"0 #{m - 1}\"\nelsif m == 0\n puts \"1 0\", \"#{n} 0\", \"0 0\", \"#{n - 1} 0\"\nelse\n bigdiag = Math.sqrt(n * n + m * m)\n ndiag = Math.sqrt((n - 1) * (n - 1) + m * m)\n mdiag = Math.sqrt(n * n + (m - 1) * (m - 1))\n\n ans2 = mdiag + ndiag + bigdiag\n if n > m\n ans1 = 2 * n + bigdiag\n # puts \"1:\", ans1, ans2\n if ans1 > ans2 || n == 1 || m == 1\n puts \"0 0\", \"#{n} #{m}\", \"0 #{m}\", \"#{n} 0\"\n else\n puts \"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"\n end\n else\n ans1 = 2 * m + bigdiag\n # puts \"2:\", ans1, ans2\n if ans1 > ans2 || n == 1 || m == 1\n puts \"0 0\", \"#{n} #{m}\", \"#{n} 0\", \"0 #{m}\"\n else\n puts \"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"\n end\n end\nend\n"}, {"source_code": "\nn, m = gets.split.map(&:to_i)\nif n == 0 && m == 0\n puts \"0 0\", \"0 0\", \"0 0\", \"0 0\"\nelsif n == 0\n puts \"0 1\", \"0 #{m}\", \"0 0\", \"0 #{m - 1}\"\nelsif m == 0\n puts \"1 0\", \"#{n} 0\", \"0 0\", \"#{n - 1} 0\"\nelse\n bigdiag = Math.sqrt(n * n + m * m)\n ndiag = Math.sqrt((n - 1) * (n - 1) + m * m)\n mdiag = Math.sqrt(n * n + (m - 1) * (m - 1))\n\n if n > m\n ans1 = [2 * n + bigdiag, [\"0 0\", \"#{n} #{m}\", \"0 #{m}\", \"#{n} 0\"]]\n else\n ans1 = [2 * m + bigdiag, [\"0 0\", \"#{n} #{m}\", \"#{n} 0\", \"0 #{m}\"]]\n end\n\n puts ans1[1] if n == 1 || m == 1\n\n ans2 = [mdiag + ndiag + bigdiag, [\"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"]]\n ans3 = [ndiag + ndiag + bigdiag, [\"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n - 1} #{m}\"]]\n ans4 = [mdiag + mdiag + bigdiag, [\"0 1\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"]]\n\n answers = [ans1, ans2, ans3, ans4].sort\n puts answers[-1][1]\n\nend\n"}, {"source_code": "\nn, m = gets.split.map(&:to_i)\nif n == 0 && m == 0\n puts \"0 0\", \"0 0\", \"0 0\", \"0 0\"\nelsif n == 0\n puts \"0 1\", \"0 #{m}\", \"0 0\", \"0 #{m - 1}\"\nelsif m == 0\n puts \"1 0\", \"#{n} 0\", \"0 0\", \"#{n - 1} 0\"\nelse\n bigdiag = Math.sqrt(n * n + m * m)\n ndiag = Math.sqrt((n - 1) * (n - 1) + m * m)\n mdiag = Math.sqrt(n * n + (m - 1) * (m - 1))\n\n ans2 = mdiag + ndiag + bigdiag\n if n > m\n ans1 = 2 * n + bigdiag\n # puts \"1:\", ans1, ans2\n if ans1 > ans2 || n == 1 || m || 1\n puts \"0 0\", \"#{n} #{m}\", \"0 #{m}\", \"#{n} 0\"\n else\n puts \"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"\n end\n else\n ans1 = 2 * m + bigdiag\n # puts \"2:\", ans1, ans2\n if ans1 > ans2 || n == 1 || m || 1\n puts \"0 0\", \"#{n} #{m}\", \"#{n} 0\", \"0 #{m}\"\n else\n puts \"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"\n end\n end\nend\n"}, {"source_code": "\nn, m = gets.split.map(&:to_i)\nif n == 0 && m == 0\n puts \"0 0\", \"0 0\", \"0 0\", \"0 0\"\nelsif n == 0\n puts \"0 1\", \"0 #{m}\", \"0 0\", \"0 #{m - 1}\"\nelsif m == 0\n puts \"1 0\", \"#{n} 0\", \"0 0\", \"#{n - 1} 0\"\nelse\n bigdiag = Math.sqrt(n * n + m * m)\n ndiag = Math.sqrt((n - 1) * (n - 1) + m * m)\n mdiag = Math.sqrt(n * n + (m - 1) * (m - 1))\n\n if n > m\n ans1 = [2 * n + bigdiag, [\"0 0\", \"#{n} #{m}\", \"0 #{m}\", \"#{n} 0\"]]\n else\n ans1 = [2 * m + bigdiag, [\"0 0\", \"#{n} #{m}\", \"#{n} 0\", \"0 #{m}\"]]\n end\n\n if n <= 2 || m <= 2\n puts ans1[1]\n else\n ans2 = [mdiag + ndiag + bigdiag, [\"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"]]\n ans3 = [ndiag + ndiag + bigdiag, [\"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n - 1} #{m}\"]]\n ans4 = [mdiag + mdiag + bigdiag, [\"0 1\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"]]\n\n answers = [ans1, ans2, ans3, ans4].sort\n puts answers[-1][1]\n end\nend\n"}, {"source_code": "\nn, m = gets.split.map(&:to_i)\nif n == 0 && m == 0\n puts \"0 0\", \"0 0\", \"0 0\", \"0 0\"\nelsif n == 0\n puts \"0 1\", \"0 #{m}\", \"0 0\", \"0 #{m - 1}\"\nelsif m == 0\n puts \"1 0\", \"#{n} 0\", \"0 0\", \"#{n - 1} 0\"\nelse\n bigdiag = Math.sqrt(n * n + m * m)\n ndiag = Math.sqrt((n - 1) * (n - 1) + m * m)\n mdiag = Math.sqrt(n * n + (m - 1) * (m - 1))\n\n ans2 = mdiag + ndiag + bigdiag\n if n > m\n ans1 = 2 * n + bigdiag\n if ans1 > ans2\n puts \"0 0\", \"#{n} #{m}\", \"0 #{m}\", \"#{n} 0\"\n else\n puts \"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"\n end\n else\n ans1 = 2 * m + bigdiag\n if ans1 > ans2\n puts \"0 0\", \"#{n} #{m}\", \"#{n} 0\", \"0 #{m}\"\n else\n puts \"1 0\", \"#{n} #{m}\", \"0 0\", \"#{n} #{m - 1}\"\n end\n end\nend\n"}, {"source_code": "# Created by Alex\nn, m = gets.split.map{|i| i.to_i}\nif n == 1 && m == 1\n puts '1 1', '0 0', '1 0', '0 1'\n exit 0\nend\nif n == 0\n puts '0 1', \"0 #{m}\", '0 0', \"0 #{m - 1}\"\n exit 0\nend\nif m == 0\n puts '1 0', \"#{n} 0\", '0 0', \"#{n - 1} 0\"\n exit 0\nend\nputs '0 0', \"#{n} #{m}\"\nif n < m\n puts '1 0', \"#{n - 1} #{m}\"\nelse\n puts '0 1', \"#{n} #{m - 1}\"\nend"}], "src_uid": "78d54d76cb113cf74ea89fb77471859b"} {"source_code": "f = STDIN.readline.split.map { |x| x.to_i }\np = Array.new(2) { [] }\n0.upto(1) do |i|\n\ta = f[i]-1\n\tb = 0\n\ta.downto(1) do |a|\n\t\tb += 1 while (b+1)**2 + a**2 <= f[i]**2\n\t\tif a**2 + b**2 == f[i]**2 ;\n\t\t\tp[i] << ( [a,b])\n\t\tend\n\tend\nend\n\n# print p\n\np[0].each do |a|\n\tp[1].each do |b|\n\t\tif a[0]*b[1] == a[1]*b[0] && a[1] != b[0] ;\n\t\t\tprint \"YES\\n\"\n\t\t\tprint \"0 0\\n\"\n\t\t\tprint \"#{a[0]} #{a[1]}\\n\"\n\t\t\tprint \"#{-b[1]} #{b[0]}\\n\"\n\t\t\texit\n\t\tend\n\tend\nend\nprint \"NO\\n\"", "positive_code": [{"source_code": "a,b = gets.split.map(&:to_i)\nans = (1...a).map { |dx|\n dy = Math.sqrt(a * a - dx * dx).to_i\n next if dx * dx + dy * dy != a * a\n dx2 = dy * b / a;\n dy2 = dx * b / a;\n next if dx2 * dx2 + dy2 * dy2 != b * b || dy == dy2\n \n [dx, dy, -dx2, dy2]\n}.select { |d|\n d != nil\n}.first\n\nunless ans\n puts \"NO\"\nelse\n puts \"YES\"\n puts \"0 0\"\n puts ans[0..1].join(\" \")\n puts ans[2..3].join(\" \")\nend\n"}, {"source_code": "x, y = gets.split.map { |x| Integer x }\np1 = 1.0\np2 = 1000.0\nfor i in 1..2000\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n arc = Math.acos(p1 / x)\n arc2 = Math::PI / 2 - arc\n p3 = y * Math.cos(arc2)\n p4 = Math.sqrt (y ** 2 - p3.round ** 2)\n if (p3.round - p3).abs <= 10 ** -9 && (p4 - p4.round).abs <= 10 ** -9\n if [p1, p3, p2, p4].index(0) != nil\n puts 'NO'\n exit\n end\n if p2.round == p4.round\n puts 'YES'\n puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s\n puts '0 0'\n puts p4.round.to_s + ' ' + p3.round.to_s\n exit\n end\n puts 'YES'\n puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s\n puts '0 0'\n puts p3.round.to_s + ' ' + p4.round.to_s\n exit\n end\n p1 += 1\n p2 -= 1\n end\nend\nputs 'NO'\n\n"}, {"source_code": "def pita(a)\n ps = []\n x = 1\n while x * x < a * a\n y = Math.sqrt(a * a - x * x).to_i\n break if y < x\n ps << [x, y] if x * x + y * y == a * a\n x += 1\n end\n ps\nend\n\na, b = gets.split.map(&:to_i)\n# p pita(a)\n# p pita(b)\n# exit\n\n\ndef check(p, q)\n px, py = p\n qx, qy = q\n if px * qx + py * qy == 0 && px != qx && py != qy\n puts :YES\n puts \"0 0\"\n puts \"#{px} #{py}\"\n puts \"#{qx} #{qy}\"\n true\n else\n false\n end\nend\n\nok = false\n\npita(a).each do |px, py|\n pita(b).each do |qx, qy|\n\n if check([px, py], [-qx, qy])\n ok = true\n break\n end\n if check([px, py], [qx, -qy])\n ok = true\n break\n end\n if check([px, py], [-qy, qx])\n ok = true\n break\n end\n if check([px, py], [qy, -qx])\n ok = true\n break\n end\n\n break if ok\n end\n break if ok\nend\n\nif !ok\n puts :NO\nend\n"}, {"source_code": "q=[[],[]]\ngets.split.map(&:to_i).each_with_index{|x,p| (1..x).each{|i|(1..x).each{|j|q[p].push [i,j]if i*i+j*j==x*x}}}\nq[0].each {|i|q[1].each{|j|exit !puts('YES',0,0,i[0],i[1],j[0],-j[1])if i[0]*j[0]==i[1]*j[1]&&i[0]!=j[0]}}\nputs'NO'"}, {"source_code": "a,b = gets.split.map &:to_i\nas = a*a\nbs = b*b\n\nav = []\n1.upto(a-1).each do |x|\n break if as <= x*x\n y = Math.sqrt(as - x*x).round\n #print [x,y]\n if as == x*x + y*y\n av << [x,y] \n end\nend\n\nbv = []\n1.upto(b-1).each do |x|\n break if bs <= x*x\n y = Math.sqrt(bs - x*x).round\n bv << [x,y] if bs == x*x + y*y\nend\n\n#print av\n#print bv\n\nav.each do |as|\n bv.each do |bs|\n x1,y1 = *as\n x2,y2 = *bs\n if x1*x2 == y1*y2 && (x1 != -x2) && (y1 != y2)\n puts \"YES\"\n print \"0 0\\n#{x1} #{y1}\\n-#{x2} #{y2}\\n\"\n exit\n end\n end\nend\n\nputs \"NO\"\n"}, {"source_code": "a,b=gets.split.map &:to_i\nq1,q2=[],[]\ndef cal(x)\n q=[]\n (1..x-1).each{|i| (1..x-1).each{ |j| q.push [i,j] if i*i+j*j==x*x}}\n return q\nend\nq1=cal(a)\nq2=cal(b)\nq1.each do |i|\n q2.each do |j|\n if j[0]*i[0]-j[1]*i[1]==0&&j[0]!=i[0]\n j[1]=-j[1]\n puts 'YES','0 0',i.join(' '),j.join(' ')\n exit\n end\n end\nend\nputs 'NO'"}, {"source_code": "a,b=gets.split.map &:to_i\nq1,q2=[],[]\n(1..a-1).each do |i|\n (1..a-1).each do |j|\n if i*i+j*j==a*a\n q1.push [i,j]\n end\n end\nend\n(1..b-1).each do |i|\n (-(b-1)..-1).each do |j|\n if i*i+j*j==b*b\n q2.push [i,j]\n end\n end\nend\nq1.each do |i|\n q2.each do |j|\n if j[0]*i[0]+j[1]*i[1]==0&&j[0]!=i[0]\n puts 'YES'\n puts '0 0'\n puts i.join' '\n puts j.join' '\n exit\n end\n end\nend\nputs 'NO'"}, {"source_code": "$q=[]\n$q[0],$q[1]=[],[]\ndef cal(x,p)\n (1..x-1).each{|i| (1..x-1).each{|j| $q[p].push [i,j]if i*i+j*j==x*x}}\nend\ngets.split.map(&:to_i).each_with_index{|i,id|cal(i,id)}\n$q[0].each {|i|$q[1].each{|j|exit(!puts('YES',0,0,i[0],i[1],j[0],-j[1]))if i[0]*j[0]==i[1]*j[1]&&i[0]!=j[0]}}\nputs 'NO'"}, {"source_code": "$q=[[],[]]\ndef cal(x,p)\n (1..x).each{|i|(1..x).each{|j|$q[p].push [i,j]if i*i+j*j==x*x}}\nend\ngets.split.map(&:to_i).each_with_index{|i,id|cal(i,id)}\n$q[0].each {|i|$q[1].each{|j|exit !puts('YES',0,0,i[0],i[1],j[0],-j[1])if i[0]*j[0]==i[1]*j[1]&&i[0]!=j[0]}}\nputs'NO'"}, {"source_code": "q=[[],[]]\ngets.split.map(&:to_i).each_with_index{|x,p| (1..x).each{|i|(1..x).each{|j|q[p].push [i,j]if i*i+j*j==x*x}}}\nq[0].each {|i|q[1].each{|j|exit !puts('YES',0,0,i[0],i[1],j[0],-j[1])if i[0]*j[0]==i[1]*j[1]&&i[0]!=j[0]}}\nputs'NO'"}, {"source_code": "$q=[[],[]]\ngets.split.map(&:to_i).each_with_index{|x,p| (1..x).each{|i|(1..x).each{|j|$q[p].push [i,j]if i*i+j*j==x*x}}}\n$q[0].each {|i|$q[1].each{|j|exit !puts('YES',0,0,i[0],i[1],j[0],-j[1])if i[0]*j[0]==i[1]*j[1]&&i[0]!=j[0]}}\nputs'NO'"}], "negative_code": [{"source_code": "x, y = gets.split.map {|x| Integer x}\np1 = 1.0\np2 = 1000.0\nwhile p2 - p1 > 1\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n break\n end\nend\nif p1 ** 2 + p2 ** 2 != x ** 2\n puts 'NO'\n exit\nend\narc = Math.acos(p1 / x)\narc2 = Math::PI / 2 - arc\np3 = y * Math.cos(arc2)\nif (p3.round - p3).abs > 10 ** -8\n puts 'NO'\n exit\nend\np4 = Math.sqrt (y ** 2 - p3.round ** 2)\nif (p4 - p4.round).abs > 10 ** -8\n puts 'NO'\n exit\nend\nif p2.round == p4.round\n puts 'YES'\n puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s\n puts '0 0'\n puts p4.round.to_s + ' ' + p3.round.to_s\n exit\nend\nputs 'YES'\nputs (-p1.to_i).to_s + ' ' + (p2.to_i).to_s\nputs '0 0'\nputs p3.round.to_s + ' ' + p4.round.to_s\n"}, {"source_code": "x, y = gets.split.map {|x| Integer x}\np1 = 1.0\np2 = 1000.0\nwhile p2 - p1 > 1\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n break\n end\nend\nif p1 ** 2 + p2 ** 2 != x ** 2\n puts 'NO'\n exit\nend\narc = Math.acos(p1 / x)\narc2 = Math::PI / 2 - arc\np3 = y * Math.cos(arc2)\nif (p3.round - p3).abs > 10 ** -9\n puts 'NO'\n exit\nend\np4 = Math.sqrt (y ** 2 - p3.round ** 2)\nif (p4 - p4.round).abs > 10 ** 9\n puts 'NO'\n exit\nend\nif p3.round == p4.round\n puts 'NO'\n exit\nend\nputs 'YES'\nputs (-p1.to_i).to_s + ' ' + (p2.to_i).to_s\nputs '0 0'\nputs p3.round.to_s + ' ' + p4.round.to_s\n"}, {"source_code": "x, y = gets.split.map { |x| Integer x }\np1 = 1.0\np2 = 1000.0\nwhile p2 - p1 > 1\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n arc = Math.acos(p1 / x)\n arc2 = Math::PI / 2 - arc\n p3 = y * Math.cos(arc2)\n p4 = Math.sqrt (y ** 2 - p3.round ** 2)\n if (p3.round - p3).abs <= 10 ** -9 && (p4 - p4.round).abs <= 10 ** -9\n if p2.round == p4.round\n puts 'YES'\n puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s\n puts '0 0'\n puts p4.round.to_s + ' ' + p3.round.to_s\n exit\n end\n puts 'YES'\n puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s\n puts '0 0'\n puts p3.round.to_s + ' ' + p4.round.to_s\n exit\n end\n p1 += 1\n p2 -= 1\n end\nend\nputs 'NO'\n\n"}, {"source_code": "x, y = gets.split.map { |x| Integer x }\np1 = 1.0\np2 = 1000.0\nif x % 5 != 0 || y % 5 != 0\n puts 'NO'\n exit\nend\nfor i in 1..2000\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n arc = Math.acos(p1 / x)\n arc2 = Math::PI / 2 - arc\n p3 = y * Math.cos(arc2)\n p4 = Math.sqrt (y ** 2 - p3.round ** 2)\n if (p3.round - p3).abs <= 10 ** -9 && (p4 - p4.round).abs <= 10 ** -9\n if p2.round == p4.round\n puts 'YES'\n puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s\n puts '0 0'\n puts p4.round.to_s + ' ' + p3.round.to_s\n exit\n end\n puts 'YES'\n puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s\n puts '0 0'\n puts p3.round.to_s + ' ' + p4.round.to_s\n exit\n end\n p1 += 1\n end\nend\nputs 'NO'\n\n"}, {"source_code": "x, y = gets.split.map {|x| Integer x}\np1 = 1.0\np2 = 1000.0\nwhile p2 - p1 > 1\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n break\n end\nend\nif p1 ** 2 + p2 ** 2 != x ** 2\n puts 'NO'\n exit\nend\narc = Math.acos(p1 / x)\narc2 = Math::PI / 2 - arc\np3 = y * Math.cos(arc2)\nif (p3.round - p3).abs > 10 ** -9\n puts 'NO'\n exit\nend\np4 = Math.sqrt (y ** 2 - p3.round ** 2)\nif (p4 - p4.round).abs > 10 ** -9\n puts 'NO'\n exit\nend\nif p2.round == p4.round\n puts 'YES'\n puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s\n puts '0 0'\n puts p4.round.to_s + ' ' + p3.round.to_s\n exit\nend\nputs 'YES'\nputs (-p1.to_i).to_s + ' ' + (p2.to_i).to_s\nputs '0 0'\nputs p3.round.to_s + ' ' + p4.round.to_s\n"}, {"source_code": "x, y = gets.split.map {|x| Integer x}\np1 = 1.0\np2 = 1000.0\nwhile p2 - p1 > 1\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n break\n end\nend\nif p1 ** 2 + p2 ** 2 != x ** 2\n puts 'NO'\n exit\nend\narc = Math.acos(p1 / x)\narc2 = Math::PI / 2 - arc\np3 = y * Math.cos(arc2)\nif (p3.round - p3).abs > 10 ** -9\n puts 'NO'\n exit\nend\np4 = Math.sqrt (y ** 2 - p3.round ** 2)\nif (p4 - p4.round).abs > 10 ** 9\n puts 'NO'\n exit\nend\nif x == 5 && y == 5\n puts 'YES'\n puts '2 1'\n puts '5 5'\n puts '-2 4'\n exit\nend\nputs 'YES'\nputs (-p1.to_i).to_s + ' ' + (-p2.to_i).to_s\nputs '0 0'\nputs p3.round.to_s + ' ' + p4.round.to_s\n"}, {"source_code": "x, y = gets.split.map {|x| Integer x}\np1 = 1.0\np2 = 1000.0\nwhile p2 - p1 > 1\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n break\n end\nend\nif p1 ** 2 + p2 ** 2 != x ** 2\n puts 'NO'\n exit\nend\narc = Math.acos(p1 / x)\narc2 = Math::PI / 2 - arc\np3 = y * Math.cos(arc2)\nif (p3.round - p3).abs > 10 ** -9\n puts 'NO'\n exit\nend\np4 = Math.sqrt (y ** 2 - p3.round ** 2)\nif (p4 - p4.round).abs > 10 ** 9\n puts 'NO'\n exit\nend\nputs 'YES'\nputs (-p1.to_i).to_s + ' ' + (-p2.to_i).to_s\nputs '0 0'\nputs p3.round.to_s + ' ' + p4.round.to_s\n"}, {"source_code": "x, y = gets.split.map { |x| Integer x }\np1 = 1.0\np2 = 1000.0\nif x == 1 && y == 1\n puts 'NO'\n exit\nend\nfor i in 1..2000\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n arc = Math.acos(p1 / x)\n arc2 = Math::PI / 2 - arc\n p3 = y * Math.cos(arc2)\n p4 = Math.sqrt (y ** 2 - p3.round ** 2)\n if (p3.round - p3).abs <= 10 ** -9 && (p4 - p4.round).abs <= 10 ** -9\n if p2.round == p4.round\n puts 'YES'\n puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s\n puts '0 0'\n puts p4.round.to_s + ' ' + p3.round.to_s\n exit\n end\n puts 'YES'\n puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s\n puts '0 0'\n puts p3.round.to_s + ' ' + p4.round.to_s\n exit\n end\n p1 += 1\n end\nend\nputs 'NO'\n\n"}, {"source_code": "x, y = gets.split.map { |x| Integer x }\np1 = 1.0\np2 = 1000.0\nfor i in 1..2000\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n arc = Math.acos(p1 / x)\n arc2 = Math::PI / 2 - arc\n p3 = y * Math.cos(arc2)\n p4 = Math.sqrt (y ** 2 - p3.round ** 2)\n if (p3.round - p3).abs <= 10 ** -9 && (p4 - p4.round).abs <= 10 ** -9\n if p2.round == p4.round\n puts 'YES'\n puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s\n puts '0 0'\n puts p4.round.to_s + ' ' + p3.round.to_s\n exit\n end\n puts 'YES'\n puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s\n puts '0 0'\n puts p3.round.to_s + ' ' + p4.round.to_s\n exit\n end\n p1 += 1\n end\nend\nputs 'NO'\n\n"}, {"source_code": "x, y = gets.split.map {|x| Integer x}\np1 = 1.0\np2 = 1000.0\nwhile p2 - p1 > 1\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n break\n end\nend\nif p1 ** 2 + p2 ** 2 != x ** 2\n puts 'NO'\n exit\nend\narc = Math.acos(p1 / x)\narc2 = Math::PI / 2 - arc\np3 = y * Math.cos(arc2)\nif (p3.round - p3).abs > 10 ** -9\n puts 'NO'\n exit\nend\np4 = Math.sqrt (y ** 2 - p3.round ** 2)\nif (p4 - p4.round).abs > 10 ** 9\n puts 'NO'\n exit\nend\nif p2.round == p4.round\n puts 'YES'\n puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s\n puts '0 0'\n puts p4.round.to_s + ' ' + p3.round.to_s\n exit\nend\nputs 'YES'\nputs (-p1.to_i).to_s + ' ' + (p2.to_i).to_s\nputs '0 0'\nputs p3.round.to_s + ' ' + p4.round.to_s\n"}, {"source_code": "x, y = gets.split.map {|x| Integer x}\np1 = 1.0\np2 = 1000.0\nwhile p2 - p1 > 1\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n break\n end\nend\nif p1 ** 2 + p2 ** 2 != x ** 2\n puts 'NO'\n exit\nend\narc = Math.acos(p1 / x)\narc2 = Math::PI / 2 - arc\np3 = y * Math.cos(arc2)\nif (p3.round - p3).abs > 10 ** -9\n puts 'NO'\n exit\nend\np4 = Math.sqrt (y ** 2 - p3.round ** 2)\nif (p4 - p4.round).abs > 10 ** 9\n puts 'NO'\n exit\nend\nif p2.round == p4.round\n puts 'YES'\n puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s\n puts p4.round.to_s + ' ' + p3.round.to_s\n exit\nend\nputs 'YES'\nputs (-p1.to_i).to_s + ' ' + (p2.to_i).to_s\nputs '0 0'\nputs p3.round.to_s + ' ' + p4.round.to_s\n"}, {"source_code": "x, y = gets.split.map {|x| Integer x}\np1 = 1.0\np2 = 1000.0\nwhile p2 - p1 > 1\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n break\n end\nend\nif p1 ** 2 + p2 ** 2 != x ** 2\n puts 'NO'\n exit\nend\narc = Math.acos(p1 / x)\narc2 = Math::PI / 2 - arc\np3 = y * Math.cos(arc2)\nif (p3.round - p3).abs > 10 ** -9\n puts 'NO'\n exit\nend\np4 = Math.sqrt (y ** 2 - p3.round ** 2)\nif (p4 - p4.round).abs > 10 ** 9\n puts 'NO'\n exit\nend\nputs 'YES'\nputs (-p1).to_s + ' ' + (-p2).to_s\nputs '0 0'\nputs p3.round.to_s + ' ' + p4.round.to_s\n"}, {"source_code": "x, y = gets.split.map {|x| Integer x}\np1 = 1.0\np2 = 1000.0\nwhile p2 - p1 > 1\n if p1 ** 2 + p2 ** 2 > x ** 2\n p2 -= 1\n elsif p1 ** 2 + p2 ** 2 < x ** 2\n p1 += 1\n else\n break\n end\nend\nif p1 ** 2 + p2 ** 2 != x ** 2\n puts 'NO'\n exit\nend\narc = Math.acos(p1 / x)\narc2 = Math::PI / 2 - arc\np3 = y * Math.cos(arc2)\nif (p3.round - p3).abs > 10 ** -9\n puts 'NO'\n exit\nend\np4 = Math.sqrt (y ** 2 - p3.round ** 2)\nif (p4 - p4.round).abs > 10 ** 9\n puts 'NO'\n exit\nend\nputs 'YES'\nputs (-p1.to_i).to_s + ' ' + (p2.to_i).to_s\nputs '0 0'\nputs p3.round.to_s + ' ' + p4.round.to_s\n"}, {"source_code": "a,b = gets.split.map &:to_i\nas = a*a\nbs = b*b\n\nav = []\n1.upto(a-1).each do |x|\n break if as <= x*x\n y = Math.sqrt(as - x*x).round\n #print [x,y]\n if as == x*x + y*y\n av << [x,y] \n end\nend\n\nbv = []\n1.upto(b-1).each do |x|\n break if bs <= x*x\n y = Math.sqrt(bs - x*x).round\n bv << [x,y] if bs == x*x + y*y\nend\n\n#print av\n#print bv\n\nav.each do |as|\n bv.each do |bs|\n x1,y1 = *as\n x2,y2 = *bs\n if x1*x2 == y1*y2\n puts \"YES\"\n print \"0 0\\n#{x1} #{y1}\\n-#{x2} #{y2}\\n\"\n exit\n end\n end\nend\n\nputs \"NO\"\n"}, {"source_code": "a,b = gets.split.map &:to_i\nas = a*a\nbs = b*b\n\nav = []\n1.upto(Math.sqrt(a).ceil).each do |x|\n break if as <= x*x\n y = Math.sqrt(as - x*x).round\n #print [x,y]\n if as == x*x + y*y\n av << [x,y] \n end\nend\n\nbv = []\n1.upto(b-1).each do |x|\n break if bs <= x*x\n y = Math.sqrt(bs - x*x).round\n bv << [x,y] if bs == x*x + y*y\nend\n\n#print av\n#print bv\n\nav.each do |as|\n bv.each do |bs|\n x1,y1 = *as\n x2,y2 = *bs\n if x1*x2 == y1*y2\n puts \"YES\"\n print \"0 0\\n#{x1} #{y1}\\n-#{x2} #{y2}\\n\"\n exit\n end\n end\nend\n\nputs \"NO\"\n"}, {"source_code": "$q=[]\n$q[0],$q[1]=[],[]\ndef cal(x,p)\n (1..x-1).each{|i| (1..x-1).each{|j| $q[p].push [i,j]if i*i+j*j==x*x}}\nend\ngets.split.map(&:to_i).each_with_index{|i,id|cal(i,id)}\n$q[0].each {|i|$q[1].each{|j|exit(!puts('YES',0,0,i[0],i[1],-j[0],j[1]))if i[0]*j[0]==i[1]*j[1]&&i[0]!=j[0]}}\nputs 'NO'"}, {"source_code": "a,b=gets.split.map &:to_i\nq1,q2=[],[]\n(1..a-1).each do |i|\n (1..a-1).each do |j|\n if i*i+j*j==a*a\n q1.push [i,j]\n end\n end\nend\n(1..b-1).each do |i|\n (-(b-1)..-1).each do |j|\n if i*i+j*j==b*b\n q2.push [i,j]\n end\n end\nend\nq1.each do |i|\n q2.each do |j|\n if j[0]*i[0]+j[1]*i[1]==0\n puts 'YES'\n puts '0 0'\n puts i.join' '\n puts j.join' '\n exit\n end\n end\nend\nputs 'NO'"}, {"source_code": "a,b=gets.split.map(&:to_i)\n$q=[]\n$q[0]=$q[1]=[]\ndef cal(x,p)\n (1..x-1).each{|i| (1..x-1).each{ |j| $q[p].push [i,j] if i*i+j*j==x*x}}\nend\ncal(a,0)\ncal(b,1)\n$q[0].each {|i|$q[1].each{|j| exit(!puts('YES',0,0,i[0],i[1],-j[0],j[1])) if i[0]*j[0]==i[1]*j[1]}}\nputs 'NO'"}, {"source_code": "f = STDIN.readline.split.map { |x| x.to_i }\np = Array.new(2) { [] }\n0.upto(1) do |i|\n\ta = f[i]-1\n\tb = 0\n\ta.downto(1) do |a|\n\t\tb += 1 while (b+1)**2 + a**2 <= f[i]**2\n\t\tif a**2 + b**2 == f[i]**2 ;\n\t\t\tp[i] << ( [a,b])\n\t\tend\n\tend\nend\n\n# print p\n\np[0].each do |a|\n\tp[1].each do |b|\n\t\tif a[0]*b[1] == a[1]*b[0] ;\n\t\t\tprint \"YES\\n\"\n\t\t\tprint \"0 0\\n\"\n\t\t\tprint \"#{a[0]} #{a[1]}\\n\"\n\t\t\tprint \"#{-b[1]} #{b[0]}\\n\"\n\t\t\texit\n\t\tend\n\tend\nend\nprint \"NO\\n\""}, {"source_code": "f = STDIN.readline.split.map { |x| x.to_i }\np = Array.new(2) { [] }\n0.upto(1) do |i|\n\ta = f[i]-1\n\tb = 0\n\ta.downto(1) do |a|\n\t\tb += 1 while (b+1)**2 + a**2 <= f[i]**2\n\t\tif a**2 + b**2 == f[i]**2 ;\n\t\t\tp[i] << ( [a,b])\n\t\tend\n\tend\nend\n\n# print p\n\np[0].each do |a|\n\tp[1].each do |b|\n\t\tif a[0]*b[1] == a[1]*b[0] && a[1] != b[1] ;\n\t\t\tprint \"YES\\n\"\n\t\t\tprint \"0 0\\n\"\n\t\t\tprint \"#{a[0]} #{a[1]}\\n\"\n\t\t\tprint \"#{-b[1]} #{b[0]}\\n\"\n\t\t\texit\n\t\tend\n\tend\nend\nprint \"NO\\n\""}, {"source_code": "def pita(a)\n ps = []\n (1...a * a).each do |x|\n break if a * a - x * x <= 0\n y = Math.sqrt(a * a - x * x).to_i\n break if y < x\n if x * x + y * y == a * a\n ps << [x, y]\n end\n end\n # p ps\n ps\nend\n\na, b = gets.split.map(&:to_i)\n# p pita(a)\n# p pita(b)\n# exit\n\nok = false\n\npita(a).each do |px, py|\n pita(b).each do |qx, qy|\n\n\n if px * qx - py * qy == 0\n ok = true\n puts \"0 0\"\n puts \"#{px} #{py}\"\n puts \"#{-qx} #{qy}\"\n break\n end\n\n if px * qy - py * qx == 0\n puts \"0 0\"\n puts \"#{px} #{py}\"\n puts \"#{-qy} #{qx}\"\n ok = true\n break\n end\n\n break if ok\n end\n break if ok\nend\n\nif !ok\n puts :NO\nend\n"}, {"source_code": "def pita(a)\n ps = []\n x = 1\n while x * x < a * a\n y = Math.sqrt(a * a - x * x).to_i\n break if y < x\n ps << [x, y] if x * x + y * y == a * a\n x += 1\n end\n ps\nend\n\na, b = gets.split.map(&:to_i)\n# p pita(a)\n# p pita(b)\n# exit\n\nok = false\n\npita(a).each do |px, py|\n pita(b).each do |qx, qy|\n\n if px * qx - py * qy == 0\n ok = true\n puts :YES\n puts \"0 0\"\n puts \"#{px} #{py}\"\n puts \"#{-qx} #{qy}\"\n break\n end\n\n if px * qy - py * qx == 0\n puts :YES\n puts \"0 0\"\n puts \"#{px} #{py}\"\n puts \"#{-qy} #{qx}\"\n ok = true\n break\n end\n\n break if ok\n end\n break if ok\nend\n\nif !ok\n puts :NO\nend\n"}], "src_uid": "a949ccae523731f601108d4fa919c112"} {"source_code": "n, d, m = gets.split.map(&:to_i)\ny = n / 2\nx = n - y\nd -= x - y\na = Array.new(n) do |i|\n t = i.odd? == (d > 0) ? 0 : [d.abs, m - 1].min\n if d > 0\n d -= t\n else\n d += t\n end\n t + 1\nend\nputs d == 0 ? a * ' ' : -1\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\nn, d, lim = STDIN.readline.split.collect {|s| s.to_i }\narr = n.times.map {|i| i%2 == 0 ? 1 : lim }\ny = n / 2\nx = n - y\nmin = x - y*lim\nmax = x*lim - y\nif d < min or d > max\n\tputs -1\nelse\n\tneed = d - min\n\tn.times do |i|\n\t\tdelta = [need, lim-1].min\n\t\tif i%2 == 0\n\t\t\tarr[i] += delta\n\t\telse\n\t\t\tarr[i] -= delta\n\t\tend\n\t\tneed -= delta\n\t\tbreak if need == 0\n\tend\n\tputs arr.join(' ')\nend\n"}, {"source_code": "n, d, l = gets.split.map(&:to_i)\n\nxl = (n+1)/2\nyl = n/2\nsum = (xl-yl)*l - d\n\nx = Array.new(xl, l)\ny = Array.new(yl, l)\n\nwhile sum != 0\n if 0 < sum\n if x.count(1) == xl\n x = [-1]; y = []\n break\n end\n\n x[x.index{|v| 1 < v }] -= 1\n end\n\n if sum < 0\n if y.count(1) == yl\n x = [-1]; y = []\n break\n end\n y[y.index{|v| 1 < v }] -= 1 if sum < 0\n end\n\n sum = sum / sum.abs * (sum.abs - 1)\nend\n\nputs x.zip(y).flatten.compact.join(\" \")\n"}, {"source_code": "#!/usr/bin/ruby\ninclude Math\nn,d,l = gets.split.map(&:to_i)\n#puts [n,d,l].join ' '\nmins = [1]\nmaxs = [l]\n(n-1).times do |i|\n maxs[i+1] = l-mins[i]\n mins[i+1] = 1-maxs[i]\nend\n#p maxs\n#p mins\ndef solve (d,l,mx,mn)\n #puts 'err' if x>l\n if(d>0) then return [l,d+mx].min\n else return [1,d+mn].max\n end\nend\nif d < mins.last || d > maxs.last\n puts -1\nelsif l==1\n puts Array.new(n,1).join ' '\nelse\n ans = []\n (n-1).times do |i|\n ans << solve(d,l,maxs[-i-2],mins[-i-2])\n d = ans.last-d\n# p [ans.last,d]\n end\n ans << d\n puts ans.join ' '\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ninput = gets.chomp.split(' ').map { |e| e.to_i }\nn = input[0]\nd = input[1]\nl = input[2]\nresAns = Array.new(n, 1)\n\nd -= n % 2\n\neven = true\nfor i in (0..(n-1)) do\n\tif even && d > 0\n\t\tresAns[i] += [l - 1, d].min\n\t\td -= (resAns[i] - 1)\n\tend\n\tif !even && d < 0\n\t\tresAns[i] += [l - 1, -d].min\n\t\td += (resAns[i] - 1)\n\tend\n\teven = !even\nend\n\nif d != 0 \n\tputs -1\n\texit\nend\n\nputs resAns.join(' ')"}, {"source_code": "a,b,c = gets.chomp.split(/ /).map!{|x| x.to_i}\npnum = a / 2\nmnum = pnum\nif a % 2 == 1\n pnum += 1\nend\nar = []\nfor i in 0..a-1\n ar[i] = 1\nend\nipb = false\nif b > 0\n wksum = b + mnum - pnum\n i = 1\n while wksum > 0\n ar[i - 1] += 1\n if ar[i-1] > c\n ipb = true\n break\n end\n wksum -= 1\n i += 1\n i += 1 if i % 2 == 0\n i = 1 if (i > a)\n end\nelse\n wksum = -(b - pnum) - mnum\n i = 2\n while wksum > 0\n ar[i - 1] += 1\n if ar[i-1] > c\n ipb = true\n break\n end\n wksum -= 1\n i += 1\n i += 1 if i % 2 == 1\n i = 2 if (i > a)\n end\nend\nif ipb\n puts \"-1\"\nelse\n puts ar.join(\" \")\nend\n"}], "negative_code": [{"source_code": "n, d, l = gets.split.map(&:to_i)\n\nxl, yl = (n+1)/2, n/2\nsum = (xl-yl)*l-d\nx, y = Array.new(xl, l), Array.new(yl, l)\n\n(0 < sum ? x : y).map! do |v|\n v = [1, v-sum.abs].max\n sum = (sum/sum.abs)*(sum.abs-[l-1, sum.abs].min) if sum != 0\n v\nend\n\nx, y = [-1], [] if 0 < sum\n\nputs x.zip(y).flatten.compact.join(\" \")"}, {"source_code": "n, d, l = gets.split.map(&:to_i)\n\nxl, yl = (n+1)/2, n/2\nsum = (xl-yl)*l-d\nx, y = Array.new(xl, l), Array.new(yl, l)\n\n(0 < sum ? x : y).map! do |v|\n v = [1, v-sum.abs].max\n sum = (sum/sum.abs)*(sum.abs-[l-1, sum.abs].min) if sum != 0\n v\nend\n\nputs x.zip(y).flatten.compact.join(\" \")"}, {"source_code": "#!/usr/bin/ruby\ninclude Math\nn,d,l = gets.split.map(&:to_i)\n#puts [n,d,l].join ' '\nmins = [1]\nmaxs = [l]\n(n-1).times do |i|\n maxs[i+1] = l-mins[i]\n mins[i+1] = 1-maxs[i]\nend\ndef solve (d,l,mn,mx)\n #puts 'err' if x>l\n if(d>0) then return [l,d+mx].min\n else return [1,d+mn].max\n end\nend\nif d < mins.last || d > maxs.last\n puts -1\nelsif l==1\n puts Array.new(n,1).join ' '\nelse\n ans = []\n (n-1).times do |i|\n ans << solve(d,l,maxs[-i-2],mins[-i-2])\n d = ans.last-d\n# p [ans.last,d]\n end\n ans << d\n puts ans.join ' '\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ninput = gets.chomp.split(' ').map { |e| e.to_i }\nn = input[0]\nd = input[1]\nl = input[2]\nresAns = Array.new(n, 1)\n\nif d == 0 && n % 2 == 1\n\tputs -1\n\texit 0\nend\t\n\nd -= n % 2\n\neven = true\nfor i in (0..(n-1)) do\n\tif even && d > 0\n\t\tresAns[i] += [l - 1, d].min\n\t\td -= (resAns[i] - 1)\n\tend\n\tif !even && d < 0\n\t\tresAns[i] += [l - 1, -d].min\n\t\td += (resAns[i] - 1)\n\tend\n\teven = !even\nend\n\nif d != 0 \n\tputs -1\n\texit\nend\n\nputs resAns.join(' ')"}], "src_uid": "a20d59a0db07cbb5692f01d28e41a3a1"} {"source_code": "# coding: utf-8\n\nn, m = gets.split.map(&:to_i) # m cols, n rows\ntoggle = true\nmap = { true => 'B', false => 'W'}\nbuffer = []\nn.times {\n gets.chomp.split(//).each { |c|\n if c == \".\"\n buffer << map[toggle]\n else\n buffer << c\n end\n toggle = !toggle\n }\n buffer << \"\\n\"\n\n if m.even?\n toggle = !toggle # prevent cyclic\n end\n}\nbuffer.pop # remove last \\n\nputs buffer.join('')\n", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\na = n.times.map{gets.chomp}\nn.times do |i|\n m.times do |j|\n a[i][j] = 'BW'[(i + j) % 2] if a[i][j] == '.'\n end\nend\nputs a\n"}, {"source_code": "# Read Input\nn, m = gets.strip.split.map{|s| s.to_i}\nboard = []; n.times {board.push(gets.strip.split(\"\"))};\n\n# Print Board\nfor i in 0..(n - 1) do\n for j in 0..(m - 1) do\n if board[i][j] == \".\"\n print ((i + j) % 2 == 0 ? 'B' :'W')\n else \n print \"-\"\n end\n end\n puts \"\"\nend"}, {"source_code": "def best(i,j)\n if i.odd? && j.odd?\n return \"B\"\n elsif i.odd? && j.even?\n return \"W\"\n elsif i.even? && j.odd?\n return \"W\"\n else\n return \"B\"\n end\nend\n\nn, m = gets.strip.split.map{|s| s.to_i}\n\nboard = []; n.times {board.push(gets.strip.split(\"\"))};\n\nfor i in 0..(n - 1) do\n for j in 0..(m - 1) do\n if board[i][j] == \".\"\n print best(i,j) \n else \n print \"-\"\n end\n end\n puts \"\"\nend"}, {"source_code": "\ndef best(i,j)\n if (i + j).odd?\n return \"W\"\n else\n return \"B\"\n end\nend\n\nn, m = gets.strip.split.map{|s| s.to_i}\n\nboard = []; n.times {board.push(gets.strip.split(\"\"))};\n\nfor i in 0..(n - 1) do\n for j in 0..(m - 1) do\n if board[i][j] == \".\"\n print best(i,j) \n else \n print \"-\"\n end\n end\n puts \"\"\nend"}, {"source_code": "line=gets\nn=line.split[0].to_i\nm=line.split[1].to_i\n\nfor i in 0...n do\n\tline=gets\n\tfor j in 0...m do\n\t\tif line[j]=='.'\n\t\t\tif((i+j)%2==0)\n\t\t\t\tline[j]='B'\n\t\t\telse\n\t\t\t\tline[j]='W'\n\t\t\tend\n\t\tend\n\tend\n\tputs line\nend\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\na=[]\nn.times { a << gets.chomp }\nn.times do |i|\n m.times do |j|\n if a[i][j]=='.'\n print ((i+j)%2==0?'B':'W')\n else\n print '-'\n end\n end\n puts\nend\n"}, {"source_code": "s = gets.split(\" \")\nn = s[0].to_i\nm = s[1].to_i\na = []\nfor i in 0..n -1\n s = gets.chomp\n a[i] = s\nend\n\nfor i in 0..n-1\n for j in 0..m-1\n\n if( (i + j) % 2 == 1 && a[i][j]==\".\")\n a[i][j] = \"B\"\n elsif a[i][j]==\".\"\n a[i][j] = \"W\"\n end\n end\n end\n rez = \"\"\n for i in 0..n-1\n for j in 0..m-1\n rez += a[i][j]\nend\n rez += \"\\n\"\nend\nputs(rez)"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\noutput = \"\"\n(0..n-1).each do |i|\n line = gets\n (0..m-1).each do |j|\n if line[j] == '-'\n output += '-'\n elsif (i+j) % 2 == 0\n output +='B'\n else\n output += 'W'\n end\n end\n output += \"\\n\"\nend\nputs output"}, {"source_code": "# 445A\n\nn, m = gets.chomp.split.map &:to_i\nch = []\nn.times do\n ch << gets.chomp.chars\nend\nnn = n - 1\nmm = m - 1\nn.times do |i|\n m.times do |j|\n if ch[i][j] == '.'\n stack = [[i, j]]\n until stack.empty?\n p, q = stack[-1]\n ch[p][q] = (p > 0 && ch[p - 1][q] == 'W') || (q > 0 && ch[p][q - 1] == 'W') ||\n (p < nn && ch[p + 1][q] == 'W') || (q < mm && ch[p][q + 1] == 'W') ? 'B' : 'W'\n if p < nn && ch[p + 1][q] == '.'\n stack.push [p + 1, q]\n elsif q < mm && ch[p][q + 1] == '.'\n stack.push [p, q + 1]\n elsif p > 0 && ch[p - 1][q] == '.'\n stack.push [p - 1, q]\n elsif q > 0 && ch[p][q - 1] == '.'\n stack.push [p, q - 1]\n else\n stack.pop\n end\n end\n end\n end\nend\nch.each { |l| puts l.join('') }"}, {"source_code": "\n\nn, m = gets.split.map(&:to_i)\n\ntab = []\nn.times{tab << gets.strip.split(//)}\n\nresult = []\n\n(0..n-1).each do |i|\n result << []\n (0..m-1).each do |j|\n if tab[i][j] == '-'\n result[-1] << '-'\n elsif (i+j) % 2 == 1\n result[-1] << 'W'\n else\n result[-1] << 'B'\n end\n end\nend\n\nresult.each{|x| puts x.join(\"\")}\n\n\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\n(0...n).each do |x|\n ar = gets.chomp\n (0...m).each do |y|\n if ( ar[y] == '-' )\n print '-'\n elsif ( (x+y)%2==0 )\n print 'B'\n else\n print 'W'\n end\n end\n print \"\\n\"\nend"}, {"source_code": "r, c = gets.split.map(&:to_i)\nchessboard=[]\nfor i in 1..r do\n\tx = gets\n\tchessboard << x\nend\nfor i in 0...r do\n\tfor j in 0...c do\n\t if chessboard[i][j]=='-' then\n\t \tnext\n\t elsif ((i+j)%2==0)\n\t \tchessboard[i][j]='B'\n\t\telse\n\t\t\tchessboard[i][j]='W'\n\t\tend\n\tend\nend\nputs chessboard"}, {"source_code": "n,m=gets.split.map(&:to_i)\na=[]\nn.times do |i|\n\tj=0\n\tfor x in gets.strip.split('')\n\t\tif x=='-'\n\t\t\ta='-'\n\t\telsif (i+j)&1!=0\n\t\t\ta='B';\n\t\telse\n\t\t\ta='W'\n\t\tend\n\t\tj+=1\n\t\tprint a\n\tend\n\tputs\nend"}, {"source_code": "n,m=gets.split.map(&:to_i)\nn.times{|i|\n\ts=gets.chop\n\t(0..s.size-1).each{|j|\n\t\tnext if s[j] != '.'\n\t\ts[j]=( (i+j)%2 == 1 ? 'B' : 'W' )\n\t}\n\tputs s\n}"}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\nboard = []\nn.times do\n line = gets.chomp\n line = line.gsub '.', 'B'\n board << line\nend\nn.times do |i|\n m.times do |j|\n if (i + j).odd? && board[i][j] != '-'\n board[i][j] = 'W'\n end\n end\nend\nboard.each do |line|\n puts line\nend\n"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nn.times{|i|\n\ts=gets.chomp\n\tm.times{|j|\n\t\tif s[j]==\"-\" then\n\t\t\tprint \"-\"\n\t\telse\n\t\t\tprint \"BW\"[(i+j)%2]\n\t\tend\n\t}\n\tprint \"\\n\"\n}\n"}, {"source_code": "numbers = gets.split(' ')\nn = numbers[0].to_i\nm = numbers[1].to_i\n\nboard = []\nn.times do\n row = gets.split('')\n row.pop\n board.push row\nend\n\nboard.each_index do |i|\n board[i].each_index do |j|\n next if board[i][j] == '-'\n if (i + j) % 2 == 0\n board[i][j] = 'B'\n else\n board[i][j] = 'W'\n end\n end\nend\n\nboard.each do |row|\n row.each do |cell|\n print cell\n end\n puts\nend"}, {"source_code": "\nn,m = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.split(\"\")\nend\na = true\nb = true\n(0..n-1).each do |i|\n\tb = a\n\t(0..m-1).each do |j|\n\t\t# if arr[i][j] == '.'\t\t\t\n\t\t# \tcandidate = a ? 'B' : 'W'\n\t\t# \tif i > 0 && arr[i-1][j] != '-'\n\t\t# \t\tcandidate = borw(arr[i-1][j])\n\t\t# \tend\n\n\t\t# \tif j > 0 && arr[i][j-1] != '-'\n\t\t# \t\tcandidate = borw(arr[i][j-1])\n\t\t# \tend\n\t\t# \tarr[i][j] = candidate\n\t\t# \ta = !a\n\t\t# end\n\t\t\n\t\tif arr[i][j] != '-'\n\t\t\tarr[i][j] = b ? 'B' : 'W'\n\t\tend\n\n\t\tb = !b\n\tend\n\ta = !a\nend\n\narr.each do |a|\n\tputs a.join(\"\")\nend"}], "negative_code": [{"source_code": "r, c = gets.split.map(&:to_i)\nchessboard=[]\nfor i in 1..r do\n\tx = gets\n\tchessboard << x\nend\n#puts chessboard\nfor i in 0...r do\n\tfor j in 0...c do\n\t if chessboard[i][j]=='-' then\n\t \tnext\n\t\telsif chessboard[i-1][j]=='B' || chessboard[i][j-1]=='B' then\n\t\t\tchessboard[i][j]='W'\n\t\telse\n\t\t\tchessboard[i][j]='B'\n\t\tend\n\n\tend\nend\n\nputs chessboard"}, {"source_code": "r, c = gets.split.map(&:to_i)\nchessboard=[]\nfor i in 1..r do\n\tx = gets\n\tchessboard << x\nend\nn='B'\n#puts chessboard\nfor i in 0...r do\n\tfor j in 0...c do\n\t\t#puts \"This is n: #{n}\"\n\t if chessboard[i][j]=='-' then\n\t \tnext\n\t elsif (chessboard[i-1][j]=='-' || i-1<0) && (chessboard[i][j-1]=='-' || j-1<0) then\n\t \t#puts \"here\"\n\t \tchessboard[i][j]=n\n\t \tif n=='W' then\n\t \t\t n='B'\n\t \telse\n\t \t\tn='W'\n\t \tend\n\t\telsif chessboard[i-1][j]=='B' || chessboard[i][j-1]=='B' then\n\t\t\tchessboard[i][j]='W'\n\t\t\tn='B'\n\t\telse\n\t\t\tchessboard[i][j]='B'\n\t\t\tn='W'\n\t\tend\n\tend\nend\n\nputs chessboard"}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\nboard = []\nn.times do\n board << gets.chomp\nend\nadjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]\nmen = ['B', 'W']\nn.times do |i|\n m.times do |j|\n cell = board[i][j]\n men.each_index do |index|\n man = men[index]\n board[i][j] = man if cell == '.'\n adjacent.each do |adj|\n di = i + adj[0]\n dj = j + adj[1]\n next if di < 0 || dj < 0 || di == n || dj == m\n neighbor = board[di][dj]\n if neighbor == '.'\n if cell == 'B'\n board[di][dj] = men[1]\n else\n board[di][dj] = men[0]\n end\n end\n end\n end\n end\nend\nboard.each do |line|\n puts line\nend\n"}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\nboard = []\nn.times do\n line = gets.chomp\n line = line.gsub '.', 'B'\n board << line\nend\nadjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]\nn.times do |i|\n m.times do |j|\n cell = board[i][j]\n adjacent.each do |adj|\n di = i + adj[0]\n dj = j + adj[1]\n next if di < 0 || dj < 0 || di == n || dj == m\n board[di][dj] = 'W' if cell == 'B' && board[di][dj] == cell\n board[di][dj] = 'B' if cell == 'W' && board[di][dj] == cell\n end\n end\nend\nboard.each do |line|\n puts line\nend\n"}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\nboard = []\nn.times do\n board << gets.chomp\nend\nadjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]\nmen = ['B', 'W']\nn.times do |i|\n m.times do |j|\n men.each_index do |index|\n man = men[index]\n board[i][j] = man if board[i][j] == '.'\n cell = board[i][j]\n adjacent.each do |adj|\n di = i + adj[0]\n dj = j + adj[1]\n next if di < 0 || dj < 0 || di == n || dj == m\n neighbor = board[di][dj]\n if neighbor == '.'\n if cell == 'B'\n board[di][dj] = men[1]\n elsif cell == 'W'\n board[di][dj] = men[0]\n end\n elsif neighbor == cell && cell != '-'\n if cell == 'B'\n board[di][dj] = men[1]\n elsif cell == 'W'\n board[di][dj] = men[0]\n end\n end\n end\n end\n end\nend\nboard.each do |line|\n puts line\nend\n"}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\nboard = []\nn.times do\n line = gets.chomp\n line = line.gsub '.', 'B'\n board << line\nend\nadjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]\nn.times do |i|\n m.times do |j|\n cell = board[i][j]\n adjacent.each do |adj|\n di = i + adj[0]\n dj = j + adj[1]\n next if di < 0 || dj < 0 || di == n || dj == m\n neighbor = board[di][dj]\n board[di][dj] = 'W' if cell == 'B' && neighbor == cell\n board[di][dj] = 'B' if cell == 'W' && neighbor == cell\n end\n end\nend\nboard.each do |line|\n puts line\nend\n"}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\nboard = []\nn.times do\n board << gets.chomp\nend\nadjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]\nn.times do |i|\n m.times do |j|\n board[i][j] = 'B' if board[i][j] == '.'\n cell = board[i][j]\n adjacent.each do |adj|\n di = i + adj[0]\n dj = j + adj[1]\n next if di < 0 || dj < 0 || di == n || dj == m\n neighbor = board[di][dj]\n if neighbor == '.'\n if cell == 'B'\n board[di][dj] = 'W'\n elsif cell == 'W'\n board[di][dj] = 'B'\n end\n elsif neighbor == cell && cell != '-'\n if cell == 'B'\n board[di][dj] = 'W'\n elsif cell == 'W'\n board[di][dj] = 'B'\n end\n end\n end\n end\nend\nboard.each do |line|\n puts line\nend\n"}, {"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\nboard = []\nn.times do\n board << gets.chomp\nend\nadjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]\nmen = ['B', 'W']\nn.times do |i|\n m.times do |j|\n men.each_index do |index|\n man = men[index]\n board[i][j] = man if board[i][j] == \".\"\n cell = board[i][j]\n adjacent.each do |adj|\n di = i + adj[0]\n dj = j + adj[1]\n next if di < 0 || dj < 0 || di == n || dj == m\n neighbor = board[di][dj]\n if neighbor == \".\"\n if cell == 'B'\n board[di][dj] = men[1]\n elsif cell == 'W'\n board[di][dj] = men[0]\n end\n elsif neighbor == cell\n if cell == 'B'\n board[di][dj] = men[1]\n elsif cell == 'W'\n board[di][dj] = men[0]\n end\n end\n end\n end\n end\nend\nboard.each do |line|\n puts line\nend\n"}, {"source_code": "numbers = gets.split(' ')\nn = numbers[0].to_i\nm = numbers[1].to_i\n\nboard = []\nn.times do\n row = gets.split('')\n row.pop\n board.push row\nend\n\nboard.each_index do |i|\n board[i].each_index do |j|\n next if board[i][j] == '-'\n if i == 0\n if j == 0\n board[i][j] = 'B'\n else\n if board[i][j - 1] == 'B'\n board[i][j] = 'W'\n else\n board[i][j] = 'B'\n end\n end\n else\n if j == 0\n if board[i - 1][j] == 'B'\n board[i][j] = 'W'\n else\n board[i][j] = 'B'\n end\n else\n if board[i - 1][j] == 'B' || board[i][j - 1] == 'B'\n board[i][j] = 'W'\n else\n board[i][j] = 'B'\n end\n end\n end\n end\nend\n\nboard.each do |row|\n row.each do |cell|\n print cell\n end\n puts\nend"}, {"source_code": "numbers = gets.split(' ')\nn = numbers[0].to_i\nm = numbers[1].to_i\n\nboard = []\nn.times do\n row = gets.split('')\n row.pop\n board.push row\nend\n\nboard.each_index do |i|\n board[i].each_index do |j|\n next if board[i][j] == '-'\n if i == 0\n if j == 0\n board[i][j] = 'B'\n else\n if board[i][j - 1] == 'B'\n board[i][j] = 'W'\n else\n board[i][j] = 'B'\n end\n end\n else\n if j == 0\n if board[i - 1][j] == 'B'\n board[i][j] = 'W'\n else\n board[i][j] = 'B'\n end\n else\n if board[i - 1][j] == 'B'\n board[i][j] = 'W'\n else\n board[i][j] = 'B'\n end\n end\n end\n end\nend\n\nboard.each do |row|\n row.each do |cell|\n print cell\n end\n puts\nend"}, {"source_code": "def borw(c)\n\tif c == 'B'\n\t\t'W'\n\telse\n\t\t'B'\n\tend\nend\n\nn,m = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.split(\"\")\nend\na = true\n(0..n-1).each do |i|\n\t(0..m-1).each do |j|\n\t\tif arr[i][j] == '.'\t\t\t\n\t\t\tcandidate = a ? 'B' : 'W'\n\t\t\tif i > 0 && arr[i-1][j] != '-'\n\t\t\t\tcandidate = borw(arr[i-1][j])\n\t\t\tend\n\n\t\t\tif j > 0 && arr[i][j-1] != '-'\n\t\t\t\tcandidate = borw(arr[i][j-1])\n\t\t\tend\n\t\t\tarr[i][j] = candidate\n\t\t\ta = !a\n\t\tend\n\tend\nend\n\narr.each do |a|\n\tputs a.join(\"\")\nend"}, {"source_code": "def borw(c)\n\tif c == 'B'\n\t\t'W'\n\telse\n\t\t'B'\n\tend\nend\n\nn,m = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.split(\" \")\nend\n\n(0..n-1).each do |i|\n\t(0..m-1).each do |j|\n\t\tif arr[i][j] == '.'\t\t\t\n\t\t\tcandidate = 'B'\n\t\t\tif i > 0\n\t\t\t\tcandidate = borw(arr[i-1][j])\n\t\t\tend\n\n\t\t\tif j > 0\n\t\t\t\tcandidate = borw(arr[i][j-1])\n\t\t\tend\n\t\t\tarr[i][j] = candidate\n\t\tend\n\tend\nend\n\narr.each do |a|\n\tputs a.join(\"\")\nend"}, {"source_code": "def borw(c)\n\tif c == 'B'\n\t\t'W'\n\telse\n\t\t'B'\n\tend\nend\n\nn,m = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.split(\"\")\nend\n\n(0..n-1).each do |i|\n\t(0..m-1).each do |j|\n\t\tif arr[i][j] == '.'\t\t\t\n\t\t\tcandidate = 'B'\n\t\t\tif i > 0 && arr[i-1][j] != '-'\n\t\t\t\tcandidate = borw(arr[i-1][j])\n\t\t\tend\n\n\t\t\tif j > 0 && arr[i][j-1] != '-'\n\t\t\t\tcandidate = borw(arr[i][j-1])\n\t\t\tend\n\t\t\tarr[i][j] = candidate\n\t\tend\n\tend\nend\n\narr.each do |a|\n\tputs a.join(\"\")\nend"}, {"source_code": "def borw(c)\n\tif c == 'B'\n\t\t'W'\n\telse\n\t\t'B'\n\tend\nend\n\nn,m = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.split(\"\")\nend\n\n(0..n-1).each do |i|\n\t(0..m-1).each do |j|\n\t\tif arr[i][j] == '.'\t\t\t\n\t\t\tcandidate = 'B'\n\t\t\tif i > 0\n\t\t\t\tcandidate = borw(arr[i-1][j])\n\t\t\tend\n\n\t\t\tif j > 0\n\t\t\t\tcandidate = borw(arr[i][j-1])\n\t\t\tend\n\t\t\tarr[i][j] = candidate\n\t\tend\n\tend\nend\n\narr.each do |a|\n\tputs a.join(\"\")\nend"}, {"source_code": "n, m = gets.chomp.split.map &:to_i\nr = []\nq = nil\nn.times do |_|\n p = gets.chomp.chars\n (0...m).each { |j| p[j] = q[j] == 'B' ? 'W' : 'B' unless p[j] == '-' || q[j] == '-' } unless q.nil?\n (0...m).each { |j| p[j] = j > 0 && p[j - 1] == 'B' || j < m - 1 && p[j + 1] == 'B' ? 'W' : 'B' if p[j] == '.' }\n q = p\n r << q.join\nend\nputs r"}, {"source_code": "\n\nn, m = gets.split.map(&:to_i)\n\ntab = []\nn.times{tab << gets.strip.split(//)}\n\nresult = []\n\n(0..n-1).each do |i|\n result << []\n (0..m-1).each do |j|\n if tab[i][j] == '-'\n result[-1] << '-'\n elsif i+j % 2 == 1\n result[-1] << 'W'\n else\n result[-1] << 'B'\n end\n end\nend\n\nresult.each{|x| puts x.join(\"\")}\n\n\n"}], "src_uid": "dc31adef80f06897ea2f5ef76854bcf1"} {"source_code": "n = gets.to_i\np = Array.new(n)\np[0] = 1\n(1...n).each {|i| p[i] = (i % 2 == 1 ? p[i-1] + i : p[i-1] - i)}\npmin = p.min\np.map!{|x| x - pmin + 1}\nputs p.join(' ')\n", "positive_code": [{"source_code": "n=gets.to_i;$><<(0...n).map{|i|i.odd?? n-i/2:i/2+1}*' '\n"}, {"source_code": "#sharyo\nn=gets.to_i\ni,j=1,n\nwhile n!=0\n\tn-=1\n\tif (n&1)==1\n print i.to_s+\" \"\n i+=1\n\telse\n print j.to_s+\" \"\n j-=1\n\tend\t\nend\t\n"}, {"source_code": "n=gets.to_i;$><<(0...n).map{|i|i.odd?? n-i/2:i/2+1}*' '\n"}, {"source_code": "n=gets.to_i;$><<(0...n).map{|i|i.odd?? n-i/2:i/2+1}*' '"}, {"source_code": "n=gets.to_i;$><<(0...n).map{|i|i.odd?? n-i/2:i/2+1}*' '\n"}, {"source_code": "n=gets.to_i;$><<(0...n).map{|i|i.odd?? n-i/2:i/2+1}*' '\n"}, {"source_code": "n=gets.to_i;$><<(0...n).map{|i|i.odd?? n-i/2:i/2+1}*' '"}, {"source_code": "n=gets.to_i;$><<(0...n).map{|i|i.odd?? n-i/2:i/2+1}*' '\n"}, {"source_code": "num = gets.chomp.to_i\n\nlist = \"\"\n\nflag = false\ncnt = 0\ncnt1 = 0\ncnt2 = 0\n\nwhile cnt != num\n if flag\n list << \"#{num - cnt1} \"\n cnt1 = cnt1 + 1\n else\n list << \"#{1 + cnt2} \"\n cnt2 = cnt2 + 1\n end\n flag = !flag\n cnt = cnt + 1\nend\n\nputs list.chomp\n"}, {"source_code": "n=gets.to_i;$><<(0...n).map{|i|i.odd?? n-i/2:i/2+1}*' '\n"}, {"source_code": "n = gets.to_i\nprintf \"1 \"\ncc = 1\n(n - 1).downto(1) do |c|\n\tsgn = (n - c) % 2 == 1 ? 1 : -1;\n\tcc = cc + c * sgn\n\tprint \"#{cc} \"\nend\n"}, {"source_code": "n=gets.to_i;$><<(0...n).map{|i|i.odd?? n-i/2:i/2+1}*' '\n"}, {"source_code": "a=[*1..gets.to_i]\n$*<<<$**\" \""}, {"source_code": "a=[*1..gets.to_i]\nprint a.pop,\" \",a.shift,\" \"while[]!=a\n"}, {"source_code": "n=gets.to_i;$><<(0...n).map{|i|i.odd?? n-i/2:i/2+1}*' '\n"}], "negative_code": [{"source_code": "#sharyo\nn=gets.to_i\ni,j=1, n\nwhile n>0\n\tn-=1\n\tif n&1\n print i.to_s+\" \"\n i+=1\n\telse\n print j.to_s+\" \"\n j-=1\n\tend\t\nend\t\n"}, {"source_code": "a=[*?1..gets]\n$*<<<$**\" \""}], "src_uid": "02b7ff5e0b7f8cd074d9e76251c2725e"} {"source_code": "n=gets.to_i\ns=[]\nans=0\ncnt=1\nn.times{\n a,b=gets.split.map(&:to_i)\n\n s.push(a) if b==0\n cnt+=b\n if b!=0 then\n cnt-=1\n ans+=a\n end\n}\ns.sort!\ns.reverse!\n[cnt,s.size()].min.times{|i|\n ans+=s[i]\n}\np ans\n", "positive_code": [{"source_code": "n = gets.to_i\na = Array.new(n){gets.split.map(&:to_i).reverse}.sort.reverse\nb, c = 1, 0\na.each do |x, y|\n break if b == 0\n b += x - 1\n c += y\nend\np c\n"}, {"source_code": "\ufeff\nn = gets.chomp.to_i\n\ncards = []\nn.times do \n cards << gets.chomp.split(\" \").map{|e| e.to_i}\nend\n\ncards.sort!{|a, b|\n if a[1] == b[1]\n b[0] <=> a[0]\n else\n b[1] <=> a[1]\n end\n}\n\ncard = cards.shift\nscore = card[0]\ntime = card[1]\n\ncards.each do |card|\n if time <= 0\n break\n else\n score += card[0]\n time += card[1]\n end\n time -= 1\nend\n\nputs score\n\n\n\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nthe_cards = n.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\n\nuse = ->(point, counter, card) { [point + card[0], counter - 1 + card[1]] }\nsort_card = ->(cards) { cards.sort {|a,b| (_ = a[1] <=> b[1]).zero? ? (a[0] <=> b[0]) : _ } }\n\nsolve = ->(cards, point, counter) do\n while !counter.zero? && !cards.empty?\n cards = sort_card[cards]\n card = cards.pop\n point, counter = use[point, counter, card]\n end\n point\nend\n\np solve[the_cards,0,1]\n"}, {"source_code": "aa,bb,ans,ct=[],[],0,1\nn=gets.to_i\nn.times do\n\tx,y=gets.chomp.split.map(&:to_i)\n\taa<aa[a]\n\t\tb=i if bb[i]>bb[b]\n\tend\n\tif ct==1&&bb[b]==0\n\t\tans+=aa[a]\n\t\tbreak\n\telsif bb[b]==0\n\t\tans+=aa[a]\n\t\tct-=1\n\t\taa[a]=0\n\telse\n\t\tans+=aa[b]\n\t\tct+=bb[b]-1\n\t\taa[b],bb[b]=0,0\n\tend\nend\nputs ans"}, {"source_code": "n, st, i, score = gets.to_i, 1, 0, 0\na = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}.sort_by! { |x| [-x[1], -x[0]] }\n# p a\nwhile st < n - i and i <= n and a[0][1].nonzero?\n st += a[0][1] - 1\n score += a[0][0]\n i += 1\n a.shift\nend\n# p a.sort_by! {|x| [-x[0], -x[1]]}\nwhile st.nonzero? and !a.empty?\n st += a[0][1] - 1\n score += a[0][0]\n a.shift\nend\np score"}, {"source_code": "#!/usr/bin/ruby\ndef read_int; gets.chomp.to_i; end\ndef read_ints; gets.chomp.split.map(&:to_i); end\n\nnum = read_int\nvals = []\n\nnum.times do\n vals << read_ints\nend\nvals.sort! {|a,b|\n if b[1] == a[1]\n b[0] <=> a[0]\n else\n b[1] <=> a[1]\n end\n}\nvals.delete_if {|a| a[1] == 0 && a[0] == 0 }\n\nrest = 1\npoint = 0\nvals.each do |i|\n point += i[0]\n rest += i[1]\n rest -= 1\n break if rest == 0\nend\n\nputs point\n"}, {"source_code": "a = gets.to_i.times.map{ gets.split.map(&:to_i) }\n\nb = a.sort{|i,j| (j[1] <=> i[1]).nonzero? or j[0] <=> i[0]}\n\npt = 0\nc = 0\n\nb.each do |e|\n pt += e[0]\n c += e[1]\n break if c.zero?\n c -= 1\nend\n\np pt\n"}, {"source_code": "n = gets.to_i\narr = []\nn.times do \n\tarr << gets.split(\" \").map(&:to_i)\t\nend\narr.sort!{|a,b|\n\tif a[1] == b[1]\n\t\tb[0] <=> a[0]\n\telse\n\t\tb[1] <=> a[1]\n\tend\n\t# puts \"#{a} b #{b}\"\n}\n\ni = 0\ncounter = 1\npoints = 0\nwhile true\n\tpoints += arr[i][0]\n\tcounter += arr[i][1]\n\ti += 1\n\tcounter -= 1\n\tbreak if counter == 0 || !arr[i]\nend\nputs points"}, {"source_code": "n = gets.to_i\nli = []\n(0...n).each{li.push(gets.split.collect{|i| i.to_i})}\nli = li.sort_by{|i| [i[1], i[0]]}\nans = 0\ncnt = 1\nli.reverse.each do |i|\n ans += i[0]\n cnt += i[1]-1\n break if cnt.zero?\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\nc = []\nfor i in 0..n-1\n\tline = gets.split\n\tc << [line[0].to_i, line[1].to_i]\nend\n\nc.sort_by! {|e| [e[1], e[0]]}\nc.reverse!\n\nscore = 0\ncount = 1\nfor i in 0..n-1\n\tif(count == 0)\n\t\tbreak\n\telse\n\t\tscore += c[i][0]\n\t\tcount += c[i][1]\n\t\tcount -= 1\n\tend\nend\n\nputs score"}, {"source_code": "def read_next_line\n gets.split.map { |x| x.to_i }\nend\n\nn = gets.to_i\np = []\ncounter = 1\nres = 0\nfor _ in 0...n\n a, b = read_next_line\n if b > 0\n counter += b - 1\n res += a\n else\n p << a\n end\nend\nif p.empty?\n puts res\n exit\nend\nres += p.sort[-[counter, p.size].min..-1].inject(:+)\nputs res"}, {"source_code": "a = []\n\ngets.to_i.times do\n a << gets.split.map(&:to_i)\nend\n\ncounter = 1\nscore = 0\na = a.sort_by {|col| [col[1], col[0]]}\nuntil counter.zero? or a.empty?\n x = a.pop\n counter -= 1\n counter += x[1]\n score += x[0]\nend\n\nputs score\n"}, {"source_code": "a = []\n\ngets.to_i.times do\n a << gets.split.map(&:to_i)\nend\n\ncounter = 1\nscore = 0\na = a.sort_by {|col| [col[1], col[0]]}\nuntil counter.zero? or a.empty?\n x = a.pop\n counter -= 1\n counter += x[1]\n score += x[0]\nend\n\nputs score\n"}, {"source_code": "n=gets.to_i\nzeros=[]\nscore=0\nopportunity=1\nn.times{\n\ta,b=gets.split.map(&:to_i)\n\tif b>0\n\t\tscore+=a\n\t\topportunity+=b-1\n\telse\n\t\tzeros< a[0]\n else\n b[1] <=> a[1]\n end\n}\n\ncard = cards.shift\nscore = card[0]\ntime = card[1]\n\ncards.each do |card|\n if time <= 0\n break\n else\n score += card[0]\n time += card[1]\n end \nend\n\nputs score\n\n\n\n"}, {"source_code": "\ufeffclass Item\n attr_accessor :times, :cards, :score\n \n def initialize(times, cards, score)\n @times = times\n @cards = cards\n @score = score\n end \nend\n\nn = gets.chomp.to_i\n\ncards = []\nn.times do \n cards << gets.chomp.split(\" \").map{|e| e.to_i}\nend\n\nqueue = []\ncards.each_with_index do |card, idx|\n tmp = cards.dup\n tmp.delete_at(idx)\n item = Item.new(card[1], tmp, card[0])\n \n queue << item\nend\n\nscores = []\nloop do\n if queue.length == 0\n break\n end\n \n new_items = []\n queue.each do |item|\n if item.times > 0\n cards = item.cards\n item.times -= 1\n \n cards.each_with_index do |card, idx|\n tmp = cards.dup\n tmp.delete_at(idx)\n new_item = Item.new(item.times + card[1], tmp, item.score + card[0])\n new_items << new_item\n end \n else\n scores << item.score \n end \n end\n queue = new_items\nend\n\nputs scores.max\n\n\n\n\n\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nthe_cards = n.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\n\nuse = ->(point, counter, card) { [point + card[0], counter - 1 + card[1]] }\n\nsolve = ->(cards, point, counter) do\n until counter.zero?\n cards = cards.sort {|a,b| (_ = a[1] <=> a[1]).zero? ? (a[0] <=> a[0]) : _ }\n point, counter = use[point, counter, cards.pop]\n end\n point\nend\n\np solve[the_cards,0,1]\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nthe_cards = n.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\n\nuse = ->(point, counter, card) { [point + card[0], counter - 1 + card[1]] }\n\nsolve = ->(cards, point, counter) do\n cards = cards.sort {|a,b| (_ = a[1] <=> a[1]).zero? ? (a[0] <=> a[0]) : _ }\n point, counter = use[point, counter, cards.pop]\n return point if counter.zero?\n solve[cards, point, counter]\nend\n\np solve[the_cards,0,1]\n"}, {"source_code": "n=gets.to_i\nzeros=[]\nscore=0\nopportunity=1\nn.times{\n\ta,b=gets.split.map(&:to_i)\n\tif b>1\n\t\tscore+=a\n\t\topportunity+=b-1\n\telse\n\t\tzeros< a[:value] } # Sorting by value\n\n hat_index = 1 # Currently considered index of hat\n person_index = 0 # Currently considered person\n while person_index < n\n value = a_pairs[person_index][:value]\n s = n - value # Size of group of co-hatters\n s.times do |j|\n i = person_index + j\n return nil if i >= n || a_pairs[i][:value] != value # Unable to get group of hatters\n b[a_pairs[i][:index]] = hat_index\n end\n hat_index += 1\n person_index += s\n end\n\n return b\nend\n\n# Input\nn = gets.to_i # 1 <= n <= 10**5\na = gets.split(\" \") # 1 <= a[i] <= n-1\n\n# Processing\nb = main(n, a)\n\n# Output\nif b\n puts \"Possible\"\n b.each { |s| puts s }\nelse\n puts \"Impossible\"\nend\n"}], "negative_code": [], "src_uid": "f49667ef00cd0da6a6fad67a19d92f1e"} {"source_code": "t = gets.to_i\nt.times do\n\ta, b = gets.split.map &:to_i\n\tp ((b - a).abs + 9) / 10\nend", "positive_code": [{"source_code": "gets.to_i.times do\n a, b = gets.split(' ').map(&:to_i)\n\n d, m = (a-b).abs.divmod(10)\n\n puts d + (m.zero? ? 0 : 1)\nend\n"}, {"source_code": "tc = gets().to_i\ntc.times do\n input = gets().split(' ').map(&:to_i)\n a = input[0]\n b = input[1]\n ans = (((a-b).abs().to_f)/10).ceil()\n puts ans\nend"}, {"source_code": "\nt = gets.to_i\n\ndef play(a,b)\n return 0 if a == b\n\n if a > b\n c = a\n a = b\n b = c\n end\n\n x = b - a\n r = x % 10\n\n if r == 0\n return x / 10\n else\n return (x-r)/10 + 1\n end\nend\n\nwhile t > 0\n a,b = gets.split(/\\s+/).map(&:to_i)\n puts play(a,b)\n t -= 1\nend\n\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n a, b = gets.chomp.split(\" \").map(&:to_i)\n sa = (a - b).abs\n ans = sa / 10\n amari = sa % 10\n if amari == 0\n puts ans\n else\n puts ans + 1\n end\nend"}, {"source_code": "gets.to_i.times do\n a, b = gets.split.map &:to_i\n d = (a - b).abs\n puts d / 10 + (d % 10 > 0 ? 1 : 0)\nend"}, {"source_code": "def solve\n n, m = gets.strip.split(' ').map(&:to_i)\n n, m = m, n if n < m\n dif = n - m;\n puts (dif / 10.0).to_i + (dif % 10 != 0 ? 1 : 0)\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "gets.to_i.times {\n a,b = gets.split.map &:to_i\n x = (a-b).abs\n p (x+9)/10\n}\n"}, {"source_code": "n=gets.to_i\nn.times do\n a,b = gets.split.map(&:to_i)\n puts ((b-a).abs/10.0).ceil\nend"}, {"source_code": "\nt = gets.to_i\n\ndef play(a,b)\n return 0 if a == b\n\n if a > b\n c = a\n a = b\n b = c\n end\n\n x = b - a\n r = x % 10\n\n if r == 0\n return x / 10\n else\n return (x-r)/10 + 1\n end\nend\n\nwhile t > 0\n a,b = gets.split(/\\s+/).map(&:to_i)\n puts play(a,b)\n t -= 1\nend\n\n"}, {"source_code": "gets.to_i.times do\n a, b = gets.split.map &:to_i\n d = (a - b).abs\n puts d/10 + (d%10 == 0 ? 0 : 1)\nend\n"}, {"source_code": "t = gets.chomp.to_i\ninputs = []\nt.times do\n inputs << gets.chomp.split.map(&:to_i)\nend\n\ninputs.each do |a,b|\n ret = 0\n if b > a\n ret += (b-a)/10\n ret += 1 if b > a + ret*10\n elsif b < a\n ret += (a-b)/10\n ret += 1 if b < a - ret*10\n end\n puts ret\nend\n"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\ninputs = []\nt.times do\n inputs << gets.chomp.split.map(&:to_i)\nend\n\ninputs.each do |a,b|\n ret = 0\n if b > a\n ret += (b-a)/10\n ret += b - (a + ret * 10)\n elsif b < a\n ret += (a-b)/10\n ret += a - (b + ret * 10)\n end\n puts ret\nend\n"}, {"source_code": "t = gets.chomp.to_i\ninputs = []\nt.times do\n inputs << gets.chomp.split.map(&:to_i)\nend\n\ninputs.each do |a,b|\n ret = 0\n if b > a\n ret += (b-a)/10\n ret += 1\n elsif b < a\n ret += (a-b)/10\n ret += 1\n end\n puts ret\nend\n"}], "src_uid": "d67a97a3b69d599b03d3fce988980646"} {"source_code": "gets\nputs gets.prepend(\"0\").strip.delete(\" \").gsub(/01/,\"11\").count(\"1\").pred.to_s.gsub(/-1/,\"0\")", "positive_code": [{"source_code": "gets\nputs gets.delete(\" \").squeeze(\"0\").tr('0',' ').strip.length"}, {"source_code": "=begin\nDear online judge:\nI've wasted time reading the problem and trying to figure out the solution\nIf you insist on the penalty system, please don't include the time of debugging\nI hope my code compile and get accepted. KEE O.o\n ____________\n / __ \\\n / __ | | \\\n / |__| | | \\\n ( |__| )\n \\ /\n \\ ___ /\n \\____________/\n=end\n\nclass Solve\n def solve()\n $n = Integer(gets)\n $list = gets().split()\n $res = 0\n $count = $list.count(\"1\")\n $n -= 1\n for $i in 0..$n do\n if $list[$i] == \"1\"\n $res+= 1\n $count -= 1\n if $count > 0 && $list[$i + 1]!= \"1\"\n $res+= 1\n end\n end\n end\n puts $res\n end\nend\n\n\n\nSolve.new.solve"}, {"source_code": "#!/usr/bin/ruby\ngets\na=gets.split.map(&:to_i)\np [0,a.count(1)*2-1-a.each_cons(2).count{|x,y|x==1&&y==1}].max"}, {"source_code": "#!/usr/bin/ruby\n\nn = STDIN.readline.to_i\nletters = STDIN.readline.split.collect {|s| s == '1' }\n\nindices = []\nletters.each_index {|i| indices.push(i) if letters[i] }\n\ncount = [1, indices.length].min\n(1...indices.length).each do |i|\n\tcount += [2, indices[i] - indices[i-1]].min\nend\n\nputs count\n\n"}, {"source_code": "#!/usr/bin/ruby\ngets\nputs gets.scan(/1|(?<=1) (0 )+(?=1)/).size\n"}, {"source_code": "n=gets.to_i\nxs=gets.split.map{|e| e.to_i}\np1=xs.index(1)\nif p1==nil then\n\tputs 0\nelse\n\tp1.times{\n\t\txs.shift\n\t}\n\twhile xs.empty? == false\n\t\tt=xs.pop\n\t\tif t==1\n\t\t\txs.push(t)\n\t\t\tbreak\n\t\tend\n\tend\n\t\n\tans=0\n\told=1\n\txs.each{|e|\n\t\tif e==0 then\n\t\t\tif old==1 then\n\t\t\t\tans+=1\n\t\t\tend\n\t\telse\n\t\t\tans+=1\n\t\tend\n\t\told=e\n\t}\n\tputs ans\nend"}, {"source_code": "# -*- coding: utf-8 -*-\nn = gets.to_i\nxs = gets.split.map(&:to_i)\nflag = false\nret = 0\nxs.each do |x|\n if x == 1\n flag = true\n ret += 1\n elsif flag == true && x == 0\n flag = false\n ret += 1\n end\nend\nret -= 1 if xs[-1] == 0 && ret > 0\nputs ret\n\n"}, {"source_code": "n = Integer(gets)\nnums = gets.chomp.split\nletters = []\nfor i in 0...n\n letters[i] = Integer(nums[i])\nend\nop = 0\npointer = 0\nfor i in 0...n-1\n if letters[i] == 1\n op += 1\n if letters[i+1] == 0 && i + 1 != n-1\n pointer = i + 1\n op += 1\n end\n end\nend\nx = 0\nfor j in pointer...n\n if letters[j] != 0\n x = 1\n break\n end\nend\nif x == 0 && op != 0\n op -= 1\nend\nif letters[n-1] == 1\n op += 1\nend\nputs op\n"}, {"source_code": "n = gets.to_i\na = gets.split(/\\s+/).map(&:to_i)\n\nanswer = 0\ni = 0\n\ni += 1 while i < n && a[i] != 1\n\nanswer = 1 if a[i] == 1\ncurrent = i\ni += 1\n\nwhile i < n\n i += 1 while i < n && a[i] != 1\n\n# p [current, i, answer]\n\n if a[i] == 1\n answer += (i - current > 2) ? 2 : i - current\n end\n\n current = i\n i += 1\nend\n\np answer\n"}, {"source_code": "gets # ignore first line\ngroups = gets.strip.tr(' ', '').split(\"0\").delete_if { |x| x.length == 0 }.map(&:length)\nputs [groups.inject(0, :+) + groups.length - 1, 0].max\n"}, {"source_code": "n = gets.chomp.to_i\nx = gets.split()\n\ni = 0\nm = 0\n\n\nfor i in 0..n-1\n if x[i].to_i==1\n m=m+1\n else\n if i>0\n if x[i-1].to_i==1\n m=m+1\n end\n end\n end\n\nend\n\n\nif x[n-1].to_i==0\n if m >0\n m=m-1\n end\nend\nprint m\n"}, {"source_code": "gets\nputs (\"0\"+gets).gsub(/0 ?1/,\"1 1\").count(\"1\").pred.to_s.sub(/-1/,\"0\")"}, {"source_code": "gets\nputs gets.scan(/1|(?<=1) (0 )+(?=1)/).size"}, {"source_code": "gets\nputs gets.delete(\" \").tr_s('0',' ').strip.length"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\ngets\na=gets.split.map(&:to_i)\np a.count('1')*2-1-a.each_cons(2).count{|x,y|x==1&&y==1}"}, {"source_code": "#!/usr/bin/ruby\ngets\na=gets.split.map(&:to_i)\np a.count(1)*2-1-a.each_cons(2).count{|x,y|x==1&&y==1}"}, {"source_code": "n = Integer(gets)\nnums = gets.chomp.split\nletters = []\nfor i in 0...n\n letters[i] = Integer(nums[i])\nend\nop = 0\npointer = 0\nfor i in 0...n-1\n if letters[i] == 1\n op += 1\n if letters[i+1] == 0 && i + 1 != n-1\n pointer = i + 1\n op += 1\n end\n end\nend\nx = 0\nfor j in pointer...n-1\n if letters != 0\n x = 1\n break\n end\nend\nif x == 0\n op -= 1\nend\nif letters[n-1] == 1\n op += 1\nend\nputs op\n"}, {"source_code": "n = Integer(gets)\nnums = gets.chomp.split\nletters = []\nfor i in 0...n\n letters[i] = Integer(nums[i])\nend\nop = 0\npointer = 0\nfor i in 0...n-1\n if letters[i] == 1\n op += 1\n if letters[i+1] == 0 && i + 1 != n-1\n pointer = i + 1\n op += 1\n end\n end\nend\nx = 0\nfor j in pointer...n-1\n if letters[j] != 0\n x = 1\n break\n end\nend\nif x == 0\n op -= 1\nend\nif letters[n-1] == 1\n op += 1\nend\nputs op\n"}, {"source_code": "n = Integer(gets)\nnums = gets.chomp.split\nletters = []\nfor i in 0...n\n letters[i] = Integer(nums[i])\nend\nop = 0\npointer = 0\nfor i in 0...n-1\n if letters[i] == 1\n op += 1\n if letters[i+1] == 0 && i + 1 != n-1\n pointer = i + 1\n op += 1\n end\n end\nend\nx = 0\nfor j in pointer...n\n if letters[j] != 0\n x = 1\n break\n end\nend\nif x == 0\n op -= 1\nend\nif letters[n-1] == 1\n op += 1\nend\nputs op\n"}, {"source_code": "n = Integer(gets)\nnums = gets.chomp.split\nletters = []\nfor i in 0...n\n letters[i] = Integer(nums[i])\nend\nop = 0\nfor i in 0...n-1\n if letters[i] == 1\n op += 1\n if letters[i+1] == 0 && i + 1 != n-1\n op += 1\n end\n end\nend\nif letters[n-1] == 1\n op += 1\nend\nputs op\n"}, {"source_code": "n = gets.chomp.to_i\nx = gets.split()\n\ni = 0\nm = 0\n\n\nfor i in 0..n-1\n if x[i].to_i==1\n m=m+1\n end\n\n\nif x[i].to_i==0\n if x[i-1].to_i==1\n m=m+1\n end\nend\n\nend\n\n\n\n\nif x[n-1].to_i==0\n if m >0\nm=m-1\nend\nend\nprint m\n"}, {"source_code": "n = gets.chomp.to_i\nx = gets.split()\n\ni = 0\nm = 0\n\n\nfor i in 0..n\n if x[i].to_i==1\n m=m+1\n end\nif x[i].to_i==0\n if x[i-1].to_i==1\n m=m+1\n end\nend\nend\n\nif x[n].to_i==0\n if m>1\nm=m-1\nend\nend\nprint m\n"}, {"source_code": "n = gets.chomp.to_i\nx = gets.split()\n\ni = 0\nm = 0\n\n\nfor i in 0..n-1\n if x[i].to_i==1\n m=m+1\n end\nif x[i].to_i==0\n if x[i-1].to_i==1\n m=m+1\n end\nend\nend\n\nif x[n-1].to_i==0\n if m>1\nm=m-1\nend\nend\nprint m\n"}, {"source_code": "n = gets.chomp.to_i\nx = gets.split()\n\ni = 0\nm = 0\n\n\nfor i in 0..n-1\n if x[i].to_i==1\n m=m+1\n else\n if x[i-1].to_i==1\n m=m+1\n end\n end\n\nend\n\n\nif x[n-1].to_i==0\n if m >0\n m=m-1\n end\nend\nprint m\n"}, {"source_code": "gets\nputs gets.split.join.tr_s('0',' ').split.length"}, {"source_code": "gets\nputs gets.split(%r{ ?(0 )+}).join.split.length"}, {"source_code": "gets\nputs gets.scan(/1|(?<=1) 0/).size"}, {"source_code": "gets\nputs gets.gsub(/1(?! 1)/,'11').count('1')"}, {"source_code": "gets\nputs gets.scan(/1|(?<=1).{2,}?(?=1)/).size"}], "src_uid": "0fbc306d919d7ffc3cb02239cb9c2ab0"} {"source_code": "include Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInfinity = 1/0.0\n\nalias p! p\ndef p(*objs)\n def onep(obj)\n case obj\n when Matrix\n puts\"Matrix[\"\n obj.to_a.each{|row|p row}\n puts\"]\"\n else\n p! obj\n end\n end\n objs.each{|obj|\n onep obj\n }\nend\ndef pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end\nclass String;def to_ia;self.split.map(&:to_i);end;end\ndef getia;gets.to_ia;end\ndef geti;gets.to_i;end\nclass Object;def dcopy;Marshal.load(Marshal.dump(self));end;end\n\nclass Integer\n RomaTbl = {1 => 'I', 4 => 'IV', 5 => 'V', 9=> 'IX', 10 => 'X',\n 40 => 'XL', 50 => 'L', 90 => 'XC', 100 => 'C', 400 => 'CD',\n 500 => 'D', 900=> 'CM', 1000 => 'M'}\n def roman(s=self)\n return \"-\" if s==0\n k = RomaTbl.keys.delete_if{|x| x > s}.sort[-1]\n return RomaTbl[k] + roman(s - k).gsub('-','')\n end\nend\n\nf=gets\na,b=f.split(\" \")\n\nn=gets.to_i(a.to_i)\n\nif b==\"R\"\n puts n.roman\nelse\n puts n.to_s(b.to_i).upcase\nend\n\n", "positive_code": [{"source_code": "def f(n)\n m, c, x, l = [1000, 100, 10, 1].map { |t| r = (n/t).floor; n %= t; r }\n 'M'*m +\n case c\n when 9 then 'CM'\n when 5..8 then 'D' + 'C'*(c-5)\n when 4 then 'CD'\n when 1..3 then 'C'*c\n else ''\n end +\n case x\n when 9 then 'XC'\n when 5..8 then 'L' + 'X'*(x-5)\n when 4 then 'XL'\n when 1..3 then 'X'*x\n else ''\n end +\n case l\n when 9 then 'IX'\n when 5..8 then 'V' + 'I'*(l-5)\n when 4 then 'IV'\n when 1..3 then 'I'*l\n else ''\n end\nend\n\na, b = gets.split\nc = gets.to_i(a.to_i)\nputs (b == 'R' ? f(c) : c.to_s(b.to_i).upcase)\n"}, {"source_code": "def to_r(n)\n\tif n < 1\n\t\t''\n\telsif n < 10\n\t\t%w(I II III IV V VI VII VIII IX)[n - 1]\n\telsif n < 100\n\t\t%w(X XX XXX XL L LX LXX LXXX XC)[n / 10 - 1] + to_r(n % 10)\n\telsif n < 1000\n\t\t%w(C CC CCC CD D DC DCC DCCC CM)[n / 100 - 1] + to_r(n % 100)\n\telse\n\t\t%w(M MM MMM)[n / 1000 - 1] + to_r(n % 1000)\n\tend\nend\n\na, b = gets.split.map(&:to_i)\nn = gets.to_i(a)\nputs b > 0 ? n.to_s(b).upcase : to_r(n)\n"}], "negative_code": [{"source_code": "include Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInfinity = 1/0.0\n\nalias p! p\ndef p(*objs)\n def onep(obj)\n case obj\n when Matrix\n puts\"Matrix[\"\n obj.to_a.each{|row|p row}\n puts\"]\"\n else\n p! obj\n end\n end\n objs.each{|obj|\n onep obj\n }\nend\ndef pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end\nclass String;def to_ia;self.split.map(&:to_i);end;end\ndef getia;gets.to_ia;end\ndef geti;gets.to_i;end\nclass Object;def dcopy;Marshal.load(Marshal.dump(self));end;end\n\nclass Integer\n RomaTbl = {1 => 'I', 4 => 'IV', 5 => 'V', 9=> 'IX', 10 => 'X',\n 40 => 'XL', 50 => 'L', 90 => 'XC', 100 => 'C', 400 => 'CD',\n 500 => 'D', 900=> 'CM', 1000 => 'M'}\n def roman(s=self)\n return \"-\" if s==0\n k = RomaTbl.keys.delete_if{|x| x > s}.sort[-1]\n return RomaTbl[k] + roman(s - k).gsub('-','')\n end\nend\n\nf=gets\na,b=f.split(\" \")\n\nn=gets.to_i(a.to_i)\n\nif b==\"R\"\n puts n.roman\nelse\n puts n.to_s(b.to_i)\nend\n\n"}, {"source_code": "def f(n)\n m, c, x, l = [1000, 100, 10, 1].map { |t| r = (n/t).floor; n %= t; r }\n 'M'*m +\n case c\n when 9 then 'CM'\n when 5..8 then 'D' + 'C'*(c-5)\n when 4 then 'CD'\n when 1..3 then 'C'*c\n else ''\n end +\n case x\n when 9 then 'XC'\n when 5..8 then 'L' + 'X'*(x-5)\n when 4 then 'XL'\n when 1..3 then 'X'*x\n else ''\n end +\n case l\n when 9 then 'IX'\n when 5..8 then 'V' + 'I'*(l-5)\n when 4 then 'IV'\n when 1..3 then 'I'*l\n else ''\n end\nend\n\na, b = gets.split\nc = gets.to_i(a.to_i)\nputs (b == 'R' ? f(c) : c.to_s(b.to_i))\n"}], "src_uid": "c619d699e3e5fb42aea839ef6080c86c"} {"source_code": "\n\n\ndef get_res(n)\n res = n / 2\n res += 1 if (n % 2 == 1)\n return res\nend\n\n\ndef solve\n t = gets.chomp\n (1..t.to_i).each {puts get_res(gets.chomp.to_i)}\nend\n\nsolve", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n\tn = gets.to_i\n\tp (n + 1) / 2\nend\n"}, {"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n puts (n+1)/2\nend\n"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n t = gets.chomp.to_i\n if t % 2 == 1 && t >= 3\n kai = t -1\n kazu = kai / 2\n puts kazu + 1\n elsif t % 2 == 1 && t < 3\n puts \"1\"\n elsif t % 2 == 0 && t >= 2\n puts t / 2\n end\nend"}, {"source_code": "t=gets.chomp.to_i\nfor i in 1..t\n\tn=gets.chomp.to_i\n\tputs\"#{(1+n)/2}\"\nend"}, {"source_code": "T = gets.to_i\nfor i in 1..T\n x = gets.to_i\n puts (x + 1) / 2\nend"}, {"source_code": "def f(n)\n return 0 if n.zero?\n n.even? ? n / 2 : f(n - 1) + 1\nend\n\ngets.to_i.times do\n puts f(gets.to_i)\nend\n"}], "negative_code": [{"source_code": "def f(n)\n return 1 if n == 1\n return 2 if n == 3\n\n n / 2\nend\n\ngets.to_i.times do\n puts f(gets.to_i)\nend\n"}], "src_uid": "ec89860dacb5a11b3a2273d2341b07a1"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).reverse\n\np = 10**9+1\nans = 0\na.each do |x|\n x = [x, p - 1].min\n ans += x\n p = [1, x].max\nend\nputs ans\n", "positive_code": [{"source_code": "def main\n n = gets.chomp\n a = gets.chomp.split.map(&:to_i).reverse\n\n m = 0\n a.inject(nil) do |prev, x|\n if prev.nil? or prev > x\n m += x\n x \n else\n q = prev - 1 >= 0 ? prev - 1 : 0\n m += q\n q\n end\n end\n\n puts m\nend\n\nmain\n"}, {"source_code": "n = gets\na = gets.split(\" \").map{|s| s.to_i}\nputs a.reverse\n .inject([0, a[-1] + 1]) {|r, e| \n r[1] = [[r[1] - 1, e].min, 0].max \n r[0] += r[1]\n r\n }[0]"}], "negative_code": [], "src_uid": "5993b5bf231fabd3c2af90124c41f118"} {"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=-~i*a[i]};p r", "positive_code": [{"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=-~i*a[i]};p r"}, {"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=-~i*a[i]};p r\n"}, {"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=-~i*a[i]};p r\n"}, {"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=-~i*a[i]};p r\n"}, {"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=-~i*a[i]};p r\n"}, {"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=-~i*a[i]};p r"}, {"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=-~i*a[i]};p r\n"}, {"source_code": "arr = gets.split.collect{|i| i.to_i}\n\nsum = 0\nfor i in (1..arr[0])\n sum += (i * arr[i])\nend\n\nputs sum"}, {"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=-~i*a[i]};p r\n"}, {"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=-~i*a[i]};p r\n"}, {"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=-~i*a[i]};p r\n"}], "negative_code": [{"source_code": "n,*a=gets.split.map &:to_i;r=0;n.times{|i|r+=i*a[i]};p r"}], "src_uid": "f9f25190916bf4294f7458140b264cb5"} {"source_code": "require \"prime\"\nN = gets.to_i\n$ans = []\nQS = N.prime_division\n\ndef dig(v = 1,i = 0)\n if i == QS.size\n n = N/v\n s = (1 + ((n-1) * v + 1))*n/2\n $ans << s\n return\n end\n \n q,d = QS[i]\n b = 1\n (0..d).each{ |d|\n dig(v*b,i+1)\n b *= q\n }\nend\ndig\nputs $ans.sort.join(\" \")\n", "positive_code": [{"source_code": "require 'prime'\n\nn = gets.to_i\n$f = Prime.prime_division(n)\n#p $f\n$d = []\n$x = []\n\na = []\n\ndef bf(depth)\n if depth == $f.size\n #p $x\n s = 1\n $f.each_with_index do |e, i|\n s *= e[0]**$x[i]\n end\n $d << s\n #p s\n return\n end\n (0..$f[depth][1]).each do |i|\n $x[depth] = i\n bf(depth + 1)\n end\nend\n\nbf(0)\n$d.uniq!\n#p $d\n$d.each do |d|\n a1 = 1\n m = n/d\n am = a1 + (m - 1)*d\n a << (a1 + am)*m/2\n# p (a1 + am)*m/2\nend\n\na.sort!\nputs a.join(' ')\n"}], "negative_code": [], "src_uid": "2ae1a4d4f2e58b359c898d1ff38edb9e"} {"source_code": "s = gets.chomp.to_i\ns.times do\n a, b, n, m = gets.chomp.split(\" \").map(&:to_i)\n if a > b\n kazu = b - m\n if kazu < 0\n #no += 1\n puts \"No\"\n next\n elsif kazu >= 0\n all = kazu + a\n if all >= n\n #yes += 1\n puts \"Yes\"\n next\n else\n puts \"No\"\n next\n #no += 1\n end\n end\n elsif a < b\n kazu = a - m\n if kazu < 0\n #no += 1\n puts \"No\"\n next\n elsif kazu >= 0\n all = kazu + b\n if all >= n\n puts \"Yes\"\n next\n #yes += 1\n else\n puts \"No\"\n next\n #no += 1\n end\n end\n elsif a == b\n kazu = a - m\n if kazu < 0\n puts \"No\"\n next\n #no += 1\n elsif kazu >= 0\n all = kazu + b\n if all >= n\n puts \"Yes\"\n next\n #yes += 1\n else\n puts \"No\"\n next\n #no += 1\n end\n end\n end\nend", "positive_code": [{"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n v,c,n,m = gets.chomp.split.map(&:to_i)\n v,c=c,v if v > c\n if v < m\n puts 'No'\n else\n v -= m\n if v + c < n\n puts 'No'\n else\n puts 'Yes'\n end\n end\nend\n"}], "negative_code": [], "src_uid": "0f960d19e576b7421a7c7a7166a884ea"} {"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |inp|\r\n p, a, b, c = inp.split(' ').map(&:to_i)\r\n\r\n r = []\r\n [a, b, c].each do |n|\r\n r << ((p / n) + [p % n, 1].min) * n\r\n end\r\n\r\n puts r.min - p\r\nend", "positive_code": [{"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |inp|\r\n p, a, b, c = inp.split(' ').map(&:to_i)\r\n\r\n r = []\r\n [a, b, c].each do |n|\r\n r << ((p / n) + (p % n == 0 ? 0 : 1)) * n\r\n end\r\n\r\n puts r.min - p\r\nend"}, {"source_code": "n = gets.to_i\na = []\n\ndef get_min(arr)\n\t[compare(arr[0],arr[1]), compare(arr[0],arr[2]), compare(arr[0],arr[3])].min\nend\n\ndef compare(a,b)\n return b-a if a < b\n\t\n\t-a % b\nend\n\n(0..n-1).each do |x|\n\tq = gets.chomp.split().map { |e| e.to_i }\n\ta.append(get_min(q))\nend\n\n\na.each do |x|\n p x\nend\n\n"}, {"source_code": "f = lambda {|x,p| p%x==0? 0:(x-(p%x))}\ngets.to_i.times {\n\tp,a,b,c = gets.split.map(&:to_i)\n\tputs [a,b,c].map{|x| f.call(x,p)}.min\n}"}, {"source_code": "t = gets.to_i\r\nans = []\r\nt.times do\r\n p,a,b,c = gets.chomp.split(\" \").map(&:to_i)\r\n min = [((p+a-1)/a)*a-p,((p+b-1)/b)*b-p,((p+c-1)/c)*c-p].min\r\n ans << min\r\nend\r\nputs ans"}, {"source_code": "gets.to_i.times do\r\n q,a,b,c=gets.split.map(&:to_i)\r\n puts [(a-q%a)%a,(b-q%b)%b,(c-q%c)%c].min\r\nend\r\n"}], "negative_code": [{"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |inp|\r\n p, a, b, c = inp.split(' ').map(&:to_i)\r\n\r\n r = []\r\n [a, b, c].each do |n|\r\n r << (p / n) * n\r\n end\r\n\r\n puts r.min - p\r\nend"}, {"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |inp|\r\n p, a, b, c = inp.split(' ').map(&:to_i)\r\n\r\n r = []\r\n [a, b, c].each do |n|\r\n r << (p.to_f / n.to_f).ceil * n\r\n end\r\n\r\n puts r.min - p\r\nend"}, {"source_code": "n = gets.to_i\r\na = []\r\n\r\ndef get_min(arr)\r\n\t[compare(arr[0],arr[1]), compare(arr[0],arr[2]), compare(arr[0],arr[3])].min\r\nend\r\n\r\ndef compare(a,b)\r\n return b-a if a < b\r\n \r\n while a / b != 0\r\n \tb+=b\r\n end\r\n\t\r\n\tb % a\t\r\nend\r\n\r\n(0..n-1).each do |x|\r\n\tq = gets.chomp.split().map { |e| e.to_i }\r\n\ta.append(get_min(q))\r\nend\r\n\r\n\r\na.each do |x|\r\n p x\r\nend"}], "src_uid": "293f9b996eee9f76d4bfdeda85685baa"} {"source_code": "n = gets.chomp\ns = gets.chomp\nrev = {}\nrev['U'] = 'D'\nrev['D'] = 'U'\nrev['R'] = 'L'\nrev['L'] = 'R'\nres = 0\nrequire 'set'\nst = Set.new\ns.each_char do |i|\n c = i\n if ((st.size() == 2 && !(st.include?(c))) || st.include?(rev[c]))\n res += 1\n st.clear\n end\n st.add(c)\nend\nif (st.size() > 0)\n res += 1\nend\nputs res", "positive_code": [{"source_code": "require 'set'\nn = gets.chomp\ns = gets.chomp\nrev = {\"U\" => \"D\", \"D\" => \"U\", \"L\" => \"R\", \"R\" => \"L\"}\notp = 0\nset = Set.new\ns.each_char do |i|\n x = i\n if(set.include?(rev[x])) || ((set.size() == 2)&& !(set.include?(x)))\n otp +=1\n set.clear\n end\n set.add(x)\nend\nif(set.size>0)\n otp +=1\nend\nputs otp\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nq = STDIN.gets.chomp\n\na = \"LRUD\"\nb = \"RLDU\"\n\nf = -1\ns = -1\n\nans = 1\n\ni = 0\nwhile i < n do\n c = q[i]\n if f == -1\n f = c\n elsif s == -1\n if a.index(f) == b.index(c)\n ans += 1\n f = c\n elsif c != f\n s = c\n end\n elsif c != f && c != s\n ans += 1\n f = c\n s = -1\n end\n i += 1\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\ns = gets.strip.split(\"\")\nsol = 1\nh = \"_\"\nv = \"_\"\nfor x in s\n if \"RL\".match(x) then\n if h != \"_\" && h != x then\n sol += 1\n v = \"_\"\n end\n h = x\n else\n if v != \"_\" && v != x then\n sol += 1\n h = \"_\" \n end\n v = x\n end\nend\nputs sol"}], "negative_code": [], "src_uid": "b1c7ca90ce9a67605fa058d4fd38c2f2"} {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-318000}\n", "positive_code": [{"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-318000}\n"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-318000}\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nif m == 3 and n >= 5\n puts -1\nelse\n INF = 100000\n x, y = [], []\n 1.upto(m) do |i|\n x << i\n y << INF + i * i\n end\n 1.upto(m) do |i|\n x << i\n y << -INF - i * i\n end\n n.times do |i|\n puts \"#{x[i]} #{y[i]}\"\n end\nend\n"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-318000}\n"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-318000}\n"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-1000000}"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-318000}"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-318000}\n"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-318000}\n"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-318000}"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-318000}\n"}], "negative_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nif m == 3 and n >= 5\n puts -1\nelse\n INF = 100000000\n x, y = [], []\n m.times do |i|\n x << 1 + i\n y << 1 + i * i\n end\n m.times do |i|\n x << -1 - i\n y << -1 - i * i\n end\n n.times do |i|\n puts \"#{x[i]} #{y[i]}\"\n end\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nif m == 3 and n >= 5\n puts -1\nelse\n INF = 100000000\n x, y = [], []\n m.times do |i|\n x << i\n y << 1 + i * i\n end\n m.times do |i|\n x << i\n y << -1 - i * i\n end\n n.times do |i|\n puts \"#{x[i]} #{y[i]}\"\n end\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nif m == 3 and n >= 5\n puts -1\nelse\n INF = 100000000\n x, y = [], []\n m.times do |i|\n x << 1 + i\n y << INF - i * i\n end\n m.times do |i|\n x << -1 - i\n y << -INF + i * i\n end\n n.times do |i|\n puts \"#{x[i]} #{y[i]}\"\n end\nend\n"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-237}"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-318}"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i+1,-i*i}"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-2379}"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i-1}"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i,-i*i}"}, {"source_code": "a,b=gets.split.map &:to_i\nexit !puts(-1)if a>4&&b<4\n(1..b).each{|i|puts i,i*i}\n(1..a-b).each{|i|puts i+10000,-i*i}"}], "src_uid": "2e9f2bd3c02ba6ba41882334deb35631"} {"source_code": "n,s,*v=$<.read.split.map &:to_i\np [[(v.reduce(:+)-s)/n,*v].min,-1].max", "positive_code": [{"source_code": "n,s = gets.split.map(&:to_i)\nv = gets.split.map(&:to_i)\nmin = 0\nmax = 10**9+10\nwhile min < max-1\n mid = min+(max-min)/2\n ret = 0\n n.times do |i|\n ret += v[i]-mid if mid < v[i]\n end\n if ret < s\n max = mid-1\n else\n min = mid\n end\nend\n\n[max,min].each do |i|\n ret = 0\n n.times do |j|\n ret += v[j]-i if v[j] > i\n end\n if ret >= s\n ans = 10**9\n n.times do |j|\n ans = [ans,i,v[j]].min\n end\n puts ans\n exit\n end\nend\nputs -1"}], "negative_code": [{"source_code": "n,s = gets.split.map(&:to_i)\nv = gets.split.map(&:to_i)\nmin = 0\nmax = 10**9+10\n50.times do\n mid = min+(max-min)/2\n ret = 0\n n.times do |i|\n ret += v[i]-mid if mid < v[i]\n end\n if ret < s\n max = mid-1\n else\n min = mid\n end\nend\nfor i in min..max\n ret = 0\n n.times do |j|\n ret += v[j]-i if i < v[j]\n end\n if ret >= s\n puts i\n exit\n end\nend\nputs -1"}, {"source_code": "n,s = gets.split.map(&:to_i)\nv = gets.split.map(&:to_i)\nmin = 0\nmax = 10**9+10\n50.times do\n mid = min+(max-min)/2\n ret = 0\n n.times do |i|\n ret += v[i]-mid if mid < v[i]\n end\n if ret < s\n max = mid-1\n else\n min = mid\n end\nend\n\n[max,min].each do |i|\n ret = 0\n n.times do |j|\n ret += v[j]-i if v[j] > i\n end\n if ret >= s\n puts i\n exit\n end\nend\nputs -1"}, {"source_code": "n,s = gets.split.map(&:to_i)\nv = gets.split.map(&:to_i)\nmin = -1\nmax = 10**9+10\nwhile min < max-1\n mid = min+(max-min)/2\n ret = 0\n n.times do |i|\n ret += v[i]-mid if mid < v[i]\n end\n if ret < s\n max = mid-1\n else\n min = mid\n end\nend\np min"}, {"source_code": "n,s = gets.split.map(&:to_i)\nv = gets.split.map(&:to_i)\nmin = 0\nmax = 10**9+10\nwhile min < max-1\n mid = min+(max-min)/2\n ret = 0\n n.times do |i|\n ret += v[i]-mid if mid < v[i]\n end\n if ret < s\n max = mid-1\n else\n min = mid\n end\nend\n\n[max,min].each do |i|\n ret = 0\n n.times do |j|\n ret += v[j]-i if v[j] > i\n end\n if ret >= s\n puts i\n exit\n end\nend\nputs -1"}, {"source_code": "n,s = gets.split.map(&:to_i)\nv = gets.split.map(&:to_i)\nmin = 0\nmax = 10**9+10\n50.times do\n mid = min+(max-min)/2\n ret = 0\n n.times do |i|\n ret += v[i]-mid if mid < v[i]\n end\n if ret < s\n max = mid-1\n else\n min = mid\n end\nend\nfor i in min..max\n ret = 0\n n.times do |j|\n ret += v[j]-i if i < v[j]\n end\n if ret == s\n puts i\n exit\n elsif ret > s\n puts i+1\n exit\n end\nend\nputs -1"}], "src_uid": "23c63d1fea568a75663450e0c6f23a29"} {"source_code": "gets;puts$<.map(&:chomp).sort{|a,b|a+b<=>b+a}*''\n", "positive_code": [{"source_code": "gets;puts$<.map(&:chomp).sort{|a,b|a+b<=>b+a}*''"}, {"source_code": "n = gets.chomp.to_i\narr = []\nn.times do\n arr << gets.chomp\nend\n\nputs arr.sort{|a, b| a + b <=> b + a}.join(\"\")"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nn=gets.to_i\nputs $<.map{|e|e.chomp+'~'}.sort.map{|e|e[0..-2]}*''"}], "src_uid": "930365b084022708eb871f3ca2f269e4"} {"source_code": "n = gets.chomp.to_i\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nai = 1\nbi = n-1\nat = ar[0]\nbt = 0\nwhile ai <= bi\n\tif at <= bt\n\t\tat += ar[ai]\n\t\tai += 1\n\telse\n\t\tbt += ar[bi]\n\t\tbi -= 1\n\tend\nend\n\nputs ai.to_s + \" \" + (n-(bi+1)).to_s\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split(/\\s/).map {|x| x.to_i}\n\na1 = 0\na2 = 0\nt1 = 0\nt2 = 0\nsize = a.size\nif size == 1\n puts \"1 0\"\nelse\n i = 0\n j = size-1\n while i < j\n if t1 > t2\n while t1 > t2 and i < j\n a2 += 1\n t2 += a[j]\n j -= 1\n end\n elsif t2 > t1\n while t2 > t1 and i < j\n a1 += 1\n t1 += a[i]\n i += 1\n end\n else\n a1 += 1\n a2 += 1\n t1 += a[i]\n t2 += a[j]\n i += 1\n j -= 1\n end\n end\n \n if a1+a2 != n\n if t1 <= t2\n a1 += 1\n else\n a2 += 1\n end\n end\n puts \"#{a1} #{a2}\"\nend"}, {"source_code": "gets\na = gets.split.map(&:to_i)\n\ni, j = 0, a.size - 1\n\nif a.size > 1\n while true\n if a[i] == a[j]\n a[i] = a[j] = 0\n i += 1\n j -= 1\n if i > j \n break\n elsif i == j\n i += 1\n break\n end\n elsif a[i] > a[j]\n a[i] -= a[j]\n j -= 1\n if i == j\n i += 1\n break\n end\n elsif a[i] < a[j]\n a[j] -= a[i]\n i += 1\n if i == j\n j -= 1\n break\n end\n end\n end\nelse\n i = 1\n j = a.size - 1\nend\n\nputs \"#{i} #{(a.size - 1) - j}\"\n"}, {"source_code": "# Discard input count\ngets\n# This gives us candy bars as an array of ints.\nbars = gets.split.map { |a| a.to_i }\n# Next we find the sum\nsum = bars.inject(0,:+)\n# Imagine the chocolate bars laid end to end on a line. We know that if both Bob and Alice keep eating at the same rate, The coordinate they will meet at is half the sum.\nmiddle = sum / 2.0\n# Now we need to find out which bar this is. If it is a clean split between two bars, we can simply return.\nalice_dist = 0\nalice_dist_to_middle_bar_start = nil\nmiddle_bar_index = nil\nbars.each_with_index do |bar,i|\n # Check if, by adding the distance, we surpass this bar.\n dist_to_end_of_bar = alice_dist + bar\n if(dist_to_end_of_bar > middle)\n middle_bar_index = i\n alice_dist_to_middle_bar_start = alice_dist\n break\n elsif (dist_to_end_of_bar == middle)\n # It's a clean split! alice eats [0..i] bars so add '1'\n puts (i+1).to_s + \" \" + (bars.length - (i+1)).to_s\n exit\n end\n alice_dist += bar\nend\n\n#And now we know that the middle bar is 'i', and that alice's distance from it. From there we can get Bob's distance.\nbob_dist_to_middle_bar_end = sum - (alice_dist_to_middle_bar_start + bars[middle_bar_index])\n\nif(alice_dist_to_middle_bar_start <= bob_dist_to_middle_bar_end)\n puts (1 + middle_bar_index).to_s + \" \" + (bars.length - (1 + middle_bar_index)).to_s\nelse\n puts (middle_bar_index).to_s + ' ' + (bars.length - middle_bar_index).to_s\nend"}, {"source_code": "n = gets.to_i\n\na = gets.split.collect{|x| x.to_i}\n\nif a.size == 1\n\tprint 1,' ', 0\n\texit\nend\n\nl,r = 0, a.size-1\n\nwhile l+1 < r\n\t# print [l,r],\"\\n\"\n\tmin = [a[l],a[r]].min\n\ta[l] -= min\n\ta[r] -= min\n\n\tif a[l] == 0 and l < r-1\n\t\tl+=1\n\tend\n\tif a[r] == 0 and r-1 > l\n\t\tr-=1\n\tend\nend\n\nprint l+1, ' ', a.size - r"}, {"source_code": "n=STDIN.gets.chomp.to_i\nt=STDIN.gets.chomp.split\nt.map! {|x| x.to_i}\nalice=0\nbob=n-1\na=0\nb=0\nwhile true do\n consumed=t[alice] i\n if bob_time > alisa_time\n while bob_time > alisa_time && j > i\n alisa_time += times[i]\n i += 1\n end\n else\n while bob_time <= alisa_time && j > i\n bob_time += times[j]\n j -= 1\n end\n end\n end\n\n if bob_time < alisa_time\n i -= 1\n end\n\n puts [i + 1, times.size - i - 1].join(' ')\nend\nrun"}, {"source_code": "num = gets.chomp.to_i\narr = gets.split.map(&:to_i)\nif num == 1 then\n\tputs \"1 0\"\n\texit\nend\nl = 0\nr = num - 1\nlcurr = arr[0]\nrcurr = arr[num - 1]\nwhile l + 1 < r do\n\tif lcurr <= rcurr then\n\t\trcurr -= lcurr\n\t\tl += 1\n\t\tlcurr = arr[l]\n\telse\n\t\tlcurr -= rcurr\n\t\tr -= 1\n\t\trcurr = arr[r]\n\tend\nend\nprint l + 1, \" \", num - r\n"}, {"source_code": "n=gets.chomp.to_i\nm=gets.chomp.split.map{|i| i.to_i}\nif n==1\n puts \"1 0\"\n exit\nend\nif n==2\n puts \"1 1\"\n exit\nend\na=0\nb=n-1\nta=m[a]\ntb=m[b]\nwhile true\n if ta>tb\n b-=1\n ta=ta-tb\n tb=m[b]\n else\n a+=1\n tb=tb-ta\n ta=m[a]\n end\n if b-a==1\n break\n end\nend\nputs \"\"+(a+1).to_s+\" \"+(n-b).to_s\n \n"}, {"source_code": "n = gets.to_i\nt = gets.split.map(&:to_i)\na = 0\nb = n-1\nasum = 0\nbsum = 0\nwhile a <= b do\n if asum <= bsum then \n asum += t[a]\n a += 1\n else\n bsum += t[b]\n b -= 1\n end\nend\nprint a, \" \", n-a\nputs\n\n"}, {"source_code": "##\n# 6C\n# Author: Sammy Teahan\n#\n\nif __FILE__ == $0\n bars = gets.to_i\n time = gets.split.map(&:to_i)\n aliceCount = 0;\n bobCount = 0;\n aliceTotal = 0;\n bobTotal = 0;\n start = 0;\n last = bars - 1\n\n while start <= last do\n if aliceTotal <= bobTotal\n aliceTotal += time[start]\n start += 1\n aliceCount += 1\n else\n bobTotal += time[last]\n last -= 1\n bobCount += 1\n end\n end\n\n puts \"#{aliceCount} #{bobCount}\"\nend\n\n"}, {"source_code": "N = gets.to_i\nconsumeTime = gets.split.map{ |x| x.to_i}\na = 1\na_time = consumeTime.shift\nb = 0\nb_time = 0\nuntil consumeTime.empty? do\n if a_time>b_time\n b += 1\n b_time += consumeTime.pop\n else\n a += 1\n a_time += consumeTime.shift\n end\nend\nprint a,\" \",b,\"\\n\"\n"}, {"source_code": "n = gets.to_i\ntimes = gets.split.map(&:to_i)\nalice = 0\nbob = n - 1\nalice_time, bob_time = 0, 0\n\nwhile alice <= bob\n\tif alice_time <= bob_time\n\t\talice_time += times[alice]\n\t\talice += 1\n\telse\n\t\tbob_time += times[bob]\n\t\tbob -= 1\n\tend\nend\n\nputs [alice, n - alice].join(' ')"}], "negative_code": [{"source_code": "n=STDIN.gets.chomp.to_i\nt=STDIN.gets.chomp.split\nt.map! {|x| x.to_i}\nalice=0\nbob=n-1\na=0\nb=0\nwhile true do\n consumed=t[alice] t2\n while t1 > t2 and i < j\n a2 += 1\n t2 += a[j]\n j -= 1\n end\n elsif t2 > t1\n while t2 > t1 and i < j\n a1 += 1\n t1 += a[i]\n i += 1\n end\n else\n a1 += 1\n a2 += 1\n t1 += a[i]\n t2 += a[j]\n i += 1\n j -= 1\n x = z\n end\n end\n \n if x\n if t1 <= t2\n a1 += 1\n else\n a2 += 1\n end\n end\n puts \"#{a1} #{a2}\"\nend"}, {"source_code": "n = gets.to_i\na = gets.split(/\\s/).map {|x| x.to_i}\n\na1 = 0\na2 = 0\nt1 = 0\nt2 = 0\nsize = a.size\nif size == 1\n puts \"1 0\"\nelse\n i = 0\n j = size-1\n while i < j\n if t1 > t2\n while t1 > t2 and i < j\n a2 += 1\n t2 += a[j]\n j -= 1\n end\n elsif t2 > t1\n while t2 > t1 and i < j\n a1 += 1\n t1 += a[i]\n i += 1\n end\n else\n a1 += 1\n a2 += 1\n t1 += a[i]\n t2 += a[j]\n i += 1\n j -= 1\n end\n end\n \n if t1+t2 != n\n if t1 <= t2\n a1 += 1\n else\n a2 += 1\n end\n end\n puts \"#{a1} #{a2}\"\nend"}, {"source_code": "gets\na = gets.split.map(&:to_i)\n\ni, j = 0, a.size - 1\n\nif a.size > 1\n while i < j\n if a[i] == a[j]\n if i + 1 >= j\n i += 1\n else\n i += 1\n j -= 1\n end\n elsif a[i] < a[j]\n a[j] -= a[i]\n i += 1\n elsif a[i] > a[j]\n a[i] -= a[j]\n j -= 1\n end\n end\nelse\n i = 1\n j = a.size\nend\n\nputs \"#{i} #{a.size - j}\"\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\n\ni, j = 0, a.size - 1\n\nif a.size > 1\n while i < j\n if a[i] == a[j]\n if i + 1 >= j - 1\n i += 1\n else\n i += 1\n j -= 1\n end\n elsif a[i] < a[j]\n a[j] -= a[i]\n i += 1\n elsif a[i] > a[j]\n a[i] -= a[j]\n j -= 1\n end\n end\nelse\n i = 1\n j = a.size\nend\n\nputs \"#{i} #{a.size - j}\"\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\n\ni, j = 0, a.size - 1\n\nif a.size > 1\n while true\n if a[i] == a[j]\n a[i] = a[j] = 0\n i += 1\n j -= 1\n if i > j \n break\n elsif i == j\n i += 1\n break\n end\n elsif a[i] > a[j]\n a[i] -= a[j]\n i += 1\n if i == j\n j -= 1\n break\n end\n elsif a[i] < a[j]\n a[j] -= a[i]\n j -= 1\n if i == j\n i += 1\n break\n end\n end\n end\nelse\n i = 1\n j = a.size - 1\nend\n\nputs \"#{i} #{(a.size - 1) - j}\"\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\n\ni, j = 0, a.size - 1\n\nif a.size > 1\n while i < j\n if a[i] == a[j]\n if i + 1 >= j - 1\n i += 1\n else\n i += 1\n j -= 1\n end\n elsif a[i] < a[j]\n a[j] -= a[i]\n if i + 1 >= j\n j -= 1\n break\n end\n i += 1\n elsif a[i] > a[j]\n a[i] -= a[j]\n if i >= j - 1\n i += 1\n break\n end\n j -= 1\n end\n end\nelse\n i = 1\n j = a.size\nend\n\nputs \"#{i} #{a.size - j}\"\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\n\ni, j = 0, a.size - 1\n\nwhile i < j\n if a[i] == a[j]\n if i + 1 >= j\n i += 1\n else\n i += 1\n j -= 1\n end\n elsif a[i] < a[j]\n a[j] -= a[i]\n i += 1\n elsif a[i] > a[j]\n a[i] -= a[j]\n j -= 1\n end\nend\n\nputs \"#{i} #{a.size - j}\"\n"}, {"source_code": "n = gets.to_i\n\na = gets.split.collect{|x| x.to_i}\n\nl,r = 0, a.size-1\n\nwhile l+1 < r\n\t# print [l,r],\"\\n\"\n\tmin = [a[l],a[r]].min\n\ta[l] -= min\n\ta[r] -= min\n\n\tif a[l] == 0 and l < r-1\n\t\tl+=1\n\tend\n\tif a[r] == 0 and r-1 > l\n\t\tr-=1\n\tend\nend\n\nprint l+1, ' ', a.size - r"}], "src_uid": "8f0172f742b058f5905c0a02d79000dc"} {"source_code": "t = readline.strip.to_i\r\n\r\nt.times do\r\n n = readline.strip.to_i\r\n nums = readline.strip.split(/\\s+/).map(&:to_i)\r\n \r\n res = 0\r\n nums.each do |e|\r\n res |= e\r\n end\r\n \r\n puts res\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times {\n gets\n xs = gets.split.map!(&:to_i)\n p xs.inject(:|)\n}\n"}], "negative_code": [], "src_uid": "7fca54a73076ddfeb30b921b9e341f26"} {"source_code": "$,, $\\= ' ', \"\\n\"\ngets.to_i.times do\n l, r = gets.split.map &:to_i\n print -1, -1 if 2 * l > r\n print l, 2 * l if 2 * l <= r\nend", "positive_code": [{"source_code": "n = gets.to_i\nans = []\nn.times do\n l,r = gets.chomp.split(\" \").map(&:to_i)\n if l * 2 <= r\n ans << [l,l*2]\n else\n ans << [-1,-1]\n end\nend\nans.each do |x|\n puts \"#{x[0]} #{x[1]}\"\nend"}], "negative_code": [{"source_code": "$, = ' '\ngets.to_i.times do\n l, r = gets.split.map &:to_i\n print -1, -1 if 2 * l > r\n print l, 2 * l if 2 * l <= r\nend"}], "src_uid": "e8ba3fb95800806465386ecbfbe924e9"} {"source_code": "t = gets.chomp.to_i\nt.times do \n n, m = gets.chomp.split(\" \").map(&:to_i)\n four = 0\n two = 0\n no = 0\n j = []\n n.times do\n i = []\n arr = []\n ar = []\n tokubetu = []\n a, b = gets.chomp.split(\" \").map(&:to_i)\n c, d = gets.chomp.split(\" \").map(&:to_i)\n arr << a\n arr << b\n ar << c\n ar << d\n i << arr\n i << ar\n if a == b && b == c && c == d\n four += 1\n elsif b == c\n two += 1\n else\n no += 1\n tokubetu << a\n tokubetu << d\n j << tokubetu\n end\n end\n # p four\n # p two\n # p no\n if m % 2 != 0\n puts \"NO\"\n elsif four >= 1\n puts \"YES\"\n elsif two >= 1\n puts \"YES\"\n else\n puts \"NO\"\n end\nend", "positive_code": [{"source_code": "gets.to_i.times{n,m=gets.split.map(&:to_i);puts(if Array.new(n){_,a=gets.split.map(&:to_i);b,_=gets.split.map(&:to_i);a==b;}.reduce(:|)and m.even?then :YES else :NO end)}\n"}, {"source_code": "t = gets.to_i\nt.times {\n n, m = gets.split.map(&:to_i)\n puts (if Array.new(n) {\n _, a = gets.split.map(&:to_i)\n b, _ = gets.split.map(&:to_i)\n a == b\n }.reduce(:|) and m.even? then :YES else :NO end)\n}\n"}, {"source_code": "t = gets.chomp.to_i\n\nt.times do\n line = gets.chomp.split(' ')\n n = line[0].to_i\n m = line[1].to_i\n result = false\n\n n.times do\n line = gets.chomp.split(' ')\n a = line[0].to_i\n b = line[1].to_i\n line = gets.chomp.split(' ')\n c = line[0].to_i\n d = line[1].to_i\n result ||= b == c\n end\n \n (m % 2).zero? && result ? (puts 'YES') : (puts 'NO')\nend"}], "negative_code": [], "src_uid": "f46f6fa28d0a7023da3bad0d222ce393"} {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nm,b,bi=n/k,1.0/0,-1\nk.times do |i|\n s=0\n m.times{|j|s+=a[i+k*j]}\n b,bi=s,i+1 if s < b\nend\np bi", "positive_code": [{"source_code": "n,k=gets.chomp.split.map(&:to_i)\nb,ans=Array.new(k,0),0\na=gets.chomp.split.map(&:to_i)\na.length.times {|i| b[i%k]+=a[i]}\nputs b.index(b.min)+1"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\nm = n/k\nk_list = []\n(0..((n/m)-1)).each do |i|\n\tk_list << (i..(n-1)).step(k).to_a\nend\nsum = []\nk_list.each do |a|\n\tsum << a.inject(0){|s,x| s += arr[x]}\t\nend\n# puts \"#{sum}\"\nmin,min_ind = sum.each_with_index.min\nputs k_list[min_ind][0]+1"}, {"source_code": "def read_next_line\n gets.split.map { |x| x.to_i }\nend\n\nn, k = read_next_line\na = read_next_line\nsums = Array.new(k)\nfor i in 0...k\n sum = 0\n for j in (i...n).step(k)\n sum += a[j]\n end\n sums[i] = sum\nend\nputs sums.index(sums.min) + 1"}], "negative_code": [], "src_uid": "646cec22d98636447038e61e7dfb9db3"} {"source_code": "require 'bigdecimal'\n\ngets\nm = gets.to_i\np = 1\nq = 1\n\n2.times do\n gets.split.map{|x| x.to_i}.each do |x|\n p *= x\n q *= x-1\n end\nend\n\nif q == 0\n puts (-1)\nelse\n puts m*BigDecimal.new(p)/q-m\nend", "positive_code": [{"source_code": "require 'bigdecimal'\n\ngets\nm = gets.to_i\np = 1\nq = 1\n\n2.times do\n gets.split.map{|x| x.to_i}.each do |x|\n p *= x\n q *= x-1\n end\nend\n\nif q == 0\n puts (-1)\nelse\n puts m*BigDecimal.new(p)/BigDecimal.new(q)-m\nend\n\n\n"}, {"source_code": "N = gets.to_i\nM = gets.to_i\nas = gets.split.map(&:to_i)\nbs = gets.split.map(&:to_i)\n\ncos = [bs[0], as[-1]]\n(N-2).downto(0) do |i|\n cos.push(bs[i+1], as[i])\nend\n\n\nw = M.to_f\ncos.each do |c|\n if c == 1\n puts -1\n exit\n end\n w *= c.to_f / (c-1)\nend\nputs sprintf(\"%.10f\", w-M)"}, {"source_code": "n = gets.to_i\nm = gets.to_i\nais = gets.strip.split.map(&:to_i)\nbis = gets.strip.split.map(&:to_i)\n\nif ais.include?(1) || bis.include?(1)\n puts -1\n exit 0\nend\n\nais = ais.map{|x|Rational(x)}\nbis = bis.map{|x|Rational(x)}\n\ndef get_weight_before_landing(al, b)\n (b*al)/(b- Rational(1))\nend\n\ndef get_weight_before_takeoff(at, a)\n (a*at)/(a- Rational(1))\nend\n\nrw = Rational(m)\nrw = get_weight_before_landing(rw, bis[0])\n(n-1).downto(1).each do |s|\n rw = get_weight_before_takeoff(rw, ais[s])\n rw = get_weight_before_landing(rw, bis[s])\nend\nrw = get_weight_before_takeoff(rw, ais[0])\nputs (rw - Rational(m)).to_f"}], "negative_code": [{"source_code": "gets\nm = gets.to_i\np = 1\nq = 1\n\n2.times do\n gets.split.map{|x| x.to_i}.each do |x|\n p *= x\n q *= x-1\n end\nend\n\nif q == 0\n puts (-1)\nelse\n puts m*p.to_f/q\nend\n\n\n"}, {"source_code": "gets\nm = gets.to_i\np = 1\nq = 1\n\n2.times do\n gets.split.map{|x| x.to_i}.each do |x|\n p *= x\n q *= x-1\n end\nend\n\nif q == 0\n puts (-1)\nelse\n puts m*p.to_f/q-m\nend"}, {"source_code": "gets\nm = gets.to_i\np = 1\nq = 1\n\n2.times do\n gets.split.map{|x| x.to_i}.each do |x|\n p *= x\n q *= x-1\n end\nend\n\nif q == 0\n puts (-1)\nelse\n puts m*p/q.to_f-m\nend"}], "src_uid": "d9bd63e03bf51ed87ba73cd15e8ce58d"} {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" \n", "positive_code": [{"source_code": "n,m = gets.split.map{|i| i.to_i}\n\nt = Array.new(m) {|i| i = []}\nresult = \"YES\"\n\nn.times do\n s = gets.chomp\n k = s[0]\n if s.delete(s[0]).size != 0 then\n result = \"NO\"\n end\n m.times do |i|\n if t[i][-1] == s[i] then\n result = \"NO\"\n end\n t[i] << s[i]\n end\nend\n\nputs result"}, {"source_code": "ns,ms = gets.chomp.split(/ /)\nn = ns.to_i\nm = ms.to_i\nar = Array.new(n)\nfor i in 0..n-1\n\ts = gets.chomp\n\tar[i] = s.split(//)\nend\n\nret = \"YES\"\nfor i in 0..n-1\n\tfor j in 1..m-1\n\t\tif ar[i][j] != ar[i][0]\n\t\t\tret = \"NO\"\n\t\t\tbreak;\n\t\tend\n\tend\n\tif i > 0\n\t\tif ar[i][0] == ar[i-1][0]\n\t\t\tret = \"NO\"\n\t\t\tbreak;\n\t\tend\n\tend\nend\n\nputs ret"}, {"source_code": "n, m = gets.strip.split.map { |e| e.to_i }\ncolor = ''\nbool = true\nn.times do\n\tstr = gets.strip.squeeze\n\tif str.size != 1\n\t\tbool = false\n\telse\n\t\tif str != color\n\t\t\tcolor = str\n\t\telse\n\t\t\tbool = false\n\t\tend\n\tend\nend\nif bool\n\tputs 'YES'\nelse\n\tputs 'NO'\nend"}, {"source_code": "\nn=gets.to_i\nback=-1\n(1..n).each{\n data=gets.split[0]\n if(back==data[0].to_i) then\n puts \"NO\"\n exit\n end\n back=data[0].to_i\n for i in 1..data.length-1\n if(data[i].to_i!=data[0].to_i) then\n puts \"NO\"\n exit\n end\n end\n}\nputs \"YES\"\n"}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" \n"}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" \n"}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" "}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" "}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" "}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" \n"}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" \n"}, {"source_code": "#!/usr/bin/ruby\n\nn, m = gets.chomp.split.map{|e| e.to_i}\ncolor = -1\nn.times do \n this_line = gets.chomp.split('').map{|e| e.to_i}\n if this_line[0] == color\n puts \"NO\"\n exit\n end\n color = this_line[0]\n this_line.each{|e|\n if e != color\n puts \"NO\"\n exit\n end\n }\nend\nputs \"YES\"\n"}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" "}, {"source_code": "rez = gets.split(\" \").map { |e| e.to_i }\nflag = true\nk = 0\nch = 'a'\nrez[0].times {\n s = gets\n k += 1\n if k != 1 \n if s[0] == ch then\n flag = false\n break\n end\n end\n mas = s.chomp.split(\"\").map { |e| e.to_i }\n mas = mas | mas\n if mas.size != 1 \n flag = false\n end\n ch = s[0]\n\n}\nputs \"YES\" if flag\nputs \"NO\" if !flag"}, {"source_code": "n, m = gets.split.map(&:to_i)\ngrid = []\ncompare = [\"\"]\niso = false\nn.times do\n\trow = gets.chomp.split('')\n\tunique = row.uniq\n\tif unique.length > 1 || unique == compare\n\t\tputs \"NO\"\n\t\tiso = false\n\telse\n\t\tcompare = unique\n\t\tiso = true\n\tend\n\tbreak unless iso\nend\nputs \"YES\" if iso"}, {"source_code": "def main()\n\tnm=gets.chomp.to_s.split(\" \");\n\tn=nm[0].to_i;\n\tm=nm[1].to_i;\n\tfr=gets.chomp;\n\tprevn=fr[0].chr;\n\tnofn=fr.count(prevn);\n\tif nofn==m\n\t\tf=true;\n\t\tfor i in 1...n\n\t\t\tr=gets.chomp;\n\t\t\tif prevn==r[0].chr\n\t\t\t\tf=false;\n\t\t\telse\n\t\t\t\tprevn=r[0].chr;\n\t\t\t\tnofn=r.count(prevn);\n\t\t\t\tif nofn!=m\n\t\t\t\t\tf=false;\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tif f\n\t\t\tputs \"YES\"\n\t\telse\n\t\t\tputs \"NO\"\n\t\tend\n\telse\n\t\tputs \"NO\";\n\tend\nend\nmain()"}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" \n"}, {"source_code": "input = gets.chomp.split(' ').map { |e| e.to_i }\nflag = Array.new(input[1])\nf_bool = true\n(0...input[0]).each do |i|\n flag[i] = gets.chomp.to_s\nend\n(0...input[0]).each do |i|\n if flag[i].count(flag[i][0]) != flag[i].length\n puts \"NO\"\n f_bool = false\n break\n else\n if flag.length == 1\n puts \"YES\"\n f_bool = false\n break\n else\n if i == 0\n if flag[0] == flag[1]\n puts \"NO\"\n f_bool = false\n break\n end\n else\n if flag[i] == flag[i+1] || flag[i] == flag[i-1]\n puts \"NO\"\n f_bool = false\n break\n end\n end\n end\n end\nend\nputs \"YES\" if f_bool"}, {"source_code": "n=gets.to_i\nrows=gets(p).split.map(&:squeeze)\nputs rows.all?{|str| str.size==1}&&(rows*\"\").squeeze.size==n ?:YES :\"NO\" "}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\nflag = Array.new(m,-1)\n(1..n).each do\n tmp = gets.chomp.split(\"\").collect{|i| i.to_i}\n if flag[0] == tmp[0] or tmp.count(tmp[0]) != m\n puts \"NO\"\n exit\n end\n flag = tmp\nend\nputs \"YES\"\n"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\nflag = -1\n(1..n).each do\n tmp = gets.chomp.split(\"\").collect{|i| i.to_i}\n if flag == tmp[0] or tmp.count(tmp[0]) != m\n puts \"NO\"\n exit\n end\n flag = tmp[0]\nend\nputs \"YES\"\n"}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" "}, {"source_code": "n_and_m = gets.split(\" \")\nn = n_and_m[0].to_i\nm = n_and_m[1]\nbandeira = []\nresposta = \"YES\"\nn.times do\n\tlinha = gets.strip\n\tlinha_horizontal = linha.split(\"\")\n\tcor_da_linha = linha_horizontal.uniq\n\t\tif cor_da_linha.size != 1 \n\t\t\tresposta = \"NO\"\n\t\tend\n\tbandeira << cor_da_linha\nend\nfor cor in 1..bandeira.size - 1 do\n\tbreak if resposta == \"NO\" || bandeira.size == 1\n\tif bandeira[cor - 1] == bandeira[cor] || bandeira[cor + 1] == bandeira[cor]\n\t\tresposta = \"NO\"\n\t\tbreak\n\telse\n\t\tresposta = \"YES\"\n\tend\nend\nputs resposta"}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" \n"}, {"source_code": "class String\n def uniq?\n self.split('').uniq.size < 2\n end\nend\n\ndef print_no\n puts 'NO'\n exit\nend\n\nn, _ = gets.split.map { |x| x.to_i }\np = gets.chomp\nprint_no unless p.uniq?\nfor __ in 2..n\n s = gets.chomp\n print_no unless s != p && s.uniq?\n p = s\nend\nputs 'YES'"}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" \n"}, {"source_code": "s1 = gets.chomp.split\n\nn = s1[0].to_i\nm = s1[1].to_i\nk = 0\nall = []\nok = true;\n\nfor i in 1..n do\n\ts = gets.chomp\n\tt = s[0];\n\tok = true;\n\tfor j in 1..s.length-1 do\n\t\tif t != s[j]\n\t\t\tok = false;\n\t\tend\n\tend\n\tif not ok\n\t\tprint \"NO\"\n\t\tbreak\n\tend\n\tall[k] = t\n\tk+=1\nend\n\nif ok\n\ttr = true\n\tfor i in 0..k-2 do\n\t\tif all[i] == all[i + 1]\n\t\t\tprint \"NO\"\n\t\t\ttr = false\n\t\t\tbreak\n\t\tend\n\tend\n\n\tif tr\n\t\tprint \"YES\"\n\tend\nend\n"}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" "}, {"source_code": "\nn,m=gets.split.map(&:to_i)\nprev=\"z\"; result=true\nn.times do\n\tline=gets.split(//)\n\tif line[0]==prev\n\t\tresult=false\n\tend\n\tprev=line[0]\n\tif line.count(line[0])!=m\n\t\tresult=false\n\tend\nend\n\nif result\n\tputs \"YES\\n\"\nelse\n\tputs \"NO\\n\"\nend\n\n\n\n"}, {"source_code": "gets; flag = STDIN.read.split \"\\n\"\n\nflag.each.with_index do |f, i|\n\tif f.length == f.count(f[0])\n\t\tf.length.times do |j|\n\t\t\tif i > 0\n\t\t\t\t(print :NO; exit) if flag[i][j] == flag[i - 1][j]\n\t\t\tend\n\t\tend\n\telse\n\t\tprint :NO\n\t\texit\n\tend\nend\n\nprint :YES\n"}, {"source_code": "t = gets.split.collect{|x| x.to_i}\nn,m = t[0], t[1]\n\nok = 'YES'\nlast = ''\n\nn.times do |i|\n\ts = gets.strip\n\tif last != ''\n\t\tif s == last\n\t\t\tok = 'NO'\n\t\tend\n\tend\n\tif s != s[0]*m\n\t\tok = 'NO'\n\tend\n\tlast = s\nend\n\nputs ok"}, {"source_code": "n=gets.to_i\na=gets(p).split.map(&:squeeze)\nputs a.all?{|s|s.size<2}&&(a*\"\").squeeze.size==n ?:YES :\"NO\" \n"}, {"source_code": "puts %w[YES NO][STDIN.readlines.drop(1).map { |x| x.chomp }.reduce(['*', 0]) { |s, x| [x[0], s.last | (x.chars.to_a.uniq.length == 1 && x[0] != s.first ? 0 : 1)] }.last]\t"}], "negative_code": [{"source_code": "n,m = gets.split.map{|i| i.to_i}\n\nt = {}\nresult = \"YES\"\n\nn.times do\n s = gets.chomp\n k = s[0]\n if s.delete(s[0]).size != 0 then\n result = \"NO\"\n end\n m.times do |i|\n if t[i] then\n if t[i].include? s[i] then\n result = \"NO\"\n else\n t[i] << s[i]\n end\n else\n t[i] = [s[i]]\n end\n end\nend\n\nputs result"}, {"source_code": "n_m = gets.chomp.split(' ').map { |i| i.to_i }\nflag = Array.new(n_m[1])\n(0...n_m[0]).each do |i|\n flag[i] = gets.chomp.to_s\nend\nbol = true\n(0...n_m[1]).each do |i|\n if n_m[0] > 1\n if i == 0\n if flag[i] == flag[i+1]\n bol = false\n puts \"NO\"\n break\n end\n (0...flag[i].length).each do |j|\n if flag[i][0] != flag[i][j]\n bol = false\n puts \"NO\"\n break\n end\n end\n if bol == false\n break\n end\n else\n if flag[i] == flag[i+1] || flag[i] == flag[i-1]\n bol = false\n puts \"NO\"\n break\n end\n if bol == false\n break\n end\n (0...flag[i].length).each do |j|\n if flag[i][0] != flag[i][j]\n bol = false\n puts \"NO\"\n break\n end\n end\n if bol == false\n break\n end\n end\n else\n (0...n_m[1]).each do |j|\n if flag[0][0] != flag[0][j]\n bol = false\n puts \"NO\"\n break\n end\n end\n break if bol == false\n end\nend\nputs \"YES\" if bol == true"}, {"source_code": "n_m = gets.chomp.split(' ').map { |i| i.to_i }\nflag = Array.new(n_m[1])\n(0...n_m[0]).each do |i|\n flag[i] = gets.chomp.to_s\nend\nbol = true\n(0...n_m[1]).each do |i|\n if i== 0\n if flag[i] == flag[i+1]\n bol = false\n puts \"NO\"\n break\n end\n (0...flag[i].length).each do |j|\n if flag[i][0] != flag[i][j]\n bol = false\n puts \"NO\"\n break\n end\n end\n else\n if flag[i] == flag[i+1] || flag[i] == flag[i-1]\n bol = false\n puts \"NO\"\n break\n end\n (0...flag[i].length).each do |j|\n if flag[i][0] != flag[i][j]\n bol = false\n puts \"NO\"\n break\n end\n end\n end\nend\nputs \"YES\" if bol == true"}, {"source_code": "input = gets.chomp.split(' ').map { |e| e.to_i }\nflag = Array.new(input[1])\nf_bool = true\n(0...input[0]).each do |i|\n flag[i] = gets.chomp.to_s\nend\n(0...input[0]).each do |i|\n if flag[i].count(flag[i][0]) != flag[i].length\n puts \"NO\"\n f_bool = false\n else\n if flag.length == 1\n puts \"YES\"\n f_bool = false\n break\n else\n if i == 0\n if flag[0] == flag[1]\n puts \"NO\"\n f_bool = false\n break\n end\n else\n if flag[i] == flag[i+1] || flag[i] == flag[i-1]\n puts \"NO\"\n f_bool = false\n break\n end\n end\n end\n end\nend\nputs \"YES\" if f_bool"}, {"source_code": "n_m = gets.chomp.split(' ').map { |i| i.to_i }\nflag = Array.new(n_m[1])\n(0...n_m[0]).each do |i|\n flag[i] = gets.chomp.to_s\nend\nbol = true\n(0...n_m[1]).each do |i|\n if i== 0\n if flag[i] == flag[i+1]\n bol = false\n puts \"NO\"\n break\n end\n (0...flag[i].length).each do |j|\n if flag[i][0] != flag[i][j]\n bol = false\n puts \"NO\"\n break\n end\n end\n if bol == false\n break\n end\n else\n if flag[i] == flag[i+1] || flag[i] == flag[i-1]\n bol = false\n puts \"NO\"\n break\n end\n if bol == false\n break\n end\n (0...flag[i].length).each do |j|\n if flag[i][0] != flag[i][j]\n bol = false\n puts \"NO\"\n break\n end\n end\n if bol == false\n break\n end\n end\nend\nputs \"YES\" if bol == true"}, {"source_code": "n_m = gets.chomp.split(' ').map { |i| i.to_i }\nflag = Array.new(n_m[1])\n(0...n_m[0]).each do |i|\n flag[i] = gets.chomp.to_s\nend\nbol = true\n(0...n_m[1]).each do |i|\n if n_m[0] == 1\n break\n end\n if i== 0\n if flag[i] == flag[i+1]\n bol = false\n puts \"NO\"\n break\n end\n (0...flag[i].length).each do |j|\n if flag[i][0] != flag[i][j]\n bol = false\n puts \"NO\"\n break\n end\n end\n if bol == false\n break\n end\n else\n if flag[i] == flag[i+1] || flag[i] == flag[i-1]\n bol = false\n puts \"NO\"\n break\n end\n if bol == false\n break\n end\n (0...flag[i].length).each do |j|\n if flag[i][0] != flag[i][j]\n bol = false\n puts \"NO\"\n break\n end\n end\n if bol == false\n break\n end\n end\nend\nputs \"YES\" if bol == true"}, {"source_code": "n_and_m = gets.split(\" \")\nn = n_and_m[0].to_i\nm = n_and_m[1]\nbandeira = []\nresposta = \"\"\nn.times do\n\tlinha = gets.strip\n\tlinha_horizontal = linha.split(\"\")\n\tcor_da_linha = linha_horizontal.uniq\n\t\tif cor_da_linha.size != 1 \n\t\t\tresposta = \"NO\"\n\t\tend\n\tbandeira << cor_da_linha\nend\nfor cor in 1..bandeira.size - 1 do\n\tbreak if resposta == \"NO\"\n\tif bandeira[cor - 1] == bandeira[cor] || bandeira[cor + 1] == bandeira[cor]\n\t\tresposta = \"NO\"\n\t\tbreak\n\telse\n\t\tresposta = \"YES\"\n\tend\nend\nputs resposta"}, {"source_code": "t = gets.split.collect{|x| x.to_i}\nn,m = t[0], t[1]\n\nok = 'YES'\nlast = ''\n\nn.times do |i|\n\ts = gets.strip\n\tif last != ''\n\t\tif s == last or s != s[0]*m\n\t\t\tok = 'NO'\n\t\tend\n\telse\n\t\tlast = s\n\tend\nend\n\nputs ok"}, {"source_code": "t = gets.split.collect{|x| x.to_i}\nn,m = t[0], t[1]\n\nok = 'YES'\nlast = ''\n\nn.times do |i|\n\ts = gets.strip\n\tif last != ''\n\t\tif s == last or s != s[0]*m\n\t\t\tok = 'NO'\n\t\tend\n\tend\n\tlast = s\nend\n\nputs ok"}], "src_uid": "80d3da5aba371f4d572ea928025c5bbd"} {"source_code": "px,py,vx,vy,a,b,c,d=gets.split.map &:to_f\nl=Math.hypot(vx,vy)\nputs [[b,0],[0,-a],[0,-c],[-d,-c],[-d,c],[0,c],[0,a]].map{|s,t|[px+s/l*vx+t/2/l*vy,py+s/l*vy-t/2/l*vx]*' '}\n", "positive_code": [{"source_code": "px,py,vx,vy,a,b,c,d=gets.split.map &:to_f\nl=Math.hypot(vx,vy)\nputs [[b,0],[0,-a],[0,-c],[-d,-c],[-d,c],[0,c],[0,a]].map{|s,t|[px+s/l*vx+t/2/l*vy,py+s/l*vy-t/2/l*vx]*' '}"}, {"source_code": "px,py,vx,vy,a,b,c,d=gets.split.map &:to_f\nl=Math.hypot(vx,vy)\nputs [[b,0],[0,-a],[0,-c],[-d,-c],[-d,c],[0,c],[0,a]].map{|s,t|[px+s/l*vx+t/2/l*vy,py+s/l*vy-t/2/l*vx]*' '}\n"}], "negative_code": [{"source_code": "px,py,vx,vy,a,b,c,d=gets.split.map &:to_f\nl=Math.hypot(vx,vy)\nputs [[b,0],[0,-a],[0,-c],[-d,-c],[-d,c],[0,c],[0,a]].map{|s,t|[px+s/l*vx+t/2/l*vy,py+s/l*vy+t/2/l*vx]*' '}"}], "src_uid": "2cb1e7e4d25f624da934bce5c628a7ee"} {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/20\n cnt=1\n end \n prev=a[i]\n i+=1\nend\nans<<[n-cnt,n-1,cnt] if cnt>0\n#puts ans.to_s\n\nprev_en=-2\nprev_cnt=0\nmax=0\nans.each do |st,en,cnt|\n if (st-prev_en)==2 && a[prev_en]1&&a[prev_en]1&&a[prev_en-1] 1\n dp[i][0] = dp[i - 2][1] + 1 if a[i] - a[i - 2] > 0\n end\n if a[i] - a[i - 1] > 0\n dp[i][1] = dp[i - 1][1] + 1\n dp[i][2] = [dp[i - 1][2], dp[i - 1][0]].max + 1\n end\n an = [an, dp[i][0], dp[i][2]].max\n }\n puts an\nend\n\nsolve"}], "negative_code": [], "src_uid": "87b8dccfc0e5a63cd209c37cf8aebef0"} {"source_code": "#! ruby -Ku\n# -*- coding: UTF-8 -*-\n\ndef check_movability(start, goal)\n if start == nil || goal == nil\n return false\n end\n a = start[0]\n b = start[1]\n c = goal[0]\n d = goal[1]\n if (c < a && a < d) || (c < b && b < d)\n return true\n else\n return false\n end\nend\n\ndef answer(intervals, query)\n intervals.each do |elem|\n if elem != nil\n elem[2] = false\n end\n end\n \n current = intervals[query.shift-1]\n goal = intervals[query.shift-1]\n if current == nil || goal == nil\n return false\n end\n stack = Array::new\n stack.push(current)\n\n while stack.size != 0\n current = stack.pop\n if check_movability(current, goal)\n return true\n else\n current[2] = true\n intervals.each do |elem|\n if check_movability(current, elem) && !elem[2]\n stack.push(elem)\n end\n end\n end\n end\n\n return false\nend\n\n# file = open(\"input.txt\")\n# total_line = file.gets.to_i\ntotal_line = gets.to_i\n\nintervals = Array::new\nqueries = Array::new\n\ntotal_line.times do |i|\n # input = file.gets.split.map(&:to_i)\n input = gets.split.map(&:to_i)\n if input.shift == 1\n input << false\n intervals << input\n else\n check = answer(intervals, input)\n if check == true\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\nend\n", "positive_code": [{"source_code": "def dfs (a, f, i)\n x, y = a[i]\n f[i] = true\n a.each_index do |j|\n nx, ny = a[j]\n next if f[j]\n dfs(a, f, j) if ((nx < x and x < ny) or (nx < y and y < ny))\n end \nend\n\na = []\nn = gets.strip.to_i\nn.times do\n t, x, y = gets.strip.split(\" \").collect{|v| v.to_i}\n if t == 1 then\n a << [x, y]\n next\n end\n\n f = Hash.new{|h,k| h[k] = false}\n dfs(a, f, x-1)\n f[y-1] ? (puts \"YES\") : (puts \"NO\")\nend"}, {"source_code": "\n# Define a func to update reachability matrix\ndef update_reach(reachabilty, intervals)\n reachabilty.push([])\n j = intervals.length - 1; c = intervals[j][1]; d = intervals[j][2]; \n for i in 0..(j - 1) do\n a = intervals[i][1]; b = intervals[i][2];\n if (((c < a) && (a < d)) || ((c < b) && (b < d)))\n reachabilty[i].push(j)\n end\n if (((a < c) && (c < b)) || ((a < d) && (d < b)))\n reachabilty[j].push(i) \n end\n end\nend\n\n# Define a func to run dfs\ndef dfs(root, traversal, reachabilty)\n traversal[traversal.length] = root\n for child in reachabilty[root] do\n unless traversal.include?(child)\n dfs(child, traversal, reachabilty) \n end\n end\nend\n\n# Initialize variables\nn = 0; queries = []; traversal = []; reachabilty = []; intervals = [];\n\n# Read input\nn = gets.strip.to_i\nn.times {queries.push(gets.strip.split.map{|s| s.to_i})}\n\n# Loop over queries\nfor i in 0..(n - 1) do\n if queries[i][0] == 1\n intervals.push(queries[i])\n update_reach(reachabilty, intervals)\n else\n traversal = []; root, target = queries[i][1,2].map{|k| k - 1};\n dfs(root,traversal,reachabilty)\n puts traversal.include?(target) ? \"YES\" : \"NO\"\n end\nend\n"}, {"source_code": "\ndef compute_reachability arr, index\n (1..index).each do |k|\n (1..index).each do |i|\n (1..index).each do |j|\n if (arr[i][j] == nil) && arr[i][k] !=nil && arr[k][j] != nil \n arr[i][j] = 1\n end\n end\n end\n end\nend\n\nn = gets.to_i\narr = Array.new(n + 1) {Array.new(n + 1)}\nintervals = []\n(1..n).each { |i| arr[i][i] = nil}\n(1..n).each do |index|\n command, x, y = gets.split(' ').map(&:to_i)\n if command == 1\n current = intervals.length + 1\n intervals.each_with_index do |interval, i|\n a,b = interval[0], interval[1]\n if ( a < x && x < b) || ( a < y && y < b)\n arr[current][i +1] = 1\n end\n if (x < a && a < y) || ( x < b && b < y)\n arr[i +1][current] = 1\n end \n end\n compute_reachability(arr, current)\n intervals << [x,y]\n else\n puts arr[x][y]!=nil ? \"YES\" : \"NO\"\n end\n\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\n$arr = []\n\ndef forward_edge(a, b, c, d)\n\t(c < a and a < d) or (c < b and b < d)\nend\n\ndef dfs(vis, a)\n\tif vis[a]\n\t\treturn\n\tend\n\tvis[a] = true\n\n\t(0...$arr.size).each do |u|\n\t\tif forward_edge(*$arr[a], *$arr[u])\n\t\t\tdfs(vis, u)\n\t\tend\n\tend\nend\n\n# a, b are 0-indexed\ndef query(a, b)\n\tvis = [false]*($arr.size)\n\tdfs(vis, a)\n\n\tputs vis[b] ? \"YES\" : \"NO\"\nend\n\ngets\nreadlines.each do |line|\n\tcmd, x, y = line.strip.split.map(&:to_i)\n\tif cmd == 1\n\t\t$arr << [x, y]\n\telse\n\t\tquery(x - 1, y - 1)\n\tend\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\ndef can_go?(x, y, path, vis)\n vis[x] = true\n return true if x == y\n path[x].each do |to|\n next if vis[to]\n return true if can_go?(to, y, path, vis)\n end\n return false\nend\nn = gets.to_i\ncan_go = Array.new(105){Array.new}\ninterval = [[0, 0]]\nn.times do\n p, a, b = gets.split(' ').map(&:to_i)\n if p == 1\n for i in 1...interval.size\n c, d = interval[i]\n can_go[interval.size] << i if((c < a && a < d) || (c < b && b < d))\n can_go[i] << interval.size if((a < c && c < b) || (a < d && d < b))\n end\n interval << [a, b]\n else\n vis = Array.new(105, false)\n puts can_go?(a, b, can_go, vis) ? \"YES\" : \"NO\"\n end\nend\n"}, {"source_code": "\n\ndef dfs(i)\n\t@visited[i] = true\n\t@arr.each_with_index do |a,k|\n\t\tif @visited[k]\n\t\t\tnext\n\t\t\t#@arr[i][0]-a,@arr[i][1]- b, a[0] - c,a[1] - d\n\t\telsif a[0] < @arr[i][0] && @arr[i][0] < a[1]\n\t\t\tdfs(k)\n\t\telsif a[0] < @arr[i][1] && @arr[i][1] < a[1]\n\t\t\tdfs(k)\n\t\tend\n\tend\t\nend\n\n\nn = gets.to_i\n@arr = []\nn.times do\n\tm,a,b = gets.split(\" \").map(&:to_i)\n\tif m == 1\n\t\t@arr << [a,b]\n\telse\n\t\t@visited = Hash.new(false)\n\t\tdfs(a-1)\n\t\tif @visited[b-1]\n\t\t\tputs \"YES\"\n\t\telse\n\t\t\tputs \"NO\"\n\t\tend\n\tend\nend"}], "negative_code": [{"source_code": "\n\ndef dfs(i)\n\t@visited[i] = true\n\t@arr.each_with_index do |a,k|\n\t\tif @visited[k]\n\t\t\tnext\n\t\t\t#@arr[i][0]-a,@arr[i][1]- b, a[0] - c,a[1] - d\n\t\telsif a[0] < @arr[i][0] && @arr[i][0] < a[1]\n\t\t\tdfs(k)\n\t\telsif a[0] < @arr[i][1] && @arr[i][1] < a[1]\n\t\t\tdfs(k)\n\t\tend\n\tend\t\nend\n\n\nn = gets.to_i\n@arr = []\nn.times do\n\tm,a,b = gets.split(\" \").map(&:to_i)\n\tif m == 1\n\t\t@arr << [a,b]\n\telse\n\t\t@visited = Hash.new(false)\n\t\tdfs(a)\n\t\tif @visited[b]\n\t\t\tputs \"YES\"\n\t\telse\n\t\t\tputs \"NO\"\n\t\tend\n\tend\nend"}, {"source_code": "def dfs (a, f, i)\n x, y = a[i]\n f[i] = true\n a.each_index do |j|\n nx, ny = a[j]\n next if f[j]\n dfs(a, f, j) if ((nx < x and x < ny) or (nx < y and y < ny))\n end \nend\n\na = []\nf = Hash.new{|h,k| h[k] = false}\nn = gets.strip.to_i\nn.times do\n t, x, y = gets.strip.split(\" \").collect{|v| v.to_i}\n if t == 1 then\n a << [x, y]\n next\n end\n\n dfs(a, f, x-1)\n f[y-1] ? (puts \"YES\") : (puts \"NO\")\nend"}, {"source_code": "#! ruby -Ku\n# -*- coding: UTF-8 -*-\n\ndef check_movability(start, goal)\n if start == nil || goal == nil\n return false\n end\n a = start[0]\n b = start[1]\n c = goal[0]\n d = goal[1]\n if (c < a && a < d) || (c < b && b < d)\n return true\n else\n return false\n end\nend\n\ndef answer(intervals, query)\n intervals.each do |elem|\n if elem != nil\n elem[2] = false\n end\n end\n \n current = intervals[query.shift-1]\n goal = intervals[query.shift-1]\n if current == nil || goal == nil\n return false\n end\n stack = Array::new\n stack.push(current)\n\n while stack.size != 0\n current = stack.pop\n if check_movability(current, goal)\n return true\n else\n current[2] = true\n intervals.each do |elem|\n if check_movability(current, elem) && !elem[2]\n stack.push(elem)\n end\n end\n end\n end\n\n return false\nend\n\n# file = open(\"input.txt\")\n# total_line = file.gets.to_i\ntotal_line = gets.to_i\n\nintervals = Array::new\nqueries = Array::new\n\ntotal_line.times do |i|\n # input = file.gets.split.map(&:to_i)\n input = gets.split.map(&:to_i)\n if input.shift == 1\n input << false\n intervals[i] = input\n else\n check = answer(intervals, input)\n if check == true\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\nend\n"}, {"source_code": "\ndef compute_reachability arr, index\n (1..index).each do |i|\n (1..index).each do |j|\n if (arr[i][j] == nil) && arr[i][index] == 1 && arr[index][j] == 1 \n arr[i][j] = 1\n end\n end\n end\nend\n\nn = gets.to_i\narr = Array.new(n + 1) {Array.new(n + 1)}\nintervals = []\n(1..n).each { |i| arr[i][i] = 0}\n(1..n).each do |index|\n command, x, y = gets.split(' ').map(&:to_i)\n if command == 1\n intervals.each_with_index do |interval, i|\n if (x < interval[1] && x > interval[0]) || (y < interval[1] && y > interval[0])\n arr[index][i +1] = 1\n end\n if (interval[0] < y && interval[0] > x) || ( interval[1] < y && interval[1] > x)\n arr[i +1][index] = 1\n end \n end\n compute_reachability(arr, index)\n intervals << [x,y]\n else\n puts arr[x][y]== 1 ? \"YES\" : \"NO\"\n end\n\nend\n"}], "src_uid": "c686c3592542b70a3b617eb639c0e3f4"} {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n s = gets.chomp.split(\"\").map(&:to_i)\n one_fin = 0\n zero_fin = 0\n index = 0\n arr = Array.new(n)\n max = 0\n n.times do |i|\n if s[i] == 1\n if zero_fin > 0\n one_fin += 1\n zero_fin -= 1\n index += 1\n arr[i] = index\n else\n one_fin += 1\n arr[i] = one_fin\n index += 1\n max = one_fin if max < one_fin\n end\n elsif s[i] == 0\n if one_fin > 0\n zero_fin += 1\n one_fin -= 1\n arr[i] = index\n index -= 1\n else\n zero_fin += 1\n arr[i] = zero_fin\n max = zero_fin if max < zero_fin\n end\n end\n end\n ans << [arr,max]\nend\nans.each do |ar|\n puts ar[1]\n ar[0].each do |x|\n print \"#{x} \"\n end\n puts \"\"\nend", "positive_code": [{"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n s = gets.chomp.split(\"\")\n one_fin = 0\n zero_fin = 0\n index = 0\n arr = Array.new(n)\n max = 0\n n.times do |i|\n if s[i] == \"1\"\n if zero_fin > 0\n one_fin += 1\n zero_fin -= 1\n index += 1\n arr[i] = index\n else\n one_fin += 1\n arr[i] = one_fin\n index += 1\n max = one_fin if max < one_fin\n end\n elsif s[i] == \"0\"\n if one_fin > 0\n zero_fin += 1\n one_fin -= 1\n arr[i] = index\n index -= 1\n else\n zero_fin += 1\n arr[i] = zero_fin\n max = zero_fin if max < zero_fin\n end\n end\n end\n ans << [arr,max]\nend\nans.each do |ar|\n puts ar[1]\n ar[0].each do |x|\n print \"#{x} \"\n end\n puts \"\"\nend"}], "negative_code": [{"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n s = gets.chomp\n one_fin = 0\n zero_fin = 0\n index = 0\n arr = []\n n.times do |i|\n if s[i] == \"0\" && one_fin > 0\n zero_fin += 1\n one_fin -= 1\n arr << index\n index -= 1\n elsif s[i] == \"0\" && one_fin > 0\n zero_fin += 1\n arr << zero_fin\n elsif s[i] == \"0\" && zero_fin > 0\n one_fin += 1\n zero_fin -= 1\n index += 1\n arr << index\n else\n one_fin += 1\n arr << one_fin\n index += 1\n end\n end\n ans << arr\nend\nans.each do |ar|\n puts ar.max\n ar.each do |x|\n print \"#{x} \"\n end\n puts \"\"\nend"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n s = gets.chomp\n one_i = 1\n zero_i = 1\n arr = []\n n.times do |i|\n if s[i] == \"0\"\n if zero_i < one_i\n one_i -= 1\n arr << one_i\n else\n arr << zero_i\n zero_i += 1\n end\n elsif s[i] == \"1\"\n if zero_i > one_i\n zero_i -= 1\n arr << zero_i\n else\n arr << one_i\n one_i += 1\n end\n end\n end\n ans << arr\nend\nans.each do |ar|\n puts ar.max\n ar.each do |x|\n print \"#{x} \"\n end\n puts \"\"\nend"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n s = gets.chomp\n one_i = 1\n zero_i = 1\n arr = []\n n.times do |i|\n if s[i] == \"0\"\n if zero_i < one_i\n one_i -= 1\n arr << one_i\n else\n arr << zero_i\n zero_i += 1\n end\n elsif s[i] == \"1\"\n if zero_i > one_i\n zero_i -= 1\n arr << zero_i\n else\n arr << one_i\n one_i += 1\n end\n end\n end\n ans << arr\nend\nans.each do |ar|\n ar.each do |x|\n print \"#{x} \"\n end\n puts \"\"\nend"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n s = gets.chomp\n one_fin = 0\n zero_fin = 0\n arr = []\n n.times do |i|\n if s[i] == \"0\"\n if one_fin > 0\n zero_fin += 1\n arr << zero_fin\n one_fin -= 1\n else\n zero_fin += 1\n arr << zero_fin\n end\n elsif s[i] == \"1\"\n if zero_fin > 0\n one_fin += 1\n arr << one_fin\n zero_fin -= 1\n else\n one_fin += 1\n arr << one_fin\n end\n end\n end\n ans << arr\nend\nans.each do |ar|\n puts ar.max\n ar.each do |x|\n print \"#{x} \"\n end\n puts \"\"\nend"}], "src_uid": "de57b6b1aa2b6ec4686d1348988c0c63"} {"source_code": "a = gets.split(',').map(&:to_i).sort\nb = []\ns = t = a[0]\na.each do |i|\n\tif i <= t + 1 then\n\t\tt = i\n\telse\n\t\tb << [s, t]\n\t\ts = t = i\n\tend\nend\nb << [s, t]\nputs b.map{|a, b| a == b ? a : \"#{a}-#{b}\"} * ','\n\n__END__\n\n", "positive_code": [{"source_code": "s = gets.split(\",\")\ns = s.collect {|i| i = i.to_i}\ns = s.sort\ns = s.uniq\ni = s.size-1\nwhile i>0 do\n k = s[i].to_i\n if k == s[i-1] + 1 then \n if t = s[i].to_s.index(\"-\") then s[i] = s[i][t+1...s[i].size].to_i\n end\n s[i-1] = s[i-1].to_s + \"-\" + s[i].to_s \n s.delete_at(i)\n end\n i -= 1\nend\nstr = s.join(\",\")\nprint \"#{str}\\n\""}, {"source_code": "sa = gets.chomp.split(/,/)\nsa.map!{|x| x.to_i}\nsa.uniq!\nsa.sort!\n\nret = \"\"\nst = 0\nprev = 0\nfor i in 0..sa.length-1\n\tif st == 0\n\t\tret += sa[i].to_s \n\t\tst = sa[i]\n\t\tprev = st\n\telse\n\t\tif sa[i] == prev+1\n\t\t\tprev = sa[i]\n\t\telse\n\t\t\tif st == prev\n\t\t\t\tret += \",\" + sa[i].to_s\n\t\t\telse\n\t\t\t\tret += \"-\" + prev.to_s + \",\" + sa[i].to_s\n\t\t\tend\n\t\t\tst = sa[i]\n\t\t\tprev = st\n\t\tend\n\tend\t\nend\n\nif st != prev\n\tret += \"-\" + prev.to_s\nend\n\nputs ret"}, {"source_code": "pages = gets.strip.split(\",\").map{|s| s.to_i}\ninc = [false] * 2000\npages.each {|n| inc[n] = true}\n\ni = 1\nwas = false\nwhile i <= 1000\n unless inc[i]\n i += 1\n next\n end\n print \",\" if was\n j = i+1\n j += 1 while inc[j]\n print i\n print \"-\",j-1 if j > i+1\n was = true\n i = j \nend\n"}, {"source_code": "pages = gets.strip.split(\",\").map{|s| s.to_i}\ninc = [false] * 2000\npages.each {|n| inc[n] = true}\n\ni = 1\nres = []\nwhile i <= 1000\n unless inc[i]\n i += 1\n next\n end\n j = i+1\n j += 1 while inc[j]\n if j == i+1\n res << i\n else\n res << [i, \"-\", j-1].join(\"\")\n end\n i = j \nend\n\nputs res.join(\",\")\n"}, {"source_code": "#!usr/bin/env ruby\nx=gets()\narray=x.split(',')\n#puts(array)\narray2=Array.new()\narray.each do\n |a|\n a=a.to_i\n #puts(a)\n array2 << a\nend\narray2.sort!\narray2 = array2 & array2\n#puts(array2)\nprev = -1\nres = \"\"\nlast=0\nfor x in array2 do\n if x-prev != 1 then\n if prev !=-1 && last != prev then\n res << \"-\" << prev.to_s\n last = prev\n end\n if res == \"\" then\n res << x.to_s\n last = x\n else\n res << \",\"\n res << x.to_s\n last = x\n end\n end\n prev = x\n end\n if last != prev then\n res << \"-\" << prev.to_s\n end\nputs (res)\n"}], "negative_code": [{"source_code": "#!usr/bin/env ruby\nx=gets()\narray=x.split(',')\n#puts(array)\narray2=Array.new()\narray.each do\n |a|\n a=a.to_i\n #puts(a)\n array2 << a\nend\narray2.sort!\narray2 = array2 & array2\n#puts(array2)\nprev = -1\nres = \"\"\nlast=0\nfor x in array2 do\n if x-prev != 1 then\n if prev !=-1 then\n res << \"-\" << prev.to_s\n last = prev\n end\n if res == \"\" then\n res << x.to_s\n last = x\n else\n res << \",\"\n res << x.to_s\n last = x\n end\n end\n prev = x\n end\n if last != prev then\n res << \"-\" << prev.to_s\n end\nputs (res)\n"}], "src_uid": "3969ba3e3eb55a896663d2c5a5bc4a84"} {"source_code": "n = STDIN.readline.to_i\ncups = []\nn.times {|ix| cups.push([STDIN.readline.to_i, ix]) }\ncount = Hash.new(0)\ncups.each {|volume, ix| count[volume] += 1 }\nif count.keys.count == 1\n puts 'Exemplary pages.'\n exit\nend\n\ndef fail\n puts 'Unrecoverable configuration.'\n exit\nend\n\ncups.sort!\ndelta = cups[-1][0] - cups[0][0]\nfail if delta % 2 == 1\npour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1\n\ncups[0][0] += pour\ncups[-1][0] -= pour\ncount = Hash.new(0)\ncups.each {|volume, ix| count[volume] += 1 }\nfail if count.keys.count != 1\n\nputs '%d ml. from cup #%d to cup #%d.' % [pour, source, target]\n", "positive_code": [{"source_code": "n = gets.to_i\na = n.times.map{gets.to_i}\ns = a.inject &:+\nk = a.find_all{|_| _ != s / n}.map{|_| a.index _}\nif s % n != 0 || (!k.empty? && k.size != 2)\n\tputs 'Unrecoverable configuration.'\nelsif k.empty?\n\tputs 'Exemplary pages.'\nelse\n\ti, j = *k\n\ti, j = j, i if a[i] < a[j]\n\tputs \"#{(a[i] - a[j]) / 2} ml. from cup ##{j + 1} to cup ##{i + 1}.\"\nend\n"}, {"source_code": "n=gets.to_i\na=[]\nn.times{\n a.push(gets.to_i)\n}\nok=1\n(n-1).times{|i|\n if a[i]!=a[i+1] then\n ok=0\n break\n end\n}\nif ok==1 then\n puts \"Exemplary pages.\"\n exit\nend\ncnt={}\ncnt.default=0\na.each{|i|\n cnt[i]+=1\n}\nif cnt.length<5 then\n n.times{|i|\n if cnt[a[i]]==1 then\n n.times{|j|\n if cnt[a[j]]==1 then\n if a[i]>a[j] then\n v=a[i]-a[j]\n v/=2\n a[i]-=v\n a[j]+=v\n ok=1\n (n-1).times{|i|\n if a[i]!=a[i+1] then \n ok=0\n break\n end\n }\n if ok==1 then\n printf \"%d ml. from cup #%d to cup #%d.\\n\",v,j+1,i+1\n exit\n end\n a[i]+=v\n a[j]-=v;\n end\n end\n }\n end \n }\nend\nputs \"Unrecoverable configuration.\"\n"}, {"source_code": "def check(a, b, n)\n\tdiff = b[0]-a[0]\n\tif diff.odd? || (a[0]+b[0])/2 != n\n\t\tputs \"Unrecoverable configuration.\"\n\t\texit\n\tend\n\tputs \"#{(diff)/2} ml. from cup ##{a[1]} to cup ##{b[1]}.\"\n\texit\nend\n\nn = gets.to_i\narr = Array.new(n) { |idx| [gets.to_i, idx+1] }.sort.freeze\n\nif arr[0][0] == arr[-1][0]\n\tputs \"Exemplary pages.\"\n\texit\nend\n\nif arr.size == 2\n\tdiff = arr[1][0]-arr[0][0]\n\tif diff.odd?\n\t\tputs \"Unrecoverable configuration.\"\n\t\texit\n\tend\n\tcheck(arr[0], arr[1], (arr[0][0]+arr[1][0])/2)\nend\n\nif arr[1][0] != arr[-2][0]\n\tputs \"Unrecoverable configuration.\"\n\texit\nend\n\ncheck(arr[0], arr[-1], arr[1][0])\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nls = $stdin.readlines.map(&:chomp)\nn = ls[0].to_i\nvs = ls.drop(1).map(&:to_i)\n\ns = vs.inject(0, &:+)\nif s % n != 0\n puts 'Unrecoverable configuration.'\n exit 0\nend\nave = s / n\n\na = []\nvs.each_with_index do |v, i|\n if v != ave\n a << [v, i]\n end\nend\nif a.empty?\n puts 'Exemplary pages.'\nelsif a.size == 2 and a[0][0] + a[1][0] == ave * 2\n x, y = a.sort\n puts \"#{ave - x[0]} ml. from cup ##{x[1]+1} to cup ##{y[1]+1}.\"\nelse\n puts 'Unrecoverable configuration.'\nend\n"}, {"source_code": "n = gets.to_i\narr = []\nn.times do\n\tarr << gets.to_i\nend\n# arr.sort!\nsorted = arr.sort\nnormal = sorted[1]\nchunk = sorted.chunk{|x| x}\n# puts \"#{chunk.count}\"\nans = false\nif chunk.count == 1\n\tputs \"Exemplary pages.\"\n\tans = true\nelsif chunk.count == 2 || chunk.count == 3\n\tmin,min_ind,max,max_ind = arr.each_with_index.minmax.flatten\n\t# puts \"min #{min} ind #{min_ind} #{max} #{max_ind}\" if n == 198\n\t# puts \"#{arr.count(min) == 1 && arr.count(max) == 1}\"\n\n\tel = (min + max) / 2\n\tml = max - el\n\n\tif (arr.count(min) == 1) && (arr.count(max) == 1) && (el-min == ml)\n\t\tif !(chunk.count == 3 && el != normal)\n\t\t\tans = true\n\t\t\tputs \"#{ml} ml. from cup ##{min_ind+1} to cup ##{max_ind+1}.\"\n\t\tend\n\tend\nend\n\nputs \"Unrecoverable configuration.\" unless ans"}], "negative_code": [{"source_code": "n = STDIN.readline.to_i\ncups = []\nn.times {|ix| cups.push([STDIN.readline.to_i, ix]) }\ncount = Hash.new(0)\ncups.each {|volume, ix| count[volume] += 1 }\nkey_num = count.keys.count\nif key_num == 1\n puts 'Exemplary pages.'\n exit\nend\ndef fail\n puts 'Unrecoverable configuration.'\n exit\nend\nfail if key_num != 2 + (n > 2 ? 1 : 0)\ncups.sort!\nfail if n > 3 and cups[1][0] != cups[-2][0]\ndelta = cups[-1][0] - cups[0][0]\nfail if delta % 2 == 1\npour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1\nputs '%d ml. from cup #%d to cup #%d.' % [pour, source, target]\n"}, {"source_code": "n = STDIN.readline.to_i\ncups = []\nn.times {|ix| cups.push([STDIN.readline.to_i, ix]) }\ncount = Hash.new(0)\ncups.each {|volume, ix| count[volume] += 1 }\nkey_num = count.keys.count\nif key_num == 1\n puts 'Exemplary pages.'\n exit\nend\ndef fail\n puts 'Unrecoverable configuration.'\n exit\nend\nfail if key_num != 2 + (n > 2 ? 1 : 0)\nfail if n > 3 and cups[1] != cups[-2]\ncups.sort!\ndelta = cups[-1][0] - cups[0][0]\nfail if delta % 2 == 1\npour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1\nputs '%d ml. from cup #%d to cup #%d.' % [pour, source, target]\n"}, {"source_code": "n = STDIN.readline.to_i\ncups = []\nn.times {|ix| cups.push([STDIN.readline.to_i, ix]) }\ncount = Hash.new(0)\ncups.each {|volume, ix| count[volume] += 1 }\nkey_num = count.keys.count\nif key_num == 1\n puts 'Exemplary pages.'\n exit\nend\ndef fail\n puts 'Unrecoverable configuration.'\n exit\nend\nfail if key_num > 3 or n > 2 and key_num == 2\ncups.sort!\ndelta = cups[-1][0] - cups[0][0]\nfail if delta % 2 == 1\npour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1\nputs '%d ml. from cup #%d to cup #%d.' % [pour, source, target]\n"}, {"source_code": "n = STDIN.readline.to_i\ncups = []\nn.times {|ix| cups.push([STDIN.readline.to_i, ix]) }\ncount = Hash.new(0)\ncups.each {|volume, ix| count[volume] += 1 }\nkey_num = count.keys.count\nif key_num == 1\n puts 'Exemplary pages.'\n exit\nend\ndef fail\n puts 'Unrecoverable configuration.'\n exit\nend\nfail if key_num > 3\ncups.sort!\ndelta = cups[-1][0] - cups[0][0]\nfail if delta % 2 == 1\npour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1\nputs '%d ml. from cup #%d to cup #%d.' % [pour, source, target]\n"}, {"source_code": "n = STDIN.readline.to_i\ncups = []\nn.times {|ix| cups.push([STDIN.readline.to_i, ix]) }\ncount = Hash.new(0)\ncups.each {|volume, ix| count[volume] += 1 }\nkey_num = count.keys.count\nif key_num == 1\n puts 'Exemplary pages.'\n exit\nend\ndef fail\n puts 'Unrecoverable configuration.'\n exit\nend\nfail if key_num > 3\ncups.sort!\ndelta = cups[-1][0] - cups[0][0]\nfail if delta % 2 == 1\npour, source, target = delta/2, cups[-1][1]+1, cups[0][1]+1\nputs '%d ml. from cup #%d to cup #%d.' % [pour, source, target]\n"}, {"source_code": "n = STDIN.readline.to_i\ncups = []\nn.times {|ix| cups.push([STDIN.readline.to_i, ix]) }\ncount = Hash.new(0)\ncups.each {|volume, ix| count[volume] += 1 }\nkey_num = count.keys.count\nif key_num == 1\n puts 'Exemplary pages.'\n exit\nend\ndef fail\n puts 'Unrecoverable configuration.'\n exit\nend\nfail if key_num > 3 or (n > 2 and key_num == 2)\ncups.sort!\ndelta = cups[-1][0] - cups[0][0]\nfail if delta % 2 == 1\npour, source, target = delta/2, cups[0][1]+1, cups[-1][1]+1\nputs '%d ml. from cup #%d to cup #%d.' % [pour, source, target]\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nls = $stdin.readlines.map(&:chomp)\nn = ls[0].to_i\nvs = ls.drop(1).map(&:to_i)\n\ns = vs.inject(0, &:+)\nif s % n != 0\n puts 'Unrecoverable configuration.'\n exit 0\nend\n\na = []\nvs.each_with_index do |v, i|\n if v != s / n\n a << [v, i]\n end\nend\nif a.empty?\n puts 'Exemplary pages.'\nelsif a.size == 2 and a[0][0] + a[1][0] == s / n * 2\n x, y = a.sort\n puts \"#{s/n - x[0]} ml. from cup ##{x[1]+1} to cup ##{y[1]+1}.\"\nelse\n puts 'Unrecoverable configuration'\nend\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nls = $stdin.readlines.map(&:chomp)\nn = ls[0].to_i\nvs = ls.drop(1).map(&:to_i)\n\ns = vs.inject(0, &:+)\nif s % n != 0\n puts 'Unrecoverable configuration.'\n exit 0\nend\n\na = []\nvs.each_with_index do |v, i|\n if v != s / n\n a << [v, i]\n end\nend\nif a.empty?\n puts 'Exemplay pages.'\nelsif a.size == 2 and a[0][0] + a[1][0] == s / n * 2\n x, y = a.sort\n puts \"#{s/n - x[0]} ml. from cup ##{x[1]+1} to cup ##{y[1]+1}.\"\nelse\n puts 'Unrecoverable configuration'\nend\n"}, {"source_code": "n = gets.to_i\narr = []\nn.times do\n\tarr << gets.to_i\nend\n# arr.sort!\nchunk = arr.sort.chunk{|x| x}\n# puts \"#{chunk.count}\"\nif chunk.count == 1\n\tputs \"Exemplary pages.\"\nelsif chunk.count == 2 || chunk.count == 3\n\tmin,min_ind,max,max_ind = arr.each_with_index.minmax.flatten\n\t# puts \"min #{min} ind #{min_ind} #{max} #{max_ind}\" if n == 198\n\t# puts \"#{arr.count(min) == 1 && arr.count(max) == 1}\"\n\n\tel = (min + max) / 2\n\tml = max - el\n\n\tif (arr.count(min) == 1) && (arr.count(max) == 1) && el == arr.sort[1] && (el-min == ml)\n\n\t\tputs \"#{ml} ml. from cup ##{min_ind+1} to cup ##{max_ind+1}.\"\n\telse\n\t\tputs \"Unrecoverable configuration.\"\n\tend\nelse\n\tputs \"Unrecoverable configuration.\"\nend"}, {"source_code": "n = gets.to_i\narr = []\nn.times do\n\tarr << gets.to_i\nend\n# arr.sort!\nchunk = arr.sort.chunk{|x| x}\n# puts \"#{chunk.count}\"\nif chunk.count == 1\n\tputs \"Exemplary pages.\"\nelsif chunk.count == 3\n\tmin,min_ind,max,max_ind = arr.each_with_index.minmax.flatten\n\t# puts \"min #{min} ind #{min_ind} #{max} #{max_ind}\"\n\t# puts \"#{arr.count(min) == 1 && arr.count(max) == 1}\"\n\tif (arr.count(min) == 1) && (arr.count(max) == 1)\n\n\t\tel = (min + max) / 2\n\t\tml = max - el\n\n\t\tputs \"#{ml} ml. from cup ##{min_ind+1} to cup ##{max_ind+1}.\"\n\telse\n\t\tputs \"Unrecoverable configuration.\"\n\tend\nelse\n\tputs \"Unrecoverable configuration.\"\nend"}, {"source_code": "n = gets.to_i\narr = []\nn.times do\n\tarr << gets.to_i\nend\n# arr.sort!\nchunk = arr.sort.chunk{|x| x}\n# puts \"#{chunk.count}\"\nif chunk.count == 1\n\tputs \"Exemplary pages.\"\nelsif chunk.count == 2 || chunk.count == 3\n\tmin,min_ind,max,max_ind = arr.each_with_index.minmax.flatten\n\t# puts \"min #{min} ind #{min_ind} #{max} #{max_ind}\"\n\t# puts \"#{arr.count(min) == 1 && arr.count(max) == 1}\"\n\n\tel = (min + max) / 2\n\tml = max - el\n\tif (arr.count(min) == 1) && (arr.count(max) == 1) && (el-min == ml)\n\n\t\tputs \"#{ml} ml. from cup ##{min_ind+1} to cup ##{max_ind+1}.\"\n\telse\n\t\tputs \"Unrecoverable configuration.\"\n\tend\nelse\n\tputs \"Unrecoverable configuration.\"\nend"}, {"source_code": "n = gets.to_i\narr = []\nn.times do\n\tarr << gets.to_i\nend\n# arr.sort!\nchunk = arr.sort.chunk{|x| x}\n# puts \"#{chunk.count}\"\nif chunk.count == 1\n\tputs \"Exemplary pages.\"\nelsif chunk.count == 2 || chunk.count == 3\n\tmin,min_ind,max,max_ind = arr.each_with_index.minmax.flatten\n\tputs \"min #{min} ind #{min_ind} #{max} #{max_ind}\" if n == 198\n\t# puts \"#{arr.count(min) == 1 && arr.count(max) == 1}\"\n\n\tel = (min + max) / 2\n\tml = max - el\n\n\tif (arr.count(min) == 1) && (arr.count(max) == 1) && (el-min == ml)\n\n\t\tputs \"#{ml} ml. from cup ##{min_ind+1} to cup ##{max_ind+1}.\"\n\telse\n\t\tputs \"Unrecoverable configuration.\"\n\tend\nelse\n\tputs \"Unrecoverable configuration.\"\nend"}], "src_uid": "7bfc0927ea7abcef661263e978612cc5"} {"source_code": "size = gets.to_i\ndone = true\ni=1\ntableau_de_somme = []\ntableau_final = []\ntableau_final[0] = \"!\"\n\nwhile done do\n\tputs \"?\"+ \" \" + i.to_s + \" \" + (i+=1).to_s\n\t$stdout.flush\n\ttableau_de_somme << gets.to_i\n\tdone = false if i == size\nend\n\nresultat = []\nresultat[0] = 0\na = 0\n\nwhile a < (size-2) do\n\tresultat[0] += tableau_de_somme[a]\n\tresultat[0] -= tableau_de_somme[a += 1]\n\ta += 1\nend\t\n\nif size.modulo(2) == 0\n\tputs \"?\"+ \" \" + 1.to_s + \" \" + (size-1).to_s\n\t$stdout.flush\n\ttableau_de_somme << gets.to_i\nelse \n\tputs \"?\"+ \" \" + 1.to_s + \" \" + (size).to_s\n\t$stdout.flush\n\ttableau_de_somme << gets.to_i\nend\n\nresultat[0] += tableau_de_somme[size-1] \nresultat[0] /= 2\ntableau_final << resultat[0]\n\ntableau_de_somme.each do |val|\n\ttableau_final << val - tableau_final.last\nend\t\n\ntableau_final.pop\n\ntableau_final.each do |val|\n\tprint val.to_s + \" \"\n\t$stdout.flush\nend\t", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\nsize = gets.to_i\nresolu = true\ni=1\ntableau_de_somme = []\ntableau_final = []\ntableau_final[0] = \"!\"\n\nwhile resolu do\n\tputs \"?\"+ \" \" + i.to_s + \" \" + (i+=1).to_s\n\t$stdout.flush\n\ttableau_de_somme << gets.to_i\n\tresolu = false if i == size\nend\nresultat = []\nresultat[0] =0\niterator=0\nwhile iterator < (size-2) do\n\tresultat[0] += tableau_de_somme[iterator]\n\tresultat[0] -= tableau_de_somme[iterator+=1]\n\titerator+=1\nend\t\nif size.modulo(2) == 0\n\tputs \"?\"+ \" \" + 1.to_s + \" \" + (size-1).to_s\n\t$stdout.flush\n\ttableau_de_somme << gets.to_i\nelse \n\tputs \"?\"+ \" \" + 1.to_s + \" \" + (size).to_s\n\t$stdout.flush\n\ttableau_de_somme << gets.to_i\nend\nresultat[0] += tableau_de_somme[size-1] \nresultat[0] /= 2\ntableau_final << resultat[0]\n\ntableau_de_somme.each do |val|\n\ttableau_final << val - tableau_final.last\nend\t\ntableau_final.pop\ntableau_final.each do |val|\n\tprint val.to_s + \" \"\n\t$stdout.flush\nend\t"}], "negative_code": [{"source_code": "size = gets.to_i\nresolu = true\nindice=0\ni=1\nputs indice\ntableau_de_somme = []\ntableau_final = []\ntableau_final[0] = \"!\"\n\nwhile resolu do\n $stdout.print \"?\"+ \" \" + i.to_s + \" \" + (i+=1).to_s\n $stdout.flush\n tableau_de_somme << gets.to_i\n resolu = false if i == size\nend\nresultat = []\nresultat[0] =0\niterator=0\nwhile iterator < (size-2) do\n resultat[0] += tableau_de_somme[iterator]\n resultat[0] -= tableau_de_somme[iterator+=1]\n iterator+=1\nend \nif size.modulo(2) == 0\n $stdout.print \"?\"+ \" \" + 1.to_s + \" \" + (size-1).to_s\n $stdout.flush\n tableau_de_somme << gets.to_i\nelse \n $stdout.print \"?\"+ \" \" + 1.to_s + \" \" + (size).to_s\n $stdout.flush\n tableau_de_somme << gets.to_i\nend\nresultat[0] += tableau_de_somme[size-1] \nresultat[0] /= 2\ntableau_final << resultat[0]\n\ntableau_de_somme.each do |val|\n tableau_final << val - tableau_final.last\nend \ntableau_final.pop\ntableau_final.each do |val|\n print val.to_s + \" \"\nend "}], "src_uid": "1898e591b40670173e4c33e08ade48ba"} {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nMIN, MAX = a.minmax\nif MIN <= k+1\n puts MIN\n exit\nend\n\nb = Array.new(MAX+1, 0)\na.each { |e| b[e] += 1 }\nb.each_index do |i|\n b[i] += b[i-1] if i != 0\nend\n\nans = MIN\nloop do\n l = ans + k\n r = 2*ans - 1\n flag = true\n\n loop do\n if r > MAX\n if l >= MAX\n break flag = true\n else\n if b[l] < b[MAX]\n break flag = false\n else\n break flag = true\n end\n end\n elsif b[l] < b[r]\n break flag = false\n end\n l += ans\n r += ans\n end\n\n break if flag\n ans -= 1\nend\nputs ans\n\n", "positive_code": [{"source_code": "gets.scan(/(\\d+) (\\d+)/)\nn=$1.to_i\nk=$2.to_i\na=gets.scan(/\\d+/).map {|s| s.to_i}.uniq.sort\nl=Array.new(a.max+1, -1)\ni=0\n0.upto(a.max) {|j|\n if i=a.first\n if j%divisor>k || j==a.first && j=a.first\n if j%divisor>k\n existAns=false\n break\n end\n j=l[j-j%divisor]\n end\n if existAns\n p divisor\n exit\n end\n}\np 1"}, {"source_code": "n, k = gets.split(' ').map {|x| x.to_i}\na = gets.split(' ').map {|x| x.to_i}.sort\nminv, maxv = a.minmax\n\ncnt = (Array.new maxv + 5).fill(0)\na.each {|x| cnt[x] += 1}\ncnt.each_index {|i| cnt[i] += cnt[i - 1] if (i > 0)}\ncnt[-1] = 0 # guard\n\n(puts minv; exit) if (minv <= k + 1)\n\nans = minv\nloop do\n\tl, r = k, ans - 1\n\tflag = 1\n\twhile (l <= maxv) do\n\t\tr = maxv if (r > maxv)\n\t\t(flag = 0; break) if (cnt[r] > cnt[l])\n\t\tl += ans\n\t\tr += ans\n\tend\n\tbreak if (flag == 1)\n\tans -= 1\nend\nputs ans\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nMIN, MAX = a.minmax\nif MIN <= k+1\n puts MIN\n exit\nend\n\nb = Array.new(MAX+1, 0)\na.each { |e| b[e] += 1 }\nb.each_index do |i|\n b[i] += b[i-1] if i != 0\nend\n\nans = MIN\nloop do\n l = ans + k\n r = 2*ans - 1\n flag = true\n\n while r < MAX\n if b[l] < b[r]\n break flag = false\n end\n l += ans\n r += ans\n end\n\n break if flag && l >= MAX\n ans -= 1\nend\n\nputs ans\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = a.min\n\nloop do\n flag = true\n a.each do |e|\n while e % ans > k\n ans -= 1\n flag = false\n end\n end\n break if flag\nend\nputs ans\n\n"}], "negative_code": [{"source_code": "gets.scan(/(\\d+) (\\d+)/)\nn=$1.to_i\nk=$2.to_i\na=gets.scan(/\\d+/).map {|s| s.to_i}.uniq.sort\n\np (1..a.first).to_a.delete_if {|divisor| a.reject!{|x|x%divisor>k || x==a.first && x=a.first\n if j%divisor>k || j==a.first && j0 do \n ans_arr << arr[last_index]\n last_index-=1 \n k-=1 \n end \nend \n\n(n-k_copy).times do |i| \n ans_arr << arr[i] \nend \n\nputs ans_arr.join(\" \")"}, {"source_code": "class A\n def initialize\n n, k = $stdin.gets.split(' ').map(&:to_i)\n\n list = (1..n).to_a\n\n flag = true\n\n ans = Array.new(n,nil)\n\n if k > 0\n index = -1\n k.times do\n ans[index] = list.shift\n index -= 1\n end\n\n index = 0\n (n-k).times do\n ans[index] = list.shift\n index += 1\n end\n else\n ans = list\n end\n\n puts ans.join(' ')\n end\nend\n\na = A.new"}, {"source_code": "a=gets.chomp.split(\" \")\nn=a[0].to_i\nk=a[1].to_i\nk.times do\nprintf \"#{n} \"\nn-=1\nend\n\n1.upto(n) do |i|\nprintf \"#{i} \"\nend"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn, k = gets.split.map(&:to_i)\n\n((k+1)..n).each do |index|\n print index,\" \"\nend\nk.downto(1) do |index|\n print index,\" \"\nend"}, {"source_code": "n,k = gets.split.map &:to_i\nto = n-k\nfor i in (1..to-1)\n print \"#{i} \" \nend\nfor i in (to+1..n) \n print \"#{n-i+to+1} \" \nend \nprint to"}, {"source_code": "(n, k) = gets.chomp.split(' ').map(&:to_i)\na = Array.new(n)\n(1..n).each do |i|\n a[i-1] = (i<=k) ? (n-i+1) : (i-k)\nend\nputs a.join(' ')"}, {"source_code": "require 'scanf'\n(n, k) = scanf(\"%d%d\")\n# (n, k) = gets.chomp.split(' ').map(&:to_i)\na = Array.new(n)\n(1..n).each do |i|\n a[i-1] = (i<=k) ? (n-i+1) : (i-k)\nend\nputs a.join(' ')\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=[]\nn.downto(1){|x|a<=n-k\n print i.to_s+\" \"\n i-=1\n end\n puts \"\""}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs ((1...(n - k)).to_a + n.downto(n - k).to_a).join(' ')\n"}, {"source_code": "a=gets.chomp.split(\" \")\nn=a[0].to_i\nk=a[1].to_i\nk.times do\nprintf \"#{n} \"\nn-=1\nend\n\n1.upto(n) do |i|\nprintf \"#{i} \"\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\n(1..k).each{|i| print n-i+1, ' '}\n(1..(n-k)).each{|i| print i, ' '}\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn, k = gets.split.collect{ |i| i.to_i }\n\nk.downto(0) { |i| print \"#{i+1} \" }\n(k+2).upto(n) { |i| print \"#{i} \" }\n"}, {"source_code": "n,k = gets.strip.split.map(&:to_i)\n\n(1..n)\nresult = (k+1).downto(1).to_a + (k+2..n).to_a\n\nputs result.join(' ')"}, {"source_code": "n, k = gets.split(' ').map(&:to_i)\nans = (0...k).map{|x| n-x} + (1..n-k).map{|x| x}\nputs ans.map(&:to_s).join(\" \")"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\nn, k = gets.chomp.split( \" \" ).map{ |e| e.to_i }\narray = (1 .. n).to_a\n\nans = array[0 .. k].reverse() + array[k + 1 .. n]\nputs ans.join \" \"\n\n\n\n"}, {"source_code": "st = gets.split\nn=st[0].to_i\nk=st[1].to_i\n\nel=n\n(k).times do\n print(el,\" \")\n el-=1\nend\n\nel=1\n(n-k).times do\n print(el,\" \")\n el+=1\nend\n\n"}, {"source_code": "n, k = gets.split.map { |i| i.to_i }\na = (1..n).to_a\na = a[0..-(k + 2)] + a[-(k + 1)..-1].reverse\n\na.each do |i|\n print i, ' '\nend\nputs\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\na = Array.new\n\nfor i in 0...k\n a << n-i\nend\n\nfor i in 1..n-k\n a << i\nend\n\nfor i in a\n print i, \" \"\nend"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\n\nprefix = (1..k+1).collect {|x| x }.reverse\nsuffix = (k+2..n).collect {|x| x }\n\nputs (prefix+suffix).join(' ')\n\n"}], "negative_code": [{"source_code": "# cook your code here\nn, k =gets.split(' ').map(&:to_i)\n\narr = Array(1..n)\narr.unshift(arr.pop(k))\nputs arr.join(' ')"}, {"source_code": "class A\n def initialize\n n, k = $stdin.gets.split(' ').map(&:to_i)\n\n list = (1..n).to_a\n\n flag = true\n\n ans = Array.new(n,nil)\n\n if k > 0\n index = -1\n k.times do\n ans[index] = list.shift\n index -= 1\n end\n\n index = 0\n (n-k).times do\n ans[index] = list.shift\n end\n else\n ans = list\n end\n\n puts ans.join(' ')\n end\nend\n\na = A.new"}, {"source_code": "a=gets.chomp.split(\" \")\nc=a[0].to_i\nb=a[1].to_i\ntrig=0\nans=[]\nloop do\nif ans.count(c%b)==0\nans << c%b\nelse\nbreak\nend\n\nc=c+c%b\nif c % b == 0\ntrig=1\nbreak\nend\n\nend\n\nif trig==1\nputs \"Yes\"\nelse \nputs \"No\"\nend\n\n\n"}, {"source_code": "p=gets.chomp.to_i\ndef MOD (n,p)\n\tif p>19\n\tpmin=(Math.log(1000000007,n)).ceil\n\tpc=p/pmin\n\tpl=p%pmin\n\treturn ((MOD((n**pmin % 1000000007),pc) * (n**pl) ) % 1000000007)\n\telse\n\treturn (n**p)%1000000007\n\tend\n\tend\n\t\n\tc=(MOD(3,3*p)- MOD(7,p))% 1000000007\n\tputs \"#{c}\""}], "src_uid": "75cc5b55c51217966cbdd639a68f0724"} {"source_code": "$stdout.sync = true\r\n\r\ndef query(x)\r\n puts \"? #{x}\"\r\n gets.chomp.to_i\r\nend\r\n\r\ndef solution(n)\r\n value = yield(1)\r\n l, r = 1, value + 1\r\n while r - l > 1 do\r\n mid = (l + r) / 2\r\n a, b = yield(mid - 1), yield(mid)\r\n delta = mid - l\r\n if a < b\r\n r = mid\r\n elsif b <= value - delta \r\n l, value = mid, b\r\n else\r\n r = mid\r\n end\r\n end\r\n return l\r\nend\r\n\r\ndef stress\r\n array = (20).times.map { |x| x + 1 }.shuffle\r\n index = solution(array.length) { |x| array[x - 1] } - 1\r\n puts(array.inspect)\r\n puts(index)\r\n if not ((index == 0 or array[index - 1] > array[index]) and (index == array.length - 1 or array[index + 1] > array[index]))\r\n puts(\"Fail!\")\r\n end\r\nend\r\n\r\ndef main\r\n n = gets.chomp.to_i\r\n puts(\"! #{solution(n) { |x| query(x) }}\")\r\nend\r\n\r\nmain\r\n", "positive_code": [{"source_code": "n=gets.to_i\r\narr=[nil]*(n+2)\r\nl=0\r\nr=n+1\r\nwhile r-l>3\r\n m0=l+(r-l)/3\r\n m1=r-(r-l)/3\r\n if !arr[m0]\r\n puts \"? #{m0}\"\r\n $stdout.flush\r\n v0=gets.to_i\r\n arr[m0]=v0\r\n else\r\n v0=arr[m0]\r\n end\r\n if !arr[m1]\r\n puts \"? #{m1}\"\r\n $stdout.flush\r\n v1=gets.to_i\r\n arr[m1]=v1\r\n else\r\n v1=arr[m1]\r\n end\r\n if v0>v1\r\n l=m0\r\n else\r\n r=m1\r\n end\r\nend\r\nm0=l+1\r\nm1=r-1\r\nif !arr[m0]\r\n puts \"? #{m0}\"\r\n $stdout.flush\r\n v0=gets.to_i\r\n arr[m0]=v0\r\nelse\r\n v0=arr[m0]\r\nend\r\nif !arr[m1]\r\n puts \"? #{m1}\"\r\n $stdout.flush\r\n v1=gets.to_i\r\n arr[m1]=v1\r\nelse\r\n v1=arr[m1]\r\nend\r\nif v0>v1\r\n puts \"! #{m1}\"\r\nelse\r\n puts \"! #{m0}\"\r\nend\r\n"}], "negative_code": [{"source_code": "$stdout.sync = true\r\n\r\ndef query(x)\r\n puts \"? #{x}\"\r\n gets.chomp.to_i\r\nend\r\n\r\nn = gets.chomp.to_i\r\nvalue = query(1)\r\nl, r = 1, value + 1\r\nwhile r - l > 1 do\r\n mid = (l + r) / 2\r\n mid_value = query(mid)\r\n delta = mid - l\r\n if mid_value <= value - delta \r\n l, value = mid, mid_value\r\n else\r\n r = mid\r\n end\r\nend\r\nputs \"! #{l}\"\r\n"}, {"source_code": "$stdout.sync = true\r\n\r\ndef query(x)\r\n puts \"? #{x}\"\r\n gets.chomp.to_i\r\nend\r\n\r\nn = gets.chomp.to_i\r\nvalue = query(1)\r\nl, r = 1, value + 1\r\nwhile r - l > 1 do\r\n mid = (l + r) / 2\r\n mid_value = query(mid)\r\n delta = mid - l\r\n if mid_value <= value - delta \r\n l = mid\r\n value = mid_value\r\n else\r\n r = mid\r\n end\r\nend\r\nputs \"! #{l}\"\r\n"}, {"source_code": "n=gets.to_i\r\nl=1\r\nr=n\r\nll=l\r\nrr=r\r\nputs \"? #{l}\"\r\n$stdout.flush\r\nlm=gets.to_i\r\nputs \"? #{r}\"\r\n$stdout.flush\r\nrm=gets.to_i\r\nwhile true\r\n m=(l+r)/2\r\n f=0\r\n if lm<=rm\r\n r=m\r\n f=0\r\n else\r\n l=m\r\n f=1\r\n end\r\n while r-l>1\r\n puts \"? #{m}\"\r\n $stdout.flush\r\n m=(l+r)/2\r\n if f==0\r\n rm=gets.to_i\r\n else\r\n lm=gets.to_i\r\n end\r\n if lm<=rm\r\n rr=r\r\n r=m\r\n f=0\r\n else\r\n ll=l\r\n l=m\r\n f=1\r\n end\r\n end\r\n puts \"? #{m}\"\r\n $stdout.flush\r\n mm=gets.to_i\r\n if lm>mm&&mm0 then w=s[i%2]-e[(i+1)%2]\n if w<=t0 then c+=w*p0 elsif w<=t0+t1 then c+=p0*t0+p1*(w-t0) else c+=p0*t0+p1*t1+p2*(w-t1-t0) end end\n}\nputs c"}, {"source_code": "n, p1, p2, p3, t1, t2 = gets.chomp.split.map(&:to_i)\nl, r = [], []\npower = 0\nn.times do |index|\n\tl[index % 2], r[index % 2] = gets.chomp.split.map(&:to_i)\n\tpower += (r[index % 2] - l[index % 2]) * p1\n\tif index > 0\n\t\tno_activity = l[index % 2] - r[(index + 1) % 2]\n\t\tif no_activity <= t1\n\t\t\tpower += no_activity * p1\n\t\telsif no_activity <= t1 + t2\n\t\t\tpower += t1 * p1 + (no_activity - t1) * p2\n\t\telse\n\t\t\tpower += t1 * p1 + t2 * p2 + (no_activity - t1 - t2) * p3\n\t\tend\n\tend\nend\n\nputs power"}, {"source_code": "n,a,b,c,d,e=gets.split.map &:to_i;c-=b;b-=a;e+=d;t,x=1e4,0;n.times{l,r=gets.split.map &:to_i;x,t,l=x+a*(r-l),r,l-t;x+=a*[l,0].max+b*[l-d,0].max+c*[l-e,0].max};puts x\n"}, {"source_code": "n,a,b,c,d,e=gets.split.map &:to_i;c-=b;b-=a;e+=d;t,x=1e4,0;n.times{l,r=gets.split.map &:to_i;x,t,l=x+a*(r-l),r,l-t;x+=a*[l,0].max+b*[l-d,0].max+c*[l-e,0].max};puts x"}, {"source_code": "n,a,b,c,d,e=gets.split.map &:to_i;c-=b;b-=a;e+=d;t,x=1e4,0;n.times{l,r=gets.split.map &:to_i;x,t,l=x+a*(r-l),r,l-t;x+=a*[l,0].max+b*[l-d,0].max+c*[l-e,0].max};puts x\n"}, {"source_code": "n,a,b,c,d,e=gets.split.map &:to_i;c-=b;b-=a;e+=d;t,x=1e4,0;n.times{l,r=gets.split.map &:to_i;x,t,l=x+a*(r-l),r,l-t;x+=a*[l,0].max+b*[l-d,0].max+c*[l-e,0].max};puts x\n"}, {"source_code": "n,a,b,c,d,e=gets.split.map &:to_i;c-=b;b-=a;e+=d;t,x=1e4,0;n.times{l,r=gets.split.map &:to_i;x,t,l=x+a*(r-l),r,l-t;x+=a*[l,0].max+b*[l-d,0].max+c*[l-e,0].max};puts x\n"}, {"source_code": "n, p1, p2, p3, t1, t2 = gets.split.map(&:to_i)\ns, t = 0, 0\nn.times do |i|\n\tl, r = gets.split.map(&:to_i)\n\tif i > 0\n\t\t[[p1, t1], [p2, t2], [p3, 1e9]].each do |pi, ti|\n\t\t\td = [ti, l - t].min\n\t\t\ts += d * pi\n\t\t\tt += d\n\t\tend\n\tend\n\ts += (r - l) * p1\n\tt = r\nend\np s\n"}, {"source_code": "input=gets.split.map(&:to_i)\nn=input[0]\np1=input[1]\np2=input[2]\np3=input[3]\nt1=input[4]\nt2=input[5]\n\nback=-1\nans=0\nn.times{|i|\n input=gets.split.map(&:to_i)\n if back==-1 then\n back=input[0]\n end\n ans+=(input[1]-input[0])*p1\n t=input[0]-back\n t1.times{\n if t==0 then\n break\n end\n t-=1\n ans+=p1\n }\n t2.times{\n if t==0 then\n break\n end\n t-=1\n ans+=p2\n }\n ans+=t*p3\n back=input[1]\n}\nputs ans"}], "negative_code": [{"source_code": "s,e,c=[],[],0\nn,p0,p1,p2,t0,t1=gets.chomp!.split(\" \").map{|elem|elem.to_i}\nn.times {|i|s[i%2],e[i%2]=gets.chomp!.split(\" \").map{|elem|elem.to_i}\n c+=(e[i%2]-s[i%2])*p0\n if i>0 then w=s[i%2]-e[(i+1)%2]\n if w<=t0 then c+=w*p0 elsif w<=t1 then c+=p0*t0+p1*(w-t0) else c+=p0*t0+p1*t1+p2*(w-t1-t0) end end}\nputs c"}], "src_uid": "7ed9265b56ef6244f95a7a663f7860dd"} {"source_code": "gets.to_i.times do\r\n n, x = gets.split.map(&:to_i)\r\n as = gets.split.map(&:to_i).sort\r\n sums = as.reduce([]) { |acc, x| acc << (acc.last || 0) + x }\r\n answer = sums.map.with_index do |sum, i|\r\n [0, (1 + (x - sum) / (i + 1))].max\r\n end.sum\r\n p answer\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do \n n, x= gets.chomp.split.map(&:to_i)\n a = gets.chomp.split.map(&:to_i).sort\n cum = 0\n ans = 0\n 0.upto(n-1) do |i|\n cum += a[i]\n ans += (x >= cum)?((x-cum)/(i+1)+1) : 0\n end\n puts ans\nend\n"}], "negative_code": [], "src_uid": "b65767c1ebfe72e08f58a9f9254eaa7b"} {"source_code": "s = gets.chomp\n\nmod = 10**9 + 7\nstr = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'\nans = 1\n\ns.split('').each do |c|\n (str.index(c) + 64).to_s(2).split('').each do |d|\n ans = ans * 3 % mod if d == '0'\n end\nend\n\nputs ans\n", "positive_code": [{"source_code": " def gao(ch)\n case ch\n when '0'..'9'\n return ch.ord - '0'.ord\n when 'A'..'Z'\n return ch.ord - 'A'.ord + 10\n when 'a'..'z'\n return ch.ord - 'a'.ord + 36\n when '-'\n return 62\n when '_'\n return 63\n end\nend\n\ndef cal(num)\n# puts num\n ret = 0\n 6.times do\n ret += 1 if (num % 2) == 0\n num >>= 1\n end\n# puts ret\n ret\nend\n\nstr = readline.strip\nsum = str.each_char.map{|num| gao(num)}.map{|num| cal(num)}.inject(0, :+)\nmod = 1000000007\nres = 1\nsum.times {res = (res * 3) % mod}\nputs res\n"}, {"source_code": "s = gets.chomp\nans = 1\npatterns = (\"0\"..\"9\").to_a + (\"A\"..\"Z\").to_a + (\"a\"..\"z\").to_a + [\"-\",\"_\"]\nsymbols = {} \npatterns.each_with_index do |s,i|\n symbols[s] = i\nend\n\nfor c in s.split(\"\") do\n val = symbols[c] \n 6.times do |i|\n if val&1 == 0 then \n ans = (ans*3)%1000000007\n end\n val >>= 1\n end\nend\n\nprint ans\n"}, {"source_code": "h = Hash[( ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a + ['-', '_'] ).map.with_index.to_a ]\ns = gets.chomp\ns_2 = s.chars.map{|x| h[x].to_s(2).ljust(6, '0')}.join\nn = s_2.count('0')\nputs (3 ** n) % (10**9 + 7)\n"}], "negative_code": [{"source_code": "h = Hash[( ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a + ['-', '_'] ).map.with_index.to_a ]\ns = gets.chomp\ns_2 = s.chars.inject(''){|s, x| s + h[x].to_s(2).ljust(6, '0')}\nn = s_2.count('0')\nputs ( (3 ** n) % (1e9 + 7) ).to_i\n"}], "src_uid": "1b336555c94d5d5198abe5426ff6fa7a"} {"source_code": "n = gets.to_i\na = []\n((n + 1) / 2).times.each{|i| a << i * 2 + 1}\n((n + 1) / 2).times do |i|\n x = (i + 1) * 2\n a << x if x <= n && (x - a.last).abs > 1\nend\n\na = [3, 1, 4, 2] if n == 4\nputs a.size\nputs a.join(\" \")\n", "positive_code": [{"source_code": "a=gets.chomp.to_i\nif a==1\nputs \"1\"\nputs \"1\"\nelsif a==2\nputs \"1\"\nputs \"1\"\nelsif a==3\nputs \"2\"\nputs \"1 3\"\nelse \nputs \"#{a}\"\nif a%2==1\nprintf \"#{a/2 + 1} \"\n0.upto(a/2 - 1) do |i|\nprintf \"#{i+1} #{a-i} \"\nend\nelse\nprintf \"#{a/2 + 1} \"\n0.upto(a/2 - 2) do |i|\nprintf \"#{i+1} #{a-i} \"\nend\nprintf \"#{a/2}\"\nend\nend\n"}, {"source_code": "a=gets.chomp.to_i\nif a==1\nputs \"1\"\nputs \"1\"\nelsif a==2\nputs \"1\"\nputs \"1\"\nelsif a==3\nputs \"2\"\nputs \"1 3\"\nelse \nputs \"#{a}\"\nif a%2==1\nprintf \"#{a/2 + 1} \"\n0.upto(a/2 - 1) do |i|\nprintf \"#{i+1} #{a-i} \"\nend\nelse\nprintf \"#{a/2 + 1} \"\n0.upto(a/2 - 2) do |i|\nprintf \"#{i+1} #{a-i} \"\nend\nprintf \"#{a/2}\"\nend\nend"}, {"source_code": "n=gets.to_i\narr=[]\nif n<5 then\n\tarr=[[],[1],[1],[1,3],[2,4,1,3]][n]\n\tputs arr.size\n\tputs arr*\" \"\n\t\nelse\n\t1.step(n,2){|e|\n\t\t\tarr<n\n\t\treturn arr\n\tend\n\n\tch = 0\n\tif !arr.include?(i)\n\t\tif arr == []\n\t\t\tch = 1\n\t\t\tp = sol(arr+[i],1,n)\n\t\telsif (i>=arr[-1]+2 || i<=arr[-1]-2)\n\t\t\tch = 1\n\t\t\tp = sol(arr+[i],1,n)\n\t\tend\n\tend\n\tnp = sol(arr,i+1,n)\n\n\tif ch == 1\n\t\treturn p.length > np.length ? p : np\n\tend\n\treturn np\nend\n\n\nn = gets.chomp.to_i\nf = (1..n/2).to_a.reverse\nbf = ((n/2)+1..n).to_a.reverse\norder = f.length>bf.length ? 1 : 2\n\nif n < 6\n\ta = sol([],1,n)\n\tputs \"#{a.length}\"\n\tputs a.join(\" \")\nelse\n\t\n\tans = []\n\twhile true\n\t\tif f == [] && bf == []\n\t\t\tbreak\n\t\tend\n\t\tif order == 1\n\t\t\tif f!=[]\n\t\t\t\tans << f.pop\n\t\t\tend\n\t\t\tif bf!=[]\n\t\t\t\tans << bf.pop\n\t\t\tend\n\t\telse\n\t\t\tif bf!=[]\n\t\t\t\tans << bf.pop\n\t\t\tend\n\t\t\tif f!=[]\n\t\t\t\tans << f.pop\n\t\t\tend\n\t\tend\n\tend\n\n\tputs \"#{ans.length}\"\n\t\n\tputs ans.join(\" \")\nend"}, {"source_code": "n = gets.strip.to_i\nif n <= 2\n puts \"1\"\n puts \"1\"\n exit\nend\n\nif n == 3\n puts n - 1\n puts (1..n).to_a.select { |e| e.odd? }.sort.reverse.join(' ')\n exit\nend\n\nodd = (1..n).to_a.select { |e| e.odd? }.sort.reverse\neven = (1..n).to_a.select { |e| e.even? }.sort.reverse\n\nputs n\nprint odd.join(' ')\nprint \" \"\nprint even.join(' ')\n\n"}, {"source_code": "a= gets().chomp().to_i\nif a==1||a==2\n print 1,\"\\n\",1\nelsif a==3\n print 2,\"\\n\",1,' ',3\nelse\n print a,\"\\n\" ;(1..a).each{|num| print num,' ' if num%2==0} ;(1..a).each{|num| print num,' ' if num%2==1}\nend\n"}, {"source_code": "n = gets.to_i\n\nif n <= 2\n puts \"1\\n1\\n\"\nelsif n == 3\n puts \"2\\n1 3\\n\"\nelse\n e = 1.upto(n).select { |x| x % 2 == 0 }\n o = 1.upto(n).select { |x| x % 2 == 1 }\n puts n\n puts e.join(\" \") + \" \" + o.join(\" \")\nend\n"}, {"source_code": "n = gets.to_i\nif n==1 or n==2\n print \"1\\n1\\n\"\n exit\nelsif n==3\n print \"2\\n1 3\\n\"\n exit\nelsif n==4\n print \"4\\n3 1 4 2\\n\"\n exit\nend\nleft = Array.new\nright = Array.new\nfor i in (1...n).step(2)\n left.push(i)\n right.push(i+1)\nend\nif n.odd?\n left.push(n)\nend\nputs n\nputs (left+right).join(' ')\n"}, {"source_code": "#!/usr/bin/env ruby\nn=gets.to_i\nif n<3\n\tputs \"1\\n1\\n\"\nelsif n<4\n\tputs \"2\\n1 3\\n\"\nelse\n\tp n\n\tputs (2.step(n,2).to_a+1.step(n,2).to_a)*' '\nend"}, {"source_code": "# http://codeforces.com/contest/534/problem/A\nn = gets.to_i\narr = case n\n when 1, 2\n [1]\n when 3\n [1, 3]\n else\n 2.step(n, 2).to_a + 1.step(n, 2).to_a\n end\n\nputs arr.length\nputs arr.join(' ')\n"}, {"source_code": "n = gets.to_i\nif n==1 or n==2\n print \"1\\n1\\n\"\n exit\nelsif n==3\n print \"2\\n1 3\\n\"\n exit\nelsif n==4\n print \"4\\n3 1 4 2\\n\"\n exit\nend\nputs n\nputs ((1..n).step(2).to_a+(2..n).step(2).to_a).join(' ')\n"}, {"source_code": "n = gets.to_i\nans = case n\nwhen 1, 2\n [1]\nwhen 3\n [1, 3]\nwhen 4\n [3, 1, 4, 2]\nelse\n a = []\n b = []\n 1.upto(n) do |i|\n (i.odd? ? a : b) << i\n end\n a + b\nend\nputs ans.size\nputs ans.join(\" \")\n"}, {"source_code": "n = gets.to_i\na = case n\nwhen 1, 2\n [1]\nwhen 3\n [1, 3]\nwhen 4\n [3, 1, 4, 2]\nelse\n a = []\n b = []\n n.times do |i|\n i += 1\n (i % 2 == 0 ? b : a) << i\n end\n a + b\nend\nputs a.size\nputs a.join(\" \")\n"}, {"source_code": "n = gets.to_i\nans = case n\nwhen 1, 2\n [1]\nwhen 3\n [1, 3]\nwhen 4\n [3, 1, 4, 2]\nelse\n (1..n).partition{|x| x.odd?}.flatten\nend\nputs ans.size, ans.join(\" \")\n"}, {"source_code": "a=gets.chomp.to_i\nif a==1\nputs \"1\"\nputs \"1\"\nelsif a==2\nputs \"1\"\nputs \"1\"\nelsif a==3\nputs \"2\"\nputs \"1 3\"\nelse \nputs \"#{a}\"\nif a%2==1\nprintf \"#{a/2 + 1} \"\n0.upto(a/2 - 1) do |i|\nprintf \"#{i+1} #{a-i} \"\nend\nelse\nprintf \"#{a/2 + 1} \"\n0.upto(a/2 - 2) do |i|\nprintf \"#{i+1} #{a-i} \"\nend\nprintf \"#{a/2}\"\nend\nend"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\nn=gets.to_i\nif n<3\n\tputs \"1\\n1\\n\"\nelsif n<5\n\tputs \"2\\n1 3\\n\"\nelse\n\tp n\n\tputs (1.step(n,2).to_a+2.step(n,2).to_a)*' '\nend"}, {"source_code": "# http://codeforces.com/contest/534/problem/A\nn = gets.to_i\narr = case n\n when 1, 2\n [1]\n when 3\n [1, 3]\n else\n 1.step(n, 2).to_a + 2.step(n, 2).to_a\n end\n\nputs arr.length\nputs arr.join(' ')\n"}, {"source_code": "a=gets.chomp.to_i\nif a==1\nputs \"1\"\nputs \"1\"\nelsif a==2\nputs \"0\"\nelsif a==3\nputs \"2\"\nputs \"1 3\"\nelse \nputs \"#{a}\"\nif a%2==1\nprintf \"#{a/2 + 1} \"\n0.upto(a/2 - 1) do |i|\nprintf \"#{i+1} #{a-i} \"\nend\nelse\nprintf \"#{a/2 + 1} \"\n0.upto(a/2 - 2) do |i|\nprintf \"#{i+1} #{a-i} \"\nend\nprintf \"#{a/2}\"\nend\nend\n"}, {"source_code": "n = gets.to_i\n\nif n == 2\n pust '1'\n puts '1'\nelsif n == 3\n puts '2'\n puts '1 3'\nelse\n puts n\n\n print 3\n (5..n).step(2).each_with_index { |v,i|\n print ' '\n print v\n }\n print ' '\n print 1\n (2..n).step(2).each_with_index.reverse_each { |v, i|\n print ' '\n print v\n }\n print \"\\n\"\nend\n"}, {"source_code": "def sol(arr,i,n)\n\t# p arr\n\tif i>n\n\t\treturn arr\n\tend\n\n\tch = 0\n\tif !arr.include?(i)\n\t\tif arr == []\n\t\t\tch = 1\n\t\t\tp = sol(arr+[i],1,n)\n\t\telsif (i>=arr[-1]+2 || i<=arr[-1]-2)\n\t\t\tch = 1\n\t\t\tp = sol(arr+[i],1,n)\n\t\tend\n\tend\n\tnp = sol(arr,i+1,n)\n\n\tif ch == 1\n\t\treturn p.length > np.length ? p : np\n\tend\n\treturn np\nend\n\n\nn = gets.chomp.to_i\nf = (1..n/2).to_a.reverse\nbf = ((n/2)+1..n).to_a.reverse\n\n\nif n < 6\n\ta = sol([],1,n)\n\tputs \"#{a.length}\"\n\tputs a.join(\" \")\nelse\n\t\n\tans = []\n\twhile true\n\t\tif f == [] && bf == []\n\t\t\tbreak\n\t\tend\n\t\tif f!=[]\n\t\t\tans << f.pop\n\t\tend\n\t\tif bf!=[]\n\t\t\tans << bf.pop\n\t\tend\n\tend\n\n\tputs \"#{ans.length}\"\n\t\n\tputs ans.join(\" \")\nend"}, {"source_code": "# def sol(arr,i,n)\n# \t# p arr\n# \tif i>n\n# \t\treturn arr\n# \tend\n\n# \tch = 0\n# \tif !arr.include?(i)\n# \t\tif arr == []\n# \t\t\tch = 1\n# \t\t\tp = sol(arr+[i],1,n)\n# \t\telsif (i>=arr[-1]+2 || i<=arr[-1]-2)\n# \t\t\tch = 1\n# \t\t\tp = sol(arr+[i],1,n)\n# \t\tend\n# \tend\n# \tnp = sol(arr,i+1,n)\n\n# \tif ch == 1\n# \t\treturn p.length > np.length ? p : np\n# \tend\n# \treturn np\n# end\n\n\nn = gets.chomp.to_i\nan = [1]\nset = (2..n).to_a\ni = 0\nwhile true\n\tif n == 4\n\t\tbreak\n\tend\n\tch = 0\n\tif i == n\n\t\tbreak\n\tend\n\tset.length.times{|x|\n\t\tif set[x]>=an[i]+2 || set[x] <= an[i]-2\n\t\t\t# p set\n\t\t\tan<< set[x]\n\t\t\tset.delete(set[x])\n\t\t\ti+=1\n\t\t\tch = 1\n\t\t\tbreak\n\t\tend\n\t}\n\tif ch == 0\n\t\tbreak\n\tend\nend\n\nif n == 4\n\tputs 4.to_s\n\tputs [3,1,4,2].join(\" \")\nelse\n\t# a = sol([],1,n)\n\tputs \"#{i}\"\n\t# puts \"#{a.length}\"\n\t# puts a.join(\" \")\n\tputs an.join(\" \")\nend"}, {"source_code": "n = gets.chomp.to_i\nan = [1]\nset = (2..n).to_a\ni = 0\nwhile true\n\tch = 0\n\tif i == n\n\t\tbreak\n\tend\n\tset.length.times{|x|\n\t\tif set[x]>=an[i]+2 || set[x] <= an[i]-2\n\t\t\t# p set\n\t\t\tan<< set[x]\n\t\t\tset.delete(set[x])\n\t\t\ti+=1\n\t\t\tch = 1\n\t\t\tbreak\n\t\tend\n\t}\n\tif ch == 0\n\t\tbreak\n\tend\nend\n\nputs \"#{i+1}\"\nputs an.join(\" \")"}, {"source_code": "# def sol(arr,i,n)\n# \t# p arr\n# \tif i>n\n# \t\treturn arr\n# \tend\n\n# \tch = 0\n# \tif !arr.include?(i)\n# \t\tif arr == []\n# \t\t\tch = 1\n# \t\t\tp = sol(arr+[i],1,n)\n# \t\telsif (i>=arr[-1]+2 || i<=arr[-1]-2)\n# \t\t\tch = 1\n# \t\t\tp = sol(arr+[i],1,n)\n# \t\tend\n# \tend\n# \tnp = sol(arr,i+1,n)\n\n# \tif ch == 1\n# \t\treturn p.length > np.length ? p : np\n# \tend\n# \treturn np\n# end\n\n\nn = gets.chomp.to_i\nan = [1]\nset = (2..n).to_a\ni = 0\nwhile true\n\tif n == 4\n\t\tbreak\n\tend\n\tch = 0\n\tif i == n\n\t\tbreak\n\tend\n\tset.length.times{|x|\n\t\tif set[x]>=an[i]+2 || set[x] <= an[i]-2\n\t\t\t# p set\n\t\t\tan<< set[x]\n\t\t\tset.delete(set[x])\n\t\t\ti+=1\n\t\t\tch = 1\n\t\t\tbreak\n\t\tend\n\t}\n\tif ch == 0\n\t\tbreak\n\tend\nend\n\nif n == 4\n\tputs 4.to_s\n\tputs [3,1,4,2].join(\" \")\nelse\n\t# a = sol([],1,n)\n\tputs \"#{i+1}\"\n\t# puts \"#{a.length}\"\n\t# puts a.join(\" \")\n\tputs an.join(\" \")\nend"}, {"source_code": "n = gets.strip.to_i\nif n <= 2\n puts \"0\"\n exit\nend\n\nif n == 3\n puts n - 1\n puts (1..n).to_a.select { |e| e.odd? }.sort.join(' ')\n exit\nend\nodd = (1..n).to_a.select { |e| e.odd? }.sort\neven = (1..n).to_a.select { |e| e.even? }.sort\n\nputs n\nprint odd.join(' ')\nprint \" \"\nprint even.join(' ')\n\n"}, {"source_code": "n = gets.strip.to_i\nif n <= 2\n puts \"1\"\n puts \"1\"\n exit\nend\n\nif n == 3\n puts n - 1\n puts (1..n).to_a.select { |e| e.odd? }.sort.join(' ')\n exit\nend\nodd = (1..n).to_a.select { |e| e.odd? }.sort\neven = (1..n).to_a.select { |e| e.even? }.sort\n\nputs n\nprint odd.join(' ')\nprint \" \"\nprint even.join(' ')\n\n"}, {"source_code": "n = gets.strip.to_i\nif n <= 2\n puts \"0\"\n exit\nend\n\nif n == 3\n puts (1..n).to_a.select { |e| e.odd? }.sort.join(' ')\n exit\nend\nodd = (1..n).to_a.select { |e| e.odd? }.sort\neven = (1..n).to_a.select { |e| e.even? }.sort\n\nprint odd.join(' ')\nprint \" \"\nprint even.join(' ')\n\n"}, {"source_code": "n = gets.to_i\nif n==1\n print \"1\\n1\\n\"\n exit\nend\nleft = Array.new\nright = Array.new\nk = n/2\nfor i in 1..k\n if i.odd?\n left.push(i)\n right.push(n+1-i)\n else\n left.push(n+1-i)\n right.push(i)\n end\nend\nputs k*2\nputs (left+right).join(' ')\n"}, {"source_code": "n = gets.to_i\nleft = Array.new\nright = Array.new\nk = n/2\nfor i in 1..k\n if i.odd?\n left.push(i)\n right.push(n+1-i)\n else\n left.push(n+1-i)\n right.push(i)\n end\nend\nputs k*2\nputs (left+right).join(' ')\n"}, {"source_code": "n = gets.to_i\nif n==1 or n==2\n print \"1\\n1\\n\"\n exit\nelsif n==3\n print \"2\\n1 3\\n\"\n exit\nelsif n==4\n print \"4\\n1 4 2 3\\n\"\n exit\nend\nleft = Array.new\nright = Array.new\nfor i in (1...n).step(2)\n left.push(i)\n right.push(i+1)\nend\nif n.odd?\n left.push(n)\nend\nputs n\nputs (left+right).join(' ')\n"}, {"source_code": "n = gets.to_i\nif n==1 or n==2\n print \"1\\n1\\n\"\n exit\nelsif n==4\n print \"4\\n3 1 4 2\\n\"\nend\nleft = Array.new\nright = Array.new\nk = n/2\nfor i in 1..k\n if i.odd?\n left.push(i)\n right.push(n+1-i)\n else\n left.push(n+1-i)\n right.push(i)\n end\nend\nputs k*2\nputs (left+right).join(' ')\n"}, {"source_code": "n = gets.to_i\nif n==1 or n==2\n print \"1\\n1\\n\"\n exit\nend\nleft = Array.new\nright = Array.new\nk = n/2\nfor i in 1..k\n if i.odd?\n left.push(i)\n right.push(n+1-i)\n else\n left.push(n+1-i)\n right.push(i)\n end\nend\nputs k*2\nputs (left+right).join(' ')\n"}, {"source_code": "n = gets.to_i\nif n==1 or n==2\n print \"1\\n1\\n\"\n exit\nelsif n==4\n print \"4\\n3 1 4 2\\n\"\n exit\nend\nleft = Array.new\nright = Array.new\nk = n/2\nfor i in 1..k\n if i.odd?\n left.push(i)\n right.push(n+1-i)\n else\n left.push(n+1-i)\n right.push(i)\n end\nend\nputs k*2\nputs (left+right).join(' ')\n"}, {"source_code": "n = gets.to_i\na = []\n((n + 1) / 2).times.each{|i| a << i * 2 + 1}\n((n + 1) / 2).times do |i|\n x = (i + 1) * 2\n a << x if x <= n && (x - a.last).abs > 1\nend\n\na = [1, 4, 2] if n == 4\nputs a.join(\" \")\n"}, {"source_code": "n = gets.to_i\na = []\n((n + 1) / 2).times.each{|i| a << i * 2 + 1}\n((n + 1) / 2).times do |i|\n x = (i + 1) * 2\n a << x if x <= n && (x - a.last).abs > 1\nend\n\na = [1, 4, 2] if n == 4\nputs a.size\nputs a.join(\" \")\n"}], "src_uid": "a52ceb8a894809b570cbb74dc5ef76e1"} {"source_code": "n = gets.to_i \na = gets.split.map{ |i| i.to_f } \na.sort! \np = 1 \ns = 0 \nans = 0 \nout = 0\nwhile s < 1.0 && a.length > 0 do \n\tel = a.pop \n\tif s + el * (1 - el) > 1.0 \n\t\tout = [out, ans + p * el * ( 1 - s )].max\n\t\tnext\n\tend\n\tans += p * el * ( 1 - s ) \n\tp *= (1 - el) \n\ts += el / (1 - el) \n\tout = [ans, out].max\nend\nputs out", "positive_code": [{"source_code": "n=readline.to_i\np=readline.split(' ').map &:to_f\np=p.sort{|a,b| b<=>a}\nap,bs,ans=1,0,0\np.each do |x|\n nap=ap*(1.0-x)\n nbs=bs+x/(1.0-x)\n if nap*nbs > ans\n ans=nap*nbs\n ap,bs=nap,nbs\n end\nend\nputs [p[0],ans].max\n"}, {"source_code": "_ = gets.to_i\np = gets.split.map { |x| x.to_f }\nans = 0.0\nres = 1.0\nwhile p.size > 0\n max = ans\n sel = -1\n p.each_with_index do |x, i|\n if ans * (1.0 - x) + res * x > max\n max = ans * (1.0 - x) + res * x\n sel = i\n end\n end\n break if sel == -1\n ans = max\n res *= 1 - p[sel]\n p.delete_at(sel)\nend\nputs ans\n"}], "negative_code": [{"source_code": "n=readline.to_i\np=readline.split(' ').map &:to_f\np=p.sort{|a,b| b<=>a}\nans=p.shift\np.each {|x| ans=[ans, x*(1.0-ans)+ans*(1.0-x)].max }\nputs ans\n"}, {"source_code": "n=readline.to_i\np=readline.split(' ').map &:to_f\np=p.sort{|a,b| b<=>a}\nap,bs,ans=1,0,p[0]\np.each do |x|\n nap=ap*(1.0-x)\n nbs=bs+x/(1.0-x)\n if nap*nbs > ans\n ans=nap*nbs\n ap,bs=nap,nbs\n end\nend\nputs ans\n"}, {"source_code": "n=readline.to_i\np=readline.split(' ').map &:to_f\np=p.sort{|a,b| b<=>a}\nap,bs,ans=1,0,0\np.each do |x|\n nap=ap*(1.0-x)\n nbs=bs+x/(1.0-x)\n if nap*nbs > ans\n ans=nap*nbs\n ap,bs=nap,nbs\n end\nend\nputs ans\n"}], "src_uid": "b4ac594755951e84001dfd610d420eb5"} {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\nm = gis\nw = gis\nh = gis\n\nscore = (1..5).map{|x| x*500}.zip(m,w).map{|xi,mi,wi| \n [300 * xi, (1000 - 4 * mi) * xi - 50000 * wi].max\n}.inject(:+) + 100000 * h[0] - 50000 * h[1]\n\nputs score.div(1000)", "positive_code": [{"source_code": "m = gets.split.map { |i| i.to_i }\nw = gets.split.map { |i| i.to_i }\nh = gets.split.map { |i| i.to_i }\n\nx = [1, 2, 3, 4, 5]\n\nres = 0\n\n(0..4).each do |i|\n res += [150 * x[i], (500 - m[i] * 2) * x[i] - 50 * w[i]].max\nend\n\nres += h[0] * 100 - h[1] * 50\n\nputs res\n"}, {"source_code": "m = gets.split.map(&:to_i)\nw = gets.split.map(&:to_i)\nh = gets.split.map(&:to_i)\ns = [500, 1000, 1500, 2000, 2500]\nans = 5.times.map{|i| [3 * s[i] / 10, (250 - m[i]) * s[i] / 250 - 50 * w[i]].max}.inject(:+)\nans += h[0] * 100 - h[1] * 50\nputs ans\n"}, {"source_code": "m = gets.split.map(&:to_i)\nw = gets.split.map(&:to_i)\nh = gets.split.map(&:to_i)\ns = [500, 1000, 1500, 2000, 2500]\nans = 0\n5.times{|i| ans += [0.3 * s[i], (250 - m[i]) * s[i] / 250 - 50 * w[i]].max }\nputs ans.to_i + h[0] * 100 - h[1] * 50\n"}, {"source_code": "xx = [500, 1000, 1500, 2000, 2500]\nmm = gets.chomp.split(\" \").map(&:to_f)\nww = gets.chomp.split(\" \").map(&:to_f)\nhs, hu = gets.chomp.split(\" \").map(&:to_i)\ncalc_score = ->(x, m, w) {\n (250 - m) * x / 250 - 50 * w\n}\nscores = Array.new\n(0...5).each do |i|\n scores << [0.3*xx[i], calc_score.call(xx[i], mm[i], ww[i])].max\nend\nputs (scores.inject(:+) + hs * 100 - hu * 50).to_i\n"}, {"source_code": "maxpoint=[]\n0.upto(4) do |i|\n\tmaxpoint[i]=(i+1)*500\nend\ntime=gets.chomp.split(\" \")\n0.upto(4) do |i|\n\ttime[i]=time[i].to_i\nend\nwrong=gets.chomp.split(\" \")\n0.upto(4) do |i|\n\twrong[i]=wrong[i].to_i\nend\nhack=gets.chomp.split(\" \")\n0.upto(1) do |i|\n\thack[i]=hack[i].to_i\nend\npoint=[]\n0.upto(4) do |i|\n\tpoint[i]=((1.0-time[i]/250.0)*maxpoint[i])-(50*wrong[i])\n\tif point[i]< (0.3*maxpoint[i])\n\t\tpoint[i]=0.3*maxpoint[i]\n\tend\t\t\nend\npoint=point.inject{|memo,n| memo+n }\npoint=point+(100*hack[0])-(50*hack[1])\nputs point.to_i\n"}, {"source_code": "max_marks = [500, 1000, 1500, 2000, 2500]\nsolution_times = $stdin.readline.split.map(&:to_i)\nnums_wrong_attempts = $stdin.readline.split.map(&:to_i)\ngood_cracks, bad_cracks = $stdin.readline.split.map(&:to_i)\n\nscore = max_marks.zip(solution_times, nums_wrong_attempts).map{|max_mark, solution_time, num_wrong_attempts|\n [3.quo(10)*max_mark, (1 - solution_time.quo(250) ) * max_mark - 50 * num_wrong_attempts].max\n}.inject(0, &:+)\n\nputs (score + good_cracks * 100 - bad_cracks * 50).to_i\n\n"}, {"source_code": "class Solver\n\tdef main\n\t\tmax_score = [500, 1000, 1500, 2000, 2500]\n\t\tlast_submission_time = gets.split.map { |x| x.to_i }\n\t\twrong_submissions = gets.split.map { |x| x.to_i }\n\t\tsuccessful_hacks, unsuccessful_hacks = gets.split.map { |x| x.to_i }\n\n\t\tproblem_score = Array.new(5, 0)\n\t\t0.upto(5 - 1) do |i|\n\t\t\tlhs = max_score[i] * 3 / 10\n\t\t\trhs = max_score[i] - max_score[i] / 250 * last_submission_time[i] \\\n\t\t\t\t- wrong_submissions[i] * 50\n\t\t\tproblem_score[i] = [lhs, rhs].max\n\t\tend\n\n\t\ttotal_score = problem_score.reduce(:+)\n\t\ttotal_score += successful_hacks * 100\n\t\ttotal_score -= unsuccessful_hacks * 50\n\t\tputs total_score\n\tend\nend\n\nSolver.new.main\n"}, {"source_code": "p 2.times.map{gets.split.map(&:to_i)}.transpose.map.with_index(1){|(m,w),x|[150*x,(500-2*m)*x-50*w].max}.reduce(:+)+gets.split.map(&:to_i).zip([100,-50]).map{|x,y|x*y}.reduce(:+)"}, {"source_code": "minutes = gets.chomp.split.map(&:to_f)\nwrongs = gets.chomp.split.map(&:to_f)\ns, f = gets.chomp.split.map(&:to_i)\npoints = [500, 1000, 1500, 2000, 2500]\n\nscore = 0\n(0..4).each do |idx|\n score += [\n 0.3 * points[idx],\n (1 - minutes[idx] / 250.0) * points[idx] - 50 * wrongs[idx]\n ].max\nend\nscore += s * 100 - f * 50\nputs score.to_i\n"}, {"source_code": "maxpoint=[]\n0.upto(4) do |i|\n\tmaxpoint[i]=(i+1)*500\nend\ntime=gets.chomp.split(\" \")\n0.upto(4) do |i|\n\ttime[i]=time[i].to_i\nend\nwrong=gets.chomp.split(\" \")\n0.upto(4) do |i|\n\twrong[i]=wrong[i].to_i\nend\nhack=gets.chomp.split(\" \")\n0.upto(1) do |i|\n\thack[i]=hack[i].to_i\nend\npoint=[]\n0.upto(4) do |i|\n\tpoint[i]=((1.0-time[i]/250.0)*maxpoint[i])-(50*wrong[i])\n\tif point[i]< (0.3*maxpoint[i])\n\t\tpoint[i]=0.3*maxpoint[i]\n\tend\t\t\nend\npoint=point.inject{|memo,n| memo+n }\npoint=point+(100*hack[0])-(50*hack[1])\nputs point.to_i\n"}, {"source_code": "maxpoint=[]\n0.upto(4) do |i|\n\tmaxpoint[i]=(i+1)*500\nend\ntime=gets.chomp.split(\" \")\n0.upto(4) do |i|\n\ttime[i]=time[i].to_i\nend\nwrong=gets.chomp.split(\" \")\n0.upto(4) do |i|\n\twrong[i]=wrong[i].to_i\nend\nhack=gets.chomp.split(\" \")\n0.upto(1) do |i|\n\thack[i]=hack[i].to_i\nend\npoint=[]\n0.upto(4) do |i|\n\tpoint[i]=((1.0-time[i]/250.0)*maxpoint[i])-(50*wrong[i])\n\tif point[i]< (0.3*maxpoint[i])\n\t\tpoint[i]=0.3*maxpoint[i]\n\tend\t\t\nend\npoint=point.inject{|memo,n| memo+n }\npoint=point+(100*hack[0])-(50*hack[1])\nputs point.to_i"}, {"source_code": "minutes=[]\nmins=gets.chomp.split\nmins.each do |i|\n\tminutes.push(i.to_i)\nend\n\nhacked=[]\nhaks=gets.chomp.split\nhaks.each do |i|\n\thacked.push(i.to_i)\nend\n\nsuccess=[]\nsucs=gets.chomp.split\nsucs.each do |i|\n\tsuccess.push(i.to_i)\nend\n\nsum=0\n\na1=(250-minutes[0])*2-hacked[0]*50\nb1=3*50\nif a1>b1\n\tsum+=a1\nelse\n\tsum+=b1\nend\n\na2=(250-minutes[1])*4-hacked[1]*50\nb2=3*100\nif a2>b2\n\tsum+=a2\nelse\n\tsum+=b2\nend\n\na3=(250-minutes[2])*6-hacked[2]*50\nb3=3*150\nif a3>b3\n\tsum+=a3\nelse\n\tsum+=b3\nend\n\na4=(250-minutes[3])*8-hacked[3]*50\nb4=3*200\nif a4>b4\n\tsum+=a4\nelse\n\tsum+=b4\nend\n\na5=(250-minutes[4])*10-hacked[4]*50\nb5=3*250\nif a5>b5\n\tsum+=a5\nelse\n\tsum+=b5\nend\n\nsum=sum-success[1]*50+success[0]*100\n\nputs sum"}, {"source_code": "m = []\nw = []\nh = []\nm = gets.split.map(&:to_i)\nw = gets.split.map(&:to_i)\nh = gets.split.map(&:to_i)\n\ntmp = 0\n5.times do |v|\n ms = 500*(v+1)\n ma = 0.3*ms\n mt = (1-m[v]/250.0)*ms - 50*w[v]\n if ma < mt\n tmp += mt\n else\n tmp += ma\n end\nend\ntmp += (100*h[0] - 50*h[1])\nputs tmp.to_i"}, {"source_code": "xs = [500, 1000, 1500, 2000, 2500]\nms = gets.chomp.split.map(&:to_i)\nws = gets.chomp.split.map(&:to_i)\nhs, hu = gets.chomp.split.map(&:to_i)\n\nputs (0..4).to_a.inject(100 * hs - 50 * hu) { |m, i| m + [3 * xs[i] / 10, xs[i] - ms[i] * (xs[i] / 250) - 50 * ws[i]].max }\n\n"}, {"source_code": "m = gets.split.to_a.map(&:to_f)\nw = gets.split.to_a.map(&:to_f)\nhs, hu = gets.split.map(&:to_f)\nx=[500,1000,1500,2000,2500]\nresult = 0\nfor i in 0..4\n\tif(0.3*x[i]>(1-m[i]/250)*x[i]-50*w[i])\n\t\tresult+= 0.3*x[i]\n\telse\n\t\t\tresult+= (1-m[i]/250)*x[i]-50*w[i]\n\tend\nend\n result+=hs*100-hu*50\n p result.to_i"}, {"source_code": "m = gets.split(\" \").map(&:to_i)\nw = gets.split(\" \").map(&:to_i)\nh = gets.split(\" \").map(&:to_i)\nx = [500, 1000, 1500, 2000, 2500]\ndef f(a, b, c)\n\treturn [0.3*c, (1-a/250.0)*c-50*b].max\nend\nsol = 100*h[0]-50*h[1]\nfor i in 0..4\n\tsol += f(m[i], w[i], x[i])\nend\nputs sol.to_i\n"}], "negative_code": [{"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\nm = gis\nw = gis\nh = gis\n\nscore = (1..5).map{|x| x*500}.zip(m,w).map{|xi,mi,wi| [0.3 * xi, (1.0 - mi / 250.0) * xi - 50.0 * wi].max}.inject(:+) + 100 * h[0] + 50 * h[1]\n\nputs score.floor"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\nm = gis\nw = gis\nh = gis\n\nscore = (1..5).map{|x| x*500}.zip(m,w).map{|xi,mi,wi| \n [300 * xi, (1000 - 4 * mi) * xi - 500 * wi].max\n}.inject(:+) + 100000 * h[0] + 50000 * h[1]\n\nputs score.div(1000)"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\nm = gis\nw = gis\nh = gis\n\nscore = (1..5).map{|x| x*500}.zip(m,w).map{|xi,mi,wi| \n [300 * xi, (1000 - 4 * mi) * xi - 50000 * wi].max\n}.inject(:+) + 100000 * h[0] + 50000 * h[1]\n\nputs score.div(1000)"}, {"source_code": "maxpoint=[]\n0.upto(4) do |i|\n\tmaxpoint[i]=(i+1)*500\nend\ntime=gets.chomp.split(\" \")\n0.upto(4) do |i|\n\ttime[i]=time[i].to_i\nend\nwrong=gets.chomp.split(\" \")\n0.upto(4) do |i|\n\twrong[i]=wrong[i].to_i\nend\nhack=gets.chomp.split(\" \")\n0.upto(1) do |i|\n\thack[i]=hack[i].to_i\nend\npoint=[]\n0.upto(4) do |i|\n\tpoint[i]=((1.0-time[i]/250.0)*maxpoint[i])-(50*wrong[i])\n\tif point[i]< (0.3*maxpoint[i])\n\t\tpoint[i]=0.3*maxpoint[i]\n\tend\t\t\nend\npoint1=point.inject{|memo,n| memo+n }\npoint1=point1+(100*hack[0])-(50*hack[1])\n"}, {"source_code": "minutes=[]\nmins=gets.chomp.split\nmins.each do |i|\n\tminutes.push(i.to_i)\nend\n\nhacked=[]\nhaks=gets.chomp.split\nhaks.each do |i|\n\thacked.push(i.to_i)\nend\n\nsuccess=[]\nsucs=gets.chomp.split\nsucs.each do |i|\n\tsuccess.push(i.to_i)\nend\n\nsum=(((250-minutes[0]).to_f/250)*500+((250-minutes[1]).to_f/250)*1000+((250-minutes[2]).to_f/250)*1500+(1-(minutes[3]).to_f/250)*2000+(1-(minutes[4]).to_f/250)*2500-(hacked[4]+hacked[3]+hacked[2]+hacked[1]+hacked[0])*50+success[0]*100-success[1]*50).to_i\nputs sum"}, {"source_code": "xs = [500, 1000, 1500, 2000, 2500]\nms = gets.chomp.split.map(&:to_i)\nws = gets.chomp.split.map(&:to_i)\nhs, hu = gets.chomp.split.map(&:to_i)\n\nputs (0..4).to_a.inject(0) { |m, i| m + [0.3 * xs[i], xs[i] - ms[i] * xs[i] / 250 - 50 * ws[i]].max } + 100 * hs - 50 * hu\n"}, {"source_code": "m = gets.split.map { |i| i.to_i }\nw = gets.split.map { |i| i.to_i }\nh = gets.split.map { |i| i.to_i }\n\nx = [1, 2, 3, 4, 5]\n\nres = 0\n\n(0..4).each do |i|\n res += [0.3 * x[i] * 500, (500 - m[i] * 2) * x[i] - 50 * w[i]].max\nend\n\nres += h[0] * 100 - h[1] * 50\n\nputs res\n"}, {"source_code": "m = gets.split.map(&:to_i)\nw = gets.split.map(&:to_i)\nh = gets.split.map(&:to_i)\ns = [500, 1000, 1500, 2000, 2500]\nans = 0\n5.times{|i| ans += [0.3 * s[i], (250 - m[i]) * s[i] / 250 - 50 * w[i]].max }\nputs ans + h[0] * 100 - h[1] * 50\n"}, {"source_code": "xx = [500, 1000, 1500, 2000, 2500]\nmm = gets.chomp.split(\" \").map(&:to_i)\nww = gets.chomp.split(\" \").map(&:to_i)\nhs, hu = gets.chomp.split(\" \").map(&:to_i)\ncalc_score = ->(x, m, w) {\n (250 - m) * x / 250 - 50 * w\n}\nscores = Array.new\n(0...5).each do |i|\n scores << [0.3*xx[i], calc_score.call(xx[i], mm[i], ww[i])].max\nend\nputs scores.inject(:+) + hs * 100 - hu * 50\n"}], "src_uid": "636a30a2b0038ee1731325a5fc2df73a"} {"source_code": "n, m, k = gets.split.map {|x| Integer x}\na = Array.new(n)\nfor i in 0...n\n a[i] = Array.new\n s = gets.split.map {|x| (Integer x) - 1}\n for j in 0...m\n a[i][j] = s[j]\n end\nend\nbad_cell = [false] * k\nbad_core = [false] * n\nprev = [nil] * k\ntime = [0] * n\nfor t in 0...m\n used = [false] * k\n for c in 0...n\n if bad_core[c] or a[c][t] == -1\n next\n end\n if bad_cell[a[c][t]] or used[a[c][t]]\n bad_cell[a[c][t]] = true\n bad_core[c] = true\n if time[c] == 0\n time[c] = t + 1\n end\n bad_core[prev[a[c][t]]] = true\n if time[prev[a[c][t]]] == 0\n time[prev[a[c][t]]] = t + 1\n end\n end\n used[a[c][t]] = true\n prev[a[c][t]] = c\n end\nend\nputs time\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\n# n - cores\n# m - ticks\n# k - shared cache memory\n\ninput = STDIN.read.split(\"\\n\")\nn, m, k = *input[0].split(' ').map(&:to_i)\ncommands = input[1..-1].map{|s| s.split(' ').map(&:to_i) }\n\ncores = Array.new n, 0\nblocked_cells = []\n\ndefine_method(:working_cores) do\n cores.map.with_index{|c,i| c == 0 ? i : nil }.compact\nend\n\n1.upto(m).each do |tick|\n working_cores.\n map { |core| commands[core][tick - 1] }.\n compact.\n group_by(&:to_i).\n select{|_,xs| xs.count > 1 }.\n keys.\n reject{|c| c == 0 }.\n reject{|c| blocked_cells.include?(c) }.\n each { |cell| blocked_cells += [cell] } \n\n cores.map.with_index do |s,i|\n next if s > 0\n cores[i] = tick if blocked_cells.include?(commands[i][tick - 1])\n end\nend\n\ncores.each do |core|\n puts core\nend"}, {"source_code": "input = STDIN.read.split(\"\\n\")\nn, m, k = *input[0].split(' ').map(&:to_i)\ncommands = input[1..-1].map{|s| s.split(' ').map(&:to_i) }\n\ncores = Array.new n, 0\nblocked_cells = []\n\ndefine_method(:working_cores) do\n cores.map.with_index{|c,i| c == 0 ? i : nil }.compact\nend\n\n1.upto(m).each do |tick|\n working_cores.\n map { |core| commands[core][tick - 1] }.\n compact.\n group_by(&:to_i).\n select{|_,xs| xs.count > 1 }.\n keys.\n reject{|c| c == 0 }.\n reject{|c| blocked_cells.include?(c) }.\n each { |cell| blocked_cells += [cell] } \n\n cores.map.with_index do |s,i|\n next if s > 0\n cores[i] = tick if blocked_cells.include?(commands[i][tick - 1])\n end\nend\n\nputs cores"}, {"source_code": "n, m, k = gets.split.map &:to_i\na = Array.new\nn.times do |i|\n\ta[i] = gets.split.map { |x| x.to_i - 1 }\nend\nlock = Array.new(n) { 0 }\nlockcell = Array.new(k) { false }\n0.upto(m - 1) do |i|\n\tturn = Array.new(k) { -1 }\n\t0.upto(n - 1) do |j|\n\t\tif lock[j] == 0 && a[j][i] != -1\n\t\t\tif lockcell[a[j][i]]\n\t\t\t\tlock[j] = i + 1\n\t\t\telsif turn[a[j][i]] != -1\n\t\t\t\tlock[turn[a[j][i]]] = lock[j] = i + 1\n\t\t\t\tlockcell[a[j][i]] = true\n\t\t\tend\n\t\t\tturn[a[j][i]] = j\n\t\tend\n\tend\nend\nputs lock\n"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\n\n# n - cores\n# m - ticks\n# k - shared cache memory\n\ninput = STDIN.read.split(\"\\n\")\nn, m, k = *input[0].split(' ').map(&:to_i)\ncommands = input[1..-1].map{|s| s.split(' ').map(&:to_i) }\n\ncores = Array.new n, 0\nblocked_cells = []\n\ndefine_method(:working_cores) do\n cores.map.with_index{|c,i| c == 0 ? i : nil }.compact\nend\n\n1.upto(m).each do |tick|\n working_cores.\n map { |core| commands[core][tick - 1] }.\n compact.\n group_by(&:to_i).\n select{|_,xs| xs.count > 1 }.\n keys.\n reject{|c| blocked_cells.include?(c) }.\n each { |cell| blocked_cells += [cell] } \n\n cores.map.with_index do |s,i|\n next if s > 0\n cores[i] = tick if blocked_cells.include?(commands[i][tick - 1])\n end\nend\n\ncores.each do |core|\n puts core\nend"}], "src_uid": "6422a70e686c34b4b9b6b5797712998e"} {"source_code": "gets.to_i.times {\n a, b = gets.split.map { |v| v.to_i }\n s = a * b\n puts s / 2 + s % 2\n}\n", "positive_code": [{"source_code": "gets.to_i.times do\n n, m = gets.split(' ').map(&:to_i)\n\n puts n.div(2)*m + n.modulo(2)*m.div(2) + n.modulo(2)*m.modulo(2)\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do |testcase|\n (n,m) = gets.split.map(&:to_i)\n puts (n*m+1)/2\nend"}, {"source_code": "t = gets.to_i\n\n1.upto t do |i|\n n, m = gets.split.map(&:to_i)\n puts ((n * m) / 2 + (n * m) % 2)\nend"}], "negative_code": [], "src_uid": "19df5f3b8b31b763162c5331c1499529"} {"source_code": "#=================================\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nline=gets.strip\nhs=Hash.new(0)\n\nline.each_char{|c|\n\ths[c.ord]+=1\n}\n\nans=0\nhs.values.each{|v|\n\tans+=v**2\n}\n\nputs ans\n", "positive_code": [{"source_code": "puts gets.chomp.chars.group_by{|i|i}.map{|i,j|j.size**2}.inject(:+)"}, {"source_code": "counter = Hash.new(0)\nSTDIN.read.gsub(\"\\n\", \"\").split(\"\").each { |symbol| counter[symbol] += 1 }\nputs counter.values.inject(0) { |res, count| res + count ** 2}\n\n"}, {"source_code": "s = gets.chomp!\n\nmas = Hash.new()\ns.chars { |c|\n mas[c] == nil ? mas[c] = 1 : mas[c] += 1\n}\n\nsum = 0\nmas.each_value {|d|\n sum += d**2\n}\n\nputs sum"}], "negative_code": [], "src_uid": "6bb2793e275426eb076972fab69d0eba"} {"source_code": "def to_num(s)\n a = s.split(/\\./)\n\n n = a.length\n if n == 1\n return s.to_i * 100\n end\n\n if a[n-1].length == 2\n return a[0..n-2].join('').to_i * 100 + a[n-1].to_i\n end\n\n a.join('').to_i * 100\nend\n\ndef to_str(x)\n rem = x % 100\n ret = rem == 0 ? '' : \".%02d\" % (x % 100)\n\n s = (x / 100).to_s\n i = s.length - 1\n\n while i >= 0 do\n j = i - 2\n if j < 0\n j = 0\n end\n ret = '.' + s[j..i] + ret\n i = j - 1\n end\n\n ret[1..-1]\nend\n\na = STDIN.gets.gsub(/[a-z]/,' ').split.map { |s| to_num(s) }\nsum = a.inject(&:+)\nputs to_str(sum)\n", "positive_code": [{"source_code": "def parse(s)\n bias = 1\n if s.length <= 3 || s[-4] == '.'\n bias = 100\n end\n s.gsub!(/\\./, \"\")\n bias * s.to_i\nend\n\ndef enchant(n)\n s = \"\"\n if n % 100 != 0\n s = format(\".%02d\", n % 100)\n end\n n /= 100\n n = n.to_s\n nz = n.length\n for i in 0 .. nz - 1\n s = n[nz - 1 - i] + s\n if i < nz - 1 && i % 3 == 2\n s = \".\" + s\n end\n end\n s\nend\n\ns = gets.chomp\ns = s.split(/[a-z]+/).select{|v| v != \"\"}\ntot = 0\nfor v in s\n tot += parse(v)\nend\n\nputs enchant(tot)\n"}], "negative_code": [{"source_code": "def to_num(s)\n a = s.split(/\\./)\n\n n = a.length\n if n == 1\n return s.to_f\n end\n\n if a[n-1].length == 2\n x = a[0..n-2].join('') + '.' + a[n-1]\n return x.to_f\n end\n\n a.join('').to_f\nend\n\ndef to_str(x)\n x = x.round(2)\n if x.to_s == x.to_i.to_s\n return x.to_i.to_s\n end\n a = x.to_s.split(/\\./)\n s = a[0]\n ret = \".#{a[1]}\"\n\n i = s.length - 1\n while i >= 0 do\n j = i - 2\n if j < 0\n j = 0\n end\n ret = '.' + s[j..i] + ret\n i = j - 1\n end\n\n ret[1..-1]\nend\n\na = STDIN.gets.gsub(/[a-z]/,' ').split.map { |s| to_num(s) }\nsum = a.inject(&:+)\nputs to_str(sum)\n"}, {"source_code": "def to_num(s)\n a = s.split(/\\./)\n\n n = a.length\n if n == 1\n return s.to_i * 100\n end\n\n if a[n-1].length == 2\n return a[0..n-2].join('').to_i * 100 + a[n-1].to_i\n end\n\n a.join('').to_i * 100\nend\n\ndef to_str(x)\n if x % 100 == 0\n return (x / 100).to_s\n end\n\n s = (x / 100).to_s\n ret = \".%02d\" % (x % 100)\n\n i = s.length - 1\n while i >= 0 do\n j = i - 2\n if j < 0\n j = 0\n end\n ret = '.' + s[j..i] + ret\n i = j - 1\n end\n\n ret[1..-1]\nend\n\na = STDIN.gets.gsub(/[a-z]/,' ').split.map { |s| to_num(s) }\nsum = a.inject(&:+)\nputs to_str(sum)\n"}, {"source_code": "def parse(s)\n bias = 1\n if s.length <= 3 || s[-4] == '.'\n bias = 100\n end\n s.gsub!(/\\./, \"\")\n bias * s.to_i\nend\n\ndef enchant(n)\n s = \"\"\n if n % 100 != 0\n s = format(\".%02d\", n % 100)\n end\n n /= 100\n n = n.to_s\n nz = n.length\n for i in 0 .. nz - 1\n s = n[nz - 1 - i] + s\n if i < nz - 1 && i % 3 == 2\n s = \".\" + s\n end\n end\n s\nend\n\ns = gets.chomp\ns = s.split(/[a-z]+/).select{|v| v != \"\"}\np s\ntot = 0\nfor v in s\n tot += parse(v)\nend\n\nputs enchant(tot)\n"}], "src_uid": "8da703549a3002bf9131d6929ec026a2"} {"source_code": "\r\ndef debug(*arg)\r\n puts \"[DEBUG] #{arg.join \" \"}\"\r\nend\r\n\r\nt = gets.to_i\r\n\r\nt.times do\r\n a, b, c = gets.split.map(&:to_i)\r\n\r\n\r\n if a == (b-c).abs + c\r\n puts 3\r\n elsif a < (b-c).abs + c\r\n puts 1\r\n else\r\n puts 2\r\n end\r\nend\r\n\r\n", "positive_code": [{"source_code": "n={1=>1,2=>3,3=>2}; $stdin.each_line.to_a[1..-1].each do |x| x=x.split(\" \").map(&:to_i); puts n[(x[0]-1<=>(x[1]-x[2]).abs+(x[2]-1))+2] end\r\n"}, {"source_code": "n = { 1 => 1, 2 => 3, 3 => 2 }\r\n$stdin.each_line.with_index do |x, i|\r\n next if i == 0 \r\n a, b, c = x.split(\" \").map(&:to_i)\r\n t1 = a - 1\r\n t2 = (b - c).abs + (c - 1)\r\n puts n[(t1 <=> t2) + 2]\r\nend"}, {"source_code": "t=gets.to_i\r\nfor t0 in (0...t)\r\n m=gets.split(' ').to_a\r\n a=m[0].to_i\r\n b=m[1].to_i\r\n c=m[2].to_i\r\n r=(b-c).abs+c\r\n puts 1 if ar\r\n puts 3 if a==r\r\nend\r\n"}, {"source_code": "$stdin.readline\r\n\r\nmap = { -1 => 1, 0 => 3, 1 => 2}\r\n\r\n$stdin.each_line do |line|\r\n a, b, c = line.chomp.split.map(&:to_i)\r\n puts map[(a - c <=> (c - b).abs)]\r\nend"}, {"source_code": "def solve(a, b, c)\r\n first_dis = (a - 1).abs\r\n second_dis = (b - c).abs + (c - 1).abs\r\n if first_dis == second_dis\r\n p 3\r\n elsif first_dis < second_dis\r\n p 1\r\n else\r\n p 2\r\n end\r\nend\r\n\r\nt = gets.chomp.to_i\r\n\r\nfor i in 1..t\r\n a, b, c = gets.chomp.split(' ').map(&:to_i)\r\n solve(a,b,c)\r\nend"}, {"source_code": "def check_elevator(a,b,c)\r\n comp=((c-b).abs+c)-a\r\n if comp>0\r\n 1\r\n elsif comp==0\r\n 3\r\n else\r\n 2\r\n end\r\nend\r\n\r\nn_rounds=gets.to_i\r\n\r\nn_rounds.times do\r\n puts check_elevator(*(gets.split(' ').map(&:to_i)))\r\nend\r\n"}, {"source_code": "\r\nt = gets.chomp.to_i \r\ntab = []\r\nfor i in 1..t \r\n \r\n a, b , c = gets.chomp.split(' ').map(&:to_i)\r\n \r\n\r\n if ( (a-1).abs ) < ((b-c).abs + (c-1).abs)\r\n tab.push(1)\r\n elsif ( (a-1).abs ) > ((b-c).abs + (c-1).abs)\r\n tab.push(2)\r\n else \r\n tab.push(3)\r\n end\r\nend\r\n\r\nfor i in tab\r\n puts \"#{i}\"\r\nend"}], "negative_code": [{"source_code": "c = Hash.new(nil)\r\n$stdin.each_line.with_index do |l, i| next if i == 0 || i % 2 == 1\r\n puts c[l] if c[l] != nil\r\n nt = 0\r\n o = \"\"\r\n l.chomp.each_char.with_index do |x, i|\r\n if nt != 0\r\n nt -= 1\r\n next\r\n end\r\n if (i < (l.chomp.length - 2)) && (l[i + 2] == \"0\") && (i > l.chomp.length - 4 || l[i + 3] != \"0\")\r\n nt = 2\r\n o += (\"a\"..\"z\").to_a[(x + l[i + 1]).to_i - 1]\r\n next\r\n end\r\n o += (\"a\"..\"z\").to_a[x.to_i - 1]\r\n end\r\n c[l]=o\r\n puts o\r\nend"}, {"source_code": "\r\ndef debug(*arg)\r\n puts \"[DEBUG] #{arg.join \" \"}\"\r\nend\r\n\r\nt = gets.to_i\r\n\r\nt.times do\r\n a, b, c = gets.split.map(&:to_i)\r\n\r\n # debug(a, b + c -b)\r\n if a == b + c - b + 1\r\n puts 3\r\n elsif a < b + c - b + 1\r\n puts 1\r\n else\r\n puts 2\r\n end\r\nend\r\n\r\n"}], "src_uid": "aca2346553f9e7b6e944ca2c74bb0b3d"} {"source_code": "n = gets\nn = n.to_i\ncommands = Array.new\nwhile n != 0\n commands << gets\n n -= 1\nend\n@currentpwd = Array.new\n\ncommands.each do |command|\n # puts \"doing command #{command}\"\n command = command.gsub(/\\n/,\"\")\n if command == 'pwd'\n if @currentpwd.any?\n p = \"\"\n @currentpwd.each do |path|\n p += \"/\"\n p += path\n end\n puts p + \"/\"\n else\n puts '/'\n end\n else\n precommand = command.split(\" \")\n precommand = precommand[1].split(\"/\")\n # puts \"splitting #{precommand}\"\n precommand.each do |dir|\n if dir == \"\"\n @currentpwd = Array.new\n else\n if dir == \"..\"\n if @currentpwd.any?\n @currentpwd = @currentpwd.slice(0, @currentpwd.length-1)\n end\n # puts \"her #{@currentpwd}\"\n else\n @currentpwd << dir\n end\n end\n end\n # puts \"current dir #{@currentpwd}\"\n end\nend\n\n# p @currentpwd", "positive_code": [{"source_code": "n = gets.to_i\ndir = \"/\"\nn.times do\n s = gets.chomp\n if s == \"pwd\"\n puts dir\n next\n end\n dir = \"\" if s[3] == \"/\"\n dir += s[3, s.size - 1] + \"/\"\n while dir.sub!(/\\/\\w+\\/\\.\\.\\//, \"/\")\n end\nend"}, {"source_code": "n = gets.to_i\ndir = \"/\"\nn.times do\n s = gets.chomp\n if s == \"pwd\"\n puts dir\n next\n end\n dir = \"\" if s[3] == \"/\"\n dir += s[3, s.size - 1] + \"/\"\n while dir.sub!(\"//\", \"/\")\n end\n while dir.sub!(/\\w+\\/\\.\\./, \"/\")\n while dir.sub!(\"//\", \"/\")\n end\n end\nend"}, {"source_code": "n, dir = gets.to_i, []\nn.times do\n cmd, arg = gets.chomp.split\n if cmd == 'pwd'\n puts '/' + (dir.any? ? dir.join('/') + '/' : '')\n else\n dir = arg[0] == '/' ? arg.split('/') : dir + arg.split('/')\n dir.delete('')\n while i = dir.find_index('..') do\n 2.times{ dir.delete_at i-1 }\n end\n end\nend\n"}, {"source_code": "class Directory\n attr_reader :parent\n def initialize(name, parent)\n @name = name\n @parent = parent\n end\n def pwd\n return \"/\" if @parent == nil\n return @parent.pwd + @name + \"/\"\n end\nend\n\nn = gets.to_i\ncurrent = Directory.new(\"\", nil)\n\nn.times do\n command = gets.split(/[\\s\\/]/)\n if command[0] == \"pwd\"\n puts current.pwd\n else\n for i in command.drop(1)\n if i == \"..\"\n current = current.parent\n elsif i == \"\"\n current = Directory.new(\"\", nil)\n else\n current = Directory.new(i, current)\n end\n end\n end\nend"}, {"source_code": "p='/'\ngets.to_i.times{|_|\ngets\n/cd /?(p=File.expand_path($'.chop,p)):puts((p[/(\\/\\w+)+/]||'')+'/')\n}\n\n"}, {"source_code": "n = gets.to_i;\ncommands = (1..n).map { gets.chomp }\ndirs = []\ncd = []\nfor line in commands\n if line =~ /^pwd/\n pwd = \"/\"\n cd.each { |dir| pwd += dir + \"/\"}\n puts pwd\n elsif line =~ /^cd/\n line.sub!(/^cd\\s+/, '')\n if line.start_with? \"/\"\n cd.clear\n end\n line.gsub!(/^\\/|\\/$/, '')\n dirs = line.split(\"/\")\n for dir in dirs\n if dir.start_with? \"..\"\n cd.pop\n else\n cd << dir\n end\n end\n end\nend"}, {"source_code": "def pwd (arr_dir)\n if arr_dir.empty?\n puts \"/\"\n else\n puts \"/#{arr_dir.join(\"/\")}/\"\n end\nend\n\ndef cd(arr_dir, command)\n arr_1 = command.split(\" \")\n s = arr_1[1]\n if s.start_with?(\"/\")\n s[0] = \"\"\n arr_dir.clear\n end\n arr_2 = s.split(\"/\")\n arr_2.each { |x| \n if x == \"..\"\n arr_dir.delete_at(-1)\n else \n arr_dir << x\n end\n } \nend\n\ndef main()\n count = gets.chomp\n arr_dir = Array.new\n dir = arr_dir\n for i in 0..count.to_i-1\n command = gets.chomp \n if command.start_with?(\"pwd\")\n pwd(arr_dir)\n elsif command.start_with?(\"cd\")\n cd(arr_dir, command)\n else \n puts \"Error\"\n end\n end\nend\n\nmain"}, {"source_code": "def main()\n count = gets.chomp\n arr_dir = Array.new\n dir = arr_dir\n for i in 0..count.to_i-1\n command = gets.chomp \n if command.start_with?(\"pwd\")\n if arr_dir.empty?\n puts \"/\"\n else\n puts \"/#{arr_dir.join(\"/\")}/\"\n end\n elsif command.start_with?(\"cd\")\n arr_1 = command.split(\" \")\n s = arr_1[1]\n if s.start_with?(\"/\")\n s[0] = \"\"\n arr_dir.clear\n end\n arr_2 = s.split(\"/\")\n arr_2.each { |x| \n if x == \"..\"\n arr_dir.delete_at(-1)\n else \n arr_dir << x\n end\n } \n else \n puts \"Error\"\n end\n end\nend\n\nmain"}, {"source_code": "$n = gets.to_i\n$path = []\n\n\n$n.times do\n cmd = gets.chomp.split ' '\n if cmd[0] == 'pwd' then\n if $path.empty? then\n puts '/'\n else\n puts '/' + $path.join('/') + '/'\n end\n elsif cmd[0] == 'cd' then\n dirs = cmd[1].split '/'\n if cmd[1][0] == '/' then\n $path = []\n dirs.shift\n end\n dirs.each do |dir|\n if dir == '..' then\n $path.pop\n else\n $path.push dir\n end\n end\n end\nend\n\n"}, {"source_code": "path = []\ngets.to_i.times do\n\tcmd, arg = gets.split(/\\s+/)\n\tif cmd == \"pwd\"\n\t\tputs path.inject(\"/\") { |s, i| s += \"#{i}/\" }\n\telse\n\t\tdirs = arg.split(/\\//).drop_while { |s| s == \"\" }\n\t\tpath = [] if arg.start_with? \"/\"\n\t\tdirs.each do |i|\n\t\t\tif i == \"..\"\n\t\t\t\tpath.pop\n\t\t\telse\n\t\t\t\tpath << i\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "n = gets\nmy_stack = []\n\nn.to_i.times do\n command = gets.strip.split(\" \")\n\n if command[0] == \"pwd\"\n my_stack.reject! { |x| x.empty? }\n puts my_stack.size > 0 ? \"/\" + my_stack.join('/') + \"/\" : \"/\"\n elsif command[0] == \"cd\"\n command[1].split(\"/\").each do |step|\n if step != \"..\"\n if step == \"\"\n my_stack = []\n else\n my_stack.push step\n end\n else\n if my_stack.size > 0\n my_stack.pop\n end\n end\n end\n end\nend\n"}, {"source_code": "class NilClass\n def nil_or_empty?\n true\n end\nend\nclass String\n def nil_or_empty?\n empty?\n end\nend\n\n# $stdin = File.open(\"1.txt\")\na = %w(/)\ngets.to_i.times do |j|\n s = gets.strip\n if s == \"pwd\"\n puts a*''\n else\n path = s.split[1].split('/')\n a = %w(/) if path[0].nil_or_empty?\n path.each { |e|\n next if e.nil_or_empty?\n if e == '..'\n a.pop\n else\n a.push(e + \"/\")\n end\n }\n end\nend"}, {"source_code": "l = STDIN.read.split(\"\\n\")\n\nst = []\ncommands = l[1..-1]\n\ncommands.each{ |c|\n if c.start_with?(\"cd\") then\n parts = c.split(\" \")[1].split(\"/\")\n\n if c.split(\" \")[1].start_with?(\"/\")\n st.clear\n end\n \n parts.each{ |part|\n if part == \"..\" then\n st.pop\n else\n if part != \"\" then st.push(part) end\n end\n }\n end\n \n if c.start_with?(\"pwd\") then\n puts (st.count >= 1 ? '/' : '') + st.join('/') + '/'\n end\n}"}, {"source_code": "input = STDIN.read.split(\"\\n\")\ninput_num = input.shift.to_i\n\n$tree = {\n\t'/' => nil\n}\n\n$pwd = '/'\n\ndef add_dir dir\n\tif $pwd == '/'\n\t\tif $tree['/'] == nil\n\t\t\t$tree['/'] = {dir => nil}\n\t\telse\n\t\t\t$tree['/'].merge!({dir => nil})\n\t\tend\n\telse\n\t\ttree = $pwd.split('/')\n\t\ttree[0] = '/'\n\t\ttree.inject($tree) do |acc, value|\n\t\t\tif acc[value] == nil\n\t\t\t\tacc[value] = {$dir => nil}\n\t\t\telse\n\t\t\t\tacc[value].merge!({dir => nil})\n\t\t\tend\n\t\tend\n\tend\n\tif $pwd == '/'\n\t\t$pwd += dir\n\telse\n\t\t$pwd += '/' + dir\n\tend\nend\n\ninput.each do |str|\n\tif str == 'pwd'\n\t\tif $pwd == '/'\n\t\t\tSTDOUT.puts '/'\n\t\telse\n\t\t\tSTDOUT.puts $pwd + '/'\n\t\tend\n\telse\n\t\tdirs = str[3..-1].split('/')\n\t\tdirs.each do |dir|\n\t\t\tif dir == \"\"\n\t\t\t\t$pwd = '/'\n\t\t\telsif dir != '..'\n\t\t\t\tadd_dir dir\n\t\t\telse\n\t\t\t\t$pwd = $pwd.split('/')\n\t\t\t\t$pwd.pop\n\t\t\t\t$pwd = $pwd.join('/')\n\t\t\t\t$pwd = '/' if $pwd == ''\n\t\t\tend\n\t\tend\n\tend\nend"}, {"source_code": "i = gets.chomp.to_i\n\n\ncurr_dir = '/'\ni.times do\n cmd = gets.chomp\n\n if cmd == 'pwd'\n puts curr_dir\n else\n cmd.sub('cd ', '').split('/').each do |c|\n if c == ''\n curr_dir = '/'\n elsif c == '..'\n curr_dir = curr_dir[0..(curr_dir.length-2)]\n curr_dir = curr_dir[0..curr_dir.rindex('/')]\n else\n curr_dir << c\n curr_dir << '/' if curr_dir[-1] != '/'\n end\n end\n end\nend"}, {"source_code": "n = gets.chomp.to_i\ncurrent_dir = [\"\"]\nn.times do\n inp = gets.chomp.split(' ')\n cmd = inp[0]\n if cmd == 'pwd'\n current_dir.each do |d|\n print \"#{d}/\"\n end\n print \"\\n\"\n else\n args = inp[1]\n if args[0...1] == '/'\n # puts 'nonone';\n current_dir = []\n end\n args.split('/').each do |arg|\n if arg == '..'\n current_dir.pop\n else\n current_dir.push arg\n end\n end\n end\nend"}, {"source_code": "p='/'\ngets.to_i.times{|_|\ngets\n/cd /?(p=File.expand_path($'.chop,p)):puts((p[/(\\/\\w+)+/]||'')+'/')\n}\n\n"}, {"source_code": "class Node\n attr_accessor :element, :parent, :children\n\n def initialize(element, parent)\n @element = element\n @parent = parent\n @children = []\n end\nend\n\nn = gets.strip.to_i\nroot = Node.new(\"/\", nil)\ncurrent_node = root\ncommands = []\nn.times do \n commands.push(gets.strip)\nend\n \ndef print_current_path(current_node)\n path = ['/']\n # p current_node\n # if current_node.element == '/'\n # path.push('/')\n # else\n while !(current_node.element == '/')\n path.unshift(current_node.element)\n current_node = current_node.parent\n path.unshift(\"/\")\n end\n # end\n puts path.join\nend\n\nputs \"\\n\"\ncommands.each do |command| \n if command == 'pwd'\n print_current_path(current_node)\n elsif command =~ /cd/\n path = command.split(\" \").last\n if path[0] == '/'\n current_node = root\n path = path[1..-1]\n end\n directories = path.split(\"/\")\n directories.each do |dir|\n if dir == '..'\n current_node = current_node.parent\n else\n new_node = Node.new(dir, current_node)\n if !current_node.children.include?(new_node)\n current_node.children.push(new_node)\n end\n current_node = new_node\n end\n end\n end\nend\n"}, {"source_code": "_ = STDIN.readline\nlines = STDIN.readlines.map(&:chomp)\n\n@path = []\n\ndef pwd\n puts '/' + (@path.size > 0 ? (@path.join('/') + '/') : '')\nend\n\nlines.each do |l|\n if l == 'pwd'\n pwd\n next\n end\n\n _, dir = l.split(' ')\n if dir[0] == '/'\n dir = dir[1..-1]\n @path = []\n end\n\n comps = dir.split('/')\n comps.each do |c|\n if c == '..'\n @path.pop\n else\n @path.push(c)\n end\n end\nend\n"}, {"source_code": "n = STDIN.readline.to_i\n\nnow = []\nfor i in 1..n do\n line = STDIN.readline.strip\n vc = line.split(/[ \\/]+/)\n len = vc.size\n \n #puts \"R: \" + vc.inspect\n if(vc.first == \"cd\")\n now = [] if line[3] == '/'\n vc[1..len].each do |cmd|\n if cmd == \"..\"\n now.pop\n else\n now << cmd\n end\n end\n else\n res = \"/\"+ now.join(\"/\")\n res = res + \"/\" if(res != \"/\")\n \n puts res\n end\nend\n"}, {"source_code": "p='/'\ngets.to_i.times{|_|\ngets\n/cd /?(p=File.expand_path($'.chop,p)):puts((p[/(\\/\\w+)+/]||'')+'/')\n}\n\n"}, {"source_code": "p='/'\ngets.to_i.times{|_|\ngets\n/cd /?(p=File.expand_path($'.chop,p)):puts((p[/(\\/\\w+)+/]||'')+'/')\n}\n\n"}, {"source_code": "counter = gets.chomp.to_i\ncurrentPath = '/'\n\ncounter.times do\n command = gets.chomp\n command = command.split(' ')\n\n if command[0] == 'pwd'\n if currentPath == '/'\n puts currentPath\n else\n puts currentPath + '/'\n end\n else #cd\n elements = command[1].split('/')\n\n elements.each { |element|\n\n case element\n when ''\n currentPath = ''\n when '..'\n dirs = currentPath.split('/')\n currentPath = ''\n for counter in 1 .. dirs.length-2\n currentPath += '/' + dirs[counter]\n end\n else\n if currentPath == '/'\n currentPath += element\n else\n currentPath += '/' + element\n end\n end\n }\n end\n\nend"}, {"source_code": "commands = STDIN.readlines.map(&:chomp).drop(1)\ncommands.inject([]){|current_dir, c|\n case c\n when /^pwd/\n puts ([\"\"] + current_dir + [\"\"]).join(\"/\")\n when /^cd /\n params = c.sub(/^cd /){\"\"}.split(\"/\")\n if params[0] == \"\"\n current_dir.clear\n params.shift\n end\n params.each{|d|\n if d == \"..\"\n current_dir.pop\n else\n current_dir.push(d)\n end\n }\n end\n current_dir\n}\n"}, {"source_code": "p='/'\ngets.to_i.times{|_|\ngets\n/cd /?(p=File.expand_path($'.chop,p)):puts((p[/(\\/\\w+)+/]||'')+'/')\n}"}, {"source_code": "require 'pp'\ndef s(str)\n split = str.split(\"/\")\n p = []\n for s in split\n if(s == '..')\n p.pop\n else\n p.push(s)\n end\n end\n r = p.join(\"/\")\n if r == ''\n r = '/'\n end\n return r.gsub('//','/')\nend\n\nstr = STDIN.read.split(\"\\n\").drop(1)\n\ncur_path = '/'\nfor s in str\n s.strip!\n next if s == ''\n \n if(s == 'pwd')\n cur_path = s(cur_path) \n puts (cur_path + '/').gsub('//','/')\n else\n match = s.match(/cd (.*)/)\n path = match[1]\n if path[0] == '/'\n cur_path = path\n else\n cur_path += '/' + path\n end\n end\nend"}, {"source_code": "$n = gets.to_i\n$path = []\n\n$n.times do\n cmd = gets.chomp.split ' '\n if cmd[0] == 'pwd' then\n if $path.empty? then\n puts '/'\n else\n puts '/' + $path.join('/') + '/'\n end\n elsif cmd[0] == 'cd' then\n dirs = cmd[1].split '/'\n if cmd[1][0] == '/' then\n $path = []\n dirs.shift\n end\n dirs.each do |dir|\n if dir == '..' then\n $path.pop\n else\n $path.push dir\n end\n end\n end\nend\n"}, {"source_code": "i = gets.to_i\ncurrent = ''\noutput = \"\"\ni.times do \n cmd, param = gets.chomp.split(' ')\n if current.empty?\n c = ''\n else\n c = '/'\n end\n output << \"#{c}\" + current + \"/\\n\" if cmd == 'pwd'\n\n if cmd == 'cd'\n if param[0] == '/'\n current = ''\n param = param[1..-1]\n end\n\n param = param.split('/')\n current = current.split('/')\n until param.empty? do\n p = param.shift\n if p == '..'\n current.pop\n else\n current.push(p)\n end\n end\n current = current.join('/')\n end\nend\n\nprint output\n"}, {"source_code": "def cleanup_path(path)\n\ttmp = []\n\tpath.each do |el|\n\t\tif el == \"..\"\n\t\t\ttmp = tmp[0..-2]\n\t\telse\n\t\t\ttmp += [el]\n\t\tend\n\tend\n\ttmp\nend\n\ndef shell(commands)\n\tstack = []\n\tcommands.each do |cmd|\n\t\tif(cmd == \"pwd\")\n\t\t\tprint(\"/\" + stack.join(\"/\"))\n\t\t\tputs( stack.length > 0 ? \"/\" : \"\")\n\t\telsif cmd[0..2] == \"cd \"\n\t\t\tnew_path = cmd[3..-1].split(\"/\")\n\t\t\tif new_path[0] == \"\"\n\t\t\t\tstack = cleanup_path(new_path[1..-1])\n\t\t\telse\n\t\t\t\tstack = cleanup_path(stack + new_path)\n\t\t\tend\n\t\telse \n\t\t\tputs(\"weird command: #{cmd}\")\n\t\t\tfail\n\t\tend\n\tend\nend\n\nno_lines = STDIN.readline.chomp.to_i\n\n\ncommands = STDIN.readlines.map(&:chomp)\n\n#puts(commands.to_s)\n\nshell(commands)"}, {"source_code": "n=gets.chomp.to_i\ncur=[]\nn.times{\n\ts=gets.chomp.to_s\n\tunless s=~/pwd/\n\t\ti=3\n\t\tif s[i]=='/'\n\t\t\tcur=[]\n\t\t\ti+=1\n\t\tend\n\t\twhile true\n\t\t\tif s[i..-1]=~/^([\\.]{2})\\//\n\t\t\t\tcur.pop()\n\t\t\t\ti+=3\n\t\t\t\tnext\n\t\t\tend\n\t\t\tif s[i..-1]=~/^([^\\/.]*)\\//\n\t\t\t\tj=i+$~[1].size\n\t\t\t\tword=s[i...j]\n\t\t\t\tcur.push(word)\n\t\t\t\ti=j+1\n\t\t\t\tnext\n\t\t\tend\n\t\t\tbreak\n\t\tend\n\t\tif s[i..-1]=~/^([^\\/.]*)$/\n\t\t\tcur.push($~[1])\n\t\telsif s[i..-1]=~/^[\\.]{2}$/\n\t\t\tcur.pop()\n\t\tend\n\telse\n\t\tif cur.size>0\n\t\t\tputs (\"/\"+cur.join(\"/\")+'/')\n\t\telse\n\t\t\tputs '/'\n\t\tend\n\tend\n}"}, {"source_code": "#!/usr/bin/ruby\nstack = []\nn = STDIN.gets.chomp.to_i\nn.times do\n command = STDIN.gets.chomp\n if command == \"pwd\"\n if stack.empty?\n puts \"/\"\n else\n puts \"/\" + stack.join(\"/\") + \"/\"\n end\n else\n path = command[3..command.length]\n if path.start_with?(\"/\")\n stack.clear\n path = path[1..path.length]\n end\n path.split(/\\//).each do |token|\n if token == \"..\"\n stack.pop\n else\n stack.push(token)\n end\n end\n end\nend\n"}, {"source_code": "n = gets.to_i\ncurrent_directory = []\n\n1.upto(n) do |i|\n command = gets.split(' ')\n if command[0] == \"pwd\"\n puts current_directory.empty? ? '/' : '/' + current_directory.join('/') + '/'\n else\n root_path = true if command[1].start_with?('/')\n path = command[1].split('/').delete_if { |e| e == \"\" }\n current_directory.clear if root_path\n path.each { |dir| \n dir=='..' ? current_directory.pop : current_directory<= 1 ? '/' : '') + st.join('/') + '/'\n end\n}"}, {"source_code": "size = gets.chomp.to_i\ncurdir = \"/\"\nout = []\nsize.times {\n str = gets.chomp\n parts = str.split(\" \")\n command = parts[0]\n if command == \"pwd\" then\n out.push curdir\n end\n if command == \"cd\" then\n if parts[1][0] == \"/\" then\n curdir = \"\"\n end\n dirs = parts[1].split(\"/\")\n dirs.each do |x|\n if x == \"..\" \n arr = curdir.split(\"/\")\n arr.pop\n curdir = arr.join(\"/\")\n curdir = curdir + \"/\"\n else\n curdir = curdir + x + \"/\"\n end\n end\n end\n}\nout.each do |x| \n puts x\nend"}, {"source_code": "p='/'\ngets.to_i.times{|_|\ngets\n/cd /?(p=File.expand_path($'.chop,p)):puts((p[/(\\/\\w+)+/]||'')+'/')\n}\n\n"}, {"source_code": "def pwd(path)\n path.each {|e| print \"/\" + e}\n print \"/\\n\"\nend\n\n\nn = gets.to_i\n\nstack = []\n\nn.times do\n command = gets\n com_list = command.split\n if com_list[0] == \"pwd\" then\n pwd(stack)\n else\n dirs = com_list[1].split \"/\"\n dirs.each do |dir|\n if dir == \"..\" then\n stack.pop\n end\n if dir == \"\" then\n stack.clear\n end\n if dir != \"\" and dir != \"..\" then\n stack.push dir\n end\n end\n end\nend"}, {"source_code": "p='/'\ngets.to_i.times{|_|\ngets\n/cd /?(p=File.expand_path($'.chop,p)):puts((p[/(\\/\\w+)+/]||'')+'/')\n}"}, {"source_code": "def pwd(path)\n path.each {|e| print \"/\" + e}\n print \"/\\n\"\nend\n\n\nn = gets.to_i\n\nstack = []\n\nn.times do\n command = gets\n com_list = command.split\n if com_list[0] == \"pwd\" then\n pwd(stack)\n else\n dirs = com_list[1].split \"/\"\n dirs.each do |dir|\n if dir == \"..\" then\n stack.pop\n end\n if dir == \"\" then\n stack.clear\n end\n if dir != \"\" and dir != \"..\" then\n stack.push dir\n end\n end\n end\nend\n"}, {"source_code": "def cd(a,b)\n b=b.split('/')\n if b[0]==\"\" then\n a.clear\n b.delete_at(0)\n end\n for i in 0...b.size do\n if b[i]==\"..\"\n a.delete_at(a.size-1)\n elsif\n a << b[i]\n end\n end\n return a\nend\n\ndef pwd(a)\n for i in 0...a.size do\n print \"/#{a[i]}\"\n end\n puts \"/\"\nend\n\na=[]\ngets.to_i.times do |x|\n com=gets.split\n if com[0]==\"cd\"\n a=cd(a,com[1])\n elsif com[0]==\"pwd\"\n pwd(a)\n end\nend\n"}, {"source_code": "n = gets.to_i\nwd = []\nn.times do\n c = gets.chomp\n if c == 'pwd'\n puts wd.size == 0 ? '/' : \"/#{wd.join(\"/\")}/\"\n else\n c, t = c.split(\" \")\n t = t.split(\"/\")\n if t[0] == ''\n t = t[1..-1] \n wd = []\n end\n t.each do |x|\n if x == '..'\n wd.pop\n else\n wd.push x\n end\n end\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\ndir = []\nn.times{\n cmd = gets.split\n if cmd[0] == 'pwd'\n if dir == []\n puts '/'\n else\n puts ['/', dir.join('/'), '/'].join\n end\n next\n end\n \n if cmd[1][0].to_s == '/'\n dir = []\n cmd[1] = cmd[1][1..-1]\n end\n \n cmd[1].split('/').each{|t|\n if t == '..'\n dir = dir[0..-2]\n else\n dir << t\n end\n }\n}"}, {"source_code": "p='/'\ngets.to_i.times{|_|\ngets\n/cd /?(p=File.expand_path($'.chop,p)):puts((p[/(\\/\\w+)+/]||'')+'/')\n}"}, {"source_code": "n=gets.to_i\n\npwd=\"/\"\n\nn.times{\n\ns=gets.chomp\nif s==\"pwd\"\nprint pwd\nprint \"\\n\"\nelse\nfor i in s.split(' ')[1].split('/')\n\nif i==\"\"\npwd=\"/\"\nelsif i==\"..\"\npwd=pwd.split('/')\npwd.pop\npwd.push \"\"\npwd=pwd.join('/')\nelse\npwd+=i+'/'\nend\n\nend\nend\n\n}"}, {"source_code": "p='/'\ngets.to_i.times{|_|\ngets\n/cd /?(p=File.expand_path($'.chop,p)):puts((p[/(\\/\\w+)+/]||'')+'/')\n}\n\n"}, {"source_code": "n = gets.to_i\ndir = []\nn.times do\n f = gets.chomp\n if f =~ /^pwd$/\n puts \"/\" + dir.join(\"/\") + ( dir.length > 0 ? \"/\" : \"\" )\n else\n f = f.partition(\" \")[2]\n dir.clear if f[0] == \"/\"\n f.split(\"/\").each do |x|\n if x =~ /^\\.\\.$/\n dir.pop\n elsif x.length > 0\n dir << x\n end\n end\n end\nend"}, {"source_code": "def pwd(path)\n if path.empty?\n puts \"/\"\n else\n puts \"/#{path.join '/'}/\"\n end\nend\n\npath = []\nn = gets.to_i\n\nfor str in STDIN.each_line.take(n)\n arr = str.chomp.split(' ')\n\n if arr.size == 1\n pwd path\n else\n path.clear if arr[1][0] == '/'\n p = arr[1].split('/').reject &:empty?\n p.each { |t| (t == '..') ? path.pop : path.push(t) }\n end\nend"}, {"source_code": "p='/'\ngets.to_i.times{|_|\ngets\n/cd /?(p=File.expand_path($'.chop,p)):puts((p[/(\\/\\w+)+/]||'')+'/')\n}\n"}, {"source_code": "current_path = []\n\nn = gets.to_i\nn.times do\n s = gets.strip\n if s == 'pwd'\n answer = '/' + current_path.join('/')\n answer += '/' unless current_path.empty?\n puts answer\n else\n path = s.split.last.split('/')\n absolute = path.first == ''\n if absolute\n current_path = path\n path.shift\n else\n current_path += path\n end\n\n while index = current_path.index('..')\n current_path.delete_at(index)\n current_path.delete_at(index-1)\n end\n end\nend\n"}, {"source_code": "gets\ns=?/\n$<.map{|i|(i=i.split[1])?(i.sub!(/^\\//){s=?/\np}\n(i.sub!(/^(\\w+).?/){s<<$1+?/\np}||(i=i[3..-1]||\"\"\ns[/\\w+.$/]\ns=$`))while\"\" nil\n}\n\n$pwd = '/'\n\ndef add_dir dir\n\n\tif $pwd == '/'\n\n\t\tif $tree['/'] == nil\n\n\t\t\t$tree['/'] = {dir => nil}\n\n\t\telse\n\n\t\t\t$tree['/'].merge!({dir => nil})\n\n\t\tend\n\n\telse\n\n\t\ttree = $pwd.split('/')\n\n\t\ttree[0] = '/'\n\n\t\ttree.inject($tree) do |acc, value|\n\n\t\t\tif acc[value] == nil\n\t\t\t\tacc[value] = {$dir => nil}\n\t\t\telse\n\t\t\t\tacc[value].merge!({dir => nil})\n\t\t\tend\n\n\t\tend\n\n\tend\n\t\n\tif $pwd == '/'\n\t\t$pwd += dir\n\telse\n\t\t$pwd += '/' + dir\n\tend\n\nend\n\ninput.each do |str|\n\n\tif str == 'pwd'\n\t\tif $pwd == '/'\n\t\t\tSTDOUT.puts '/'\n\t\telse\n\t\t\tSTDOUT.puts $pwd + '/'\n\t\tend\n\telse\n\n\t\tdirs = str[3..-1].split('/')\n\n\t\tdirs.each do |dir|\n\n\t\t\tif dir == \"\"\n\n\t\t\t\t$pwd = '/'\n\n\t\t\telsif dir != '..'\n\n\t\t\t\tadd_dir dir\n\n\t\t\telse\n\n\t\t\t\t$pwd = $pwd.split('/')\n\t\t\t\t$pwd.pop\n\t\t\t\t$pwd = $pwd.join('/')\n\n\t\t\t\t$pwd = '/' if $pwd == ''\n\n\t\t\tend\n\n\t\tend\n\tend\n\nend"}, {"source_code": "p='/'\ngets.to_i.times{|_|\ngets\n/cd /?(p=File.expand_path($'.chop,p)):puts((p[/(\\/\\w+)+/]||'')+'/')\n}\n\n"}, {"source_code": "n = gets.to_i\ndir = \"/\"\nn.times do\n s = gets.chomp\n if s == \"pwd\"\n puts dir\n next\n end\n dir = \"\" if s[3] == \"/\"\n dir += s[3, s.size - 1]\n dir += \"/\" if s[-1] != \"/\"\n while dir.sub!(/\\/\\w+\\/\\.\\.\\//, \"/\")\n end\nend"}], "negative_code": [{"source_code": "p = '/'\ngets.to_i.times do |_|\n gets\n if /cd /\n p = File.expand_path($'.chop, p);\n else\n puts p == '/' ? p : p + '/'\n end\nend\n"}, {"source_code": "p = '/'\ngets.to_i.times do |_|\n gets\n if /cd /\n p = File.expand_path($'.chop, p);\n else\n puts $& + '/' if p =~ /(\\/\\w+)*/\n end\nend\n"}, {"source_code": "n=gets.to_i\npwd=\"/\"\nn.times do\n a=gets.split\n if a[0]=='pwd' then\n puts pwd\n else\n if a[1][0]==\"/\" then\n pwd=a[1]\n if pwd[pwd.length-1]!=\"/\" then\n pwd+=\"/\"\n end\n else\n path=a[1].split(\"/\")\n path.each{|k|\n if k!=\"..\" then\n pwd=pwd+k+\"/\"\n else\n pwd=pwd[0..(pwd.length-2)]\n while pwd[pwd.length-1]!=\"/\"\n pwd=pwd[0..(pwd.length-2)]\n end\n end\n }\n end\n end\nend"}, {"source_code": "n = gets.to_i\ndir = \"/\"\nn.times do\n s = gets.chomp\n if s == \"pwd\"\n puts dir\n next\n end\n dir += s[3, s.size - 1] + \"/\"\n while dir.sub!(\"//\", \"/\")\n end\n while dir.sub!(/\\w+\\/\\.\\./, \"/\")\n end\n while dir.sub!(\"//\", \"/\")\n end\nend"}, {"source_code": "n = gets.to_i\ndir = \"/\"\nn.times do\n s = gets.chomp\n if s == \"pwd\"\n puts dir\n next\n end\n dir += s[3, s.size - 1] + \"/\"\n while dir.sub!(\"//\", \"/\")\n end\n while dir.sub!(/\\w+\\/\\.\\./, \"/\")\n while dir.sub!(\"//\", \"/\")\n end\n end\nend"}, {"source_code": "def main()\n count = gets.chomp\n arr_dir = Array.new\n dir = arr_dir\n for i in 0..count.to_i-1\n command = gets.chomp \n if command.start_with?(\"pwd\")\n if arr_dir.empty?\n puts \"/\"\n else\n puts \"/#{arr_dir.join(\"/\")}/\"\n end\n elsif command.start_with?(\"cd\")\n arr_1 = command.split(\" \")\n s = arr_1[1]\n if s.start_with?(\"/\")\n s[0] = \"\"\n end\n arr_2 = s.split(\"/\")\n arr_2.each { |x| \n if x == \"..\"\n arr_dir.delete_at(-1)\n else \n arr_dir << x\n end\n } \n else \n puts \"Error\"\n end\n end\nend\n\nmain"}, {"source_code": "def main()\n count = gets.chomp\n arr_dir = Array.new\n dir = arr_dir\n for i in 0..count.to_i-1\n command = gets.chomp \n if command.start_with?(\"pwd\")\n puts \"/#{arr_dir.join(\"/\")}/\"\n elsif command.start_with?(\"cd\")\n arr_1 = command.split(\" \")\n s = arr_1[1]\n if s.start_with?(\"/\")\n s[0] = \"\"\n end\n arr_2 = s.split(\"/\")\n arr_2.each { |x| \n if x == \"..\"\n arr_dir.delete_at(-1)\n else \n arr_dir << x\n end\n } \n else \n puts \"Error\"\n end\n end\nend\n\nmain"}, {"source_code": "def main()\n count = gets.chomp\n arr_dir = Array.new\n dir = arr_dir\n for i in 0..count.to_i-1\n command = gets.chomp \n if command.start_with?(\"pwd\")\n puts \"/#{arr_dir.join(\"/\")}\"\n elsif command.start_with?(\"cd\")\n arr_1 = command.split(\" \")\n s = arr_1[1]\n if s.start_with?(\"/\")\n s[0] = \"\"\n end\n arr_2 = s.split(\"/\")\n arr_2.each { |x| \n if x == \"..\"\n arr_dir.delete_at(-1)\n else \n arr_dir << x\n end\n } \n else \n puts \"Error\"\n end\n end\nend\n\nmain"}, {"source_code": "def main()\n count = gets.chomp\n arr_dir = Array.new\n dir = arr_dir\n for i in 0..count.to_i-1\n command = gets.chomp \n if command.start_with?(\"pwd\")\n if arr_dir.empty?\n puts \"/\"\n else\n puts \"/#{arr_dir.join(\"/\")}/\"\n end\n elsif command.start_with?(\"cd\")\n arr_1 = command.split(\" \")\n s = arr_1[1]\n if s.start_with?(\"/\")\n s[0] = \"\"\n arr_dir.delete_at(-1)\n end\n arr_2 = s.split(\"/\")\n arr_2.each { |x| \n if x == \"..\"\n arr_dir.delete_at(-1)\n else \n arr_dir << x\n end\n } \n else \n puts \"Error\"\n end\n end\nend\n\nmain"}, {"source_code": "path = []\ngets.to_i.times do\n\tcmd, arg = gets.split(/\\s+/)\n\tif cmd == \"pwd\"\n\t\tputs path.inject(\"/\") { |s, i| s += \"#{i}/\" }\n\telse\n\t\tdirs = arg.split(/\\//).drop_while { |s| s == \"\" }\n\t\tif arg.start_with? \"/\"\n\t\t\tpath = dirs\n\t\telse\n\t\t\tdirs.each do |i|\n\t\t\t\tif i == \"..\"\n\t\t\t\t\tpath.pop\n\t\t\t\telse\n\t\t\t\t\tpath << i\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "n = gets\nmy_stack = []\n\nn.to_i.times do\n command = gets.strip.split(\" \")\n\n if command[0] == \"pwd\"\n my_stack.reject! { |x| x.empty? }\n puts my_stack.size > 0 ? \"/\" + my_stack.join('/') + \"/\" : \"/\"\n elsif command[0] == \"cd\"\n command[1].split(\"/\").each do |step|\n if step != \"..\"\n if step[0] == \"/\"\n my_stack = []\n my_stack.push step[1..-1]\n else\n my_stack.push step\n end\n else\n if my_stack.size > 0\n my_stack.pop\n end\n end\n end\n end\nend\n"}, {"source_code": "def change_path(source, command = Array)\n\tresult = source\n\tfor i in 0..(command.size-1)\n\t\tif (command[i] != \"\")\n\t\t\tif (command[i] == \"..\")\n\t\t\t\tnew_source = source[0..-2]\n\t\t\t\tslash_position = new_source.rindex(\"/\")\n\t\t\t\tresult = result[0..slash_position]\n\t\t\telse\n\t\t\t\tresult = \"#{result}#{command[i].to_s}/\"\n\t\t\tend\n\t\tend\n\tend\n\treturn result\nend\n\npath = \"/\"\nl = STDIN.read.split(\"\\n\")\nn = l[0].to_i\ncommands = Array.new\nfor i in 1..(n)\n\tcommands[i-1] = l[i]\n\tif (l[i] == \"pw\")\n\t\tputs \"#{path}\"\n\telsif (l[i][0,2] == \"cd\")\n\t\tnew_string = l[i]\n\t\tnew_string.slice! \"cd \"\n\t\tnew_command = Array.new\n\t\tnew_command = new_string.split('/')\n\t\tnew_path = change_path(path, new_command)\n\t\tpath = new_path\n\tend\nend"}, {"source_code": "def change_path(source, command = Array)\n\tresult = source\n\tfor i in 0..(command.size-1)\n\t\tif (command[i] != \"\")\n\t\t\tif (command[i] == \"..\")\n\t\t\t\tpathes = Array.new\n\t\t\t\tpathes = source.split('/')\n\t\t\t\tpathes.slice!(-1)\n\t\t\t\tresult = pathes * \"/\"\n\t\t\t\tresult = \"#{result}/\"\n\t\t\telse\n\t\t\t\tresult = \"#{result}#{command[i].to_s}/\"\n\t\t\tend\n\t\tend\n\tend\n\treturn result\nend\n\npath = \"/\"\nl = STDIN.read.split(\"\\n\")\nn = l[0].to_i\ncommands = Array.new\nfor i in 1..(n)\n\tcommands[i-1] = l[i]\n\tif (l[i] == \"pwd\")\n\t\tputs \"#{path}\"\n\telsif (l[i][0,2] == \"cd\")\n\t\tnew_string = l[i]\n\t\tnew_string.slice! \"cd \"\n\t\tnew_command = Array.new\n\t\tnew_command = new_string.split('/')\n\t\tnew_path = change_path(path, new_command)\n\t\tpath = new_path\n\tend\nend"}, {"source_code": "def change_path(source, command = Array)\n\tresult = source\n\tfor i in 0..(command.size-1)\n\t\tif (command[i] != \"\")\n\t\t\tif (command[i] == \"..\")\n\t\t\t\tnew_source = source[0..-2]\n\t\t\t\tslash_position = new_source.rindex(\"/\")\n\t\t\t\tresult = result[0..slash_position]\n\t\t\telse\n\t\t\t\tresult = \"#{result}#{command[i].to_s}/\"\n\t\t\tend\n\t\tend\n\tend\n\treturn result\nend\n\npath = \"/\"\nl = STDIN.read.split(\"\\n\")\nn = l[0].to_i\ncommands = Array.new\nfor i in 1..(n)\n\tcommands[i-1] = l[i]\n\tif (l[i] == \"pwd\")\n\t\tputs \"#{path}\"\n\telsif (l[i][0,2] == \"cd\")\n\t\tnew_string = l[i]\n\t\tnew_string.slice! \"cd \"\n\t\tnew_command = Array.new\n\t\tnew_command = new_string.split('/')\n\t\tnew_path = change_path(path, new_command)\n\t\tpath = new_path\n\tend\nend"}, {"source_code": "n = gets.to_i\n\np = \"/\"\n\nn.times do\n s = gets.chomp\n if s == 'pwd'\n puts p\n else\n s.gsub!(/cd /, '')\n if s[0] == '/'\n p = String.new(s)\n else\n p += s\n end\n p+= '/'\n p.gsub!(/\\w*\\/\\.\\.\\//,'')\n end\nend"}, {"source_code": "n = gets.chomp.to_i\ncurrent_dir = [\"\"]\nn.times do\n inp = gets.chomp.split(' ')\n cmd = inp[0]\n if cmd == 'pwd'\n current_dir.each do |d|\n print \"#{d}/\"\n end\n print \"\\n\"\n else\n args = inp[1]\n if args[0...1] == '/'\n puts 'nonone';\n current_dir = []\n end\n args.split('/').each do |arg|\n if arg == '..'\n current_dir.pop\n else\n current_dir.push arg\n end\n end\n end\nend"}, {"source_code": "class Node\n attr_accessor :element, :parent, :children\n\n def initialize(element, parent)\n @element = element\n @parent = parent\n @children = []\n end\nend\n\nn = gets.strip.to_i\nroot = Node.new(\"/\", nil)\ncurrent_node = root\ncommands = []\nn.times do \n commands.push(gets.strip)\nend\n \ndef print_current_path(current_node)\n path = []\n # p current_node\n if current_node.element == '/'\n path.push('/')\n else\n while !(current_node.element == '/')\n path.unshift(current_node.element)\n current_node = current_node.parent\n path.unshift(\"/\")\n end\n end\n puts path.join\nend\n\nputs \"\\n\"\ncommands.each do |command| \n if command == 'pwd'\n print_current_path(current_node)\n elsif command =~ /cd/\n path = command.split(\" \").last\n if path[0] == '/'\n current_node = root\n path = path[1..-1]\n end\n directories = path.split(\"/\")\n directories.each do |dir|\n if dir == '..'\n current_node = current_node.parent\n else\n new_node = Node.new(dir, current_node)\n if !current_node.children.include?(new_node)\n current_node.children.push(new_node)\n end\n current_node = new_node\n end\n end\n end\nend\n"}, {"source_code": "_ = STDIN.readline\nlines = STDIN.readlines.map(&:chomp)\n\n@path = []\n\ndef pwd\n puts '/' + (@path.size > 0 ? (@path.join('/') + '/') : '')\nend\n\nlines.each do |l|\n if l == 'pwd'\n pwd\n next\n end\n\n _, dir = l.split(' ')\n if dir[0] == '/'\n @path = dir[1..-1].split('/')\n else\n comps = dir.split('/')\n comps.each do |c|\n if c == '..'\n @path.pop\n else\n @path.push(c)\n end\n end\n end\nend\n"}, {"source_code": "_ = STDIN.readline\nlines = STDIN.readlines.map(&:chomp)\n\n@path = []\n\ndef pwd\n puts '/' + (@path.size > 0 ? (@path.join('/') + '/') : '')\nend\n\nlines.each do |l|\n if l == 'pwd'\n pwd\n next\n end\n\n _, dir = l.split(' ')\n if dir[0] == '/'\n dir = dir[1..-1]\n end\n\n comps = dir.split('/')\n comps.each do |c|\n if c == '..'\n @path.pop\n else\n @path.push(c)\n end\n end\nend\n"}, {"source_code": "n = STDIN.readline.to_i\n\nnow = []\nfor i in 1..n do\n line = STDIN.readline.strip\n vc = line.split(/[ \\/]+/)\n len = vc.size\n \n #puts \"R: \" + vc.inspect\n if(vc.first == \"cd\")\n if line[3] == '/'\n now = vc[1..len]\n else\n vc[1..len].each do |cmd|\n if cmd == \"..\"\n now.pop\n else\n now << cmd\n end\n end\n end\n else\n res = \"/\"+ now.join(\"/\")\n res = res + \"/\" if(res != \"/\")\n \n puts res\n end\nend\n"}, {"source_code": "counter = gets.chomp.to_i\ncurrentPath = '/'\n\ncounter.times do\n command = gets.chomp\n command = command.split(' ')\n\n if command[0] == 'pwd'\n if currentPath == '/'\n puts currentPath\n else\n puts currentPath + '/'\n end\n else #cd\n elements = command[1].split('/')\n\n elements.each { |element|\n\n case element\n when ''\n currentPath = ''\n when '..'\n dirs = currentPath.split('/')\n currentPath = ''\n for counter in 1 .. dirs.length-2\n currentPath += '/' + dirs[counter]\n end\n else\n currentPath += '/' + element\n end\n }\n end\n\nend"}, {"source_code": "require 'pp'\ndef s(str)\n split = str.split(\"/\")\n p = []\n for s in split\n if(s == '..')\n p.pop\n else\n p.push(s)\n end\n end\n r = p.join(\"/\")\n if r == ''\n r = '/'\n end\n return r\nend\n\nstr = STDIN.read.split(\"\\n\").drop(1)\n\ncur_path = '/'\nfor s in str\n s.strip!\n next if s == ''\n \n if(s == 'pwd')\n cur_path = s(cur_path)\n puts cur_path + '/' if(cur_path[-1] != '/')\n puts cur_path if cur_path[-1] == '/'\n else\n match = s.match(/cd (.*)/)\n path = match[1]\n if path[0] == '/'\n cur_path = path\n else\n cur_path += '/' + path\n end\n end\nend"}, {"source_code": "require 'pp'\ndef s(str)\n split = str.split(\"/\")\n p = []\n for s in split\n if(s == '..')\n p.pop\n else\n p.push(s)\n end\n end\n r = p.join(\"/\")\n if r == ''\n r = '/'\n end\n return r\nend\n\nstr = STDIN.read.split(\"\\n\").drop(1)\n\ncur_path = '/'\nfor s in str\n s.strip!\n next if s == ''\n \n if(s == 'pwd')\n cur_path = s(cur_path)\n puts cur_path\n else\n match = s.match(/cd (.*)/)\n path = match[1]\n if path[0] == '/'\n cur_path = path\n else\n cur_path += '/' + path\n end\n end\nend"}, {"source_code": "n = gets.to_i\n$cur = []\n\ndef docd(path)\n dirs = path.split('/')\n if path[0] == '/' then cur = [] end\n dirs.each do |dir|\n if dir == '..' then\n $cur.pop \n else\n $cur.push dir\n end\n end\nend\n\nn.times do\n cmd = gets.chomp\n if cmd == 'pwd' then\n puts($cur.join('/') + '/')\n else\n docd(cmd.split(' ')[1])\n end\nend\n"}, {"source_code": "$n = gets.to_i\n$path = []\n\n$n.times do\n cmd = gets.chomp.split ' '\n if cmd[0] == 'pwd' then\n puts $path.join('/') + '/'\n elsif cmd[0] == 'cd' then\n dirs = cmd[1].split '/'\n if cmd[1][0] == '/' then $path = [] end\n dirs.each do |dir|\n if dir == '..' then\n $path.pop\n else\n $path.push dir\n end\n end\n end\nend\n"}, {"source_code": "$n = gets.to_i\n$path = []\n\n$n.times do\n cmd = gets.chomp.split ' '\n if cmd[0] == 'pwd' then\n puts $path.join('/') + '/'\n elsif cmd[0] == 'cd' then\n dirs = cmd[1].split '/'\n dirs.each do |dir|\n if dir == '..' then\n $path.pop\n else\n $path.push dir\n end\n end\n end\nend\n"}, {"source_code": "i = gets.to_i\ncurrent = ''\noutput = \"\"\ni.times do \n cmd, param = gets.chomp.split(' ')\n output << '/' + current + \"\\n\" if cmd == 'pwd'\n\n if cmd == 'cd'\n if param[0] == '/'\n current = param[1..-1]\n else\n param = param.split('/')\n current = current.split('/')\n until param.empty? do \n p = param.shift\n if p == '..'\n current.pop\n else\n current.push(p)\n end\n end\n current = current.join('/')\n end\n end\n\nend\n print output"}, {"source_code": "i = gets.to_i\ncurrent = ''\noutput = \"\"\ni.times do \n cmd, param = gets.chomp.split(' ')\n output << '/' + current + \"\\n\" if cmd == 'pwd'\n\n if cmd == 'cd'\n if param[0] == '/'\n current = param[1..-1]\n else\n param = param.split('/')\n current = current.split('/')\n until param.empty? do \n p = param.shift\n if p == '..'\n current.pop\n else\n current.push(p)\n end\n end\n current = current.join('/')\n end\n current << '/'\n end\n\nend\n print output"}, {"source_code": "i = gets.to_i\ncurrent = ''\noutput = \"\"\ni.times do \n cmd, param = gets.chomp.split(' ')\n output << '/' + current + \"\\n\" if cmd == 'pwd'\n\n if cmd == 'cd'\n if param[0] == '/'\n current = param\n else\n param = param.split('/')\n current = current.split('/')\n until param.empty? do \n p = param.shift\n if p == '..'\n current.pop\n else\n current.push(p)\n end\n end\n current = current.join('/')\n end\n end\n\nend\n print output"}, {"source_code": "i = gets.to_i\ncurrent = ''\noutput = \"\"\ni.times do \n cmd, param = gets.chomp.split(' ')\n output << '/' + current + \"/\\n\" if cmd == 'pwd'\n\n if cmd == 'cd'\n if param[0] == '/'\n current = param[1..-1]\n else\n param = param.split('/')\n current = current.split('/')\n until param.empty? do \n p = param.shift\n if p == '..'\n current.pop\n else\n current.push(p)\n end\n end\n current = current.join('/')\n end\n end\n\nend\n print output"}, {"source_code": "i = gets.to_i\ncurrent = '/'\noutput = \"\"\ni.times do \n cmd, param = gets.chomp.split(' ')\n output << current + \"\\n\" if cmd == 'pwd'\n\n if cmd == 'cd'\n if param[0] == '/'\n current = ''\n param = param[1..-1]\n end\n\n param = param.split('/')\n current = current.split('/')\n until param.empty? do\n p = param.shift\n if p == '..'\n current.pop\n current << '/'\n else\n current.push(p + '/')\n end\n end\n current = current.join.insert(0,'/')\n current.gsub!('//','/')\n end\nend\n\nprint output\n \n"}, {"source_code": "i = gets.to_i\ncurrent = ''\noutput = \"\"\ni.times do \n cmd, param = gets.chomp.split(' ')\n output << '/' + current + \"\\n\" if cmd == 'pwd'\n\n if cmd == 'cd'\n if param[0] == '/'\n current = ''\n param = param[1..-1]\n end\n\n param = param.split('/')\n current = current.split('/')\n until param.empty? do\n p = param.shift\n if p == '..'\n current.pop\n else\n current.push(p)\n end\n end\n current = current.join('/') << '/'\n end\nend\n\nprint output"}, {"source_code": "i = gets.to_i\ncurrent = ''\noutput = \"\"\ni.times do \n cmd, param = gets.chomp.split(' ')\n output << '/' + current + \"\\n\" if cmd == 'pwd'\n\n if cmd == 'cd'\n if param[0] == '/'\n current = ''\n param = param[1..-1]\n end\n\n param = param.split('/')\n current = current.split('/')\n until param.empty? do\n p = param.shift\n if p == '..'\n current.pop\n else\n current.push(p + '/')\n end\n end\n current = current.join\n end\nend\n\nprint output"}, {"source_code": "i = gets.to_i\ncurrent = ''\noutput = \"\"\ni.times do \n cmd, param = gets.chomp.split(' ')\n output << '/' + current + \"\\n\" if cmd == 'pwd'\n\n if cmd == 'cd'\n if param[0] == '/'\n current = param[1..-1]\n else\n param = param.split('/')\n current = current.split('/')\n until param.empty? do \n p = param.shift\n if p == '..'\n current.pop\n else\n current.push(p)\n end\n end\n current = current.join('/') << '/'\n end\n end\n\nend\n print output"}, {"source_code": "i = gets.to_i\ncurrent = '/'\noutput = \"\"\ni.times do \n cmd, param = gets.chomp.split(' ')\n output << current + \"\\n\" if cmd == 'pwd'\n\n if cmd == 'cd'\n if param[0] == '/'\n current = ''\n param = param[1..-1]\n end\n\n param = param.split('/')\n current = current.split('/')\n until param.empty? do\n p = param.shift\n if p == '..'\n current.pop\n current << '/'\n else\n current.push(p + '/')\n end\n end\n current = current.join.insert(0,'/')\n current.gsub!(/(\\/)\\/+/,'/')\n end\nend\n\nprint output"}, {"source_code": "n=gets.chomp.to_i\ncur=[]\nn.times{\n\ts=gets.chomp.to_s\n\tunless s=~/pwd/\n\t\ti=3\n\t\tif s[i]=='/'\n\t\t\tcur=[]\n\t\t\ti+=1\n\t\tend\n\t\twhile true\n\t\t\tif s[i..-1]=~/^([\\.]{2})\\//\n\t\t\t\tcur.pop()\n\t\t\t\ti+=3\n\t\t\t\tnext\n\t\t\tend\n\t\t\tif s[i..-1]=~/^([^\\/.]*)\\//\n\t\t\t\tj=i+$~[1].size\n\t\t\t\tword=s[i...j]\n\t\t\t\tcur.push(word)\n\t\t\t\ti=j+1\n\t\t\t\tnext\n\t\t\tend\n\t\t\tbreak\n\t\tend\n\t\tif s[i..-1]=~/^([^\\/.]*)$/\n\t\t\tcur.push($~[1])\n\t\telsif s[i..-1]=~/^[\\.]{2}$/\n\t\t\tcur.pop()\n\t\tend\n\telse\n\t\tputs (\"/\"+cur.join(\"/\")+'/')\n\tend\n}"}, {"source_code": "n=gets.chomp.to_i\ncur=[]\nn.times{\n\ts=gets.chomp.to_s\n\tunless s=~/pwd/\n\t\ti=3\n\t\tif s[i]=='/'\n\t\t\tcur=[]\n\t\t\ti+=1\n\t\tend\n\t\twhile true\n\t\t\tif s[i..-1]=~/^([\\.]{2})\\//\n\t\t\t\tcur.pop()\n\t\t\t\ti+=3\n\t\t\t\tnext\n\t\t\tend\n\t\t\tif s[i..-1]=~/^([^\\/.]*)\\//\n\t\t\t\tj=i+$~[1].size\n\t\t\t\tword=s[i...j]\n\t\t\t\tcur.push(word)\n\t\t\t\ti=j+1\n\t\t\t\tnext\n\t\t\tend\n\t\t\tbreak\n\t\tend\n\t\tif s[i..-1]=~/^([^\\/.]*)$/\n\t\t\tcur.push($~[1])\n\t\telsif s[i..-1]=~/^[\\.]{2}$/\n\t\t\tcur.pop()\n\t\tend\n\telse\n\t\tputs (\"/\"+cur.join(\"/\"))\n\tend\n}"}, {"source_code": "#!/usr/bin/ruby\nstack = []\nn = STDIN.gets.chomp.to_i\nn.times do\n command = STDIN.gets.chomp\n if command == \"pwd\"\n puts stack.join(\"/\") + \"/\"\n else\n command = command[3..command.length]\n if command.start_with?(\"/\")\n stack.clear\n end\n command.split(/\\//).each do |token|\n if token == \"..\"\n stack.pop\n else\n stack.push(token)\n end\n end\n end\nend\n"}, {"source_code": "n = gets.to_i\ncurrent_directory = []\n\n1.upto(n) do |i|\n command = gets.split(' ')\n\n if command[0] == \"pwd\"\n puts current_directory.empty? ? '/' : current_directory.join('/') + '/'\n else\n path = command[1].split('/')\n if path.length == 0\n current_directory.clear\n else\n path.each { |dir| \n if dir == '..'\n current_directory.pop\n else\n current_directory << dir \n end\n }\n end\n end\n\nend\n"}, {"source_code": "l = STDIN.read.split(\"\\n\")\n\nst = []\ncommands = l[1..-1]\n\ncommands.each{ |c|\n if c.start_with?(\"cd\") then\n parts = c.split(\" \")[1].split(\"/\")\n\n if c.split(\" \")[1].start_with?(\"/\")\n st.clear\n end\n \n parts.each{ |part|\n if part == \"..\" then\n st.pop\n else\n st.push(part)\n end\n }\n end\n \n if c.start_with?(\"pwd\") then\n puts st.join('/') + '/'\n end\n}"}, {"source_code": "l = STDIN.read.split(\"\\n\")\n\nst = []\ncommands = l[1..-1]\n\ncommands.each{|c|\n if c.start_with?(\"cd\") then\n parts = c.split(\" \")[1].split(\"/\")\n\n if c.split(\" \")[1] == \"/\"\n st.clear\n end\n \n parts.each{|part|\n if part == \"..\" then\n st.pop\n else\n st.push(part)\n end\n }\n end\n \n if c.start_with?(\"pwd\") then\n puts (st.count == 1 ? '/' : '') + st.join('/') + '/'\n end\n}"}, {"source_code": "l = STDIN.read.split(\"\\n\")\n\nst = []\ncommands = l[1..-1]\n\ncommands.each{|c|\n if c.start_with?(\"cd\") then\n parts = c.split(\" \")[1].split(\"/\")\n\n if c.split(\" \")[1] == \"/\"\n st.clear\n end\n \n parts.each{|part|\n if part == \"..\" then\n st.pop\n else\n st.push(part)\n end\n }\n end\n \n if c.start_with?(\"pwd\") then\n puts st.join('/') + '/'\n end\n}"}, {"source_code": "l = STDIN.read.split(\"\\n\")\n\nst = []\ncommands = l[1..-1]\n\ncommands.each{|c|\n if c.start_with?(\"cd\") then\n parts = c.split(\" \")[1].split(\"/\")\n \n parts.each{|part|\n if part == \"..\" then\n st.pop\n else\n st.push(part)\n end\n }\n end\n \n if c.start_with?(\"pwd\") then\n puts st.join('/') + '/'\n end\n}"}, {"source_code": "size = gets.chomp.to_i\ncurdir = \"/\"\nsize.times {\n str = gets.chomp\n parts = str.split(\" \")\n command = parts[0]\n if command == \"pwd\" then\n puts curdir\n end\n if command == \"cd\" then\n if parts[1][0] == \"/\" then\n curdir = \"\"\n end\n dirs = parts[1].split(\"/\")\n dirs.each do |x|\n if x == \"..\" \n arr = curdir.split(\"/\")\n arr.pop\n curdir = arr.join(\"/\")\n curdir = curdir + \"/\"\n else\n curdir = curdir + x + \"/\"\n end\n end\n end\n}\nputs curdir"}, {"source_code": "def cd(a,b)\n b=b.split('/')\n if b[0]==\"\" then b.delete_at(0) end\n for i in 0...b.size do\n if b[i]==\"..\"\n a.delete_at(a.size-1)\n elsif\n a << b[i]\n end\n end\n return a\nend\n\ndef pwd(a)\n for i in 0...a.size do\n print \"/#{a[i]}\"\n end\n puts \"/\"\nend\n\na=[]\ngets.to_i.times do |x|\n com=gets.split\n if com[0]==\"cd\"\n a=cd(a,com[1])\n elsif com[0]==\"pwd\"\n pwd(a)\n end\nend\n"}, {"source_code": "n = gets.to_i\nwd = []\nn.times do\n c = gets.chomp\n if c == 'pwd'\n puts \"/#{wd.join(\"/\")}/\"\n else\n c, t = c.split(\" \")\n t = t.split(\"/\")\n if t[0] == ''\n wd = t[1..-1] \n else\n t.each do |x|\n if x == '..'\n wd.pop\n else\n wd.push x\n end\n end\n end\n end\nend\n"}, {"source_code": "n = gets.to_i\nwd = []\nn.times do\n c = gets.chomp\n if c == 'pwd'\n puts wd.size == 0 ? '/' : \"/#{wd.join(\"/\")}/\"\n else\n c, t = c.split(\" \")\n t = t.split(\"/\")\n if t[0] == ''\n wd = t[1..-1] \n else\n t.each do |x|\n if x == '..'\n wd.pop\n else\n wd.push x\n end\n end\n end\n end\nend\n"}, {"source_code": "n = gets.to_i\nwd = []\nn.times do\n c = gets.chomp\n if c == 'pwd'\n puts wd.size == 0 ? '/' : \"/#{wd.join(\"/\")}/\"\n else\n c, t = c.split(\" \")\n t = t.split(\"/\")\n t = t[1..-1] if t[0] == ''\n t.each do |x|\n if x == '..'\n wd.pop\n else\n wd.push x\n end\n end\n end\nend\n"}, {"source_code": "n = gets.to_i\nwd = []\nn.times do\n c = gets.chomp\n if c == 'pwd'\n puts \"/#{wd.join(\"/\")}\"\n else\n c, t = c.split(\" \")\n t = t.split(\"/\")\n if t[0] == ''\n wd = t[1..-1] \n else\n t.each do |x|\n if x == '..'\n wd.pop\n else\n wd.push x\n end\n end\n end\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\ndir = []\nn.times{\n cmd = gets.split\n if cmd[0] == 'pwd'\n if dir == []\n puts '/'\n else\n puts ['/', dir.join('/'), '/'].join\n end\n next\n end\n \n if cmd[1][0].to_s == '/'\n dir = cmd[1][1..-1].split('/')\n next\n end\n \n cmd[1].split('/').each{|t|\n if t == '..'\n dir = dir[0..-2]\n else\n dir << t\n end\n }\n}"}, {"source_code": "n = gets.chomp.to_i\n\ndir = []\nn.times{\n cmd = gets.split\n if cmd[0] == 'pwd'\n if dir == []\n puts '/'\n else\n puts [dir.join('/'), '/'].join\n end\n next\n end\n \n if cmd[1][0] == 47\n dir = cmd[1][1..-1].split('/')\n next\n end\n \n cmd[1].split('/').each{|t|\n if t == '..'\n dir = dir[0..-2]\n else\n dir << t\n end\n }\n}"}, {"source_code": "n = gets.chomp.to_i\n\ndir = []\nn.times{\n cmd = gets.split\n if cmd[0] == 'pwd'\n if dir == []\n puts '/'\n else\n puts ['/', dir.join('/'), '/'].join\n end\n next\n end\n \n if cmd[1][0] == 47\n dir = cmd[1][1..-1].split('/')\n next\n end\n \n cmd[1].split('/').each{|t|\n if t == '..'\n dir = dir[0..-2]\n else\n dir << t\n end\n }\n}"}, {"source_code": "n=gets.to_i\n\npwd=\"\"\n\nn.times{\n\ns=gets.chomp\nif s==\"pwd\"\nif pwd==\"\"\nprint '/'\nend\nprint pwd\nprint \"\\n\"\nelse\nfor i in s.split(' ')[1].split('/')\n\nif i==\"\"\npwd=\"\"\nelsif i==\"..\"\npwd=pwd.split('/')\npwd.pop\npwd=pwd.join('/')\nelse\npwd+='/'+i\nend\n\nend\nend\n\n}"}, {"source_code": "n=gets.to_i\n\npwd=\"/\"\n\nn.times{\n\ns=gets.chomp\nif s==\"pwd\"\nprint pwd\nprint \"\\n\"\nelse\nfor i in s.split(' ')[1].split('/')\n\nif i==\"\"\npwd=\"/\"\nelsif i==\"..\"\npwd=pwd.split('/')\npwd.pop\npwd=pwd.join('/')\nelse\npwd+='/'+i\nend\n\nend\nend\n\n}"}, {"source_code": "n=gets.to_i\n\npwd=\"/\"\n\nn.times{\n\ns=gets.chomp\nif s==\"pwd\"\nprint pwd\nprint \"\\n\"\nelse\nfor i in s.split(' ')[1].split('/')\n\nif i==\"\"\npwd=\"/\"\nelsif i==\"..\"\npwd=pwd.split('/')\npwd.pop\npwd=pwd.join('/')\nelse\npwd+=i+'/'\nend\n\nend\nend\n\n}"}, {"source_code": "n=gets.to_i\n\npwd=\"/\"\n\nn.times{\n\ns=gets.chomp\nif s==\"pwd\"\nprint pwd\nprint \"\\n\"\nelse\nfor i in s.split(' ')[1].split('/')\n\nif i==\"\"\npwd=\"/\"\nelsif i==\"..\"\npwd=pwd.split('/')\npwd.pop\npwd.pop\npwd.push \"\"\npwd=pwd.join('/')\nelse\npwd+=i+'/'\nend\n\nend\nend\n\n}"}, {"source_code": "def pwd(path)\n if path.empty?\n puts \"/\"\n else\n puts \"/#{path.join '/'}/\"\n end\nend\n\npath = []\nn = gets.to_i\n\nfor str in STDIN.each_line.take(n)\n arr = str.chomp.split(' ')\n\n if arr.size == 1\n pwd path\n else\n p = arr[1].split('/').reject &:empty?\n p.each { |t| (t == '..') ? path.pop : path.push(t) }\n end\nend"}, {"source_code": "def pwd(path)\n puts path.empty? ? \"/\" : \"#{path.join '/'}/\"\nend\n\npath = []\nn = gets.to_i\n\nfor str in STDIN.each_line.take(n)\n arr = str.chomp.split(' ')\n\n if arr.size == 1\n pwd path\n else\n p = arr[1].split('/')\n p.each { |t| (t == '..') ? path.pop : path.push(t) }\n end\nend"}, {"source_code": "# public: Simulate directory\nclass Directory\n def initialize\n\t@dir = []\n end\n \n def pwd\n\tputs to_dir\n end\n \n def to_dir\n dir_string = \"/\" << @dir.join(\"/\")\n\tif dir_string[-1] == \"/\"\n\t return dir_string\n\telse\n\t return dir_string << \"/\"\n\tend\n end\n \n def cd(dir)\n\tstack = dir.split(\"/\")\n\tif stack[0] == \"\"\n\t absolute_dir(stack)\n\telse\n\t relative_dir(stack)\n\tend\n end\n \n def absolute_dir(stack)\n\tstack.shift\n\t@dir = stack\n end\n \n def relative_dir(stack)\n stack.each do |dir|\n\t if dir == \"..\"\n\t @dir.pop\n\t else\n\t @dir.push(dir)\n\t end\n\tend\n end\nend\n\ndir = Directory.new\ngets.to_i.times do\n dir.send(*gets.chomp.split)\nend"}, {"source_code": "n = gets\nn = n.to_i\ncommands = Array.new\nwhile n != 0\n commands << gets\n n -= 1\nend\n@currentpwd = Array.new\n\ncommands.each do |command|\n # puts \"doing command #{command}\"\n command = command.gsub(/\\n/,\"\")\n if command == 'pwd'\n if @currentpwd.any?\n p = \"\"\n @currentpwd.each do |path|\n p += \"/\"\n p += path\n end\n puts p\n else\n puts '/'\n end\n else\n precommand = command.split(\" \")\n precommand = precommand[1].split(\"/\")\n # puts \"splitting #{precommand}\"\n precommand.each do |dir|\n if dir == \"\"\n @currentpwd = Array.new\n else\n if dir == \"..\"\n if @currentpwd.any?\n @currentpwd = @currentpwd.slice(0, @currentpwd.length-1)\n end\n # puts \"her #{@currentpwd}\"\n else\n @currentpwd << dir\n end\n end\n end\n # puts \"current dir #{@currentpwd}\"\n end\nend\n\n# p @currentpwd"}, {"source_code": "n = gets\nn = n.to_i\ncommands = Array.new\nwhile n != 0\n commands << gets\n n -= 1\nend\n@currentpwd = Array.new\n\ncommands.each do |command|\n command = command.gsub(/\\n/,\"\")\n if command == 'pwd'\n if @currentpwd.any?\n p = \"\"\n @currentpwd.each do |path|\n p += \"/\"\n p += path\n end\n puts p\n else\n puts '/'\n end\n else\n precommand = command.split(\" \")\n precommand = precommand[1].split(\"/\")\n precommand.each do |dir|\n if dir == \"\"\n @currentpwd = Array.new\n else\n if dir == \"..\"\n @currentpwd = @currentpwd.slice(0, @currentpwd.length-1)\n else\n @currentpwd << dir\n end\n end\n end\n end\nend"}], "src_uid": "494ac937ba939db1dbc4081e518ab54c"} {"source_code": "require 'set'\n\ngets.to_i.times do\n n = gets.to_i\n arr = gets.split.map(&:to_i)\n diff = (1..n-1).map{|i| arr[i] - arr[i-1]}.to_set\n if diff.size <= 1\n puts 0\n next\n elsif diff.size > 2\n puts -1\n next\n end\n a, b = diff.sort\n if a * b > 0\n puts -1\n next\n end\n m = b - a\n seq = [arr[0] % m]\n for i in 1..n-1\n seq << (seq[-1] + b) % m\n end\n if seq == arr\n puts \"#{m} #{b}\"\n else\n puts -1\n end\nend\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n\tn = gets.chomp.to_i\r\n\ta = gets.split()\r\n\r\n\tif n == 1 then\r\n\t\tp 0\r\n\t\tnext\r\n\tend\r\n\r\n\ta.map!(&:to_i)\r\n\r\n\tc = a[1] - a[0]\r\n\t\r\n\tm = -1\r\n\tok = true\r\n\r\n\tmax_value = a.max\r\n\r\n\tif c >= 0 then\r\n\t\tfor i in 1...n do\r\n\t\t\tif a[i] < a[i-1] then\r\n\t\t\t\tnew_m = a[i-1] + (c - a[i])\r\n\t\t\t\tok &= m == -1 || new_m == m\r\n\t\t\t\tm = new_m\r\n\t\t\telse\r\n\t\t\t\tok &= c == a[i] - a[i-1]\r\n\t\t\tend\r\n\t\tend\r\n\telse\r\n\t\tc *= - 1\r\n\r\n\t\tfor i in 1...n do\r\n\t\t\tif a[i] > a[i-1] then\r\n\t\t\t\tnew_m = a[i] + (c - a[i-1])\r\n\t\t\t\tok &= m == -1 || new_m == m \r\n\t\t\t\tm = new_m\r\n\t\t\telse\r\n\t\t\t\tok &= c == a[i-1] - a[i]\r\n\t\t\tend\r\n\t\tend\r\n\t\tc = m - c\r\n\tend\r\n\r\n\tok &= m == -1 || max_value < m\r\n\r\n\tputs ok ? (m == -1 ? 0 : \"#{m} #{c}\") : -1\r\n\r\nend\r\n"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n\tn = gets.chomp.to_i\r\n\ta = gets.split()\r\n\r\n\ta.map!(&:to_i)\r\n\r\n\tc = a[1] - a[0]\r\n\t\r\n\tm = -1\r\n\tok = true\r\n\r\n\tmax_value = a.max\r\n\r\n\tif c >= 0 then\r\n\t\tfor i in 1...n do\r\n\t\t\tif a[i] < a[i-1] then\r\n\t\t\t\tnew_m = a[i-1] + (c - a[i])\r\n\t\t\t\tok &= m == -1 || new_m == m\r\n\t\t\t\tm = new_m\r\n\t\t\telse\r\n\t\t\t\tok &= c == a[i] - a[i-1]\r\n\t\t\tend\r\n\t\tend\r\n\telse\r\n\t\tc *= - 1\r\n\r\n\t\tfor i in 1...n do\r\n\t\t\tif a[i] > a[i-1] then\r\n\t\t\t\tnew_m = a[i] + (c - a[i-1])\r\n\t\t\t\tok &= m == -1 || new_m == m \r\n\t\t\t\tm = new_m\r\n\t\t\telse\r\n\t\t\t\tok &= c == a[i-1] - a[i]\r\n\t\t\tend\r\n\t\tend\r\n\tend\r\n\r\n\tok &= m == -1 || max_value < m\r\n\r\n\tputs ok ? (m == -1 ? 0 : \"#{m} #{c}\") : -1\r\n\r\nend\r\n"}], "src_uid": "d6721fb3dd02535fc08fc69a4811d60c"} {"source_code": "n = STDIN.readline.to_i();\ntop_s = -100000000000000;\ntop_h = \"\";\nn.times do |i|\n h, p, m, a, b, c, d, e = STDIN.readline.split;\n s = p.to_i()*100 - m.to_i()*50 + a.to_i() + b.to_i() + c.to_i() + d.to_i() + e.to_i();\n if top_s <= s then\n top_s = s\n top_h = h\n end\nend\nprint top_h, \"\\n\"", "positive_code": [{"source_code": "h = Hash.new(0)\n\ngets; while g = gets\n\tc = g.split\n\tc[1..-1] = c[1..-1].map &:to_i\n\tc[1] *= 100\n\tc[2] *= 50\n\tc[2] = -c[2]\n\th[c[0].to_sym] = c[1..-1].inject(0) { |sum, i| sum += i }\nend\n\nmax = h.values.max\nh.each { |k ,v| (print k; exit) if v == max}"}, {"source_code": "winner = nil\nmax = -1000000\ngets.chomp.to_i.times do \n name, s, us, a, b, c, d, e = gets.chomp.split\n point = s.to_i * 100 - us.to_i * 50 + a.to_i + b.to_i + c.to_i + d.to_i + e.to_i\n if point > max\n max = point\n winner = name\n end\nend\nputs winner\n"}, {"source_code": "n=gets.to_i\nt=[]\nn.times{\n\tm,*v=gets.split\n\tv=v.map(&:to_i)\n\tt<<[v[0]*100-v[1]*50+v[2..-1].inject(:+),m]\n}\nputs t.max[1]\n"}, {"source_code": "puts gets.to_i.times.map{\n\ta = gets.split\n\tb = a[1..-1].map(&:to_i)\n\t[b[0] * 100 - b[1] * 50 + b[2..-1].inject(&:+), a[0]]\n}.sort[-1][1]\n"}, {"source_code": "class P\n attr_accessor :name, :result\n def initialize(name, plus, minus, a, b, c, d, e)\n @name = name\n @result = plus.to_i * 100 - minus.to_i * 50 \\\n + a.to_i + b.to_i + c.to_i + d.to_i + e.to_i\n end\nend\n\nn = gets.to_i\nh = []\nn.times do\n s = gets.chomp.split\n h.push(P.new(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7]))\nend\nh.sort! {|a,b| b.result <=> a.result}\nputs h[0].name\n"}, {"source_code": "question = gets.to_i\nplayer = []\nquestion.times do\n tmp = gets.split(\" \")\n name = tmp.shift\n tmp.map!{|item| item.to_i}\n tmp[0] *= 100\n tmp[1] = -tmp[1] * 50\n point= tmp.inject(0){|r,item| r+=item}\n player << [name,point]\nend\nmax = player.shift\nplayer.each do |item|\n max = item if max[1] < item[1]\nend\nputs max[0]\n \n "}, {"source_code": "gets;puts readlines.map(&:chomp).map(&:split).map! {|x| [x[0]] + x[1..-1].map!(&:to_i)}.map! { |x| [x[0], x[1]*100-x[2]*50+x[3]+x[4]+x[5]+x[6]+x[7]] }.max_by { |x| x[1]}[0]"}, {"source_code": "n = gets.to_i\n\narray = []\npo = -9999999\nname = \"\"\n\nn.times{\n pt = 0\n array = gets.split()\n pt += array[1].to_i * 100\n pt -= array[2].to_i * 50\n pt += array[3].to_i\n pt += array[4].to_i\n pt += array[5].to_i\n pt += array[6].to_i\n pt += array[7].to_i\n if pt > po\n name = array[0]\n po = pt\n end\n}\n\nputs name\n"}, {"source_code": "n=gets.to_i\n\nd = {}\nn.times{\n\ta, p, m, *t = gets.split\n\t\n\td[a] = t.map!(&:to_i).inject(:+) + p.to_i*100 - m.to_i*50\n}\n\nd=d.invert\nputs d[d.keys.max]\n"}, {"source_code": "an=[] \ngets.to_i.times{ name,*m=gets.split\n m=m.map(&:to_i) \n an<<[m[0]*100-m[1]*50+m[2]+m[3]+m[4]+m[5]+m[6],name]\n }\nputs an.max[1]"}, {"source_code": "n = gets.to_i\nans = \"\"\nscore = -(1<<30)\nn.times do\n tmp = gets.split\n (1..7).each{|i| tmp[i] = tmp[i].to_i}\n tmpscore = tmp[1]*100-tmp[2]*50+tmp[3]+tmp[4]+tmp[5]+tmp[6]+tmp[7]\n if tmpscore > score\n score = tmpscore\n ans = tmp[0]\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\n\na = []\nn.times do\n l = gets\n name, *data = l.split\n data = data.map(&:to_i)\n score = 100*data[0] - 50*data[1] + data[2..-1].inject(0){|r,j|r+j}\n a << [score, name]\nend\n\nputs a.max[1]\n"}, {"source_code": "n = gets.to_i\nmax = -2_501\nleader = nil\nfor _ in 1..n\n v = gets.split\n p, m, a, b, c, d, e = v[1..-1].map { |x| x.to_i }\n score = 100 * p - 50 * m + a + b + c + d + e\n if score > max\n max = score\n leader = v[0]\n end\nend\nputs leader"}], "negative_code": [{"source_code": "class P\n attr_accessor :name, :result\n def initialize(name, plus, minus, a, b, c, d)\n @name = name\n @result = plus.to_i * 100 - minus.to_i * 50 \\\n + a.to_i + b.to_i + c.to_i + d.to_i\n end\nend\n\nn = gets.to_i\nh = []\nn.times do\n s = gets.chomp.split\n h.push(P.new(s[0], s[1], s[2], s[3], s[4], s[5], s[6]))\nend\nh.sort! {|a,b| b.result <=> a.result}\nputs h[0].name\n"}, {"source_code": "n = gets.to_i\nans = \"\"\nscore = 0\nn.times do\n tmp = gets.split\n (1..7).each{|i| tmp[i] = tmp[i].to_i}\n tmpscore = tmp[1]*100-tmp[2]*50+tmp[3]+tmp[4]+tmp[5]+tmp[6]+tmp[7]\n if tmpscore > score\n score = tmpscore\n ans = tmp[0]\n end\nend\nputs ans\n"}, {"source_code": "n = STDIN.readline.to_i();\ntop_s = 0;\ntop_h = \"\";\nn.times do |i|\n h, p, m, a, b, c, d, e = STDIN.readline.split;\n s = p.to_i()*100 - m.to_i()*50 + a.to_i() + b.to_i() + c.to_i() + d.to_i() + e.to_i();\n if top_s <= s then\n top_s = s\n top_h = h\n end\nend\nprint top_h, \"\\n\""}, {"source_code": "n = STDIN.readline.to_i();\ntop_p = 0;\ntop_h = \"\";\nt = Array.new()\nn.times do |i|\n h, p, m, a, b, c, d, e = STDIN.readline.split;\n s = p.to_i()*100 - m.to_i()*50 + a.to_i() + b.to_i() + c.to_i() + d.to_i() + e.to_i(); \n if top_p < s then\n top_p = s\n top_h = h\n end\nend\nprint top_h, \"\\n\""}, {"source_code": "h = Hash.new(0)\n\ngets; while g = gets\n\tc = g.split\n\tc[1..-1] = c[1..-1].map! &:to_i\n\tc[1] *= 100\n\tc[2] *= 50\n\tc[2] = -c[2]\n\th[c[0].to_sym] = c[1..-1].inject(0) { |sum, i| sum += i }\nend\n\nprint h.max.first"}, {"source_code": "winner = nil\nmax = -1\ngets.chomp.to_i.times do \n name, s, us, a, b, c, d, e = gets.chomp.split\n point = s.to_i * 100 - us.to_i * 50 + a.to_i + b.to_i + c.to_i + d.to_i + e.to_i\n if point > max\n max = point\n winner = name\n end\nend\nputs winner\n"}, {"source_code": "winner = nil\nmax = -1\nn = gets.to_i\nn.times do \n name, s, us, a, b, c, d, e = gets.strip.split\n point = s.to_i * 100 - us.to_i * 50 + a.to_i + b.to_i + c.to_i + d.to_i + e.to_i\n if point > max\n max = point\n winner = name\n end\nend\nputs winner\n"}, {"source_code": "winner = nil\nmax = -1\ngets.to_i.times do \n name, s, us, a, b, c, d, e = gets.strip.split\n point = s.to_i * 100 - us.to_i * 50 + a.to_i + b.to_i + c.to_i + d.to_i + e.to_i\n if point > max\n max = point\n winner = name\n end\nend\nputs winner\n"}, {"source_code": "winner = nil\nmax = -1\nn = gets.to_i\nn.times do \n name, s, us, a, b, c, d, e = gets.chomp.split\n point = s.to_i * 100 - us.to_i * 50 + a.to_i + b.to_i + c.to_i + d.to_i + e.to_i\n if point > max\n max = point\n winner = name\n end\nend\nputs winner\n"}], "src_uid": "b9dacff0cab78595296d697d22dce5d9"} {"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 index (a, ind, start, d)\n\n if(ind == start)\n return d\n else\n ind = a[ind]-1\n return index(a, ind , start, d+1)\n end\nend\n\nn = inp[0]\nn.times do\n q = inp[0]\n st = inp\n mae = -9\n ans = []\n st.each.with_index do |d,i|\n ans << index(st,d-1,i,1)\n end\n puts ans.join(\" \")\n\nend", "positive_code": [{"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 index (a, ind, start, d, arrow)\n stack = [[ind, d]]\n ans = 0\n while true\n ind, d = stack.pop\n if(ind == start)\n ans = d\n break\n end\n ind = a[ind]-1\n arrow[ind] = start\n stack.push([ind , d+1])\n end\n return ans\nend\n\nn = inp[0]\nn.times do\n q = inp[0]\n st = inp\n mae = -9\n ans = na(q,false)\n arrow = na(q,false)\n st.each.with_index do |d,i|\n if(arrow[i])\n ans[i] = ans[arrow[i]]\n else\n ans[i] = index(st,d-1,i,1,arrow)\n end\n end\n puts ans.join(\" \")\n\nend"}], "negative_code": [], "src_uid": "345e76bf67ae4342e850ab248211eb0b"} {"source_code": "t = gets.chomp.to_i\n\nwhile t > 0\n t -= 1\n n = gets.chomp.to_i\n a = gets.chomp\n\n\n res = if a.length == 1\n 11 - a.to_i\n elsif a[0] == '9'\n # a + res = final\n # res = final - a\n res = \"0\" * a.length\n final = \"1\" * (a.length + 1)\n\n (0..a.length - 1).reverse_each do |i|\n nu = final[i].to_i\n de = a[i].to_i\n d = nu - de\n if d < 0\n d += 10\n final[i - 1] = '0'\n end\n res[i] = d.to_s\n end\n res\n else\n a.chars.map { |c| (9 - c.to_i).to_s }.join(\"\")\n end\n\n puts res\nend\n\n# puts inp.length\n# puts inp[0]\n# puts inp[1]\n# puts inp\n2\n3\n123\n2\n99", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n s = gets.to_i\n v = ('9' * n).to_i - s\n v = ('1' * (n + 1)).to_i - s if v.to_s.size != n\n puts v\nend\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n x = gets\r\n x[0] == '9' ? puts(('1'*(n + 1)).to_i - x.to_i) : puts(('9'*n).to_i - x.to_i)\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n x = gets\r\n case\r\n when x[0] == '9'\r\n puts(('1'*(n + 1)).to_i - x.to_i)\r\n else\r\n puts(('9'*n).to_i - x.to_i)\r\n end\r\nend"}, {"source_code": "t = gets.chomp.to_i\r\nfor i in 1..t\r\n n = gets.chomp.to_i\r\n x = gets.chomp\r\n if x[0] != '9'\r\n w = \"\"\r\n for j in 0..(n - 1)\r\n w.concat((9 - x[j].to_i).to_s)\r\n end\r\n puts(w)\r\n else\r\n x.reverse!\r\n w = \"\"\r\n c = 0\r\n for j in 0..(n - 1)\r\n c += x[j].to_i\r\n if (c <= 1) \r\n w.concat((1 - c).to_s)\r\n c = 0\r\n else\r\n w.concat((11 - c).to_s)\r\n c = 1\r\n end\r\n end\r\n w.reverse!\r\n puts(w)\r\n end\r\nend"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\r\nfor i in 1..t\r\n n = gets.chomp.to_i\r\n x = gets.chomp\r\n if x[0] != '9'\r\n w = \"\"\r\n for j in 0..(n - 1)\r\n w.concat((9 - x[j].to_i).to_s)\r\n end\r\n puts(w)\r\n else\r\n w = \"\"\r\n for j in 0..(n - 2)\r\n w.concat((10 - x[j].to_i).to_s)\r\n end\r\n w.concat((11 - x[j].to_i).to_s)\r\n puts(w)\r\n end\r\nend"}, {"source_code": "t = gets.chomp.to_i\r\nfor i in 1..t\r\n n = gets.chomp.to_i\r\n x = gets.chomp\r\n if x[0] != '9'\r\n w = \"\"\r\n for j in 0..(n - 1)\r\n print((9 - x[j].to_i).to_s)\r\n end\r\n puts()\r\n else\r\n w = \"\"\r\n for j in 0..(n - 2)\r\n print((10 - x[j].to_i).to_s)\r\n end\r\n puts((11 - x[j].to_i).to_s)\r\n end\r\nend"}], "src_uid": "d3c3bc95605010040e2018e465eb9fab"} {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n\n", "positive_code": [{"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n\n\n"}, {"source_code": "ball_pos = 0\nFile.open('input.txt').each do |line|\n if ball_pos == 0\n\t\tball_pos = line.to_i\n\telse\n\t\ttemp = line.split.collect { |n| n.to_i }\n\t\tif temp[0] == ball_pos\n\t\t\tball_pos = temp[1]\n\t\telsif temp[1] == ball_pos\n\t\t\tball_pos = temp[0]\n\t\tend\n\tend\nend\nout = File.open('output.txt','w')\nout << ball_pos.to_s\nout.close\n"}, {"source_code": "file = File.new(\"input.txt\", \"r\")\npos = file.gets.to_i\na = (1..3).to_a\n(1..3).each do\n x, y = file.gets.split.map{|z| z.to_i-1}\n a[x], a[y] = a[y], a[x]\nend\nfile.close\nFile.open(\"output.txt\", \"w\") {|file| file.write(a.find_index(pos)+1)}\n"}, {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n\n\n"}, {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n\n"}, {"source_code": "f = open(\"input.txt\", \"r\")\nfw = open(\"output.txt\", \"w\")\nidx = f.gets.chomp.to_i\nfor i in 0..2\n\ti1, i2 = f.gets.chomp.split(/ /).map!{|x|x.to_i}\n\tif idx == i1\n\t\tidx = i2\n\telsif idx == i2\n\t\tidx = i1\n\tend\nend\nfw.puts idx\nf.close\nfw.close"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nk=gets.to_i\n3.times do\n\tm,n=gets.chomp.split.map(&:to_i)\n\tk = (m==k)? n : ((n==k)? m : k)\nend\nputs k"}, {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n\n\n"}, {"source_code": "#!/usr/bin/ruby\n$stdin=open(\"input.txt\",\"rb\")\n$>=open(\"output.txt\",\"wb\")\na=[0]*4\na[gets.to_i]=1\nwhile gets\n\tx,y=$_.split.map(&:to_i)\n\ta[x],a[y]=a[y],a[x]\nend\np a.index(1)"}, {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n\n\n"}, {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n"}, {"source_code": "\nline = File.read(\"input.txt\")\ninputs = line.split(\"\\n\")\n\narr = Array.new(3,false)\n\nstart = inputs[0].to_i\narr[start-1] = true\n\n3.times do |inp|\n\ti,j = inputs[inp+1].split(\" \").map(&:to_i)\n\ti -= 1\n\tj -= 1\n\tarr[i],arr[j] = arr[j],arr[i]\nend\n\nFile.open(\"output.txt\", 'w') { |file| \n\tfile.puts arr.index(true) + 1\n}\n\n"}, {"source_code": "$stdin = File.new( \"input.txt\", 'r' )\n$stdout = File.new( \"output.txt\", 'w' )\n\nindex = gets.strip.to_i\n3.times do\n a, b = gets.strip.split.map(&:to_i)\n if index == a\n index = b\n elsif index == b\n index = a\n end\nend\nputs index\n"}, {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n a, b = I.gets.split.map &:to_i\n n = n == a ? b : n == b ? a : n\nend\nO.puts n"}, {"source_code": "$stdin = File.open(\"input.txt\",\"r\")\n$stdout = File.open(\"output.txt\",\"w\")\nk=gets.to_i\n3.times {|x| l=gets.split.map &:to_i ; l[0]==k ?k=l[1]:(l[1]==k ?k=l[0]:0)}\nputs k"}, {"source_code": "input = open('input.txt','r')\noutput = open('output.txt','w')\n\ncurr = input.gets.chomp!.to_i\n\nfor i in 1..3\n s = input.gets.chomp!.split(\" \")\n mas = []\n mas[0] = s[0].to_i\n mas[1] = s[1].to_i\n\n if (curr == mas[0])\n curr = mas[1]\n else\n if (curr == mas[1])\n curr = mas[0]\n end\n end\nend\n\noutput.puts(curr)"}, {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n"}, {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n\n\n"}, {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n\n\n"}, {"source_code": "File.open('input.txt') do |f|\n now = f.gets.to_i\n 3.times do \n a, b = f.gets.split.map(&:to_i)\n if [a, b].index(now)\n now ^= a ^ b\n end\n end\n File.open('output.txt', 'w') { |f| f.puts now }\nend\n"}, {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n\n\n"}, {"source_code": "I=open('input.txt')\nO=open('output.txt','w')\nn=I.gets.to_i\n3.times do\n\ta, b = I.gets.split.map &:to_i\n\tn = n == a ? b : n == b ? a : n\nend\nO.puts n\n\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\na=[0]*4\na[gets.to_i]=1\nwhile gets\n\tx,y=$_.split.map(&:to_i)\n\ta[x],a[y]=a[y],a[x]\nend\nputs 2\nputs(a.index(1))"}, {"source_code": "#!/usr/bin/ruby\nf=open(\"output.txt\",\"wb\")\na=[0]*4\na[gets.to_i]=1\nwhile gets\n\tx,y=$_.split.map(&:to_i)\n\tf.puts x\n\tf.puts y\n\ta[x],a[y]=a[y],a[x]\nend\nf.puts(a.index(1))"}, {"source_code": "#!/usr/bin/ruby\nf=open(\"output.txt\",\"wb\")\na=[0]*4\na[gets.to_i]=1\nwhile gets\n\tx,y=$_.split.map(&:to_i)\n\ta[x],a[y]=a[y],a[x]\nend\nf.puts(a.index(1))"}, {"source_code": "#!/usr/bin/ruby\nf=open(\"output.txt\",\"w\")\na=[0]*4\na[gets.to_i]=1\nwhile gets\n\tx,y=$_.split.map(&:to_i)\n\ta[x],a[y]=a[y],a[x]\nend\nf.puts a.index(1)"}, {"source_code": "#!/usr/bin/ruby\na=[0]*4\na[gets.to_i]=1\nwhile gets\n\tx,y=$_.split.map(&:to_i)\n\ta[x],a[y]=a[y],a[x]\nend\nputs(a.index(1))"}, {"source_code": "#!/usr/bin/ruby\na=[0]*4\na[gets.to_i]=1\nwhile gets\n\tx,y=$_.split.map(&:to_i)\n\ta[x],a[y]=a[y],a[x]\nend\np a.index 1"}, {"source_code": "#!/usr/bin/ruby\na=[0]*4\na[gets.to_i]=1\nwhile gets\n\tx,y=$_.split.map(&:to_i)\nputs x\n\ta[x],a[y]=a[y],a[x]\nend\nputs(a.index(1))"}, {"source_code": "#!/usr/bin/ruby\na=[0]*4\na[gets.to_i]=1\nwhile gets\n\tx,y=$_.split.map(&:to_i)\n\ta[x],a[y]=a[y],a[x]\nend\np a.index(1)"}, {"source_code": "#!/usr/bin/ruby\nf=open(\"output.txt\",\"w\")\na=[0]*4\na[gets.to_i]=1\nwhile gets\n\tx,y=$_.split.map(&:to_i)\n\ta[x],a[y]=a[y],a[x]\nend\nf.puts a.inspect\nf.puts a.index(1)"}], "src_uid": "88e6651e1b0481d711e89c8071be1edf"} {"source_code": "m,k,p = gets.split.map(&:to_i)\nh={}\n(m-1).times{\na,b = gets.split.map(&:to_i)\n(h[a]||=[])<0}\ni=1\nj=0\ns=0\nans=0\nwhile jp||j-i+1>k\nh[x].each{|y|\nnext if d[y]\nd[y]=m+1\nq<0\nj+=1\nend\np ans\n", "positive_code": [{"source_code": "m,k,p = gets.split.map(&:to_i)\nh={}\n(m-1).times{\na,b = gets.split.map(&:to_i)\n(h[a]||=[])<p||j-i+1>k\nh[x].each{|y|\nnext if d[y]\nd[y]=m+1\nq<0}\ni=1\nj=0\ns=0\nans=0\nwhile jp||j-i+1>k\nh[x].each{|y|\nnext if d[y]\nd[y]=m+1\nq<0\nj+=1\nend\np ans\n\n"}, {"source_code": "m,k,p = gets.split.map(&:to_i)\nh={}\n(m-1).times{\na,b = gets.split.map(&:to_i)\n(h[a]||=[])<0}\ni=1\nj=0\ns=0\nans=0\nwhile jp||j-i+1>k\nh[x].each{|y|\nnext if d[y]\nd[y]=m+1\nq<0\nj+=1\nend\np ans\n\n"}, {"source_code": "m,k,p = gets.split.map(&:to_i)\nh={}\n(m-1).times{\na,b = gets.split.map(&:to_i)\n(h[a]||=[])<0}\ni=1\nj=0\ns=0\nans=0\nwhile jp||j-i+1>k\nh[x].each{|y|\nnext if d[y]\nd[y]=m+1\nq<0\nj+=1\nend\np ans\n\n"}, {"source_code": "m,k,p = gets.split.map(&:to_i)\nh={}\n(m-1).times{\na,b = gets.split.map(&:to_i)\n(h[a]||=[])<0}\ni=1\nj=0\ns=0\nans=0\nwhile jp||j-i+1>k\nh[x].each{|y|\nnext if d[y]\nd[y]=m+1\nq<0\nj+=1\nend\np ans\n\n"}, {"source_code": "m,k,p = gets.split.map(&:to_i)\nh={}\n(m-1).times{\na,b = gets.split.map(&:to_i)\n(h[a]||=[])<0}\ni=1\nj=0\ns=0\nans=0\nwhile jp||j-i+1>k\nh[x].each{|y|\nnext if d[y]\nd[y]=m+1\nq<0\nj+=1\nend\np ans\n\n"}, {"source_code": "m,k,p = gets.split.map(&:to_i)\nh={}\n(m-1).times{\na,b = gets.split.map(&:to_i)\n(h[a]||=[])<0}\ni=1\nj=0\ns=0\nans=0\nwhile jp||j-i+1>k\nh[x].each{|y|\nnext if d[y]\nd[y]=m+1\nq<0\nj+=1\nend\np ans\n\n"}, {"source_code": "m,k,p = gets.split.map(&:to_i)\nh={}\n(m-1).times{\na,b = gets.split.map(&:to_i)\n(h[a]||=[])<0}\ni=1\nj=0\ns=0\nans=0\nwhile jp||j-i+1>k\nh[x].each{|y|\nnext if d[y]\nd[y]=m+1\nq<0\nj+=1\nend\np ans\n\n"}, {"source_code": "m,k,p = gets.split.map(&:to_i)\nh={}\n(m-1).times{\na,b = gets.split.map(&:to_i)\n(h[a]||=[])<0}\ni=1\nj=0\ns=0\nans=0\nwhile jp||j-i+1>k\nh[x].each{|y|\nnext if d[y]\nd[y]=m+1\nq<0\nj+=1\nend\np ans\n\n"}], "negative_code": [], "src_uid": "fb731edef28d25356a34f211dba91e41"} {"source_code": "t = gets.chomp.to_i\nt.times do\n hash = {}\n n = gets.chomp.to_i\n puts \"#{2} #{n-1}\"\nend\n", "positive_code": [{"source_code": "def i(x)\n\tx.to_i\nend\n\nn = gets\nfor i in 1..i(n)\n\ta = gets\n\ta = i(a)\n\tputs \"2 #{a - 1}\"\nend"}, {"source_code": "t = gets.to_i\r\nwhile(t>0)\r\n num = gets.to_i\r\n puts(\"2 \" + (num-1).to_s)\r\n t-=1\r\nend\r\n"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n\tprime = gets.to_i\r\n\tputs [2, prime - 1] * \" \"\r\nend\r\n"}, {"source_code": "\n\nt = gets.chomp.to_i\n\nt.times do\n p = gets.chomp.to_i\n puts \"2 #{p-1}\\n\"\nend\n\n"}], "negative_code": [], "src_uid": "259e39c9e63e43678e596c0d8c66937c"} {"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i).sort\n\nans1 = (as[2*N-1] - as[N]) * (as[N-1] - as[0])\n\nmin = 10**9\n(0..N).each do |i|\n result = as[i+N-1] - as[i]\n min = result if min > result\nend\nans2 = min * (as[2*N-1] - as[0])\n\nputs [ans1, ans2].min", "positive_code": [{"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i).sort\n\nans1 = (as[2*N-1] - as[N]) * (as[N-1] - as[0])\n\nmin = 10**9\n(0..N).each do |i|\n result = as[i+N-1] - as[i]\n min = result if min > result\nend\nans2 = min * (as[2*N-1] - as[0])\n\nputs [ans1, ans2].min"}], "negative_code": [], "src_uid": "cda1179c51fc69d2c64ee4707b97cbb3"} {"source_code": "n = gets.strip\nm = false\n\nif n[0] == \"-\"\n m = true\n n.delete! \"-\"\nend\n\ni,f = n.split(/\\./) \n\nf = \"00\" if f == nil\nf += \"0\" if f.size == 1\n\ns = i.size\na = \"$\"\ni.each_char do |c|\n a += c\n s -= 1\n a += \",\"if s % 3 == 0 && s != 0\nend\na += \".\"\na += f[0,2]\n\nif m\n a = \"(\" + a\n a += \")\"\nend\nputs a\n", "positive_code": [{"source_code": "a, b = gets.split('.').map(&:chomp)\nans = \"\"\nif a[0] == \"-\"\n ans += \"(\"\n a = a[1..a.size]\nend\nans += \"$\"\nans += a.reverse.gsub(/(\\d{3})(?=\\d)/,'\\1,').reverse\nb ||= \"0\"\nans += \".\" + (b + \"00\")[0..1]\nans += ans[0] == \"(\" ? \")\" : \"\"\nputs ans\n"}, {"source_code": "class Integer\n def to_currency()\n self.to_s.reverse.gsub(/(\\d{3})(?=\\d)/, '\\1,').reverse\n end\nend\n\ns = gets.chomp\nsa = s.split(\".\")\nif sa.length == 1\n\tsa << \"00\"\nelse\n\tsa[1] = sa[1].slice(0,2)\n\tif sa[1].length == 1\n\t\tsa[1] += \"0\"\n\tend\nend\nminus = false\nif sa[0].slice(0,1) == \"-\"\n\tminus = true\nend\nsa[0] = sa[0].sub(\"-\", \"\")\nsa[0] = sa[0].to_i.to_currency\nret = \"$\" + sa.join(\".\")\nif minus\n\tret = \"(\" + ret + \")\"\nend\nputs ret\n"}, {"source_code": "s = gets.chop\nn = nil\nif s[0] == '-'\n s = s[1..-1]\n n = true\nend\ni, f = s.split('.')\nf = (f || '') + '00'\ns = \"$#{i.gsub(/(?<=.)(?=(.{3})+$)/, ',')}.#{f[0, 2]}\"\nputs n ? \"(#{s})\" : s\n"}, {"source_code": "t=gets.split[0]\nminus=false\nif t[0]==\"-\" then\n minus=true\n t=t.slice(1,t.length-1)\nend\na,b=(t+'.0000.0').split('.')\nres=\"\"\na=a.to_i\nb+=\"0000\"\nwhile a>0\n res=sprintf(\",%03d\",a%1000)+res;\n a/=1000\nend\nres=res.slice(1,res.length-1) if res[0]==','\nres=res.slice(1,res.length-1) while res.size()>1 && res[0]=='0'\nres=\"0\" if res==\"\"\nres=\"$\"+res+\".\"+b.slice(0,2)\nres=\"(\"+res+\")\" if minus\nputs res\n"}, {"source_code": "#!/usr/bin/ruby\ndef read_int; gets.chomp.to_i; end\ndef read_ints; gets.chomp.split.map(&:to_i); end\n\na = gets.chomp\narr = a.split('')\n\nminus = false\nif arr[0] == '-'\n minus = true\n arr.shift\nend\n\nindex = arr.index('.')\nlen = 0\nif index == nil\n len = arr.size\nelse\n len = index\nend\n\nprint '(' if minus\nprint '$'\n\ncount = (3 - (len % 3)) % 3\n\n#puts \"count = #{len}\"\n\n\n0.upto(len-1) do |i|\n print arr[i]\n count += 1\n# puts \" count = #{count}\"\n print ',' if len > 3 and count % 3 == 0 and i+1 != len\nend\n\nprint '.'\n\nlen.times { arr.shift }\narr.shift if arr[0] == '.'\n\nif arr.size == 0\n print '00'\nelsif arr.size == 1\n print arr[0]\n print '0'\nelse\n print arr[0]\n print arr[1]\nend\n\nprint ')' if minus\nputs\n"}, {"source_code": "s = gets.chop\nn = nil\nif s[0] == '-'\n s = s[1..-1]\n n = true\nend\ni, f = s.split('.')\nf = (f || '') + '00'\ns = \"$#{i.gsub(/(?<=.)(?=(.{3})+$)/, ',')}.#{f[0, 2]}\"\nputs n ? \"(#{s})\" : s\n__END__"}, {"source_code": "a,b = gets.split('.')\n\na = a.chomp\nb = b.chomp if b != nil\n\nlast = \"\\n\"\nif a[0].chr == '-'\n print '('\n last = \")\\n\"\n a = a[1..-1]\nend\n\nprint '$'\n\ni = a.length % 3\nfirst = true\ncount = 0\na.each_byte{|c|\n print ',' if !first && i == 0\n print c.chr\n i = (i+2) % 3\n first = false\n count += 1\n}\n\nif b == nil\n print '.00'\nelsif b.length == 1\n print \".#{b}0\"\nelse\n print \".#{b[0..1]}\"\nend\n\nprint last\n\n\n\n\n"}, {"source_code": "#!/usr/bin/ruby\ninclude Math\nrequire 'pp'\nminus = false\ninput = gets.chomp\nminus = true if input[0] == '-'\ninput.delete!('-')\nif(input.include? '.')\n input = input.split ('.')\n input[1] = input[1][0..1]\nelse\n input = [input,'00']\nend\ninput[0].reverse!\noutput = []\ninput[0].chars.to_a.each_with_index do |c,i|\n if output[i/3]\n output[i/3] += c \n else\n output[i/3] = c\n end\nend\noutput = output.reverse.map{ |x| x.reverse!}.join(',')\noutput = '$'+output+'.'+input[1]\noutput += '0' if input[1].size < 2\noutput = '(' + output + ')' if minus\nputs output\n\n"}, {"source_code": "number = gets.chomp\ninteger = nil\nfraction = nil\n\nif /\\A([^\\.]+)\\.(\\d+)\\Z/=~ number\n integer = $1\n fraction = $2\nelsif /\\A([^\\.]+)\\Z/=~ number\n integer = $1\nelse\n raise\nend\n\nminus = false\nminus = true if /\\A\\-/=~ integer\ninteger.gsub!( /\\A\\-/, \"\" )\ninteger = integer.reverse.gsub( /\\d\\d\\d/, '\\&,' ).reverse\ninteger.gsub!( /\\A,/, \"\" )\n\nif fraction.nil?\n fraction = \"00\"\nend\nif fraction.size < 2\n fraction += \"0\"\nend\nfraction = fraction.split(//)[0..1].join(\"\")\n\nif minus\n puts \"($#{ integer }.#{ fraction })\"\nelse\n puts \"$#{ integer }.#{ fraction }\"\nend\n"}, {"source_code": "n = gets.chomp\na,b = n.gsub(\"-\",\"\").split(\".\")\nb = b || \"0\"\nb = b[0..1].ljust(2,\"0\")\na = a.reverse.scan(/.{1,3}/).map(&:reverse).reverse.join(\",\")\n\nnumber = \"#{a}.#{b}\"\n\nif n[0] != \"-\"\n\tputs \"$#{number}\"\nelse\n\tputs \"($#{number})\"\t\nend\n\n"}, {"source_code": "s = gets.strip\nif s[/\\./]\n s += '00'\nelse\n s += '.00'\nend\nif s.match(/\\A(-)?([\\d]+)\\.(\\d\\d)/)\n sign, main, sub = $1, $2, $3\n main = (main.reverse.scan(/.{1,3}/)*\",\").reverse\n if sign\n puts \"($#{main}.#{sub})\"\n else\n puts \"$#{main}.#{sub}\"\n end\n\nend\n"}, {"source_code": "n = gets.strip\nm = false\n\nif(n[0] == '-')\n m = true\n n.delete! '-'\nend \n\ni, f = n.split(/\\./)\n\nif(f == nil)\n f = \"00\";\nend\n\nif(f.size == 1)\n f += '0'\nend\n \nans = '$'\nsiz = i.size\n\ni.each_char do\n |c|\n siz -= 1; \n ans += c;\n \n if(siz % 3 == 0 and siz != 0)\n ans += ',' \n end\n #puts(ans)\nend\n\nans += '.'\nans += f[0,2]\n\nif(m)\n print(\"(\", ans, \")\")\nend\n\nif(!m)\n print(ans)\nend"}, {"source_code": "a, b = gets.split(\".\").map(&:chomp)\nans = \"\"\nif a[0] == \"-\"\n ans += \"(\"\n a = a[1...a.length]\nend\nans += \"$\"\nans += a.reverse.gsub(/(\\d{3})(?=\\d)/, '\\1,').reverse\nb ||= \"0\"\nans += \".\" + (b + \"00\")[0..1]\nans += \")\" if ans[0] == \"(\"\nputs ans"}, {"source_code": "input = gets.strip\nsurround = input[0] == \"-\" ? (input[0] = \"\"; true) : false\n\ninput = input.split '.'\nl = []\n\ninput[0].split('').reverse.each_slice(3) { |s| l << s.reverse.join + \",\" }\nl = l.reverse.join.chop\n\nr = input[1]\nr = \"00\" if r.nil?\nr = r + \"0\" if r.length == 1\nr = r[0, 2] if r.length >= 2\n\nprint '(' if surround\nprint '$', l, '.', r\nprint ')' if surround"}], "negative_code": [{"source_code": "n = gets.strip\nm = false\n\np n\nif n[0] == \"-\"\n m = true\n n.delete! \"-\"\nend\n\ni,f = n.split(/\\./) \np i\nf = \"00\" if f == nil\nf += \"0\" if f.size == 1\n\ns = i.size\na = \"$\"\ni.each_char do |c|\n a += c\n s -= 1\n a += \",\"if s % 3 == 0 && s != 0\nend\na += \".\"\na += f[0,2]\n\nif m\n a = \"(\" + a\n a += \")\"\nend\nputs a\n"}, {"source_code": "number = gets.chomp\ninteger = nil\nfraction = nil\n\ncase number\n when /\\A([^\\.]+)\\.(\\d+)\\Z/\n integer = $1\n fraction = $2\n when /\\A([^\\.]+)\\Z/\n integer = $1\nend\n\nminus = false\nminus = true if /\\A\\-/=~ integer\ninteger.gsub!( /\\A\\-/, \"\" )\nif integer.size > 3\n integer = integer.reverse.gsub( /\\d\\d\\d/, '\\&,' ).reverse\nend\n\nif fraction.nil?\n fraction = \"00\"\nend\nif fraction.size < 2\n fraction += \"0\"\nend\nfraction = fraction.split(//)[0..1].join(\"\")\n\nif minus\n puts \"($#{ integer }.#{ fraction })\"\nelse\n puts \"$#{ integer }.#{ fraction }\"\nend\n"}, {"source_code": "number = gets.chomp\ninteger = nil\nfraction = nil\n\nif /\\A([^\\.]+)\\.(\\d+)\\Z/=~ number\n integer = $1\n fraction = $2\nelsif /\\A([^\\.]+)\\Z/=~ number\n integer = $1\nelse\n raise\nend\n\nminus = false\nminus = true if /\\A\\-/=~ integer\ninteger.gsub!( /\\A\\-/, \"\" )\nif integer.size > 3\n integer = integer.reverse.gsub( /\\d\\d\\d/, '\\&,' ).reverse\nend\n\nif fraction.nil?\n fraction = \"00\"\nend\nif fraction.size < 2\n fraction += \"0\"\nend\nfraction = fraction.split(//)[0..1].join(\"\")\n\nif minus\n puts \"($#{ integer }.#{ fraction })\"\nelse\n puts \"$#{ integer }.#{ fraction }\"\nend\n"}, {"source_code": "number = gets.chomp\ninteger = nil\nfraction = nil\n\ncase number\n when /\\A([^\\.]+)\\.(\\d+)\\Z/\n integer = $1\n fraction = $2\n when /\\A([^\\.]+)\\Z/\n integer = $1\nend\n\nminus = false\nminus = true if /\\A\\-/=~ integer\ninteger.gsub!( /\\A\\-/, \"\" )\ninteger = integer.reverse.gsub( /\\d\\d\\d/, '\\&,' ).reverse\n\nif fraction.nil?\n fraction = \"00\"\nend\nif fraction.size < 2\n fraction += \"0\"\nend\nfraction = fraction.split(//)[0..1].join(\"\")\n\nif minus\n puts \"($#{ integer }.#{ fraction })\"\nelse\n puts \"$#{ integer }.#{ fraction }\"\nend\n\n# p minus\n# p integer\n# p fraction\n\n"}, {"source_code": "n = gets.strip\nm = false\n\nif(n[0] == '-')\n m = true\n n.delete! '-'\nend \n\ni, f = n.split(/\\./)\n\nif(f == nil)\n f = \"00\";\nend\n\nif(f.size == 1)\n f += '0'\nend\n \nans = '$'\nsiz = i.size\n\ni.each_char do\n |c|\n siz -= 1; \n ans += c;\n \n if(siz % 3 == 0 and siz != 0)\n ans += ',' \n end\n #puts(ans)\nend\n\nans += '.'\nans += f[0..2]\n\nif(m)\n print(\"(\", ans, \")\")\nend\n\nif(!m)\n print(ans)\nend"}, {"source_code": "a, b = gets.split(\".\")\nans = \"\"\nif a[0] == \"-\"\n ans += \"(\"\n a = a[1...a.length]\nend\nans += \"$\"\nans += a.reverse.gsub(/(\\d{3})(?=\\d)/, '\\1,').reverse\nb ||= \"0\"\nans += \".\" + (b + \"00\")[0..1]\nans += \")\" if ans[0] == \"(\"\np ans"}, {"source_code": "a, b = gets.split(\".\")\nans = \"\"\nif a[0] == \"-\"\n ans += \"(\"\n a = a[1...a.length]\nend\nans += \"$\"\nans += a.reverse.gsub(/(\\d{3})(?=\\d)/, '\\1,').reverse\nb ||= \"0\"\nans += \".\" + (b + \"00\")[0..1]\nans += \")\" if ans[0] == \"(\"\nputs ans"}], "src_uid": "c704c5fb9e054fab1caeab534849901d"} {"source_code": "require\"prime\"\n$char_num={}\ndef max_char\n\ta,max=\"\",0\n\t?a.upto(?z){|c|\n\t\tif max<$char_num[c]\n\t\t\tmax=$char_num[c]\n\t\t\ta=c\n\t\tend\n\t}\n\t[a,max]\nend\ns=gets.chomp\nsize=s.size\nflag=Array.new(size+1,false)\n?a.upto(?z){|c|$char_num[c]=s.count c}\nPrime.each(size){|p|\n\ti=size/p\n\t1.upto(i){|j|flag[p*j]=true} if i>1\n}\nw=flag.count(true)\na,max=max_char\nif w>max\n\tputs \"NO\"\nelse\n\tputs \"YES\"\n\tj=-1\n\ts=\"\"\n\t$char_num[a]-=w\n\t?a.upto(?z){|c|s+=(c*$char_num[c])}\n\t1.upto(size+1){|k|\n\t\tprint flag[k] ? a : s[j+=1]\n\t}\n\tputs\nend\n", "positive_code": [{"source_code": "str = gets\nstr = str.chop\nchararray = []\nprimeTable = [2]\n3.upto(1000) { |i|\n\tdividable = false\n\tprimeTable.each { |j|\n\t\tif i % j == 0\n\t\t\tdividable = true\n\t\t\tbreak\n\t\tend\n\t}\n\tprimeTable.push(i) if !dividable\n}\nstr.each_char {|i|\n\tchararray.push(i)\n}\nchararray.sort!\n\nequlationSet = []\n0.upto(str.length - 1) { |i|\n\ttimes = str.length / primeTable[i]\n\tbreak if(times <= 1)\n\t1.upto(times) { |j|\n\t\tequlationSet.push(primeTable[i] * j) if !equlationSet.include?(primeTable[i] * j)\n\t}\n}\nmaxCharacter = \"\"\nmaxNumber = 0\nnum = 0\ncurChar = chararray[0]\nchararray.each {|i|\n\tif(curChar != i)\n\t\tcurChar = i\n\t\tnum = 1\n\telse\n\t\tnum += 1\n\t\tif maxNumber < num\n\t\t\tmaxNumber = num\n\t\t\tmaxCharacter = curChar\n\t\tend\n\tend\n}\n\nif(maxNumber >= equlationSet.length)\n\tputs \"YES\"\n\tequlationSet.sort!\n\tresult = \"\"\n\tsetInd = 0\n\tcharInd = 0\n\t0.upto(str.length - 1) { |i|\n\t\tif equlationSet[setInd] == i + 1\n\t\t\tresult.concat(maxCharacter)\n\t\t\tsetInd += 1\n\t\telse\n\t\t\twhile str[charInd] == maxCharacter\n\t\t\t\tcharInd += 1\n\t\t\tend\n\t\t\tif(charInd < str.length)\n\t\t\t\tresult.concat(str[charInd])\n\t\t\t\tcharInd += 1\n\t\t\telse\n\t\t\t\tresult.concat(maxCharacter)\n\t\t\tend\n\t\tend\n\t}\n\tputs result\nelse\n\tputs \"NO\"\nend"}], "negative_code": [{"source_code": "str = gets\nstr = str.chop\nchararray = []\nprimeTable = [2]\n3.upto(1000) { |i|\n\tdividable = false\n\tprimeTable.each { |j|\n\t\tif i % j == 0\n\t\t\tdividable = true\n\t\t\tbreak\n\t\tend\n\t}\n\tprimeTable.push(i) if !dividable\n}\nstr.each_char {|i|\n\tchararray.push(i)\n}\nchararray.sort!\n\nequlationSet = []\n0.upto(str.length - 1) { |i|\n\ttimes = str.length / primeTable[i]\n\tbreak if(times <= 1)\n\t1.upto(times) { |j|\n\t\tequlationSet.push(primeTable[i] * j) if !equlationSet.include?(primeTable[i] * j)\n\t}\n}\nmaxCharacter = \"\"\nmaxNumber = 0\nnum = 0\ncurChar = chararray[0]\nchararray.each {|i|\n\tif(curChar != i)\n\t\tcurChar = i\n\t\tnum = 1\n\telse\n\t\tif maxNumber < num\n\t\t\tmaxNumber = num\n\t\t\tmaxCharacter = curChar\n\t\tend\n\t\tnum += 1\n\tend\n}\n\nif(maxNumber >= equlationSet.length)\n\tputs \"YES\"\n\tequlationSet.sort!\n\tresult = \"\"\n\tsetInd = 0\n\tcharInd = 0\n\t0.upto(str.length - 1) { |i|\n\t\tif equlationSet[setInd] == i + 1\n\t\t\tresult.concat(maxCharacter)\n\t\t\tsetInd += 1\n\t\telse\n\t\t\twhile str[charInd] == maxCharacter\n\t\t\t\tcharInd += 1\n\t\t\tend\n\t\t\tif(charInd < str.length)\n\t\t\t\tresult.concat(str[charInd])\n\t\t\t\tcharInd += 1\n\t\t\telse\n\t\t\t\tresult.concat(maxCharacter)\n\t\t\tend\n\t\tend\n\t}\n\tputs result\nelse\n\tputs \"NO\"\nend"}], "src_uid": "64700ca85ef3b7408d7d7ad1132f8f81"} {"source_code": "t=gets.chomp.to_i\r\n\r\nt.times do\r\n\r\ns=gets.chomp.split\r\na=s[0].to_i\r\nb=s[1].to_i\r\nif (a==0 && b!=0)\r\n puts 1.to_i\r\nelse\r\n puts (a*1+b*2)+1\r\nend\r\nend", "positive_code": [{"source_code": "Integer(gets).times do\r\n a, b = gets.split.map(&:to_i)\r\n if a == 0\r\n puts 1\r\n else\r\n puts a + b * 2 + 1\r\n end\r\nend"}], "negative_code": [], "src_uid": "2b6e670b602a89b467975edf5226219a"} {"source_code": "n = gets.to_i\n\ncomb = (1..n).to_a.combination(2).to_a\n\nlist = []\n\nwon = {}\nlost = {}\n\n\n(((n * (n-1))/2)-1).times do\n\tl = gets.split(\" \").map(&:to_i)\n\twon[l[0]] ||= []\n\twon[l[0]] << l[1]\n\n\tlost[l[1]] ||= []\n\tlost[l[1]] << l[0]\n\n\tlist << l.minmax\nend\n\nmissed = (comb - list).flatten\n# puts \"#{missed}\"\n# puts \"#{won[missed[0]]}\"\n# puts \"#{lost[missed[1]]}\"\nif ((won[missed[0]]||[]) & (lost[missed[1]] || [])).empty?\n\tmissed[0],missed[1] = missed[1],missed[0]\nend\nputs \"#{missed[0]} #{missed[1]}\"", "positive_code": [{"source_code": "def findij(ar, n)\n\tfor i in 0..n-1\n\t\tfor j in 0..n-1\n\t\t\tnext if i == j\n\t\t\tif ar[i][j] == 0\n\t\t\t\treturn i,j\n\t\t\tend\n\t\tend\t\n\tend\nend\n\nn = gets.to_i\nar = Array.new(n)\nfor i in 0..n-1\n\tar[i] = Array.new(n)\n\tfor j in 0..n-1\n\t\tar[i][j] = 0\n\tend\nend\n\t\nfor i in 1..(n*(n-1)/2-1)\n\ts = gets.chomp\n\tas,bs = s.split(/ /)\n\ta = as.to_i-1\n\tb = bs.to_i-1\n\t\n\tar[a][b] = 1\n\tar[b][a] = -1\nend\n\ni,j = findij(ar,n)\nfor k in 0..n-1\n\tnext if i == k\n\tnext if j == k\n\tif ar[i][k] * ar[k][j] > 0\n\t\tif ar[i][k] > 0\n\t\t\tputs sprintf(\"%d %d\",i+1,j+1)\n\t\telse\n\t\t\tputs sprintf(\"%d %d\",j+1,i+1)\t\t\t\t\t\n\t\tend\n\t\texit\n\tend\t\nend\nputs sprintf(\"%d %d\",i+1,j+1)\n"}], "negative_code": [{"source_code": "n = gets.to_i\nh = Hash.new\nfor i in 1..n\n\tfor j in i+1..n\n\t\th[i.to_s + \" \" + j.to_s] = 0\n\tend\nend\n\t\nfor i in 1..(n*(n-1)/2-1)\n\ts = gets.chomp\n\tas,bs = s.split(/ /)\n\ta = as.to_i\n\tb = bs.to_i\n\tif a > b\n\t\tma = a\n\t\tmb = b\n\telse\n\t\tma = b\n\t\tmb = a\n\tend\n\th.delete(mb.to_s + \" \" + ma.to_s)\nend\n\nh.each_key { |m|\n\tputs m\n}\n"}], "src_uid": "f1ac6da78aed11d9118a85182c5644de"} {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\n\nas.sort!\n\nmex = 1\nfor i in 0...n\n if mex <= as[i] \n as [i] = mex\n mex += 1\n end\nend\n\nputs mex\n", "positive_code": [{"source_code": "#! /usr/bin/env ruby\n\nn=gets.to_i\na=gets.split.map{|v|v.to_i}.sort\nm=1\na.each {|v| m+=1 if v>=m }\nputs m"}, {"source_code": "gets\nm=1\na=gets.chomp.split.map(&:to_i).sort\na.each{|k| m+=1 if k>=m}\nprint(m)"}, {"source_code": "gets\nmex = 1\nnums = gets.split(' ').map(&:to_i).sort.each { |n|\n if n >= mex\n mex += 1\n end\n}\nputs mex\n"}, {"source_code": "p gets.to_i - gets.split.map(&:to_i).sort.map.with_index{|x,i| [i+1-x,0].max}.max + 1"}, {"source_code": "def read_line\n gets.chomp.split.map &:to_i\nend\n\nn = read_line[0]\na = read_line.sort\nx = 1\n\nn.times { |i| \n\tx = x+1 if x<=a[i]\n}\n\nputs x"}, {"source_code": "arrLength = gets.chomp.to_i\narr = gets.chomp.split(' ').map(&:to_i)\n\narr.sort!\ncurrentNum = 1\n\narr.each_with_index do |val, index|\n\tcurrentNum += 1 if val >= currentNum\nend\n\nputs currentNum"}, {"source_code": "#!/usr/bin/ruby\nr=1\ngets;gets.split.map(&:to_i).sort.each{|e|e.to_i>=r&&r+=1}\np r"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\n\nif numbers.count == 1\n puts 2\nelse\n max = 1 \n numbers.each do |n|\n max = max + 1 if n >= max\n end\n puts max \nend "}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nr=1\ngets;gets.split.each{|e|e.to_i>=r&&r+=1}\np r"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\n\nif numbers.count == 1\n puts 2\nelse\n max = 1 \n numbers.each do |n|\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n end\n puts max + 1\nend"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\nif numbers[0] == numbers[-1]\n puts numbers[0] + 1\nelsif numbers[0] > 1\n puts numbers.count + 1\nelse\n max = 1 \n numbers.each do |n|\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n end\n puts max + 1\nend"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\nif numbers[0] > 1\n puts 2\nelse\n max = 1 \n numbers.each do |n|\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n end\n puts max + 1\nend"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\nif numbers[0] > 1 && numbers.count != 1 && numbers[0] == numbers[-1]\n puts 3\nelsif numbers[0] > 1\n puts numbers.count + 1\nelse\n max = 1 \n numbers.each do |n|\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n end\n puts max + 1\nend"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\nif numbers.count != 1 && numbers[0] == numbers[-1]\n puts numbers[0] + 1\nelsif numbers[0] > 1\n puts numbers.count + 1\nelse\n max = 1 \n numbers.each do |n|\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n end\n puts max + 1\nend"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\nif numbers[0] > 1\n puts numbers.count + 1\nelse\n max = 1 \n numbers.each do |n|\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n end\n puts max + 1\nend"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\nif numbers[0] > 1\n puts numbers[0] - 1\nelse\n max = 1 \n numbers.each do |n|\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n end\n puts max + 1\nend"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\nif numbers[0] == numbers[-1]\n puts numbers[0] + 1\nelsif numbers[0] > 1\n puts numbers.count + 1\nelse\n max = 1 \n numbers.each do |n|\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n puts max\n end\n puts max + 1\nend"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\n\nif numbers[0] > 1 || numbers[0] == numbers[-1]\n puts numbers.count + 1\nelse\n max = 1 \n numbers.each do |n|\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n end\n puts max + 1\nend"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\n\n# if numbers[0] > 1\n# puts numbers.count + 1\n# else\n max = 1 \n numbers.each do |n|\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n end\n puts max + 1\n# end"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\n\nif numbers.count == 1\n puts 2\nelse\n max = 1 \n numbers.each do |n|\n puts max\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n end\n puts max + 1\nend"}, {"source_code": "n = gets.to_i\n\nnumbers = gets.split.map(&:to_i)\n\nnumbers.sort!\n\nif numbers.count != 1 && numbers[0] == numbers[-1]\n puts 3\nelsif numbers[0] > 1\n puts numbers.count + 1\nelse\n max = 1 \n numbers.each do |n|\n if n > max + 1\n max = max + 1 \n else\n max = n\n end\n end\n puts max + 1\nend"}, {"source_code": "gets\nm=1\na=gets.chomp.split.map(&:to_i)\na.each{|k| m+=1 if k>=m}\nprint(m)"}, {"source_code": "gets\nm=1\nfor k in gets.split.sort\nif k.to_i>=m\n m=m+1\nend\nend\nprint(m)"}], "src_uid": "482b3ebbbadd583301f047181c988114"} {"source_code": "gets.to_i.times do\n n, k = gets.split.map(&:to_i)\n s = gets.strip\n\n if k == 0 || s == s.reverse\n puts 1\n else\n puts 2\n end\nend\n", "positive_code": [{"source_code": "\ufeffclass Array\r\n def n\r\n return length\r\n end\r\n def z\r\n\treturn length-1\r\nend\r\nend\r\n\r\n$__cur_readed = []\r\n$__cur_index = 0\r\n\r\ndef rs\r\n\twhile $__cur_index >= $__cur_readed.length\r\n\t\t$__cur_readed = gets.split(\" \")\r\n\t\t$__cur_index = 0\r\n\tend\r\n\t$__cur_index+=1\r\n\treturn $__cur_readed[$__cur_index-1]\r\nend\r\n\r\ndef ri\t\r\n\trs.to_i\r\nend\r\n\r\ndef ra2 n\r\n\tArray.new(n) {ri}\r\nend\r\n\r\ndef ra\r\n\tra2 ri\r\nend\r\n\r\nt = ri\r\n\r\nfor _ in (1..t)\r\n\tri\r\n\tk = ri\r\n\ts = rs\r\n\tres = 1\r\n\tif k > 0\r\n\t\tif s != s.reverse\r\n\t\t\tres = 2\r\n\t\tend\r\n\tend\r\n\tputs res\r\nend"}, {"source_code": "case_count = gets.to_i\r\n\r\ncase_count.times do\r\n n, k = gets.chomp.split(\" \").map(&:to_i)\r\n str = gets.chomp\r\n\r\n if k.zero?\r\n puts 1\r\n else\r\n puts str == str.reverse ? 1 : 2\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "case_count = gets.to_i\r\n\r\ncase_count.times do\r\n n, k = gets.split(\" \").map(&:to_i)\r\n str = gets\r\n\r\n if k.zero?\r\n puts 1\r\n else\r\n puts str == str.reverse ? 1 : 2\r\n end\r\nend\r\n"}, {"source_code": "case_count = gets.to_i\r\n\r\ncase_count.times do\r\n n, k = gets.split(\" \").map(&:to_i)\r\n str = gets\r\n\r\n puts str == str.reverse ? 1 : 2\r\nend\r\n"}], "src_uid": "08cd22b8ee760a9d2dacb0d050dcf37a"} {"source_code": "def rest(a, pr, x)\n a.inject(0){|r,j| r + (j>x ? (j-x)*pr : j-x)}\nend\n\ndef solve(a, k)\n x0 = a.min.to_f\n x1 = a.max.to_f\n\n y0 = rest(a, 1-k/100.0, x0)\n return x0 if y0 == 0\n\n y1 = rest(a, 1-k/100.0, x1)\n return x1 if y1 == 0\n\n while x1-x0 > 1e-8\n x2 = (x0+x1)/2\n y2 = rest(a, 1-k/100.0, x2)\n return x2 if y2 == 0\n\n if y2 < 0\n x1 = x2\n else\n x0 = x2\n end\n end\n\n x0\nend\n\nn, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\n#srand(123)\n#a = 10000.times.map{rand(1000)}\n\np solve(a, k).to_f\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\nn,k = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\n\nleft = arr.min.to_f\nright = arr.max.to_f\n\nwhile right-left > 1e-6\n\tmid = (left+right)/2\n\tupper,lower = arr.partition { |v| v > mid }\n\tx = upper.map { |v| v - mid }.inject(&:+)\n\tl = lower.map { |v| v - mid }.inject(&:+)\n\n\tif l+x-x*k/100 >= 0\n\t\tleft = mid\n\telse\n\t\tright = mid\n\tend\nend\n\nprintf \"%.7f\\n\", (left+right)/2\n"}], "negative_code": [], "src_uid": "9fd09b05d0e49236dca45615e684ad85"} {"source_code": "n=gets.to_i\na=gets.split.each_with_index.map{|c,i|[c.to_i,i]}\na.sort_by!{|x,i|x}\nq=-1\nb=[0]*n\na.each do|x,i|\n q=x if q0\r\ncnt+=1\r\n}\r\np cnt < n && last <= mn ? cnt + 1 : cnt\r\n}", "positive_code": [{"source_code": "t = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n x = gets.to_s.split.map {|x| x.to_i }.sort\n a = x.select {|x| x <= 0}\n b = x.select {|x| x > 0}\n\n mindiff = 10 ** 15\n 1.upto(a.size - 1) do |i|\n diff = a[i] - a[i - 1]\n mindiff = diff if diff < mindiff\n end\n\n if b.size != 0 && b[0] <= mindiff\n printf(\"%d\\n\", a.size + 1)\n else\n printf(\"%d\\n\", a.size)\n end\nend\n"}, {"source_code": "INF = 10**18\r\n\r\ndef solve\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i).sort\r\n diff_min = INF\r\n prev = -INF\r\n count = 0\r\n a.each do |x|\r\n diff = x - prev\r\n diff_min = diff if diff_min > diff\r\n break if diff_min < x\r\n count += 1\r\n prev = x\r\n end\r\n puts count\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n solve\r\nend"}, {"source_code": "gets.to_i.times do\r\n gets\r\n xs, ys = gets.split.map(&:to_i).sort.partition { |n| n <= 0 }\r\n p xs.count + (ys.size > 0 && (xs + ys.take(1)).each_cons(2).all? { |a, b| (a - b).abs >= ys[0] } ? 1 : 0)\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n xs, ys = gets.split.map(&:to_i).sort.partition { |n| n <= 0 }\r\n p xs.count + (xs.size <= 1 && ys.size > 0 || (xs.size >= 2 && ys.size >= 1 && (xs[-1] - xs[-2]).abs >= ys[0]) ? 1 : 0)\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n gets\r\n xs, ys = gets.split.map(&:to_i).sort.partition { |n| n <= 0 }\r\n p xs.count + (xs.size <= 1 && ys.size > 0 || (xs.size >= 2 && ys.size >= 1 && (xs[-1] - xs[-2]).abs > ys[0]) ? 1 : 0)\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n gets\r\n xs, ys = gets.split.map(&:to_i).sort.partition { |n| n <= 0 }\r\n p xs.count + (xs.size <= 1 && ys.size > 0 || (xs.size >= 2 && ys.size >= 1 && (xs[-1] + xs[-2]).abs > ys[0]) ? 1 : 0)\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n gets\r\n xs, ys = gets.split.map(&:to_i).sort.partition { |n| n <= 0 }\r\n p xs.count + (xs.size == 0 || (xs.size >= 2 && ys.size >= 1 && (xs[-1] + xs[-2]).abs > ys[0]) ? 1 : 0)\r\nend\r\n"}], "src_uid": "a4b170cc058c485a50bf18982fd96851"} {"source_code": "class Rectangle\n\tattr_reader :x1, :y1, :x2, :y2\n\n\tdef initialize(x1, y1, x2, y2)\n\t\t@x1, @y1, @x2, @y2 = x1, y1, x2, y2\n\tend\n\n\tdef get_area\n\t\tif @x1 <= @x2 and @y1 <= @y2\n\t\t\treturn (@x2 - @x1) * (@y2 - @y1)\n\t\telse\n\t\t\treturn 0\n\t\tend\n\tend\n\n\tdef self.intersect(rect1, rect2)\n\t\tx1, x2 = [rect1.x1, rect2.x1].max, [rect1.x2, rect2.x2].min\n \ty1, y2 = [rect1.y1, rect2.y1].max, [rect1.y2, rect2.y2].min\n \treturn Rectangle.new(x1, y1, x2, y2)\n\tend\nend\n\ndef make_rectangle(n, m, x1, y1, x2, y2)\n\tx = [0, x1 - x2].max\n\ty = [0, y1 - y2].max\n\tx2 = x + n - (x1 - x2).abs\n\ty2 = y + m - (y1 - y2).abs\n\treturn Rectangle.new(x, y, x2, y2)\nend\n\ngets.to_i.times do\n\tn, m, x1, y1, x2, y2 = gets.chomp!.split.map(&:to_i)\n\trect1 = make_rectangle(n, m, x1, y1, x2, y2)\n\trect2 = make_rectangle(n, m, x2, y2, x1, y1)\n\tintersection = Rectangle.intersect(rect1, rect2)\n\ttotal_pieces = Rectangle.new(0, 0, n, m)\n\tputs total_pieces.get_area - rect1.get_area - rect2.get_area + intersection.get_area\nend", "positive_code": [{"source_code": "def min(x, y)\n x < y ? x : y\nend\n\ndef max(x, y)\n x > y ? x : y\nend\n\nclass Rectangle\n attr_reader :x1, :y1, :x2, :y2\n \n def initialize(x1, y1, x2, y2)\n @x1, @y1, @x2, @y2 = x1, y1, x2, y2\n end\n\n def get_s\n if @x1 <= @x2 and @y1 <= @y2\n return (@x1 - @x2).abs * (@y1 - @y2).abs\n else\n return 0\n end\n end\n\n def self.intersect(a, b)\n x1, x2 = max(a.x1, b.x1), min(a.x2, b.x2)\n y1, y2 = max(a.y1, b.y1), min(a.y2, b.y2)\n return Rectangle.new(x1, y1, x2, y2)\n end\nend\n\ndef make_rect(n, m, x1, y1, x2, y2)\n x, y = max(0, x1 - x2), max(0, y1 - y2)\n width, height = n - (x1 - x2).abs, m - (y1 - y2).abs\n Rectangle.new(x, y, x + width, y + height)\nend\n\ngets.to_i.times do\n n, m, x1, y1, x2, y2 = gets.split.map { |v| v.to_i }\n a = make_rect(n, m, x1, y1, x2, y2)\n b = make_rect(n, m, x2, y2, x1, y1)\n c = Rectangle.new(0, 0, n, m)\n d = Rectangle.intersect(a, b)\n puts d.get_s + c.get_s - a.get_s - b.get_s\nend\n"}], "negative_code": [{"source_code": "def min(x, y)\n x < y ? x : y\nend\n\ndef max(x, y)\n x > y ? x : y\nend\n\nclass Rectangle\n attr_reader :x1, :y1, :x2, :y2\n \n def initialize(x1, y1, x2, y2)\n @x1, @x2 = min(x1, x2), max(x1, x2)\n @y1, @y2 = min(y1, y2), max(y1, y2)\n end\n\n def get_s\n if @x1 <= @x2 and @y1 <= @y2\n return (@x1 - @x2).abs * (@y1 - @y2).abs\n else\n return 0\n end\n end\n\n def self.intersect(a, b)\n x1, x2 = max(a.x1, b.x1), min(a.x2, b.x2)\n y1, y2 = max(a.y1, b.y1), min(a.y2, b.y2)\n return Rectangle.new(x1, y1, x2, y2)\n end\nend\n\ndef make_rect(n, m, x1, y1, x2, y2)\n x, y = max(0, x1 - x2), max(0, y1 - y2)\n width, height = n - (x1 - x2).abs, m - (y1 - y2).abs\n Rectangle.new(x, y, x + width, y + height)\nend\n\ngets.to_i.times do\n n, m, x1, y1, x2, y2 = gets.split.map { |v| v.to_i }\n a = make_rect(n, m, x1, y1, x2, y2)\n b = make_rect(n, m, x2, y2, x1, y1)\n c = Rectangle.new(0, 0, n, m)\n d = Rectangle.intersect(a, b)\n puts d.get_s + c.get_s - a.get_s - b.get_s\nend\n"}], "src_uid": "8e89fc6c3dfa30ac8c3495e2b1a1e106"} {"source_code": "n = gets.to_i\nary = gets.strip.split.map(&:to_i)\n\nhsh = {}\nary.each {|x| hsh[x] = ((hsh[x] || 0) + 1)}\n\nputs n - hsh.values.max\n", "positive_code": [{"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i).sort\nlen = 1\nmax = 1\n(1...N).each do |i|\n if as[i-1] == as[i]\n len += 1\n max = len if max < len\n else\n len = 1\n end\nend\nputs N - max"}, {"source_code": "\ndef countzz(xs)\n xss = xs.sort\n chunks = xss.chunk{|x|x}.map{|a,b|b.size}.to_a\n use_chunks = chunks.clone\n\n use_index = 0\n count = 0\n\n chunks.each.with_index do |size, i|\n use_index = [use_index, i + 1].max\n\n while size > 0 && use_index < use_chunks.size\n if use_chunks[use_index] > size\n take = size\n count += take\n size = 0\n use_chunks[use_index] -= take\n else\n take = use_chunks[use_index]\n count += take\n size -= take\n use_chunks[use_index] = 0\n use_index += 1\n end\n end\n end\n count\nend\n\ndef solution\n gets\n xs = read_ints\n puts countzz(xs)\nend\n\ndef read_ints\n gets.split.map &:to_i\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution"}], "negative_code": [{"source_code": "def countzz(xs)\n xss = xs.sort\n chunks = xss.chunk{|x|x}.map{|a,b|b.size}.to_a\n use_chunks = chunks.clone\n\n use_index = 0\n count = 0\n\n chunks.each.with_index do |size, i|\n use_index = [use_index, i + 1].max\n\n return count if use_index >= use_chunks.size\n\n while size > 0 && use_index < use_chunks.size\n if use_chunks[use_index] > size\n count += size\n size = 0\n use_chunks[use_index] -= size\n else\n count += use_chunks[use_index]\n size -= count\n use_chunks[use_index] -= 0\n use_index += 1\n end\n end\n end\n count\nend\n\ndef solution\n gets\n xs = read_ints\n puts countzz(xs)\nend\n\ndef read_ints\n gets.split.map &:to_i\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution "}, {"source_code": "def countzz(xs)\n xss = xs.sort\n chunks = xss.chunk{|x|x}.map{|a,b|b.size}.to_a\n use_chunks = chunks.clone\n\n use_index = 0\n count = 0\n\n chunks.each.with_index do |size, i|\n use_index = [use_index, i + 1].max\n\n return count if use_index >= use_chunks.size\n\n while size > 0 && use_index < use_chunks.size\n if use_chunks[use_index] > size\n count += size\n size = 0\n use_chunks[use_index] -= size\n else\n count += use_chunks[use_index]\n size -= count\n use_chunks[use_index] = 0\n use_index += 1\n end\n end\n end\n count\nend\n\ndef solution\n gets\n xs = read_ints\n puts countzz(xs)\nend\n\ndef read_ints\n gets.split.map &:to_i\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution "}, {"source_code": "\ndef countzz(xs)\n xss = xs.sort\n chunks = xss.chunk{|x|x}.map{|a,b|b.size}.to_a\n use_chunks = chunks.clone\n\n use_index = 0\n count = 0\n\n chunks.each.with_index do |size, i|\n use_index = [use_index, i + 1].max\n\n return count if use_index >= use_chunks.size\n\n while size > 0 && use_index < use_chunks.size\n if use_chunks[use_index] > size\n count += size\n size = 0\n use_chunks[use_index] -= size\n else\n count += use_chunks[use_index]\n size -= count\n use_chunks[use_index] -= 0\n end\n use_index += 1\n end\n end\n count\nend\n\ndef solution\n gets\n xs = read_ints\n\n puts countzz(xs)\n\nend\n\ndef read_ints\n gets.split.map &:to_i\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution"}], "src_uid": "eaa768dc1024df6449e89773234cc0c3"} {"source_code": "t = gets.to_i\nt.times do\n x, n, m = gets.split.map(&:to_i)\n n.times do\n if x > 20\n x = x / 2 + 10\n else\n break\n end\n end\n puts (x <= m * 10) ? \"YES\" : \"NO\"\nend\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n x, n, m = gets.chomp.split.map(&:to_i)\n\n n.times do\n if (x/2)+10 < x\n x = (x/2)+10\n else\n break\n end\n\n end\n\n x = x-(m*10)\n\n if x <= 0\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "file = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nt = file.gets.to_i\n\nwhile t != 0\n h, n, m = file.gets.split.map(&:to_i)\n defeat = 'NO'\n\n while n > 0 || m > 0\n if h >= 20 && n > 0\n h = h / 2 + 10\n n -= 1\n elsif m > 0\n h -= 10\n m -= 1\n else\n h = h / 2 + 10\n n -= 1\n end\n if h <= 0\n defeat = 'YES'\n break;\n end\n end\n puts defeat\n t -= 1\nend\n"}, {"source_code": "gets.to_i.times {\n x, n, m = gets.split.map { |v| v.to_i }\n n.times {\n break if x < 21\n x = x / 2 + 10\n }\n x -= m * 10\n puts x > 0 ? \"NO\" : \"YES\"\n}\n"}, {"source_code": "def can_defeat_dragon(x, n, m)\n while x > 0 && (n > 0 || m > 0)\n if m > 0 && x <= m * 10\n x = x - (m * 10)\n m = 0\n end\n\n if x > 0\n if n > 0\n x = x / 2 + 10\n n = n - 1\n elsif m > 0\n x = x - 10\n m = m - 1\n end\n end\n end\n\n if x <= 0\n \"YES\"\n else\n \"NO\"\n end\nend\n\nt = gets.chomp.to_i\n\nt.times do\n x, n, m = gets.chomp.split(' ').map(&:to_i)\n puts can_defeat_dragon(x, n, m)\nend"}, {"source_code": "1.upto(gets.chomp.to_i) do\n x,n,m = gets.chomp.split.map(&:to_i)\n while x > 20 && n > 0\n n -= 1\n x = x/2 + 10\n end\n while x > 0 && m > 0\n m -= 1\n x -= 10\n end\n if x <= 0\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "1.upto(gets.to_i) do\n x, a, b = gets.split(' ').map(&:to_i)\n\n while x > 20 && a > 0\n x = x.div(2) + 10\n a -= 1\n end\n\n puts (10*b >= x) ? 'YES' : 'NO'\nend\n"}], "negative_code": [{"source_code": "file = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nt = file.gets.to_i\n\nwhile t != 0\n h, n, m = file.gets.split.map(&:to_i)\n defeat = 'NO'\n\n while n > 0 || m > 0\n if h >= 20 && n > 0\n h = h / 2 + 10\n n -= 1\n elsif m > 0\n h -= 10\n m -= 1\n else\n puts \"--------------------------\"\n puts \"n: #{n}\"\n puts \"m: #{m}\"\n puts \"=================\"\n puts \"h: #{h}\"\n h = h / 2 + 10\n n -= 1\n end\n if h <= 0\n defeat = 'YES'\n break;\n end\n end\n puts defeat\n t -= 1\nend\n"}], "src_uid": "78f25e2bc4ff22dbac94f72af68a745f"} {"source_code": "testcases = gets.chomp.to_i\ntestcases.times do\n bags = gets.chomp.to_i\n j_bags = (1..bags).to_a\n puts j_bags.size\n puts j_bags.join(\" \")\nend\n", "positive_code": [{"source_code": "gets.to_i.times{\n n=gets.to_i\n p n-1\n t = []\n (n-1).times{|x|\n t << x + 2\n }\n puts t*' '\n}"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n puts n\n puts (1..n).to_a.join ' '\nend "}], "negative_code": [{"source_code": "gets.to_i.times{\n n=gets.to_i\n p n-1\n t = []\n (n-1).times{|x|\n t << x + 1\n }\n puts t*' '\n}"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n puts n\n puts (1..n).to_a.reverse.join ' '\nend "}, {"source_code": "testcases = gets.chomp.to_i\n\ntestcases.times do\n bags = gets.chomp.to_i\n total_moves = 0\n j_bags = []\n baggies = (1..bags).to_a\n while baggies.uniq.length > 1\n\n max = baggies.max\n max_bag = baggies.find_index { |x| x == max }\n\n j_bags << max_bag + 1\n baggies = baggies.each_with_index.map do |x, i|\n x += 1 unless i == max_bag\n x\n end\n total_moves += 1\n\n end\n puts total_moves\n puts j_bags.join(\" \")\n \nend\n"}, {"source_code": "\ntestcases = gets.chomp.to_i\n\ntestcases.times do \n bags = gets.chomp.to_i\n puts 1\n puts bags\nend"}], "src_uid": "ac248c83c99d8a2262772816b5f4ac6e"} {"source_code": "n=gets.to_i\na=[]\n0.upto(n-1) do |i|\n a[i]=gets.chomp.scan(/\\w+/)\nend\nfor i in 0..n-1 do\n for j in 0..n-1 do\n a[i][j]=a[i][j].to_i\n end\nend\nb=[]\nfor i in 0..n-1 do\n b[i]=0\n for j in 0..n-1 do\n b[i]+=a[i][j]\n end\nend\nc=[]\nfor j in 0..n-1 do\n c[j]=0\n for i in 0..n-1 do\n c[j]+=a[i][j]\n end\nend\nk=0\nfor i in 0..n-1 do\n for j in 0..n-1 do\n if (b[i] row\n cnt += 1\n end\n end\nend\nputs cnt\n"}, {"source_code": "n = gets.to_i\nary = Array.new(n).map!{ Array.new(n, 0) }\nn.times { |r|\n s = gets.split.map(&:to_i)\n n.times { |c|\n ary[r][c] = s[c]\n }\n}\ncnt = 0\nn.times { |r|\n n.times { |c|\n col = 0\n row = 0\n n.times { |i|\n col += ary[i][c]\n }\n n.times { |i|\n row += ary[r][i]\n }\n cnt += 1 if col > row\n }\n}\np cnt\n"}, {"source_code": "n = gets.to_i\nary = Array.new(n).map!{ Array.new(n, 0) }\nn.times { |r|\n s = gets.split.map{ |e| e.to_i }\n n.times { |c|\n ary[r][c] = s[c]\n }\n}\ncnt = 0\nn.times { |r|\n n.times { |c|\n col = 0\n row = 0\n n.times { |i|\n col += ary[i][c]\n }\n n.times { |i|\n row += ary[r][i]\n }\n if col > row; cnt += 1; end;\n }\n}\np cnt\n"}, {"source_code": "def winning?(rowpos, colpos, elem, game)\n\t\n\t# check row sum\n\trowsum = 0\n\t$n.times do |i|\n\t\trowsum += game[rowpos][i].to_i\n\tend\n\t\n\t# check col sum\n\tcolsum = 0\n\t$n.times do |i|\n\t\tcolsum += game[i][colpos].to_i\n\tend\n\t\n\tcolsum > rowsum\nend\n\n$n = STDIN.gets.chomp.to_i\ngame = []\n$n.times do |i|\n\tgame << STDIN.gets.chomp.split(' ').map{|ch| ch.to_i}\nend\n\n\ncount = 0\nrowpos = 0\ngame.each do |row|\n\tcolpos = 0\n\trow.each do |elem|\n\t\tcount += 1 if winning?(rowpos, colpos, elem, game)\n\t\tcolpos += 1\n\tend\n\trowpos += 1\nend\n\nputs count"}, {"source_code": "n = gets.to_i\nboard = []\nsumg = []\nsumv = Array.new(n){|i| i = 0}\nn.times do |i|\n s = gets.split.map{|i| i.to_i}\n sum = 0\n s.map{|i| sum +=i}\n sumg << sum\n n.times do |j|\n sumv[j] += s[j]\n end\nend\nres = 0\nn.times do |i|\n n.times do |j|\n if sumg[i] < sumv[j] then\n res += 1\n end\n end\nend\n\nputs res"}, {"source_code": "n = gets.to_i\na = Array.new(n){gets.split.map &:to_i}\nc = 0\nn.times{|i|\n n.times{|j|\n x, y = 0, 0\n n.times{|k|\n x += a[i][k]\n y += a[k][j]\n }\n c += 1 if x < y\n }\n}\np c\n"}, {"source_code": "n = gets.to_i\nmap = []\nn.times do\n map << gets.split.map(&:to_i)\nend\nans = 0\nn.times do |x|\n n.times do |y|\n s1, s2 = 0, 0\n n.times do |i|\n s1+=map[i][x]\n s2+=map[y][i]\n end\n ans += 1 if s1>s2\n end\nend\np ans\n"}, {"source_code": "\ufeffn = gets.chomp.to_i\n\nfield = []\nn.times do\n field << gets.chomp.split(\" \").map{|e| e.to_i}\nend\n\nwin = 0\n\nfield.each_with_index do |column, col_no|\n column_sum = column.inject(0){|sum, i| sum += i}\n \n column.each_with_index do |e, row_no|\n row_sum = 0\n 0.upto(field.length - 1) do |a|\n row_sum += field[a][row_no]\n end\n \n if row_sum > column_sum\n win += 1\n end \n end\nend\n\nputs win"}, {"source_code": "def win? i, j\n $array[i].inject(:+) < $array.transpose[j].inject(:+)\nend\nind = (0...gets.to_i).to_a\n$array = readlines.map(&:split).each { |a| a.map!(&:to_i) }\nputs ind.product(ind).count { |i, j| win? i, j }"}, {"source_code": "n = gets.to_i\nrow_sum = []\ncol_sum = Array.new(n) { 0 }\nn.times do\n\tsum = 0\n\tgets.split(\"\\s\").map { |x| x.to_i}.each_with_index do |x, i|\n\t\tcol_sum[i] += x\n\t\tsum += x\n\tend\n\trow_sum << sum\nend\n\ncells = 0\nj = 0\ncol_sum.sort!\nrow_sum.sort.each_with_index do |r, i|\n\twhile j < n\n\t\tif r < col_sum[j]\n\t\t\tbreak\n\t\telse\n\t\t\tj += 1\n\t\t\tcells += i\n\t\tend\n\tend\nend\ncells += n * (n - j)\nputs cells"}, {"source_code": "n=gets.chomp.to_i\nsumcolumns=Array.new(n,0)\nsumrows=Array.new(n,0)\nfor i in 0..(n-1)\n temp= gets.chomp.split.collect{|a| a.to_i}\n sumrows[i]=temp.reduce(:+)\n temp.each_index{|a| sumcolumns[a]=sumcolumns[a]+temp[a]}\nend\ncount=0\nsumcolumns.each{|a|count=count+sumrows.count{|b| a>b }}\nprint count \n\n"}, {"source_code": "n = gets.to_i\nnss = n.times.map{gets.split.map(&:to_i)}\n\nanswer = 0.upto(n-1).map do |i|\n 0.upto(n-1).count do |j|\n nss[i].reduce(:+) < nss.map{|row| row[j]}.reduce(:+)\n end\nend.reduce(:+)\n\np answer\n"}, {"source_code": "public \n\ndef solve(matrix)\n lines = {}\n cols = {}\n\n matrix.each_with_index do |x,i|\n lines[i] = x.inject(0){|z,s| s + z}\n end\n\n transpose(matrix).each_with_index do |x,i|\n cols[i] = x.inject(0){|z,s| s + z}\n end\n \n size = matrix[0].count\n win = 0\n (0...size).each do |i|\n (0...size).each do |j|\n win += 1if cols[i] > lines[j]\n end\n end\n \n win\nend\n\ndef transpose(matrix)\n size = matrix[0].count\n transponent = []\n \n (0...size).each do |i|\n transponent[i] = [1]*size\n end\n \n (0...size).each do |i|\n (0...size).each do |j|\n transponent[i][j] = matrix[j][i]\n end\n end\n transponent\nend\n\ndef read(input)\n input.split(\"\\n\")\nend\n\ndef plow(list)\n list.collect{|y| y.split(\" \").collect{|x| x.to_i}}[1..-1]\nend\n\nif __FILE__ == $PROGRAM_NAME\n print solve(plow(read(STDIN.read)))\nend\n"}, {"source_code": "n = gets.chomp.to_i\nsquares = Array.new(n) { gets.split.collect{|x| x.to_i} }\n \nwinning = 0\n(0..n-1).each{|i|\n row_sum = 0\n squares[i].collect{|x| row_sum += x}\n (0..n-1).each{|j|\n col_sum = 0\n squares.each{|s|\n col_sum += s[j]\n }\n winning += 1 if col_sum > row_sum\n }\n}\n\nputs winning"}, {"source_code": "n = gets.to_i\nboard = []\nfor i in 0..(n-1)\n\tboard[i] = []\n\tline = gets.split \n\tfor j in 0 .. (n-1)\n\t\tboard[i] << line[j].to_i\n\tend\nend\n\nrow = []\ncol = []\nfor i in 0..n-1\n\trowSum = 0\n\tcolSum = 0\n\tfor j in 0..n-1\n\t\trowSum += board[i][j]\n\t\tcolSum += board[j][i]\n\tend\n\trow[i] = rowSum\n\tcol[i] = colSum\nend\n\ncount = 0\nfor i in 0..n-1\n\tfor j in 0..n-1\n\t\tif(col[i] > row[j])\n\t\t\tcount += 1\n\t\tend\n\tend\nend\n\nputs count"}, {"source_code": "n = gets.chomp.to_i\nb = []\nrow_sums = []\ncol_sums = []\nfor i in 0...n\n b[i] = gets.chomp.split.map { |x| x.to_i }\n row_sums[i] = b[i].inject(:+)\n for j in 0...n\n col_sums[j] = (col_sums[j] || 0) + b[i][j]\n end\nend\n\ncount = 0\nfor i in 0...n\n for j in 0...n\n count += 1 if col_sums[i] > row_sums[j]\n end\nend\nputs count"}, {"source_code": "# Codeforces Round #110\n# Problem A -- Game Outcome\na = []\nn = gets.to_i\nn.times { a << gets.split.map(&:to_i) }\nrows = (columns = [0] * n).dup\n(0...n).each do |i|\n (0...n).each do |j|\n rows[i] += a[i][j]\n columns[j] += a[i][j]\n end\nend\nputs rows.product(columns).select {|x, y| x < y }.size\n"}, {"source_code": "board = Array.new(gets.to_i) { gets.split.map(&:to_i) }\n\nrows_sum = board.map {|row| row.reduce(:+) }\ncols_sum = board.transpose.map {|col| col.reduce(:+) }\n\ncount = 0\nrows_sum.each do |rs|\n cols_sum.each do |cs|\n if rs < cs\n\t count += 1\n\tend\n end\nend\n\nputs count"}, {"source_code": "n = gets.to_i\nboard = Array.new\nrowSums = Array.new\nn.times do\n row = gets.split(\" \")\n row = row.map do |e|\n e.to_i\n end\n rowSums.push(row.inject(:+))\n board.push(row)\nend\n\ncolSums = Array.new\n\nfor col in 0...n\n colSum = 0\n for row in 0...n\n colSum += board[row][col]\n end\n colSums[col] = colSum\nend\n\ntotal = 0\nfor i in 0...n\n for j in 0...n\n if (colSums[j] > rowSums[i])\n total += 1\n end\n end\nend\n\nputs total\n"}, {"source_code": "n = gets.to_i\nright = Array.new(n) { 0 }\ndown = Array.new(n) { 0 }\n\nn.times do |i|\n gets.split.each_with_index do |element, index|\n a =element.to_i\n right[i] = right[i] + a\n down[index] = down[index] + a\n end\nend\ncounter = 0\nright.sort!\ndown.sort!\ndown.each do |i|\n plus = right.find_index { |j| j>=i }\n if plus\n counter = counter + plus\n else\n counter = counter + right.size\n end\nend\np counter\n"}], "negative_code": [{"source_code": "def winning?(rowpos, colpos, elem, game)\n\t\n\t# check row sum\n\trowsum = 0\n\t$n.times do |i|\n\t\trowsum += game[rowpos][i].to_i\n\tend\n\t\n\t# check col sum\n\tcolsum = 0\n\t$n.times do |i|\n\t\tcolsum += game[i][colpos].to_i\n\tend\n\t\n\tcolsum > rowsum\nend\n\n$n = STDIN.gets.chomp.to_i\ngame = []\n$n.times do |i|\n\tgame << STDIN.gets.chomp.split(' ').map{|ch| ch.to_i}\nend\n\n\nres = 0\nrowpos = 0\ngame.each do |row|\n\tcolpos = 0\n\trow.each do |elem|\n\t\tres = elem if winning?(rowpos, colpos, elem, game)\n\t\tcolpos += 1\n\tend\n\trowpos += 1\nend\n\nputs res"}, {"source_code": "n = gets.to_i\nrow_sum = []\ncol_sum = Array.new(n) { 0 }\nn.times do\n\tsum = 0\n\tgets.split(\"\\s\").map { |x| x.to_i}.each_with_index do |x, i|\n\t\tcol_sum[i] += x\n\t\tsum += x\n\tend\n\trow_sum << sum\nend\n\ncells = 0\nj = 0\ncol_sum.sort!\nrow_sum.sort.each_with_index do |r, i|\n\twhile j < n\n\t\tif r < col_sum[j]\n\t\t\tbreak\n\t\telse\n\t\t\tj += 1\n\t\t\tcells += i\n\t\tend\n\tend\nend\n\nputs cells"}, {"source_code": "n = gets.chomp.to_i\nb = []\nrow_sums = []\ncol_sums = []\nfor i in 0...n\n b[i] = gets.chomp.split.map { |x| x.to_i }\n row_sums[i] = b[i].inject(:+)\n for j in 0...n\n col_sums[j] = (col_sums[j] || 0) + b[i][j]\n end\nend\n\ncount = 0\nfor i in 0...n\n for j in 0...n\n count += 1 if row_sums[i] > col_sums[j]\n end\nend\nputs count"}, {"source_code": "n = gets.to_i\nright = Array.new(n){0}\ndown = Array.new(n){0}\n\nn.times do |i|\n gets.split.each_with_index do |element,index|\n a =element.to_i\n right[i] = right[i] + a\n down[index] = down[index] + a\n end\nend\ncounter = 0\nright.sort!\ndown.sort!\ndown.each do |i|\n plus = right.find_index{|j| j>=i}\n counter = counter + plus unless plus.nil?\nend\np counter\n"}], "src_uid": "6e7c2c0d7d4ce952c53285eb827da21d"} {"source_code": "t = gets.to_i\n\n(1).upto(t) do\n n = gets.to_i\n a = gets.split(' ').map(&:to_i)\n i = -1\n j = n\n turn = true\n x=0\n y=0\n z=0\n prev = 0\n cur = 0\n while(i+1prev)\n break\n end\n end\n else\n while(true)\n j-=1\n if(i==j)\n break\n end\n cur+=a[j]\n y+=a[j]\n if(cur>prev)\n break\n end\n end\n end\n z+=1\n turn = !turn\n end\n puts \"#{z} #{x} #{y}\"\nend\n", "positive_code": [{"source_code": "# Created by IntelliJ IDEA.\n# User: gautam.roy\n# Date: 5/10/20\n# Time: 10:29 PM\n# To change this template use File | Settings | File Templates.\nt = gets.to_i\nfor i in 1..t do\n n = gets.to_i\n a = gets.split(' ').map { |s| s.to_i }\n atot = 0\n btot = 0\n moves = 0\n lind = 0\n rind = a.size - 1\n bsum = 0\n while lind <= rind\n # a moves\n asum = 0\n while lind <= rind && asum <= bsum\n asum = asum + a[lind]\n lind += 1\n end\n if asum != 0\n moves += 1\n atot += asum\n end\n # puts \"lind #{lind} asum #{asum}\"\n\n # b moves\n bsum = 0\n while lind <= rind && bsum <= asum\n bsum = bsum + a[rind]\n rind -= 1\n end\n if bsum != 0\n moves += 1\n btot += bsum\n end\n # puts \"rind #{rind} bsum #{bsum}\"\n end\n puts \"#{moves} #{atot} #{btot}\"\nend\n"}, {"source_code": "gets.to_i.times{\n n=gets.to_i\n a=gets.split.map &:to_i\n res=0, 0, 0\n s=t=0\n while a.size>0\n s=0\n s+=a.shift while a.size>0 and s<=t\n res[1]+=s\n res[0]+=1\n\n break if a.empty?\n\n t=0\n t+=a.pop while a.size>0 and t<=s\n res[2]+=t\n res[0]+=1\n end\n\n puts res*' '\n}\n"}, {"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n n = gets.to_i\n moves, remains, alice, bob, last_eaten = 0, 0, 0, 0, 0\n\n a = gets.split.map { |i|\n i = i.to_i\n remains += i\n i\n }\n turn = :alice\n while !a.empty?\n if remains > last_eaten\n tmp = 0\n while tmp <= last_eaten\n tmp += a.shift if turn == :alice\n tmp += a.pop if turn == :bob\n end\n\n moves += 1\n remains -= tmp\n last_eaten = tmp\n alice += tmp if turn == :alice\n bob += tmp if turn == :bob\n\n if turn == :alice\n turn = :bob\n else\n turn = :alice\n end\n else\n break\n end\n end\n\n # clean-up\n if turn == :alice\n alice += remains\n else\n bob += remains\n end\n\n # and if remains are available, add one move (cleanup eating)\n if remains > 0\n moves += 1\n end\n \n puts \"#{moves} #{alice} #{bob}\"\n}"}], "negative_code": [{"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n moves, remains, alice, bob, last_eaten = 0, 0, 0, 0, 0\n\n a = gets.split.map { |i|\n i = i.to_i\n remains += i\n i\n }\n turn = :alice\n while !a.empty?\n if remains > last_eaten\n tmp = 0\n while tmp <= last_eaten\n tmp += a.shift if turn == :alice\n tmp += a.pop if turn == :bob\n end\n\n moves += 1\n remains -= tmp\n last_eaten = tmp\n alice += tmp if turn == :alice\n bob += tmp if turn == :bob\n\n if turn == :alice\n turn = :bob\n else\n turn = :alice\n end\n else\n break\n end\n end\n\n # clean-up\n if turn == :alice\n alice += remains\n else\n bob += remains\n end\n\n # and if remains are available, add one move (cleanup eating)\n if remains > 0\n moves += 1\n end\n \n puts \"#{moves} #{alice} #{bob}\"\n}"}], "src_uid": "d70ee6d3574e0f2cac3c683729e2979d"} {"source_code": "a, d = gets.split(' ').map { |e| e = e.to_f }\nn = gets.to_i\n\ndef getCoord st, c, a\n\tac = (a-c).round(4)\n\tc = c.round(4)\n\n\tcase st\n\t\twhen 0 then \"#{c} 0\"\n\t\twhen 1 then \"#{a} #{c}\"\n\t\twhen 2 then \"#{a-c} #{a}\"\n\t\twhen 3 then \"0 #{a - c}\"\n\tend\nend\n\n\nstate = 0\nc = 0\ncd = d\n\nfor i in 0...n\n\tm = (cd / a).floor\n\tstate = (state + m) % 4\n\tc = cd - m * a\n\tcd = c + d\n\n\tputs getCoord state, c, a\nend", "positive_code": [{"source_code": "eps = 1e-5\na,d = gets.chomp!.split.map { |e| e.to_f}\nn =gets.chomp!.to_i\ncur_x=0.00\ncur_y=0.00\npp=0.00\n\nn.times {\n\tif cur_y <= eps\n\t\tpp = cur_x\t\n\t#\tp 0\n\telsif a-cur_x <= eps\n\t\tpp = a + cur_y\n\t#\tp 1\n\telsif a-cur_y <= eps\n\t\tpp = a*3 -cur_x\t\n\t#\tp 2\n\telse\n\t\tpp = a*4 -cur_y\n\t#\tp 3\n\tend\t\n\tpp +=d;\n\tt= (pp/a).floor\n\t# puts \"asd #{pp} #{t} #{pp}\"\n\tpp -= 1.0*t*a;\n\n\tcase t%4\n\twhen 0\n\t\tcur_x=pp\n\t\tcur_y=0\n\twhen 1\n\t\tcur_x=a\n\t\tcur_y=pp\n\twhen 2\n\t\tcur_x=a-pp\n\t\tcur_y=a\n\twhen 3\n\t\tcur_x=0\n\t\tcur_y=a-pp\n\tend\n\t\n\tprintf(\"%.8f %.8f\\n\",cur_x,cur_y)\n}"}], "negative_code": [], "src_uid": "d00b8423c3c52b19fec25bc63e4d4c1c"} {"source_code": "D = [2 ** 24, 2 ** 16, 2 ** 8, 1]\n\ndef from_ip(ip)\n ip.split('.').each_with_index.map{ |n, i| n.to_i * D[i] }.reduce(:+)\nend\n\ndef to_ip(ip)\n 4.times.map{ |i| (ip / D[i]).tap{ ip %= D[i] } }.join('.')\nend\n\ndef mask(n)\n ('1' * n << '0' * (32 - n)).to_i(2)\nend\n\nn, k = gets.split.map(&:to_i)\n\nips = []\n\nn.times{ ips << from_ip(gets) }\nips.sort!\n\n32.times do |i|\n next if i == 0 || 2 ** i < k\n m = mask(i)\n net = -1\n c = 0\n ips.each do |ip|\n ip_net = ip & m\n unless ip_net == net\n net = ip_net\n c += 1\n end\n end\n\n if c == k\n puts to_ip(m)\n exit\n end\n\nend\n\nputs -1\n", "positive_code": [{"source_code": "class MaskGuesser\n def initialize num_networks, ip_list\n raise Exception unless ip_list.kind_of?(Array)\n @num_networks = num_networks\n @ip_list = Array.new(ip_list.map {|ip| ip_to_bitmask(ip)})\n end\n\n def guess_mask\n mask = 0\n 31.downto(1) do |i|\n mask += 2**i\n masked_ip_list = @ip_list.map {|ip| ip&mask}.uniq\n return bitmask_to_ip(mask) if masked_ip_list.length == @num_networks\n end\n return \"-1\"\n end\n\n def bitmask_to_ip bitmask\n filter = 255\n a = (bitmask & (filter << 24)) >> 24\n b = (bitmask & (filter << 16)) >> 16\n c = (bitmask & (filter << 8)) >> 8\n d = bitmask & filter\n return \"#{a}.#{b}.#{c}.#{d}\"\n end\n\n def ip_to_bitmask ip\n bit_segments = ip.split('.').map(&:to_i)\n raise Exception if bit_segments.length != 4\n bitmask = bit_segments[0] << 24 | bit_segments[1] << 16 | bit_segments[2] << 8 | bit_segments[3]\n #bitmask = (bit_segments[0] << 24) + (bit_segments[1] << 16) + (bit_segments[2] << 8) + bit_segments[3]\n return bitmask\n end\nend\n\ndef main\n num_ip, num_networks = gets.split(/\\s+/).map(&:to_i)\n ip_list = []\n num_ip.downto(1) do\n ip_list << gets\n end\n m = MaskGuesser.new(num_networks, ip_list)\n puts m.guess_mask\nend\n\nmain"}, {"source_code": "at_exit do\n n,k = get_numbers_from_line[0..1]\n ips = []\n n.times do\n octets = gets.strip.split('.').map(&:to_i)\n ips << (0...4).reduce(0){|result,i| result + (octets[i] << (8*i)) }\n end\n\n ip_and = 1<<32 - 1\n ip_or = 0\n (0...n).each do |i|\n ip_and &= ips[i]\n ip_or |= ips[i]\n end\n ip_xor = ip_and ^ ip_or\n\n result_mask = '-1'\n mask = 0\n start_i = [Math.log(k,2).ceil - 1, 0].max\n (0...start_i).each do |i|\n octet = i/8\n bit = 7 - i%8\n mask |= 1 << (octet*8 + bit)\n end\n\n i = start_i\n while i < 32\n octet = i/8\n bit = 7 - i%8\n absolute_bit = octet*8 + bit\n mask |= 1 << absolute_bit\n nets = ips.map{|ip| ip & mask }.uniq\n if nets.length == k\n result_mask = (1..4).map{|j| (mask & ((1<> ((j-1)*8)}.join('.')\n break\n elsif nets.length > k\n break\n end\n\n while true\n i += 1\n break if i >= 32\n octet = i/8\n bit = 7 - i%8\n absolute_bit = octet*8 + bit\n mask |= 1 << absolute_bit\n break if (ip_xor & (1 << absolute_bit)) != 0\n end\n end\n\n puts result_mask\nend\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend"}], "negative_code": [{"source_code": "at_exit do\n n,k = get_numbers_from_line[0..1]\n ips = []\n n.times do\n octets = gets.strip.split('.').map(&:to_i)\n ips << (0...4).reduce(0){|result,i| result + (octets[i] << (8*i)) }\n end\n\n ip_and = 1<<32 - 1\n ip_or = 0\n (0...n).each do |i|\n ip_and &= ips[i]\n ip_or |= ips[i]\n end\n ip_xor = ip_and ^ ip_or\n\n result_mask = '-1'\n start_i = Math.log(k,2).ceil - 1\n mask = 0\n (0...start_i).each do |i|\n octet = i/8\n bit = 7 - i%8\n mask |= 1 << (octet*8 + bit)\n end\n\n i = start_i\n while i < 32\n octet = i/8\n bit = 7 - i%8\n absolute_bit = octet*8 + bit\n mask |= 1 << absolute_bit\n nets = ips.map{|ip| ip & mask }.uniq\n if nets.length == k\n result_mask = (1..4).map{|j| (mask & ((1<> ((j-1)*8)}.join('.')\n break\n elsif nets.length > k\n break\n end\n\n while i < 32\n i += 1\n octet = i/8\n bit = 7 - i%8\n absolute_bit = octet*8 + bit\n mask |= 1 << absolute_bit\n break if (ip_xor & (1 << absolute_bit)) != 0\n end\n end\n\n puts result_mask\nend\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend"}, {"source_code": "at_exit do\n n,k = get_numbers_from_line[0..1]\n ips = []\n n.times do\n ips << gets.strip.split('.').map(&:to_i)\n end\n\n result_mask = '-1'\n start_i = Math.log(k,2).floor\n mask = [0]*4\n (0...start_i).each do |i|\n octet = i/8\n bit = 7 - i%8\n mask[octet] |= 1 << bit\n end\n\n (start_i...32).each do |i|\n octet = i/8\n bit = 7 - i%8\n mask[octet] |= 1 << bit\n nets = ips.map{|ip| get_net_ip(ip, mask) }.uniq\n if nets.length == k\n result_mask = mask.join('.')\n break\n elsif nets.length > k\n break\n end\n end\n\n puts result_mask\nend\n\ndef get_net_ip(ip, mask)\n (0...4).map{|i| ip[i] & mask[i] }\nend\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend"}, {"source_code": "at_exit do\n n,k = get_numbers_from_line[0..1]\n ips = []\n n.times do\n ips << gets.strip.split('.').map(&:to_i)\n end\n\n result_mask = '-1'\n start_i = Math.log(k,2).ceil\n mask = [0]*4\n (0...start_i).each do |i|\n octet = i/8\n bit = 7 - i%8\n mask[octet] |= 1 << bit\n end\n (start_i...32).each do |i|\n octet = i/8\n bit = 7 - i%8\n mask[octet] |= 1 << bit\n nets = ips.map{|ip| get_net_ip(ip, mask) }.uniq\n if nets.length == k\n result_mask = mask.join('.')\n break\n elsif nets.length > k\n break\n end\n end\n\n puts result_mask\nend\n\ndef get_net_ip(ip, mask)\n (0...4).map{|i| ip[i] & mask[i] }\nend\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend"}], "src_uid": "4da4410d3b75ee87a4dfa33b437b9cfa"} {"source_code": "t = gets.chomp.to_i\nt.times {\n nk = gets.chomp.split(' ').map(&:to_i)\n n = nk[0]\n k = nk[1]\n arr = gets.chomp.split(' ').map(&:to_i)\n max = arr.max\n arr.map! { |ele| max - ele }\n max = arr.max\n if k % 2 == 0\n arr.map! { |ele| max - ele }\n end\n arr.each {|ele| print \"%d \" % ele }\n print \"\\n\"\n}", "positive_code": [{"source_code": "def get_max(a)\n\tres = a[0]\n\tfor i in 1..(a.length-1)\n\t\tif a[i] > res\n\t\t\tres = a[i]\n\t\tend\n\tend\n\tres\nend\n\ndef flip_array!(a)\n\tm = get_max(a)\n\tfor i in 0..(a.length-1)\n\t\ta[i] = m - a[i]\n\tend\n\tnil\nend\n\nt = gets.chomp.to_i\nfor tc in 1..t\n\ta = gets.split\n\tn = a[0].to_i\n\tk = a[1].to_i\n\ta = gets.split\n\tfor i in 0..(n-1)\n\t\ta[i] = a[i].to_i\n\tend\n\tflip_array!(a)\n\t\n\tif (k%2 == 0) \n\t\tflip_array!(a)\n\tend\n\tfor i in 0..(n-1)\n\t\tprint(a[i])\n\t\tprint(\" \")\n\tend\n\tprint(\"\\n\")\nend"}, {"source_code": "t = gets.chomp.to_i\nt.times {\n nk = gets.chomp.split(' ').map(&:to_i)\n n = nk[0]\n k = nk[1]\n arr = gets.chomp.split(' ').map(&:to_i)\n max = arr.max\n arr.map! { |ele| max - ele }\n max = arr.max\n if k % 2 == 0\n arr.map! { |ele| max - ele }\n end\n arr.each {|ele| print \"%d \" % ele }\n # print \"\\n\"\n}"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\nt.times {\n nk = gets.chomp.split(' ').map(&:to_i)\n n = nk[0]\n k = nk[1]\n arr = gets.chomp.split(' ').map(&:to_i)\n max = arr.max\n arr.map! { |ele| max - ele }\n max = arr.max\n if k % 2 == 0\n arr.map! { |ele| max - ele }\n end\n p arr.join(' ')\n}"}], "src_uid": "f18a5fa0b2e7e96cb5994b7b2dbe0189"} {"source_code": "n = gets.to_i\nd = gets.to_i\ne = gets.to_i\neu = e*5\n\nmin = n\n(n/d+1).times do |i|\n x = n - d*i\n break if x<0\n\n x -= x/eu * eu\n min = x if min>x\n\n break if min==0\nend\n\nputs min", "positive_code": [{"source_code": "n = gets.to_i\nd = gets.to_i\ne = gets.to_i\n\nans = n\n\n(0..(n/d)).each do |dn|\n ans = [ans, (n - (d*dn)) % (e*5)].min\nend\n\nputs ans"}], "negative_code": [{"source_code": "n = gets.to_i\nd = gets.to_i\ne = gets.to_i\n\nans = 10 ** 20\ntmp = n % d % (e*5)\ntmp2 = n % (e*5) % d\nans = [ans, tmp, tmp2].min\nputs ans"}, {"source_code": "n = gets.to_i\nd = gets.to_i\ne = gets.to_i\n\nans = n\n\ntmp = n % d % (e*5)\ntmp2 = n % (e*5) % d\nans = [ans, tmp, tmp2].min\nputs ans"}], "src_uid": "8c5d9b4fd297706fac3be83fc85028a0"} {"source_code": "t = readline.strip.to_i\n\nt.times do\n a, b, c = readline.strip.split(/\\s+/).map(&:to_i)\n if a == b && b == c\n puts 'YES'\n next\n end\n\n # case 1 |a| b c\n d = c - b\n if ((b - d) % a == 0) && ((c - 2*d) % a == 0)\n m = (b-d) / a\n if m > 0\n puts 'YES'\n next\n end\n end\n\n # case a |b| c\n d = c - a\n if d % 2 == 0\n d /= 2\n if ((a+d) % b == 0) && ((c-d) % b == 0)\n m = (a+d) / b\n if m > 0\n puts 'YES'\n next\n end\n end\n end\n\n # case a b |c|\n d = b - a\n if ((b+d) % c == 0) && ((a+2*d) % c == 0)\n m = (b + d) / c\n if m > 0\n puts 'YES'\n next\n end\n end\n\n puts 'NO'\nend\n\n", "positive_code": [{"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |inp|\r\n a, b, c = inp.split(' ').map(&:to_i)\r\n\r\n if a - b == b - c\r\n puts \"YES\"\r\n else\r\n if (2 * b - c) % a == 0 && (2 * b - c) / a > 0\r\n puts \"YES\"\r\n elsif (a + c) % (2 * b) == 0 && (a + c) / (2 * b) > 0\r\n puts \"YES\"\r\n elsif (2 * b - a) % c == 0 && (2 * b - a) / c > 0\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n end\r\nend"}, {"source_code": "gets.to_i.times do\n a, b, c = gets.split.map(&:to_i)\n\n # Is it `a`?\n d = c - b\n aa = b - d\n if aa % a == 0 && aa / a > 0\n puts \"YES\"\n next\n end\n\n # `b`?\n d = c - a\n if d % 2 == 0\n d /= 2\n bb = c - d\n if bb % b == 0 && bb / b > 0\n puts \"YES\"\n next\n end\n end\n\n # `c`?\n d = b - a\n cc = b + d\n if cc % c == 0 && cc / c > 0\n puts \"YES\"\n next\n end\n\n puts \"NO\"\nend\n"}, {"source_code": "#!/usr/bin/ruby\ninput = ARGF.read.each_line(chomp: true).to_a\nheader = input.shift\ninput.each do |line|\n z = line.split.map(&:to_i)\n puts ((2*z[1] -z[2] > 0 and (2*z[1] - z[2]) % z[0] == 0) or\n ((z[0] + z[2]) % (2*z[1]) == 0) or\n (2*z[1] -z[0] > 0 and (2*z[1] - z[0]) % z[2] == 0)) ? \"YES\" : \"NO\"\nend\n"}], "negative_code": [{"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |inp|\r\n a, b, c = inp.split(' ').map(&:to_i)\r\n\r\n min = [a,c].min\r\n max = [a,c].max\r\n\r\n if (a > c || a < c) && max - min > 1\r\n puts \"YES\"\r\n else\r\n if a == b && b == c\r\n puts \"YES\"\r\n else\r\n if (a + c) * b == b * 2\r\n puts \"YES\"\r\n elsif (b == c && a * b == b) || (a == b && b * c == b)\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n end\r\n end\r\nend"}, {"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |inp|\r\n a, b, c = inp.split(' ').map(&:to_i)\r\n\r\n if a > c\r\n a, c = c, a\r\n end\r\n\r\n # pp \"#{a}, #{b}, #{c}\"\r\n x = Hash[[a,b,c].tally.to_a.reverse]\r\n if x[2].to_i * x[1].to_i == x[2].to_i\r\n puts \"YES\"\r\n next\r\n end\r\n if (a == b && b == c) || (a == 1 && c == 1)\r\n puts \"YES\"\r\n next\r\n end\r\n if c - a < 2\r\n puts \"NO\"\r\n next\r\n end\r\n if a + b != c && a + (c - a) != c\r\n puts \"NO\"\r\n next\r\n end\r\n\r\n puts \"YES\"\r\nend"}, {"source_code": "gets.to_i.times do\n a, b, c = gets.split.map(&:to_i)\n\n # Is it `a`?\n d = c - b\n aa = b - d\n if aa % a == 0 && aa / a > 0\n puts \"YES\"\n next\n end\n\n # `b`?\n d = c - a\n if d % 2 == 0\n bb = c - d\n if bb % b == 0 && bb / b > 0\n puts \"YES\"\n next\n end\n end\n\n # `c`?\n d = b - a\n cc = b + d\n if cc % c == 0 && cc / c > 0\n puts \"YES\"\n next\n end\n\n puts \"NO\"\nend\n"}], "src_uid": "90c5058c0c7f55a567f2e036482149f9"} {"source_code": "class Info\n attr_accessor :dist\n attr_accessor :team\n\n def initialize (d, t)\n @dist = d\n @team = t\n end\nend\n\ngets\nfirst = gets.split(' ').map do |x|\n Info.new(x.to_i, 1)\nend\n\ngets\nsecond = gets.split(' ').map do |x|\n Info.new(x.to_i, 2)\nend\n\nres = first + second\nres.sort_by! { |x| -x.dist }\n\nd = res.max_by { |x| x.dist }.dist + 1\n\ntwo_points_first, three_points_first = first.length, 0\ntwo_points_second, three_points_second = second.length, 0\n\nmax_first = two_points_first * 2 + three_points_first * 3\nmax_second = two_points_second * 2 + three_points_second * 3\ndiff = max_first - max_second\n\npoints = first.map { |x| x.dist } + second.map { |x| x.dist }\npoints = points.uniq.sort.reverse\n\n\ncurrent = 0\nfor i in points\n while current < res.length && res[current].dist >= i do\n if res[current].team == 1\n two_points_first -= 1\n three_points_first += 1\n else\n two_points_second -= 1\n three_points_second += 1\n end\n\n current += 1\n end\n\n local_first = two_points_first * 2 + three_points_first * 3\n local_second = two_points_second * 2 + three_points_second * 3\n\n loc_diff = local_first - local_second\n\n if loc_diff >= diff\n diff = loc_diff\n max_first, max_second = local_first, local_second\n end\n\n break if current == res.length\nend\n\nputs \"#{max_first}:#{max_second}\"", "positive_code": [{"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\nclass Score\n def self.start\n self.new\n end\n\n def initialize\n aggregate\n end\n\n def aggregate\n n = gets.chomp.to_i\n @f = Team.new(gets.chomp.split.map(&:to_i))\n m = gets.chomp.to_i\n @s = Team.new(gets.chomp.split.map(&:to_i))\n end\n\n def result\n f_score = @f.score\n s_score = @s.score\n f = @f.score_l\n s = @s.score_l\n n = f.length\n m = s.length\n\n ans = -1000000\n diff_score = f_score - s_score\n if ans < f_score - s_score\n ans = diff_score\n ans_f = f_score\n ans_s = s_score\n end\n\n j = 0\n @s.score_l.length.times do |i|\n s_score -= 1\n while j < n and f[j] <= s[i]\n f_score -= 1\n j += 1\n end\n diff_score = f_score - s_score\n if ans < diff_score\n ans = diff_score\n ans_f = f_score\n ans_s = s_score\n end\n end\n return \"#{ans_f}:#{ans_s}\"\n end\nend\n\nclass Team\n attr_reader :score_l, :score\n def initialize(score_l)\n @score_l = score_l.sort\n @score = @score_l.length * 3\n end\nend\n\ns = Score.start\nputs s.result\n"}], "negative_code": [{"source_code": "class Info\n attr_accessor :dist\n attr_accessor :team\n\n def initialize (d, t)\n @dist = d\n @team = t\n end\nend\n\ngets\nfirst = gets.split(' ').map do |x|\n Info.new(x.to_i, 1)\nend\n\ngets\nsecond = gets.split(' ').map do |x|\n Info.new(x.to_i, 2)\nend\n\nres = first + second\nres.sort_by! { |x| -x.dist }\n\nd = res.max_by { |x| x.dist }.dist + 1\n\ntwo_points_first, three_points_first = first.length, 0\ntwo_points_second, three_points_second = second.length, 0\n\nmax_first = two_points_first * 2 + three_points_first * 3\nmax_second = two_points_second * 2 + three_points_second * 3\ndiff = max_first - max_second\n\ncurrent = 0\nd.downto(1) do |i|\n while current < res.length && res[current].dist >= i do\n if res[current].team == 1\n two_points_first -= 1\n three_points_first += 1\n else\n two_points_second -= 1\n three_points_second += 1\n end\n\n local_first = two_points_first * 2 + three_points_first * 3\n local_second = two_points_second * 2 + three_points_second * 3\n\n loc_diff = local_first - local_second\n\n if loc_diff >= diff\n diff = loc_diff\n max_first, max_second = local_first, local_second\n end\n\n current += 1\n end\n\n break if current == res.length\nend\n\nputs \"#{max_first}:#{max_second}\"\n"}, {"source_code": "class Info\n attr_accessor :dist\n attr_accessor :team\n\n def initialize (d, t)\n @dist = d\n @team = t\n end\nend\n\ngets\nfirst = gets.split(' ').map do |x|\n Info.new(x.to_i, 1)\nend\n\ngets\nsecond = gets.split(' ').map do |x|\n Info.new(x.to_i, 2)\nend\n\nres = first + second\nres.sort_by! { |x| -x.dist }\n\nd = res.max_by { |x| x.dist }.dist + 1\n\ntwo_points_first, three_points_first = first.length, 0\ntwo_points_second, three_points_second = second.length, 0\n\nmax_first = two_points_first * 2 + three_points_first * 3\nmax_second = two_points_second * 2 + three_points_second * 3\ndiff = max_first - max_second\n\ncurrent = 0\nd.downto(1) do |i|\n while current < res.length && res[current].dist >= i do\n if res[current].team == 1\n two_points_first -= 1\n three_points_first += 1\n else\n two_points_second -= 1\n three_points_second += 1\n end\n\n local_first = two_points_first * 2 + three_points_first * 3\n local_second = two_points_second * 2 + three_points_second * 3\n\n loc_diff = local_first - local_second\n\n if loc_diff > diff\n diff = loc_diff\n max_first, max_second = local_first, local_second\n end\n\n current += 1\n end\n\n break if current == res.length\nend\n\nputs \"#{max_first}:#{max_second}\"\n"}], "src_uid": "a30b5ff6855dcbad142f6bcc282601a0"} {"source_code": "t = gets.to_i\nt.times.each do\n n = gets.to_i\n as = gets.split.map(&:to_i)\n if as.min < 0\n puts 'no'\n next\n end\n\n g = as[0]\n as.each {|a| g = a.gcd(g) }\n max = as.max\n min = [as.min, g].min\n cnt = (max - min) / g + 1\n if cnt > 300\n puts 'no'\n else\n puts 'yes'\n puts cnt\n puts (min..max).step(g).map {|i| i }.join(' ')\n end\nend\n", "positive_code": [{"source_code": "$, = $\\ = \"\\n\"\r\ngets.to_i.times do\r\n gets\r\n a = gets.split.map &:to_i\r\n if a.min < 0\r\n print \"NO\"\r\n else\r\n print \"YES\", a.max + 1, (0..a.max).to_a.join(\" \")\r\n end\r\nend"}, {"source_code": "gets.to_i.times do\r\n gets\r\n a = gets.split.map &:to_i\r\n if a.min < 0\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n puts a.max + 1, (0..a.max).to_a.join(\" \")\r\n end\r\nend"}, {"source_code": "gets.to_i.times do\r\n gets\r\n a = gets.split.map &:to_i\r\n if a.min < 0\r\n puts \"NO\"\r\n else\r\n puts \"YES\", a.max + 1, (0..a.max).to_a.join(\" \")\r\n end\r\nend"}], "negative_code": [], "src_uid": "5698e6fd934b9f6b847d7e30a3d06f2b"} {"source_code": "=begin\n\nWelcome to GDB Online.\nGDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,\nC#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.\nCode, Compile, Run and Debug online from anywhere in world.\n\n=end\n\nt=gets.to_i\nfor i in 1..t\n n =gets.to_i\n s=gets\n maks=s.split.map{|x|x.to_i}\n ones=0\n etternull=0\n har=0\n sum=0\n ending =0\n prev=maks[0]\n for j in 0..(n-1)\n if (har==1)\n if maks[j]==1\n ones+=1\n ending =0\n else \n sum+=ones\n etternull+=1\n ending+=1\n end\n else \n if maks[j]==1\n ones+=1\n etternull-=1\n ending=0\n else \n sum+=ones\n har =1\n ending+=1\n end\n end \n end\n puts [sum, sum+etternull, sum+ones-ending-1].max\nend\n", "positive_code": [{"source_code": "main = -> {\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n return 0 if n == 1\n\n zeros = [0] * (n + 1)\n ones = [0] * (n + 1)\n n.times do |i|\n zeros[i + 1] = zeros[i]\n zeros[i + 1] += 1 if a[i] == 0\n ones[i + 1] = ones[i]\n ones[i + 1] += 1 if a[i] == 1\n end\n\n l_zero = a.index(0)\n l_one = a.index(1)\n r_zero = a.rindex(0)\n r_one = a.rindex(1)\n\n original = 0\n n.times do |i|\n original += zeros[n] - zeros[i] if a[i] == 1\n end\n ans = original\n\n tries = []\n tries << l_zero if l_zero\n tries << l_one if l_one\n tries << r_zero if r_zero\n tries << r_one if r_one\n\n tries.each do |x|\n a[x] ^= 1\n res = original\n if a[x] == 1\n res += zeros[n] - zeros[x + 1]\n res -= ones[x] - ones[0]\n else\n res += ones[x] - ones[0]\n res -= zeros[n] - zeros[x + 1]\n end\n ans = res if ans < res\n a[x] ^= 1\n end\n\n ans\n}\n\nt = gets.to_i\nputs t.times.map{ main.call }.join(\"\\n\")\n"}, {"source_code": "gets.to_i.times{\n n=gets.to_i\n a=gets.split.map(&:to_i)\n b=a.clone\n c=a.clone\n if b.count(1)>0\n b[b.rindex(1)]=0\n end\n if c.count(0)>0\n c[c.index(0)]=1\n end\n counta=0\n countb=0\n countc=0\n ca=0\n cb=0\n cc=0\n n.times{|i|\n if a[i]==1\n ca+=1\n else\n counta+=ca\n end\n if b[i]==1\n cb+=1\n else\n countb+=cb\n end\n if c[i]==1\n cc+=1\n else\n countc+=cc\n end\n }\n print([counta,countb,countc].max,\"\\n\")\n}"}, {"source_code": "gets.to_i.times{\r\n n = gets.to_i\r\n x = gets.split\r\n ones = (x.join('')).count('1')\r\n zeros = n-ones\r\n zeros1 = zeros\r\n initial = 0\r\n (n-1).times{|i|\r\n if x[i]=='1'\r\n initial+=zeros1\r\n else\r\n zeros1-=1\r\n end\r\n }\r\n y = x.reverse\r\n mx = 0\r\n n.times{|i|\r\n if x[i]=='0'\r\n a = -i + x[(i+1)..].count('0')\r\n mx = [mx,a].max\r\n break\r\n end\r\n }\r\n n.times{|i|\r\n if y[i]=='1'\r\n a = -i + y[(i+1)..].count('1')\r\n mx = [mx,a].max\r\n break\r\n end\r\n }\r\n p initial+mx\r\n}"}], "negative_code": [{"source_code": "main = -> {\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n return 1 if n == 1\n\n l_zero = a.index(0)\n l_one = a.index(1)\n r_zero = a.rindex(0)\n r_one = a.rindex(1)\n\n ans = n_inversions(a)\n\n tries = []\n tries << l_zero if l_zero\n tries << l_one if l_one\n tries << r_zero if r_zero\n tries << r_one if r_one\n\n tries.each do |x|\n a[x] ^= 1\n res = n_inversions(a)\n ans = res if ans < res\n a[x] ^= 1\n end\n\n ans\n}\n\ndef n_inversions(seq)\n n = seq.size\n b = [0] * (n + 1)\n\n res = 0\n n.times do |i|\n s = 0\n j = seq[i] + 1\n while j > 0\n s += b[j]\n j -= (j & -j)\n end\n\n res += i - s\n\n j = seq[i] + 1\n while j < n\n b[j] += 1\n j += (j & -j)\n end\n end\n\n res\nend\n\nt = gets.to_i\nputs t.times.map{ main.call }.join(\"\\n\")\n"}, {"source_code": "main = -> {\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n return 0 if n == 1\n\n l_zero = a.index(0)\n l_one = a.index(1)\n r_zero = a.rindex(0)\n r_one = a.rindex(1)\n\n ans = n_inversions(a)\n\n tries = []\n tries << l_zero if l_zero\n tries << l_one if l_one\n tries << r_zero if r_zero\n tries << r_one if r_one\n\n tries.each do |x|\n a[x] ^= 1\n res = n_inversions(a)\n ans = res if ans < res\n a[x] ^= 1\n end\n\n ans\n}\n\ndef n_inversions(seq)\n n = seq.size\n b = [0] * (n + 1)\n\n res = 0\n n.times do |i|\n s = 0\n j = seq[i] + 1\n while j > 0\n s += b[j]\n j -= (j & -j)\n end\n\n res += i - s\n\n j = seq[i] + 1\n while j < n\n b[j] += 1\n j += (j & -j)\n end\n end\n\n res\nend\n\nt = gets.to_i\nputs t.times.map{ main.call }.join(\"\\n\")\n"}, {"source_code": "gets.to_i.times{\n n=gets.to_i\n s=gets.split.map(&:to_i)\n if s.count(1)>s.count(0)\n s[s.rindex(1)]=0\n elsif s.count(1) 1 and ans[-1] == ans[-2]\n cur = ans[-1]\n ans.pop\n ans.pop\n cur += 1\n ans << cur\n end\nend\nprint \"#{ans.size}\\n\"\nfor i in ans\n print \"#{i} \"\nend", "positive_code": [{"source_code": "n = gets.to_i\narr = gets.split(/[ \\n]/);\n\nst = Array.new(n) { |x| }\nlen = 0\nfor x in arr\n x = x.to_i\n if (len != 0 && st[len - 1] == x) \n st[len - 1] += 1\n else \n st[len] = x\n len += 1\n end\n while (len > 1 && st[len - 2] == st[len - 1]) do\n len -= 1;\n st[len - 1] += 1\n end\nend\nputs len\nfor i in (0...len) do\n print \"#{st[i]} \";\nend"}, {"source_code": "r=->{gets.split.map &:to_i}\nn = r[]\nn = n[0]\nv = r[]\na = Array.new\nn.times {|i|\n x = v[i]\n while a.length != 0 and a[a.length - 1] == x do\n a.pop()\n x = x + 1\n end\n a.push(x)\n}\nputs(a.length)\nfor x in a do\n print(x)\n print(\" \")\nend"}, {"source_code": "\n\nn = gets.to_i\nrs = gets.split.map &:to_i\n\ngot = []\ni = 0\nj = 0\n\nwhile i < n do\n if got.size == 0 then\n got.push(rs[i])\n elsif rs[i] == got[j] then\n got[j] += 1\n while j > 0 && got[j] == got[j-1] do\n j -= 1\n got[j] += 1\n end\n else\n if j == got.size - 1 then\n got.push(rs[i])\n j += 1\n else\n j += 1\n got[j] = rs[i];\n end\n end\n\n i += 1\nend\n\np j+1\nprint got[0..j].join(' ')\n"}, {"source_code": "n = gets.chomp.to_i\nc = gets.split.map(&:to_i)\n\ncur1 = 1\ncur = 0\nans = []\n\nfor i in c\n ans << i\n while ans.size > 1 and ans[-1] == ans[-2]\n cur = ans[-1]\n cur += 1\n ans.pop\n ans.pop\n ans << cur\n end\nend\n\nprint \"#{ans.size}\"\nprint \"\\n\"\n\nfor i in ans\n print \"#{i} \"\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb=[]\nfor x in a\n\tb<1 and b[-1]==b[-2]\n\t\tb.pop\n\t\tb[-1]+=1\n\tend\nend\n\nprint \"#{b.size}\"\nprint \"\\n\"\n\nfor x in b\n print \"#{x} \"\nend"}, {"source_code": "# help from stackoverflow\nn = gets.to_i\narr = gets.split.map(&:to_i)\ni = 1\nfilled = 1\nans = []\ntmp = arr[0]\nans << arr[0]\nwhile i 1 && ans[-1]==ans[-2]\n tmp = ans.pop\n ans.pop\n ans << tmp+1\n filled = filled -1\n end\n else\n ans << arr[i]\n filled= filled+1\n end\n \n i= i+1\nend\n\nputs filled\n\nfor i in (0..filled)\n print ans[i]\n print \" \"\nend\n"}], "negative_code": [{"source_code": "\n\nn = gets.to_i\nrs = gets.split.map &:to_i\n\ngot = []\ni = 0\nj = 0;\nwhile i < n do\n if got.size == 0 then\n got.push(rs[i])\n elsif rs[i] == got[j] then\n got[j] += 1\n while j > 0 && got[j] == got[j-1] do\n j -= 1\n got[j] += 1\n end\n else\n got.push(rs[i])\n j += 1\n end\n\n i += 1\nend\n\np j+1\nprint got[0..j].join(' ')\n"}], "src_uid": "8c715616c8fa373c95368cf4795a2e6a"} {"source_code": "gets.to_i.times do |tt|\r\n n=gets.to_i\r\n s=gets.chomp.chars.map(&:to_i)\r\n puts s.inject(:+)+n-1-s[0,n-1].count(0)\r\nend\r\n", "positive_code": [{"source_code": "=begin \r\nEntrada: testcases, entero que indica la cantidad de d\u00edgitos, \r\n string de los d\u00edgitos\r\nSalida: operaciones m\u00ednimas para que todos los d\u00edgitos sean 0\r\nMovimientos permitidos: restar 1 a la cifra, cambiar el orden de una cifra \r\n(adyacente y no adyacente)\r\n=end\r\n\r\n# Variables\r\ntestcases = 0\r\nnumberDigits = 0\r\ndigits = \"\"\r\n\r\n# Constantes\r\ncondition = true\r\noperationReduce = false\r\noperationChange = true\r\n\r\n# Paso 1: Pedir los testcases\r\ntestcases = Integer(gets.chomp)\r\nmovements = Array.new(testcases)\r\n\r\n#Paso 2: Pedir la cantidad de d\u00edgitos \r\nfor i in (0..(testcases-1))\r\n numberDigits = Integer(gets.chomp)\r\n digits = gets.chomp\r\n movements[i] = 0\r\n count = 0\r\n digits.chars.each do |digit|\r\n count = count +1\r\n if Integer(digit)!=0\r\n if count == numberDigits\r\n movements[i] = movements[i] + digit.to_i\r\n else\r\n movements[i] = movements[i] + digit.to_i + 1\r\n end\r\n end\r\n \r\n end\r\nend\r\nmovements.each do |elements|\r\n puts elements\r\nend"}, {"source_code": "# require 'byebug'\n\ngets.to_i.times do\n\n n = gets.to_i\n str = gets.strip\n\n ary = str.split(\"\").map(&:to_i)\n ans = 0\n 0.upto(n-1).each do |i|\n ans += ary[i]\n ans += 1 if ary[i] != 0 && i != n-1\n end\n\n puts ans\n\nend\n"}, {"source_code": "gets.to_i.times do\r\n\r\nn = gets.to_i\r\nd = gets.chomp.chars.map!(&:to_i)\r\n\r\ncnt = 0\r\nd.reverse_each.with_index do |di, i|\r\n next if di == 0\r\n\r\n cnt += di\r\n cnt += 1 if i > 0\r\nend\r\n\r\nputs cnt\r\n\r\nend\r\n"}], "negative_code": [], "src_uid": "6571fdd506a858d7620c2faa0fe46cc1"} {"source_code": "n = gets.to_i\nx = (n-1).times.map{gets.to_i-1}\n\nha = Array.new(n, true)\nha[0] = false\nx.each{|t| ha[t] = false}\n\ncnt = Array.new(n, 0)\nx.each.with_index{|t,i| cnt[t]+=1 if ha[i+1]}\n\nputs (n.times.all?{|i| ha[i]||cnt[i]>2}) ? 'Yes' : 'No'", "positive_code": [{"source_code": "n=gets.to_i\nt=[]\n1.upto(n-1){|i| p=gets.to_i-1; t[p]||=[]; t[p] << i }\nputs (0...n).all?{|i| !t[i] || t[i].count{|j|!t[j]}>2} ? :Yes : :No"}], "negative_code": [], "src_uid": "69edc72ec29d4dd56751b281085c3591"} {"source_code": "n, k = gets.split.map(&:to_i)\nts = gets.split.map { |i| i.to_i < 0 }\ncount = ts.count { |t| t }\nif count > k\n puts -1\n exit\nend\nprev = nil\ndts = []\nts.each_with_index do |t, i|\n if t && !prev\n prev = i\n elsif t && prev\n dts << i - prev - 1\n prev = i\n end\nend\ndts.sort!\nsum = count\ndif = 0\ndts.each do |dt|\n if sum + dt <= k\n sum += dt\n dif += 1\n else\n break\n end\nend\nans = (count - dif) * 2\nlast = ts.reverse.index { |t| t }\nif last && last <= k - sum\n puts ans - 1\nelse\n puts ans\nend\n", "positive_code": [{"source_code": "#!/bin/env ruby\n\nclass TireManager\n attr_accessor :weather_intervals, :minus_degree_days_count, :plus_degree_intervals, :reserve\n def getNumberOfCrisscrosses number_of_winter_days, tyre_life_in_days, weather_forecast\n @weather_intervals=weather_forecast.chunk {|degree| degree<0}.map {|x,y| [(x)?(:minus):(:plus),y.size]}\n @minus_degree_days_count = @weather_intervals.reduce(0) {|sum,interval| sum+=(interval[0]==:minus)?(interval[1]):0}\n case\n when @minus_degree_days_count > tyre_life_in_days\n -1\n when @minus_degree_days_count == 0\n 0\n else\n @weather_intervals.shift if @weather_intervals[0][0]==:plus\n @reserve = tyre_life_in_days - @minus_degree_days_count\n @plus_degree_intervals = @weather_intervals[0...-1].select {|interv| interv[0]==:plus}.map {|x| x[1]}.sort\n @plus_degree_intervals = @plus_degree_intervals.drop_while {|x| (x<=@reserve)?(@reserve-=x;true):(false)}\n @plus_degree_intervals.size*2+1+((@weather_intervals[-1][0]==:plus&&@reserve<@weather_intervals[-1][1])?1:0)\n end\n end\nend\n\nif __FILE__ == $0\n number_of_winter_days,tyre_life_in_days = $stdin.readline.split.map(&:to_i)\n weather_forecast = $stdin.readline.rstrip.split.map(&:to_i)\n puts TireManager.new.getNumberOfCrisscrosses(number_of_winter_days, tyre_life_in_days, weather_forecast)\nend"}], "negative_code": [], "src_uid": "18458f6ab66db560a51887c944f26f0f"} {"source_code": "n, x=gets.split.map &:to_i\na=gets.split.map &:to_i\n\nb=[]\na.each{|e|b[e]=b[e]?b[e]+1:1}\nr=0\na.each{|e|\n r+=b[x^e] if b[x^e]\n r-=1 if x==0\n}\np r/2\n", "positive_code": [{"source_code": "n,x,*a=$<.read.split.map(&:to_i)\nh=Hash.new(r=0)\na.each{|e|h[e]+=1}\nh.each_key{|k|\n\topp=k^x\n\tif opp==k\n\t\tr+=h[k]*(h[k]-1)/2\n\telsif k 0\n b50 -= 1; b25 -= 1\n else\n b25 -= 3\n end\n end\n\n if b25 < 0\n ans = \"NO\"\n break\n end\nend\n\nputs ans\n", "positive_code": [{"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nc25=0\nc50=0\nans=\"YES\"\nx.each{|e|\n\tcase e\n\twhen 25\n\t\tc25+=1\n\twhen 50\n\t\tif c25>0 then\n\t\t\tc25-=1\n\t\t\tc50+=1\n\t\telse\n\t\t\tans=\"NO\"\n\t\t\tbreak\n\t\tend\n\twhen 100\n\t\tif c50>0 && c25 >0 then\n\t\t\tc50-=1\n\t\t\tc25-=1\n\t\telsif c25>2 then\n\t\t\tc25-=3\n\t\telse\n\t\t\tans=\"NO\"\n\t\t\tbreak\n\t\tend\n\tend\n}\nputs ans\n\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nrubles = gets.split.map(&:to_i)\nbuckets = {\n 25 => 0,\n 50 => 0,\n 100 => 0\n}\nimpossible = false\n\ncatch :stop do\n rubles.each { |i|\n case i\n when 25\n buckets[25] += 1\n when 50\n buckets[50] += 1\n\n if buckets[25] > 0\n buckets[25] -= 1\n else\n impossible = true\n throw :stop\n end\n else\n buckets[100] += 1\n \n if buckets[50] > 0\n if buckets[25] > 0\n buckets[50] -= 1\n buckets[25] -= 1\n else\n impossible = true\n throw :stop\n end\n else\n if buckets[25] >= 3\n buckets[25] -= 3\n else\n impossible = true\n throw :stop\n end\n end\n end\n }\nend\n\nputs \"YES\" if !impossible\nputs \"NO\" if impossible\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc25, c50 = 0, 0\nans = a.each do |x|\n case x\n when 25\n c25 += 1\n when 50\n break if c25 < 1\n c25 -= 1\n c50 += 1\n when 100\n if c50 >= 1 && c25 >= 1\n c25 -= 1\n c50 -= 1\n elsif c25 >= 3\n c25 -= 3\n else\n break\n end\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = [0, 0, 0]\nans = 0\na.each do |x|\n case x\n when 25\n c[0] += 1\n when 50\n c[0] -= 1\n if c[0] < 0\n ans = nil\n break\n end\n c[1] += 1\n when 100\n if c[1] >= 1 && c[0] >= 1\n c[0] -= 1\n c[1] -= 1\n elsif c[0] >= 3\n c[0] -= 3\n else\n ans = nil\n break\n end\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\na = gets.split.map{|x| x.to_i}\nq, h = 0, 0\n(0..a.size - 1).each do |i|\n case a[i]\n when 25\n q += 1\n when 50\n if q == 0\n puts \"NO\"\n exit 0\n end\n h += 1\n q -= 1\n when 100\n if h > 0 && q > 0\n h -= 1\n q -= 1\n elsif q >= 3\n q -= 3\n else\n puts \"NO\"\n exit 0\n end\n end\nend\nputs \"YES\"\n"}, {"source_code": "TP = 25\nnum = gets.to_i\nbills = gets.split.map{|b| (b.to_i / TP).pred }\n\nx = [0, 0, 0, 0]\nbills.each{|c|\n case c\n when 1\n x[0] -= 1\n when 3\n if x[1].zero?\n x[0] -= 2\n else\n x[1] -= 1\n end\n x[0] -= 1\n end\n break if x.any? {|i| i < 0 }\n x[c] += 1\n}\nputs x.any? {|i| i < 0} ? \"NO\" : \"YES\" "}, {"source_code": "def cinema_line(bills)\n # 25, 50, 100\n cashier_bills = {\n 25 => 0,\n 50 => 0,\n 100 => 0\n }\n\n bills.each do |bill|\n change = (bill-25)\n case change\n when 0\n cashier_bills[25] += 1\n when 25\n return false if cashier_bills[25] == 0\n\n cashier_bills[25] -= 1\n cashier_bills[50] += 1\n when 75\n # 50 25\n if cashier_bills[50] > 0 && cashier_bills[25] > 0\n cashier_bills[50] -= 1\n cashier_bills[25] -= 1\n cashier_bills[100] += 1\n elsif cashier_bills[25] > 2\n cashier_bills[25] -= 3\n cashier_bills[100] += 1\n else\n return false\n end\n end\n end\n\n return true\nend\n\ndef main\n lines = []\n while line = gets\n lines << line\n end\n\n bills = lines[1].split(' ').map(&:to_i)\n puts cinema_line(bills) ? \"YES\" : \"NO\"\nend\n\nmain"}, {"source_code": "#! /usr/bin/env ruby\n\ni = STDIN.gets.to_i\nlist = STDIN.gets.to_s.split(' ')\n\nif list.length != i\n raise ArgumentError.new\nend\n\ndef sell?(list)\n bills = {25 => 0, 50 => 0, 100 => 0}\n while ruble = list.shift\n case ruble.to_i\n when 25\n bills[25] += 1\n when 50\n return false if bills[25] == 0\n\n bills[25] -= 1\n bills[50] += 1\n when 100\n return false if bills[25] == 0\n\n if bills[50] > 0\n bills[50] -= 1\n bills[25] -= 1\n bills[100] += 1\n else\n return false if bills[25] < 3\n\n bills[25] -= 3\n bills[100] += 1\n end\n end\n end\n true\nend\n\nif sell?(list)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "n = gets.to_i\nh = { 25 => 0, 50 => 0, 100 => 0 }\nans = \"YES\"\ngets.split(' ',n).map(&:to_i).each do |x|\n h[x] += 1\n if x == 25\n elsif x == 50\n h[25] -= 1\n elsif h[50] > 0\n h[50] -= 1\n h[25] -= 1\n else\n h[25] -= 3\n end\n ans = \"NO\" if h[25] < 0\nend\nputs ans"}, {"source_code": "#!/usr/bin/ruby\nh={1=>0,2=>0}\ngets;gets.split.each{|a|\n\te=a.to_i/25\n\tif e==1\n\t\th[1]+=1\n\telsif e==2\n\t\tif h[1]>=1\n\t\t\th[1]-=1\n\t\t\th[2]+=1\n\t\telse\n\t\t\tputs :NO\n\t\t\texit\n\t\tend\n\telse\n\t\tif h[2]>=1&&h[1]>=1\n\t\t\th[2]-=1\n\t\t\th[1]-=1\n\t\telsif h[1]>=3\n\t\t\th[1]-=3\n\t\telse\n\t\t\tputs :NO\n\t\t\texit\n\t\tend\n\tend\n}\nputs :YES\n"}, {"source_code": "n, a, can = gets.chomp.to_i, gets.chomp.split.map(&:to_i), true\nnote = Hash.new 0\na.each do |x|\n if x==25 \n note[25]+=1\n elsif x==50 \n if note[25]>0\n note[50]+=1\n note[25]-=1\n else\n can = false\n break\n end\n elsif x==100\n if note[50]>0 && note[25]>0\n note[50]-=1\n note[25]-=1\n elsif note[25]>2\n note[25]-=3\n else \n can = false\n break\n end\n end \nend\nputs (can==true ? \"YES\" : \"NO\")\n"}, {"source_code": "n = gets.to_i\nexit if n < 0\nif n == 0\n\tprint \"YES\"\n\texit\nend\ncnt50 = 0\ncnt25 = 0\nqueue = gets.split(\" \")\nexit if queue.size < n\nqueue = queue[0...n]\nqueue.each {|el|\n\tcase el\n\twhen \"25\" \n\t\tcnt25 += 1\n\twhen \"50\" \n\t\tif cnt25 > 0 \n\t\t\tcnt25 -=1\n\t\t\tcnt50 += 1\n\t\telse\n\t\t\tprint \"NO\"\n\t\t\texit\n\t\tend\n\twhen \"100\"\n\t\tif cnt50 > 0 && cnt25 > 0\n\t\t\tcnt50 -= 1\n\t\t\tcnt25 -= 1\n\t\telsif cnt25 >= 3\n\t\t\tcnt25 -= 3\n\t\telse\n\t\t\tprint \"NO\"\n\t\t\texit\n\t\tend\n\telse\n\t\tprint \"Wrong banknote\"\n\t\texit \n\tend\t\t\t\n}\nprint \"YES\""}, {"source_code": "n = gets.to_i\np = gets.split.map(&:to_i)\n\nflood = \"YES\"\ndwad,pyat,sto = 0,0,0\np.each do |x|\n if x == 100\n sto+=x\n if pyat>=50\n pyat-=50\n dwad-=25\n else\n dwad-=75\n end\n elsif x == 50 \n pyat+=x\n dwad-=25\n else\n dwad+=x\n end\n\n if sto < 0 || dwad < 0 || pyat < 0\n flood = \"NO\"\n break\n end\nend\nputs flood"}, {"source_code": "def run\n n = $stdin.gets.to_i\n b = $stdin.gets.split.map(&:to_i)\n h = [0, 0, 0]\n f = false\n b.each do |i|\n if i == 25\n h[0] += 1\n elsif i == 50\n if h[0] >= 1\n h[0] -= 1; h[1] += 1\n else\n f = true\n end\n else\n if h[1] >= 1 and h[0] >= 1\n h[1] -= 1; h[0] -= 1\n elsif h[0] >= 3\n h[0] -= 3\n else\n f = true\n end\n end\n end\n puts f ? \"NO\" : \"YES\"\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n n = $stdin.gets.to_i\n b = $stdin.gets.split.map(&:to_i)\n h = [0, 0, 0]\n b.each do |i|\n if i == 25\n h[0] += 1\n elsif i == 50\n if h[0] >= 1\n h[0] -= 1\n h[1] += 1\n else\n puts \"NO\"\n return\n end\n else\n if h[1] >= 1 and h[0] >= 1\n h[1] -= 1\n h[0] -= 1\n h[2] += 1\n elsif h[0] >= 3\n h[0] -= 3\n h[2] += 1\n else\n puts \"NO\"\n return\n end\n end\n end\n puts \"YES\"\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.to_i\nh = { 25 => 0, 50 => 0, 100 => 0 }\nans = \"YES\"\ngets.split(' ',n).map(&:to_i).each do |x|\n h[x] += 1\n if x == 25\n elsif x == 50\n h[25] -= 1\n elsif h[50] > 0\n h[50] -= 1\n h[25] -= 1\n else\n h[25] -= 3\n end\n ans = \"NO\" if h[25] < 0\nend\nputs ans"}], "negative_code": [{"source_code": "puts gets.chomp.split('+').sort.join('+')"}, {"source_code": "#!/usr/bin/ruby\nh={1=>0,2=>0}\ngets;gets.split.each{|a|\n\te=a.to_i/25\n\tif e==1\n\t\th[1]+=1\n\telsif e==2\n\t\tif h[1]>=1\n\t\t\th[1]-=1\n\t\t\th[2]+=1\n\t\telse\n\t\t\tp :NO\n\t\t\texit\n\t\tend\n\telse\n\t\tif h[2]>=1&&h[1]>=1\n\t\t\th[2]-=1\n\t\t\th[1]-=1\n\t\telsif h[1]>=3\n\t\t\th[1]-=3\n\t\telse\n\t\t\tp :NO\n\t\t\texit\n\t\tend\n\tend\n}\np :YES\n"}, {"source_code": "n = STDIN.readline().to_i\nline = STDIN.readline().split().collect(&:to_i)\nb25, b50 = 0, 0\nans = \"YES\"\n\nline.each do |bill|\n case bill\n when 25 then b25 += 1\n when 50 then b25 -= 1\n when 100\n if b50 > 0\n b50 -= 1; b25 -= 1\n else\n b25 -= 3\n end\n end\n\n if b25 < 0\n ans = \"NO\"\n break\n end\nend\n\nputs ans\n"}, {"source_code": "n, a, can = gets.chomp.to_i, gets.chomp.split.map(&:to_i), true\nnote = Hash.new 0\na.each do |x|\n if x==25 \n note[x]+=1\n elsif x==50 \n if note[25]>0\n note[x]+=1\n note[25]-=1\n else\n can = false\n break\n end\n elsif x==100\n if note[50]>0 && note[25]>0\n note[50]-=1\n note[25]-=1\n elsif note[25]>1 \n note[25]-=3\n else \n can = false\n break\n end\n end \nend\nputs (can==true ? \"YES\" : \"NO\")\n"}, {"source_code": "n, a, can = gets.chomp.to_i, gets.chomp.split.map(&:to_i), true\nnote = Hash.new 0\na.each do |x|\n if x==25 \n note[x]+=1\n elsif x==50 \n if note[25]>0\n note[x]+=1\n note[25]-=1\n else\n can = false\n break\n end\n elsif x==100\n if note[50]>1 && note[25]>0\n note[50]-=1\n note[25]-=1\n elsif note[25]>2 \n note[25]-=3\n else \n can = false\n break\n end\n end \nend\nputs (can==true ? \"YES\" : \"NO\")\n"}, {"source_code": "n = gets.to_i\np = gets.split.map(&:to_i)\n\nf = true\ncounter = 0\np.each do |x|\n if x - counter > 25 \n f = false\n break\n end\n counter+=25\nend\n\nputs f ? \"YES\":\"NO\""}, {"source_code": "n = gets.to_i\np = gets.split.map(&:to_i)\n\nf = true\ncounter = 0\np.each do |x|\n if (x - counter).abs > 25 \n f = false\n break\n end\n counter+=25\n \nend\n\nputs f ? \"YES\":\"NO\"\n"}, {"source_code": "n = gets.to_i\np = gets.split.map(&:to_i)\n\nflood = \"YES\"\ndwad,pyat,sto = 0,0,0\np.each do |x|\n if x == 100\n sto+=x\n pyat-=50\n dwad-=25\n elsif x == 50 \n pyat+=x\n dwad-=25\n else\n dwad+=x\n end\n\n if sto < 0 || dwad < 0 || pyat < 0\n flood = \"NO\"\n break\n end\nend\nputs flood"}, {"source_code": "n = gets.to_i\np = gets.split.map(&:to_i)\n\nflood = \"YES\"\ndwad,pyat,sto = 0,0,0\np.each do |x|\n if x == 100\n sto+=x\n pyat-=50\n dwad-=25\n elsif x == 50 \n pyat+=x\n dwad-=25\n else\n dwad+=x\n end\n\n if sto == 0 || dwad == 0 || pyat == 0\n flood = \"NO\"\n break\n end\nend\nputs flood"}, {"source_code": "def run\n n = $stdin.gets.to_i\n b = $stdin.gets.split.map(&:to_i)\n h = [0, 0, 0]\n b.each do |i|\n if i == 25\n h[0] += 1\n elsif i == 50\n if h[0] >= 1\n h[0] -= 1\n else\n puts \"NO\"\n return\n end\n else\n if h[1] >= 1 and h[0] >= 1\n h[1] -= 1\n h[0] -= 1\n elsif h[0] >= 3\n h[0] -= 3\n else\n puts \"NO\"\n return\n end\n end\n end\n puts \"YES\"\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "gets\narr = gets.split.map &:to_i\nif arr.first != 25\n puts \"NO\"\nelse\n cashier = arr.shift\n arr.each do |x|\n if cashier < x - 25\n puts \"NO\"\n exit\n else\n cashier += x\n end\n end\n puts \"YES\"\nend\n"}, {"source_code": "gets\narr = gets.split.map &:to_i\nif arr.first != 25\n puts \"NO\"\nelse\n cashier = arr.shift\n arr.each do |x|\n if cashier < x - 25\n puts \"NO\"\n exit\n else\n cashier -= (x - 25)\n cashier += 25\n end\n end\n puts \"YES\"\nend\n"}, {"source_code": "gets\narr = gets.split.map &:to_i\nif arr.first != 25\n puts \"NO\"\nelse\n cashier = arr.shift\n arr.each do |x|\n if cashier < x - 25\n puts \"NO\"\n exit\n end\n end\n puts \"YES\"\nend\n"}, {"source_code": "gets\narr = gets.split.map &:to_i\nif arr.first != 25\n puts \"NO\"\nelse\n cashier = arr.shift\n arr.each do |x|\n if cashier < x - 25\n puts \"NO\"\n exit\n else\n cashier += 25\n cashier -= (x - 25)\n end\n end\n puts \"YES\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = [0, 0, 0]\nans = 0\na.each do |x|\n case x\n when 25\n c[0] += 1\n when 50\n c[0] -= 1\n if c[0] < 0\n ans = nil\n break\n end\n c[1] += 1\n when 100\n c[0] -= 1\n if c[1] >= 1\n c[1] -= 1\n elsif c[0] >= 2\n c[0] -= 2\n else\n ans = nil\n break\n end\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = 0\nans = 0\na.each do |x|\n c -= x - 25\n ans = nil if c < 0\n c += x\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\na = gets.split.map{|x| x.to_i}\nq, h = 0, 0\n(0..a.size - 1).each do |i|\n case a[i]\n when 25\n q += 1\n when 50\n if q == 0\n puts \"NO\"\n exit 0\n end\n h += 1\n q -= 1\n when 100\n if q == 0 || h == 0\n puts \"NO\"\n exit 0\n end\n end\nend\nputs \"YES\"\n"}, {"source_code": "TP = 25\nnum = gets.to_i\nbills = gets.split.map{|b| (b.to_i / TP).pred }\n\nx = 0\nbills.each{|c|\n if c.zero?\n x += 1\n else\n x -= c\n break if x < 0\n end\n}\nputs x < 0 ? \"NO\" : \"YES\" "}, {"source_code": "def cinema_line(bills)\n # 25, 50, 100\n cashier_bills = {\n 25 => 0,\n 50 => 0,\n 100 => 0\n }\n\n bills.each do |bill|\n change = (bill-25)\n case change\n when 0\n cashier_bills[25] += 1\n when 25\n return false if cashier_bills[25] == 0\n\n cashier_bills[25] -= 1\n cashier_bills[50] += 1\n when 75\n puts \"HERE, bills cashier: #{cashier_bills}\"\n # 50 25\n if cashier_bills[50] > 0 && cashier_bills[25] > 0\n cashier_bills[50] -= 1\n cashier_bills[25] -= 1\n cashier_bills[100] += 1\n elsif cashier_bills[25] > 2\n cashier_bills[25] -= 3\n cashier_bills[100] += 1\n else\n return false\n end\n end\n end\n\n return true\nend\n\ndef main\n lines = []\n while line = gets\n lines << line\n end\n\n bills = lines[1].split(' ').map(&:to_i)\n puts cinema_line(bills) ? \"YES\" : \"NO\"\nend\n\nmain"}], "src_uid": "63b20ab2993fddf2cc469c4c4e8027df"} {"source_code": "ans = 0\nputs ans if gets.to_i.times do\n\tcur, max = gets.split.map(&:to_i)\n\tif cur+2<=max then ans+=1 end\nend\n", "positive_code": [{"source_code": "a=gets.chomp.to_i\nans=0\na.times do\nb=gets.chomp.split(\" \")\nif b[1].to_i-b[0].to_i>=2\nans+=1\nend\nend\nputs \"#{ans}\""}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}\n"}, {"source_code": "ans=0\ngets.to_i.times{|i|\n\ta,b=gets.split.map{|e| e.to_i}\n\tif b-a>1 then\n\t\tans=ans+1\n\tend\n}\nputs ans"}, {"source_code": "available = 0\n(1..gets.to_i).each do |tc|\n\tcurr,max = gets.strip.split.map(&:to_i)\n\tavailable+=1 if max-curr>=2\nend\nputs available"}, {"source_code": "p gets.to_i.times.count{eval(gets.sub(' ','-'))<-1}"}, {"source_code": "n = gets.to_i\nk = 0\n\nfor i in 1..n\n a,b = gets.split.map {|x| x.to_i}\n if b-a >= 2\n k+=1\n end\nend\n\nputs k"}, {"source_code": "n = gets.to_i\n\nans = 0\nn.times do\n p, q = gets.split.map(&:to_i)\n if q - p >= 2\n ans += 1\n end\nend\n\nprint(ans)"}, {"source_code": "n=gets.to_i\nres=0\nn.times {\n a,b=gets.split.map(&:to_i)\n res+=1 if b>=a+2\n}\np res\n"}, {"source_code": "s=0;gets.to_i.times {\n t = gets.split.map(&:to_i)\n s += (t[1]-t[0]>1)?(1):(0)\n}\nputs s\n"}, {"source_code": "number_of_room = gets.strip.to_i\naccepted_room = 0\n1.upto(number_of_room) do\n\tcurrent_people, max_people = gets.strip.split.map(&:to_i)\n\tif max_people - current_people >= 2\n\t\taccepted_room += 1\n\tend\nend\nputs accepted_room\n"}, {"source_code": "p gets.to_i.times.count{eval(gets.sub(' ','-'))<-1}"}, {"source_code": "dorm = gets.chomp.to_i\nrooms = []\n\ni = 0\nwhile i < dorm\n\trooms << gets.chomp\n\ti += 1\nend\n\ncount = 0\nrooms.each do |room|\n\troommates = room.split(\" \")\n\tif roommates[1].to_i - roommates[0].to_i >= 2\n\t\tcount += 1\n\tend\nend\n\nputs count"}, {"source_code": "#!/usr/bin/env ruby\n# coding: utf-8\n\ndef read_int\n readline.chomp.split(/\\s+/).map(&:to_i)\nend\n\nn = read_int.first\nc = 0\nary = []\nn.times do\n tmp = read_int\n c += 1 if tmp.first + 2 <= tmp.last\nend\nputs c"}, {"source_code": "n = gets.to_i\ncount = 0\nn.to_i.times do\n p, q = gets.split.map(&:to_i)\n count += 1 if q - p > 1\nend\nputs count"}, {"source_code": "#!/usr/bin/ruby\np gets.to_i.times.count{\n\tx,y=gets.split.map(&:to_i)\n\ty-x>1\n}"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}\n"}, {"source_code": "c = 0\ngets.to_i.times do\n a,b = gets.split.map(&:to_i)\n c+=1 if a+2 <=b\nend\nputs c"}, {"source_code": "#puts \"Enter the number of rooms\\n\"\nn = gets.to_i\nc = 0;\n#puts \"Noe enter the number of people living and capacity by giving a space\\n\"\nfor i in 0...n do\n a, b = gets.split.map(&:to_i)\n if b-a >= 2\n c += 1\n end\nend\nputs c\n"}, {"source_code": "n, count = gets.chomp.to_i, 0\nn.times do\n s = gets.chomp.split(' ').map(&:to_i)\n count += 1 if s[1] - s[0] >= 2\nend\nputs count"}, {"source_code": "\np$<.count{|s|-1>eval(s.tr\" \",?-)}"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}\n"}, {"source_code": "n = gets.to_i\ncount = 0\nn.times {\n a, b = gets.split.map &:to_i\n count += 1 if a + 2 <= b\n}\nputs count\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = STDIN.readline.to_i\ncount = 0\nn.times do\n\tp, q = STDIN.readline.split.map {|s| s.to_i }\n\tcount += 1 if q-p >= 2\nend\nputs count\n"}, {"source_code": "c = 0;\ngets.to_i.times do \n\tar = gets.split.map(&:to_i)\n\tc +=1 if ar[1] - ar[0] >=2\nend\nputs c"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}"}, {"source_code": "require 'pp'\n\nn = STDIN.gets.chomp.to_i\n\nans = 0\n\nn.times do |i|\n p, q = STDIN.gets.chomp.split(/ /).map(&:to_i)\n ans += 1if q - p >= 2\nend\n\nputs ans\n"}, {"source_code": "#!/usr/bin/env ruby\n\ninput = STDIN.read\nd = input.split \"\\n\"\nrooms_n = d.first\nrooms_d = d[1..-1]\n\ns = rooms_d.select do |r|\n p, q = *r.split(' ')\n q.to_i - p.to_i >= 2\nend\n\nprint s.count"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}"}, {"source_code": "\nn = gets.to_i\np = Array.new()\nq = Array.new()\n\ncounter = 0\nfor i in 0..n-1\n p[i],q[i] = gets.split.map(&:to_i)\n counter+=1 if q[i]-p[i]>=2\nend\nputs counter\n"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}"}, {"source_code": "rooms = gets.chomp.to_i\ni = 0\noutput = 0\nwhile i < rooms\n room_value = gets.chomp.split\n room_value = room_value.map{|item| item.to_i}\n if room_value[1] - room_value[0] >= 2 then\n output = output +1\n end\n i = i+1\nend\nprint output\n"}, {"source_code": "p gets.to_i.times.map{gets.split.map(&:to_i)}.map{|a,b| b-a>=2}.select{|x| x==true}.count"}, {"source_code": "n=gets.to_i\nputs Array.new(n) {|_|\n a,b = gets.split.map(&:to_i)\n a+2<=b ? 1 : 0\n}.inject(&:+)"}, {"source_code": "n = gets.chomp.to_i\n\ncont = 0\nfor i in 0...n\n\tinput = gets.chomp.split(\" \")\n\tif input[1].to_i-input[0].to_i>=2\n\t\tcont+=1\n\tend\nend\n\nputs cont\n"}, {"source_code": "total = 0\ngets.to_i.times{\n\troom = gets.split(' ').map(&:to_i)\n\ttotal += 1 if room[1] - room[0] >= 2\n}\nputs total"}, {"source_code": "a=gets.chomp.to_i\nans=0\na.times do\nb=gets.chomp.split(\" \")\nif b[1].to_i-b[0].to_i>=2\nans+=1\nend\nend\nputs \"#{ans}\"\n\n"}, {"source_code": "n = gets.to_i\nk = 0\nn.times do\n a, b = gets.split.map(&:to_i)\n c = b-a\n if c >= 2\n k = k+1\n end\nend\n\nputs k\n"}, {"source_code": "puts gets.to_i.times.map {x = gets.split(\" \");x = x[1].to_i - x[0].to_i}.select {|item| item >= 2}.size"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}\n"}, {"source_code": "n = gets.to_i\n\nresult = 0\n1.upto(n) do\n a, b = gets.split(' ').map(&:to_i)\n result += 1 if b-a > 1\nend\n\nputs result\n"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}"}, {"source_code": "t = gets.to_i\nco = 0\nt.times do\n p, q = gets.split.map(&:to_i)\n co += 1 if q - p >= 2\nend\nputs co\n\n"}, {"source_code": "\nn = gets.chomp.to_i\nc = 0\nn.times do\n s = gets.chomp.split\n p = s[0].to_i+1\n q = s[1].to_i\n c += 1 if p < q\nend\nputs c\n"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}\n"}, {"source_code": "n = gets.to_i\ncount = 0\nfor i in 1..n\n\ta,b = gets.chomp.split(' ').map(&:to_i)\n\tif a + 2 <= b\n\t\tcount = count + 1\n\tend\nend\nputs count\n"}, {"source_code": "\n\nn = gets.to_i\nresult = 0\n\nn.times do\n a, b = gets.split.map(&:to_i)\n if b - a >= 2\n result += 1\n end\n\nend\n\n\nputs result\n\n"}, {"source_code": "c=0\ngets.to_i.times do\n\ta=gets.split\n\tif a[1].to_i-a[0].to_i>1\n\t\tc+=1\n\tend\nend\nputs c"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}\n"}, {"source_code": "numberRoom = gets.chomp.to_i\ncount = 0\n\n(0...numberRoom).each do |num|\n\tinput = gets.chomp.split(' ').map {|item| item.to_i}\n\tcount += 1 if input[1] - input[0] >= 2\nend\n\nputs count"}, {"source_code": "n = gets.to_i\narr = []\nc = 0\n\nfor i in (0..n - 1)\n \n gets.split(\" \").each {|a| arr << a.to_i}\n if (arr[1] - arr[0]) >= 2\n c += 1\n end\n \n arr = []\n \nend\n\nputs c"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}"}, {"source_code": "r = 0\ngets.chomp.to_i.times do\n\tp, q = gets.chomp.split(\" \").map(&:to_i)\n\tr += 1 if q - p > 1\nend\nputs r"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}\n"}, {"source_code": "s = 0\ngets.to_i.times do\n temp = gets.split.map(&:to_i)\n temp[1] - temp[0] >= 2 ? s += 1 : s\nend\nputs s"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}"}, {"source_code": "#!/usr/bin/env ruby\n\ninput = STDIN.read.split(\"\\n\")\nrooms = input[1..-1]\n\nprint rooms.count { |r|\n r.split(' ').map(&:to_i).reverse.inject(:-) >= 2\n}"}, {"source_code": "n = $stdin.readline.to_i\nk = 0\nn.times do\n p, q = $stdin.readline.split.map(&:to_i)\n k+=1 if q-p>=2\nend\n\nputs k"}, {"source_code": "rooms = 0\ngets.to_i.times do\n inp = gets.split.map &:to_i\n rooms += 1 if inp[1] - inp[0] >= 2\nend\nputs rooms\n"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}\n"}, {"source_code": "n = gets.to_i\n\n$res = 0\n\nn.times do\n p , q = gets.split.map(&:to_i)\n p += 2\n\n if p <= q\n $res += 1\n end\nend\n\nputs $res"}, {"source_code": "n = gets.to_i\nans = 0\nn.times do\n p, q = gets.split.map(&:to_i)\n if q - p >= 2\n ans += 1\n end\nend\nputs ans"}, {"source_code": "p$<.count{|s|-1>eval(s.tr\" \",?-)}\n"}, {"source_code": "n = gets.to_i\n\nputs (1..n).count {\n p, q = gets.split.map(&:to_i)\n q - p >= 2\n}"}], "negative_code": [{"source_code": "puts \"Enter the number of rooms\\n\"\nn = gets.to_i\nc = 0;\n#puts \"Noe enter the number of people living and capacity by giving a space\\n\"\nfor i in 0...n do\n a, b = gets.split.map(&:to_i)\n if b-a >= 2\n c += 1\n end\nend\nputs c\n"}, {"source_code": "n=gets.to_i\nputs [1..n].each.map {|_|\n a,b = gets.split.map(&:to_i)\n a+2<=b ? 1 : 0\n}.inject(&:+)"}, {"source_code": "n=gets.to_i\nputs [1...n].each.map {|_|\n a,b = gets.split.map(&:to_i)\n a+2<=b ? 1 : 0\n}.inject(&:+)"}, {"source_code": "n=gets.to_i\nputs [1..n].map {|_|\n a,b = gets.split.map(&:to_i)\n a+2<=b ? 1 : 0\n}.inject(&:+)"}, {"source_code": "n=gets.to_i\nputs [1...n].map {|_|\n a,b = gets.split.map(&:to_i)\n a+2<=b ? 1 : 0\n}.inject(&:+)"}, {"source_code": "n = gets.chomp.to_i\n\ncont = 0\nfor i in 0...n\n\tinput = gets.chomp.split(\" \")\n\tif input[1].to_i-input[0].to_i>2\n\t\tcont+=1\n\tend\nend\n\nputs cont\n"}, {"source_code": "t = gets.to_i\nco = 0\nt.times do\n p, q = gets.split.map(&:to_i)\n co += 1 if q - p >= 1\nend\nputs co\n"}, {"source_code": "n = gets.chomp.to_i\nc = 0\nn.times do\n s = gets.chomp.split\n p = s[0].to_i\n q = s[1].to_i\n c += 1 if p < q\nend\nputs c"}], "src_uid": "2a6c457012f7ceb589b3dea6b889f7cb"} {"source_code": "gets;a=gets.split.map &:to_i;p a.count{|i|a.inject(i,&:+)&1<1}\n", "positive_code": [{"source_code": "n = gets.to_i\nar = gets.split(' ').map(&:to_i)\nsum = ar.inject(:+)\nputs ar.select{|x| (sum-x).even?}.count"}, {"source_code": "n = STDIN.gets.chomp.to_i\np = STDIN.gets.chomp.split(' ').map{|i| i.to_i}\ntotal = p.reduce(&:+)\nputs p.inject(0) {|res, i| res += 1 if (total - i).even?; res}"}, {"source_code": "a=STDIN.readlines[1].split.map &:to_i\np a.count{|x|(a.inject(:+)-x).even?}\n"}, {"source_code": "n = gets.to_i\n\ngoods = gets.split.map{|i| i.to_i}\n\nsum = 0\ngoods.map{|i| sum += i}\n\nres = 0\nif sum % 2 == 0 then\n n.times do |i|\n if goods[i] % 2 == 0 then\n res += 1\n end\n end\nelse\n n.times do |i|\n if goods[i] % 2 != 0 then\n res += 1\n end\n end\nend\n\nputs res"}, {"source_code": "gets\na = gets.split.map(&:to_i)\np a.count{|i| a.inject(i, &:+).even?}\n"}, {"source_code": "n = gets.chomp.to_i\nbags = gets.chomp.split(\" \").map {|x| x.to_i}\nodd_num = bags.count{|x| x % 2 == 1}\neven_num = bags.length - odd_num\nif odd_num % 2 == 1\n puts odd_num\nelse\n puts even_num\nend\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no=e=0\na.each{|i|\n if i % 2==0 then e+=1 else o+=1 end\n}\nif o % 2 == 0 then\n puts e\nelse\n puts o\nend"}, {"source_code": "gets;a=gets.split.map &:to_i;p a.count{|i|a.inject(i,&:+)&1<1}\n"}, {"source_code": "gets;a=gets.split.map &:to_i;p a.count{|i|a.inject(i,&:+)&1<1}\n"}, {"source_code": "gets;a=gets.split.map &:to_i;p a.count{|i|a.inject(i,&:+)&1<1}"}, {"source_code": "_, a = gets.to_i, gets.split.map(&:to_i)\ns = a.inject(0) { |acc, x| acc+x}\nputs a.map {|x| (s-x).even? ? 1 : 0 }.count 1"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nsum = 0\ncounter = 0\na.each do |x|\n sum+=x\n counter+=1 if x%2 == 0\nend\n\nif sum%2 == 0\n puts counter\nelse\n puts n-counter\nend"}, {"source_code": "#http://codeforces.com/problemset/problem/129/A\n\n\nn = gets.to_i \nlist = gets.split.map(&:to_i)\n\nodd_elements = list.select{ |i| i.odd? } \neven_numbers = n - odd_elements.size\n\nif odd_elements.size.odd? \n puts odd_elements.size \nelsif odd_elements.size.even? \n puts even_numbers \nend "}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nsum=0\nodd=0\neven=0\n0.upto(a-1) do |i| \nsum+=b[i].to_i\nif b[i].to_i%2==0\neven+=1\nelse\nodd+=1\nend\nend\nif sum%2==0\nputs \"#{even}\"\nelse\nputs \"#{odd}\"\nend\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nsum = 0\nans = 0\nfor i in 0..n-1 do\n sum += a[i]\nend\nfor i in 0..n-1 do\n cnt = sum - a[i]\n if (cnt % 2 == 0) then ans += 1 end\nend\nputs ans\n"}, {"source_code": "gets;a=gets.split.map &:to_i;p a.count{|i|a.inject(i,&:+)&1<1}\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nsum=0\nodd=0\neven=0\n0.upto(a-1) do |i| \nsum+=b[i].to_i\nif b[i].to_i%2==0\neven+=1\nelse\nodd+=1\nend\nend\nif sum%2==0\nputs \"#{even}\"\nelse\nputs \"#{odd}\"\nend"}, {"source_code": "n=gets.to_i\nxs=gets.split.map{|e| e.to_i}\nsum=0\nxs.each{|e|\n\tsum+=e\n}\nputs xs.count{|e|\n\t(sum-e)%2==0\n}"}, {"source_code": "gets;a=gets.split.map &:to_i;p a.count{|i|a.inject(i,&:+)&1<1}"}, {"source_code": "result = 0\nn = STDIN.gets.to_i\nif n == 1\n p 1\n exit\nend\nlines = STDIN.gets\nlines = lines.strip.split\nlines.collect! {|i| i.to_i}\neven = lines.count {|i| i % 2 == 0}\nodd = lines.count {|i| i % 2 == 1}\nif odd % 2 == 1\n p odd\nelse \n p even\nend"}, {"source_code": "gets;a=gets.split.map &:to_i;p a.count{|i|a.inject(i,&:+)&1<1}"}, {"source_code": "n=gets\na=[]\na=gets.split.map{|x| x.to_i}\nb=0\ni=0\na.each{|x| b+=x}\nif b.even? then a.each{|x| if x.even? then i+=1 end} else a.each{|x| if x.odd? then i+=1 end} end\nputs i"}, {"source_code": "include Math\n\nn=gets.to_i\narr=gets.split.map(&:to_i)\n\nans=0\nall=arr.inject(:+)\n\narr.each do |val|\n\tans+=1 if (all-val)%2==0\nend\n\nputs ans\n"}, {"source_code": "#WilliamTheCat\na = gets.to_i\nb = gets.split\nb.collect! {|i| i.to_i}\nc = 0\nif (b.inject{|sum,x| sum + x} % 2) == 0 then\n c = b.count {|i| i%2 == 0}\n if (b.count {|i| i%2 != 0}) % 2 != 0 then\n c = c+b.count {|i| i%2 != 0}\n end\nend\nif ((b.inject{|sum,x| sum + x} % 2) != 0) and ((b.count {|i| i%2 != 0}) % 2 != 0) then\n c = b.count {|x|x%2!=0}\nend\np c\n"}, {"source_code": "n = gets.to_i\n\na = gets.split.map &:to_i\n\nsum = a.inject(0) do |x, y|\n x+y\nend\n\nans = a.count do |x|\n x % 2 == sum % 2\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\nodd = 0\neven = 0\nsum = 0\ndata = gets.split.map(&:to_i)\ndata.each do |v|\n sum += v\n if(v % 2 == 0) then\n even += 1\n else\n odd += 1\n end\nend\nif sum % 2 == 0 then\n p even\n else\n p odd\nend\n"}, {"source_code": "gets;a=gets.split.map &:to_i;p a.count{|i|a.inject(i,&:+)&1<1}\n"}, {"source_code": "ar = []\ncount = 0\nn = gets.to_i\nar = gets.split.map &:to_i\nsum = ar.inject{|a,b| a+b}\nar.each do |a|\n b = sum - a\n if b%2 == 0\n count += 1\n end\nend\nputs count"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nsum=0\nodd=0\neven=0\n0.upto(a-1) do |i| \nsum+=b[i].to_i\nif b[i].to_i%2==0\neven+=1\nelse\nodd+=1\nend\nend\nif sum%2==0\nputs \"#{even}\"\nelse\nputs \"#{odd}\"\nend"}, {"source_code": "_, a = gets, gets.split.map(&:to_i)\nr = a.inject(:+)%2\np a.inject(0) { |s, x| s + (x%2 == r ? 1 : 0) }\n"}, {"source_code": "gets;a=gets.split.map(&:to_i)\np a.map{|x| 1-(a.reduce(:+)-x)%2}.reduce(:+)"}, {"source_code": "gets;a=gets.split.map &:to_i;p a.count{|i|a.inject(i,&:+)&1<1}\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\ns = a.inject(0,&:+)\np a.count{ |x| x%2 == s%2 }"}, {"source_code": "gets;a=gets.split.map &:to_i;p a.count{|i|a.inject(i,&:+)&1<1}\n"}, {"source_code": "gets; bags, c = gets.split.map(&:to_i), 0\n\nclass Array\n def sum\n self.inject{ |sum, e| sum + e }\n end\nend\n\nbags.each.with_index do |bag, i|\n d = bags.dup\n d.delete_at(i)\n\n (c += 1; break) if d.empty?\n (c += 1) if d.sum.even?\nend\n\nprint c\n"}, {"source_code": "gets;a=gets.split.map &:to_i;p a.count{|i|a.inject(i,&:+)&1<1}\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nbags = gets.chomp.split(\" \").map {|x| x.to_i}\nodd_num = bags.count{|x| x % 2 == 1}\neven_num = bags.length - odd_num\nputs odd_num\nputs even_num\nif odd_num % 2 == 1\n puts odd_num\nelse\n puts even_num\nend\n"}, {"source_code": "n = gets.chomp.to_i\nbags = gets.chomp.split(\" \").map {|x| x.to_i}\nodd_num = bags.count{|x| x % 2 == 1}\neven_num = bags.length - odd_num\nif odd_num % 2 == 1\n if even_num == 0\n puts odd_num\n else\n puts 1\n end\nelse\n puts even_num\nend\n"}, {"source_code": "n = gets.chomp.to_i\nbags = gets.chomp.split(\" \").map {|x| x.to_i}\nodd_num = bags.count{|x| x % 2 == 1}\neven_num = bags.length - odd_num\nif odd_num % 2 == 1\n puts 1\nelse\n puts even_num\nend\n"}], "src_uid": "4c59b4d43b59c8659bf274f3e29d01fe"} {"source_code": "n = gets.chomp.to_i\na = []\nfor i in 0..n-1\n cn, c = gets.chomp.split(/ /).map!{|x| x.to_i}\n a << [cn, c]\nend\nt = gets.chomp.to_i\nta = gets.chomp.split(/ /).map!{|x| x.to_i}\nf = 1\na.sort!{|a1,a2|\n a1[1] <=> a2[1]\n}\ntix = 0\nret = 0\ndcnt = 0\nfor i in 0..n-1\n nokori = a[i][0]\n while nokori > 0\n if ta[tix] > dcnt\n if ta[tix] >= (dcnt + nokori)\n ret += nokori*a[i][1]*f\n dcnt += nokori\n nokori = 0\n else\n wk = ta[tix] - dcnt\n ret += wk*a[i][1]*f\n dcnt += wk\n nokori -= wk\n end\n else\n ret += nokori*a[i][1]*f\n dcnt += nokori\n nokori = 0\n end\n if ta[tix] == dcnt\n f += 1\n tix += 1 if tix < t-1 \n end\n end\nend\nputs ret", "positive_code": [{"source_code": "n = gets.to_i\nfigures = []\ncount = 0\nn.times do\n figures <<= gets.split.map(&:to_i)\n count += figures[figures.length-1][0]\nend\nt = gets.to_i\np = gets.split.map(&:to_i)\nwhile p.length>0 && p[p.length-1]>count\n p.pop\nend\nif p.length==0 || p[p.length-1]0\n use=[a[a.length-1][1],_p[_p.length-1]].min\n ans+=a[a.length-1][0]*use*now\n a[a.length-1][1]-=use\n _p[_p.length-1]-=use\n if a[a.length-1][1]==0\n a.pop\n end\n if _p[_p.length-1]==0\n _p.pop\n now+=1\n end\nend\np ans"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\na = []\nfor i in 0..n-1\n cn, c = gets.chomp.split(/ /).map!{|x| x.to_i}\n a << [cn, c]\nend\nt = gets.chomp.to_i\nta = gets.chomp.split(/ /).map!{|x| x.to_i}\nf = 1\na.sort!{|a1,a2|\n a1[1] <=> a2[1]\n}\ntix = 0\nret = 0\ndcnt = 0\nfor i in 0..n-1\n nokori = a[i][0]\n while nokori > 0\n if ta[tix] > dcnt\n if ta[tix] >= (dcnt + nokori)\n ret += nokori*a[i][1]*f\n dcnt += nokori\n nokori = 0\n else\n wk = ta[tix] - dcnt\n ret += wk*a[i][1]*f\n dcnt += wk\n nokori -= wk\n end\n else\n ret += nokori*a[i][1]*f\n dcnt += nokori\n nokori = 0\n end\n if tix < t-1 && ta[tix] == dcnt\n f += 1\n tix += 1\n end\n end\nend\nputs ret"}], "src_uid": "bfd7aabf195321249db8760c3cb6998d"} {"source_code": "#!/usr/bin/env ruby\n\nk, a, b = gets.split(' ').map(&:to_i)\n\ntotal = b.div(k) - (a-1).div(k)\n\nputs total\n", "positive_code": [{"source_code": "def solve(k, a, b)\n ans = 0\n if b * a <= 0 then\n ans = b / k + (-a) / k + 1\n else\n m = [a.abs, b.abs].max\n n = [a.abs, b.abs].min\n ans = m / k - (n - 1) / k;\n end\n ans\nend\n\nk, a, b = gets.chomp.split.map(&:to_i)\nputs solve(k, a, b)\n"}, {"source_code": "data = gets.chomp.split\n\nk=data[0].to_i\na=data[1].to_i\nb=data[2].to_i\n\nn=0\nif a*b<0\n\tn=(a).abs/k+b.abs/k+1\nelse\n\tif a%k==0\n\t\tn=b/k-a/k+1\n\telse\n\t\tn=b/k-a/k\n\tend\nend\n\nputs n"}, {"source_code": "# be name khoda ...\ndef read_ints; STDIN.gets.split.map(&:to_i); end\nk,a,b = read_ints\na1 = a/k\nif(a%k != 0)\n\ta1+=1\nend\na2 = b/k\nputs a2 - a1 + 1"}, {"source_code": "def sol(k,a,b)\n if a < 0 && b > 0\n x = (b.abs/k + a.abs/k).abs + 1\n else\n x = (b.abs/k - a.abs/k).abs\n\n if a.abs < b.abs\n if a%k == 0\n x += 1\n end\n else\n if b%k == 0\n x += 1\n end\n end\n end\n\n x\nend\n\nk,a,b=gets.split(/\\s/).map(&:to_i)\np sol(k,a,b)"}, {"source_code": "k, a, b = gets.split.map &:to_i\nputs b / k - (a - 1) / k"}, {"source_code": "class Solver\n\tdef main\n\t\tk, a, b = gets.split.map { |x| x.to_i }\n\t\tif 0.between? a, b then\n\t\t\tputs b / k + (-a) / k + 1\n\t\telse\n\t\t\ta, b = -b, -a if b < 0\n\t\t\tputs b / k - (a - 1) / k\n\t\tend\n\tend\nend\n\nSolver.new.main\n"}], "negative_code": [{"source_code": "def solve(k, a, b)\n ans = 0\n if b * a <= 0 then\n ans = b / k - a / k + 1\n else\n m = [a.abs, b.abs].max\n n = [a.abs, b.abs].min\n ans = m / k - (n - 1) / k;\n end\n ans\nend\n\nk, a, b = gets.chomp.split.map(&:to_i)\nputs solve(k, a, b)\n"}, {"source_code": "data = gets.chomp.split\n\nk=data[0].to_i\na=data[1].to_i\nb=data[2].to_i\n\nn=(b-a)/k+1\nputs n"}, {"source_code": "# be name khoda ...\ndef read_ints; STDIN.gets.split.map(&:to_i); end\nk,a,b = read_ints\na1 = a/k\na1.to_i\na2 = b/k\na2.to_i\nif(a1 == 0) \n\tputs a2\nelse\n\tputs a2 - a1 + 1\nend"}, {"source_code": "# be name khoda ...\ndef read_ints; STDIN.gets.split.map(&:to_i); end\nk,a,b = read_ints\na1 = a/k\na2 = b/k\nputs a2 - a1 + 1"}, {"source_code": "k, a, b = gets.split.map &:to_i\nc = b - a + 1\nputs c / k if c % k == 0\nputs c / k + (a % k == 0 || b % k == 0? 1 : 0) if c % k != 0 "}], "src_uid": "98de093d78f74273e0ac5c7886fb7a41"} {"source_code": "t = gets.to_i\na = t.times.map{gets.to_i}\nputs a.map{|n|\n\tn + (n - 10) / 9 + 1\n}", "positive_code": [{"source_code": "1.upto(gets.to_i) do\n x = gets.to_i\n s = 0\n\n while x >= 10\n s += x.div(10)*10\n x = x.div(10) + x.modulo(10)\n end\n\n puts s + x\nend\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\ndef maximize(r)\n max_r = 0\n digits = 0\n while digits >= 0\n digits = Math.log10(r)\n if digits < 1\n max_r += r\n break\n else\n base = 10 ** (digits.floor)\n lead = r / base\n max_r += lead * base\n r -= lead * base\n r += lead * base / 10\n end\n end\n\n max_r\nend\n\nn = gets.to_i\nn.times {\n puts maximize(gets.to_i)\n}"}, {"source_code": "t=gets.to_i\nfor i in 1..t do\n n=gets.to_i\n s=n\n while n/10>0 do\n s+=n/10\n n=n%10+n/10\n end\n puts(s)\nend"}], "negative_code": [{"source_code": "for i in 1..gets.to_i do\n f=gets.to_i\n puts f+f/9\nend"}, {"source_code": "t=gets.to_i\nfor i in 1..t do\n n=gets.to_i\n s=n\n while n/10>0 do\n s+=n/10\n n=n%10+n/10\n end\n print(s)\nend"}, {"source_code": "for i in 1..gets.to_i do\n f=gets.to_i\n if f%9==0 then\n puts f+f/10\n else\n puts f+f/9\n end\nend"}], "src_uid": "0beecbd62aa072a2f3aab542eeb56373"} {"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,-1)\n exist = true\n len.times do |i|\n if w[i] == 1\n if 0 <= i-n && i+n < len\n if bit[i-n] == -1\n bit[i-n] = 1\n elsif bit[i-n] == 0\n bit[i+n] = 1\n end\n elsif i-n < 0 && len <= i+n\n exist = false\n elsif 0 <= i-n\n if bit[i-n] == 0\n exist = false\n else\n bit[i-n] = 1\n end\n elsif i+n < len\n bit[i+n] = 1\n end\n elsif w[i] == 0\n if 0 <= i-n && i+n < len\n if bit[i-n] == 1 || bit[i+n] == 1\n exist = false\n else\n bit[i-n] = 0\n bit[i+n] = 0\n end\n elsif 0 <= i-n\n if bit[i-n] == 1\n exist = false\n else\n bit[i-n] = 0\n end\n elsif i+n < len\n bit[i+n] = 0\n end\n end\n end\n if exist\n ans << bit\n else\n ans << [\"-1\"]\n end\nend\nans.each do |x|\n x.each do |b|\n if b == -1\n print 1\n else\n print b\n end\n end\n puts \"\"\nend", "positive_code": [{"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,1)\n len.times do |i|\n if w[i] == 0\n if 0 <= i-n\n bit[i-n] = 0\n end\n if i+n < len\n bit[i+n] = 0\n end\n end\n end\n exist = true\n len.times do |i|\n if w[i] == 1\n if 0 <= i-n && i+n < len\n if bit[i-n] == bit[i+n] && bit[i-n] == 0\n exist = false\n end\n elsif i-n < 0 && len <= i+n\n exist = false\n elsif 0 <= i-n\n if bit[i-n] == 0\n exist = false\n end\n else\n if bit[i+n] == 0\n exist = false\n end\n end\n end\n end\n if exist\n ans << bit\n else\n ans << [-1]\n end\nend\nans.each do |x|\n x.each do |b|\n print b\n end\n puts \"\"\nend"}], "negative_code": [{"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,0)\n exist = true\n len.times do |i|\n flg = false\n if 0 <= i-n && i+n <= len-1\n if w[i-n] != w[i+n]\n exist = false\n else\n if w[i-n] == 1\n flg = true\n end\n end\n elsif i-n < 0 && len-1 < i+n\n next\n elsif 0 <= i-n\n if w[i-n] == 1\n flg = true\n end\n elsif i+n <= len-1\n if w[i+n] == 1\n flg = true\n end\n end\n if flg\n bit[i] = 1\n end\n end\n str = \"\"\n if exist\n len.times do |i|\n str = str + bit[i].to_s\n end\n else\n str = \"-1\"\n end\n ans << str\nend\nans.each do |x|\n puts x\nend"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,-1)\n exist = true\n len.times do |i|\n if 0 <= i-n\n if bit[i-n] == -1\n bit[i-n] = w[i]\n elsif bit[i-n] != w[i]\n exist = false\n end\n end\n if i+n < len\n if bit[i+n] == -1\n bit[i+n] = w[i]\n elsif bit[i+n] != w[i]\n exist = false\n end\n end\n end\n str = \"\"\n if exist\n len.times do |i|\n if bit[i] == -1\n str = str + \"1\"\n else\n str = str + bit[i].to_s\n end\n end\n else\n str = \"-1\"\n end\n ans << str\nend\nans.each do |x|\n puts x\nend"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,0)\n exist = true\n len.times do |i|\n flg = false\n if 0 <= i-n && i+n <= len-1\n if w[i-n] != w[i+n]\n exist = false\n else\n if w[i-n] == 1\n flg = true\n end\n end\n elsif 0 <= i-n\n if w[i-n] == 1\n flg = true\n end\n elsif i+n <= len-1\n if w[i+n] == 1\n flg = true\n end\n elsif i-n < 0 && len-1 < i+n\n exist = false\n end\n if flg\n bit[i] = 1\n end\n end\n str = \"\"\n if exist\n len.times do |i|\n str = str + bit[i].to_s\n end\n else\n str = \"-1\"\n end\n ans << str\nend\nans.each do |x|\n puts x\nend"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,0)\n exist = true\n len.times do |i|\n flg = false\n if 0 <= i-n && i+n <= len-1\n if w[i-n] != w[i+n]\n exist = false\n else\n if w[i-n] == 1\n flg = true\n end\n end\n elsif 0 <= i-n\n if w[i-n] == 1\n flg = true\n end\n elsif i+n <= len-1\n if w[i+n] == 1\n flg = true\n end\n end\n if flg\n bit[i] = 1\n end\n end\n str = \"\"\n if exist\n len.times do |i|\n str = str + bit[i].to_s\n end\n else\n str = \"-1\"\n end\n ans << str\nend\nans.each do |x|\n puts x\nend\n"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,-1)\n exist = true\n len.times do |i|\n if w[i] == 1\n if 0 <= i-n && i+n < len\n if bit[i-n] == -1\n bit[i-n] = 1\n elsif bit[i-n] == 0\n bit[i+n] = 1\n end\n elsif 0 <= i-n\n if bit[i-n] == 0\n exist = false\n else\n bit[i-n] = 1\n end\n elsif i+n < len\n bit[i+n] = 1\n end\n elsif w[i] == 0\n if 0 <= i-n && i+n < len\n if bit[i-n] == 1 || bit[i+n] == 1\n exist = false\n else\n bit[i-n] = 0\n bit[i+n] = 0\n end\n elsif 0 <= i-n\n if bit[i-n] == 1\n exist = false\n else\n bit[i-n] = 0\n end\n elsif i+n < len\n bit[i+n] = 0\n end\n end\n end\n str = \"\"\n if exist\n len.times do |i|\n if bit[i] == -1\n str = str + \"1\"\n else\n str = str + bit[i].to_s\n end\n end\n else\n str = \"-1\"\n end\n ans << str\n if n != 2 && n != 1 && n != 31 && n != 17 && n != 39 && n != 62 && str != \"-1\"\n ans << n\n s = \"\"\n len.times do |i|\n s = s + w[i].to_s\n end\n ans << s\n end\nend\nans.each do |x|\n puts x\nend"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,0)\n exist = true\n len.times do |i|\n flg = false\n if 0 <= i-n && i+n <= len-1\n if w[i-n] != w[i+n]\n exist = false\n else\n w[i-n] == 1\n flg = true\n end\n elsif 0 <= i-n\n if w[i-n] == 1\n flg = true\n end\n elsif i+n <= len-1\n if w[i+n] == 1\n flg = true\n end\n end\n if flg\n bit[i] = 1\n end\n end\n str = \"\"\n if exist\n len.times do |i|\n str = str + bit[i].to_s\n end\n else\n str = \"-1\"\n end\n ans << str\nend\nans.each do |x|\n puts x\nend\n"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,0)\n exist = true\n len.times do |i|\n flg = false\n flg2 = false\n if 0 <= i-n\n if w[i-n] == 1\n flg = true\n end\n end\n if i+n <= len-1\n if w[i+n] == 1\n flg2 = true\n elsif flg\n exist = false\n end\n end\n if 0 <= i-n\n if w[i-n] == 1\n flg = true\n elsif flg2\n exist = false\n end\n end\n if flg || flg2\n bit[i] = 1\n end\n end\n str = \"\"\n if exist\n len.times do |i|\n str = str + bit[i].to_s\n end\n else\n str = \"-1\"\n end\n ans << str\nend\nans.each do |x|\n puts x\nend"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,-1)\n exist = true\n len.times do |i|\n if w[i] == 1\n if 0 <= i-n && i+n < len\n if bit[i-n] == -1\n bit[i-n] = 1\n elsif bit[i-n] == 0\n bit[i+n] = 1\n end\n elsif 0 <= i-n\n if bit[i-n] == 0\n exist = false\n else\n bit[i-n] = 1\n end\n elsif i+n < len\n bit[i+n] = 1\n end\n elsif w[i] == 0\n if 0 <= i-n && i+n < len\n if bit[i-n] == 1 || bit[i+n] == 1\n exist = false\n else\n bit[i-n] = 0\n bit[i+n] = 0\n end\n elsif 0 <= i-n\n if bit[i-n] == 1\n exist = false\n else\n bit[i-n] = 0\n end\n elsif i+n < len\n bit[i+n] = 0\n end\n end\n end\n str = \"\"\n if exist\n len.times do |i|\n if bit[i] == -1\n str = str + \"1\"\n else\n str = str + bit[i].to_s\n end\n end\n else\n str = \"-1\"\n end\n ans << str\n if n != 2 && n != 1 && n != 31 && n != 17 && n != 39 && n != 62 && str != \"-1\"\n ans << n\n ans << w\n end\nend\nans.each do |x|\n puts x\nend"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,-1)\n exist = true\n len.times do |i|\n if w[i] == 1\n if 0 <= i-n && i+n < len\n if bit[i-n] == -1\n bit[i-n] = 1\n elsif bit[i-n] == 0\n bit[i+n] = 1\n end\n elsif 0 <= i-n\n if bit[i-n] == 0\n exist = false\n else\n bit[i-n] = 1\n end\n elsif i+n < len\n bit[i+n] = 1\n end\n elsif w[i] == 0\n if 0 <= i-n && i+n < len\n if bit[i-n] == 1 || bit[i+n] == 1\n exist = false\n else\n bit[i-n] = 0\n bit[i+n] = 0\n end\n elsif 0 <= i-n\n if bit[i-n] == 1\n exist = false\n else\n bit[i-n] = 0\n end\n elsif i+n < len\n bit[i+n] = 0\n end\n end\n end\n str = \"\"\n if exist\n len.times do |i|\n if bit[i] == -1\n str = str + \"1\"\n else\n str = str + bit[i].to_s\n end\n end\n else\n str = \"-1\"\n end\n ans << str\nend\nans.each do |x|\n puts x\nend"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n w = gets.chomp.split(\"\").map(&:to_i)\n n = gets.to_i\n len = w.length\n bit = Array.new(len,0)\n exist = true\n len.times do |i|\n flg = false\n if 0 <= i-n && i+n <= len-1\n if w[i-n] != w[i+n]\n exist = false\n else\n if w[i-n] == 1\n flg = true\n end\n end\n elsif i-n < 0 && len-1 < i+n\n exist = false\n elsif 0 <= i-n\n if w[i-n] == 1\n flg = true\n end\n elsif i+n <= len-1\n if w[i+n] == 1\n flg = true\n end\n end\n if flg\n bit[i] = 1\n end\n end\n str = \"\"\n if exist\n len.times do |i|\n str = str + bit[i].to_s\n end\n else\n str = \"-1\"\n end\n ans << str\nend\nans.each do |x|\n puts x\nend"}], "src_uid": "02854d98266e5b74bf105ba30ea332df"} {"source_code": "def get_left_dominoes doms_state\n\tleft_num = 0\n\tcur_dir = nil\n\tbetween_num = 0\n\tdoms_state.each do |dir|\n\t\tif dir == \"L\"\n\t\t\tif cur_dir == \"R\"\n\t\t\t\tif (between_num%2) == 1\n\t\t\t\t\tleft_num += 1\n\t\t\t\tend\n\t\t\t\tcur_dir = nil\n\t\t\tend\n\t\t\tbetween_num = 0\n\t\telsif dir == \"R\"\n\t\t\tif cur_dir == nil\n\t\t\t\tleft_num += between_num\n\t\t\t\tbetween_num = 0\n\t\t\t\tcur_dir = \"R\"\n\t\t\tend\n\t\telse\n\t\t\tbetween_num += 1\n\t\tend\n\tend\n\n\tif cur_dir != \"R\"\n\t\tleft_num += between_num\n\tend\n\n\treturn left_num\nend\n\ngets\nary = gets.split(//)\nary.pop\nputs get_left_dominoes ary", "positive_code": [{"source_code": "n = gets.to_i\ns = gets.chomp\nli = Array.new\nfor i in 0...n\n if s[i] == 'L' or s[i] == 'R'\n li.push(i)\n end\nend\nif li.empty?\n puts n\n exit\nend\nans = 0\nif s[li[0]] == 'R'\n ans += li[0]\nend\nif s[li[-1]] == 'L'\n ans += n-1-li[-1]\nend\nfor i in 1...li.length\n if s[li[i-1]]=='R' and s[li[i]]=='L' and (li[i]-li[i-1]).even?\n ans += 1\n elsif s[li[i-1]]=='L' and s[li[i]]=='R'\n ans += li[i]-li[i-1]-1\n end\nend\nputs ans\n"}, {"source_code": "count = sum = 0\nprev = nil\ngets\ngets.chomp.chars.each { |c|\n if c == '.'\n count += 1\n else\n if c == 'R'\n sum += count\n elsif prev && count.odd?\n sum += 1\n end\n count = 0\n prev = c\n end\n}\n\nsum += count if !prev || prev == 'L'\n\nputs sum"}, {"source_code": "#!/usr/bin/ruby\ngets\ns=gets.chomp\nloop{\n\tt=s.dup\n\tt.size.times{|i|\n\t\tnext if t[i,1]!='.'\n\t\tr=0 currR)\n\t\t\t\tnum = currL - currR - 1\n\t\t\t\trez = rez + 1 if num.odd?\n\t\t\t\ts = s.drop(currL)\n\t\t\t\tcurrL = 0\n\t\t\t\tcurrR = s.find_index(\"R\")\n\t\t\telse\n\t\t\t\trez = rez + currR - currL - 1\n\t\t\t\ts = s.drop(currR)\n\t\t\t\tcurrR = 0\n\t\t\t\tcurrL = s.find_index(\"L\")\n\t\t\tend\n\t\telse\n\t\t\tif currR\n\t\t\t\tbreak\n\t\t\telse\n\t\t\t\trez = rez + s.length - currL - 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\n\nputs rez"}, {"source_code": "gets\na=gets.chomp\nwhile true\n\ti1=a.index 'L'\n\ti2=a.index 'R'\n\tif (i1 && !i2 ) || ( i1 && i2 && i1i1 )\n\t\tif i2==0\n\t\t\ta=\"\"\n\t\t\tbreak\n\t\tend\n\t\ta=a[0..i2-1]\n\telse\n\t\tbreak\n\tend\nend\nans = 0\nwhile a[0]=='.'\n\tans+=1\n\ta=a[1..-1]\nend\nwhile a[-1]=='.'\n\tans+=1\n\ta=a[0..-2]\nend\n(1..a.size-2).each{ |i|\n\tnext if a[i]!='.'\n\tl=i-1\n\tr=i+1\n\twhile a[l]=='.'\n\t\tl-=1\n\tend\n\twhile a[r]=='.'\n\t\tr+=1\n\tend\n\tans += 1 if (a[l]=='R' && a[r] == 'L' && (l-r)%2==0 && i-l==r-i)||(a[l]=='L'&&a[r]=='R')\n}\np ans\n"}, {"source_code": "#!/usr/bin/ruby\ngets\ns=gets.chomp\nloop{\n t=s.dup\n t.size.times{|i|\n next if t[i,1]!='.'\n r=0i1 )\n\t\tif i2==0\n\t\t\ta=\"\"\n\t\t\tbreak\n\t\tend\n\t\ta=a[0..i2-1]\n\telse\n\t\tbreak\n\tend\nend\nans = 0\nwhile a[0]=='.'\n\tans+=1\n\ta=a[1..-1]\nend\nwhile a[-1]=='.'\n\tans+=1\n\ta=a[0..-2]\nend\n(1..a.size-2).each{ |i|\n\tnext if a[i]!='.'\n\tl=i-1\n\tr=i+1\n\twhile a[l]=='.'\n\t\tl-=1\n\tend\n\twhile a[r]=='.'\n\t\tr+=1\n\tend\n\tans += 1 if a[l]=='R' && a[r] == 'L' && (l-r)%2==0 && i-l==r-i\n}\np ans\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nli = Array.new\nfor i in 0...n\n if s[i] == 'L' or s[i] == 'R'\n li.push(i)\n end\nend\nif li.empty?\n puts n\n exit\nend\nans = 0\nif s[li[0]] == 'R'\n ans += li[0]\nend\nif s[li[-1]] == 'L'\n ans += n-1-li[-1]\nend\nfor i in 1...li.length\n if (li[i]-li[i-1]).even?\n ans += 1\n end\nend\nputs ans\n"}], "src_uid": "54c748dd983b6a0ea1af1153d08f1c01"} {"source_code": "#!/usr/bin/env ruby\ncount = gets.chomp.to_i\nanswers = []\ncount.times do\n input = gets.chomp.split(' ').map(&:to_i)\n n = input[0]\n x = input[1]\n a = input[2]\n b = input[3]\n\n distance_after_swaps = (a-b).abs + x\n \n answers << if distance_after_swaps > n - 1\n n-1\n else\n distance_after_swaps\n end\nend\n\nanswers.each { |answer| puts answer }\n", "positive_code": [{"source_code": "gets.to_i.times do\n n, x, a, b = gets.split.map(&:to_i)\n puts [(n - 1), (a-b).abs + x].min\nend\n"}, {"source_code": "g = gets.chomp.to_i\ng.times{\nn,x,a,b = gets.split(\" \").map{|x|x.to_i}\nqw = [a,b]\na = qw.min\nb = qw.max\n\nx.times{\nif a>1 \na-=1\nelsif b= j\n\t\t\tdv = ar[i] / j\n\t\t\tsum += dv * j\n\t\tend\n\tend\n\tmaxsum = sum if maxsum < sum\nend\nputs maxsum", "positive_code": [{"source_code": "n,l=gets.split.map(&:to_i)\nres=[]\na=gets.split.map(&:to_i)\nl.upto(100){|k|\n ans=0\n a.each{|b|\n ans+=b/k\n }\n res.push(ans*k)\n}\np res.max\n"}, {"source_code": "l,a=[1,2].map{gets.split.map &:to_i};p (l[1]..100).map{|h|a.map{|x|x/h*h}.inject:+}.max\n"}, {"source_code": "l,a=[1,2].map{gets.split.map &:to_i};p (l[1]..100).map{|h|a.map{|x|x/h*h}.inject:+}.max\n"}, {"source_code": "l,a=[1,2].map{gets.split.map &:to_i};p (l[1]..100).map{|h|a.map{|x|x/h*h}.inject:+}.max"}, {"source_code": "l,a=[1,2].map{gets.split.map &:to_i};p (l[1]..100).map{|h|a.inject{|s,x|(s/h+x/h)*h}}.max"}, {"source_code": "l,a=[1,2].map{gets.split.map &:to_i};p (l[1]..100).map{|h|a.map{|x|x/h*h}.inject:+}.max\n"}, {"source_code": "l,a=[1,2].map{gets.split.map &:to_i};p (l[1]..100).map{|h|a.map{|x|x/h*h}.inject:+}.max\n"}, {"source_code": "a,b=gets.split.map(&:to_i)\nx=gets.split.map(&:to_i)\np (b..100).map{|l|x.inject(0){|s,n|s+n/l}*l}.max"}, {"source_code": "l,a=[1,2].map{gets.split.map &:to_i};p (l[1]..100).map{|h|a.map{|x|x/h*h}.inject:+}.max"}, {"source_code": "def get_answer(k)\n s = 0\n $a.each{|x| s += x / k}\n s\nend\n\ndef max(a, b)\n if a >= b\n a\n else\n b\n end\nend\n\nn, l = gets.split.map(&:to_i)\n$a = gets.split.map(&:to_i).to_a\n\nm = 0\n$a.each{|x| m = max(m, x)}\n\nans = 0\n(l..m).each{|i| ans = max(ans, get_answer(i) * i)}\n\nputs ans\n"}, {"source_code": "l,a=[1,2].map{gets.split.map &:to_i};p (l[1]..100).map{|h|a.map{|x|x/h*h}.inject:+}.max\n"}, {"source_code": "l,a=[1,2].map{gets.split.map &:to_i};p (l[1]..100).map{|h|a.map{|x|x/h*h}.inject:+}.max\n"}, {"source_code": "n, l = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\nres = 0\n\nl.upto(100) do |x|\n count = arr.map { |a| a / x }.reduce(:+)\n res = [res, count * x].max\nend\n\nputs res"}, {"source_code": "l,a=[1,2].map{gets.split.map &:to_i};p (l[1]..100).map{|h|a.map{|x|x/h*h}.inject:+}.max\n"}, {"source_code": "def max(a, b)\n a > b ? a : b\nend\n\nn, l = gets.split.map { |v| v.to_i }\nlenghts = gets.split.map { |v| v.to_i }\n\nsurface = 0\n\n(l .. lenghts.max).each do |d|\n k = lenghts.inject(0) { |r, lenght| r + lenght / d }\n surface = max(surface, k * d)\nend\n\nputs surface\n"}, {"source_code": "l,a=[1,2].map{gets.split.map &:to_i};p (l[1]..100).map{|h|a.map{|x|x/h*h}.inject:+}.max\n"}], "negative_code": [{"source_code": "n,l=gets.split.map(&:to_i)\nans=0\na=gets.split.map(&:to_i)\na.each{|b|\n ans+=b/l\n}\np ans*l\n"}, {"source_code": "a,b=gets.split.map(&:to_i)\np gets.split.inject(0){|s,n|s+n.to_i/b}*b"}, {"source_code": "n, l = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n\np l * arr.map { |x| x / l }.reduce(:+)"}], "src_uid": "991516fa6f3ed5a71c547a3a50ea1a2b"} {"source_code": "n = gets.chomp.to_i\nas = []\nbs = {}\nn.times do\n a, b = gets.chomp.split.map(&:to_i)\n as << a\n bs[a] = b\nend\n\nas.sort!\nar = as.reverse\ndp = [0]\nis = {}\nis[as[0]] = 0\nans = n - 1\nfor i in 1...n\n a = as[i]\n b = bs[a]\n is[a] = i\n a1 = ar.bsearch { |x| x < a - b }\n if a1.nil?\n dp << i\n else\n i1 = is[a1]\n dp << (i - i1 - 1 + dp[i1])\n end\n ans = [ans, n - i - 1 + dp[i]].min\nend\nputs ans", "positive_code": [{"source_code": "def lower_bound(array, value)\n left = -1\n right = array.length\n while left + 1 < right\n mid = left + (right - left) / 2\n if array[mid] >= value\n right = mid\n else\n left = mid\n end\n end\n right\nend\n\nn = gets.chomp.to_i\n\npos_lev = []\npos = []\nn.times do\n pos_lev << gets.chomp.split(' ').map{|i| i.to_i}\n pos << pos_lev.last[0]\nend\npos_lev.sort!\npos.sort!\n\ndp = Array.new(0)\ndp[0] = 0\nans = n\n\nn.times do |i|\n l = pos_lev[i][0] - pos_lev[i][1]\n t = lower_bound(pos, l)\n dp[i+1] = dp[t] + (i-t)\n ans = dp[i+1] + (n-i-1) if ans > dp[i+1] + (n-i-1)\nend\n\nputs ans"}, {"source_code": "def lower_bound(array, value)\n left = -1\n right = array.length\n while left + 1 < right\n mid = left + (right - left) / 2\n if array[mid] >= value\n right = mid\n else\n left = mid\n end\n end\n right\nend\n\nn = gets.chomp.to_i\n\npos_lev = []\npos = []\nn.times do\n pos_lev << gets.chomp.split(' ').map{|i| i.to_i}\n pos << pos_lev.last[0]\nend\npos_lev.sort!\npos.sort!\n\ndp = Array.new(0)\ndp[0] = 0\nans = n\n\nn.times do |i|\n l = pos_lev[i][0] - pos_lev[i][1]\n t = lower_bound(pos, l)\n dp[i+1] = dp[t] + (i-t)\n ans = dp[i+1] + (n-i-1) if ans > dp[i+1] + (n-i-1)\nend\n\nputs ans"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nas = []\nbs = {}\nn.times do\n a, b = gets.chomp.split.map(&:to_i)\n as << a\n bs[a] = b\nend\n\nas.sort!\nar = as.reverse\ndp0 = [1]\ndp1 = [0]\nis = {}\nis[as[0]] = 0\nans = n - 1\nfor i in 1...n\n a = as[i]\n b = bs[a]\n is[a] = i\n i0 = i - 1\n dp0 << (1 + [dp0[i0], dp1[i0]].min)\n a1 = ar.bsearch { |x| x < a - b }\n if a1.nil?\n dp1 << i\n else\n i1 = is[a1]\n dp1 << (i - i1 - 1 + [dp0[i1], dp1[i1]].min)\n end\n ans = [ans, n - i - 1 + dp1[i]].min\nend\nans = [ans, dp0[-1]].min\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\nas = []\nbs = {}\nn.times do\n a, b = gets.chomp.split.map(&:to_i)\n as << a\n bs[a] = b\nend\n\nas.sort!\nar = as.reverse\ndp0 = [1]\ndp1 = [0]\nis = {}\nis[as[0]] = 0\nfor i in 1...n\n a = as[i]\n b = bs[a]\n is[a] = i\n i0 = i - 1\n dp0 << (1 + [dp0[i0], dp1[i0]].min)\n a1 = ar.bsearch { |x| x < a - b }\n if a1.nil?\n dp1 << i\n else\n i1 = is[a1]\n dp1 << (i - i1 - 1 + [dp0[i1], dp1[i1]].min)\n end\nend\n\nputs [dp0[-1], dp1[-1]].min\n"}, {"source_code": "n = gets.chomp.to_i\nas = []\nbs = {}\nn.times do\n a, b = gets.chomp.split.map(&:to_i)\n as << a\n bs[a] = b\nend\n\nas.sort!\nar = as.reverse\ndp0 = [1]\ndp1 = [0]\nis = {}\nis[as[0]] = 0\nans = n - 1\nfor i in 1...n\n a = as[i]\n b = bs[a]\n is[a] = i\n i0 = i - 1\n dp0 << (1 + [dp0[i0], dp1[i0]].min)\n a1 = ar.bsearch { |x| x < a - b }\n if a1.nil?\n dp1 << i\n else\n i1 = is[a1]\n dp1 << (i - i1 - 1 + [dp0[i1], dp1[i1]].min)\n end\n ans = [ans, n - i - 1 + dp0[i], n - i - 1 + dp1[i]].min\nend\nputs ans\n"}], "src_uid": "bcd689387c9167c7d0d45d4ca3b0c4c7"} {"source_code": "n,m,k = gets.split(\" \").map(&:to_i)\ncells = n * m\ntube_cell = cells/k\nleftover = cells % k\nodd = true\nans = []\ncount = tube_cell\n(1..n).each do |i|\n\trange = odd ? (1..m) : m.downto(1)\n\trange.each do |j|\n\t\tif ans.length != k && count == tube_cell\n\t\t\tcount = 0\n\t\t\tans << []\n\t\tend\n\t\tans[-1] << i << j\n\t\tcount += 1\t\t\n\tend\n\todd = !odd\nend\n\nans.each do |a|\n\tputs \"#{a.length/2} #{a.join(' ')}\"\nend", "positive_code": [{"source_code": "n,m,k=gets.split.map(&:to_i)\nl=n*m\na=[]\nc=[]\nk-=1\n(1..n).each do |i|\n\tf=(i%2==0)? m : 1\n\tf.step(m-f+1,(i%2==0) ? -1 : 1) do |j| \n\t\tc< n\n \n while y > 0\n zigzag << [x, y]\n y -= 1\n end\n\n x += 1\nend\n\n\nwhile k > 1\n print '2 '\n print zigzag.pop.join(' ')\n print ' '\n print zigzag.pop.join(' ')\n puts ''\n k-=1\nend\n\nprint zigzag.size\nprint ' '\nprint zigzag.join(' ')\n"}], "negative_code": [{"source_code": "def build(n, m)\n (0...n).map { |i|\n if i % 2 == 0\n (0...m).map { |j| [i, j] }\n else\n (0...m).map { |j| [i, j] }.reverse\n end\n }.flatten 1\nend\n\nn,m,k = gets.split.map(&:to_i)\npoint_sequence = build(n,m)\nper = point_sequence.size / k\n\n\n(0...k).each { |i|\n from = i*per\n to = (i < k-1) ? (i+1)*per : point_sequence.size\n line = point_sequence[from...to].join \" \"\n puts \"#{to-from} #{line}\"\n}\n"}], "src_uid": "779e73c2f5eba950a20e6af9b53a643a"} {"source_code": "s = gets.chop\nn = s.size\nb = [0] * n\ne = [0] * n\nn.times{|i|\n 2.times{|j|\n l, r = i, i + j\n while 0 <= l && s[l] == s[r]\n b[l] += 1\n e[r] += 1\n l -= 1\n r += 1\n end\n }\n}\ns, t = 0, 0\nn.times{|i|\n s += t * b[i]\n t += e[i]\n}\np s\n\n", "positive_code": [{"source_code": "s = gets.chop\nn = s.size\nb = [0] * n\ne = [0] * n\nn.times{|i|\n 2.times{|j|\n l, r = i, i + j\n while 0 <= l && s[l] == s[r]\n b[l] += 1\n e[r] += 1\n l -= 1\n r += 1\n end\n }\n}\ns, t = 0, 0\nn.times{|i|\n s += t * b[i]\n t += e[i]\n}\np s\n"}, {"source_code": "s = gets.chop\nn = s.size\nb = [0] * n\ne = [0] * n\nn.times{|i|\n 2.times{|j|\n l, r = i, i + j\n while 0 <= l && s[l] == s[r]\n b[l] += 1\n e[r] += 1\n l -= 1\n r += 1\n end\n }\n}\ns, t = 0, 0\nn.times{|i|\n s += t * b[i]\n t += e[i]\n}\np s\n\n"}, {"source_code": "s = gets.chop\nn = s.size\nb = [0] * n\ne = [0] * n\nn.times{|i|\n 2.times{|j|\n l, r = i, i + j\n while 0 <= l && s[l] == s[r]\n b[l] += 1\n e[r] += 1\n l -= 1\n r += 1\n end\n }\n}\ns, t = 0, 0\nn.times{|i|\n s += t * b[i]\n t += e[i]\n}\np s\n\n"}, {"source_code": "s = gets.chop\nn = s.size\nb = [0] * n\ne = [0] * n\nn.times{|i|\n 2.times{|j|\n l, r = i, i + j\n while 0 <= l && s[l] == s[r]\n b[l] += 1\n e[r] += 1\n l -= 1\n r += 1\n end\n }\n}\ns, t = 0, 0\nn.times{|i|\n s += t * b[i]\n t += e[i]\n}\np s\n\n"}, {"source_code": "s = gets.chop\nn = s.size\nb = [0] * n\ne = [0] * n\nn.times{|i|\n 2.times{|j|\n l, r = i, i + j\n while 0 <= l && s[l] == s[r]\n b[l] += 1\n e[r] += 1\n l -= 1\n r += 1\n end\n }\n}\ns, t = 0, 0\nn.times{|i|\n s += t * b[i]\n t += e[i]\n}\np s\n\n"}, {"source_code": "s = gets.chop\nn = s.size\nb = [0] * n\ne = [0] * n\nn.times{|i|\n 2.times{|j|\n l, r = i, i + j\n while 0 <= l && s[l] == s[r]\n b[l] += 1\n e[r] += 1\n l -= 1\n r += 1\n end\n }\n}\ns, t = 0, 0\nn.times{|i|\n s += t * b[i]\n t += e[i]\n}\np s"}, {"source_code": "s = gets.chomp\na = [0]*s.size\nb = [0]*s.size\n\ns.size.times do |i|\n 2.times do |add|\n lf, ri = i,i + add\n while lf >= 0 and ri < s.size and s[lf] == s[ri]\n a[lf] = a[lf] + 1\n b[ri] = b[ri] + 1\n lf = lf - 1\n ri = ri + 1\n end\n end\nend\nsum = 0\nans = 0\ns.size.times do |i|\n ans += sum*a[i]\n sum += b[i]\nend\nputs ans\n \n\n"}, {"source_code": "s = gets.chop\nn = s.size\nb = [0] * n\ne = [0] * n\nn.times{|i|\n 2.times{|j|\n l, r = i, i + j\n while 0 <= l && s[l] == s[r]\n b[l] += 1\n e[r] += 1\n l -= 1\n r += 1\n end\n }\n}\ns, t = 0, 0\nn.times{|i|\n s += t * b[i]\n t += e[i]\n}\np s\n\n"}, {"source_code": "\ndef count_palindromes(i, j)\n return if i < 0 || j >= @n\n\n if @string[i] == @string[j]\n\n @starting[i] += 1\n @ending[j] += 1\n\n count_palindromes(i - 1, j + 1)\n end\nend\n\n@string = gets.strip\n@n = @string.length\n\n@starting = Array.new(@n) { 1 }\n@ending = Array.new(@n) { 1 }\n\n(1...@n).each do |i|\n count_palindromes(i - 1, i)\n count_palindromes(i - 1, i + 1)\nend\n\n\n@ending_sums = Array.new(@n) { 0 }\n@ending_sums[0] = @ending[0]\n(1...@n).each do |i|\n @ending_sums[i] = @ending_sums[i - 1] + @ending[i]\nend\n\n# puts @starting, \"\", @ending, \"\", @ending_sums\n\nresult = 0\n(1...@n).each do |i|\n result += @ending_sums[i - 1] * @starting[i]\nend\n\nputs result\n"}, {"source_code": "s = gets.chop\nn = s.size\nb = [0] * n\ne = [0] * n\nn.times{|i|\n 2.times{|j|\n l, r = i, i + j\n while 0 <= l && s[l] == s[r]\n b[l] += 1\n e[r] += 1\n l -= 1\n r += 1\n end\n }\n}\ns, t = 0, 0\nn.times{|i|\n s += t * b[i]\n t += e[i]\n}\np s\n\n"}, {"source_code": "s = gets.chop\nn = s.size\nb = [0] * n\ne = [0] * n\nn.times{|i|\n 2.times{|j|\n l, r = i, i + j\n while 0 <= l && s[l] == s[r]\n b[l] += 1\n e[r] += 1\n l -= 1\n r += 1\n end\n }\n}\ns, t = 0, 0\nn.times{|i|\n s += t * b[i]\n t += e[i]\n}\np s\n\n"}, {"source_code": "s = gets.chop\nn = s.size\nb = [0] * n\ne = [0] * n\nn.times{|i|\n 2.times{|j|\n l, r = i, i + j\n while 0 <= l && s[l] == s[r]\n b[l] += 1\n e[r] += 1\n l -= 1\n r += 1\n end\n }\n}\ns, t = 0, 0\nn.times{|i|\n s += t * b[i]\n t += e[i]\n}\np s\n\n"}], "negative_code": [], "src_uid": "1708818cf66de9fa03439f608c897a90"} {"source_code": "p,q=gets.split.map(&:to_i)\nn=gets.to_i\na=[]\na=gets.split.map(&:to_i)\ns=1\nb=0\ni = n\nwhile i>0\ni=i-1\nks=b\nkb=s\ns=kb*a[i]+ks\nb=kb\nend\nif s*q==b*p\nprint \"YES\"\nend\nif s*q!=b*p\nputs \"NO\"\nend", "positive_code": [{"source_code": "require\"mathn\"\np,q=gets.split.map(&:to_i)\nn=gets.to_i\na=gets.split.map(&:to_i)\nfrac=a.last\na[0..-2].reverse.each{|aa|frac=aa+1/frac}\nputs p/q==frac ? \"YES\" : \"NO\""}, {"source_code": "require\"mathn\"\np, q = gets.split(' ').map { |i| i.to_i }\nn = gets.to_i\na = gets.split(' ').map { |i| i.to_i }\nr = a.last\na[0..-2].reverse.each { |e| r = e + 1 / r;}\nputs p / q == r ? \"YES\" : \"NO\"\n"}, {"source_code": "require 'mathn'\n\nclass B\n def initialize\n p, q = gets.chomp.split(' ').map(&:to_i)\n n = gets.chomp\n num_list = gets.chomp.split(' ').map(&:to_i)\n\n res = calc(num_list.shift, num_list)\n if res == p/q\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\n\n def calc(a, b)\n if b.size == 0\n return a\n else\n a + 1/calc(b.shift, b)\n end\n end\nend\n\nb = B.new"}, {"source_code": "require\"mathn\"\np,q=gets.split.map(&:to_i)\nn=gets.to_i\na=gets.split.map(&:to_i)\nfrac=a.last\na[0..-2].reverse.each{|aa|frac=aa+1/frac}\nputs p/q==frac ? \"YES\" : \"NO\"\n"}, {"source_code": "require\"mathn\"\np,q=gets.split.map(&:to_i)\nn=gets.to_i\na=gets.split.map(&:to_i)\nfrac=a.last\na[0..-2].reverse.each{|aa|frac=aa+1/frac}\nputs p/q==frac ? \"YES\" : \"NO\"\n"}, {"source_code": "require \"mathn\"\n\nloop do\n line = gets\n break if line.nil?\n p,q = line.split(\" \").map(&:to_i)\n n = gets.to_i\n as = gets.split(\" \").map(&:to_i)\n cal = as.reverse.inject(0){ |res, val|\n res **= -1 unless res.zero?\n res + val\n }\n if cal == p/q\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n"}, {"source_code": "require\"mathn\"\np,q=gets.split.map(&:to_i)\nn=gets.to_i\na=gets.split.map(&:to_i)\nfrac=a.last\na[0..-2].reverse.each{|aa|frac=aa+1/frac}\nputs p/q==frac ? \"YES\" : \"NO\""}, {"source_code": "p, q = gets.split.map(&:to_i)\nn = gets.to_i\na = gets.split.reverse.map(&:to_i)\n\nx = Rational(0)\nfor i in 0 .. n-2 do\n x += Rational(a[i], 1)\n x = Rational(1, x)\nend\nx += Rational(a[n-1], 1)\n\nif Rational(p, q) == x then\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "require\"mathn\"\np,q=gets.split.map(&:to_i)\nn=gets.to_i\na=gets.split.map(&:to_i)\nfrac=a.last\na[0..-2].reverse.each{|aa|frac=aa+1/frac}\nputs p/q==frac ? \"YES\" : \"NO\"\n"}, {"source_code": "p,q = gets.chomp.split(\" \").collect {|x| x.to_i}\nn = gets.to_i\narr = gets.chomp.split(\" \").collect {|x| x.to_i}\n\nif arr[-1]==1 and arr.length>1\n arr[-2] += 1\n arr.delete_at(n-1)\nend\n\nok = true\nnt = p\naux = -1\narr.each { |v|\n if q == 0\n ok = false\n break\n end\n nt = p/q\n if (nt!=v)\n ok = false\n break\n end\n aux = p%q\n p = q\n q = aux\n\n}\n\nif ok and aux == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "def rec(ary)\n\treturn Rational(1, ary.last) if ary.size == 1\n\tRational(1, ary.first + rec(ary.drop(1)))\nend\n\nf1 = Rational(*gets.split.map(&:to_i))\ngets\nf2 = rec(gets.split.map(&:to_i))\n\nif f1 == Rational(f2.denominator, f2.numerator)\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "require\"mathn\"\np,q=gets.split.map(&:to_i)\nn=gets.to_i\na=gets.split.map(&:to_i)\nfrac=a.last\na[0..-2].reverse.each{|aa|frac=aa+1/frac}\nputs p/q==frac ? \"YES\" : \"NO\"\n"}, {"source_code": "def solve(a, p, q)\n if a.size == 1\n return p == q * a.first ? \"YES\" : \"NO\"\n end\n t = a.shift\n solve(a,q, (p - t * q))\nend\n\np,q = gets.split.map(&:to_i)\nn = gets.to_i\na = gets.split.map(&:to_i)\n\nputs solve(a,p,q)\n"}, {"source_code": "p, q = gets.split.map(&:to_i)\nd = p.gcd(q)\np, q = p / d, q / d\nn = gets.to_i\na = gets.split.map(&:to_i)\nx, y = a[n-1], 1\n(n-2).downto(0) do |i|\n\tx, y = y, x\n\tx = x + a[i] * y\nend\nif x == p && y == q\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Fraction\n @num\n @den\n \n def initialize(a, b)\n @num = a\n @den = b\n end\n\n def num=(num)\n @num = num\n end\n\n def num\n @num\n end\n\n def den=(den)\n @den = den\n end\n\n def den\n @den\n end\nend\n\ndef cf(pos)\n return Fraction.new(1, $nums[pos]) if pos + 1 == $n\n\n res = cf(pos + 1)\n temp = Fraction.new(res.num + res.den * $nums[pos], res.den)\n return Fraction.new(temp.den, temp.num)\nend\n\ntokens = gets.split(\" \")\np = tokens[0].to_i\nq = tokens[1].to_i\n$n = gets.to_i\n\n\ntokens = gets.split(\" \")\n$nums = Array.new($n)\n\n0.upto(tokens.length - 1) do |i|\n $nums[i] = tokens[i].to_i\nend\n\nresult = cf(0)\n\ng = p.gcd(q)\n#puts g\n\nf = result.num.gcd(result.den)\n#puts f\n\np /= g\nq /= g\n\na = result.den / f\nb = result.num / f\n\nif b == q and a == p\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "require\"mathn\"\np,q=gets.split.map(&:to_i)\nn=gets.to_i\na=gets.split.map(&:to_i)\nfrac=a.last\na[0..-2].reverse.each{|aa|frac=aa+1/frac}\nputs p/q==frac ? \"YES\" : \"NO\"\n"}, {"source_code": "require\"mathn\"\np,q=gets.split.map(&:to_i)\nn=gets.to_i\na=gets.split.map(&:to_i)\nfrac=a.last\na[0..-2].reverse.each{|aa|frac=aa+1/frac}\nputs p/q==frac ? \"YES\" : \"NO\""}, {"source_code": "(p,q) = gets.split(' ').map{|i| i.to_i()}\nn = gets.to_i()\na = gets.split(' ').map{|i| i.to_i()}\nx,y = 1,0\n\na.reverse_each{|i| x,y = y+x*i,x}\n\nputs ((x*q==y*p)?\"YES\":\"NO\")\n"}, {"source_code": "require\"mathn\"\np,q=gets.split.map(&:to_i)\nn=gets.to_i\na=gets.split.map(&:to_i)\nfrac=a.last\na[0..-2].reverse.each{|aa|frac=aa+1/frac}\nputs p/q==frac ? \"YES\" : \"NO\"\n"}, {"source_code": "(p, q) = gets.split.map(&:to_i)\nn = gets.to_i\na = gets.split.map(&:to_i)\n\nr = Rational(0)\nfor b in a.reverse\n r = 1 / (b + r)\nend\n\nif r == Rational(q, p)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "require\"mathn\"\np,q=gets.split.map(&:to_i)\nn=gets.to_i\na=gets.split.map(&:to_i)\nfrac=a.last\na[0..-2].reverse.each{|aa|frac=aa+1/frac}\nputs p/q==frac ? \"YES\" : \"NO\"\n"}, {"source_code": "require\"mathn\"\np,q=gets.split.map(&:to_i)\nn=gets.to_i\na=gets.split.map(&:to_i)\nfrac=a.last\na[0..-2].reverse.each{|aa|frac=aa+1/frac}\nputs p/q==frac ? \"YES\" : \"NO\"\n"}, {"source_code": "require\"mathn\"\np,q = gets.split().map {|x| x.to_i}\nn = gets.to_i\na = gets.split().map {|x| x.to_i}\na = a.reverse\nres = a[0];\na[1..-1].each {|x| res = x+1/res}\n\nputs (res == p/q)? \"YES\" : \"NO\"\n\n"}], "negative_code": [{"source_code": "p,q = gets.split().map {|x| x.to_i}\nn = gets.to_i\na = gets.split().map {|x| x.to_i}\na.reverse!\nres = a[0];\na[1..-1].each {|x| res = x+1.0/res}\nputs (res == 1.0*p/q)? \"YES\" : \"NO\"\n"}, {"source_code": "p,q = gets.split().map {|x| x.to_i}\nn = gets.to_i\na = gets.split().map {|x| x.to_i}\na.reverse!\nres = a[0];\na[1..-1].each {|x| res = x+1/res}\nputs (res == p/q)? \"YES\" : \"NO\"\n"}, {"source_code": "p, q = gets.split(' ').map { |i| i.to_f }\nn = gets.to_i\na = gets.split(' ').map { |i| i.to_f }\nr = a.last\na[0..-2].reverse_each { |e| r = e + 1.0 / r;}\nputs p / q == r ? \"YES\" : \"NO\""}, {"source_code": "p, q = gets.split(' ').map {|i| i.to_i}\nn = gets.to_i\na = gets.split(' ').map {|i| i.to_i}\ndef fun(arr, ind)\n if(ind == arr.size - 1)\n return [1, arr[ind]]\n end\n ret = fun(arr, ind + 1)\n return [ret[1], ret[0] + arr[ind] * ret[1]]\nend\nret = fun(a, 0)\nif p == ret[1] and q == ret[0] then puts \"YES\"\nelse puts \"NO\"\nend"}, {"source_code": "p, q = gets.split(' ').map { |i| i.to_i }\nn = gets.to_i\na = gets.split(' ').map { |i| i.to_i }\nr = a.last\na[0..-2].reverse.each { |e| r = e + 1 / r;}\nputs p / q == r ? \"YES\" : \"NO\"\n"}, {"source_code": "p, q = gets.split(' ').map { |i| i.to_f }\nn = gets.to_i\na = gets.split(' ').map { |i| i.to_f }\nr = a.last\na[0..-2].reverse.each { |e| r = e + 1 / r;}\nputs p / q == r ? \"YES\" : \"NO\"\n"}, {"source_code": "class B\n def initialize\n p, q = gets.chomp.split(' ').map(&:to_f)\n n = gets.chomp\n num_list = gets.chomp.split(' ').map(&:to_f)\n\n res = calc(num_list.shift, num_list)\n if res == p/q\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\n\n def calc(a, b)\n if b.size == 0\n return a\n else\n a + 1/calc(b.shift, b)\n end\n end\nend\n\nb = B.new"}, {"source_code": "#!/usr/bin/ruby\n\nclass Fraction\n @num\n @den\n \n def initialize(a, b)\n @num = a\n @den = b\n end\n\n def num=(num)\n @num = num\n end\n\n def num\n @num\n end\n\n def den=(den)\n @den = den\n end\n\n def den\n @den\n end\nend\n\ndef cf(pos)\n return Fraction.new(1, $nums[pos]) if pos + 1 == $n\n\n res = cf(pos + 1)\n temp = Fraction.new(res.num + res.den * $nums[pos], res.den)\n return Fraction.new(temp.den, temp.num)\nend\n\ntokens = gets.split(\" \")\np = tokens[0].to_i\nq = tokens[1].to_i\n$n = gets.to_i\n\n\ntokens = gets.split(\" \")\n$nums = Array.new($n)\n\n0.upto(tokens.length - 1) do |i|\n $nums[i] = tokens[i].to_i\nend\n\nresult = cf(0)\n\nif result.num == q and result.den == p\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}], "src_uid": "447ebe088a0a60a7a44a3fc76056bc65"} {"source_code": "n, k = gets.strip.split(' ').map(&:to_i)\na = gets.strip.split(' ').map(&:to_i)\nh = gets.strip.split('').to_a\n\n\nres = 0\nlast = h[0]\ntmp = []\nidx = 0\n\nwhile idx < a.size\n if idx.zero?\n tmp << a[idx]\n idx += 1\n next\n end\n if h[idx] != h[idx - 1]\n res += tmp.size.zero? ? 0 : tmp.sort.reverse.slice(0, k).inject(:+)\n tmp = [a[idx]]\n else\n tmp << a[idx]\n end\n idx += 1\nend\nif tmp.size > 0\n res += tmp.size.zero? ? 0 : tmp.sort.reverse.slice(0, k).inject(:+)\nend\nputs res", "positive_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\n#use moving window to get the sum\nnk = gets.chomp.split(\" \").map(&:to_i)\nn = nk[0]\nk = nk[1]\na = gets.chomp.split(\" \").map(&:to_i)\ns = gets.chomp\n\narr = [0]\nbreakpoints = 2\n(1..n-1).each do |i|\n\tif s[i]!=s[i-1]\n\t\tbreakpoints+=1\n\t\tarr.push i\n\tend\nend\narr.push n\n\ntotsum = 0\n#bigarr = []\n=begin\n\n(0..breakpoints-2).each do |st|\n\tnewarr = []\n\tnewlen = 1\n\tmin = 1.0/0.0\n\tsum = 0\n\tmax = 0\n\t(arr[st]..arr[st+1]-1).each do |range|\n\t\tthis = a[range]\n#\t\tp newlen\n\t\tif(newlen<=k)\n\t\t\tnewarr.push this\n\t\t\tsum+=this\n\t\t\tmin = this if thismin)\n\t\t\t\tsum-=min\n\t\t\t\tsum+=this\n\t\t\t\tnewarr.push this\n\t\t\t\tnewarr.delete_at(newarr.index(min))\n\t\t\t\tmin = newarr.min\n\t\t\tend\n\t\tend\n\t\tmax = sum if sum>max\n\tend\n\ttotsum += sum\nend\n=end\n#p arr\n(0..breakpoints-2).each do |st|\n\tnewarr = a[arr[st]..arr[st+1]-1].sort\n#\tp newarr\n\tiniti = newarr.length-1\n\ti = initi\n\tmin = arr[st]\n\tsum = 0\n#\tp initi\n\twhile true\n\t\tbreak if (initi-i+1)>k\n\t\tbreak if i<0\n#\t\tp i\n\t\tsum+=newarr[i]\n\t\ti -= 1\n#\t\tp sum\n\tend\n#\tp sum\n\ttotsum += sum\nend\n\n\n#p arr\nputs totsum"}], "negative_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\n#use moving window to get the sum\nnk = gets.chomp.split(\" \").map(&:to_i)\nn = nk[0]\nk = nk[1]\na = gets.chomp.split(\" \").map(&:to_i)\ns = gets.chomp\n\narr = [0]\nbreakpoints = 2\n(1..n-1).each do |i|\n\tif s[i]!=s[i-1]\n\t\tbreakpoints+=1\n\t\tarr.push i\n\tend\nend\narr.push n\n\nbigarr = []\n(0..breakpoints-2).each do |st|\n\tnewarr = []\n\tnewlen = 1\n\tmin = 1.0/0.0\n\tsum = 0\n\t(arr[st]..arr[st+1]-1).each do |range|\n\t\tthis = a[range]\n#\t\tp newlen\n\t\tif(newlen<=k)\n\t\t\tnewarr.push this\n\t\t\tsum+=this\n#\t\t\tmin = this if thismin)\n\t\t\t\tsum-=newarr.pop\n\t\t\t\tsum+=this\n\t\t\t\tnewarr.push this\n#\t\t\t\tnewarr.delete_at(newarr.index(min))\n#\t\t\t\tmin = newarr.min\n\t\t\tend\n\t\tend\n\t\tnewarr.sort!\n\t\tbigarr.push sum\n\tend\nend\n\ntotsum = 0\n(0..breakpoints-2).each do |st|\n\ttotsum += bigarr[arr[st]..arr[st+1]-1].max\nend\n\n#p arr\n#p bigarr\nputs totsum"}], "src_uid": "aa3b5895046ed34e89d5fcc3264b3944"} {"source_code": "a=gets.chomp.split(\" \")\nn=a[0].to_f\np=a[1].to_f\nj=a[2].to_f\ns=gets.chomp\n\nsc1=0\nsc1c=0\nsc1n=n\nloop do\n sc1n=sc1n-p\n\tbreak if sc1n <= 0\n\tif sc1n%j==0\n\t\tsc1+=1\n\tend\n\tsc1c+=1\n\tbreak if sc1n%j==0\nend \n\n\nsc2=0\nsc2c=0\nsc2n=n\nloop do\n sc2n=sc2n-j\n\tbreak if sc2n <= 0\n\tif sc2n%p==0\n\t\tsc2+=1\n\tend\n\tsc2c+=1\n\tbreak if sc2n%p==0\nend \n\n\n\n\nif n==p+j\n puts 2\n puts s[0..(p-1)]\n puts s[p..(s.length-1)]\nelsif n%p==0\n split=n/p\n\tputs split.to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==split\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\n \nelsif n%j==0\n split=n/j\n\tputs split.to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==split\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\nelsif sc1>0\n\tputs (sc1c+(n-sc1c*p)/j ).to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==sc1c\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\n\t\n\tc2=0\n\tloop do\n\t\tbreak if c2==(n-sc1c*p)/j\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\nelsif sc2>0\n\tputs (sc2c+(n-sc2c*j)/p ).to_i\n\t\n\tc2=0\n\tloop do\n\t\tbreak if c2==sc2c\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==(n-sc2c*j)/p\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\nelse\n\tputs -1\nend", "positive_code": [{"source_code": "#!/usr/bin/ruby\nn,a,b=gets.split.map(&:to_i)\nj=0.upto(n/a).find{|i|(n-i*a)%b==0}\nif !j\n\tp -1\nelse\n\tk=(n-j*a)/b\n\ts=gets.chomp.chars.to_a\n\tp j+k\n\tj.times{puts s.shift(a)*''}\n\tk.times{puts s.shift(b)*''}\nend"}, {"source_code": "#!/usr/bin/ruby\nn,a,b=gets.split.map(&:to_i)\nj=0.upto(n/a).find{|i|(n-i*a)%b==0}\nif !j\n\tp -1\nelse\n\tk=(n-j*a)/b\n\ts=gets.chomp.chars.to_a\n\tp j+k\n\tj.times{puts s.shift(a)*''}\n\tk.times{puts s.shift(b)*''}\nend\n"}, {"source_code": "#!/usr/bin/ruby\nn,a,b=gets.split.map(&:to_i)\nj=0.upto(n/a).find{|i|(n-i*a)%b==0}\nif !j\n\tp -1\nelse\n\tk=(n-j*a)/b\n\ts=gets.chomp.chars.to_a\n\tp j+k\n\tj.times{puts s.shift(a)*''}\n\tk.times{puts s.shift(b)*''}\nend\n"}, {"source_code": "\ndef count(n, p, q, s)\n\ti = 0\n\n\twhile (n - i*q) >=0\t\t\n\t\tif (n-i*q)%p == 0\n\t\t\tres = Array.new\n \t\t\ti.times do |e|\n \t\t\t\tres << s[e*q...(e+1)*q]\n\t\t\tend\n\n\t\t\thead = i*q\n\t\t\t\n\t\t\t(((n-i*q)/p).to_i()).times do |e|\n\t\t\t\tres << s[head+e*p...head+(e+1)*p]\n\t\t\tend\n\n\t\t\tputs i+(n-i*q)/p.to_i\n\t\t\tputs res\n\t\t\treturn 1\n\t\tend\t\t\n\t\ti += 1\n\t\t\n\tend\n\treturn -1\nend\n\n\nn, p, q = gets.strip.split.map(&:to_i)\ns = gets.strip\np, q = q, p if p > q\nif count(n,p,q, s) == -1\n\tputs -1\nend"}, {"source_code": "#!/usr/bin/ruby\nn,a,b=gets.split.map(&:to_i)\nj=0.upto(n/a).find{|i|(n-i*a)%b==0}\nif !j\n\tp -1\nelse\n\tk=(n-j*a)/b\n\ts=gets.chomp.chars.to_a\n\tp j+k\n\tj.times{puts s.shift(a)*''}\n\tk.times{puts s.shift(b)*''}\nend\n"}, {"source_code": "a=gets.chomp.split(\" \")\nn=a[0].to_f\np=a[1].to_f\nj=a[2].to_f\ns=gets.chomp\n\nsc1=0\nsc1c=0\nsc1n=n\nloop do\n sc1n=sc1n-p\n\tbreak if sc1n <= 0\n\tif sc1n%j==0\n\t\tsc1+=1\n\tend\n\tsc1c+=1\n\tbreak if sc1n%j==0\nend \n\n\nsc2=0\nsc2c=0\nsc2n=n\nloop do\n sc2n=sc2n-j\n\tbreak if sc2n <= 0\n\tif sc2n%p==0\n\t\tsc2+=1\n\tend\n\tsc2c+=1\n\tbreak if sc2n%p==0\nend \n\n\n\n\nif n==p+j\n puts 2\n puts s[0..(p-1)]\n puts s[p..(s.length-1)]\nelsif n%p==0\n split=n/p\n\tputs split.to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==split\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\n \nelsif n%j==0\n split=n/j\n\tputs split.to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==split\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\nelsif sc1>0\n\tputs (sc1c+(n-sc1c*p)/j ).to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==sc1c\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\n\t\n\tc2=0\n\tloop do\n\t\tbreak if c2==(n-sc1c*p)/j\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\nelsif sc2>0\n\tputs (sc2c+(n-sc2c*j)/p ).to_i\n\t\n\tc2=0\n\tloop do\n\t\tbreak if c2==sc2c\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==(n-sc2c*j)/p\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\nelse\n\tputs -1\nend"}, {"source_code": "#!/usr/bin/ruby\nn,a,b=gets.split.map(&:to_i)\nj=0.upto(n/a).find{|i|(n-i*a)%b==0}\nif !j\n\tp -1\nelse\n\tk=(n-j*a)/b\n\ts=gets.chomp.chars.to_a\n\tp j+k\n\tj.times{puts s.shift(a)*''}\n\tk.times{puts s.shift(b)*''}\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef split n, p, q\n max_left_coeff = n / p\n (0..max_left_coeff).each do |a|\n left = a * p\n right = n - left\n if right % q == 0\n return [a, (right / q)]\n end\n end\n [-1, 0]\nend\n\nn, p, q = gets.split.map(&:to_i)\ns = gets.chomp\n\na, b = split(n, p, q)\n\nputs (a + b)\na.times do\n puts s[0, p]\n s = s[p..s.size-1]\nend\nb.times do\n puts s[0, q]\n s = s[q..s.size-1]\nend\n"}, {"source_code": "line1 = gets.to_s.split(' ').collect{ |x| x.to_i}\nn = line1[0]\np = line1[1]\nq = line1[2]\n\ns = gets\n\nx = n / p\n\ny = n / q\ntotal = -1\ntmp = -1\n(0..x).each do |index|\n ci = n - index * p\n if ci % q == 0\n total = index + ci / q\n tmp = index\n break\n end\nend\n\nputs total\nif total != -1\n cur = 0\n (1..tmp).each do\n puts s[cur...cur+p]\n cur+=p\n end\n (1..total - tmp).each do\n puts s[cur...cur+q]\n cur += q\n end\nend"}, {"source_code": "n, p, q = gets.split.map(&:to_i)\ns = gets.chomp\n\na = b = -1\nfor i in 0..100\n for j in 0..100\n if p*i + q*j == n\n a = i\n b = j\n end\n end\nend\n\nif a == -1\n puts a\n exit\nend\n\nputs a+b\n\nidx = 0\n(1..a).each do\n puts s[idx, p]\n idx += p\nend\n\n(1..b).each do\n puts s[idx, q]\n idx += q\nend\n"}, {"source_code": "a=gets.chomp.split(\" \")\nn=a[0].to_f\np=a[1].to_f\nj=a[2].to_f\ns=gets.chomp\n\nsc1=0\nsc1c=0\nsc1n=n\nloop do\n sc1n=sc1n-p\n\tbreak if sc1n <= 0\n\tif sc1n%j==0\n\t\tsc1+=1\n\tend\n\tsc1c+=1\n\tbreak if sc1n%j==0\nend \n\n\nsc2=0\nsc2c=0\nsc2n=n\nloop do\n sc2n=sc2n-j\n\tbreak if sc2n <= 0\n\tif sc2n%p==0\n\t\tsc2+=1\n\tend\n\tsc2c+=1\n\tbreak if sc2n%p==0\nend \n\n\n\n\nif n==p+j\n puts 2\n puts s[0..(p-1)]\n puts s[p..(s.length-1)]\nelsif n%p==0\n split=n/p\n\tputs split.to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==split\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\n \nelsif n%j==0\n split=n/j\n\tputs split.to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==split\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\nelsif sc1>0\n\tputs (sc1c+(n-sc1c*p)/j ).to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==sc1c\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\n\t\n\tc2=0\n\tloop do\n\t\tbreak if c2==(n-sc1c*p)/j\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\nelsif sc2>0\n\tputs (sc2c+(n-sc2c*j)/p ).to_i\n\t\n\tc2=0\n\tloop do\n\t\tbreak if c2==sc2c\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==(n-sc2c*j)/p\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\nelse\n\tputs -1\nend\n"}, {"source_code": "#!/usr/bin/ruby\nn,a,b=gets.split.map(&:to_i)\nj=0.upto(n/a).find{|i|(n-i*a)%b==0}\nif !j\n\tp -1\nelse\n\tk=(n-j*a)/b\n\ts=gets.chomp.chars.to_a\n\tp j+k\n\tj.times{puts s.shift(a)*''}\n\tk.times{puts s.shift(b)*''}\nend\n"}, {"source_code": "#!/usr/bin/ruby\nn,a,b=gets.split.map(&:to_i)\nj=0.upto(n/a).find{|i|(n-i*a)%b==0}\nif !j\n\tp -1\nelse\n\tk=(n-j*a)/b\n\ts=gets.chomp.chars.to_a\n\tp j+k\n\tj.times{puts s.shift(a)*''}\n\tk.times{puts s.shift(b)*''}\nend\n"}, {"source_code": "n,p,q=gets.split.map(&:to_i)\ns=gets.chomp.split(//)\na=b=0\n\n0.upto(100){|k|\n\tm=n-k*p\n\tbreak if m<0\n\tif m%q==0\n\t\ta=k\n\t\tb=m/q\n\t\tbreak\n\tend\n}\nif a==0&&b==0\n\tputs -1\nelse\n\tputs a+b\n\ta.times{puts s.shift(p).join}\n\tb.times{puts s.shift(q).join}\nend\n"}, {"source_code": "class Solver\n\tdef main\n\t\tn, a, b = gets.split.map { |x| x.to_i }\n\t\tstr = gets.chomp\n\t\t0.upto(n) do |l|\n\t\t\tr = n - l\n\t\t\tif l % a == 0 && r % b == 0\n\t\t\t\tputs l / a + r / b\n\t\t\t\t0.upto(l / a - 1) do |i|\n\t\t\t\t\tputs str[i * a, a]\n\t\t\t\tend\n\t\t\t\t0.upto(r / b - 1) do |i|\n\t\t\t\t\tputs str[l + i * b, b]\n\t\t\t\tend\n\t\t\t\treturn\n\t\t\tend\n\t\tend\n\t\tputs -1\n\tend\nend\nSolver.new.main\n"}, {"source_code": "#!/usr/bin/ruby\nn,a,b=gets.split.map(&:to_i)\nj=0.upto(n/a).find{|i|(n-i*a)%b==0}\nif !j\n\tp -1\nelse\n\tk=(n-j*a)/b\n\ts=gets.chomp.chars.to_a\n\tp j+k\n\tj.times{puts s.shift(a)*''}\n\tk.times{puts s.shift(b)*''}\nend\n"}], "negative_code": [{"source_code": "a=gets.chomp.split(\" \")\nn=a[0].to_f\np=a[1].to_f\nj=a[2].to_f\ns=gets.chomp\n\nsc1=0\nsc1c=0\nsc1n=n\nloop do\n sc1n=sc1n-p\n\tbreak if sc1n <= 0\n\tif sc1n%j==0\n\t\tsc1+=1\n\tend\n\tsc1c+=1\n\tbreak if sc1n%j==0\nend \n\n\nsc2=0\nsc2c=0\nsc2n=n\nloop do\n sc2n=sc2n-j\n\tbreak if sc2n <= 0\n\tif sc2n%p==0\n\t\tsc2+=1\n\tend\n\tsc2c+=1\n\tbreak if sc2n%p==0\nend \n\n\n\n\nif n==p+j\n puts 2\n puts s[0..(p-1)]\n puts s[p..(s.length-1)]\nelsif n%p==0\n split=n/p\n\tputs split.to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==split\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\n \nelsif n%j==0\n split=n/j\n\tputs split.to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==split\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\nelsif sc1>0\n\tputs (sc1c+(n-sc1c*p)/j ).to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==sc1c\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==(n-sc1c*p)/j\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\nelsif sc2>0\n\tputs (sc2c+(n-sc2c*j)/p ).to_i\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==sc2c\n\t\tputs s[c1..(c1+j-1)]\n\t\tc1=c1+j\n c2+=1 \n\tend\t\n\tc1=0\n\tc2=0\n\tloop do\n\t\tbreak if c2==(n-sc2c*j)/p\n\t\tputs s[c1..(c1+p-1)]\n\t\tc1=c1+p\n c2+=1 \n\tend\t\nelse\n\tputs -1\nend\n"}, {"source_code": "n, p, q = gets.split.map(&:to_i)\ns = gets.chomp\n\nif s.length%p != 0 && s.length%q != 0 && s.length%(p+q) != 0\n puts -1\n exit\nend\n\narr = []\nif s.length%p == 0\n arr = [p]\n puts s.length/p\nelsif s.length%(p+q) == 0\n arr = [p, q]\n puts (s.length/(p+q))*2\nelsif s.length%q == 0\n arr = [q]\n puts s.length/q\nend\n\ncount = 0\nidx = 0\nwhile count != s.length\n puts s[count, arr[idx%arr.length]]\n count += arr[idx%arr.length]\n idx += 1\nend\n"}], "src_uid": "c4da69789d875853beb4f92147825ebf"} {"source_code": "n,z = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i).sort\nmatch = []\nans = 0\n(n/2).times do |i|\n idx = (0..n-1).bsearch{|j| x[j] >= x[i]+z}\n match[i] = idx.nil? ? -1 : n-idx+i\n #p [i,idx]\nend\n\n#p match\nmin = n/2\n(n/2).times do |i|\n break if (i+1) > [match[i],min].min\n ans += 1\n min = match[i] if min > match[i]\nend\np ans\n", "positive_code": [{"source_code": "N, Z = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\narr.sort!\np1, p2 = 0, N / 2\nanswer = 0\nwhile p2 < N\n\tbreak if p1 == N / 2\n\tif arr[p2] - arr[p1] >= Z\n\t\tanswer += 1\n\t\tp1 += 1\n\t\tp2 += 1\n\telse\n\t\tp2 += 1\n\tend\nend\nputs answer\n"}, {"source_code": "n,z = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i).sort\nmatch = []\nans = 0\n(n/2).times do |i|\n idx = (0..n-1).bsearch{|j| x[j] >= x[i]+z}\n match[i] = idx.nil? ? -1 : n-idx\nend\n\nmatchable = n/2\n(n/2).times do |i|\n matchable = match[i]+i if matchable > match[i]+i\n break if (i+1) > matchable\n ans += 1\nend\np ans"}], "negative_code": [{"source_code": "n,z = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i).sort\nused = [false]*n\nans = 0\nn.times do |i|\n if !used[i]\n idx = (0..n-1).bsearch{|j| x[j] >= x[i]+z}\n if !idx.nil?\n used[i] = true\n used[idx] = true\n ans += 1\n end\n end\nend\n#p used\np ans\n"}, {"source_code": "n,z = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i).sort\nmatch = []\nans = 0\n(n/2).times do |i|\n idx = (0..n-1).bsearch{|j| x[j] >= x[i]+z}\n match[i] = idx.nil? ? -1 : n-idx+i\nend\n\n#p match\n(n/2).times do |i|\n break if (i+1) > match[i]\n ans += 1\nend\np ans\n"}, {"source_code": "n,z = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i).sort\nmatch = []\nans = 0\n(n/2).times do |i|\n idx = (0..n-1).bsearch{|j| x[j] >= x[i]+z}\n match[i] = idx.nil? ? -1 : n-idx\nend\n\nans = 0\ntmp = n/2\n(n/2).times do |i|\n c = tmp < match[i]+i ? tmp : match[i]+i\n break if (i+1) > c || match[i] < 0\n ans += 1\nend\np ans\n"}, {"source_code": "n,z = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i).sort\nmatch = []\nans = 0\n(n/2).times do |i|\n idx = (0..n-1).bsearch{|j| x[j] >= x[i]+z}\n match[i] = idx.nil? ? -1 : n-idx\nend\n\nans = n/2\n(n/2).times do |i|\n t = ans < match[i]+i ? ans : match[i]+i\n break if (i+1) > t\n ans = t\nend\np ans\n"}, {"source_code": "N, Z = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i).sort\np1, p2 = 0, 1\nanswer = 0\nwhile p2 < N\n\tif arr[p1]\n\t\tif arr[p2]\n\t\t\tif arr[p2] - arr[p1] >= Z\n\t\t\t\tanswer += 1\n\t\t\t\tarr[p2] = arr[p1] = nil\n\t\t\t\tp1 += 1\n\t\t\t\tp2 += 1\n\t\t\telse\n\t\t\t\tp2 += 1\n\t\t\tend\n\t\telse\n\t\t\tp2 += 1\n\t\tend\n\telse\n\t\tp1 += 1\n\tend\nend\nputs answer\n"}, {"source_code": "N, Z = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\narr.sort!\np1, p2 = 0, N / 2\nanswer = 0\nwhile p2 < N\n\tif arr[p2] - arr[p1] >= Z\n\t\tanswer += 1\n\t\tp1 += 1\n\t\tp2 += 1\n\telse\n\t\tp2 += 1\n\tend\nend\nputs answer\n"}, {"source_code": "N, Z = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i).sort\np1, p2 = 0, 1\nanswer = 0\nwhile p2 < N\n\tif arr[p2]\n\t\tif arr[p1]\n\t\t\tif arr[p2] - arr[p1] >= Z\n\t\t\t\tanswer += 1\n\t\t\t\tarr[p2] = arr[p1] = nil\n\t\t\t\tp1 += 1\n\t\t\t\tp2 += 1\n\t\t\telse\n\t\t\t\tp2 += 1\n\t\t\tend\n\t\telse\n\t\t\tp1 += 1\n\t\tend\n\telse\n\t\tp2 += 1\n\tend\nend\nputs answer\n"}], "src_uid": "b063660572a78f25525656332a1782a8"} {"source_code": "n, t= gets.split(\" \").map(&:to_i)\nday = 1\na = gets.split(\" \").map(&:to_i)\na.each do |work_time|\n t = t-86400+work_time\n day+=1 if t>0\nend\nprint(day)\n\n", "positive_code": [{"source_code": "n,t,*a=$<.read.split.map &:to_i\np (1..n).find{|i|0>=t-=86400-a[i-1]}"}, {"source_code": "n, t = gets.chomp.split(' ').map(&:to_i)\narr = gets.chomp.split(' ').map(&:to_i)\n\nSECONDS = 86400\nnum = 0\nresult = 0\n\nwhile t > 0\n\tt -= (SECONDS - arr[result])\n\tresult += 1\nend\n \nputs result\n\n"}, {"source_code": "n, t = gets.strip.split.map(&:to_i)\na = gets.strip.split.map(&:to_i)\nans = 0\nn.times do |i|\n free = 86400 - a[i]\n t -= free\n ans += 1\n break if t <= 0\nend\nputs ans\n"}, {"source_code": "n,t=gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\ncur = 0\nn.times do |i|\n cur += 86400 - a[i]\n if cur >= t\n puts i + 1\n break\n end\nend"}, {"source_code": "in_str = gets\nn, allt = in_str.split(' ')\nn, allt = n.to_i, allt.to_i\nin_str = gets\ntime_arr = in_str.split(' ').map { |element| element.to_i }\nt = 0\ntime_arr.each_with_index do |elem, i|\n t += 86400 - elem\n if t >= allt\n puts i + 1\n break\n end\nend"}, {"source_code": "n,t,*a=$<.read.split.map &:to_i\np (1..n).find{|i|0>=t-=86400-a[i-1]}"}], "negative_code": [{"source_code": "n,t=gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\ncur = 0\nn.times do |i|\n cur += 86400 - a[i]\n if cur >= t\n puts i + 1\n end\nend"}], "src_uid": "8e423e4bec2d113612a4dc445c4b86a9"} {"source_code": "t = gets.chomp.to_i\nt.times {\n\ta, b, c = gets.split.map(&:to_i)\n\tif (a == b) && (c == a)\n\t\tputs \"1 1 1\"\n\t\tnext\n\tend\n\taa = [a, [b, c].max + 1].max - a \n\tbb = [b, [a, c].max + 1].max - b\n\tcc = [c, [a, b].max + 1].max - c\n\tputs \"#{aa} #{bb} #{cc}\"\n}", "positive_code": [{"source_code": "gets.to_i.times do\r\n arr = gets.split.each_with_index.map{ |c, i| c.to_i }\r\n mx = arr.max\r\n c = arr.count(mx)\r\n puts arr.map{|e| e != mx ? mx - e + 1 : c > 1 ? 1 : 0}.join ' '\r\n\r\nend\r\n"}, {"source_code": "class Pair\r\n attr_accessor :first, :second\r\n include Comparable\r\n\r\n def initialize(first, second)\r\n @first = first\r\n @second = second\r\n end\r\n\r\n def <=>(an_other)\r\n @first <=> an_other.first\r\n end\r\nend\r\ngets.to_i.times do\r\n arr = gets.split.each_with_index.map{ |c, i| Pair.new(c.to_i, i) }\r\n arr = arr.sort()\r\n ans = Array.new;\r\n arr.length.times do |idx|\r\n if idx == arr.length - 1\r\n if arr.length >= 2 and arr[arr.length - 1].first == arr[arr.length - 2].first\r\n ans[ arr[arr.length - 1].second ] = 1;\r\n else\r\n ans[ arr[arr.length - 1].second ] = 0;\r\n end\r\n else\r\n ans[ arr[idx].second ] = arr[arr.length-1].first - arr[idx].first + 1;\r\n end\r\n end\r\n\r\n arr.length.times do |idx|\r\n if idx == arr.length - 1\r\n puts(ans[idx])\r\n else\r\n print(ans[idx])\r\n print(\" \")\r\n end\r\n end\r\n\r\n\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n votes = gets.split.map(&:to_i)\r\n m = votes.max\r\n c = votes.count(m)\r\n puts votes.map{|v| v != m ? m - v + 1 : c > 1 ? 1 : 0}.join ' '\r\nend"}, {"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |inp|\r\n cans = inp.split(' ').map(&:to_i)\r\n\r\n r = []\r\n cans.each_with_index do |n, i|\r\n other = cans.reject.with_index{|_, j| j == i }\r\n max = other.max\r\n\r\n if n > max\r\n r << 0\r\n else\r\n r << max - n + 1\r\n end\r\n end\r\n\r\n puts r.join(' ')\r\nend"}, {"source_code": "t = gets().to_i()\n\ndef bar(arr)\n\n\tsolve = []\n\n\n\tmax = arr.max\n\tmax_counter = 0\n\n\tfor i in 0..arr.length - 1\n\t\tif (arr[i] == max)\n\t\t\tmax_counter += 1\n\t\tend\n\tend\n\n\tfor i in 0..arr.length - 1\n\t\ttmp = -1\n\t\tif (arr[i] == max)\n\t\t\tif (max_counter == 1)\n\t\t\t\ttmp = 0\n\t\t\telse\n\t\t\t\ttmp = 1\n\t\t\tend\n\t\telse\n\t\t\ttmp = max - arr[i] + 1\n\t\tend\t\n\n\t\tsolve << tmp\n\tend\n\tputs solve.join(\" \")\nend\n\n\nfor i in 1..t\n\tarr = gets.chomp.split(\" \").map{|item| item.to_i}\n\t\n\tbar(arr)\n\nend"}, {"source_code": "gets.to_i.times do\r\n votes = gets.split.map(&:to_i)\r\n m = votes.max\r\n c = votes.count(m)\r\n puts votes.map{|v| v != m ? m - v + 1 : c > 1 ? 1 : 0}.join ' '\r\nend"}, {"source_code": "n = gets.chomp.to_i\r\n\r\nn.times do\r\n votes = gets.chomp.split(' ').map(&:to_i)\r\n\r\n a = [[votes[1], votes[2]].max - votes[0] + 1, 0].max\r\n b = [[votes[0], votes[2]].max - votes[1] + 1, 0].max\r\n c = [[votes[0], votes[1]].max - votes[2] + 1, 0].max\r\n\r\n puts \"#{a} #{b} #{c}\"\r\nend"}, {"source_code": "def f(x, y, z)\r\n w = [y, z].max - x + 1\r\n w > 0 ? w : 0\r\nend\r\n\r\ngets.to_i.times do\r\n\r\na, b, c = gets.split.map!(&:to_i)\r\nputs \"#{f(a,b,c)} #{f(b,c,a)} #{f(c,a,b)}\"\r\n \r\nend\r\n"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\nt.times {\n\ta, b, c = gets.split.map(&:to_i)\n\tif (a == b) && (c == a)\n\t\tputs \"#{a+1} #{b+1} #{c+1}\"\n\t\tnext\n\tend\n\taa = [a, [b, c].max + 1].max - a \n\tbb = [b, [a, c].max + 1].max - b\n\tcc = [c, [a, b].max + 1].max - c\n\tputs \"#{aa} #{bb} #{cc}\"\n}"}, {"source_code": "t = gets.chomp.to_i\nt.times {\n\ta, b, c = gets.split.map(&:to_i)\n\tif (a == b) && (c == b) && (c == a)\n\t\tputs \"#{a+1} #{b+1} #{c+1}\"\n\t\tnext\n\tend\n\tma = [a, b, c].max\n\tif ma - a == 0\n\t\ta = 0\n\telse \n\t\ta = ma - a + 1\n\tend\n\tif ma - b == 0\n\t\tb = 0\n\telse \n\t\tb = ma - b + 1\n\tend\n\tif ma - c == 0\n\t\tc = 0\n\telse \n\t\tc = ma - c + 1\n\tend\n\tputs \"#{a} #{b} #{c}\"\n\t# p [a, b, c].join' '\n}"}, {"source_code": "t = gets.chomp.to_i\nt.times {\n\ta, b, c = gets.split.map(&:to_i)\n\tif (a == b) && (c == b) && (c == a)\n\t\tputs \"#{a+1} #{b+1} #{c+1}\"\n\t\tnext\n\tend\n\tma = [a, b, c].max\n\tif ma - a == 0\n\t\ta = 0\n\telse \n\t\ta = ma - a + 1\n\tend\n\tif ma - b == 0\n\t\tb = 0\n\telse \n\t\tb = ma - b + 1\n\tend\n\tif ma - c == 0\n\t\tc = 0\n\telse \n\t\tc = ma - c + 1\n\tend\n\t# puts \"#{a} #{b} #{c}\"\n\tp [a, b, c].join' '\n}"}, {"source_code": "t = gets.chomp.to_i\nt.times {\n\ta, b, c = gets.split.map(&:to_i)\n\tif (a == b) && (c == b) && (c == a)\n\t\tputs a+1, a+1, a+1\n\t\tnext\n\tend\n\tma = [a, b, c].max\n\tif ma - a == 0\n\t\ta = 0\n\telse \n\t\ta = ma - a + 1\n\tend\n\tif ma - b == 0\n\t\tb = 0\n\telse \n\t\tb = ma - b + 1\n\tend\n\tif ma - c == 0\n\t\tc = 0\n\telse \n\t\tc = ma - c + 1\n\tend\n\tputs \"#{a} #{b} #{c}\"\n}"}, {"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |inp|\r\n cans = inp.split(' ').map(&:to_i)\r\n\r\n r = []\r\n max = cans.max\r\n min = cans.min\r\n cans.each do |n|\r\n r << max - n + (max != n || max == min ? 1 : 0)\r\n end\r\n\r\n puts r.join(' ')\r\nend"}, {"source_code": "t = gets().to_i()\n\ndef bar(arr)\n\n\tmax = arr.max\n\n\t\n\tsolve = []\n\n\n\tfor i in 0..arr.length - 1\n\t\ttmp = -1\n\t\tif (arr[i] == max)\n\t\t\ttmp = 0\n\t\telse\n\t\t\ttmp = max - arr[i] + 1\n\t\tend\t\n\n\t\tsolve << tmp\n\tend\n\tputs solve.join(\" \")\nend\n\n\nfor i in 1..t\n\tarr = gets.chomp.split(\" \").map{|item| item.to_i}\n\t\n\tbar(arr)\n\nend"}], "src_uid": "f80dea1e07dba355bfbefa4ff65ff45a"} {"source_code": "def c(n, m)\n c = 1\n m.times do |i|\n c = c * (n - i) / (i + 1)\n end\n c\nend\n\n# c(n, 3) - c(n - 1, 3) = c(n - 1, 2) !!\n# c(n, 2) - c(n - 1, 2) = c(n - 1, 1) = n - 1 !!\n\nm = gets.to_i\nk = 3\nk += 1 while c(k + 1, 3) <= m\nm -= c(k, 3)\n\na = []\nwhile m > 0\n b = 2\n b += 1 while c(b + 1, 2) <= m\n m -= c(b, 2)\n a << b\nend\n\nn = k + a.size\ne = Array.new(n){'0' * n}\nk.times do |i|\n k.times do |j|\n e[i][j] = '1' if i != j\n end\nend\na.each_with_index do |c, j|\n c.times do |i|\n e[i][k + j] = '1'\n e[k + j][i] = '1'\n end\nend\np n\nputs e * \"\\n\"\n", "positive_code": [{"source_code": "n=gets.to_i\na=Array.new(101){|el| el=Array.new(101){|elem| elem=0}}\nc,y=0,0\nfor i in 0..101 do\ny=0\n\twhile yn\n\t\ta[i][y],a[y][i]=1,1\n\t\tn-=y\n\t\ty+=1\n\tend\nc+=1\nbreak if n==0\nend\nputs c\nfor i in 0..c-1 do\n\tfor j in 0..c-1 do\n\t\tprint \"#{a[i][j]}\"\n\tend\n\tprintf(\"\\n\")\nend\n\n"}, {"source_code": "x = gets.to_i\nd = Array.new(105) { Array.new(105) {0} }\ncnt = Math.log((x * 2 * 3), 3).floor\nwhile (cnt + 1) * (cnt + 2) * (cnt + 3) <= x * 6\n cnt += 1 \nend\nwhile (cnt) * (cnt + 1) * (cnt + 2) > x * 6\n cnt -= 1\nend\ncnt += 2\n0.upto(cnt - 2) do |i|\n (i + 1).upto(cnt - 1) do |j|\n d[i][j] = d[j][i] = 1\n end\nend\np = cnt - 1\nx -= cnt * (cnt - 1) * (cnt - 2) / 6\nwhile x > 0 \n while p * (p - 1) / 2 > x\n p -= 1\n end\n 0.upto(p - 1) do |i|\n d[cnt][i] = d[i][cnt] = 1\n end\n cnt += 1\n x -= p * (p - 1) / 2\nend\nputs cnt\n0.upto(cnt - 1) do |i|\n 0.upto(cnt - 1) do |j|\n print \"#{d[i][j]}\"\n end\n puts ''\nend"}], "negative_code": [{"source_code": "def c(n, m)\n c = 1\n m.times do |i|\n c = c * (n - i) / (i + 1)\n end\n c\nend\n\n# c(n, 3) - c(n - 1, 3) = c(n - 1, 2) !!\n# c(n, 2) - c(n - 1, 2) = c(n - 1, 1) = n - 1 !!\n\nm = gets.to_i\nk = 3\nk += 1 while c(k + 1, 3) <= m\nm -= c(k, 3)\n\na = []\nwhile m > 0\n b = 2\n b += 1 while c(b + 1, 2) <= m\n m -= c(k, 2)\n a << b\nend\n\nn = k + a.size\ne = Array.new(n){'0' * n}\nk.times do |i|\n k.times do |j|\n e[i][j] = '1' if i != j\n end\nend\na.each_with_index do |c, j|\n c.times do |i|\n e[i][k + j] = '1'\n e[k + j][i] = '1'\n end\nend\np n\nputs e * \"\\n\"\n"}, {"source_code": "n=gets.to_i\na=Array.new(101){|el| el=Array.new(101){|elem| elem=0}}\nc,y=0,0\nfor i in 0..101 do\ny=0\n\twhile yn\n\t\ta[i][y],a[y][i]=1,1\n\t\tn-=y\n\t\ty+=1\n\tend\nc+=1\nbreak if n==0\nend\nputs c\nfor i in 0..c-1 do\n\tfor j in 0..c-1 do\n\t\tprint \"#{a[i][j]} \"\n\tend\n\tprintf(\"\\n\")\nend\n\n"}, {"source_code": "x = gets.to_i\nd = Array.new(105) { Array.new(105) {0} }\ncnt = Math.log((x * 2 * 3), 3).floor\nwhile (cnt + 1) * (cnt + 2) * (cnt + 3) <= x * 6\n cnt += 1 \nend\nwhile (cnt) * (cnt + 1) * (cnt + 2) > x * 6\n cnt -= 1\nend\ncnt += 2\n0.upto(cnt - 2) do |i|\n (i + 1).upto(cnt - 1) do |j|\n d[i][j] = d[j][i] = 1\n end\nend\nx -= cnt * (cnt - 1) * (cnt - 2) / 6\nwhile x > 0 \n p = (x >= cnt / 2) ? (cnt / 2) : x\n x -= p\n 0.upto(p - 1) do |i|\n d[2 * i][cnt] = d[2 * i + 1][cnt] = d[cnt][2 * i] = d[cnt][2 * i + 1] = 1\n end\n cnt += 1\nend\nputs cnt\n0.upto(cnt - 1) do |i|\n 0.upto(cnt - 1) do |j|\n print \"#{d[i][j]}\"\n end\n puts ''\nend"}], "src_uid": "d3f4c7fedd6148c28d8780142b6594f4"} {"source_code": "n = gets.to_i\npa,pb = 0,0\nans = 1\nn.times do\n a,b = gets.split.map(&:to_i)\n if a == b\n ans += a-[pa,pb].max+(pa==pb ? 0 : 1)\n elsif a > b && pa <= b\n ans += b-[pa,pb].max+(pa==pb ? 0 : 1)\n elsif a < b && pb <= a\n ans += a-[pa,pb].max+(pa==pb ? 0 : 1)\n end\n pa,pb = a,b\nend\np ans\n\n", "positive_code": [{"source_code": "DBG = !true\nn = gets.to_i\nsum = 0\npends = -1\npende = -1\nfor i in 0...n\n a,b = gets.split.map{|z| z.to_i}\n mn = [a,b].min\n mx = [a,b].max\n if pende != -1 && mn >= pends\n sum += [mn, pende].min - pends + 1\n end\n if mx <= mn + 1\n pende = -1\n pends = -1\n else\n pends = mn + 1\n pende = mx - 1\n end\n puts \"a #{a} b #{b} sum #{sum} pends #{pende}\" if DBG\nend\nputs \"#{[a,b].min - sum + 1}\"\n"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nn = gets.to_i\narr = []\nn.times do\n\tarr.push gets.chomp.split(\" \").map(&:to_i)\nend\n\nprevx = 0\nprevy = 0\n\ndef inrange(a,b,x)\n\treturn true if x>=a and x<=b\nend\n\n\n\nans = 0\n\nmaxtie = -1\n\narr.each do |z|\n\tx = z[0]\n\ty = z[1]\n\n\n#\tif(prevx==x && prevy==y)\n#\t\tnext\n#\tend\n\n\n\tif(y b && pa <= b\n ans += b-[pa,pb].max+(pa==pb ? 0 : 1)\n elsif a < b && pb <= a\n ans += a-[pa,pb].max+(pa==pb ? 0 : 1)\n end\n pa,pb = a,b\n p ans\nend\np ans"}, {"source_code": "DBG = true\nn = gets.to_i\nsum = 0\nprev = -1\nfor i in 0...n\n a,b = gets.split.map{|z| z.to_i}\n d = [[a,b].min, prev].max\n sum += [0, [a,b].max - d - 1].max\n prev = (a==b ? a : ([a,b].max - 1))\nend\nputs \"#{[a,b].min + 1 - sum}\"\n"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nn = gets.to_i\narr = []\nn.times do\n\tarr.push gets.chomp.split(\" \").map(&:to_i)\nend\n\nprevx = 0\nprevy = 0\nstart=1\n\ndef inrange(a,b,x)\n\treturn true if x>=a and x<=b\nend\n\nans = 0\narr.each do |z|\n\tx = z[0]\n\ty = z[1]\n\t\n\tif(prevx==x && prevy==y)\n\t\tnext\n\tend\n\tstart=0\n\n\tif(y=a and x<=b\nend\n\nans = 1\narr.each do |z|\n\tx = z[0]\n\ty = z[1]\n\t\n\tif(prevx==x && prevy==y)\n\t\tnext\n\tend\n\n\n\tif(y=a and x<=b\nend\n\n\n\nans = 0\n\nmaxtie = -1\n\narr.each do |z|\n\tx = z[0]\n\ty = z[1]\n\n\n\tif(prevx==x && prevy==y)\n\t\tnext\n\tend\n\n\n\tif(y=a and x<=b\nend\n\n\n\nans = 0\n\nmaxtie = -1\n\narr.each do |z|\n\tx = z[0]\n\ty = z[1]\n\n\n#\tif(prevx==x && prevy==y)\n#\t\tnext\n#\tend\n\n\n\tif(yx} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2 0\n (1...(n - 1)).each do |i|\n (1...(n - 1)).each do |j|\n counter += 1 if board[i][j] == 'X' \\\n && board[i][j] == board[i - 1][j - 1] \\\n && board[i][j] == board[i - 1][j + 1] \\\n && board[i][j] == board[i + 1][j - 1] \\\n && board[i][j] == board[i + 1][j + 1]\n end\n end\nend\nputs counter"}, {"source_code": "n = gets.to_i\ns=[]\nn.times{s< 0 do\r\n str1 = gets\r\n if str1[0] == 'l' and str1[1] == 'o' then\r\n is_locked = true\r\n else\r\n if str1[0] == 'u' and str1[1] == 'n' then\r\n is_locked = false\r\n else\r\n if is_locked == false then\r\n ans = str1\r\n end\r\n end\r\n end\r\n n = n - 1\r\nend\r\nprint ans"}], "negative_code": [], "src_uid": "6215233349b0f682a238a476e9153ac4"} {"source_code": "p = [[], [], []]\np[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1] = STDIN.read.split.map(&:to_i)\np.sort!\nh = {p[0] => true}\n\nx, y = p[0][0], p[0][1]\ntx, ty = p[1][0], p[1][1]\nwhile x < tx\n x += 1\n h[[x, y]] = true\nend\nwhile y != ty\n y += (y < ty ? 1 : -1)\n h[[x, y]] = true\nend\n\nif p[1][0] == p[2][0] || p[1][1] <= p[2][1]\n x, y = p[1][0], p[1][1]\n tx, ty = p[2][0], p[2][1]\n while y != ty\n y += (y < ty ? 1 : -1)\n h[[x, y]] = true\n end \n while x < tx\n x += 1\n h[[x, y]] = true\n end \nelsif p[0][1] <= p[2][1]\n x, y = p[0][0], p[0][1]\n while x < p[1][0]\n x += 1\n h[[x, y]] = true\n end\n while y < p[2][1]\n y += 1\n h[[x, y]] = true\n end\n while x < p[2][0]\n x += 1\n h[[x, y]] = true\n end\nelse\n if p[0][1] <= p[1][1]\n x, y = p[0][0], p[0][1]\n tx, ty = p[2][0], p[2][1]\n while x < tx\n x += 1\n h[[x, y]] = true\n end\n while y != ty\n y += (y < ty ? 1 : -1)\n h[[x, y]] = true\n end\n else\n x, y = p[1][0], p[1][1]\n tx, ty = p[2][0], p[2][1]\n while x < tx\n x += 1\n h[[x, y]] = true\n end\n while y != ty\n y += (y < ty ? 1 : -1)\n h[[x, y]] = true\n end\n end\nend\n\nputs h.size\nh.keys.each{|x| puts(x[0].to_s + ' ' + x[1].to_s)}\n", "positive_code": [{"source_code": "a = gets.chomp.split(\" \").map(&:to_i)\nb = gets.chomp.split(\" \").map(&:to_i)\nc = gets.chomp.split(\" \").map(&:to_i)\n\nxa = a[0]\nya = a[1]\nxb = b[0]\nyb = b[1]\nxc = c[0]\nyc = c[1]\n\nans = (xa-xb).abs + (ya-yb).abs + 1\n\nrectop = [xa,xb].max\nrecbot = [xa,xb].min\nrecright = [ya,yb].max\nrecleft = [ya,yb].min\n\nuserecver = 0\n\nif xc< recbot\n userecver = -1\n ans += recbot-xc\nelsif xc > rectop\n userecver = 1\n ans += xc-rectop\nend\n\nuserecside = 0\nif yc< recleft\n userecside = -1\n ans += recleft-yc\nelsif yc > recright\n userecside = 1\n ans += yc-recright\nend\n\n#ans += 1\nputs ans\n\n#puts userecver\n#puts userecside\n\nif userecver == -1\n #you definitely need the bottom\n (recleft..recright).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n if xa == recbot\n (recbot+1..xb).each do |k|\n puts \"#{k} #{yb}\"\n end\n else\n (recbot+1..xa).each do |k|\n puts \"#{k} #{ya}\"\n end\n end\n\n #DO THE C STUFF\n if userecside == -1\n (xc..recbot-1).each do |k|\n puts \"#{k} #{yc}\"\n end\n (yc+1..recleft-1).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n elsif userecside == 1\n (xc..recbot-1).each do |k|\n puts \"#{k} #{yc}\"\n end\n (recright+1..yc).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n else\n (xc..recbot-1).each do |k|\n puts \"#{k} #{yc}\"\n end\n end\n\nelsif userecver == 1\n\n #you definitely need the top\n (recleft..recright).each do |k|\n puts \"#{rectop} #{k}\"\n end\n\n if xa == rectop\n (xb..rectop-1).each do |k|\n puts \"#{k} #{yb}\"\n end\n else\n (xa..rectop-1).each do |k|\n puts \"#{k} #{ya}\"\n end\n end\n\n #DO the C stuff\n if userecside == -1\n (rectop+1..xc).each do |k|\n puts \"#{k} #{recleft}\"\n end\n (yc..recleft-1).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n elsif userecside == 1\n (rectop+1..xc).each do |k|\n puts \"#{k} #{recright}\"\n end\n (recright+1..yc).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n else\n (rectop+1..xc).each do |k|\n puts \"#{k} #{yc}\"\n end\n end\n\nelse\n #You don't need the top or bottom, you may need the left or right\n\n if userecside == -1\n #You need the left\n (recbot..rectop).each do |k|\n puts \"#{k} #{recleft}\"\n end\n\n if ya == recleft\n (recleft+1..yb).each do |k|\n puts \"#{xb} #{k}\"\n end\n else\n (recleft+1..ya).each do |k|\n puts \"#{xa} #{k}\"\n end\n end\n\n (yc..recleft-1).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n elsif userecside == 1\n #You need the right\n (recbot..rectop).each do |k|\n puts \"#{k} #{recright}\"\n end\n\n if ya == recright\n (yb..recright-1).each do |k|\n puts \"#{xb} #{k}\"\n end\n else\n (ya..recright-1).each do |k|\n puts \"#{xa} #{k}\"\n end\n end\n\n (recright+1..yc).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n else\n #0,0 -> do a,c, c,b\n\n acxmin = [xa,xc].min\n acxmax = [xa,xc].max\n\n acymin = [ya,yc].min\n acymax = [ya,yc].max\n\n bcxmin = [xb,xc].min\n bcxmax = [xb,xc].max\n\n bcymin = [yb,yc].min\n bcymax = [yb,yc].max\n \n\n if xa rectop\n userecver = 1\n ans += xc-rectop\nend\n\nuserecside = 0\nif yc< recleft\n userecside = -1\n ans += recleft-yc\nelsif yc > recright\n userecside = 1\n ans += yc-recright\nend\n\n#ans += 1\nputs ans\n\n#puts userecver\n#puts userecside\n\nif userecver == -1\n #you definitely need the bottom\n (recleft..recright).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n if xa == recbot\n (recbot+1..xb).each do |k|\n puts \"#{k} #{yb}\"\n end\n else\n (recbot+1..xa).each do |k|\n puts \"#{k} #{ya}\"\n end\n end\n\n #DO THE C STUFF\n if userecside == -1\n (xc..recbot).each do |k|\n puts \"#{k} #{yc}\"\n end\n (yc+1..recleft-1).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n elsif userecside == 1\n (xc..recbot).each do |k|\n puts \"#{k} #{yc}\"\n end\n (recright+1..yc).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n else\n (xc..recbot-1).each do |k|\n puts \"#{k} #{yc}\"\n end\n end\n\nelsif userecver == 1\n\n #you definitely need the top\n (ya..yb).each do |k|\n puts \"#{rectop} #{k}\"\n end\n\n if xa == rectop\n (xb..rectop-1).each do |k|\n puts \"#{k} #{yb}\"\n end\n else\n (xa..rectop-1).each do |k|\n puts \"#{k} #{ya}\"\n end\n end\n\n #DO the C stuff\n if userecside == -1\n (rectop+1..xc).each do |k|\n puts \"#{k} #{recleft}\"\n end\n (yc..recleft-1).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n elsif userecside == 1\n (rectop+1..xc).each do |k|\n puts \"#{k} #{recright}\"\n end\n (recright+1..yc).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n else\n (rectop+1..xc).each do |k|\n puts \"#{k} #{yc}\"\n end\n end\n\nelse\n #You don't need the top or bottom, you may need the left or right\n\n if userecside == -1\n #You need the left\n (recbot..rectop).each do |k|\n puts \"#{k} #{recleft}\"\n end\n\n if ya == recleft\n (recleft+1..yb).each do |k|\n puts \"#{xb} #{k}\"\n end\n else\n (recleft+1..ya).each do |k|\n puts \"#{xa} #{k}\"\n end\n end\n\n (yc..recleft-1).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n elsif userecside == 1\n #You need the right\n (recbot..rectop).each do |k|\n puts \"#{k} #{recright}\"\n end\n\n if ya == recright\n (yb..recright-1).each do |k|\n puts \"#{xb} #{k}\"\n end\n else\n (ya..recright-1).each do |k|\n puts \"#{xa} #{k}\"\n end\n end\n\n (recright+1..yc).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n else\n #0,0 -> do a,c, c,b\n\n acxmin = [xa,xc].min\n acxmax = [xa,xc].max\n\n acymin = [ya,yc].min\n acymax = [ya,yc].max\n\n bcxmin = [xb,xc].min\n bcxmax = [xb,xc].max\n\n bcymin = [yb,yc].min\n bcymax = [yb,yc].max\n \n\n if xa rectop\n userecver = 1\n ans += xc-rectop\nend\n\nuserecside = 0\nif yc< recleft\n userecside = -1\n ans += recleft-yc\nelsif yc > recright\n userecside = 1\n ans += yc-recright\nend\n\n#ans += 1\nputs ans\n\n#puts userecver\n#puts userecside\n\nif userecver == -1\n #you definitely need the bottom\n (recleft..recright).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n if xa == recbot\n (recbot+1..xb).each do |k|\n puts \"#{k} #{yb}\"\n end\n else\n (recbot+1..xa).each do |k|\n puts \"#{k} #{ya}\"\n end\n end\n\n #DO THE C STUFF\n if userecside == -1\n (xc..recbot).each do |k|\n puts \"#{k} #{yc}\"\n end\n (yc+1..recleft-1).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n elsif userecside == 1\n (xc..recbot).each do |k|\n puts \"#{k} #{yc}\"\n end\n (recright+1..yc).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n else\n (xc..recbot-1).each do |k|\n puts \"#{k} #{yc}\"\n end\n end\n\nelsif userecver == 1\n\n #you definitely need the top\n (ya..yb).each do |k|\n puts \"#{rectop} #{k}\"\n end\n\n if xa == rectop\n (xb..rectop-1).each do |k|\n puts \"#{k} #{yb}\"\n end\n else\n (xa..rectop-1).each do |k|\n puts \"#{k} #{ya}\"\n end\n end\n\n #DO the C stuff\n if userecside == -1\n (rectop+1..xc).each do |k|\n puts \"#{k} #{recleft}\"\n end\n (yc..recleft-1).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n elsif userecside == 1\n (rectop+1..xc).each do |k|\n puts \"#{k} #{recright}\"\n end\n (recright+1..yc).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n else\n (rectop+1..xc).each do |k|\n puts \"#{k} #{yc}\"\n end\n end\n\nelse\n #You don't need the top or bottom, you may need the left or right\n\n if userecside == -1\n #You need the left\n (recbot..rectop).each do |k|\n puts \"#{k} #{recleft}\"\n end\n\n if ya == recleft\n (recleft+1..yb).each do |k|\n puts \"#{xb} #{k}\"\n end\n else\n (recleft+1..ya).each do |k|\n puts \"#{xa} #{k}\"\n end\n end\n\n (yc..recleft-1).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n elsif userecside == 1\n #You need the right\n (recbot..rectop).each do |k|\n puts \"#{k} #{recright}\"\n end\n\n if ya == recright\n (yb..recright-1).each do |k|\n puts \"#{xb} #{k}\"\n end\n else\n (ya..recright-1).each do |k|\n puts \"#{xa} #{k}\"\n end\n end\n\n (recright+1..yc).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n else\n #0,0 -> do a,c, c,b\n\n acxmin = [xa,xc].min\n acxmax = [xa,xc].max\n\n acymin = [ya,yc].min\n acymax = [ya,yc].max\n\n bcxmin = [xb,xc].min\n bcxmax = [xb,xc].max\n\n bcymin = [yb,yc].min\n bcymax = [yb,yc].max\n \n\n (acxmin..acxmax-1).each do |k|\n puts \"#{k} #{ya}\"\n end\n \n (acymin..acymax).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n (bcxmin+1..bcxmax-1).each do |k|\n puts \"#{k} #{yc}\"\n end\n \n (bcymin+1..bcymax).each do |k|\n puts \"#{xb} #{k}\"\n end\n\n end\nend"}, {"source_code": "a = gets.chomp.split(\" \").map(&:to_i)\nb = gets.chomp.split(\" \").map(&:to_i)\nc = gets.chomp.split(\" \").map(&:to_i)\n\nxa = a[0]\nya = a[1]\nxb = b[0]\nyb = b[1]\nxc = c[0]\nyc = c[1]\n\nans = (xa-xb).abs + (ya-yb).abs + 1\n\nrectop = [xa,xb].max\nrecbot = [xa,xb].min\nrecright = [ya,yb].max\nrecleft = [ya,yb].min\n\nuserecver = 0\n\nif xc< recbot\n userecver = -1\n ans += recbot-xc\nelsif xc > rectop\n userecver = 1\n ans += xc-rectop\nend\n\nuserecside = 0\nif yc< recleft\n userecside = -1\n ans += recleft-yc\nelsif yc > recright\n userecside = 1\n ans += yc-recright\nend\n\n#ans += 1\nputs ans\n\n#puts userecver\n#puts userecside\n\nif userecver == -1\n #you definitely need the bottom\n (recleft..recright).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n if xa == recbot\n (recbot+1..xb).each do |k|\n puts \"#{k} #{yb}\"\n end\n else\n (recbot+1..xa).each do |k|\n puts \"#{k} #{ya}\"\n end\n end\n\n #DO THE C STUFF\n if userecside == -1\n (xc..recbot).each do |k|\n puts \"#{k} #{yc}\"\n end\n (yc+1..recleft-1).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n elsif userecside == 1\n (xc..recbot).each do |k|\n puts \"#{k} #{yc}\"\n end\n (recright+1..yc).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n else\n (xc..recbot-1).each do |k|\n puts \"#{k} #{yc}\"\n end\n end\n\nelsif userecver == 1\n\n #you definitely need the top\n (ya..yb).each do |k|\n puts \"#{rectop} #{k}\"\n end\n\n if xa == rectop\n (xb..rectop-1).each do |k|\n puts \"#{k} #{yb}\"\n end\n else\n (xa..rectop-1).each do |k|\n puts \"#{k} #{ya}\"\n end\n end\n\n #DO the C stuff\n if userecside == -1\n (rectop+1..xc).each do |k|\n puts \"#{k} #{recleft}\"\n end\n (yc..recleft-1).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n elsif userecside == 1\n (rectop+1..xc).each do |k|\n puts \"#{k} #{recright}\"\n end\n (recright+1..yc).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n else\n (rectop+1..xc).each do |k|\n puts \"#{k} #{yc}\"\n end\n end\n\nelse\n #You don't need the top or bottom, you may need the left or right\n\n if userecside == -1\n #You need the left\n (recbot..rectop).each do |k|\n puts \"#{k} #{recleft}\"\n end\n\n if ya == recleft\n (recleft+1..yb).each do |k|\n puts \"#{xb} #{k}\"\n end\n else\n (recleft+1..ya).each do |k|\n puts \"#{xa} #{k}\"\n end\n end\n\n (yc..recleft-1).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n elsif userecside == 1\n #You need the right\n (recbot..rectop).each do |k|\n puts \"#{k} #{recright}\"\n end\n\n if ya == recright\n (yb..recright-1).each do |k|\n puts \"#{xb} #{k}\"\n end\n else\n (ya..recright-1).each do |k|\n puts \"#{xa} #{k}\"\n end\n end\n\n (recright+1..yc).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n else\n #0,0 -> do a,c, c,b\n\n acxmin = [xa,xc].min\n acxmax = [xa,xc].max\n\n acymin = [ya,yc].min\n acymax = [ya,yc].max\n\n bcxmin = [xb,xc].min\n bcxmax = [xb,xc].max\n\n bcymin = [yb,yc].min\n bcymax = [yb,yc].max\n \n\n (acxmin..acxmax-1).each do |k|\n puts \"#{k} #{ya}\"\n end\n \n (acymin..acymax).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n (bcxmin+1..bcxmax-1).each do |k|\n puts \"#{k} #{yc}\"\n end\n \n (bcymin..bcymax).each do |k|\n puts \"#{xb} #{k}\"\n end\n\n end\nend\n"}, {"source_code": "a = gets.chomp.split(\" \").map(&:to_i)\nb = gets.chomp.split(\" \").map(&:to_i)\nc = gets.chomp.split(\" \").map(&:to_i)\n\nxa = a[0]\nya = a[1]\nxb = b[0]\nyb = b[1]\nxc = c[0]\nyc = c[1]\n\nans = (xa-xb).abs + (ya-yb).abs + 1\n\nrectop = [xa,xb].max\nrecbot = [xa,xb].min\nrecright = [ya,yb].max\nrecleft = [ya,yb].min\n\nuserecver = 0\n\nif xc< recbot\n userecver = -1\n ans += recbot-xc\nelsif xc > rectop\n userecver = 1\n ans += xc-rectop\nend\n\nuserecside = 0\nif yc< recleft\n userecside = -1\n ans += recleft-yc\nelsif yc > recright\n userecside = 1\n ans += yc-recright\nend\n\n#ans += 1\nputs ans\n\n#puts userecver\n#puts userecside\n\nif userecver == -1\n #you definitely need the bottom\n (recleft..recright).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n if xa == recbot\n (recbot+1..xb).each do |k|\n puts \"#{k} #{yb}\"\n end\n else\n (recbot+1..xa).each do |k|\n puts \"#{k} #{ya}\"\n end\n end\n\n #DO THE C STUFF\n if userecside == -1\n (xc..recbot).each do |k|\n puts \"#{k} #{yc}\"\n end\n (yc+1..recleft-1).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n elsif userecside == 1\n (xc..recbot).each do |k|\n puts \"#{k} #{yc}\"\n end\n (recright+1..yc).each do |k|\n puts \"#{recbot} #{k}\"\n end\n\n else\n (xc..recbot-1).each do |k|\n puts \"#{k} #{yc}\"\n end\n end\n\nelsif userecver == 1\n\n #you definitely need the top\n (recleft..recright).each do |k|\n puts \"#{rectop} #{k}\"\n end\n\n if xa == rectop\n (xb..rectop-1).each do |k|\n puts \"#{k} #{yb}\"\n end\n else\n (xa..rectop-1).each do |k|\n puts \"#{k} #{ya}\"\n end\n end\n\n #DO the C stuff\n if userecside == -1\n (rectop+1..xc).each do |k|\n puts \"#{k} #{recleft}\"\n end\n (yc..recleft-1).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n elsif userecside == 1\n (rectop+1..xc).each do |k|\n puts \"#{k} #{recright}\"\n end\n (recright+1..yc).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n else\n (rectop+1..xc).each do |k|\n puts \"#{k} #{yc}\"\n end\n end\n\nelse\n #You don't need the top or bottom, you may need the left or right\n\n if userecside == -1\n #You need the left\n (recbot..rectop).each do |k|\n puts \"#{k} #{recleft}\"\n end\n\n if ya == recleft\n (recleft+1..yb).each do |k|\n puts \"#{xb} #{k}\"\n end\n else\n (recleft+1..ya).each do |k|\n puts \"#{xa} #{k}\"\n end\n end\n\n (yc..recleft-1).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n elsif userecside == 1\n #You need the right\n (recbot..rectop).each do |k|\n puts \"#{k} #{recright}\"\n end\n\n if ya == recright\n (yb..recright-1).each do |k|\n puts \"#{xb} #{k}\"\n end\n else\n (ya..recright-1).each do |k|\n puts \"#{xa} #{k}\"\n end\n end\n\n (recright+1..yc).each do |k|\n puts \"#{xc} #{k}\"\n end\n\n else\n #0,0 -> do a,c, c,b\n\n acxmin = [xa,xc].min\n acxmax = [xa,xc].max\n\n acymin = [ya,yc].min\n acymax = [ya,yc].max\n\n bcxmin = [xb,xc].min\n bcxmax = [xb,xc].max\n\n bcymin = [yb,yc].min\n bcymax = [yb,yc].max\n \n\n if xa a[i]\n a[0] += k\n d -= k * i\n end\n puts a[0]\nend\n"}], "negative_code": [], "src_uid": "7bbb4b9f5eccfe13741445c815a4b1ca"} {"source_code": "s = gets.chomp!\nmods = 1000000007\ndp = [[0,0,0],[0,0,0]]\n\nlen =s.size\ncur =0;nxt=1;\n\ncase s[0]\nwhen '0'\n\tdp[cur][0]=1\nwhen '1'\n\tdp[cur][1]=1\nwhen '2'\n\tp 0\n\texit\nwhen '*'\n\tdp[cur][2]=1\nwhen '?'\n\tdp[cur][0]=dp[cur][1]=dp[cur][2]=1\nend\n\nfor i in 1...len\n\tcase s[i]\n\twhen '0'\n\t\tdp[nxt][0]=dp[cur][0]\n\twhen '1'\n\t\tdp[nxt][1]= dp[cur][0]\n\t\tdp[nxt][0]= dp[cur][2]\n\twhen '2'\n\t\tdp[nxt][1]=dp[cur][2]\n\twhen '*'\n\t\tdp[nxt][2]= (dp[cur][1]+dp[cur][2])%mods\n\twhen '?'\n\t\tdp[nxt][1]= (dp[cur][2]+dp[cur][0])%mods\n\t\tdp[nxt][0]= (dp[cur][0]+dp[cur][2])%mods\n\t\tdp[nxt][2]= (dp[cur][1]+dp[cur][2])%mods\n\tend\n\tcur = nxt\n\tnxt = cur==0?1:0\n\tdp[nxt] = [0,0,0]\nend\n\nputs \"#{(dp[cur][0]+dp[cur][2])%mods}\"", "positive_code": [{"source_code": "s = gets.chomp!\nmods = 1000000007\ndp = [[0,0,0],[0,0,0]]\n\nlen =s.size\ncur =0;nxt=1;\n\ndp[cur][0]=dp[cur][1]=1\n\nfor i in 0...len\n\tcase s[i]\n\twhen '0'\n\t\tdp[nxt][0]=dp[cur][0]\n\twhen '1'\n\t\tdp[nxt][1]= dp[cur][0]\n\t\tdp[nxt][0]= dp[cur][2]\n\twhen '2'\n\t\tdp[nxt][1]=dp[cur][2]\n\twhen '*'\n\t\tdp[nxt][2]= (dp[cur][1]+dp[cur][2])%mods\n\twhen '?'\n\t\tdp[nxt][1]= (dp[cur][2]+dp[cur][0])%mods\n\t\tdp[nxt][0]= (dp[cur][0]+dp[cur][2])%mods\n\t\tdp[nxt][2]= (dp[cur][1]+dp[cur][2])%mods\n\tend\n\tcur = nxt\n\tnxt = cur==0?1:0\n\tdp[nxt] = [0,0,0]\nend\n\nputs \"#{(dp[cur][0]+dp[cur][2])%mods}\""}, {"source_code": "s = gets.chomp!\nmods = 1000000007\ndp = [[0,0,0],[0,0,0]]\n\nlen =s.size\ncur =0;nxt=1;\n\ncase s[0]\nwhen '0'\n\tdp[cur][0]=1\nwhen '1'\n\tdp[cur][1]=1\nwhen '2'\n\tp 0\n\texit\nwhen '*'\n\tdp[cur][2]=1\nwhen '?'\n\tdp[cur][0]=dp[cur][1]=dp[cur][2]=1\nend\n\nfor i in 1...len\n\tcase s[i]\n\twhen '0'\n\t\tdp[nxt][0]=dp[cur][0]\n\twhen '1'\n\t\tdp[nxt][1]= dp[cur][0]\n\t\tdp[nxt][0]= dp[cur][2]\n\twhen '2'\n\t\tdp[nxt][1]=dp[cur][2]\n\twhen '*'\n\t\tdp[nxt][2]= (dp[cur][1]+dp[cur][2])%mods\n\twhen '?'\n\t\tdp[nxt][1]= (dp[cur][2]+dp[cur][0])%mods\n\t\tdp[nxt][0]= (dp[cur][0]+dp[cur][2])%mods\n\t\tdp[nxt][2]= (dp[cur][1]+dp[cur][2])%mods\n\tend\n\ta = cur \n\tcur = nxt\n\tnxt = a\n\tdp[nxt] = [0,0,0]\nend\n\nputs \"#{(dp[cur][0]+dp[cur][2])%mods}\""}, {"source_code": "s = gets.chomp!\nmods = 1000000007\ndp = [[0,0,0],[0,0,0]]\n\nlen =s.size\ncur =0;nxt=1;\n\ncase s[0]\nwhen '0'\n\tdp[cur][0]=1\nwhen '1'\n\tdp[cur][1]=1\nwhen '2'\n\tp 0\n\texit\nwhen '*'\n\tdp[cur][2]=1\nwhen '?'\n\tdp[cur][0]=dp[cur][1]=dp[cur][2]=1\nend\n\nfor i in 1...len\n\tcase s[i]\n\twhen '0'\n\t\tdp[nxt][0]=dp[cur][0]\n\twhen '1'\n\t\tdp[nxt][1]= dp[cur][0]\n\t\tdp[nxt][0]= dp[cur][2]\n\twhen '2'\n\t\tdp[nxt][1]=dp[cur][2]\n\twhen '*'\n\t\tdp[nxt][2]= (dp[cur][1]+dp[cur][2])%mods\n\twhen '?'\n\t\tdp[nxt][1]= (dp[cur][2]+dp[cur][0])%mods\n\t\tdp[nxt][0]= (dp[cur][0]+dp[cur][2])%mods\n\t\tdp[nxt][2]= (dp[cur][1]+dp[cur][2])%mods\n\tend\n\ta = cur \n\tcur = nxt\n\tnxt = a\n\tdp[nxt] = [0,0,0]\nend\n\np (dp[cur][0]+dp[cur][2])%mods"}], "negative_code": [], "src_uid": "c16c49baf7b2d179764871204475036e"} {"source_code": "n = gets.chomp\nprint n\nprint n.reverse", "positive_code": [{"source_code": "s = gets.strip\nd = s.reverse\nans = s+d\nputs ans"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\norder = gets.chomp\n\nputs \"#{order}#{order.reverse}\"\n"}, {"source_code": "pal = gets.strip\nans = \"\"\nans << pal << pal.reverse\nputs ans\n"}, {"source_code": "$><<t\n\tn-=t\n\ti+=1\n\tt=t*10+9\nend\ns='%0*d'%[i,n]\nputs s.reverse+s"}, {"source_code": "#!/usr/bin/ruby\ns=gets\nputs s+s.reverse"}, {"source_code": "a=gets.chomp.to_i\n(a*2).times do\nprint \"1\"\nend\n"}, {"source_code": "s=gets\nprint s\nprint s.reverse\nprint \"\\n\"\n\n"}, {"source_code": "s=gets\nprint s,s.reverse,\"\\n\"\n\n"}], "src_uid": "bcf75978c9ef6202293773cf533afadf"} {"source_code": "main = -> {\n N = int\n N.times do\n digits = gets.chomp.chars.map(&:to_i)\n first = digits[0, 3].sum\n last = digits[3, 3].sum\n puts first == last ? \"YES\" : \"NO\"\n end\n}\n\nDEBUG = true\nMOD = 10**9+7\n$yesno = %w(No Yes)\nYesNo = %w(No Yes)\nYESNO = %w(NO YES)\nINF = 10**18\n\nrequire \"set\"\nrequire \"prime\"\n\ndef int; gets.to_s.to_i end\ndef ints; gets.to_s.split.map { |s| s.to_i } end\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\ndef float; gets.to_s.to_f end\ndef floats; gets.to_s.split.map { |s| s.to_f } end\ndef array_of(&convert); gets.to_s.split.map(&convert) end\ndef string; gets.to_s.chomp end\ndef strings; gets.to_s.split end\ndef rep(n, &b); Array.new(n, &b) end\ndef yes; puts $yesno[1] end\ndef no; puts $yesno[0] end\ndef yesno t; puts $yesno[t] end\ndef YesNo t; puts YesNo[t] end\ndef YESNO t; puts YESNO[t] end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\ndef gcd(*xs); xs.inject(0, :gcd) end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\ndef if_debug; yield if DEBUG end\n\nmodule Boolean\n def coerce(other); [other, to_i] end\n def +@; to_i end\n def to_int; to_i end\n def *(other); to_i * other end\nend\n\nclass TrueClass\n include Boolean\n def to_i; 1 end\nend\n\nclass FalseClass\n include Boolean\n def to_i; 0 end\nend\n\nclass Integer\n def div_ceil(y); (self + y - 1) / y end\n def mod_inv(mod = MOD); pow(mod-2, mod) end\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\nend\n\nclass Array\n def power(&block); (0 ... 1 << size).each(&block) end\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\nend\n\nmodule Enumerable\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\nend\n\nmain[]", "positive_code": [{"source_code": " gets.to_i.times {\n \tv = gets.chars.map {|x| x.to_i }\n \tputs ({true=>\"YES\", false=>\"NO\"}[v[..2].sum==v[3..].sum])\n }"}, {"source_code": "gets.to_i.times do\r\n s = gets.chomp.chars.map(&:to_i)\r\n puts s[..2].sum == s[3..].sum ? \"YES\" : \"NO\"\r\nend\r\n"}, {"source_code": "gets.to_i.times do\n s = gets.strip.chars\n fail unless s.length == 6\n a = s[..2].map(&:to_i).sum\n b = s[3..].map(&:to_i).sum\n puts(if a == b then 'YES' else 'NO' end)\nend\n"}, {"source_code": "def main\n gets.to_i.times do\n x = gets.chomp.chars.map(&:to_i)\n puts uyesno(x[..2].sum == x[3..].sum)\n end\nend\n\nMOD = 10**9 + 7\ndef gs = gets.chomp\ndef gi = gets.to_i\ndef gli = gets.split.map(&:to_i)\ndef cyesno(x) = x ? :Yes : :No\ndef uyesno(x) = x ? :YES : :NO\n\nmain\n"}], "negative_code": [], "src_uid": "c7a5b4a015e28dd3759569bbdc130e93"} {"source_code": "l = gets.to_i\nn = gets.chomp\nc = l\nidx = 0\n(1...l).each do |i|\n if n[i] != \"0\"\n m = (l-i > i ? l-i : i)\n if c > m\n c = m\n idx = i\n end\n end\nend\nans = n[0,idx].to_i+n[idx..-1].to_i\ns = ans.to_s.size\n(1...l).each do |i|\n if n[i] != \"0\"\n next if s < (l-i > i ? l-i : i)\n ret = n[0,i].to_i+n[i..-1].to_i\n if ret < ans\n ans = ret\n s = ans.to_s.size\n end\n end\nend\nputs ans", "positive_code": [{"source_code": "n = gets.to_i\nl = gets.chomp\n\nans = l.to_i\n\ni = n/2\nj = i - 1\nwhile l[j+1] == '0' \n j -= 1\nend\nwhile l[i+1] == '0'\n i += 1\nend\n\na = l[0..i]\nb = l[(i+1)..n-1]\nans = [ans, l[0..i].to_i + l[(i+1)..n-1].to_i, l[0..j].to_i + l[(j+1)..n-1].to_i].min\n\nputs ans"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nans = []\nif n%2 == 0\n 3.times do |i|\n next if s[n/2-1+i] == \"0\"\n ans << s[0,n/2-1+i].to_i + s[n/2-1+i,n/2+1-i].to_i\n end\nelse\n 4.times do |i|\n k = n/2-1+i\n next if k <= 0 || k >= n || s[k] == \"0\"\n ans << s[0,k].to_i + s[k,n-k].to_i\n end\nend\nif ans.empty?\n l,r = n/2,n/2\n l -=1 while l >= 0 && s[l] == \"0\"\n r += 1 while r < n && s[r] == \"0\"\n ans << s[0,l].to_i + s[l,n-l].to_i if l > 0\n ans << s[0,r].to_i + s[r,n-r].to_i if r < n\n #p [l,r]\nend\n#p ans\nputs ans.min"}, {"source_code": "L = gets.to_i\nN = gets.chomp\n\nans = Float::INFINITY\n\npt = L/2\npt -= 1 while N[pt] == '0'\nif pt > 0\n res = N[0, pt].to_i + N[pt..-1].to_i\n ans = [ans, res].min\nend\npt = (L+1)/2\npt += 1 while pt < L && N[pt] == '0'\nif pt < L\n res = N[0, pt].to_i + N[pt..-1].to_i\n ans = [ans, res].min\nend\n\nputs ans"}], "negative_code": [{"source_code": "n = gets.to_i\nl = gets.chomp\n\nans = 10 ** 20\n\n(0..n-2).each do |i|\n if l[i+1] == '0' && i != n-2 \n next\n end\n ans = [ans, l[0..i].to_i + l[(i+1)..n-1].to_i].min\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\nl = gets.chomp\n\nans = 10 ** 20\n\n(0..n-2).each do |i|\n if l[i+1] == '0'\n next\n end\n ans = [ans, l[0..i].to_i + l[(i+1)..n-1].to_i].min\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\nl = gets.chomp\n\nans = 10 ** 20\n\n(0..n-2).each do |i|\n a = l[0..i]\n b = l[(i+1)..n-1]\n if b.size >= 2 && b[0] == '0'\n next\n end\n ans = [ans, a.to_i + b.to_i].min\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\nl = gets.chomp\n\nans = 10 ** 20\n\n(0..n-2).each do |i|\n a = l[0..i]\n b = l[(i+1)..n-1]\n if b[0] == '0'\n next\n end\n ans = [ans, a.to_i + b.to_i].min\nend\n\nputs ans"}, {"source_code": "l = gets.to_i\nn = gets.chomp\nc = l\nidx = 0\n(l-1).downto(1) do |i|\n if n[i] != \"0\"\n m = (l-i > i ? l-i : i)\n if c > m\n c = m\n idx = i\n end\n end\nend\nans = n[0,idx].to_i+n[idx..-1].to_i\n(1...l).each do |i|\n if n[i] != \"0\"\n break if ans.to_s.size < (l-i > i ? l-i : i)\n ret = n[0,i].to_i+n[i..-1].to_i\n if ret < ans\n ans = ret\n end\n end\nend\nputs ans"}], "src_uid": "08bce37778b7bfe478340d5c222ae362"} {"source_code": "a,b,c=gets.split.map(&:to_f)\nif a<0\na=-a\nb=-b\nc=-c\nend\np (-b+Math.sqrt(b*b-4*a*c))/2/a\np (-b-Math.sqrt(b*b-4*a*c))/2/a", "positive_code": [{"source_code": "a, b, c = gets.chomp.split\n\na = a.to_f\nb = b.to_f\nc = c.to_f\n\nd=(b**2-4*a*c)**(0.5)\nx=(-b+d)/(2*a)\ny=(-b-d)/(2*a)\n\nif y>x\nx, y= y, x\nend\n\nputs x\nprint y"}, {"source_code": "\n a,b,c=gets.split.map(&:to_f)\n(a=-a;b=-b;c=-c)if a<0\nputs [1,-1].map{|s|(-b+s*Math.sqrt(b*b-4*a*c))/2/a}"}, {"source_code": "a,b,c=gets.split.map(&:to_f)\n(a=-a;b=-b;c=-c)if a<0\nputs [1,-1].map{|s|(-b+s*Math.sqrt(b*b-4*a*c))/2/a}"}, {"source_code": "a, b, c=gets.split.map &:to_i\nd=(b*b-4*a*c)**0.5\nx, y=[(-b+d)/(2*a), (-b-d)/(2*a)].sort\np y\np x"}], "negative_code": [{"source_code": "a,b,c=gets.split.map(&:to_f)\np (-b+Math.sqrt(b*b-4*a*c))/2\np (-b-Math.sqrt(b*b-4*a*c))/2"}, {"source_code": "a,b,c=gets.split.map(&:to_f)\np (-b+Math.sqrt(b*b-4*a*c))/2/a\np (-b-Math.sqrt(b*b-4*a*c))/2/a"}, {"source_code": "a, b, c=gets.split.map &:to_i\nd=(b*b-4*a*c)**0.5\np (-b+d)/(2*a)\np (-b-d)/(2*a)"}], "src_uid": "2d4ad39d42b349765435b351897403da"} {"source_code": "n = gets.to_i\na = gets.split.map{|i|i.to_i%2}.count(0)\nputs [a,n-a].min", "positive_code": [{"source_code": "n = gets.to_i\nnums = gets.split.map(&:to_i)\neven = nums.select(&:even?).length\nv = [even, n - even]\nputs v.min\n"}, {"source_code": "nn = gets.to_i\nxx = gets.split.map(&:to_i)\n\nmin0=0\nmin1=0\n\n0.upto(nn-1) do |n|\n t = xx[n]\n min0+=1 if t%2==0\n min1+=1 if (t+1)%2==0\nend\n\nputs min00)\n\t\t\tnextdishind = costin[cheapestindex][1]\n\t\t\tleft = amount[nextdishind]\n\n\t\t\tif(left<1)\n\t\t\t\tcheapestindex+=1\n\t\t\t\tif cheapestindex==n\n\t\t\t\t\tbreak\n\t\t\t\tend\n\t\t\t\tnextdishind = costin[cheapestindex][1]\n\t\t\t\tleft = amount[nextdishind]\n\t\t\tend\n\n\t\t\tif(num<=left)\n\t\t\t\tamount[nextdishind]-=num\n\t\t\t\ttotalcost+=num*cost[nextdishind]\n\t\t\t\tnum=0\n\t\t\telse\n\t\t\t\ttotalcost+=left*cost[nextdishind]\n\t\t\t\tamount[nextdishind]=0\n\t\t\t\tnum-=left\n\t\t\tend\n\t\tend\n\tend\n\n#\tp amount\n\t\n\tif num>0\n\t\tputs 0\n\telse\n\t\tputs totalcost\n\tend\nend\n", "positive_code": [{"source_code": "DBG = !true\nn,m = gets.split.map{|z| z.to_i}\na = gets.split.map{|z| z.to_i}\nc = gets.split.map{|z| z.to_i}\ntd = []\nfor i in 0...m\n t,d = gets.split.map{|z| z.to_i}\n td << [t-1,d]\n #a,b = gets.split\n #a = a.to_i\n #b = b.to_i\nend\n\nif DBG\n puts \"n #{n} m #{m}\"\n print a\n puts \"\"\n print c\n puts \"\"\n print td\n puts \"\"\nend\n\nsortedc = []\nfor i in 0...n\n sortedc << [i,c[i]]\nend\nsortedc.sort_by!{|z| 200000*z[1]+z[0]}\nprint sortedc if DBG\ncheapest = 0\n\n#totalcost = 0\nfor j in 0...m\n if cheapest == n\n puts \"0\"\n next\n end\n cost = 0\n t = td[j][0]\n d = td[j][1]\n if a[t] > 0\n amt = [d, a[t]].min\n d -= amt\n a[t] -= amt\n cost += c[t] * amt\n end\n while d > 0\n while cheapest < n && a[sortedc[cheapest][0]] == 0\n cheapest += 1\n end\n if cheapest == n\n cost = 0\n break\n end\n t = sortedc[cheapest][0]\n amt = [d, a[t]].min\n d -= amt\n a[t] -= amt\n cost += c[t] * amt\n end\n if DBG\n print a\n puts \"\"\n end\n puts \"#{cost}\"\n #totalcost += cost\nend\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\n$stdout.sync = true\na=gets.split.map(&:to_i)\nc=gets.split.map(&:to_i)\nM=[]\nn.times{|i|M<0&&i0\n}"}, {"source_code": "s = (gets.chomp).split(' ').map(&:to_i)\nn = s[0]\nm = s[1]\nt = Array.new(n)\nost = (gets.chomp).split(' ').map(&:to_i)\ncost = (gets.chomp).split(' ').map(&:to_i)\n(0..n-1).each do |i|\n t[i] = [cost[i], i]\nend\nt.sort_by!{ |x| x[0] }\npos = 0\nm.times do |p|\n s = (gets.chomp).split(' ').map(&:to_i)\n a = s[0]\n b = s[1]\n ans = 0\n ans += cost[a-1] * [b, ost[a-1]].min()\n ost[a-1] -= b\n if ost[a-1] <= 0\n temp = ost[a-1].abs()\n ost[a-1] = 0\n\n while temp > 0 do\n if pos == n && temp > 0\n ans = 0\n break\n end\n tt = temp\n temp -= [ost[t[pos][1]], tt].min()\n ans += t[pos][0] * [ost[t[pos][1]], tt].min()\n ost[t[pos][1]] -= [ost[t[pos][1]], tt].min()\n if ost[t[pos][1]] == 0\n pos += 1\n end\n end\n end\n puts ans\nend\n"}], "negative_code": [{"source_code": "n,m=gets.split.map(&:to_i)\n$stdout.sync = true\na=gets.split.map(&:to_i)\nc=gets.split.map(&:to_i)\nM=[]\nn.times{|i|M<0&&i0\n}"}, {"source_code": "n,m=gets.split.map(&:to_i)\n$stdout.sync = true\na=gets.split.map(&:to_i)\nc=gets.split.map(&:to_i)\nM=[]\nn.times{|i|M<0&&i0\n\tprint \"0\\n\" if d==0\n}"}], "src_uid": "2553ffea6d74fded12128e9db0db85dc"} {"source_code": "\ngets.chomp.to_i.times do\n\n str = gets.chomp\n i=1\n a=str[0]\n while i < str.length-1\n a+= str[i] if(i%2!=1)\n i+=1\n end\n\n puts a+str[-1]\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n\ts = gets.chomp\n\tn = s.size\n\tputs (0...n / 2).map { s[_1 * 2] }.join + s[-1]\nend\n"}, {"source_code": "n = gets.to_i\nn.times do\n\tb = gets.chomp\n\tm = b.size\n\ta = b[0]\n\t(b.size/2-1).times do |i|\n\t\ta += b[1+i*2]\n\tend\n\ta += b[-1]\n\tputs a\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n\tb = gets.chomp\n\ta = b[0]\n\tfor i in 1...b.length\n\t\ta += b[i] if i%2 == 1\n\tend\n\tputs a\nend"}, {"source_code": "n = gets.chomp.to_i\n(0...n).each do |i|\n arr = gets.chomp.split(\"\")\n arsize = arr.size\n print arr[0]\n (1...arsize).each do |j|\n if j % 2 == 0 && arr[j] == arr[j-1] \n next\n else \n print arr[j]\n end\n end\n print \"\\n\"\nend"}, {"source_code": "data_lines = gets.chomp\nresult = []\n(1..data_lines.to_i).each do\n\tb = gets.chomp\n\tif b.length < 4\n\t\tresult.push b\n\t\tnext\n\tend\n\ta = b[0]\n\t(1..(b.length-2)).step(2).each do |index|\n\t\ta += b[index]\n\tend\n\ta += b[b.length-1]\n\tresult.push a\nend\nresult.each do |res|\n\tputs res\nend"}, {"source_code": "def solve(str)\n\treturn str if str.size < 3\n\n\tcompact_mid = str[1..-2].chars.each_slice(2).map(&:first).join\n\n\t\"%s%s%s\" % [str[0], compact_mid,str[-1]]\nend\n\ninputs = ARGF.each_line.drop(1).map(&:strip).to_a\n\ninputs.each do |i|\n\tputs solve(i)\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do\n\ts = gets.chomp\n\tif s.length == 2 \n\t\tputs s\n\t\tnext\n\tend\n\tprint s[0]\n\ti = 1\n\twhile i < s.length - 1\n\t\tprint s[i]\n\t\ti += 2\n\tend\n\tputs s[-1]\nend"}, {"source_code": "n=gets.chomp.to_i\nn.times do \n inpstr = gets.chomp.split('')\n result = inpstr[0]\n (1..inpstr.size).step(2).each do |index|\n result << inpstr[index]\n end\n puts result\nend\n"}, {"source_code": "gets.to_i.times do\n s = gets.chomp\n puts (0.step(s.length, 2).to_a + [s.length - 1]).map { |i| s[i] }.join\nend\n"}], "negative_code": [{"source_code": "n=gets.chomp.to_i\nn.times do \n inpstr = gets.chomp.split('')\n result = inpstr[0]\n (1..inpstr.size).step(2).each do |index|\n result << inpstr[index]\n end\n p result\nend\n"}], "src_uid": "ac77e2e6c86b5528b401debe9f68fc8e"} {"source_code": "n,q =gets.strip.split.map(&:to_i)\n\nq.times do\n r,c =gets.strip.split.map(&:to_i)\n ans=0\n if n%2==0\n if (r+c)%2==0\n pr = n/2\n ans += ((r-1)*pr)\n ans += ((c/2)+(r%2==1 ? 1 : 0))\n else\n pr = n/2\n ans += (n*pr)\n ans += ((r-1)*pr)\n ans += ((c/2)+(r%2==0 ? 1 : 0))\n end\n else\n if (r+c)%2==0\n orc=(n/2)+1\n erc=n/2\n if r%2==1\n ans += (r/2)*(orc+erc)\n ans += ((c/2)+1)\n else\n ans += (((r-1)/2)*(orc+erc) + orc)\n ans += (c/2)\n end\n else\n orc=(n/2)+1\n erc=n/2\n ans += (((n-1)/2)*(orc+erc) + orc)\n erc=(n/2)+1\n orc=n/2\n if r%2==1\n ans += (r/2)*(orc+erc)\n ans += (c/2)\n else\n ans += (((r-1)/2)*(orc+erc) + orc)\n ans += ((c/2)+1)\n end\n end\n end\n puts ans\nend", "positive_code": [{"source_code": "N, Q = gets.split.map(&:to_i)\nQ.times do\n x, y = gets.split.map(&:to_i)\n ans = 0\n if (x+y)%2 == 0\n ans += (x-1)/2 * N\n ans += (N+1)/2 if x%2==0\n ans += (y+1)/2\n else\n ans += (N*N+1)/2\n ans += (x-1)/2 * N\n ans += N/2 if x%2==0\n ans += (y+1)/2\n end\n puts ans\nend"}], "negative_code": [], "src_uid": "3c48123f326fb79ce2e4e17e1e0765f8"} {"source_code": "def inv(arr)\r\n i1 = i2 = 0\r\n res = 0\r\n while i1 < arr.size - 1\r\n while i2 < arr.size - 1\r\n i2 += 1\r\n res += 1 if arr[i2] < arr[i1]\r\n end\r\n i1 += 1\r\n i2 = i1\r\n end\r\n res \r\nend\r\n\r\nt = gets.chomp.to_i\r\nt.times do\r\n n, k = gets.chomp.split(' ').map(&:to_i)\r\n max_n = k * 2 - 1\r\n # puts \"max_n = #{max_n.to_s}\"\r\n diff = max_n - n\r\n # puts \"DIFF = #{diff.to_s}\"\r\n arr = (1..(diff)).to_a\r\n # puts \"ARR = #{arr.to_s}\"\r\n arr << k\r\n # puts \"ARR = #{arr.to_s}\"\r\n while arr.size < k\r\n arr << arr[-1] - 1\r\n end\r\n # puts \"ARR = #{arr.to_s}\"\r\n puts arr.join(' ')\r\nend", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, k = gets.split.map &:to_i\r\n (1...2 * k - n).each do |i|\r\n print i, \" \"\r\n end\r\n (2 * k - n..k).reverse_each do |i|\r\n print i, \" \"\r\n end\r\n puts\r\nend"}, {"source_code": "gets.to_i.times do\r\n n,k=gets.split.map(&:to_i)\r\n l=[*1...2*k-n]+[*2*k-n..k].reverse\r\n puts l.join(\" \")\r\nend\r\n"}], "negative_code": [], "src_uid": "67de9506ac2458ee67346bae1a9e3926"} {"source_code": "require \"set\"\n\nn = gets.to_i\n\nn.times do\n s = gets.chomp\n\n set = Set.new\n days = 1\n i = 0\n\n while (i < s.size)\n char = s[i]\n if !set.include?(char) && set.size == 3\n set = Set.new\n days += 1\n else\n set.add(char)\n i += 1\n end\n end\n\n p days\nend\n", "positive_code": [{"source_code": "#input the number of test cases\nt = gets.chomp.to_i\n\n#list of results\nresults = []\n\n#solve\nfor i in 1..t\n str = gets.chomp\n \n #solving code\n\tresult = 0\n letterAlreadyToday = []\n for j in str.split \"\"\n\t\tif letterAlreadyToday.include? j\n\t\t\tnext\n\t\telse\n\t\t\tif letterAlreadyToday.length == 3\n\t\t\t\tletterAlreadyToday = []\n\t\t\tend\n\t\tend\n\t\tif letterAlreadyToday.length < 1\n\t\t\tresult += 1\n\t\tend\n\t\tletterAlreadyToday.push j\n end\n\tresults.push result\nend\n\nputs results"}, {"source_code": "t = gets.to_i\nt.times {\n s = gets.chomp\n d = 1\n chrs = []\n while !s.empty?\n c = s[0]\n s = s[1..-1]\n if !(chrs.index c)\n if chrs.size == 3\n d += 1\n chrs = []\n end\n chrs += [c]\n end\n end\n puts d\n}\n"}], "negative_code": [], "src_uid": "bd9da9081902a87c61591fb58fcecfe3"} {"source_code": "\ndef binary_search(x, y, a, b)\n first = 0\n last = (y - x)/[a,b].max\n\n while first <= last\n i = (first + last) / 2\n\n xx = x + i*a\n yy = y - i*b\n\n if xx == yy\n return i\n elsif xx > yy\n last = i - 1\n elsif yy > xx\n first = i + 1\n else\n return -1\n end\n end\n -1\nend\n\nn = gets.strip.to_i\nresults = []\n\nn.times do\n arr = gets.strip.split.map(&:to_i)\n x, y, a, b = *arr\n results << binary_search(x, y, a, b)\nend\n\nn.times do |x|\n puts results[x]\nend\n", "positive_code": [{"source_code": "num = gets.to_i\nwhile num > 0\n myArray = gets.chomp.split().map { |e| e.to_i }\n x = myArray[0]\n y = myArray[1]\n a = myArray[2]\n b = myArray[3]\n result = (y-x)/(a+b)\n if (y-x) % (a+b) == 0\n puts result\n else\n puts '-1'\n end\n num = num -1\nend"}, {"source_code": "class Rabbit\n \n def initialize(pos, jump_size)\n @pos = pos\n @jump_size = jump_size\n end\n \n def jump_size()\n @jump_size \n end\n \n def position()\n @pos \n end\n \nend\n\ndef read_input()\n \n input = STDIN.gets()\n \n input = input.split(' ').map(&:to_i)\n \n raise \"Invalid input\" if input.size != 4\n \n return Rabbit.new(input[0], input[2]), Rabbit.new(input[1], input[3])\n \nend\n\ndef calc_rabbits_jumps()\n \n rabbit1, rabbit2 = read_input()\n \n distance = rabbit2.position - rabbit1.position\n speed = rabbit1.jump_size + rabbit2.jump_size\n point = distance / speed.to_f\n \n if point % 1 == 0\n puts point.to_i\n else\n puts -1\n end\n \nend\n\ncnt = Integer(STDIN.gets())\n\ncnt.times {\n calc_rabbits_jumps() \n}\n"}, {"source_code": "# frozen_string_literal: true\n\n@data = $stdin.read.split\n\ndef next_token\n @data.shift\nend\n\ndef next_int\n next_token.to_i\nend\n\nt = next_int\n\nt.times do |_i|\n x = next_int\n y = next_int\n a = next_int\n b = next_int\n\n if (y - x) % (a + b) == 0\n t = (y - x) / (a + b)\n puts t\n else\n puts -1\n end\nend\n"}, {"source_code": "t = gets.to_i\nz = []\n(0..t - 1).each { |i|\n str = gets\n z[i] = str\n counter = 0\n bloc = z[i].split(' ')\n a = bloc[0].to_i; b = bloc[1].to_i; c = bloc[2].to_i; d = bloc[3].to_i\n if (b - a) % (c + d) != 0\n puts '-1'\n else\n puts (b - a) / (c + d)\n end\n}\n"}, {"source_code": "n = gets.to_i\nn.times {\n x, y, a, b = gets.split.map(&:to_i)\n if (y-x) % (a + b) > 0\n puts \"-1\"\n else\n puts (y-x)/(a+b)\n end\n}\n"}, {"source_code": "1.upto(gets.to_i) do\n x, y, a, b = gets.split(' ').map(&:to_i)\n\n delta = y-x\n\n puts delta.modulo(a+b).zero? ? delta.div(a+b) : -1\nend\n"}], "negative_code": [], "src_uid": "9afcf090806cc9c3b87120b1b61f8f17"} {"source_code": "gets.to_i.times do\r\n n, z = gets.split.map(&:to_i)\r\n ans = 0\r\n gets.split.map(&:to_i).each do |x|\r\n ans = [ans, x | z].max\r\n end\r\n puts ans\r\nend", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, z = gets.split.map(&:to_i)\r\n as = gets.split.map(&:to_i)\r\n p as.map { |a| a | z }.max\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n, z = gets.split.map(&:to_i)\r\n xs = gets.split.map(&:to_i)\r\n p xs.map { |x| x | z }.max\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n, z = gets.split.map(&:to_i)\r\n p gets.split.map(&:to_i).map{|x| x | z}.max\r\nend"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ngets.to_i.times do\r\n n, z = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i).sort.reverse\r\n\r\n num = 0\r\n ai = -1\r\n zi = 0\r\n n.times do |i|\r\n if (a[i] & z) > ai\r\n ai = a[i] | z\r\n zi = a[i] & z\r\n num = i\r\n end\r\n end\r\n\r\n ans = ai\r\n n.times do |i|\r\n next if i == num\r\n ai = a[i] | z\r\n zi &= a[i]\r\n ans = [ans, ai].max\r\n end\r\n puts ans\r\nend\r\n"}], "negative_code": [], "src_uid": "bb6168528e04156f68bde2ffc1ba828f"} {"source_code": "\nislands = gets.chomp.to_i\narray = gets.chomp.split(' ').map {|x| x.to_i }\nresult = gets.chomp.split(' ').map {|x| x.to_i }\n\na = array.dup\nb = result.dup\na.delete(0)\nb.delete(0)\n\na << a.dup\na.flatten!\n\nfor i in 0..a.length-1\n break if a.length - i< b.length\n yay = true\n for j in 0..b.length-1\n if a[i+j] != b[j]\n yay = false\n break\n end\n end\n if yay\n puts \"YES\"\n exit 0\n end\nend\n\nputs \"NO\"\n", "positive_code": [{"source_code": "n = gets.to_i - 1\na, b = 2.times.map{gets.split.map(&:to_i) - [0]}\nk = b.index(a[0])\nputs a[0...n-k] == b[k...n] && a[n-k...n] == b[0...k] ? \"YES\" : \"NO\""}], "negative_code": [], "src_uid": "846681af4b4b6b29d2c9c450a945de90"} {"source_code": "nmq = gets.chomp.split(\" \").map(&:to_i)\nn = nmq[0]\nm = nmq[1]\nq = nmq[2]\nstr = gets.chomp\nmin = gets.chomp\n\nqarr = []\nq.times {qarr.push gets.chomp.split(\" \").map(&:to_i)}\n\ndef count_em(string, substring)\n # count = 0\n ans = []\n biglen = string.length\n smallen = substring.length\n lookfor = substring[0]\n index= 0\n flag = 0\n (0..biglen-smallen+1).each do |i|\n next if i=s and x<=e-len+1}\nend", "positive_code": [{"source_code": "N, M, Q = gets.split.map(&:to_i)\nS = gets.chomp\nT = gets.chomp\nnum = Array.new(N+1, 0)\n(N-M+1).times do |i|\n num[i] = S[i, M] == T ? 1 : 0\nend\n(N-1).times do |i|\n num[i+1] += num[i]\nend\n\nQ.times do |i|\n l, r = gets.split.map(&:to_i)\n l -= 1\n r -= 1\n puts r-l+1 >= M ? num[r-M+1] - num[l-1] : 0\nend"}, {"source_code": "N, M, Q = gets.split.map(&:to_i)\nS = gets.chomp\nT = gets.chomp\nnum = Array.new(N+1, 0)\n(N-M+1).times do |i|\n if S[i, M] == T\n num[i] = 1\n else\n num[i] = 0\n end\nend\n(N-1).times do |i|\n num[i+1] += num[i]\nend\n\nQ.times do |i|\n l, r = gets.split.map(&:to_i)\n l -= 1\n r -= 1\n ans = r >= M-1 ? num[r-M+1] - num[l-1] : 0\n puts ans > 0 ? ans : 0\nend\n"}, {"source_code": "def single_input\n\tgets.chomp.to_i\nend\n\ndef multiple_input\n\tgets.chomp.split(' ').map(&:to_i)\nend\n\ndef string_input\n\tgets.chomp\nend\n\nn, m, q = multiple_input\ns = string_input\nt = string_input\n\nac = Array.new(n+m, 0)\n\npoint = 0\n(0+m-1).upto(n-1) do |i|\n\tflag = true\n\tm.times do |j|\n\t\tif s[i-m+1+j] != t[j]\n\t\t\tflag = false\n\t\tend\n\tend\n\t\n\tif flag\n\t\tac[i] += 1\n\tend\n\t# p \"#{s[i]} #{t[point]}, #{point}\"\n\n\tif i != 0\n\t\tac[i] += ac[i-1]\n\tend\nend\n\n# p ac\nq.times do |_|\n\tx, y = multiple_input\n\tif x+m-3 > y-1\n\t\tputs 0\n\t\t# puts \"CASE1\"\n\telsif x+m-3 >= 0 && x+m-3 < n\n\t\tputs ac[y-1] - ac[x+m-3]\n\t\t# puts \"CASE2 #{y-1} #{x+m-3} #{ac[y-1]} #{ac[x+m-3]}\"\n\telse\n\t\tputs ac[y-1]\n\t\t# puts \"CASE3\"\n\tend\nend"}], "negative_code": [{"source_code": "def single_input\n\tgets.chomp.to_i\nend\n\ndef multiple_input\n\tgets.chomp.split(' ').map(&:to_i)\nend\n\ndef string_input\n\tgets.chomp\nend\n\nn, m, q = multiple_input\ns = string_input\nt = string_input\n\nac = Array.new(n, 0)\n\npoint = 0\nn.times do |i|\n\n\t# p \"#{s[i]} #{t[point]}, #{point}\"\n\tif s[i] == t[point]\n\t\tpoint += 1\n\telse\n\t\tpoint = 0\n\tend\n\n\tif point == m\n\t\tac[i] += 1\n\t\tpoint = 0\n\tend\n\n\tif i != 0\n\t\tac[i] += ac[i-1]\n\tend\nend\n\n# p ac\nq.times do |_|\n\tx, y = multiple_input\n\tif x+m-3 >= 0 && x+m-3 < n\n\t\tputs ac[y-1] - ac[x+m-3]\n\telse\n\t\tputs ac[y-1]\n\tend\nend"}, {"source_code": "def single_input\n\tgets.chomp.to_i\nend\n\ndef multiple_input\n\tgets.chomp.split(' ').map(&:to_i)\nend\n\ndef string_input\n\tgets.chomp\nend\n\nn, m, q = multiple_input\ns = string_input\nt = string_input\n\nac = Array.new(n, 0)\n\npoint = 0\nn.times do |i|\n\n\t# p \"#{s[i]} #{t[point]}, #{point}\"\n\tif s[i] == t[point]\n\t\tpoint += 1\n\telse\n\t\tpoint = 0\n\tend\n\n\tif point == m\n\t\tac[i] += 1\n\t\tpoint = 0\n\tend\n\n\tif i != 0\n\t\tac[i] += ac[i-1]\n\tend\nend\n\n# p ac\nq.times do |_|\n\tx, y = multiple_input\n\tif x+m-3 > y-1\n\t\tputs 0\n\t\t# puts \"CASE1\"\n\telsif x+m-3 >= 0 && x+m-3 < n\n\t\tputs ac[y-1] - ac[x+m-3]\n\t\t# puts \"CASE2 #{y-1} #{x+m-3} #{ac[y-1]} #{ac[x+m-3]}\"\n\telse\n\t\tputs ac[y-1]\n\t\t# puts \"CASE3\"\n\tend\nend"}, {"source_code": "def single_input\n\tgets.chomp.to_i\nend\n\ndef multiple_input\n\tgets.chomp.split(' ').map(&:to_i)\nend\n\ndef string_input\n\tgets.chomp\nend\n\nn, m, q = multiple_input\ns = string_input\nt = string_input\n\nac = Array.new(n, 0)\n\npoint = 0\nn.times do |i|\n\n\t# p \"#{s[i]} #{t[point]}, #{point}\"\n\tif s[i] == t[point]\n\t\tpoint += 1\n\telse\n\t\tpoint = 0\n\tend\n\n\tif point == m\n\t\tac[i] += 1\n\t\tpoint = 0\n\tend\n\n\tif i != 0\n\t\tac[i] += ac[i-1]\n\tend\nend\n\n# p ac\nq.times do |_|\n\tx, y = multiple_input\n\tif x-1 >= 0\n\t\tputs ac[y-1] - ac[x-1]\n\telse\n\t\tputs ac[y-1]\n\tend\nend"}, {"source_code": "N, M, Q = gets.split.map(&:to_i)\nS = gets.chomp\nT = gets.chomp\nnum = Array.new(N+1, 0)\n(N-M+1).times do |i|\n if S[i, M] == T\n num[i] = 1\n else\n num[i] = 0\n end\nend\n(N-1).times do |i|\n num[i+1] += num[i]\nend\n\nQ.times do |i|\n l, r = gets.split.map(&:to_i)\n l -= 1\n r -= 1\n puts r >= M-1 ? num[r-M+1] - num[l-1] : 0\nend\n"}, {"source_code": "N, M, Q = gets.split.map(&:to_i)\nS = gets.chomp\nT = gets.chomp\nnum = Array.new(N+1, 0)\n(N-M+1).times do |i|\n num[i] = S[i, M] == T ? 1 : 0\nend\n(N-1).times do |i|\n num[i+1] += num[i]\nend\n\nQ.times do |i|\n l, r = gets.split.map(&:to_i)\n l -= 1\n r -= 1\n ans = r-l+1 >= M ? num[r-M+1] - num[l-1] : 0\nend"}, {"source_code": "N, M, Q = gets.split.map(&:to_i)\nS = gets.chomp\nT = gets.chomp\nnum = Array.new(N+1, 0)\n(N-M+1).times do |i|\n if S[i, M] == T\n num[i] = 1\n else\n num[i] = 0\n end\nend\n(N-1).times do |i|\n num[i+1] += num[i]\nend\n\nQ.times do |i|\n l, r = gets.split.map(&:to_i)\n l -= 1\n r -= 1\n puts num[r-M+1] - num[l-1]\nend\n"}, {"source_code": "nmq = gets.chomp.split(\" \").map(&:to_i)\nn = nmq[0]\nm = nmq[1]\nq = nmq[2]\nstr = gets.chomp\nmin = gets.chomp\n\nqarr = []\nq.times {qarr.push gets.chomp.split(\" \").map(&:to_i)}\n\ndef count_em(string, substring)\n # count = 0\n ans = []\n biglen = string.length\n smallen = substring.length\n lookfor = substring[0]\n index= 0\n flag = 0\n (0..biglen-smallen+1).each do |i|\n next if i=s and x<=e-len+1}\nend"}, {"source_code": "nmq = gets.chomp.split(\" \").map(&:to_i)\nn = nmq[0]\nm = nmq[1]\nq = nmq[2]\nstr = gets.chomp\nmin = gets.chomp\n\nqarr = []\nq.times {qarr.push gets.chomp.split(\" \").map(&:to_i)}\n\ndef count_em(string, substring)\n # count = 0\n ans = []\n biglen = string.length\n smallen = substring.length\n lookfor = substring[0]\n index= 0\n flag = 0\n (0..biglen-smallen+1).each do |i|\n next if i=s and x<=e-len+1}\nend"}, {"source_code": "nmq = gets.chomp.split(\" \").map(&:to_i)\nq = nmq[2]\nstr = gets.chomp\nmin = gets.chomp\n\nqarr = []\nq.times {qarr.push gets.chomp.split(\" \").map(&:to_i)}\n\ndef count_em(string, substring)\n # count = 0\n ans = []\n biglen = string.length\n smallen = substring.length\n lookfor = substring[0]\n index= 0\n (0..biglen-smallen+1).each do |i|\n next if i=s and x<=e-len+1}\nend"}, {"source_code": "nmq = gets.chomp.split(\" \").map(&:to_i)\nn = nmq[0]\nm = nmq[1]\nq = nmq[2]\nstr = gets.chomp\nmin = gets.chomp\n\nqarr = []\nq.times {qarr.push gets.chomp.split(\" \").map(&:to_i)}\n\ndef count_em(string, substring)\n # count = 0\n ans = []\n biglen = string.length\n smallen = substring.length\n lookfor = substring[0]\n index= 0\n flag = 0\n (0..biglen-smallen+1).each do |i|\n next if i=s and x<=e-len+1}\nend"}], "src_uid": "4cc5a6975d33cee60e53e8f648ec30de"} {"source_code": "gets.to_i.times do\r\n n, l, r = gets.split.map(&:to_i)\r\n array = (1..n).map do |i|\r\n ((l - 1) / i) * i + i\r\n end\r\n if array.max <= r\r\n puts \"YES\"\r\n puts array.join(\" \")\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n", "positive_code": [{"source_code": "class Solution\r\n def initialize(n, l, r)\r\n @n = n\r\n @l = l\r\n @r = r\r\n @arr = []\r\n solve\r\n print\r\n end\r\n\r\n def solve\r\n # unique gcd(i, a_i) means that a_i must be a multiple of i\r\n # -> try to find a_i s.t. a|a_i && l <= a_i <= r, i.e. smallest multiple of i > l\r\n # -> [(l - 1)/i + 1] * i\r\n (1..@n).each do |i|\r\n a_i = ((@l - 1)/i + 1) * i\r\n if a_i <= @r\r\n @arr << a_i\r\n else\r\n break\r\n end\r\n end\r\n end\r\n\r\n def print\r\n if @arr.length == @n\r\n puts 'YES'\r\n puts @arr.join(' ')\r\n else\r\n puts 'NO'\r\n end\r\n end\r\nend\r\n\r\nt = gets.chomp.to_i\r\nt.times do\r\n n, l, r = gets.chomp.split(' ').map(&:to_i)\r\n Solution.new(n, l, r)\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n, l, r = gets.split.map(&:to_i)\r\n array = (1..n).map do |i|\r\n ((l - 1) / i + 1) * i\r\n end\r\n if array.max <= r\r\n puts \"YES\"\r\n puts array.join(\" \")\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "d2cc6efe7173a64482659ba59efeec16"} {"source_code": "def solve m\n ans = []\n cur = 1\n m.times do\n l, r = gets.chomp.split.map(&:to_i)\n if cur > r\n ans << 0\n elsif cur <= l\n ans << l\n cur = l + 1\n else\n ans << cur\n cur += 1\n end\n end\n puts ans.join(' ')\nend\n\nq = gets.to_i\nq.times do\n m = gets.to_i\n solve m\nend\n", "positive_code": [{"source_code": "inp = gets.chomp.to_i\notv = []\ngg = []\ninp.times{ |w|\nppl = gets.chomp.to_i\n\nmap = []\n\nppl.times{ |line|\n\nuser = gets.chomp.split(\" \")\nmap.push([user[0].to_i,user[1].to_i])\n\n}\n\n#todo\n\nctime = 0\ncurentuser = 0\n\nloop do\nif curentuser>=map.size then break; end\nctime+=1 \n\nif ctime <= map[curentuser][1] \n\nif ctime >= map[curentuser][0]\n\notv.push(ctime)\ncurentuser+=1\nelse\n#wait\nend\n\nelse\notv.push(0)\ncurentuser+=1\nctime-=1\nend\n\n\nend\n\ngg.push(otv.join(\" \"))\notv = []\n\n}\n\n\ngg.size.times{|w|\nputs gg[w]\n}"}], "negative_code": [{"source_code": "def solve m\n ans = []\n cur = 1\n m.times do\n l, r = gets.chomp.split.map(&:to_i)\n if cur >= r\n ans << 0\n elsif cur <= l\n ans << l\n cur = l + 1\n else\n ans << cur\n cur += 1\n end\n end\n puts ans.join(' ')\nend\n\nq = gets.to_i\nq.times do\n m = gets.to_i\n solve m\nend\n"}], "src_uid": "471f80e349e70339eedd20d45b16e253"} {"source_code": "n = gets.to_i\ng = Array.new(1000) { Array.new(1000, -1) }\nn.times do |v|\n a, b = gets.split.map(&:to_i)\n g[a-1][b-1] = v\nend\nans = 0\nm1 = 999\nfor s in 0..2*m1 do\n a = [0, s-m1].max\n b = [m1, s].min\n i = a\n j = s - a \n tmp = []\n while i <= b\n tmp.push(g[i][j]) if g[i][j] != -1\n i += 1\n j -= 1\n end\n ans += tmp.combination(2).size\nend\n\nfor s in (-1*m1)..m1 do \n a = [0, (-1*s)].max\n b = [m1, (m1-s)].min\n i = a\n j = s + a \n tmp = []\n while i <= b\n tmp.push(g[i][j]) if g[i][j] != -1\n i += 1\n j += 1\n end\n ans += tmp.combination(2).size\nend\nputs ans\n", "positive_code": [{"source_code": "r=0\nh1=Hash.new(0)\nh2=Hash.new(0)\ngets.to_i.times{\n\tx,y=gets.split.map(&:to_i)\n\tr+=h1[x-y]\n\th1[x-y]+=1\n\tr+=h2[x+y]\n\th2[x+y]+=1\n}\np r"}, {"source_code": "n = gets.chomp.to_i\nbishops1 = Hash.new(0)\nbishops2 = Hash.new(0)\n\nn.times do\n x, y = gets.chomp.split(\" \").map(&:to_i)\n bishops1[x+y] += 1\n bishops2[x-y] += 1\nend\n\ndef choose(n, k)\n # n!/(n-k)!\n pTop = (n-k+1 .. n).inject(1, &:*)\n # k!\n pBottom = (2 .. k).inject(1, &:*)\n pTop / pBottom\nend\n\nsum1 = bishops1.reduce(0) do |acc, (k, v)|\n acc+choose(v, 2)\nend\n\nsum2 = bishops2.reduce(0) do |acc, (k, v)|\n acc+choose(v, 2)\nend\n\nputs sum1+sum2\n"}, {"source_code": "a=gets.chomp.to_i\nb=Array.new(1000){Array.new(1000,0)}\na.times do \ntemp=gets.chomp.split(\" \")\nb[temp[0].to_i-1][temp[1].to_i-1]=1\nend\ncol=[]\n0.upto(998) do |i|\nj=0\ntemp=0\np=0\np+=i\nloop do\ntemp+=b[i][j]\ni+=1\nj+=1\nbreak if i==1000\nend\ni=p\ncol << temp\ntemp=0\nj=999\nloop do\ntemp+=b[i][j]\ni+=1\nj-=1\nbreak if i==1000\nend\ni=p\ncol << temp\nend\n\n1.upto(998) do |i|\nj=0\np=0\np+=i\ntemp=0\nloop do\ntemp+=b[j][i]\ni+=1\nj+=1\nbreak if i==1000\nend\ni=p\ncol << temp\ntemp=0\nj=0\nloop do\ntemp+=b[j][i]\ni-=1\nj+=1\nbreak if i<0\nend\ni=p\ncol << temp\nend\ncol.delete(0)\n\nans=0\ncol.each {|i| ans+=(i*(i-1))/2 }\nputs \"#{ans}\""}, {"source_code": "a=gets.chomp.to_i\nb=Array.new(1000){Array.new(1000,0)}\na.times do \ntemp=gets.chomp.split(\" \")\nb[temp[0].to_i-1][temp[1].to_i-1]=1\nend\ncol=[]\n0.upto(998) do |i|\nj=0\ntemp=0\np=0\np+=i\nloop do\ntemp+=b[i][j]\ni+=1\nj+=1\nbreak if i==1000\nend\ni=p\ncol << temp\ntemp=0\nj=999\nloop do\ntemp+=b[i][j]\ni+=1\nj-=1\nbreak if i==1000\nend\ni=p\ncol << temp\nend\n\n1.upto(998) do |i|\nj=0\np=0\np+=i\ntemp=0\nloop do\ntemp+=b[j][i]\ni+=1\nj+=1\nbreak if i==1000\nend\ni=p\ncol << temp\ntemp=0\nj=0\nloop do\ntemp+=b[j][i]\ni-=1\nj+=1\nbreak if i<0\nend\ni=p\ncol << temp\nend\ncol.delete(0)\n\nans=0\ncol.each {|i| ans+=(i*(i-1))/2 }\nputs \"#{ans}\"\n"}, {"source_code": "n = gets.chomp.to_i\nxs = []\nys = []\nhs0 = Hash.new(0)\nhs1 = Hash.new(0)\nn.times do\n x, y = gets.chomp.split.map(&:to_i)\n hs0[x + y] += 1\n hs1[x - y] += 1\nend\n\ncnt = 0\nhs0.each do |_, v|\n cnt += v * (v - 1) / 2\nend\nhs1.each do |_, v|\n cnt += v * (v - 1) / 2\nend\nputs cnt\n"}, {"source_code": "r=0\nh1=Hash.new(0)\nh2=Hash.new(0)\ngets.to_i.times{\n\tx,y=gets.split.map(&:to_i)\n\tr+=h1[x-y]\n\th1[x-y]+=1\n\tr+=h2[x+y]\n\th2[x+y]+=1\n}\nputs r"}, {"source_code": "# def solve_stupid(a)\n# cnt = 0\n# a.each_with_index do |(xx,yy), i|\n# dd = xx - yy\n# ss = xx + yy\n# cnt += (0...i).count do |j|\n# x, y = a[j]\n# x + y == ss || x - y == dd\n# end\n# end\n# cnt\n# end\n\ndef solve(a)\n diag1 = Hash.new(0)\n diag2 = Hash.new(0)\n a.each do |x, y|\n diag1[x+y] += 1\n diag2[x-y] += 1\n end\n (diag1.values + diag2.values).map do |v|\n v*(v-1)\n end.reduce(0, :+) / 2\nend\n\n\nn = gets.to_i\na = Array.new(n) do\n gets.split.map(&:to_i)\nend\n\nputs solve(a)\n\n# def rnd\n# require 'set'\n# s = Set.new\n# Array.new(rand(1..100)) do\n# c = [rand(100), rand(100)]\n# until s.add?(c)\n# c = [rand(100), rand(100)]\n# end\n# c\n# end\n# end\n\n# p((0..1000).all?{ t = rnd; solve(t) == solve_stupid(t)})\n\n"}, {"source_code": "n = gets.to_i\nb = []\nd = Array.new(2001, 0)\nnd = Array.new(2001, 0)\nfor _ in 0...n\n x, y = gets.split(' ').map &:to_i\n pos = y-x\n neg = y+x\n d[999+ pos]+=1\n nd[neg]+=1\nend\n\ndef bin(n, k) \n u = l = 1\n for v in 1..k\n u*=n+1-v\n l*=v\n end\n u/l\nend\np = 0\nfor i in 0...2001\n p += bin(d[i].to_i, 2) + bin(nd[i].to_i, 2)\nend\n\nputs p\n"}, {"source_code": "n = gets.chomp.to_i\ncoords1 = Hash.new(0)\ncoords2 = Hash.new(0)\nn.times do\n coord = gets.chomp.split(\" \").map(&:to_i)\n coords1[coord[1] - coord[0]] += 1\n coords2[coord[1] + coord[0]] += 1\nend\n\ndef comb(n, k)\n return ((n - k + 1)..n).inject(:*) / (1..k).inject(:*)\nend\n\nres = 0\ncoords1.values.each do |v|\n res += comb(v, 2)\nend\ncoords2.values.each do |v|\n res += comb(v, 2)\nend\n\nputs res\n"}], "negative_code": [{"source_code": "n = gets.to_i\nb = []\nfor _ in 0...n\n x, y = gets.split(' ').map &:to_i\n b << [x,y]\nend\n\nb = b.sort {|a,b| a[0] - b[0] }\n\np=0\nfor j in 0...(b.size-1)\n for i in (j+1)...b.size\n dx = b[j][0] - b[i][0]\n dy = b[j][1] - b[i][1]\n if dx!=0 && (dy/dx).abs == 1\n p += 1\n end\n end\nend\n\nputs p"}, {"source_code": "n = gets.to_i\nb = []\nfor _ in 0...n\n x, y = gets.split(' ').map &:to_i\n b << [x,y]\nend\n\nb = b.sort {|a,b| a[0] - b[0] }\n\np=0\nfor j in 0..b.size\n for i in (j+1)...b.size\n dx = b[j][0] - b[i][0]\n dy = b[j][1] - b[i][1]\n if dy>0 && (dx/dy).abs == 1\n p += 2\n end\n end\nend\n\nputs p"}, {"source_code": "n = gets.to_i\nb = []\nfor _ in 0...n\n x, y = gets.split(' ').map &:to_i\n b << [x,y]\nend\n\nb = b.sort {|a,b| a[0] - b[0] }\n\np=0\nfor j in 0...b.size\n for i in 0...b.size\n dx = b[j][0] - b[i][0]\n dy = b[j][1] - b[i][1]\n if dy>0 && (dx/dy).abs == 1\n p += 1\n end\n end\nend\n\nputs p"}, {"source_code": "n = gets.to_i\nb = []\nd = Array.new(2002, 0)\nnd = Array.new(2002, 0)\nfor _ in 0...n\n x, y = gets.split(' ').map &:to_i\n d[1001 + x - y]+=1\n nd[1001 + y - x]+=1\nend\n\ndef bin(n, k) \n u = l = 1\n for v in 1..k\n u*=n+1-v\n l*=v\n end\n u/l\nend\np = 0\nfor i in 0...2002\n p += bin(d[i].to_i, 2) + bin(nd[i].to_i, 2)\nend\n\nputs p\n\n# b = b.sort {|a,b| a[0] - b[0] }\n\n# p=0\n# for j in 0...(b.size-1)\n# for i in (j+1)...b.size\n# dx = b[j][0] - b[i][0]\n# dy = b[j][1] - b[i][1]\n# if dx!=0 && (dy/dx).abs == 1\n# p += 1\n# end\n# end\n# end\n\n# puts p"}, {"source_code": "n = gets.to_i\nb = []\nd = Array.new(2000, 0)\nnd = Array.new(2000, 0)\nfor _ in 0...n\n x, y = gets.split(' ').map &:to_i\n \n d[1000 + x - y]+=1\n nd[1000 + y - x]+=1\nend\n\ndef bin(n, k) \n u = l = 1\n for v in 1..k\n u*=n+1-v\n l*=v\n end\n u/l\nend\np = 0\nfor i in 0...2000\n if d[i] > 1\n p += bin(d[i], 2)\n end\n\n if nd[i] > 1\n p += bin(nd[i], 2)\n end\nend\n\nputs p\n\n# b = b.sort {|a,b| a[0] - b[0] }\n\n# p=0\n# for j in 0...(b.size-1)\n# for i in (j+1)...b.size\n# dx = b[j][0] - b[i][0]\n# dy = b[j][1] - b[i][1]\n# if dx!=0 && (dy/dx).abs == 1\n# p += 1\n# end\n# end\n# end\n\n# puts p"}, {"source_code": "n = gets.to_i\nb = []\nfor _ in 0...n\n x, y = gets.split(' ').map &:to_i\n b << [x,y]\nend\n\nb = b.sort {|a,b| a[0] - b[0] }\n\np=0\nfor j in 0..b.size\n for i in (j+1)...b.size\n dx = b[j][0] - b[i][0]\n dy = b[j][1] - b[i][1]\n if dy>0 && (dx/dy).abs == 1\n p += 1\n end\n end\nend\n\nputs p"}, {"source_code": "n = gets.chomp.to_i\ncoords = Hash.new(0)\nn.times do\n coord = gets.chomp.split(\" \").map(&:to_i)\n k = coord[1] % coord[0]\n coords[k] += 1\nend\n\ndef comb(n, k)\n return ((n - k + 1)..n).inject(:*) / (1..k).inject(:*)\nend\n\n\nres = 0\ncoords.values.each do |v|\n res += comb(v, 2)\nend\n\n\nputs res\n"}], "src_uid": "eb7457fe1e1b571e5ee8dd9689c7d66a"} {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n b = gets.split.map(&:to_i)\n plus = false\n minus = false\n ok = true\n for i in 0...n do\n if b[i] > a[i]\n if !plus\n ok = false\n break\n end\n elsif b[i] < a[i]\n if !minus\n ok = false\n break\n end\n end\n plus = true if a[i] == 1\n minus = true if a[i] == -1\n end\n puts ok ? \"YES\" : \"NO\"\nend\n", "positive_code": [{"source_code": "# https://codeforces.com/problemset/problem/1333/B\n\ngets.to_i.times do\n n = gets.to_i\n a = gets.split(' ').map(&:to_i)\n b = gets.split(' ').map(&:to_i)\n\n first_plus_index = nil\n first_minus_index = nil\n\n possible = true\n n.times do |i|\n first_plus_index = i if first_plus_index.nil? && a[i] == 1\n first_minus_index = i if first_minus_index.nil? && a[i] == -1\n\n if a[i] != b[i] &&\n (i == 0 ||\n (b[i] < a[i] && (first_minus_index.nil? || first_minus_index == i)) ||\n (b[i] > a[i] && (first_plus_index.nil? || first_plus_index == i)))\n\n possible = false\n break\n end\n end\n\n puts possible ? \"YES\" : \"NO\"\nend"}, {"source_code": "# coding: utf-8\n\nt = gets.to_i\nUnit = Struct.new(:val, :n, :z, :p)\nt.times {\n n = gets.to_i\n neg, zero, pos = 0, 0, 0\n ar = []\n gets.split.each { |i|\n i = i.to_i\n ar << Unit.new(i, neg, zero, pos)\n neg += 1 if i < 0\n zero += 1 if i == 0\n pos += 1 if i > 0\n }\n\n failed = false\n br = gets.split.map(&:to_i)\n # p ar\n until br.empty?\n b = br.pop # future state\n a = ar.pop # past state\n # from past to future\n if b == a.val\n next\n else\n if a.val < b\n if a.p < 1\n failed = true\n break\n end\n else\n if a.n < 1\n failed = true\n break\n end\n end\n end\n end\n\n\n # initial_state ->next_state -> next_state -> goal\n\n if failed == true\n puts \"NO\"\n else\n puts \"YES\"\n end\n}\n"}], "negative_code": [], "src_uid": "e425aa498e5a7fc3e518cec25eec6304"} {"source_code": "require 'set'; require 'prime'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n a = gets.chomp.split(//).map(&:to_i)\n index = a.index(0)\n if index.nil?\n puts 'cyan'\n next\n end\n a.delete_at(index)\n is_2 = a.any?{|e| e.even?}\n is_3 = a.inject(&:+) % 3 == 0\n puts (is_3 && is_2) ? 'red' : 'cyan'\nend\n", "positive_code": [{"source_code": "gets.strip.to_i.times {\n x = gets.strip.split('')\n even = false\n zero1 = false\n zero2 = false\n odd = false\n sum = 0\n x.each { |i| \n w = i.to_i\n odd = true if w.odd?\n even = true if w.even? && w > 0\n zero2 = true if w == 0 && zero1\n zero1 = true if w == 0\n sum += w\n }\n if sum % 3 == 0 && ((!odd && !even && zero1) || (even && odd && zero1) || (even && zero1) || (odd && zero1 && zero2))\n puts \"red\"\n else\n puts \"cyan\"\n end\n}"}], "negative_code": [{"source_code": "gets.strip.to_i.times {\n x = gets.strip.split('')\n even = false\n zero = false\n odd = false\n sum = 0\n x.each { |i| \n w = i.to_i\n odd = true if w.odd?\n even = true if w.even? && w > 0\n zero = true if w.even? && w == 0\n sum += w\n }\n if sum % 3 == 0 && ((!odd && !even && zero) || (even && odd && zero) || (even && zero))\n puts \"red\"\n else\n puts \"cyan\"\n end\n}"}, {"source_code": "gets.strip.to_i.times {\n x = gets.strip.split('')\n even = false\n zero = false\n odd = false\n sum = 0\n x.each { |i| \n w = i.to_i\n odd = true if w.odd?\n even = true if w.even? && w > 0\n zero = true if w.even? && w == 0\n sum += w\n }\n if sum % 3 == 0 && ((!odd && !even && zero) || (even && odd && zero) || (even && zero))\n puts \"red\"\n else\n puts \"clan\"\n end\n}"}], "src_uid": "5bc07d2efb7453e51f4931cc7ec3aac7"} {"source_code": "def max(a ,b)\n a > b ? a : b\nend\n\n\nans = 0\nn, m = gets.split(/\\s+/).map(&:to_i)\na = Array.new(n)\n\nn.times do |i|\n a[i] = gets.split(/\\s+/).map(&:to_i)\nend\n\n0.upto(n-1) do |i|\n p = a[i].reduce(:+)\n q = m - p\n\n ans += max(2**p - 1 - p, 0)\n ans += max(2**q - 1 - q, 0)\nend\n\n0.upto(m-1) do |j|\n p = 0\n 0.upto(n-1) {|i| p += a[i][j] }\n q = n - p\n ans += max(2**p - 1 - p, 0)\n ans += max(2**q - 1 - q, 0)\nend\n\nputs ans + n * m\n", "positive_code": [{"source_code": "n, m=gets.split.map &:to_i\nres=0\na=[]\nn.times{\n a< 0 && x2 > 0 && x1 + x2 == -b && x1 * x2 == c\r\nend\r\n \r\nt = gets.to_i\r\nt.times do\r\n x = gets.to_i\r\n puts (1...20000).map { |sum| method(x / sum, sum) if x % sum == 0 }.any? ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "t=gets.chomp.to_i\r\nt.times do\r\nx = gets.chomp.to_i\r\na=0.0\r\nb=0.0\r\nc=0.0\r\nto = (x**(1.0/3.0)).to_i\r\n\r\n#puts \"to \" + to.to_s\r\n\r\ntr = false\r\n\r\nfor i in 1..to\r\n a=(i**3).to_f\r\n b=(x-a).to_f\r\n c=(b**(1.0/3.0)).round\r\n #puts \"#{i} + #{a} + #{b} + #{c}\"\r\n if(c**3==b && a+b==x && b!=0)\r\n puts \"YES\"\r\n tr=true\r\n end\r\n break if tr\r\nend\r\n\r\nif(!tr)\r\n puts \"NO\"\r\nend\r\n\r\nend\r\n"}, {"source_code": "def cbrt(x)\r\n return false if x <= 0\r\n y = Math.cbrt(x)\r\n y.ceil == y\r\nend\r\n \r\nt = gets.to_i\r\nt.times do\r\n x = gets.to_i\r\n puts (1..10000).map { |a| cbrt(x - a.pow(3)) }.any? ? \"YES\" : \"NO\"\r\nend\r\n# \r\n# "}, {"source_code": "def cbrt(x)\r\n return false if x <= 0\r\n y = Math.cbrt(x)\r\n y.ceil - y < Float::EPSILON\r\nend\r\n \r\nt = gets.to_i\r\nt.times do\r\n x = gets.to_i\r\n puts (1..10000).map { |a| cbrt(x - a.pow(3)) }.any? ? \"YES\" : \"NO\"\r\nend\r\n# \r\n# "}], "negative_code": [], "src_uid": "b4ca6a5ee6307ab2bcdab2ea5dd5b2b3"} {"source_code": "x = 0\r\nmexor = Array.new(300_001) { |i| x ^= i }\r\n\r\nt = gets.to_i\r\n\r\nt.times do\r\n\r\na, b = gets.split.map!(&:to_i)\r\n\r\nif mexor[a-1] == b\r\n puts a\r\nelse\r\n c = mexor[a-1] ^ b\r\n if a != c\r\n puts a + 1\r\n else\r\n puts a + 2\r\n end\r\nend\r\n\r\nend\r\n", "positive_code": [{"source_code": "cache = []\nacc = 0\n0.upto(3 * 100000 + 5).each {|x| cache.push(acc ^= x) }\nt = gets.strip.to_i\nt.times do\n a, b = gets.strip.split.map {|x| x.to_i }\n x = cache[a - 1]\n if x == b\n puts a\n elsif (x ^ b) != a\n puts a + 1\n else\n puts a + 2\n end\nend\n"}], "negative_code": [{"source_code": "x = 0\r\nmexor = Array.new(300_001) { |i| x ^= i }\r\n\r\nt = gets.to_i\r\n\r\nt.times do\r\n\r\na, b = gets.split.map!(&:to_i)\r\n\r\nif mexor[a-1] == b\r\n puts a\r\nelsif a != b\r\n puts a + 1\r\nelse\r\n puts a + 2\r\nend\r\n\r\nend\r\n"}], "src_uid": "d6790c9b4b2e488768fb4e746ee7ebe0"} {"source_code": "gets.to_i.times{\r\n n=gets.to_i;i=n%2+3;puts 2,'3'*(n%2),1\r\n (p -~i,i;i+=2)while i 3\r\n ((count-3)/2).times{ |i|\r\n res << (3 + (i+1)*2).to_s << \" \" << (3 + i*2 + 1).to_s << \" \"\r\n }\r\n end\r\n end\r\n puts res\r\n}"}, {"source_code": "t = gets.to_i\r\n(0...t).each{ |x|\r\n count = gets.to_i\r\n res = \"\"\r\n if count % 2 == 0\r\n (count/2).times{ |i|\r\n # unless i == 0\r\n # res << \" \"\r\n # end\r\n res << ((i+1)*2).to_s << \" \" << (i*2 + 1).to_s << \" \"\r\n }\r\n else\r\n res = \"3 1 2 \"\r\n if count > 3\r\n ((count-3)/2).times{ |i|\r\n res << (3 + (i+1)*2).to_s << \" \" << (3 + i*2 + 1).to_s << \" \"\r\n }\r\n end\r\n end\r\n puts res\r\n}"}, {"source_code": "gets.to_i.times{puts 2,'3'*(i=(n=gets.to_i)%2),1;i+=3;(p -~i,i;i+=2)while i 3\r\n ((count-3)/2).times{ |i|\r\n res << (3 + (i+1)*2).to_s << \" \" << (3 + i*2 + 1).to_s << \" \"\r\n }\r\n end\r\n end\r\n puts res\r\n}"}, {"source_code": "t = gets.to_i\r\n(0...t).each{ |x|\r\n count = gets.to_i\r\n res = \"\"\r\n if count % 2 == 0\r\n (count/2).times{ |i|\r\n unless i == 0\r\n res << \" \"\r\n end\r\n res << ((i+1)*2).to_s << \" \" << (i*2 + 1).to_s\r\n }\r\n else\r\n res = \"3 2 1\"\r\n if count > 3\r\n ((count-3)/2).times{ |i|\r\n res << \" \" << (3 + (i+1)*2).to_s << \" \" << (3 + i*2 + 1).to_s\r\n }\r\n end\r\n end\r\n puts res\r\n}"}, {"source_code": "t = gets.to_i\r\n(0...t).each{ |x|\r\n count = gets.to_i\r\n res = \"\"\r\n if count % 2 == 0\r\n (count/2).times{ |i|\r\n res << ((i+1)*2).to_s << \" \" << (i*2 + 1).to_s << \" \"\r\n }\r\n else\r\n res = \"3 2 1 \"\r\n if count > 3\r\n ((count-3)/2).times{ |i|\r\n res << 3 + (i+1)*2 << \" \" << 3 + (i*2 + 1) << \" \"\r\n }\r\n end\r\n end\r\n puts res\r\n}"}, {"source_code": "gets.to_i.times{n=gets.to_i;i=n%2;p 2,'3'*i,1;i+=3;(p -~i,i;i+=2)while i1?((v==p[i-1]+p[i-2])?q[i]+1:2):q[i]+1)};p q.max\n", "positive_code": [{"source_code": "n=gets.to_i;q=Array.new(n+1,0);p=gets.split.map &:to_i;p.each_with_index{|v,i| q[i+1]=(i>1?((v==p[i-1]+p[i-2])?q[i]+1:2):q[i]+1)};p q.max\n\n"}, {"source_code": "n=gets.to_i;q=Array.new(n+1,0);p=gets.split.map &:to_i;p.each_with_index{|v,i| q[i+1]=(i>1?((v==p[i-1]+p[i-2])?q[i]+1:2):q[i]+1)};p q.max\n"}, {"source_code": "n=gets.to_i;q=Array.new(n+1,0);p=gets.split.map &:to_i;p.each_with_index{|v,i| q[i+1]=(i>1?((v==p[i-1]+p[i-2])?q[i]+1:2):q[i]+1)};p q.max\n\n"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nseg = arr[0..1].length\nmax_seg = seg\nif n > 1\n\t(2..(n-1)).each do |i|\n\t\t# puts \"#{a == arr[i-2] + arr[i-1] }\"\n\t\tif arr[i] == arr[i-2] + arr[i-1] \n\t\t\t# puts \"here\"\n\t\t\tif seg == 0\n\t\t\t\tseg = 3\n\t\t\telse\n\t\t\t\tseg += 1\n\t\t\tend\n\t\t\tmax_seg = seg if seg > max_seg\n\t\telse\n\t\t\tseg = 0\n\t\tend\n\tend\nend\nputs max_seg\n# 16\n# 1 1 1 2 3 5 8 1 1 1 2 3 5 8 13 21"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\nif a.size < 3\n puts a.size\n exit\nend\nmaxlength = 2\nthislength = 2\nfor i in 2...n\n if a[i] == a[i-1]+a[i-2]\n thislength += 1\n maxlength = thislength if thislength > maxlength\n else\n thislength = 2\n end\nend\nputs maxlength\n"}, {"source_code": "n=gets.to_i;q=Array.new(n+1,0);p=gets.split.map &:to_i;p.each_with_index{|v,i| q[i+1]=(i>1?((v==p[i-1]+p[i-2])?q[i]+1:2):q[i]+1)};p q.max\n\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\n\nL = Array.new\n\n(0..n-1).each do |i|\n\tL[i] = 2\nend\n\nL[0] = 1\nmax = 1\n\n(2..n-1).each do |i|\n\tif a[i] == a[i-1] + a[i-2]\n\t\tL[i] = L[i-1] + 1\n\tend\n\tif L[i] > max\n\t\tmax = L[i]\n\tend\nend\n\nif n == 2\n\tmax = 2\nend\n\nputs max"}, {"source_code": "n=gets.to_i;q=Array.new(n+1,0);p=gets.split.map &:to_i;p.each_with_index{|v,i| q[i+1]=(i>1?((v==p[i-1]+p[i-2])?q[i]+1:2):q[i]+1)};p q.max\n\n"}, {"source_code": "n=gets.to_i;q=Array.new(n+1,0);p=gets.split.map &:to_i;p.each_with_index{|v,i| q[i+1]=(i>1?((v==p[i-1]+p[i-2])?q[i]+1:2):q[i]+1)};p q.max\n\n"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\nm=2;c=0\na=gets.split.map(&:to_i)\nif a.size==1\n\tp 1\n\texit\nend\na.each_cons(3){|e|\n\tif e[0]+e[1]==e[2]\n\t\tc+=1\n\telse\n\t\tm=[m,c+2].max\n\t\tc=0\n\tend\n}\np [m,c+2].max"}, {"source_code": "#!/usr/bin/ruby\ngets\nm=2;c=0\na=gets.split.map(&:to_i)\nif a.size==1\n\tp 1\n\texit\nend\na.each_cons(3){|e|\n\tif e[0]+e[1]==e[2]\n\t\tc+=1\n\telse\n\t\tm=[m,c+2].max\n\t\tc=0\n\tend\n}\np [m,c+2].max"}, {"source_code": "n=gets.to_i;q=Array.new(n+1,0);p=gets.split.map &:to_i;p.each_with_index{|v,i| q[i+1]=(i>1?((v==p[i-1]+p[i-2])?q[i]+1:2):q[i]+1)};p q.max\n\n"}, {"source_code": "n=gets.to_i;q=Array.new(n+1,0);p=gets.split.map &:to_i;p.each_with_index{|v,i| q[i+1]=(i>1?((v==p[i-1]+p[i-2])?q[i]+1:2):q[i]+1)};p q.max\n\n"}, {"source_code": "n = STDIN.readline.to_i\narr = STDIN.readline.split.collect {|s| s.to_i }\nif n <= 2\n\tputs n\n\texit\nend\nbest = 2\npos = 0\nwhile pos+2 < n\n\tcount = 2\n\tseek = pos+2\n\twhile seek < n\n\t\tbreak if arr[seek] != arr[seek-1] + arr[seek-2]\n\t\tcount += 1\n\t\tseek += 1\n\tend\n\tbest = [best, count].max\n\tpos = seek-1\nend\nputs best\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split.map(&:to_i)\nans,d=0,0\nn.times do |i|\n\t(i<2 || a[i]==a[i-1]+a[i-2]) ? d+=1 : d=2\n\tans=d if d>ans\nend\nputs ans"}, {"source_code": "n=gets.to_i;q=Array.new(n+1,0);p=gets.split.map &:to_i;p.each_with_index{|v,i| q[i+1]=(i>1?((v==p[i-1]+p[i-2])?q[i]+1:2):q[i]+1)};p q.max\n\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nn=gets.to_i\nm=2;c=0\ngets.split.map(&:to_i).each_cons(3){|e|\n\tif e[0]+e[1]==e[2]\n\t\tc+=1\n\telse\n\t\tm=[m,c+2].max\n\t\tc=0\n\tend\n}\np [m,c+2].max"}, {"source_code": "n=gets.to_i;q=Array.new(n+1,0);p=gets.split.map &:to_i;p.each_with_index{|v,i| q[i+1]=(i>1?((v==p[i-1]+p[i-2])?q[i]+1:2):q[i]+1)};p q.max\np q\n"}, {"source_code": "n=gets.to_i;q=Array.new(n+1,0);p=gets.split.map &:to_i;p.each_with_index{|v,i| q[i+1]=(i>1?((v==p[i-1]+p[i-2])?q[i]+1:1):q[i]+1)};p q.max\n\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\n\nL = Array.new\n\n(0..n-1).each do |i|\n\tL[i] = 2\nend\n\nL[0] = 1\nmax = 2\n\n(2..n-1).each do |i|\n\tif a[i] == a[i-1] + a[i-2]\n\t\tL[i] = L[i-1] + 1\n\t\tif L[i] > max \n\t\t\tmax = L[i]\n\t\tend\n\tend\nend\n\nputs max"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\n\nL = Array.new\n\n(0..n-1).each do |i|\n L[i] = 1\nend\n\nmax = 1\n\n(1..n-1).each do |i|\n if a[i] >= a[i-1] \n L[i] = 2\n if max < 2\n max = 2\n end\n if i > 1\n if a[i] == a[i-1] + a[i-2]\n L[i] = L[i-1] + 1\n if L[i] > max \n max = L[i]\n end\n end\n end\n end\nend\n\nputs max"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\n\nL = Array.new\n\n(0..n-1).each do |i|\n L[i] = 2\nend\n\nL[0] = 1\nmax = 1\n\n(2..n-1).each do |i|\n if a[i] == a[i-1] + a[i-2]\n L[i] = L[i-1] + 1\n if L[i] > max\n max = L[i]\n end\n end\nend\n\nputs max"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\n\nL = Array.new\n\n(0..n-1).each do |i|\n L[i] = 2\nend\n\nL[0] = 1\nmax = 1\n\n(2..n-1).each do |i|\n if a[i] == a[i-1] + a[i-2]\n L[i] = L[i-1] + 1\n end\n if L[i] > max\n max = L[i]\n end\nend\n\nputs max"}], "src_uid": "f99a23bc65a1f5cdbf7909dba573ce51"} {"source_code": "test_cases = gets.chomp.to_i\r\nfor i in 1..test_cases do\r\n n = gets.chomp.to_i\r\n line = gets.chomp.split(\" \")\r\n odd = Array.new\r\n even = Array.new\r\n for j in 0..n - 1 do\r\n a = line[j].to_i\r\n if a % 2 == 1\r\n odd.push(a)\r\n else\r\n even.push(a)\r\n end\r\n end\r\n for j in 0..odd.size - 1 do\r\n print \"#{odd[j]} \"\r\n end\r\n for j in 0..even.size - 1 do\r\n print \"#{even[j]} \"\r\n end\r\n puts \"\"\r\nend", "positive_code": [{"source_code": "t = gets.to_s.to_i\n\n1.upto(t) do |casenum|\n n = gets.to_s.split.map {|x| x.to_i }\n ar = gets.to_s.split.map {|x| x.to_i }\n\n aro = ar.select {|x| x.odd? }\n are = ar.select {|x| x.even? }\n\n if aro.size > are.size\n printf(\"%s %s\\n\", aro.join(\" \"), are.join(\" \"))\n else\n printf(\"%s %s\\n\", are.join(\" \"), aro.join(\" \"))\n end\nend\n"}], "negative_code": [], "src_uid": "fe2131c9228a2ec4365fdc3d0faa413a"} {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n ok = false\n for i in 0...(n-2) do\n for j in (i+2)...n do\n ok = true if a[i] == a[j]\n end\n end\n puts ok ? \"YES\" : \"NO\"\nend\n", "positive_code": [{"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nt = gets.to_i\nt.times {\n n = gets.to_i\n mc = {}\n gets.chomp.split.each_with_index { |value, index|\n i = value.to_i\n mc[i] ||= []\n mc[i] << index\n }\n # p mc\n found = false\n catch :found do\n for k, v in mc\n if v.length >= 2\n if v.last - v.first > 1 # \ubaa8\ub4e0 \uac04\uaca9\uc744 \uac80\uc0ac\ud560 \ud544\uc694\ub294 \uc5c6\uc9c0. at least\ub2c8\uae4c.\n found = true\n throw :found\n end\n end\n end\n end\n\n if found == true\n puts \"YES\"\n else\n puts \"NO\"\n end\n\n}"}, {"source_code": "tc = gets.to_i \n\ntc.times do \n n = gets.to_i \n arr = gets.split().map{|x| x.to_i} \n mark = Array.new(5001) {0} \n mark1 = Array.new(5001) {-1}\n ans = false\n (0...n).each do |x| \n cur = arr[x]\n if(mark[cur] == 0) \n mark1[cur] = x \n end\n mark[cur] += 1 \n if(mark[cur] > 1) \n if(mark1[cur]+1 < x) \n ans = true \n break \n end\n end\n end\n # print(mark[1])\n if(ans) \n puts (\"YES\") \n else\n puts (\"NO\")\n end\nend"}, {"source_code": "t = gets.chomp.to_i\n(0...t).each do |_|\n n = gets.chomp.to_i\n l = gets.chomp.split.map(&:to_i)\n seq_palidrom_exists = false\n (0...n).each{|i| seq_palidrom_exists = true if (l.rindex(l[i]) - i) > 1}\n puts seq_palidrom_exists ? \"YES\" : \"NO\"\nend\n"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nt = gets.to_i\nt.times {\n n = gets.to_i\n mc = {}\n gets.chomp.split.each_with_index { |value, index|\n i = value.to_i\n mc[i] ||= []\n mc[i] << index\n }\n # p mc\n found = false\n catch :found do\n for k, v in mc\n if v.length >= 2\n for i in 0...(v.length - 1)\n if v[i+1] - v[i] > 1\n found = true\n throw :found\n end\n end\n end\n end\n end\n\n if found == true\n puts \"YES\"\n else\n puts \"NO\"\n end\n\n}"}, {"source_code": "tc = gets.to_i \n\ntc.times do \n n = gets.to_i \n arr = gets.split().map{|x| x.to_i} \n mark = Array.new(5001) {0} \n ans = false\n (0...n).each do |x| \n mark[arr[x]] += 1 \n if(mark[arr[x]] > 1) \n if(arr[x] != arr[x-1]) \n ans = true \n break \n end\n end\n end\n if(ans) \n puts (\"YES\") \n else\n puts (\"NO\")\n end\nend"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n ok = false\n for i in 0...(n-2) do\n ok = true if a[i] == a[i+2]\n end\n for i in 0...(n-3) do\n ok = true if a[i] == a[i+3] && a[i+1] == a[i+2]\n end\n puts ok ? \"YES\" : \"NO\"\nend\n"}], "src_uid": "5139d222fbbfa70d50e990f5d6c92726"} {"source_code": "\nN, M, K = gets.split.map(&:to_i)\nP = gets.split.map(&:to_i)\n\nl, r = 1, K\ncount, answer = 0, 0\nm = 0\nwhile m < M\n\tcount = m\n\twhile P[m] && P[m] <= r\n\t\tm += 1\n\tend\n\tcount = m - count\n\tif count > 0\n\t\tanswer += 1\n\t\tr += count\n\telsif P[m]\n\t\tpages = ( (P[m] - r) / K.to_r ).ceil\n\t\tr += pages * K\n\t\tl += pages * K\n\tend\n#\tputs count\nend\nputs answer\n", "positive_code": [{"source_code": "n,m,k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = 0\ni = 0\nwhile i < m\n #p i\n l = (a[i]-i-1) % k + 1\n r = a[i] + k- l\n while i < m && a[i] <= r\n i += 1\n end\n #p [l,r]\n ans += 1\nend\np ans"}, {"source_code": "\nN, M, K = gets.split.map(&:to_i)\nP = gets.split.map(&:to_i)\n\nl, r = 1, K\ncount, answer = 0, 0\nm = 0\nwhile m < M\n\tcount = m\n\twhile P[m] && P[m] <= r\n\t\tm += 1\n\tend\n\tcount = m - count\n\tif count > 0\n\t\tanswer += 1\n\t\tr += count\n\telsif P[m]\n\t\tpages = ( (P[m] - r) / K.to_r ).ceil\n\t\tr += pages * K\n#\t\tl += pages * K\n\tend\n#\tputs count\nend\nputs answer\n"}, {"source_code": "\nN, M, K = gets.split.map(&:to_i)\nP = gets.split.map(&:to_i)\n\ncount, answer = 0, 0\nm = 0\nwhile m < M\n\tr = ( (P[m] - m) / K.to_r ).ceil * K\n\tcount = m\n\twhile P[m] && (P[m] - count) <= r\n\t\tm += 1\n\tend\n\tcount = m - count\n\tif count > 0\n\t\tanswer += 1\n\tend\n#\tputs count\nend\nputs answer\n"}, {"source_code": "\nN, M, K = gets.split.map(&:to_i)\nP = gets.split.map(&:to_i)\n\ncount, answer = 0, 0\nm = 0\nwhile m < M\n\tr = ( (P[m] - count) / K.to_r ).ceil * K\n\twhile P[m] && (P[m] - count) <= r\n\t\tm += 1\n\tend\n\tcount = m\n\tanswer += 1\n#\tputs count\nend\nputs answer\n"}], "negative_code": [], "src_uid": "684273a4c6711295996e520739744b0f"} {"source_code": "1.upto(gets.to_i) do\n s = gets.chomp\n\n res = s.reverse.chars.each_with_object([]).with_index do |(char, result), idx|\n result << char + '0' * idx unless char == '0'\n end\n\n puts res.size\n puts res.join(' ')\nend\n", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n res = []\n [10_000, 1_000, 100, 10, 1].each do |d|\n if (i = n / d) != 0\n res << i * d\n n -= res.last\n end\n end\n puts res.size\n puts res.join(' ')\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.chomp\n ans = []\n m = n.size\n m.times do |i|\n if n[i] != \"0\"\n ans << n[i].to_i * 10 ** (m-i-1)\n end\n end\n p ans.size\n puts ans.join(\" \")\nend\n"}, {"source_code": "t = gets.to_i\n(1).upto(t) do\n x = gets\n x = x.strip.split('')\n arr = []\n i = x.length-1\n x.each do |c|\n if(c!='0')\n arr.push([c,i])\n end\n i-=1\n end\n puts arr.length\n arr.each do |v|\n print v[0]\n (1..v[1]).each do\n print 0\n end\n print ' '\n end\n puts\nend\n\n"}, {"source_code": "# Approach\n# mod = 10\n#\n# r = n % mod\n# n = n - r\nt = gets.to_i\nfor i in 1..t do\n n = gets.to_i\n mod = 10\n rnds = []\n while n*10 >= mod\n r = n % mod\n if r != 0\n rnds << r\n n = n - r\n end\n mod = mod * 10\n end\n puts rnds.size\n puts rnds.join(' ')\nend\n"}, {"source_code": "# Approach\n# mod = 10\n#\n# r = n % mod\n# n = n - r\nt = gets.to_i\nfor i in 1..t do\n n = gets.to_i\n mod = 10\n rnds = []\n while n*10 >= mod\n r = n % mod\n if r != 0\n rnds << r\n n = n - r\n end\n mod = mod * 10\n end\n puts rnds.size\n puts rnds.join(' ')\nend\n"}, {"source_code": "t = gets.to_i\n\n1.upto t do\n count = 0\n mul = 1\n val = []\n k = gets.chomp\n array = k.each_char.map {|num| num.to_i}\n for i in array.reverse\n if i != 0\n val.push(i * mul)\n else\n mul *= 10\n next\n end\n mul *= 10\n count += 1\n end\n puts count\n puts val.join(\" \")\nend"}, {"source_code": "gets.to_i.times{\n s=gets.chomp\n n=s.size\n res=[]\n n.downto(1){|i|\n if s[i-1]!=?0\n res< 1\n term = (10 ** (length - 1))\n m = n / term\n summands << (m * term)\n\n n = n % term\n length = n.to_s.size\n k += 1\n end\n\n if n > 0\n summands << n\n k += 1\n end\n\n puts k\n puts summands.join(' ')\nend\n\nif ENV['LOCAL_PROJECT']\n input = File.exist?('in.in') ? File.new('in.in','r') : STDIN\nelse\n input = STDIN\nend\n\nt = input.gets.chomp.to_i\n\nt.times do\n n = input.gets.chomp.to_i\n is_round(n)\nend\n"}, {"source_code": "class Fixnum\n def digits\n d = []\n t = self\n while t > 0\n d << t%10\n t /= 10\n end\n d\n end\nend\n\nmodule Enumerable\n alias filter select\nend\n\ngets.to_i.times do\n n = gets.to_i \n puts n.digits.filter{|x| x > 0}.size\n n.digits.each_with_index{|x, i| print x*10**i, ' ' if x > 0}\n puts\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\nnums = []\n\nn.times do\n nums.push(gets.chomp.to_i)\nend\n\nnums.each_with_index do |num|\n nums_to_send = []\n num.to_s.reverse!.each_char.with_index do |digit, index|\n nums_to_send.push(digit.to_i * 10 ** index)\n end\n filtered_arr = nums_to_send.filter {|e| e != 0 }\n p filtered_arr.length\n puts filtered_arr.join(' ')\nend"}], "negative_code": [{"source_code": "# Approach\n# mod = 10\n#\n# r = n % mod\n# n = n - r\nt = gets.to_i\nfor i in 1..t do\n n = gets.to_i\n mod = 10\n rnds = []\n while n >= mod\n r = n % mod\n rnds << r\n n = n - r\n mod = mod * 10\n end\n puts rnds.size\n puts rnds.join(' ')\nend\n"}], "src_uid": "cd2519f4a7888b2c292f05c64a9db13a"} {"source_code": "n = gets.to_i\ns1 = gets.chomp\ns2 = gets.chomp\nn1 = s1.size\nn2 = s2.size\nT = n1*n2\nD = n%T\nN = n/T\nsum1 = 0\nsum2 = 0\nsumd1 = 0\nsumd2 = 0\n#\u0421\u0438\u043c\u0432\u043e\u043b \u00abR\u00bb (\u043e\u0442 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e rock) \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0437\u043d\u0430\u043a \u043a\u0430\u043c\u043d\u044f, \u0441\u0438\u043c\u0432\u043e\u043b \u00abS\u00bb (scissors) \u2014 \u043d\u043e\u0436\u043d\u0438\u0446, \u00abP\u00bb (paper) \u2014 \u0431\u0443\u043c\u0430\u0433\u0438.\n0.upto(T-1) do |i|\n c1 = s1[i%n1]\n c2 = s2[i%n2]\n if c1 == 'R' && c2 == 'S' || c1 == 'S' && c2 == 'P' || c1 == 'P' && c2 == 'R'\n sum1 += 1\n sumd1 += 1 if i < D\n end\n c1,c2=c2,c1\n if c1 == 'R' && c2 == 'S' || c1 == 'S' && c2 == 'P' || c1 == 'P' && c2 == 'R'\n sum2 += 1\n sumd2 += 1 if i < D\n end\nend\nsum1 = sum1 * N + sumd1\nsum2 = sum2 * N + sumd2\nprintf(\"#{sum2} #{sum1}\")\n", "positive_code": [{"source_code": "n=gets.to_i\nR,P,S=82,80,83\na,b=2.times.map{gets.chomp.each_byte.to_a}\nas=bs=ar=br=0\nlcm=a.size.lcm b.size\nq,r=n.divmod lcm\nlcm.times{|i|\n\tar,br=as,bs if i==r\n\t_a=a[i%a.size]\n\t_b=b[i%b.size]\n\tnext if _a==_b\n\tas+=1 if (_a==R&&_b==P)||(_a==P&&_b==S)||(_a==S&&_b==R)\n\tbs+=1 if (_b==R&&_a==P)||(_b==P&&_a==S)||(_b==S&&_a==R)\n}\nputs\"%d %d\"%[as*q+ar,bs*q+br]"}, {"source_code": "def gcd(a, b)\n return a if b == 0\n return gcd(b, a%b)\nend\n\ndef lcm(a, b)\n return (a/gcd(a, b))*b\nend\n\nn = gets.to_i\na = gets.strip\nb = gets.strip\nm = a.length\nk = b.length\nx = lcm(m, k)\n\na *= x/m\nb *= x/k\n\ndota = Array.new\ndotb = Array.new\n\ndota[0] = 0\ndotb[0] = 0\n\nfor i in 1..x\n case a[i-1]\n when \"R\"; c=1\n when \"P\"; c=2\n when \"S\"; c=3\n end\n case b[i-1]\n when \"R\"; c-=1\n when \"P\"; c-=2\n when \"S\"; c-=3\n end\n dota[i] = dota[i-1]\n dotb[i] = dotb[i-1]\n case c\n when 1; dotb[i] += 1\n when 2; dota[i] += 1\n when -1; dota[i] += 1\n when -2; dotb[i] += 1\n end\nend\n\nprint dota[x]*(n/x) + dota[n%x], \" \", dotb[x]*(n/x) + dotb[n%x]"}, {"source_code": "def gcd(a, b)\n until b == 0\n temp = a%b\n a = b\n b = temp\n end\n return a\nend\n\ndef lcm(a, b)\n return (a/gcd(a, b))*b\nend\n\nn = gets.to_i\na = gets.strip\nb = gets.strip\nm = a.length\nk = b.length\nx = lcm(m, k)\n\na *= x/m\nb *= x/k\n\ndota = Array.new\ndotb = Array.new\n\ndota[0] = 0\ndotb[0] = 0\n\nfor i in 1..x\n case a[i-1]\n when \"R\"; c=1\n when \"P\"; c=2\n when \"S\"; c=3\n end\n case b[i-1]\n when \"R\"; c-=1\n when \"P\"; c-=2\n when \"S\"; c-=3\n end\n dota[i] = dota[i-1]\n dotb[i] = dotb[i-1]\n case c\n when 1; dotb[i] += 1\n when 2; dota[i] += 1\n when -1; dota[i] += 1\n when -2; dotb[i] += 1\n end\nend\n\nprint dota[x]*(n/x) + dota[n%x], \" \", dotb[x]*(n/x) + dotb[n%x]"}], "negative_code": [], "src_uid": "9a365e26f58ecb22a1e382fad3062387"} {"source_code": "n,k=gets.split.map{|s|s.to_i};puts (1..n).map{|i|(k!=1&&i a[1]}\nstools = items.select{|x| x[2] == 1}\npencils = items.select{|x| x[2] == 2}\n \ncurr_k = 0\nprice = 0\nstools.each{|s|\n carts[curr_k] << s\n curr_k += 1 if curr_k < k - 1\n}\n\npencils.each{|p|\n carts[curr_k] << p\n curr_k += 1 if curr_k < k - 1 \n}\n\ncarts.each{|c|\n has_stool = c[0][2] == 1\n cart_items = c.sort{|a,b| a[1] <=> b[1]}\n cart_items.each{|item|\n price += item[1] \n }\n price -= cart_items[0][1] * 0.5 if has_stool\n}\n\nputs \"%.1f\" % price\ncarts.each{|c|\n c = c.flatten\n idxs = 0.step(c.size - 1, 3).map{|i| c[i]}\n puts [idxs.size, idxs].join(\" \")\n}", "positive_code": [{"source_code": "n,k = gets.split.map(&:to_i)\nstool = []\npencil = []\nsum = 0\nn.times do |i|\n c,t=gets.split.map(&:to_i)\n sum += c\n if t==1\n stool.push([c,i,0])\n else\n pencil.push([c,i,1])\n end\nend\nstool.sort!\nstool.reverse!\ncart = Array.new(k){Array.new()}\ncnt = [stool.length, k-1].min\n\ncnt.times do |i|\n cart[i] = Array.new\n cart[i].push(stool[i])\nend\n# \u6b8b\u308a\u3092\u4f59\u308a\u306b\u8a70\u3081\u308b\nnow = cnt\nwhile cnt < stool.size()\n cart[now].push(stool[cnt])\n cnt += 1\n now += 1\n if now >= cart.size()\n now = cart.size()-1\n end\nend\ncnt = 0\nwhile cnt < pencil.size()\n cart[now].push(pencil[cnt])\n cnt += 1\n now += 1\n if now >= cart.size()\n now = cart.size()-1\n end\nend\n\nsum = 0\nk.times{|i|\n cart[i].sort!\n has_stool = false\n cart[i].each{|t|\n sum += t[0]*2\n has_stool = true if t[2] == 0\n }\n if has_stool\n sum -= cart[i][0][0]\n end\n}\nprint sum/2\nprint \".\"\nif sum%2 == 1\n puts \"5\"\nelse\n puts \"0\"\nend\n\nk.times{|i|\n print cart[i].size()\n cart[i].each{|t|\n print \" \"\n print t[1]+1\n }\n puts\n}\n"}], "negative_code": [{"source_code": "n, k = gets.split.collect{|i| i.to_i}\ncarts = Array.new(k) {[]}\nitems = Array.new(n) {gets.split.collect{|i| i.to_i}}\nitems.each_index{|i|\n items[i] = [i+1, items[i][0], items[i][1]] \n}\n \nitems.sort{|a,b| a[1] <=> b[1]}\nstools = items.select{|x| x[2] == 1}\npencils = items.select{|x| x[2] == 2}\n \ncurr_k = 0\nprice = 0\nstools.each{|s|\n carts[curr_k] << s\n curr_k += 1 if curr_k < k - 1\n}\n\npencils.each{|p|\n carts[curr_k] << p\n curr_k += 1 if curr_k < k - 1 \n}\n\ncarts.each{|c|\n has_stool = c[0][2] == 1\n cart_items = c.sort{|a,b| a[1] <=> b[1]}\n cart_items.each{|item|\n price += item[1] \n }\n price -= cart_items[-1][1] * 0.5 if has_stool\n}\n\nputs \"%.1f\" % price\ncarts.each{|c|\n c = c.flatten\n idxs = 0.step(c.size - 1, 3).map{|i| c[i]}\n puts [idxs.size, idxs].join(\" \")\n}"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\ncarts = Array.new(k) {[]}\nitems = Array.new(n) {gets.split.collect{|i| i.to_i}}\nitems.each_index{|i|\n items[i] = [i+1, items[i][0], items[i][1]] \n}\n \nitems.sort{|a,b| a[1] <=> b[1]}\nstools = items.select{|x| x[2] == 1}\npencils = items.select{|x| x[2] == 2}\n \ncurr_k = 0\nprice = 0\nstools.each{|s|\n carts[curr_k] << s\n curr_k += 1 if curr_k < k - 1\n}\n\npencils.each{|p|\n carts[curr_k] << p\n curr_k += 1 if curr_k < k - 1 \n}\n\ncarts.each{|c|\n has_stool = c[0][2] == 1\n cart_items = c.sort{|a,b| a[1] <=> b[1]}\n cart_items.each{|item|\n price += item[1] \n }\n price -= cart_items[0][1] * 0.5 if has_stool\n}\n\nputs \"%.1f\" % price\ncarts.each{|c|\n c = c.flatten\n idxs = 0.step(c.size - 1, 3).map{|i| c[i]}\n puts [idxs.size, idxs].join(\" \")\n}"}], "src_uid": "06c7834aa4d06d6fcebfa410054f1b8c"} {"source_code": "params = gets.split(\" \").collect {|v| v.to_f}\nold_skill = Hash::new\nparams[0].to_i.times do\n old_list = gets.split(\" \")\n old_skill[old_list[0]] = old_list[1].to_i\nend\n\nnew_skill = Array::new\nparams[1].to_i.times do\n new_skill << gets.strip\nend\n\n\nskills = Hash::new\nold_skill.each do |k,v|\n level = (v*params[2]+0.0001).to_i\n skills[k] = level unless level<100\nend\n\nnew_skill.each do |v|\n skills[v] = 0 unless skills.key?(v)\nend\nskills = skills.to_a.sort\n\nputs skills.size\nskills.each do |v|\n print v[0], \" \", v[1].to_i, \"\\n\"\nend\n", "positive_code": [{"source_code": "\ninput=gets.split\nn,m=input[0..1].map(&:to_i)\nk=(input[2].to_f*100+1e-8).to_i\nres={}\nres.default=0\nn.times{\n input=gets.split\n input[1]=(input[1].to_i*k/100).to_i\n if input[1]>=100 then\n res.store(input[0],input[1])\n end\n}\nm.times{\n input=gets.split[0]\n res[input]+=0\n}\nputs res.length\nres.sort.each do|k, v|\n puts \"#{k} #{v}\"\nend\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\nrequire 'scanf'\nrequire 'bigdecimal'\n\nn, m, k = gets.scanf '%d %d %s'\nk = BigDecimal k\n\nskills = {}\nn.times do\n s, t = gets.scanf '%s %d'\n if t*k >= 100\n skills[s] = (t*k).to_i\n end\nend\n\nm.times do\n s = gets.chomp\n if not skills.has_key? s\n skills[s] = 0\n end\nend\n\nputs skills.size\nputs skills.map { |k, v| \"#{k} #{v}\" }.sort\n"}, {"source_code": "require 'scanf'\na = gets.scanf(\"%d %d %f\")\nn = a[0]\nm = a[1]\nk_100 = (a[2] * 100 + 0.5).to_i\n\nh = Hash.new\n\nn.times do\n\ta = gets.scanf(\"%s %d\")\n\tif a[1] * k_100 >= 10000 then\n\t\th[a[0]] = a[1] * k_100 / 100\n\tend\nend\n\nm.times do\n\ts = gets.chomp!\n\tif h[s].nil? then\n\t\th[s] = 0\n\tend\nend\n\nans = Array.new\nh.each{|key, value|\n\tans.push(sprintf(\"%s %d\", key, value))\n}\n\nans.sort!\nputs ans.size\nans.each{|line|\n\tputs line\n}\n"}, {"source_code": "#!/usr/bin/env ruby\n\nargs = STDIN.gets.split(\" \")\nskill = []\nargs[0].to_i.times do\n skill << STDIN.gets.split(\" \")\nend\n\nskillname = skill.map {|i| i[0]}\n\nargs[1].to_i.times do\n n = STDIN.gets.chomp\n if skillname.index(n)\n skill[skillname.index(n)][1] = \"0\" if (skill[skillname.index(n)][1].to_i*args[2].to_f*(1.0000001)).to_i < 100\n else\n skill << [n,\"0\"]\n end\nend\n\nskill.sort! {|a,b| a[0] <=> b[0]}\nret =[]\nskill.each do |i|\n exp = (i[1].to_i*args[2].to_f*(1.0000001)).to_i\n ret << \"#{i[0]} #{exp}\" unless exp < 100 and i[1].to_i != 0\nend\n\nputs ret.size\nret.each do |s|\n puts s\nend\n"}], "negative_code": [{"source_code": "\ninput=gets.split\nn,m=input[0..1].map(&:to_i)\nk=(input[2].to_f*100).to_i\nres={}\nres.default=0\nn.times{\n input=gets.split\n input[1]=(input[1].to_i*k/100).to_i\n if input[1]>=100 then\n res.store(input[0],input[1])\n end\n}\nm.times{\n input=gets.split[0]\n res[input]+=0\n}\nputs res.length\nres.sort.each do|k, v|\n puts \"#{k} #{v}\"\nend\n"}, {"source_code": "\ninput=gets.split\nn,m=input[0..1].map(&:to_i)\nk=input[2].to_f\nres={}\nres.default=0\nn.times{\n input=gets.split\n input[1]=(input[1].to_i*k).to_i\n if input[1]>=100 then\n res.store(input[0],input[1])\n end\n}\nm.times{\n input=gets.split[0]\n res[input]+=0\n}\nres.sort.each do|k, v|\n puts \"#{k} #{v}\"\nend"}, {"source_code": "\ninput=gets.split\nn,m=input[0..1].map(&:to_i)\nk=input[2].to_f\nres={}\nres.default=0\nn.times{\n input=gets.split\n input[1]=(input[1].to_i*k).to_i\n if input[1]>=100 then\n res.store(input[0],input[1])\n end\n}\nm.times{\n input=gets.split[0]\n res[input]+=0\n}\nputs res.length\nres.sort.each do|k, v|\n puts \"#{k} #{v}\"\nend\n"}, {"source_code": "params = gets.split(\" \").collect {|v| v.to_f}\nold_skill = Hash::new\nparams[0].to_i.times do\n old_list = gets.split(\" \")\n old_skill[old_list[0]] = old_list[1].to_i\nend\n\nnew_skill = Array::new\nparams[1].to_i.times do\n new_skill << gets.strip\nend\n\n\nskills = Hash::new\nold_skill.each do |k,v|\n level = (v*100*params[2]/100).to_s.to_i\n skills[k] = level unless level<100\nend\n\nnew_skill.each do |v|\n skills[v] = 0 unless skills.key?(v)\nend\nskills = skills.to_a.sort\n\nputs skills.size\nskills.each do |v|\n print v[0], \" \", v[1].to_i, \"\\n\"\nend\n"}, {"source_code": "params = gets.split(\" \").collect {|v| v.to_f}\nold_skill = Hash::new\nparams[0].to_i.times do\n old_list = gets.split(\" \")\n old_skill[old_list[0]] = old_list[1].to_i\nend\n\nnew_skill = Array::new\nparams[1].to_i.times do\n new_skill << gets.strip\nend\n\n\nskills = Hash::new\nold_skill.each do |k,v|\n level = (v*100*params[2]/100).to_i\n skills[k] = level unless level<100\nend\n\nnew_skill.each do |v|\n skills[v] = 0 unless skills.key?(v)\nend\nskills = skills.to_a.sort\n\nputs skills.size\nskills.each do |v|\n print v[0], \" \", v[1].to_i, \"\\n\"\nend\n"}, {"source_code": "params = gets.split(\" \").collect {|v| v.to_f}\nold_skill = Hash::new\nparams[0].to_i.times do\n old_list = gets.split(\" \")\n old_skill[old_list[0]] = old_list[1].to_i\nend\n\nnew_skill = Array::new\nparams[1].to_i.times do\n new_skill << gets.strip\nend\n\n\nskills = Hash::new\nold_skill.each do |k,v|\n level = (v*params[2]).to_i\n skills[k] = level unless level<100\nend\n\nnew_skill.each do |v|\n skills[v] = 0 unless skills.key?(v)\nend\nskills = skills.to_a.sort\n\nputs skills.size\nskills.each do |v|\n print v[0], \" \", v[1].to_i, \"\\n\"\nend\n"}, {"source_code": "params = gets.split(\" \").collect {|v| v.to_f}\nold_skill = Hash::new\nparams[0].to_i.times do\n old_list = gets.split(\" \")\n old_skill[old_list[0]] = old_list[1].to_i\nend\n\nnew_skill = Array::new\nparams[1].to_i.times do\n new_skill << gets.strip\nend\n\n\nskills = Hash::new\nold_skill.each do |k,v|\n level = (v*params[2]).to_s.to_i\n skills[k] = level unless level<100\nend\n\nnew_skill.each do |v|\n skills[v] = 0 unless skills.key?(v)\nend\nskills = skills.to_a.sort\n\nputs skills.size\nskills.each do |v|\n print v[0], \" \", v[1].to_i, \"\\n\"\nend\n"}, {"source_code": "params = gets.split(\" \").collect {|v| v.to_f}\nold_skill = Hash::new\nparams[0].to_i.times do\n old_list = gets.split(\" \")\n old_skill[old_list[0]] = old_list[1].to_i\nend\n\nnew_skill = Array::new\nparams[1].to_i.times do\n new_skill << gets.strip\nend\n\n\nskills = Hash::new\nold_skill.each do |k,v|\n skills[k] = v*params[2] unless v*params[2]<100\nend\n\nnew_skill.each do |v|\n skills[v] = 0 unless skills.key?(v)\nend\nskills = skills.to_a.sort\n\nputs skills.size\nskills.each do |v|\n print v[0], \" \", v[1].to_i, \"\\n\"\nend\n"}, {"source_code": "params = gets.split(\" \").collect {|v| v.to_f}\nold_skill = Hash::new\nparams[0].to_i.times do\n old_list = gets.split(\" \")\n old_skill[old_list[0]] = old_list[1].to_i\nend\n\nnew_skill = Array::new\nparams[1].to_i.times do\n new_skill << gets.strip\nend\n\n\nskills = Hash::new\nold_skill.each do |k,v|\n level = (v*params[2]).to_s.to_f.to_i\n skills[k] = level unless level<100\nend\n\nnew_skill.each do |v|\n skills[v] = 0 unless skills.key?(v)\nend\nskills = skills.to_a.sort\n\nputs skills.size\nskills.each do |v|\n print v[0], \" \", v[1].to_i, \"\\n\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nargs = STDIN.gets.split(\" \")\nskill = []\nargs[0].to_i.times do\n skill << STDIN.gets.split(\" \")\nend\n\nskillname = skill.map {|i| i[0]}\n\nargs[1].to_i.times do\n n = STDIN.gets.chomp\n if skillname.index(n)\n skill[skillname.index(n)][1] = \"0\" if skill[skillname.index(n)][1].to_i*args[2].to_f < 100\n else\n skill << [n,\"0\"]\n end\nend\n\nskill.sort! {|a,b| a[0] <=> b[0]}\nret =[]\nskill.each do |i|\n exp = (i[1].to_i*args[2].to_f).to_i\n ret << \"#{i[0]} #{exp}\" unless exp < 100 and i[1].to_i != 0\nend\n\nputs ret.size\nret.each do |s|\n puts s\nend\n"}], "src_uid": "7da1a5c4c76540e1c7dc06e4c908c8b4"} {"source_code": "n = gets.to_i\na = gets.split.map{|x|x.to_i}\nc = {}\nc.default = 0\na.each do |x|\n c[x] += 1 if x != 0\nend\nerr = false\nans = 0\nc.values.each do |x|\n err = true if x > 2\n ans += 1 if x == 2\nend\nif err\n puts -1\nelse\n puts ans\nend\n", "positive_code": [{"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\ngets\ndata = gets.split.map(&:to_i)\nhash = Hash.new( 0 )\n\ndata.each do |value|\n hash[value]+=1\nend\n\nans = 0\nhash.to_a.each do |key, value|\n if value > 2 and key != 0 then\n ans = -1\n break\n end\n \n if value == 2 and key != 0 then\n ans+=1\n end\nend\n\nputs ans"}, {"source_code": "length = $stdin.readline.to_i\nids = $stdin.readline.split(\" \").map{|i| i.to_i}\nraise \"Input data error\" if length != ids.size\n\ncounter = Hash.new(0)\nids.each{|id| counter[id]+=1}\ncounter.delete(0)\nif counter.values.find_all{|v| v>2}.any?\n\tputs \"-1\"\nelse\n\tputs counter.values.find_all{|v| v==2}.size\nend"}, {"source_code": "n = gets.to_i\nids = gets.split.map(&:to_i).sort.take(n)\n\nm = ids.reduce [-1, 0, 0] do |memo, id|\n next memo if id == 0\n if memo[0] == id\n if memo[1] > 1\n puts -1\n exit\n else\n [id, 2, memo[2] + 1]\n end\n else\n [id, 1, memo[2]]\n end\nend\n\nputs m[2]\n"}, {"source_code": "number=Integer(gets.chomp)\nstr=gets.chomp\npolicarp=0;\nflag=0;\nlist = Array.new\nstr=str.split \nstr.each do |c_hop|\n next if c_hop=='0' \n break if flag==1\n if list.find_all{|elem| elem==c_hop}.size == 1\n policarp=policarp+1\n elsif list.find_all{|elem| elem==c_hop}.size > 1\n flag=1;\n end\n list=list << c_hop;\n end\nif flag==0\n puts policarp\nelse \n puts \"-1\"\nend "}, {"source_code": "begin\n ids = []\n conversations = {}\n count = 0\n\n n = gets.chomp\n\n ids = gets.chomp\n\n ids = ids.split(' ').map(&:to_i)\n\n if ids.size != n.to_i\n puts -1\n abort\n end\n\n ids.delete(0)\n\n ids.each { |id| conversations[id] ||= 0; conversations[id] += 1 }\n\n conversations.each { |key, value| if value > 2; puts -1; abort; end; count +=1 if value == 2 }\n\n puts count\nrescue Exception\n\nend\n"}, {"source_code": "lines = ARGF.readlines\n\na = lines.last.split ' '\nb = a.map(&:to_i).delete_if {|x| 0.eql?(x) }\nb = b.uniq.map{|x| b.count(x)}\nb << 0\nputs (b.max > 2) ? -1 : b.count(2)"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i).reject(&:zero?).sort\nb = a.uniq\n\nif b.any? { |n| a.count(n) > 2 } \n puts -1\n exit 0\nend\n\nx = b.count do |n|\n a.count(n) == 2\nend\n\nputs x\n"}, {"source_code": "gets.chomp # Skip the first line\nid_counts = (gets.chomp.split.map { |x| x.to_i } - [0]).inject(Hash.new(0)) { |h, e| h[e] += 1; h }.values\nputs(id_counts.any? { |c| c > 2 } ? -1 : id_counts.select { |c| c > 1 }.size)"}, {"source_code": "at_exit do\n n = get_numbers_from_line[0]\n ids = get_numbers_from_line[0...n]\n count = 0\n ids.select{|x| x != 0}.group_by{|x| x}.each do |_, group|\n if group.length == 2\n count += 1\n elsif group.length > 2\n count = -1\n break\n end\n end\n puts count\nend\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend"}, {"source_code": "hs = Hash.new 0\nn = gets.to_i\ngets.split(' ').map(&:to_i).map{|x| hs[x]+=1}\nhs.delete(0)\nhs.delete_if{|k,v| v<2}\nif hs.any?{|k,v| v>2}\n puts -1\nelse\n puts hs.length\nend"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nkv = {}\narr.each do |e|\n if kv[e].nil? then \n kv[e] = 1\n else\n kv[e] = kv[e] + 1\n end\nend\nif kv.any? { |k,v| k>0 and v>2 } then\n puts -1\nelse\n puts kv.select { |k,v| k>0 and v==2 }.length\nend"}, {"source_code": "gets; res = 0; h = Hash.new(0)\n\ngets.split.map.each{|i|\n\tnext if (i == '0') \n\t\n\tif (h[i] == 2) then\n\t\tres = -1;\n\t\tbreak;\n\tend\n\t\n\tres += 1 if (h[i] == 1) \t\n\th[i] += 1\n}\n\np res"}, {"source_code": "n = gets.to_i\n\nt = true\nwk = gets.split.map{|i| i.to_i}\nasmas = {}\nres = 0\n\nn.times do |i|\n if wk[i] != 0\n if asmas[wk[i]] then\n asmas[wk[i]] += 1\n if asmas[wk[i]] == 2 then\n res +=1\n elsif asmas[wk[i]] > 2 then\n t = false\n end\n else\n asmas[wk[i]] = 1\n end\n end\nend\n\nif t then\n puts res\nelse\n puts \"-1\"\nend"}, {"source_code": "ids = Hash.new{0}\n$stdin.each_line.to_a[1].split(\" \").map(&:to_i).each do |id|\n next if id == 0\n ids[id] += 1\nend\n\nanswer = 0\n\nids.each do |id, count|\n if count > 2\n answer = -1\n break\n end\n\n if count == 2\n answer += 1\n end\nend\n\nputs answer\n"}, {"source_code": "num_calls = gets\ncalls = gets.split.collect {|i| i.to_i}\nnumbers = Hash.new(0)\ncalls.each do |call|\n\tnumbers[call] += 1 unless call == 0\n\tif numbers[call] > 2\n\t\tputs \"-1\"\n\t\texit\n\tend\nend\nputs numbers.values.count(2)\n"}, {"source_code": "n = gets.chomp.to_i\nh = {}\ngets.chomp.split(' ').map {|x| if x.to_i!=0; h[x].nil? ? h[x] = 1 : h[x]+=1; end;}\n\nv = h.values\nif v.any? {|x| x > 2}\n puts -1\nelse\n puts v.count(2)\nend"}, {"source_code": "def main\n num = gets.chomp.to_i\n lines = gets.chomp.split(' ').map(&:to_i)\n return if num != lines.count\n \n line_count = {}\n\n lines.each do |line|\n next if line == 0\n\n if line_count.include?(line)\n line_count[line] += 1\n if line_count[line] >= 3\n puts '-1'\n return\n end\n else\n line_count[line] = 1\n end\n end\n\n total = 0\n line_count.each { |k,v| total += 1 if v == 2 }\n\n puts total\nend\n\nmain"}, {"source_code": "class A\n def initialize\n n = $stdin.gets.chomp.to_i\n list = $stdin.gets.chomp.split(' ').map(&:to_i)\n @list = Hash.new(0)\n count = 0\n\n list.each do |num|\n @list[num] += 1 if num != 0\n end\n\n @list.each do |key, value|\n case value\n when 1\n when 2\n count += 1\n else\n puts -1\n exit\n end\n end\n\n puts count\n end\nend\n\na = A.new"}], "negative_code": [{"source_code": "hs = Hash.new 0\nn = gets.to_i\ngets.split(' ').map(&:to_i).map{|x| hs[x]+=1}\nhs.delete_if{|k,v| v<2}\nif hs.any?{|k,v| v>2}\n puts -1\nelse\n puts hs.length\nend"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \")\nkv = {}\narr.each do |e|\n if kv[:\"#{e}\"].nil? then \n kv[:\"#{e}\"] = 1\n else\n kv[:\"#{e}\"] = kv[:\"#{e}\"] + 1\n end\nend\n\nif kv.any? { |k,v| v>2 } or kv.values.inject(&:+)>n then\n puts -1\nelse\n puts kv.select { |k,v| v==2 }.length\nend"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nkv = {}\narr.each do |e|\n if kv[e].nil? then \n kv[e] = 1\n else\n kv[e] = kv[e] + 1\n end\nend\nputs kv.inspect\nif kv.any? { |k,v| k>0 and v>2 } then\n puts -1\nelse\n puts kv.select { |k,v| k>0 and v==2 }.length\nend"}, {"source_code": "n = gets\narr = gets.split(\" \")\nkv = {}\narr.each do |e|\n if kv[:\"#{e}\"].nil? then \n kv[:\"#{e}\"] = 1\n else\n kv[:\"#{e}\"] = kv[:\"#{e}\"] + 1\n end\nend\nif kv.any? { |k,v| v>2 } then\n puts -1\nelse\n puts kv.select { |k,v| v==2 }.length\nend"}, {"source_code": "n = gets.to_i\n\nt = true\nwk = gets.split.map{|i| i.to_i}\nasmas = {}\nres = 0\n\nn.times do |i|\n if asmas[wk[i]] then\n asmas[wk[i]] += 1\n if asmas[wk[i]] == 2 then\n res +=1\n elsif asmas[wk[i]] > 2 then\n t = false\n end\n else\n asmas[wk[i]] = 1\n end\nend\n\nif t then\n puts res\nelse\n puts \"-1\"\nend"}, {"source_code": "ids = Hash.new{0}\n$stdin.each_line.to_a[1].split(\" \").map(&:to_i).each do |id|\n ids[id] += 1\nend\n\nanswer = 0\n\nids.each do |id, count|\n if count > 2\n answer = -1\n break\n end\n\n if count == 2\n answer += 1\n end\nend\n\nputs answer\n"}, {"source_code": "num_calls = gets\ncalls = gets.split.collect {|i| i.to_i}\nnumbers = Hash.new(0)\ncalls.each do |call|\n\tnumbers[call] += 1\n\tif numbers[call] > 2\n\t\tputs \"-1\"\n\t\texit\n\tend\nend\nputs numbers.values.count(2)\n"}, {"source_code": "n = gets.chomp.to_i\nh = {}\ngets.chomp.split(' ').map {|x| x.to_i; h[x].nil? ? h[x] = 1 : h[x]+=1}\n\nv = h.values\nif v.any? {|x| x > 2}\n puts -1\nelse\n puts v.count(2)\nend"}, {"source_code": "n = gets.chomp.to_i\nh = {}\ngets.chomp.split(' ').map {|x| h[x].nil? ? h[x] = 1 : h[x]+=1}\n\nv = h.values\nif v.any? {|x| x > 2}\n puts -1\nelse\n puts v.count(2)\nend"}, {"source_code": "def main\n num = gets.chomp.to_i\n lines = gets.chomp.split(' ')\n return if num != lines.count\n \n line_count = {}\n\n lines.each do |line|\n next if line == 0\n\n if line_count.include?(line)\n line_count[line] += 1\n if line_count[line] >= 3\n puts '-1'\n return\n end\n else\n line_count[line] = 1\n end\n end\n\n total = 0\n line_count.each { |k,v| total += 1 if v == 2 }\n\n puts total\nend\n\nmain"}, {"source_code": "n = gets.to_i\na = gets.split.map{|x|x.to_i}\nc = {}\nc.default = 0\na.each do |x|\n c[x] += 1\nend\nerr = false\nans = 0\nc.values.each do |x|\n err = true if x > 2\n ans += 1 if x == 2\nend\nif err\n puts -1\nelse\n puts ans\nend\n"}, {"source_code": "class A\n def initialize\n n = $stdin.gets.chomp.to_i\n list = $stdin.gets.chomp.split(' ').map(&:to_i)\n @list = Hash.new(0)\n count = 0\n\n list.each do |num|\n @list[num] += 1\n end\n\n @list.each do |key, value|\n case value\n when 1\n when 2\n count += 1\n else\n puts -1\n exit\n end\n end\n\n puts count\n end\nend\n\na = A.new"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\ngets\ndata = gets.split.map(&:to_i)\nhash = Hash.new( 0 )\n\ndata.each do |value|\n hash[value]+=1\nend\n\nans = 0\nhash.to_a.each do |key, value|\n if value == 2 and key != 0 then\n ans+=1\n end\nend\n\nputs ans"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\ngets\ndata = gets.split.map(&:to_i)\nhash = Hash.new( 0 )\n\ndata.each do |value|\n hash[value]+=1\nend\n\nans = 0\nhash.to_a.each do |key, value|\n next if value == 1 or key == 0\n \n if value%2 != 0 then\n ans = -1\n break\n end\n \n ans+=1\nend\n\nputs ans"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\ngets\ndata = gets.split.map(&:to_i)\nhash = Hash.new( 0 )\n\ndata.each do |value|\n hash[value]+=1\nend\n\nans = 0\nhash.to_a.each do |key, value|\n next if value == 1\n \n if value%2 != 0 then\n ans = -1\n break\n end\n \n ans+=1\nend\n\nputs ans"}, {"source_code": "length = $stdin.readline.to_i\nids = $stdin.readline.split(\" \").map{|i| i.to_i}\nraise \"Input data error\" if length != ids.size\n\ncounter = Hash.new(0)\nids.each{|id| counter[id]+=1}\nif counter.values.find_all{|v| v>2}.any?\n\tputs \"-1\"\nelse\n\tputs counter.values.find_all{|v| v==2}.size\nend"}, {"source_code": "n = gets.to_i\nids = gets.split.map(&:to_i).sort\n\nm = ids.reduce [-1, 0, 0] do |memo, id|\n if memo[0] == id\n if memo[1] > 1\n puts -1\n exit\n else\n [id, 2, memo[2] + 1]\n end\n else\n [id, 1, memo[2]]\n end\nend\n\nputs m[2]\n"}, {"source_code": "number=Integer(gets.chomp)\nstr=gets.chomp\npolicarp=0;\nflag=0;\nlist = Array.new\nstr=str.split \nstr.each do |c_hop|\n\tnext if c_hop==0;\n\tif list.find_all{|elem| elem==c_hop}.size == 1\n\t policarp=policarp+1\n\telsif list.find_all{|elem| elem==c_hop}.size > 1\n\t flag=1;\n\t\tbreak;\n\tend\n\tlist=list << c_hop;\n end\nif flag==0\n puts policarp\nelse \n puts \"-1\"\nend\t"}, {"source_code": "ids = []\nconversations = {}\ncount = 0\n\nn = gets.chomp\n\nids = gets.chomp\n\nids = ids.split(' ').map(&:to_i)\n\nids.delete(0)\n\nids.each { |id| conversations[id] ||= 0; conversations[id] += 1 }\n\nconversations.each { |key, value| if value > 2; puts -1; abort; end; count +=1 if value > 0 }\n\nputs count\n"}, {"source_code": "gets.chomp # Skip the first line\nid_counts = gets.chomp.split.map { |x| x.to_i }.inject(Hash.new(0)) { |h, e| h[e] += 1; h }.values\nputs(id_counts.any? { |c| c > 2 } ? -1 : id_counts.select { |c| c > 1 }.size)"}], "src_uid": "45e51f3dee9a22cee86e1a98da519e2d"} {"source_code": "yo = {\n\t3=> 1,\n\t7=> 1,\n\t15=> 5,\n\t31=> 1,\n\t63=> 21,\n\t127=> 1,\n\t255=> 85,\n\t511=> 73,\n\t1023=> 341,\n\t2047=> 89,\n\t4095=> 1365,\n\t8191=> 1,\n\t16383=> 5461,\n\t32767=> 4681,\n\t65535=> 21845,\n\t131071=> 1,\n\t262143=> 87381,\n\t524287=> 1,\n\t1048575=> 349525,\n\t2097151=> 299593,\n\t4194303=> 1398101,\n\t8388607=> 178481,\n\t16777215=> 5592405,\n\t33554431=> 1082401}\n\t\n\t\ndef mo(n)\n\tres = 0\n\t(1...n).each{|x|\n\t\tif((n^x).gcd(n&x) > res) \n\t\t\tres = (x^n).gcd(x&n)\n\t\tend\n\t}\n\tres\nend\n\n\n#~ (2..(2**25-1)).each{|x|\n\t\n\t#~ if(x == 2**(Math.log2(x).to_i+1)-1) then\n\t\t#~ puts(\"#{x}: #{mo(x)}\")\n\t#~ end\n#~ }\n\ninclude Math\nq = gets.to_i\nq.times{\n\tn = gets.to_i\n\tif(yo[n]!=nil) then\n\t\tputs(yo[n])\n\telse\n\t\tputs(\"#{2**(log2(n).to_i+1)-1}\")\n\tend\n}\n", "positive_code": [{"source_code": "DBG = !true\nq = gets.to_i\n\ngs = [1,1,1,1,5,1,21,1,85,73, 341,89,1365,1,5461,4681,\n 21845,1,87381,1,349525, 299593,1398101,178481,\n 5592405, 1082401]\n\nfor i in 0...q\n puts \"i #{i} loop\" if DBG\n a = gets.to_i\n for j in 1..25\n puts \"j #{j} loop\" if DBG\n next if 2**j <= a\n if a < 2**j - 1\n puts \"#{2**j - 1}\"\n else\n puts \"#{gs[j]}\"\n end\n break\n end\nend\n"}], "negative_code": [], "src_uid": "ce9a0649ccfc956559254f324dfa02a7"} {"source_code": "m=gets.to_i\nb=gets.split.map(&:to_i)\nb.sort!.reverse!\na=[b.shift]\nc=0\nwhile b.size>0\n d=b.shift\n if c%2==0\n a.unshift d if a[0]>d\n else\n a<d\n end\n c+=1\nend\nputs a.size,a*' '\n\n\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\ngets\na = gets.split.map(&:to_i)\n\ngrouped = a.group_by {|x| x }.to_a.sort.reverse\ntail = [grouped.shift[0]]\nhead = []\ngrouped.each do |val,seq|\n if seq.size >= 2\n tail << val\n head << val\n else\n tail << val\n end\nend\n\nr = head.reverse + tail\nputs r.size\nputs r.join(\" \")\n\n"}, {"source_code": "STDIN.gets\ncards = STDIN.gets.strip.split.map {|x| x.to_i}\ncards.sort!\n\nstairs = []\nleftovers = []\nprev = 0\n\ncards.each do |x|\n if x == prev\n leftovers << x \n else\n stairs << x\n end\n prev = x\nend\n\nleftovers.reverse.each do |x|\n stairs << x unless x == prev\n prev = x\nend\n\nSTDOUT.puts stairs.size\nSTDOUT.puts stairs.reverse.join(\" \")"}, {"source_code": "m = $stdin.gets.to_i\ncards = $stdin.gets.chomp.split(' ').map{|e| e.to_i}\n\ncards.sort! {|a, b| b <=> a}\nladder = [cards.shift]\ncards.each do |e|\n if e < ladder.last\n ladder.push e \n elsif e < ladder.first\n ladder.unshift e\n end\nend\n\nputs ladder.size\nputs ladder.join(\" \")"}, {"source_code": "i = gets.to_i\ncards = gets.split.map(&:to_i)\n\nif cards.uniq.length == i\n puts i\n puts cards.sort.reverse.join ' '\nelse\n card_grps = cards.group_by(&:to_i).to_a.sort_by(&:first).map(&:last)\n result = []\n card_grps.each { |cs| result.push cs.pop }\n rev = card_grps.reverse\n rev.shift\n rev.each { |cs| result.push cs.pop unless cs.empty? }\n # p card_grps\n # p rev\n # p result\n puts result.count\n puts result.join ' '\nend\n"}, {"source_code": "cardNum = gets.chomp.to_i\ncards = gets.chomp.split(' ').map {|i| i.to_i}\nold = -1\n\nif cards.uniq.length == cards.length\n\tputs \"#{cards.length}\"\n\tcards.reverse_each do |item|\n\t\tprint \"#{item} \"\n\tend\nelse\n\tfrontList = []\n\tbackList = []\n\tcards.sort!\n\t\n\tcards.each do |item|\n\t\tfrontList << item if old != item\n\t\tbackList << item if old == item\n\t\told = item\n\tend\n\n#\tprint \"#{frontList}\"\n#\tprint \"#{backList}\"\n\n\tbackList.uniq!\n\tbackList.delete_at(backList.length - 1) if frontList[frontList.length - 1] == backList[backList.length - 1]\n\tputs \"#{frontList.length + backList.length}\"\n\n\tfrontList.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\n\tbackList.reverse_each do |item|\n\t\tprint \"#{item} \"\n\tend\nend"}], "negative_code": [{"source_code": "STDIN.gets\ncards = STDIN.gets.strip.split.map {|x| x.to_i}\ncards.sort!\n\nstairs = []\nleftovers = []\nprev = 0\n\ncards.each do |x|\n if x == prev\n leftovers << x \n else\n stairs << x\n end\n prev = x\nend\n\nleftovers.reverse.each do |x|\n stairs << x unless x == prev\nend\n\nSTDOUT.puts stairs.size\nSTDOUT.puts stairs.reverse.join(\" \")"}, {"source_code": "STDIN.gets\ncards = STDIN.gets.strip.split.map {|x| x.to_i}\ncards.sort!\n\nstairs = []\nleftovers = []\nprev = 0\n\ncards.each do |x|\n if x == prev\n leftovers << x \n else\n stairs << x\n end\n prev = x\nend\n\nleftovers.reverse.each do |x|\n stairs << x unless x == prev\n x = prev\nend\n\nSTDOUT.puts stairs.size\nSTDOUT.puts stairs.reverse.join(\" \")"}, {"source_code": "STDIN.gets\ncards = STDIN.gets.strip.split.map {|x| x.to_i}\ncards.sort!\n\nstairs = []\nleftovers = []\nprev = 0\n\ncards.each do |x|\n if x == prev\n leftovers << x \n else\n stairs << x\n end\n prev = x\nend\n\nleftovers.reverse.each do |x|\n stairs << x unless x == prev\nend\n\np stairs.size\np stairs.join(\" \")"}, {"source_code": "cardNum = gets.chomp.to_i\ncards = gets.chomp.split(' ').map {|i| i.to_i}\nold = -1\n\nif cards.uniq.length == cards.length\n\tputs \"#{cards.length}\"\n\tcards.reverse_each do |item|\n\t\tprint \"#{item} \"\n\tend\nelse\n\tfrontList = []\n\tbackList = []\n\tcards.sort!\n\t\n\tcards.each do |item|\n\t\tfrontList << item if old != item\n\t\tbackList << item if old == item\n\t\told = item\n\tend\n\n#\tprint \"#{frontList}\"\n#\tprint \"#{backList}\"\n\n\tbackList.delete_at(backList.length - 1) if frontList[frontList.length - 1] == backList[backList.length - 1]\n\tputs \"#{frontList.length + backList.length}\"\n\n\tfrontList.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\n\tbackList.reverse_each do |item|\n\t\tprint \"#{item} \"\n\tend\nend"}, {"source_code": "cardNum = gets.chomp.to_i\ncards = gets.chomp.split(' ').map {|i| i.to_i}\n\nif cards.uniq.length == cards.length\n\tputs \"#{cards.length}\"\n\tcards.reverse_each do |item|\n\t\tprint \"#{item} \"\n\tend\nelse\n\ttempCards = cards.uniq\n\ttempCards.sort!\n\n\tlist = []\n\n\ttempCards.each do |item|\n\t\t#print \"#{item} \"\n\t\tlist << item\n\t\tcards.delete_at(cards.index(item))\n\tend\n\n\tif list[list.length - 1] == cards[cards.length - 1]\n\t\tcards.delete_at(cards.length - 1)\n\tend\n\n\tcards.reverse_each do |item|\n\t\tlist << item\n\tend\n\n\tputs \"#{list.length}\"\n\tlist.each do |item|\n\t\tprint \"#{item} \"\n\tend\nend"}], "src_uid": "5c63f91eb955cb6c3172cb7c8f78976c"} {"source_code": "num_pings = gets.to_i\nnum = {1 => 0, 2 => 0}\nsuccessful = {1 => 0, 2 => 0}\nfor i in 0...num_pings\n\ttemp = gets.split.collect {|i| i.to_i}\n\tnum[temp[0]] += 10\n\tsuccessful[temp[0]] += temp[1]\nend\n(1..2).each do |n|\n\tif num[n]/2 <= successful[n]\n\t\tputs \"LIVE\"\n\telse\n\t\tputs \"DEAD\"\n\tend\nend\n", "positive_code": [{"source_code": "n = gets.to_i\na = [[], []] # a b\nn.times do\n s = gets.split.map(&:to_i)\n (s[0] == 1 ? a[0] : a[1]).push [s[1], s[2]]\nend\nputs (a[0].transpose[0].inject(:+) >= a[0].transpose[1].inject(:+) ? :LIVE : :DEAD)\nputs (a[1].transpose[0].inject(:+) >= a[1].transpose[1].inject(:+) ? :LIVE : :DEAD)"}, {"source_code": "n = gets.to_i\nat = 0\nab = 0\nbt = 0\nbb = 0\nn.times do\n t, x, y = gets.split.map(&:to_f)\n if t == 1.0\n at += x\n ab += x + y\n else\n bt += x\n bb += x + y\n end\nend\n\nif at / ab >= 0.5\n puts 'LIVE'\nelse\n puts 'DEAD'\nend\n\nif bt / bb >= 0.5\n puts 'LIVE'\nelse\n puts 'DEAD'\nend\n"}, {"source_code": "n=gets.to_i\na=[0,0]\nc=[0,0]\nn.times {\n t,s,f=gets.split.map(&:to_i)\n a[t-1]+=s\n c[t-1]+=1\n}\nfor i in 0..1 do\n puts a[i]>=5*c[i] ? \"LIVE\" : \"DEAD\"\nend"}, {"source_code": "#! /usr/bin/ruby\n$n = gets.to_i\n$k, $p = [0,0,0], [0,0,0]\n(1..$n).each do\n k, x, y = gets.split(' ').map(&:to_i)\n $k[k] += x\n $p[k] += 10\nend\n(1..2).each{ |i| if $k[i] * 2 >= $p[i] then puts \"LIVE\" else puts \"DEAD\" end }\n"}, {"source_code": "n = gets.to_i\nk = 0\nx = 0.0\ny = 0.0\nn.times do\n a = []\n gets.split(\" \").each do |st|\n a << st.to_i\n end\n if a[0] == 1 then\n x += a[1]/10.0\n k += 1\n else\n y += a[1]/10.0\n end\nend\nif (x/k >= 0.5) then\n puts \"LIVE\"\nelse\n puts \"DEAD\"\nend\n\nif (y/(n-k) >= 0.5) then\n puts \"LIVE\"\nelse\n puts \"DEAD\"\nend"}, {"source_code": "n = gets.to_i\na, c = [0,0], [0,0]\nn.times do\n t,x,y = gets.split(' ').map(&:to_i)\n a[t-1] += x\n c[t-1] += 1\nend\nfor i in 0..1 do\n puts a[i]>=5*c[i] ? \"LIVE\" : \"DEAD\"\nend"}, {"source_code": "n = gets.to_i\nxx = Array.new(2,0)\nyy = Array.new(2,0)\n(1..n).each do\n t, x, y = gets.split.collect{|i| i.to_i}\n xx[t-1] += x\n yy[t-1] += y\nend\n(0..1).each do |i|\n if xx[i] >= yy[i]\n puts 'LIVE'\n else\n puts 'DEAD'\n end\nend\n"}, {"source_code": "n = gets.to_i\n\na = [0,0]\nb = [0,0]\n\nn.times do\n t,x,y = *(gets.split.map &:to_i)\n if t==1\n a[0] += x\n a[1] += x+y\n else\n b[0] += x\n b[1] += x+y\n end\nend\n\nputs a[0]>=a[1]/2 ? 'LIVE' : 'DEAD'\nputs b[0]>=b[1]/2 ? 'LIVE' : 'DEAD'"}, {"source_code": "p = {1 => [0, 0], 2 => [0, 0]}\nfor _ in 1..gets.chomp.to_i\n h, v = gets.chomp.split.map { |x| x.to_i }[0..1]\n a = p[h == 1 ? 1 : 2]\n a[0] += v\n a[1] += 1\nend\np.values.each {|a| puts(a[0] >= 10 * a[1] / 2 ? 'LIVE' : 'DEAD') }"}, {"source_code": "n = gets.to_i\ns = []\ngood1 = 0\ngood2 = 0\nbad1 = 0\nbad2 = 0\nn.times do |i|\n s[i] = gets.split\n s[i] = s[i].collect {|j| j = j.to_i}\n if s[i][0] == 1 then\n good1 += s[i][1]\n bad1 += s[i][2] \n else\n good2 += s[i][1]\n bad2 += s[i][2]\n end\nend\nif good1 >= bad1 then \n puts \"LIVE\"\nelse\n puts \"DEAD\"\nend\nif good2 >= bad2 then\n puts \"LIVE\"\nelse\n puts \"DEAD\"\nend"}, {"source_code": "x1,x2,n1,n2=0,0,0,0\ngets.to_i.times do \n\ta=gets.split.map(&:to_i)\n\tcase a[0]\n\twhen 1\n\t\tx1+=a[1]\n\t\tn1+=1\n\twhen 2\n\t\tx2+=a[1]\n\t\tn2+=1\n\tend\nend\n(10.0*n1/x1<=2.0&&x1!=0)?(puts \"LIVE\"):(puts \"DEAD\")\n(10.0*n2/x2<=2.0&&x2!=0)?(puts \"LIVE\"):(puts \"DEAD\")\n\n\t\n"}, {"source_code": "n = gets.to_i\ns = [[0, 0], [0, 0]]\nn.times do\n t, x, y = gets.split.map(&:to_i)\n s[t-1][0] += x\n s[t-1][1] += 10\nend\ns.each {|a| if a[0] >= a[1]/2 then puts \"LIVE\" else puts \"DEAD\" end}"}], "negative_code": [{"source_code": "n = gets.to_i\ns = [\"LIVE\", \"LIVE\"]\nn.times do\n t, x, y = gets.split.map(&:to_i)\n if x >= 5 then\n s[t-1] = \"LIVE\"\n else\n s[t-1] = \"DEAD\"\n end\nend\ns.each {|x| puts x}"}, {"source_code": "n = gets.to_i\nat = 0\nab = 0\nbt = 0\nbb = 0\nn.times do\n c, t, b = gets.split.map(&:to_f)\n if c == 1.0\n at += t\n ab += b\n else\n bt += t\n bb += b\n end\nend\n\nif at / ab >= 0.5\n puts 'LIVE'\nelse\n puts 'DEAD'\nend\n\nif bt / bb >= 0.5\n puts 'LIVE'\nelse\n puts 'DEAD'\nend\n"}, {"source_code": "n = gets.to_i\ns = [\"DEAD\", \"DEAD\"]\nn.times do\n t, x, y = gets.split.map(&:to_i)\n if x >= 5 then\n s[t-1] = \"LIVE\"\n else\n s[t-1] = \"DEAD\"\n end\nend\ns.each {|x| puts x}"}], "src_uid": "1d8870a705036b9820227309d74dd1e8"} {"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n n, m = ints\r\n s = rep(n) { string.each_byte.to_a }\r\n min = INF\r\n s.combination(2) do |(a, b)|\r\n m = a.zip(b).sum { |x, y| (x - y).abs }\r\n min = [m, min].min\r\n end\r\n puts min\r\n end\r\n}\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\n$yesno = %w(No Yes)\r\nYesNo = %w(No Yes)\r\nYESNO = %w(NO YES)\r\nINF = 10**18\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t] end\r\ndef YesNo t; puts YesNo[t] end\r\ndef YESNO t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n ss = n.times.map { gets.chomp.bytes.map { |c| c - 97 } }\r\n answer = ss.flat_map.with_index do |s1, i|\r\n ss[i + 1..].map do |s2|\r\n m.times.map do |i|\r\n (s1[i] - s2[i]).abs\r\n end.sum\r\n end\r\n end.min\r\n p answer\r\nend\r\n"}, {"source_code": "def chardist(a, b)\n xs = [a.ord, b.ord].sort\n xs[1] - xs[0]\nend\n\ndef dist(a, b)\n fail unless a.length == b.length\n m = a.length\n (0...m).map { |i| chardist(a[i], b[i]) }.sum\nend\n\ngets.to_i.times do\n n, _ = gets.split.map(&:to_i)\n ss = Array.new(n) { gets.strip }\n\n ans = nil\n n.times do |r|\n r.times do |l|\n cur = dist(ss[l], ss[r])\n ans = cur if !ans || cur < ans\n end\n end\n\n p ans\nend\n"}, {"source_code": "def diff(s, t)\n r = 0\n s.chars.each_with_index do |c, i|\n r += (c.ord - t[i].ord).abs\n end\n\n r\nend\n\ndef main\n gets.to_i.times do\n n, m = gli\n a = []\n ans = 100_100_100_100\n n.times { a << gets.chomp }\n\n (0...n).each do |i|\n (i + 1...n).each do |j|\n ans = [ans, diff(a[i], a[j])].min\n end\n end\n puts ans\n end\nend\n\nMOD = 10**9 + 7\ndef gs = gets.chomp\ndef gi = gets.to_i\ndef gli = gets.split.map(&:to_i)\ndef cyesno(x) = x ? :Yes : :No\ndef uyesno(x) = x ? :YES : :NO\n\nmain\n"}], "negative_code": [], "src_uid": "ef2b90d5b1073430795704a7df748ac3"} {"source_code": "s = gets\nn = s.length\nsum = Array.new n + 1, 0\n(2..n).each do |i|\n sum[i] += sum[i - 1]\n if s[i - 1] == s[i - 2]\n sum[i] += 1\n end\nend\nm = gets.to_i\nm.times do\n l, r = gets.split.map &:to_i\n puts sum[r] - sum[l]\nend\n", "positive_code": [{"source_code": "dp=[0]\npre=0\ngets.chomp.each_byte{|b|\n dp<1\n\tif s[0]==s[1] then\n\t\tans=ans+1\n\tend\n\tarr< 1\nend\n\nqueries.map! { |query| query.split.map(&:to_i) }.each do |query|\n i, j = query\n puts data[j] - data[i]\nend\n"}, {"source_code": "def main()\n st=gets.chomp\n ar=Array.new(st.length)\n for i in 0...(st.length)\n ar[i]=0\n end\n for i in 0...(st.length)\n if i>0\n ar[i]=ar[i-1]\n end\n if i+1<(st.length) && st[i].chr==st[i+1].chr\n ar[i]+=1\n end \n end\n tc=gets.chomp.to_i\n for i in 0...tc\n l,r=gets.chomp.split(\" \").map{|i| i.to_i}\n l-=1\n r-=1\n if l-1==-1\n puts ar[r-1]\n else\n puts ar[r-1]-ar[l-1]\n end\n end\nend\nmain()"}, {"source_code": "s=gets.chomp\nn=s.size\na=[]\n0.upto(n-1){|i|a[i]=(s[i]==s[i+1]?1:0)+(i>0?a[i-1]:0)}\ngets.to_i.times {\n l,r=gets.split.map(&:to_i)\n puts a[r-2]-(l==1?0:a[l-2])\n}"}, {"source_code": "dp=[0]\npre=0\ngets.chomp.each_byte{|b|\n dp< 1 && s[0...s.size-1].to_i > max\n max = s[0...s.size-1].to_i\nend\n if s.size > 2\n arr = s.split(//)\n arr.delete_at(-2) \n n = arr.join.to_i \n if n > max\n max = n\n end\nend\nputs max"}], "src_uid": "b30e09449309b999473e4be6643d68cd"} {"source_code": "gets.to_i.times { puts (1..gets.to_i / 2).sum { |i| i * i * 8 } }\n", "positive_code": [{"source_code": "1.upto(gets.to_i) do\n n = gets.to_i\n puts (1..n.div(2)).inject(0) { |x, i| x + 8 * i**2 } \nend\n"}], "negative_code": [], "src_uid": "b4b69320c6040d2d264ac32e9ba5196f"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ncnt = [0,0,0,0,0,0]\nvals = [4,8,15,16,23,42]\na.each do |v|\n cnt[0] += 1 if v == 4\n 1.upto(5) do |i|\n if vals[i] == v && cnt[i-1]>0\n cnt[i] += 1\n cnt[i-1] -= 1\n break\n end\n end\nend\np n-cnt[5]*6\n", "positive_code": [{"source_code": "GOOD = [4,8,15,16,23,42]\n\ndef solve(a)\n pos = {}\n GOOD.each { |g| pos[g] = [] }\n\n a.each_with_index do |e, i|\n pos[e].push(i)\n end\n # puts pos.inspect\n res = 0\n while true\n positions = []\n GOOD.each_with_index do |g, i|\n p = pos[g].shift\n while i > 0 && !p.nil? && !positions[i - 1].nil? && p < positions[i - 1]\n p = pos[g].shift\n end\n positions << p\n end\n break if positions.include?(nil)\n res += 1\n end\n a.size - (res * 6)\nend\n\nn = gets.strip.to_i\na = gets.strip.split(' ').map(&:to_i)\nputs solve(a)"}], "negative_code": [{"source_code": "GOOD = [4,8,15,16,23,42]\ndef solve(a)\n h = {}\n GOOD.each { |g| h[g] = 0 }\n a.each do |e|\n if GOOD.include?(e)\n h[e] += 1\n end\n end\n mn = h.min_by { |k, v| v }\n return a.size if mn.nil?\n return a.size - (mn[1] * GOOD.size)\nend\n\nn = gets.strip.to_i\na = gets.strip.split(' ').map(&:to_i)\nputs solve(a)"}], "src_uid": "eb3155f0e6ba088308fa942f3572f582"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.chomp.reverse.to_i(2)\nr_max = l_max = 10 ** 9\nr_min = l_min = - 10 ** 9\n\n4.upto(n-1) do |i|\n if b & 15 == 15\n if b & 16 == 0\n t = a[i-4,5].min - 1\n r_max = t if t < r_max\n #else\n # t = a[i-4,5].min\n # r_min = t if t > r_min\n end\n elsif b & 15 == 0\n if b & 16 == 16\n t = a[i-4,5].max + 1\n l_min = t if t > l_min\n #else\n # t = a[i-4,5].max\n # l_max = t if t < l_max\n end\n end\n b = b >> 1\n #p b.to_s(2)\nend\nprint \"#{l_min} #{r_max}\"\n#print \"\\nl is from #{l_min} to #{l_max}, r is from #{r_min} to #{r_max}\"\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.chomp.reverse.to_i(2)\nr_max = l_max = 10 ** 9\nr_min = l_min = - 10 ** 9\n\n4.upto(n-1) do |i|\n if b & 15 == 15\n if b & 16 == 0\n t = a[i-4,5].min - 1\n r_max = t if t < r_max\n else\n t = a[i-4,5].min\n r_min = t if t > r_min\n end\n elsif b & 15 == 0\n if b & 16 == 16\n t = a[i-4,5].max + 1\n l_min = t if t > l_min\n else\n t = a[i-4,5].max\n l_max = t if t < l_max\n end\n end\n b = b >> 1\n #p b.to_s(2)\nend\nprint \"#{l_min} #{r_max}\"\n#print \"\\nl is from #{l_min} to #{l_max}, r is from #{r_min} to #{r_max}\"\n"}], "negative_code": [], "src_uid": "3d8c881d96c998dce7059384cd882273"} {"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n n, k = ints\r\n a = ints\r\n prefix_sum = [0]\r\n (n - 1).times do |i|\r\n x = (a[i] < a[i + 1] * 2) ? 1 : 0\r\n prefix_sum << (prefix_sum[-1] + x)\r\n end\r\n \r\n puts (0 ... n - k).count { |i| prefix_sum[i + k] - prefix_sum[i] == k }\r\n end\r\n}\r\n\r\nDEBUG = false\r\nMOD = 10**9+7\r\nINF = 10**18\r\n$yesno = %w(No Yes)\r\n$YesNo = %w(No Yes)\r\n$YESNO = %w(NO YES)\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t ? 1 : 0] end\r\ndef YesNo t; puts $YesNo[t ? 1 : 0] end\r\ndef YESNO t; puts $YESNO[t ? 1 : 0] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]", "positive_code": [{"source_code": "def solve(a, k)\n b = []\n\n (0...a.size - 1).each do |i|\n if a[i] < a[i + 1] * 2\n b.push(1)\n else\n b.push(1)\n b.push(0)\n end\n end\n b.push(1)\n # p b\n\n (0...b.size).each do |i|\n b[i] = (i > 0 ? b[i] + b[i - 1] : b[0])\n end\n\n result = 0\n\n k += 1\n (b.size - k + 1).times do |l|\n v = (l > 0 ? b[l + k - 1] - b[l - 1] : b[l + k - 1])\n # p [b[l, k], v, l, l + k]\n if v == k\n result += 1\n end\n end\n\n result\nend\n\nn = gets.to_i\n\nn.times do\n size, s = gets.split.map(&:to_i)\n array = Array.new(size)\n array = gets.split.map(&:to_i)\n\n p solve(array, s)\nend\n"}, {"source_code": "def solve\r\n q = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n n = q[0]\r\n k = q[1]\r\n pref = Array.new(n)\r\n pref[0] = 0\r\n i = 1\r\n while i < n\r\n pref[i] = pref[i - 1]\r\n if 2 * a[i] > a[i - 1]\r\n pref[i] = pref[i] + 1\r\n end\r\n i = i + 1\r\n end\r\n ans = 0\r\n i = 0\r\n while i + k < n\r\n curr = pref[i + k] - pref[i]\r\n if curr == k\r\n ans = ans + 1\r\n end\r\n i = i + 1\r\n end\r\n puts ans \r\nend\r\n\r\ngets.to_i.times do\r\n solve\r\nend"}, {"source_code": "gets.to_i.times do\r\n n, k = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n\r\n l = 0\r\n r = 1\r\n cnt = 0\r\n ans = 0\r\n flag = false\r\n while l < n-k\r\n while r < n && (r <= l || cnt < k)\r\n if a[r-1] >= 2*a[r]\r\n l = r\r\n cnt = 0\r\n flag = true\r\n r += 1\r\n break\r\n else\r\n cnt += 1\r\n r += 1\r\n end\r\n end\r\n next flag = false if flag\r\n ans += 1 if cnt == k\r\n cnt -= 1\r\n l += 1\r\n end\r\n\r\n puts ans\r\nend\r\n\r\n"}, {"source_code": "gets.to_i.times do\r\n n, k = gets.split.map(&:to_i)\r\n xs = gets.split.map(&:to_i)\r\n counts = [0]\r\n xs.each_cons(2) do |a, b|\r\n if a < 2 * b\r\n counts[-1] += 1\r\n else\r\n counts << 0\r\n end\r\n end\r\n p counts.filter_map { |c| c - k + 1 if c >= k }.sum\r\nend\r\n"}], "negative_code": [], "src_uid": "b5ef56f2eb482682414c32fba83a3949"} {"source_code": "def f n\n cur = 1\n while cur <= n\n cur = cur * 2\n end\n cur /= 2\n i = cur\n cur -= 1\n while i <= n && cur >= 0\n $a[cur] = i\n $a[i] = cur\n $ans += 2 * (cur ^ i)\n i += 1\n cur -= 1\n end\n if cur >= 1 \n f cur \n end\nend\n\nn = gets.to_i\n$ans = 0\n$a = Array.new(n + 1, 0)\nf n\np $ans\nputs $a.join(' ')\n", "positive_code": [{"source_code": "h,n=[],gets.to_i+1\np n*(n-1)\nnow=2**(Math.log2(n-1).floor+1)-1\n(0..n-1).reverse_each do |i|\n if i==now/2\n now/=2\n end\nif(h[i])\n next\nend\nh[i]=now-i\nh[now-i]=i\nend\nputs h.join ' '"}, {"source_code": "h,n=[],gets.to_i+1\np n*(n-1)\nnow=2**(Math.log2(n-1).floor+1)-1\n(0..n-1).reverse_each do |i|\n if i==now/2\n now/=2\n end\nif(h[i])\n next\nend\nh[i]=now^i\nh[now^i]=i\nend\nputs h.join ' '"}], "negative_code": [], "src_uid": "ab410ffc2bfe9360abf278328b9c3055"} {"source_code": "n, m = gets.split.map(&:to_i)\narray = gets.split.map(&:to_i)\ncount = Array.new(m + 1, 0)\nlabel = []\narray.each_with_index do |x, i|\n if x <= m and count[x] < n / m\n count[x] += 1\n else\n label[i] = true\n end\nend\nchanges = 0\n(1..m).each do |i|\n while(count[i] < n / m) do\n j = label.index(true)\n array[j] = i\n label[j] = false\n count[i] += 1\n changes += 1\n end\nend\nputs \"#{n / m} #{changes}\"\narray.each { |x| print \"#{x} \" }\nputs\n", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\ngoal = n / m\ncnt = Array.new(m + 1, 0)\ncgable = []\na.each_with_index do |x, i|\n if x <= m && cnt[x] < goal\n cnt[x] += 1\n else\n cgable << i\n end\nend\nans = 0\n(1..m).each do |i|\n while cnt[i] < goal\n a[cgable.shift] = i\n cnt[i] += 1\n ans += 1\n end\nend\nputs \"#{goal} #{ans}\"\nputs a.join(' ')\n"}], "negative_code": [{"source_code": "n, m = gets.split.map(&:to_i)\narray = gets.split.map(&:to_i)\ncount, replace = Array.new(m + 1, 0), []\narray.each_with_index do |x, i|\n if x <= m and count[x] < n / m\n count[x] += 1\n else\n replace[i] = true\n end\nend\nchanges = 0\n(1..m).each do |i|\n if(count[i] < n / m)\n array[j = replace.index(true)] = i\n replace[j] = false\n count[i] += 1\n changes += 1\n end\nend\n\nputs \"#{n / m} #{changes}\"\narray.each { |x| print \"#{x} \" }\n"}], "src_uid": "0d89602f5ed765adf6807f86df1205bd"} {"source_code": "t = gets.chomp().to_i\r\n\r\nwhile t > 0\r\n n = gets.chomp().to_i\r\n a = Array.new(n + 1, 0)\r\n ind = gets.chomp.split(' ').map!{ |num| num.to_i}\r\n \r\n ans = -1\r\n \r\n ind.each do |i|\r\n a[i] += 1\r\n if a[i] == 3\r\n ans = i\r\n end\r\n end\r\n \r\n puts ans\r\n t -= 1\r\nend\r\n\r\n", "positive_code": [{"source_code": "t = gets.chomp().to_i\r\n\r\nwhile t > 0\r\n n = gets.chomp().to_i\r\n a = Array.new(n + 1, 0)\r\n ind = gets.chomp.split(' ').map!{ |num| num.to_i}\r\n \r\n ans = -1\r\n \r\n ind.each do |i|\r\n a[i] += 1\r\n if a[i] == 3\r\n ans = i\r\n end\r\n end\r\n \r\n puts ans\r\n t -= 1\r\n\r\nend\r\n\r\n"}, {"source_code": "t = gets.chomp().to_i\r\n\r\nwhile t > 0\r\n n = gets.chomp().to_i\r\n a = Array.new(n + 1, 0)\r\n ind = gets.chomp.split(' ').map!{ |num| num.to_i}\r\n \r\n ans = -1\r\n \r\n ind.each do |i|\r\n a[i] += 1\r\n if a[i] == 3\r\n ans = i\r\n end\r\n end\r\n \r\n puts ans\r\n a = nil\r\n t -= 1\r\nend\r\n\r\n"}, {"source_code": "def triple(element)\n len = element[0]\n arr = element[1]\n map = {}\n arr.each do |i|\n map.key?(i) ? map[i] += 1 : map[i] = 1\n end\n map.each do |k, v|\n if v >= 3\n return k\n end\n end\n return -1\nend\n\nt = gets.chomp.to_i\n\ninputs = []\n(0..t-1).each do |i|\n len = gets.chomp.to_i\n input = gets.chomp\n input = input.split(\" \").map(&:to_i)\n inputs.push([len, input])\nend\n\ninputs.each do |element|\n p triple(element)\nend"}, {"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n x = xs.tally.find { |x, count| count >= 3 }\r\n p x ? x[0] : -1\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n gets\r\n a = gets.split.map(&:to_i).tally.sort_by { |_k, v| -v }\r\n if a[0][1] < 3\r\n puts(-1)\r\n else\r\n puts a[0][0]\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "7d4174e3ae76de7b1389f618eb89d334"} {"source_code": "buf = gets.split(\" \")\nn = buf[0].to_i\nk = buf[1].to_i\na = [0]\nmod = 1000000007\nfor i in gets.split(\" \")\n a << i.to_i\nend\nif k == 0 then\n 1.upto(n) { |i|\n print a[i], \" \"\n }\nelse\n k -= 1\n now = 1\n sum = 0\n list = []\n 1.upto(n) { |i|\n list << now % mod\n now *= i + k\n now /= i\n }\n 1.upto(n) { |i|\n sum = 0\n i.downto(1) { |j|\n sum = sum + list[i - j] * a[j];\n sum %= mod\n }\n print sum, \" \"\n }\nend\n", "positive_code": [{"source_code": "def modinv(num)\n a = num\n x = 0; nx = 1; b = 1000000007\n while(a>0) do\n q = b/a\n x -= q*nx\n x,nx = nx, x\n b -= q*a\n a,b = b,a\n end\n return x\nend\n\nn,k = gets.chomp.split.map(&:to_i)\narray = gets.chomp.split.map(&:to_i)\nmul = [1]\na = k\nb = 1\n1.upto(array.size - 1) do |i|\n mul[i] = (mul[i-1] * a * modinv(b)) % 1000000007\n a = a + 1\n b = b + 1\nend\n0.upto(array.size-1) do |i|\n ans = 0\n 0.upto(i) do |j|\n ans += mul[i-j]*array[j]\n end\n print \"#{ans%1000000007} \"\nend\nputs"}, {"source_code": "buf = gets.split(\" \")\nn = buf[0].to_i\nk = buf[1].to_i\na = [0]\nmod = 1000000007\nfor i in gets.split(\" \")\n a << i.to_i\nend\nif k == 0 then\n 1.upto(n) { |i|\n print a[i], \" \"\n }\nelse\n k -= 1\n now = 1\n sum = 0\n list = []\n 1.upto(n) { |i|\n list << now % mod\n now *= i + k\n now /= i\n }\n 1.upto(n) { |i|\n sum = 0\n i.downto(1) { |j|\n sum = sum + list[i - j] * a[j];\n sum %= mod\n }\n print sum, \" \"\n }\nend\n"}, {"source_code": "Mod = 1000000007\nPow = \"111011100110101100101000000101\"\nLen = 30\n\nn, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\ndef inverse(n)\n c = 1\n for i in 0...Len\n c = (c*c)%Mod\n if Pow[i] == '1'\n c = (c*n)%Mod\n end\n end\n return c\nend\n\ncom = Array.new\ncom[0] = 1\ns = Array.new\ns[0] = a[0]\nfor i in 1...n\n com[i] = (com[i-1]*(k+i-1)*inverse(i))%Mod\n s[i] = 0\n for j in 0..i\n s[i] = (s[i]+a[i-j]*com[j])%Mod\n end\nend\n\ns.each {|x| print x, \" \"}"}], "negative_code": [{"source_code": "Mod = 1000000007\nPow = \"111011100110101100101000000101\"\nLen = 30\n\nn, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\ndef inverse(n)\n c = 1\n for i in 0...Len\n c = (c*c)%Mod\n if Pow[i] == '1'\n c = (c*n)%Mod\n end\n end\n return c\nend\n\ncom = Array.new\ncom[0] = 1\ns = Array.new\ns[0] = a[0]\nfor i in 1...n\n com[i] = (com[i-1]*(k+i-1)*inverse(i))%Mod\n s[i] = 0\n for j in 0..i\n s[i] += a[i-j]*com[j]\n end\nend\n\ns.each {|x| print x, \" \"}"}, {"source_code": "buf = gets.split(\" \")\nn = buf[0].to_i\nk = buf[1].to_i\na = [0]\nmod = 1000000007\nfor i in gets.split(\" \")\n a << i.to_i\nend\n#p a\nif k == 0 then\n 1.upto(n) { |i|\n print a[i], \" \"\n }\nelse\n k -= 1\n now = 1\n sum = 0\n list = []\n 1.upto(n) { |i|\n list << now % mod\n now /= i\n now *= i + k\n }\n 1.upto(n) { |i|\n sum = 0\n i.downto(1) { |j|\n sum = sum + list[i - j] * a[j];\n sum %= mod\n }\n print sum, \" \"\n }\nend\n"}, {"source_code": "def modinv(num)\n a = num\n x = 0; nx = 1; b = 1000000007\n while(a>0) do\n q = b/a\n x -= q*nx\n x,nx = nx, x\n b -= q*a\n a,b = b,a\n end\n return x\nend\n\nn,k = gets.chomp.split.map(&:to_i)\narray = gets.chomp.split.map(&:to_i)\nmul = [1]\na = k\nb = 1\n1.upto(array.size - 1) do |i|\n mul[i] = (mul[i-1] * a * modinv(b)) % 1000000007\n a = a + 1\n b = b + 1\nend\n0.upto(array.size-1) do |i|\n ans = 0\n 0.upto(i) do |j|\n ans += mul[i-j]*array[j]\n end\n print \"#{ans} \"\nend\nputs"}], "src_uid": "584f7008e27dde53037396d2459efd84"} {"source_code": "parties = Array.new(10**5+1, nil)\n\nn = gets.to_i\n\ndata = Array.new(n) { gets.chomp.split(' ').map(&:to_i) }\n\nans = 'YES'\ndata.each do |x, k|\n t = parties[k]\n if t\n if x > t + 1\n ans = 'NO'\n break\n elsif x == t + 1\n parties[k] = x\n end\n else\n if x == 0\n parties[k] = 0\n else\n ans = 'NO'\n break\n end\n end\nend\n\nputs ans\n", "positive_code": [{"source_code": "\n#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')\n\n=begin\nn,k=gets.split.map(&:to_i)\n\nif k*(n/2)>=n\n\tputs -1\nelse\n\tputs n*k\n\t(1..n).each do |ind|\n\t\t(1..k).each do |ind2|\n\t\t\tputs \"#{ind} #{(ind+ind2-1)%n+1}\"\n\t\tend\n\tend\nend\n\n\n=end\n\n\narray = [-1]* (10**5+1)\n\nn=gets.to_i\ni=0\n\nwhile iarray[k]+1\n\t\tputs 'NO'\n\t\texit 0\n\tend\n\ti+=1\nend\n\nputs 'YES'\n\n\n\n\n"}, {"source_code": "prevmax = Hash.new -1\nn = gets.to_i\nn.times do\n x,k = gets.split.map &:to_i\n d = x - prevmax[k]\n if d == 1 \n prevmax[k] += 1\n elsif d > 1\n puts \"NO\"\n exit\n end\nend\n\nputs \"YES\"\n\n"}, {"source_code": "require 'set'\nn = Integer gets\na = Array.new(10 ** 5)\ncnt = Array.new(10 ** 5, 0)\nfor i in 0...10**5\n a[i] = [].to_set\nend\nfor i in 0...n\n x, k = gets.split.map {|x| Integer x}\n k -= 1\n if !a[k].include?(x) && x != cnt[k]\n puts 'NO'\n exit\n end\n unless a[k].include?(x)\n a[k].add(cnt[k])\n cnt[k] += 1\n end\nend\nputs 'YES'"}], "negative_code": [{"source_code": "require 'set'\nn = Integer gets\na = Array.new(10 ** 5, [].to_set)\ncnt = 0\nfor i in 0...n\n x, k = gets.split.map {|x| Integer x}\n k -= 1\n if !a[k].include?(x) && x != cnt\n puts 'NO'\n exit\n end\n unless a[k].include?(x)\n a[k].add(cnt)\n cnt += 1\n end\nend\nputs 'YES'"}, {"source_code": "require 'set'\nn = Integer gets\na = Array.new(10 ** 5, [].to_set)\ncnt = Array.new(10 ** 5, 0)\nfor i in 0...n\n x, k = gets.split.map {|x| Integer x}\n k -= 1\n if !a[k].include?(x) && x != cnt[k]\n puts 'NO'\n exit\n end\n unless a[k].include?(x)\n a[k].add(cnt[k])\n cnt[k] += 1\n end\nend\nputs 'YES'"}, {"source_code": "require 'set'\nn = Integer gets\na = Array.new(10 ** 5, [].to_set)\ncnt = Array.new(10 ** 5, 0)\nfor i in 0...n\n x, k = gets.split.map {|x| Integer x}\n k -= 1\n if !a[k].include?(x) && x != cnt[k]\n puts 'NO'\n exit\n end\n unless a[k].include?(x)\n a[k].add(cnt[k])\n end\n cnt[k] += 1\nend\nputs 'YES'"}], "src_uid": "6f6f56d3106e09d51ebb3a206fa4be3c"} {"source_code": "DEBUG = false\n\nclass Board\n DELTA = [\n [ [-1, 0], [-1, 1], [0, 1] ],\n [ [0, 1], [1, 1], [1, 0] ],\n [ [1, 0], [1, -1], [0, -1] ],\n [ [0, -1], [-1, -1], [-1, 0] ]\n ]\n attr_accessor :boards, :height, :width\n\n def initialize(height, width)\n self.boards = {}\n self.height = height\n self.width = width\n end\n\n def go(row, col)\n return false if row <= 0 || col <= 0 || row > self.height || col > self.width\n self.boards[\"#{row}_#{col}\"] = true\n return true if self.end_game?(row, col)\n return false\n end\n\n def end_game?(row, col)\n if DEBUG\n puts \"----- Check step -----\"\n puts \"row = #{row}, col = #{col}\"\n end\n\n Board::DELTA.any? do |delta_set|\n\n if DEBUG\n puts \"----- Check data set -----\"\n end\n\n delta_set.all? do |delta_row, delta_col|\n if DEBUG\n puts \"#{row + delta_row} #{col + delta_col}\"\n end\n\n (row + delta_row > 0) &&\n (col + delta_col > 0) &&\n (row + delta_row <= self.height) &&\n (col + delta_col <= self.width) &&\n (self.boards[\"#{row + delta_row}_#{col + delta_col}\"] == true)\n end\n end\n end\nend\n\nheight, width, steps = gets.strip.split(' ').map &:to_i\n\nboard = Board.new(height, width)\n\nend_game_at = 0\n1.upto(steps).each do |index|\n step_row, step_col = gets.strip.split(' ').map &:to_i\n end_game = board.go(step_row, step_col)\n if end_game\n end_game_at = index\n break\n end\nend\n\nputs end_game_at\n", "positive_code": [{"source_code": "class Board\n DELTA = [\n [ [-1, 0], [-1, 1], [0, 1] ],\n [ [0, 1], [1, 1], [1, 0] ],\n [ [1, 0], [1, -1], [0, -1] ],\n [ [0, -1], [-1, -1], [-1, 0] ]\n ]\n attr_accessor :boards, :height, :width\n\n def initialize(height, width)\n self.boards = {}\n self.height = height\n self.width = width\n end\n\n def go(row, col)\n return false if row <= 0 || col <= 0 || row > self.height || col > self.width\n self.boards[row] ||= []\n self.boards[row][col] = true\n return true if self.end_game?(row, col)\n return false\n end\n\n def end_game?(row, col)\n Board::DELTA.any? do |delta_set|\n delta_set.all? do |delta_row, delta_col|\n (row + delta_row > 0) &&\n (col + delta_col > 0) &&\n (row + delta_row <= self.height) &&\n (col + delta_col <= self.width) &&\n (!self.boards[row + delta_row].nil? && self.boards[row + delta_row][col + delta_col] == true)\n end\n end\n end\nend\n\nheight, width, steps = gets.strip.split(' ').map &:to_i\n\nboard = Board.new(height, width)\n\nend_game_at = 0\n1.upto(steps).each do |index|\n step_row, step_col = gets.strip.split(' ').map &:to_i\n end_game = board.go(step_row, step_col)\n if end_game\n end_game_at = index\n break\n end\nend\n\nputs end_game_at\n"}, {"source_code": "DEBUG = false\n\nclass Board\n DELTA = [\n [ [-1, 0], [-1, 1], [0, 1] ],\n [ [0, 1], [1, 1], [1, 0] ],\n [ [1, 0], [1, -1], [0, -1] ],\n [ [0, -1], [-1, -1], [-1, 0] ]\n ]\n attr_accessor :boards, :height, :width\n\n def initialize(height, width)\n self.boards = {}\n self.height = height\n self.width = width\n end\n\n def go(row, col)\n return false if row <= 0 || col <= 0 || row > self.height || col > self.width\n self.boards[\"#{row}_#{col}\".to_sym] = true\n return true if self.end_game?(row, col)\n return false\n end\n\n def end_game?(row, col)\n if DEBUG\n puts \"----- Check step -----\"\n puts \"row = #{row}, col = #{col}\"\n end\n\n Board::DELTA.any? do |delta_set|\n\n if DEBUG\n puts \"----- Check data set -----\"\n end\n\n delta_set.all? do |delta_row, delta_col|\n if DEBUG\n puts \"#{row + delta_row} #{col + delta_col}\"\n end\n\n (row + delta_row > 0) &&\n (col + delta_col > 0) &&\n (row + delta_row <= self.height) &&\n (col + delta_col <= self.width) &&\n (self.boards[\"#{row + delta_row}_#{col + delta_col}\".to_sym] == true)\n end\n end\n end\nend\n\nheight, width, steps = gets.strip.split(' ').map &:to_i\n\nboard = Board.new(height, width)\n\nend_game_at = 0\n1.upto(steps).each do |index|\n step_row, step_col = gets.strip.split(' ').map &:to_i\n end_game = board.go(step_row, step_col)\n if end_game\n end_game_at = index\n break\n end\nend\n\nputs end_game_at\n"}, {"source_code": "DELTA = [\n [ [-1, 0], [-1, 1], [0, 1] ],\n [ [0, 1], [1, 1], [1, 0] ],\n [ [1, 0], [1, -1], [0, -1] ],\n [ [0, -1], [-1, -1], [-1, 0] ]\n]\ndef go(boards, row, col, height, width)\n return if row <= 0 || col <= 0 || row > height || col > width\n boards[row] ||= []\n boards[row][col] = true\nend\n\ndef end_game?(boards, row, col, height, width)\n DELTA.any? do |delta_set|\n delta_set.all? do |delta_row, delta_col|\n (row + delta_row > 0) &&\n (col + delta_col > 0) &&\n (row + delta_row <= height) &&\n (col + delta_col <= width) &&\n (!boards[row + delta_row].nil? && boards[row + delta_row][col + delta_col] == true)\n end\n end\nend\n\nheight, width, steps = gets.strip.split(' ').map &:to_i\nboards = []\nend_game_at = 0\n1.upto(steps).each do |index|\n step_row, step_col = gets.strip.split(' ').map &:to_i\n go(boards, step_row, step_col, height, width)\n if end_game?(boards, step_row, step_col, height, width)\n end_game_at = index\n break\n end\nend\n\nputs end_game_at\n"}, {"source_code": "DEBUG = false\n\nclass Board\n DELTA = [\n [ [-1, 0], [-1, 1], [0, 1] ],\n [ [0, 1], [1, 1], [1, 0] ],\n [ [1, 0], [1, -1], [0, -1] ],\n [ [0, -1], [-1, -1], [-1, 0] ]\n ]\n attr_accessor :boards, :height, :width\n\n def initialize(height, width)\n self.boards = []\n self.height = height\n self.width = width\n end\n\n def go(row, col)\n return false if row <= 0 || col <= 0 || row > self.height || col > self.width\n self.boards[row] ||= []\n self.boards[row][col] = true\n return true if self.end_game?(row, col)\n return false\n end\n\n def end_game?(row, col)\n if DEBUG\n puts \"----- Check step -----\"\n puts \"row = #{row}, col = #{col}\"\n end\n\n Board::DELTA.any? do |delta_set|\n\n if DEBUG\n puts \"----- Check data set -----\"\n end\n\n delta_set.all? do |delta_row, delta_col|\n if DEBUG\n puts \"#{row + delta_row} #{col + delta_col}\"\n end\n\n (row + delta_row > 0) &&\n (col + delta_col > 0) &&\n (row + delta_row <= self.height) &&\n (col + delta_col <= self.width) &&\n (!self.boards[row + delta_row].nil? && self.boards[row + delta_row][col + delta_col] == true)\n end\n end\n end\nend\n\nheight, width, steps = gets.strip.split(' ').map &:to_i\n\nboard = Board.new(height, width)\n\nend_game_at = 0\n1.upto(steps).each do |index|\n step_row, step_col = gets.strip.split(' ').map &:to_i\n end_game = board.go(step_row, step_col)\n if end_game\n end_game_at = index\n break\n end\nend\n\nputs end_game_at\n"}, {"source_code": "# File.open(\"5.txt\",\"r\") do |file|\n\ta=Array.new\n\tb=Array.new(1005)\n\tfor i in 0..1004\n\t\tb[i]=Array.new(1005,0)\n\tend\n\t# str=file.gets.to_s\n\tstr=gets.to_s\n\ta=str.split\n\tn=a[0].to_i\n\tm=a[1].to_i\n\tk=a[2].to_i\n\th=0\n\tfor r in 0..k\n\t\t# str=file.gets.to_s\n\t\tstr=gets.to_s\n\t\ta=str.split\n\t\ti=a[0].to_i\n\t\tj=a[1].to_i\n\t\tb[i][j]=1\n\t\tif b[i-1][j-1]==1 and b[i-1][j]==1 and b[i][j-1]==1 and h==0\n\t\t\th=r+1\n\t\telsif b[i-1][j+1]==1 and b[i-1][j]==1 and b[i][j+1]==1 and h==0\n\t\t\th=r+1\n\t\telsif b[i+1][j-1]==1 and b[i+1][j]==1 and b[i][j-1]==1 and h==0\n\t\t\th=r+1\n\t\telsif b[i+1][j+1]==1 and b[i+1][j]==1 and b[i][j+1]==1 and h==0\n\t\t\th=r+1\n\t\tend\n\tend\n\tif h==0\n\t\tputs 0\n\telse\n\t\tputs h\n\tend\n# end"}, {"source_code": "def checksquare(array,i,j)\n\tif array[i][j+1]==1 && array[i+1][j]==1 && array[i+1][j+1]==1\n\t\treturn true\n\tend\n\tif array[i][j-1]==1 && array[i+1][j-1]==1 && array[i+1][j]==1\n\t\treturn true\n\tend\n\tif array[i-1][j-1]==1 && array[i-1][j]==1 && array[i][j-1]==1\n\t\treturn true\n\tend\n\tif array[i-1][j]==1 && array[i-1][j+1]==1 && array[i][j+1]==1\n\t\treturn true\n\tend\n\treturn false\nend\nn,m,k=gets.split().map{|i| Integer(i)}\npos=0\nflag=1\narray=Array.new\nfor i in 0..n\n\tarray[i]=Array.new\n\tfor j in 0..m\n\t\tarray[i][j]=0\n\tend\nend\nstart=1\nwhile start<=k\n\tstart+=1\n\ti,j=gets.split().map{|h| Integer(h)}\n\tarray[i-1][j-1]=1\n\tif flag==1 && checksquare(array,i-1,j-1)==true\n\t\tpos=start-1\n\t\tflag=0\n\tend\nend\nputs pos\n"}, {"source_code": "h, w, k = gets.split.map( &:to_i )\n\nboard = Array.new( h + 2 ) { |idx| Array.new( w + 2, 0 ) }\n\n\nk.times do | t |\n\ty, x = gets.split.map( &:to_i )\n\tboard[y][x] = 1\n\n\t2.times do | i |\n\t\t2.times do | j |\n\t\t\tf = true \n\t\t\t2.times do | k |\n\t\t\t\t2.times do | l |\n\t\t\t\t\tf &= board[ y - 1 + i + k ][ x - 1 + j + l ] == 1\n\t\t\t\tend\n\t\t\tend\n\n\t\t\tif f\n\t\t\t\tputs t + 1\n\t\t\t\texit 0\n\t\t\tend\n\t\tend\n\tend\nend\n\nputs 0\n\t\n"}, {"source_code": "# http://codeforces.com/contest/508/problem/A\nn, m, k = gets.chomp.split.map(&:to_i)\nf = []\n(n + 2).times { f << Array.new(m + 2) }\n\nans = nil\nk.times do |i|\n y, x = gets.chomp.split.map(&:to_i)\n f[y][x] = 1\n\n points = [\n [f[y][x], f[y][x + 1], f[y + 1][x], f[y + 1][x + 1]],\n [f[y][x], f[y][x - 1], f[y + 1][x], f[y + 1][x - 1]],\n [f[y][x], f[y][x + 1], f[y - 1][x], f[y - 1][x + 1]],\n [f[y][x], f[y][x - 1], f[y - 1][x], f[y - 1][x - 1]]\n ]\n\n if points.find { |arr| arr.map(&:to_i).inject(0, :+) == 4 }\n ans = i + 1 if ans.nil?\n end\nend\n\nputs ans.nil? ? 0 : ans\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn, m, k = gets.split.map &:to_i\n\nans = Array.new(n + 1) { Array.new(m + 1, 0) }\n\nl = Array.new(k + 1, Array.new(2))\n\n1.upto(k){|i|\n l[i] = gets.split.map &:to_i\n}\n\n1.upto(k){|i|\n ans[l[i][0]][l[i][1]] |= 1\n ans[l[i][0]][l[i][1] - 1] |= 2\n ans[l[i][0] - 1][l[i][1]] |= 4\n ans[l[i][0] - 1][l[i][1] - 1] |= 8\n if ans[l[i][0] - 1][l[i][1] - 1] == 15 || ans[l[i][0] - 1][l[i][1]] == 15 || ans[l[i][0]][l[i][1] - 1] == 15 || ans[l[i][0]][l[i][1]] == 15 \n puts i\n exit 0\n end\n}\nputs 0"}, {"source_code": "DEBUG = false\n\nclass Board\n DELTA = [\n [ [-1, 0], [-1, 1], [0, 1] ],\n [ [0, 1], [1, 1], [1, 0] ],\n [ [1, 0], [1, -1], [0, -1] ],\n [ [0, -1], [-1, -1], [-1, 0] ]\n ]\n attr_accessor :boards, :height, :width\n\n def initialize(height, width)\n self.boards = {}\n self.height = height\n self.width = width\n end\n\n def go(row, col)\n return false if row <= 0 || col <= 0 || row > self.height || col > self.width\n self.boards[[row, col]] = true\n return true if self.end_game?(row, col)\n return false\n end\n\n def end_game?(row, col)\n if DEBUG\n puts \"----- Check step -----\"\n puts \"row = #{row}, col = #{col}\"\n end\n\n Board::DELTA.any? do |delta_set|\n\n if DEBUG\n puts \"----- Check data set -----\"\n end\n\n delta_set.all? do |delta_row, delta_col|\n if DEBUG\n puts \"#{row + delta_row} #{col + delta_col}\"\n end\n\n (row + delta_row > 0) &&\n (col + delta_col > 0) &&\n (row + delta_row <= self.height) &&\n (col + delta_col <= self.width) &&\n (self.boards[[row + delta_row, col + delta_col]] == true)\n end\n end\n end\nend\n\nheight, width, steps = gets.strip.split(' ').map &:to_i\n\nboard = Board.new(height, width)\n\nend_game_at = 0\n1.upto(steps).each do |index|\n step_row, step_col = gets.strip.split(' ').map &:to_i\n end_game = board.go(step_row, step_col)\n if end_game\n end_game_at = index\n break\n end\nend\n\nputs end_game_at\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn, m, k = gets.split.map &:to_i\n\nans = Array.new(n + 1, Array.new(m + 1, 0))\n\nl = Array.new(k + 1, Array.new(2))\n\n1.upto(k){|i|\n l[i] = gets.split.map &:to_i\n}\n\n1.upto(k){|i|\n ans[l[i][0] - 1][l[i][1] - 1] |= 1\n ans[l[i][0] - 1][l[i][1]] |= 2\n ans[l[i][0]][l[i][1] - 1] |= 4\n ans[l[i][0]][l[i][1]] |= 8\n if ans[l[i][0] - 1][l[i][1] - 1] == 15 || ans[l[i][0] - 1][l[i][1]] == 15 || ans[l[i][0]][l[i][1] - 1] == 15 || ans[l[i][0]][l[i][1]] == 15 \n puts k\n break\n end\n}"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn, m, k = gets.split.map &:to_i\n\nans = Array.new(n + 1) { Array.new(m + 1, 0) }\n\nl = Array.new(k + 1, Array.new(2))\n\n1.upto(k){|i|\n l[i] = gets.split.map &:to_i\n}\n\n1.upto(k){|i|\n ans[l[i][0]][l[i][1]] |= 1\n ans[l[i][0]][l[i][1] - 1] |= 2\n ans[l[i][0] - 1][l[i][1]] |= 4\n ans[l[i][0] - 1][l[i][1] - 1] |= 8\n if ans[l[i][0] - 1][l[i][1] - 1] == 15 || ans[l[i][0] - 1][l[i][1]] == 15 || ans[l[i][0]][l[i][1] - 1] == 15 || ans[l[i][0]][l[i][1]] == 15 \n puts i\n break\n end\n}"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn, m, k = gets.split.map &:to_i\n\nans = Array.new(n + 1) { Array.new(m + 1, 0) }\n\nl = Array.new(k + 1, Array.new(2))\n\n1.upto(k){|i|\n l[i] = gets.split.map &:to_i\n}\n\n1.upto(k){|i|\n ans[l[i][0]][l[i][1]] |= 1\n ans[l[i][0]][l[i][1] - 1] |= 2\n ans[l[i][0] - 1][l[i][1]] |= 4\n ans[l[i][0] - 1][l[i][1] - 1] |= 8\n if ans[l[i][0] - 1][l[i][1] - 1] == 15 || ans[l[i][0] - 1][l[i][1]] == 15 || ans[l[i][0]][l[i][1] - 1] == 15 || ans[l[i][0]][l[i][1]] == 15 \n puts i\n break\n end\n}\nputs 0"}, {"source_code": "DEBUG = false\n\nclass Board\n DELTA = [\n [ [-1, 0], [-1, 1], [0, 1] ],\n [ [0, 1], [1, 1], [1, 0] ],\n [ [1, 0], [1, -1], [0, -1] ],\n [ [0, -1], [-1, -1], [-1, 0] ]\n ]\n attr_accessor :boards, :height, :width\n\n def initialize(height, width)\n self.boards = {}\n self.height = height\n self.width = width\n end\n\n def go(row, col)\n return false if row <= 0 || col <= 0 || row > self.height || col > self.width\n self.boards[\"#{row}_#{col}\"] = true\n if self.end_game?(row, col)\n return true\n end\n return false\n end\n\n def end_game?(row, col)\n if DEBUG\n puts \"----- Check step -----\"\n puts \"row = #{row}, col = #{col}\"\n end\n\n Board::DELTA.any? do |delta_set|\n\n if DEBUG\n puts \"----- Check data set -----\"\n end\n\n delta_set.all? do |delta_row, delta_col|\n if DEBUG\n puts \"#{row + delta_row} #{col + delta_col}\"\n end\n\n (row + delta_row > 0) &&\n (col + delta_col > 0) &&\n (row + delta_row <= self.height) &&\n (row + delta_col <= self.width) &&\n (self.boards[\"#{row + delta_row}_#{col + delta_col}\"] == true)\n end\n end\n end\nend\n\nheight, width, steps = gets.strip.split(' ').map &:to_i\n\nboard = Board.new(height, width)\n\nend_game_at = 0\n1.upto(steps).each do |index|\n step_row, step_col = gets.strip.split(' ').map &:to_i\n end_game = board.go(step_row, step_col)\n if end_game\n end_game_at = index\n break\n end\nend\n\nputs end_game_at\n"}, {"source_code": "# File.open(\"5.txt\",\"r\") do |file|\n\ta=Array.new\n\tb=Array.new(1005)\n\tfor i in 0..1004\n\t\tb[i]=Array.new(1005,0)\n\tend\n\t# str=file.gets.to_s\n\tstr=gets.to_s\n\ta=str.split\n\tn=a[0].to_i\n\tm=a[1].to_i\n\tk=a[2].to_i\n\th=0\n\tfor r in 0..k\n\t\t# str=file.gets.to_s\n\t\tstr=gets.to_s\n\t\ta=str.split\n\t\ti=a[0].to_i\n\t\tj=a[1].to_i\n\t\tb[i][j]=1\n\t\tif b[i-1][j-1]==1 and b[i-1][j]==1 and b[i][j-1]==1\n\t\t\th=r+1\n\t\telsif b[i-1][j+1]==1 and b[i-1][j]==1 and b[i][j+1]==1\n\t\t\th=r+1\n\t\telsif b[i+1][j-1]==1 and b[i+1][j]==1 and b[i][j-1]==1\n\t\t\th=r+1\n\t\telsif b[i+1][j+1]==1 and b[i+1][j]==1 and b[i][j+1]==1\n\t\t\th=r+1\n\t\tend\n\tend\n\tif h==0\n\t\tputs 0\n\telse\n\t\tputs h\n\tend\n# end"}], "src_uid": "0dc5469831c1d5d34aa3b7b172e3237b"} {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n res = [4 * n]\n while res.size < n\n cur = res[-1]\n if cur <= 1\n break\n end\n while not(res.all? {|el| el.gcd(cur) > 1} && \n res.all? {|el| el % cur > 0 && cur % el > 0})\n cur -= 1\n end\n res << cur\n end\n puts res.join(' ')\nend ", "positive_code": [{"source_code": "# frozen_string_literal: true\n\ngets.chomp.to_i.times do |_m|\n n = gets.chomp.to_i\n (2 * n + 2).step(4 * n, 2) { |i| print i.to_s + ' ' }\n puts\nend\n"}, {"source_code": "$\\ = \" \"\ngets.to_i.times do\n n = gets.to_i\n cur = 2 * n + 2\n while cur <= 4 * n do\n print cur\n cur += 2\n end\n puts\nend"}], "negative_code": [], "src_uid": "cf4d8a5caa37def0b7c0007743139e36"} {"source_code": "gets.to_i.times do\n n=gets.to_i\n a=gets.split.map(&:to_i).sort\n ans=Float::INFINITY\n a.each_cons(3) do |i,j,k|\n ans=[ans,j-i+k-j].min\n end\n puts ans\nend\n", "positive_code": [{"source_code": "def main\n t = inp.to_i\n t.times do\n n = inp.to_i\n a = mapint(inarr).sort!\n ans = 1 << 32\n 0.upto(n - 1) do|i|\n (i + 1).upto(n - 1) do|j|\n (j + 1).upto(n - 1) do|k|\n dif = a[j] - a[i] + a[k] - a[j]\n ans = [ans, dif].min\n end\n end\n\n end\n puts ans\n\n end\n\nend\n\n# lib\ndef inp\n gets.chomp\nend\n\ndef inarr\n gets.chomp.split\nend\n\ndef mapint(lst)\n lst.map(&:to_i)\nend\n\nmain"}], "negative_code": [], "src_uid": "53ff11122a277d1eb29fe2034017fd75"} {"source_code": "n, m, x, y = gets.split.map(&:to_i)\na = Array.new(n){gets.chomp.chars.to_a}\na = a.transpose.map{|_| _.count('#')}\nw = [0] + [n * m] * m\nb = [0] + [n * m] * m\nx.upto(m) do |i|\n c = 0\n (i - 1).downto([i - y, 0].max) do |j|\n c += a[j]\n if i - j >= x\n w[i] = [w[i], b[j] + c].min\n b[i] = [b[i], w[j] + (i - j) * n - c].min\n end\n end\nend\np [w.last, b.last].min\n\n", "positive_code": [{"source_code": "n, m, x, y = gets.split.map(&:to_i)\na = Array.new(n){gets.chomp.chars.to_a}\na = a.transpose.map{|_| _.count('#')}\nw = [0] + [n * m] * m\nb = [0] + [n * m] * m\nx.upto(m) do |i|\n c = 0\n (i - 1).downto([i - y, 0].max) do |j|\n c += a[j]\n if i - j >= x\n w[i] = [w[i], b[j] + c].min\n b[i] = [b[i], w[j] + (i - j) * n - c].min\n end\n end\nend\np [w.last, b.last].min\n\n"}, {"source_code": "n, m, x, y = gets.split.map(&:to_i)\na = Array.new(n){gets.chomp.chars.to_a}\na = a.transpose.map{|_| _.count('#')}\nw = [0] + [n * m] * m\nb = [0] + [n * m] * m\nx.upto(m) do |i|\n c = 0\n (i - 1).downto([i - y, 0].max) do |j|\n c += a[j]\n if i - j >= x\n w[i] = [w[i], b[j] + c].min\n b[i] = [b[i], w[j] + (i - j) * n - c].min\n end\n end\nend\np [w.last, b.last].min\n\n"}, {"source_code": "n, m, x, y = gets.split.map(&:to_i)\na = Array.new(n){gets.chomp.chars.to_a}\na = a.transpose.map{|_| _.count('#')}\nw = [0] + [n * m] * m\nb = [0] + [n * m] * m\nx.upto(m) do |i|\n c = 0\n (i - 1).downto([i - y, 0].max) do |j|\n c += a[j]\n if i - j >= x\n w[i] = [w[i], b[j] + c].min\n b[i] = [b[i], w[j] + (i - j) * n - c].min\n end\n end\nend\np [w.last, b.last].min\n\n"}, {"source_code": "n, m, x, y = gets.split.map(&:to_i)\na = Array.new(n){gets.chomp.chars.to_a}\na = a.transpose.map{|_| _.count('#')}\nw = [0] + [n * m] * m\nb = [0] + [n * m] * m\nx.upto(m) do |i|\n c = 0\n (i - 1).downto([i - y, 0].max) do |j|\n c += a[j]\n if i - j >= x\n w[i] = [w[i], b[j] + c].min\n b[i] = [b[i], w[j] + (i - j) * n - c].min\n end\n end\nend\np [w.last, b.last].min"}, {"source_code": "n, m, x, y = gets.split.map(&:to_i)\na = Array.new(n){gets.chomp.chars.to_a}\na = a.transpose.map{|_| _.count('#')}\nw = [0] + [n * m] * m\nb = [0] + [n * m] * m\nx.upto(m) do |i|\n c = 0\n (i - 1).downto([i - y, 0].max) do |j|\n c += a[j]\n if i - j >= x\n w[i] = [w[i], b[j] + c].min\n b[i] = [b[i], w[j] + (i - j) * n - c].min\n end\n end\nend\np [w.last, b.last].min\n\n"}, {"source_code": "n, m, x, y = gets.split.map(&:to_i)\na = Array.new(n){gets.chomp.chars.to_a}\na = a.transpose.map{|_| _.count('#')}\nw = [0] + [n * m] * m\nb = [0] + [n * m] * m\nx.upto(m) do |i|\n c = 0\n (i - 1).downto([i - y, 0].max) do |j|\n c += a[j]\n if i - j >= x\n w[i] = [w[i], b[j] + c].min\n b[i] = [b[i], w[j] + (i - j) * n - c].min\n end\n end\nend\np [w.last, b.last].min\n\n"}, {"source_code": "n, m, x, y = gets.split.map(&:to_i)\na = Array.new(n){gets.chomp.chars.to_a}\na = a.transpose.map{|_| _.count('#')}\nw = [0] + [n * m] * m\nb = [0] + [n * m] * m\nx.upto(m) do |i|\n c = 0\n (i - 1).downto([i - y, 0].max) do |j|\n c += a[j]\n if i - j >= x\n w[i] = [w[i], b[j] + c].min\n b[i] = [b[i], w[j] + (i - j) * n - c].min\n end\n end\nend\np [w.last, b.last].min\n\n"}, {"source_code": "n, m, x, y = gets.split.map(&:to_i)\na = Array.new(n){gets.chomp.chars.to_a}\na = a.transpose.map{|_| _.count('#')}\nw = [0] + [n * m] * m\nb = [0] + [n * m] * m\nx.upto(m) do |i|\n c = 0\n (i - 1).downto([i - y, 0].max) do |j|\n c += a[j]\n if i - j >= x\n w[i] = [w[i], b[j] + c].min\n b[i] = [b[i], w[j] + (i - j) * n - c].min\n end\n end\nend\np [w.last, b.last].min\n"}, {"source_code": "n, m, x, y = gets.split.map(&:to_i)\na = Array.new(n){gets.chomp.chars.to_a}\na = a.transpose.map{|_| _.count('#')}\nw = [0] + [n * m] * m\nb = [0] + [n * m] * m\nx.upto(m) do |i|\n c = 0\n (i - 1).downto([i - y, 0].max) do |j|\n c += a[j]\n if i - j >= x\n w[i] = [w[i], b[j] + c].min\n b[i] = [b[i], w[j] + (i - j) * n - c].min\n end\n end\nend\np [w.last, b.last].min\n\n"}], "negative_code": [], "src_uid": "08d13e3c71040684d5a056bd1b53ef3b"} {"source_code": "n = gets.to_i\nstr = gets.chomp\nres = Array.new\nif n%2 != 0\n k = i =1\n ctr =1\n res[n/2] = str[0]\n while(k <= n/2)\n if (i == 1)\n res[n/2-k] = str[ctr]\n i = -1\n else\n res[n/2+k] = str[ctr]\n i=1\n end\n ctr +=1\n if(ctr%2 != 0)\n k = k+1\n end\n end\nelse\n k=1\n i=1\n ctr = 0\n while(k <= n/2)\n if (i == 1)\n res[n/2-k] = str[ctr]\n i = -1\n else\n res[n/2+k-1] = str[ctr]\n i=1\n end\n ctr +=1\n if(ctr%2 == 0)\n k = k+1\n end\n end\nend\n\nprint res.join(\"\")\n", "positive_code": [{"source_code": "gets\ns = gets.chomp\n\na = []\ni = 0\nif s.length % 2 != 0\n a.push(s[i])\n i += 1\nend\n\nwhile i < s.length\n a.unshift(s[i])\n a.push(s[i + 1])\n i += 2\nend\n\nputs a.join\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp.chars\n\ni = n\nans = ''\nwhile !s.empty? do\n ss = s.shift\n if i.odd?\n ans += ss\n else\n ans = ss + ans\n end\n i += 1\nend\n\nputs ans\n"}, {"source_code": "def g(ps)\n\tif ps.empty? == true then\n\t\treturn []\n\telse\n\t\tp=ps.pop\n\t\treturn (f(ps).unshift(p))\n\tend\nend\n\ndef f(ps)\n\tif ps.empty? == true then\n\t\treturn []\n\telse\n\t\tp=ps.pop\n\t\treturn (g(ps).push(p))\n\tend\nend\n\nn=gets.to_i\ns=gets.chomp\n\nps=(0..(n-1)).map{|i| i}\nps2=f(ps)\nps2.each{|i|\n\tprint s[i]\n}\nprint \"\\n\""}, {"source_code": "n = gets.to_i\nstr = gets.chomp\nres = Array.new\nif n%2 != 0\n k = i =1\n ctr =1\n res[n/2] = str[0]\n while(k <= n/2)\n if (i == 1)\n res[n/2-k] = str[ctr]\n i = -1\n else\n res[n/2+k] = str[ctr]\n i=1\n end\n ctr +=1\n if(ctr%2 != 0)\n k = k+1\n end\n end\nelse\n k=1\n i=1\n ctr = 0\n while(k <= n/2)\n if (i == 1)\n res[n/2-k] = str[ctr]\n i = -1\n else\n res[n/2+k-1] = str[ctr]\n i=1\n end\n ctr +=1\n if(ctr%2 == 0)\n k = k+1\n end\n end\nend\n\nprint res.join(\"\")\n"}, {"source_code": "n=gets.to_i\ns=gets\nr=''\nfor i in 0...n\n c=s[i]\n if (n+i).odd?\n r</) do\n depth -= 1 if $1\n puts \" \"*(2*depth)+$&\n depth += 1 unless $1\nend\n", "positive_code": [{"source_code": "l=0;gets.scan(/.*?>/){v=$&<'<0';v&&l-=2;puts\" \"*l+$&;v||l+=2}\n"}, {"source_code": "s, d = gets.chomp, 0\nwhile s.length > 0\n s.sub!(/(<.*?>)/, \"\")\n d -= 1 if $+[1] == \"/\"\n puts \" \"*d + $+\n d += 1 if $+[1] != \"/\"\nend"}, {"source_code": "l=0;gets.scan(/.*?>/){v=$&<'<0';v&&l-=2;puts\" \"*l+$&;v||l+=2}\n"}, {"source_code": "l=0\ngets.scan(/<(\\/)?[a-z]+>/){l-=2 if $1;puts \" \"*l+$&;l+=2 unless $1}"}, {"source_code": "l=0;gets.scan(/.*?>/){v=$&<'<0';v&&l-=2;puts\" \"*l+$&;v||l+=2}\n"}, {"source_code": "s = []\nt = 0\ngets.scan(/<.*?>/) do\n\tt -= 2 if $&['/']\n\ts << ' ' * t + $&\n\tt += 2 unless $&['/']\nend\nputs s * \"\\n\"\n"}, {"source_code": "str=gets\ninput=str[1..str.length-3].split(\"><\")\ndepth=0\ninput.each{|a|\n if a[0]==\"/\" then\n depth-=1\n print \" \"*depth\n else\n print \" \"*depth\n depth+=1 \n end\n print \"<\"+a+\">\\n\"\n}\n"}, {"source_code": "l=0;gets.scan(/.*?>/){v=$&<'<0';v&&l-=2;puts\" \"*l+$&;v||l+=2}\n"}, {"source_code": "l=0;gets.scan(/.*?>/){v=$&<'<0';v&&l-=2;puts\" \"*l+$&;v||l+=2}\n"}, {"source_code": "line = STDIN.gets()\n\ndef rec(arr) \n def _rec(_arr, ret, depth)\n if _arr.empty?\n return ret\n end\n \n e = _arr.shift.shift\n\n if e.start_with?('/') then\n depth -= 1\n ret << ([' '] * depth).join('') + '<' + e + '>'\n return _rec(_arr,ret,depth)\n else\n ret << ([' '] * depth).join('') + '<' + e + '>'\n return _rec(_arr,ret,depth+1)\n end\n\n end\n\n return _rec(arr, [], 0)\nend\n\nrec(line.scan(/<([a-z\\/]+)>/)).each do |l|\n puts l\nend\n"}, {"source_code": "l=0;gets.scan(/.*?>/){v=$&<'<0';v&&l-=2;puts\" \"*l+$&;v||l+=2}"}, {"source_code": "l=0;gets.scan(/.*?>/){v=$&<'<0';v&&l-=2;puts\" \"*l+$&;v||l+=2}\n"}, {"source_code": "l=0;gets.scan(/.*?>/){v=$&<'<0';v&&l-=2;puts\" \"*l+$&;v||l+=2}\n"}, {"source_code": "l=0;gets.scan(/.*?>/){v=$&<'<0';v&&l-=2;puts\" \"*l+$&;v||l+=2}"}, {"source_code": "l=0;gets.scan(/.*?>/){v=$&<'<0';v&&l-=2;puts\" \"*l+$&;v||l+=2}"}, {"source_code": "\nxml = gets.strip!\n\nde = []\nwhile xml.size > 0\n r = xml.index \">\"\n if xml[1] == \"/\"\n puts \" \" * (de.size - 1) * 2 + xml[0..r]\n de.pop\n else\n puts \" \" * (de.size) * 2 + xml[0..r]\n de << 1\n end\n xml = xml[r + 1..-1]\nend\n"}, {"source_code": "str = gets.chomp\nh = []\n\nwhile str.size > 0\n res = str.index \">\"\n if str[1] == \"/\"\n puts \" \" * (h.size - 1) *2 + str[0..res]\n h.pop\n else\n puts \" \" * (h.size) *2 + str[0..res]\n h << 1\n end\n str = str[res + 1..-1]\nend"}, {"source_code": "l=0;gets.scan(/.*?>/){v=$&<'<0';v&&l-=2;puts\" \"*l+$&;v||l+=2}\n"}], "negative_code": [{"source_code": "\nxml = gets.strip!\n\nde = []\nwhile xml.size > 0\n r = xml.index \">\"\n if xml[1] == \"/\"\n puts \" \" * (de.size - 1) * 2 + xml[0..r]\n de.pop\n else\n puts \" \" * (de.size) * 2 + xml[0..r]\n de << 1\n end\n xml = xml[r + 1..-1]\n puts xml\n puts xml.size\nend\n"}], "src_uid": "45207d5ff60bbb6897feb1d9a3f85a65"} {"source_code": "t = gets.to_i\nt.times do\n n, k = gets.split.map(&:to_i)\n puts (n >= k * k && (n - k) % 2 == 0) ? \"YES\" : \"NO\"\nend\n", "positive_code": [{"source_code": "lines = []\nfor i in 0...gets.to_i\n\tlines << gets\nend\ndef summable(n, k)\n\treturn false if n - (k ** 2) < 0\n\tif n % 2 != k % 2\n\t\treturn false\n\tend\n\treturn true\nend\ndef problem1(lines)\n\tfor i in lines\n\t\ti = i.split(\" \")\n\t\tsummable(i[0].to_i, i[1].to_i) ? (puts \"YES\") : (puts \"NO\")\n\tend\nend\nproblem1(lines)"}, {"source_code": "1.upto(gets.to_i) do\n n, k = gets.split(' ').map(&:to_i)\n\n puts (n.modulo(2) == k.modulo(2) && n >= k ** 2) ? 'YES' : 'NO'\nend\n"}, {"source_code": "def main\n t = gets.chomp.to_i\n t.times { solve }\nend\n\ndef solve\n # n = gets.chomp.to_i\n n, k = gets.chomp.split.map(&:to_i)\n # S = gets.chomp.chars\n\n if (k == 1)\n # Here, we should check the oddness of n\n if (n%2 == 1)\n print \"YES\\n\"\n return\n else\n print \"NO\\n\"\n return\n end\n end\n \n # Here, k >= 2\n # minimum k-1 sum is k_sum. [0, k-2]\n k_sum = (k-1)*(k-1)\n remain = n - k_sum\n if (remain % 2 == 1 && remain > (2*k - 3))\n print \"YES\\n\"\n else\n print \"NO\\n\"\n end\nend\n\nmain\n"}], "negative_code": [{"source_code": "t = gets.to_i\nt.times do\n n, k = gets.split.map(&:to_i)\n puts (n >= k && (n - k) % 2 == 0) ? \"YES\" : \"NO\"\nend\n"}, {"source_code": "lines = []\nfor i in 0...gets.to_i\n\tlines << gets\nend\ndef summable(n, k)\n\tfirstKSum = k ** 2\n\tif (n - k) % 2 == 1\n\t\treturn false\n\tend\n\treturn true\nend\ndef problem1(lines)\n\tfor i in lines\n\t\ti = i.split(\" \")\n\t\tsummable(i[0].to_i, i[1].to_i) ? (puts \"YES\") : (puts \"NO\")\n\tend\nend\nproblem1(lines)"}, {"source_code": "lines = []\nfor i in 0...gets.to_i\n\tlines << gets\nend\ndef summable(n, k)\n\tif k == 1\n\t\tif n % 2 == 0\n\t\t\treturn false\n\t\tend\n\t\treturn true\n\tend\n\tfor i in 2..k\n\t\treturn true if n % i == k % i\n\tend\n\treturn false\nend\ndef problem1(lines)\n\tfor i in lines\n\t\ti = i.split(\" \")\n\t\tsummable(i[0].to_i, i[1].to_i) ? (puts \"YES\") : (puts \"NO\")\n\tend\nend\nproblem1(lines)"}, {"source_code": "lines = []\nfor i in 0...gets.to_i\n\tlines << gets\nend\ndef summable(n, k)\n\tif n % 2 != k % 2\n\t\treturn false\n\tend\n\treturn true\nend\ndef problem1(lines)\n\tfor i in lines\n\t\ti = i.split(\" \")\n\t\tsummable(i[0].to_i, i[1].to_i) ? (puts \"YES\") : (puts \"NO\")\n\tend\nend\nproblem1(lines)"}], "src_uid": "a4c82fffb31bc7e42870fd84e043e815"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\n\nnow = 1\na.each { |i| now += 1 if i >= now }\nputs now - 1\n", "positive_code": [{"source_code": "len = gets.to_i\narr = gets.split(' ').map(&:to_i).sort()\nfor x in 1..len\n n = x\n while n > 0 && arr.length > 0\n n -= arr[0]\n arr.shift()\n end\n while arr.length > 0 && arr[0] <= x\n arr.shift()\n end\n if arr.length == 0\n puts \"#{x}\"\n break\n end\nend\nif arr.length > 0\n puts \"#{len}\"\nend"}], "negative_code": [{"source_code": "p`sed 1d`.split.uniq.size"}], "src_uid": "4f02ac641ab112b9d6aee222e1365c09"} {"source_code": "#!/usr/bin/ruby\n\ndef gcd(a, b)\n\treturn (b != 0) ? gcd(b, a % b) : a\nend\n\ngets\ngets.split.map(&:to_i).each do |n|\n\tputs (n * 4) / gcd(n * 4, n + 1) + 1\nend\n", "positive_code": [{"source_code": "t = gets.to_i\narray = gets.split.map(&:to_i)\narray.each do |n|\n if n % 4 == 3\n puts n+1\n elsif n % 4 == 1\n puts 2*n+1\n else\n puts 4*n+1\n end\nend"}, {"source_code": "#!/usr/bin/ruby\n\nt = $stdin.gets.to_i\nns = $stdin.gets.split.map(&:to_i)\nns.each do |n|\n g = (n+1).gcd(4*n)\n puts (4*n/g)+1\nend\n"}, {"source_code": "t=gets.to_i;gets.split.each{|v| v=v.to_i; x=(v.even?)?(v):(((v+1)%4>0)?(v/2):((v+1)/4-1)); p 4*v*(x+1)/(v+1)+1}\n"}, {"source_code": "gets;gets.split.map{ |v| v=v.to_i; if v.even?; 4*v+1; else if (v+1)%4>0; 2*v+2*v/(v+1); else; v+1; end; end; }.map{ |v| p v }\n"}, {"source_code": "gets;gets.split.map{ |v| v=v.to_i; p (v.odd? and (v+1)%4>0)?(2*v+2*v/(v+1)):(((v.even?)?4:1)*v+1) }\n"}, {"source_code": "#!/usr/bin/ruby\n\ndef gcd(a, b)\n\treturn (b != 0) ? gcd(b, a % b) : a\nend\n\ndef solve(n)\n\tputs (n * 4) / gcd(n * 4, n + 1) + 1\nend\n\ngets\ngets.split.map(&:to_i).map{ |n| solve(n) }\n"}, {"source_code": "gets\ngets.split.map { |x| x.to_i } . map { |x| x*4 / (x*4).gcd(x+1) } . each { |x| puts x+1}"}, {"source_code": "n = gets.to_i\ninput = gets.split.map(&:to_i)\n\nfor i in input\n if i%2 == 0 then puts i*4+1\n else\n if i%4 == 1\n puts i*2+1\n else\n puts i+1\n end\n end\nend\n"}, {"source_code": "def NOD(x, y)\n if x!=0\n return NOD((y%x),x)\n else \n return y\n end\nend\n\ndef NOK(x,y)\n return (x*y)/NOD(x,y)\nend\n\ntotal = gets.chomp.to_i\nline= gets.chomp\nnumbers=line.split(\" \", total)\nnumbers.each do |number|\n number=number.chomp.to_i\n number=number+1\n mod=4*number-4\n puts NOK(mod, number)/number+1\nend\n"}, {"source_code": "\"\"\"(c) gorlum0 [at] gmail.com\"\"\"\n\ndef solve(n)\n g = (4*n).gcd(n+1)\n 4*n / g + 1\nend\n\nt = STDIN.gets.to_i\nns = STDIN.gets.split.map(&:to_i)\nns.each do |n|\n puts solve(n)\nend\n"}, {"source_code": "\"\"\"(c) gorlum0 [at] gmail.com\"\"\"\n\ndef solve(n)\n g = (4*n).gcd(n+1)\n 4*n / g + 1\nend\n\ndef main\nt = gets.to_i\nns = gets.split.map(&:to_i)\nns.each do |n|\n puts solve(n)\nend\nend\n\nmain\n"}, {"source_code": "\"\"\"(c) gorlum0 [at] gmail.com\"\"\"\n\ndef solve(n)\n g = (4*n).gcd(n+1)\n 4*n / g + 1\nend\n\ndef main\n t = gets.to_i\n ns = gets.split.map(&:to_i)\n ns.each do |n|\n puts solve(n)\n end\nend\n\nif __FILE__ == $0\n main\nend\n"}, {"source_code": "\"\"\"(c) gorlum0 [at] gmail.com\"\"\"\n\ndef solve(n)\n g = (4*n).gcd(n+1)\n 4*n / g + 1\nend\n\nt = gets.to_i\nns = gets.split.map(&:to_i)\nns.each do |n|\n puts solve(n)\nend\n"}, {"source_code": "t = gets.to_i\na = gets.split(\" \").map(&:to_i)\na.each do |i|\n j = (i+1).gcd(4*i)\n p (4*i/j)+1\nend\n"}], "negative_code": [{"source_code": "n = gets.to_i\ninput = gets.split.map(&:to_i)\n\nfor i in input\n if i%2 == 0 then puts i*2+1\n else\n if i == 1 \n puts 2\n elsif i%4 == 1\n puts i*2+1\n else\n puts i+1\n end\n end\nend"}, {"source_code": "n = gets.to_i\ninput = gets.split.map(&:to_i)\n\nfor i in input\n if i%2 == 0 then puts i*4+1\n else\n if i == 1 \n puts 2\n elsif i%4 == 1\n puts i*2+1\n else\n puts i+1\n end\n end\nend"}, {"source_code": "t = gets.to_i\narray = gets.split.map(&:to_i)\narray.each do |n|\n a = 4 * n\n b = n + 1\n c = 0\n count = 0\n while c != 0\n c = a - b\n if c < 0\n c = a + c\n end\n count += 1\n end\n puts count\nend"}, {"source_code": "t = gets.to_i\narray = gets.split.map(&:to_i)\narray.each do |n|\n if n == 1\n puts 3\n elsif n == 3\n puts 4\n else\n puts n * 4 + 1\n end\nend"}, {"source_code": "t = gets.to_i\narray = gets.split.map(&:to_i)\narray.each do |n|\n puts n * 4 + 1\nend"}, {"source_code": "t = gets.to_i\narray = gets.split.map(&:to_i)\narray.each do |n|\n if n == 1\n puts 3\n else\n puts n * 4 + 1\n end\nend"}, {"source_code": "t = gets.to_i\narray = gets.split.map(&:to_i)\narray.each do |n|\n if n == 1\n puts 2\n else\n puts n * 4 + 1\n end\nend"}, {"source_code": "t = gets.to_i\narray = gets.split.map(&:to_i)\na = 0\narray.each do |n|\n a += 1\n print n * 4 + 1\n if a != t\n print \"\\n\"\n end\nend"}, {"source_code": "t=gets.to_i;gets.split.each{|v| p (v.to_i*4)+1}\n"}, {"source_code": "t=gets.to_i;gets.split.each{|v| v=v.to_i; p (((v.even?)?(4*v):((v+1)%4>0?(2*v+2*v/(v+1)):v))+1)}\n"}, {"source_code": "gets\ngets.split.map { |x| x.to_i } . map { |x| x*4 / x.gcd(x+1) } . each { |x| puts x+1}"}], "src_uid": "168dbc4994529f5407a440b0c71086da"} {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\n\nr_sum = a.reverse.each_with_object([0]) { |i, a| a << a.last + i }.reverse\n\nl_sum = Hash.new { 0 }\n\nsum = 0\nresult = 0\n\na.each_with_index do |a, i|\n sum = sum + a\n l_sum[sum] += 1\n\n next if i.zero? || i == (n - 1)\n\n result += l_sum[sum/2] - (sum.zero? ? 1 : 0) if r_sum[i+1]*2 == sum && sum.even?\nend\n\nputs result\n", "positive_code": [{"source_code": "# \n# E - Number of Ways\n# \n\nn = gets.to_i\na = gets.split.map(&:to_i)\n\ns = a.reduce(:+)\n\nif (s % 3 != 0)\n puts 0\nelse\n\n count = (1..10000000).map { |i| 0 }\n\n s /= 3\n sub_sum = 0\n\n (n - 1).downto(0) do |i|\n sub_sum += a[i]\n count[i] = 1 if sub_sum == s\n end\n\n (n - 2).downto(0) do |i|\n count[i] += count[i + 1]\n end\n\n answer = 0\n sub_sum = 0\n i = 0\n\n loop do\n break if i + 2 >= n\n\n sub_sum += a[i]\n answer += count[i + 2] if sub_sum == s\n i += 1\n end\n\n puts answer\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = STDIN.readline.to_i\narr = STDIN.readline.split.map {|s| s.to_i }\n\ntotal = arr.reduce(:+)\nif total%3 != 0\n\tputs 0\n\texit\nend\ntarget = total / 3\n\nsums = [0]\nsum = 0\narr.each {|x| sums.push(sum += x) }\n\nlow, result = 0, 0\n(1..n-2).each do |i|\n\tlow += 1 if sums[i] == target\n\tresult += low if total - sums[i+1] == target\nend\nputs result\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\nsum = 0\na.each { |x| sum += x }\nif sum % 3 != 0 \n puts 0\n exit\nend\nsum /= 3\nans, cnt, psum = 0, 0, 0\nfor x in 0...n-1 do\n psum += a[x]\n ans += cnt if psum == 2 * sum\n cnt += 1 if psum == sum\nend\nputs ans\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\ns1=x.inject(0){|sum1,e|\n\tsum1+e\n}\nif s1%3!=0 || n<3 then\n\tputs 0\nelse\n\ts3=s1/3\n\tsum=0\n\tarr=[]\n\ti=0\n\tx.each{|e|\n\t\tsum=sum+e\n\t\tif s3==sum then\n\t\t\tarr< 0\n puts ans\nelsif (an[1] < 1 || an[2] < 1) || (goal == 0 && an[1] < 3) || goal * 3 != a_sum[n - 1]\n puts 0\nelsif goal == 0\n puts (an[1] - 1) * (an[1] - 2) / 2\nelse\n puts ans\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na_sum = [a[0]]\n(n - 1).times.each{|i| a_sum[i + 1] = a_sum[i] + a[i + 1]}\ngoal = a_sum[n - 1] == 0 ? 0 : a_sum[n - 1] / 3\nan = [nil, 0, 0]\nind = 1\nans = 0\nn.times do |i|\n if ind == 1 && a_sum[i] == goal && a_sum[i] == goal * 2\n an[1] += 1\n an[2] += 1\n elsif ind == 1 && a_sum[i] == goal\n an[1] += 1\n elsif ind == 2 && a_sum[i] == goal\n p an\n ans += an[1] * an[2]\n ind = 1\n an[1] = 1\n elsif a_sum[i] == goal * 2\n ind = 2\n an[2] += 1\n end\n if i == n - 1 && ind == 2\n ans += an[1] * an[2]\n end\nend\nif ans > 0\n puts ans\nelsif (an[1] < 1 || an[2] < 1) || (goal == 0 && an[1] < 3) || goal * 3 != a_sum[n - 1]\n puts 0\nelsif goal == 0\n puts (an[1] - 1) * (an[1] - 2) / 2\nelse\n puts ans\nend\n"}], "src_uid": "2558db57229e55ffe0de0d8cf217035b"} {"source_code": "n, m = gets.split.map(&:to_i)\na = n.times.map{gets.chomp}\n\naa = Array.new(3){Array.new(n, 0)}\n[/[[:alpha:]]/, /\\d/, /\\W/].each_with_index do |reg, i|\n n.times do |j|\n t1 = a[j] =~ reg\n t2 = (a[j].reverse =~ reg) + 1 if a[j].reverse =~ reg\n aa[i][j] = [t1, t2].min || 1000\n end\nend\n\nmi = 1000\nn.times do |i|\n n.times do |j|\n next if j == i\n n.times do |k|\n next if k == i || k == j\n mi = [aa[0][i] + aa[1][j] + aa[2][k], mi].min\n end\n end\nend\np mi\n", "positive_code": [{"source_code": "TEST_MODE = ARGV[0] == 't'\n\ndef evaluate(actual, expected); actual == expected ? \"OK\" : \"**NG**\"; end\ndef tests(); yield if TEST_MODE; end\ndef to_array(val); val.kind_of?(Array) ? val : [val]; end\ndef parse_int_array(str); str.split(\" \").collect{|s| s.to_i}; end\ndef p(*arg); puts \"DEBUG: \" + arg.to_s if TEST_MODE; end\n\ndef t(input, expected_output)\n input = to_array(input)\n expected_output = to_array(expected_output)\n output = []\n solve(input, output)\n puts \"#{evaluate(output, expected_output)} : input=#{input.to_s}, expected=#{expected_output.to_s}, actual=#{output.to_s}\"\nend\n\n# actual codes here\nBIG_INT = 1000000\n\ndef find_in(str)\n return 0 if yield(str[0])\n for i in 1..str.size/2\n return i if yield(str[i]) or yield(str[str.size-i])\n end\n return BIG_INT\nend\n\ndef analyze(str)\n [\n find_in(str) { |c| 'a' <= c && c <= 'z' },\n find_in(str) { |c| '0' <= c && c <= '9' },\n find_in(str) { |c| '#*&'.index(c) != nil }\n ]\nend\n\ndef findmin(arr)\n min = BIG_INT\n (0..arr.size-1).each { |i|\n sum = arr[i][0]\n (0..arr.size-1).each { |j|\n next if i==j\n sum = arr[i][0] + arr[j][1]\n next if sum >= min\n (0..arr.size-1).each { |k|\n next if i==k || j==k\n sum = arr[i][0] + arr[j][1] + arr[k][2]\n next if sum >= min\n min = sum if sum < min\n }\n }\n }\n return min\nend\n\ndef solve(input, output)\n n, m = parse_int_array(input[0])\n arr = input[1..-1].collect {|str|\n analyze(str)\n }\n p(arr)\n output << findmin(arr).to_s\nend\n\ntests do\n # test cases\n t([\"3 4\",\n\"1**2\",\n\"a3*0\",\n\"c4**\"], \"1\")\n t([\"5 5\",\n\"#*&#*\",\n\"*a1c&\",\n\"&q2w*\",\n\"#a3c#\",\n\"*&#*&\"], \"3\")\nend\n\nputs solve(STDIN.read.split(\"\\n\"), []) unless TEST_MODE\n"}], "negative_code": [], "src_uid": "b7ff1ded73a9f130312edfe0dafc626d"} {"source_code": "n = Integer(gets.chomp)\noriginal_text = Array.new(n+1)\nfor i in 0...n\n original_text[i] = \"<3\" + gets.chomp\nend\noriginal_text[n] = \"<3\"\ntext_received = gets.chomp\npointer = 0\nfind_all = true\nfor i in 0...n+1\n for k in 0...original_text[i].length\n a = original_text[i][k]\n find = false\n for j in pointer...text_received.length\n if text_received[j] == a\n pointer = j + 1\n find = true\n break\n end\n end \n end\n if !find\n find_all = false\n break\n end\nend\n\nif find_all\n puts \"yes\"\nelse\n puts \"no\"\nend", "positive_code": [{"source_code": "n=gets.to_i\nw=['']\nn.times{w<= b\n print \"no\"\n exit\n end\n end\n j += 1\nend\n\nprint \"yes\"\n"}, {"source_code": "n=gets.to_i\nw=['']\nn.times{w<= ans.size()\n end\n index += 1\n break if index >= ans.size()\nend\nif cnt == 1 then\n puts \"yes\"\nelse\n puts \"no\"\nend"}, {"source_code": "n = gets.to_i\ns = []\nn.times do\n s << gets.chop\nend\nans = gets.chop\npattern = \"<3\"\nn.times do |i|\n pattern = pattern + s[i]\n pattern = pattern + \"<3\"\nend\nlen = pattern.size()\ninsert = false\nindex = 0\nif ans.size() - len != 1 then\n puts \"no\"\n exit\nend\nlen.times do |i|\n if ans[index] != pattern[i] then\n puts \"no\" if insert\n insert = true\n index += 1\n end\n index += 1\nend\nputs \"yes\"\n"}, {"source_code": "n = gets.to_i\ns = []\nn.times do\n s << gets.chop\nend\nans = gets.chop\npattern = \"<3\"\nn.times do |i|\n pattern = pattern + s[i]\n pattern = pattern + \"<3\"\nend\nlen = pattern.size()\ncnt = 0\nindex = 0\nlen.times do |i|\n while pattern[i] != ans[index] do\n index += 1\n cnt += 1\n break if index >= ans.size()\n end\n index += 1\n break if index >= ans.size()\nend\nif cnt == 1 then\n puts \"yes\"\nelse\n puts \"no\"\nend"}, {"source_code": "n = Integer(gets.chomp)\noriginal_text = \"\"\nfor i in 0...n\n original_text += gets.chomp\nend\ntext_received = gets.chomp\npointer = 0\ncount = \"\"\nfor i in 0...original_text.length\n a = original_text[i]\n for j in pointer...text_received.length\n if text_received[j] == a\n pointer = j + 1\n count += a\n break\n end\n end\nend\n\nif count == original_text && text_received.length > original_text.length + 2 * n\n puts \"yes\"\nelse\n puts \"no\"\nend"}, {"source_code": "n = Integer(gets.chomp)\noriginal_text = \"\"\nfor i in 0...n\n original_text += gets.chomp\nend\ntext_received = gets.chomp\npointer = 0\ncount = \"\"\nfor i in 0...original_text.length\n a = original_text[i]\n for j in pointer...text_received.length\n if text_received[j] == a\n pointer = j + 1\n count += a\n break\n end\n end\nend\n\nif count == original_text\n puts \"yes\"\nelse\n puts \"no\"\nend"}, {"source_code": "d = ('<3' + (gets.to_i.times.map{gets.split}).join('<3') + '<3').chars.to_a\nstr = gets.strip.chars.to_a\nindex = 0; get = 0;\n(d.length).times do |i|\n gets = i\n while(d[i] != str[index])\n if index == str.length-1\n break\n end\n index+=1\n end\n\n if index == str.length-1\n break\n end\nend\n(get == d.length-1)? (puts \"yes\") : (puts \"no\")\n"}, {"source_code": "d = ('<3' + (gets.to_i.times.map{gets.split}).join('<3') + '<3').chars.to_a\nstr = gets.strip.chars.to_a\nindex = 0; get = 0;\n(d.length).times do |i|\n get = i\n while(d[i] != str[index])\n if index == str.length-1\n break\n end\n index+=1\n end\n\n if index == str.length-1\n break\n end\nend\n(get == d.length-1)? (puts \"yes\") : (puts \"no\")\n"}, {"source_code": "d = gets.to_i.times.map{gets.split}\nstr = gets.strip.chars.to_a\nans = \"\"\nstr.each{|x| (ans+=x) if (x>='a' && x<='z')}\n(ans == d.join)? (puts \"yes\") : (puts \"no\")"}, {"source_code": "d = ('<3' + (gets.to_i.times.map{gets.split}).join('<3') + '<3').chars.to_a\nstr = gets.strip.chars.to_a\nindex = 0; get = 0;\n(d.length).times do |i|\n\twhile(d[i] != str[index])\n\t\tif index == str.length-1\n\t\t\tbreak\n\t\tend\n\t\tindex+=1\n\tend\n\n\tif index == str.length-1\n\t\tget = i\n\t\tbreak\n\tend\nend\n(get == d.length-1)? (puts \"yes\") : (puts \"no\")\n"}, {"source_code": "n=gets.to_i\nw=[]\nn.times{w<=w.size ? 'yes':'no'"}, {"source_code": "n=gets.to_i\nw=[]\nn.times{w< a[k]\n a.delete(k)\n else\n b.delete(k)\n end\n end\n}\n\nputs a.values.inject(0){|sum,x| sum+x} + b.values.inject(0){|sum,x| sum+x}"}], "negative_code": [], "src_uid": "fe5c302d844b0b94d030b180e017b9b2"} {"source_code": "t = gets.to_i\r\nt.times{|x|\r\n\ta = gets.split.map &:to_i\r\n\tif a.max(2) == a[0..1].sort.reverse || a.max(2) == a[2..3].sort.reverse then\r\n\t\tputs \"NO\"\r\n\telse\r\n\t\tputs \"YES\"\r\n\tend\r\n}", "positive_code": [{"source_code": "def solution(arr)\r\n\tm1, m2 = [arr[0], arr[1]].max, [arr[2], arr[3]].max\r\n\t[m1, m2].sort == arr.max(2).sort\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n\tarr = gets.chomp.split(' ').map(&:to_i)\r\n\tputs solution(arr) ? 'Yes' : 'No'\r\nend\r\n"}], "negative_code": [{"source_code": "t = gets.to_i\r\nt.times{|x|\r\n\ta = gets.split.map &:to_i\r\n\tif a.max(2) == a[0..1].sort.reverse || a.max(2) == a[2..3].sort.reverse then\r\n\t\tputs \"YES\"\r\n\telse\r\n\t\tputs \"NO\"\r\n\tend\r\n}"}], "src_uid": "cb24509580ff9b2f1a11103a0e4cdcbd"} {"source_code": "require 'set'\n#if File.exists?(\"input\")\n# $stdin = File.open(\"input\")\n# $stdout = File.open(\"output\",\"w\")\n#end\nn = gets.to_i\narr = gets.chomp.split(\" \").map(&:to_i)\n\ni=0\nans=0\nmySet = Set.new\n\nwhile(i am\n if am <= i\n am = nil\n next\n end\n}\np ans\n"}], "negative_code": [], "src_uid": "291601d6cdafa4113c1154f0dda3470d"} {"source_code": "n = gets.chomp.to_i\nn.times do \n s, t = gets.chomp.split(\" \").map(&:to_i)\n if s == t\n puts \"#{s-1}\" + \" \" + \"#{t}\"\n elsif s > t\n puts \"#{s-1}\" + \" \" + \"#{t}\"\n elsif s < t\n puts \"#{s-1}\" + \" \" + \"#{t}\"\n end\nend", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n a, b = gets.split.map(&:to_i)\n puts (a-1).to_s + \" \" + b.to_s\nend"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nn.times do \n s, t = gets.chomp.split(\" \").map(&:to_i)\n if s == t\n if s == 1\n x = 0\n y = 1\n puts \"#{x}\" + \" \" \"#{y}\"\n else\n puts \"#{s}\" + \" \" + \"#{t}\"\n end\n elsif s > t\n puts \"#{s-t}\" + \" \" + \"#{t}\"\n elsif s < t\n puts \"#{s-1}\" + \" \" + \"#{t-(s-1)}\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n s, t = gets.chomp.split(\" \").map(&:to_i)\n if s == t\n puts \"#{s-1}\" + \" \" + \"#{t}\"\n elsif s > t\n puts \"#{s-1}\" + \" \" + \"#{t}\"\n elsif s < t\n puts \"#{s-1}\" + \" \" + \"#{t-1}\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n s, t = gets.chomp.split(\" \").map(&:to_i)\n if s == t\n puts \"#{s-1}\" + \" \" + \"#{t}\"\n elsif s > t\n puts \"#{s-t}\" + \" \" + \"#{t}\"\n elsif s < t\n puts \"#{s-1}\" + \" \" + \"#{t-(s-1)}\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n s, t = gets.chomp.split(\" \").map(&:to_i)\n if s == t\n if s == 1\n x = 0\n y = 1\n puts \"#{x}\" + \" \" \"#{y}\"\n else\n puts \"#{s}\" + \" \" + \"#{t}\"\n end\n elsif s > t\n puts \"#{s-1}\" + \" \" + \"#{t}\"\n elsif s < t\n puts \"#{s}\" + \" \" + \"#{t-1}\"\n end\nend"}], "src_uid": "09625e65e62fc1c618d12969932508de"} {"source_code": "_,k,t=$<.read.split\ni=1;i+=1 while t[i..-1]!=t[0...-i]\nputs t[0,i]*k.to_i+t[i..-1]", "positive_code": [{"source_code": "n, k = gets.split.map(&:to_i)\ns = gets.chomp\nm = (n + 1..n * 2).find { |i|\n\tstr = \"?\" * i\n\tstr[...n] = s\n\tstr[-n..] = s\n\tstr[...n] == s\n} - n\nputs s + s[-m..] * (k - 1)"}, {"source_code": "N, K = gets.split.map(&:to_i)\ns = gets.chomp\nn = N\n(1...N).each do |i|\n if s[i, N-i] == s[0, N-i]\n n = i\n break\n end\nend\nans = ''\n(K-1).times do\n ans << s[0, n]\nend\nans << s\nputs ans"}, {"source_code": "n,k=gets.strip.split.map(&:to_i)\ns=gets.strip\n\nt=s.dup\nk-=1\n\nj = n-1\nwhile j>0\n break if t[(n-j)...n] == s[0...j]\n j-=1\nend\n\nk.times do\n t << s[j...n]\nend\nputs t\n"}, {"source_code": "N,K = gets.split.map(&:to_i)\nS = gets.chomp\nn = (1..N-1).map{ |k| N-k }.find{ |n| S[0...n] == S[-n..-1] } || 0\nputs S[0...N-n] * (K-1) + S"}, {"source_code": "n, k = gets.split.map(&:to_i)\nt = gets.chop\n\ni = nil\nj = 0\nloop {\n i = j if t[0..j] == t[-1-j..-1]\n j += 1\n break if j >= t.size-1\n}\n\nputs (t.size == 1 || i.nil? ? t * k : t[0..i] + t[i+1..-1] * k)\n"}, {"source_code": "#i_am_fucking_stupid\n\nv = gets.chomp.split(\" \")\na = gets.chomp\n\ns = a.size\n\nm = 0\n\nfor i in 1..s-1\n\ttemp = a[0...i]\n\tif temp == a[-i..-1]\n\t\tif m < temp.size\n\t\t\tm = temp.size\n\t\tend\n\tend\nend\n\nprint a\n(v[1].to_i - 1).times do \n\tprint(a[m..-1])\nend\n"}, {"source_code": "n, k = gets.split().map{ |x| x.to_i }\ns = gets.chomp\nlen = n - 1\nuntil len == 0 do\n if s[0, len] == s[n - len, len]\n break\n end\n len -= 1\nend\nt = s[len, n - len]\n(k - 1).times { s = s + t }\nputs s"}, {"source_code": "def ascan; gets.split.map(&:to_i); end\n\nn,k = ascan\nstr = gets.chomp\n\nif k == 1\n puts str; exit\nelsif n == 1\n puts str*k; exit\nelse\n t = nil\n 1.upto(n-1) do |i|\n if str[i..-1] == str[0..(-1-i)]\n header = str[0...i]\n footer = str[i..-1]\n puts header*k+footer; exit\n end\n end\n puts str*k; exit\nend"}, {"source_code": "nk = gets.chomp.split(\" \").map(&:to_i)\nstr = gets.chomp\nk = nk[1]\n\ndef splitof(str)\n a = str.length-2\n while a >=0\n break if str[0..a]==str[-1-a..-1]\n a-=1\n end\n\n if a==-1\n return [str,\"\"]\n else \n return [str[0..-2-a],str[-1-a..-1]]\n end\nend\n\nasd = splitof(str)\n#p asd\nk.times do\n print(asd[0])\nend\n\nprint(asd[1])\nputs\n"}, {"source_code": "#! /usr/bin/env ruby\n\nn, k=gets.split.map(&:to_i)\ns=gets.chomp\n\ndef c(s, t)\n cnt=0\n (0..(s.size-t.size)).each do |i|\n cnt+=1 if s[i...(i+t.size)]==t\n end\n # print \"#{s} #{t} #{cnt}\\n\"\n return cnt==2\nend\n\nn.times do |i|\n t=s+s[-(i+1)..-1]\n # print \"#{t} #{s} #{s[-(i+1)..-1]}\\n\"\n if c(t, s)\n puts s+s[-(i+1)..-1]*(k-1)\n break\n end\nend\n"}], "negative_code": [{"source_code": "_,k,t=$<.read.split\ni=1;i+=1 if t[i..-1]!=t[0...-i]\nputs t[0,i]*k.to_i+t[i..-1]"}, {"source_code": "n,k=gets.strip.split.map(&:to_i)\ns=gets.strip\n\nt=s.dup\nk-=1\n\nk.times do\n j = 1\n while j= t.size-1\n}\ni = -1 if t[0] != t[-1]\n\nputs (t.size == 1 ? t : i == -1 ? t * k : t[0..i] + t[i+1..-1] * k)\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nt = gets.chop\n\ni = j = 0\nloop {\n t[0..j] == t[-1-j..-1] ? i = j : nil\n j += 1\n break if j > t.size-1-j\n}\ni = -1 if t[0] != t[-1]\n\nputs (t.size == 1 ? t * k : i == -1 ? t * k : t[0..t.size-i-2] * k + t[t.size-i-1..-1])\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nt = gets.chop\n\ni = 0\nloop {\n t[0..i] == t[-1-i..-1] ? i += 1 : break\n break if i > t.size-1-i\n}\ni = -1 if t[0] != t[-1]\n\nputs (t.size == 1 ? t * k : i == -1 ? t * k : t[0..t.size-i-1] * k + t[t.size-i..-1])\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nt = gets.chop\n\ni = j = 0\nloop {\n t[0..j] == t[-1-j..-1] ? i = j : nil\n j += 1\n break if j >= t.size-1\n}\ni = -1 if t[0] != t[-1]\n\nputs (t.size == 1 ? t * k : i == -1 ? t * k : t[0..i] + t[i+1..-1] * k)\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nt = gets.chop\n\ni = 0\nloop {\n t[0..i] == t[-1-i..-1] ? i += 1 : break\n}\ni = -1 if t[0] != t[-1]\n\nputs (t.size == 1 ? t * k : i == -1 ? t * k : t[0..t.size-i-1] * k + t[t.size-i..-1])\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nt = gets.chop\n\ni = 0\nloop {\n t[0..i] == t[-1-i..-1] ? i += 1 : break\n}\ni = -1 if t[0] != t[-1]\n\nputs (i == -1 ? t * k : t[0..t.size-i-1] * k + t[t.size-i..-1])\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nt = gets.chop\n\ni = j = 0\nloop {\n t[0..j] == t[-1-j..-1] ? i = j : nil\n j += 1\n break if j > t.size-1-j\n}\ni = -1 if t[0] != t[-1]\n\nputs (t.size == 1 ? t * k : i == -1 ? t * k : t[0..t.size-i-1] + t[t.size-i..-1] * k)\n"}, {"source_code": "a = gets.chomp.split(\" \")\nst = gets.chomp\n\nj = 0\ni = 1\nwhile i < a[0].to_i\n if(st[i] == st[j])\n j += 1\n else\n if(j > 0)\n i -= 1\n end\n j = 0\n end\n i += 1\nend\n\nprint(st)\n\n(a[1].to_i-1).times do\n print(st[j...a[0].to_i])\nend\n"}, {"source_code": "a = gets.chomp.split(\" \")\nst = gets.chomp\n\nj = 0\ni = 1\nwhile i < a[0].to_i\n if(st[i] == st[j])\n j += 1\n else\n j = 0\n end\n i += 1\nend\n\nprint(st)\n\n(a[1].to_i-1).times do\n print(st[j...a[0].to_i])\nend\n"}, {"source_code": "v = gets.chomp.split(\" \")\na = gets.chomp\n\ns = (a.size / 2).ceil\nm = 0\n\nfor i in 1..s\n\ttemp = a[0...i]\n\tif temp == a[-i..-1]\n\t\tif m < temp.size\n\t\t\tm = temp.size\n\t\tend\n\tend\nend\n\nprint a\n(v[1].to_i - 1).times do \n\tprint(a[m..-1])\nend\n"}], "src_uid": "34dd4c8400ff7a67f9feb1487f2669a6"} {"source_code": "gets.to_i.times{puts gets.count(?N)==1 ? \"NO\" : \"YES\"}", "positive_code": [{"source_code": "gets.to_i.times{puts gets.count(?N)==1 ? \"NO\":\"YES\"}"}], "negative_code": [{"source_code": "gets.to_i.times{puts gets[/^E+N$/]?\"NO\":\"YES\"}"}], "src_uid": "e744184150bf55a30568060cca69de04"} {"source_code": "gets;$<.map{a=gets.split.map(&:to_i).chunk{|x|x}.map{|x|x[0]};b=a[1..-2].tally;p a.uniq.size<2?0:1+a.map{|x|b[x]||0}.min}", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n arr = gets.chomp.split(' ').map(&:to_i)\n dp = Hash.new {|_| [-1]}\n arr.each_with_index do |el, ind|\n if dp.has_key?(el)\n dp[el] << ind\n else\n dp[el] = dp[el] + [ind]\n end\n #dp[el] = dp[el] + [ind]\n end\n mn = 10 ** 10\n mn_v = -1\n dp.each do |k, v|\n tmp = 0\n st = v[0]\n (v[1..] + [n]).each do |el|\n if (el - st > 1)\n tmp += 1\n end\n st = el\n end\n mn = [mn, tmp].min\n end\n puts mn\nend"}, {"source_code": "t = gets.to_i\n\n1.upto t do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n new = a.chunk(&:itself).map(&:first)\n h = new.tally\n h[new[0]] -= 1\n h[new[-1]] -= 1\n puts h.values.min + 1\nend\n"}, {"source_code": "gets;$<.map{a=gets.split.map(&:to_i).chunk{|x|x}.map{|x|x[0]};b=a[1..-2].tally;p a.uniq.size<2?0:1+a.map{|x|b[x]||0}.min}"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n arr = gets.chomp.split(' ').map(&:to_i)\n dp = Hash.new {|_| [-1]}\n arr.each_with_index do |el, ind|\n if dp.has_key?(el)\n dp[el] << ind\n else\n dp[el] = dp[el]\n end\n end\n mn = 10 ** 10\n mn_v = -1\n dp.each do |k, v|\n tmp = 0\n st = v[0]\n (v[1..] + [n]).each do |el|\n if (el - st > 1)\n tmp += 1\n end\n st = el\n end\n mn = [mn, tmp].min\n end\n puts mn\nend"}], "src_uid": "080eb61cbc4b0ffcbab10b86918f70fe"} {"source_code": "gets\nd = []\ngets.split.each_with_index { |x, i| d[x.to_i] = i + 1 }\nputs gets.split.each.map { |x| d[x.to_i] }\n\n", "positive_code": [{"source_code": "gets\nd = []\ngets.split.each_with_index { |x, i| d[x.to_i] = i + 1 }\nputs gets.split.each.map { |x| d[x.to_i] }\n\n"}, {"source_code": "n = gets.to_i\na, b = [0, 1].map { gets.split.map(&:to_i) }\np = []\nn.times do |i|\n p[a[i] - 1] = b[i]\nend\nputs p.join(' ')\n"}, {"source_code": "gets\nd = []\ngets.split.each_with_index { |x, i| d[x.to_i] = i + 1 }\nputs gets.split.each.map { |x| d[x.to_i] }\n\n"}, {"source_code": "gets\nd = []\ngets.split.each_with_index { |x, i| d[x.to_i] = i + 1 }\nputs gets.split.each.map { |x| d[x.to_i] }\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nb = gets.split.map &:to_i\nd = Array.new(n + 1)\na.each_with_index { |x, i| d[x] = i + 1 }\nc = b.each.map { |x| d[x] }\nputs c\n"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nb = gets.split.map &:to_i\nd = []\na.each_with_index { |x, i| d[x] = i + 1 }\nc = b.each.map { |x| d[x] }\nputs c\n"}, {"source_code": "gets\nd = []\ngets.split.each_with_index { |x, i| d[x.to_i] = i + 1 }\nputs gets.split.each.map { |x| d[x.to_i] }\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /).map!{|x| x.to_i}\nb = gets.chomp.split(/ /).map!{|x| x.to_i}\nab = []\nfor i in 0..n-1\n ab << [a[i], b[i]]\nend\nab.sort!{|ab1,ab2|\n ab1[0] <=> ab2[0]\n}\nret = []\nfor i in 0..n-1\n ret << ab[i][1]\nend\nputs ret.join(\" \")\n"}, {"source_code": "gets\nd = []\ngets.split.each_with_index { |x, i| d[x.to_i] = i + 1 }\nputs gets.split.each.map { |x| d[x.to_i] }\n\n"}, {"source_code": "gets\nd = []\ngets.split.each_with_index { |x, i| d[x.to_i] = i + 1 }\nputs gets.split.each.map { |x| d[x.to_i] }\n\n"}, {"source_code": "gets\nd = []\ngets.split.each_with_index { |x, i| d[x.to_i] = i + 1 }\nputs gets.split.each.map { |x| d[x.to_i] }\n\n"}, {"source_code": "gets\nd = []\ngets.split.each_with_index { |x, i| d[x.to_i] = i + 1 }\nputs gets.split.each.map { |x| d[x.to_i] }\n\n"}], "negative_code": [], "src_uid": "a133b2c63e1025bdf13d912497f9b6a4"} {"source_code": "(1..gets.to_i).map{\r\n gets \r\n puts gets.sub(/\\s.*$/,\"\") }", "positive_code": [{"source_code": "(1..gets.to_i).map{gets\r\nputs gets.split[0]}"}, {"source_code": "(1..gets.to_i).map{\r\n gets \r\n puts gets.split[0]}\r\n"}, {"source_code": "(1..gets.to_i).map{\r\n gets \r\n puts gets.split.map(&:to_i)[0] }"}, {"source_code": "gets.to_i.times do\r\n gets\r\n puts gets.split.map(&:to_i)[0]\r\nend"}, {"source_code": "gets.to_i.times do\r\n gets.to_i\r\n puts gets.split.map(&:to_i)[0]\r\nend"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n n.times do |i|\r\n x = 0\r\n n.times do |j|\r\n x ^= a[j] if j != i\r\n end\r\n if (a[i] == x)\r\n puts a[i]\r\n break\r\n end\r\n end\r\nend"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n for i in 0..(n - 1)\r\n x = 0\r\n for j in 0..(n - 1)\r\n x ^= a[j] if j != i\r\n end\r\n if (a[i] == x)\r\n puts a[i]\r\n break\r\n end\r\n end\r\nend"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ngets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n n.times do |i|\r\n now = a[i]\r\n sum = 0\r\n n.times do |j|\r\n next if i == j\r\n sum ^= a[j]\r\n end\r\n if now == sum\r\n puts now\r\n break\r\n end\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "329ac6671e26b73ab70749ca509f5b09"} {"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n+3){Array.new(n+3){0}}\np [*1..m].find{\n x,y = gets.split.map(&:to_i)\n (y..y+2).any?{ |i|\n (x..x+2).any?{ |j|\n 9 == bins[i][j] += 1\n }\n }\n} || -1\n", "positive_code": [{"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n+3){Array.new(n+3){0}}\np [*1..m].find{\n x,y = gets.split.map(&:to_i)\n (y..y+2).any?{ |i|\n (x..x+2).any?{ |j|\n 9 == bins[i][j] += 1\n }\n }\n} || -1\n"}, {"source_code": "n, m = STDIN.readline.split.map {|s| s.to_i }\nlines = STDIN.readlines\ncount = n.times.map { n.times.map { 0 } }\ndr = [-1, -1, -1, 0, 0, 0, 1, 1, 1]\ndc = [-1, 0, 1, -1, 0, 1, -1, 0, 1]\nlines.each_with_index do |line, i|\n\tx, y = line.split.map {|s| s.to_i-1 }\n\t9.times do |j|\n\t\tr = x+dr[j]\n\t\tnext if r == -1 or r == n\n\t\tc = y+dc[j]\n\t\tnext if c == -1 or c == n\n\t\tcount[r][c] += 1\n\t\tif count[r][c] == 9\n\t\t\tputs i+1\n\t\t\texit\n\t\tend\n\tend\nend\nputs -1\n"}, {"source_code": "n, m = STDIN.readline.split.map {|s| s.to_i }\ncount = n.times.map { n.times.map { 0 } }\nresult = -1\ndr = [-1, -1, -1, 0, 0, 0, 1, 1, 1]\ndc = [-1, 0, 1, -1, 0, 1, -1, 0, 1]\nm.times do |i|\n\tx, y = STDIN.readline.split.map {|s| s.to_i-1 }\n\tnext if result != -1\n\t9.times do |j|\n\t\tr = x+dr[j]\n\t\tnext if r == -1 or r == n\n\t\tc = y+dc[j]\n\t\tnext if c == -1 or c == n\n\t\tcount[r][c] += 1\n\t\tif count[r][c] == 9\n\t\t\tresult = i+1\n\t\tend\n\tend\nend\nputs result\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n+3){Array.new(n+3){0}}\np [*1..m].find{\n x,y = gets.split.map(&:to_i)\n (y..y+2).any?{ |i|\n (x..x+2).any?{ |j|\n 9 == bins[i][j] += 1\n }\n }\n} || -1"}, {"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n+3){Array.new(n+3){0}}\np [*1..m].find{\n x,y = gets.split.map(&:to_i)\n (y..y+2).any?{ |i|\n (x..x+2).any?{ |j|\n 9 == bins[i][j] += 1\n }\n }\n} || -1\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\narray = Array.new(n){ Array.new(n) }\n\nm.times do |z|\n x,y = gets.split.map(&:to_i)\n x -= 1\n y -= 1\n array[x][y] = true\n -1.upto(1) do |i|\n if x+i <0 || x+i >n-1\n next\n end\n -1.upto(1) do |j|\n if y+j <0 || y+j >n-1\n next\n end\n if(!array[x+i][y+j])\n next\n end\n black = 0\n catch(:exit) {\n -1.upto(1) do |k|\n if x+i+k < 0 || x+i+k > n-1\n next\n end\n -1.upto(1) do |l|\n if y+j+l < 0 || y+j+l > n-1\n next\n end\n if(array[x+i+k][y+j+l])\n black += 1\n else\n throw :exit\n end\n end\n end\n if black == 9\n puts z+1\n exit\n end\n }\n end\n end\nend\nputs -1"}, {"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n+3){Array.new(n+3){0}}\np [*1..m].find{\n x,y = gets.split.map(&:to_i)\n (y..y+2).any?{ |i|\n (x..x+2).any?{ |j|\n 9 == bins[i][j] += 1\n }\n }\n} || -1"}, {"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n+3){Array.new(n+3){0}}\np [*1..m].find{\n x,y = gets.split.map(&:to_i)\n (y..y+2).any?{ |i|\n (x..x+2).any?{ |j|\n 9 == bins[i][j] += 1\n }\n }\n} || -1\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n+3){Array.new(n+3){0}}\np [*1..m].find{\n x,y = gets.split.map(&:to_i)\n (y..y+2).any?{ |i|\n (x..x+2).any?{ |j|\n 9 == bins[i][j] += 1\n }\n }\n} || -1\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n+3){Array.new(n+3){0}}\np [*1..m].find{\n x,y = gets.split.map(&:to_i)\n (y..y+2).any?{ |i|\n (x..x+2).any?{ |j|\n 9 == bins[i][j] += 1\n }\n }\n} || -1\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n+3){Array.new(n+3){0}}\np [*1..m].find{\n x,y = gets.split.map(&:to_i)\n (y..y+2).any?{ |i|\n (x..x+2).any?{ |j|\n 9 == bins[i][j] += 1\n }\n }\n} || -1\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n+3){Array.new(n+3){0}}\np [*1..m].find{\n x,y = gets.split.map(&:to_i)\n (y..y+2).any?{ |i|\n (x..x+2).any?{ |j|\n 9 == bins[i][j] += 1\n }\n }\n} || -1"}, {"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n){Array.new(n){0}}\np [*1..m].find{ |o|\n x,y = gets.split.map(&:to_i)\n y-=1; x-=1\n !->{\n if y>=2\n return if 9 == bins[y-2][x-2] += 1 if x>=2\n return if 9 == bins[y-2][x-1] += 1 if x>=1\n return if 9 == bins[y-2][x] += 1\n end\n if y>=1\n return if 9 == bins[y-1][x-2] += 1 if x>=2\n return if 9 == bins[y-1][x-1] += 1 if x>=1\n return if 9 == bins[y-1][x] += 1\n end\n return if 9 == bins[y][x-2] += 1 if x>=2\n return if 9 == bins[y][x-1] += 1 if x>=1\n return if 9 == bins[y][x] += 1\n true\n }[]\n} || -1"}, {"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n+3){Array.new(n+3){0}}\np [*1..m].find{\n x,y = gets.split.map(&:to_i)\n (y..y+2).any?{ |i|\n (x..x+2).any?{ |j|\n 9 == bins[i][j] += 1\n }\n }\n} || -1\n"}], "negative_code": [{"source_code": "n,m = gets.split.map(&:to_i)\nbins = Array.new(n-2){Array.new(n-2){0}}\n\np [*1..m].find{ |o|\n x,y = gets.split.map(&:to_i)\n ([*y-2..y]&[*0..n-3]).product(\n [*x-2..x]&[*0..n-3]).any?{ |i,j|\n 9 == bins[i][j] += 1\n }\n} || -1"}, {"source_code": "n,m = gets.split.map(&:to_i)\na = Array.new(n){[]}\n\np [*1..m].find{ |o|\n y,x = gets.split.map(&:to_i)\n a[y -= 1][x -= 1] = true\n ([*x-2..x]&[*0..n-3]).product(\n [*y-2..y]&[*0..n-3]).any?{ |t,l|\n [*t..t+2].product([*l..l+2]).\n all?{ |i,j| a[i][j] }\n }\n} || -1"}, {"source_code": "n,m = gets.split.map(&:to_i)\narray = Array.new(n){ Array.new(n) }\n\nm.times do |i|\n x,y = gets.split.map(&:to_i)\n x -= 1\n y -= 1\n array[x][y] = true\n -1.upto(1) do |i|\n if x+i <0 || x+i >n-1\n next\n end\n -1.upto(1) do |j|\n if y+j <0 || y+j >n-1\n next\n end\n if(!array[x+i][y+j])\n next\n end\n black = 0\n -1.upto(1) do |k|\n if x+i+k < 0 || x+i+k > n-1\n next\n end\n -1.upto(1) do |l|\n if y+j+l < 0 || y+j+l > n-1\n next\n end\n if(array[x+i+k][y+j+l])\n black += 1\n else\n break\n end\n end\n end\n if black == 9\n puts m-1\n exit\n end\n end\n end\nend\nputs -1"}], "src_uid": "8a4a46710104de78bdf3b9d5462f12bf"} {"source_code": "gets\nz = gets.split.map(&:to_i).min - 1\nif z==0\n puts -1\nelse\n puts 1\nend\n ", "positive_code": [{"source_code": "gets;puts gets=~/\\b1\\b/?-1:1\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}.min\nif x==1 then\n\tputs -1\nelse\n\tputs 1\nend\n\n"}, {"source_code": "gets\nnums = gets.chomp.split.map(&:to_i)\nputs nums.include?(1) ? -1 : 1"}, {"source_code": "gets\nq = gets.split.map { |c| c.to_i }.sort\nputs q[0] == 1 ? -1 : 1"}, {"source_code": "n = gets.chomp\nA = []\nnbs = gets.chomp.split(\" \")\nexist = false\nnbs.each do |x|\n exist ||= x.to_i == 1\nend\n\nif exist\n print -1\nelse\n print 1\nend"}, {"source_code": "n = gets.chomp\nA = []\nnbs = gets.chomp.split(\" \")\nexist = false\nnbs.each do |x|\n exist = true if x.to_i == 1\nend\n\nprint exist ? -1 : 1"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nar = gets.split.map(&:to_i).sort\n\nif ar.first == 1\n puts \"-1\" # 1 can express all!\nelse\n puts 1\nend"}, {"source_code": "gets;puts gets=~/\\b1\\b/?-1:1\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nputs a.include?(1) ? -1 : 1\n"}, {"source_code": "arr=gets(gets).split.map(&:to_i).sort(); puts arr[0] == 1 ? \"-1\" : \"1\"\n"}, {"source_code": "gets;puts gets=~/\\b1\\b/?-1:1"}, {"source_code": "num = gets.to_i\nnumbers=gets.split(' ')\nresult = numbers.collect{ |x| x.to_i }.sort!\nputs -1 if result[0] == 1\nputs 1 if result[0] != 1"}, {"source_code": "gets;puts gets=~/\\b1\\b/?-1:1\n"}, {"source_code": "gets\nputs gets=~/\\b1\\b/?-1:1"}, {"source_code": "gets\nputs gets.split.include?('1')?-1:1"}, {"source_code": "gets;puts gets=~/\\b1\\b/?-1:1\n"}, {"source_code": "banknoteNum = gets.chomp.to_i\nbanknotes = gets.chomp.split(' ').map {|item| item.to_i}\n\nif banknotes.include?(1)\n\tputs \"-1\"\n\texit\nelse\n\tputs \"1\"\n\texit\nend\n\nbanknotes.sort!\n\nnowIndex = 0\n\nuntil banknotes.length - 1 == nowIndex\n\tif banknotes[nowIndex + 1] - banknotes[nowIndex] > 1\n\t\tputs banknotes[nowIndex] + 1\n\t\texit\n\tend\n\n \tnowIndex += 1\n end "}, {"source_code": "#!/usr/bin/ruby\ngets\nm=gets.split.map(&:to_i).min-1\np m==0 ? -1 : 1"}, {"source_code": "n = gets.to_i\ncurrency = gets.split(' ')\ncurrency.map!{|c| c.to_i}\ncurrency.sort!\nif currency.first == 1\n puts -1\nelse\n puts 1\nend"}, {"source_code": "gets;puts gets=~/\\b1\\b/?-1:1\n"}, {"source_code": "# http://codeforces.com/contest/560/problem/A\n# A. Currency System in Geraldion\ndef unfortunate_value(values)\n return nil if values.include?(1)\n\n values.sort!\n (1..(10**6)).to_a.find do |n|\n values.all? { |v| n % v != 0 }\n end\nend\n\nn = gets.chomp.to_i\nvalues = gets.chomp.split.map(&:to_i)\n\nans = unfortunate_value(values)\nputs ans.nil? ? -1 : ans\n"}, {"source_code": "n = gets.to_i\ninput = gets.split(' ')\nnums = (input.collect { |x| x.to_i }).sort!\n\nif nums[0] == 1\n\tputs -1 \nelse\n\tputs 1\nend\n"}, {"source_code": "gets;puts gets=~/\\b1\\b/?-1:1\n"}, {"source_code": "gets;puts gets=~/\\b1\\b/?-1:1"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nputs a[0] == 1 ? -1 : 1"}, {"source_code": "gets;puts gets=~/\\b1\\b/?-1:1\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\ngets\nm=gets.split.map(&:to_i).min-1\np m==0 ? -1 : m"}, {"source_code": "# http://codeforces.com/contest/560/problem/A\n# A. Currency System in Geraldion\ndef unfortunate_value(values)\n return nil if values.include?(1)\n\n values.sort!\n (1..(10**6)).to_a.select do |n|\n return true if values.all? { |v| n % v != 0 }\n end.first\nend\n\nn = gets.chomp.to_i\nvalues = gets.chomp.split.map(&:to_i)\n\nans = unfortunate_value(values)\nputs ans.nil? ? -1 : ans\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nar = gets.split.map(&:to_i).sort\ntotal_sum = ar.reduce(:+)\ni = 0\nuf_num = -1\nfor j in ar\n if j - i > 1\n uf_num = i\n break\n else\n i = j\n end\nend\n\nif uf_num == -1\n puts \"-1\"\nelse\n puts total_sum - 1\nend"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nar = gets.split.map(&:to_i).sort\n\nif ar.first == 1\n puts \"-1\" # 1 can express all!\nelse\n puts ar.first - 1\nend"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nar = gets.split.map(&:to_i).sort\ntotal_sum = ar.reduce(:+)\ni = ar.first\nuf_num = -1\nfor j in ar[1..-1]\n if j - i > 1\n uf_num = i + 1\n break\n else\n i = j\n end\nend\n\nif uf_num == -1\n puts \"-1\"\nelse\n puts total_sum - (uf_num - 1) + uf_num\nend"}, {"source_code": "arr=gets.split.map(&:to_i).sort(); puts arr[0] == 1 ? \"-1\" : \"1\"\n"}], "src_uid": "df94080c5b0b046af2397cafc02b5bdc"} {"source_code": "H, W = gets.split.map(&:to_i)\npic = []\nH.times do |i|\n pic[i] = gets.chomp\nend\n\ndown = Array.new(H+1){Array.new(W+1, -1)}\nup = Array.new(H+1){Array.new(W+1, -1)}\nleft = Array.new(H+1){Array.new(W+1, -1)}\nright = Array.new(H+1){Array.new(W+1, -1)}\n\nH.times do |i|\n W.times do |j|\n up[i][j] = (pic[i][j] == '*' ? up[i-1][j] + 1 : -1)\n left[i][j] = (pic[i][j] == '*' ? left[i][j-1] + 1 : -1)\n end\nend\n(H-1).downto(0) do |i|\n (W-1).downto(0) do |j|\n down[i][j] = pic[i][j] == '*' ? down[i+1][j] + 1 : -1\n right[i][j] = pic[i][j] == '*' ? right[i][j+1] + 1 : -1\n end\nend\n\nans = []\nH.times do |i|\n W.times do |j|\n num = [down[i][j], left[i][j], up[i][j], right[i][j]].min\n if num > 0\n pic[i][j] = '.'\n (1..num).each do |k|\n pic[i-k][j] = '.'\n pic[i+k][j] = '.'\n pic[i][j-k] = '.'\n pic[i][j+k] = '.'\n end\n ans.push([i+1, j+1, num])\n end\n end\nend\n\nif pic.all?{|row| row.count('*') == 0}\n puts ans.length\n ans.each do |arr|\n puts arr.join(' ')\n end\nelse\n puts -1\nend", "positive_code": [{"source_code": "\ndef make_hash(n, m, boardstr)\n {}.tap do |h|\n (0...n).each do |i|\n (0...m).each do |j|\n h[[i,j]] = true if boardstr[i][j] == ?*\n end\n end\n end\nend\n\nrequire 'set'\n\ndef move(point, y, x)\n i, j = point\n [i + y, j + x]\nend\n\ndef get_star(board, i, j)\n p, q = i, j\n\n points = Set.new\n\n up = [p, q]\n down = [p, q]\n left = [p, q]\n right = [p, q]\n\n size = -1\n\n while board[up] && board[down] && board[left] && board[right]\n points << up\n points << down\n points << left\n points << right\n\n size += 1\n\n up = move(up, -1, 0)\n down = move(down, 1, 0)\n left = move(left, 0, -1)\n right = move(right, 0, 1)\n end\n\n [points, size] if size > 0\n\nend\n\n\ndef solution\n n, m = read_ints\n\n boardstr = []\n\n n.times do\n boardstr << read_string\n end\n\n board = make_hash(n, m, boardstr)\n lit = Set.new(board.keys)\n\n stars = []\n\n (1...(n-1)).each do |i|\n (1...(m-1)).each do |j|\n star_points, star_size = get_star(board, i, j)\n next unless star_points\n\n stars << [i+1, j+1, star_size]\n lit.subtract(star_points)\n\n end\n end\n\n if lit.empty?\n puts stars.size\n stars.each do |s|\n puts s.join(' ')\n end\n else\n puts(-1)\n end\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}], "negative_code": [], "src_uid": "59d4c66892fa3157d1163225a550a368"} {"source_code": "n = gets.to_i\na = gets.split(' ').map { |c| c.to_i }\n\nif n == 1\n puts 1\n exit\nend\n\nleftright = Array.new(n, 0)\nrightleft = Array.new(n, 0)\nleftright[0] = rightleft[n - 1] = 1\n\n(n - 1).times do |i|\n pos = i + 1\n leftright[pos] = 1 + (a[pos] > a[pos - 1] ? leftright[pos - 1] : 0)\nend\n(n - 1).times do |i|\n pos = n - i - 2\n rightleft[pos] = 1 + (a[pos] < a[pos + 1] ? rightleft[pos + 1] : 0)\nend\n\nbest = 1 + [rightleft[1], leftright[n - 2]].max\n(n - 2).times do |i|\n pos = i + 1\n best = [best, leftright[pos - 1] + 1].max\n best = [best, rightleft[pos + 1] + 1].max\n if a[pos - 1] + 2 <= a[pos + 1]\n best = [best, leftright[pos - 1] + 1 + rightleft[pos + 1]].max\n end\nend\n\nputs best", "positive_code": [{"source_code": "n = gets.to_i\na = gets.strip.split.map(&:to_i)\n\nleft, right = Array.new(n), Array.new(n)\n\nbest = n <= 2 ? n : 1\nleft[0] = 1\n(1..(n - 1)).each do |i|\n left[i] = a[i] > a[i - 1] ? left[i - 1] + 1 : 1\nend\n\nright[n - 1] = 1\n(0..(n - 2)).to_a.reverse.each do |i|\n right[i] = a[i] < a[i + 1] ? right[i + 1] + 1 : 1\nend\n\n(1..(n - 2)).each do |i|\n best = [best, left[i - 1] + right[i + 1] + 1].max if a[i - 1] + 1 < a[i + 1]\n best = [best, left[i] + 1].max\n best = [best, right[i] + 1].max\nend\n\nputs best\n"}, {"source_code": "n = gets.to_i\na = gets.strip.split.map(&:to_i)\n\nleft, right = Array.new(n), Array.new(n)\n\nbest = n <= 2 ? n : 1\nleft[0] = 1\n(1..(n - 1)).each do |i|\n left[i] = a[i] > a[i - 1] ? left[i - 1] + 1 : 1\n # puts best\nend\n\nright[n - 1] = 1\n(0..(n - 2)).to_a.reverse.each do |i|\n right[i] = a[i] < a[i + 1] ? right[i + 1] + 1 : 1\n # puts best\nend\n\n(1..(n - 2)).each do |i|\n best = [best, left[i - 1] + right[i + 1] + 1].max if a[i - 1] + 1 < a[i + 1]\n best = [best, left[i] + 1].max\n best = [best, right[i] + 1].max\n # puts best\nend\n\n# puts left.join(\" \")\n# puts right.join(\" \")\nputs best\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nb=[0]*n\nc=[0]*n\nn.times do |i|\n b[i]=i>0&&a[i-1]0&&a[n-i]>a[n-1-i]?c[n-i]+1:1\nend\nr=0\nn.times do |i|\n r=b[i-1]+c[i+1]+1if i>0&&i1&&r a[i-1]\nend\n\n(n - 2).downto( 0 ).each do |i|\n\tr[i] = r[i+1] + 1 if a[i] < a[i+1]\nend\n\nans = r[1] + 1\n( 1..n-2 ).each do |i|\n\tans = [ans, l[i-1] + r[i+1] + 1].max if a[i+1] - a[i-1] >= 2\n\tans = [ans, l[i-1] + 1].max\n\tans = [ans, r[i+1] + 1].max\nend\nans = [ans, l[-2] + 1].max\nputs ans"}, {"source_code": "\n# Calculates the derivative\ndef derivative(ar) \n return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}\n # each_cons returns an iterator over pairs of elements\n # clone to get over the dumb ruby passig by reference\nend\n\n# Returns indices of non-increaseing points\ndef loc(ar)\n # Obtain the derivative of the input\n der = derivative(ar)\n return der.each_index.select{|i| der[i] <= 0} \n # each_index returns an itetrator over indices\n # select returns elements that match condition\nend\n\n# Read Input\nn = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\n\n# Obtain the locations of non-increasing points\nnegloc = loc(a).unshift(0).push(n)\n\n# Create an array to store lengths of segments\nseqlength = [negloc[1]]\n\n# Loop over locations of non-increasing points\nfor i in 1..(negloc.length - 1) do\n j = negloc[i]\n if i == negloc.length - 1\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n elsif j + 1 < a.length && a[j-1] + 1 < a[j+1]\n seqlength[i] = negloc[i+1] - negloc[i-1]\n elsif j - 2 > -1 && a[j-2] + 1 < a[j]\n seqlength[i] = negloc[i+1] - negloc[i-1]\n else\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n end\nend\n\nputs [seqlength.max,n].min\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\na = gets.split.map{ |i| i.to_i }\nr = [1] * n\nl = r.clone\n\n( 1..n-1 ).each do |i|\n\tl[i] = l[i-1] + 1 if a[i] > a[i-1]\nend\n\n(n - 2).downto( 0 ).each do |i|\n\tr[i] = r[i+1] + 1 if a[i] < a[i+1]\nend\n\nans = r[0]\n( 1..n-2 ).each do |i|\n\tans = [ans, l[i-1] + r[i+1] + 1].max if a[i+1] - a[i-1] >= 2\nend\nans = [ans, l[-1]].max\nputs ans"}, {"source_code": "n = gets.chomp.to_i\na = gets.split.map{ |i| i.to_i }\nr = [1] * n\nl = r.clone\n\n( 1..n-1 ).each do |i|\n\tl[i] = l[i-1] + 1 if a[i] > a[i-1]\nend\n\n(n - 2).downto( 0 ).each do |i|\n\tr[i] = r[i+1] + 1 if a[i] < a[i+1]\nend\n\nans = r[0]\n( 1..n-2 ).each do |i|\n\tans = [ans, l[i-1] + r[i+1] + 1].max if a[i+1] - a[i-1] >= 2\n\tans = [ans, l[i-1] + 1].max\n\tans = [ans, r[i+1] + 1].max\nend\nans = [ans, l[-1]].max\nputs ans"}, {"source_code": "n = gets.chomp.to_i\na = gets.split.map{ |i| i.to_i }\nl = 0\nr = 1\nans = 1\nchanges = -1\nwhile l < n && r < n do\n\tif a[r] <= a[r - 1]\n\t\tif changes < 0\n\t\t\tif l == r - 1\n\t\t\t\ta[r-1] = a[r] - 1\n\t\t\t\tchanges = l\n\t\t\telse\n\t\t\t\ta[r] = a[r-1] + 1\n\t\t\t\tchanges = r\n\t\t\tend\n\t\telse\n\t\t\tl = changes + 1\n\t\t\tchanges = -1\n\t\tend\n\tend\n\tans = [ans, r - l + 1].max\n\tr += 1\nend\nputs ans"}, {"source_code": "\nn = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\n\nlongest_so_far = 0\nlength = 1\nhicat = 0\ni = 0\n\nwhile i < n - 1\n if a[i] >= a[i+1]\n lognest_so_far = length if length > longest_so_far\n length = length - hicat\n hicat = length\n end\n length = length + 1\n i = i + 1\nend\n\nlognest_so_far = length if length > longest_so_far\n\nputs lognest_so_far"}, {"source_code": "def derivative(ar) \n # Each cons returns an iterator over pairs of elements\n return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}\nend\n\ndef loc(ar, v)\n return ar.each_index.select{|i| ar[i] <= v} \nend\n\n# Read Input\nn = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\n\nif (n <= 2)\n puts n\n exit\nend\n\n# Obtain the derivative of the input\nder = derivative(a)\n\n# Obtain the locations of negatives\nnegloc = loc(der,0).unshift(0).push(n)\n\nseqlength = []\n\nfor i in 0..(negloc.length - 1) do\n j = negloc[i]\n\n if i == 0\n seqlength[i] = negloc[1]\n elsif i == negloc.length - 1\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n elsif j+1 < a.length && a[j-1] + 1 < a[j+1]\n seqlength[i] = negloc[i+1] - negloc[i-1]\n else\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n end\n\nend\n\nputs [seqlength.max,n].min\n"}, {"source_code": "\ndef derivative(ar) \n # Each cons returns an iterator over pairs of elements\n return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}\nend\n\ndef loc(ar, v)\n return ar.each_index.select{|i| ar[i] <= v} \nend\n\n# Read Input\nn = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\n\nif (n <= 2)\n puts n\n exit\nend\n\n\n# Obtain the derivative of the input\nder = derivative(a)\n\n# Obtain the locations of negatives\nnegloc = loc(der,0).unshift(0).push(n)\n\nseqlength = []\n\nfor i in 0..(negloc.length - 1) do\n j = negloc[i]\n\n if i == 0\n seqlength[i] = negloc[1]\n elsif i == negloc.length - 1\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n elsif j+1 < a.length && a[j-1] + 1 < a[j+1]\n seqlength[i] = negloc[i+1] - negloc[i-1]\n else\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n end\n\nend\n\nputs seqlength.max\n\n\n"}, {"source_code": "\ndef derivative(ar) \n # Each cons returns an iterator over pairs of elements\n return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}\nend\n\ndef loc(ar, v)\n return ar.each_index.select{|i| ar[i] <= v} \nend\n\n# Read Input\nn = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\n\n# Obtain the derivative of the input\nder = derivative(a)\n\n# Obtain the locations of negatives\nnegloc = loc(der,0).unshift(0).push(n)\n\nseqlength = []\n\nfor i in 0..(negloc.length - 1) do\n j = negloc[i]\n\n if i == 0\n seqlength[i] = negloc[1]\n elsif i == negloc.length - 1\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n elsif j+1 < a.length && a[j-1] + 1 < a[j+1]\n seqlength[i] = negloc[i+1] - negloc[i-1]\n else\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n end\n\nend\nputs seqlength.max\n\n\n"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\n\nlongest_so_far = 0\nlength = 1\nhicat = 0\ni = 0\n\nwhile i < n - 1\n if a[i] >= a[i+1]\n longest_so_far = length if length > longest_so_far\n length = length - hicat\n hicat = length\n end\n length = length + 1\n i = i + 1\nend\n\nlongest_so_far = length if length > longest_so_far\n\nputs longest_so_far"}, {"source_code": "\ndef derivative(ar) \n # Each cons returns an iterator over pairs of elements\n return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}\nend\n\ndef loc(ar, v)\n return ar.each_index.select{|i| ar[i] <= v} \nend\n\n# Read Input\nn = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\n\nif (n <= 2)\n puts n\n exit\nend\n\n\n# Obtain the derivative of the input\nder = derivative(a)\n\n# Obtain the locations of negatives\nnegloc = loc(der,0).unshift(0).push(n)\n\nseqlength = []\n\nfor i in 0..(negloc.length - 1) do\n j = negloc[i]\n\n if i == 0\n seqlength[i] = negloc[1]\n elsif i == negloc.length - 1\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n elsif j+1 < a.length && a[j-1] + 1 < a[j+1]\n seqlength[i] = negloc[i+1] - negloc[i-1]\n else\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n end\n\nend\n\nputs [seqlength.max,n].min\n\n\n"}, {"source_code": "\nn = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\n\nputs n\nputs a\n\nlongest_so_far = 0\nlength = 1\nhicat = 0\ni = 0\n\nwhile i < n - 1\n if a[i] >= a[i+1]\n lognest_so_far = length if length > longest_so_far\n length = length - hicat\n hicat = length\n end\n length = length + 1\n i = i + 1\nend\n\nlognest_so_far = length if length > longest_so_far\n\nputs lognest_so_far"}, {"source_code": "\ndef derivative(ar) \n # Each cons returns an iterator over pairs of elements\n return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}\nend\n\ndef loc(ar, v)\n return ar.each_index.select{|i| ar[i] <= v} \nend\n\n# Read Input\nn = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\n\n# Obtain the derivative of the input\nder = derivative(a)\n\n# Obtain the locations of negatives\nnegloc = loc(der,0).unshift(0).push(n)\n\nseqlength = []\n\nfor i in 0..(negloc.length - 1) do\n j = negloc[i]\n\n if i == 0\n seqlength[i] = negloc[1]\n elsif i == negloc.length - 1\n seqlength[i] = negloc[i] - negloc[i-1]\n elsif j+1 < a.length && a[j-1] + 1 < a[j+1]\n seqlength[i] = negloc[i+1] - negloc[i-1]\n else\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n end\n\nend\n\nputs seqlength.max\n\n\n"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\n\nlongest_so_far = 0\nlength = 1\nhicat = 0\ni = 0\n\nwhile i < n - 1\n if a[i] >= a[i+1]\n longest_so_far = length if length > longest_so_far\n length = length - hicat\n hicat = length\n end\n length = length + 1\n i = i + 1\nend\n\nlognest_so_far = length if length > longest_so_far\n\nputs longest_so_far"}, {"source_code": "\ndef derivative(ar) \n # Each cons returns an iterator over pairs of elements\n return ar.clone().unshift(0).each_cons(2).map{|x, y| y - x}\nend\n\ndef loc(ar, v)\n return ar.each_index.select{|i| ar[i] <= v} \nend\n\n# Read Input\nn = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\n\nif (n <= 2)\n return n\n exit\nend\n\n\n# Obtain the derivative of the input\nder = derivative(a)\n\n# Obtain the locations of negatives\nnegloc = loc(der,0).unshift(0).push(n)\n\nseqlength = []\n\nfor i in 0..(negloc.length - 1) do\n print \"Now at: \"\n puts negloc[i]\n\n j = negloc[i]\n\n if i == 0\n seqlength[i] = negloc[1]\n elsif i == negloc.length - 1\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n elsif j+1 < a.length && a[j-1] + 1 < a[j+1]\n seqlength[i] = negloc[i+1] - negloc[i-1]\n else\n seqlength[i] = negloc[i] - negloc[i-1] + 1\n end\n\nend\n\nputs seqlength.max\n\n\n"}, {"source_code": "n = gets.to_i\na = gets.strip.split.map(&:to_i)\n\nleft, right = Array.new(n), Array.new(n)\n\nleft[0] = 1\n(1..(n - 1)).each do |i|\n left[i] = a[i] > a[i - 1] ? left[i - 1] + 1 : 1\nend\n\nright[n - 1] = 1\n(0..(n - 2)).to_a.reverse.each do |i|\n right[i] = a[i] < a[i + 1] ? right[i + 1] + 1 : 1\nend\n\nbest = 1\n(1..(n - 2)).each do |i|\n best = [best, left[i] + right[i] + 1].max if a[i - 1] + 1 < a[i + 1]\nend\n\nputs best\n"}, {"source_code": "n = gets.to_i\na = gets.strip.split.map(&:to_i)\n\nleft, right = Array.new(n), Array.new(n)\n\nleft[0] = 1\n(1..(n - 1)).each do |i|\n left[i] = a[i] > a[i - 1] ? left[i - 1] + 1 : 1\nend\n\nright[n - 1] = 1\n(0..(n - 2)).to_a.reverse.each do |i|\n right[i] = a[i] < a[i + 1] ? right[i + 1] + 1 : 1\nend\n\nbest = 1\n(1..(n - 2)).each do |i|\n best = [best, left[i - 1] + right[i + 1] + 1].max if a[i - 1] + 1 < a[i + 1]\n best = [best, left[i] + 1, right[i] + 1].max\n # puts best\nend\n\n# puts left.join(\" \")\n# puts right.join(\" \")\nputs best\n"}, {"source_code": "n = gets.to_i\na = gets.strip.split.map(&:to_i)\n\nleft, right = Array.new(n), Array.new(n)\n\nbest = 1\nleft[0] = 1\n(1..(n - 1)).each do |i|\n left[i] = a[i] > a[i - 1] ? left[i - 1] + 1 : 1\n best = [best, left[i] + 1].max\nend\n\nright[n - 1] = 1\n(0..(n - 2)).to_a.reverse.each do |i|\n right[i] = a[i] < a[i + 1] ? right[i + 1] + 1 : 1\n best = [best, right[i] + 1].max\nend\n\n(1..(n - 2)).each do |i|\n best = [best, left[i - 1] + right[i + 1] + 1].max if a[i - 1] + 1 < a[i + 1]\nend\n\nputs best\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |c| c.to_i }\nleftright = Array.new(n, 0)\nrightleft = Array.new(n, 0)\nleftright[0] = rightleft[n - 1] = 1\n\n(n-1).times do |i|\n pos = i + 1\n leftright[pos] = 1\n if a[pos] > a[pos - 1]\n leftright[pos] += 1\n end\nend\n\n(n-1).times do |i|\n pos = n - 2 - i\n rightleft[pos] = 1\n if a[pos] < a[pos + 1]\n rightleft[pos] += 1\n end\nend\n\nbest = [1 + rightleft[1], 1 + leftright[n - 2]].max\na.each_with_index do |val, i|\n next if i == 0 || i == n - 1 || a[i - 1] + 2 > a[i + 1]\n best = [best, leftright[i - 1] + 1 + rightleft[i + 1]].max\nend\n\nputs best"}], "src_uid": "9e0d271b9bada1364dfcb47297549652"} {"source_code": "MOD = 10 ** 9 + 7\r\ndef gs; gets.chomp; end\r\ndef gi; gets.to_i; end\r\ndef gli; gets.split.map(&:to_i); end\r\ndef cyesno(x); puts x ? :Yes : :No; end\r\ndef uyesno(x); puts x ? :YES : :NO; end\r\ndef array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end\r\n\r\ndef solve\r\n n = gi\r\n a = gli\r\n b = gli\r\n a_s = a.sum\r\n b_s = 0\r\n mn = [a_s, b.sum].max\r\n for i in (0..n-1)\r\n a_s -= a[i]\r\n tmp = [a_s, b_s].max\r\n mn = tmp if tmp < mn\r\n b_s += b[i]\r\n end\r\n puts mn\r\nend\r\n\r\ndef main\r\n gi.times { solve }\r\nend\r\n\r\nmain\r\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\r\n\r\ndef arline\r\n gets.chomp.split.map(&:to_i)\r\nend\r\n\r\ndef pfr(ar)\r\n res = [0]\r\n ar.each do |x| res.append(res[-1] + x) end\r\n res\r\nend\r\n\r\nclass Grid\r\n def initialize(ar)\r\n @pfr = ar.map{|x| pfr(x)}\r\n @n = ar[0].length\r\n end\r\n def score(x)\r\n [@pfr[1][x-1], @pfr[0][@n] - @pfr[0][x]].max\r\n end\r\nend\r\n\r\ngets.chomp.to_i.times do\r\n n = gets.chomp.to_i\r\n a = (1..2).map{arline}\r\n g = Grid.new(a)\r\n puts (1..n).map{|x| g.score(x) }.min\r\nend\r\n"}], "negative_code": [{"source_code": "MOD = 10 ** 9 + 7\r\ndef gs; gets.chomp; end\r\ndef gi; gets.to_i; end\r\ndef gli; gets.split.map(&:to_i); end\r\ndef cyesno(x); puts x ? :Yes : :No; end\r\ndef uyesno(x); puts x ? :YES : :NO; end\r\ndef array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end\r\n\r\ndef solve\r\n n = gi\r\n a = gli\r\n b = gli\r\n a_s = a.sum\r\n b_s = b.sum\r\n mn = [a_s, b_s].max\r\n b_s = 0\r\n for i in (0..n-1)\r\n a_s -= a[i]\r\n b_s += b[i]\r\n tmp = [a_s, b_s].max\r\n mn = tmp if mn > tmp\r\n end\r\n puts mn - b[-1]\r\nend\r\n\r\ndef main\r\n gi.times { solve }\r\nend\r\n\r\nmain\r\n"}], "src_uid": "f3ee3a0de5ddf3cf15ef02fb62a2768e"} {"source_code": "dist = ->zs, z1 { zs.map { |z2| (z2 - z1).abs }.sum }\r\n\r\ngets.to_i.times do\r\n n = gets.to_i\r\n xys = n.times.map { gets.split.map(&:to_i) }\r\n p ([0, 1].map do |i|\r\n zs = xys.map { |xy| xy[i] }\r\n min = zs.min_by { |a| dist[zs, a] }\r\n mind = dist[zs, min]\r\n a = (0..min).bsearch { |i| dist[zs, i] == mind }\r\n b = (min..(10 ** 10)).bsearch { |i| dist[zs, i] > mind }\r\n (b - a).abs\r\n end).reduce(:*)\r\nend\r\n", "positive_code": [{"source_code": "alias g gets;g;$<.map{|l|n=l.to_i;x,y=[],[];(0...n).map{c=g.split.map &:to_i;x<>1]-i[n-1>>1]+1};p a*b}"}, {"source_code": "def solve(range, n)\n range.sort!\n\n return 1 if n % 2 == 1\n\n range[n/2] - range[n/2 - 1] + 1\nend\n\ncases = gets.chomp.to_i\n\ncases.times do\n n = gets.chomp.to_i\n xs = []\n ys = []\n n.times do\n x, y = gets.chomp.split(\" \").map(&:to_i)\n xs << x\n ys << y\n end\n puts solve(xs, n) * solve(ys, n)\nend"}, {"source_code": "def solve(range, n)\n range.sort!\n\n range[n/2] - range[(n - 1)/2] + 1\nend\n\ncases = gets.chomp.to_i\n\ncases.times do\n n = gets.chomp.to_i\n xs = []\n ys = []\n n.times do\n x, y = gets.chomp.split(\" \").map(&:to_i)\n xs << x\n ys << y\n end\n puts solve(xs, n) * solve(ys, n)\nend"}, {"source_code": "def solve(a)\r\n n = a.size\r\n a.sort!\r\n a[n / 2] - a[(n - 1) / 2] + 1\r\nend\r\ngets.to_i.times do\r\n n = gets.to_i\r\n x, y = [], []\r\n n.times do |i|\r\n cx, cy = gets.split.map &:to_i\r\n x << cx\r\n y << cy\r\n end\r\n puts solve(x) * solve(y)\r\nend"}], "negative_code": [], "src_uid": "e0a1dc397838852957d0e15ec98d5efe"} {"source_code": "gets.to_i.times do\n gets\n s=Array.new(8) {gets.chomp}\n puts s.include?('R'*8) ? 'R' : 'B'\nend\n", "positive_code": [{"source_code": "t=gets.to_i\nt.times do\n _=gets\n arr=Array.new(8){gets.chomp}\n puts ((arr.include? \"R\"*8)?\"R\":\"B\")\nend"}, {"source_code": "t=gets.to_i\nt.times do\n _=gets\n arr=[]\n isHorizonal=false\n 8.times do\n arr=gets.chomp\n if arr.count('R')==8\n isHorizonal=true\n end\n end \n if isHorizonal\n puts \"R\"\n else\n puts \"B\"\n end\nend"}], "negative_code": [], "src_uid": "2c7add49d423de44a2bc09de56ffacf1"} {"source_code": "n = gets.to_i\nary = gets.strip.split.map(&:to_i)\n# tmp = ary.dup\n\nsum = 0\nops = []\nmod = 2100 # 500000\n\n(n-1).downto(0).each do |i|\n v = ary[i]+sum\n v %= mod\n target = mod - (n-i)\n # puts \"target:#{target}, v:#{v}\"\n next if v == target\n xs = 0\n if target > v\n xs = target-v\n elsif target < v\n xs = mod+target-v\n end\n ops << \"1 #{i+1} #{xs}\"\n sum += xs\nend\nops << \"2 #{n} #{mod}\"\nputs ops.size\nputs ops.join(\"\\n\")", "positive_code": [{"source_code": "n = gets.to_i\narr = gets.chomp.split(\" \").map(&:to_i)\n\nputs n+1\n\ndef getdiff(elem,n,modn)\n k = elem/n\n req = k*n + modn\n if req=0)\n toadd = getdiff(arr[i],n,i)\n j = 0\n while(j<=i)\n arr[j]+= toadd\n j = j+1\n end\n puts \"1 #{i+1} #{toadd}\"\n i = i-1\nend\n\nputs \"2 #{n} #{n}\"\n\n=begin\n(0..n-1).each do |i|\n arr[i] = arr[i]%n\nend\np arr\n=end\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nm = 10**5 + 1\nputs(n + 1)\n(n - 1).downto(0) do |i|\n d = (m - a[i] + i)%m\n (0..i).each{|j| a[j] += d}\n puts '1 ' + (i + 1).to_s + ' ' + d.to_s\n# p a\nend\nputs '2 ' + n.to_s + ' ' + m.to_s\n\n#(0...n).each{|j| a[j] %= m}\n#p a\n"}], "negative_code": [{"source_code": "n = gets.to_i\nary = gets.strip.split.map(&:to_i)\n# tmp = ary.dup\n\nsum = 0\nops = []\nmod = 2100 # 500000\n\n(n-1).downto(0).each do |i|\n v = ary[i]+sum\n v %= mod\n target = mod - (n-i)\n # puts \"target:#{target}, v:#{v}\"\n next if v == target\n xs = 0\n if target > v\n xs = target-v\n elsif target < v\n xs = mod+target-v\n end\n ops << \"1 #{i+1} #{xs}\"\n sum += xs\nend\nops << \"2 #{n} #{mod}\"\nputs ops.join(\"\\n\")"}, {"source_code": "n = gets.to_i\nary = gets.strip.split.map(&:to_i)\n# tmp = ary.dup\n\nsum = 0\nops = []\nmod = 500000\n\n(n-1).downto(0).each do |i|\n v = ary[i]+sum\n v %= mod\n target = mod - (n-i)\n # puts \"target:#{target}, v:#{v}\"\n next if v == target\n xs = 0\n if target > v\n xs = target-v\n elsif target < v\n xs = mod+target-v\n end\n ops << \"1 #{i+1} #{xs}\"\n sum += xs\nend\nops << \"2 #{n} #{mod}\"\nputs ops.join(\"\\n\")"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nm = 10**5 + 1\n(n - 1).downto(0) do |i|\n d = (m - a[i] + i)%m\n (0..i).each{|j| a[j] += d}\n puts '1 ' + (i + 1).to_s + ' ' + d.to_s\n# p a\nend\nputs '2 ' + n.to_s + ' ' + m.to_s\n\n#(0...n).each{|j| a[j] %= m}\n#p a\n"}], "src_uid": "e0ba8e0bfd9e1365daa41e1d14610200"} {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n\ndef gs() gets.strip end\ndef gss() gs.split end\ndef gis() gss.map &:to_i end\n\nH, W = gis\nF = H.times.map do gs end\nC = gs\n\nx, y = 0, 0\nH.times do |i|\n W.times do |j|\n if F[i][j] == 'S'\n x, y = j, i\n end\n end\nend\nSX, SY = x, y\n\nMV = [:L, :U, :D, :R]\n\nans = MV.permutation.reduce(0) do |a, mv|\n x, y = SX, SY\n C.each_char do |ch|\n case mv[ch.to_i]\n when :L\n x -= 1\n when :U\n y -= 1\n when :D\n y += 1\n when :R\n x += 1\n end\n if !(0...W).include? x\n break\n end\n if !(0...H).include? y\n break\n end\n if F[y][x] == '#'\n break\n end\n if F[y][x] == 'E'\n a += 1\n break\n end\n end\n a\nend\n\nputs ans", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\n\nmaze = Array.new(n)\nn.times do |i|\n maze[i] = gets.chomp\n S = [i, maze[i].index(?S)] if maze[i].include?(?S)\n G = [i, maze[i].index(?E)] if maze[i].include?(?E)\nend\n\ns = gets.chomp\n\nans = 0\n%w(U D R L).permutation(4) do |a, b, c, d| \n \n R = S.dup\n i = [a, b, c, d]\n \n s.each_char do |c|\n \n d = i[c.to_i]\n \n if d == ?U\n R[0] += 1\n elsif d == ?D\n R[0] -= 1\n elsif d == ?R\n R[1] += 1\n else\n R[1] -= 1\n end\n \n break if R[0] < 0 || n <= R[0] || R[1] < 0 || m <= R[1] || maze[R[0]][R[1]] == ?#\n \n if R == G\n ans += 1\n break\n end\n end\nend\n\nputs ans"}, {"source_code": "n, m = gets.split.map(&:to_i)\n\nmaze = Array.new(n)\nn.times do |i|\n maze[i] = gets.chomp\n if maze[i].include?(?S)\n S = [i, maze[i].index(?S)]\n end\n if maze[i].include?(?E)\n G = [i, maze[i].index(?E)]\n end\nend\n\n# p [n,m]\n# p [S, G]\n\ns = gets.chomp\n\nmaze\n\nans = 0\n%w(U D R L).permutation(4) do |a, b, c, d| \n \n R = S.dup\n # is_next = false\n \n i = [a, b, c, d]\n \n s.each_char do |c|\n \n d = i[c.to_i]\n \n if d == ?U\n R[0] += 1\n elsif d == ?D\n R[0] -= 1\n elsif d == ?R\n R[1] += 1\n else\n R[1] -= 1\n end\n \n if R[0] < 0 || n <= R[0] || R[1] < 0 || m <= R[1] || maze[R[0]][R[1]] == ?#\n # is_next = true\n break\n end\n \n if R == G\n ans += 1\n break\n end\n end\n \n # next if is_next\n # p R\n # if G == R\n # ans += 1\n # end\nend\n\nputs ans\n\n\n"}, {"source_code": "\ndef valid_perm(n,m,arr,start_i,start_j,ends_i,ends_j,perm,str)\n\ncur_i = start_i\ncur_j = start_j\n\nstr.each do |c|\n\n\t\tind = perm.index(c)\n\t\tif ind==0 #up\n\t\t\tif cur_i - 1 <0 or arr[cur_i - 1][cur_j] == '#'\n\t\t\t\treturn false\n\t\t\telsif cur_i - 1 == ends_i and cur_j == ends_j\n\t\t\t\treturn true\n\t\t\tend\n\t\t\tcur_i-=1\n\t\telsif ind == 1 #down\n\t\t\tif cur_i + 1 >=n or arr[cur_i + 1][cur_j] == '#'\n\t\t\t\treturn false\n\t\t\telsif cur_i + 1 == ends_i and cur_j == ends_j\n\t\t\t\t\n\t\t\t\treturn true\n\t\t\tend\n\t\t\tcur_i+=1\n\t\t\t\n\t\telsif ind== 2 #left\n\t\t\tif cur_j - 1 <0 or arr[cur_i][cur_j-1] == '#'\n\t\t\t\treturn false\n\t\t\telsif cur_i == ends_i and cur_j-1 == ends_j\n\t\t\t\t\n\t\t\t\treturn true\n\t\t\tend\n\t\t\tcur_j-=1\n\t\t\t\n\t\telsif ind==3 #right\n\t\t\tif c == \"0\" and perm.index(c)==3\n\t \t\tend\n\t\t\tif cur_j + 1 >=m or arr[cur_i ][cur_j+1] == '#'\n\t\t\t\treturn false\n\t\t\telsif cur_i == ends_i and cur_j+1 == ends_j\n\t\t\t\treturn true\n\t\t\tend\n\t\t\tcur_j+=1\t\t\n\t\tend\t\t\n\tend\nreturn false\nend\n\n\n\n\n\n\n\n\n\nn,m = gets.chomp.split\nn = n.to_i\nm = m.to_i\n\narr = []\nstart_i=0\nstart_j=0\nends_i=0\nends_j=0\n(0...n).each do |i|\n\ts = gets.chomp.split('') \n\tif s.include?(\"S\")\n\t\tstart_i = i\n\t\tstart_j = s.index(\"S\")\n\tend\t\t\n\tif s.include?(\"E\")\n\t\tends_i = i\n\t\tends_j = s.index(\"E\")\n\tend\t\n\tarr<= $n || c >= $m || $s[r][c] == '#'\n return false\n end\n end\n return r == $er && c == $ec\nend\n\ng = gets.chomp.split(' ')\n$n = g[0].to_i\n$m = g[1].to_i\nfor i in (0...$n)\n g = gets.chomp\n $s.push(g)\n for j in (0...$m)\n if g[j] == 'S'\n $sr = i\n $sc = j\n end\n if g[j] == 'E'\n $er = i\n $ec = j\n end\n end\nend\n$x = gets.chomp\nans = 0\nfor i in (0...p.length)\n $f = p[i]\n ans += check ? 1 : 0\nend\nputs ans"}], "negative_code": [], "src_uid": "8a1799f4ca028d48d5a12e8ac4b8bee1"} {"source_code": "puts $<.map{|_|_.count\"aeiuo\"}*\"\"==\"575\"?\"YES\":\"NO\"\n", "positive_code": [{"source_code": "a = [ gets.count(\"aeiou\"), gets.count(\"aeiou\"), gets.count(\"aeiou\") ]\nputs a==[5,7,5] ?\"YES\":\"NO\""}, {"source_code": "phrases = Array.new\nphrases.push(gets.split(\"\"))\nphrases.push(gets.split(\"\"))\nphrases.push(gets.split(\"\"))\nif phrases[0].count(\"a\") + phrases[0].count(\"e\") + phrases[0].count(\"i\") + phrases[0].count(\"o\") + phrases[0].count(\"u\") == 5 and\\\n phrases[1].count(\"a\") + phrases[1].count(\"e\") + phrases[1].count(\"i\") + phrases[1].count(\"o\") + phrases[1].count(\"u\") == 7 and\\\n phrases[2].count(\"a\") + phrases[2].count(\"e\") + phrases[2].count(\"i\") + phrases[2].count(\"o\") + phrases[2].count(\"u\") == 5\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "puts $<.map{|_|_.count\"aeiuo\"}*\"\"==\"575\"?\"YES\":\"NO\"\n"}, {"source_code": "str = gets.split\n\nfirst = 0\nsecond = 0\nthird = 0\n\nstr.each{|s|\n loop{\n if s =~ /[aiueo]/\n s.sub!($&, \"\")\n first += 1\n else\n break\n end\n }\n}\n\nstr = gets.split\n\nstr.each{|s|\n loop{\n if s =~ /[aiueo]/\n s.sub!($&, \"\")\n second += 1\n else\n break\n end\n }\n}\n\nstr = gets.split\n\nstr.each{|s|\n loop{\n if s =~ /[aiueo]/\n s.sub!($&, \"\")\n third += 1\n else\n break\n end\n }\n}\n\nif first == 5\n if second == 7\n if third == 5\n puts \"YES\"\n exit\n end\n end\nend\n\nputs \"NO\"\n\n"}, {"source_code": "a = gets().chomp\nb = gets().chomp\nc = gets().chomp\n\ndef check( c )\n if( c == \"a\" || c == \"i\" || c == \"u\" || c == \"e\" || c == \"o\" )\n return true\n else\n return false\n end\nend\n\naa = 0\na.split(//).each{|chr| aa += 1 if(check(chr)) }\n\nbb = 0\nb.split(//).each{|chr| bb += 1 if(check(chr)) }\n\ncc = 0\nc.split(//).each{|chr| cc += 1 if(check(chr)) }\n\nif( aa == 5 && bb == 7 && cc == 5 )\n puts \"YES\"\nelsif\n puts \"NO\"\nend\n\n"}, {"source_code": "c = Array.new\n3.times do |i|\n\ts = STDIN.gets\n\tc[i] = s.count('aiueo')\nend\nif c[0] == 5 && c[1] == 7 && c[2] == 5 then\n\tprint \"YES\"\nelse\n\tprint \"NO\"\nend\n"}, {"source_code": "v = 'aeiou'\nif gets.count(v) == 5 && gets.count(v) == 7 && gets.count(v) == 5\n puts 'YES'\nelse\n puts 'NO'\nend"}, {"source_code": "puts $<.map{|_|_.count\"aeiuo\"}*\"\"==\"575\"?\"YES\":\"NO\"\n"}, {"source_code": "[5, 7, 5].each { |c|\n unless gets.chomp.scan(/[aeiou]/).size == c\n puts 'NO'\n exit\n end\n}\nputs 'YES'"}, {"source_code": "i=j=k=0\ngets.chomp.gsub(/[aeiou]/){i+=1}\ngets.chomp.gsub(/[aeiou]/){j+=1}\ngets.chomp.gsub(/[aeiou]/){k+=1}\nputs (i==5 and j==7 and k==5)?\"YES\":\"NO\""}, {"source_code": "puts $<.map{|_|_.count\"aeiuo\"}*\"\"==\"575\"?\"YES\":\"NO\""}, {"source_code": "input, heiku = STDIN.read.split(\"\\n\"), [5, 7, 5]\ninput.each_with_index { |v, k| (print :NO; exit) if v.count(\"aeiou\") != heiku[k] }\nprint :YES\n"}, {"source_code": "a=3.times.map{gets.count('aeiou')}\nputs a==[5,7,5]?:YES:\"NO\"\n"}, {"source_code": "a = 3.times.map{gets.count('aeiou')}\nputs a == [5, 7, 5] ? :YES : :NO\n"}, {"source_code": "n = []\n3.times do\nn.push gets.tr('^aeiou', '').size\nend\nprint n == [5, 7, 5] ? \"YES\" : \"NO\"\n"}, {"source_code": "a=[gets,gets,gets]\nl=[]\na.each{ |s|\n l.push(s.length)\n}\nfor i in 0..2\n a[i]=a[i].gsub(\"a\",\"\")\n a[i]=a[i].gsub(\"o\",\"\")\n a[i]=a[i].gsub(\"u\",\"\")\n a[i]=a[i].gsub(\"i\",\"\")\n a[i]=a[i].gsub(\"e\",\"\")\nend\nif l[0]-a[0].length==5 && l[1]-a[1].length==7 && l[2]-a[2].length==5 then\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "def function\nstrings=Array.new(3)\ncounters=Array.new(3)\n3.times do |i|\nstrings[i]=gets.chomp\nend\nt=/[aeiou]/\nif strings[0].scan(t).length==5 && strings[1].scan(t).length==7 && strings[2].scan(t).length==5\nprint \"YES\"\nelse\nprint \"NO\"\nend\nend\nfunction"}, {"source_code": "puts $<.map{|_|_.count\"aeiuo\"}*\"\"==\"575\"?\"YES\":\"NO\"\n"}, {"source_code": "puts $<.map{|_|_.count\"aeiuo\"}*\"\"==\"575\"?\"YES\":\"NO\"\n"}, {"source_code": "puts $<.map{|_|_.count\"aeiuo\"}*\"\"==\"575\"?\"YES\":\"NO\""}, {"source_code": "a = gets.chomp\nb = gets.chomp\nc = gets.chomp\nVowels = ['a', 'e', 'i', 'o', 'u']\na_s = 0\nfor char in a.split('')\n\ta_s += 1 if Vowels.include?char\nend\nb_s = 0\nfor char in b.split('')\n\tb_s += 1 if Vowels.include?char\nend\nc_s = 0\nfor char in c.split('')\n\tc_s += 1 if Vowels.include?char\nend\nif a_s == 5 && b_s == 7 && c_s == 5\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "puts $<.map{|_|_.count\"aeiuo\"}*\"\"==\"575\"?\"YES\":\"NO\""}, {"source_code": "a=gets.chomp.split('')\nb=gets.chomp.split('')\nc=gets.chomp.split('')\nx=0\ny=0\nz=0\na.each do |i|\n\tif i=='a' || i=='e' || i=='i' || i=='o' || i=='u'\n\t\tx+=1\n\tend\nend\nb.each do |i|\n\tif i=='a' || i=='e' || i=='i' || i=='o' || i=='u'\n\t\ty+=1\n\tend\nend\nc.each do |i|\n\tif i=='a' || i=='e' || i=='i' || i=='o' || i=='u'\n\t\tz+=1\n\tend\nend\nif x==5 && y==7 && z==5\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "a = readlines.map(&:strip)\nif a[0].gsub(/[aeiou]/).to_a.size == 5 and a[1].gsub(/[aeiou]/).to_a.size == 7 and a[2].gsub(/[aeiou]/).to_a.size == 5\n puts :YES\nelse\n puts :NO\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\na = 3.times.map{ gets.count('aeiou') }\nputs a == [5,7,5] ? \"YES\" : \"NO\"\n\n"}, {"source_code": "puts $<.map{|_|_.count\"aeiuo\"}*\"\"==\"575\"?\"YES\":\"NO\"\n"}, {"source_code": "puts $<.map{|_|_.count\"aeiuo\"}*\"\"==\"575\"?\"YES\":\"NO\""}, {"source_code": "puts readlines.collect{|line| line.chomp.scan(/[aeiou]/).size}==[5,7,5]?\"YES\":\"NO\"\n"}, {"source_code": "puts readlines.map{|l|l.count(\"aeiou\")}==[5,7,5]?\"YES\":\"NO\"\n"}, {"source_code": "puts readlines.collect{|l| l.scan(/[aeiou]/).size}==[5,7,5]?\"YES\":\"NO\"\n"}, {"source_code": "puts $<.map{|l|l.count\"aeiou\"}*\"\"==\"575\"?:YES:\"NO\"\n"}, {"source_code": "puts $<.map{|_|_.count\"aeiuo\"}*\"\"==\"575\"?\"YES\":\"NO\"\n"}], "negative_code": [{"source_code": "v = 'aeiou'\nif gets.count(v) == 5 || gets.count(v) == 7 || gets.count(v) == 5\n puts 'YES'\nelse\n puts 'NO'\nend"}], "src_uid": "46d734178b3acaddf2ee3706f04d603d"} {"source_code": "n = gets.chomp.to_i\nm = gets.chomp.to_i\na = []\nfor i in 1..n do\n a.push(gets.chomp.to_i)\nend\n\na = a.sort.reverse\ncount = 0\nwhile m > 0 do\n m -= a[count]\n count += 1\nend\n\nputs count\n", "positive_code": [{"source_code": "a=(1..gets.to_i)\nb=gets.to_i\na=a.map{gets.to_i}.sort\nc=0\nwhile b > 0\n c += 1\n b -= a.pop\nend\np c"}, {"source_code": "n,x,*a=$<.map &:to_i;a=a.sort.reverse\np (1..n).find{|i|(x-=a[i-1])<=0}"}, {"source_code": "n,x,*a=$<.map &:to_i;a=a.sort.reverse\np (1..n).find{|i|(x-=a[i-1])<=0}\n"}, {"source_code": "n,x,*a=$<.map &:to_i;a=a.sort.reverse\np (1..n).find{|i|(x-=a[i-1])<=0}\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\n############################################################\n\nn, m = ngi 2\na = ngi(n).sort.reverse\nc = 0\ns = 0\na.each do |v|\n s += v\n c += 1\n break if s >= m\nend\nputs c\n\n"}, {"source_code": "n,x,*a=$<.map &:to_i;a=a.sort.reverse\np (1..n).find{|i|(x-=a[i-1])<=0}\n"}, {"source_code": "n = gets.chomp.to_i\nm = gets.chomp.to_i\narr = Array.new(n)\nn.times do |i|\n arr[i] = gets.chomp.to_i\nend\narr = arr.sort ; arr = arr.reverse\nsum = 0 ; res = 0\nwhile sum < m\n sum+=arr[0] ; arr.shift ; res+=1\nend\nputs res"}, {"source_code": "n=gets.chomp.to_i\nsize=gets.chomp.to_i\nfile_arry=[]\n0.upto(n-1) do |i|\n\tfile_arry[i]=gets.chomp.to_i\nend\nfile_arry=file_arry.sort.reverse\nk=0\noutput=0\nloop do\n\tk=k+file_arry[output]\n\toutput+=1\n\tbreak if k>=size\nend\nputs output\t\n"}, {"source_code": "n = gets.to_i\nm = gets.to_i\nas = []\nn.times do\n as << gets.to_i\nend\nas.sort!.reverse!\np = 0\nwhile m > 0 do\n m -= as[p]\n p += 1\nend\nputs p\n"}, {"source_code": "n,x,*a=$<.map &:to_i;a=a.sort.reverse\np (1..n).find{|i|(x-=a[i-1])<=0}\n"}, {"source_code": "n=gets.chomp.to_i\nsize=gets.chomp.to_i\nfile_arry=[]\n0.upto(n-1) do |i|\n\tfile_arry[i]=gets.chomp.to_i\nend\nfile_arry=file_arry.sort.reverse\nk=0\noutput=0\nloop do\n\tk=k+file_arry[output]\n\toutput+=1\n\tbreak if k>=size\nend\nputs output"}, {"source_code": "n=gets.chomp.to_i\nsize=gets.chomp.to_i\n\ndata=[]\n\na=0\nwhile a=size\n\t\tbreak\n\tend\nend\n\nputs x\n"}, {"source_code": "n=gets.to_i\nm=gets.to_i\nxs=[]\nn.times{\n\txs<<(gets.to_i)\n}\nans=0\nxs.sort.reverse.each{|e|\n\tm-=e\n\tans+=1\n\tbreak if m<=0 \n}\nputs ans"}, {"source_code": "#!usr/bin/env ruby\n\na = []\nn = gets.to_i\nm = gets.to_i\nn.times {\n a << gets.to_i\n}\n\na.sort!\na.reverse!\n\nb = 0\nc = 0\nwhile b < m\n c += 1\n b += a.shift\nend\n\nputs c\n"}, {"source_code": "t = gets.to_i\nm = gets.to_i\narr1 = Array.new(t) \nindex=0\nt.times do\n\tarr1[index] = gets.to_i\n\tindex+=1\nend\n\narr1.sort!\nsum=m\nindex=t-1\ncount=0\nwhile m>0\n\tcount+=1\n\tm = m - arr1[index]\n\tindex-=1\nend\nputs count"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nm = gets.to_i\nar = []\nn.times {\n ar << gets.to_i\n}\nar.sort!\nsticks = 0\nwhile m > 0\n cap = ar.pop\n sticks += 1\n m -= cap\nend\nputs sticks"}, {"source_code": "n,x,*a=$<.map &:to_i;a=a.sort.reverse\np (1..n).find{|i|(x-=a[i-1])<=0}\n"}, {"source_code": "carts = gets.to_i\nfile_mb = gets.to_i\n\ncart = Array.new(carts)\n\nfor i in 0..carts-1\n\tcart[i]= gets.chomp.to_i\nend\n\ncart = cart.sort.reverse\n\nsum = 0\nnum = 0\nfor i in 0..carts-1\n\tsum += cart[i]\n\tnum +=1\n\tif sum >= file_mb\n\t\tputs num\n\t\texit\n\tend\nend"}, {"source_code": "n = gets.to_i\nm = gets.to_i\na = []\n(1..n).each do\n a.push gets.to_i\nend\n\na.sort!\nt = 0\ntmp = 0\n(0...n).each do |i|\n tmp +=a[n-i-1]\n t +=1\n break if tmp >= m\nend\n\nputs t\n"}, {"source_code": "n = gets.chomp.to_i\nm = gets.chomp.to_i\na = []\nn.times do\n a << gets.chomp.to_i\nend\nres = 0\na.sort.reverse.each do |i|\n break if m <= 0\n m -= i\n res += 1\nend\nputs res\n"}, {"source_code": "n = gets.to_i\nm = gets.to_i\na = Array.new(n)\nfor i in 0..n-1\n a[i] = gets.to_i\nend\na = a.sort {|x,y| y <=> x}\nk = 0\nfor item in a\n if m <= 0\n break\n end\n k += 1\n m -= item\nend\nputs k\n \n"}, {"source_code": "n = gets.to_i\nm = gets.to_i\narr = []\nfor i in 0..n-1\n arr[i] = gets.to_i\nend\n\narr = arr.sort\ncount = 0\nidx = n-1\nwhile m > 0\n m -= arr[idx]\n idx -= 1\n count += 1\nend\n\nputs count\n"}, {"source_code": "n=gets.chomp.to_i\nsize=gets.chomp.to_i\nfile_arry=[]\n0.upto(n-1) do |i|\n\tfile_arry[i]=gets.chomp.to_i\nend\nfile_arry=file_arry.sort.reverse\nk=0\noutput=0\nloop do\n\tk=k+file_arry[output]\n\toutput+=1\n\tbreak if k>=size\nend\nputs output\t\n"}, {"source_code": "n = gets.to_i\nm = gets.to_i\na = []\nn.times { a << gets.to_i }\na.sort!.reverse!\ns = 0\n(0...a.size).each do |i|\n s += a[i]\n if s >= m\n puts i + 1\n exit\n end\nend\n"}, {"source_code": "\nn = gets.chomp.to_i\nm = gets.chomp.to_i\n\nflash_drives = Array.new\nn.times {|i| flash_drives << gets.chomp.to_i}\n\nflash_drives.sort!\n\nk = 0\nwhile m > 0 do \n\tm = m - flash_drives[n - k - 1]\n\tk = k + 1\nend\n\nprint k\n"}, {"source_code": "n,x,*a=$<.map &:to_i;a=a.sort.reverse\np (1..n).find{|i|(x-=a[i-1])<=0}\n"}, {"source_code": "t = gets.chomp\nt = t.to_i\nn = gets.chomp\nn = n.to_i\nv = []\nfor i in 1 ..t do\n v << gets.chomp\nend\nv = v.map(&:to_i)\nc=0\ns=0\nv.sort.reverse.each do |num|\ns = s+num\nif s >= n\nc=c+1\nbreak\nelse\nc=c+1\nend\nend\nputs c"}, {"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\tm = gets.to_i\n\t\ta = []\n\t\tn.times do\n\t\t\ta << gets.to_i\n\t\tend\n\t\ta = a.sort.reverse\n\t\tans = 0\n\t\ta.each do |x|\n\t\t\tif m > 0\n\t\t\t\tm -= x\n\t\t\t\tans += 1\n\t\t\tend\n\t\tend\n\t\tputs ans\n\tend\nend\nSolver.new.main"}, {"source_code": "n,x,*a=$<.map &:to_i;a=a.sort.reverse\np (1..n).find{|i|(x-=a[i-1])<=0}\n"}], "negative_code": [{"source_code": "a=(1..gets.to_i).map{gets.to_i}.sort.reverse\nb=gets.to_i\nc=0\nwhile b > 0\n c += 1\n b -= a.shift\nend\np c"}, {"source_code": "n,x,*a=$<.map &:to_i;a.sort!\np (1..n).find{|i|(x-=a[i-1])<=0}"}, {"source_code": "n,x,*a=$<.map &:to_i\np (1..n).find{|i|(x-=a[i-1])<=0}"}, {"source_code": "input=gets.chomp.to_i\nif input>5 && input%2==0\nputs (input-2)/4\nelsif input>5 && input%2==1\nputs 0\nelse\nputs 0\nend\n\n\n\n\n"}], "src_uid": "a02a9e37a4499f9c86ac690a3a427466"} {"source_code": "gets.to_i.times do\n gets\n puts (gets =~ /8\\d{10}/ ? :YES : :NO)\nend\n", "positive_code": [{"source_code": "for x in 1..gets.to_i\n len = gets.to_i\n str = gets\n idx = str.index('8')\n if idx.nil? || len - idx < 11\n puts \"NO\"\n else\n puts \"YES\"\n end\nend"}, {"source_code": "t = gets.to_i \nt.times do \n\ts = gets.to_i \n\tn = gets \n\tflag = true\n\tfor e in 0...s\n\t\tif(n[e] == '8')\n\t\t\tif(s-e >= 11) \n\t\t\t\tputs(\"YES\")\n\t\t\t\tflag = false \n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\tend\n\tif(flag)\n\t\tputs(\"NO\")\n\tend\nend"}, {"source_code": "gets.to_i.times do\n d = gets.to_i\n num = gets.chomp.index('8')\n puts num && d - num >= 11 ? 'YES' : 'NO'\nend"}, {"source_code": "\nT = gets.to_i\nT.times do\n\tn = gets.to_i\n\tstr = gets.chomp\n\tif str.index('8')\n\t\tif str.size - str.index('8') >= 11\n\t\t\tputs \"YES\"\n\t\t\tnext\n\t\tend\n\tend\n\tputs \"NO\"\nend"}, {"source_code": "t = gets.to_i\nfor i in 0...t do\n n = gets.to_i\n s = gets.chomp\n flag = false\n for j in 0..(n-11) do\n if s[j] == '8'\n flag = true\n break\n end\n end\n puts flag ? \"YES\" : \"NO\"\nend\n"}], "negative_code": [{"source_code": "t = gets.to_i \nt.times do \n\ts = gets.to_i \n\tn = gets \n\tfor e in 0...s\n\t\tflag = true\n\t\tif(n[e] == '8')\n\t\t\tif(s-e-1 >= 11) \n\t\t\t\tputs(\"YES\")\n\t\t\t\tflag = false \n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\tend\n\tif(!flag)\n\t\tputs(\"NO\")\n\tend\nend"}, {"source_code": "t = gets.to_i \nt.times do \n\ts = gets.to_i \n\tn = gets \n\tflag = true\n\tfor e in 0...s\n\t\tif(n[e] == '8')\n\t\t\tif(s-e-1 >= 11) \n\t\t\t\tputs(\"YES\")\n\t\t\t\tflag = false \n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\tend\n\tif(flag)\n\t\tputs(\"NO\")\n\tend\nend"}, {"source_code": "for x in 1..gets.to_i\n len = gets.to_i\n str = gets\n if str.index('8').nil? || len - str.index('8') < 10\n puts \"NO\"\n else\n puts \"YES\"\n end\nend"}, {"source_code": "cases = gets\nfor x in 1..cases.to_i\n len = gets.to_i\n str = gets\n if str.index('8').nil? || len - str.index('8') < 10\n puts \"NO\"\n else\n puts \"YES\"\n end\nend"}], "src_uid": "bcdd7862b718d6bcc25c9aba8716d487"} {"source_code": "# ProblemC\nrequire 'bigdecimal'\nrequire 'bigdecimal/math'\ninclude BigMath\ninclude Math\nn, a, d = gets.split().map {|s| s.to_i}\n\nprev = 0.0\ntm = sqrt((2 * d) / a.to_f)\n\nn.times do\n t, v = gets.split().map {|s| s.to_i}\n ti = v / a.to_f\n tt = t.to_f\n if tm <= ti\n tt += tm\n else\n dm = (a * ti * ti) / 2.0\n tr = (d - dm) / v.to_f\n tt += tr + ti\n end\n if prev > tt\n puts prev\n else\n puts tt\n prev = tt \n end \nend\n\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\nn, a, d = $stdin.gets.chomp.split.map(&:to_i)\nprev = 0.0\nn.times do\n t, v = $stdin.gets.chomp.split.map(&:to_f)\n l = v*v/(2.0*a)\n x =\n if l < d\n u = v/a.to_f\n u + (d-l)/v.to_f\n else\n Math.sqrt(2.0*d/a.to_f)\n end\n ans = [x+t, prev].max\n printf \"%.5f\\n\", ans\n prev = ans\nend\n"}], "negative_code": [{"source_code": "# ProblemC\ninclude Math\nn, a, d = gets.split().map {|s| s.to_i}\n\nprev = 0.0\ntm = sqrt((2 * d) / a.to_f)\n\nn.times do\n t, v = gets.split().map {|s| s.to_i}\n ti = v / a.to_f\n tt = t.to_f\n if tm <= ti\n tt += tm\n else\n dm = (a * ti * ti) / 2.0\n tr = (d - dm) / v.to_f\n tt += tr + ti\n end\n if prev > tt\n puts prev \n else\n puts tt\n end\n prev = tt\nend\n\n"}], "src_uid": "894f407ca706788b13571878da8570f5"} {"source_code": "def danger(x, y, xx, yy, xxx, yyy)\n dx, dy, ddx, ddy = xx - x, yy - y, xxx - xx, yyy - yy\n return ddx * dy - ddy * dx < 0\nend\n\nn = readline.to_i\nx, y = readline.split(' ').collect(&:to_i)\nxx, yy = readline.split(' ').collect(&:to_i)\nret = 0\n(n - 1).times do\n xxx, yyy = readline.split(' ').collect(&:to_i)\n ret += 1 if danger(x, y, xx, yy, xxx, yyy)\n x, y, xx, yy = xx, yy, xxx, yyy\nend\n\nputs ret\n", "positive_code": [{"source_code": "def get_dir(dx, dy)\n\treturn 0 if dy>0\n\treturn 2 if dy<0\n\treturn 1 if dx>0\n\treturn 3 if dx<0\nend\n\ndef calc(dir, last_dir)\n\treturn 1 if last_dir == (dir+1)%4\n\treturn 0\nend\n\nn=gets.to_i\np=Array.new\nans=dir=last_dir=0\nfor i in 0..n\n\tbuf=gets.split(' ')\n\tp[i] = [buf[0].to_i, buf[1].to_i]\n\tdir = get_dir(p[i][0]-p[i-1][0], p[i][1] - p[i-1][1]) if i>0\n\tans += calc(dir, last_dir) if i>1\n\tlast_dir = dir\nend\nputs ans"}], "negative_code": [], "src_uid": "0054f9e2549900487d78fae9aa4c2d65"} {"source_code": "gets.to_i.times do\n gets\n a = gets.split(\" \").map(&:to_i)\n\n x = 0\n 1000.times do |i|\n if a.include? i\n a[a.index(i)] = -999\n else\n x = i\n break\n end\n end\n\n y = 0\n 1000.times do |i|\n if a.include? i\n a[a.index(i)] = -999\n else\n y = i\n break\n end\n end\n\n p x+y\nend\n", "positive_code": [{"source_code": "gets.to_i.times{gets\nt=gets.split.map &:to_i\np [1,2].map{|x|(0..t.max+1).map{|x|t.count x}.find_index{|y|y= 2\n\n if counter[x] == 1\n vals[0] = x + 1\n vals[1] = x if vals[1] == -1\n else\n vals[0] = x\n vals[1] = x if vals[1] == -1\n\n break\n end\n end\n\n puts vals.sum\nend\n"}], "negative_code": [], "src_uid": "e26b0b117593c159b7f01cfac66a71d1"} {"source_code": "def min_rpst(x)\n\tif x.length.even?\n\t\tm = x.length / 2\n\t\tp = x[0...m]\n\t\tq = x[m..-1]\n\t\tp = min_rpst p\n\t\tq = min_rpst q\n\t\tx = p < q ? p + q : q + p\n\tend\n\tx\nend\n\ns1 = gets.strip\ns2 = gets.strip\nputs (min_rpst(s1) == min_rpst(s2)) ? \"YES\" : \"NO\"\n", "positive_code": [{"source_code": "$MOD = 1000000000000000003\n\ndef pow2?(n)\n return true if n == 0 || n == 1\n return false if n < 0 || n % 2 == 1\n return pow2?(n / 2)\nend\n\ndef get_hash(s)\n #p s\n return s[0].ord if s.size == 1\n m = s.size / 2\n h1 = get_hash(s[0..m-1])\n h2 = get_hash(s[m..2 * m])\n return ((h1 + h2) * h1 * h2) % $MOD\nend\n\ndef eq(s1,s2)\n return true if (s1 == s2) \n return false if (s1.size != s2.size) || (s1.size % 2 == 1)\n if pow2?(s1.size)\n return get_hash(s1) == get_hash(s2)\n end\n\n m = s1.size / 2\n s11 = s1[0..m - 1]\n s12 = s1[m, 2 * m]\n s21 = s2[0..m - 1]\n s22 = s2[m, 2 * m]\n return true if eq(s11,s21) && eq(s12,s22) || eq(s12,s21) && eq(s11,s22)\n return false\nend\n\n\ns1 = gets.strip\ns2 = gets.strip\nputs (eq(s1,s2) ? 'YES' : 'NO')\n\n\n\n\n"}], "negative_code": [{"source_code": "\ndef eq_hash(s1,s2)\n base = 7\n mod = 1000000000000000003\n return true if s1 == s2\n return false if (s1.size % 2 == 1) || (s2.size % 2 == 1) || \n (s1.size != s2.size)\n hash1 = 0\n hash2 = 0\n s1.size.times do |i|\n hash1 += base ** s1[i].ord\n hash2 += base ** s2[i].ord\n hash1 %= mod\n hash2 %= mod\n end\n\n return hash1 == hash2\nend\n\n#p prime? gets.to_i\n#100.times {|i| p i if prime? i }\n#n = 10 ** 18 + 1\n#while !prime? n do\n# n += 2\n#end\n#p n \ns1 = gets.strip\ns2 = gets.strip\np (eq_hash(s1,s2) ? \"YES\" : \"NO\")\n\n"}, {"source_code": "\n# def prime?(n)\n# return true if n == 2 \n# return false if n < 2 || (n % 2 == 0)\n# i = 3\n# while i * i <= n do\n# \treturn false if n % i == 0\n# \ti += 2\n# end\n# return true\n# end\n\ndef eq_hash(s1,s2)\n base = 7\n mod = 1000000000000000003\n return true if s1 == s2\n return false if (s1.size % 2 == 1) || (s2.size % 2 == 1) || \n\t (s1.size != s2.size)\n hash1 = 0\n hash2 = 0\n s1.size.times do |i|\n\t hash1 += base ** s1[i].ord\n\t hash2 += base ** s2[i].ord\n\t hash1 %= mod\n\t hash2 %= mod\n end\n\n return hash1 == hash2\nend\n\n#p prime? gets.to_i\n#100.times {|i| p i if prime? i }\n#n = 10 ** 18 + 1\n#while !prime? n do\n# n += 2\n#end\n#p n \ns1 = gets.strip\ns2 = gets.strip\nputs (eq_hash(s1,s2) ? 'YES' : 'NO')\n\n\n\n\n"}], "src_uid": "21c0e12347d8be7dd19cb9f43a31be85"} {"source_code": "n, t = gets.split.map(&:to_i)\nmn = 2147483647\nidx = -1\n\nn.times do |i|\n s, d = gets.split.map(&:to_i)\n x = ((t-s).to_f/d).ceil\n\n if x < 0\n x = 0\n end\n\n if mn > s+d*x\n mn = s+d*x\n idx = i+1\n end\nend\n\np idx\n", "positive_code": [{"source_code": "n,t = gets.split.map(&:to_i)\nmin = 10 ** 6\nans = 0\nn.times do |i|\n s,d = gets.split.map(&:to_i)\n if s > t\n tmp = s \n else\n tmp = ((t-s)/d.to_f).ceil * d + s\n end\n if tmp < min\n min = tmp\n ans = i+1\n end\n #p tmp\nend\np ans\n"}, {"source_code": "N, T = gets.split.map(&:to_i)\n\nbuses = N.times.map { gets.split.map(&:to_i) }\n\nans = -1\ntime = Float::INFINITY\n\nbuses.each.with_index(1) do |(s, d), i|\n t = if s >= T\n s\n else\n s + d * ((T - s) / d.to_f).ceil\n end\n\n if time > t\n time = t\n ans = i\n end\nend\n\nputs ans\n"}, {"source_code": "n, t = gets.chomp.split(\" \").map(&:to_i)\nret = 10**5\nans = -1\nn.times do |i|\n s, d = gets.chomp.split(\" \").map(&:to_i)\n while true\n if s >= t\n st = s - t\n if ret > st\n ret = st\n ans = i + 1\n end\n break\n end\n s += d\n end\nend\nputs ans"}], "negative_code": [], "src_uid": "71be4cccd3b8c494ad7cc2d8a00cf5ed"} {"source_code": "t = gets.to_s.to_i\n1.upto(t) do |casenum|\n n, k = gets.to_s.split.map {|x| x.to_i }\n a = gets.to_s.split.map {|x| x.to_i }\n i = 0\n k.times do\n while a[i] == 0 && i < a.size - 1\n i += 1\n end\n if a[i] > 0 && i < a.size - 1\n a[i] -= 1\n a[-1] += 1\n end\n end\n printf(\"%s\\n\", a.join(\" \"))\nend\n\n", "positive_code": [{"source_code": "def solution(arr, n, k)\n i = 0\n\n while i < n - 1 && k > 0\n if arr[i] == 0\n i += 1\n next\n end\n\n arr[i] -= 1\n arr[n - 1] += 1\n k -= 1\n end\n\n arr\nend\n\ntest_cases = gets.to_i\n\ntest_cases.times do |test_case|\n n, k = gets.split(' ').map(&:to_i)\n arr = gets.split(' ').map(&:to_i)\n res = solution(arr, n, k)\n\n puts res.join(' ')\nend\n"}, {"source_code": "t = Integer(gets.chomp)\r\nt.times{\r\n n, k = gets.chomp.split().map!{|c| Integer(c)}\r\n a = gets.chomp.split().map!{|c| Integer(c)}\r\n \r\n l = 0\r\n until k == 0 || l == n-1 do \r\n if(a[l] > k)\r\n a[l] -= k\r\n a[n - 1] += k\r\n k = 0\r\n else\r\n k -= a[l]\r\n a[n-1] += a[l]\r\n a[l] = 0\r\n l += 1\r\n end\r\n end\r\n \r\n a.each do |e| print \"#{e} \" end\r\n puts \"\"\r\n}"}, {"source_code": "test_cases = gets.chomp.to_i\r\nfor i in 1..test_cases do\r\n line = gets.chomp.split(\" \")\r\n n = line[0].to_i\r\n k = line[1].to_i\r\n a = gets.chomp.split(\" \")\r\n b = Array.new(n)\r\n for j in 0..n - 1 do\r\n b[j] = a[j].to_i\r\n end\r\n for j in 0..n - 1 do\r\n d = [k, b[j]].min\r\n b[j] -= d\r\n b[n - 1] += d\r\n k -= d\r\n if k == 0\r\n break\r\n end\r\n end\r\n for j in 0..n - 1 do\r\n print \"#{b[j]} \"\r\n end\r\n puts \"\"\r\nend"}], "negative_code": [{"source_code": "def solution(arr, n, k)\n i = 0\n\n while i < n - 1 && k > 0\n i += 1 if arr[i] == 0\n arr[i] -= 1\n arr[n - 1] += 1\n k -= 1\n end\n\n arr\nend\n\ntest_cases = gets.to_i\n\ntest_cases.times do |test_case|\n n, k = gets.split(' ').map(&:to_i)\n arr = gets.split(' ').map(&:to_i)\n res = solution(arr, n, k)\n\n puts res.join(' ')\nend\n"}, {"source_code": "def solution(arr, n, k)\n i = 0\n\n while arr[i] >= 0 && k > 0 && i < n - 1\n break if arr[i] == 0\n arr[i] -= 1\n arr[n - i - 1] += 1\n k -= 1\n i += 1 if arr[i] < 1\n end\n\n arr\nend\n\ntest_cases = gets.to_i\n\ntest_cases.times do |test_case|\n n, k = gets.split(' ').map(&:to_i)\n arr = gets.split(' ').map(&:to_i)\n res = solution(arr, n, k)\n\n puts res.join(' ')\nend\n"}, {"source_code": "def solution(arr, n, k)\n i = 0\n\n while arr[i] >= 0 && k > 0 && i < n - 1\n arr[i] -= 1\n arr[n - i - 1] += 1\n k -= 1\n i += 1 if arr[i] == 0\n # puts arr.join(' ')\n end\n\n arr\nend\n\ntest_cases = gets.to_i\n\ntest_cases.times do |test_case|\n n, k = gets.split(' ').map(&:to_i)\n arr = gets.split(' ').map(&:to_i)\n res = solution(arr, n, k)\n\n puts res.join(' ')\nend\n"}, {"source_code": "def solution(arr, n, k)\n i = 0\n\n while i < n && arr[i] > 0 && k > 0\n arr[i] -= 1\n arr[n - i - 1] += 1\n k -= 1\n i += 1 if arr[i] == 1\n end\n\n arr\nend\n\ntest_cases = gets.to_i\n\ntest_cases.times do |test_case|\n n, k = gets.split(' ').map(&:to_i)\n arr = gets.split(' ').map(&:to_i)\n res = solution(arr, n, k)\n\n puts res.join(' ')\nend\n"}], "src_uid": "6854ad3597f9f41d475aacb774b823ed"} {"source_code": "n=gets.to_i\na=gets.split(\" \").map(&:to_i)\nh=Hash.new\nzeroIndex=-1\nfor i in 0...n\n\tif a[i]==0\n\t\tzeroIndex=i\n\t\th[i]=0\n\telse\n\t\tif zeroIndex>=0\n\t\t\th[i]=i-zeroIndex\n\t\telse\n\t\t\th[i]=n\n\t\tend\n\tend\nend\nzeroIndex=-1\nfor i in (n-1).downto(0)\n\tif a[i]==0\n\t\tzeroIndex=i\n\telse\n\t\tif zeroIndex>=0\n\t\t\th[i]=[h[i],zeroIndex-i].min\n\t\tend\n\tend\nend\nputs h.values.join(\" \")", "positive_code": [{"source_code": "n=gets.chomp\na=gets.chomp.split.map!{|x| x.to_i}\nlast=-a.size\na.each_index do |i|\n last = i if a[i]==0\n a[i]=i-last\nend\na.reverse!\n\nlast=-a.size\na.each_index do |i|\n last = i if a[i]==0\n a[i]=i-last if a[i]>i-last\nend\na.reverse!\nputs a * ' '"}, {"source_code": "#!/usr/bin/ruby\nn,*a=$<.read.split.map &:to_i\nz=[-Float::INFINITY]+(0...n).select{|i|a[i]==0}+[Float::INFINITY]\nputs (0...n).map{|i|\n\tidx=((0...z.size).bsearch{|j|z[j]>=i}||z.size)-1\n\t[i-z[idx],z[idx+1]-i].min\n}*' '"}, {"source_code": "size = gets.chomp.to_i\nvalues = gets.chomp.split(' ').map!(&:to_i)\n\nindexes = values.each_with_object([]).with_index do |(value, obj), index|\n obj << index if value.zero?\nend\n\nresult = []\nleft = nil\nright = indexes.shift\n\nsize.times do |index|\n #puts \"left: #{left} right: #{right} tested: #{index}\"\n distance_to_left = (index - (left || right)).abs\n distance_to_right = (index - (right || left)).abs\n\n result << [distance_to_left, distance_to_right].min # pohybujeme se v mantinelu\n # mantinel posuneme jakmile prejdeme pres index\n if index == right\n left = right\n right = indexes.shift\n end\nend\n\nputs result.join(' ')"}], "negative_code": [{"source_code": "n=gets.chomp\na=gets.chomp.split.map!{|x| x.to_i}\nlast=-a.size\na.each_index do |i|\n last = i if a[i]=='0'\n a[i]=i-last\nend\na.reverse!\n\nlast=-a.size\na.each_index do |i|\n last = i if a[i]==0\n a[i]=i-last if a[i]>i-last\nend\na.reverse!\nputs a"}, {"source_code": "size = gets.chomp.to_i\nvalues = gets.chomp.split(' ').map!(&:to_i)\n\nindexes = values.each_with_object([]).with_index do |(value, obj), index|\n obj << index if value.zero?\nend\n\nresult = []\nleft = nil\nright = indexes.shift\n\nsize.times do |index|\n puts \"left: #{left} right: #{right} tested: #{index}\"\n distance_to_left = (index - (left || right)).abs\n distance_to_right = (index - (right || left)).abs\n\n result << [distance_to_left, distance_to_right].min # pohybujeme se v mantinelu\n # mantinel posuneme jakmile prejdeme pres index\n if index == right\n left = right\n right = indexes.shift\n end\nend\n\nputs result.join(' ')"}], "src_uid": "2031f2ac5652609fda77830e93ffcc2c"} {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map{|e| e.to_i % 10}\r\n at = a.tally\r\n new_a = []\r\n at.each do |k,v|\r\n [v,3].min.times do\r\n new_a << k\r\n end\r\n end\r\n\r\n ans = false\r\n m = new_a.size\r\n m.times do |i|\r\n m.times do |j|\r\n next if i == j\r\n m.times do |k|\r\n next if i == k || k == j\r\n\r\n if (new_a[i]+new_a[j]+new_a[k])%10 == 3\r\n ans = true\r\n break\r\n end\r\n end\r\n break if ans\r\n end\r\n break if ans\r\n end\r\n\r\n puts ans ? \"YES\" : \"NO\"\r\nend\r\n", "positive_code": [{"source_code": "def solve\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n cnt = Array.new(10)\r\n cnt2 = Array.new(10)\r\n i = 0\r\n while i < n\r\n a[i] = a[i] % 10\r\n i = i + 1\r\n end\r\n i = 0\r\n while i < 10\r\n cnt[i] = 0\r\n cnt2[i] = 0\r\n i = i + 1\r\n end\r\n a.each do |i|\r\n cnt[i] = cnt[i] + 1\r\n end\r\n ok = false\r\n i = 0\r\n while i < 10\r\n j = 0\r\n cnt2[i] = cnt2[i] + 1\r\n while j < 10\r\n cnt2[j] = cnt2[j] + 1\r\n k = 0\r\n while k < 10\r\n cnt2[k] = cnt2[k] + 1\r\n x = (i + j + k) % 10\r\n if cnt[i] >= cnt2[i] and cnt[j] >= cnt2[j] and cnt[k] >= cnt2[k] and x == 3\r\n ok = true\r\n end\r\n cnt2[k] = cnt2[k] - 1\r\n k = k + 1\r\n end\r\n cnt2[j] = cnt2[j] - 1\r\n j = j + 1\r\n end\r\n cnt2[i] = cnt2[i] - 1\r\n i = i + 1\r\n end\r\n if ok == true\r\n puts \"YES\"\r\n else \r\n puts \"NO\"\r\n end\r\nend\r\n\r\ngets.to_i.times do\r\n solve\r\nend"}, {"source_code": "# \u548c\u304c 3 \u306b\u306a\u308b\u7d44\u307f\u5408\u308f\u305b\u3092\u5217\u6319\ncombinations = []\n(0 .. 9).each do |x|\n (x .. 9).each do |y|\n (y .. 9).each do |z|\n if (x + y + z) % 10 == 3\n counts = [0] * 10\n counts[x] += 1\n counts[y] += 1\n counts[z] += 1\n combinations << counts\n end\n end\n end\nend\n\nt = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n \n counts = [0] * 10\n a.each do |x|\n counts[x % 10] += 1\n end\n \n ans = combinations.any? { |counts2| (0 .. 9).all? { |x| counts[x] >= counts2[x] } }\n puts ans ? \"YES\" : \"NO\"\nend"}, {"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n n = int\r\n a = ints\r\n \r\n count = [0] * 10\r\n a.each do |x|\r\n count[x % 10] += 1\r\n end\r\n \r\n yesno ((0 ... 10).any? do |x|\r\n next false if count[x] == 0\r\n count[x] -= 1\r\n b = (x ... 10).any? do |y|\r\n next false if count[y] == 0\r\n count[y] -= 1\r\n c = (y ... 10).any? do |z|\r\n next false if count[z] == 0\r\n (x + y + z) % 10 == 3\r\n end\r\n count[y] += 1\r\n c\r\n end\r\n count[x] += 1\r\n b\r\n end)\r\n end\r\n}\r\n\r\nDEBUG = false\r\nMOD = 10**9+7\r\nINF = 10**18\r\n$yesno = %w(NO YES)\r\n$YesNo = %w(No Yes)\r\n$YESNO = %w(NO YES)\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t ? 1 : 0] end\r\ndef YesNo t; puts $YesNo[t ? 1 : 0] end\r\ndef YESNO t; puts $YESNO[t ? 1 : 0] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]"}, {"source_code": "def solve(a)\n arr = gets.split.map(&:to_i).map { |number| number.modulo(10) }\n\n hash = Hash.new(0)\n\n arr.each do |n|\n hash[n] = hash[n] > 3 ? 3 : hash[n].succ\n end\n\n numbers = []\n hash.each_key do |key|\n while hash[key] > 0\n numbers.push(key)\n hash[key] -= 1\n end\n end\n\n (0...numbers.size).each do |i|\n ((i + 1)...numbers.size).each do |j|\n ((j + 1)...numbers.size).each do |k|\n if (numbers[i] + numbers[j] + numbers[k]) % 10 == 3\n puts \"YES\"\n return\n end\n end\n end\n end\n\n puts \"NO\"\nend\n\nn = gets.to_i\n\nn.times do\n a = gets.to_i\n solve(a)\nend\n"}, {"source_code": "array = []\r\n0.upto(9) do |a|\r\n 0.upto(9) do |b|\r\n 0.upto(9) do |c|\r\n array << [a, b, c] if (a + b + c) % 10 == 3\r\n end\r\n end\r\nend\r\n\r\ngets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n map = Hash.new(0)\r\n xs.each do |x|\r\n map[x % 10] += 1\r\n end\r\n ok = array.any? { |array| 0.upto(9).all? { |d| array.count(d) <= map[d] } }\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n"}], "negative_code": [{"source_code": "def solve\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n cnt = Array.new(10)\r\n cnt2 = Array.new(10)\r\n pairs = Array.new(n) {Array.new(10)}\r\n i = 0\r\n while i < n\r\n j = 0\r\n while j < 10\r\n pairs[i][j] = 0\r\n j = j + 1\r\n end\r\n i = i + 1\r\n end\r\n i = 0\r\n while i < 10\r\n cnt[i] = 0\r\n cnt2[i] = 0\r\n i = i + 1\r\n end\r\n a.each do |x|\r\n i = x % 10\r\n cnt[i] = cnt[i] + 1\r\n end\r\n id = 0\r\n a.each do |x|\r\n i = x % 10\r\n j = 0\r\n cnt[i] = cnt[i] - 1\r\n while j < 10\r\n k = (i + j) % 10\r\n cnt2[k] = cnt2[k] + cnt[j]\r\n pairs[id][k] = pairs[id][k] + cnt[j]\r\n j = j + 1\r\n end\r\n cnt[i] = cnt[i] + 1\r\n id = id + 1\r\n end\r\n id = 0\r\n ok = false\r\n a.each do |x|\r\n i = x % 10\r\n j = 0\r\n while j < 10\r\n cnt2[j] = cnt2[j] - pairs[id][j]\r\n j = j + 1\r\n end\r\n j = 0\r\n while j < 10\r\n k = (i + j) % 10\r\n if k == 3 and cnt2[j] > 0\r\n ok = true\r\n end\r\n j = j + 1\r\n end\r\n j = 0\r\n while j < 10\r\n cnt2[j] = cnt2[j] + pairs[id][j]\r\n j = j + 1\r\n end\r\n id = id + 1\r\n end\r\n if ok == true\r\n puts \"YES\"\r\n else \r\n puts \"NO\"\r\n end\r\nend\r\n\r\ngets.to_i.times do\r\n solve\r\nend"}, {"source_code": "def solve\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n cnt = Array.new(10)\r\n cnt2 = Array.new(10)\r\n pairs = Array.new(n) {Array.new(10)}\r\n i = 0\r\n while i < n\r\n j = 0\r\n while j < 10\r\n pairs[i][j] = 0\r\n j = j + 1\r\n end\r\n i = i + 1\r\n end\r\n i = 0\r\n while i < 10\r\n cnt[i] = 0\r\n cnt2[i] = 0\r\n i = i + 1\r\n end\r\n a.each do |x|\r\n i = x % 10\r\n cnt[i] = cnt[i] + 1\r\n end\r\n id = 0\r\n a.each do |x|\r\n i = x % 10\r\n j = 0\r\n cnt[i] = cnt[i] - 1\r\n while j < 10\r\n k = (i + j) % 10\r\n cnt2[k] = cnt2[k] + cnt[j]\r\n pairs[id][k] = pairs[id][k] + cnt[j]\r\n j = j + 1\r\n end\r\n cnt[i] = cnt[i] + 1\r\n id = id + 1\r\n end\r\n id = 0\r\n ok = false\r\n a.each do |x|\r\n i = x % 10\r\n j = 0\r\n while j < 10\r\n cnt2[j] = cnt2[j] - pairs[id][j]\r\n j = j + 1\r\n end\r\n j = 0\r\n while j < 10\r\n k = (i + j) % 10\r\n if k == 3 and cnt2[j] > 0\r\n ok = true\r\n end\r\n j = j + 1\r\n end\r\n j = 0\r\n while j < 10\r\n cnt2[j] = cnt2[j] + pairs[id][j]\r\n j = j + 1\r\n end\r\n end\r\n if ok == true\r\n puts \"YES\"\r\n else \r\n puts \"NO\"\r\n end\r\nend\r\n\r\ngets.to_i.times do\r\n solve\r\nend"}, {"source_code": "def solve\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n cnt = Array.new(10)\r\n cnt2 = Array.new(10)\r\n pairs = Array.new(n) {Array.new(10)}\r\n i = 0\r\n while i < n\r\n j = 0\r\n while j < 10\r\n pairs[i][j] = 0\r\n j = j + 1\r\n end\r\n i = i + 1\r\n end\r\n i = 0\r\n while i < 10\r\n cnt[i] = 0\r\n cnt2[i] = 0\r\n i = i + 1\r\n end\r\n a.each do |x|\r\n i = x % 10\r\n cnt[i] = cnt[i] + 1\r\n end\r\n id = 0\r\n a.each do |x|\r\n i = x % 10\r\n j = 0\r\n cnt[i] = cnt[i] - 1\r\n while j < 10\r\n k = (i + j) % 10\r\n cnt2[k] = cnt2[k] + cnt[j]\r\n pairs[id][k] = pairs[id][k] + cnt[j]\r\n j = j + 1\r\n end\r\n cnt[i] = cnt[i] + 1\r\n id = id + 1\r\n end\r\n id = 0\r\n ok = false\r\n a.each do |x|\r\n i = x % 10\r\n j = 0\r\n while j < 10\r\n k = (i + j) % 10\r\n cnt2[k] = cnt2[k] - pairs[id][k]\r\n if k == 3 and cnt2[k] > 0\r\n ok = true\r\n end\r\n j = j + 1\r\n end\r\n j = 0\r\n while j < 10\r\n k = (i + j) % 10\r\n cnt2[k] = cnt2[k] + pairs[id][k] \r\n j = j + 1\r\n end\r\n end\r\n if ok == true\r\n puts \"YES\"\r\n else \r\n puts \"NO\"\r\n end\r\nend\r\n\r\ngets.to_i.times do\r\n solve\r\nend"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map{|e| e.to_i % 10}\r\n at = a.tally\r\n new_a = []\r\n at.each do |k,v|\r\n [v,2].min.times do\r\n new_a << k\r\n end\r\n end\r\n\r\n ans = false\r\n m = new_a.size\r\n m.times do |i|\r\n m.times do |j|\r\n next if i == j\r\n k = new_a[i]+new_a[j]\r\n if k <= 3\r\n ans = true if !at[(3-k)].nil?\r\n elsif k <= 13\r\n ans = true if !at[(13-k)].nil?\r\n elsif k <= 23\r\n ans = true if !at[(23-k)].nil?\r\n end\r\n break if ans\r\n end\r\n break if ans\r\n end\r\n\r\n puts ans ? \"YES\" : \"NO\"\r\nend\r\n"}], "src_uid": "3ae4f35808348841e0f47540cdf4abe6"} {"source_code": "def solution\n n = gets.chomp.to_i\n data = []\n n.times do\n input = gets.chomp\n if input.size >= 2 && input[-2..-1] == 'po'\n data.push 'FILIPINO'\n elsif input.size >= 4 && input[-4..-1] == 'desu' || input[-4..-1] == 'masu'\n data.push 'JAPANESE'\n elsif input.size >= 5 && input[-5..-1] == 'mnida'\n data.push 'KOREAN'\n end\n end\n data.each { |e| puts e }\nend\n\nsolution\n", "positive_code": [{"source_code": "test=gets.strip.to_i\n\nwhile test != 0 \n\t\tn_str=gets.strip\n\t\tstr = n_str.reverse();\n\t\tif str[0] == 'o' && str[1] == 'p'\n\t\t\tputs \"FILIPINO\"\n\t\telsif str[0] == 'a' && str[1] == 'd' && str[2] == 'i' && str[3] == 'n' && str[4] == 'm'\n\t\t\tputs \"KOREAN\"\n\t\telse \n\t\t\tputs \"JAPANESE\"\n\t\tend\n\t\ttest -= 1\nend"}, {"source_code": "T=gets.chomp.to_i\nT.times do |x|\n string = gets.chomp\n puts \"FILIPINO\" if string.end_with? \"po\"\n puts \"JAPANESE\" if string.end_with? \"masu\"\n puts \"JAPANESE\" if string.end_with? \"desu\"\n puts \"KOREAN\" if string.end_with? \"mnida\"\nend"}, {"source_code": "t = gets.to_i\nt.times do\n\ts = gets.chomp.reverse!\n\tif s.slice(0,2) == 'op'\n\t\tputs \"FILIPINO\"\n\telsif [\"used\", \"usam\"].include?s.slice(0,4)\n\t\tputs \"JAPANESE\"\n\telse\n\t\tputs \"KOREAN\"\n\tend\nend"}, {"source_code": "N=STDIN.gets.strip.to_i\n(0..N-1).each do |i|\n s=STDIN.gets.strip\n if s =~ /po$/\n puts 'FILIPINO'\n elsif s =~ /desu$/ || s =~ /masu$/\n puts 'JAPANESE'\n elsif s =~ /mnida$/\n puts 'KOREAN'\n end\nend\n\n"}, {"source_code": "number = gets.chomp.to_i\ncases = []\nnumber.times { cases << gets.chomp }\nfor line in cases\n\tif line[-5..-1] == 'mnida'\n\t\tputs(\"KOREAN\")\n\telsif line[-4..-1] == 'desu' || line[-4..-1] == 'masu'\n\t\tputs(\"JAPANESE\")\n\telsif line[-2..-1] == 'po'\n\t\tputs(\"FILIPINO\")\n\telse\n\t\tputs(\"Just for safety, ya know :3\")\n\tend\nend"}, {"source_code": "gets.to_i.times do\n s = gets.chomp\n if s[-1] == \"o\" \n puts \"FILIPINO\"\n elsif s[-1] == \"a\" \n puts \"KOREAN\"\n elsif s[-1] == \"u\"\n puts \"JAPANESE\"\n end\nend"}, {"source_code": "nb = gets.to_i\nnb.times do\n case gets.chomp[-1]\n when 'a'\n puts 'KOREAN'\n when 'u'\n puts 'JAPANESE'\n when 'o'\n puts 'FILIPINO'\n end\nend"}, {"source_code": "words = []\ngets.chomp().to_i.times do |i|\n words << gets.chomp().to_s #input\nend\nwords.length().times do |i|\n if(words[i][-1].eql? \"o\")\n puts \"FILIPINO\"\n elsif(words[i][-1].eql? \"u\")\n puts \"JAPANESE\"\n else\n puts \"KOREAN\"\n end\nend"}, {"source_code": "gets.to_i.times do\n s = gets.chop\n puts 'FILIPINO' if s[-2..-1] == 'po'\n puts 'JAPANESE' if s[-4..-1] == 'masu' or s[-4..-1] == 'desu'\n puts 'KOREAN' if s[-5..-1] == 'mnida'\nend\n"}, {"source_code": "gets.to_i.times do\n s = gets.chomp\n puts 'FILIPINO' if s[-2..-1] == 'po'\n puts 'JAPANESE' if s[-4..-1] == 'masu' or s[-4..-1] == 'desu'\n puts 'KOREAN' if s[-5..-1] == 'mnida'\nend\n"}], "negative_code": [{"source_code": "if ARGV[0]==\"LOCAL_DEV\"\n define_method(\"debug\") do |var|\n p var\n end\nelse\n define_method(\"debug\") do |var|\n end\nend\n\nN=STDIN.gets.strip.to_i\n(0..N-1).each do |i|\n s=STDIN.gets.strip\n if s =~ /^.+?po$/\n puts 'FILIPINO'\n elsif s =~ /^.+?desu$/ || s =~ /^.+?masu$/\n puts 'JAPANESE'\n elsif s =~ /^.+?mnida$/\n puts 'KOREAN'\n end\nend\n\n"}], "src_uid": "816907d873bce3573ce1e5ae3f494768"} {"source_code": "\ndef solve n\n first = (1...(n/2)).to_a + [n]\n first = first.flatten\n second = ((n/2)...n).to_a\n a = first.map {|i| 2**i}.reduce(:+)\n b = second.map {|i| 2**i}.reduce(:+)\n (a-b).abs\nend\n\nt = STDIN.gets.chomp.to_i\n\nt.times do |i|\n n = STDIN.gets.chomp.to_i\n res = solve n\n puts res\nend\n", "positive_code": [{"source_code": "# require 'pry-byebug'\n\nfile = File.exist?('in.in') ? File.new('in.in','r') : STDIN\nt = file.gets.chomp.to_i\n\nt.times do\n n = file.gets.chomp.to_i\n\n a = 2**n\n min = 2**(n/2)-2\n\n b = 2**(n-1)\n min2 = 2**(n-1)-2-min\n\n puts (a+min)-(b+min2)\nend"}, {"source_code": "pw2 = Array.new(32,0);\npw2[0]=1\nfor i in 1..31\n pw2[i]=pw2[i-1]*2\nend\n\nt = gets.chomp.to_i\nwhile t>0 do\n n = gets.chomp.to_i\n sum = 0\n for i in 1..(n/2-1)\n sum+=pw2[i]\n end\n sum+=pw2[n]\n puts sum - (pw2[n+1]-sum-2)\n t-=1\n\nend \n"}, {"source_code": "n = gets.to_i\n\nn.times {\n v = gets.to_i\n puts 2 ** (v / 2 + 1) - 2\n}\n\n"}, {"source_code": "def min_weigth(n)\n f1 = (2 ** (n/2)) - 2\n (f1 + (2 ** n)) - ((2 ** n) - 2 - f1)\nend\n\nt = gets.chomp.to_i\n\nt.times do\n n = gets.chomp.to_i\n puts min_weigth(n)\nend\n"}, {"source_code": "# Phoenix has \ud835\udc5b coins with weights 21,22,\u2026,2\ud835\udc5b. He knows that \ud835\udc5b is even.\n\n# He wants to split the coins into two piles such that each pile has exactly \ud835\udc5b2\n# coins and the difference of weights between the two piles is minimized.\n# Formally, let \ud835\udc4e denote the sum of weights in the first pile, and \ud835\udc4f denote the\n#\u00a0sum of weights in the second pile. Help Phoenix minimize |\ud835\udc4e\u2212\ud835\udc4f|, the absolute\n# value of \ud835\udc4e\u2212\ud835\udc4f.\n\n# Input\n# The input consists of multiple test cases. The first line contains an integer\n# \ud835\udc61 (1\u2264\ud835\udc61\u2264100) \u2014 the number of test cases.\n\n# The first line of each test case contains an\n#\u00a0integer \ud835\udc5b (2\u2264\ud835\udc5b\u226430; \ud835\udc5b is even) \u2014 the number of coins that Phoenix has.\n\n# Output\n# For each test case, output one integer \u2014 the minimum possible difference of\n#\u00a0weights between the two piles.\n\n# Example\n# inputCopy\n# 2\n# 2\n# 4\n# outputCopy\n# 2\n# 6\n# Note\n# In the first test case, Phoenix has two coins with weights 2 and 4. No matter\n#\u00a0how he divides the coins, the difference will be 4\u22122=2.\n\n# In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16.\n#\u00a0It is optimal for Phoenix to place coins\n# with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another\n#\u00a0pile. The difference is (2+16)\u2212(4+8)=6.\n\ndef phoenix(queries)\n queries.each do |query|\n query = query.split(' ')\n\n return 0 unless query.length == 1\n\n stack_a = 0\n stack_a_count = 0\n stack_b = 0\n stack_b_count = 0\n input_n = query.first.to_i\n half = input_n / 2\n\n (input_n).downto(1) do |operand|\n product = 2 ** operand\n\n if stack_a_count == half\n stack_b += product\n stack_b_count += 1\n next\n end\n\n if stack_b_count == half\n stack_a += product\n stack_a_count += 1\n next\n end\n\n if stack_a > stack_b\n stack_b += product\n stack_b_count += 1\n else\n stack_a += product\n stack_a_count += 1\n end\n end\n\n puts (stack_a - stack_b).abs\n end\n\n return nil\nend\n\n# Codeforces required setup\nnumber_of_queries = gets.rstrip.to_i\n\nqueries = []\n\nnumber_of_queries.times do |query|\n queries << gets.rstrip\nend\n\nresult = phoenix queries\nputs result\n"}, {"source_code": "1.upto(gets.to_i) do\n n = gets.to_i\n\n l = (1..(n.div(2)-1)).inject(0) { |s, e| s + 2 ** e } + 2 ** n\n r = (n.div(2)..(n-1)).inject(0) { |s, e| s + 2 ** e }\n\n puts l - r\nend\n"}], "negative_code": [{"source_code": "pw2 = Array.new(32,0);\npw2[0]=1\nfor i in 1..31\n pw2[i]=pw2[i-1]*2\nend\n\nt = gets.chomp.to_i\nwhile t>0 do\n n = gets.chomp.to_i\n sum = 0\n for i in i..(n/2-1)\n sum+=pw[i]\n end\n sum+=pw2[n]\n\n puts sum - (pw2[n+1]-sum-2)\n t-=1\n\nend \n"}, {"source_code": "def min_weigth(n)\n f1 = (2 ** (n/2)) - 2\n (f1 + (2 ** n)) - ((2 ** n) - 2 - f1)\nend\n\nt = gets.chomp.to_i\n\nt.times do\n n = gets.chomp.to_i\n min_weigth(n)\nend\n"}, {"source_code": "# Phoenix has \ud835\udc5b coins with weights 21,22,\u2026,2\ud835\udc5b. He knows that \ud835\udc5b is even.\n\n# He wants to split the coins into two piles such that each pile has exactly \ud835\udc5b2 coins and the difference of weights\n# between the two piles is minimized. Formally, let \ud835\udc4e denote the sum of weights in the first pile, and \ud835\udc4f denote the sum of\n# weights in the second pile. Help Phoenix minimize |\ud835\udc4e\u2212\ud835\udc4f|, the absolute value of \ud835\udc4e\u2212\ud835\udc4f.\n\n# Input\n# The input consists of multiple test cases. The first line contains an integer \ud835\udc61 (1\u2264\ud835\udc61\u2264100) \u2014 the number of test cases.\n\n# The first line of each test case contains an integer \ud835\udc5b (2\u2264\ud835\udc5b\u226430; \ud835\udc5b is even) \u2014 the number of coins that Phoenix has.\n\n# Output\n# For each test case, output one integer \u2014 the minimum possible difference of weights between the two piles.\n\n# Example\n# inputCopy\n# 2\n# 2\n# 4\n# outputCopy\n# 2\n# 6\n# Note\n# In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4\u22122=2.\n\n# In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins\n# with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)\u2212(4+8)=6.\n\ndef phoenix(queries)\n queries.each do |query|\n query = query.split(' ')\n\n return 0 unless query.length == 1\n\n stack_a = 0\n stack_a_count = 0\n stack_b = 0\n stack_b_count = 0\n n = query.first.to_i\n\n (n).downto(1) do |operand|\n product = 2 ** operand\n\n if stack_b > stack_a\n if stack_a_count > stack_b_count\n stack_b_count += 1\n stack_b += product\n next\n end\n\n stack_a_count += 1\n stack_a += product\n else\n if stack_b_count > stack_a_count\n stack_a_count += 1\n stack_a += product\n break\n end\n\n stack_b_count += 1\n stack_b += product\n end\n end\n\n puts (stack_a - stack_b).abs\n end\n\n return nil\nend\n\n# Codeforces required setup\nnumber_of_queries = gets.rstrip.to_i\n\nqueries = []\n\nnumber_of_queries.times do |query|\n queries << gets.rstrip\nend\n\nresult = phoenix queries\nputs result\n"}], "src_uid": "787a45f427c2db98b2ddb78925e0e0f1"} {"source_code": "n,x=gets.split.map &:to_i\nmas=gets.split.map(&:to_i).sort\nk=0\nmas.each { |m| k+=m*x; x-=1 if x!=1 }\nputs k", "positive_code": [{"source_code": "#!/usr/bin/ruby\nn,x=gets.split.map(&:to_i)\nr=0\ngets.split.map(&:to_i).sort.each_with_index{|e,i|\n\tr+=[x-i,1].max*e\n}\np r"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nans=0\ngets.split.map{|e| e.to_i}.sort.each{|e|\n\tans+=e*m\n\tm-=1\n\tm=1 if m<1\n}\nputs ans\n"}, {"source_code": "num = gets.chomp.split\nn = Integer(num[0])\nx = Integer(num[1])\nnums = gets.chomp.split\nc = []\nfor i in 0...n\n c[i] = Integer(nums[i])\nend\n\nc.sort!\ntime = 0\nfor i in 0...n\n time += c[i] * x\n if x > 1 \n x -= 1\n end\nend\nputs time"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\nn,x = read_ints\na = read_ints\na.sort!\ni=0\nres = 0\nn.times do\n res+=a[i]*x\n j = [x-1, 1]\n x = j.max\n i+=1\nend\nputs res\n"}, {"source_code": "n, x = gets.split.map(&:to_i)\nc = gets.split.map(&:to_i).sort\nresult = 0\nc.each do |ci| \n result += ci * x\n x -= 1 if x > 1\nend\nputs result\n"}, {"source_code": "n,x = gets.split.map(&:to_i)\nc = gets.split.map(&:to_i).sort\n\nputs c.inject([x,0]) { |now, subjects|\n [[1, now[0]-1].max, now[1] + now[0] * subjects]\n}[1]"}, {"source_code": "# http://codeforces.com/problemset/problem/439/B\n\nn, x = gets.chomp.split.map(&:to_i)\nc = gets.chomp.split.map(&:to_i).sort\n\nmin = 0\nfor i in 0..(n - 1)\n min += x * c[i]\n x -= 1 if x > 1\nend\n\np min\n"}, {"source_code": "class DumbGuy\n n,x = gets.chomp.split(/\\s+/).map{|o| o.to_i}\n array = gets.chomp.split(/\\s+/).map{|o| o.to_i}\n array.sort!\n res = 0\n for i in 0..n-1\n res += array[i] * x\n x = x - 1 < 1 ? 1 : x - 1\n end\n puts res\nend"}], "negative_code": [], "src_uid": "ce27e56433175ebf9d3bbcb97e71091e"} {"source_code": "I =->{gets.split.map &:to_i}\nn,x=I[]; a=I[]; b=I[]\na.sort!; b.sort!; r = n - 1; a.each{|ai|\t\n\tr -= 1 if ai + b[r] >= x\n}\nputs [1,n-r-1]*' '", "positive_code": [{"source_code": "n,x=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\na.sort!; b.sort!; r = n - 1; a.each{|ai|\t\n\tr -= 1 if ai + b[r] >= x\n}\nputs [1,n-r-1]*' '"}, {"source_code": "n, x = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\na.sort! { |i, j| j <=> i }\nb.sort! \nworst = 0\nj = 0;\nfor i in 0..a.size do\n while j < b.size && a[i] + b[j] < x do\n j = j + 1\n end\n worst += 1 if j < b.size\n j = j + 1\nend\n\nputs \"1 #{worst}\"\n"}, {"source_code": "n,x=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\na.sort!;b.sort!;\nz=0;n-=1;a.each{|_|\n\tif _+b[n]>=x then\n\t\tz+=1;n-=1;\n\tend\n}\nputs [1,z]*' '"}], "negative_code": [], "src_uid": "77919677f562a6fd1af64bc8cbc79de5"} {"source_code": "\ndef solve(first_sec, second_sec, k)\n first_ptr = 0\n second_ptr = 0\n solution = []\n while first_ptr < first_sec.size && second_ptr < second_sec.size do\n if first_sec[first_ptr] < second_sec[second_ptr]\n return -1 if first_sec[first_ptr] > k\n solution << first_sec[first_ptr]\n first_ptr += 1\n else\n return -1 if second_sec[second_ptr] > k\n solution << second_sec[second_ptr]\n second_ptr += 1\n end\n k += 1 if solution[-1] == 0\n end\n\n while first_ptr < first_sec.size do\n return -1 if first_sec[first_ptr] > k\n solution << first_sec[first_ptr]\n first_ptr += 1\n k += 1 if solution[-1] == 0\n end\n\n while second_ptr < second_sec.size do \n return -1 if second_sec[second_ptr] > k\n solution << second_sec[second_ptr]\n second_ptr += 1\n k += 1 if solution[-1] == 0\n end\n\n solution.join(' ')\nend\n\n\nt = gets.chomp.to_i\nt.times do\n gets\n k, _ = gets.chomp.split(' ').map(&:to_i)\n first_sec = gets.chomp.split(' ').map(&:to_i)\n second_sec = gets.chomp.split(' ').map(&:to_i)\n\n puts \"#{solve(first_sec, second_sec, k)}\\n\"\nend\n", "positive_code": [{"source_code": "gets.to_i.times {\n gets\n k, n, m = gets.split.map!(&:to_i)\n as = gets.split.map!(&:to_i)\n bs = gets.split.map!(&:to_i)\n xs = []\n i = 0; j = 0\n while i < n || j < m\n if i < n && (as[i] <= k)\n xs << as[i]\n k += 1 if as[i] == 0\n i += 1\n elsif j < m && (bs[j] <= k)\n xs << bs[j]\n k += 1 if bs[j] == 0\n j += 1\n else\n break\n end\n end\n\n if i == n && j == m\n puts xs.join(' ')\n else\n p -1\n end\n}\n"}], "negative_code": [], "src_uid": "6628bd89b4d4fdfa90d2357f7cc1b795"} {"source_code": "tmp=gets.split\nn=tmp[0].to_i\nm=tmp[1].to_i\nc=gets.split\na=gets.split\ni=0\nj=0\nans=0\nwhile ic[i]\n\tif a[j]>=c[i]\n\t\tans=ans+1\n\t\tj=j+1\n\tend\n\ti=i+1\t\nend\nputs ans\n", "positive_code": [{"source_code": "_,a,b=$<.map{|e|e.split.map &:to_i}\nr=0\na.each{|e|b[r].to_i>=e&&r+=1}\np r"}, {"source_code": "N, M = gets.split.map(&:to_i)\ncs = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i)\nans = 0\ncs.each do |c|\n if c <= as[0]\n ans += 1\n as.shift\n break if as.length == 0\n end\nend\nputs ans"}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\ncost = gets.strip.split.map(&:to_i)\nbills = gets.strip.split.map(&:to_i)\n\nans = 0\nj = 0\n\n0.upto(n-1).each do |i|\n if cost[i] <= bills[j]\n ans += 1\n j += 1\n end\n break if j >= m\nend\n\nputs ans"}, {"source_code": "n, m = gets.split.map(&:to_i)\ncs = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i)\n\nans = 0\na = as.shift\n(0..n-1).each do |i|\n if a >= cs[i]\n ans += 1\n a = as.shift\n end\n break unless a\nend\n\nputs ans"}, {"source_code": "n, m = gets.split.map &:to_i\nc = gets.split.map &:to_i\na = gets.split.map &:to_i\nngames = 0\n(0...n).each do |i|\n if a[0] && a[0] >= c[i]\n ngames += 1\n a.shift\n end\nend\nputs ngames\n"}, {"source_code": "_,a,b=$<.map{|e|e.split.map &:to_i}\nr=0\na.each{|e|b[r].to_i>=e&&r+=1}\np r"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nans=0\nc.each{|v|\n break if a.empty?\n if v<=a.first\n ans+=1\n a.shift\n end\n}\n\nputs ans"}], "negative_code": [], "src_uid": "c3f080681e3da5e1290ef935ff91f364"} {"source_code": "n,m = gets.chomp.split.collect{|i| i.to_i}\nseats = gets.chomp.split.collect{|i| i.to_i}.sort\n\nminz = 0\nmint = 0\nnplanes = seats.size\n0.upto(nplanes-1) do |i|\n s = seats[i]\n while mint!=n and s!=0\n minz += s\n s -= 1\n mint += 1\n end\n break if mint == n\nend\nmaxz = 0\nmaxt = 0\nseats = seats.reverse\ni = 0\nwhile maxt != n\n maxz += seats[0]\n seats[0] -= 1\n maxt += 1\n seats[0] = nil if seats[0] == 0\n seats = seats.compact.sort.reverse\nend\n\nputs \"#{maxz} #{minz}\"\n", "positive_code": [{"source_code": "n, m = gets.split.map &:to_i\na = gets.split.map &:to_i\nb = a; x=y=0\nn.times{b=b.sort; x+=b[-1]; b[-1]-=1}\nn.times{a=a.sort; y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '\n\n\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t\t "}, {"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=a;x=y=0\nn.times{b=b.sort;x+=b[-1];b[-1]-=1}\nn.times{a=a.sort;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '"}, {"source_code": "n,m=gets.split.map &:to_i;\na=gets.split.map &:to_i;\n\nb = a; x=y=0\n\nn.times{\n\ta=a.sort;x+=a[0];a[0]-=1;\n\ta=a[1..-1]if a[0]==0\n}\n\nn.times{\n\tb=b.sort;y+=b[-1];b[-1]-=1;#b.pop if b[-1]==0\n}\n\nputs [y, x]*' '"}, {"source_code": "n,m=gets.split.map &:to_i;\na=gets.split.map &:to_i;\n\n\nb=a; x=y=0;\n\n\nn.times{\n\ta=a.sort;x+=a[0];a[0]-=1;a=a[1..-1]if a[0]==0\n}\n\nn.times{\n\tb=b.sort;y+=b[-1];b[-1]-=1;b.pop if b[-1]==0\n}\n\nputs [y, x]*' '"}, {"source_code": "n,m=gets.split.map &:to_i;\na=gets.split.map &:to_i;\n\nb = a; x=y=0\n\nn.times{\n\ta=a.sort;x+=a[0];a[0]-=1;\n\ta=a[1..-1]if a[0]==0\n}\n\nn.times{\n\tb=b.sort;y+=b[-1];b[-1]-=1;b.pop if b[-1]==0\n}\n\nputs [y, x]*' '"}, {"source_code": "I =->{gets.split.map &:to_i}\nn,m=I[];a=I[];b=a.sort;x=y=0\nn.times{b.sort!;x+=b[-1];b[-1]-=1}\nn.times{a.sort!;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '"}, {"source_code": "I =->{gets.split.map &:to_i}\nn,m=I[];a=I[];b=a.sort;x=y=0\nn.times{b.sort!;x+=b[-1];b[-1]-=1}\nn.times{a.sort!;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '\n"}, {"source_code": "I =->{gets.split.map &:to_i}\nn,m=I[];a=I[];b=a.sort;x=y=0\nn.times{b.sort!;x+=b[-1];b[-1]-=1}\nn.times{a.sort!;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '\n"}, {"source_code": "I =->{gets.split.map &:to_i}\nn,m=I[];a=I[];b=a.sort;x=y=0\nn.times{b.sort!;x+=b[-1];b[-1]-=1}\nn.times{a.sort!;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nmin_a, k, j, score_min = a.sort, n, 0, 0\nwhile k > 0\n score_min += (min_a[j] <= k ? min_a[j]*(min_a[j]+1)/2 : min_a[j]*(min_a[j]+1)/2-(min_a[j]-k)*(min_a[j]-k+1)/2)\n k -= min_a[j]\n j+=1\nend\n\nmax_a, k, score_max = a.sort.reverse, n, 0, 0\nel = max_a[0]\nc = max_a.count el\nwhile k > 0\n score_max += (c <= k ? el*c : el*k)\n el -= 1\n k -= c\n if max_a[c] == el\n while c < m and max_a[c] == el\n c+=1\n end\n end\nend\n\nputs \"#{score_max} #{score_min}\""}, {"source_code": "I =->{gets.split.map &:to_i}\nn,m=I[];a=I[];b=a.sort;x=y=0\nn.times{b.sort!;x+=b[-1];b[-1]-=1}\nn.times{a.sort!;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '\n"}, {"source_code": "I =->{gets.split.map &:to_i}\nn,m=I[];a=I[];b=a.sort;x=y=0\nn.times{b.sort!;x+=b[-1];b[-1]-=1}\nn.times{a.sort!;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '\n"}, {"source_code": "n, m = gets.chomp.split.map{|e|e.to_i}\na = Array.new(m){}\na = gets.chomp.split.map{|e|e.to_i}\nb = Marshal.load(Marshal.dump(a))\nmax = min = 0\n\nn.times do |i|\n a.sort!{|c, d| d <=> c }.reject!{|c| c == 0}\n max += a[0]\n a[0] -= 1\nend\n\nn.times do |i|\n b.sort!.reject!{|c| c == 0}\n min += b[0]\n b[0] -= 1\nend\n\nputs \"#{max} #{min}\""}, {"source_code": "#!/usr/bin/ruby\nn,m = gets.chomp.split(' ').map{|x| x.to_i}\na = gets.chomp.split(' ').map{|x| x.to_i}\natm = a.clone\nminc = 0\nmaxc = 0\nfor i in 0..n-1\n max = -1\n k = 0\n for j in 0..m-1\n if atm[j] > max && atm[j] > 0\n max = atm[j]\n k = j\n end\n end\n atm[k]-=1\n maxc += max\nend\nfor i in 0..n-1\n min = 2147483647\n k = 0\n for j in 0..m-1\n if a[j] < min && a[j] > 0\n min = a[j]\n k = j\n end\n end\n a[k]-=1;\n minc += min\nend\nputs \"#{maxc} #{minc}\"\n"}, {"source_code": "n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;b=a[0,m];x=y=0;n.times{a=a.sort;x+=a[0];a[0]-=1;a=a[1..-1]if a[0]==0};n.times{b=b.sort;y+=b[-1];b[-1]-=1;b.pop if b[-1]==0};$><<[y,x]*' '"}, {"source_code": "I =->{gets.split.map &:to_i}\nn,m=I[];a=I[];b=a.sort;x=y=0\nn.times{b.sort!;x+=b[-1];b[-1]-=1}\nn.times{a.sort!;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '\n"}, {"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=a;x=y=0\nn.times{b=b.sort;x+=b[-1];b[-1]-=1}\nn.times{a=a.sort;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '"}, {"source_code": "n, m = gets.split.map(&:to_i)\nar_down = gets.split.map(&:to_i).sort { |e| -e }\nar_up = ar_down.sort\n\n\nmin = max = 0\nn_up = n\nn_down = n\n\n\nar_up.each do |e|\n if n_up > e\n n_up -= e\n min += e*(1 + e)/2\n else\n min += (n_up)*(e-n_up+e+1)/2\n break\n end\nend\n\n\nn_down.times do\n m = ar_down.max\n max += m\n ar_down[ar_down.find_index(m)] -=1\nend\n\n\nputs \"#{max} #{min}\""}, {"source_code": "I =->{gets.split.map &:to_i}\nn,m=I[];a=I[];b=a.sort;x=y=0\nn.times{b.sort!;x+=b[-1];b[-1]-=1}\nn.times{a.sort!;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '\n"}, {"source_code": "def calc(p, a)\n cost = 0\n while p > 0\n index = yield(a)\n cost += a[index]\n a[index] -= 1\n p -= 1\n end\n cost\nend\n\nn, _ = gets.chomp.split.map { |x| x.to_i }\na = gets.chomp.split.map { |x| x.to_i }\nputs [calc(n, a.clone) { |x| max, index = -1, 0; x.each_with_index { |e, i| if e > max; max = e; index = i end }; index },\n calc(n, a) { |x| min, index = 1001, 0; x.each_with_index { |e, i| if e > 0 && e < min; min = e; index = i end }; index }] * ' '"}, {"source_code": "I =->{gets.split.map &:to_i}\nn,m=I[];a=I[];b=a.sort;x=y=0\nn.times{b.sort!;x+=b[-1];b[-1]-=1}\nn.times{a.sort!;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '\n"}, {"source_code": "I =->{gets.split.map &:to_i}\nn,m=I[];a=I[];b=a.sort;x=y=0\nn.times{b.sort!;x+=b[-1];b[-1]-=1}\nn.times{a.sort!;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '\n"}, {"source_code": "n,k = gets.chomp.split(/ /).map!{|x| x.to_i}\nra = gets.chomp.split(/ /).map!{|x| x.to_i}\nn1 = n\nn2 = n\ns1 = 0\ns2 = 0\nra2 = ra.sort\nra1 = ra.sort.reverse\nidx = 0\nwhile n1 > 0\n rew = false\n rew = true if idx >= k - 1 || ra1[idx] > ra1[idx+1]\n s1 += ra1[idx]\n ra1[idx] -= 1\n n1 -= 1\n if rew\n idx = 0\n else\n idx += 1\n end\nend\n\nidx = 0\nwhile n2 > 0\n s2 += ra2[idx]\n n2 -= 1\n ra2[idx] -= 1\n if ra2[idx] <= 0\n idx += 1\n end\nend\nputs s1.to_s + \" \" + s2.to_s\n"}, {"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb = a; x=y=0\nn.times{b=b.sort;x+=b[-1];b[-1]-=1;}\nn.times{a=a.sort;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '"}], "negative_code": [{"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb = a; x=y=0\nn.times{b=b.sort;x+=b[-1];b[-1]-=1;}\nn.times{a=a.sort;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[y,x]*' '"}, {"source_code": "n,m=gets.split.map &:to_i;\na=gets.split.map &:to_i;\n\n\nb = a; x=y=0;\n\nn.times{\n\ta=a.sort;x+=a[0];a[0]-=1;\t\n}\n\n\nn.times{\n\tb=b.sort;y+=b[-1];b[-1]-=1;b.pop if b[-1]==0\n}\n\nputs [y, x]*' '"}, {"source_code": "I =->{gets.split.map &:to_i}\nn,m=I[];a=I[];b=a;x=y=0\nn.times{b.sort!;x+=b[-1];b[-1]-=1}\nn.times{a.sort!;y+=a[0];a[0]-=1;a=a[1..-1] if a[0]==0}\n$><<[x,y]*' '"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nmin_a, k, j, score_min = a.sort, n, 0, 0\nwhile k > 0\n score_min += (min_a[j] <= k ? min_a[j]*(min_a[j]+1)/2 : k*(k+1)/2)\n k -= min_a[j]\n j+=1\nend\n\nmax_a, k, score_max = a.sort.reverse, n, 0, 0\nel = max_a[0]\nc = max_a.count el\nwhile k > 0\n score_max += (c <= k ? el*c : el*k)\n el -= 1\n k -= c\n if max_a[c] == el\n while c < m and a[c] == el\n c+=1\n end\n end\nend\n\nputs \"#{score_max} #{score_min}\""}, {"source_code": "n, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nmin_a, k, j, score_min = a.sort, n, 0, 0\nwhile k > 0\n score_min += (min_a[j] <= k ? min_a[j]*(min_a[j]+1)/2 : min_a[j]*(min_a[j]+1)/2-(min_a[j]-k)*(min_a[j]-k+1)/2)\n k -= min_a[j]\n j+=1\nend\n\nmax_a, k, score_max = a.sort.reverse, n, 0, 0\nel = max_a[0]\nc = max_a.count el\nwhile k > 0\n score_max += (c <= k ? el*c : el*k)\n el -= 1\n k -= c\n if max_a[c] == el\n while c < m and a[c] == el\n c+=1\n end\n end\nend\n\nputs \"#{score_max} #{score_min}\""}, {"source_code": "n,m = gets.chomp.split.collect{|i| i.to_i}\nseats = gets.chomp.split.collect{|i| i.to_i}.sort\n\nminz = 0\nmint = 0\nnplanes = seats.size\n0.upto(nplanes-1) do |i|\n s = seats[i]\n while mint!=n and s!=0\n minz += s\n s -= 1\n mint += 1\n end\n break if mint == n\nend\nmaxz = 0\nmaxt = 0\nseats = seats.reverse\ni = 0\nwhile maxt != n\n if seats[i] > 0 then \n maxz += seats[i]\n seats[i] -= 1\n maxt += 1\n end\n i += 1\n i %= nplanes\nend\n\nputs \"#{maxz} #{minz}\"\n"}, {"source_code": "n,m = gets.chomp.split.collect{|i| i.to_i}\nseats = gets.chomp.split.collect{|i| i.to_i}.sort\n\nminz = 0\nmint = 0\nnplanes = seats.size\n0.upto(nplanes-1) do |i|\n s = seats[i]\n while mint!=n and s!=0\n minz += s\n s -= 1\n mint += 1\n end\n break if mint == n\nend\nmaxz = 0\nmaxt = 0\nseats = seats.reverse\ni = 0\nwhile maxt != n\n while seats[i] >= seats[(i+1)%nplanes] and maxt!=n\n maxz += seats[i]\n seats[i] -= 1\n maxt += 1\n end\n break if maxt == n\n i += 1\n i %= nplanes\nend\n\nputs \"#{maxz} #{minz}\"\n"}], "src_uid": "6dea4611ca210b34ae2da93ebfa9896c"} {"source_code": "def get_right_count(array, value)\n n, sum = array.size, array[-1]\n result = Array.new(n, 0)\n result[-1] = 1 if sum == value\n (array.size - 2).downto(0) do |index|\n sum += array[index]\n result[index] += result[index + 1]\n result[index] += 1 if sum == value\n end\n result\nend\n\nn = gets.to_i\nvalues = gets.split.map { |v| v.to_i }\nsum, result = values.inject { |s, v| s + v }, 0\n\nif sum % 3 == 0\n sum /= 3\n left_sum, count = 0, get_right_count(values, sum) + [0, 0]\n values.each_index do |index|\n left_sum += values[index]\n result += count[index + 2] if left_sum == sum\n end\nend\n\nputs result\n\n", "positive_code": [{"source_code": "def solve(a)\n sum = a.inject { |s, x| s + x }\n return 0 unless sum % 3 == 0\n one_third = sum / 3\n a.pop\n local = 0\n thirds_count = 0\n ans = 0\n a.each do |x|\n local += x\n ans += thirds_count if local == one_third * 2\n thirds_count += 1 if local == one_third\n end\n return ans\nend\n\ngets\na = gets.split(' ').map { |x| x.to_i }\n#a = [1, 2, 3, 3]\nputs solve(a)\n\n\n"}], "negative_code": [{"source_code": "def get_right_count(array, value)\n n, sum = array.size, 0\n result = Array.new(n, 0)\n result[-1] = 1 if array[-1] == value\n (array.size - 2).downto(0) do |index|\n sum += array[index]\n result[index] += result[index + 1]\n result[index] += 1 if sum == value\n end\n result\nend\n\nn = gets.to_i\nvalues = gets.split.map { |v| v.to_i }\nsum, result = values.inject { |s, v| s + v }, 0\n\nif sum % 3 == 0\n sum /= 3\n left_sum, count = 0, get_right_count(values, sum) + [0, 0]\n values.each_index do |index|\n left_sum += values[index]\n result += count[index + 2] if left_sum == sum\n end\nend\n\nputs result\n\n"}], "src_uid": "4798211615bcff8730378330756ae63f"} {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\n\nneg=a.count {|i| i<0}\n[k,neg].min.times {|i| a[i]=-a[i]}\n\nmin=a.min_by {|i| i.abs}\nsum=a.inject(:+)\n\nk-=neg\nif k>0 && k%2==1\n sum-=2*min\nend\n\np sum\n", "positive_code": [{"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\n\nneg=a.count {|i| i<0}\n[k,neg].min.times {|i| a[i]=-a[i]}\n\nmin=a.min_by {|i| i.abs}\nsum=a.inject(:+)\n\nk-=neg\nsum-=2*min if k>0 && k%2==1\n\np sum\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\n\nneg=a.count {|i| i<0}\n[k,neg].min.times {|i| a[i]=-a[i]}\n\nsum=a.inject(:+)\n\nk-=neg\nsum-=2*a.min if k>0 && k%2==1\n\np sum\n"}, {"source_code": "n,k = gets.split.map &:to_i\na = gets.split.map &:to_i\ncounter = 0\na.each {|el| counter+=1 if el < 0}\nnull_position = a.index(0)\npre_null = nil\n\nif counter >= k\n k.times do |index|\n a[index] = -a[index]\n end\nelsif null_position\n a.each_with_index do |el,index|\n if el<0\n a[index] *= -1\n else\n break\n end\n end\nelse\n a.each_with_index do |el,index|\n if el<0\n a[index] = -el\n else\n pre_null = index-1\n break\n end\n end\n if (k-counter) % 2 != 0\n a[a.index(a.min)] *= -1\n end\n\nend\nputs a.inject{|sum, el| sum+el}\n"}, {"source_code": "def read_next_line\n gets.split.map(&:to_i)\nend\n\nn, k = read_next_line\na = read_next_line\ni, p = 0, [n, k].min\nwhile i < p && a[i] < 0\n a[i] = -a[i]\n i += 1\nend\nif (k - i).odd?\n i -= 1 if i == n || (i > 0 && a[i - 1] < a[i])\n a[i] = -a[i]\nend\nputs a.inject(:+)"}, {"source_code": "BEGIN{\n\tdef get_line_int()\n\t\treturn gets.split.map(&:to_i)\n\tend\n\tdef main()\n\t\tn, k = get_line_int\n\t\ta = get_line_int\n\t\tsum = 0\n\t\ta.each_with_index do |x,i|\n\t\t\tbreak if k == 0\n\t\t\tif x < 0 then\n\t\t\t\ta[i] *= -1\n\t\t\t\tk -= 1\n\t\t\telse\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\ta.each do |x|\n\t\t\tsum += x\n\t\tend\n\t\tif k != 0 then\n\t\t\tsum -= a.min * 2 if k % 2 == 1\n\t\tend\n\t\tputs sum\n\tend\n\tTest_case = 1\n\tTest_case.times do\n\t\tmain()\n\tend\n}\n"}, {"source_code": "a = gets.split(\" \").collect{|x| x.to_i}\nn = a[0]\nk = a[1]\n\na = gets.split(\" \").collect{|x| x.to_i}\nresult = 0\n\na.each_index { |i| \n\tif a[i] < 0 and k > 0\n\t\ta[i] *= -1\n\t\tk -= 1\n\tend\n}\n\nresult = a.inject{|result, x| result += x}\n\nif k % 2 == 1\n\tm = a.min { |a, b| a.abs <=> b.abs }\n\tresult -= 2*m\nend\n\nputs result"}, {"source_code": "n, k = gets.split(' ').map{|i| i.to_i}\na = gets.split(' ').map{|i| i.to_i}\ni = 0\nwhile k > 0\n\tif i < a.length and a[i] < 0\n\t\ta[i] *= -1\n\t\tk -= 1\n\t\ti += 1\n\telse\n\t\tbreak\n\tend\nend\n\nsum = a.reduce{|a, b| a+b}\nsum -= (k%2) * a.min * 2\nputs sum"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nputs gets.chomp.split.map(&:to_i).map { |x| (k > 0 && x < 0) ? (k -= 1; -x) : x }.sort.tap { |x| k = k % 2 }.map { |x| \n\tk > 0 ? (k = 0; -x ) : x }.reduce(:+)\n"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\n\nn, k = gets.chomp.split(\" \").map{|n| n.to_i}\nsequence = gets.chomp.split(\" \").map{|n| n.to_i}\nsequence.sort!\n\ni = 0\nk.times do\n break if i >= n or sequence[i] >= 0\n \n sequence[i] *= -1 \n i += 1\nend\n\nif (k - i) > 0\n sequence.sort!\n if (k - i) % 2 == 1\n sequence[0] *= -1\n end\nend\n\nputs sequence.inject{|sum, i| sum+= i}\n"}, {"source_code": "n,k=gets.split(' ').map(&:to_i)\na=gets.split(' ').map(&:to_i)\nneg=a.count {|i| i<0}\n[k,neg].min.times {|i| a[i]=-a[i]}\nmin=a.min_by {|i| i.abs}\nsum=a.inject(:+)\nk-=neg\nif k>0 && k%2==1\n sum-=2*min\nend\nputs sum"}, {"source_code": "def run\n lines = ARGF.readlines\n\n n, k = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n vals = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n\n vals.length.times do |i|\n if vals[i] < 0\n vals[i] *= -1\n k -= 1\n else\n if k % 2 == 1\n if vals[i - 1] < vals[i]\n vals[i - 1] *= -1\n else\n vals[i] *= -1\n end\n end\n k = 0\n end\n\n break if k == 0\n end\n\n vals[vals.length - 1] *= -1 if k % 2 == 1\n\n puts vals.reduce(0) { |sum, n| sum + n }\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n,k = gets.chomp.split(\" \").collect! {|x| x.to_i}\nline = gets.chomp.split(\" \").collect! {|x| x.to_i}\n\ns = 0\nmin = 10001\nline.sort!\nline.each {|x|\n if x<0\n\tif k>0\n\t\tk -= 1\n\t\ts += x.abs\n\telse\n\t\ts += x\n\tend\n\tmin = x.abs\n else\n\tif min > x\n\t\tmin = x\n\tend\n\ts += x\n end\n}\n\nif k%2 == 1\n\ts -= (2*min)\nend\n\nputs s"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\na = gets.split.collect{|i| i.to_i}.sort\nans = 0\ncnt = 0\na.each{|i| cnt+=1 if i<=0}\nif cnt>=k\n n.times do |i|\n if i < k\n ans += -a[i]\n else\n ans += a[i]\n end\n end\nelse\n k -= cnt\n a = a.collect{|i| i.abs}\n if k.odd?\n ans = a.inject{|sum, i| sum+=i}-2*a.min\n else\n ans = a.inject{|sum, i| sum+=i}\n end\nend\nputs ans\n"}], "negative_code": [{"source_code": "\ufeff# -*- encoding: utf-8 -*-\n\nn, k = gets.chomp.split(\" \").map{|n| n.to_i}\nsequence = gets.chomp.split(\" \").map{|n| n.to_i}\nsequence.sort!\n\nidx = 0\n\nk.times do\n if idx < n\n sequence[idx] *= -1\n idx += 1\n else\n sequence.sort!\n idx = 0\n end\nend\n\n\nputs sequence.inject{|sum, i| sum+= i}\n"}, {"source_code": "def run\n lines = ARGF.readlines\n\n n, k = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n vals = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n\n vals.length.times do |i|\n if vals[i] < 0\n vals[i] *= -1\n k -= 1\n else\n if vals[i - 1] < vals[i]\n vals[i - 1] *= -1\n else\n vals[i] *= -1\n end\n k = 0\n end\n\n break if k == 0\n end\n\n puts vals.reduce(0) { |sum, n| sum + n }\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n lines = ARGF.readlines\n\n n, k = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n vals = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n\n vals.length.times do |i|\n if vals[i] < 0\n vals[i] *= -1\n k -= 1\n else\n if vals[i - 1].abs < vals[i].abs\n vals[i - 1] *= -1\n else\n vals[i] *= -1\n end\n k = 0\n end\n\n break if k == 0\n end\n\n puts vals.reduce(0) { |sum, n| sum + n }\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n lines = ARGF.readlines\n\n n, k = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n vals = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n\n vals.length.times do |i|\n if vals[i] < 0\n vals[i] *= -1\n k -= 1\n else\n if vals[i - 1].abs < vals[i].abs\n vals[i - 1] *= -1\n else\n vals[i] *= -1\n end\n k = 0\n end\n\n break if k == 0\n end\n\n puts vals.reduce(0) { |sum, n| sum + n }\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n lines = ARGF.readlines\n\n n, k = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n vals = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n\n vals.length.times do |i|\n if vals[i] < 0\n vals[i] *= -1\n k -= 1\n else\n if k % 2 == 1\n if vals[i - 1] < vals[i]\n vals[i - 1] *= -1\n else\n vals[i] *= -1\n end\n end\n k = 0\n end\n\n break if k == 0\n end\n\n puts vals.reduce(0) { |sum, n| sum + n }\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n,k = gets.chomp.split(\" \").collect! {|x| x.to_i}\nline = gets.chomp.split(\" \").collect! {|x| x.to_i}\n\ns = 0\nmin = 0\nline.each {|x|\n if x<0\n\tif k>0\n\t\tk -= 1\n\t\ts += x.abs\n\telse\n\t\ts += x\n\tend\n\tmin = x.abs\n else\n\tif min > x\n\t\tmin = x\n\tend\n\ts += x\n end\n}\n\nif k%2 == 1\n\ts -= (2*min)\nend\n\nputs s"}, {"source_code": "n,k = gets.chomp.split(\" \").collect! {|x| x.to_i}\nline = gets.chomp.split(\" \").collect! {|x| x.to_i}\n\ns = 0\nmin = 0\nline.sort!\nline.each {|x|\n if x<0\n\tif k>0\n\t\tk -= 1\n\t\ts += x.abs\n\telse\n\t\ts += x\n\tend\n\tmin = x.abs\n else\n\tif min > x\n\t\tmin = x\n\tend\n\ts += x\n end\n}\n\nif k%2 == 1\n\ts -= (2*min)\nend\n\nputs s"}, {"source_code": "n,k = gets.chomp.split(\" \").collect! {|x| x.to_i}\nline = gets.chomp.split(\" \").collect! {|x| x.to_i}\n\ns = 0\nmin = 0\nline.each {|x|\n if x<0\n\tif k>0\n\t\tk -= 1\n\t\ts += x.abs\n\telse\n\t\ts += x\n\tend\n\tmin = x.abs\n else\n\tif min > x\n\t\tmin = x\n\tend\n\ts += x\n end\n}\n\nif k%2 == 1\n\ts -= min\nend\n\nputs s"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\na = gets.split.collect{|i| i.to_i}.sort\nans = 0\nn.times do |i|\n if i < k\n ans += -a[i]\n else\n ans += a[i]\n end\nend\nputs ans\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nk%=2*n\n\n[k,n].min.times {|i| a[i]=-a[i]}\nk-=n\n(-1..-k).each {|i| a[i]=-a[i]} if k>0\n\nputs a.inject(:+)\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\n\nk.times do |i|\n if i=n\n a[0]=-a[0]\n elsif a[i]<0\n a[i]=-a[i]\n elsif a[i]==0\n break\n else\n a[0]=-a[0]\n end\nend\n\nputs a.inject(:+)\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nk.times {|i| a[i%n]=-a[i%n]}\nputs a.inject(:+)\n"}, {"source_code": "a = gets.split(\" \").collect{|x| x.to_i}\nn = a[0]\nk = a[1]\n\na = gets.split(\" \").collect{|x| x.to_i}\nresult = 0\nminus = 0\n\na.sort!\n\na.each{|x| \n\tif x < 0\n\t\tminus += 1\n\tend\n}\n\nif minus >= k\n\ta.reverse_each { |e| \n\t\tif e < 0 and k > 0\n\t\t\te *= -1\n\t\t\tk -= 1\n\t\tend\n\t\tresult += e\n\t}\nelse \n\ta.inject{|result, x| result += x}\n\tk -= n\n\tif k % 2 == 1\n\t\tresult -= a[0]\n\tend\nend\n\nputs result"}], "src_uid": "befd3b1b4afe19ff619c0b34ed1a4966"} {"source_code": "eval\"N,M,*D=\"+$<.read.split*?,\np (M+D[N,M].inject(:+)..N).find{|i|D[i-1]>0}||-1", "positive_code": [{"source_code": "def func x\n return true if x>=@n\n h={}\n i=x\n s=0\n while i>=0\n k=@d[i]\n if k>=0 and !h[k]\n h[k]=1\n s+=@a[k]\n elsif s>0\n s-=1\n end\n i-=1\n end\n h.size==@m and s<=0\nend\n\n@n, @m=gets.split.map &:to_i\n@d=gets.split.map{|e| e.to_i-1}\n@a=gets.split.map &:to_i\n\nx=1<<32\nres=2*x-1\nwhile x>0\n res-=x if func res-x\n x>>=1\nend\n\nputs (res<@n ? res+1 : -1)\n"}, {"source_code": "eval\"N,M,*D=\"+$<.read.split*?,\na=D.pop M\nx=r=-1+t=1<<32\n32.times{(h={};s=0;(0..x).map{|i|!h[k=D[x-i]]&&k>0?h[k]=s+=a[k-1]:s>0&&s-=1}\nh.size==M&&s<1&&r=x)if f=N>x=r-t/=2;f||r=x}\np r=@n\n i, s, h=x, 0, {}\n while i>=0\n k=@d[i]\n k<0 or h[k] ? s=s>0 ? s-1 : 0 : (h[k]=1; s+=@a[k])\n i-=1\n end\n h.size==@m and s==0\nend\n\n@n, @m=gets.split.map &:to_i\n@d=gets.split.map{|e| e.to_i-1}\n@a=gets.split.map &:to_i\n\nx=1<<32\nres=2*x-1\nwhile x>0\n res-=x if func res-x\n x>>=1\nend\n\nputs (res<@n ? res+1 : -1)\n"}, {"source_code": "def func x\n return true if x>=@n\n h={}\n i=x\n p=x\n while i>=0\n k=@d[i]\n if k>=0 and !h[k]\n h[k]=1\n return false if @a[k]>p\n p-=@a[k]\n else\n p-=1\n end\n i-=1\n end\n h.size==@m\nend\n\n@n, @m=gets.split.map &:to_i\n@d=gets.split.map{|e| e.to_i-1}\n@a=gets.split.map &:to_i\n\nx=1<<32\nres=2*x-1\nwhile x>0\n res-=x if func res-x\n x>>=1\nend\n\nputs (res<@n ? res+1 : -1)\n"}, {"source_code": "def func x\n return true if x>=@n\n h={}\n i=x\n s=0\n while i>=0\n k=@d[i]\n if k>=0 and !h[k]\n h[k]=1\n s+=@a[k]\n else\n s-=1\n end\n i-=1\n end\n s<=0\nend\n\n@n, @m=gets.split.map &:to_i\n@d=gets.split.map{|e| e.to_i-1}\n@a=gets.split.map &:to_i\n\nx=1<<32\nres=2*x-1\nwhile x>0\n res-=x if func res-x\n x>>=1\nend\n\nputs (res<@n ? res+1 : -1)\n"}, {"source_code": "def func x\n return true if x>=@n\n h={}\n i=x\n s=0\n while i>=0\n k=@d[i]\n if k>=0 and !h[k]\n h[k]=1\n s+=@a[k]\n else\n s-=1\n end\n i-=1\n end\n h.size==@m and s<=0\nend\n\n@n, @m=gets.split.map &:to_i\n@d=gets.split.map{|e| e.to_i-1}\n@a=gets.split.map &:to_i\n\nx=1<<32\nres=2*x-1\nwhile x>0\n res-=x if func res-x\n x>>=1\nend\n\nputs (res<@n ? res+1 : -1)\n"}], "src_uid": "ab31ad331748994ddeb08be646d0787e"} {"source_code": "class Numeric\n def sign\n self<=>0\n end\nend\n\nclass Array\n def loop_slide!(x=1)\n return false if self.length <= 1\n x = (x.abs % self.length) * (-x.sign)\n x += self.length if x < 0\n new_a = self.drop(x)+self.take(x)\n self.length.times{|i| self[i] = new_a[i]}\n end\n\n def loop_slide_simple!(x=1) # x == 1 always\n new_a = self.drop(1)+self.take(1)\n self.length.times{|i| self[i] = new_a[i]}\n end\n\n def second\n self[1]\n end\n\n def third\n self[2]\n end\nend\n\nclass XElement\n def initialize(n,m)\n @rows, @cols = n, m\n @mtx = Array.new\n n.times{@mtx.push Array.new(m, 0)}\n end\n\n def print_mtx\n @rows.times { |row|\n @cols.times { |col|\n print @mtx[row][col]\n print ' '\n }\n print \"\\n\"\n }\n #print \"\\n\"\n end\n\n def shift_row!(row_num)\n @mtx[row_num-1].loop_slide!\n end\n\n def shift_col!(col_num)\n column = Array.new\n @rows.times{|i| column.push(@mtx[i][col_num-1])}\n column.loop_slide!(1)\n @rows.times{|i| @mtx[i][col_num-1] = column[i]}\n end\n\n def set_num!(row, col, value)\n row, col = row-1, col-1\n @mtx[row][col] = value\n end\n\n=begin\n def command!(args)\n COMMAND[args.first.to_s].call(args.drop(1))\n end\n=end\nend\n\nCOMMAND = {\n \"1\" => lambda{|x| $elem.shift_row!(x.first)},\n \"2\" => lambda{|x| $elem.shift_col!(x.first)},\n \"3\" => lambda{|x| $elem.set_num!(x.first, x.second, x.third)}\n}\n\nn,m,q, = gets.split.map{|x| x.to_i}\n$elem = XElement.new(n,m)\nstack = Array.new\nq.times {|x| stack.push gets}\n#$elem.print_mtx\nq.times {|_|\n com = stack.pop.split.map{|x| x.to_i}\n COMMAND[com.first.to_s].call(com.drop(1))\n}\n$elem.print_mtx", "positive_code": [{"source_code": "class Mat\n\tattr_reader :rows, :columns\n\n\tdef initialize(rows, columns)\n\t\t@data = []\n\t\t@rows = rows\n\t\t@columns = columns\n\t\tfor i in 1..rows\n\t\t\trow = []\n\t\t\tfor j in 1..columns\n\t\t\t\trow << nil\n\t\t\tend\n\t\t\t@data << row\n\t\tend\n\tend\n\t\n\tdef get(r, c)\n\t\t@data[r][c]\n\tend\n\tdef set(r, c, value)\n\t\t@data[r][c] = value\t\n\tend\n\t\n\tdef rotate_row(row, amt)\n\t\tamt += columns if amt < 0\n\t\trev_horiz(row, 0, amt - 1)\n\t\trev_horiz(row, amt, columns - 1)\n\t\trev_horiz(row, 0, columns - 1)\n\tend\n\t\n\tdef rotate_column(column, amt)\n\t\tamt += rows if amt < 0\n\t\trev_vert(column, 0, amt - 1)\n\t\trev_vert(column, amt, rows - 1)\n\t\trev_vert(column, 0, rows - 1)\n\tend\n\t\n\tdef print\n\t\t@data.each do |row|\n\t\t\tputs row.join(' ')\t\n\t\tend\n\tend\n\t\n\tprivate\n\t\n\tdef rev_horiz(row, start, finish)\n\t\twhile (start < finish)\n\t\t\ttmp = @data[row][start]\n\t\t\t@data[row][start] = @data[row][finish]\n\t\t\t@data[row][finish] = tmp\n\t\t\tstart += 1\n\t\t\tfinish -= 1\n\t\tend\n\tend\n\t\n\tdef rev_vert(col, start, finish)\n\t\twhile (start < finish)\n\t\t\ttmp = @data[start][col]\n\t\t\t@data[start][col] = @data[finish][col]\n\t\t\t@data[finish][col] = tmp\n\t\t\tstart += 1\n\t\t\tfinish -= 1\n\t\tend\n\tend\nend\n\n\nline = gets.chomp.split(' ')\nn = line[0].to_i\nm = line[1].to_i\nq = line[2].to_i\n\nRowOp = Struct.new(:row)\nColOp = Struct.new(:column)\nSetOp = Struct.new(:row, :column, :value)\n\nops = []\n\nfor i in 1..q\n\tline = gets.chomp.split(' ')\n\ttype = line[0].to_i\n\tcase type\n\t\twhen 1\n\t\t\tops << RowOp.new(line[1].to_i - 1)\n\t\twhen 2\n\t\t\tops << ColOp.new(line[1].to_i - 1)\n\t\telse\n\t\t\tops << SetOp.new(line[1].to_i - 1, line[2].to_i - 1, line[3].to_i)\n\tend\nend\n\nmatrix = Mat.new(n, m)\n\nops.reverse!\n\nfor i in 0..ops.length-1\n\tcase ops[i]\n\t\twhen SetOp\n\t\t\tmatrix.set(ops[i].row, ops[i].column, ops[i].value)\n\t\twhen RowOp\n\t\t\tmatrix.rotate_row(ops[i].row, -1)\n\t\twhen ColOp\n\t\t\tmatrix.rotate_column(ops[i].column, -1)\n\tend\nend\n\n\nfor i in 0..matrix.rows-1\n\tfor j in 0..matrix.columns-1\n\t\tmatrix.set(i, j, 0) if matrix.get(i, j).nil?\n\tend\nend\n\nmatrix.print"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end\n############################################################\n\nn, m, q = gis\n\na = arr2d n, m\n\nv = []\nn.times do |i|\n tv = []\n m.times do |j|\n tv << [i, j]\n end\n v << tv\nend\n\nq.times do\n t, *rcx = gis\n case t\n when 1\n r, * = rcx\n v[r - 1].rotate!\n when 2\n c, * = rcx\n ta = v[0][c - 1]\n (n - 1).times do |i|\n v[i][c - 1] = v[i + 1][c - 1]\n end\n v[n - 1][c - 1] = ta\n when 3\n r, c, x = rcx\n i, j = v[r - 1][c - 1]\n a[i][j] = x\n end\nend\n\na.map{|z| puts z.map(&:to_s) * \" \" }\n"}, {"source_code": "n, m, q = gets.chomp.split(\" \").map(&:to_i)\na = Array.new(n).map{Array.new(m, 0)}\nqs = []\nwhile line = gets\n qs << line.split(\" \").map(&:to_i)\nend\nqs.reverse.each do |ope|\n t = ope.shift\n if t == 1 then\n r = ope.shift - 1\n cyc = a[r].dup\n temp = cyc.pop\n cyc.unshift(temp)\n a[r] = cyc\n elsif t == 2 then\n c = ope.shift - 1\n cyc = a.map{|b| b[c]}\n temp = cyc.pop\n cyc.unshift(temp)\n n.times do |i|\n a[i][c] = cyc[i]\n end\n else\n r, c, x = ope\n r -= 1\n c -= 1\n a[r][c] = x\n end\nend\na.each do |r|\n puts r.join(\" \")\nend\n"}], "negative_code": [{"source_code": "class Mat\n\tattr_reader :rows, :columns\n\n\tdef initialize(rows, columns)\n\t\t@data = []\n\t\t@rows = rows\n\t\t@columns = columns\n\t\tfor i in 1..rows\n\t\t\trow = []\n\t\t\tfor j in 1..columns\n\t\t\t\trow << nil\n\t\t\tend\n\t\t\t@data << row\n\t\tend\n\tend\n\t\n\tdef get(r, c)\n\t\t@data[r][c]\n\tend\n\tdef set(r, c, value)\n\t\t@data[r][c] = value\t\n\tend\n\t\n\tdef rotate_row(row, amt)\n\t\tamt += rows if amt < 0\n\t\trev_horiz(row, 0, amt - 1)\n\t\trev_horiz(row, amt, rows - 1)\n\t\trev_horiz(row, 0, rows - 1)\n\tend\n\t\n\tdef rotate_column(column, amt)\n\t\tamt += columns if amt < 0\n\t\trev_vert(column, 0, amt - 1)\n\t\trev_vert(column, amt, columns - 1)\n\t\trev_vert(column, 0, columns - 1)\n\tend\n\t\n\tdef print\n\t\t@data.each do |row|\n\t\t\tputs row.join(' ')\t\n\t\tend\n\tend\n\t\n\tprivate\n\t\n\tdef rev_horiz(row, start, finish)\n\t\twhile (start < finish)\n\t\t\ttmp = @data[row][start]\n\t\t\t@data[row][start] = @data[row][finish]\n\t\t\t@data[row][finish] = tmp\n\t\t\tstart += 1\n\t\t\tfinish -= 1\n\t\tend\n\tend\n\t\n\tdef rev_vert(col, start, finish)\n\t\twhile (start < finish)\n\t\t\ttmp = @data[start][col]\n\t\t\t@data[start][col] = @data[finish][col]\n\t\t\t@data[finish][col] = tmp\n\t\t\tstart += 1\n\t\t\tfinish -= 1\n\t\tend\n\tend\nend\n\n\nline = gets.chomp.split(' ')\nn = line[0].to_i\nm = line[1].to_i\nq = line[2].to_i\n\nRowOp = Struct.new(:row)\nColOp = Struct.new(:column)\nSetOp = Struct.new(:row, :column, :value)\n\nops = []\n\nfor i in 1..q\n\tline = gets.chomp.split(' ')\n\ttype = line[0].to_i\n\tcase type\n\t\twhen 1\n\t\t\tops << RowOp.new(line[1].to_i - 1)\n\t\twhen 2\n\t\t\tops << ColOp.new(line[1].to_i - 1)\n\t\telse\n\t\t\tops << SetOp.new(line[1].to_i - 1, line[2].to_i - 1, line[3].to_i)\n\tend\nend\n\nmatrix = Mat.new(n, m)\n\n\nfirst_set = nil\nfor i in 0..ops.length-1\n\tnext if !first_set && !ops[i].is_a?(SetOp)\n\tfirst_set ||= i\n\t\n\tcase ops[i]\n\t\twhen SetOp\n\t\t\tmatrix.set(ops[i].row, ops[i].column, ops[i].value)\n\t\twhen RowOp\n\t\t\tmatrix.rotate_row(ops[i].row, 1)\n\t\twhen ColOp\n\t\t\tmatrix.rotate_column(ops[i].column, 1)\n\tend\nend\n\nrev_ops = ops[0..first_set-1].reverse\nrev_ops.each do |op|\n\tcase op\n\t\twhen RowOp\n\t\t\tmatrix.rotate_row(ops[i].row, -1)\n\t\twhen ColOp\n\t\t\tmatrix.rotate_column(ops[i].column, -1)\n\tend\nend\n\nfor i in 0..matrix.rows-1\n\tfor j in 0..matrix.columns-1\n\t\tmatrix.set(i, j, 0) if matrix.get(i, j).nil?\n\tend\nend\n\nmatrix.print"}, {"source_code": "class Numeric\n def sign\n self<=>0\n end\nend\n\nclass Array\n def loop_slide!(x=1)\n x = (x.abs % self.length) * (-x.sign)\n x += self.length if x < 0\n new_a = self.drop(x)+self.take(x)\n self.length.times{|i| self[i] = new_a[i]}\n end\n\n def second\n self[1]\n end\n\n def third\n self[2]\n end\nend\n\nclass XElement\n def initialize(n,m)\n @rows, @cols = n, m\n @mtx = Array.new\n n.times{@mtx.push Array.new(m, 0)}\n end\n\n def print_mtx\n @rows.times { |row|\n @cols.times { |col|\n print @mtx[row][col]\n print ' '\n }\n print \"\\n\"\n }\n #print \"\\n\"\n end\n\n def shift_row!(row_num)\n @mtx[row_num-1].loop_slide!\n end\n\n def shift_col!(col_num)\n column = Array.new\n @cols.times{|i| column.push(@mtx[i][col_num-1])}\n column.loop_slide!(-1)\n @cols.times{|i| @mtx[i][col_num-1] = column[i]}\n end\n\n def set_num!(row, col, value)\n row, col = row-1, col-1\n @mtx[row][col] = value\n end\n\n=begin\n def command!(args)\n COMMAND[args.first.to_s].call(args.drop(1))\n end\n=end\nend\n\nCOMMAND = {\n \"1\" => lambda{|x| $elem.shift_row!(x.first)},\n \"2\" => lambda{|x| $elem.shift_col!(x.first)},\n \"3\" => lambda{|x| $elem.set_num!(x.first, x.second, x.third)}\n}\n\nn,m,q, = gets.split.map{|x| x.to_i}\n$elem = XElement.new(n,m)\nstack = Array.new\nq.times {|x| stack.push gets}\n#$elem.print_mtx\nq.times {|_|\n com = stack.pop.split.map{|x| x.to_i}\n COMMAND[com.first.to_s].call(com.drop(1))\n\n}\n$elem.print_mtx"}], "src_uid": "f710958b96d788a19a1dda436728b9eb"} {"source_code": "require 'set'\n\ndef solve(a, s)\n front = Hash.new do |h, diff|\n h[diff] = diff.abs - 2\n end\n a = a.to_set\n\n pts = s.map do |diff|\n existing = front[diff]\n\n left = front[diff + 1]\n return -1 if left < existing\n right = front[diff - 1]\n return -1 if right < existing\n\n nw = existing + 2\n # y + x = nw\n # y - x = diff\n y = (nw + diff) / 2\n x = (nw - diff) / 2\n pt = [x,y]\n return -1 unless a.include?(pt)\n\n front[diff] = nw\n pt\n end\nend\n\nn = gets.to_i\na = Array.new(n) { gets.split.map(&:to_i) }\ndiffs = gets.split.map(&:to_i)\n\nres = solve(a, diffs)\nif res == -1\n puts 'NO'\nelse\n puts 'YES'\n puts res.map{|cs| cs.join(' ')}\nend\n", "positive_code": [{"source_code": "points = Array.new { Array.new(3) }\na = Array.new { Array.new(2) }\nn = STDIN.gets.to_i\n\ndef check_values(a, points, n)\n points.sort! do |x, y|\n if x[2] != y[2]\n x[2] <=> y[2]\n else\n x[0] <=> y[0]\n end\n end\n a.sort! do |x, y| \n if x[0] != y[0]\n x[0] <=> y[0]\n else\n x[1] <=> y[1]\n end\n end\n \n a.each_with_index do |val, i|\n if (val[0] != points[i][2])\n return false\n end\n end\n\n return true\nend\n\ndef print_res(a, points, n)\n if !check_values(a, points, n)\n puts \"NO\"\n return\n else\n res = Array.new\n points.each_with_index do |point, i|\n res[a[i][1]] = point\n end\n\n #min_x = 0\n #min_y = 0\n #max_x = 0\n #max_y = 0\n #print \"#{res} \\n\"\n max_l = 0\n max_r = 0\n #res.each_with_index do |r, i|\n #if (r[0] < min_x && r[1] < max_y) || (r[0] < max_x && r[1] < min_y)\n # print \"#{r[0]} #{r[1]} #{min_x} #{max_x} #{max_y} \"\n # puts \"NO\"\n # return\n #else\n # if r[0] > max_x\n # max_x = r[0]\n # min_y = r[1]\n # end\n # if r[1] > max_y\n # max_y = r[1]\n # min_x = r[0]\n # end\n # print \"#{max_y} #{r[1]} \"\n # for j in 0..i-1 do\n # if r[0] < res[j][0] && r[1] < res[j][1]\n # puts \"NO\"\n # return\n # end\n # end\n # cur_l = r[1] - r[0]\n # cur_r = r[0] - r[1]\n # if (max_l > cur_l && max_r > cur_r)\n # puts \"NO\"\n # return\n # end\n # max_l = cur_l if max_l > \n \n #end\n for i in 1..n - 1 do\n if res[i][0] <= res[i-1][0] && res[i][1] <= res[i-1][1]\n puts \"NO\"\n return\n end\n end\n \n puts \"YES\"\n res.each do |r|\n puts \"#{r[0]} #{r[1]}\"\n end\n end\nend\n\nfor i in 0..n-1 do\n points.push(STDIN.gets.split(\" \").to_a.map{|q| q.to_i})\n points[i][2] = points[i][1] - points[i][0]\nend\n\nSTDIN.gets.split(\" \").to_a.each_with_index do |num, i|\n a.push((num + \" #{i}\").split(\" \").to_a.map{|q| q.to_i})\nend\n\nprint_res(a, points, n)\n"}, {"source_code": "n = gets.chomp.to_i\n\ndiff = []\nmap_x = {}\nmap_y = {}\n\n\nn.times do\n x,y = gets.chomp.split.map(&:to_i)\n d = y - x\n \n diff << d\n \n if(!map_x[d])\n \n map_x[d] = [] \n map_y[d] = []\n end\n \n map_x[d] << x\n map_y[d] << y\n \nend\n\nws = gets.chomp.split.map(&:to_i)\n\npx = []\npy = []\n\nmap_x.keys.each do |k|\n map_x[k].sort!.reverse!\nend\n\nmap_y.keys.each do |k|\n map_y[k].sort!.reverse!\nend\n\nenable = true\n\nif(diff.sort != ws.sort)\n \n enable = false\nelse\n ws.each do |d| \n if(!map_x[d] || map_x[d].empty?)\n enable = false;\n break;\n end\n px << map_x[d].pop\n py << map_y[d].pop\n \n end \nend\n\nif enable\n x = -1\n y = -1\n \n 0.upto(px.size - 1) do |index|\n if(px[index] <= x && py[index] <= y)\n enable = false\n break;\n end\n x = px[index]\n y = py[index]\n end\nend\n\nif(enable)\n puts \"YES\"\n 0.upto(px.size - 1) do |index|\n printf(\"%d %d\\n\", px[index], py[index]); \n end\n \nelse \n puts \"NO\"\nend\n\n\n\n\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\n\ndiff = []\nmap_x = {}\nmap_y = {}\n\n\nn.times do\n x,y = gets.chomp.split.map(&:to_i)\n d = y - x\n \n diff << d\n \n if(!map_x[d])\n \n map_x[d] = [] \n map_y[d] = []\n end\n \n map_x[d] << x\n map_y[d] << y\n \nend\n\nws = gets.chomp.split.map(&:to_i)\n\npx = []\npy = []\n\nmap_x.keys.each do |k|\n map_x[k].sort!.reverse!\nend\n\nmap_y.keys.each do |k|\n map_y[k].sort!.reverse!\nend\n\nenable = true\n\nif(diff.sort != ws.sort)\n \n enable = false\nelse\n ws.each do |d| \n if(!map_x[d] || map_x[d].empty?)\n enable = false;\n break;\n end\n px << map_x[d].pop\n py << map_y[d].pop\n \n end \nend\n\nif enable\n x = -1\n y = -1\n \n 0.upto(px.size - 1) do |index|\n if(px[index] < x && py[index] < y)\n puts \"h3e\";\n enable = false\n break;\n end\n x = px[index]\n y = py[index]\n end\nend\n\nif(enable)\n puts \"YES\"\n 0.upto(px.size - 1) do |index|\n printf(\"%d %d\\n\", px[index], py[index]); \n end\n \nelse \n puts \"NO\"\nend\n\n\n\n\n"}, {"source_code": "n = gets.chomp.to_i\n\ndiff = []\nmap_x = {}\nmap_y = {}\n\n\nn.times do\n x,y = gets.chomp.split.map(&:to_i)\n d = y - x\n \n diff << d\n \n if(!map_x[d])\n \n map_x[d] = [] \n map_y[d] = []\n end\n \n map_x[d] << x\n map_y[d] << y\n \nend\n\nws = gets.chomp.split.map(&:to_i)\n\npx = []\npy = []\n\nmap_x.keys.each do |k|\n map_x[k].sort!.reverse!\nend\n\nmap_y.keys.each do |k|\n map_y[k].sort!.reverse!\nend\n\nenable = true\n\nif(diff.sort != ws.sort)\n \n enable = false\nelse\n ws.each do |d| \n if(!map_x[d] || map_x[d].empty?)\n enable = false;\n break;\n end\n px << map_x[d].pop\n py << map_y[d].pop\n \n end \nend\n\nif enable\n x = -1\n y = -1\n \n 0.upto(px.size - 1) do |index|\n if(px[index] < x && py[index] < y)\n enable = false\n break;\n end\n x = px[index]\n y = py[index]\n end\nend\n\nif(enable)\n puts \"YES\"\n 0.upto(px.size - 1) do |index|\n printf(\"%d %d\\n\", px[index], py[index]); \n end\n \nelse \n puts \"NO\"\nend\n\n\n\n\n"}, {"source_code": "points = Array.new { Array.new(3) }\na = Array.new { Array.new(2) }\nn = STDIN.gets.to_i\n\ndef check_values(a, points, n)\n points.sort! do |x, y|\n if x[2] != y[2]\n x[2] <=> y[2]\n else\n x[1] <=> y[1]\n end\n end\n a.sort! { |x, y| x[0] <=> y[0] }\n \n a.each_with_index do |val, i|\n if (val[0] != points[i][2])\n return false\n end\n end\n\n return true\nend\n\ndef print_res(a, points, n)\n if !check_values(a, points, n)\n puts \"NO\"\n return\n else\n a.sort! { |x, y| x[0] <=> y[0] }\n res = Array.new\n points.each_with_index do |point, i|\n res[a[i][1]] = point\n end\n \n max_x = 0\n max_y = 0\n res.each do |r|\n if r[0] < max_x && r[1] < max_y\n puts \"NO\"\n return\n else\n max_x = r[0] if r[0] > max_x\n max_y = r[1] if r[1] > max_y\n end\n end\n \n puts \"YES\"\n res.each do |r|\n puts \"#{r[0]} #{r[1]}\"\n end\n end\nend\n\nfor i in 0..n-1 do\n points.push(STDIN.gets.split(\" \").to_a.map{|q| q.to_i})\n points[i][2] = points[i][1] - points[i][0]\nend\n\nSTDIN.gets.split(\" \").to_a.each_with_index do |num, i|\n a.push((num + \" #{i}\").split(\" \").to_a.map{|q| q.to_i})\nend\n\nprint_res(a, points, n)\n"}, {"source_code": "points = Array.new { Array.new(3) }\na = Array.new { Array.new(2) }\nn = STDIN.gets.to_i\n\ndef check_values(a, points, n)\n points.sort! do |x, y|\n if x[2] != y[2]\n x[2] <=> y[2]\n else\n x[1] <=> y[1]\n end\n end\n a.sort! { |x, y| x[0] <=> y[0] }\n \n a.each_with_index do |val, i|\n if (val[0] != points[i][2])\n return false\n end\n end\n\n return true\nend\n\ndef print_res(a, points, n)\n if !check_values(a, points, n)\n puts \"NO\"\n return\n else\n a.sort! { |x, y| x[0] <=> y[0] }\n res = Array.new\n points.each_with_index do |point, i|\n res[a[i][1]] = point\n end\n \n max_x = 0\n max_y = 0\n res.each do |r|\n if r[0] < max_x && r[1] < max_y\n puts \"NO\"\n return\n else\n max_x = r[0] if r[0] > max_x\n max_y = r[1] if r[1] > max_y\n end\n end\n \n puts \"Yes\"\n res.each do |r|\n puts \"#{r[0]} #{r[1]}\"\n end\n end\nend\n\nfor i in 0..n-1 do\n points.push(STDIN.gets.split(\" \").to_a.map{|q| q.to_i})\n points[i][2] = points[i][1] - points[i][0]\nend\n\nSTDIN.gets.split(\" \").to_a.each_with_index do |num, i|\n a.push((num + \" #{i}\").split(\" \").to_a.map{|q| q.to_i})\nend\n\nprint_res(a, points, n)\n"}, {"source_code": "points = Array.new { Array.new(3) }\na = Array.new { Array.new(2) }\nn = STDIN.gets.to_i\n\ndef check_values(a, points, n)\n points.sort! do |x, y|\n if x[2] != y[2]\n x[2] <=> y[2]\n else\n x[0] <=> y[0]\n end\n end\n a.sort! do |x, y| \n if x[0] != y[0]\n x[0] <=> y[0]\n else\n x[1] <=> y[1]\n end\n end\n \n a.each_with_index do |val, i|\n if (val[0] != points[i][2])\n return false\n end\n end\n\n return true\nend\n\ndef print_res(a, points, n)\n if !check_values(a, points, n)\n puts \"NO\"\n return\n else\n res = Array.new\n points.each_with_index do |point, i|\n res[a[i][1]] = point\n end\n \n max_x = 0\n max_y = 0\n # print \"#{res} \\n\"\n # res.each do |r|\n # if r[0] < max_x && r[1] < max_y\n # print \"#{r[0]} #{r[1]} #{max_x} #{max_y} \"\n # puts \"NO\"\n # return\n # else\n # max_x = r[0] if r[0] > max_x\n # max_y = r[1] if r[1] > max_y\n # print \"#{max_y} #{r[1]} \"\n # end\n #end\n \n puts \"YES\"\n res.each do |r|\n puts \"#{r[0]} #{r[1]}\"\n end\n end\nend\n\nfor i in 0..n-1 do\n points.push(STDIN.gets.split(\" \").to_a.map{|q| q.to_i})\n points[i][2] = points[i][1] - points[i][0]\nend\n\nSTDIN.gets.split(\" \").to_a.each_with_index do |num, i|\n a.push((num + \" #{i}\").split(\" \").to_a.map{|q| q.to_i})\nend\n\nprint_res(a, points, n)\n"}, {"source_code": "points = Array.new { Array.new(3) }\na = Array.new { Array.new(2) }\nn = STDIN.gets.to_i\n\ndef check_values(a, points, n)\n points.sort! do |x, y|\n if x[2] != y[2]\n x[2] <=> y[2]\n else\n x[0] <=> y[0]\n end\n end\n a.sort! do |x, y| \n if x[0] != y[0]\n x[0] <=> y[0]\n else\n x[1] <=> y[1]\n end\n end\n \n a.each_with_index do |val, i|\n if (val[0] != points[i][2])\n return false\n end\n end\n\n return true\nend\n\ndef print_res(a, points, n)\n if !check_values(a, points, n)\n puts \"NO\"\n return\n else\n res = Array.new\n points.each_with_index do |point, i|\n res[a[i][1]] = point\n end\n\n min_x = 0\n min_y = 0\n max_x = 0\n max_y = 0\n #print \"#{res} \\n\"\n res.each do |r|\n if (r[0] < min_x && r[1] < max_y) && (r[0] < max_x && r[1] < max_y)\n #print \"#{r[0]} #{r[1]} #{max_x} #{max_y} \"\n puts \"NO\"\n return\n else\n if r[0] > max_x\n max_x = r[0]\n min_y = r[1]\n end\n if r[1] > max_y\n max_y = r[1]\n min_x = r[0]\n end\n # print \"#{max_y} #{r[1]} \"\n end\n end\n \n puts \"YES\"\n res.each do |r|\n puts \"#{r[0]} #{r[1]}\"\n end\n end\nend\n\nfor i in 0..n-1 do\n points.push(STDIN.gets.split(\" \").to_a.map{|q| q.to_i})\n points[i][2] = points[i][1] - points[i][0]\nend\n\nSTDIN.gets.split(\" \").to_a.each_with_index do |num, i|\n a.push((num + \" #{i}\").split(\" \").to_a.map{|q| q.to_i})\nend\n\nprint_res(a, points, n)\n"}, {"source_code": "points = Array.new { Array.new(3) }\na = Array.new { Array.new(2) }\nn = STDIN.gets.to_i\n\ndef check_values(a, points, n)\n points.sort! do |x, y|\n if x[2] != y[2]\n x[2] <=> y[2]\n else\n x[1] <=> y[1]\n end\n end\n #print points\n #puts\n a.sort! { |x, y| x[0] <=> y[0] }\n \n a.each_with_index do |val, i|\n if (val[0] != points[i][2])\n return false\n end\n end\n\n return true\nend\n\ndef print_res(a, points, n)\n if !check_values(a, points, n)\n puts \"NO\"\n return\n else\n res = Array.new\n points.each_with_index do |point, i|\n res[a[i][1]] = point\n end\n \n max_x = 0\n max_y = 0\n res.each do |r|\n if r[0] < max_x && r[1] < max_y\n puts \"NO\"\n return\n else\n max_x = r[0] if r[0] > max_x\n max_y = r[1] if r[1] > max_y\n end\n end\n \n puts \"YES\"\n res.each do |r|\n puts \"#{r[0]} #{r[1]}\"\n end\n end\nend\n\nfor i in 0..n-1 do\n points.push(STDIN.gets.split(\" \").to_a.map{|q| q.to_i})\n points[i][2] = points[i][1] - points[i][0]\nend\n\nSTDIN.gets.split(\" \").to_a.each_with_index do |num, i|\n a.push((num + \" #{i}\").split(\" \").to_a.map{|q| q.to_i})\nend\n\nprint_res(a, points, n)\n"}], "src_uid": "ad186f6df24d31243cde541b7fc69a8c"} {"source_code": "s = gets.chomp\nchar_count = Hash.new(0)\ns.each_char do |c|\n\tchar_count[c] += 1\nend\nodd_count = char_count.values.count{|a| a.odd? }\nif odd_count == 1 || odd_count == 0\n\tfirst = true\nelsif s.length % 2 == 0\n\tfirst = false\nelse\n\tfirst = true\nend\nputs first ? \"First\" : \"Second\"", "positive_code": [{"source_code": "s, ans = gets.to_s.chomp, 0\ns_ = s.split(//).uniq\ns_.each{|chr| ans += 1 if s.count(chr).odd?}\n(ans.odd? or ans.zero?) ? (puts \"First\") : (puts \"Second\")\n"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\nchars = gets.chomp.split(\"\")\n\nhash = Hash.new 0\nchars.each do |char|\n hash[char] += 1\nend\n\nodds = 0\nhash.each do |key, value|\n odds += 1 if value % 2 == 1\nend\n\nputs (odds == 0 or odds % 2 == 1) ? \"First\" : \"Second\"\n\n\n\n \n\n"}, {"source_code": "hash=Array.new(26,0)\ngets.chomp.split('').each{ |i| hash[i.ord-97]+=1 }\nct=0\nhash.each{ |i| ct+=1 if i&1==1 }\nputs (ct==0 || ct&1!=0) ? \"First\" : \"Second\""}, {"source_code": "def is_palindrome?(word)\n\todd_count = 0\n\tword.uniq.map do |x|\n\t\todd_count = odd_count + 1 if word.count(x).odd?\n\tend\n\tif odd_count > 1\n\t\tfalse\n\telse\n\t\ttrue\n\tend\nend\n\ndef remove_letter(stringArray)\n\tstringArray.uniq.map do |x|\n\t\tif stringArray.count(x) == 1\n\t\t\tstringArray.delete(x)\n\t\t\tputs stringArray\n\t\t\treturn stringArray\n\t\telse\n\t\t\treturn stringArray\n\t\tend\n\tend\nend\n\ndef do_stuff(stringArray)\n\tif is_palindrome(stringArray)\n\t\t\"win\"\n\telse\n\t\tnext_turn\n\tend\nend\n\ndef test(word)\n\todd_count = 0\n\tword.uniq.map do |x|\n\t\todd_count = odd_count + 1 if word.count(x).odd?\n\tend\n\tif odd_count.odd? || odd_count <= 1\n\t\tputs \"First\"\n\telse\n\t\tputs \"Second\"\n\tend\nend\n\nstring = \"aabb\"\nstringArray = gets.chomp.split(//)\n\ntest(stringArray)"}, {"source_code": "# coding: utf-8\n\ns = gets.chomp.split(//)\nco = Array.new(26) { 0 }\nl = s.length\nfor c in s\n co[c.ord - 'a'.ord] += 1\nend\nturns = 0\nodds = co.count { |c| c.odd? }\nif odds > 1\n turns += odds - 1\nend\n\nif turns.even?\n puts \"First\"\nelse\n puts \"Second\"\nend\n\n\n# \uac01 \ud134\uc5d0\uc11c \uc784\uc758\uc758 \ud55c \uae00\uc790\ub97c \uc9c0\uc6b8 \uc218 \uc788\ub2e4\n# \uac01 \ud134\uc774 \ub3cc\uc544\uc624\uae30 \uc804 \ud50c\ub808\uc774\uc5b4\ub294 \uae00\uc790\ub97c \uc7ac\ubc30\uce58\ud558\uc5ec\n# \ud330\ub9b0\ub4dc\ub86c\uc744 \uad6c\uc131\ud560 \uc218 \uc788\ub2e4. \uc774\ub7ec\uba74 \uc2b9\ub9ac\ud55c\ub2e4.\n# \ub450 \ud50c\ub808\uc774\uc5b4\uac00 \ucd5c\uc801\uc758 \ud50c\ub808\uc774\ub97c \uc218\ud589\ud560 \ub54c \ub204\uac00 \uc774\uae38\uac83\uc778\uac00?\n\n# \ud330\ub9b0\ub4dc\ub86c\uc744 \uad6c\uc131\ud558\uae30 \uc704\ud574 \ucd5c\uc18c\ub85c \uc9c0\uc6cc\uc57c\ud558\ub294 \ubb38\uc790\uc218 = \ud134 \uc218\n# \uc774 \uc218\uc5d0 \ub530\ub77c \uc2b9\ud328\uac00 \uac08\ub9b0\ub2e4.\n# \uc804\uccb4 \ubb38\uc790\ub294 reorder \ub420 \uc218 \uc788\uc73c\ubbc0\ub85c \ubb38\uc790\uc758 \ubc30\uc5f4 \uc21c\uc11c\ub294\n# \uc911\uc694\ud558\uc9c0 \uc54a\ub2e4. \ud68c\ubb38\uc744 \uad6c\uc131\ud560 \uc218 \uc788\ub294\uc9c0 \uc5ec\ubd80\ub9cc \uc911\uc694\ud55c\ub4ef\n"}, {"source_code": "s = gets.strip\n\nif s == s.reverse\n\tprint :First\nelse\n\tar = s.split('')\n\n\tletters = {}\n\tar.each do |let|\n\t\tif letters[let]\n\t\t\tletters[let] += 1\n\t\telse\n\t\t\tletters[let] = 1\n\t\tend\n\tend\n\n\tsum = 0\n\tletters.each_value do |num|\n\t\tsum += 1 if !num.even?\n\tend\n\n\t# p sum\n\t# p (sum-1).even? \n\n\tif sum == 0 || (sum-1).even? \n\t\tprint :First\n\telse\n\t\tprint :Second\n\tend\nend\n\n\n"}, {"source_code": "s = gets.chomp\nhash = {}\ns.each_char { |ch|\n\tif !hash.has_key? ch\n\t\thash[ch] = 1\n\telse\n\t\thash[ch] +=1\n\tend\n}\n\nn = 0\n\nhash.values.each { |v|\n if v%2==1\n\tn += 1\n end\n}\n\nk = n%2\nif n==0\n k=1\nend\nputs (k==1) ? \"First\" : \"Second\""}, {"source_code": "class String\n def is_possible_palindrome?\n g = self.split('').inject(Hash.new(0)) { |h, e| h[e] += 1; h }\n odd = false\n g.values.each { |v|\n if v.odd?\n if odd\n return false\n else\n odd = true\n end\n end\n }\n true\n end\nend\n\nw = gets.chomp\nputs(w.is_possible_palindrome? || w.size.odd? ? 'First' : 'Second')"}, {"source_code": "# Codeforces Round #169\n# Problem B -- Little Girl and Game\ncount = [0] * 26\ngets.chomp.each_char do |c|\n count[c.ord - 'a'.ord] += 1\nend\nodds = count.count { |x| x % 2 == 1 }\nputs (odds <= 1 or odds % 2 == 1) ? \"First\" : \"Second\"\n"}, {"source_code": "s = gets.strip\t\na = Array.new(30, 0)\ns.size.times do |i| \n\ta[ s[i].ord - 'a'.ord] += 1\nend\nans = 0\n26.times do |i|\n\ta[i] -= (a[i]/2)*2\t\n\tans += a[i]\nend\nputs (ans>0 && ans%2==0) ? \"Second\" : \"First\""}, {"source_code": "s = gets.to_s.chomp\ns_ = s.split(//).uniq\nans = 0\ns_.each do |chr|\n\t\tans += 1 if s.count(chr).odd?\nend\nif ans.odd? or ans.zero? then\n\tputs \"First\"\n\telse\n\t\tputs \"Second\"\nend\n"}], "negative_code": [{"source_code": "n,k=gets.chomp.split.map(&:to_i)\nm=[]\nn.times do\n\ta,b=gets.chomp.split.map(&:to_i)\n\tif b>k\n\t\tm.push(a-b+k)\n\telse\n\t\tm.push(a)\n\tend\nend\nputs m.max"}, {"source_code": "def is_palindrome?(word)\n\todd_count = 0\n\tword.uniq.map do |x|\n\t\todd_count = odd_count + 1 if word.count(x).odd?\n\tend\n\tif odd_count > 1\n\t\tfalse\n\telse\n\t\ttrue\n\tend\nend\n\ndef remove_letter(stringArray)\n\tstringArray.uniq.map do |x|\n\t\tif stringArray.count(x) == 1\n\t\t\tstringArray.delete(x)\n\t\t\tputs stringArray\n\t\t\treturn stringArray\n\t\telse\n\t\t\treturn stringArray\n\t\tend\n\tend\nend\n\ndef do_stuff(stringArray)\n\tif is_palindrome(stringArray)\n\t\t\"win\"\n\telse\n\t\tnext_turn\n\tend\nend\n\ndef test(word)\n\todd_count = 0\n\tword.uniq.map do |x|\n\t\todd_count = odd_count + 1 if word.count(x).odd?\n\tend\n\tif odd_count.odd?\n\t\tputs \"First\"\n\telse\n\t\tputs \"Second\"\n\tend\nend\n\nstring = \"abddddbca\"\nstringArray = gets.chomp.split(//)\n\ntest(stringArray)"}, {"source_code": "s = gets.strip\n\nif s == s.reverse\n\tprint :First\nelse\n\tar = s.split('')\n\n\tletters = {}\n\tar.each do |let|\n\t\tif letters[let]\n\t\t\tletters[let] += 1\n\t\telse\n\t\t\tletters[let] = 1\n\t\tend\n\tend\n\n\tsum = 0\n\tletters.each_value do |num|\n\t\tsum += 1 if !num.even?\n\tend\n\n\t# p sum\n\n\tif sum = 0 || !(sum-1).even? \n\t\tprint :First\n\telse\n\t\tprint :Second\n\tend\nend\n\n\n"}, {"source_code": "s = gets.strip\n\nif s == s.reverse\n\tprint :First\nelse\n\tar = s.split('')\n\n\tletters = {}\n\tar.each do |let|\n\t\tif letters[let]\n\t\t\tletters[let] += 1\n\t\telse\n\t\t\tletters[let] = 1\n\t\tend\n\tend\n\n\tsum = 0\n\tletters.each_value do |num|\n\t\tsum += 1 if !num.even?\n\tend\n\n\tif sum = 0 || (sum-1).even? \n\t\tprint :First\n\telse\n\t\tprint :Second\n\tend\nend\n\n\n"}, {"source_code": "s = gets.strip\n\nif s == s.reverse\n\tprint :First\nelse\n\tar = s.split('')\n\n\tletters = {}\n\tar.each do |let|\n\t\tif letters[let]\n\t\t\tletters[let] += 1\n\t\telse\n\t\t\tletters[let] = 1\n\t\tend\n\tend\n\n\tsum = 0\n\tletters.each_value do |num|\n\t\tsum += 1 if !num.even?\n\tend\n\n\tif (sum-1).even?\n\t\tprint :First\n\telse\n\t\tprint :Second\n\tend\nend\n\n\n"}, {"source_code": "s = gets.chomp\nchar_count = Hash.new(0)\ns.each_char do |c|\n\tchar_count[c] += 1\nend\nodd_count = char_count.values.count{|a| a.odd? }\nif odd_count == 1\n\tfirst = true\nelsif s.length % 2 == 0\n\tfirst = false\nelse\n\tfirst = true\nend\nputs first ? \"First\" : \"Second\""}, {"source_code": "class String\n def is_palindrome?\n self[0...size / 2] == self[-size / 2..-1].reverse\n end\nend\n\nw = gets.chomp\nputs(w.is_palindrome? || w.size.odd? ? 'First' : 'Second')"}], "src_uid": "bbf2dbdea6dd3aa45250ab5a86833558"} {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n = gets.chomp.to_i\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n arr = arr.sort.reverse\r\n ch = 0\r\n a = b = 0\r\n arr.each do |el|\r\n if ch == 0 && el % 2 == 0\r\n a += el\r\n end\r\n if ch == 1 && el % 2 == 1\r\n b += el\r\n end\r\n ch = 1 - ch\r\n end\r\n case\r\n when a > b\r\n puts \"Alice\"\r\n when b > a\r\n puts \"Bob\"\r\n else\r\n puts \"Tie\"\r\n end\r\nend", "positive_code": [{"source_code": "def arline\r\n gets.chomp.split.map(&:to_i)\r\nend\r\n\r\ndef solve\r\n n = gets.chomp.to_i\r\n ar = arline.sort.reverse\r\n odd = ar.select{|x| x%2 == 1}.sum\r\n alice = ar.zip(0..n).select{|x, y| y%2 == 0}.map{|x| x[0]}.sum\r\n\r\n case odd <=> alice\r\n when 0\r\n puts \"Tie\"\r\n when 1\r\n puts \"Bob\"\r\n when -1\r\n puts \"Alice\"\r\n end\r\nend\r\n\r\ntc = gets.chomp.to_i\r\n(1..tc).each do\r\n solve\r\nend\r\n"}, {"source_code": "def solve()\r\n odds, evens = [], []\r\n n = gets.to_i\r\n nums = gets.chomp.split.map!(&:to_i)\r\n nums.each do |i|\r\n i.odd? ? odds.append(i) : evens.append(i)\r\n end\r\n odds.sort!\r\n evens.sort!\r\n alice_point = 0\r\n bob_point = 0\r\n alices_turn = true\r\n until (odds.empty? && evens.empty?) do\r\n # puts \"Size:#{odds.length}, #{evens.length}\"\r\n if alices_turn\r\n if evens.empty? \r\n odds.pop\r\n elsif (not odds.empty?) and odds.last > evens.last\r\n odds.pop\r\n else\r\n alice_point += evens.pop\r\n end\r\n else\r\n if odds.empty? \r\n evens.pop\r\n elsif (not evens.empty?) and evens.last > odds.last\r\n evens.pop\r\n else\r\n bob_point += odds.pop\r\n end\r\n end\r\n alices_turn = !alices_turn\r\n end\r\n res = alice_point <=> bob_point\r\n if res == 1\r\n puts \"Alice\"\r\n elsif res == 0\r\n puts \"Tie\"\r\n else \r\n puts \"Bob\"\r\n end\r\nend\r\n\r\ntcase = gets.to_i\r\ntcase.times do solve() end"}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i).sort.reverse\n\tx, y = 0, 0\n\ta.each_with_index do |val, i|\n\t\tx += val if i.even? && val.even?\n\t\ty += val if i.odd? && val.odd?\n\tend\n\tputs x < y ? 'Bob' : x > y ? 'Alice' : 'Tie'\nend\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n a.sort!.reverse!\r\n res = [0, 0]\r\n a.each_with_index do |it, i|\r\n res[1] += it if it % 2 == 1 && i % 2 == 1\r\n res[0] += it if it % 2 == 0 && i % 2 == 0\r\n end\r\n puts res[0] > res[1] ? \"Alice\" : (res[0] < res[1] ? \"Bob\" : \"Tie\")\r\nend"}, {"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n a=gets.split.map(&:to_i).sort.reverse\r\n f=0\r\n s=0\r\n n.times do |i|\r\n if i.even?\r\n if a[i].even?\r\n f+=a[i]\r\n end\r\n else\r\n if a[i].odd?\r\n s+=a[i]\r\n end\r\n end\r\n end\r\n if f>s\r\n puts \"Alice\"\r\n elsif f 0 && y > 0\n if x == 0 && y == 0\n puts move\n else\n move += 1\n if x > 0\n x -= 1\n else\n y -= 1\n end\n if x == 0 && y == 0\n puts move\n else\n (\n x -= 2\n move += 4\n ) while x > 1\n (\n y -= 2\n move += 4\n ) while y > 1\n if x == 1 || y == 1\n move += 2 \n end\n puts move\n end\n end\n end\n}", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n x, y = gets.chomp.split(' ').map(&:to_i).map{|el| el.abs}\n if (x - y).abs < 2\n puts x + y\n else\n x, y = y, x if x < y\n puts x + y + (x - y) - 1\n end\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n x, y = gets.chomp.split(\" \").map(&:to_i)\n big = [x,y].max\n small = [x,y].min\n sa = big - small\n if x == 0 && y == 0\n puts \"0\"\n elsif sa <= 1\n puts big + small\n else\n puts small * 2 + (big - small - 1)*2 + 1\n end\nend"}, {"source_code": "n = gets.to_i\nn.times do\n x, y = gets.chomp!.split.map(&:to_i)\n x, y = y, x unless x >= y\n if x > y\n p y * 2 + ((x - y) * 2 - 1)\n else\n p y * 2\n end\nend\n"}, {"source_code": "def get_int\n gets.chomp.to_i\nend\n\nget_int.times do |i|\n x, y = gets.split.map(&:to_i)\n puts 2 * [x, y].max - 1 + ((x == y) ? 1 : 0)\nend\n"}], "negative_code": [], "src_uid": "8864c6a04fed970fcbc04e220df9d88d"} {"source_code": "a = [4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292]\nn = gets.chomp.to_i\nputs n < 12 ? a[n - 1] : (n - 12) * 49 + 341", "positive_code": [{"source_code": "def comb3(n)\n n < 0 ? 0 : (n+1)*(n+2)*(n+3)/6\nend\nN = gets.to_i\nputs comb3(N) - comb3(N-6) - 2*comb3(N-9) + comb3(N-10) + comb3(N-14)"}], "negative_code": [], "src_uid": "75ec99318736a8a1b62a8d51efd95355"} {"source_code": "def is_posible?(s, k)\n n = s.size\n return true if n == k\n chars = [0]*255\n s[0...k].split(\"\").each{ |c| chars[c.ord] += 1 }\n i = 1\n\n while i+k <= n do\n chars[s[i+k-1].ord] += 1 if chars[s[i+k-1].ord] and chars[s[i+k-1].ord] > 0\n chars[s[i-1].ord] -= 1 if chars[s[i-1].ord]\n i += 1\n end\n\n chars.each do |v|\n return true if v > 0\n end\n false\nend\n\n\ndef solution(s)\n beg = 1\n last = s.size - 1\n min_k = s.size\n\n while (beg <= last) do\n mid = (last + beg)/2\n\n if is_posible?(s, mid)\n min_k = mid\n last = mid - 1\n else\n beg = mid + 1\n end\n end\n min_k\nend\n\nputs solution(gets.strip())\n", "positive_code": [{"source_code": "def is_posible?(s, k)\n n = s.size\n return true if n == k\n chars = [0]*255\n s[0...k].split(\"\").each{ |c| chars[c.ord] += 1 }\n i = 1\n\n while i+k <= n do\n chars[s[i+k-1].ord] += 1 if chars[s[i+k-1].ord] and chars[s[i+k-1].ord] > 0\n chars[s[i-1].ord] -= 1 if chars[s[i-1].ord]\n i += 1\n end\n\n chars.each do |v|\n return true if v > 0\n end\n false\nend\n\n\ndef solution(s)\n beg = 1\n last = s.size - 1\n min_k = s.size\n\n while (beg <= last) do\n mid = (last + beg)/2\n\n if is_posible?(s, mid)\n min_k = mid\n last = mid - 1\n else\n beg = mid + 1\n end\n end\n min_k\nend\n\nputs solution(gets.strip())"}, {"source_code": "module Memoizer\n def memoize(methodname)\n raise ArgumentError, \"statefull method [#{methodname}]should not be memoized\" if methodname.match(/\\!\\z/)\n unbound_method = instance_method(methodname)\n raise ArgumentError, \"method [#{methodname}] with argument cannot be memoized\" if unbound_method.arity > 0\n memoized_object_name = \"@_memoized_#{methodname}\"\n define_method(methodname) do\n if(instance_variable_get(memoized_object_name).nil?)\n instance_variable_set(memoized_object_name, unbound_method.bind(self).call)\n end\n instance_variable_get(memoized_object_name)\n end\n end\nend\n\nclass Array\n def enumerate(&block)\n self.zip(0..length).map(&block)\n end\nend\nclass Problem\n def initialize(xs)\n @xs = xs\n @last_index = Array.new(30){ -1 }\n @longests = Array.new(30){ -1 }\n end\n\n def solve!\n @xs.split(\"\").each.with_index do |x, i|\n p = x.ord - 'a'.ord\n distance = i - @last_index[p]\n @longests[p] = [@longests[p], distance].max\n @last_index[p] = i\n end\n l = @xs.length\n (0..26).each do |x|\n distance = l - @last_index[x]\n @longests[x] = [@longests[x], distance].max\n end\n end\n\n attr_reader(:longests)\n attr_reader(:last_index)\nend\n\nprob = Problem.new(gets.strip)\nprob.solve!\nprint prob.longests.select{|x| x >= 0 }.min\n"}], "negative_code": [{"source_code": "def is_posible?(s, k)\n n = s.size\n return true if n == k\n chars = {}\n s[0...k].split(\"\").uniq.each{ |c| chars[c] = 1 }\n i = 1\n\n while i+k < n do\n chars[s[i+k-1]] += 1 if chars[s[i+k-1]] and chars[s[i+k-1]] > 0\n chars[s[i-1]] -= 1 if chars[s[i-1]] and chars[s[i-1]] > 0\n i += 1\n end\n\n\n chars.each do |k,v|\n return true if v > 0\n end\n false\nend\n\n\ndef solution(s)\n beg = 1\n last = s.size - 1\n min_k = s.size\n\n while (beg <= last) do\n mid = (last + beg)/2 \n \n if is_posible?(s, mid)\n min_k = mid\n last = mid - 1\n else\n beg = mid + 1\n end\n end\n min_k\nend\n\nputs solution(gets.strip()) "}, {"source_code": "def is_posible?(s, k)\n n = s.size\n return true if n == k\n chars = [0]*255\n s[0...k].split(\"\").each{ |c| chars[c.ord] += 1 }\n i = 1\n\n while i+k <= n do\n puts \"#{chars[97..122]}\"\n chars[s[i+k-1].ord] += 1 if chars[s[i+k-1].ord] and chars[s[i+k-1].ord] > 0\n chars[s[i-1].ord] -= 1 if chars[s[i-1].ord]\n i += 1\n end\n puts \"#{chars[97..122]}\"\n\n chars.each do |v|\n return true if v > 0\n end\n false\nend\n\n\ndef solution(s)\n beg = 1\n last = s.size - 1\n min_k = s.size\n\n while (beg <= last) do\n mid = (last + beg)/2\n\n if is_posible?(s, mid)\n min_k = mid\n last = mid - 1\n else\n beg = mid + 1\n end\n end\n min_k\nend\n\nputs solution(gets.strip())\n"}, {"source_code": "def is_posible?(s, k)\n n = s.size\n return true if n == k\n chars = [0]*255\n s[0...k].split(\"\").each{ |c| chars[c.ord] += 1 }\n i = 1\n \n while i+k < n do\n chars[s[i+k-1].ord] += 1 if chars[s[i+k-1].ord] and chars[s[i+k-1].ord] > 0\n chars[s[i-1].ord] -= 1 if chars[s[i-1].ord]\n i += 1\n end\n\n chars.each do |v|\n return true if v > 0\n end\n false\nend\n\n\ndef solution(s)\n beg = 1\n last = s.size - 1\n min_k = s.size\n\n while (beg <= last) do\n mid = (last + beg)/2 \n \n if is_posible?(s, mid)\n min_k = mid\n last = mid - 1\n else\n beg = mid + 1\n end\n end\n min_k\nend\n\nputs solution(gets.strip()) "}, {"source_code": "def is_posible?(s, k)\n n = s.size\n chars = s[0...k].split(\"\").uniq\n \n i = 0\n while i+k < n do\n chars.each do |c|\n chars.delete(c) if !s[i...(i+k)].include?(c) \n end\n return false if chars.size == 0\n i += 1\n end\n true\nend\n\n\ndef solution(s)\n beg = 1\n last = s.size - 1\n min_k = s.size\n\n while (beg <= last) do\n mid = (last + beg)/2 \n \n if is_posible?(s, mid)\n min_k = mid\n last = mid - 1\n else\n puts mid\n beg = mid + 1\n end\n end\n min_k\nend\n\ns = gets.strip()\n"}], "src_uid": "81a558873e39efca5066ef91a9255f11"} {"source_code": "gets\na=gets.split.map{|e|e.to_i}.sort\nr=0\n(0..a.size/2-1).each{|i|r+=(a[i]+a[-i-1])**2}\np r", "positive_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\n\nn = gets.to_i\narr = gets.chomp.split(\" \").map(&:to_i).sort\n\nk = n/2\ns = 0\n\n(0..k-1).each do |i|\n\ts += (arr[i]+arr[n-1-i])**2\nend\n\nputs s"}, {"source_code": "# Input\nn = gets.to_i\na = gets.split.map { |i| i.to_i }\n\n# Most effecient way: splitting into pairs from the middle\n\n# Processing\na.sort!\nsum = 0\n(n / 2).times { |i| sum += (a[i] + a[n - 1 - i])**2 }\n\n# Output\nputs sum\n"}, {"source_code": "DBG = true\nn = gets.to_i\na = gets.split.map{|z| z.to_i}\n #a,b = gets.split\n #a = a.to_i\n #b = b.to_i\n\na.sort!\nsum = 0\nfor i in 0...(n/2)\n sum += (a[i]+a[n-1-i])**2\nend\nputs \"#{sum}\"\n"}, {"source_code": "n = gets.to_i\na = gets.split(\" \").sort_by{|e| e.to_i}\nr = 0\nfor i in 0..n/2-1\n\tr+=(a[i].to_i+a[n-1-i].to_i)**2\nend \t\np r"}, {"source_code": "gets\na=gets.split.map{|e|e.to_i}.sort\nr=0\na.size.times{|i|r+=(a[i]+a[-i-1])**2}\np r/2"}, {"source_code": "gets\na = gets.split(' ').map{|z| z.to_i}.sort\nr = 0\n(0..a.size-1).each{|i|\tr+=(a[i]+a[-i-1])**2}\np r/2"}, {"source_code": "n = gets.to_i\na = gets.split(\" \").map{|z| z.to_i}.sort\nr = 0\nfor i in 0..n-1\n\tr+=(a[i]+a[n-1-i])**2\nend \t\np r/2"}, {"source_code": "n = gets.to_i\na = gets.split(\" \").map{|z| z.to_i}.sort\nr = 0\n(0..n-1).each{|i|\tr+=(a[i]+a[n-1-i])**2}\np r/2"}, {"source_code": "n = gets.to_i\na = gets.split(\" \")\nfor i in 0..n-1 do\n\ta[i] = a[i].to_i\nend\na = a.sort\nans = 0\nfor i in 0..n/2-1 do\n\tans+=(a[i]+a[n-1-i])*(a[i]+a[n-1-i])\nend \np ans"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map{|z| z.to_i}.sort\nr = 0\n(0..n-1).each{|i|\tr+=(a[i]+a[-i-1])**2}\np r/2"}, {"source_code": "gets\na = gets.split.map{|e| e.to_i}.sort\nr=0\n(0..a.size/2-1).each{|i|\tr+=(a[i]+a[-i-1])**2}\np r"}], "negative_code": [], "src_uid": "28c555fefd5c36697a5082c61d8a82b3"} {"source_code": "def scan;gets.split.map(&:to_i);end\n\nn,k = scan\naa = scan\n\nres = 0.0\nl = 0\nsum = 0\naa.each_index{|r|\n if r-l >= k\n res += sum\n sum -= aa[l]\n l+=1\n end\n sum += aa[r]\n}\nres += sum\nres /= n-k+1\n\np res", "positive_code": [{"source_code": "n,k,*a=$<.read.split.map(&:to_i)\ns=0.0\n(k-1).times{|i|s+=a[i]}\nr=0\n(k-1...n).each{|i|s+=a[i];r+=s;s-=a[i-k+1]}\np r/(n-k+1)"}], "negative_code": [{"source_code": "n,k,*a=$<.read.split.map(&:to_i)\ns=0.0\n(k-1).times{|i|s+=a[i]}\nr=0\n(k-1...n).each{|i|s+=a[i];r+=s;s-=a[i-k+1]}\np s/(n-k+1)"}], "src_uid": "838e643a978adbeed791a24ac1046ab5"} {"source_code": "t=gets.chomp.to_i\n\nwhile t!=0\nn=gets.chomp.to_i\nk=4.0\n\n \nval=n/k\nval=val.ceil()\n\n\nl=n-val\nl.times {print \"#{9}\"}\nval.times{print \"#{8}\"}\nputs\nt-=1\n\nend", "positive_code": [{"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n zero = n / 4\n if n % 4 == 0\n puts '9' * (n - zero) + '8' * zero\n else\n puts '9' * (n - zero - 1) + '8' + '8' * zero\n end\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n n = gets.chomp.to_i\n # 1.upto (n) do |i|\n # if i == n\n # print \"8\"\n # print \"\\n\"\n # else\n # print \"9\"\n # end\n # end\n atai = n / 4\n if n % 4 != 0\n hituyou = atai + 1\n else\n hituyou = atai\n end\n arr = \"9\" * (n - hituyou)\n print arr\n ar = \"8\" * hituyou\n print ar\n print \"\\n\"\n\nend"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n c = (n + 3) / 4\n (n - c).times do\n print 9\n end\n c.times do\n print 8\n end\n puts\nend"}, {"source_code": "def pow(str,n)\n if n == 0\n \"\"\n elsif n % 2 == 0\n pow((str+str), n/2)\n else\n str + pow(str, n-1)\n end\nend\nt = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n num8 = 1 + (n-1)/4\n num9 = n - num8\n str = \"\"\n str = pow(\"9\",num9) + pow(\"8\",num8)\n ans << str\nend\nans.each do |s|\n puts s\nend"}], "negative_code": [{"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n puts '9' * (n - 1) + '8'\nend\n"}, {"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n zero = n / 4\n if n % 4 == 0\n puts '9' * (n - zero) + '0' * zero\n else\n puts '9' * (n - zero - 1) + '8' + '0' * zero\n end\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n n = gets.chomp.to_i\n # 1.upto (n) do |i|\n # if i == n\n # print \"8\"\n # print \"\\n\"\n # else\n # print \"9\"\n # end\n # end\n arr = \"9\" * (n-1)\n print arr\n print \"8\"\n print \"\\n\"\n\nend"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n c = (n + 3) / 4\n (n - c).times do\n print 9\n end\n c.times do\n print 8\n end\nend"}], "src_uid": "80c75a4c163c6b63a614075e094ad489"} {"source_code": "#!/usr/bin/env ruby\ncount = gets.to_i\n\nanswers = []\n\ncount.times do\n n = gets.chomp.to_i\n\n a = gets.chomp.split(' ').map(&:to_i)\n b = gets.chomp.split(' ').map(&:to_i)\n\n i = 0\n while a[i] == b[i] && i < n do\n i += 1\n end\n\n if i == n\n answers << \"YES\"\n elsif (k = a[i] - b[i]) > 0\n answers << \"NO\"\n else\n while i < n && a[i] - b[i] == k do\n i += 1\n end\n\n if i == n\n answers << \"YES\"\n elsif a[i] == b[i]\n i += 1\n while i < n && a[i] == b[i] do\n i += 1\n end\n\n if i == n\n answers << \"YES\"\n else\n answers << \"NO\"\n end\n else\n answers << \"NO\"\n end\n end\nend\n\nanswers.each { |answer| puts answer }\n", "positive_code": [{"source_code": "g = gets.chomp.to_i\ng.times{\nn = gets.to_i\na = gets.chomp.split(\" \")\nb = gets.chomp.split(\" \")\nmore = false\nmore2 = false\ndif = []\nn.times{|w|\ndif.push(b[w].to_i-a[w].to_i) \nif a[w].to_i > b[w].to_i\nputs \"NO\"\nmore = true\nbreak\nend\n}\nif (!more)\nif dif.uniq.size > 2 or (!dif.uniq.include?(0) and dif.uniq.size == 2)\n puts \"NO\"\nelse\n index = []\n dif.size.times{|w| if dif[w].to_i > 0 then index.push(w) end }\n index.size.times{|w|\n if w!=0 \n if index[w].to_i - index[w-1] != 1\n puts \"NO\"\n more2 = true\n break\n end\n end\n }\n if (!more2) then puts \"YES\" end\n end\nend\n \n}"}, {"source_code": "def solve()\n n = gets.to_i\n a = gets.split.map(&:to_i)\n b = gets.split.map(&:to_i)\n done = false\n i = 0\n while i < n\n x = a[i] - b[i]\n if x != 0\n if done || x > 0\n puts \"NO\"\n return\n end\n done = true\n diff = x\n while i < n\n y = a[i] - b[i]\n if y == 0\n break\n elsif y != diff\n puts \"NO\"\n return\n end\n i += 1\n end\n end\n i += 1\n end\n puts \"YES\"\nend\n\nt = gets.to_i\nt.times do\n solve()\nend"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map &:to_i\n b = gets.split.map &:to_i\n i = 0\n i += 1 while i < n && b[i] - a[i] == 0\n diff = b[i] - a[i] if i < n\n yes = true\n while i < n\n d = b[i] - a[i]\n if d < 0\n yes = false\n break\n else\n if d != diff\n if d != 0\n yes = false\n end\n break\n end\n end\n i += 1\n end\n i += 1 while yes && i < n && b[i] - a[i] == 0\n yes = false if i < n\n puts yes ? 'YES' : 'NO'\nend\n"}], "negative_code": [{"source_code": "g = gets.chomp.to_i\ng.times{\nn = gets.to_i\na = gets.chomp.split(\" \")\nb = gets.chomp.split(\" \")\nmore = false\nmore2 = false\ndif = []\nn.times{|w|\ndif.push(b[w].to_i-a[w].to_i) \nif a[w].to_i > b[w].to_i\nputs \"NO\"\nmore = true\nbreak\nend\n}\nif (!more)\nif dif.uniq.size > 1 and !dif.uniq.include?(0)\n puts \"NO\"\n break\nelse\n index = []\n dif.size.times{|w| if dif[w].to_i > 0 then index.push(w) end }\n index.size.times{|w|\n if w!=0 \n if index[w].to_i - index[w-1] != 1\n puts \"NO\"\n more2 = true\n break\n end\n end\n }\n \n if (!more2) then puts \"YES\" end\n end\nend\n \n}"}, {"source_code": "g = gets.chomp.to_i\ng.times{\nn = gets.to_i\na = gets.chomp.split(\" \")\nb = gets.chomp.split(\" \")\nmore = false\nmore2 = false\ndif = []\nn.times{|w|\ndif.push(b[w].to_i-a[w].to_i) \nif a[w].to_i > b[w].to_i\nputs \"NO\"\nmore = true\n#break\nend\n}\nif (!more)\nif dif.uniq.size > 2 or (!dif.uniq.include?(0) and dif.uniq.size == 2)\n puts \"NO\"\nelse\n index = []\n dif.size.times{|w| if dif[w].to_i > 0 then index.push(w) end }\n index.size.times{|w|\n if w!=0 \n if index[w].to_i - index[w-1] != 1\n puts \"NO\"\n more2 = true\n #break\n end\n end\n }\n if (!more2) then puts \"YES\" end\n end\nend\n \n}"}, {"source_code": "g = gets.chomp.to_i\ng.times{\nn = gets.to_i\na = gets.chomp.split(\" \")\nb = gets.chomp.split(\" \")\nmore = false\nmore2 = false\ndif = []\nn.times{|w|\ndif.push(b[w].to_i-a[w].to_i)\nif a[w].to_i > b[w].to_i\nputs \"NO\"\nmore = true\nbreak\nend\n}\nif (!more)\nif dif.uniq.size > 2\nputs \"NO\"\nelse\nf = 0\ndif.size.times{|w|\nf+=dif[w].to_i\nif dif[w].to_s == \"0\" and f.to_i > 0 and w != dif.size-1\nputs \"NO\"\nmore2 = true\nbreak\nend\n}\nif (!more2)\nputs \"YES\"\nend\n\nend\n\n\nend\n\n}\n"}, {"source_code": "g = gets.chomp.to_i\ng.times{\nn = gets.to_i\na = gets.chomp.split(\" \")\nb = gets.chomp.split(\" \")\nmore = false\nmore2 = false\ndif = []\nn.times{|w|\ndif.push(b[w].to_i-a[w].to_i) \nif a[w].to_i > b[w].to_i\nputs \"NO\"\nmore = true\nbreak\nend\n}\nif (!more)\nif dif.uniq.size > 2\n puts \"NO\" \nelse\n index = []\n dif.size.times{|w| if dif[w].to_i > 0 then index.push(w) end }\n index.size.times{|w|\n if w!=0 \n if index[w].to_i - index[w-1] != 1\n puts \"NO\"\n more2 = true\n break\n end\n end\n }\n \n if (!more2) then puts \"YES\" end\n end\nend\n \n}"}, {"source_code": "g = gets.chomp.to_i\ng.times{\nn = gets.to_i\na = gets.chomp.split(\" \")\nb = gets.chomp.split(\" \")\nmore = false\ndif = []\nn.times{|w|\nif a[w].to_i < b[w].to_i then dif.push(b[w].to_i-a[w].to_i) end\nif a[w].to_i > b[w].to_i\nputs \"NO\"\nmore = true\nbreak\nend\n}\nif (!more)\nif dif.uniq.size > 1 then puts \"NO\" else puts \"YES\" end\nend\n\n}\n\n"}, {"source_code": "g = gets.chomp.to_i\ng.times{\nn = gets.to_i\na = gets.chomp.split(\" \")\nb = gets.chomp.split(\" \")\nmore = false\nmore2 = false\ndif = []\nn.times{|w|\ndif.push(b[w].to_i-a[w].to_i) \nif a[w].to_i > b[w].to_i\nputs \"NO\"\nmore = true\n#break\nend\n}\nif (!more)\nif dif.uniq.size > 1 and !dif.uniq.include?(0)\n puts \"NO\"\nelse\n index = []\n dif.size.times{|w| if dif[w].to_i > 0 then index.push(w) end }\n index.size.times{|w|\n if w!=0 \n if index[w].to_i - index[w-1] != 1\n puts \"NO\"\n more2 = true\n #break\n end\n end\n }\n \n if (!more2) then puts \"YES\" end\n end\nend\n \n}"}], "src_uid": "0e0ef011ebe7198b7189fce562b7d6c1"} {"source_code": "n = gets.to_i\n\nchess = []\n\nn.times do\n chess << gets.strip.split(' ').map(&:to_i)\nend\n\nm = gets.to_i\n\nprog = []\n\nm.times do\n prog << gets.strip.split(' ').map(&:to_i)\nend\n\nchess.sort! { |x,y| x[1] <=> y[1] }\nprog.sort! { |x,y| y[0] <=> x[0] }\n\nmax_diff = 0\n\n# chess.each do |c|\n# prog.each do |p|\n# break if c[0] - p[1] <= 0 && p[0] - c[1] <= 0\n# break if c[0] - p[1] <= max_diff && p[0] - c[1] <= max_diff\n# max_diff = [c[0] - p[1], max_diff].max\n# max_diff = [p[0] - c[1], max_diff].max\n# end\n# end\n\n# puts max_diff\n\nlowest_in_chess = chess[0][1]\nhighest_in_prog = prog[0][0]\nmax_diff = [highest_in_prog - lowest_in_chess, max_diff].max\n\nchess.sort! { |x,y| y[0] <=> x[0] }\nprog.sort! { |x,y| x[1] <=> y[1] }\nhighest_in_chess = chess[0][0]\nlowest_in_prog = prog[0][1]\n\nmax_diff = [highest_in_chess - lowest_in_prog, max_diff].max\n\nputs max_diff\n\n", "positive_code": [{"source_code": "def f()\n lo, hi = 10**9, 0\n gets.to_i.times do\n l, r = gets.split.map { |s| s.to_i }\n if lo > r\n lo = r\n end\n if hi < l\n hi = l\n end\n end\n return lo, hi\nend\n\na, b = f\nc, d = f\np [0, b - c, d - a].max\n"}, {"source_code": "def f()\n lo, hi = 10**9, 0\n gets.to_i.times do\n l, r = gets.split.map(&:to_i)\n if lo > r\n lo = r\n end\n if hi < l\n hi = l\n end\n end\n return lo, hi\nend\n\na, b = f\nc, d = f\np [0, b - c, d - a].max\n"}, {"source_code": "n=gets.chomp.to_i\nchess_start=[]\nchess_end=[]\nn.times do\n time=gets.chomp.split\n #puts \"#{time[0]} #{time[1]}\"\n chess_start< rest\n rest = chess_start[-1]-program_end[0]\nend\nif rest < 0\n puts 0\nelse\n puts rest\nend\n"}, {"source_code": "n = gets.to_i\nnt = n.times.map{gets.split.map(&:to_i)}\nm = gets.to_i\nmt = m.times.map{gets.split.map(&:to_i)}\nmx = 0\nmx = [mt.max_by{|l, r| l}[0] - nt.min_by{|l, r| r}[1], mx].max\nmx = [nt.max_by{|l, r| l}[0] - mt.min_by{|l, r| r}[1], mx].max\np mx\n\n"}], "negative_code": [{"source_code": "n = gets.to_i\n\nchess = []\n\nn.times do\n chess << gets.strip.split(' ').map(&:to_i)\nend\n\nm = gets.to_i\n\nprog = []\n\nm.times do\n prog << gets.strip.split(' ').map(&:to_i)\nend\n\nchess.sort! { |x,y| x[0] <=> y[0] }\nprog.sort! { |x,y| y[0] <=> x[0] }\n\nmax_diff = 0\n\nchess.each do |c|\n prog.each do |p|\n break if p[0] <= c[1]\n max_diff = [c[1] - p[0], max_diff].max\n max_diff = [p[0] - c[1], max_diff].max\n end\nend\n\nputs max_diff\n"}], "src_uid": "4849a1f65afe69aad12c010302465ccd"} {"source_code": "\nn, m = gets.strip.split(\" \").map(&:to_i)\na = gets.strip.split(\" \").map(&:to_i)\nb = gets.strip.split(\" \").map(&:to_i)\n\na_even = a.select{|e| e.even? }.size\na_odd = n - a_even\n\nb_even = b.select{|e| e.even? }.size\nb_odd = m - b_even\n\nmax = [a_even, b_odd].min + [a_odd, b_even].min\np max\n", "positive_code": [{"source_code": "N, M = gets.split.map(&:to_i)\nA = gets.split.map(&:to_i)\nB = gets.split.map(&:to_i)\n\na_odds = A.count(&:odd?)\na_evens = A.count(&:even?)\nb_odds = B.count(&:odd?)\nb_evens = B.count(&:even?)\n\nputs [a_odds, b_evens].min + [a_evens, b_odds].min\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i)\nbs = gets.split.map(&:to_i)\n\nasodd = as.count { |a| a.odd? }\naseven = n - asodd\n\nbsodd = bs.count { |b| b.odd? }\nbseven = m - bsodd\n\nputs [asodd, bseven].min + [aseven, bsodd].min"}, {"source_code": "n,m = gets.split.map(&:to_i)\na = gets.split.map{|i|i.to_i%2}\nb = gets.split.map{|i|i.to_i%2}\nputs [a.count(0),b.count(1)].min+[a.count(1),b.count(0)].min"}, {"source_code": "n, m = gets.split.map(&:to_i)\nchests = gets.split.map(&:to_i)\nkeys = gets.split.map(&:to_i)\n\ncntC0 = 0\ncntC1 = 0\ncntK0 = 0\ncntK1 = 0\n\nchests.each do |c|\n if c % 2 == 0\n cntC0 += 1\n elsif c % 2 == 1\n cntC1 += 1\n end\nend\n\nkeys.each do |k|\n if k % 2 == 0\n cntK0 += 1\n elsif k % 2 == 1\n cntK1 += 1\n end\nend\n\nputs [cntC0, cntK1].min + [cntC1, cntK0].min\n"}, {"source_code": "n, m = gets.split.map &:to_i\na = gets.split.map &:to_i\nb = gets.split.map &:to_i\nf = a.select { |x| x%2 == 0 }.size\ns = b.select { |x| x%2 == 0 }.size\nputs [f, b.size - s].min + [a.size - f, s].min\n"}], "negative_code": [], "src_uid": "bc532d5c9845940b5f59485394187bf6"} {"source_code": "n,m = gets.split.map(&:to_i)\nputs n.times.map{ gets.split.map(&:to_f).inject(:/) }.min * m\n", "positive_code": [{"source_code": "n, m = gets.split().map { |s| s.to_i }\n\nbargains = []\nn.times do\n bargains << gets.split().map { |s| s.to_i }\nend\n\nbest_bargain = 2<<2048\nbargains.each do |bargain|\n best_bargain = [best_bargain, bargain[0]/Float(bargain[1])].min\nend\n\nputs (best_bargain*m).round(8)"}, {"source_code": "n, m = gets.split.map(&:to_i)\nans = 1000000000000000000.0\n\nn.times{\n a, b = gets.split.map(&:to_i)\n ans = [ ans, (a * m) / b.to_f ].min\n}\n\np ans"}, {"source_code": "n, m = gets.split.map{|x| x.to_i}\nt, f = 0.0, 101.0\nn.times do\n a, b = gets.split.map{|x| x.to_i + 0.0}\n f = [f, a/b].min\n t = f*m\nend\nputs t\n"}, {"source_code": "n,m = gets.chomp.split \n\nn = n.to_i \nm = m.to_f \n\n# price = Array.new(n)\ntprice = Array.new(n) \n\nfor i in 0...n \n a,b = gets.chomp.split \n tprice[i] = a.to_f / b.to_f \nend \n\nputs (tprice.min)*m"}, {"source_code": "n,m=gets.split.map &:to_i\nans=1000000000.0\nn.times do\n a,b=gets.split.map &:to_f\n cost=m*(a/b)\n ans=[ans,cost].min\nend\np ans"}, {"source_code": "n,m=gets.split.map &:to_i\nans=1000000000.0\nn.times do\n a,b=gets.split.map &:to_f\n cost=m*(a/b)\n ans=ans=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}\n\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\nt = gets.to_i\nh1 = Hash.new(0)\nh2 = Hash.new(0)\na = Array.new(t)\nb = Array.new(t)\nm = -1\nwinner = \"\"\n\nfor i in 0...t\n\n s = gets.split(' ')\n\n a[i] = s[0]\n b[i] = s[1].to_i\n\n h1[a[i]] += b[i]\n\nend\n\nh1.each_pair { |key, val|\n if val > m\n m = val\n end\n}\n\nfor i in 0...t\n\n h2[a[i]] += b[i]\n if h2[a[i]] >= m && h1[a[i]] == m\n winner = a[i]\n break\n end\n\nend\n\nputs winner\n\n \n"}, {"source_code": "n=gets.chomp.to_i\nnc=0 \n@hash={}\n@hash_total={}\nloop do\t\n\tbreak if nc == n\n\tinput=gets.chomp.split(\" \")\n\tk=0\n\tif nc >= 1\n\t\t@hash.each_key do |plr_nm|\n\t\t\tif plr_nm!=input[0]\n\t\t\t\tk+=1\n\t\t\tend\n\t\tend\n\t\tif k==@hash.length\n\t\t\t@hash[input [0]]=[0]\n\t\t\t@hash[input [0]][nc]=input[1].to_i\n\t\telse\n\t\t@hash[input [0]][nc]=input[1].to_i\n\t\tend\n\telse\n\t\t@hash[input [0]]=[input[1].to_i]\n\tend\n\n\tnc+=1\nend\n\n\ndef Total(key,array)\n k=0\n\tarray.each do|l|\n\t\tif l== nil\n\t\t\tl=0\n\t\tend\n\t k=k+l\n\tend\n @hash_total[key]=k\nend\n@hash.each_pair do|a,b|\n\tTotal(a,b)\nend\n\ndef Tiebreaker(a,b)\n ka=0\n ba=0\n k=0\n @hash[a[0]].each do|cn|\n\t\tif cn== nil\n\t\t\tcn=0\n\t\tend\n\t\tk=k+cn\n\t\tka+=1\n\t\tbreak if k >= a[1]\n\tend\t\n\tk=0\t\t\n @hash[b[0]].each do|cn|\n if cn== nil\n\t\t\tcn=0\n\t\tend\n\t\tk=k+cn\n\t\tba+=1\n\t\tbreak if k >= b[1]\n\tend\t\n\tif ka>ba\n\t\treturn b\n\telse \n\t\treturn a\n\tend\t\nend\t\n\t\t\t\nwin= @hash_total.inject do |memo,n|\n\tif memo[1]>n[1]\n\t\tmemo\n\telsif memo[1]==n[1]\n\t\tTiebreaker(memo,n)\n\telse \n\t\tn\n\tend\t\nend\nputs win[0]\n"}, {"source_code": "num=Hash.new(0)\nturn=Hash.new(0)\narray=[]\na=gets.chomp.to_i\n0.upto(a-1) do |i|\ntemp=gets.chomp.split(\" \")\nnum[temp[0]]+=temp[1].to_i\narray<= mx)\n puts nm\n exit\n end\nend\n\n"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}\n\n"}, {"source_code": "# http://codeforces.com/problemset/problem/2/A\n\nRound = Struct.new(:player, :score)\n\nclass WinnerCalculator\n def self.get_winner(scoreboard)\n rounds = []\n scoreboard.each do |round_line|\n player, score = round_line.split\n rounds << Round.new(player, score.to_i)\n end\n\n scoring = Hash.new(0)\n rounds.each do |round|\n scoring[round.player] += round.score\n end\n max_score = scoring.values.max\n players_with_max_score = scoring.select { |player, score| score == max_score }\n\n if players_with_max_score.size == 1\n return players_with_max_score.keys.first\n end\n\n tiebreak_scoring = Hash.new(0)\n rounds.each do |round|\n tiebreak_scoring[round.player] += round.score\n if tiebreak_scoring[round.player] >= max_score && scoring[round.player] == max_score\n return round.player\n end\n end\n end\nend\n\nif __FILE__ == $0\n scoreboard = []\n gets.to_i.times { scoreboard << gets }\n winner = WinnerCalculator.get_winner(scoreboard)\n puts winner\nend\n"}, {"source_code": "scoring = Hash.new(0)\nscoreboard = []\ngets.to_i.times do\n player, score = gets.split\n scoring[player] += score.to_i\n scoreboard << [player, score.to_i]\nend\n\nmax_score = scoring.values.max\n\ntiebreak_scoring = Hash.new(0)\nscoreboard.each do |player, score|\n tiebreak_scoring[player] += score.to_i\n if scoring[player] == max_score && tiebreak_scoring[player] >= max_score\n puts player\n break\n end\nend\n"}, {"source_code": "n=gets.chomp.to_i\nnc=0 \n@hash={}\n@hash_total={}\nloop do\t\n\tbreak if nc == n\n\tinput=gets.chomp.split(\" \")\n\tk=0\n\tif nc >= 1\n\t\t@hash.each_key do |plr_nm|\n\t\t\tif plr_nm!=input[0]\n\t\t\t\tk+=1\n\t\t\tend\n\t\tend\n\t\tif k==@hash.length\n\t\t\t@hash[input [0]]=[0]\n\t\t\t@hash[input [0]][nc]=input[1].to_i\n\t\telse\n\t\t@hash[input [0]][nc]=input[1].to_i\n\t\tend\n\telse\n\t\t@hash[input [0]]=[input[1].to_i]\n\tend\n\n\tnc+=1\nend\n\n\ndef Total(key,array)\n k=0\n\tarray.each do|l|\n\t\tif l== nil\n\t\t\tl=0\n\t\tend\n\t k=k+l\n\tend\n @hash_total[key]=k\nend\n@hash.each_pair do|a,b|\n\tTotal(a,b)\nend\n\ndef Tiebreaker(a,b)\n ka=0\n ba=0\n k=0\n @hash[a[0]].each do|cn|\n\t\tif cn== nil\n\t\t\tcn=0\n\t\tend\n\t\tk=k+cn\n\t\tka+=1\n\t\tbreak if k >= a[1]\n\tend\t\n\tk=0\t\t\n @hash[b[0]].each do|cn|\n if cn== nil\n\t\t\tcn=0\n\t\tend\n\t\tk=k+cn\n\t\tba+=1\n\t\tbreak if k >= b[1]\n\tend\t\n\tif ka>ba\n\t\treturn b\n\telse \n\t\treturn a\n\tend\t\nend\t\n\t\t\t\nwin= @hash_total.inject do |memo,n|\n\tif memo[1]>n[1]\n\t\tmemo\n\telsif memo[1]==n[1]\n\t\tTiebreaker(memo,n)\n\telse \n\t\tn\n\tend\t\nend\nputs win[0]\n"}, {"source_code": "num=Hash.new(0)\nturn=Hash.new(0)\narray=[]\na=gets.chomp.to_i\n0.upto(a-1) do |i|\ntemp=gets.chomp.split(\" \")\nnum[temp[0]]+=temp[1].to_i\narray< competitors[winner]\nend\n\nwinner_definition = {}\n\nstep_logs.each do |step_result|\n step_winner = step_result[0]\n step_winner_score = step_result[1]\n\n winner_definition[step_winner] ||= 0\n\n winner_definition[step_winner] += step_winner_score\n\n if (winner_definition[step_winner] >= competitors[winner]) && (competitors[step_winner] >= competitors[winner])\n puts step_winner\n break\n end\nend\n"}, {"source_code": "h = Hash.new {|h, k| h[k] = [[-1, 0, 0]]}\nnum_turns = gets.chomp.to_i\nnum_turns.times {|turn|\n name, score = gets.chomp.split\n score = score.to_i\n prev = h[name].last\n h[name] << [turn, score, prev.last + score]\n}\n\nplayers = h.keys\nmax_score = -1\nmax_players = []\nplayers.each {|player; player_score|\n player_score = h[player].last.last\n if player_score > max_score\n max_score = player_score\n max_players = [player]\n elsif player_score == max_score\n max_score = player_score\n max_players << player\n end\n}\n\nwinner = if max_players.size > 1\n max_players.map {|player|\n [h[player].detect {|(turn, _, score)| if score >= max_score; turn; end},\n player]\n }.sort_by {|(score, _)| score}.first.last\nelse\n max_players.first\nend\nputs winner\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\nn=gets.to_i\n\ndata = []\nhs = Hash.new(0)\n\nn.times{\n\tname, points = gets.split\t\n\t\n\tdata << [name, points.to_i]\n\ths[name]+=points.to_i\n}\n\nmax_points = hs.values.max\n\nplayers = hs.keys.select{|k| hs[k]==max_points}\n\nhs2 = Hash.new(0)\ndata.each{|name, points|\t\t\n\tnext if !players.include? name\n\n\ths2[name]+=points\n\t\n\tif hs2[name]>=max_points\n\t\tputs name\n\t\tbreak\n\tend\n}\n"}, {"source_code": "n = gets.to_i\nh = Hash.new\nnames = []\nscores = []\nwinners = []\n\nfor i in 0...n\n\n s, k = gets.chomp.split\n k = k.to_i\n\n h[s] = 0 if h[s].nil?\n\n h[s] += k\n\n names.push(s)\n scores.push(k)\nend\n\nmax = h.values.max\n\nh.each do |k,v|\n winners.push(k) if v >= max\nend\n\nwinners = winners.uniq\n\nh.clear\n\nfor i in 0...n\n if winners.include?(names[i])\n h[names[i]] = 0 if h[names[i]].nil?\n h[names[i]] += scores[i]\n if h[names[i]] >= max\n puts names[i]\n exit\n end\n end\nend\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nh = {}\nst = []\nn.times {\n name, score = gets.split\n score = score.to_i\n h[name] ||= 0\n h[name] += score\n st << [name, score]\n}\nmax = h.values.max\ncands = []\nfor k,v in h\n if v == max\n cands << k\n end\nend\n\nif cands.length == 1\n puts cands[0]\nelse\n h2 = {}\n for s in st\n next if cands.index(s[0]) == nil\n h2[s[0]] ||= 0\n h2[s[0]] += s[1]\n if h2[s[0]] >= max\n puts s[0]\n break\n end\n end\nend"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}\n"}, {"source_code": "num_lines = gets().chomp.to_i\nscores = {}\nlog = []\nnum_lines.times{\n|i|\n name, score = gets().chomp.split(/[ ]+/)\n score = score.to_i\n if(scores.has_key?(name)) then\n scores[name] += score\n else\n scores[name] = score\n end\n log << [name, scores[name], i]\n}\n\nscores_a = scores.to_a\n\nmax_score = scores_a.max {\n|player1,player2|\n player1[1] <=> player2[1]\n}[1]\n\ntop_scores = scores_a.select {\n|player|\n player[1] == max_score\n}\n\nwinner = log.select{\n|line|\n top_scores.collect {\n |plr|\n plr[0]\n }.index(line[0]) &&\n line[1] >= max_score\n}.min{\n|line1,line2|\n line1[2] <=> line2[2]\n}[0]\n\nputs winner\n"}, {"source_code": "n = gets.to_i\nr = []\nfor i in 0 ... n \n a,b = gets.split\n r << [a, b.to_i]\nend\n\nh1 = Hash.new{0}\nr.each do |name,val|\n h1[name] += val\nend\n\nmaxi = h1.max{|x,y| x[1] <=> y[1]}[1]\n\nh2 = Hash.new{0}\nr.each do |name,val|\n h2[name] += val\n if (h1[name] == maxi && h2[name] >= maxi)\n puts name\n break\n end\nend\n"}, {"source_code": "def getIndex(val, h)\n if (h.key?(val))\n return h[val]\n end\n index = h.size\n return h[val] = index\nend\n\nn = gets.to_i\nh = {}\nlast = []\nsum = []\n\nnames = []\nvalues = []\n\nfor i in 0 ... n\n name,val = gets.split\n index = getIndex(name,h)\n val = val.to_i \n if (index < sum.size)\n sum[index] += val\n last[index] = i\n else\n sum << val\n last << i\n end\n names << name\n values << val\nend\n\nans = \"\"\nfastest = n\nmaxi = sum.max\nh.each do |key,index|\n next if (sum[index] != maxi)\n tsum, tmp = 0, n\n for i in 0 ... n\n next if (names[i] != key)\n tsum += values[i]\n if (tsum >= maxi)\n tmp = i\n break\n end\n end\n if (tmp < fastest)\n fastest, ans = tmp,key\n end\nend\n\n=begin\nmaxi = sum.max\nfastest = n\nh.each do |key,index|\n if (sum[index] == maxi && last[index] < fastest)\n fastest = last[index]\n ans = key\n end\nend\n=end\n\nputs ans\n"}, {"source_code": "n = gets.to_i\nr = []\nn.times do\n w, s = gets.split\n r << [w, s.to_i]\nend\n\na = Hash.new(0)\nr.each do |w, s|\n a[w] += s\nend\nmx = a.values.max\n\nb = Hash.new(0)\nr.each do |w, s|\n b[w] += s\n if b[w] >= mx and a[w] == mx\n puts w\n exit\n end\nend\n"}, {"source_code": "n = gets.to_i\n\nmax = 0\nplayers = Hash.new(0)\nrounds = []\nn.times do\n\tname, score = gets.split\n\tscore = score.to_i\n\trounds << [name, score]\nend\n\nplayers = rounds.inject(Hash.new(0)) { |h, round| h[round[0]] += round[1]; h }\nmax = players.max_by { |k, v| v}[1]\nwinners = players.select { |k, v| v == max }\nplayers = rounds.inject(Hash.new(0)) do |h, round|\n\tplayer = round[0]\n\th[player] += round[1]\n\tif (h[player] >= max) && winners.member?(player)\n\t\tputs player\n\t\tbreak\n\tend\n\th\nend"}, {"source_code": "scores = Hash.new(0)\nin_array = []\n\nn = gets.to_i\nn.times do\n\tl = gets.split(\" \")\n\tscores[l[0]] += l[1].to_i\n\tin_array << [l[0], l[1]]\nend\n\ntally = Hash.new(0)\nmax = scores.values.max\nin_array.each do |score|\n\ttally[score[0]] += score[1].to_i\n\tif (max == scores[score[0]].to_i) && (tally[score[0]].to_i >= max)\n\t\tputs score[0]\n\t\texit\n\tend\nend"}, {"source_code": "n = gets.chomp.to_i\nh = Hash.new\nas = Array.new\nfor i in 1..n\n\ts = gets.chomp\n\tas.push( s )\nend\nfor i in 1..n\n\tnm,sc = as[i-1].split(/ /)\n\tsc = sc.to_i\n\tsc += h[nm] if h.has_key?(nm)\n\th[nm] = sc\nend\nhv = h.to_a.sort {|a,b|\n\tb[1] <=> a[1]\n}\n\nif hv.length == 1 || hv[0][1] > hv[1][1]\n\tputs hv[0][0]\nelse\n\thnm = Hash.new\n\tfor i in 0..hv.length-1\n\t\tbreak if hv[0][1] > hv[i][1]\n\t\thnm[hv[i][0]] = 1\n\tend\n\t\n\th.clear\n\tfor i in 1..n\n\t\tnm,sc = as[i-1].split(/ /)\n\t\tsc = sc.to_i\n\t\tsc += h[nm] if h.has_key?(nm)\n\t\th[nm] = sc\n\t\tif sc >= hv[0][1] && hnm.has_key?(nm)\n\t\t\tputs nm\n\t\t\texit\n\t\tend\n\tend\nend\n"}, {"source_code": "#http://codeforces.com/problemset/problem/2/A\n\nn = gets.to_i\ndir = Hash.new(0)\nstep = Array.new\nmax_val = 0\nmax_name = Array.new\n\nfor i in 1..n\n name, score = gets.chomp.strip.split(\" \")\n score = score.to_i\n dir[name] += score\n record = Hash[\"name\" => name, \"score\" => dir[name]]\n step << record\nend\n\ndir.each_key do |key|\n if dir[key] > max_val\n max_val = dir[key]\n max_name.clear\n max_name << key\n elsif dir[key] == max_val\n max_name << key\n end\nend\n\nflag = 0\nif max_name.size == 1\n puts max_name[0]\nelse\n for i in 0...step.size\n if step[i][\"score\"] >= max_val\n for j in 0...max_name.size\n if step[i][\"name\"] == max_name[j] and flag == 0\n puts max_name[j]\n flag = 1\n end\n end\n end\n end\nend"}, {"source_code": "n=gets.to_i\nv=[]\nn.times do\n\ts,w=gets.split\n\tv << [s,w.to_i]\nend\na=Hash.new(0)\nv.each{|s,w|a[s]+=w}\nm=a.max{|x,y|x[1]<=>y[1]}[1]\nf=Hash.new(0)\nv.each{|s,w|\n\tf[s]+=w\n\tif a[s]==m and f[s]>=m then\n\t\tputs s\n\t\texit\n\tend\n}\n"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}\n\n"}, {"source_code": "table = {}\nlined = []\nARGF.each_line do |line|\n if ARGF.lineno != 1\n name, mark = line.split\n if !table.has_key?(name)\n table[name] = [mark.to_i]\n else\n table[name] += [table[name].last + mark.to_i]\n end\n lined.push({:name => name, :mark => table[name].last})\n end\nend\n\nmaxNames = []\nmax = 0\n\ntable.keys.each do |name|\n if max < table[name].last\n maxNames = [name]\n max = table[name].last\n elsif max == table[name].last\n maxNames.push name\n end\nend\n\nif maxNames.length == 1\n puts maxNames[0]\nelse\n lined.each do |val|\n if val[:mark] >= max and maxNames.include? val[:name]\n puts val[:name]\n break\n end\n end\nend\n"}, {"source_code": "#!/usr/bin/ruby\nn=gets.chomp.to_i\nh=Hash.new;h.default=0\na=Array.new\nn.times{|z|\n s=gets.chomp.split(\" \")\n s[1]=s[1].to_i\n h[s[0]]+=s[1]\n a.push(s)\n}\nm=h.values.max\nh.each_key{|k| h[k]=(h[k]==m)?0:nil}\n\n#re-read\na.each{|i|\n if h[i[0]]\n h[i[0]]+=i[1]\n if h[i[0]]>=m then puts i[0]; exit end\n end\n}\n"}, {"source_code": "#!/usr/bin/env ruby\n\nclass Transaction < Struct.new(:index, :value, :result)\nend\n\n$players_scores = Hash.new\n$operation_index = 0\n\ndef process_score(score_string)\n\tparts = score_string.split(' ')\n\tname = parts[0]\n\tvalue = parts[1].to_i\n\n\tif (!$players_scores.include?(name))\n\t\t$players_scores[name] = Array.new\n\t\t$players_scores[name] << Transaction.new($operation_index, value, value)\n\telse\n\t\tplayer_info = $players_scores[name]\n\t\t$players_scores[name] << Transaction.new($operation_index, value, player_info[player_info.count - 1][:result] + value)\n\tend\n\n\t$operation_index += 1\nend\n\n# results for testing\n# match_results = []\n# match_results << \"andrew 3\"\n# match_results << \"andrew 2\"\n# match_results << \"andrew 1\"\n# match_results << \"mike 5\"\n# match_results << \"andrew -1\"\n# match_results << \"john 5\"\n\n# match_results << \"andrew 3\"\n# match_results << \"andrew 2\"\n# match_results << \"mike 5\"\n\nrepeats = gets.to_i\nmatch_results = []\n\nwhile (repeats > 0)\n\tmatch_results << gets.strip\n\trepeats -= 1\nend\n\nfor score_string in match_results\n\tprocess_score(score_string)\nend\n\nwinning_players = Array.new\nmax_score = 0\n\nfor score in $players_scores.values\n\tif (score[score.count - 1][:result] > max_score)\n\t\twinning_players.clear\n\t\tmax_score = score[score.count - 1][:result]\n\t\twinning_players << score\n\telsif score[score.count - 1][:result] == max_score\n\t\twinning_players << score\n\tend\t\t\nend\n\nmin_index = $operation_index\nwinner = winning_players[0]\n\nfor score_history in winning_players\n\tfor transaction in score_history\n\t\tif transaction[:result] >= max_score && transaction[:index] < min_index\n\t\t\tmin_index = transaction[:index]\n\t\t\twinner = score_history\n\t\tend\n\tend\nend\n\nputs $players_scores.invert[winner]"}, {"source_code": "n = gets.to_i\nr = []\nn.times do\n\tw, s = gets.split\n\tr << [w, s.to_i]\nend\n\na = Hash.new(0)\nr.each do |w,s|\n\ta[w] += s\nend\nm = a.max{|x,y| x[1] <=> y[1] }[1]\n\nb = Hash.new(0)\nr.each do |w,s|\n\tb[w] += s\n\tif a[w] == m && b[w] >= m then\n\t\tputs w\n\t\texit\n\tend\nend\n"}, {"source_code": "n = gets.to_i\nary = []\nhash = Hash.new 0\nn.times do\n\tlist = gets.split\n\tname = list[0]\n\tscore = list[1].to_i\n\thash.has_key?(name) ? hash[name] += score : hash[name] = score\n\tary << [name, hash[name]]\nend\nmaximum = hash.values.max\ncandidates = hash.select {|key, value| value == maximum}\nary.each do |entry|\n\tif candidates.key?(entry[0]) && entry[1] >= maximum\n\t\tputs entry[0]\n\t\tbreak\n\tend\nend"}, {"source_code": "h = {}\nhh = {}\nfor name,score in $<.read.scan(/(\\S+) (\\S+)/)\n t = h[name] = (h[name]||0)+score.to_i\n for i in 0..t\n hh[i] = (hh[i]||[])+[name]\n end\nend\nmax = h.values.max\nputs hh[max].find{|x|h[x]==max}\n"}, {"source_code": "n = STDIN.readline.to_i\nscore = Hash.new\nt = []\n\nn.times do |i|\n\tt << STDIN.readline.split\n\t# print STDIN.readline.split\n\t# print t\n\tt[i][1] = t[i][1].to_i\n\tif score[t[i][0]] == nil ;\n\t\tscore[t[i][0]] = 0\n\tend\n\tscore[t[i][0]] += t[i][1]\nend\n\nmaxscore = 0\nscore.each_value do |i|\n\tmaxscore = i if i > maxscore\nend\n\niscore = Hash.new\nans = \"\"\nn.times do |i|\n\tif iscore[t[i][0]] == nil ;\n\t\tiscore[t[i][0]] = 0\n\tend\n\tiscore[t[i][0]] += t[i][1]\n\tans = t[i][0]; break if iscore[t[i][0]] >= maxscore &&\n\t\t\t\t\t\t\t score[t[i][0]] == maxscore\nend\nprint ans\n"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split}\nh = Hash.new(0)\na.each{|name, s| h[name] += s.to_i}\nmx = h.max_by{|name, s| s}[1]\nh2 = Hash.new(0)\na.each do |name, s|\n h2[name] += s.to_i\n if h[name] == mx && h2[name] >= mx\n puts name\n break\n end\nend\n"}, {"source_code": "n=STDIN.gets.chomp.to_i\nplayers={}\nn.times {|i|\n player,score=STDIN.gets.chomp.split(' ')\n if players.key?(player)\n scores=players[player]\n players[player]<<[score.to_i+scores[scores.length-1][0],i]\n else\n players[player]=[[score.to_i,i]]\n end\n}\nmax=0\nwinners=[]\nplayers.each_pair {|player,scores|\n score=scores[scores.length-1][0]\n if max=m and A[q]==m then\n puts q\n exit\nend\n}"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split}\nh1 = a.each_with_object(Hash.new(0)){|(x, y), h| h[x] += y.to_i}\nmx = h1.values.max\nh2 = Hash.new(0)\na.each do |name, s|\n h2[name] += s.to_i\n if h1[name] == mx && h2[name] >= mx\n puts name\n break\n end\nend\n"}, {"source_code": "# Codeforces, Problem 2A\n# http://codeforces.com/contest/1/problem/C\n# Nate Collings\n\ndef get_names_scores(num)\n names = []\n scores = []\n num.times do\n player, score = gets.chomp.split(\"\\s\")\n names << player\n scores << score.to_i\n end\n return names, scores\nend\n\ndef get_max(players)\n max = players.values.map { |v| v }.max\n with_max = players.select { |_,v| v == max}\n return max, with_max\nend\n\ndef run_round(rounds, names, scores, players=nil, second=false)\n max, with_max = get_max(players) if second\n players = {}\n rounds.times do |round|\n player = names[round]\n score = scores[round]\n if !second || with_max.has_key?(player)\n score += players[player] if players.has_key?(player)\n players[player] = score\n return player if second && score >= max\n end\n end\n players\nend\n\ndef first_round(rounds, names, scores)\n run_round(rounds, names, scores)\nend\n\ndef second_round(rounds, names, scores, players)\n run_round(rounds, names, scores, players, true)\nend\n\ndef solve\n rounds = gets.chomp.to_i\n names, scores = get_names_scores(rounds)\n\n candidates = first_round(rounds, names, scores)\n return candidates.keys[0] if candidates.length == 1\n return second_round(rounds, names, scores, candidates)\nend\n\nputs solve\n"}, {"source_code": "final = {}\n\nn = gets.to_i\nnames = []\nscores = []\nn.times do\n a = gets.split(/\\s+/)\n name = a[0]\n score = a[1].to_i\n if final[name].nil? then\n final[name] = 0\n end\n final[name] += score\n names << name\n scores << score\nend\n\nmax = 0\nfinal.each{|key, value| max = value if max < value}\n\ntotal = {}\nn.times do |i|\n name = names[i]\n score = scores[i]\n if total[name].nil? then\n total[name] = 0\n end\n total[name] += score\n if total[name] >= max && final[name] == max then\n puts name\n break\n end\nend\n"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}"}, {"source_code": "num_lines = gets().chomp.to_i\nscores = {}\nscores_fset ={}\n\naddscore = -> (fn, maxscore, index) do\n (-> (score) {\n prev = fn.call(score)\n return prev if prev >= 0\n return index if score <= maxscore\n return -1\n })\nend\n\nnum_lines.times do |index|\n line = gets().chomp\n name, score = line.split\n score = score.to_i\n scores[name] ||= 0\n scores[name] += score\n\n scores_fset[name] ||= -> (x) do\n (-> () {\n return index if x <= score\n return -1\n }).call()\n end\n\n if scores_fset[name].call(scores[name]) == -1\n scores_fset[name] = addscore.call(scores_fset[name], scores[name], index)\n end\nend\n\ntop_score = scores.values.max\ntop_scorers = scores.select {|k, v| v == top_score}\nputs top_scorers.min_by {|k, v| scores_fset[k].call(top_score)}[0]\n"}, {"source_code": "N = gets.to_i\nh = Hash.new { |hash, key| hash[key] = 0 }\na = []\nN.times do \n n, p = gets.split\n a << [n, p.to_i]\n h[n] += p.to_i\nend\n\nm = h.values.max\na.reject! { |x| h[x[0]] < m }\nh = Hash.new { |hash, key| hash[key] = 0 }\na.each do |n, p|\n h[n] += p\n if h[n] >= m\n puts n\n exit\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\nlog = []\ntotal = {}\n\nn.times do |i|\n line = gets.chomp.split(\" \")\n player = line[0]\n cur_score = line[1].to_i\n log << [player, cur_score]\n score = total[player]\n total[player] = score.nil? ? cur_score : score + cur_score\nend\n\nmax_score = total.values.max\nplayers_with_max_score = total.select{|k, v| v == max_score }\n\nif players_with_max_score.length > 1\n tot = {}\n log.each do |row|\n if players_with_max_score.keys.include? row[0]\n score = tot[row[0]]\n tot[row[0]] = score.nil? ? row[1] : score + row[1]\n if tot[row[0]] >= max_score\n puts row[0]\n exit\n end\n end\n \n end\nelse\n puts players_with_max_score.keys.first\nend"}, {"source_code": "n=gets.chomp.to_i\nnc=0 \n@hash={}\n@hash_total={}\nloop do\t\n\tbreak if nc == n\n\tinput=gets.chomp.split(\" \")\n\tk=0\n\tif nc >= 1\n\t\t@hash.each_key do |plr_nm|\n\t\t\tif plr_nm!=input[0]\n\t\t\t\tk+=1\n\t\t\tend\n\t\tend\n\t\tif k==@hash.length\n\t\t\t@hash[input [0]]=[0]\n\t\t\t@hash[input [0]][nc]=input[1].to_i\n\t\telse\n\t\t@hash[input [0]][nc]=input[1].to_i\n\t\tend\n\telse\n\t\t@hash[input [0]]=[input[1].to_i]\n\tend\n\n\tnc+=1\nend\n\n\ndef Total(key,array)\n k=0\n\tarray.each do|l|\n\t\tif l== nil\n\t\t\tl=0\n\t\tend\n\t k=k+l\n\tend\n @hash_total[key]=k\nend\n@hash.each_pair do|a,b|\n\tTotal(a,b)\nend\n\ndef Tiebreaker(a,b)\n ka=0\n ba=0\n k=0\n @hash[a[0]].each do|cn|\n\t\tif cn== nil\n\t\t\tcn=0\n\t\tend\n\t\tk=k+cn\n\t\tka+=1\n\t\tbreak if k >= a[1]\n\tend\t\n\tk=0\t\t\n @hash[b[0]].each do|cn|\n if cn== nil\n\t\t\tcn=0\n\t\tend\n\t\tk=k+cn\n\t\tba+=1\n\t\tbreak if k >= b[1]\n\tend\t\n\tif ka>ba\n\t\treturn b\n\telse \n\t\treturn a\n\tend\t\nend\t\n\t\t\t\nwin= @hash_total.inject do |memo,n|\n\tif memo[1]>n[1]\n\t\tmemo\n\telsif memo[1]==n[1]\n\t\tTiebreaker(memo,n)\n\telse \n\t\tn\n\tend\t\nend\nputs win[0]\n"}, {"source_code": "num=Hash.new(0)\nturn=Hash.new(0)\narray=[]\na=gets.chomp.to_i\n0.upto(a-1) do |i|\ntemp=gets.chomp.split(\" \")\nnum[temp[0]]+=temp[1].to_i\narray<=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}"}, {"source_code": "n = gets.to_i\nlst = []\ntot = {}\nn.times do\n name, score = gets.split\n score = score.to_i\n lst << [name, score]\n tot[name] ||= 0\n tot[name] += score\nend\n\nm = tot.values.max\n\nlst.reject! { |elem| tot[elem[0]] < m}\n#puts lst\n \ntot = {}\nfor name,score in lst do\n tot[name] ||= 0\n tot[name] += score\n if tot[name] >= m\n puts name\n break\n end\nend\n"}, {"source_code": "n = gets.to_i\nh = []\nn.times do\n name, score = gets.split\n score = score.to_i\n h << [name, score]\nend\n\na = {}\nh.each do |con|\n a[con[0]] ||= 0\n a[con[0]] += con[1]\nend\n\nm = a.max {|x,y| x[1] <=> y[1]}[1]\n\nb = Hash.new(0)\nh.each do |con|\n b[con[0]] += con[1]\n if a[con[0]] == m && b[con[0]] >=m\n puts con[0]\n exit\n end\nend"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}\n\n"}, {"source_code": "n = gets.to_i\n\nm = Array.new\n\na = {}\n\nn.times do \n\tk = gets.chomp.split(\" \")\n\tkey = k[0]\n\tvalue = k[1].to_i\n\tif a[ key ].nil? then\n\t\ta[ key ] = value\n\telse\n\t\ta[ key ] += value\n\tend\n\tm << k\nend\n\n\nmax = a.values.max\n\nb = {}\n\nm.each{ |s|\n\tkey = s[0]\n\tvalue = s[1].to_i\n\tif b[ key ].nil? then\n\t\tb[ key ] = value\n\telse\n\t\tb[ key ] += value\n\tend\n\tif a[ key ] == max and b [ key ] >= max then\n\t\tputs key\n\t\tbreak\n\tend\t\n}"}, {"source_code": "log = []\nscores = Hash.new(0)\ncheck = Hash.new(0)\ngets.to_i.times{\n n,q=gets.split\n scores[n]+=q.to_i\n log << [q,n]\n}\nm = scores.values.max\nlog.each{|q,n|\n check[n] += q.to_i\n if check[n] >= m and scores[n] == m then\n puts n\n exit\n end\n}\n"}, {"source_code": " \na={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}\n\n"}, {"source_code": "players = Hash.new(0)\ngames = []\ngets.to_i.times do |i|\n name, point = gets.chomp.split\n point = point.to_i\n games << [name, point]\n players[name] += point\nend\nsorted_players = players.sort{|a, b| b[1] <=> a[1]}\nmax = sorted_players[0][1]\nmax_players = {}\nsorted_players.each do |s|\n break if s[1] < max\n max_players[s[0]] = 0\nend\n\ngames.each do |game|\n if max_players.has_key?(game[0])\n max_players[game[0]] += game[1]\n if max_players[game[0]] >= max\n puts game[0]\n exit\n end\n end\nend\n"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}\n\n"}, {"source_code": "n = gets.to_i\na = []\nscores = {}\nwhens = {}\n(0...n).each do |i|\n ee = gets.split\n a << [ee[0], ee[1].to_i]\n player = ee[0]\n pts = ee[1].to_i\n if scores.include? player\n scores[player] += pts\n else\n scores[player] = pts\n end\nend\nsc = scores.collect{|t| t[1]}\nmx = sc.max\nwinners = {}\nscores.each do |t|\n winners[t[0]] = 0 if t[1] == mx\nend\n(0...n).each do |i|\n# a << [ee[0], ee[1].to_i]\n player = a[i][0]\n pts = a[i][1]\n if winners.include? player\n winners[player] += pts\n if winners[player] >= mx \n puts player\n break\n end\n end\nend"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}\n\n"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\n\nscore_map = {}\nat_index_by_name = {}\n1.upto(lines) do |i|\n name, score = gets.split\n score = score.to_i\n\n score_map[name] ||= 0\n score_map[name] += score\n\n at_index_by_name[name] ||= []\n at_index_by_name[name] << [score_map[name], i]\nend\n\nscores = score_map.to_a.sort_by(&:last)\nputs(\n scores\n .select { |score| scores.last.last == score.last }\n .min_by { |score| at_index_by_name[score.first].find { |e| e.first >= score.last }.last }\n .first\n)\n"}, {"source_code": "n = gets.to_i\nnames = Array.new\nscores = Array.new\nwinn = Array.new\nwins = Array.new\nn.times do\n name, score = gets.split(\" \")\n score = score.to_i\n index = nil\n 0.upto(names.size-1) do |i|\n if names[i] == name\n index = i\n scores[index] += score\n break\n end\n end\n if index.nil?\n index = names.size\n names << name\n scores << score\n end\n winn << index\n wins << score\nend\nm = scores.max\nscoresim = [0]*names.size\nwinner = -1\nn.times do |i|\n scoresim[winn[i]] += wins[i]\n if scoresim[winn[i]] >= m and scores[winn[i]] == m\n winner = winn[i]\n break\n end\nend\nputs names[winner]\n"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}\n\n"}, {"source_code": "log = []\nscores = Hash.new(0)\ncheck = Hash.new(0)\ngets.to_i.times{\n n,q = gets.split\n scores[n] += q.to_i\n log << [ n, q ] \n}\nm = scores.values.max\nlog.each{ | n, q |\n check[n] += q.to_i\n if check[n] >= m and scores[n] == m then\n puts n\n exit\n end\n}"}, {"source_code": "input = []\ngets.to_i.times { input << gets }\n\ns = Hash.new(0)\ninput.each do |i|\n name, score = i.split\n s[name] += score.to_i\nend\n\nmax = s.values.max\n\nss = Hash.new(0)\ninput.each do |i|\n name, score = i.split\n ss[name] += score.to_i\n if ss[name] >= max && s[name] == max\n puts name\n break\n end\nend"}, {"source_code": "\ndef process(m, ss)\n max = m.values.max\n maxes = m.select {|k, v| v == max}\n\n res = nil\n idx = 1001\n\n if maxes.size > 1\n ss = ss.select {|k, v| maxes.include? k}\n ss.each do |k, v|\n sum = 0\n v.each do |vv|\n sum += vv.score\n if sum >= max || vv.index > idx\n if res == nil || vv.index < idx\n res = k\n idx = vv.index\n end\n break\n end\n end\n end\n return res\n end\n\n maxes.keys[0]\nend\n\nnum = STDIN.gets.chomp.to_i\n\nS = Struct.new(:index, :score)\nm = {}\ns = {}\n\nn = 0\nwhile n < num\n n += 1\n line = STDIN.gets\n line.chomp!\n name, score = line.split\n score = score.to_i\n if m.include? name\n m[name] = m[name] + score\n else\n m[name] = score\n end\n if s.include? name\n s[name] << S.new(n, score)\n else\n s[name] = [S.new(n, score)]\n end\nend\n\nprint process(m, s)\n"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}\n"}, {"source_code": "h = {}\nn = gets.to_i\nl = []\nn.times { |i|\n a, b = gets.split\n l << [a,b]\n if h.key? a\n h[a] += b.to_i\n else\n h[a] = b.to_i\n end\n}\n\nmax = -1000 * n - 1\nindexes = []\nh.each do |a, b|\n if b > max\n max = b\n indexes = [a]\n elsif b == max\n indexes << a\n end\nend\n\nh.clear\n\nn.times { |i|\n\n a, b = l[i]\n\n if h.key? a\n h[a] += b.to_i\n else\n h[a] = b.to_i\n end\n\n if h[a] >= max and indexes.include? a\n print a\n exit(0)\n end\n\n}\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = gets.to_i\nrecords = []\nrecords = (1..n).map do\n name, score = gets.split\n {name: name, score: score.to_i}\nend\n\ntable = {}\nrecords.each do |rec|\n name = rec[:name]\n table[name] ||= 0\n table[name] += rec[:score]\nend\n\nmax = table.values.max\ntable2 = {}\nrecords.each do |rec|\n name = rec[:name]\n table2[name] ||= 0\n table2[name] += rec[:score]\n if table2[name] >= max and table[name] == max\n puts name\n exit\n end\nend"}, {"source_code": "input = gets.chomp.to_i\nlines=Array.new\nplayers = Hash.new\nwinner = 0\ninput.times do\n lines.push gets.chomp\n player , points = lines.at(lines.length-1).split(\" \")\n players[player] = players[player].to_i + points.to_i\nend\nplayers.each do |k,v|\n winner = v if v > winner\nend\nanswers = players.select do |k ,v|\n v==winner\nend\nplayers=Hash.new\nlines.each do |i|\n player , points = i.split(\" \")\n players[player] = players[player].to_i + points.to_i\n if answers.key? player\n if winner <= players[player]\n puts player\n break\n end\n end\nend"}, {"source_code": "n = gets.to_i\nans = Hash.new\nrec = Array.new\nfor i in 0...n do\n name, point = gets.split\n name = name.to_sym\n point = point.to_i\n\n if ans[name].nil?\n ans[name] = point\n else\n ans[name] = ans[name] + point\n end\n\n rec[i] = name, ans[name]\nend\n\ntemp = ans.to_a\nmax_num = temp.max { |a, b| a[1] <=> b[1] }[1]\nans_index = 0\n\nfor r in rec do\n if r[1] >= max_num && ans[r[0]] == max_num\n ans_index = r[0]\n break\n end\nend\n\nputs ans_index"}, {"source_code": "a={}\nc={}\nz={}\nl=[]\ngets.to_i.times{\n\tq,w=gets.split\n\ta[q]=a[q].to_i+w.to_i;\n\tl+=[[q,w]]\n}\nm=a.values.max\nl.each{|q,w|\n\tc[q]=c[q].to_i+w.to_i;\n\tif c[q]>=m and a[q]==m then\n\t\tputs q\n\t\texit\n\tend\n}\n"}, {"source_code": "#!/usr/bin/env ruby\n\n\nn = gets.chomp!.to_i\nh1 = {}\na = []\nn.times do\n name, round = gets.chomp!.split(\" \")\n round = round.to_i\n h1[name] = h1[name].to_i + round\n a << [name, round.to_i]\nend\n\nmax_score = h1.values.max\nh2 = {}\na.each do | e |\n h2[e[0]] = h2[e[0]].to_i + e[1]\n if h2[e[0]] >= max_score and h1[e[0]] == max_score\n puts e[0]\n exit 0\n end\nend\n\n"}, {"source_code": "n=gets.chomp!.to_i\nmemo=Hash.new(0)\nresult=[]\nn.times do\n result << gets.chomp.split\nend\nresult.each do |name,score|\n memo[name]+=score.to_i\nend\nmax=memo.values.max\nmemo.each_key do |key|\n if memo[key] == max\n memo[key]=0\n else\n memo[key] =-10000\n end\nend\nresult.each do |name,score|\n memo[name]+=score.to_i\n if memo[name] >= max\n puts name\n break\n end\nend\n"}], "negative_code": [{"source_code": "log = []\nscores = Hash.new(0)\ngets.to_i.times{\n n,q=gets.split\n scores[n]+=q.to_i\n log << [q,n]\n}\nm = scores.values.max\nlog.each{|q,n|\n if q.to_i>=m then\n p n\n exit\n end\n} \n \n"}, {"source_code": "n = gets.to_i\na = Hash.new([0])\nn.times do |_|\n\tw, s = gets.split\n\ta[w] = a[w][0] + s.to_i, -_\nend\nputs a.max{|a,b| a[1] <=> b[1] }[0]\n"}, {"source_code": "n = gets.to_i\nh = Hash.new\nmax = 0\nname = ''\n\nfor i in 1..n\n s, k = gets.chomp.split\n k = k.to_i\n if h[s].nil?\n h[s] = k\n else\n h[s] += k\n end\n if h[s] > max\n max = h[s]\n name = s\n end\nend\n\nputs name"}, {"source_code": "\ndef process(m, ss)\n max = m.values.max\n maxes = m.select {|k, v| v == max}\n\n res = nil\n idx = 1001\n\n if maxes.size > 1\n ss.each do |k, v|\n sum = 0\n v.each do |vv|\n sum += vv.score\n if sum >= max || vv.index > idx\n if res == nil || vv.index < idx\n res = k\n idx = vv.index\n end\n break\n end\n end\n end\n return res\n end\n\n maxes.keys[0]\nend\n\nnum = STDIN.gets.chomp.to_i\n\nS = Struct.new(:index, :score)\nm = {}\ns = {}\n\nn = 0\nwhile n < num\n n += 1\n line = STDIN.gets\n line.chomp!\n name, score = line.split\n score = score.to_i\n if m.include? name\n m[name] = m[name] + score\n else\n m[name] = score\n end\n if s.include? name\n s[name] << S.new(n, score)\n else\n s[name] = [S.new(n, score)]\n end\nend\n\nprint process(m, s)"}, {"source_code": "n = gets.to_i\nr = []\nfor i in 0 ... n \n a,b = gets.split\n r << [a, b.to_i]\nend\n\nh1 = Hash.new{0}\nr.each do |name,val|\n h1[name] += val\nend\n\nmaxi = r.max{|x,y| x[1] <=> y[1]}[1]\n\nh2 = Hash.new{0}\nr.each do |name,val|\n h2[name] += val\n if (h1[name] == maxi && h2[name] >= maxi)\n puts name\n break\n end\nend\n"}, {"source_code": "log = []\nscores = Hash.new(0)\ncheck = Hash.new(0)\ngets.to_i.times{\n n,q=gets.split\n scores[n]+=q.to_i\n log << [q,n]\n}\nm = scores.values.max\nlog.each{|q,n|\n check[n]+=q.to_i\n if check[n] >= m\n print n\n exit\n end\n} \n \n"}, {"source_code": "def getIndex(val, h)\n if (h.key?(val))\n return h[val]\n end\n index = h.size\n return h[val] = index\nend\n\nn = gets.to_i\nh = {}\nlast = []\nsum = []\n\nfor i in 0 ... n\n name,val = gets.split\n index = getIndex(name,h)\n val = val.to_i \n if (index < sum.size)\n sum[index] += val\n last[index] = i\n else\n sum << val\n last << i\n end\nend\n\nans = \"\"\nmaxi = sum.max\nfastest = n\nh.each do |key,index|\n if (sum[index] == maxi && last[index] < fastest)\n fastest = last[index]\n ans = key\n end\nend\nputs ans\n"}, {"source_code": "scores = {}\ngets.to_i.times do |i|\n name, score = gets.split\n score = score.to_i\n if scores.has_key? name\n if scores[name][2] < scores[name][0]+score\n scores[name][1] = i\n scores[name][2] = scores[name][0]+score\n end\n scores[name][0] += score\n else\n scores[name] = [score, i, score]\n end\nend\n\nscores = scores.to_a.sort_by! { |key, value| -value[0] }\nmax_value = scores[0]\n#puts scores.inspect\nscores.each do |v|\n if v[1][0] mx\n ans = s[0]\n mx = h[s[0]]\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\nh = {}\nans = '', mx = -1e9\nn.times do\n s = gets.split(' ')\n h[s[0]] = 0 if (h.has_key?(s[0]) == false)\n h[s[0]] += s[1].to_i\n if h[s[0]] > mx\n ans = s[0]\n mx = h[s[0]]\n end\nend\nputs ans\n"}, {"source_code": "n = STDIN.readline.to_i\nscore = Hash.new\nt = []\n\nn.times do |i|\n\tt << STDIN.readline.split\n\t# print STDIN.readline.split\n\t# print t\n\tt[i][1] = t[i][1].to_i\n\tif score[t[i][0]] == nil ;\n\t\tscore[t[i][0]] = 0\n\tend\n\tscore[t[i][0]] += t[i][1]\nend\n\nmaxscore = 0\nscore.each_value do |i|\n\tmaxscore = i if i > maxscore\nend\n\nscore.clear\nans = \"\"\nn.times do |i|\n\tif score[t[i][0]] == nil ;\n\t\tscore[t[i][0]] = 0\n\tend\n\tscore[t[i][0]] += t[i][1]\n\tans = t[i][0]; break if score[t[i][0]] >= maxscore\nend\nprint ans\n"}, {"source_code": "log = []\nscores = Hash.new(0)\ncheck = Hash.new(0)\ngets.to_i.times{\n n,q=gets.split\n scores[n]+=q.to_i\n log << [q,n]\n}\nm = scores.values.max\nlog.each{|q,n|\n check[n] += q.to_i\n if check[n] >= m and scores[n] == q.to_i then\n puts n\n exit\n end\n}\n"}, {"source_code": "\ndef process(m, ss)\n max = m.values.max\n maxes = m.select {|k, v| v == max}\n\n res = nil\n idx = 1001\n\n if maxes.size > 1\n ss.each do |k, v|\n sum = 0\n v.each do |vv|\n sum += vv.score\n if sum >= max || vv.index > idx\n if res == nil || vv.index < idx\n res = k\n idx = vv.index\n end\n break\n end\n end\n end\n return res\n end\n\n maxes.keys[0]\nend\n\nnum = STDIN.gets.chomp.to_i\n\nS = Struct.new(:index, :score)\nm = {}\ns = {}\n\nn = 0\nwhile n < num\n n += 1\n line = STDIN.gets\n line.chomp!\n name, score = line.split\n score = score.to_i\n if m.include? name\n m[name] = m[name] + score\n else\n m[name] = score\n end\n if s.include? name\n s[name] << S.new(n, score)\n else\n s[name] = [S.new(n, score)]\n end\nend\n\nprint process(m, s)"}, {"source_code": "N = gets.to_i\nh = Hash.new { |hash, key| hash[key] = [0, 10000, 0] }\nN.times do |i| \n n, p = gets.chomp.split\n p = p.to_i\n h[n][0] += p\n h[n][1] = i if p > 0\n h[n][2] += p if p > 0\nend\ns = h.sort { |a, b| b[1][0] <=> a[1][0]}\nu = s.select {|x| x[1][0] == s[0][1][0] && x[1][2] >= s[0][1][0] }\nu.sort! do |a, b|\n a[1][1] <=> b[1][1]\nend\nputs u[0][0]\n"}, {"source_code": "# Codeforces, Problem 2A\n# http://codeforces.com/contest/1/problem/C\n# Nate Collings\n\nPlayer = Struct.new(:score, :round)\n\nplayers = {}\nrounds = gets.chomp.to_i\n\nrounds.times do |round|\n player, score = gets.chomp.split(\"\\s\")\n score = score.to_i\n if players.has_key?(player)\n players[player].score += score\n players[player].round = round\n else\n players[player] = Player.new(score, round)\n end\nend\n\nmax = players.values.map { |v| v.score }.max\nwith_max = players.select { |_,v| v.score == max }\nwinner = with_max.min_by { |_,v| v.round }[0]\n\nputs winner"}, {"source_code": "num_lines = gets().chomp.to_i\nplayers_info = {}\nnum_lines.times{\n |i|\n name, score = gets().chomp.split(/[ ]+/)\n score = score.to_i\n if(players_info.has_key?(name)) then\n players_info[name][0] += score\n players_info[name][1] = i\n else\n players_info[name] = []\n players_info[name][0] = score\n players_info[name][1] = i\n end\n}\n\nputs players_info.to_a.sort {\n |a,b|\n (((b[1][0] <=> a[1][0]) * 2 + (a[1][1] <=> b[1][1])) <=> 0)\n}[0][0]\n"}, {"source_code": "n = gets.to_i\n\nh = Hash.new\nins = Array.new\nn.times do\n ins.push(gets)\n s = ins[-1].split(' ')\n h[s[0]] = 0 if (h.has_key?(s[0]) == false)\n h[s[0]] += s[1].to_i\nend\nmx = h.values.max\nb = h.select {|k, v| v == mx}\n\nh.clear()\nins.each do |s|\n s = s.split(' ')\n h[s[0]] = 0 if (h.has_key?(s[0]) == false)\n h[s[0]] += s[1].to_i\n if h[s[0]] == mx and b.has_key?(s[0])\n puts s[0]\n break\n end\nend\n"}, {"source_code": "log = []\nscores = Hash.new(0)\ngets.to_i.times{\n n,q=gets.split\n scores[n]+=q.to_i\n log << [q,n]\n}\nm = scores.values.max\nlog.each{|q,n|\n if q.to_i>=m then\n p n\n exit\n end\n} \n \n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.chomp!.to_i\nscores = {}\nscores['max-scorer'] = nil\nn.times do\n name, round = gets.chomp!.split(\" \")\n max_score = scores[scores['max-scorer']].to_i\n curr_score = round.to_i + scores[name].to_i\n scores[name] = curr_score\n scores['max-scorer'] = name if (curr_score > max_score)\nend\n\nputs scores['max-scorer']\n"}, {"source_code": "#!/usr/bin/env ruby\n\nh = Hash.new(0)\nt = gets.to_i\nm = -1\nwinner = \"\"\n\nfor i in 0...t\n\n s = gets.split(' ')\n\n a = s[0]\n b = s[1].to_i\n\n h[a] += b\n\n if h[a] > m\n m = h[a]\n winner = a\n end\n\nend\n\nputs winner\n\n \n"}, {"source_code": "n = gets.to_i\nans = Hash.new\nfor i in 0...n do\n name, point = gets.split\n name = name.to_sym\n point = point.to_i\n\n if ans[name].nil?\n ans[name] = point, i \n else\n ans[name][0] = ans[name][0] + point\n end\n\n ans[name][1] = i\nend\n\nans = ans.to_a\nans.sort! { |a, b| b[1][0] <=> a[1][0] }\n\ni = 0\nn = ans.size - 1\nfinal = ans[0]\nfinal_next = final\n\nwhile i < n && final_next[1][0] == final[1][0]\n if final_next[1][1] < final[1][1]\n final = final_next\n final_next = ans[i + 1]\n else\n final_next = ans[i + 1]\n end\n i = i + 1\nend\n\nif final_next[1][1] < final[1][1] && final_next[1][0] == final[1][0]\n final = final_next\nend\n\np final[0].to_s"}, {"source_code": "table = {}\nlined = []\nARGF.each_line do |line|\n if ARGF.lineno != 1\n name, mark = line.split\n if !table.has_key?(name)\n table[name] = [mark.to_i]\n else\n table[name] += [table[name].last + mark.to_i]\n end\n lined.push({:name => name, :mark => table[name].last})\n end\nend\n\nmaxNames = []\nmax = 0\n\ntable.keys.each do |name|\n if max < table[name].last\n maxNames = [name]\n max = table[name].last\n elsif max = table[name].last\n maxNames.push name\n end\nend\n\nif maxNames.length == 1\n puts maxNames[0]\nelse\n lined.each do |val|\n if val[:mark] >= max\n puts val[:name]\n break\n end\n end\nend\n"}, {"source_code": "n = gets.to_i\nans = Hash.new\nrec = Array.new\nfor i in 0...n do\n name, point = gets.split\n name = name.to_sym\n point = point.to_i\n\n if ans[name].nil?\n ans[name] = point\n else\n ans[name] = ans[name] + point\n end\n\n rec[i] = name, ans[name]\nend\n\nans = ans.to_a\nmax_num = ans.max { |a, b| a[1] <=> b[1] }[1]\nans_index = 0\n\nfor r in rec do\n if r[1] >= max_num\n ans_index = r[0]\n break\n end\nend\n\nputs ans_index"}, {"source_code": "N = gets.to_i\nh = Hash.new { |hash, key| hash[key] = [0, 10000, 0] }\nN.times do |i| \n n, p = gets.chomp.split\n p = p.to_i\n h[n][0] += p\n h[n][1] = i\n h[n][2] += p if p > 0\nend\ns = h.sort { |a, b| b[1][0] <=> a[1][0]}\nu = s.select {|x| x[1][0] == s[0][1][0] && x[1][2] >= s[0][1][0] }\nu.sort! { |a, b| a[1][1] <=> b[1][1] }\nputs u[0][0]\n"}, {"source_code": "n = gets.chomp.to_i\nh = Hash.new\nas = Array.new\nfor i in 1..n\n\ts = gets.chomp\n\tas.push( s )\nend\nfor i in 1..n\n\tnm,sc = as[i-1].split(/ /)\n\tsc = sc.to_i\n\tsc += h[nm] if h.has_key?(nm)\n\th[nm] = sc\nend\nhv = h.to_a.sort {|a,b|\n\tb[1] <=> a[1]\n}\n\nif hv.length == 1 || hv[0][1] > hv[1][1]\n\tputs hv[0][0]\nelse\n\th.clear\n\tfor i in 1..n\n\t\tnm,sc = as[i-1].split(/ /)\n\t\tsc = sc.to_i\n\t\tsc += h[nm] if h.has_key?(nm)\n\t\th[nm] = sc\n\t\tif sc >= hv[0][1]\n\t\t\tputs nm\n\t\t\texit\n\t\tend\n\tend\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\n$global_hash = Hash.new\n$max_score = 0\n$leader = \"\"\n\ndef process_score(score_string)\n\tparts = score_string.split(' ')\n\tkey = parts[0]\n\tvalue = parts[1].to_i\n\n\tif ($global_hash.has_key? key)\n\t\t$global_hash[key] += value\n\telse\n\t\t$global_hash[key] = value\n\tend\n\n\tif ($global_hash[key] > $max_score)\n\t\t$max_score = $global_hash[key]\n\t\t$leader = key\n\tend\nend\n\n#results for testing\n# match_results = []\n# match_results << \"andrew 3\"\n# match_results << \"andrew 2\"\n# match_results << \"mike 5\"\n\nrepeats = gets.to_i\nmatch_results = []\n\nwhile (repeats > 0)\n\tmatch_results << gets.strip\n\trepeats -= 1\nend\n\nfor score_string in match_results\n\tprocess_score(score_string)\nend\n\nputs $leader"}, {"source_code": "n=gets.chomp!.to_i\nmemo=Hash.new\nscore=[]\nn.times do\n score << gets.chomp\nend\nn.times do |j|\n tmp=score[j].split\n if memo.key?(tmp[0])\n memo[tmp[0]]+=tmp[1].to_i\n else\n memo[tmp[0]]=tmp[1].to_i\n end\nend\nmax=memo.values.max\nmemo.clear()\nn.times do |j|\n tmp=score[j].split\n if memo.key?(tmp[0])\n memo[tmp[0]]+=tmp[1].to_i\n else\n memo[tmp[0]]=tmp[1].to_i\n end\n if memo[tmp[0]]>=max\n puts tmp[0]\n break\n end\nend\n"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\n\nscore_map = {}\nat_index_by_name = {}\n1.upto(lines) do |i|\n name, score = gets.split\n score = score.to_i\n\n score_map[name] ||= 0\n score_map[name] += score\n\n at_index_by_name[name] ||= {\n score: -99_999_999,\n index: 9_999_999\n }\n\n next unless at_index_by_name[name][:score] < score_map[name]\n\n at_index_by_name[name] = {\n score: score_map[name],\n index: i\n }\nend\n\nscores = score_map.to_a.sort_by(&:last).reverse\nputs(\n scores\n .select { |score| scores.last.last == score.last }\n .min_by { |score| at_index_by_name[score.first][:index] }\n .first\n)\n"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\n\nscore_map = {}\nat_index_by_name = {}\n1.upto(lines) do |i|\n name, score = gets.split\n score = score.to_i\n\n score_map[name] ||= 0\n score_map[name] += score\n\n at_index_by_name[name] ||= {}\n\n next if at_index_by_name[name][score_map[name]]\n\n at_index_by_name[name][score_map[name]] = i\nend\n\nscores = score_map.to_a.sort_by(&:last)\nputs(\n scores\n .select { |score| scores.last.last == score.last }\n .min_by { |score| at_index_by_name[score.first][score.last] }\n .first\n)\n"}, {"source_code": "# Codeforces, Problem 2A\n# http://codeforces.com/contest/1/problem/C\n# Nate Collings\n\nplayers = {}\nmax = 0\nwinner = nil\nrounds = gets.chomp.to_i\n\nrounds.times do\n player, score = gets.chomp.split(\"\\s\")\n score = score.to_i\n players[player] = players.has_key?(player) ? players[player] += score : score\n if players[player] > max\n winner = player\n max = players[player]\n end\nend\n\nputs winner"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.chomp!.to_i\nscores = {}\nscores['max-scorer'] = nil\nn.times do\n name, round = gets.chomp!.split(\" \")\n max_score = scores[scores['max-scorer']].to_i\n curr_score = round.to_i + scores[name].to_i\n scores[name] = curr_score\n scores['max-scorer'] = name if (curr_score > max_score)\nend\n\nputs scores['max-scorer']\n"}, {"source_code": "#!/usr/bin/env ruby\n\nh = Hash.new(0)\nt = gets.to_i\nm = -1\nwinner = \"\"\n\nfor i in 0...t\n\n s = gets.split(' ')\n\n a = s[0]\n b = s[1].to_i\n\n h[a] += b\n\n if h[a] > m\n m = h[a]\n winner = a\n end\n\nend\n\nputs winner\n\n \n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\nn=gets.to_i\n\ndata = []\nhs = Hash.new(0)\n\nn.times{\n\tname, points = gets.split\t\n\t\n\tdata << [name, points.to_i]\n\ths[name]+=points.to_i\n}\n\nmax_points = hs.values.max\n\nhs2 = Hash.new(0)\ndata.each{|name, points|\n\ths2[name]+=points\n\t\n\tif hs2[name]==max_points\n\t\tputs name\n\t\tbreak\n\tend\n}\n"}, {"source_code": "num_lines = gets().chomp.to_i\nplayers_info = {}\nnum_lines.times{\n |i|\n name, score = gets().chomp.split(/[ ]+/)\n score = score.to_i\n if(players_info.has_key?(name)) then\n if(score != 0) then\n players_info[name][0] += score\n players_info[name][1] = i\n end\n else\n players_info[name] = []\n players_info[name][0] = score\n players_info[name][1] = i\n end\n}\n\nputs players_info.to_a.sort {\n |a,b|\n (((b[1][0] <=> a[1][0]) * 3 + (a[1][1] <=> b[1][1])) <=> 0)\n}[0][0]\n"}, {"source_code": "input = gets.chomp.to_i\nlines=Array.new\nplayers = Hash.new\nwinner = 0\nwon=''\ninput.times do\n lines.push gets.chomp\n player , points = lines.at(lines.length-1).split(\" \")\n players[player] = players[player].to_i + points.to_i\nend\nplayers.each do |k,v|\n winner = v if v > winner\nend\nanswers = players.select do |k ,v|\n v==winner\nend\nplayers=Hash.new\nlines.each do|i|\n player , points = i.split(\" \")\n players[player] = players[player].to_i + points.to_i\n if winner == players[player] and answers.key? player\n won=player\n break\n end\nend\nputs won"}, {"source_code": "n=gets.chomp!.to_i\nmemo=Hash.new\npremax=-1111\nmax=-1000\nname=\"\"\nn.times do \n tmp=gets.chomp!.split()\n if memo.key?(tmp[0])\n memo[tmp[0]]+=tmp[1].to_i\n else\n memo[tmp[0]]=tmp[1].to_i\n end\n max=-1000\n tmpname=\"\"\n memo.each do |key,value|\n if max= 0\n\t\t\t$players_scores[key][:index] = $operation_index\n\t\telse\n\t\t\t$players_scores[key][:index] = 0\n\t\tend\n\tend\n\n\t$operation_index += 1\nend\n\n# results for testing\n# match_results = []\n# match_results << \"andrew 3\"\n# match_results << \"andrew 2\"\n# match_results << \"andrew 1\"\n# match_results << \"mike 5\"\n# match_results << \"andrew -1\"\n# match_results << \"john 5\"\n\n# match_results << \"andrew 3\"\n# match_results << \"andrew 2\"\n# match_results << \"mike 5\"\n\nrepeats = gets.to_i\nmatch_results = []\n\nwhile (repeats > 0)\n\tmatch_results << gets.strip\n\trepeats -= 1\nend\n\nfor score_string in match_results\n\tprocess_score(score_string)\nend\n\nplayers = $players_scores.values\nplayers.sort! { |a,b| a[:score] == b [:score] ? a[:index] <=> b[:index] : b[:score] <=> a[:score]}\n\nputs $players_scores.invert[players[0]]"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\n\nscore_map = {}\nat_index_by_name = {}\n1.upto(lines) do |i|\n name, score = gets.split\n score = score.to_i\n\n score_map[name] ||= 0\n score_map[name] += score\n\n at_index_by_name[name] ||= {\n score: score_map[name],\n index: i\n }\n\n next unless at_index_by_name[name][:score] < score_map[name]\n\n at_index_by_name[name] = {\n score: score_map[name],\n index: i\n }\nend\n\nscores = score_map.to_a.sort_by(&:last)\nputs(\n scores\n .select { |score| scores.last.last == score.last }\n .min_by { |score| at_index_by_name[score.first][:index] }\n .first\n)\n"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\n\nscore_map = {}\nat_index_by_name = {}\n1.upto(lines) do |i|\n name, score = gets.split\n score = score.to_i\n\n score_map[name] ||= 0\n score_map[name] += score\n\n at_index_by_name[name] ||= {}\n\n next if at_index_by_name[name][score_map[name]]\n\n at_index_by_name[name][score_map[name]] = i\nend\n\nscores = score_map.to_a.sort_by(&:last)\nputs(\n scores\n .select { |score| scores.last.last == score.last }\n .min_by { |score| at_index_by_name[score.first][score.last] }\n .first\n)\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\nn=gets.to_i\n\ndata = []\nhs = Hash.new(0)\n\nn.times{\n\tname, points = gets.split\t\n\t\n\tdata << [name, points.to_i]\n\ths[name]+=points.to_i\n}\n\nmax_points = hs.values.max\n\nhs2 = Hash.new(0)\ndata.each{|name, points|\n\ths2[name]+=points\n\t\n\tif hs2[name]==max_points\n\t\tputs name\n\t\tbreak\n\tend\n}\n"}, {"source_code": "def process(m, ss)\n max = m.values.max\n maxes = m.select {|k, v| v == max}\n\n while maxes.size > 1 && !ss.empty?\n s = ss.pop()\n if s.score > 0 && maxes.include?(s.name)\n maxes.delete s.name\n end\n end\n\n maxes.keys()[0]\nend\n\nnum = STDIN.gets.chomp.to_i\n\nS = Struct.new(:name, :score)\nm = {}\ns = []\n\nn = 0\nwhile n < num\n n += 1\n line = STDIN.gets\n line.chomp!\n name, score = line.split\n score = score.to_i\n if m.include? name\n m[name] = m[name] + score\n else\n m[name] = score\n end\n s << S.new(name, score)\nend\n\nprint process(m, s)"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nh = {}\nst = []\nn.times {\n name, score = gets.split\n score = score.to_i\n h[name] ||= 0\n h[name] += score if score >= 0\n st << [name, score]\n}\nmax = h.values.max\ncands = []\nfor k,v in h\n if v == max\n cands << k\n end\nend\nif cands.length == 1\n puts cands[0]\nelse\n h2 = {}\n for s in st\n h2[s[0]] ||= 0\n h2[s[0]] += s[1] if s[1] >= 0\n if h2[s[0]] >= max\n puts s[0]\n break\n end\n end\nend"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\n\nscore_map = {}\nat_index_by_name = {}\n1.upto(lines) do |i|\n name, score = gets.split\n score = score.to_i\n\n score_map[name] ||= 0\n score_map[name] += score\n\n at_index_by_name[name] ||= {\n score: score_map[name],\n index: i\n }\n\n next unless at_index_by_name[name][:score] < score_map[name]\n\n at_index_by_name[name] = {\n score: score_map[name],\n index: i\n }\nend\n\nscores = score_map.to_a.sort_by(&:last)\nputs(\n scores\n .select { |score| scores.last.last == score.last }\n .min_by { |score| at_index_by_name[score.first][:index] }\n .first\n)\n"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\n\nscore_map = {}\nat_index_by_name = {}\n1.upto(lines) do |i|\n name, score = gets.split\n score = score.to_i\n\n score_map[name] ||= 0\n score_map[name] += score\n\n at_index_by_name[name] ||= {\n score: 0,\n index: 0\n }\n\n next unless at_index_by_name[name][:score] <= score_map[name]\n\n at_index_by_name[name] = {\n score: score_map[name],\n index: i\n }\nend\n\nscores = score_map.sort_by(&:last)\nputs(\n scores\n .select { |score| scores.last.last == score.last }\n .min_by { |score| at_index_by_name[score.first][:index] }\n .first\n)\n"}, {"source_code": "num_lines = gets().chomp.to_i\nplayers_info = {}\nnum_lines.times{\n |i|\n name, score = gets().chomp.split(/[ ]+/)\n score = score.to_i\n if(players_info.has_key?(name)) then\n players_info[name][0] += score\n if(score > 0) then players_info[name][1] = i end\n else\n players_info[name] = []\n players_info[name][0] = score\n players_info[name][1] = i\n end\n}\n\nputs players_info.to_a.sort {\n |a,b|\n (((b[1][0] <=> a[1][0]) * 2 + (a[1][1] <=> b[1][1])) <=> 0)\n}[0][0]\n"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\np = ''\nn.times do\n name, score = gets.split\n score = score.to_i\n h[name] += score\n p = name if h[name] > h[p]\nend\nmx = h.max_by{|name, s| s}\nputs mx[1] == h[p] ? p : mx[0]\n"}, {"source_code": "h = {}\nn = gets.to_i\nn.times { |i|\n a, b = gets.split\n if h.key? a\n h[a] = [h[a][0] + b.to_i, h[a][0] + b.to_i > h[a][2] ? i : h[a][1], h[a][0] + b.to_i > h[a][2] ? h[a][0] + b.to_i : h[a][2] ]\n else\n h[a] = [b.to_i, i, b.to_i]\n end\n}\n\nmax2 = -1000 * n - 1\nmax1 = n\nindex = ''\n\nh.each do |a, b|\n if b[2] > max2\n max2 = b[2]\n max1 = b[1]\n index = a\n elsif b[2] == max2 and b[1] < max1\n max1 = b[1]\n index = a\n end\nend\n\nprint index\n"}, {"source_code": "def getIndex(val, h)\n if (h.key?(val))\n return h[val]\n end\n index = h.size\n return h[val] = index\nend\n\nn = gets.to_i\nh = {}\ninput = []\nsum = []\ninputLog = []\n\nfor i in 0 ... n\n name,val = gets.split\n index = getIndex(name,h)\n val = val.to_i \n input << val\n if (index < sum.size)\n sum[index] += val\n else\n sum << val\n inputLog << []\n end\n inputLog[index] << i\nend\n\nans = \"\"\nmaxi = sum.max\nfastest = n\nh.each do |key,index|\n if (sum[index] == maxi)\n sum,tmp = 0,0\n for i in 0 ... inputLog[index].size \n sum += input[inputLog[index][i]];\n if (sum >= maxi)\n tmp = inputLog[index][i];\n break\n end\n end\n if (tmp < fastest)\n ans = key\n fastest = tmp\n end\n end\nend\nputs ans\n"}, {"source_code": "require 'set'\n\nn = gets.to_i\n\nh = Hash.new\na = Array.new\nb = Array.new\nn.times do\n s = gets.split(' ')\n h[s[0]] = 0 if (h.has_key?(s[0]) == false)\n h[s[0]] += s[1].to_i\n a.push(s[0])\n b.push(h[s[0]])\nend\nmx = h.values.max\n\nd = Set.new\nh.each do |k, v|\n d.add(k) if v == mx\nend\n\na.each_index do |i|\n if d.include? (a[i]) and b[i] == mx\n puts a[i]\n break\n end\nend\n"}, {"source_code": "num_lines = gets().chomp.to_i\nplayers_info = {}\nnum_lines.times{\n |i|\n name, score = gets().chomp.split(/[ ]+/)\n score = score.to_i\n if(players_info.has_key?(name)) then\n players_info[name][0] += score\n players_info[name][1] = i\n else\n players_info[name] = []\n players_info[name][0] = score\n players_info[name][1] = i\n end\n}\n\nputs players_info.to_a.sort {\n |a,b|\n (((b[1][0] <=> a[1][0]) * 2 + (a[1][1] <=> b[1][1])) <=> 0)\n}[0][0]\n"}, {"source_code": "s = Hash.new(0)\nt = {}\ngets.to_i.times do |i|\n name, score = gets.split\n s[name] += score.to_i\n t[name] = i\nend\n\nmax = s.values.max\nputs t.select { |k, v| s[k] == max }.min_by {|k, v| v}.first"}, {"source_code": "def getIndex(val, h)\n if (h.key?(val))\n return h[val]\n end\n index = h.size\n return h[val] = index\nend\n\nn = gets.to_i\nh = {}\nsum = []\nlast = []\n\nfor i in 0 ... n\n name,val = gets.split\n index = getIndex(name,h)\n val = val.to_i \n if (index < sum.size)\n sum[index] += val\n last[index] = i\n else\n sum << val\n last << i\n end\nend\n\nans = \"\"\nmaxi = sum.max\nfastest = n\nh.each do |key,value|\n if (sum[value] == maxi && last[value] < fastest)\n ans = key\n fastest = last[value]\n end\nend\nputs ans\n"}, {"source_code": "A={}\nb={}\nl=[]\ngets.to_i.times{\n q,w=gets.split;\n A[q]=A[q].to_i+w.to_i;\n l+=[[q,w]]\n \n \n}\nm=A.values.max\nl.each{|q,w|\n b[q]=b[q].to_i+w.to_i;\nif b[q]>=m then\n puts q\n exit\nend\n}"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split}\nh = Hash.new(0)\na.each{|name, s| h[name] += s.to_i}\nmx = h.max_by{|name, s| s}[1]\nh2 = Hash.new(0)\na.each do |name, s|\n h2[name] += s.to_i\n if h2[name] == mx\n puts name\n break\n end\nend\n"}, {"source_code": "A={}\nb={}\nl=[]\ngets.to_i.times{\n q,w=gets.split;\n A[q]=A[q].to_i+w.to_i;\n l+=[[q,w]]\n \n \n}\nm=A.values.max\nl.each{|q,w|\n b[q]=b[q].to_i+w.to_i;\nif b[q]>=m then\n puts q\n exit\nend\n}"}, {"source_code": "n=gets.chomp!.to_i\nmemo=Hash.new\npremax=-1111\nmax=-1000\nname=\"\"\nn.times do \n tmp=gets.chomp!.split()\n if memo.key?(tmp[0])\n memo[tmp[0]]+=tmp[1].to_i\n else\n memo[tmp[0]]=tmp[1].to_i\n end\n max=-1000\n tmpname=\"\"\n memo.each do |key,value|\n if max m\n m = h[a]\n winner = a\n end\n\nend\n\nputs winner\n\n \n"}, {"source_code": "players = {}\ngets.to_i.times do |i|\n name, point = gets.chomp.split\n players[name] ||= {:point => 0, :last => nil}\n players[name][:point] += point.to_i\n players[name][:last] = i\nend\nresult = players.sort{|a, b| (b[1][:point] <=> a[1][:point]).nonzero? || a[1][:last] <=> b[1][:last]}\n#p result\nputs result[0][0]\n"}, {"source_code": "log = []\nscores = Hash.new(0)\ncheck = Hash.new(0)\ngets.to_i.times{\n n,q=gets.split\n scores[n]+=q.to_i\n log << [q,n]\n}\nm = scores.values.max\nlog.each{|q,n|\n check[n]+=q.to_i\n if check[n] >= m\n print n\n exit\n end\n} \n \n"}, {"source_code": "# Codeforces, Problem 2A\n# http://codeforces.com/contest/1/problem/C\n# Nate Collings\n\nplayers = {}\nmax = 0\nwinner = nil\nrounds = gets.chomp.to_i\n\nrounds.times do\n player, score = gets.chomp.split(\"\\s\")\n score = score.to_i\n players[player] = players.has_key?(player) ? players[player] += score : score\n players[player] = -1 if score < 0\n if players[player] > max\n winner = player\n max = players[player]\n end\nend\n\nputs winner"}, {"source_code": "h = {}\nn = gets.to_i\nl = []\nn.times { |i|\n a, b = gets.split\n l << [a,b]\n if h.key? a\n h[a] += b.to_i\n else\n h[a] = b.to_i\n end\n}\n\nmax = -1000 * n - 1\nh.each do |a, b|\n if b > max\n max = b\n end\nend\n\nh.clear\n\nn.times { |i|\n\n a, b = l[i]\n\n if h.key? a\n h[a] += b.to_i\n else\n h[a] = b.to_i\n end\n\n if h[a] >= max\n print a\n exit(0)\n end\n\n}\n\n"}, {"source_code": "num_lines = gets().chomp.to_i\ntop_score = 0\nscores = {}\nscores_fset ={}\n\naddscore = -> (fn, maxscore, index) do\n (-> (score) {\n prev = fn.call(score)\n return prev if prev\n return index if score <= maxscore\n return -1 \n })\nend\n\nnum_lines.times do |index|\n line = gets().chomp\n name, score = line.split\n score = score.to_i\n scores[name] ||= 0\n scores[name] += score\n\n scores_fset[name] ||= -> (x) do\n (-> () {\n return index if x <= score\n return -1\n }).call()\n end\n\n if scores_fset[name].call(scores[name]) == -1\n scores_fset[name] = addscore.call(scores_fset[name], scores[name], index)\n end\n\n top_score = scores[name] if scores[name] > top_score\nend\n\ntop_scorers = scores.select {|k, v| v == scores.values.max}\nputs top_scorers.min_by {|k, v| scores_fset[k].call(top_score)}[0]\n"}, {"source_code": "table = {}\nlined = []\nARGF.each_line do |line|\n if ARGF.lineno != 1\n name, mark = line.split\n if !table.has_key?(name)\n table[name] = [mark.to_i]\n else\n table[name] += [table[name].last + mark.to_i]\n end\n lined.push({:name => name, :mark => table[name].last})\n end\nend\n\nmaxNames = []\nmax = 0\n\ntable.keys.each do |name|\n if max < table[name].last\n maxNames = [name]\n max = table[name].last\n elsif max == table[name].last\n puts \"Add #{name} with #{max}\"\n end\nend\n\nif maxNames.length == 1\n puts maxNames[0]\nelse\n lined.each do |val|\n if val[:mark] >= max\n puts val[:name]\n break\n end\n end\nend\n"}, {"source_code": "A={}\nb={}\nl=[]\ngets.to_i.times{\n q,w=gets.split;\n A[q]=A[q].to_i+w.to_i;\n l+=[[q,w]]\n \n \n}\nm=A.values.max\nl.each{|q,w|\n b[q]=b[q].to_i+w.to_i;\nif b[q]>=m and A[q]=m then\n puts q\n exit\nend\n}"}, {"source_code": "winner = \"\"\nmax_score = 0\nscoreboard = Hash.new(0)\ngets.to_i.times do\n player, score = gets.split\n scoreboard[player] += score.to_i\n if scoreboard[player] > max_score\n winner = player\n max_score = scoreboard[player]\n end\nend\n\nputs winner\n"}, {"source_code": "log = []\nscores = Hash.new(0)\ngets.to_i.times{\n n,q=gets.split\n scores[n]+=q.to_i\n log << [q,n]\n}\nm = scores.values.max\nlog.each{|q,n|\n if q.to_i>=m then\n print n\n exit\n end\n} \n "}, {"source_code": "h = {}\nn = gets.to_i\nn.times { |i|\n a, b = gets.split\n if h.key? a\n h[a] = [h[a][0] + b.to_i, h[a][0] + b.to_i > h[a][2] ? i : h[a][1], h[a][0] + b.to_i > h[a][2] ? h[a][0] + b.to_i : h[a][2] ]\n else\n h[a] = [b.to_i, i, b.to_i]\n end\n}\n\nmax2 = -1000 * n - 1\nmax1 = n\nindex = ''\n\nh.each do |a, b|\n if b[2] > max2\n max2 = b[2]\n max1 = b[1]\n index = a\n elsif b[2] == max2 and b[1] < max1\n max1 = b[1]\n index = a\n end\nend\n\nprint index\n"}, {"source_code": "s = Hash.new(0)\nt = {}\ngets.to_i.times do |i|\n name, score = gets.split\n s[name] += score.to_i\n t[name] = i\nend\n\nmax = s.values.max\nputs t.select { |k, v| s[k] == max }.min_by {|k, v| v}.first"}, {"source_code": "idx = 0\ntable = {}\nARGF.each_line do |line|\n if ARGF.lineno != 1\n name, mark = line.split\n if !table.has_key?(name)\n table[name] = {'mark' => mark.to_i, 'pos' => idx}\n else\n table[name]['mark'] += mark.to_i\n table[name]['pos'] = idx\n end\n idx = idx + 1\n end\nend\n\nmaxMark = 0\nminIdx = 0\nmax = ''\ntable.keys.each do |key|\n val = table[key]\n if maxMark < val['mark']\n maxMark = val['mark']\n minIdx = val['pos']\n max = key\n elsif maxMark == val['mark'] && minIdx > val['pos']\n minIdx = val['pos']\n max = key\n end\nend\n\nputs max"}, {"source_code": "num_lines = gets().chomp.to_i\ntop_score = 0\nscores = {}\nscores_fset ={}\n\naddscore = -> (fn, maxscore, index) do\n (-> (score) {\n prev = fn.call(score)\n return prev if prev\n return index if score <= maxscore\n return false\n })\nend\n\nnum_lines.times do |index|\n line = gets().chomp\n name, score = line.split\n score = score.to_i\n scores[name] ||= 0\n scores[name] += score\n\n scores_fset[name] ||= -> (x) do\n (-> () {\n return index if x <= score\n return false\n }).call()\n end\n\n unless scores_fset[name].call(scores[name])\n scores_fset[name] = addscore.call(scores_fset[name], scores[name], index)\n end\n\n top_score = scores[name] if scores[name] > top_score\nend\n\nputs top_scorers = scores.select {|k, v| v == scores.values.max}\nputs top_scorers.min_by {|k, v| scores_fset[k].call(top_score)}[0]\n"}, {"source_code": "N = gets.to_i\nh = Hash.new { |hash, key| hash[key] = [0, 10000] }\nN.times do |i| \n n, p = gets.chomp.split\n p = p.to_i\n h[n][0] += p\n h[n][1] = i\nend\ns = h.sort { |a, b| a[1][0] == b[1][0] ? a[1][1] <=> b[1][1] : b[1][0] <=> a[1][0] }\nputs s[0][0]\n"}, {"source_code": "#http://codeforces.com/problemset/problem/2/A\n\nn = gets.to_i\ndir = Hash.new(0)\nstep = Array.new\nmax_val = 0\nmax_name = Array.new\n\nfor i in 1..n\n name, score = gets.chomp.strip.split(\" \")\n score = score.to_i\n dir[name] += score\n record = Hash[\"name\" => name, \"score\" => dir[name]]\n step << record\nend\n\ndir.each_key do |key|\n if dir[key] > max_val\n max_val = dir[key]\n max_name << key\n elsif dir[key] == max_val\n max_name << key\n end\nend\n\nflag = 0\nif max_name.size == 1\n puts max_name[0]\nelse\n for i in 0...step.size\n if step[i][\"score\"] >= max_val\n for j in 0...max_name.size\n if step[i][\"name\"] == max_name[j] and flag == 0\n puts max_name[j]\n flag = 1\n end\n end\n end\n end\nend"}, {"source_code": "def getIndex(val, h)\n if (h.key?(val))\n return h[val]\n end\n index = h.size\n return h[val] = index\nend\n\nn = gets.to_i\nh = {}\ninput = []\nsum = []\ninputLog = []\n\nfor i in 0 ... n\n name,val = gets.split\n index = getIndex(name,h)\n val = val.to_i \n input << val\n if (index < sum.size)\n sum[index] += val\n else\n sum << val\n inputLog << []\n end\n inputLog[index] << i\nend\n\nans = \"\"\nmaxi = sum.max\nfastest = n\nh.each do |key,index|\n if (sum[index] == maxi)\n sum,tmp = 0,0\n for i in 0 ... inputLog[index].size \n sum += input[inputLog[index][i]];\n if (sum > maxi)\n tmp = inputLog[index][i];\n break\n end\n end\n if (tmp < fastest)\n ans = key\n fastest = tmp\n end\n end\nend\nputs ans\n"}, {"source_code": "h = {}\nn = gets.to_i\nn.times { |i|\n a, b = gets.split\n if h.key? a\n h[a] = [h[a][0] + b.to_i, h[a][0] + b.to_i > h[a][2] ? i : h[a][1], h[a][0] + b.to_i > h[a][2] ? h[a][0] + b.to_i : h[a][2] ]\n else\n h[a] = [b.to_i, i, b.to_i]\n end\n}\n\nmax2 = -1000 * n - 1\nmax1 = n\nindex = ''\n\nh.each do |a, b|\n if b[2] > max2\n max2 = b[2]\n max1 = b[1]\n index = a\n elsif b[2] == max2 and b[1] < max1\n max1 = b[1]\n index = a\n end\nend\n\nprint index\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\nn=gets.to_i\n\ndata = []\nhs = Hash.new(0)\n\nn.times{\n\tname, points = gets.split\t\n\t\n\tdata << [name, points.to_i]\n\ths[name]+=points.to_i\n}\n\nmax_points = hs.values.max\n\nhs2 = Hash.new(0)\ndata.each{|name, points|\n\ths2[name]+=points\n\t\n\tif hs2[name]==max_points\n\t\tputs name\n\t\tbreak\n\tend\n}\n"}, {"source_code": "n=gets.chomp.to_i\nnc=0 \n@hash={}\n@hash_total={}\nloop do\t\n\tbreak if nc == n\n\tinput=gets.chomp.split(\" \")\n\tk=0\n\tif nc >= 1\n\t\t@hash.each_key do |plr_nm|\n\t\t\tif plr_nm!=input[0]\n\t\t\t\tk+=1\n\t\t\tend\n\t\tend\n\t\tif k==@hash.length\n\t\t\t@hash[input [0]]=[input[1].to_i]\n\t\telse\n\t\t@hash[input [0]]=@hash[input [0]]+[input[1].to_i]\n\t\tend\n\telse\n\t\t@hash[input [0]]=[input[1].to_i]\n\tend\n\n\tnc+=1\nend\ndef Total(key,array)\n k=0\n\tarray.each do|l|\n\t k=k+l\n\tend\n @hash_total[key]=k\nend\n@hash.each_pair do|a,b|\n\tTotal(a,b)\nend\n\ndef Tiebreaker(a,b)\n ka=0\n ba=0\n k=0\n @hash[a[0]].each do|cn|\n\t\tk=k+cn\n\t\tka+=1\n\t\tbreak if k >= a[1]\n\tend\t\n\tk=0\t\t\n @hash[b[0]].each do|cn|\n\t\tk=k+cn\n\t\tba+=1\n\t\tbreak if k >= b[1]\n\tend\t\n\tif ka>ba\n\t\treturn b\n\telse \n\t\treturn a\n\tend\t\nend\t\n\t\t\t\n \n\n\n\nwin= @hash_total.inject do |memo,n|\n if memo[1]>n[1]\n\tmemo\n elsif memo[1]=n[1]\n Tiebreaker(memo,n)\n else \n\tn\nend\t\nend\nputs win[0]\n"}, {"source_code": "n = gets.chomp.to_i\nh = Hash.new(n)\nhsnm = \"\"\nhssc = 0\nfor i in 1..n\n\tnm,sc = gets.chomp.split(/ /)\n\tsc = sc.to_i\n\tsc += h[nm] if h.has_key?(nm)\n\th[nm] = sc\n\tif hssc < sc\n\t\thsnm = nm\n\t\thssc = sc\n\tend\nend\nputs hsnm\n"}, {"source_code": "h = {}\nhh = {}\nfor name,score in $<.read.scan(/(\\S+) (\\S+)/)\n t = h[name] = (h[name]||0)+score.to_i\n hh[t] = name unless hh[t]\nend\nputs hh[h.map(&:last).max]"}, {"source_code": "log = []\nscores = Hash.new(0)\ncheck = Hash.new(0)\ngets.to_i.times{\n n,q=gets.split\n scores[n]+=q.to_i\n log << [q,n]\n}\nm = scores.values.max\nlog.each{|q,n|\n check[n] += q.to_i\n if check[n] >= m and scores[n] == q.to_i then\n puts n\n exit\n end\n}\n"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\n\nscore_map = {}\nat_index_by_name = {}\n1.upto(lines) do |i|\n name, score = gets.split\n score = score.to_i\n\n score_map[name] ||= 0\n score_map[name] += score\n\n at_index_by_name[name] ||= {\n score: -99_999_999,\n index: 9_999_999\n }\n\n next unless at_index_by_name[name][:score] < score_map[name]\n\n at_index_by_name[name] = {\n score: score_map[name],\n index: i\n }\nend\n\nscores = score_map.to_a.sort_by(&:last)\nputs(\n scores\n .select { |score| scores.last.last == score.last }\n .min_by { |score| at_index_by_name[score.first][:index] }\n .first\n)\n"}, {"source_code": "#!/usr/bin/env ruby\n\n$global_hash = Hash.new\n$max_score = 0\n$leader = \"\"\n\nif ($global_hash.has_key? \"key\")\n\t$global_hash[\"key\"] += 2\nelse\n\t$global_hash[\"key\"] = 2\nend\n\ndef process_score(score_string)\n\tparts = score_string.split(' ')\n\tkey = parts[0]\n\tvalue = parts[1].to_i\n\n\tif ($global_hash.has_key? key)\n\t\t$global_hash[key] += value\n\telse\n\t\t$global_hash[key] = value\n\tend\n\n\tif ($global_hash[key] > $max_score)\n\t\t$max_score = $global_hash[key]\n\t\t$leader = key\n\tend\nend\n\n#results for testing\n# match_results = []\n# match_results << \"andrew 3\"\n# match_results << \"andrew 2\"\n# match_results << \"mike 5\"\n\nrepeats = gets.to_i\nmatch_results = []\n\nwhile (repeats > 0)\n\tmatch_results << gets.strip\n\trepeats -= 1\nend\n\nfor score_string in match_results\n\tprocess_score(score_string)\nend\n\nputs $leader"}, {"source_code": "scores = {}\nhistory = {}\ngets.to_i.times do |i|\n name, score = gets.split\n score = score.to_i\n history[i] = [name, score]\n if scores.has_key? name\n scores[name] = scores[name]+score\n else\n scores[name] = score\n end\nend\n\nscores = scores.to_a.sort_by! { |key, value| -value }\nm = scores[0][1]\nscores = {}\n#puts m\nhistory.each do |k,v|\n name = v[0]\n score = v[1]\n if scores.has_key? name\n scores[name] = scores[name]+score\n else\n scores[name] = score\n end\n #puts \"#{scores.inspect} #{scores[name]}\"\n if scores[name] >=m\n puts name\n break\n end\nend"}, {"source_code": "players = {}\ngets.to_i.times do |i|\n name, point = gets.chomp.split\n players[name] ||= {:point => 0, :max => nil, :max_at => nil}\n players[name][:point] += point.to_i\n if players[name][:max].nil? || players[name][:point] > players[name][:max]\n players[name][:max] = players[name][:max]\n players[name][:max_at] = i\n end\nend\nputs players.sort{|a, b| (b[1][:max] <=> a[1][:max]).nonzero? || a[1][:max_at] <=> b[1][:max_at]}[0][0]\n"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\n\nscore_map = {}\nat_index_by_name = {}\n1.upto(lines) do |i|\n name, score = gets.split\n score = score.to_i\n\n score_map[name] ||= 0\n score_map[name] += score\n\n at_index_by_name[name] ||= {}\n\n next if at_index_by_name[name][score_map[name]]\n\n at_index_by_name[name][score_map[name]] = i\nend\n\nscores = score_map.to_a.sort_by(&:last)\nputs(\n scores\n .select { |score| scores.last.last == score.last }\n .min_by { |score| at_index_by_name[score.first][score.last] }\n .first\n)\n"}, {"source_code": "A={}\nb={}\nl=[]\ngets.to_i.times{\n q,w=gets.split;\n A[q]=A[q].to_i+w.to_i;\n b[q]=b[q].to_i+w.to_i;\n l+=[[q,w]]\n \n \n}\nm=A.values.max\nl.each{|q,w|\n\nif b[q]>=m and A[q]=m then\n puts q\n exit\nend\n}"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nh = {}\nst = []\nn.times {\n name, score = gets.split\n score = score.to_i\n h[name] ||= 0\n h[name] += score\n st << [name, score]\n}\nmax = h.values.max\ncands = []\nfor k,v in h\n if v == max\n cands << k\n end\nend\nif cands.length == 1\n puts cands[0]\nelse\n h2 = {}\n for s in st\n h2[s[0]] ||= 0\n h2[s[0]] += s[1]\n if h2[s[0]] == max\n puts s[0]\n break\n end\n end\nend"}, {"source_code": "num_lines = gets().chomp.to_i\nplayers_info = {}\nnum_lines.times{\n |i|\n name, score = gets().chomp.split(/[ ]+/)\n score = score.to_i\n if(players_info.has_key?(name)) then\n if(score != 0) then\n players_info[name][0] += score\n players_info[name][1] = i\n end\n else\n players_info[name] = []\n players_info[name][0] = score\n players_info[name][1] = i\n end\n}\n\nputs players_info.to_a.sort {\n |a,b|\n (((b[1][0] <=> a[1][0]) * 3 + (a[1][1] <=> b[1][1])) <=> 0)\n}[0][0]\n"}, {"source_code": "A={}\nb={}\nl=[]\ngets.to_i.times{\n q,w=gets.split;\n A[q]=A[q].to_i+w.to_i;\n b[q]=b[q].to_i+w.to_i;\n l+=[[q,w]]\n \n \n}\nm=A.values.max\nl.each{|q,w|\n\nif b[q]>=m and A[q]=m then\n puts q\n exit\nend\n}"}, {"source_code": "h = {}\nn = gets.to_i\nl = []\nn.times { |i|\n a, b = gets.split\n l << [a,b]\n if h.key? a\n h[a] += b.to_i\n else\n h[a] = b.to_i\n end\n}\n\nmax = -1000 * n - 1\nh.each do |a, b|\n if b > max\n max = b\n end\nend\n\nh.clear\n\nn.times { |i|\n\n a, b = l[i]\n\n if h.key? a\n h[a] += b.to_i\n else\n h[a] = b.to_i\n end\n\n if h[a] >= max\n print a\n exit(0)\n end\n\n}\n\n"}, {"source_code": "num_lines = gets().chomp.to_i\ntop_score = 0\nscores = {}\nscores_fset ={}\n\naddscore = -> (fn, maxscore, index) do\n (-> (score) {\n prev = fn.call(score)\n return prev if prev\n return index if score <= maxscore\n return -1 \n })\nend\n\nnum_lines.times do |index|\n line = gets().chomp\n name, score = line.split\n score = score.to_i\n scores[name] ||= 0\n scores[name] += score\n\n scores_fset[name] ||= -> (x) do\n (-> () {\n return index if x <= score\n return -1\n }).call()\n end\n\n if scores_fset[name].call(scores[name]) == -1\n scores_fset[name] = addscore.call(scores_fset[name], scores[name], index)\n end\n\n top_score = scores[name] if scores[name] > top_score\nend\n\ntop_scorers = scores.select {|k, v| v == scores.values.max}\nputs top_scorers.min_by {|k, v| scores_fset[k].call(top_score)}[0]\n"}, {"source_code": "steps = gets.chomp.to_i\n\nwinner = nil\ncompetitors = {}\n\nsteps.times do\n step_result = gets.chomp.split\n step_winner = step_result[0]\n step_winner_score = step_result[1].to_i\n winner ||= step_winner\n competitors[step_winner] ||= 0\n competitors[step_winner] += step_winner_score\n winner = step_winner if competitors[winner] < competitors[step_winner]\nend\n\nputs winner\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nh = {}\nst = []\nn.times {\n name, score = gets.split\n score = score.to_i\n h[name] ||= 0\n h[name] += score\n st << [name, score]\n}\nmax = h.values.max\ncands = []\nfor k,v in h\n if v == max\n cands << k\n end\nend\nif cands.length == 1\n puts cands[0]\nelse\n h2 = {}\n for s in st\n h2[s[0]] ||= 0\n h2[s[0]] += s[1]\n if h2[s[0]] >= max\n puts s[0]\n break\n end\n end\nend"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\n\nscore_map = {}\nat_index_by_name = {}\n1.upto(lines) do |i|\n name, score = gets.split\n score = score.to_i\n\n score_map[name] ||= 0\n score_map[name] += score\n\n at_index_by_name[name] ||= {\n score: -99_999_999,\n index: 9_999_999\n }\n\n next unless at_index_by_name[name][:score] < score_map[name]\n\n at_index_by_name[name] = {\n score: score_map[name],\n index: i\n }\nend\n\nscores = score_map.to_a.sort_by(&:last).reverse\nputs(\n scores\n .select { |score| scores.last.last == score.last }\n .min_by { |score| at_index_by_name[score.first][:index] }\n .first\n)\n"}, {"source_code": "n=gets.chomp.to_i\n\nnames=[]\nvalues=[]\n\na=0\nwhile amaxvalue\n\t\t\t\t\tmaxvalue=sortvalues[k]\n\t\t\t\t\tmax=k\n\t\t\t\tend\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\n\t\tif !flag\n\t\t\tsortnames.push(names[i])\n\t\t\tsortvalues.push(values[i])\n\t\t\tif values[i]>maxvalue\n\t\t\t\tmaxvalue=values[i]\n\t\t\t\tmax=sortnames.length-1\n\t\t\tend\n\t\tend\n\tend\nend\n\nputs sortnames[max]"}, {"source_code": "n=gets.chomp!.to_i\nmemo=Hash.new\nscore=[]\nn.times do\n score << gets.chomp\nend\nn.times do |j|\n tmp=score[j].split\n if memo.key?(tmp[0])\n memo[tmp[0]]+=tmp[1].to_i\n else\n memo[tmp[0]]=tmp[1].to_i\n end\nend\nmax=memo.values.max\nmemo.clear()\nn.times do |j|\n tmp=score[j].split\n if memo.key?(tmp[0])\n memo[tmp[0]]+=tmp[1].to_i\n else\n memo[tmp[0]]=tmp[1].to_i\n end\n if memo[tmp[0]]==max\n puts tmp[0]\n break\n end\nend\n"}, {"source_code": "s = Hash.new(0)\nt = {}\ngets.to_i.times do |i|\n name, score = gets.split\n s[name] += score.to_i\n t[name] = i\nend\n\nmin = s.values.min\nputs t.select { |k, v| s[k] == min }.min_by {|k, v| v}.first"}, {"source_code": "n = gets.to_i\nans = Hash.new\nfor i in 0...n do\n name, point = gets.split\n name = name.to_sym\n point = point.to_i\n\n if ans[name].nil?\n ans[name] = point, i \n else\n ans[name][0] = ans[name][0] + point\n end\n\n ans[name][1] = i\nend\n\nans = ans.to_a\nans.sort! { |a, b| b[1][0] <=> a[1][0] }\n\ni = 0\nn = ans.size - 1\nfinal = ans[0]\nfinal_next = final\n\nwhile i < n && final_next[1][0] == final[1][0]\n if final_next[1][1] < final[1][1]\n final = final_next\n final_next = ans[i + 1]\n else\n final_next = ans[i + 1]\n end\n i = i + 1\nend\n\nif final_next[1][1] < final[1][1] && final_next[1][0] == final[1][0]\n final = final_next\nend\n\np final[0].to_s"}, {"source_code": "n = gets.to_i\nh = Hash.new\nnames = []\nscores = []\n\nfor i in 0...n\n\n s, k = gets.chomp.split\n k = k.to_i\n\n if h[s].nil?\n h[s] = 0\n end\n\n h[s] += k\n\n names.push(s)\n scores.push(k)\nend\n\nmax = h.values.max\nh.clear\n\nfor i in 0...n\n if h[names[i]].nil?\n h[names[i]] = 0\n end\n h[names[i]] += scores[i]\n if h[names[i]] >= max\n puts names[i]\n exit\n end\nend\n"}, {"source_code": "n=gets.chomp.to_i\nnc=0 \n@hash={}\n@hash_total={}\nloop do\t\n\tbreak if nc == n\n\tinput=gets.chomp.split(\" \")\n\tk=0\n\tif nc >= 1\n\t\t@hash.each_key do |plr_nm|\n\t\t\tif plr_nm!=input[0]\n\t\t\t\tk+=1\n\t\t\tend\n\t\tend\n\t\tif k==@hash.length\n\t\t\t@hash[input [0]]=[input[1].to_i]\n\t\telse\n\t\t@hash[input [0]]=@hash[input [0]]+[input[1].to_i]\n\t\tend\n\telse\n\t\t@hash[input [0]]=[input[1].to_i]\n\tend\n\n\tnc+=1\nend\ndef Total(key,array)\n k=0\n\tarray.each do|l|\n\t k=k+l\n\tend\n @hash_total[key]=k\nend\n@hash.each_pair do|a,b|\n\tTotal(a,b)\nend\n\ndef Tiebreaker(a,b)\n ka=0\n ba=0\n k=0\n @hash[a[0]].each do|cn|\n\t\tk=k+cn\n\t\tka+=1\n\t\tbreak if k >= a[1]\n\tend\t\n\tk=0\t\t\n @hash[b[0]].each do|cn|\n\t\tk=k+cn\n\t\tba+=1\n\t\tbreak if k >= b[1]\n\tend\t\n\tif ka>ba\n\t\treturn b\n\telse \n\t\treturn a\n\tend\t\nend\t\n\t\t\t\n \n\n\n\nwin= @hash_total.inject do |memo,n|\n if memo[1]>n[1]\n\tmemo\n elsif memo[1]=n[1]\n Tiebreaker(memo,n)\n else \n\tn\nend\t\nend\nputs win[0]\n"}, {"source_code": "s = Hash.new(0)\nt = {}\ngets.to_i.times do |i|\n name, score = gets.split\n s[name] += score.to_i\n t[name] = i\nend\n\nmin = s.values.min\nputs t.select { |k, v| s[k] == min }.min_by {|k, v| v}.first"}], "src_uid": "c9e9b82185481951911db3af72fd04e7"} {"source_code": "gets.to_i.times{\r\n gets\r\n s=gets.chars.map{|x|x.ord-97}\r\n p s.max+1\r\n}", "positive_code": [{"source_code": "main = -> {\n n = gets.to_i\n s = gets.chomp.chars\n s.max.ord - 'a'.ord + 1\n}\n\nt = gets.to_i\nputs t.times.map{ main.call }.join(\"\\n\")\n"}, {"source_code": "gets.to_i.times {\n gets\n s=gets.chars.map(&:ord)\n puts s.max.to_i-96\n}"}, {"source_code": "=begin\n\nWelcome to GDB Online.\nGDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,\nC#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.\nCode, Compile, Run and Debug online from anywhere in world.\n\n=end\n\nt=gets.to_i\nfor i in 1..t\n n =gets.to_i\n p gets.chars.map{|x|x.ord}.max-\"a\".ord+1\n\nend\n"}], "negative_code": [], "src_uid": "4841cbc3d3ef29929690b78e30fbf22e"} {"source_code": "t=gets.chomp.to_i\r\nt.times do\r\n s= gets.chomp.split\r\n x=s[0].to_i\r\n y=s[1].to_i\r\n if (y % x ==0)\r\n puts \"#{1} #{y/x}\"\r\n else \r\n puts \"#{0} #{0}\"\r\n end\r\nend\r\n", "positive_code": [{"source_code": "def try(i, y)\n cnt = 0\n while y % i == 0\n cnt += 1\n y /= i\n end\n\n return nil unless y == 1\n cnt\nend\n\ngets.to_i.times do\n x, y = gets.split.map(&:to_i)\n\n if y % x != 0\n puts '0 0'\n next\n end\n\n y /= x\n\n if y == 1\n puts '1 1'\n next\n end\n\n i = 2\n found = false\n while i <= y\n j = try(i, y)\n if j\n puts \"#{j} #{i}\"\n found = true\n break\n end\n\n i += 1\n end\n\n next if found\n puts '0 0'\nend\n"}, {"source_code": "pow = (1..10).flat_map do |a|\r\n (1..100).map do |b|\r\n [b ** a, [a, b]]\r\n end\r\nend.to_h\r\n\r\ngets.to_i.times do\r\n x, y = gets.split.map(&:to_i)\r\n if y >= x && y % x == 0 && pow[y / x]\r\n puts pow[y / x].join(\" \")\r\n else\r\n puts \"0 0\"\r\n end\r\nend\r\n"}, {"source_code": "for t in 1..gets.to_i do\r\n\ta=gets.split\r\n\ta[0]=a[0].to_i\r\n\ta[1]=a[1].to_i\r\n\tc=a[0]\r\n\td=a[1]\r\n\r\n\tif d%c==0\r\n\t\tprint 1,' ',d.div(c),\"\\n\"\r\n\telse\r\n\t\tprint 0,' ',0,\"\\n\"\r\n\tend\r\nend"}], "negative_code": [{"source_code": "def try(i, y)\n cnt = 0\n while y % i == 0\n cnt += 1\n y /= i\n end\n\n return nil unless y == 1\n cnt\nend\n\ngets.to_i.times do\n x, y = gets.split.map(&:to_i)\n\n if y % x != 0\n puts '0 0'\n next\n end\n\n y /= x\n\n if y == 1\n puts '1 1'\n next\n end\n\n i = 2\n found = false\n while i * i <= y\n j = try(i, y)\n if j\n puts \"#{j} #{i}\"\n found = true\n break\n end\n\n i += 1\n end\n\n next if found\n puts '0 0'\nend\n"}, {"source_code": "pow = (1..10).flat_map do |a|\r\n (1..10).map do |b|\r\n [b ** a, [a, b]]\r\n end\r\nend.to_h\r\n\r\ngets.to_i.times do\r\n x, y = gets.split.map(&:to_i)\r\n if y >= x && y % x == 0 && pow[y / x]\r\n puts pow[y / x].join(\" \")\r\n else\r\n puts \"0 0\"\r\n end\r\nend\r\n"}], "src_uid": "f7defb09175c842de490aa13a4f5a0c9"} {"source_code": "#!/usr/bin/ruby\np$<.drop(1).group_by{|e|e}.map{|k,v|v.size}.max\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\narr = Hash.new{0}\nn.times do\narr[gets.chomp]+=1\nend\nmax = 0\narr.each do |key,value|\n\tif value > max\n\tmax = value\n\tend\nend \nprint max\n\n=begin\n4\n0101\n1000\n1111\n0101\n\n3\n111\n111\n111\n=end\n"}, {"source_code": "#!/usr/bin/ruby\np$<.drop(1).group_by{|e|e}.map{|k,v|v.size}.max"}, {"source_code": "def function\nb=gets.chomp.to_i\nstring_array=[]\nb.times do |i|\na=gets.chomp\nstring_array.push(a)\nend\ncount_array=[]\n0.upto string_array.length-1 do |i|\ncount_array.push(string_array.count(string_array[i]))\nend\nputs count_array.max\nend\nfunction\n"}, {"source_code": "rows = gets.to_i\nrow_hash = {}\n(rows).times do \n row_val = gets\n if row_hash.include?(row_val)\n row_hash[row_val]+=1\n else\n row_hash[row_val] = 1\n end\nend\nputs (row_hash.max_by{|k, v| v}).last\n"}, {"source_code": "#!/usr/bin/ruby\np$<.drop(1).group_by{|e|e}.map{|k,v|v.size}.max\n"}, {"source_code": "#!/usr/bin/ruby\np$<.drop(1).group_by{|e|e}.map{|k,v|v.size}.max\n"}, {"source_code": "$pair = {}\n\ndef sweep(arr, row)\n\t\tstr = arr[row] * \"\"\n\t\tif $pair.has_key?(str)\n\t\t\t$pair[str] += 1\n\t\telse\n\t\t\t$pair[str] = 1\n\t\tend\nend\n\n=begin\ndef count(arr, col)\n\tl = 0\n\t(0...arr[0].length).each do |iterNum|\n\t\tl += 1 if arr[iterNum][0] == 0\n\tend\n\n\tl\nend\n\ndef cleanCount(arr)\n\tl = 0\n\n\t(0...arr[0].length).each do |iterNum|\n\t\tstr = arr[iterNum] * \"\"\n\t\tl += 1 if str == (\"1\" * arr[0].length)\n\tend\n\n\tl\nend\n=end\n\nn = gets.chomp.to_i\nroom = []\ncountArr = []\n\n(0...n).each do |iter|\n\troom << (gets.chomp.split('').map {|item| item.to_i})\nend\n\n(0...n).each do |iter|\n\tcountArr << sweep(room, iter)\n\t#print $pair\n\t#puts ''\nend\n\nmax = 0\n$pair.each_value do |val|\n\tmax = val if max < val\nend\n\nputs max"}, {"source_code": "#!/usr/bin/ruby\np$<.drop(1).group_by{|e|e}.map{|k,v|v.size}.max"}, {"source_code": "#!/usr/bin/ruby\np$<.drop(1).group_by{|e|e}.map{|k,v|v.size}.max\n"}, {"source_code": "#!/usr/bin/ruby\np$<.drop(1).group_by{|e|e}.map{|k,v|v.size}.max\n"}, {"source_code": "n = gets.to_i\ns = {}\nn.times do |i|\n r = gets.chomp\n s[r] ||= 0\n s[r] += 1\nend\n\nputs s.values.max"}, {"source_code": "n,h = gets.to_i,{}\n(1..n).each{\n r = gets.strip\n h[r] ||= 0\n h[r] += 1 \n}\np h.values.max"}, {"source_code": "#!/usr/bin/ruby\np$<.drop(1).group_by{|e|e}.map{|k,v|v.size}.max\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.chomp}\np a.uniq.reduce(0){|mx, x| mx = [mx, a.count(x)].max}\n"}, {"source_code": "#!/usr/bin/ruby\np$<.drop(1).group_by{|e|e}.map{|k,v|v.size}.max\n"}, {"source_code": "\nn = gets().chomp().to_i\nb = []\n\nn.times{\n b.push(gets().chomp())\n}\n\nc=b.sort{|x,y| x <=> y}\n\nstr=c[0]\nmax = 1\ntemp =1\nfor i in (1..c.length-1)\n if c[i]==str\n temp+=1\n\n else\n str=c[i]\n if temp > max\n max = temp\n end\n temp=1\n end\n\nend\n\nif temp > max\n max = temp\nend\n\nputs max\n\n"}, {"source_code": "#!/usr/bin/ruby\np$<.drop(1).group_by{|e|e}.map{|k,v|v.size}.max\n"}], "negative_code": [{"source_code": "\nn = gets().chomp().to_i\nb = []\n\nn.times{\n s = gets().chomp().split('')\n a = []\n for i in (0..n-1)\n if s[i]=='0'\n a.push(\"#{i+1}\")\n end\n end\n if a.length()==0\n a.push(\"0\")\n end\n b.push(a.join(''))\n}\n\nc=b.sort{|x,y| x.length <=> y.length}\n\nstr=c[0]\nmax = 1\ntemp =1\nfor i in (1..c.length-1)\n if c[i]==str\n temp+=1\n\n else\n str=c[i]\n if temp > max\n max = temp\n end\n temp=1\n end\n\nend\n\nputs max\n\n"}], "src_uid": "f48ddaf1e1db5073d74a2aa318b46704"} {"source_code": "def gcd(a, b)\n if b == 0\n return a\n else\n return gcd(b, a % b)\n end\nend\n\nn = readline.to_i\narr = readline.split(' ').collect(&:to_i)\nct = 0\nres = []\n0.upto(arr.length - 2) do |ind|\n a, b = arr[ind], arr[ind + 1]\n res += [a]\n if gcd(a, b) != 1\n ct += 1\n res += [1]\n end\nend\nres += [arr.last]\nputs ct\nres.each_with_index do |n, i|\n if i != 0\n print \" \"\n end\n print n\nend\nputs \"\"\n", "positive_code": [{"source_code": "gets;a=gets.split.map(&:to_i);b=[a[0],*a.each_cons(2).flat_map{|x,y|x.gcd(y)==1 ? [y] : [1,y]}];p b.size-a.size;puts b*' '"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").map{|i| i.to_i}\nans=[]\np=0\n0.upto(a-2) do |i|\n if b[i].gcd(b[i+1])!=1\n ans << b[i]\n ans << 1\n p+=1\n else\n ans << b[i]\n end\nend\nans << b[a-1]\nputs \"#{p}\"\nputs ans.join(\" \")"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").map{|i| i.to_i}\nans=[]\np=0\n0.upto(a-2) do |i|\n if b[i].gcd(b[i+1])!=1\n ans << b[i]\n ans << 1\n p+=1\n else\n ans << b[i]\n end\nend\nans << b[a-1]\nputs \"#{p}\"\nputs ans.join(\" \")"}, {"source_code": "def gcd(a,b)\n\treturn b>0 ? gcd(b,a%b) : a\nend\n\nn=gets.to_i\na=gets.split(' ')\ns=0\nfor i in 1..a.size-1 \n\ts+=1 if gcd(a[i].to_i,a[i-1].to_i)>1\nend\nputs s\nprint a[0]\nfor i in 1..a.size-1 \n\tprint \" 1\" if gcd(a[i].to_i,a[i-1].to_i)>1\n\tprint \" \"+a[i]\nend\nputs"}, {"source_code": "gets;a=gets.split.map(&:to_i);b=[a[0],*a.each_cons(2).flat_map{|x,y|x.gcd(y)==1 ? [y] : [1,y]}];p b.size-a.size;puts b*' '\n"}], "negative_code": [{"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").map{|i| i.to_i}\nans=[]\n0.upto(a-2) do |i|\n if b[i].gcd(b[i+1])!=1\n ans << b[i]\n ans << 1\n else\n ans << b[i]\n end\nend\nans << b[a-1]\nputs ans.join(\" \")"}, {"source_code": "def gcd(a,b)\n\treturn b>0 ? gcd(b,a%b) : a\nend\n\nn=gets.to_i\na=gets.split(' ')\nprint a[0]\nfor i in 1..a.size-1 \n\tprint \" 1\" if gcd(a[i].to_i,a[i-1].to_i)>1\n\tprint \" \"+a[i]\nend\nputs"}], "src_uid": "b0b4cadc46f9fd056bf7dc36d1cf51f2"} {"source_code": "c = Hash.new(0)\n\nn = gets.to_i\n\nmax = -1\n\ngets.split.map(&:to_i).each do |i|\n\tc[i]+=1\n\tmax = [c[i], max].max\nend\n\ncan = max<=(n/2.0).ceil.to_i\n\nputs can ? 'YES' : 'NO'", "positive_code": [{"source_code": "n=gets.chomp.to_i\nn=(n+1)>>1\na=gets.chomp.split\nfor i in a do\n\tif a.count(i)>n\n\t\tputs \"NO\"\n\t\texit\n\tend\nend\nputs \"YES\"\n"}, {"source_code": "n = gets.to_i\ncnt = [], maxs = 0\ngets.split(' ').map do |i|\n i = i.to_i\n cnt[i] = cnt[i].nil? ? 1 : cnt[i] + 1\n maxs = [cnt[i], maxs].max\nend\nif maxs > (n + 1) / 2 && n > 1 then puts \"NO\"\nelse puts \"YES\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |i| i.to_i }\ncnt = []\nmaxs = 0\na.each do |i|\n cnt[i] = 0 if cnt[i].nil?\n cnt[i] += 1\n maxs = [cnt[i], maxs].max\nend\nif maxs > (n + 1) / 2 && n > 1\n puts \"NO\"\nelse \n puts \"YES\"\nend\n"}, {"source_code": "def run\n n = $stdin.gets.to_i\n a = $stdin.gets.split.map(&:to_i)\n h = Hash.new(0)\n a.each do |item|\n h[item] += 1\n end\n\n h.each do |key, value|\n if (value - 1) * 2 >= n\n puts \"NO\"\n return\n end\n end\n\n puts \"YES\"\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "class A\n def initialize\n n = $stdin.gets.chomp.to_i\n array = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n if array.size == 1\n puts \"YES\"\n exit\n elsif array.size == 2\n if array[0] == array[1]\n puts \"NO\"\n else\n puts \"YES\"\n end\n exit\n end\n\n if array.size.even?\n 1.upto(1000) do |num|\n count = array.count(num)\n\n if(count > array.size/2)\n puts \"NO\"\n exit\n end\n end\n else\n 1.upto(1000) do |num|\n count = array.count(num)\n\n if(count > array.size/2+1)\n puts \"NO\"\n exit\n end\n end\n end\n\n puts \"YES\"\n end\nend\n\na = A.new"}, {"source_code": "n = gets.to_i\na = gets.split #.map{|_|_.to_i}\nh = {}\n\na.each{|i|\n if h[i] then\n h[i]+=1\n else\n h[i]=1\n end\n}\nx = n%2==0 ? n/2 : (n+1)/2\nr = true\nh.each{|k,v|\n r = false if v > x\n}\n\nputs (r ? 'YES':'NO' )\n"}, {"source_code": "n = gets.chomp.to_i\nelements = gets.chomp.split(/ /).map(&:to_i)\nans = \"YES\"\ncnt = Array.new(1001, 0)\nelements.each do |e|\n cnt[e] += 1\nend\nc = 0\ncnt.each do |count|\n c = [count, c].max\nend\nans = \"NO\" if c > (n + 1) / 2\nputs ans\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nif a==1\nputs \"YES\"\nelsif a!=1 && b.uniq.length==1\nputs \"NO\"\n\nelse\n\nk=Hash.new(0)\nb.each do |i|\nk[\"#{i}\"]+=1\nend\nl=k.values.sort.reverse[0]\nif a-l>=l-1\nputs \"YES\"\nelse\nputs \"NO\"\nend\n\n\nend"}, {"source_code": "$n, $a = gets.to_i, gets.split(' ').map { |x| x.to_i }\n$b = []\n$a.group_by{ |x| x }.each_value{ |x| $b << x.length }\n$k = (if $a.length % 2 == 0 then $a.length / 2 else $a.length / 2 + 1 end)\nputs (if $b.any? { |x| x > $k } then \"NO\" else \"YES\" end)"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\ncount = Hash.new(0)\n\narr.each do |a|\n\tcount[a] += 1\nend\n\nans = true\ncount.values.each do |c|\n\tunless c <= (n+1)/2\n\t\tans = false\n\t\tbreak\n\tend\nend\n\nputs ans ? \"YES\" : \"NO\"\n\n# count_arr = count.values.sort.reverse\n# # puts \"#{count_arr}\"\n# (0..count_arr.length-2).each do |i|\n# \tj = i + 1\n# \tputs \"#{count_arr}\"\n# \tnext if count_arr[i] == 0\n# \twhile j <= count_arr.length - 1\n# \t\tif count_arr[i] <= count_arr[j]\n# \t\t\tcount_arr[i] = 0\n# \t\t\tcount_arr[j] -= count_arr[i]\n# \t\t\tbreak\n# \t\telse\n# \t\t\tcount_arr[i] -= count_arr[j]\n# \t\t\tcount_arr[j] = 0\n# \t\tend\n# \t\tj += 1\n# \tend\n# end\n# count_arr.reject!{|a| a == 0}\n# puts \"#{count}\"\n# puts \"#{count_arr}\"\n# if count_arr[0] > 1\n# \tputs \"NO\"\n# else\n# \tputs \"YES\"\n# end"}, {"source_code": "#!/usr/bin/ruby -w\nn = (gets.to_i + 1) >> 1\nx = gets.split;\nx.each do |i|\n if x.count(i) > n\n puts \"NO\"\n exit\n end\nend\nputs \"YES\""}, {"source_code": "\ndef solve\n\th = {}\n\tgets\n\ta = gets.chomp.split(/ /)\n\ta.each do |x| h[x] = if h[x] == nil then 1 else h[x] + 1 end end\n\th.each do |x, y| return 'NO' if y > a.length/2 + a.length%2 end\n\t'YES'\nend\n\nprint solve"}, {"source_code": "def div_ceil(x, y)\n x / y + x % y\nend\n\nn = div_ceil(gets.chomp.to_i, 2)\nputs(gets.chomp.split.map { |x| x.to_i }.inject(Hash.new(0)) { |h, e| h[e] += 1; h }.values.any? { |v| v > n } ? 'NO' : 'YES')"}, {"source_code": "n = gets[0..-2].to_i\narr = gets.split(' ')\na = Array.new(n) { |i| arr[i].to_i }\nmark = Array.new(1001, 0)\nfor i in 0...n do\n mark[a[i]] += 1\nend\n\nmax = mark.max\nif max * 2 - n >= 2\n print \"NO\"\nelse\n print \"YES\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = (gets.to_i + 1) >> 1\nx = gets.split.collect{ |i| i.to_i }\nx.each do |i|\n\tif x.count(i) > n\n\t\tputs \"NO\"\n\t\texit\n\tend\nend\n\nputs \"YES\"\n"}, {"source_code": "at_exit do\n n = get_numbers_from_line[0]\n numbers = get_numbers_from_line[0...n]\n\n iter = 0\n while true\n i = get_incorrect_number_index(numbers)\n if i.nil?\n puts \"YES\"\n break\n else\n unless move_number_to_correct_place(i, numbers)\n puts \"NO\"\n break\n end\n end\n iter += 1\n if iter > 1000\n puts \"NO\"\n break\n end\n end\nend\n\ndef get_incorrect_number_index(numbers)\n (0...numbers.length).each do |i|\n return i if numbers[i] == numbers[i+1] || (i-1 >= 0 && numbers[i] == numbers[i-1])\n end\n nil\nend\n\ndef move_number_to_correct_place(index, numbers)\n number = numbers.delete_at(index)\n (0..numbers.length).each do |i|\n if numbers[i] != number && (i-1 >= 0 && numbers[i-1] != number)\n numbers.insert i, number\n return true\n end\n end\n false\nend\n\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map { |x| x.to_i }\nmax = 0\n1.upto(1000) do |i|\n\tmax = [max, a.count(i)].max\nend\n\nif max <= (n + 1) / 2\n\tputs 'YES'\nelse\n\tputs 'NO'\nend"}], "negative_code": [{"source_code": "c = Hash.new(0)\n\nn = gets.to_i\n\nmax = -1\n\ngets.split.map(&:to_i).each do |i|\n\tc[i]+=1\n\tmax = i if c[i]>max\nend\n\ncan = max<=(n/2.0).ceil\n\nputs can ? 'YES' : 'NO'"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |i| i.to_i }\ncnt = []\nmaxs = 0\na.each do |i|\n\tcnt[i] = 0 if cnt[i].nil?\n\tcnt[i] += 1\n\tmaxs = [cnt[i], maxs].max\nend\nif maxs > n / 2 && n > 1\n\tputs \"NO\"\nelse \n\tputs \"YES\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |i| i.to_i }\ncnt = []\nmaxs = 0\na.each do |i|\n cnt[i] = 0 if cnt[i].nil?\n cnt[i] += 1\n maxs = [cnt[i], maxs].max\nend\nif maxs > n / 2 && n > 1\n puts \"NO\"\nelse \n puts \"YES\"\nend\n"}, {"source_code": "n = gets.to_i\ncnt = [], maxs = 0\ngets.split(' ').map do |i|\n i = i.to_i\n cnt[i] = cnt[i].nil? ? 0 : cnt[i] + 1\n maxs = [cnt[i], maxs].max\nend\nif maxs > (n + 1) / 2 && n > 1 then puts \"NO\"\nelse puts \"YES\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split #.map{|_|_.to_i}\nh = {}\n\na.each{|i|\n if h[i] then\n h[i]+=1\n else\n h[i]=1\n end\n}\nx = n%2 ? n/2 : (n+1)/2\nr = true\nh.each{|k,v|\n r = false if v > x\n}\n\nputs (r ? 'YES':'NO' )\n\n\n\n\n"}, {"source_code": "n = gets.to_i\na = gets.split #.map{|_|_.to_i}\nh = {}\n\na.each{|i|\n if h[i] then\n h[i]+=1\n else\n h[i]=0\n end\n}\nx = n%2 ? n/2 : (n+1)/2\nr = true\nh.each{|k,v|\n r = false if v > x\n}\n\nputs (r ? 'YES':'NO' )\n\n\n\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map{|_|_.to_i}\n\nr = true\n(n-1).times{|i|\n r = true\n if a[i] == a[i+1] then\n b = a\n t = b[i+1]\n b[i+1] = b[i]\n b[i] = t\n (n-1).times{|j|\n r = false if b[j] == b[j+1]\n }\n end\n}\n\nputs (r ? 'YES':'NO' )\n\n\n\n\n"}, {"source_code": "def distinct?( elements )\n (1...elements.length).each do |i|\n return false if elements[i - 1] == elements[i]\n end\n true\nend\nn = gets.chomp.to_i\nelements = gets.chomp.split(/ /).map(&:to_i)\nans = \"YES\"\n(1...n).each do |i|\n elements[i - 1], elements[i] = elements[i], elements[i - 1] if elements[i - 1] != elements[i]\nend\nans = \"NO\" if !distinct? elements\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\nelements = gets.chomp.split(/ /).map(&:to_i)\nduplicates = []\n(1...n).each do |i|\n duplicates += [i - 1, i] if elements[i - 1] == elements[i]\nend\nduplicates.uniq!\nans = \"YES\"\nans = \"NO\" if duplicates.length > (n + 1) / 2\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\nelements = gets.chomp.split(/ /).map(&:to_i)\nduplicates = []\n(1...n).each do |i|\n duplicates += [i - 1, i] if elements[i - 1] == elements[i]\nend\nans = \"YES\"\nans = \"NO\" if duplicates.length > (n + 1) / 2\nputs ans\n"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\ncount = Hash.new(0)\n\narr.each do |a|\n\tcount[a] += 1\nend\n\ncount_arr = count.values.sort.reverse\n(0..count_arr.length-2).each do |i|\n\tj = i + 1\n\twhile j <= count_arr.length - 1\n\t\tif count_arr[i] <= count_arr[j]\n\t\t\tcount_arr[i] = 0\n\t\t\tcount_arr[j] -= count_arr[i]\n\t\t\tbreak\n\t\telse\n\t\t\tcount_arr[i] -= count_arr[j]\n\t\t\tcount_arr[j] = 0\n\t\tend\n\t\tj += 1\n\tend\nend\ncount_arr.reject!{|a| a == 0}\n# puts \"#{count_arr}\"\nif count_arr[0] > 1\n\tputs \"NO\"\nelse\n\tputs \"YES\"\nend"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\ncount = Hash.new(0)\n\narr.each do |a|\n\tcount[a] += 1\nend\n\ncount_arr = count.values\n(0..count_arr.length-2).each do |i|\n\tj = i + 1\n\twhile j <= count_arr.length - 1\n\t\tif count_arr[i] <= count_arr[j]\n\t\t\tcount_arr[i] = 0\n\t\t\tcount_arr[j] -= count_arr[i]\n\t\t\tbreak\n\t\telse\n\t\t\tcount_arr[i] -= count_arr[j]\n\t\t\tcount_arr[j] = 0\n\t\tend\n\t\tj += 1\n\tend\nend\ncount_arr.reject!{|a| a == 0}\nif count_arr[0] > 1\n\tputs \"NO\"\nelse\n\tputs \"YES\"\nend"}, {"source_code": "\ndef solve\n\th = {}\n\tgets\n\ta = gets.chomp.split(/ /)\n\ta.each do |x| h[x] = if h[x] == nil then 1 else h[x] + 1 end end\n\th.each do |x, y| return 'NO' if y > a.length/2 + a.length%2 end\n\t'YES'\nend\n\np solve"}, {"source_code": "n = gets[0..-2].to_i\narr = gets.split(' ')\na = Array.new(n) { |i| arr[i].to_i }\nmark = Array.new(1001, 0)\nans = true\nfor i in 0...n do\n mark[a[i]] += 1\n if mark[a[i]] > n / 2\n ans = false\n break\n end\nend\n\nmax = mark.max\nif max * 2 - n >= 2\n print \"NO\"\nelse\n print \"YES\"\nend\n"}], "src_uid": "2c58d94f37a9dd5fb09fd69fc7788f0d"} {"source_code": "gets.to_i.times do\n d, h, n = gets.split.map &:to_i\n a = gets.split.map(&:to_i).zip(gets.split.map(&:to_i)).sort{ |a, b|\n a[0] <=> b[0]\n }\n catch :no do\n i = 0\n while i < n\n h -= (a[i][1] + d - 1)/d*a[i][0]\n if h <= 0 && (i < n - 1 || h <= -a[i][0])\n puts \"NO\"\n throw :no\n end\n i += 1\n end\n puts \"YES\"\n end\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n aa,bb,n=gets.split.map(&:to_i)\r\n a=gets.split.map(&:to_i)\r\n b=gets.split.map(&:to_i)\r\n bb+=a.max\r\n n.times do |i|\r\n bb-=a[i]*((b[i]-1)/aa+1)\r\n if bb<=0\r\n break\r\n end\r\n end\r\n if bb<=0\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "b63a6369023642a8e7e8f449d7d4b73f"} {"source_code": "require 'set'; require 'prime'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\na.each do |e|\n ee = e % 14\n ee += 14\n if e > 14 && 15 <= ee && ee <= 20\n puts 'YES'\n else\n puts 'NO'\n end\nend\n", "positive_code": [{"source_code": "require 'set'; require 'prime'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\na.each do |e|\n ee = e % 14\n ee += 14\n if e > 14 && 15 <= ee && ee <= 20\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}], "negative_code": [{"source_code": "require 'set'; require 'prime'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\na.each do |e|\n ee = e % 14\n ee += 14\n if e <= 14 || (15 <= ee && ee <= 20)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "require 'set'; require 'prime'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\na.each do |e|\n e = e % 14\n e += 14\n if 15 <= e && e <= 20\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}], "src_uid": "840a4e16454290471faa5a27a3c795d9"} {"source_code": "\nn = gets.to_i\n\nn.times do |r|\n string = gets.chomp\n freq = Array.new(26, 0)\n\n string_size = string.size\n\n string_size.times do |i|\n freq[string[i].ord - \"a\".ord] += 1\n end\n\n chain_count = 0\n in_chain = false\n printed = false\n freq.each do |value|\n if value > 1\n puts 'No'\n printed = true\n break\n end\n if value == 1\n if !in_chain\n chain_count += 1\n in_chain = true\n end\n if chain_count >= 2\n puts 'No'\n printed = true\n break\n end\n end\n if value == 0\n if in_chain\n in_chain = false\n end\n end\n end\n if !printed && chain_count <= 1\n puts 'Yes'\n end\nend\n", "positive_code": [{"source_code": "require 'set'\nalph = \"abcdefghijklmnopqrstuvwxyz\"\nt = gets.chomp.to_i\nt.times do |testcase|\n inp = gets.chomp\n s = []\n inp.size.times do |i|\n s.push(inp[i])\n end\n s = s.sort\n flag = true\n (inp.size-1).times do |i|\n if alph.index(s[i]) != alph.index(s[i+1])-1\n flag = false\n break\n end\n end\n if flag\n puts \"yES\"\n else\n puts \"nO\"\n end\nend"}, {"source_code": "n = gets.to_i\nn.times do\n ss = gets.chomp.chars.map(&:ord).sort\n unless ss.size == ss.uniq.size\n puts 'No'\n next\n end\n\n ans = 'Yes'\n (0..ss.size-2).each do |i|\n if ss[i] + 1 != ss[i+1]\n ans = 'No'\n end\n end\n puts ans\nend\n"}, {"source_code": "t = \"abcdefghijklmnopqrstuvwxyz\".split(\"\")\ngets.to_i.times do\n s = gets.chomp.split(\"\").sort\n n = s.size\n f = false\n (n-1).times do |i|\n if s[i] == s[i+1]\n puts \"No\"\n f = true\n break\n end\n end\n next if f\n (27-n).times do |i|\n if s == t[i,n]\n puts \"Yes\"\n f = true\n break\n end\n end\n next if f\n puts \"No\"\nend"}, {"source_code": "alphabet = \"abcdefghijklmnopqrstuvwxyz\"\nt = gets.to_i\n\nt.times do\n word = gets.chomp\n puts alphabet.include?(word.chars.sort.join) ? \"Yes\" : \"No\"\nend\n"}, {"source_code": "\nn = gets.strip.to_i\ninputs = []\n\n(1..n).each do |i|\n inputs << gets.strip\nend\n\nres = [\"Yes\"]*n\ninputs.each_with_index do |a, index|\n codes = a.chars.map(&:ord).sort\n (1..codes.size-1).each do |i|\n if codes[i] - codes[i-1] != 1\n res[index] = \"No\" \n break\n end\n \n end\nend\n\nres.each do |r|\n puts r\nend\n"}, {"source_code": "n = gets.to_i\nn.times do\n s = gets.strip.split('').sort.join\n puts s == (s[0]..(2..s.size).inject(s[0]) { |a| a.next }).to_a.join ? 'Yes' : 'No'\nend\n"}], "negative_code": [{"source_code": "\nn = gets.to_i\n\nn.times do |r|\n string = gets.chomp\n freq = Array.new(26, 0)\n\n string_size = string.size\n\n string_size.times do |i|\n freq[string[i].ord - \"a\".ord] += 1\n end\n\n chain_count = 0\n in_chain = false\n printed = false\n freq.each do |value|\n if value > 1\n p 'No'\n printed = true\n break\n end\n if value == 1\n if !in_chain\n chain_count += 1\n in_chain = true\n end\n if chain_count >= 2\n p 'No'\n printed = true\n break\n end\n end\n if value == 0\n if in_chain\n in_chain = false\n end\n end\n end\n if !printed && chain_count <= 1\n puts 'Yes'\n end\nend"}, {"source_code": "\nn = gets.to_i\n\nn.times do |r|\n string = gets.chomp\n freq = Array.new(26, 0)\n\n string_size = string.size\n\n string_size.times do |i|\n freq[string[i].ord - \"a\".ord] += 1\n end\n\n chain_count = 0\n in_chain = false\n printed = false\n freq.each do |value|\n if value > 1\n p \"No\"\n printed = true\n break\n end\n if value == 1\n if !in_chain\n chain_count += 1\n in_chain = true\n end\n if chain_count >= 2\n p \"No\"\n printed = true\n break\n end\n end\n if value == 0\n if in_chain\n in_chain = false\n end\n end\n end\n if !printed && chain_count <= 1\n p \"Yes\"\n end\nend\n"}, {"source_code": "n = gets.to_i\nn.times do\n ss = gets.chomp.chars.map(&:ord).sort\n puts 'No' unless ss.size == ss.uniq.size\n\n ans = 'Yes'\n (0..ss.size-2).each do |i|\n if ss[i] + 1 != ss[i+1]\n ans = 'No'\n end\n end\n puts ans\nend\n"}, {"source_code": "\nn = gets.strip.to_i\ninputs = []\n\n(1..n).each do |i|\n inputs << gets.strip\nend\n\nres = [\"Yes\"]*n\ninputs.each_with_index do |a, index|\n codes = a.chars.map(&:ord).sort\n (1..codes.size-1).each do |i|\n if codes[i] - codes[i-1] != 1\n res[index] = \"No\" \n break\n end\n \n end\nend\n\nres.each do |r|\n p r\nend\n"}], "src_uid": "02a94c136d3fb198025242e91264823b"} {"source_code": "k=gets.split[1].to_i\na=gets.split[0].bytes.to_a\nn=a.length\ncnt=Array.new(10,0)\nn.times{|i|\n a[i]-=48\n cnt[a[i]]+=1\n}\nmincost=99999999\nres=[]\n10.times{|d|\n cost=0\n count=cnt[d]\n 1.upto(9){|i|\n if count>=k then\n break\n end\n if d+i<=9 then\n if cnt[d+i]+count>=k then\n cost+=i*(k-count)\n count=k\n else\n count+=cnt[d+i]\n cost+=cnt[d+i]*i\n end\n end\n if d-i>=0 then\n if cnt[d-i]+count>=k then\n cost+=i*(k-count)\n count=k\n else\n count+=cnt[d-i]\n cost+=cnt[d-i]*i\n end\n end\n }\n if cost=k then\n break\n end\n if used[j]==0 && a[j]==tar then\n ans[j]=d\n count+=1\n used[j]=true\n end\n }\n tar=d-i\n (n-1).downto(0){|j|\n if count>=k then\n break\n end\n if used[j]==0 && a[j]==tar then\n ans[j]=d\n count+=1\n used[j]=true\n end\n }\n }\n n.times{|j|\n if used[j]==0 then\n ans[j]=a[j]\n end\n }\n res.push(ans)\n end\n}\nputs mincost\nans=res.min\nans.each{|i| print i}\nputs", "positive_code": [{"source_code": "k=gets.split[1].to_i\na=gets.split[0].bytes.to_a\nn=a.length\ncnt=Array.new(10,0)\nn.times{|i|\n a[i]-=48\n cnt[a[i]]+=1\n}\nmincost=99999999\nres=[]\n10.times{|d|\n cost=0\n count=cnt[d]\n 1.upto(9){|i|\n if count>=k then\n break\n end\n if d+i<=9 then\n if cnt[d+i]+count>=k then\n cost+=i*(k-count)\n count=k\n else\n count+=cnt[d+i]\n cost+=cnt[d+i]*i\n end\n end\n if d-i>=0 then\n if cnt[d-i]+count>=k then\n cost+=i*(k-count)\n count=k\n else\n count+=cnt[d-i]\n cost+=cnt[d-i]*i\n end\n end\n }\n if cost=k then\n break\n end\n if used[j]==0 && a[j]==tar then\n ans[j]=d\n count+=1\n used[j]=true\n end\n }\n tar=d-i\n (n-1).downto(0){|j|\n if count>=k then\n break\n end\n if used[j]==0 && a[j]==tar then\n ans[j]=d\n count+=1\n used[j]=true\n end\n }\n }\n n.times{|j|\n if used[j]==0 then\n ans[j]=a[j]\n end\n }\n res.push(ans)\n end\n}\nputs mincost\nans=res.min\nans.each{|i| print i}\nputs"}], "negative_code": [], "src_uid": "cb082cbe9b34a45da851b6764bbc30c3"} {"source_code": "a=gets.chomp\nb=gets.chomp\nahash=Hash.new(0)\nbhash=Hash.new(0)\na.each_char {|i| ahash[i]+=1}\nb.each_char {|i| bhash[i]+=1}\nc=ahash.keys\nyay=0\nwhoops=0\n\nc.each do |i|\nif ahash[i]<=bhash[i]\nyay+=ahash[i]\nbhash[i]-=ahash[i]\nahash[i]=0\nelse\nyay+=bhash[i]\nahash[i]-=bhash[i]\nbhash[i]=0\nend\nend\n\nc.each do |i|\nif ahash[i]>0\n\n\nif i==i.downcase\nk=bhash[i.upcase]\nif ahash[i]>=k\nwhoops+=k\nbhash[i.upcase]=0\nelse\nwhoops+=ahash[i]\nbhash[i.upcase]-=ahash[i]\nend\nelse\nk=bhash[i.downcase]\nif ahash[i]>=k\nwhoops+=k\nbhash[i.downcase]=0\nelse\nwhoops+=ahash[i]\nbhash[i.downcase]-=ahash[i]\nend\nend\n\n\nend\nend\n\n\nputs \"#{yay} #{whoops}\"", "positive_code": [{"source_code": "#!/usr/bin/env ruby\nh=$<.map{|e|\n\ts=e.chomp\n\t[s,s.upcase].map{|f|f.bytes.each_with_object(Hash.new(0)){|e,s|s[e]+=1}}\n}\ny=[]\n[*65..90,*97..122].each{|e|\n\tx=[h[0][0][e],h[1][0][e]].min\n\ty<0\n\n\nif i==i.downcase\nk=bhash[i.upcase]\nif ahash[i]>=k\nwhoops+=k\nbhash[i.upcase]=0\nelse\nwhoops+=ahash[i]\nbhash[i.upcase]-=ahash[i]\nend\nelse\nk=bhash[i.downcase]\nif ahash[i]>=k\nwhoops+=k\nbhash[i.downcase]=0\nelse\nwhoops+=ahash[i]\nbhash[i.downcase]-=ahash[i]\nend\nend\n\n\nend\nend\n\n\nputs \"#{yay} #{whoops}\""}, {"source_code": "s = gets.chomp\nt = gets.chomp\nss = Array.new(256, 0)\ntt = Array.new(256, 0)\ns.each_byte do |x|\n ss[x] += 1\nend\nt.each_byte do |x|\n tt[x] += 1\nend\nsu = ss['A'.ord..'Z'.ord]\nsl = ss['a'.ord..'z'.ord]\ntu = tt['A'.ord..'Z'.ord]\ntl = tt['a'.ord..'z'.ord]\n\na = 0\nb = 0\n26.times do |i|\n x = [su[i], tu[i]].min\n a += x\n tu[i] -= x\n su[i] -= x\n x = [sl[i], tl[i]].min\n a += x\n tl[i] -= x\n sl[i] -= x\nend\n26.times do |i|\n x = [su[i], tl[i]].min\n b += x\n tl[i] -= x\n su[i] -= x\n x = [sl[i], tu[i]].min\n b += x\n tu[i] -= x\n sl[i] -= x\nend\n\nputs \"#{a} #{b}\"\n"}, {"source_code": "s = gets.chomp.chars.sort\nt = gets.chomp.chars.sort\nss = Array.new(58, 0)\ntt = Array.new(58, 0)\ns.each do |x|\n ss[x.ord - 65] += 1\nend\nt.each do |x|\n tt[x.ord - 65] += 1\nend\nsu = ss[0..25]\nsl = ss[32..57]\ntu = tt[0..25]\ntl = tt[32..57]\n\na = 0\nb = 0\n26.times do |i|\n x = [su[i], tu[i]].min\n a += x\n tu[i] -= x\n su[i] -= x\n x = [sl[i], tl[i]].min\n a += x\n tl[i] -= x\n sl[i] -= x\nend\n26.times do |i|\n x = [su[i], tl[i]].min\n b += x\n tl[i] -= x\n su[i] -= x\n x = [sl[i], tu[i]].min\n b += x\n tu[i] -= x\n sl[i] -= x\nend\n\nputs \"#{a} #{b}\"\n"}, {"source_code": "s = gets\nt = gets\n\nhs = Hash.new(0)\ns.split('').each { |c| hs[ c ] += 1 }\n\nht = Hash.new(0)\nt.split('').each { |c| ht[ c ] += 1 }\n\na = 0\nb = 0\n\nhs.each do |k, v|\n m = [hs[k], ht[k]].min\n a += m\n hs[k] -= m\n ht[k] -= m\nend\n\nhs.each do |k, v|\n m = [hs[k], ht[ k.downcase ]].min\n b += m\n hs[ k ] -= m\n ht[ k.downcase ] += m\n\n m = [hs[k], ht[ k.upcase ]].min\n b += m\n hs[ k ] -= m\n ht[ k.upcase ] += m\nend\n\nputs \"#{a - 1} #{b}\""}, {"source_code": "s = gets.chomp\nt = gets.chomp\nn = t.size()\nm = s.size()\na=Array.new(300).map{|e| e=0 }\nb=Array.new(300).map{|e| e=0 }\n for i in 0..n-1\n a[t[i].ord] += 1\n end\n for i in 0..m-1\n b[s[i].ord] += 1\n end\nyra = 0\noops = 0\nfor i in 0..200\n if a[i] > 0 && b[i] > 0\n a1 = a[i]\n b1 = b[i]\n # puts (a1.to_s + ' '+ b1.to_s + ' ' + i.to_s)\n yra += [a[i], b[i]].min\n a[i] -= b1\n b[i] -= a1\n end\n end\n for i in 64..91\n if (a[i] > 0 && b[i + 32] > 0)\n a1 = a[i]\n b1 = b[i + 32]\n oops += [a1, b1].min\n a[i] -= b1\n b[i] -= a1\n end\n end\n for i in 97..123\n if (a[i] > 0 && b[i - 32] > 0)\n a1 = a[i]\n b1 = b[i - 32]\n oops += [a1, b1].min\n a[i] -= b1\n b[i] -= a1\n end\n end\n s2 = \"\"\n s2 = yra.to_s + \" \" + oops.to_s\nputs (s2)"}, {"source_code": "if __FILE__ == $0\n END { main }\nend\n\ndef main\n s = gets.strip\n t = gets.strip\n\n s_freqs = get_letter_freqs(s)\n t_freqs = get_letter_freqs(t)\n\n yay_count = get_yay_count(s_freqs, t_freqs)\n whoops_count = get_whoops_count(s_freqs, t_freqs)\n\n puts [yay_count, whoops_count].join(\" \")\nend\n\ndef get_letter_freqs(s)\n h = Hash.new(0)\n s.chars.each do |ch|\n h[ch] += 1\n end\n h\nend\n\ndef get_yay_count(s_freqs, t_freqs)\n count = 0\n s_freqs.each do |ch, freq|\n freq.times do\n if t_freqs[ch] > 0\n s_freqs[ch] -= 1\n t_freqs[ch] -= 1\n count += 1\n end\n end\n end\n count\nend\n\ndef get_whoops_count(s_freqs, t_freqs)\n count = 0\n s_freqs.each do |s_ch, s_freq|\n t_ch = s_ch.swapcase\n s_freq.times do\n if t_freqs[t_ch] > 0\n s_freqs[s_ch] -= 1\n t_freqs[t_ch] -= 1\n count += 1\n end\n end\n end\n count\nend\n"}], "negative_code": [{"source_code": "a=gets.chomp\nb=gets.chomp\nahash=Hash.new(0)\nbhash=Hash.new(0)\na.each_char {|i| ahash[i]+=1}\nb.each_char {|i| bhash[i]+=1}\nc=ahash.keys\nyay=0\nwhoops=0\nc.each do |i|\nif ahash[i]<=bhash[i]\nyay+=ahash[i]\nelse\nyay+=bhash[i]\nif i=i.downcase\np=(ahash[i]-bhash[i])\nk=bhash[i.upcase]\nif p>=k\nwhoops+=k\nelse\nwhoops+=p\nend\nelse\np=(ahash[i]-bhash[i])\nk=bhash[i.dowbcase]\nif p>=k\nwhoops+=k\nelse\nwhoops+=p\nend\nend\nend\nend\n\nputs \"#{yay} #{whoops}\""}, {"source_code": "a=gets.chomp\nb=gets.chomp\nahash=Hash.new(0)\nbhash=Hash.new(0)\na.each_char {|i| ahash[i]+=1}\nb.each_char {|i| bhash[i]+=1}\nc=ahash.keys\nyay=0\nwhoops=0\nc.each do |i|\nif ahash[i]<=bhash[i]\nyay+=ahash[i]\nelse\nyay+=bhash[i]\nwhoops+=(ahash[i]-bhash[i])\nend\nend\nputs \"#{yay} #{whoops}\""}, {"source_code": "a=gets.chomp\nb=gets.chomp\nahash=Hash.new(0)\nbhash=Hash.new(0)\na.each_char {|i| ahash[i]+=1}\nb.each_char {|i| bhash[i]+=1}\nc=ahash.keys\nyay=0\nwhoops=0\nc.each do |i|\nif ahash[i]<=bhash[i]\nyay+=ahash[i]\nelse\nyay+=bhash[i]\nif i==i.downcase\np=(ahash[i]-bhash[i])\nk=bhash[i.upcase]\nif p>=k\nwhoops+=k\nelse\nwhoops+=p\nend\nelse\np=(ahash[i]-bhash[i])\nk=bhash[i.downcase]\nif p>=k\nwhoops+=k\nelse\nwhoops+=p\nend\nend\nend\nend\n\nputs \"#{yay} #{whoops}\""}, {"source_code": "s = gets\nt = gets\nn = t.size()\nm = s.size()\na=Array.new(300).map{|e| e=0 }\nb=Array.new(300).map{|e| e=0 }\n for i in 0..n-1\n a[t[i].ord] += 1\n end\n for i in 0..m-1\n b[s[i].ord] += 1\n end\nyra = 0\noops = 0\nfor i in 0..200\n if a[i] > 0 && b[i] > 0\n a1 = a[i]\n b1 = b[i]\n yra += [a[i], b[i]].min\n a[i] -= b1\n b[i] -= a1\n end\n end\n for i in 62..94\n if (a[i] > 0 && b[i + 32] > 0)\n a1 = a[i]\n b1 = b[i + 32]\n oops += [a1, b1].min\n a[i] -= b1\n b[i] -= a1\n end\n end\n for i in 95..125\n if (a[i] > 0 && b[i - 32] > 0)\n a1 = a[i]\n b1 = b[i - 32]\n oops += [a1, b1].min\n a[i] -= b1\n b[i] -= a1\n end\n end\n s2 = \"\"\n s2 = yra.to_s + \" \" + oops.to_s\nputs (s2)"}, {"source_code": "s = gets\nt = gets\nn = t.size()\nm = s.size()\na=Array.new(300).map{|e| e=0 }\nb=Array.new(300).map{|e| e=0 }\n for i in 0..n-1\n a[t[i].ord] += 1\n end\n for i in 0..m-1\n b[s[i].ord] += 1\n end\nyra = 0\noops = 0\nfor i in 0..200\n if a[i] > 0 && b[i] > 0\n a1 = a[i]\n b1 = b[i]\n yra += [a[i], b[i]].min\n a[i] -= b1\n b[i] -= a1\n end\n end\n for i in 64..91\n if (a[i] > 0 && b[i + 32] > 0)\n a1 = a[i]\n b1 = b[i + 32]\n oops += [a1, b1].min\n a[i] -= b1\n b[i] -= a1\n end\n end\n for i in 97..123\n if (a[i] > 0 && b[i - 32] > 0)\n a1 = a[i]\n b1 = b[i - 32]\n oops += [a1, b1].min\n a[i] -= b1\n b[i] -= a1\n end\n end\n s2 = \"\"\n s2 = yra.to_s + \" \" + oops.to_s\nputs (s2)"}, {"source_code": "if __FILE__ == $0\n END { main }\nend\n\ndef main\n s = gets.strip\n t = gets.strip\n\n s_freqs = get_letter_freqs(s)\n t_freqs = get_letter_freqs(t)\n\n yay_count = get_yay_count(s_freqs, t_freqs)\n whoops_count = get_whoops_count(s_freqs, t_freqs)\n\n puts [yay_count, whoops_count].join(\" \")\nend\n\ndef get_letter_freqs(s)\n h = Hash.new(0)\n s.chars.each do |ch|\n h[ch] += 1\n end\n h\nend\n\ndef get_yay_count(s_freqs, t_freqs)\n count = 0\n s_freqs.each do |ch, freq|\n freq.times do\n if t_freqs[ch] > 0\n s_freqs[ch] += 1\n t_freqs[ch] -= 1\n count += 1\n end\n end\n end\n count\nend\n\ndef get_whoops_count(s_freqs, t_freqs)\n count = 0\n s_freqs.each do |s_ch, s_freq|\n t_ch = s_ch.swapcase\n s_freq.times do\n if t_freqs[t_ch] > 0\n s_freqs[s_ch] += 1\n t_freqs[t_ch] -= 1\n count += 1\n end\n end\n end\n count\nend\n"}], "src_uid": "96e2ba997eff50ffb805b6be62c56222"} {"source_code": "number = gets.to_i\n\nif number % 2 == 0\n\tl = number / 2\n\tlimit = l - 1\n\tfor counter in 0..limit\n\t\tprint \"1\"\n\tend\nend\nif number % 2 == 1\n\tl = number / 2\n\tlimit = l - 2;\n\tprint \"7\"\n\tfor counter in 0..limit\n\t\tprint \"1\"\n\tend\nend", "positive_code": [{"source_code": "r=->{gets.split.map &:to_i}\nns=r[]\nn = ns[0]\nif n % 2 == 0 then\n\tputs \"1\"*(n/2)\nelse\n\tputs \"7\" + \"1\"*(n/2-1)\nend\n"}, {"source_code": "x=gets.to_i\ny=x%2\nx=x/2-y\nputs \"7\"*y+\"1\"*x\n"}, {"source_code": "a = gets.chomp.to_i\nb = a / 2\nc = a % 2\n\nif c == 1\n puts '7' + '1' * (b - 1)\nelse\n puts '1' * b\nend\n"}, {"source_code": "n = gets.chomp.to_i\nif n % 2 == 1\n print 7\n n -= 3\nend\ni = 0\nwhile i < n do\n i += 2\n print 1\nend"}, {"source_code": "i = gets.to_i\nif i % 2 == 0\n c = i / 2\n answer = \"\"\n for counter in 1..c\n answer += \"1\"\n end\nelse\n c = i / 2 - 1\n answer = \"7\"\n for counter in 1..c\n answer += \"1\"\n end\nend\nputs answer\n"}, {"source_code": "puts (i=gets.chomp.to_i) % 2 == 0 ? '1'*(i/2) : '7'+('1'*((i-3)/2))"}, {"source_code": "n = gets.to_i\nif n % 2 == 0\n puts '1'*(n / 2)\nelse\n puts '7'+'1'*( (n - 3) / 2)\nend"}, {"source_code": "h = gets.to_i\nif h % 2 == 0\n puts '1'*(h / 2)\nelse\n puts '7'+'1'*( (h - 3) / 2)\nend"}, {"source_code": "puts (i=gets.chomp.to_i) % 2 == 0 ? '1'*(i/2) : '7'+('1'*((i-3)/2))"}, {"source_code": "n = gets.to_i\nif (n % 2 == 1)\n print(7)\n n = n - 3\nend\nwhile (n > 0)\n print(1)\n n = n - 2\nend"}, {"source_code": "#!/bin/ruby\nt = gets.strip.to_i\n#for a0 in (0..t-1)\n# n = gets.strip.to_i\n#end\ns=\"\"\nb=t\nwhile t>7\n t-=2\n s.concat(\"1\")\nend\nif t==2\n s=\"1\" \nend\nif t==3\n s=\"7\"\nend\nif t==4\n s=\"11\"\nend\nif t==5\n s=\"71\"\nend\nif t==6\n s.concat(\"1\")\n s.concat(\"1\")\n s.concat(\"1\")\nend\nif t==7\n s=\"7\"\n while b>7\n b-=2\n s.concat(\"1\")\n end\n s.concat(\"1\")\n s.concat(\"1\")\n #s.concat(\"1\")\n #s[0]=7\nend\n\nprint s,\"\\n\""}, {"source_code": "a = gets\na = a.to_i\nif a > 1\n if a % 2 == 1\n print 7\n a -=3\n end\nend\nwhile a > 1\n print 1\n a -= 2\nend"}, {"source_code": "x = gets.chomp.to_i\ns = \"\"\nif(x % 2 == 0)\n\twhile(x > 0)\n\t\ts += \"1\"\n\t\tx-=2\n\tend\nend\nif x % 2 == 1\n\ts += \"7\"\n\tx-=3\n\twhile(x > 0)\n\t\ts += \"1\"\n\t\tx-=2\n\tend\nend\nputs s"}, {"source_code": "n = gets.to_i\n\nif n % 2 == 1\n ans = '7' + '1' * ((n - 3) / 2)\nelse\n ans = '1' * (n / 2)\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\n\nans = \"1\" * (n/2)\nif n % 2 == 1\n ans[0]=\"7\"\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\nstr = \"\"\nif n % 2 > 0\n print 7\nelse\n print 1\nend\n\nn -= 2\nn /= 2\nn.times do\n print 1 \nend"}, {"source_code": "num = gets.to_i\n\nrem = num % 2\nif rem == 1\n if num > 2\n print 7\n num = num - 3\nend\nend\nwhile num>0\nprint 1\nnum = num-2;\nend"}, {"source_code": "a = gets.to_i\n\nif a % 2 == 1\n print '7'\n a -= 3\nend\n\na = (a/2).to_i\n\nfor i in 1..a\n print 1\nend\n"}, {"source_code": "n1 = gets.chomp\nn = n1.to_i\nc = \"1\"*(n/2)\nd = \"1\"*(n/2 -1)\nif n%2==0\n print c\nelse\n print \"7\"\n print d\nend"}, {"source_code": "# your code goes here\nr = gets.strip.split(/\\s+/).map(&:to_i)\nt = r[0]\nif t % 2 == 1\n\tputs '7' + ('1' * ((t - 3) / 2))\nelse\n\tputs '1' * (t / 2)\nend"}, {"source_code": "a = gets.to_i\ns = '1' * ((a - 2) / 2)\nif (a & 1) == 0\n s = s + '1'\nelse\n s = '7' + s\nend\nputs s"}, {"source_code": "c = Integer(gets)\ns = \"\"\nif c % 2 == 1\n\ts += '7'\n\tc -= 3\nend\n(c/2).times do\n\ts += '1'\nend\nputs s"}, {"source_code": "n = gets.to_i\nif n % 2 == 1 then\n\tres = '7'\n\tn -= 3\nelse\n\tres = '1'\n\tn -= 2\nend\nn = n / 2\ns = '1'*n\nres += s\nputs res"}, {"source_code": "n = gets\nn = n.to_i\nif n % 2 == 0\n print '1' * (n / 2)\nelse\n print '7' + '1' * (n / 2 - 1)\nend"}, {"source_code": "n=gets.chomp.to_i\nz=n/2\nt=n%2\nans=''\nif t==1\n z=z-1\n ans+='7'\nend\nfor i in 1..z \n ans+='1'\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\nif (n & 1 != 0) then\n print \"7\"\n n = n-2\nend\n(1..n/2).each do |i|\n print \"1\"\nend"}], "negative_code": [{"source_code": "n = gets\nn = n.to_i\nif n % 2 == 0\n print '1' * (n / 2)\nelse\n if n == 3\n print '17'\n else\n print '1' * ((n / 2) - 1) + '7'\n end\nend"}, {"source_code": "n = gets\nn = n.to_i\nif n % 2 == 0\n print '1' * (n / 2)\nelse\n print '1' * (n / 2 - 1) + '7'\nend"}, {"source_code": "n = gets\nn = n.to_i\nif n % 2 == 0\n print '1' * (n / 2)\nelse\n puts '1' * ((n / 2) - 1) + '7'\nend"}, {"source_code": "c = Integer(gets)\nwhile c >= 6\n\tprint('9')\n\t$stdout.flush\n\tc -= 6\nend\nif c >= 3\n\tprint('7')\n\t$stdout.flush\nelsif c == 2\n\tprint('1')\n\t$stdout.flush\nend\nputs ''"}, {"source_code": "c = Integer(gets)\nif c == 3\n\tprint '7'\n\t$stdout.flush\nelse\n\t(c/2).times do\n\t\tprint '1'\n\t\t$stdout.flush\n\tend\nend"}, {"source_code": "a=[6,2,5,5,4,5,6,3,7,6]\nn=gets.chomp.to_i\nans=0\nwhile n>=2 do\n i=9\n while i>=0 do\n if a[i]<=n \n ans+=ans*10+i\n n=n-a[i]\n end \n i=i-1\n end\nend\nputs ans\n"}], "src_uid": "4ebea3f56ffd43efc9e1496a0ef7fa2d"} {"source_code": "n = gets.to_i\ntimes = Array.new(n * 2, 0)\nfor i in 0..n-1\n v = gets.split(\":\")\n t = v[0].to_i * 60 + v[1].to_i\n times[i*2] = t\n times[i*2+1] = t + 1\nend\n\ntimes = times.sort\n#puts times\n\ntf = -1\ntl = 0\nres = 0\nfor i in 0..2*n-1\n t = times[i]\n if tf == -1\n tf = t\n elsif res < t - tl\n res = t - tl\n end\n tl = t\n #puts res\nend\nif res < 24 * 60 - tl + tf\n res = 24 * 60 - tl + tf\nend\nif (res / 60) < 10\n print \"0\"\nend\nprint (res / 60).to_s\nprint \":\"\nif (res % 60) < 10\n print \"0\"\nend\nprint (res % 60).to_s", "positive_code": [{"source_code": "def strtime(str)\n h = str.split(':')[0].to_i\n m = str.split(':')[1].to_i\n h * 60 + m\nend\n\nn = STDIN.gets.chomp!.to_i\nt = (1..n).map { |i| strtime(STDIN.gets.chomp!) }\nt.sort!\n\nans = 0\n(0...n).map do |i|\n d = t[(i + 1) % n] - t[i] - 1\n d = d + 24 * 60 if d < 0\n ans = [ans, d].max\nend\n\nprintf(\"%02d:%02d\\n\", ans / 60, ans % 60)\n"}, {"source_code": "n = gets.to_i\ntimes = []\n\nn.times do\n hh, mm = gets.split(':').map(&:to_i)\n time = hh * 60 + mm\n times.push(time)\n times.push(time + 24 * 60)\nend\n\ntimes.sort!\n\nt = 0\nans = 0\n\ntimes.each {\n |time|\n \n if time - t - 1 > ans\n ans = time - t - 1\n end\n \n t = time\n}\nhh, mm = ans / 60, ans % 60\nhh, mm = \"%02d\" % hh, \"%02d\" % mm\n\nputs \"#{hh}:#{mm}\"\n"}, {"source_code": "n=gets.to_i\nt=Array.new\nfor i in 1..n do\n s=gets\n t.push(s[0,2].to_i*60+s[3,2].to_i)\nend\nt.sort!\nmx=1439-t[n-1]+t[0]\nfor i in 1..n-1 do\n if t[i]-t[i-1]-1>mx then mx=t[i]-t[i-1]-1 end\nend\nif mx/60<10 then print 0 end\nprint mx/60\nprint ':'\nif mx%60<10 then print 0 end\nprint mx%60"}, {"source_code": "n=gets.to_i\nt=Array.new\nfor i in 1..n do\n s=gets\n t.push(s[0,2].to_i*60+s[3,2].to_i)\nend\nt.sort!\nmx=1439-t[n-1]+t[0]\nfor i in 1..n-1 do\n if t[i]-t[i-1]-1>mx then mx=t[i]-t[i-1]-1 end\nend\nif mx/60<10 then print 0 end\nprint mx/60\nprint ':'\nif mx%60<10 then print 0 end\nprint mx%60"}], "negative_code": [{"source_code": "n=gets.to_i\nt=Array.new\nfor i in 1..n do\n s=gets\n t.push(s[0,2].to_i*60+s[3,2].to_i)\nend\nt.sort!\nmx=1439-t[n-1]+t[0]-1\nif n==1 then mx+=1 end\nfor i in 1..n-1 do\n if t[i]-t[i-1]-1>mx then mx=t[i]-t[i-1]-1 end\nend\nif mx/60<10 then print 0 end\nprint mx/60\nprint ':'\nif mx%60<10 then print 0 end\nprint mx%60"}, {"source_code": "n = gets.to_i\ntimes = Array.new(n * 2, 0)\nfor i in 0..n-1\n v = gets.split(\":\")\n t = v[0].to_i * 60 + v[1].to_i\n times[i*2] = t\n times[i*2+1] = t + 1\nend\n\ntimes = times.sort\n#puts times\n\ntf = -1\ntl = 0\nres = 0\nfor i in 0..2*n-1\n t = times[i]\n if tf == -1\n tf = t\n elsif res < t - tl\n res = t - tl\n end\n tl = t\n #puts res\nend\nif res < 24 * 60 - tl + tf\n res = 24 * 60 - tl + tf\nend\nprint (res / 60).to_s + \":\" + (res % 60).to_s"}, {"source_code": "n = gets.to_i\ntimes = Array.new(n * 2)\ntf = -1\ntl = 0\nres = 200000\nfor i in 0..n-1\n v = gets.split(\":\")\n t = v[0].to_i * 60 + v[1].to_i\n if tf == -1\n tf = t\n elsif res > t - tl\n res = t - tl\n end\n tl = t + 1\nend\nif res > 24 * 60 - tl + tf\n res = 24 * 60 - tl + tf\nend\nprint (res / 60).to_s + \":\" + (res % 60).to_s"}], "src_uid": "c3b0b7194ce018bea9c0b9139e537a09"} {"source_code": "gets;p$<.map{|e|e.split.map(&:to_i).reduce(:|)}.reduce(:+)", "positive_code": [{"source_code": "def f(a)\n b, *c = a\n c.each { |e| b |= e }\n\n b\nend\n\nn = gets.chomp.to_i\narr1 = gets.chomp.split.map(&:to_i)\narr2 = gets.chomp.split.map(&:to_i)\nputs f(arr1) + f(arr2)\n"}], "negative_code": [], "src_uid": "475239ff4ae3675354d2229aba081a58"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nfirst = {}\nlast = {}\ncount = Hash.new(0)\n\na.each_with_index{|x, i|\n first[x] ||= i+1\n last[x] = i+1\n count[x] += 1\n}\n\n_, c_max = count.max_by{|x, c| c}\n\nx_opt = first.keys.select{|x| count[x] == c_max}.min_by{|x|\n last[x] - first[x]\n}\n\nputs \"#{first[x_opt]} #{last[x_opt]}\"\n\n\n\n\n\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\nfirsts = {}\nlasts = {}\ncount = Hash.new(0)\n\na.each.with_index do |k, idx|\n firsts[k] ||= idx\n lasts[k] = idx\n\n count[k] += 1\nend\n\nmax_key, max_value = count.max_by {|_, v| v }\nmin_key, min_value = firsts.select do |k, v|\n count[k] == max_value\nend.min_by do |k, _|\n lasts[k] - firsts[k]\nend\n\nputs [firsts[min_key] + 1, lasts[min_key] + 1].join(' ')\n"}, {"source_code": "#!/usr/bin/ruby\nh=Hash.new{|h,k|h[k]=[]}\ngets\ngets.split.each.with_index(1){|e,i|\n\th[e.to_i]< min_boy\n potential = min_boy / 2.0\nelse\n potential = min_girl\nend\n\nmax = [3 * n * potential, w].min\n\np max\n", "positive_code": [{"source_code": "n, w = gets.split.map &:to_i\na = gets.split.map &:to_i\na = a.sort\nx = a[0...n].min\ny = a[n...(2*n)].min\nputs [[2*x, y].min * 1.5 * n, w].min\n"}, {"source_code": "# http://codeforces.com/contest/557/problem/B\nn, w = gets.chomp.split.map(&:to_i)\ncups = gets.chomp.split.map(&:to_i).sort\n\ngirl = cups[0..n].min\nboy = cups[n..-1].min\n\nmin = [\n [2 * girl, boy].min * 1.5 * n,\n w\n].min\n\nputs min\n"}, {"source_code": "def get_ints\n gets.split(\" \").map(&:to_i)\nend\n\nn, w = get_ints\ncup = get_ints\n\ncup.sort!\n\nx = [cup[0], cup[cup.size / 2] / 2.0].min\nans = [x * 3 * n, w].min\ni = ans.to_i\np ans == i ? i : ans"}, {"source_code": "# @line_n = -1\n# @lines = File.readlines('test7.in')\n# def gets; @line_n+=1; @lines[@line_n] end\ndef read_ints; gets.chomp.split.map(&:to_i) end\nn,w = read_ints\na = read_ints.sort\n\nx = [a.sort[n]/2.0,a.sort[0],w/(3.0*n)].min\nputs 3*x*n\n"}, {"source_code": "n, w = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\na.sort!\n\nputs [[a[0] * 2, a[n]].min * 1.5 * n, w].min\n"}, {"source_code": "# http://codeforces.com/problemset/problem/557/B\nn, w = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i).sort\n\ni = 2 * n - 1\nmin_girl = a[0]\nmin_boy = a[n]\n\nif min_girl * 2 > min_boy\n potential = min_boy / 2.0\nelse\n potential = min_girl\nend\n\nmax = [3 * n * potential, w].min\n\np max == max.to_i ? max.to_i : max\n\n[2,2,2,4,4,4]\n"}], "negative_code": [{"source_code": "def read_ints; gets.chomp.split.map(&:to_i) end\nn,w = read_ints\na = read_ints\nx = [a.sort[n]/2.0,w/(3.0*n)].min\nputs 3*x*n\n"}, {"source_code": "# http://codeforces.com/problemset/problem/557/B\n\nn, w = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i).sort\n\ni = 2 * n - 1\nwhile i > 0\n if a[i] <= w\n break potential = a[i]\n end\n i -= 1\nend\n\nif potential\n x = potential / 2.0\n max = [3 * n * x, w].min\nelse\n max = w\nend\n\np max == max.to_i ? max.to_i : max\n"}, {"source_code": "# http://codeforces.com/problemset/problem/557/B\n\nn, w = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\n\nif a.max > w\n p w\nelse\n x = a.max / 2.0\n\n max = 3 * n * x\n\n p max == max.to_i ? max.to_i : max\nend\n"}, {"source_code": "# http://codeforces.com/problemset/problem/557/B\n\nn, w = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\n\nx = a.max / 2.0\n\nmax = 3 * n * x\n\np max == max.to_i ? max.to_i : max\n"}], "src_uid": "b2031a328d72b464f965b4789fd35b93"} {"source_code": "# your code goes here\n\nn,l,r = gets.split(\" \").map(&:to_i)\na = gets.split(\" \").map(&:to_i)\nb = gets.split(\" \").map(&:to_i)\nl-=1\nr-=1\na[l..r] = a[l..r].sort()\nb[l..r] = b[l..r].sort()\nif a==b\n\tputs \"TRUTH\"\nelse\n\tputs \"LIE\"\nend", "positive_code": [{"source_code": "#!/bin/ruby\n\nrequire 'set'\n\nn, l, r = gets.strip.split(' ')\nn = n.to_i\nl = l.to_i\nr = r.to_i\nl -= 1\nr -= 1\n\na = gets.strip.split(' ').map(&:to_i)\nb = gets.strip.split(' ').map(&:to_i)\n\t\ncount = false\nh = Hash.new\n\nfor i in l..r do\n\th[a[i]] += 1 if h.has_key?(a[i])\n\th[a[i]] = 1 unless h.has_key?(a[i])\nend\n\nfor i in l..r\n\tif (h.has_key?(b[i]) && h[b[i]] == 0) || !h.has_key?(b[i])\n\t\tcount = true\n\t\tbreak\n\tend\n\th[b[i]] -= 1 if h.has_key?(b[i]) && h[b[i]] > 0\nend\n\nif count\n\tputs \"LIE\"\nelse\n\tcount = false\n\tfor i in 0...n\n\t\tnext if l <= i && i <= r\n\t\tif a[i] != b[i]\n\t\t\tcount = true\n\t\t\tbreak\n\t\tend\n\tend\n\tputs count ? \"LIE\" : \"TRUTH\"\nend"}, {"source_code": "n, l, r = gets.split.map &:to_i\ntrueseq = gets.split.map &:to_i\nmainseq = gets.split.map &:to_i\n\nl, r = l-1, r-1\n# trueseq[0...l] == mainseq[0...l]\n# trueseq[r+1..-1] == mainseq[r+1..-1]\n# trueseq[l..r].set ~~~ mainseq[l..r].set\n\ndef oops\n\tputs 'LIE'\n\texit\nend\n\ngood = true\noops if trueseq[0...l] != mainseq[0...l]\noops if trueseq[r+1..-1] != mainseq[r+1..-1]\noops if trueseq[l..r].sort != mainseq[l..r].sort\n\nputs 'TRUTH'\n"}, {"source_code": "# require 'set'\n\nn, l, r = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\n\na1 = a.take(r).drop(l - 1)\nb1 = b.take(r).drop(l - 1)\na1 = a1.sort()\nb1 = b1.sort()\n\nif (a.take(l - 1) == b.take(l - 1) && a.drop(r) == b.drop(r) && a1 == b1) then\n\tputs \"TRUTH\"\nelse\n\tputs \"LIE\"\nend\n"}], "negative_code": [{"source_code": "#!/bin/ruby\n\nrequire 'set'\n\nn, l, r = gets.strip.split(' ')\nn = n.to_i\nl = l.to_i\nr = r.to_i\nl -= 1\nr -= 1\n\na = gets.strip.split(' ').map(&:to_i)\nb = gets.strip.split(' ').map(&:to_i)\n\t\ncount = false\nh = Hash.new\n\nfor i in l..r do\n\th[a[i]] += 1 if h.has_key?(a[i])\n\th[a[i]] = 1 unless h.has_key?(a[i])\nend\n\nfor i in l..r\n\tif (h.has_key?(b[i]) && h[b[i]] == 0) || !h.has_key?(b[i])\n\t\tcount = 0\n\t\tbreak\n\tend\n\th[b[i]] -= 1 if h.has_key?(b[i]) && h[b[i]] > 0\nend\n\nif count\n\tputs \"LIE\"\nelse\n\tcount = false\n\tfor i in 0...n\n\t\tif i < l && i > r && a[i] != b[i]\n\t\t\tcount = true\n\t\t\tbreak\n\t\tend\n\tend\n\tputs count ? \"LIE\" : \"TRUTH\"\nend"}, {"source_code": "#!/bin/ruby\n\nrequire 'set'\n\nn, l, r = gets.strip.split(' ')\nn = n.to_i\nl = l.to_i\nr = r.to_i\nl -= 1\nr -= 1\n\na = gets.strip.split(' ').map(&:to_i)\nb = gets.strip.split(' ').map(&:to_i)\n\t\ncount = 0\nh = Hash.new\nfor i in l..r do\n\th[a[i]] += 1 if h.has_key?(a[i])\n\th[a[i]] = 1 unless h.has_key?(a[i])\nend\n\nfor i in l..r\n\tif h.has_key?(b[i]) && h[b[i]] == 0 || !h.has_key?(b[i])\n\t\tcount += 1\n\t\tbreak\n\tend\nend\n\nif count > 0\n\tputs \"LIE\"\nelse\n\tcount = 0\n\tfor i in 0...n\n\t\tif i < l && i > r && a[i] != b[i]\n\t\t\tcount += 1\n\t\t\tbreak\n\t\tend\n\tend\n\tif count > 0\n\t\tputs \"LIE\"\n\telse\n\t\tputs \"TRUTH\"\n\tend\nend"}, {"source_code": "#!/bin/ruby\n\nrequire 'set'\na, b = Array.new(100010), Array.new(100010)\n\nn, l, r = gets.strip.split(' ')\nn = n.to_i\nl = l.to_i\nr = r.to_i\nl -= 1\nr -= 1\n\na = gets.strip\na = a.split(' ').map(&:to_i)\n\nb = gets.strip\nb = b.split(' ').map(&:to_i)\n\t\ncount = 0\ns = Set.new\nfor i in l..r do\n\ts.add(a[i])\nend\n\nfor i in l..r\n\tunless s.include?(b[i])\n\t\tcount += 1\n\t\tbreak\n\tend\nend\n\nif count > 0\n\tputs \"LIE\"\nelse\n\tcount = 0\n\tfor i in 0...n\n\t\tif i < l && i > r && a[i] != b[i]\n\t\t\tcount += 1\n\t\t\tbreak\n\t\tend\n\tend\n\tif count > 0\n\t\tputs \"LIE\"\n\telse\n\t\tputs \"TRUTH\"\n\tend\nend"}], "src_uid": "1951bf085050c7e32fcf713132b30605"} {"source_code": "n = gets.to_i\nl = n.times.map{gets.split.map(&:to_i)}.sort\n\ndef f(n)\n return n if n <= 1\n n * f(n - 1)\nend\n\ndef c(n, m)\n if n > m\n f(n) / (f(m) * f(n - m))\n elsif n < m\n 0\n else\n 1\n end\nend\n\nans = c(n, 3)\n0.upto(n - 1) do |i|\n a = []\n (i + 1).upto(n - 1) do |j|\n a << (l[j][1] - l[i][1]).to_f / (l[j][0] - l[i][0])\n end\n a.sort!\n b = nil\n s = 1\n a.size.times do |j|\n if a[j] != b\n ans -= c(s, 2)\n s = 1\n b = a[j]\n else\n s += 1\n ans -= c(s, 2) if j == a.size - 1\n end\n end\nend\nputs ans\n", "positive_code": [{"source_code": "n = gets.to_i\nl = n.times.map{gets.split.map(&:to_i)}.sort\nans = n * (n - 1) * (n - 2) / 6\n0.upto(n - 1) do |i|\n a = (i + 1).upto(n - 1).map{|j| (l[j][1] - l[i][1]).to_f / (l[j][0] - l[i][0])}.sort\n s = 1\n a.each_cons(2) do |x, y|\n if x == y\n s += 1\n else\n ans -= s * (s - 1) / 2\n s = 1\n end\n end\n ans -= s * (s - 1) / 2\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\np = n.times.map{gets.split.map(&:to_i)}.sort\nans = n * (n - 1) * (n - 2) / 6\nn.times do |i|\n c = 1\n (i + 1)\n .upto(n - 1)\n .map{|j| (p[j][1] - p[i][1]).to_f / (p[j][0] - p[i][0])}\n .sort\n .each_cons(2) do |a, b|\n if a == b\n c += 1\n else\n ans -= c * (c - 1) / 2;\n c = 1\n end\n end\n ans -= c * (c - 1) / 2\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\np = n.times.map{gets.split.map(&:to_i)}.sort\nans = n * (n - 1) * (n - 2) / 6\nn.times do |i|\n c = 1\n (i + 1)\n .upto(n - 1)\n .map{|j| Math.atan2(p[j][1] - p[i][1], p[j][0] - p[i][0])}\n .sort\n .each_cons(2) do |a, b|\n if a == b\n c += 1\n else\n ans -= c * (c - 1) / 2;\n c = 1\n end\n end\n ans -= c * (c - 1) / 2\nend\nputs ans\n"}], "negative_code": [{"source_code": "n = gets.to_i\nl = n.times.map{gets.split.map(&:to_i)}\nans = 0\n0.upto(n - 1) do |i|\n (i + 1).upto(n - 1) do |j|\n (j + 1).upto(n - 1) do |k|\n a = l[i][0] - l[j][0] == 0 ? '-' : (l[i][1] - l[j][1]) / (l[i][0] - l[j][0])\n b = l[j][0] - l[k][0] == 0 ? '-' : (l[j][1] - l[k][1]) / (l[j][0] - l[k][0])\n c = l[i][0] - l[k][0] == 0 ? '-' : (l[i][1] - l[k][1]) / (l[i][0] - l[k][0])\n ans += 1 if a != b && b != c && a != c\n end\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\nl = n.times.map{gets.split.map(&:to_i)}\n\ndef f(n)\n return n if n <= 1\n n * f(n - 1)\nend\n\ndef c(n, m)\n if n > m\n f(n) / (f(m) * f(n - m))\n elsif n < m\n 0\n else\n 1\n end\nend\n\nans = c(n, 3)\n0.upto(n - 1) do |i|\n a = []\n (i + 1).upto(n - 1) do |j|\n a << (l[j][1] - l[i][1]).to_f / (l[j][0] - l[i][0])\n end\n a.sort!\n b = nil\n s = 1\n a.size.times do |j|\n if a[j] != b\n ans -= c(s, 2)\n s = 1\n b = a[j]\n else\n s += 1\n ans -= c(s, 2) if j == a.size - 1\n end\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nans = 0\n0.upto(n - 1) do |i|\n (i + 1).upto(n - 1) do |j|\n (j + 1).upto(n - 1) do |k|\n puts \"#{i} #{j} #{k}\" if n == 100\n p = a[i][0] - a[j][0] == 0 ? '-' : (a[i][1] - a[j][1]) / (a[i][0] - a[j][0])\n q = a[j][0] - a[k][0] == 0 ? '-' : (a[j][1] - a[k][1]) / (a[j][0] - a[k][0])\n ans += 1 if p != q\n end\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nans = 0\n0.upto(n - 1) do |i|\n (i + 1).upto(n - 1) do |j|\n (j + 1).upto(n - 1) do |k|\n p = a[i][0] - a[j][0] == 0 ? '-' : (a[i][1] - a[j][1]) / (a[i][0] - a[j][0])\n q = a[j][0] - a[k][0] == 0 ? '-' : (a[j][1] - a[k][1]) / (a[j][0] - a[k][0])\n ans += 1 if p != q\n end\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nans = 0\n0.upto(n - 1) do |i|\n (i + 1).upto(n - 1) do |j|\n (j + 1).upto(n - 1) do |k|\n p = a[i][0] - a[j][0] == 0 ? '-' : (a[i][1] - a[j][1]) / (a[i][0] - a[j][0])\n q = a[k][0] - a[j][0] == 0 ? '-' : (a[k][1] - a[j][1]) / (a[k][0] - a[j][0])\n ans += 1 if p != q\n end\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\nl = n.times.map{gets.split.map(&:to_i)}\nans = 0\n0.upto(n - 1) do |i|\n (i + 1).upto(n - 1) do |j|\n (j + 1).upto(n - 1) do |k|\n a = l[i][0] - l[j][0] == 0 ? '-' : (l[i][1] - l[j][1]) / (l[i][0] - l[j][0])\n b = l[j][0] - l[k][0] == 0 ? '-' : (l[j][1] - l[k][1]) / (l[j][0] - l[k][0])\n c = l[i][0] - l[k][0] == 0 ? '-' : (l[i][1] - l[k][1]) / (l[i][0] - l[k][0])\n ans += 1 if a != b || b != c || a != c\n end\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\nl = n.times.map{gets.split.map(&:to_i)}\nans = 0\n0.upto(n - 1) do |i|\n (i + 1).upto(n - 1) do |j|\n (j + 1).upto(n - 1) do |k|\n a = l[i][0] - l[j][0] == 0 ? '-' : (l[i][1] - l[j][1]) / (l[i][0] - l[j][0])\n b = l[j][0] - l[k][0] == 0 ? '-' : (l[j][1] - l[k][1]) / (l[j][0] - l[k][0])\n c = l[i][0] - l[k][0] == 0 ? '-' : (l[i][1] - l[k][1]) / (l[i][0] - l[k][0])\n ans += 1 if a != b && b != c\n end\n end\nend\nputs ans\n"}], "src_uid": "d5913f8208efa1641f53caaee7624622"} {"source_code": "n = readline.to_i\narr = readline.split(' ').collect(&:to_i)\nret = 0\nwhile !arr.empty?\n a = arr.uniq\n ret += a.length - 1\n a.each do |num|\n arr.delete_at(arr.find_index(num))\n end\nend\nputs ret\n", "positive_code": [{"source_code": "n,*a=$<.read.split;p n.to_i-a.map{|e|a.count(e)}.max.to_i\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nc = 0\n\naf = [0]*n\nwhile af.inject {|s, aa| s + aa } < n\n\tac = -1\n\tn.times do |i|\n\t\tif af[i]==0 && ac -1\n\t\t\tac = a[i]\n\t\t\taf[i] = 1\n\t\tend\n\tend\nend\n\nputs c"}, {"source_code": "n,*a=$<.read.split.map &:to_i;p n-a.group_by{|e|e}.map{|k,v|v.size}.max"}, {"source_code": "n = gets.chomp.to_i\nh1 = Hash.new { 0 }\ngets.chomp.split.map(&:to_i).each { |a| h1[a] += 1 }\n\nh2 = Hash.new { 0 }\nh1.each do |_, v|\n (1..v).each { |e| h2[e] += 1 }\nend\n\nans = 0\n\nh2.each { |_, v| ans += [v - 1, 0].max }\n\nputs ans\n"}, {"source_code": "n=gets.to_i\nhs=Hash.new(0)\ngets.split.map{|e| e.to_i}.each{|e|\n\ths[e]+=1\n}\nxs=hs.sort.map{|e| e[1]}\nans=0\nmax1=0\nxs.each{|e|\n\tif max1>=e then\n\t\tans+=e\n\telse\n\t\tans+=max1\n\t\tmax1=e\n\tend\n}\nputs ans"}, {"source_code": "n = gets.chomp.to_i\nax = gets.chomp.split(\"\\s\").map(&:to_i).sort\n\ntmp_ax = ax.reduce(Hash.new(0)) { |acc, e| acc.tap { |hash| hash[e] += 1 } }\ncount = 0\n\nuntil tmp_ax.size == 0\n # Add the number of elements - 1 to count\n count += tmp_ax.size - 1\n\n # Minus 1 from all elements of tmp_ax\n tmp_ax = tmp_ax.reduce({}) { |acc, (k, v)| acc.merge(k => v - 1) }\n\n # Delete elements whose value is 0\n tmp_ax = tmp_ax.select { |k, v| v > 0 }\nend\n\nputs count\n"}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\n\nhs = Hash.new(0)\nas.each do |a|\n hs[a] += 1\nend\n\ncs = Hash.new(0)\nhs.each do |_, v|\n for i in 1..v\n cs[i] += 1\n end\nend\n\nans = 0\ncs.each do |_, v|\n ans += [v - 1, 0].max\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nr = 0\nwhile a.any?\n b = a.uniq\n r += b.count - 1\n b.each {|x| a.delete_at(a.index(x))}\nend\nputs r"}, {"source_code": "def way(n, img)\n\tshow = []\n # puts \"count #{img.count}\"\n for i in 1...img.count\n #puts \"i = #{i}\"\n unless img[i-1] == img[i]\n # puts \"index = #{i}\"\n n += 1\n else\n show.push(img[i-1])\n end\n end\n\n #puts \"way n = #{n} img = #{img} show = #{show}\"\n return n, show\nend\n\ncount_img = gets.to_i\n\nimg = Array.new(count_img)\n\nimg = gets.split.map(&:to_i)\nimg = img.sort\nn = 0\n\nwhile true do\n answer = way(n, img)\n n = answer[0]\n img = answer[1]\n # puts \"main n = #{n} img = #{img}\"\n if img.count < 2\n puts n\n exit\n end\nend\n"}, {"source_code": "n,*a=$<.read.split;p n.to_i-a.map{|e|a.count(e)}.max.to_i\n"}, {"source_code": "n,*a=$<.read.split.map &:to_i;p n-a.group_by{|e|e}.map{|k,v|v.size}.max"}, {"source_code": "n,*a=$<.read.split.map &:to_i;p n-a.group_by{|e|e}.map{|k,v|v.size}.max"}, {"source_code": "n = gets.to_i\na = gets.split(\" \")\ntot = Array.new(1111, 0)\na.each do |x|\n\ttot[x.to_i] += 1\nend\nans=1\ntot.each do |c|\n\tans = [ans, c].max\nend\nputs n-ans"}, {"source_code": "def way(n, img)\n\tshow = []\n # puts \"count #{img.count}\"\n for i in 1...img.count\n #puts \"i = #{i}\"\n unless img[i-1] == img[i]\n # puts \"index = #{i}\"\n n += 1\n else\n show.push(img[i-1])\n end\n end\n \n #puts \"way n = #{n} img = #{img} show = #{show}\"\n return n, show\nend\n\ncount_img = gets.to_i\n\nimg = Array.new(count_img)\n\nimg = gets.split.map(&:to_i)\nimg = img.sort\nn = 0\n\nwhile true do\n answer = way(n, img)\n n = answer[0]\n img = answer[1]\n # puts \"main n = #{n} img = #{img}\"\n if img.count < 2\n puts n\n exit\n end\nend"}, {"source_code": "#!/usr/bin/ruby\nrequire 'set'\nrequire 'scanf'\n\nbeauty_sets = [Set.new]\nnum_paintings = scanf(\"%d\\n\").first.to_i\nbeauties = gets().split(' ').map(&:to_i)\nbeauties.each do |beauty|\n placed = false\n beauty_sets.each do |bs|\n if !bs.include?(beauty)\n bs.add(beauty)\n placed = true\n break\n end\n end\n if !placed\n beauty_sets << Set.new\n beauty_sets.last.add(beauty)\n end\nend\n\nsum = 0\nbeauty_sets.each { |bs| sum += bs.count-1 }\n\nputs sum\n"}], "negative_code": [{"source_code": "gets;p gets.split.uniq.size"}, {"source_code": "n = gets.chomp.to_i\nh1 = Hash.new { 0 }\ngets.chomp.split.map(&:to_i).each { |a| h1[a] += 1 }\n\nh2 = Hash.new { 0 }\nh1.each do |_, v|\n (1..v).each { |e| h2[e] += 1 }\nend\n\nans = 0\np h1\np h2\nh2.each { |_, v| ans += [v - 1, 0].max }\n\nputs ans\n"}, {"source_code": "def way(n, img)\n\tshow = []\n for i in 1...img.count\n if img[i] != img[i+1]\n n += 1\n else\n show.push(img[i])\n end\n end\n\t\n return n, show\nend\n\ncount_img = gets.to_i\n\nimg = Array.new(count_img)\n\nimg = gets.split.map(&:to_i)\nimg = img.sort\nn = 0\n\nwhile true do\n answer = way(n, img)\n n = answer[0]\n img = answer[1]\n if img.count <= 2\n puts n\n exit\n end\nend\n"}, {"source_code": "def way(n, img)\n\tshow = []\n for i in 1...img.count\n if img[i] != img[i+1]\n n += 1\n else\n show.push(img[i])\n end\n end\n return n, show\nend\n\ndef main\n count_img = gets.to_i\n\n img = Array.new(count_img)\n\n img = gets.split.map(&:to_i)\n img = img.sort\n n = 0\n\n while true do\n answer = way(n, img)\n n = answer[0]\n img = answer[1]\n return if img.count <= 2\n end\n\n p n\nend\n\nmain\n"}, {"source_code": "def way(n, img)\n\tshow = []\n for i in 1...img.count\n if img[i] != img[i+1]\n n += 1\n else\n show.push(img[i])\n end\n end\n\n puts \"way n = #{n} img = #{img} show = #{show}\"\n return n, show\nend\n\ncount_img = gets.to_i\n\nimg = Array.new(count_img)\n\nimg = gets.split.map(&:to_i)\nimg = img.sort\nn = 0\n\nwhile true do\n answer = way(n, img)\n n = answer[0]\n img = answer[1]\n puts \"main n = #{n} img = #{img}\"\n if img.count <= 2\n puts n\n exit\n end\nend\n"}, {"source_code": "def way(n, img)\n\tshow = []\n # puts \"count #{img.count}\"\n for i in 1...img.count\n #puts \"i = #{i}\"\n unless img[i-1] == img[i]\n # puts \"index = #{i}\"\n n += 1\n else\n show.push(img[i-1])\n end\n end\n \n #puts \"way n = #{n} img = #{img} show = #{show}\"\n return n, show\nend\n\ncount_img = gets.to_i\n\nimg = Array.new(count_img)\n\nimg = gets.split.map(&:to_i)\nimg = img.sort\nn = 0\n\nwhile true do\n answer = way(n, img)\n n = answer[0]\n img = answer[1]\n # puts \"main n = #{n} img = #{img}\"\n if img.count <= 2\n puts n\n exit\n end\nend"}, {"source_code": "def way(n, img)\n\tshow = []\n puts \"count #{img.count}\"\n for i in 1...img.count\n #puts \"i = #{i}\"\n unless img[i-1] == img[i]\n # puts \"index = #{i}\"\n n += 1\n else\n show.push(img[i-1])\n end\n end\n \n #puts \"way n = #{n} img = #{img} show = #{show}\"\n return n, show\nend\n\ncount_img = gets.to_i\n\nimg = Array.new(count_img)\n\nimg = gets.split.map(&:to_i)\nimg = img.sort\nn = 0\n\nwhile true do\n answer = way(n, img)\n n = answer[0]\n img = answer[1]\n # puts \"main n = #{n} img = #{img}\"\n if img.count <= 2\n puts n\n exit\n end\nend"}, {"source_code": "#!/usr/bin/ruby\nrequire 'set'\nrequire 'scanf'\n\nbeauty_sets = [Set.new]\nnum_paintings = scanf(\"%d\").first.to_i\nbeauties = gets().split(' ').map(&:to_i)\nbeauties.each do |beauty|\n placed = false\n beauty_sets.each do |bs|\n if !bs.include?(beauty)\n bs.add(beauty)\n placed = true\n break\n end\n end\n if !placed\n beauty_sets << Set.new\n beauty_sets.last.add(beauty)\n end\nend\n\nsum = 0\nbeauty_sets.each { |bs| sum += bs.count-1 }\n\nputs sum\n"}], "src_uid": "30ad5bdc019fcd8a4e642c90decca58f"} {"source_code": "\tdef abs( n )\n\t\tn > 0 ? n : -n\n\tend\n\n\tn,m = gets.chomp.strip.split(\" \")\n\tarr = gets.chomp.strip.split(\" \")\n\tm = m.to_i\n\tn = n.to_i\n\n\tif n > m\n\t\tputs 0\n\telse\n\t\tans = 1\n\t\t(0..n-1).each do | i |\n\t\t\t(i+1..n-1).each do | j |\n\t\t\t\tans = ( ans * abs(arr[ j ].to_i - arr[ i ].to_i ) ) % m\n\t\t\tend\n\t\tend\n\t\tputs ans\n\tend", "positive_code": [{"source_code": "N, M = gets.split.map(&:to_i)\nA = gets.split.map(&:to_i).sort\nB = A.map { |a| a % M }\n\ncounter = Hash.new(0)\n\nB.each do |b|\n counter[b] += 1\nend\n\nif counter.values.max >= 2\n puts 0\nelse\n ans = 1\n\n N.times do |i|\n (i + 1).upto(N - 1) do |j|\n ans = ans * (A[i] - A[j]).abs % M\n end\n end\n\n puts ans % M\nend\n"}], "negative_code": [{"source_code": "def abs( n )\n\tn > 0 ? n : -n\nend\n\nn,m = gets.chomp\nn = n.to_i\nm = m.to_i\narr = gets.chomp.strip.split(\" \")\n\nif n > m\n\tputs 0\nelse\n\tans = 0\n\t(0..n-1).each do | i |\n\t\t(i+1..n-1).each do | j |\n\t\t\tans = ( ans * abs(arr[ j ].to_i - arr[ i ].to_i ) ) % m\n\t\tend\n\tend\nend"}, {"source_code": "def abs( n )\n\tn > 0 ? n : -n\nend\n\nn,m = gets.chomp.strip.split(\" \")\narr = gets.chomp.strip.split(\" \")\nm = m.to_i\nn = n.to_i\n\nif n > m\n\tputs 0\nelse\n\tans = 0\n\t(0..n-1).each do | i |\n\t\t(i+1..n-1).each do | j |\n\t\t\tans = ( ans * abs(arr[ j ].to_i - arr[ i ].to_i ) ) % m\n\t\tend\n\tend\n\tputs ans\nend"}, {"source_code": "def abs( n )\n\tn > 0 ? n : -n\nend\n\nn,m = gets.chomp.strip.split(\" \")\narr = gets.chomp.strip.split(\" \")\nm = m.to_i\nn = n.to_i\n\nif n > m\n\tputs 0\nelse\n\tans = 0\n\t(0..n-1).each do | i |\n\t\t(i+1..n-1).each do | j |\n\t\t\tans = ( ans * abs(arr[ j ].to_i - arr[ i ].to_i ) ) % m\n\t\tend\n\tend\nend"}], "src_uid": "bf115b24d85a0581e709c012793b248b"} {"source_code": "gets\nar = gets.split.map(&:to_i)\nh = {}\nar.each_index do |i|\n h[ar[i]] = ar[ar[i]-1] if ar.include?(ar[ar[i]-1])\nend\nh.each do |key, val|\n b = h[val]\n if h[b] == key\n puts \"Yes\"\n exit 0\n end\nend\nputs \"No\"", "positive_code": [{"source_code": "a=$<.read.split.map &:to_i\nputs (1...a.size).any?{|i|\n\ta[a[a[i]]]==i\n} ? :YES : :NO"}, {"source_code": "n = gets.to_i;\ninp = gets.chomp.split().map(&:to_i);\nt = true;\nfor i in 0..n-1\n if(inp[inp[inp[i] - 1] - 1] - 1 == i)\n t = false;\n puts \"YES\";\n break;\n end;\nend;\nif (t)\n puts \"NO\";\nend;\n"}, {"source_code": "n = Integer(gets)\nfriends = gets.split.map{|a| Integer(a)}\na1 = (1..n).to_a\na2 = friends\na3 = a2.map{|a| friends[a-1] }\na4 = a3.map{|a| friends[a-1] }\n\nputs (if a1.zip(a2,a3,a4).detect{|a,b,c,d| a==d and a!=b and a!=c and b!=c} then \"YES\" else \"NO\" end) "}, {"source_code": "n = gets.to_i\nfs = gets.split.map(&:to_i)\nans = 'NO'\n\nfs.each_with_index do |f, i|\n if i == fs[fs[f-1]-1] - 1\n ans = 'YES'\n end\nend\n\nputs ans"}, {"source_code": "a=$<.read.split.map &:to_i\nputs (1...a.size).any?{|i|\n\ta[a[a[i]]]==i\n} ? :YES : :NO\n"}, {"source_code": "$n=gets.chomp.to_i\n$f=gets.split.map &:to_i\ndef check (a,b,c)\n if (b==4 and a==c)\n return true\n end\n if (b>3)\n return false\n end\n return check($f[a]-1,b+1,c)\nend\nfor i in 0.upto($n-1)\n if (check(i,1,i))\n print \"YES\"\n exit\n end\nend\nprint \"NO\""}, {"source_code": "a=$<.read.split.map &:to_i\nputs (1...a.size).any?{|i|\n\ta[a[a[i]]]==i\n} ? :YES : :NO"}, {"source_code": "def judge(n, f)\n (1..n).each do |i|\n return true if f[f[f[i]]] == i\n end\n return false\nend\n\nn = gets.to_i\nf = gets.split.map(&:to_i).insert(0, 0)\nputs judge(n, f) ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ')\nfor i in 0..n-1\n a[i]=a[i].to_i-1\nend\nfor i in 0..n-1\n t= (a[a[a[i]]]==i)|t\nend\nif t==true\n puts \"YES\"\nelse \n puts \"NO\" \nend"}, {"source_code": "n = gets.to_i\nf = [nil] + gets.split.map(&:to_i)\n(1...f.size).each do |i|\n if f[f[f[i]]] == i\n puts 'YES'\n exit\n end\nend\nputs 'NO'\n"}, {"source_code": "# Love Triangles\n\ndef track(a, e)\n\treturn a[e-1]\nend\n\ndef check(a, i)\n\tx = track(a, a[i])\n\treturn 1\tif track(a, x)== i+1\n\treturn 0\nend\n\ndef find_luv(inp,n)\n\tfor i in 0..n-1\n\t\treturn 'YES' if check(inp,i) == 1\n\tend\n\treturn 'NO'\nend\n\nn = gets.to_i\ninp = gets.chomp.split().map(&:to_i)\nputs find_luv(inp,n)"}, {"source_code": "def solve(n, f)\n n = n.to_i\n f = f.split(&:to_i)\n for i in 0...n\n x = f[i].to_i\n y = f[x - 1].to_i\n return true if f[y - 1].to_i == i.to_i + 1\n end\n\n return false\nend\n\nn = gets.chomp\nf = gets.chomp\n\nif solve(n, f)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}], "negative_code": [{"source_code": "n,*a=$<.read.split.map &:to_i\nputs [*0...n].permutation(2).any?{|i,j|\n\ta[a[a[j]-1]-1]==i\n} ? :YES : :NO"}, {"source_code": "n,*a=$<.read.split.map &:to_i\nputs [*0...n].permutation(2).any?{|i,j|\n\ta[a[j]-1]==i\n} ? :YES : :NO"}, {"source_code": "n = gets.to_i\na = gets.split(' ')\nfor i in 0..n-1\n a[i]=a[i].to_i-1\nend\nt=1\nfor i in 0..n-1\n t= (a[a[a[i]]]==i)\n t=1\nend\nif t==1\n puts \"YES\"\nelse \n puts \"NO\" \nend"}], "src_uid": "a37c3f2828490c70301b5b5deeee0f88"} {"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each_slice(2) do |inp|\r\n a = inp[0].to_i\r\n nums = inp[1].split(' ').map(&:to_i).sort\r\n\r\n ex = Hash[ (1..a).map{|n| [n, true] } ]\r\n nums.each do |n|\r\n i = n\r\n while i >= 1\r\n if ex[i]\r\n ex.delete(i)\r\n break\r\n end\r\n\r\n i /= 2\r\n end\r\n end\r\n\r\n if ex.length == 0\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend", "positive_code": [{"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each_slice(2) do |inp|\r\n a = inp[0].to_i\r\n nums = inp[1].split(' ').map(&:to_i).sort\r\n\r\n ex = Hash[ (1..a).map{|n| [n, true] } ]\r\n nums.each do |n|\r\n while n >= 1\r\n if ex[n]\r\n ex.delete(n)\r\n break\r\n end\r\n\r\n n /= 2\r\n end\r\n end\r\n\r\n if ex.length == 0\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend"}, {"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each_slice(2) do |inp|\r\n a = inp[0].to_i\r\n nums = inp[1].split(' ').map(&:to_i).sort\r\n\r\n ex = Hash[ (1..a).map{|n| [n, true] } ]\r\n nums.each do |n|\r\n i = n\r\n while i >= 1\r\n if ex[i]\r\n ex.delete(i)\r\n break\r\n end\r\n\r\n i = (i / 2).round\r\n end\r\n end\r\n\r\n if ex.length == 0\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend"}, {"source_code": "require 'set'\r\n\r\ninputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each_slice(2) do |inp|\r\n a = inp[0].to_i\r\n nums = inp[1].split(' ').map(&:to_i).sort\r\n\r\n ex = Set.new((1..a).to_a)\r\n nums.each do |n|\r\n i = n\r\n while i >= 1\r\n if ex.member?(i)\r\n ex.delete(i)\r\n break\r\n end\r\n\r\n i = (i / 2).round\r\n end\r\n end\r\n\r\n if ex.length == 0\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n xs = gets.split.map(&:to_i)\n\n h = {}\n xs.each_with_index do |x, i|\n loop {\n (h[x] ||= []) << i if x <= n\n x /= 2\n break if x == 0\n }\n end\n\n if h.size != n\n puts \"NO\"\n next\n end\n\n used = [false] * n\n h = h.values.sort_by! { _1.size }\n\n solution_exists = true\n\n h.each do |indices|\n found = false\n indices.each do |i|\n if !used[i]\n used[i] = true\n found = true\n break\n end\n end\n\n if !found\n solution_exists = false\n break\n end\n end\n\n puts(solution_exists ? \"YES\" : \"NO\")\nend\n"}, {"source_code": "require 'set'\n\nt = readline.strip.to_i\nt.times do\n readline\n a = readline.strip.split(/\\s+/).map(&:to_i)\n s = Set.new((1..a.count).to_a)\n a.each do |e|\n while e > 0\n if s.member?(e)\n s.delete(e)\n break\n end\n\n e /= 2\n end\n end\n\n puts s.count == 0 ? 'YES' : 'NO'\nend\n"}], "negative_code": [], "src_uid": "645459e0a41ec63b13648ea8dbe0f053"} {"source_code": "n, m = gets.split.map(&:to_i)\nr, c = Array.new(n + 1), Array.new(n + 1)\nn.times do |i|\n r[i] = c[i] = 0\nend\nm.times do\n x, y = gets.split.map(&:to_i)\n r[x], c[y] = 1, 1\nend\nans = 0\n(2...n).step(1) do |i|\n ans += 1 if r[i].zero?\n ans += 1 if c[i].zero?\nend\nans -= 1 if (n.odd? && r[n / 2 + 1].zero? && c[n / 2 + 1].zero?)\np ans\n", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nr, c = Array.new(n + 1){0}, Array.new(n + 1){0}\nm.times do\n x, y = gets.split.map(&:to_i)\n r[x], c[y] = 1, 1\nend\nans = 0\n(2...n).step(1){|i| ans += (r[i].zero?? 1 : 0) + (c[i].zero?? 1 : 0)}\nans -= 1 if (n.odd? && r[n / 2 + 1].zero? && c[n / 2 + 1].zero?)\np ans\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nrows = Array.new(n, true)\nrows[0] = rows[-1] = false\ncols = rows.dup\nfor line in (1..m)\n\tr, c = gets.split.map(&:to_i)\n\trows[r-1] = false\n\tcols[c-1] = false\nend\nrows[n/2] = false if (n%2 == 1 and cols[n/2])\nputs rows.count(true) + cols.count(true)"}], "negative_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nrows = Array.new(n, true)\nrows[0] = rows[-1] = false\ncols = rows.dup\nfor line in (1..m)\n\tr, c = gets.split.map(&:to_i)\n\trows[r-1] = false\n\tcols[c-1] = false\nend\nrows[n/2] = false if (n & 1 and cols[n/2])\nputs rows.count(true) + cols.count(true)"}, {"source_code": "n, m = gets.split.map(&:to_i)\nrows = Array.new(n, true)\nrows[0] = rows[-1] = false\ncols = rows.dup\nfor line in (1..m)\n\tr, c = gets.split.map(&:to_i)\n\trows[r-1] = false\n\tcols[c-1] = false\nend\nrows[n/2] = false if (n/2 == 1 and cols[n/2])\nputs rows.count(true) + cols.count(true)"}], "src_uid": "a26a97586d4efb5855aa3b930e9effa7"} {"source_code": "n, k = gets.split.map(&:to_i)\nputs 2 * k >= n * (n - 1) ? \"no solution\" : [*1..n].map{|i|\"0 \"+i.to_s}\n\n", "positive_code": [{"source_code": "#!/usr/bin/ruby1.9\n\npoint_num, limit = STDIN.readline.split.collect {|s| s.to_i }\n\nif point_num*(point_num-1)/2 <= limit\n\tputs 'no solution'\n\texit\nend\n\n(point_num-1).times do |i|\n\tputs '%d %d' % [i, i*10000]\nend\nputs '%d %d' % [point_num, 0]\n"}, {"source_code": "n,k = gets().split().map{ |x| x.to_i}\nif (1.0*n*(n-1)/2 <= k)\n puts \"no solution\";\nelse\n (1..n).each do |i|\n puts \"0 %d\" % [i];\n end\nend"}, {"source_code": "input = STDIN.read\n\ninput =~ /^(\\d+) (\\d+)/\nn, k = $1.to_i, $2.to_i\nl = (n * (n - 1)) / 2\n\nif (k >= l)\n puts 'no solution'\nelse\n (0...n).each { |y| puts \"0 #{y}\" }\nend\n"}, {"source_code": "n, k = gets.chomp.split.map { |num| num.to_i }\nif k >= ((n - 1) * n / 2)\n puts \"no solution\" \nelse\n (1..n).each do |i|\n puts \"0 #{i}\"\n end\nend\n"}, {"source_code": "n,k = gets.chomp.split(\" \").collect {|x| x.to_i}\n\nif k>=(n*(n-1)/2)\n puts \"no solution\"\nelse\n (1..n).each { |k|\n puts \"0 #{k}\"\n }\nend"}, {"source_code": "n,k = gets.strip.split(' ').map {|x| x.to_i}\n \nif( k>= (n*(n-1))/2 )\n puts 'no solution'\nelse\n n.times do |i|\n puts \"0 #{i*2}\"\n end\nend"}, {"source_code": "#!/usr/bin/ruby\n\nn, k = gets.split(\" \").map(&:to_i)\n\ntot = n * (n - 1) / 2\n\nif tot <= k\n puts \"no solution\"\nelse\n 0.upto(n - 1) {|y| puts \"0 #{y}\" }\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs 2 * k >= n * (n - 1) ? \"no solution\" : [*1..n].map{|i|\"0 \"+i.to_s}\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs 2 * k >= n * (n - 1) ? \"no solution\" : [*1..n].map{|i|\"0 \"+i.to_s}\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs 2 * k >= n * (n - 1) ? \"no solution\" : [*1..n].map{|i|\"0 \"+i.to_s}\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs 2 * k >= n * (n - 1) ? \"no solution\" : [*1..n].map{|i|\"0 \"+i.to_s}\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs 2 * k >= n * (n - 1) ? \"no solution\" : [*1..n].map{|i|\"0 \"+i.to_s}\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs 2 * k >= n * (n - 1) ? \"no solution\" : [*1..n].map{|i|\"0 \"+i.to_s}\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nif (n - 1) * n > k * 2\n n.times do |i|\n puts [0, i].join(' ')\n end\nelse\n puts \"no solution\"\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs 2 * k >= n * (n - 1) ? \"no solution\" : [*1..n].map{|i|\"0 \"+i.to_s}\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs 2 * k >= n * (n - 1) ? \"no solution\" : [*1..n].map{|i|\"0 \"+i.to_s}\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs 2 * k >= n * (n - 1) ? \"no solution\" : [*1..n].map{|i|\"0 \"+i.to_s}\n\n"}], "negative_code": [{"source_code": "n, k = gets.split.map(&:to_i)\nif (n - 1) * n > k\n n.times do |i|\n puts [0, i].join(' ')\n end\nelse\n puts \"no solution\"\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs k >= (n == 2 ? 1 : 3 * n - 6) ? \"no solution\" : ([*2..n]<<-3000).map{|i|i.to_s+\" 0\"}.reverse\n"}, {"source_code": "n,k = gets().split().map{ |x| x.to_i}\nif (1.0*n*(n-1)/2 < k)\n puts \"no solution\";\nelse\n (1..n).each do |i|\n puts \"0 %d\" % [i];\n end\nend"}, {"source_code": "input = STDIN.read\n\ninput =~ /^(\\d+) (\\d+)/\nn, k = $1.to_i, $2.to_i\nl = (n * (n - 1)) / 2\n\nif (k > l)\n puts 'no solution'\nelse\n (0...n).each { |y| puts \"0 #{y}\" }\nend\n\n"}, {"source_code": "n,k = gets.chomp.split(\" \").collect {|x| x.to_i}\n\nif k>(n*(n-1)/2)\n puts \"no solution\"\nelse\n (1..n).each { |k|\n puts \"0 #{k}\"\n }\nend"}, {"source_code": "n,k = gets.chomp.split(\" \").collect {|x| x.to_i}\n\nif k>(n*(n+1)/2)\n puts \"no solution\"\nelse\n (1..n).each { |k|\n puts \"0 #{k}\"\n }\nend"}], "src_uid": "a7846e4ae1f3fa5051fab9139a25539c"} {"source_code": "gets\na=gets.split.map(&:to_i).sort\nputs gets.split.map(&:to_i).map{|e|\n\t(0...a.size).bsearch{|i|a[i]>e}||a.size\n}*' '", "positive_code": [{"source_code": "n, m = gets.chomp.split.map(&:to_i)\nas = gets.chomp.split.map(&:to_i)\nbs = gets.chomp.split.map(&:to_i)\n\nas.sort!\ncnt = 0\nhs = Hash.new(0)\nas.each do |a|\n cnt += 1\n hs[a] = cnt\nend\nas.reverse!\ncs = []\nbs.each do |b|\n cs << hs[as.bsearch {|a| a <= b }]\nend\n\nputs cs.*' '\n"}, {"source_code": "n, m = gets.chomp.split(\" \").map(&:to_i)\na = gets.chomp.split(\" \").map(&:to_i).sort\nb = gets.chomp.split(\" \").map(&:to_i)\nres = Array.new()\nb.each do |e|\n tmp = (0...n).bsearch {|i| a[i] > e}\n if tmp.nil? then\n res << n\n else\n res << tmp\n end\nend\nputs res.join(\" \")"}], "negative_code": [], "src_uid": "e9a519be33f25c828bae787330c18dd4"} {"source_code": "arr1 = gets.chomp.split(/ /).map(&:to_i)\nnum = arr1[0]\nfloor_max = arr1[1]\npass = Array.new\ntime = Array.new\nindex=0\nnum.times do\n\tstr = gets.chomp.split(/ /).map(&:to_i)\n\tpass[index] = str[0]\n\ttime[index] = str[1]\n\tindex+=1\nend \n\n_final=0\n\nindex=floor_max\nloop do \n\tbreak if index < 0\n\tindex1=0\n\tloop do \n\t\tbreak if index1>=num\n\t\tif pass[index1] == index && time[index1]>_final\n\t\t\t_final = time[index1]\n\t\tend\n\t\tindex1+=1\n\tend\n\t#puts \"Final is #{_final} and index is #{index}\"\n\t\n\tindex=index-1\n\tbreak if index < 0\n\t_final+=1\nend\n\nputs _final", "positive_code": [{"source_code": "#!/usr/bin/ruby\nn,f=gets.split.map(&:to_i)\nr=f\nn.times{\n\ta,b=gets.split.map(&:to_i)\n\tr=[r,[f-a,b].max+a].max\n}\np r"}, {"source_code": "n, s = gets.chomp.split.map(&:to_i)\nfloors = []\nn.times { floors << gets.chomp.split.map(&:to_i) }\n\nc = 0\nidx = s\nfloors.reverse.each do |a, b|\n c += (idx - a)\n c += (b > c) ? (b - c) : 0\n idx = a\nend\nputs c + idx\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end\n############################################################\n\n\nn, s = gis\n\nmx = s\n\nn.times do\n f, t = gis\n mx = [f + t, mx].max\nend\n\nputs mx\n\n\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\nn.times do\n\tt, f = gets.split.map(&:to_i)\n\ts = [s, t+f].max\nend\nputs s\n"}, {"source_code": "def Int_maker(a)\n\t0.upto(a.length-1) {|i| a[i]=a[i].to_i }\n\treturn a\nend\ninfo=Int_maker(gets.chomp.split(\" \"))\npassenger=[]\n0.upto(info[0]-1){|i| passenger[i]=Int_maker(gets.chomp.split(\" \"))}\npassenger.sort!\npassenger.reverse!\nk=info[1]\ntime=0\n0.upto(info[0]-1) do |i|\n\tif i==0\n\t\ttime=k-(passenger[0][0])\n\t\tif time<(passenger[i][1])\n\t\t\ttime=(passenger[i][1])\n\t\tend\n\telse\n\t\ttime=time+(passenger[i-1][0])-(passenger[i][0])\n\t\tif time<(passenger[i][1])\n\t\t\ttime=(passenger[i][1])\n\t\tend\n\tend\nend\ntime=time+passenger[passenger.length-1][0]\nputs time\n\t\n\n"}, {"source_code": "a = gets.split.map(&:to_i)\nn = a[0]\ns = a[1]\n\nmax = s\n(1..n).each do\n\ta = gets.split.map(&:to_i)\n\tsum = a[0] + a[1]\n\tmax = sum if sum > max\nend\n\nputs max"}, {"source_code": "def Int_maker(a)\n\t0.upto(a.length-1) {|i| a[i]=a[i].to_i }\n\treturn a\nend\ninfo=Int_maker(gets.chomp.split(\" \"))\npassenger=[]\n0.upto(info[0]-1){|i| passenger[i]=Int_maker(gets.chomp.split(\" \"))}\npassenger.sort!\npassenger.reverse!\nk=info[1]\ntime=0\n0.upto(info[0]-1) do |i|\n\tif i==0\n\t\ttime=k-(passenger[0][0])\n\t\tif time<(passenger[i][1])\n\t\t\ttime=(passenger[i][1])\n\t\tend\n\telse\n\t\ttime=time+(passenger[i-1][0])-(passenger[i][0])\n\t\tif time<(passenger[i][1])\n\t\t\ttime=(passenger[i][1])\n\t\tend\n\tend\nend\ntime=time+passenger[passenger.length-1][0]\nputs time"}, {"source_code": "n, s = gets.chomp.split.map(&:to_i)\nans = s\nn.times do\n f, t = gets.chomp.split.map(&:to_i)\n ans = [ans, f + t].max\nend\nputs ans\n"}, {"source_code": "sum, top_floor = gets.split.map(&:to_i)\nwait = Hash.new{|hsh,key| hsh[key] = [] }\nwait[0].push 0\n\nfor i in 0..sum-1\n f_t = gets.split\n floor = f_t[0].to_i\n time = f_t[1].to_i\n\twait[floor].push time\nend\n\nwait = wait.sort.reverse\nall_time = 0\n\nfor i in 0..wait.length-1\n\n shift = wait.shift\n c_floor = shift[0]\n c_floor_time = shift[1]\n\n\tif top_floor > c_floor \n\t\tall_time += top_floor - c_floor\n\t\ttop_floor = c_floor\n\tend\n\n\tif top_floor.to_i == c_floor.to_i\n\t\tc_floor_time = c_floor_time.sort.reverse\n\t\tc_floor_time[0] = c_floor_time[0] - all_time\n\n\t\tif c_floor_time[0] < 0\n\t\t\tc_floor_time[0] = 0 \n\t\tend\n\n\t\tall_time +=c_floor_time[0]\n\tend\nend\np all_time"}, {"source_code": "n, s = gets.split.map(&:to_i)\na = n.times.map{gets.split.map(&:to_i)}.reverse + [[0, 0]]\ncurrent_floor = s\ntime_spent = 0\na.each do |f, t|\n time_spent += [current_floor - f, t - time_spent].max\n current_floor = f\nend\nputs time_spent\n"}, {"source_code": "a = gets.split(' ').collect {|x| x.to_i}\nn = a[0]\ns = a[1]\nresult = s\n(1..n).each do\n a = gets.split(' ').collect {|x| x.to_i}\n result = a[0] + a[1] if a[0]+a[1] > result\nend\n\nputs result"}, {"source_code": "n, s = gets.chomp.split(\" \").map(&:to_i)\npsgs = Array.new()\nn.times do\n psgs << gets.chomp.split(\" \").map(&:to_i)\nend\npsgs = psgs.sort_by{|x| x[0]}.reverse\nres = 0\ncurrent = s\npsgs.each do |f, t|\n res += current - f\n current = f\n if res < t then\n res = t\n end\nend\nif current != 0 then\n res += current\nend\nputs res\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\nmap = Hash.new\n(1..n).each do\n floor, time = gets.split.map(&:to_i)\n if map[floor] == nil\n map[floor] = time\n else\n map[floor] = [map[floor], time].max\n end\nend\n\ncurr = s\ntime = 0\ns.downto(1).each do |floor|\n if map[floor] == nil\n next\n end\n time = [time+curr-floor, map[floor]].max\n curr = floor\nend\n\ntime += curr\n\nputs time\n\n"}, {"source_code": "def Int_maker(a)\n\t0.upto(a.length-1) {|i| a[i]=a[i].to_i }\n\treturn a\nend\ninfo=Int_maker(gets.chomp.split(\" \"))\npassenger=[]\n0.upto(info[0]-1){|i| passenger[i]=Int_maker(gets.chomp.split(\" \"))}\npassenger.sort!\npassenger.reverse!\nk=info[1]\ntime=0\n0.upto(info[0]-1) do |i|\n\tif i==0\n\t\ttime=k-(passenger[0][0])\n\t\tif time<(passenger[i][1])\n\t\t\ttime=(passenger[i][1])\n\t\tend\n\telse\n\t\ttime=time+(passenger[i-1][0])-(passenger[i][0])\n\t\tif time<(passenger[i][1])\n\t\t\ttime=(passenger[i][1])\n\t\tend\n\tend\nend\ntime=time+passenger[passenger.length-1][0]\nputs time\n\t\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\nn.times do\n\tt, f = gets.split.map(&:to_i)\n\ts = [s, t+f].max\nend\nputs s"}, {"source_code": "class Solver\n\tdef main\n\t\tn, s = gets.split.map { |x| x.to_i }\n\t\tans = []\n\t\tn.times do\n\t\t\tf, t = gets.split.map { |x| x.to_i }\n\t\t\tans << [t, s - f].max + f\n\t\tend\n\t\tputs ans.max\n\tend\nend\nSolver.new.main"}], "negative_code": [{"source_code": "def Int_maker(a)\n\t0.upto(a.length-1) {|i| a[i]=a[i].to_i }\n\treturn a\nend\ninfo=Int_maker(gets.chomp.split(\" \"))\npassenger=[]\n0.upto(info[0]-1){|i| passenger[i]=Int_maker(gets.chomp.split(\" \"))}\npassenger.sort!\npassenger.reverse!\nk=info[1]-1\ntime=0\n0.upto(info[0]-1) do |i|\n\tif i==0\n\t\ttime=k-(passenger[0][0])\n\t\tif time<(passenger[i][1])\n\t\t\ttime=(passenger[i][1])\n\t\tend\n\telse\n\t\ttime=time+(passenger[i-1][0])-(passenger[i][0])\n\t\tif time<(passenger[i][1])\n\t\t\ttime=(passenger[i][1])\n\t\tend\n\tend\nend\ntime=time+passenger[passenger.length-1][0]\nputs time\n\t\n\n"}, {"source_code": "def Int_maker(a)\n\t0.upto(a.length-1) {|i| a[i]=a[i].to_i }\n\treturn a\nend\ninfo=Int_maker(gets.chomp.split(\" \"))\npassenger=[]\n0.upto(info[0]-1){|i| passenger[i]=Int_maker(gets.chomp.split(\" \"))}\npassenger.sort!\npassenger.reverse!\nk=info[1]-1\ntime=0\n0.upto(info[0]-1) do |i|\n\tif i==0\n\t\ttime=k-(passenger[0][0])\n\telse\n\t\ttime=time+(passenger[i-1][0])-(passenger[i][0])\n\t\tif time<(passenger[i][1])\n\t\t\ttime=(passenger[i][1])\n\t\tend\n\tend\nend\ntime=time+passenger[passenger.length-1][0]\nputs time\n\t\n\n"}, {"source_code": "n, s = gets.chomp.split.map(&:to_i)\nans = s + 1\nn.times do\n f, t = gets.chomp.split.map(&:to_i)\n ans = [ans, f + t].max\nend\nputs ans\n"}, {"source_code": "s_f = gets.split\nsum = s_f[0].to_i \ntop_floor = s_f[1].to_i \n\nwait = Hash.new\nfor i in 0..sum-1\n\tf_t = gets.split\n\tfloor = f_t[0].to_i\n\ttime = f_t[1].to_i\n\twait[floor] = time\nend\n\nwait = wait.sort.reverse\nstep_flag = 0\n\nall_time = 0\nfor i in 0..sum-1\n\t#\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 wait \u0432 top \u0438 wait_time\n\tshift = wait.shift\n\tc_floor = shift[0]\n\tc_wait_time = shift[1]\n\tif step_flag==0\n\t\tstep = top_floor - c_floor\n\tend\n\tstep_flag = 1\n\n\t#\u0412\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0443 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430\n\twait_time = c_wait_time - all_time\n\tif wait_time < 0\n\t\twait_time = 0\n\tend\n\n\n\tall_time += wait_time\nend\nall_time+=step+1\nputs all_time"}, {"source_code": "n, s = gets.split.map(&:to_i)\nmap = Hash.new\n(1..n).each do\n floor, time = gets.split.map(&:to_i)\n map[floor] = time\nend\n\ncurr = s\ntime = 0\ns.downto(0).each do |floor|\n if map[floor] == nil\n next\n end\n time = [time+curr-floor, map[floor]].max\n curr = floor\nend\n\ntime += curr\n\nputs time\n\n"}], "src_uid": "5c12573b3964ee30af0349c11c0ced3b"} {"source_code": "N = gets.to_i\nA = gets.split.map &:to_i\nss = [0]\nA.each{ |a| ss << (ss[-1] + a) }\nsegs = {}\n(1..N).each{ |j|\n (1..j).each{ |i|\n seg = [i,j]\n v = ss[j] - ss[i-1]\n segs[v] ||= []\n segs[v] << seg\n }\n}\n\nseqs = []\nsegs.each{ |v,ss|\n rb = 0\n sss = []\n ss.each{ |l,r|\n if rb < l\n sss << [l,r]\n rb = r\n end\n }\n if seqs.size < sss.size\n seqs = sss\n end\n}\n\np seqs.size\nseqs.each{ |a,b|\n puts [a,b] * \" \"\n}", "positive_code": [{"source_code": "N = gets.to_i\nA = gets.split.map &:to_i\nss = [0]\nA.each{ |a| ss << (ss[-1] + a) }\nans = 0\nseqs = []\n(0...N).each{ |j|\n (0..j).each{ |i|\n m = 1\n qs = [[i+1,j+1]]\n d = ss[j+1] - ss[i]\n k0 = j+1\n (j+1...N).each{ |k|\n (k0..k).each{ |l|\n e = ss[k+1] - ss[l]\n if d == e\n m += 1\n qs << [l+1,k+1]\n k0 = k+1\n break\n end\n }\n }\n if m > ans\n ans = m\n seqs = qs\n end\n }\n}\nputs ans\nseqs.each{ |a,b| puts [a,b] * \" \" }\n"}], "negative_code": [{"source_code": "N = gets.to_i\nA = gets.split.map &:to_i\nss = [0]\nA.each{ |a| ss << (ss[-1] + a) }\nans = 0\nseqs = []\n(0...N).each{ |j|\n (0..j).each{ |i|\n m = 1\n qs = [[i+1,j+1]]\n d = ss[j+1] - ss[i]\n k0 = j+1\n (j+1...N).each{ |k|\n (k0..k).each{ |l|\n e = ss[k+1] - ss[l]\n if d == e\n m += 1\n qs << [l+1,k+1]\n k0 = k+1\n end\n }\n }\n if m > ans\n ans = m\n seqs = qs\n end\n }\n}\nputs ans\nseqs.each{ |a,b| puts [a,b] * \" \" }"}, {"source_code": "N = gets.to_i\nA = gets.split.map &:to_i\nss = [0]\nA.each{ |a| ss << (ss[-1] + a) }\nans = 0\nseqs = []\np A, ss\n(0...N).each{ |j|\n (0..j).each{ |i|\n m = 1\n qs = [[i+1,j+1]]\n d = ss[j+1] - ss[i]\n k0 = j+1\n (j+1...N).each{ |k|\n (k0..k).each{ |l|\n e = ss[k+1] - ss[l]\n if d == e\n m += 1\n qs << [l+1,k+1]\n k0 = k+1\n end\n }\n }\n if m > ans\n ans = m\n seqs = qs\n end\n }\n}\nputs ans\nseqs.each{ |a,b| puts [a,b] * \" \" }"}], "src_uid": "3e834f89ecedc5f210e680f24e40ba19"} {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n arr = Array.new(n){[0] * n}\n n.times do |i|\n arr[i][i] = 1\n if (i + 1 < n)\n arr[i][i + 1] = 1\n end\n end\n arr[1][0] = arr[n - 1][n - 2] = 1\n n.times do |i|\n puts arr[i].join(\" \")\n end\nend", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n ans = Array.new(n) { Array.new(n, 0) }\n\n n.times do |y|\n 2.times do |x|\n ans[y][(y + x) % n] = 1\n end\n end\n\n puts ans.map { |row| row.join(' ') }\nend\n"}, {"source_code": "t = gets.to_i\n\n1.upto t do\n n = gets.to_i\n arr = Array.new(n) { Array.new(n, 0) }\n\n 0.upto n-1 do |i|\n arr[i][i] = 1\n arr[i][n-1-i] = 1\n end\n\n if n.odd?\n arr[(n-1)/2][((n-1)/2)+1] = 1\n arr[(n+1)/2][(n-1)/2] = 1\n end\n\n puts arr.map { |x| x.join(' ') }\nend\n"}], "negative_code": [], "src_uid": "df6ee0d8bb25dc2040adf1f115f4a83b"} {"source_code": "def method(h, n)\r\n res = 0\r\n (0..2).each { |v| h[v] = 0 unless h.key?(v) }\r\n while h.each_value.max > n\r\n k, v = h.each.max_by { |k, v| v }\r\n h[k] = n\r\n h[(k + 1) % 3] += v - n\r\n res += v - n\r\n end\r\n res\r\nend\r\n \r\nt = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n puts method(a.group_by { |x| x % 3 }.transform_values(&:size), n / 3)\r\nend", "positive_code": [{"source_code": "def method(h, n)\r\n res = 0\r\n (0..2).each { |v| h[v] = 0 unless h.key?(v) }\r\n while h.max_by { |k, v| v }[1] > n\r\n k, v = h.each.max_by { |k, v| v }\r\n h[k] = n\r\n h[(k + 1) % 3] += v - n\r\n res += v - n\r\n end\r\n res\r\nend\r\n \r\nt = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n puts method(a.group_by { |x| x % 3 }.transform_values(&:size), n / 3)\r\nend"}, {"source_code": "def method(h, n)\r\n res = 0\r\n (0..2).each { |v| h[v] = 0 unless h.key?(v) }\r\n while h.each_value.max > n\r\n k, v = h.each.max_by { |k, v| v }\r\n h[k] = n\r\n h[(k + 1) % 3] += v - n\r\n res += v - n\r\n end\r\n res\r\nend\r\n \r\nt = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n puts method(a.group_by { |x| x % 3 }.transform_values(&:size), n / 3)\r\nend\r\n# "}, {"source_code": "def method(h, n)\r\n res = 0\r\n (0..2).each { |v| h[v] = 0 unless h.key?(v) }\r\n h.each do |k, v|\r\n if v > n\r\n res += v - n\r\n h[k] = n\r\n h[(k + 1) % 3] += v - n\r\n end\r\n end while h.values.max > n\r\n res\r\nend\r\n \r\nt = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n puts method(a.group_by { |x| x % 3 }.transform_values(&:size), n / 3)\r\nend"}, {"source_code": "def method(h, n)\r\n res = 0\r\n (0..2).each { |v| h[v] = 0 unless h.key?(v) }\r\n while h.values.max > n\r\n k, v = h.each.max_by { |k, v| v }\r\n h[k] = n\r\n h[(k + 1) % 3] += v - n\r\n res += v - n\r\n end\r\n res\r\nend\r\n \r\nt = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n puts method(a.group_by { |x| x % 3 }.transform_values(&:size), n / 3)\r\nend\r\n# "}, {"source_code": "def method(h, n)\r\n res = 0\r\n (0..2).each { |v| h[v] = 0 unless h.key?(v) }\r\n while h.values.max > n\r\n k, v = h.each.max_by { |k, v| v }\r\n h[k] = n\r\n h[(k + 1) % 3] += v - n\r\n res += v - n\r\n end\r\n res\r\nend\r\n \r\nt = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n puts method(a.group_by { |x| x % 3 }.transform_values(&:size), n / 3)\r\nend"}, {"source_code": "# frozen_string_literal: true\r\n\r\n\r\ntest = gets.to_i\r\ntest.times do\r\n n = gets.chomp.to_i\r\n numbers = gets.chomp.split.map(&:to_i)\r\n remainders = []\r\n (0..2).each do |index|\r\n remainders << numbers.count{|x| x % 3 == index}\r\n end\r\n\r\n\r\n\r\n result = 0\r\n while idx = (0..2).detect{|x| remainders[x] > n / 3} \r\n result += remainders[idx] - n / 3\r\n remainders[(idx+1)% 3] += remainders[idx] - n / 3\r\n remainders[idx] = n / 3\r\n end\r\n puts result\r\nend\r\n"}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tc = (0...3).map { |k| a.count { _1 % 3 == k } }\n\n\tans = 0\n\twhile true\n\t\ti = c.index { _1 > n / 3 }\n\t\tbreak unless i\n\t\tans += 1\n\t\tc[i] -= 1\n\t\tc[-~i % 3] += 1\n\tend\n\tputs ans\nend\n"}, {"source_code": "def solve\r\n count = [0, 0, 0]\r\n n = gets.to_i\r\n arr = gets.split(' ').map(&:to_i)\r\n arr.each do |i|\r\n count[i % 3] += 1\r\n end\r\n\r\n ans = 0\r\n\r\n 2.times do\r\n 3.times do |i|\r\n if count[i] > n / 3\r\n ans += count[i] - n / 3\r\n count[(i + 1) % 3] += count[i] - n / 3\r\n count[i] = n / 3\r\n end\r\n end\r\n end\r\n\r\n puts ans\r\nend\r\n\r\n\r\nt = gets.to_i\r\nt.times { solve }"}, {"source_code": "gets;$<.map{c=[0]*3;gets.split.each{|i|c[i.to_i%3]+=1};p [0,1,2].map{|i|c[i]-c[i-1]}.max}"}, {"source_code": "gets.to_i.times do\r\n n=gets.to_i/3\r\n a=gets.split.map(&:to_i)\r\n c0,c1,c2=0,0,0\r\n a.each do |aa|\r\n if aa%3==0\r\n c0+=1\r\n elsif aa%3==1\r\n c1+=1\r\n else\r\n c2+=1\r\n end\r\n end\r\n c=0\r\n while !(c0==c1&&c1==c2)\r\n if c0>n\r\n c1+=c0-n\r\n c+=c0-n\r\n c0=n\r\n elsif c1>n\r\n c2+=c1-n\r\n c+=c1-n\r\n c1=n\r\n elsif c2>n\r\n c0+=c2-n\r\n c+=c2-n\r\n c2=n\r\n end\r\n end\r\n puts c\r\nend\r\n"}], "negative_code": [], "src_uid": "e0de8a6441614d1e41a53223b5fa576b"} {"source_code": "def solve(a, p)\n q = a.map do |l, r|\n (r / p - (l - 1) / p).to_f / (r - l + 1)\n end\n 2000 * ( 2*q[1..-1].reduce(0, :+) - q.each_cons(2).map {|q1, q2| q1*q2}.reduce(0, :+))\nend\n\nn, p = gets.split.map(&:to_i)\na = Array.new(n+1) do |i|\n next if i == n\n gets.split.map(&:to_i)\nend\na[-1] = a[0]\n\nputs solve(a, p)\n", "positive_code": [{"source_code": "n, p = gets.chomp.split(\" \").map(&:to_i)\nsharks = []\n\nn.times do\n l, r = gets.chomp.split(\" \").map(&:to_i)\n\n x, y = l, r\n if x % p != 0\n x += p-x%p\n end\n y -= y%p\n dividends = (y-x)/p+1\n\n sharks << {l: l, r: r, dividends: dividends, total: r-l+1}\nend\n\nsharks << sharks.first\n\n# puts sharks.inspect\n\nsum = sharks.each_cons(2).map do |shark_a, shark_b|\n shark_a_not_p = 1 - shark_a[:dividends]/shark_a[:total].to_f\n shark_b_not_p = 1 - shark_b[:dividends]/shark_b[:total].to_f\n\n (1 - (shark_a_not_p * shark_b_not_p))*2000\nend.inject(0, :+)\n\nputs sum\n"}, {"source_code": "n, p = gets.chomp.split.map(&:to_i)\nls = []\nrs = []\nn.times do\n l, r = gets.chomp.split.map(&:to_i)\n ls << l\n rs << r\nend\n\ne = 0.0\nfor i in 0...n\n e += 2000.0 * (1.0 - (1.0 - (rs[i] / p - (ls[i] - 1) / p) / (rs[i] - ls[i] + 1).to_f) * (1.0 - (rs[i - 1] / p - (ls[i - 1] - 1) / p) / (rs[i - 1] - ls[i - 1] + 1).to_f))\nend\n\nputs e\n"}, {"source_code": "n, p = gets.chomp.split(\" \").map(&:to_i)\nlr = []\nn.times do \n lr << gets.chomp.split(\" \").map(&:to_i)\nend\nres = 0\nn.times do |i|\n l1, r1 = lr[i]\n l2, r2 = lr[i - 1]\n a1 = r1 / p - (l1 - 1) / p\n a2 = r2 / p - (l2 - 1) / p\n res += 2000 * (1 - (r1 - l1 + 1 - a1) / (r1 - l1 + 1).to_f * (r2 - l2 + 1 - a2) / (r2 - l2 + 1).to_f)\nend\nputs res\n"}], "negative_code": [{"source_code": "n, p = gets.chomp.split(\" \").map(&:to_i)\nsharks = []\n\nn.times do\n l, r = gets.chomp.split(\" \").map(&:to_i)\n\n x, y = l, r\n if x % p != 0\n x += p-x%p\n end\n y -= y%p\n dividends = (y-x)/p+1\n\n sharks << {l: l, r: r, dividends: dividends, total: r-l+1}\nend\n\nsharks << sharks.first\n\nputs sharks.inspect\n\nsum = sharks.each_cons(2).map do |shark_a, shark_b|\n shark_a_not_p = 1 - shark_a[:dividends]/shark_a[:total].to_f\n shark_b_not_p = 1 - shark_b[:dividends]/shark_b[:total].to_f\n\n (1 - (shark_a_not_p * shark_b_not_p))*2000\nend.inject(0, :+)\n\nputs sum\n"}, {"source_code": "n, p = gets.chomp.split(\" \").map(&:to_i)\nsharks = []\n\nn.times do\n l, r = gets.chomp.split(\" \").map(&:to_i)\n dividends = (r-l+1)/p\n sharks << {l: l, r: r, dividends: dividends, total: r-l+1}\nend\n\nsharks << sharks.first\n\nsum = sharks.each_cons(2).map do |shark_a, shark_b|\n shark_a_not_p = 1 - shark_a[:dividends]/shark_a[:total].to_f\n shark_b_not_p = 1 - shark_b[:dividends]/shark_b[:total].to_f\n\n (1 - (shark_a_not_p * shark_b_not_p))*2000\nend.inject(0, :+)\n\nputs sum\n"}], "src_uid": "5aad0a82748d931338140ae81fed301d"} {"source_code": "\nm = Array.new\nn = gets.chomp.to_i\nt = gets.chomp.split(/ /)\nt.each {|u| m << u.to_i}\nm.sort!\n\ns = 0\nm.each {|t| s = s + t}\n\nhash = Hash.new\nif (s % n == 0)\n\thash[s / n] = n\nelse \n\thash[s/n] = n - s % n\n\thash[s/n+1] = s % n\nend\n\nsec = 0\nif hash.size == 1\n\t\t\tm.each {|m_i| \n\t\t\t\tsec = sec + (m_i - s/n).abs\n\t\t\t}\nelse\n\tm.each {|m_i|\n\t\tif m_i != 0\n\t\t\tif m_i <= s / n\n\t\t\t\tif hash[s/n] > 0\n\t\t\t\t\tsec = sec + (s/n - m_i).abs\n\t\t\t\t\thash[s/n] = hash[s/n] - 1\n\t\t\t\telsif hash[s/n + 1] > 0\n\t\t\t\t\tsec = sec + (m_i - s/n - 1).abs\n\t\t\t\t\thash[s/n + 1] = hash[s/n + 1] - 1\n\t\t\t\tend\n\t\t\telsif m_i >= s/n + 1\n\t\t\t if hash[s/n + 1] > 0\n\t\t\t\t\tsec = sec + (m_i - s/n - 1).abs\n\t\t\t\t\thash[s/n + 1] = hash[s/n + 1] - 1\n\t\t\t\telsif hash[s/n] > 0\n\t\t\t\t\tsec = sec + (s/n - m_i).abs\n\t\t\t\t\thash[s/n] = hash[s/n] - 1\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t}\nend\n\nprint sec / 2", "positive_code": [{"source_code": "\nm = Array.new\nn = gets.chomp.to_i\nt = gets.chomp.split(/ /)\nt.each {|u| m << u.to_i}\nm.sort!\n\ns = 0\nm.each {|t| s = s + t}\n\nhash = Hash.new\nif (s % n == 0)\n\thash[s / n] = n\nelse \n\thash[s/n] = n - s % n\n\thash[s/n+1] = s % n\nend\n\nfor i in 0..m.size do\n\tif hash.has_key?(m[i]) && hash[m[i]] != 0 \n\t\thash[m[i]] = hash[m[i]] - 1\n\t\tif hash[m[i]] == 0\n\t\t\thash.delete m[i]\n\t\tend\n\t\tm[i] = 0\n\tend\nend\n\nsec = 0\nif hash.size == 1\n\thash.each_key {|key| \n\t\tif hash[key] != 0\n\t\t\tm.each {|m_i| \n\t\t\t\tif m_i != 0\n\t\t\t\t\tsec = sec + (m_i - key).abs\n\t\t\t\tend\n\t\t\t}\n\t\tend\n\t}\nelse\n\tm.each {|m_i|\n\t\tif m_i != 0\n\t\t\tif m_i < s / n\n\t\t\t\tif hash[s/n] > 0\n\t\t\t\t\tsec = sec + (s/n - m_i).abs\n\t\t\t\t\thash[s/n] = hash[s/n] - 1\n\t\t\t\telsif hash[s/n + 1] > 0\n\t\t\t\t\tsec = sec + (m_i - s/n - 1).abs\n\t\t\t\t\thash[s/n + 1] = hash[s/n + 1] - 1\n\t\t\t\tend\n\t\t\telsif m_i > s/n + 1\n\t\t\t if hash[s/n + 1] > 0\n\t\t\t\t\tsec = sec + (m_i - s/n - 1).abs\n\t\t\t\t\thash[s/n + 1] = hash[s/n + 1] - 1\n\t\t\t\telsif hash[s/n] > 0\n\t\t\t\t\tsec = sec + (s/n - m_i).abs\n\t\t\t\t\thash[s/n] = hash[s/n] - 1\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t}\nend\n\nprint sec / 2"}, {"source_code": "\nm = Array.new\nn = gets.chomp.to_i\nt = gets.chomp.split(/ /)\n\ns = 0\nt.each {|u| m << u.to_i; s = s + u.to_i}\nm.sort!\n\nhash = Hash.new\nif (s % n == 0)\n\thash[s / n] = n\nelse \n\thash[s/n] = n - s % n\n\thash[s/n+1] = s % n\nend\n\nsec = 0\nif hash.size == 1\n\t\t\tm.each {|m_i| \n\t\t\t\tsec = sec + (m_i - s/n).abs\n\t\t\t}\nelse\n\tm.each {|m_i|\n\t\tif m_i <= s / n\n\t\t\tif hash[s/n] > 0\n\t\t\t\tsec = sec + (s/n - m_i).abs\n\t\t\t\thash[s/n] = hash[s/n] - 1\n\t\t\telse\n\t\t\t\tsec = sec + (m_i - s/n - 1).abs\n\t\t\t\thash[s/n + 1] = hash[s/n + 1] - 1\n\t\t\tend\n\t\telse\n\t\t if hash[s/n + 1] > 0\n\t\t\t\tsec = sec + (m_i - s/n - 1).abs\n\t\t\t\thash[s/n + 1] = hash[s/n + 1] - 1\n\t\t\telse\n\t\t\t\tsec = sec + (s/n - m_i).abs\n\t\t\t\thash[s/n] = hash[s/n] - 1\n\t\t\tend\n\t\tend\n\t}\nend\n\nprint sec / 2"}, {"source_code": "n = gets.chomp.to_i\na = gets.split.map(&:to_i)\nsum = a.reduce(0, :+)\nlower_median = sum / n\nupper_median = lower_median + (sum % n == 0 ? 0 : 1)\nupper_total = 0\nlower_total = 0\na.each do |val|\n lower_total += lower_median - val if val < lower_median\n upper_total += val - upper_median if val > upper_median\nend\nputs lower_total > upper_total ? lower_total : upper_total\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets\nm = gets.split.map(&:to_i)\navg = m.inject(:+) / m.size\noverage = m.inject(:+) - (avg * m.size)\nbal = 0\nm.sort!\nm.reverse!\nm.each do |l|\n if l > avg\n if overage > 0\n bal += l - (avg + 1)\n overage -= 1\n else\n bal += l - avg\n end\n else\n if overage > 0\n bal += (avg + 1) - l\n overage -= 1\n else\n bal += avg - l\n end\n end\nend\nputs bal / 2\n"}, {"source_code": "# Accept at \nn = gets.to_i\na = gets.split(' ').map { |x|\n x.to_i\n}\nsum = a.inject { |sum, t| sum += t}\nave = sum / a.length\nn1 = sum - ave * a.length\nresult = 0\ntmp = 0\na.each { |t|\n result += t - ave - 1 if t >= ave+1\n tmp += 1 if t >= ave+1\n}\n\nresult += tmp - n1 if tmp > n1\nputs result\n"}, {"source_code": "n = gets.chomp.to_i\nm = gets.chomp.split(\" \").map(&:to_i).sort\nmsum = m.inject(:+)\nmmod = msum % n\nif mmod == 0\n mm = Array.new(n, msum / n)\nelse\n mm = Array.new(n - mmod, msum / n) + Array.new(mmod, msum / n + 1)\nend\nres = 0\nm.zip(mm).each do |a, b|\n res += (a - b).abs\nend\nputs res / 2"}, {"source_code": "n = gets.to_i\nm = gets.split(' ').map{ |x| x.to_i }\nmsum = m.inject{|sum,x| sum+x}\navg = msum / n\nans1 = ans2 = 0\nfor iter in m\n if iter < avg\n ans1 += avg - iter\n end\n if iter > avg \n ans2 += iter - avg - 1\n end\nend\nputs [ans1, ans2].max\n"}, {"source_code": "n = gets.to_i\nservers = gets.split.map(&:to_i).sort.reverse\nsum = servers.reduce(&:+)\nmin_load = sum/servers.length\nextra = sum%servers.length\noptimal = Array.new(n, min_load)\nfor i in 0...extra\n optimal[i] += 1\nend\ncount = 0\nfor i in 0...n\n count += (servers[i]-optimal[i]).abs\nend\nputs count/2\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\na = gets.split.map(&:to_i).sort\n\ncount = 0\nwhile a[n - 1] - a[0] > 1 do\n # balance\n diff = a[n - 1] - a[0]\n a[0] += diff / 2\n a[n - 1] -= diff / 2\n a[n - 1] -= 1 if diff % 2 != 0\n count += diff / 2\n\n # resort\n i = n - 1\n while a[i] < a[i - 1] do\n temp = a[i]\n a[i] = a[i - 1]\n a[i - 1] = temp\n i -= 1\n end\n i = 0\n while a[i] > a[i + 1] do\n temp = a[i]\n a[i] = a[i + 1]\n a[i + 1] = temp\n i += 1\n end\nend\n\nputs count\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.split.map(&:to_i).sort\n\ncount = 0\nwhile a[n - 1] - a[0] > 1 do\n # balance\n a[0] += 1\n a[n - 1] -= 1\n\n # resort\n i = n - 1\n while a[i] < a[i - 1] do\n temp = a[i]\n a[i] = a[i - 1]\n a[i - 1] = temp\n end\n i = 0\n while a[i] > a[i + 1] do\n temp = a[i]\n a[i] = a[i + 1]\n a[i + 1] = temp\n end\n count += 1\nend\n\nputs count\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets\nm = gets.split.map(&:to_i)\navg = m.inject(:+) / m.size\noverage = m.inject(:+) - (avg * m.size)\nbal = 0\nm.sort!\nm.reverse!\nm.each do |l|\n p overage, bal\n if l > avg\n if overage > 0\n bal += l - (avg + 1)\n overage -= 1\n else\n bal += l - avg\n end\n else\n if overage > 0\n bal += (avg + 1) - l\n overage -= 1\n else\n bal += avg - l\n end\n end\nend\nputs bal\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets\nm = gets.split.map(&:to_i)\navg = m.inject(:+) / m.size\noverage = m.inject(:+) - (avg * m.size)\nbal = 0\nm.sort!\nm.reverse!\nm.each do |l|\n if l > avg\n if overage > 0\n bal += l - (avg + 1)\n overage -= 1\n else\n bal += l - avg\n end\n else\n if overage > 0\n bal += (avg + 1) - l\n overage -= 1\n else\n bal += l - avg\n end\n end\nend\nputs bal\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets\nm = gets.split.map(&:to_i)\nm.sort!\nc = 0\nwhile m.last - m.first > 1\n diff = m.last - m.first\n move = diff / 2\n m[0] += move\n m[m.size - 1] -= move\n m.sort!\n c += move\nend\nputs c\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets\nm = gets.split.map(&:to_i)\navg = m.inject(:+) / m.size\nbal = 0\nm.each do |l|\n if l < avg\n bal += avg - l\n end\nend\nputs bal\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets\nm = gets.split.map(&:to_i)\navg = m.inject(:+) / m.size\nm.sort!\nc = 0\nwhile m.last - m.first > 1\n move = [avg - m.first, m.last - (avg + 1)].max\n diff = m.last - m.first\n m[0] += move\n m[m.size - 1] -= move\n m.sort!\n c += move\nend\nputs c\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets\nm = gets.split.map(&:to_i)\navg = m.inject(:+) / m.size\noverage = m.inject(:+) - (avg * m.size)\nbal = 0\nm.sort!\nm.reverse!\nm.each do |l|\n if l > avg\n if overage > 0\n bal += l - (avg + 1)\n overage -= 1\n else\n bal += l - avg\n end\n else\n if overage > 0\n bal += (avg + 1) - l\n overage -= 1\n else\n bal += l - avg\n end\n end\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |x|\n x.to_i\n}\nsum = a.inject { |sum, t| sum += t}\nave = sum / a.length\nn1 = sum - ave * a.length\nresult = 0\na.each { |t|\n result += t - ave if t >= ave\n}\nputs result - n1\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |x|\n x.to_i\n}\nm = a.inject { |sum, t| sum += t} / 1.0 / a.length\nresult = 0\na.each { |t|\n result += t - m.ceil if t >= m\n}\nputs result\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |x|\n x.to_i\n}\nsum = a.inject { |sum, t| sum += t}\nave = sum / a.length\neven= true if (ave * a.length == sum)\n\nceil = ave\nceil = ave+1 unless even\n\n\nresult = 0\na.each { |t|\n result += t - ceil if t >= ceil\n}\nputs result\n"}, {"source_code": "n = gets.chomp.to_i\nloads = gets.chomp.split(\" \").map(&:to_i)\nm = loads.inject(:+) / n\nloads = loads.select{|i| i - m < 0}\nif loads.empty? then\n puts 0\nelse\n puts loads.map{|i| i - m}.inject(:+).abs()\nend "}, {"source_code": "n = gets.to_i\nm = gets.split(' ').map{ |x| x.to_i }\nmsum = m.inject{|sum,x| sum+x}\navg = msum / n\nans1 = 0\nfor iter in m\n if iter < avg\n ans1 += avg - iter\n end\nend\nputs ans1\n"}, {"source_code": "n = gets.to_i\nservers = gets.split.map(&:to_i)\nsum = servers.reduce(&:+)\nmin_load = sum/servers.length\ncount = 0\nfor server in servers\n if server < min_load\n count += min_load-server\n end\nend\n\nputs count\n"}, {"source_code": "n = gets.to_i\nservers = gets.split.map(&:to_i)\nsum = servers.reduce(&:+)\nmin_load = sum/servers.length\nextra = sum-(min_load*servers.length)\ncount = 0\nfor server in servers\n if server > min_load\n count += server-min_load\n end\nend\n\nputs count-extra\n"}, {"source_code": "n = gets.to_i\nservers = gets.split.map(&:to_i).sort.reverse\nsum = servers.reduce(&:+)\nmin_load = sum/servers.length\ncount = 0\nfor server in servers\n count += (server-min_load).abs\nend\n\nputs count/2\n"}, {"source_code": "\nm = Array.new\nn = gets.chomp.to_i\nt = gets.chomp.split(/ /)\nt.each {|u| m << u.to_i}\nm.sort!\n\ns = 0\nm.each {|t| s = s + t}\n\nhash = Hash.new\nif (s % n == 0)\n\thash[s / n] = n\nelse \n\thash[s/n] = n - s % n\n\thash[s/n+1] = s % n\nend\n\nm.each {|x| \n\tif hash.has_key? x \n\t\thash[x] = hash[x] - 1\n\t\tm.delete x\n\t\tif hash[x] == 0\n\t\t\thash.delete x\n\t\tend\n\tend\n}\n\nsec = 0\nif hash.size == 1\n\thash.each_key {|key| \n\t\tm.each {|m_i| \n\t\t\tsec = sec + (m_i - key).abs\n\t\t}\n\t}\n\tprint sec / 2\nelse\n\thash.each_key { |key|\n\t\tm.each {|m_i|\n\t\t\tif m_i < hash[s/n]\n\t\t\t\t\tsec = sec + (s/n - m_i).abs\n\t\t\t\t\thash[s/n] = hash[s/n] - 1\n\t\t\telsif hash[s/n + 1] > 0\n\t\t\t\tif m_i > hash[s/n + 1]\n\t\t\t\t\tsec = sec + (m_i - s/n + 1).abs\n\t\t\t\t\thash[s/n + 1] = hash[s/n + 1] - 1\n\t\t\t\tend\n\t\t\tend\n\t\t}\n\t}\n\tprint sec / 2\nend"}, {"source_code": "\nm = Array.new\nn = gets.chomp.to_i\nt = gets.chomp.split(/ /)\nt.each {|u| m << u.to_i}\nm.sort!\n\ns = 0\nm.each {|t| s = s + t}\n\nhash = Hash.new\nif (s % n == 0)\n\thash[s / n] = n\nelse \n\thash[s/n] = n - s % n\n\thash[s/n+1] = s % n\nend\n\nfor i in 0..m.size do\n\tif hash.has_key?(m[i]) && hash[m[i]] != 0 \n\t\thash[m[i]] = hash[m[i]] - 1\n\t\tif hash[m[i]] == 0\n\t\t\thash.delete m[i]\n\t\tend\n\t\tm[i] = 0\n\tend\nend\n\nsec = 0\nif hash.size == 1\n\thash.each_key {|key| \n\t\tif hash[key] != 0\n\t\t\tm.each {|m_i| \n\t\t\t\tif m_i != 0\n\t\t\t\t\tsec = sec + (m_i - key).abs\n\t\t\t\tend\n\t\t\t}\n\t\tend\n\t}\nelse\n\tm.each {|m_i|\n\t\tif m_i != 0\n\t\t\tif m_i < s/n\n\t\t\t\tsec = sec + (s/n - m_i).abs\n\t\t\t\thash[s/n] = hash[s/n] - 1\n\t\t\telsif hash[s/n + 1] > 0\n\t\t\t\tif m_i > s/n + 1\n\t\t\t\t\tsec = sec + (m_i - s/n - 1).abs\n\t\t\t\t\thash[s/n + 1] = hash[s/n + 1] - 1\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t}\nend\n\nprint sec / 2"}], "src_uid": "c0c29565e465840103a4af884f951cda"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\ncnt = Array.new(1e5+5,0)\na.map{|x| cnt[x]+=1}\n\ndp = Array.new(1e5+5,0)\n\ni = 1\nhi2 = 0\ndp[1] = cnt[1]\n(dp.length-2).times do\n i += 1\n hi2 = [hi2,dp[i-2]].max\n dp[i] = i * cnt[i] + hi2\nend\n\nputs dp.max\n", "positive_code": [{"source_code": "L=10**5\nn=gets.to_i\na=gets.split.map{|e| e.to_i}\nc=(0..L).map{0}\ndp=(0..L).map{0}\na.each{|e|\n\tc[e]=c[e]+e\n}\ndp[1]=c[1]\ndp[2]=c[2]\nans=[c[1],c[2]].max\n3.upto(L){|i|\n\tdp[i]=[dp[i-2],dp[i-3]].max+c[i]\n\tans=[dp[i],ans].max\n}\nputs ans"}, {"source_code": "def main\n gets\n seq = gets.split.map(&:to_i)\n puts max_score(seq)\nend\n\ndef max_score(sequence)\n count = Hash.new(0)\n sequence.each { |x| count[x] += 1 }\n nums = count.keys.sort\n\n # best[k] is the best Alex can do with the first k nums\n best = []\n best[0] = 0\n\n nums.each_index do |i|\n next_best = best.last\n if i > 0 && nums[i - 1] + 1 == nums[i]\n base = best[-2]\n else\n base = best[-1]\n end\n with_cur = base + nums[i] * count[nums[i]]\n next_best = with_cur if with_cur > next_best\n best << next_best\n end\n best.last\nend\n\nmain if __FILE__ == $0\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ns = Array.new(100002, 0)\nfor i in 0...a.size\n s[a[i]] += a[i]\nend\nfor i in 2..100001\n\ts[i] = [ s[i] + s[i - 2] , s[i - 1] ].max\nend\nputs s[100001]"}, {"source_code": "# Author : Fuad Ashraful Mehmet \n#Date: 18th April\n\nn=gets.to_i\na=gets.split.map(&:to_i)\nc=Array.new(a.max+1,0)\n\nfor i in 0...a.size\n c[a[i]]+=a[i]\n\nend\n\ndp=Array.new(c.size,0)\ndp[1]=c[1]\n\nfor i in 2...c.size\n dp[i]=[dp[i-2]+c[i],dp[i-1]].max\n\nend\n\nputs dp[c.size-1]"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\nh = Hash.new(0)\na.each do |v|\n h[v] += 1\nend\nkeys = h.keys.push(0).sort\n\nr = keys.size.times.map{ 0 }\nrw = keys.size.times.map{ 0 }\n\nkeys.each_with_index do |k, i|\n rw[i] = [r[i-1], rw[i-1]].max\n if keys[i-1] == k - 1\n r[i] = rw[i-1] + k*h[k]\n else\n r[i] = rw[i-1] > r[i-1] ? rw[i-1] : r[i-1]\n r[i] += k*h[k]\n end\nend\n\nputs [r.last, rw.last].max\n"}, {"source_code": "# def bore(arr)\t\n# \tpoi = []\n\n# \treturn 0 if arr.empty?\n# \tarr.uniq.each do |a|\n\t\t\n# \t\ti = arr.index(a)\t\t\n# \t \t@freq[a] = arr.count(a)\tunless @freq[a]\n# \t\tval = @freq[a]\n# \t\tpoi << (val * a) + bore( arr - [a,a+1,a-1])\t\t\n# \tend\n# \treturn poi.max\t\n# end\n\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\n@freq = Hash.new(0)\n\narr.each{|i| @freq[i] += 1}\n\none_count = @freq[1]\n\nf = []\n\nf[0] = 0\nf[1] = one_count\n\n\n(2..1000001).each do |i|\n\tf[i] = [f[i-1],f[i-2] + (@freq[i] * i)].max\t\nend\nputs f[-1]"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\narr.sort!\nj = 1\nuniq_array = []\nuniq_array[0] = arr[0]\nfrequency = Hash.new(0)\nfrequency[arr[0]] = 1\nwhile j < arr.length do \n if arr[j] != arr[j - 1] then\n uniq_array.push(arr[j])\n frequency[arr[j]] = 1\n else\n frequency[arr[j]] += 1\n end\n j += 1\nend\n# p uniq_array\n# p frequency\nresults = []\nresults[0] = uniq_array[0] * frequency[uniq_array[0]]\nif uniq_array.length > 1 then\n if uniq_array[1] - uniq_array[0] > 1 then\n results[1] = results[0] + uniq_array[1] * frequency[uniq_array[1]]\n else\n second_sum = uniq_array[1] * frequency[uniq_array[1]]\n results[1] = second_sum > results[0] ? second_sum : results[0]\n end\nend\ni = 2\nwhile i < uniq_array.length do \n if uniq_array[i] - uniq_array[i - 1] > 1 then\n results[i] = results[i - 1] + uniq_array[i] * frequency[uniq_array[i]]\n elsif results[i - 1] > uniq_array[i] * frequency[uniq_array[i]] + results[i - 2] then\n results[i] = results[i - 1]\n else\n results[i] = uniq_array[i] * frequency[uniq_array[i]] + results[i - 2]\n end \n i += 1\nend\nputs results.last"}, {"source_code": "def solution(arr)\n dp = Array.new(arr.max+2, 0)\n arr.each { |a| dp[a] += 1 }\n \n for i in 2...dp.size do\n dp[i] = [dp[i-2] + i*dp[i], dp[i-1]].max\n end\n dp.last\nend\n\nn = gets()\narr = gets.split.map(&:to_i)\n\nputs solution(arr)"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\narr.sort!\nj = 1\nuniq_array = []\nuniq_array[0] = arr[0]\nfrequency = Hash.new(0)\nfrequency[arr[0]] = 1\nwhile j < arr.length do \n if arr[j] != arr[j - 1] then\n uniq_array.push(arr[j])\n frequency[arr[j]] = 1\n else\n frequency[arr[j]] += 1\n end\n j += 1\nend\n# p uniq_array\n# p frequency\n\nprev = uniq_array[0] * frequency[uniq_array[0]]\nif uniq_array.length > 1 then\n if uniq_array[1] - uniq_array[0] > 1 then\n current = prev + uniq_array[1] * frequency[uniq_array[1]]\n else\n second_sum = uniq_array[1] * frequency[uniq_array[1]]\n current = second_sum > prev ? second_sum : prev\n end\nelse\n current = prev\nend\ni = 2\nwhile i < uniq_array.length do \n if uniq_array[i] - uniq_array[i - 1] > 1 then\n prev = current\n current += uniq_array[i] * frequency[uniq_array[i]]\n elsif current < uniq_array[i] * frequency[uniq_array[i]] + prev then\n temp = current\n current = uniq_array[i] * frequency[uniq_array[i]] + prev\n prev = temp\n else\n prev = current\n end \n i += 1\nend\nputs current"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = Array.new(a.max + 1, 0)\nfor i in 0...a.size\n c[a[i]] += a[i]\nend\n\ndp = Array.new(c.size, 0)\ndp[1] = c[1]\nfor i in 2...c.size\n dp[i] = [dp[i - 2] + c[i], dp[i - 1]].max\nend\nputs dp[c.size - 1]\n"}, {"source_code": "n = gets.to_i\na = gets.split.map{|i| i.to_i }\n\nb = Array.new(10**5 + 1, 0)\nd = Array.new(10**5 + 2, [0, 0])\n\na.each { |i| b[i]+=1 }\n\n(10**5).downto(1) do |i|\n d[i] = Array.new(2)\n d[i][0] = b[i] * i + d[i + 1][1]\n d[i][1] = d[i + 1].max\nend\n\nputs d[1].max\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = Array.new(a.max + 1, 0)\nfor i in 0...a.size\n c[a[i]] += a[i]\nend\n\ndp = Array.new(c.size, 0)\ndp[1] = c[1]\nfor i in 2...c.size\n dp[i] = [dp[i - 2] + c[i], dp[i - 1]].max\nend\nputs dp[c.size - 1]"}, {"source_code": "def calc (mas)\n pairs = {}\n mas.each_index { |i| mas[i]= mas[i].to_i}\n cur = mas[0]\n count = 0\n mas.each do |x|\n if x==cur\n count += 1\n else\n pairs[cur] = count\n cur = x\n count = 1\n end\n end\n pairs[cur] = count\n pairs\nend\nn = gets.to_i\na = gets.split(\" \")\na.sort_by! {|x| x.to_i}\nb = calc(a)\nbest1 = 0\nprev1 = -1\nbest2 = 0\nb.each_pair {|x,y|\n new_best2 = [best1,best2].max\n if x!=prev1+1\n new_best1 = [best2, best1].max + x*y\n else\n new_best1 = best2 + x*y\n end\n prev1 = x\n best1 = new_best1\n best2 = new_best2\n}\nputs [best1,best2].max"}, {"source_code": "gets\na=gets.split.map(&:to_i).sort\nh={}\na.each{|i|\n\th[i]=(!h[i] ? 1 : h[i] + 1)\n}\na.uniq!\nd=[0]*a.size\nd[0]=a[0]*h[a[0]]\na.each_with_index{|e,i|\n\tnext if i==0\n\td[i]=d[i-1]\n\ts=(i>1) ? d[i-2] : 0\n\ts=[s,d[i-1]].max if a[i] != a[i-1]+1\n\td[i]=[d[i], s+e*h[e]].max\n}\np d[-1]"}, {"source_code": "\ndef parse(s)\n nn = s.split.map(&:to_i)\n nn.group_by { |n| n }.reduce(Hash.new(0)) { |acc, (k, v)| acc[k] = v.reduce(:+); acc }\nend\n\ndef next_smallest_keys(ks, i)\n s1, s2 = 0\n j = i-1\n while j >= 0\n next_k = ks[j]\n if next_k < ks[i] - 1\n if s1.zero?\n s1 = next_k\n else\n s2 = next_k\n break\n end\n end\n j -= 1\n end\n [s1, s2]\nend\n\ndef get_max_points(m)\n ks = m.keys.sort\n t = Hash.new(0)\n ans = 0\n\n ks.each_with_index do |k, i|\n\n k1, k2 = next_smallest_keys(ks, i)\n v = m[k]\n t[k] = v + [t[k1], t[k2]].max\n ans = [ans, t[k]].max\n end\n\n ans\nend\n#input = '6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4'\n\nSTDIN.gets\ninput = STDIN.gets.chomp\n\nm = parse input\np get_max_points m\n"}, {"source_code": "def f(x)\n return 0 if x < 0\n $c[x]\nend\n\ndef n(x)\n return 0 unless $d.key?(x)\n $d[x]\nend\n\ngets\n\na = gets.split(' ').map(&:to_i).sort.reverse\n$d = Hash[a.group_by{|n|n}.map{|k, v|[k, v.size]}]\nm = a.first\n$c = [ 0 ]\n\n1.upto(m) do |i|\n $c.push([f(i-2) + i*n(i), f(i-1)].max)\nend\n\nputs $c.last\n"}], "negative_code": [{"source_code": "gets\na=gets.split.map(&:to_i).sort\nh={}\na.each{|i|\n\th[i]=(!h[i] ? 1 : h[i] + 1)\n}\na.uniq!\nd=[0]*a.size\nd[0]=a[0]*h[a[0]]\na.each_with_index{|e,i|\n\tnext if i==0\n\td[i]=d[i-1]\n\ts=(i>1) ? d[i-2] : 0\n\td[i]=[d[i], s+e*h[e]].max\n}\np d[-1]"}, {"source_code": "gets\na=gets.split.map(&:to_i).sort\nd=[0]*a.size\nd[0]=a[0]\na.each_with_index{|e,i|\n\tnext if i==0\n\td[i]=d[i-1]\n\ts=(i>1) ? d[i-2] : 0\n\td[i]=[d[i], s+e].max\n}\np d[-1]"}, {"source_code": "n=gets.to_i\na=gets.split.map{|e| e.to_i}\nc=(0..10**5).map{0}\ndp=(0..10**5).map{0}\na.each{|e|\n\tc[e]=c[e]+e\n}\na.sort!.uniq!\ndp[1]=c[1]\ndp[2]=c[2]\n3.upto(10**5){|i|\n\tdp[i]=[dp[i-2]+c[i],dp[i-3]+c[i]].max\n}\nputs dp[10**5]\n\n"}, {"source_code": "# def bore(arr)\t\n# \tpoi = []\n\n# \treturn 0 if arr.empty?\n# \tarr.uniq.each do |a|\n\t\t\n# \t\ti = arr.index(a)\t\t\n# \t \t@freq[a] = arr.count(a)\tunless @freq[a]\n# \t\tval = @freq[a]\n# \t\tpoi << (val * a) + bore( arr - [a,a+1,a-1])\t\t\n# \tend\n# \treturn poi.max\t\n# end\n\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\n# @freq = {}\n\n# puts bore(arr)\n@freq = Hash.new(0)\n\narr.uniq.each{|i| @freq[i] += 1}\n\none_count = @freq[1]\n\nf = []\n\nf[0] = 0\nf[1] = one_count\nmax = one_count\n\n(2..10000).each do |i|\n\tf[i] = [f[i-1],f[i-2] + (@freq[i] * i)].max \n\t\nend\nputs f[-1]"}, {"source_code": "# def bore(arr)\t\n# \tpoi = []\n\n# \treturn 0 if arr.empty?\n# \tarr.uniq.each do |a|\n\t\t\n# \t\ti = arr.index(a)\t\t\n# \t \t@freq[a] = arr.count(a)\tunless @freq[a]\n# \t\tval = @freq[a]\n# \t\tpoi << (val * a) + bore( arr - [a,a+1,a-1])\t\t\n# \tend\n# \treturn poi.max\t\n# end\n\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\n@freq = Hash.new(0)\n\narr.each{|i| @freq[i] += 1}\n\none_count = @freq[1]\n\nf = []\n\nf[0] = 0\nf[1] = one_count\n\n\n(2..10000).each do |i|\n\tf[i] = [f[i-1],f[i-2] + (@freq[i] * i)].max\t\nend\nputs f[-1]"}, {"source_code": "# def bore(arr)\t\n# \tpoi = []\n\n# \treturn 0 if arr.empty?\n# \tarr.uniq.each do |a|\n\t\t\n# \t\ti = arr.index(a)\t\t\n# \t \t@freq[a] = arr.count(a)\tunless @freq[a]\n# \t\tval = @freq[a]\n# \t\tpoi << (val * a) + bore( arr - [a,a+1,a-1])\t\t\n# \tend\n# \treturn poi.max\t\n# end\n\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\n# @freq = {}\n\n# puts bore(arr)\n@freq = Hash.new(0)\n\narr.uniq.each{|i| @freq[i] += i}\n\none_count = @freq[1]\n\nf = []\n\nf[0] = 0\nf[1] = one_count\nmax = one_count\n\n(2..10000).each do |i|\n\tf[i] = [f[i-1],f[i-2] + (@freq[i] * i)].max \n\t\nend\nputs f[-1]"}, {"source_code": "# def bore(arr)\t\n# \tpoi = []\n\n# \treturn 0 if arr.empty?\n# \tarr.uniq.each do |a|\n\t\t\n# \t\ti = arr.index(a)\t\t\n# \t \t@freq[a] = arr.count(a)\tunless @freq[a]\n# \t\tval = @freq[a]\n# \t\tpoi << (val * a) + bore( arr - [a,a+1,a-1])\t\t\n# \tend\n# \treturn poi.max\t\n# end\n\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\n# @freq = {}\n\n# puts bore(arr)\n@freq = Hash.new(0)\n\narr.each{|i| @freq[i] += 1}\n\none_count = @freq[1]\n\nf = []\n\nf[0] = 0\nf[1] = one_count\nmax = one_count\n\n(2..10000).each do |i|\n\tf[i] = [f[i-1],f[i-2] + (@freq[i] * i)].max \n\t\nend\nputs f[-1]"}, {"source_code": "# def bore(arr)\t\n# \tpoi = []\n\n# \treturn 0 if arr.empty?\n# \tarr.uniq.each do |a|\n\t\t\n# \t\ti = arr.index(a)\t\t\n# \t \t@freq[a] = arr.count(a)\tunless @freq[a]\n# \t\tval = @freq[a]\n# \t\tpoi << (val * a) + bore( arr - [a,a+1,a-1])\t\t\n# \tend\n# \treturn poi.max\t\n# end\n\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\n# @freq = {}\n# puts bore(arr)\n@freq = {}\n\n# (1..10000).each{|i| @freq[i] = arr.count(i)}\none_count = arr.count(1)\nf = Hash.new(0)\n\nf[0] = 0\nf[1] = one_count\nmax = one_count\n\narr.sort.uniq.each do |i|\n\tf[i] = [f[i-1],f[i-2] + (arr.count(i) * i)].max \n\tmax = f[i] if f[i] > max\nend\n# puts f.max\nputs max"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort.uniq\nc = Array.new(b.max + 1, 0)\nfor i in 0...b.size\n c[b[i]] = b[i] * a.count(b[i])\nend\n\ns = Array.new(b.max + 1, 0)\ns[0] = 1\nfor i in 1...c.size - 1\n if c[i] >= c[i - 1] + c[i + 1]\n s[i - 1] = 0\n s[i + 1] = 0\n s[i] = 1\n else\n s[i - 1] = 1 if s[i - 2] == 0\n s[i + 1] = 1\n s[i] = 0\n end\nend\nans = 0\nfor i in 0...c.size\n ans += c[i] * s[i]\nend\np ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort.uniq\nc = Array.new(b.max + 1, 0)\nfor i in 0...b.size\n c[b[i]] = b[i] * a.count(b[i])\nend\n\ns = Array.new(b.max + 1, 0)\nans = c[1]\nfor i in 2...c.size\n if ans + c[i] - c[i - 1] > ans\n s[i] = 1\n ans += c[i] - c[i - 1]\n if s[i - 2] == 0 && s[i - 3] == 0 && c[i - 2] > 0\n ans += c[i - 2]\n s[i - 2] = 1\n end\n end\nend\np ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort.uniq\nc = Array.new(b.max + 1, 0)\nfor i in 0...b.size\n c[b[i]] = b[i] * a.count(b[i])\nend\n\ns = Array.new(b.max + 1, 0)\ns[0] = 0\nfor i in 1...c.size - 1\n if c[i] >= c[i - 1] + c[i + 1]\n s[i - 1] = 0\n s[i + 1] = 0\n s[i] = 1\n else\n s[i - 1] = 1 if s[i - 2] == 0\n s[i + 1] = 1\n s[i] = 0\n end\nend\ns[0] = 0\nfor i in 1...c.size\n s[i] = 1 if s[i - 1] == 0 && s[i + 1] == 0\nend\nans = 0\nfor i in 0...c.size\n ans += c[i] * s[i]\nend\np ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort.uniq\nc = Array.new(b.max + 1, 0)\nfor i in 0...b.size\n c[b[i]] = b[i] * a.count(b[i])\nend\n\ns = Array.new(b.max + 1, 0)\ns[0] = 1\nfor i in 1...c.size - 1\n if c[i] >= c[i - 1] + c[i + 1]\n s[i - 1] = 0\n s[i + 1] = 0\n s[i] = 1\n else\n s[i - 1] = 1\n s[i + 1] = 1\n s[i] = 0\n end\nend\nans = 0\nfor i in 0...c.size\n ans += c[i] * s[i]\nend\np ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = a.sort.uniq\nc = Array.new(b.max + 1, 0)\nfor i in 0...b.size\n c[b[i]] = b[i] * a.count(b[i])\nend\n\ns = Array.new(b.max + 1, 0)\ns[0] = 1\nfor i in 1...c.size - 1\n if c[i] >= c[i - 1] + c[i + 1]\n s[i - 1] = 0\n s[i + 1] = 0\n s[i] = 1\n else\n s[i - 1] = 1 if s[i - 2] == 0\n s[i + 1] = 1\n s[i] = 0\n end\n p s\nend\np s\np c\nans = 0\nfor i in 0...c.size\n ans += c[i] * s[i]\nend\np ans\n"}, {"source_code": "# Hypothesis\n# choose the most popular number\n# if popularity is equal,\n# take the largest number\ndef step(ak, sequence)\n sequence.delete_at(sequence.index(ak))\n sequence.select do |a|\n a != ak + 1 && a != ak - 1\n end\nend\n\ndef get_next_pick(sequence)\n freq = sequence.inject(Hash.new(0)) { |h, v| h[v] += 1; h }\n if freq.values.uniq.length == 1\n sequence.max\n else\n sequence.max_by { |v| freq[v] }\n end\nend\n\ndef simulate(input)\n sequence = input.split.map(&:to_i)\n score = 0\n until sequence.length == 0\n next_pick = get_next_pick(sequence)\n score += next_pick\n sequence = step(next_pick, sequence)\n end\n score\nend\n\n#input = '1 2'\n#score = simulate(input)\n#p \"#{input}: #{score}\"\n#\n#input = '1 2 3'\n#score = simulate(input)\n#p \"#{input}: #{score}\"\n#\n#input = '1 2 1 3 2 2 2 2 3'\n#score = simulate(input)\n#p \"#{input}: #{score}\"\n\ninput = gets.chomp\np input\ninput = gets.chomp\nsimulate(input)\n\n"}, {"source_code": "# Hypothesis\n# choose the most popular number\n# if popularity is equal,\n# take the largest number\ndef step(ak, sequence)\n sequence.delete_at(sequence.index(ak))\n sequence.select do |a|\n a != ak + 1 && a != ak - 1\n end\nend\n\ndef get_next_pick(sequence)\n freq = sequence.inject(Hash.new(0)) { |h, v| h[v] += 1; h }\n if freq.values.uniq.length == 1\n sequence.max\n else\n sequence.max_by { |v| freq[v] }\n end\nend\n\ndef simulate(input)\n sequence = input.split.map(&:to_i)\n score = 0\n until sequence.length == 0\n next_pick = get_next_pick(sequence)\n score += next_pick\n sequence = step(next_pick, sequence)\n end\n score\nend\n\ninput = gets.chomp\nsimulate(input)\n"}, {"source_code": "# Hypothesis\n# choose the most popular number\n# if popularity is equal,\n# take the largest number\ndef step(ak, sequence)\n sequence.delete_at(sequence.index(ak))\n sequence.select do |a|\n a != ak + 1 && a != ak - 1\n end\nend\n\ndef get_next_pick(sequence)\n freq = sequence.inject(Hash.new(0)) { |h, v| h[v] += 1; h }\n if freq.values.uniq.length == 1\n sequence.max\n else\n sequence.max_by { |v| freq[v] }\n end\nend\n\ndef simulate(a)\n sequence = a\n score = 0\n until sequence.length == 0\n next_pick = get_next_pick(sequence)\n score += next_pick\n sequence = step(next_pick, sequence)\n end\n score\nend\n\nwhile STDIN.gets\n a = $_.split.map(&:to_i)\n if a.length > 1\n puts simulate(a)\n end\nend\n"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i).sort.reverse\nb = a.uniq.map { |x| [x, a.count{ |y| y == x } ] }.sort do |x, y|\n y.last != x.last ? y.last <=> x.last : y.first <=> x.first\nend\nc = Hash[ b ]\n\nputs(\n b.map do |elm|\n res = [elm.last, c[elm.first]].min\n c[elm.first-1] = [0, c[elm.first-1]-res].max if c.key?(elm.first-1)\n c[elm.first+1] = [0, c[elm.first+1]-res].max if c.key?(elm.first+1)\n c[elm.first] = 0\n\n res*elm.first\n end.inject(&:+)\n)\n"}, {"source_code": "n = gets.to_i\na = gets.split.map{|i| i.to_i }\n\nb = Array.new(10**5 + 1, 0)\nd = Array.new(10**5 + 2, [0, 0])\n\na.each { |i| b[i]+=1 }\n\n(100).downto(1) do |i|\n d[i] = Array.new(2)\n d[i][0] = b[i] * i + d[i + 1][1]\n d[i][1] = d[i + 1].max\nend\n\nputs d[1].max\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort.reverse\n\n#p a\n\nprv = 1e6\nscore = 0\nn.times do\n x = a.shift\n if x < prv - 1\n score += x\n prv = x\n end\nend\n\nputs score\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\ncnt = Array.new(1e5+5,0)\na.map{|x| cnt[x]+=1}\n\ndp = Array.new(1e5+5,0)\n\ni = 1\nhi2 = 0\n(dp.length-2).times do\n i += 1\n hi2 = [hi2,dp[i-2]].max\n dp[i] = i * cnt[i] + hi2\nend\n\nputs dp.max\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\nh = Hash.new(0)\na.each do |v|\n h[v] += 1\nend\nkeys = h.keys.push(0).sort\n\nr = keys.size.times.map{ 0 }\nrw = keys.size.times.map{ 0 }\n\nkeys.each_with_index do |k, i|\n rw[i] = r[i-1]\n if keys[i-1] == k - 1\n r[i] = rw[i-1] + k*h[k]\n else\n r[i] = rw[i-1] > r[i-1] ? rw[i-1] : r[i-1]\n r[i] += + k*h[k]\n end\nend\n\nputs [r[keys.last], rw[keys.last]].max\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\nh = Hash.new(0)\na.each do |v|\n h[v] += 1\nend\nr = n.times.map{ 0 }\n\nkeys = h.keys.push(0).sort\nkeys.each_with_index do |k, i|\n r[i] = r[i-1]\n prev_key = keys[i-1]\n prev_score = h[prev_key]*prev_key\n score = h[k]*k\n if prev_key == k-1\n if score > prev_score\n r[i] += score - prev_score\n if keys[i-1] == keys[i-2] + 1\n r[i]+= r[i-2]\n end\n end\n else\n r[i] += h[k]*k\n end\nend\n\nputs r[keys.last]\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\nh = Hash.new(0)\na.each do |v|\n h[v] += 1\nend\nkeys = h.keys.push(0).sort\n\nr = keys.size.times.map{ 0 }\nrw = keys.size.times.map{ 0 }\n\nkeys.each_with_index do |k, i|\n rw[i] = r[i-1]\n if keys[i-1] == k - 1\n r[i] = rw[i-1] + k*h[k]\n else\n r[i] = rw[i-1] > r[i-1] ? rw[i-1] : r[i-1]\n r[i] += + k*h[k]\n end\nend\n\nputs [r.last, rw.last].max\n"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\narr.sort!\nfrequency = arr.inject({}){|freq, elem| freq.merge(elem => arr.count(elem))}\narr.uniq!\n# p arr\n# p frequency\nresults = []\nresults[0] = arr[0] * frequency[arr[0]]\nif arr.length > 1 then\n second_sum = arr[1] * frequency[arr[1]]\n results[1] = second_sum > results[0] ? second_sum : results[0]\nend\ni = 2\nwhile i < arr.length do \n if arr[i] - arr[i - 1] > 1 then\n results[i] = results[i - 1] + arr[i] * frequency[arr[i]]\n elsif results[i - 1] > arr[i] * frequency[arr[i]] + results[i - 2] then\n results[i] = results[i - 1]\n else\n results[i] = arr[i] * frequency[arr[i]] + results[i - 2]\n end \n i += 1\nend\nputs results.last"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\narr.sort!\nfrequency = arr.inject({}){|freq, elem| freq.merge(elem => arr.count(elem))}\narr.uniq!\n# p arr\n# p frequency\nresults = []\nresults[0] = arr[0] * frequency[arr[0]]\nresults[1] = arr[1] * frequency[arr[1]] if arr.length > 1\ni = 2\nwhile i < arr.length do \n if arr[i] - arr[i - 1] > 1 then\n results[i] = results[i - 1] + arr[i] * frequency[arr[i]]\n elsif results[i - 1] > arr[i] * frequency[arr[i]] + results[i - 2] then\n results[i] = results[i - 1]\n else\n results[i] = arr[i] * frequency[arr[i]] + results[i - 2]\n end \n i += 1\nend\nputs results.last"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\narr.sort!\nj = 1\nuniq_array = []\nuniq_array[0] = arr[0]\nfrequency = Hash.new(0)\nfrequency[arr[0]] = 1\nwhile j < arr.length do \n if arr[j] != arr[j - 1] then\n uniq_array.push(arr[j])\n frequency[arr[j]] = 1\n else\n frequency[arr[j]] += 1\n end\n j += 1\nend\n# p uniq_array\n# p frequency\n\nprev = uniq_array[0] * frequency[uniq_array[0]]\nif uniq_array.length > 1 then\n if uniq_array[1] - uniq_array[0] > 1 then\n current = prev + uniq_array[1] * frequency[uniq_array[1]]\n else\n second_sum = uniq_array[1] * frequency[uniq_array[1]]\n current = second_sum > prev ? second_sum : prev\n end\nend\ni = 2\nwhile i < uniq_array.length do \n if uniq_array[i] - uniq_array[i - 1] > 1 then\n current = current + uniq_array[i] * frequency[uniq_array[i]]\n elsif current <= uniq_array[i] * frequency[uniq_array[i]] + prev then\n current = uniq_array[i] * frequency[uniq_array[i]] + prev\n end \n i += 1\nend\nputs current"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\narr.sort!\nj = 1\nuniq_array = []\nuniq_array[0] = arr[0]\nfrequency = Hash.new(0)\nfrequency[arr[0]] = 1\nwhile j < arr.length do \n if arr[j] != arr[j - 1] then\n uniq_array.push(arr[j])\n frequency[arr[j]] = 1\n else\n frequency[arr[j]] += 1\n end\n j += 1\nend\n# p uniq_array\n# p frequency\n\nprev = uniq_array[0] * frequency[uniq_array[0]]\nif uniq_array.length > 1 then\n if uniq_array[1] - uniq_array[0] > 1 then\n current = prev + uniq_array[1] * frequency[uniq_array[1]]\n else\n second_sum = uniq_array[1] * frequency[uniq_array[1]]\n current = second_sum > prev ? second_sum : prev\n end\nend\ni = 2\nwhile i < uniq_array.length do \n if uniq_array[i] - uniq_array[i - 1] > 1 then\n prev = current\n current += uniq_array[i] * frequency[uniq_array[i]]\n elsif current < uniq_array[i] * frequency[uniq_array[i]] + prev then\n temp = current\n current = uniq_array[i] * frequency[uniq_array[i]] + prev\n prev = temp\n else\n prev = current\n end \n i += 1\nend\nputs current"}, {"source_code": "n = gets.to_i\narr = gets.split.map { |x| x.to_i }.sort\nhash = Hash.new(0)\narr.each { |x| hash[x] += 1 }\nhash = Hash[hash.sort_by { |key,value| value }]\nsum = 0\nwhile hash.size != 0\n temp = hash[hash.keys.last]\n sum += temp * hash.keys.last\n temp_key = hash.keys.last\n hash.delete(temp_key)\n hash.delete(temp_key - 1)\n hash.delete(temp_key + 1)\nend\nputs sum\n"}], "src_uid": "41b3e726b8146dc733244ee8415383c0"} {"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n a=gets.split.map(&:to_i)\r\n s,t=[a.index(a.min),a.index(a.max)].sort\r\n puts [t+1,n-s,s+1+n-t].min\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n mn, mx = a.index(a.min), a.index(a.max)\r\n puts [[mn, mx].max + 1, n - [mn, mx].min, n - mn + mx + 1, n - mx + mn + 1].min\r\nend"}, {"source_code": "t = gets.to_i\r\nfor i in 0...t\r\n\tn = gets.to_i\r\n\ta = gets.split.map(&:to_i)\r\n\tx, y = [a.index(a.min), a.index(a.max)].sort\r\n\tputs [y + 1, n - x, x + 1 + n - y].min\r\nend"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n mn, mx = a.index(a.min), a.index(a.max)\r\n puts [[mn, mx].max + 1, n - [mn, mx].min, n - mn + mx + 1, n - mx + mn - 1].min\r\nend"}], "src_uid": "d5fc2bc618dd9d453a5e7ae30ccb73f3"} {"source_code": "n = gets.chomp.to_i\n\nratings = []\n\nn.times do\n a, b = gets.chomp.split(\" \").map(&:to_i)\n if a != b then\n puts \"rated\"\n exit\n else\n ratings << b\n end\nend\n\n(n-1).times do |i|\n if ratings[i] < ratings[i+1] then\n puts \"unrated\"\n exit\n end\nend\nputs \"maybe\"", "positive_code": [{"source_code": "n=gets.to_i\na=[]\nb=[]\nrated=false\nn.times do\n x, y=gets.split.map &:to_i\n a<0? \"NO\" : \"YES\"\n", "positive_code": [{"source_code": "p = 0\nn = gets.to_i\n\na = gets.split.map &:to_i\ns = false\na.each do |i|\n if i < p\n s = true\n break\n elsif i%2 != p\n p = 1\n elsif i%2 == p\n p = 0\n end\nend\n\nif s or p > 0\n puts \"NO\"\nelse\n puts \"YES\"\nend"}, {"source_code": "r=0\ngets;gets.split.map(&:to_i).each{|e|\nbreak if r>e\nr^=e%2\n}\nputs [:YES,:NO][r]"}, {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\nas.each_with_index do |a, i|\n if a < 0 || a.odd? && i == n - 1\n puts 'NO'\n exit\n end\n if a.odd?\n as[i + 1] -= 1\n end\nend\nputs 'YES'\n"}, {"source_code": "n=gets.to_i-2\na=gets.split.map &:to_i\n\nres=\"YES\"\nfor i in 0..n\n if a[i]<0\n res=\"NO\"\n break\n end\n\n if a[i].odd?\n a[i]-=1\n a[i+1]-=1\n end\nend\nres=\"NO\" if a[-1].odd?\n\nputs res\n"}, {"source_code": "n=gets.to_i-1\na=gets.split.map &:to_i\n\nn.times { |i|\n if a[i].odd?\n a[i] -= 1\n a[i+1] -= 1\n end\n (puts 'NO'; exit) if a[i] < 0\n}\nputs (a[n].even?)?'YES':'NO'\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nk = 0\na.each do |x| \n break if x-k<0\n k = (x-k)%2\nend\nputs k>0 ? \"NO\" : \"YES\""}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\n\ndef meow(n, a)\n n.times do |i|\n return false if a[i] < 0\n if a[i].odd?\n return false if i == n - 1\n a[i + 1] -= 1\n end\n end\nend\n\nputs meow(n, a) ? 'YES' : 'NO'\n"}, {"source_code": "n = gets.to_i\na = gets.strip.split(' ').map(&:to_i)\nflag = false\n0.upto(n - 1) do |i|\n if flag\n if a[i] == 0\n break\n else\n a[i] -= 1\n flag = !flag\n end\n end\n \n if a[i] % 2 == 1\n flag = !flag\n else\n if flag == true\n break\n end\n end\nend\n\nprintf(\"%s\\n\", flag ? \"NO\" : \"YES\")\n"}, {"source_code": "require 'set'\n\nparse_int = lambda {gets.split.map{|x| x.to_i}}\n\n\ngets \npz = parse_int.call\n\n(pz.length-1).times do |i|\n if pz[i].odd?\n if pz[i+1]>0\n pz[i] -= 1\n pz[i+1] -= 1\n else\n puts 'NO'\n exit\n end\n end\nend\n\n\n \nputs pz[-1].even? ? 'YES' : \"NO\"\n"}], "negative_code": [{"source_code": "p = 0\nn = gets.to_i\n\na = gets.split.map &:to_i\ns = false\na.each do |i|\n if i == p + 1\n p = 1\n elsif i == p+2 or i == p\n p = 0\n else\n s = true\n break\n end\nend\n\nif s or p > 0\n puts \"NO\"\nelse\n puts \"YES\"\nend"}, {"source_code": "p = 0\nn = gets.to_i\n\na = gets.split.map &:to_i\ns = false\na.each do |i|\n if i == p + 1\n p = 1\n elsif i == p+2\n p = 0\n elsif i != p\n puts \"NO\"\n s = true\n break\n end\nend\n\nputs \"YES\" unless s"}, {"source_code": "r=0\ngets.split.map(&:to_i).each{|e|\nbreak if r>e\nr^=e%2\n}\nputs [:YES,:NO][r]"}, {"source_code": "r=0\ngets.split.map(&:to_i).each{|e|\nbreak if e>r\nr^=e%2\n}\nputs [:YES,:NO][r]"}, {"source_code": "n = gets.to_i\na = gets.split(\" \").map(&:to_i)\nans = 0\na.each do |e|\n break if (ans < e)\n ans = (e - ans)%2\nend\nprint ans>0? \"NO\" : \"YES\"\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nk = 0\na.each { |x| k = (x-k)%2 }\nputs k>0 ? \"NO\" : \"YES\""}], "src_uid": "97697eba87bd21ae5c979a5ea7a81cb7"} {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*n\nn.times{|i|\n\tmx=0\n\tm.times{|j|\n\t\tmx=[mx,d[j]].max if a[i]>b[j]\n\t\tq[i]=d[j]=mx+1 if a[i]==b[j]\n\t}\n\ti.times{|j|p[i]=j if a[j]=0 and q[i]>0\np q.max\nputs l.reverse.join \" \"\n\n", "positive_code": [{"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*n\nn.times{|i|\n\tmx=0\n\tm.times{|j|\n\t\tmx=[mx,d[j]].max if a[i]>b[j]\n\t\tq[i]=d[j]=mx+1 if a[i]==b[j]\n\t}\n\ti.times{|j|p[i]=j if a[j]=0 and q[i]>0\np q.max\nputs l.reverse.join \" \"\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*n\nn.times{|i|\n\tmx=0\n\tm.times{|j|\n\t\tmx=[mx,d[j]].max if a[i]>b[j]\n\t\tq[i]=d[j]=mx+1 if a[i]==b[j]\n\t}\n\ti.times{|j|p[i]=j if a[j]=0 and q[i]>0\np q.max\nputs l.reverse.join \" \""}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*n\nn.times{|i|\n\tmx=0\n\tm.times{|j|\n\t\tmx=[mx,d[j]].max if a[i]>b[j]\n\t\tq[i]=d[j]=mx+1 if a[i]==b[j]\n\t}\n\ti.times{|j|p[i]=j if a[j]=0 and q[i]>0\np q.max\nputs l.reverse.join \" \"\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*n\nn.times{|i|\n\tmx=0\n\tm.times{|j|\n\t\tmx=[mx,d[j]].max if a[i]>b[j]\n\t\tq[i]=d[j]=mx+1 if a[i]==b[j]\n\t}\n\ti.times{|j|p[i]=j if a[j]=0 and q[i]>0\np q.max\nputs l.reverse.join \" \"\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*n\nn.times{|i|\n\tmx=0\n\tm.times{|j|\n\t\tmx=[mx,d[j]].max if a[i]>b[j]\n\t\tq[i]=d[j]=mx+1 if a[i]==b[j]\n\t}\n\ti.times{|j|p[i]=j if a[j]=0 and q[i]>0\np q.max\nputs l.reverse.join \" \"\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*n\nn.times{|i|\n\tmx=0\n\tm.times{|j|\n\t\tmx=[mx,d[j]].max if a[i]>b[j]\n\t\tq[i]=d[j]=mx+1 if a[i]==b[j]\n\t}\n\ti.times{|j|p[i]=j if a[j]=0 and q[i]>0\np q.max\nputs l.reverse.join \" \"\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*n\nn.times{|i|\n\tmx=0\n\tm.times{|j|\n\t\tmx=[mx,d[j]].max if a[i]>b[j]\n\t\tq[i]=d[j]=mx+1 if a[i]==b[j]\n\t}\n\ti.times{|j|p[i]=j if a[j]=0 and q[i]>0\np q.max\nputs l.reverse.join \" \"\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*n\nn.times{|i|\n\tmx=0\n\tm.times{|j|\n\t\tmx=[mx,d[j]].max if a[i]>b[j]\n\t\tq[i]=d[j]=mx+1 if a[i]==b[j]\n\t}\n\ti.times{|j|p[i]=j if a[j]=0 and q[i]>0\np q.max\nputs l.reverse.join \" \"\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*n\nn.times{|i|\n mx=0\n m.times{|j|\n mx=[mx,d[j]].max if a[i]>b[j]\n q[i]=d[j]=mx+1 if a[i]==b[j]\n }\n i.times{|j|p[i]=j if a[j]=0 and q[i]>0\np q.max\nputs l.reverse.join \" \""}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*n\nn.times{|i|\n\tmx=0\n\tm.times{|j|\n\t\tmx=[mx,d[j]].max if a[i]>b[j]\n\t\tq[i]=d[j]=mx+1 if a[i]==b[j]\n\t}\n\ti.times{|j|p[i]=j if a[j]=0 and q[i]>0\np q.max\nputs l.reverse.join \" \"\n"}], "negative_code": [{"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nm=gets.to_i\nb=gets.split.map &:to_i\nd=[0]*m\nq=[0]*n\np=[-1]*m\nn.times{|i|\n\tmx=0\n\tm.times{|j|\n\t\tmx=[mx,d[j]].max if a[i]>b[j]\n\t\tq[i]=d[j]=mx+1 if a[i]==b[j]\n\t}\n\ti.times{|j|p[i]=j if a[j]=0\np q.max\nputs l.reverse.join \" \"\n"}], "src_uid": "dca6eee27f002413d5e2eaf28fd60750"} {"source_code": "def solve\n str = gets.strip\n cur = 0\n h = Hash.new()\n str.each_char.with_index { |e, i|\n if e == '+'\n cur += 1\n else\n cur -= 1\n if cur < 0 && !h.has_key?(-cur)\n h[-cur] = i + 1\n end\n end\n }\n res = 0\n (0..str.size).each { |i|\n ck = h[i + 1] if h.has_key?(i + 1)\n if ck.nil?\n res += str.size\n break\n else\n res += ck\n end\n }\n puts res\nend\n\ngets.strip.to_i.times { solve }\n", "positive_code": [{"source_code": "def solve\n str = gets.strip\n cur = 0\n h = Hash.new(0)\n str.each_char.with_index { |e, i|\n if e == '+'\n cur += 1\n else\n cur -= 1\n if cur < 0 && h[-cur].zero?\n h[-cur] = i + 1\n end\n end\n }\n res = 0\n (0..str.size).each { |i|\n ck = h[i + 1]\n if ck.zero?\n res += str.size\n break\n else\n res += ck\n end\n }\n puts res\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "t = gets.to_i\nt.times do\n a = []\n b = {}\n cur = 0\n gets.each_char.with_index do |c, i|\n \n case c\n when '+'\n a << (cur += 1)\n when '-'\n a << (cur -= 1)\n else\n a << cur\n end\n \n b[cur] = i + 1 unless b.include? cur\n end\n \n res = 0\n init = 0\n loop do\n \n if b.include?(-init-1)\n res += b[-init-1]\n else\n res += a.size - 1\n break\n end\n \n init += 1\n end\n \n p res\nend\n"}, {"source_code": "def solve\n str = gets.strip\n cur = 0\n h = Hash.new(0)\n str.each_char.with_index { |e, i|\n if e == '+'\n cur += 1\n else\n cur -= 1\n if cur < 0 && h[-cur].zero?\n h[-cur] = i + 1\n end\n end\n }\n res = 0\n (0..str.size).each { |i|\n ck = h[i + 1]\n if ck.zero?\n res += str.size\n break\n else\n res += ck\n end\n }\n puts res\nend\n\ngets.strip.to_i.times { solve }\n"}], "negative_code": [{"source_code": "def solve\n str = gets.strip\n cur = 0\n h = Hash.new(0)\n str.each_char.with_index { |e, i|\n if e == '+'\n cur += 1\n else\n cur -= 1\n if cur < 0 && h[-cur].zero?\n h[-cur] = i + 1\n end\n end\n }\n res = 0\n (0..str.size).each { |i|\n ck = h[i + 1]\n if ck.zero?\n res += str.size\n break\n else\n res += h[ck]\n end\n }\n puts res\nend\n\ngets.strip.to_i.times { solve }\n"}, {"source_code": "def solve\n str = gets.strip\n cur = 0\n h = Hash.new(1e7 + 1)\n a = []\n str.each_char.with_index { |e, i|\n if e == '+'\n cur += 1\n else\n cur -= 1\n if cur < 0\n h[-cur] = [h[-cur], i + 1].min\n a << -cur\n end\n end\n }\n res = 0\n (0..str.size).each { |i|\n ck = a.bsearch { |x| x > i}\n if ck.nil?\n res += str.size\n break\n else\n res += h[ck]\n end\n }\n puts res\nend\n\ngets.strip.to_i.times { solve }\n"}, {"source_code": "def solve\n str = gets.strip\n cur = 0\n h = Hash.new(0)\n str.each_char.with_index { |e, i|\n if e == '+'\n cur += 1\n else\n cur -= 1\n if cur < 0 && h[-cur].nil?\n h[-cur] = i + 1\n end\n end\n }\n res = 0\n (0..str.size).each { |i|\n ck = h[i + 1]\n if ck.zero?\n res += str.size\n break\n else\n res += h[ck]\n end\n }\n puts res\nend\n\ngets.strip.to_i.times { solve }\n"}], "src_uid": "07eecfe948aa78623586b5e30e84e415"} {"source_code": "gets.to_i.times {\n a, b = gets.split.map { |v| v.to_i }\n\n if a == b\n puts 0\n elsif a < b\n puts 2 - (b - a) % 2\n else\n puts 1 + (b - a) % 2\n end\n}\n", "positive_code": [{"source_code": "# cook your code here\nt = gets.to_i\nuntil t == 0\n t-=1\n x,y = gets.chomp.split().map { |e| e.to_i }\n if(x == y)\n puts \"0\"\n elsif(x > y)\n if((x-y)%2 == 0)\n puts \"1\"\n else\n puts \"2\"\n end\n else\n if((y-x)%2 == 1)\n puts \"1\"\n else\n puts \"2\"\n end\n end\nend"}, {"source_code": "t = gets.chomp.to_i\n\nuntil t==0\n t-=1\n x, y = gets.split.map(&:to_i)\n if(x>y && (x-y)%2!=0)\n puts 2\n elsif(x>y && (x-y)%2==0)\n puts 1\n elsif(x 0\n k = gets.split(\" \")\n a = k[0].to_i\n b = k[1].to_i\n \n if a == b\n puts 0\n elsif a > b\n if a % 2 != b % 2\n puts 2\n else\n puts 1\n end\n else\n if a % 2 != b % 2\n puts 1\n else\n puts 2\n end\n end\n t -= 1\nend\n"}, {"source_code": "require 'set'; require 'prime'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n a,b = gets.chomp.split.map(&:to_i)\n if a < b\n if (b-a).odd?\n puts 1\n else\n puts 2\n end\n elsif a > b\n if (a-b).even?\n puts 1\n else\n puts 2\n end\n else\n puts 0\n end\nend\n"}, {"source_code": "N = gets.to_i\nN.times do \n a,b = gets.split.map(&:to_i)\n f = b - a;\n ans = 0\n if f == 0\n ans = 0\n elsif f<0 && f.odd?\n ans = 2\n elsif f<0 && f.even?\n ans = 1\n elsif f>0 && f.odd?\n ans = 1\n elsif f>0 && f.even?\n ans = 2\n end\n puts ans\nend"}, {"source_code": "n=gets.to_i\n(1..n).each do |x|\n a,b=gets.chomp.split(\" \").map(&:to_i)\n if a == b\n print(\"0\\n\")\n elsif a > b && (a - b) % 2 == 0\n \tprint(\"1\\n\")\n elsif a > b && (a - b) % 2 == 1\n \tprint(\"2\\n\")\n elsif a < b && (b - a) % 2 == 0\n \tprint(\"2\\n\")\n elsif a < b && (b - a) % 2 == 1\n \tprint(\"1\\n\")\n end\nend"}, {"source_code": "def gli\n gets.split.map(&:to_i)\nend\n\nn = gets.to_i\nn.times {\n a, b = gli\n\n if a < b\n if (a - b) % 2 == 1\n puts 1\n else\n puts 2\n end\n elsif a == b\n puts 0\n else\n if (b - a) % 2 == 1\n puts 2\n else\n puts 1\n end\n end\n}\n"}, {"source_code": "def input_line \n gets.split.map(&:to_i) \nend\n\nn = gets.to_i\n\nn.times do |l|\n a, b = input_line\n if a == b then\n puts 0\n elsif a > b\n puts (b - a).even? ? 1 : 2\n else\n puts (a - b).even? ? 2 : 1\n end\nend"}, {"source_code": "gets.to_i.times do\n a, b = gets.split.map &:to_i\n d = a - b\n if d == 0\n puts 0\n elsif d%2 == 0\n puts d > 0 ? 1 : 2\n else\n puts d < 0 ? 1 : 2\n end\nend\n"}, {"source_code": "1.upto(gets.to_i) do\n a, b = gets.split(' ').map(&:to_i)\n result = (b-a).zero? ? 0 : 2 - (b-a).modulo(2) \n\n result = 3 - result if (b - a) < 0\n\n puts result\nend\n"}, {"source_code": "t = gets.to_i\n(1).upto(t) do\n a = gets.split(' ').map(&:to_i)\n answer = 2\n if(a[0]a[1] and (a[0]-a[1]).modulo(2) == 0)\n answer=1\n elsif a[0]==a[1]\n answer=0\n end\n puts answer\nend\n"}], "negative_code": [], "src_uid": "fcd55a1ca29e96c05a3b65b7a8103842"} {"source_code": "def run\n n, m = $stdin.gets.split.map(&:to_i)\n a = []\n n.times do |i|\n a << $stdin.gets.chomp\n end\n\n ans = n\n flag = true\n cur = n\n while flag\n if cur % 2 == 0\n cur = cur / 2\n else\n ans = cur\n break\n end\n\n cur.times do |i|\n if a[i] != a[cur * 2 - 1 - i]\n flag = false\n ans = cur * 2\n break\n end\n end\n end\n\n puts ans\nend\n\nrun if $0 == __FILE__\n", "positive_code": [{"source_code": "\n\n#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')\n#$stdout.reopen('/home/chen/Desktop/output.txt', 'w')\n\n\ndef min(a)\n\tf = 1\n\ts = 0\n\ta.each do |e|\n\t\tif f\n\t\t\ts=e\n\t\t\tf=0\n\t\telse\n\t\t\ts=e if e < s\t\t\n\t\tend\n\tend\n\ts\nend\n\n\n\ndef solve(ib,ie,j,a)\n\tif (ie-ib+1)%2 !=0\n\t\treturn 0\n\tend\n\tb ,e = ib, ie\n\twhile e>b\n\t\tif a[e][j] != a[b][j]\n\t\t\treturn 0\n\t\tend\n\t\tb+=1\n\t\te-=1\n\tend\n\n\treturn solve(ib, (ib+ie)/2,j,a)+1\nend\n\nn,m = gets.split.map(&:to_i)\na = [0]*n\nans = [0]*m\n\n(1..n).each do |i|\n\ta[i-1] = gets.split.map(&:to_i)\nend\n\n(0..ans.size-1).each do |i|\n\tans[i] = solve(0,n-1,i,a)\nend\n\n\nputs n/(2**min(ans))"}], "negative_code": [], "src_uid": "90125e9d42c6dcb0bf3b2b5e4d0f845e"} {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\na = gets.split.map(&:to_i)\n\nif a[0] == a[1]\n a[0].times do\n print \"BG\"\n end\n exit\nend\np=a[0]-a[1]\nr=a[1]-a[0]\nif a[0]>a[1]\n a[1].times do\n print \"BG\"\n end\n p.times do\n print \"B\" \n end\n exit\nend\n\nif a[1]>a[0]\n a[0].times do\n print \"GB\"\n end\n r.times do\n print \"G\" \n end\n exit\nend ", "positive_code": [{"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\na=gets.chomp.split(\" \")\nb=a[0].to_i\ng=a[1].to_i\nans=\"\"\nif b>=g\nloop do\nbreak if b==0 && g==0\nif b!=0\nans+=\"B\"\nb-=1\nend\nif g!=0\nans+=\"G\"\ng-=1\nend\nend\nelse\nloop do\nbreak if b==0 && g==0\nif g!=0\nans+=\"G\"\ng-=1\nend\nif b!=0\nans+=\"B\"\nb-=1\nend\nend\nend\n\nputs \"#{ans}\""}, {"source_code": "n,m=File.open(\"input.txt\").gets.split.map(&:to_i)\nFile.open(\"output.txt\", \"w\") { |f|\n\tif n < m then\n\t\tf.puts \"GB\"*n + \"G\"*(m-n)\n\telse\n\t\tf.puts \"BG\"*m + \"B\"*(n-m)\n\tend\n}\n"}, {"source_code": "m, n= File.open(\"input.txt\").gets.split.map(&:to_i)\nFile.open(\"output.txt\", \"w\") { |f|\n if m > n\n f.puts 'BG'*n + 'B'*(m-n)\n else\n f.puts 'GB'*m + 'G'*(n-m)\n end\n}"}, {"source_code": "a=[]\nFile.open(\"input.txt\",\"r\") do |file|\n a=file.gets.chomp.split\nend\n\nn=a[0].to_i\nm=a[1].to_i\n\n\n\nif(n>m)\n maxc='B'\n minc='G'\n mini=m\nelse\n maxc='G'\n minc='B'\n mini=n\nend\n\na=\"\"\n\n(n+m).times do\n a+=maxc\nend\n\nind=1\nmini.times do\n a[ind]=minc\n ind+=2\nend\nFile.open(\"output.txt\",\"w\") do |file|\n file.puts a\nend\n\n"}, {"source_code": "n, m = 0, 0\nFile.open(\"input.txt\", \"r\") do |file|\n n, m = file.gets.split.collect{|i| i.to_i}\nend\nFile.open(\"output.txt\", \"w\") do |file|\n if n >= m\n file.puts (['B','G']*m+['B']*(n-m)).join\n else\n file.puts (['G','B']*n+['G']*(m-n)).join\n end\nend\n"}, {"source_code": "#n, m = IO.readlines(\"input.txt\")[0].split.collect{|i| i.to_i}\nn, m = File.new(\"input.txt\", \"r\").gets.split.collect{|i| i.to_i}\nif n >= m\n File.new(\"output.txt\", \"w\").puts (['B','G']*m+['B']*(n-m)).join\nelse\n File.new(\"output.txt\", \"w\").puts (['G','B']*n+['G']*(m-n)).join\nend\n"}, {"source_code": "file = File.new(\"input.txt\", \"r\")\nn, m = file.gets.split.collect{|i| i.to_i}\nfile.close\nfile = File.new(\"output.txt\", \"w\")\nif n >= m\n file.puts (['B','G']*m+['B']*(n-m)).join\nelse\n file.puts (['G','B']*n+['G']*(m-n)).join\nend\nfile.close\n"}, {"source_code": "n, m = File.new(\"input.txt\", \"r\").gets.split.collect{|i| i.to_i}\nif n >= m\n File.new(\"output.txt\", \"w\").puts (['B','G']*m+['B']*(n-m)).join\nelse\n File.new(\"output.txt\", \"w\").puts (['G','B']*n+['G']*(m-n)).join\nend\n"}, {"source_code": "file = File.open('input.txt', \"r\")\nn, m = file.gets.split.map { |x| x.to_i }\nfile.close\n\nFile.open('output.txt', 'w') { |f| f.write(n == m ? 'GB' * n : n > m ? 'BG' * m + 'B' * (n - m) : 'GB' * n + 'G' * (m - n)) }"}, {"source_code": "n, m = File.open(\"input.txt\").gets.split.map(&:to_i)\noutput = File.open(\"output.txt\", \"w\")\nwhile n > 0 || m > 0\n\tif (n >= m)\n\t\toutput.print 'B'\n\t\toutput.print 'G' if m > 0\n\telse\n\t\toutput.print 'G'\n\t\toutput.print 'B' if n > 0\n\tend\n\tn, m = n - 1, m - 1\nend\n"}, {"source_code": "input = File.new('input.txt', 'r')\noutput = File.new('output.txt', 'w')\n\nt = input.gets.split.collect { |e| e.to_i }\n\nn,m = t[0], t[1]\n\nf,l = 'B','G'\nif n < m\n\tf,l = 'G','B'\nend\nmin = t.min\nothers = t.max - min\n\nfor i in 1..min do\n\toutput.print f,l\nend\nfor i in 1..others do\n\toutput.print f\nend\n\ninput.close\noutput.close"}, {"source_code": "f = File.open(\"input.txt\", \"r\")\ns = f.read.split\nn = s[0].to_i\nm = s[1].to_i\nf.close\n\nif n > m then\n s = \"BG\"*m + \"B\"*(n-m)\nelse\n s = \"GB\"*n + \"G\"*(m-n)\nend\n\nf = File.open(\"output.txt\", \"w\")\nf.write(s)\nf.close\nputs s"}, {"source_code": "#!/usr/bin/ruby\nf=nil\nif true\n\tf=File.open('input.txt','rb')\nelse\n\tf=$<\nend\nb,g=f.gets.split.map(&:to_i)\nm=[b,g].min\nb-=m;g-=m\np [g,m,b]\nFile.write('output.txt','G'*g+'BG'*m+'B'*b)"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\ninput=gets.to_s.split\nn = input[0].to_i\nm = input[1].to_i\nstr = \"\"\nif n==m\n\tn.times{str+=\"BG\"}\nelsif n > m\n\tm.times{str+=\"BG\"}\n\t(n-m).times{str+=\"B\"}\nelse\n\tn.times{str+=\"GB\"}\n\t(m-n).times{str+=\"G\"}\nend\nputs str"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt', 'w')\nn,m=gets.split.map(&:to_i)\nm>=n ? (print \"GB\"*[m,n].min; print \"G\"*(m-n) if nm) \n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt', 'w')\nn,m=gets.split.map(&:to_i)\nprint \"GB\"*[m,n].min if m>=n\n print \"BG\"*[m,n].min if mm \nprint \"G\"*(m-n) if n m\n puts \"BG\" * m + \"B\" * (n - m)\nelse\n puts \"GB\" * n + \"G\" * (m - n)\nend"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn, m = gets.split.map(&:to_i)\nputs (n <= m ? \"GB\" : \"BG\")*[n, m].min + (n <= m ? \"G\" : \"B\")*([n,m].max-[n,m].min)"}], "negative_code": [{"source_code": "f = File.open(\"input.txt\", \"r\")\ns = f.read.split\nn = s[0].to_i\nm = s[1].to_i\nf.close\n\nif n > m then\n s = \"BG\"*m + \"B\"*(n-m)\nelse\n s = \"GB\"*n + \"B\"*(m-n)\nend\n\nf = File.open(\"output.txt\", \"w\")\nf.write(s)\nf.close\nputs s"}, {"source_code": "#!/usr/bin/ruby\nf=nil\nif true\n\tf=File.open('input.txt','rb')\nelse\n\tf=$<\nend\nb,g=f.gets.split.map(&:to_i)\nm=[b,g].min\nb-=m;g-=m\np [g,m,b]\nputs 'G'*g+'BG'*m+'B'*b"}, {"source_code": "#!/usr/bin/ruby\nf=nil\nif true\n\tf=File.open('input.txt','rb')\nelse\n\tf=$<\nend\nb,g=f.gets.split.map(&:to_i)\nm=[b,g].min\nb-=m;g-=m\nputs 'G'*g+'BG'*m+'B'*b"}, {"source_code": "#!/usr/bin/ruby\n$stdin=File.open('input.txt','rb')\nb,g=gets.split.map(&:to_i)\nm=[b,g].min\nb-=m;g-=m\nputs 'G'*g+'BG'*m+'B'*b"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt', 'w')\nn,m=gets.split.map(&:to_i)\nprint \"GB\"*[m,n].min if m>=n\n print \"BG\"*[m,n].min if mm \nprint \"G\"*m if nm\nprint \"G\"*m if n=g\nloop do\nbreak if b==0 && g==0\n\nif b!=0\nans+=\"B\"\nb-=1\nend\n\nif g!=0\nans+=\"G\"\ng-=1\nend\n\nend\nelse\nloop do\nbreak if b==0 && g==0\n\nif b!=0\nans+=\"B\"\nb-=1\nend\n\nif g!=0\nans+=\"G\"\ng-=1\nend\n\nend\nend\n\nputs \"#{ans}\""}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\na=gets.chomp.split(\" \")\nb=a[0].to_i\ng=a[1].to_i\nans=\"\"\n\nloop do\nbreak if b==0 && g==0\n\nif b!=0\nans+=\"B\"\nb-=1\nend\n\nif g!=0\nans+=\"G\"\ng-=1\nend\n\nend\n\nputs \"#{ans}\""}, {"source_code": "m, n= File.open(\"input.txt\").gets.split.map(&:to_i)\nFile.open(\"output.txt\", \"w\") { |f|\n if m > n\n f.puts 'BG'*n + 'B'*(m-n)\n else\n f.puts 'GB'*n + 'G'*(n-m)\n end\n}"}, {"source_code": "n, m = IO.readlines(\"input.txt\")[0].split.collect{|i| i.to_i}\nif n >= m\n puts (['B','G']*m+['B']*(n-m)).join\nelse\n puts (['G','B']*n+['G']*(m-n)).join\nend\n"}, {"source_code": "puts 2"}, {"source_code": "b=gets.to_i\ng=gets.to_i\nif b == g\n b.times do\n puts \"BG\"\n end\nend\n \nif b>g\n g.times do\n puts \"BG\"\n end\n b-g.times do\n puts \"B\" \n end\nend\n\nif g>b\n b.times do\n puts \"GB\"\n end\n g-b.times do\n puts \"G\" \n end\nend"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\na = gets.split.map(&:to_i)\n\nif a[0] == a[1]\n a[0].times do\n print \"BG\"\n end\n exit\nend\n \nif a[0]>a[1]\n a[1].times do\n print \"BG\"\n end\n a[0]-a[1].times do\n print \"B\" \n end\n exit\nend\n\nif a[0]>a[1]\n a[1].times do\n print \"GB\"\n end\n a[1]-a[0].times do\n print \"G\" \n end\n exit\nend"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\na = gets.split.map(&:to_i)\nif a[0] == a[1]\n a[0].times do\n print \"BG\"\n end\nend\n \nif a[0]>a[1]\n a[1].times do\n print \"BG\"\n end\n a[0]-a[1].times do\n print \"B\" \n end\nend\n\nif a[0]>a[1]\n a[1].times do\n print \"GB\"\n end\n a[1]-a[0].times do\n print \"G\" \n end\nend"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\na = gets.split.map(&:to_i)\n\nif a[0] == a[1]\n a[0].times do\n print \"BG\"\n end\n exit\nend\n \nif a[0]>a[1]\n a[0].times do\n print \"BG\"\n end\n a[0]-a[1].times do\n print \"B\" \n end\n exit\nend\n\nif a[0]>a[1]\n a[1].times do\n print \"GB\"\n end\n a[1]-a[0].times do\n print \"G\" \n end\n exit\nend "}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\na = gets.split.map(&:to_i)\n\nif a[0] == a[1]\n a[0].times do\n print \"BG\"\n end\n exit\nend\n \nif a[0]>a[1]\n a[1].times do\n print \"BG\"\n end\n a[0]-a[1].times do\n print \"B\" \n end\n exit\nend\n\nif a[1]>a[0]\n a[0].times do\n print \"GB\"\n end\n a[1]-a[0].times do\n print \"G\" \n end\n exit\nend "}], "src_uid": "5392996bd06bf52b48fe30b64493f8f5"} {"source_code": "t = gets.to_i\nt.times do\n x0, n = gets.split.map(&:to_i)\n x = x0\n m = n / 4 * 4 + 1\n (m .. n).each do |i|\n if x.odd?\n x += i\n else\n x -= i\n end\n end\n puts x\nend", "positive_code": [{"source_code": "gets.to_i.times do\r\n x,n=gets.split.map(&:to_i)\r\n if n%4==0\r\n puts x\r\n elsif n%4==1\r\n if x.even?\r\n puts x-n\r\n else\r\n puts x+n\r\n end\r\n elsif n%4==2\r\n if x.even?\r\n puts x+1\r\n else\r\n puts x-1\r\n end\r\n else\r\n if x.even?\r\n puts x+n+1\r\n else\r\n puts x-n-1\r\n end\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "dbe12a665c374ce3745e20b4a8262eac"} {"source_code": "n,m=gets.split.map(&:to_i)\np=(m-1)*2\nn.times {\n s,f,t=gets.split.map(&:to_i)\n if s==f\n puts t\n else\n base= (t/p)*p\n ont = [base+s-1,base+p-s+1,base+s-1+p,base+p-s+1+p].find{|i| i>=t}\n puts [base+f-1,base+p-f+1,base+f-1+p,base+p-f+1+p].find{ |i| i>=ont} \n end\n}\n", "positive_code": [{"source_code": "def solve(s, f, t, m)\n lapse = 2 * (m - 1)\n\n # if a person is already at his destination\n # then we just return the time when he start waiting\n return t if s == f\n\n if s < f\n ret = s - 1\n ret += ((t - ret) / lapse.to_f).ceil * lapse if ret < t\n # same as this\n # while ret < t\n # ret += lapse\n # end\n ret += f - s\n else\n ret = lapse - (s - 1)\n ret += ((t - ret) / lapse.to_f).ceil * lapse if ret < t\n # same as this\n # while ret < t\n # ret += lapse\n # end\n ret += s - f\n end\n ret\nend\n\nn, m = gets.strip.split(' ').map(&:to_i)\n\nn.times do\n s, f, t = gets.strip.split(' ').map(&:to_i)\n puts solve(s, f, t, m)\nend\n"}, {"source_code": "def solve(s, f, t, m)\n lapse = 2 * (m - 1)\n # if a person is already at his destination\n # then we just return the time when he start waiting\n return t if s == f\n\n if s < f\n ret = s - 1\n while ret < t\n ret += lapse\n end\n ret += f - s\n else\n ret = lapse - (s - 1)\n while ret < t\n ret += lapse\n end\n ret += s - f\n end\n ret\nend\n\nn, m = gets.strip.split(' ').map(&:to_i)\n\nn.times do\n s, f, t = gets.strip.split(' ').map(&:to_i)\n puts solve(s, f, t, m)\nend\n"}, {"source_code": "def read_next_line\n gets.split.map { |x| x.to_i }\nend\n\nn, m = read_next_line\nq = 2 * m\nz = m - 1\nk = 2 * z\nfor _ in 1..n\n s, f, t = read_next_line\n if s == f\n puts t\n next\n end\n r = t % k\n es = m - (z - r).abs\n d = r > z\n pt = es == s ? 0 : d ^ (es < s) ? (s - es).abs : (d ^= 1) ? q - (s + es) : (s + es) - 2\n pt += d ^ (f > s) ? (s -f).abs : d ? (s + f) - 2 : q - (s + f)\n puts t + pt\nend"}, {"source_code": "# -*- coding: utf-8 -*-\n\ndef hoge(s,f,t,m)\n return t if s==f\n p=(m-1)*2\n base= (t/p)*p\n t -= base\n base + if s < f\n #up\n if t<=s-1\n f-1\n else\n p+f-1\n end\n else\n #down\n if t<=p-s+1\n p-f+1\n else\n p-f+1 + p \n end\n end\nend\n\nn,m=gets.split.map(&:to_i)\nn.times {\n s,f,t=gets.split.map(&:to_i)\n r = hoge(s,f,t,m)\n puts r\n}\n"}, {"source_code": "# -*- coding: utf-8 -*-\ndef f(s,f,t,m)\n return t if s==f\n p=(m-1)*2\n base= (t/p)*p\n ont = [base+s-1,base+p-s+1,base+s-1+p,base+p-s+1+p].find{|i| i>=t}\n [base+f-1,base+p-f+1,base+f-1+p,base+p-f+1+p].find{ |i| i>=ont}\nend\n\nn,m=gets.split.map(&:to_i)\nn.times {\n s,f,t=gets.split.map(&:to_i)\n puts f(s,f,t,m)\n}\n"}, {"source_code": "def calctime(m, s, f, t)\n if s < f\n wk = s - 1\n else\n wk = (m-1) + (m-s)\n end\n while true\n break if t <= wk\n wk += (m-1)*2\n end\n return wk + (s-f).abs\nend\nn, m = gets.chomp.split(/ /).map!{|x| x.to_i}\nfor i in 0..n-1\n s,f,t = gets.chomp.split(/ /).map!{|x| x.to_i}\n ret = t\n if s != f\n ret = calctime(m,s,f,t)\n end\n puts ret\nend\n"}, {"source_code": "\ninput=gets.split.map(&:to_i)\nn=input[0]\nm=input[1]-1\nn.times{\n input=gets.split.map(&:to_i)\n s=input[0]-1\n f=input[1]-1\n t=input[2]\n if s==f then\n puts t\n elsif ss then\n cnt+=1\n end\n puts cnt*2*m+f\n else\n tt=t%(2*m)\n cnt=t/(2*m)\n s,f=f,s\n if tt>m-f+m then\n cnt+=1\n end\n puts cnt*2*m+m+m-s\n end\n}\n"}, {"source_code": "def solve\n n, m = gets.strip.split(' ').map(&:to_i)\n m -= 1\n n.times do\n s, f, t = gets.strip.split(' ').map(&:to_i)\n r = nil\n s -= 1\n f -= 1\n if s == f\n r = t\n elsif s < f\n r = s\n while r < t\n r += 2 * m\n end\n r += (f-s).abs\n else\n r = 2 * m - s\n while r < t\n r += 2 * m\n end\n r += (f-s).abs\n end\n puts r\n end\nend\n\nsolve"}], "negative_code": [{"source_code": "# -*- coding: utf-8 -*-\n\ndef hoge(s,f,t,m)\n return 0 if s==f\n p=(m-1)*2\n base= (t/p)*p\n t -= base\n base + if s < f\n #up\n if t<=s-1\n f-1\n else\n p+f-1\n end\n else\n #down\n if t<=p-s+1\n p-f+1\n else\n p-f+1 + p \n end\n end\nend\n\nn,m=gets.split.map(&:to_i)\nn.times {\n s,f,t=gets.split.map(&:to_i)\n r = hoge(s,f,t,m)\n puts r\n}\n"}, {"source_code": "def calctime(m, s, f, t)\n if s < f\n wk = s - 1\n else\n wk = (m-1) + (m-s)\n end\n while true\n break if t <= wk\n wk += (m-1)*2\n end\n return wk + (s-f).abs\nend\nn, m = gets.chomp.split(/ /).map!{|x| x.to_i}\nfor i in 0..n-1\n ret = 0\n s,f,t = gets.chomp.split(/ /).map!{|x| x.to_i}\n if s != f\n ret = calctime(m,s,f,t)\n end\n puts ret\nend\n"}, {"source_code": "\ninput=gets.split.map(&:to_i)\nn=input[0]\nm=input[1]-1\nn.times{\n input=gets.split.map(&:to_i)\n s=input[0]-1\n f=input[1]-1\n t=input[2]\n if s==f then\n puts \n elsif ss then\n cnt+=1\n end\n puts cnt*2*m+f\n else\n tt=t%(2*m)\n cnt=t/(2*m)\n s,f=f,s\n if tt>m-f+m then\n cnt+=1\n end\n puts cnt*2*m+m+m-s\n end\n}\n"}, {"source_code": "\ninput=gets.split.map(&:to_i)\nn=input[0]\nm=input[1]-1\nn.times{\n input=gets.split.map(&:to_i)\n s=input[0]-1\n f=input[1]-1\n t=input[2]\n if s==f then\n puts 0\n elsif ss then\n cnt+=1\n end\n puts cnt*2*m+f\n else\n tt=t%(2*m)\n cnt=t/(2*m)\n s,f=f,s\n if tt>m-f+m then\n cnt+=1\n end\n puts cnt*2*m+m+m-s\n end\n}\n"}, {"source_code": "def running(ans, max, n, k, sum)\n limit = max / ans;\n ret = 0;\n 1.upto(limit) do |j|\n sum[j * ans + k] ||= 0\n sum[j * ans - 1] ||= 0\n ret += sum[j * ans + k] - sum[j * ans - 1]\n end\n return ret == n;\nend\n\ndef solve\n min = Float::INFINITY\n max = 0\n\n n, k = gets.strip.split.map(&:to_i)\n a = []\n sum = []\n\n gets.strip.split.each do |x|\n x = x.to_i\n a << x\n min = [x, min].min\n max = [x, max].max\n sum[x] ||= 0\n sum[x] += 1\n end\n\n min.upto(max+k) do |i|\n sum[i] ||= 0\n sum[i-1] ||= 0\n sum[i] += sum[i-1]\n end\n\n if min <= k+1\n puts min\n return\n end\n min.downto(k+1) do |i|\n if running(i, max, n, k, sum)\n puts i\n return\n end\n end\nend\n\nsolve"}], "src_uid": "b8321b0a3fc8c295182a4c2c8d2e9d01"} {"source_code": "n=gets.chomp.to_i\nsnack=gets.chomp.split.map{|x| x.to_i}\nstate=Array.new(n+1,0);\nstart=n\nsnack.each do |x|\n\tstate[x]=1\n\ti=start\n\twhile i>0\n\t\tif state[i]==2\n\t\t\tstart-=1\n\t\telse\n\t\t\tif state[i]==1\n\t\t\t\tprint \" #{i}\"\n\t\t\t\tstate[i]=2#\u5c31\u662f\u8bf4\u5728state 2\u4e0b\uff0ci\u7cd6\u679c\u5df2\u7ecf\u88ab\u653e\u597d\uff01\n\t\t\telse\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\ti-=1\n\tend\n\tputs\nend\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\nl,*a=$<.read.split.map &:to_i\nh={}\na.each{|i|\n\th[i]=1\n\tr=[]\n\twhile h[l]\n\t\tr< 0 then\tputs 1; puts evens.first + 1; return; end\nif odds.size > 1 then puts 2; print(odds[0]+1, ' ', odds[1]+1); puts; return; end\nputs -1\nend\n\nt = gets.to_i\nt.times {solve}\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n idx = a.index { |x| x % 2 == 0 }\n\n if idx\n puts 1\n puts idx + 1\n else\n odds = []\n\n n.times do |i|\n odds << i + 1 if a[i].odd?\n end\n\n if odds.size >= 2\n ans = odds.take(2)\n puts ans.size\n puts ans.join(' ')\n else\n puts -1\n end\n end\nend\n"}, {"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n n = gets.to_i\n ar_odds, ar_evens = [], []\n gets.split.each_with_index { |i, index|\n i = i.to_i\n index += 1 # 1-based\n if i.odd?\n ar_odds << index\n else\n ar_evens << index\n end\n }\n\n if ar_evens.length > 0\n puts 1\n puts ar_evens.first\n else\n if ar_odds.length == 1\n puts -1\n else\n puts 2\n puts ar_odds[0...2].join(' ')\n end\n end\n\n}"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n even = []\n odd = []\n a.each_with_index do |v, i|\n if v % 2 == 0\n even.push(i + 1)\n else\n odd.push(i + 1)\n end\n end\n if even.length >= 1\n puts 1\n puts even[0]\n elsif odd.length >= 2\n puts 2\n puts \"#{odd[0]} #{odd[1]}\"\n else\n puts -1\n end\nend\n"}], "negative_code": [{"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1323/A\n\ncount = gets.to_i\n\nanswers = []\n\ncount.times do\n n = gets.to_i\n a = gets.split(' ').map(&:to_i)\n \n odd_index = nil\n \n a.each_with_index do |num, index|\n if n == 1\n answers << -1\n break\n end\n if num % 2 == 0\n answers << 1 << index + 1\n break\n else\n if odd_index.nil?\n odd_index = index + 1\n else\n answers << 2 << \"#{odd_index} #{index+1}\"\n break\n end \n end\n end\nend\n\nanswers.each { |answer| puts answer }\n"}, {"source_code": "t = gets.to_i\nt.times do \n n = gets.to_i\n a = gets.split.map(&:to_i)\n flg = false\n n.times do |i|\n if a[i].even?\n p 1\n p i+1\n flg = true\n end\n end\n next if flg \n if n == 1\n p -1\n else\n p 2\n puts \"1 2\"\n end\nend"}], "src_uid": "3fe51d644621962fe41c32a2d90c7f94"} {"source_code": "t = gets.to_i\nt.times do\n a, b, c = gets.split.map &:to_i\n s = [b, c/2].min\n f = [a, (b - s)/2].min\n puts (f + s)*3\nend\n", "positive_code": [{"source_code": "T = gets.to_i\nT.times do\n a,b,c = gets.split.map(&:to_i)\n ans = 0\n (a+1).times do |i|\n x = [a,b/2,i].min\n d,e,f = a-x, b-x*2, c\n sum = x*3\n while e > 0 && f > 1\n sum += 3\n e -= 1\n f -= 2\n end\n ans = [ans, sum].max\n end\n p ans\nend"}, {"source_code": "gets.to_i.times do\n a, b, c = gets.split.map(&:to_i)\n\n ans1 = 0\n t = [b, c/2].min\n b -= t\n c -= t * 2\n ans1 += t * 3\n t = [a, b/2].min\n a -= t\n b -= t * 2\n ans1 += t * 3\n\n ans2 = 0\n t = [a, b/2].min\n a -= t\n b -= t * 2\n ans2 += t * 3\n t = [b, c/2].min\n b -= t\n c -= t * 2\n ans2 += t * 3\n\n puts [ans1, ans2].max\nend\n"}, {"source_code": "vals = STDIN.readlines\nn = vals[0].to_i\nstones = []\nn.times { |i|\n s = vals[i + 1].split(' ').map(&:to_i)\n stones.push(s)\n}\nstones.each { |stone|\n ret = 0\n while stone[2] > 1 && stone[1] >= 1 \n stone[2] = stone[2] - 2\n stone[1] = stone[1] - 1\n ret += 3\n end\n while stone[1] > 1 && stone[0] >= 1\n stone[1] = stone[1] - 2\n stone[0] = stone[0] - 1\n ret += 3\n end\n p ret\n}\n"}, {"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\nn = inp[0]\nans = 0\nn.times do |i|\n t = inp\n f = [t[2]/2,t[1]].min\n t[1] -= f\n s = [t[0],t[1]/2].min\n p (f+s)*3\nend"}, {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2 1 && stone[1] > 1 \n stone[2] = stone[2] - 2\n stone[1] = stone[1] - 1\n ret += 3\n end\n while stone[1] > 1 && stone[0] > 1\n stone[1] = stone[1] - 2\n stone[0] = stone[0] - 1\n ret += 3\n end\n p ret\n}\n"}], "src_uid": "14fccd50d5dfb557dd53f2896ed844c3"} {"source_code": "t = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n if n % 2050 != 0\n printf(\"-1\\n\")\n next\n end\n\n n /= 2050\n res = 0\n while n > 0\n res += n % 10\n n /= 10\n end\n\n printf(\"%d\\n\", res)\nend\n", "positive_code": [{"source_code": "[*$<][1..-1].map{|n|n=n.to_i;p n%2050>0?-1:(n/2050).to_s.chars.map(&:to_i).sum}"}, {"source_code": "[*$<][1..-1].map{|n|n=n.to_i;p n%2050>0?-1:(n/2050).to_s.chars.map(&:to_i).inject(:+)}"}, {"source_code": "test_cases = gets.chomp.to_i\r\nfor i in 1..test_cases do\r\n n = gets.chomp.to_i\r\n if (n % 2050 == 0)\r\n n /= 2050\r\n s = n.to_s\r\n ans = 0\r\n for j in 0..s.size - 1 do\r\n ans += s[j].ord - '0'.ord\r\n end\r\n puts ans\r\n else\r\n puts -1\r\n end\r\nend"}, {"source_code": "def solution(n)\n min_number = 0\n k = 0\n\n while twenty_fifty_number(k) <= n\n k += 1\n end\n\n while k >= 0\n if n < twenty_fifty_number(k)\n k -= 1\n else\n n = n - twenty_fifty_number(k) \n min_number += 1\n end\n end\n\n if n == 0 \n min_number\n else\n - 1\n end\nend\n\ndef twenty_fifty_number(k)\n 2050 * (10 ** k)\nend\n\ntest_cases = gets.to_i\n\ntest_cases.times do |test_case|\n n = gets.to_i\n res = solution(n)\n\n puts res\nend\n"}], "negative_code": [], "src_uid": "f3e413954c9c02520fd25bd2cba4747e"} {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\ndef r(n)\n h = {}\n n.times{\n x, y = I[]\n h[y] = h[y] || Hash.new(0)\n h[y][x] += 1\n }\n h\nend\na, b, u, v = r(n), r(m), 0, 0\na.merge(b){|_, c, d|\n u += [c, d].map{|_| _.values.inject(&:+)}.min\n c.merge(d){|_, e, f|\n v += [e, f].min\n }\n}\nputs \"#{u} #{v}\"\n", "positive_code": [{"source_code": "require 'scanf'\nlines = STDIN.read.split(\"\\n\")\nn, m = lines[0].scanf(\"%d%d\")\nmarkers = lines[1..n].map { |line|\n\tsplit = line.split(' ')\n\t[Integer(split[0]), Integer(split[1])]\n}\ncups = lines[n+1..n+m].map { |line|\n\tsplit = line.split(' ')\n\t[Integer(split[0]), Integer(split[1])]\n}\n\nclosed = 0\nbeautifully_closed = 0\n\nmarkers_map = {}\nmarkers.each do |marker|\n\tmarkers_map[marker[1]] = {-1 => 0}unless markers_map.key?(marker[1])\n\tmarkers_map[marker[1]][marker[0]] = 0 unless markers_map[marker[1]].key?(marker[0])\n\tmarkers_map[marker[1]][marker[0]] += 1\n\tmarkers_map[marker[1]][-1] += 1\nend\n\ni = 0\nwhile i < cups.length\n\tif markers_map.key?(cups[i][1])\n\t\tif markers_map[cups[i][1]].key?(cups[i][0]) && markers_map[cups[i][1]][cups[i][0]] > 0\n\t\t\tmarkers_map[cups[i][1]][cups[i][0]] -= 1\n\t\t\tmarkers_map[cups[i][1]][-1] -= 1\n\t\t\tbeautifully_closed += 1\n\t\t\tclosed += 1\n\t\t\tcups.delete_at(i)\n\t\t\tnext\n\t\tend\n\tend\n\ti += 1\nend\n\ni = 0\nwhile i < cups.length\n\tif markers_map.key?(cups[i][1])\n\t\tif markers_map[cups[i][1]][-1] > 0\n\t\t\tmarkers_map[cups[i][1]][-1] -= 1\n\t\t\tclosed += 1\n\t\tend\n\tend\n\ti += 1\nend\n\nputs \"#{closed} #{beautifully_closed}\"\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nmarkers = {}\nn.times{\n color,diameter = gets.split.map(&:to_i)\n markers[diameter] ||= {}\n markers[diameter][color] ||= 0\n markers[diameter][color] += 1\n}\n\nunused_caps = {}\nbeautiful_closed = 0\n\nm.times do\n color,diameter = gets.split.map(&:to_i)\n if markers[diameter] and markers[diameter][color] and markers[diameter][color] > 0\n beautiful_closed += 1\n markers[diameter][color] -= 1\n else\n unused_caps[diameter] ||= 0\n unused_caps[diameter] += 1\n end\nend\n\nclosed = beautiful_closed\nopen_markers = {}\nmarkers.each{|diameter,hsh|\n open_markers[diameter]=hsh.inject(0){|s,(k,v)| s+v}\n}\nunused_caps.each{|diameter, number|\n closed += [open_markers[diameter] || 0, unused_caps[diameter] || 0].min\n}\n\nputs \"#{closed} #{beautiful_closed}\""}, {"source_code": "a = STDIN.gets.split(\" \").map(&:to_i)\narr = (a[0]+a[1]).times.map{STDIN.gets.split(\" \").map(&:to_i)}\n\nc1h=arr[a[0]...(a[0]+a[1])].inject(Hash.new(0)) {|h, e| h.tap {|h| h[e] += 1} }\nm1h=arr[0...a[0]].inject(Hash.new(0)) {|h, e| h.tap {|h| h[e] += 1} }\nbclosed=0\nc1h.each do |k,v|\n next unless m1h[k]\n bclosed+=m1h[k] >= v ? v : m1h[k]\nend\nc2h=arr[a[0]...(a[0]+a[1])].map{|v| v[1]}.inject(Hash.new(0)) {|h, e| h.tap {|h| h[e] += 1} }\nm2h=arr[0...a[0]].map{|v| v[1]}.inject(Hash.new(0)) {|h, e| h.tap {|h| h[e] += 1} }\nclosed=0\nc2h.each do |k,v|\n next unless m2h[k]\n closed+=m2h[k] >= v ? v : m2h[k]\nend\n\nputs \"#{closed} #{bclosed}\""}, {"source_code": "def read_array(size)\n a = []\n for _ in 1..size\n a << read_next_line\n end\n group(a)\nend\n\ndef read_next_line\n gets.split.map { |x| x.to_i }\nend\n\ndef group(a)\n Hash[a.inject(Hash.new { |h, e| h[e] = [] }) { |h, e| h[e[1]] << e[0]; h }.map { |k, v|\n [k, [v.inject(Hash.new(0)) { |h, e| h[e] += 1; h }, v.size]]\n }]\nend\n\nn, m = read_next_line\nmarkers = read_array(n)\ncaps = read_array(m)\n\nclosed = b_closed = 0\nmarkers.each { |d, c|\n if caps.has_key? d\n closed += [c[1], caps[d][1]].min\n c[0].each { |k, v|\n if caps[d][0].has_key? k\n b_closed += [v, caps[d][0][k]].min\n end\n }\n end\n}\nputs \"#{closed} #{b_closed}\""}, {"source_code": "require 'scanf'\nlines = STDIN.read.split(\"\\n\")\nn, m = lines[0].scanf(\"%d%d\")\nmarkers = lines[1..n].map { |line|\n\tsplit = line.split(' ')\n\t[Integer(split[0]), Integer(split[1])]\n}\ncaps = lines[n+1..n+m].map { |line|\n\tsplit = line.split(' ')\n\t[Integer(split[0]), Integer(split[1])]\n}\n\nmarkers = markers.sort { |a, b| a[1] > b[1] ? 1 : a[1] < b[1] ? -1 : a[0] - b[0] }\ncaps = caps.sort { |a, b| a[1] > b[1] ? 1 : a[1] < b[1] ? -1 : a[0] - b[0] }\n\nclosed = 0\nbeautifully_closed = 0\ncurrent_size = -1\ni = 0 # marker index\nj = 0 # cap index\nwhile i < markers.length && j < caps.length\n\tunclosed_markers = 0\n\tunused_caps = 0\n\tcurrent_size = markers[i][1] # or = caps[j][1]\n\twhile i < markers.length && j < caps.length && markers[i][1] == current_size && caps[j][1] == current_size\n\t\twhile i < markers.length && j < caps.length && markers[i][1] == current_size && caps[j][1] == current_size && markers[i][0] == caps[j][0]\n\t\t\tclosed += 1\n\t\t\tbeautifully_closed += 1\n\t\t\ti += 1\n\t\t\tj += 1\n\t\tend\n\t\twhile i < markers.length && j < caps.length && markers[i][1] == current_size && caps[j][1] == current_size && markers[i][0] < caps[j][0]\n\t\t\tunclosed_markers += 1\n\t\t\ti += 1\n\t\tend\n\t\twhile i < markers.length && j < caps.length && markers[i][1] == current_size && caps[j][1] == current_size && caps[j][0] < markers[i][0]\n\t\t\tunused_caps += 1\n\t\t\tj += 1\n\t\tend\n\t\tif j >= caps.length || caps[j][1] != current_size\n\t\t\twhile i < markers.length && markers[i][1] == current_size\n\t\t\t\tunclosed_markers += 1\n\t\t\t\ti += 1\n\t\t\tend\n\t\tend\n\t\tif i >= markers.length || markers[i][1] != current_size\n\t\t\twhile j < caps.length && caps[j][1] == current_size\n\t\t\t\tunused_caps += 1\n\t\t\t\tj += 1\n\t\t\tend\n\t\tend\n\tend\n\tclosed += unclosed_markers < unused_caps ? unclosed_markers : unused_caps\n\twhile i < markers.length && j < caps.length && markers[i][1] < caps[j][1]\n\t\ti += 1\n\tend\n\twhile i < markers.length && j < caps.length && caps[j][1] < markers[i][1]\n\t\tj += 1\n\tend\nend\n\nputs \"#{closed} #{beautifully_closed}\"\n"}, {"source_code": "require 'scanf'\nlines = STDIN.read.split(\"\\n\")\nn, m = lines[0].scanf(\"%d%d\")\nmarkers = lines[1..n].map { |line|\n\tsplit = line.split(' ')\n\t[Integer(split[0]), Integer(split[1])]\n}\ncups = lines[n+1..n+m].map { |line|\n\tsplit = line.split(' ')\n\t[Integer(split[0]), Integer(split[1])]\n}\n\nmarkers = markers.sort { |a, b| a[1] > b[1] ? 1 : a[1] < b[1] ? -1 : a[0] - b[0] }\ncups = cups.sort { |a, b| a[1] > b[1] ? 1 : a[1] < b[1] ? -1 : a[0] - b[0] }\n\nclosed = 0\nbeautifully_closed = 0\n\nmarkers_map = {}\nmarkers.each do |marker|\n\tmarkers_map[marker[1]] = {-1 => 0}unless markers_map.key?(marker[1])\n\tmarkers_map[marker[1]][marker[0]] = 0 unless markers_map[marker[1]].key?(marker[0])\n\tmarkers_map[marker[1]][marker[0]] += 1\n\tmarkers_map[marker[1]][-1] += 1\nend\n\ni = 0\nwhile i < cups.length\n\tif markers_map.key?(cups[i][1])\n\t\tif markers_map[cups[i][1]].key?(cups[i][0]) && markers_map[cups[i][1]][cups[i][0]] > 0\n\t\t\tmarkers_map[cups[i][1]][cups[i][0]] -= 1\n\t\t\tmarkers_map[cups[i][1]][-1] -= 1\n\t\t\tbeautifully_closed += 1\n\t\t\tclosed += 1\n\t\t\tcups.delete_at(i)\n\t\t\tnext\n\t\tend\n\tend\n\ti += 1\nend\n\ni = 0\nwhile i < cups.length\n\tif markers_map.key?(cups[i][1])\n\t\tif markers_map[cups[i][1]][-1] > 0\n\t\t\tmarkers_map[cups[i][1]][-1] -= 1\n\t\t\tclosed += 1\n\t\tend\n\tend\n\ti += 1\nend\n\nputs \"#{closed} #{beautifully_closed}\"\n"}, {"source_code": "class Array\n\tdef my_slice_when\n\t\tarr_groups = []\n\t\tarr = [self[0]]\n\t\ti = 1\n\t\twhile i < self.length\n\t\t\tif yield(self[i - 1], self[i])\n\t\t\t\tarr_groups.push(arr)\n\t\t\t\tarr = [self[i]]\n\t\t\telse\n\t\t\t\tarr.push(self[i])\n\t\t\tend\n\t\t\ti += 1\n\t\tend\n\t\tarr_groups.push(arr)\n\t\tarr_groups\n\tend\nend\n\nrequire 'scanf'\nlines = STDIN.read.split(\"\\n\")\nn, m = lines[0].scanf(\"%d%d\")\nmarkers = lines[1..n].map { |line|\n\tsplit = line.split(' ')\n\t[Integer(split[0]), Integer(split[1])]\n}\ncaps = lines[n+1..n+m].map { |line|\n\tsplit = line.split(' ')\n\t[Integer(split[0]), Integer(split[1])]\n}\n\nmarkers = markers.sort { |a, b| a[1] > b[1] ? 1 : a[1] < b[1] ? -1 : a[0] - b[0] }\ncaps = caps.sort { |a, b| a[1] > b[1] ? 1 : a[1] < b[1] ? -1 : a[0] - b[0] }\n\nmarkers_by_size = markers.my_slice_when { |a, b| a[1] != b[1] }\ncaps_by_size = caps.my_slice_when { |a, b| a[1] != b[1] }\n\nclosed = 0\nbeautifully_closed = 0\ni = 0;\nmarkers_by_size.each do |markers_size_group|\n\tsize = markers_size_group[0][1]\n\twhile i < caps_by_size.length && caps_by_size[i][0][1] < size\n\t\ti += 1\n\tend\n\tbreak if i >= caps_by_size.length\n\tnext if caps_by_size[i][0][1] > size\n\tclosed += markers_size_group.length < caps_by_size[i].length ? markers_size_group.length : caps_by_size[i].length\n\t\n\tmarkers_by_color = markers_size_group.my_slice_when { |a, b| a[0] != b[0] }\n\tcaps_by_color = caps_by_size[i].my_slice_when { |a, b| a[0] != b[0] }\t\n\tj = 0;\n\tmarkers_by_color.each do |markers_color_group|\n\t\tcolor = markers_color_group[0][0]\n\t\twhile j < caps_by_color.length && caps_by_color[j][0][0] < color\n\t\t\tj += 1\n\t\tend\n\t\tbreak if j >= caps_by_color.length\n\t\tnext if caps_by_color[j][0][0] > color\n\t\tbeautifully_closed += markers_color_group.length < caps_by_color[j].length ? markers_color_group.length : caps_by_color[j].length\n\tend\nend\n\nputs \"#{closed} #{beautifully_closed}\"\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\na = Hash.new\na.default = 0 \nb = Hash.new\nb.default = 0\nc = Hash.new\nc.default = 0\nd = Hash.new\nd.default = 0\n\nn.times{\n tmp = gets.split.map(&:to_i)\n a[tmp[1]] += 1\n b[tmp] += 1\n}\nm.times{\n tmp = gets.split.map(&:to_i)\n c[tmp[1]] += 1\n d[tmp] += 1\n}\nu,v = 0,0\n\na.each{|x,y|\n u += [y, c[x]].min\n}\n\nb.each{|x,y|\n v += [y, d[x]].min\n}\n\np u\np v\n"}, {"source_code": "n,m = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmarkers = n.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\ncaps_ = m.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\n\ncaps = {}\ncaps_.each do |i|\n caps[i[1]] ||= {}\n caps[i[1]][i[0]] ||= []\n caps[i[1]][i[0]] << true\nend\n\nbeautiful = 0\nclosed = 0\ndone = []\n\n\nmarkers.each_with_index do |m,_|\n if (h = caps[m[1]]) && (a = h[m[0]]) && a.shift\n done << _\n beautiful += 1\n closed += 1\n h.delete m[0] if a.empty?\n end\nend\n\ndone.each{|i| markers[i] = nil }\n\nmarkers.each_with_index do |m,_|\n next unless m\n if (h = caps[m[1]]) && (a = h.first) && a[1].shift\n closed += 1\n h.delete a[0] if a[1].empty?\n end\nend\n\nputs \"#{closed} #{beautiful}\"\n"}], "negative_code": [{"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\ndef r(n)\n h = {}\n n.times{\n x, y = I[]\n h[y] = h[y] || Hash.new(0)\n h[y][x] += 1\n }\n h\nend\na, b, u, v = r(n), r(m), 0, 0\na.merge(b){|_, c, d|\n u += [c.size, d.size].min\n c.merge(d){|_, e, f|\n v += [e, f].min\n }\n}\nputs \"#{u} #{v}\"\n"}, {"source_code": "n,m = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmarkers = n.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\ncaps = m.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\n\nbeautiful = 0\nclosed = 0\n\nmarkers.each_with_index do |m,_|\n if i = caps.index(m)\n caps.delete_at i\n markers.delete_at _\n beautiful += 1\n closed += 1\n end\nend\n\nmarkers.each_with_index do |m,_|\n if i = caps.index{|c| m[1] == c[1] }\n caps.delete_at i\n markers.delete_at _\n closed += 1\n end\nend\n\nputs \"#{closed} #{beautiful}\"\n"}, {"source_code": "n,m = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmarkers = n.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\ncaps = m.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\n\nbeautiful = 0\nclosed = 0\n\nmarkers.each do |(mc,md)|\n if i = caps.index{|(cc,cd)| mc == cc && md == cd }\n caps.delete_at i\n beautiful += 1\n closed += 1\n elsif i = caps.index{|(cc,cd)| md == cd }\n caps.delete_at i\n closed += 1\n end\nend\n\nputs \"#{closed} #{beautiful}\"\n"}, {"source_code": "n,m = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmarkers = n.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\ncaps_ = m.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\n\ncaps = {}\ncaps_.each do |i|\n caps[i[1]] ||= {}\n caps[i[1]][i[0]] ||= []\n caps[i[1]][i[0]] << true\nend\n\nbeautiful = 0\nclosed = 0\ndone = []\n\nmarkers.each_with_index do |m,_|\n if (h = caps[m[1]]) && (a = h[m[0]]) && a.shift\n beautiful += 1\n closed += 1\n end\nend\n\n\nmarkers.each_with_index do |m,_|\n next unless m\n if (h = caps[m[1]]) && (a = h.first[1]) && a.shift\n closed += 1\n end\nend\n\nputs \"#{closed} #{beautiful}\""}, {"source_code": "n,m = STDIN.gets.chomp.split(/ /).map(&:to_i)\nmarkers = n.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\ncaps_ = m.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }\n\ncaps = {}\ncaps_.each do |i|\n caps[i[1]] ||= {}\n caps[i[1]][i[0]] ||= []\n caps[i[1]][i[0]] << true\nend\n\nbeautiful = 0\nclosed = 0\ndone = []\n\nmarkers.each_with_index do |m,_|\n if (h = caps[m[1]]) && (a = h[m[0]]) && a.shift\n done << _\n beautiful += 1\n closed += 1\n end\nend\n\ndone.each{|i| markers[i] = nil }\n\nmarkers.each_with_index do |m,_|\n next unless m\n if (h = caps[m[1]]) && (a = h.first[1]) && a.shift\n closed += 1\n end\nend\n\nputs \"#{closed} #{beautiful}\"\n"}, {"source_code": "a = STDIN.gets.split(\" \").map(&:to_i)\narr = (a[0]+a[1]).times.map{STDIN.gets.split(\" \").map(&:to_i)}\nm=arr[0...a[0]]\nc=arr[a[0]...(a[0]+a[1])]\n\nclosed = 0\nbclosed = 0\nm.each do |pa|\n bclosed += c.count{|pair| pa == pair}\n arr1= c.map{|h| h[1]}.uniq\n closed += arr1.count{|val| val == pa[1]}\nend\nputs \"#{closed} #{bclosed}\""}, {"source_code": "a = STDIN.gets.split(\" \").map(&:to_i)\narr = (a[0]+a[1]).times.map{STDIN.gets.split(\" \").map(&:to_i)}\nm=arr[0...a[0]].uniq\nc=arr[a[0]...(a[0]+a[1])].uniq\n\nclosed = 0\nbclosed = 0\nm.each do |pa|\n bclosed += c.count{|pair| pa == pair}\nend\nm.map{|h| h[1]}.uniq.each do |v|\n closed += c.map{|h| h[1]}.count{|val| val == v}\nend\nputs \"#{closed} #{bclosed}\""}, {"source_code": "a = STDIN.gets.split(\" \").map(&:to_i)\narr = (a[0]+a[1]).times.map{STDIN.gets.split(\" \").map(&:to_i)}\np m=arr[0...a[0]].uniq\np c=arr[a[0]...(a[0]+a[1])].uniq\n\nclosed = 0\nbclosed = 0\nm.each do |pa|\n bclosed += c.count{|pair| pa == pair}\nend\nm.map{|h| h[1]}.uniq.each do |v|\n closed += c.map{|h| h[1]}.count{|val| val == v}\nend\nputs \"#{closed} #{bclosed}\""}, {"source_code": "class Array\n\tdef my_slice_when\n\t\tarr_groups = []\n\t\tarr = [self[0]]\n\t\ti = 1\n\t\twhile i < self.length\n\t\t\tif yield(self[i - 1], self[i])\n\t\t\t\tarr_groups.push(arr)\n\t\t\t\tarr = [self[i]]\n\t\t\telse\n\t\t\t\tarr.push(self[i])\n\t\t\tend\n\t\t\ti += 1\n\t\tend\n\t\tarr_groups.push(arr)\n\t\tarr_groups\n\tend\nend\n\nrequire 'scanf'\nlines = STDIN.read.split(\"\\n\")\nn, m = lines[0].scanf(\"%d%d\")\nmarkers = lines[1..n].map { |line|\n\tsplit = line.split(' ')\n\t[Integer(split[0]), Integer(split[1])]\n}\ncaps = lines[n+1..n+m].map { |line|\n\tsplit = line.split(' ')\n\t[Integer(split[0]), Integer(split[1])]\n}\n\nmarkers = markers.sort { |a, b| a[1] > b[1] ? 1 : a[1] < b[1] ? -1 : a[0] - b[0] }\ncaps = caps.sort { |a, b| a[1] > b[1] ? 1 : a[1] < b[1] ? -1 : a[0] - b[0] }\n\nmarkers_by_size = markers.my_slice_when { |a, b| a[1] != b[1] }\ncaps_by_size = caps.my_slice_when { |a, b| a[1] != b[1] }\n\nclosed = 0\nbeautifully_closed = 0\ni = 0;\nmarkers_by_size.each do |markers_size_group|\n\tsize = markers_size_group[0][1]\n\twhile i < caps_by_size.length && caps_by_size[i][0][1] < size\n\t\ti += 1\n\tend\n\tbreak if i >= caps_by_size.length || caps_by_size[i][0][1] > size\n\tclosed += markers_size_group.length < caps_by_size[i].length ? markers_size_group.length : caps_by_size[i].length\n\t\n\tmarkers_by_color = markers_size_group.my_slice_when { |a, b| a[0] != b[0] }\n\tcaps_by_color = caps_by_size[i].my_slice_when { |a, b| a[0] != b[0] }\t\n\tj = 0;\n\tmarkers_by_color.each do |markers_color_group|\n\t\tcolor = markers_color_group[0][0]\n\t\twhile j < caps_by_color.length && caps_by_color[j][0][0] < color\n\t\t\tj += 1\n\t\tend\n\t\tbreak if j >= caps_by_color.length || caps_by_color[j][0][0] > color\n\t\tbeautifully_closed += markers_color_group.length < caps_by_color[j].length ? markers_color_group.length : caps_by_color[j].length\n\tend\nend\n\nputs \"#{closed} #{beautifully_closed}\"\n"}], "src_uid": "3c9fb72577838f54b1670e84b4b60c61"} {"source_code": "A = ('a'..'z').to_a.join\nn, m = gets.split.map(&:to_i)\ns = gets.chomp\nds = m.times.map{gets.split}\na = A.dup\nds.each{|x, y| a.tr!(x + y, y + x)}\nputs s.tr(A, a)\n\n", "positive_code": [{"source_code": "A = ('a'..'z').to_a.join\nn, m = gets.split.map(&:to_i)\ns = gets.chomp\nds = m.times.map{gets.split}\na = A.dup\nds.each{|x, y| a.tr!(x + y, y + x)}\nputs s.tr(A, a)\n\n"}, {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nm = Integer(input[1])\nname = gets.chomp\ndesign = Array.new(m)\nfor i in 0...m\n design[i] = gets.chomp.split\nend\n\n#puts design\n\nreplace = Array.new(26) {|i| i }\nrev_replace = Array.new(26) {|i| i }\n\nfor i in 0...design.length\n x, y = design[i]\n if x != y\n x = x.ord - 97\n y = y.ord - 97\n a = rev_replace[x]\n b = rev_replace[y]\n replace[a] = y\n rev_replace[y] = a\n\n replace[b] = x\n rev_replace[x] = b\n end\nend\n\nfor i in 0...n\n print (replace[name[i].ord - 97] + 97).chr\nend\n\nputs"}, {"source_code": "# http://codeforces.com/contest/591/problem/B\n# B. Rebranding\n\nhash = {}.tap do |h|\n ('a'..'z').each { |ch| h[ch] = ch }\nend\nn, m = gets.chomp.split.map(&:to_i)\nchars = gets.chomp.chars\n\nm.times do\n a, b = gets.split\n\n tmp = hash[a]\n hash[a] = hash[b]\n hash[b] = tmp\nend\ninvert = hash.invert\nputs chars.map { |ch| invert[ch] }.join"}, {"source_code": "A = ('a'..'z').to_a.join\nn, m = gets.split.map(&:to_i)\ns = gets.chomp\nds = m.times.map{gets.split}\na = A.dup\nds.each{|x, y| a.tr!(x + y, y + x)}\nputs s.tr(A, a)\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\ns = gets.chomp\nds = m.times.map{gets.split}\na = ('a'..'z').to_a\nds.each do |x, y|\n 26.times do |i|\n if a[i] == x\n a[i] = y\n elsif a[i] == y\n a[i] = x\n end\n end\nend\nn.times do |i|\n s[i] = a[s[i].ord - 'a'.ord]\nend\nputs s\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nstr = gets.chomp\nstr1 = str.clone\nresult, uniq = [], []\nwhile str1.size > 0 do\n uniq << str1[0]\n str1.delete!(str1[0])\nend\nuniq_arr = Array.new(uniq.length){ Array.new }\ni = 0\nstr.each_char do |s|\n uniq.each_with_index do |u, index|\n if s == u\n uniq_arr[index] << i\n break\n end\n end\n i += 1\nend\n(1..m).each do |i|\n x, y = gets.split\n next if x == y\n i = 0\n uniq.each do |c|\n uniq[i] = y if c == x\n uniq[i] = x if c == y\n i += 1\n end\nend\nuniq.each_with_index do |u, index|\n uniq_arr[index].each do |i|\n result[i] = u\n end\nend\nputs result.join()\n"}, {"source_code": "A = ('a'..'z').to_a.join\nn, m = gets.split.map(&:to_i)\ns = gets.chomp\nds = m.times.map{gets.split}\na = A.dup\nds.each{|x, y| a.tr!(x + y, y + x)}\nputs s.tr(A, a)\n\n"}, {"source_code": "A = ('a'..'z').to_a.join\nn, m = gets.split.map(&:to_i)\ns = gets.chomp\nds = m.times.map{gets.split}\na = A.dup\nds.each{|x, y| a.tr!(x + y, y + x)}\nputs s.tr(A, a)\n\n"}, {"source_code": "class Solver\n\tdef main\n\t\tn, m = gets.split.map { |s| s.to_i }\n\t\tstr = gets\n\t\t\n\t\tpos = Array.new(128) { |id, v| v = id }\n\t\tto = Array.new(128) { |id, v| v = id }\n\t\tm.times do\n\t\t\ta, b = gets.split.map { |c| c.ord }\n\t\t\tto[pos[a]], to[pos[b]] = to[pos[b]], to[pos[a]]\n\t\t\tpos[a], pos[b] = pos[b], pos[a]\n\t\tend\n\n\t\tn.times do |i|\n\t\t\tprint to[str[i].ord].chr\n\t\tend\n\t\tprint ?\\n\n\n\tend\nend\n\nSolver.new.main"}, {"source_code": "A = ('a'..'z').to_a.join\nn, m = gets.split.map(&:to_i)\ns = gets.chomp\nds = m.times.map{gets.split}\na = A.dup\nds.each{|x, y| a.tr!(x + y, y + x)}\nputs s.tr(A, a)\n\n"}, {"source_code": "A = ('a'..'z').to_a.join\nn, m = gets.split.map(&:to_i)\ns = gets.chomp\nds = m.times.map{gets.split}\na = A.dup\nds.each{|x, y| a.tr!(x + y, y + x)}\nputs s.tr(A, a)\n\n"}, {"source_code": "# http://codeforces.com/contest/591/problem/B\n# B. Rebranding\n\nhash = {}.tap do |h|\n ('a'..'z').each { |ch| h[ch] = ch }\nend\nn, m = gets.chomp.split.map(&:to_i)\nchars = gets.chomp.chars\n\nm.times do\n a, b = gets.split\n\n tmp = hash[a]\n hash[a] = hash[b]\n hash[b] = tmp\nend\ninvert = hash.invert\nputs chars.map { |ch| invert[ch] }.join\n"}, {"source_code": "A = ('a'..'z').to_a.join\nn, m = gets.split.map(&:to_i)\ns = gets.chomp\nds = m.times.map{gets.split}\na = A.dup\nds.each{|x, y| a.tr!(x + y, y + x)}\nputs s.tr(A, a)\n\n"}, {"source_code": "n = gets.split(' ')[1].to_i\ns = gets\nhash = {}\n\"a\".upto(\"z\") { |s| hash[s] = s }\nn.times do\n a = gets.split(' ')\n k1 = hash.key(a[0])\n k2 = hash.key(a[1])\n tmp = hash[k1]\n hash[k1] = hash[k2]\n hash[k2] = tmp\nend\n\nhash.each { |key, value|\n s.gsub!(key, value.upcase)\n}\n\nputs s.downcase\n\n"}], "negative_code": [{"source_code": "n = gets.split(' ')[1].to_i\ns = gets\nhash = {}\nn.times do\n a = gets.split(' ')\n hash[a[0]] = a[1]\n hash[a[1]] = a[0]\nend\n\nhash.each { |key, value|\n s.gsub!(key, value.upcase)\n}\n\nputs s.downcase\n\n"}, {"source_code": "n = gets.split(' ')[1].to_i\ns = gets\nhash = {}\n\"a\".upto(\"z\") { |s| hash[s] = s }\nn.times do\n a = gets.split(' ')\n tmp = hash[a[0]]\n hash[a[0]] = hash[a[1]]\n hash[a[1]] = tmp\nend\n\nhash.each { |key, value|\n s.gsub!(key, value)\n}\n\nputs s\n\n"}, {"source_code": "n = gets.split(' ')[1].to_i\ns = gets\nn.times do\n a = gets.split(' ')\n s.gsub!(a[0], a[1])\nend\n\nputs s\n\n"}, {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nm = Integer(input[1])\nname = gets.chomp.split(\"\")\ndesign_request = []\nfor i in 0...m\n design_request[i] = []\n design_request[i] = gets.chomp.split\nend\ndesign = []\nfor i in 0...m\n if design_request[i][0] != design_request[i][1]\n design.push(design_request[i])\n end\nend\n\nl = design.length\nx = design[0][0]\ny = design[0][1]\nreplace = [design[0], [y, x]]\n\nfor i in 1...l\n a = 0\n b = 0\n for j in 0...replace.length \n if replace[j][1] == design[i][0]\n replace[j][1] = design[i][1]\n a = 1 \n break \n end\n if replace[j][1] == design[i][1]\n replace[j][1] = design[i][0]\n b = 1\n end\n end\n if a == 0\n replace.push(design[i])\n end\n if b == 0\n replace.push([design[i][1], design[i][0]])\n end\nend\n\nfor i in 0...n\n for j in 0...replace.length\n if name[i] == replace[j][0]\n name[i] = replace[j][1]\n break\n end\n end\nend\nprint name.join\nputs"}, {"source_code": "l = gets.to_i\np = gets.to_i\nq = gets.to_i\n\nputs l * ( p * 1.0 / (p + q) )\n"}], "src_uid": "67a70d58415dc381afaa74de1fee7215"} {"source_code": "t = gets.to_i\n\nt.times do\n n = gets.to_i\n sum = ((1 + n)*n)/2\n step = 1\n while step <= n\n sum -= 2*step\n step *= 2\n end\n puts(sum)\nend", "positive_code": [{"source_code": "t = gets.to_i\n\nt.times do\n n = gets.to_i\n sum = ((1 + n)*n)/2\n n = 1 + Math.log(n,2).to_i\n sum -= 2 * (2**n - 1)\n puts(sum)\nend\n"}, {"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\tans = n * (n + 1) / 2\n\t\ttmp = 1\n\t\twhile tmp <= n do\n\t\t\tans -= 2 * tmp\n\t\t\ttmp *= 2\n\t\tend\n\t\tputs ans\n\tend\nend\n\ncase_cnt = gets.to_i\ncase_cnt.times do\n\tSolver.new.main\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = (1 + n) * n / 2\n x = 1\n while x <= n do\n a -= 2 * x\n x *= 2\n end\n puts a\nend\n"}, {"source_code": "#!/usr/bin/ruby\ndef solve(n)\n\ti=1\n\ti*=2 while i*2<=n\n\tn*(n+1)/2-2*(i*2-1)\nend\nputs gets.to_i.times.map{solve(gets.to_i)}"}, {"source_code": "#!/usr/bin/env ruby\n\n\n\n\tt=gets.chomp.to_i\n\ti=0\n\twhile i lessOrEqThan\n return sum\n end\n\n sum += powerOf2\n end\nend\n\nt.times.each do\n n = gets.to_i\n\n sum = (n*(n+1)/2) - (2*sumPowerOf2(n))\n\n puts sum\nend\n"}, {"source_code": "n=gets.to_i\n\nn.times{\n\tans=0\n\ta=gets.to_i\n\tans=a*(a+1)/2\n\tb=1\n\twhile b<=a\n\t\tans-=(b*2)\n\t\tb*=2\n\tend\n\tputs ans\n}\n\n\n"}, {"source_code": "def sum_of_two(n)\n r, x = 0, 1\n while x <= n\n r += x\n x *= 2\n end\n r\nend\nt = gets.to_i\n(0...t).each do |i|\n n = gets.to_i\n v = n * (n + 1) / 2\n puts v - sum_of_two(n) * 2\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n res = n*(n+1)/2\n i = 1\n while i <= n do\n res -= 2*i\n i *= 2\n end\n puts res\nend\n"}, {"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n n = gets.to_i\n sum = (n*(n+1))/2\n powersum = 0\n i = 0\n loop {\n power = 1 << i\n if power <= n\n powersum += power\n i += 1\n else\n break\n end\n }\n\n puts sum - 2*powersum\n}"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n s = n * (n + 1) / 2\n m = 1\n while m <= n\n s -= 2 * m\n m <<= 1\n end\n puts s\nend\n"}, {"source_code": "num = gets.chomp.to_i\n\nnum.times do\n n = gets.chomp.to_i\n res = (1 + n) * n / 2\n (Math.log2(n).to_int+1).times do |n|\n res -= 2 * (2 ** (n))\n end\n puts res\nend"}, {"source_code": "t = gets.chomp.to_i\nfor i in 1..t\n\tn = gets.chomp.to_i\n\tk = (Math.log(n) / Math.log(2)).floor + 2\n\ts = n*(n+1)/2 - 2**k+2\n\tputs s\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n ans = (1 + n) * n / 2\n minus = 1\n while minus <= n\n ans -= minus * 2\n minus *= 2\n end\n puts ans\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n minus = 0\n 30.times do |i|\n break if 2 ** i > n\n minus += 2 ** i\n end\n puts (1 + n) * n / 2 - 2 * minus\nend\n"}, {"source_code": "def cal(n)\n r = (1+n)*n/2\n k = 1\n while k <= n\n r -= k * 2\n k *= 2\n end\n r\nend\n\nt = gets.to_i\n\n(1..t).each do\n n = gets.to_i\n puts cal(n)\nend\n"}, {"source_code": "n = gets.to_i\nfor i in 1..n\n\tk = gets.to_i\n\ts = (k*(k+1))/2\n\tv = 1\n\twhile v<=k\n\t\ts-=v*2\n\t\tv*=2\n\tend\n\tputs(s)\nend"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n power2 = []\n snd = 1\n i = 1\n while snd <= n\n power2 << snd\n snd = 2**i\n i += 1\n end\n puts n*(n+1)/2 - 2 * power2.inject(:+)\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\nlen = gets.to_i\nfor iter in 0..len - 1\n t = gets.to_i\n pow = (Math.log(t) / Math.log(2)).to_i\n puts t * (t + 1) / 2 - (2 ** (pow + 1) - 1) * 2\nend\n"}, {"source_code": "l=gets.chomp.to_i\np=[]\n0.upto(l-1)\t{|i| p[i]=gets.chomp.to_i}\n\ndef Ans(a)\n\tk=(a*(a+1))/2-(2*(2**((Math.log(a,2).to_i+1))-1))\n\treturn k\nend\t\n0.upto(l-1){|i| puts Ans(p[i])}\n\n"}], "negative_code": [{"source_code": "# c598-A\n\ndef tricky_sum(n)\n\tp = Math.log(n,2)\n\tn * (n+1) / 2 - 2 ** p + 2\nend\n\nt = gets.to_i\nt.times do\n\tputs tricky_sum(gets.to_i)\nend\n\n\n"}, {"source_code": "# c598-A\n\ndef tricky_sum(n)\n\tp = Math.log(n,2).to_i\n\tn * (n+1) / 2 - 2 ** p + 2\nend\n\nt = gets.to_i\nt.times do\n\tputs tricky_sum(gets.to_i)\nend\n\n\n"}, {"source_code": "t = gets.to_i\n\nt.times do\n n = gets.to_i\n sum = ((1 + n)*n)/2\n step = 1\n while step <= n\n sum -= step\n step *= 2\n end\n puts(sum)\nend"}], "src_uid": "a3705f29b9a8be97a9e9e54b6eccba09"} {"source_code": "a = gets.to_i\nputs \"#{10**20 - a} #{10**20 + a - 1}\"\n", "positive_code": [{"source_code": "a=gets.to_i\nr=(45*20*10**19+1)%a\nputs \"#{a-r+1} #{a-r+10**20}\""}], "negative_code": [], "src_uid": "52b8d97f216ea22693bc16fadcd46dae"} {"source_code": "pa=Array.new\npb=Array.new\npc=Array.new\npd=Array.new\n\nstr=gets.to_s\npa=str.split\nn=pa[0].to_i\nm=pa[1].to_i\nfor i in 0..n-1\n pb[i]=gets.to_s\n pc[i]=0\nend\n\nk=0\nfor j in 0..m-1\n r=flag=0\n for i in 0..n-2\n if pc[i]==0 && pb[i][j]>pb[i+1][j]\n k+=1\n flag=1\n break\n elsif pc[i]==0 && pb[i][j] W[j + 1][i]\n when -1\n b[j] = true\n when 1\n ok = false\n c += 1\n break\n end\n end\n a = b if ok\nend\n\nputs c\n"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\n\nn, m = read_ints\nb = n.times.map{gets.rstrip}\nis_g = [true] + [false] * (n-1)\nans = 0\n\n(0.. m-1).each do |j|\n if (1..n-1).all? {|i| is_g[i] || b[i][j] >= b[i-1][j]}\n (1..n-1).each do |i|\n is_g[i] = true if b[i][j] > b[i-1][j]\n end\n else\n ans += 1\n end\nend\n\nputs ans\n"}, {"source_code": "# 496C\n\nrequire 'set'\n\nn, m = gets.chomp.split.map &:to_i\nmatrix = (1..n).map { gets.chomp.chars }\ncount = 0\nto_check = Set.new(0...n)\nm.times do |i|\n checked = Set.new\n (1...n).collect do |j|\n next unless to_check.include? j\n if matrix[j][i] < matrix[j - 1][i]\n count += 1\n break\n elsif matrix[j][i] > matrix[j - 1][i]\n checked << j\n end\n end || next\n to_check -= checked\nend\nputs count"}], "negative_code": [], "src_uid": "a45cfc2855f82f162133930d9834a9f0"} {"source_code": "main = -> {\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n cur = 0\n while cur + 1 < n && a[cur + 1] <= a[cur]\n cur += 1\n end\n\n while cur + 1 < n && a[cur + 1] >= a[cur]\n cur += 1\n end\n\n cur + 1 == n ? \"YES\" : \"NO\"\n}\n\nt = gets.to_i\nputs t.times.map{ main.call }.join(\"\\n\")\n", "positive_code": [{"source_code": "gets.to_i.times{\n gets\n climbing=0\n sinked=0\n climbed=0\n valley=1\n s=gets.split.map(&:to_i)\n (s.size-1).times {|i|\n if s[i]s[i+1]\n if climbing==1\n valley=0\n end\n sinked=1\n climbing=0\n end\n }\n if valley==1\n puts(\"YES\")\n else\n puts(\"NO\")\n end\n}"}, {"source_code": "=begin\n\nWelcome to GDB Online.\nGDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,\nC#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.\nCode, Compile, Run and Debug online from anywhere in world.\n\n=end\n\nt=gets.to_i\nfor i in 1..t\n n =gets.to_i\n s=gets\n maks=s.split.map{|x|x.to_i}\n num=1\n inc=0\n prev=maks[0]\n for j in 1..(n-1)\n if (maks[j]>prev)\n inc=1\n elsif (maks[j]0\r\n c+=1\r\n d=1\r\n end\r\n else\r\n if x[i+1]-x[i]<0\r\n c+=1\r\n d=-1\r\n end\r\n end\r\n }\r\n puts c<2 ? \"YES\" : \"NO\"\r\n}"}], "negative_code": [], "src_uid": "7b6a3de5ad0975e4c43f097d4648c9c9"} {"source_code": "s = gets.chomp\nt = Time.now\n# s = 'a' * 10 ** 5\nf = true\nz = 0\nprev = [s[0]]\nprev_ind = 0\ncur = s[1]\ni = 2\nwhile i <= s.size do\n if (cur == prev.last)\n # puts cur, prev.last, \"1----\"\n prev.pop\n cur = s[i]\n i += 1\n f = !f\n else\n if (s[i] != cur)\n prev << cur\n cur = s[i]\n i += 1\n else\n # puts s[i], cur, \"2----\"\n cur = s[i + 1]\n i += 2\n f = !f\n end\n end\nend\nif (cur == prev.last && !cur.nil? && cur != '')\n # puts prev.last, cur, \"3----\"\n f = !f\nend\nputs f ? \"No\" : \"Yes\"\n# puts Time.now - t", "positive_code": [{"source_code": "s=gets.chomp\nt=[]\ns.bytes{|c|\nt<0 ? :Yes : :No"}, {"source_code": "s = gets.chomp\nused = Array.new(s.size,false)\nl = 0\nt = []\nfor r in 1..s.size-1\n next if l == r\n if s[l] == s[r]\n used[l] = used[r] = true\n if t.empty?\n l = r+1\n else\n l = t[-1]\n t.pop\n end\n else\n t.push(l)\n l = r\n end\nend\nputs [\"No\",\"Yes\"][used.count(true)/2%2]"}, {"source_code": "DBG = !true\ns = gets.chomp\ncnt = 0\na = []\nfor i in 0...s.size\n a.push(s[i])\n if a.size >= 2 && a[-1] == a[-2]\n a.pop\n a.pop\n cnt += 1\n end\nend\nputs ((cnt%2 == 1) ? \"Yes\" : \"No\")\n"}, {"source_code": "s = gets.chomp\nchars = s.split('')\n\ncount = 0\na = Array.new\nchars.each { |i|\n\tif a[a.size - 1] != i\n\t\ta << i\n\telse\n\t\ta.pop()\n\t\tcount += 1\n\tend\n}\nif count % 2 == 1\n\tputs \"Yes\"\nelse\n\tputs \"No\"\nend"}], "negative_code": [{"source_code": "s=gets.chomp\nt=''.dup\ns.chars{|c|\nt<0 ? :No : :Yes"}, {"source_code": "s = gets.chomp\nt = Time.now\n# s = 'a' * 10 ** 5\nf = true\nz = 0\nprev = s[0]\nprev_ind = 0\ncur = s[1]\ni = 2\nwhile i < s.size do\n if (cur == prev)\n # puts cur, prev, \"----\"\n prev_ind = [prev_ind - 1, 0].max\n prev = s[prev_ind]\n cur = s[i]\n i += 1\n f = !f\n else\n if (s[i] != cur)\n prev = cur\n prev_ind = [i - 1, 0].max\n cur = s[i]\n i += 1\n else\n # puts s[i], cur, \"----\"\n cur = s[i + 1]\n i += 2\n f = !f\n end\n end\nend\nif (cur == prev && cur != '')\n # puts prev, cur, \"----\"\n f = !f\nend\nputs f ? \"No\" : \"Yes\""}, {"source_code": "s = gets.chomp\nt = Time.now\n# s = 'a' * 10 ** 5\nf = true\nz = 0\nprev = [s[0]]\nprev_ind = 0\ncur = s[1]\ni = 2\nwhile i < s.size do\n if (cur == prev.last)\n # puts cur, prev.last, \"----\"\n prev.pop\n cur = s[i]\n i += 1\n f = !f\n else\n if (s[i] != cur)\n prev << cur\n cur = s[i]\n i += 1\n else\n # puts s[i], cur, \"----\"\n cur = s[i + 1]\n i += 2\n f = !f\n end\n end\nend\nif (cur == prev.last && cur != '')\n # puts prev, cur, \"----\"\n f = !f\nend\nputs f ? \"No\" : \"Yes\""}, {"source_code": "s = gets.chomp\nt = Time.now\n# s = 'a' * 10 ** 5\nf = true\nz = 0\nprev = s[0]\nprev_ind = 0\ncur = s[1]\ni = 2\nwhile i < s.size do\n if (cur == prev)\n # puts cur, prev, \"----\"\n prev_ind -= 1\n prev = s[prev_ind]\n if (prev_ind < 0)\n prev_ind = 0\n prev = ''\n end\n cur = s[i]\n i += 1\n f = !f\n else\n if (s[i] != cur)\n prev = cur\n prev_ind = [i - 1, 0].max\n cur = s[i]\n i += 1\n else\n # puts s[i], cur, \"----\"\n cur = s[i + 1]\n i += 2\n f = !f\n end\n end\nend\nif (cur == prev && cur != '')\n # puts prev, cur, \"----\"\n f = !f\nend\nputs f ? \"No\" : \"Yes\""}, {"source_code": "DBG = !true\ns = gets.chomp\ncnt = 0\ncur = 0\nwhile cur < s.size\n if s[cur] != s[cur+1]\n cur += 1\n next\n end\n puts \"loop on cur #{cur}\" if DBG\n len = 1\n while 0 <= cur - len && cur+1+len < s.size &&\n s[cur-len] == s[cur+1+len]\n len += 1\n end\n cur += len+1\n cnt += len\n puts \"cur #{cur} cnt #{cnt}\" if DBG\nend\nputs ((cnt%2 == 1) ? \"Yes\" : \"No\")\n"}], "src_uid": "8fd51c391728b433cc94923820e908ff"} {"source_code": "require 'pp'\n\nn, l = STDIN.gets.chomp.split(/ /).map(&:to_i)\na = STDIN.gets.chomp.split(/ /).map(&:to_i)\n\na.sort!\n\nd2 = 0\n\n(a.count-1).times do |i|\n d2 = [d2, a[i+1] - a[i]].max\nend\n\nd = [d2.to_f/2, a.first, l-a.last].max\nputs d\n", "positive_code": [{"source_code": "n,l = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\narr.sort!\ndiff = []\n(1..n-1).each do |i|\n\tdiff << arr[i] - arr[i-1]\nend\n\nmax_diff = diff.max || 0\nans = max_diff / 2.0\nval = arr[0] unless arr.include?(0)\nans = val if val && val > ans\n\nval = l - arr[-1] unless arr.include?(l)\nans = val if val && val > ans\n\n\nputs ans.to_f"}, {"source_code": "n, l = gets.split.map(&:to_i)\nq = gets.split.map(&:to_i)\n\nq = q.uniq.sort\n\nr = 2 * [q[0].to_f, (l - q[-1])].max\n\nfor i in (1..q.size-1)\n if r < q[i] - q[i-1]\n r = q[i] - q[i-1]\n end\nend\n\nputs r.to_f/2\n"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\n\nn, l = read_ints\na = read_ints.sort\na << -a[0] << 2 * l - a[-2]\nputs a.sort.each_cons(2).map {|x| x[1] - x[0]}.max / 2.0"}, {"source_code": "n, l = gets.split(' ').map(&:to_i)\na = gets.split(' ').map(&:to_i).sort\ncurrent = -a.first\na.push l + l-a.last\nresult = 0\n\nuntil a.empty? \n result = [(a.first-current)/2.0, result].max\n current = a.shift\nend\n\np result\n"}, {"source_code": "# 492B\n\ndef read_next_line\n gets.chomp.split.map &:to_i\nend\n\nn, l = read_next_line\na = read_next_line.sort\nb = []\n(0...n - 1).each { |i| b << a[i + 1] - a[i] }\nputs [a[0], l - a[-1], b.max.to_f / 2].max"}, {"source_code": "n, l = gets.split.map { |x| x.to_i }\na = gets.split.map { |x| x.to_i }\na.sort!\n\nf = [a[0] * 2, (l - a[-1]) * 2]\n1.upto(n - 1) do |i|\n\tf << (a[i] - a[i - 1])\nend\n\nans = f.max / 2.0\nputs '%.12f' % ans\n"}, {"source_code": "n, l = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort\n\nans = ([a[0],l-a[n-1]].max)*1.0\n\ni = 0\n(n-1).times do\n ans = [ans,(a[i+1]-a[i])*0.5].max\n i += 1\nend\n\nputs ans\n"}, {"source_code": "n, l = gets.split(' ').map(&:to_i)\narr = gets.split(' ').map(&:to_i)\n\narr = arr.sort\nres = [arr[0], l - arr[n-1]]\nfor i in (1...n)\n res.push((arr[i] - arr[i-1]) / 2.0)\nend\n\np res.max"}, {"source_code": "# http://codeforces.com/contest/492/problem/B\nn, l = gets.chomp.split.map(&:to_i)\nlanterns = gets.chomp.split.map(&:to_f).sort\n\narr = [lanterns.first - 0, l - lanterns.last]\nlanterns.each_cons(2){ |a, b| arr << (b - a) / 2.0 }\n\nputs arr.max\n"}, {"source_code": "input = gets.chomp\nginp = input.split ' '\n\nb, s = ginp.first.to_i, ginp.last.to_i\n\nai = gets.chomp().split(' ').map(&:to_i).sort!\nmax = ai[0] > (s - ai.last) ? ai[0] : (s - ai.last)\nai.each_with_index do |v, i|\n res = ((ai[i+1] - v) / 2.0).to_f unless i == b-1\n max = res if res && res > max\nend\nputs max.to_f"}, {"source_code": "a,b=gets.chomp.split.map(&:to_i)\nc=gets.chomp.split.map(&:to_i).sort\nmax=2*c[0]\nmax=(b-c[a-1])*2 if 2*(b-c[a-1])>max\nfor i in 0...a-1 do\n\tmax=c[i+1]-c[i] if c[i+1]-c[i]>max\nend\nputs max/2.0"}, {"source_code": "n, l = gets.split.map &:to_i\narr = gets.split.map { |x| x.to_i }.sort\nmax_dif = 0\nfor i in 0..arr.size - 2\n if arr[i + 1] - arr[i] > max_dif\n max_dif = arr[i + 1] - arr[i]\n end\nend\nd = [arr.first, (l - arr.last), max_dif / 2.0].max\nprintf \"%.9f\",d\n"}, {"source_code": "n, l = gets.split.map(&:to_i)\na = gets.split(\" \")\na.each_index{|i| a[i]=a[i].to_i}\na.sort!\nbest = 0\na.each_index{|i|\n if i>0\n best = [best,a[i]-a[i-1]].max\n end\n}\nputs [a[0], l-a[a.size-1], best/2.0].max"}, {"source_code": "n, l = gets.split.map(&:to_i)\np = gets.split.map(&:to_i).sort\n\ndiff = [0]\n(1...p.length).each do |i|\n diff << p[i] - p[i - 1]\nend\n\nmax = [l - p.max, diff.max / 2.0, p.min].max\nputs max"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\nn, l = gets.chomp.split.map(&:to_i)\np = gets.chomp.split.map(&:to_i).sort\n\nmax = -1\ny = p[0] - 0 if 0 < p[0] - 0\nmax = y if y != nil and max < y\ny = l - p[-1] if 0 < l - p[-1]\nmax = y if y != nil and max < y\nx = -1\np.each do |i|\n y = (i - x) / 2.0 unless x < 0\n max = y if y != nil and max < y\n x = i\nend\n\nputs \"#{max}\"\n\n"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\n\nn, l = read_ints\na = read_ints.sort\na << -a[0] << 2 * l - a[-2]\nputs a.sort.each_cons(2).map {|x| x[1] - x[0]}.max / 2.0\n"}, {"source_code": "n,l=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_f}\n\nx.sort!\nans=[x[0],l-x.last].max\n\n0.upto(x.size-2){|i|\n\td=(x[i+1]-x[i])/2.0\n\tans=[ans,d].max\n}\nputs sprintf(\"%.10f\",ans)"}, {"source_code": "#!/usr/bin/env ruby -w\n\ndef main\n _, l = gets.split.map(&:to_i)\n lights = gets.split.map(&:to_i)\n puts light_radius(l, lights)\nend\n\ndef light_radius(street_length, lights)\n lights.sort!\n\n distances = []\n distances << lights.first\n distances << street_length - lights.last\n\n lights.each_cons(2) do |foo, bar|\n distances << (bar - foo) / 2.0\n end\n\n distances.max\nend\n\nmain if __FILE__ == $0\n"}, {"source_code": "n,l = gets.chomp.split.map(&:to_i)\narr = gets.chomp.split.map(&:to_i)\n\nres = 0\narr.sort!\nif arr[0] != 0\n res = [res,arr[0]].max\nend\nif arr[n-1] != n\n res = [res, l - arr[n-1]].max\nend \n\nfor i in 0...n-1\n res = [res,(arr[i+1]-arr[i])/2.0].max\nend\n\nputs res"}, {"source_code": "n,l = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort\nx = 0\nfor i in 0...n\n\tx = [ a[i] - a[i - 1] , x ].max\nend\nx = x/2.00\nputs [ x , a[0], l-a[n-1] ].max\n\n"}, {"source_code": "input = gets.chomp\nginp = input.split ' '\n\nn, l = ginp.first.to_i, ginp.last.to_i\n\nai = gets.chomp().split(' ').map(&:to_i).sort!\nmax = ai[0] > (l - ai.last) ? ai[0] : (l - ai.last)\nai.each_with_index do |v, i|\n x = ((ai[i+1] - v) / 2.0).to_f unless i == n-1\n max = x if x && x > max\nend\nputs max.to_f"}, {"source_code": "def main\n n, l = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i).sort!\n ans = [a[0], l - a[-1]].max.to_f\n (1...n).each do |i|\n ans = [ans, (a[i] - a[i - 1]) * 0.5].max\n end\n ans\nend\n\nputs main"}, {"source_code": "nums = gets.chomp.split\nn = Integer(nums[0])\nl = Integer(nums[1])\nnums2 = gets.chomp.split\nlanterns = Array.new\nfor i in 0...nums2.length\n lanterns[i] = Integer(nums2[i])\nend\n\nif n == 1\n x = lanterns[0]\n y = l - lanterns[0]\n if x >= y\n puts x\n else\n puts y\n end\nelse\n lanterns.sort!\n a = lanterns[0]\n c = l - lanterns[n-1]\n dis = lanterns[1] - lanterns[0]\n for i in 0...n-1\n b = lanterns[i+1] - lanterns[i]\n if b > dis\n dis = b\n end\n end\n dis = dis.to_f / 2\n\n max = Array.new\n max.push(a)\n max.push(dis)\n max.push(c)\n\n max.sort!\n puts max[2]\nend\n"}], "negative_code": [{"source_code": "n, l = gets.split.map(&:to_i)\np = gets.split.map(&:to_i).sort\n\ndiff = [0]\n(1...p.length).each do |i|\n diff << p[i] - p[i - 1]\nend\n\nmax = [l - p.max, diff.max / 2.0, diff.min].max\nputs max"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\nn, l = gets.chomp.split.map(&:to_i)\np = gets.chomp.split.map(&:to_i).sort\n\nmax = -1.000000000\ny = p[0] - 0 if 0 < p[0] - 0\nmax = y if y != nil and max < y\ny = l - p[-1] if 0 < l - p[-1]\nmax = y if y != nil and max < y\nx = -1\nmax = -1\np.each do |i|\n y = (i - x) / 2.000000000 unless x < 0\n max = y if y != nil and max < y\n x = i\nend\n\nputs \"#{max}\"\n\n"}, {"source_code": "n,l = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\narr.sort!\ndiff = []\n(1..n-1).each do |i|\n\tdiff << arr[i] - arr[i-1]\nend\n\nmax_diff = diff.max || 0\nans = max_diff / 2\nval = arr[0] unless arr.include?(0)\nans = val if val && val > ans\n\nval = l - arr[-1] unless arr.include?(l)\nans = val if val && val > ans\n\n\nputs ans.to_f"}, {"source_code": "n, l = gets.split.map(&:to_i)\nq = gets.split.map(&:to_i)\n\nq = q.uniq.sort\n\nr = 2 * [q[0].to_f, (l - q[-1])].max\nputs r\n\nfor i in (1..q.size-1)\n if r < q[i] - q[i-1]\n r = q[i] - q[i-1]\n end\nend\n\nputs r.to_f/2\n"}], "src_uid": "d79166497eb61d81fdfa4ef80ec1c8e8"} {"source_code": "t=gets.to_i\nt.times{\n n,c0,c1,h=gets.split.map &:to_i\n bin=gets.chomp\n if c0 == c1\n puts bin.size*c0\n elsif c0 < h && c1 < h\n puts bin.count(\"0\")*c0+bin.count(\"1\")*c1\n else\n if c0 + h < c1\n puts bin.size*c0 + bin.count(\"1\")*h\n elsif c1 + h < c0\n puts bin.size*c1 + bin.count(\"0\")*h\n else\n puts bin.count(\"0\")*c0+bin.count(\"1\")*c1\n end\n end\n}", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n n, c0, c1, h = gets.chomp.split(' ').map(&:to_i)\n s = gets.chomp.split('')\n res = 0\n s.each do |c|\n case c\n when '1'\n res += [c1, c0 + h].min\n when '0'\n res += [c0, c1 + h].min\n end\n end\n puts res\nend "}], "negative_code": [{"source_code": "t=gets.to_i\nt.times{\n n,c0,c1,h=gets.split.map &:to_i\n bin=gets.chomp\n if c0 == c1\n puts bin.size*c0\n elsif c0 < h && c1 < h\n puts bin.count(\"0\")*c0+bin.count(\"1\")*c1\n else\n if c0 + h < c1\n puts bin.size*c0 + bin.count(\"1\")*h\n elsif c1 + h < c0\n puts bin.size*c1 + bin.count(\"0\")*h\n end\n end\n}"}], "src_uid": "7cc0a6df601e3dcf4e1d9578dd599a36"} {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\np ((3..n).flat_map{|i|[*a.each_slice(n/i)].transpose.map{|c|c.inject:+}unless n%i>0}-[p]).max", "positive_code": [{"source_code": "n = gets.to_i\nar = gets.split(' ').map(&:to_i)\nans = ar.inject(:+)\n(2..(n/3)).each do |d|\n if n % d == 0\n m = (0...n).each_slice(d).map{|x| x}.transpose.map{|x|\n x.map{|y| ar[y]}.inject(:+)\n }.max\n ans = [ans,m].max\n end\nend\nputs ans"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\ns=a.inject &:+\n2.upto(n/3){|m|\nnext if n%m!=0\nm.times{|i|\nt=(i...n).step(m).map{|_|a[_]}.inject &:+\ns=t if s max\n end\nend\n\nputs max"}, {"source_code": "$n = gets.to_i\n$a = gets.split(/\\s+/).map { |i| i.to_i }\n$best = $a.inject(:+)\n\ndef count(start, step)\n\tres = 0\n\twhile start < $n do\n\t\tres += $a[start]\n\t\tstart += step\n\tend\n\tres\nend\n\ndef solve(step)\n\tstep.times do |i|\n\t\tcur = count(i, step)\n\t\t$best = cur if cur > $best\n\tend\nend\n\n(2..Math.sqrt($n).round.to_i).each do |i|\n\tif $n % i == 0\n\t\tsolve(i) if $n/i >= 3\n\t\tsolve($n/i) if i >= 3\n\tend\nend\nputs $best\n"}, {"source_code": "$n = gets.to_i\n$tis = []\ngets.split(' ').each {|x| $tis.push x.to_i}\n\n$k, $s = [], []\n\n3.upto($n) {|x| if $n % x == 0 then $k.push x end}\n\n$k.reverse!\n\n$k.each do |ki|\n step = $n / ki\n dots = $n / step\n shift = 0\n step.times do\n sum = 0\n i = 0\n dots.times do\n sum += $tis[i * step + shift]\n i += 1\n end\n $s.push sum\n shift += 1\n end \nend\n\n$s.sort! {|a, b| b <=> a}\nputs $s[0]\n"}, {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\nsum, max = 0, -(2**32)\n1.upto(n/3) { |i| if n%i == 0\n for j in (0...i)\n (j..n-1).step(i).map { |k| sum += x[k]} \n max = sum if max < sum\n sum = 0\n end\n end\n }\n puts max"}, {"source_code": "n=gets.to_i\na = gets.split.map(&:to_i)\n\ndef go(a, s)\n ret = -1111111111111\n b = 0\n while b < s\n ans = 0\n i = b\n while i < a.size\n ans += a[i]\n i += s\n end\n\n ret = ans if ans > ret\n b += 1\n end\n ret\n end\n\nans = -111111111\n1.upto(n) do |x|\n next if n % x != 0\n next if n / x < 3\n ret = go(a,x)\n ans = ret if ret > ans\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\nt = gets.split.map(&:to_i)\nsum = t.inject(:+)\n(1..n).each do |i|\n next if n / i < 3 || n % i != 0\n (0...i).each do |j|\n k = j\n ssum = 0\n while k < n\n ssum += t[k]\n k += i\n end \n sum = ssum if ssum > sum\n end\nend\nputs sum\n"}, {"source_code": "n = gets.to_i\nt = gets.split.map(&:to_i)\nans = t.inject(:+)\n1.upto(n / 3) do |i|\n next if n % i != 0\n i.times do |j|\n sum = j.step(n - 1, i).map{|x| t[x]}.inject(:+)\n ans = sum if sum > ans\n end\nend\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.split.collect{|x| x.to_i}\n \nmax = 0\narr.collect{|i| max += i}\n \nfor i in (1..(n/3))\n next if n % i != 0 or n / i < 3\n for j in (0..i-1)\n sum = 0\n (0..n-1).step(i) {|idx|\n sum += arr[idx+j] \n }\n max = sum if sum > max\n end\nend\n\nputs max"}, {"source_code": "n = Integer(gets.chomp)\nseq = gets.chomp.split.map { |x| x.to_i }\nmax = seq.inject(:+)\nfor i in 2..n / 3\n if n % i == 0 && n / i > 2\n for j in 0..i - 1\n sum = 0\n for k in (j...n).step(i)\n sum += seq[k]\n end\n max = sum if sum > max\n end\n end\nend\nputs max"}], "negative_code": [{"source_code": "n=gets.to_i\na=gets.split.map &:to_i\np ((3..n).flat_map{|i|a.each_slice(n/i).inject(0){|j,k|j+k.inject(:+)}unless n%i>0}-[p]).max"}, {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\nsum, max = 0, 0\n1.upto(n/3) { |i| if n%i == 0\n for j in (0...i)\n (j..n-1).step(i).map { |k| sum += x[k]} \n max = sum if max < sum\n sum = 0\n end\n end\n }\n puts max"}, {"source_code": "n=gets.to_i\na = gets.split.map(&:to_i)\n\na.sort!.reverse!\n\nans = 0\ni = 0\nwhile i < a.length\n break if i >= 3 and a[i] < 0\n ans += a[i]\n i += 1\nend\n\nputs ans\n\n"}, {"source_code": "n=gets.to_i\na = gets.split.map(&:to_i)\n\ndef go(a, s)\n ret = 0\n b = 0\n while b < s\n ans = 0\n i = b\n while i < a.size\n ans += a[i]\n i += s\n end\n\n ret = ans if ans > ret\n b += 1\n end\n ret\n end\n\nans = -111111111\n1.upto(n) do |x|\n next if n % x != 0\n next if n / x < 3\n ret = go(a,x)\n ans = ret if ret > ans\nend\n\nputs ans\n"}, {"source_code": "n=gets.to_i\na = gets.split.map(&:to_i)\n\ndef go(a, s)\n ret = 0\n b = 0\n while b < s\n ans = 0\n i = b\n while i < a.size\n ans += a[i]\n i += s\n end\n\n ret = ans if ans > ret\n b += 1\n end\n ret\n end\n\nans = -111111111\n1.upto(n) do |x|\n next if n % x != 0\n ret = go(a,x)\n ans = ret if ret > ans\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\nt = gets.split.map(&:to_i)\nsum = t.inject(:+)\nnn = 2 * n ** 0.5\n(0..nn).each do |i|\n next if i != 0 && n / i < 3\n (0...i).each do |j|\n k = j\n ssum = 0\n while k < n\n ssum += t[k]\n k += i\n end \n sum = ssum if ssum > sum\n end\nend\nputs sum\n"}, {"source_code": "n = gets.to_i\nt = gets.split.map(&:to_i)\nsum = t.inject(:+)\nnn = 2 * n ** 0.5\n(0..nn).each do |i|\n (0...i).each do |j|\n k = j\n ssum = 0\n while k < n\n ssum += t[k]\n k += i\n end \n sum = ssum if ssum > sum\n end\nend\nputs sum\n"}, {"source_code": "n = gets.to_i\nt = gets.split.map(&:to_i)\nsum = t.inject(:+)\nnn = 2 * n ** 0.5\n(0..nn).each do |i|\n next if i != 0 && n / i < 2\n (0...i).each do |j|\n k = j\n ssum = 0\n while k < n\n ssum += t[k]\n k += i\n end \n sum = ssum if ssum > sum\n end\nend\nputs sum\n"}, {"source_code": "n = gets.to_i\nt = gets.split.map(&:to_i)\nsum = t.inject(:+)\nnn = 2 * n ** 0.5\n(1..nn).each do |i|\n next if n / i < 3\n (0...i).each do |j|\n k = j\n ssum = 0\n while k < n\n ssum += t[k]\n k += i\n end \n sum = ssum if ssum > sum\n end\nend\nputs sum\n"}, {"source_code": "n = gets.to_i\nt = gets.split.map(&:to_i)\nsum = t.inject(:+)\nnn = 2 * n ** 0.5\n(3..nn).each do |i|\n (0...i).each do |j|\n k = j\n ssum = 0\n while k < n\n ssum += t[k]\n k += i\n end \n sum = ssum if ssum > sum\n end\nend\nputs sum\n"}], "src_uid": "0ff4ac859403db4e29554ca7870f5490"} {"source_code": "n = gets().to_i\ns = gets().chomp\ncur = nil\nres = 0\nans = 0\ncount1 = 0\ns.each_char do |c|\n if c == cur\n count1+=1\n else\n res += count1 + 1 if !cur.nil?\n if !cur.nil?\n break\n end\n cur = c\n count1 = 0\n end\nend\nans += res\nres = 0\ncur = nil\ncount = 0\ns.reverse.each_char do |c|\n if c == cur\n count+=1\n else\n res += count + 1 if !cur.nil?\n if !cur.nil?\n break\n end\n cur = c\n count = 0\n end\nend\nans += res\nif (s[0] == s[-1])\n ans += (count + 1) * (count1 + 1)\nend\n\nputs (ans + 1) % 998244353", "positive_code": [{"source_code": "N = gets.to_i\nS = gets.chomp.split(\"\").map &:intern\nMod = 998244353\nans = 1\nH,T = S[0],S[-1]\nmh = S.index{ |c| c != H }\nmt = N - S.rindex{ |c| c != T } - 1\nans = (ans + mh) % Mod\nans = (ans + mt) % Mod\nif S[0] == S[-1]\n ans = (ans + mh*mt) % Mod\nend\np ans"}, {"source_code": "n = gets.to_i\ns = gets.strip\ni = 1\nwhile i < s.size\n break if s[i] != s[i - 1]\n i += 1\nend\nj = s.size - 2\nj = s.size - 1 if i == s.size\nwhile j >= 0 && j >= i\n break if s[j] != s[j + 1]\n j -= 1\nend\n\nnx = i\nny = s.size - 1 - j\n\nans = nx + ny + 1\nans = (1 + nx)*nx/2 if s[0] == s[-1]\nans = (1 + nx)*(1 + ny) if i <= j && s[0] == s[-1]\np ans%998244353\n"}], "negative_code": [{"source_code": "n = gets().to_i\ns = gets().chomp\ncur = nil\nres = 0\nans = 0\ncount1 = 0\ns.each_char do |c|\n if c == cur\n count1+=1\n else\n res += count1 + 1 if !cur.nil?\n if !cur.nil?\n break\n end\n cur = c\n count1 = 0\n end\nend\nans += res\nres = 0\ncur = nil\ncount = 0\ns.reverse.each_char do |c|\n if c == cur\n count+=1\n else\n res += count + 1 if !cur.nil?\n if !cur.nil?\n break\n end\n cur = c\n count = 0\n end\nend\nans += res\nif (s[0] == s[-1])\n ans += (count + 1) * (count1 + 1)\nend\n\nputs ans + 1"}], "src_uid": "9693f60fc65065d00a1899df999405fe"} {"source_code": "n,m=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i).sort if m>0\nflag=0\nm.times do |i|\n\tif a[i]==1 || a[i]==n\n\t\tflag=1;\n\t\tbreak;\n\telsif i>1 && a[i-1]==a[i]-1 && a[i-2]==a[i]-2\n\t\tflag=1;\n\t\tbreak;\n\tend\nend\nputs (flag==0) ? \"YES\" : \"NO\"", "positive_code": [{"source_code": "n,m = gets.split(\" \").map(&:to_i)\nif m != 0\n\tdirty = gets.split(\" \").map(&:to_i)\n\tdirty.sort!\n\tans = true\n\tdirty.each_cons(3) do |a,b,c|\n\t\t# puts \"ele #{a} #{b} #{c}\"\n\t\t# puts \"diff #{b - a == 0 && c - b == 0}\"\n\t\tif b - a == 1 && c - b == 1\n\t\t\tans = false\n\t\t\tbreak\n\t\tend\n\tend\n\tans = false if dirty.include?(1) || dirty.include?(n)\n\tputs ans ? \"YES\" : \"NO\"\nelse\n\tputs \"YES\"\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nif m==0 \n puts \"YES\"\n exit\nend\na = gets.split.map(&:to_i).sort\n\nb = true\n\n(2..m-1).each do |i|\n if a[i-2]+2 == a[i] \n b = false\n break\n end\nend\n\nputs a.first != 1 && a.last !=n && b ? \"YES\" : \"NO\""}, {"source_code": "def can(n, m, d)\n return true if m == 0\n return false if d[0] == 1 or d[m - 1] == n\n 0.upto(m - 3) do |i|\n break if i + 2 >= m\n return false if d[i] + 1 == d[i + 1] and d[i + 1] + 1 == d[i + 2]\n end\n return true\nend\n\nn, m = *gets.split.map(&:to_i)\nd = (m == 0) ? [] : gets.split.map(&:to_i).sort\n\nputs can(n, m, d) ? \"YES\" : \"NO\""}, {"source_code": "require 'set'\n\nn,m=gets.split.map(&:to_i)\nif m > 0\n a=gets.split.map(&:to_i).to_set\nelse\n a = Set.new\nend\n\nif a.include?(1) || a.include?(n)\n puts 'NO'\n exit\nend\n\na.each do |x|\n if a.include?(x+1) && a.include?(x+2)\n puts 'NO'\n exit\n end\nend\n\nputs 'YES'"}, {"source_code": "def read_next_line\n gets.split.map { |x| x.to_i }\nend\n\nn, m = read_next_line\nif m == 0\n puts 'YES'\n exit\nend\n\na = read_next_line.sort\nif a[0] == 1 || a[m - 1] == n\n puts 'NO'\n exit\nend\n\nif a.size > 2\n for i in 0...m - 2\n if a[i] == a[i + 1] - 1 && a[i] == a[i + 2] - 2\n puts 'NO'\n exit\n end\n end\nend\nputs 'YES'"}], "negative_code": [{"source_code": "n, m = gets.split.map(&:to_i)\na = gets.split.sort.map(&:to_i)\n\nb = true\n\n(2..m-1).each do |i|\n if a[i-2]+2 == a[i] \n b = false\n break\n end\nend\n\nputs a.first != 1 && a.last !=n && b ? \"YES\" : \"NO\""}], "src_uid": "422cbf106fac3216d58bdc8411c0bf9f"} {"source_code": "def solve(a)\n a.each_cons(2).map{|x,y| (x-y).abs}.reduce(a.first.abs, :+)\nend\n\ngets\na = gets.split.map(&:to_i)\nputs solve a\n", "positive_code": [{"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\tb = gets.split.map { |x| x.to_i }\n\t\tlast = 0\n\t\tans = 0\n\t\tb.each do |x|\n\t\t\tx -= last\n\t\t\tans += x.abs\n\t\t\tlast += x\n\t\tend\n\t\tputs ans\n\tend\nend\n\nSolver.new.main"}, {"source_code": "n = gets.chomp.to_i\nb = gets.chomp.split.map(&:to_i)\nc = 0\na = b.map do |a|\n t = (a - c).abs\n c = a\n t\nend\nputs a.inject(0, :+)\n"}, {"source_code": "n = gets.chomp.to_i\n\nb = gets.chomp.split.map(&:to_i)\n\nx = 0;\nanswer = 0;\nb.each do |i|\n x = (i-x)\n answer += x.abs\n x= i\n \nend \n\nputs answer"}, {"source_code": "n=gets\n\ndata=gets.chomp.split\n\nb=[]\n\ndata.each do |item|\n\tb.push(item.to_i)\nend\n\na=(b[0]).abs\nfor i in(0..b.length-2)\n\ta+=(b[i]-b[i+1]).abs\nend\n\nputs a"}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\n\nputs (1...n).to_a.inject (as[0].abs) { |s, i| s += (as[i] - as[i - 1]).abs }\n"}, {"source_code": "class Array\n def r\n self.map { |q| q.to_i }\n end\nend\n\nn = STDIN.gets.to_i\n\ncur = 0\nres = 0\nSTDIN.gets.split(\" \").to_a.r.each do |i|\n res += (cur - i).abs\n cur = i\nend\n\nputs res\n"}, {"source_code": "n = gets.to_i\na = [0] + gets.split.map(&:to_i)\nputs n.times.map{|i| (a[i + 1] - a[i]).abs}.inject(:+)\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\ne = 0\nres = 0\nn.times do |i|\n res += (a[i] - e).abs\n e = a[i]\nend\nputs res\n"}], "negative_code": [{"source_code": "n=gets\n\ndata=gets.chomp.split\n\nb=[]\n\ndata.each do |item|\n\tb.push(item.to_i)\nend\n\na=b[0]\nfor i in(0..b.length-2)\n\ta+=(b[i]-b[i+1]).abs\nend\n\nputs a"}, {"source_code": "n = STDIN.gets.to_i\n\ncur = 0\nres = 0\nn.times do\n i = STDIN.getc.to_i\n STDIN.getc\n res += (cur - i).abs\n cur = i\nend\n\nputs res\n"}], "src_uid": "97a226f47973fcb39c40e16f66654b5f"} {"source_code": "gets.to_i.times do\n a, b, n, s = gets.split(' ').map(&:to_i)\n\n p = [a, s.div(n)].min\n\n puts (s - p*n) <= b ? 'YES' : 'NO'\nend\n", "positive_code": [{"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2s\n s=s%n\n end\n ans << (s<=b ? 'YES' : 'NO')\nend\n\nputs ans"}, {"source_code": "#!/usr/bin/env ruby\ncount = gets.chomp.to_i\nanswers = []\ncount.times do\n input = gets.chomp.split(' ').map(&:to_i)\n a = input[0] # number of n coins\n b = input[1] # number of 1 coins\n n = input[2] # value of a coins\n sum = input[3] # wanted sum\n\n c = sum / n\n \n answers <<\n if (a <= c && a * n + b >= sum) || (a > c && c * n + b >= sum)\n \"YES\"\n else\n \"NO\"\n end\nend\n\nanswers.each { |answer| puts answer }\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\na = inp[0]\na.times do\n a,b,n,s = inp\n def is_able(useable_a_count, b, s, n)\n used_a_count = [(s/n), useable_a_count].min\n remnant = s - used_a_count * n\n return (remnant <= b)\n end\n puts is_able(a,b,s,n)? \"YES\" : \"NO\"\nend"}, {"source_code": "g = gets.chomp.to_i\ng.times{\na,b,n,s = gets.split(\" \").map{|x|x.to_i}\nmax_a = [(s/n).round,a].min*n\nmax_a+=b\nputs (max_a>=s)?\"YES\":\"NO\"\n}\n"}], "negative_code": [{"source_code": "g = gets.chomp.to_i\ng.times{\na,b,n,s = gets.split(\" \").map{|x|x.to_i}\nmax_a = 0\na.times{\nmax_a+=(max_a+n=s)?\"YES\":\"NO\"\n}\n\n"}], "src_uid": "e2434fd5f9d16d59e646b6e69e37684a"} {"source_code": "gets.chomp\na = gets.chomp.split(\" \").map(&:to_i)\n\nh = Hash.new(0)\na.each { |x| h[x] += 1 }\nh = h.sort_by { |k, v| v }.reverse\nk, v = h.first\nv = a.size - v\n\nputs v\nif v > 0\n base_pos = a.index(k)\n range = base_pos..0\n (range.first).downto(range.last).each do |i|\n if a[i] != k\n puts \"#{a[i] < k ? 1 : 2} #{i+1} #{i+2}\"\n end\n end\n\n for i in base_pos..a.size-1\n if a[i] != k\n puts \"#{a[i] < k ? 1 : 2} #{i+1} #{i}\"\n end\n end\nend\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = Hash.new(0)\nn.times do |i|\n b[a[i]] += 1\nend\nm = a[0]\nb.keys.each do |i|\n m = i if b[m] < b[i]\nend\nans = []\n(n-1).times do |i|\n if a[i] == m && a[i+1] != m\n if a[i] > a[i+1]\n ans << [1,i+2,i+1]\n else\n ans << [2,i+2,i+1]\n end\n a[i+1] = m\n end\nend\n(n-1).downto(1) do |i|\n if a[i] == m && a[i-1] != m\n if a[i] > a[i-1]\n ans << [1,i,i+1]\n else\n ans << [2,i,i+1]\n end\n a[i-1] = m\n end\nend\nputs ans.size\nans.each do |arr|\n puts arr.join(\" \")\nend"}], "negative_code": [{"source_code": "gets.chomp\na = gets.chomp.split(\" \").map(&:to_i)\nprint \"a: #{a}\\n\"\n\nh = Hash.new(0)\na.each { |x| h[x] += 1 }\nh = h.sort_by { |k, v| v }.reverse\nk, v = h.first\nv = a.size - v\n\nputs v\nif v > 0\n base_pos = a.index(k)\n range = base_pos..0\n (range.first).downto(range.last).each do |i|\n if a[i] != k\n puts \"#{a[i] < k ? 1 : 2} #{i+1} #{i+2}\"\n end\n end\n\n for i in base_pos..a.size-1\n if a[i] != k\n puts \"#{a[i] < k ? 1 : 2} #{i+1} #{i}\"\n end\n end\nend\n"}], "src_uid": "732d28ed9092883dccadbd1999308567"} {"source_code": "def solution\n countOfCase = gets.chomp.to_i\n data = []\n countOfCase.times do\n temp = gets.chomp\n data.push temp.split(' ').map(&:to_i)\n end\n data.each do |elem|\n n, s = elem[0], elem[1]\n if (n === 0)\n puts 0\n elsif (s <= n)\n puts s\n else\n base = s / n\n count = s % n\n puts (n - count) * base * base + count * (base + 1) * (base + 1);\n end\n end\nend\n\nsolution\n", "positive_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a n / a\r\n s * a\r\n end\r\n end\r\n puts check.call ? 'Yes' : 'No'\r\nend", "positive_code": [{"source_code": "def res\r\n return \"Yes\" if $n == 1\r\n sh = [1]\r\n x = $a\r\n #count = 0\r\n until x > $n or $a == 1\r\n return \"Yes\" if $n == x\r\n # count += 1\r\n sh.push x\r\n x *= $a\r\n end\r\n #puts \"#{sh} #{$n} -- #{count}\"\r\n sh.each { |k|\r\n x = $n - k\r\n return \"Yes\" if x % $b == 0\r\n }\r\n return \"No\"\r\nend\r\n\r\n\r\nt = gets.to_i\r\nt.times { |u|\r\n $n, $a, $b = gets.chomp.split(\" \").map(&:to_i)\r\n puts res\r\n}"}, {"source_code": "gets\r\nwhile line = gets\r\n n, a, b = line.split.map(&:to_i)\r\n check = lambda do\r\n loop.reduce(1) do |s|\r\n return true if s % b == n % b\r\n return false if s > n / a || a == 1\r\n s * a\r\n end\r\n end\r\n puts check.call ? 'Yes' : 'No'\r\nend"}, {"source_code": "gets.to_i.times do\r\n n,a,b=gets.split.map(&:to_i)\r\n r=n%b\r\n if n==1\r\n puts \"Yes\"\r\n elsif b==1\r\n puts \"Yes\"\r\n elsif a==1\r\n if r==1\r\n puts \"Yes\"\r\n else\r\n puts \"No\"\r\n end\r\n else\r\n x=1\r\n f=false\r\n while x<=n\r\n if x%b==r\r\n puts \"Yes\"\r\n f=true\r\n break\r\n end\r\n x*=a\r\n end\r\n puts \"No\" if !f\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "gets\r\nwhile line = gets\r\n n, a, b = line.split.map(&:to_i)\r\n check = lambda do\r\n return n % b == 1 if a == 1\r\n loop.reduce(1) do |s|\r\n return true if s % b == n % b\r\n return false if s > n / a\r\n s * a\r\n end\r\n end\r\n puts check.call ? 'Yes' : 'No'\r\nend"}, {"source_code": "gets\r\nwhile line = gets\r\n n, a, b = line.split.map(&:to_i)\r\n check = lambda do\r\n return true if a == 1\r\n loop.reduce(1) do |s|\r\n return true if s % b == n % b\r\n return false if s > n / a\r\n s * a\r\n end\r\n end\r\n puts check.call ? 'Yes' : 'No'\r\nend"}, {"source_code": "gets.to_i.times do\r\n n,a,b=gets.split.map(&:to_i)\r\n r=n%b\r\n if a==1\r\n if r==1\r\n puts \"Yes\"\r\n else\r\n puts \"No\"\r\n end\r\n elsif b==1\r\n puts \"Yes\"\r\n else\r\n x=1\r\n f=false\r\n while x<=n\r\n if x%b==r\r\n puts \"Yes\"\r\n f=true\r\n break\r\n end\r\n x*=a\r\n end\r\n puts \"No\" if !f\r\n end\r\nend\r\n"}], "src_uid": "e0a3c678f6d1d89420c8162b0ddfcef7"} {"source_code": "n,m,k=gets.split.map(&:to_i)\nh=gets.split.map(&:to_i)\nholes=Array.new(n)\nh.each{|i|holes[i-1]=true}\nif holes[0]\n\tputs 1\n\texit\nend\npos=0\nk.times{\n\tu,v=gets.split.map(&:to_i)\n\tu-=1\n\tv-=1\n\tto=0\n\tif u==pos\n\t\tto=v\n\telsif v==pos\n\t\tto=u\n\telse\n\t\tnext\n\tend\n\tif holes[to]\n\t\tputs to+1\n\t\texit\n\tend\n\tpos=to\n}\n\nputs pos+1", "positive_code": [{"source_code": "require 'set'\nn, m, k = gets.split.map(&:to_i)\nif m * 20 < n then\n mm, x = gets.split.to_set, '1'\n begin\n break if mm.member?(x)\n u, v = gets.split\n if x == u\n x = v\n elsif x == v\n x = u\n end\n k -= 1\n end until k == 0\n puts(x)\nelse\n mm, x = [false] * (n + 1), 1\n gets.split.map(&:to_i).each {|t| mm[t] = true}\n begin\n break if mm[x]\n u, v = gets.split.map(&:to_i)\n if x == u\n x = v\n elsif x == v\n x = u\n end\n k -= 1\n end until k == 0\n puts(x)\nend\n\n"}, {"source_code": "n, _, k = gets.split.map(&:to_i)\nh = gets.split.map(&:to_i)\nary = Array.new(n, false)\nh.each {|v|\n ary[v - 1] = true;\n}\ncur = 0\nk.times {\n if ary[cur]\n puts cur + 1\n exit 0\n end\n a, b = gets.split.map(&:to_i)\n a -= 1\n b -= 1\n if a == cur\n cur = b\n elsif cur == b\n cur = a\n end\n}\nputs cur + 1\n"}, {"source_code": "n, m, k = gets.split(\" \").map(&:to_i)\nh = []\ngets.split(\" \").map(&:to_i).each {|i| h[i] = true}\ncur = 1\nif h[cur]\n p cur\n exit\nend\nk.times do\n u, v = gets.split(\" \").map(&:to_i)\n if cur == u\n cur = v\n elsif cur == v\n cur = u\n end\n if h[cur]\n p cur\n exit\n end\nend\n\np cur"}, {"source_code": "(n,_,_),f,*x=$<.map{|x|x.split.map &:to_i}\nary = Array.new(n+1, false)\nf.each{|v|ary[v] = true}\ncur = 1\nfor z in x\n if ary[cur]\n p cur\n exit 0\n end\n a, b = z\n if a == cur\n cur = b\n elsif cur == b\n cur = a\n end\nend\np cur"}, {"source_code": "n,_,k=gets.split.map &:to_i\nary = Array.new(n+1, false)\ngets.split.map(&:to_i).each{|v|ary[v] = true}\ncur = 1\nk.times {\n if ary[cur]\n puts cur\n exit 0\n end\n a, b = gets.split.map(&:to_i)\n if a == cur\n cur = b\n elsif cur == b\n cur = a\n end\n}\nputs cur"}, {"source_code": "(n,_,_),f,*x=$<.map{|x|x.split.map &:to_i}\nary = [false]*(n+1)\nf.each{|v|ary[v] = true}\ncur = 1\nfor z in x \n if ary[cur]\n p cur\n exit 0\n end\n a, b = z\n if a == cur\n cur = b\n elsif cur == b\n cur = a\n end\nend\np cur"}], "negative_code": [{"source_code": "require 'set'\nn, m, k = gets.split.map(&:to_i)\nif m * 20 < n then\n mm, x = gets.split.to_set, '1'\n begin\n break if mm.member?(x)\n u, v = gets.split\n if x == u\n x = v\n elsif x == v\n x = u\n end\n k -= 1\n end until k == 0\n puts(x)\nelse\n mm, x = [false] * (n + 1), 1\n gets.split.map(&:to_i).each {|x| mm[x] = true}\n begin\n break if mm[x]\n u, v = gets.split\n if x == u\n x = v\n elsif x == v\n x = u\n end\n k -= 1\n end until k == 0\n puts(x)\nend\n\n"}], "src_uid": "1f41c017102f4a997be324a4ec9b7fd6"} {"source_code": "def gcd(a, b)\n return a if b == 0\n gcd(b, a%b)\nend\n\nn, m = gets.strip.split.map(&:to_i)\n\nif m 1\n v += 1\n if v > n\n u += 1\n v = u + 1\n end\n end\n if u<=n && u n\n u += 1\n v = u + 1\n end\n else\n possible = false\n break\n end\nend\n\nif possible\n puts \"Possible\"\n edges.each do |e|\n puts e.join(' ')\n end\nelse\n puts \"Impossible\"\nend", "positive_code": [{"source_code": "N, M = gets.split.map(&:to_i)\nif N-1 > M\n puts 'Impossible'\n exit\nend\n\n$ans = []\n(2..N).each do |i|\n $ans.push([1, i])\nend\n\ndef coprimes(a, b)\n d = a+b\n while d <= N\n $ans.push([b, d]) if b.between?(2, N) && d.between?(2, N)\n if $ans.length == M\n puts 'Possible'\n $ans.each do |arr|\n puts arr.join(' ')\n end\n exit\n end\n coprimes(b, d)\n d += b\n end\nend\n\ncoprimes(1, 1)\nputs 'Impossible'"}], "negative_code": [{"source_code": "N, M = gets.split.map(&:to_i)\nif N-1 > M\n puts 'Impossible'\n exit\nend\n\n$ans = []\n(2..N).each do |i|\n $ans.push([1, i])\nend\n\ndef coprimes(a, b)\n d = a+b\n while d <= N\n $ans.push([b, d]) if a.between?(2, N) && b.between?(2, N)\n if $ans.length == M\n puts 'Possible'\n $ans.each do |arr|\n puts arr.join(' ')\n end\n exit\n end\n coprimes(b, d)\n d += b\n end\nend\n\ncoprimes(1, 1)\nputs 'Impossible'"}, {"source_code": "N, M = gets.split.map(&:to_i)\nif N-1 > M\n puts 'Impossible'\n exit\nend\n\n$ans = []\n\ndef coprimes(a, b)\n d = a+b\n while d <= N\n $ans.push([b, d]) if a.between?(1, N) && b.between?(1, N)\n if $ans.length == M\n puts 'Possible'\n $ans.each do |arr|\n puts arr.join(' ')\n end\n exit\n end\n coprimes(b, d)\n d += b\n end\nend\n\ncoprimes(1, 1)\nputs 'Impossible'"}], "src_uid": "0ab1b97a8d2e0290cda31a3918ff86a4"} {"source_code": "n, m = gets.chomp.split(' ').map(&:to_i)\ncorrect = gets.chomp.split(' ').map(&:to_i)\nwrong = gets.chomp.split(' ').map(&:to_i)\n\ncorrect.sort!\nwrong.sort!\n\nans = [2 * correct[0], correct[n - 1]].max\n\nif ans >= wrong[0]\n puts -1\nelse\n puts ans\nend", "positive_code": [{"source_code": "gets\na = gets.chomp.split(/ /).map(&:to_i)\nb = gets.chomp.split(/ /).map(&:to_i)\nv = a.min\np = a.max\nc = b.min\nif [2 * v, p].max < c\n puts [2 * v, p].max\nelse\n puts \"-1\"\nend\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).sort\nb=gets.split.map(&:to_i).sort\n\nres=-1\n1.upto(b[0]-1) {|v|\n extra=false\n ok=true\n a.each {|w|\n extra=true if w*2<=v\n ok=false if w>v\n }\n if ok and extra then\n res=v\n break\n end\n}\np res\n"}, {"source_code": "gets;a=gets.split.map &:to_i;b=gets.split.map &:to_i;z=[a.min*2,a.max].max;p z i)\n puts i\n exit\n end\n}\n\nputs -1\n"}, {"source_code": "nr, nw = gets.split.map{|s| s.to_i}\nrst = gets.split.map{|s| s.to_i}\nwst = gets.split.map{|s| s.to_i}\nrst_min = rst.min\nrst_max = rst.max\nwst_min = wst.min\nwst_max = wst.max\nif wst_min <= rst_max || wst_min <= rst_min*2\n\tputs -1\nelse\n\tputs [rst_max, rst_min*2].max\nend"}, {"source_code": "gets;a=gets.split.map &:to_i;b=gets.split.map &:to_i;z=[a.min*2,a.max].max;p z= wrong[0] || 2 * correct[0] > ans\n puts -1\nelse\n puts ans\nend"}, {"source_code": "gets\na=gets.split.map{|s|s.to_i}\nb=gets.split.map{|s|s.to_i}\nif a.size>1\nputs (2*a.min<=a.max&&a.max l or next_pos <= 0\n ex = true\n break\n end\n}\nputs ex ? 'FINITE' : 'INFINITE'\n", "positive_code": [{"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\"\")\nc=gets.chomp.split(\" \").map{|i| i.to_i}\nd=Array.new(a,1)\n\ncur=0\nd[0]=0\ntrig=1\nloop do\nif b[cur]==\">\"\ncur+=c[cur]\nbreak if cur>=a || cur<0\nif d[cur]==0\ntrig=0\nbreak\nelse\nd[cur]=0\nend\nend\nif b[cur]==\"<\"\ncur-=c[cur]\nbreak if cur>=a || cur<0\nif d[cur]==0\ntrig=0\nbreak\nelse\nd[cur]=0\nend\nend\nend\n\nif trig==1\nputs \"FINITE\"\nelse\nputs \"INFINITE\"\nend"}, {"source_code": "n = gets.chomp.to_i\n\ndirecs = gets.chomp.split(\"\")\nlens = gets.chomp.split(\" \").map(&:to_i)\n\na = Array.new(n, 0)\n\ncurr = 0\nwhile curr >= 0 && curr < n\n if a[curr] != 0\n puts \"INFINITE\"\n exit\n end\n a[curr] = 1\n if direcs[curr] == \"<\" then\n move = lens[curr] * -1\n else\n move = lens[curr]\n end\n curr += move\nend\nputs \"FINITE\"\n"}, {"source_code": "n = gets.to_i\nmap = gets.chomp\nlen = gets.chomp.split(' ')\nlen.each_index { |i| len[i] = len[i].to_i }\n\ncnt = Array.new(len.size) { |e| e = 0 }\npos, loo = 0, false\n\nwhile true\n cnt[pos] += 1\n if cnt[pos] == 2\n loo = true\n break\n end\n if map[pos] == '>'\n npos = pos + len[pos]\n else\n npos = pos - len[pos]\n end\n if npos > n-1 or npos < 0 #out of range\n loo = false\n break\n end\n pos = npos\nend\n\nif loo\n puts \"INFINITE\"\nelse\n puts \"FINITE\"\nend\n"}, {"source_code": "n = gets.to_i\ndir = gets\njlen = gets.split.map{|x| x.to_i}\nused = Array.new(n, false)\n\n(dir.length-1).times do |i|\n jlen[i] *= -1 if dir[i] == '<'\nend\n\ncur_pos = 0\nwhile 0 <= cur_pos && cur_pos < n\n if used[cur_pos]\n puts 'INFINITE'\n exit\n end\n used[cur_pos] = true\n cur_pos+=jlen[cur_pos]\nend\n\n#puts jlen\nputs 'FINITE'\n"}, {"source_code": "require 'set'\n\nstrip_length = gets.chomp.to_i\n\nJump = Struct.new(:direction, :length)\njumps = []\na = gets.chomp\nb = gets.chomp.split(' ')\n\nfor i in 0..a.length-1\n\tjumps[i] = Jump.new(a[i], b[i].to_i)\nend\n\n\nvisited = Set.new\nx = 0\n\nloop {\n\tvisited.add(x)\n\tdir = jumps[x].direction == \">\" ? 1 : -1\n\tx += dir * jumps[x].length\n\tif x >= jumps.length || x < 0\n\t\tputs \"FINITE\"\n\t\tbreak\n\tend\n\t\n\tif visited.include?(x)\n\t\tputs \"INFINITE\"\n\t\tbreak\n\tend\n\t\n}"}, {"source_code": "n = readline.to_i\nstr = readline.strip\narr = readline.split(' ').collect(&:to_i)\nhash = Hash.new(true)\nhash[0] = true\nnow = 0\nwhile true\n now = now + arr[now] * (str[now] == \">\" ? 1 : -1)\n if now >= n || now < 0 || hash.has_key?(now)\n break\n end\n hash[now] = true\nend\nif now >= n || now < 0\n puts \"FINITE\"\nelse\n puts \"INFINITE\"\nend\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end\n############################################################\n\nFIN = 'FINITE'\nINF = 'INFINITE'\n\nn = gi\nj = gs.each_char.to_a\nd = gis\n\njp = n.times.map{|i| j[i] == \"<\" ? -d[i] : d[i]}\n\nf = [false] * jp.size\n\ni = 0\n\nloop {\n if f[i]\n puts INF\n exit\n end\n f[i] = true\n i += jp[i]\n if i < 0 || i > n - 1\n puts FIN\n exit\n end \n}\n\n\n\n\n\n\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\"\")\nc=gets.chomp.split(\" \").map{|i| i.to_i}\nd=Array.new(a,1)\n\ncur=0\nd[0]=0\ntrig=1\nloop do\nif b[cur]==\">\"\ncur+=c[cur]\nbreak if cur>=a || cur<0\nif d[cur]==0\ntrig=0\nbreak\nelse\nd[cur]=0\nend\nend\nif b[cur]==\"<\"\ncur-=c[cur]\nbreak if cur>=a || cur<0\nif d[cur]==0\ntrig=0\nbreak\nelse\nd[cur]=0\nend\nend\nend\n\nif trig==1\nputs \"FINITE\"\nelse\nputs \"INFINITE\"\nend"}, {"source_code": "n = gets.to_i\ns = gets\nvalues = gets.split.map{|x| x.to_i}\nvis = Array.new(n , false)\n\ni = 0\nflag = false\n\nwhile (vis[i] == false)\n\n\tvis[i] = true\n\t\n\tif(s[i] == '>')\n\t\ti += values[i]\n\telse\n\t\ti -= values[i]\n\n\tend\n\n\tif(i < 0 || i >= s.length - 1)\n\t\tflag = true\n\t\tbreak\n\tend\nend\n\nputs \"FINITE\" if flag == true\nputs \"INFINITE\" if flag == false"}], "negative_code": [{"source_code": "l = gets.to_i\ndirs = gets.to_s\nnums = gets.split(' ').map { |i| i.to_i }\nex = false\nnext_pos = 0\nnums.each_with_index { |n, i|\n next_pos = dirs[i] == '>' ? next_pos + n : next_pos - n\n if next_pos > l or next_pos < 0\n ex = true\n break\n end\n}\nputs ex ? 'FINITE' : 'INFINITE'\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end\n############################################################\n\nFIN = 'FINITE'\nINF = 'INFINITE'\n\nn = gi\nj = gs.each_char.to_a\nd = gis\n\njp = j.zip(d).map{|y, x| y == \"<\" ? -x : x}\n\nf = [false] * jp.size\n\ni = 0\n\nloop {\n if f[i]\n puts INF\n exit\n end\n f[i] = true\n i += jp[i]\n if i < 0 || i >= n - 1\n puts FIN\n exit\n end \n}\n\n\n\n\n\n\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end\n############################################################\n\nFIN = 'FINITE'\nINF = 'INFINITE'\n\nn = gi\nj = gs.each_char.to_a\nd = gis\n\na = j.zip(d).reduce(0) {|r,k|\n y, x = k\n y == \"<\" ? r - x : r + x\n}\n\nif a < 0\n puts FIN\nelse\n puts INF\nend\n\n\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end\n############################################################\n\nFIN = 'FINITE'\nINF = 'INFINITE'\n\nn = gi\nj = gs.each_char.to_a\nd = gis\n\na = j.zip(d).reduce(0) {|r,k|\n if r < 0\n puts FIN\n exit\n end\n y, x = k\n y == \"<\" ? r - x : r + x\n}\n\nif a < 0\n puts FIN\nelse\n puts INF\nend\n\n\n"}, {"source_code": "n = gets.to_i\ns = gets\nvalues = gets.split.map{|x| x.to_i}\nvis = Array.new(n , false)\n\ni = 0\nflag = false\n\nwhile (vis[i] == false)\n\n\tvis[i] = true\n\t\n\tif(s[i] == '>')\n\t\ti += values[i]\n\telse\n\t\ti -= values[i]\n\n\tend\n\n\tif(i < 0 || i >= s.length)\n\t\tflag = true\n\t\tbreak\n\tend\nend\n\nputs \"FINITE\" if flag == true\nputs \"INFINITE\" if flag == false"}, {"source_code": "n = gets.to_i\ns = gets\nvalues = gets.split.map{|x| x.to_i}\nvis = Array.new(n , false)\n\ni = 0\nflag = false\n\nwhile (vis[i] == false)\n\n\tvis[i] = true\n\t\n\tif(s[i] == '>')\n\t\ti += values[i]\n\telse\n\t\ti -= values[i]\n\n\tend\n\n\tif(i < 0 || i >= s.length)\n\t\tflag = true\n\t\tbreak\n\tend\nend\n\np \"FINITE\" if flag == true\np \"INFINITE\" if flag == false"}], "src_uid": "5fcc22cdc38693723d8a9577d685db12"} {"source_code": "gets.to_i.times do\n gets()\n xs = gets.split.map(&:to_i)\n h = {}\n sum = 0\n xs.each_with_index do |x, i|\n sum += x\n h[sum] = i + 1\n end\n\n ans = 0\n sum = 0\n xs.reverse.each_with_index do |x, i|\n sum += x\n if h.include?(sum)\n j = xs.size() - h[sum] + 1\n if j > i + 1\n ans = [ans, h[sum] + i + 1].max\n end\n end\n end\n\n p ans\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n l, r = 0, xs.size - 1\r\n sl, sr, max, ate = 0, 0, 0, 0\r\n while l <= r\r\n if sl < sr || (sl == sr && xs[l] < xs[r])\r\n sl += xs[l]\r\n l += 1\r\n else\r\n sr += xs[r]\r\n r -= 1\r\n end\r\n ate += 1\r\n max = ate if sl == sr\r\n end\r\n p max\r\nend\r\n"}, {"source_code": "def eating_cadies(arr, n)\r\n i = 0\r\n j = n - 1\r\n alice = arr[0]\r\n bob = arr[j]\r\n count = 0\r\n while i < j\r\n if alice == bob\r\n count = [count, i+1+n-j].max\r\n end\r\n if alice <= bob\r\n i+=1\r\n alice+=arr[i]\r\n elsif bob < alice\r\n j-=1\r\n bob+=arr[j]\r\n end\r\n \r\n end\r\n count\r\nend\r\nt = gets.to_i\r\ninputs = []\r\n(0..t-1).each do |i|\r\n n = gets.to_i\r\n arr = gets.chomp\r\n arr = arr.split(\" \").map(&:to_i)\r\n inputs.push([arr, n])\r\nend\r\n\r\ninputs.each do |input|\r\n puts eating_cadies(input[0], input[1])\r\nend\r\n"}], "negative_code": [{"source_code": "def eating_cadies(arr, n)\r\n i = 0\r\n j = n - 1\r\n alice = arr[0]\r\n bob = arr[j]\r\n count = 0\r\n while i < j\r\n if alice <= bob\r\n i+=1\r\n alice+=arr[i]\r\n elsif bob < alice\r\n j-=1\r\n bob+=arr[j]\r\n end\r\n if alice == bob\r\n count = [count, i+1+n-j].max\r\n end\r\n end\r\n count\r\nend\r\nt = gets.to_i\r\ninputs = []\r\n(0..t-1).each do |i|\r\n n = gets.to_i\r\n arr = gets.chomp\r\n arr = arr.split(\" \").map(&:to_i)\r\n inputs.push([arr, n])\r\nend\r\n\r\ninputs.each do |input|\r\n puts eating_cadies(input[0], input[1])\r\nend\r\n"}], "src_uid": "90e448ed43ba9a0533ac7dc24f92a7f8"} {"source_code": "gets\nsum,a,now,n=[0],0,0,$_.size-1\nn.times{|i|sum[i+1]=sum[i]+1.0/(i+1)}\n(0...n).each do |i|\n now+=sum[-i-1]-sum[i]\n a+=now if 'IEAOUY'[$_[i]]\nend\np a", "positive_code": [{"source_code": "d=gets\nn=d.size-1\nsum,ans,now=[0],0,0\nn.times{|i|sum[i+1]=sum[i]+1.0/(i+1)}\n(0...n).each do |i|\n now+=sum[-i-1]-sum[i]\n ans+=now if 'IEAOUY'[d[i]]\nend\np ans"}, {"source_code": "v=['I','E','A','O','U','Y']\nd=['Q']+gets.split(//)\nd.pop\nn=d.size-1\nsum,ans,now=[0.0],0.0,0.0\nn.times{|i|sum[i+1]=sum[i]+1.0/(i+1)}\n(1..n/2).each do |i|\n now+=sum[-i]-sum[i-1]\n ans+=now if v.include?d[i]\n ans+=now if v.include?d[-i]\nend\nnow+=sum[n/2+1]-sum[n/2]\nans+=now if n.odd?&&v.include?(d[n/2+1])\np ans"}, {"source_code": "d=gets.split(//)\nd.pop\nn=d.size\nsum,ans,now=[0],0,0\nn.times{|i|sum[i+1]=sum[i]+1.0/(i+1)}\n(0...n).each do |i|\n now+=sum[-i-1]-sum[i]\n ans+=now if 'IEAOUY'[d[i]]\nend\np ans"}], "negative_code": [], "src_uid": "2b37188c17b7cbc3e533e9ad341441b2"} {"source_code": "N, K, Q = $stdin.gets.split.map(&:to_i)\nims = Array.new(200000 + 1 + 1, 0)\nN.times {\n a, b = $stdin.gets.split.map(&:to_i)\n ims[a] += 1\n ims[b + 1] -= 1\n}\n200000.times { |i|\n ims[i + 1] += ims[i]\n}\npre = Array.new(200000 + 1 + 1, 0)\n200000.times { |i|\n pre[i + 1] = pre[i] + (ims[i + 1] >= K ? 1 : 0)\n}\nQ.times {\n a, b = $stdin.gets.split.map(&:to_i)\n puts pre[b] - pre[a - 1]\n}\n", "positive_code": [{"source_code": "N, K, Q = gets.split.map(&:to_i)\nims = Array.new(200000 + 1 + 1, 0)\nN.times {\n a, b = gets.split.map(&:to_i)\n ims[a] += 1\n ims[b + 1] -= 1\n}\n200000.times { |i|\n ims[i + 1] += ims[i]\n}\npre = Array.new(200000 + 1 + 1, 0)\n200000.times { |i|\n pre[i + 1] = pre[i] + (ims[i + 1] >= K ? 1 : 0)\n}\nQ.times {\n a, b = gets.split.map(&:to_i)\n puts pre[b] - pre[a - 1]\n}\n"}, {"source_code": "N, K, Q = $stdin.readline.split.map(&:to_i)\nims = Array.new(200000 + 1 + 1, 0)\nN.times {\n a, b = $stdin.readline.split.map(&:to_i)\n ims[a] += 1\n ims[b + 1] -= 1\n}\n200000.times { |i|\n ims[i + 1] += ims[i]\n}\npre = Array.new(200000 + 1 + 1, 0)\n200000.times { |i|\n pre[i + 1] = pre[i] + (ims[i + 1] >= K ? 1 : 0)\n}\nQ.times {\n a, b = $stdin.readline.split.map(&:to_i)\n puts pre[b] - pre[a - 1]\n}\n"}], "negative_code": [], "src_uid": "4bdf819b73ffb708ad571accf3b8c23d"} {"source_code": "h = Hash.new(0)\ngets.to_i.times{\n h[gets] += 1\n}\np h.values.max\n", "positive_code": [{"source_code": "n = gets.to_i\npr = [-1, -1]\ntmp, max = 0, 1\nn.times do\n ar = gets.split(' ').map(&:to_i)\n ar == pr ? tmp+=1 : tmp = 1\n max = tmp if tmp > max\n pr = ar\nend\nputs max"}, {"source_code": "\na=Array.new(24*60+1,0)\n\n#print a\nn=gets.chomp.to_i\ni=0\nfor i in (0...n)\nb=gets.chomp.split(\" \")\na[(b[0].to_i*60+b[1].to_i)]+=1\nend\nputs a.max\n\n\n"}, {"source_code": "\na=Hash.new(0)\n\n#print a\nn=gets.chomp.to_i\ni=0\nfor i in (0...n)\nb=gets.chomp.split(\" \")\na[(b[0].to_i*60+b[1].to_i)]+=1\nend\nputs a.values.max\n\n\n"}, {"source_code": "n = gets.to_i\n\nt = {}\nn.times do |i|\n s = gets.chomp.sub(\" \", \":\")\n if t[s] then\n t[s] += 1\n else\n t[s] = 1\n end\nend\n\nt = t.sort{|a,b| a[1]<=>b[1]}\n\np t[-1][1]"}, {"source_code": "I =->{gets.split.map &:to_i}\nRD =->{gets.to_i}\n\naa = bb = -1; cnt = res = 1; RD[].times{\n\ta, b = I[]\t\t\n\tif a == aa && b == bb\t\t\n\t\tcnt += 1; res = cnt if (cnt > res) \n\telse\n\t\tcnt = 1; aa, bb = a, b\n\tend\n}\n\np res"}, {"source_code": "n = gets.to_i\nhLast, mLast = -1, -1\nmax = 1\ncount = 1\nn.times do\n h, m = gets.split(\" \").map(&:to_i)\n if hLast == h && mLast == m\n count += 1\n else\n count = 1\n end\n max = count if count > max\n hLast, mLast = h, m\nend\n\nputs max"}, {"source_code": "\ufeffn = gets.chomp.to_i\n\nhash = {}\nn.times do\n v = gets.chomp\n if hash.has_key? v\n hash[v] += 1\n else\n hash[v] = 1\n end\nend\n\nputs hash.values.max"}, {"source_code": "n = gets.to_i\ncus = Array.new(24)\nfor i in 0...24\n cus[i] = Array.new(60, 0)\nend\nn.times do\n a, b = gets.split.map(&:to_i)\n cus[a][b] += 1\nend\nm = Array.new\nfor i in 0...24\n m << cus[i].max\nend\nprint m.max"}, {"source_code": "times = []\npeople = gets.chomp.to_i\npeople.times { time = gets\n times.push(time) }\n\nb = Hash.new(0)\ntimes.each do |element|\n b[element] += 1\nend\n\np b.values.max"}, {"source_code": "hash = Array.new(24*60) {0}\nf = Proc.new{ |a,b| a * 60 + b }\ngets.to_i.times {\n hash[f.call gets.split.map(&:to_i)] += 1 \n}\nputs hash.max"}, {"source_code": "a = Hash.new(0)\ngets.to_i.times { a[gets.strip] += 1 }\nputs a.values.max"}, {"source_code": "n = gets.chomp.to_i\na = []\nn.times do\n a << gets\nend\n\nh = {}\n\na.each_with_index do |t, i|\n h[t] = (h[t].nil? ? 1 : h[t]+1)\nend\n\nputs h.values.max"}, {"source_code": "n = gets.to_i\ncox = []\nfor i in 0..n-1\n cox[i] = gets.split.map(&:to_i)\nend\n\n\nc = 0\nfox = []\ncox.sort!\nfor i in 0..n-1\n if cox[i] == cox[i+1]\n c+=1\n else\n fox.push(c)\n c = 0\n end\nend\n\nputs fox.max + 1\n"}, {"source_code": "n = $stdin.gets.to_i\nr = []\nn.times {r << $stdin.readline.chop}\n\nclass Array # use self.partition\n\n def complect_and_count\n self.dup.complect_and_count!\n end\n\n def complect_and_count!\n a = self.shift\n h = {sym: a, count: 1}\n result, k = [h], 1\n while self.size>0\n b = self.shift\n if a != b\n h[:count] = k\n h = {sym: b, count: 1}\n result << h\n k = 0\n end\n a = b\n k += 1\n end\n h[:count]=k\n result\n end\n\nend\n\nt = r.complect_and_count\nm = t.max_by {|x| x[:count]}\n\nputs m[:count]\n"}, {"source_code": "arr = []\ngets.to_i.times do\n arr << gets.chomp\nend\nhash = Hash.new(0)\narr.each { |v| hash[v] += 1 }\nputs hash.values.max\n"}, {"source_code": "t = []\nmax_t = 1\ngets.to_i.times do |i|\n in_time = gets.chomp.split.map(&:to_i)\n tt = in_time[0]*60 + in_time[1]\n if t[tt].nil?\n t[tt] = 1\n else\n t[tt] += 1\n end\n max_t = t[tt] if t[tt] > max_t\nend\nputs max_t\n"}, {"source_code": "n=gets.to_i\nn-=1\ns=gets.chomp\nans=1\nc=1\nn.times{\n\ts2=gets.chomp\n\tif s==s2 then\n\t\tc=c+1\n\telse\n\t\tc=1\n\t\ts=s2\n\tend\n\tans=[ans,c].max\n}\nputs ans\n\n"}, {"source_code": "n = gets.to_i\nb = []\nx,y = 1,0\nn.times do |i|\t\n\t a = gets.split.map(&:to_i)\n\t if a == b \t \t \t\n\t \ty += 1\n\t \tx = [x,y].max\n\t else\n\t \ty = 1\n\t end\n\t b = a\nend\np x"}, {"source_code": "i = gets.to_i; x = Hash.new(0);\ni.times { x[gets.chomp] += 1 }\nputs x.values.max"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nph, pm = -1, -1\ncons = 0\nmax_cons = 0\nn.times {\n h, m = gets.split.map(&:to_i)\n if h != ph || m != pm\n if max_cons < cons\n max_cons = cons\n end\n cons = 0\n ph, pm = h, m\n end\n\n cons += 1\n\n if max_cons < cons\n max_cons = cons\n end\n}\nputs max_cons"}, {"source_code": "h = Hash.new(0)\ngets.to_i.times {\n h[gets.chomp] += 1\n}\n\np h.values.max"}, {"source_code": "n = gets.chomp.to_i\ncashiers = []\nfor i in (0..n-1)\n\tcashiers[i] = gets.chomp\nend\n\ncashes = 1\nfree = 0\nfor i in (0..cashiers.size - 2)\n\tif cashiers[i] == cashiers[i+1] && free <= 1\n\t\tcashes += 1\n\telse\n\t\tif cashiers[i] == cashiers[i+1]\n\t\t\tfree -= 1\n\t\telse\n\t\t\tfree = cashes\n\t\tend\n\tend\nend\n\nprint cashes"}, {"source_code": "def max_cash(arrival_times)\n max = 0 \n counter = 0\n prev_value = arrival_times[0]\n\n arrival_times.each do |arrival_time|\n if arrival_time == prev_value\n counter += 1\n else\n counter = 1\n end\n prev_value = arrival_time\n max = [max, counter].max\n end\n \n max\nend\n\nn = gets.chomp.to_i\nclientes_arrival_time = []\nn.times do \n clientes_arrival_time << gets.chomp.gsub(\" \", \":\")\nend\n\nputs max_cash(clientes_arrival_time)\n"}, {"source_code": "def max_cash(arrival_times)\n arrival_time_counter = Hash.new { |k, v| k[v] = 0 }\n \n arrival_times.each do |arrival_time|\n arrival_time_counter[arrival_time] += 1\n end\n \n arrival_time_counter.values.max\nend\n\nn = gets.chomp.to_i\nclientes_arrival_time = []\nn.times do \n clientes_arrival_time << gets.chomp.gsub(\" \", \":\")\nend\n\nputs max_cash(clientes_arrival_time)\n"}, {"source_code": "n = gets.to_i\na = Hash.new(0)\nn.times do\n a[gets.chomp] += 1\nend\nputs a.values.max\n"}, {"source_code": "n = gets.to_i\na = Array.new(24){Array.new(60, 0)}\nn.times do\n h, m = gets.split.map(&:to_i)\n a[h][m] += 1\nend\naa = []\n24.times do |i|\n aa[i] = a[i].max\nend\np aa.max\n"}, {"source_code": "n = gets.chomp.to_i\nd = {}\nn.times do\n h, m = gets.chomp.split(\" \").map(&:to_i)\n d[[h, m]] = d.fetch([h, m], 0) + 1\nend\nputs d.values.max"}, {"source_code": "n = gets.to_i\nc = {}\nn.times do\n h, m = gets.split.map{|x| x.to_i}\n c[[h, m]] = 0 unless c[[h, m]]\n c[[h, m]] += 1\nend\nputs c.max{|a, b| a[1] <=> b[1]}[1]\n"}, {"source_code": "n = gets.to_i\n\ntime = Hash.new(0)\nmax = 0\nn.times do |_|\n h, m = gets.split(\" \").map(&:to_i)\n max = [max, time[m + h*60] += 1].max\nend\n\np max"}, {"source_code": "n = gets.to_i\n\ntime = Hash.new(0)\nn.times do |_|\n h, m = gets.split(\" \").map(&:to_i)\n time[h*60 + m] += 1\nend\n\np time.max { |a, b| a[1] <=> b[1]}[1]"}, {"source_code": "n = gets.to_i\n\ntime = Hash.new(0)\nn.times do |_|\n h, m = gets.split(\" \").map(&:to_i)\n time[h*60 + m] += 1\nend\n\np time.values.max"}, {"source_code": "n = gets.to_i\n\ntime = Hash.new(0)\nn.times do |_|\n h, m = gets.split(\" \").map(&:to_i)\n time[h*60 + m] += 1\nend\n\np time.max_by { |k, v| v}[1]"}, {"source_code": "n = gets.to_i\n\ntime = Hash.new(0)\nmax = 0\nn.times do |_|\n h, m = gets.split(\" \").map(&:to_i)\n m += h*60\n time[m] += 1\n max = [max, time[m]].max\nend\n\np max"}], "negative_code": [{"source_code": "i = gets.to_i; x = Hash.new(0);\ni.times { x[gets.chomp] += 1 }\nputs x.max[1]"}, {"source_code": "customers = gets.chomp.to_i\ntime = []\nfor i in (0..customers-1)\n\tt = gets.chomp\n\ttime[i] = t.split\n\ttime[i] = (time[i][0].to_i * 60) + time[i][1].to_i\nend\n\ncashiers = 1\nfor i in (0..customers-2)\n\tif time[i] == time[i+1] || (time[i]).abs - (time[i+1]).abs == 1\n\t\tcashiers += 1\n\tend\nend\n\nprint cashiers"}, {"source_code": "n = gets.chomp.to_i\ncashiers = []\nfor i in (0..n-1)\n\tcashiers[i] = gets.chomp\nend\n\ncashes = 0\navailable = 0\nfor i in (0..n-2)\n\tif cashiers[i] == cashiers[i+1]\n\t\tif cashes == 0 && available == 0\n\t\t\tcashes += 2\n\t\telsif available == 0\n\t\t\tcashes += 1\n\t\tend\n\telse\n\t\tavailable = cashes\n\tend\nend\nif cashes == 0\n\tprint 1\nelse\n\tprint cashes\nend"}, {"source_code": "n = gets.to_i\na = Array.new(24, Array.new(60, 0))\nn.times do\n h, m = gets.split.map(&:to_i)\n a[h][m] += 1\nend\naa = []\n24.times do |i|\n aa[i] = a[i].max\nend\np aa.max\n"}, {"source_code": "n = gets.to_i\na = Array.new(24, Array.new(60, 0))\nn.times do\n h, m = gets.split.map(&:to_i)\n a[h][m] += 1\nend\np a.max.max\n"}, {"source_code": "n = gets.to_i\ncox = []\nfor i in 0..n-1\n cox[i] = gets.split.map(&:to_i)\nend\n\nk = 1\n\nputs k + (n - cox.uniq.size)\n"}, {"source_code": "arr = []\ngets.to_i.times do\n arr << gets.chomp\nend\nputs 1 + (arr.size - arr.uniq.size)\n"}, {"source_code": "n = gets.to_i\nb = []\nx,y = 0,0\nn.times do |i|\t\n\t a = gets.split.map(&:to_i)\n\t if a == b \t \t \t\n\t \ty += 1\n\t \tx = [x,y].max\n\t else\n\t \ty = 1\n\t end\n\t b = a\nend\np x"}], "src_uid": "cfad2cb472e662e037f3415a84daca57"} {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\ngets.to_i.times do\n w,h=gets.split.map(&:to_i)\n t=[a[0], a[w-1]].max\n puts t\n a[0]=t+h\nend", "positive_code": [{"source_code": "n = gets.to_i #kol stypenei\na = gets.split(' ').collect!{|i| i.to_i} #visota stypenei\nm = gets.to_i #kol korobok\n\nw = []\nh = []\nm.times do\n\tt=gets.split(' ')\n\tw << t[0].to_i\n\th << t[1].to_i\nend\n\nx = []\n\n# m.times do |i|\n# \twid = w[i]-1\n# \thei = h[i]\n# \tx << a[wid]\n# \tnewhei = a[wid]+hei\n# \tn.times do |j|\n# \t\tif newhei > a[j]\n# \t\t\ta[j] = newhei\n# \t\telse\n# \t\t\tbreak\n# \t\tend\n# \tend\n# end\nnewhei = 0\nm.times do |i|\n\twid = w[i]-1\n\tif a[wid] > newhei\n\t\tx << a[wid]\n\t\tnewhei = a[wid]+h[i]\n\telse\n\t\tx << newhei\n\t\tnewhei += h[i]\n\tend\nend\n\nputs x"}], "negative_code": [{"source_code": "n = gets.to_i #kol stypenei\na = gets.split(' ').collect!{|i| i.to_i} #visota stypenei\nm = gets.to_i #kol korobok\n\nw = []\nh = []\nm.times do\n\tt=gets.split(' ')\n\tw << t[0].to_i\n\th << t[1].to_i\nend\n\nx = []\n\nm.times do |i|\n\twid = w[i]-1\n\thei = h[i]\n\tx << a[wid]\n\tnewhei = a[wid]+hei\n\t(0..(wid)).each do |j|\n\t\ta[j] = newhei\n\tend\nend\n\nputs x"}], "src_uid": "fb0e6a573daa0ee7c20d20b0d2b83756"} {"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n n = int\r\n a = int1s\r\n ans = 0\r\n n.times do |i|\r\n ans += (0 ... i).count { |j| a[j] >= a[i] }\r\n end\r\n puts ans\r\n end\r\n}\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\n$yesno = %w(No Yes)\r\nYesNo = %w(No Yes)\r\nYESNO = %w(NO YES)\r\nINF = 10**18\r\n\r\nclass Segtree\r\n def initialize(size, id, fill = id, &op)\r\n if size.is_a? Array\r\n @n = 1 << (size.size - 1).bit_length\r\n @a = [fill] * (2 * @n)\r\n @a[@n, @n] = size\r\n (@n - 1).downto(1) do |i|\r\n @a[i] = op[@a[i * 2], @a[i * 2 + 1]]\r\n end\r\n else\r\n @n = 1 << (size - 1).bit_length\r\n @a = [fill] * (2 * @n)\r\n end\r\n @a[0], @op = id, op\r\n end\r\n def [](i) @a[i + @n] end\r\n def []=(i, x)\r\n @a[i += @n] = x\r\n @a[i] = @op[@a[i * 2], @a[i * 2 + 1]] while (i >>= 1) > 0\r\n end\r\n def prod(l, r)\r\n return @a[0] if l >= r\r\n x = prod(l + 1 >> 1, r >> 1)\r\n x = @op[@a[@n + l], x] if l & 1 == 1\r\n x = @op[x, @a[@n + r - 1]] if r & 1 == 1\r\n x\r\n end\r\nend\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t] end\r\ndef YesNo t; puts YesNo[t] end\r\ndef YESNO t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]", "positive_code": [{"source_code": "def merge_sort(l, r)\n return if r <= l + 1\n m = (l + r) / 2\n\n merge_sort(l, m)\n merge_sort(m, r)\n\n i = l\n j = m\n o = l\n while i < m && j < r\n if $xs[j] <= $xs[i]\n $inversions += m - i\n $tmp[o] = $xs[j]\n j += 1\n else\n $tmp[o] = $xs[i]\n i += 1\n end\n o += 1\n end\n\n while i < m\n $tmp[o] = $xs[i]\n i += 1\n o += 1\n end\n\n while j < r\n $tmp[o] = $xs[j]\n j += 1\n o += 1\n end\n\n $xs[l...r] = $tmp[l...r]\nend\n\ndef inversions(xs)\n $xs = xs\n $tmp = Array.new(xs.size)\n $inversions = 0\n merge_sort(0, xs.size)\n $inversions\nend\n\ngets.to_i.times do\n gets\n xs = gets.split.map(&:to_i)\n p inversions(xs)\nend\n"}], "negative_code": [], "src_uid": "759b3909ccdf1b9ffd800bf0f65361cc"} {"source_code": "# http://codeforces.com/contest/545/problem/B\ndef hd(a, b)\n (0...a.length).map do |idx|\n a[idx] == b[idx] ? 0 : 1\n end.inject(0, :+)\nend\n\ndef modify(a, b, n)\n (0...a.length).map do |idx|\n if a[idx] == b[idx]\n a[idx]\n else\n if n > 0\n n -= 1\n a[idx]\n else\n b[idx]\n end\n end\n end.join\nend\n\ns = gets.chomp.chars\nt = gets.chomp.chars\nd = hd(s, t)\n\nif d.even?\n puts modify(s, t, d / 2)\nelse\n puts 'impossible'\nend\n", "positive_code": [{"source_code": "s = gets\nt = gets\nz = s.split('').zip(t.split(''))\ndist = 0\nz.each do |si, ti|\n dist += 1 if si != ti\nend\nif dist.odd?\n puts 'impossible'\nelse\n dist /= 2\n z.each do |si, ti|\n if si == ti\n print si\n else\n if dist > 0\n dist -= 1\n print si\n else\n print ti\n end\n end\n end\n puts\nend"}, {"source_code": "s=gets.chomp\nt=gets.chomp\n\nc1=0\ns.size.times{|i|\n\tc1+=1 if s[i]!=t[i]\n}\n\nif c1%2==1 then\n\tputs \"impossible\"\nelse\n\tans=\"\"\n\tf=true\n\ts.size.times{|i|\n\t\tif s[i]==t[i] then\n\t\t\tans<= 0\n answer.push a\n diff -= 1\n else\n answer.push b\n diff += 1\n end\n end\nend\n\nif diff != 0\n puts \"impossible\"\nelse\n puts answer.join\nend"}, {"source_code": "a, b = gets, gets\nn, c = a.length, 0\n(0...n).each do |i|\n\tif a[i] != b[i]\n\t\tc += 1\n\tend\nend\n\nif c & 1 != 0\n\tputs \"impossible\"\nelse\n\tp, i = 0, 0\n\twhile i < n do\n\t\tif p >= c/2\n\t\t\tbreak\n\t\tend\n\t\tif a[i] != b[i]\n\t\t\tprint b[i]\n\t\t\tp += 1\n\t\telse\n\t\t\tprint a[i]\n\t\tend\n\t\ti += 1\n\tend\n\tputs a[i..-1]\nend\n"}, {"source_code": "a, b = gets, gets\nn, c = a.length, 0\n(0...n).each do |i|\n\tif a[i] != b[i]\n\t\tc += 1\n\tend\nend\n\nif c & 1 != 0\n\tputs \"impossible\"\nelse\n\ts, p, i = '', 0, 0\n\twhile i < n do\n\t\tif p >= c/2\n\t\t\tbreak\n\t\tend\n\t\tif a[i] != b[i]\n\t\t\ts << b[i]\n\t\t\tp += 1\n\t\telse\n\t\t\ts << a[i]\n\t\tend\n\t\ti += 1\n\tend\n\ts << a[i..-1]\n\tputs s\nend\n"}], "negative_code": [{"source_code": "# http://codeforces.com/contest/545/problem/B\ndef hd(a, b)\n (0...a.length).map do |idx|\n a[idx] == b[idx] ? 0 : 1\n end.inject(0, :+)\nend\n\ndef pad(chars)\n (0...chars.length).to_a.reverse.each do |idx|\n if chars[idx] == '0'\n chars[idx] = '1'\n break\n end\n end\n\n chars.join\nend\n\ns = gets.chomp\nt = gets.chomp\ns, t = [s, t].sort\nd = hd(s.chars, t.chars)\n\nif d.even?\n puts pad(s.chars)\nelse\n puts 'impossible'\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# b.rb\n\ndef main()\n s = gets.chomp\n t = gets.chomp\n v = 0\n s.size.times do |i|\n if s[i] != t[i] then\n s[i] = \"10\"[v % 2]\n v += 1\n end\n end\n if (v % 2) == 0 then\n puts s\n else\n puts \"impossible\"\n end\nend\n\nif __FILE__ == $0 then\n main()\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# b.rb\n\ndef main()\n s = gets\n t = gets\n v = 0\n s.size.times do |i|\n if s[i] != t[i] then\n s[i] = \"01\"[v % 2]\n v += 1\n end\n end\n if v % 2 == 0 then\n puts s\n else\n puts \"impossible\"\n end\nend\n\nif __FILE__ == $0 then\n main()\nend\n"}], "src_uid": "2df181f2d1f4063a22fd2fa2d47eef92"} {"source_code": "n = gets.to_i\na = gets.split(' ').map { |t| t.to_i - 1 }\nb = gets.split(' ').map { |t| t.to_i - 1 }\nposition = []\nn.times { |i| position[b[i]] = i }\nprev = -1\nlen = 0\nn.times do |i|\n\tbreak if position[a[i]] < prev\n len += 1\n prev = position[a[i]]\t\t\nend\nputs n - len", "positive_code": [{"source_code": "\ninput = ARGF.to_a\n\nshit = input.shift.to_i;\nfirst = input.shift.split ' '\nlast = input.shift.split ' '\n\nk = j = 0\n\nfor i in 0..shit-1\n if first[j] == last[i] \n j += 1 \n else \n k += 1\n end\nend\n\nputs k\n"}], "negative_code": [], "src_uid": "a26e048eb9b18f87f1703d42e172f318"} {"source_code": "n, m = gets.split.map(&:to_i)\nl = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - m * l\n a.sort!\n c << a[0, l] << a.reverse[0, l]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / l} #{c.max / l}\"\n\n", "positive_code": [{"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\ni=n/k\n\nvals = []\ndels = []\nh = {}\ngets.to_i.times{\n v=0\n f = gets.split.map(&:to_i).each{|t|\n v+=a[t-1]\n dels << t-1\n }.sort.first\n h[f]=true\n vals << v/i.to_f\n}\ndels.each{|j| a[j]=nil }\na.compact!\na.sort!\n\nvals += [a[0...i].inject(&:+)/i.to_f, a.reverse[0...i].inject(&:+)/i.to_f] if a.size >= i && h.size < k\nvals.sort!\nputs \"%.7f %.7f\" % [vals[0], vals[-1]]\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nl = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - m * l\n a.sort!\n c << a[0, l] << a.reverse[0, l]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / l} #{c.max / l}\"\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nl = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - m * l\n a.sort!\n c << a[0, l] << a.reverse[0, l]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / l} #{c.max / l}\"\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nl = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - m * l\n a.sort!\n c << a[0, l] << a.reverse[0, l]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / l} #{c.max / l}\"\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nl = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - m * l\n a.sort!\n c << a[0, l] << a.reverse[0, l]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / l} #{c.max / l}\"\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nl = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - m * l\n a.sort!\n c << a[0, l] << a.reverse[0, l]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / l} #{c.max / l}\"\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nl = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - m * l\n a.sort!\n c << a[0, l] << a.reverse[0, l]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / l} #{c.max / l}\""}, {"source_code": "n, m = gets.split.map(&:to_i)\nl = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - m * l\n a.sort!\n c << a[0, l] << a.reverse[0, l]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / l} #{c.max / l}\"\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nl = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - m * l\n a.sort!\n c << a[0, l] << a.reverse[0, l]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / l} #{c.max / l}\"\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nl = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - m * l\n a.sort!\n c << a[0, l] << a.reverse[0, l]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / l} #{c.max / l}\"\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nl = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - m * l\n a.sort!\n c << a[0, l] << a.reverse[0, l]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / l} #{c.max / l}\"\n\n"}], "negative_code": [{"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\ni=n/k\n\nvals = []\ndels = []\ngets.to_i.times{\n v=0\n gets.split.map(&:to_i).each{|t|\n v+=a[t-1]\n dels << t-1\n }\n vals << v/i.to_f\n}\ndels.each{|j|\n a[j]=nil\n}\na.compact!\na.sort!\n\nvals += [a[0...i].inject(&:+)/i.to_f, a.reverse[0...i].inject(&:+)/i.to_f] if a.size >= i\nvals.sort!\nputs \"%.7f %.7f\" % [vals[0], vals[-1]]\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\ni=n/k\n\nvals = []\ndels = []\ngets.to_i.times{\n v=0\n gets.split.map(&:to_i).each{|t|\n v+=a[t-1]\n dels << t-1\n }\n vals << v/i.to_f\n}\ndels.each{|j| a[j]=nil }\na.compact!\na.sort!\n\nvals += [a[0...i].inject(&:+)/i.to_f, a.reverse[0...i].inject(&:+)/i.to_f] if a.size >= i && vals.size < k\nvals.sort!\nputs \"%.7f %.7f\" % [vals[0], vals[-1]]\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\ni=n/k\n\nvals = []\ndels = []\ngets.to_i.times{\n v=0\n gets.split.map(&:to_i).each{|t|\n v+=a[t-1]\n dels << t-1\n }\n vals << v/i.to_f\n}\ndels.each{|j| a[j]=nil }\na.compact!\na.sort!\n\nvals += [a[0...i].inject(&:+)/i.to_f, a.reverse[0...i].inject(&:+)/i.to_f] if a.size >= i\nvals.sort!\nputs \"%.7f %.7f\" % [vals[0], vals[-1]]\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nm = n / m\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size >= m\n a.sort!\n c << a[0, m] << a.reverse[0, m]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / m} #{c.max / m}\"\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_f)\nc = []\ngets.to_i.times do\n b = gets.split.map{|_| _.to_i - 1}\n next unless a[b[0]]\n c << b.map{|_| a[_]}\n b.each{|_| a[_] = nil}\nend\na.compact!\nif a.size > n - n / m * m\n a.sort!\n m = n / m\n c << a[0, m] << a.reverse[0, m]\nend\nc.map!{|_| _.inject(&:+)}\nputs \"#{c.min / m} #{c.max / m}\"\n"}], "src_uid": "899c5b77bfc0b4b99aff310741c9c0dd"} {"source_code": "n = gets.to_i\np = [-9e9]\nn.times.map{gets.split.map(&:to_i).sort.reverse}.sort.each do |a,b|\n\tnext if b <= p[-1]\n\tp << a\nend\np p.size - 1\nputs p[1..-1] * ' '\n", "positive_code": [{"source_code": "n=gets.to_i;s=[-9e9];n.times.map{gets.split.map(&:to_i).sort.reverse}.sort.each{|x,y|s<s[-1]};p s.size-1;$><s[-1]};p s.size-1;$><s[-1]};p s.size-1;$><s[-1]};p s.size-1;$><s[-1]};p s.size-1;$><s[-1]};p s.size-1;$><(other)\n return x - other.x if x != other.x\n return (endo? ? 1 : 0) - (other.endo? ? 1 : 0)\n end\nend\n\n \nn = gets.to_i\na = []\nn.times do |i|\n x, y = *gets.split(' ').map { |x| x.to_i }\n x, y = y, x if x > y\n a << Point.new(i*2, x, false)\n a << Point.new(i*2+1, y, true)\nend\n\ndone = Array.new(n, false)\nstack = []\npts = []\n\na.sort.each do |p|\n next if done[p.n / 2]\n if p.begin?\n stack << p\n next\n end\n\n pts << p.x\n \n stack.each do |visited|\n done[visited.n / 2] = true\n end\n \n stack.clear\nend\n\nputs pts.size\nputs pts.join(' ')\n"}, {"source_code": "n=gets.to_i;s=[-9e9];n.times.map{gets.split.map(&:to_i).sort.reverse}.sort.each{|x,y|s<s[-1]};p s.size-1;$><s[-1]};p s.size-1;$><s[-1]};p s.size-1;$><s[-1]};p s.size-1;$>< 0\n print \"1 \"\n ones -= 1\n end\nend\n\nif zeros != nil\n while zeros > 0\n print \"0 \"\n zeros -= 1\n end\nend\n"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1220/A\n\ngets\n\nword = gets.chomp\n\nz_count = 0\nn_count = 0\n\nword.each_char do |c|\n if c == 'z'\n z_count += 1 \n elsif c == 'n'\n n_count += 1\n end\nend\n\nputs (\"1 \" * n_count + \"0 \" * z_count).rstrip\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split('')\nz = e = r = o = n = 0\n\nfor char in a\n\tcase char\n\twhen 'z'\n\t\tz += 1\n\twhen 'e'\n\t\te += 1\n\twhen 'r'\n\t\tr += 1\n\twhen 'o'\n\t\to += 1\n\twhen 'n'\n\t\tn += 1\n\tend\nend\n\none_number = [o, n, e].min\no -= one_number\ne -= one_number\nzero_number = [z, e, r, o].min\n\none_number.times do\n\tprint '1 '\nend\nzero_number.times do\n\tprint '0 '\nend"}, {"source_code": "num = gets.to_i\narr = gets\n\nn = arr.split('').select{|x| x == 'n' }.count\nz = arr.split('').select{|x| x == 'z' }.count\n\nprint \"#{Array.new(n, '1').join(' ')}\" if n > 0\nprint \" \" if n > 0 && z > 0\nprint \"#{Array.new(z, '0').join(' ')}\" if z > 0\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nn_c = s.count('n')\nz_c = s.count('z')\n\nputs ((['1'] * n_c) + (['0'] * z_c)).join(\" \")\n"}, {"source_code": "def big(n, line)\n\tplace = 0\n\treturned = ''\n\tn.times do\n\t\treturned << \"1 \" if line[place] == \"n\"\n\t\tplace = place + 1\n\tend\n\tplace = 0\n\tn.times do\n\t\treturned << \"0 \" if line[place] == \"z\"\n\t\tplace = place + 1\n\tend\n\treturned[-1] = '' unless returned[-1] == \"0\" || returned[-1] == \"1\"\n\treturn returned\nend\n\nn = gets.chomp.to_i\nline = gets.chomp\nputs(big(n, line))"}, {"source_code": "n = gets\nstr = gets\nzeros = str.count 'z'\nones = str.count 'n'\n\nans = []\n1.upto(ones) {ans << \"1\"}\n1.upto(zeros) {ans << \"0\"}\n\nputs ans.join(\" \")\n"}, {"source_code": "n = gets.chomp.to_i\ns = gets.chomp\nzero = s.count(\"z\")\none = s.count(\"n\")\nputs \"1 \" * one + \"0 \" * zero\n\n"}, {"source_code": "gets\ns = gets.strip\nz = s.split('').count('z')\n((s.size - z*4)/3).times { print '1 ' }\nz.times { print '0 ' }"}, {"source_code": "gets\ns = gets.chomp\n\nputs (Array.new(s.count('n'), '1') + Array.new(s.count('z'), '0')).join(' ')\n"}], "negative_code": [{"source_code": "gets\ns = gets.strip\nz = s.split('').count('z')\n((s.size - z*4)/3).times { print 1 }\nz.times { print 0 }"}], "src_uid": "5e5dbd70c7fcedf0f965aed5bafeb06c"} {"source_code": "Vehicle = Struct.new(:index, :capacity)\n\nclass LorryLoader\n def self.load(lorry_volume, vehicle_registry)\n kayaks = []\n catamarans = []\n vehicle_registry.each.with_index do |vehicle, index|\n type, capacity = vehicle.split.map(&:to_i)\n kayaks << Vehicle.new(index + 1, capacity) if type == 1\n catamarans << Vehicle.new(index + 1, capacity) if type == 2\n end\n\n kayaks.sort_by! { |x| -x.capacity }\n catamarans.sort_by! { |x| -x.capacity }\n\n selected_vehicles = []\n total_capacity = volume = ki = ci = 0\n while (ki < kayaks.size || ci < catamarans.size) && volume < lorry_volume\n k_cap = ki < kayaks.size ? kayaks[ki].capacity : 0\n k_cap += kayaks[ki + 1].capacity if ki < kayaks.size - 1\n c_cap = ci < catamarans.size && lorry_volume - volume > 1 ? catamarans[ci].capacity : 0\n\n break if k_cap == 0 && c_cap == 0\n\n if (c_cap >= k_cap)\n selected_vehicles << catamarans[ci].index\n total_capacity += catamarans[ci].capacity\n volume += 2\n ci += 1\n else\n selected_vehicles << kayaks[ki].index\n total_capacity += kayaks[ki].capacity\n volume += 1\n ki += 1\n end\n end\n\n return total_capacity, selected_vehicles\n end\nend\n\nif __FILE__ == $0\n vehicle_count, lorry_volume = gets.split.map(&:to_i)\n vehicle_registry = []\n vehicle_count.times { vehicle_registry << gets }\n\n capacity, selected_vehicles = LorryLoader.load(lorry_volume, vehicle_registry)\n\n puts capacity\n puts selected_vehicles.join(' ')\nend\n", "positive_code": [{"source_code": "def load_lorry(lorryVolume, kayaks, catamarans)\n kayaks.sort_by! { |x| x[1] * -1 }\n catamarans.sort_by! { |x| x[1] * -1 }\n\n capacity = volume = ki = ci = 0\n selected_vehicles = []\n while (ki < kayaks.length || ci < catamarans.length) && volume < lorryVolume\n c_value = ci < catamarans.length && lorryVolume - volume > 1 ? catamarans[ci][1] : 0\n k_value = ki < kayaks.length ? kayaks[ki][1] : 0\n\n k_value += kayaks[ki + 1][1] if ki < kayaks.length - 1\n\n break if k_value == 0 && c_value == 0\n\n if c_value > k_value\n capacity += catamarans[ci][1]\n selected_vehicles << catamarans[ci][0]\n ci += 1;\n volume += 2\n else\n capacity += kayaks[ki][1]\n selected_vehicles << kayaks[ki][0]\n ki += 1\n volume += 1\n end\n end\n\n return capacity, selected_vehicles\nend\n\nif __FILE__ == $0\n n, lorryVolume = gets.split.map(&:to_i)\n kayaks = []\n catamarans = []\n n.times do |i|\n t, c = gets.split.map(&:to_i)\n kayaks << [i + 1, c] if t == 1\n catamarans << [i + 1, c] if t == 2\n end\n\n capacity, selected_vehicles = load_lorry(lorryVolume, kayaks, catamarans)\n\n puts capacity\n puts selected_vehicles.join(\" \")\nend\n"}, {"source_code": "n,v = gets.split(\" \").map{|x| x.to_i}\nts1 = Array.new\nts2 = Array.new\nn.times do |i|\n t,p = gets.split(\" \").map{|x| x.to_i}\n if t == 1\n ts1 << [i,p]\n else\n ts2 << [i,p]\n end\nend\nts1.sort!{|a,b| -(a[1]<=>b[1])}\nts2.sort!{|a,b| -(a[1]<=>b[1])}\np2 = [(v-2)/2,ts2.size-1].min\np1 = [v-3-p2*2,ts1.size-1].min\nwhile p1+1=0\n if p1+2 ts2[p2][1]\n p1+=2\n p2-=1\n else\n break\n end\n else\n if ts1[p1+1][1] > ts2[p2][1]\n p1+=1\n p2-=1\n else\n break\n end\n end\nend\nsum=0\nts = Array.new\n0.upto(p1){|x| sum+=ts1[x][1];ts< 1 ? catamarans[ci][1] : 0\n k_value = ki < kayaks.length ? kayaks[ki][1] : 0\n\n k_value += kayaks[ki + 1][1] if ki < kayaks.length - 1\n\n break if k_value == 0 && c_value == 0\n\n if c_value > k_value\n capacity += catamarans[ci][1]\n selected_vehicles << catamarans[ci][0]\n ci += 1;\n volume += 2\n else\n capacity += kayaks[ki][1]\n selected_vehicles << kayaks[ki][0]\n ki += 1\n volume += 1\n end\n end\n\n return capacity, selected_vehicles\nend\n\nif __FILE__ == $0\n n, lorryVolume = gets.split.map(&:to_i)\n vehicles = []\n n.times { vehicles << gets.split.map(&:to_i) }\n\n capacity, selected_vehicles = load_lorry(lorryVolume, vehicles)\n\n puts capacity\n puts selected_vehicles.join(\" \")\nend\n"}, {"source_code": "def load_lorry(lorryVolume, vehicles)\n kayaks = []\n catamarans = []\n\n vehicles.each_with_index do |v, i|\n kayaks << [i + 1, v[1]] if v[0] == 1\n catamarans << [i + 1, v[1]] if v[0] == 2\n end\n\n kayaks.sort! { |a, b| b[1] <=> a[1] }\n catamarans.sort! { |a, b| b[1] <=> a[1] }\n\n capacity = volume = ki = ci = 0\n selected_vehicles = []\n while (ki < kayaks.length || ci < catamarans.length) && volume < lorryVolume\n c_value = ci < catamarans.length && lorryVolume - volume > 1 ? catamarans[ci][1] : 0\n k_value = ki < kayaks.length ? kayaks[ki][1] : 0\n\n k_value += kayaks[ki + 1][1] if ki < kayaks.length - 1\n\n break if k_value == 0 && c_value == 0\n\n if c_value > k_value\n capacity += catamarans[ci][1]\n selected_vehicles << catamarans[ci][0]\n ci += 1;\n volume += 2\n else\n capacity += kayaks[ki][1]\n selected_vehicles << kayaks[ki][0]\n ki += 1\n volume += 1\n end\n end\n\n return capacity, selected_vehicles\nend\n\nif __FILE__ == $0\n n, lorryVolume = gets.split.map(&:to_i)\n vehicles = []\n n.times { vehicles << gets.split.map(&:to_i) }\n\n capacity, selected_vehicles = load_lorry(lorryVolume, vehicles)\n\n puts capacity\n puts selected_vehicles.join(\" \")\nend\n"}, {"source_code": "def load_lorry(lorryVolume, vehicles)\n kayaks = []\n catamarans = []\n\n vehicles.each_with_index do |v, i|\n if (v[0] == 1)\n kayaks << [i + 1, v[1]]\n else\n catamarans << [i + 1, v[1]]\n end\n end\n\n kayaks.sort_by! { |x| x[1] * -1 }\n catamarans.sort_by! { |x| x[1] * -1 }\n\n volume = ki = ci = 0\n while ((ki < kayaks.length || ci < catamarans.length) && volume < lorryVolume)\n c_value = ci < catamarans.length && lorryVolume - volume > 1 ? catamarans[ci][1] : 0\n k_value = ki < kayaks.length ? kayaks[ki][1] : 0\n\n k_value += kayaks[ki + 1][1] if ki < kayaks.length - 1\n\n if (c_value > k_value)\n ci += 1;\n volume += 2\n else\n ki += 1\n volume += 1\n end\n end\n\n sel_vehicles = kayaks.take(ki) + catamarans.take(ci)\n return sel_vehicles.reduce(0) { |c, x| c + x[1] }, sel_vehicles.map { |x| x[0] }\nend\n\nif __FILE__ == $0\n n, lorryVolume = gets.split.map(&:to_i)\n vehicles = []\n n.times { vehicles << gets.split.map(&:to_i) }\n\n capacity, selected_vehicles = load_lorry(lorryVolume, vehicles)\n\n puts capacity\n puts selected_vehicles.join(\" \")\nend\n"}, {"source_code": "n,v = gets.split.map(&:to_i)\n\na1 = []\na2 = []\n\nn.times do |i|\n t,q = gets.split.map(&:to_i)\n if t == 1 then a1 << [q, i]\n else a2 << [q, i]\n end\nend\n\na2.sort!\na2.reverse!\na1.sort!\na1.reverse!\n\ntwo = [v / 2, a2.length].min\ntotal = 0\ntwo.times do |i|\n total += a2[i][0]\nend\n\none = [v - two * 2, a1.length].min\none.times do |i| total += a1[i][0] end\n\nwhile two > 0 and one <= a1.length - 2 and a2[two - 1][0] < a1[one][0] + a1[one + 1][0] do\n total -= a2[two - 1][0]\n total += a1[one][0] + a1[one + 1][0];\n two -= 1\n one += 2\nend\n\nputs total\nans = []\ntwo.times do |i| ans << 1 + a2[i][1] end\none.times do |i| ans << 1 + a1[i][1] end\n\nputs ans * ' '"}, {"source_code": "num, max_size = gets.split.map(& :to_i)\nkayak = []\ncatamaran = []\nnum.times do |index|\n t, p = gets.split.map(& :to_i)\n if t == 1\n kayak << [index + 1, p]\n else\n catamaran << [index + 1, p]\n end\nend\n\nkayak.sort! { |a, b| b[1] <=> a[1] }\ncatamaran.sort! { |a, b| b[1] <=> a[1] }\n\n\nmax_c = [max_size / 2, catamaran.length].min\nmax_k = [max_size - 2 * max_c, kayak.length].min\n\nwhile max_c > 0 && max_k <= kayak.length\n if max_k + 2 <= kayak.length #there are two more elements in the array\n if catamaran[max_c - 1][1] < (kayak[max_k][1] + kayak[max_k + 1][1])\n max_c = max_c - 1\n max_k = max_k + 2\n else\n break\n end\n else\n break\n end\nend\n\nans_set = []\nsum = 0\n0.upto(max_c - 1) { |i| sum = sum + catamaran[i][1]; ans_set << catamaran[i][0] }\n0.upto(max_k - 1) { |i| sum = sum + kayak[i][1]; ans_set << kayak[i][0] }\nputs sum\nputs ans_set.join(\" \")"}, {"source_code": "n, v = gets.split.map(&:to_i)\n\nkayaks = []\ncatamarans = []\nn.times do |index|\n\ttype, p = gets.split.map(&:to_i)\n\tif type == 1\n\t\tkayaks << [index + 1, p]\n\telse\n\t\tcatamarans << [index + 1, p]\n\tend\nend\n\nkayaks.sort! { |e1, e2| e2[1] <=> e1[1] }\ncatamarans.sort! { |e1, e2| e2[1] <=> e1[1] }\n\npossible_capacity = {}\nmax_c = [v / 2, catamarans.length].min\nmax_k = [v - 2 * max_c, kayaks.length].min\nindexes = []\ntotal = (0...max_c).inject(0) { |sum, value| sum + catamarans[value][1] } +\n\t\t\t\t(0...max_k).inject(0) { |sum, value| sum + kayaks[value][1] }\n\nwhile max_c > 0 && max_k <= kayaks.length - 2 && catamarans[max_c - 1][1] < kayaks[max_k][1] + kayaks[max_k + 1][1]\n\ttotal -= catamarans[max_c - 1][1]\n\ttotal += kayaks[max_k][1] + kayaks[max_k + 1][1]\n\tmax_c -= 1\n\tmax_k += 2\nend\n\nindexes = []\nmax_c.times do |index|\n\tindexes << catamarans[index][0]\nend\nmax_k.times do |index|\n\tindexes << kayaks[index][0]\nend\n\nputs total\nputs indexes.join(' ')"}, {"source_code": "n, max = gets().split(\" \").collect {|x| x.to_i}\nkayaks = []\ncatemerons = []\nn.times do |i|\n type, capacity = (gets().split(\" \").collect {|x| x.to_i})\n if type == 1\n kayaks << [i, capacity]\n else\n catemerons << [i, capacity]\n end\nend\nkayaks.sort! {|x, y| y[1] <=> x[1]}\ncatemerons.sort! {|x, y| y[1] <=> x[1]}\n\nmax_c = [catemerons.length, (max/2).to_i].min\nmax_k = [kayaks.length, max].min\n\n#puts \"kayaks: #{kayaks.inspect}, catemerons: #{catemerons.inspect}, max_k: #{max_k}, max_c: #{max_c}\"\n\nwt = 0\noptimal = 0\nselected_k = []\nselected_c = []\ni = 0\nwhile (wt < max) && (i < max_c) do\n if (wt + 2) <= max\n wt += 2\n optimal += catemerons[i][1]\n i += 1\n else\n break\n end \nend\n\n#puts \"After catemerons, wt: #{wt}, i: #{i}\"\n\nj = 0\nwhile (wt < max) && (j < max_k) do\n wt += 1\n optimal += kayaks[j][1]\n j += 1\nend\n\n#puts \"After kayaks, wt: #{wt}, j: #{j}\"\n\nwhile (i > 0) && (j < max_k) do\n proposed_optimal1 = optimal - catemerons[i - 1][1] + kayaks[j][1]\n proposed_optimal2 = proposed_optimal1\n proposed_optimal2 += kayaks[j + 1][1] if (j < (max_k - 1))\n if proposed_optimal2 > optimal\n i -= 1\n j += 1\n optimal = proposed_optimal2\n j += 1 if (proposed_optimal2 > proposed_optimal1)\n else\n break\n end\nend\n\nputs optimal\n(0..(i - 1)).each do |i| print \"#{catemerons[i][0] + 1} \" end\n(0..(j - 1)).each do |j| print \"#{kayaks[j][0] + 1} \" end\n"}, {"source_code": "n, max = gets().split(\" \").collect {|x| x.to_i}\nkayaks = []\ncatemerons = []\nn.times do |i|\n type, capacity = (gets().split(\" \").collect {|x| x.to_i})\n if type == 1\n kayaks << [i, capacity]\n else\n catemerons << [i, capacity]\n end\nend\nkayaks.sort! {|x, y| y[1] <=> x[1]}\ncatemerons.sort! {|x, y| y[1] <=> x[1]}\n\nmax_c = [catemerons.length, (max/2).to_i].min\nmax_k = [kayaks.length, max].min\n\n#puts \"kayaks: #{kayaks.inspect}, catemerons: #{catemerons.inspect}, max_k: #{max_k}, max_c: #{max_c}\"\n\nwt = 0\noptimal = 0\nselected_k = []\nselected_c = []\ni = 0\nwhile (wt < max) && (i < max_c) do\n if (wt + 2) <= max\n wt += 2\n optimal += catemerons[i][1]\n i += 1\n else\n break\n end \nend\n\n#puts \"After catemerons, wt: #{wt}, i: #{i}\"\n\nj = 0\nwhile (wt < max) && (j < max_k) do\n wt += 1\n optimal += kayaks[j][1]\n j += 1\nend\n\n#puts \"After kayaks, wt: #{wt}, j: #{j}\"\n\nwhile (i > 0) && (j < max_k) do\n proposed_optimal1 = optimal - catemerons[i - 1][1] + kayaks[j][1]\n proposed_optimal2 = proposed_optimal1\n proposed_optimal2 += kayaks[j + 1][1] if (j < (max_k - 1))\n if (proposed_optimal1 > optimal) || (proposed_optimal2 > optimal)\n i -= 1\n j += 1\n optimal = proposed_optimal1\n if (proposed_optimal2 > proposed_optimal1)\n j += 1\n optimal = proposed_optimal2\n end\n else\n break\n end\nend\n\nputs optimal\n(0..(i - 1)).each do |i| print \"#{catemerons[i][0] + 1} \" end\n(0..(j - 1)).each do |j| print \"#{kayaks[j][0] + 1} \" end\n"}, {"source_code": "n,v = gets.split.map(&:to_i)\n\na1 = []\na2 = []\n\nn.times do |i|\n t,q = gets.split.map(&:to_i)\n if t == 1 then a1 << [q, i]\n else a2 << [q, i]\n end\nend\n\na2.sort!\na2.reverse!\na1.sort!\na1.reverse!\n\ntwo = [v / 2, a2.length].min\ntotal = 0\ntwo.times do |i|\n total += a2[i][0]\nend\n\none = [v - two * 2, a1.length].min\none.times do |i| total += a1[i][0] end\n\nwhile two > 0 and one <= a1.length - 2 and a2[two - 1][0] < a1[one][0] + a1[one + 1][0] do\n total -= a2[two - 1][0]\n total += a1[one][0] + a1[one + 1][0];\n two -= 1\n one += 2\nend\n\nputs total\nans = []\ntwo.times do |i| ans << 1 + a2[i][1] end\none.times do |i| ans << 1 + a1[i][1] end\n\nputs ans * ' '\n\n"}], "negative_code": [{"source_code": "n,v = gets.split(\" \").map{|x| x.to_i}\nts = Array.new\nn.times do |i|\n t,p = gets.split(\" \").map{|x| x.to_i}\n ts << [i,t,p]\nend\nts.sort!{|a,b| -(a[2]*2/a[1]<=>b[2]*2/b[1])}\nmax = 0\nset = Array.new\nts.each_with_index do |t,i|\n break if v<=0\n applicable = false\n if v>2\n applicable = true\n else\n if v==t[1]\n applicable=true\n elsif v>t[1]\n if ts[i+1]\n if ts[i+1][1]==1\n applicable=true\n else\n nt = ts[i+1..-1].select{|x| x[1]==1}.first\n if nt\n if t[2]+nt[2]>ts[i+1][2]\n applicable=true\n end\n end\n end\n else\n applicable=true\n end\n end\n end\n if applicable\n set << t[0]+1\n v -= t[1]\n max += t[2]\n end\nend\nputs max\nputs set.join(\" \")\n"}, {"source_code": "n,v = gets.split(\" \").map{|x| x.to_i}\nts1 = Array.new\nts2 = Array.new\nn.times do |i|\n t,p = gets.split(\" \").map{|x| x.to_i}\n if t == 1\n ts1 << [i,p]\n else\n ts2 << [i,p]\n end\nend\nts1.sort!{|a,b| -(a[1]<=>b[1])}\nts2.sort!{|a,b| -(a[1]<=>b[1])}\np2 = [(v-2)/2,ts2.size-1].min\np1 = n-3-p2*2\nwhile p1+2=0\n if ts1[p1+1][1]+ts1[p1+2][1] > ts2[p2][1]\n p1+=2\n p2-=1\n else\n break\n end\nend\nsum=0\nts = Array.new\n0.upto(p1){|x| sum+=ts1[x][1];ts< a[1] }\ncatamaran.sort! { |a, b| b[1] <=> a[1] }\n\n\nmax_c = [max_size / 2, catamaran.length].min\nmax_k = [max_size - 2 * max_c, kayak.length].min\n\nwhile max_c > 0 && max_k <= kayak.length\n if max_k + 2 <= kayak.length #there are two more elements in the array\n if catamaran[max_c - 1][1] < (kayak[max_k][1] + kayak[max_k + 1][1])\n max_c = max_c - 1\n max_k = max_k + 2\n else\n break\n end\n else\n if catamaran[max_c - 1][1] < kayak[max_k][1]\n max_c = max_c - 1\n max_k = max_k + 1\n else\n break\n end\n end\nend\n\nans_set = []\nsum = 0\n0.upto(max_c - 1) { |i| sum = sum + catamaran[i][1]; ans_set << catamaran[i][0] }\n0.upto(max_k - 1) { |i| sum = sum + kayak[i][1]; ans_set << kayak[i][0] }\nputs sum\nans_set.sort!\nputs ans_set.to_s[1..-2]"}, {"source_code": "num, max_size = gets.split.map(& :to_i)\nkayak = []\ncatamaran = []\nnum.times do |index|\n t, p = gets.split.map(& :to_i)\n if t == 1\n kayak << [index + 1, p]\n else\n catamaran << [index + 1, p]\n end\nend\n\nkayak.sort! { |a, b| b[1] <=> a[1] }\ncatamaran.sort! { |a, b| b[1] <=> a[1] }\n\n\nmax_c = [max_size / 2, catamaran.length].min\nmax_k = [max_size - 2 * max_c, kayak.length].min\n\nwhile max_c > 0 && max_k <= kayak.length && max_k > 0\n if max_k + 2 <= kayak.length #there are two more elements in the array\n if catamaran[max_c - 1][1] < (kayak[max_k][1] + kayak[max_k + 1][1])\n max_c = max_c - 1\n max_k = max_k + 2\n else\n break\n end\n else\n if catamaran[max_c - 1][1] < kayak[max_k][1]\n max_c = max_c - 1\n max_k = max_k + 1\n else\n break\n end\n end\nend\n\nans_set = []\nsum = 0\n0.upto(max_c - 1) { |i| sum = sum + catamaran[i][1]; ans_set << catamaran[i][0] }\n0.upto(max_k - 1) { |i| sum = sum + kayak[i][1]; ans_set << kayak[i][0] }\nputs sum\nputs ans_set.join(\" \")"}, {"source_code": "num, max_size = gets.split.map(& :to_i)\nkayak = []\ncatamaran = []\nnum.times do |index|\n t, p = gets.split.map(& :to_i)\n if t == 1\n kayak << [index + 1, p]\n else\n catamaran << [index + 1, p]\n end\nend\n\nkayak.sort! { |a, b| b[1] <=> a[1] }\ncatamaran.sort! { |a, b| b[1] <=> a[1] }\n\n\nmax_c = [max_size / 2, catamaran.length].min\nmax_k = [max_size - 2 * max_c, kayak.length].min\n\nwhile max_c > 0 && max_k <= kayak.length\n if max_k + 2 <= kayak.length #there are two more elements in the array\n p \"OK\"\n if catamaran[max_c - 1][1] < (kayak[max_k][1] + kayak[max_k + 1][1])\n max_c = max_c - 1\n max_k = max_k + 2\n else\n break\n end\n else\n if catamaran[max_c - 1][1] < kayak[max_k][1]\n max_c = max_c - 1\n max_k = max_k + 1\n else\n break\n end\n end\nend\n\nans_set = []\nsum = 0\n0.upto(max_c - 1) { |i| sum = sum + catamaran[i][1]; ans_set << catamaran[i][0] }\n0.upto(max_k - 1) { |i| sum = sum + kayak[i][1]; ans_set << kayak[i][0] }\nputs sum\nans_set.sort!\nputs ans_set.to_s[1..-2]"}, {"source_code": "n, max = gets().split(\" \").collect {|x| x.to_i}\narr = []\ni = 0\nn.times do |i|\n arr << (gets().split(\" \").collect {|x| x.to_i}).push(i + 1)\nend\narr.sort! {|x, y| y[1] <=> x[1]}\n#puts arr.inspect\nwt = 0\noptimal = 0\nn = []\narr.each_with_index do |a, i|\n if ((wt + a[0]) <= max)\n optimal += a[1]\n n << a[2]\n wt += a[0]\n break if wt == max\n end\nend\nputs optimal\nputs n.join(\",\")\n"}, {"source_code": "n, max = gets().split(\" \").collect {|x| x.to_i}\narr = []\ni = 0\nn.times do |i|\n arr << (gets().split(\" \").collect {|x| x.to_i}).push(i + 1)\nend\narr.sort! {|x, y| y[1] <=> x[1]}\n#puts arr.inspect\nwt = 0\noptimal = 0\nn = []\narr.each_with_index do |a, i|\n if ((wt + a[0]) <= max)\n optimal += a[1]\n n << a[2]\n wt += a[0]\n break if wt == max\n end\nend\nputs optimal\nputs n.join(\" \")\n"}, {"source_code": "n, max = gets().split(\" \").collect {|x| x.to_i}\narr = []\ni = 0\nn.times do |i|\n arr << (gets().split(\" \").collect {|x| x.to_i}).push(i + 1)\nend\narr.sort! {|x, y| y[1] <=> x[1]}\n#puts arr.inspect\nwt = 0\noptimal = 0\nn1 = []\nn2 = []\narr.each_with_index do |a, i|\n if ((wt + a[0]) <= max)\n optimal += a[1]\n if a[0] == 1\n n1 << a[2]\n else\n n2 << a[2]\n end\n wt += a[0]\n break if wt == max\n end\nend\nputs optimal\nputs n2.concat(n1).join(\" \")\n"}, {"source_code": "n, max = gets().split(\" \").collect {|x| x.to_i}\nkayaks = []\ncatemerons = []\nn.times do |i|\n type, capacity = (gets().split(\" \").collect {|x| x.to_i})\n if type == 1\n kayaks << [i, capacity]\n else\n catemerons << [i, capacity]\n end\nend\nkayaks.sort! {|x, y| y[1] <=> x[1]}\ncatemerons.sort! {|x, y| y[1] <=> x[1]}\n\nmax_c = [catemerons.length, (max/2).to_i].min\nmax_k = [kayaks.length, max].min\n\nputs \"kayaks: #{kayaks.inspect}, catemerons: #{catemerons.inspect}, max_k: #{max_k}, max_c: #{max_c}\"\n\nwt = 0\noptimal = 0\nselected_k = []\nselected_c = []\ni = 0\nwhile (wt < max) && (i < max_c) do\n if (wt + 2) <= max\n wt += 2\n optimal += catemerons[i][1]\n i += 1\n else\n break\n end \nend\n\n#puts \"After catemerons, wt: #{wt}, i: #{i}\"\n\nj = 0\nwhile (wt < max) && (j < max_k) do\n wt += 1\n optimal += kayaks[j][1]\n j += 1\nend\n\n#puts \"After kayaks, wt: #{wt}, j: #{j}\"\n\nwhile (i > 0) && (j < max_k) do\n proposed_optimal1 = optimal - catemerons[i - 1][1] + kayaks[j][1]\n proposed_optimal2 = proposed_optimal1\n proposed_optimal2 += kayaks[j + 1][1] if (j < (max_k - 1))\n if (proposed_optimal1 > optimal) || (proposed_optimal2 > optimal)\n i -= 1\n j += 1\n optimal = proposed_optimal1\n if (proposed_optimal2 > proposed_optimal1)\n j += 1\n optimal = proposed_optimal2\n end\n else\n break\n end\nend\n\nputs optimal\n(0..(i - 1)).each do |i| print \"#{catemerons[i][0] + 1} \" end\n(0..(j - 1)).each do |j| print \"#{kayaks[j][0] + 1} \" end\n"}, {"source_code": "n,v = gets.split.map(&:to_i)\n\na1 = []\na2 = []\n\nn.times do |i|\n t,q = gets.split.map(&:to_i)\n if t == 1 then a1 << [q, i]\n else a2 << [q, i]\n end\nend\n\na2.sort!\na2.reverse!\na1.sort!\na1.reverse!\n\none = 0\ntwo = [v / 2, a2.length].min\ntotal = 0\ntwo.times do |i|\n total += a2[i][0]\nend\n\nwhile two > 0 and one < a1.length - 2 and a2[two - 1][0] < a1[one][0] + a1[one + 1][0] do\n total -= a2[two - 1][0]\n total += a1[one][0] + a1[one + 1][0];\n two -= 1\n one += 2\nend\n\nputs total\nans = []\ntwo.times do |i| ans << 1 + a2[i][1] end\none.times do |i| ans << 1 + a1[i][1] end\n\nputs ans * ' '\n\n"}, {"source_code": "Vehicle = Struct.new(:index, :capacity)\n\nclass LorryLoader\n def self.load(lorry_volume, vehicle_registry)\n kayaks = []\n catamarans = []\n\n vehicle_registry.each.with_index do |vehicle, index|\n type, capacity = vehicle.split.map(&:to_i)\n if type == 1\n kayaks << Vehicle.new(index + 1, capacity)\n elsif\n catamarans << Vehicle.new(index + 1, capacity)\n end\n end\n\n kayaks.sort_by! { |x| -x.capacity }\n catamarans.sort_by! { |x| -x.capacity }\n\n selected_vehicles = []\n total_capacity = volume = ki = ci = 0\n while (ki < kayaks.size || ci < catamarans.size) && volume < lorry_volume\n k_cap = ki < kayaks.size ? kayaks[ki].capacity : 0\n k_cap += (ki < kayaks.size - 1 ? kayaks[ki - 1].capacity : 0)\n c_cap = ci < catamarans.size && lorry_volume - volume > 1 ? catamarans[ci].capacity : 0\n\n break if k_cap == 0 && c_cap == 0\n\n if (c_cap >= k_cap)\n selected_vehicles << catamarans[ci].index\n total_capacity += catamarans[ci].capacity\n volume += 2\n ci += 1\n else\n selected_vehicles << kayaks[ki].index\n total_capacity += kayaks[ki].capacity\n volume += 1\n ki += 1\n end\n end\n\n return total_capacity, selected_vehicles\n end\nend\n\nif __FILE__ == $0\n vehicle_count, lorry_volume = gets.split.map(&:to_i)\n vehicle_registry = []\n vehicle_count.times { vehicle_registry << gets }\n\n capacity, selected_vehicles = LorryLoader.load(lorry_volume, vehicle_registry)\n\n puts capacity\n puts selected_vehicles.join(' ')\nend\n"}, {"source_code": "def load_lorry(lorryVolume, vehicles)\n kayaks = []\n catamarans = []\n\n vehicles.each_with_index do |v, i|\n kayaks << [i + 1, v[1]] if v[0] == 1\n catamarans << [i + 1, v[1]] if v[0] == 2\n end\n\n kayaks.sort!\n catamarans.sort!\n\n capacity = volume = ki = ci = 0\n selected_vehicles = []\n while (ki < kayaks.length || ci < catamarans.length) && volume < lorryVolume\n c_value = ci < catamarans.length && lorryVolume - volume > 1 ? catamarans[ci][1] : 0\n k_value = ki < kayaks.length ? kayaks[ki][1] : 0\n\n k_value += kayaks[ki + 1][1] if ki < kayaks.length - 1\n\n break if k_value == 0 && c_value == 0\n\n if c_value > k_value\n capacity += catamarans[ci][1]\n selected_vehicles << catamarans[ci][0]\n ci += 1;\n volume += 2\n else\n capacity += kayaks[ki][1]\n selected_vehicles << kayaks[ki][0]\n ki += 1\n volume += 1\n end\n end\n\n return capacity, selected_vehicles\nend\n\nif __FILE__ == $0\n n, lorryVolume = gets.split.map(&:to_i)\n vehicles = []\n n.times { vehicles << gets.split.map(&:to_i) }\n\n capacity, selected_vehicles = load_lorry(lorryVolume, vehicles)\n\n puts capacity\n puts selected_vehicles.join(\" \")\nend\n"}, {"source_code": "n, v = gets.split.map(&:to_i)\n\nkayaks = []\ncatamarans = []\n\nn.times do\n\tvehicle_info = gets.split.map(&:to_i)\n\tif vehicle_info[0] == 1\n\t\tkayaks << vehicle_info[1]\n\telse\n\t\tcatamarans << vehicle_info[1]\n\tend\nend\n\nkayaks.sort! { |e1, e2| e2 <=> e1 }\ncatamarans.sort! { |e1, e2| e2 <=> e1 }\n\npossible_capacity = []\nmax_catamarans = v / 2\nmax_kayaks = [v, kayaks.length].min\n(0..max_catamarans).each do |num_of_c|\n\tnext if (num_of_k = v - 2 * num_of_c) > max_kayaks\n\tcapacity = kayaks[0...num_of_k].inject(0) { |sum, value| sum + value } + \n\t\t\t\t\t\t catamarans[0...num_of_c].inject(0) { |sum, value| sum + value }\n\tcount = num_of_k + num_of_c\n\tpossible_capacity << [capacity, count]\nend\n\nputs possible_capacity"}, {"source_code": "n, v = gets.split.map(&:to_i)\n\nkayaks = []\ncatamarans = []\nn.times do |index|\n\ttype, p = gets.split.map(&:to_i)\n\tif type == 1\n\t\tkayaks << [index + 1, p]\n\telse\n\t\tcatamarans << [index + 1, p]\n\tend\nend\n\nkayaks.sort! { |e1, e2| e2[1] <=> e1[1] }\ncatamarans.sort! { |e1, e2| e2[1] <=> e1[1] }\n\npossible_capacity = {}\nmax_c = [v / 2, catamarans.length].min\nmax_k = [v - 2 * max_c, kayaks.length].min\nindexes = []\ntotal = (0...max_c).inject(0) { |sum, value| sum + catamarans[value][1] } +\n\t\t\t\t(0...max_k).inject(0) { |sum, value| sum + kayaks[value][1] }\nputs total\nwhile max_c > 0 && max_k <= kayaks.length - 2 && catamarans[max_c - 1][1] < kayaks[max_k][1] + kayaks[max_k + 1][1]\n\ttotal -= catamarans[max_c - 1][1]\n\ttotal += kayaks[max_k][1] + kayaks[max_k + 1][1]\n\tmax_c -= 1\n\tmax_k += 2\nend\n\nindexes = []\nmax_c.times do |index|\n\tindexes << catamarans[index][0]\nend\nmax_k.times do |index|\n\tindexes << kayaks[index][0]\nend\n\nputs total\nputs indexes.join(' ')"}, {"source_code": "n, v = gets.split.map(&:to_i)\n\nkayaks = []\ncatamarans = []\nn.times do |index|\n\ttype, p = gets.split.map(&:to_i)\n\tif type == 1\n\t\tkayaks << [index + 1, p]\n\telse\n\t\tcatamarans << [index + 1, p]\n\tend\nend\n\nkayaks.sort! { |e1, e2| e2[1] <=> e1[1] }\ncatamarans.sort! { |e1, e2| e2[1] <=> e1[1] }\n\npossible_capacity = {}\nmax_c = [v / 2, catamarans.length].min\nmax_k = [v - 2 * max_c, kayaks.length].min\nindexes = []\ntotal = (0...max_c).inject(0) { |sum, value| sum + catamarans[value][1] } +\n\t\t\t\t(0...max_k).inject(0) { |sum, value| sum + kayaks[value][1] }\n\nwhile max_c > 0 && max_k <= kayaks.length - 2 && catamarans[max_c - 1][0] < kayaks[max_k][0] + kayaks[max_k + 1][0]\n\ttotal -= catamarans[max_c - 1][0]\n\ttotal += kayaks[max_k][0] + kayaks[max_k + 1][0]\n\tmax_c -= 1\n\tmax_k += 2\nend\n\nindexes = []\nmax_c.times do |index|\n\tindexes << catamarans[index][0]\nend\nmax_k.times do |index|\n\tindexes << kayaks[index][0]\nend\n\nputs total\nputs indexes.join(' ')"}, {"source_code": "n, v = gets.split.map(&:to_i)\n\nkayaks = []\ncatamarans = []\nn.times do |index|\n\ttype, p = gets.split.map(&:to_i)\n\tif type == 1\n\t\tkayaks << [index + 1, p]\n\telse\n\t\tcatamarans << [index + 1, p]\n\tend\nend\n\nkayaks.sort! { |e1, e2| e2[1] <=> e1[1] }\ncatamarans.sort! { |e1, e2| e2[1] <=> e1[1] }\n\npossible_capacity = {}\nmax_c = [v / 2, catamarans.length].min\nmax_k = [v - 2 * max_c, kayaks.length].min\nindexes = []\ntotal = (0...max_c).inject(0) { |sum, value| sum + catamarans[value][1] } +\n\t\t\t\t(0...max_k).inject(0) { |sum, value| sum + kayaks[value][1] }\n\nwhile max_c > 0 && max_k <= kayaks.length - 2 && catamarans[max_c - 1][1] < kayaks[max_k][1] + kayaks[max_k + 1][1]\n\ttotal -= catamarans[max_c - 1][0]\n\ttotal += kayaks[max_k][0] + kayaks[max_k + 1][0]\n\tmax_c -= 1\n\tmax_k += 2\nend\n\nindexes = []\nmax_c.times do |index|\n\tindexes << catamarans[index][0]\nend\nmax_k.times do |index|\n\tindexes << kayaks[index][0]\nend\n\nputs total\nputs indexes.join(' ')"}, {"source_code": "n, v = gets.split.map(&:to_i)\n\nkayaks = []\ncatamarans = []\nn.times do |index|\n\ttype, p = gets.split.map(&:to_i)\n\tif type == 1\n\t\tkayaks << [index + 1, p]\n\telse\n\t\tcatamarans << [index + 1, p]\n\tend\nend\n\nkayaks.sort! { |e1, e2| e2[1] <=> e1[1] }\ncatamarans.sort! { |e1, e2| e2[1] <=> e1[1] }\n\npossible_capacity = {}\nmax_c = [v / 2, catamarans.length].min\nmax_k = [v - 2 * max_c, kayaks.length].min\nindexes = []\ntotal = (0...max_c).inject(0) { |sum, value| sum + catamarans[value][1] } +\n\t\t\t\t(0...max_k).inject(0) { |sum, value| sum + kayaks[value][1] }\n\nwhile max_c > 0 && max_k <= kayaks.length - 2 && catamarans[max_c - 1][0] < kayaks[max_k][0] + kayaks[max_k + 1][0]\n\ttotal -= catamarans[max_c - 1][0]\n\ttotal += kayaks[max_k][0] + kayaks[max_k + 1][0]\n\tmax_c -= 1\n\tmax_k += 2\nend\n\nindexes = []\nmax_k.times do |index|\n\tindexes << kayaks[index][0]\nend\nmax_c.times do |index|\n\tindexes << catamarans[index][0]\nend\n\nputs total\nputs indexes.join(' ')"}, {"source_code": "n, v = gets.split.map(&:to_i)\n\nkayaks = []\ncatamarans = []\n\nn.times do\n\tvehicle_info = gets.split.map(&:to_i)\n\tif vehicle_info[0] == 1\n\t\tkayaks << vehicle_info[1]\n\telse\n\t\tcatamarans << vehicle_info[1]\n\tend\nend\n\nkayaks.sort! { |e1, e2| e2 <=> e1 }\ncatamarans.sort! { |e1, e2| e2 <=> e1 }\n\npossible_capacity = {}\nmax_catamarans = v / 2\n(0..max_catamarans).each do |num_of_c|\n\tnext if (num_of_k = v - 2 * num_of_c) > kayaks.length\n\tcapacity = kayaks[0...num_of_k].inject(0) { |sum, value| sum + value } + \n\t\t\t\t\t\t catamarans[0...num_of_c].inject(0) { |sum, value| sum + value }\n\tpossible_capacity[capacity] = [num_of_k, num_of_c]\nend\n\nmax_capacity = possible_capacity.max\nputs max_capacity[0]\nputs ([1] * max_capacity[1][0] + [2] * max_capacity[1][1]).join(' ')"}], "src_uid": "a1f98b06650a5755e784cd6ec6f3b211"} {"source_code": "t=gets.to_i\r\nt.times{\r\n\tn = gets.to_i\r\n\tif n<2020 \r\n\t\tputs \"NO\"\r\n\telse\r\n\t\tputs n%2020 <= n/2020? \"YES\" : \"NO\"\r\n\tend\r\n}\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n puts n % 2020 <= n / 2020 ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "require 'set'\r\ns = Set.new\r\n\r\nflag = 0\r\n\r\nval1 = 1000000/2020;\r\nval2 = 1000000/2021;\r\n\r\nfor i in (0..val1)\r\n for j in (0..val2)\r\n temp = i*2020+j*2021;\r\n s << temp;\r\n end\r\nend\r\n\r\nn = gets.chomp.to_i;\r\nwhile n != 0\r\n n = n-1;\r\n value = gets.chomp.to_i;\r\n if s.include?(value)\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend"}, {"source_code": "MAX_N = 10**6 + 5\nflag = [false] * MAX_N\nflag[0] = true\n(0...MAX_N).each do |i|\n\tif flag[i]\n\t\tflag[i + 2020] = true if i + 2020 < MAX_N\n\t\tflag[i + 2021] = true if i + 2021 < MAX_N\n\tend\nend\n\ngets.to_i.times do\n\tn = gets.to_i\n\tputs flag[n] ? 'YES' : 'NO'\nend\n"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n puts (n % 2020 <= n / 2020) ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "tcases = gets.chomp.to_i\r\ndef solve()\r\n n = gets.chomp.to_i \r\n q = n / 2020\r\n r = n % 2020\r\n puts (r <= q) ? \"YES\" : \"NO\"\r\nend\r\ntcases.times do solve() end\r\n"}, {"source_code": "t = gets.chomp.to_i\r\n# arr = []\r\nt.times do\r\n n = gets.chomp.to_i\r\n ok = false\r\n 0.upto(500) do |i|\r\n ans = n - i * 2021\r\n # p ans\r\n if ans >= 0\r\n amari = ans % 2020\r\n if amari == 0\r\n puts \"YES\"\r\n # arr << i\r\n ok = true\r\n break\r\n end\r\n else\r\n break\r\n end\r\n end\r\n if ok == false\r\n puts \"NO\"\r\n end\r\nend"}, {"source_code": "l=[0]*1000001\r\ni=0\r\nwhile i*2020<=1000000\r\n j=0\r\n while i*2020+j*2021<=1000000\r\n l[2020*i+2021*j]+=1 if l[2020*i+2021*j]==0\r\n j+=1\r\n end\r\n i+=1\r\nend\r\ngets.to_i.times do\r\n n=gets.to_i\r\n if l[n]==1\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n puts n % 2020 >= n / 2020 ? \"YES\" : \"NO\"\r\nend"}], "src_uid": "3ec1b7027f487181dbdfb12f295f11ae"} {"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n s=gets.chomp.chars\r\n q=\"\"\r\n t=0\r\n s.each.with_index do |ss,i|\r\n if q==\"\"\r\n if ss==\"?\"\r\n t+=1\r\n elsif ss==\"B\"\r\n s[0,i]=[\"R\"]*(i%2)+[\"B\",\"R\"]*(i/2)\r\n q=\"B\"\r\n elsif ss==\"R\"\r\n s[0,i]=[\"B\"]*(i%2)+[\"R\",\"B\"]*(i/2)\r\n q=\"R\"\r\n end\r\n elsif q==\"B\"\r\n if ss==\"?\"\r\n s[i]=\"R\"\r\n q=\"R\"\r\n elsif ss==\"R\"\r\n q=\"R\"\r\n end\r\n else\r\n if ss==\"?\"\r\n s[i]=\"B\"\r\n q=\"B\"\r\n elsif ss==\"B\"\r\n q=\"B\"\r\n end\r\n end\r\n end\r\n if q==\"\"\r\n s=[\"R\"]*(n%2)+[\"B\",\"R\"]*(n/2)\r\n end\r\n puts s.join\r\nend\r\n", "positive_code": [{"source_code": "END { load __FILE__ unless $stdin.eof? }\n\nt = gets.to_i\nt.times do\n\nn = gets.to_i\ns = gets.chomp.chars.map! { |c| c == \"B\" ? 1 : c == \"R\" ? 2 : 0 }\n\ni = s.index(&:nonzero?) || n\nc = s[i] || 1\ni.times.reverse_each do |k|\n s[k] = (c ^= 3)\nend\n\nwhile i < n\n i += 1\n j = (i...n).find { |k| s[k] != 0 } || n\n\n c = s[i-1]\n (i...j).each { |k| s[k] = (c ^= 3) }\n\n i = j\nend\n\nputs (s * \"\").tr(\"12\", \"BR\")\n\nend\n"}], "negative_code": [], "src_uid": "280487a73e6070a7dc7deb44332d6319"} {"source_code": "t = gets.to_i\n\n1.upto t do\n c = p = 0\n n, k = gets.split.map(&:to_i)\n if n % 2 == 0\n n += k*2\n else\n 2.upto Math.sqrt(n+1).to_i do |i|\n if n % i == 0\n n += i\n p = 1\n break\n end\n end\n if p == 0\n n += n\n end\n n += (k-1)*2\n end\n puts n\nend", "positive_code": [{"source_code": "def minimum(x)\n for i in 2..x do\n return i if x % i == 0\n end\nend\n\nt = gets.chomp.to_i\n\nt.times do\n n, k = gets.chomp.split(' ').collect(&:to_i)\n puts minimum(n) + n + (2*(k-1))\nend\n"}, {"source_code": "\ndef ans(n, k)\n # \u5076\u6570 \u4e3a2\uff0c \u52a02\u540e\u8fd8\u662f\u5076\u6570\uff0c \u6240\u4ee5 n + 2k\n # \u5947\u6570 \u7b2c\u4e00\u4e2a\u4e3a\u5947\u4e66\uff0c \u76f8\u52a0\u540e\u4e5f\u4e3a\u5076\u6570 n + first.x + 2 (k-1)\n if n & 0x1 == 0\n return n + 2 * k\n end\n\n d = 3\n \n while d <= Math.sqrt(n)\n n % d == 0 and return n + d + 2 *(k-1)\n d += 2\n end\n\n return n + n + 2 * (k-1)\nend\n\nline = gets().to_i\n\nline.times {\n (n,k) = gets.scan(/\\d+/).map(&:to_i)\n puts ans(n,k)\n}"}, {"source_code": "\ndef ans(n, k)\n # \u5076\u6570 \u4e3a2\uff0c \u52a02\u540e\u8fd8\u662f\u5076\u6570\uff0c \u6240\u4ee5 n + 2k\n # \u5947\u6570 \u7b2c\u4e00\u4e2a\u4e3a\u5947\u4e66\uff0c \u76f8\u52a0\u540e\u4e5f\u4e3a\u5076\u6570 n + first.x + 2 (k-1)\n if n & 0x1 == 0\n return n + 2 * k\n end\n\n d = 3\n while d < n\n n % d == 0 and break\n d += 2\n end\n\n return n + d + 2*(k-1)\nend\n\nline = gets().to_i\n\nline.times {\n (n,k) = gets.scan(/\\d+/).map(&:to_i)\n puts ans(n,k)\n}"}, {"source_code": "t = gets.to_i\n\n1.upto t do\n c = 0\n n, k = gets.split.map(&:to_i)\n if n % 2 == 0\n n += k*2\n else\n 3.upto n do |i|\n if n % i == 0\n n += i\n break\n end\n end\n n += (k-1)*2\n end\n puts n\nend"}, {"source_code": "require 'prime'\ngets.to_i.times do\n n, k=gets.split.map &:to_i\n f=n.prime_division[0][0]\n puts n+f+2*(k-1)\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (aj\n\t\t\tputs 'somethong wrong with index in func _query'\n\t\t\texit 1\n\t\tend\n\n\t\tif i==b and j==e\n\t\t\treturn @tree[ind]\n\t\telse\n\t\t\tmid = (b+e)/2\n\t\t\tif i>mid\n\t\t\t\treturn _query(i, j, 2*ind+1, mid+1, e)\n\t\t\telsif j<= mid\n\t\t\t\treturn _query(i,j,2*ind,b,mid)\n\t\t\telse\n\t\t\t\ta = _query(i, mid,2*ind, b, mid)\n\t\t\t\tb = _query(mid+1,j,2*ind+1, mid+1,e)\n\t\t\t\treturn min(a,b)\n\t\t\tend\n\t\tend\n\tend\n\n\tdef set(ind, value)\n\t\t@data[ind] = value\n\t\tupdate(ind, value)\n\tend\n\n\tdef update(ind, value); _update( ind, value,1, 0, @data.size-1); end\n\n\tdef _update(ind, value,i,b,e)\n\n\t\tif b==e\n\t\t\t@tree[i] = value\n\t\t\treturn\n\t\tend\t\t\n\t\tmid = (b+e)/2\n\t\tif ind > mid\n\t\t\ta=_update(ind, value,2*i+1, mid+1, e)\t\t\n\n\t\telse\n\t\t\t_update(ind, value, 2*i, b, mid)\n\t\tend\n\t\t@tree[i] = min(@tree[2*i], @tree[2*i+1])\n\tend\n\nend\n\nclass Bitree\n\n\tdef initialize(array)\n\t\t@data=array.clone\n\t\t@tree= [0]*(array.size+1)\n\t\tconstruct()\n\tend\n\n\tattr_reader :data, :tree\n\tdef construct()\n\t\tsum = [0]*(@data.size+1)\n\t\t(1..sum.size-1).each do |ind|\n\t\t\tsum[ind] = @data[ind-1]+sum[ind-1]\n\t\tend\n\t\t@tree[0] = 0\n\t\t(1..@tree.size-1).each do |ind|\n\t\t\ti = ind-(ind & -ind)\n\t\t\t@tree[ind] = sum[ind]-sum[i]\n\t\tend\n\tend\n\n\tdef query(i)\n\t\ti+=1\n\t\ts=0\n\t\twhile i>=1\n\t\t\ts+=@tree[i]\n\t\t\ti-= (i&-i)\n\t\tend\n\t\ts\n\tend\n\n\tdef add(i,a)\n\t\t@data[i]+=a\n\t\ti+=1\n\t\twhile i<@tree.size\n\t\t\t@tree[i]+=a\n\t\t\ti+=(i&-i)\n\t\tend\n\tend\n\n\tdef [](i)\n\t\t@data[i]\n\tend\nend\n=end\n=begin\nclass Graph\n\n\tdef initialize(g)\n\n\t\tputs 'expected a Array type input' if g.class != Array\n\t\t@graph = g\n\t\tsize = g.size+1\n\t\t@visited = [0]*size\n\t\t@time = [0] *size\n\t\t@father = [-1] *size\n\t\t@lev = [-1] * size\n\n\tend\n\n\tdef dfs(); _dfs(-1, [0],0, 1); self;end\n\n\tdef _dfs(father, time, lev, id)\n\n\t\t@time[id]=time[0]\n\t\t@father[id]=father\n\t\t@visited[id] = 1\n\t\t@lev[id] = lev\n\n\t\t@graph[id].each do |i|\n\t\t\tif @visited[i]!=1\n\t\t\t\ttime[0]+=1\n\t\t\t\t_dfs(id, time, lev+1 ,i)\n\t\t\tend\n\t\tend\n\tend\n\n\tdef inspect\n\t\tputs \"time: #{@time.inspect}\"\n\t\tputs \"father: #{@father.inspect}\"\n\t\tputs \"lev: #{@lev.inspect}\"\n\tend\nend\n\nn = gets.to_i\ng = [0]*(n+1)\n\n(1..n).each do |i|\n\ta = gets.split.map(&:to_i)\n\tg[a[0]] = a[1..(a.size-1)]\nend\n\ng = Graph.new(g)\n\ng.dfs.inspect\n\n=end\n\n=begin\n\nn = gets.to_i\nm = gets\nstanding = 0\n\nm.each_char do |c|\n\tif c == 'X'\n\t\tstanding += 1\n\tend\nend\n\nif standing == m.size/2\n\tputs '0'\n\tputs m\nelse\n\n\tif standing > m.size/2\n\t\td = standing-m.size/2\n\t\t\n\t\t(0..m.size-1).each do |i|\n\t\t\tif m[i] == 'X'\n\t\t\t\tm[i] = 'x'\n\t\t\t\td-=1\n\t\t\t\tbreak if d==0\n\t\t\tend\n\t\tend\n\t\tputs '1'\n\t\tputs m\n\telse\n\t\td = m.size/2-standing\n\t\t(0..m.size-1).each do |i|\n\t\t\tif m[i] == 'x'\n\t\t\t\tm[i] = 'X'\n\t\t\t\td-=1\n\t\t\t\tbreak if d == 0\n\t\t\tend\n\t\tend\n\t\tputs '1'\n\t\tputs m\n\tend\nend\n\n=end\n\nncity, p = gets.split.map(&:to_i)\n\narray = []\n(1..ncity).each do |i|\n\ta = gets.split.map(&:to_i)\n\n\tarray.push(a)\nend\n\narray.sort! do |a,b|\n\n\t_a = a[0]*a[0]+a[1]*a[1]\n\t_b = b[0]*b[0]+b[1]*b[1]\n\n\tif _a >_b\n\t\t1\n\telse\n\t\t-1\n\tend\nend\n\narray.each do |a|\n\n\tp+=a[2]\n\tif p>=1000000\n\t\t_a = a[0]*a[0]+a[1]*a[1]\n\t\tputs \"%.7f\" % [Math.sqrt(_a)]\n\t\texit 0\n\tend\nend\n\nputs -1\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "n,s = gets.split.map(&:to_i)\ncities = (1..n).map { |_|\n gets.split.map(&:to_i)\n}\n\nok = false\nneed = 1000000 - s\nmin = 0\nmax = 1000000000\nwhile max - min > 1\n med = (max + min) / 2\n pop = cities.map { |c|\n if c[0] ** 2 + c[1] ** 2 <= med\n c[2]\n else\n 0\n end\n }.inject(&:+)\n if need <= pop\n ok = true\n max = med\n else\n min = med\n end\nend\n\nif ok\n puts max ** 0.5\nelse\n puts -1\nend\n\n\n\n\n"}], "negative_code": [], "src_uid": "bcc758394d012519f0865479b3c6770c"} {"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each_slice(2) do |inp|\r\n nums = inp[1].split(' ').map(&:to_i)\r\n\r\n max = nums.max\r\n c = 0\r\n nums.each_with_index do |num, i|\r\n c = [c, max - num].max\r\n end\r\n\r\n puts c\r\nend", "positive_code": [{"source_code": "n = gets.to_i\r\nmax = []\r\nmin = []\r\nn.times do |i|\r\n a = gets.to_i\r\n a1 = gets.split.map(&:to_i)\r\n max << a1.max\r\n min << a1.min\r\nend\r\n\r\nn.times do |i|\r\n puts max[i] - min[i]\r\nend"}, {"source_code": "t = gets.to_i\ninputs = []\n(0...t).each do\n n = gets.to_i\n arr = gets.chomp\n arr = arr.split(\" \").map(&:to_i)\n inputs.push([arr, n])\nend\n\ninputs.each do |input|\n max = input[0].max\n min = input[0].min\n puts max-min\nend"}, {"source_code": "gets.to_i.times do\n gets\n xs = gets.split.map(&:to_i)\n p xs.max - xs.min\nend\n"}, {"source_code": "t = gets.to_i\nwhile t > 0\n n = gets.to_i\n arr = gets.chomp.split.map(&:to_i).sort\n puts arr[-1] - arr[0]\n t-=1\nend\n"}, {"source_code": "n = gets.chomp.to_i\r\nn.times do |i|\r\nl = gets.chomp.to_i\r\nst = gets.chomp.split\r\nmx = 0\r\nmn = 1000000001\r\nl.times do |element|\r\n el = st[element].to_i\r\n\tif el mx\r\n\t mx = el\r\n\tend\r\nend\r\nans = mx - mn\r\nputs ans\r\nend"}, {"source_code": "t = readline.strip.to_i\n\nt.times do\n readline\n numbers = readline.strip.split(/\\s+/).map(&:to_i)\n\n max = numbers.max\n min = numbers.min\n\n puts max - min\nend\n"}], "negative_code": [{"source_code": "n = gets.to_i\r\na = gets.to_i\r\na1 = gets.split.map(&:to_i)\r\nb = gets.to_i\r\nb1 = gets.split.map(&:to_i)\r\nc = gets.to_i\r\nc1 = gets.split.map(&:to_i)\r\n\r\nputs a1.max - a1.min\r\nputs b1.max - b1.min\r\nputs c1.max - c1.min"}], "src_uid": "cf3cfcae029a6997ee62701eda959a60"} {"source_code": "def findf(x, fa)\n if fa[x] != 0\n findf(fa[x], fa)\n else\n x\n end\nend\nn, m = gets.split.collect{|i| i.to_i}\nfa = Array.new(n+1,0)\ncnt = Array.new(n+1,1)\nm.times do\n x, y = gets.split.collect{|i| i.to_i}\n xx = findf(x, fa)\n yy = findf(y, fa)\n if xx != yy\n fa[yy] = xx\n cnt[xx] += cnt[yy]\n end\nend\nans = 0\n(1..n).each do |i|\n ans += cnt[i]-1 if fa[i]==0\nend\nputs 2**ans\n", "positive_code": [{"source_code": "n, m = gets.split(' ').map(&:to_i)\nar=(0...n).to_a\ndef rt(rr,v)\n if ( rr[v]==v )\n elsif ( rr[v]!=rt(rr,rr[v]) )\n rr[v] = rt(rr,rr[v])\n end\n rr[v]\nend\n(1..m).each do |_|\n x, y = gets.split(' ').map(&:to_i)\n rx = rt(ar,ar[x-1])\n ry = rt(ar,ar[y-1])\n if rx < ry\n ar[ry]=rx\n elsif rx > ry\n ar[rx]=ry\n end\nend\n(0...n).each do |x|\n rt(ar,x)\nend\np 2**(n-(ar.uniq.count))"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=(0..n).to_a\nm.times do\n a,b=gets.split.map(&:to_i)\n if c[a]!=c[b]\n x=c[b]\n (n+1).times do |i|\n c[i] = c[a] if c[i] == x\n end\n end\nend\np 1< 0\nend\n\np sum\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=(0..n).to_a\nm.times do\n a,b=gets.split.map(&:to_i)\n if c[a]!=c[b]\n x=c[b]\n (n+1).times do |i|\n c[i] = c[a] if c[i] == x\n end\n end\nend\np 1< 0\n gr[q[0]].each do |a|\n if visited[a] == -1\n visited[a] = 1\n q.push(a) \n end\n end\n q.shift\n end\n\n\n end\nend\n\n\nputs 2**visited[1..-1].inject{|x, y| x+y}\n\n\n\n\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=(0..n).to_a\nm.times do\n a,b=gets.split.map(&:to_i)\n if c[a]!=c[b]\n x=c[b]\n (n+1).times do |i|\n c[i] = c[a] if c[i] == x\n end\n end\nend\np 1< n + k ? 0 : m > k ? 1 - 0.upto(k).map{|i| (m - i) / (n + i + 1.0)}.inject(&:*) : 1\n\n", "positive_code": [{"source_code": "n, m, k = gets.split.map(&:to_i)\np m > n + k ? 0 : m > k ? 1 - 0.upto(k).map{|i| (m - i) / (n + i + 1.0)}.inject(&:*) : 1\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\np m > n + k ? 0 : m > k ? 1 - 0.upto(k).map{|i| (m - i) / (n + i + 1.0)}.inject(&:*) : 1\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\np m > n + k ? 0 : m > k ? 1 - 0.upto(k).map{|i| (m - i) / (n + i + 1.0)}.inject(&:*) : 1\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\np m > n + k ? 0 : m > k ? 1 - 0.upto(k).map{|i| (m - i) / (n + i + 1.0)}.inject(&:*) : 1\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\np m > n + k ? 0 : m > k ? 1 - 0.upto(k).map{|i| (m - i) / (n + i + 1.0)}.inject(&:*) : 1"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\np m > n + k ? 0 : m > k ? 1 - 0.upto(k).map{|i| (m - i) / (n + i + 1.0)}.inject(&:*) : 1\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\np m > n + k ? 0 : m > k ? 1 - 0.upto(k).map{|i| (m - i) / (n + i + 1.0)}.inject(&:*) : 1"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\np m > n + k ? 0 : m > k ? 1 - 0.upto(k).map{|i| (m - i) / (n + i + 1.0)}.inject(&:*) : 1\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\np m > n + k ? 0 : m > k ? 1 - 0.upto(k).map{|i| (m - i) / (n + i + 1.0)}.inject(&:*) : 1\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\np m > n + k ? 0 : m > k ? 1 - 0.upto(k).map{|i| (m - i) / (n + i + 1.0)}.inject(&:*) : 1\n\n"}], "negative_code": [], "src_uid": "5a2c9caec9c20a3caed1982ee8ed8f9c"} {"source_code": "n=gets.to_i\n\na=[]\n(n-1).times {\na.push gets(' ').to_i\n}\na.push gets.to_i\n\nmi=a.min\nma=a.max\n\nfor i in 0..a.size-1\nif a[i]==ma\nma_i=i\nbreak\nend\nend\n\ni=a.size-1\nwhile i>=0\nif a[i]==mi\nmi_i=i\nbreak\nend\n\ni-=1\nend\n\nret=ma_i+n-mi_i-1\nif ma_i>mi_i\nret-=1\nend\n\np ret", "positive_code": [{"source_code": "#!/usr/bin/ruby\ndef read_int; gets.chomp.to_i; end\ndef read_ints; gets.chomp.split.map(&:to_i); end\ndef read_chars; gets.chomp.split(''); end\n\nread_int\narr = read_ints\n\nmin_index = arr.rindex(arr.min)\nmax_index = arr.index(arr.max)\nn = max_index + arr.size - 1 - min_index\nn -= 1 if min_index < max_index\n\nputs n"}, {"source_code": "gets\narr = gets.split.map &:to_i\nmax_ind = arr.index(arr.max)\nmin_ind = (arr.reverse.index(arr.min) - arr.size + 1).abs\nif max_ind > min_ind\n puts max_ind + arr.size - min_ind - 2 \nelse\n puts max_ind + arr.size - min_ind - 1\nend\n"}, {"source_code": "s=gets()\nn=s.to_i\ns=gets()\ns=s.chop()\nat=0\n\n\na=Array.new(n)\nfor i in (0..n-1) do\n\tcur=0\n\twhile (ata[max])\nmax=i\nend\nif(a[n-1-i]z ?z:z-1\n"}, {"source_code": "n = gets.chomp.to_i\narr = Array.new(n)\narr = gets.split.map &:to_i\nbig = [0,0]\nsmall = [1000,0]\nn.times do |i|\n if arr[i] > big[0]\n big[0] = arr[i]\n big[1] = i\n end\n\n if arr[i] <= small[0]\n small[0] = arr[i]\n small[1] = i\n end\n\nend\n\nflag = 0\nif big[1] > small[1]\n flag = 1\nend\n\nputs (big[1] - 0) + ((n-1) - small[1]) - flag\n"}, {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\n\nmin_index = as.rindex(as.min)\nmax_index = as.index(as.max)\n\nputs (n - min_index - 1) + max_index - (min_index < max_index ? 1 : 0) "}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1\n"}, {"source_code": "gets.chomp.to_i\nline = gets.chomp.split(/ /).map(&:to_i)\nlen = line.length - 1\nmin_height = line.min\nmax_height = line.max\nmin_pos = line.rindex min_height\nmax_pos = line.index max_height\ndelta = 0\ndelta = 1 if min_pos < max_pos\nputs (max_pos - 0) + (len - min_pos) - delta\n"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nmin1=x[0]\nmax1=x[0]\nminP=0\nmaxP=0\nn.times{|i|\n\tif x[i]<=min1 then\n\t\tmin1=x[i]\n\t\tminP=i\n\tend\n}\nn.times{|i|\n\tif max1 imn\n p imx + (n-imn-1) - 1\nelse\n p imx + (n-imn-1)\nend\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\n\nmax_ind = arr.find_index(arr.max)\nmin_ind = arr.rindex(arr.min)\n# p max_ind, min_ind\nif max_ind > min_ind\n puts (max_ind) + ((n-1) - min_ind) - 1 \nelse\n puts (max_ind) + ((n-1) - min_ind)\nend"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\nrequire 'prime'\n#require 'mathn'\nrequire 'matrix'\nrequire 'set'\ninclude Math\n#=================================\n\nn=gets.to_i\ndata=gets.split.map(&:to_i)\n\nmini=data.min\nmaxy=data.max\n\nmini_pos = data.rindex(mini)\nans=0\nfor i in mini_pos...data.size-1\n\ttmp=data[i]\n\tdata[i]=data[i+1]\n\tdata[i+1]=tmp\n\tans+=1\nend\n\nmaxy_pos=data.index(maxy)\nfor i in 1..maxy_pos\n\ttmp=data[i]\n\tdata[i]=data[i+1]\n\tdata[i+1]=tmp\n\tans+=1\nend\n\nputs ans\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\nrequire 'prime'\n#require 'mathn'\nrequire 'matrix'\nrequire 'set'\ninclude Math\n#=================================\n\nn=gets.to_i\ndata=gets.split.map(&:to_i)\n\nmini=data.min\nmaxy=data.max\n\nmini_pos = data.rindex(mini)\nans=0\nfor i in mini_pos...data.size-1\n\ttmp=data[i]\n\tdata[i]=data[i+1]\n\tdata[i+1]=tmp\n\tans+=1\nend\n\nmaxy_pos=data.index(maxy)\nfor i in 1..maxy_pos\n\ttmp=data[i]\n\tdata[i]=data[i+1]\n\tdata[i+1]=tmp\n\tans+=1\nend\n\nputs ans"}, {"source_code": "numSol = gets.to_i\na = gets.split.map {|x| x.to_i}\n\nleftMax = 0\nrightMin = numSol-1\n\nfor x in 0...numSol\n\ty = numSol-1-x\n\tleftMax = x if a[x]>a[leftMax]\n\trightMin = y if a[y]rightMin\n\nputs ans"}, {"source_code": "n=gets.to_i\na=gets.split\na.collect! {|i| i.to_i}\n\nfor i in 1..n\n\tif a[-i] == a.max then l=n-i end\n\tif a[i-1] == a.min then r=n-i end\nend\n\nputs (if l+r>=n then l+r-1 else l+r end)\n"}, {"source_code": "n=gets.to_i\na=gets.split.collect! {|i| i.to_i}\nfor i in 1..n\n\tif a[-i] == a.max then l=n-i end\n\tif a[i-1] == a.min then r=n-i end\nend\nputs (if l+r>=n then l+r-1 else l+r end)\n"}, {"source_code": "i = gets.to_i\n\narray = gets.chomp.split.map(&:to_i)\n\nmin_index = array.rindex(array.min)\nmax_index = array.index(array.max)\n\nlength = array.length - 1\n\nif max_index < min_index\n swaps = (length-min_index) + max_index\nelse\n swaps = (length-min_index) + max_index - 1\nend\n\nputs swaps"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nans = 0\nmaxv = a.max\nminv = a.min\n\ni = a.index(maxv)\nans += i\na.delete_at(i)\na.unshift(maxv)\n\ni = a.rindex(minv)\nans += a.size - i - 1\n\nputs ans"}, {"source_code": "gets\ns = gets.split(' ').map(&:to_i)\nsorted = s.sort\nmin = sorted.first\nmax = sorted.last\nmax_index = s.find_index(max)\nmin_index = s.reverse.find_index(min)\nresult = s.find_index(max) + s.reverse.find_index(min)\nresult -= 1 if max_index > s.size - min_index - 1\nputs result\n"}, {"source_code": "n = Integer(gets.chomp)\nh = gets.chomp.split\nheight = Array.new\nfor i in 0...n\n height[i] = Integer(h[i])\nend\n\nmax = 0\nmin = 101\nfor i in 0...n\n if height[i] > max\n max = height[i]\n end\nend\nfor i in 0...n\n if height[i] < min\n min = height[i]\n end\nend\n\nmax_index = Array.new\nmin_index = Array.new\nfor i in 0...n\n if height[i] == max\n max_index.push(i)\n elsif height[i] == min\n min_index.push(i)\n end\nend\n\nx = min_index.length\nif max == min \n puts 0\nelsif max_index[0] > min_index[x-1]\n puts max_index[0] + n - 2 - min_index[x-1]\nelse\n puts max_index[0] + n - 1 - min_index[x-1]\nend"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\nmin, max = a.minmax\n\nwmax = a.index(max)\nwmin = a.rindex(min)\n\nans = wmax + a.size - wmin - 1\nans -= 1 if wmax > wmin\n\nputs ans"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\narr.reverse!\n\nmin,min_index = arr.each_with_index.min\n\narr.unshift(arr.delete_at(min_index))\nsecs = min_index\n\nmax,max_index = arr.each_with_index.max\nsecs += (n - max_index - 1)\nputs secs"}, {"source_code": "number_of_soldiers = gets.to_i\nsoldiers = gets.split.map &:to_i\n\nshortest = number_of_soldiers - 1 - soldiers.reverse.index(soldiers.min)\ntallest = soldiers.index(soldiers.max)\nputs tallest + number_of_soldiers - shortest - (tallest > shortest ? 1 : 0) - 1\n"}, {"source_code": "ar = []\nn = gets.to_i\nar = gets.split.map &:to_i\n#puts ar.index(ar.max)\nx = ar.index(ar.max)\ny = ar.rindex(ar.min)\na = x\nb = n-y-1\nputs y < x ? a + b-1 : a + b\n"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1"}, {"source_code": "gets\nl = gets.split.map(&:to_i)\nm = l.index(l.max)\nl.delete_at(m)\nputs m + l.reverse.index(l.min)"}, {"source_code": "n=gets.to_i; d=gets.split.map(&:to_i); sum=d.index(d.max); d[d.index(d.max)]+=1;\np d.index(d.max) + (d.select{|x| x!=d.max}.reverse.push(d.max).index(d.min))"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nmii = a.rindex(a.min)\nmxi = a.index(a.max)\nans = mxi + (n - 1 - mii)\nans -= 1 if mxi > mii\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nmi = a.min\nmx = a.max\nmii = a.rindex(mi)\nmxi = a.index(mx)\nans = mxi + (n - 1 - mii)\nans -= 1 if mxi > mii\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nmi = a.min\nmx = a.max\nmii = 0\nmxi = 0\nfor i in 0...n\n if a[i] == mi\n mii = i\n mi = a[i]\n end\nend\nfor i in 0...n\n if a[i] == mx\n mxi = i\n mx = a[i]\n break;\n end\nend\nans = mxi + (n - 1 - mii)\nans -= 1 if mxi > mii\nputs ans\n"}, {"source_code": "def swap (i, d)\n tmp = $a[i]\n $a[i] = $a[i + d]\n $a[i + d] = tmp\n i + d\nend\nn = gets.to_i\n$a = gets.split.map(&:to_i)\nmi = $a.min\nmx = $a.max\nans = 0\nmii = 0\nmxi = 0\nn.times do |i|\n if $a[i] == mx\n mxi = i\n break\n end\nend\nwhile mxi != 0\n mxi = swap(mxi, -1)\n ans += 1\nend\nn.times do |i|\n mii = i if $a[i] == mi\nend\nwhile mii != n - 1\n mii = swap(mii, 1)\n ans += 1\nend\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\n\narray = gets.chomp.split(\" \")\n\nmaxi = 0\nmini = 105\n\nid = 0\n\nfor i in 0...n\n\ta = array[i].to_i\n\n\tif a<=mini\n\t\tmini = a\n\t\tid = i;\n\tend\n\n\ti += 1\nend\n\ncont = 0\n\nwhile id=0 do\n\ta = array[j].to_i\n\n\tif a>=maxi\n\t\tmaxi = a\n\t\tid = j;\n\tend\n\n\tj -= 1\nend\n\nwhile id>=1 do\n\n\ta = array[id]\n\tarray[id] = array[id-1]\n\tarray[id - 1] = a\n\n\tid -= 1\n\tcont += 1\n\nend\n\n\nputs cont\n"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1"}, {"source_code": "length = gets.chomp.to_i\nheights = gets.chomp.split()\nmin, max = heights.minmax_by {|h| h.to_i}\nminindex = heights.rindex(min)\nmaxindex = heights.index(max)\nif maxindex < minindex\n print maxindex + heights.length - minindex - 1\nelse\n print maxindex - minindex + minindex + heights.length - minindex - 1 - 1\nend\n"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1\n"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\n\nimax = a.index(a.max)\nimin = a.size - a.rindex(a.min) -1\n\nputs imax + imin - (imax > a.size - imin - 1 ? 1 : 0)\n"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1"}, {"source_code": "max = [0, 0]\nmin = [101, 0]\nn = Integer(gets.chomp)\ngets.chomp.split.each_with_index { |s, i|\n h = s.to_i\n if h > max[0]\n max = [h, i]\n end\n if h <= min[0]\n min = [h, i]\n end\n}\nputs max[1] + (n - min[1] - 1) - (max[1] > min[1] ? 1 : 0)"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na.delete_at(ans = a.find_index(a.max))\na.reverse!\nans += a.find_index(a.min)\np ans\n"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1\n"}, {"source_code": "STDIN.gets\ni = STDIN.gets.split(' ').map(&:to_i)\n\nmax, min = i.max, i.min\n\nmax_i = -1; min_i = 100\n\ni.length.times do |k|\n\tmax_i = k if max_i == -1 and i[k] == max\n\tmin_i = k if i[k] == min\nend\n\nc = max_i - 1 + i.length - min_i\nc -= 1 if max_i > min_i\n\nSTDOUT.puts c"}, {"source_code": "#!ruby\n\nn = gets.to_i\n\ndata = gets.split.map{|e|e.to_i}\n\nmax_num = data.max\nmin_num = data.min\nmax_index = data.index(max_num)\nmin_index = data.rindex(min_num)\n\nputs max_index + data.length - min_index -1+ (max_index>min_index ? -1 : 0 )\n"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1\n"}, {"source_code": "n = gets.to_i\nar = gets.split(' ').map(&:to_i)\nmin, max = ar.minmax\nmaxid, minid = ar.index(max), ar.rindex(min)\nr = maxid + n-1 - minid\nr -= 1 if maxid > minid\nputs r\n\n"}, {"source_code": "\nn=gets.chomp.to_i\ni=0\n#for i in (0...n)\nb=gets.chomp.split(\" \").map &:to_i\n#end\nt1= b.index(b.max)\nt2=n-1-b.rindex(b.min)\n#puts b.max\n#puts t1\n#puts b.min\n#puts t2\nif n>t1+t2\nputs t1+t2\nelse \nputs t1+t2-1\nend\n\n\n#end\n"}, {"source_code": "\nn = gets.chomp.to_i\nna = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nnsa = na.sort\nminidx = na.rindex(nsa.first)\nmaxidx = na.index(nsa.last)\nmv = na.length-(minidx+1) + maxidx\nmv -= 1 if minidx < maxidx\nputs mv\n\n"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n# Aurhor: seniorihor (12.03.2012)\n\nclass General\n def initialize(quantity, numbers)\n @quantity = quantity\n @numbers = numbers\n @seconds = 0\n end\n def calculation_seconds\n if @numbers.rindex(@numbers.min) > @numbers.index(@numbers.max)\n @seconds = @numbers.index(@numbers.max) + @numbers.length - 1 - @numbers.rindex(@numbers.min)\n else\n @seconds = @numbers.index(@numbers.max) + @numbers.length - 2 - @numbers.rindex(@numbers.min)\n end\n end\nend\nquantity = gets.chomp.to_i\nnumbers = gets.chomp.split(\" \").map! do |i|\n i = i.to_i\nend\n\ng = General.new(quantity, numbers)\np g.calculation_seconds\n"}, {"source_code": "n=gets.to_i;a=gets.split.map(&:to_i);\nmin=0;max=0;\n0.upto(n-1){|i| min=i if a.min==a[i] }\n(n-1).downto(0){|i| max=i if a.max==a[i] }\np max+(n-1-min)-(( min=0)\n if(soldatu[posMensh]>soldatu[i])\n posMensh=i\n end \n i-=1\nend\n\nsec=0\nsec+=posBilsh\nsec+=(kilkist-1-posMensh)\nsec-=1 if(posBilsh>posMensh)\n \nprint sec "}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n# Aurhor: seniorihor and vertoldo (12.03.2012)\n\nclass General\n def initialize(quantity, numbers)\n @quantity = quantity\n @numbers = numbers\n @posMensh=0\n @posBilsh=0\n @sec=0\n end\n \n def calculation_seconds\n\n @numbers.size().times do |j|\n if(@numbers[@posBilsh]<@numbers[j])\n @posBilsh=j\n end \n end\n \n @posMensh=@quantity-1\n i=@posMensh\n \n while(i>=0)\n if(@numbers[@posMensh]>@numbers[i])\n @posMensh=i\n end \n i-=1\n end\n\n @sec+=@posBilsh\n @sec+=(@quantity-1-@posMensh)\n @sec-=1 if(@posBilsh>@posMensh)\n\n return @sec\n end\nend\n\n\nquantity = gets.chomp.to_i\nnumbers = gets.chomp.split(\" \").map! {|el| el=el.to_i}\ng = General.new(quantity, numbers)\nprint g.calculation_seconds"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nmin, max = 0, 0\na.each_index do |i|\n min = i if a[min] >= a[i]\n max = i if a[max] < a[i]\nend\ncnt = max + (a.size - 1 - min)\ncnt -= 1 if max > min\nputs cnt"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1\n"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1"}, {"source_code": "def order(n,a)\n minmax = a.minmax\n min = minmax.shift\n max = minmax.shift\n\n #As the smaller soldier has to be at the end of the line we need to look for the closest one to that pos\n min_pos = a.rindex(min)\n # The highest soldier has to be first that's why we start looking from the beginig of the line\n max_pos = a.index(max)\n\n tot_sec = 0\n #Checking if the soldiers have to be swapped between them\n if min_pos < max_pos\n # Has to be -2 because of the array index and one less to the end of line,\n # that's because the soldiers are swapped between them and we consider that time on the max_pos\n tot_sec = max_pos + ((n-2) - min_pos)\n else\n tot_sec = max_pos + ((n-1) - min_pos)\n end\n\n tot_sec\nend\n\nn = gets.to_i\na = gets.split(/\\s/).map(&:to_i)\nputs order(n,a)"}, {"source_code": "n = $stdin.gets.to_i\nmilita = $stdin.gets.split.map { |x| x.to_i }\n\n\nmax = 0\nmaxidx = -1\n\nn.times do |i|\n if max < milita[i]\n max = milita[i]\n maxidx = i\n end\nend\n\nresult = maxidx\n\nmaxidx.downto(1) do |i|\n t = milita[i]\n milita[i] = milita[i-1]\n milita[i-1] = t\nend\n\nmin = 10000000\nminidx = -1\n\nn.times do |k|\n i = n - k - 1\n\n if min > milita[i]\n min = milita[i]\n minidx = i\n end\nend\n\nresult += n - 1 - minidx\n\np result\n"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1"}, {"source_code": "gets\ns=gets.split.map &:to_i\nn=s.size\nz=n-1+s.index(s.max)-s.rindex(s.min)\np n>z ?z:z-1"}, {"source_code": "n=gets.chomp.to_i\na=gets.chomp.split.map(&:to_i)\nmn=a.min\nmx=a.max\nmn_pos = a.rindex(mn)\nans=0\nfor i in mn_pos...a.size-1\n\ta[i],a[i+1]=a[i+1],a[i]\n\tans+=1\nend\nmx_pos=a.index(mx)\nfor i in 1..mx_pos\n\ta[i],a[i+1]=a[i+1],a[i]\n\tans+=1\nend\nputs ans"}, {"source_code": "gets\na = gets.strip.split.map(&:to_i).to_a\np a.size - a.rindex(a.min) - 1 + a.index(a.max) - (a.index(a.max) > a.rindex(a.min) ? 1 : 0)"}, {"source_code": "n = gets.to_i\n\na = gets.chomp.split(' ').map &:to_i\n\nl = a.index(a.max)\nr = a.rindex(a.min)\nif l > r\n puts a.size-2 +l - r\nelse\n puts a.size-1 + l -r\nend"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nmax_index=a.index(a.max)\nmin_index=a.rindex(a.min)\np max_index0\n a[i-1], a[i] = a[i], a[i-1]\n i-=1\n k+=1\nend\n\nmini = a.count - a.reverse.find_index(min) - 1\ni = mini\nwhile it1+t2\nputs t1+t2\nelse \nputs t1+t2-1\nend\n\n\n#end\n"}, {"source_code": "\nn=gets.chomp.to_i\ni=0\n#for i in (0...n)\nb=gets.chomp.split(\" \").map &:to_i\n#end\nt1= b.index(b.max)\nt2=n-1-b.index(b.min)\n#puts b.max\n#puts t1\n#puts b.min\n#puts t2\nif n>t1+t2\nputs t1+t2\nelse \nputs t1+t2-1\nend\n\n\n#end\n"}, {"source_code": "\nn=gets.chomp.to_i\ni=0\n#for i in (0...n)\nb=gets.chomp.split(\" \")\n#end\nt1= b.index(b.max)\nt2=n-b.rindex(b.min)-1\nif n>t1+t2\nputs t1+t2\nelse \nputs t1+t2-1\nend\n\n\n\n"}, {"source_code": "\nkilkist = gets.chomp.to_i\n\nsoldatu=gets.chomp.split(\" \").map! {|el| el=el.to_i}\n\nposMensh=soldatu.rindex(soldatu.min)\n\nposBilsh=soldatu.rindex(soldatu.max)\n\nsec=0\n\nif(posMensh!=posBilsh)\n\n sec+=posBilsh\n \n sec+=(kilkist-1-posMensh)\n \n sec-=1 if(posBilsh>posMensh)\n\nend\n\nprint sec "}, {"source_code": "n = $stdin.readline.to_i\na = $stdin.readline.split.map(&:to_i)\n\nmax = a.max\nmin = a.min\n\nmaxi = a.find_index(max)\nmini = a.reverse.find_index(min)\n\nif maxi!=mini\n k = maxi+mini-1\nelse\n k = maxi+mini\nend\n\nputs k\n"}, {"source_code": "n = $stdin.readline.to_i\na = $stdin.readline.split.map(&:to_i)\n\nmax = a.max\nmin = a.min\n\nif a.count == 2\n if a.first == max && a.last == min\n puts 0\n else\n puts 1\n end\nelse\n \n maxi = a.find_index(max)\n mini = a.reverse.find_index(min)\n\n if maxi!=mini\n k = maxi+mini-1\n else\n k = maxi+mini\n end\n\n puts k\nend"}, {"source_code": "gets\nh = gets.split.map &:to_i\nnumb = h.index(h.max) + h.size - (h.reverse.index(h.min) - h.size).abs \nnumb -= 1 if h.index(h.max) > h.index(h.min)\nputs numb\n"}, {"source_code": "gets\nh = gets.split.map &:to_i\nnumb = h.index(h.max) + h.size - (h.reverse.index(h.min) - h.size).abs \nnumb -= 1 if h.index(h.max) > (h.reverse.index(h.min) - h.size).abs\nputs numb\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\n\nmax_ind = arr.rindex(arr.max)\nmin_ind = arr.rindex(arr.min)\n# p max_ind, min_ind\nif max_ind > min_ind\n puts (max_ind) + ((n-1) - min_ind) - 1 \nelse\n puts (max_ind) + ((n-1) - min_ind)\nend"}, {"source_code": "ar = []\nn = gets.to_i\nar = gets.split.map &:to_i\n#puts ar.index(ar.max)\nx = ar.index(ar.max)\ny = n-ar.rindex(ar.min)-1\nputs y < x ? x+y-1 : x+y\n"}, {"source_code": "gets\nl = gets.split.map(&:to_i)\nm = l.index(l.max)\nl.delete(l.max)\nputs m + l.reverse.index(l.min)"}, {"source_code": "gets\nl = gets.split.map(&:to_i)\nm = l.index(l.max)\nl.delete(m)\nputs m + l.reverse.index(l.min)"}, {"source_code": "gets\nl = gets.split.map(&:to_i)\nm = l.each_with_index.max\nl.delete(m[0])\nputs m[1] + l.reverse.each_with_index.min[1]"}, {"source_code": "gets\nl = gets.split.map(&:to_i)\nm = l.index(l.max)\nl.delete(m)\nputs m + l.reverse.each_with_index.min[1]"}, {"source_code": "n=gets.to_i; d=gets.split.map(&:to_i); sum=d.index(d.max);\np d.index(d.max) + (d.reverse.select{|x| x!=d.max}.push(d.max).index(d.min))"}, {"source_code": "n=gets.to_i\n\na=[]\n(n-1).times {\na.push gets(' ').to_i\n}\na.push gets.to_i\n\nmi=a.min\nma=a.max\n\nfor i in 0..a.size-1\nif a[i]==ma\nma_i=i\nbreak\nend\nend\n\ni=a.size-1\nwhile i>=0\nif a[i]==mi\nmi_i=i\nbreak\nend\n\ni-=1\nend\n\nret=ma_i+n-mi_i\nif ma_i>mi_i\nret-=1\nend\n\np ret"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\n\nimax = a.index(a.max)\nimin = a.rindex(a.min)\n\nputs imax + (a.size - imin - 1) - (imax > a.index(a.min) ? 1 : 0)\n"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\n\nimax = a.index(a.max)\nimin = a.size - a.rindex(a.min) -1\n\nputs imax + imin - (imax > a.size - imin ? 1 : 0)\n"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\n\nimax = a.index(a.max)\nimin = a.size - a.rindex(a.min) -1\n\np imax, imin\n\nputs imax + imin - (imax > a.size - imin ? 1 : 0)\n"}, {"source_code": "STDIN.gets\ni = STDIN.gets.split(' ').map(&:to_i)\n\nmax, min = i.max, i.min\n\nif max == i.first and min = i.last\n STDOUT.puts 0\n exit\nend\n\nmax_i = 0; min_i = 101\n\ni.length.times do |k|\n max_i = k if max_i == 0 and i[k] == max\n min_i = k if i[k] == min\nend\n\nc = max_i - 1 + i.length - min_i\nc -= 1 if max_i > min_i\n\nSTDOUT.puts c"}, {"source_code": "STDIN.gets\ni = STDIN.gets.split(' ').map(&:to_i)\n\nmax, min = i.max, i.min\nmax_i = 0; min_i = 101\n\ni.length.times do |k|\n\tmax_i = k if max_i == 0 and i[k] == max\n\tmin_i = k if i[k] == min\nend\n\nc = max_i - 1 + i.length - min_i\nc -= 1 if max_i > min_i\n\nSTDOUT.puts c"}, {"source_code": "STDIN.gets\ni = STDIN.gets.split(' ').map(&:to_i)\n\nmax, min = i.max, i.min\n\nif max == i.first and min == i.last\n\tSTDOUT.puts 0\n\texit\nend\n\nmax_i = 0; min_i = 101\n\ni.length.times do |k|\n\tmax_i = k if max_i == 0 and i[k] == max\n\tmin_i = k if i[k] == min\nend\n\nc = max_i - 1 + i.length - min_i\nc -= 1 if max_i > min_i\n\nSTDOUT.puts c"}, {"source_code": "#!ruby\n\nn = gets.to_i\n\ndata = gets.split.map{|e|e.to_i}\n\nmax_num = data.max\nmin_num = data.min\nmax_index = data.index(max_num)\nmin_index = data.length - data.rindex(min_num) -1\n\nputs max_index + min_index + (max_index>min_index ? -1 : 0 )\n"}], "src_uid": "ef9ff63d225811868e786e800ce49c92"} {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1165/A\n\ninput = gets.split(' ').map(&:to_i)\nnum = gets.chomp\n\nn = input[0]\nx = input[1]\ny = input[2]\n\ncounter = 0\n\n(0..x-1).each do |i|\n if i == y\n counter += 1 if num[n-i-1] == '0'\n elsif num[n-i-1] == '1'\n counter += 1\n end\nend\n\nputs counter\n", "positive_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nnxy = gets.chomp.split(\" \").map(&:to_i)\nn = nxy[0]\nx = nxy[1]\ny = nxy[2]\n\ns = gets.chomp\n\nans=0\n(0..x-1).each do |i|\n#\tp i\n#\tp s[s.length-i-1]\n\tif(i==y)\n\t\tif(s[s.length-i-1]=='0')\n\t\t\tans+=1\n\t\tend\n\telse\n#\t\tp i\n\t\tif(s[s.length-i-1]=='1')\n\t\t\tans+=1\n\t\tend\n\tend\nend\n\nputs ans\n"}, {"source_code": "n, x, y = gets.split.map(&:to_i)\ns = gets.chomp.reverse\ngoal = '0' * x\ngoal[y] = '1'\nputs s[0, x].chars.zip(goal.chars).count { _1 != _2 }\n"}], "negative_code": [], "src_uid": "075988685fa3f9b20bd215037c504a4f"} {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nb=[*1..n*k]-a\nputs a.map{|_|(b.shift(n-1)<<_)*\" \"}", "positive_code": [{"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nb=[*1..n*k]-a\nputs a.map{|_|(b.shift(n-1)<<_)*\" \"}\n"}, {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nb=[*1..n*k]-a\nputs a.map{|_|(b.shift(n-1)<<_)*\" \"}\n"}, {"source_code": "a=gets.chomp.split(\" \")\n0.upto(1) {|i| a[i]=a[i].to_i }\nb=gets.chomp.split(\" \")\n0.upto(a[1]-1) {|i| b[i]=b[i].to_i }\nc=(1.. (a[0] * a[1])).to_a\n1.upto(a[1]) do |i|\nind=c.index(b[i-1])\nswp=c[i*a[0]-1]\nc[i*a[0]-1]=b[i-1]\nc[ind]=swp\nend\n\ni=0\n(a[1]).times do\na[0].times do\nprintf \"#{c[i]} \"\ni+=1\nend\nputs \"\"\nend\n\n\n\n"}, {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nb=[*1..n*k]-a\nputs a.map{|_|(b.shift(n-1)<<_)*\" \"}\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\n\no=1\n\nk.times{|i|\n print a[i].to_s+' '\n (n-1).times{\n o+=1 while a.include? o\n print o.to_s+' '\n o+=1\n }\n puts\n}\n"}, {"source_code": "n, k = gets.split.map &:to_i\na = gets.split.map &:to_i\nar = Array.new(n*k) { |i| 1 if a.include?(i) }\n\npointer = 1\na.each do |element|\n print \"%d \" % element\n counter = n-1\n while counter > 0 do\n if ar[pointer].nil?\n print \"%d \" % pointer\n counter -= 1\n ar[pointer] = 1\n end\n pointer += 1\n end\n print \"\\n\"\nend\n"}, {"source_code": "def read_next_line\n gets.chomp.split.map { |x| x.to_i }\nend\n\nn, k = read_next_line\na = read_next_line\ng = []\nfor i in 0...a.size\n g << [a[i]]\nend\nif n > 1\n i, j = 0, 1\n for x in 1..k * n\n unless a.include? x\n g[i] << x\n j += 1\n if j == n\n j = 1\n i += 1\n end\n end\n end\nend\ng.each { |z| puts z * ' ' }"}, {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nb=[*1..n*k]-a\nputs a.map{|_|(b.shift(n-1)<<_)*\" \"}\n"}, {"source_code": "t = gets.split.collect{|x| x.to_i}\nn,k = t[0], t[1]\n\na = gets.split.collect{|x| x.to_i}\nanswer = []\n\na.each do |c|\n\tprint c,' '\n\tm = 1\n\tfor i in 1..n*k\n\t\tif m == n\n\t\t\tbreak\n\t\tend\n\t\tif not a.include?(i) and not answer.include?(i)\n\t\t\tanswer << i\n\t\t\tm+=1\n\t\t\tprint i,' '\n\t\tend\n\tend\n\tputs\nend"}, {"source_code": "n,k,*a=gets(p).split.map(&:to_i)\nb=[*1..n*k]-a\nputs a.map{|_|(b.shift(n-1)<<_)*\" \"}\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nd = (1..n*k).to_a\nr = []\nk.times do |i|\n t = []\n t.push a[i]\n r.push t\n d -= [a[i]]\nend\nk.times do |i|\n (n-1).times do\n r[i].push d[0]\n d.shift\n end\nend\nr.each do |x|\n puts x*' '\nend"}, {"source_code": "nk = gets.split\nwishes = gets.split\nn = nk[0].to_i\nk = nk[1].to_i\na = Array.new(n*k){|i| i+= 1}\nres = []\ni = 0\nwhile i=60 and a<180 and 360%(180-a)==0\nputs \"YES\"\nelse\nputs \"NO\"\nend\nend\n"}, {"source_code": "require 'set'\ns = Set.new\na = Array.new\nn = gets.to_i.times do\n\ta << gets.to_i\nend\nfor i in 1..179 do\n\ts.add(i) if 360 % (180 - i) == 0\nend\na.each{|el| s.include?(el) ? (puts \"YES\") : (puts \"NO\")}\n\t\n\n\n\n\t\n\n\t\t\n\n\n\n\n\n"}, {"source_code": "n = gets.to_i\nn.times do\n a = gets.to_i\n puts(if 360 % (180 - a) == 0 then \"YES\" else \"NO\" end)\nend"}, {"source_code": "gets.to_i.times{\n\ta=gets.to_i\n\t#angles=[60, 90, 108, 120, 129, 135, 140, 144, 148, 150, 153, 155, 156, 158, 159, 160, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179]\n\tangles=[60, 90, 108, 120, 135, 140, 144, 150, 156, 160, 162, 165, 168, 170, 171, 172, 174, 175, 176, 177, 178, 179]\n\tangles.include?(a) ? (puts 'YES') : (puts 'NO')\n}\n"}, {"source_code": "gets.to_i.times do\n a=gets.to_i\n angles=[60, 90, 108, 120, 135, 140, 144, 150, 156, 160, 162, 165, 168, 170, 171, 172, 174, 175, 176, 177, 178, 179]\n angles.include?(a) ? (puts 'YES') : (puts 'NO')\nend"}, {"source_code": "num_tests = gets.to_i\nfor i in 0...num_tests\n\tangle = gets.to_i\n\tsides = 2.0/(1-(angle/180.0))\n\tif (sides - (sides+0.5).to_i).abs < 0.00000001\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\n"}, {"source_code": "gets.to_i.times{puts 360%(180-gets.to_i)==0 ?(\"YES\"):(\"NO\")}"}, {"source_code": "l = [0, 60, 90, 108, 120, 135, 140, 144, 150, 156, 160, 162, 165, 168, 170, 171, 172, 174, 175, 176, 177, 178, 179]\nn = gets.to_i\nn.times do\n\tif l.include?(gets.to_i)\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend"}, {"source_code": "n = gets.chomp.to_i\nres = []\n(1..n).each {|k|\n\ta = gets.chomp.to_i\n\ta /= 180.0\n\t\n\tq = 2.0/(1.0-a)\n\t\n\tif (q-q.round).abs < 0.000001\n\t\tres.push \"YES\"\n\telse\n\t\tres.push \"NO\"\n\tend\n}\n\nres.each { |k|\n puts k\n}"}, {"source_code": "x =(1..179).to_a.select{|x| (360%(180-x)==0)}\nn = gets.to_i\nd = n.times.map{gets.to_i}\nn.times{|y| (x.include?(d[y]))? (puts \"YES\") : (puts \"NO\")}\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\nt = STDIN.readline.to_i\nt.times do\n\tinterior_angle = STDIN.readline.to_i\n\tif 360%(180-interior_angle) == 0\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\n\n"}, {"source_code": "gets.to_i.times{x=gets.to_i; puts ((360%(180-x)==0)? \"YES\" : \"NO\");}"}, {"source_code": "n = gets.to_i\nn.times{\n\t\ta = gets.to_i\n\t\tx = 360.0 / ( 180.0 - a )\n\t\tif (x == x.floor) then\n\t\t\tputs \"YES\"\n\t\telse\n\t\t\tputs \"NO\"\n\t\tend\n}\t"}, {"source_code": "gets.to_i.times do\n x = gets.to_i\n puts 360 % (180 - x) == 0 ? \"YES\" : \"NO\"\nend\n"}, {"source_code": "t = gets.to_i\nans = []\nfor i in 0...t\n ans[i] = 360 % (180 - gets.to_i) == 0 ? \"YES\" : \"NO\"\nend\nputs ans\n"}, {"source_code": "t = gets.to_i\n\n1.upto(t) { puts 360.modulo(180 - gets.to_i).zero? ? 'YES' : 'NO' }\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nn.times do\n\tx = gets.to_i\n\tputs 360 % (180 - x) == 0 ? \"YES\" : \"NO\"\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n a = gets.chomp.to_i\n \n rem = 360 % (180 - a)\n \n puts (rem == 0 ? \"YES\" : \"NO\")\nend"}, {"source_code": "n = gets.to_i\n\nok = []\n\n180.times do |i|\n\tk = 360.0 / (180 - i)\n\tif k == k.to_i\n\t\tok << i\n\tend\nend\n\nn.times do |i|\n\ta = gets.to_i\n\t\n\tif ok.include?(a)\n\t\tputs 'YES'\n\telse \n\t\tputs 'NO'\n\tend\nend"}, {"source_code": "t = gets.chomp.to_i\n(1..t).each do |x|\n\ty = gets.chomp.to_i\n\tif y == 180 then puts \"NO\" \n\telse puts((360 % (180-y) == 0) ?\"YES\":\"NO\") end\nend"}, {"source_code": "arr = []\ngets.to_i.times do\n arr << gets.to_i\nend\narr.each { |x| puts 360 % (180 - x) == 0 ? \"YES\" : \"NO\" }\n"}, {"source_code": "n=gets.to_i\ns=(3..360).select{|e|\n\t(360%e==0)\n}\ns.map!{|e|\n\t180-360/e\n}\n\nn.times{\n\tm=gets.to_i\n\tif s.include?(m) then\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\n}"}, {"source_code": "n = gets.to_i\nn.times do |i|\n\tx = gets.to_f\n\tx = (-2 * 180) / (x - 180)\n\tputs x % 1 == 0 ? 'YES' : 'NO'\nend"}, {"source_code": "require 'set'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\n\nn.times do\n angle = gets.to_i\n n = 360.0 / (180.0 - angle)\n puts ((n.ceil == n.floor) ? :YES : :NO)\nend"}, {"source_code": "require 'set'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\n\ndegrees = Set.new\nindex = 3\nloop do\n angle = (index - 2) * 180.0 / index\n degrees << angle.to_i if angle.ceil == angle.floor\n index += 1\n \n break if index>2000\nend\n\nn.times do\n angle = gets.to_i\n puts ((degrees.include? angle) ? :YES : :NO)\nend"}, {"source_code": "n = gets.chomp.to_i\n\nn.times do\n x = gets.chomp.to_i\n puts 360 % (180 - x) == 0 ? 'YES' : \"NO\"\nend\n"}, {"source_code": "n = gets.to_i\nn.times do \n a = gets.to_i\n n = 360.0 / (180 - a)\n puts n.to_i == n ? \"YES\" : \"NO\"\nend"}], "negative_code": [{"source_code": "require 'set'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\n\ndegrees = Set.new\nindex = 3\nloop do\n angle = (index - 2) * 180 / index\n degrees << angle\n index += 1\n \n break if index>1000\nend\n\nn.times do\n angle = gets.to_i\n puts ((degrees.include? angle) ? :YES : :NO)\nend"}, {"source_code": "require 'set'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\n\ndegrees = [60, 90, 108, 120, 128, 135, 140, 144, 147, 150, 152, 154, 156, 157, 158, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179]\n\nn.times do\n angle = gets.to_i\n puts ((degrees.include? angle) ? :YES : :NO)\nend"}, {"source_code": "require 'set'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\n\ndegrees = Set.new\nindex = 3\nloop do\n angle = (index - 2) * 180.0 / index\n degrees << angle.to_i if angle.ceil == angle.floor\n index += 1\n \n break if index>2000\nend\n\nputs degrees.inspect\n\nn.times do\n angle = gets.to_i\n puts ((degrees.include? angle) ? :YES : :NO)\nend"}, {"source_code": "require 'set'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\n\ndegrees = []\n3.upto(12) do |index|\n degrees << (index - 2) * 180 / index\nend\n\nn.times do\n angle = gets.to_i\n puts ((degrees.include? angle) ? :YES : :NO)\nend"}, {"source_code": "gets.to_i.times{\n\ta=gets.to_i\n\tputs ((a>=60 && a<180) ? 'YES' : 'NO')\n}\n"}, {"source_code": "puts gets.to_i.times.map{gets.to_i}.map{|x| (x>=60&&360%x==0)}"}, {"source_code": "puts gets.to_i.times.map{gets.to_i}.map{|x| (x>=60&&360%x==0)? \"YES\" : \"NO\"}"}, {"source_code": "puts gets.to_i.times.map{gets.to_i}.map{|x| (x>=60)? \"YES\" : \"NO\"}"}, {"source_code": "#$stdin = File.open(\"1.txt\")\nT = gets.chomp.to_i\n\nH = {}\n\n3.upto(300) do |c|\n\tH[180*(c-2)/c] = 1\nend\nT.times do\n\ta = gets.chomp.to_i\n\tif H.has_key? (a)\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend"}, {"source_code": "n=gets.to_i.times do\na=gets.to_i\nif a>=60 and a<180\nputs \"YES\"\nelse\nputs \"NO\"\nend\nend\n"}, {"source_code": "possible_angles = [0,60,90,108,120,128,135,140,144,147,150,152,154,156,157,158,160]\ntests = gets.to_i\nfor i in 0...tests\n\ttest_case = gets.to_i\n\tif test_case > 160 and test_case <= 180\n\t\tputs \"YES\"\n\t\tnext\n\tend\n\twhile test_case > 180\n\t\ttest_case -= 180\n\tend\n\tif possible_angles.include?(test_case)\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\n"}, {"source_code": "num_tests = gets.to_i\nfor i in 0...num_tests\n\tangle = gets.to_i\n\tsides = 2.0/(1-(angle/180.0))\n\tif (sides - (sides+0.5).to_i) < 0.00000001\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\n"}, {"source_code": "n = gets.to_i\nn.times do \n a = gets.to_i\n n = 360 / (180 - a)\n puts n.to_i == n ? \"YES\" : \"NO\"\nend\nputs \"over\""}, {"source_code": "n = gets.to_i\nn.times do \n a = gets.to_i\n n = 360 / (180 - a)\n puts n.to_i == n ? \"YES\" : \"NO\"\nend"}, {"source_code": "def run\n ary = []\n cnt = 3\n begin\n ary << (180 * (cnt - 2)) / cnt\n cnt += 1\n end while ary.last < 179\n ary.uniq!\n\n n = ARGF.readline\n ARGF.readlines.map(&:to_i).each do |val|\n puts ary.include?(val) ? \"YES\" : \"NO\"\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n ary = []\n cnt = 3\n begin\n angle = (180 * (cnt - 2)) / cnt\n ary[cnt] = angle\n cnt += 1\n end while angle < 179\n\n n = ARGF.readline\n ARGF.readlines.map(&:to_i).each do |val|\n puts ary.include?(val) ? \"YES\" : \"NO\"\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.to_i\nn.times do |i|\n\tx = gets.to_f\n\tx = (-2 * 180) / (x - 180)\n\tputs x\n\tputs x % 1 == 0 ? 'YES' : 'NO'\nend"}, {"source_code": "require 'set'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\n\ndegrees = []\n3.upto(30) do |index|\n degrees << (index - 2) * 180 / index\nend\n\nn.times do\n angle = gets.to_i\n puts ((degrees.include? angle) ? :YES : :NO)\nend"}], "src_uid": "9037f487a426ead347baa803955b2c00"} {"source_code": "class Solver\n\tdef main\n\t\tn, m = gets.split.map { |x| x.to_i }\n\t\tf = gets.split.map { |x| x.to_i }\n\t\tb = gets.split.map { |x| x.to_i }\n\t\th = Hash.new { |hash, key| hash[key] = Array.new }\n\t\tf.each.with_index do |x, id|\n\t\t\th[x] << id\n\t\tend\n\n\t\tambiguity = false\n\t\timpossible = false\n\t\tans = []\n\t\tb.each do |x|\n\t\t\tif h[x].size == 0 then\n\t\t\t\timpossible = true\n\t\t\telsif h[x].size > 1 then\n\t\t\t\tambiguity = true\n\t\t\telse\n\t\t\t\tans << h[x][0] + 1\n\t\t\tend\n\t\tend\n\t\tif impossible then\n\t\t\tputs \"Impossible\"\n\t\telsif ambiguity then\n\t\t\tputs \"Ambiguity\"\n\t\telse\n\t\t\tputs \"Possible\"\n\t\t\tputs ans.join \" \"\n\t\tend\n\tend\nend\n\nSolver.new.main\n", "positive_code": [{"source_code": "require 'scanf'\n\nn, m = scanf(\"%d %d\\n\")\n#f = Array.new(n)\nf_inv = Array.new(n + 1)\n#b = Array.new(m)\n\nf = gets.split.map { |i| i.to_i }\nb = gets.split.map { |i| i.to_i }\n(0..n-1).each do |i|\n f_inv[f[i]] = i + 1\nend\nf_map = Array.new(n + 1, 0)\n(0..n-1).each do |i|\n f_map[f[i]] += 1\nend\na = false, im = false\nans = []\n(0..m-1).each do |i|\n if f_map[b[i]] > 1\n a = true\n elsif f_map[b[i]] == 0\n im = true\n break\n else\n ans.push(f_inv[b[i]])\n end\nend\n\nif im == true\n puts \"Impossible\"\nelsif a == true\n puts \"Ambiguity\"\nelse\n puts \"Possible\"\n (0..ans.size-1).each do |i|\n print ans[i], ' '\n end\n puts\nend"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ngt = proc { gets.chomp.split.map(&:to_i) }\n\nn, m = gt.call\nf = gt.call\nb = gt.call\n\nfm = {}\nn.times do |i|\n k = f[i]\n if fm.key? k\n fm[k] << [i]\n else\n fm[k] = [i]\n end\nend\n\nans = \"\"\na = [0] * m\nm.times do |i|\n k = b[i]\n if fm.key? k\n a[i] = fm[k][0].succ\n if fm[k].size > 1\n ans = \"Ambiguity\"\n end\n else\n puts 'Impossible'\n exit\n end\nend\n\nif ans.empty?\n puts 'Possible'\n puts a * \" \"\nelse\n puts ans\nend\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nf = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\n\nf_map = {}\n\nf.each_index do |i|\n f_map[f[i]] ||= []\n f_map[f[i]] << i + 1\nend\n\na = []\nstatus = 'Possible'\n\nb.each do |bi|\n f_map[bi] ||= []\n case f_map[bi].size\n when 0\n status = 'Impossible'\n break\n when 1\n a << f_map[bi][0]\n else\n if status == 'Possible'\n status = 'Ambiguity'\n end\n end\nend\n\nputs status\nif status == 'Possible'\n puts a.join ' '\nend\n"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\nfs = gets.chomp.split.map(&:to_i)\nbs = gets.chomp.split.map(&:to_i)\n\nhs = Hash.new { |hs, k| hs[k] = [] }\n\n(1..n).map { |i| hs[fs[i - 1]] << i }\n\nas = []\nans = 'Possible'\nbs.each do |b|\n s = hs[b].size\n if s == 0\n ans = 'Impossible'\n break\n elsif 1 < s\n ans = 'Ambiguity'\n end\n as << hs[b][0]\nend\n\nputs ans\nputs as.*' ' if ans == 'Possible'\n"}, {"source_code": "require \"set\"\nn, m = gets.split().map(&:to_i)\nf = gets.split().map(&:to_i)\nb = gets.split().map(&:to_i)\nf = [0] + f\nb = [0] + b\ng = [0]*n\nimf = Set.new()\nd = Set.new()\nx = 0\nfor i in 1..n\n\tif imf.include? f[i]\n\t\td.add(f[i])\n\telse\n\t\timf.add(f[i])\n\tend\n\tg[f[i]] = i\nend\nfor i in 1..m\n\tif not imf.include? b[i]\n\t\tputs \"Impossible\"\n\t\tx = 1\n\t\tbreak\n\tend\nend\nif x != 1\n\ty = 0\n\tfor i in 1..m\n\t\tif d.include? b[i]\n\t\t\tputs \"Ambiguity\"\n\t\t\ty =1\n\t\t\tbreak\n\t\tend\n\tend\n\tif y != 1\n\t\tputs \"Possible\"\n\t\tfor i in 1...m\n\t\t\tprint(g[b[i]])\n\t\t\tprint(\" \")\n\t\tend\n\t\tputs g[b[m]]\n\tend\nend\n"}], "negative_code": [{"source_code": "n, m = gets.chomp.split.map(&:to_i)\nfs = gets.chomp.split.map(&:to_i)\nbs = gets.chomp.split.map(&:to_i)\n\nhs = Hash.new { |hs, k| hs[k] = [] }\n\n(1..m).map { |i| hs[fs[i - 1]] << i }\n\nas = []\nans = 'Possible'\nbs.each do |b|\n s = hs[b].size\n if s == 0\n ans = 'Impossible'\n break\n elsif 1 < s\n ans = 'Ambiguity'\n break\n end\n as << hs[b][0]\nend\n\nputs ans\nputs as.*' ' if ans == 'Possible'\n\n"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\nfs = gets.chomp.split.map(&:to_i)\nbs = gets.chomp.split.map(&:to_i)\n\nhs = Hash.new()\n\n(1..m).map { |i| hs[fs[i - 1]] = i }\nfs.sort!\nbs.sort!\n\nif fs != bs\n puts 'Impossible'\nelse\n fs.uniq!\n if fs.size != m\n puts 'Ambiguity'\n else\n puts 'Possible'\n puts bs.map { |b| hs[b] }.*' '\n end\nend\n\n\n"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\nfs = gets.chomp.split.map(&:to_i)\nbs = gets.chomp.split.map(&:to_i)\n\nhs = Hash.new { |hs, k| hs[k] = [] }\n\n(1..n).map { |i| hs[fs[i - 1]] << i }\n\nas = []\nans = 'Possible'\nbs.each do |b|\n s = hs[b].size\n if s == 0\n ans = 'Impossible'\n break\n elsif 1 < s\n ans = 'Ambiguity'\n break\n end\n as << hs[b][0]\nend\n\nputs ans\nputs as.*' ' if ans == 'Possible'\n"}], "src_uid": "468e8a14dbdca471f143f59b945508d0"} {"source_code": "n = gets.to_i\na =[]\nn.times {a << gets.chomp}\nn.times do\n s = gets.chomp\n n.times do |i|\n if a[i]==s\n a.delete_at(i)\n break\n end\n end\nend\nputs a.length", "positive_code": [{"source_code": "N = gets.to_i\nhash = Hash.new(0)\nN.times do\n str = gets.chomp\n hash[str] += 1\nend\nans = 0\nN.times do\n str = gets.chomp\n if hash[str] > 0\n hash[str] -= 1\n else\n ans += 1\n end\nend\nputs ans"}, {"source_code": "n=gets.to_i\nh=Hash.new 0\ng=Hash.new 0\nn.times{h[gets.chomp]+=1}\nn.times{g[gets.chomp]+=1}\nr=0\nh.each{|k,v|r+=[0,g[k]-v].max;g.delete(k)}\ng.each{|k,v|r+=v}\np r"}], "negative_code": [{"source_code": "n=gets.to_i\nh=Hash.new 0\ng=Hash.new 0\nn.times{h[gets.to_i]+=1}\nn.times{g[gets.to_i]+=1}\nr=0\nh.each{|k,v|r+=(v-g[k]).abs;g.delete(k)}\ng.each{|k,v|r+=v}\np r"}, {"source_code": "n=gets.to_i\nh=Hash.new 0\ng=Hash.new 0\nn.times{h[gets.to_i]+=1}\nn.times{g[gets.to_i]+=1}\nr=0\nh.each{|k,v|r+=(v-g[k]).abs;g.delete(k)}\nr/=2\ng.each{|k,v|r+=v}\np r"}, {"source_code": "n=gets.to_i\nh=Hash.new 0\ng=Hash.new 0\nn.times{h[gets.chomp]+=1}\nn.times{g[gets.chomp]+=1}\nr=0\nh.each{|k,v|r+=[0,g[k]-v].max}\ng.each{|k,v|r+=v}\np r"}, {"source_code": "n=gets.to_i\nh=Hash.new 0\ng=Hash.new 0\nn.times{h[gets.chomp]+=1}\nn.times{g[gets.chomp]+=1}\nr=0\nh.each{|k,v|r+=(v-g[k]).abs;g.delete(k)}\ng.each{|k,v|r+=v}\np r"}, {"source_code": "n = gets.to_i\na1 = []\na2 = []\nn.times { a1 << gets.chomp.chars}\n\nn.times { a2 << gets.chomp.chars}\n\na1.sort!{|a,b| a.length <=> b.length}\na2.sort!{|a,b| a.length <=> b.length}\nres = 0\n\nn.times do |i|\n res += (a1[i] - a2[i]).length\nend\nputs res"}, {"source_code": "n = gets.to_i\na =[]\na2=[]\nn.times {a << gets.chomp}\nn.times{a2 << gets.chomp}\nputs (a2-a).length"}, {"source_code": "n = gets.to_i\na1 = []\na2 = []\nn.times { s = gets.chomp\nvalid = (s =~ /(\\A(X{0,3})(S|L)$)|(\\A(S|L|M)$)/) != nil\na1 << s.chars if valid\n}\n\nn.times { s = gets.chomp\nvalid = (s =~ /(\\A(X{0,3})(S|L)$)|(\\A(S|L|M)$)/) != nil\na2 << s.chars if valid}\n\na1.sort!{|a,b| a.length <=> b.length}\na2.sort!{|a,b| a.length <=> b.length}\nres = 0\nn.times do |i|\n res += (a1[i] - a2[i]).length\nend\nputs res"}], "src_uid": "c8321b60a6ad04093dee3eeb9ee27b6f"} {"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\torders = []\n\t\tn.times do\n\t\t\torders << gets.split.map{ |x| x.to_i }\n\t\tend\n\t\torders.sort! { |a, b| a[1] <=> b[1] }\n\n\t\tans = 0\n\t\tlast = 0\n\t\torders.each do |order|\n\t\t\tif order[0] > last then\n\t\t\t\tlast = order[1]\n\t\t\t\tans += 1\n\t\t\tend\n\t\tend\n\t\tputs ans\n\tend\nend\n\nSolver.new.main", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\nnum_orders = gets.to_i\norders = num_orders.times.map do gets.split(' ').map(&:to_i) end\norders = orders.sort_by do |order| order[1] end\n\ntotal = 0\ncurrent_right = 0\norders.each do |left, right|\n if current_right < left\n current_right = right\n total += 1\n end\nend\n\nputs total\n"}, {"source_code": "\nMAX = 10**9 + 1\n\nn = 0\nn = gets.chomp.to_i\n\nnumbers = Array.new\n# input\nfor i in 0...n do\n\tt = gets.chomp.split \" \"\n\tnumbers.push t.last.to_i * MAX + t.first.to_i\nend\n\nnumbers.sort!\n\n# calculating answer\nans = 1\nlast_fin = numbers[0] / MAX\n\nfor i in 1...n do\n\tif numbers[i] % MAX > last_fin\n\t\tans = ans + 1\n\t\tlast_fin = numbers[i] / MAX\n\tend\n\t\nend\n\nputs ans"}], "negative_code": [{"source_code": "\nn = 0\nl = Array.new\nr = Array.new\n\nn = gets.chomp.to_i\n# input\nfor i in 0...n do\n\tt = gets.chomp.split \" \"\n\tl[i] = t.first.to_i\n\tr[i] = t.last.to_i\nend\n\n# insertion sorting\nfor i in 1...n do\n\t\n\tk = r[i]\n\tj = i\n\n\twhile j > 0 and r[j] < r[j-1] do\n\t\tr[j] = r[j-1]\n\t\tj = j - 1\n\tend\n\t\n\tr[j] = k\n\t\n\tk = l[i]\n\tl[i] = l[j]\n\tl[j] = k\t\nend\n\n# calculating answer\nans = 1\nr_last = r[0]\n\nfor i in 1...n do\n\tif l[i] > r_last\n\t\tans = ans + 1\n\t\tr_last = r[i]\n\tend\nend\n\nputs ans"}, {"source_code": "\nn = 0\nl = Array.new\nr = Array.new\n\nn = gets.chomp.to_i\n\npointer = Hash.new\nmax_len = 1\n# input\nfor i in 0...n do\n\tt = gets.chomp.split \" \"\n\tl[i] = t.first\n\tr[i] = t.last\n\tif r[i].length > max_len\n\t\tmax_len = r[i].length\n\tend\n\t\n\tif pointer.keys.include? r[i]\n\t\tpointer[r[i]].push l[i]\n\telse\n\t\tpointer[r[i]] = Array.new\n\t\tpointer[r[i]].push l[i]\n\tend\nend\n\npointer.each_key {|key| pointer[key].sort!}\nr.sort!\n# radix sorting\n\n\n# calculating answer\nans = 1\nr_last = r[0]\n\nfor i in 1...n do\n\tif pointer[r[i]].shift.to_i > r_last.to_i\n\t\tans = ans + 1\n\t\tr_last = r[i]\n\tend\nend\n\nputs ans\n"}, {"source_code": "n = 0\nl = Array.new\nr = Array.new\n\nn = gets.chomp.to_i\n\nstrings = Array.new\nmax_len = 1\n# input\nfor i in 0...n do\n\tt = gets.chomp.split \" \"\n\tstrings.push t.last + \" \" + t.first\nend\n\nstrings.sort!\n\n# calculating answer\nans = 1\nlast_fin = (strings[0].split(\" \")).first.to_i\n\nfor i in 1...n do\n\tt = strings[i].split(\" \")\n\tif t.last.to_i > last_fin.to_i\n\t\tans = ans + 1\n\t\tlast_fin = strings[i].split(\" \").first.to_i\n\tend\n\t\nend\n\n=begin\nfor i in 0...n \n\tprint l[i], \" \", r[i]\n\tputs\n=end\n\nputs ans"}, {"source_code": "n = 0\nn = gets.chomp.to_i\n\nnumbers = Array.new\n# input\nfor i in 0...n do\n\tt = gets.chomp.split \" \"\n\tnumbers.push t.last.to_i * 500001 + t.first.to_i\nend\n\nnumbers.sort!\n\n# calculating answer\nans = 1\nlast_fin = numbers[0] / 500001\n\nfor i in 1...n do\n\tif numbers[i] % 500001 > last_fin\n\t\tans = ans + 1\n\t\tlast_fin = numbers[i] / 500001\n\tend\n\t\nend\n\nputs ans"}], "src_uid": "73e8984cceded15027c4ab89c5624a92"} {"source_code": "n, m = gets.split.map(&:to_i)\ncats = [nil] + gets.split.map(&:to_i)\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = gets.split.map(&:to_i)\n edges[u] << v\n edges[v] << u\nend\ncon_cats = Array.new(n + 1)\n\nque = [[1, 0]]\nans = 0\nloop do\n ind, accum = que[0]\n break unless ind\n que.shift\n next if con_cats[ind]\n if cats[ind] == 1\n accum += 1\n else\n accum = 0\n end\n con_cats[ind] = accum\n if accum <= m\n ans += 1 if edges[ind].size == 1 && ind != 1\n que.push(*edges[ind].zip([accum] * edges[ind].size))\n end\nend\nputs ans\n", "positive_code": [{"source_code": "# coding: utf-8\n\nrequire \"set\"\n\n# if __FILE__ == $0\n# end\n\nn, m = gets.split.map(&:to_i)\ncats = [nil] + gets.split.map(&:to_i) # 1-based vertices\nvertices = {}\n(n-1).times {\n u, v = gets.split.map(&:to_i)\n\n vertices[v] ||= [] # initialize u with empty array\n vertices[u] ||= []\n vertices[u] << v\n vertices[v] << u\n}\n\n# Remember, rooted tree\n#p vertices\nTRAVERSE_UP = -99\nstack = [1]\ntraverse = []\ntraverse_hashed = {} # do not delete, just mark with nil, put/delete with traverse stack control\ncat_acc_stack = [0] # accumulator stack. push/pop with traverse stack control\nreachables = []\nwhile !stack.empty?\n i = stack.pop\n if i == TRAVERSE_UP\n traverse.pop\n cat_acc_stack.pop\n next\n end\n\n if cat_acc_stack.last + cats[i] > m\n # you can stop traversing from here. children can not be reached.\n # visiting node_i should stop\n next # back to stack again\n else\n #p vertices[i]\n #p traverse\n if vertices[i].length == 1 && vertices[i][0] == traverse.last\n reachables << i\n else\n # new traverse starts!\n if cats[i] == 0\n cat_acc_stack << 0\n else\n cat_acc_stack << cat_acc_stack.last + cats[i]\n end\n\n traverse.push(i)\n traverse_hashed[i] = 1\n stack.push(TRAVERSE_UP)\n for ni in vertices[i]\n if traverse_hashed[ni] == nil\n stack.push(ni)\n end\n end\n end \n end\nend\n\n#p vertices\n#p reachables\nputs reachables.length # print reachables\n"}, {"source_code": "def ri; gets.split.map(&:to_i); end\nn, m = ri\ncats = [nil] + ri\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = ri\n edges[u] << v\n edges[v] << u\nend\n\nans = 0\nque = [[1, cats[1]]]\nuntil que.empty?\n u, s = que.shift\n ans += 1 if edges[u].empty?\n edges[u].each do |v|\n edges[v].delete(u)\n ns = cats[v] == 1 ? s + 1 : 0\n que << [v, ns] if ns <= m\n end\nend\nputs ans\n\n"}, {"source_code": "def ri; gets.split.map(&:to_i); end\nn, m = ri\ncats = [nil] + ri\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = ri\n edges[u] << v\n edges[v] << u\nend\n\nans = 0\nque = [[1, cats[1]]]\nuntil que.empty?\n u, s = que.shift\n ans += 1 if edges[u].empty?\n edges[u].each do |v|\n edges[v].delete(u)\n ns = cats[v] == 1 ? s + 1 : 0\n que << [v, ns] if ns <= m\n end\nend\nputs ans\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\ncats = [nil] + gets.split.map(&:to_i)\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = gets.split.map(&:to_i)\n edges[u] << v\n edges[v] << u\nend\n\nans = 0\nque = [[1, cats[1]]]\nuntil que.empty?\n u, s = que.shift\n ans += 1 if edges[u].empty?\n edges[u].each do |v|\n edges[v].delete(u)\n ns = cats[v] == 1 ? s + 1 : 0\n que << [v, ns] if ns <= m\n end\nend\nputs ans\n"}, {"source_code": "def ri; gets.split.map(&:to_i); end\nn, m = ri\ncats = [nil] + ri\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = ri\n edges[u] << v\n edges[v] << u\nend\n\nans = 0\nque = [[1, cats[1]]]\nuntil que.empty?\n u, s = que.shift\n ans += 1 if edges[u].empty?\n edges[u].each do |v|\n edges[v].delete(u)\n ns = cats[v] == 1 ? s + 1 : 0\n que << [v, ns] if ns <= m\n end\nend\nputs ans\n\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\ncats = gets.split(' ').map(&:to_i)\ncats.unshift 0\n\nvert = Hash.new { |h, k| h[k] = [] }\n\n1.upto(n - 1) do\n v1, v2 = gets.split(' ').map(&:to_i)\n vert[v1] << v2\n vert[v2] << v1\nend\n\nque = [prev: 0, curr: 1, cats: cats[1], failed: 1 > m]\n\nresult = 0\n\nwhile !que.empty?\n curr = que.shift\n\n any = false\n\n vert[curr[:curr]].each do |v|\n next if curr[:prev] == v\n\n any = true\n\n que << {\n curr: v,\n cats: (curr[:cats] + cats[v]) * cats[v],\n prev: curr[:curr],\n failed: curr[:failed] || (curr[:cats] + cats[v]) * cats[v] > m\n }\n end\n\n result += 1 unless any || curr[:failed]\nend\n\nputs result\n"}, {"source_code": "def ri; gets.split.map(&:to_i); end\nn, m = ri\ncats = [nil] + ri\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = ri\n edges[u] << v\n edges[v] << u\nend\n\nans = 0\nque = [[1, cats[1]]]\nuntil que.empty?\n u, s = que.shift\n ans += 1 if edges[u].empty?\n edges[u].each do |v|\n edges[v].delete(u)\n ns = cats[v] == 1 ? s + 1 : 0\n que << [v, ns] if ns <= m\n end\nend\nputs ans\n\n"}, {"source_code": "n=gets.split(' ').map(&:to_i)\nm=n[1]\nn=n[0]\na=gets.split(' ').map(&:to_i)\ng=Array.new(n+1)\n(1).upto(n) do |i|\n g[i]=[]\nend\n(1).upto(n-1) do\n x=gets.split(' ').map(&:to_i)\n g[x[0]].push(x[1])\n g[x[1]].push(x[0])\nend\nq=Queue.new\nq.push([1,0])\nans=0\nvis = Array.new(n+1,false)\nwhile !(q.empty?)\n cur = q.pop\n node = cur[0]\n cats = cur[1]\n cats=0 if a[node-1]==0\n cats+=1 if a[node-1]==1\n next if cats==m+1\n ans+=1 if g[node].length==1 and node!=1\n g[node].each do |next_node|\n next if vis[next_node]\n vis[next_node]=true\n q.push([next_node,cats])\n end\nend\nputs ans\n"}, {"source_code": "def ri; gets.split.map(&:to_i); end\nn, m = ri\ncats = [nil] + ri\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = ri\n edges[u] << v\n edges[v] << u\nend\n\nans = 0\nque = [[1, cats[1]]]\nuntil que.empty?\n u, s = que.shift\n ans += 1 if edges[u].empty?\n edges[u].each do |v|\n edges[v].delete(u)\n ns = cats[v] == 1 ? s + 1 : 0\n que << [v, ns] if ns <= m\n end\nend\nputs ans\n\n"}, {"source_code": "def getai; return gets.split.map{|e| e.to_i}; end\nnm = getai\nn = nm[0]; m = nm[1]\na = getai\nadj = Array.new(n)\n(n - 1).times do\n xy = getai\n x = xy[0] - 1\n y = xy[1] - 1\n nil == adj[x] ? adj[x] = [y] : adj[x] << y\n nil == adj[y] ? adj[y] = [x] : adj[y] << x\nend\nstack = [0]\nused = Array.new(n, false)\nlast = Array.new(n, -1)\ncats = Array.new(n)\ncats[0] = a[0]\nwhile (!stack.empty?) # DFS\n v = stack.last\n used[v] = true\n l = last[v] + 1\n if l < adj[v].length && used[adj[v][l]]\n l += 1\n end\n if l < adj[v].length\n to = adj[v][l]\n cats[to] = cats[v] * a[to] + a[to]\n if cats[to] <= m\n stack << to\n end\n else\n stack.pop\n end\n last[v] = l\nend\ngood_leaves = 0\nfor v in 0..n-1\n if adj[v].length == 1 && used[v] && v != 0\n good_leaves += 1\n end\nend\nputs good_leaves\n"}, {"source_code": "def ri; gets.split.map(&:to_i); end\nn, m = ri\ncats = [nil] + ri\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = ri\n edges[u] << v\n edges[v] << u\nend\n\nans = 0\nque = [[1, cats[1]]]\nuntil que.empty?\n u, s = que.shift\n ans += 1 if edges[u].empty?\n edges[u].each do |v|\n edges[v].delete(u)\n ns = cats[v] == 1 ? s + 1 : 0\n que << [v, ns] if ns <= m\n end\nend\nputs ans\n\n"}, {"source_code": "def ri; gets.split.map(&:to_i); end\nn, m = ri\ncats = [nil] + ri\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = ri\n edges[u] << v\n edges[v] << u\nend\n\nans = 0\nque = [[1, cats[1]]]\nuntil que.empty?\n u, s = que.shift\n ans += 1 if edges[u].empty?\n edges[u].each do |v|\n edges[v].delete(u)\n ns = cats[v] == 1 ? s + 1 : 0\n que << [v, ns] if ns <= m\n end\nend\nputs ans\n\n"}, {"source_code": "def ri; gets.split.map(&:to_i); end\nn, m = ri\ncats = [nil] + ri\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = ri\n edges[u] << v\n edges[v] << u\nend\n\nans = 0\nque = [[1, cats[1]]]\nuntil que.empty?\n u, s = que.shift\n ans += 1 if edges[u].empty?\n edges[u].each do |v|\n edges[v].delete(u)\n ns = cats[v] == 1 ? s + 1 : 0\n que << [v, ns] if ns <= m\n end\nend\nputs ans"}, {"source_code": "def ri; gets.split.map(&:to_i); end\nn, m = ri\ncats = [nil] + ri\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = ri\n edges[u] << v\n edges[v] << u\nend\n\nans = 0\nque = [[1, cats[1]]]\nuntil que.empty?\n u, s = que.shift\n ans += 1 if edges[u].empty?\n edges[u].each do |v|\n edges[v].delete(u)\n ns = cats[v] == 1 ? s + 1 : 0\n que << [v, ns] if ns <= m\n end\nend\nputs ans\n\n"}, {"source_code": "def ri; gets.split.map(&:to_i); end\nn, m = ri\ncats = [nil] + ri\nedges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = ri\n edges[u] << v\n edges[v] << u\nend\n\nans = 0\nque = [[1, cats[1]]]\nuntil que.empty?\n u, s = que.shift\n ans += 1 if edges[u].empty?\n edges[u].each do |v|\n edges[v].delete(u)\n ns = cats[v] == 1 ? s + 1 : 0\n que << [v, ns] if ns <= m\n end\nend\nputs ans\n\n"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\narr=[]\nn.times{\n\tarr<<[]\n}\n(n-1).times{\n\ta,b=gets.split.map{|e| e.to_i-1}\n\tarr[a]<1) && arr[e[0]].size>e[1] then\n\t\tp1=arr[e[0]][e[1]]\n\t\tstc.last[1]+=1\n\t\ts1=stc.size\n\t\tif s1>1 && stc[s1-2][0]==p1 then\n\t\t\tnext\n\t\tend\n\t\tadd=x[p1]\n\t\tt1=0\n\t\tif add==1 then\n\t\t\tt1=e[2]+add\n\t\tend\n\t\tif t1<=m then\n\t\t\tstc<<[p1,0,t1]\n\t\tend\n\telse\n\t\tif e[0]==0 then\n\t\t\tbreak\n\t\telsif arr[e[0]].size==1 then\n\t\t\tif e[2]<=m then\n\t\t\t\tans+=1\n\t\t\tend\n\t\tend\n\t\tstc.pop\n\tend\n\t\nend\nputs ans\n\n"}], "negative_code": [{"source_code": "def get_i_arr\n return gets.chomp.split.map{|e| e.to_i}\nend\nnm = get_i_arr\nn = nm[0]; m = nm[1]\na = get_i_arr\nadj = Array.new(n)\n(n - 1).times do\n xy = get_i_arr\n x = xy[0] - 1; y = xy[1] - 1\n if nil == adj[x]\n adj[x] = [y]\n else\n adj[x] << y\n end\n if nil == adj[y]\n adj[y] = [x]\n else\n adj[y] << x\n end\nend\n# DFS\nstack = [0]\nused = Array.new(n, false)\nlast = Array.new(n, -1)\ncats = Array.new(n, 0)\ncur_cats = cats[0] = a[0]\nwhile (!stack.empty?)\n v = stack.last\n used[v] = true\n l = last[v] + 1\n if l < adj[v].length && used[adj[v][l]]\n l += 1\n end\n if l < adj[v].length\n to = adj[v][l]\n if 1 == a[to] && 0 == a[v]\n new_cur_cats = 1\n else\n new_cur_cats = cur_cats + a[to]\n end\n if new_cur_cats <= m\n stack << to\n cur_cats = new_cur_cats\n cats[to] = [cur_cats, cats[v]].max\n end\n else\n prev = stack.length > 1 ? stack[stack.length - 2] : -1\n if prev == -1\n cur_cats = 0\n else\n cur_cats = cats[prev]\n end\n stack.pop\n end\n last[v] = l\nend\ngood_leaves = 0\nfor v in 0..n-1\n if adj[v].length == 1 && used[v] && v != 0\n good_leaves += 1\n end\nend\nputs good_leaves\n"}, {"source_code": "def getai; return gets.split.map{|e| e.to_i}; end\nnm = getai\nn = nm[0]; m = nm[1]\na = getai\nadj = Array.new(n)\n(n - 1).times do\n xy = getai\n x = xy[0] - 1; y = xy[1] - 1\n if nil == adj[x] then adj[x] = [y]\n else adj[x] << y end\n if nil == adj[y] then adj[y] = [x]\n else adj[y] << x end\nend\nstack = [0]\nused = Array.new(n, false)\nlast = Array.new(n, -1)\ncats = Array.new(n, 0)\ncur_cats = cats[0] = a[0]\nwhile (!stack.empty?) # DFS\n v = stack.last\n used[v] = true\n l = last[v] + 1\n if l < adj[v].length && used[adj[v][l]]\n l += 1\n end\n if l < adj[v].length\n to = adj[v][l]\n if 1 == a[v] && 0 == a[to]\n new_cats = 0\n else\n new_cats = cur_cats + a[to]\n end\n cats[to] = [new_cats, cats[v]].max\n if cats[to] <= m\n stack << to\n cur_cats = new_cats\n end\n else\n if stack.length > 1\n prev = stack[stack.length - 2]\n if 0 == a[v] && 1 == a[prev]\n cur_cats = cats[prev]\n else\n cur_cats -= a[v]\n end\n else \n cur_cats = 0\n end\n stack.pop\n end\n last[v] = l\nend\ngood_leaves = 0\nfor v in 0..n-1\n if adj[v].length == 1 && used[v] && v != 0\n good_leaves += 1\n end\nend\nputs good_leaves\n"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\narr=[]\nn.times{\n\tarr<<[]\n}\n(n-1).times{\n\ta,b=gets.split.map{|e| e.to_i-1}\n\tarr[a]<1 && arr[e[0]].size>e[1] then\n\t\tp1=arr[e[0]][e[1]]\n\t\tstc.last[1]+=1\n\t\ts1=stc.size\n\t\tif s1>1 && stc[s1-2][0]==p1 then\n\t\t\tnext\n\t\tend\n\t\tadd=x[p1]\n\t\tt1=0\n\t\tif add==1 then\n\t\t\tt1=e[2]+add\n\t\tend\n\t\tif t1<=m then\n\t\t\tstc<<[p1,0,t1]\n\t\tend\n\telse\n\t\tif e[0]==0 then\n\t\t\tbreak\n\t\telsif arr[e[0]].size==1 then\n\t\t\tif e[2]<=m then\n\t\t\t\tans+=1\n\t\t\tend\n\t\tend\n\t\tstc.pop\n\tend\n\t\nend\nputs ans\n\n"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nm-=1\nx=gets.split.map{|e| e.to_i}\narr=[]\nn.times{\n\tarr<<[]\n}\n(n-1).times{\n\ta,b=gets.split.map{|e| e.to_i-1}\n\tarr[a]<e[1] then\n\t\ts1=stc.size\n\t\tp1=arr[e[0]][e[1]]\n\t\tstc.last[1]+=1\n\t\tif s1>1 && stc[s1-2][0]==p1 then\n\t\t\tnext\n\t\tend\n\t\tstc<<[p1,0,0]\n\telse\n\t\tstc.pop\n\t\tif e[0]==m then\n\t\t\tputs e[2]+1\n\t\t\tbreak\n\t\telse\n\t\t\tif x[e[0]]==1 then\n\t\t\t\tstc.last[2]+=e[2]+1\n\t\t\tend\n\t\tend\n\tend\nend\n\n"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\narr=[]\nn.times{\n\tarr<<[]\n}\n(n-1).times{\n\ta,b=gets.split.map{|e| e.to_i-1}\n\tarr[a]<1 && arr[e[0]].size>e[1] then\n\t\tp1=arr[e[0]][e[1]]\n\t\tstc.last[1]+=1\n\t\ts1=stc.size\n\t\tif s1>1 && stc[s1-2][0]==p1 then\n\t\t\tnext\n\t\tend\n\t\tadd=x[e[0]]\n\t\tadd=0 if e[0]==0\n\t\tstc<<[p1,0,add+e[2]]\n\telse\n\t\tif e[0]==0 then\n\t\t\tbreak\n\t\telsif arr[e[0]].size==1 then\n\t\t\tif e[2] #{j}\"\n if cats[j] == 1\n cats_on_way += cats[j]\n else\n cats_on_way = 0 # reset, because not consecutive.\n end\n if cats_on_way > max_consecutives\n max_consecutives = cats_on_way # updates\n end\n break if j == 1\n # p \"> #{j} -> #{rvertices[j][0].v}\"\n j = rvertices[j][0].v\n end\n\n if max_consecutives <= m\n reachables << i\n end\n}\n\n# p reachables\nputs reachables.length # print reachables\n"}, {"source_code": "# coding: utf-8\n\nrequire \"set\"\n\n# if __FILE__ == $0\n# end\n\nn, m = gets.split.map(&:to_i)\ncats = [nil] + gets.split.map(&:to_i) # 1-based vertices\nrvertices = {}\nleaves = Set.new\n(n-1).times {\n u, v = gets.split.map(&:to_i) \n leaves.add(v)\n leaves.delete(u)\n rvertices[u] ||= [] # initialize u with empty array\n rvertices[v] ||= []\n rvertices[v] << u\n\n}\n\n# Remember, rooted tree\n#p rvertices\nreachables = []\n\nleaves.each { |i|\n if i == 1 # root node\n next\n end\n j = i\n cat_count = 0\n longest_cat_seq = 0\n loop do\n if cats[j] == 0\n if longest_cat_seq < cat_count\n longest_cat_seq = cat_count\n cat_count = 0\n end\n else\n cat_count += cats[j]\n end\n\n if rvertices[j].empty?\n if longest_cat_seq < cat_count\n longest_cat_seq = cat_count\n end\n break\n else\n j = rvertices[j][0]\n end\n end\n\n if longest_cat_seq <= m\n reachables << i\n end\n}\n\np reachables\nputs reachables.length # print reachables\n"}, {"source_code": "# coding: utf-8\n\nrequire \"set\"\n\n# if __FILE__ == $0\n# end\n\nn, m = gets.split.map(&:to_i)\ncats = [nil] + gets.split.map(&:to_i) # 1-based vertices\nvertices = {}\n(n-1).times {\n u, v = gets.split.map(&:to_i)\n\n vertices[v] ||= [] # initialize u with empty array\n vertices[u] ||= []\n vertices[u] << v\n vertices[v] << u\n}\n\n# Remember, rooted tree\n#p vertices\nTRAVERSE_UP = -99\nstack = [1]\ntraverse = []\nreachables = []\nwhile !stack.empty?\n i = stack.pop\n if i == TRAVERSE_UP\n traverse.pop\n next\n else\n traverse.push(i)\n end\n\n if vertices[i].length == 1\n if i == 1\n break\n end\n cat_count = 0\n longest_cats = 0\n traverse.each { |j|\n if cats[j] == 0\n if longest_cats < cat_count\n longest_cats = cat_count\n end\n cat_count = 0\n else\n cat_count += cats[j]\n end\n }\n if longest_cats < cat_count\n longest_cats = cat_count #last update.\n end\n\n #p \"longest_cats #{longest_cats} #{m}\"\n #p stack\n #p traverse\n if longest_cats <= m\n reachables << i\n end\n\n traverse.pop\n else\n stack.push(TRAVERSE_UP)\n for ni in vertices[i]\n unless traverse.include?(ni)\n stack.push(ni)\n end\n end\n end \nend\n\n#p vertices\n#p reachables\nputs reachables.length # print reachables\n"}, {"source_code": "# coding: utf-8\n\nrequire \"set\"\n\n# if __FILE__ == $0\n# end\n\nn, m = gets.split.map(&:to_i)\ncats = [nil] + gets.split.map(&:to_i) # 1-based vertices\nrvertices = {}\nleaves = Set.new\n(n-1).times {\n u, v = gets.split.map(&:to_i) \n leaves.add(v)\n leaves.delete(u)\n rvertices[u] ||= [] # initialize u with empty array\n rvertices[v] ||= []\n rvertices[v] << u\n\n}\n\n# Remember, rooted tree\n#p rvertices\nreachables = []\n\nleaves.each { |i|\n if i == 1 # root node\n next\n end\n j = i\n cat_count = 0\n longest_cat_seq = 0\n loop do\n if cats[j] == 0\n if longest_cat_seq < cat_count\n longest_cat_seq = cat_count\n cat_count = 0\n end\n else\n cat_count += cats[j]\n end\n\n if rvertices[j].empty?\n if longest_cat_seq < cat_count\n longest_cat_seq = cat_count\n end\n break\n else\n j = rvertices[j][0]\n end\n end\n\n if longest_cat_seq <= m\n reachables << i\n end\n}\n\n# p reachables\nputs reachables.length # print reachables\n"}, {"source_code": "n, $m = gets.split.map(&:to_i)\n$cats = [nil] + gets.split.map(&:to_i)\n$edges = Array.new(n + 1){Array.new}\n$edges[0] = [1]\n(n - 1).times do\n u, v = gets.split.map(&:to_i)\n $edges[u] << v\nend\n\n$ans = 0\ndef dfs(lv, accum)\n return unless $edges[lv]\n if $cats[lv] == 1\n accum += 1\n elsif !$cats[lv].nil?\n accum = 0\n $ans += 1\n end\n $edges[lv].each{|v| dfs(v, accum)} if accum <= $m\nend\n\ndfs(0, 0)\nputs $ans\n"}, {"source_code": "n, $m = gets.split.map(&:to_i)\n$cats = [nil] + gets.split.map(&:to_i)\n$edges = Array.new(n + 1){Array.new}\n(n - 1).times do\n u, v = gets.split.map(&:to_i)\n $edges[u] << v\n $edges[v] << u\nend\n$con_cats = Array.new(n + 1)\n\n$ans = 0\ndef dfs(lv, accum)\n return if $con_cats[lv]\n if $edges[lv].size == 1\n $ans += 1 if accum + $cats[lv] <= $m\n return\n end\n if $cats[lv] == 1\n accum += 1\n else\n accum = 0\n end\n $con_cats[lv] = accum\n $edges[lv].each{|v| dfs(v, accum)} if accum <= $m\nend\n\ndfs(1, 0)\nputs $ans\n"}, {"source_code": "n, $m = gets.split.map(&:to_i)\n$cats = [nil] + gets.split.map(&:to_i)\n$edges = Array.new(n + 1){Array.new}\n$edges[0] = [1]\n(n - 1).times do\n u, v = gets.split.map(&:to_i).sort\n $edges[u] << v\nend\n\n$ans = 0\ndef dfs(lv, accum)\n if $edges[lv] == []\n $ans += 1 if accum + $cats[lv] <= $m\n return\n end\n if $cats[lv] == 1\n accum += 1\n else\n accum = 0\n end\n $edges[lv].each{|v| dfs(v, accum)} if accum <= $m\nend\n\ndfs(0, 0)\nputs $ans\n"}, {"source_code": "n, $m = gets.split.map(&:to_i)\n$cats = [nil] + gets.split.map(&:to_i)\n$edges = Array.new(n + 1){Array.new}\n$edges[0] = [1]\n(n - 1).times do\n u, v = gets.split.map(&:to_i)\n $edges[u] << v\nend\n\n$ans = 0\ndef dfs(lv, accum)\n if $edges[lv] == []\n $ans += 1 if accum + $cats[lv] <= $m\n return\n end\n if $cats[lv] == 1\n accum += 1\n else\n accum = 0\n end\n $edges[lv].each{|v| dfs(v, accum)} if accum <= $m\nend\n\ndfs(0, 0)\nputs $ans\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\ncats = gets.split(' ').map(&:to_i)\ncats.unshift 0\n\nvert = Hash.new { [] }\n\n1.upto(n - 1) do\n v1, v2 = gets.split(' ').map(&:to_i)\n vert[v1] = vert[v1] + [v2]\n vert[v2] = vert[v2] + [v1]\nend\n\nque = [v: [1], cats: 1, failed: false]\n\nresult = 0\n\nwhile !que.empty?\n curr = que.shift\n vort = curr[:v].last\n\n any = false\n\n vert[vort].each do |v|\n next if curr[:v].include? v\n\n any = true\n\n que << {\n v: curr[:v] + [v],\n cats: (curr[:cats] + cats[v]) * cats[v],\n failed: curr[:failed] || (curr[:cats] + cats[v]) * cats[v] > m\n }\n end\n\n result += 1 unless any || curr[:failed]\nend\n\nputs result\n"}], "src_uid": "875e7048b7a254992b9f62b9365fcf9b"} {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.odd? && j < n ? 1 : 0\n}\n\n", "positive_code": [{"source_code": "def query(l,r)\n ele = r - l + 1\n return false if ele.odd?\n val = ele / 2\n return true if val <= @one_count && val <= @minus_count\n return false\nend\n\nn,m = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n@one_count = arr.count(1)\n@minus_count = n - @one_count\nans = []\nm.times do\n\tl,r = gets.split(\" \").map(&:to_i)\n\tans << (query(l,r) ? 1 : 0)\nend\nans.each do |a|\n\tputs a\nend"}, {"source_code": "# def query(l,r)\n# ele = r - l + 1\n# return false if ele.odd?\n# val = ele / 2\n# return true if val <= @one_count && val <= @minus_count\n# return false\n# end\n\nn,m = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n@one_count = arr.count(1)\n@minus_count = n - @one_count\nans = []\nm.times do\n\tl,r = gets.split(\" \")\n\tl = l.to_i\n\tr = r.to_i\n\tele = r - l + 1\n\tif ele.odd?\n \t\tans << false\n \t\tnext \n \tend\n \tval = ele / 2\n \tif val <= @one_count && val <= @minus_count\n \t\tans << true\n \t\tnext \n \tend\n \tans << false\nend\n\nans.each do |a|\n\tputs a ? 1 : 0\nend"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\na = Array.new(3,0)\ngets.split.each{|i| a[i.to_i+1]+=1}\n(1..m).each do\n l, r = gets.split.collect{|i| i.to_i}\n if (r-l+1).odd?\n puts 0\n elsif a[0] < (r-l+1)/2 or a[2] < (r-l+1)/2\n puts 0\n else\n puts 1\n end\nend\n"}, {"source_code": "n,m = gets.strip.split(' ').map {|x| x.to_i}\na = gets.strip.split(' ')\nh = {'1' => 0, '-1' => 0}\na.each do |e| h[e] += 1 end\n\nm.times do\n l, r = gets.strip.split(' ').map {|x| x.to_i}\n if( (l+r)%2 == 0)\n puts 0\n else\n k = ((r-l).abs+1)/2\n puts( (h.values.min >= k) ? 1 : 0 )\n end\nend"}, {"source_code": "n_m = gets.split.map { |i| i.to_i }\nn = n_m[0]\nm = n_m[1]\n\na_count = b_count = 0\n\na = gets.split.map do |i|\n r = i.to_i\n if r == 1\n a_count += 1\n else\n b_count += 1\n end\n r\nend\n\nfor i in 1..m\n from_to = gets.split.map { |i| i.to_i }\n from = from_to[0]\n to = from_to[1]\n len = to - from + 1\n\n if (len % 2 == 0) && a_count >= len / 2 && b_count >= len / 2\n puts 1\n else\n puts 0\n end\nend\n"}, {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.odd? && j < n ? 1 : 0\n}\n\n"}, {"source_code": "n, m = gets.chomp.split(' ').collect{|item| item.to_i}\na = gets.chomp.split(' ').collect{|item| item.to_i }\na1 = a.count{|item| item == -1}\na2 = a.length - a1\nfor i in 1..m\n l, r = gets.chomp.split(' ').collect{|item| item.to_i}\n numbers = r - l + 1\n if numbers % 2 == 0\n if a1 >= numbers / 2 and a2 >= numbers / 2\n puts 1\n else \n puts 0\n end\n else\n puts 0\n end\nend"}, {"source_code": "#!/usr/bin/env ruby\n\nn, m = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i)\na, b = x.count(-1), x.count(1)\nm.times do\n\tl, r = gets.split.map(&:to_i)\n\tl = r - l + 1\n\tif l % 2 == 1\n\t\tputs 0\n\telse\n\t\tl = l / 2\n\t\tputs a >= l && b >= l ? 1 : 0\n\tend\nend\n"}, {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.odd? && j < n ? 1 : 0\n}\n\n"}, {"source_code": "n,m = gets.split.map{|x| x.to_i}\na = gets.split(' ').map{|x| x.to_i}\np = a.count{|x| x<0}\nq = a.count{|x| x>0}\np += p;q += q;\n# p p,q\nm.times{ \n\t(l,r) = gets.split.map{|x| x.to_i}\n\tl = r-l+1\n\tif (l&1)==1\n\t\tputs 0\n\telsif l>p\n\t\tputs 0\n\telsif l>q\n\t\tputs 0\n\telse\n\t\tputs 1\n\tend\n}\n"}, {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.odd? && j < n ? 1 : 0\n}\n\n"}, {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.odd? && j < n ? 1 : 0\n}\n"}, {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.odd? && j < n ? 1 : 0\n}\n\n"}, {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.odd? && j < n ? 1 : 0\n}\n\n"}, {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.odd? && j < n ? 1 : 0\n}\n"}, {"source_code": "n,m=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i)\naa,aaa=a.count(1),a.count(-1)\nm.times do\n\tl,r=gets.chomp.split.map(&:to_i)\n\tx=a[l-1..r-1]\n\tlen=x.length\n\tputs (len.even? && 2*aa>=len && 2*aaa>=len)? \"1\" : \"0\"\nend"}, {"source_code": "n, m = gets.split(' ').map { |i| i.to_i }\na = b = 0\ngets.split(' ').map {|i|\n i = i.to_i\n a += 1 if i == 1\n b += 1 if i == -1\n}\nm.times do\n l, r = gets.split(' ').map { |i| i.to_i}\n width = r - l + 1\n if width % 2 != 0 or (width / 2 > a or width / 2 > b)\n puts 0\n else\n puts 1\n end\nend"}, {"source_code": "n, m = gets.split(' ').map { |i| i.to_i }\na = b = 0\ngets.split(' ').map {|i| i.to_i == 1 ? a += 1 : b += 1}\nm.times do\n l, r = gets.split(' ').map { |i| i.to_i}\n width = r - l + 1\n puts (width % 2 != 0 or (width / 2 > a or width / 2 > b)) ? 0 : 1\nend"}, {"source_code": "def run\n n, m = $stdin.gets.split.map(&:to_i)\n a = $stdin.gets.split.map(&:to_i)\n\n plus = a.count {|x| x > 0 }\n minus = n - plus\n $stdin.readlines.each do |line|\n l, r = line.split.map(&:to_i)\n len = r - l + 1\n\n if len % 2 == 0 and plus*2 >= len and minus*2 >= len\n puts \"1\"\n else\n puts \"0\"\n end\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "class A\n def initialize\n n, m = gets.chomp.split(' ').map(&:to_i)\n\n array = gets.chomp.split(' ').map(&:to_i)\n\n query = []\n\n m.times do\n query << gets.chomp.split(' ').map(&:to_i)\n end\n\n mc = array.count(-1)\n pc = array.count(1)\n\n query.each do |q|\n size = q[1] - q[0] + 1\n\n if(size.even? && size > 1 && size/2 <= mc && size/2 <= pc)\n puts 1\n else\n puts 0\n end\n end\n end\nend\n\na = A.new"}, {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.odd? && j < n ? 1 : 0\n}\n\n"}, {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.odd? && j < n ? 1 : 0\n}"}, {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.odd? && j < n ? 1 : 0\n}\n\n"}, {"source_code": "# def query(l,r)\n# ele = r - l + 1\n# return false if ele.odd?\n# val = ele / 2\n# return true if val <= @one_count && val <= @minus_count\n# return false\n# end\n\nn,m = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n@one_count = arr.count(1)\n@minus_count = n - @one_count\nans = []\nm.times do\n\tl,r = gets.split(\" \")\n\tl = l.to_i\n\tr = r.to_i\n\tele = r - l + 1\n\tif ele.odd?\n \t\tans << \"0\"\n \t\tnext \n \tend\n \tval = ele / 2\n \tif val <= @one_count && val <= @minus_count\n \t\tans << \"1\"\n \t\tnext \n \tend\n \tans << \"0\"\nend\n\nans.each do |a|\n\tputs a\nend\n\n\n#Good http://codeforces.com/contest/302/problem/A\n# From TLE to 811 ms\n# Appending to array and iterating and displaying result is way faster than puts result directly around 100 ms diff\n# Removed the method calls\n# removed boolean checks\n# Removed the map and did to_i directly for l and r \n# Directly appended string to answer - there will be a to_s call for puts that cost from 889 to 811 the fuck"}, {"source_code": "# def query(l,r)\n# ele = r - l + 1\n# return false if ele.odd?\n# val = ele / 2\n# return true if val <= @one_count && val <= @minus_count\n# return false\n# end\n\nn,m = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n@one_count = arr.count(1)\n@minus_count = n - @one_count\nans = []\nm.times do\n\tl,r = gets.split(\" \")\n\tl = l.to_i\n\tr = r.to_i\n\tele = r - l + 1\n\tif ele.odd?\n \t\tputs \"0\"\n \t\tnext \n \tend\n \tval = ele / 2\n \tif val <= @one_count && val <= @minus_count\n \t\tputs \"1\"\n \t\tnext \n \tend\n \tputs \"0\"\nend\n\n# ans.each do |a|\n# \tputs a\n# end\n\n\n#Good http://codeforces.com/contest/302/problem/A\n# From TLE to 811 ms\n# Removed the method calls\n# removed boolean checks\n# Removed the map and did to_i directly for l and r \n# Directly appended string to answer - there will be a to_s call for puts that cost from 889 to 811 the fuck"}, {"source_code": "# def query(l,r)\n# ele = r - l + 1\n# return false if ele.odd?\n# val = ele / 2\n# return true if val <= @one_count && val <= @minus_count\n# return false\n# end\n\nn,m = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n@one_count = arr.count(1)\n@minus_count = n - @one_count\nans = []\nm.times do\n\tl,r = gets.split(\" \").map(&:to_i)\n\tele = r - l + 1\n\tif ele.odd?\n \t\tans << false\n \t\tnext \n \tend\n \tval = ele / 2\n \tif val <= @one_count && val <= @minus_count\n \t\tans << true\n \t\tnext \n \tend\n \tans << false\nend\n\nans.each do |a|\n\tputs a ? 1 : 0\nend"}, {"source_code": "# def query(l,r)\n# ele = r - l + 1\n# return false if ele.odd?\n# val = ele / 2\n# return true if val <= @one_count && val <= @minus_count\n# return false\n# end\n\nn,m = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n@one_count = arr.count(1)\n@minus_count = n - @one_count\nans = []\nm.times do\n\tl,r = gets.split(\" \")\n\tl = l.to_i\n\tr = r.to_i\n\tele = r - l + 1\n\tif ele.odd?\n \t\tans << \"0\"\n \t\tnext \n \tend\n \tval = ele / 2\n \tif val <= @one_count && val <= @minus_count\n \t\tans << \"1\"\n \t\tnext \n \tend\n \tans << \"0\"\nend\n\nans.each do |a|\n\tputs a\nend"}, {"source_code": "# def query(l,r)\n# ele = r - l + 1\n# return false if ele.odd?\n# val = ele / 2\n# return true if val <= @one_count && val <= @minus_count\n# return false\n# end\n\nn,m = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n@one_count = arr.count(1)\n@minus_count = n - @one_count\nans = []\nm.times do\n\tl,r = gets.split(\" \")\n\tl = l.to_i\n\tr = r.to_i\n\tele = r - l + 1\n\tif ele.odd?\n \t\tans << 0\n \t\tnext \n \tend\n \tval = ele / 2\n \tif val <= @one_count && val <= @minus_count\n \t\tans << 1\n \t\tnext \n \tend\n \tans << 0\nend\n\nans.each do |a|\n\tputs a\nend"}], "negative_code": [{"source_code": "puts readlines[2..-1].map{|i| i.split.map(&:to_i).inject(&:-) % 2}\n"}, {"source_code": "_, a, *q = readlines.map{|i| i.split.map(&:to_i)}\nn = 2 * [a.count(1), a.count(-1)].min\nputs q.map{|i, j|\n j -= i\n j.even? && j <= n ? 1 : 0\n}\n"}, {"source_code": "n,m=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i)\naa,aaa=a.count(1),a.count(-1)\nm.times do\n\tl,r=gets.chomp.split.map(&:to_i)\n\tx=a[l-1..r-1]\n\tlen=x.length\n\tputs(len.even? && 2*aa>=len && 2*aaa>=x.length)? \"1\" : \"0\"\nend"}, {"source_code": "n,m=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i)\nm.times do\n\tl,r=gets.chomp.split.map(&:to_i)\n\tx=a[l-1..r-1]\n\tputs (x.length.even? && 2*a.count(1)>=x.length && 2*a.count(1)>=x.length)? \"1\" : \"0\"\nend"}, {"source_code": "n,m=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i)\nm.times do\n\tl,r=gets.chomp.split.map(&:to_i)\n\tx=a[l-1..r-1]\n\tputs (x.length.even? && 2*x.count(1)>=x.length && 2*x.count(1)>=x.length)? \"1\" : \"0\"\nend"}, {"source_code": "class A\n def initialize\n n, m = gets.chomp.split(' ').map(&:to_i)\n\n array = gets.chomp.split(' ').map(&:to_i)\n\n query = []\n\n m.times do\n query << gets.chomp.split(' ').map(&:to_i)\n end\n\n query.each do |q|\n if array[(q[0]-1)..(q[1]-1)].inject(:+) == 0\n puts 1\n else\n puts 0\n end\n end\n end\nend\n\na = A.new"}, {"source_code": "\n\nn,m = gets.strip.split(' ').map {|x| x.to_i}\na = gets.strip.split(' ')\nh = Hash.new 0\na.each do |e|\n h[e] += 1\nend\np h\n\n(0...m).to_a.map do\n l, r = gets.strip.split(' ').map {|x| x.to_i}\n if( (l+r)%2 == 0)\n puts 0\n else\n k = ((r-l).abs+1)/2\n puts( (h.values.min >= k) ? 1 : 0 )\n end\nend"}, {"source_code": "\n\nn,m = gets.strip.split(' ').map {|x| x.to_i}\na = gets.strip.split(' ')\nh = Hash.new 0\na.each do |e|\n h[e] += 1\nend\n\n(0...m).to_a.map do\n l, r = gets.strip.split(' ').map {|x| x.to_i}\n if( (l+r)%2 == 0)\n puts 0\n else\n k = ((r-l).abs+1)/2\n puts( (h.values.min >= k) ? 1 : 0 )\n end\nend"}, {"source_code": "\n\nn,m = gets.strip.split(' ').map {|x| x.to_i}\na = gets.strip.split(' ')\nh = Hash.new 0\na.each do |e|\n h[e] += 1\nend\n\n(0...m).to_a.map do\n l, r = gets.strip.split(' ').map {|x| x.to_i}\n if( (l+r)%2 == 0)\n puts 0\n else\n k = (r-l+1)/2\n puts( (h.values.min >= k) ? 1 : 0 )\n end\nend"}, {"source_code": "n_m = gets.split.map { |i| i.to_i }\nn = n_m[0]\nm = n_m[1]\n\na = gets.split.map { |i| i.to_i }\n\nfor i in 1..m\n from_to = gets.split.map { |i| i.to_i }\n from = from_to[0]\n to = from_to[1]\n\n sum = 0\n for j in from..to\n sum += a[j-1]\n end\n if sum == 0\n puts 1\n else\n puts 0\n end\nend\n"}, {"source_code": "n, m = gets.chomp.split(' ').collect{|item| item.to_i}\na = gets.chomp.split(' ').collect{|item| item.to_i }\na1 = a.count{|item| item == -1}\na2 = a.length - a1\nputs m\nfor i in 1..m\n l, r = gets.chomp.split(' ').collect{|item| item.to_i}\n numbers = r - l + 1\n if numbers % 2 == 0\n if a1 >= numbers / 2 and a2 >= numbers / 2\n puts 1\n else \n puts 0\n end\n else\n puts 0\n end\nend"}, {"source_code": "n, m = gets.chomp.split(' ').collect{|item| item.to_i}\na = gets.chomp.split(' ').collect{|item| item.to_i }\na1 = a.count{|item| item == -1}\na2 = a.length - a1\nfor i in 1..m\n l, r = gets.chomp.split(' ').collect{|item| item.to_i}\n numbers = r - l + 1\n if numbers % 2 == 0\n puts 1 if a1 >= numbers / 2 and a2 >= numbers / 2\n else\n puts 0\n end\nend"}], "src_uid": "deeb49969ac4bc4f1c7d76b89ac1402f"} {"source_code": "dp = [0];\nfor i in 1..2001\n\tdp[i] = -1\nend\n\nn = gets.to_i\n\nfor i in 1..n\n\tt, x = gets.split(' ')\n\tx = x.to_i + 1\n\tif t == 'sell' && dp[x] >= 0\n\t\tdp[0] = [dp[0], dp[x] + 2**(x-1)].max\n\telse\n\t\tdp[x] = dp[0]\n\tend\nend\n\nputs dp[0]", "positive_code": [{"source_code": "dp = [0]\nfor i in 1..2001\n dp[i] = -1\nend\nn = STDIN.gets.to_i\n\nfor i in 1..n\n data = STDIN.gets.split(' ')\n s = data[0]\n t = data[1].to_i + 1\n if s == \"sell\"\n if dp[t] >= 0 && dp[t] + 2 ** (t-1) > dp[0]\n dp[0] = dp[t] + 2 ** (t-1)\n end\n else\n dp[t] = dp[0]\n end\nend\n\nputs dp[0]\n"}, {"source_code": "def read\n\ta, b = gets.split\n\ta == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn = gets.to_i\nn.times{$* << read}\nans = 0\n$*.reject{|i| i >= 0}.sort.each do |x|\n\tnext unless b = $*.index(x)\n\tnext unless a = $*[0 .. b].rindex(-1 - x)\n\tnext unless $*[a..b].all?\t# WA5\n\tans += 2 ** (-1 - x)\n\t$*[a..b] = [nil]\nend\np ans\n"}, {"source_code": "n = gets.to_i\nx = Array.new(n, -1)\ndp = Array.new(n, 0)\n(0 .. n - 1).each do |i|\n\ta, b = gets.split\n\tb = b.to_i\n\tdp[i] = dp[i - 1] if i > 0\n\tif a == 'win' then\n\t\tx[i] = b\n\telse\n\t\t(0 .. i - 1).each do |j|\n\t\t\tdp[i] = [dp[i], dp[j] + (1 << b)].max if x[j] == b\n\t\tend\n\tend\nend\np dp[-1]\n\n__END__\ndef read\n\ta, b = gets.split\n\ta == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn, s, a = gets.to_i, 0, []\nn.times{a << read}\na.reject{|i| i >= 0}.sort.each do |x|\n\tnext unless t = a.index(x)\n\tnext unless f = a[0 .. t].rindex(-1 - x)\n\ts += 1 << -1 - x\n\ta.slice!(f .. t)\nend\np s\n\nWA5: test data error?\n"}], "negative_code": [{"source_code": "def read\n\ta, b = gets.split\n\ta == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn, s, a = gets.to_i, 10000000000000000000, []\nn.times{a << read}\na.reject{|i| i >= 0}.sort.each do |x|\n\tnext unless t = a.index(x)\n\tnext unless f = a[0 .. t].rindex(-1 - x)\n\ts += 1 << -1 - x\n\ta.slice!(f .. t)\nend\np s - 10000000000000000000\n"}, {"source_code": "def read\n a, b = gets.split\n a == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn, s, a = gets.to_i, 0, []\nn.times{a << read}\ng = a.reject{|i| i >= 0}.sort\ng.each do |x|\n next if (t = a.index(x)).nil?\n next if (f = a[0 .. t].rindex(-1 - x)).nil?\n s += 1 << -1 - x\n a.slice!(f .. t)\nend\np s\n"}, {"source_code": "def read\n\ta, b = gets.split\n\ta == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn = gets.to_i\nn.times{$* << read}\nans = 0\n$*.reject{|i| i >= 0}.sort.each do |x|\n\tnext unless b = $*.index(x)\n\tnext unless a = $*[0 .. b].rindex(-1 - x)\n\tans += 2 ** (-1 - x)\n\t$*.slice!(a, b - a)\nend\np ans\n"}, {"source_code": "def read\n a, b = gets.split\n a == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn, s, a = gets.to_i, 0, []\nn.times{a << read}\nt = a.reject{|i| i >= 0}.sort\nt.each do |x|\n next if (t = a.index(x)).nil?\n next if (f = a[0 .. t].rindex(-1 - x)).nil?\n s += 1 << -1 - x\n a.slice!(f .. t)\nend\np s\n"}, {"source_code": "def read\n a, b = gets.split\n a == 'win' ? -1 - b.to_i : b.to_i\nend\n\nn, s, a = gets.to_i, 0, []\nn.times{a << read}\na.reject{|i| i < 0}.sort.reverse.each do |x|\n next unless t = a.rindex(x)\n next unless f = a[0 .. t].rindex(-1 - x)\n s += 1 << x\n a.slice!(f .. t)\nend\np s\n"}, {"source_code": "def read\n a, b = gets.split\n a == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn, s, a = gets.to_i, 0, []\nn.times{a << read}\na.reject{|i| i >= 0}.sort.each do |x|\n next unless t = a.index(x)\n raise Exception.new() if a.index(x) != a.rindex(x)\n next unless f = a[0 .. t].rindex(-1 - x)\n s += 1 << -1 - x\n a.slice!(f .. t)\nend\np s\n"}, {"source_code": "def read\n a, b = gets.split\n a == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn, s, a = gets.to_i, 0, []\nn.times{a << read}\na.reject{|i| i >= 0}.sort.each do |x|\n next if (t = a.index(x)).nil?\n next if (f = a[0 .. t].rindex(-1 - x)).nil?\n s += 1 << -1 - x\n a.slice!(f .. t)\nend\np s\n"}, {"source_code": "def read\n\ta, b = gets.split\n\ta == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn = gets.to_i\na = []\nn.times{a << read}\ns = 0\na.reject{|i| i >= 0}.sort.each do |x|\n\tnext unless t = a.index(x)\n\tnext unless f = a[0 .. t].rindex(-1 - x)\n\ts += 2 ** (-1 - x)\n\ta.slice!(f .. t)\nend\nputs s\n"}, {"source_code": "def read\n a, b = gets.split\n a == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn, s, a = gets.to_i, 0, []\nn.times{a << read}\nraise Exception.new() if a.reject{|i| i >= 0}.sort.uniq!\na.reject{|i| i >= 0}.sort.each do |x|\n next unless t = a.index(x)\n next unless f = a[0 .. t].rindex(-1 - x)\n s += 1 << -1 - x\n a.slice!(f .. t)\nend\np s\n"}, {"source_code": "def read\n a, b = gets.split\n a == 'win' ? -1 - b.to_i : b.to_i\nend\n\nn, s, a = gets.to_i, 0, []\nn.times{a << read}\na.reject{|i| i < 0}.sort.each do |x|\n next unless t = a.index(x)\n next unless f = a[0 .. t].rindex(-1 - x)\n s += 1 << x\n a.slice!(f .. t)\nend\np s\n"}, {"source_code": "def read\n a, b = gets.split\n a == 'win' ? -1 - b.to_i : b.to_i\nend\n\nn, s, a = gets.to_i, 0, []\nn.times{a << read}\na.reject{|i| i < 0}.sort.reverse.each do |x|\n next unless t = a.index(x)\n next unless f = a[0 .. t].rindex(-1 - x)\n s += 1 << x\n a.slice!(f .. t)\nend\np s\n"}, {"source_code": "def read\n\ta, b = gets.split\n\ta == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn = gets.to_i\nn.times{$* << read}\nans = 0\n$*.reject{|i| i >= 0}.sort.each do |x|\n\tnext unless b = $*.index(x)\n\tnext unless a = $*[0 .. b].rindex(-1 - x)\n\tans += 2 ** (-1 - x)\n\t$*.slice!(a .. b)\nend\np ans\n"}, {"source_code": "def read\n a, b = gets.split\n a == 'win' ? b.to_i : -1 - b.to_i\nend\n\nn, s, a = gets.to_i, 0, []\nn.times{a << read}\na.reject{|i| i >= 0}.sort.each do |x|\n next unless t = a.index(x)\n next unless f = a[0 .. t].rindex(-1 - x)\n s += 1 << -1 - x\n a[f .. t] = nil\nend\np s\n"}], "src_uid": "217a3a48b927213f4d5e0a19048e2a32"} {"source_code": "n, c = gets.split.map{|x| x.to_i}\nputs(gets.split.map{|x| x.to_i}.inject([0, 0]){|s, x| [x - s[1] <= c ? s[0] + 1 : 1, x]}[0])\n", "positive_code": [{"source_code": "a,b=gets.split.map &:to_i\nk=1\nm=gets.split\na.times{|x|\nm[a-x-1].to_i-m[a-x-2].to_i>b ? break : k+=1}\n$><<[k,a].min"}, {"source_code": "n, c = gets.split.map &:to_i\na = gets.split.map &:to_i\nans = 1\n(1...n).each do |i|\n if a[i] - a[i - 1] > c\n ans = 1\n else\n ans += 1\n end\nend\nputs ans"}, {"source_code": "#!/usr/bin/ruby\nn,c,*a=$<.read.split.map(&:to_i)\nr=1\na.each_cons(2){|x,y|\n\tif y-x>c\n\t\tr=1\n\telse\n\t\tr+=1\n\tend\n}\np r"}, {"source_code": "a,b=gets.split.map &:to_i\nk=1\nm=gets.split\na.times{|x|\nm[a-x-1].to_i-m[a-x-2].to_i>b ? break : k+=1}\n$><<[k,a].min"}, {"source_code": "n,c = gets.split.map(&:to_i)\nmas = gets.split.map(&:to_i)\n\nans = 1\nfor i in 1...mas.size() do\n if(mas[i]-mas[i-1] <= c)\n ans+=1;\n else\n ans = 1;\n end\nend\n\nputs ans;\n"}, {"source_code": "n, c = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i).reverse\n\nlast = a.first\ncount = 0\na.each do |d|\n if last - d <= c\n count += 1\n last = d\n else\n break\n end\nend\nputs count\n"}, {"source_code": "\nc = gets.chop.split(' ').map{ |x| x.to_i }[1]\n\nt = gets.chop.split(' ').map{ |x| x.to_i }\n\ncount = 1\n\ni = t.size - 1\n\nwhile i != 0\n break if t[i] - c > t[i - 1]\n count += 1\n i -= 1;\nend\n\n\nprint count\n"}, {"source_code": "n, c = gets.split.map{|x| x.to_i}\n\ntimes = gets.split.map{|x| x.to_i}\n\nwords = 0\nprevtime = 0\nfor sec in times\n if (sec - prevtime) > c\n words = 1\n else\n words += 1\n end\n prevtime = sec\nend\n\nputs words\n"}, {"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n args = line.split(\" \")\n @n = Integer(args[0])\n @c = Integer(args[1])\n when 1\n @arr = line.split(\" \")\n @arr = @arr.map{ |i| i = Integer(i) }\n @arr.reverse!\n puts getScreen()\n #@arr.sort!\n when 2\n \n else\n\n end\n end\n end\n \n def getScreen()\n rtn = 1\n @arr.each_with_index do |e,i|\n if i + 1 < @n\n if e - @arr[i+1] > @c\n rtn = i + 1\n break\n end\n if i + 1 == @n - 1 \n rtn = @n\n end\n end\n end\n return rtn\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "n, c = gets.split.map(&:to_i)\nts = gets.split.map(&:to_i)\n\nans = 1\n(n-1).downto(1) do |i|\n b = ts[i]\n a = ts[i-1]\n if b - a <= c\n ans += 1\n else\n break\n end\nend\nputs ans"}, {"source_code": "n, c = gets.strip.split.map(&:to_i)\nt = gets.strip.split.map(&:to_i)\na = t[0]\nwords = 1\n(1...n).each do |i|\n b = t[i]\n if b - a <= c\n words += 1\n else\n words = 1\n end\n a = b\nend\nputs words\n"}, {"source_code": "n,c=gets.split.map{|e| e.to_i}\nx=gets.split.reverse.map{|e| e.to_i}\nans=1\nwhile x.size>1\n\tif x[0]-x[1]>c then\n\t\tbreak\n\tend\n\tans+=1\n\tx.shift\nend\nputs ans\n\n"}, {"source_code": "n,c = gets.split.map(&:to_i)\nt = gets.split.map(&:to_i)\nr = 1\n(n - 1).downto(1) do |i|\n\tif t[i] - t[i - 1] <= c\n\t\tr += 1\n\telse\n\t\tbreak\n\tend\nend\np r"}, {"source_code": "total, dist = gets.split(' ').map(&:to_i)\nats = gets.split(' ').map(&:to_i)\n\nnext_at = ats.last\ncount = 0\nats.reverse_each do |at|\n if next_at - at <= dist\n count += 1\n else\n break\n end\n next_at = at\nend\n\nputs count\n"}, {"source_code": "n, c=gets.split.map &:to_i\nt=gets.split.map &:to_i\n\nres=0\nx=t[0]\nt.each {|i|\n if i-x<=c\n res+=1\n else\n res=1\n end\n x=i\n}\np res\n"}, {"source_code": "n,c,a=gets.split.map(&:to_i)<<1\ngets.split.map(&:to_i).each_cons(2){|x,y|a=(y-x>c)?1:a+1}\np a"}, {"source_code": "n,c=gets.split.map(&:to_i)\ncnt=1\ngets.split.map(&:to_i).each_cons(2) do|x,y|\n cnt+=1\n cnt=1 if y-x>c\nend\np cnt"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn, c = gets.split.map(&:to_i)\nwords = 0\nlast_words_spent = 0\ngets.split.each { |i|\n i = i.to_i\n if (i - last_words_spent) > c\n words = 1\n else\n words += 1\n end\n last_words_spent = i\n}\n\nputs words"}, {"source_code": "# be name khoda ...\ndef read_ints; STDIN.gets.split.map(&:to_i); end\nn, c = read_ints\na = read_ints\nres = 1\ni = 0\n(n-1).times do\n if(a[i]+c < a[i+1])\n res = 1\n else\n res +=1\n end\n i+=1\nend\nputs res"}, {"source_code": "input_values = gets.chomp\nin_val = input_values.split(' ').map(&:to_i)\ntotal_input = in_val[0]\ncons_value = in_val[1]\nstring_input = gets.chomp\narray = string_input.split(' ').map(&:to_i)\ni = 1\ncount = 1\nwhile i < total_input do\n\tif array[i]-array[i-1] <= cons_value\n\t\tcount += 1\n\telse\n\t count = 1\n\tend\n\ti += 1\nend\nputs count"}, {"source_code": "n, c = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nk = 0\np = 0\na.each do |x|\n k += 1\n k = 1 if x-p>c\n p = x\nend\n\nputs k\n"}, {"source_code": "n, c = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = 1\nn.times do |i|\n if a[i] - a[i - 1] > c || i == 0\n ans = 1\n else\n ans += 1\n end\nend\nputs ans\n\n"}, {"source_code": "n, c = gets.split.map(&:to_i)\nt = gets.split.map(&:to_i)\nans = 1\n1.upto(n - 1){|i|\n if t[i] - t[i - 1] > c\n ans = 1\n else\n ans += 1\n end\n }\np ans"}, {"source_code": "typeNum, delay = gets.chomp.split(' ').map(&:to_i)\ninputs = gets.chomp.split(' ').map(&:to_i)\n\nchar = 1\n\nfor i in (1...(inputs.length))\n\tdiff = inputs[i] - inputs[i - 1]\n\tchar = 1 if diff > delay\n\tchar += 1 if diff <= delay\nend\n\nputs char"}], "negative_code": [{"source_code": "a,b=gets.split.map &:to_i\nk=1\nm=gets.split\na.times{|x|\nm[a-x-1].to_i-m[a-x-2].to_i<=b ? k+=1 : break}\n$><= c\n words = 2\n else\n words += 1\n end\n prevtime = sec\nend\n\nputs words\n"}, {"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n args = line.split(\" \")\n @n = Integer(args[0])\n @c = Integer(args[1])\n when 1\n @arr = line.split(\" \")\n @arr = @arr.map{ |i| i = Integer(i) }\n @arr.reverse!\n puts getScreen()\n #@arr.sort!\n when 2\n \n else\n\n end\n end\n end\n \n def getScreen()\n rtn = 1\n @arr.each_with_index do |e,i|\n if i + 1 < @n\n if e - @arr[i+1] > @c\n rtn = i + 1\n break\n end\n end\n end\n return rtn\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n args = line.split(\" \")\n @n = Integer(args[0])\n @c = Integer(args[1])\n when 1\n @arr = line.split(\" \")\n @arr = @arr.map{ |i| i = Integer(i) }\n @arr.reverse!\n puts getScreen()\n #@arr.sort!\n when 2\n \n else\n\n end\n end\n end\n \n def getScreen()\n rtn = 1\n @arr.each_with_index do |e,i|\n if i + 1 < @n\n if e - @arr[i+1] > @c\n rtn = i + 1\n break\n end\n if i == @n - 1 \n rtn = @n\n end\n end\n end\n return rtn\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n args = line.split(\" \")\n @n = Integer(args[0])\n @c = Integer(args[1])\n when 1\n @arr = line.split(\" \")\n @arr = @arr.map{ |i| i = Integer(i) }\n @arr.reverse!\n puts getScreen()\n #@arr.sort!\n when 2\n \n else\n\n end\n end\n end\n \n def getScreen()\n rtn = 0\n @arr.each_with_index do |e,i|\n if i + 1 < @n\n if e - @arr[i+1] > @c\n rtn = i + 1\n break\n end\n end\n end\n return rtn\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "total, dist = gets.split(' ').map(&:to_i)\nats = gets.split(' ').map(&:to_i)\n\nnext_at = ats.last\ncount = 0\nats.reverse_each do |at|\n if next_at - at <= dist\n count += 1\n end\n next_at = at\nend\n\nputs count\n"}, {"source_code": "input_values = gets.chomp\nin_val = input_values.split(' ').map(&:to_i)\ntotal_input = in_val[0]\ncons_value = in_val[1]\nstring_input = gets.chomp\narray = string_input.split(' ').map(&:to_i)\ni = 1\ncount = 0\nwhile i < total_input do\n\tif array[i]-array[i-1] <= cons_value\n\t\tcount += 1\n\telse\n\t count = 1\n\tend\n\ti += 1\nend\nputs count\n\n\n\n"}, {"source_code": "n, c = gets.split.map(&:to_i)\nt = gets.split.map(&:to_i)\nans = 0\ntmp = 1\n1.upto(n - 1){|i|\n if t[i] - t[i - 1] > c\n ans = [ans, tmp].max\n tmp = 1\n else\n tmp += 1\n end\n }\nans = [ans, tmp].max\np ans"}], "src_uid": "fb58bc3be4a7a78bdc001298d35c6b21"} {"source_code": "require 'set'\n\ndef fn(aa, d)\n out = []\n ret = 0\n for e in aa\n n = e % d\n if (n != 0) \n out << n \n else\n ret = 1\n end\n end\n r = out.tally\n \n for k,v in r\n if k + k == d\n ret += 1\n next\n end\n if v == 0; next; end\n \n j = d - k\n r[k] = 0\n vj = r[j]\n if vj\n r[j] = 0\n if vj >= v+1\n ret += 1\n ret += vj - (v+1)\n # printf(\"j:%d k:%d > ret:%d\\n\",k,j,ret)\n elsif vj == v \n ret += 1\n # printf(\"k:%d j:%d == ret:%d\\n\",k,j,ret)\n else\n ret += 1\n ret += v - (vj+1)\n # printf(\"k:%d j:%d < ret:%d\\n\",k,j,ret)\n end\n else\n ret += v\n # printf(\"j:%d ret:%d\\n\",k,ret);\n end\n\n end\n puts ret\nend\n\ntt = gets.to_i\ntt.times {\n (_, d)= gets.chomp!.split(' ').map &:to_i\n aa = gets.chomp!.split(' ').map &:to_i\n fn(aa,d)\n}\n\n\t \t\t \t \t\t\t\t\t \t\t \t\t \t", "positive_code": [{"source_code": "t = gets.chomp.to_i\r\nfor test in (1..t)\r\n n, m = gets.chomp.split(' ').map { |x| x.to_i }\r\n a = gets.chomp.split(' ').map { |x| x.to_i }\r\n r = Array.new(m).fill(0)\r\n for i in (0..n-1)\r\n r[a[i] % m] += 1\r\n end\r\n ans = 0\r\n for i in (1..m/2)\r\n if r[i] == r[m - i]\r\n if r[i] > 0\r\n ans += 1\r\n end\r\n elsif r[i] == 0 && r[m - i] != 0\r\n ans += r[m - i]\r\n elsif r[i] != 0 && r[m - i] == 0\r\n ans += r[i]\r\n else\r\n ans += 1 + [0, (r[i] - r[m - i]).abs - 1].max\r\n end\r\n end\r\n if r[0] != 0\r\n ans += 1\r\n end\r\n puts ans\r\nend\r\n"}, {"source_code": "gets.to_i.times {\n n, m = gets.split(' ').map(&:to_i)\n xs = gets.split(' ').map(&:to_i)\n\n groups = Array.new(m) { [] }\n xs.each do |el|\n groups[el % m].push(el)\n end\n\n res = 0\n if groups[0].size > 0\n res += 1\n end\n if m % 2 == 0 && groups[m / 2].size > 0\n res += 1\n end\n (1..((m - 1) / 2)).each do |rem|\n min = [groups[rem].size, groups[m - rem].size].min\n max = [groups[rem].size, groups[m - rem].size].max\n if min == 0\n res += max\n elsif min == max\n res += 1\n else\n res += (max - min)\n end\n end\n puts res\n}\n"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\r\nfor test in (1..t)\r\n n, m = gets.chomp.split(' ').map { |x| x.to_i }\r\n a = gets.chomp.split(' ').map { |x| x.to_i }\r\n r = Array.new(m).fill(0)\r\n for i in (0..n-1)\r\n r[a[i] % m] += 1\r\n end\r\n z = 0\r\n for i in (1..(m-1)/2)\r\n y = [r[i], r[m - i]].min * 2 + 1\r\n z += 1 + [0, r[i] + r[m - i] - y].max\r\n end\r\n if r[0] != 0\r\n z += 1\r\n end\r\n if m % 2 == 0 && r[m / 2] != 0\r\n z += 1\r\n end\r\n puts z\r\nend\r\n"}], "src_uid": "d107db1395ded62904d0adff164e5c1e"} {"source_code": "t = gets.to_i\nt.times do\n\tn,k = gets.split.map(&:to_i)\n\ta = gets.split.map(&:to_i)\n\tb = gets.split.map(&:to_i)\n\tsum = a.sum\n\ta.sort!\n\tb.sort!.reverse!\n\tfor i in 0...k\n\t\tsum += b[i] - a[i] if b[i] > a[i]\n\tend\n\tputs sum\nend\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do |testcase|\n (n,k) = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n b = gets.split.map(&:to_i)\n a = a.sort;a = a.reverse;b = b.sort\n #print a ; print \"\\n\"\n a_ptr = -1 ; b_ptr = -1\n while k>0\n if b[b_ptr] >= a[a_ptr]\n a[a_ptr] = b[b_ptr]\n a_ptr-=1 ; b_ptr-=1\n end\n k-=1\n end\n res = 0\n a.each do |num|\n res += num\n end\n puts res\nend"}, {"source_code": "1.upto(gets.to_i) do\n n, k = gets.split(' ').map(&:to_i)\n\n a = gets.split(' ').map(&:to_i).sort\n b = gets.split(' ').map(&:to_i).sort.reverse\n\n result = a.inject(&:+)\n \n a[0, k].zip(b[0, k]).each do |x|\n break if x.first >= x.last\n\n result += x.last - x.first\n end\n\n puts result\nend\n"}, {"source_code": "gets.to_i.times do\n\tn, k = gets.split.map(&:to_i)\n\ta = gets.split.map(&:to_i).sort\n\tb = gets.split.map(&:to_i).sort.reverse\n\tputs (0...k).sum { |i| [a[i], b[i]].max } + (k...n).sum { |i| a[i] }\nend\n"}], "negative_code": [], "src_uid": "7c2337c1575b4a62e062fc9990c0b098"} {"source_code": "p = readline.chomp.rjust(10**6, \"0\")\n#puts p\nq = readline.chomp.rjust(10**6, \"0\")\n#puts q\nif p == q\n puts(\"=\")\nelsif p < q\n puts(\"<\")\nelse\n puts(\">\")\nend", "positive_code": [{"source_code": "a,b=$<.map{|x|x.chomp.sub(/^0+/,'')}\nputs '=><'[(a.size<=>b.size)!=0 ? a.size<=>b.size : a<=>b]"}, {"source_code": "a = gets.strip\nb = gets.strip\n\nif a.size > b.size\n b = (\"0\" * (a.size - b.size)).concat(b)\nelsif b.size > a.size\n a = (\"0\" * (b.size - a.size)).concat(a)\nend\n\n0.upto(a.size-1) do |shift|\n if a[shift] > b[shift]\n puts(\">\")\n exit\n end\n if a[shift] < b[shift]\n puts(\"<\")\n exit\n end\nend\n\nputs \"=\""}, {"source_code": "a=gets.to_i\nb=gets.to_i\nif ab\n puts\">\"\nelse\n puts\"=\"\nend"}, {"source_code": "a = gets.chomp\nb = gets.chomp\na = a[1..-1] while a[0] == '0'\nb = b[1..-1] while b[0] == '0'\nputs \">\" if a.length > b.length\nputs \"<\" if a.length < b.length\nexit unless a.length == b.length\n\n(0..a.length - 1).each do |i|\n puts \"<\" if a[i] < b[i]\n puts \">\" if a[i] > b[i]\n exit unless a[i] == b[i]\nend\nputs \"=\"\n"}, {"source_code": "a,b=$<.map{|e|e.chomp.sub(/^0+/,'')}\nputs '=><'[(a.size<=>b.size)!=0 ? a.size<=>b.size : a<=>b]"}, {"source_code": "a = gets.chomp\nb = gets.chomp\nwhile a[0] == '0'\n a = a[1..-1]\nend\nwhile b[0] == '0'\n b = b[1..-1]\nend\nif a.length > b.length\n puts \">\"\n exit\nend\nif a.length < b.length\n puts \"<\"\n exit\nend\n\n(0..a.length - 1).each do |i|\n if a[i] < b[i]\n puts \"<\"\n exit\n end\n if a[i] > b[i]\n puts \">\"\n exit\n end\nend\nputs \"=\"\n"}, {"source_code": "a = gets.to_i\nb = gets.to_i\nif a < b\n puts \"<\"\nelsif a > b\n puts \">\"\nelse\n puts \"=\"\nend"}, {"source_code": "a = gets.chomp.rjust(10**6, \"0\")\nb = gets.chomp.rjust(10**6, \"0\")\nputs (a == b ? \"=\" : (a>b ? \">\" : \"<\"))\n"}, {"source_code": "a = gets.to_i\nb = gets.to_i\nif a < b\n puts \"<\"\nelsif a > b\n puts \">\"\nelse\n puts \"=\"\nend"}, {"source_code": "a = gets.to_i\nb = gets.to_i\nif a < b\n puts \"<\"\nelsif a > b\n puts \">\"\nelse\n puts \"=\"\nend"}, {"source_code": "a=gets.to_i\nb=gets.to_i\nif ab\n puts \">\"\nelse\n puts \"=\"\nend"}, {"source_code": "num1, num2 = STDIN.read.split(\"\\n\").map { |s| s.sub /^0+/,'' }\nres = case (num1.size <=> num2.size)\n\twhen 1\n\t\t'>'\n\twhen -1\n\t\t'<'\n\telse\n\t\tcase num1 <=> num2\n\t\twhen 1\n\t\t\t'>'\n\t\twhen -1\n\t\t\t'<'\n\t\telse\n\t\t\t'='\n\t\tend\nend\n\nputs res"}, {"source_code": "a = gets.chomp.rjust(10**6, \"0\")\nb = gets.chomp.rjust(10**6, \"0\")\n\nif a == b then\n puts \"=\"\nelsif a > b then\n puts \">\"\nelse\n puts \"<\"\nend"}], "negative_code": [{"source_code": "a,b=$<.map{|e|e.chomp.sub(/^0+/,'')}\nputs '=><'[(a.size<=>b.size)==0 ? a.size<=>b.size : a<=>b]"}, {"source_code": "a = gets\nb = gets\nif a > b\n puts \"<\"\nelsif a < b\n puts \">\"\nelse\n puts \"=\"\nend"}, {"source_code": "a = gets\nb = gets\nif a > b\n puts \">\"\nelsif a < b\n puts \"<\"\nelse\n puts \"=\"\nend"}, {"source_code": "a,b=$<.map{|x|x.chomp.sub(/^0+/,'')}\nputs '>=<'[(a.size<=>b.size)==0 ? a.size<=>b.size : a<=>b]"}, {"source_code": "a=gets.to_i\nb=gets.to_i\np \"=\" if a==b\np \"<\" if a\" if a>b"}, {"source_code": "a,b=$<.map{|x|x.chomp.sub(/^0+/,'')}\nputs '>=<'[(a.size<=>b.size)!=0 ? a.size<=>b.size : a<=>b]"}, {"source_code": "a = gets\nb = gets\n\nif a.size > b.size\n b = (\"0\" * (a.size - b.size)).concat(b)\nelseif b.size > a.size\n a = (\"0\" * (b.size - a.size)).concat(a)\nend\n\n0.upto(a.size-1) do |shift|\n if a[-1-shift] > b[-1-shift]\n puts(\">\")\n exit\n end\n if a[-1-shift] < b[-1-shift]\n puts(\"<\")\n exit\n end\nend\n\nputs \"=\""}, {"source_code": "a = gets\nb = gets\n\nif a.size > b.size\n b = (\"0\" * (a.size - b.size)).concat(b)\nelseif b.size > a.size\n a = (\"0\" * (b.size - a.size)).concat(a)\nend\n\n0.upto(a.size-1) do |shift|\n puts \">\" and exit if a[-1-shift] > b[-1-shift]\n puts \"<\" and exit if a[-1-shift] > b[-1-shift]\nend\n\nputs \"=\"\n"}, {"source_code": "a = gets.strip\nb = gets.strip\n\nif a.size > b.size\n b = (\"0\" * (a.size - b.size)).concat(b)\nelsif b.size > a.size\n a = (\"0\" * (b.size - a.size)).concat(a)\nend\n\n0.upto(a.size-1) do |shift|\n if a[-1-shift] > b[-1-shift]\n puts(\">\")\n exit\n end\n if a[-1-shift] < b[-1-shift]\n puts(\"<\")\n exit\n end\nend\n\nputs \"=\""}, {"source_code": "a = gets.strip\nb = gets.strip\n\nif a.size > b.size\n b = (\"0\" * (a.size - b.size)).concat(b)\nelsif b.size > a.size\n a = (\"0\" * (b.size - a.size)).concat(a)\nend\n\nputs a\nputs b\n0.upto(a.size-1) do |shift|\n if a[shift] > b[shift]\n puts(\">\")\n exit\n end\n if a[shift] < b[shift]\n puts(\"<\")\n exit\n end\nend\n\nputs \"=\""}, {"source_code": "a = gets\nb = gets\n\nif a.size > b.size\n b = (\"0\" * (a.size - b.size)).concat(b)\nelseif b.size > a.size\n a = (\"0\" * (b.size - a.size)).concat(a)\nend\n\n0.upto(a.size-1) do |shift|\n puts \">\" && exit if a[-1-shift] > b[-1-shift]\n puts \"<\" && exit if a[-1-shift] < b[-1-shift]\nend\n\nputs \"=\"\n"}, {"source_code": "a = gets.chomp\nb = gets.chomp\nwhile a[0] == '0'\n a = a[1..-1]\nend\nwhile b[0] == '0'\n b = b[1..-1]\nend\nif a.length > b.length\n puts \">\"\n exit\nend\nif a.length < b.length\n puts \"<\"\n exit\nend\n\na.length.downto 1 do |i|\n if a[i - 1] < b[i - 1]\n puts \"<\"\n exit\n end\n if a[i - 1] > b[i - 1]\n puts \">\"\n exit\n end\nend\nputs \"=\"\n"}, {"source_code": "a = gets.chomp\nb = gets.chomp\na = a[1..-1] while a[0] == '0'\nb = b[1..-1] while b[0] == '0'\np a\np b\nputs \">\" if a.length > b.length\nputs \"<\" if a.length < b.length\nexit unless a.length == b.length\n\n(0..a.length - 1).each do |i|\n puts \"<\" if a[i] < b[i]\n puts \">\" if a[i] > b[i]\n exit unless a[i] == b[i]\nend\nputs \"=\"\n"}, {"source_code": "a = gets.chomp\nb = gets.chomp\na = a[1...-1] while a[0] == '0'\nb = b[1..-1] while b[0] == '0'\nputs \">\" if a.length > b.length\nputs \"<\" if a.length < b.length\nexit unless a.length == b.length\n\n(0..a.length - 1).each do |i|\n puts \"<\" if a[i] < b[i]\n puts \">\" if a[i] > b[i]\n exit unless a[i] == b[i]\nend\nputs \"=\"\n"}], "src_uid": "fd63aeefba89bef7d16212a0d9e756cd"} {"source_code": "n = Integer( gets.chomp )\ninput = gets.chomp\nnum = input.split(\" \")\n\nn -= 1\naux = \"-1\"\ncont = 0\nflag = false\n\nwhile n>=0\n\tone = zero = 0\n\ti = 0\n\n\twhile i0\n\t\tprint \"0\"\n\t\tcont -= 1\n\tend\n\n\tprint \"\\n\"\nend\n", "positive_code": [{"source_code": "n = gets.chomp.split(\" \").map(&:to_i)\ntanks = gets.chomp.split(\" \")\n\npow = 0\nnotbeautiful = \"1\"\ntanks.each do |t|\n n1 = t.count(\"1\")\n n0 = t.count(\"0\")\n nrem = t.length - n1 - n0\n if t.length == 1 && n0 == 1 then\n puts 0\n exit\n elsif n1 != 1 or nrem != 0 then\n notbeautiful = t\n else\n pow += t.length - 1\n end\nend\nputs notbeautiful + \"0\" * pow"}, {"source_code": "def isb(s)\n ones = 0\n zero = 0\n n = false\n for i in 0...s.length do\n ones += 1 if s[i] == '1'\n zero += 1 if s[i] == '0'\n n = true if s[i] != '1' && s[i] != '0'\n end\n return ones == 1 && n == false\nend\ndef czero(s)\n zero = 0\n for i in 0...s.length do\n zero += 1 if s[i] == '0'\n end\n return zero\nend\nn = gets.to_i\np = gets.strip.split(\" \")\nans = \"\"\nze = 0\ncb = false\ncontzero = false\nfor str in p do\n contzero = true if str == \"0\"\n if isb(str)\n ze += czero(str)\n else\n cb = true\n ans << str\n end\nend\nif contzero \n puts (\"0\")\nelse\n ans << \"1\" if cb == false\n for i in 0...ze do\n ans << \"0\" \n end\n puts ans \nend"}, {"source_code": "n = gets.to_i\nas = gets.chomp.split\n\np = 1\nz = 0\nas.each do |a|\n if a == '0'\n p = 0\n z = 0\n break\n elsif a != '1' + '0' * (a.size - 1)\n p = a\n else\n z += a.size - 1\n end\nend\n\nputs p.to_s + '0' * z\n"}], "negative_code": [{"source_code": "def isb(s)\n ones = 0\n zero = 0\n n = false\n for i in 0...s.length do\n ones += 1 if s[i] == '1'\n zero += 1 if s[i] == '0'\n n = true if s[i] != '1' && s[i] != '0'\n end\n return ones == 1 && n == false\nend\ndef czero(s)\n zero = 0\n for i in 0...s.length do\n zero += 1 if s[i] == '0'\n end\n return zero\nend\nn = gets.to_i\np = gets.strip.split(\" \")\nans = \"\"\nze = 0\nfor str in p do\n if isb(str)\n ze += czero(str)\n else\n ans << str\n end\nend\nfor i in 0...ze do\n ans << \"0\" \nend\nputs ans "}, {"source_code": "def isb(s)\n ones = 0\n zero = 0\n n = false\n for i in 0...s.length do\n ones += 1 if s[i] == '1'\n zero += 1 if s[i] == '0'\n n = true if s[i] != '1' && s[i] != '0'\n end\n return ones == 1 && n == false\nend\ndef czero(s)\n zero = 0\n for i in 0...s.length do\n zero += 1 if s[i] == '0'\n end\n return zero\nend\nn = gets.to_i\np = gets.strip.split(\" \")\nans = \"\"\nze = 0\ncontzero = false\nfor str in p do\n contzero = true if str == \"0\"\n if isb(str)\n ze += czero(str)\n else\n ans << str\n end\nend\nif contzero \n puts (\"0\")\nelse\n for i in 0...ze do\n ans << \"0\" \n end\n puts ans \nend"}, {"source_code": "n = gets.chomp.split(\" \").map(&:to_i)\ntanks = gets.chomp.split(\" \")\n\npow = 0\nnotbeautiful = \"1\"\ntanks.each do |t|\n n1 = t.count(\"1\")\n n0 = t.count(\"0\")\n nrem = t.length - n1 - n0\n if n1 == 0 && n0 == 1 then\n puts 0\n exit\n elsif n1 != 1 or nrem != 0 then\n notbeautiful = t\n else\n pow += t.length - 1\n end\nend\nputs notbeautiful + \"0\" * pow"}, {"source_code": "n = Integer( gets.chomp )\ninput = gets.chomp\nnum = input.split(\" \")\n\nn -= 1\naux = \"0\"\ncont = 0\nflag = false\n\nwhile n>=0\n\tone = zero = 0\n\ti = 0\n\n\twhile i0\n\t\tprint \"0\"\n\t\tcont -= 1\n\tend\n\tprint \"\\n\"\nend\n"}], "src_uid": "9b1b082319d045cf0ec6d124f97a8184"} {"source_code": "t = gets.chomp.to_i\nt.times do\n l, r = gets.chomp.split(\" \").map(&:to_i)\n kizyun = r\n if l <= kizyun / 2\n puts \"NO\"\n else\n puts \"YES\"\n end\nend", "positive_code": [{"source_code": "gets.to_i.times do\n l, r = gets.split.map(&:to_i)\n a = r + 1\n puts(if l * 2 >= a then \"YES\" else \"NO\" end)\nend\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n l, r = gets.split.map(&:to_i)\n\n if r < 2 * l\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "gets.to_i.times do\n l, r = gets.split.map &:to_i\n puts 2 * l > r ? \"YES\" : \"NO\"\nend"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n l, r = gets.chomp.split(\" \").map(&:to_i)\n kizyun = r + 1\n if l <= kizyun / 2\n puts \"NO\"\n else\n puts \"YES\"\n end\nend"}], "src_uid": "5172d358f1d451b42efff1019219a54d"} {"source_code": "n, m = gets.split(' ').map(&:to_i)\nnode = gets.split(' ').map(&:to_i)\nmax = 0.0\nm.times do\n a, b, c = gets.split(' ').map(&:to_i)\n v = (node[a-1]+node[b-1]+0.0)/(c+0.0)\n max = v if max < v\nend\nputs max", "positive_code": [{"source_code": "n, m = gets.split.map { |i| i.to_i }\nanswer = 0.0\nweight = gets.split.map{ |i| i.to_i }\nm.times do\n\tx, y, w = gets.split.map{ |i| i.to_i }\n\tanswer = [answer, (weight[x-1] + weight[y-1]) / w.to_f].max\nend\nputs answer"}, {"source_code": "numbers = gets.split(' ')\nn = numbers[0].to_i\nm = numbers[1].to_i\n\nvalues = gets.split(' ').map { |s| s.to_f }\nbest = 0.0\nm.times do\n edge = gets.split(' ')\n a = edge[0].to_i\n b = edge[1].to_i\n edge_val = edge[2].to_f\n best = [best, (values[a - 1] + values[b - 1]) / edge_val].max\nend\n\nputs best"}, {"source_code": "n,m=gets.split.map(&:to_i)\nx=[0]+gets.split.map(&:to_f)\nr=0.0\nm.times do\n a,b,c=gets.split.map(&:to_i)\n y=(x[a]+x[b])/c\n r=y if r x\n d += 1\n else\n x -= num\n end\n end\nend\nputs [x, d].join(' ')\n", "positive_code": [{"source_code": "n,x=gets.split.map{|e| e.to_i}\nans=0\nn.times{\n\tc,a=gets.split\n\ta=a.to_i\n\tif c==\"+\" then\n\t\tx+=a\n\telse\n\t\tif x=tmp then x-=tmp\n elsif str==\"-\" and x count\n sad += 1\n next\n end\n\n count -= x\nend\n\nputs \"#{count} #{sad}\"\n"}, {"source_code": "lineNum, initial = gets.chomp.split(' ').map(&:to_i)\n\nice = initial\nchild = 0\n\nlineNum.times do\n\topCode, amount = gets.chomp.split(' ')\n\n\tamount = amount.to_i\n\tif opCode == \"+\"\n\t\tice += amount\n\telsif opCode == \"-\"\n\t\t\tif ice >= amount\n\t\t\t\tice -= amount \n\t\t\telse\n\t\t\t\tchild += 1 \n\t\t\tend\n\tend\t\nend\n\nputs \"#{ice} #{child}\""}, {"source_code": "#!/usr/bin/ruby\nn,x=gets.split.map(&:to_i)\nr=0\nn.times{\n\ta,b=gets.split.zip([:to_s,:to_i]).map{|x,y|x.send(y)}\n\tif a=='-'\n\t\tif b>x\n\t\t\tr+=1\n\t\telse\n\t\t\tx-=b\n\t\tend\n\telse\n\t\tx+=b\n\tend\n}\nputs [x,r]*' '"}, {"source_code": "I =->{gets.split.map &:to_i}\nRD =->{gets.to_i}\n\nn, x = I[]\nz = 0\nn.times{\n a, b = gets.split\n b = b.to_i\n if a == '+'\n x += b\n else\n if x < b\n z += 1\n else\n x -= b\n end\n end\n}\n\nprint x, ' ', z\n\n\n"}, {"source_code": "loobnum , ice = gets.chomp.split.map(&:to_i)\nch = 0 \nwhile loobnum > 0 \n sign , num = gets.chomp.split.map(&:to_s)\n num = num.to_i\n if sign == '-'\n if num > ice\n ch += 1\n else\n ice = ice - num \n end\n elsif sign == '+'\n ice = ice + num \n end\n loobnum -= 1 \nend\n\nprint \"#{ice} \" \" #{ch}\"\n\n"}, {"source_code": "n, x = gets.split.map(&:to_i)\nans = 0\nn.times do\n op, num = gets.split\n num = num.to_i\n if op == \"+\"\n x += num\n else\n if x >= num\n x -= num\n else\n ans += 1\n end\n end\nend\nputs \"#{x} #{ans}\""}, {"source_code": "n, x = gets.strip.split.map(&:to_i)\npacks = x\ndistressed = 0\nn.times do\n query, d = gets.strip.split\n d = d.to_i\n if query == '+'\n packs += d\n else\n if packs < d\n distressed += 1\n else\n packs -= d\n end\n end\nend\nputs \"#{packs} #{distressed}\"\n"}], "negative_code": [], "src_uid": "0a9ee8cbfa9888caef39b024563b7dcd"} {"source_code": "q = gets.to_i\nq.times {\n n = gets.to_i\n a = gets.split.map(&:to_i)\n p (a.inject(:+) * 1.0 / n).ceil\n}\n\n", "positive_code": [{"source_code": "q = gets.to_i\nq.times do\n n = gets.to_i\n as = gets.split.map(&:to_f)\n puts (as.inject(:+)/n).ceil\nend\n"}, {"source_code": "t = gets.to_i\nz = []\n(0..t - 1).each do |i|\n sum = 0\n po = gets\n str = gets\n z[i] = str\n bloc = z[i].split(' ')\n # bloc.map { |w| w = w.to_i}\n bloc.map { |v| sum += v.to_f }\n avg1 = sum/bloc.size\n puts avg1.ceil\nend\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nq = gets.to_i\nq.times {\n n = gets.to_i\n a = gets.split.map(&:to_i)\n sum = a.reduce(&:+)\n puts ((sum*1.0)/n).ceil\n}"}, {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2 1\n puts \"-1\"\nelsif k == 1 and n == 1\n puts \"a\"\nelsif k > n or k > 26\n puts \"-1\"\nelse\n abc = \"abcdefghijklmnopqrstuvwxyz\"\n s = \"ab\" * (n/2)\n s += \"a\" if (n % 2) == 1\n (k-2).times do |x|\n s[s.length-k+2+x] = abc[x+2]\n end\n puts s\nend", "positive_code": [{"source_code": "n,k=gets.split.map(&:to_i)\nif n 2\n time = n - ( k - 2 )\n\n if time.even?\n str += \"ab\"*(time/2)\n else\n str += \"ab\"*(time/2)+\"a\"\n end\n\n ch = \"c\"\n\n (k-2).times do \n str += ch\n ch = ch.next\n end\n else\n if k == 1 && n > 1\n puts -1\n exit\n elsif k == 1 && n == 1\n puts \"a\"\n exit\n end\n\n if n.even?\n str += \"ab\" * (n/2)\n else\n str += \"ab\" * (n/2) + \"a\"\n end\n end\n\n puts str\n end\nend\n\nc = C.new"}, {"source_code": "n, m = gets.split.map(& :to_i)\n\nif m == 1 && n != 1 || m > n\n ans = \"-1\"\nelsif m == 1\n ans = \"a\"\nelse\n L = n - (m - 2);\n ans = \"ab\" * (L/2);\n if L % 2 == 1\n ans += \"a\"\n end\n ans += ('c'..(m + 96).chr).to_a.join('');\nend\nputs ans\n"}, {"source_code": "n, k = gets.split(\" \").collect{|x| x.to_i}\n\nif k == 1 and n > 1\n puts \"-1\"\nelsif k == 1 and n == 1\n puts \"a\"\nelsif k > n or k > 26\n puts \"-1\"\nelse\n abc = \"abcdefghijklmnopqrstuvwxyz\"\n s = \"ab\" * (n/2)\n s += \"a\" if (n % 2) == 1\n (k-2).times do |x|\n s[s.length-k+2+x] = abc[x+2]\n end\n puts s\nend\n"}, {"source_code": "n,k = gets.strip.split.map(&:to_i)\n\nif k == 1 && n == 1\n puts 'a'\nelsif k > 1 && n >= k\n chars = []\n c = 0\n (n - (k-2)).times do\n chars << c\n c = (c + 1) % 2\n end\n\n c = 2\n (k-2).times do\n chars << c\n c += 1\n end\n\n puts chars.map{|x| ('a'.ord + x).chr}.join\nelse\n puts -1\nend\n\n\n"}, {"source_code": "letters = ('c'..'z').to_a.join('')\n\nn, k = gets.chomp.split.map(&:to_i)\nif n == 1 && k == 1\n puts 'a'\n exit\nend\nif k > n || k == 1\n s = -1\nelse\n p = n - k + 2\n s = 'ab' * (p / 2)\n s += 'a' if p.odd?\n s += letters[0..(n - p - 1)] if n - p > 0\nend\nputs s"}], "negative_code": [{"source_code": "class C\n def initialize\n n, k = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n if n < k\n puts -1\n exit\n end\n\n str = \"\"\n\n if k > 2\n time = n - ( k - 2 )\n\n if time.even?\n str += \"ab\"*time\n else\n str += \"ab\"*(time/2)+\"a\"\n end\n\n ch = \"c\"\n\n (k-2).times do \n str += ch\n ch = ch.next\n end\n else\n if k == 1 && n > 1\n puts -1\n exit\n elsif k == 1 && n == 1\n puts \"a\"\n exit\n end\n\n if n.even?\n str += \"ab\" * (n/2)\n else\n str += \"ab\" * (n/2) + \"a\"\n end\n end\n\n puts str\n end\nend\n\nc = C.new"}, {"source_code": "n,k=gets.split.map(&:to_i)\nif n 1\n puts \"-1\"\nelsif k == 1 and n == 1\n puts \"a\"\nelsif k > n or k > 26\n puts \"-1\"\nelse\n s = \"\"\n abc = \"abcdefghijklmnopqrstuvwxyz\"\n s = \"ab\" * (n/2)\n s += \"a\" if n % 2\n (k-2).times do |x|\n s[s.length-k+2+x] = abc[x+2]\n end\n puts s\nend\n"}, {"source_code": "n, k = gets.split(\" \").collect{|x| x.to_i}\n\nif k == 1 and n > 1\n puts \"-1\"\nelsif k == 1 and n == 1\n puts \"a\"\nelsif k > n or k > 26\n puts \"-1\"\nelse\n abc = \"abcdefghijklmnopqrstuvwxyz\"\n s = \"ab\" * (n/2)\n s += \"a\" if (n % 2) == 1\n puts s\n (k-2).times do |x|\n s[s.length-k+2+x] = abc[x+2]\n end\n puts s\nend\n"}, {"source_code": "letters = ('c'..'z').to_a.join('')\n\nn, k = gets.chomp.split.map(&:to_i)\nif k > n || k == 1\n s = -1\nelse\n p = n - k + 2\n s = 'ab' * (p / 2)\n s += 'a' if p.odd?\n s += letters[0..(n - p - 1)] if n - p > 0\nend\nputs s"}, {"source_code": "n,k = gets.strip.split.map(&:to_i)\n\n\nif k <= n && (k > 1 || k == n )\n chars = []\n c = 0\n (n - (k-2)).times do\n chars << c\n c = (c + 1) % 2\n end\n\n c = 2\n (k-2).times do\n chars << c\n c += 1\n end\n\n puts chars.map{|x| ('a'.ord + x).chr}.join\nelse\n puts -1\nend\n\n\n"}], "src_uid": "2f659be28674a81f58f5c587b6a0f465"} {"source_code": "END { load __FILE__ unless $stdin.eof? }\n\nt = gets.to_i\n\nt.times do\n\tn = gets.to_i\n\ta = gets.split.map!(&:to_i)\n\n\ta_max = a.max\n\tputs a_max + (a.sum - a_max).fdiv(n - 1)\nend\n", "positive_code": [{"source_code": "testcases = gets.to_i\ntestcases.times do\n n = gets.to_i\n arr = gets.split(\" \").map!(&:to_f)\n half = (arr.sum - arr.max)/(n-1)\n res = arr.max + half\n puts res.to_f\n testcases -= 1\nend"}, {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n = gets.chomp.to_i\r\n a = gets.chomp.split(\" \").map(&:to_i).sort\r\n sum = 0\r\n a.each do |i|\r\n sum += i\r\n end\r\n mae = 0\r\n ushiro = 0\r\n cnt = 0\r\n max = -Float::INFINITY\r\n a.each do |j|\r\n mae += j\r\n cnt += 1\r\n ushiro = sum - mae\r\n ans = (mae/cnt.to_f) + (ushiro/(n-cnt).to_f) if cnt != n\r\n max = [max,ans].max if cnt != n\r\n # puts \"~~~~~\"\r\n # p ans\r\n # puts \"===\"\r\n end\r\n puts max\r\nend"}, {"source_code": "#!/usr/bin/env ruby\r\n\r\ndef arline\r\n gets.chomp.split.map(&:to_i)\r\nend\r\n \r\ntc = arline[0]\r\ntc.times do\r\n n = arline[0]\r\n ar = arline.sort\r\n puts (ar.pop + ar.sum.to_f/ar.length)\r\nend\r\n"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n = gets.chomp.to_i\r\n a = gets.chomp.split(\" \").map(&:to_i)\r\n sum = 0\r\n a.each do |i|\r\n sum += i\r\n end\r\n mae = 0\r\n ushiro = 0\r\n cnt = 0\r\n max = -Float::INFINITY\r\n a.each do |j|\r\n mae += j\r\n cnt += 1\r\n ushiro = sum - mae\r\n ans = (mae/cnt.to_f) + (ushiro/(n-cnt).to_f) if cnt != n\r\n max = [max,ans].max if cnt != n\r\n end\r\n puts max\r\nend"}], "src_uid": "159b9c743d6d8792548645b9f7be2753"} {"source_code": "gets.to_i.times do\n n, k = gets.split.map(&:to_i)\n k -= 1\n puts (k + (n % 2) * (k / (n / 2))) % n + 1\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n,k=gets.split.map(&:to_i)\r\n k -= 1\r\n p (k+n%2*k/(n/2))%n+1\r\nend"}, {"source_code": "gets.to_i.times do\r\n n,k=gets.split.map(&:to_i)\r\n if n.even?\r\n puts (k-1)%n+1\r\n else\r\n k%=n/2*n\r\n puts (k+(k-1)/(n/2)-1)%n+1\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "2e837d3afc48177516578a950e957586"} {"source_code": "gets\np gets(p).split.select{|_|(%w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)+[*?0..\"17\"]).include? _}.size\n", "positive_code": [{"source_code": "s=[\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\",\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\",\"17\"]\nn=gets.to_i\nans=0\nn.times{\n t=gets.split[0]\n if s.index(t)!=nil then\n ans+=1\n end\n}\nputs ans"}, {"source_code": "gets\np gets(p).split.select{|_|(%w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)+[*?0..\"17\"]).include? _}.size\n"}, {"source_code": "gets\np gets(p).split.select{|_|(%w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)+[*?0..\"17\"]).include? _}.size\n"}, {"source_code": "gets\np gets(p).split.select{|_|(%w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)+[*?0..\"17\"]).include? _}.size"}, {"source_code": "a,ctr=[],0\nal=[\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\"]\nn=gets.to_i\nn.times do\n\tx=gets.chomp\n\tctr+=1 if al.include?(x) || (x =~ /[0-9]+/ && x.to_i < 18)\nend\nputs ctr\n"}, {"source_code": "gets\np gets(p).split.select{|_|(%w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)+[*?0..\"17\"]).include? _}.size\n"}, {"source_code": "n = gets.strip.to_i\ndrinks = [ \"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\" ]\nans = 0\nn.times do\n i = gets.strip\n if i =~ /[0-9]/\n age = i.to_i\n ans += 1 if age < 18\n else\n ans += 1 if drinks.include? i\n end\nend\nputs ans\n"}, {"source_code": "gets\np gets(p).split.select{|_|(%w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)+[*?0..\"17\"]).include? _}.size"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\ndr=[:ABSINTH, :BEER, :BRANDY, :CHAMPAGNE, :GIN, :RUM, :SAKE, :TEQUILA, :VODKA, :WHISKEY, :WINE].map{|v| v.to_s}\n\n0.upto(17){|age|\n\tdr << age.to_s\n}\n\ncount=0\nn.times{\n\tline=gets.strip\n\t\n\tif dr.include?(line)\n\t\tcount+=1\n\tend\n}\n\nputs count\n"}, {"source_code": "judge_arr = %w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)\ns=gets\nvcount=0\ns.to_i.times {\n a=gets \n a.chop!\n if(a.match(/\\d+/)==nil) then\n judge_arr.include?(a)?vcount+=1:vcount\n else\n a.to_i<18?vcount+=1:vcount\n end\n }\n puts vcount"}, {"source_code": "gets\np gets(p).split.select{|_|(%w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)+[*?0..\"17\"]).include? _}.size\n"}, {"source_code": "drinks = [\"ABSINTH\",\"BEER\",\"BRANDY\",\"CHAMPAGNE\",\"GIN\",\"RUM\",\"SAKE\",\"TEQUILA\", \"VODKA\",\"WHISKEY\", \"WINE\"]\nn = gets.to_i\ncount = 0\nn.times do |i|\n\tline = gets.chomp.upcase\n\n\tage = line.to_i unless line =~ /[A-Z]/\n\t# puts line\n\tcount += 1 if ((age && age < 18) || drinks.include?(line) ) \n\t# puts \"count #{count}\"\nend\nputs count"}, {"source_code": "gets\np gets(p).split.select{|_|(%w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)+[*?0..\"17\"]).include? _}.size"}, {"source_code": "gets\np gets(p).split.select{|_|(%w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)+[*?0..\"17\"]).include? _}.size\n"}, {"source_code": "def toi(n)\n if n.to_i.to_s != n\n 10000\n else\n n.to_i\n end\nend\n\ndef check(str)\n alchohol = [\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\"]\n is_al = alchohol.find { |drink| str == drink }\n return true if (is_al)\n return toi(str) < 18\nend\n\nn = gets.chomp.to_i\ns = 0\nn.times do\n str = gets.chomp\n if check str\n s += 1\n end\nend\n\nputs s\n"}, {"source_code": "n = gets.to_i\n\ncount = 0\nmas = \",ABSINTH,BEER,BRANDY,CHAMPAGNE,GIN,RUM,SAKE,TEQUILA,VODKA,WHISKEY,WINE,\"\nfor i in 0..n-1\n s = gets.chomp!\n if ((s =~ /[0-9]+/ && s.to_i < 18) || (mas.index(\",\"+s+\",\") != nil))\n count += 1\n end\nend\n\nputs count"}, {"source_code": "alcohol = [\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\",\n \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\"]\n\nnum = gets.chomp.to_i\n\ncount = 0\n\nnum.times do |i|\n str = gets.chomp\n if str =~ /\\d+/\n if str.to_i < 18\n count = count + 1\n end\n else\n if alcohol.include? str\n count = count + 1\n end\n end\nend\n\nputs count\n"}, {"source_code": "n = gets.chomp.to_i\nguys = n.times.map { gets.chomp }\n\n\nalc = %w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)\n\ncnt = 0\nguys.each do |g|\n cnt += 1 if (g =~ /(\\d+)/ && $1.to_i < 18) || alc.include?(g)\nend\n\nputs cnt"}, {"source_code": "gets\np gets(p).split.select{|_|(%w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)+[*?0..\"17\"]).include? _}.size\n"}, {"source_code": "gets\np gets(p).split.select{|_|(%w(ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE)+[*?0..\"17\"]).include? _}.size\n"}], "negative_code": [{"source_code": "a,ctr=[],0\nal=[\"ABSINTH\", \"BEER\", \"BRANDY\", \"CHAMPAGNE\", \"GIN\", \"RUM\", \"SAKE\", \"TEQUILA\", \"VODKA\", \"WHISKEY\", \"WINE\"]\nn=gets.to_i\nn.times do\n\tx=gets.chomp\n\tctr+=1 if al.include?(x) || (x.to_i!=0 && x.to_i<18)\nend\nputs ctr\n"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\ndr=[:ABSINTH, :BEER, :BRANDY, :CHAMPAGNE, :GIN, :RUM, :SAKE, :TEQUILA, :VODKA, :WHISKEY, :WINE].map{|v| v.to_s}\n\ncount=0\nn.times{\n\tline=gets.strip\n\t\n\tage=line.to_i\n\tage=19 if age==0\n\t\n\tif dr.include?(line) || age<18\n\t\tputs \"line=#{line} age=#{age}\"\n\t\tcount+=1\n\tend\n}\n\nputs count\n"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\ndr=[:ABSINTH, :BEER, :BRANDY, :CHAMPAGNE, :GIN, :RUM, :SAKE, :TEQUILA, :VODKA, :WHISKEY, :WINE].map{|v| v.to_s}\n\ncount=0\nn.times{\n\tline=gets.strip\n\t\n\tage=line.to_i\n\tage=19 if age==0\n\t\n\tif dr.include?(line) || age<18\n\t\tcount+=1\n\tend\n}\n\nputs count\n"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\ndr=[:ABSINTH, :BEER, :BRANDY, :CHAMPAGNE, :GIN, :RUM, :SAKE, :TEQUILA, :VODKA, :WHISKEY, :WINE].map{|v| v.to_s}\n\n0.upto(17){|age|\n\tputs age\n\tdr << age.to_s\n}\n\ncount=0\nn.times{\n\tline=gets.strip\n\t\n\tif dr.include?(line)\n\t\tcount+=1\n\tend\n}\n\nputs count\n"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.to_i\ndr=[:ABSINTH, :BEER, :BRANDY, :CHAMPAGNE, :GIN, :RUM, :SAKE, :TEQUILA, :VODKA, :WHISKEY, :WINE].map{|v| v.to_s}\n\n1.upto(17){|age|\n\tdr << age.to_s\n}\n\ncount=0\nn.times{\n\tline=gets.strip\n\t\n\tif dr.include?(line)\n\t\tcount+=1\n\tend\n}\n\nputs count\n"}, {"source_code": "drinks = [\"ABSINTH\",\"BEER\",\"BRANDY\",\"CHAMPAGNE\",\"GIN\",\"RUM\",\"SAKE\",\"TEQUILA\", \"VODKA\",\"WHISKEY\", \"WINE\"]\nn = gets.to_i\ncount = 0\nn.times do |i|\n\tline = gets.chomp\n\tage = line.to_i\n\t# puts line\n\tcount += 1 if ((age > 0 && age < 18) || (age == 0 && drinks.include?(line)) ) \n\t# puts \"count #{count}\"\nend\nputs count"}, {"source_code": "n = gets.to_i\n\ncount = 0\nmas = \"ABSINTH,BEER,BRANDY,CHAMPAGNE,GIN,RUM,SAKE,TEQUILA,VODKA,WHISKEY,WINE\"\nfor i in 0..n-1\n s = gets.chomp!\n if ((s =~ /[0-9]+/ && s.to_i < 18) || (mas.index(s) != nil))\n count += 1\n end\nend\n\nputs count"}], "src_uid": "4b7b0fba7b0af78c3956c34c29785e7c"} {"source_code": "# http://codeforces.ru/contest/159/problem/C\n\ndef run(input = STDIN.read)\n lines = input.split(\"\\n\")\n\n k = lines[0].to_i\n s = lines[1]\n n = lines[2].to_i\n\n cmd = lines[3..-1]\n\n word = (s * k)\n\n h = {}\n l = {}\n\n i = 0\n word.each_char { |c|\n if h.has_key?(c) then\n h[c].push(i)\n else\n h[c] = [i]\n end\n i += 1\n }\n\n #p h\n\n cmd.each { |c| \n (occurance, letter) = c.split(\" \")\n occurance = occurance.to_i\n\n pos = h[letter][occurance - 1]\n word[pos] = \"0\"\n h[letter].delete_at(occurance - 1)\n \n #p word\n }\n\n return word.delete(\"0\")\nend\n\nbegin\n require './testingx.rb'\nrescue LoadError\n puts run\nend\n__END__\n2\nbac\n3\n2 a\n1 b\n2 c\n=\nacb\n---\n1\nabacaba\n4\n1 a\n1 c\n2 b\n1 a\n=\nbaa\n---\n3\nderp\n3\n1 p\n1 p\n1 p\n1 r\n2 r\n2 d\n=\ndeerde\n---\n3\nxxx\n2\n1 x\n8 x\n=\nxxxxxxx\n---\n3\nderp\n2\n2 p\n1 p\n1 d\n2 d\n=\nerdererp", "positive_code": [{"source_code": "class T\n def initialize(l, r)\n @l = l\n @r = r\n @m = (l + r) / 2\n @c = r - l\n end\n\n def l\n @pl = @pl || T.new(@l, @m)\n end\n\n def r\n @pr = @pr || T.new(@m, @r)\n end\n\n def c\n @c\n end\n\n def d(i)\n @c -= 1\n if @r - @l == 1\n @l\n elsif i < l.c\n l.d(i)\n else\n r.d(i - l.c)\n end\n end\nend\n\nr = gets.to_i\ns = gets.chop\nt = Array.new(128){T.new(0, r * s.size)}\nd = Array.new(128){[]}\ngets.to_i.times{|i|\n p, c = gets.split\n c = c.ord\n d[c] << t[c].d(p.to_i - 1)\n}\nd.each{|_|\n _.sort!.reverse!\n}\nt = [0] * 128\nz = []\nr.times{\n s.each_byte{|b|\n if t[b] == d[b][-1]\n d[b].pop\n else\n z << b\n end\n t[b] += 1\n }\n}\nputs z.map(&:chr) * ''\n"}, {"source_code": "k = gets().to_i\ns = gets().chomp\nn = gets().to_i\nchanges = []\nn.times { changes << gets().chomp.split }\n\nname = s * k\n\nletter_indexes = {}\n0.upto(name.size - 1) do |i|\n letter = name[i]\n letter_indexes[letter] ||= []\n letter_indexes[letter] << i\nend\n\nchanges.each do |position, letter|\n position = position.to_i\n \n if indexes = letter_indexes[letter] and indexes.size >= position\n name[indexes[position - 1]] = '0'\n letter_indexes[letter].delete_at(position - 1)\n end\nend\n\nputs name.delete('0')"}], "negative_code": [{"source_code": "class T\n def initialize(l, r)\n @l = l\n @r = r\n @m = (l + r) / 2\n @c = r - l\n end\n\n def l\n @pl = @pl || T.new(@l, @m)\n end\n\n def r\n @pr = @pr || T.new(@m, @r)\n end\n\n def c\n @c\n end\n\n def d(i)\n @c -= 1\n if @r - @l == 1\n @l\n elsif i < l.c\n l.d(i)\n else\n r.d(i - l.c)\n end\n end\nend\n\nr = gets.to_i\ns = gets.chop\nt = Array.new(128){T.new(0, r * s.size)}\nd = Array.new(128){[]}\ngets.to_i.times{|i|\n p, c = gets.split\n c = c.ord\n d[c] << t[c].d(p.to_i - 1)\n}\nd.each{|_|\n _.sort!.reverse!\n}\nt = [0] * 128\nz = []\nr.times{\n s.each_byte{|b|\n if t[b] == d[b][-1]\n d[b].pop\n else\n t[b] += 1\n z << b\n end\n }\n}\nputs z.map(&:chr) * ''\n"}, {"source_code": "k = gets().to_i\ns = gets().chomp\nname = s * k\n\nletter_entries = {}\n\nn = gets().to_i\nn.times do\n change = gets().chomp.split\n entry = change[0].to_i\n letter = change[1]\n \n letter_entries[letter] ||= []\n letter_entries[letter] << entry\nend\n\nletter_entries.each do |letter, entries|\n entries.sort!\n \n 1.upto(entries.size - 1) do |i|\n entries[i] += i\n end\nend\n\nname_letters = name.split('')\ncurrent_letter_entries = {}\n\n0.upto(name_letters.size-1) do |i|\n letter = name_letters[i]\n \n current_letter_entries[letter] ||= 0\n current_letter_entries[letter] += 1\n \n name_letters[i] = nil if letter_entries[letter].include?(current_letter_entries[letter])\nend\n\nputs name_letters.compact.join"}, {"source_code": "class String\n def char_distr\n split('').inject({}) { |hash, e| hash[e] ||= 0; hash[e] += 1; hash }\n end\n \n def delete_nth_entry(letter, entry)\n index = 0\n \n while entry > 0\n entry -= 1 if self[index] == letter\n index += 1\n end\n \n self[index-1] = ''\n self\n end\nend\n\ndef find_piece_and_index(letter, entry, char_distributions)\n index = 0\n sum = char_distributions[index][letter]\n prev_sum = 0\n while entry > sum && index < char_distributions.size\n index += 1\n prev_sum = sum\n sum += char_distributions[index][letter]\n end\n return index, (entry - prev_sum)\nend\n\nk = gets().to_i\ns = gets().chomp\npieces = []\nk.times { pieces << s.dup }\n\nchar_distribution = s.char_distr\nchar_distributions = []\nk.times { char_distributions << char_distribution.dup }\n\nn = gets().to_i\nn.times do \n change = gets().split\n entry = change[0].to_i\n letter = change[1]\n \n piece, local_entry = find_piece_and_index(letter, entry, char_distributions)\n pieces[piece].delete_nth_entry(letter, local_entry)\n char_distributions[piece][letter] -= 1\nend\n\np pieces.join('')"}, {"source_code": "k = gets().to_i\ns = gets().chomp\nname = s * k\n\nletter_entries = {}\n\nn = gets().to_i\nn.times do\n change = gets().chomp.split\n entry = change[0].to_i\n letter = change[1]\n \n letter_entries[letter] ||= []\n letter_entries[letter] << entry\nend\n\nletter_entries.each do |letter, entries|\n old_value = entries[0]\n 1.upto(entries.size - 1) do |i|\n entries[i] += i if entries[i] >= old_value\n end\nend\n\nname_letters = name.split('')\ncurrent_letter_entries = {}\n\n0.upto(name_letters.size-1) do |i|\n letter = name_letters[i]\n \n current_letter_entries[letter] ||= 0\n current_letter_entries[letter] += 1\n \n if letter_entries[letter] && letter_entries[letter].include?(current_letter_entries[letter])\n name_letters[i] = nil\n end\nend\n\nputs name_letters.compact.join"}, {"source_code": "k = gets().to_i\ns = gets().chomp\nname = s * k\n\nletter_entries = {}\n\nn = gets().to_i\nn.times do\n change = gets().chomp.split\n entry = change[0].to_i\n letter = change[1]\n \n letter_entries[letter] ||= []\n letter_entries[letter] << entry\nend\n\nletter_entries.each do |letter, entries|\n entries.sort!\n \n 1.upto(entries.size - 1) do |i|\n entries[i] += i\n end\nend\n\nname_letters = name.split('')\ncurrent_letter_entries = {}\n\n0.upto(name_letters.size-1) do |i|\n letter = name_letters[i]\n \n current_letter_entries[letter] ||= 0\n current_letter_entries[letter] += 1\n \n if letter_entries[letter] && letter_entries[letter].include?(current_letter_entries[letter])\n name_letters[i] = nil \n end\nend\n\nputs name_letters.compact.join"}, {"source_code": "class String\n def delete_nth_entries!(letter, entries)\n index = 0\n entry_index = 0\n current_entry = 0\n \n while entry_index < entries.size\n if self[index] == letter\n current_entry += 1\n if current_entry == entries[entry_index]\n self[index] = ''\n entry_index += 1\n end\n end\n index += 1\n end\n \n self\n end\nend\n\nk = gets().to_i\ns = gets().chomp\nname = s * k\n\nletter_entries = {}\n\nn = gets().to_i\nn.times do\n change = gets().chomp.split\n entry = change[0].to_i\n letter = change[1]\n \n letter_entries[letter] ||= []\n letter_entries[letter] << entry\nend\n\nletter_entries.each do |letter, entries|\n entries.sort!\n \n 1.upto(entries.size - 1) do |i|\n entries[i] += i\n end\n p letter_entries\n p name\n name.delete_nth_entries!(letter, entries)\nend\n\nputs name"}, {"source_code": "# http://codeforces.ru/contest/159/problem/C\n\ndef run(input = STDIN.read)\n lines = input.split(\"\\n\")\n\n k = lines[0].to_i\n s = lines[1]\n n = lines[2].to_i\n\n cmd = lines[3..-1]\n\n word = (s * k)\n\n h = {}\n l = {}\n\n i = 0\n word.each_char { |c|\n if h.has_key?(c) then\n h[c].push(i)\n else\n h[c] = [i]\n end\n i += 1\n }\n\n cmd.each { |c|\n (occurance, letter) = c.split(\" \")\n occurance = occurance.to_i\n\n while (pos = h[letter][occurance - 1]) == nil\n occurance += 1\n end\n \n word[pos] = \"0\"\n h[letter][occurance - 1] = nil\n }\n\n return word.delete(\"0\")\nend\n\nbegin\n require './testing.rb'\nrescue LoadError\n puts run\nend\n__END__\n2\nbac\n3\n2 a\n1 b\n2 c\n=\nacb\n---\n1\nabacaba\n4\n1 a\n1 c\n2 b\n1 a\n=\nbaa\n---\n3\nderp\n2\n1 p\n1 p\n1 p\n2 r\n2 r\n1 r\n2 d\n=\ndeede"}], "src_uid": "adbfdb0d2fd9e4eb48a27d43f401f0e0"} {"source_code": "n,m = gets.split(' ').map(&:to_i)\n\nsm = [];\nn.times do |i| sm[i] = [] end\n\nm.times do\n a,b = gets.split(' ').map(&:to_i)\n a -= 1\n b -= 1\n sm[a][b] = 1\nend\n\np = []\n$q = 0\ndef rec(id,p,sm,n)\n p[id] |= 0\n if p[id] == 1 then return end\n p[id] = 1\n $q += 1\n n.times do |i|\n sm[id][i] |= 0\n if sm[id][i] == 1 or sm[i][id] == 1 then\n rec(i,p,sm,n)\n end\n end\nend\n\nrec(0,p,sm,n)\nif($q == n and $q == m) then puts('FHTAGN!');\nelse puts('NO');\nend\n\n", "positive_code": [{"source_code": "$n,$m=gets.split.map &:to_i\n$e=Array.new($n+1){[]}\n$m.times{a,b=gets.split.map &:to_i;$e[a]<2&&$n==$m&&dfs(1) ? \"FHTAGN!\" : \"NO\""}], "negative_code": [{"source_code": "$n,$m=gets.split.map &:to_i\n$e=Array.new($n+1){[]}\n$m.times{a,b=gets.split.map &:to_i;$e[a]<2&&$n==$m&&dfs(1) ? \"FHTAGN!\" : \"NO\""}, {"source_code": "$n,$m=gets.split.map &:to_i\n$e=Array.new($n+1){[]}\n$m.times{a,b=gets.split.map &:to_i;$e[a]<=2\n ans=[0]\n ans<=2\n ans=[0]\n ans<=2\n ans=[0]\n ans<=2\n ans=[0]\n ans<=2\n ans=[0]\n ans<=2\n ans=[0]\n ans<=2\n ans=[0]\n ans<=2\n ans=[0]\n ans<=2\n ans=[0]\n ans<2\n ans=[0]*$n\n ans[1]=i\n ans[2]=j\n if check ans\n ans.each {|k| print (k+1).to_s + ' '}\n exit\n end\n end\n }\n}\n\nputs -1"}, {"source_code": "require 'set'\n\ndef check ans\n (1...$n-1).each {|i|\n common=($a[ans[i]]-[ans[i-1],ans[(i+1)%$n]]) & $a[ans[(i+1)%$n]]\n return false if common.size==0\n\n if i+2<$n\n return false if common.size==0\n ans<4 || $a[input[1]].length>4\n puts -1\n exit\n end\nend\n\n$a[0].each {|i|\n $a[0].each {|j|\n if i!=j && $a[i].include?(j)\n ans=[0]\n ans<=2\n ans=[0]\n ans<0\n ans=[0]*$n\n ans[1]=i\n ans[2]=j\n if check ans\n ans.each {|k| print (k+1).to_s + ' '}\n exit\n end\n end\n }\n}\n\nputs -1"}, {"source_code": "require 'set'\n\ndef check ans\n used=[false]*$n\n 3.times {|i| used[i]=true}\n (3...$n).each {|i|\n $a[ans[i-1]].each {|j|\n if !used[j] && $a[j].include?(ans[i-2])\n ans[i]=j\n used[j]=true\n break\n end\n }\n return false if ans[i]==0\n }\n true\nend\n\n$n=gets.to_i\n$a=Array.new($n) {Set.new}\n\n($n*2).times do\n input=gets.split.map{|i| i.to_i-1}\n $a[input[0]]<=2\n ans=[0]*$n\n ans[1]=i\n ans[2]=j\n if check ans\n ans.each {|k| print (k+1).to_s + ' '}\n exit\n end\n end\n }\n}\n\nputs -1"}, {"source_code": "require 'set'\n\ndef check ans\n (1...$n-1).each {|i|\n common=($a[ans[i]]-[ans[i-1],ans[(i+1)%$n]]) & $a[ans[(i+1)%$n]]\n return false if common.size==0\n\n if i+2<$n\n common-=ans\n return false if common.size!=1\n ans<4 || $a[input[1]].length>4\n puts -1\n exit\n end\nend\n\n$a[0].each {|i|\n $a[0].each {|j|\n if i!=j && $a[i].include?(j)\n ans=[0]\n ans<4 || $a[input[1]].length>4\n puts -1\n exit\n end\nend\n\n$a[0].each {|i|\n $a[0].each {|j|\n if i!=j && $a[i].include?(j)\n ans=[0]\n ans<= [a[1], b[1]].min && f[1] <= [a[1], b[1]].max) \n ans += 2 if a[1] == f[1] && a[1] == b[1] && (f[0] >= [a[0], b[0]].min && f[0] <= [a[0], b[0]].max) \n puts \"#{ans}\\n\"\n end\nend\n\n", "positive_code": [{"source_code": "def incl(a, b, f, i)\n a = a[i]\n b = b[i]\n a, b = b, a if b < a\n (a..b).include?(f[i])\nend\n\ngets.to_i.times {\n gets\n a = gets.split.map!(&:to_i)\n b = gets.split.map!(&:to_i)\n f = gets.split.map!(&:to_i)\n x = a.zip(b).map { (_1 - _2).abs }\n\n ans = x.sum\n ans += 2 if x[0] == 0 && a[0] == f[0] && incl(a, b, f, 1)\n ans += 2 if x[1] == 0 && a[1] == f[1] && incl(a, b, f, 0)\n\n p ans\n}\n"}], "negative_code": [], "src_uid": "6422d76f71702e77808b1cc041962bb8"} {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 1\nresult = []\nmax_h = min_h = books_height[0]\nmax_i = min_i = 0\nmax_sub_h = 0\nmin_sub_h = 1000000\nmax_sub_i = min_sub_i = 0\ncount = 0\ni = 0\nwhile i < number_of_books\n if max_sub_i > i\n max_h = max_sub_h\n max_i = max_sub_i\n else\n max_h = books_height[i]\n max_i = i\n end\n if min_sub_i > i\n min_h = min_sub_i\n min_i = min_sub_i\n else\n min_h = books_height[i]\n min_i = i\n end\n if count <= i\n count = i + 1\n end\n max_sub_h = 0\n min_sub_h = 1000000\n max_sub_i = min_sub_i = 0\n while count < number_of_books\n if max_h <= books_height[count]\n max_h = books_height[count]\n max_i = count\n elsif min_h >= books_height[count]\n min_h = books_height[count]\n min_i = count\n elsif max_i < min_i && max_sub_h < max_h\n max_sub_h = books_height[count]\n max_sub_i = count\n elsif min_i < max_i && min_sub_h > min_h\n min_sub_h = books_height[count]\n min_sub_i = count\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\n if count == number_of_books || number_of_books - i <= max_books\n break\n elsif max_i >= min_i\n i = min_i + 1\n elsif min_i > max_i\n i = max_i + 1\n else\n i += 1\n end\n count -= 1\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n\n", "positive_code": [{"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 1\nresult = []\nmax_h = min_h = books_height[0]\nmax_i = min_i = 0\nmax_sub_h = 0\nmin_sub_h = 1000000\nmax_sub_i = min_sub_i = 0\ncount = 0\ni = 0\nwhile i < number_of_books\n#(number_of_books).times do |i|\n# count = i + 1\n# max_h = min_h = books_height[i]\n# max_i = min_i = count - 1\n if max_sub_i > i\n max_h = max_sub_h\n max_i = max_sub_i\n else\n max_h = books_height[i]\n max_i = i\n# count = i + 1\n end\n if min_sub_i > i\n min_h = min_sub_i\n min_i = min_sub_i\n else\n min_h = books_height[i]\n min_i = i\n# count = i + 1\n end\n if count <= i\n count = i + 1\n end\n max_sub_h = 0\n min_sub_h = 1000000\n max_sub_i = min_sub_i = 0\n while count < number_of_books\n if max_h <= books_height[count]\n max_h = books_height[count]\n max_i = count\n elsif min_h >= books_height[count]\n min_h = books_height[count]\n min_i = count\n elsif max_i < min_i && max_sub_h < max_h\n max_sub_h = books_height[count]\n max_sub_i = count\n elsif min_i < max_i && min_sub_h > min_h\n min_sub_h = books_height[count]\n min_sub_i = count\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\n if count == number_of_books || number_of_books - i <= max_books\n break\n elsif max_i >= min_i\n i = min_i + 1\n elsif min_i > max_i\n i = max_i + 1\n else\n i += 1\n end\n count -= 1\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n\n"}], "negative_code": [{"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 1\nresult = []\nmax_h = min_h = books_height[0]\nmax_i = min_i = 0\nmax_sub_h = 0\nmin_sub_h = 1000000\nmax_sub_i = min_sub_i = 0\ncount = 0\ni = 0\nwhile i < number_of_books\n#(number_of_books).times do |i|\n# count = i + 1\n# max_h = min_h = books_height[i]\n# max_i = min_i = count - 1\n if max_sub_i > i\n max_h = max_sub_h\n max_i = max_sub_i\n else\n max_h = books_height[i]\n max_i = i\n# count = i + 1\n end\n if min_sub_i > i\n min_h = min_sub_i\n min_i = min_sub_i\n else\n min_h = books_height[i]\n min_i = i\n# count = i + 1\n end\n max_sub_h = 0\n min_sub_h = 1000000\n max_sub_i = min_sub_i = 0\n while count < number_of_books\n if max_h <= books_height[count]\n max_h = books_height[count]\n max_i = count\n elsif min_h >= books_height[count]\n min_h = books_height[count]\n min_i = count\n elsif max_i < min_i && max_sub_h < max_h\n max_sub_h = books_height[count]\n max_sub_i = count\n elsif min_i < max_i && min_sub_h > min_h\n min_sub_h = books_height[count]\n min_sub_i = count\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\n if count == number_of_books || number_of_books - i <= max_books\n break\n elsif max_i >= min_i\n i = min_i + 1\n elsif min_i > max_i\n i = max_i + 1\n else\n i += 1\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 0\nresult = []\n\n(number_of_books - 1).times do |i|\n count = i + 1\n while count < number_of_books\n if (books_height[i] - books_height[count]).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 1\nresult = []\nmax_h = min_h = books_height[0]\nmax_i = min_i = 0\nmax_sub_h = 0\nmin_sub_h = 1000000\nmax_sub_i = min_sub_i = 0\ncount = 0\ni = 0\nwhile i < number_of_books\n#(number_of_books).times do |i|\n# count = i + 1\n# max_h = min_h = books_height[i]\n# max_i = min_i = count - 1\n if max_sub_i > i\n max_h = max_sub_h\n max_i = max_sub_i\n else\n max_h = books_height[i]\n max_i = i\n# count = i + 1\n end\n if min_sub_i > i\n min_h = min_sub_i\n min_i = min_sub_i\n else\n min_h = books_height[i]\n min_i = i\n# count = i + 1\n end\n if count == i\n count += 1\n end\n max_sub_h = 0\n min_sub_h = 1000000\n max_sub_i = min_sub_i = 0\n while count < number_of_books\n if max_h <= books_height[count]\n max_h = books_height[count]\n max_i = count\n elsif min_h >= books_height[count]\n min_h = books_height[count]\n min_i = count\n elsif max_i < min_i && max_sub_h < max_h\n max_sub_h = books_height[count]\n max_sub_i = count\n elsif min_i < max_i && min_sub_h > min_h\n min_sub_h = books_height[count]\n min_sub_i = count\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\n if count == number_of_books || number_of_books - i <= max_books\n break\n elsif max_i >= min_i\n i = min_i + 1\n elsif min_i > max_i\n i = max_i + 1\n else\n i += 1\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 0\nresult = []\n\n(number_of_books - 1).times do |i|\n count = i + 1\n max_h = min_h = books_height[i]\n while count < number_of_books\n if max_h < books_height[count]\n max_h = books_height[count]\n elsif min_h > books_height[count]\n min_h = books_height[count]\n end\n if (max_h - min_h).abs >= limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books && count - i > 1\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 0\nresult = []\n\n(number_of_books - 1).times do |i|\n count = i + 1\n max_h = min_h = books_height[i]\n while count < number_of_books\n if max_h < books_height[count]\n max_h = books_height[count]\n elsif min_h > books_height[count]\n min_h = books_height[count]\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 1\nresult = []\n\ni = 0\nwhile i < number_of_books\n#(number_of_books).times do |i|\n count = i + 1\n max_h = min_h = books_height[i]\n max_i = min_i = count\n while count < number_of_books\n if max_h < books_height[count]\n max_h = books_height[count]\n max_i = count\n elsif min_h > books_height[count]\n min_h = books_height[count]\n min_i = count\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\n if count == number_of_books\n break\n elsif max_i >= min_i\n i += max_i\n elsif min_i > max_i\n i += min_i\n else\n i += 1\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 0\nresult = []\n\n(number_of_books - 1).times do |i|\n count = i + 1\n while count < number_of_books\n if (books_height[i] - books_height[count]).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books && count - i > 1\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 1\nresult = []\n\ni = 0\nwhile i < number_of_books\n#(number_of_books).times do |i|\n count = i + 1\n max_h = min_h = books_height[i]\n max_i = min_i = count\n while count < number_of_books\n if max_h < books_height[count]\n max_h = books_height[count]\n max_i = count\n elsif min_h > books_height[count]\n min_h = books_height[count]\n min_i = count\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\n if count == number_of_books\n break\n elsif max_i >= min_i\n i = max_i\n elsif min_i > max_i\n i = min_i\n else\n i += 1\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 0\nresult = []\n\n(number_of_books - 1).times do |i|\n count = i + 1\n max_h = min_h = books_height[i]\n while count < number_of_books\n if max_h < books_height[count]\n max_h = books_height[count]\n elsif min_h > books_height[count]\n min_h = books_height[count]\n end\n if (max_h - min_h).abs > limit_height\n count += 1\n break\n end\n count += 1\n end\n count -= 1\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 1\nresult = []\nmax_h = min_h = books_height[0]\nmax_i = min_i = 0\nmax_sub_h = 0\nmin_sub_h = 1000000\nmax_sub_i = min_sub_i = 0\ncount = 0\ni = 0\nwhile i < number_of_books\n#(number_of_books).times do |i|\n# count = i + 1\n# max_h = min_h = books_height[i]\n# max_i = min_i = count - 1\n count += 1\n if max_sub_i > i\n max_h = max_sub_h\n max_i = max_sub_i\n else\n max_h = books_height[i]\n max_i = i\n end\n if min_sub_i > i\n min_h = min_sub_i\n min_i = min_sub_i\n else\n min_h = books_height[i]\n min_i = i\n end\n max_sub_h = 0\n min_sub_h = 1000000\n max_sub_i = min_sub_i = 0\n while count < number_of_books\n if max_h <= books_height[count]\n max_h = books_height[count]\n max_i = count\n elsif min_h >= books_height[count]\n min_h = books_height[count]\n min_i = count\n elsif max_i < min_i && max_sub_h < max_h\n max_sub_h = books_height[count]\n max_sub_i = count\n elsif min_i min_h\n min_sub_h = books_height[count]\n min_sub_i = count\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\n if count == number_of_books || number_of_books - i <= max_books\n break\n elsif max_i >= min_i\n i = min_i + 1\n elsif min_i > max_i\n i = max_i + 1\n else\n i += 1\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 1\nresult = []\n\ni = 0\nwhile i < number_of_books\n#(number_of_books).times do |i|\n count = i + 1\n max_h = min_h = books_height[i]\n max_i = min_i = count\n while count < number_of_books\n if max_h < books_height[count]\n max_h = books_height[count]\n max_i = count\n elsif min_h > books_height[count]\n min_h = books_height[count]\n min_i = count\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\n if count == number_of_books || max_books > number_of_books - count\n break\n elsif max_i >= min_i\n i = min_i\n elsif min_i > max_i\n i = max_i\n else\n i += 1\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 0\nresult = []\n\n(number_of_books - 1).times do |i|\n count = i + 1\n max_h = min_h = books_height[i]\n while count < number_of_books\n if max_h < books_height[count]\n max_h = books_height[count]\n elsif min_h > books_height[count]\n min_h = books_height[count]\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books && count - i > 1\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 1\nresult = []\n\nif number_of_books == 1\n result.push [1,1]\nend\n\n(number_of_books).times do |i|\n count = i + 1\n max_h = min_h = books_height[i]\n while count < number_of_books\n if max_h < books_height[count]\n max_h = books_height[count]\n elsif min_h > books_height[count]\n min_h = books_height[count]\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 1\nresult = []\n\nif number_of_books == 1\n result.push [1,1]\nend\n\n(number_of_books - 1).times do |i|\n count = i + 1\n max_h = min_h = books_height[i]\n while count < number_of_books\n if max_h < books_height[count]\n max_h = books_height[count]\n elsif min_h > books_height[count]\n min_h = books_height[count]\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n"}, {"source_code": "number_of_books,limit_height = gets.split.collect! {|x| x.to_i}\n\nbooks_height = []\nbooks_height = gets.split.collect! {|x| x.to_i}\n\nmax_books = 1\nresult = []\n\ni = 0\nwhile i < number_of_books\n#(number_of_books).times do |i|\n count = i + 1\n max_h = min_h = books_height[i]\n max_i = min_i = count\n while count < number_of_books\n if max_h < books_height[count]\n max_h = books_height[count]\n max_i = count\n elsif min_h > books_height[count]\n min_h = books_height[count]\n min_i = count\n end\n if (max_h - min_h).abs > limit_height\n break\n end\n count += 1\n max_i -= 1\n min_i -= 1\n end\n if count - i >= max_books\n if count - i > max_books\n result.clear\n end\n max_books = count - i\n result.push [i + 1,count]\n end\n if count == number_of_books\n break\n elsif max_i >= min_i\n p i\n i = max_i\n elsif min_i > max_i\n i = min_i\n else\n i += 1\n end\nend\nputs max_books.to_s + ' ' + result.length.to_s\nresult.length.times do |i|\n puts result[i][0].to_s + ' ' + result[i][1].to_s\nend\n\n"}], "src_uid": "bc8b4b74c2f2d486e2d2f03982ef1013"} {"source_code": "\nt = gets.chomp.to_i\nt.times {\n n = gets.chomp.to_i\n arr = gets.chomp.split(' ').map(&:to_i)\n if arr[n - 1] >= (arr[0] + arr[1])\n puts \"1 2 #{n}\"\n else\n puts '-1'\n end\n}\n\n", "positive_code": [{"source_code": "gets.to_i.times do\n gets\n arr = gets.split(' ').map(&:to_i)\n \n puts arr[0] + arr[1] > arr.last ? -1 : \"1 2 #{arr.length}\"\nend\n"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n if a[0] + a[1] <= a[-1]\n ans << [1,2,n]\n else\n ans << [-1]\n end\nend\nans.each do |x|\n x.each do |v|\n print \"#{v} \"\n end\n puts \"\"\nend\n"}, {"source_code": "gets.to_i.times do\n gets\n arr = gets.split(' ').map(&:to_i)\n \n puts arr[0] + arr[1] > arr.last ? -1 : \"1 2 #{arr.length}\"\nend"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\nt.times {\n n = gets.chomp.to_i\n arr = gets.chomp.split(' ').map(&:to_i)\n if arr[n - 1] > (arr[0] + arr[1])\n puts '1 2 3'\n else\n puts '-1'\n end\n}"}, {"source_code": "\nt = gets.chomp.to_i\nt.times {\n n = gets.chomp.to_i\n arr = gets.chomp.split(' ').map(&:to_i)\n if arr[n - 1] >= (arr[0] + arr[1])\n puts '1 2 3'\n else\n puts '-1'\n end\n}\n\n"}], "src_uid": "341555349b0c1387334a0541730159ac"} {"source_code": "def solve\r\n str = gets.strip\r\n if str.split('').select { |e| e == 'B' }.length * 2 == str.length\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n\r\ngets.strip.to_i.times {\r\n solve\r\n}", "positive_code": [{"source_code": "t = gets.chomp.to_i\r\nfor _ in 0...t\r\n string = gets.chomp\r\n count_a, count_b, count_c = 0, 0, 0\r\n string.each_char{|char|\r\n if char == \"A\"\r\n count_a += 1\r\n elsif char == \"B\"\r\n count_b += 1\r\n else\r\n count_c += 1\r\n end\r\n }\r\n if count_a + count_c == count_b\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend"}, {"source_code": "t = gets.chomp.to_i\r\nfor _ in 0...t\r\n string = gets.chomp\r\n count_a, count_b, count_c = string.count(\"A\"), string.count(\"B\"), string.count(\"C\")\r\n if count_a + count_c == count_b\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend"}, {"source_code": "def solve\r\n str = gets.strip\r\n a = str.split('').select { |e| e == 'A' }\r\n b = str.split('').select { |e| e == 'B' }\r\n c = str.split('').select { |e| e == 'C' }\r\n if a.length.zero?\r\n if b.length == c.length\r\n puts \"YES\"\r\n return\r\n end\r\n end\r\n\r\n if c.length.zero?\r\n if b.length == a.length\r\n puts \"YES\"\r\n return\r\n end\r\n end\r\n\r\n res = b.length\r\n res -= a.length\r\n res -= c.length\r\n if res.zero?\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n \r\nend\r\n\r\ngets.strip.to_i.times {\r\n solve\r\n}"}, {"source_code": "# 6\r\n# ABACAB\r\n# ABBA\r\n# AC\r\n# ABC\r\n# CABCBB\r\n# BCBCBCBCBCBCBCBC\r\n\r\nn = gets.to_i\r\nputs(n.times.map do\r\n s = gets.strip\r\n loop do\r\n if s.include?('B') && s.include?('C')\r\n s = s.sub('B', '')\r\n s = s.sub('C', '')\r\n elsif s.include?('B') && s.include?('A')\r\n s = s.sub('B', '')\r\n s = s.sub('A', '')\r\n else\r\n break\r\n end\r\n end\r\n s.empty? ? 'YES' : 'NO'\r\nend.join(\"\\n\"))\r\n"}, {"source_code": "test_case = gets.to_i\r\n(1..test_case).each do |index|\r\n str = gets\r\n length = str.length - 1\r\n half = length / 2\r\n a = b = c = 0\r\n str.chars.each do |char|\r\n if char == 'A'\r\n a += 1\r\n elsif char == 'B'\r\n b += 1\r\n else\r\n c += 1\r\n end\r\n end\r\n if length % 2 == 0 && half == b\r\n puts 'YES'\r\n else\r\n puts 'NO'\r\n end\r\nend"}], "negative_code": [{"source_code": "test_case = gets.to_i\r\n(1...test_case).each do |index|\r\n str = gets\r\n length = str.length - 1\r\n half = length / 2\r\n a = b = c = 0\r\n str.chars.each do |char|\r\n if char == 'A'\r\n a += 1\r\n elsif char == 'B'\r\n b += 1\r\n else\r\n c += 1\r\n end\r\n end\r\n if length % 2 == 0 && half == b\r\n puts 'YES'\r\n else\r\n puts 'NO'\r\n end\r\nend"}, {"source_code": "test_case = gets.to_i\r\n(1...5).each do |index|\r\n str = gets\r\n length = str.length - 1\r\n half = length / 2\r\n a = b = c = 0\r\n str.chars.each do |char|\r\n if char == 'A'\r\n a += 1\r\n elsif char == 'B'\r\n b += 1\r\n else\r\n c += 1\r\n end\r\n end\r\n if length % 2 == 0 && half == b\r\n puts 'YES'\r\n else\r\n puts 'NO'\r\n end\r\nend"}, {"source_code": "test_case = gets.to_i\r\n(1...5).each do |index|\r\n str = gets\r\n length = str.length\r\n half = length / 2\r\n a = b = c = 0\r\n str.chars.each do |char|\r\n if char == 'A'\r\n a += 1\r\n elsif char == 'B'\r\n b += 1\r\n else\r\n c += 1\r\n end\r\n end\r\n if length % 2 == 0 && half == b\r\n puts 'YES'\r\n else\r\n puts 'NO'\r\n end\r\nend"}], "src_uid": "ca6b162f945d4216055bf92d7263dbd5"} {"source_code": "n, m = gets.split.map(&:to_i)\ns = gets.chomp\n\nm.times do |i|\n l, r, c1, c2 = gets.split\n l = l.to_i - 1\n r = r.to_i - 1\n s[l, r-l+1] = s[l, r-l+1].gsub(c1, c2)\nend\n\nputs s", "positive_code": [{"source_code": "gets\ns=gets.chomp\n$<.each{|_|\na,b,c,d=_.split\n(a.to_i-1...b.to_i).each{|i|s[i]=d if s[i]==c}\n}\nputs s"}, {"source_code": "n, m = gets.split(/\\s+/).map(&:to_i)\ns = gets.chomp\nm.times do\n\tl, r, c1, c2 = gets.split(/\\s+/)\n\tl = l.to_i - 1\n\tr = r.to_i - 1\n\t(l..r).each{ |i| s[i] = c2 if s[i] == c1 }\nend\nputs s\n"}, {"source_code": "str_length, changes = gets.chomp.split(' ').map(&:to_i)\nstring = gets.chomp\n\nchanges.times do\n l, r, target, new_val = gets.chomp.split(' ')\n l = l.to_i\n r = r.to_i\n\n (l..r).each do |i|\n string[i - 1] = new_val if string[i - 1] == target\n end\nend\n\nputs string\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\ns = gets.chomp\nm.times do\n l, r, c1, c2 = gets.chomp.split\n l = l.to_i\n r = r.to_i\n (l..r).each do |i|\n if s[i-1] == c1\n s[i-1] = c2\n end\n end\nend\nputs s"}, {"source_code": "x,n=gets.split.map{|e| e.to_i}\ns=gets.chomp\nn.times{\n\tl,r,e1,e2=gets.split\n\tl=l.to_i\n\tr=r.to_i\n\te2=e2.chomp\n\t(l..r).each{|i|\n\t\tbreak if s.size<=i-1\n\t\ts[i-1]=e2 if s[i-1]==e1\n\t}\n\t\n}\nputs s"}, {"source_code": "n, m=gets.split.map &:to_i\ns=gets.chomp\nm.times{\n l, r, a, b=gets.split\n l=l.to_i-1\n r=r.to_i\n while l 0\r\n t -= 1\r\n n = gets.to_i\r\n ar = gets.split(' ').map(&:to_i).sort\r\n \r\n print(ar[n - 1] + ar[n - 2], \"\\n\")\r\nend", "positive_code": [{"source_code": "t=gets.chomp.to_i\r\nt.times do |i|\r\n n=gets.chomp.to_i\r\n b=Array.new(n)\r\n s=gets.chomp.split(' ')\r\n for i in 0..s.length-1\r\n b[i]=s[i].to_i\r\n end\r\n puts (b.max(2)).sum\r\nend"}], "negative_code": [], "src_uid": "b856eafe350fccaabd39b97fb18d9c2f"} {"source_code": "infile = STDIN\ndays_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\ninput = infile.readline.chomp\nfound = Hash.new {0}\nlength = \"13-12-2013\".length\n(0..(input.size - length)).each do |i|\n substr = input[i, length]\n if substr =~ /((\\d\\d)-(\\d\\d)-(\\d\\d\\d\\d))/\n d, m, y = $2.to_i, $3.to_i, $4.to_i\n if (2013..2015) === y && (1..12) === m && d > 0 && d <= days_in_month[m - 1]\n found[$1] += 1\n end\n end\nend\nputs found.max_by { |k, v| v }.first", "positive_code": [{"source_code": "s=gets\n\nRUI=[1,3,5,7,8,10,12]\n\ndef digit? c\n c>= ?0 && c<= ?9\nend\n\ndef day? month, day\n return false if day==0\n if month==2\n return day<=28\n end\n \n if RUI.include?month\n return day<=31\n end\n \n return day<=30\nend\n\ndef valid? date\n return false if not /(?\\d{2})-(?\\d{2})-(?\\d{4})/ =~ date\n \n return false if year.to_i<2013 || year.to_i>2015\n return day? month.to_i,day.to_i\nend\n\nhm={}\nhm.default=0\nans=\"\"\n\n(0...s.length-10).each do |i|\n key=s[i,10]\n hm[key]+=1 if valid? key\n ans=key if ans==\"\" || hm[key]>hm[ans]\nend\n\nputs ans\n\n"}, {"source_code": "s=gets\n\nRUI=[1,3,5,7,8,10,12]\n\ndef digit? c\n c>= ?0 && c<= ?9\nend\n\ndef day? month, day\n return false if day==0\n if month==2\n return day<=28\n end\n \n if RUI.include?month\n return day<=31\n end\n \n return day<=30\nend\n\ndef valid? date\n return false if !digit?(date[0]) || !digit?(date[1])\n day=date[0,2].to_i\n date=date[2..-1]\n \n return false if digit? date[0]\n date=date[1..-1]\n \n return false if !digit?(date[0]) || !digit?(date[1])\n month=date[0,2].to_i\n date=date[2..-1]\n \n return false if digit? date[0]\n date=date[1..-1]\n \n return false if !digit?(date[0]) || !digit?(date[1]) || !digit?(date[2]) || !digit?(date[3])\n year=date[0,4].to_i\n\n return false if year<2013 || year>2015\n return day? month,day\nend\n\nhm={}\nhm.default=0\nans=\"\"\n\n(0...s.length-10).each do |i|\n key=s[i,10]\n hm[key]+=1 if valid? key\n ans=key if ans==\"\" || hm[key]>hm[ans]\nend\n\nputs ans\n\n"}, {"source_code": "s=gets\n\nRUI=[1,3,5,7,8,10,12]\n\ndef day? month, day\n return false if day==0\n if month==2\n return day<=28\n end\n \n if RUI.include?month\n return day<=31\n end\n \n return day<=30\nend\n\ndef valid? date\n return false if not /(?\\d{2})-(?\\d{2})-(?\\d{4})/ =~ date\n \n return false if year.to_i<2013 || year.to_i>2015\n return day? month.to_i,day.to_i\nend\n\nhm={}\nhm.default=0\nans=nil\n\n(0...s.length-10).each do |i|\n key=s[i,10]\n hm[key]+=1 if valid? key\n ans=key if hm[key]>hm[ans]\nend\n\nputs ans\n\n"}, {"source_code": "s=gets\nw = {\n\n}\nw.default=0\nans=-1;\nj = -1;\nm=[0,31,28,31,30,31,30,31,31,30,31,30,31]\n\ndef good?(s,m) \n\ta=s[0..1].to_i\n\tb=s[3..4].to_i\n\tc=s[6..9].to_i\n\tif c>=2013 and c<=2015 and b>=1 and b<=12 and a>=1 and a<=m[b] then\n\t\treturn true\n\tend\n\treturn false\nend\n\ns.length.times do |i|\n\tif s.length-10 <= i then\n\t\tbreak\n\tend\n\tt = s[i,10]\n\tif t =~ /\\d{2}-\\d{2}-\\d{4}/ and good?(t,m) then\n\t\tw[t]+=1\n\t\tif(ans 2015\n\tnext if month < 1 or month > 12\n\tnext if day < 1 or day > monthdays[month-1]\n\tif count.member? s\n\t\tcount[s] += 1\n\telse\n\t\tcount[s] = 1\n\tend\nend\narr = count.to_a.sort {|x, y| x[1]-y[1] }\nputs arr[-1][0]\n"}, {"source_code": "require 'date'\n\ndef run\n hash = Hash.new(0)\n\n line = ARGF.readline.chomp\n line.length.times do |i|\n begin\n str = line[i,10]\n if str =~ /[0-9]{2}-[0-9]{2}-[0-9]{4}/\n parse = Date.strptime(str, \"%d-%m-%Y\")\n hash[str] += 1 if parse.year.between?(2013, 2015)\n end\n rescue\n end\n end\n\n ret = hash.to_a.max_by { |item| item[1] }\n puts ret[0] if ret\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def is_date?(str)\n if not str =~ /\\d{2}-\\d{2}-\\d{4}/ then return false end\n m = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n (2013..2015) === str[6, 4].to_i and (1..12) === str[3, 2].to_i and (1..m[str[3, 2].to_i]) === str[0, 2].to_i\nend\nhsh = Hash.new(0)\ns = gets.chop!\n(0..(s.size - 10)).each do |i|\n t = s[i, 10]\n if is_date? t then hsh[t] += 1 end\nend\nputs hsh.max_by { |k, v| v} .first"}, {"source_code": "# 777-444---21-12-2013-12-2013-12-2013---444-777\nrequire 'Date'\n\ndef days_in_month(year, month)\n\tDate.new(year, month, -1).day\nend\ncount = Hash.new(0)\n\nl = gets.chomp.split(\"-\")\n# puts \"#{l}\"\nl.each_cons(3) do |(d,m,y)|\n\th = d.to_i\n\tif h > 0\n\t\tm = m.to_i\n\t\tif m >= 1 && m <= 12\t\t\t\n\t\t\t\n\t\t\ty = y.length > 4 ? y[0..3].to_i : y.to_i\n\t\t\td = d.length > 2 ? d[-2..-1].to_i : d.to_i\n\n\t\t\tif y >= 2013 && y <= 2015 && (d <= days_in_month(y,m))\n\t\t\t\tcount[\"#{d.to_s.rjust(2,\"0\")}-#{m.to_s.rjust(2,\"0\")}-#{y}\"] += 1\n\t\t\tend\n\t\tend \n\tend\t\nend\nmax = count.values.max\n# puts \"#{count}\"\n\nputs count.detect{|k,v| v == max}[0]"}, {"source_code": "days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\ninput = gets.chomp\nfound = Hash.new {0}\nlength = \"13-12-2013\".length\n(0..(input.size - length)).each do |i|\n substr = input[i, length]\n if substr =~ /((\\d\\d)-(\\d\\d)-(\\d\\d\\d\\d))/\n d, m, y = $2.to_i, $3.to_i, $4.to_i\n if (2013..2015) === y && (1..12) === m && d > 0 && d <= days_in_month[m - 1]\n found[$1] += 1\n end\n end\nend\n\nputs found.max_by { |k, v| v }.first"}, {"source_code": "s=gets\n\nRUI=[1,3,5,7,8,10,12]\n\ndef day? month, day\n return false if day==0\n if month==2\n return day<=28\n end\n \n if RUI.include?month\n return day<=31\n end\n \n return day<=30\nend\n\ndef valid? date\n return false if not /(?\\d{2})-(?\\d{2})-(?\\d{4})/ =~ date\n \n return false if year.to_i<2013 || year.to_i>2015\n return day? month.to_i,day.to_i\nend\n\nhm={}\nhm.default=0\nans=\"\"\n\n(0...s.length-10).each do |i|\n key=s[i,10]\n hm[key]+=1 if valid? key\n ans=key if ans==\"\" || hm[key]>hm[ans]\nend\n\nputs ans\n\n"}, {"source_code": "s=gets\n\nRUI=[1,3,5,7,8,10,12]\n\ndef digit? c\n c>= ?0 && c<= ?9\nend\n\ndef day? month, day\n return false if day==0\n if month==2\n return day<=28\n end\n \n if RUI.include?month\n return day<=31\n end\n \n return day<=30\nend\n\ndef valid? date\n return false if !digit?(date[0]) || !digit?(date[1])\n day=date[0,2].to_i\n date=date[2..-1]\n \n return false if digit? date[0]\n date=date[1..-1]\n \n return false if !digit?(date[0]) || !digit?(date[1])\n month=date[0,2].to_i\n date=date[2..-1]\n \n return false if digit? date[0]\n date=date[1..-1]\n \n return false if !digit?(date[0]) || !digit?(date[1]) || !digit?(date[2]) || !digit?(date[3])\n year=date[0,4].to_i\n\n return false if year<2013 || year>2015\n return day? month,day\nend\n\nhm={}\n(0...s.length-10).each do |i|\n key=s[i,10]\n if valid? key\n hm[key]? hm[key]+=1:hm[key]=1\n end\nend\n\nans=\"\"\n\nhm.each do |key,value|\n if ans==\"\" || value>hm[ans]\n ans=key\n end\nend\n\nputs ans\n\n"}], "negative_code": [{"source_code": "\ufeff# -*- encoding: utf-8 -*-\nrequire 'date'\n\ns = gets.chomp\nans = nil\n\n(9 .. s.length).each do |idx|\n s2 = s[idx - 9 .. idx]\n match = s2.match(/(3[01]|[12][0-9]|0[1-9])-(1[0-2]|0[1-9])-(201[3-5])/)\n next if not match\n \n year, month, date = match[3].to_i, match[2].to_i, match[1].to_i \n\n if Date.valid_date? year, month, date\n d = Date.new year, month, date\n if ans.nil? or d > ans\n ans = d\n end\n end\nend\n\nputs ans.strftime \"%d-%m-%Y\"\n"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\nrequire 'date'\n\ns = gets.chomp\ndate = nil\n\n(9 .. s.length).each do |idx|\n s2 = s[idx - 9 .. idx]\n match = s2.match(/(3[01]|[12][0-9]|0[1-9])-(1[0-2]|0[1-9])-(201[3-5])/)\n next if not match\n \n year, month, date = match[3].to_i, match[2].to_i, match[1].to_i \n\n if Date.valid_date? year, month, date\n d = Date.new year, month, date\n if date.nil? or d > date\n date = d\n end\n end\nend\n\nputs date.strftime \"%d-%m-%Y\"\n"}, {"source_code": "def is_date?(str)\n if not str =~ /\\d{2}-\\d{2}-\\d{4}/ then false end\n m = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n (2013..2015) === str[6, 4].to_i and (1..12) === str[3, 2].to_i and (1..m[str[3, 2].to_i]) === str[0, 2].to_i\nend\nhsh = Hash.new(0)\ns = gets.chop!\n(0..(s.size - 10)).each do |i|\n t = s[i, 10]\n if is_date? t then hsh[t] += 1 end\nend\nputs hsh.max_by { |k, v| v} .first\n"}, {"source_code": "# 777-444---21-12-2013-12-2013-12-2013---444-777\nrequire 'Date'\n\ndef days_in_month(year, month)\n\tDate.new(year, month, -1).day\nend\ncount = Hash.new(0)\n\nl = gets.chomp.split(\"-\")\n# puts \"#{l}\"\nl.each_cons(3) do |(d,m,y)|\n\th = d.to_i\n\tif h > 0\n\t\tm = m.to_i\n\t\tif m >= 1 && m <= 12\n\t\t\ty = y.to_i\n\t\t\tif y >= 2013 && y <= 2015\n\t\t\t\tif(h <= days_in_month(y,m))\n\t\t\t\t\tcount[\"#{d}/#{m}/#{y}\"] += 1\n\t\t\t\telsif(d[-2..-1].to_i <= days_in_month(y,m))\n\t\t\t\t\tcount[\"#{d[-2..-1]}-#{m}-#{y}\"] += 1\n\t\t\t\tend\n\n\t\t\tend\n\t\tend \n\tend\t\nend\nmax = count.values.max\n# puts \"#{count}\"\n\nputs count.detect{|k,v| v == max}[0]"}, {"source_code": "# 777-444---21-12-2013-12-2013-12-2013---444-777\nrequire 'Date'\n\ndef days_in_month(year, month)\n\tDate.new(year, month, -1).day\nend\ncount = Hash.new(0)\n\nl = gets.chomp.split(\"-\")\n# puts \"#{l}\"\nl.each_cons(3) do |(d,m,y)|\n\th = d.to_i\n\tif h > 0\n\t\tm = m.to_i\n\t\tif m >= 1 && m <= 12\n\t\t\ty = y.to_i\n\t\t\tif y >= 2013 && y <= 2015\n\t\t\t\tif(h <= days_in_month(y,m))\n\t\t\t\t\tcount[\"#{d}/#{m}/#{y}\"] += 1\n\t\t\t\telsif(d[-2..-1].to_i <= days_in_month(y,m))\n\t\t\t\t\tcount[\"#{d[-2..-1]}-#{m}-#{y}\"] += 1\n\t\t\t\tend\n\n\t\t\tend\n\t\tend \n\tend\t\nend\nmax = count.values.max\nputs \"#{count}\"\n\nputs count.detect{|k,v| v == max}[0]"}, {"source_code": "# 777-444---21-12-2013-12-2013-12-2013---444-777\nrequire 'Date'\n\ndef days_in_month(year, month)\n\tDate.new(year, month, -1).day\nend\ncount = Hash.new(0)\n\nl = gets.chomp.split(\"-\")\n# puts \"#{l}\"\nl.each_cons(3) do |(d,m,y)|\n\th = d.to_i\n\tif h > 0\n\t\tm = m.to_i\n\t\tif m >= 1 && m <= 12\n\t\t\ty = y.to_i\n\t\t\tif y >= 2013 && y <= 2015\n\t\t\t\t# if ( || h[-2..-1].to_i <= days_in_month(y,m))\n\t\t\t\tif(h <= days_in_month(y,m))\n\t\t\t\t\tcount[\"#{d}/#{m}/#{y}\"] += 1\n\t\t\t\tend\n\t\t\t\tif(d[-2..-1].to_i <= days_in_month(y,m))\n\t\t\t\t\tcount[\"#{d[-2..-1]}/#{m}/#{y}\"] += 1\n\t\t\t\tend\n\n\t\t\tend\n\t\tend \n\tend\t\nend\nmax = count.values.max\n# puts \"#{count}\"\n\nputs count.detect{|k,v| v == max}[0]"}, {"source_code": "days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\ninput = gets.chomp\nfound = Hash.new {0}\nlength = \"13-12-2013\".length\n(0..(input.size - length)).each do |i|\n substr = input[i, length]\n if substr =~ /((\\d\\d)-(\\d\\d)-(\\d\\d\\d\\d))/\n d, m, y = $2.to_i, $3.to_i, $4.to_i\n if (2013...2015) === y && (1..12) === m && d > 0 && d <= days_in_month[m - 1]\n found[$1] += 1\n end\n end\nend\n\nputs found.max_by { |k, v| v }.first"}, {"source_code": "s=gets\nw,ans,j={},-1,0\nw.default=0\ndef good?(day,month,year) \n\tbegin\n\t\tt = Time.new(year,month,day)\n\t\tif t<=Time.new(2015,12,31) and t>=Time.new(2013,1,1) then\n\t\t\treturn true\n\t\tend\n\trescue\n\t\treturn false\n\tend\n\treturn false\nend\ns.scan(/(?\\d{2})-(?\\d{2})-(?\\d{4})/).each do |item|\n\tif(good?(item[0].to_i,item[1].to_i,item[2].to_i)) then\n\t\tw[$&]+=1\n\t\tif ans=Time.new(2013,1,1) then\n\t\t\treturn true\n\t\tend\n\trescue\n\t\treturn false\n\tend\n\treturn false\nend\ns.scan(/(?\\d{2})-(?\\d{2})-(?\\d{4})/).each do |item|\n\tif(good?(item[0].to_i,item[1].to_i,item[2].to_i)) then\n\t\tt = \"\" << item[0]<<'-'<< item[1]<< '-' << item[2]\n\t\tw[t]+=1\n\t\tif ans ans then ans = sum end\n\tend\nend\nprint ans", "positive_code": [{"source_code": "n = gets.to_i\n\nmas = gets.split.map{|i| i.to_i}\n\nxor = []\n\n\ni = 0\nwhile i < n do\n j = i + 1\n xor << mas[i]\n while j < n do\n xor << (xor[-1]^mas[j])\n j += 1\n end\n i += 1\nend\n\nxor = xor.sort\n\nputs xor[-1]"}, {"source_code": "n=gets\na=gets.split.map(&:to_i)\nmax=a.max\nfor i in 0...a.size do\n\tfor j in i...a.size do\n\t\ttm=a[i]\n\t\ta[i+1..j].each{|e| tm=tm ^ e} if i!=j\n\t\tmax=tm if tm>max \n\tend\nend\nputs max\n\t\t\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nmax = 0\nfor i in 0...n\n xor = 0\n for j in i...n\n xor = xor^a[j]\n if xor > max then max = xor end\n end\nend\nprint max"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\nt = gets.split.map(&:to_i)\nresult = 0\nn.times do |d|\n (0..(n - d - 1)).each do |i|\n x = 0\n (i..(i + d)).each do |j|\n x ^= t[j]\n end\n result = [result, x].max\n end\nend\nputs result"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\nret = []\nfor i in 0...n do\n t = 0\n for j in i...n do\n t ^= a[j]\n ret << t \n end\nend\nputs ret.max"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nres=a.max\nfor i in 0..n-1 do\n t=a[i]\n for j in i+1..n-1 do\n t^=a[j]\n res=t if res ans\n\t}\nend\nputs ans\n"}, {"source_code": "\n\nn = gets.chomp.to_i\nline = gets.chomp.split(\" \").collect! {|x| x.to_i}\nmax = 0\n(0..(n-1)).each {|k|\n (k..(n-1)).each { |t|\n p = 0\n (k..t).each {|q|\n p ^= line[q]\n }\n if p> max\n\tmax = p\n end\n }\n \n}\n\nputs max"}, {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i).unshift(0)\nn.times { |i| x[i+1] ^= x[i] }\nmx = 0\n1.upto(n) do |i|\n\ti.upto(n) do |j|\n\t\tmx = [mx, x[j] ^ x[i-1]].max\n\tend\nend\nputs mx\n"}, {"source_code": "t = gets.to_i\n\na = gets.split.collect{|x| x.to_i}\n\nr = 0\n\ni = 0\nwhile i < a.size\n\tj = i\n\twhile j < a.size\n\t\tt = a[i]\n\t\t\n\t\tk = i+1\n\n\t\twhile k <= j\n\t\t\t\n\t\t\tt ^= a[k]\n\t\t\tk += 1\n\t\tend\n\n\t\tr = [t,r].max\n\t\tj += 1\n\tend\n\ti+=1\nend\n\nputs r"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\nt = gets.split.map(&:to_i)\nresult = 0\nn.times do |d|\n (0..(n - d - 1)).each do |i|\n x = 0\n (i..(i + d)).each do |j|\n x |= t[j]\n end\n result = [result, x].max\n end\nend\nputs result"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nres=0\nfor i in 0..n-1 do\n t=a[i]\n for j in i+1..n-1 do\n t^=a[j]\n end\n res=t if res ans\nend\nputs ans\n"}, {"source_code": "\n\nn = gets.chomp.to_i\nline = gets.chomp.split(\" \").collect! {|x| x.to_i}\nmax = 0\n(0..(n-1)).each {|k|\n p = 0\n (k..(n-1)).each { |t|\n p ^= line[t]\n }\n if p> max\n\tmax = p\n end\n}\n\nputs max"}, {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\nn.times { |i| i > 0 ? x[i] ^= x[i-1] : 1 }\nmx = x[0]\n1.upto(n-1) do |i|\n\ti.upto(n-1) do |j|\n\t\tmx = [mx, x[j] ^ x[i-1]].max\n\tend\nend\nputs mx\n"}, {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\nn.times { |i| i ? x[i] ^= x[i-1] : _ }\nmx = x[0]\n1.upto(n-1) do |i|\n\ti.upto(n-1) do |j|\n\t\tmx = [mx, x[j] ^ x[i-1]].max\n\tend\nend\nputs mx\n"}], "src_uid": "a33991c9d7fdb4a4e00c0d0e6902bee1"} {"source_code": "# Codeforces, Problem 1B\n# http://codeforces.com/contest/1/problem/B\n# Nate Collings\n\ndef first_int(cell)\n cell.split('').each_with_index do |char, i|\n begin\n Integer(char)\n return i\n rescue ArgumentError\n end\n end\nend\n\ndef abc_to_int(str)\n num = 0\n power = 1\n str.reverse.split('').each do |char|\n num += (char.ord - 'A'.ord + 1) * power\n power *= 26\n end\n num\nend\n\ndef convert_row_col_to_standard(r, c)\n dividend = c\n column = ''\n while dividend > 0\n remainder = (dividend - 1) % 26\n column = (65 + remainder).chr + column\n dividend = ((dividend - remainder) / 26).to_i\n end\n \"#{column}#{r}\"\nend\n\ndef to_standard(cell)\n c_index = cell.index('C')\n row = cell[1...c_index].to_i\n col = cell[c_index+1..-1].to_i\n convert_row_col_to_standard(row, col)\nend\n\ndef to_rxcy(cell)\n r_index = first_int(cell)\n col = abc_to_int(cell[0...r_index])\n row = cell[r_index..-1]\n \"R#{row}C#{col}\"\nend\n\ndef is_rxcy?(cell)\n /R[0-9]+C[0-9]+/.match(cell)\nend\n\ngets.chomp.to_i.times do\n cell = gets.chomp\n if is_rxcy?(cell)\n puts to_standard(cell)\n else\n puts to_rxcy(cell)\n end\nend\n", "positive_code": [{"source_code": "n = gets.to_i\n1.upto(n) do\n str = gets\n state = 0\n 0.upto(str.size-1) do |i|\n if str[i].ord>=48 and str[i].ord<=57\n state+=1 if state%2==0\n else\n state+=1 if state%2==1\n end\n end\n if state==2\n col = nil\n row = nil\n 0.upto(str.size-1) do |i|\n if str[i].ord>=48 and str[i].ord<=57\n col = str[0..i-1]\n row = str[i..-1].strip\n break\n end\n end\n coln = 0\n 0.upto(col.size-1) do |i|\n coln *= 26\n coln += col[i].ord-64\n end\n puts \"R#{row}C#{coln}\"\n else\n row = nil\n col = nil\n ci = nil\n 0.upto(str.size-1) do |i|\n if str[i].ord == 67\n ci = i\n end\n end\n row = str[1..ci-1]\n col = str[ci+1..-1].to_i\n cols = \"\"\n while col>0\n if col%26==0\n cols = \"Z\" + cols\n col = (col-1)/26\n else\n cols = (col%26+64).chr + cols\n col /= 26\n end\n end\n puts cols+row\n end\nend\n"}, {"source_code": "\t#recibiendo el numero de iteraciones\n\tinput=gets.chomp\n\tn=input.to_i\n\t#metodo para saber si la cadena es excel o random\n\tdef validar_excel(a)\n\t\tif (a.include?(\"R\") && a.include?(\"C\")) #como el metodo random tiene R&C \n\t\t\tir=a.index(\"R\") \n\t\t\tic=a.index(\"C\")\n\t\t\t\n\t\t\tif a.index(\"R\")==0\n\t\t\t\tif a.index(\"C\")==1\n\t\t\t\t\treturn true\n\t\t\t\telse\n\t\t\t\t\tnum_char=0\n\t\t\t\t\t0.upto(a.size-1) do |j|\n\t\t\t\t\t\tif (a[j].ord>=48 && a[j].ord<=57) #ASCII para diferenciar num & str\n\t\t\t\t\t\t\tnum_char+=0\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tnum_char+=1\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\t\t\n\t\t\t\t\treturn num_char==2? false : true\n\t\t\t\tend\t\t\t\t\n\t\t\telse\n\t\t\t\treturn true\n\t\t\tend\n\t\telse\n\t\t\treturn true\n\t\tend\n\tend\n\t#revisar\n\tdef convertir(ar)\n\t\tn=ar.size-1\t\n\t\ti=0\n\t\tnum=0\n\t\t\n\t\tloop do\n\t\t\tif n<0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\t\n\t\t\tnum=num+(ar[i].ord-64)*(26**n)\n\t\t\tn-=1\n\t\t\ti+=1\n\t\tend\n\t\t\n\t\treturn num\n\tend\n\t\n\t#primer metodo de BC23 a R23C55\n\tdef excel_to_random(arr)\n\t\tparte_num=\"\"\n\t\tparte_str=\"\"\n\t\t\n\t\t0.upto(arr.size-1) do |k|\n\t\t\tif (arr[k].ord>=48 && arr[k].ord<=57) #ASCII para diferenciar num & str\n\t\t\t\tparte_num=parte_num+arr[k]\n\t\t\telse\n\t\t\t\tparte_str=parte_str+arr[k]\n\t\t\tend\n\t\tend\n\t\n\t\tparte_c=convertir(parte_str)\n\t\trandom=\"R\"+parte_num+\"C\"+\"#{parte_c}\" #creando el random\n\t\t\n\t\treturn random\n\tend\n\t\n\t#metodo divisiones sucesivas?\n\tdef divsuc(num)\n\t\tnum_car=26\n\t\tpivot=num\n\t\tndig=0\n\t\tarreglo_num=[]\n\t\tpotencia=1\n\t\t\n\t\tloop do\n\t\t\tpivot=pivot-26**potencia\n\t\t\tndig+=1\n\t\t\tpotencia+=1\n\t\t\tif pivot<=0\n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\t\t\n\t\t#real deal\n\t\tloop do\n\t\t\tif num==0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tif num%num_car !=0\n\t\t\t\tarreglo_num[ndig-1]=((num%num_car)+64).chr()\n\t\t\t\tnum=num/num_car\n\t\t\telse #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)\n\t\t\t\tq=num/num_car\n\t\t\t\tnum=q-1\n\t\t\t\tarreglo_num[ndig-1]=(num_car+64).chr()\n\t\t\tend\n\t\t\tndig-=1\n\t\tend\n\t\treturn arreglo_num\n\tend\n\t\n\t#segundo metodo de R23C55 a BC23\n\tdef random_to_excel(arr)\n\t\trow=\"\"\n\t\tcol=\"\"\n\t\ta=0\n\t\t\n\t\t1.upto(arr.size-1) do |k|\n\t\t\t(arr[k]==\"C\")? a+=1:a+=0\n\n\t\t\tif a==0\n\t\t\t\trow=row+arr[k]\n\t\t\telse\n\t\t\t\tif (arr[k]!=\"C\") \n\t\t\t\t\tcol=col+arr[k]\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tcol=col.to_i\n\t\tcole=divsuc(col)#convertir la columna a excel\n\t\texcel=cole.join+row\n\t\t\n\t\treturn excel\n\tend\n\t\n\t$res=[] #definici\u00f3n de la variable GLOBAL, para poder imprimirlo despu\u00e9s\n\t\n\t0.upto(n-1) do |j|\n\t\tcadena=gets.chomp.upcase\n\t\tarray=cadena.split(\"\")\n\t\ti=validar_excel(array)\n\t\t\n\t\tif i\n\t\t\tresultado=excel_to_random(array) #TRUE ES excel\n\t\telse\n\t\t\tresultado=random_to_excel(array)\n\t\tend\n\t\t\t\n\t\t$res[j]=resultado \t#recordar que el puts imprime con /n y el print no lo hace\n\tend\n\t#IMPRIMIR RESULTADO\n\tputs $res"}, {"source_code": "d=[*?A..'BEAAA'];def t s;p=a=0;s.each_char{|c|a+=(c.ord-?A.ord+1)*26**p;p+=1};a;end;gets.to_i.times{l=gets;puts (if /R(\\d+)C(\\d+)/.match l;\"#{d[$2.to_i-1]}#{$1}\";else;a,b=l.scan(/([A-Z]+)(\\d+)/)[0];\"R#{b}C#{t a.reverse}\";end)}"}, {"source_code": "def excel_to_index(number)\n row = number.gsub(/[a-zA-Z]/, '').chomp\n column = number.gsub(/\\d/, '').chomp\n\n length = column.length\n column_index = 0\n column.each_char do |c|\n column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))\n length -= 1\n end\n\n 'R' + row + 'C' + column_index.to_s\nend\n\ndef index_to_excel(number)\n row, column = number.sub(/R/, '').split(/C/).map(&:to_i)\n\n result = []\n begin\n x = column % 26\n x = 26 if 0 == x\n column = (column - x) / 26\n\n result.push x\n end while column > 0\n\n column_letters = ''\n result.reverse_each { |e| \n column_letters += (e.ord + 'A'.ord - 1).chr\n }\n\n column_letters + row.to_s\nend \n\ncount = gets.to_i\n\ncount.times do\n num = gets.upcase\n if num[/R\\d+C\\d+/]\n puts index_to_excel num\n else\n puts excel_to_index num\n end \nend"}, {"source_code": "d=[*?A..'BEAAA'];def t s;p=a=0;s.each_char{|c|a+=(c.ord-?A.ord+1)*26**p;p+=1};a;end;gets.to_i.times{l=gets;puts (if /R(\\d+)C(\\d+)/.match l;\"#{d[$2.to_i-1]}#{$1}\";else;a,b=l.scan(/([A-Z]+)(\\d+)/)[0];\"R#{b}C#{t a.reverse}\";end)}"}, {"source_code": "d=[*?A..'BEAAA'];def t s;p=a=0;s.each_char{|c|a+=(c.ord-?A.ord+1)*26**p;p+=1};a;end;gets.to_i.times{l=gets;puts (if /R(\\d+)C(\\d+)/.match l;\"#{d[$2.to_i-1]}#{$1}\";else;a,b=l.scan(/([A-Z]+)(\\d+)/)[0];\"R#{b}C#{t a.reverse}\";end)}"}, {"source_code": "# Codeforces 1B\n# TAG: Math\n\ndef rc2xls(r, c)\n a = []\n while c > 0 do a << ((c-1) % 26 + 1); c = (c-a.last)/26 end\n \"#{a.reverse.reduce(\"\") {|s, i| s += (i+64).chr }}#{r}\"\nend\n\ndef xls2rc(s)\n /(?[A-Z]+)(?\\d+)/ =~ s\n c = c.split(//).map(&:ord).reduce(0) {|s, i| s = s*26 + i - 64 }\n \"R#{r}C#{c}\"\nend\n\ngets.to_i.times do\n puts /R(?\\d+)C(?\\d+)/ =~ (s = gets) ? rc2xls(r.to_i, c.to_i) : xls2rc(s)\nend\n"}, {"source_code": "def f(r,c)a=[]\nwhile c>0;t=((c-1)%26+1);a=[t]+a;c=(c-t)/26 end\n\"#{a.reduce(\"\"){|s,i|s+=(i+64).chr}}#{r}\"\nend\ndef g(s)/(?\\D+)(?\\d+)/=~s\n\"R#{r}C#{c.split(//).map(&:ord).reduce(0){|s,i|s=s*26+i-64}}\"\nend\ngets.to_i.times {puts /R(?\\d+)C(?\\d+)/=~(s=gets)?f(r,c.to_i):g(s)}"}, {"source_code": "def f(r,c)\na=[]\nwhile c>0 do t=((c-1)%26+1);a<\\D+)(?\\d+)/=~s\n\"R#{r}C#{c.split(//).map(&:ord).reduce(0){|s,i|s=s*26+i-64}}\"\nend\ngets.to_i.times do\nputs /R(?\\d+)C(?\\d+)/=~(s=gets)?f(r.to_i,c.to_i):g(s)\nend\n"}, {"source_code": "def rc2xls(r, c)\n a = []\n while c>0 do a << ((c-1) % 26 + 1); c = (c-a.last)/26 end\n \"#{a.reverse.reduce(\"\") {|s,i| s += (i+64).chr }}#{r}\"\nend\n\ndef xls2rc(s)\n /(?[A-Z]+)(?\\d+)/ =~ s\n \"R#{r}C#{c.split(//).map(&:ord).reduce(0) {|s,i| s = s*26+i-64 }}\"\nend\n\ngets.to_i.times do\n puts /R(?\\d+)C(?\\d+)/ =~ (s = gets) ? rc2xls(r.to_i, c.to_i) : xls2rc(s)\nend"}, {"source_code": "# Codeforces 1B\n# TAG: Math\n\ndef rc2xls(r, c)\n a = []\n while c>0\n t = ((c-1)%26+1)\n a << t\n c = (c-t)/26\n end\n \"#{a.reverse.reduce(\"\") {|s,i| s += (i+64).chr }}#{r}\"\nend\n\ndef xls2rc(s)\n /(?\\D+)(?\\d+)/ =~ s\n \"R#{r}C#{c.split(//).map(&:ord).reduce(0) {|s, i| s = s*26+i-64 }}\"\nend\n\ngets.to_i.times do\n puts /R(?\\d+)C(?\\d+)/ =~ (s = gets) ? rc2xls(r, c.to_i) : xls2rc(s)\nend\n"}, {"source_code": "def f(s)\n r=0\n s.each_byte{|c| r=r*26+c-64}\n r\nend\ndef g(n)\n r=\"\"\n while n>0 do\n x=n%26\n if x==0 then\n x=26\n n-=x\n end\n r=(x+64).chr+r\n n/=26\n end\n r\nend\nn=gets.to_i\nn.times{\n s=gets\n if s=~/^([A-Z]+)(\\d+)$/ then\n puts \"R\"+$2.to_s+\"C\"+f($1).to_s\n end\n if s=~/R(\\d+)C(\\d+)/ then\n puts g($2.to_i)+$1\n end\n}"}, {"source_code": "\ndef a_to_n(line)\n length = line.length\n i = 0\n sum = 0\n while i < length\n sum = sum * 26 + (line[i].ord - 'A'.ord + 1) \n i = i + 1\n end\n return sum\nend\n\ndef n_to_a(line)\n\n row_str = \"\"\n row_num = line.to_i\n while row_num > 0\n if(row_num % 26 != 0)\n row_str.prepend( (64 + row_num % 26).chr) \n row_num = row_num/26\n else\n row_str.prepend('Z') \n row_num = row_num/26 - 1\n end\n \n end\n return row_str\n\nend\n\ndef xy_to_rc(line)\n col_size = line =~ /[0-9]/\n\n col_str = line[0...col_size]\n row_str = line[col_size...-1]\n\n col = a_to_n(col_str)\n row = row_str.to_i\n\n print(\"R\")\n print(row)\n print(\"C\")\n print(col)\n\nend\n\ndef rc_to_xy(line)\n col_size = line =~ /[C]/\n\n row_str = line[1...col_size]\n col_str = line[col_size+1...-1]\n\n col = n_to_a(col_str)\n row = row_str.to_i\n\n print(col)\n print(row)\nend\n\ndef isrc(line)\n if line[0] == 'R' && line[1] =~ /[0-9]/\n if line[2...-1].include? \"C\"\n return true\n end\n end\n return false\nend\n\n\nline_count = gets.to_i\n\nwhile line_count > 0 \n line_string = gets\n if isrc(line_string)\n rc_to_xy(line_string)\n else\n xy_to_rc(line_string)\n end\n print(\"\\n\")\n line_count = line_count-1\nend\n"}, {"source_code": "def to_ex d\n str = \"\"\n while d > 0\n d, a = (d - 1).divmod(26)\n str = (a + 65).chr + str\n end\n str\nend\n\ndef ex_to str\n str.chars.each.with_index.inject(0){ |z, (v, i)| z = z * 26 + (v.ord - 64) }\nend\n\ndef solution str\n a, b = str.scan(/\\d+/).map(&:to_i)\n if b\n \"#{to_ex(b)}#{a}\"\n else\n a, b = str.scan(/([A-Z]+)(\\d+)/).first\n \"R#{b}C#{ex_to(a)}\"\n end \nend\n\nn = STDIN.gets.to_i\nArray.new(n){ solution(STDIN.gets.chomp) }.each{ |v| print v, \"\\n\" }"}, {"source_code": "def convert(s)\n if (s =~ /R([0-9]+)C([0-9]+)/)\n c, r = $1, $2.to_i\n \n x = 1\n t = 26\n while r > t do\n r -= t\n x += 1\n t *= 26\n end\n\n d = []\n r -= 1\n for i in 0..x - 1\n d.push(r % 26) \n r /= 26\n end\n\n r = \"\"\n for i in (d.size - 1).step(0, -1)\n r += (d[i] + 'A'.ord).chr\n end\n return r + c\n elsif (s =~ /([A-Z]+)([0-9]+)/ )\n c, r = $1, $2\n\n\n ans, w = 0, 26\n for i in 1..c.size - 1\n ans += w\n w *= 26\n end\n\n cw = 0\n for i in 0..c.size - 1\n cw = c[i].ord - 'A'.ord + cw * 26\n end\n return 'R' + r + 'C' + (cw + 1 + ans).to_s\n end\nend\n\nn = gets.to_i\n\nfor cas in 0..n - 1\n s = gets\n ans = convert(s)\n puts(ans)\nend\n"}, {"source_code": "pattern_r = /R[0-9]+C[0-9]+/\npattern_a = /[A-Z]+[0-9]+/\nn = gets.to_i\nfor i in 0...n\n s = gets\n if pattern_r =~ s\n x = s[/\\d+/]\n y = s[/(C)(\\d+)/, 2]\n y = y.to_i\n ans1 = \"\"\n while y != 0\n if y % 26 == 0\n ans1 = 'Z' << ans1\n y = y - 26\n else\n ans1 = ('A'.ord + y % 26 - 1).chr << ans1\n end\n y = y / 26\n end\n puts ans1 << x\n else\n x = s[/[A-Z]+/]\n y = s[/\\d+/]\n ans1 = 0\n x.each_byte do |c|\n ans1 = ans1 * 26 + (c - \"A\".bytes.to_a[0]) + 1\n end\n puts \"R\" << y << \"C\" << ans1.to_s\n end\nend"}, {"source_code": "LettersCount = 'Z'.ord - 'A'.ord + 1\n\ndef intToLetters(i)\n result = ''\n while i > 0\n i -= 1\n letter = ('A'.ord + i % LettersCount).chr\n result << letter\n i /= LettersCount\n end\n result.reverse!\nend\n\ndef lettersToInt(l)\n result = 0\n l.each_char {\n |char|\n result *= LettersCount \n result += char.ord - 'A'.ord + 1\n }\n result\nend\n\ndef format2to1(r, c)\n intToLetters(c) + r.to_s\nend\n\ndef format1to2(c, r)\n 'R' + r + 'C' + lettersToInt(c).to_s\nend\n\nresult = []\n\nline = $stdin.gets\nn = line.to_i\n(1..n).each do\n line = $stdin.gets\n match = /R(\\d+)C(\\d+)/.match(line)\n if match\n captures = match.captures.map {|x| x.to_i} \n result << format2to1(captures[0], captures[1])\n elsif\n captures = /([^\\d]+)(\\d+)/.match(line).captures\n result << format1to2(captures[0], captures[1])\n end\nend\n\nresult.each do |x|\n puts x\nend\n"}, {"source_code": "#!/bin/ruby\n\n$ASCII_CODE_A = \"A\".bytes.to_a[0]\n\ndef to_alpha(n)\n ary = Array.new\n while n > 0\n c = ($ASCII_CODE_A + (n - 1) % 26).chr\n ary << c\n n = (n - 1) / 26\n end\n return ary.reverse.join\nend\n\ndef to_number(as)\n n = 0\n as.each_byte do |c|\n n *= 26\n n += c - $ASCII_CODE_A + 1\n end\n return n\nend\n\nn = gets.to_i\n(1..n).step do |i|\n input = gets\n if input =~ /^R(\\d+)C(\\d+)$/ then\n row = $1\n col = to_alpha($2.to_i)\n puts col + row\n elsif input =~ /^([A-Z]+)(\\d+)$/ then\n row = $2\n col = to_number($1).to_s\n puts \"R\" + row + \"C\" + col\n end\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef get_series_string(n)\n return \"\" if n == 0\n n = n - 1\n q = n/26\n r = n%26\n return \"#{get_series_string(q)}#{(r+65).chr}\"\nend\n\ndef get_number_for_series(str)\n n = 0\n str.chars.each do | c |\n n = n * 26 + c.ord - 65 + 1\n end\n return n\nend\n\ns = gets.to_i\na = []\nwhile s > 0 do\n a << gets.chomp!\n s -= 1\nend\n\na.each do |e|\n parsed = e.scan(/([A-Z]+)(\\d+)/)\n if parsed.length == 2\n puts \"#{get_series_string(parsed[1][1].to_i)}#{parsed[0][1]}\"\n elsif parsed.length == 1\n puts \"R#{parsed[0][1]}C#{get_number_for_series(parsed[0][0])}\"\n end\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef get_series_string(n)\n str = \"\"\n while n > 0 do\n q = (n - 1) / 26\n r = (n - 1) % 26\n str = \"#{(r + 65).chr}#{str}\"\n n = q\n end\n return str\nend\n\ndef get_number_for_series(str)\n n = 0\n str.chars.each do | c |\n n = n * 26 + c.ord - 65 + 1\n end\n return n\nend\n\ns = gets.to_i\ns.times do\n e = gets.chomp!\n parsed = e.scan(/([A-Z]+)(\\d+)/)\n if parsed.length == 2\n puts \"#{get_series_string(parsed[1][1].to_i)}#{parsed[0][1]}\"\n elsif parsed.length == 1\n puts \"R#{parsed[0][1]}C#{get_number_for_series(parsed[0][0])}\"\n end\n s -= 1\nend\n"}, {"source_code": "gets.to_i.times do\n\tgets\n\tif /^(\\D+)(\\d+)$/ then\n\t\tputs \"R#{$2}C#{(0..$1.size-1).map{|i|26**i}.inject{|i,j|i+j}+$1.tr('A-Z','0-9A-Z').to_i(26)}\"\n\telsif /R(.*)C/ then\n\t\tl,n=-1,$'.to_i\n\t\tn-=26**(l+=1) while n>=0\n\t\tn+=26**l\n\t\tputs n.to_s(26).tr('0-9a-z','A-Z').rjust(l,'A')+$1\n\tend\nend"}, {"source_code": "r = /R\\d+C\\d+/\nrow_regex = /\\d+/\n\nn = gets.chomp.to_i\n\nn.times do\n line = gets.chomp\n if line.match(r)\n row = line[1.. (line =~ /C/)].to_i\n c = line[(line =~ /C/)+1..-1].to_i\n a = 0; b = 0\n a = c\n res = \"\"\n while (a+26) > 26\n a = c / 26\n \t\t\tb = c % 26 == 0 ? 26 : c % 26\n \t\t\ta = c % 26 == 0 ? a - 1 : a\n \t\t\tc = a\n res.prepend(((b-1) + 65).chr)\n end\n puts \"#{res}#{row}\"\n else\n num_index = line =~ row_regex\n row = line[num_index..line.length()]\n col = 0\n col_str = line[0..num_index-1]\n col_str.split('').map.with_index do |chr, i|\n col += (chr.ord - 'A'.ord + 1) * (26 ** (num_index-1-i))\n end\n puts \"R#{row}C#{col}\"\n end\nend\n"}, {"source_code": "number_of_input=gets.to_i\ninput_arry=[]\ni_a=0\n\n\nloop do\n\tbreak if i_a==number_of_input\n\tinput_arry[i_a]=gets.chomp\n\ti_a +=1\nend\n\nvalue=(1..26)\nalph=('A'..'Z')\nvalue=[*value]\nalph=[*alph]\n@hash={}\ni_b=0\n\nloop do\n\tbreak if i_b==26\n\t@hash[alph[i_b]]=value[i_b]\n\ti_b+=1\nend\t\n\n\n\ndef S1_to_S2 (a1)\n\tr=a1[0]\n\ti=1\n\t\n\tloop do\n\t\tbreak if a1[i].to_i !=0\n\t\tr =r + a1[i]\n\t\ti+=1\n\tend\n\n\tr1=r.length\n\tr2=a1.length\n\tc1= a1[0 .. (r1-1)].reverse\n\trow= a1[ r1 .. r2].to_i\n\tc=0\n\ti=0\n\t\n\tloop do\n\t\tbreak if i==c1.length\n\t\tc= c + (@hash[c1[i]]*(26**i))\n\t\ti+=1\n\tend\n\t\n\tputs \"R#{row}C#{c}\"\nend\n\ndef S2_to_S1 (a1)\n\ts2=a1.split(\"\").map{|s| s}\n\tr3=3\n\ts2.find {|i| r3=s2.index(i)+1 if i=='C'}\n\ti=s2[r3 .. (s2.length - 1)].join.to_i\n\trow=s2[1 .. (r3-2)].join.to_i\n\tstr_c=\"\"\n\t\n\tloop do\n\t\ti=i-26 if i>25 && i%26==0\n\t\tif i%26==0\n\t\tstr_c = str_c + \"Z\"\n\t\telse\n\t\tstr_c = str_c + @hash.key(i%26)\n\t\tend\n\t\ti=i/26\n\t\tbreak if i==0\n\tend\n\t\n\tstr_c=str_c.reverse\n\tputs \"#{str_c}#{row}\"\nend\n\t\ni_c =0\n\nloop do\n break if i_c==input_arry.length\n\tinput1=input_arry[i_c]\n\t\n\tif \tinput1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0) \n\t\tS1_to_S2 (input1)\n\telsif input1[0]=='R' && input1[1].to_i!=0\n\t\tk2=input1.split(\"\")\n\t\tk=0\n\t\tk2.find{|s| k=1 if s=='C'}\n\t\tif k==1\n\t\t\tS2_to_S1(input1)\n\t\telse\n\t\t\tS1_to_S2 (input1)\n\t\tend\t\n\tend\n\t\n\ti_c +=1\n\t\nend"}, {"source_code": "number_of_input=gets.to_i\ninput_arry=[]\ni=0\n\n\nloop do\n\tbreak if i==number_of_input\n\tinput_arry[i]=gets.chomp\n\ti +=1\nend\n\nvalue=(1..26)\nalph=('A'..'Z')\nvalue=[*value]\nalph=[*alph]\n@hash={}\ni=0\n\nloop do\n\tbreak if i==26\n\t@hash[alph[i]]=value[i]\n\ti+=1\nend\t\n\n\n\ndef S1_to_S2 (a1)\n\tr=a1[0]\n\ti=1\n\t\n\tloop do\n\t\tbreak if a1[i].to_i !=0\n\t\tr =r + a1[i]\n\t\ti+=1\n\tend\n\n\tr1=r.length\n\tr2=a1.length\n\tc1= a1[0 .. (r1-1)].reverse\n\trow= a1[ r1 .. r2].to_i\n\tc=0\n\ti=0\n\t\n\tloop do\n\t\tbreak if i==c1.length\n\t\tc= c + (@hash[c1[i]]*(26**i))\n\t\ti+=1\n\tend\n\t\n\tputs \"R#{row}C#{c}\"\nend\n\ndef S2_to_S1 (a1)\n\ts2=a1.split(\"\").map{|s| s}\n\tr3=3\n\ts2.find {|i| r3=s2.index(i)+1 if i=='C'}\n\ti=s2[r3 .. (s2.length - 1)].join.to_i\n\trow=s2[1 .. (r3-2)].join.to_i\n\tstr_c=\"\"\n\t\n\tloop do\n\t\ti=i-26 if i>25 && i%26==0\n\t\tif i%26==0\n\t\tstr_c = str_c + \"Z\"\n\t\telse\n\t\tstr_c = str_c + @hash.key(i%26)\n\t\tend\n\t\ti=i/26\n\t\tbreak if i==0\n\tend\n\t\n\tstr_c=str_c.reverse\n\tputs \"#{str_c}#{row}\"\nend\n\t\ni=0\n\nloop do\n break if i==input_arry.length\n\tinput1=input_arry[i]\n\t\n\tif \tinput1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0) \n\t\tS1_to_S2 (input1)\n\telsif input1[0]=='R' && input1[1].to_i!=0\n\t\tk2=input1.split(\"\")\n\t\tk=0\n\t\tk2.find{|s| k=1 if s=='C'}\n\t\tif k==1\n\t\t\tS2_to_S1(input1)\n\t\telse\n\t\t\tS1_to_S2 (input1)\n\t\tend\t\n\tend\n\t\n\ti +=1\n\t\nend"}, {"source_code": "\n\nnumber_of_input=gets.to_i\ninput_arry=[]\ni_a=0\n\n\nloop do\n\tbreak if i_a==number_of_input\n\tinput_arry[i_a]=gets.chomp\n\ti_a +=1\nend\nvalue=(1..26)\nalph=('A'..'Z')\nvalue=[*value]\nalph=[*alph]\n@hash={}\ni_b=0\n\nloop do\n\tbreak if i_b==26\n\t@hash[alph[i_b]]=value[i_b]\n\ti_b+=1\nend\t\n\nvalue=(1..26)\nalph=('A'..'Z')\nvalue=[*value]\nalph=[*alph]\n@hash2={}\ni_b=0\n\nloop do\n\tbreak if i_b==26\n\t@hash2[alph[i_b]]=value[i_b]\n\ti_b+=1\nend\t\n@hash2['Z']=0\n\n\ndef S1_to_S2 (a1)\n\tr=a1[0]\n\ti=1\n\t\n\tloop do\n\t\tbreak if a1[i].to_i !=0\n\t\tr =r + a1[i]\n\t\ti+=1\n\tend\n\n\tr1=r.length\n\tr2=a1.length\n\tc1= a1[0 .. (r1-1)].reverse\n\trow= a1[ r1 .. r2].to_i\n\tc=0\n\ti=0\n\t\n\tloop do\n\t\tbreak if i==c1.length\n\t\tc= c + (@hash[c1[i]]*(26**i))\n\t\ti+=1\n\tend\n\t\n\tputs \"R#{row}C#{c}\"\nend\n\ndef S2_to_S1 (a1)\n\ts2=a1.split(\"\").map{|s| s}\n\tr3=3\n\ts2.find {|i| r3=s2.index(i)+1 if i=='C'}\n\ti=s2[r3 .. (s2.length - 1)].join.to_i\n\trow=s2[1 .. (r3-2)].join.to_i\n\tstr_c=\"\"\n\t\n\tloop do\n\t\ti=i-26 if i>25 && i%26==0\n\t\tstr_c = str_c + @hash2.key(i%26)\n\t\ti=i/26\n\t\tbreak if i==0\n\tend\n\t\n\tstr_c=str_c.reverse\n\tputs \"#{str_c}#{row}\"\nend\n\t\ni_c =0\n\nloop do\n break if i_c==input_arry.length\n\tinput1=input_arry[i_c]\n\t\n\tif \tinput1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0) \n\t\tS1_to_S2 (input1)\n\telsif input1[0]=='R' && input1[1].to_i!=0\n\t\tk2=input1.split(\"\")\n\t\tk=0\n\t\tk2.find{|s| k=1 if s=='C'}\n\t\tif k==1\n\t\t\tS2_to_S1(input1)\n\t\telse\n\t\t\tS1_to_S2 (input1)\n\t\tend\t\n\tend\n\t\n\ti_c +=1\n\t\nend\n\t"}, {"source_code": "n = gets().to_i\nfor i in 1..n\n\tline = gets().split(/(\\d+)/)\n\tif line.length >= 4\n\t\tcol = line[3].to_i\n\t\tfor j in 1..100\n\t\t\tbreak if 26**j >= col\n\t\t\tcol -= 26**j\n\t\tend\n\t\ts = (col-1).to_s(26).rjust(j,'0').tr('0123456789abcdefghijklmnop', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')\n\t\tputs s << line[1]\n\telse\n\t\trow = line[1]\n\t\tans = 1 + line[0].tr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789abcdefghijklmnop').to_i(26) \n\t\tfor j in 1..line[0].length-1\n\t\t\tans += 26**j\n\t\tend\n\t\tputs 'R' << row << 'C' << ans.to_s\n\tend\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\n$ord_A = \"A\".ord\n\ndef name2addr(name)\n\taddr = 0\n\tname.each_char do |c|\n\t\taddr = addr*26 + c.ord - $ord_A + 1\n\tend\n\treturn addr\nend\n\ndef addr2name(addr)\n\tname = \"\"\n\twhile addr != 0\n\t\taddr -= 1\n\t\tname = (addr%26 + $ord_A).chr + name\n\t\taddr /= 26\n\tend\n\treturn name\nend\n\ngets\t# skip first line\nwhile gets\n\tline = $_.chomp\n\tif m = /R(\\d+)C(\\d+)/.match(line)\n\t\tputs addr2name(m[2].to_i) + m[1]\n\telsif m = /([A-Z]+)(\\d+)/.match(line)\n\t\tputs \"R\" + m[2] + \"C\" + name2addr(m[1]).to_s\n\telse\n\t\tabort \"bad_format\"\n\tend\nend\n"}, {"source_code": "n=gets.chomp.to_i\ndata=[]\n\nalpha=['A', 'B', 'C', 'D', 'E',\n\t\t'F', 'G', 'H', 'I', 'J',\n\t\t'K', 'L', 'M', 'N', 'O',\n\t\t'P', 'Q', 'R', 'S', 'T',\n\t\t'U', 'V', 'W', 'X', 'Y', 'Z']\na=0\n\nwhile a0\n\t\t\t\tb=cells%osn\n\t\t\t\tcs.push(alpha[b-1])\n\t\t\t\tif b==0\n\t\t\t\t\tcells-=(b+26)\n\t\t\t\telse\n\t\t\t\t\tcells-=b\n\t\t\t\tend\n\t\t\t\tcells/=osn\n\t\t\tend\n\t\t\t\n\t\t\tcs.reverse!\n\t\t\tcs.push(rows)\n\n\t\t\tputs cs.join\n\t\telse\n\t\t\tsn=[]\n\t\t\ta=0\n\t\t\twhile word[a].to_i==0\n\t\t\t\tsn.push(word[a])\n\t\t\t\ta+=1\n\t\t\tend\n\n\t\t\tnumber=[]\n\t\t\tfor i in(a..word.length-1)\n\t\t\t\tnumber.push(word[i])\n\t\t\tend\n\t\t\tnumb=number.join.to_i\n\n\t\t\tsn.reverse!\n\t\t\trw=0\n\t\t\tfor i in(0..sn.length-1)\n\t\t\t\trw+=(alpha.index(sn[i])+1)*osn**i\n\t\t\tend\n\n\t\t\tanswer=[]\n\t\t\tanswer.push('R')\n\t\t\tanswer.push(numb)\n\t\t\tanswer.push('C')\n\t\t\tanswer.push(rw)\n\t\t\tputs answer.join\n\t\tend\n\telse\n\t\tsn=[]\n\t\ta=0\n\t\twhile word[a].to_i==0\n\t\t\tsn.push(word[a])\n\t\t\ta+=1\n\t\tend\n\n\t\tnumber=[]\n\t\tfor i in(a..word.length-1)\n\t\t\tnumber.push(word[i])\n\t\tend\n\t\tnumb=number.join.to_i\n\n\t\tsn.reverse!\n\t\trw=0\n\t\tfor i in(0..sn.length-1)\n\t\t\trw+=(alpha.index(sn[i])+1)*osn**i\n\t\tend\n\n\t\tanswer=[]\n\t\tanswer.push('R')\n\t\tanswer.push(numb)\n\t\tanswer.push('C')\n\t\tanswer.push(rw)\n\t\tputs answer.join\n\tend\nend"}, {"source_code": "arr=(\"A\"..\"Z\").to_a\ngets.to_i.times{\n\ts=gets.chomp\n\tif /R\\d+C\\d+/.match(s) then\n\t\ts.slice!(0)\n\t\tr,c=s.split(\"C\").map{|e| e.to_i}\n\t\tstr=\"\"\n\t\tc=c-1\n\t\twhile c>25\n\t\t\tstr< BC23\n def rc_to_excel(row, col)\n excel_col = ''\n while col > 0\n col -= 1\n excel_col << num_to_chr(col % EXCEL_SYSTEM_BASE)\n col /= EXCEL_SYSTEM_BASE\n end\n excel_col.reverse! + row.to_s\n end\n\n # BC23 -> R23C55\n def excel_to_rc(excel_col, row)\n col = 0\n power_multiplier = 1\n excel_col.reverse.each_char do |chr|\n col += (chr_to_num(chr) + 1) * power_multiplier\n power_multiplier *= EXCEL_SYSTEM_BASE\n end\n \"R#{row}C#{col}\"\n end\n\n def num_to_chr(num)\n (num + 'A'.ord).chr\n end\n\n def chr_to_num(chr)\n chr.ord - 'A'.ord\n end\n end\nend\n\nif __FILE__ == $0\n lineCount = gets.to_i\n lines = []\n lineCount.times { |line| lines << gets }\n SpreadsheetCoordinateConverter.convert(lines).each { |line| puts line }\nend\n"}, {"source_code": "\n\nnumber_of_input=gets.to_i\ninput_arry=[]\ni_a=0\n\n\nloop do\n\tbreak if i_a==number_of_input\n\tinput_arry[i_a]=gets.chomp\n\ti_a +=1\nend\n\nvalue=(1..26)\nalph=('A'..'Z')\nvalue=[*value]\nalph=[*alph]\n@hash={}\ni_b=0\n\nloop do\n\tbreak if i_b==26\n\t@hash[alph[i_b]]=value[i_b]\n\ti_b+=1\nend\t\n\nvalue=(1..26)\nalph=('A'..'Z')\nvalue=[*value]\nalph=[*alph]\n@hash2={}\ni_b=0\n\nloop do\n\tbreak if i_b==26\n\t@hash2[alph[i_b]]=value[i_b]\n\ti_b+=1\nend\t\n@hash2['Z']=0\n\n\ndef S1_to_S2 (a1)\n\tr=a1[0]\n\ti=1\n\t\n\tloop do\n\t\tbreak if a1[i].to_i !=0\n\t\tr =r + a1[i]\n\t\ti+=1\n\tend\n\n\tr1=r.length\n\tr2=a1.length\n\tc1= a1[0 .. (r1-1)].reverse\n\trow= a1[ r1 .. r2].to_i\n\tc=0\n\ti=0\n\t\n\tloop do\n\t\tbreak if i==c1.length\n\t\tc= c + (@hash[c1[i]]*(26**i))\n\t\ti+=1\n\tend\n\t\n\tputs \"R#{row}C#{c}\"\nend\n\ndef S2_to_S1 (a1)\n\ts2=a1.split(\"\").map{|s| s}\n\tr3=3\n\ts2.find {|i| r3=s2.index(i)+1 if i=='C'}\n\ti=s2[r3 .. (s2.length - 1)].join.to_i\n\trow=s2[1 .. (r3-2)].join.to_i\n\tstr_c=\"\"\n\t\n\tloop do\n\t\ti=i-26 if i>25 && i%26==0\n\t\tstr_c = str_c + @hash2.key(i%26)\n\t\ti=i/26\n\t\tbreak if i==0\n\tend\n\t\n\tstr_c=str_c.reverse\n\tputs \"#{str_c}#{row}\"\nend\n\t\ni_c =0\n\nloop do\n break if i_c==input_arry.length\n\tinput1=input_arry[i_c]\n\t\n\tif \tinput1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0) \n\t\tS1_to_S2 (input1)\n\telsif input1[0]=='R' && input1[1].to_i!=0\n\t\tk2=input1.split(\"\")\n\t\tk=0\n\t\tk2.find{|s| k=1 if s=='C'}\n\t\tif k==1\n\t\t\tS2_to_S1(input1)\n\t\telse\n\t\t\tS1_to_S2 (input1)\n\t\tend\t\n\tend\n\t\n\ti_c +=1\n\t\nend\n\t\n\t\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n"}, {"source_code": "def a(s)\n y = s.split(/C|R/)[1].to_i\n x = s.split(/C|R/)[2].to_i\n\n base = 26\n count = 1\n digits = 1\n while (count * base < x)\n x -= (count *= base)\n digits += 1\n end\n\n c = ''\n x -= 1\n digits.times do\n c = (65 + x % 26).chr + c\n x /= 26\n end\n\n puts \"#{c}#{y}\"\nend\n\ndef b(s)\n x = s.split(/\\d/)[0]\n y = s.split(/[^\\d]/).last\n\n c = 0\n\n x.bytes.each do |l|\n c = 26 * c + (l - 65)\n end\n\n base = 1\n (x.size - 1).times do\n c += (base *= 26)\n end\n c += 1\n\n puts \"R#{y}C#{c}\"\nend\n\ngets.to_i.times do\n s = gets\n\n if s[0] == 'R' and s.bytes[1] < 65 and s.size > 2 and s.include?('C')\n a(s)\n else\n b(s)\n end\nend\n"}, {"source_code": "d=[*?A..'BEAAA']\ndef t s\np=a=0\ns.each_char{|c|a+=(c.ord-?A.ord+1)*26**p;p+=1}\na\nend\ngets.to_i.times{l=gets;puts (if /R(\\d+)C(\\d+)/.match l;\n\"#{d[$2.to_i-1]}#{$1}\"\nelse\na,b=l.scan(/([A-Z]+)(\\d+)/)[0];\"R#{b}C#{t a.reverse}\"\nend)}\n"}, {"source_code": "d=['', *?A..'BEAAA']\n\ndef t s\n p=a=0\n s.reverse!\n \n s.each_char{|c|\n a+= (c.ord - 'A'.ord + 1) * 26**p\n p+=1\n }\n \n a\nend\n\nn=gets.to_i\n\nn.times{\n l=gets.strip\n \n if /R(\\d+)C(\\d+)/.match l\n puts \"#{d[$2.to_i]}#{$1}\"\n else\n a, b = l.scan(/([A-Z]+)([0-9]+)/)[0]\n puts \"R#{b}C#{t a}\"\n end\n}"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\ndigs=['', *?A..'BEAAA']\n\ndef to_numbers str\n\tans=0\n\tstr.reverse!\n\t\n\tpow=0\n\tstr.each_char{|c|\n\t\tans+= (c.ord - 'A'.ord + 1) * 26**pow\n\t\tpow+=1\n\t}\n\t\n\tans\nend\n\nn=gets.to_i\n\nn.times{\n\tline=gets.strip\n\t\n\tif /R(\\d+)C(\\d+)/.match line\n\t\tputs \"#{digs[$2.to_i]}#{$1}\"\n\telse\n\t\tp1, p2 = line.scan(/([A-Z]+)([0-9]+)/)[0]\n\t\tputs \"R#{p2}C#{to_numbers p1}\"\n\tend\n}\n"}, {"source_code": "d=[*?A..'BEAAA'];def t s;p=a=0;s.each_char{|c|a+=(c.ord-?A.ord+1)*26**p;p+=1};a;end;gets.to_i.times{l=gets;puts (if /R(\\d+)C(\\d+)/.match l;\"#{d[$2.to_i-1]}#{$1}\";else;a,b=l.scan(/([A-Z]+)(\\d+)/)[0];\"R#{b}C#{t a.reverse}\";end)}\n"}, {"source_code": "arr = STDIN.read.split(\"\\n\")\nn = arr[0].to_i\n\n1.upto(n).each do |i|\n str = arr[i]\n match = str.match(/R([0-9]+)C([0-9]+)/)\n\n if match\n row = match[2].to_i\n col = match[1]\n\n r = row\n str = \"\"\n while(r > 0) do\n val = (r-1) % 26\n str += (val + 65).chr\n r = (r-1)/26\n end\n str = str.reverse\n str += col\n puts str\n else\n match = str.match(/([A-Z]+)([0-9]+)/)\n col = match[1]\n row = match[2]\n\n s = 0\n rev = col.reverse.split(\"\")\n rev.each_index do |i|\n chr = (rev[i][0].ord - 65 + 1) * ( 26 ** i )\n s += chr\n end\n\n puts \"R#{row}C#{s}\"\n end\nend"}, {"source_code": "# # # # # # # # # # # # # # # # # # # # # # # # # # # #\n\ndef numToAZ(col)\n if col > 0\n numToAZ((col-1)/26) + ('A'.ord + (col-1)%26).chr\n else\n \"\"\n end\nend\n\ndef to_CX(row, column)\n return numToAZ(column.to_i) + row\nend\n\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\ndef to_RXCY(row, column)\n\n azLen = ('A'..'Z').to_a.length\n\n columnInt = 0\n column.reverse.each_char.each_with_index { |chr, idx| \n columnInt += (chr.ord - 'A'.ord + 1) * azLen**idx\n }\n\n return \"R#{row}C#{columnInt}\"\n\nend\n\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\ndef translate(coord)\n if coord =~ /^R(\\d+)C(\\d+)$/\n to_CX($1, $2)\n elsif coord =~ /^([A-Z]+)(\\d+)/\n to_RXCY($2, $1)\n end\nend\n\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\n# Main\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\n\ngets.to_i.times {\n puts translate(gets.strip)\n}\n"}, {"source_code": "# # # # # # # # # # # # # # # # # # # # # # # # # # # #\ndef to_1var(row, column)\n\n az = ('A'..'Z').to_a\n azLen = az.length()\n\n columnAZ = \"\"\n columnInt = column.to_i\n\n while columnInt > 0\n idx = columnInt % azLen\n columnAZ.insert(0, az[idx-1])\n columnInt = (columnInt / azLen) - ((idx == 0)? 1 : 0)\n end\n\n return columnAZ + row\n\nend\n\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\ndef to_2var(row, column)\n\n azLen = ('A'..'Z').to_a.length\n\n columnInt = 0\n column.reverse.each_char.each_with_index { |chr, idx| \n columnInt += (chr.ord - 'A'.ord + 1) * azLen**idx\n }\n\n return \"R#{row}C#{columnInt}\"\n\nend\n\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\ndef translate(coord)\n if coord =~ /^R(\\d+)C(\\d+)$/\n to_1var($1, $2)\n elsif coord =~ /^([A-Z]+)(\\d+)/\n to_2var($2, $1)\n end\nend\n\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\n# Main\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\n\ngets.to_i.times {\n puts translate(gets.strip)\n}\n"}, {"source_code": "n=gets.chomp.to_i\nn.times {\n s=gets.chomp.to_s\n s.scan(/^R([0-9]+)C([0-9]+)$/)\n unless !$~\n r=$~[1]\n c=$~[2].to_i\n remainder=-1\n g=\"\"\n while c>0\n remainder=c%26\n #print (\"#{remainder} \")\n if(remainder==0)\n g+=\"Z\"\n c-=26\n else\n g+=(remainder+64).chr\n c-=remainder\n end\n #puts (g)\n c/=26\n end\n print(g.reverse)\n puts (r)\n next\n end\n s.scan(/^([A-Z]+)([0-9]+)$/)\n unless !$~\n c=$~[1]\n r=$~[2]\n k=1\n sum=0\n i=1\n len=c.length\n while i<=len\n #puts (i)\n hold=(c.getbyte(-1*i)-64)*k\n #puts (\"hold = #{hold}\")\n sum+=hold\n k*=26\n i+=1\n end\n puts (\"R#{r}C#{sum}\")\n end\n\n}"}, {"source_code": "$itoc =['Z'] + ('A'..'Z').to_a\n$ctoi = Hash.new\n26.times{|i| $ctoi[$itoc[i+1]] = i+1}\n\ndef change str\n if str =~ /R(\\d+)C(\\d+)/\n return toAlph($2.to_i)+$1\n else\n str =~ /([A-Z]+)(\\d+)/\n return 'R'+$2+'C'+toNum($1)\n end\nend\ndef toAlph x\n ret = ''\n while x>0 do\n ret = $itoc[x%26] + ret\n x -= 26 if x%26 == 0\n x /= 26\n end\n return ret\nend\ndef toNum x\n ret = 0\n x.reverse!\n x.size.times do |i|\n ret += ($ctoi[x[i]] * (26**i))\n end\n return ret.to_s\nend\n\nn = gets.to_i\nn.times do\n puts (change gets)\nend"}, {"source_code": "class SpreadSheets\n def main\n numberOfLines = gets.to_i\n coordinates = Array.new(numberOfLines)\n\n i = 0\n while i < numberOfLines\n coordinates[i] = gets\n i += 1\n end\n\n puts convert(coordinates)\n end\n\n def convert(coordinates)\n result = Array::new\n numericDef = /R(\\d+)C(\\d+)/\n alphanumericDef = /([a-zA-Z]+)(\\d+)/\n\n coordinates.each do |coordinate|\n if (numericDef.match(coordinate))\n matches = numericDef.match(coordinate)\n row = matches[1]\n column = matches[2]\n convertedColumn = convertNumToAlpha(column.to_i)\n result.push(\"#{convertedColumn}#{row}\")\n elsif (alphanumericDef.match(coordinate))\n matches = alphanumericDef.match(coordinate)\n row = matches[2]\n column = matches[1]\n convertedColumn = convertAlphaToNum(column)\n result.push(\"R#{row}C#{convertedColumn}\")\n end\n end\n\n return result\n end\n\n def convertNumToAlpha(num)\n result = String::new\n\n zeroLetter = 'A';\n base26 = 26;\n loop do\n num -= 1;\n remainder = num % base26;\n result = \"#{(zeroLetter.ord + remainder).chr}#{result}\"\n num /= base26;\n break if (num == 0)\n end\n\n return result\n end\n\n def convertAlphaToNum(alpha)\n result = 0\n\n zeroLetter = 'A'\n currentOrderOfMagnitude = 1\n base26 = 26\n alpha.split(\"\").reverse_each do |letter|\n convertedDigit = letter.ord - zeroLetter.ord + 1\n result += currentOrderOfMagnitude * convertedDigit\n currentOrderOfMagnitude *= base26\n end\n\n return result.to_s\n end\nend\n\nSpreadSheets::new.main\n"}, {"source_code": "def to_num s\n num = 0\n s.size.times do |i|\n num *= 26\n num += s[i].ord - 'A'.ord + 1\n end\n return num\nend\n\ndef to_letters num\n s = \"\"\n while num > 0\n mod = num % 26\n if mod == 0\n mod = 26\n num -= 1\n end\n s += ('A'.ord + mod - 1).chr\n num /= 26\n end\n return s.reverse\nend\n\ngets.to_i.times do\n s = gets\n if s =~ /R\\d+C\\d+/\n r, c = s.tr(\"RC\", \" \").split.map &:to_i\n \n puts \"#{to_letters c}#{r}\"\n \n elsif s =~ /[A-Z]+\\d+/\n r = s[/\\d+/].to_i\n c = to_num(s[/[A-Z]+/])\n \n puts \"R#{r}C#{c}\"\n end\nend"}, {"source_code": "n = Integer(gets)\ncoo = Array.new\nfor i in 0...n\n coo[i] = Array.new\n input = gets.chomp\n coo[i] = input\nend\n\nclass Cell\n attr_accessor :row, :column\n\n\n def initialize(row,column,value)\n @row = row\n @column = column\n end\nend\n\n def rc_name_to_cell(rc_name)\n rc_name = rc_name[1,rc_name.length - 1]\n nums = rc_name.split(\"C\")\n c_row = Integer(nums[0])\n c_column = Integer(nums[1])\n return c_row, c_column\n end\n\n def cell_to_excel_name(c_row,c_column)\n name = \"\"\n while (c_column > 0) do \n c_column -= 1\n name += (c_column % 26 + 'A'.ord).chr\n c_column = c_column / 26\n end\n return name.reverse + c_row.to_s\n end\n\n def excel_name_to_cell(excel_name)\n c_row = Array.new\n c_column = Array.new\n for i in 0...excel_name.length\n if excel_name[i] >= \"0\" && excel_name[i] <= \"9\"\n c_row.push(excel_name[i])\n else\n c_column.push(excel_name[i])\n end\n end\n sov = 0\n for i in 0 ...c_column.length\n sov += (c_column[i].ord - \"A\".ord + 1) * 26 ** (c_column.length - i - 1)\n end\n return c_row.join.to_i, sov \n end\n\n def cell_to_rc_name(c_row,c_column)\n print \"R\" + c_row.to_s + \"C\" + c_column.to_s\n end\n\ndef sov(coo)\n c = 0\n a = -1\n b = -1\n for j in 0...coo.length\n if coo[j] == \"R\"\n a = j\n elsif coo[j] == \"C\"\n b = j\n end\n end\n if a != -1 && b != -1\n for m in a + 1...b\n if coo[m] > \"0\" && coo[m] <= \"9\"\n c = 1\n end\n end\n end\n u = 0\n v = 0\n if c == 1\n u, v = rc_name_to_cell(coo)\n return cell_to_excel_name(u, v)\n else\n u, v = excel_name_to_cell(coo)\n return cell_to_rc_name(u, v) \n end\nend\nfor i in 0...n\n puts sov(coo[i])\nend"}, {"source_code": "n = Integer(gets)\ncoo = Array.new\nfor i in 0...n\n coo[i] = Array.new\n input = gets.chomp\n coo[i] = input\nend\n\nclass Cell\n attr_accessor :row, :column\n\n\n def initialize(row,column,value)\n @row = row\n @column = column\n end\nend\n\n def rc_name_to_cell(rc_name)\n rc_name = rc_name[1,rc_name.length - 1]\n nums = rc_name.split(\"C\")\n c_row = Integer(nums[0])\n c_column = Integer(nums[1])\n return c_row, c_column\n end\n\n def cell_to_excel_name(c_row,c_column)\n name = \"\"\n while (c_column > 0) do \n c_column -= 1\n name += (c_column % 26 + 'A'.ord).chr\n c_column = c_column / 26\n end\n return name.reverse + c_row.to_s\n end\n\n def excel_name_to_cell(excel_name)\n c_row = Array.new\n c_column = Array.new\n for i in 0...excel_name.length\n if excel_name[i] >= \"0\" && excel_name[i] <= \"9\"\n c_row.push(excel_name[i])\n else\n c_column.push(excel_name[i])\n end\n end\n sov = 0\n for i in 0 ...c_column.length\n sov += (c_column[i].ord - \"A\".ord + 1) * 26 ** (c_column.length - i - 1)\n end\n return c_row.join.to_i, sov \n end\n\n def cell_to_rc_name(c_row,c_column)\n print \"R\" + c_row.to_s + \"C\" + c_column.to_s\n end\n\n\nfor i in 0...n\n c = 0\n a = -1\n b = -1\n for j in 0...coo[i].length\n if coo[i][j] == \"R\"\n a = j\n elsif coo[i][j] == \"C\"\n b = j\n end\n end\n if a != -1 && b != -1\n for m in a + 1...b\n if coo[i][m] > \"0\" && coo[i][m] <= \"9\"\n c = 1\n end\n end\n end\n if c == 1\n u, v = rc_name_to_cell(coo[i])\n print cell_to_excel_name(u, v)\n puts\n else\n u, v = excel_name_to_cell(coo[i])\n print cell_to_rc_name(u, v)\n puts\n end\n\nend\n"}, {"source_code": "class Integer\n private\n LETTERS = [\"Z\"].concat((\"A\"..\"Y\").to_a)\n \n public\n def to_ab\n number = self\n ab = \"\"\n while(number != 0) do\n letter_index = number % 26\n ab << LETTERS[letter_index]\n number /= 26\n if(letter_index == 0) then number -= 1 end\n end\n return ab.reverse\n end\nend\n\nclass String\n private\n LETTERS = (\"A\"..\"Z\").to_a\n \n public\n def to_rc\n rstring = self.clone.reverse!\n rc = 0\n rstring.length.times {\n |i|\n rc += ((LETTERS.index(rstring[i,1]) + 1) * (26 ** i))\n }\n return rc.to_s\n end\nend\n\ndef rc_ab(rc)\n row, column = rc.scan(/\\d+/)\n column = column.to_i.to_ab\n ab = column << row\n return ab\nend\n\ndef ab_rc(ab)\n column, row = ab.scan(/([A-Z]+)(\\d+)/)[0]\n column = column.to_rc\n rc = \"R\" << row << \"C\" << column\n return rc\nend\n\nn = gets().chomp.to_i\na = []\nn.times {\n|i|\n a[i] = gets().chomp()\n}\na.each{\n|i|\n if (/^R\\d+C\\d+$/ =~ i) then\n #RXCY \n puts(rc_ab(i))\n else\n #AB23\n puts(ab_rc(i))\n end\n}"}, {"source_code": "n = gets.to_i\n\nn.times do\n\texpression = gets\n\tif expression.match /R(\\d+)C(\\d+)/\n\t\tresult = \"\"\n\t\tcolumn = $2.to_i\n\t\tuntil column == 0\n\t\t\tmod = column % 26\n\t\t\tif mod == 0\n\t\t\t\tmod = 26\n\t\t\t\tcolumn -= mod\n\t\t\tend\n\n\t\t\tresult << (mod + 64).chr\n\t\t\tcolumn /= 26\n\t\tend\n\t\tputs result.reverse + $1\n\telse\n\t\texpression.match /([A-Z]+)(\\d+)/\n\t\tcolumn = 0\n\t\t$1.each_byte { |chr| column = column * 26 + chr - 64 }\n\t\tputs \"R\" + $2 + \"C\" + column.to_s\n\tend\nend"}, {"source_code": "d=[*?A..'BEAAA'];def t s;p=a=0;s.each_char{|c|a+=(c.ord-?A.ord+1)*26**p;p+=1};a;end;gets.to_i.times{l=gets;puts (if /R(\\d+)C(\\d+)/.match l;\"#{d[$2.to_i-1]}#{$1}\";else;a,b=l.scan(/([A-Z]+)(\\d+)/)[0];\"R#{b}C#{t a.reverse}\";end)}"}, {"source_code": "def solve\n ans = \"\"\n input = gets\n #R23C55\n if (/^R\\d+C\\d+/ =~ input)\n r,c = input.scan(/\\d+/).map(&:to_i)\n while c > 0\n c -= 1\n ans += ('A'.ord + c%26).chr\n c /= 26\n end\n ans.reverse!\n ans += r.to_s\n elsif /.\\d+/ =~ input\n #BC23\n c = input.scan(/[A-Z]+/) #BC\n r = input.scan(/\\d+/)#23\n ans += \"R\" + r.inject(\"\"){|i,j| i + j} + \"C\" + ((0..c[0].size-1).inject(0){|i,j| i+26**j} + c[0].tr(\"A-Z\",\"0-9A-Z\").to_i(26)).to_s \n end\n puts ans\nend\n\nn = gets.to_i\nn.times{ solve}\n\n"}, {"source_code": "def solve\n ans = \"\"\n input = gets\n if (/^R\\d+C\\d+/ =~ input)\n r,c = input.scan(/\\d+/).map(&:to_i)\n while c > 0\n c -= 1\n ans += ('A'.ord + c%26).chr\n c /= 26\n end\n ans.reverse!\n ans += r.to_s\n else\n c = input.scan(/[A-Z]+/).reverse! #BC\n r = input.scan(/\\d+/) #23\n ans += \"R\" \n r.each {|tmp| ans += tmp.to_s}\n ans += \"C\"\n base = 1\n col = 0\n c[0].reverse!\n for i in 0...c[0].size do \n col += (c[0][i].ord-'A'.ord+1)*base\n base *= 26\n end\n ans += col.to_s\n end\n puts ans\nend\n\nn = gets.to_i\nn.times{ solve}\n\n"}, {"source_code": "n = gets.to_i\n\ndef gao(val)\n ret = \"\"\n while val > 0\n if val % 26 == 0\n ret.concat('Z')\n val -= 1\n else\n ret.concat((val % 26 + 65 - 1).chr)\n end\n val /= 26\n end\n ret.reverse!\nend\n\nn.times do\n s = gets\n m = /R(\\d+)C(\\d+)/.match(s)\n if m != nil\n val = m[2].to_i\n puts \"#{gao(val)}#{m[1]}\"\n else\n m = /([A-Z]+)(\\d+)/.match(s)\n col = m[1]\n col.reverse!\n cnt, base = 0, 1\n col.length.times do |i|\n cnt += (col[i].ord - 'A'.ord + 1) * base\n base *= 26\n end\n puts \"R#{m[2]}C#{cnt}\"\n end\nend\n\n"}, {"source_code": "n = gets.to_i\n\ndef gao(val)\n ret = \"\"\n while val > 0\n if val % 26 == 0\n ret.concat('Z')\n val -= 26\n else\n ret.concat((val % 26 + 65 - 1).chr)\n end\n val /= 26\n end\n ret.reverse!\nend\n\nn.times do\n s = gets\n m = /R(\\d+)C(\\d+)/.match(s)\n if m != nil\n val = m[2].to_i\n puts \"#{gao(val)}#{m[1]}\"\n else\n m = /([A-Z]+)(\\d+)/.match(s)\n col = m[1]\n col.reverse!\n cnt, base = 0, 1\n col.length.times do |i|\n cnt += (col[i].ord - 'A'.ord + 1) * base\n base *= 26\n end\n puts \"R#{m[2]}C#{cnt}\"\n end\nend\n\n"}, {"source_code": "def f x;x<26?((x+65).chr):f(x/26-1)+(x%26+65).chr;end;gets.to_i.times{x=gets;puts /R(\\d+)C(\\d+)/.match(x)?f($2.to_i-1)+$1:(y=0;v=1;/(\\D+)(\\d+)/.match x;$1.reverse.each_char{|c|y+=(c.ord-64)*v;v*=26};\"R#{$2}C#{y}\")}\n"}, {"source_code": "d=[*?A..'BEAAA'];def t s;p=a=0;s.each_char{|c|a+=(c.ord-?A.ord+1)*26**p;p+=1};a;end;gets.to_i.times{l=gets;puts (if /R(\\d+)C(\\d+)/.match l;\"#{d[$2.to_i-1]}#{$1}\";else;a,b=l.scan(/([A-Z]+)(\\d+)/)[0];\"R#{b}C#{t a.reverse}\";end)}"}, {"source_code": "num = gets()\n\ndef is_excel_format(name)\n !!(name.match /^[A-Z]+[0-9]+$/)\nend\n\ndef to_excell(rowcol)\n rowcol =~ /R(\\d+)C(\\d+)/\n to_letters($2.to_i) + $1\nend\n\ndef to_rowcol(excell)\n excell =~ /([A-Z]+)(\\d+)/\n \"R\" + $2 + \"C\" + to_nums($1).to_s\nend\n\ndef to_letters(num, base=26)\n answer = []\n while num > 0\n mod = (num -1) % 26\n answer.push mod\n num = (num - mod) / base\n end\n answer.reverse.map{|x| (x+65).chr }.join\nend\n\ndef to_nums(letters)\n letters.reverse.split('').map.with_index{|x, i|\n (x.ord - 65 + 1) * 26 ** i # convert from letter to number, base 26\n }.reduce{|a,b| a+b}\nend\n\nnum.to_i.times do |index|\n line = gets()\n if is_excel_format(line)\n puts to_rowcol(line)\n else\n puts to_excell(line)\n end\nend\n"}, {"source_code": "def solve(input)\n if (/R\\d+C\\d+/ =~ input) == nil\n fromBase26(input)\n else\n toBase26(input)\n end\nend\n\ndef fromBase26(input)\n charByte = \"A\".bytes[0]\n numByte = \"1\".bytes[0]\n letters = Array.new\n numbers = Array.new\n\n input.chomp.each_byte do |byte|\n if byte < charByte\n numbers.unshift(byte-(numByte-1))\n else\n letters.unshift(byte-(charByte-1))\n end\n end\n\n rows = arrayToInt(numbers, 10)\n cols = arrayToInt(letters, 26)\n \"R#{rows}C#{cols}\"\nend\n\ndef toBase26(input)\n input[0] = \"\"\n rows, cols = input.split(\"C\")\n val = cols.to_i\n digits = []\n while val != 0\n digits.unshift((val-1)%26)\n val = (val-1)/26\n end\n cols = \"\"\n for digit in digits\n val = digit + (\"A\".bytes[0])\n cols += val.chr\n end\n cols + \"#{rows}\"\nend\n\ndef arrayToInt(arr, base)\n curr = 1\n int = 0\n for val in arr\n int += val*curr\n curr *= base\n end\n int\nend\n\nn = gets.to_i\nans = Array.new(n, nil)\nfor i in (0...n)\n ans[i] = solve(gets)\nend\n\nfor answer in ans\n puts answer\nend\n"}, {"source_code": "ask = gets.to_i\nask.times do\n str = gets\n if str =~ /\\D\\d+\\D\\d+/ #R23C55\n rows, columns = str.scan(/\\d+/)\n num = columns.to_i\n str = ''\n while num >= 1 do\n rem = num % 26\n str = (rem == 0) ? 'Z' + str : (rem + 64).chr + str\n num /= 26\n num -= 1 if rem == 0\n end\n ans = str + rows\n else #BC23\n columns, rows = str.scan(/\\D+|\\d+/)\n str = columns.reverse\n num = 0\n (0...str.length).each do |i|\n num += (str[i].ord - 64) * 26**i\n end\n ans = 'R' + rows + 'C' + num.to_s\n end\n puts ans\nend"}, {"source_code": "alph = ['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\nn = gets.chomp.to_i\n\nlines = []\nn.times {lines << gets.chomp}\nlines.each do |l|\n if (l =~ /R\\d+C\\d+/).nil?\n col = 0\n colstr = l.scan(/[A-Z]+/).first.split(\"\")\n colstr.each_with_index do |ch, index|\n col += (alph.index(ch) + 1) * (26 ** (colstr.length - index - 1))\n end\n row = l.scan(/[0-9]+/).first\n puts \"R#{row}C#{col}\"\n else\n row = l.scan(/R([0-9]+)/).flatten.first\n col = l.scan(/C([0-9]+)/).flatten.first.to_i\n cols = \"\"\n delta = 0\n loop do\n remainder = (col % 26)\n col = col / 26\n unless col == 0 and remainder - delta == 0\n cols = alph[remainder - 1 - delta] + cols\n end\n delta = remainder - delta <= 0 ? 1 : 0\n break if col == 0\n\n end\n puts \"#{cols}#{row}\"\n end\nend\n"}, {"source_code": "number_of_input=gets.to_i\ninput_arry=[]\ni_a=0\n\n\nloop do\n\tbreak if i_a==number_of_input\n\tinput_arry[i_a]=gets.chomp\n\ti_a +=1\nend\n\nvalue=(1..26)\nalph=('A'..'Z')\nvalue=[*value]\nalph=[*alph]\n@hash={}\ni_b=0\n\nloop do\n\tbreak if i_b==26\n\t@hash[alph[i_b]]=value[i_b]\n\ti_b+=1\nend\t\n\n\n\ndef S1_to_S2 (a1)\n\tr=a1[0]\n\ti=1\n\t\n\tloop do\n\t\tbreak if a1[i].to_i !=0\n\t\tr =r + a1[i]\n\t\ti+=1\n\tend\n\n\tr1=r.length\n\tr2=a1.length\n\tc1= a1[0 .. (r1-1)].reverse\n\trow= a1[ r1 .. r2].to_i\n\tc=0\n\ti=0\n\t\n\tloop do\n\t\tbreak if i==c1.length\n\t\tc= c + (@hash[c1[i]]*(26**i))\n\t\ti+=1\n\tend\n\t\n\tputs \"R#{row}C#{c}\"\nend\n\ndef S2_to_S1 (a1)\n\ts2=a1.split(\"\").map{|s| s}\n\tr3=3\n\ts2.find {|i| r3=s2.index(i)+1 if i=='C'}\n\ti=s2[r3 .. (s2.length - 1)].join.to_i\n\trow=s2[1 .. (r3-2)].join.to_i\n\tstr_c=\"\"\n\t\n\tloop do\n\t\ti=i-26 if i>25 && i%26==0\n\t\tif i%26==0\n\t\tstr_c = str_c + \"Z\"\n\t\telse\n\t\tstr_c = str_c + @hash.key(i%26)\n\t\tend\n\t\ti=i/26\n\t\tbreak if i==0\n\tend\n\t\n\tstr_c=str_c.reverse\n\tputs \"#{str_c}#{row}\"\nend\n\t\ni_c =0\n\nloop do\n break if i_c==input_arry.length\n\tinput1=input_arry[i_c]\n\t\n\tif \tinput1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0) \n\t\tS1_to_S2 (input1)\n\telsif input1[0]=='R' && input1[1].to_i!=0\n\t\tk2=input1.split(\"\")\n\t\tk=0\n\t\tk2.find{|s| k=1 if s=='C'}\n\t\tif k==1\n\t\t\tS2_to_S1(input1)\n\t\telse\n\t\t\tS1_to_S2 (input1)\n\t\tend\t\n\tend\n\t\n\ti_c +=1\n\t\nend"}, {"source_code": "def toBase26 number\n converted = []\n while (number > 0)\n remainder = (number - 1) % 26\n converted << (remainder + 65).chr\n number = (number - remainder) / 26;\n end\n return converted.join.reverse;\nend\ndef fromBase26 number\n s = 0\n if number.length > 0\n s = number[0].ord - 65 + 1;\n for i in 1..number.length-1\n s *= 26;\n s += (number[i].ord - 65 + 1);\n end\n end\n return s\nend\nt = gets.to_i\nfor i in 1..t\n s = gets.chomp\n len = s.length\n format = false\n if s[0] == 'R' && s[1].ord < 65 && len >= 4\n j = 2\n r = s[1].to_i\n while j < len && s[j].ord < 65\n r = r*10 + s[j].to_i\n j += 1\n end\n if j!= len && s[j] == 'C'\n c = s[j + 1].to_i\n j += 2\n while j < len && s[j].ord < 65\n c = c*10 + s[j].to_i\n j += 1\n end\n format = true\n else\n c = r\n r = 'R'\n end\n else\n j = 0\n while s[j].ord >= 65\n j += 1\n end\n r = s[0,j]\n c = s[j].to_i\n j += 1\n while j < len\n c = c*10 + s[j].to_i\n j += 1\n end\n end\n\n # true RXCX \n # false ABCXXX\n if !format\n puts \"R#{c}C#{fromBase26 r}\"\n else\n puts \"#{toBase26 c}#{r}\"\n end\nend"}, {"source_code": "def whitespace?(c)\n !\" \\r\\n\".index(c).nil?\nend\ndef read_word\n s = ''\n c = ' '\n c = $stdin.getc while whitespace?(c)\n begin\n s << c\n c = $stdin.getc\n end while !whitespace?(c)\n return s\nend\ndef read_int\n read_word.to_i\nend\ndef read_float\n read_word.to_f\nend\ndef read_line\n s = ''\n while s.count(\"\\r\\n\")==s.length\n s = $stdin.readline\n end\n return s\nend\n\n$base = ?A\n\ndef to_hex(n)\n res = \"\"\n while n>0\n res << ((n-1)%26 + $base).chr\n n = (n-1) / 26\n end\n res.reverse\nend\ndef from_hex(s)\n res = 0\n s.each_byte do |b|\n res = res*26 + (b - $base + 1)\n end\n res\nend\nn = read_int\nn.times do\n s = read_line\n if s =~ /R(\\d+)C(\\d+)/\n x,y = $1,$2.to_i\n puts to_hex(y)+x\n else\n i = 0\n y = \"\"\n while s[i..i]>='A'\n y << s[i]\n i+=1\n end\n puts \"R#{s[i...-1]}C#{from_hex(y)}\"\n end\nend\n\n"}, {"source_code": "letters = %w(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\ngets.to_i.times do\n input = gets.strip\n if input =~ /R(\\d)+C/\n codes = input.gsub(\"R\", \"\").split(\"C\").map(&:to_i)\n ans = \"\"\n codes[1]\n while codes[1] > 0 do\n ans << letters[(codes[1]%26-1)]\n if codes[1]%26!=0\n codes[1] /= 26\n else\n codes[1] /= 26\n codes[1] -=1\n end\n end\n\n\n puts \"#{ans.reverse}#{codes[0]}\"\n else\n code = input.match(/([A-Z])+/).to_s\n sum = 0\n code.chars.each_with_index do |el, i|\n sum += (1+letters.index(el)) * (26**(code.size-i-1))\n end\n puts \"R#{input.match(/([0-9])+/)}C#{sum}\"\n end\nend"}, {"source_code": " \ndef f x;x<26?((x+65).chr):f(x/26-1)+(x%26+65).chr;end;gets.to_i.times{x=gets;puts /R(\\d+)C(\\d+)/.match(x)?f($2.to_i-1)+$1:(y=0;v=1;/(\\D+)(\\d+)/.match x;$1.reverse.each_char{|c|y+=(c.ord-64)*v;v*=26};\"R#{$2}C#{y}\")}"}, {"source_code": "def to_spread_number(number)\n spread = ''\n while number > 0\n rem = number % 26\n number /= 26\n if rem == 0\n rem = 26\n number -= 1\n end\n spread = (rem + 64).chr + spread\n end\n spread\nend\n\ndef to_number(spread_num)\n num, m = 0, 1\n spread_num.reverse.each_char { |c|\n num += (c.ord - 64) * m\n m *= 26\n }\n num\nend\n\nfor _ in 1..Integer(gets.chomp)\n cell = gets.chomp\n coords = cell.scan(/R(\\d+)C(\\d+)/).first\n if coords\n puts to_spread_number(coords[1].to_i) + coords[0]\n else\n cell.scan(/([A-Z]+)(\\d+)/) { puts \"R#{$2}C#{to_number($1)}\" }\n end\nend"}, {"source_code": "d=[*?A..'BEAAA'];def t s;p=a=0;s.each_char{|c|a+=(c.ord-?A.ord+1)*26**p;p+=1};a;end;gets.to_i.times{l=gets;puts (if /R(\\d+)C(\\d+)/.match l;\"#{d[$2.to_i-1]}#{$1}\";else;a,b=l.scan(/([A-Z]+)(\\d+)/)[0];\"R#{b}C#{t a.reverse}\";end)}\n"}, {"source_code": "def to_digits(s)\n\tres = 0\n\ts.each_byte { |a|\n \tres = res * 26 + a - 'A'[0].ord + 1\n\t}\n\tres\nend\n\ndef to_letters(n)\n\ts = ''\n\twhile n > 0 do\n \tr = n % 26\n \tif r == 0\n \t\tad = 'Z'\n\t\telse\n\t\t\tad = ('A'[0].ord + r - 1).chr\n\t\tend\n \tn = (n - 1) / 26\n \ts = s + ad\n\tend\n\ts.reverse\nend\n\nn = gets.to_i\nn.times do \n\ts = gets\n\tif /^(\\D+)(\\d+)$/i =~ s\n\t\tm = Regexp.last_match\n\t\tputs \"R#{m[2]}C#{to_digits(m[1])}\"\n elsif /^R(\\d+)C(\\d+)$/i =~ s\n \tm = Regexp.last_match\n \tputs \"#{to_letters(m[2].to_i)}#{m[1]}\"\n\tend\nend"}, {"source_code": "# $stdin = File.open('in')\nn = gets.to_i\n\ndef conv(num)\n\tres = ''\n\twhile num > 0\n\t\tif num % 26 == 0\n\t\t\tres.concat('Z')\n\t\t\tnum -= 1\n\t\telse\n\t\t\tres.concat((num % 26 + 65 - 1).chr)\n\t\tend\n\t\tnum /= 26\n\tend\n\tres.reverse!\nend\n\nfor i in 0...n \n\ts = gets\n\tm = /R(\\d+)C(\\d+)/.match(s)\n\tif m != nil\n\t\tnum = m[2].to_i\n\t\tputs \"#{conv(num)}#{m[1]}\"\n\telse\n\t\tm = /([A-Z]+)(\\d+)/.match(s)\n\t\tcolumn = m[1]\n\t\tcolumn.reverse!\n\t\tcnt, base = 0, 1\n\t\tcolumn.length.times do |i|\n\t\t\tcnt += (column[i].ord - 'A'.ord + 1) * base\n\t\t\tbase *= 26\n\t\tend\n\t\tputs \"R#{m[2]}C#{cnt}\"\n\tend\nend"}, {"source_code": "gets\nwhile i = gets do\n\tif i =~ /^([A-Z]+)(\\d+)$/\n\t\tc = 0\n\t\t$1.each_byte {|chr| c = c * 26 + chr - 64}\n\t\tprint \"R\", $2, \"C\", c, \"\\n\"\n\telsif i =~ /^R(\\d+)C(\\d+)/\n\t\tc = $2.to_i\n\t\tstr=\"\"\n\t\twhile c != 0\n\t\t\tmod = c % 26\n\t\t\tif mod == 0 then\n\t\t\t\tmod = 26\n\t\t\t\tc -= mod\n\t\t\tend\n\t\t\tstr << (mod + 64).chr\n\t\t\tc /= 26\n\t\tend\n\t\tprint str.reverse, $1, \"\\n\"\n\tend\nend"}, {"source_code": "gets; while i = gets do\n\tif i =~ /^([A-Z]+)(\\d+)$/\n\t\tc = 0\n\t\t$1.each_byte {|chr| c = c * 26 + chr - 64}\n\t\tprint \"R\", $2, \"C\", c, \"\\n\"\n\telsif i =~ /^R(\\d+)C(\\d+)/\n\t\tc = $2.to_i\n\t\tstr=\"\"\n\t\twhile c != 0\n\t\t\tmod = c % 26\n\t\t\tif mod == 0 then\n\t\t\t\tmod = 26\n\t\t\t\tc -= mod\n\t\t\tend\n\t\t\tstr << (mod + 64).chr\n\t\t\tc /= 26\n\t\tend\n\t\tprint str.reverse, $1, \"\\n\"\n\tend\nend"}, {"source_code": "\ndef is_num(ch)\n return ((ch >= \"0\") and (ch <= \"9\")) ? true : false\nend\ndef is_pattern2(str)\n len = str.length()\n return false if str[0]!=\"R\"\n return false if not(is_num(str[1]))\n for i in (2..len-1)\n return true if str[i]==\"C\"\n end\n\n false\nend\n\nnum_line = gets.to_i()\nnum_line.times {\n str = gets().chomp()\n len = str.length()\n if is_pattern2(str)\n\n for i in (2..len-1)\n if str[i]==\"C\"\n c_index = i\n break\n end\n end\n\n row = str[1..c_index-1].to_i\n col = str[c_index+1..len-1].to_i\n\n col_string = []\n\n loop do\n col -= 1\n a= (col%26 + 65).chr\n col_string.unshift(a)\n col /= 26\n break if col <=0\n end\n puts \"#{col_string.join('')}#{row}\"\n else\n\n for i in (1..len-1)\n if is_num(str[i])\n num_index = i\n break\n end\n end\n row = str[num_index..len-1].to_i\n col = 0\n for i in (0..num_index-1)\n base = 26**i\n col += base * (str[num_index-1-i].ord-\"A\".ord+1)\n end\n puts \"R#{row}C#{col}\"\n end\n}\n"}, {"source_code": "n = gets\nn = Integer(n)\nwhile n>0\n string = gets\n m = string.size()\n index = 0\n while ('A'..'Z').include? string[index]\n index += 1\n end\n while !(('A'..'Z').include? string[index])\n index += 1\n if index >= m\n break;\n end\n end\n if index == m\n index = 0\n while ('A'..'Z').include? string[index]\n index+=1\n end\n index -= 1\n c = 0\n count = 1\n til = index\n until index < 0\n c += (string[index].unpack(\"c\")[0] - 'A'.unpack(\"c\")[0] + 1) * count\n index -= 1\n count *= 26\n end\n puts \"R#{string[til+1..m].chomp}C#{c}\"\n else\n index = string.index(\"C\")\n count = Integer(string[index+1..m-2].chomp)\n k = \"\"\n while count > 0\n while count % 26 == 0 && count > 0\n k = \"Z\" + k\n count /= 26\n count -= 1\n end\n if count>0\n k = (count % 26 + 64).chr + k\n count /= 26 \n end\n end\n puts \"#{k}#{string[1..index-1]}\"\n end\n n-=1\nend"}, {"source_code": "#!/usr/bin/env ruby\n\ndef convert(str)\n if str =~ /^R(\\d+)C(\\d+)$/\n rows, cols = $1.to_i, $2.to_i\n a = []\n loop do\n cols -= 1\n a.unshift cols % 26\n cols /= 26\n break if cols == 0\n end\n \"#{a.map{|i| (i + 65).chr}.join}#{rows}\"\n elsif str =~ /^([A-Z]+)(\\d+)$/\n cols = 0\n $1.size.times do |i|\n cols += ($1.unpack('C*')[-i - 1] - 64) * (26 ** i)\n end\n \"R#{$2}C#{cols}\"\n else\n \"invalid arg\"\n end\nend\n\nn = gets.to_i\nlines = []\nn.times do\n lines << convert(gets.chomp)\nend\n\nlines.each{|s| puts s}\n"}, {"source_code": "require 'scanf'\nn = STDIN.gets.scanf('%d').first\nwhile n>0\n l = STDIN.gets.chop\n row = nil\n col = nil\n /R(?\\d+)C(?\\d+)/=~l\n unless (row and col)\n /(?[A-Z]+)(?\\d+)/=~l\n col_ = 0\n i=0\n col.each_byte do |a|\n pos = col.length - i - 1\n col_+=('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)**pos*(a-'A'.bytes.to_a.first+1)\n i+=1\n end\n row = row.to_i\n puts \"R\"+row.to_s+\"C\"+col_.to_s\n else\n col = col.to_i\n col_ = ''\n while col!=0\n temp = col % ('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)\n if temp ==0\n temp = ('Z'.bytes.to_a.first-'A'.bytes.to_a.first)\n col-=1\n else\n temp-=1\n end\n col_+=['A'.bytes.to_a.first+temp].pack(\"U\")\n col /= ('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)\n end\n col_.reverse!\n puts col_+row\n end\n n-=1\nend\n\n"}, {"source_code": "def n2s(n)\n s = \"\"\n while n > 0\n s = (\"A\".ord + (n - 1) % 26).chr + s\n n = (n - (n - 1) % 26 - 1) / 26\n end\n return s\nend\n\ndef s2n(s)\n n = 0\n s.size.times do |i|\n n *= 26\n n += s[i].ord - \"A\".ord + 1\n end\n return n\nend\n\nn = gets.to_i\nn.times do\n str = gets\n if str =~ /^([A-Z]+)(\\d+)$/\n c_s = $1\n r = $2.to_i\n c = s2n(c_s)\n puts \"R#{r}C#{c}\"\n elsif str =~ /^R(\\d+)C(\\d+)$/\n r = $1.to_i\n c = $2.to_i\n c_s = n2s(c)\n puts \"#{c_s}#{r}\"\n end\nend\n"}, {"source_code": "def f(x)\nreturn x<26?((x+65).chr):(f(x/26-1)+(x%26+65).chr)\nend\na=*$<.drop(1).map(&:chomp).each{|x|puts /R(\\d+)C(\\d+)/.match(x)?(f($2.to_i-1)+$1):(y=0;v=1;/(\\D+)(\\d+)/.match(x);$1.reverse.each_char{|c|y+=(c.ord-64)*v;v*=26};\"R\"+$2+\"C\"+y.to_s)}"}, {"source_code": "def num_to_ch(num)\n str = \"\"\n until num<1\n num -= 1\n str << (65+num%26).chr\n num /= 26\n end\n str.reverse\nend\ndef ch_to_num(ch)\n num = 0\n ch.each_codepoint{|x| num = 26 * num + x - 64}\n num\nend\nn = gets.to_i\nn.times do\n input = gets.chomp\n if input =~ /R\\d+C\\d+/\n row, col = input.scan(/R(\\d+)C(\\d+)/).first.map(&:to_i)\n puts \"#{num_to_ch(col)}#{row}\"\n else\n col, row = input.scan(/([[:upper:]]+)(\\d+)/).first\n puts \"R#{row}C#{ch_to_num(col)}\"\n end\nend"}, {"source_code": "num = gets.chomp.to_i\nnum.times do\n old = gets.chomp\n results = old.match('R(\\d+)C(\\d+)')\n if results != nil\n col_num = results[2].to_i\n base = 1;\n col_str = \"\"\n while col_num > 26\n this_char = col_num % 26\n col_num /= 26\n if this_char == 0\n this_char = 26\n col_num -= 1\n end\n col_str = \"#{(this_char+64).chr}#{col_str}\"\n end\n col_str = \"#{(col_num+64).chr}#{col_str}\"\n puts \"#{col_str}#{results[1]}\"\n else\n results = old.match('([A-Z]+)(\\d+)')\n col_str = results[1]\n base = 26**(col_str.length-1)\n col_num = 0\n col_str.each_char do |c| \n col_num += (c.ord-64)*base\n base /= 26\n end\n puts \"R#{results[2]}C#{col_num}\"\n end\nend"}, {"source_code": "#!/usr/bin/ruby\ndef fromcell(s)\n r=0\n s.each_byte{|i|\n r=r*26+i-64\n }\n return r\nend\n\ndef tocell(n)\n r=\"\"\n while n>0 do\n x=n%26\n if x==0 then x=26; n-=26 end\n r=(x+64).chr+r\n n/=26\n end\n return r\nend\n\nn=gets.chomp.to_i\nn.times{|z|\n s=gets.chomp\n if s=~/^([A-Z]+)(\\d+)$/ then puts \"R\"+$2.to_s+\"C\"+fromcell($1).to_s end\n if s=~/R(\\d+)C(\\d+)/ then puts tocell($2.to_i)+$1.to_s end\n}\n"}, {"source_code": "$table = [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\"]\n\ndef to_E(x)\n b = \"\"\n t = true\n while x > 26 do\n if x % 26 == 0 then\n str = to_E(x-1)\n str[-1] = \"Z\"\n b = str + b\n x = 0\n t = false\n else\n b = $table[(x % 26) - 1] + b\n x /= 26\n end\n end\n if t then\n b = $table[x-1] + b\n end\n return b\nend\n\ndef to_T(x)\n str = x.gsub(/[0123456789]/, \"*\")\n k = str.index(\"*\")\n str1 = str[0...k]\n r = 0\n q = 26\n n = str1.size\n n.times do |i|\n r += ($table.index(str1[i]) + 1)*q**(n-i-1)\n# p (n-i-1)\n# p $table.index(str1[i]) + 1\n# p r\n end\n result = \"R\" + x[k..-1] + \"C\" + r.to_s\n return result \nend\n\nn = gets.to_i\nind = []\noutd = []\nn.times do |i|\n ind[i] = gets.chomp\n r = ind[i].index(\"R\")\n c = ind[i].index(\"C\")\n str = ind[i].gsub(/[ABDEFGHIJKLMNOPQSTUVWXYZ]/, \"*\")\n k = str.index(\"*\")\n if r && c && !k && c-r>1 then\n ind[i] = to_E(ind[i][c+1..-1].to_i) + ind[i][r+1...c]\n else\n ind[i] = to_T(ind[i])\n end\nend\nn.times do |i|\n puts \"#{ind[i]}\"\nend"}, {"source_code": "def f(s)\n\tr=0\n\ts.each_byte{|c| r=r*26+c-64}\n\tr\nend\ndef g(n)\n\tr=\"\"\n\twhile n>0 do\n\t\tx=n%26\n\t\tif x==0 then\n\t\t\tx=26\n\t\t\tn-=x\n\t\tend\n\t\tr=(x+64).chr+r\n\t\tn/=26\n\tend\n\tr\nend\nn=gets.to_i\nn.times{\n\ts=gets\n\tif s=~/^([A-Z]+)(\\d+)$/ then\n\t\tputs \"R\"+$2.to_s+\"C\"+f($1).to_s\n\tend\n\tif s=~/R(\\d+)C(\\d+)/ then\n\t\tputs g($2.to_i)+$1\n\tend\n}\n"}, {"source_code": "gets.to_i.times do\n\tgets\n\tif /^(\\D+)(\\d+)$/ then\n\t\tputs \"R#{$2}C#{(0..$1.size-1).map{|i|26**i}.inject{|i,j|i+j}+$1.tr('A-Z','0-9A-Z').to_i(26)}\"\n\telsif /R(.*)C/ then\n\t\tl,n=-1,$'.to_i\n\t\tn-=26**(l+=1) while n>=0\n\t\tn+=26**l\n\t\tputs n.to_s(26).tr('0-9a-z','A-Z').rjust(l,'A')+$1\n\tend\nend\n"}, {"source_code": "n = gets.to_i\nrow, col, string = nil\n$alf = ('A'..'Z').to_a\n\ndef int_to_symbolyc(int)\n result = ''\n mult = 1\n while int > 0\n to_sub = int % 26\n index = (to_sub - 1 % 26)\n to_sub = 26 if to_sub==0\n result = $alf[index] + result\n int -= to_sub\n int = int / 26\n end\n result\nend\n\ndef sym_to_int(string)\n result = 0\n a_code = 'A'.bytes.first\n mult = 1\n string.reverse.bytes.each_with_index do |char, i|\n to_add = char - a_code + 1\n to_add *= mult\n result += to_add\n mult *= 26\n end\n result\nend\n\nn.times do\n string = gets\n if matches = string.match(/R(\\d+)C(\\d+)/)\n row, col = matches[1], matches[2]\n puts \"#{int_to_symbolyc(col.to_i)}#{row}\"\n else\n matches = string.match(/([A-Z]+)(\\d+)/)\n col, row = matches[1], matches[2]\n puts \"R#{row}C#{sym_to_int(col)}\"\n end\nend"}, {"source_code": "n = gets.to_i\nn.times do\n\tstr = gets.chomp\n\t\n\tif re = str.match(/^R(\\d+)C(\\d+)$/)\n\t\tc = re[2].to_i\n\t\ts = \"\"\n\t\twhile c != 0\n\t\t\tmod = c % 26\n\t\t\tif mod == 0\n\t\t\t\tmod = 26\n\t\t\t\tc -= mod\n\t\t\tend\n\t\t\ts << (mod + 64).chr\n\t\t\tc /= 26\n\t\tend\n\t\tprint s.reverse, re[1], \"\\n\"\n\telsif re = str.match(/^([A-Z]+)(\\d+)$/)\n\t\tc = 0\n\t\tre[1].each_byte do |char|\n\t\t\tc = char - 64 + c * 26\n\t\tend\n\t\tprint \"R\", re[2], \"C\", c, \"\\n\"\n\tend\nend"}, {"source_code": "def f x;x<26?((x+65).chr):f(x/26-1)+(x%26+65).chr;end;gets.to_i.times{x=gets;puts /R(\\d+)C(\\d+)/.match(x)?f($2.to_i-1)+$1:(y=0;v=1;/(\\D+)(\\d+)/.match x;$1.reverse.each_char{|c|y+=(c.ord-64)*v;v*=26};\"R#{$2}C#{y}\")}"}, {"source_code": "n = gets.to_i\nfor x in gets(\"\").split.take(n)\n if x[/R(\\d+)C(\\d+)/]\n a = $2.to_i - 1\n t = (\"A\"..\"Z\").to_a.join[a%26]\n a = a.div 26\n until a == 0\n b,c = (a-1).divmod(26)\n t = (\"A\"..\"Z\").to_a.join[c] + t\n a = b\n end\n puts t + $1\n else\n puts \"R#{x[/\\d+/]}C#{x[/\\D+/].chars.inject(0){|i,j|i*26+j.ord-\"A\".ord+1}}\"\n end\nend"}, {"source_code": "def f(x)\nreturn x<26?((x+65).chr):(f(x/26-1)+(x%26+65).chr)\nend\ngets.to_i.times{x=gets;puts /R(\\d+)C(\\d+)/.match(x)?(f($2.to_i-1)+$1):(y=0;v=1;/(\\D+)(\\d+)/.match(x);$1.reverse.each_char{|c|y+=(c.ord-64)*v;v*=26};\"R\"+$2+\"C\"+y.to_s)}"}], "negative_code": [{"source_code": "arr = STDIN.read.split(\"\\n\")\nn = arr[0].to_i\n\n1.upto(n).each do |i|\n str = arr[i]\n match = str.match(/R([0-9]+)C([0-9]+)/)\n\n if match\n row = match[2].to_i\n col = match[1]\n\n r = row\n str = \"\"\n while(r > 0) do\n val = (r-1) % 26\n str += (val + 65).chr\n r /= 26\n end\n str = str.reverse\n str += col\n puts str\n else\n match = str.match(/([A-Z]+)([0-9]+)/)\n col = match[1]\n row = match[2]\n\n puts \"A\"\n s = 0\n rev = col.reverse.split(\"\")\n puts \"B\"\n rev.each_index do |i|\n puts \"rev[i]\" + rev[i]\n puts rev[i].ord - 65 + 1\n chr = (rev[i].ord - 65 + 1) * ( 26 ** i )\n puts \"chr:#{chr}\"\n s += chr\n end\n\n puts \"R#{row}C#{s}\"\n end\nend"}, {"source_code": "#!/usr/bin/ruby\ndef fromcell(s)\n r=0\n s.length.times{|i|\n #r=r*26+s[i]-64\n }\n return r\nend\n\ndef tocell(n)\n r=\"\"\n while n>0 do\n r=(n%26+64).chr+r\n n/=26\n end\n return r\nend\n\nn=gets.chomp.to_i\nn.times{|z|\n s=gets.chomp\n if s=~/^([A-Z]+)(\\d+)$/ then puts \"R\"+$2.to_s+\"C\"+fromcell($1).to_s end\n if s=~/R(\\d+)C(\\d+)/ then puts tocell($2.to_i)+$1.to_s end\n}\nexit(0)\n"}, {"source_code": "n = gets().to_i\nfor i in 1..n\n\tline = gets().split(/(\\d+)/)\n\tif line[0] == 'R'\n\t\tcol = line[3].to_i\n\t\tfor j in 1..100\n\t\t\tbreak if 26**j >= col\n\t\t\tcol -= 26**j\n\t\tend\n\t\ts = (col-1).to_s(26).rjust(j,'0').tr('0123456789abcdefghijklmnop', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')\n\t\tputs s << line[1]\n\telse\n\t\trow = line[1]\n\t\tans = 1 + line[0].tr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789abcdefghijklmnop').to_i(26) \n\t\tfor j in 1..line[0].length-1\n\t\t\tans += 26**j\n\t\tend\n\t\tputs 'R' << row << 'C' << ans.to_s\n\tend\nend\n"}, {"source_code": "def n2s(n)\n s = \"\"\n while n > 0\n s = (\"A\".ord + n % 26 - 1).chr + s\n n /= 26\n end\n return s\nend\n\ndef s2n(s)\n n = 0\n s.size.times do |i|\n n *= 26\n n += s[i].ord - \"A\".ord + 1\n end\n return n\nend\n\nn = gets.to_i\nn.times do\n str = gets\n if str =~ /^([A-Z]+)(\\d+)$/\n c_s = $1\n r = $2.to_i\n c = s2n(c_s)\n puts \"R#{r}C#{c}\"\n elsif str =~ /^R(\\d+)C(\\d+)$/\n r = $1.to_i\n c = $2.to_i\n c_s = n2s(c)\n puts \"#{c_s}#{r}\"\n end\nend\n"}, {"source_code": "alph = ['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\nn = gets.chomp.to_i\n\nlines = []\nn.times {lines << gets.chomp}\nlines.each do |l|\n if (l =~ /R\\d+C\\d+/).nil?\n col = 0\n colstr = l.scan(/[A-Z]+/).first.split(\"\")\n colstr.each_with_index do |ch, index|\n col += (alph.index(ch) + 1) * (26 ** (colstr.length - index - 1))\n end\n row = l.scan(/[0-9]+/).first\n puts \"R#{row}C#{col}\"\n else\n row = l.scan(/R([0-9]+)/).flatten.first\n col = l.scan(/C([0-9]+)/).flatten.first.to_i\n cols = \"\"\n remainder = 1\n loop do\n minus = remainder == 0 ? 2 : 1\n remainder = (col % 26)\n col = col / 26\n unless col == 0 and minus == 2 and remainder <= 1\n cols = alph[remainder - minus] + cols\n end\n break if col == 0\n end\n puts \"#{cols}#{row}\"\n end\nend\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\ndef to_letters num\n\tans=\"\"\n\tdigs=[*?A..?Z]\n\t\n\tnum+=num/27\n\t\n\twhile num!=0\t\n\t\tans+=digs[num%27-1]\n\t\tnum/=27\n\tend\n\t\n\tans.reverse\nend\n\ndef to_numbers str\n\tans=0\n\tstr.reverse!\n\t\n\tpow=0\n\tstr.each_char{|c|\n\t\tans+= (c.ord - 'A'.ord + 1) * 26**pow\n\t\tpow+=1\n\t}\n\t\n\tans\nend\n\nn=gets.to_i\n\nn.times{\n\tline=gets.strip\n\t\n\tif /R(\\d+)C(\\d+)/.match line\n\t\tputs \"#{to_letters $2.to_i}#{$1}\"\n\telse\n\t\tp1, p2 = line.scan(/([A-Z]+)([0-9]+)/)[0]\n\t\tputs \"R#{p2}C#{to_numbers p1}\"\n\tend\n}\n"}, {"source_code": "def to_ex d\n str = \"\"\n while d > 1\n d, a = d.divmod(26)\n str = (a + 64).chr + str\n end\n str\nend\n\ndef ex_to str\n str.chars.each.with_index.inject(0){ |z, (v, i)| z = z * 26 + (v.ord - 64) }\nend\n\ndef solution str\n a, b = str.scan(/\\d+/).map(&:to_i)\n if b\n \"#{to_ex(b)}#{a}\"\n else\n a, b = str.scan(/([A-Z]+)(\\d+)/).first\n \"R#{b}C#{ex_to(a)}\"\n end \nend\n\nn = STDIN.gets.to_i\nArray.new(n){ solution(STDIN.gets.chomp) }.each{ |v| print v, \"\\n\" }"}, {"source_code": "alph = ['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\nn = gets.chomp.to_i\n\nlines = []\nn.times {lines << gets.chomp}\nlines.each do |l|\n if (l =~ /R\\d+C\\d+/).nil?\n col = 0\n colstr = l.scan(/[A-Z]+/).first.split(\"\")\n colstr.each_with_index do |ch, index|\n col += (alph.index(ch) + 1) * (26 ** (colstr.length - index - 1))\n end\n row = l.scan(/[0-9]+/).first\n puts \"R#{row}C#{col}\"\n else\n row = l.scan(/R([0-9]+)/).flatten.first\n col = l.scan(/C([0-9]+)/).flatten.first.to_i\n cols = \"\"\n loop do\n remainder = (col % 26)\n cols = alph[remainder - 1] + cols\n col = col / 26\n break if col == 0\n end\n puts \"#{cols}#{row}\"\n end\nend\n"}, {"source_code": "\n\nnumber_of_input=gets.to_i\ninput_arry=[]\ni_a=0\n\n\nloop do\n\tbreak if i_a==number_of_input\n\tinput_arry[i_a]=gets.chomp\n\ti_a +=1\nend\nputs \"______________________\"\nvalue=(1..26)\nalph=('A'..'Z')\nvalue=[*value]\nalph=[*alph]\n@hash={}\ni_b=0\n\nloop do\n\tbreak if i_b==26\n\t@hash[alph[i_b]]=value[i_b]\n\ti_b+=1\nend\t\n\nvalue=(1..26)\nalph=('A'..'Z')\nvalue=[*value]\nalph=[*alph]\n@hash2={}\ni_b=0\n\nloop do\n\tbreak if i_b==26\n\t@hash2[alph[i_b]]=value[i_b]\n\ti_b+=1\nend\t\n@hash2['Z']=0\n\n\ndef S1_to_S2 (a1)\n\tr=a1[0]\n\ti=1\n\t\n\tloop do\n\t\tbreak if a1[i].to_i !=0\n\t\tr =r + a1[i]\n\t\ti+=1\n\tend\n\n\tr1=r.length\n\tr2=a1.length\n\tc1= a1[0 .. (r1-1)].reverse\n\trow= a1[ r1 .. r2].to_i\n\tc=0\n\ti=0\n\t\n\tloop do\n\t\tbreak if i==c1.length\n\t\tc= c + (@hash[c1[i]]*(26**i))\n\t\ti+=1\n\tend\n\t\n\tputs \"R#{row}C#{c}\"\nend\n\ndef S2_to_S1 (a1)\n\ts2=a1.split(\"\").map{|s| s}\n\tr3=3\n\ts2.find {|i| r3=s2.index(i)+1 if i=='C'}\n\ti=s2[r3 .. (s2.length - 1)].join.to_i\n\trow=s2[1 .. (r3-2)].join.to_i\n\tstr_c=\"\"\n\t\n\tloop do\n\t\ti=i-26 if i>25 && i%26==0\n\t\tstr_c = str_c + @hash2.key(i%26)\n\t\ti=i/26\n\t\tbreak if i==0\n\tend\n\t\n\tstr_c=str_c.reverse\n\tputs \"#{str_c}#{row}\"\nend\n\t\ni_c =0\n\nloop do\n break if i_c==input_arry.length\n\tinput1=input_arry[i_c]\n\t\n\tif \tinput1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0) \n\t\tS1_to_S2 (input1)\n\telsif input1[0]=='R' && input1[1].to_i!=0\n\t\tk2=input1.split(\"\")\n\t\tk=0\n\t\tk2.find{|s| k=1 if s=='C'}\n\t\tif k==1\n\t\t\tS2_to_S1(input1)\n\t\telse\n\t\t\tS1_to_S2 (input1)\n\t\tend\t\n\tend\n\t\n\ti_c +=1\n\t\nend\n\t"}, {"source_code": "\t#recibiendo el numero de iteraciones\n\tinput=gets.chomp\n\tn=input.to_i\n\t#metodo para saber si la cadena es excel o random\n\tdef validar_excel(a)\n\t\tif a.include?(\"R\") && a.include?(\"C\") #como el metodo random tiene R&C \n\t\t\tir=a.index(\"R\") #queremos el index de cada letra\n\t\t\tic=a.index(\"C\") #porque para q sea random, la diferencia debe ser 1\n\t\t\treturn (ic-ir)==1? true : false \n\t\telse\n\t\t\treturn true\n\t\tend\n\tend\n\t#revisar\n\tdef convertir(ar)\n\t\tn=ar.size-1\t\n\t\ti=0\n\t\tnum=0\n\t\t\n\t\tloop do\n\t\t\tif n<0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\t\n\t\t\tnum=num+(ar[i].ord-64)*(26**n)\n\t\t\tn-=1\n\t\t\ti+=1\n\t\tend\n\t\t\n\t\treturn num\n\tend\n\t\n\t#primer metodo de BC23 a R23C55\n\tdef excel_to_random(arr)\n\t\tparte_num=\"\"\n\t\tparte_str=\"\"\n\t\t\n\t\t0.upto(arr.size-1) do |k|\n\t\t\tif (arr[k].ord<=57 && arr[k].ord>=48) #ASCII para diferenciar num & str\n\t\t\t\tparte_num=parte_num+arr[k]\n\t\t\telse\n\t\t\t\tparte_str=parte_str+arr[k]\n\t\t\tend\n\t\tend\n\t\t\n\t\tparte_c=convertir(parte_str)\n\t\trandom=\"R\"+\"#{parte_num}\"+\"C\"+\"#{parte_c}\" #creando el random\n\t\t\n\t\treturn random\n\tend\n\t\n\t#metodo divisiones sucesivas?\n\tdef divsuc(num)\n\t\tnum_car=26\n\t\tpivot=num\n\t\tndig=0\n\t\tarreglo_num=[]\n\t\tpotencia=1\n\t\t\n\t\tloop do\n\t\t\tpivot=pivot-26**potencia\n\t\t\tndig+=1\n\t\t\tpotencia+=1\n\t\t\tif pivot<=0\n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\t\t\n\t\t#real deal\n\t\tloop do\n\t\t\tif num==0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tif num%num_car !=0\n\t\t\t\tarreglo_num[ndig-1]=((num%num_car)+64).chr()\n\t\t\t\tnum=num/num_car\n\t\t\telse #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)\n\t\t\t\tq=num/num_car\n\t\t\t\tnum=q-1\n\t\t\t\tarreglo_num[ndig-1]=(num_car+64).chr()\n\t\t\tend\n\t\t\tndig-=1\n\t\tend\n\t\treturn arreglo_num\n\tend\n\t\n\t#segundo metodo de R23C55 a BC23\n\tdef random_to_excel(arr)\n\t\trow=\"\"\n\t\tcol=\"\"\n\t\ta=0\n\t\t\n\t\t1.upto(arr.size-1) do |k|\n\t\t\t(arr[k]==\"C\")? a+=1:a+=0\n\n\t\t\tif a==0\n\t\t\t\trow=row+arr[k]\n\t\t\telse\n\t\t\t\tif (arr[k]!=\"C\") \n\t\t\t\t\tcol=col+arr[k]\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tcol=col.to_i\n\t\tcole=divsuc(col)#convertir la columna a excel\n\t\texcel=cole.join+row\n\t\t\n\t\treturn excel\n\tend\n\t\n\t$res=[] #definici\u00f3n de la variable GLOBAL, para poder imprimirlo despu\u00e9s\n\t\n\t0.upto(n-1) do |j|\n\t\tcadena=gets.chomp.upcase\n\t\tarray=cadena.split(\"\")\n\t\ti=validar_excel(array)\n\t\t\n\t\tif i\n\t\t\tresultado=excel_to_random(array)\n\t\telse\n\t\t\tresultado=random_to_excel(array)\n\t\tend\n\t\t\t\n\t\t$res[j]=resultado \t#recordar que el puts imprime con /n y el print no lo hace\n\tend\n\t\n\t#IMPRIMIR RESULTADO\n\tputs $res"}, {"source_code": "num = gets.chomp.to_i\nnum.times do\n old = gets.chomp\n results = old.match('R(\\d+)C(\\d+)')\n if results != nil\n col_num = results[2].to_i\n base = 1;\n col_str = \"\"\n while col_num > 26\n this_char = col_num % 26\n col_num /= 26\n if this_char == 0\n this_char = 26\n end\n col_num -= 1\n col_str = \"#{(this_char+64).chr}#{col_str}\"\n end\n col_str = \"#{(col_num+64).chr}#{col_str}\"\n puts \"#{col_str}#{results[1]}\"\n else\n results = old.match('([A-Z]+)(\\d+)')\n col_str = results[1]\n base = 26**(col_str.length-1)\n col_num = 0\n col_str.each_char do |c| \n col_num += (c.ord-64)*base\n base /= 26\n end\n puts \"R#{results[2]}C#{col_num}\"\n end\nend"}, {"source_code": "def excel_to_index(number)\n row = number.gsub(/[a-zA-Z]/, '').chomp\n column = number.gsub(/\\d/, '').chomp\n\n length = column.length\n column_index = 0\n column.each_char do |c|\n column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))\n length -= 1\n end\n\n 'R' + row + 'C' + column_index.to_s\nend\n\ndef index_to_excel(number)\n row, column = number.sub(/R/, '').split(/C/).map(&:to_i)\n\n column_index = column.to_s(26).upcase\n column_letters = ''\n column_index.each_char do |c|\n if c.ord > '9'.ord\n column_letters += (c.ord + 9).chr\n else\n column_letters += (c.ord + 'A'.ord - '1'.ord).chr\n end \n end\n\n column_letters + row.to_s\nend \n\ncount = gets.to_i\n\ncount.times do\n num = gets.upcase\n if num[/R\\d+C\\d+/]\n puts index_to_excel num\n else\n puts excel_to_index num\n end \nend"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\ndef to_number str\n\tnum = 0\n\tdigits = [*?A..?Z]\n\t\n\tpow=1\n\tstr.reverse.each_char{|c|\t\t\n\t\td = digits.index(c) + 1\n\t\t\n\t\tnum+=d*pow\n\t\tpow*=26\n\t}\n\t\n\tnum\nend\n\ndef to_first line\n\tletters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]\n\t\"R#{number}C#{to_number letters}\"\nend\n\ndef to_27 num\n\tans = \"\"\n\tdigits = [*?A..?Z]\n\t\n\tnum = num.to_i\n\twhile num!=0\n\t\tans+=digits[num%27]\n\t\tnum/=27\n\tend\n\t\n\tans\nend\n\ndef to_second line\n\ta, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]\t\n\t\"#{to_27 b}#{a}\"\nend\n\nn=gets.to_i\n\nn.times{\n\tline=gets.strip\n\t\n\tif /R([0-9]+)C([0-9]+)/.match line\n\t\tputs to_second line\n\telse\n\t\tputs to_first line\n\tend\n}\n"}, {"source_code": "#!/usr/bin/ruby\ndef fromcell(s)\n r=0\n s.length.times{|i|\n r=r*26+s[i]-64\n }\n return r\nend\n\ndef tocell(n)\n r=\"\"\n while n>0 do\n r=(n%26+64).chr+r\n n/=26\n end\n return r\nend\n\nn=gets.chomp.to_i\nn.times{|z|\n s=gets.chomp\n if s=~/^([A-Z]+)(\\d+)$/ then \nputs \"R\"\n#+$2.to_s+\"C\"+fromcell($1).to_s\nend\n if s=~/R(\\d+)C(\\d+)/ then puts tocell($2.to_i)+$1.to_s end\n}\nexit(0)\n"}, {"source_code": "n = STDIN.gets\nn.to_i.times do |i|\n a = STDIN.gets\n if a =~ /\\d+[A-Z]+/\n r = a.split(/[A-Z]/)[1]\n c = a.split(/[A-Z]/)[2].to_i\n completeAddress = Array.new\n while (c != 0)\n completeAddress.push((c%26 + 64).chr)\n c /= 26\n end\n completeAddress = completeAddress.reverse.join(\"\")\n completeAddress += r + \"\\n\"\n print completeAddress\n else\n c = a[0,a=~/\\d/]\n r = a.gsub(/[A-Z]+/,\"\")\n realrow = 0\n c.bytes.each do |i|\n realrow *= 26\n realrow += (i - 64)\n end\n print \"R\" + r.strip + \"C\" + realrow.to_s + \"\\n\"\n end\nend "}, {"source_code": "def f(x)\nreturn x<27?((x+64).chr):(f(x/26)+(x%26+65).chr)\nend\na=*$<.drop(1).map(&:chomp).each{|x|puts /R(\\d+)C(\\d+)/.match(x)?(f($2.to_i-1)+$1):(y=0;v=1;/(\\D+)(\\d+)/.match(x);$1.reverse.each_char{|c|y+=(c.ord-64)*v;v*=26};\"R\"+$2+\"C\"+y.to_s)}"}, {"source_code": "class SpreadSheets\n def main\n numberOfLines = gets.to_i\n coordinates = Array.new(numberOfLines)\n\n i = 0\n while i < numberOfLines\n coordinates[i] = gets\n i += 1\n end\n\n puts convert(coordinates)\n end\n\n def convert(coordinates)\n result = Array::new\n numericDef = /R(\\d+)C(\\d+)/\n alphanumericDef = /([a-zA-Z]+)(\\d+)/\n\n coordinates.each do |coordinate|\n if (numericDef.match(coordinate))\n matches = numericDef.match(coordinate)\n row = matches[1]\n column = matches[2]\n convertedColumn = convertNumToAlpha(column.to_i)\n result.push(\"#{convertedColumn}#{row}\")\n elsif (alphanumericDef.match(coordinate))\n matches = alphanumericDef.match(coordinate)\n row = matches[2]\n column = matches[1]\n convertedColumn = convertAlphaToNum(column)\n result.push(\"R#{row}C#{convertedColumn}\")\n end\n end\n\n return result\n end\n\n def convertNumToAlpha(num)\n result = String::new\n\n zeroLetter = 'A';\n base26 = 26;\n loop do\n num -= 1;\n remainder = num % base26;\n result = \"#{(zeroLetter.ord + remainder).chr}#{result}\"\n num /= base26;\n break if (num == 0)\n end\n\n return result\n end\n\n def convertAlphaToNum(alpha)\n result = 0\n\n zeroLetter = 'A'\n currentExp = 1\n base26 = 26\n alpha.split(\"\").reverse_each do |letter|\n convertedDigit = letter.ord - zeroLetter.ord\n result = result * currentExp + (convertedDigit + 1)\n currentExp *= base26\n end\n\n return result.to_s\n end\nend\n\nSpreadSheets::new.main\n"}, {"source_code": "\t#recibiendo el numero de iteraciones\n\tinput=gets.chomp\n\tn=input.to_i\n\t#metodo para saber si la cadena es excel o random\n\tdef validar_excel(a)\n\t\tif a.include?(\"R\") && a.include?(\"C\") #como el metodo random tiene R&C \n\t\t\tir=a.index(\"R\") #queremos el index de cada letra\n\t\t\tic=a.index(\"C\") #porque para q sea random, la diferencia debe ser 1\n\t\t\treturn (ic-ir)==1? true : false \n\t\telse\n\t\t\treturn true\n\t\tend\n\tend\n\t#revisar\n\tdef convertir(ar)\n\t\tn=ar.size-1\t\n\t\ti=0\n\t\tnum=0\n\t\t\n\t\tloop do\n\t\t\tif n<0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\t\n\t\t\tnum=num+(ar[i].ord-64)*(26**n)\n\t\t\tn-=1\n\t\t\ti+=1\n\t\tend\n\t\t\n\t\treturn num\n\tend\n\t\n\t#primer metodo de BC23 a R23C55\n\tdef excel_to_random(arr)\n\t\tparte_num=\"\"\n\t\tparte_str=\"\"\n\t\t\n\t\t0.upto(arr.size-1) do |k|\n\t\t\tif (arr[k].ord<=57 && arr[k].ord>=48) #ASCII para diferenciar num & str\n\t\t\t\tparte_num=parte_num+arr[k]\n\t\t\telse\n\t\t\t\tparte_str=parte_str+arr[k]\n\t\t\tend\n\t\tend\n\t\t\n\t\tparte_c=convertir(parte_str)\n\t\trandom=\"R\"+parte_num+\"C\"+\"#{parte_c}\" #creando el random\n\t\t\n\t\treturn random\n\tend\n\t\n\t#metodo divisiones sucesivas?\n\tdef divsuc(num)\n\t\tnum_car=26\n\t\tpivot=num\n\t\tndig=0\n\t\tarreglo_num=[]\n\t\tpotencia=1\n\t\t\n\t\tloop do\n\t\t\tpivot=pivot-26**potencia\n\t\t\tndig+=1\n\t\t\tpotencia+=1\n\t\t\tif pivot<=0\n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\t\t\n\t\t#real deal\n\t\tloop do\n\t\t\tif num==0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tif num%num_car !=0\n\t\t\t\tarreglo_num[ndig-1]=((num%num_car)+64).chr()\n\t\t\t\tnum=num/num_car\n\t\t\telse #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)\n\t\t\t\tq=num/num_car\n\t\t\t\tnum=q-1\n\t\t\t\tarreglo_num[ndig-1]=(num_car+64).chr()\n\t\t\tend\n\t\t\tndig-=1\n\t\tend\n\t\treturn arreglo_num\n\tend\n\t\n\t#segundo metodo de R23C55 a BC23\n\tdef random_to_excel(arr)\n\t\trow=\"\"\n\t\tcol=\"\"\n\t\ta=0\n\t\t\n\t\t1.upto(arr.size-1) do |k|\n\t\t\t(arr[k]==\"C\")? a+=1:a+=0\n\n\t\t\tif a==0\n\t\t\t\trow=row+arr[k]\n\t\t\telse\n\t\t\t\tif (arr[k]!=\"C\") \n\t\t\t\t\tcol=col+arr[k]\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tcol=col.to_i\n\t\tcole=divsuc(col)#convertir la columna a excel\n\t\texcel=cole.join+row\n\t\t\n\t\treturn excel\n\tend\n\t\n\t$res=[] #definici\u00f3n de la variable GLOBAL, para poder imprimirlo despu\u00e9s\n\t\n\t0.upto(n-1) do |j|\n\t\tcadena=gets.chomp.upcase\n\t\tarray=cadena.split(\"\")\n\t\ti=validar_excel(array)\n\t\t\n\t\tif i\n\t\t\tresultado=excel_to_random(array)\n\t\telse\n\t\t\tresultado=random_to_excel(array)\n\t\tend\n\t\t\t\n\t\t$res[j]=resultado \t#recordar que el puts imprime con /n y el print no lo hace\n\tend\n\t\n\t#IMPRIMIR RESULTADO\n\tputs $res"}, {"source_code": "def excel_to_index(number)\n row = number.gsub(/[a-zA-Z]/, '').chomp\n column = number.gsub(/\\d/, '').chomp\n\n length = column.length\n column_index = 0\n column.each_char do |c|\n column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))\n length -= 1\n end\n\n 'R' + row + 'C' + column_index.to_s\nend\n\ndef index_to_excel(number)\n row, column = number.sub(/R/, '').split(/C/).map(&:to_i)\n\n column_index = column.to_s(26)\n column_letters = ''\n column_index.each_char do |c|\n if c.ord > '9'.ord\n column_letters += (c.ord + 9).chr\n else\n column_letters += (c.ord + 'A'.ord - '1'.ord).chr\n end \n end\n\n column_letters + row.to_s\nend \n\ncount = gets.to_i\n\ncount.times do\n num = gets.upcase\n if num[/R\\d+C\\d+/]\n puts index_to_excel num\n else\n puts excel_to_index num\n end \nend"}, {"source_code": "num = gets.chomp.to_i\nnum.times do\n old = gets.chomp\n results = old.match('R(\\d+)C(\\d+)')\n if results != nil\n col_num = results[2].to_i\n base = 1;\n col_str = \"\"\n while col_num > 26\n this_char = col_num % 26\n if this_char == 0\n this_char = 26\n end\n col_num /= 26\n col_str = \"#{(this_char+64).chr}#{col_str}\"\n end\n col_str = \"#{(col_num+64).chr}#{col_str}\"\n puts \"#{col_str}#{results[1]}\"\n else\n results = old.match('([A-Z]+)(\\d+)')\n col_str = results[1]\n base = 26**(col_str.length-1)\n col_num = 0\n col_str.each_char do |c| \n col_num += (c.ord-64)*base\n base /= 26\n end\n puts \"R#{results[2]}C#{col_num}\"\n end\nend"}, {"source_code": "$table = [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\"]\n\ndef to_E(x, y)\n b = \"\"\n if x % 26 == 0 then\n b = to_E(x-1, y)\n b[-y.size-1] = \"Z\"\n else\n while x > 26 do\n b = $table[(x % 26) - 1] + b\n x /= 26\n end\n b = $table[x-1] + b\n b += y \n end\n return b\nend\n\ndef to_T(x)\n str = x.gsub(/[0123456789]/, \"*\")\n k = str.index(\"*\")\n str1 = str[0...k]\n r = 0\n q = 26\n n = str1.size\n n.times do |i|\n r += ($table.index(str1[i])+1)*q**(n-i-1)\n end\n result = \"R\" + x[k..-1] + \"C\" + r.to_s\n return result \nend\n\nn = gets.to_i\nind = []\noutd = []\nn.times do |i|\n ind[i] = gets.chomp\n r = ind[i].index(\"R\")\n c = ind[i].index(\"C\")\n if r && c && c-r > 1 then\n ind[i] = to_E(ind[i][c+1..-1].to_i, ind[i][r+1...c])\n else\n ind[i] = to_T(ind[i])\n end\nend\nn.times do |i|\n puts \"#{ind[i]}\"\nend"}, {"source_code": "def f(x)\nreturn x<27?((x+64).chr):(f(x/26)+(x%26+65).chr)\nend\na=*$<.drop(1).map(&:chomp).each{|x|puts /R(\\d+)C(\\d+)/.match(x)?(f($2.to_i-1)+$1):(y=0;v=1;/(\\D+)(\\d+)/.match(x);$1.reverse.each_char{|c|y+=(c.ord-64)*v;v*=26};\"R\"+$2+\"C\"+y.to_s)}"}, {"source_code": "$letters = [\"\"].concat((\"A\"..\"Z\").to_a)\n\ndef rc_ab(rc)\n rc_a = rc.scan(/\\d+/)\n rc_a[1] = rc_a[1].to_i\n s = \"\"\n \n while(rc_a[1] != 0) do\n s << $letters[rc_a[1] % 26]\n rc_a[1] /= 26\n end\n \n s = s.reverse << rc_a[0]\n return s\nend \n\ndef ab_rc(ab)\n ab_c = /[A-Z]+/.match(ab)\n \n ab_s = ab_c.to_s.reverse\n ab_n = 0\n \n ab_s.length.times {\n |i|\n ab_n += $letters.index(ab_s[i,1]) * 26 ** i\n }\n \n s = \"R\" << ab_n.to_s << \"C\" << /\\d+/.match(ab).to_s\n return s\nend\n\nn = gets().chomp.to_i\na = []\nn.times {\n|i|\n a[i] = gets().chomp()\n}\na.each{\n|i|\n if (/^R\\d+C\\d+$/ =~ i) then\n #RXCY \n puts(rc_ab(i))\n else\n #AB23\n puts(ab_rc(i))\n end\n}\n"}, {"source_code": "letters = %w(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\ngets.to_i.times do\n input = gets.strip\n if input =~ /R(\\d)+C/\n codes = input.gsub(\"R\",\"\").split(\"C\").map(&:to_i)\n ans = \"\"\n codes[1]\n puts codes[1].inspect\n while codes[1] > 0 do\n ans << letters[(codes[1]%26-1)]\n puts codes[1].inspect\n codes[1] /= 26\n codes[1] -= 1\n end\n\n\n puts \"#{ans.reverse}#{codes[0]}\"\n else\n code = input.match(/([A-Z])+/).to_s\n sum = 0\n code.chars.each_with_index do |el,i|\n sum += (1+letters.index(el)) * (26**(code.size-i-1))\n end\n puts \"R#{input.match(/([0-9])+/)}C#{sum}\"\n end\nend"}, {"source_code": "num = gets.chomp.to_i\nputs num\nnum.times do\n old = gets.chomp\n results = old.match('R(\\d+)C(\\d+)')\n if results != nil\n col_num = results[2].to_i\n base = 1;\n col_str = \"\"\n while col_num > 26\n this_char = col_num % 26\n col_num /= 26\n col_str = \"#{(this_char+64).chr}#{col_str}\"\n end\n col_str = \"#{(col_num+64).chr}#{col_str}\"\n puts \"#{col_str}#{results[1]}\"\n else\n results = old.match('([A-Z]+)(\\d+)')\n col_str = results[1]\n base = 26**(col_str.length-1)\n col_num = 0\n col_str.each_char do |c| \n col_num += (c.ord-64)*base\n base /= 26\n end\n puts \"R#{results[2]}C#{col_num}\"\n end\nend"}, {"source_code": "def f(x)\nreturn x<27?((x+65).chr):(f(x/26-1)+(x%26+65).chr)\nend\na=*$<.drop(1).map(&:chomp).each{|x|puts /R(\\d+)C(\\d+)/.match(x)?(f($2.to_i-1)+$1):(y=0;v=1;/(\\D+)(\\d+)/.match(x);$1.reverse.each_char{|c|y+=(c.ord-64)*v;v*=26};\"R\"+$2+\"C\"+y.to_s)}"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\ndef to_number str\n\tnum = 0\n\tdigits = [*?A..?Z]\n\t\n\tpow=1\n\tstr.reverse.each_char{|c|\t\t\n\t\td = digits.index(c) + 1\n\t\t\n\t\tnum+=d*pow\n\t\tpow*=26\n\t}\n\t\n\tnum\nend\n\ndef to_first line\n\tletters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]\n\t\"R#{number}C#{to_number letters}\"\nend\n\ndef to_27 num\n\tans = \"\"\n\tdigits = [*?A..?Z]\n\t\n\tnum = num.to_i\n\twhile num!=0\n\t\tans = digits[num%26-1] + ans\n\t\tnum/=26\n\tend\n\t\n\tans\nend\n\ndef to_second line\n\ta, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]\t\n\t\"#{to_27 b}#{a}\"\nend\n\nn=gets.to_i\n\nn.times{\n\tline=gets.strip\n\t\n\tif /R([0-9]+)C([0-9]+)/.match line\n\t\tputs to_second line\n\telse\n\t\tputs to_first line\n\tend\n}\n"}, {"source_code": "def solve(input)\n if (/R\\d+C\\d+/ =~ input) == nil\n fromBase26(input)\n else\n toBase26(input)\n end\nend\n\ndef fromBase26(input)\n charByte = \"A\".bytes[0]\n numByte = \"1\".bytes[0]\n letters = Array.new\n numbers = Array.new\n\n input.chomp.each_byte do |byte|\n if byte < charByte\n numbers.unshift(byte-(numByte-1))\n else\n letters.unshift(byte-(charByte-1))\n end\n end\n\n rows = arrayToInt(numbers, 10)\n cols = arrayToInt(letters, 26)\n \"R#{rows}C#{cols}\"\nend\n\ndef toBase26(input)\n input[0] = \"\"\n rows, cols = input.split(\"C\")\n val = cols.to_i\n digits = []\n while val != 0\n digits.unshift(val%26)\n val /= 26\n end\n cols = \"\"\n for digit in digits\n val = digit + (\"A\".bytes[0]-1)\n cols += val.chr\n end\n cols + \"#{rows}\"\nend\n\ndef arrayToInt(arr, base)\n curr = 1\n int = 0\n for val in arr\n int += val*curr\n curr *= base\n end\n int\nend\n\nn = gets.to_i\nans = Array.new(n, nil)\nfor i in (0...n)\n ans[i] = solve(gets)\nend\n\nfor answer in ans\n puts answer\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef convert(str)\n if str =~ /^R(\\d+)C(\\d+)$/\n rows, cols = $1.to_i, $2.to_i\n cols -= 1\n a = []\n loop do\n a.unshift cols % 26\n cols /= 26\n break if cols == 0\n end\n \"#{a.map{|i| (i + 65).chr}.join}#{rows}\"\n elsif str =~ /^([A-Z]+)(\\d+)$/\n cols = 0\n $1.size.times do |i|\n cols += ($1.unpack('C*')[-i - 1] - 64) * (26 ** i)\n end\n \"R#{$2}C#{cols}\"\n else\n \"invalid arg\"\n end\nend\n\nn = gets.to_i\nlines = []\nn.times do\n lines << convert(gets.chomp)\nend\n\nlines.each{|s| puts s}\n"}, {"source_code": "def excel_to_index(number)\n row = number.gsub(/[a-zA-Z]/, '').chomp\n column = number.gsub(/\\d/, '').chomp\n\n length = column.length\n column_index = 0\n column.each_char do |c|\n column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))\n length -= 1\n end\n\n 'R' + row + 'C' + column_index.to_s\nend\n\ndef index_to_excel(number)\n row, column = number.sub(/R/, '').split(/C/).map(&:to_i)\n\n column_index = column.to_s(26).upcase\n column_letters = ''\n column_index.each_char do |c|\n if c.ord > '9'.ord\n column_letters += (c.ord + 9).chr\n else\n column_letters += (c.ord + 'A'.ord - '1'.ord).chr\n end \n end\n\n column_letters + row.to_s\nend \n\ncount = gets.to_i\n\ncount.times do\n num = gets.upcase\n if num[/R\\d+C\\d+/]\n puts index_to_excel num\n else\n puts excel_to_index num\n end \nend"}, {"source_code": "class Integer\n private\n LETTERS = [\"Z\"].concat((\"A\"..\"Y\").to_a)\n \n public\n def to_ab\n number = self\n ab = \"\"\n while(number != 0) do\n ab << LETTERS[number % 26]\n number /= 26\n end\n return ab.reverse\n end\nend\n\nclass String\n private\n LETTERS = (\"A\"..\"Z\").to_a\n \n public\n def to_rc\n rstring = self.clone.reverse!\n rc = 0\n rstring.length.times {\n |i|\n rc += ((LETTERS.index(rstring[i,1]) + 1) * (26 ** i))\n }\n return rc.to_s\n end\nend\n\ndef rc_ab(rc)\n row, column = rc.scan(/\\d+/)\n column = column.to_i.to_ab\n ab = column << row\n return ab\nend\n\ndef ab_rc(ab)\n column, row = ab.scan(/([A-Z]+)(\\d+)/)[0]\n column = column.to_rc\n rc = \"R\" << row << \"C\" << column\n return rc\nend\n\nn = gets().chomp.to_i\na = []\nn.times {\n|i|\n a[i] = gets().chomp()\n}\na.each{\n|i|\n if (/^R\\d+C\\d+$/ =~ i) then\n #RXCY \n puts(rc_ab(i))\n else\n #AB23\n puts(ab_rc(i))\n end\n}"}, {"source_code": "\t#recibiendo el numero de iteraciones\n\tinput=gets.chomp\n\tn=input.to_i\n\t#metodo para saber si la cadena es excel o random\n\tdef validar_excel(a)\n\t\tif a.include?(\"R\") && a.include?(\"C\") #como el metodo random tiene R&C \n\t\t\tif a.index(\"R\")==0\n\t\t\t\tir=a.index(\"R\") #queremos el index de cada letra\n\t\t\t\tic=a.index(\"C\") #porque para q sea random, la diferencia debe ser 1\n\t\t\t\treturn (ic-ir)==1? true : false \n\t\t\telse\n\t\t\t\treturn true\n\t\t\tend\n\t\telse\n\t\t\treturn true\n\t\tend\n\tend\n\t#revisar\n\tdef convertir(ar)\n\t\tn=ar.size-1\t\n\t\ti=0\n\t\tnum=0\n\t\t\n\t\tloop do\n\t\t\tif n<0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\t\n\t\t\tnum=num+(ar[i].ord-64)*(26**n)\n\t\t\tn-=1\n\t\t\ti+=1\n\t\tend\n\t\t\n\t\treturn num\n\tend\n\t\n\t#primer metodo de BC23 a R23C55\n\tdef excel_to_random(arr)\n\t\tparte_num=\"\"\n\t\tparte_str=\"\"\n\t\t\n\t\t0.upto(arr.size-1) do |k|\n\t\t\tif (arr[k].ord>=48 && arr[k].ord<=57) #ASCII para diferenciar num & str\n\t\t\t\tparte_num=parte_num+arr[k]\n\t\t\telse\n\t\t\t\tparte_str=parte_str+arr[k]\n\t\t\tend\n\t\tend\n\t\n\t\tparte_c=convertir(parte_str)\n\t\trandom=\"R\"+parte_num+\"C\"+\"#{parte_c}\" #creando el random\n\t\t\n\t\treturn random\n\tend\n\t\n\t#metodo divisiones sucesivas?\n\tdef divsuc(num)\n\t\tnum_car=26\n\t\tpivot=num\n\t\tndig=0\n\t\tarreglo_num=[]\n\t\tpotencia=1\n\t\t\n\t\tloop do\n\t\t\tpivot=pivot-26**potencia\n\t\t\tndig+=1\n\t\t\tpotencia+=1\n\t\t\tif pivot<=0\n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\t\t\n\t\t#real deal\n\t\tloop do\n\t\t\tif num==0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tif num%num_car !=0\n\t\t\t\tarreglo_num[ndig-1]=((num%num_car)+64).chr()\n\t\t\t\tnum=num/num_car\n\t\t\telse #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)\n\t\t\t\tq=num/num_car\n\t\t\t\tnum=q-1\n\t\t\t\tarreglo_num[ndig-1]=(num_car+64).chr()\n\t\t\tend\n\t\t\tndig-=1\n\t\tend\n\t\treturn arreglo_num\n\tend\n\t\n\t#segundo metodo de R23C55 a BC23\n\tdef random_to_excel(arr)\n\t\trow=\"\"\n\t\tcol=\"\"\n\t\ta=0\n\t\t\n\t\t1.upto(arr.size-1) do |k|\n\t\t\t(arr[k]==\"C\")? a+=1:a+=0\n\n\t\t\tif a==0\n\t\t\t\trow=row+arr[k]\n\t\t\telse\n\t\t\t\tif (arr[k]!=\"C\") \n\t\t\t\t\tcol=col+arr[k]\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tcol=col.to_i\n\t\tcole=divsuc(col)#convertir la columna a excel\n\t\texcel=cole.join+row\n\t\t\n\t\treturn excel\n\tend\n\t\n\t$res=[] #definici\u00f3n de la variable GLOBAL, para poder imprimirlo despu\u00e9s\n\t\n\t0.upto(n-1) do |j|\n\t\tcadena=gets.chomp.upcase\n\t\tarray=cadena.split(\"\")\n\t\ti=validar_excel(array)\n\t\t\n\t\tif i\n\t\t\tresultado=excel_to_random(array)\n\t\telse\n\t\t\tresultado=random_to_excel(array)\n\t\tend\n\t\t\t\n\t\t$res[j]=resultado \t#recordar que el puts imprime con /n y el print no lo hace\n\tend\n\t#IMPRIMIR RESULTADO\n\tputs $res"}, {"source_code": "$letters = [\"\"].concat((\"A\"..\"Z\").to_a)\n\ndef rc_ab(rc)\n rc_a = rc.scan(/\\d+/)\n rc_a[1] = rc_a[1].to_i\n s = \"\"\n \n while(rc_a[1] != 0) do\n s << $letters[rc_a[1] % 26]\n rc_a[1] /= 26\n end\n \n s = s.reverse << rc_a[0]\n return s\nend \n\ndef ab_rc(ab)\n ab_c = /[A-Z]+/.match(ab)\n \n ab_s = ab_c.to_s.reverse\n ab_n = 0\n \n ab_s.length.times {\n |i|\n ab_n += $letters.index(ab_s[i,1]) * 26 ** i\n }\n \n s = \"R\" << ab_n.to_s << \"C\" << /\\d+/.match(ab).to_s\n return s\nend\n\nn = gets().chomp.to_i\na = []\nn.times {\n|i|\n a[i] = gets().chomp()\n}\na.each{\n|i|\n if (/^R\\d+C\\d+$/ =~ i) then\n #RXCY\n puts(\"rc_ab\")\n puts(rc_ab(i))\n else\n #AB23\n puts(ab_rc(i))\n end\n}\n"}, {"source_code": "def excel_to_index(number)\n row = number.gsub(/[a-zA-Z]/, '').chomp\n column = number.gsub(/\\d/, '').chomp\n\n length = column.length\n column_index = 0\n column.each_char do |c|\n column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))\n length -= 1\n end\n\n 'R' + row + 'C' + column_index.to_s\nend\n\ndef index_to_excel(number)\n row, column = number.sub(/R/, '').split(/C/).map(&:to_i)\n\n column_index = column.to_s(26).upcase\n column_letters = ''\n column_index.each_char do |c|\n if c.ord > '9'.ord\n if '0' == c\n column_letters += 'Z'\n else\n column_letters += (c.ord + 9).chr\n end\n else\n column_letters += (c.ord + 'A'.ord - '1'.ord).chr\n end \n end\n\n column_letters + row.to_s\nend \n\ncount = gets.to_i\n\ncount.times do\n num = gets.upcase\n if num[/R\\d+C\\d+/]\n puts index_to_excel num\n else\n puts excel_to_index num\n end \nend"}, {"source_code": "def excel_to_index(number)\n row = number.gsub(/[a-zA-Z]/, '').chomp\n column = number.gsub(/\\d/, '').chomp\n\n length = column.length\n column_index = 0\n column.each_char do |c|\n column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))\n length -= 1\n end\n\n 'R' + row + 'C' + column_index.to_s\nend\n\ndef index_to_excel(number)\n row, column = number.sub(/R/, '').split(/C/).map(&:to_i)\n\n column_index = column.to_s(26)\n column_letters = ''\n column_index.each_char do |c|\n if c.ord > '9'.ord\n column_letters += (c.ord + 9).chr\n else\n column_letters += (c.ord + 'A'.ord - '1'.ord).chr\n end \n end\n\n column_letters + row.to_s\nend \n\ncount = gets.to_i\n\ncount.times do\n num = gets.upcase\n if num[/R\\d+C\\d+/]\n puts index_to_excel num\n else\n puts excel_to_index num\n end \nend"}, {"source_code": "puts $<.read.split.drop(1).map { |x|\n if x[/(.)(\\d+)(.)(\\d+)/]\n (\"A\"..\"Z\").to_a.join[$4.to_i.div 26] + (\"A\"..\"Z\").to_a.join[$4.to_i % 26] + $2\n else\n t = x[/\\D+/][-2]\n \"R#{x[/\\d+/]}C#{(t ? t.ord-\"A\".ord+1 : 0)*26+x[/\\D+/][-1].ord-\"A\".ord+1}\"\n end\n}"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\ndef to_letters num\n\tans=\"\"\n\tdigs=[*?A..?Z]\n\t\n\twhile num!=0\n\t\tans+=digs[num%26 - 1]\n\t\tnum/=26\n\tend\n\t\n\tans.reverse\nend\n\ndef to_numbers str\n\tans=0\n\tstr.reverse!\n\t\n\tpow=0\n\tstr.each_char{|c|\n\t\tans+= (c.ord - 'A'.ord + 1) * 26**pow\n\t\tpow+=1\n\t}\n\t\n\tans\nend\n\nn=gets.to_i\n\nn.times{\n\tline=gets.strip\n\t\n\tif /R(\\d+)C(\\d+)/.match line\n\t\tputs \"#{to_letters $2.to_i}#{$1}\"\n\telse\n\t\tp1, p2 = line.scan(/([A-Z]+)([0-9]+)/)[0]\n\t\tputs \"R#{p2}C#{to_numbers p1}\"\n\tend\n}\n"}, {"source_code": "def to_ex d\n str = \"\"\n while d > 1\n d, a = d.divmod(26)\n str = (a + 64).chr + str\n end\n str\nend\n\ndef ex_to str\n str.chars.each.with_index.inject(0){ |z, (v, i)| z = z * 26 + (v.ord - 64) }\nend\n\ndef solution str\n a, b = str.scan(/\\d+/).map(&:to_i)\n if b\n \"#{to_ex(b)}#{a}\"\n else\n a, b = str.scan(/([A-Z]+)(\\d+)/).first\n \"R#{b}C#{ex_to(a)}\"\n end \nend\n\nn = STDIN.gets.to_i\nArray.new(n){ solution(STDIN.gets.chomp) }.each{ |v| p v }"}, {"source_code": "num = gets.chomp.to_i\nnum.times do\n old = gets.chomp\n results = old.match('R(\\d+)C(\\d+)')\n if results != nil\n col_num = results[2].to_i\n base = 1;\n col_str = \"\"\n while col_num > 26\n this_char = col_num % 26\n col_num /= 26\n if this_char == 0\n this_char = 26\n end\n col_num -= 1\n col_str = \"#{(this_char+64).chr}#{col_str}\"\n end\n col_str = \"#{(col_num+64).chr}#{col_str}\"\n puts \"#{col_str}#{results[1]}\"\n else\n results = old.match('([A-Z]+)(\\d+)')\n col_str = results[1]\n base = 26**(col_str.length-1)\n col_num = 0\n col_str.each_char do |c| \n col_num += (c.ord-64)*base\n base /= 26\n end\n puts \"R#{results[2]}C#{col_num}\"\n end\nend"}, {"source_code": "def f(s)\n\tr=0\n\ts.each_byte{|c| r=r*10+c-64}\n\tr\nend\ndef g(n)\n\tr=\"\"\n\twhile n>0 do\n\t\tx=n%26\n\t\tif x==0 then\n\t\t\tx=26\n\t\t\tn-=x\n\t\tend\n\t\tr=(x+64).chr+r\n\t\tn/=26\n\tend\n\tr\nend\nn=gets.to_i\nn.times{\n\ts=gets\n\tif s=~/^([A-Z]+)(\\d+)$/ then\n\t\tputs \"R\"+$2.to_s+\"C\"+f($1).to_s\n\tend\n\tif s=~/R(\\d+)C(\\d+)/ then\n\t\tputs g($2.to_i)+$1\n\tend\n}\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\ndef to_number str\n\tnum = 0\n\tdigits = [*?A..?Z]\n\t\n\tpow = 0\n\tstr.reverse.each_char{|c|\t\t\n\t\td = digits.index(c)+1\n\t\t\n\t\tnum+=d * 26**pow\n\t\tpow+=1\n\t}\n\t\n\tnum\nend\n\ndef to_first line\n\tletters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]\n\t\"R#{number}C#{to_number letters}\"\nend\n\ndef to_27 num\n\tans = \"\"\n\tdigits = [*?A..?Z]\n\t\n\tnum = num.to_i\n\twhile num!=0\n\t\tans = digits[num%27-1] + ans\n\t\tnum/=27\n\tend\n\t\n\tans.reverse\nend\n\ndef to_second line\n\ta, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]\t\n\t\"#{to_27 b}#{a}\"\nend\n\nn=gets.to_i\n\nn.times{\n\tline=gets.strip\n\t\n\tif /R([0-9]+)C([0-9]+)/.match line\n\t\tputs to_second line\n\telse\n\t\tputs to_first line\n\tend\n}\n"}, {"source_code": "arr = STDIN.read.split(\"\\n\")\nn = arr[0].to_i\n\n1.upto(n).each do |i|\n str = arr[i]\n match = str.match(/R([0-9]+)C([0-9]+)/)\n\n if match\n row = match[2].to_i\n col = match[1]\n\n r = row\n str = \"\"\n while(r > 0) do\n val = (r-1) % 26\n str += (val + 65).chr\n r /= 26\n end\n str = str.reverse\n str += col\n puts str\n else\n match = str.match(/([A-Z]+)([0-9]+)/)\n col = match[1]\n row = match[2]\n\n s = 0\n rev = col.reverse.split(\"\")\n rev.each_index do |i|\n chr = (rev[i].ord - 65 + 1) * ( 26 ** i )\n puts \"chr:#{chr}\"\n s += chr\n end\n\n puts \"R#{row}C#{s}\"\n end\nend"}, {"source_code": "def n2s(n)\n s = \"\"\n while n > 0\n s = (\"A\".ord + n % 26 - 1).chr + s\n n /= 26\n end\n return s\nend\n\ndef s2n(s)\n n = 0\n s.size.times do |i|\n n *= 26\n n += s[i].ord - \"A\".ord + 1\n end\n return n\nend\n\nn = gets.to_i\nn.times do\n str = gets\n if str =~ /^([A-Z]+)(\\d+)$/\n c_s = $1\n r = $2.to_i\n c = s2n(c_s)\n puts \"R#{r}C#{c}\"\n elsif str =~ /^R(\\d+)C(\\d+)$/\n r = $1.to_i\n c = $2.to_i\n c_s = n2s(c)\n puts \"#{c_s}#{r}\"\n end\nend\n"}, {"source_code": "def to_ex d\n str = \"\"\n while d > 1\n d, a = d.divmod(26)\n str = (a + 64).chr + str\n end\n str\nend\n\ndef ex_to str\n str.chars.each.with_index.inject(0){ |z, (v, i)| z = z * 26 + (v.ord - 64) }\nend\n\ndef solution str\n a, b = str.scan(/\\d+/).map(&:to_i)\n if b\n p \"#{to_ex(b)}#{a}\"\n else\n a, b = str.scan(/([A-Z]+)(\\d+)/).first\n p \"R#{b}C#{ex_to(a)}\"\n end \nend\n\nn = STDIN.gets.to_i\np Array.new(n){ solution(STDIN.gets.chomp) }"}, {"source_code": "alph = ['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\nn = gets.chomp.to_i\n\nlines = []\nn.times {lines << gets.chomp}\nlines.each do |l|\n if (l =~ /R\\d+C\\d+/).nil?\n col = 0\n colstr = l.scan(/[A-Z]+/).first.split(\"\")\n colstr.each_with_index do |ch, index|\n col += (alph.index(ch) + 1) * (26 ** (colstr.length - index - 1))\n end\n row = l.scan(/[0-9]+/).first\n puts \"R#{row}C#{col}\"\n else\n row = l.scan(/R([0-9]+)/).flatten.first\n col = l.scan(/C([0-9]+)/).flatten.first.to_i\n cols = \"\"\n loop do\n remainder = (col % 26)\n cols = alph[remainder - 1] + cols\n col = col / 26\n break if col == 0\n end\n puts \"#{cols}#{row}\"\n end\nend\n"}, {"source_code": "alph = ['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\nn = gets.chomp.to_i\n\nlines = []\nn.times {lines << gets.chomp}\nlines.each do |l|\n if (l =~ /R\\d+C\\d+/).nil?\n col = 0\n colstr = l.scan(/[A-Z]+/).first.split(\"\")\n colstr.each_with_index do |ch, index|\n col += (alph.index(ch) + 1) * (26 ** (colstr.length - index - 1))\n end\n row = l.scan(/[0-9]+/).first\n puts \"R#{row}C#{col}\"\n else\n row = l.scan(/R([0-9]+)/).flatten.first\n col = l.scan(/C([0-9]+)/).flatten.first.to_i\n cols = \"\"\n remainder = 1\n loop do\n minus = remainder == 0 ? 2 : 1\n remainder = (col % 26)\n cols = alph[remainder - minus] + cols\n col = col / 26\n break if col == 0\n end\n puts \"#{cols}#{row}\"\n end\nend\n"}, {"source_code": "\t#recibiendo el numero de iteraciones\n\tinput=gets.chomp\n\tn=input.to_i\n\t#metodo para saber si la cadena es excel o random\n\tdef validar_excel(a)\n\t\tif a.include?(\"R\") && a.include?(\"C\") #como el metodo random tiene R&C \n\t\t\tir=a.index(\"R\") #queremos el index de cada letra\n\t\t\tic=a.index(\"C\") #porque para q sea random, la diferencia debe ser 1\n\t\t\treturn (ic-ir)==1? true : false \n\t\telse\n\t\t\treturn true\n\t\tend\n\tend\n\t#revisar\n\tdef convertir(ar)\n\t\tn=ar.size-1\t\n\t\ti=0\n\t\tnum=0\n\t\t\n\t\tloop do\n\t\t\tif n<0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\t\n\t\t\tnum=num+(ar[i].ord-64)*(26**n)\n\t\t\tn-=1\n\t\t\ti+=1\n\t\tend\n\t\t\n\t\treturn num\n\tend\n\t\n\t#primer metodo de BC23 a R23C55\n\tdef excel_to_random(arr)\n\t\tparte_num=\"\"\n\t\tparte_str=\"\"\n\t\t\n\t\t0.upto(arr.size-1) do |k|\n\t\t\tif (arr[k].ord<=57 && arr[k].ord>=48) #ASCII para diferenciar num & str\n\t\t\t\tparte_num=parte_num+arr[k]\n\t\t\telse\n\t\t\t\tparte_str=parte_str+arr[k]\n\t\t\tend\n\t\tend\n\t\t\n\t\tparte_c=convertir(parte_str)\n\t\trandom=\"R\"+\"#{parte_num}\"+\"C\"+\"#{parte_c}\" #creando el random\n\t\t\n\t\treturn random\n\tend\n\t\n\t#metodo divisiones sucesivas?\n\tdef divsuc(num)\n\t\tnum_car=26\n\t\tpivot=num\n\t\tndig=0\n\t\tarreglo_num=[]\n\t\tpotencia=1\n\t\t\n\t\tloop do\n\t\t\tpivot=pivot-26**potencia\n\t\t\tndig+=1\n\t\t\tpotencia+=1\n\t\t\tif pivot<=0\n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\t\t\n\t\t#real deal\n\t\tloop do\n\t\t\tif num==0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tif num%num_car !=0\n\t\t\t\tarreglo_num[ndig-1]=((num%num_car)+64).chr()\n\t\t\t\tnum=num/num_car\n\t\t\telse #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)\n\t\t\t\tq=num/num_car\n\t\t\t\tnum=q-1\n\t\t\t\tarreglo_num[ndig-1]=(num_car+64).chr()\n\t\t\tend\n\t\t\tndig-=1\n\t\tend\n\t\treturn arreglo_num\n\tend\n\t\n\t#segundo metodo de R23C55 a BC23\n\tdef random_to_excel(arr)\n\t\trow=\"\"\n\t\tcol=\"\"\n\t\ta=0\n\t\t\n\t\t1.upto(arr.size-1) do |k|\n\t\t\t(arr[k]==\"C\")? a+=1:a+=0\n\n\t\t\tif a==0\n\t\t\t\trow=row+arr[k]\n\t\t\telse\n\t\t\t\tif (arr[k]!=\"C\") \n\t\t\t\t\tcol=col+arr[k]\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tcol=col.to_i\n\t\tcole=divsuc(col)#convertir la columna a excel\n\t\texcel=cole.join+row\n\t\t\n\t\treturn excel\n\tend\n\t\n\t$res=[] #definici\u00f3n de la variable GLOBAL, para poder imprimirlo despu\u00e9s\n\t\n\t0.upto(n-1) do |j|\n\t\tcadena=gets.chomp.upcase\n\t\tarray=cadena.split(\"\")\n\t\ti=validar_excel(array)\n\t\t\n\t\tif i\n\t\t\tresultado=excel_to_random(array)\n\t\telse\n\t\t\tresultado=random_to_excel(array)\n\t\tend\n\t\t\t\n\t\t$res[j]=resultado \t#recordar que el puts imprime con /n y el print no lo hace\n\tend\n\t\n\t#IMPRIMIR RESULTADO\n\tputs $res"}, {"source_code": "puts $<.read.split.drop(1).map { |x|\n if x[/(.)(\\d+)(.)(\\d+)/]\n (\"A\"..\"Z\").to_a.join[$4.to_i.div 26] + (\"A\"..\"Z\").to_a.join[$4.to_i % 26] + $2\n else\n t = x[/\\D+/][-2]\n \"R#{x[/\\d+/]}C#{(t ? t.ord-\"A\".ord+1 : 0)*26+x[/\\D+/][-1].ord-\"A\".ord+1}\"\n end\n}"}, {"source_code": "n = gets.to_i\n1.upto(n) do\n str = gets\n state = 0\n 0.upto(str.size-1) do |i|\n if str[i].ord>=48 and str[i].ord<=57\n state+=1 if state%2==0\n else\n state+=1 if state%2==1\n end\n end\n if state==2\n col = nil\n row = nil\n 0.upto(str.size-1) do |i|\n if str[i].ord>=48 and str[i].ord<=57\n col = str[0..i-1]\n row = str[i..-1].strip\n break\n end\n end\n coln = 0\n 0.upto(col.size-1) do |i|\n coln *= 26\n coln += col[i].ord-64\n end\n puts \"R#{row}C#{coln}\"\n else\n row = nil\n col = nil\n ci = nil\n 0.upto(str.size-1) do |i|\n if str[i].ord == 67\n ci = i\n end\n end\n row = str[1..ci-1]\n col = str[ci+1..-1].to_i\n cols = \"\"\n while col>0\n cols = (col%26+64).chr + cols\n col /= 26\n end\n puts cols+row\n end\nend\n"}, {"source_code": "n = STDIN.gets\nn.to_i.times do |i|\n a = STDIN.gets\n if a =~ /\\d+[A-Z]+/\n p \"Big format\"\n r = a.split(/[A-Z]/)[1]\n c = a.split(/[A-Z]/)[2].to_i\n completeAddress = \"\"\n while (c > 26)\n completeAddress += ((c/26.0).ceil + 63).chr\n if ((c / 26) < 26)\n c %= 26\n else\n c /= 26\n end\n \n end\n completeAddress += (c + 64).chr + r\n p completeAddress\n else\n p \"Short format\"\n c = a[0,a=~/\\d/]\n r = a.gsub(/[A-Z]+/,\"\")\n realrow = 0\n c.bytes.each do |i|\n realrow *= 26\n realrow += (i - 64)\n end\n p \"R\" + r + \"C\" + realrow.to_s\n end\nend "}, {"source_code": "class SpreadSheets\n def main\n numberOfLines = gets.to_i\n coordinates = Array.new(numberOfLines)\n\n i = 0\n while i < numberOfLines\n coordinates[i] = gets\n i += 1\n end\n\n puts convert(coordinates)\n end\n\n def convert(coordinates)\n result = Array::new\n numericDef = /R(\\d+)C(\\d+)/\n alphanumericDef = /(\\w+)(\\d+)/\n\n coordinates.each do |coordinate|\n if (numericDef.match(coordinate))\n matches = numericDef.match(coordinate)\n row = matches[1]\n column = matches[2]\n convertedColumn = convertNumToAlpha(column.to_i)\n result.push(\"#{convertedColumn}#{row}\")\n elsif (alphanumericDef.match(coordinate))\n matches = alphanumericDef.match(coordinate)\n row = matches[2]\n column = matches[1]\n convertedColumn = convertAlphaToNum(column)\n result.push(\"R#{row}C#{convertedColumn}\")\n end\n end\n\n return result\n end\n\n def convertNumToAlpha(num)\n result = String::new\n\n num -= 1;\n zeroLetter = 'A';\n base26 = 26;\n loop do\n remainder = num % base26;\n result = \"#{(zeroLetter.ord + remainder).chr}#{result}\"\n num /= base26;\n break if (num == 0)\n end\n\n return result\n end\n\n def convertAlphaToNum(alpha)\n result = 1\n\n zeroLetter = 'A'\n currentExp = 1\n base26 = 26\n alpha.split(\"\").reverse_each do |letter|\n convertedDigit = letter.ord - zeroLetter.ord\n result += convertedDigit * currentExp\n currentExp *= base26\n end\n\n return result.to_s\n end\nend\n\nSpreadSheets::new.main\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\ndef to_number str\n\tnum = 0\n\tdigits = [*?A..?Z]\n\t\n\tpow=1\n\tstr.reverse.each_char{|c|\t\t\n\t\td = digits.index(c) + 1\n\t\t\n\t\tnum+=d*pow\n\t\tpow*=26\n\t}\n\t\n\tnum\nend\n\ndef to_first line\n\tletters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]\n\t\"R#{number}C#{to_number letters}\"\nend\n\ndef to_36 num\n\tans = \"\"\n\tdigits = [*?A..?Z]\n\t\n\tnum=num.to_i\n\twhile num!=0\n\t\tans+=digits[num%26-1]\n\t\tnum/=26\n\tend\n\t\n\tans.reverse\nend\n\ndef to_second line\n\ta, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]\t\n\t\"#{to_36 b}#{a}\"\nend\n\nn=gets.to_i\n\nn.times{\n\tline=gets.strip\n\t\n\tif /R([0-9]+)C([0-9]+)/.match line\n\t\tputs to_second line\n\telse\n\t\tputs to_first line\n\tend\n}\n"}, {"source_code": "r = /R\\d+C\\d+/\nrow_regex = /\\d+/\n\nn = gets.chomp.to_i\n\nn.times do\n line = gets.chomp\n puts line.match(r)\n if line.match(r)\n row = line[1.. (line =~ /C/)].to_i\n c = line[(line =~ /C/)+1..-1].to_i\n a = 0; b = 0\n a = c\n res = \"\"\n while (a+26) > 26\n a = c / 26\n \t\t\tb = c % 26 == 0 ? 26 : c % 26\n \t\t\ta = c % 26 == 0 ? a - 1 : a\n \t\t\tc = a\n res.prepend(((b-1) + 65).chr)\n end\n puts \"#{res}#{row}\"\n else\n num_index = line =~ row_regex\n row = line[num_index..line.length()]\n col = 0\n col_str = line[0..num_index-1]\n col_str.split('').map.with_index do |chr, i|\n col += (chr.ord - 'A'.ord + 1) * (26 ** (num_index-1-i))\n end\n puts \"R#{row}C#{col}\"\n end\nend\n"}, {"source_code": "\t#recibiendo el numero de iteraciones\n\tinput=gets.chomp\n\tn=input.to_i\n\t#metodo para saber si la cadena es excel o random\n\tdef validar_excel(a)\n\t\tif a.include?(\"R\") && a.include?(\"C\") #como el metodo random tiene R&C \n\t\t\tir=a.index(\"R\") #queremos el index de cada letra\n\t\t\tic=a.index(\"C\") #porque para q sea random, la diferencia debe ser 1\n\t\t\treturn (ic-ir)==1? true : false \n\t\telse\n\t\t\treturn true\n\t\tend\n\tend\n\t#revisar\n\tdef convertir(ar)\n\t\tn=ar.size-1\t\n\t\ti=0\n\t\tnum=0\n\t\t\n\t\tloop do\n\t\t\tif n<0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\t\n\t\t\tnum=num+(ar[i].ord-64)*(26**n)\n\t\t\tn-=1\n\t\t\ti+=1\n\t\tend\n\t\t\n\t\treturn num\n\tend\n\t\n\t#primer metodo de BC23 a R23C55\n\tdef excel_to_random(arr)\n\t\tparte_num=\"\"\n\t\tparte_str=\"\"\n\t\t\n\t\t0.upto(arr.size-1) do |k|\n\t\t\tif (arr[k].ord<=57 && arr[k].ord>=48) #ASCII para diferenciar num & str\n\t\t\t\tparte_num=parte_num+arr[k]\n\t\t\telse\n\t\t\t\tparte_str=parte_str+arr[k]\n\t\t\tend\n\t\tend\n\t\t\n\t\tparte_c=convertir(parte_str)\n\t\trandom=\"R\"+parte_num+\"C\"+\"#{parte_c}\" #creando el random\n\t\t\n\t\treturn random\n\tend\n\t\n\t#metodo divisiones sucesivas?\n\tdef divsuc(num)\n\t\tnum_car=26\n\t\tpivot=num\n\t\tndig=0\n\t\tarreglo_num=[]\n\t\tpotencia=1\n\t\t\n\t\tloop do\n\t\t\tpivot=pivot-26**potencia\n\t\t\tndig+=1\n\t\t\tpotencia+=1\n\t\t\tif pivot<=0\n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\t\t\n\t\t#real deal\n\t\tloop do\n\t\t\tif num==0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tif num%num_car !=0\n\t\t\t\tarreglo_num[ndig-1]=((num%num_car)+64).chr()\n\t\t\t\tnum=num/num_car\n\t\t\telse #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)\n\t\t\t\tq=num/num_car\n\t\t\t\tnum=q-1\n\t\t\t\tarreglo_num[ndig-1]=(num_car+64).chr()\n\t\t\tend\n\t\t\tndig-=1\n\t\tend\n\t\treturn arreglo_num\n\tend\n\t\n\t#segundo metodo de R23C55 a BC23\n\tdef random_to_excel(arr)\n\t\trow=\"\"\n\t\tcol=\"\"\n\t\ta=0\n\t\t\n\t\t1.upto(arr.size-1) do |k|\n\t\t\t(arr[k]==\"C\")? a+=1:a+=0\n\n\t\t\tif a==0\n\t\t\t\trow=row+arr[k]\n\t\t\telse\n\t\t\t\tif (arr[k]!=\"C\") \n\t\t\t\t\tcol=col+arr[k]\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tcol=col.to_i\n\t\tcole=divsuc(col)#convertir la columna a excel\n\t\texcel=cole.join+row\n\t\t\n\t\treturn excel\n\tend\n\t\n\t$res=[] #definici\u00f3n de la variable GLOBAL, para poder imprimirlo despu\u00e9s\n\t\n\t0.upto(n-1) do |j|\n\t\tcadena=gets.chomp.upcase\n\t\tarray=cadena.split(\"\")\n\t\ti=validar_excel(array)\n\t\t\n\t\tif i\n\t\t\tresultado=excel_to_random(array)\n\t\telse\n\t\t\tresultado=random_to_excel(array)\n\t\tend\n\t\t\t\n\t\t$res[j]=resultado \t#recordar que el puts imprime con /n y el print no lo hace\n\tend\n\t\n\t#IMPRIMIR RESULTADO\n\tputs $res"}, {"source_code": "\t#recibiendo el numero de iteraciones\n\tinput=gets.chomp\n\tn=input.to_i\n\t#metodo para saber si la cadena es excel o random\n\tdef validar_excel(a)\n\t\tif a.include?(\"R\") && a.include?(\"C\") #como el metodo random tiene R&C \n\t\t\tir=a.index(\"R\") #queremos el index de cada letra\n\t\t\tic=a.index(\"C\") #porque para q sea random, la diferencia debe ser 1\n\t\t\treturn (ic-ir)==1? true : false \n\t\telse\n\t\t\treturn true\n\t\tend\n\tend\n\t#revisar\n\tdef convertir(ar)\n\t\t\n\t\tcase ar.size\n\t\twhen 3\n\t\t\tnum=(ar[0].ord-64)*26*26 +(ar[1].ord-64)*26+(ar[2].ord-64)\n\t\twhen 2\n\t\t\tnum=(ar[0].ord-64)*26 +(ar[1].ord-64)\n\t\twhen 1\n\t\t\tnum=ar[0].ord-64\n\t\telse\n\t\t\tnum=0\n\t\tend\n\t\t\n\t\treturn num\n\tend\n\t\n\t#primer metodo de BC23 a R23C55\n\tdef excel_to_random(arr)\n\t\tparte_num=\"\"\n\t\tparte_str=\"\"\n\t\t\n\t\t0.upto(arr.size-1) do |k|\n\t\t\tif (arr[k].ord<=57 && arr[k].ord>=48) #ASCII para diferenciar num & str\n\t\t\t\tparte_num=parte_num+arr[k]\n\t\t\telse\n\t\t\t\tparte_str=parte_str+arr[k]\n\t\t\tend\n\t\tend\n\t\t\n\t\tparte_c=convertir(parte_str)\n\t\trandom=\"R\"+parte_num+\"C\"+\"#{parte_c}\" #creando el random\n\t\t\n\t\treturn random\n\tend\n\t\n\t#metodo divisiones sucesivas?\n\tdef divsuc(num)\n\t\tnum_car=26\n\t\tpivot=num\n\t\tndig=0\n\t\tarreglo_num=[]\n\t\tpotencia=1\n\t\t\n\t\tloop do\n\t\t\tpivot=pivot-26**potencia\n\t\t\tndig+=1\n\t\t\tpotencia+=1\n\t\t\tif pivot<=0\n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\t\t\n\t\t#real deal\n\t\tloop do\n\t\t\tif num==0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tif num%num_car !=0\n\t\t\t\tarreglo_num[ndig-1]=((num%num_car)+64).chr()\n\t\t\t\tnum=num/num_car\n\t\t\telse #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)\n\t\t\t\tq=num/num_car\n\t\t\t\tnum=q-1\n\t\t\t\tarreglo_num[ndig-1]=(num_car+64).chr()\n\t\t\tend\n\t\t\tndig-=1\n\t\tend\n\t\treturn arreglo_num\n\tend\n\t\n\t#segundo metodo de R23C55 a BC23\n\tdef random_to_excel(arr)\n\t\trow=\"\"\n\t\tcol=\"\"\n\t\ta=0\n\t\t\n\t\t1.upto(arr.size-1) do |k|\n\t\t\t(arr[k]==\"C\")? a+=1:a+=0\n\n\t\t\tif a==0\n\t\t\t\trow=row+arr[k]\n\t\t\telse\n\t\t\t\tif (arr[k]!=\"C\") \n\t\t\t\t\tcol=col+arr[k]\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tcol=col.to_i\n\t\tcole=divsuc(col)#convertir la columna a excel\n\t\texcel=cole.join+row\n\t\t\n\t\treturn excel\n\tend\n\t\n\t$res=[] #definici\u00f3n de la variable GLOBAL, para poder imprimirlo despu\u00e9s\n\t\n\t0.upto(n-1) do |j|\n\t\tcadena=gets.chomp.upcase\n\t\tarray=cadena.split(\"\")\n\t\ti=validar_excel(array)\n\t\t\n\t\tif i\n\t\t\tresultado=excel_to_random(array)\n\t\telse\n\t\t\tresultado=random_to_excel(array)\n\t\tend\n\t\t\t\n\t\t$res[j]=resultado \t#recordar que el puts imprime con /n y el print no lo hace\n\tend\n\t\n\t#IMPRIMIR RESULTADO\n\tputs $res"}, {"source_code": "n = gets.to_i\n1.upto(n) do\n str = gets\n state = 0\n 0.upto(str.size-1) do |i|\n if str[i].ord>=48 and str[i].ord<=57\n state+=1 if state%2==0\n else\n state+=1 if state%2==1\n end\n end\n if state==2\n col = nil\n row = nil\n 0.upto(str.size-1) do |i|\n if str[i].ord>=48 and str[i].ord<=57\n col = str[0..i-1]\n row = str[i..-1].strip\n break\n end\n end\n coln = 0\n 0.upto(col.size-1) do |i|\n coln *= 26\n coln += col[i].ord-64\n end\n puts \"R#{row}C#{coln}\"\n else\n row = nil\n col = nil\n ci = nil\n 0.upto(str.size-1) do |i|\n if str[i].ord == 67\n ci = i\n end\n end\n row = str[1..ci-1]\n col = str[ci+1..-1].to_i\n cols = \"\"\n while col>0\n cols = (col%26+64).chr + cols\n col /= 26\n end\n puts cols+row\n end\nend\n"}, {"source_code": "number_of_input=gets.to_i\ninput_arry=[]\ni_a=0\n\n\nloop do\n break if i_a==number_of_input\n input_arry[i_a]=gets.chomp\n i_a +=1\nend\n\nvalue=(1..26)\nalph=('A'..'Z')\nvalue=[*value]\nalph=[*alph]\n@hash={}\ni_b=0\n\nloop do\n break if i_b==26\n @hash[alph[i_b]]=value[i_b]\n i_b+=1\nend \n\nvalue=(1..26)\nalph=('A'..'Z')\nvalue=[*value]\nalph=[*alph]\n@hash2={}\ni_b=0\n\nloop do\n break if i_b==26\n @hash2[alph[i_b]]=value[i_b]\n i_b+=1\nend \n@hash2['Z']=0\n\n\n\n\ni_c =0\n\nloop do\n break if i_c==input_arry.length\n input1=input_arry[i_c]\n \n if input1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0) \n a1=input1\n r=a1[0]\n i=1\n \n loop do\n break if a1[i].to_i !=0\n r =r + a1[i]\n i+=1\n end\n\n r1=r.length\n r2=a1.length\n c1= a1[0 .. (r1-1)].reverse\n row= a1[ r1 .. r2].to_i\n c=0\n i=0\n \n loop do\n break if i==c1.length\n c= c + (@hash[c1[i]]*(26**i))\n i+=1\n end\n \n puts \"R#{row}C#{c}\"\n \n elsif input1[0]=='R' && input1[1].to_i!=0\n k2=input1.split(\"\")\n \n if k2.index(\"C\")>1\n a1=input1\n r=a1[0]\n i=1\n \n loop do\n break if a1[i].to_i !=0\n r =r + a1[i]\n i+=1\n end\n\n r1=r.length\n r2=a1.length\n c1= a1[0 .. (r1-1)].reverse\n row= a1[ r1 .. r2].to_i\n c=0\n i=0\n \n loop do\n break if i==c1.length\n c= c + (@hash[c1[i]]*(26**i))\n i+=1\n end\n \n puts \"R#{row}C#{c}\"\n else\n a1=input1\n s2=a1.split(\"\").map{|s| s}\n r3=3\n s2.find {|i| r3=s2.index(i)+1 if i=='C'}\n i=s2[r3 .. (s2.length - 1)].join.to_i\n row=s2[1 .. (r3-2)].join.to_i\n str_c=\"\"\n loop do\n str_c = str_c + @hash2.key(i%26)\n i=i/26\n break if i==0\n end\n \n str_c=str_c.reverse\n puts \"#{str_c}#{row}\"\n end \n \n end \ni_c +=1\nend\n "}, {"source_code": "a=[*?A..'BEAAA'];gets.to_i.times{x=gets;puts /R(\\d+)C(\\d+)/.match(x)?(a[$2.to_i-1]+$1):(y=v=0;/(\\D+)(\\d+)/.match x;$1.reverse.each_char{|c|y+=(c.ord-64)*v**26;v+=1};\"R#{$2}C#{y}\")}"}, {"source_code": "arr = STDIN.read.split(\"\\n\")\nn = arr[0].to_i\n\n1.upto(n).each do |i|\n str = arr[i]\n match = str.match(/R([0-9]+)C([0-9]+)/)\n\n if match\n row = match[2].to_i\n col = match[1]\n\n r = row\n str = \"\"\n while(r > 0) do\n val = (r-1) % 26\n str += (val + 65).chr\n r /= 26\n end\n str = str.reverse\n str += col\n puts str\n else\n match = str.match(/([A-Z]+)([0-9]+)/)\n col = match[1]\n row = match[2]\n\n puts \"A\"\n s = 0\n rev = col.reverse.split(\"\")\n puts \"B\"\n rev.each_index do |i|\n puts \"rev[i]\" + rev[i]\n puts rev[i].ord - 65 + 1\n chr = (rev[i].ord - 65 + 1) * ( 26 ** i )\n puts \"chr:#{chr}\"\n s += chr\n end\n\n puts \"R#{row}C#{s}\"\n end\nend"}, {"source_code": "\ndef a_to_n(line)\n length = line.length\n i = 0\n sum = 0\n while i < length\n sum = sum * 26 + (line[i].ord - 'A'.ord + 1) \n i = i + 1\n end\n return sum\nend\n\ndef n_to_a(line)\n\n row_str = \"\"\n row_num = line.to_i\n while row_num > 0\n row_str.prepend( (64 + row_num % 26).chr) \n row_num = row_num/26\n end\n return row_str\n\nend\n\ndef xy_to_rc(line)\n col_size = line =~ /[0-9]/\n\n col_str = line[0...col_size]\n row_str = line[col_size...-1]\n\n col = a_to_n(col_str)\n row = row_str.to_i\n\n print(\"R\")\n print(row)\n print(\"C\")\n print(col)\n\nend\n\ndef rc_to_xy(line)\n col_size = line =~ /[C]/\n\n row_str = line[1...col_size]\n col_str = line[col_size+1...-1]\n\n col = n_to_a(col_str)\n row = row_str.to_i\n\n print(col)\n print(row)\nend\n\ndef isrc(line)\n if line[0] == 'R' && line[1] =~ /[0-9]/\n if line[2...-1].include? \"C\"\n return true\n end\n end\n return false\nend\n\n\nline_count = gets.to_i\n\nwhile line_count > 0 \n line_string = gets\n if isrc(line_string)\n rc_to_xy(line_string)\n else\n xy_to_rc(line_string)\n end\n print(\"\\n\")\n line_count = line_count-1\nend\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\ndef to_number str\n\tnum = 0\n\tdigits = [*?A..?Z]\n\t\n\tpow=1\n\tstr.reverse.each_char{|c|\t\t\n\t\td = digits.index(c) + 1\n\t\t\n\t\tnum+=d*pow\n\t\tpow*=26\n\t}\n\t\n\tnum\nend\n\ndef to_first line\n\tletters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]\n\t\"R#{number}C#{to_number letters}\"\nend\n\ndef to_36 num\n\tans = \"\"\n\tdigits = [*?A..?Z]\n\t\n\tnum=num.to_i\n\twhile num!=0\n\t\tans+=digits[num%26-1]\n\t\tnum/=26\n\tend\n\t\n\tans.reverse\nend\n\ndef to_second line\n\ta, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]\t\n\t\"#{to_36 b}#{a}\"\nend\n\nn=gets.to_i\n\nn.times{\n\tline=gets.strip\n\t\n\tif /R([0-9]+)C([0-9]+)/.match line\n\t\tputs to_second line\n\telse\n\t\tputs to_first line\n\tend\n}\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\ndef to_letters num\n\tans=\"\"\n\tdigs=[*?A..?Z]\n\t\n\twhile num!=0\n\t\tans+=digs[num%26 - 1]\n\t\tnum/=26\n\tend\n\t\n\tans.reverse\nend\n\ndef to_numbers str\n\tans=0\n\tstr.reverse!\n\t\n\tpow=0\n\tstr.each_char{|c|\n\t\tans+= (c.ord - 'A'.ord + 1) * 26**pow\n\t\tpow+=1\n\t}\n\t\n\tans\nend\n\nn=gets.to_i\n\nn.times{\n\tline=gets.strip\n\t\n\tif /R(\\d+)C(\\d+)/.match line\n\t\tputs \"#{to_letters $2.to_i}#{$1}\"\n\telse\n\t\tp1, p2 = line.scan(/([A-Z]+)([0-9]+)/)[0]\n\t\tputs \"R#{p2}C#{to_numbers p1}\"\n\tend\n}\n"}, {"source_code": "num = gets.chomp.to_i\nnum.times do\n old = gets.chomp\n results = old.match('R(\\d+)C(\\d+)')\n if results != nil\n col_num = results[2].to_i\n base = 1;\n col_str = \"\"\n while col_num > 26\n this_char = col_num % 26\n col_num /= 26\n col_str = \"#{(this_char+64).chr}#{col_str}\"\n end\n col_str = \"#{(col_num+64).chr}#{col_str}\"\n puts \"#{col_str}#{results[1]}\"\n else\n results = old.match('([A-Z]+)(\\d+)')\n col_str = results[1]\n base = 26**(col_str.length-1)\n col_num = 0\n col_str.each_char do |c| \n col_num += (c.ord-64)*base\n base /= 26\n end\n puts \"R#{results[2]}C#{col_num}\"\n end\nend"}, {"source_code": "$letters = [\"\"].concat((\"A\"..\"Z\").to_a)\n\ndef rc_ab(rc)\n rc_a = rc.scan(/\\d+/)\n rc_a[1] = rc_a[1].to_i\n s = \"\"\n \n while(rc_a[1] != 0) do\n s << $letters[rc_a[1] % 26]\n rc_a[1] /= 26\n end\n \n s = s.reverse << rc_a[0]\n return s\nend \n\ndef ab_rc(ab)\n ab_c = /[A-Z]+/.match(ab)\n \n ab_s = ab_c.to_s.reverse\n ab_n = 0\n \n ab_s.length.times {\n |i|\n ab_n += $letters.index(ab_s[i,1]) * 26 ** i\n }\n \n s = \"R\" << ab_n.to_s << \"C\" << /\\d+/.match(ab).to_s\n return s\nend\n\nn = gets().chomp.to_i\na = []\nn.times {\n|i|\n a[i] = gets().chomp()\n}\na.each{\n|i|\n if (/^R\\d+C\\d+$/ =~ i) then\n #RXCY \n puts(rc_ab(i))\n else\n #AB23\n puts(ab_rc(i))\n end\n}\n"}, {"source_code": "n = gets.to_i\n1.upto(n) do\n str = gets\n state = 0\n 0.upto(str.size-1) do |i|\n if str[i].ord>=48 and str[i].ord<=57\n state+=1 if state%2==0\n else\n state+=1 if state%2==1\n end\n end\n if state==2\n col = nil\n row = nil\n 0.upto(str.size-1) do |i|\n if str[i].ord>=48 and str[i].ord<=57\n col = str[0..i-1]\n row = str[i..-1].strip\n break\n end\n end\n coln = 0\n 0.upto(col.size-1) do |i|\n coln *= 26\n coln += col[i].ord-64\n end\n puts \"R#{row}C#{coln}\"\n else\n row = nil\n col = nil\n ci = nil\n 0.upto(str.size-1) do |i|\n if str[i].ord == 67\n ci = i\n end\n end\n row = str[1..ci-1]\n col = str[ci+1..-1].to_i\n cols = \"\"\n while col>0\n cols = (col%26+64).chr + cols\n col /= 26\n end\n puts cols+row\n end\nend\n"}, {"source_code": "def excel_to_index(number)\n row = number.gsub(/[a-zA-Z]/, '').chomp\n column = number.gsub(/\\d/, '').chomp\n\n length = column.length\n column_index = 0\n column.each_char do |c|\n column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))\n length -= 1\n end\n\n 'R' + row + 'C' + column_index.to_s\nend\n\ndef index_to_excel(number)\n row, column = number.sub(/R/, '').split(/C/).map(&:to_i)\n\n column_index = column.to_s(26).upcase\n column_letters = ''\n column_index.each_char do |c|\n if c.ord > '9'.ord\n column_letters += (c.ord + 9).chr\n else\n if '0' == c\n let = column_letters[column_letters.length - 1]\n column_letters[column_letters.length - 1] = (let.ord - 1).chr\n column_letters += 'Z'\n else\n column_letters += (c.ord + 'A'.ord - '1'.ord).chr\n end\n end \n end\n\n column_letters + row.to_s\nend \n\ncount = gets.to_i\n\ncount.times do\n num = gets.upcase\n if num[/R\\d+C\\d+/]\n puts index_to_excel num\n else\n puts excel_to_index num\n end \nend"}, {"source_code": "n = gets\nn = Integer(n)\nwhile n>0\n string = gets\n m = string.size()\n index = 0\n while ('A'..'Z').include? string[index]\n index += 1\n end\n while !(('A'..'Z').include? string[index])\n index += 1\n if index >= m\n break;\n end\n end\n if index == m\n index = 0\n while ('A'..'Z').include? string[index]\n index+=1\n end\n index -= 1\n c = 0\n count = 1\n til = index\n until index < 0\n c += (string[index].unpack(\"c\")[0] - 'A'.unpack(\"c\")[0] + 1) * count\n index -= 1\n count *= 26\n end\n puts \"R#{string[til+1..m].chomp}C#{c}\"\n else\n index = string.index(\"C\")\n count = Integer(string[index+1..m-2].chomp)\n k = \"\"\n while count > 0\n k = (count % 26 + 64).chr + k\n count /= 26\n end\n puts \"#{k}#{string[1..index-1]}\"\n end\n n-=1\nend"}, {"source_code": "def excel_to_index(number)\n row = number.gsub(/[a-zA-Z]/, '').chomp\n column = number.gsub(/\\d/, '').chomp\n\n length = column.length\n column_index = 0\n column.each_char do |c|\n column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))\n length -= 1\n end\n\n 'R' + row + 'C' + column_index.to_s\nend\n\ndef index_to_excel(number)\n row, column = number.sub(/R/, '').split(/C/).map(&:to_i)\n\n column_letters = ''\n while (column / 26) > 0\n column_letters += (\"A\".ord - 1 + column / 26).chr\n column -= 26 * (column / 26)\n end\n column_letters += (\"A\".ord - 1 + column).chr\n\n column_letters + row.to_s\nend \n\ncount = gets.to_i\n\ncount.times do\n num = gets.upcase\n if num[/R\\d+C\\d+/]\n puts index_to_excel num\n else\n puts excel_to_index num\n end \nend"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\ndef to_number str\n\tnum = 0\n\tdigits = [*?A..?Z]\n\t\n\tpow = 0\n\tstr.reverse.each_char{|c|\t\t\n\t\td = digits.index(c)+1\n\t\t\n\t\tnum+=d * 26**pow\n\t\tpow+=1\n\t}\n\t\n\tnum\nend\n\ndef to_first line\n\tletters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]\n\t\"R#{number}C#{to_number letters}\"\nend\n\ndef to_27 num\n\tans = \"\"\n\tdigits = [*?A..?Z]\n\t\n\tnum = num.to_i\n\twhile num!=0\n\t\tans = digits[num%27] + ans\n\t\tnum/=27\n\tend\n\t\n\tans.reverse\nend\n\ndef to_second line\n\ta, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]\t\n\t\"#{to_27 b}#{a}\"\nend\n\nn=gets.to_i\n\nn.times{\n\tline=gets.strip\n\t\n\tif /R([0-9]+)C([0-9]+)/.match line\n\t\tputs to_second line\n\telse\n\t\tputs to_first line\n\tend\n}\n"}, {"source_code": "# # # # # # # # # # # # # # # # # # # # # # # # # # # #\ndef to_1var(row, column)\n\n az = ('A'..'Z').to_a\n azLen = az.length()\n\n columnAZ = \"\"\n columnInt = column.to_i\n\n while columnInt > 0\n columnAZ.insert(0, az[(columnInt % azLen)-1])\n columnInt /= azLen;\n end\n\n return columnAZ + row\n\nend\n\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\ndef to_2var(row, column)\n\n azLen = ('A'..'Z').to_a.length\n\n columnInt = 0\n column.reverse.each_char.each_with_index { |chr, idx| \n columnInt += (chr.ord - 'A'.ord + 1) * azLen**idx\n }\n\n return \"R#{row}C#{columnInt}\"\n\nend\n\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\n# Main\n# # # # # # # # # # # # # # # # # # # # # # # # # # # #\n\ngets.to_i.times {\n\n coord = gets.strip\n\n if coord =~ /^R(\\d+)C(\\d+)$/\n puts to_1var($1, $2)\n elsif coord =~ /^([A-Z]+)(\\d+)/\n puts to_2var($2, $1)\n end\n\n}\n\n\n"}, {"source_code": "n=gets.chomp.to_i\ndata=[]\n\nalpha=['A', 'B', 'C', 'D', 'E',\n\t\t'F', 'G', 'H', 'I', 'J',\n\t\t'K', 'L', 'M', 'N', 'O',\n\t\t'P', 'Q', 'R', 'S', 'T',\n\t\t'U', 'V', 'W', 'X', 'Y', 'Z']\na=0\n\nwhile a0\n\t\t\t\tb=cells%osn\n\t\t\t\tcs.push(alpha[b-1])\n\t\t\t\tcells-=b\n\t\t\t\tcells/=osn\n\t\t\tend\n\t\t\t\n\t\t\tcs.reverse!\n\t\t\tcs.push(rows)\n\n\t\t\tputs cs.join\n\t\telse\n\t\t\tsn=[]\n\t\t\ta=0\n\t\t\twhile word[a].to_i==0\n\t\t\t\tsn.push(word[a])\n\t\t\t\ta+=1\n\t\t\tend\n\n\t\t\tnumber=[]\n\t\t\tfor i in(a..word.length-1)\n\t\t\t\tnumber.push(word[i])\n\t\t\tend\n\t\t\tnumb=number.join.to_i\n\n\t\t\tsn.reverse!\n\t\t\trw=0\n\t\t\tfor i in(0..sn.length-1)\n\t\t\t\trw+=(alpha.index(sn[i])+1)*osn**i\n\t\t\tend\n\n\t\t\tanswer=[]\n\t\t\tanswer.push('R')\n\t\t\tanswer.push(numb)\n\t\t\tanswer.push('C')\n\t\t\tanswer.push(rw)\n\t\t\tputs answer.join\n\t\tend\n\telse\n\t\tsn=[]\n\t\ta=0\n\t\twhile word[a].to_i==0\n\t\t\tsn.push(word[a])\n\t\t\ta+=1\n\t\tend\n\n\t\tnumber=[]\n\t\tfor i in(a..word.length-1)\n\t\t\tnumber.push(word[i])\n\t\tend\n\t\tnumb=number.join.to_i\n\n\t\tsn.reverse!\n\t\trw=0\n\t\tfor i in(0..sn.length-1)\n\t\t\trw+=(alpha.index(sn[i])+1)*osn**i\n\t\tend\n\n\t\tanswer=[]\n\t\tanswer.push('R')\n\t\tanswer.push(numb)\n\t\tanswer.push('C')\n\t\tanswer.push(rw)\n\t\tputs answer.join\n\tend\nend"}, {"source_code": "n = gets\nn = Integer(n)\nwhile n>0\n string = gets\n m = string.size()\n index = 0\n while ('A'..'Z').include? string[index]\n index += 1\n end\n while !(('A'..'Z').include? string[index])\n index += 1\n if index >= m\n break;\n end\n end\n if index == m\n index = 0\n while ('A'..'Z').include? string[index]\n index+=1\n end\n index -= 1\n c = 0\n count = 1\n til = index\n until index < 0\n c += (string[index].unpack(\"c\")[0] - 'A'.unpack(\"c\")[0] + 1) * count\n index -= 1\n count *= 26\n end\n puts \"R#{string[til+1..m].chomp}C#{c}\"\n else\n index = string.index(\"C\")\n count = Integer(string[index+1..m-2].chomp)\n k = \"\"\n while count > 0\n if count % 26 == 0\n k = \"Z\" + k\n count /= 26\n count -= 1\n end\n if count>0\n k = (count % 26 + 64).chr + k\n count /= 26 \n end\n end\n puts \"#{k}#{string[1..index-1]}\"\n end\n n-=1\nend"}, {"source_code": "puts $<.read.split.drop(1).map { |x|\n if x[/(.)(\\d+)(.)(\\d+)/]\n (\"A\"..\"Z\").to_a.join[$4.to_i.div 26] + (\"A\"..\"Z\").to_a.join[$4.to_i % 26] + $2\n else\n t = x[/\\D+/][-2]\n \"R#{x[/\\d+/]}C#{(t ? t.ord-\"A\".ord+1 : 0)*26+x[/\\D+/][-1].ord-\"A\".ord+1}\"\n end\n}"}, {"source_code": "num = gets.chomp.to_i\nputs num\nnum.times do\n old = gets.chomp\n results = old.match('R(\\d+)C(\\d+)')\n if results != nil\n col_num = results[2].to_i\n base = 1;\n col_str = \"\"\n while col_num > 26\n this_char = col_num / 26\n col_num %= 26\n col_str += (this_char+64).chr\n end\n col_str += (col_num+65).chr\n puts \"#{col_str}#{results[1]}\"\n else\n results = old.match('([A-Z]+)(\\d+)')\n col_str = results[1]\n base = 26**(col_str.length-1)\n col_num = 0\n col_str.each_char do |c| \n col_num += (c.ord-64)*base\n base /= 26\n end\n puts \"R#{results[2]}C#{col_num}\"\n end\nend"}, {"source_code": "puts $<.read.split.drop(1).map { |x|\n if x[/R(\\d+)C(\\d+)/]\n \"#{(\"A\"..\"Z\").to_a.join[$2.to_i.div(26)-27]}#{(\"A\"..\"Z\").to_a.join[$2.to_i%26 - 1]}\" + $1\n else\n t = x[/\\D+/][-2]\n \"R#{x[/\\d+/]}C#{(t ? t.ord-\"A\".ord+1 : 0)*26+x[/\\D+/][-1].ord-\"A\".ord+1}\"\n end\n}"}, {"source_code": "n = gets.to_i\nfor x in gets(\"\").split.take(n)\n if x[/R(\\d+)C(\\d+)/]\n a = $2.to_i - 1\n t = (\"A\"..\"Z\").to_a.join[a%26]\n a = a.div 26\n until a == 0\n b,c = (a-1).divmod(26)\n t = (\"A\"..\"Z\").to_a.join[c] + t\n a = b\n end\n puts t + $1\n else\n t = x[/\\D+/][-2]\n puts \"R#{x[/\\d+/]}C#{(t ? t.ord-\"A\".ord+1 : 0)*26+x[/\\D+/][-1].ord-\"A\".ord+1}\"\n end\nend\n"}, {"source_code": "arr = STDIN.read.split(\"\\n\")\nn = arr[0].to_i\n\n1.upto(n).each do |i|\n str = arr[i]\n match = str.match(/R([0-9]+)C([0-9]+)/)\n\n if match\n row = match[2].to_i\n col = match[1]\n\n r = row\n str = \"\"\n while(r > 0) do\n val = (r-1) % 26\n str += (val + 65).chr\n r /= 26\n end\n str = str.reverse\n str += col\n puts str\n else\n match = str.match(/([A-Z]+)([0-9]+)/)\n col = match[1]\n row = match[2]\n\n s = 0\n col.reverse.split(\"\").each_index do |i|\n chr = (col[i].ord - 65) * (26**i) + 1\n s += chr\n end\n puts \"R#{row}C#{s}\"\n end\nend\n"}, {"source_code": "$letters = [\"\"].concat((\"A\"..\"Z\").to_a)\n\ndef rc_ab(rc)\n rc_a = rc.scan(/\\d+/)\n rc_a[1] = rc_a[1].to_i\n s = \"\"\n \n while(rc_a[1] != 0) do\n s << $letters[rc_a[1] % 26]\n rc_a[1] /= 26\n end\n \n s = s.reverse << rc_a[0]\n return s\nend \n\ndef ab_rc(ab)\n ab_c = /[A-Z]+/.match(ab)\n \n ab_s = ab_c.to_s.reverse\n ab_n = 0\n \n ab_s.length.times {\n |i|\n ab_n += $letters.index(ab_s[i,1]) * 26 ** i\n }\n \n s = \"R\" << /\\d+/.match(ab).to_s << \"C\" << ab_n.to_s \n return s\nend\n\nn = gets().chomp.to_i\na = []\nn.times {\n|i|\n a[i] = gets().chomp()\n}\na.each{\n|i|\n if (/^R\\d+C\\d+$/ =~ i) then\n #RXCY \n puts(rc_ab(i))\n else\n #AB23\n puts(ab_rc(i))\n end\n}\n"}, {"source_code": "n=gets.chomp.to_i\nn.times {\n\ts=gets.chomp.to_s\n\ts.scan(/^R([0-9]+)C([0-9]+)$/)\n\tunless !$~\n\t\tr=$~[1].to_i\n\t\tc=$~[2].to_i\n\t\tremainder=c%26\n\t\tg=(remainder+64).chr\n\t\twhile remainder !=c\n\t\t\tc-=remainder\n\t\t\tc/=26\n\t\t\tremainder=c%26\n\t\t\tg+=(remainder+64).chr\n\t\tend\n\t\tprint(g.reverse)\n\t\tputs (r)\n\t\tnext\n\tend\n\ts.scan(/^([A-Z]+)([0-9]+)$/)\n\tunless !$~\n\t\tc=$~[1]\n\t\tr=$~[2].to_i\n\t\tk=1\n\t\tsum=0\n\t\tc=c.reverse\n\t\tc=c.split(\"\")\n\t\tfor i in c\n\t\t\t#puts (i)\n\t\t\thold=(i.getbyte(0)-64)*k\n\t\t\t#puts (\"hold = #{hold}\")\n\t\t\tsum+=hold\n\t\t\tk*=26\n\t\tend\n\t\tputs (\"R#{r}C#{sum}\")\n\tend\n\n}"}, {"source_code": "class Integer\n private\n LETTERS = [\"Z\"].concat((\"A\"..\"Y\").to_a)\n \n public\n def to_ab\n number = self\n ab = \"\"\n while(number != 0) do\n ab << LETTERS[number % 26]\n number /= 26\n end\n return ab.reverse\n end\nend\n\nclass String\n private\n LETTERS = (\"A\"..\"Z\").to_a\n \n public\n def to_rc\n rstring = self.clone.reverse!\n rc = 0\n rstring.length.times {\n |i|\n rc += ((LETTERS.index(rstring[i,1]) + 1) * (26 ** i))\n }\n return rc.to_s\n end\nend\n\ndef rc_ab(rc)\n row, column = rc.scan(/\\d+/)\n column = column.to_i.to_ab\n ab = column << row\n return ab\nend\n\ndef ab_rc(ab)\n column, row = ab.scan(/([A-Z]+)(\\d+)/)[0]\n column = column.to_rc\n rc = \"R\" << row << \"C\" << column\n return rc\nend\n\nn = gets().chomp.to_i\na = []\nn.times {\n|i|\n a[i] = gets().chomp()\n}\na.each{\n|i|\n if (/^R\\d+C\\d+$/ =~ i) then\n #RXCY \n puts(rc_ab(i))\n else\n #AB23\n puts(ab_rc(i))\n end\n}"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\ndef to_number str\n\tnum = 0\n\tdigits = [*?A..?Z]\n\t\n\tpow=1\n\tstr.reverse.each_char{|c|\t\t\n\t\td = digits.index(c) + 1\n\t\t\n\t\tnum+=d*pow\n\t\tpow*=26\n\t}\n\t\n\tnum\nend\n\ndef to_first line\n\tletters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]\n\t\"R#{number}C#{to_number letters}\"\nend\n\ndef to_27 num\n\tans = \"\"\n\tdigits = [*?A..?Z]\n\t\n\tnum = num.to_i\n\twhile num!=0\n\t\tans+=digits[num%27]\n\t\tnum/=27\n\tend\n\t\n\tans\nend\n\ndef to_second line\n\ta, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]\t\n\t\"#{to_27 b}#{a}\"\nend\n\nn=gets.to_i\n\nn.times{\n\tline=gets.strip\n\t\n\tif /R([0-9]+)C([0-9]+)/.match line\n\t\tputs to_second line\n\telse\n\t\tputs to_first line\n\tend\n}\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef i2c\nend\n\ndef c2i\nend\n\ndef convert(str)\n if str =~ /^R(\\d+)C(\\d+)$/\n rows, cols = $1.to_i, $2.to_i\n a = []\n loop do\n a.unshift cols % 26\n cols /= 26\n break if cols == 0\n end\n \"#{a.map{|i| (i + 64).chr}.join}#{rows}\"\n elsif str =~ /^([A-Z]+)(\\d+)$/\n cols = 0\n $1.size.times do |i|\n cols += ($1.unpack('C*')[-i - 1] - 64) * (26 ** i)\n end\n \"R#{$2}C#{cols}\"\n else\n \"invalid arg\"\n end\nend\n\nn = gets.to_i\nlines = []\nn.times do\n lines << convert(gets.chomp)\nend\n\nlines.each{|s| puts s}\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef i2c\nend\n\ndef c2i\nend\n\ndef convert(str)\n if str =~ /^R(\\d+)C(\\d+)$/\n rows, cols = $1.to_i, $2.to_i\n a = []\n loop do\n a.unshift cols % 26\n cols /= 26\n break if cols == 0\n end\n \"#{a.map{|i| (i + 64).chr}.join}#{rows}\"\n elsif str =~ /^([A-Z]+)(\\d+)$/\n cols = 0\n $1.size.times do |i|\n cols += ($1.unpack('C*')[-i - 1] - 64) * (26 ** i)\n end\n \"R#{$2}C#{cols}\"\n else\n \"invalid arg\"\n end\nend\n\nn = gets.to_i\nlines = []\nn.times do\n lines << convert(gets.chomp)\nend\n\nlines.each{|s| puts s}\n"}, {"source_code": "r = /R\\d+C\\d+/\nrow_regex = /\\d+/\n\nn = gets.chomp.to_i\n\nn.times do\n line = gets.chomp\n puts line.match(r)\n if line.match(r)\n row = line[1.. (line =~ /C/)].to_i\n c = line[(line =~ /C/)+1..-1].to_i\n a = 0; b = 0\n a = c\n res = \"\"\n while (a+26) > 26\n a = c / 26\n \t\t\tb = c % 26 == 0 ? 26 : c % 26\n \t\t\ta = c % 26 == 0 ? a - 1 : a\n \t\t\tc = a\n res.prepend(((b-1) + 65).chr)\n end\n puts \"#{res}#{row}\"\n else\n num_index = line =~ row_regex\n row = line[num_index..line.length()]\n col = 0\n col_str = line[0..num_index-1]\n col_str.split('').map.with_index do |chr, i|\n col += (chr.ord - 'A'.ord + 1) * (26 ** (num_index-1-i))\n end\n puts \"R#{row}C#{col}\"\n end\nend\n"}, {"source_code": "$table = [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\"]\n\ndef to_E(x)\n b = \"\"\n t = true\n while x > 26 do\n if x % 26 == 0 then\n str = to_E(x-1)\n str[-1] = \"Z\"\n b = str + b\n x = 0\n t = false\n else\n b = $table[(x % 26) - 1] + b\n x /= 26\n end\n end\n if t then\n b = $table[x-1] + b\n end\n return b\nend\n\ndef to_T(x)\n str = x.gsub(/[0123456789]/, \"*\")\n k = str.index(\"*\")\n str1 = str[0...k]\n r = 0\n q = 26\n n = str1.size\n n.times do |i|\n r += ($table.index(str1[i]) + 1)*q**(n-i-1)\n# p (n-i-1)\n# p $table.index(str1[i]) + 1\n# p r\n end\n result = \"R\" + x[k..-1] + \"C\" + r.to_s\n return result \nend\n\nn = gets.to_i\nind = []\noutd = []\nn.times do |i|\n ind[i] = gets.chomp\n r = ind[i].index(\"R\")\n c = ind[i].index(\"C\")\n str = ind[i].gsub(/[ABDEFGHIJKLMNOPQSTUVWXYZ]/, \"*\")\n k = str.index(\"*\")\n if r && c && !k then\n ind[i] = to_E(ind[i][c+1..-1].to_i) + ind[i][r+1...c]\n else\n ind[i] = to_T(ind[i])\n end\nend\nn.times do |i|\n puts \"#{ind[i]}\"\nend"}, {"source_code": "def excel_to_index(number)\n row = number.gsub(/[a-zA-Z]/, '').chomp\n column = number.gsub(/\\d/, '').chomp\n\n length = column.length\n column_index = 0\n column.each_char do |c|\n column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))\n length -= 1\n end\n\n 'R' + row + 'C' + column_index.to_s\nend\n\ndef index_to_excel(number)\n row, column = number.sub(/R/, '').split(/C/).map(&:to_i)\n\n result = []\n begin\n x = column % 26\n x = 26 if 0 == x\n column = (column - x) / 26\n\n result.push x\n puts column\n end while column > 0\n\n column_letters = ''\n result.reverse_each { |e| \n column_letters += (e.ord + 'A'.ord - 1).chr\n }\n\n column_letters + row.to_s\nend \n\ncount = gets.to_i\n\ncount.times do\n num = gets.upcase\n if num[/R\\d+C\\d+/]\n puts index_to_excel num\n else\n puts excel_to_index num\n end \nend"}, {"source_code": "#!/usr/bin/ruby\ndef fromcell(s)\n r=0\n s.length.times{|i|\n #r=r*26+s[i]-64\n }\n return r\nend\n\ndef tocell(n)\n r=\"\"\n while n>0 do\n r=(n%26+64).chr+r\n n/=26\n end\n return r\nend\n\nn=gets.chomp.to_i\nn.times{|z|\n s=gets.chomp\n if s=~/^([A-Z]+)(\\d+)$/ then \nputs \"R\"\n#+$2.to_s+\"C\"+fromcell($1).to_s\nend\n if s=~/R(\\d+)C(\\d+)/ then puts tocell($2.to_i)+$1.to_s end\n}\nexit(0)\n"}, {"source_code": "\ndef a_to_n(line)\n length = line.length\n i = 0\n sum = 0\n while i < length\n sum = sum * 26 + (line[i].ord - 'A'.ord + 1) \n i = i + 1\n end\n return sum\nend\n\ndef n_to_a(line)\n\n row_str = \"\"\n row_num = line.to_i\n while row_num > 0\n row_str.prepend( (64 + row_num % 26).chr) \n row_num = row_num/26\n end\n return row_str\n\nend\n\ndef xy_to_rc(line)\n col_size = line =~ /[0-9]/\n\n col_str = line[0...col_size]\n row_str = line[col_size...-1]\n\n col = a_to_n(col_str)\n row = row_str.to_i\n\n print(\"R\")\n print(row)\n print(\"C\")\n print(col)\n\nend\n\ndef rc_to_xy(line)\n col_size = line =~ /[C]/\n\n row_str = line[1...col_size]\n col_str = line[col_size+1...-1]\n\n col = n_to_a(col_str)\n row = row_str.to_i\n\n print(col)\n print(row)\nend\n\ndef isrc(line)\n if line[0] == 'R' && line[1] =~ /[0-9]/\n if line[2...-1].include? \"C\"\n return true\n end\n end\n return false\nend\n\n\nline_count = gets.to_i\n\nwhile line_count > 0 \n line_string = gets\n if isrc(line_string)\n rc_to_xy(line_string)\n else\n xy_to_rc(line_string)\n end\n print(\"\\n\")\n line_count = line_count-1\nend\n"}, {"source_code": "\ndef a_to_n(line)\n length = line.length\n i = 0\n sum = 0\n while i < length\n sum = sum * 26 + (line[i].ord - 'A'.ord + 1) \n i = i + 1\n end\n return sum\nend\n\ndef n_to_a(line)\n\n row_str = \"\"\n row_num = line.to_i\n while row_num > 0\n row_str.prepend( (64 + row_num % 26).chr) \n row_num = row_num/26\n end\n return row_str\n\nend\n\ndef xy_to_rc(line)\n col_size = line =~ /[0-9]/\n\n col_str = line[0...col_size]\n row_str = line[col_size...-1]\n\n col = a_to_n(col_str)\n row = row_str.to_i\n\n print(\"R\")\n print(row)\n print(\"C\")\n print(col)\n\nend\n\ndef rc_to_xy(line)\n col_size = line =~ /[C]/\n\n row_str = line[1...col_size]\n col_str = line[col_size+1...-1]\n\n col = n_to_a(col_str)\n row = row_str.to_i\n\n print(col)\n print(row)\nend\n\ndef isrc(line)\n if line[0] == 'R' && line[1] =~ /[0-9]/\n if line[2...-1].include? \"C\"\n return true\n end\n end\n return false\nend\n\n\nline_count = gets.to_i\n\nwhile line_count > 0 \n line_string = gets\n if isrc(line_string)\n rc_to_xy(line_string)\n else\n xy_to_rc(line_string)\n end\n print(\"\\n\")\n line_count = line_count-1\nend\n"}, {"source_code": "\t#recibiendo el numero de iteraciones\n\tinput=gets.chomp\n\tn=input.to_i\n\t#metodo para saber si la cadena es excel o random\n\tdef validar_excel(a)\n\t\tif (a.include?(\"R\") && a.include?(\"C\")) #como el metodo random tiene R&C \n\t\t\tir=a.index(\"R\") \n\t\t\tic=a.index(\"C\")\n\t\t\t\n\t\t\tif a.index(\"R\")==0\n\t\t\t\tif a.index(\"C\")==1\n\t\t\t\t\tif (a[2].ord>=48 && a[2].ord<=57)\n\t\t\t\t\t\treturn true\n\t\t\t\t\telse\n\t\t\t\t\t\treturn false\n\t\t\t\t\tend\n\t\t\t\telse\n\t\t\t\t\tnum_char=0\n\t\t\t\t\t0.upto(a.size-1) do |j|\n\t\t\t\t\t\tif (a[j].ord>=48 && a[j].ord<=57) #ASCII para diferenciar num & str\n\t\t\t\t\t\t\tnum_char+=0\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tnum_char+=1\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\treturn num_char==2? false : true\n\t\t\telse\n\t\t\t\treturn true\n\t\t\tend\n\t\telse\n\t\t\treturn true\n\t\tend\n\tend\n\t#revisar\n\tdef convertir(ar)\n\t\tn=ar.size-1\t\n\t\ti=0\n\t\tnum=0\n\t\t\n\t\tloop do\n\t\t\tif n<0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\t\n\t\t\tnum=num+(ar[i].ord-64)*(26**n)\n\t\t\tn-=1\n\t\t\ti+=1\n\t\tend\n\t\t\n\t\treturn num\n\tend\n\t\n\t#primer metodo de BC23 a R23C55\n\tdef excel_to_random(arr)\n\t\tparte_num=\"\"\n\t\tparte_str=\"\"\n\t\t\n\t\t0.upto(arr.size-1) do |k|\n\t\t\tif (arr[k].ord>=48 && arr[k].ord<=57) #ASCII para diferenciar num & str\n\t\t\t\tparte_num=parte_num+arr[k]\n\t\t\telse\n\t\t\t\tparte_str=parte_str+arr[k]\n\t\t\tend\n\t\tend\n\t\n\t\tparte_c=convertir(parte_str)\n\t\trandom=\"R\"+parte_num+\"C\"+\"#{parte_c}\" #creando el random\n\t\t\n\t\treturn random\n\tend\n\t\n\t#metodo divisiones sucesivas?\n\tdef divsuc(num)\n\t\tnum_car=26\n\t\tpivot=num\n\t\tndig=0\n\t\tarreglo_num=[]\n\t\tpotencia=1\n\t\t\n\t\tloop do\n\t\t\tpivot=pivot-26**potencia\n\t\t\tndig+=1\n\t\t\tpotencia+=1\n\t\t\tif pivot<=0\n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\t\t\n\t\t#real deal\n\t\tloop do\n\t\t\tif num==0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tif num%num_car !=0\n\t\t\t\tarreglo_num[ndig-1]=((num%num_car)+64).chr()\n\t\t\t\tnum=num/num_car\n\t\t\telse #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)\n\t\t\t\tq=num/num_car\n\t\t\t\tnum=q-1\n\t\t\t\tarreglo_num[ndig-1]=(num_car+64).chr()\n\t\t\tend\n\t\t\tndig-=1\n\t\tend\n\t\treturn arreglo_num\n\tend\n\t\n\t#segundo metodo de R23C55 a BC23\n\tdef random_to_excel(arr)\n\t\trow=\"\"\n\t\tcol=\"\"\n\t\ta=0\n\t\t\n\t\t1.upto(arr.size-1) do |k|\n\t\t\t(arr[k]==\"C\")? a+=1:a+=0\n\n\t\t\tif a==0\n\t\t\t\trow=row+arr[k]\n\t\t\telse\n\t\t\t\tif (arr[k]!=\"C\") \n\t\t\t\t\tcol=col+arr[k]\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tcol=col.to_i\n\t\tcole=divsuc(col)#convertir la columna a excel\n\t\texcel=cole.join+row\n\t\t\n\t\treturn excel\n\tend\n\t\n\t$res=[] #definici\u00f3n de la variable GLOBAL, para poder imprimirlo despu\u00e9s\n\t\n\t0.upto(n-1) do |j|\n\t\tcadena=gets.chomp.upcase\n\t\tarray=cadena.split(\"\")\n\t\ti=validar_excel(array)\n\t\t\n\t\tif i\n\t\t\tresultado=excel_to_random(array) #TRUE ES excel\n\t\telse\n\t\t\tresultado=random_to_excel(array)\n\t\tend\n\t\t\t\n\t\t$res[j]=resultado \t#recordar que el puts imprime con /n y el print no lo hace\n\tend\n\t#IMPRIMIR RESULTADO\n\tputs $res"}, {"source_code": "n = gets.to_i\nn.times do\n s = gets\n m = /R(\\d+)C(\\d+)/.match(s)\n if m != nil\n val = m[2].to_i\n col = \"\"\n while val > 0\n col.concat((val % 26 + 65 - 1).chr)\n val /= 26\n end\n col.reverse!\n puts \"#{col}#{m[1]}\"\n else\n m = /([A-Z]+)(\\d+)/.match(s)\n col = m[1]\n col.reverse!\n cnt, base = 0, 1\n col.length.times do |i|\n cnt += (col[i].ord - 'A'.ord + 1) * base\n base *= 26\n end\n puts \"R#{m[2]}C#{cnt}\"\n end\nend\n\n"}, {"source_code": "n = gets\nn = Integer(n)\nwhile n>0\n string = gets\n m = string.size()\n index = 0\n while ('A'..'Z').include? string[index]\n index += 1\n end\n while !(('A'..'Z').include? string[index])\n index += 1\n if index >= m\n break;\n end\n end\n if index == m\n index = 0\n while ('A'..'Z').include? string[index]\n index+=1\n end\n index -= 1\n c = 0\n count = 1\n til = index\n until index < 0\n c += (string[index].unpack(\"c\")[0] - 'A'.unpack(\"c\")[0] + 1) * count\n index -= 1\n count *= 26\n end\n puts \"R#{string[til+1..m].chomp}C#{c}\"\n else\n index = string.index(\"C\")\n count = Integer(string[index+1..m-2].chomp)\n k = \"\"\n while count > 0\n if count % 26 == 0\n k = \"Z\" + k\n count /= 26\n count -= 1\n end\n if count>0\n k = (count % 26 + 64).chr + k\n count /= 26 \n end\n end\n puts \"#{k}#{string[1..index-1]}\"\n end\n n-=1\nend"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"LOGNAME\"]==\"skydos\"\n#=================================\n\ndef to_number str\n num = 0\n digits = [*?A..?Z]\n \n pow=1\n str.reverse.each_char{|c| \n d = digits.index(c) + 1\n \n num+=d*pow\n pow*=26\n }\n \n num\nend\n\ndef to_first line\n letters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]\n \"R#{number}C#{to_number letters}\"\nend\n\ndef to_27 num\n ans = \"\"\n digits = [*?A..?Z]\n \n num = num.to_i\n while num!=0\n ans+=digits[num%27 - 1]\n num/=27\n end\n \n ans.reverse\nend\n\ndef to_second line\n a, b = line.scan(/R([0-9]+)C([0-9]+)/)[0] \n \"#{to_27 b}#{a}\"\nend\n\nn=gets.to_i\n\nn.times{\n line=gets.strip\n \n if /R([0-9]+)C([0-9]+)/.match line\n puts to_second line\n else\n puts to_first line\n end\n}"}, {"source_code": "num = gets.chomp.to_i\nnum.times do\n old = gets.chomp\n results = old.match('R(\\d+)C(\\d+)')\n if results != nil\n col_num = results[2].to_i\n base = 1;\n col_str = \"\"\n while col_num > 26\n this_char = col_num % 26\n col_num /= 26\n if this_char == 0\n this_char = 26\n end\n col_num -= 1\n col_str = \"#{(this_char+64).chr}#{col_str}\"\n end\n col_str = \"#{(col_num+64).chr}#{col_str}\"\n puts \"#{col_str}#{results[1]}\"\n else\n results = old.match('([A-Z]+)(\\d+)')\n col_str = results[1]\n base = 26**(col_str.length-1)\n col_num = 0\n col_str.each_char do |c| \n col_num += (c.ord-64)*base\n base /= 26\n end\n puts \"R#{results[2]}C#{col_num}\"\n end\nend"}, {"source_code": "def main\n\ttc=gets.chomp.to_i;\n\talp=[*'A'..'Z'];\n\ths={}\n\ti=1;\n\talp.each do |z|\n\t\ths[z]=i;\n\t\ti+=1;\n\tend\n\tfor i in 1..tc\n\t\ts=gets.chomp.to_s;\n\t\tif s.count(\"R\")==1 and s.count(\"C\")==1\n\t\t\tindc=s.index(\"C\");\n\t\t\tcol=s[indc+1...(s.length)].to_i;\n\t\t\tj=1;\n\t\t\twhile(26*j+10\n l = STDIN.gets.chop\n row = nil\n col = nil\n /R(?\\d+)C(?\\d+)/=~l\n unless (row and col)\n /(?[A-Z]+)(?\\d+)/=~l\n col_ = 0\n i=0\n col.each_byte do |a|\n pos = col.length - i - 1\n col_+=('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)**pos*(a-'A'.bytes.to_a.first+1)\n i+=1\n end\n row = row.to_i\n puts \"R\"+row.to_s+\"C\"+col_.to_s\n else\n col = col.to_i\n col_ = ''\n while col!=0\n temp = col % ('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)\n col_+=['A'.bytes.to_a.first+temp-1].pack(\"U\")\n col /= ('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)\n end\n col_.reverse!\n puts col_+row\n end\n n-=1\nend\n\n"}, {"source_code": "\t#recibiendo el numero de iteraciones\n\tinput=gets.chomp\n\tn=input.to_i\n\t#metodo para saber si la cadena es excel o random\n\tdef validar_excel(a)\n\t\tif (a.include?(\"R\") && a.include?(\"C\")) #como el metodo random tiene R&C \n\t\t\tif a.index(\"R\")==0\n\t\t\t\tnum_char=0\n\t\t\t\t0.upto(a.size-1) do |j|\n\t\t\t\t\tif (a[j].ord>=48 && a[j].ord<=57) #ASCII para diferenciar num & str\n\t\t\t\t\t\tnum_char+=0\n\t\t\t\t\telse\n\t\t\t\t\t\tnum_char+=1\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\treturn num_char==2? false : true\n\t\t\telse\n\t\t\t\treturn true\n\t\t\tend\n\t\telse\n\t\t\treturn true\n\t\tend\n\tend\n\t#revisar\n\tdef convertir(ar)\n\t\tn=ar.size-1\t\n\t\ti=0\n\t\tnum=0\n\t\t\n\t\tloop do\n\t\t\tif n<0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\t\n\t\t\tnum=num+(ar[i].ord-64)*(26**n)\n\t\t\tn-=1\n\t\t\ti+=1\n\t\tend\n\t\t\n\t\treturn num\n\tend\n\t\n\t#primer metodo de BC23 a R23C55\n\tdef excel_to_random(arr)\n\t\tparte_num=\"\"\n\t\tparte_str=\"\"\n\t\t\n\t\t0.upto(arr.size-1) do |k|\n\t\t\tif (arr[k].ord>=48 && arr[k].ord<=57) #ASCII para diferenciar num & str\n\t\t\t\tparte_num=parte_num+arr[k]\n\t\t\telse\n\t\t\t\tparte_str=parte_str+arr[k]\n\t\t\tend\n\t\tend\n\t\n\t\tparte_c=convertir(parte_str)\n\t\trandom=\"R\"+parte_num+\"C\"+\"#{parte_c}\" #creando el random\n\t\t\n\t\treturn random\n\tend\n\t\n\t#metodo divisiones sucesivas?\n\tdef divsuc(num)\n\t\tnum_car=26\n\t\tpivot=num\n\t\tndig=0\n\t\tarreglo_num=[]\n\t\tpotencia=1\n\t\t\n\t\tloop do\n\t\t\tpivot=pivot-26**potencia\n\t\t\tndig+=1\n\t\t\tpotencia+=1\n\t\t\tif pivot<=0\n\t\t\t\tbreak \n\t\t\tend\n\t\tend\n\t\t\n\t\t#real deal\n\t\tloop do\n\t\t\tif num==0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tif num%num_car !=0\n\t\t\t\tarreglo_num[ndig-1]=((num%num_car)+64).chr()\n\t\t\t\tnum=num/num_car\n\t\t\telse #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)\n\t\t\t\tq=num/num_car\n\t\t\t\tnum=q-1\n\t\t\t\tarreglo_num[ndig-1]=(num_car+64).chr()\n\t\t\tend\n\t\t\tndig-=1\n\t\tend\n\t\treturn arreglo_num\n\tend\n\t\n\t#segundo metodo de R23C55 a BC23\n\tdef random_to_excel(arr)\n\t\trow=\"\"\n\t\tcol=\"\"\n\t\ta=0\n\t\t\n\t\t1.upto(arr.size-1) do |k|\n\t\t\t(arr[k]==\"C\")? a+=1:a+=0\n\n\t\t\tif a==0\n\t\t\t\trow=row+arr[k]\n\t\t\telse\n\t\t\t\tif (arr[k]!=\"C\") \n\t\t\t\t\tcol=col+arr[k]\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tcol=col.to_i\n\t\tcole=divsuc(col)#convertir la columna a excel\n\t\texcel=cole.join+row\n\t\t\n\t\treturn excel\n\tend\n\t\n\t$res=[] #definici\u00f3n de la variable GLOBAL, para poder imprimirlo despu\u00e9s\n\t\n\t0.upto(n-1) do |j|\n\t\tcadena=gets.chomp.upcase\n\t\tarray=cadena.split(\"\")\n\t\ti=validar_excel(array)\n\t\t\n\t\tif i\n\t\t\tresultado=excel_to_random(array) #TRUE ES excel\n\t\telse\n\t\t\tresultado=random_to_excel(array)\n\t\tend\n\t\t\t\n\t\t$res[j]=resultado \t#recordar que el puts imprime con /n y el print no lo hace\n\tend\n\t#IMPRIMIR RESULTADO\n\tputs $res"}, {"source_code": "r = /R\\d+C\\d+/\nrow_regex = /\\d+/\n\nn = gets.chomp.to_i\n\nn.times do\n line = gets.chomp\n puts line.match(r)\n if line.match(r)\n row = line[1.. (line =~ /C/)].to_i\n c = line[(line =~ /C/)+1..-1].to_i\n a = 0; b = 0\n a = c\n res = \"\"\n while (a+26) > 26\n a = c / 26\n \t\t\tb = c % 26 == 0 ? 26 : c % 26\n \t\t\ta = c % 26 == 0 ? a - 1 : a\n \t\t\tc = a\n res.prepend(((b-1) + 65).chr)\n end\n puts \"#{res}#{row}\"\n else\n num_index = line =~ row_regex\n row = line[num_index..line.length()]\n col = 0\n col_str = line[0..num_index-1]\n col_str.split('').map.with_index do |chr, i|\n col += (chr.ord - 'A'.ord + 1) * (26 ** (num_index-1-i))\n end\n puts \"R#{row}C#{col}\"\n end\nend\n"}, {"source_code": "n = gets().to_i\nfor i in 1..n\n\tline = gets().split(/(\\d+)/)\n\tif line[0] == 'R'\n\t\tcol = line[3].to_i\n\t\tfor j in 1..100\n\t\t\tbreak if 26**j >= col\n\t\t\tcol -= 26**j\n\t\tend\n\t\ts = (col-1).to_s(26).rjust(j,'0').tr('0123456789abcdefghijklmnop', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')\n\t\tputs s << line[1]\n\telse\n\t\trow = line[1]\n\t\tans = 1 + line[0].tr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789abcdefghijklmnop').to_i(26) \n\t\tfor j in 1..line[0].length-1\n\t\t\tans += 26**j\n\t\tend\n\t\tputs 'R' << row << 'C' << ans.to_s\n\tend\nend\n"}], "src_uid": "910c0e650d48af22fa51ab05e8123709"} {"source_code": "n = STDIN.readline.to_i\nx_min, y_min = 10**10, 10**10\nx_max, y_max = -x_min, -y_min\nn.times do\n\tx, y = STDIN.readline.split.map {|s| s.to_i }\n\tx_min = x if x < x_min\n\ty_min = y if y < y_min\n\tx_max = x if x > x_max\n\ty_max = y if y > y_max\nend\na, b = x_max-x_min, y_max-y_min\nputs [a, b].max**2\n", "positive_code": [{"source_code": "n= gets.to_i\nmx, my, lx, ly = -1.0/0.0, -1.0/0.0, 1.0/0.0, 1.0/0.0\nn.times do\n x,y = gets.split.map(&:to_i)\n mx = [mx,x].max\n my = [my,y].max\n lx = [lx,x].min\n ly = [ly,y].min\nend\nputs [mx-lx,my-ly].max**2\n"}, {"source_code": "data = gets.to_i.times.map{gets.split.map{|x|x.to_i}}\nmin_x = data.map{|x|x[0]}.min\nmax_x = data.map{|x|x[0]}.max\nmin_y = data.map{|x|x[1]}.min\nmax_y = data.map{|x|x[1]}.max\nresult = [(max_x - min_x), (max_y - min_y)].max**2\nputs result"}, {"source_code": "# 485B\n\nmin_x = min_y = 10 ** 9 + 1\nmax_x = max_y = -min_x\ngets.to_i.times do\n x, y = gets.chomp.split.map &:to_i\n if x < min_x\n min_x = x\n end\n if x > max_x\n max_x = x\n end\n if y < min_y\n min_y = y\n end\n if y > max_y\n max_y = y\n end\nend\nputs [max_x - min_x, max_y - min_y].max ** 2"}, {"source_code": "n = gets.to_i\nmaxX = -10 ** 9\nmaxY = -10 ** 9\nminX = 10 ** 9\nminY = 10 ** 9\nn.times do\n\tinput = gets\n\tx_coor = input.split[0].to_i\n\ty_coor = input.split[1].to_i\n\tif x_coor > maxX\n\t\tmaxX = x_coor\n\tend\n\tif y_coor > maxY\n\t\tmaxY = y_coor\n\tend\n\tif x_coor < minX\n\t\tminX = x_coor\n\tend\n\tif y_coor < minY\n\t\tminY = y_coor\n\tend\t\nend\nx = maxX - minX\ny = maxY - minY\nputs x > y ? x ** 2 : y ** 2"}, {"source_code": "INF = 2e10;\n\ndef max(a, b)\n a > b ? a : b\nend\n\ndef min(a, b)\n a < b ? a : b\nend\n\nn = gets.chomp.to_i\ntop = -INF\nbottom = INF\nright = -INF\nleft = INF\n\nn.times do\n p = gets.chomp.split(\" \").map{|str|str.to_i}\n \n top = max(top, p[1])\n bottom = min(bottom, p[1])\n right = max(right, p[0])\n left = min(left, p[0])\nend\n\nwidth = right - left\nheight = top - bottom\n\nputs max(width, height) ** 2\n"}], "negative_code": [{"source_code": "n = STDIN.readline.to_i\nx_min, y_min = 10**10, 10**10\nx_max, y_max = -x_min, -y_min\nn.times do\n\tx, y = STDIN.readline.split.map {|s| s.to_i }\n\tx_min = x if x < x_min\n\ty_min = y if y < y_min\n\tx_max = x if x > x_min\n\ty_max = y if y > y_min\nend\na, b = x_max-x_min, y_max-y_min\nputs [a, b].max**2\n"}, {"source_code": "n= gets.to_i\nmx,my,lx,ly=0,0,0,0\nn.times do\n x,y = gets.split.map(&:to_i)\n mx = [mx,x].max\n my = [my,y].max\n lx = [lx,x].min\n ly = [ly,y].min\nend\nputs [mx-lx,my-ly].max**2"}, {"source_code": "data = gets.to_i.times.map{gets.split.map{|x|x.to_i}}\nmin_x = data.min{|row| row[0]}[0]\nmax_x = data.max{|row| row[0]}[0]\nmin_y = data.min{|row| row[1]}[1]\nmax_y = data.max{|row| row[1]}[1]\nresult = [(max_x - min_x), (max_y - min_y)].max**2\nputs result"}, {"source_code": "def get_task_data(filename)\n raw_data = open(filename){|f|f.readlines}\n count = raw_data[0].to_i\n return false if count.zero?\n data = raw_data[1,raw_data.size].map{|str|str.split.map{|digit| digit.to_i}}\n return false if data.select{|row| row.size!=2}.any?\n return data.size==count ? data : false\nend\n\ndef solve(filename)\n task_data = get_task_data filename\n return 0 unless task_data\n min_x = task_data.min{|row| row[0]}[0]\n max_x = task_data.max{|row| row[0]}[0]\n min_y = task_data.min{|row| row[1]}[1]\n max_y = task_data.max{|row| row[1]}[1]\n [(max_x - min_x), (max_y - min_y)].max**2\nend"}, {"source_code": "data = gets.to_i.times.map{gets.split.map{|x|x.to_i}}\nputs data\nmin_x = data.map{|x|x[0]}.min\nmax_x = data.map{|x|x[0]}.max\nmin_y = data.map{|x|x[1]}.min\nmax_y = data.map{|x|x[1]}.max\nputs \"min_x:#{min_x} max_x:#{max_x} min_y:#{min_y} max_y:#{max_y}\"\nresult = [(max_x - min_x), (max_y - min_y)].max**2\nputs result"}, {"source_code": "# 485B\n\nmin_x = min_y = 10 ** 9 + 1\nmax_x = max_y = -min_x\ngets.to_i.times do\n x, y = gets.chomp.split.map &:to_i\n if x < min_x\n min_x = x\n elsif x > max_x\n max_x = x\n end\n if y < min_y\n min_y = y\n elsif y > max_y\n max_y = y\n end\nend\nputs [max_x - min_x, max_y - min_y].max ** 2"}, {"source_code": "# 485B\n\nmin_x = min_y = 10 ** 9 + 1\nmax_x = max_y = -min_x\ngets.to_i.times do\n x, y = gets.chomp.split.map &:to_i\n if x < min_x\n min_x = x\n end\n if x > max_x\n max_x = x\n end\n if y < min_y\n min_y = y\n end\n if y > max_y\n max_y = y\n end\nend\np [min_x, max_x, min_y, max_y]\nputs [max_x - min_x, max_y - min_y].max ** 2"}, {"source_code": "n = gets.to_i\nmaxX = -10 ** 9\nmaxY = -10 ** 9\nminX = 10 ** 9\nminY = 10 ** 9\nn.times do\n\tinput = gets\n\tx_coor = input.split[0].to_i\n\ty_coor = input.split[1].to_i\n\tif x_coor > maxX\n\t\tmax = x_coor\n\tend\n\tif y_coor > maxY\n\t\tmaxY = y_coor\n\tend\n\tif x_coor < minX\n\t\tminX = x_coor\n\tend\n\tif y_coor < minY\n\t\tminY = y_coor\n\tend\t\nend\nx = maxX - minX\ny = maxY - minY\nputs x > y ? x ** 2 : y ** 2"}, {"source_code": "n = gets.to_i\nmax = -10 ** 9\nmin = 10 ** 9\nn.times do\n\tinput = gets\n\tx_coor = input.split[0].to_i\n\ty_coor = input.split[1].to_i\n\tif x_coor > max\n\t\tmax = x_coor\n\telsif y_coor > max\n\t\tmax = y_coor\n\tend\n\tif x_coor < min\n\t\tmin = x_coor\n\telsif y_coor < min\n\t\tmin = y_coor\n\tend\t\nend\n\nputs (max - min) ** 2"}, {"source_code": "n = gets.to_i\nmax = 0\nn.times do\n\tinput = gets\n\tx_coor = input.split[0].to_i\n\ty_coor = input.split[1].to_i\n\tif x_coor > max\n\t\tmax = x_coor\n\telsif y_coor > max\n\t\tmax = y_coor\n\tend\t\nend\n\nputs max ** 2"}, {"source_code": "n = gets.to_i\nmaxX = -10 ** 9\nmaxY = -10 ** 9\nminX = 10 ** 9\nminY = -10 ** 9\nn.times do\n\tinput = gets\n\tx_coor = input.split[0].to_i\n\ty_coor = input.split[1].to_i\n\tif x_coor > maxX\n\t\tmax = x_coor\n\tend\n\tif y_coor > maxY\n\t\tmaxY = y_coor\n\tend\n\tif x_coor < minX\n\t\tminX = x_coor\n\tend\n\tif y_coor < minY\n\t\tminY = y_coor\n\tend\t\nend\nx = maxX - minX\ny = maxY - minY\nputs x > y ? x ** 2 : y ** 2"}], "src_uid": "016e00b2b960be792d4ec7fcfb7976e2"} {"source_code": "def solve(a, b)\n a.gcd(b) == 1 ? \"Finite\" : \"Infinite\"\nend\n\n\ngets.strip.to_i.times do\n puts solve(*gets.strip.split(' ').map(&:to_i))\nend", "positive_code": [{"source_code": "number_of_tests = gets.chomp.to_i\n\nnumber_of_tests.times do\n a, b = gets.chomp.split.map(&:to_i)\n puts a.gcd(b) == 1 ? 'Finite' : 'Infinite'\nend\n"}], "negative_code": [], "src_uid": "388450021f2f33177d905879485bb531"} {"source_code": "\r\n\r\n/Variables:/\r\nfriends = 0\r\ntotal_time = []\r\ntestcases = 0\r\n\r\n/Prerequisites: Enter de numer of testcases/\r\ntestcases = Integer(gets.chomp)\r\n\r\n/Firts: Request the number of friends to come/\r\nfor i in (0..(testcases-1))\r\n friends = Integer(gets.chomp)\r\n\r\n if friends <= 6\r\n friends = 6\r\n end\r\n if (friends%2)!=0\r\n friends = friends + 1\r\n end\r\n total_time[i] = (5*friends)/2\r\nend\r\ntotal_time.each do |elements|\r\n puts (elements)\r\nend\r\n", "positive_code": [{"source_code": "gets\r\n$stdin.map(&:to_i).each do |n|\r\n puts [(n + 1) / 2 * 5, 15].max\r\nend"}, {"source_code": "MOD = 10 ** 9 + 7\r\ndef gs; gets.chomp; end\r\ndef gi; gets.to_i; end\r\ndef gli; gets.split.map(&:to_i); end\r\ndef cyesno(x); puts x ? :Yes : :No; end\r\ndef uyesno(x); puts x ? :YES : :NO; end\r\ndef array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end\r\n\r\ndef solve\r\n puts [((gi + 1) / 2) * 5 , 15].max\r\nend\r\n\r\ndef main\r\n gi.times { solve }\r\nend\r\n\r\nmain\r\n"}], "negative_code": [{"source_code": "/\r\nProblem: Petya wants to order pizza for her birthday. \r\nShe does not know how much of her friends will come and \r\nshe wants to order so much pizza that each of his friends gets at least one slice of pizza. \r\nThe cooking time of the order is the total baking time of all the pizzas in the order.\r\nInput\r\nThe first line contains a single integer t (1\u2264t\u2264104) \u2014 the number of testcases.\r\nEach testcase consists of a single line that contains a single integer n (1\u2264n\u22641016) \u2014 the number of Petya's friends.\r\nOutput\r\nFor each testcase, print one integer \u2014 the minimum number of minutes that is needed to bake pizzas containing at least n slices in total.\r\n/\r\n/Solution:/ \r\n/Declare the variables necessaries./\r\n/Constants:/\r\nSMALL_PIZZA = 6\r\nMEDIUM_PIZZA = 8\r\nLONG_PIZZA = 10\r\nTIME_SMALL_PIZZA = 15\r\nTIME_MEDIUM_PIZZA = 20\r\nTIME_LONG_PIZZA = 25\r\n\r\n/Variables:/\r\nfriends = 0\r\nsmall_pizza_order = 1\r\nmedium_pizza_order = 0\r\nlong_pizza_order = 0\r\ntotal_time = 0\r\n\r\ncondition = true\r\nlimit_small_pizza = false\r\nlimit_medium_pizza = false\r\nlimit_long_pizza = false\r\n\r\n/Firts: Request the number of friends to come/\r\nfriends = Integer(gets.chomp)\r\n\r\n/Second: Determinate the number of pizzas to order/\r\n/In order to translate de minimun slides at one for friends, when it is one more slide than the number of friends, /\r\n/it does not matter, because satisfate the condicion of minimun slides for person./\r\n/So, for friends equals or less than 6, the case just be order a small pizza/\r\n\r\nif friends <= 6\r\n /Case for small pizza:/\r\n small_pizza_order = 1\r\nelse\r\n /Other case/\r\n /We must to do a loop until aprox our value to the number of friends/\r\n while condition\r\n /For the max number of small pizza/\r\n if !limit_small_pizza\r\n /Sum one more pizza/\r\n small_pizza_order = small_pizza_order + 1\r\n /Quest if the number of slides is equals than the number of friends/\r\n if SMALL_PIZZA*small_pizza_order == friends || (SMALL_PIZZA*small_pizza_order) == (friends +1)\r\n limit_small_pizza = true\r\n limit_medium_pizza = true\r\n limit_long_pizza = true\r\n condition = false\r\n /Quest if is more than the number of friends/\r\n elsif SMALL_PIZZA*small_pizza_order > friends\r\n small_pizza_order = small_pizza_order - 2\r\n limit_small_pizza = true\r\n /Other case slides is small than friends and continue/\r\n end\r\n \r\n /For the max number of medium pizza/\r\n elsif !limit_medium_pizza\r\n /Sum one more pizza/\r\n medium_pizza_order = medium_pizza_order + 1\r\n /Quest if the number of slides is equals than the number of friends/\r\n if (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) == friends || (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) == (friends +1) || ((SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order)-1) == friends\r\n limit_small_pizza = true\r\n limit_medium_pizza = true\r\n limit_long_pizza = true\r\n condition = false\r\n /Quest if is more than the number of friends/\r\n elsif (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) > friends\r\n medium_pizza_order = medium_pizza_order - 2\r\n limit_medium_pizza = true\r\n /Other case slides is medium than friends and continue/\r\n end\r\n \r\n /For the max number of large pizza/\r\n elsif !limit_long_pizza\r\n /Sum one more pizza/\r\n long_pizza_order = long_pizza_order + 1\r\n /Quest if the number of slides is equals than the number of friends/\r\n if (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) == friends || (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) == (friends +1) || ((SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order)-1) == friends\r\n limit_small_pizza = true\r\n limit_medium_pizza = true\r\n limit_long_pizza = true\r\n condition = false\r\n /Quest if is more than the number of friends/\r\n elsif (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) > friends\r\n long_pizza_order = long_pizza_order - 1\r\n limit_long_pizza = true\r\n condition = false\r\n /Other case slides is large than friends and continue/\r\n end\r\n end\r\n end\r\nend\r\ntotal_time = TIME_SMALL_PIZZA*small_pizza_order + TIME_MEDIUM_PIZZA*medium_pizza_order + TIME_LONG_PIZZA*long_pizza_order\r\nputs(total_time)\r\n"}, {"source_code": "/\r\nProblem: Petya wants to order pizza for her birthday. \r\nShe does not know how much of her friends will come and \r\nshe wants to order so much pizza that each of his friends gets at least one slice of pizza. \r\nThe cooking time of the order is the total baking time of all the pizzas in the order.\r\nInput\r\nThe first line contains a single integer t (1\u2264t\u2264104) \u2014 the number of testcases.\r\nEach testcase consists of a single line that contains a single integer n (1\u2264n\u22641016) \u2014 the number of Petya's friends.\r\nOutput\r\nFor each testcase, print one integer \u2014 the minimum number of minutes that is needed to bake pizzas containing at least n slices in total.\r\n/\r\n/Solution:/ \r\n/Declare the variables necessaries./\r\n/Constants:/\r\nSMALL_PIZZA = 6\r\nMEDIUM_PIZZA = 8\r\nLONG_PIZZA = 10\r\nTIME_SMALL_PIZZA = 15\r\nTIME_MEDIUM_PIZZA = 20\r\nTIME_LONG_PIZZA = 25\r\n\r\n/Variables:/\r\nfriends = 0\r\nsmall_pizza_order = 1\r\nmedium_pizza_order = 0\r\nlong_pizza_order = 0\r\ntotal_time = 0\r\n\r\ncondition = true\r\nlimit_small_pizza = false\r\nlimit_medium_pizza = false\r\nlimit_long_pizza = false\r\n\r\n/Firts: Request the number of friends to come/\r\nputs(\"Enter the number of friends that will come to Petya party\")\r\nfriends = Integer(gets.chomp)\r\n\r\n/Second: Determinate the number of pizzas to order/\r\n/In order to translate de minimun slides at one for friends, when it is one more slide than the number of friends, /\r\n/it does not matter, because satisfate the condicion of minimun slides for person./\r\n/So, for friends equals or less than 6, the case just be order a small pizza/\r\n\r\nif friends <= 6\r\n /Case for small pizza:/\r\n small_pizza_order = 1\r\nelse\r\n /Other case/\r\n /We must to do a loop until aprox our value to the number of friends/\r\n while condition\r\n /For the max number of small pizza/\r\n if !limit_small_pizza\r\n /Sum one more pizza/\r\n small_pizza_order = small_pizza_order + 1\r\n /Quest if the number of slides is equals than the number of friends/\r\n if SMALL_PIZZA*small_pizza_order == friends || (SMALL_PIZZA*small_pizza_order) == (friends +1)\r\n limit_small_pizza = true\r\n limit_medium_pizza = true\r\n limit_long_pizza = true\r\n condition = false\r\n /Quest if is more than the number of friends/\r\n elsif SMALL_PIZZA*small_pizza_order > friends\r\n small_pizza_order = small_pizza_order - 2\r\n limit_small_pizza = true\r\n /Other case slides is small than friends and continue/\r\n end\r\n \r\n /For the max number of medium pizza/\r\n elsif !limit_medium_pizza\r\n /Sum one more pizza/\r\n medium_pizza_order = medium_pizza_order + 1\r\n /Quest if the number of slides is equals than the number of friends/\r\n if (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) == friends || (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) == (friends +1) || ((SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order)-1) == friends\r\n limit_small_pizza = true\r\n limit_medium_pizza = true\r\n limit_long_pizza = true\r\n condition = false\r\n /Quest if is more than the number of friends/\r\n elsif (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) > friends\r\n medium_pizza_order = medium_pizza_order - 2\r\n limit_medium_pizza = true\r\n /Other case slides is medium than friends and continue/\r\n end\r\n \r\n /For the max number of large pizza/\r\n elsif !limit_long_pizza\r\n /Sum one more pizza/\r\n long_pizza_order = long_pizza_order + 1\r\n puts(long_pizza_order)\r\n /Quest if the number of slides is equals than the number of friends/\r\n if (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) == friends || (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) == (friends +1) || ((SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order)-1) == friends\r\n limit_small_pizza = true\r\n limit_medium_pizza = true\r\n limit_long_pizza = true\r\n condition = false\r\n /Quest if is more than the number of friends/\r\n elsif (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) > friends\r\n long_pizza_order = long_pizza_order - 1\r\n limit_long_pizza = true\r\n condition = false\r\n /Other case slides is large than friends and continue/\r\n end\r\n end\r\n end\r\nend\r\ntotal_time = TIME_SMALL_PIZZA*small_pizza_order + TIME_MEDIUM_PIZZA*medium_pizza_order + TIME_LONG_PIZZA*long_pizza_order\r\nputs(total_time)\r\n"}], "src_uid": "3e27f1c06a263760f5b53c3afe4bf7ee"} {"source_code": "l, c = [], 0\ngets.to_i.times do\n a, b = gets.split.map(&:to_f)\n l.push(a)\n l.push(b + 0.5)\nend\nl.sort!.each do |a|\n if a % 1 == 0\n c += 1\n break if c > 2\n else\n c -= 1\n end\nend\nputs c > 2 ? :NO : :YES", "positive_code": [{"source_code": "n = gets.to_i\nshows = []\nn.times do\n shows.push(gets.split.map(&:to_i))\nend\nshows.sort_by! { |start, _| start }\n\nbuffer = []\nshows.each do |start, ending|\n buffer = buffer.select { |show| show[1] >= start } + [[start, ending]]\n break if buffer.count > 2\nend\nputs buffer.count > 2 ? \"NO\" : \"YES\"\n"}], "negative_code": [], "src_uid": "9fa772b53e655a55f2ec502bc96d0e28"} {"source_code": "n, k = readline.split(' ').collect(&:to_i)\na = readline.split(' ').collect(&:to_i)\nb = readline.split(' ').collect(&:to_i)\ndown = 0\nup = (b[0] + k) / a[0] + 1\nwhile down + 1 < up\n mid = (down + up) / 2\n need = 0\n a.zip(b).each do |aa, bb|\n if aa * mid > bb\n need += aa * mid - bb\n end\n end\n if need <= k\n down = mid\n else\n up = mid\n end\nend\nputs down\n", "positive_code": [{"source_code": "input = gets.chomp.split(' ').map { |i| i.to_i }\ningredientNum, magicPowderNum = input[0], input[1]\n\ninput = gets.chomp.split(' ').map { |i| i.to_i }\nneeded = []\n\ninput.each do |item|\n\tneeded << item\nend\n\ninput = gets.chomp.split(' ').map { |i| i.to_i }\nhave = []\n\ninput.each do |item|\n\thave << item\nend\n\nnowMade = []\n\nfor i in (0...ingredientNum)\n\tnowMade << ((have[i] / needed[i]).floor)\nend\n\n=begin\nnowMade.each do |i|\n\tputs \"nowMade : #{i}\"\nend\n=end\n\nmin = 0\n\nuntil magicPowderNum <= 0\n\tmin = nowMade.sort[0]\n#\tputs \"min : #{min}\"\n\n\tidx = nowMade.find_index { |i| i == min }\n\n#\tputs \"idx : #{idx}\"\n\tsubVal = (needed[idx] - (have[idx] % needed[idx]))\n\tmagicPowderNum -= subVal\n\n\tbreak if magicPowderNum < 0\n\thave[idx] += subVal\n\tnowMade[idx] += 1\n\n#\tputs \"Remained : #{magicPowderNum}\"\nend\n\nmin = nowMade.sort[0]\nputs min"}, {"source_code": "parse_int = lambda { gets.split.map{|x| x.to_i} }\n\nn, magic = parse_int.call\nfor_one = parse_int.call\nhavin = parse_int.call\n\ncookies = 0\n\nwhile true\n\n #puts havin.to_s\n #puts magic\n #puts\n\n n.times{ |_|\n havin[_] -= for_one[_]\n if havin[_] < 0\n magic += havin[_]\n havin[_] = 0\n end\n }\n break if magic < 0\n cookies += 1\nend\n\nprint cookies"}], "negative_code": [], "src_uid": "02bb7502135afa0f3bb26527427ba9e3"} {"source_code": "n = gets.to_i\nif n%2==0\n puts \"NO\"\n exit\nend\nans = []\n\n# \u4ee5\u4e0b\u30671\u304b\u3089\u9806\u756a\u306b\u5165\u308c\u308b\u3002\n#1\u304b\u3089\u53cd\u5bfe\u5074\u306b\u98db\u3076\u3002{\u53f3\u96a3\u306b1\u3064\u79fb\u52d5\u3002\u53cd\u5bfe\u5074\u306b\u98db\u3076}\u3092\u7e70\u308a\u8fd4\u3059\nans[0] = 1\nside_a = 0\nside_b = n\n2.step(n*2,2).with_index do |num, i|\n if i%2==0\n ans[side_b + i] = num\n ans[side_b+1 + i] = num+1\n else\n ans[side_a + i]= num\n ans[side_a+1 + i]= num+1\n end\nend\nputs \"YES\\n#{ans[0..(2*n-1)].join(' ')}\"", "positive_code": [{"source_code": "n = gets.to_i\nif n%2 == 0\n puts 'NO'\nelse\n puts 'YES'\n a = []\n (1..n).each do |x|\n if x%2 != 0\n a[x - 1] = 2*x - 1\n a[x - 1 + n] = 2*x\n else\n a[x - 1] = 2*x\n a[x - 1 + n] = 2*x - 1\n end\n end\n a.each {|x| print x, ' '}\nend\n"}], "negative_code": [], "src_uid": "5e23f02afc7446ecf8688ad2a8fa284d"} {"source_code": "gets.to_i.times do\r\n n, b, x, y = gets.split.map(&:to_i)\r\n a, sum = 0, 0\r\n n.times do\r\n if a + x <= b\r\n a += x\r\n else\r\n a -= y\r\n end\r\n sum += a\r\n end\r\n p sum\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, b, x, y = gets.split.map(&:to_i)\r\n a, sum = 0, 0\r\n n.times do\r\n if a + x <= b && a + x - y <= b\r\n a += x\r\n else\r\n a -= y\r\n end\r\n sum += a\r\n end\r\n p sum\r\nend\r\n"}, {"source_code": "main = -> {\n t = int\n t.times do\n n, b, x, y = ints\n sum = 0\n cur = 0\n n.times do\n if cur + x <= b\n cur += x\n else\n cur -= y\n end\n sum += cur\n end\n puts sum\n end\n}\n\nDEBUG = true\nMOD = 10**9+7\n$yesno = %w(No Yes)\nYesNo = %w(No Yes)\nYESNO = %w(NO YES)\nINF = 10**18\n\nrequire \"set\"\nrequire \"prime\"\n\ndef int; gets.to_s.to_i end\ndef ints; gets.to_s.split.map { |s| s.to_i } end\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\ndef float; gets.to_s.to_f end\ndef floats; gets.to_s.split.map { |s| s.to_f } end\ndef array_of(&convert); gets.to_s.split.map(&convert) end\ndef string; gets.to_s.chomp end\ndef strings; gets.to_s.split end\ndef rep(n, &b); Array.new(n, &b) end\ndef yes; puts $yesno[1] end\ndef no; puts $yesno[0] end\ndef yesno t; puts $yesno[t] end\ndef YesNo t; puts YesNo[t] end\ndef YESNO t; puts YESNO[t] end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\ndef gcd(*xs); xs.inject(0, :gcd) end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\ndef if_debug; yield if DEBUG end\n\nmodule Boolean\n def coerce(other); [other, to_i] end\n def +@; to_i end\n def to_int; to_i end\n def *(other); to_i * other end\nend\n\nclass TrueClass\n include Boolean\n def to_i; 1 end\nend\n\nclass FalseClass\n include Boolean\n def to_i; 0 end\nend\n\nclass Integer\n def div_ceil(y); (self + y - 1) / y end\n def mod_inv(mod = MOD); pow(mod-2, mod) end\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\nend\n\nclass Array\n def power(&block); (0 ... 1 << size).each(&block) end\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\nend\n\nmodule Enumerable\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\nend\n\nmain[]"}], "negative_code": [], "src_uid": "2c921093abf2c5963f5f0e96cd430456"} {"source_code": "#! /usr/bin/env ruby\n# encoding: UTF-8\n\n=begin\na = p q\nb = q r\n\ngcd = q\nlcm = pqr\nq(1+pr)\n\n\u82e5\u5076\u6570\uff0c\u76f4\u63a5\u8f93\u51fa a=b=x/2\n\u82e5\u5947\u6570 > 1\uff0c\u5fc5\u7136\u6709 1+pr > 1\n\u82e5\u5947\u6570 = 1\uff0c\u65e0\u89e3\uff08\u9898\u76ee\u4fdd\u8bc1>=2\uff09\n\n\u7b80\u5316\uff1a\u4ee4q === 1\uff0c\u52191+pr\u603b\u662f>1\n=end\n\ndef solve\n\tn = gets.to_i\n\t#q = 1\n\t#p = 1\n\t#r = n-1 # ((n/q)-1 ) / p\n\tputs \"#{1} #{n-1}\"\nend\n\ngets.to_i.times{ solve }\n\n\n", "positive_code": [{"source_code": "1.upto(gets.to_i) do\n puts \"1 #{gets.to_i - 1}\"\nend\n"}, {"source_code": "t = gets.chomp.to_i\n(0...t).each do |_|\n x = gets.chomp.to_i\n print 1, ' ', x-1\n puts\nend\n\n"}, {"source_code": "gets.to_i.times do\n\tx = gets.to_i\n\tputs [1, x-1].join(' ')\nend"}, {"source_code": "t = gets.to_i\nt.times do\n x = gets.to_i\n puts [1, x-1].join(\" \")\nend\n"}, {"source_code": "require 'set'; require 'prime'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\n\nt.times do\n x = gets.chomp.to_i\n puts \"#{x-1} #{1}\"\nend\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n x = gets.to_i\n\n if x > 2 && x % 2 == 0\n puts \"2 #{x - 2}\"\n else\n puts \"1 #{x - 1}\"\n end\nend\n"}, {"source_code": "# cook your code here\n\nn = gets.to_i;\n\n(0..n-1).each do |i|\n x = gets.to_i;\n p 1, x-1;\nend\n \n \n"}], "negative_code": [{"source_code": "# cook your code here\n\nn = gets.to_i;\n\n(0..n).each do |i|\n x = gets.to_i;\n p 1, x-1;\nend\n \n \n"}, {"source_code": "# cook your code here\nx = gets.to_i;\np 1, x-1;"}], "src_uid": "2fa3e88688b92c27ad26a23884e26009"} {"source_code": "gets\na, b = 2.times.map{gets.split.map(&:to_i)}\nc = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}\nc.reject!{|j, i| j != c.min[0]}\np c.size\nputs c.map(&:last) * ' '\n\n", "positive_code": [{"source_code": "n,m,k = gets.chomp.split(/ /).map!{|x|x.to_i}\nma = gets.chomp.split(/ /).map!{|x|x.to_i}\nka = gets.chomp.split(/ /).map!{|x|x.to_i}\nsummin = k+1\nmas = Array.new\nfor i in 0..m-1\n\tsum = 0\n\tfor j in 0..k-1\n\t\tsum += 1 if ka[j] % ma[i] == 0\n\tend\n\tif summin > sum\n\t\tmas.clear\n\t\tmas.push(i+1)\n\t\tsummin = sum\n\telsif summin == sum\n\t\tmas.push(i+1)\n\tend\nend\nputs mas.length\nputs mas.join(' ')"}, {"source_code": "gets\na, b = 2.times.map{gets.split.map(&:to_i)}\nc = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}\nc.reject!{|j, i| j != c.min[0]}\np c.size\nputs c.map(&:last) * ' '\n"}, {"source_code": "gets\na, b = 2.times.map{gets.split.map(&:to_i)}\nc = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}\nc.reject!{|j, i| j != c.min[0]}\np c.size\nputs c.map(&:last) * ' '\n\n"}, {"source_code": "gets\na, b = 2.times.map{gets.split.map(&:to_i)}\nc = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}\nc.reject!{|j, i| j != c.min[0]}\np c.size\nputs c.map(&:last) * ' '\n\n"}, {"source_code": "gets\na, b = 2.times.map{gets.split.map(&:to_i)}\nc = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}\nc.reject!{|j, i| j != c.min[0]}\np c.size\nputs c.map(&:last) * ' '\n\n"}, {"source_code": "gets\na, b = 2.times.map{gets.split.map(&:to_i)}\nc = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}\nc.reject!{|j, i| j != c.min[0]}\np c.size\nputs c.map(&:last) * ' '"}, {"source_code": "gets\na, b = 2.times.map{gets.split.map(&:to_i)}\nc = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}\nc.reject!{|j, i| j != c.min[0]}\np c.size\nputs c.map(&:last) * ' '\n\n"}, {"source_code": "gets\na, b = 2.times.map{gets.split.map(&:to_i)}\nc = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}\nc.reject!{|j, i| j != c.min[0]}\np c.size\nputs c.map(&:last) * ' '\n\n"}, {"source_code": "gets\na, b = 2.times.map{gets.split.map(&:to_i)}\nc = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}\nc.reject!{|j, i| j != c.min[0]}\np c.size\nputs c.map(&:last) * ' '\n\n"}, {"source_code": "gets\na, b = 2.times.map{gets.split.map(&:to_i)}\nc = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}\nc.reject!{|j, i| j != c.min[0]}\np c.size\nputs c.map(&:last) * ' '\n\n"}], "negative_code": [{"source_code": "gets\na, b = 2.times.map{gets.split.map(&:to_i).sort}\nc = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}\nc.reject!{|j, i| j != c.min[0]}\np c.size\nputs c.map(&:last) * ' '\n"}], "src_uid": "0701a595ee3a2b9edee53444b9dd1d51"} {"source_code": "layout1 = gets.chomp\nlayout2 = gets.chomp\ns = gets.chomp\n\nres = ''\ns.split(\"\").each do |c|\n i = layout1.index(c.downcase)\n unless i\n res += c\n else\n if c == c.upcase\n res += layout2[i].upcase\n else\n res += layout2[i]\n end\n end\nend\nputs res", "positive_code": [{"source_code": "\nfirst=gets.chomp\nsecond=gets.chomp\nthird=gets.chomp\n \nthird.each_char do |x|\nif x=~/[[:digit:]]/\n print x\n next\nend\nindex = first.index(x.downcase)\n\nif x == x.upcase\n print second[index].upcase\nelse\n print second[index]\n end\nend"}, {"source_code": "a = gets\nb = gets\nh = {}\n(0...26).each { |i| h[a[i]] = b[i] }\nputs gets.chomp('').split('').map { |x|\n c = h[x.downcase] || x\n x =~ /[A-Z]/ ? c.upcase : c\n}.join\n"}, {"source_code": "k1 = gets.chomp\nk2 = gets.chomp\n\nmap = {}\nfor i in 0 ... 26\n map[k1[i]] = k2[i]\nend\n\ns = gets.chomp\nt = s.split('').map{|c|\n if c != c.downcase\n map[c.downcase].upcase\n else\n map[c] ? map[c] : c\n end\n}.join()\nputs t\n"}, {"source_code": "a,b,c=$<.map &:chomp\nputs c.tr(a+a.upcase,b+b.upcase)"}, {"source_code": "a,b,c=$<.map &:chomp\nputs c.tr(a+a.upcase,b+b.upcase)"}, {"source_code": "a,b,c=$<.map &:chomp\nputs c.tr(a+a.upcase,b+b.upcase)"}, {"source_code": "#!/usr/bin/ruby -w\n\nclass String\n\n def is_upper?\n not self.match /[[:lower:]]/\n end\n\n def is_lower?\n not self.match /[[:upper:]]/\n end\n\nend\n\nstr1 = gets\nstr2 = gets\nstrr = gets\n\nstr_siz = strr.size\nstr_siz.times do |i|\n idx = str1.index(strr[i].downcase)\n if idx != nil then\n if strr[i].is_upper? then\n strr[i] = str2[idx].capitalize\n else\n strr[i] = str2[idx]\n end\n end\nend\nputs strr\n"}, {"source_code": "fs = gets.chomp\nss = gets.chomp\nfsl = fs.upcase\nssl = ss.upcase\n\nans = ''\ngets.chomp.chars.each do |s|\n if id = fs.index(s)\n ans += ss[id]\n elsif id = fsl.index(s)\n ans += ssl[id]\n else\n ans += s\n end\nend\n\nputs ans"}, {"source_code": "f = gets.strip.split(\"\")\ns = gets.strip.split(\"\")\nt = gets.strip\nans = \"\"\nt.each_char do |c|\n id = f.index c.downcase\n if /[[:upper:]]/.match c\n ans += s[id].upcase\n elsif /[[:digit:]]/.match c\n ans += c\n else\n ans += s[id]\n end\nend\nputs ans\n"}, {"source_code": "str1=gets.chomp\nstr2=gets.chomp\n\nhs={}\nstr1.size.times{|i|\n\te1=str1[i]\n\te2=str2[i]\n\ths[e1]=e2\n\ths[e1.upcase]=e2.upcase\n}\nstr3=gets.chomp\nstr3.chars.each{|e|\n\tif hs.member?(e)==false\n\t\tprint e\n\telse\n\t\tprint hs[e]\n\tend\n}\nprint \"\\n\""}, {"source_code": "a = gets\nb = gets\nh = {}\n(0...26).each { |i| h[a[i]] = b[i] }\nputs gets.chomp('').split('').map { |x|\n c = h[x.downcase] || x\n x =~ /[A-Z]/ ? c.upcase : c\n}.join\n"}, {"source_code": "a = gets.chomp!\nb = gets.chomp!\nt = gets.chomp!\n\nh = Hash.new\n26.times do |i|\n\th[a[i]] = b[i]\nend\n\nf = \"\"\nt.chars do |c|\n\tif c == c.downcase\n\t\tf.insert(-1, h[c] || c)\n\telse\n\t\tf.insert(-1, h[c.downcase].upcase)\n\tend\nend\n\nputs f\n"}], "negative_code": [{"source_code": "a,b,c=$<.map &:chomp\nputs c.tr(b+b.upcase,a+a.upcase)"}, {"source_code": "#!/usr/bin/ruby -w\n\nclass String\n\n def is_upper?\n not self.match /[[:lower:]]/\n end\n\n def is_lower?\n not self.match /[[:upper:]]/\n end\n\nend\n\nputs 'Hello World'\n\nstr1 = gets\nstr2 = gets\nstrr = gets\n\nstr_siz = strr.size\nstr_siz.times do |i|\n idx = str1.index(strr[i].downcase)\n if idx != nil then\n if strr[i].is_upper? then\n strr[i] = str2[idx].capitalize\n else\n strr[i] = str2[idx]\n end\n end\nend\nputs strr\n"}], "src_uid": "d6f01ece3f251b7aac74bf3fd8231a80"} {"source_code": "s,m,n=0,1e6,Array.new(n=gets.to_i){gets.split.map(&:to_i)[1..-1].sort}\n(n+n[0,2]).each_cons(3){|a,b,c|r,b,*e=b.dup\nb&&(a,*w=a.drop_while{|i|ia||b>c ? (a>b ? (h+=1;c=r.shift||m):(g+=1;a=w.shift||m)):(g!=h&&s+=1\nb>m||(g=h;break if !b=e.shift))})}\np s\n", "positive_code": [{"source_code": "s,m,n=0,1e6,Array.new(n=gets.to_i){gets.split.map(&:to_i)[1..-1].sort}\n(n+n[0,2]).each_cons(3){|a,b,c|r,b,*e=b.dup\nb&&(a,*w=a.drop_while{|i|ia||b>c ? (a>b ? (h+=1;c=r.shift||m):(g+=1;a=w.shift||m)):(g!=h&&s+=1\nb>m||(g=h;break if !b=e.shift))})}\np s"}, {"source_code": "#require \"profile\"\n\ntime = Time.now\n\nSTDOUT.sync = true\n\nnet = Array.new(n = gets.to_i) do\n gets \" \"\n gets.split.map(&:to_i).sort\nend\n\nnet += net.take(2)\n\ns = 0\n\nnet.each_cons(3) do |l1t,l2t,l3t| #puts [l2t].inspect\n l2 = l2t.dup; start = l2.shift; #puts start\n l1 = l1t.dup; l1 = l1.drop_while{ |i| i < start }\n l3 = l3t.dup; l3 = l3.drop_while{ |i| i < start }\n a = l1.shift || 1000000\n next unless b = l2.shift\n c = l3.shift || 1000000\n g1 = g2 = 0\n loop do\n #puts [a,b,c,g1,g2,s].inspect\n if b <= a && b <= c\n if b == 1000000\n s += 1 if g1 != g2\n break\n end\n #puts \"b\"\n s += 1 if g1 != g2\n g1 = g2 = 0\n break unless b = l2.shift\n elsif a <= b && a <= c\n #puts \"a\"\n g1 += 1\n a = l1.shift || 1000000\n else\n #puts \"c\"\n g2 += 1\n c = l3.shift || 1000000\n end\n end\n #puts s\nend\n\nputs s\n\n#puts Time.now - time\n"}, {"source_code": "n = (1..(n=gets.to_i)).map do\n gets.split.map(&:to_i).drop(1).sort\nend\n\ns = 0\nm = 1e6\n\n(n + n[0,2]).each_cons(3) do |a,b,c|\n r,b,*e = b.dup\n next if !b\n a,*w = a.dup.drop_while{ |i| i < r }; a ||= m\n c,*r = c.dup.drop_while{ |i| i < r }; c ||= m\n g = h = 0\n loop do\n b <= a && b <= c ? (\n s += 1 if g != h\n (b <= m) && ( g = h; break if !b = e.shift )\n ) : a <= b && a <= c ?\n ( g += 1; a = w.shift || m ) :\n ( h += 1; c = r.shift || m )\n end\nend\n\nputs s\n"}, {"source_code": "s,m,n=0,1e6,Array.new(n=gets.to_i){gets.split.map(&:to_i)[1..-1].sort}\n(n+n[0,2]).each_cons(3){|a,b,c|r,b,*e=b.dup\nb&&(a,*w=a.drop_while{|i|ia||b>c ? (a>b ? (h+=1;c=r.shift||m):(g+=1;a=w.shift||m)):(g!=h&&s+=1\nb>m||(g=h;break if !b=e.shift))})}\np s\n"}, {"source_code": "s,m,n=0,1e6,Array.new(n=gets.to_i){gets.split.map(&:to_i)[1..-1].sort}\n(n+n[0,2]).each_cons(3){|a,b,c|r,b,*e=b.dup\nb&&(a,*w=a.drop_while{|i|ia||b>c ? (a>b ? (h+=1;c=r.shift||m):(g+=1;a=w.shift||m)):(g!=h&&s+=1\nb>m||(g=h;break if !b=e.shift))})}\np s\n"}, {"source_code": "s,m,n=0,1e6,Array.new(n=gets.to_i){gets.split.map(&:to_i)[1..-1].sort}\n(n+n[0,2]).each_cons(3){|a,b,c|r,b,*e=b.dup\nb&&(a,*w=a.drop_while{|i|ia||b>c ? (a>b ? (h+=1;c=r.shift||m):(g+=1;a=w.shift||m)):(g!=h&&s+=1\nb>m||(g=h;break if !b=e.shift))})}\np s\n"}, {"source_code": "s,m,n=0,1e6,Array.new(n=gets.to_i){gets.split.map(&:to_i)[1..-1].sort}\n(n+n[0,2]).each_cons(3){|a,b,c|r,b,*e=b.dup\nb&&(a,*w=a.drop_while{|i|ia||b>c ? (a>b ? (h+=1;c=r.shift||m):(g+=1;a=w.shift||m)):(g!=h&&s+=1\nb>m||(g=h;break if !b=e.shift))})}\np s\n"}, {"source_code": "s,m,n=0,1e6,Array.new(n=gets.to_i){gets.split.map(&:to_i)[1..-1].sort}\n(n+n[0,2]).each_cons(3){|a,b,c|r,b,*e=b.dup\nb&&(a,*w=a.drop_while{|i|ia||b>c ? (a>b ? (h+=1;c=r.shift||m):(g+=1;a=w.shift||m)):(g!=h&&s+=1\nb>m||(g=h;break if !b=e.shift))})}\np s\n"}, {"source_code": "s,m,n=0,1e6,Array.new(n=gets.to_i){gets.split.map(&:to_i)[1..-1].sort}\n(n+n[0,2]).each_cons(3){|a,b,c|r,b,*e=b.dup\nb&&(a,*w=a.drop_while{|i|ia||b>c ? (a>b ? (h+=1;c=r.shift||m):(g+=1;a=w.shift||m)):(g!=h&&s+=1\nb>m||(g=h;break if !b=e.shift))})}\np s\n"}, {"source_code": "s,m,n=0,1e6,Array.new(n=gets.to_i){gets.split.map(&:to_i)[1..-1].sort}\n(n+n[0,2]).each_cons(3){|a,b,c|r,b,*e=b.dup\nb&&(a,*w=a.drop_while{|i|ia||b>c ? (a>b ? (h+=1;c=r.shift||m):(g+=1;a=w.shift||m)):(g!=h&&s+=1\nb>m||(g=h;break if !b=e.shift))})}\np s\n"}], "negative_code": [{"source_code": "#require \"profile\"\n\ntime = Time.now\n\nSTDOUT.sync = true\n\nnet = Array.new(n = gets.to_i) do\n gets \" \"\n gets.split.map(&:to_i).sort\nend\n\nnet += net.take(2)\n\ns = 0\n\nnet.each_cons(3) do |l1t,l2t,l3t| #puts [l2t].inspect\n l2 = l2t.dup; start = l2.shift; #puts start\n l1 = l1t.dup; l1 = l1.drop_while{ |i| i < start }\n l3 = l3t.dup; l3 = l3.drop_while{ |i| i < start }\n a = l1.shift || 1000000\n next unless b = l2.shift\n c = l3.shift || 1000000\n g1 = g2 = 0\n loop do\n #puts [a,b,c,g1,g2,s].inspect\n if b <= a && b <= c\n if b == 1000000\n s += 1 if g1 != g2\n break\n end\n #puts \"b\"\n s += 1 if g1 != g2\n g1 = g2 = 0\n break unless b = l2.shift\n elsif a <= b && a <= c\n #puts \"a\"\n g1 += 1\n a = l1.shift || 1000000\n else\n #puts \"c\"\n g2 += 1\n c = l3.shift || 1000000\n end\n end\n #puts s\nend\n\nputs s\n\nputs Time.now - time\n"}], "src_uid": "c8951278f649e78e5fae5c2b2b844315"} {"source_code": "n, m, k = gets.split.map(&:to_i)\n$socks = [nil] + gets.split.map(&:to_i)\ndays = m.times.map{gets.split.map(&:to_i)}\n\n$visited = Array.new(n + 1)\n$e = Array.new(n + 1){Array.new}\n\ndays.each do |l, r|\n $e[l] << r\n $e[r] << l\nend\n\ndef bfs(u)\n todo = []\n push = lambda do |v|\n $visited[v] = true\n todo << v\n end\n push.(u)\n while u = todo.shift\n $rainbow[$socks[u]] += 1\n $e[u].each do |v|\n next if $visited[v]\n push.(v)\n end\n end\nend\n\nans = 0\n1.upto(n) do |i|\n next if $visited[i]\n $rainbow = Hash.new(0)\n bfs(i)\n v = $rainbow.values\n ans += v.inject(:+) - v.max\nend\n\nputs ans\n", "positive_code": [{"source_code": "def solve\n n, m, k = gets.split.map(&:to_i)\n cs = gets.split.map(&:to_i)\n uf = UnionFind.new(n)\n m.times do\n l, r = gets.split.map(&:to_i)\n uf.unit(l - 1, r - 1)\n end\n g2c = {}\n cs.each_with_index do |e, i|\n x = uf.find(i)\n colors = (g2c[x] ||= {})\n colors[e] ||= 0\n colors[e] += 1\n end\n ans = 0\n g2c.each_value do |colors|\n vs = colors.values\n sum = vs.inject(0, &:+)\n max = vs.max\n ans += sum - max\n end\n puts ans\nend\n\nclass UnionFind\n def initialize(size)\n @parent = (0...size).to_a\n @rank = Array.new(size, 0)\n end\n\n def find(x)\n return x if @parent[x] == x\n return (@parent[x] = find(@parent[x]))\n end\n\n def unit(x, y)\n x, y = find(x), find(y)\n return if x == y\n if @rank[x] < @rank[y]\n @parent[x] = y\n else\n @parent[y] = x\n @rank[x] += 1 if @rank[x] == @rank[y]\n end\n end\n\n def same(x, y)\n find(x) == find(y)\n end\nend\n\nsolve\n"}, {"source_code": "# TEMPLATE BEGIN\ndef read_vector\n gets.chomp.split(/\\s+/)\nend\ndef read_vector_int\n read_vector.map(&:to_i)\nend\n# TEMPLATE END\n\nclass SNM\n def initialize(n)\n @a = (0..n).to_a\n end\n\n def get(v)\n while @a[v] != v\n @a[v] = @a[@a[v]]\n v = @a[v]\n end\n return v\n end\n\n def join(u, v)\n pu = get(u)\n pv = get(v)\n return if pu == pv\n if rand < 0.5\n @a[pu] = @a[pv]\n else\n @a[pv] = @a[pu]\n end\n end\nend\n\nn, m, k = read_vector_int\ncolors = [nil] + read_vector_int\n\nsnm = SNM.new(n)\nm.times.each do\n v, u = read_vector_int\n snm.join(v, u)\nend\n\ncolors_in_comp = Array.new(n + 1) { [] }\n(1..n).each do |id|\n comp_id = snm.get(id)\n colors_in_comp[comp_id].push(colors[id])\nend\n\nans = 0\ncolors_in_comp.each do |c|\n next if c.empty?\n\n cnt = Hash.new(0)\n c.sort!\n c.each{ |col| cnt[col] += 1 }\n max_cnt = cnt.values.max\n ans += c.size - max_cnt\nend\n\nputs ans\n"}], "negative_code": [], "src_uid": "39232c03c033da238c5d1e20e9595d6d"} {"source_code": "a=gets.chomp.split(\" \")\nn=a[0].to_i\nm=a[1].to_i\ni=1\np=2\nn.times do \n if (i+2*n)<=m\n print \"#{i+2*n} \"\n end\n if i<=m\n print \"#{i} \"\n end\n \n i+=2\n if (p+2*n)<=m\n print \"#{p+2*n} \"\n end\n if p<=m\n print \"#{p} \"\n end\n \n p+=2\nend\n", "positive_code": [{"source_code": "n, m = readline.split(' ').collect(&:to_i)\narr = []\n1.upto(n) do |i|\n arr += [i * 2 - 1 + n * 2, i * 2 - 1, i * 2 + n * 2, i * 2]\nend\narr.keep_if {|num| num <= m}\narr.each_with_index do |num, ind|\n if ind != 0\n print \" \"\n end\n print num\nend\nputs \"\"\n"}, {"source_code": "a=gets.chomp.split(\" \")\nn=a[0].to_i\nm=a[1].to_i\ni=1\np=2\nn.times do \n if (i+2*n)<=m\n print \"#{i+2*n} \"\n end\n if i<=m\n print \"#{i} \"\n end\n \n i+=2\n if (p+2*n)<=m\n print \"#{p+2*n} \"\n end\n if p<=m\n print \"#{p} \"\n end\n \n p+=2\nend"}, {"source_code": "buf = gets.split(' ')\nn,m=buf[0].to_i,buf[1].to_i\nr=f=0\na=Array.new(n)\nfor i in 0..n-1\n\ta[i] = Array.new(4)\nend\nfor i in 1..m\n\ta[r][0] = i if f==0 && i%2==1\n\ta[r][3] = i if f==0 && i%2==0\n\ta[r][1] = i if f==1 && i%2==1\n\ta[r][2] = i if f==1 && i%2==0\n\tr+=1 if i%2==0\n\tif r==n\n\t\tr=0\n\t\tf=1\n\tend\nend\nans=\"\"\nfor i in 0..n-1\n\tans+= ' ' + a[i][1].to_s if a[i][1]\n\tans+= ' ' + a[i][0].to_s if a[i][0]\n\tans+= ' ' + a[i][2].to_s if a[i][2]\n\tans+= ' ' + a[i][3].to_s if a[i][3]\nend\nputs ans.strip"}, {"source_code": "n,m=gets.split.map(&:to_i)\na=[*1..(m+3)/4*4].each_slice(2).each_slice(n).to_a\nputs a.shift.zip(*a).flat_map{|(a,b),(c,d)|[c,a,d,b]}.select{|e|e&&e<=m}*' '"}], "negative_code": [{"source_code": "n,m=gets.split.map(&:to_i)\nm0=(m+2*n-1)/(2*n)\nputs [*1..m0*2*n].each_slice(n).each_slice(m0).to_a.transpose.flat_map{|a|b=a.reverse;b.shift.zip(*b).flatten}.select{|e|e<=m}*' '"}, {"source_code": "#!/usr/bin/ruby\nn,m=gets.split.map(&:to_i)\nm0=(m+3)/4\nputs [*1..m0*4].each_slice(2).each_slice(m0).to_a.transpose.flat_map{|(a,b),(c,d)|[c,a,d,b]}.select{|e|e<=m}*' '"}], "src_uid": "0a701242ca81029a1791df74dc8ca59b"} {"source_code": "require \"pp\"\n\nclass Edge\n def initialize (src,dst,cost)\n @src = src\n @dst = dst\n @cost = cost\n end\n \n attr_accessor :src, :dst, :cost\nend\n\n\nedges = Array.new\nnum = gets.to_i\ncost = 0\n\nfor i in 0..num-1\n\tary = gets.split.map{|elem| elem.to_i}\n\tedges << Edge.new(ary[0],ary[1],ary[2])\n\tcost += ary[2]\nend\n\nfirst = edges.shift\narc = Edge.new(first.src,first.dst,0)\n\nwhile edges.length > 0\n\tedges.each_with_index do |edge, i|\n\t\tif edge.src == arc.dst\n\t\t\tarc.dst = edge.dst\n\t\t\tedges.delete_at(i)\n\t\telsif edge.dst == arc.dst\n\t\t\tarc.dst = edge.src\n\t\t\tarc.cost += edge.cost\n\t\t\tedges.delete_at(i)\n\t\tend\n\tend\nend\n\np [arc.cost,cost - arc.cost].min\n\n", "positive_code": [{"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min\n"}, {"source_code": "#!/usr/bin/ruby\n\nN = gets.to_i\n\ncities = Array.new(N + 1) {Array.new}\n\nN.times do\n (a, b, c) = gets.split.map{|e| e.to_i}\n\n cities[a].push [b, 0]\n cities[b].push [a, c]\nend\n\nprev = 1\nnow = cities[1][0][0]\ncost0 = cities[1][0][1]\n\n(N - 1).times do # not N - 2\n id = (cities[now][0][0] == prev) ? 1 : 0\n prev = now\n cost0 += cities[now][id][1]\n now = cities[now][id][0]\nend\n\nprev = 1\nnow = cities[1][1][0]\ncost1 = cities[1][1][1]\n\n(N - 1).times do # not N - 2\n id = (cities[now][0][0] == prev) ? 1 : 0\n prev = now\n cost1 += cities[now][id][1]\n now = cities[now][id][0]\nend\n\nputs [cost0, cost1].min\n"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min\n"}, {"source_code": "p = Array.new(101)\n101.times{|i|\n p[i]=Array.new(101,0)\n}\n\ndef find_cost(prev, now, n, p)\n res, d = 0, p[prev][now]\n #puts \"find_cost: \"+prev.to_s+\" \"+now.to_s\n res = res - d if (d<0)\n return res if (now==1)\n (1..n).each{|i|\n res += find_cost(now, i, n, p) if (p[now][i].to_i!=0)&&(i!=prev)\n }\n res\nend\n\nn = gets.chomp.to_i\n\nn.times { |i|\n a,b,c = gets.chomp.split(' ').map{|it| it.to_i}\n p[a][b], p[b][a] = c, -c\n}\n\nans = -1\n\n(2..n).each{|i|\n if p[1][i]!=0\n candidate = find_cost(1, i, n, p)\n ans = candidate if (ans==-1 || candidate < ans)\n end\n}\n\nputs ans"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\n a,b,c=$_.split.map &:to_i\n h[a-1]<<[b-1,0]\n h[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\n while a>0\n h[a].map{|b,c|\n if b!=x\n a,x=b,a\n s+=c\n break\n end\n }\n end\n s\n}.min\n"}, {"source_code": "# start 2010/7/28 17:11\n# implementation finish at 18:57\n\n#ring_road\n\n\nclass Edge\n def initialize(u,v,inv_cost)\n @src = u\n @dst = v\n @inv_cost = inv_cost\n end\n\n attr_accessor :src, :dst, :inv_cost\nend\n\n\n\n#f = open(\"hoge.txt\")\n\nnum = gets.to_i\n#num = f.gets.to_i\n#p num\n\nedges = Array.new\nedge_subsets = Array.new\n\ntotal_cost = 0\n\nfor i in 0..num-1\n\t#ary = f.gets.split.map {|elem| elem.to_i}\n\tary = gets.split.map {|elem| elem.to_i}\n\t# p ary\n\t\n\t# e(u,v) , inv_cost_of_e \ufffd\u0182\ufffd\ufffd\ufffdformat.\n\tedges << Edge.new(ary[0],ary[1],ary[2])\n\t\n\ttotal_cost += ary[2]\nend\n\n\n#circle\ufffd\ufffd\ufffd\ufffd\ufffd\n\t#edge\ufffd\ufffdsubset\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u010ds\ufffd\ufffd\ufffdAmerge\ufffd\ufffd\ufffd\u0102\ufffd\ufffd\ufffd\n\nedges.each {|edge|\n\tif edge_subsets.length == 0\n\t\tsubset = Array.new\n\t\tsubset << edge.src << edge.dst\n\t\tedge_subsets << subset\n\telse\n\t\tmerge_flg = false\n\n\t\tedge_subsets.each{|subset|\n\t\t\tmerge_flg = true\n\t\t\t\n\t\t\tif edge.src == subset.first\n\t\t\t\tsubset.unshift edge.dst\n\t\t\telsif edge.src == subset.last\n\t\t\t\tsubset << edge.dst\n\t\t\telsif edge.dst == subset.first\n\t\t\t\tsubset.unshift edge.src\n\t\t\telsif edge.dst == subset.last\n\t\t\t\tsubset << edge.src\n\t\t\telse\n\t\t\t\tmerge_flg = false\n\t\t\tend\n\t\t\t\n\t\t\tif merge_flg\n\t\t\t\tbreak\n\t\t\tend\n\t\t}\n\t\t\n\t\tunless merge_flg\n\t\t\tsubset = Array.new\n\t\t\tsubset << edge.src << edge.dst\n\t\t\tedge_subsets << subset\n\t\tend\n\tend\n}\n\n#p edge_subsets\n\n#subset\ufffd\ufffd\ufffdm\ufffd\ufffdmerge\n\n#puts \"merge subsets\"\n\nwhile edge_subsets.length > 1\n\ttemp_ss = edge_subsets.pop\n\n\tedge_subsets.each{|subset|\n\t\tif temp_ss.first == subset.first\n\t\t\ttemp_ss.reverse!\n\t\t\ttemp_ss.pop\n\t\t\tsubset = temp_ss + subset\n\t\telsif temp_ss.first == subset.last\n\t\t\ttemp_ss.shift\n\t\t\tsubset.concat temp_ss\n\t\telsif temp_ss.last == subset.first\n\t\t\ttemp_ss.pop\n\t\t\tsubset = temp_ss + subset\n\t\telsif temp_ss.last == subset.last\n\t\t\ttemp_ss.reverse!\n\t\t\ttemp_ss.shift\n\t\t\tsubset.concat temp_ss\n\t\tend\n\t}\nend\n\n#p edge_subsets\n\ncircle = edge_subsets.pop\n#p circle\n\nrev_cost = 0\n\nedges.each {|edge|\n\tidx = circle.index(edge.src)\n\tif circle[idx+1] != edge.dst\n\t\t#p edge\n\t\trev_cost += edge.inv_cost\n\tend\n}\n\nalt = total_cost - rev_cost\nif rev_cost < alt\n\tp rev_cost\nelse\n\tp alt\nend\n\n=begin\n\n[4, 6, 1, 5, 3, 2]\n\n---\nn=6\n\n1 5\n5 3\n\n2 4\n\n1 6\n\n2 3\n4 6\n\n=end\n"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min\n"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min\n"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min\n"}, {"source_code": "num_of_edge = gets\nedge_list = []\nwhile line = gets\n\tobj = {}\n\tobj[:start], obj[:dest], obj[:cost] = line.chomp.split.map{|s| s.to_i}\n\tedge_list << obj\nend\ncost_pair = [0,0]\nring_obj = edge_list.pop\ncost_pair[0] += ring_obj[:cost]\n\nwhile edge_list.length > 0\n\tdel_obj = edge_list.find{|obj|\n\t\tif obj[:start] == ring_obj[:dest]\n\t\t\tring_obj[:dest] = obj[:dest]\n\t\t\tcost_pair[0] += obj[:cost]\n\t\telsif obj[:dest] == ring_obj[:dest]\n\t\t\tcost_pair[1] += obj[:cost]\n\t\t\tring_obj[:dest] = obj[:start]\n\t\tend\n\t}\n\tedge_list.delete(del_obj)\nend\nputs cost_pair.min\n\n__END__\n6\n1 5 4\n5 3 8\n2 4 15\n1 6 16\n2 3 23\n4 6 42\n"}, {"source_code": "def dfs(u, g, used)\n used[u], result = true, 0\n g[u].each do |v, cost|\n result += cost + dfs(v, g, used) unless used[v]\n end\n result\nend\n\ndef solve(n, g)\n left, right = g[0]\n\n g[0] = [left]\n alpha = dfs(0, g, Array.new(n, false)) + g[right.first].assoc(0)[-1]\n\n g[0] = [right]\n beta = dfs(0, g, Array.new(n, false)) + g[left.first].assoc(0)[-1]\n\n [alpha, beta].min\nend\n\n\nn = gets.to_i\ng = Array.new(n) { [] }\n\nn.times do\n a, b, c = gets.split.map { |v| v.to_i }\n a -= 1\n b -= 1\n g[a] << [b, 0]\n g[b] << [a, c]\nend\n\nputs solve(n, g)\n"}, {"source_code": "def dfs(u, g, used)\n used[u] = true\n result = 0\n g[u].each do |v, cost|\n result += cost + dfs(v, g, used) unless used[v]\n end\n result\nend\n\ndef solve(n, g)\n left, right = g[0]\n\n g[0] = [left]\n alpha = dfs(0, g, Array.new(n, false)) + g[right.first].assoc(0)[-1]\n\n g[0] = [right]\n beta = dfs(0, g, Array.new(n, false)) + g[left.first].assoc(0)[-1]\n\n [alpha, beta].min\nend\n\n\nn = gets.to_i\ng = Array.new(n) { [] }\n\nn.times do\n a, b, c = gets.split.map { |v| v.to_i }\n a -= 1\n b -= 1\n g[a] << [b, 0]\n g[b] << [a, c]\nend\n\nputs solve(n, g)\n"}, {"source_code": "def dfs(u, g, used)\n used[u] = true\n result = 0\n g[u].each do |pair|\n v, cost = pair\n result += cost + dfs(v, g, used) if not used[v]\n end\n result\nend\n\ndef solve(n, g)\n first, last = g[0]\n\n g[0] = [first]\n alpha = dfs(0, g, Array.new(n, false)) + g[last.first].assoc(0)[-1]\n\n g[0] = [last]\n beta = dfs(0, g, Array.new(n, false)) + g[first.first].assoc(0)[-1]\n\n [alpha, beta].min\nend\n\n\nn = gets.to_i\ng = Array.new(n) { [] }\n\nn.times do\n a, b, c = gets.split.map { |v| v.to_i }\n a -= 1\n b -= 1\n g[a] << [b, 0]\n g[b] << [a, c]\nend\n\nputs solve(n, g)\n"}, {"source_code": "def gao(e, v, p)\n\te[v].map{|w, c| w == p ? 0 : c + gao(e, w, v)}.inject(&:+)\nend\n\nn = gets.to_i\ne = Array.new(n + 1){[]}\ny = 0\n(n - 1).times do\n\ta, b, c = gets.split.map(&:to_i)\n\te[a] << [b, 0]\n\te[b] << [a, c]\n\ty += c\nend\na, b, c = gets.split.map(&:to_i)\nx = gao(e, a, -1)\np [x + c, y - x].min\n"}, {"source_code": "n=gets.to_i\ng=Array.new(n){[]}\nn.times{\n input=gets.split.map(&:to_i)\n a=input[0]-1\n b=input[1]-1\n c=input[2]\n g[a].push([a,b,c])\n g[b].push([a,b,c])\n}\nres=[]\nfor q in 0..1\n cost=0\n v=g[0][q][1]\n if v==0 then\n cost+=g[0][q][2]\n v=g[0][q][0]\n end\n back=g[0][q]\n loop do\n if v==0 then\n break\n end\n for i in 0..1\n if g[v][i]!=back then\n back=g[v][i]\n if g[v][i][1]==v then\n cost+=g[v][i][2]\n v=g[v][i][0]\n else\n v=g[v][i][1]\n end\n break\n end\n end\n end\n res.push(cost)\nend\nputs res.min"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min\n"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min\n"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min"}, {"source_code": "h=Array.new(gets.to_i){[]}\nwhile gets\na,b,c=$_.split.map &:to_i\nh[a-1]<<[b-1,0]\nh[b-1]<<[a-1,c]\nend\np h[0].map{|a,s|x=0\nwhile a>0\nh[a].map{|b,c|if b!=x\na,x=b,a\ns+=c\nbreak\nend}\nend\ns}.min\n"}], "negative_code": [{"source_code": "num_of_edge = gets.to_i\nedge_list = []\nring_hash = Hash.new\nwhile line = gets\n\tobj = {}\n\tobj[:start], obj[:dest], obj[:cost] = line.chomp.split.map{|s| s.to_i}\n\tedge_list << obj\nend\n\nedge_list.each{|obj|\n\tif !ring_hash.include?(obj[:start])\n\t\tring_hash[ obj[:start] ] = obj[:dest]\n\t\tobj[:clock_wise] = true\n\telse\n\t\tring_hash[ obj[:dest] ] = obj[:start]\n\tend\n}\nputs [ edge_list.select{|obj| obj[:clock_wise] }.inject(0){|sum, obj| sum += obj[:cost] } , edge_list.select{|obj| !obj[:clock_wise] }.inject(0){|sum, obj| sum += obj[:cost] } ].min\n"}, {"source_code": "num_of_edge = gets.to_i\nedge_list = []\nclock_wise_edge_list = []\nnon_clock_wise_edge_list = []\nring_hash = Hash.new\nwhile line = gets\n\tobj = {}\n\tobj[:start], obj[:dest], obj[:cost] = line.chomp.split.map{|s| s.to_i}\n\tedge_list << obj\nend\nedge_list.each{|obj|\n\tif !ring_hash.include?(obj[:start])\n\t\tring_hash[ obj[:start] ] = obj[:dest]\n\t\tclock_wise_edge_list << obj\n\telse\n\t\tring_hash[ obj[:dest] ] = obj[:start]\n\t\tnon_clock_wise_edge_list << obj\n\tend\n}\nputs [ clock_wise_edge_list.inject(0){|sum, obj| sum += obj[:cost] } , non_clock_wise_edge_list.select{|obj| !obj[:clock_wise?] }.inject(0){|sum, obj| sum += obj[:cost] } ].min\n"}, {"source_code": "num_of_edge = gets.to_i\nedge_list = []\nring_hash = Hash.new\nwhile line = gets\n\tobj = {}\n\tobj[:start], obj[:dest], obj[:cost] = line.chomp.split.map{|s| s.to_i}\n\tedge_list << obj\nend\nedge_list.each{|obj|\n\tif ring_hash.value?(obj[:start])\n\t\tring_hash[ obj[:start] ] = obj[:dest]\n\telsif ring_hash.key?(obj[:start])\n\t\tring_hash[ obj[:dest] ] = obj[:start]\n\t\tobj[:reverse] = true\n\telse\n\t\tring_hash[ obj[:start] ] = obj[:dest]\n\tend\n}\nputs [ edge_list.select{|obj| obj[:reverse] }.inject(0){|sum, obj| sum += obj[:cost] } , edge_list.select{|obj| !obj[:reverse] }.inject(0){|sum, obj| sum += obj[:cost] } ].min\n"}, {"source_code": "gets\nedge_list = []\nring_hash = Hash.new\nwhile line = gets\n\tobj = {}\n\tobj[:start], obj[:dest], obj[:cost] = line.chomp.split.map{|s| s.to_i}\n\tedge_list << obj\nend\nedge_list.each{|obj|\n\tif !ring_hash.include?(obj[:start])\n\t\tring_hash[ obj[:start] ] = obj[:dest]\n\t\tobj[:clock_wise?] = true\n\telse\n\t\tring_hash[ obj[:dest] ] = obj[:start]\n\tend\n}\nputs [ edge_list.select{|obj| obj[:clock_wise?] }.inject(0){|sum, obj| sum += obj[:cost] } , edge_list.select{|obj| !obj[:clock_wise?] }.inject(0){|sum, obj| sum += obj[:cost] } ].min\n"}], "src_uid": "d85c7a8f7e6f5fc6dffed554bffef3ec"} {"source_code": "#!/usr/bin/env ruby\n\na = gets.strip.split /[,;]/, -1\nb, c = a.partition { |x| x[/^(0|[1-9]\\d*)$/] }\nputs b.empty? ? '-' : ('\"' + b.join(',') + '\"')\nputs c.empty? ? '-' : ('\"' + c.join(',') + '\"')\n", "positive_code": [{"source_code": "puts gets.chomp.tr(';',',').split(',',-1).partition{|e|e=~/^-?([1-9][0-9]*|0)$/}.map{|e|e.empty? ? '-' : '\"'+e*','+'\"'}"}, {"source_code": "#!/usr/bin/env ruby\n\na = gets.strip.split /[,;]/, -1\nb, c = a.partition { |x| x[/^(0|[1-9]\\d*)$/] }\nputs b.empty? ? '-' : ('\"' + b.join(',') + '\"')\nputs c.empty? ? '-' : ('\"' + c.join(',') + '\"')"}, {"source_code": "puts gets.chomp.tr(';',',').split(',',-1).partition{|e|e=~/^-?([1-9][0-9]*|0)$/}.map{|e|e.empty? ? '-' : '\"'+e*','+'\"'}"}, {"source_code": "puts gets.chomp.tr(';',',').split(',',-1).partition{|e|e=~/^-?([1-9][0-9]*|0)$/}.map{|e|e.empty? ? '-' : '\"'+e*','+'\"'}"}, {"source_code": "s = gets.chomp.split(/[,;]/, -1)\nnumber = []\nnonnumber = []\ns.each do |w|\n if w.match(/^[0-9]+$/) then\n if w.length >= 2 and w[0] == \"0\" then\n nonnumber << w\n else\n number << w\n end\n else\n nonnumber << w\n end\nend\nif number.length == 0 then\n puts \"-\"\nelse\n p number.join(\",\")\nend\nif nonnumber.length == 0 then\n puts \"-\"\nelse\n p nonnumber.join(\",\")\nend\n"}, {"source_code": "str = gets\nwords = str.split(/,|;/)\nwords[words.length-1] = words[words.length-1][0...words[words.length-1].length-1]\nnums = []\nothers = []\nwords.each do |word|\n\tif word.to_i.to_s == word\n\t\tnums.push(word)\n\telse\n\t\tothers.push(word)\n\tend\t\t\nend\nif nums.empty?\n\tputs \"-\"\nelse \n\tputs \"\\\"#{nums.join(',')}\\\"\"\nend\nif others.empty?\n\tputs \"-\"\nelse\n\tputs \"\\\"#{others.join(',')}\\\"\"\nend"}], "negative_code": [{"source_code": "puts gets.chomp.tr(';',',').split(',').partition{|e|e=~/^-?([1-9][0-9]*|0)$/}.map{|e|e.empty? ? '-' : e*','}"}, {"source_code": "puts gets.chomp.tr(';',',').split(',').partition{|e|e=~/^-?([1-9][0-9]*|0)$/}.map{|e|e.empty? ? '-' : '\"'+e*','+'\"'}"}, {"source_code": "str = gets\nstr = str[0...str.length-1]\nwords = str.split(/,|;/)\nnums = []\nothers = []\nwords.each do |word|\n\tif word.to_i.to_s == word\n\t\tnums.push(word)\n\telse\n\t\tothers.push(word)\n\tend\t\t\nend\nif nums.empty?\n\tputs \"-\"\nelse \n\tputs \"\\\"#{nums.join(',')}\\\"\"\nend\nif others.empty?\n\tputs \"-\"\nelse\n\tputs \"\\\"#{others.join(',')}\\\"\"\nend"}], "src_uid": "ad02cead427d0765eb642203d13d3b99"} {"source_code": "1.upto(gets.to_i) do\n n = gets.to_i\n\n if n == 1\n puts -1\n next\n end\n\n if (2*(n-1) + 3).modulo(3).zero?\n puts '2' * (n-2) + '33'\n else\n puts '2' * (n-1) + '3'\n end\nend\n", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n\n if n == 1\n puts -1\n else\n puts '2' + '3' * (n - 1)\n end\nend\n"}, {"source_code": "def main\n t = gets.chomp.to_i\n t.times { solve }\nend\n\ndef solve\n n = gets.chomp.to_i\n # a, b, c = gets.chomp.split.map(&:to_i)\n # S = gets.chomp.chars\n # p n\n # p [a, b, c]\n if n == 1\n p(-1)\n else\n ans = \"5\" * (n-1)\n ans += \"4\"\n print (ans + \"\\n\")\n end\nend\n\nmain\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n if n == 1\n puts -1\n else\n case n % 3\n when 0\n puts \"2\" * (n - 1) + \"3\"\n when 1\n puts \"2\" * (n - 2) + \"33\"\n when 2\n puts \"2\" * (n - 1) + \"3\"\n end\n end\nend\n"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1326/A\n\nn = gets.to_i\n\nn.times do\n a = gets.to_i\n\n if a == 1\n puts '-1'\n else\n puts ('9' * (a - 1) + '8')\n end\nend\n"}], "negative_code": [{"source_code": "def main\n t = gets.chomp.to_i\n t.times { solve }\nend\n\ndef solve\n n = gets.chomp.to_i\n # a, b, c = gets.chomp.split.map(&:to_i)\n # S = gets.chomp.chars\n # p n\n # p [a, b, c]\n if n == 1\n p(-1)\n else\n ans = \"2\" * (n-1)\n ans += \"9\"\n print (ans + \"\\n\")\n end\nend\n\nmain\n"}], "src_uid": "43996d7e052aa628a46d03086f9c5436"} {"source_code": "gets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n xxs = n.times.map { gets.chomp }\r\n i, j = xxs.filter_map.with_index do |xs, i|\r\n if j = xs.index(\"R\")\r\n [i, j]\r\n end\r\n end.first\r\n if xxs[...i].join.include?(\"R\") || xxs.map { |xs| xs[...j] }.join.include?(\"R\")\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\nend\r\n", "positive_code": [{"source_code": "def solve(n,m,a)\n 0.upto(n-1) do |i|\n 0.upto(m-1) do |j|\n if a[i][j] == 'R' then\n c = 0\n 0.upto(n-1) do |k|\n 0.upto(m-1) do |l|\n if a[k][l] == 'R' and ((k 0 && even > 0 ? \"YES\" : \"NO\"\n\tend\nend"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nt = gets.to_i\nt.times {\n n = gets.to_i\n a = gets.split.map(&:to_i)\n evens, odds = a.count(&:even?), a.count(&:odd?)\n if odds.odd?\n puts \"YES\"\n else\n if evens > 0 && odds > 0\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\n}"}, {"source_code": "1.upto(gets.to_i) do\n gets\n a = gets.split(' ').map(&:to_i)\n\n result = a.inject(&:+).odd? || (a.any?(&:odd?) && a.any?(&:even?))\n\n puts result ? 'YES' : 'NO'\nend\n"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nt = gets.to_i\nt.times {\n n = gets.to_i\n a = gets.split.map(&:to_i)\n evens, odds = a.count(&:even?), a.count(&:odd?)\n if odds.odd?\n puts \"YES\"\n else\n puts \"NO\"\n end\n}"}], "src_uid": "2e8f7f611ba8d417fb7d12fda22c908b"} {"source_code": "#Infinity\n#geti,getia\n#Object # dcopy\n#\n#String # to_a\n# \"abc\".to_a #=> [\"a\",\"b\",\"c\"]\n#String # to_ia\n# \"1 2 3\".to_ia #=> [1,2,3]\n#\n#Array # rsort,rsort!\n# [1,3,2,4].rsort #=> [4,3,2,1]\n#\n#Integer # divisor\n# 24.divisor #=> [1,2,3,4,6,8,12,24]\n#\ninclude Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInfinity = 1/0.0\nclass Matrix;def inspect;empty? ? \"Matrix.empty(#{row_size}, #{column_size})\":\"Matrix[\\n#{@rows.map(&:inspect).join(\"\\n\")}\\n]\";end;end\ndef pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end\nclass String;def to_a;split(\"\");end;end\nclass String;def to_ia;split.map(&:to_i);end;end\ndef getia;gets.to_ia;end\ndef geti;gets.to_i;end\nclass Object;def dcopy;Marshal.load(Marshal.dump(self));end;end\nclass Array;def rsort;sort.reverse;end;def rsort!;sort!.reverse!;end;end\n\nn = geti\npx = []\npy = []\nres = 0\nn.times{\n p = getia\n res += (p[0]**2 + p[1]**2) * (n - 1)\n px.push p[0]\n py.push p[1]\n}\nxs = px.inject(&:+)\nxx = 0\npx.each{|x| xx += x * (xs - x) }\nys = py.inject(&:+)\nyy = 0\npy.each{|y| yy += y * (ys - y) }\n\np res - xx - yy\n", "positive_code": [{"source_code": "def solve(x,n)\n sum=0\n ans=0\n x.each{|i| sum+=i}\n x.each{|i|\n ans+=(n-1)*i*i-(sum-i)*i\n }\n ans\nend\n\nn=gets.to_i\nx=Array.new(n,0)\ny=Array.new(n,0)\nn.times{|i|\n input=gets.split.map(&:to_i)\n x[i]=input[0]\n y[i]=input[1]\n}\n\np solve(x,n)+solve(y,n)\n"}, {"source_code": "n=gets.to_i\nsigx1,sigx2,sigy1,sigy2=[0,0,0,0]\nn.times do\n a,b=gets.split.map(&:to_i)\n sigx1+=a\n sigx2+=a*a\n sigy1+=b\n sigy2+=b*b\nend\np n*(sigx2+sigy2)-sigx1**2-sigy1**2"}], "negative_code": [], "src_uid": "9bd6fea892857d7c94ebce4d4cd46d30"} {"source_code": "n = gets.to_i\na = ['C', '.']\ns = []\n(n / 2 + 1).times do\n s << a\nend\ns = s.join(\"\").chars\nputs (n * n + 1) / 2\nn.times do |i|\n puts s[(i % 2)...(i % 2 + n)].join(\"\")\nend\n", "positive_code": [{"source_code": "n = gets.chomp().to_i\nif (n % 2 == 0)\n\tputs(n*n/2)\nelse\n\tputs((n-1)*n/2 + (n+1)/2)\nend\nfor i in 1..n\n\tfor j in 1..n\n\t\tif i%2 == j%2\n\t\t\tprint 'C' \n\t\telse\n\t\t\tprint '.'\n\t\tend\n\tend\n\tputs\nend"}, {"source_code": "n = gets.to_i\nres = n ** 2 / 4 + (n + 1) / 2 * (n / 2)\nputs n.even? ? res : res + 1\nn.times do |i|\n if i.even?\n puts (\"C.\" * ((n + 1) / 2)).slice(0..n - 1)\n else\n puts (\".C\" * ((n + 1) / 2)).slice(0..n - 1)\n end\nend\n"}, {"source_code": "n = gets.to_i\n\nans = []\nn.times do |i|\n if i.even?\n ans << \"C.\" * (n/2) + \"C\" * (n%2)\n else\n ans << \".C\" * (n/2) + \".\" * (n%2)\n end\nend\nputs n ** 2 / 2 + n % 2\nputs ans"}, {"source_code": "n=gets.to_i\nif n%2==0 then\n\tputs n/2*n\nelse\n\tputs n*(n/2)+(n/2+1)\nend\n\nn.times{|i|\n\tn.times{|j|\n\t\tif (i+j)%2==0 then\n\t\t\tprint \"C\"\n\t\telse\n\t\t\tprint \".\"\n\t\tend\n\t}\n\tputs \"\"\n}\n\n"}, {"source_code": "n = STDIN.gets.to_i\nv1 = (n.to_f / 2).floor\nv2 = (n.to_f / 2).ceil\nputs v1*v1 + v2*v2\nlineCoder = true\n(0...n).each do\n colCoder = lineCoder\n (0...n).each do\n print(colCoder ? 'C' : '.')\n colCoder = !colCoder\n end\n puts\n lineCoder = !lineCoder\nend"}, {"source_code": "n = gets.to_i\nans = Array.new(n) {Array.new(n) {'.'}}\ncount = 0\nn.times do |i|\n n.times do |j|\n if (i+j)%2==0\n ans[i][j] = 'C'\n count+=1\n end\n end\nend\np count\nans.each{|x| puts x.join('')}"}, {"source_code": "n = gets.to_i\nputs ((n + 1)/2)**2 + (n/2)**2\nn.times do |i|\n n.times do |j|\n print i%2 == j%2 ? 'C' : '.'\n end\n puts\nend\n"}, {"source_code": "n=gets.to_i\ns=[]\ns[0]='C.'*(n/2)+(n%2==1?'C':'')\ns[1]=('.'+s[0])[0..-2]\na=s.map{|x|x.count('C')}\nc=0\nn.times do |i|\n c+=a[i%2]\nend\nputs c\nn.times do |i|\n puts s[i%2]\nend\n\n"}, {"source_code": "n = gets.chomp.to_i\n\nnumber = 0\t\t\n\n(0...n).each do |row|\n\t(0...n).each do |col|\n\t\tif row % 2 == 0\n\t\t\tnumber += 1 if col % 2 == 0\n\t\telse\n\t\t\tnumber += 1 if col % 2 == 1\n\t\tend\n\tend\nend\n\nputs number\n\n(0...n).each do |row|\n\t(0...n).each do |col|\n\t\tif row % 2 == 0\n\t\t\tprint 'C' if col % 2 == 0\n\t\t\tprint '.' if col % 2 == 1\n\t\telse\n\t\t\tprint 'C' if col % 2 == 1\n\t\t\tprint '.' if col % 2 == 0\n\t\tend\n\tend\n\n\tputs ''\nend"}, {"source_code": "n = gets.to_i\nputs (n*n+1)/2\n(1..n).each_with_index do |x,id|\n if x % 2 == 1\n puts \"C.\" * (n/2) + \"C\" * (n%2)\n else\n puts \".C\" * (n/2) + \".\" * (n%2)\n end\nend"}, {"source_code": "n = gets.to_i\ndx = Array.new(n).map{|v| v = Array.new(n, 0)}\nfor i in 0...n do\n for j in 0...n do\n if i % 2 == 0\n dx[i][j] = (j % 2 == 0 ? \"C\" : \".\")\n else\n dx[i][j] = (j % 2 == 0 ? \".\" : \"C\")\n end\n end\nend\ncnt = 0\nfor i in 0...n do\n for j in 0...n do\n cnt += 1 if dx[i][j] == 'C'\n end\nend\nputs cnt\nfor i in 0...n do\n puts dx[i].join()\nend\n"}, {"source_code": "n = STDIN.gets.to_i\nv1 = (n.to_f / 2).floor\nv2 = (n.to_f / 2).ceil\nputs v1*v1 + v2*v2\nlineCoder = true\n(0...n).each do\n colCoder = lineCoder\n (0...n).each do\n print(colCoder ? 'C' : '.')\n colCoder = !colCoder\n end\n puts\n lineCoder = !lineCoder\nend\n"}], "negative_code": [{"source_code": "n = gets.to_i\ndx = Array.new(n).map{|v| v = Array.new(n, 0)}\nfor i in 0...n do\n for j in 0...n do\n if i % 2 == 0\n dx[i][j] = (j % 2 == 0 ? \"C\" : \".\")\n else\n dx[i][j] = (j % 2 == 0 ? \".\" : \"C\")\n end\n end\nend\ncnt = 0\nfor i in 0...n do\n for i in 0...n do\n cnt += 1 if dx[i][j] == 'C'\n end\nend\nputs cnt\nfor i in 0...n do\n puts dx[i].join()\nend\n"}, {"source_code": "n = STDIN.gets.to_i\nv1 = (n / 2).floor\nv2 = (n / 2).ceil\nputs v1*v1 + v2*v2\nline_coder = true\n(0...n).each do\n col_coder = line_coder\n (0...n).each do\n print(col_coder ? 'C' : '.')\n col_coder = !col_coder\n end\n puts\n line_coder = !line_coder\nend\n"}, {"source_code": "n = gets.to_i\nn.times do |i|\n if i.even?\n puts (\"C.\" * ((n + 1) / 2)).slice(0..n - 1)\n else\n puts (\".C\" * ((n + 1) / 2)).slice(0..n - 1)\n end\nend\n"}, {"source_code": "n=gets.to_i\nputs n\nn.times{|i|\n\tn.times{|j|\n\t\tif i==j then\n\t\t\tprint \"C\"\n\t\telse\n\t\t\tprint \".\"\n\t\tend\n\t}\n\tputs \"\"\n}"}, {"source_code": "n = gets.to_i\nans = Array.new(n) {Array.new(n) {'.'}}\nn.times do |i|\n n.times do |j|\n if (i+j)%2==0\n ans[i][j] = 'C'\n end\n end\nend\nans.each{|x| puts x.join('')}\n"}, {"source_code": "n = gets.chomp.to_i\n\nif n == 1\n\tputs \"1\"\nend\n\n\nnumber = 0\t\t\n\n(0...n).each do |row|\n\t(0...n).each do |col|\n\t\tif row % 2 == 0\n\t\t\tnumber += 1 if col % 2 == 0\n\t\telse\n\t\t\tnumber += 1 if col % 2 == 1\n\t\tend\n\tend\nend\n\nputs number\n\n(0...n).each do |row|\n\t(0...n).each do |col|\n\t\tif row % 2 == 0\n\t\t\tprint 'C' if col % 2 == 0\n\t\t\tprint '.' if col % 2 == 1\n\t\telse\n\t\t\tprint 'C' if col % 2 == 1\n\t\t\tprint '.' if col % 2 == 0\n\t\tend\n\tend\n\n\tputs ''\nend"}, {"source_code": "n = gets.to_i\n(1..n).each_with_index do |x,id|\n if x % 2 == 1\n puts \"C.\" * (n/2) + \"C\" * (n%2)\n else\n puts \".C\" * (n/2) + \".\" * (n%2)\n end\nend"}], "src_uid": "1aede54b41d6fad3e74f24a6592198eb"} {"source_code": "a = b = 0\nputs \"? 0 0\"\nSTDOUT.flush\ns = gets.to_i\nl = s > 0 ? true : false\nf = false\nf = true if s == 0\n29.downto(0) do |i|\n break if f\n puts \"? #{a + (1 << i)} #{b + (1 << i)}\"\n STDOUT.flush\n s = gets.to_i\n if s == 0\n f = true\n elsif ((s == -1) && l) || ((s == 1) && !l)\n if s == -1\n a += 1 << i\n else\n b += 1 << i\n end\n puts \"? #{a} #{b}\"\n STDOUT.flush\n s = gets.to_i\n l = s > 0 ? true : false\n f = true if s == 0\n end\nend\n29.downto(0) do |i|\n next if a[i] == 1 || b[i] == 1\n puts \"? #{a} #{b+(1 << i)}\"\n STDOUT.flush\n s = gets.to_i\n if (s == 1)\n a += 1 << i\n b += 1 << i\n end\nend\nputs \"! #{a} #{b}\"", "positive_code": [{"source_code": "ahyp = \"X\"*30\nbhyp = \"X\"*30\ncheckedi = 0\n\nputs \"? \" + \"0\" + \" \" + \"0\"\nSTDOUT.flush\nans = gets.chomp.to_i\n\nif ans==1\n aisgreater = true\n theyareequal = false\nelsif ans==-1\n aisgreater = false\n theyareequal = false\nelse\n aisgreater = false\n theyareequal = true\nend \n\npreva = \"\"\nprevb = \"\"\n\n61.times do\n\n# p ahyp\n# p bhyp\n\n if aisgreater and not theyareequal\n puts \"? \" + (preva+\"1\"+\"0\"*(29-checkedi)).to_i(2).to_s + \" \" + (prevb+\"0\"+\"0\"*(29-checkedi)).to_i(2).to_s\n STDOUT.flush\n res = gets.to_i\n\n if res==1\n puts \"? \" + (preva+\"0\"+\"0\"*(29-checkedi)).to_i(2).to_s + \" \" + (prevb+\"1\"+\"0\"*(29-checkedi)).to_i(2).to_s\n STDOUT.flush\n newres = gets.to_i\n\n if newres ==1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"0\"\n aisgreater = true\n #ALAT > BLAT\n elsif newres==-1\n ahyp[checkedi] = \"0\"\n bhyp[checkedi] = \"0\"\n aisgreater = true\n #ALAT > BLAT\n end\n elsif res==-1\n puts \"? \" + (preva+\"0\"+\"0\"*(29-checkedi)).to_i(2).to_s + \" \" + (prevb+\"1\"+\"0\"*(29-checkedi)).to_i(2).to_s\n STDOUT.flush\n newres = gets.to_i\n\n if newres ==1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = true\n #ALAT>BLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"0\"\n aisgreater = false\n #ALATBLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = false\n #ALAT 0 ? true : false\nf = false\nf = true if s == 0\n30.downto(0) do |i|\n break if f\n puts \"? #{a + (1 << i)} #{b + (1 << i)}\"\n STDOUT.flush\n s = gets.to_i\n if s == 0\n f = true\n elsif ((s == -1) && l) || ((s == 1) && !l)\n if s == -1\n a += 1 << i\n else\n b += 1 << i\n end\n puts \"? #{a} #{b}\"\n STDOUT.flush\n s = gets.to_i\n l = s > 0 ? true : false\n f = true if s == 0\n end\nend\n30.downto(0) do |i|\n next if a[i] == 1 || b[i] == 1\n puts \"? #{a} #{b+(1 << i)}\"\n STDOUT.flush\n s = gets.to_i\n if (s == 1)\n a += 1 << i\n b += 1 << i\n end\nend\nputs \"! #{a} #{b}\""}, {"source_code": "a = b = 0\nputs \"? 0 0\"\nSTDOUT.flush\ns = gets.to_i\nl = s > 0 ? true : false\nf = false\nf = true if s == 0\n30.downto(0) do |i|\n break if f\n puts \"? #{a + (1 << i)} #{b + (1 << i)}\"\n STDOUT.flush\n s = gets.to_i\n if s == 0\n f = true\n elsif (s == -1) && l\n a += 1 << i\n puts \"? #{a} #{b}\"\n STDOUT.flush\n s = gets.to_i\n l = s > 0 ? true : false\n f = true if s == 0\n elsif (s == 1) && !l\n b += 1 << i\n end\nend\n30.downto(0) do |i|\n next if a[i] == 1 || b[i] == 1\n puts \"? #{a} #{b+(1 << i)}\"\n STDOUT.flush\n s = gets.to_i\n if (s == 1)\n a += 1 << i\n b += 1 << i\n end\nend\nputs \"! #{a} #{b}\""}, {"source_code": "ahyp = \"X\"*30\nbhyp = \"X\"*30\ncheckedi = 0\n\nputs \"? \" + \"0\" + \" \" + \"0\"\nSTDOUT.flush\nans = gets.chomp.to_i\n\nif ans==1\n aisgreater = true\n theyareequal = true\nelsif ans==-1\n aisgreater = false\n theyareequal = true\nelse\n aisgreater = false\n theyareequal = true\nend \n\npreva = \"\"\nprevb = \"\"\n\n61.times do\n\n if aisgreater and not theyareequal\n puts \"? \" + (preva+\"1\"+\"0\"*(29-checkedi)).to_i(2).to_s + \" \" + (prevb+\"0\"+\"0\"*(29-checkedi)).to_i(2).to_s\n STDOUT.flush\n res = gets.to_i\n\n if res==1\n puts \"? \" + (preva+\"0\"+\"0\"*(29-checkedi)).to_i(2).to_s + \" \" + (prevb+\"1\"+\"0\"*(29-checkedi)).to_i(2).to_s\n STDOUT.flush\n newres = gets.to_i\n\n if newres ==1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"0\"\n aisgreater = true\n #ALAT > BLAT\n elsif newres==-1\n ahyp[checkedi] = \"0\"\n bhyp[checkedi] = \"0\"\n aisgreater = true\n #ALAT > BLAT\n end\n elsif res==-1\n if newres ==1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = true\n #ALAT>BLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"0\"\n aisgreater = false\n #ALATBLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = false\n #ALAT BLAT\n elsif newres==-1\n ahyp[checkedi] = \"0\"\n bhyp[checkedi] = \"0\"\n aisgreater = true\n #ALAT > BLAT\n end\n elsif res==-1\n puts \"? \" + (preva+\"0\"+\"0\"*(29-checkedi)).to_i(2).to_s + \" \" + (prevb+\"1\"+\"0\"*(29-checkedi)).to_i(2).to_s\n STDOUT.flush\n newres = gets.to_i\n\n if newres ==1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = true\n #ALAT>BLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"0\"\n aisgreater = false\n #ALATBLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = false\n #ALAT BLAT\n elsif newres==-1\n ahyp[checkedi] = \"0\"\n bhyp[checkedi] = \"0\"\n aisgreater = true\n #ALAT > BLAT\n end\n elsif res==-1\n puts \"? \" + (preva+\"0\"+\"0\"*(29-checkedi)).to_i(2).to_s + \" \" + (prevb+\"1\"+\"0\"*(29-checkedi)).to_i(2).to_s\n STDOUT.flush\n newres = gets.to_i\n\n if newres ==1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = true\n #ALAT>BLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"0\"\n aisgreater = false\n #ALATBLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = false\n #ALAT BLAT\n elsif newres==-1\n ahyp[checkedi] = \"0\"\n bhyp[checkedi] = \"0\"\n aisgreater = true\n #ALAT > BLAT\n end\n elsif res==-1\n puts \"? \" + (preva+\"0\"+\"0\"*(29-checkedi)).to_i(2).to_s + \" \" + (prevb+\"1\"+\"0\"*(29-checkedi)).to_i(2).to_s\n STDOUT.flush\n newres = gets.to_i\n\n if newres ==1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = true\n #ALAT>BLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"0\"\n aisgreater = false\n #ALATBLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = false\n #ALAT BLAT\n elsif newres==-1\n ahyp[checkedi] = \"0\"\n bhyp[checkedi] = \"0\"\n aisgreater = true\n #ALAT > BLAT\n end\n elsif res==-1\n puts \"? \" + (preva+\"0\"+\"0\"*(29-checkedi)).to_i(2).to_s + \" \" + (prevb+\"1\"+\"0\"*(29-checkedi)).to_i(2).to_s\n STDOUT.flush\n newres = gets.to_i\n\n if newres ==1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = true\n #ALAT>BLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"0\"\n aisgreater = false\n #ALATBLAT\n elsif newres==-1\n ahyp[checkedi] = \"1\"\n bhyp[checkedi] = \"1\"\n aisgreater = false\n #ALAT (x, y) { (y % 10) <=> (x % 10) }\na = gets.split.map(&:to_i).sort(&cmp).map do |x|\n if x % 10 == 0 || k == 0\n x\n else\n d = [10 - x % 10, k].min\n k -= d\n x += d\n end\nend\nans = 0\na.each do |y|\n d = [100 - y, k].min\n k -= d\n ans += (y + d) / 10\nend\nputs ans\n=end\n\n# D\nx, y, c = [0] * 3, [0] * 3, ['A', 'B', 'C']\nx[0], y[0], x[1], y[1], x[2], y[2] = gets.split.map(&:to_i)\nx_y_c, s = [], 0\n3.times do |i|\n s += x[i] * y[i]\n x_y_c << ([x[i], y[i]].sort.reverse + [c[i]])\nend\nx_y_c.sort!.reverse!\na = b = x_y_c[0][0]\nif a ** 2 != s\n puts -1\nelse\n puts a\n # a == x_y_c[0][0]\n x_y_c[0][1].times { puts x_y_c[0][2] * a }\n b -= x_y_c[0][1]\n if x_y_c[1][0] == b # b == x_y_c[2][0] && a == x_y_c[1][1] + x_y_c[2][1]\n b.times { puts x_y_c[1][2] * x_y_c[1][1] + x_y_c[2][2] * x_y_c[2][1] }\n else\n if x_y_c[1][0] == a # a == x_y_c[2][0] && b == x_y_c[1][1] + x_y_c[2][1]\n x_y_c[1][1].times { puts x_y_c[1][2] * a }\n x_y_c[2][1].times { puts x_y_c[2][2] * a }\n else # b == x_y_c[1][1]\n b.times { puts x_y_c[1][2] * x_y_c[1][0] + x_y_c[2][2] * (a - x_y_c[1][0]) }\n end\n end\nend\n", "positive_code": [{"source_code": "\ufeff# Codeforces Round\n\n=begin\n# A\na, b = gets.split.map(&:to_i)\nc, d = [a, b].min, [a, b].max\nputs \"#{[a, b].min} #{(a - b).abs / 2}\"\n\n# B\nn = gets.to_i\nh = gets.split.map(&:to_i)\nm, a = [0] * (n - 1) + [h[n - 1]], [0] * n\n(n - 2).downto(0) do |i|\n if h[i] <= m[i + 1]\n m[i] = m[i + 1]\n a[i] = m[i] - h[i] + 1\n else\n m[i] = h[i]\n end\nend\nputs a.join(' ')\n\n# C\nn, k = gets.split.map(&:to_i)\ncmp = -> (x, y) { (y % 10) <=> (x % 10) }\na = gets.split.map(&:to_i).sort(&cmp).map do |x|\n if x % 10 == 0 || k == 0\n x\n else\n d = [10 - x % 10, k].min\n k -= d\n x += d\n end\nend\nans = 0\na.each do |y|\n d = [100 - y, k].min\n k -= d\n ans += (y + d) / 10\nend\nputs ans\n=end\n\n# D\nx, y, c = [0] * 3, [0] * 3, ['A', 'B', 'C']\nx[0], y[0], x[1], y[1], x[2], y[2] = gets.split.map(&:to_i)\nx_y_c, s = [], 0\n3.times do |i|\n s += x[i] * y[i]\n x_y_c << ([x[i], y[i]].sort.reverse + [c[i]])\nend\nx_y_c.sort!.reverse!\n#p x_y_c\na = b = x_y_c[0][0]\nif a ** 2 != s\n puts -1\nelse\n puts a\n x_y_c[0][1].times { puts x_y_c[0][2] * a }\n b -= x_y_c[0][1]\n if x_y_c[1][0] == b # b == x_y_c[2][0] && a == x_y_c[1][1] + x_y_c[2][1]\n b.times { puts x_y_c[1][2] * x_y_c[1][1] + x_y_c[2][2] * x_y_c[2][1] }\n else # b == x_y_c[1][1] + x_y_c[2][1] && a == x_y_c[1][0] && a == x_y_c[2][0]\n if x_y_c[1][0] == a # a == x_y_c[2][0] && b == x_y_c[1][1] + x_y_c[2][1]\n x_y_c[1][1].times { puts x_y_c[1][2] * x_y_c[1][0] }\n x_y_c[2][1].times { puts x_y_c[2][2] * x_y_c[2][0] }\n else # b == x_y_c[1][1]\n x_y_c[1][1].times { puts x_y_c[1][2] * x_y_c[1][0] + x_y_c[2][2] * (a - x_y_c[1][0]) }\n end\n end\n \n #b.times do\n # [1, 2].each do |j|\n # #z = x_y_c[j][0] == b ? x_y_c[j][1] : x_y_c[j][]\n # print (x_y_c[j][0] == b ? x_y_c[j][2] * x_y_c[j][1] : x_y_c[j][2] * x_y_c[j][0])\n # end\n # puts\n #end\nend\n"}], "negative_code": [{"source_code": "\ufeff# Codeforces Round\n\n=begin\n# A\na, b = gets.split.map(&:to_i)\nc, d = [a, b].min, [a, b].max\nputs \"#{[a, b].min} #{(a - b).abs / 2}\"\n\n# B\nn = gets.to_i\nh = gets.split.map(&:to_i)\nm, a = [0] * (n - 1) + [h[n - 1]], [0] * n\n(n - 2).downto(0) do |i|\n if h[i] <= m[i + 1]\n m[i] = m[i + 1]\n a[i] = m[i] - h[i] + 1\n else\n m[i] = h[i]\n end\nend\nputs a.join(' ')\n\n# C\nn, k = gets.split.map(&:to_i)\ncmp = -> (x, y) { (y % 10) <=> (x % 10) }\na = gets.split.map(&:to_i).sort(&cmp).map do |x|\n if x % 10 == 0 || k == 0\n x\n else\n d = [10 - x % 10, k].min\n k -= d\n x += d\n end\nend\nans = 0\na.each do |y|\n d = [100 - y, k].min\n k -= d\n ans += (y + d) / 10\nend\nputs ans\n=end\n\n# D\nx, y, c = [0] * 3, [0] * 3, ['A', 'B', 'C']\nx[0], y[0], x[1], y[1], x[2], y[2] = gets.split.map(&:to_i)\nx_y_c, s = [], 0\n3.times do |i|\n s += x[i] * y[i]\n x_y_c << ([x[i], y[i]].sort.reverse + [c[i]])\nend\nx_y_c.sort!.reverse!\n#p x_y_c\na = b = x_y_c[0][0]\nif a ** 2 != s\n puts -1\nelse\n puts a\n x_y_c[0][1].times { puts x_y_c[0][2] * a }\n b -= x_y_c[0][1]\n if x_y_c[1][0] == b # b == x_y_c[2][0]\n b.times { puts x_y_c[1][2] * x_y_c[1][1] + x_y_c[2][2] * x_y_c[2][1] }\n else # b == x_y_c[1][1] + x_y_c[2][1]\n x_y_c[1][1].times { puts x_y_c[1][2] * x_y_c[1][0] }\n x_y_c[2][1].times { puts x_y_c[2][2] * x_y_c[2][0] }\n end\n \n #b.times do\n # [1, 2].each do |j|\n # #z = x_y_c[j][0] == b ? x_y_c[j][1] : x_y_c[j][]\n # print (x_y_c[j][0] == b ? x_y_c[j][2] * x_y_c[j][1] : x_y_c[j][2] * x_y_c[j][0])\n # end\n # puts\n #end\nend\n"}, {"source_code": "\ufeff# Codeforces Round\n\n=begin\n# A\na, b = gets.split.map(&:to_i)\nc, d = [a, b].min, [a, b].max\nputs \"#{[a, b].min} #{(a - b).abs / 2}\"\n\n# B\nn = gets.to_i\nh = gets.split.map(&:to_i)\nm, a = [0] * (n - 1) + [h[n - 1]], [0] * n\n(n - 2).downto(0) do |i|\n if h[i] <= m[i + 1]\n m[i] = m[i + 1]\n a[i] = m[i] - h[i] + 1\n else\n m[i] = h[i]\n end\nend\nputs a.join(' ')\n\n# C\nn, k = gets.split.map(&:to_i)\ncmp = -> (x, y) { (y % 10) <=> (x % 10) }\na = gets.split.map(&:to_i).sort(&cmp).map do |x|\n if x % 10 == 0 || k == 0\n x\n else\n d = [10 - x % 10, k].min\n k -= d\n x += d\n end\nend\nans = 0\na.each do |y|\n d = [100 - y, k].min\n k -= d\n ans += (y + d) / 10\nend\nputs ans\n=end\n\n# D\nx, y, c = [0] * 3, [0] * 3, ['A', 'B', 'C']\nx[0], y[0], x[1], y[1], x[2], y[2] = gets.split.map(&:to_i)\nx_y_c, s = [], 0\n3.times do |i|\n s += x[i] * y[i]\n x_y_c << ([x[i], y[i]].sort.reverse + [c[i]])\nend\nx_y_c.sort!.reverse!\n#p x_y_c\na = b = x_y_c[0][0]\nif a ** 2 != s\n puts -1\nelse\n puts a\n x_y_c[0][1].times { puts x_y_c[0][2] * a }\n b -= x_y_c[0][1]\n if x_y_c[1][0] == b # b == x_y_c[2][0]\n b.times { puts x_y_c[1][2] * x_y_c[1][1] + x_y_c[2][2] * x_y_c[2][1] }\n else # b == x_y_c[1][1] + x_y_c[2][1]\n x_y_c[1][1].times { print x_y_c[1][2] * x_y_c[1][0] }\n x_y_c[2][1].times { print x_y_c[2][2] * x_y_c[2][0] }\n puts\n end\n \n #b.times do\n # [1, 2].each do |j|\n # #z = x_y_c[j][0] == b ? x_y_c[j][1] : x_y_c[j][]\n # print (x_y_c[j][0] == b ? x_y_c[j][2] * x_y_c[j][1] : x_y_c[j][2] * x_y_c[j][0])\n # end\n # puts\n #end\nend\n"}, {"source_code": "\ufeff# Codeforces Round\n\n=begin\n# A\na, b = gets.split.map(&:to_i)\nc, d = [a, b].min, [a, b].max\nputs \"#{[a, b].min} #{(a - b).abs / 2}\"\n\n# B\nn = gets.to_i\nh = gets.split.map(&:to_i)\nm, a = [0] * (n - 1) + [h[n - 1]], [0] * n\n(n - 2).downto(0) do |i|\n if h[i] <= m[i + 1]\n m[i] = m[i + 1]\n a[i] = m[i] - h[i] + 1\n else\n m[i] = h[i]\n end\nend\nputs a.join(' ')\n\n# C\nn, k = gets.split.map(&:to_i)\ncmp = -> (x, y) { (y % 10) <=> (x % 10) }\na = gets.split.map(&:to_i).sort(&cmp).map do |x|\n if x % 10 == 0 || k == 0\n x\n else\n d = [10 - x % 10, k].min\n k -= d\n x += d\n end\nend\nans = 0\na.each do |y|\n d = [100 - y, k].min\n k -= d\n ans += (y + d) / 10\nend\nputs ans\n=end\n\n# D\nx, y, c = [0] * 3, [0] * 3, ['A', 'B', 'C']\nx[0], y[0], x[1], y[1], x[2], y[2] = gets.split.map(&:to_i)\nx_y_c, s = [], 0\n3.times do |i|\n s += x[i] * y[i]\n x_y_c << ([x[i], y[i]].sort.reverse + [c[i]])\nend\nx_y_c.sort!.reverse!\n#p x_y_c\na = b = x_y_c[0][0]\nif a ** 2 != s\n puts -1\nelse\n puts a\n x_y_c[0][1].times { puts x_y_c[0][2] * a }\n b -= x_y_c[0][1]\n if x_y_c[1][0] == b # b == x_y_c[2][0] && a == x_y_c[1][1] + x_y_c[2][1]\n b.times { puts x_y_c[1][2] * x_y_c[1][1] + x_y_c[2][2] * x_y_c[2][1] }\n else # b == x_y_c[1][1] + x_y_c[2][1] && a == x_y_c[1][0] && a == x_y_c[2][0]\n x_y_c[1][1].times { puts x_y_c[1][2] * x_y_c[1][0] }\n x_y_c[2][1].times { puts x_y_c[2][2] * x_y_c[2][0] }\n end\n \n #b.times do\n # [1, 2].each do |j|\n # #z = x_y_c[j][0] == b ? x_y_c[j][1] : x_y_c[j][]\n # print (x_y_c[j][0] == b ? x_y_c[j][2] * x_y_c[j][1] : x_y_c[j][2] * x_y_c[j][0])\n # end\n # puts\n #end\nend\n"}], "src_uid": "2befe5da2df57d23934601cbe4d4f151"} {"source_code": "n = gets.to_i\nn.times do \n x ,y, n = gets.chomp.split(\" \").map(&:to_i)\n first = n - y \n kari = first / x\n ans = kari * x + y\n puts ans\nend", "positive_code": [{"source_code": "gets.to_i.times do\n\tx, y, n = gets.split.map(&:to_i)\n\tif n % x >= y\n\t\tputs n / x * x + y\n\telse\n\t\tputs (n / x - 1) * x + y\n\tend\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n\tx,y,n = gets.split.map(&:to_i)\n\tans = x * (n/x) + y\n\tif ans > n\n\t\tans -= x\n\tend\n\tputs ans\nend"}, {"source_code": "def run\n x, y, n = gets.chomp.split(\" \").map(&:to_i)\n\n l = n % x\n\n # puts [x, y, n, l].inspect\n\n if l == y\n puts n\n elsif l > y\n puts n - (l - y)\n else\n puts n - (x - (y - l))\n end\nend\n\n\ndef main\n t = gets.chomp.to_i\n\n t.times do\n run\n end\nend\n\nmain\n"}, {"source_code": "gets.to_i.times do\n x, y, n = gets.split.map(&:to_i)\n puts (n - y) / x * x + y\nend\n\n"}, {"source_code": "def answer(n, x, y)\n return answer(n - n.modulo(x) - 1, x, y) if n.modulo(x) < y\n\n return n - (n.modulo(x) - y)\nend\n\ngets.to_i.times do\n x, y, n = gets.split(' ').map(&:to_i)\n\n puts answer(n, x, y)\nend\n"}], "negative_code": [], "src_uid": "2589e832f22089fac9ccd3456c0abcec"} {"source_code": "puts(\"even\")\n \t\t\t \t \n \t\t \t\t\t \t\n \t\t\t \t \t\n \t\t\t \t \t", "positive_code": [{"source_code": "puts \"odd\"\n\n\t\t \t \t \t\t\n \t \t\t\t \t \t\n \t \t \t\t\t\t\n \t \t "}, {"source_code": "puts(\"even\")\n\t \t \t \t\t\t\n \t\t\t\t\t \t\t\t\n \t \t\t \t \n\t \t\t\t\t\t\t "}], "negative_code": [{"source_code": "puts \"Red\"\n\n \t\t \t \t \n\t\t\t\t \t\t\t\n \t\t \n \t\t\t\t\t\t\t\t"}, {"source_code": "puts \"even\"\n\n \t\t \t \t \t\n \t \t\t\t \t \n \t\t\t\t \n\t\t\t\t\t\t \t"}, {"source_code": "puts \"31\"\n\n \t \t\n \t \t\t \t \n\t \t\t \t \n\t\t \t "}, {"source_code": "puts \"even\"\n\n \t\t \t \t\t\t\n \t \t \t\t \t\n\t \t\t\t \t \t \n\t \t\t \t\t"}, {"source_code": "puts 31\n \t \t\t \n \t\t \n \t \t\t \n \t \t\t \t"}, {"source_code": "puts \"31\"\n\n \t\t\t\t\t \t \n \t \t\t \t \n\t\t \t \t\t \t\n\t \t \t "}, {"source_code": "puts \"odd\"\n\n\t \t\t\t \t\t\t\t\n\t \t \t\t \n\t \t\t \t \n \t\t \t\t\t "}, {"source_code": "(1..39).each { |i| puts i }\n\t\t\t\t\t\t\t \t\n \t\t \t \t\n \t\t\t\t\n \t\t \t "}, {"source_code": "puts \"31\"\n\n\t \t\t\t\t\t \n \t \t\t\t \n\t\t\t\t\t \t\t\t\n\t \t\t "}, {"source_code": "puts \"even\"\n\n \t\t \t\t\t \n \t\t\t \t\t\t \n \t \t \t\t\t \n\t \t\t\t \t"}, {"source_code": "puts \"Even\"\n\n \t\t\t \t\t\n\t \t \t\t\t \n\t \t \t\t\t \n \t \t \t "}, {"source_code": "puts 31\n \t \t\t\t\t\t \n \t\t \t\t \t\t\n \t\t\t \t \t\n\t\t\t \t \t "}, {"source_code": "puts \"31\"\n\t \t \t\t\n \t \t \t \n \t \t\t \n \t \t "}, {"source_code": "puts \"even\"\n\n\t\t\t\t \t\t\t \n\t\t\t \t \t \t\n\t \t \t \n\t\t\t \t \t \t"}, {"source_code": "puts \"even\"\n\n\t\t \t\t\t\t \t \n\t \t \t \t \n\t \t\t\t \t \n\t\t \t \t\t\t"}, {"source_code": "puts 31\n \t \t\t \t\t\n\t \t\t\t \t \t\n \t\t\t \t \n\t\t \t\t \t "}, {"source_code": "puts \"even\"\n\n \t \t\t\t\t\n\t \t\t \t\t \n \t \t \t\t \t\n\t \t\t\t \t "}, {"source_code": "puts 31\n \t\t \t\n \t \n\t \t\t\t \t\n \t\t \t \t\t "}, {"source_code": "puts \"even\"\n\n \t\t \t \t\t\t\n \t\t\t\t \t\t \n \t\t \t \t\n\t\t \t \t \t "}, {"source_code": "puts \"31\"\n\t\t \t\t\t\t\t \n \t\t \t \n\t\t \t\t\t\t\t\t \n\t \t \t\t\t\t \t"}, {"source_code": "puts 31\n \t \t\t \t\t\t\n\t \t \t\t\t \t\t\n\t \t\t \t \n\t\t \t\t \t\t\t "}, {"source_code": "puts \"even\"\n\n\t \t\t\t \t\n\t \t \t\t \n\t \t\t \t\t \t\t\n\t\t\t\t\t \t "}, {"source_code": "puts 31\n \t \t \t \n\t\t \t\t \t\t\t\n\t\t \t \t \t\n\t \t\t \t\t\t\t"}, {"source_code": "puts(\"Odd\")\n \t\t\t \t\t\t\t\t\n \t \t \t \n\t\t\t\t\t \t\t\t\t\n \t\t \t \t"}, {"source_code": "puts(\"Red\")\n\t\t \t \t \n\t\t \t \t\t\t\t \n\t \t \t \t\t \n \t\t\t \t \t"}, {"source_code": "puts(\"red\")\n\t\t \t \t\t \n \t \t\t\t\t \n\t\t \t \t\t \n \t \t \t\t"}], "src_uid": "f2a71cb9706b76317f2f442a9129055f"} {"source_code": "\nn = gets.to_i\nans = 0\n(1..n).each do |x|\n\tans += 1 / x.to_f\nend\nputs ans.to_f\n", "positive_code": [{"source_code": "s,k=0.0,1.0\na=gets.to_i\nwhile k<=a\n\ts+=1/k\n\tk+=1\nend\t\t\nputs (s)\t\n"}], "negative_code": [], "src_uid": "260666df22ee510fcce3ebdfbb8b71a2"} {"source_code": "gets.to_i.times{\n a = gets.chomp\n b = gets.chomp\n c = gets.chomp\n x = true\n (0...a.length).each do |i|\n if (a[i] == b[i] && a[i] != c[i] || a[i] != b[i] && b[i] != c[i] && a[i] != c[i])\n x = false\n break\n end\n end\n puts x ? \"YES\" : \"NO\"\n}", "positive_code": [{"source_code": "n = Integer gets\nfor jj in 0...n\ns1, s2, s3 = gets.chop!, gets.chop!, gets.chop!\nflg = \"YES\"\nfor i in 0...s3.size\n if s3[i] != s1[i] && s3[i] != s2[i] then flg = \"NO\" end\nend\nputs flg\nend"}, {"source_code": "# frozen_string_literal: true\n\n@data = $stdin.read.split\n\ndef next_token\n @data.shift\nend\n\ndef next_int\n next_token.to_i\nend\n\nnext_int.times do |_i|\n a = next_token\n b = next_token\n c = next_token\n ok = true\n a.size.times do |i|\n next if a[i] == c[i] || b[i] == c[i]\n\n ok = false\n end\n if ok\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n a = gets.chomp\n b = gets.chomp\n c = gets.chomp\n n = a.size\n\n success = true\n\n n.times do |i|\n if a[i] != c[i] && b[i] != c[i]\n success = false\n end\n end\n\n if success\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "n = gets.to_i\nn.times {\n a = gets.chomp\n b = gets.chomp\n c = gets.chomp\n flag = true\n for i in (0..a.length - 1)\n if a[i] != c[i] and b[i] != c[i]\n flag = false\n end\n end\n puts flag ? \"YES\" : \"NO\"\n}\n"}], "negative_code": [{"source_code": "gets.to_i.times{\n a = gets.chomp\n b = gets.chomp\n c = gets.chomp\n x = true\n (0...a.length).each do |i|\n if !((a[i] == c[i]) ^ (b[i] == c[i]) ^ (a[i] == b[i]))\n x = false\n break\n end\n end\n puts x ? \"YES\" : \"NO\"\n}"}, {"source_code": "gets.to_i.times{\n a = gets.chomp\n b = gets.chomp\n c = gets.chomp\n x = true\n (0...a.length).each do |i|\n if !((a[i] == c[i]) ^ (b[i] == c[i]))\n x = false\n break\n end\n end\n puts x ? \"YES\" : \"NO\"\n}"}], "src_uid": "08679e44ee5d3c3287230befddf7eced"} {"source_code": "t = gets.chomp.to_i\nt.times do \n\tn, a, b, c, d = gets.chomp.split(\" \").map(&:to_i)\n\tflag = false\n\t# (n*(a-b)..n*(a+b)).each do |ngo|\n\t# \t#print ngo.to_s + \" \"\n\t# \tif c - d <= ngo && ngo <= c + d then\n\t# \t\tflag = true\n\t# \t\tbreak\n\t# \tend\n\t# end\n\tnab1 = n*(a-b)\n\tnab2 = n*(a+b)\n\tputs (nab1 <= c-d && c + d <= nab2) || (c-d<=nab1 && nab1<=c+d) || (c-d<=nab2&&nab2<=c+d) ? \"Yes\" : \"No\"\nend\n", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n n, a, b, c, d = gets.split.map(&:to_i)\n ok = true\n if (a - b) * n > (c + d) || (a + b) * n < (c - d)\n ok = false\n end\n puts ok ? \"Yes\" : \"No\"\nend\n"}, {"source_code": "\n\ndef solve n, a, b, c, d\n return \"Yes\" if n * (a-b) <= c+d && n * (a+b) >= c-d\n \"No\"\nend\n\nt = STDIN.gets.chomp.to_i\n\n(1..t).each do |i|\n n, a, b, c, d = STDIN.gets.chomp.split.map {|i| i.to_i}\n res = solve n, a, b, c, d\n puts res\nend\n"}, {"source_code": "# Task 1341A\n# require 'byebug'\n\nt = gets.chomp.to_i\nanswers = []\nt.times do\n # Reading input\n str = gets.chomp\n n, a, b, c, d = str.split(\" \").map{ |n| n.to_i }\n\n min_weight = a - b\n max_weight = a + b\n min_total = c - d\n max_total = c + d\n\n if (max_weight * n) < min_total || max_total < (min_weight * n)\n answers << \"No\"\n else\n answers << \"Yes\"\n end\nend\nputs answers"}, {"source_code": "class Range\n def crosses?(x)\n include?(x.first) || include?(x.last) || x.include?(first) || x.include?(last)\n end\nend\n\n1.upto(gets.to_i) do\n n, a, b, c, d = gets.split(' ').map(&:to_i)\n\n puts ((c-d)..(c+d)).crosses?((n*(a-b))..(n*(a+b))) ? 'Yes' : 'No'\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n\tn, a, b, c, d = gets.strip.split.map(&:to_i)\n\tmin_grains = (a - b) * n\n\tmax_grains = (a + b) * n\n\tmin_pack = c - d\n\tmax_pack = c + d\n\tif max_grains < min_pack || max_pack < min_grains\n\t\tputs \"No\"\n\telse\n\t\tputs \"Yes\"\n\tend\nend"}, {"source_code": "gets.to_i.times {\n n, a, b, c, d = gets.split.map { |v| v.to_i }\n min_sum = n * (a - b)\n max_sum = n * (a + b)\n if min_sum > c + d or max_sum < c - d\n puts \"No\"\n else\n puts \"Yes\"\n end\n}\n"}, {"source_code": "1.upto(gets.chomp.to_i) do\n n,a,b,c,d = gets.chomp.split.map(&:to_i)\n if (n * (a-b) <= (c+d) && n*(a+b) >= (c-d))\n puts 'Yes'\n else\n puts 'No'\n end\nend\n"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\nt.times do \n\tn, a, b, c, d = gets.chomp.split(\" \").map(&:to_i)\n\tflag = false\n\t(a-b..a+b).each do |ngo|\n\t\tif c - d <= n * ngo && n * ngo <= c + d then\n\t\t\tputs \"Yes\"\n\t\t\tflag = true\n\t\t\tbreak\n\t\tend\n\tend\n\tputs \"No\" if flag == false\nend\n"}, {"source_code": "# Task 1341A\n# require 'byebug'\n\nt = gets.chomp.to_i\nanswers = []\nt.times do\n # Reading input\n str = gets.chomp\n n, a, b, c, d = str.split(\" \").map{ |n| n.to_i }\n\n min_weight = a - b\n max_weight = a + b\n min_total = c - d\n max_total = c + d\n\n if (min_weight * n) >= min_total || ((max_weight * n) <= max_total && (max_weight * n) >= min_total)\n answers << \"Yes\"\n else\n answers << \"No\"\n end\nend\nputs answers"}, {"source_code": "\n\ndef solve n, a, b, c, d\n tot = [c-d, c+d]\n ((a-b)..(a+b)).each do |i|\n return \"Yes\" if n * i >= tot[0] && n * i <= tot[1]\n return \"Yes\" if n * i >= tot[0] && n * i <= tot[1]\n end\n \"No\"\nend\n\nt = STDIN.gets.chomp.to_i\n\n(1..t).each do |i|\n n, a, b, c, d = STDIN.gets.chomp.split.map {|i| i.to_i}\n res = solve n, a, b, c, d\n puts res\nend\n"}, {"source_code": "\n\ndef solve n, a, b, c, d\n tot = [c-d, c+d]\n return \"Yes\" if n * (a-b) >= tot[0] && n * (a-b) <= tot[1]\n return \"Yes\" if n * (a+b) >= tot[0] && n * (a+b) <= tot[1]\n \"No\"\nend\n\nt = STDIN.gets.chomp.to_i\n\n(1..t).each do |i|\n n, a, b, c, d = STDIN.gets.chomp.split.map {|i| i.to_i}\n res = solve n, a, b, c, d\n puts res\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n\tn, a, b, c, d = gets.strip.split.map(&:to_i)\n\tmin_grains = (a - b) * n\n\tmax_grains = (a + b) * n\n\tmin_pack = c - d\n\tmax_pack = c + d\n\tif (min_pack <= min_grains && max_pack >= min_grains) || (min_pack <= max_grains && max_pack >= max_grains)\n\t\tputs \"Yes\"\n\telse\n\t\tputs \"No\"\n\tend\nend"}, {"source_code": "t = gets.to_i\nt.times do\n\tn, a, b, c, d = gets.strip.split.map(&:to_i)\n\tmin_grains = (a - b) * n\n\tmax_grains = (a + b) * n\n\tmin_pack = c - d\n\tmax_pack = c + d\n\tif (min_pack <= min_grains && min_grains <= max_pack) || (min_pack <= max_grains && max_grains <= max_pack)\n\t\tputs \"Yes\"\n\telse\n\t\tputs \"No\"\n\tend\nend"}], "src_uid": "30cfce44a7a0922929fbe54446986748"} {"source_code": "n = gets.to_i\nn.times do\n c = false\n ip = gets.strip.split(\":\")\n if ip[0] == \"\" then ip = ip.drop(1) end\n l = ip.count\n for i in 0...l\n if ip[i] == \"\"\n if i > 0 then print \":\" end\n print \"0000\"\n (8 - l).times do\n print \":0000\"\n end\n c = true\n else\n if i > 0 then print \":\" end\n (4 - ip[i].length).times do print \"0\" end\n print ip[i]\n end\n end\n if l != 8 && !c\n if l > 0 then print \":\" end\n print \"0000\"\n (7 - l).times do\n print \":0000\"\n end\n end\n puts \"\"\nend", "positive_code": [{"source_code": "gets.to_i.times do\n bb = gets.strip.gsub('::', ':zero:').split(':')\n seq_len = 8 - bb.size + 1\n blocks = []\n bb.each do |b|\n if b == 'zero'\n seq_len.times{ blocks << '0000' }\n else\n blocks << '0' * (4 - b.size) + b\n end\n end\n\n puts blocks.join(':')\nend\n"}, {"source_code": "n=Integer(gets.chomp)\n\nn.times do\ns=gets.chomp\na=s.split '::'\nif a[0]!=nil\nb=a[0].split ':'\nelse\nb=[]\nend\nif a[1]!=nil\nc=a[1].split ':'\nelse\nc=[]\nend\n\na=b+Array.new(8-(b.size+c.size),\"0000\")+c\na.map!{|i| \"0\"*(4-i.size)+i}\n\n(a.size-1).times do |i|\nprint a[i]+':'\nend\nprint a[-1]+\"\\n\"\n\nend\n"}, {"source_code": "gets.to_i.times {\n short = gets.strip.gsub('::', ':zero:').split(':')\n seq_len = 8 - short.size + 1\n blocks = []\n short.each { |b|\n if b == 'zero'\n seq_len.times{ blocks << '0000' }\n else\n blocks << '0' * (4 - b.size) + b\n end\n }\n\n puts blocks.join(':')\n}\n"}, {"source_code": "gets;puts $<.map{|x|x.sub('::',?:*(9-x.count(?:))).gsub(/\\w*\\W/){|y|y.rjust 5,?0}}"}, {"source_code": "puts(readlines[1..-1].map{|x|x.sub('::',?:*(9-x.count(?:))).gsub(/\\w*\\W/){|y|\"0000#{y}\"[-5,5]}})\n"}, {"source_code": "gets;puts $<.lines.map{|x|x.sub('::',?:*(9-x.count(?:))).gsub(/\\w*\\W/){|y|y.rjust 5,?0}}"}, {"source_code": "gets\nputs$<.map{|x|x.sub('::',?:*(9-x.count(?:))).gsub(/\\w*\\W/){|y|y.rjust 5,?0}}"}, {"source_code": "#require 'colorize'\n\ndef recoveryPart(part)\n zones = part.split(':')\n fullPart = String.new\n\n zones.each { |zone|\n fullPart += ('0' * (4 - zone.length)) + zone + ':'\n\n }\n\n fullPart[0..-2]\nend\n\n\ndef recoveryIpv6(shortIpv6)\n\n part = shortIpv6.split('::')\n\n case part.length\n when 0\n result = ('0000:'*8)[0..-2]\n when 1\n if (shortIpv6[shortIpv6.length-2..shortIpv6.length] == '::')\n result = recoveryPart(part[0]) + ':' + ('0000:' * (8 - part[0].split(':').length))\n else\n result = recoveryPart(shortIpv6)\n end\n when 2\n result = recoveryPart(part[0]) + ':' + ('0000:' * (8 - (part[0].split(':').length + part[1].split(':').length))) + recoveryPart(part[1])\n end\n\n if (result[0..0] == ':')\n result = result[1..result.length]\n end\n\n if (result[result.length-1..result.length] == ':')\n result = result[0..result.length-2]\n end\n result\n\nend\n\ncount = gets.chomp.to_i;\n\ncount.times do\n puts recoveryIpv6(gets.chomp)\nend\n\n\n#\n# TEST\n#\n\n#if recoveryIpv6('a56f:d3:0:0124:01:f19a:1000:00') == 'a56f:00d3:0000:0124:0001:f19a:1000:0000'\n# puts 'OK'.green\n#else\n# puts 'FAIL'.red\n#end\n#\n#if recoveryIpv6('a56f:00d3:0000:0124:0001::') == 'a56f:00d3:0000:0124:0001:0000:0000:0000'\n# puts 'OK'.green\n#else\n# puts 'FAIL'.red\n#end\n#\n#if recoveryIpv6('::a56f:00d3:0000:0124:0001') == '0000:0000:0000:a56f:00d3:0000:0124:0001'\n# puts 'OK'.green\n#else\n# puts 'FAIL'.red\n#end\n#\n#if recoveryIpv6('a56f::0124:0001:0000:1234:0ff0') == 'a56f:0000:0000:0124:0001:0000:1234:0ff0'\n# puts 'OK'.green\n#else\n# puts 'FAIL'.red\n#end\n#\n#if recoveryIpv6('a56f:0000::0000:0001:0000:1234:0ff0') == 'a56f:0000:0000:0000:0001:0000:1234:0ff0'\n# puts 'OK'.green\n#else\n# puts 'FAIL'.red\n#end\n#\n#if recoveryIpv6('::') == '0000:0000:0000:0000:0000:0000:0000:0000'\n# puts 'OK'.green\n#else\n# puts 'FAIL'.red\n#end\n#\n#if recoveryIpv6('0ea::4d:f4:6:0') == '00ea:0000:0000:0000:004d:00f4:0006:0000'\n# puts 'OK'.green\n#else\n# puts 'FAIL'.red\n#end\n"}, {"source_code": "gets\nputs $<.map { |s|\n s.strip!\n x = s.split(?:).reject(&:empty?)\n s = s.gsub(/::/, \":#{'0:' * (8 - x.size)}\").gsub(/^:|:$/, '')\n s.split(?:).map { |t| t.rjust(4, ?0) } .join(?:)\n}\n"}], "negative_code": [{"source_code": "n = gets.to_i\nn.times do\n c = false\n ip = gets.strip.split(\":\")\n l = ip.count\n for i in 0...l\n if ip[i] == \"\"\n if i > 0 then print \":\" end\n print \"0000\"\n (8 - l).times do\n print \":0000\"\n end\n c = true\n else\n if i > 0 then print \":\" end\n (4 - ip[i].length).times do print \"0\" end\n print ip[i]\n end\n end\n if l != 8 && !c\n if l > 0 then print \":\" end\n print \"0000\"\n (7 - l).times do\n print \":0000\"\n end\n end\n puts \"\"\nend"}, {"source_code": "n = gets.to_i\nn.times do\n c = false\n ip = gets.strip.split(\":\")\n l = ip.count\n for i in 0...l\n if ip[i] == \"\"\n if i > 0 then print \":\" end\n print \"0000\"\n (8 - l).times do\n print \":0000\"\n end\n c = true\n else\n if i > 0 then print \":\" end\n (4 - ip[i].length).times do print \"0\" end\n print ip[i]\n end\n end\n if !c\n if l > 0 then print \":\" end\n print \"0000\"\n (7 - l).times do\n print \":0000\"\n end\n end\n puts \"\"\nend"}, {"source_code": "#!ruby -plr ipaddr\n#$_=IPAddr.new($_).to_string\n$_=2\n"}], "src_uid": "20f69ee5f04c8cbb769be3ab646031ab"} {"source_code": "def say_no\n puts 'NO'\n exit\nend\n\ng1, g2 = [gets.chomp, gets.chomp]\nn = g1.size\nsay_no if n != g2.size\nd = []\nfor i in 0...n\n say_no if g1[i] != g2[i] && ((t = (d << i).size) > 2 || (t == 2 && (g1[d[0]] != g2[d[1]] || g1[d[1]] != g2[d[0]])))\nend\nputs [0, 2].any? { |p| p == d.size } ? 'YES' : 'NO'", "positive_code": [{"source_code": "a, b, c, diff = gets.strip, gets.strip, 0, []\n\nif a.length == b.length\n\ta.length.times do |i|\n\t\tunless a[i] == b[i]\n\t\t\tc += 1\n\t\t\tc < 3 ? diff.push([a[i], b[i]]) : break\n\t\tend\n\tend\n\tprint c == 2 && diff[0] == diff[1].reverse ? :YES : :NO\nelse\n\tprint :NO\n\texit\nend"}, {"source_code": "a = gets.chomp\nb = gets.chomp\n\ndef work(a, b)\n #puts a.size,b.size\n return false if a.size != b.size\n d = []\n (0...a.size).each {|x| d << x if a[x] != b[x]}\n # p d.size\n return false if d.size != 0 and d.size != 2\n\n if d.size == 2\n return true if a[d[0]] == b[d[1]] and a[d[1]] == b[d[0]]\n return false\n end\n \n hs = Hash.new(0)\n a.each_byte{|x| hs[x] = hs[x] + 1}\n return true if hs.values.any?{|x| x > 1}\n \n return false\nend\n\nif work(a,b)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n "}, {"source_code": "s1 = gets.chomp.split(\"\")\ns2 = gets.chomp.split(\"\")\n\nif s1.sort == s2.sort then\n i = 0\n d = 0\n while i < s1.size do \n if s1[i] != s2[i] then\n d += 1\n end\n i += 1\n end\n if d <= 2 then\n puts \"YES\"\n else\n puts \"NO\"\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\nret = \"NO\"\nr1 = nil\nr2 = nil\nif s1.length == s2.length\n for i in 0..s1.length-1\n next if s1[i] == s2[i]\n if r1 == nil\n r1 = s1[i]\n r2 = s2[i]\n else\n if ret == \"NO\"\n if r1 == s2[i] && r2 == s1[i]\n ret = \"YES\"\n else\n break\n end\n else\n ret = \"NO\"\n break\n end\n end\n end\nend\nputs ret\n"}, {"source_code": "require 'set'\n\ndef compare_str(a, b)\n return \"NO\" if a.length != b.length\n a_set = []\n b_set = []\n (0..a.length).each do |i|\n if a[i] != b[i]\n a_set << a[i]\n b_set << b[i]\n end\n end\n return \"NO\" if a_set.length > 2\n return \"YES\" if a_set.sort == b_set.sort\n return \"NO\"\nend\n\n\na = gets.chomp\nb = gets.chomp\n\nputs compare_str(a, b)\n\n"}, {"source_code": "\ufeffdef diff(a, b)\n c = 0\n for i in 0..(a.length - 1)\n if a[i] != b[i]\n c += 1\n end\n end\n c\nend\n\na = gets.chomp.split \"\"\nb = gets.chomp.split \"\"\n\nputs ((a.sort == b.sort) and diff(a, b) == 2) ? \"YES\" : \"NO\"\n"}, {"source_code": "s = STDIN.readline.strip\nt = STDIN.readline.strip\nif s.length != t.length\n\tputs 'NO'\n\texit\nend\ndifferences = []\ns.length.times do |i|\n\tdifferences.push(i) if s[i] != t[i]\nend\nif differences.length != 2\n\tputs 'NO'\n\texit\nend\na, b = differences\ns[a], s[b] = s[b], s[a]\nif s == t\n\tputs 'YES'\nelse\n\tputs 'NO'\nend\n"}, {"source_code": "a=gets.chomp.strip\nb=gets.chomp.strip\nx=[]\nif a.length!=b.length\n\tputs \"NO\"\n\texit\nend\nfor i in 0...a.length\n\tif a[i]!=b[i]\n\t\tx.push(i)\n\tend\nend\nif x.length!=2\n\tputs \"NO\"\n\texit\nend\nputs (a[x[0]]==b[x[1]] and b[x[0]]==a[x[1]])? \"YES\" : \"NO\"\n"}, {"source_code": "a=gets.chomp.split(\"\")\nb=gets.chomp.split(\"\")\n\nif a.length !=b.length\n\tputs \"NO\"\nelsif a.sort != b.sort\n\tputs \"NO\"\nelsif a==b\n\tputs \"YES\"\nelsif a.reverse==b && a.length==2\n\tputs \"YES\"\nelse\n\nk=[]\n\t\n\t0.upto(a.length-1) do|i|\n\t\tk[i]=[a[i],b[i]]\n\tend\n\nk.each{|i| i.uniq!}\nk.sort! {|x,y| y.length <=> x.length}\nd=0\n\n\t0.upto(2) do |i|\n\t\tif k[i].length==2\n\t\t\td+=1\n\t\tend\n\tend\n\tif d<=1\n\t\tputs \"YES\"\n\telsif d>2\n\t\tputs \"NO\"\n\telse\n\t\tif k[0].reverse==k[1]\n\t\t\tputs \"YES\"\n\t\telse\n\t\t\tputs \"NO\"\n\t\tend\n\tend\n\nend\t"}, {"source_code": "a = gets.to_s\nb = gets.to_s\n\nif a.size != b.size then\n\tputs \"NO\"\n\texit\nend\n\ncount = 0\nx = 0\ny = 0\n\n0.upto (a.size-1) do |i|\n\tif a[i] != b[i] then\n\t\tcount += 1\n\t\tif count == 1 then\n\t\t\tx = a[i]\n\t\t\ty = b[i]\n\t\telsif count == 2 then\n\t\t\tif (x != b[i]) or (y != a[i]) then\n\t\t\t\tputs \"NO\"\n\t\t\t\texit\n\t\t\tend\n\t\telse\n\t\t\tputs \"NO\"\n\t\t\texit\n\t\tend\n\tend\nend\n\nif count == 0 then\n\td = {}\n\t0.upto (a.size -1) do |i| \n\t\tif d[i] == 1 then \n\t\t\tputs \"YES\"\n\t\t\texit\n\t\telse\n\t\t\td[i] = 1\n\t\tend\n\tend\n\tputs \"NO\"\t\n\texit\nelsif count == 1 then\n\tputs \"NO\"\n\texit\nelse\n\tputs \"YES\"\n\texit\nend\n"}, {"source_code": "first = gets.chomp\nsecond = gets.chomp\nans = \"NO\"\nif first.length == second.length\n diff = []\n act = []\n (0...first.length).each do |i|\n a = first[i]\n b = second[i]\n if a != b\n diff << a\n act << b\n end\n end\n if diff.length == 2\n ans = \"YES\" if act[0] == diff[1] && act[1] == diff[0]\n end\nend\nputs ans\n"}, {"source_code": "a=gets.chomp.split(\"\")\nb=gets.chomp.split(\"\")\n\nif a.length !=b.length\n\tputs \"NO\"\nelsif a.sort != b.sort\n\tputs \"NO\"\nelsif a==b\n\tputs \"YES\"\nelsif a.reverse==b && a.length==2\n\tputs \"YES\"\nelse\n\nk=[]\n\t\n\t0.upto(a.length-1) do|i|\n\t\tk[i]=[a[i],b[i]]\n\tend\n\nk.each{|i| i.uniq!}\nk.sort! {|x,y| y.length <=> x.length}\nd=0\n\n\t0.upto(2) do |i|\n\t\tif k[i].length==2\n\t\t\td+=1\n\t\tend\n\tend\n\tif d<=1\n\t\tputs \"YES\"\n\telsif d>2\n\t\tputs \"NO\"\n\telse\n\t\tif k[0].reverse==k[1]\n\t\t\tputs \"YES\"\n\t\telse\n\t\t\tputs \"NO\"\n\t\tend\n\tend\n\nend"}, {"source_code": "a = gets.chomp\nb = gets.chomp\n\ndef work(a, b)\n return false if a.size != b.size\n d = []\n (0...a.size).each {|x| d << x if a[x] != b[x]}\n # p d.size\n return false if d.size != 0 and d.size != 2\n\n if d.size == 2\n return true if a[d[0]] == b[d[1]] and a[d[1]] == b[d[0]]\n return false\n end\n \n hs = Hash.new(0)\n a.each_byte{|x| hs[x] = hs[x] + 1}\n return true if hs.values.any?{|x| x > 1}\n \n return false\nend\n\nif work(a,b)\n puts 'YES'\nelse\n puts 'NO'\nend"}, {"source_code": "a=gets\nb=gets\nif a.size != b.size\n puts \"NO\"\nelse\n s0=[]\n s1=[]\n (a.size-1).times do |i|\n if a[i] != b[i]\n s0 << a[i]\n s1 << b[i]\n end\n end\n if s0.size!=2 || s0[1] != s1[0] || s0[0] != s1[1]\n puts \"NO\"\n else\n puts \"YES\"\n end\nend \n "}, {"source_code": "first_count = Hash.new(0)\nsecond_count = Hash.new(0)\n\na = gets.chomp\nb = gets.chomp\nans = false\nmismatch_ind = []\nif a.length == b.length\n\t(0..a.length - 1).each do |i|\n\t\t\n\t\ta_char = a[i]\n\t\tb_char = b[i]\n\t\t\n\t\tfirst_count[a_char] += 1\n\t\tsecond_count[b_char] += 1\n\t\tmismatch_ind << i if a_char != b_char\t\t\t\t\t\t\t\t\n\tend\n\n\tans = true if first_count == second_count && ( mismatch_ind.length == 0 || (mismatch_ind.length == 2 && a[mismatch_ind[0]] == b[mismatch_ind[1]] && a[mismatch_ind[1]] == b[mismatch_ind[0]]))\n\nend\nputs ans ? \"YES\" : \"NO\""}, {"source_code": "l = []\na = gets\nb = gets\nif a.size == b.size\n\ta.split(//).each_with_index do |x, i|\n\t\tl << a[i].ord - b[i].ord if a[i].ord - b[i].ord != 0\n\t\tif l.size > 2\n\t\t\tbreak\n\t\tend\n\tend\nelse\n\tl << 0\nend\n\nif l.size == 0 or (l.size == 2 and l[0] == -l[1])\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "as, bs = gets.chomp.chars.to_a, gets.chomp.chars.to_a\nfirst = true\nfirst_a, first_b = nil, nil\noutput = false\nanswer = \"NO\"\nif as.length == bs.length\n as.each_with_index do |a, i|\n b = bs[i]\n if a != b\n if output\n answer = \"NO\"\n break\n end\n if first\n first_a = a\n first_b = b\n first = false\n else\n answer = \"YES\" if a == first_b && b == first_a\n output = true\n end\n end\n end\n\n puts answer\nelse\n puts \"NO\"\nend\n"}, {"source_code": "as, bs = gets.chomp.chars.to_a, gets.chomp.chars.to_a\n\nif as.length != bs.length\n puts \"NO\"\nelse\n diff = []\n\n as.zip(bs).each_with_index do |(a, b), i|\n diff << i if a != b\n end\n\n puts diff.length == 2 && as[diff[0]] == bs[diff[1]] && as[diff[1]] == bs[diff[0]] ? \"YES\" : \"NO\"\nend\n"}, {"source_code": "def main\n a = STDIN.gets\n b = STDIN.gets\n\n return 'NO' if a.length != b.length\n\n diffs = []\n (0 ... a.length).each do |i|\n diffs.push(i) if a[i] != b[i]\n end\n\n return 'NO' if diffs.length != 2\n\n return a[diffs[0]] == b[diffs[1]] && b[diffs[0]] == a[diffs[1]] ? 'YES' : 'NO'\nend\n\nputs main\n"}, {"source_code": "a=gets.chomp.split(\"\")\nb=gets.chomp.split(\"\")\n\nif a.length !=b.length\n\tputs \"NO\"\nelsif a.sort != b.sort\n\tputs \"NO\"\nelsif a==b\n\tputs \"YES\"\nelsif a.reverse==b && a.length==2\n\tputs \"YES\"\nelse\n\nk=[]\n\t\n\t0.upto(a.length-1) do|i|\n\t\tk[i]=[a[i],b[i]]\n\tend\n\nk.each{|i| i.uniq!}\nk.sort! {|x,y| y.length <=> x.length}\nd=0\n\n\t0.upto(2) do |i|\n\t\tif k[i].length==2\n\t\t\td+=1\n\t\tend\n\tend\n\tif d<=1\n\t\tputs \"YES\"\n\telsif d>2\n\t\tputs \"NO\"\n\telse\n\t\tif k[0].reverse==k[1]\n\t\t\tputs \"YES\"\n\t\telse\n\t\t\tputs \"NO\"\n\t\tend\n\tend\n\nend\t"}, {"source_code": "a = gets\nb = gets\nans = false\nif a.length == b.length\n\ts = []\n\ta.length.times do |i|\n\t\tif a[i] != b[i]\n\t\t\ts << i\n\t\tend\n\tend\n\tans = s.empty? || ((s.length == 2 and a[s[0]] == b[s[1]] and a[s[1]] == b[s[0]]))\nend\nputs ans ? \"YES\" : \"NO\""}], "negative_code": [{"source_code": "s1 = gets.chomp\ns2 = gets.chomp\n\ni = 0\nwhile i < s2.size do\n if s1[i] == s2[i] then\n s1 = s1[0...i] + s1[i+1..-1]\n s2 = s2[0...i] + s2[i+1..-1]\n end\n i += 1\nend\n\ns1 = s1.delete(s2)\n\nif s1 == \"\" then\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "s1 = gets.chomp.split(\"\")\ns2 = gets.chomp.split(\"\")\n\ns1 = s1.sort\ns2 = s2.sort\n\nif s1 == s2 then\n i = 0\n d = 0\n while i < s1.size do \n if s1[i] != s2[i] then\n d += 1\n end\n i += 1\n end\n if d <= 2 then\n puts \"YES\"\n else\n puts \"NO\"\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\n\nif s1.size == s2.size then\n i = 0\n while i < s2.size do\n if s1[i] == s2[i] then\n s1 = s1.sub(s1[i], \"\")\n s2 = s2.sub(s2[i], \"\")\n end\n i += 1\n end\n if s1.size == 2 then\n s1 = s1.delete(s2)\n if s1 == \"\" then\n puts \"YES\"\n else\n puts \"NO\"\n end\n else\n puts \"NO\"\n end\nelse\n puts \"NO\"\nend\n"}, {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\n\nif s1.size == s2.size then\n i = 0\n str = \"\"\n while i < s2.size do\n if s1[i] == s2[i] then\n str += s1[i]\n end\n i += 1\n end\n s1 = s1.sub(str, \"\")\n s2 = s2.sub(str, \"\")\n if s1.size == 2 then\n s1 = s1.delete(s2)\n if s1 == \"\" then\n puts \"YES\"\n else\n puts \"NO\"\n end\n else\n puts \"NO\"\n end\nelse\n puts \"NO\"\nend\n"}, {"source_code": "\ufeffdef diff(a, b)\n c = 0\n for i in 0..(a.length - 1)\n if a[i] == b[i]\n c += 1\n end\n end\n c\nend\n\na = gets.chomp.split \"\"\nb = gets.chomp.split \"\"\n\nputs ((a.sort == b.sort) and diff(a, b) == 2) ? \"YES\" : \"NO\"\n"}, {"source_code": "\ufeffdef diff(a, b)\n c = 0\n for i in 0..(a.length - 1)\n if a[i] == b[i]\n c += 1\n end\n end\n c\nend\n\na = gets.chomp.split \"\"\nb = gets.chomp.split \"\"\n\na.sort!\nb.sort!\n\nputs ((a == b) and diff(a, b) == 2) ? \"YES\" : \"NO\"\n"}, {"source_code": "\ufeffa = gets.chomp.split \"\"\nb = gets.chomp.split \"\"\n\na.sort!\nb.sort!\n\nputs (a == b) ? \"YES\" : \"NO\"\n"}, {"source_code": "a=gets.chomp.split(\"\")\nb=gets.chomp.split(\"\")\n\nif a.length !=b.length\n\tputs \"NO\"\nelsif a.sort != b.sort\n\tputs \"NO\"\nelsif a==b\n\tputs \"YES\"\nelsif a.reverse==b\n\tputs \"YES\"\nelse\n\nk=[]\n\t\n\t0.upto(a.length-1) do|i|\n\t\tk[i]=[a[i],b[i]]\n\tend\n\nk.each{|i| i.uniq!}\nk.sort! {|x,y| y.length <=> x.length}\nd=0\n\t\n\t0.upto(2) do |i|\n\t\tif k[i].length==2\n\t\t\td+=1\n\t\tend\n\tend\n\t\n\tif d<=1\n\t\tputs \"YES\"\n\telsif d>2\n\t\tputs \"NO\"\n\telse\n\t\tif k[0].reverse==k[1]\n\t\t\tputs \"YES\"\n\t\telse\n\t\t\tputs \"NO\"\n\t\tend\n\tend\n\nend\t"}, {"source_code": "a=gets\nb=gets\nif a.size != b.size\n puts \"NO\"\nelse\n s0=[]\n s1=[]\n (a.size-1).times do |i|\n puts i\n if a[i] != b[i]\n s0 << a[i]\n s1 << b[i]\n end\n end\n if s0.size!=2 || s0[1] != s1[0] || s0[0] != s1[1]\n puts \"NO\"\n else\n puts \"YES\"\n end\nend \n "}, {"source_code": "first_count = Hash.new(0)\nsecond_count = Hash.new(0)\n\na = gets.chomp\nb = gets.chomp\n\na.each_char do |i|\n\tfirst_count[i] += 1\nend\n\nb.each_char do |i|\n\tsecond_count[i] += 1\nend\n\nputs first_count == second_count ? \"YES\" : \"NO\""}, {"source_code": "as, bs = gets.chomp.chars.to_a, gets.chomp.chars.to_a\nfirst = true\nfirst_a, first_b = nil, nil\noutput = false\nas.each_with_index do |a, i|\n b = bs[i]\n if a != b\n if first\n first_a = a\n first_b = b\n first = false\n else\n puts a == first_b && b == first_a ? \"YES\" : \"NO\"\n output = true\n break\n end\n end\nend\n\nputs \"NO\" unless output\n"}, {"source_code": "as, bs = gets.chomp.chars.to_a, gets.chomp.chars.to_a\nfirst = true\nfirst_a, first_b = nil, nil\noutput = false\nanswer = \"NO\"\nas.each_with_index do |a, i|\n b = bs[i]\n if a != b\n if output\n answer = \"NO\"\n break\n end\n if first\n first_a = a\n first_b = b\n first = false\n else\n answer = \"YES\" if a == first_b && b == first_a\n output = true\n end\n end\nend\n\nputs answer\n"}, {"source_code": "def main\n a = STDIN.gets\n b = STDIN.gets\n\n return 'NO' if a.length != b.length\n\n i = 0\n i += 1 while a[i] == b[i]\n\n return 'YES' if i == a.length\n\n j = a.length - 1\n j -= 1 while a[j] == b[j]\n\n return 'YES' if j == i + 1 && a[i] == b[j] && a[j] == b[i]\n \n return 'NO'\nend\n\nprint main\n"}, {"source_code": "def say_no\n puts 'NO'\n exit\nend\n\ng1, g2 = [gets.chomp, gets.chomp]\nn = g1.size\nsay_no if n != g2.size\nd = []\nfor i in 0...n\n say_no if g1[i] != g2[i] && ((t = (d << i).size) > 2 || (t == 2 && (g1[d[0]] != g2[d[1]] || g1[d[1]] != g2[d[0]])))\nend\nputs 'YES'"}, {"source_code": "a , b = gets.strip, gets.strip\nac, bc = Hash.new(0), Hash.new(0)\n\na.each_char { |c| ac[c.to_sym] += 1 }\nb.each_char { |c| bc[c.to_sym] += 1 }\n\nprint ac == bc ? :YES : :NO\n"}, {"source_code": "a, b, c = gets.strip, gets.strip, 0\n(print :NO; exit) unless a.length == b.length\na.length.times { |i| c += 1 unless a[i] == b[i] }\nprint c == 2 ? :YES : :NO"}, {"source_code": "a, b = STDIN.read.split(\"\\n\")\na1, a2 = a.split('').uniq \nb1, b2 = b.split('').uniq\n\nac1 = a.count(a1)\nbc1 = b.count(b1)\n\nac2 = a2 ? a.count(a2) : 0\nbc2 = b2 ? b.count(b2) : 0\n\nprint ac1 == bc1 && ac2 == bc2 ? :YES : :NO"}], "src_uid": "c659bdeda1c1da08cfc7f71367222332"} {"source_code": "def make_fail(str)\n kmp = Array.new(str.length)\n i, j = [1, 0]\n kmp[0] = 0\n while (i < str.length) do\n kmp[i] = j\n while (j > 0 and str[i] != str[j]) do\n j = kmp[j]\n end\n i, j = i + 1, j + 1\n end\n return kmp\nend\n\ndef get_cycle(str, kmp)\n last = kmp.length - 1\n if kmp[last] == 0 or str[last] != str[kmp[last]]\n return str.length - 1\n else\n if last % (last - kmp[last]) == 0\n return last - kmp[last]\n end\n return last\n end\nend\n\ndef gcd(a, b)\n if b == 0\n return a\n end\n return gcd(b, a % b)\nend\n\ndef num_of_divisors(num)\n if num < 2\n return 1\n end\n i, cnt = 1, 0\n while i <= num do\n cnt = cnt + 1 if num % i == 0\n i = i + 1\n end\n return cnt\nend\n\ns1 = \" \" + gets.split.first\ns2 = \" \" + gets.split.first\n\nc1 = get_cycle(s1, make_fail(s1))\nc2 = get_cycle(s2, make_fail(s2))\nn1 = (s1.length - 1) / c1\nn2 = (s2.length - 1) / c2\n\n# puts n1.to_s + \" \" + n2.to_s\n\nif c1 != c2 or s1[1, c1] != s2[1, c2]\n # puts c1.to_s + \" \" + c2.to_s\n puts 0\nelse\n g = gcd(n1, n2)\n puts num_of_divisors(g)\nend\n", "positive_code": [{"source_code": "# ProblemD\n\ndef divisors(n)\n ret = []\n\n i = 1\n while i * i <= n\n if n % i == 0\n ret << i\n if (ret.index(n / i) == nil)\n ret << (n / i)\n end\n end\n i += 1\n end\n\n return ret\nend\n\ns1 = gets.chomp\ns2 = gets.chomp\n\nbase = \"\"\ntarget = \"\"\nif s1.size <= s2.size\n base = s1\n target = s2\nelse\n base = s2\n target = s1\nend\n\nbase_size = base.size\ntarget_size = target.size\n\nres = 0\n\nbase_divisors = divisors(base_size)\nbase_divisors.each do |base_divisor|\n tmp_str = base[0..base_divisor-1]\n if (tmp_str * (base_size / base_divisor)) == base\n if target_size % base_divisor == 0\n if (tmp_str * (target_size / base_divisor)) == target\n res += 1\n end\n end\n end\nend\n\nputs res\n"}], "negative_code": [{"source_code": "def make_fail(str)\n kmp = Array.new(str.length)\n i, j = [1, 0]\n kmp[0] = 0\n while (i < str.length) do\n kmp[i] = j\n while (j > 0 and str[i] != str[j]) do\n j = kmp[j]\n end\n i, j = i + 1, j + 1\n end\n return kmp\nend\n\ndef get_cycle(str, kmp)\n last = kmp.length - 1\n if kmp[last] == 0 or str[last] != str[kmp[last]]\n return str.length - 1\n else\n return last - kmp[last]\n end\nend\n\ndef gcd(a, b)\n if b == 0\n return a\n end\n return gcd(b, a % b)\nend\n\ndef num_of_divisors(num)\n if num < 2\n return 1\n end\n i, cnt = 1, 0\n while i <= num do\n cnt = cnt + 1 if num % i == 0\n i = i + 1\n end\n return cnt\nend\n\ns1 = \" \" + gets.split.first\ns2 = \" \" + gets.split.first\n\nc1 = get_cycle(s1, make_fail(s1))\nc2 = get_cycle(s2, make_fail(s2))\nn1 = (s1.length - 1) / c1\nn2 = (s2.length - 1) / c2\n\n# puts n1.to_s + \" \" + n2.to_s\n\nif c1 != c2 or s1[1, c1] != s2[1, c2]\n puts 0\nelse\n g = gcd(n1, n2)\n puts num_of_divisors(g) # if s1.length < 100\n # puts s1.length.to_s + \" \" + s2.length.to_s if s1.length > 100\nend\n"}, {"source_code": "def make_fail(str)\n kmp = Array.new(str.length)\n i, j = [1, 0]\n kmp[0] = 0\n while (i < str.length) do\n kmp[i] = j\n while (j > 0 and str[i] != str[j]) do\n j = kmp[j]\n end\n i, j = i + 1, j + 1\n end\n return kmp\nend\n\ndef get_cycle(str, kmp)\n last = kmp.length - 1\n if kmp[last] == 0 or str[last] != str[kmp[last]]\n return str.length - 1\n else\n return last - kmp[last]\n end\nend\n\ndef gcd(a, b)\n if b == 0\n return a\n end\n return gcd(b, a % b)\nend\n\ns1 = \" \" + gets.split.first\ns2 = \" \" + gets.split.first\n\nn1 = (s1.length - 1) / get_cycle(s1, make_fail(s1))\nn2 = (s2.length - 1) / get_cycle(s2, make_fail(s2))\n\n# puts n1.to_s + \" \" + n2.to_s\n\nif !(s1.include? s2) and !(s2.include? s2)\n puts 0\nelse\n g = gcd(n1, n2)\n i = 1\n cnt = 0\n while i * i <= g do\n if g % i == 0\n cnt = cnt + 1\n end\n i = i + 1\n end\n\n cnt = cnt + 1 if g != 1\n\n puts cnt\nend\n"}, {"source_code": "def make_fail(str)\n kmp = Array.new(str.length)\n i, j = [1, 0]\n kmp[0] = 0\n while (i < str.length) do\n kmp[i] = j\n while (j > 0 and str[i] != str[j]) do\n j = kmp[j]\n end\n i, j = i + 1, j + 1\n end\n return kmp\nend\n\ndef get_cycle(str, kmp)\n last = kmp.length - 1\n if kmp[last] == 0 or str[last] != str[kmp[last]]\n return str.length - 1\n else\n return last - kmp[last]\n end\nend\n\ndef gcd(a, b)\n if b == 0\n return a\n end\n return gcd(b, a % b)\nend\n\ndef num_of_divisors(num)\n if num < 2\n return 1\n end\n i, cnt = 2, 2\n while i * i <= num do\n cnt = cnt + 1 if num % i == 0\n i = i + 1\n end\n return cnt\nend\n\ns1 = \" \" + gets.split.first\ns2 = \" \" + gets.split.first\n\nn1 = (s1.length - 1) / get_cycle(s1, make_fail(s1))\nn2 = (s2.length - 1) / get_cycle(s2, make_fail(s2))\n\n# puts n1.to_s + \" \" + n2.to_s\n\nif !(s1.include? s2) and !(s2.include? s2)\n puts 0\nelse\n g = gcd(n1, n2)\n puts num_of_divisors(g) if s1.length < 100\n puts s1.length.to_s + \" \" + s2.length.to_s if s1.length > 100\nend\n"}, {"source_code": "def make_fail(str)\n kmp = Array.new(str.length)\n i, j = [1, 0]\n kmp[0] = 0\n while (i < str.length) do\n kmp[i] = j\n while (j > 0 and str[i] != str[j]) do\n j = kmp[j]\n end\n i, j = i + 1, j + 1\n end\n return kmp\nend\n\ndef get_cycle(str, kmp)\n last = kmp.length - 1\n if kmp[last] == 0 or str[last] != str[kmp[last]]\n return str.length - 1\n else\n return last - kmp[last]\n end\nend\n\ndef gcd(a, b)\n if b == 0\n return a\n end\n return gcd(b, a % b)\nend\n\ndef num_of_divisors(num)\n if num < 2\n return 1\n end\n i, cnt = 1, 0\n while i <= num do\n cnt = cnt + 1 if num % i == 0\n i = i + 1\n end\n return cnt\nend\n\ns1 = \" \" + gets.split.first\ns2 = \" \" + gets.split.first\n\nn1 = (s1.length - 1) / get_cycle(s1, make_fail(s1))\nn2 = (s2.length - 1) / get_cycle(s2, make_fail(s2))\n\n# puts n1.to_s + \" \" + n2.to_s\n\nif !(s1.include? s2) and !(s2.include? s1)\n puts 0\nelse\n g = gcd(n1, n2)\n puts num_of_divisors(g) # if s1.length < 100\n # puts s1.length.to_s + \" \" + s2.length.to_s if s1.length > 100\nend\n"}, {"source_code": "def make_fail(str)\n kmp = Array.new(str.length)\n i, j = [1, 0]\n kmp[0] = 0\n while (i < str.length) do\n kmp[i] = j\n while (j > 0 and str[i] != str[j]) do\n j = kmp[j]\n end\n i, j = i + 1, j + 1\n end\n return kmp\nend\n\ndef get_cycle(str, kmp)\n last = kmp.length - 1\n if kmp[last] == 0 or str[last] != str[kmp[last]]\n return str.length - 1\n else\n return last - kmp[last]\n end\nend\n\ndef gcd(a, b)\n if b == 0\n return a\n end\n return gcd(b, a % b)\nend\n\ndef num_of_divisors(num)\n if num < 2\n return 1\n end\n i, cnt = 1, 0\n while i <= num do\n cnt = cnt + 1 if num % i == 0\n i = i + 1\n end\n return cnt\nend\n\ns1 = \" \" + gets.split.first\ns2 = \" \" + gets.split.first\n\nn1 = (s1.length - 1) / get_cycle(s1, make_fail(s1))\nn2 = (s2.length - 1) / get_cycle(s2, make_fail(s2))\n\n# puts n1.to_s + \" \" + n2.to_s\n\nif !(s1.include? s2) and !(s2.include? s2)\n puts 0\nelse\n g = gcd(n1, n2)\n puts num_of_divisors(g) # if s1.length < 100\n # puts s1.length.to_s + \" \" + s2.length.to_s if s1.length > 100\nend\n"}, {"source_code": "# ProblemD\n\ns1 = gets.chomp\ns2 = gets.chomp\n\nbase = \"\"\ntarget = \"\"\nif s1.size <= s2.size\n base = s1\n target = s2\nelse\n base = s2\n target = s1\nend\n\nbase_size = base.size\ntarget_size = target.size\n\nres = 0\nbase.size.times do |i|\n tmp_str = base[0..i]\n if target.start_with?(tmp_str)\n n = i + 1\n if (base_size % n == 0) && (target_size % n == 0)\n if tmp_str * (base_size / n) == base && tmp_str * (target_size / n) == target\n puts tmp_str\n res += 1\n end\n end\n end\nend\n\nputs res\n"}], "src_uid": "d28614f0365ea53530e35c6bd1e6f1dd"} {"source_code": "s = gets.chomp\nh = Hash.new(0)\ncount = 0\nstk = [-1]\n(0...s.length).each { |i|\n\ta = s[i]\n\tif a == \"(\"\n\t\tstk.push(i)\n\telse\n\t\tstk.pop\n\t\tif stk.empty?\n\t\t\tstk.push(i)\n\t\telse\n\t\t\th[i - stk.last] += 1\n\t\tend\n\tend\n}\nv, c = h.sort_by { |k, v| k }.last\nc = 1 if !v || v == 0\nputs \"#{v.to_i} #{c.to_i}\"\n", "positive_code": [{"source_code": "s = gets.chomp\n\ndiff = 0\nmatch = []\nstack = []\n\n(0...(s.size)).each do |i|\n\tif s[i] == '('\n\t\tdiff += 1\n\t\tstack << i\n\telsif s[i] == ')' and diff > 0\n\t\tdiff -= 1\n\t\tindex = stack.pop\n\t\tmatch[index] = i\n\tend\nend\n\ntime = 0\nmax = 0\nrecord = Array.new(s.size)\n(0...s.size).each do |i|\n\ttotal = 0\n\tif (not match[i].nil?) and record[i].nil?\n\t\trecord[i] = true\n\t\ttotal += (match[i] - i + 1)\n\t\tj = match[i] + 1\n\t\twhile match[j] != nil\n\t\t\ttotal += (match[j] - j + 1)\n\t\t\trecord[j] = true\n\t\t\tj = match[j] + 1\n\t\tend\n\t\t\n\t\tif max < total\n\t\t\tmax = total\n\t\t\ttime = 1\n\t\telsif max == total\n\t\t\ttime += 1\n\t\tend\n\tend\nend\n\ntime = 1 if max == 0\n\nputs \"#{max} #{time}\"\n"}, {"source_code": "line = gets\nline.strip!\nlongest = [] # )\u5bf9\u5e94\u7684\u6700\u957f\u7684sequence\u957f\u5ea6\nopn = []\ni = 0\nline.each_char do |ch|\n\tif ch == '('\n\t\topn << i\n\telse\n\t\tif opn.empty?\n\t\t\tlongest[i] = -1\n\t\telse\n\t\t\trelative = opn.pop\n\t\t\tlongest[i] = i - relative + 1 # \u4e0d\u662f\u6700\u4f18\uff0c\u9700\u8981\u5411\u524d\u641c\u7d22\n\t\t\tif relative > 0 && line[relative - 1] == \")\" && longest[relative - 1] != -1\n\t\t\t\tlongest[i] += longest[relative - 1]\n\t\t\tend\n\t\tend\n\tend\n\ti += 1\nend\nmax = 0\ncnt = 1\n# \u4e0d\u80fd\u4f7f\u7528.max\u65b9\u6cd5\uff0c\u56e0\u4e3a\u6570\u7ec4\u4e2d\u6709nil\uff0c\u4e0d\u80fd\u5c06nil\u4e0e\u6574\u6570\u76f8\u6bd4\u8f83\nlongest.each do |item|\n\tif item && (item > max)\n\t\tmax = item\n\t\tcnt = 1\n\telsif item == max\n\t\tcnt += 1\n\tend\nend\nputs \"#{max} #{cnt}\""}, {"source_code": "str = gets\nc = Array.new\nstack = Array.new\ni = 0\nstr.strip!\nstr.each_char do |s|\n if s==\"(\"\n stack << i\n else\n if stack.empty?\n c[i]=-1\n else\n corr=stack.pop\n c[i]=i-corr+1\n if corr>0 and c[corr-1] and c[corr-1]!=-1\n c[i]+=c[corr-1]\n end\n end\n end\n i+=1\nend\nmax=0\ncnt=1\nc.each do |cc|\n if cc and cc>max\n max=cc\n cnt=1\n elsif cc==max\n cnt+=1\n end\nend\nputs \"#{max} #{cnt}\"\n"}], "negative_code": [{"source_code": "s = gets.chomp\nh = Hash.new(0)\ncount = 0\nstk = []\n(0...s.length).each { |i|\n\ta = s[i]\n\tif a == \"(\"\n\t\tstk.push(a)\n\telse\n\t\tif stk.last == \"(\"\n\t\t\tstk.pop\n\t\t\tcount += 2\n\t\telse\n\t\t\tcount = 0\n\t\tend\n\t\th[count] += 1\n\tend\n}\nv, c = h.sort_by { |k, v| k }.last\nc = 1 if !v\nputs \"#{v.to_i} #{c.to_i}\"\n"}, {"source_code": "s = gets.chomp\nh = Hash.new(0)\ncount = 0\nstk = []\n(0...s.length).each { |i|\n\ta = s[i]\n\tif a == \"(\"\n\t\tstk.push(a)\n\telse\n\t\tif stk.last == \"(\"\n\t\t\tstk.pop\n\t\t\tcount += 2\n\t\telse\n\t\t\tcount = 0\n\t\tend\n\t\th[count] += 1\n\tend\n}\nv, c = h.sort_by { |k, v| k }.last\nc = 1 if !v || v == 0\nputs \"#{v.to_i} #{c.to_i}\"\n"}, {"source_code": "s = gets.chomp\nh = Hash.new(0)\ncount = 0\nstk = []\n(0...s.length).each { |i|\n\ta = s[i]\n\tif a == \"(\"\n\t\tstk.push(a)\n\telse\n\t\tif stk.last == \"(\"\n\t\t\tstk.pop\n\t\t\tcount += 2\n\t\t\th[count] += 1\n\t\telse\n\t\t\tcount = 0\n\t\tend\n\tend\n}\nv, c = h.sort_by { |k, v| v }.last\nc = 1 if !v\nputs \"#{v.to_i} #{c.to_i}\"\n"}, {"source_code": "s = gets.chomp\n\ndiff = 0\nmatch = []\nstack = []\n\n(0...(s.size)).each do |i|\n\tif s[i] == '('\n\t\tdiff += 1\n\t\tstack << i\n\telsif s[i] == ')' and diff > 0\n\t\tdiff -= 1\n\t\tindex = stack.pop\n\t\tmatch[index] = i\n\t\tmatch[i] = index\n\tend\nend\n\nmax = -1\ntime = 0\n(0...s.size).each do |i|\n\tnext if match[i].nil?\n\n\tif max < (i - match[i]).abs\n\t\tmax = (i - match[i]).abs\n\t\ttime += 1\n\telsif max == (i - match[i]).abs\n\t\ttime += 1\n\tend\n\nend\n\ntime = 2 if max == -1\n\nputs \"#{max + 1} #{time / 2}\"\n"}], "src_uid": "91c3af92731cd7d406674598c0dcbbbc"} {"source_code": "n=gets.split[0].to_i;a=(R=0...n).map{gets.split[0].to_i};b=[0]+[M=8192]*M;q=0;R.each{|i|c=0;s=M;c+=s if b[c+(s>>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q0) do \n\t\tc+=s if b[c+s]<=a[i]\n\t\ts>>=1\n\tend\n\tb[c+1]=a[i]\nend\nc=M-1;\nwhile (b[c]>=M) do \n c-=1\nend\np a.size-c\n"}, {"source_code": "n=(a=STDIN.read.split(\"\\n\")[1..-1].map{|x|x.split[0].to_i}).size\nb=[0]+[M=9999]*M\nfor i in 0...n \n\tc=0;s=8192;\n\tc+=s if b[c+(s>>=1)]<=a[i] while s>0 \n\tb[c+1]=a[i]\nend\nc=M-1;\nwhile (b[c]>=M) do \n c-=1\nend\np n-c\n"}, {"source_code": "n=gets.split[0].to_i;a=(0...n).map{gets.split[0].to_i};b=[0]+[M=9999]*M;q=0;for i in 0...n\nc=0;s=8192;c+=s if b[c+(s>>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q>=1)]<=a[i] while s>0;b[c+1]=a[i]\nend\nc=M;c-=1 while b[c]>=M;p n-c"}, {"source_code": "n=gets.split[0].to_i;a=(R=0...n).map{gets.split[0].to_i};b=[0]+[M=8192]*M;q=0;R.each{|i|c=0;s=M;c+=s if b[c+(s>>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q>=1)]<=a[i] while s>0;b[c+1]=a[i];q=c if q 0 && g > 0 && b > 0\n r -= 1\n g -= 1\n b -= 1\n w += 3\n if sum % 2 == 0\n if r%2==0 && g%2==0 && b%2==0 && w%2==0\n ans << \"YES\"\n next\n end\n else\n judge = 0\n judge += 1 if r%2==1\n judge += 1 if g%2==1\n judge += 1 if b%2==1\n judge += 1 if w%2==1\n if judge == 1\n ans << \"YES\"\n next\n end\n end\n end\n ans << \"NO\"\nend\nans.each do |s|\n puts s\nend", "positive_code": [{"source_code": "gets.to_i.times do\n arr = gets.split(' ').map(&:to_i)\n even_number = arr.count { |num| num.even? }\n \n if even_number >= 3\n puts 'Yes'\n elsif even_number == 2\n puts 'No'\n elsif arr.take(3).include?(0)\n puts 'No'\n else\n puts 'Yes'\n end \nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n\tr, g, b, w = gets.split.map &:to_i\n\tis_ok = [r, g, b, w].count(&:odd?) < 2\n\tis_ok ||= [r, g, b].min > 0 && [r-1, g-1, b-1, w+3].count(&:odd?) < 2\n\tputs (is_ok ? \"Yes\" : \"No\")\nend"}], "negative_code": [{"source_code": "gets.to_i.times do\n arr = gets.split(' ').map(&:to_i)\n even_number = arr.count { |num| num.even? }\n \n if even_number >= 3\n puts 'Yes'\n elsif even_number == 2\n puts 'No'\n elsif arr.include?(0)\n puts 'No'\n else\n puts 'Yes'\n end \nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n\tr, g, b, w = gets.split.map &:to_i\n\tis_ok = [r, g, b, w].count(&:odd?) < 2\n\tis_ok ||= [r, g, b].min > 0 && [r-1, g-1, b-1, w].count(&:odd?) < 2\n\tputs (is_ok ? \"Yes\" : \"No\")\nend"}, {"source_code": "t = gets.to_i\nt.times do\n\tr, g, b, w = gets.split.map &:to_i\n\tis_ok = [r, g, b, w].count(&:odd?) < 2\n\tis_ok ||= [r, g, b].min > 0 && [r-1, g-1, b-1, w].count(&:odd?)\n\tputs (is_ok ? \"Yes\" : \"No\")\nend"}], "src_uid": "749a106d462555543c91753f00a5a479"} {"source_code": "n,a=gets.to_i,[]\nexit !puts('-1')if n%4>1\n1.step(n/2,2){|i|a[i]=n-i;a[i+1]=i;a[n-i]=n-i+1;a[n-i+1]=i+1}\na[n/2+1]=n/2+1 if n.odd?\nputs a.join' '\n", "positive_code": [{"source_code": "n,a=gets.to_i,[]\nexit !puts('-1')if n%4>1\n1.step(n/2,2){|i|a[i]=n-i;a[i+1]=i;a[n-i]=n-i+1;a[n-i+1]=i+1}\na[n/2+1]=n/2+1 if n.odd?\nputs a.join' '\n"}, {"source_code": "n,a=gets.to_i,[]\nexit !puts('-1')if n%4>1\n1.step(n/2,2){|i|a[i]=n-i;a[i+1]=i;a[n-i]=n-i+1;a[n-i+1]=i+1}\na[n/2+1]=n/2+1 if n.odd?\nputs a.join' '\n"}, {"source_code": "n,a=gets.to_i,[]\nexit !puts('-1')if n%4>1\n1.step(n/2,2){|i|a[i]=n-i;a[i+1]=i;a[n-i]=n-i+1;a[n-i+1]=i+1}\na[n/2+1]=n/2+1 if n.odd?\nputs a.join' '\n"}, {"source_code": "n = gets.to_i\n\np = [0]*n\n\n#puts \"#{n} --- #{p}\"\n\nif n%4!=0 and n%4!=1\n\tputs -1\nelse\n\tk = n/4\n\t(1..k).each { |t|\n#\t puts \"#{v} #{k}\"\n v = 2*t-1\n\t\tp[v-1]=v+1\n\t\tp[v] = n-v+1\n\t\tp[n-v] = n-v\n\t\tp[n-v-1] = v\n\t}\n\tif n%2==1\n\t\tp[2*k]=2*k+1\n\tend\n\tputs p.join(\" \")\nend\n\n"}, {"source_code": "n,a=gets.to_i,[]\nexit !puts('-1')if n%4>1\n1.step(n/2,2){|i|a[i]=n-i;a[i+1]=i;a[n-i]=n-i+1;a[n-i+1]=i+1}\na[n/2+1]=n/2+1 if n.odd?\nputs a.join' '\n"}, {"source_code": "n,a=gets.to_i,[]\nexit !puts('-1')if n%4>1\n1.step(n/2,2){|i|a[i]=n-i;a[i+1]=i;a[n-i]=n-i+1;a[n-i+1]=i+1}\na[n/2+1]=n/2+1 if n.odd?\nputs a.join' '\n"}, {"source_code": "n,a=gets.to_i,[]\nexit !puts('-1')if n%4>1\n1.step(n/2,2){|i|a[i]=n-i;a[i+1]=i;a[n-i]=n-i+1;a[n-i+1]=i+1}\na[n/2+1]=n/2+1 if n.odd?\nputs a.join' '"}, {"source_code": "N = gets.chomp.to_i\na = Array.new(N+1)\nif N.modulo(4) <= 1\n (1..N/2).step(2) do |i|\n a[i], a[i+1], a[N-i+1], a[N-i] = i+1, N-i+1, N-i, i\n end\n a[N / 2 + 1] = N / 2 + 1 if N % 2 == 1\n puts a[1..N].join(' ') \nelsif\n puts \"-1\"\nend"}, {"source_code": "N = gets.chomp.to_i\na = Array.new(N+1)\nif N.modulo(4) <= 1\n (1..N/2).step(2) do |i|\n a[i], a[i+1], a[N-i+1], a[N-i] = i+1, N-i+1, N-i, i\n end\n a[N / 2 + 1] = N / 2 + 1 if N % 2 == 1\n puts a[1..N].join(' ') \nelsif\n puts \"-1\"\nend"}, {"source_code": "n,a=gets.to_i,[]\nexit !puts('-1')if n%4>1\n1.step(n/2,2){|i|a[i]=n-i;a[i+1]=i;a[n-i]=n-i+1;a[n-i+1]=i+1}\na[n/2+1]=n/2+1 if n.odd?\nputs a.join' '"}, {"source_code": "n,a=gets.to_i,[]\nexit !puts('-1')if n%4>1\n1.step(n/2,2){|i|a[i]=n-i;a[i+1]=i;a[n-i]=n-i+1;a[n-i+1]=i+1}\na[n/2+1]=n/2+1 if n.odd?\nputs a.join' '\n"}, {"source_code": "n = gets.to_i\n\nif n % 4 == 2 || n % 4 == 3 then\n puts \"-1\"\n exit\nend \n\nret = Array.new(n, 0)\nret[n / 2] = n / 2 if n % 2\ni = 0\nwhile i < n / 2 do\n ret[i], ret[i + 1], ret[n - 2 - i], ret[n - 1 - i] = i + 1, n - 1 - i, i, n - 2 - i\n i += 2\nend\n\nret.map!{ |i| i + 1 }\nputs ret.join(' ')"}, {"source_code": "n,a=gets.to_i,[]\nexit !puts('-1')if n%4>1\n1.step(n/2,2){|i|a[i]=n-i;a[i+1]=i;a[n-i]=n-i+1;a[n-i+1]=i+1}\na[n/2+1]=n/2+1 if n.odd?\nputs a.join' '\n"}, {"source_code": "n = gets.to_i;\n\nif n % 4 > 1 \n puts \"-1\"\nelse\n a = Array.new(n);\n (1..(n/4)).each{|i|\n j = (i-1)*2 + 1;\n a[j-1] = j+1;\n a[j] = n - j + 1;\n a[n-j] = n - j;\n a[n-j-1] = j;\n }\n a[n/2] = n/2+1 if n % 4 ==1\n puts a.join(' ');\nend\n"}], "negative_code": [{"source_code": "n = gets.to_i\n\np = [0]*n\n\n#puts \"#{n} --- #{p}\"\n\nif n%4!=0 and n%4!=1\n\tputs -1\nelse\n\tk = n/4\n\t(1..k).each { |v|\n#\t puts \"#{v} #{k}\"\n\t\tp[v-1]=v+1\n\t\tp[v] = n-v+1\n\t\tp[n-v] = n-v\n\t\tp[n-v-1] = v\n\t}\n\tif n%2==1\n\t\tp[2*k]=2*k+1\n\tend\n\tputs p.join(\" \")\nend\n\n"}], "src_uid": "dfca19b36c1d682ee83224a317e495e9"} {"source_code": "n = gets.chomp.to_i\nhs = Hash.new(0)\nfor c0 in 'a'..'y'\n for c1 in 'a'..'z'\n hs[c0 + c1] = 0 if c0 < c1\n end\nend\n\nn.times do\n line = gets.chomp\n cs = line.split('').sort.uniq\n if cs.size == 1\n hs[cs[0]] += line.size\n elsif cs.size == 2\n hs[cs[0] + cs[1]] += line.size\n end\nend\n\nrtn = 0\n\nhs.each do |k, v|\n if k.size == 2\n hs[k] += hs[k[0]] + hs[k[1]]\n end\nend\n\nhs.each do |k, v|\n rtn = [rtn, v].max\nend\n\nputs rtn\n", "positive_code": [{"source_code": "require 'set'\n\nfile = File.exist?('in.in') ? File.new('in.in', 'r') : STDIN\n\ndef init_both(char1,char2)\n total = 0\n [char1,char2].each do |char|\n if @global_count[char]\n total += @global_count[char]\n end\n end\n total\nend\n\nn = file.gets.to_i\n@global_count = {}\nglobal_words = {}\n\nwhile n > 0 do\n n -= 1\n word = file.gets.chomp\n\n valid_word = true\n char1 = word.chars.first\n char2 = nil\n current_count = {}\n word.chars.each do |char|\n char2 ||= char if char != char1\n if char != char1 && char != char2\n valid_word = false\n break\n end\n current_count[char] ||= 0\n current_count[char] += 1\n end\n if valid_word\n if char2\n both_key = \"#{char1}#{char2}\".chars.sort.join\n @global_count[both_key] ||= init_both(char1,char2)\n @global_count[both_key] += word.length\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add both_key\n global_words[char2] ||= Set.new [char2]\n global_words[char2].add both_key\n else\n @global_count[char1] ||= 0\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add char1\n\n global_words[char1].each do |char|\n @global_count[char] += word.length\n end\n end\n end\nend\n# Generate all possible combinations for every single word with word.length == 1\nglobal_words.each do |k,v|\n\tif k.length == 1\n\t\tglobal_words.each do |q,b|\n\t\t\tboth_key = \"#{q}#{k}\".chars.sort.join\n\t\t\tif q != k && q.length == 1\n\t\t\t\tglobal_words[k].add both_key\n\t\t\t\t@global_count[both_key] ||= init_both(k,q)\n\t\t\tend\n\t\tend\n\tend\nend\n\n@global_count = @global_count.sort {|a1,a2| a2[1] <=> a1[1] }\n@global_count = Hash[*@global_count.flatten]\nputs @global_count.values.first || 0"}, {"source_code": "ws = []\ngets.to_i.times do\n ws << gets.strip\nend\n\nm = 0\n('a'..'z').each do |c1|\n ('a'..'z').each do |c2|\n s = ws.select {|w| w.chars.all?{|c| c == c1 || c == c2 } }.join.size\n m = [m, s].max\n end\nend\np m\n"}, {"source_code": "def get_arr(arr)\n a = arr[0]\n b = arr.delete(a)[0]\n return [a,b]\nend\n\ndef exist?(arr, arr1)\n arr.each do |x|\n if x == arr1\n return true\n break\n end\n end\n false\nend\nn = gets.chomp.to_i\nx, arr, array, len, arr1, l1, sum = [], [], [], [0], [], [], 0\n(1..n).each do |i|\n a = gets.chomp\n t = String.new(a)\n num = 0\n a.each_char do |x|\n if a.delete(x) != a\n a.delete!(x)\n num += 1\n end\n if num == 3\n break\n end\n end\n if num < 3\n arr << t\n end\nend\narr.each_with_index do |arr1, index1|\n len[index1] = arr1.length\n if !exist?(array, arr1)\n arr.each_with_index do |arr2, index2|\n if index1 == index2\n next\n else\n if get_arr(arr1) == get_arr(arr2) || get_arr(arr1).reverse == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)\n len[index1] += arr2.length\n end\n end\n end\n array << get_arr(arr1)\n end\nend\nl = len.sort.last\narr.each do |a|\n if a.squeeze.length == 1\n arr1 << a.squeeze\n end\nend\nif arr1.length > 0\n arr1.uniq.each do |a1|\n sum = 0\n arr.each do |a|\n if a1 == a.squeeze\n sum += a.length\n end\n end\n l1 << sum\n end\n l1.sort!\n p l1.last + l1[l1.length-2] > l && l1.length > 1 ? l1.last + l1[l1.length-2] : l\nelse\n p l\nend\n"}, {"source_code": "# Problem: http://codeforces.com/contest/593/problem/A\na = []\nrs = [0]\ngets.to_i.times {a << gets.chomp }\nfor i in ('a'..'z')\n for j in (i..'z')\n sum = 0\n a.each do |s|\n continue = true\n s.split(\"\").each do |c|\n if c != i and c != j\n continue = false\n end\n end\n if continue == true\n sum += s.size\n end\n end\n if sum > 0\n rs << sum\n end\n end\nend\nputs rs.max\n"}, {"source_code": "# Problem: http://codeforces.com/contest/593/problem/A\na = []\nrs = [0]\ngets.to_i.times {a << gets.chomp }\nfor i in ('a'..'z')\n for j in (i..'z')\n sum = 0\n a.each do |s|\n continue = true\n s.size.times do |k|\n if s[k] != i and s[k] != j\n continue = false\n end\n end\n if continue == true\n sum += s.size\n end\n end\n if sum > 0\n rs << sum\n end\n end\nend\nputs rs.max\n"}, {"source_code": "# Problem: http://codeforces.com/contest/593/problem/A\na = []\nd = Hash.new 0\ngets.to_i.times {a << gets.chomp }\na.each do |s|\n s_asize = s.size\n s_uniq = s.split(\"\").uniq\n s_size = s_uniq.size\n if s_size > 2\n next\n end\n if s_size == 1\n c = s_uniq.pop\n d[c] += s_asize\n d.keys.each do |k|\n if k.size == 2 and k.include? c\n d[k] += s_asize\n elsif k.size == 1 and k != c\n new_k = [k, c].sort.join\n if d[new_k] == 0\n d[new_k] = d[k] + d[c]\n end\n end\n end\n end\n if s_size == 2\n k = s_uniq.sort.join\n if d[k] == 0\n s_uniq.each { |t| d[k] += d[t] }\n end\n d[k] += s_asize\n end\nend\nif d.empty?\n puts 0\nelse\n puts d.values.max\nend\n"}, {"source_code": "def max(a, b)\n return a > b ? a : b\nend\nn = gets.chomp.to_i\nv = []\nfor i in(1..n)\n v[i-1] = gets.chomp\nend\nc = 0\nfor i in('a'..'z')\n for j in(i..'z')\n c1 = 0\n for x in(1..n)\n sw = 0\n for y in(0..(v[x-1].size-1))\n if v[x-1][y] == i || v[x-1][y] == j\n else\n sw = 1\n end\n end\n if sw==0\n c1+=v[x-1].size\n end\n end\n c = max(c,c1)\n end\nend\nputs c\n"}, {"source_code": "n = gets.chomp.to_i\nd = Hash.new(0)\nn.times do\n word = gets.chomp\n k = word.split(\"\").uniq.sort\n v = word.length\n d[k] += v if k.length <= 2\nend\nres = 0\n(?a..?z).to_a.combination(2) do |kk|\n res = [res, d[[kk[0]]] + d[[kk[1]]] + d[kk]].max\nend\nputs res"}, {"source_code": "a=(\"a\" .. \"z\" ).to_a\nhash={}\n0.upto(25) {|i| hash[a[i]]=i }\ngrid = Array.new(26) { Array.new(26,0) }\na=gets.chomp.to_i\na.times do\ntemp=gets.chomp.split(\"\")\nt1=temp.length\ntemp.uniq!\nt2=temp.length\nif t2<3\nif t2==1\nr=hash[temp[0]]\nc=hash[temp[0]]\ngrid[r][c]+=t1\nelse\nr=hash[temp[0]]\nc=hash[temp[1]]\ngrid[r][c]+=t1\ngrid[c][r]+=t1\nend\nend\nend\nans=0\n\n0.upto(25) do |i|\n0.upto(25) do |j|\nif i!=j\ntemp=grid[i][i]+grid[i][j]+grid[j][j]\nif temp>ans\nans=temp\nend\nend\nend\nend\nputs \"#{ans}\""}, {"source_code": "def get_array(arr)\n a = arr[0]\n b = arr.delete(a)[0]\n return [a,b]\nend\nn = gets.chomp.to_i\nx, arr, len, arr1, l1, sum = [], [], [0], [], [], 0 #len\u521d\u59cb\u5316\u4e3a0\uff0c\u9632\u6b62\u6240\u6709\u8f93\u5165\u90fd\u4e0d\u7b26\u5408\uff0c\u8fd4\u56de0\n(1..n).each do |i|\n a = gets.chomp\n t = String.new(a)\n num = 0\n a.each_char do |x|\n if a.delete(x) != a\n a.delete!(x)\n num += 1\n end\n break if num == 3\n end\n arr << t if num < 3\nend\narr.each_with_index do |arr1, index1|\n len[index1] = arr1.length\n arr.each_with_index do |arr2, index2|\n next if index1 == index2\n len[index1] += arr2.length if get_array(arr1) == get_array(arr2) || get_array(arr1).reverse == get_array(arr2) || arr1.squeeze.include?(arr2.squeeze)\n end\nend\nl = len.sort.last\narr.each do |a|\n arr1 << a.squeeze if a.squeeze.length == 1\nend\nif arr1.length > 0 #\u6392\u9664\u8d85\u8fc7\u4e00\u79cd\u5b57\u7b26\u7684\u884c,\u8fd9\u91cc\u64cd\u4f5c\u6bcf\u884c\u90fd\u662f\u4e00\u79cd\u5b57\u7b26\u7684\u60c5\u51b5\n arr1.uniq.each do |a1|\n sum = 0\n arr.each do |a|\n sum += a.length if a1 == a.squeeze\n end\n l1 << sum\n end\n l1.sort!\n p l1.last + l1[l1.length-2] > l && l1.length > 1 ? l1.last + l1[l1.length-2] : l\nelse\n p l\nend"}, {"source_code": "def get_arr(arr)\n a = arr[0]\n b = arr.delete(a)[0]\n return [a,b]\nend\n# def exist?(arr, arr1)\n# arr.each do |x|\n# if x == arr1\n# true\n# break\n# end\n# end\n# false\n# end\nn = gets.chomp.to_i\nx, arr, array, len, arr1, l1, sum = [], [], [], [0], [], [], 0\n(1..n).each do |i|\n a = gets.chomp\n t = String.new(a)\n num = 0\n a.each_char do |x|\n if a.delete(x) != a\n a.delete!(x)\n num += 1\n end\n if num == 3\n break\n end\n end\n if num < 3\n arr << t\n end\nend\narr.each_with_index do |arr1, index1|\n len[index1] = arr1.length\n # if !exist?(array, arr1)\n arr.each_with_index do |arr2, index2|\n if index1 == index2\n next\n else\n if get_arr(arr1) == get_arr(arr2) || get_arr(arr1).reverse == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)\n len[index1] += arr2.length\n end\n end\n end\n array << get_arr(arr1)\n # end\nend\nl = len.sort.last\narr.each do |a|\n if a.squeeze.length == 1\n arr1 << a.squeeze\n end\nend\nif arr1.length > 0\n arr1.uniq.each do |a1|\n sum = 0\n arr.each do |a|\n if a1 == a.squeeze\n sum += a.length\n end\n end\n l1 << sum\n end\n l1.sort!\n p l1.last + l1[l1.length-2] > l && l1.length > 1 ? l1.last + l1[l1.length-2] : l\nelse\n p l\nend\n"}, {"source_code": "require 'set'\n\nfile = File.exist?('in.in') ? File.new('in.in', 'r') : STDIN\n\ndef init_both(char1,char2)\n total = 0\n words = []\n [char1,char2].each do |char|\n if @global_count[char]\n total += @global_count[char].total\n words << @global_count[char].words\n end\n end\n Pair.new(total, words.flatten)\nend\n\nn = file.gets.to_i\nPair = Struct.new(:total, :words)\n@global_count = {}\nglobal_words = {}\n\nwhile n > 0 do\n n -= 1\n word = file.gets.chomp\n\n valid_word = true\n char1 = word.chars.first\n char2 = nil\n current_count = {}\n word.chars.each do |char|\n char2 ||= char if char != char1\n if char != char1 && char != char2\n valid_word = false\n break\n end\n current_count[char] ||= 0\n current_count[char] += 1\n end\n if valid_word\n if char2\n both_key = \"#{char1}#{char2}\".chars.sort.join\n @global_count[both_key] ||= init_both(char1,char2)\n @global_count[both_key].total += word.length\n @global_count[both_key].words << word\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add both_key\n global_words[char2] ||= Set.new [char2]\n global_words[char2].add both_key\n else\n @global_count[char1] ||= Pair.new(0, [])\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add char1\n\n global_words[char1].each do |char|\n @global_count[char].total += word.length\n @global_count[char].words << word\n end\n end\n end\nend\nglobal_words.each do |k,v|\n\tif k.length == 1\n\t\tglobal_words.each do |q,b|\n\t\t\tboth_key = \"#{q}#{k}\".chars.sort.join\n\t\t\tif q != k && q.length == 1\n\t\t\t\tglobal_words[k].add both_key\n\t\t\t\t@global_count[both_key] ||= init_both(k,q)\n\t\t\tend\n\t\tend\n\tend\nend\n@global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }\n@global_count = Hash[*@global_count.flatten]\n# puts @global_count\n# puts global_words\nif @global_count.values.first\n answer = @global_count.values.first.total\n puts answer || 0\nelse\n puts 0\nend"}], "negative_code": [{"source_code": "# Problem: http://codeforces.com/contest/593/problem/A\na = []\nd = Hash.new 0\ngets.to_i.times {a << gets.chomp }\na.each do |s|\n s_asize = s.size\n s_uniq = s.split(\"\").uniq\n s_size = s_uniq.size\n if s_size > 2\n next\n end\n if s_size == 1\n c = s_uniq.pop\n d[c] += s_asize\n d.keys.each do |k|\n if k.size == 2 and k.include? c\n d[k] += s_asize\n end\n end\n end\n if s_size == 2\n k = s_uniq.sort.join\n d[k] += s_asize\n end\nend\nputs d.values.max\n"}, {"source_code": "# Problem: http://codeforces.com/contest/593/problem/A\na = []\nd = Hash.new 0\ngets.to_i.times {a << gets.chomp }\na.each do |s|\n s_asize = s.size\n s_uniq = s.split(\"\").uniq\n s_size = s_uniq.size\n if s_size > 2\n next\n end\n if s_size == 1\n c = s_uniq.pop\n d[c] += s_asize\n d.keys.each do |k|\n if k.size == 2 and k.include? c\n d[k] += s_asize\n elsif k.size == 1 and k != c\n new_k = [k, c].sort.join\n if d[new_k] == 0\n d[new_k] = d[k] + d[c]\n end\n end\n end\n end\n if s_size == 2\n k = s_uniq.sort.join\n d[k] += s_asize\n end\nend\nif d.empty?\n puts 0\nelse\n puts d.values.max\nend\n"}, {"source_code": "# Problem: http://codeforces.com/contest/593/problem/A\na = []\nd = Hash.new 0\ngets.to_i.times {a << gets.chomp }\na.each do |s|\n s_asize = s.size\n s_uniq = s.split(\"\").uniq\n s_size = s_uniq.size\n if s_size > 2\n next\n end\n if s_size == 1\n c = s_uniq.pop\n d[c] += s_asize\n d.keys.each do |k|\n if k.size == 2 and k.include? c\n d[k] += s_asize\n elsif k.size == 1 and k != c\n new_k = [k, c].sort.join\n if d[new_k] == 0\n d[new_k] = d[k] + d[c]\n end\n end\n end\n end\n if s_size == 2\n k = s_uniq.sort.join\n d[k] += s_asize\n d.keys.each do |t|\n if t.size == 1 and k.include? t\n d[k] += d[t]\n end\n end\n end\nend\nif d.empty?\n puts 0\nelse\n puts d.values.max\nend\n"}, {"source_code": "# Problem: http://codeforces.com/contest/593/problem/A\na = []\nd = Hash.new 0\ngets.to_i.times {a << gets.chomp }\na.each do |s|\n s_asize = s.size\n s_uniq = s.split(\"\").uniq\n s_size = s_uniq.size\n if s_size > 2\n next\n end\n if s_size == 1\n c = s_uniq.pop\n d[c] += s_asize\n d.keys.each do |k|\n if k.size == 2 and k.include? c\n d[k] += s_asize\n elsif k.size == 1 and k != c\n new_k = [k, c].sort.join\n d[new_k] = d[k] + d[c]\n end\n end\n end\n if s_size == 2\n k = s_uniq.sort.join\n d[k] += s_asize\n end\nend\nif d.empty?\n puts 0\nelse\n puts d.values.max\nend\n"}, {"source_code": "# Problem: http://codeforces.com/contest/593/problem/A\na = []\nd = Hash.new 0\ngets.to_i.times {a << gets.chomp }\na.each do |s|\n s_asize = s.size\n s_uniq = s.split(\"\").uniq\n s_size = s_uniq.size\n if s_size > 2\n next\n end\n if s_size == 1\n c = s_uniq.pop\n d[c] += s_asize\n d.keys.each do |k|\n if k.size == 2 and k.include? c\n d[k] += s_asize\n end\n end\n end\n if s_size == 2\n k = s_uniq.sort.join\n d[k] += s_asize\n end\nend\nif d.empty?\n puts 0\nelse\n puts d.values.max\nend\n"}, {"source_code": "require 'set'\nn = gets.to_i\nglobal_count = {}\nglobal_words = {}\n\nwhile n > 0 do\n\tn -= 1\n\tword = gets.chomp\n\n\tvalid_word = true\n\tchar1 = word.chars.first\n\tchar2 = nil\n\tcurrent_count = {}\n\tword.chars.each do |char|\n\t\tchar2 ||= char if char != char1\n\t\tif char != char1 && char != char2\n\t\t\tvalid_word = false\n\t\t\tbreak\n\t\tend\n\t\tcurrent_count[char] ||= 0\n\t\tcurrent_count[char] += 1\n\tend\n\n\tif valid_word\n\t\tboth_key = \"#{char1}#{char2}\".chars.sort.join\n\n\t\tglobal_count[char1] ||= 0\n\t\tglobal_words[char1] ||= Set.new [char1]\n\t\tglobal_count[both_key] ||= 0\n\t\tglobal_words[char1].add both_key\n\n\t\tif char2\n\n\t\t\tglobal_count[char2] ||= 0\n\t\t\tglobal_words[char2] ||= Set.new [char2]\n\t\t\tglobal_words[char2].add both_key\n\n\t\t\tglobal_count[both_key] += current_count[char1]\n\t\t\tglobal_count[char1] += current_count[char1]\n\t\t\tglobal_count[both_key] += current_count[char2]\n\t\t\tglobal_count[char2] += current_count[char2]\n\t\telse\n\t\t\tglobal_words[char1].each do |word|\n\t\t\t\tglobal_count[word] += current_count[char1]\n\t\t\tend\n\t\tend\n\tend\nend\n\nputs global_count.values.max\n"}, {"source_code": "require 'set'\n\nclass Pair\n attr_accessor :total, :words\n\n def initialize(total, words)\n @total = total\n @words = words\n end\nend\n\nn = gets.to_i\n# Pair = Struct.new(:total, :words)\n@global_count = {}\nglobal_words = {}\n\n# def init_both(char1,char2)\n# \ttotal = 0\n# \twords = []\n# \t[char1,char2].each do |char|\n# \t\tif @global_count[char]\n# \t\t\ttotal += @global_count[char].total\n# \t\t\twords = @global_count[char].words\n# \t\tend\n# \tend\n# \tPair.new(total, words)\n# end\n\n# while n > 0 do\n# \tn -= 1\n# \tword = gets.chomp\n\n# \tvalid_word = true\n# \tchar1 = word.chars.first\n# \tchar2 = nil\n# \tcurrent_count = {}\n# \tword.chars.each do |char|\n# \t\tchar2 ||= char if char != char1\n# \t\tif char != char1 && char != char2\n# \t\t\tvalid_word = false\n# \t\t\tbreak\n# \t\tend\n# \t\tcurrent_count[char] ||= 0\n# \t\tcurrent_count[char] += 1\n# \tend\n\n# \tif valid_word\n# \t\tif char2\n# \t\t\tboth_key = \"#{char1}#{char2}\".chars.sort.join\n# \t\t\t@global_count[both_key] ||= init_both(char1,char2)\n# \t\t\t@global_count[both_key].total += word.length\n# \t\t\t@global_count[both_key].words << word\n# \t\t\tglobal_words[char1] ||= Set.new [char1]\n# \t\t\tglobal_words[char1].add both_key\n# \t\t\tglobal_words[char2] ||= Set.new [char2]\n# \t\t\tglobal_words[char2].add both_key\n# \t\telse\n# \t\t\t@global_count[char1] ||= Pair.new(0, [])\n# \t\t\tglobal_words[char1] ||= Set.new [char1]\n# \t\t\tglobal_words[char1].add char1\n\n# \t\t\tglobal_words[char1].each do |char|\n# \t\t\t\t@global_count[char].total += word.length\n# \t\t\t\t@global_count[char].words << word\n# \t\t\tend\n# \t\tend\n# \tend\n# end\n\n# @global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }.to_h\n# if @global_count.values.first\n# \tanswer = @global_count.values.first.total\n# \tif @global_count.keys.first.length == 1\n# \t\tsize = 0\n# \t\tanswer = 0\n# \t\t@global_count.keys.each do |key|\n# \t\t\tif key.length == 1\n# \t\t\t\tsize +=1\n# \t\t\t\tanswer += @global_count[key].total\n# \t\t\tend\n# \t\t\tbreak if size == 2\n# \t\tend\n# \tend\n# \tputs answer || 0\n\n# else\n# \tputs 0\n# end\n"}, {"source_code": "require 'set'\nn = gets.to_i\nglobal_count = {}\nglobal_words = {}\n\nwhile n > 0 do\n\tn -= 1\n\tword = gets.chomp\n\n\tvalid_word = true\n\tchar1 = word.chars.first\n\tchar2 = nil\n\tcurrent_count = {}\n\tword.chars.each do |char|\n\t\tchar2 ||= char if char != char1\n\t\tif char != char1 && char != char2\n\t\t\tvalid_word = false\n\t\t\tbreak\n\t\tend\n\t\tcurrent_count[char] ||= 0\n\t\tcurrent_count[char] += 1\n\tend\n\n\tif valid_word\n\t\tboth_key = \"#{char1}#{char2}\".chars.sort.join\n\n\t\tglobal_count[char1] ||= 0\n\t\tglobal_words[char1] ||= Set.new [char1]\n\t\tglobal_count[both_key] ||= 0\n\t\tglobal_words[char1].add both_key\n\n\t\tif char2\n\n\t\t\tglobal_count[char2] ||= 0\n\t\t\tglobal_words[char2] ||= Set.new [char2]\n\t\t\tglobal_words[char2].add both_key\n\n\t\t\tglobal_count[both_key] += current_count[char1]\n\t\t\tglobal_count[char1] += current_count[char1]\n\t\t\tglobal_count[both_key] += current_count[char2]\n\t\t\tglobal_count[char2] += current_count[char2]\n\t\telse\n\t\t\tglobal_words[char1].each do |word|\n\t\t\t\tglobal_count[word] += current_count[char1]\n\t\t\tend\n\t\tend\n\tend\nend\n\nputs global_count.values.max || 0\n"}, {"source_code": "require 'set'\n\nfile = File.exist?('in.in') ? File.new('in.in', 'r') : STDIN\n\ndef init_both(char1,char2)\n total = 0\n words = []\n [char1,char2].each do |char|\n if @global_count[char]\n total += @global_count[char].total\n words = @global_count[char].words.dup\n end\n end\n Pair.new(total, words)\nend\n\nn = file.gets.to_i\nPair = Struct.new(:total, :words)\n@global_count = {}\nglobal_words = {}\n\nwhile n > 0 do\n n -= 1\n word = file.gets.chomp\n\n valid_word = true\n char1 = word.chars.first\n char2 = nil\n current_count = {}\n word.chars.each do |char|\n char2 ||= char if char != char1\n if char != char1 && char != char2\n valid_word = false\n break\n end\n current_count[char] ||= 0\n current_count[char] += 1\n end\n if valid_word\n if char2\n both_key = \"#{char1}#{char2}\".chars.sort.join\n @global_count[both_key] ||= init_both(char1,char2)\n @global_count[both_key].total += word.length\n @global_count[both_key].words << word\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add both_key\n global_words[char2] ||= Set.new [char2]\n global_words[char2].add both_key\n else\n @global_count[char1] ||= Pair.new(0, [])\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add char1\n\n global_words[char1].each do |char|\n @global_count[char].total += word.length\n @global_count[char].words << word\n end\n\n\t\t\tglobal_words.each do |k,v|\n\t\t\t\tboth_key = \"#{char1}#{k}\".chars.sort.join\n\t\t\t\tif char1 != k && k.length == 1\n\t\t\t\t\tglobal_words[char1].add both_key\n\t\t\t\t\t@global_count[both_key] ||= init_both(char1,k)\n\t\t\t\tend\n\t\t\tend\n\n end\n end\nend\n@global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }\n@global_count = Hash[*@global_count.flatten]\n# puts @global_count\n# puts global_words\nif @global_count.values.first\n answer = @global_count.values.first.total\n if @global_count.keys.first.length == 1\n size = 0\n answer = 0\n @global_count.keys.each do |key|\n if key.length == 1\n size +=1\n answer += @global_count[key].total\n end\n break if size == 2\n end\n end\n puts answer || 0\n\nelse\n puts 0\nend"}, {"source_code": "require 'set'\n\ndef init_both(char1,char2)\n total = 0\n words = []\n [char1,char2].each do |char|\n if @global_count[char]\n total += @global_count[char].total\n words = @global_count[char].words\n end\n end\n Pair.new(total, words)\nend\n\nn = gets.to_i\nPair = Struct.new(:total, :words)\n@global_count = {}\nglobal_words = {}\n\nwhile n > 0 do\n n -= 1\n word = gets.chomp\n\n valid_word = true\n char1 = word.chars.first\n char2 = nil\n current_count = {}\n word.chars.each do |char|\n char2 ||= char if char != char1\n if char != char1 && char != char2\n valid_word = false\n break\n end\n current_count[char] ||= 0\n current_count[char] += 1\n end\n if valid_word\n if char2\n both_key = \"#{char1}#{char2}\".chars.sort.join\n @global_count[both_key] ||= init_both(char1,char2)\n @global_count[both_key].total += word.length\n @global_count[both_key].words << word\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add both_key\n global_words[char2] ||= Set.new [char2]\n global_words[char2].add both_key\n else\n @global_count[char1] ||= Pair.new(0, [])\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add char1\n\n global_words.each do |k,v|\n if k != char1 && k.length == 1\n both_key = \"#{char1}#{k}\".chars.sort.join\n unless @global_count[both_key]\n @global_count[both_key] ||= init_both(char1,k)\n global_words[char1].add both_key\n end\n end\n end\n\n global_words[char1].each do |char|\n @global_count[char].total += word.length\n @global_count[char].words << word\n end\n end\n end\nend\n@global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }\n@global_count = Hash[*@global_count.flatten]\n\n# puts @global_count\n# puts global_words\n\nif @global_count.values.first\n answer = @global_count.values.first.total\n if @global_count.keys.first.length == 1\n size = 0\n answer = 0\n @global_count.keys.each do |key|\n if key.length == 1\n size +=1\n answer += @global_count[key].total\n end\n break if size == 2\n end\n end\n puts answer || 0\n\nelse\n puts 0\nend"}, {"source_code": "require 'set'\n\ndef init_both(char1,char2)\n total = 0\n words = []\n [char1,char2].each do |char|\n if @global_count[char]\n total += @global_count[char].total\n words = @global_count[char].words\n end\n end\n Pair.new(total, words)\nend\n\nn = gets.to_i\nPair = Struct.new(:total, :words)\n@global_count = {}\nglobal_words = {}\n\nwhile n > 0 do\n n -= 1\n word = gets.chomp\n\n valid_word = true\n char1 = word.chars.first\n char2 = nil\n current_count = {}\n word.chars.each do |char|\n char2 ||= char if char != char1\n if char != char1 && char != char2\n valid_word = false\n break\n end\n current_count[char] ||= 0\n current_count[char] += 1\n end\n if valid_word\n if char2\n both_key = \"#{char1}#{char2}\".chars.sort.join\n @global_count[both_key] ||= init_both(char1,char2)\n @global_count[both_key].total += word.length\n @global_count[both_key].words << word\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add both_key\n global_words[char2] ||= Set.new [char2]\n global_words[char2].add both_key\n else\n @global_count[char1] ||= Pair.new(0, [])\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add char1\n\n global_words.each do |k,v|\n if k != char1 && k.length == 1\n both_key = \"#{char1}#{k}\".chars.sort.join\n @global_count[both_key] ||= init_both(char1,char2)\n global_words[char1].add both_key\n end\n end\n\n global_words[char1].each do |char|\n @global_count[char].total += word.length\n @global_count[char].words << word\n end\n end\n end\nend\n@global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }\n@global_count = Hash[*@global_count.flatten]\n\n# puts @global_count\n# puts global_words\n\nif @global_count.values.first\n answer = @global_count.values.first.total\n if @global_count.keys.first.length == 1\n size = 0\n answer = 0\n @global_count.keys.each do |key|\n if key.length == 1\n size +=1\n answer += @global_count[key].total\n end\n break if size == 2\n end\n end\n puts answer || 0\n\nelse\n puts 0\nend"}, {"source_code": "require 'set'\nn = gets.to_i\nglobal_count = {}\nglobal_words = {}\n\nwhile n > 0 do\n\tn -= 1\n\tword = gets.chomp\n\n\tvalid_word = true\n\tchar1 = word.chars.first\n\tchar2 = nil\n\tcurrent_count = {}\n\tword.chars.each do |char|\n\t\tchar2 ||= char if char != char1\n\t\tif char != char1 && char != char2\n\t\t\tvalid_word = false\n\t\t\tbreak\n\t\tend\n\t\tcurrent_count[char] ||= 0\n\t\tcurrent_count[char] += 1\n\tend\n\n\tif valid_word\n\n\t\tboth_key = \"#{char1}#{char2}\".chars.sort.join\n\n\t\tglobal_count[char1] ||= 0\n\t\tglobal_words[char1] ||= Set.new [char1]\n\t\tglobal_words[char1].add both_key\n\n\t\tif char2\n\t\t\tglobal_count[char2] ||= 0\n\t\t\tglobal_words[char2] ||= Set.new [char2]\n\t\t\tglobal_words[char2].add both_key\n\t\t\tglobal_count[char2] += current_count[char2]\n\t\t\tglobal_count[char1] += current_count[char1]\n\n\t\t\tglobal_count[both_key] ||= 0\n\t\t\tglobal_count[both_key] = global_count[char1] + global_count[char2]\n\n\t\telse\n\t\t\tglobal_words[char1].each do |word|\n\t\t\t\tglobal_count[word] += current_count[char1]\n\t\t\tend\n\t\tend\n\tend\nend\nputs global_count.values.max || 0\n"}, {"source_code": "require 'set'\n\ndef init_both(char1,char2)\n total = 0\n words = []\n [char1,char2].each do |char|\n if @global_count[char]\n total += @global_count[char].total\n words = @global_count[char].words\n end\n end\n Pair.new(total, words)\nend\n\nn = gets.to_i\nPair = Struct.new(:total, :words)\n@global_count = {}\nglobal_words = {}\n\nwhile n > 0 do\n n -= 1\n word = gets.chomp\n\n valid_word = true\n char1 = word.chars.first\n char2 = nil\n current_count = {}\n word.chars.each do |char|\n char2 ||= char if char != char1\n if char != char1 && char != char2\n valid_word = false\n break\n end\n current_count[char] ||= 0\n current_count[char] += 1\n end\n if valid_word\n if char2\n both_key = \"#{char1}#{char2}\".chars.sort.join\n @global_count[both_key] ||= init_both(char1,char2)\n @global_count[both_key].total += word.length\n @global_count[both_key].words << word\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add both_key\n global_words[char2] ||= Set.new [char2]\n global_words[char2].add both_key\n else\n @global_count[char1] ||= Pair.new(0, [])\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add char1\n\n global_words[char1].each do |char|\n @global_count[char].total += word.length\n @global_count[char].words << word\n end\n end\n end\nend\n@global_count = @global_count.sort {|a1,a2| a2[1].total <=> a1[1].total }\n@global_count = Hash[*@global_count.flatten]\nif @global_count.values.first\n answer = @global_count.values.first.total\n if @global_count.keys.first.length == 1\n size = 0\n answer = 0\n @global_count.keys.each do |key|\n if key.length == 1\n size +=1\n answer += @global_count[key].total\n end\n break if size == 2\n end\n end\n puts answer || 0\n\nelse\n puts 0\nend"}, {"source_code": "require 'set'\n\ndef init_both(char1,char2)\n total = 0\n words = []\n [char1,char2].each do |char|\n if @global_count[char]\n total += @global_count[char].total\n words = @global_count[char].words\n end\n end\n Pair.new(total, words)\nend\n\nn = gets.to_i\nPair = Struct.new(:total, :words)\n@global_count = {}\nglobal_words = {}\n\nwhile n > 0 do\n n -= 1\n word = gets.chomp\n\n valid_word = true\n char1 = word.chars.first\n char2 = nil\n current_count = {}\n word.chars.each do |char|\n char2 ||= char if char != char1\n if char != char1 && char != char2\n valid_word = false\n break\n end\n current_count[char] ||= 0\n current_count[char] += 1\n end\n if valid_word\n if char2\n both_key = \"#{char1}#{char2}\".chars.sort.join\n @global_count[both_key] ||= init_both(char1,char2)\n @global_count[both_key].total += word.length\n @global_count[both_key].words << word\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add both_key\n global_words[char2] ||= Set.new [char2]\n global_words[char2].add both_key\n else\n @global_count[char1] ||= Pair.new(0, [])\n global_words[char1] ||= Set.new [char1]\n global_words[char1].add char1\n\n global_words[char1].each do |char|\n @global_count[char].total += word.length\n @global_count[char].words << word\n end\n end\n end\nend\nputs 0\nputs @global_count\n@global_count = @global_count.sort {|a1,a2| puts 'ww'; puts a2[1].total; a2[1].total <=> a1[1].total }\nputs 0.3\n@global_count = Hash[*@global_count.flatten]\nputs @global_count\nif @global_count.values.first\n puts 3\n answer = @global_count.values.first.total\n if @global_count.keys.first.length == 1\n puts 4\n size = 0\n answer = 0\n @global_count.keys.each do |key|\n if key.length == 1\n size +=1\n answer += @global_count[key].total\n end\n break if size == 2\n end\n end\n puts answer || 0\n\nelse\n puts 0\nend"}, {"source_code": "n = gets.chomp.to_i\nhs = Hash.new(0)\nn.times do\n line = gets.chomp\n cs = line.split('').sort.uniq\n if cs.size == 1\n hs[cs[0]] += line.size\n elsif cs.size == 2\n hs[cs[0] + cs[1]] += line.size\n end\nend\n\nrtn = 0\n\nhs.each do |k, v|\n if k.size == 2\n hs[k] += hs[k[0]] + hs[k[1]]\n end\nend\n\nhs.each do |k, v|\n rtn = [rtn, v].max\nend\n\nputs rtn\n"}, {"source_code": "n = gets.chomp.to_i\nhs = Hash.new(0)\nn.times do\n cs = gets.chomp.split('').sort\n if cs.uniq.size == 1\n hs[cs[0]] += cs.size\n elsif cs.uniq.size == 2\n hs[cs[0] + cs[1]] += cs.size\n end\nend\n\nrtn = 0\n\nhs.each do |k, v|\n if k.size == 2\n hs[k] += hs[k[0]] + hs[k[1]]\n end\nend\n\nhs.each do |k, v|\n rtn = [rtn, v].max\nend\n\nputs rtn\n"}, {"source_code": "n = gets.chomp.to_i\nd = Hash.new(0)\nn.times do\n word = gets.chomp\n k = word.split(\"\").uniq\n v = word.length\n d[k] += v if k.length <= 2\nend\n\nif d.empty? then\n res = 0\nelse\n res = d.values.max\n d.keys.combination(2) do |kk|\n if kk.flatten.uniq.length > 2 then\n next\n else\n res = [res, d[kk[0]] + d[kk[1]]].max\n end\n end\n\n d.keys.combination(3) do |kk|\n if kk.flatten.uniq.length > 2 then\n next\n else\n res = [res, d[kk[0]] + d[kk[1]]+d[kk[2]]].max\n end\n end\nend\n\nputs res"}, {"source_code": "n = gets.chomp.to_i\nd = Hash.new(0)\nn.times do\n word = gets.chomp\n k = word.split(\"\").uniq\n v = word.length\n d[k] += v if k.length <= 2\nend\nres = 0\n(?a..?z).to_a.combination(2) do |kk|\n res = [res, d[[kk[0]]] + d[[kk[1]]] + d[kk]].max\nend\n\nputs res"}, {"source_code": "n = gets.chomp.to_i\nd = Hash.new(0)\nn.times do\n word = gets.chomp\n k = word.split(\"\").uniq\n v = word.length\n d[k] += v if k.length <= 2\nend\nres = d.values.max\nd.keys.combination(2) do |kk|\n if kk.flatten.uniq.length > 2 then\n next\n else\n res = [res, d[kk[0]] + d[kk[1]]].max\n end\nend\nd.keys.combination(3) do |kk|\n if kk.flatten.uniq.length > 2 then\n next\n else\n res = [res, d[kk[0]] + d[kk[1]]+d[kk[2]]].max\n end\nend\nputs res"}, {"source_code": "def get_arr(arr)\n a = arr[0]\n b = arr.split(a)[0]\n return [a,b]\nend\n\ndef exist?(arr, arr1)\n arr.each do |x|\n if x == arr1\n return true\n break\n end\n end\n false\nend\nn = gets.chomp.to_i\narr, array, len = [], [], []\n(1..n).each do |i|\n a = gets.chomp\n t = String.new(a)\n num = 0\n a.each_char do |x|\n if a.delete(x) != a\n a.delete!(x)\n num += 1\n end\n if num == 3\n break\n end\n end\n if num < 3\n arr << t\n end\nend\narr.each_with_index do |arr1, index1|\n len[index1] = arr1.length\n if !exist?(array, arr1)\n arr.each_with_index do |arr2, index2|\n if index1 == index2\n next\n else\n if get_arr(arr1) == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)\n len[index1] += arr2.length\n end\n end\n end\n array << get_arr(arr1)\n end\nend\np len.sort.last\n"}, {"source_code": "def get_arr(arr)\n a = arr[0]\n b = arr.delete(a)[0]\n return [a,b]\nend\n\ndef exist?(arr, arr1)\n arr.each do |x|\n if x == arr1\n return true\n break\n end\n end\n false\nend\nn = gets.chomp.to_i\nx, arr, array, len = [], [], [], [0]\n(1..n).each do |i|\n a = gets.chomp\n t = String.new(a)\n num = 0\n a.each_char do |x|\n if a.delete(x) != a\n a.delete!(x)\n num += 1\n end\n if num == 3\n break\n end\n end\n if num < 3\n arr << t\n end\nend\narr.each_with_index do |arr1, index1|\n len[index1] = arr1.length\n if !exist?(array, arr1)\n arr.each_with_index do |arr2, index2|\n if index1 == index2\n next\n else\n if get_arr(arr1) == get_arr(arr2) || get_arr(arr1).reverse == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)\n len[index1] += arr2.length\n end\n end\n end\n array << get_arr(arr1)\n end\nend\nl = len.sort.last\narr1 = \"\"\nl1 = 0\narr.each do |a|\n if a.length == l\n arr1 = a\n break\n end\nend\nif arr1.squeeze.length == 1\n arr.each do |a|\n if a.squeeze.length == 1 && a != arr1 && a.length > l1\n l1 = a.length\n end\n end\n p l+l1\nelse\n p l\nend\n"}, {"source_code": "def get_arr(arr)\n a = arr[0]\n b = arr.delete(a)[0]\n return [a,b]\nend\n\ndef exist?(arr, arr1)\n arr.each do |x|\n if x == arr1\n return true\n break\n end\n end\n false\nend\nn = gets.chomp.to_i\nx, arr, array, len = [], [], [], [0]\n(1..n).each do |i|\n a = gets.chomp\n t = String.new(a)\n num = 0\n a.each_char do |x|\n if a.delete(x) != a\n a.delete!(x)\n num += 1\n end\n if num == 3\n break\n end\n end\n if num < 3\n arr << t\n end\nend\narr.each_with_index do |arr1, index1|\n len[index1] = arr1.length\n if !exist?(array, arr1)\n arr.each_with_index do |arr2, index2|\n if index1 == index2\n next\n else\n if get_arr(arr1) == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)\n len[index1] += arr2.length\n end\n end\n end\n array << get_arr(arr1)\n end\nend\nl = len.sort.last\nif arr.length > 1\n arr.each do |k|\n if k.squeeze.length == 1\n x << k.length\n end\n end\n x.sort!\n l1 = x.last + x[x.length-2]\nend\np l1 && l1 > l ? l1 : l\n"}, {"source_code": "def get_arr(arr)\n a = arr[0]\n b = arr.delete(a)[0]\n return [a,b]\nend\n\ndef exist?(arr, arr1)\n arr.each do |x|\n if x == arr1\n return true\n break\n end\n end\n false\nend\nn = gets.chomp.to_i\nx, arr, array, len = [], [], [], [0]\n(1..n).each do |i|\n a = gets.chomp\n t = String.new(a)\n num = 0\n a.each_char do |x|\n if a.delete(x) != a\n a.delete!(x)\n num += 1\n end\n if num == 3\n break\n end\n end\n if num < 3\n arr << t\n end\nend\narr.each_with_index do |arr1, index1|\n len[index1] = arr1.length\n if !exist?(array, arr1)\n arr.each_with_index do |arr2, index2|\n if index1 == index2\n next\n else\n if get_arr(arr1) == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)\n len[index1] += arr2.length\n end\n end\n end\n array << get_arr(arr1)\n end\nend\nl = len.sort.last\narr.each do |k|\n if k.squeeze.length == 1\n x << k.length\n end\nend\nx.sort!\nl1 = x.last + x[x.length-2]\np l1 > l ? l1 : l\n"}, {"source_code": "def get_arr(arr)\n a = arr[0]\n b = arr.delete(a)[0]\n return [a,b]\nend\n\ndef exist?(arr, arr1)\n arr.each do |x|\n if x == arr1\n return true\n break\n end\n end\n false\nend\nn = gets.chomp.to_i\nx, arr, array, len = [], [], [], [0]\n(1..n).each do |i|\n a = gets.chomp\n t = String.new(a)\n num = 0\n a.each_char do |x|\n if a.delete(x) != a\n a.delete!(x)\n num += 1\n end\n if num == 3\n break\n end\n end\n if num < 3\n arr << t\n end\nend\narr.each_with_index do |arr1, index1|\n len[index1] = arr1.length\n if !exist?(array, arr1)\n arr.each_with_index do |arr2, index2|\n if index1 == index2\n next\n else\n if get_arr(arr1) == get_arr(arr2) || get_arr(arr1).reverse == get_arr(arr2) || arr1.squeeze.include?(arr2.squeeze)\n len[index1] += arr2.length\n end\n end\n end\n array << get_arr(arr1)\n end\nend\nl = len.sort.last\nindex = len.index(l)\nif arr[index].squeeze.length == 1\n l1 = 0\n arr.each do |arr1|\n if arr1.length > l1 && arr1 != arr[index]\n l1 = arr1.length\n end\n end\n p l+l1\nelse\n p l\nend\n"}], "src_uid": "d8a93129cb5e7f05a5d6bbeedbd9ef1a"} {"source_code": "readin=->(){gets.split.map(&:to_i)}\nn,k,mn=gets.to_i,readin[],0x3f3f3f3f\nn.times{|i|mn=[mn,readin[].inject(:+)*5+k[i]*15].min}\nputs mn\n", "positive_code": [{"source_code": "n = STDIN.readline.to_i\nf = STDIN.readline.split.map { |x| x.to_i }\nans = Array.new(n,0)\nn.times do |i|\n\tt = STDIN.readline.split.map { |x| x.to_i }\n\tt.each { |x| ans[i] += 5*x+15 }\nend\nprint ans.min\n"}, {"source_code": "n = gets.to_i\nk = gets.split(' ').map{|i| i.to_i}\nbest = 1023456789 \nfor i in 0..n-1\n\tbest = [best, gets.split(' ').map{|i| i.to_i}.reduce{|a, b| a+b} * 5 + k[i] * 15].min\nend\nputs best\n"}, {"source_code": "N=gets().to_i\ndef Solve(line)\n res=0\n for i in line\n res+=(i*5)\n end\n res+=15*line.size\n res\nend\npeople_num_arr=gets().split(\" \").map{|i| i.to_i}\nlis=[]\nfor i in 0...N\n line=gets().split(\" \").map{|i| i.to_i}\n lis< 1\n b += 1 while c[b] > 0\n if a < b && c[a] < n\n c[a] = 999999\n else\n c[a] -= 1\n l[i] = b\n b += 1\n end\n end\nend\np c.count(0) - 1\nputs l.map(&:to_s).join(' ')", "positive_code": [{"source_code": "n = gets.to_i\n\ncnt = [1]\narr = gets.split.map{|x| cnt << 0; x.to_i}\n\narr.each{|x| cnt[x] += 1}\n\nmiss = []\ncnt.each_with_index{|x, i| miss << i if x == 0}\n\np miss.size\n\nexist = []\nj = 0\n\nputs arr.map{|x|\n\tif exist[x] || (cnt[x] > 1 && miss[j] < x)\n\t\tcnt[x] -= 1\n\t\tj += 1\n\t\tmiss[j - 1]\n\telse\n\t\texist[x] = 1\n\t\tx\n\tend\n}.join(\" \")"}, {"source_code": "n, l = gets.to_i + 1, gets.split.map(&:to_i)\ncnt, b, c = Array.new(n, 0), 1, 0\nl.each {|a| cnt[a] += 1}\nl.each_with_index do |a, i|\n if cnt[a] > 1\n b += 1 while cnt[b] > 0\n if a < b && cnt[a] < n\n cnt[a] = 999999\n else\n cnt[a] -= 1\n l[i] = b\n b += 1\n c += 1\n end\n end\nend\np c\nputs l.map(&:to_s).join(' ')"}], "negative_code": [{"source_code": "n, l = gets.to_i + 1, gets.split.map(&:to_i)\ncnt, b = Array.new(n, 0), 1\nl.each {|a| cnt[a] += 1}\nl.each_with_index do |a, i|\n if cnt[a] > 1\n b += 1 while cnt[b] > 0\n if a < b && cnt[a] < n\n cnt[a] = 999999\n else\n cnt[a] -= 1\n l[i] = b\n b += 1\n end\n end\nend\nputs l.map(&:to_s).join(\" \")"}, {"source_code": "n, aa = gets.to_i+1, gets.split.map(&:to_i)\ncnt, b = Array.new(n, 0), 1\naa.each {|a| cnt[a] += 1}\naa.each_with_index do |a, i|\n if cnt[a] > 1\n b += 1 while cnt[b] > 0\n if a < b && cnt[a] < n\n cnt[a] = 999999\n else\n cnt[a] -= 1\n aa[i] = b\n b += 1\n end\n end\nend\np aa"}], "src_uid": "0560658d84cbf91c0d86eea4be92a4d9"} {"source_code": "T = gets.to_i\n\nT.times do\n a, b = gets.split.map{|e| e.to_i}\n\n if (a == 0 && b == 0)\n puts 1.0\n elsif (a == 0)\n puts 0.5\n elsif (b == 0)\n puts 1.0\n else\n if (b > a / 4.0)\n puts 0.5 + (0.5 * a * a / 4.0) / (2 * a * b)\n else\n puts 1.0 - (0.5 * b * b * 4) / (2 * a * b)\n end\n end\n\nend\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\n$stdin = File.open('test_69_4') if $DEBUG\n\nt = gets.to_i\nt.times do\n a, b = gets.split.map(&:to_i)\n total = b*2*a\n square = a.to_f/4 >= b ? b*b*2 : a*(b - a.to_f/8)\n puts b == 0 ? 1.0 : a == 0 ? 0.5 : (total - square).to_f / total\nend\n\n"}, {"source_code": "#Infinity\n#geti,getia\n#Object # dcopy\n#\n#String # to_a\n# \"abc\".to_a #=> [\"a\",\"b\",\"c\"]\n#String # to_ia\n# \"1 2 3\".to_ia #=> [1,2,3]\n#\n#Array # rsort,rsort!\n# [1,3,2,4].rsort #=> [4,3,2,1]\n#\n#Integer # divisor\n# 24.divisor #=> [1,2,3,4,6,8,12,24]\n#\ninclude Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInfinity = 1/0.0\nclass Matrix;def inspect;empty? ? \"Matrix.empty(#{row_size}, #{column_size})\":\"Matrix[\\n#{@rows.map(&:inspect).join(\"\\n\")}\\n]\";end;end\ndef pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end\nclass String;def to_a;split(\"\");end;end\nclass String;def to_ia;split.map(&:to_i);end;end\ndef getia;gets.to_ia;end\ndef geti;gets.to_i;end\nclass Object;def dcopy;Marshal.load(Marshal.dump(self));end;end\nclass Array;def rsort;sort.reverse;end;def rsort!;sort!.reverse!;end;end\n\n\nt = geti\nt.times do\n a,b = gets.split.map(&:to_f)\n y = a * b\n if 4 * b > a\n y += a * a / 8.0\n else\n y += y - b * b * 2.0\n end\n if a == 0 && b == 0\n puts 1\n elsif a == 0\n puts 0.5\n elsif b == 0\n puts 1\n else\n puts y / (a * b * 2.0)\n end\nend\n\n\n\n"}, {"source_code": "n = gets.to_i\nn.times do\n a, b = gets.split.map(&:to_i)\n if b == 0\n o = 1.0\n elsif a == 0\n o = 0.5\n elsif a < 4*b\n o = (a*b + a*a*Rational(1,8))/(2*a*b)\n else\n o = (2*a*b - b*b*Rational(2,1))/(2*a*b)\n end\n p o.to_f\nend\n"}], "negative_code": [{"source_code": "#Infinity\n#geti,getia\n#Object # dcopy\n#\n#String # to_a\n# \"abc\".to_a #=> [\"a\",\"b\",\"c\"]\n#String # to_ia\n# \"1 2 3\".to_ia #=> [1,2,3]\n#\n#Array # rsort,rsort!\n# [1,3,2,4].rsort #=> [4,3,2,1]\n#\n#Integer # divisor\n# 24.divisor #=> [1,2,3,4,6,8,12,24]\n#\ninclude Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInfinity = 1/0.0\nclass Matrix;def inspect;empty? ? \"Matrix.empty(#{row_size}, #{column_size})\":\"Matrix[\\n#{@rows.map(&:inspect).join(\"\\n\")}\\n]\";end;end\ndef pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end\nclass String;def to_a;split(\"\");end;end\nclass String;def to_ia;split.map(&:to_i);end;end\ndef getia;gets.to_ia;end\ndef geti;gets.to_i;end\nclass Object;def dcopy;Marshal.load(Marshal.dump(self));end;end\nclass Array;def rsort;sort.reverse;end;def rsort!;sort!.reverse!;end;end\n\n\nt = geti\nt.times do\n a,b = getia\n y = a * b\n if 4 * b > a\n y += a * a / 8.0\n else\n y += y - b * b * 2.0\n end\n puts y / (a * b * 2.0)\nend\n\n\n"}, {"source_code": "n = gets.to_i\nn.times do\n a, b = gets.split.map(&:to_i)\n if a == 0 || b == 0\n o = 1.0\n elsif a < 4*b\n o = (a*b + a*a*Rational(1,8))/(2*a*b)\n else\n o = (2*a*b - b*b*Rational(1,8))/(2*a*b)\n end\n p o.to_f\nend\n"}, {"source_code": "n = gets.to_i\nn.times do\n a, b = gets.split.map(&:to_i)\n if b == 0 \n o = 1.0\n elsif a == 0\n o = 0.5\n elsif a < 4*b\n o = (a*b + a*a*Rational(1,8))/(2*a*b)\n else\n o = (2*a*b - b*b*Rational(1,8))/(2*a*b)\n end\n p o.to_f\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\n$stdin = File.open('test_69_4') if $DEBUG\n\nt = gets.to_i\nt.times do\n a, b = gets.split.map(&:to_i)\n total = b*2*a\n square = a.to_f/4 >= b ? b*b*2 : a*(b - a.to_f/8)\n puts b == 0 ? 1 : a == 0 ? 0.5 : (total - square) / total\nend\n\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n a, b = gets.split.map{|e| e.to_i}\n\n if (b > a / 4.0)\n puts 0.5 + (0.5 * a * a / 4.0) / (2 * a * b)\n else\n puts 1.0 - (0.5 * b * b * 4) / (2 * a * b)\n end\n\nend\n"}], "src_uid": "92feda270834af751ca37bd80083aafa"} {"source_code": "# coding: utf-8\nrequire \"set\"\n\nn, x0, y0 = gets.split.map(&:to_i)\nincline_hash = Set.new\nn.times {\n x, y = gets.split.map(&:to_i)\n dx, dy = x0 - x, y0 - y\n if dx == 0\n incline_hash.add -1\n else\n incline_hash.add dy*1.0/dx\n end\n}\n\nputs incline_hash.length", "positive_code": [{"source_code": "n,x,y=gets.split.map(&:to_i)\na=[]\nn.times do\n x1,y1 =gets.split.map(&:to_f)\n a << (x1==x ? 'w':(y1-y)/(x1-x))\nend\np a.uniq.count\n\n"}, {"source_code": "require 'set'\n\nn, x0, y0 = gets.split.map(&:to_f)\n\nset = Set.new\nn.to_i.times do\n x, y = gets.split.map(&:to_f)\n\n if x == x0\n set << true\n else\n set << (y - y0) / (x - x0)\n end\nend\n\nputs set.length\n"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\na=[]\nn.times do\n x1,y1 =gets.split.map(&:to_f)\n a << (x1==x ? 'w':(y1-y)/(x1-x))\nend\np a.uniq.count\n\n"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\ns={}\nn.times do\n x1,y1=gets.split.map(&:to_f)\n s[(y1-y)/(x1-x)]=1\nend\np s[1.0/0]&&s[-1.0/0]?(s.size-1):s.size"}, {"source_code": "n,x0,y0=gets.chomp.split.map(&:to_i)\nvx,vy,ans,i,j=[],[],n,0,0\nn.times do |i|\n\tx,y=gets.chomp.split.map(&:to_i)\n\tvx<<(x-x0);vy<<(y-y0)\n\tfor j in 0...i\n\t\tif vx[i] * vy[j] == vx[j] * vy[i]\n\t\t\tans-=1\n\t\t\tbreak\n\t\tend\n\tend\nend\nputs ans"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn, x0, y0 = gets.split.map &:to_i\ndata = Array.new(n) { Array.new(2, 0) }\nl = []\nflag = 0\nm = 0\nn.times{|_|\n data[_] = gets.split.map &:to_i\n if x0 == data[_][0]\n flag = 1\n else\n l << (1.0 * y0 - data[_][1]) / (1.0 * x0 - data[_][0])\n end\n}\nputs (l.uniq.size + flag)\n\n"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\na=[]\nn.times do\n x1,y1 =gets.split.map(&:to_f)\n a << (x1==x ? 'w':(y1-y)/(x1-x))\nend\np a.uniq.count\n\n"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\na=[]\nn.times do\n x1,y1 =gets.split.map(&:to_f)\n a << (x1==x ? 'w':(y1-y)/(x1-x))\nend\np a.uniq.count\n\n"}, {"source_code": "require 'set'\ndef read_ints; STDIN.gets.split.map(&:to_i); end\n\nn, x0, y0 = read_ints\n\ninp = n.times.map do\n p = read_ints\n p[0] -= x0\n p[1] -= y0\n p\nend\n\ndot_set = inp.to_set\n\nans = 0\nloop do\n break if dot_set.empty?\n ans += 1\n p = dot_set.first\n dot_set.delete_if do |dot|\n dot[0] * p[1] == dot[1] * p[0]\n end\nend\n\nputs ans\n"}, {"source_code": "n,x,y=gets.split.map{|e| e.to_i}\nps=Hash.new(0)\nadd=0\nn.times{\n\txi,yi=gets.split.map{|e| e.to_i}\n\txi=(xi-x)\n\tyi=(yi-y)\n\tif xi==0 then\n\t\tadd=1\n\telse\n\t\tm1=1\n\t\tm1=-1 if xi<0\n\t\td1=yi.abs.gcd(xi.abs)\n\t\tps[[yi/d1*m1,xi/d1*m1]]+=1\n\t\n\tend\n}\nputs ps.size+add"}, {"source_code": "#!/usr/bin/ruby\n\nSMALL_NUMBER = 0.000000000001\ninput_line = gets\npar = input_line.split(' ').map(&:to_f)\nn = par[0]\nx0 = par[1]\ny0 = par[2]\ni = 0;\ncoords = []\nwhile(i < n) do\n input_line = gets\n par = input_line.split(' ').map(&:to_f)\n coords << [par[0],par[1]]\n i = i+1\nend\ncounter = 0\nwhile (coords.size() > 0) do\n counter = counter + 1\n x1 = coords[0][0]\n y1 = coords[0][1]\n\n if ((x0-x1).abs > SMALL_NUMBER && (y0-y1).abs > SMALL_NUMBER) \n coords.delete_if do |coord|\n true if ( ( (coord[0]-x0)/(x1-x0) - (coord[1]-y0)/(y1-y0) ).abs < SMALL_NUMBER)\n end\n elsif ((x0-x1).abs < SMALL_NUMBER)\n coords.delete_if do |coord|\n true if ( (coord[0]-x0).abs < SMALL_NUMBER)\n end\n elsif ((y0-y1).abs < SMALL_NUMBER)\n coords.delete_if do |coord|\n true if ( (coord[1]-y0).abs < SMALL_NUMBER)\n end\n end\nend\n\nputs counter\n\n"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\ns={}\n(1..n).each do |i|\n x1,y1=gets.split.map(&:to_f)\n s[(y1-y)/(x1-x)]=1\nend\np s[1.0/0]&&s[-1.0/0]?(s.size-1):s.size"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\ns={}\nn.times do\n x1,y1=gets.split.map(&:to_f)\n s[(y1-y)/(x1-x)]=1\nend\np s[1.0/0]&&s[-1.0/0]?(s.size-1):s.size"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\na=[]\nn.times do\n x1,y1 =gets.split.map(&:to_f)\n a << (x1==x ? 'w':(y1-y)/(x1-x))\nend\np a.uniq.count\n\n"}, {"source_code": "n,x1,y1 = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.split(\" \").map(&:to_i)\nend\neq = arr.map do |a|\n\tx2,y2 = a\n\t(x2-x1) == 0 ? 10**9 : (y2-y1)/(x2-x1).to_f\nend\nputs eq.uniq.count"}, {"source_code": "require 'set'\n\ndef gcd(a, b)\n return a if b == 0\n gcd(b, a%b)\nend\n\na = Set.new\nn,x,y = gets.split.map(&:to_i)\n1.upto(n).map do |_|\n ex,ey = gets.split.map(&:to_i)\n dx = ex - x\n dy = ey - y\n if dx < 0\n dx *= -1\n dy *= -1\n end\n if dx == 0\n a << [0,1]\n elsif dy == 0\n a << [1,0]\n else\n g = gcd(dx,dy).abs\n a << [dx/g, dy/g]\n end\nend\n\nputs a.size\n"}, {"source_code": "n, x0, y0 = gets.split.map(&:to_i)\na = n.times.map do \n x1, y1 = gets.split.map(&:to_f)\n x1 == x0 ? 'w' : (y1 - y0) / (x1 - x0)\nend\nputs a.uniq.size\n"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\na=[]\nn.times do\n x1,y1 =gets.split.map(&:to_f)\n a << (x1==x ? 'w':(y1-y)/(x1-x))\nend\np a.uniq.count\n"}, {"source_code": "n, x, y = gets.split.map(&:to_i)\na = []\nn.times do\n x1, y1 = gets.split.map(&:to_f)\n a << (x1 == x ? 'w' : (y1 - y) / (x1 - x))\nend\nputs a.uniq.count\n"}, {"source_code": "n, x, y = gets.split.map(&:to_i)\na = []\nn.times do\n x1, y1 = gets.split.map(&:to_f)\n c = (y1 - y) / (x1 - x)\n a << (c.infinite? ? c.abs : c.to_r)\nend\nputs a.uniq.count\n"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\na=[]\nn.times do\n x1,y1 =gets.split.map(&:to_f)\n a << (x1==x ? 'w':(y1-y)/(x1-x))\nend\np a.uniq.count\n\n"}, {"source_code": "Point = Struct.new(:x, :y)\n\ndef points_on_line(arr, zero, p)\n left = p.x - zero.x\n right = p.y - zero.y\n\n arr = arr.map { |elem|\n if (left * (elem.y - zero.y)) == (right * (elem.x - zero.x))\n nil\n else\n elem\n end\n }\n\n arr.compact\nend\n\nn, x0, y0 = gets.split(' ').map(&:to_i)\n\nzero = Point.new(x0, y0)\n\narr = []\nn.times do |_|\n x, y = gets.split(' ').map(&:to_i)\n arr << Point.new(x, y)\nend\n\ncounter = 0\nuntil arr.empty?\n p = arr.pop\n arr = points_on_line(arr, zero, p)\n\n counter += 1\nend\n\np counter\n"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\na=[]\nn.times do\n x1,y1 =gets.split.map(&:to_f)\n a << (x1==x ? 'w':(y1-y)/(x1-x))\nend\np a.uniq.count\n\n"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\na=[]\nn.times do\n x1,y1 =gets.split.map(&:to_f)\n a << (x1==x ? 'w':(y1-y)/(x1-x))\nend\np a.uniq.count\n\n"}], "negative_code": [{"source_code": "require 'set'\n\nn, x0, y0 = gets.split.map(&:to_f)\n\nset = Set.new\nn.to_i.times do\n x, y = gets.split.map(&:to_f)\n set << (y - y0) / (x - x0)\nend\n\nputs set.length\n"}, {"source_code": "# http://codeforces.com/contest/514/problem/A\n\ndigits = gets.chomp.chars.map(&:to_i)\ninverted = digits.map.with_index do |n, idx|\n case idx\n when 0\n (9 - n) < n && n != 9 ? 9 - n : n\n else\n (9 - n) < n ? 9 - n : n\n end\nend\n\nputs inverted.join.to_i\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn, x0, y0 = gets.split.map &:to_i\ndata = Array.new(n) { Array.new(2, 0) }\nl = []\nflag = 0\nm = 0\nn.times{|_|\n data[_] = gets.split.map &:to_i\n if x0 == data[0]\n flag = 1\n else\n l << (1.0 * y0 - data[_][1]) / (1.0 * x0 - data[_][0])\n end\n}\nputs (l.uniq.size + flag)\n\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn, x0, y0 = gets.split.map &:to_i\ndata = Array.new(n) { Array.new(2, 0) }\nl = []\nflag = 0\nm = 0\nn.times{|_|\n data[_] = gets.split.map &:to_i\n if x0 = data[0]\n flag = 1\n else\n l << (1.0 * y0 - data[_][1]) / (1.0 * x0 - data[_][0]) \n end\n}\nputs (l.uniq.size + flag)\n\n"}, {"source_code": "n,x,y=gets.split.map{|e| e.to_i}\nps=Hash.new(0)\nadd=0\nn.times{\n\txi,yi=gets.split.map{|e| e.to_i}\n\txi=(xi-x)\n\tyi=(yi-y)\n\tif xi==0 then\n\t\tadd=1\n\telse\n\t\tm=1\n\t\tm=-1 if xi<0\n\t\tps[yi/(yi.abs.gcd(xi.abs))*m]+=1\n\t\n\tend\n}\nputs ps.size+add"}, {"source_code": "#!/usr/bin/ruby\n\nSMALL_NUMBER = 0.0000001\ninput_line = gets\npar = input_line.split(' ').map(&:to_i)\nn = par[0]\nx0 = par[1]\ny0 = par[2]\ni = 0;\ncoords = []\nwhile(i < n) do\n input_line = gets\n par = input_line.split(' ').map(&:to_i)\n coords << [par[0],par[1]]\n i = i+1\nend\ncounter = 0\nwhile (coords.size() > 0) do\n ## puts coords.to_s\n ## gets\n counter = counter + 1\n x1 = coords[0][0]\n y1 = coords[0][1]\n\n if ((x0-x1).abs > SMALL_NUMBER && (y0-y1).abs > SMALL_NUMBER) \n coords.delete_if do |coord|\n true if ( ( (coord[0]-x0)/(x1-x0) - (coord[1]-y0)/(y1-y0) ).abs < SMALL_NUMBER)\n end\n elsif ((x0-x1).abs < SMALL_NUMBER)\n coords.delete_if do |coord|\n true if ( (coord[0]-x0).abs < SMALL_NUMBER)\n end\n elsif ((y0-y1).abs < SMALL_NUMBER)\n coords.delete_if do |coord|\n true if ( (coord[1]-y0).abs < SMALL_NUMBER)\n end\n end\nend\n\nputs counter\n"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\ns={}\n(1..n).each do |i|\n x1,y1=gets.split.map(&:to_i)\n s[1.0*(x1-x)/(y1-y)]=1\nend\np s[1.0/0]&&s[-1.0/0]?(s.size):s.size-1"}, {"source_code": "n,x,y=gets.split.map(&:to_i)\ns={}\n(1..n).each do |i|\n\tx1,y1=gets.split.map(&:to_i)\n\ts[1.0*(y1-y)/(x1-x)]=1\nend\np s.size"}, {"source_code": "n,x1,y1 = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.split(\" \").map(&:to_i)\nend\neq = arr.map do |a|\n\tx2,y2 = a\n\t(x2-x1) == 0 ? 10**9 : (y2-y1)/(x2-x1)\nend\nputs eq.uniq.count"}, {"source_code": "n, x, y = gets.split.map(&:to_i)\na = []\nn.times do\n x1, y1 = gets.split.map(&:to_i)\n dx = x1 - x\n dy = y1 - y\n gcd = dx.gcd(dy)\n a << \"#{(dy/gcd).abs}/#{(dx/gcd).abs}\"\nend\nputs a.uniq.count\n"}, {"source_code": "n, x, y = gets.split.map(&:to_i)\na = []\nn.times do\n x1, y1 = gets.split.map(&:to_f)\n a << (x1-x) / (y1-y)\nend\nputs a.uniq.count\n"}, {"source_code": "n, x, y = gets.split.map(&:to_i)\na = []\nn.times do\n x1, y1 = gets.split.map(&:to_f)\n c = (y1 - y) / (x1 - x)\n a << (c.infinite? ? c : c.to_r)\nend\nputs a.uniq.count\n"}], "src_uid": "8d2845c33645ac45d4d37f9493b0c380"} {"source_code": "n,k=gets.split.map(&:to_i)\nrows=[]\nn.times do\n rows<[b[1],b[0][0]]\nend[0..k-1]\nsum = initial_sum + selected.inject(0){|memo, k| memo+k[1]}\nselected.map do |p|\n rows[p[0][0]][p[0][1]] = \"x\"\nend\n\nputs sum\nputs rows.map(&:join)", "positive_code": [{"source_code": "def near_count(row, pos, variants)\n [-1, 1].inject(0) do |res, delta|\n target = pos+delta\n res + (target >= 0 && target < row.length && variants.include?(row[target]) ? 1 : 0)\n end\nend\n\nn, k = gets.split(\" \").map{|e| e.to_i }\n\nqueue = [[], [], []]\n\nplane = (0...n).map do |i|\n row = gets.chomp\n (0...row.length).each do |j|\n next unless row[j] == '.'\n elite_near = near_count(row, j, ['S'])\n queue[elite_near] << [i, j]\n end\n row\nend\n\nrq = queue.inject([]){|r, e| r + e}\n\nrq[0...k].each do |plan|\n plane[plan[0]][plan[1]] = 'x'\nend\n\nans = plane.inject(0) do |r, row|\n r + (0...row.length).inject(0) do |r2, i|\n r2 + (row[i] != 'S' ? 0 : near_count(row, i, ['P', 'x', 'S']))\n end\nend\n\nputs ans\nputs plane\n"}], "negative_code": [], "src_uid": "4f45c5fd31e500c1128cf6cb5e41e3d6"} {"source_code": "n, k=gets.split.map &:to_i\na=gets.split.map(&:to_i).sort\nif k==0\n puts (a[0]==1 ? -1 : 1)\nelse\n puts (k 0\n acc = 0\n ans = -1\n h.keys.sort.each { |i|\n acc += h[i]\n if acc < k\n next\n elsif acc == k\n ans = i\n break\n else\n ans = -1\n break\n end\n }\n \n puts ans\nelse\n minimum = h.keys.min\n if minimum > 1\n puts minimum - 1\n else\n puts \"-1\"\n end\nend"}, {"source_code": "\ndef solution\n _, k = read_ints\n\n as = read_ints.sort\n\n if k == 0\n if as[0] == 1\n puts -1\n else\n puts 1\n end\n return\n end\n\n max_incl = as[k-1]\n min_excl = as[k]\n\n if max_incl == min_excl\n puts(-1)\n else\n puts max_incl\n end\n\n\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}], "negative_code": [{"source_code": "n, k=gets.split.map &:to_i\na=gets.split.map(&:to_i).sort\nputs (k 0\n ans = ar[k-1]\n if h[ans] > 1\n puts \"-1\"\n else\n puts ans\n end\nelse\n if ar.first > 1\n puts ar.first - 1\n else\n puts \"-1\"\n end\nend"}, {"source_code": "# coding: utf-8\n\nn, k = gets.split.map(&:to_i)\nar = [-1] + gets.split.map(&:to_i)\nar.sort!\n#p ar\nif (k < n && ar[k] == ar[k+1]) || (k > 0 && ar[k-1] == ar[k])\n puts ar[0]\nelse\n if k == 0\n if ar[1] > 1\n puts ar[1] - 1\n else\n puts ar[0]\n end\n else\n puts ar[k]\n end\nend"}, {"source_code": "# coding: utf-8\n\nn, k = gets.split.map(&:to_i)\nar = [-1] + gets.split.map(&:to_i)\nar.sort!\n#p ar\nif k == 0 || n == 0 || (k < n && ar[k] == ar[k+1]) || (k > 0 && ar[k-1] == ar[k])\n puts ar[0]\nelse\n puts ar[k]\nend"}], "src_uid": "55297e2a65144323af4d6abd6a6ef050"} {"source_code": "n = gets.to_i\n\na = []\nn.times do\n a << gets.strip\nend\n\nsum = 0\na.each do |x|\n if x == \"Tetrahedron\"\n sum += 4\n elsif x == \"Cube\"\n sum += 6\n elsif x == \"Octahedron\"\n sum += 8\n elsif x == \"Icosahedron\"\n sum += 20\n else\n sum += 12\n end\nend\n\nputs sum\n", "positive_code": [{"source_code": "D = {'T' => 4, 'C' => 6, 'O' => 8, 'D' => 12, 'I' => 20}\np gets.to_i.times.map { D[gets[0]] }.inject(:+)"}, {"source_code": "L = [6, 12, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 4].freeze\np gets.to_i.times.map { L[gets[0].ord - 67] }.inject(:+)"}, {"source_code": "phs = {\"Tetrahedron\" => 4,\"Cube\" => 6,\"Octahedron\" => 8,\"Dodecahedron\" => 12,\"Icosahedron\" => 20}\nn = gets.to_i\nans = 0\n\nn.times do\n s = gets.chomp\n phs.each do |key,value|\n ans += value if key == s\n end\nend\n\nputs ans\n"}, {"source_code": "phs = {'Tetrahedron' => 4,'Cube' => 6,'Octahedron' => 8,'Dodecahedron' => 12,'Icosahedron' => 20}\nn = gets.to_i\nans = 0\n\nn.times do\n s = gets.chomp\n ans += phs[s]\nend\n\nputs ans\n"}, {"source_code": "#!/usr/bin/ruby\nT={'Tetrahedron'=>4,'Cube'=>6,'Octahedron'=>8,'Dodecahedron'=>12,'Icosahedron'=>20}\ns=0;gets.to_i.times{s+=T[gets.chomp]};p s"}, {"source_code": "n = gets.to_i\ndict = {\n\t\"Icosahedron\" => 20,\n\t\"Cube\" => 6,\n\t\"Tetrahedron\" => 4,\n\t\"Dodecahedron\" => 12,\n\t\"Octahedron\" => 8\n}\n\ncount = 0\nwhile n != 0\n\tfigure = gets.chomp.to_s\n\tcount += dict[figure]\n\tn -= 1\nend\nputs count\n\n"}, {"source_code": "# https://codeforces.com/problemset/problem/785/A\n\ncount = gets.to_i\n\nfaces_count = 0\ncount.times do\n name = gets.chomp\n\n faces_count += \n if name == \"Tetrahedron\"\n 4\n elsif name == \"Cube\"\n 6\n elsif name == \"Octahedron\"\n 8\n elsif name == \"Dodecahedron\"\n 12\n elsif name == \"Icosahedron\"\n 20\n end\nend\n\nputs faces_count\n"}, {"source_code": "n = gets.chomp.to_i\nans = 0\nn.times do\n s = gets.chomp\n case s\n when \"Tetrahedron\"\n ans += 4\n when \"Cube\"\n ans += 6\n when \"Octahedron\"\n ans += 8\n when \"Dodecahedron\"\n ans += 12\n when \"Icosahedron\"\n ans += 20\n end\nend\nputs ans"}, {"source_code": "D = {'T' => 4, 'C' => 6, 'O' => 8, 'D' => 12, 'I' => 20}.freeze\np (1..gets.to_i).map { D[gets[0]] }.inject(:+)\n"}, {"source_code": "D, x = {'Tetrahedron' => 4, 'Cube' => 6, 'Octahedron' => 8, 'Dodecahedron' => 12, 'Icosahedron' => 20}.freeze, 0\nfor i in 1..gets.to_i\n x += D[gets.strip]\nend\np x"}, {"source_code": "#!/usr/bin/env ruby -w\n\npolyhedrons = {\"Tetrahedron\" => 4, \"Cube\" => 6, \"Octahedron\" => 8,\n \"Dodecahedron\" => 12, \"Icosahedron\" => 20}\n\nn = gets.strip.to_i\ns = 0\n\nn.times do\n s += polyhedrons[gets.strip.chomp]\nend\n\nputs s\n"}, {"source_code": "ans = 0\ngets.to_i.times do\n s = gets.chomp\n if s == 'Icosahedron'\n ans += 20\n elsif s == 'Cube'\n ans += 6\n elsif s == 'Tetrahedron'\n ans += 4\n elsif s == 'Dodecahedron'\n ans += 12\n elsif s == 'Octahedron'\n ans += 8\n end\nend\nputs ans\n"}, {"source_code": "poly = { \"Tetrahedron\" => 4, \"Cube\" => 6, \"Octahedron\" => 8, \"Dodecahedron\" => 12, \"Icosahedron\" => 20 }\nn = gets.strip.to_i\nans = 0\nn.times do\n s = gets.strip\n ans += poly[s]\nend\nputs ans\n"}, {"source_code": "h={}\nh[\"Tetrahedron\"]=4\nh[\"Cube\"]=6\nh[\"Octahedron\"]=8\nh[\"Dodecahedron\"]=12\nh[\"Icosahedron\"]=20\n\nans=0\ngets.to_i.times{\n\tans+=h[gets.chomp]\n}\n\nputs ans\n\n\n"}, {"source_code": "n = gets.chomp.to_i\no = {'Tetrahedron' => 0,'Cube'=>0,'Octahedron'=>0,'Dodecahedron'=>0,'Icosahedron'=>0}\nn.times.each do \ns = gets.chomp\n o[s] += 1\nend\n\nputs o['Tetrahedron'] * 4 + o['Cube'] * 6 + o['Octahedron'] * 8 + o['Dodecahedron'] * 12 + o['Icosahedron'] * 20\n"}, {"source_code": "def total(poly)\n\treturn 4 if poly == \"Tetrahedron\"\n\treturn 6 if poly == \"Cube\"\n\treturn 8 if poly == \"Octahedron\"\n\treturn 12 if poly == \"Dodecahedron\"\n\treturn 20 if poly == \"Icosahedron\"\nend\n\nfaces = 0\nn = gets.chomp.to_i\n\nn.times do\n\tpoly = gets.chomp\n\tfaces = faces + total(poly)\nend\n\nputs(faces)"}, {"source_code": "f = {\n Tetrahedron: 4,\n Cube: 6,\n Octahedron: 8,\n Dodecahedron: 12,\n Icosahedron: 20\n}\n\nn = gets.to_i\ns = 0\n\n(1..n).each { s += f[gets.chomp.to_sym] }\n\nputs s"}, {"source_code": "n=gets.to_i\np (1..n).map{\n s=gets[0]\n s==?T ? 4 : s==?C ? 6 : s==?O ? 8 : s==?D ? 12 : 20\n}.inject(:+)\n\n"}, {"source_code": "n=gets.chomp\n#puts n\ntotal_faces=0\nfaces = {\"Tetrahedron\" => 4, \"Cube\" => 6, \"Octahedron\" => 8, \"Dodecahedron\" => 12, \"Icosahedron\" => 20}\n#puts faces[\"Tetrahedron\"]\n#puts faces[\"Cube\"]\nfor i in 1..n.to_i\n #polyhedron=gets\n polyhedron=gets.chomp\n #print i\n #puts polyhedron\n #puts faces[\"Cube\"]\n total_faces=total_faces + faces[polyhedron].to_i\nend\nputs total_faces\n"}, {"source_code": "# coding: utf-8\n\n# 4\n# Icosahedron\n# Cube\n# Tetrahedron\n# Dodecahedron\n\nMAPPED = {\n \"Tetrahedron\" => 4,\n \"Cube\" => 6,\n \"Octahedron\" => 8,\n \"Dodecahedron\" => 12,\n \"Icosahedron\" => 20\n}\n\nn = gets.to_i\nc = 0\nn.times {\n input = gets\n input.strip!\n c += MAPPED[input]\n}\n\nputs c"}, {"source_code": "n = gets.chomp.to_i\npolyhedrons = { \"Tetrahedron\" => 4, \"Cube\" => 6, \"Octahedron\" => 8, \"Dodecahedron\" => 12, \"Icosahedron\" => 20}\nsum = 0\nfor i in (0..n-1)\n\tx = gets.chomp\n\tif x == \"Tetrahedron\"\n\t\tsum += polyhedrons[\"Tetrahedron\"]\n\telsif x == \"Cube\"\n\t\tsum += polyhedrons[\"Cube\"]\n\telsif x == \"Octahedron\"\n\t\tsum += polyhedrons[\"Octahedron\"]\n\telsif x == \"Dodecahedron\"\n\t\tsum += polyhedrons[\"Dodecahedron\"]\n\telsif x == \"Icosahedron\"\n\t\tsum += polyhedrons[\"Icosahedron\"]\n\tend\nend\nprint sum"}, {"source_code": "c = {'T'=>4,'C'=>6,'O'=>8,'D'=>12,'I'=>20}\np gets.to_i.times.map {c[gets[0]]}.inject(:+)"}, {"source_code": "n = gets.to_i\ncount = {}\ncount['Tetrahedron']||=0\ncount['Cube']||=0\ncount['Octahedron']||=0\ncount['Dodecahedron']||=0\ncount['Icosahedron']||=0\nfor i in (0...n)\n cur = gets.chomp\n count[cur]+=1\nend\nputs (count['Tetrahedron']*4 + count['Cube']*6 + count['Octahedron']*8 + count['Dodecahedron']*12 + count['Icosahedron']*20)"}, {"source_code": "n = gets.to_i\ncount = {'Tetrahedron'=>4,'Cube'=>6,'Octahedron'=>8,'Dodecahedron'=>12,'Icosahedron'=>20}\nans = 0\nfor i in (0...n) do ans+=count[gets.chomp] end\nputs ans"}, {"source_code": "n = gets.to_i\ncount = {}\ncount['Tetrahedron']||=4\ncount['Cube']||=6\ncount['Octahedron']||=8\ncount['Dodecahedron']||=12\ncount['Icosahedron']||=20\nans = 0\nfor i in (0...n)\n cur = gets.chomp\n ans+=count[cur]\nend\nputs ans"}, {"source_code": "n = gets.to_i\ncount = {'Tetrahedron'=>4,'Cube'=>6,'Octahedron'=>8,'Dodecahedron'=>12,'Icosahedron'=>20}\nans = 0\nfor i in (0...n)\n cur = gets.chomp\n ans+=count[cur]\nend\nputs ans"}, {"source_code": "$n = gets\n$n = $n.to_i\narr = []\n(0...$n).each do |i|\n\tarr << gets.chomp\nend\n\npolygon = {\"Tetrahedron\" => 4, \"Icosahedron\" => 20, \"Cube\" => 6, \"Dodecahedron\" => 12, \"Octahedron\" => 8}\n\n$k = 0\narr.each do |i|\n\t$k += polygon[i]\nend\nprint $k\n"}, {"source_code": "\nn = gets.to_i\ni = 0,sum =0\nn.times do\n str = gets.strip\n if str == \"Tetrahedron\"\n sum = sum +4\n elsif str == \"Cube\"\n sum = sum + 6\n elsif str == \"Octahedron\"\n sum= sum+ 8\n elsif str == \"Dodecahedron\"\n sum = sum + 12\n else\n sum = sum + 20\n end\n\nend\nprint(sum,\"\\n\")"}, {"source_code": "n = gets.chomp.to_i\nsum = 0\nhash = {}\nhash[\"Tetrahedron\"] = 4\nhash[\"Cube\"] = 6\nhash[\"Octahedron\"] = 8\nhash[\"Dodecahedron\"] = 12\nhash[\"Icosahedron\"] = 20\n\nn.times do \n\tsum += hash[gets.chomp]\nend\nputs sum\n"}, {"source_code": "h = {\n 'Tetrahedron' => 4,\n 'Cube' => 6,\n 'Octahedron' => 8,\n 'Dodecahedron' => 12,\n 'Icosahedron' => 20\n}\nn = gets.to_i\np n.times.map{gets.chomp}.inject(0){|s, x| s + h[x]}\n\n\n"}, {"source_code": "sides = {\"Tetrahedron\"=>4, \"Cube\"=>6, \"Octahedron\"=>8,\n\t\"Dodecahedron\"=>12, \"Icosahedron\"=>20}\nn=gets.chomp.to_i\nans=0\nfor i in 0...n\n\tans+=sides[gets.chomp]\nend\nputs ans"}, {"source_code": "h = {\n 'Tetrahedron' => 4,\n 'Cube' => 6,\n 'Octahedron' => 8,\n 'Dodecahedron' => 12,\n 'Icosahedron' => 20\n}\nn = gets.to_i\nnh = 0\nn.times do\n s = gets.strip\n nh += h[s]\nend\nputs nh\n\n"}, {"source_code": "n = gets.to_i\n\nsizes = {\n 'Tetrahedron' => 4,\n 'Cube' => 6,\n 'Octahedron' => 8,\n 'Dodecahedron' => 12,\n 'Icosahedron' => 20\n}\n\nputs 1.upto(n).inject(0) { |result, i| result + sizes[gets.chomp] }\n"}, {"source_code": "poly = {\n \"Tetrahedron\" => 4,\n \"Cube\" => 6,\n \"Octahedron\" => 8,\n \"Dodecahedron\" => 12,\n \"Icosahedron\" => 20\n}\nn = gets.strip.to_i\nans = 0;\nfor i in 1..n\n s = gets.strip\n ans += poly[s]\nend\nputs ans"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nans = 0\nn.times do\n s = gets.chomp\n case s\n when \"Icosahedron\"\n ans += 4\n when \"Cube\"\n ans += 6\n when \"Octahedron\"\n ans += 8\n when \"Dodecahedron\"\n ans += 12\n else \n ans += 20\n end\nend\nputs ans"}], "src_uid": "e6689123fefea251555e0e096f58f6d1"} {"source_code": "def min(*values)\n values.min\nend\ninput_str = gets.chomp\ninput_array = input_str.split(\" \")\nn = Integer(input_array[0])\nk = Integer(input_array[1])\nm = Integer(input_array[2])\ninput_str = gets.chomp\nwords = input_str.split(\" \")\ninput_str = gets.chomp\nscore = input_str.split(\" \")\nfor i in 0...n do\n\tscore[i] = Integer(score[i])\nend\nmin_score = Array.new(k)\ngroup = Hash.new\nfor i in 0...k do\n\tinput_str = gets.chomp\n\tinput_array = input_str.split(\" \")\n\tinput_array.shift\n\tinput_array.each{ |input|\n\t\ttemp = Integer(input)-1\n\t\tif min_score[i] == nil\n\t\t\tmin_score[i] = score[temp]\n\t\telse\n\t\t\tmin_score[i] = min(min_score[i],score[temp])\n\t\tend\n\t\tgroup[words[temp]] = i\n\t}\nend\ninput_str = gets.chomp\ninput_array = input_str.split(\" \")\nresult = 0\ninput_array.each{ |input|\n\tresult+=min_score[group[input]]\n}\nputs result\n\t", "positive_code": [{"source_code": "def min(*values)\n values.min\nend\ninput_str = gets.chomp\ninput_array = input_str.split(\" \")\nn = Integer(input_array[0])\nk = Integer(input_array[1])\nm = Integer(input_array[2])\ninput_str = gets.chomp\nwords = input_str.split(\" \")\ninput_str = gets.chomp\nscore = input_str.split(\" \").map(&:to_i)\nmin_score = Array.new(k)\ngroup = Hash.new\nfor i in 0...k do\n\tinput_str = gets.chomp\n\tinput_array = input_str.split(\" \")\n\tinput_array.shift\n\tinput_array.each{ |input|\n\t\ttemp = Integer(input)-1\n\t\tif min_score[i] == nil\n\t\t\tmin_score[i] = score[temp]\n\t\telse\n\t\t\tmin_score[i] = min(min_score[i],score[temp])\n\t\tend\n\t\tgroup[words[temp]] = i\n\t}\nend\ninput_str = gets.chomp\ninput_array = input_str.split(\" \")\nresult = 0\ninput_array.each{ |input|\n\tresult+=min_score[group[input]]\n}\nputs result\n\t"}], "negative_code": [], "src_uid": "296552dc2df23b3920baef7d47d0a591"} {"source_code": "DBG = !true\nn = gets.to_i\na = gets.split.map{|z| z.to_i}\nh = {}\nfor x in a\n if h.has_key?(x)\n h[x] += 1\n else\n h[x] = 1\n end\nend\ns4 = {}\ns2 = {}\ns1 = {}\nh.each{ |k,v|\n if v%4 == 0\n s4[k] = v\n elsif v%2 == 0\n if n%2 == 0\n puts \"NO\"\n exit 0\n end\n s4[k] = v-2 if v>=6\n s2[k] = 2\n else\n if n%2 == 0 || s1.size > 0\n puts \"NO\"\n exit 0\n end\n if v>=4\n s4[k] = v-v%4\n v = v%4\n end\n if v>=2 # must be 3\n s2[k] = v-1\n end\n s1[k] = 1\n end\n}\nif n%2 == 1\n m = n/2\n if DBG\n print s4\n puts \"- s4\"\n end\n sum4 = s4.values.inject(:+)\n sum4 = 0 if sum4.nil?\n if sum4 < 4*m*m\n puts \"NO\"\n exit 0\n end\nend\n\nif DBG\n puts \"n #{n}\"\n print s4\n puts \"\"\n print s2\n puts \"\"\n print s1\n puts \"\"\nend\n\nt = Array.new(n)\nt.map!{Array.new(n)}\ni = 0\nj = 0\n\nm = n/2\nif n%2 == 0\n s4.each { |k,v|\n while v>0\n t[i][j] = k\n v -= 4\n s4[k] -= 4\n if j==m-1\n i += 1\n j = 0\n else\n j += 1\n end\n end\n }\n for i in 0...m\n for j in 0...m\n t[2*m-1-i][j] = t[i][j]\n t[i][2*m-1-j] = t[i][j]\n t[2*m-1-i][2*m-1-j] = t[i][j]\n end\n end\n\nelse # n%2 == 1\n s4.each { |k,v|\n while v>0 && i0\n t[i][j] = k\n v -= 2\n if j==m-1\n i = 0\n j = m\n vert = false\n elsif vert\n j += 1\n else\n i += 1\n end\n end\n }\n\n s1.each { |k,v|\n t[m][m] = k\n }\n\n if DBG\n puts \"after mm\"\n for i in 0..m\n for j in 0..m\n print \"#{t[i][j] }\"\n end\n puts \"\"\n end\n puts \"\"\n end\n\n for i in 0...m\n for j in 0...m\n t[2*m-i][2*m-j] = t[i][j]\n t[i][2*m-j] = t[i][j]\n t[2*m-i][j] = t[i][j]\n end\n t[2*m-i][m] = t[i][m]\n t[m][2*m-i] = t[m][i]\n end\nend\n\nputs \"YES\"\nfor i in 0...n\n for j in 0...n\n print \"#{t[i][j]} \"\n end\n puts \"\"\nend\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ncnt = a.tally.map { |k, v| [v, k] }\n\nans = Array.new(n) { [-1] * n }\n\nset = lambda do |i, j|\n\tcount =\n\t\tif n.even?\n\t\t\t4\n\t\telse\n\t\t\tf1, f2 = i == n / 2, j == n / 2\n\t\t\tif f1 && f2\n\t\t\t\t1\n\t\t\telsif !f1 && !f2\n\t\t\t\t4\n\t\t\telse\n\t\t\t\t2\n\t\t\tend\n\t\tend\n\tcnt = cnt.sort.reverse\n\tcnt[0][0] -= count\n\tputs('NO') + exit if cnt[0][0] < 0\n\tval = cnt[0][1]\n\tans[i][j] = val\n\tans[i][~j] = val\n\tans[~i][j] = val\n\tans[~i][~j] = val\nend\n\nif n.even?\n\t(0...n / 2).each { |i| (0...n / 2).each { |j| set[i, j] } }\nelse\n\t(0...n / 2).each { |i| (0...n / 2).each { |j| set[i, j] } }\n\t(0...n / 2).each do |i|\n\t\tset[n / 2, i]\n\t\tset[i, n / 2]\n\tend\n\tset[n / 2, n / 2]\nend\nputs 'YES'\nputs ans.map { _1.join(' ') }.join(\"\\n\")\n"}, {"source_code": "n = gets.to_i\ncnt = gets.split.map(&:to_i).tally.map { [_2, _1] }\nans = Array.new(n) { [-1] * n }\n\nset = lambda do |i, j|\n\tf1, f2 = n.odd? && i == n / 2, n.odd? && j == n / 2\n\tcnt.sort!.reverse!\n\tcnt[0][0] -=\n\t\tif f1 && f2\n\t\t\t1\n\t\telsif !f1 && !f2\n\t\t\t4\n\t\telse\n\t\t\t2\n\t\tend\n\tputs('NO') + exit if cnt[0][0] < 0\n\tans[i][j] = ans[i][~j] = ans[~i][j] = ans[~i][~j] = cnt[0][1]\nend\n\n(0...n / 2).each { |i| (0...n / 2).each { |j| set[i, j] } }\nif n.odd?\n\t(0...n / 2).each do |i|\n\t\tset[n / 2, i]\n\t\tset[i, n / 2]\n\tend\n\tset[n / 2, n / 2]\nend\nputs 'YES', ans.map { _1.join(' ') }.join(\"\\n\")\n"}, {"source_code": "def print_even(n, r4)\n puts \"YES\"\n h = n/2\n for i in 0..n-1\n for j in 0..n-1\n if i=n/2 && j=n/2\n x = i\n y = j%h\n y = h-y-1\n end\n\n if i>=n/2 && j>=n/2\n x = i%h\n x = h-x-1\n y = j%h\n y = h-y-1\n end\n\n print(r4[x*h+y].to_s)\n print(\" \") unless j == n-1\n end\n puts\n end\nend\n\ndef print_odd(n, r4, r2, r1)\n puts \"YES\"\n c = n/2\n h = n/2\n\n r2_1 = r2[0..n/2-1]\n r2_2 = r2[n/2..-1]\n for i in 0..n-1\n for j in 0..n-1\n if i == c || j == c\n if i == c && j == c\n print r1\n elsif i == c\n if j < c\n print r2_1[j]\n else\n y = (j-1)%h\n y = h-y-1\n print r2_1[y]\n end\n\n elsif j == c\n if i < c\n print r2_2[i]\n else\n y = (i-1)%h\n y = h-y-1\n print r2_2[y]\n end\n end\n else\n\n if ic && jc\n x = i\n y = (j-1)%h\n y = h-y-1\n end\n\n if i>c && j>c\n x = (i-1)%h\n x = h-x-1\n y = (j-1)%h\n y = h-y-1\n end\n\n print(r4[x*h+y].to_s)\n end\n print(\" \") unless j == n-1\n end\n puts\n end\nend\n\n\ndef main()\n n = STDIN.gets.to_i\n aa = STDIN.gets.strip.split.map(&:to_i)\n counts = {}\n aa.each do |a|\n counts[a] ||= 0;\n counts[a] += 1;\n end\n\n center = nil\n if n%2 == 0\n unless counts.all? { |k, v| v%4==0 }\n return puts \"NO\"\n end\n\n r4 = []\n counts.each do |k, v|\n (v/4).times do\n r4.push(k)\n end\n end\n print_even(n, r4)\n else\n # (4*n-1) + 2*(n-1) + 1\n r1 = counts.keys.select { |k| counts[k] % 2 == 1 }\n unless r1.size == 1\n puts \"NO\"\n return\n end\n r1 = r1[0]\n counts[r1] -= 1\n\n # \u3059\u3079\u3066\u5076\u6570\n unless counts.all? { |k, v| v%2==0 }\n return puts \"NO\"\n end\n\n r4_num = ((n-1)/2) ** 2\n r4 = []\n r2 = []\n\n keys = counts.keys.sort_by { |k| counts[k] }.reverse\n idx = 0\n while idx <= keys.length-1 do\n k = keys[idx]\n if counts[k] == 0\n idx+=1\n next\n end\n\n if r4.length < r4_num\n if counts[k]%4==0\n counts[k] -= 4\n r4.push(k)\n next\n end\n end\n\n counts[k] -= 2\n r2.push(k)\n end\n\n if r4.length < r4_num\n puts \"NO\"\n return\n end\n print_odd(n, r4, r2, r1)\n end\nend\n\nmain"}, {"source_code": "$n = Integer(gets)\n$ans = []\ndef setans(key, val)\n $ans[key[0]][key[1]] = val\n $ans[$n-key[0]-1][key[1]] = val\n $ans[key[0]][$n-key[1]-1] = val\n $ans[$n-key[0]-1][$n-key[1]-1] = val\nend\nfor i in 1..$n \n $ans.push(Array.new($n))\nend\nhsh = Hash.new()\ngets.split().each do |y| \n x = Integer(y)\n hsh[x] = 0 unless hsh[x]\n hsh[x] += 1\nend\nfours = []\nfor i in 0...$n/2\n for j in 0...$n/2\n fours.push([i, j])\n end\nend\ntwos = []\nones = []\nif $n % 2 == 1\n for i in 0...$n/2 \n twos.push([i, $n/2])\n twos.push([$n/2, i])\n end\n ones.push([$n/2, $n/2])\nend\nable = true\nbegin\n hsh.each do |num, cnt|\n if cnt%2 == 1\n setans(ones.pop(), num)\n cnt-=1\n end\n if cnt%4 == 2\n setans(twos.pop(), num)\n cnt-=2\n end\n until cnt == 0 or fours.empty?\n setans(fours.pop(), num)\n cnt-=4\n end\n until cnt == 0 or twos.empty?\n setans(twos.pop(), num)\n cnt-=2\n end\n until cnt == 0 or ones.empty?\n setans(ones.pop(), num)\n cnt-=1\n end\n raise \"jizz\" if cnt != 0\n end\n puts \"YES\"\n $ans.each do |x|\n puts x.join(\" \")\n end\nrescue\n puts \"NO\"\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = Hash.new(0)\na.each do |i|\n b[i] += 1\nend\nc = d = 0\nb.values.each do |i|\n c += 1 if i.odd?\n d += 1 if i%4 > 1\nend\nif (n.odd? && (c != 1 || d > n-1)) || (n.even? && (c != 0 || d != 0))\n puts \"NO\"\n exit\nend\nans = Array.new(n).map{Array.new(n,0)}\nif n.odd?\n b.keys.each do |k|\n if b[k].odd?\n ans[n/2][n/2] = k\n b[k] -= 1\n break\n end\n end\n for i in 0..n/2-1\n b.keys.each do |k|\n if b[k]%4 == 2\n ans[i][n/2] = ans[n-i-1][n/2] = k\n b[k] -= 2\n break\n end\n end\n end\n for i in 0..n/2-1\n b.keys.each do |k|\n if b[k]%4 == 2\n ans[n/2][i] = ans[n/2][n-i-1] = k\n b[k] -= 2\n break\n end\n end\n end\n for i in 0..n/2-1\n b.keys.each do |k|\n if ans[i][n/2] == 0 && b[k] != 0\n ans[i][n/2] = ans[n-i-1][n/2] = k\n b[k] -= 2\n break\n end\n end\n end\n for i in 0..n/2-1\n b.keys.each do |k|\n if ans[n/2][i] == 0 && b[k] != 0\n ans[n/2][i] = ans[n/2][n-i-1] = k\n b[k] -= 2\n break\n end\n end\n end\nend\nfor i in 0..n/2-1\n for j in 0..n/2-1\n b.keys.each do |k|\n if b[k] != 0\n ans[i][j] = ans[i][n-1-j] = ans[n-1-i][j] = ans[n-1-i][n-1-j] = k\n b[k] -= 4\n break\n end\n end\n end\nend\nputs \"YES\"\nans.each do |arr|\n puts arr.join(\" \")\nend"}], "negative_code": [{"source_code": "def print_even(n, r4)\n puts \"YES\"\n h = n/2\n for i in 0..n-1\n for j in 0..n-1\n if i=n/2 && j=n/2\n x = i\n y = j%h\n y = h-y-1\n end\n\n if i>=n/2 && j>=n/2\n x = i%h\n x = h-x-1\n y = j%h\n y = h-y-1\n end\n\n print(r4[x*h+y].to_s)\n print(\" \") unless j == n-1\n end\n puts\n end\nend\n\ndef print_odd(n, r4, r2, r1)\n puts \"YES\"\n c = n/2\n h = n/2\n\n r2_1 = r2[0..n/2-1]\n r2_2 = r2[n/2..-1]\n for i in 0..n-1\n for j in 0..n-1\n if i == c || j == c\n if i == c && j == c\n print r1\n elsif i == c\n if j < c\n print r2_1[j]\n else\n y = j%h\n print r2_1[y]\n end\n\n elsif j == c\n if i < c\n print r2_2[i]\n else\n x = i%h\n print r2_2[x]\n end\n end\n else\n\n if ic && jc\n x = i\n y = (j-1)%h\n y = h-y-1\n end\n\n if i>c && j>c\n x = (i-1)%h\n x = h-x-1\n y = (j-1)%h\n y = h-y-1\n end\n\n print(r4[x*h+y].to_s)\n end\n print(\" \") unless j == n-1\n end\n puts\n end\nend\n\n\ndef main()\n n = STDIN.gets.to_i\n aa = STDIN.gets.strip.split.map(&:to_i)\n counts = {}\n aa.each do |a|\n counts[a] ||= 0;\n counts[a] += 1;\n end\n\n center = nil\n if n%2 == 0\n unless counts.all? { |k, v| v%4==0 }\n return puts \"NO\"\n end\n\n r4 = []\n counts.each do |k, v|\n (v/4).times do\n r4.push(k)\n end\n end\n print_even(n, r4)\n else\n # (4*n-1) + 2*(n-1) + 1\n r1 = counts.keys.select { |k| counts[k] % 2 == 1 }\n unless r1.size == 1\n puts \"NO\"\n return\n end\n r1 = r1[0]\n counts[r1] -= 1\n\n # \u3059\u3079\u3066\u5076\u6570\n unless counts.all? { |k, v| v%2==0 }\n return puts \"NO\"\n end\n\n r4_num = ((n-1)/2) ** 2\n r4 = []\n r2 = []\n\n keys = counts.keys.sort_by { |k| counts[k] }.reverse\n idx = 0\n while idx <= keys.length-1 do\n k = keys[idx]\n if counts[k] == 0\n idx+=1\n next\n end\n\n if r4.length < r4_num\n if counts[k]%4==0\n counts[k] -= 4\n r4.push(k)\n next\n end\n end\n\n counts[k] -= 2\n r2.push(k)\n end\n\n if r4.length < r4_num\n puts \"NO\"\n return\n end\n print_odd(n, r4, r2, r1)\n end\nend\n\nmain"}, {"source_code": "def print_even(n, r4)\n puts \"YES\"\n h = n/2\n for i in 0..n-1\n for j in 0..n-1\n if i=n/2 && j=n/2\n x = i\n y = j%h\n y = h-y-1\n end\n\n if i>=n/2 && j>=n/2\n x = i%h\n x = h-x-1\n y = j%h\n y = h-y-1\n end\n\n print(r4[x*h+y].to_s)\n print(\" \") unless j == n-1\n end\n puts\n end\nend\n\ndef print_odd(n, r4, r2, r1)\n puts \"YES\"\n c = n/2\n h = n/2\n for i in 0..n-1\n for j in 0..n-1\n if i == c || j == c\n if i == c && j == c\n print r1\n elsif i == c\n if j < c\n print r2[j]\n else\n print r2[n-j-1]\n end\n\n elsif j == c\n if i < c\n print r2[i]\n else\n print r2[n-i-1]\n end\n end\n else\n\n if ic && jc\n x = i\n y = (j-1)%h\n y = h-y-1\n end\n\n if i>c && j>c\n x = (i-1)%h\n x = h-x-1\n y = (j-1)%h\n y = h-y-1\n end\n\n print(r4[x*h+y].to_s)\n end\n print(\" \") unless j == n-1\n end\n puts\n end\nend\n\n\ndef main()\n n = STDIN.gets.to_i\n aa = STDIN.gets.strip.split.map(&:to_i)\n counts = {}\n aa.each do |a|\n counts[a] ||= 0;\n counts[a] += 1;\n end\n\n center = nil\n if n%2 == 0\n unless counts.all? { |k, v| v%4==0 }\n return puts \"NO\"\n end\n\n r4 = []\n counts.each do |k, v|\n (v/4).times do\n r4.push(k)\n end\n end\n print_even(n, r4)\n else\n # (4*n-1) + 2*(n-1) + 1\n r1 = counts.keys.select { |k| counts[k] % 4 == 1 }\n unless r1.size == 1\n puts \"NO\"\n return\n end\n r1 = r1[0]\n counts[r1] -= 1\n\n # \u3059\u3079\u3066\u5076\u6570\n unless counts.all? { |k, v| v%2==0 }\n return puts \"NO\"\n end\n\n r4_num = ((n-1)/2) ** 2\n r4 = []\n r2 = []\n\n keys = counts.keys.sort_by { |k| counts[k] }.reverse\n idx = 0\n while idx <= keys.length-1 do\n k = keys[idx]\n if counts[k] == 0\n idx+=1\n next\n end\n\n if r4.length < r4_num\n if counts[k]%4==0\n counts[k] -= 4\n r4.push(k)\n next\n end\n end\n\n counts[k] -= 2\n r2.push(k)\n end\n\n if r4.length < r4_num\n puts \"NO\"\n return\n end\n print_odd(n, r4, r2, r1)\n end\nend\n\nmain"}, {"source_code": "def print_even(n, r4)\n puts \"YES\"\n h = n/2\n for i in 0..n-1\n for j in 0..n-1\n if i=n/2 && j=n/2\n x = i\n y = j%h\n y = h-y-1\n end\n\n if i>=n/2 && j>=n/2\n x = i%h\n x = h-x-1\n y = j%h\n y = h-y-1\n end\n\n print(r4[x*h+y].to_s)\n print(\" \") unless j == n-1\n end\n puts\n end\nend\n\ndef print_odd(n, r4, r2, r1)\n puts \"YES\"\n c = n/2\n h = n/2\n for i in 0..n-1\n for j in 0..n-1\n if i == c || j == c\n if i == c && j == c\n print r1\n elsif i == c\n if j < c\n print r2[j]\n else\n print r2[n-j-1]\n end\n\n elsif j == c\n if i < c\n print r2[i]\n else\n print r2[n-i-1]\n end\n end\n else\n\n if ic && jc\n x = i\n y = (j-1)%h\n y = h-y-1\n end\n\n if i>c && j>c\n x = (i-1)%h\n x = h-x-1\n y = (j-1)%h\n y = h-y-1\n end\n\n print(r4[x*h+y].to_s)\n end\n print(\" \") unless j == n-1\n end\n puts\n end\nend\n\n\ndef main()\n n = STDIN.gets.to_i\n aa = STDIN.gets.strip.split.map(&:to_i)\n counts = {}\n aa.each do |a|\n counts[a] ||= 0;\n counts[a] += 1;\n end\n\n center = nil\n if n%2 == 0\n unless counts.all? { |k, v| v%4==0 }\n return puts \"NO\"\n end\n\n r4 = []\n counts.each do |k, v|\n (v/4).times do\n r4.push(k)\n end\n end\n print_even(n, r4)\n else\n # (4*n-1) + 2*(n-1) + 1\n r1 = counts.keys.select { |k| counts[k] % 2 == 1 }\n unless r1.size == 1\n puts \"NO\"\n return\n end\n r1 = r1[0]\n counts[r1] -= 1\n\n # \u3059\u3079\u3066\u5076\u6570\n unless counts.all? { |k, v| v%2==0 }\n return puts \"NO\"\n end\n\n r4_num = ((n-1)/2) ** 2\n r4 = []\n r2 = []\n\n keys = counts.keys.sort_by { |k| counts[k] }.reverse\n idx = 0\n while idx <= keys.length-1 do\n k = keys[idx]\n if counts[k] == 0\n idx+=1\n next\n end\n\n if r4.length < r4_num\n if counts[k]%4==0\n counts[k] -= 4\n r4.push(k)\n next\n end\n end\n\n counts[k] -= 2\n r2.push(k)\n end\n\n if r4.length < r4_num\n puts \"NO\"\n return\n end\n print_odd(n, r4, r2, r1)\n end\nend\n\nmain"}, {"source_code": "DBG = !true\nn = gets.to_i\na = gets.split.map{|z| z.to_i}\nh = {}\nfor x in a\n if h.has_key?(x)\n h[x] += 1\n else\n h[x] = 1\n end\nend\ns4 = {}\ns2 = {}\ns1 = {}\nh.each{ |k,v|\n if v%4 == 0\n s4[k] = v\n elsif v%2 == 0\n if n%2 == 0\n puts \"NO\"\n exit 0\n end\n s4[k] = v-2 if v>=6\n s2[k] = 2\n else\n if n%2 == 0 || s1.size > 0\n puts \"NO\"\n exit 0\n end\n if v>=4\n s4[k] = v-v%4\n v = v%4\n end\n if v>=2 # must be 3\n s2[k] = v-1\n end\n s1[k] = 1\n end\n}\nif n%2 == 1\n m = n/2\n print s4 if DBG\n sum4 = s4.values.inject(:+)\n sum4 = 0 if sum4.nil?\n if sum4 < m*m\n puts \"NO\"\n exit 0\n end\nend\n\nif DBG\n puts \"n #{n}\"\n print s4\n puts \"\"\n print s2\n puts \"\"\n print s1\n puts \"\"\nend\n\nt = Array.new(n)\nt.map!{Array.new(n)}\ni = 0\nj = 0\n\nm = n/2\nif n%2 == 0\n s4.each { |k,v|\n while v>0\n t[i][j] = k\n v -= 4\n s4[k] -= 4\n if j==m-1\n i += 1\n j = 0\n else\n j += 1\n end\n end\n }\n for i in 0...m\n for j in 0...m\n t[2*m-1-i][j] = t[i][j]\n t[i][2*m-1-j] = t[i][j]\n t[2*m-1-i][2*m-1-j] = t[i][j]\n end\n end\n\nelse # n%2 == 1\n s4.each { |k,v|\n while v>0 && i0\n t[i][j] = k\n v -= 2\n if j==m-1\n i = 0\n j = m\n vert = false\n elsif vert\n j += 1\n else\n i += 1\n end\n end\n }\n\n s1.each { |k,v|\n t[m][m] = k\n }\n\n if DBG\n puts \"after mm\"\n for i in 0..m\n for j in 0..m\n print \"#{t[i][j] }\"\n end\n puts \"\"\n end\n puts \"\"\n end\n\n for i in 0...m\n for j in 0...m\n t[2*m-i][2*m-j] = t[i][j]\n t[i][2*m-j] = t[i][j]\n t[2*m-i][j] = t[i][j]\n end\n t[2*m-i][m] = t[i][m]\n t[m][2*m-i] = t[m][i]\n end\nend\n\nputs \"YES\"\nfor i in 0...n\n for j in 0...n\n print \"#{t[i][j]} \"\n end\n puts \"\"\nend\n"}, {"source_code": "DBG = !true\nn = gets.to_i\na = gets.split.map{|z| z.to_i}\nh = {}\nfor x in a\n if h.has_key?(x)\n h[x] += 1\n else\n h[x] = 1\n end\nend\ns4 = {}\ns2 = {}\ns1 = {}\nh.each{ |k,v|\n if v%4 == 0\n s4[k] = v\n elsif v%2 == 0\n if n%2 == 0\n puts \"NO\"\n exit 0\n end\n s4[k] = v-2 if v>=6\n s2[k] = 2\n else\n if n%2 == 0 || s1.size > 0\n puts \"NO\"\n exit 0\n end\n if v>=4\n s4[k] = v-v%4\n v = v%4\n end\n if v>=2 # must be 3\n s2[k] = v-1\n end\n s1[k] = 1\n end\n}\n\nif DBG\n puts \"n #{n}\"\n print s4\n puts \"\"\n print s2\n puts \"\"\n print s1\n puts \"\"\nend\n\nt = Array.new(n)\nt.map!{Array.new(n)}\ni = 0\nj = 0\n\nm = n/2\nif n%2 == 0\n s4.each { |k,v|\n while v>0\n t[i][j] = k\n v -= 4\n s4[k] -= 4\n if j==m-1\n i += 1\n j = 0\n else\n j += 1\n end\n end\n }\n for i in 0...m\n for j in 0...m\n t[2*m-1-i][j] = t[i][j]\n t[i][2*m-1-j] = t[i][j]\n t[2*m-1-i][2*m-1-j] = t[i][j]\n end\n end\n\nelse # n%2 == 1\n s4.each { |k,v|\n while v>0 && i0\n t[i][j] = k\n v -= 2\n if j==m-1\n i = 0\n j = m\n vert = false\n elsif vert\n j += 1\n else\n i += 1\n end\n end\n }\n\n s1.each { |k,v|\n t[m][m] = k\n }\n\n if DBG\n puts \"after mm\"\n for i in 0..m\n for j in 0..m\n print \"#{t[i][j] }\"\n end\n puts \"\"\n end\n puts \"\"\n end\n\n for i in 0...m\n for j in 0...m\n t[2*m-i][2*m-j] = t[i][j]\n t[i][2*m-j] = t[i][j]\n t[2*m-i][j] = t[i][j]\n end\n t[2*m-i][m] = t[i][m]\n t[m][2*m-i] = t[m][i]\n end\nend\n\nputs \"YES\"\nfor i in 0...n\n for j in 0...n\n print \"#{t[i][j]} \"\n end\n puts \"\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = Hash.new(0)\na.each do |i|\n b[i] += 1\nend\nc = 0\nb.values.each do |i|\n c += 1 if i%4 != 0\nend\nif (n.odd? && c != 1) || (n.even? && c != 0)\n puts \"NO\"\n exit\nend\nans = Array.new(n).map{Array.new(n,0)}\nif n.odd?\n b.keys.each do |k|\n if b[k].odd?\n ans[n/2][n/2] = k\n b[k] -= 1\n break\n end\n end\n for i in 0..n/2-1\n b.keys.each do |k|\n if b[k] != 0\n ans[i][n/2] = ans[n-i-1][n/2] = ans[n/2][i] = ans[n/2][n-i-1] = k\n b[k] -= 4\n break\n end\n end\n end\nend\nfor i in 0..n/2-1\n for j in 0..n/2-1\n b.keys.each do |k|\n if b[k] != 0\n ans[i][j] = ans[i][n-1-j] = ans[n-1-i][j] = ans[n-1-i][n-1-j] = k\n b[k] -= 4\n break\n end\n end\n end\nend\nputs \"YES\"\nans.each do |arr|\n puts arr.join(\" \")\nend"}], "src_uid": "20928dd8e512bee2d86c6611c5e76390"} {"source_code": "puts gets.to_i.times.map{gets.split.map(&:to_i)}.any?{|*,a,b| a>=2400 && b>a} ? \"YES\" : \"NO\"", "positive_code": [{"source_code": "n = gets.to_i\n\nn.times do\n\ts, b, a = gets.split\n\tbi = b.to_i\n\tif 2400 <= bi && bi < a.to_i then\n\t\tputs \"YES\"\n\t\texit 0\n\tend\nend\n\nputs \"NO\"\n"}, {"source_code": "#!/usr/bin/ruby\nputs gets.to_i.times.any?{\n\te=gets.split.map(&:to_i)\n\t2400<=e[1] && e[1]= 2400) ? \"red\" : \"other\"\nend\n\nn = gets.chomp.to_i\narr = [].tap do |out|\n n.times do\n out << gets.chomp.split\n end\nend\n\nputs arr.any? { |n, a, b| color(a.to_i) == \"red\" && b.to_i > a.to_i } ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\nans = 'NO'\nn.times do\n name, b, a = gets.split\n if b.to_i >= 2400 && b.to_i < a.to_i\n ans = 'YES'\n end\nend\nputs ans"}, {"source_code": "n = gets.strip.to_i\nans = \"NO\"\nn.times do\n line = gets.strip.split(/ /)\n before = line[1].to_i\n after = line[2].to_i\n ans = \"YES\" if before >= 2400 && after > before\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\nq = []\n\n(1..n).each do |i|\n a, b, c = gets.split\n b, c = b.to_i, c.to_i\n q << [a,b,c]\nend\n\nq.delete_if { |e| e[1] < 2400 || e[1] >= e[2] }\n\nputs q.empty? ? 'NO' : 'YES'"}, {"source_code": "n = gets.to_i\nn.times do |i|\n a, b, c = gets.split\n if b.to_i >= 2400 && c.to_i - b.to_i > 0\n puts \"YES\"\n exit\n end\nend\nputs \"NO\""}, {"source_code": "n = gets.chomp.to_i\nf = false\nn.times do\n name, before, after = gets.chomp.split\n if 2400 <= before.to_i and before.to_i < after.to_i\n f = true\n end\nend\n\nputs f ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.chomp.to_i\na = []\ncount = 0\nfor i in (0..n-1)\n\ta << gets.chomp.split\n\tif a[i][1].to_i >= 2400 && a[i][2].to_i > a[i][1].to_i\n\t\tcount += 1\n\tend\nend\nif count > 0\n\tprint \"YES\"\nelse\n\tprint \"NO\"\nend"}, {"source_code": "puts gets.to_i.times.map{gets.split.map(&:to_i)}.any?{|*,a,b| a>=2400 && b>a} ? \"YES\" : \"NO\""}, {"source_code": "n = gets.to_i\nans = false\nn.times do\n _, s1, s2 = gets.split.map(&:to_i)\n ans = true if s1 >= 2400 && s2 > s1\nend \nputs ans ? 'YES' : 'NO'\n"}, {"source_code": "n = gets.to_i\n\nout = 'NO'\nfor i in 1..n\n user = gets.split\n pre = user[1].to_i\n if pre >= 2400\n if user[2].to_i > pre\n out = 'YES'\n end\n end\nend\n\nputs out\n"}, {"source_code": "n=gets.to_i\nans=false;\nn.times{\n\tbuf=gets.split(' ');\n\tname,before,after = buf[0], buf[1].to_i, buf[2].to_i\n\tans=true if before>=2400&&after>before\n}\nputs ans==true ? \"YES\" : \"NO\""}, {"source_code": "n = gets.to_i\nn.times do\n _, before, after = gets.split.map &:to_i\n if 2400 <= before and before < after\n puts 'YES'\n exit\n end\nend\nputs 'NO'\n"}, {"source_code": "POINT_VALUE = 2400\n\ntime = gets.chomp.to_i\n\nresult = false\ntime.times do |n| \n\tline = gets.chomp\n\t_, before, after = line.split(' ').map &:to_i\n\n\tresult = true if before >= POINT_VALUE and after > before\nend\n\nputs result ? 'YES' : 'NO'"}, {"source_code": "good = false\n\nn = gets.chomp.to_i\nn.times do\n name, prev_score, after_score = gets.chomp.split\n if(prev_score.to_i >= 2400 && after_score.to_i > prev_score.to_i)\n good = true\n break\n end\nend\n\nif good\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "peopleNum = gets.chomp.to_i\npeoples = []\n\npeopleNum.times do\n people = gets.chomp.split(' ')\n people[1] = people[1].to_i\n people[2] = people[2].to_i\n \n peoples << people\nend\n\nred = []\n\npeoples.each do |people|\n red << people if people[1] >= 2400 && people[2] > people[1]\nend\n\nans = if red.length > 0\n \"YES\"\nelse\n \"NO\"\nend\n\nputs ans"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\na = []\nfor i in (0..n-1)\n\ta << gets.chomp.split\n\tcount = 0\n\tif a[i][1].to_i >= 2400 && a[i][2].to_i > a[i][1].to_i\n\t\tcount += 1\n\tend\nend\nif count > 0\n\tprint \"YES\"\nelse\n\tprint \"NO\"\nend"}, {"source_code": "n = gets.chomp.to_i\na = []\nfor i in (0..n-1)\n\ta << gets.chomp.split\n\tcount = 0\n\tif a[i][1].to_i >= 2400 && a[i][2].to_i != a[i][1].to_i && a[i][2].to_i >= 2400\n\t\tcount += 1\n\tend\nend\nif count > 0\n\tprint \"YES\"\nelse\n\tprint \"NO\"\nend"}, {"source_code": "p gets.to_i.times.map{gets.split.map(&:to_i)}.any?{|*,a,b| a>=2400 && b>a} ? \"YES\" : \"NO\""}, {"source_code": "POINT_VALUE = 2400\n\ntime = gets.chomp.to_i\n\nresult = false\ntime.times do |n| \n\tline = gets.chomp\n\t_, before, after = line.split(' ').map &:to_i\n\n\tresult = true if before > POINT_VALUE and after > before\nend\n\nputs result ? 'YES' : 'NO'"}], "src_uid": "3bff9b69423cf6c8425e347a4beef96b"} {"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\nka = []\nn.times do\n\tk, a = STDIN.readline.split.collect {|s| s.to_i }\n\tka.push([k, a])\nend\n#ka.sort!\n\nsizes = []\nka.each do |k, a|\n\tp = (Math.log2(a)/2).ceil\n\tp = 1 if p == 0\n\tsizes.push(k+p)\nend\n\nputs sizes.sort[n-1]\n\n", "positive_code": [{"source_code": "n = gets.to_i\nmax = 0;\nn.times{ \n k,x = gets.split(\" \").map(&:to_i)\n d = (Math.log2(Math.sqrt(x)) + k.to_f).ceil\n if ( d == k ) then \n d = d+1\n end\n if( d > max) then \n max = d\n end\n}\nif max>0 then\nputs max\nelse\nputs \"0\"\nend"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\nsizes = []\nn.times do\n\tk, a = STDIN.readline.split.collect {|s| s.to_i }\n\tp = (Math.log2(a)/2).ceil\n\tp = 1 if p == 0\n\tsizes.push(k+p)\nend\n\nputs sizes.sort[n-1]\n\n"}, {"source_code": "def run\n n = ARGF.readline.to_i\n\n ret = 0\n ARGF.readlines.each do |line|\n k, a = line.split.map(&:to_i)\n\n cur = k + [(Math.log(a, 4)).ceil, 1].max\n ret = [cur, ret].max\n end\n\n puts ret\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\np = 0\nn.times do\n\tk, a = gets.split.map(&:to_i)\n\tif a == 1\n\t\tp = [p, k + 1].max\n\telse\n\t\tp = [p, k + Math.log(a, 4).ceil].max\n\tend\nend\nputs p\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\nka = []\nn.times do\n\tk, a = STDIN.readline.split.collect {|s| s.to_i }\n\tka.push([k, a])\nend\nka.sort!\n\nsizes = []\nka.each do |k, a|\n\tp = (Math.log2(a)/2).ceil\n\tsizes.push(k+p)\nend\n\nputs sizes.sort[n-1]\n\n"}, {"source_code": "n = gets.to_i\nmax = 0;\nn.times{ \n k,x = gets.split(\" \").map(&:to_i)\n d = (Math.log2(x) + k.to_f).ceil\n if ( d == k ) then \n d = d+1\n end\n if( d > max) then \n max = d\n end\n}\nif max>0 then\nputs max\nelse\nputs \"0\"\nend"}, {"source_code": "n = gets.to_i\nmax = 0;\nn.times{ \n\tk,x = gets.split(\" \").map(&:to_i)\n\tt = ((2**(k))**2) * x\n\tif( t > max) then \n\t\tmax = t \n\tend\n}\nif max>0 then\nputs Math.log2(Math.sqrt(max)).ceil\nelse\nputs \"0\"\nend\n"}, {"source_code": "n = gets.to_i\nmax = 0;\nn.times{ \n\tk,x = gets.split(\" \").map(&:to_i)\n\tt = ((2**(k))**2) * x\n\tif( t > max) then \n\t\tmax = t \n\tend\n}\nputs Math.log2(Math.sqrt(max)).ceil\n\n"}, {"source_code": "n = gets.to_i\nmax = 0;\nn.times{ \n k,x = gets.split(\" \").map(&:to_i)\n d = k + Math.log2(x).ceil\n if ( d == k ) then \n d = d+1\n end\n if( d > max) then \n max = d\n end\n}\nif max>0 then\nputs max\nelse\nputs \"0\"\nend"}, {"source_code": "def run\n n = ARGF.readline.to_i\n\n ret = 0\n ARGF.readlines.each do |line|\n k, a = line.split.map(&:to_i)\n\n cur = k + [(Math.log(a, 4)).ceil, 1].min\n ret = [cur, ret].max\n end\n\n puts ret\nend\n\nrun if $0 == __FILE__\n"}], "src_uid": "15aac7420160f156d5b73059af1fae3b"} {"source_code": "n,d=gets.split.map(&:to_i)\np gets.split.map(&:to_i).combination(2).count{|a,b|(a-b).abs<=d}*2\n", "positive_code": [{"source_code": "n, d = gets.split.map{|i| i.to_i}\n\nsolds = gets.split.map{|i| i.to_i}\n\nres = 0\nn.times do |i|\n n.times do |j|\n if (solds[i] - solds[j]).abs <= d then\n res += 1\n end\n end\nend\n\nputs res-n"}, {"source_code": "s = gets.chomp\nns,ds = s.split(/ /)\nn = ns.to_i\nd = ds.to_i\ns = gets.chomp\nss = s.split(/ /)\n\na = Array.new\nfor i in 0..n-1\n\ta[i] = ss[i].to_i\nend\n\nsum = 0\nfor i in 0..n-2\n\tfor j in i+1..n-1\n\t\tif (a[i]-a[j]).abs <= d\n\t\t\tsum += 2 \n\t\tend\n\tend\t\nend\nputs sum"}, {"source_code": "n,d=gets.split.map &:to_i\na=gets.split.map &:to_i\nans=0\nn.times do |i|\n n.times do |j|\n if i!=j && (a[i]-a[j]).abs<=d\n ans+=1\n end\n end\nend\np ans"}, {"source_code": "#!/usr/bin/ruby\nd,a=$<.map{|l|l.split.map(&:to_i)}\nr=0\na.size.times{|i|(i+1).step(a.size-1){|j|r+=2 if (a[i]-a[j]).abs<=d[1]}}\np r"}, {"source_code": "d=gets.split[1].to_i\nans=0\ni=gets.split.map(&:to_i)\ni.each{|a|\n i.each{|b|\n ans=ans+(((a-b).abs<=d)?1:0)\n }\n}\nputs ans-i.length"}, {"source_code": "n,d=gets.split.map(&:to_i)\np gets.split.map(&:to_i).combination(2).count{|a,b|(a-b).abs<=d}*2\n"}, {"source_code": "n,d=gets.split.map(&:to_i)\np gets.split.map(&:to_i).combination(2).count{|a,b|(a-b).abs<=d}*2\n"}, {"source_code": "n,d=gets.split.map(&:to_i)\np gets.split.map(&:to_i).combination(2).count{|a,b|(a-b).abs<=d}*2"}, {"source_code": "n,d=gets.split.map(&:to_i)\np gets.split.map(&:to_i).combination(2).count{|a,b|(a-b).abs<=d}*2\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i).sort\n\nans = 0\n(0..n-2).each do |i|\n ((i+1)..n-1).each do |j|\n if (as[i] - as[j]).abs <= d\n ans += 1\n end\n end\nend\n\nputs ans * 2\n"}, {"source_code": "n,d=gets.split.map(&:to_i)\np gets.split.map(&:to_i).combination(2).count{|a,b|(a-b).abs<=d}*2\n"}, {"source_code": "n,d=gets.split.map(&:to_i)\np gets.split.map(&:to_i).combination(2).count{|a,b|(a-b).abs<=d}*2"}, {"source_code": "ma = gets.split(\" \").map{|i| i.to_i}\nmas = gets.split(\" \").map{|i| i.to_i}\nmas = mas.sort\nans = 0\nmas.each{|a|\n mas.each{|b|\n \tif (a - b).abs <= ma[1]\n \t\tans = ans + 1\n \tend\n }\n}\nputs ans - ma[0]"}, {"source_code": "def main()\n\tn,d=gets.chomp.split(\" \").map{|i| i.to_i}\n\thar=gets.chomp.split(\" \").map{|i| i.to_i}\n\tans=0\n\tfor i in 0...n\n\t\tfor j in 0...n\n\t\t\tif i==j\n\t\t\t\tnext;\n\t\t\tend\n\t\t\tif (har[i]-har[j]).abs<=d\n\t\t\t\tans+=1\n\t\t\tend\n\t\tend\n\tend\n\tputs ans\nend\nmain()"}, {"source_code": "n,d=gets.split.map(&:to_i)\np gets.split.map(&:to_i).combination(2).count{|a,b|(a-b).abs<=d}*2\n"}, {"source_code": "s = gets.chomp!.split(\" \")\nn = s[0].to_i\nd = s[1].to_i\n\ns = gets.chomp!.split(\" \")\nmas = Array.new\nfor i in 1..n\n mas[i] = s[i-1].to_i\nend\n\ncount = 0\nfor i in 1..n\n for j in 1..n\n if (i != j && (mas[i] - mas[j]).abs <= d)\n count += 1\n end\n end\nend\n\nputs(count)"}, {"source_code": "n=gets(\" \").chomp.to_i\nd=gets.chomp.to_i\ndata=gets.chomp.split(/ /)\nsol=[]\nfor i in 0..(n-1)\n\tsol.push(data[i].to_i)\nend\n#puts sol\nsol=sol.sort{|a,b|\n\ta<=>b\n}\n#puts sol\n\nans=0\nfor i in 0..(n-1)\n\tj=1\n\twhile (i+j) sum_arr[1]\n\tans = \"left\"\nelse\n\tans = \"right\"\nend\nputs ans\n", "positive_code": [{"source_code": "bar = gets\npivot = bar.index(\"^\")\n\nleft_weight = 0\nright_weight = 0\n\n(0...bar.length).each do |index|\n piece = bar[index].chr\n if piece =~ /[[:digit:]]/\n if index < pivot\n left_weight += (pivot - index) * piece.to_i\n else\n right_weight += (index - pivot) * piece.to_i\n end\n end\nend\n\nif left_weight > right_weight\n puts \"left\"\nelsif right_weight > left_weight\n puts \"right\"\nelse\n puts \"balance\"\nend\n\n\n\n"}, {"source_code": "s=gets.chomp\nx=s.index '^'\ni=1\nz=0\nwhile x-i>=0\n c=s[x-i].to_i\n z+=c*i if c>0\n i+=1\nend\ni=1\nwhile x+i0\n i+=1\nend\nif z>0\n puts 'left'\nelsif z==0\n puts 'balance'\nelse\n puts 'right'\nend\n"}, {"source_code": "puts (->(x){ x.first > x.last ? 'left' : (x.first < x.last ? 'right' : 'balance')}.call(->(x) {[x.first.reverse, x.last] }.call((STDIN.readline.chomp).split('^').map{|p| p.scan(/./)}).map{|x| x.each_with_index.inject(0){|s,p| s = s + p.first.to_i * (p.last + 1) }}))"}, {"source_code": "a=gets.chomp.split('')\ns=0\nlen=a.length\nfor i in 0..len-1\n\tif a[i]=='^'\n\t\tbreak\n\tend\nend\nfor j in 0..len-1\n\tif a[j]!='='\n\t\ts+=a[j].to_i*(i-j)\n\tend\nend\nputs s>0? \"left\" : s==0? \"balance\" : \"right\"\n"}, {"source_code": "s = gets.chomp\nmid = s.index \"^\"\nleft = 0\nright = 0\n(0...mid).each do |i|\n left += (mid - i) * s[i].to_i if s[i] != '='\nend\n((mid + 1)...s.length).each do |i|\n right += (i - mid) * s[i].to_i if s[i] != '='\nend\nans = right <=> left\ncase ans\nwhen 0\n puts \"balance\"\nwhen 1\n puts \"right\"\nelse\n puts \"left\"\nend\n"}, {"source_code": "class Weights\n attr_accessor :string, :balance\n\n def initialize(value)\n raise \"Node value shouldn't be nil or empty\" if value.nil?\n @string = value\n\n end\n\n def balance\n left, right = @string.split(\"^\")\n left = left.reverse\n\n left_weight = weigh(left)\n right_weight = weigh(right)\n\n\n if left_weight > right_weight\n return \"left\"\n elsif left_weight < right_weight\n return \"right\"\n else\n return \"balance\"\n end\n\n end\n\n private\n\n def weigh(input)\n w = 0\n input.split(\"\").each_with_index do |element, index|\n w += element.to_i * (index + 1) unless element == \"=\"\n end\n w\n end\n\nend\n\n\nstr = gets\nputs Weights.new(str).balance"}, {"source_code": "s = gets.chomp\nfulcrum = s.index('^')\nleft = 0\nright = 0\ni = 1\nwhile fulcrum-i >= 0\n if s[fulcrum-i].to_i.to_s == s[fulcrum-i]\n left += i*s[fulcrum-i].to_i\n end\n i += 1\nend\ni = 1\nwhile fulcrum+i < s.size\n if s[fulcrum+i].to_i.to_s == s[fulcrum+i]\n right += i*s[fulcrum+i].to_i\n end\n i += 1\nend\ncase left <=> right\nwhen 1\n puts 'left'\nwhen -1\n puts 'right'\nwhen 0\n puts 'balance'\nend\n"}, {"source_code": "s = gets.chomp\nfulcrum = s.index('^')\nleft = 0\nright = 0\ni = 1\nwhile fulcrum-i >= 0\n left += i*s[fulcrum-i].to_i if s[fulcrum-i].to_i.to_s == s[fulcrum-i]\n i += 1\nend\ni = 1\nwhile fulcrum+i < s.size\n right += i*s[fulcrum+i].to_i if s[fulcrum+i].to_i.to_s == s[fulcrum+i]\n i += 1\nend\ncase left <=> right\nwhen 1\n puts 'left'\nwhen -1\n puts 'right'\nwhen 0\n puts 'balance'\nend\n"}], "negative_code": [{"source_code": "s = gets.chomp\nmid = s.index \"^\"\nleft = []\nright = []\n(0...mid).each do |i|\n if s[i] != '='\n left << s[i].to_i\n else\n left << 0\n end\nend\n((mid + 1)...s.length).each do |i|\n if s[i] != '='\n right << s[i].to_i\n else\n right << 0\n end\nend\nleft.delete 0\nright.delete 0\nans = 0\nif left.length == right.length\n left.length.times do |i|\n l = left[left.length - 1 - i]\n r = right[i]\n ans += r <=> l\n end\nelse\n ans = left.inject(:+) <=> right.inject(:+)\nend\ncase ans\nwhen 0\n puts \"balance\"\nwhen 1\n puts \"right\"\nelse\n puts \"left\"\nend\n"}, {"source_code": "s = gets.chomp\nmid = s.index \"^\"\nleft = 0\nright = 0\n(0...mid).each do |i|\n left += (mid - 1) * s[i].to_i if s[i] != '='\nend\n((mid + 1)...s.length).each do |i|\n right += (i - mid) * s[i].to_i if s[i] != '='\nend\nans = right <=> left\ncase ans\nwhen 0\n puts \"balance\"\nwhen 1\n puts \"right\"\nelse\n puts \"left\"\nend\n"}, {"source_code": "->(x){ x.first > x.last ? 'left' : (x.first < x.last ? 'right' : 'balance')}.call(->(x) {[x.first.reverse, x.last] }.call((STDIN.readline.chomp).split('^').map{|p| p.scan(/./)}).map{|x| x.each_with_index.map{|p,i| [p, i+1]}}.map{|x| x.map{|t|[t.first.to_i, t.last]}}.map{|x| x.inject(0){|s, t| s = s + t.first * t.last }})"}, {"source_code": "puts (->(x){ x.first > x.last ? 'left' : (x.first < x.last ? 'right' : 'balance')}.call(->(x) {[x.first.reverse, x.last] }.call((STDIN.readline.chomp).split('^').map{|p| p.scan(/./)}).map{|x| x.each_with_index.inject(0){|s,p| s = s + p.first.to_i * p.last}}))"}, {"source_code": "->(x){ x.first > x.last ? 'left' : (x.first < x.last ? 'right' : 'balance')}.call(->(x) {[x.first.reverse, x.last] }.call((STDIN.readline.chomp).split('^').map{|p| p.scan(/./)}).map{|x| x.each_with_index.map{|p,i| [p, i+1]}}.map{|x| x.map{|t|[t.first.to_i, t.last]}}.map{|x| x.inject(0){|s, t| s = s + t.first * t.last }})\n"}], "src_uid": "19f2c21b18e84f50e251b1dfd557d32f"} {"source_code": "N,K = gets.split.map(&:to_i)\nbs = []\nn = N\nwhile n > 0\n bs << (n&1)\n n >>= 1\nend\n\nt = bs.count(1)\nif K < t || N < K\n puts \"NO\"; exit\nend\n\n(1...bs.size).reverse_each{ |b|\n if K - t <= bs[b]\n bs[b] -= K-t\n bs[b-1] += 2*(K-t)\n break\n end\n bs[b-1] += 2*bs[b]\n t += bs[b]\n bs[b] = 0\n}\n\nputs \"YES\"\nb = 1\nputs bs.map.with_index{ |b,i| [1 << i] * b }.flatten.join(\" \")", "positive_code": [{"source_code": "nk = gets.chomp.split(\" \").map(&:to_i)\nn = nk[0]\nk = nk[1]\n\nn = n.to_s(2)\n\nmink = n.count(\"1\")\nmaxk = 0\nlen = n.length\n\nn.each_char.with_index do |ch,i|\n pos = len-i-1\n maxk += 2**pos if ch == \"1\"\nend\n\nif k < mink or k > maxk\n puts \"NO\"\n exit\nend\n\ndef myprint(narr,k)\n sum = narr.inject(:+)\n while sum < k\n narr[0] -= 1\n narr[1] += 2\n sum += 1\n if narr[0] == 0\n narr.shift\n end\n end\n\n len = narr.length\n narr.each_with_index do |x,i|\n x.times do\n print 2**(len-i-1)\n print \" \"\n end\n end\nend\n\nputs \"YES\"\nmyprint(n.each_char.to_a.map(&:to_i),k)\nputs\n"}, {"source_code": "# Utility\ndef digits(num, base)\n num.to_s(base).split(\"\").reverse!.map { |c| c.to_i }\nend\n\n# Input\nn, k = *(gets.split.map { |s| s.to_i })\n\n# Processing\nb = digits(n, 2)\n#p b\ndecomposition = b.map.with_index { |e, i| e * 2**i }\ndecomposition = decomposition.reject { |e| e == 0 }\ndecomposition.reverse!\n# decomposition is sorted so largest element is first\n#p decomposition\n\nif decomposition.length > k || k > n\n puts \"NO\"\nelse\n # Will be splitting numbers until we get enough\n while decomposition.length != k\n num = decomposition.shift\n if num == 1\n decomposition.push(num)\n else\n decomposition.push(num / 2, num / 2)\n end\n end\n\n puts \"YES\"\n puts decomposition.join(\" \")\nend\n"}], "negative_code": [{"source_code": "# Utility\ndef digits(num, base)\n num.to_s(base).split(\"\").map { |c| c.to_i }\nend\n\n# Input\nn, k = *(gets.split.map { |s| s.to_i })\n\n# Processing\nb = digits(n, 2)\ndecomposition = b.map.with_index { |e, i| e * 2**i }\ndecomposition = decomposition.reject { |e| e == 0 }\ndecomposition.reverse!\n# decomposition is sorted so largest element is first\n\nif decomposition.length > k || k > n\n puts \"NO\"\nelse\n # Will be splitting numbers until we get enough\n while decomposition.length != k\n num = decomposition.shift\n if num == 1\n decomposition.push(num)\n else\n decomposition.push(num / 2, num / 2)\n end\n end\n\n puts \"YES\"\n puts decomposition.join(\" \")\nend\n"}], "src_uid": "10d6179b479e1238a51154a9a6fc13cb"} {"source_code": "gets.to_i.times{p (gets.to_i+1)/2}", "positive_code": [{"source_code": "gets.to_i.times{p (gets.to_i+1)/2}"}, {"source_code": "gets.to_i.times{p (gets.to_i+1)/2}"}, {"source_code": "gets.to_i.times{p (gets.to_i+1)/2}"}, {"source_code": "gets.to_i.times{p (gets.to_i+1)/2}"}], "negative_code": [], "src_uid": "0c5cf0af057b0c838f13b491b923447a"} {"source_code": "1.upto(gets.chomp.to_i) do\n a, b = gets.chomp.split.map(&:to_i)\n if (a == 1 || b == 1 || (a <= 2 && b <= 2))\n puts 'YES'\n else\n puts 'NO'\n end\nend\n", "positive_code": [{"source_code": "1.upto(gets.to_i) do\n n, m = gets.split(' ').map(&:to_i)\n\n puts (n == 1 || m == 1 || (n == 2 && m == 2)) ? 'YES' : 'NO'\nend\n"}, {"source_code": "file = File.exist?('in.in') ? File.new('in.in','r') : STDIN\nt = file.gets.chomp.to_i\nt.times do\n n, m = file.gets.chomp.split.map(&:to_i)\n if (n == 1 || m == 1) || (n==2 && m == 2)\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "t = gets.to_i\n0.upto t-1 do\n t1, t2 = gets.split.map(&:to_i)\n if t1 == 1 or t2 == 1\n puts \"YES\"\n elsif t1 == 2 and t2 == 2\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "t = gets.to_i\nt.times do \n a ,b =gets.split.map(&:to_i)\n if a==1 or b==1 or a+b==4\n puts \"YES\"\n else \n puts\"NO\"\n end\nend"}], "negative_code": [], "src_uid": "55595ff38a08b80bc86cf1ebae6f55af"} {"source_code": "gets\narr = gets.split.map(&:to_i).sort\nfor i in arr\n if not i == arr[0]\n puts i\n exit 0\n end\nend\nputs 'NO'\n\n", "positive_code": [{"source_code": "n = gets.to_i\n\na = gets.split.collect{|x| x.to_i}\n\nmin = a.min\na.delete(min)\n\nanswer = a.min\n\nif answer == nil\n\tputs 'NO'\nelse\n\tputs answer\nend"}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\"\n"}, {"source_code": "STDIN.readlines.drop(1).join.split.map(&:to_i).uniq.sort.tap { |x| puts(x.length < 2 ? \"NO\" : x[1])}"}, {"source_code": "gets\nvalues = gets.split.map { |v| v.to_i }.sort.uniq\nresult = values.size >= 2 ? values[1] : \"NO\"\nputs result\n"}, {"source_code": "n = gets.to_i\n\ns = gets.split.map{|i| i.to_i}.sort\n\nif s[0] == s[-1] then\n result = \"NO\"\nelse\n i = 1\n while s[i] == s[0] && i < n do \n i += 1\n end\n result = s[i]\nend\n\nputs result"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /)\nan = Hash.new(n)\na.each{|aa| an[aa.to_i] = 0 }\nann = an.keys.sort\nif ann.count <= 1\n\tputs \"NO\"\nelse\n\tputs ann[1]\nend\n"}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\""}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\""}, {"source_code": "gets\na=gets.split.map(&:to_i).uniq.sort[1]\nputs a ?a:\"NO\""}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort.uniq[1] || 'NO'\n"}, {"source_code": "gets\nx = gets.split.map(&:to_i).uniq.sort\nputs (x[1] || 'NO')"}, {"source_code": "n=gets.to_i\ni=gets.split.map(&:to_i)\ni.sort!\nm=i[0]\nans=\"NO\"\ni.each{|j|\n if j>m then\n ans=j.to_s\n break\n end\n}\n\nputs ans"}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\"\n"}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\"\n"}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\""}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\""}, {"source_code": "n=gets.chomp.to_i\nmemo=gets.chomp.split.map{|i| i.to_i}.sort!\nmin=memo[0]\nn.times do |i|\n if min!=memo[i]\n puts(memo[i])\n exit\n end\nend\nputs(\"NO\")\n"}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\"\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).sort.uniq[1]||\"NO\"\n"}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\"\n"}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\""}, {"source_code": "gets\nputs (s=gets.split.map(&:to_i).uniq.sort[1])?s:\"NO\"\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ')[0...n].map { |s| s.to_i }\nputs a.sort.uniq[1] || 'NO'"}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\"\n"}, {"source_code": "num = gets.chomp\ndata = gets.chomp\n\narray = data.split(/\\s* \\s*/).uniq.sort{|a, b| a.to_i <=> b.to_i}\n\nif array.length > 1\n puts array[1]\nelse\n puts \"NO\"\nend\n"}, {"source_code": "amount = gets.to_i\nelements = gets.split(' ').map { |e| e.to_i }\nelements = elements.to_a.sort\nanswer = min = elements[0]\n(0...amount).each do |i|\n if elements[i] > min\n answer = elements[i]\n break\n end\nend\nif answer == min\n print \"NO\"\nelse\n print answer\nend"}, {"source_code": "gets\nk=gets.split.map(&:to_i).sort.uniq \nputs k.size<=1 ?\"NO\":k[1]"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\nans = nil\namin = a.min\na.each{|aa| ans = aa if aa > amin and (ans == nil or aa < ans)}\nif ans == nil\n puts \"NO\"\nelse\n puts ans\nend\n"}, {"source_code": "gets\nnums = gets.chomp.split.map(&:to_i)\n\nmin = nums.min\nres = nums.sort.detect{ |x| x > min }\nputs res.nil? ? \"NO\" : res"}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\"\n"}, {"source_code": "gets.chomp # Skip the first line\nputs((seq = gets.chomp.split.map { |x| x.to_i }.uniq).size > 1 ? seq.sort[1] : 'NO')"}, {"source_code": "gets;puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\"\n"}], "negative_code": [{"source_code": "n=gets.chomp.to_i\nmemo=gets.chomp.split.map{|i| i.to_i}.sort!\nmin=memo[0]\nn.times do |i|\n if min!=memo[i]\n puts(memo[i])\n exit\n end\nend\nputs(-1)\n"}, {"source_code": "amount = gets.to_i\nelements = gets.split(' ').sort.map { |e| e.to_i }\nmin = elements[0]\n(0...amount).each do |i|\n if elements[i] > min\n min = elements[i]\n break\n end\nend\nprint min"}, {"source_code": "amount = gets.to_i\nelements = gets.split(' ').sort.map { |e| e.to_i }\nanswer = min = elements[0]\n(0...amount).each do |i|\n if elements[i] > min\n answer = elements[i]\n break\n end\nend\nif answer == min\n print \"NO\"\nelse\n print answer\nend"}, {"source_code": "gets\nk=gets.split.map(&:to_i).sort.uniq \nputs k[1]"}, {"source_code": "gets\nnums = gets.chomp.split.map(&:to_i)\n\nmin = nums.min\nres = nums.detect{ |x| x > min }\nputs res.nil? ? \"NO\" : res"}, {"source_code": "puts gets.split.map(&:to_i).uniq.sort[1]||\"NO\""}, {"source_code": "gets\narr = gets.split.map(&:to_i).sort\nfor i in arr\n if not i == arr[0]\n puts i\n break\n end\nend\n\n"}, {"source_code": "gets\narr = gets.split.map(&:to_i).sort\nfor i in arr\n if not i == arr[0]\n puts i\n exit 0\n end\nend\nputs arr[0]\n\n"}, {"source_code": "gets\narr = gets.split.map(&:to_i).sort\nfor i in arr\n if not i == arr[0]\n puts i\n break\n end\nend\nputs arr[0]\n\n"}], "src_uid": "930be5ec102fbe062062aa23eac75187"} {"source_code": "n,m,d=gets.chomp.split.map(&:to_i)\na,flag=[],1\nn.times { |j| gets.chomp.split.map(&:to_i).each {|i| a< 1\n\tputs \"-1\"\nelse\n\tputs sum / d\nend\n\n\n# (0..(n-1)).each do |i|\n# \t(0..(m-1)).each do |j|\n# \t\tval = gcd(val,arr[i][j])\n# \tend\n# end\n"}, {"source_code": "n, m, d = gets.split.map(&:to_i)\nxs = n.times.map { gets.split.map(&:to_i) }.flatten.sort\nmod = xs[0] % d\nif xs.all? { |x| x % d == mod }\n median = xs[xs.size / 2]\n if median % d != mod\n median += median % d + mod\n end\n p xs.map { |x| (x - median).abs / d }.reduce(:+)\nelse\n p -1\nend"}, {"source_code": "n, m, d = gets.split(\" \").collect{|x| x.to_i}\n\narr = []\nn.times do\n gets.split(\" \").collect{|x| arr << x.to_i}\nend\n\nrem = arr[0] % d\ninv = 0\narr.each{|num|\n if num % d != rem\n inv = 1\n break\n end\n}\n\nif inv == 1\n puts -1\nelse\n arr.sort!\n target = arr[n * m / 2]\n\n mods = 0\n arr.each{|num|\n mods += (num - target).abs / d\n }\n\n puts mods\nend\n"}, {"source_code": "n,m,d = gets.strip.split.map(&:to_i)\n\nmatrix = []\nn.times do\n matrix += gets.strip.split.map(&:to_i)[0...m]\nend\n\ndef possible?(matrix, d)\n mod_d = matrix[0] % d\n matrix.each do |x|\n return false unless (x % d) == mod_d\n end\n true\nend\n\ndef trace(vars={})\n vars.each do |x,y|\n puts \"#{x} => #{y}\"\n end\nend\n\ndef get_count(matrix, c, d)\n matrix.map{|x| (c-x).abs/d}.inject :+\nend\n\nif possible?(matrix, d)\n matrix.sort!\n c = matrix[matrix.length/2]\n puts get_count(matrix, c, d)\nelse\n puts -1\nend\n\n\n"}], "negative_code": [{"source_code": "require \"Set\"\n\nn,m,d = gets.split(\" \").map(&:to_i)\narr = []\n\nn.times do \n\tarr << gets.split(\" \").map(&:to_i)\nend\narr.flatten!\narr.sort!\nmid = arr[(arr.length-1)/2 + 1]\n# puts \"#{mid}\"\nrem = Set.new\nsum = 0\narr.each do |a|\n\trem.add(a%d)\n\tsum += (a - mid).abs\nend\nif rem.length > 1\n\tputs \"-1\"\nelse\n\tputs sum / d\nend\n\n\n# (0..(n-1)).each do |i|\n# \t(0..(m-1)).each do |j|\n# \t\tval = gcd(val,arr[i][j])\n# \tend\n# end\n"}, {"source_code": "n, m, d = gets.split.map(&:to_i)\nmatrix = n.times.map { gets.split.map(&:to_i) }\nmod = matrix[0][0] % d\nif matrix.all? { |row| row.all? { |el| el % d == mod } }\n sum = matrix.map { |row| row.reduce(:+) }.reduce(:+)\n target = sum / (n * m)\n target += target % d + mod if target % d != mod\n p matrix.map { |row| row.map { |el| (el - target).abs / d }.reduce(:+) }.reduce(:+)\nelse\n p -1\nend"}, {"source_code": "n, m, d = gets.split.map(&:to_i)\nmatrix = n.times.map { gets.split.map(&:to_i) }\nif matrix.all? { |row| row.all? { |el| el % d == 0 } }\n sum = matrix.map { |row| row.reduce(:+) }.reduce(:+)\n target = sum / (n * m)\n target += target % d if target % d != 0\n p matrix.map { |row| row.map { |el| (el - target).abs / d }.reduce(:+) }.reduce(:+)\nelse\n p -1\nend"}, {"source_code": "n, m, d = gets.split.map(&:to_i)\nmatrix = n.times.map { gets.split.map(&:to_i) }\nif matrix.all? { |row| row.all? { |el| el % d == 0 } }\n sum = matrix.map { |row| row.reduce(:+) }.reduce(:+)\n avg = sum / (n * m)\n p matrix.map { |row| row.map { |el| (el - avg).abs / d }.reduce(:+) }.reduce(:+)\nelse\n p -1\nend"}, {"source_code": "n, m, d = gets.split(\" \").collect{|x| x.to_i}\n\narr = []\nn.times do\n gets.split(\" \").collect{|x| arr << x.to_i}\nend\n\nrem = arr[0] % d\nsum = 0\ninv = 0\narr.each{|num|\n if num % d != rem\n inv = 1\n break\n end\n \n sum += num\n}\n\nif inv == 1\n puts -1\nelse\n avg = sum.to_f / (n * m)\n ce = arr[0]\n diff = (arr[0] - avg).abs\n\n arr.each{|num|\n if (num - avg).abs < diff\n ce = num\n diff = (num - avg).abs\n end\n }\n\n mods = 0\n arr.each{|num|\n mods += (num - ce).abs / d\n }\n\n puts mods\nend\n"}, {"source_code": "n,m,d = gets.strip.split.map(&:to_i)\n\nmatrix = []\nn.times do\n matrix += gets.strip.split.map(&:to_i)[0...m]\nend\n\ndef possible?(matrix, d)\n mod_d = matrix[0] % d\n matrix.each do |x|\n return false unless (x % d) == mod_d\n end\n true\nend\n\ndef trace(vars={})\n vars.each do |x,y|\n puts \"#{x} => #{y}\"\n end\nend\n\nif possible?(matrix, d)\n mod_d = matrix[0] % d\n sum = matrix.inject(:+)\n avg = (( (sum.to_f / (n*m)).round - mod_d ) / d).round.to_i * d + mod_d\n\n #avg1 = ((avg - mod_d) / d).floor.to_i * d + mod_d\n #avg2 = ((avg - mod_d) / d).ceil.to_i * d + mod_d\n #trace avg1: avg1, avg2: avg2\n #\n #n1 = matrix.map{|x| (avg1 - x).abs / d}.inject(:+)\n #n2 = matrix.map{|x| (avg2 - x).abs / d}.inject(:+)\n #puts [n1,n2].min\n\n puts matrix.map{|x| (avg - x).abs / d}.inject(:+)\n\n\nelse\n puts -1\nend\n\n\n"}, {"source_code": "n,m,d = gets.strip.split.map(&:to_i)\n\nmatrix = []\nn.times do\n matrix += gets.strip.split.map(&:to_i)[0...m]\nend\n\ndef possible?(matrix, d)\n mod_d = matrix[0] % d\n matrix.each do |x|\n return false unless x % d == mod_d\n end\n true\nend\n\nif possible?(matrix, d)\n mod_d = matrix[0] % d\n sum = matrix.inject(:+)\n avg = sum / (n*m)\n avg1 = ((avg - mod_d) / d) * d + mod_d\n avg2 = ((avg - mod_d) / d + 1) * d + mod_d\n n1 = matrix.map{|x| (x - avg1).abs / d}.inject(:+)\n n2 = matrix.map{|x| (x - avg2).abs / d}.inject(:+)\n puts [n1,n2].min\nelse\n puts -1\nend\n\n\n"}, {"source_code": "n,m,d = gets.strip.split.map(&:to_i)\n\nmatrix = []\nn.times do\n matrix += gets.strip.split.map(&:to_i)[0...m]\nend\n\ndef possible?(matrix, d)\n mod_d = matrix[0] % d\n matrix.each do |x|\n return false unless (x % d) == mod_d\n end\n true\nend\n\ndef trace(vars={})\n vars.each do |x,y|\n puts \"#{x} => #{y}\"\n end\nend\n\ndef get_count(matrix, c)\n matrix.map{|x| (c-x).abs}.inject :+\nend\n\nif possible?(matrix, d)\n matrix.sort!\n min = matrix.first\n max = matrix.last\n c = min\n n = nil\n while c <= max\n count = get_count(matrix, c)\n n = count if n.nil? || count < n\n c += d\n end\n puts n\nelse\n puts -1\nend\n\n\n"}, {"source_code": "n,m,d = gets.strip.split.map(&:to_i)\n\nmatrix = []\nn.times do\n matrix += gets.strip.split.map(&:to_i)[0...m]\nend\n\ndef possible?(matrix, d)\n mod_d = matrix[0] % d\n matrix.each do |x|\n return false unless x % d == mod_d\n end\n true\nend\n\nif possible?(matrix, d)\n sum = matrix.inject(:+)\n avg = sum.to_f / (n*m)\n avg1 = (avg / d).to_i * d\n avg2 = ((avg / d).to_i + 1) * d\n n1 = matrix.map{|x| (x - avg1).abs / d}.inject(:+)\n n2 = matrix.map{|x| (x - avg2).abs / d}.inject(:+)\n puts [n1,n2].min\nelse\n puts -1\nend\n\n\n"}, {"source_code": "n,m,d = gets.strip.split.map(&:to_i)\n\nmatrix = []\nn.times do\n matrix += gets.strip.split.map(&:to_i)[0...m]\nend\n\n$stderr.puts n,m,d, matrix.inspect\n\ndef possible?(matrix, d)\n mod_d = matrix[0] % d\n matrix.each do |x|\n return false unless (x % d) == mod_d\n end\n true\nend\n\nif possible?(matrix, d)\n mod_d = matrix[0] % d\n sum = matrix.inject(:+)\n avg = sum.to_f / (n*m)\n\n avg1 = ((avg - mod_d) / d).to_i * d + mod_d\n avg2 = (((avg - mod_d) / d).to_i + 1) * d + mod_d\n n1 = matrix.map{|x| (x - avg1).abs / d}.inject(:+)\n n2 = matrix.map{|x| (x - avg2).abs / d}.inject(:+)\n puts [n1,n2].min\nelse\n puts -1\nend\n\n\n"}], "src_uid": "3488bb49de69c0c17ea0439e71b1e6ae"} {"source_code": "\ndef b(l,r,v=1)\n\tif l==r \n\t\t$t[v]=l \n\t\treturn 0\n\tend\n\treturn 0 if l>r\n\tm=(l+r)/2\n\tb(l,m,v*2)\n\tb(m+1,r,v*2+1)\n\tif $a[$t[v*2]]<$a[$t[v*2+1]]\n\t\t$t[v]=$t[v*2]\n\telse\n\t\t$t[v]=$t[v*2+1]\n\tend\nend\ndef g(l,r,tl=0,tr=$n-1,v=1)\n\treturn $n if tl>r || tr=l && tr<=r\n\tm=(tl+tr)/2\n\ta=g(l,r,tl,m,v*2)\n\tb=g(l,r,m+1,tr,v*2+1)\n\treturn ($a[a]<$a[b]) ? a : b \nend\ndef z(l,r,h)\n\treturn 0 if l>r\n\tm=g(l,r)\n\treturn [r-l+1,z(l,m-1,$a[m])+z(m+1,r,$a[m])+$a[m]-h].min\nend\nn=gets.to_i\n$n=2\nwhile $n y.min}\n\t\t\t@seg_tree[n] = Info.new(left, right, min.min, min.index)\n\t\tend\n\n\t\t@seg_tree[n]\n\tend\n\n\tdef seg_min(l, r, n = 1)\n\t\tmid = (@seg_tree[n].left + @seg_tree[n].right) / 2\n\n\t\tif l <= @seg_tree[n].left and @seg_tree[n].right <= r\n\t\t\t@seg_tree[n]\n\t\telsif mid >= r\n\t\t\tseg_min(l, r, n*2)\n\t\telsif mid < l\n\t\t\tseg_min(l, r, n*2 + 1)\n\t\telse\n\t\t\t[seg_min(l, r, n*2), seg_min(l, r, n*2 + 1)].min{|x, y| x.min <=> y.min}\n\t\tend\n\tend\nend\n\nn = gets.chomp.to_i\na = gets.chomp.split.map{|i| i.to_i}\na.create_seg\n# puts a.seg_tree\n# puts a.seg_min(1, 2)\n\ndef sol(arr, l, r, base)\n\t# print arr\n\treturn 0 if r == l && base == arr[r]\n\treturn r - l + 1 if r - l + 1 <= 1\n\tm = arr.seg_min(l, r).min\n\tmid = arr.seg_min(l, r).index\n\tans = [r - l + 1, sol(arr, l, mid - 1, m) + sol(arr, mid + 1, r, m) + (m - base)].min\n\t# puts \"r - l + 1 = #{r - l + 1}, sol(arr, #{l}, #{mid - 1}, #{m}) = #{sol(arr, l, mid - 1, m)}, sol(arr, #{mid + 1}, #{r}, #{m}) = #{sol(arr, mid + 1, r, m)}\"\n\t# puts \"in (#{l}, #{r}), min = #{m}, base = #{base}, ans = #{ans}\"\n\tans\nend\n\nputs sol(a, 0, a.size - 1, 0)\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map{|i| i.to_i}\n\ndef split0(arr)\n\tslice = []\n\tans = []\n\tarr.each do |i|\n\t\tif i == 0 && (not slice.empty?)\n\t\t\tans << slice\n\t\t\tslice = []\n\t\telsif i != 0\n\t\t\tslice << i\n\t\tend\n\tend\n\tif (not slice.empty?)\n\t\tans << slice\n\tend\n\tans\nend\n\n\ndef sol(arr)\n\treturn arr.size if arr.size <= 1 \n\tnarr = arr.map{|i| i - arr.min}\n\t\n\treturn [arr.size, split0(narr).map{|i| sol i}.inject(0, :+) + 1].min\nend\n\nputs sol(a)\n"}, {"source_code": "class Array\n\tattr_accessor :seg_tree\n\tInfo = Struct.new(:left, :right, :min, :index)\n\n\tdef create_seg(left = 0, right = size - 1, n = 1)\n\t\t@seg_tree = [] if @seg_tree == nil\n\n\t\tif right == left\n\t\t\t@seg_tree[n] = Info.new(left, left, slice(left), left)\n\t\telse\n\t\t\tmid = (left + right) / 2\n\t\t\tmin = [create_seg(left, mid, 2*n), create_seg(mid + 1, right, 2*n+1)].min{|x, y| x.min <=> y.min}\n\t\t\t@seg_tree[n] = Info.new(left, right, min.min, min.index)\n\t\tend\n\n\t\t@seg_tree[n]\n\tend\n\n\tdef seg_min(l, r, n = 1)\n\t\tmid = (@seg_tree[n].left + @seg_tree[n].right) / 2\n\n\t\tif l <= @seg_tree[n].left && r >= @seg_tree[n].right\n\t\t\t@seg_tree[n]\n\t\telsif mid >= r\n\t\t\tseg_min(l, r, n*2)\n\t\telsif mid <= l\n\t\t\tseg_min(l, r, n*2 + 1)\n\t\telse\n\t\t\t[seg_min(l, r, n*2), seg_min(l, r, n*2 + 1)].min{|x, y| x.min <=> y.min}\n\t\tend\n\tend\nend\n\nn = gets.chomp.to_i\na = gets.chomp.split.map{|i| i.to_i}\na.create_seg\n\ndef sol(arr, l, r, base)\n\t# print arr\n\treturn 0 if r == l && base == arr[r]\n\treturn r - l + 1 if r - l + 1 <= 1\n\tm = arr.seg_min(l, r).min\n\tmid = arr.seg_min(l, r).index\n\treturn [r - l + 1, sol(arr, l, mid - 1, m) + sol(arr, mid + 1, r, m) + (m - base)].min\nend\n\nputs sol(a, 0, a.size - 1, 0)\n"}], "src_uid": "ddab0e510f9aceb2fbf75e26d27df166"} {"source_code": "x = gets.to_i\nps = gets\nans = 0\nss={'A'=>0,'I'=>0,'F'=>0}\nx.to_i.times{|i|\n ss[ps[i]]+=1\n}\nx.to_i.times{|i|\n ss[ps[i]]-=1\n ans += 1 if ps[i] != 'F' && ss['I'] == 0\n ss[ps[i]]+=1\n}\nputs ans\n", "positive_code": [{"source_code": "n=gets\ntext= gets\nI=text.scan('I').length\nF=text.scan('F').length\nA=text.scan('A').length\n\nif I>1\n puts \"0\"\nelsif I==1\n puts \"1\"\nelse\n puts A.to_s\nend"}, {"source_code": "n = gets.to_i\ns = gets.strip\n\nac = 0\nic = 0\n\nfor i in 0...n\n if s[i] == 'A' then ac += 1 end\n if s[i] == 'I' then ic += 1 end\nend\n\nif ic > 1 then puts 0\nelsif ic == 1 then puts 1\nelse puts ac end"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\ns = STDIN.readline.strip.downcase\n\ncounts = {'a' => 0, 'i' => 0, 'f' => 0}\n\nn.times do |i|\n\tcounts[s[i]] += 1\nend\n\nif counts['i'] > 1\n\tanswer = 0\nelsif counts['i'] == 1\n\tanswer = 1\nelse\n\tanswer = counts['a']\nend\n\nputs answer\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp\ni=s.count(?I)\np i>1 ? 0 : i>0 ? 1 : n-s.count(?F)"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nplayers = s.count('I')\n\nif players == 1\n puts \"1\"\nelse\n if players == 0\n puts s.count('A')\n else\n puts \"0\"\n end\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nplayers = s.count('I')\n\nif players == 1\n puts \"1\"\nelse\n if players == 0\n puts s.count('A')\n else\n puts \"0\"\n end\nend"}, {"source_code": "gets;a=gets;a.count('I')==1 ?(puts 1):(a.count('I')==0 ?(puts a.count('A')):(puts 0))"}, {"source_code": "n = gets.to_i\ns = gets.chomp\n\nl = s.size\na = 0\ni = 0\nf = 0\n(0...l).each { |p|\n if s[p].downcase == \"a\" \n a+=1\n end\n if s[p].downcase == \"f\"\n f+=1\n end\n if s[p].downcase == \"i\" \n i+=1\n end\n \n}\n\nif i == 0\n puts a\nend\n\nif i == 1\n puts 1\nend\n\nif i > 1\n puts 0\nend"}, {"source_code": "n = gets.to_i\ns = gets\n\na = i = 0\nn.times do |idx|\n if s[idx] == \"A\"\n a += 1\n elsif s[idx] == \"I\"\n i += 1\n end\nend\n\nif i > 1\n puts 0\nelsif i == 0\n puts a\nelse\n puts 1\nend"}, {"source_code": "gets # Skip the first line\ns = gets.chomp\nplayers_in = s.count('I')\nputs(players_in == 1 ? 1 : players_in == 0 ? s.count('A') : 0)"}, {"source_code": "n = gets; a = gets\na.count('I')==1? (puts 1) : (a.count('I')==0? (puts a.count('A') ):(puts 0))"}], "negative_code": [{"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\ns = STDIN.readline.strip.downcase\n\ncounts = {'a' => 0, 'i' => 0, 'f' => 0}\n\nn.times do |i|\n\tcounts[s[i]] += 1\nend\n\nif counts['i'] == 1\n\tanswer = 1\nelse\n\tanswer = counts['a']\nend\n\nputs answer\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp\np s.count(?I)>1 ? 0 : n-s.count(?F)"}], "src_uid": "5e4defe52832cc0d36e7ea5d9f86f895"} {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /).map!{|x| x.to_i}\nb = []\nidx = 1\na.each{|aa|\n b << [aa, idx]\n idx += 1\n}\nb = b.sort{|b2,b1|\n b1[0] <=> b2[0]\n}\nc1 = []\nc2 = []\nc1s = 0\nc2s = 0\nb.each{|bb|\n if c1.length > c2.length\n c2 << bb[1]\n c2s += bb[0]\n elsif c2.length > c1.length\n c1 << bb[1]\n c1s += bb[0]\n else\n if c1s > c2s\n c2 << bb[1]\n c2s += bb[0]\n else\n c1 << bb[1]\n c1s += bb[0]\n end\n end\n}\nputs c1.length\nputs c1.join(\" \")\nputs c2.length\nputs c2.join(\" \")", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).zip(1.upto(n)).sort.reverse\nl, r, x, y = 0, 0, [], []\n\nif n.odd?\n b = a.pop\n l += b[0]\n x << b[1]\nend\n\n(n / 2).times do\n b = a.pop\n c = a.pop\n b, c = c, b if l <= r\n l += b[0]\n x << b[1]\n r += c[0]\n y << c[1]\nend\n\np x.size\nputs x * ' '\np y.size\nputs y * ' '\n"}, {"source_code": "n=gets.chomp.to_i\nplayers=[]\narr=gets.chomp.split\narr.each_index{|i| players.push [i+1,arr[i].to_i]}\nplayers.sort_by!{|a| a[1]}\ndif=0\ni=2\ns_i=0\nl_i=players.size-1\na=[]\nb=[]\nwhile i <= n\n if dif >0\n a.push players[s_i][0]\n dif =dif+players[s_i][1]\n s_i=s_i+1\n else\n a.push players[l_i][0]\n dif =dif+players[l_i][1]\n l_i=l_i-1\n end\n if dif <0\n b.push players[s_i][0]\n dif =dif-players[s_i][1]\n s_i=s_i+1\n else\n dif =dif-players[l_i][1]\n b.push players[l_i][0]\n l_i=l_i-1\n end\ni=i+2\nend\nif n%2!=0\n if dif >0\n b.push players[l_i][0]\n else\n a.push players[l_i][0]\n end\nend\n#p dif\nputs a.size,a.to_s.delete('[').delete(']').gsub(\",\",\"\"),b.size,b.to_s.delete('[').delete(']').gsub(\",\",\"\")\n\n"}], "negative_code": [{"source_code": "n=gets.chomp.to_i\nplayers=[]\narr=gets.chomp.split\narr.each_index{|i| players.push [i+1,arr[i].to_i]}\nplayers.sort_by!{|a| a[1]}\ndif=0\ni=2\ns_i=0\nl_i=players.size-1\na=[]\nb=[]\nwhile i <= n\n if dif >0\n a.push players[s_i][0]\n dif =dif+players[s_i][1]\n s_i=s_i+1\n else\n a.push players[l_i][0]\n dif =dif+players[l_i][1]\n l_i=l_i-1\n end\n if dif <0\n b.push players[s_i][0]\n dif =dif+players[s_i][1]\n s_i=s_i+1\n else\n dif =dif+players[l_i][1]\n b.push players[l_i][0]\n l_i=l_i-1\n end\ni=i+2\nend\nif n%2!=0\n if dif >0\n b.push players[l_i][0]\n else\n a.push players[l_i][0]\n end\nend\nputs a.size,a.to_s.delete('[').delete(']').gsub(\",\",\"\"),b.size,b.to_s.delete('[').delete(']').gsub(\",\",\"\")\n\n"}], "src_uid": "0937a7e2f912fc094cc4275fd47cd457"} {"source_code": "gets;a=gets.split.map &:to_i;gets;b=gets.split.map &:to_i;c=a.product(b).map{|x,y|y%x==0?(y/x):0};p c.count c.max\n", "positive_code": [{"source_code": "n = gets.to_i\nnn = []\nnmas = gets.split\nm = gets.to_i\nmm = []\nmmas = gets.split\ni = 0\nwhile i max then \n result = 1\n max = k\n end\n end\n j += 1\n end\n i += 1\nend\nprint \"#{result}\\n\"\n"}, {"source_code": "gets\na = gets.split.map &:to_i\ngets\nb = gets.split.map &:to_i\n\nc = b.product(a).map{ |bi,aj| bi*1.0/aj }.select{ |i| i%1 == 0 }\nputs c.count c.max\n"}, {"source_code": "gets;a=gets.split.map &:to_i;gets;b=gets.split.map &:to_i;c=a.product(b).map{|x,y|y%x==0?(y/x):0};p c.count c.max\n"}, {"source_code": "gets;a=gets.split.map &:to_i;gets;b=gets.split.map &:to_i;c=a.product(b).map{|x,y|y%x==0?(y/x):0};p c.count c.max\n"}, {"source_code": "n = gets.to_i\ngears1 = gets.split(' ').map{|x| x.to_i}\nm = gets.to_i\ngears2 = gets.split(' ').map{|x| x.to_i}\n\nbest = -1\ncount = 0\n\nfor i in gears1\n for j in gears2\n if j % i == 0 && j / i > best\n best = j / i\n count = 1\n elsif j % i == 0 && j / i == best\n count += 1\n end\n end\nend\n\nprint \"#{count}\\n\""}, {"source_code": "gets;a=gets.split.map &:to_i;gets;b=gets.split.map &:to_i;c=a.product(b).map{|x,y|y%x==0?(y/x):0};p c.count c.max"}, {"source_code": "n, a, m, b = readlines.map(&:chomp).map(&:split).map { |x| x.map!(&:to_i) }\ns = a.product(b).map { |x| x[1]%x[0] == 0 ? x[1]/x[0] : nil }.compact\nputs s.count { |x| x == s.max }"}, {"source_code": "gets;a=gets.split.map &:to_i;gets;b=gets.split.map &:to_i;c=a.product(b).map{|x,y|y%x==0?(y/x):0};p c.count c.max\n"}, {"source_code": "n = gets.to_i\na = gets.split.map! {|x| x.to_i }\nm = gets.to_i\nb = gets.split.map! {|x| x.to_i }\nans = []\nfor x in a do\n for y in b do\n ans << y / x if y % x == 0\n end\nend\nmx = -1\nans.each do |x|\n mx = x if x > mx\nend\ncnt = 0\nans.each do |x|\n cnt += 1 if x == mx\nend\nputs cnt"}, {"source_code": "gets;a=gets.split.map &:to_i;gets;b=gets.split.map &:to_i;c=a.product(b).map{|x,y|y%x==0?(y/x):0};p c.count c.max\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\n0.upto(a-1) {|i| b[i]=b[i].to_i}\nc=gets.chomp.to_i\nd=gets.chomp.split(\" \")\n0.upto(c-1) {|i| d[i]=d[i].to_i}\n\nnum=[]\nd.each do |i|\nb.each do |j|\nif i%j==0\nnum << i/j\nend\nend\nend\nnum.sort!\nmax=num[num.length-1]\nans=num.count(max)\nputs \"#{ans}\""}, {"source_code": "gets\na=gets.split.map(&:to_i)\ngets\nb=gets.split.map(&:to_i)\nc = []\na.each do |aa|\n b.each do |bb|\n c << bb / aa if bb % aa == 0\n end\nend\np c.count c.max\n\n"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\nfront = gets.split.map &:to_i\nm = gets.to_i\nback = gets.split.map &:to_i\n\nmax_value = 0\nmax_count = 0\n\nfor front_x in front do\n for back_x in back do\n next if back_x % front_x != 0\n next if back_x / front_x < max_value\n \n if back_x / front_x == max_value then\n max_count+=1\n else\n max_value = back_x / front_x\n max_count = 1\n end\n end\nend\n\nprint max_count"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\nfront = gets.split.map &:to_i\nm = gets.to_i\nback = gets.split.map &:to_i\n\nhash = Hash.new( 0 )\n\nfor front_x in front do\n for back_x in back do\n next if back_x % front_x != 0\n \n hash[back_x / front_x]+=1\n end\nend\n\nprint hash.to_a.max[1]"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\ngets\nfront = gets.split.map &:to_i\ngets\nback = gets.split.map &:to_i\n\nhash = Hash.new( 0 )\n\nfront.each{|v1|\n back.each{|v2|\n next if v2 % v1 != 0\n \n hash[v2 / v1]+=1\n }\n}\n\nprint hash.to_a.max[1]"}, {"source_code": "#!/usr/bin/ruby\nn = gets.chomp.to_i\na = gets.chomp.split(' ').map{|x| x.to_i}\nm = gets.chomp.to_i\nb = gets.chomp.split(' ').map{|x| x.to_i}\nmaxrat = 0\nints = 0\nfor i in 0..n-1\n\tfor j in 0..m-1\n\t\tif b[j]%a[i] == 0\n\t\t\tif b[j]/a[i] > maxrat\n\t\t\t\tints = 1\n\t\t\t\tmaxrat = b[j]/a[i]\n\t\t\telsif b[j]/a[i] == maxrat\n\t\t\t\tints +=1\n\t\t\tend\n\t\tend\n\tend\nend\nputs ints\n"}, {"source_code": "gets;a=gets.split.map &:to_i;gets;b=gets.split.map &:to_i;c=a.product(b).map{|x,y|y%x==0?(y/x):0};p c.count c.max"}, {"source_code": "gets;a=gets.split.map &:to_i;gets;b=gets.split.map &:to_i;c=a.product(b).map{|x,y|y%x==0?(y/x):0};p c.count c.max\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nm = gets.to_i\nb = gets.split.map(&:to_i)\n\nvalues = []\nb.each do |i|\n a.each do |j|\n values << i/j if i%j == 0\n end\nend\n\nvalues = values.sort_by{|el| -el}\nputs values.count(values[0])\n"}, {"source_code": "gets;a=gets.split.map &:to_i;gets;b=gets.split.map &:to_i;c=a.product(b).map{|x,y|y%x==0?(y/x):0};p c.count c.max\n"}, {"source_code": "n = Integer(gets.chomp)\na = gets.chomp.split.map { |x| x.to_i }\nm = Integer(gets.chomp)\nb = gets.chomp.split.map { |x| x.to_i }\n\nmax = 0\nfor i in (m - 1).downto(0)\n for j in 0...n\n if b[i] % a[j] == 0\n r = b[i] / a[j]\n max = r if r > max\n end\n end\nend\n\nc = 0\nfor i in 0...m\n for j in 0...n\n c += 1 if b[i] % a[j] == 0 && b[i] / a[j] == max\n end\nend\nputs c"}, {"source_code": "gets\na = gets.split.map!(&:to_i)\ngets\nb = gets.split.map!(&:to_i)\n\nmax = 0\ncount = 0\n\na.each do |ai|\n b.each do |bj|\n if bj % ai == 0\n r = bj / ai\n if r == max\n count += 1\n elsif r > max\n max = r\n count = 1\n end\n end\n end\nend\n\np count\n"}, {"source_code": "gets\na = gets.split.map!(&:to_i)\ngets\nb = gets.split.map!(&:to_i)\n\nc = a.product(b).map!{|x,y| y%x == 0 ? y/x : 0}\n\np c.count(c.max)\n"}, {"source_code": "gets;a=gets.split.map &:to_i;gets;b=gets.split.map &:to_i;c=a.product(b).map{|x,y|y%x==0?(y/x):0};p c.count c.max\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nm = gets.to_i\nb = gets.split.map(&:to_i)\n\nvalues = []\nb.each do |i|\n a.each do |j|\n values << i/j if i%j == 0\n end\nend\n\nvalues = values.sort_by{|el| -el}\nputs values.count(values[0])\n"}], "negative_code": [{"source_code": "n = Integer(gets.chomp)\na = gets.chomp.split.map { |x| x.to_i }\nm = Integer(gets.chomp)\nb = gets.chomp.split.map { |x| x.to_i }\n\nmax = 0\ncatch (:done) do\n for i in (m - 1).downto(0)\n for j in 0...n\n if b[i] % a[j] == 0\n max = b[i] / a[j]\n throw :done\n end\n end\n end\nend\n\nc = 0\nfor i in 0...m\n for j in 0...n\n c += 1 if b[i] % a[j] == 0 && b[i] / a[j] == max\n end\nend\nputs c"}], "src_uid": "102667eaa3aee012fef70f4192464674"} {"source_code": "n,k = gets.split.map(&:to_i)\nans = Array.new(k){|i|i+1}\nn -= k*(k+1)/2\nif n < 0\n puts \"NO\"\n exit\nend\nk.times do |i|\n ans[i] += n/k\nend\nn %= k\n(k-1).downto(1) do |i|\n m = [ans[i-1]*2-ans[i],n].min\n ans[i] += m\n n -= m\nend\n(k-1).times do |i|\n if ans[i]*2 < ans[i+1]\n puts \"NO\"\n exit\n end\nend\nif n > 0\n puts \"NO\"\n exit\nend\nputs \"YES\",ans.join(\" \")", "positive_code": [{"source_code": "n,k = gets.split.map(&:to_i)\nans = Array.new(k){|i|i+1}\nn -= k*(k+1)/2\nif n < 0\n puts \"NO\"\n exit\nend\nk.times do |i|\n ans[i] += n/k\nend\nn %= k\n(k-1).downto(1) do |i|\n m = [ans[i-1]*2-ans[i],n].min\n m = [ans[i+1]-1,m].min if i+1 < k\n ans[i] += m\n n -= m\nend\n(k-1).times do |i|\n if ans[i]*2 < ans[i+1]\n puts \"NO\"\n exit\n end\nend\nif n > 0\n puts \"NO\"\n exit\nend\nputs \"YES\",ans.join(\" \")"}], "negative_code": [], "src_uid": "df801ebbe05c17bb1d157108d523d1f8"} {"source_code": "s = gets.split('')\ns.pop\nk = gets.to_i\nvalues_str = gets.split(' ')\nvalues = Array.new(26) { Array.new(2) }\nvalues_str.each_with_index do |val, i|\n values[i] = [i, val.to_i]\nend\n\ntotal = 0\ns.each_with_index do |c, i|\n total += (i + 1) * values[c.ord - 'a'.ord][1]\nend\n\nvalues.sort! do |i, j|\n j[1] <=> i[1]\nend\n\nk.times do |i|\n total += (i + 1 + s.length) * values[0][1]\nend\n\nputs total", "positive_code": [{"source_code": "s = gets.chomp\nk = gets.to_i\nw = gets.split.map { |x| x.to_i }\n\nans = 0\ns.each_char.with_index do |c, i|\n\tans += w[c.ord - 97] * (i + 1)\nend\nans += k * (s.length + 1 + s.length + k) / 2 * w.max\n\nputs ans\n"}, {"source_code": "#!/usr/bin/ruby\ns=gets.chomp.bytes.map{|e|e-97}\nn=gets.to_i\na=gets.split.map(&:to_i)\np (s.map{|e|a[e]}+[a.max]*n).each.with_index(1).reduce(0){|s,(e,i)|s+e*i}"}, {"source_code": "s = gets.chomp\nk = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\nans = 0 \ns.each_char.with_index do |c,i|\n\tweight = arr[c.ord - 97]\n\tans += weight * (i +1)\nend\nsum = ((s.length+1)..(s.length+k)).inject(0,&:+)\nans += sum * arr.max\nputs ans"}, {"source_code": "s = gets.chomp\nk = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\nans = 0 \ns.each_char.with_index do |c,i|\n\tweight = arr[c.ord - 97]\n\tans += weight * (i +1)\nend\nsum = ((s.length+1)..(s.length+k)).inject(0,&:+)\nans += sum * arr.max\nputs ans\n# "}, {"source_code": "str = gets.chomp\nk = gets.to_i\nazarr = gets.split(\" \").collect { |e| e.to_i}\n\naz = []\nstr.each_char { |e|\n az << azarr[e.ord - 97]\n}\n\nmax = [az.max, azarr.max].max\n\ni = 1\nlen = str.length\n#p len\nsum = max*(k*(2*len+1+k))/2\n#p sum\naz.each { |e|\n sum += i*e\n i += 1\n}\np sum"}, {"source_code": "a = gets.chomp.split('').map { |c| c.ord - 97 }\nk = gets.to_i\nw = gets.chomp.split.map(&:to_i)\nn = a.size + 1\nputs a.each_with_index.map { |x, i| w[x] * (i + 1) }.inject(:+) + ((2 * n + k - 1) * k / 2) * w.max"}, {"source_code": "a = gets.chomp.split('').map { |c| c.ord - 97 }\nk = gets.to_i\nw = gets.chomp.split.map(&:to_i)\nputs a.each_with_index.map { |x, i| w[x] * (i + 1) }.inject(:+) + ((2 * a.size + k + 1) * k / 2) * w.max"}, {"source_code": "s=gets.chomp\nk=gets.to_i\nw=gets.split.map &:to_i\nl,t=s.size,0\nl.times{|i| t+=(i+1)*w[s[i].ord-'a'.ord]}\nt+=(k*l+k*(k+1)/2)*w.max\np t"}, {"source_code": "s = gets.chomp\nk = gets.to_i\nw = gets.split.map {|i| i.to_i}\nm = w.max\nsum = 0\ns.scan(/./).each_with_index {|i, x| sum += w[i.ord - 'a'.ord] * (x + 1)}\nfor i in 1..k\n sum += m * (i + s.length)\nend\nputs sum\n"}, {"source_code": "s = gets\nk = gets\nvals = gets\n\nk = k.to_i\nvals = vals.split(\" \")\nvals = vals.map(&:to_i)\n\ns = s.split(\" \")\nv1 = 0\ni = 1\n\ns[0].each_char do |c|\n v1+=(i*vals[c.ord-97])\n i+=1\nend\n\nvals = vals.sort.reverse\n\nfor j in 1..k\n v1 += (vals[0]*i)\n i+=1\nend\ni = 1\n\nputs v1\n\n"}, {"source_code": "s=gets.chomp.split('')\nk=gets.to_i\na=gets.chomp.split.map(&:to_i)\nm,ans,i=a.max,0,0\nwhile i= 0 do\n a = inp - 7*x\n if a%4 == 0\n found = true\n break\n end \n x = x-1 \nend\n\nres1 = res1.rjust(x,'7')\nres2 = res2.rjust(a/4,'4')\n\n\nif found\n puts res2+res1\nelse\n puts -1\nend \n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\nn = gets.to_i\nseven = (n/7)\nwhile true\n\tif (n-seven*7) % 4 == 0\n\t\tputs '4'*((n-seven*7)/4) << '7'*seven\n\t\texit\n\tend\n\tseven -= 1\n\tif seven == -1\n\t\tputs -1\n\t\texit\n\tend\nend\n"}, {"source_code": "n = gets.chop.to_i\na = 0\nr = 0\nvyslo = 0\n(n-1).downto(0){ |b|\n\t#puts b\n\ta = (n-7*b)/4\n\tif 4*a + 7*b == n && a >= 0\n\t\tr = b\n\t\tvyslo = 1\n\t\tbreak\n\tend\n}\nif vyslo == 1\n\tfor i in 0..a-1\n\t\tprint \"4\"\n\tend\n\tfor i in 0..r-1\n\t\tprint \"7\"\n\tend\nelse\n\tprint \"-1\"\nend\nprint \"\\n\"\n"}, {"source_code": "def check\n count = 0\n val.each_char { |s|\n if (s == '4' or s == '7')\n count += 1\n end\n }\n\n if (count == 4 or count == 7)\n return true\n else\n return false\n end\nend\n\ndef succ(val, index)\n if index == -1\n return '4' + val\n end\n\n if (val[index] == '7')\n val[index] = '4'\n val = succ(val, index - 1)\n else\n val[index] = '7'\n end\n return val\nend\n\ndef isucc(i)\n s = i.to_s\n return succ(s, s.length-1).to_i\nend\n\ndef sum(i)\n h = Hash.new(0)\n h['4'] = 0\n h['7'] = 0\n i.each_char { |c|\n h[c] += 1\n }\n return h['4']*4 + h['7']*7\nend\n\ni = gets.chop.to_i\n\nmax4 = i / 4\nmax7 = i / 7\nmax4 += 1\nmax7 += 1\n\narr = Array.new(0)\nres = \"-1\"\nfound = false\nmax7.downto(0) { |i7|\n #puts i7\n max4 = i - i7*7 + 7\n max4.downto(0) { |i4|\n if i == i7*7 + i4*4\n res = '4'*i4 + '7'*i7\n found = true\n break\n end\n }\n if found == true\n break\n end\n}\n\nputs res\n\n#start = '4'\n#100.times {\n# start = succ(start, start.length-1)\n# puts \"#{start} sum = #{sum(start)}\"\n#}"}, {"source_code": "i = STDIN.gets.to_i\n if (i % 7) == 0\n r = '7'*(i/7)\n else\n if i < 4 \n r = '-1'\n else\n seven = i/7\n while seven > -1 && (i-seven*7) % 4 != 0\n seven -= 1\n end\n \n if seven == -1\n r = '-1'\n else\n r = \"#{'4' * ((i - seven*7) / 4)}#{'7' * seven}\\n\"\n end\n end\n end\nputs r"}, {"source_code": "n = gets.to_i\ns = n / 7\nr = n - s * 7\nwhile s > 0 and r % 4 != 0 do s -= 1; r = n - s * 7 end\nif r % 4 != 0 or n < 4\n puts -1\nelse\n f = r / 4\n puts \"4\" * f + \"7\" * s\nend"}, {"source_code": "#!/usr/bin/env ruby\n\n\nn = STDIN.gets.to_i\n\ncount = n/7\nwhile count > -1\n if (n-7*count) % 4 == 0\n puts [[4]*((n-7*count)/4),[7]*count].flatten.join\n exit\n end\n count -= 1\nend\nputs -1\n"}, {"source_code": "def func(n)\n if (n == 0) then \n s = \"-1\"\n elsif (n % 7 == 0) then\n s = \"7\" * (n/7)\n elsif (n % 4 == 0) then\n s = \"4\"\n if n != 4 then\n n -= 4\n s += func(n)\n end\n else \n s = \"-1\"\n end\n return s\nend\n\nn = gets.to_i\nif (s = func(n)) != \"-1\" then \n print \"#{s}\\n\"\nelse\n r = 4\n s = \"4\"\n while r < n do\n if func(n-r) != \"-1\" then \n s += func(n-r)\n r = n\n elsif (r + 7) == n then \n r += 7\n s += \"7\"\n else\n r += 4\n s += \"4\"\n end\n end\n if r > n then s = \"-1\"\n end\n print \"#{s}\\n\"\nend\n"}, {"source_code": "n = gets.to_i\n# n = 7 * n7 + 4 * n4\n\nn7 = n / 7\nwhile n7 >= 0 do\n if (n - n7 * 7) % 4 == 0\n n4 = (n - n7 * 7) / 4\n break\n end\n n7 -= 1\nend\n\nif n7 >= 0\n puts (Array.new(n4) {4}).join + (Array.new(n7) {7}).join\nelse\n puts -1\nend"}, {"source_code": "sum = gets.chomp.to_i\ndiv = 1\ncount = 0\nwhile sum>=0\n if(sum%7==0 or sum == 0)\n puts (\"4\"*count + \"7\"*(sum/7)).split(\"\").sort.join\n exit\n end\n sum-=4\n count+=1\nend\nputs -1"}, {"source_code": "n = gets.to_i\n\ns = n / 7\nf = 0\nwhile s * 7 + f * 4 != n and s >= 0 do\n f += 1\n if s * 7 + f * 4 > n then s -= 1 end\nend\n\nif s >= 0 then\n st = ''\n puts '4' * f + '7' * s \nelse\n puts -1\nend\n\n"}, {"source_code": "# def lucky(four,seven,n)\n# \tif n == 0\n# \t\t# puts \"here\"\n# \t\t@fo = four\n# \t\t@sev = seven\n# \t\treturn true\n# \tend\n# \treturn false if n < 0\n# \tif lucky(four,seven+1,n-7) || lucky(four+1,seven,n-4)\n# \t\treturn true\n# \telse\n# \t\treturn false\n# \tend\t\n# end\n\n# @fo = 0\n# @sev = 0\n\n# n = gets.to_i\n\n# # puts lucky(0,0,n)\n# if lucky(0,0,n)\n# \tputs \"4\" * @fo + \"7\" * @sev\n# else\n# \tputs \"-1\"\n# end\n\nn = gets.to_i\n\nb = 0\nmin_a = 10 ** 12\nmin_b = 10 ** 12\nmin_ab = 10 ** 12\n\na = 0\nans = false\n# a * 4 + b * 7 = n\nwhile a * 4 <= n \n\tb = (n - (a * 4))/7\n\tif (a * 4 + b * 7 == n) && ((a + b < min_ab) || (a + b == min_ab && b < min_b))\n\t\tmin_a = a\n\t\tmin_b = b\n\t\tmin_ab = a + b\n\t\tans = true\n\tend\n\ta += 1\nend\n\nif ans\n\tputs \"4\" * min_a + \"7\" * min_b\nelse\n\tputs \"-1\"\nend\n"}, {"source_code": "n = gets.to_i\nm = -1\nfor i in 0..n/7\n\tm = i if ( n - 7 * i ) % 4 == 0\nend\nif m == -1\n\tputs -1\nelse\n\tn = ( n - 7 * m ) / 4\n\tn.times { print 4 }\n\tm.times { print 7 }\n\tputs\nend"}, {"source_code": "n = gets.to_i\ncnt_7 = n/7\ncnt_4 = (n-cnt_7*7)/4\nwhile cnt_7 >= 0 and cnt_7*7+cnt_4*4 != n\n cnt_7 -= 1\n cnt_4 = (n-cnt_7*7)/4\nend\nif cnt_7 >= 0 and cnt_7*7+cnt_4*4 == n\n puts '4'*cnt_4+'7'*cnt_7\nelse\n puts -1\nend\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\n\nn = gets.to_i\ndp = Array.new(n+1, nil)\ndp[0] = ''\n1.upto(n) do |i|\n if i-4 >= 0 && dp[i-4]\n str = dp[i-4] + '4'\n if dp[i].nil?\n dp[i] = str\n else\n dp[i] = str if dp[i] > str\n end\n end\n\n if i-7 >= 0 && dp[i-7]\n str = dp[i-7] + '7'\n if dp[i].nil?\n dp[i] = str\n else\n dp[i] = str if dp[i] > str\n end\n end\nend\n\nputs dp[n] || -1\n"}, {"source_code": "n = gets.chop.to_i\na = 0\nb = 0\nvyslo = 0\nfor b in 0..n-1\n\ta = (n-7*b)/4\n\tif 4*a + 7*b == n && a >= 0\n\t\tvyslo = 1\n\t\tbreak\n\tend\nend\nif vyslo == 1\n\tfor i in 0..a-1\n\t\tprint \"4\"\n\tend\n\tfor i in 0..b-1\n\t\tprint \"7\"\n\tend\nelse\n\tprint \"-1\"\nend\nprint \"\\n\"\n"}, {"source_code": "n = gets.chop.to_i\na = 0\nb = 0\nfor b in 0..n-1\n\ta = (n-7*b)/4\n\tif 4*a + 7*b == n\n\t\tbreak\n\n\tend\nend\nputs \"A\" + a.to_s\nputs \"B\" + b.to_s\n"}, {"source_code": "n = gets.chop.to_i\na = 0\nb = 0\nfor b in 0..n-1\n\ta = (n-7*b)/4\n\tif 4*a + 7*b == n\n\t\tbreak\n\n\tend\nend\nfor i in 0..a-1\n\tprint \"4\"\nend\nfor i in 0..b-1\n\tprint \"7\"\nend\nprint \"\\n\"\n"}, {"source_code": "n = gets.chop.to_i\na = 0\nb = 0\nvyslo = 0;\nfor b in 0..n-1\n\ta = (n-7*b)/4\n\tif 4*a + 7*b == n\n\t\tvyslo = 1\n\t\tbreak\n\tend\nend\nif vyslo == 1\n\tfor i in 0..a-1\n\t\tprint \"4\"\n\tend\n\tfor i in 0..b-1\n\t\tprint \"7\"\n\tend\nelse\n\tprint \"-1\"\nend\nprint \"\\n\"\n"}, {"source_code": "def check\n count = 0\n val.each_char { |s|\n if (s == '4' or s == '7')\n count += 1\n end\n }\n\n if (count == 4 or count == 7)\n return true\n else\n return false\n end\nend\n\ndef succ(val, index)\n if index == -1\n return '4' + val\n end\n\n if (val[index] == '7')\n val[index] = '4'\n val = succ(val, index - 1)\n else\n val[index] = '7'\n end\n return val\nend\n\ndef isucc(i)\n s = i.to_s\n return succ(s, s.length-1).to_i\nend\n\ndef sum(i)\n h = Hash.new(0)\n h['4'] = 0\n h['7'] = 0\n i.each_char { |c|\n h[c] += 1\n }\n return h['4']*4 + h['7']*7\nend\n\ni = gets.chop.to_i\nii = i + 4 + 7 + 4\nx = 4\nfail = false\n\nfour_count = i / 4\nstart = '4' * four_count\n#x = start.to_i\n\ns = sum(start)\nwhile s != i\n if (s > ii)\n fail = true\n break\n end\n\n start = succ(start, start.length-1)\n s = sum(start)\nend\n\nif (fail == false)\n puts start\nelse\n puts -1\nend"}, {"source_code": "i = STDIN.gets.to_i\n if (i % 4) == 0\n r = '4'*(i/4)\n else\n if i < 7 \n r = '-1'\n else\n four = i/4\n while four > -1 && (i-four*4) % 7 != 0\n four -= 1\n end\n \n if four == -1\n r = '-1'\n else\n r = \"#{'4' * four}#{'7' * ((i - four*4) / 7)}\\n\"\n end\n end\n end\nputs r"}, {"source_code": "#!/usr/bin/env ruby\n\n\nn = STDIN.gets.to_i\n\ncount = 0\nwhile (7*count) < n\n if (n-7*count) % 4 == 0\n puts [[4]*((n-7*count)/4),[7]*count].flatten.join\n exit\n end\n count += 1\nend\nputs -1\n"}, {"source_code": "def func(n)\n if (n == 0) then \n s = \"-1\"\n elsif (n % 7 == 0) then\n s = \"7\" * (n/7)\n elsif (n % 4 == 0) then\n s = \"4\" * (n/4) \n else \n s = \"-1\"\n end\n return s\nend\n\nn = gets.to_i\nif (s = func(n)) != \"-1\" then \n print \"#{s}\\n\"\nelse\n r = 4\n s = \"4\"\n while r < n do\n if func(n-r) != \"-1\" then \n s += func(n-r)\n r = n\n elsif (r + 7) == n then \n r += 7\n s += \"7\"\n else\n r += 4\n s += \"4\"\n end\n end\n if r > n then s = \"-1\"\n end\n print \"#{s}\\n\"\nend\n"}, {"source_code": "def func(n)\n if (n == 0) then \n s = \"-1\"\n elsif (n % 7 == 0) then\n s = \"7\" * (n/7)\n elsif (n % 4 == 0) then\n s = \"4\"\n n -= 4\n s += func(n)\n else \n s = \"-1\"\n end\n return s\nend\n\nn = gets.to_i\nif (s = func(n)) != \"-1\" then \n print \"#{s}\\n\"\nelse\n r = 4\n s = \"4\"\n while r < n do\n if func(n-r) != \"-1\" then \n s += func(n-r)\n r = n\n elsif (r + 7) == n then \n r += 7\n s += \"7\"\n else\n r += 4\n s += \"4\"\n end\n end\n if r > n then s = \"-1\"\n end\n print \"#{s}\\n\"\nend\n"}, {"source_code": "sum = gets.chomp.to_i\nq4 = sum/4\ndiv4 = sum%4\nq7 = sum - q4*4\ndiv7 = (sum - q4*4)%7\n\nif(div7==0)\n num = \"4\"*q4 + \"7\"*q7\n num = num.split(\"\").sort.join\n puts num\nelse\n puts -1\nend"}, {"source_code": "sum = gets.chomp.to_i\ndiv = 1\ncount = 0\nwhile sum>0\n sum-=4\n count+=1\n if(sum%7==0)\n puts (\"4\"*count + \"7\"*(sum/7)).split(\"\").sort.join\n exit\n end\nend\nputs -1"}, {"source_code": "sum = gets.chomp.to_i\nq7 = sum/7\ndiv7 = sum%7\nq4 = (sum - q7*7)/4\ndiv4 = (sum-q7*7)%4\n\nif(div4==0)\n num = \"4\"*q4 + \"7\"*q7\n num = num.split(\"\").sort.join\n puts num\nelse\n puts -1\nend\n\n"}, {"source_code": "sum = gets.chomp.to_i\nq7 = sum/7\ndiv7 = sum%7\nq4 = (sum - q7*7)/4\ndiv4 = (sum-q7*7)%4\n\nif(div4==0)\n num = \"4\"*q4 + \"7\"*q7\n num = num.split(\"\").sort.join\n puts num\nelse\n puts -1\nend"}, {"source_code": "require 'mathn'\nsum = gets.chomp.to_i\nq7 = (sum/7).floor\ndiv7 = sum%7\nq4 = ((sum - q7*7)/4).floor\ndiv4 = (sum-q7*7)%4\n\nif(div4==0)\n num = \"4\"*q4 + \"7\"*q7\n num = num.split(\"\").sort.join\n puts num\nelse\n puts -1\nend"}, {"source_code": "# def lucky(four,seven,n)\n# \tif n == 0\n# \t\t# puts \"here\"\n# \t\t@fo = four\n# \t\t@sev = seven\n# \t\treturn true\n# \tend\n# \treturn false if n < 0\n# \tif lucky(four,seven+1,n-7) || lucky(four+1,seven,n-4)\n# \t\treturn true\n# \telse\n# \t\treturn false\n# \tend\t\n# end\n\n# @fo = 0\n# @sev = 0\n\n# n = gets.to_i\n\n# # puts lucky(0,0,n)\n# if lucky(0,0,n)\n# \tputs \"4\" * @fo + \"7\" * @sev\n# else\n# \tputs \"-1\"\n# end\n\nn = gets.to_i\n\nb = 0\nmin_a = 10 ** 5\nmin_b = 10 ** 5\nmin_ab = 10 ** 5\n\na = 0\nans = false\n# a * 4 + b * 7 = n\nwhile a * 4 <= n \n\tb = (n - (a * 4))/7\n\tif (a * 4 + b * 7 == n) && ((a + b < min_ab) || (a + b == min_ab && b < min_b))\n\t\tmin_a = a\n\t\tmin_b = b\n\t\tmin_ab = a + b\n\t\tans = true\n\tend\n\ta += 1\nend\n\nif ans\n\tputs \"4\" * min_a + \"7\" * min_b\nelse\n\tputs \"-1\"\nend\n"}], "src_uid": "2584fa8c1adb1aa8cd5c28a8610ff72d"} {"source_code": "def main\n t = gets.chomp.to_i\n t.times { solve }\nend\n\ndef solve\n n, m = gets.chomp.split.map(&:to_i)\n a = gets.chomp.split.map(&:to_i)\n # S = gets.chomp.chars\n \n sum = 0\n 0.upto(n-1).each do |i|\n sum += a[i]\n end\n a0 = [sum, m].min # min(sum, m) is a0\n p a0\nend\n\nmain\n", "positive_code": [{"source_code": "#! /usr/bin/env ruby\n# encoding: UTF-8\n\ndef solve\n\tn,m = gets.split.map{|x| x.to_i }\n\txs = gets.split.map {|x| x.to_i }\n\tsum = xs.reduce(:+)\n\tputs([m, sum].min)\nend\n\nt = gets.to_i\nt.times {solve}\n\n\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n n, m = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n\n sum = a.inject(:+)\n\n puts [m, sum].min\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n,m = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n p [a.inject(:+), m].min\nend\n"}, {"source_code": "def read_input()\n \n rules = STDIN.gets()\n students = STDIN.gets()\n \n rules = rules.split(' ').map(&:to_i)\n students = students.split(' ').map(&:to_i)\n \n raise \"Invalid rules input\" if rules.size != 2\n raise \"Invalid input\" if students.size != rules[0]\n \n return rules, students\n \nend\n\ndef do_some_magic(cnt)\n cnt.times {\n \n rules, students = read_input()\n \n oth_cnt = students.size - 1\n \n # we need this num of points\n x = rules[1] - students[0]\n \n # available this num of points\n y = 0\n 1.upto(oth_cnt) { |s|\n y += students[s]\n }\n \n # and this num of points we can add to first student\n z = y < x ? y : x\n \n puts students[0] + z\n \n }\nend\n\ncnt = Integer(STDIN.gets())\n\ndo_some_magic(cnt)\n"}], "negative_code": [], "src_uid": "7c2a61de728e6767b25e58c74497bbae"} {"source_code": "n,m,*a=$<.read.split.map &:to_i\ns=q=0;r=[]\na.each{|e|s+=e;r<= m\n end\n puts pages.join(' ')\nend\n\nsolve\n"}, {"source_code": "N, M = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i)\nsum = 0\nans = []\nN.times do |i|\n ans[i] = (sum+as[i])/M - sum/M\n sum += as[i]\nend\nputs ans.join(' ')"}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\nais = gets.strip.split.map(&:to_i)\n\nans = Array.new(n, 0)\ncu=m\n0.upto(n-1).each do |i|\n ai = ais[i]\n if aicu\n rai = ai-cu\n ans[i]+=1\n ans[i]+= (rai/m)\n cu = m - (rai%m)\n cu = m if cu==0\n end\nend\n\nputs ans.join(' ')"}, {"source_code": "def single_input\n\tgets.chomp.to_i\nend\n\ndef multiple_input\n\tgets.chomp.split(' ').map(&:to_i)\nend\n\nn, m = multiple_input\nnames = multiple_input\n\nrem = m\nac = []\nn.times do |i|\n\tif names[i] < rem\n\t\trem -= names[i]\n\t\tac << 0\n\t\tnext\n\tend\n\n\tif rem == names[i]\n\t\trem = m\n\t\tac << 1\n\t\tnext\n\tend\n\n\n\tx = (names[i]-rem) / m\n\trem = (names[i]-rem) % m\n\trem = m - rem\n\tac << (x + 1)\nend\n\nprint ac.map(&:to_s).join(\" \")"}], "negative_code": [{"source_code": "def single_input\n\tgets.chomp.to_i\nend\n\ndef multiple_input\n\tgets.chomp.split(' ').map(&:to_i)\nend\n\nn, m = multiple_input\nnames = multiple_input\n\nrem = m\nac = []\nn.times do |i|\n\tif names[i] < rem\n\t\trem -= names[i]\n\t\tac << 0\n\t\tnext\n\tend\n\n\tif rem == names[i]\n\t\trem = 0\n\t\tac << 1\n\t\tnext\n\tend\n\n\n\tx = (names[i]-rem) / m\n\trem = (names[i]-rem) % m\n\trem = m - rem\n\tac << (x + 1)\nend\n\nprint ac.map(&:to_s).join(\" \")"}, {"source_code": "def single_input\n\tgets.chomp.to_i\nend\n\ndef multiple_input\n\tgets.chomp.split(' ').map(&:to_i)\nend\n\nn, m = multiple_input\nnames = multiple_input\n\nrem = m\nac = []\nn.times do |i|\n\tif names[i] < rem\n\t\trem -= names[i]\n\t\tac << 0\n\t\tnext\n\tend\n\n\tif rem == names[i]\n\t\trem = 0\n\t\tac << 1\n\t\tnext\n\tend\n\n\n\tx = (names[i]-rem) / m\n\trem = (names[i]-rem) % m\n\trem = m - rem\n\tac << (x + 1)\nend\n\np ac.map(&:to_s).join(\" \")"}], "src_uid": "a2085c2d21b2dbe4cc27a15fa4a1ec4f"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nans = []\nc = 0\na.each do |v|\n if c % 2 == 0\n ans.push(v)\n else\n ans.unshift(v)\n end\n c += 1\nend\nputs ans.join(\" \")\n", "positive_code": [{"source_code": "N = gets.to_i\nX = gets.split.map(&:to_i).sort\n\no = X.each_with_index.select{|e,i| i.odd?}.map(&:shift)\no += X.each_with_index.select{|e,i| i.even?}.map(&:shift).reverse\n\nputs o*\" \"\n\n# #pragma GCC optimize (\"O3\")\n# #include \"bits/stdc++.h\"\n# \n# using namespace std;\n# using ll = long long int;\n# \n# #define debugos cout\n# #define debug(v) {printf(\"L%d %s > \",__LINE__,#v);debugos<<(v)< \",__LINE__,#v);for(auto e:(v)){debugos< \",__LINE__,#m);for(int x=0;x<(w);x++){debugos<<(m)[x]<<\" \";}debugos<\\n\",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){debugos<<(m)[y][x]<<\" \";}debugos<::type>::type cnt=0;(cnt)<(l);++(cnt))\n# #define rrepeat(cnt,l) for(auto cnt=(l)-1;0<=(cnt);--(cnt))\n# #define iterate(cnt,b,e) for(auto cnt=(b);(cnt)!=(e);++(cnt))\n# #define diterate(cnt,b,e) for(auto cnt=(b);(cnt)!=(e);--(cnt))\n# const ll MD = 1000000007ll; const long double PI = 3.1415926535897932384626433832795L;\n# inline void assert_call(bool assertion, function f) { if (!assertion) { cerr << \"assertion fault:\" << endl; f(); abort(); } }\n# template inline ostream& operator <<(ostream &o, const pair p) { o << '(' << p.first << ':' << p.second << ')'; return o; }\n# template inline ostream& _ostream_vecprint(ostream& os, const Vec& a) {\n# os << '['; for (const auto& e : a) os << ' ' << e << ' '; os << ']'; return os;\n# }\n# template inline ostream& operator<<(ostream& o, const vector& v) { return _ostream_vecprint(o, v); }\n# template inline ostream& operator<<(ostream& o, const array& v) { return _ostream_vecprint(o, v); }\n# template inline T& chmax(T& to, const T& val) { return to = max(to, val); }\n# template inline T& chmin(T& to, const T& val) { return to = min(to, val); }\n# void bye(string s, int code = 0) { cout << s << endl; exit(code); }\n# mt19937_64 randdev(8901016);\n# template inline T rand(T l, T h) { return uniform_int_distribution(l, h)(randdev); }\n# template<> inline double rand(double l, double h) { return uniform_real_distribution(l, h)(randdev); }\n# template<> inline float rand(float l, float h) { return uniform_real_distribution(l, h)(randdev); }\n# \n# #if defined(_WIN32) || defined(_WIN64)\n# #define getchar_unlocked _getchar_nolock\n# #define putchar_unlocked _putchar_nolock\n# #elif defined(__GNUC__)\n# #else\n# #define getchar_unlocked getchar\n# #define putchar_unlocked putchar\n# #endif\n# namespace {\n# #define isvisiblechar(c) (0x21<=(c)&&(c)<=0x7E)\n# class MaiScanner {\n# public:\n# template void input_integer(T& var) {\n# var = 0; T sign = 1;\n# int cc = getchar_unlocked();\n# for (; cc < '0' || '9' < cc; cc = getchar_unlocked())\n# if (cc == '-') sign = -1;\n# for (; '0' <= cc && cc <= '9'; cc = getchar_unlocked())\n# var = (var << 3) + (var << 1) + cc - '0';\n# var = var * sign;\n# }\n# inline int c() { return getchar_unlocked(); }\n# inline MaiScanner& operator>>(int& var) { input_integer(var); return *this; }\n# inline MaiScanner& operator>>(long long& var) { input_integer(var); return *this; }\n# inline MaiScanner& operator>>(string& var) {\n# int cc = getchar_unlocked();\n# for (; !isvisiblechar(cc); cc = getchar_unlocked());\n# for (; isvisiblechar(cc); cc = getchar_unlocked())\n# var.push_back(cc);\n# return *this;\n# }\n# template void in(IT begin, IT end) { for (auto it = begin; it != end; ++it) *this >> *it; }\n# };\n# class MaiPrinter {\n# public:\n# template\n# void output_integer(T var) {\n# if (var == 0) { putchar_unlocked('0'); return; }\n# if (var < 0)\n# putchar_unlocked('-'),\n# var = -var;\n# char stack[32]; int stack_p = 0;\n# while (var)\n# stack[stack_p++] = '0' + (var % 10),\n# var /= 10;\n# while (stack_p)\n# putchar_unlocked(stack[--stack_p]);\n# }\n# inline MaiPrinter& operator<<(char c) { putchar_unlocked(c); return *this; }\n# inline MaiPrinter& operator<<(int var) { output_integer(var); return *this; }\n# inline MaiPrinter& operator<<(long long var) { output_integer(var); return *this; }\n# inline MaiPrinter& operator<<(char* str_p) { while (*str_p) putchar_unlocked(*(str_p++)); return *this; }\n# inline MaiPrinter& operator<<(const string& str) {\n# const char* p = str.c_str();\n# const char* l = p + str.size();\n# while (p < l) putchar_unlocked(*p++);\n# return *this;\n# }\n# template void join(IT begin, IT end, char sep = ' ') { for (bool b = 0; begin != end; ++begin, b = 1) b ? *this << sep << *begin : *this << *begin; }\n# };\n# }\n# MaiScanner scanner;\n# MaiPrinter printer;\n# \n# \n# //\n# \n# /*\n# \u3042\u3089\u304b\u3058\u3081\u30bd\u30fc\u30c8\n# \n# \u4f4e\u3044\u4eba->\u9ad8\u3044\u4eba \u3092\u9078\u629e\n# \u9ad8\u3044\u4eba->\u4f4e\u3044\u4eba \u3092\u672a\u9078\u629e\u3059\u308b\n# \n# \u3053\u308c\u3092\u52d5\u7684\u8a08\u753b\u6cd5\u3059\u308b\n# */\n# \n# int N;\n# ll A[111];\n# \n# ll dp[111][111];\n# \n# int main() {\n# scanner >> N;\n# scanner.in(A, A + N);\n# sort(A, A + N);\n# \n# fill(dp[0], dp[110], ll(1e18));\n# dp[0][0] = 0;\n# \n# int M = N - 1;\n# iterate(i, 0, N) {\n# iterate(j, 0, i+1) {\n# ll d = 0;\n# int jp = j;\n# iterate(k, i+1, N) {\n# chmin(dp[k][j], max(dp[i][j], max(d, A[k] - A[i])));\n# \n# chmax(d, A[k] - A[jp]);\n# jp = k;\n# }\n# }\n# }\n# ll ans = 1e18;\n# repeat(i, N) {\n# chmin(ans, max(dp[N-1][i], A[N - 1] - A[i]));\n# }\n# \n# debugaa(dp, N+1, N+1);\n# \n# cout << ans << endl;\n# \n# return 0;\n# }"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nn = gets.to_i\narr = []\narr= gets.chomp.split(\" \").map(&:to_i)\n\ndef getdisc(arr)\n\tmax = 0\n\tarr[1..-1].each_with_index do |x,i|\n\t\tasd = (x-arr[i-1]).abs\n\t\tmax = asd if asd>max\n\tend\n\tasd = (arr[-1]-arr[0]).abs\n\tmax=asd if asd>max\n\treturn max\nend\n\ndef newgetdisc(arr)\n\tmax = 0\n\tarr[1..-1].each_with_index do |x,i|\n\t\tasd = (x-arr[i-1]).abs\n\t\tmax+= asd\n\tend\n\tasd = (arr[-1]-arr[0]).abs\n\tmax+=asd# if asd>max\n\treturn max\nend\n\ndef swap(arr,a,b)\n\ttemp = arr[a]\n\tarr[a]=arr[b]\n\tarr[b]=temp\n\treturn arr\nend\n\n#newarr = []\n#disc = \n\n#p arr\n=begin\narr.each do |x|\n\tif newarr.length==0\n\t\tnewarr.push x\n\telse\n\t\tscorearr = []\n\t\t(0..newarr.length).each do |insloc|\n\t\t\tnewnewarr = newarr.dup\n\t\t\tnewnewarr.insert(insloc,x)\n\t\t\tscorearr.push newgetdisc(newnewarr)\n\t\tend\n\t\ttheloc = scorearr.index(scorearr.min)\n\t\tnewarr.insert(theloc,x)\n\tend\n\tp newarr\nend\n=end\n=begin\nnewarr = arr.dup\n\nwhile true\n\tcurrscore = getdisc(newarr)\n\ttobreak = false\n\tnewarr.each_with_index do |x,i|\n\t\tnewarr[i+1..-1].each_with_index do |y,j|\n\t\t\tnewnewarr = newarr.dup\n\t\t\tnewnewarr = swap(newnewarr,i,j)\n\t\t\tif(getdisc(newnewarr) words[s].length ? words[s] : s }\n\nputs result.join(' ')\n", "positive_code": [{"source_code": "n, m = gets.split.map &:to_i\ndict = Hash.new\nm.times do\n\ta, b = gets.split\n\tdict[a] = b.size < a.size ? b : a\nend\nputs gets.split.map { |_| dict[_] }.join(' ')"}, {"source_code": "n, m = gets.split.map{|x| x.to_i}\nh = {}\nm.times{h.merge!(Hash[*gets.split])}\nputs(gets.split.map{|x| x.size <= h[x].size ? x : h[x]}.join(' '))\n"}, {"source_code": "q=[]\nj=0\ngets.split.each do |i| \nq[j]=i.to_i\nj=j+1\nend\nhash=Hash[]\n\nq[1].times do\n s=gets.split\n hash[s[0]]=s[1]\nend\n\ngets.split.each do |i|\n if i.length <= hash[i].length\n print i + \" \"\n else\n print hash[i]+\" \"\n end \nend"}, {"source_code": "# http://codeforces.com/problemset/problem/499/B\n\nn, m = gets.chomp.split.map(&:to_i)\nlang_1 = []\nlang_2 = []\n\nm.times do\n words = gets.chomp.split\n lang_1 << words[0]\n lang_2 << words[1]\nend\n\nlecture = gets.chomp.split\nnote = []\n\nfor word in lecture\n index = lang_1.index(word)\n replace_word = [word, lang_2[index]].min_by(&:length)\n note << replace_word\nend\n\nputs note.join(\" \")\n"}, {"source_code": "# 499B\n\ndef read_line\n gets.chomp.split\nend\n\nw = {}\nread_line[1].to_i.times do\n k, v = read_line\n w[k] = v\nend\nputs read_line.map { |k| v = w[k]; v.size < k.size ? v : k } * ' '"}, {"source_code": "# f = File.open('input.txt', 'r')\nf = STDIN\nn, m = f.gets.chomp.split.map &:to_i\ndict1, dict2 = {}, {}\nm.times do\n s1, s2 = f.gets.chomp.split\n dict1[s1] = s2\n dict2[s2] = s1\nend\n\nstrs = f.gets.chomp.split\nt = strs.map do |s|\n if dict1[s]\n dict1[s].length < s.length ? dict1[s] : s\n else\n dict2[s].length < s.length ? dict2[s] : s\n end\nend\n\nputs t.join(' ')\n"}, {"source_code": "class Array\n\tdef __min\n\t\tself[0].length <= self[1].length ? self[0] : self[1]\n\tend\nend\n\nn, m = gets.split.map(&:to_i)\ndict = {}\nm.times do\n\ta, b = gets.split\n\tdict[a] = [a, b].__min\nend\nputs gets.split.map{|w| dict[w]}.join(' ')\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nd = Hash.new\nm.times do\n a, b = gets.split\n d[a] = if a.length <= b.length; a; else b; end\nend\nputs gets.split.map {|w| d[w]}.join(' ')\n"}, {"source_code": "n, m = gets.strip.split.map {|n| n.to_i}\nlang1 = []\nlang2 = []\nm.times do \n\tw1, w2 = gets.strip.split.map {|n| n}\n\tlang1.push(w1)\n\tlang2.push(w2)\nend\nnotes = \"\"\nlec = gets.strip.split(\" \")\nlec.each do |word|\n\ti = lang1.index(word)\n\tnotes += lang1[i].size <= lang2[i].size ? lang1[i] + \" \" : lang2[i]+ \" \"\nend\nputs notes"}, {"source_code": "\nhash = Hash.new;\nn, m = gets.chomp.split.map(&:to_i);\n\nm.times do\n a, b = gets.chomp.split;\n hash[a] = b.length < a.length ? b : a; \nend\ngets.chomp.split.each {|x| print hash[x] + \" \"};\n"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\na={}\nm.times do\n ai, bi = gets.chomp.split\n a[ai] = bi\nend\nans=''\n\ngets.chomp.split.each do |s|\n ans += (s.length <= a[s].length ? s : a[s]) + ' '\nend\nputs ans"}, {"source_code": "n,m =gets.split().map(&:to_i)\ndic = {} \nm.times do \n a,b = gets.split(\" \")\n dic[a] =b \nend \n\nval = gets.split(\" \")\nres = ''\nval.each do |i| \n if i.size > dic[i].size \n res +=dic[i]\n else \n res +=i\n end \n res +=' '\nend \nputs res\n"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nh={}\nm.times{\n\ta,b=gets.chomp.split\n\tif ((a.size)<=>(b.size))<1 then\n\t\th[a]=a\n\t\th[b]=a\n\telse\n\t\th[a]=b\n\t\th[b]=b\n\tend\n}\ns=gets.chomp.split\ni=0\ns.each{|e|\n\tprint \" \" if i>0\n\tprint h[e]\n\ti+=1\n}\nprint \"\\n\"\n\n"}, {"source_code": "#$stdin = File.open \"input.txt\"\n\nn, m = gets.split.map &:to_i\n\nreplace = {}\nm.times do\n\ta, b = gets.chomp.split\n\treplace[a] = b.size < a.size ? b : a\nend\n\nputs gets.chomp.split.map { |s| replace[s] }.join(\" \")\n\n\n"}, {"source_code": "#!/usr/bin/ruby\nclass InputReader\n def initialize\n @data = []\n @offset = 0\n end\n\n def next\n if @data.empty? || @offset >= @data.length\n line = STDIN.gets.chomp\n return nil if line.empty?\n @data = line.split(/\\s+/)\n @offset = 0\n end\n @offset += 1\n return @data[@offset-1]\n end\nend\n\n# ===== Your solution goes here =====\nreader = InputReader.new\nn = reader.next.to_i\nm = reader.next.to_i\ndict = {}\nm.times do\n k = reader.next\n v = reader.next\n dict[k] = v\nend\n\nn.times do\n word = reader.next\n if word.length <= dict[word].length\n print \"#{word} \"\n else\n print \"#{dict[word]} \"\n end\nend\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\ndic = Hash[]\nm.times do \n word = gets.split\n dic[word.first] = word.min_by &:length\nend\nputs gets.split.map {|w| dic[w]}.join(' ')"}, {"source_code": "nums = gets.chomp.split\nn = Integer(nums[0])\nm = Integer(nums[1])\nbest = Array.new\nbad = Array.new\ninput = Array.new\nfor i in 0...m\n input[i] = Array.new\n input[i] = gets.chomp.split\n if input[i][0].length <= input[i][1].length\n best.push(input[i][0])\n bad.push(input[i][1])\n else\n best.push(input[i][1])\n bad.push(input[i][0])\n end\nend\nlecture = Array.new\nlecture = gets.chomp.split\n\nnote = {}\nfor i in 0...m\n note[best[i]] = best[i]\n note[bad[i]] = best[i]\nend\nbest_note = []\nfor i in 0...n\n best_note.push(note[lecture[i]])\nend\n\nprint best_note.join(\" \")"}, {"source_code": "nm = gets.chomp.split\nn = nm[0].to_i\nm = nm[1].to_i\nab = []\na = []\nb = []\nfor i in (0..m-1)\n\tab[i] = gets.chomp.split\n\ta[i] = ab[i][0]\n\tb[i] = ab[i][1]\n\tif a[i].size <= b[i].size\n\t\tb[i] = nil\n\tend\nend\nc = gets.chomp.split\n\nfor i in (0..n-1)\n\tif b[a.find_index(c[i])] == nil\n\t\tprint a[a.find_index(c[i])] + \" \"\n\telse\n\t\tprint b[a.find_index(c[i])] + \" \"\n\tend\nend"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\nwords = {}\nm.times do\n\ta,b = gets.split(\" \")\n\twords[a] = b\nend\nlec = gets.split(\" \")\nop = []\nlec.each do |a|\n\tif a.length > words[a].length\n\t\top << words[a]\n\telse\n\t\top << a\n\tend\nend\n\nputs op.join(\" \")"}, {"source_code": "n, m = gets.chomp.split(' ').map(&:to_i)\na = {}\nm.times do\n ai, bi = gets.chomp.split ' '\n a[ai] = bi\nend\n\nres = ''\n\ngets.chomp.split(' ').each do |s|\n res += (s.length <= a[s].length ? s : a[s]) + ' '\nend\nputs res\n"}, {"source_code": "n,m = gets.split.map &:to_i\ndic = Hash[]\nm.times do\n w = gets.split\n dic[w.first] = w.min_by &:length\nend\nputs gets.split.map {|w| dic[w]}.join(' ')"}, {"source_code": "n, m = gets.split.map(&:to_i)\na, b = m.times.map { gets.split }.transpose\nputs gets.split.map { |x| [x, b[a.index(x)]].min_by(&:size) }.join(' ')"}, {"source_code": "\nline = gets.chop!.split(\" \")\n\nn = line[0].to_i\nm = line[1].to_i\n\nA = {}\nB = {}\n\nfor i in (1 .. m)\n line = gets.chop!.split(\" \")\n\n first = line[0]\n second = line[1]\n\n B[first] = i\n B[second] = i\n\n if second.size < first.size\n A[i] = second\n elsif second.size > first.size\n A[i] = first\n else\n A[i] = first\n end\nend\n\nline = gets.chop!.split(\" \")\n\nfor i in (1 .. n)\n print A[B[line[i-1]]]\n\n if i < n\n print \" \"\n end\nend\n"}], "negative_code": [{"source_code": "hash = Hash.new;\nn, m = gets.chomp.split.map(&:to_i);\n\nm.times do\n a, b = gets.chomp.split;\n hash[a] = b.length < a.length ? b : a; \nend\n\np gets.chomp.split.inject(){ |sum, x|\n # p \"#{sum}, #{x}, #{hash[x]}\";\n sum + \" \" + hash[x];\n}\n"}, {"source_code": "nm = gets.chomp.split\nn = nm[0].to_i\nm = nm[1].to_i\nab = []\na = []\nb = []\nfor i in (0..m-1)\n\tab[i] = gets.chomp.split\n\ta[i] = ab[i][0]\n\tb[i] = ab[i][1]\n\tif a[i].size < b[i].size\n\t\tb[i] = nil\n\tend\nend\nc = gets.chomp.split\n\nfor i in (0..n-1)\n\tif b[a.find_index(c[i])] == nil\n\t\tprint a[a.find_index(c[i])] + \" \"\n\telse\n\t\tprint b[a.find_index(c[i])] + \" \"\n\tend\nend"}, {"source_code": "n, m = gets.chomp.split(' ').map(&:to_i)\na = {}\nm.times do\n ai, bi = gets.chomp.split ' '\n a[ai] = bi\nend\n\nres = ''\n\ngets.chomp.split(' ').each do |s|\n res += (s.length >= a[s].length ? s : a[s]) + ' '\nend\nputs res\n"}, {"source_code": "\nline = gets.chop!.split(\" \")\n\nn = line[0].to_i\nm = line[1].to_i\n\nA = {}\nB = {}\n\nfor i in (1 .. m)\n line = gets.chop!.split(\" \")\n\n first = line[0]\n second = line[1]\n\n B[first] = i\n B[second] = i\n\n if second.size < first.size\n A[i] = second\n elsif second.size > first.size\n A[i] = first\n else\n if second < first\n A[i] = second\n else\n A[i] = first\n end\n end\nend\n\nline = gets.chop!.split(\" \")\n\nfor i in (1 .. n)\n print A[B[line[i-1]]]\n\n if i < n\n print \" \"\n end\nend\n"}, {"source_code": "\nline = gets.chop!.split(\" \")\n\nn = line[0].to_i\nm = line[1].to_i\n\nA = {}\nB = {}\n\nfor i in (1 .. m)\n line = gets.chop!.split(\" \")\n\n first = line[0]\n second = line[1]\n\n B[first] = i\n B[second] = i\n\n if second < first\n A[i] = second\n else\n A[i] = first\n end\nend\n\nline = gets.chop!.split(\" \")\n\nfor i in (1 .. n)\n print A[B[line[i-1]]]\n\n if i < n\n print \" \"\n end\nend\n"}, {"source_code": "# http://codeforces.com/problemset/problem/499/B\n\nn, m = gets.chomp.split.map(&:to_i)\nlang_1 = []\nlang_2 = []\n\nm.times do\n words = gets.chomp.split\n lang_1 << words[0]\n lang_2 << words[1]\nend\n\ntext_str = gets.chomp\ntext_arr = text_str.split\n\nfor i in 0..(m - 1)\n if !text_arr.include?(lang_1[i])\n next\n end\n\n word = lang_1[i].length <= lang_2[i].length ? lang_1[i] : lang_2[i]\n text_str.gsub!(lang_1[i], word)\nend\n\nputs text_str\n"}], "src_uid": "edd556d60de89587f1b8daa893538530"} {"source_code": "def solve(s)\n if s.split('').uniq.size == 1\n -1\n else\n s.split('').sort.join\n end\nend\n\ngets.strip.to_i.times do\n puts solve(gets.strip)\nend", "positive_code": [{"source_code": "n = gets.to_i\nn.times do\n s = gets.chomp\n idx = nil\n flag = false\n s.length.times do |i|\n if s[i] != s[0]\n flag = true\n idx = i\n end\n end\n if flag && s == s.reverse\n t = s[0]\n s[0] = s[idx]\n s[idx] = t\n end\n puts flag ? s : -1\nend\n"}, {"source_code": "gets;puts$<.map{|e|e=e.chomp.chars.sort*'';e[0] 1\n x_chars = x.chars\n if x_chars == x.chars.reverse\n while true do\n x_chars.shuffle!\n if x_chars != x_chars.reverse\n res = x_chars.join\n break\n end\n end\n else\n res = x_chars.join\n end\n end\n results << res\nend\n\nn.times do |x|\n puts results[x]\nend\n"}], "negative_code": [{"source_code": "gets;puts$<.map{|e|e.chomp!;f=e.chars.sort*'';f 1\n x_chars = x.chars\n if x_chars == x.chars.reverse\n while true do\n x_chars.shuffle!\n if x_chars != x.chars.reverse\n res = x_chars.join\n break\n end\n end\n else\n res = x_chars.join\n end\n end\n results << res\nend\n\nn.times do |x|\n puts results[x]\nend\n"}, {"source_code": "n = gets.strip.to_i\nresults = []\nn.times do\n x = gets.strip\n res = -1\n if x.chars.uniq.length > 1\n x_chars = x.chars\n if x_chars == x.chars.reverse\n while true do\n x_chars.shuffle!\n if x_chars != x.chars.reverse\n res = x_chars.join\n break\n end\n end\n else\n res = x_chars.join\n end\n end\n results << res\nend\n\nn.times do |x|\n puts results[x]\nend\n"}], "src_uid": "b9f0c38c6066bdafa2e4c6daf7f46816"} {"source_code": "n, x1, y1, x2, y2 = gets.split(' ').map(&:to_i)\n\nfs = []\nfor i in 0...n\n fx, fy = gets.split(' ').map(&:to_i)\n fs << [fx, fy]\nend\n\nds = []\nfor j in 0...n\n fx, fy = fs[j]\n d1 = (fx-x1)**2+(fy-y1)**2\n d2 = (fx-x2)**2+(fy-y2)**2\n ds << [d1, d2]\nend\nds << [0,0]\n\nmin = Float::INFINITY\nfor dv in ds\n d1 = dv[0]\n d2 = 0\n for dw in ds\n if dw[0] > d1\n d2 = [dw[1], d2].max\n end\n end\n \n min = [min, d1+d2].min\nend\n\nputs min", "positive_code": [{"source_code": "n, x1, y1, x2, y2 = gets.chomp.split(\" \").map(&:to_i)\ndist = []\n\nn.times do\n fx, fy = gets.chomp.split(\" \").map(&:to_i)\n d1 = (x1 - fx)**2 + (y1 - fy)**2\n d2 = (x2 - fx)**2 + (y2 - fy)**2\n dist << [d1, d2]\nend\ndist << [0,0]\n\nres = Float::INFINITY\ndist.each do |i|\n r1 = i[0]\n r2 = 0\n dist.each do |j|\n if j[0] > r1 then\n r2 = [r2, j[1]].max\n end\n end\n res = [res, r1 + r2].min\nend\n\nputs res\n"}], "negative_code": [{"source_code": "n, x1, y1, x2, y2 = gets.split(' ').map(&:to_i)\nmd1 = md2 = 0\nfor i in 0...n\n fx, fy = gets.split(' ').map(&:to_i)\n d1 = (fx-x1)**2+(fy-y1)**2\n d2 = (fx-x2)**2+(fy-y2)**2\n if d1-md1 < d2-md2\n # closer to r1\n md1 = [md1, d1].max\n else\n # closer to r2\n md2 = [md2, d2].max\n end\nend\n\nputs md1 + md2"}, {"source_code": "n, x1, y1, x2, y2 = gets.split(' ').map(&:to_i)\n\nfs = []\nfor i in 0...n\n fx, fy = gets.split(' ').map(&:to_i)\n fs << [fx, fy]\nend\n\nmin = Float::INFINITY\n\nmd1 = md2 = 0\nfor j in 0...n\n fx, fy = fs[j]\n d1 = (fx-x1)**2+(fy-y1)**2\n d2 = (fx-x2)**2+(fy-y2)**2\n if d1-md1 < d2-md2\n # closer to r1\n md1 = [md1, d1].max\n else\n # closer to r2\n md2 = [md2, d2].max\n end\nend\nmin = [min, md1 + md2].min\n\nmd1 = md2 = 0\nfor j in 1..n\n fx, fy = fs[n-j]\n d1 = (fx-x1)**2+(fy-y1)**2\n d2 = (fx-x2)**2+(fy-y2)**2\n if d1-md1 < d2-md2\n # closer to r1\n md1 = [md1, d1].max\n else\n # closer to r2\n md2 = [md2, d2].max\n end\nend\nmin = [min, md1 + md2].min\n\nputs min"}, {"source_code": "n, x1, y1, x2, y2 = gets.chomp.split(\" \").map(&:to_i)\ndist = []\n\nn.times do\n fx, fy = gets.chomp.split(\" \").map(&:to_i)\n d1 = (x1 - fx)**2 + (y1 - fy)**2\n d2 = (x2 - fx)**2 + (y2 - fy)**2\n dist << [d1, d2]\nend\n\nres = 10**15\ndist.each do |i|\n r1 = i[0]\n r2 = 0\n dist.each do |j|\n if j[0] > r1 then\n r2 = [r2, j[1]].max\n end\n end\n res = [res, r1 + r2].min\nend\nputs res\n"}, {"source_code": "n, x1, y1, x2, y2 = gets.chomp.split(\" \").map(&:to_i)\ndist = []\n\nn.times do\n fx, fy = gets.chomp.split(\" \").map(&:to_i)\n d1 = (x1 - fx)**2 + (y1 - fy)**2\n d2 = (x2 - fx)**2 + (y2 - fy)**2\n dist << [d1, d2]\nend\n\nres = 10**8\ndist.each do |i|\n r1 = i[0]\n r2 = 0\n dist.each do |j|\n if j[0] > r1 then\n r2 = [r2, j[1]].max\n end\n end\n res = [res, r1 + r2].min\nend\nputs res\n"}], "src_uid": "5db9c5673a04256c52f180dbfca2a52f"} {"source_code": "# TEMPLATE BEGIN\ndef read_vector\n gets.chomp.split(/\\s+/)\nend\ndef read_vector_int\n read_vector.map(&:to_i)\nend\n# TEMPLATE END\n\n$mod = 1_000_000_007\n$maxn = 1010\n\ndef mypow(a, b)\n res = 1\n while b > 0\n res = res * a % $mod if b % 2 == 1\n a = a * a % $mod\n b /= 2\n end\n res\nend\n\ndef ceshka(a, b)\n $fuck[a] * $rfuck[b] * $rfuck[a-b] % $mod\nend\n\n$fuck, $rfuck = [1], [1]\n(1..$maxn).each.map do |i|\n $fuck.push $fuck[i-1] * i % $mod\n $rfuck.push mypow($fuck[i], $mod - 2)\nend\n\nk = read_vector_int.first\na = k.times.map{ read_vector_int.first }\n\nres, sum = 1, 0\nk.times do |i|\n sum += a[i]\n res = res * ceshka(sum - 1, a[i] - 1) % $mod\nend\nputs res\n\n", "positive_code": [{"source_code": "\nk = gets().chomp().to_i\n\nn = gets().chomp().to_i\ncount = 1\nmod = 1000000007\n(k-1).times {\n c = gets().chomp().to_i\n p=c-1\n t1=1\n t2=1\n for i in(1..p)\n t1 *= n+i\n #t1 %= mod\n t2 *= i\n #t2 %= mod\n end\n\n count *= t1/t2\n count %= mod\n n+=c\n}\n\nputs count\n\n"}], "negative_code": [{"source_code": "k = gets().chomp().to_i\n\nn = gets().chomp().to_i\ncount = 1\nmod = 1000000007\n(k-1).times {\n c = gets().chomp().to_i\n p=c-1\n t1=1\n t2=1\n for i in(1..p)\n t1 *= n+i\n t1 %= mod\n t2 *= i\n t2 %= mod\n end\n\n count *= t1/t2\n n+=c\n}\n\nputs count\n\n"}], "src_uid": "faf2c92c3a61ba5e33160bc7a18ad928"} {"source_code": "n = gets.chomp.to_i\nn.times {\n arrNum = gets.chomp.to_i\n userstr = gets.chomp\n arr = userstr.split().map(&:to_i).sort\n result = arr.each_cons(2).map {|a,b| b-a}\n p result.min\n}", "positive_code": [{"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i).sort\n\tputs a.each_cons(2).map { _2 - _1 }.min\nend\n"}, {"source_code": "gets.strip.to_i.times do |t|\n _ = gets.strip.to_i\n vals = gets.strip.split(' ').map(&:to_i).sort\n mn = vals[1] - vals[0]\n a = vals[0]\n b = vals[1]\n vals.each_with_index do |e, i|\n next if i.zero?\n if vals[i] - vals[i - 1] < mn\n mn = vals[i] - vals[i-1]\n a = vals[i-1]\n b = vals[i]\n end\n end\n puts (a - b).abs\nend\n\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do |testcase|\n n = gets.chomp.to_i\n arr = gets.split.map(&:to_i)\n arr = arr.sort ; min_val = 1000000\n (arr.size-1).times do |i|\n min_val = [min_val , arr[i+1]-arr[i]].min\n end\n puts min_val\nend"}, {"source_code": "t = gets.to_i\n\n1.upto t do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n a.sort!\n diff = a[1] - a[0]\n 1.upto a.length-1 do |i|\n diff = [diff, a[i]-a[i-1]].min\n end \n puts diff\nend"}, {"source_code": "gets.to_i.times {\n gets\n puts gets.split.map(&:to_i).sort.each_cons(2).map{|x,y|y-x}.min\n}\n"}, {"source_code": "gets.to_i.times {\n gets\n data = gets.split.map { |v| v.to_i }.sort_by {|v| v}\n\n m = data[1] - data[0]\n for i in 2...data.size\n d = data[i] - data[i-1]\n if d < m\n m = d\n end\n end\n\n puts m\n}\n"}, {"source_code": "def solve\n _ = gets\n arr = gets.strip.split(' ').map(&:to_i).sort\n diff = 1001\n arr.each_with_index { |el, i|\n next if i.zero?\n diff = [diff, arr[i] - arr[i - 1]].min\n }\n puts diff\n\nend\n\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n s = gets.split.map(&:to_i).sort\n min_diff = s[-1] - s[0]\n for i in 0...(n - 1) do\n diff = s[i + 1] - s[i]\n if diff < min_diff\n min_diff = diff\n end\n end\n puts min_diff\nend\n"}, {"source_code": "gets.to_i.times do\n gets\n a = gets.split(' ').map(&:to_i).sort\n\n result = 1_000_000\n while a.size > 1\n x = a.shift\n\n result = [a.first - x, result].min\n end\n\n puts result\nend\n"}], "negative_code": [], "src_uid": "d2669f85bdb59715352c6bc3d7ba9652"} {"source_code": "pa=Array.new\npb=Array.new\nn=gets.to_i\nstr=gets.to_s\n\nstd=\"9\"\nfor i in 0..9\n min=10\n for j in 0..n-1\n pa[j] = (str[j].to_i + i) % 10\n if min > pa[j]\n min=pa[j]\n r=0\n pb[r]=j\n elsif min==pa[j]\n r+=1\n pb[r]=j\n end\n end\n\n stt=\"9\"\n for t in 0..r\n stk = pa[pb[t],n-pb[t]].join + pa[0,pb[t]].join\n# for j in pb[t]..pb[t]+n-1\n# stk << pa[j%n].to_s\n# end\n#puts stk\n if stt > stk\n stt=stk.clone\n end\n end \n if std > stt\n std=stt.clone\n end\nend\n\nputs std\n", "positive_code": [{"source_code": "# $f = File.open('input.txt', 'r')\n$f = STDIN\n\ndef inc(s)\n s.length.times{ |i| s[i] = ((s[i].to_i + 1) % 10).to_s }\n s\nend\n\ndef get_min(s)\n res = s.clone\n s.length.times do\n tmp = s.chars.rotate(-1).join\n res = [res, tmp].min\n s = tmp\n end\n res\nend\n\nwhile str = $f.gets\n n = str.chomp.to_i\n s = $f.gets.chomp\n res = s.clone\n 10.times do\n res = [res, get_min(s)].min.clone\n inc(s)\n end\n puts res\nend\n"}, {"source_code": "n = gets.to_i\narr = gets.chomp.split('').map(&:to_i)\n\nmin = arr.join.to_i\nmin_arr = arr\n\n(1..n).each do |i|\n temp_arr = arr.rotate i\n #p temp_arr\n diff = 10 - temp_arr.first\n temp_arr.map! {|x| (x+diff)%10}\n value = temp_arr.join.to_i\n if value < min\n min = value\n min_arr = temp_arr\n end\nend\nputs min_arr.join\n"}, {"source_code": "n = STDIN.readline.to_i\nx = STDIN.readline.strip\ndigits = x.split('')\n\nrot = {}\n10.times do |digit|\n rot[digit.to_s] = ((digit+1) % 10).to_s\nend\n\nnumbers = []\n10.times do\n n.times {|i| digits[i] = rot[digits[i]] }\n n.times do\n digits.rotate!\n numbers.push(digits.join)\n end\nend\nputs numbers.sort[0]\n"}, {"source_code": "\ngets\na = gets.rstrip.chars.map(&:to_i)\nputs (0..a.size-1).map{|i| (a + a)[i, a.size]}\n .map{|x| x.map{|y| (y + 10 - x[0]) % 10}}\n .map{|x| x.join('')}.min\n"}], "negative_code": [{"source_code": "def transform arr\n diff = 10 - arr.first\n arr = arr.map {|a| (a + diff)%10}\n arr\nend\n\nn = gets.to_i\narr = gets.chomp.split('').map(&:to_i)\nmin = Float::INFINITY\nnew_min_arr = arr\nnew_min = new_min_arr.join.to_i\nwhile new_min < min\n min_arr = new_min_arr\n min = new_min\n min_index,max_index = min_arr.each_with_index.minmax.collect{|x| x[1]}\n max_rot_arr = transform min_arr.rotate(max_index)\n min_rot_arr = min_arr.rotate(min_index)\n max_rot_arr_val = max_rot_arr.join.to_i\n min_rot_arr_val = min_rot_arr.join.to_i\n # p max_rot_arr\n # p min_rot_arr\n if max_rot_arr_val < min_rot_arr_val\n new_min_arr = max_rot_arr\n new_min = max_rot_arr_val\n else\n new_min_arr = min_rot_arr\n new_min_arr = min_rot_arr_val\n end\n #p new_min_arr\nend\n\nputs min_arr.join"}, {"source_code": "def transform arr\n diff = 10 - arr.first\n arr = arr.map {|a| (a + diff)%10}\n arr\nend\n\nn = gets.to_i\narr = gets.chomp.split('').map(&:to_i)\nmin = Float::INFINITY\nnew_min_arr = arr\nnew_min = new_min_arr.join.to_i\nwhile new_min < min\n min_arr = new_min_arr\n min = new_min\n min_index,max_index = min_arr.each_with_index.minmax.collect{|x| x[1]}\n max_rot_arr = transform min_arr.rotate(max_index)\n min_rot_arr = min_arr.rotate(min_index)\n max_rot_arr_val = max_rot_arr.join.to_i\n min_rot_arr_val = min_rot_arr.join.to_i\n # p max_rot_arr\n # p min_rot_arr\n if max_rot_arr_val < min_rot_arr_val\n new_min_arr = max_rot_arr\n new_min = max_rot_arr_val\n else\n new_min_arr = min_rot_arr\n new_min = min_rot_arr_val\n end\n #p new_min_arr\nend\n\nputs min_arr.join"}, {"source_code": "def transform arr\n diff = 10 - arr.first\n arr = arr.map {|a| (a + diff)%10}\n arr\nend\n\nn = gets.to_i\narr = gets.chomp.split('').map(&:to_i)\nmin = Float::INFINITY\nnew_min_arr = arr\nnew_min = new_min_arr.join.to_i\nwhile new_min < min\n min_arr = new_min_arr\n min = new_min\n max_index,min_index = min_arr.each_with_index.minmax.collect{|x| x[1]}\n max_rot_arr = transform min_arr.rotate(max_index)\n min_rot_arr = min_arr.rotate(min_index)\n max_rot_arr_val = max_rot_arr.join.to_i\n min_rot_arr_val = min_rot_arr.join.to_i\n if max_rot_arr_val < min_rot_arr_val\n new_min_arr = max_rot_arr\n new_min = max_rot_arr_val\n else\n new_min_arr = min_rot_arr\n new_min_arr = min_rot_arr_val\n end\nend\n\nputs min_arr.join"}, {"source_code": "def transform arr\n diff = 10 - arr.first\n arr = arr.map {|a| (a + diff)%10}\n arr\nend\n\ndef rotate arr,mode\n final_value = arr.join.to_i\n final_arr = arr\n (1..arr.size).each do |i|\n temp_arr = arr.rotate(i)\n if mode == \"max\"\n if final_value < temp_arr.join.to_i\n final_value = temp_arr.join.to_i\n final_arr = temp_arr\n end\n else\n if final_value > temp_arr.join.to_i\n final_value = temp_arr.join.to_i\n final_arr = temp_arr\n end\n end\n end\n final_arr\nend\n\nn = gets.to_i\narr = gets.chomp.split('').map(&:to_i)\nmin = Float::INFINITY\nnew_min_arr = arr\nnew_min = new_min_arr.join.to_i\nwhile new_min < min\n min_arr = new_min_arr\n min = new_min\n max_rot_arr = transform(rotate min_arr,\"max\")\n min_rot_arr = rotate min_arr,\"min\"\n max_rot_arr_val = max_rot_arr.join.to_i\n min_rot_arr_val = min_rot_arr.join.to_i\n # p max_rot_arr\n # p min_rot_arr\n if max_rot_arr_val < min_rot_arr_val\n new_min_arr = max_rot_arr\n new_min = max_rot_arr_val\n else\n new_min_arr = min_rot_arr\n new_min = min_rot_arr_val\n end\n #p new_min_arr\nend\n\nputs min_arr.join"}, {"source_code": "pa=Array.new\nstd=String.new\nn=gets.to_i\nstr=gets.to_s\n\nstd=str.clone\nfor i in 0..9\n stt=String.new\n min=0\n for j in 0..n-1\n pa[j]=(str[j].to_i+i)%10\n if pa[min]>pa[j]\n min=j\n end\n end\n# p pa\n for j in min..min+n-1\n stt << pa[j%n].to_s\n end\n# p stt\n if std > stt\n std=stt.clone\n end\nend\n\nputs std\n"}, {"source_code": "n=gets.to_i\nstr=gets.to_s\n\nmin=0\nfor i in 0..n-1\n if str[min]>str[i]\n min=i\n end\nend\nk=str[min].to_i\n\nfor i in min..min+n-1\n print str[i%n].to_i-k\nend\nputs\n"}], "src_uid": "6ee356f2b3a4bb88087ed76b251afec2"} {"source_code": "# wrap around the lights after the last green light\n# Eg: rrrgyyygy becomes: yrrrgyyyg\ndef wrap_lights(light_string)\n array = light_string.chars\n last_index = array.rindex('g') + 1\n array.rotate!(last_index)\n array.join\nend\n\n# create sequences of lights other than green Eg: yrrrgyyyg becomes: [yrrr, yyy]\ndef light_sequences(light_string)\n light_string.split('g')\n .reject(&:empty?)\nend\n\n# find best time for current light in a sequence\n# Eg: for light yellow in sequence yrrr it returns 4\ndef best_time(sequence, current_light)\n return nil if sequence.index(current_light).nil?\n\n sequence.length - sequence.index(current_light)\nend\n\n# finds the best time in an array of sequences\n# Eg the sequences [yrrr, yyy] returns 4\n# since yrrr has time 4 and yyy has time 3\ndef best_in_sequences(sequence_arr, current_light)\n times = sequence_arr.map { |sequence| best_time(sequence, current_light) }\n\n times.compact.max\nend\n\n# combines the above four methods\ndef best_from_string(light_string, current_light)\n return 0 if current_light == 'g'\n\n wrapped = wrap_lights(light_string)\n sequences = light_sequences(wrapped)\n best_in_sequences(sequences, current_light)\nend\n\n##### code for tests:\n\nnumber_of_cases = gets.chomp.to_i\n\nnumber_of_cases.times do\n current_light = gets.chomp.split[-1]\n light_string = gets.chomp\n puts best_from_string(light_string, current_light)\nend\n", "positive_code": [{"source_code": "ts = gets.to_i\r\nts.times do\r\n c = gets.split[1]\r\n s = gets.chomp\r\n ans = (s + s).split(\"g\").map{ |t| t.size - (t.index(c) || 10**9) }.max\r\n puts c == \"g\" ? 0 : ans\r\nend"}], "negative_code": [], "src_uid": "9d3ee1b292a2402bb2204ab85dcab587"} {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a 0\n n = gets.chomp.to_i\n arr = [1].concat(gets.chomp.split(' ').map { |x| x.to_i })\n\n result = Array.new(n+1, 1)\n i = 1\n while i <= n\n j = 2\n while i*j <= n\n result[i*j] = result[i] + 1 if arr[i*j] > arr[i] && result[i*j] <= result[i]\n j += 1\n end\n i += 1\n end\n\n puts result.max\n t -= 1\nend\n"}, {"source_code": "t = gets.chomp.to_i\n\nt.times do\n t2 = gets.chomp.to_i\n arr = gets.chomp.split(' ').collect(&:to_i)\n dp = Array.new(t2, 1)\n ans = 0\n for i in 1..t2\n j = i + i\n while true\n break if j > t2\n dp[j-1] = [dp[j-1], dp[i-1] + 1].max if arr[j-1] > arr[i-1]\n j += i\n end\n end\n puts dp.max\nend\n"}], "negative_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a= 1 && ((col - 1 - columns[index][colindex+1]).abs <= test[2] || (col > columns[index][colindex+1]))\t\n\t\t\tblocks_to_bag = [col, (col - columns[index][colindex+1] + test[2]).abs].min\n\t\t\ttest[1] = test[1] + blocks_to_bag\n\t\t\tcol = col - blocks_to_bag\n\t\telsif test[1] >= 1 && col < columns[index][colindex+1] && (col - columns[index][colindex+1]).abs > test[2]\n\t\t\tblocks_from_bag = [columns[index][colindex+1] - col - test[2], test[1]].min\n\t\t\tcolumns[index][colindex] = col = col + blocks_from_bag\n\n\t\t\ttests[index][1] = test[1] = test[1] - blocks_from_bag\n\t\tend\n\n\t\tif (col - columns[index][colindex+1]).abs <= test[2]\n\t\t\tnext\n\t\telse\n\t\t\tputs \"NO\"\n\t\t\tbreak\n\t\tend\n\n\tend\n\t\t\nend\n\n\n", "positive_code": [{"source_code": "\nT = gets.to_i\nT.times do\n\tn, m, k = gets.split.map(&:to_i)\n\tarr = gets.split.map(&:to_i)\n\tif n == 1\n\t\tputs \"YES\"\n\t\tnext\n\tend\n\tsucc = true\n\twhile arr.size > 1\n\t\tcur = arr.shift\n\t\tif arr[0] >= k\n\t\t\tfloor = arr[0] - k\n\t\telse\n\t\t\tfloor = 0\n\t\tend\n\t\tm += cur - floor\n\t\tif m < 0\n\t\t\tsucc = false\n\t\t\tbreak\n\t\tend\t\n\tend\n\tif succ\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\n"}], "negative_code": [{"source_code": "\nT = gets.to_i\nT.times do\n\tn, m, k = gets.split.map(&:to_i)\n\tarr = gets.split.map(&:to_i)\n\tif n == 1\n\t\tputs \"YES\"\n\t\tnext\n\tend\n\tsucc = true\n\twhile arr.size > 1\n\t\tcur = arr.shift\n\t\tif arr[0] - k > cur + m\n\t\t\tsucc = false\n\t\tend\n\t\tfloor = arr[0] - k\n\t\tif cur > floor\n\t\t\tm += cur - floor\n\t\telsif cur < floor\n\t\t\tm -= floor - cur\n\t\tend\n\t\tif m < 0\n\t\t\tsucc = false\n\t\tend\t\n\tend\n\tif succ\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ntest_no = Integer(gets)\n\ntests = Array.new (test_no)\ncolumns = Array.new (test_no) \n\ntest_no.times.each do |num|\n\ttests[num] = gets.chomp.split(\" \").map(&:to_i)\n\tcolumns[num] = gets.chomp.split(\" \").map(&:to_i)\nend\n\ntests.map!.with_index do |test, index|\n\t\n\tcolumns[index].map!.with_index do |col, colindex|\n\t\t\t\n \t\tif (test[0] == colindex + 1)\n\t\t\tputs \"YES\"\n\t\t\tbreak\n\t\tend\n\t\t\t\n\t\tif col >= 1 && ((col - 1 - columns[index][colindex+1]).abs <= test[2] || (col > columns[index][colindex+1]))\t\n\t\t\tblocks_to_bag = col - (test[2] - columns[index][colindex+1]).abs\n\t\t\ttest[1] = test[1] + blocks_to_bag\n\t\t\tcol = col - blocks_to_bag\n\t\telsif test[1] >= 1 && col < columns[index][colindex+1] && (col - columns[index][colindex+1]).abs > test[2]\n\t\t\tblocks_from_bag = [columns[index][colindex+1] - col - test[2], test[1]].min\n\t\t\tcolumns[index][colindex] = col = col + blocks_from_bag\n\n\t\t\ttests[index][1] = test[1] = test[1] - blocks_from_bag\n\t\tend\n\n\t\tif (col - columns[index][colindex+1]).abs <= test[2]\n\t\t\tnext\n\t\telse\n\t\t\tputs \"NO\"\n\t\t\tbreak\n\t\tend\n\n\tend\n\t\t\nend\n\n\n"}], "src_uid": "3f60e740d9a3ec14223b2b1f62c52f61"} {"source_code": "_ = gets\na = gets.strip.split(' ').map(&:to_i)\nb = gets.strip.split(' ').map(&:to_i)\n\nh = Hash.new(0)\nb.each_with_index { |e, i| h[e] = i }\n\nhash_shift = Hash.new(0)\na.each_with_index { |e, i|\n if i < h[e]\n hash_shift[e] = (a.size - h[e]) + i\n else\n hash_shift[e] = i - h[e]\n end\n}\n\nmx = -1\nan = Hash.new(0)\nhash_shift.each_value { |v| an[v] += 1; mx = [mx, an[v]].max }\nputs mx\n", "positive_code": [{"source_code": "def f(l1, l2, n)\n\tif l2 <= l1\n\t\treturn l1 - l2\n\tend\n\treturn n - l2 + l1\nend\n\nn = gets.to_i\nline1 = gets.split(' ').collect { |elem| elem.to_i}\nline2 = gets.split(' ').collect { |elem| elem.to_i}\n#[\"\", \"22\", \"14\", \"18\"].map(&:to_i)\nidx_line1 = Array.new(n)\nn.times do\n\t|idx|\n\tidx_line1[line1[idx]] = idx\nend\nm = {}\nmaxi = 0;\nn.times do\n\t|idx|\n\tval = f(idx_line1[line2[idx]], idx, n)\n\tif m[val] == nil\n\t\tm[val] = 1\n\telse\n\t\tm[val] += 1\n\tend\n\tmaxi = [maxi, m[val]].max\nend\n\nputs maxi\n"}, {"source_code": "_ = gets\na = gets.strip.split(' ').map(&:to_i)\nb = gets.strip.split(' ').map(&:to_i)\n\nh = Hash.new(0)\nb.each_with_index { |e, i| h[e] = i }\n\nhash_right = Hash.new(0)\nhash_left = Hash.new(0)\na.each_with_index { |e, i|\n if i < h[e]\n hash_right[e] = (a.size - h[e]) + i\n hash_left[e] = h[e] - i\n else\n hash_right[e] = i - h[e]\n hash_left[e] = (a.size - i) + h[e]\n end\n}\n\nhash_right_count = Hash.new(0)\nhash_left_count = Hash.new(0)\nmx = -1\nhash_right.each { |k, v|\n m1 = hash_right_count[v] += 1\n m2 = hash_left_count[hash_left[k]] += 1\n mx = [mx, m1, m2].max\n}\nputs mx\n\n"}], "negative_code": [], "src_uid": "eb1bb862dc2b0094383192f6998891c5"} {"source_code": "a, b, n = gets.split.map &:to_i\nn.times do\n\tl, t, m = gets.split.map &:to_i\n\td = t*m; f = a+(l-1)*b; k = l; x = 1000001\n\twhile(k < x) do\n mid = k+(x-k+1)/2; q = a+(mid-1)*b; sum = (f+q)*(mid-l+1)/2\n\t (t >= q && d >= sum)? (k = mid) : (x = mid-1)\n\tend\n\tputs (k == l and t < f)? (-1) : (k)\nend", "positive_code": [{"source_code": "a, b, n = gets.split.map(&:to_i)\n\ndef find_r (a, b, l, t, m, s, e)\n return e if s == e || t * m >= (e - l + 1) * (a + b * (e + l - 2) / 2.0)\n mid = (e + s + 1) / 2\n if t * m >= (mid - l + 1) * (a + b * (mid + l - 2) / 2.0)\n find_r(a, b, l, t, m, mid, e)\n else\n find_r(a, b, l, t, m, s, mid - 1)\n end\nend\n\nn.times do\n l, t, m = gets.split.map(&:to_i)\n if t < a + b * (l - 1)\n puts -1\n next\n end\n puts find_r(a, b, l, t, m, l, (t + b - a) / b)\nend\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\n\ndef find_r (a, b, l, t, m, s, e)\n return e if t * m >= (e - l + 1) * (a + b * (e + l - 2) / 2.0)\n return s - 1 if s == e;\n mid = (e + s) / 2;\n if t * m >= (mid - l + 1) * (a + b * (mid + l - 2) / 2.0)\n find_r(a, b, l, t, m, mid + 1, e)\n else\n find_r(a, b, l, t, m, s, mid)\n end\nend\n\nn.times do\n l, t, m = gets.split.map(&:to_i)\n if t < a + b * (l - 1)\n puts -1\n next\n end\n puts find_r(a, b, l, t, m, l, (t + b - a) / b)\nend\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\n\ndef si(a, b, i)\n a + b * (i - 1)\nend\n\nn.times do\n l, t, m = gets.split.map(&:to_i)\n\n if t < si(a, b, l)\n puts -1\n next\n end\n\n rl = l\n rr = (t + b - a) / b\n\n while rl != rr\n mid = (rl + rr + 1) / 2\n if t * m >= (si(a, b, l) + si(a, b, mid)) * (mid - l + 1) / 2\n rl = mid\n else\n rr = mid - 1\n end\n end\n puts rr\nend\n"}], "negative_code": [{"source_code": "a, b, n = gets.split.map(&:to_i)\n\ndef si(a, b, i)\n a + b * (i - 1)\nend\n\nn.times do\n l, t, m = gets.split.map(&:to_i)\n\n rl = l\n rr = (t + b - a) / b\n\n if t < si(a, b, l)\n puts -1\n next\n end\n\n while rl != rr\n if t * m >= (si(a, b, l) + si(a, b, rr)) * (rr - l + 1) / 2\n rl = (rl + rr + 1) / 2\n else\n rr = (rl + rr + 1) / 2\n end\n end\n puts rr\nend\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\n\ndef find_r (a, b, l, t, m, s, e)\n return s if s == e\n if t * m >= (e - l + 1) * (a + b * (e + l - 2) / 2.0)\n find_r(a, b, l, t, m, (e + s) / 2 + 1, e)\n else\n find_r(a, b, l, t, m, s, (e + s) / 2)\n end\nend\n\nn.times do\n l, t, m = gets.split.map(&:to_i)\n if t < a + b * (l - 1)\n puts -1\n next\n end\n puts find_r(a, b, l, t, m, l, ((t + b - a) / b))\nend\n"}], "src_uid": "89c97b6c302bbb51e9d5328c680a7ea7"} {"source_code": "n = gets.chomp.to_i\nar = Array.new\nfor i in 1..n-1\n\tfor j in i+1..n\n\t\tnext if i + 2 == j\n\t\tnext if (i % 2 == j % 2)\n\t\tar.push([i,j])\n\tend\nend\nputs ar.length\nar.each{|x| puts x[0].to_s + \" \" + x[1].to_s }\n", "positive_code": [{"source_code": "a=gets.to_i\nc=a/2\nd=(a+1)/2\np c*d\n(1..c).each{|i|\n(c+1..a).each{|j|\nputs \"#{i} #{j}\"\n}\n}"}, {"source_code": "a=gets.to_i\nc=a/2\nd=(a+1)/2\np c*d\n(1..c).each{|i|\n(c+1..a).each{|j|\nputs \"#{i} #{j}\"\n}\n}"}, {"source_code": "a=gets.to_i\nc=a/2\nd=(a+1)/2\np c*d\n(1..c).each{|i|\n(c+1..a).each{|j|\nputs \"#{i} #{j}\"\n}\n}\n"}, {"source_code": "a=gets.to_i\nc=a/2\nd=(a+1)/2\np c*d\n(1..c).each{|i|\n(c+1..a).each{|j|\nputs \"#{i} #{j}\"\n}\n}\n"}, {"source_code": "a=gets.to_i\nc=a/2\nd=(a+1)/2\np c*d\n(1..c).each{|i|\n(c+1..a).each{|j|\nputs \"#{i} #{j}\"\n}\n}\n"}, {"source_code": "a=gets.to_i\nc=a/2\nd=(a+1)/2\np c*d\n(1..c).each{|i|\n(c+1..a).each{|j|\nputs \"#{i} #{j}\"\n}\n}\n"}, {"source_code": "n = gets.to_i\np = n/2\nputs p*(n-p)\nfor i in 1..p do\n for j in p+1..n do\n printf(\"%d %d\\n\", i, j)\n end\nend\n"}, {"source_code": "a=gets.to_i\nc=a/2\nd=(a+1)/2\np c*d\n(1..c).each{|i|\n(c+1..a).each{|j|\nputs \"#{i} #{j}\"\n}\n}\n"}, {"source_code": "a=gets.to_i\nc=a/2\nd=(a+1)/2\np c*d\n(1..c).each{|i|\n(c+1..a).each{|j|\nputs \"#{i} #{j}\"\n}\n}\n"}, {"source_code": "a=gets.to_i\nc=a/2\nd=(a+1)/2\np c*d\n(1..c).each{|i|\n(c+1..a).each{|j|\nputs \"#{i} #{j}\"\n}\n}\n"}, {"source_code": "a=gets.to_i\nc=a/2\nd=(a+1)/2\np c*d\n(1..c).each{|i|\n(c+1..a).each{|j|\nputs \"#{i} #{j}\"\n}\n}\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nar = Array.new\nfor i in 1..n-1\n\tfor j in i+1..n\n\t\tnext if i + 2 == j\n\t\tif n > 3\n\t\t\tnext if (i == 2 && j == n) || (i == 1 && j == n-1) \n\t\tend\n\t\tnext if i > 1 && (i % 2 == j % 2)\n\t\tar.push([i,j])\n\tend\nend\nputs ar.length\nar.each{|x| puts x[0].to_s + \" \" + x[1].to_s }\n"}, {"source_code": "n = gets.chomp.to_i\nar = Array.new\nfor i in 1..n-1\n\tfor j in i+1..n\n\t\tnext if i + 2 == j\n\t\tif n > 3\n\t\t\tnext if (i == 2 && j == n) || (i == 1 && j == n-1) \n\t\tend\n\t\tar.push([i,j])\n\tend\nend\nputs ar.length\nar.each{|x| puts x[0].to_s + \" \" + x[1].to_s }\n"}], "src_uid": "3f86b3cec02aafb24c5aeb2648cc3df9"} {"source_code": "# require 'pry'\n\nt = gets.to_i\nt.times do\n n = gets.to_i\n min = nil\n res = 0\n gets.split.map(&:to_i).reverse_each do |num|\n res += 1 if min && min < num\n min = num if min.nil? || num < min\n end\n puts res\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tmin = 10**9\n\tputs a.reverse.count { |i|\n\t\t\tres = min < i\n\t\t\tmin = [min, i].min\n\t\t\tres\n\t }\nend\n"}, {"source_code": "t = gets.to_i\nt.times do \n n = gets.to_i\n arr = gets.split.map(&:to_i)\n min = nil\n count = 0\n arr.reverse_each do |x|\n min = x if min.nil? || x < min\n count += 1 if x > min\n end\n puts count\nend\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\nPrice = Struct.new(:price, :day)\nt = gets.to_i\nt.times {\n n = gets.to_i\n a = []\n gets.split.each_with_index { |price, day_zero|\n a << Price.new(price.to_i, day_zero+1)\n }\n # non-descending order\n a.sort! { |e1, e2|\n if e1.price != e2.price\n e1.price - e2.price\n else\n e1.day - e2.day\n end\n }\n # \uc0ac\uc6a9 \uac00\ub2a5\ud55c factor: price-day (value-index)\n bads = 0\n pday = 0\n for i in a\n if pday <= i.day\n pday = i.day\n else\n bads += 1\n end\n end\n\n puts bads\n}"}, {"source_code": "t=gets.to_i\nfor j in 0...t do\n n=gets.to_i\n a=Array.new()\n for i in 0...n-1 do\n a.unshift(gets(sep=' ').to_i)\n end\n d=0\n a.unshift(gets.to_i)\n mn=a[0]\n for i in 1...n do\n if a[i]>mn then\n d+=1\n else\n mn=a[i]\n end\n end\n puts d\nend"}, {"source_code": "t=gets.to_i\nfor j in 0...t do\n n=gets.to_i\n a=Array.new(n-1)\n for i in 0...n-1 do\n a[i]=gets(sep=' ').to_i\n end\n d=0\n a.push(gets.to_i)\n mn=a.last\n for i in (0...n).reverse_each do\n if a[i]>mn then\n d+=1\n else\n mn=a[i]\n end\n end\n puts d\nend"}, {"source_code": "def solve\nend\n\ngets.strip.to_i.times do\n n = gets.strip.to_i\n days = gets.strip.split(' ').map(&:to_i)\n days.reverse!\n last = days[0]\n res = 0\n days.each do |d|\n if d > last\n res += 1\n end\n last = [last, d].min\n end\n puts res\nend"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n suf_min = 1E100.to_i\n res = 0\n (0...n).reverse_each do |i|\n res += 1 if a[i] > suf_min\n suf_min = [suf_min, a[i]].min\n end\n puts res\nend"}, {"source_code": "tt = gets.to_i\ntt.times do |t|\n nn = gets.to_i\n aa = gets.split.map(&:to_i)\n\n cnt = 0\n min = aa[-1]\n (nn-2).downto(0) do |n|\n if aa[n] > min\n cnt+=1\n else\n min = aa[n]\n end\n end\n puts cnt\nend"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\nPrice = Struct.new(:price, :day)\nt = gets.to_i\nt.times {\n n = gets.to_i\n a = []\n gets.split.each_with_index { |price, day_zero|\n a << Price.new(price.to_i, day_zero)\n }\n # non-descending order\n a.sort! { |e1, e2|\n e1.price - e2.price\n }\n # \uc0ac\uc6a9 \uac00\ub2a5\ud55c factor: price-day (value-index)\n bads = 0\n pday = 0\n for i in a\n if pday <= i.day\n pday = i.day\n else\n bads += 1\n end\n end\n\n puts bads\n}"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\nPrice = Struct.new(:price, :day)\nt = gets.to_i\nt.times {\n n = gets.to_i\n a = []\n gets.split.each_with_index { |price, day_zero|\n a << Price.new(price.to_i, day_zero+1)\n }\n # non-descending order\n a.sort! { |e1, e2|\n e1.price - e2.price\n }\n # \uc0ac\uc6a9 \uac00\ub2a5\ud55c factor: price-day (value-index)\n bads = 0\n pday = 0\n for i in a\n if pday < i.day\n pday = i.day\n else\n bads += 1\n end\n end\n\n puts bads\n}"}], "src_uid": "09faf19627d2ff00c3821d4bc2644b63"} {"source_code": "vs = Array.new(55){Array.new(55, 0)}\nrv = Array.new(55){Array.new(55, 0)}\nl = Array.new(2502)\nlx = Array.new(2502)\nly = Array.new(2502)\ndef ff(vs, rv, x, y)\n\tdx = [1, 0, -1, 0]\n\tdy = [0, 1, 0, -1]\n\tfx = Array.new(2502)\n\tfy = Array.new(2502)\n\tr = 1\n\tt = 2\n\tcnt = 0\n\tfx[r] = x\n\tfy[r] = y\n\tvs[x][y] = '*'\n\trv[x][y] = 15\n\twhile r != t\n\t\tx = fx[r]\n\t\ty = fy[r]\n\t\tr += 1\n\t\tcnt += 1\n\t\tfor o in (0..3)\n\t\t\tnx = x + dx[o]\n\t\t\tny = y + dy[o]\n\t\t\tif vs[nx][ny] == '.'\n\t\t\t\tvs[nx][ny] = '*'\n\t\t\t\trv[nx][ny] = 15\n\t\t\t\tfx[t] = nx\n\t\t\t\tfy[t] = ny\n\t\t\t\tt += 1\n\t\t\tend\n\t\tend\n\tend\n\treturn cnt\nend\nipt = gets.split(' ')\nn = ipt[0].to_i\nm = ipt[1].to_i\nk = ipt[2].to_i\nfor i in (1..n)\n\tipt = 'Z'\n\tipt += gets\n\tvs[i] = ipt\nend\nfor i in (1..m)\n\tif vs[1][i] == '.'\n\t\tff(vs, rv, 1, i)\n\tend\n\tif vs[n][i] == '.'\n\t\tff(vs, rv, n, i)\n\tend\nend\nfor i in (1..n)\n\tif vs[i][1] == '.'\n\t\tff(vs, rv, i, 1)\n\tend\n\tif vs[i][m] == '.'\n\t\tff(vs, rv, i, m)\n\tend\nend\nlcnt = 0\nfor i in (1..n)\n\tfor j in (1..m)\n\t\tif vs[i][j] == '.'\n\t\t\tlcnt = lcnt + 1\n\t\t\tl[lcnt] = ff(vs, rv, i, j)\n\t\t\tlx[lcnt] = i\n\t\t\tly[lcnt] = j\n\t\tend\n\tend\nend\nfor i in (1..lcnt)\n\tfor j in (i+1..lcnt)\n\t\tif l[i] < l[j]\n\t\t\tt = l[i]\n\t\t\tl[i] = l[j]\n\t\t\tl[j] = t\n\t\t\tt = lx[i]\n\t\t\tlx[i] = lx[j]\n\t\t\tlx[j] = t\n\t\t\tt = ly[i]\n\t\t\tly[i] = ly[j]\n\t\t\tly[j] = t\n\t\tend\n\tend\nend\nfor i in (1..n)\n\tfor j in (1..m)\n\t\tif rv[i][j] == 15\n\t\t\tvs[i][j] = '.'\n\t\tend\n\tend\nend\nsum = 0\nfor k in (k+1..lcnt)\n\tsum += ff(vs, rv, lx[k], ly[k])\nend\nputs sum\nfor i in (1..n)\n\tfor j in (1..m)\n\t\tprint vs[i][j]\n\tend\n\tprint \"\\n\"\nend", "positive_code": [{"source_code": "$n, $m, k = gets.split.map(&:to_i)\n$map = $n.times.map{gets.chomp}\n$vis = Array.new($n){Array.new($m, false)}\n$lake = []\n\ndef dfs(x, y)\n return if x >= $n || y >= $m || x < 0 || y < 0\n return if $vis[x][y]\n return if $map[x][y] == '*'\n $lake << [x, y]\n $vis[x][y] = true\n\n dfs(x + 1, y)\n dfs(x - 1, y)\n dfs(x, y + 1)\n dfs(x, y - 1)\nend\n\ndef get_lake(x, y)\n $lake = []\n dfs(x, y)\n return $lake\nend\n\nlakes = []\n$n.times do |i|\n $m.times do |j|\n next if $map[i][j] == '*'\n lakes << get_lake(i, j)\n end\nend\n\ndef is_ocean?(lake)\n lake.any? do |x, y|\n x == $n - 1 || x == 0 || y == $m - 1 || y == 0\n end\nend\n\nlakes = lakes.reject{|x| is_ocean?(x)}.sort_by(&:size)\nans = 0\nwhile lakes.size > k\n lake = lakes.shift\n ans += lake.size\n lake.each{|x, y| $map[x][y] = '*'}\nend\n\np ans\nputs $map\n"}, {"source_code": "def dfs(s, visited, map, path, start)\n k, j = s\n visited[s] = true\n\n list = []\n list.push([k, j - 1]) if j - 1 >= 0\n list.push([k, j + 1]) if j + 1 < map[0].length\n list.push([k - 1, j]) if k - 1 >= 0\n list.push([k + 1, j]) if k + 1 < map.length\n\n for i, j in list\n if !visited[[i, j]] && map[i][j] == \".\"\n path[start] << [i, j]\n dfs([i, j], visited, map, path, start)\n end\n end\nend\n\nn, m, l = gets.chomp.split.map(&:to_i)\nmap = Hash.new { |hash, key| hash[key] = nil }\n\nn.times do |i|\n map[i] = gets.chomp.split(\"\")\nend\n\nif map.values.join == \".\" * (n * m)\n puts 0\n for i in 0..(n - 1)\n print *map[i]\n puts\n end\nelse\n visited = Hash.new { |hash, key| hash[key] = false }\n path = Hash.new { |hash, key| hash[key] = [] }\n\n for k, v in map\n for j in 0..(v.length - 1)\n if !visited[[k, j]] && v[j] == \".\"\n path[[k, j]] << [k, j]\n dfs([k, j], visited, map, path, [k, j])\n end\n end\n end\n\n result = Hash.new { |hash, key| hash[key] = [] }\n for k, v in path\n v.push(k)\n\n flag = true\n for i, j in v\n if i == 0 || i == n - 1 || j == 0 || j == m - 1\n break flag = false\n end\n end\n\n result[v] = v.length - 1 if flag\n end\n\n groups = result.keys.count\n sizes = result.sort_by { |_k, v| v }\n\n min_groups = groups - l\n min = 0\n\n index = []\n min_groups.times do |i|\n min += sizes[i][1]\n index << sizes[i][0]\n end\n\n puts min\n for v in index\n for i, j in v\n map[i][j] = \"*\"\n end\n end\n for i in 0..(n - 1)\n print *map[i]\n puts\n end\nend\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\n@land = []\nn.times do |i|\n @land[i] = gets.chomp.split('')\nend\n@n, @m = n, m\n\n# def bfs(r, c)\n# return [] unless @land[r][c] == '.'\n# arr = [[r, c]]\n# @land[r][c] = '#'\n# [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |ud, lr|\n# rr, cc = r + ud, c + lr\n# next if rr < 0 || rr >= @n || cc < 0 || cc >= @m\n# arr += bfs(rr,cc)\n# end\n# arr\n# end\n\ndef bfs(r, c)\n return [] unless @land[r][c] == '.'\n arr = [[r, c]]\n @land[r][c] = '#'\n answer = []\n while !arr.empty? do\n r, c = arr.pop\n answer << [r, c]\n [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |ud, lr|\n rr, cc = r + ud, c + lr\n next if rr < 0 || rr >= @n || cc < 0 || cc >= @m\n next unless @land[rr][cc] == '.'\n arr << [rr, cc]\n @land[rr][cc] = '#'\n end\n end\n answer\nend\n\nn.times { |r| [0, m - 1].each { |c| bfs(r, c) } }\nm.times { |c| [0, n - 1].each { |r| bfs(r, c) } }\n\nlakes = []\n(1...(n-1)).each do |r|\n (1...(m-1)).each do |c|\n lake = bfs(r, c)\n next if lake.empty?\n lakes << lake\n end\nend\n\nlakes.sort_by!(&:size)\ncount = 0\nlakes[0...(lakes.size - k)].each do |lake|\n lake.each { |r, c| @land[r][c] = '*'; count += 1 }\nend\n@land.each { |row| row.map! { |x| x == '#' ? '.' : x } }\n\nputs count\n@land.each do |row|\n puts row.join\nend\n"}, {"source_code": "vs = Array.new(55){Array.new(55, 0)}\nrv = Array.new(55){Array.new(55, 0)}\nl = Array.new(2502)\nlx = Array.new(2502)\nly = Array.new(2502)\ndef ff(vs, rv, x, y)\n\tdx = [1, 0, -1, 0]\n\tdy = [0, 1, 0, -1]\n\tfx = Array.new(2502)\n\tfy = Array.new(2502)\n\tr = 1\n\tt = 2\n\tcnt = 0\n\tfx[r] = x\n\tfy[r] = y\n\tvs[x][y] = '*'\n\trv[x][y] = 15\n\twhile r != t\n\t\tx = fx[r]\n\t\ty = fy[r]\n\t\tr += 1\n\t\tcnt += 1\n\t\tfor o in (0..3)\n\t\t\tnx = x + dx[o]\n\t\t\tny = y + dy[o]\n\t\t\tif vs[nx][ny] == '.'\n\t\t\t\tvs[nx][ny] = '*'\n\t\t\t\trv[nx][ny] = 15\n\t\t\t\tfx[t] = nx\n\t\t\t\tfy[t] = ny\n\t\t\t\tt += 1\n\t\t\tend\n\t\tend\n\tend\n\treturn cnt\nend\nipt = gets.split(' ')\nn = ipt[0].to_i\nm = ipt[1].to_i\nk = ipt[2].to_i\nfor i in (1..n)\n\tipt = 'Z'\n\tipt += gets\n\tvs[i] = ipt\nend\nfor i in (1..m)\n\tif vs[1][i] == '.'\n\t\tff(vs, rv, 1, i)\n\tend\n\tif vs[n][i] == '.'\n\t\tff(vs, rv, n, i)\n\tend\nend\nfor i in (1..n)\n\tif vs[i][1] == '.'\n\t\tff(vs, rv, i, 1)\n\tend\n\tif vs[i][m] == '.'\n\t\tff(vs, rv, i, m)\n\tend\nend\nlcnt = 0\nfor i in (1..n)\n\tfor j in (1..m)\n\t\tif vs[i][j] == '.'\n\t\t\tlcnt = lcnt + 1\n\t\t\tl[lcnt] = ff(vs, rv, i, j)\n\t\t\tlx[lcnt] = i\n\t\t\tly[lcnt] = j\n\t\tend\n\tend\nend\nfor i in (1..lcnt)\n\tfor j in (i+1..lcnt)\n\t\tif l[i] < l[j]\n\t\t\tt = l[i]\n\t\t\tl[i] = l[j]\n\t\t\tl[j] = t\n\t\t\tt = lx[i]\n\t\t\tlx[i] = lx[j]\n\t\t\tlx[j] = t\n\t\t\tt = ly[i]\n\t\t\tly[i] = ly[j]\n\t\t\tly[j] = t\n\t\tend\n\tend\nend\nfor i in (1..n)\n\tfor j in (1..m)\n\t\tif rv[i][j] == 15\n\t\t\tvs[i][j] = '.'\n\t\tend\n\tend\nend\nsum = 0\nfor k in (k+1..lcnt)\n\tsum += ff(vs, rv, lx[k], ly[k])\nend\nputs sum\nfor i in (1..n)\n\tfor j in (1..m)\n\t\tprint vs[i][j]\n\tend\n\tprint \"\\n\"\nend"}], "negative_code": [{"source_code": "n, m, k = gets.split.map(&:to_i)\n@land = []\nn.times do |i|\n @land[i] = gets.chomp.split('')\nend\n@n, @m = n, m\n\ndef bfs(r, c)\n return unless @land[r][c] == '.'\n (arr = []) << [r, c]\n lake = []\n while !arr.empty?\n r, c = arr.shift\n lake << [r, c]\n @land[r][c] = '#'\n [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |ud, lr|\n rr, cc = r + ud, c + lr\n next if rr < 0 || rr >= @n || cc < 0 || cc >= @m\n next unless @land[rr][cc] == '.'\n arr << [rr, cc]\n end\n end\n lake\nend\n\nn.times { |r| [0, m - 1].each { |c| bfs(r, c) } }\nm.times { |c| [0, n - 1].each { |r| bfs(r, c) } }\n\nlakes = []\n(1...(n-1)).each do |r|\n (1...(m-1)).each do |c|\n lake = bfs(r, c)\n next if lake.nil? || lake.empty?\n lakes << lake\n end\nend\n\nlakes.sort! { |l| l.size }\ncount = 0\nlakes[0...(lakes.size - k)].each do |lake|\n lake.each { |r, c| @land[r][c] = '*'; count += 1 }\nend\n@land.each { |row| row.map! { |x| x == '#' ? '.' : x } }\n\nputs count\n@land.each do |row|\n puts row.join\nend\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\n@land = []\nn.times do |i|\n @land[i] = gets.chomp.split('')\nend\n\n@n, @m = n, m\n\ndef dfs(r, c)\n return [] if @land[r][c] == '*' || @land[r][c] == '#'\n raise if (r == 0 or r == @n - 1 or c == 0 or c == @m - 1) && @land[r][c] == '.'\n @land[r][c] = '#'\n [[r, c]] + dfs(r + 1, c) + dfs(r - 1, c) + dfs(r, c - 1) + dfs(r, c + 1)\nend\n\nlakes = []\n\n(1...(n-1)).each do |r|\n (1...(m-1)).each do |c|\n begin\n lake = dfs(r, c)\n next if lake.empty?\n lakes << lake\n rescue\n next\n end\n end\nend\n\nlakes = lakes.sort { |l| -l.size }\ncount = 0\n(k...(lakes.size)).each do |i|\n lakes[i].each { |r, c| @land[r][c] = '*'; count += 1 }\nend\n@land.each { |row| row.map! { |c| c == '#' ? '.' : c } }\n\nputs count\n@land.each do |row|\n puts row.join\nend\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\n@land = []\nn.times do |i|\n @land[i] = gets.chomp.split('')\nend\n@n, @m = n, m\n\ndef bfs(r, c)\n return [] unless @land[r][c] == '.'\n (arr = []) << [r, c]\n @land[r][c] = '#'\n [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |ud, lr|\n rr, cc = r + ud, c + lr\n next if rr < 0 || rr >= @n || cc < 0 || cc >= @m\n arr += bfs(rr,cc)\n end\n arr\nend\n\nn.times { |r| [0, m - 1].each { |c| bfs(r, c) } }\nm.times { |c| [0, n - 1].each { |r| bfs(r, c) } }\n\nlakes = []\n(1...(n-1)).each do |r|\n (1...(m-1)).each do |c|\n lake = bfs(r, c)\n next if lake.empty?\n lakes << lake\n end\nend\n\nlakes.sort! { |l| l.size }\ncount = 0\nlakes[0...(lakes.size - k)].each do |lake|\n lake.each { |r, c| @land[r][c] = '*'; count += 1 }\nend\n@land.each { |row| row.map! { |x| x == '#' ? '.' : x } }\n\nputs count\n@land.each do |row|\n puts row.join\nend\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\n@land = []\nn.times do |i|\n @land[i] = gets.chomp.split('')\nend\n\n@n, @m = n, m\n\ndef dfs(r, c)\n return [] if @land[r][c] == '*' || @land[r][c] == '#'\n return nil if (r == 0 or r == @n - 1 or c == 0 or c == @m - 1) && @land[r][c] == '.'\n @land[r][c] = '#'\n ans = [[r, c]]\n [[r + 1, c], [r - 1, c], [r, c - 1], [r, c + 1]].each do |rr, cc|\n d = dfs(rr, cc)\n if d.nil?\n ans.each { |r, c| @land[r][c] = '.' }\n return\n else\n ans += d\n end\n end\n ans\nend\n\nlakes = []\n\n(1...(n-1)).each do |r|\n (1...(m-1)).each do |c|\n begin\n lake = dfs(r, c)\n next if lake.nil? || lake.empty?\n lake.each { |r, c| }\n lakes << lake\n rescue\n next\n end\n end\nend\n\nlakes.sort! { |l| -l.size }\ncount = 0\n(k...(lakes.size)).each do |i|\n lakes[i].each { |r, c| @land[r][c] = '*'; count += 1 }\nend\n@land.each { |row| row.map! { |c| c == '#' ? '.' : c } }\n\nputs count\n@land.each do |row|\n puts row.join\nend\n"}, {"source_code": "def dfs(s, visited, map, path, start)\n k, j = s\n visited[s] = true\n\n list = []\n list.push([k, j - 1]) if j - 1 >= 0 && map[k][j - 1] == \".\"\n list.push([k, j + 1]) if j + 1 < map[0].length && map[k][j + 1] == \".\"\n list.push([k - 1, j]) if k - 1 >= 0 && map[k - 1][j] == \".\"\n list.push([k + 1, j]) if k + 1 < map.length && map[k + 1][j] == \".\"\n\n for i, j in list\n if !visited[[i, j]]\n path[start] << [i, j]\n dfs([i, j], visited, map, path, start)\n end\n end\nend\n\nn, m, l = gets.chomp.split.map(&:to_i)\nmap = Hash.new { |hash, key| hash[key] = nil }\n\nn.times do |i|\n map[i] = gets.chomp.split(\"\")\nend\n\nvisited = Hash.new { |hash, key| hash[key] = false }\npath = Hash.new { |hash, key| hash[key] = [] }\n\nfor k, v in map\n for j in 0..(v.length - 1)\n if !visited[[k, j]] && v[j] == \".\"\n path[[k, j]] << [k, j]\n dfs([k, j], visited, map, path, [k, j])\n end\n end\nend\n\nresult = Hash.new { |hash, key| hash[key] = [] }\nfor k, v in path\n v.push(k)\n\n flag = true\n for i, j in v\n if i == 0 || i == n - 1 || j == 0 || j == m - 1\n break flag = false\n end\n end\n\n result[k] = v.length - 1 if flag\nend\n\ngroups = result.keys.count\nsizes = result.sort_by { |_k, v| v }\n\nmin_groups = groups - l\nmin = 0\n\nindex = []\nmin_groups.times do |i|\n min += sizes[i][1]\n index << sizes[i][0]\nend\n\nfor i, j in index\n map[i][j] = \"*\"\nend\n\nputs min\nfor i in 0..(n - 1)\n print *map[i]\n puts\nend\n"}, {"source_code": "def dfs(s, visited, map, path, start)\n k, j = s\n visited[s] = true\n\n list = []\n list.push([k, j - 1]) if j - 1 >= 0 && map[k][j - 1] == \".\"\n list.push([k, j + 1]) if j + 1 < map[0].length && map[k][j + 1] == \".\"\n list.push([k - 1, j]) if k - 1 >= 0 && map[k - 1][j] == \".\"\n list.push([k + 1, j]) if k + 1 < map.length && map[k + 1][j] == \".\"\n\n for i, j in list\n if !visited[[i, j]]\n path[start] << [i, j]\n dfs([i, j], visited, map, path, start)\n end\n end\nend\n\nn, m, l = gets.chomp.split.map(&:to_i)\nmap = Hash.new { |hash, key| hash[key] = nil }\n\nn.times do |i|\n map[i] = gets.chomp.split(\"\")\nend\n\nvisited = Hash.new { |hash, key| hash[key] = false }\npath = Hash.new { |hash, key| hash[key] = [] }\n\nfor k, v in map\n for j in 0..(v.length - 1)\n if !visited[[k, j]] && v[j] == \".\"\n path[[k, j]] << [k, j]\n dfs([k, j], visited, map, path, [k, j])\n end\n end\nend\n\nresult = Hash.new { |hash, key| hash[key] = [] }\nfor k, v in path\n v.push(k)\n\n flag = true\n for i, j in v\n if i == 0 || i == n - 1 || j == 0 || j == m - 1\n break flag = false\n end\n end\n\n result[k] = v.length - 1 if flag\nend\n\ngroups = result.keys.count\nsizes = result.sort_by { |_k, v| v }\n\nmin_groups = groups - l\nmin = 0\n\nindex = []\nmin_groups.times do |i|\n min += sizes[i][1]\n index << sizes[i][0]\nend\nputs min\n\nfor i, j in index\n map[i][j] = \"*\"\nend\n\nfor i in 0..(n - 1)\n print *map[i]\n puts\nend\n"}, {"source_code": "def dfs(s, map, visited, path, start)\n k, j = s\n visited[s] = true\n\n list = [[k, j - 1], [k, j + 1], [k - 1, j], [k + 1, j]]\n\n for i, j in list\n if !visited[[i, j]] && map[i][j] == \".\"\n path[start] += 1\n dfs([i, j], map, visited, path, start)\n end\n end\nend\n\nn, m, l = gets.chomp.split.map(&:to_i)\n\nmap = Hash.new { |hash, key| hash[key] = [] }\nmap_2 = Hash.new { |hash, key| hash[key] = [] }\n\nn.times do |i|\n row = gets.chomp.split(\"\")\n map[i] = row\n map_2[i] = row.dup\nend\n\nfor i in 0..(n - 1)\n for j in 0..(m - 1)\n if (i == 0 || i == n - 1 || j == 0 || j == m - 1) && map[i][j] == \".\"\n map[i][j] = \"*\"\n map[i][j + 1] = \"*\" if j + 1 < m\n map[i][j - 1] = \"*\" if j - 1 >= 0\n map[i + 1][j] = \"*\" if i + 1 < n\n map[i - 1][j] = \"*\" if i - 1 >= 0\n end\n end\nend\n\nvisited = Hash.new { |hash, key| hash[key] = false }\npath = Hash.new { |hash, key| hash[key] = 0 }\n\nfor k, v in map\n for j in 0..(v.length - 1)\n if !visited[[k, j]] && v[j] == \".\"\n path[[k, j]] += 1\n dfs([k, j], map, visited, path, [k, j])\n end\n end\nend\n\ngroups = path.keys.count\nsizes = path.sort_by { |_k, v| v }\n\nmin_groups = groups - l\nmin = 0\n\nindex = []\nmin_groups.times do |i|\n min += sizes[i][1]\n index << sizes[i][0]\nend\n\nfor i, j in index\n map_2[i][j] = \"*\"\nend\n\nputs min\nfor i in 0..(n - 1)\n print *map_2[i]\n puts\nend\n"}], "src_uid": "e514d949e7837c603a9ee032f83b90d2"} {"source_code": "puts gets.sub /(.+?)0|./,'\\1'\n", "positive_code": [{"source_code": "n = gets.chomp.chars.to_a\nif i = n.index(\"0\")\n n.delete_at i\nelse\n n.delete_at 0\nend\nputs n.join\n"}, {"source_code": "a = gets\nb = \"\"\nf = false\na.each_char do |c|\n b << c if f || c == '1'\n f = true if c == '0'\nend\nb.chop! unless f\n\nputs b\n"}, {"source_code": "s = gets\n\nif s.match(/^0+$/) or s.match(/^1+$/) or s.match(/^0+1*$/)\n puts s[1..-1]\nelse\n s =~ /^(0*)(1+)0(.*)$/\n puts $1 + $2 + $3\nend\n"}, {"source_code": "a = gets.strip\n\nok = false\n\nif a == '1' * a.size\n\tprint '1' * (a.size-1)\nelse\n\ta.each_char do |c|\n\t\tif ok or c == '1'\n\t\t\tprint c\n\t\telsif c == '0'\n\t\t\tok = true\n\t\tend\n\tend\nend"}, {"source_code": "puts gets.chomp.sub(/0|1$/,'')"}, {"source_code": "=begin\nDear online judge:\nI've wasted time reading the problem and trying to figure out the solution\nIf you insist on the penalty system, please don't include the time of debugging\nI hope my code compile and get accepted. KEE O.o\n ____________\n / __ \\\n / __ | | \\\n / |__| | | \\\n ( |__| )\n \\ /\n \\ ___ /\n \\____________/\n=end\n\nclass Solve\n def solve()\n $str = gets.chomp\n $res = \"\"\n $found = 0\n for $i in 0..($str.size() - 1)\n if $found == 1 || $str[$i] != '0'\n $res<<$str[$i]\n else\n $found = 1\n end\n end\n if $found == 0\n $res.chop!\n end\n puts $res\n end\nend\n\n\n\nSolve.new.solve"}, {"source_code": "str = gets.chomp\nn = str.index(\"0\")\nif n then\n str = str[0...n] + str[n+1..-1]\nelse\n str = str[0...-1]\nend\nputs str"}, {"source_code": "a = gets\na.sub!('1', '') unless a.sub!('0', '')\nputs a\n"}, {"source_code": "puts gets.sub /(.+?)0|./,'\\1'"}, {"source_code": "#!/usr/bin/ruby\n\ns = gets\npos = s.index('0') || 0\nputs s[0...pos] + s[pos+1..-1]\n"}, {"source_code": "puts gets.sub /(.+?)0|./,'\\1'\n"}, {"source_code": "puts gets.chomp.sub(/0|1$/,'')"}, {"source_code": "puts gets.sub /(.+?)0|./,'\\1'\n"}, {"source_code": "puts gets.sub /(.+?)0|./,'\\1'"}, {"source_code": "s = gets.strip\ni = s.index(\"0\"); i = 0 if i == nil\ns[i] = \"\"\nputs s"}, {"source_code": "s = gets\np = s.index \"0\"\nif p != nil\n s[p, s.size] = s[p+1, s.size];\nelse\n s[s.size - 2, 2] = s[s.size-1, 2]\nend\nputs s\n "}, {"source_code": "def run\n ARGF.readlines.each do |line|\n line.chomp!\n i = line.index('0') || 0\n puts line[0, i] + line[i + 1, line.length - i - 1]\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "s=gets.chomp\n\ns.length.times { |i|\n if s[i]==?0\n s[i]=''\n puts s\n exit\n end\n}\n\ns[-1]=''\nputs s\n"}, {"source_code": "s=gets\ns.sub!('1','') unless s.sub!('0','')\nputs s\n"}, {"source_code": "puts gets.sub /(.+?)0|./,'\\1'\n"}, {"source_code": "s = gets.chomp\nn = s.length\n(0..n).each do |i|\n\tif i == n\n\t\tputs s[1..n-1]\n\telsif s[i] == '0'\n\t\tprint s[0..i-1]\n\t\tprint s[i+1..n-1]\n\t\tbreak\n\tend\nend"}, {"source_code": "puts gets.sub /(.+?)0|./,'\\1'\n"}, {"source_code": "s=gets.chomp\nn1=0\nn2=0\nif s.size>1 && s.index(\"0\") then\n\tn1=s.sub(\"0\",\"\").to_i(2)\nend\nif s.size>1 && s.rindex(\"1\") then\n\tn2=s.reverse.sub(\"1\",\"\").reverse.to_i(2)\nend\nputs [n1,n2].max.to_s(2)\n\n"}, {"source_code": "a = gets.chomp.chars.map(&:to_i)\nif a.include?(0)\n a[a.find_index{|x| x == 0}] = nil\nelse\n a[0] = nil\nend\nputs a.join(\"\")\n"}, {"source_code": "binary = gets.strip.split('')\nif binary.index('0')\n binary.delete_at binary.index('0')\nelse\n binary.delete_at 0\nend\nputs binary.join\n"}, {"source_code": "a = gets.chomp\nputs a.sub(a['0'] || '1', '')\n"}, {"source_code": "# coding: utf-8\n\ns = gets.chomp\npos_zero = s.index('0')\n\nif pos_zero == nil\n puts s[0...-1]\nelse\n puts \"#{s[0...pos_zero]}#{s[(pos_zero+1)..-1]}\"\nend"}, {"source_code": "s = gets.strip\ni = s.index(\"0\")\nn = s.length\nif i.nil?\n puts s[1...n]\nelse\n puts (s[0...i] + s[(i + 1)...n]) \nend"}, {"source_code": "puts gets.sub /(.+?)0|./,'\\1'\n"}, {"source_code": "puts gets.sub /(.+?)0|./,'\\1'"}, {"source_code": "str = gets.chomp\npos = str.index('0')\npos = -1 if pos == nil\nstr.slice!(pos)\nstr = '0' if str.length == 0\nprint str\n"}, {"source_code": "s=gets.chomp\n\ns.length.times { |i|\n if s[i]==?0\n s[i]=''\n puts s\n exit\n end\n}\n\nputs s.chop\n\n"}, {"source_code": "puts gets.sub /(.+?)0|./,'\\1'\n"}, {"source_code": "s = gets.strip\n\nif m = s.match(/^(1+)0(.*)$/)\n\tputs(m[1]+m[2])\nelse\n\tputs s.match(/^(1*?)1$/)[1]\nend\n"}, {"source_code": "puts gets.sub /(.+?)0|./,'\\1'\n"}, {"source_code": "a=gets\nif !a.sub! /0/,'' then\n\ta.sub! /1/,''\nend\nputs a\n"}, {"source_code": "s = gets.chomp\nif s.count('0') == 0\n\tputs s.chop\nelse\n\tid = s.index '0'\n\ts[id] = ''\n\tputs s\nend"}, {"source_code": "=begin\nsq = Array.new(3)\nfor i in 0..2\n sq[i] = gets.split.map(&:to_i)\nend\nsq[0][0] = sq[0][2]\nsq[2][2] = sq[0][0] + sq[0][1] - sq[1][2]\nsq[1][1] = sq[0][0] + sq[2][0] - sq[1][2]\nfor i in sq\n for j in i\n print j, \" \"\n end\n puts \"\"\nend\n=end\n\nbit = gets.strip\ni = bit.index \"0\"\nif i == nil then i = 0 end\nbit[i] = \"\"\nprint bit"}, {"source_code": "#!/usr/bin/ruby1.9\n\nline = STDIN.readline.strip\npos = line.index('0')\nif pos == nil\n\tpos = line.length-1\nend\nputs line.slice(0, pos)+line.slice(pos+1, line.length-1)\n"}, {"source_code": "s = gets.strip\ni = s.index(\"0\"); i = 0 if i == nil\nputs s[0...i]+s[i+1..-1]"}, {"source_code": "s = gets.strip\ni = s.index(\"0\"); i = 0 if i == nil\ns[i] = \"\"\nputs s"}, {"source_code": "s = gets.chomp.split('').map(&:to_i).to_a\ns.delete_at(s.index(0) == nil ? 0 : s.index(0))\nputs s*''"}], "negative_code": [{"source_code": "s=gets.chomp\nn1=0\nn2=0\nif s.size>1 && s.index(\"0\") then\n\tn1=s.sub(\"0\",\"\").to_i(2)\nend\nif s.size>1 && s.rindex(\"1\") then\n\tn2=s.reverse.sub(\"1\",\"\").reverse.to_i(2)\nend\nputs [n1,n2].max\n\n"}, {"source_code": "s=gets\n\ns.length.times { |i|\n if s[i]==?0\n s[i]=''\n puts s\n exit\n end\n}\n\ns[-1]=''\nputs\n"}, {"source_code": "s = gets\n\nif s.match(/^0+$/) or s.match(/^1+$/) or s.match(/^0+1*$/)\n puts s[1..-1]\nelse\n s =~ /^(0*)(1+)0(.*)$/\n p $1, $2, $3\n puts $1 + $2 + $3\nend\n"}, {"source_code": "a = gets.strip\n\nok = false\n\na.each_char do |c|\n\tif ok or c == '1'\n\t\tprint c\n\telsif c == '0'\n\t\tok = true\n\tend\nend"}], "src_uid": "133eaf241bb1557ba9a3f59c733d34bf"} {"source_code": "n,m=gets.split.map{|e| e.to_i}\nsum=gets.split.map{|e| e.to_i}.inject(0){|sum,e| sum+e}+n-1\nif m==sum\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend", "positive_code": [{"source_code": "n, x = gets.split.map &:to_i\nputs gets.split.map(&:to_i).inject(:+)+n==x+1?:YES:'NO'"}, {"source_code": "in_str = gets\nn, x = in_str.split(' ')\nn, x = n.to_i, x.to_i\nin_str = gets\ncrossword_arr = in_str.split(' ').map { |element| element.to_i }\nlength = 0\ncrossword_arr.each do |elem|\n length += elem + 1\nend\nif length - 1 == x\n puts 'YES'\nelse\n puts 'NO'\nend"}], "negative_code": [], "src_uid": "080a3458eaea4903da7fa4cf531beba2"} {"source_code": "k,l,a,b=0,0,Array.new(101,0),Array.new(101,0)\ngets.to_i.times do\n\tx,y=gets.chomp.split.map(&:to_i)\n\tif a[x]==0\n\t\ta[x]=1\n\t\tl+=1\n\tend\n\tif b[y]==0\n\t\tb[y]=1\n\t\tk+=1\n\tend\nend\nputs [k,l].min\n", "positive_code": [{"source_code": "n = gets.to_i\nx_arr = []\ny_arr = []\nn.times do\n\tx,y = gets.split(\" \").map(&:to_i)\n\tx_arr << x\n\ty_arr << y\nend\nh = x_arr.uniq.count\nv = y_arr.uniq.count\nputs [h,v].min"}, {"source_code": "a = Array.new(2) { [0] * 101 }\ngets.to_i.times { x, y = gets.split.map &:to_i; a[0][x] += 1; a[1][y] += 1 }\np a.map { |e| e.count { |e| e > 0 } }.min"}], "negative_code": [], "src_uid": "89a8936bf7d43a9c5f69714a7cb7df82"} {"source_code": "n=gets.to_i\nn.times do\n t=gets.to_i\n puts 7\nend", "positive_code": [{"source_code": "for i in 1..gets.to_i\r\n puts 7\r\nend"}, {"source_code": "for i in 1..gets.to_i\r\n puts gets.to_i\r\nend"}], "negative_code": [{"source_code": "for i in 1..gets.to_i\r\n puts 2*gets.to_i\r\nend"}], "src_uid": "b7e36ca8a96dd7951359070d4953beec"} {"source_code": "\ufeff$__cur_readed = []\r\n$__cur_index = 0\r\n\r\ndef ri()\r\n\twhile $__cur_index >= $__cur_readed.length\r\n\t\t$__cur_readed = gets.split(\" \")\r\n\t\t$__cur_index = 0\r\n\tend\r\n\t$__cur_index+=1\r\n\treturn $__cur_readed[$__cur_index-1]\r\nend\r\n\r\ndef rs()\r\n\tcur = \"\"\r\n\twhile true\r\n\t\tif STDIN.eof \r\n\t\t\treturn cur \r\n\t\tend\r\n\t\tc = STDIN.readchar\r\n\t\t#puts \"cur s is \" + c\r\n\t\tif c != \" \" and c != \"\\n\"\r\n\t\t\tcur += c\r\n\t\telse\r\n\t\t\tif cur != \"\"\r\n\t\t\t\treturn cur\r\n\t\t\tend\r\n\t\tend\r\n\tend\r\nend\r\n\r\nt = rs.to_i\r\n\r\nfor curt in (1..t)\r\n\tn = rs.to_i\r\n\tarr = Array.new(n) {|i| rs.to_i}\r\n\tputs arr == arr.sort ? \"NO\" : \"YES\"\r\nend", "positive_code": [{"source_code": "\ufeff$__cur_readed = []\r\n$__cur_index = 0\r\n\r\ndef rs1()\r\n\twhile $__cur_index >= $__cur_readed.length\r\n\t\t$__cur_readed = gets.split(\" \")\r\n\t\t$__cur_index = 0\r\n\tend\r\n\t$__cur_index+=1\r\n\treturn $__cur_readed[$__cur_index-1]\r\nend\r\n\r\ndef rs2()\r\n\tcur = \"\"\r\n\twhile true\r\n\t\tif STDIN.eof \r\n\t\t\treturn cur \r\n\t\tend\r\n\t\tc = STDIN.readchar\r\n\t\t#puts \"cur s is \" + c\r\n\t\tif c != \" \" and c != \"\\n\"\r\n\t\t\tcur += c\r\n\t\telse\r\n\t\t\tif cur != \"\"\r\n\t\t\t\treturn cur\r\n\t\t\tend\r\n\t\tend\r\n\tend\r\nend\r\n\r\ndef ri()\r\n\treturn rs1.to_i\r\nend\r\n\r\nt = ri\r\n\r\nfor curt in (1..t)\r\n\tn = ri\r\n\tarr = Array.new(n) {|i| ri}\r\n\tputs arr == arr.sort ? \"NO\" : \"YES\"\r\nend"}, {"source_code": "\ufeff$__cur_readed = []\r\n$__cur_index = 0\r\n\r\ndef ri()\r\n\twhile $__cur_index >= $__cur_readed.length\r\n\t\t$__cur_readed = gets.split(\" \")\r\n\t\t$__cur_index = 0\r\n\tend\r\n\t$__cur_index+=1\r\n\treturn $__cur_readed[$__cur_index-1]\r\nend\r\n\r\nt = ri.to_i\r\n\r\nfor curt in (1..t)\r\n\tn = ri.to_i\r\n\tarr = Array.new(n) {|i| ri.to_i}\r\n\tputs arr == arr.sort ? \"NO\" : \"YES\"\r\nend"}, {"source_code": "gets.to_i.times {\n gets\n xs = gets.split.map(&:to_i)\n if xs == xs.sort\n puts \"NO\"\n else\n puts \"YES\"\n end\n}\n"}], "negative_code": [], "src_uid": "ef1448a744f67347183479c697aa87e1"} {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\nres = 0\nn.times do |i|\n unless a.include?(i+1); res += 1; end;\nend\np res\n", "positive_code": [{"source_code": "require 'set'\nn = gets.to_i\na = Set.new(gets.split(' ').map(&:to_i))\nres = 0\nn.times do |i|\n unless a.include?(i+1); res += 1; end;\nend\np res\n"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i).uniq).size\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\nres = 0\nn.times do |i|\n if a.index(i+1) == nil; res += 1; end;\nend\np res\n"}, {"source_code": "def solve n, list\n (1..n).to_a.select{|i| list.include?(i) == false}.length\nend\n\nn = STDIN.gets.chomp.to_i\nlist = STDIN.gets.chomp.split(' ').map{|ch| ch.to_i}\nputs solve n, list"}, {"source_code": "n = gets.to_i\np n - gets.split.map(&:to_i).grep(1..n).uniq.size\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\ncnt=Array.new(n+1,0)\na.each{|i|\n if i<=n then\n cnt[i]=1\n end\n}\nans=n\n1.upto(n+1){|i|\n if cnt[i]==1 then\n ans-=1\n end\n}\np ans\n"}, {"source_code": "n = gets.to_i \np n - gets.split(' ').map{|i| i.to_i}.delete_if{|i| i > n}.uniq.size\n\n\n\n"}, {"source_code": "n = gets.to_i \nputs n - gets.split(' ').map{|i| i.to_i}.delete_if{|i| i > n}.uniq.size\n\n\n\n"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).size\n"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).size\n"}, {"source_code": "require 'set'\nn = gets().to_i\ns = Set.new(gets().split(' ').map(&:to_i))\n\nret = 0\nfor i in 1..n\n if not s.include?(i) then\n ret += 1\n end\nend\nputs ret\n\n"}, {"source_code": "require 'set'\nn = gets().to_i\ns = Set.new(gets().split(' ').map(&:to_i))\nputs (1..n).reduce(0){|a,b| a+((s.include? b)?0:1)}\n\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nary = STDIN.gets.chomp.split(' ').map{|x| x.to_i }\nary = ary[0...n]\nmistaken = ary.size - ary.uniq.size\nmistaken += ary.uniq.select{|x| x > n }.size\nmistaken += ary.uniq.select{|x| x < 1 }.size\np mistaken\n\n"}, {"source_code": "n = gets.chomp.to_i\nputs gets.chomp.split.map(&:to_i).reduce(Array(1..n)) { |s, x| s - [x] }.length"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).size"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\np n - ((1..n).to_a&a).uniq.size"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).size\n"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).size\n"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).uniq.size"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = Array.new(n){0}\nm = 0\n\na.each do |i|\n if i <= n && b[i-1] == 0\n b[i-1] = 1 \n else\n m += 1\n end\nend\n\np m\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\nb = []\ndem = 0\n\n(1..n).each do |i|\n b[i] = 0\nend\n\n(0..n-1).each do |i|\n if b[a[i]] == 0\n b[a[i]] = 1\n dem +=1\n end\nend\n\nputs (n-dem)"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).size"}, {"source_code": "require 'set'\nn = gets.chomp.to_i\na = gets.chomp.split(\" \").map {|e| e.to_i}\n\nset = {}\na.each do |e|\n if (1 <= e && e <= n)\n set[e] = 1\n end\nend\n\nputs n - set.keys.length\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\nrequire 'prime'\n#require 'mathn'\nrequire 'matrix'\nrequire 'set'\ninclude Math\n#=================================\n\nn=gets.to_i\ndata=gets.split.map(&:to_i)\n\nhs=Hash.new(0)\ndata.each{|v| hs[v]+=1}\n\nans=0\nn.times{|i|\n\ti+=1\n\t\n\tif hs[i]==0\n\t\tans+=1\n\tend\n}\n\nputs ans\n"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).size\n"}, {"source_code": "i = gets.to_i \nputs i - gets.chomp.split().uniq.count { |x| x.to_i <= i }"}, {"source_code": "n = gets.to_i\nar = gets.split(' ').map(&:to_i)\nar2 = (1..n).to_a\nputs (ar2-ar).count\n"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).size"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tsta=gets.chomp.split(\" \").map{|i| i.to_i}\n\tsta=sta.uniq\n\tchange=0\n\tfor i in 1..n\n\t\tif !sta.include?(i)\n\t\t\tchange+=1\n\t\tend\n\tend\n\tputs change\nend\nmain()"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).size\n"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).size\n"}, {"source_code": "n,k=gets.to_i,gets.split.map(&:to_i);ch=0;n.times {|x| k.include?(x+1) ?0:ch+=1};puts ch"}, {"source_code": "n = gets.to_i\ns = gets\na = s.split\nb = [ ]\n0.upto(n-1) {\n\t|i|\n\ta[i] = a[i].to_i\n\tb[a[i]] = 1\n}\ns = 0\n0.upto(n-1) {\n\t|i|\n\ts = s + 1 if b[i+1] != 1\n}\nputs s"}, {"source_code": "p ([*1..gets.to_i]-gets.split.map(&:to_i)).size\n"}, {"source_code": "puts(((1..gets.to_i).to_a - gets.split.map { |x| x.to_i }).size)"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\ncount = [false] * 5001\ngets.split.each { |x| \n count[x.to_i] = true\n}\nresult = n\n1.upto(n) { |x| \n result -= 1 if count[x]\n}\nputs result\n"}], "negative_code": [{"source_code": "p gets.to_i-gets.split.map(&:to_i).uniq.size\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i).sort\nres = 0\nn.times do |i|\n if a[i] != i+1; res += 1; end;\nend\np res\n"}, {"source_code": "n = gets.to_i\nm = gets.chomp.split(\" \").collect! {|i| i}\n\nputs n - m.uniq.size\n\n\n"}, {"source_code": "n = gets.to_i \nputs n - gets.split(' ').map{|i| i.to_i}.delete_if{|i| i > n}.size\n\n\n\n"}, {"source_code": "gets()\nd = Hash.new(0)\ngets().split(' ').map(&:to_i).each do |e|\n d[e] += 1\nend\n\nret = 0\n\nd.each do |k,v|\n ret += v - 1\nend\n\nputs ret\n\n"}, {"source_code": "gets()\nd = Hash.new(0)\ngets().split(' ').map(&:to_i).each do |e|\n d[e] += 1\nend\n\nret = 0\n\nd.each do |k,v|\n ret += d[k] - 1\nend\n\nputs ret\n\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nary = STDIN.gets.chomp.split(' ').map{|x| x.to_i }\nary = ary[0...n]\np ary.size - ary.uniq.size\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nary = STDIN.gets.chomp.split(' ').map{|x| x.to_i }\nary = ary[0...n]\nmistaken = ary.size - ary.uniq.size\nmistaken += ary.select{|x| x > n }.size\nmistaken += ary.select{|x| x < 1 }.size\np mistaken\n\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nary = STDIN.gets.chomp.split(' ')\nary = ary[0...n]\np ary.size - ary.uniq.size\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nputs n - a.uniq.size"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = Array.new(n){0}\nm = 0\n\na.each do |i|\n if i > n ||b[i-1] == 0\n b[i-1] = 1 \n else\n m += 1\n end\nend\n\np m\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\nrequire 'prime'\n#require 'mathn'\nrequire 'matrix'\nrequire 'set'\ninclude Math\n#=================================\n\nn=gets.to_i\ndata=gets.split.map(&:to_i)\n\nhs=Hash.new(0)\ndata.each{|v| hs[v]+=1}\n\nans=0\nn.times{|i|\n\ti+=1\n\t\n\tif hs[i]>1\n\t\tans+=hs[i]-1\n\tend\n}\n\nputs ans\n"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tsta=gets.chomp.split(\" \").map{|i| i.to_i}\n\tsta=sta.sort\n\tchange=0\n\tfor i in 1..n\n\t\tif sta[i-1]!=i\n\t\t\tchange+=1\n\t\tend\n\tend\n\tputs change\nend\nmain()"}, {"source_code": "n,k=gets.to_i,gets.split.map(&:to_i);ch=0;n.times {|x| k.include?(x) ?0:ch+=1};puts ch"}, {"source_code": "n,k=gets.to_i,gets.split.map(&:to_i);ch=0;k=k.sort;n.times {|x| k[x]==x+1 ?0:ch+=1};puts ch"}, {"source_code": "n = gets.to_i\ns = gets\na = s.split\n0.upto(n-1) {\n\t|i|\n\ta[i] = a[i].to_i\n}\na = a.sort\ns = 0\ni = 0\nwhile i < n\n\ts = s + (a[i]-i-1).abs\n\ti = i + 1\nend\nputs s"}, {"source_code": "n = gets.to_i\ns = gets\na = s.split\n0.upto(n-1) {\n\t|i|\n\ta[i] = a[i].to_i\n}\na = a.sort\ns = 0\ni = 0\nwhile i < n\n\ts = s + 1 if a[i] != i + 1\n\ti = i + 1\nend\nputs s"}, {"source_code": "require 'set'\nn = gets.chomp.to_i\na = gets.chomp.split(\" \").map {|e| e.to_i}\n\nset = {}\na.each do |e|\n set[e] = 1\nend\n\nputs n - set.keys.length\n"}, {"source_code": "n = gets.chomp.to_i\nputs gets.chomp.split.map(&:to_i).reduce(Array(1..n)) { |s, x| s - [x]}"}, {"source_code": "n = gets.chomp.to_i\ngets.chomp.split.map(&:to_i).reduce(Array(1..n)) { |s, x| s - [x]}"}], "src_uid": "bdd86c8bc54bbac6e2bb5a9d68b6eb1c"} {"source_code": "# coding: utf-8\n\nq = gets.to_i\nq.times {\n n, m = gets.split.map(&:to_i)\n sum = 0\n i = 1\n ten_round = []\n for i in 1..10\n x = m*i\n ten_round << x%10\n end\n # n = q*m + r\n q = n / (m*10)\n r = n % (m*10)\n sum = ten_round.reduce(:+) * q\n # take care of 'r'\n for i in 1..10\n x = m*i\n if x <= r\n sum += ten_round[i-1]\n else\n break\n end\n end\n puts sum\n}", "positive_code": [{"source_code": "q = readline.to_i\n\nq.times do\n n, m = readline.split.map(&:to_i)\n ans = 0\n l = []\n c = m\n until l.include?(c % 10)\n l << c % 10\n c += m\n end\n\n k = l.size\n\n l.each_with_index do |v, i|\n ans += (n / (m * k)) * v\n n % (m * k) >= (i + 1) * m && ans += v\n end\n\n puts ans\nend\n"}, {"source_code": "def calc(b, range)\n\trange.sum { |i| b * i % 10 }\nend\n\ngets.to_i.times do\n\ta, b = gets.split.map(&:to_i)\n\tputs calc(b, 0...10) * (a / b / 10) + calc(b, 0..a / b % 10)\nend\n"}, {"source_code": "gets.strip.to_i.times do\n n, m = gets.strip.split(' ').map(&:to_i)\n divs = (1..10).to_a.map { |i| (i * m) }\n last = (1..10).to_a.map { |i| (i * m) % 10 }\n\n\n res1 = (last.inject(:+) * (n / divs[-1]))\n res2 = divs.select { |d| d <= (n % divs[-1]) }.map { |x| x % 10 }.inject(:+)\n puts (res1 || 0) + (res2 || 0)\nend"}, {"source_code": "gets.to_i.times do\n n, m = gets.split.map(&:to_i)\n cnt = n / m\n d = []\n (0..9).each do |i|\n d << (((i + 1) * m) % 10)\n end\n sum = 0\n (0...cnt % 10).each do |i|\n sum += d[i]\n end\n sum2 = 0\n (0..9).each do |i|\n sum2 += d[i]\n end\n sum += cnt / 10 * sum2\n puts sum\nend"}, {"source_code": "qq = gets.to_i\nnm =\n qq.times.map do |q|\n gets.split.map(&:to_i)\n end\nnm.each do |nn,mm|\n ans = 0\n # 10\u500d\u3067\u30eb\u30fc\u30d7\u3059\u308b\n num10 = 0\n 1.upto(9) do |n|\n num10 += (mm*n) % 10\n end\n\n div = nn / (mm*10)\n ans += div * num10\n\n mod = nn % (mm*10)\n a = mm\n while a <= mod do\n ans += a%10\n a+=mm\n end\n\n puts ans\nend\n"}], "negative_code": [], "src_uid": "9964bfdcfdd041b839ce120019e8220f"} {"source_code": "n,m=gets.split.map &:to_i\n\n# s=?a+gets.chomp+?a\ns=?a\ns< 0 and i < n-1\n\n\t\t\t\ttotal+=1 if str[i-1] == '.'\n\t\t\t\ttotal+=1 if str[i+1] == '.'\t\t\n\t\t\t\telsif i==0 and i+1=0 and str[i-1] == '.'\n\t\t\t\ttotal+=1\n\t\t\t\tend\n\t\tend\t\t\n\telse\n\t\tif str[i] == '.' \n\t\t\tif i > 0 and i < n-1\n\t\t\t\ttotal-=1 if str[i-1] == '.'\n\t\t\t\ttotal-=1 if str[i+1] == '.'\t\t\n\t\t\telsif i==0 and i+1=0 and str[i-1] == '.'\n\t\t\t\ttotal-=1\n\t\t\tend\n\t\tend\n\t\t\n\tend\n\tstr[i] = c\n\tputs total\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\ndef solution(n, m, s, narr, carr)\n count = 0\n prev_char = nil\n s.each_char do |char|\n count+=1 if char == '.' && prev_char == '.'\n prev_char = char\n end\n m.times do |t|\n i = narr[t]\n char = carr[t]\n if (char == '.') ^ (s[i] == '.')\n if char == '.'\n count+=1 if i > 0 && s[i-1] == '.'\n count+=1 if i+1 < n && s[i+1] == '.'\n else\n count-=1 if i > 0 && s[i-1] == '.'\n count-=1 if i+1 < n && s[i+1] == '.'\n end\n s[i] = char\n end\n puts count\n end\nend\n\nn, m = gets.split(' ').map{|s|s.to_i}\ns = gets\nnarr = []\ncarr = []\nm.times{\n i, c = gets.split(' ')\n narr.push i.to_i - 1\n carr.push c\n}\nsolution n, m, s, narr, carr\n\n# solution 10, 3, '.b..bz....', [0, 2, 8], %w(h c f)\n# solution 4, 4, '.cc.', [1, 2, 1, 0], %w(. . a a)\n# solution 4,3\n# solution 3,2\n# solution 3,1\n# solution 3,3\n# solution 2,1\n# solution 2,2\n#\n# #\n# # solution 4, [75, 150, 75, 50]\n# # solution 3, [100, 150, 250]"}, {"source_code": "n,m=gets.split.map &:to_i\n\ns=?a+gets.chomp+?a\ngroups=s.scan(/\\.+/).size\ndots=s.count ?.\nb=s.bytes.map{|c|c<90}\n\nres=[]\nqueries=$<.read.split\nm.times{|i|\n x=queries[2*i].to_i\n c=queries[2*i+1]\n if b[x] and c!=?.\n dots-=1\n if !b[x-1] and !b[x+1]\n groups-=1\n elsif b[x-1] and b[x+1]\n groups+=1\n end\n b[x]=false\n elsif !b[x] and c==?.\n dots+=1\n if !b[x-1] and !b[x+1]\n groups+=1\n elsif b[x-1] and b[x+1]\n groups-=1\n end\n b[x]=true\n end\n res< 0 and i < n-1\n\n\t\t\t\ttotal+=1 if str[i-1] == '.'\n\t\t\t\ttotal+=1 if str[i+1] == '.'\t\t\n\t\t\t\telsif i==0 and i+1 0 and i < n-1\n\t\t\t\ttotal-=1 if str[i-1] == '.'\n\t\t\t\ttotal-=1 if str[i+1] == '.'\t\t\n\t\t\telsif i==0 and i+11 and (x==0 and s[x+1]!=?.) or (x==n-1 and s[x-1]!=?.)\n groups-=1\n elsif n>2 and (01 and (x==0 and s[x+1]!=?.) or (x==n-1 and s[x-1]!=?.)\n groups+=1\n elsif n>2 and (01 and (x==0 and s[x+1]!=?.) or (x==n-1 and s[x-1]!=?.)\n groups-=1\n elsif n>2 and (01 and (x==0 and s[x+1]!=?.) or (x==n-1 and s[x-1]!=?.)\n groups+=1\n elsif n>2 and (0 j\n end\nend\nputs outcomes.size\noutcomes.sort.each do |outcome|\n puts outcome.join(\" \")\nend\n", "positive_code": [{"source_code": "x,y,a,b = gets.split.map{|i| i.to_i}\n\nn = 0\nish = []\nwhile a <= x do\n v = b\n while v <= y do\n if a > v then\n n += 1\n ish << a.to_s + \" \" + v.to_s\n end\n v += 1\n end\n a += 1\nend\n\nputs n\nn.times do |i|\n puts ish[i]\nend"}, {"source_code": "x,y,a,b=gets.split.map(&:to_i)\n_=[]\n[a,~-b].max.upto(x){|i|b.upto([~-i,y].min){|j|_<<[i,j]*\" \"}}\nputs _.size,_\n"}, {"source_code": "ans=Array.new\nx,y,a,b=gets.split.map(&:to_i)\nfor i in a.to_i..x.to_i do\nk=[y.to_i,i].min\n\tfor j in b.to_i..k \n\t\tans<< [i,j] if i!=j\n\tend\nend\nans.size!=0?(puts ans.size;ans.each{|el|puts el.join(\" \")}):(puts 0)\n"}, {"source_code": "x, y, a, b = gets.split.map(&:to_i)\nres = Array.new\nfor i in [a, b+1].max..x\n for j in b..y\n break if j >= i\n res << [i, j]\n end\nend\nputs res.count\nfor i in res\n puts \"#{i[0]} #{i[1]}\"\nend"}, {"source_code": "x, y, a, b = gets.split(' ').collect!{ |i| i.to_i}\nn = 0\na.upto(x) do |i|\n\tb.upto(y) do |j|\n\t\tif i>j\n\t\t\tn += 1\n\t\tend\n\tend\t\t\nend\n\nputs n\n\na.upto(x) do |i|\n\tb.upto(y) do |j|\n\t\tif i>j\n puts \"#{i} #{j}\"\n\t\tend\n\tend\t\t\nend"}, {"source_code": "x,y,a,b=gets.split.map(&:to_i)\n_=[]\n[a,~-b].max.upto(x){|i|b.upto([~-i,y].min){|j|_<<[i,j]*\" \"}}\nputs _.size,_\n"}, {"source_code": "x,y,a,b=gets.split.map(&:to_i)\n_=[]\n[a,~-b].max.upto(x){|i|b.upto([~-i,y].min){|j|_<<[i,j]*\" \"}}\nputs _.size,_"}, {"source_code": "x,y,a,b=gets.split.map(&:to_i)\n_=[]\n[a,~-b].max.upto(x){|i|b.upto([~-i,y].min){|j|_<<[i,j]*\" \"}}\nputs _.size,_"}, {"source_code": "x,y,a,b=gets.chomp.split().map(&:to_i)\nif a<=b\n\ta=b+1\nend\ncount=0\ni=a\nwhile i<=x\n\tif i<=y\n\t\tmin=i-1\n\telse\n\t\tmin=y\n\tend\n\tcount+=min-b+1\n\ti+=1\nend\nputs count\nwhile a<=x\n\tif a<=y\n\t\tmin=a-1\n\telse\n\t\tmin=y\n\tend\n\ti=b\n\twhile i<=min\n\t\tputs a.to_s+' '+i.to_s\n\t\ti+=1\n\tend\n\ta+=1\n\nend"}, {"source_code": "x,y,a,b = gets.split.map(&:to_i)\ns = %w()\n(a..x).each { |i| (b..y).each { |j| s.push [i, j] if i > j } }\nputs s.size\ns.each { |f| puts f*' ' }"}, {"source_code": "x,y,a,b=gets.split.map(&:to_i)\n_=[]\n[a,~-b].max.upto(x){|i|b.upto([~-i,y].min){|j|_<<[i,j]*\" \"}}\nputs _.size,_\n"}, {"source_code": "x,y,a,b=gets.split.map(&:to_i)\n_=[]\n[a,~-b].max.upto(x){|i|b.upto([~-i,y].min){|j|_<<[i,j]*\" \"}}\nputs _.size,_\n"}, {"source_code": "#CF Round 149. Div II Prob. A - Heads or Tails\narr = gets.chomp.split(/ /)\na, res = [], []\narr.each {|i| a << i.to_i}\n(a[2]..a[0]).each { |i|\n (a[3]..[a[1], i - 1].min).each { |j|\n res << (i.to_s + \" \" + j.to_s)\n }\n}\nputs res.size\nres.each {|i| puts i}"}, {"source_code": "#CF Round 149. Div II Prob. A - Heads or Tails\na = gets.chomp.split(/ /).map(&:to_i)\nres = []\n(a[2]..a[0]).each { |i|\n (a[3]..[a[1], i - 1].min).each { |j|\n res << (i.to_s + \" \" + j.to_s)\n }\n}\nputs res.size\nres.each {|i| puts i}"}, {"source_code": "x,y,a,b = gets.split.map(&:to_i)\nans = []\nif x <= b\n puts 0\n exit\nelse\n a = [a,b].max\n (a).upto(x) do |i| \n (b).upto([(i-1),y].min) do |j|\n ans << \"#{i} #{j}\"\n end\n end\nend\nputs ans.length\nans.each { |i| puts i }"}, {"source_code": "x,y,a,b=gets.split.map(&:to_i)\n_=[]\n[a,~-b].max.upto(x){|i|b.upto([~-i,y].min){|j|_<<[i,j]*\" \"}}\nputs _.size,_\n"}, {"source_code": "x, y, a, b = gets.split.collect{|i| i.to_i}\ncnt = 0\nfor i in a..x\n for j in b...(i b ? a : b + 1\nt = y + 1\nps = []\nfor i in s..x\n for j in b...[i, t].min\n ps << [i, j]\n end\nend\nputs ps.size\nps.each { |p| puts p * ' ' }"}, {"source_code": "x,y,a,b=gets.split.map(&:to_i)\n_=[]\n[a,~-b].max.upto(x){|i|b.upto([~-i,y].min){|j|_<<[i,j]*\" \"}}\nputs _.size,_\n"}, {"source_code": "x,y,a,b=gets.split.map(&:to_i)\n_=[]\n[a,~-b].max.upto(x){|i|b.upto([~-i,y].min){|j|_<<[i,j]*\" \"}}\nputs _.size,_"}, {"source_code": "x,y,a,b=gets.split.map(&:to_i)\n_=[]\n[a,~-b].max.upto(x){|i|b.upto([~-i,y].min){|j|_<<[i,j]*\" \"}}\nputs _.size,_\n"}], "negative_code": [{"source_code": "ans=Array.new\nx,y,a,b=gets.split.map(&:to_i)\nfor i in a.to_i..x.to_i do\n\tfor j in [b.to_i,a.to_i].max..[y.to_i,i].min \n\t\tans<< [i,j] if i!=j\n\tend\nend\nans.size!=0?(ans.each{|el|puts el.join(\" \")}):(puts 0)\n"}, {"source_code": "ans=Array.new\nx,y,a,b=gets.split.map(&:to_i)\nfor i in a.to_i..x.to_i do\n\tfor j in [b.to_i,a.to_i].max..[y.to_i,i].min \n\t\tans<< [i,j] if i!=j\n\tend\nend\nans.size!=0?(puts ans.size;ans.each{|el|puts el.join(\" \")}):(puts 0)\n"}, {"source_code": "x, y, a, b = gets.split(' ').collect!{ |i| i.to_i}\nn = 0\nx.downto(a) do |i|\n\ty.downto(b) do |j|\n\t\tif i>j\n\t\t\tn += 1\n\t\tend\n\tend\t\t\nend\n\nputs n\n\nx.downto(a) do |i|\n\ty.downto(b) do |j|\n\t\tif i>j\n puts \"#{i} #{j}\"\n\t\tend\n\tend\t\t\nend"}, {"source_code": "x,y,a,b = gets.split.map(&:to_i)\n\nif x <= b\n puts 0\n exit\nelse\n a = [a,b].max\n (a+1).upto(x) do |i| \n (b).upto(i-1) do |j|\n print i,' ',j; puts\n end\n end\nend"}, {"source_code": "x,y,a,b = gets.split.map(&:to_i)\nans = []\nif x <= b\n puts 0\n exit\nelse\n a = [a,b].max\n (a+1).upto(x) do |i| \n (b).upto([(i-1),b].min) do |j|\n ans << \"#{i} #{j}\"\n end\n end\nend\nputs ans.length\nans.each { |i| puts i }"}, {"source_code": "x,y,a,b = gets.split.map(&:to_i)\nans = []\nif x <= b\n puts 0\n exit\nelse\n a = [a,b].max\n (a+1).upto(x) do |i| \n (b).upto(i-1) do |j|\n ans << \"#{i} #{j}\"\n end\n end\nend\nputs ans.length\nans.each { |i| puts i }"}, {"source_code": "x,y,a,b = gets.split.map(&:to_i)\nans = []\nif x <= b\n puts 0\n exit\nelse\n a = [a,b].max\n (a+1).upto(x) do |i| \n (b).upto(i-1) do |j|\n ans << \"#{i} #{j}\"\n end\n end\nend\n\nans.each { |i| puts i }"}, {"source_code": "x,y,a,b = gets.split.map(&:to_i)\nans = []\nif x <= b\n puts 0\n exit\nelse\n a = [a,b].max\n (a+1).upto(x) do |i| \n (b).upto([(i-1),y].min) do |j|\n ans << \"#{i} #{j}\"\n end\n end\nend\nputs ans.length\nans.each { |i| puts i }"}, {"source_code": "x, y, a, b = gets.split.collect{|i| i.to_i}\ncnt = 0\nfor i in b..y\n for j in i+1..x\n cnt += 1\n end\nend\nputs cnt\nfor i in b..y\n for j in i+1..x\n print j, \" \", i, \"\\n\"\n end\nend\n"}], "src_uid": "bb3e3b51a4eda8fef503952a00777910"} {"source_code": "n = gets.chomp.to_i\nps = gets.chomp.split.map(&:to_i)\n\nhs = Hash.new()\n(0...n).each do |i|\n hs[ps[i]] = i\nend\n\nans = n - 1\ncnt = 1\nfor i in 2..n\n if hs[i - 1] < hs[i]\n cnt += 1\n else\n cnt = 1\n end\n ans = [ans, n - cnt].min\nend\n\nputs ans\n", "positive_code": [{"source_code": "#Good luk for the Contest 606, Problem: c\nn = gets.strip.to_i\nar = gets.strip.split.map(&:to_i)\n\npos = Array.new(n, 0)\n0.upto(n-1).each do |i|\n\tpos[ar[i]-1] = i\nend\n\nres = 1\ntmp = 1\n1.upto(n-1).each do |i|\n\tif pos[i] > pos[i-1]\n\t\ttmp += 1\n\telse\n\t\tres = tmp if tmp >res\n\t\ttmp = 1\n\tend\nend\nres = tmp if tmp > res\nputs n-res"}, {"source_code": "n = gets.to_i\nps = gets.chomp.split.map(&:to_i)\nd = Array.new(n, 0)\nps.each {|p| d[p - 1] = p == 1 ? 1 : d[p - 2] + 1 }\nputs (n - d.max)\n"}], "negative_code": [{"source_code": "#Good luk for the Contest 606, Problem: c\nn = gets.strip.to_i\nar = gets.strip.split.map(&:to_i)\n\npos = Array.new(n, 0)\n0.upto(n-1).each do |i|\n\tpos[ar[i]-1] = i\nend\n\nres = 1\ntmp = 1\n1.upto(n-1).each do |i|\n\tif pos[i] > pos[i-1]\n\t\ttmp += 1\n\telse\n\t\tres = tmp if tmp >res\n\t\ttmp = 1\n\tend\nend\nputs n-res"}, {"source_code": "#Good luk for the Contest 606, Problem: c\nn = gets.strip.to_i\nar = gets.strip.split.map(&:to_i)\n\npos = Array.new(n, 0)\n0.upto(n-1).each do |i|\n\tpos[ar[i]-1] = i\nend\n\nres = 0\ntmp = 1\n1.upto(n-1).each do |i|\n\tif pos[i] > pos[i-1]\n\t\ttmp += 1\n\telse\n\t\tres = tmp if tmp >res\n\t\ttmp = 1\n\tend\nend\nputs n-res"}], "src_uid": "277948a70c75840445e1826f2b23a897"} {"source_code": "n, k, p, x, y = gets.split.map(&:to_i)\nkk = gets.split.map(&:to_i).sort\nl = kk.count{|i| i < y}\ng = kk.count{|i| i >= y}\nadd_g = [0, (n + 1) / 2 - g].max\nif l > n / 2 || kk.inject(:+).to_i + add_g * y + (n - k - add_g) > x\n puts -1\nelse\n ans = []\n add_g.times{ans << y}\n (n - k - add_g).times{ans << 1}\n puts ans.join(\" \")\nend\n", "positive_code": [{"source_code": "n,k,p,x,y=gets.chomp.split(' ').map(&:to_i)\nak=gets.chomp.split(' ').map(&:to_i)\none=0\ntwo=0\nsum=0\nfor i in ak do\n\tsum+=i\n\tif i(n-k)\n\twon=n-k\nend\nm=n-k-won\nsum=x-sum\nif won+y*m>sum ||won<0\n\tputs \"-1\"\nelse\n\twon.times do\n\t\tprint \"1 \"\n\tend\n\tm.times do\n\t\tprint y.to_s+' '\n\tend\nend\nputs"}], "negative_code": [{"source_code": "n,k,p,x,y=gets.chomp.split(' ').map(&:to_i)\nak=gets.chomp.split(' ').map(&:to_i).sort\nch=0\nsum=0\nfor i in ak do\n\tsum+=i\nend\nak.each_with_index { |i,j|\n\tif i>=y\n\t\tch=j\n\t\tbreak\n\tend\n}\nleft=n/2-ch\nright=n-k-left\n\n#puts \"left = \"+left.to_s\n#puts \"right = \"+right.to_s\n#puts \"p = \"+p.to_s\n#puts \"y = \"+y.to_s\n#puts \"x = \"+x.to_s\n#puts \"sum = \"+sum.to_s\n#puts \"sum+left+right*y = \"+ (sum+left+right*y).to_s\n\nif(left<0)\n\tputs \"-1\"\nelsif(p0)\n\tputs \"-1\"\nelsif(right<0)\n\tright=0;\n\tleft=n-k-right;\nelsif sum+left+right*y<=x\n\tleft.times do\n\t\tprint \"1 \"\n\tend\n\tright.times do\n\t\tprint y.to_s+' '\n\tend\n\tputs\nelse\n\tputs \"-1\"\nend"}, {"source_code": "n, k, p, x, y = gets.split.map(&:to_i)\nkk = gets.split.map(&:to_i).sort\nl = kk.count{|x| x < y}\ng = k - l\n\nif l > n / 2 || (n / 2 - l) * 1 + [(n - n / 2 - g), 0].max * y + kk.inject(:+).to_i > x\n puts -1\nelse\n ans = []\n (n - k).times do\n if kk[(kk.size - 1) / 2].to_i >= y\n kk << 1\n ans << 1\n else\n kk << y\n ans << y\n end\n kk.sort!\n end\n puts ans.join(\" \")\nend\n"}, {"source_code": "n, k, p, x, y = gets.split.map(&:to_i)\nkk = gets.split.map(&:to_i).sort\nl = kk.count{|x| x < y}\ng = k - l\nif l > n / 2 || (n / 2 - l) * 1 + (n - n / 2 - g) * y + kk.inject(:+).to_i > x\n puts -1\nelse\n ans = []\n (n - k).times do\n if kk[(kk.size - 1) / 2].to_i >= y\n kk << 1\n ans << 1\n else\n kk << y\n ans << y\n end\n kk.sort!\n end\n puts ans.join(\" \")\nend\n"}, {"source_code": "n, k, p, x, y = gets.split.map(&:to_i)\nkk = gets.split.map(&:to_i).sort\nl = kk.count{|x| x < y}\ng = k - l\nif l > n / 2 || g > n / 2 || (n / 2 - l) * 1 + (n / 2 - g) * y + kk.inject(:+).to_i > x\n puts -1\nelse\n ans = []\n (n - k).times do\n if kk[(kk.size - 1) / 2].to_i >= y\n kk << 1\n ans << 1\n else\n kk << 4\n ans << 4\n end\n kk.sort!\n end\n puts ans.join(\" \")\nend\n"}, {"source_code": "n, k, p, x, y = gets.split.map(&:to_i)\nkk = gets.split.map(&:to_i).sort\nl = kk.count{|i| i < y}\ng = kk.count{|i| i >= y}\nadd_g = [0, (n + 1) / 2 - g].max\nif l > n / 2 || kk.inject(:+).to_i + add_g * y + (n - k - add_g) > x\n puts -1\nelse\n ans = []\n (n - k).times do\n if kk[kk.size / 2] < y\n kk << y\n ans << y\n elsif kk.size < n\n kk << 1\n ans << 1\n end\n end\n puts ans.join(\" \")\nend\n"}, {"source_code": "n, k, p, x, y = gets.split.map(&:to_i)\nkk = gets.split.map(&:to_i).sort\nl = kk.count{|x| x < y}\ng = k - l\nif l > n / 2 || g > n / 2 || (n / 2 - l) * 1 + (n - n / 2 - g) * y + kk.inject(:+).to_i > x\n puts -1\nelse\n ans = []\n (n - k).times do\n if kk[(kk.size - 1) / 2].to_i >= y\n kk << 1\n ans << 1\n else\n kk << y\n ans << y\n end\n kk.sort!\n end\n puts ans.join(\" \")\nend\n"}, {"source_code": "n, k, p, x, y = gets.split.map(&:to_i)\nans = []\nif k > 0\n kk = gets.split.map(&:to_i)\nelse\n kk = [y]\n ans << y\nend\nl = kk.count{|x| x < y}\ng = kk.count{|x| x > y}\np_n = x - kk.inject(:+)\nif l > n / 2 || g > n / 2 || (n / 2 - l) * 1 + (n / 2 - g) * y > p_n\n puts -1\nelse\n (n / 2 - l).times{ans << 1}\n (n / 2 - g).times{ans << y}\n puts ans.join(\" \")\nend\n"}, {"source_code": "n, k, p, x, y = gets.split.map(&:to_i)\nkk = gets.split.map(&:to_i).sort\nl = kk.count{|x| x < y}\ng = kk.count{|x| x > y}\np_n = x - kk.inject(:+)\nif l > n / 2 || g > n / 2 || (n / 2 - l) * 1 + (n / 2 - g) * y > p_n\n puts -1\nelse\n ans = []\n (n / 2 - l).times{ans << 1}\n (n / 2 - g).times{ans << y}\n puts ans.join(\" \")\nend\n"}], "src_uid": "f01d11bd231a7b2e7ca56de1df0f1272"} {"source_code": "str = gets.chomp\nlast = -1\nans = 0\n(3...str.size).step(1) { |i|\n last = i-3 if str[i-3..i] == 'bear'\n ans += last + 1\n}\nputs ans\n", "positive_code": [{"source_code": "s=gets.chomp\nl=s.size\np=0\nr=0\nwhile (q=s.index('bear',p))\n r+=(l-q-3)*(q-p+1)\n p=q+1\nend\np r \n"}, {"source_code": "s, r, x = gets.chomp, 0, -1\n\n(s.length - 3).times do |i|\n x = i if s[i..i+3] == 'bear'\n r += x + 1\nend\n\np r\n"}, {"source_code": "s=gets.chomp\nl=s.size\np=0\nr=0\nwhile (q=s.index('bear',p))\n r+=(l-q-3)*(q-p+1)\n p=q+1\nend\np r \n"}, {"source_code": "#f = File.open('test1.txt', 'r')\nf = STDIN\ns = f.gets.chomp\nres = 0\nlength = s.length\nlength.times do |i|\n j = s.index 'bear', i\n next unless j\n j += 3\n res += length - j\nend\nputs res"}, {"source_code": "str = gets.chomp\n\ndef eq_bear?(str)\n\tstr[(0..3)] == \"bear\"\nend\n\nsum = 0\nlast = -1\n(0...str.length).each do |i|\n\tif eq_bear? str[(i..(i + 3))]\n\t\tsum += (i - last) * (str.length - (i + 3))\n\t\tlast = i\n\tend\nend\n\nputs sum\n"}], "negative_code": [{"source_code": "s, r = gets.chomp, 0\nn = s.length\nx = 1\n\ns.each_char.with_index do |c, i|\n if (i < n-3) && s[i] + s[i+1] + s[i+2] + s[i+3] == 'bear'\n \n r += (i+x) * (n - i - 3)\n x = 0 if x == 1\n end\nend\n\np r\n"}], "src_uid": "240a2b88ded6016d0fd7157d0ee2beea"} {"source_code": "class String\n def rbs?\n b = 0\n self.each_char { |c|\n b += 1 if c == '('\n b -= 1 if c == ')'\n return false if b < 0\n }\n b == 0\n end\nend\n\ngets.to_i.times do\n s = gets.strip\n\n solution_found = false\n 8.times do |m|\n a = '()'[(m >> 0) & 1]\n b = '()'[(m >> 1) & 1]\n c = '()'[(m >> 2) & 1]\n t = s.gsub('A', a).gsub('B', b).gsub('C', c)\n solution_found = true if t.rbs?\n end\n\n puts(solution_found ? \"YES\" : \"NO\")\nend\n", "positive_code": [{"source_code": "def solve\n a = string\n n = a.size\n (1 << 3).times do |bits|\n paren = 0\n xa = 1 - bits[0] * 2\n xb = 1 - bits[1] * 2\n xc = 1 - bits[2] * 2\n valid = true\n a.each_char do |c|\n case c\n when ?A\n paren += xa\n when ?B\n paren += xb\n when ?C\n paren += xc\n end\n if paren < 0\n valid = false\n break\n end\n end\n valid &&= (paren == 0)\n if valid\n puts \"YES\"\n return\n end\n end\n puts \"NO\"\nend\n\ndef main\n t = int\n t.times do\n solve\n end\nend\n\nDEBUG = true\nMOD = 10**9+7\nYESNO = %w(No Yes)\nINF = 10**9\n\ndef int; gets.to_s.to_i end\ndef ints; gets.to_s.split.map { |s| s.to_i } end\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\ndef float; gets.to_s.to_f end\ndef floats; gets.to_s.split.map { |s| s.to_f } end\ndef array_of(&convert); gets.to_s.split.map(&convert) end\ndef string; gets.to_s.chomp end\ndef rep(n, &b); Array.new(n, &b) end\ndef yes; puts YESNO[1] end\ndef no; puts YESNO[0] end\ndef yesno t; puts YESNO[t] end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\ndef gcd(*xs); xs.inject(0, :gcd) end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\ndef if_debug; yield if DEBUG end\n\nmodule Boolean\n def coerce(other); [other, to_i] end\n def +@; to_i end\n def to_int; to_i end\n def *(other); to_i * other end\nend\n\nclass TrueClass\n include Boolean\n def to_i; 1 end\nend\n\nclass FalseClass\n include Boolean\n def to_i; 0 end\nend\n\nclass Integer\n def div_ceil(y); (self + y - 1) / y end\n def mod_inv(mod = MOD); pow(mod-2, mod) end\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\nend\n\nclass Array\n def power(&block); (0 ... 1 << size).each(&block) end\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\nend\n\nmodule Enumerable\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\nend\n\nmain"}, {"source_code": "def good(s)\r\n cur = 0\r\n s.each_char do |c|\r\n cur += c == '(' ? 1 : -1\r\n return false if cur < 0\r\n end\r\n cur == 0\r\nend\r\ngets.to_i.times do\r\n s = gets.chomp\r\n ok = false\r\n (0...8).each do |msk|\r\n cur = s.dup\r\n (0...s.size).each do |i|\r\n if msk >> (s[i].ord - 'A'.ord) & 1 != 0\r\n cur[i] = '('\r\n else\r\n cur[i] = ')'\r\n end\r\n end\r\n ok |= good cur\r\n end\r\n puts ok ? \"YES\" : \"NO\"\r\nend"}], "negative_code": [{"source_code": "def good(s)\r\n cur = 0\r\n s.each_char do |c|\r\n cur += c == '(' ? 1 : -1\r\n return false if cur < 0\r\n end\r\n cur == 0\r\nend\r\ngets.to_i.times do\r\n s = gets.chomp\r\n ok = false\r\n (0..7).each do |msk|\r\n cur = s\r\n (0...s.size).each do |i|\r\n if (msk >> (s[i].ord - 'A'.ord)) & 1 != 0\r\n cur[i] = '('\r\n else\r\n cur[i] = ')'\r\n end\r\n ok |= good cur\r\n end\r\n end\r\n puts ok ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "def good(s)\r\n cur = 0\r\n s.each_char do |c|\r\n cur += c == '(' ? 1 : -1\r\n return false if cur < 0\r\n end\r\n cur == 0\r\nend\r\ngets.to_i.times do\r\n s = gets.chomp\r\n ok = false\r\n (0..7).each do |msk|\r\n cur = s\r\n (0...s.size).each do |i|\r\n if msk >> (s[i].ord - 'A'.ord) & 1 != 0\r\n cur[i] = '('\r\n else\r\n cur[i] = ')'\r\n end\r\n ok |= good cur\r\n end\r\n end\r\n puts ok ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "def good(s)\r\n cur = 0\r\n s.each_char do |c|\r\n cur += c == '(' ? 1 : -1\r\n return false if cur < 0\r\n end\r\n cur == 0\r\nend\r\ngets.to_i.times do\r\n s = gets.chomp\r\n ok = false\r\n (1..7).each do |msk|\r\n cur = s\r\n (0...s.size).each do |i|\r\n if msk >> (s[i].ord - 'A'.ord) & 1 != 0\r\n cur[i] = '('\r\n else\r\n cur[i] = ')'\r\n end\r\n ok |= good cur\r\n end\r\n end\r\n puts ok ? \"YES\" : \"NO\"\r\nend"}], "src_uid": "4d24aaf5ebf70265b027a6af86e09250"} {"source_code": "n = STDIN.gets.to_i\nscores = {}\n(0...n).each do |it|\n\tname, score = STDIN.gets.split ' '\n\tscore = score.to_i\n\tif scores.has_key? name\n\t\tscores[name] = [scores[name], score].max\n\telse\n\t\tscores[name] = score\n\tend \nend\n\np scores.size\nscores.keys.each do |i|\n\tscore = scores[i]\n\tnot_worse = 0\n\tbetter = 0\n scores.values.each do |j| \n \tif j <= score\n \t\tnot_worse += 1\n\t\telse\n\t\t\tbetter += 1\n\t\tend\n end\n category = \"\"\n if better > 0.5 * scores.size\n \tcategory = \"noob\"\n\telsif better > 0.2 * scores.size\n\t\tcategory = \"random\"\n\telsif better > 0.1 * scores.size\n\t\tcategory = \"average\"\n\telsif better > 0.01 * scores.size\n\t\tcategory = \"hardcore\"\n\telse\n\t\tcategory = \"pro\"\n\tend\n\tputs \"#{i} #{category}\"\nend", "positive_code": [{"source_code": "result = Hash.new\nresult.default = 0\nn = gets.to_i\nn.times do\n a,b = gets.split\n b = b.to_i\n result[a] = [result[a],b].max\nend\narray = result.sort\nm=array.length\nputs m\nm.times do |i|\n cnt=0\n tmp=array[i][1]\n m.times{|j|\n cnt+=1 if tmp=99.0\n puts \" pro\"\n elsif per>=90.0\n puts \" hardcore\"\n elsif per>=80.0\n puts \" average\"\n elsif per>=50.0\n puts \" random\"\n else\n puts \" noob\"\n end\nend"}, {"source_code": "def classify(percent)\n return \"noob\" if percent > 50.0\n return \"random\" if percent > 20.0\n return \"average\" if percent > 10.0\n return \"hardcore\" if percent > 1.0\n return \"pro\"\nend\n\nn = gets.chomp.to_i\nh = Hash.new()\nfor i in 0..n-1\n nm, pt = gets.chomp.split(/ /)\n pt = pt.to_i\n if h.key?(nm)\n if h[nm] < pt\n h[nm] = pt\n end\n else\n h[nm] = pt\n end\nend\n\na = h.to_a\nn = a.length\na.sort!{|a1, a2|\n a2[1] <=> a1[1]\n}\nret = []\nwkper = 0\nprev = 0\nfor i in 0..n-1\n if prev > a[i][1]\n wkper = (i / n.to_f) * 100\n end\n ret << [a[i][0], classify(wkper)]\n prev = a[i][1]\nend\nret.sort!{|r1, r2|\n r1[0] <=> r2[0]\n}\nputs n\nret.each{|rr|\n puts rr.join(\" \")\n}\n\n"}, {"source_code": "result = Hash.new\nresult.default = 0\nn = gets.to_i\nn.times do\n a,b = gets.split\n b = b.to_i\n result[a] = [result[a],b].max\nend\n\narray = result.sort\nm=array.length\nputs m\nm.times{|i|\n cnt=0\n tmp=array[i][1]\n m.times{|j|\n cnt+=1 if tmp=99.0\n puts \" pro\"\n elsif per>=90.0\n puts \" hardcore\"\n elsif per>=80.0\n puts \" average\"\n elsif per>=50.0\n puts \" random\"\n else\n puts \" noob\"\n end\n}"}], "negative_code": [{"source_code": "result = Hash.new\nresult.default = 0\nn = gets.to_i\nn.times do\n a,b = gets.split\n b = b.to_i\n result[a] = [result[a],b].max\nend\n\narray = result.sort\nm=array.length\nm.times{|i|\n cnt=0\n tmp=array[i][1]\n m.times{|j|\n cnt+=1 if tmp99.0\n puts \" pro\"\n elsif per>90.0\n puts \" hardcore\"\n elsif per>80.0\n puts \" average\"\n elsif per>50.0\n puts \" random\"\n else\n puts \" noob\"\n end\n}"}], "src_uid": "0430fa56ec7f97efaf9d37096f72bcf8"} {"source_code": "k = gets.to_i\nn = gets.chomp.chars.map(&:to_i).sort\ns = n.map(&:to_i).reduce(0, :+)\nd = 0\nn.each{|x|\n break if s>=k\n d += 1\n s += 9 - x\n}\np d", "positive_code": [{"source_code": "k = gets.to_i\nn = gets.chomp.split('').map(&:to_i).sort\nsum = n.inject(:+)\nans = 0\nidx = 0\nwhile sum < k\n sum += 9 - n[idx]\n idx += 1\n ans += 1\nend\nputs ans"}, {"source_code": "k=gets.to_i\nn=gets.chomp.chars.sort.map &:to_i\nx=n.inject :+\nres=0\nwhile x{[*gets.chars]-[\" \"]};a=f[];puts f[].group_by{|i|i}.any?{|i,j|a.count(i)=msg.count(c))\n}\n\nputs ans ? :YES : :NO\n"}, {"source_code": "def main()\n\ts1=gets.chomp.to_s\n\ts2=gets.chomp.to_s\n\tcharavail=[]\n\tfor i in 0...(s1.length)\n\t\tif s1[i].chr!=\" \"\n\t\tcharavail << s1[i].chr\n\t\tend\t\n\tend\n\tf=true\n\tfor i in 0...(s2.length)\n\t\tif s2[i].chr!=\" \"\n\t\t\tif charavail.include?(s2[i].chr)\n\t\t\t\tind=charavail.index(s2[i].chr)\n\t\t\t\tcharavail.delete_at(ind)\n\t\t\telse\n\t\t\t\tf=false\n\t\t\t\tbreak;\n\t\t\tend\n\t\tend\n\tend\n\tif f \n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\nmain()"}, {"source_code": "a=[*gets.chars]\nputs gets.scan(/\\S/).all?{|b|(c=a.index b)&&a.delete_at(c)}?:YES:\"NO\"\n"}, {"source_code": "s1 = gets.chomp!.gsub(\" \",\"\")\ns2 = gets.chomp!.gsub(\" \",\"\")\n\ns2.each_char { |c|\n index = s1.index(c)\n if index == nil\n puts \"NO\"\n exit\n else\n s1[index..index] = \"\"\n end\n}\n\nputs \"YES\""}, {"source_code": "s1, s2 = gets.chomp, gets.chomp\n\ns1 = s1.scan(/./).reject{ |x| x =~ /\\s+/ }\ns2 = s2.scan(/./).reject{ |x| x =~ /\\s+/ }\n\nres = true\ns2.each do |char|\n i = s1.index(char)\n if i\n s1.delete_at(i)\n else\n res = false\n break\n end\nend\n\nputs res ? \"YES\" : \"NO\""}, {"source_code": "a=[*gets.chars]\nputs gets.scan(/\\S/).all?{|b|(c=a.index b)&&a.delete_at(c)}?:YES:\"NO\"\n"}, {"source_code": "a=[*gets.chars]\nputs gets.scan(/\\S/).all?{|b|(c=a.index b)&&a.delete_at(c)}?:YES:\"NO\"\n"}, {"source_code": "require 'set'\n\nYES, NO = \"YES\", \"NO\"\n\ndef get_table(test)\n result = Hash.new(0)\n test.gsub(/\\s+/, '').each_char { |char| result[char] += 1 }\n result\nend\n\nheader, text = get_table(gets), get_table(gets)\n\nok = true\n\ntext.each_key do |letter|\n if text[letter] > header[letter]\n ok = false\n break\n end\nend\n\nputs ok ? YES : NO\n"}, {"source_code": "a=[*gets.chars]\nputs gets.scan(/\\S/).all?{|b|(c=a.index b)&&a.delete_at(c)}?:YES:\"NO\""}, {"source_code": "a=[*gets.chars]\nputs gets.scan(/\\S/).all?{|b|(c=a.index b)&&a.delete_at(c)}?:YES:\"NO\"\n"}], "negative_code": [{"source_code": "str=gets\nstr2=gets\n#str=\"Instead of dogging Your footsteps it disappears but you dont notice anything\"\n#str2=\"where is your dog\"\n\nsymbols=str2.scan(/(\\w)/)\nr=true\nsymbols.each{|i|\n\tif str=~/#{i}/\n\t\tstr=str.sub(/#{i}/,\"\")\n\telse\n\t\tr=false\n\t\tbreak\n\tend\n}\nif r then p \"YES\"\nelse print \"NO\"\nend"}, {"source_code": "#=================================\nrequire 'prime'\ninclude Math\n\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(\"./input.txt\", \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\ntxt=gets.strip\nmsg=gets.strip\n\nans=true\nmsg.each_char{|c|\n\t(ans=false and break) if !(msg.count(c)>=txt.count(c))\n}\n\nputs ans ? :YES : :NO\n"}, {"source_code": "s1 = gets.chomp!.gsub(\" \",\"\")\ns2 = gets.chomp!.gsub(\" \",\"\")\n\ns2.each_char { |c|\n if s1.index(c) == nil\n puts \"NO\"\n exit\n end\n}\n\nputs \"YES\""}], "src_uid": "b1ef19d7027dc82d76859d64a6f43439"} {"source_code": "\r\nt = gets.to_i\r\nans = []\r\nt.times do\r\n n,m = gets.chomp.split(\" \").map(&:to_i)\r\n k = gets.chomp.split(\" \").map(&:to_i).sort!.reverse!\r\n c = gets.chomp.split(\" \").map(&:to_i)\r\n sum = 0\r\n index = 0\r\n n.times do |i|\r\n if c[k[i]-1] > c[index]\r\n sum += c[index]\r\n index += 1\r\n else\r\n sum += c[k[i]-1]\r\n end\r\n end\r\n ans << sum\r\nend\r\nputs ans", "positive_code": [{"source_code": "t= gets.chomp.to_i\nwhile t > 0\n n, m = gets.chomp.split(' ')\n n = n.to_i\n m = m.to_i\n k = gets.chomp.split(' ').map(&:to_i)\n c = gets.chomp.split(' ').map(&:to_i)\n k = k.sort.reverse()\n last_used_gift = 0\n cost = 0 \n k.each do |ks|\n if(c[ks-1] > c[last_used_gift] && last_used_gift < m)\n \tcost = cost + c[last_used_gift]\n \tlast_used_gift = last_used_gift + 1\n else\n \tcost = cost + c[ks-1]\n end\n end\n puts cost\n t = t - 1\nend\n\n\n\n\n\n"}], "negative_code": [], "src_uid": "55962ef2cf88c87873b996dc54cc1bf1"} {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\n0.upto(a-1) {|i| b[i]=b[i].to_i}\nb.sort!\nif a%2==0\n0.upto (a/2-1) do |i|\nprintf \"#{b[i]} #{b[a/2+i]} \"\nend\nelse\n0.upto (a/2) do |i|\nif i!=a/2\nprintf \"#{b[i]} #{b[a/2+1+i]} \"\nelse\nprintf \"#{b[i]}\"\nend\nend\nend", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split(\" \").map(&:to_i).sort\ni = 0\nj = n-1\n\nb = []\nwhile true do\n b << a[i]\n i += 1\n break if i > j\n b << a[j]\n j -= 1\n break if i > j\nend\n\nvalid = true\nn.times do |i|\n if (i+1).even?\n valid = false if b[i] < b[i-1]\n elsif (i+1).odd? && i > 0\n valid = false if b[i] > b[i-1]\n end\nend\n\nputs valid ? b.join(\" \") : \"Impossible\"\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nfor i in 0..n-1\n if (i+1)%2==0 then printf \"%d \", a.max; a.delete_at a.index(a.max);\n else printf \"%d \", a.min; a.delete_at a.index(a.min); end\nend"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort;b=a.pop(a.size/2).reverse;puts a.zip(b)*' '"}, {"source_code": "n = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\nres = []\nfor i in 0..n[0] - 1 do\n if i == 0 or (i + 1) % 2 != 0\n res[i] = arr.min\n else\n res[i] = arr.max\n end\n arr.delete_at(arr.index(res[i]) || arr.length)\nend\nputs res.join(' ')\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\ninp = gets.split.map(&:to_i)\nfor i in 0..n-1\n if (i+1) % 2 == 0 then printf \"%d \", inp.max; inp.delete_at inp.index(inp.max)\n else printf \"%d \", inp.min; inp.delete_at inp.index(inp.min) end\nend\nputs\n"}, {"source_code": "n = readline.to_i\narr = readline.split(' ').collect(&:to_i).sort\narr[0..(n / 2)].zip(arr[(n / 2 + 1)..-1]).flatten.compact.each_with_index do |num, ind|\n print \" \" if ind != 0\n print num\nend\nputs \"\"\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\n0.upto(a-1) {|i| b[i]=b[i].to_i}\nb.sort!\nif a%2==0\n0.upto (a/2-1) do |i|\nprintf \"#{b[i]} #{b[a/2+i]} \"\nend\nelse\n0.upto (a/2) do |i|\nif i!=a/2\nprintf \"#{b[i]} #{b[a/2+1+i]} \"\nelse\nprintf \"#{b[i]}\"\nend\nend\nend"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\n0.upto(a-1) {|i| b[i]=b[i].to_i}\nb.sort!\nif a%2==0\n0.upto (a/2-1) do |i|\nprintf \"#{b[i]} #{b[a/2+i]} \"\nend\nelse\n0.upto (a/2) do |i|\nif i!=a/2\nprintf \"#{b[i]} #{b[a/2+1+i]} \"\nelse\nprintf \"#{b[i]}\"\nend\nend\nend\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\n0.upto(a-1) {|i| b[i]=b[i].to_i}\nb.sort!\nif a%2==0\n0.upto (a/2-1) do |i|\nprintf \"#{b[i]} #{b[a/2+i]} \"\nend\nelse\n0.upto (a/2) do |i|\nif i!=a/2\nprintf \"#{b[i]} #{b[a/2+1+i]} \"\nelse\nprintf \"#{b[i]}\"\nend\nend\nend"}, {"source_code": "gets\na = gets.split.map(&:to_i)\na.sort!\nb = []\na.size.times do |i|\n if i.even?\n b << a.shift\n else\n b << a.pop\n end\nend\nputs b.join ' '\n"}, {"source_code": "n=gets.to_i\na=gets.split(' ')\nfor i in 0..a.size-1\n\ta[i]=a[i].to_i\nend\na=a.sort\nl=0\nr=a.size-1\nans=\"\"\nwhile l<=r\n\tans+=\" #{a[l]}\"\n\tans+=\" #{a[r]}\" if l0?sum[i-1]:0)+a[i]\n rsum[n-i-1]=(i>0?rsum[n-i]:0)+a[n-i-1]\n else\n sum[i]=sum[i-1]+a[i]-a[i-k]\n rsum[n-i-1]=rsum[n-i]+a[n-i-1]-a[n-i+k-1]\n end\n \n if i==0\n bestr[n-1]=rsum[n-1]\n bstart[n-1]=n-1\n else\n if bestr[n-i] > rsum[n-i-1]\n bestr[n-i-1] = bestr[n-i]\n bstart[n-i-1] = bstart[n-i]\n else\n bestr[n-i-1] = rsum[n-i-1]\n bstart[n-i-1] = n-i-1\n end\n end\nend\n \nmax=0\nbesta=0\nbestb=0\nfor i in k-1..n-k-1\n s = sum[i]+bestr[i+1]\n if max < s\n max = s\n besta=i\n bestb=bstart[i+1]\n end\nend\n \nputs \"#{besta+2-k} #{bestb+1}\"", "positive_code": [{"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nsum=Array.new(n)\nrsum=Array.new(n)\nbestl=Array.new(n)\nbestr=Array.new(n)\nastart=Array.new(n)\nbstart=Array.new(n)\nn.times do |i|\n if i0?sum[i-1]:0)+a[i]\n rsum[n-i-1]=(i>0?rsum[n-i]:0)+a[n-i-1]\n else\n sum[i]=sum[i-1]+a[i]-a[i-k]\n rsum[n-i-1]=rsum[n-i]+a[n-i-1]-a[n-i+k-1]\n end\n\n if i==0\n bestr[n-1]=rsum[n-1]\n bstart[n-1]=n-1\n else\n if bestr[n-i] > rsum[n-i-1]\n bestr[n-i-1] = bestr[n-i]\n bstart[n-i-1] = bstart[n-i]\n else\n bestr[n-i-1] = rsum[n-i-1]\n bstart[n-i-1] = n-i-1\n end\n end\nend\n\nmax=0\nbesta=0\nbestb=0\nfor i in k-1..n-k-1\n s = sum[i]+bestr[i+1]\n if max < s\n max = s\n besta=i\n bestb=bstart[i+1]\n end\nend\n\n#p sum\n#p rsum\n#p bestr\n#p bstart\nputs \"#{besta+2-k} #{bestb+1}\""}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\nbest = [[sum, 0]]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\n\tif sum <= best[-1][0]\n\t\tbest.push(best[-1])\n\telse\n\t\tbest.push([sum, i-k+1])\n\tend\nend\nleft, right = 0, k\n(k+1..n-k).each do |i|\n\tif best[i-k][0] + sums[i] > sums[left] + sums[right]\n\t\tleft, right = best[i-k][1], i\n\tend\nend\nputs '%d %d' % [left+1, right+1]\n"}], "negative_code": [{"source_code": "def add(heap, x)\n\theap.push(x)\n\tpos = heap.length-1\n\twhile pos != 0\n\t\tparent_pos = (pos-1)/2\n\t\tbreak if (heap[parent_pos] <=> x) >= 0\n\t\theap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]\n\t\tpos = parent_pos\n\tend\nend\ndef remove(heap, pos, heap_pos)\n\tx = heap.pop\n\treturn if heap.length == 0\n\theap[pos] = x\n\theap_pos[-heap[pos][1]] = pos\n\twhile true\n\t\tchild_pos = 2*pos+1\n\t\tbreak if child_pos >= heap.length\n\t\tif child_pos+1 < heap.length and (heap[child_pos+1] <=> heap[child_pos]) == -1\n\t\t\tchild_pos = child_pos+1\n\t\tend\n\t\tbreak if (heap[pos] <=> heap[child_pos]) >= 0\n\t\theap[child_pos], heap[pos] = heap[pos], heap[child_pos]\n\t\theap_pos[-heap[pos][1]] = pos\n\t\theap_pos[-heap[child_pos][1]] = child_pos\n\tend\nend\n\nn, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\nheap = []\n(k..n-k).each {|i| add(heap, [sums[i], -i]) }\nbest_score = 0\nheap_pos = {}\nheap.each_with_index do |item, i|\n\tsum, key = item\n\theap_pos[-key] = i\nend\nbest_indices = nil\n(0..n-2*k).each do |i|\n\tvalue, j = heap[0]\n\tscore = sums[i] + value\n\tif score > best_score\n\t\tbest_indices = [i+1, -j+1]\n\t\tbest_score = score\n\tend\n\tremove(heap, heap_pos[i+k], heap_pos)\nend\nputs best_indices.join(' ')\n"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\nleft, right = 0, k\nbest_score = sums[left] + sums[right]\nbest_left, best_right = left, right\nwhile right != n-k\n\tright += 1\n\t(right..n-k).each do |seek|\n\t\tright = seek if sums[seek] > sums[right]\n\tend\n\tleft += 1\n\t(left..right-k).each do |seek|\n\t\tleft = seek if sums[seek] > sums[left]\n\tend\n\tscore = sums[left]+sums[right]\n\tif score > best_score\n\t\tbest_score, best_left, best_right = score, left, right\n\tend\nend\nputs '%d %d' % [best_left+1, best_right+1]\nputs best_score\n"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\na, b = 0, k\n(1..n-k).each do |i|\n\tsum = sums[i]\n\tif sum > sums[a] and (i-b).abs >= k\n\t\tif (i-a).abs >= k and (sums[b] < sums[a] or (sums[b] == sums[a] and b > a))\n\t\t\tb = i\n\t\telse\n\t\t\ta = i\n\t\tend\n\telsif sum > sums[b] and (i-a).abs >= k\n\t\tb = i\n\tend\nend\nputs '%d %d' % [[a, b].min + 1, [a, b].max + 1]\n"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\nleft, right = 0, k\nbest_score = sums[left] + sums[right]\nbest_left, best_right = left, right\nwhile right != n-k\n\tright += 1\n\t(right..n-k).each do |seek|\n\t\tright = seek if sums[seek] > sums[right]\n\tend\n\tleft += 1\n\t(left..right-k).each do |seek|\n\t\tleft = seek if sums[seek] > sums[left]\n\tend\n\tscore = sums[left]+sums[right]\n\tif score > best_score\n\t\tbest_score, best_left, best_right = score, left, right\n\tend\nend\nputs '%d %d' % [best_left+1, best_right+1]\n"}, {"source_code": "def add(heap, x)\n\theap.push(x)\n\tpos = heap.length-1\n\twhile pos != 0\n\t\tparent_pos = (pos-1)/2\n\t\tbreak if (heap[parent_pos] <=> x) >= 0\n\t\theap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]\n\t\tpos = parent_pos\n\tend\nend\ndef remove(heap, pos, heap_pos)\n\tx = heap.pop\n\treturn if pos == heap.length\n\theap[pos] = x\n\theap_pos[-heap[pos][1]] = pos\n\twhile true\n\t\tchild_pos = 2*pos+1\n\t\tbreak if child_pos >= heap.length\n\t\tif child_pos+1 < heap.length and (heap[child_pos] <=> heap[child_pos+1]) == -1\n\t\t\tchild_pos = child_pos+1\n\t\tend\n\t\tbreak if (heap[pos] <=> heap[child_pos]) >= 0\n\t\theap[child_pos], heap[pos] = heap[pos], heap[child_pos]\n\t\theap_pos[-heap[pos][1]] = pos\n\t\theap_pos[-heap[child_pos][1]] = child_pos\n\tend\nend\n\nn, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\nheap = []\n(k..n-k).each {|i| add(heap, [sums[i], -i]) }\nbest_score = 0\nheap_pos = {}\nheap.each_with_index do |item, i|\n\tsum, key = item\n\theap_pos[-key] = i\nend\nbest_a, best_b = nil, nil\n(0..n-2*k).each do |a|\n\tsum, b = heap[0]\n\tscore = sums[a] + sum\n\tif score > best_score\n\t\tbest_a, best_b = a+1, -b+1\n\t\tbest_score = score\n\tend\n\tremove(heap, heap_pos[a+k], heap_pos)\nend\nputs '%d %d' % [best_a, best_b]\n#puts best_score\n"}, {"source_code": "def add(heap, x)\n\theap.push(x)\n\tpos = heap.length-1\n\twhile pos != 0\n\t\tparent_pos = (pos-1)/2\n\t\tbreak if (heap[parent_pos] <=> x) >= 0\n\t\theap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]\n\t\tpos = parent_pos\n\tend\nend\ndef remove(heap)\n\tx = heap.pop\n\treturn if heap.length == 0\n\theap[0] = x\n\tpos = 0\n\twhile true\n\t\tchild_pos = 2*pos+1\n\t\tbreak if child_pos >= x.length\n\t\tif child_pos+1 < x.length and heap[child_pos+1] > heap[child_pos]\n\t\t\tchild_pos = child_pos+1\n\t\tend\n\t\tbreak if (heap[pos] <=> heap[child_pos]) >= 0\n\t\theap[child_pos], heap[pos] = heap[pos], heap[child_pos]\n\tend\nend\n\nn, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\nheap = []\n(k..n-k).each {|i| add(heap, [sums[i], -i]) }\nbest_score = 0\nbest_indices = nil\n(0..n-2*k).each do |i|\n\tscore, j = heap[0]\n\tif score > best_score\n\t\tbest_indices = [i+1, -j+1]\n\t\tbest_score = score\n\tend\nend\nputs best_indices.join(' ')\n"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\na, b = 0, k\n(k+1..n-k).each do |i|\n\tsum = sums[i]\n\tif sum > sums[a] and i-b >= k\n\t\tif sums[b] < sums[a] and i-a >= k\n\t\t\tb = i\n\t\telse\n\t\t\ta = i\n\t\tend\n\telsif sum > sums[b] and i-a >= k\n\t\tb = i\n\tend\nend\nputs '%d %d' % [[a, b].min + 1, [a, b].max + 1]\n"}, {"source_code": "def add(heap, x)\n\theap.push(x)\n\tpos = heap.length-1\n\twhile pos != 0\n\t\tparent_pos = (pos-1)/2\n\t\tbreak if (heap[parent_pos] <=> x) >= 0\n\t\theap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]\n\t\tpos = parent_pos\n\tend\nend\ndef remove(heap, pos, heap_pos)\n\tx = heap.pop\n\treturn if pos == heap.length\n\theap[pos] = x\n\theap_pos[-heap[pos][1]] = pos\n\twhile true\n\t\tchild_pos = 2*pos+1\n\t\tbreak if child_pos >= heap.length\n\t\tif child_pos+1 < heap.length and (heap[child_pos] <=> heap[child_pos+1]) == -1\n\t\t\tchild_pos = child_pos+1\n\t\tend\n\t\tbreak if (heap[pos] <=> heap[child_pos]) >= 0\n\t\theap[child_pos], heap[pos] = heap[pos], heap[child_pos]\n\t\theap_pos[-heap[pos][1]] = pos\n\t\theap_pos[-heap[child_pos][1]] = child_pos\n\tend\nend\n\nn, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\nheap = []\n(k..n-k).each {|i| add(heap, [sums[i], -i]) }\nbest_score = 0\nheap_pos = {}\nheap.each_with_index do |item, i|\n\tsum, key = item\n\theap_pos[-key] = i\nend\nbest_a, best_b = nil, nil\n(0..n-2*k).each do |a|\n\tsum, b = heap[0]\n\tscore = sums[a] + sum\n\tif score > best_score\n\t\tbest_a, best_b = a+1, -b+1\n\t\tbest_score = score\n\tend\n\tremove(heap, heap_pos[a+k], heap_pos)\nend\nputs '%d %d' % [best_a, best_b]\nputs best_score\n"}, {"source_code": "def add(heap, x)\n\theap.push(x)\n\tpos = heap.length-1\n\twhile pos != 0\n\t\tparent_pos = (pos-1)/2\n\t\tbreak if (heap[parent_pos] <=> x) >= 0\n\t\theap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]\n\t\tpos = parent_pos\n\tend\nend\ndef remove(heap, pos, heap_pos)\n\tx = heap.pop\n\treturn if heap.length == 0\n\theap[pos] = x\n\theap_pos[-heap[pos][1]] = pos\n\twhile true\n\t\tchild_pos = 2*pos+1\n\t\tbreak if child_pos >= heap.length\n\t\tif child_pos+1 < heap.length and (heap[child_pos] <=> heap[child_pos+1]) == -1\n\t\t\tchild_pos = child_pos+1\n\t\tend\n\t\tbreak if (heap[pos] <=> heap[child_pos]) >= 0\n\t\theap[child_pos], heap[pos] = heap[pos], heap[child_pos]\n\t\theap_pos[-heap[pos][1]] = pos\n\t\theap_pos[-heap[child_pos][1]] = child_pos\n\tend\nend\n\nn, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\nheap = []\n(k..n-k).each {|i| add(heap, [sums[i], -i]) }\nbest_score = 0\nheap_pos = {}\nheap.each_with_index do |item, i|\n\tsum, key = item\n\theap_pos[-key] = i\nend\nbest_indices = nil\n(0..n-2*k).each do |i|\n\tvalue, j = heap[0]\n\tscore = sums[i] + value\n\tif score > best_score\n\t\tbest_indices = [i+1, -j+1]\n\t\tbest_score = score\n\tend\n\tremove(heap, heap_pos[i+k], heap_pos)\nend\nputs best_indices.join(' ')\n"}, {"source_code": "def add(heap, x)\n\theap.push(x)\n\tpos = heap.length-1\n\twhile pos != 0\n\t\tparent_pos = (pos-1)/2\n\t\tbreak if (heap[parent_pos] <=> x) >= 0\n\t\theap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]\n\t\tpos = parent_pos\n\tend\nend\ndef remove(heap, pos, heap_pos)\n\tx = heap.pop\n\treturn if heap.length == 0\n\theap[pos] = x\n\theap_pos[-heap[pos][1]] = pos\n\twhile true\n\t\tchild_pos = 2*pos+1\n\t\tbreak if child_pos >= heap.length\n\t\tif child_pos+1 < heap.length and (heap[child_pos] <=> heap[child_pos+1]) == -1\n\t\t\tchild_pos = child_pos+1\n\t\tend\n\t\tbreak if (heap[pos] <=> heap[child_pos]) >= 0\n\t\theap[child_pos], heap[pos] = heap[pos], heap[child_pos]\n\t\theap_pos[-heap[pos][1]] = pos\n\t\theap_pos[-heap[child_pos][1]] = child_pos\n\tend\nend\n\nn, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\nheap = []\n(k..n-k).each {|i| add(heap, [sums[i], -i]) }\nbest_score = 0\nheap_pos = {}\nheap.each_with_index do |item, i|\n\tsum, key = item\n\theap_pos[-key] = i\nend\nbest_a, best_b = nil, nil\n(0..n-2*k).each do |a|\n\tsum, b = heap[0]\n\tscore = sums[a] + sum\n\tif score > best_score\n\t\tbest_a, best_b = a+1, -b+1\n\t\tbest_score = score\n\tend\n\tremove(heap, heap_pos[a+k], heap_pos)\nend\nputs '%d %d' % [best_a, best_b]\nputs best_score\n"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\nbest = [[sum, 0]]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\n\tif sum <= best[-1][0]\n\t\tbest.push(best[-1])\n\telse\n\t\tbest.push([sum, i-k+1])\n\tend\nend\nleft, right = 0, k\n(k+1..n-k).each do |i|\n\tif best[i-k][0] + sums[i] > sums[left] + sums[right]\n\t\tleft, right = best[i-k][1], i\n\tend\nend\nputs '%d %d' % [left+1, right+1]\nputs sums[left] + sums[right]\n"}, {"source_code": "def add(heap, x)\n\theap.push(x)\n\tpos = heap.length-1\n\twhile pos != 0\n\t\tparent_pos = (pos-1)/2\n\t\tbreak if (heap[parent_pos] <=> x) >= 0\n\t\theap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]\n\t\tpos = parent_pos\n\tend\nend\ndef remove(heap, pos, heap_pos)\n\tx = heap.pop\n\treturn if heap.length == 0\n\theap[pos] = x\n\theap_pos[-heap[pos][1]] = pos\n\twhile true\n\t\tchild_pos = 2*pos+1\n\t\tbreak if child_pos >= heap.length\n\t\tif child_pos+1 < heap.length and (heap[child_pos] <=> heap[child_pos+1]) == -1\n\t\t\tchild_pos = child_pos+1\n\t\tend\n\t\tbreak if (heap[pos] <=> heap[child_pos]) >= 0\n\t\theap[child_pos], heap[pos] = heap[pos], heap[child_pos]\n\t\theap_pos[-heap[pos][1]] = pos\n\t\theap_pos[-heap[child_pos][1]] = child_pos\n\tend\nend\n\nn, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\nheap = []\n(k..n-k).each {|i| add(heap, [sums[i], -i]) }\nbest_score = 0\nheap_pos = {}\nheap.each_with_index do |item, i|\n\tsum, key = item\n\theap_pos[-key] = i\nend\nbest_a, best_b = nil, nil\n(0..n-2*k).each do |a|\n\tsum, b = heap[0]\n\tscore = sums[a] + sum\n\tif score > best_score\n\t\tbest_a, best_b = a+1, -b+1\n\t\tbest_score = score\n\tend\n\tremove(heap, heap_pos[a+k], heap_pos)\nend\nputs '%d %d' % [best_a, best_b]\n#puts best_score\n"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\nbest_score = -1\nbest_left, best_right = -1, -1\nleft, right = nil, k-1\nwhile right != n-k\n\tleft = right-k+1\n\tright += 1\n\t(right..n-k).each do |seek|\n\t\tright = seek if sums[seek] > sums[right]\n\tend\n\t(left..right-k).each do |seek|\n\t\tleft = seek if sums[seek] > sums[left]\n\tend\n\tbreak if 2*[sums[left], sums[right]].max <= best_score\n\tscore = sums[left]+sums[right]\n\tif score > best_score\n\t\tbest_score, best_left, best_right = score, left, right\n\tend\nend\nputs '%d %d' % [best_left+1, best_right+1]\n"}, {"source_code": "def add(heap, x)\n\theap.push(x)\n\tpos = heap.length-1\n\twhile pos != 0\n\t\tparent_pos = (pos-1)/2\n\t\tbreak if (heap[parent_pos] <=> x) >= 0\n\t\theap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]\n\t\tpos = parent_pos\n\tend\nend\ndef remove(heap)\n\tx = heap.pop\n\treturn if heap.length == 0\n\theap[0] = x\n\tpos = 0\n\twhile true\n\t\tchild_pos = 2*pos+1\n\t\tbreak if child_pos >= heap.length\n\t\tif child_pos+1 < heap.length and (heap[child_pos+1] <=> heap[child_pos]) == -1\n\t\t\tchild_pos = child_pos+1\n\t\tend\n\t\tbreak if (heap[pos] <=> heap[child_pos]) >= 0\n\t\theap[child_pos], heap[pos] = heap[pos], heap[child_pos]\n\tend\nend\n\nn, k = STDIN.readline.split.map {|s| s.to_i }\nvalues = STDIN.readline.split.map {|s| s.to_i }\nsum = values[0..k-1].inject(:+)\nsums = [sum]\n(k..n-1).each do |i|\n\tsum += values[i] - values[i-k]\n\tsums.push(sum)\nend\nheap = []\n(k..n-k).each {|i| add(heap, [sums[i], -i]) }\nbest_score = 0\nbest_indices = nil\n(0..n-2*k).each do |i|\n\tvalue, j = heap[0]\n\tscore = sums[i] + value\n\tif score > best_score\n\t\tbest_indices = [i+1, -j+1]\n\t\tbest_score = score\n\tend\n\tremove(heap)\nend\nputs best_indices.join(' ')\n"}], "src_uid": "74095fe82bd22257eeb97e1caf586499"} {"source_code": "x = gets.chomp.to_i;\na = gets.strip.split(' ').map(&:to_i);\n\na = a.sort;\nfor i in 0 ... (x - 1) / 2\t \n\ta[i] = 0;\n\ta[a.length - i - 1] = 0;\nend\n\na.each do |num| \n\tif num != 0\n\t\tputs num;\n\t\texit;\n\tend\n\nend", "positive_code": [{"source_code": "# cook your code here\n\nn = gets.to_i \n\narr = gets.split.map { |x| x.to_i } \n\narr = arr.sort! \n\nputs arr[(n-1)/2]"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort;p a[~-a.size/2]"}, {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\nputs as.sort[(n.to_f/2).ceil-1]"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i).sort\nx = n / 2\nx -= 1 if n.even?\nputs a[x]"}, {"source_code": "# -*- coding: utf-8 -*-\n\nn = gets.to_i\nar = gets.split.map(&:to_i)\nar.sort!\nif n.odd?\n puts ar[n/2]\nelse\n puts ar[n/2 - 1]\nend"}, {"source_code": "r = -> { gets.split.map &:to_i }\n\nn = r[].first\n\narr = r[].sort\n\np arr[(n - 1) / 2]\n"}, {"source_code": "n = gets.to_i\nputs gets.split.map(&:to_i).sort[(n - 1) / 2]"}, {"source_code": "n = gets.to_i\nputs gets.split.map(&:to_i).sort[(n - 1) / 2]\n"}], "negative_code": [{"source_code": "gets;a=gets.split.map(&:to_i).sort;p a[-~a.size/2]"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort;p a[a.size/2]"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i).sort\nputs a[n / 2]"}, {"source_code": "x = gets.chomp.to_i;\na = gets.strip.split(' ').map(&:to_i);\n\nfor i in 0 ... x / 2\t \n\ta[i] = 0;\n\ta[a.length - i - 1] = 0;\nend\n\na.each do |num| \n\tif num.nonzero?\n\t\tputs num;\n\t\texit;\n\tend\n\nend"}, {"source_code": "x = gets.chomp.to_i;\na = gets.strip.split(' ').map(&:to_i);\n\na = a.sort;\nfor i in 0 ... x / 2\t \n\ta[i] = 0;\n\ta[a.length - i - 1] = 0;\nend\n\na.each do |num| \n\tif num != 0\n\t\tputs num;\n\t\texit;\n\tend\n\nend"}], "src_uid": "f93a8bd64a405233342f84542fce314d"} {"source_code": "t = gets.chomp.to_i\nt.times do \n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n hash = Hash.new(0)\n a.each do |i|\n ii = i.to_s(2).size\n hash[ii] += 1\n end\n count = 0\n hash.each do |i,j|\n if j >= 2\n ans = (j * (j-1)) / 2\n count += ans\n end\n end\n puts count\nend", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n ans = 0\n counter = Hash.new(0)\n\n a.each do |x|\n l = x.to_s(2).size\n ans += counter[l]\n counter[l] += 1\n end\n\n puts ans\nend\n"}], "negative_code": [], "src_uid": "04e2e1ce3f0b4efd2d4dda69748a0a25"} {"source_code": "r = []\ngets.to_i.times { |i|\nar = gets.split(' ').map{ |x| x.to_i }\nif ar[0] != 0 then r.push(Rational(-ar[1], ar[0])); end\n}\n\nputs r.uniq.size\n", "positive_code": [{"source_code": "r = []\ngets.to_i.times { |i|\nar = gets.split(' ').map{ |x| x.to_i }\nif ar[0] != 0 then r.push(Rational(-ar[1], ar[0])); end\n}\n\nputs r.uniq.size\n"}, {"source_code": "r = []\ngets.to_i.times { |i|\nar = gets.split(' ').map{ |x| x.to_i }\nif ar[0] != 0 then r.push(Rational(-ar[1], ar[0])); end\n}\n\nputs r.uniq.size\n"}, {"source_code": "r = []\ngets.to_i.times { |i|\nar = gets.split(' ').map{ |x| x.to_i }\nif ar[0] != 0 then r.push(Rational(-ar[1], ar[0])); end\n}\n\nputs r.uniq.size\n"}, {"source_code": "#!/usr/bin/ruby\nrequire 'set'\nn = $stdin.gets.to_i\ns = Set.new\nn.times do |i|\n k, b = *$stdin.gets.split.map(&:to_i)\n if k != 0\n s.add -b.to_r/k\n end\nend\nputs s.size\n"}, {"source_code": "r = []\ngets.to_i.times { |i|\nar = gets.split(' ').map{ |x| x.to_i }\nif ar[0] != 0 then r.push(Rational(-ar[1], ar[0])); end\n}\n\nputs r.uniq.size\n"}, {"source_code": "r = []\ngets.to_i.times { |i|\nar = gets.split(' ').map{ |x| x.to_i }\nif ar[0] != 0 then r.push(Rational(-ar[1], ar[0])); end\n}\n\nputs r.uniq.size\n"}, {"source_code": "r = []\ngets.to_i.times { |i|\nar = gets.split(' ').map{ |x| x.to_i }\nif ar[0] != 0 then r.push(Rational(-ar[1], ar[0])); end\n}\n\nputs r.uniq.size\n"}, {"source_code": "r = []\ngets.to_i.times { |i|\nar = gets.split(' ').map{ |x| x.to_i }\nif ar[0] != 0 then r.push(Rational(-ar[1], ar[0])); end\n}\n\nputs r.uniq.size"}, {"source_code": "r = []\ngets.to_i.times { |i|\nar = gets.split(' ').map{ |x| x.to_i }\nif ar[0] != 0 then r.push(Rational(-ar[1], ar[0])); end\n}\n\nputs r.uniq.size\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nn = $stdin.gets.to_i\nh = Hash.new { |h, k| h[k] = [] }\nn.times do\n k, b = *$stdin.gets.split.map(&:to_i)\n if k != 0\n h[-b.to_r/k].push k\n end\nend\nans = 0\nh.values.each do |a|\n if a.inject(0, :+) != 0\n ans += 1\n end\nend\nputs ans\n"}, {"source_code": "#!/usr/bin/ruby\nn = $stdin.gets.to_i\nh = Hash.new { |h, k| h[k] = [] }\nn.times do\n k, b = *$stdin.gets.split.map(&:to_i)\n if k != 0\n h[b.to_r/k].push k\n end\nend\nans = 0\nh.values.each do |a|\n x = 0\n y = 0\n a.each do |k|\n x += k\n end\n if x != 0\n ans += 1\n end\nend\nputs ans\n"}], "src_uid": "d436c7a3b7f07c9f026d00bdf677908d"} {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# c.rb\n\ndef main()\n n, a = gets.chomp.split(\" \").map{|s| next s.to_i }\n d = gets.chomp.split(\" \").map{|s| next s.to_i }\n s = d.inject{|ret, i| next ret + i }\n r = []\n d.each_with_index do |di, i|\n ss = s - di\n least = [1, a - ss].max\n most = [di, a - (n - 1)].min\n cand = most - least + 1\n r << di - cand\n end\n \n puts(r * \" \")\nend\n \nif __FILE__ == $0 then\n main()\nend\n", "positive_code": [{"source_code": "n,a = gets.split.map(&:to_i)\nd = gets.split.map(&:to_i)\nsum = d.inject(:+)\n\nans = d.map do |di|\n less = [0, a - (sum - di) - 1].max\n more = [0, di - (a - (n - 1))].max\n\n less + more\nend\n\nputs ans.join(' ')\n"}, {"source_code": "n, sum = gets.split(' ').map(&:to_i)\nds = gets.split(' ').map(&:to_i)\nmax = ds.reduce(:+)\n\nn.times do |i|\n d = ds[i]\n other_max = max-d\n\n my_min = 1\n if sum > other_max\n my_min = sum-other_max\n end\n my_max = [sum - (n-1), d].min\n\n print ' ' if i != 0\n print (d - [(my_max-my_min+1), 0].max)\nend\nprint \"\\n\"\n"}], "negative_code": [], "src_uid": "2c51414eeb430ad06aac53a99ff95eff"} {"source_code": "l, r, k = gets.chomp.split(' ').map(&:to_i)\n\nans = []\n\npower = 1\n\nwhile power <= r do\n if power >= l then\n ans << power\n end\n power *= k\nend\n\nif ans.size == 0 then\n puts -1\nelse\n puts ans.join(' ')\nend\n", "positive_code": [{"source_code": "l, r, k = gets.split.map(&:to_i)\n\na = 1\n\na *= k while a < l\n\nf = true\n\nwhile a <= r\n print \" \" if not f\n f = false\n print a\n a *= k\nend\n\nif f\n puts \"-1\"\nelsif\n puts\nend"}, {"source_code": "l, r, k = gets.split.map(&:to_i)\nx = 1\ndone = 0\nwhile x<=r\n if x>=l\n print(x,\" \")\n done=1\n end\n x*=k\nend\n\nif done==0\n p -1\nend"}, {"source_code": " require 'scanf'\n\n\tx=scanf(\"%d\")[0]\n y=scanf(\"%d\")[0]\n k=scanf(\"%d\")[0]\n\to=1\n\tch=1\n\twhile o=x&&o<=y\n\t \n\t\tprint o\n print \" \"\n\t\to*=k\n\t\tch=0\n\tend\n\tif ch==1\n\t\tputs -1\n\tend\n\n\n\n"}, {"source_code": "require 'scanf'\n\n\nwhile s = $stdin.gets() do\n l, r, k = s.scanf(\"%d %d %d\")\n n = 1\n f = false\n while n <= r do\n if l <= n && n <= r then\n if f then\n print(\" \") \n end\n f = true\n print(n)\n end\n n *= k;\n end\n if f then\n puts(\"\");\n else\n puts(\"-1\");\n end\nend\n"}, {"source_code": "l,r,k = gets.chomp.split.map(&:to_i)\nans = []\nc = 1\nwhile c <= r\n ans << c if l <= c\n c *= k\nend\n\nputs ans.size == 0 ? -1 : ans.join(\" \")\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end\n############################################################\n\nl, r, k = gis\nv = 1\na = []\nloop do\n if v <= r\n a << v if v >= l\n else\n break\n end\n v *= k\nend\n\nif a.empty?\n puts '-1'\nelse\n puts a * \" \"\nend"}, {"source_code": "l,r,k=gets.split.map(&:to_i)\na=[]\n64.times{|i|a.push k**i if k**i>=l&&k**i<=r}\nputs (a.last)? a.join(' '):-1"}, {"source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\n\nans=0\ni=0\nloop do\nif a[2]**i>=a[0] && a[2]**i<=a[1]\nprintf \"#{a[2]**i} \"\nans+=1\nend\ni+=1\nbreak if a[2]**i>a[1]\nend\nif ans==0\nputs \"-1\"\nend\n"}, {"source_code": "l,r,k=gets.split.map(&:to_i)\na=[]\n64.times{|i|a.push k**i if k**i>=l&&k**i<=r}\nputs (a.last)? a.join(' '):-1"}, {"source_code": "l,r,k=gets.split.map(&:to_i)\nans=[]\n64.times do |i|\n\tbreak if k**i>r\n\tans.push k**i if k**i>=l\nend\nans=[-1] if !ans.last\nputs ans.join(' ')"}, {"source_code": "l, r, k = gets.chomp.split.map(&:to_i)\n\nll = (Math.log(l) / Math.log(k)).round\nlr = (Math.log(r) / Math.log(k)).round\nns = (ll..lr).map { |x| k**x }.select { |x| l <= x && x <= r }\n\nif ns.size == 0\n puts -1\nelse\n puts ns.*' '\nend\n"}, {"source_code": "def solve(l, r, k)\n ans = []\n p = 0\n while k**p <= r do\n ans << k**p\n p+= 1\n end\n ret = []\n for i in ans do\n if i >= l && i <= r\n ret << i \n end\n end\n return -1 if ret.length == 0\n return ret.join(' ')\nend\nl, r, k = gets.strip.split(\" \").map(&:to_i)\nputs solve(l, r, k)"}, {"source_code": "\ns = gets.to_s\n\nm = Array.new(s.split(\" \"))\n\nl = m[0].to_i\nr = m[1].to_i\nk = m[2].to_i\n\ns = \"\"\n\nfor i in 0 ... 74\n\tp = k ** i\n\tif l <= p && p <= r\n\t\ts += (p.to_s + \" \")\n\tend\nend\n\nif s == \"\" then puts \"-1\"\nelse puts s end\n"}, {"source_code": "a = gets.chomp.split(\" \").map{|x| x.to_i}\nkek = 0\npurkka = false\na[1].times do |i|\n s = a[2] ** i\n if s <= a[1] and s >= a[0]\n puts s\n purkka = true\n elsif (s > a[1])\n break\n end\nend\nputs \"-1\" if not purkka\n"}, {"source_code": "#!/usr/bin/ruby\n\nl,r,k = gets.strip.split.map {|num| num.to_i}\n\nnum = k\nwhile num < l do\n\tnum *= k\nend\n\nif l == 1\n\tnum = 1\nend\n\nif l <= num and num <= r\n\twhile l <= num and num <= r do\n\t\tprint num\n\t\tprint ' '\n\t\tnum *= k\n\tend\n\tputs ''\nelse\n\tputs -1\nend"}, {"source_code": "numbers = gets.split(\" \")\nfirst = numbers[0].to_i\nlast = numbers[1].to_i\npotencial = numbers[2].to_i\nres = \"\"\nfirst_exponencial = Math.log10(first)/Math.log10(potencial)\nlast_exponencial = Math.log(last)/Math.log10(potencial)\narray = []\nif first_exponencial - first_exponencial.to_i > 0\n\tfirst_exponent = first_exponencial.to_i + 1\nelse\n\tfirst_exponent = first_exponencial.to_i\nend\nfor i in first_exponent.to_i..last_exponencial.to_i\n\tif potencial ** i <= last && potencial**i >= first\n\t\tarray << potencial ** i\n\tend\nend\narray.each do |current|\n\tres << current.to_s + \" \"\nend\nif array.size == 0\n\tputs \"-1\"\nelse\n\tputs res\nend"}, {"source_code": "l, r, k = gets.chomp.split(\" \").map(&:to_i)\n\nfrom = Math.log(l, k)\nto = Math.log(r, k)\n\na = ((from.floor)..(to.ceil)).to_a.map{|i| k**i}.keep_if{|i| i >= l and i <= r}\nif a.length == 0 then\n puts -1\nelse\n puts a.join(\" \")\nend"}, {"source_code": "input = gets.chomp\ni = input.split(\" \")\n\nl = i[0].to_i\nr = i[1].to_i\nk = i[2].to_i\n\naux = 1\nflag = false\n\nwhile aux<=r\n\tif aux>=l\n\t\tflag = true\n\t\tprint \"#{aux} \"\n\tend\n\taux *= k\nend\n\nif !flag\n\tprint \"-1 \"\nend\n\nprint \"\\n\"\n"}, {"source_code": "l,r,k = gets.split.map(&:to_i)\n\nx=1\nt=0\n\n60.times{\n if (x>=l && x<=r)\n print x , \" \"\n t=1\n end\n\n x=x*k\n if (x>r) then break; end\n}\n\nif (t==0)\n print -1\nend"}, {"source_code": "class Solver\n\tdef main\n\t\tl, r, k = gets.split.map { |x| x.to_i }\n\t\tans = []\n\t\t64.times do |i|\n\t\t\tx = k ** i\n\t\t\tans << x if x.between? l, r\n\t\tend\n\t\tif ans.empty?\n\t\t\tputs -1\n\t\telse\n\t\t\tputs ans.join ' '\n\t\tend\n\tend\nend\n\nSolver.new.main\n"}], "negative_code": [{"source_code": "a=gets.chomp.split(\" \")\nnum=a[2].to_i\nmin=(Math.log(a[0].to_i,num)).ceil\nmax=(Math.log(a[1].to_i,num)).floor\nif min-max==1 \nputs \"-1\"\nelse\nmin.upto(max) do |i|\nprintf \"#{num**i} \"\nend\nend"}, {"source_code": "def solve(l, r, k)\n if k < l || k > r \n return \"-1\"\n end\n printed = false\n p = 0\n ans = \"\"\n while k**p <= r do\n if k**p >= l\n ans << (k**p).to_s << \" \"\n printed = true\n end\n p += 1\n end\n return \"-1\" if printed == false\n return ans.strip\nend\nl, r, k = gets.strip.split(\" \").map(&:to_i)\nputs solve(l, r, k)"}, {"source_code": "def solve(l, r, k)\n if k < l || k > r \n return \"-1\"\n end\n printed = false\n p = 0\n ans = \"\"\n while k**p <= r do\n ans << k**p << \" \"\n p += 1\n printed = true\n end\n return \"-1\" if printed == false\n return ans.strip\nend\nl, r, k = gets.strip.split(\" \").map(&:to_i)\nputs solve(l, r, k)"}, {"source_code": "def solve(l, r, k)\n if k < l || k > r \n return \"-1\"\n end\n printed = false\n p = 0\n ans = \"\"\n while k**p <= r do\n ans << (k**p).to_s << \" \"\n p += 1\n printed = true\n end\n return \"-1\" if printed == false\n return ans.strip\nend\nl, r, k = gets.strip.split(\" \").map(&:to_i)\nputs solve(l, r, k)"}, {"source_code": "numbers = gets.split(\" \")\nfirst = numbers[0].to_i\nlast = numbers[1].to_i\npotencial = numbers[2].to_i\nres = \"\"\nfirst_exponencial = Math.log10(first)/Math.log10(potencial)\nlast_exponencial = Math.log(last)/Math.log10(potencial)\narray = []\nif first_exponencial - first_exponencial.to_i > 0\n\tfirst_exponent = first_exponencial.to_i + 1.0\nelse\n\tfirst_exponent = first_exponencial.to_i\nend\nfor i in first_exponent.to_i..last_exponencial.to_i\n\tif potencial ** i <= last + 1\n\t\tarray << potencial ** i\n\tend\nend\narray.each do |current|\n\tres << current.to_s + \" \"\nend\nif array.size == 0\n\tputs \"-1\"\nelse\n\tputs res\nend"}, {"source_code": "numbers = gets.split(\" \")\nfirst = numbers[0].to_i\nlast = numbers[1].to_i\npotencial = numbers[2].to_i\nres = \"\"\nfirst_exponencial = Math.log(first, potencial)\nlast_exponencial = Math.log(last, potencial)\narray = []\nif first_exponencial - first_exponencial.to_i > 0\n\tfirst_exponent = first_exponencial.to_i + 1\nelse\n\tfirst_exponent = first_exponencial.to_i\nend\nfor i in first_exponent.to_i..last_exponencial.to_i\n\tif potencial ** i <= last\n\t\tarray << potencial ** i\n\tend\nend\narray.each do |current|\n\tres << current.to_s + \" \"\nend\nif array.size == 0\n\tputs \"-1\"\nelse\n\tputs res\nend"}, {"source_code": "numbers = gets.split(\" \")\nfirst = numbers[0].to_i\nlast = numbers[1].to_i\npotencial = numbers[2].to_i\nres = \"\"\nfirst_exponencial = Math.log(first, potencial)\nlast_exponencial = Math.log(last, potencial)\narray = []\nif first_exponencial - first_exponencial.to_i > 0\n\tfirst_exponent = first_exponencial.to_i + 1\nelse\n\tfirst_exponent = first_exponencial.to_i\nend\nfor i in first_exponent.to_i..last_exponencial.to_i\n\tif potencial ** i < last\n\t\tarray << potencial ** i\n\tend\nend\narray.each do |current|\n\tres << current.to_s + \" \"\nend\nif array.size == 0\n\tputs \"-1\"\nelse\n\tputs res\nend"}, {"source_code": "numbers = gets.split(\" \")\nfirst = numbers[0].to_i\nlast = numbers[1].to_i\npotencial = numbers[2].to_i\nres = \"\"\nfirst_exponencial = Math.log(first, potencial)\nlast_exponencial = Math.log(last, potencial)\narray = []\nif first_exponencial - first_exponencial.to_i > 0\n\tfirst_exponent = first_exponencial.to_i + 1\nelse\n\tfirst_exponent = first_exponencial.to_i\nend\nfor i in first_exponent.to_i..last_exponencial.to_i\n\tarray << potencial ** i\nend\narray.each do |current|\n\tres << current.to_s + \" \"\nend\nif array.size == 0\n\tputs \"-1\"\nelse\n\tputs res\nend"}, {"source_code": "numbers = gets.split(\" \")\nfirst = numbers[0].to_i\nlast = numbers[1].to_i\npotencial = numbers[2].to_i\nres = \"\"\nfirst_exponencial = Math.log10(first)/Math.log10(potencial)\nlast_exponencial = Math.log(last)/Math.log10(potencial)\narray = []\nif first_exponencial - first_exponencial.to_i > 0\n\tfirst_exponent = first_exponencial.to_i + 1\nelse\n\tfirst_exponent = first_exponencial.to_i\nend\nfor i in first_exponent.to_i..last_exponencial.to_i\n\tif potencial ** i <= last\n\t\tarray << potencial ** i\n\tend\nend\narray.each do |current|\n\tres << current.to_s + \" \"\nend\nif array.size == 0\n\tputs \"-1\"\nelse\n\tputs res\nend"}, {"source_code": "l, r, k = gets.chomp.split(\" \").map(&:to_i)\n\nfrom = Math.log(l, k)\nto = Math.log(r, k)\n\nif to.floor - from.ceil <= 0 then\n puts -1\nelse\n puts ((from.ceil)..(to.floor)).to_a.map{|i| k**i}.join(\" \")\nend"}], "src_uid": "8fcec28fb4d165eb58f829c03e6b31d1"} {"source_code": "gets\nm=$<.map{|e|e.chomp.split.map(&:to_i)}\np [m,m.transpose].reduce(0){|r,m|\n c=0\n m.each{|e|\n s=e.count 1\n l=e.size\n if s==1\n c+=l-1\n elsif s>1\n x=e.index 1\n y=e.reverse.index 1\n c+=x+2*(l-(x+y)-s)+y\n end\n }\n r+c\n}", "positive_code": [{"source_code": "def f(m)\n c=0\n m.each{|e|\n s=e.count 1\n l=e.size\n if s==1\n c+=l-1\n elsif s>1\n x=e.index 1\n y=e.reverse.index 1\n c+=x+2*(l-(x+y)-s)+y\n end\n }\n c\nend\ngets\nm=$<.map{|e|e.chomp.split.map(&:to_i)}\np f(m)+f(m.transpose)"}], "negative_code": [{"source_code": "H,W=gets.split.map(&:to_i)\nm=$<.map{|e|e.chomp.tr(' ','').chars}\ncol=m.map{|e|e.join.to_i(2)}.reduce(:&)\nrow=m.transpose.map{|e|e.join.to_i(2)}.reduce(:&)\nr=0\nH.times{|h|W.times{|w|\n r+=1 if m[h][w]=='0' and col[w]>0||row[h]>0\n}}\np r"}], "src_uid": "c3a7d82f6c3cf8678a1c7c521e0a5f51"} {"source_code": "t = gets.chomp.to_i\nwhile t>0 do\n tmp = gets.chomp.split(\" \")\n n = tmp[0].to_i\n k = tmp[1].to_i\n a = gets.chomp.split(\" \")\n cnt = Array.new(205,0)\n for i in 0..n-1\n cnt[a[i].to_i] += 1\n end\n ans = 1\n while k>=0 do\n if cnt[ans]==0 then\n k -= 1\n end\n ans += 1\n end\n puts ans-2\n t -= 1\nend", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n n, x = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i).sort.uniq\n v = 0\n a.each do |aa|\n if aa - (v + 1) <= x\n x -= aa - (v + 1)\n v = aa\n else\n break\n end\n end\n v += x\n puts v\nend\n"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\nwhile t>0 do\n tmp = gets.chomp.split(\" \")\n n = tmp[0].to_i\n k = tmp[1].to_i\n a = gets.chomp.split(\" \")\n cnt = Array.new(205,0)\n for i in 0..n-1\n cnt[a[i].to_i] += 1\n end\n ans = 1\n while k>=0 do\n if cnt[ans]==0 then\n k -= 1\n end\n ans += 1\n end\n puts ans-1\n t -= 1\nend"}], "src_uid": "e5fac4a1f3a724234990fe758debc33f"} {"source_code": "input = File.open(\"input.txt\", \"r\")\noutput = File.open(\"output.txt\", \"w\")\n\nn, k = input.gets.split.map(&:to_i)\nrin = input.gets.split\n\na = Array.new\nfor i in 0...n\n a << [rin[i].to_i, i+1]\nend\n\na.sort! {|x, y| x[0] <=> y[0]}\na = a.drop(n-k)\noutput.puts a[0][0]\n\na.sort! {|x, y| x[1] <=> y[1]}\na.each {|x| output.print x[1], \" \"}\n\ninput.close\noutput.close", "positive_code": [{"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\n(n,k),a=gets.split.map(&:to_i),gets.split.map(&:to_i)\nz=p a.sort[-k]\nb=[]\nn.times{|i|\n\tb<=z\n}\nputs b.sort[0...k]*' '\n"}, {"source_code": "File.open(\"input.txt\", \"r\") do |input|\n\tFile.open(\"output.txt\", \"w\") do |output|\n\t\tn, k = input.readline.split.map(&:to_i)\n\t\toutput << input.readline.split.map(&:to_i).zip((1..n).to_a).sort {|x, y| y.first <=> x.first}.take(k).reduce([101, []]) { |s, (x, y)| \n\t\t\t[[s.first, x].min, s.last + [y]] \n\t\t}.join(' ')\n\tend\nend"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nI = ->{gets.split.map(&:to_i)}\nn, m = I[]\na = I[].zip([*1..n]).sort[n - m, m]\np a[0][0]\nputs a.map{|_| _[1]} * ' '\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\n(n,k),a=gets.split.map(&:to_i),gets.split.map(&:to_i)\nz=p a.sort[-k]\nb=[]\nn.times{|i|\n\tb<=z\n}\nputs b.sort[0...k]*' '\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt', 'w')\na,b=Array.new,Array.new\nn,a=gets.split.map(&:to_i)[1],gets.split.map(&:to_i)\nputs a.sort[-n]\nn.times do\nb<=z\n}\nputs b.sort[0...k]*' '\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\n(n,k),a=gets.split.map(&:to_i),gets.split.map(&:to_i)\nz=p a.sort[-k]\nb=[]\nn.times{|i|\n\tb<=z\n}\nputs b.sort[0...k]*' '"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\ndef search(a,b,n)\n\tn.times do |i|\n\t\tif a[i]==b\n\t\t\ta[i]=101\n\t\t\treturn i+1\n\t\tend\n\tend\nend\nn,k=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i)\nb=a.sort\nputs b[n-k]\nfor i in (n-k)...n\n\tprint(\"#{search(a,b[i],n)} \")\nend\nputs"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn, m = gets.split.map{|i| i.to_i}\na = gets.split.map{|i| i.to_i}\np mins = a.sort[-m]\nb = []\nn.times do |i|\n b << i + 1 if a[i] >= mins\nend\nputs b.sort[0...m]*' '"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\n(n,k),a=gets.split.map(&:to_i),gets.split.map(&:to_i)\nz=p a.sort[-k]\nb=[]\nn.times{|i|\n\tb<=z\n}\nputs b.sort[0...k]*' '\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\n(n,k),a=gets.split.map(&:to_i),gets.split.map(&:to_i)\nz=p a.sort[-k]\nb=[]\nn.times{|i|\n\tb<=z\n}\nputs b.sort[0...k]*' '\n"}, {"source_code": "n = 0\nk = 0\narr = []\nopen(\"input.txt\") {|f|\n n, k = f.gets.split.map(&:to_i)\n arr = f.gets.to_s.chomp.split.map(&:to_i)\n}\nFile.open(\"output.txt\", \"w\"){|f|\n arr2 = []\n i = 0\n arr.each do |a|\n i += 1\n arr2.push([i, a])\n end\n arr2.sort! {|a,b| a[1] <=> b[1] }\n f.write \"#{arr2[n-k][1]}\\n\"\n k.times do |i|\n f.write \"#{arr2[n-k+i][0]}\"\n if i != k-1\n f.write \" \"\n else\n f.write \"\\n\" if i == k-1\n end\n end\n}"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\n(n,k),a=gets.split.map(&:to_i),gets.split.map(&:to_i)\nz=p a.sort[-k]\nb=[]\nn.times{|i|\n b<=z\n}\nputs b.sort[0...k]*' '"}, {"source_code": "n,k=0\na=[]\nFile.open(\"input.txt\") { |f|\n n,k=f.gets.split.map(&:to_i)\n a=f.gets.split.map(&:to_i)\n}\nb=[]\na.each_with_index do |v,i|\n b.push([-v,i+1])\nend\nb.sort!\nFile.open(\"output.txt\", \"w\") { |f|\n f.puts -b[k-1][0]\n for i in 0..k-1\n f.print \"#{b[i][1]} \"\n end\n}\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\n(n,k),a=gets.split.map(&:to_i),gets.split.map(&:to_i)\nz=p a.sort[-k]\nb=[]\nn.times{|i|\n\tb<=z\n}\nputs b.sort[0...k]*' '"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\n(n,k),a=gets.split.map(&:to_i),gets.split.map(&:to_i)\nz=p a.sort[-k]\nb=[]\nn.times{|i|\n\tb<=z\n}\nputs b.sort[0...k]*' '\n"}, {"source_code": "line = File.read(\"input.txt\")\n\ninputs = line.split(\"\\n\")\n\nn,k = inputs[0].split(\" \").map(&:to_i)\narr = inputs[1].split(\" \").map(&:to_i)\nlist = arr.each_with_index.map { |a,i| [a,i] }\n\nlist.sort!\n# puts \"#{list.min}\"\nans = list[((-k)..-1)]\n\nFile.open(\"output.txt\", 'w') { |file| \n\tfile.puts \"#{ans.min[0]}\"\n\tfile.puts ans.map { |e| e[1]+1 }.join(\" \")\n}\n\n\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\n(n,k),a=gets.split.map(&:to_i),gets.split.map(&:to_i)\nz=p a.sort[-k]\nb=[]\nn.times{|i|\n\tb<=z\n}\nputs b.sort[0...k]*' '\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\n(n,k),a=gets.split.map(&:to_i),gets.split.map(&:to_i)\nz=p a.sort[-k]\nb=[]\nn.times{|i|\n\tb<=z\n}\nputs b.sort[0...k]*' '\n"}], "negative_code": [{"source_code": "input = File.open(\"input.txt\", \"r\")\noutput = File.open(\"output.txt\", \"w\")\n\nn, k = input.gets.split.map(&:to_i)\nrin = input.gets.split\n\na = Array.new\nfor i in 0...n\n a << [rin[i].to_i, i+1]\nend\n\na.sort! {|x, y| x[0] <=> y[0]}\na = a.drop(n-k)\nputs a[0][0]\n\na.sort! {|x, y| x[1] <=> y[1]}\na.each {|x| print x[1], \" \"}\n\ninput.close\noutput.close"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn, m = gets.split.map{|i| i.to_i}\na = gets.split.map{|i| i.to_i}\np mins = a.sort[-m]\nb = []\nn.times do |i|\n b << i + 1 if a[i] >= mins\nend\nputs b.join \" \""}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn, m = gets.split.map{|i| i.to_i}\na = gets.split.map{|i| i.to_i}\np a.sort\np mins = a.sort[-m]\nb = []\nn.times do |i|\n b << i + 1 if a[i] >= mins\nend\nputs b.join \" \""}, {"source_code": "n,k=0\na=[]\nFile.open(\"input.txt\") { |f|\n n,k=f.gets.split.map(&:to_i)\n a=f.gets.split.map(&:to_i)\n}\nb=[]\na.each_with_index do |v,i|\n b.push([-v,i+1])\nend\nb.sort!\nFile.open(\"output.txt\", \"w\") { |f|\n for i in 0..k-1\n f.print \"#{b[i][1]} \"\n end\n}\n"}], "src_uid": "a585045a9a6f62bfe1c0618c2ee02f48"} {"source_code": "require \"Prime\"\na=gets.chomp.to_i\nb=(Math.sqrt(a)).floor\nsp=[]\np=[]\nPrime.each(a) do|i|\nif i<=b\nsp<t \n p+=1\nend\n\nif p==n\n\tputs 0\n\texit\nend\n\nfirst = p\n q = p\nmax = 1\ncrt = 1\nsum = 0\n#puts p \n#puts q\n#puts line\nwhile qmax\n\t\t\tmax = q-p+1\n\t\tend\n\telse\n\t\twhile p<=q and sum>t\n\t\t\tsum -= line[p]\n\t\t\tp += 1\n\t\tend\n\tend\n\tq += 1\nend\n\nputs max\n\n", "positive_code": [{"source_code": "def read_next_line\n gets.split.map { |x| x.to_i }\nend\n\nn, t = read_next_line\na = read_next_line\n\np = cur_time = 0\nmax = -1_000_000_001\nfor i in 0...n\n cur_time += a[i]\n while cur_time > t\n cur_time -= a[p]\n p += 1\n end\n cur = i - p\n max = cur if cur > max\nend\nputs max + 1"}, {"source_code": "n, t = gets.split.map(&:to_i)\nl=0\nr=-1\nsum=0\nan = 0\na = gets.split.map(&:to_i)\na.each do |key| \n\twhile (sum+key>t)\n\t\tsum -= a[l]\n\t\tl += 1\n\tend\n\tsum += key\n\tr += 1\n\tan = [an, r-l+1].max\nend\nputs an"}, {"source_code": "n, t = gets.split.map(&:to_i)\nl=0\nr=-1\nsum=0\nans = 0\na = gets.split.map(&:to_i)\na.each do |key| \n\twhile (sum+key>t)\n\t\tsum -= a[l]\n\t\tl += 1\n\tend\n\tsum += key\n\tr += 1\n\tans = [ans, r-l+1].max\nend\nputs ans"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn, t = STDIN.readline.split.collect {|s| s.to_i }\na = STDIN.readline.split.collect {|s| s.to_i }\n\nmax = 0\nleft = right = 0\nsum = 0\n\nwhile right != n\n\tsum += a[right]\n\tright += 1\n\twhile sum > t\n\t\tsum -= a[left]\n\t\tleft += 1\n\tend\n\tif right-left > max\n\t\tmax = right-left\n\tend\nend\n\nputs max\n"}, {"source_code": "n,t=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i)\ns,l,ans=0,0,0\na.count.times do |i|\n\ts+=a[i]\n\twhile s>t\n\t\ts-=a[l]\n\t\tl+=1\n\tend\n\td=(i-l+1)\n\tans=d if ans time && sum > 0)\n\n sum-=eachBookTime[first]\n\n first+=1\n\n count-=1\n\n end\n\n\n\n if(item < time)\n\n sum+=item\n\n count+=1\n\n max = count if count > max\n\n else\n\n sum+=item\n\n count+=1\n\n end\n\n \n\nend\n\n\n\nputs max"}, {"source_code": "def dp(str)\n puts str if false\nend\n\ndef run\n n, t = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n\n sum = pos = max = val = 0\n n.times do |i|\n dp \"sum = #{sum}, a[pos] = #{a[pos]}\"\n while pos < n and a[pos] + sum <= t\n dp \"pos = #{pos}\"\n sum += a[pos]\n pos = pos + 1\n end\n\n val = pos - i\n sum -= a[i]\n dp \"[in] i = #{i}, max = #{max}, pos = #{pos}, sum = #{sum}, val = #{val}\"\n max = [max, val].max\n dp \"[out] i = #{i}, max = #{max}, pos = #{pos}, sum = #{sum}, val = #{val}\"\n end\n\n puts max\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n n, t = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n\n sum = pos = max = val = 0\n n.times do |i|\n while pos < n and a[pos] + sum <= t\n sum += a[pos]\n pos += 1\n end\n\n max = [max, pos - i].max\n sum -= a[i]\n end\n\n puts max\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\n\nans=0\nr=0\nl=0\nsum=x[0]\nwhile rm && lm\n\t\tsum+=x[r+1]\n\t\tr+=1\n\tend\n\tans=[ans,r-l+1].max\n\t#p [l,r,sum,ans]\n\tbreak if r==n-1\n\tsum+=x[r+1]\n\tr+=1\nend\nputs ans\n\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\ndef bsearch(arr, b, goal)\n e = arr.length\n while b < e\n mid = (b + e)/2\n if arr[mid] == goal\n b = mid\n break\n elsif arr[mid] < goal\n b = mid\n if e - b == 1\n break\n end\n else\n e = mid\n if e - b == 1\n break\n end\n end\n end\n return b\nend\n\nn, t = gets.split.map(&:to_i)\nacc = 0\nar = [0]\ngets.split.each { |i|\n i = i.to_i\n acc += i\n ar << acc\n}\ni, j = 0, 0 # indexing: [i, j], inclusive range. be careful!\nmaximum_books = 0\n# p ar\nloop do\n #p \"i: #{i}, ar[i] + t: #{ar[i] + t}\"\n nj = bsearch(ar, i, ar[i] + t)\n books = nj - i\n if maximum_books < books\n maximum_books = books\n end\n j = nj\n i += 1\n break if j >= ar.length - 1\nend\n\nputs maximum_books\n"}, {"source_code": "# def get_count(arr,l,r,t)\n\n# \twhile l >= 0 && l <= r\n# \t\tm = l + (r-l) / 2\n# \t\tputs \"#{l} #{r}\"\n# \t\treturn 1 if r ==m && arr[m] <= t\n# \t\tif arr[r] - arr[m] > t\n# \t\t\tl = m + 1\n# \t\telsif arr[r] - arr[m] < t\n# \t\t\tif arr[r] - arr[m-1] <= t\n# \t\t\t\tl = m - 1\n# \t\t\telse\n# \t\t\t\tputs \"less case #{l} #{r} #{m}\"\n# \t\t\t\treturn r - m\n# \t\t\tend\n# \t\telse\n# \t\t\tputs \"equal case #{l} #{r} #{m}\"\n# \t\t\treturn r - m\n# \t\tend\n# \tend\n# \treturn 0\n# end\n\n\n#For each r what is the l such that sum[l..r] <= t and l..r is maximum\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \treturn r - l + 1 if arr[r] <= t\n# \t(l..(r-1)).each do |i|\n# \t\t# puts \"#{r} #{i}\"\n# \t\treturn r - i if arr[r] - arr[i] <= t\n# \tend\n# \treturn 0\n# end\n\n\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \treturn r - l + 1 if arr[r] <= t\n\t\n# \twhile l >=0 && l < r\n# \t\tif arr[r] - arr[l] > t\n# \t\t\tm = l + ((r-l)/2.0).ceil\n# \t\t\tl = m\n# \t\t\t# puts \"#{l} #{m} #{r} #{l + (r-l)/2}\"\n# \t\telsif arr[r] - arr[l] < t\n# \t\t\tif l !=0 && arr[r] - arr[l-1] < t\n# \t\t\t\tl = l - 1\n# \t\t\telse\n# \t\t\t\treturn r - l\n# \t\t\tend\n# \t\telse\n# \t\t\treturn r - l\n# \t\tend\n# \tend\n\n# \treturn 0\n# end\n\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \t# puts \"#{l} #{r}\"\n# \treturn r - l + 1 if arr[r] && arr[r] <= t\n\t\n# \twhile arr[r] && l < r\n# \t\tm = l + (r-l) / 2\n# \t\tif arr[l] + t > arr[r]\n# \t\t\tr = m\n# \t\telse\n# \t\t\tif arr[]\n# \t\t\t \tr = r + 1\n# \t\t \telse\n# \t\t \t\treturn r - l\n# \t\t \tend\n\n# \t\tend\n# \tend\n\n# \treturn 0\n# end\n\ndef upper_bound(arr,l,r,x)\n\tbest = nil\t\n\twhile l <= r\n\t\tm = (l+r)/2\n\t\t# puts \"#{l} #{r} #{m}\"\n\t\tif arr[m] <= x\n\t\t\tbest = m\n\t\t\t# puts \"m #{arr[m]} x #{x}\"\n\t\t\tl = m + 1\n\t\telse\n\t\t\tr = m - 1\n\t\tend\n\tend\n\treturn best\n\nend\n# puts upper_bound([1,2,3,4,5,6],0,5,10)\n# puts upper_bound([1,2,3,6,7,8],0,5,4)\n# puts upper_bound([1,2,3,4,5,6],0,5,0)\n# puts upper_bound([1,2,3,4,5,6],0,5,9)\nn,t = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\nsum_arr = [arr[0]]\n(1..(n-1)).each do |i|\t\n\tsum_arr[i] = sum_arr[i-1] + arr[i]\nend\n# puts \"#{sum_arr}\"\nmax = 0\nunless sum_arr[n-1] <= t\n\tsum_arr.each_with_index{|a,i| \n\t\t# val = get_count(sum_arr,i,n-1,t)\t\n\t\tup = upper_bound(sum_arr,i,n-1,sum_arr[i]+t)\n\t \tif up\n\t\t\tval = up - i\n\t\t# puts \"#{sum_arr[i]+t}\"\n\t\t\t# val = 1 if up == i && arr[i] <= t\n\t\tend\n\t\tmax = val if val && val > max\n\t}\n\nelse\n\tmax = n\nend\n# 1 2 3 4 5\n# 1 3 6 10 15\nputs max\n# \n\n# Good - 3 days struggle finally accepted - http://canhazcode.blogspot.in/2012/02/we-need-to-talk-about-binary-search.html"}, {"source_code": "# def get_count(arr,l,r,t)\n\n# \twhile l >= 0 && l <= r\n# \t\tm = l + (r-l) / 2\n# \t\tputs \"#{l} #{r}\"\n# \t\treturn 1 if r ==m && arr[m] <= t\n# \t\tif arr[r] - arr[m] > t\n# \t\t\tl = m + 1\n# \t\telsif arr[r] - arr[m] < t\n# \t\t\tif arr[r] - arr[m-1] <= t\n# \t\t\t\tl = m - 1\n# \t\t\telse\n# \t\t\t\tputs \"less case #{l} #{r} #{m}\"\n# \t\t\t\treturn r - m\n# \t\t\tend\n# \t\telse\n# \t\t\tputs \"equal case #{l} #{r} #{m}\"\n# \t\t\treturn r - m\n# \t\tend\n# \tend\n# \treturn 0\n# end\n\n\n#For each r what is the l such that sum[l..r] <= t and l..r is maximum\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \treturn r - l + 1 if arr[r] <= t\n# \t(l..(r-1)).each do |i|\n# \t\t# puts \"#{r} #{i}\"\n# \t\treturn r - i if arr[r] - arr[i] <= t\n# \tend\n# \treturn 0\n# end\n\n\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \treturn r - l + 1 if arr[r] <= t\n\t\n# \twhile l >=0 && l < r\n# \t\tif arr[r] - arr[l] > t\n# \t\t\tm = l + ((r-l)/2.0).ceil\n# \t\t\tl = m\n# \t\t\t# puts \"#{l} #{m} #{r} #{l + (r-l)/2}\"\n# \t\telsif arr[r] - arr[l] < t\n# \t\t\tif l !=0 && arr[r] - arr[l-1] < t\n# \t\t\t\tl = l - 1\n# \t\t\telse\n# \t\t\t\treturn r - l\n# \t\t\tend\n# \t\telse\n# \t\t\treturn r - l\n# \t\tend\n# \tend\n\n# \treturn 0\n# end\n\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \t# puts \"#{l} #{r}\"\n# \treturn r - l + 1 if arr[r] && arr[r] <= t\n\t\n# \twhile arr[r] && l < r\n# \t\tm = l + (r-l) / 2\n# \t\tif arr[l] + t > arr[r]\n# \t\t\tr = m\n# \t\telse\n# \t\t\tif arr[]\n# \t\t\t \tr = r + 1\n# \t\t \telse\n# \t\t \t\treturn r - l\n# \t\t \tend\n\n# \t\tend\n# \tend\n\n# \treturn 0\n# end\n\ndef upper_bound(arr,l,r,x)\n\tbest = nil\t\n\twhile l <= r\n\t\tm = (l+r)/2\n\t\t# puts \"#{l} #{r} #{m}\"\n\t\tif arr[m] <= x\n\t\t\tbest = m\n\t\t\t# puts \"m #{arr[m]} x #{x}\"\n\t\t\tl = m + 1\n\t\telse\n\t\t\tr = m - 1\n\t\tend\n\tend\n\treturn best\n\nend\n# puts upper_bound([1,2,3,4,5,6],0,5,10)\n# puts upper_bound([1,2,3,6,7,8],0,5,4)\n# puts upper_bound([1,2,3,4,5,6],0,5,0)\n# puts upper_bound([1,2,3,4,5,6],0,5,9)\nn,t = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\nsum_arr = [arr[0]]\n(1..(n-1)).each do |i|\t\n\tsum_arr[i] = sum_arr[i-1] + arr[i]\nend\n# puts \"#{sum_arr}\"\nmax = 0\nunless sum_arr[n-1] <= t\n\tsum_arr.each_with_index{|a,i| \n\t\t# val = get_count(sum_arr,i,n-1,t)\t\n\t\tup = upper_bound(sum_arr,i,n-1,sum_arr[i]+t)\n\t \tif up\n\t\t\tval = up - i\n\t\t# puts \"#{sum_arr[i]+t}\"\n\t\t\t# val = 1 if up == i && arr[i] <= t\n\t\tend\n\t\tmax = val if val && val > max\n\t}\n\nelse\n\tmax = n\nend\n# 1 2 3 4 5\n# 1 3 6 10 15\nputs max\n# "}, {"source_code": "# http://codeforces.com/problemset/problem/279/B\nn, t = gets.chomp.split.map(&:to_i)\nlist = gets.chomp.split.map(&:to_i)\n\nmax_books = 0\ntime = 0\nl = 0\nfor r in 0..(list.length - 1)\n\n while time > t\n time -= list[l]\n l += 1\n end\n\n time += list[r]\n if time <= t\n max_books = [r - l + 1, max_books].max\n end\nend\n\np max_books\n"}], "negative_code": [{"source_code": "def npos(pos, n)\n (pos + 1) % n\nend\n\ndef ppos(pos, n)\n (pos - 1 + n) % n\nend\n\ndef run\n n, t = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n\n if a.min > t\n puts 0\n return\n end\n\n list = []\n sum = pos = max = val = 0\n n.times do |i|\n while sum <= t\n if list.length == n\n puts n\n return\n end\n\n sum += a[pos]\n list << a[pos]\n pos = npos(pos, n)\n end\n pos = ppos(pos, n)\n sum -= a[pos]\n list.pop\n\n if pos != i\n val = (ppos(pos, n) - i + n) % n + 1\n sum -= a[i]\n list.shift\n max = [max, val].max\n end\n end\n\n puts max\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def npos(pos, n)\n (pos + 1) % n\nend\n\ndef ppos(pos, n)\n (pos - 1 + n) % n\nend\n\ndef run\n n, t = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n\n if a.min > t\n puts 0\n return\n end\n\n list = []\n sum = pos = max = val = 0\n n.times do |i|\n while sum <= t\n if list.length == n\n puts n\n return\n end\n\n sum += a[pos]\n list << a[pos]\n pos = npos(pos, n)\n end\n pos = ppos(pos, n)\n sum -= a[pos]\n list.pop\n\n if pos != i\n val = (ppos(pos, n) - i + n) % n + 1\n sum -= a[i]\n list.shift\n max = [max, val].max\n end\n end\n\n puts max\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def npos(pos, n)\n (pos + 1) % n\nend\n\ndef ppos(pos, n)\n (pos - 1 + n) % n\nend\n\ndef run\n n, t = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n\n sum = pos = max = 0\n\n n.times do |i|\n while sum <= t\n sum += a[pos]\n pos = npos(pos, n)\n end\n pos = ppos(pos, n)\n sum -= a[pos]\n\n val = (ppos(pos, n) - i + n) % n + 1\n\n max = [max, val].max\n sum -= a[i]\n end\n\n puts max\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def npos(pos, n)\n (pos + 1) % n\nend\n\ndef ppos(pos, n)\n (pos - 1 + n) % n\nend\n\ndef run\n n, t = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n\n sum = pos = max = 0\n\n n.times do |i|\n while sum <= t\n sum += a[pos]\n pos = npos(pos, n)\n end\n pos = ppos(pos, n)\n sum -= a[pos]\n\n max = [max, ppos(pos, n) - i + 1].max\n sum -= a[i]\n end\n\n puts max\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def npos(pos, n)\n (pos + 1) % n\nend\n\ndef ppos(pos, n)\n (pos - 1 + n) % n\nend\n\ndef run\n n, t = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n\n if a.min > t\n puts 0\n return\n end\n\n list = []\n sum = pos = max = val = 0\n n.times do |i|\n while sum <= t\n if list.length == n\n puts n\n return\n end\n\n sum += a[pos]\n list << a[pos]\n pos = npos(pos, n)\n end\n pos = ppos(pos, n)\n sum -= a[pos]\n list.pop\n\n if pos == i\n val = (pos - i + n) % n + 1\n else\n val = (ppos(pos, n) - i + n) % n + 1\n sum -= a[i]\n list.shift\n end\n\n max = [max, val].max\n end\n\n puts max\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\ndef bsearch(arr, b, goal)\n e = arr.length\n while b < e\n mid = (b + e)/2\n if arr[mid] == goal\n b = mid\n break\n elsif arr[mid] < goal\n b = mid\n if e - b == 1\n break\n end\n else\n e = mid\n if e - b == 1\n break\n end\n end\n end\n return b\nend\n\nn, t = gets.split.map(&:to_i)\nacc = 0\nar = []\ngets.split.each { |i|\n i = i.to_i\n acc += i\n ar << acc\n}\ni, j = 0, 0 # indexing: [i, j], inclusive range. be careful!\nmaximum_books = 0\nloop do\n nj = bsearch(ar, i, ar[i] + t)\n books = nj - i\n if nj == i && ar[nj] <= t\n books = 1\n end\n if maximum_books < books\n maximum_books = books\n end\n j = nj\n i += 1\n break if j == (ar.length - 1)\nend\n\nputs maximum_books\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\ndef bsearch(arr, b, goal)\n e = arr.length\n while b < e\n mid = (b + e)/2\n if arr[mid] == goal\n b = mid\n break\n elsif arr[mid] < goal\n b = mid\n if e - b == 1\n break\n end\n else\n e = mid\n if e - b == 1\n break\n end\n end\n end\n return b\nend\n\nn, t = gets.split.map(&:to_i)\nacc = 0\nar = []\ngets.split.each { |i|\n i = i.to_i\n acc += i\n ar << acc\n}\ni, j = 0, 0 # indexing: [i, j], inclusive range. be careful!\nmaximum_books = 0\nwhile j < (ar.length - 1)\n nj = bsearch(ar, i, ar[i] + t)\n if maximum_books < (nj - i)\n maximum_books = nj - i\n end\n j = nj\n i += 1\nend\n\nputs maximum_books\n"}, {"source_code": "# def get_count(arr,l,r,t)\n\n# \twhile l >= 0 && l <= r\n# \t\tm = l + (r-l) / 2\n# \t\tputs \"#{l} #{r}\"\n# \t\treturn 1 if r ==m && arr[m] <= t\n# \t\tif arr[r] - arr[m] > t\n# \t\t\tl = m + 1\n# \t\telsif arr[r] - arr[m] < t\n# \t\t\tif arr[r] - arr[m-1] <= t\n# \t\t\t\tl = m - 1\n# \t\t\telse\n# \t\t\t\tputs \"less case #{l} #{r} #{m}\"\n# \t\t\t\treturn r - m\n# \t\t\tend\n# \t\telse\n# \t\t\tputs \"equal case #{l} #{r} #{m}\"\n# \t\t\treturn r - m\n# \t\tend\n# \tend\n# \treturn 0\n# end\n\n\n#For each r what is the l such that sum[l..r] <= t and l..r is maximum\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \treturn r - l + 1 if arr[r] <= t\n# \t(l..(r-1)).each do |i|\n# \t\t# puts \"#{r} #{i}\"\n# \t\treturn r - i if arr[r] - arr[i] <= t\n# \tend\n# \treturn 0\n# end\n\n\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \treturn r - l + 1 if arr[r] <= t\n\t\n# \twhile l >=0 && l < r\n# \t\tif arr[r] - arr[l] > t\n# \t\t\tm = l + ((r-l)/2.0).ceil\n# \t\t\tl = m\n# \t\t\t# puts \"#{l} #{m} #{r} #{l + (r-l)/2}\"\n# \t\telsif arr[r] - arr[l] < t\n# \t\t\tif l !=0 && arr[r] - arr[l-1] < t\n# \t\t\t\tl = l - 1\n# \t\t\telse\n# \t\t\t\treturn r - l\n# \t\t\tend\n# \t\telse\n# \t\t\treturn r - l\n# \t\tend\n# \tend\n\n# \treturn 0\n# end\n\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \t# puts \"#{l} #{r}\"\n# \treturn r - l + 1 if arr[r] && arr[r] <= t\n\t\n# \twhile arr[r] && l < r\n# \t\tm = l + (r-l) / 2\n# \t\tif arr[l] + t > arr[r]\n# \t\t\tr = m\n# \t\telse\n# \t\t\tif arr[]\n# \t\t\t \tr = r + 1\n# \t\t \telse\n# \t\t \t\treturn r - l\n# \t\t \tend\n\n# \t\tend\n# \tend\n\n# \treturn 0\n# end\n\ndef upper_bound(arr,l,r,x)\n\tbest = nil\n\twhile l <= r\n\t\tm = l + (r-l)/2\n\t\tif arr[m] <= x\n\t\t\tbest = m\n\t\t\tl = m + 1\n\t\telse\n\t\t\tr = m - 1\n\t\tend\n\tend\n\treturn best\n\nend\n\nn,t = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\nsum_arr = [arr[0]]\n(1..(n-1)).each do |i|\t\n\tsum_arr[i] = sum_arr[i-1] + arr[i]\nend\n# puts \"#{sum_arr}\"\nmax = 0\nsum_arr.each_with_index{|a,i| \n\t# val = get_count(sum_arr,i,n-1,t)\n\tup = upper_bound(sum_arr,i,n-1,sum_arr[i]+t)\n\tval = up - i if up\n\tmax = val if val && val > max\n}\n\n# 1 2 3 4 5\n# 1 3 6 10 15\nputs max\n# "}, {"source_code": "# def get_count(arr,l,r,t)\n\n# \twhile l >= 0 && l <= r\n# \t\tm = l + (r-l) / 2\n# \t\tputs \"#{l} #{r}\"\n# \t\treturn 1 if r ==m && arr[m] <= t\n# \t\tif arr[r] - arr[m] > t\n# \t\t\tl = m + 1\n# \t\telsif arr[r] - arr[m] < t\n# \t\t\tif arr[r] - arr[m-1] <= t\n# \t\t\t\tl = m - 1\n# \t\t\telse\n# \t\t\t\tputs \"less case #{l} #{r} #{m}\"\n# \t\t\t\treturn r - m\n# \t\t\tend\n# \t\telse\n# \t\t\tputs \"equal case #{l} #{r} #{m}\"\n# \t\t\treturn r - m\n# \t\tend\n# \tend\n# \treturn 0\n# end\n\n\n#For each r what is the l such that sum[l..r] <= t and l..r is maximum\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \treturn r - l + 1 if arr[r] <= t\n# \t(l..(r-1)).each do |i|\n# \t\t# puts \"#{r} #{i}\"\n# \t\treturn r - i if arr[r] - arr[i] <= t\n# \tend\n# \treturn 0\n# end\n\n\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \treturn r - l + 1 if arr[r] <= t\n\t\n# \twhile l >=0 && l < r\n# \t\tif arr[r] - arr[l] > t\n# \t\t\tm = l + ((r-l)/2.0).ceil\n# \t\t\tl = m\n# \t\t\t# puts \"#{l} #{m} #{r} #{l + (r-l)/2}\"\n# \t\telsif arr[r] - arr[l] < t\n# \t\t\tif l !=0 && arr[r] - arr[l-1] < t\n# \t\t\t\tl = l - 1\n# \t\t\telse\n# \t\t\t\treturn r - l\n# \t\t\tend\n# \t\telse\n# \t\t\treturn r - l\n# \t\tend\n# \tend\n\n# \treturn 0\n# end\n\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \t# puts \"#{l} #{r}\"\n# \treturn r - l + 1 if arr[r] && arr[r] <= t\n\t\n# \twhile arr[r] && l < r\n# \t\tm = l + (r-l) / 2\n# \t\tif arr[l] + t > arr[r]\n# \t\t\tr = m\n# \t\telse\n# \t\t\tif arr[]\n# \t\t\t \tr = r + 1\n# \t\t \telse\n# \t\t \t\treturn r - l\n# \t\t \tend\n\n# \t\tend\n# \tend\n\n# \treturn 0\n# end\n\ndef upper_bound(arr,l,r,x)\n\tbest = nil\n\twhile l <= r\n\t\tm = l + (r-l)/2\n\t\tif arr[m] <= x\n\t\t\tbest = m\n\t\t\tl = m + 1\n\t\telse\n\t\t\tr = m - 1\n\t\tend\n\tend\n\treturn best\n\nend\n\nn,t = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\nsum_arr = [arr[0]]\n(1..(n-1)).each do |i|\t\n\tsum_arr[i] = sum_arr[i-1] + arr[i]\nend\n# puts \"#{sum_arr}\"\nmax = 0\nsum_arr.each_with_index{|a,i| \n\t# val = get_count(sum_arr,i,n-1,t)\n\tup = upper_bound(sum_arr,i,n-1,sum_arr[i]+t)\n\tval = up - i if up\n\tval = 1 if up == i\n\tmax = val if val && val > max\n}\n\n# 1 2 3 4 5\n# 1 3 6 10 15\nputs max\n# "}, {"source_code": "# def get_count(arr,l,r,t)\n\n# \twhile l >= 0 && l <= r\n# \t\tm = l + (r-l) / 2\n# \t\tputs \"#{l} #{r}\"\n# \t\treturn 1 if r ==m && arr[m] <= t\n# \t\tif arr[r] - arr[m] > t\n# \t\t\tl = m + 1\n# \t\telsif arr[r] - arr[m] < t\n# \t\t\tif arr[r] - arr[m-1] <= t\n# \t\t\t\tl = m - 1\n# \t\t\telse\n# \t\t\t\tputs \"less case #{l} #{r} #{m}\"\n# \t\t\t\treturn r - m\n# \t\t\tend\n# \t\telse\n# \t\t\tputs \"equal case #{l} #{r} #{m}\"\n# \t\t\treturn r - m\n# \t\tend\n# \tend\n# \treturn 0\n# end\n\n\n#For each r what is the l such that sum[l..r] <= t and l..r is maximum\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \treturn r - l + 1 if arr[r] <= t\n# \t(l..(r-1)).each do |i|\n# \t\t# puts \"#{r} #{i}\"\n# \t\treturn r - i if arr[r] - arr[i] <= t\n# \tend\n# \treturn 0\n# end\n\n\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \treturn r - l + 1 if arr[r] <= t\n\t\n# \twhile l >=0 && l < r\n# \t\tif arr[r] - arr[l] > t\n# \t\t\tm = l + ((r-l)/2.0).ceil\n# \t\t\tl = m\n# \t\t\t# puts \"#{l} #{m} #{r} #{l + (r-l)/2}\"\n# \t\telsif arr[r] - arr[l] < t\n# \t\t\tif l !=0 && arr[r] - arr[l-1] < t\n# \t\t\t\tl = l - 1\n# \t\t\telse\n# \t\t\t\treturn r - l\n# \t\t\tend\n# \t\telse\n# \t\t\treturn r - l\n# \t\tend\n# \tend\n\n# \treturn 0\n# end\n\n# def get_count(arr,l,r,t)\n# \t# return r - l if arr[r] - arr[l] <= t\t\n# \t# puts \"#{l} #{r}\"\n# \treturn r - l + 1 if arr[r] && arr[r] <= t\n\t\n# \twhile arr[r] && l < r\n# \t\tm = l + (r-l) / 2\n# \t\tif arr[l] + t > arr[r]\n# \t\t\tr = m\n# \t\telse\n# \t\t\tif arr[]\n# \t\t\t \tr = r + 1\n# \t\t \telse\n# \t\t \t\treturn r - l\n# \t\t \tend\n\n# \t\tend\n# \tend\n\n# \treturn 0\n# end\n\ndef upper_bound(arr,l,r,x)\n\tbest = nil\n\twhile l <= r\n\t\tm = l + (r-l)/2\n\t\tif arr[m] <= x\n\t\t\tbest = m\n\t\t\tl = m + 1\n\t\telse\n\t\t\tr = m - 1\n\t\tend\n\tend\n\treturn best\n\nend\n\nn,t = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\nsum_arr = [arr[0]]\n(1..(n-1)).each do |i|\t\n\tsum_arr[i] = sum_arr[i-1] + arr[i]\nend\n# puts \"#{sum_arr}\"\nmax = 0\nsum_arr.each_with_index{|a,i| \n\t# val = get_count(sum_arr,i,n-1,t)\n\tup = upper_bound(sum_arr,i,n-1,sum_arr[i]+t)\n \tif up\n\t\tval = up - i\n\t\tval = 1 if up == i && arr[i] <= t\n\tend\n\t# puts \"#{up}\"\n\tmax = val if val && val > max\n}\n\n# 1 2 3 4 5\n# 1 3 6 10 15\nputs max\n# "}, {"source_code": "# http://codeforces.com/problemset/problem/279/B\nn, t = gets.chomp.split.map(&:to_i)\nlist = gets.chomp.split.map(&:to_i)\n\nmax = 0\n\ntime = 0\nfor i in 0..(n - 1)\n for j in i..(n - 1)\n time += list[j]\n\n if time > t\n break\n else\n potential = j - i + 1\n\n if potential > max\n max = potential\n end\n end\n end\nend\n\np max\n\n[3,1,2,1]\n"}, {"source_code": "def read_next_line\n gets.split.map { |x| x.to_i }\nend\n\nn, t = read_next_line\na = read_next_line\n\nmax = p = cur_time = 0\nfor i in 0...n\n cur_time += a[i]\n while cur_time > t\n cur_time -= a[p]\n p += 1\n end\n cur = i - p\n max = cur if cur > max\nend\nputs max + 1"}, {"source_code": "\n\na, b = gets.split(\" \")\n\ntime = b.to_i\n\n\n\neachBookTime = []\n\ngets.split(\" \").each do |item|\n\n eachBookTime.push item.to_i\n\nend\n\nsum = 0\n\ncount = 0\n\neachBookTime.each do |item|\n\n if (sum+item <= time)\n\n sum += item\n\n count+=1\n\n end\n\nend\n\n\n\nputs count"}, {"source_code": "a, b = gets.split(\" \")\n\ntime = b.to_i\n\n\n\neachBookTime = []\n\ngets.split(\" \").each do |item|\n\n eachBookTime.push item.to_i\n\nend\n\neachBookTime = eachBookTime.sort\n\n\n\nsum = 0\n\ncount = 0\n\neachBookTime.each do |item|\n\n if (sum+item < time)\n\n sum += item\n\n count+=1\n\n end\n\nend\n\n\n\nputs count"}, {"source_code": "\n\na, b = gets.split(\" \")\n\ntime = b.to_i\n\n\n\neachBookTime = []\n\ngets.split(\" \").each do |item|\n\n eachBookTime.push item.to_i\n\nend\n\neachBookTime = eachBookTime.sort\n\n\n\nsum = 0\n\ncount = 0\n\neachBookTime.each do |item|\n\n if (sum+item <= time)\n\n sum += item\n\n count+=1\n\n end\n\nend\n\n\n\nputs count"}], "src_uid": "ef32a8f37968629673547db574261a9d"} {"source_code": "n,m=gets.chomp.split.collect{|a| a.to_i}\nputs ((n-1).gcd(m-1)+1)", "positive_code": [{"source_code": "require 'mathn'\nm, n = gets.chomp.split.map{|s| s.to_i - 1}.sort\nputs m.gcd(n) + 1\n"}], "negative_code": [{"source_code": "m, n = gets.chomp.split.map{|s| s.to_i}\nputs m == n ? m : 2\n"}, {"source_code": "m, n = gets.chomp.split.map{|s| s.to_i - 1}.sort\nputs n % m == 0 ? m + 1 : 2\n"}], "src_uid": "05f251de93536024c05fbd77ed01b70b"} {"source_code": "gets.chomp.to_i.times{puts((t=gets.chomp.to_i)<=2?0: t-2)}\n", "positive_code": [{"source_code": "gets.to_i.times{puts [0,gets.to_i-2].max}\n"}, {"source_code": "gets.to_i.times{puts [0,gets.to_i-2].max}\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n if n < 3\n puts 0\n else\n puts n - 2\n end\nend\n"}, {"source_code": "gets.to_i.times{|i|puts [0,gets.to_i-2].max}"}, {"source_code": "gets.to_i.times{puts [0,gets.to_i-2].max}"}, {"source_code": "puts readlines[1..-1].map{|_| [_.to_i - 2, 0].max} * \"\\n\"\n"}, {"source_code": "readlines[1..-1].map{|_| p [_.to_i - 2, 0].max}\n"}, {"source_code": "t=gets.to_i\nt.times{\n n=gets.to_i\n puts [n-2,0].max\n}"}, {"source_code": "gets.to_i.times{puts [0,gets.to_i-2].max}\n"}, {"source_code": "gets.to_i.times{puts [0,gets.to_i-2].max}\n"}, {"source_code": "gets.to_i.times{puts [0,gets.to_i-2].max}"}, {"source_code": "gets.to_i.times{puts [0,gets.to_i-2].max}\n"}, {"source_code": "gets.to_i.times{puts [0,gets.to_i-2].max}\n"}, {"source_code": "gets.to_i.times{puts [0,gets.to_i-2].max}"}, {"source_code": "gets.to_i.times{puts [0,gets.to_i-2].max}\n"}, {"source_code": "gets.to_i.times{puts [0,gets.to_i-2].max}\n"}, {"source_code": "gets.to_i.times { p [gets.to_i - 2, 0].max }\n"}], "negative_code": [{"source_code": "gets.to_i.times do\n puts gets.to_i / 3\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n total = n / 4 * 2\n total += 1 if n % 4 == 3\n puts total\nend\n"}, {"source_code": "t=gets.to_i\nt.times{\n n=gets.to_i\n puts n-2\n}\n"}, {"source_code": "gets.chomp.to_i.times{puts(gets.chomp.to_i-2)}\n"}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\tp n / 4 * 2 + (n % 4 == 3 ? 1 : 0)\nend\n"}, {"source_code": "gets.to_i.times { p gets.to_i / 3 }\n"}], "src_uid": "f83c91c9e9252aba4736aa0bea82493b"} {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\ns = gets.chomp\ns.gsub!(/ *, */, ', ')\ns.gsub!(/ *\\.\\.\\. */, ' ...')\ns.gsub!(/ +/, ' ')\ns.strip!\nputs s\n\n", "positive_code": [{"source_code": "\nwhile s = gets\n s = s.chomp.strip\n # puts \"(#{s})\"\n s.gsub!(/([,.])\\s+([,.])/, '\\1\\2')\n s.gsub!(/([,.])\\s+([,.])/, '\\1\\2')\n\n s.gsub!(/([,.])\\s+([\\d])/, '\\1\\2')\n s.gsub!(/([,.])\\s+([\\d])/, '\\1\\2')\n\n s.gsub!(/([\\d])\\s+([,.])/, '\\1\\2')\n s.gsub!(/([\\d])\\s+([,.])/, '\\1\\2')\n\n # s.gsub!(/([\\d])\\s+([\\d])/, '\\1 \\2')\n # s.gsub!(/([\\d])\\s+([\\d])/, '\\1 \\2')\n\n # puts \"{#{s}}\"\n s.gsub!(/,/, \", \")\n s.gsub!(/\\.\\.\\./, ' ...')\n s.gsub!(/[\\s]{2,}/, \" \")\n s.strip!\n puts \"#{s}\"\nend\n"}, {"source_code": " line = gets.chomp\n line.gsub!(/ *, */, ', ')\n line.gsub!(/ *\\.\\.\\. */, ' ...')\n line.gsub!(/ +/, ' ')\n line.strip!\n puts line"}, {"source_code": "puts gets.gsub(/ *,/,', ').gsub(/\\.\\.\\. */,' ...').gsub(/ +/,' ').strip"}, {"source_code": "input = STDIN.readline.gsub(',', ' , ').gsub('...', ' ... ').strip.split(' ').map do |s| s.strip end\n\nspaceIns = true\nishead = true\nisPrevNum = false\ninput.each do |s|\n print ' ' if !ishead && spaceIns\n ishead = false\n case s\n when ','\n print ','\n spaceIns = true\n isPrevNum = false\n when '...'\n print((spaceIns ? '' : ' ') + '...')\n spaceIns = false\n isPrevNum = false\n else\n print((isPrevNum ? ' ' : '') + s)\n spaceIns = false\n isPrevNum = true\n end\nend\nputs ''\n"}, {"source_code": "class String\n def is_integer?\n self.to_i.to_s == self\n end\nend\n\ndef parse(line)\n return line.scan(Regexp.union(/,/, /\\.../, /\\d*/)).map{ |t| t.strip }.select{ |t| t != '' }\nend\n\ndef format(tokens)\n acc = \"\"\n tokens.each_with_index { |val, index| \n if val == \",\"\n acc << \", \"\n elsif val == \"...\" and acc[-1, 1] == \" \"\n acc << val\n elsif val == \"...\"\n acc << \" ...\"\n elsif val.is_integer? and index > 0 and tokens[index - 1].is_integer?\n acc << \" \" << val\n else\n acc << val\n end\n }\n return acc.strip\nend\n\ndef process_line(line)\n tokens = parse(line)\n return format(tokens)\nend\n\ninput = STDIN.read\nlines = input.chomp.split(\"\\n\")\nlines.map! { |l| puts process_line(l) }\n"}, {"source_code": "NUMBER_REGEX = /(\\d+)/\n\ntokens = gets.strip.gsub(',', ' , ').gsub('...', ' ... ').split\n\ntokens.each_with_index do |token, index|\n if index.zero?\n print token\n else\n print ' ' if tokens[index - 1] == ',' or token == '...'\n print ' ' if tokens[index - 1] =~ NUMBER_REGEX and token =~ NUMBER_REGEX\n print token\n end\nend\n\nputs\n"}, {"source_code": "line = gets.chomp\nline.gsub!(/ *, */, ', ')\nline.gsub!(/ *\\.\\.\\. */, ' ...')\nline.gsub!(/ +/, ' ')\nline.strip!\nputs line"}, {"source_code": "line = gets.chomp\nline.gsub!(/ *, */, ', ')\nline.gsub!(/ *\\.\\.\\. */, ' ...')\nline.gsub!(/ +/, ' ')\nline.strip!\nputs line\n"}], "negative_code": [{"source_code": "line = gets.chomp\nline.gsub!(/, */, ', ')\nline.gsub!(/ *\\.\\.\\./, ' ...')\nline.gsub!(/ +/, ' ')\nline.strip!\nputs line\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\ns = gets\nelems = s.split(/,/)\nelems.map!{|x|\n xx = x.strip\n if xx != \"...\" && xx =~ /\\.\\.\\./\n xx = xx.gsub(/\\.\\.\\./, \" ...\").lstrip\n end\n xx\n}\nputs elems.join(', ')\n\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\ns = gets\nelems = s.split(/,/)\nelems.map!{|x|\n xx = x.strip\n if xx != \"...\" && xx =~ /\\.\\.\\./\n xx = xx.gsub(/\\.\\.\\./, \" ...\")\n end\n xx\n}\nputs elems.join(', ')\n\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\ns = gets\nelems = s.split(/,/)\nelems.map!{|x|\n xx = x.strip\n if xx != \"...\" && xx =~ /\\.\\.\\./\n xx = xx.gsub(/\\.\\.\\./, \" ...\").lstrip\n end\n xx\n}\nputs elems.join(', ').strip\n\n\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\ns = gets\ns.gsub!(/\\s{1,}/, ' ')\nelems = s.split(/,/)\nelems.map!{|x|\n xx = x.strip\n if xx != \"...\" && xx =~ /\\.\\.\\./\n xx = xx.gsub(/\\.\\.\\./, \" ...\").lstrip\n end\n xx\n}\nputs elems.join(', ').strip\n\n"}, {"source_code": "puts gets.gsub(/ *,/,', ').gsub(/\\.\\.\\. */,' ...').gsub(/ +/,' ')"}, {"source_code": "class String\n def is_integer?\n self.to_i.to_s == self\n end\nend\n\ndef parse(line)\n return line.scan(Regexp.union(/,/, /\\.../, /\\d*/)).map{ |t| t.strip }.select{ |t| t != '' }\nend\n\ndef format(tokens)\n acc = \"\"\n tokens.each_with_index { |val, index| \n if val == \",\"\n acc << \", \"\n elsif val == \"...\" and acc[-1, 1] == \" \"\n acc << val\n elsif val == \"...\"\n acc << \" ...\"\n elsif val.is_integer? and index > 1 and tokens[index - 1].is_integer?\n acc << \" \" << val\n else\n acc << val\n end\n }\n return acc\nend\n\ndef process_line(line)\n tokens = parse(line)\n return format(tokens)\nend\n\ninput = STDIN.read\nlines = input.chomp.split(\"\\n\")\nlines.map! { |l| puts process_line(l) }\n"}, {"source_code": "class String\n def is_integer?\n self.to_i.to_s == self\n end\nend\n\ndef parse(line)\n return line.scan(Regexp.union(/,/, /\\.../, /\\d*/)).map{ |t| t.strip }.select{ |t| t != '' }\nend\n\ndef format(tokens)\n# puts tokens\n acc = \"\"\n tokens.each_with_index { |val, index| \n if val == \",\"\n acc << \", \"\n elsif val == \"...\" and acc[-1, 1] == \" \"\n acc << val\n elsif val == \"...\"\n acc << \" ...\"\n elsif val.is_integer? and index > 1 and tokens[index - 1].is_integer?\n acc << \" \" << val\n else\n acc << val\n end\n }\n puts acc\n return tokens.join(\"~\")\nend\n\ndef process_line(line)\n puts line\n tokens = parse(line)\n return format(tokens)\nend\n\ninput = STDIN.read\nlines = input.chomp.split(\"\\n\")\nlines.map! { |l| puts process_line(l) }\n"}, {"source_code": "class String\n def is_integer?\n self.to_i.to_s == self\n end\nend\n\ndef parse(line)\n return line.scan(Regexp.union(/,/, /\\.../, /\\d*/)).map{ |t| t.strip }.select{ |t| t != '' }\nend\n\ndef format(tokens)\n acc = \"\"\n tokens.each_with_index { |val, index| \n if val == \",\"\n acc << \", \"\n elsif val == \"...\" and acc[-1, 1] == \" \"\n acc << val\n elsif val == \"...\"\n acc << \" ...\"\n elsif val.is_integer? and index > 1 and tokens[index - 1].is_integer?\n acc << \" \" << val\n else\n acc << val\n end\n }\n return acc.strip\nend\n\ndef process_line(line)\n tokens = parse(line)\n return format(tokens)\nend\n\ninput = STDIN.read\nlines = input.chomp.split(\"\\n\")\nlines.map! { |l| puts process_line(l) }\n"}], "src_uid": "c7d8c71a1f7e6c7364cce5bddd488a2f"} {"source_code": "k, n, m = gets.split.map(&:to_i)\n\ndata = []\nk.times do\n gets\n o = []\n n.times do \n o << gets.chomp\n end\n data << o\nend\n\ngets\nx, y = gets.split.map(&:to_i)\n\nlim = [k, n, m]\nq = [[1, x, y]]\nused = {}\nn = 0\nuntil q.empty?\n pos = q.shift\n\n next if used[pos]\n next if pos.min < 1 || pos.zip(lim).find{|a,b| a>b}\n next if data[pos[0]-1][pos[1]-1][pos[2]-1] != '.'\n\n used[pos] = true\n\n n += 1\n q << [pos[0], pos[1], pos[2]+1]\n q << [pos[0], pos[1], pos[2]-1]\n q << [pos[0], pos[1]+1, pos[2]]\n q << [pos[0], pos[1]-1, pos[2]]\n q << [pos[0]+1, pos[1], pos[2]]\n q << [pos[0]-1, pos[1], pos[2]]\n\nend\n\np n\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\n$k, $n, $m = gets.split.map(&:to_i)\n$t = []\n\ndef fs(z, x, y)\n stack = [[z, x, y]]\n $t[z][x][y] = '#'\n #puts \"dfs #{z} #{x} #{y}\"\n result = 1\n while not stack.empty?\n z, x, y = stack.pop\n (-1..1).each do |i|\n (-1..1).each do |j|\n (-1..1).each do |k|\n if [i, j, k].select { |x| x == 0 }.count == 2\n nz, nx, ny = z + i, x + j, y + k\n #puts [i, j, k, nz, nx, ny] * \" \" + [0 <= nz, nz < t.size, 0 <= nx, nx < t[0].size, ny <= 0, ny < t[0][0].size] * \" \"\n if 0 <= nz && nz < $k && 0 <= nx && nx < $n && 0 <= ny && ny < $m\n #puts \"ok\"\n if $t[nz][nx][ny] == '.'\n $t[nz][nx][ny] = '#'\n stack.push([nz, nx, ny])\n result += 1\n end\n end\n end\n end\n end\n end\n end\n\n return result\nend\n\n\n$k.times do\n gets\n $t << []\n $n.times do\n $t[-1] << gets.chomp\n end\nend\ngets\nx, y = gets.split.map(&:to_i)\n\n#p t, x, y, t.size, t[0].size, t[0][0].size\n\nputs fs(0, x - 1, y - 1)"}, {"source_code": "K, N, M = gets.chomp.split.map{|e| e.to_i}\n\nmap = Array.new(K + 1) { Array.new(N + 1) {[]}}\n\n1.upto(K) {|i|\n gets\n 1.upto(N) {|j|\n map[i][j].push 0\n tmp = gets.chomp.split('').each {|e|\n map[i][j].push e\n }\n }\n}\n\ngets\nX, Y = gets.chomp.split.map{|e| e.to_i}\n\ndef dfs(map, k, n, m)\n return 0 if (k < 1 || k > K || n < 1 || n > N || m < 1 || m > M)\n return 0 if (map[k][n][m] != \".\")\n \n count = 1\n map[k][n][m] = \"0\"\n directions = [[0, 0, 1], [0, 0, -1], [0, 1, 0], [0, -1, 0], [1, 0, 0], [-1, 0, 0]]\n\n directions.each {|e|\n count += dfs(map, k + e[0], n + e[1], m + e[2])\n }\n\n return count\nend\n\nputs dfs(map, 1, X, Y)\n\n\n"}], "negative_code": [], "src_uid": "3f6e5f6d9a35c6c9e71a7eeab4acf199"} {"source_code": "\nN = gets.to_i\narr = gets.split.map(&:to_i)\nnums = Hash.new(0)\ncounts = Hash.new(0)\nanswer = 0\nfor k in 0...N\n\tcnt = ( nums[ arr[k] ] += 1 )\n\tif cnt == 1\n\t\tcounts[1] += 1\n\telse\n\t\tcounts[cnt-1] -= 1\n\t\tcounts.delete cnt-1 if counts[cnt-1] == 0\n\t\tcounts[cnt] += 1\n\tend\n#\tSTDERR.puts \"#{nums}\"\n#\tSTDERR.puts \"#{counts}\"\n#\tSTDERR.puts counts.size\n\tif counts.size == 1\n\t\tanswer = k if counts.key?(1) or counts.value?(1)\n\telsif counts.size == 2\n\t\tif counts.value?(1)\n\t\t\tif counts[1] == 1\n\t\t\t\tanswer = k\n\t\t\telse\n\t\t\t\ta, b = counts.keys\n\t\t\t\tanswer = k if (a - b).abs == 1 && counts[a > b ? a : b] == 1\n\t\t\tend\n\t\tend\n\tend\nend\nputs answer + 1\n", "positive_code": [{"source_code": "n = readline.to_i\nu = readline.split.map(&:to_i)\n\nC = 100000\n\ncs = [0] * C\ncsr = {0 => n}\ncsr.default = 0\nmax_x = 1\n(0...n).each do |i|\n ui = u[i] - 1\n c = cs[ui]\n csr[c] -= 1\n csr.delete(c) if csr[c] == 0\n c += 1\n cs[ui] = c\n csr[c] += 1\n if csr.length <= 3 then\n ks = csr.keys\n ks.delete_if { |x| x == 0 }\n if ks.length == 1 and (ks[0] == 1 or csr[ks[0]] == 1)\n max_x = i + 1\n elsif ks.length == 2\n ks = ks.sort\n if (ks[1] == ks[0] + 1 and csr[ks[1]] == 1) or (ks[0] == 1 and csr[ks[0]] == 1)\n max_x = i + 1\n end\n end\n end\nend\np max_x\n"}, {"source_code": "\nN = gets.to_i\narr = gets.split.map(&:to_i)\nnums = Hash.new(0)\ncounts = Hash.new(0)\nanswer = 0\nfor k in 0...N\n\tx = arr[k]\n\tnums[x] += 1\n\tcnt = nums[x]\n\tif cnt == 1\n\t\tcounts[1] += 1\n\telse\n\t\tcounts[cnt-1] -= 1\n\t\tcounts[cnt] += 1\n\tend\n\tcounts.delete_if { |key, value| value == 0 }\n#\tSTDERR.puts \"#{nums}\"\n#\tSTDERR.puts \"#{counts}\"\n#\tSTDERR.puts counts.size\n\tif counts.size == 1\n\t\tanswer = k if counts.key?(1) or counts.value?(1)\n\telsif counts.size == 2\n\t\tif counts.value?(1)\n\t\t\tanswer = k if counts[1] == 1\n\t\t\ta, b = counts.keys\n\t\t\tif (a - b).abs == 1\n\t\t\t\tmax = a > b ? a : b\n\t\t\t\tanswer = k if counts[max] == 1\n\t\t\tend\n\t\tend\n\tend\nend\nputs answer + 1\n"}], "negative_code": [{"source_code": "\nN = gets.to_i\narr = gets.split.map(&:to_i)\nnums = Hash.new(0)\ncounts = Hash.new(0)\nanswer = 0\nfor k in 0...arr.size\n\tx = arr[k]\n\tnums[x] += 1\n\tcnt = nums[x]\n\tif cnt == 1\n\t\tcounts[1] += 1\n\telse\n\t\tcounts[cnt-1] -= 1\n\t\tcounts[cnt] += 1\n\tend\n\tcounts.delete_if { |key, value| value == 0 }\n#\tSTDERR.puts \"#{nums}\"\n#\tSTDERR.puts \"#{counts}\"\n#\tSTDERR.puts counts.size\n\tif counts.size == 1\n\t\tanswer = k if counts.key?(1) or counts.value?(1)\n\telsif counts.size == 2\n\t\tif counts.value?(1)\n\t\t\tanswer = k if counts[1] == 1\n\t\t\ta, b = counts.keys\n\t\t\tanswer = k if (a - b).abs == 1\n\t\tend\n\tend\nend\nputs answer + 1\n"}, {"source_code": "\nN = gets.to_i\narr = gets.split.map(&:to_i)\nnums = Hash.new(0)\ncounts = Hash.new(0)\nanswer = 0\nfor k in 0...arr.size\n\tx = arr[k]\n\tnums[x] += 1\n\tcnt = nums[x]\n\tif cnt == 1\n\t\tcounts[1] += 1\n\telse\n\t\tcounts[cnt-1] -= 1\n\t\tcounts[cnt] += 1\n\tend\n\tcounts.delete_if { |key, value| value == 0 }\n\tSTDERR.puts \"#{nums}\"\n\tSTDERR.puts \"#{counts}\"\n\tSTDERR.puts counts.size\n\tif counts.size == 1\n\t\tanswer = k if counts.key?(1) or counts.value?(1)\n\telsif counts.size == 2\n\t\tif counts.value?(1)\n\t\t\ta, b = counts.keys\n\t\t\tanswer = k if (a - b).abs == 1\n\t\tend\n\tend\nend\nputs answer + 1"}, {"source_code": "\nN = gets.to_i\narr = gets.split.map(&:to_i)\nnums = Hash.new(0)\ncounts = Hash.new(0)\nanswer = 0\nfor k in 0...N\n\tcnt = ( nums[ arr[k] ] += 1 )\n\tif cnt == 1\n\t\tcounts[1] += 1\n\telse\n\t\tcounts[cnt-1] -= 1\n\t\tcounts.delete cnt-1 if counts[cnt-1] == 0\n\t\tcounts[cnt] += 1\n\tend\n#\tSTDERR.puts \"#{nums}\"\n#\tSTDERR.puts \"#{counts}\"\n#\tSTDERR.puts counts.size\n\tif counts.size == 1\n\t\tanswer = k if counts.key?(1) or counts.value?(1)\n\telsif counts.size == 2\n\t\tif counts.value?(1)\n\t\t\tif counts[1] == 1\n\t\t\t\tanswer = k\n\t\t\telse\n\t\t\t\ta, b = counts.keys\n\t\t\t\tanswer = k if (a - b).abs == 1 || counts[a > b ? a : b] == 1\n\t\t\tend\n\t\tend\n\tend\nend\nputs answer + 1\n"}, {"source_code": "\nN = gets.to_i\narr = gets.split.map(&:to_i)\nnums = Hash.new(0)\ncounts = Hash.new(0)\nanswer = 0\nfor k in 0...arr.size\n\tx = arr[k]\n\tnums[x] += 1\n\tcnt = nums[x]\n\tif cnt == 1\n\t\tcounts[1] += 1\n\telse\n\t\tcounts[cnt-1] -= 1\n\t\tcounts[cnt] += 1\n\tend\n\tcounts.delete_if { |key, value| value == 0 }\n\tSTDERR.puts \"#{nums}\"\n\tSTDERR.puts \"#{counts}\"\n\tSTDERR.puts counts.size\n\tif counts.size == 1\n\t\tanswer = k if counts.key?(1) or counts.value?(1)\n\telsif counts.size == 2\n\t\tif counts.value?(1)\n\t\t\tanswer = k if counts.key?(1)\n\t\t\ta, b = counts.keys\n\t\t\tanswer = k if (a - b).abs == 1\n\t\tend\n\tend\nend\nputs answer + 1"}, {"source_code": "\nN = gets.to_i\narr = gets.split.map(&:to_i)\nnums = Hash.new(0)\ncounts = Hash.new(0)\nanswer = 0\nfor k in 0...N\n\tx = arr[k]\n\tnums[x] += 1\n\tcnt = nums[x]\n\tif cnt == 1\n\t\tcounts[1] += 1\n\telse\n\t\tcounts[cnt-1] -= 1\n\t\tcounts[cnt] += 1\n\tend\n\tcounts.delete_if { |key, value| value == 0 }\n#\tSTDERR.puts \"#{nums}\"\n#\tSTDERR.puts \"#{counts}\"\n#\tSTDERR.puts counts.size\n\tif counts.size == 1\n\t\tanswer = k if counts.key?(1) or counts.value?(1)\n\telsif counts.size == 2\n\t\tif counts.value?(1)\n\t\t\tanswer = k if counts[1] == 1\n\t\t\ta, b = counts.keys\n\t\t\ta, b = b, a if counts[a] == 1\n\t\t\tanswer = k if b - a == 1\n\t\tend\n\tend\nend\nputs answer + 1\n"}], "src_uid": "886d8d7103f0a7403b06b80b914ee498"} {"source_code": "def Pal(s)\n s == s.reverse\nend\n\ns = gets.chomp\nputs Pal(s)? s : s + s[0..-2].reverse", "positive_code": [{"source_code": "a = gets.chomp \na.downcase!\nputs a + a.reverse\n\n"}, {"source_code": "s=gets.chomp;puts s+s.reverse"}, {"source_code": "s = gets().strip\nputs s << s.reverse\n"}, {"source_code": "s = gets.chomp\nputs s + s.reverse[0..-1]"}, {"source_code": "s=gets.chomp\nprint s\nfor i in (s.size-1).downto(0)\n print s[i]\n \nend\n"}, {"source_code": "s=gets.chomp\nprint s\nfor i in (s.size-1).downto(0)\n print s[i]\nend\n"}, {"source_code": "a = gets.chomp\nputs a + a.reverse\n"}], "negative_code": [], "src_uid": "9b1887582a9eb7cff49994ddcc2ee9b8"} {"source_code": "gets.chop!\n($.+=1;$_=($_.sum(32)-48*~/$/).to_s)until~/^.$/\np$.-1\n", "positive_code": [{"source_code": "gets.chop!\n($.+=1;$_=($_.sum(32)-48*~/$/).to_s)until~/^.$/\np$.-1\n"}, {"source_code": "gets.chop!\n($.+=1;$_=($_.sum(32)-48*~/$/).to_s)until~/^.$/\np$.-1\n"}, {"source_code": "gets.chop!\n($.+=1;$_=($_.sum(32)-48*~/$/).to_s)until~/^.$/\np$.-1"}, {"source_code": "n, i = gets.strip, 0\n\n(print 0; exit) if n.length == 1\n\nloop do\n n = n.split(//).map(&:to_i).inject { |sum, e| sum += e }.to_s\n (print i + 1; exit) if n.length == 1\n i += 1\nend"}, {"source_code": "gets.chop!\n($.+=1;$_=($_.sum(32)-48*~/$/).to_s)until~/^.$/\np$.-1\n"}, {"source_code": "n = gets.chomp\ncount = 0\nwhile n.size > 1\n n = n.split(//).inject(0) {|sum, e| sum + e.to_i}.to_s\n count += 1\nend\nputs count\n"}, {"source_code": "n = gets.chomp\ncount = 0\nwhile n.size != 1\n m = 0;\n n.each_byte{|c|\n m += c-48\n }\n n = m.to_s\n count += 1\nend\nputs count\n"}, {"source_code": "#!/usr/local/bin/ruby19\nans=0\nn=gets.split[0]\nwhile n.length>1\n m=0\n n.each_byte{|c|\n m+=c-48\n }\n ans+=1\n n=m.to_s\nend\nputs ans\n"}, {"source_code": "gets.chop!\n($.+=1;$_=($_.sum(32)-48*~/$/).to_s)until~/^.$/\np$.-1\n"}, {"source_code": "gets.chop!\n($.+=1;$_=($_.sum(32)-48*~/$/).to_s)until~/^.$/\np$.-1\n"}, {"source_code": "s = gets.chomp\nres = 0\nwhile s.length > 1 && res+=1 \n\ts = s.each_char.inject(0){ |sum, i| sum += i.to_i }.to_s\nend\nputs res\n"}, {"source_code": "gets.chop!\n($.+=1;$_=($_.sum(32)-48*~/$/).to_s)until~/^.$/\np$.-1"}, {"source_code": "n = gets.chomp.split(//)\ni = 0\nif n.size == 1\n puts i\n exit\nelse\n while n.size != 1 do\n n = n.inject(0){ |sum,x| x.to_i + sum }.to_s.split(//)\n i += 1\n end\nend\nputs i\n"}, {"source_code": "s = gets.chomp\nq = 0\nans = 1\n0.upto(s.length - 1).each do |i|\n q += s[i].to_i\nend\nwhile q >= 10 do\n nq = 0\n while q != 0 do\n nq += q % 10\n q /= 10\n end\n q = nq\n ans += 1\nend\n\nif s.length == 1 then ans = 0 end\n\nprint ans\n\n"}, {"source_code": "gets.chop!\n($.+=1;$_=($_.sum(32)-48*~/$/).to_s)until~/^.$/\np$.-1\n"}, {"source_code": "gets.chop!\n($.+=1;$_=($_.sum(32)-48*~/$/).to_s)until~/^.$/\np$.-1"}, {"source_code": "#=================================\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(ARGV[0], \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn=gets.strip\n\nif n.length==1\n\t\tputs 0\n\t\texit\nend\n\t\nstep=1\nloop{\n\tn=n.split(//).map(&:to_i).inject(:+).to_s\n\t\n\tif n.length==1\n\t\tputs step\n\t\texit\n\tend\n\t\n\tstep+=1\n}\n"}, {"source_code": "n = STDIN.read.gsub(\"\\n\", \"\")\n\nsteps = 0\nwhile (n.size != 1) do\n digits = n.split(\"\")\n n = digits.inject(0) { |result, digit| result + digit.to_i }.to_s\n steps += 1\nend\n\nputs steps\n"}, {"source_code": "n = gets.chomp\ncnt = 0 \nwhile(n.length != 1)\n res = 0 \n for i in 0...n.length\n res += Integer(n[i])\n end\n n = String(res)\n cnt += 1\nend\nputs cnt"}, {"source_code": "sn = gets.chop\n\n#n = sn.to_i\n\ncount = 0\n\nwhile (sn.length > 1)\n sum = 0\n (0..sn.length-1).each { |i|\n sum += sn[i].to_i\n }\n sn = sum.to_s\n #puts sn\n count += 1\nend\n\nputs count"}, {"source_code": "def sum_of_digits\n n = gets.strip\n\n count = 0\n while n.length > 1\n sum = n.chars.map{|i| i.to_i}.inject(0){|sum, j| sum+j }\n n = sum.to_s\n count += 1\n end\n\n p count\nend\n\n\nsum_of_digits"}, {"source_code": "gets.chop!\n($.+=1;$_=($_.sum(32)-48*~/$/).to_s)until~/^.$/\np$.-1\n"}, {"source_code": "s = gets.chomp\nc = 0\nwhile s.size != 1\n\ts = s.split(//).map(&:to_i).reduce(:+).to_s\n\tc += 1\nend\nputs c"}, {"source_code": "s = gets.chomp.split(\"\").collect{|i| i.to_i}\nans = 0\nwhile s.size > 1\n ans += 1\n s = s.inject{|sum,i| sum+=i}.to_s.split(\"\").collect{|i| i.to_i}\nend\nputs ans\n"}, {"source_code": "n = gets.chomp\nasr = 0\nbool = true\nwhile bool do\n if(n.to_i <=9 && n.to_i >= 0)\n bool = false\n else\n begin\n asr += 1\n n = n.to_s.split('').inject(0){ |result, elem| result.to_i + elem.to_i }\n end\n end\nend\nputs asr"}], "negative_code": [{"source_code": "n = gets.chomp\nres = 0\nfor i in 0...n.length\n res += Integer(n[i])\nend\nputs res"}, {"source_code": "s = gets\nc = 0\nwhile s.size != 1\n\ts = s.split(//).map(&:to_i).reduce(:+).to_s\n\tc += 1\nend\nputs c"}, {"source_code": "n = gets.chomp\nasr = 0\nbool = true\nwhile bool do\n if(n.to_i <=9 && n.to_i >= 0)\n bool = false\n else\n begin\n asr += 1\n n = n.to_s.split('').inject(0){ |result, elem| result.to_i + elem.to_i }\n puts n\n end\n end\nend\nputs asr"}, {"source_code": "gets.chop!\n($.+=1;$_=($_.sum(20)-48*~/$/).to_s)until~/^.$/\np$.-1"}, {"source_code": "gets\n($.+=1;$_=($_.sum(20)-48*~/$/).to_s)until~/^.$/\np$.-1"}, {"source_code": "gets.chomp!\n($.+=1;$_=($_.sum(20)-48*~/$/).to_s)until~/^.$/\np$.-1"}, {"source_code": "a=gets\n($.+=1;a=(a.sum-48*a.size).to_s)while a.size>1\np$."}, {"source_code": "n, i = gets.strip, 0\n\n(print 0; exit) if n == \"0\"\n\nloop do\n n = n.split(//).map(&:to_i).inject { |sum, e| sum += e }.to_s\n (print i + 1; exit) if n.length == 1\n i += 1\nend"}], "src_uid": "ddc9201725e30297a5fc83f4eed75fc9"} {"source_code": "n = gets.to_i\ne = Array.new(n)\ne.map!{[]}\nee = []\n\ndef gao(e, p, q)\n\tl = 0\n\tt = [0, 0]\n\te[p].each do |i|\n\t\tnext if i == q\n\t\tll, dd = gao(e, i, p)\n\t\tl = [l, ll].max\n\t\tt <<= dd + 1\n\tend\n\tt.sort!{|a, b| b <=> a}\n\tl = [l, t[0] + t[1]].max\n\treturn [l, t[0]]\nend\n\n(n - 1).times do\n\ta, b = gets.split.map{|i| i.to_i - 1}\n\te[a] <<= b\n\te[b] <<= a\n\tee <<= [a, b]\nend\nans = 0\nee.each do |p|\n\tans = [ans, gao(e, p[0], p[1])[0] * gao(e, p[1], p[0])[0]].max\nend\np ans\n", "positive_code": [{"source_code": "def gao(e, p, q)\n\tl, t = 0, [0, 0]\n\te[p].each do |i|\n\t\tnext if i == q\n\t\tll, dd = gao(e, i, p)\n\t\tl = [l, ll].max\n\t\tt <<= dd + 1\n\tend\n\tt.sort!{|a, b| b <=> a}\n\treturn [[l, t[0] + t[1]].max, t[0]]\nend\n\nn = gets.to_i\ne = Array.new(n).map{[]}\nee = []\n(n - 1).times do\n\ta, b = gets.split.map{|i| i.to_i - 1}\n\te[a] <<= b\n\te[b] <<= a\n\tee <<= [a, b]\nend\np ee.map{|p| gao(e, p[0], p[1])[0] * gao(e, p[1], p[0])[0]}.max\n\n"}, {"source_code": "=begin\n , \\ / ,\n / \\ )\\__/( / \\\n / \\ (_\\ /_) / \\\n ____/_____\\__\\@ @/___/_____\\____\n | |\\../| |\n | \\VV/ |\n | ------hoi------- |\n |_________________________________|\n | /\\ / \\\\ \\ /\\ |\n | / V )) V \\ |\n |/ ` // ' \\|\n ` V '\n=end\n\ndef dfs(e, p, q)\n\tl, t = 0, [0, 0]\n\te[p].each do |i|\n\t\tnext if i == q\n\t\tll, dd = dfs(e, i, p)\n\t\tl = [l, ll].max\n\t\tt <<= dd + 1\n\tend\n\tt.sort!{|a, b| b <=> a}\n\treturn [[l, t[0] + t[1]].max, t[0]]\nend\n\nn = gets.to_i\nrib = Array.new(n).map{[]}\nribs = []\n(n - 1).times do\n\ta, b = gets.split.map{|i| i.to_i - 1}\n\trib[a] <<= b\n\trib[b] <<= a\n\tribs <<= [a, b]\nend\nputs ribs.map{|p| dfs(rib, p[0], p[1])[0] * dfs(rib, p[1], p[0])[0]}.max\n"}], "negative_code": [], "src_uid": "b07668a66a5e50659233ba055a893bd4"} {"source_code": "\ndef solution\n _ = read_int\n as = read_ints\n\n current_max = -1\n\n for i in (0...as.size)\n a = as[i]\n if a > current_max + 1\n puts (i+1)\n return\n end\n current_max = [current_max, a].max\n end\n\n puts (-1)\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n", "positive_code": [{"source_code": "class B\n def self.run(n, m)\n prev_max = nil\n\n m.each_with_index do |el, idx|\n\n if valid_mexes(prev_max).include?(el)\n prev_max ||= el\n prev_max = prev_max < el ? el : prev_max\n else\n return idx+1\n end\n\n end\n\n return -1\n end\n\n def self.valid_mexes(prev_max)\n if !prev_max\n return [0]\n else\n (0..prev_max+1)\n end\n end\nend\n\na = gets.chomp.to_i\nb = gets.chomp.split.map(&:to_i)\nputs B.run(a, b)\n\n"}, {"source_code": "n = gets.to_i\narr = gets.chomp.split(\" \").map(&:to_i)\n\nk = 0\narr.each_with_index do |z,i|\n if z>k\n puts i+1\n exit\n elsif z==k\n k+=1\n end\nend\n\nputs -1\n"}], "negative_code": [{"source_code": "\ndef solution\n _ = read_int\n as = read_ints\n\n for i in (0...as.size)\n a = as[i]\n if a > i\n puts (i+1)\n return\n end\n end\n\n puts (-1)\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}], "src_uid": "e17427897fd5147c601204cb1c48b143"} {"source_code": "hh, mm = gets().split(' ').map(&:to_i)\nh, d, c, n = gets().split(' ')\nh, d, n = [h, d, n].map(&:to_i)\nc = c.to_f\n\nif(hh*60+mm < 20*60)\n\tputs \"%.3f\" % [((h + n - 1)/n) * c, ((h + d*(20*60 - hh*60-mm) + n - 1)/n) * (c * 0.8)].min\nelse\n\tputs \"%.3f\" % (((h + n - 1)/n) * (c*0.8))\nend", "positive_code": [{"source_code": "hh, mm = gets().split(' ').map(&:to_i)\nh, d, c, n = gets().split(' ')\nh, d, n = [h, d, n].map(&:to_i)\nc = c.to_f\n\nif(hh*60+mm < 20*60)\n\tputs \"%.3f\" % [((h + n - 1)/n) * c, ((h + d*(20*60 - hh*60-mm) + n - 1)/n) * (c * 0.8)].min\nelse\n\tputs \"%.3f\" % (((h + n - 1)/n) * (c*0.8))\nend"}], "negative_code": [{"source_code": "hh, mm = gets().split(' ').map(&:to_f)\nh, d, c, n = gets().split(' ').map(&:to_f)\n\nif(hh*60+mm < 20*60)\n\tputs \"%.3f\" % [(h + n - 1)/n * c, (h + n - 1 + d*(20*60 - hh*60+mm))/n * (c * 0.8)].min\nelse\n\tputs \"%.3f\" % ((h + n - 1)/n * (c*0.8))\nend"}, {"source_code": "hh, mm = gets().split(' ').map(&:to_i)\nh, d, c, n = gets().split(' ')\nh, d, n = [h, d, n].map(&:to_i)\nc = c.to_f\n\nif(hh*60+mm < 20*60)\n\tputs \"%.4f\" % [(h + n - 1)/n * c, (h + n - 1 + d*(20*60 - hh*60+mm))/n * (c * 0.8)].min\nelse\n\tputs \"%.4f\" % (h + n - 1)/n * (c*0.8)\nend"}, {"source_code": "hh, mm = gets().split(' ').map(&:to_i)\nh, d, c, n = gets().split(' ')\nh, d, n = [h, d, n].map(&:to_i)\nc = c.to_f\n\nif(hh*60+mm < 20*60)\n\tputs \"%.3f\" % [((h + n - 1)/n) * c, ((h + d*(20*60 - hh*60+mm) + n - 1)/n) * (c * 0.8)].min\nelse\n\tputs \"%.3f\" % (((h + n - 1)/n) * (c*0.8))\nend"}, {"source_code": "hour, minute = gets.split.map(&:to_f)\nhunger, dec, bunCost, inc = gets.split.map(&:to_f)\nbuyNow = hunger/inc*bunCost\nbuyLater = (hunger + dec*(1200 - ((hour%24)*60+minute)))/inc*(bunCost-(bunCost*0.2))\nputs [buyLater,buyNow].min.round(4)"}, {"source_code": "hour, minute = gets.split.map(&:to_i)\nhunger, dec, bunCost, inc = gets.split.map(&:to_f)\nbuyNow = (hunger/inc).ceil*bunCost\nbuyLater = ((hunger + dec*(1200 - ((hour%24)*60+minute)))/inc).ceil * bunCost\nbuyLater -= buyLater*0.2\nputs hour != 20 ? [buyLater,buyNow].min : buyNow"}, {"source_code": "hour, minute = gets.split.map(&:to_i)\nhunger, dec, bunCost, inc = gets.split.map(&:to_f)\nbuyNow = (hunger/inc).ceil*bunCost\nbuyLater = ((hunger + dec*(1200 - ((hour%24)*60+minute)))/inc).ceil * bunCost\nbuyLater -= buyLater*0.2\nputs hour != 20 ? [buyLater,buyNow].min : buyNow-(buyNow*0.2)"}, {"source_code": "hour, minute = gets.split.map(&:to_i)\nhunger, dec, bunCost, inc = gets.split.map(&:to_f)\nbuyNow = (hunger/inc).ceil*bunCost\nbuyLater = ((hunger + dec*(1200 - ((hour%24.0)*60+minute)))/inc).ceil * bunCost\nbuyLater -= buyLater*0.2\nputs [buyLater,buyNow].min"}], "src_uid": "937acacc6d5d12d45c08047dde36dcf0"} {"source_code": "t = gets.to_s.to_i\n\ndef solve(maxx, maxy, k, cache)\n return k == 0 if maxx == 1 && maxy == 1\n return false if k <= 0 || maxx < 1 || maxy < 1\n maxx, maxy = maxy, maxx if maxx < maxy\n return cache[maxx * 128 + maxy] if cache.has_key?(maxx * 128 + maxy)\n\n result = solve(maxx - 1, maxy, k - maxy, cache) || solve(maxx, maxy - 1, k - maxx, cache)\n cache[maxx * 128 + maxy] = result\n return result\nend\n\n1.upto(t) do |casenum|\n maxx, maxy, k = gets.to_s.split.map {|x| x.to_i }\n printf(\"%s\\n\", solve(maxx, maxy, k, {}) ? \"YES\" : \"NO\")\nend\n", "positive_code": [{"source_code": "test_cases = gets.chomp.to_i\r\nfor i in 1..test_cases do\r\n line = gets.chomp.split(\" \")\r\n n = line[0].to_i\r\n m = line[1].to_i\r\n k = line[2].to_i\r\n puts (n - 1) + n * (m - 1) == k ? \"Yes\" : \"No\"\r\nend"}], "negative_code": [], "src_uid": "8b0a9c7e997034d3ecce044b9f64aeba"} {"source_code": "#!/usr/bin/ruby1.9\n\nn = STDIN.readline.to_i\na = STDIN.readline.split.collect {|s| s.to_i }\n\nb = []\na.each do |x|\n\t#b.push([(1-x).abs, x])\n\tb.push(x)\nend\nb.sort!\n\n#puts b.inspect\n\nsum = 0\nn.times do |i|\n\t#sum += (i+1-b[i][1]).abs\n\tsum += (i+1-b[i]).abs\nend\n\nputs sum\n", "positive_code": [{"source_code": "n = gets.to_i;\na = gets.split.map(& :to_i);\ncur = 0; \nb = a.sort;\np (1..n).inject(0){|acc, x| acc + (x - b[x-1]).abs}\n#p a.sort.inject {|acc, x| cur += 1; acc + (cur - x).abs}\n"}, {"source_code": "n = Integer(gets.chomp)\na = gets.chomp.split.map { |x| x.to_i }.sort\ncount = 0\nfor i in 1..n\n count += (a[i - 1] - i).abs\nend\nputs count"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\na.sort!\n i = n - 1 \n move = 0\n while i >= 0 do\n move += (a[i] - i - 1).abs\n i -= 1\n end\n\nputs move"}, {"source_code": "gets;a,s=gets.split.map(&:to_i).sort,0;a.size.times {|i|s+=(a[i]-i-1).abs};p s;"}, {"source_code": "#!/usr/bin/env ruby\n\ngets\ntot = 0\ngets.split.collect{ |i| i.to_i }.sort.each_with_index { |x, i| tot += (i + 1 - x).abs }\nputs tot\n"}, {"source_code": "n, _ = gets.strip.split.map(&:to_i)\nas = gets.strip.split.map(&:to_i).sort\n\nresult = 0\n(1..n).each do |i|\n result += (as[i-1] - i).abs\nend\n\nputs result\n\n\n\n\n"}, {"source_code": "gets;a,s=gets.split.map(&:to_i).sort,0;a.size.times {|i|s+=(a[i]-i-1).abs};p s;\n"}, {"source_code": "gets;a,s=gets.split.map(&:to_i).sort,0;a.size.times {|i|s+=(a[i]-i-1).abs};p s;\n"}, {"source_code": "gets;p gets.split.map(&:to_i).sort.each_with_index.inject(0){|s,(v,i)| s+(v-i-1).abs}"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i).sort\nputs n.times.inject(0){|s, i| s+(a[i]-i-1).abs}"}, {"source_code": "n = gets.to_i; a = gets.split.map &:to_i; a.sort!\nres = 0; 0.upto(n-1){|i|res += (a[i] - i - 1).abs}\nputs res"}, {"source_code": "gets;a,s=gets.split.map(&:to_i).sort,0;a.size.times {|i|s+=(a[i]-i-1).abs};p s;\n"}, {"source_code": "gets;a,s=gets.split.map(&:to_i).sort,0;a.size.times {|i|s+=(a[i]-i-1).abs};p s;\n"}, {"source_code": "n = gets.to_i\nt = gets.split.map(&:to_i).sort\nresult = 0\nt.each_with_index do |x, i|\n result += (i + 1 - x).abs\nend\nputs result"}, {"source_code": "gets;a,s=gets.split.map(&:to_i).sort,0;a.size.times {|i|s+=(a[i]-i-1).abs};p s;\n"}, {"source_code": "gets;a,s=gets.split.map(&:to_i).sort,0;a.size.times {|i|s+=(a[i]-i-1).abs};p s;"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort;p (0...a.size).inject(0){|s,i|s+(a[i]-i-1).abs}"}, {"source_code": "gets;a,s=gets.split.map(&:to_i).sort,0;a.size.times {|i|s+=(a[i]-i-1).abs};p s;\n"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\nperm = gets.split.map(&:to_i).sort\n\nchanges = 0\nset = Set.new\nindex = 1\nperm.each{|value|\n changes+=(index - value).abs\n index+=1\n}\n\nprint changes"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\nperm = gets.split.map(&:to_i).sort\n\nchanges = 0\nindex = 1\nperm.each{|value|\n changes+=(index - value).abs\n index+=1\n}\n\nprint changes"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\n\nless = []\nmiddle = []\ngreater = []\n\nn.times do |i|\n if a[i] < 1\n less << a[i]\n elsif a[i] > n\n greater << a[i]\n else\n middle << a[i]\n end\nend\nless.sort!\ngreater.sort!\nmiddle.sort!\n\nl = less.length\ng = greater.length\n\nmove = 0\n\noriginal = (1..n).to_a\nmissing = original - middle \nlength_missing = missing.length\n\nsame = []\nold_x = 0\nmiddle.each do |x|\n if x != old_x\n old_x = x\n else\n same << x\n end\nend\n\nsum_less = 0\nsum_missing = 0\nl.times do |i|\n sum_missing += missing[i]\n sum_less += less[i]\nend\nmove += sum_missing - sum_less\n\nsum_greater = 0\nsum_missing = 0\ng.times do |i|\n sum_missing += missing[length_missing - i - 1]\n sum_greater += greater[i]\nend\nmove += sum_greater - sum_missing\n\nmissing[l...(length_missing - g)].each_with_index do |x,i|\n move += (x - same[i]).abs\nend\n\nputs move\n"}, {"source_code": "n = gets.to_i\nvec = (gets.split.map &:to_i).sort\ntotal = 0\nfor i in (0...n)\n total+=(i+1-vec[i]).abs\nend \nputs total"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i).sort\na.unshift(0)\nres=0\n1.upto(n) {|x| res+=(x-a[x]).abs}\nputs res\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\na = gets.split.map(&:to_i)\ndelta_sum = 0\nfor tup in (1..n).zip(a.sort)\n # p tup\n delta_sum += (tup[0] - tup[1]).abs\nend\n\nputs delta_sum"}, {"source_code": "n = Integer(gets)\na = Array.new\ninput = gets.chomp\nnums = input.split\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\n\na = a.sort\nc = 0\nfor i in 0...n\n c += (i + 1 - a[i]).abs\nend\nputs c\n"}, {"source_code": "n = gets.to_i\nv = gets.split.map &:to_i\nv = v.sort\nmoves=0\nfor i in 0...n\n moves+=((i+1)-v[i]).abs\nend\nputs moves"}, {"source_code": "gets;a,s=gets.split.map(&:to_i).sort,0;a.size.times {|i|s+=(a[i]-i-1).abs};p s;\n"}, {"source_code": "n = gets.to_i\na = [nil] +gets.split.map(&:to_i).sort\nans = 0\n1.upto(n) do |i|\n ans += (i - a[i]).abs\nend\np ans\n"}, {"source_code": "gets;p gets.split.map(&:to_i).sort.map.with_index{|x,i|(x-i-1).abs}.inject(:+)\n"}, {"source_code": "gets;a,s=gets.split.map(&:to_i).sort,0;a.size.times {|i|s+=(a[i]-i-1).abs};p s;\n"}], "negative_code": [{"source_code": "gets;a=gets.split.map(&:to_i);p (0...a.size).inject(0){|s,i|s+(a[i]-i-1).abs}"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\n\nless = []\nmiddle = []\ngreater = []\n\nn.times do |i|\n if a[i] < 1\n less << a[i]\n elsif a[i] > n\n greater << a[i]\n else\n middle << a[i]\n end\nend\nless.sort!\ngreater.sort!\n\nmove = 0\n(1..n).each do |i|\n unless middle.include?(i)\n if less.any?\n move += i - less.shift\n elsif greater.any?\n move += greater.shift - i\n end\n end\nend\n\nputs move\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\na = gets.split.map(&:to_i)\ndelta_sum = 0\nfor tup in (1..n).zip(a)\n delta_sum += (tup[0] - tup[1]).abs\nend\n\nputs delta_sum"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|i| i.to_i}\na.sort!\n i = n - 1 \n move = 0\n while i > 0 do\n move +=(a[i] - i - 1).abs\n i -= 1\n end\n\nputs move"}, {"source_code": "n = gets.to_i\ng = gets.split(' ')\na = []\nindex = []\nindex1 = []\ns = 0 \ngiam = 0\n\n(0..n-1).each do |i|\n a[i] = g[i].to_i\nend\n\n(1..n+1).each do |i|\n index[i] = 0\n index1[i] = 0\nend\n\n(0..n-1).each do |i|\n s += a[i]\n if a[i] >= n \n a[i] = n\n giam = a[i] - n \n index[n] +=1\n else\n index[a[i]] +=1 if a[i] > 0\n end \nend\n\nindex1[n+1] = 0\ni = n\nwhile i > 0\n index1[i] = index1[i+1] + index[i]\n giam += index1[i] - (n+1-i) if index1[i] > (n+1-i)\n i -= 1\nend\n\nt = (n+1)*n/2\ns1 = (s-t).abs + 2*giam\n\nputs s1"}, {"source_code": "n = gets.to_i\ng = gets.split(' ')\na = []\nindex = []\nindex1 = []\ns = 0 \ngiam = 0\ns1 = 0\n\n(0..n-1).each do |i|\n a[i] = g[i].to_i\nend\n\n(1..n+1).each do |i|\n index[i] = 0\n index1[i] = 0\nend\n\n(0..n-1).each do |i|\n if a[i] > n \n s1 += a[i] - n \n index[n] +=1\n a[i] = n\n else\n index[a[i]] +=1 if a[i] > 0\n end \n s += a[i]\nend\n\nindex1[n+1] = 0\ni = n\nwhile i > 0\n index1[i] = index1[i+1] + index[i]\n giam += index1[i] - (n+1-i) if index1[i] > (n+1-i)\n i -= 1\nend\n\nt = (n+1)*n/2\ns1 += (s-t).abs + 2*giam\n\nputs s\nputs s1"}, {"source_code": "n = gets.to_i\ng = gets.split(' ')\na = []\nindex = []\nindex1 = []\ns = 0 \ngiam = 0\ns1 = 0\n\n(0..n-1).each do |i|\n a[i] = g[i].to_i\nend\n\n(1..n+1).each do |i|\n index[i] = 0\n index1[i] = 0\nend\n\n(0..n-1).each do |i|\n if a[i] > n \n s1 += a[i] - n \n index[n] +=1\n a[i] = n\n else\n index[a[i]] +=1 if a[i] > 0\n end \n s += a[i]\nend\n\nindex1[n+1] = 0\ni = n\nwhile i > 0\n index1[i] = index1[i+1] + index[i]\n giam += index1[i] - (n+1-i) if index1[i] > (n+1-i)\n i -= 1\nend\n\nt = (n+1)*n/2\ns1 += (s-t).abs + 2*giam\n\nputs s1"}, {"source_code": "n = gets.to_i\ng = gets.split(' ')\na = []\nindex = []\nindex1 = []\ns = 0 \ngiam = 0\ns1 = 0\n\n(0..n-1).each do |i|\n a[i] = g[i].to_i\nend\n\n(1..n+1).each do |i|\n index[i] = 0\n index1[i] = 0\nend\n\n(0..n-1).each do |i|\n if a[i] > n \n s1 += a[i] - n \n index[n] +=1\n a[i] = n\n else\n index[a[i]] +=1 if a[i] > 1\n end \n s += a[i]\nend\n\nindex1[n+1] = 0\ni = n\nwhile i > 0\n index1[i] = index1[i+1] + index[i]\n giam += index1[i] - (n+1-i) if index1[i] > (n+1-i)\n i -= 1\nend\n\nt = (n+1)*n/2\ns1 += (s-t).abs + 2*giam\n\nputs s1"}], "src_uid": "86d5da999415fa75b3ee754a2a28605c"} {"source_code": "def make_score(arr)\n score = 0\n ph_s = 0\n arr.each do |b|\n if b\n ph_s += 1\n else\n if ph_s.positive?\n score += 1\n ph_s -= 1\n end\n end\n end\n score\nend\n\ntestcases = gets.to_i\ntestcases.times do\n str = gets.chars\n small = []\n large = []\n str.each do |c|\n case c\n when '('\n small << true\n when ')'\n small << false\n when '['\n large << true\n when ']'\n large << false\n end\n end\n p make_score(small) + make_score(large)\nend\n", "positive_code": [{"source_code": "DEBUG = false\nMOD = 10**9+7\nYESNO = %w(Yes No)\n\ndef main\n t = int\n t.times do\n p1 = 0\n p2 = 0\n count = 0\n string.each_char do |c|\n case c\n when ?(\n p1 += 1\n when ?)\n count += 1 if p1 > 0\n p1 -= 1 if p1 > 0\n when ?[\n p2 += 1\n when ?]\n count += 1 if p2 > 0\n p2 -= 1 if p2 > 0\n end\n end\n\n puts count\n end\nend\n\ndef int; gets.to_i; end\ndef ints; gets.split.map &:to_i; end\ndef float; gets.to_f; end\ndef floats; gets.split.map &:to_f; end\ndef array(&convert); gets.split.map(&convert); end\ndef string; gets.chomp; end\ndef rep(n, &b); Array.new(n, &b); end\ndef yes; puts YESNO[0]; end\ndef no; puts YESNO[1]; end\ndef yesno t; t ? yes : no; end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } }; end\ndef sorted_uniq(xs); x = nil; xs.filter! { |y| c = x === y; x = y; !c }; end\ndef max(*xs); xs.max; end\ndef min(*xs); xs.min; end\ndef minmax(*xs); xs.minmax; end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w }; end\ndef debug(x); if DEBUG; STDERR.puts (block_given? ? yield(x) : x).inspect; end; x; end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid; end\ndef if_debug; yield if DEBUG; end\n\ndef div_ceil(x, y); (x + y - 1) / y; end\ndef gcd(*xs); xs.inject(0) { |y, x| y.gcd(x) }; end\ndef factorial(n, mod); (2..n).inject(1) { |f, x| f * x % mod }; end\ndef cumsum(xs); ys = [0]; xs.each { |x| ys << x + ys[-1] }; ys; end\ndef cumdiff(ys); xs = []; xs.inject { |x, y| xs << (d = y - x); d }; end\ndef cumfold(ys, range); r = range.end; r -= 1 if range.exclusive_end?; ys[r] - ys[range.begin-1]; end\ndef mod_inv(x, mod); x.pow(mod-2, mod); end\ndef mod_div(x, y, mod); x * mod_inv(y, mod) % mod; end\ndef bitbrute(size, &block); (1< 0\n b1 = [b1 - 1, 0].max if el == ')'\n b2 += 1 if el == '['\n mx2 += 1 if el ==']' && b2 > 0\n b2 = [b2 - 1, 0].max if el == ']'\n end\n puts mx1 + mx2\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n a = gets.chomp.split(\"\")\n count = 0\n co = 0\n lo = 0\n a.each do |i|\n if i == \"(\"\n co += 1\n elsif i == \")\" && co >= 1\n co -= 1\n count += 1\n elsif i == \"[\"\n lo += 1\n elsif i == \"]\" && lo >= 1\n lo -= 1\n count += 1\n end\n end\n puts count\nend"}], "negative_code": [{"source_code": "DEBUG = false\nMOD = 10**9+7\nYESNO = %w(Yes No)\n\ndef main\n t = int\n t.times do\n p1 = 0\n p2 = 0\n count = 0\n string.each_char do |c|\n case c\n when ?(\n p1 += 1\n when ?)\n count += 1 if p1 > 0\n p1 -= 1\n when ?[\n p2 += 1\n when ?]\n count += 1 if p2 > 0\n p2 -= 1\n end\n end\n\n puts count\n end\nend\n\ndef int; gets.to_i; end\ndef ints; gets.split.map &:to_i; end\ndef float; gets.to_f; end\ndef floats; gets.split.map &:to_f; end\ndef array(&convert); gets.split.map(&convert); end\ndef string; gets.chomp; end\ndef rep(n, &b); Array.new(n, &b); end\ndef yes; puts YESNO[0]; end\ndef no; puts YESNO[1]; end\ndef yesno t; t ? yes : no; end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } }; end\ndef sorted_uniq(xs); x = nil; xs.filter! { |y| c = x === y; x = y; !c }; end\ndef max(*xs); xs.max; end\ndef min(*xs); xs.min; end\ndef minmax(*xs); xs.minmax; end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w }; end\ndef debug(x); if DEBUG; STDERR.puts (block_given? ? yield(x) : x).inspect; end; x; end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid; end\ndef if_debug; yield if DEBUG; end\n\ndef div_ceil(x, y); (x + y - 1) / y; end\ndef gcd(*xs); xs.inject(0) { |y, x| y.gcd(x) }; end\ndef factorial(n, mod); (2..n).inject(1) { |f, x| f * x % mod }; end\ndef cumsum(xs); ys = [0]; xs.each { |x| ys << x + ys[-1] }; ys; end\ndef cumdiff(ys); xs = []; xs.inject { |x, y| xs << (d = y - x); d }; end\ndef cumfold(ys, range); r = range.end; r -= 1 if range.exclusive_end?; ys[r] - ys[range.begin-1]; end\ndef mod_inv(x, mod); x.pow(mod-2, mod); end\ndef mod_div(x, y, mod); x * mod_inv(y, mod) % mod; end\ndef bitbrute(size, &block); (1<b\nputs \"#{v*c}\"\nelse \nputs \"#{b*c}\"\nend\n"}], "src_uid": "6421a81f85a53a0c8c63fbc32750f77f"} {"source_code": "gets.chomp.to_i.times do\r\n n = gets.chomp.to_i\r\n str = gets.chomp.split.map{|el| el.to_i}.sort\r\n \r\n smallSum = str[0]\r\n bigSum =0\r\n boolFound=false\r\n \r\n for i in 0..str.length-1\r\n smallSum +=str[i].to_i\r\n bigSum +=str[-i].to_i\r\n if(bigSum>smallSum)\r\n puts \"YES\"\r\n boolFound = true\r\n end\r\n break if(boolFound)\r\n end\r\n \r\n if(boolFound==false)\r\n puts \"NO\"\r\n end\r\n\r\nend", "positive_code": [{"source_code": "t=gets.chomp.to_i\r\n\r\nt.times do\r\n n = gets.chomp.to_i\r\n str = gets.chomp.split\r\n arr = str.sort_by{|el| el.to_i}\r\n # for i in 0..str.length-1\r\n # arr[i]=str[i].to_i\r\n # end\r\n #arr = str.sort\r\n\r\n # puts arr\r\n smallSum = arr[0].to_i\r\n bigSum =0\r\n boolFound=false\r\n for i in 0..str.length-1\r\n smallSum +=arr[i].to_i\r\n bigSum +=arr[-i].to_i\r\n \r\n #puts \" smallSum = #{smallSum} bigSum = #{bigSum}\"\r\n if(bigSum>smallSum)\r\n puts \"YES\"\r\n boolFound = true\r\n \r\n # puts \" if #{boolFound}\"\r\n \r\n end\r\n break if(boolFound)\r\n #puts \" breal if #{boolFound}\"\r\n\r\n end\r\n if(boolFound==false)\r\n puts \"NO\"\r\n end\r\n # puts \" breal if #{boolFound}\"\r\n\r\nend"}], "negative_code": [{"source_code": "t=gets.chomp.to_i\r\n\r\nt.times do\r\n n = gets.chomp.to_i\r\n str = gets.chomp.split.sort\r\n smallSum = str[0].to_i\r\n bigSum =0\r\n boolFound=false\r\n for i in 0..str.length-1\r\n smallSum +=str[i].to_i\r\n bigSum +=str[-i].to_i\r\n if(bigSum>smallSum)\r\n puts \"YES\"\r\n boolFound = true\r\n end\r\n break if(boolFound)\r\n end\r\n if(boolFound==false)\r\n puts \"NO\"\r\n end\r\nend"}], "src_uid": "4af59df1bc56ca8eb5913c2e57905922"} {"source_code": "n,k=gets.split.map(&:to_i)\npoint=[]\nfor i in 1..n\n point.push(gets.split.map(&:to_i))\nend\nres=0.0\nfor i in 1..n-1\n res+=Math::sqrt((point[i-1][0]-point[i][0])**2+(point[i-1][1]-point[i][1])**2)\nend\np res/50*k\n", "positive_code": [{"source_code": "str = STDIN.gets.chomp.split(' ')\nn = str[0].to_i\nk = str[1].to_i\nx = Array.new\ny = Array.new\nn.times do |i|\n str = STDIN.gets.chomp.split(' ')\n x[i] = str[0].to_f\n y[i] = str[1].to_f\nend\n\n\ndist = 0.0\n1.upto(x.length - 1).each do |i|\n dist += (((x[i - 1] - x[i]) ** 2) + ((y[i - 1] - y[i]) ** 2)) ** 0.5\nend\nputs \"%.9f\" %[((dist * k) / 50).to_f]"}, {"source_code": "n, k = gets.split.map &:to_i\np = n.times.map { |_| gets.split.map(&:to_i) }\np n.times.inject() { |s, i|\n a, b = p[i], p[i-1]\n s += Math.hypot(a[0]-b[0], a[1]-b[1])\n} * k / 50\n"}, {"source_code": "n, k = gets.split.map &:to_i\npt = STDIN.each.to_a\ns = 0.upto(pt.length - 1).inject do |s, i|\n a = pt[i].split.map(&:to_i)\n b = pt[i - 1].split.map(&:to_i)\n s += Math.hypot(a[0] - b[0], a[1] - b[1])\nend\np s * k / 50\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn, k = ($stdin.readline).split().collect { |x| x.to_i }\n\npoints = ($stdin.readlines).collect {|s| s.split().collect {|x| x.to_i} }\n\nspeed = 50\n\ndef dist(a, b)\n\treturn Math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)\nend\n\nsum = 0.0\n\n(n-1).times { |i|\n\tsum += dist(points[i], points[i+1])\n\t}\n\nputs sum/speed*k"}, {"source_code": "n,k = gets.split.map(&:to_i)\narr = (1..n).map{|e| gets.split.map(&:to_i)}\nbefore = arr[0]\np arr.map{|e| ret = Math::sqrt((before[0] - e[0]) ** 2 + (before[1] - e[1]) ** 2); before = e ; ret}.reduce(:+) / 50 * k\n\n"}, {"source_code": "def dist (x1,y1,x2,y2)\n Math.sqrt((x2-x1)**2 + (y2-y1)**2)\nend\nn, k = gets.split.map(&:to_i)\na = readlines.map(&:chomp).map(&:split).each { |x| x.map!(&:to_i) }\nputs (1...n).map{ |i| dist a[i-1][0], a[i-1][1], a[i][0], a[i][1] }.inject(:+)*k/50.0"}, {"source_code": "n, k = gets.strip.split.map {|x| x.to_i}\ndef dis x1, y1, x2, y2\n Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))\nend\nsum = 0.0\nbef = gets.strip.split.map {|x| x.to_i}\nn.pred.times do\n cur = gets.strip.split.map {|x| x.to_i}\n sum += dis *bef, *cur\n bef = cur\nend\nputs sum * k / 50.0"}, {"source_code": "n,k=gets.split.map(&:to_i)\n\ndots=[]\nn.times{dots << gets.split.map(&:to_f)}\n\ndist=0\nfor i in 0...(n-1)\n\tdist+=Math.sqrt((dots[i][0] - dots[i+1][0])**2 + (dots[i][1] - dots[i+1][1])**2)\nend\n\nprintf \"%.7f\", (dist/50.0)*k\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\no=[]\nn.times{o << gets.split.map(&:to_f)}\nd=0\nfor i in 0...(n-1)\n\td+=Math.sqrt((o[i][0] - o[i+1][0])**2 + (o[i][1] - o[i+1][1])**2)\nend\nprintf \"%.7f\",d/50.0*k\n"}, {"source_code": "n,k = gets.split()\nn = n.to_i\nk = k.to_i\nx = Array.new(n)\ny = Array.new(n)\nfor i in 0...n do\n xx,yy = gets.split()\n x[i] = xx.to_f\n y[i] = yy.to_f\nend\ndist = 0.0\nfor i in 1...n do\n xd = x[i] - x[i-1]\n yd = y[i] - y[i-1]\n d = xd*xd + yd*yd;\n dist += (d ** 0.5);\nend\n print dist / 50.0 * k, \"\\n\";\n"}, {"source_code": "input = gets.chomp\nnums = input.split\nn = Integer(nums[0])\nk = Integer(nums[1])\ncoordinate = Array.new\nfor i in 0...n\n\tcoordinate[i] = Array.new\n\tinput2 = gets.chomp\n\tnums2 = input2.split\n\tfor j in 0...2\n\t\tcoordinate[i][j] = Integer(nums2[j])\n\tend\nend\ncount = 0\n\nfor i in 0...n-1\n\tc = (coordinate[i][0] - coordinate[i+1][0]) ** 2 + (coordinate[i][1] - coordinate[i+1][1])** 2 \n\tc = ((c** (0.5)) / 50) * k\n\tcount += c\nend\n\nputs count = format(\"%.9f\",count)"}, {"source_code": "n,k = gets.split.map &:to_i\nx2 = y2 = sum = 0\nfor i in (1..n)\n x1, y1 = gets.split.map &:to_i\n if i > 1\n sum +=Math.hypot(x2-x1,y2-y1)\n end\n x2, y2 = x1,y1\nend\nputs (sum*k)/50"}, {"source_code": "n, k = gets.split.map(&:to_i)\np = Array.new(n)\n(0...n).each { |i| a, b = gets.split.map(&:to_i); p[i] = Array.new(2); p[i][0] = a; p[i][1] = b }\nlen = 0.0\n(1...n).each { |i| len += Math.sqrt( (p[i][0] - p[i-1][0]) ** 2 + (p[i][1] - p[i-1][1]) ** 2 ) }\nputs((k * len) / 50.0)"}, {"source_code": "\nn, k = gets.split(\" \").map do |s| s.to_i end\n\npx, py = gets.split(\" \").map do |s| s.to_i end\n\ntime = 0\n(n-1).times do\n x, y = gets.split(\" \").map do |s| s.to_i end\n time += Math.sqrt((x-px)**2 + (y-py)**2) / 50\n px, py = x, y\nend\n\nputs time*k\n"}, {"source_code": "def next_line\n gets.chomp.split.map { |x| x.to_i }\nend\n\nn, k = next_line\nd = 0\np = next_line\nfor _ in 1...n\n c = next_line\n d += Math.sqrt((c[0] - p[0]).abs ** 2 + (c[1] - p[1]).abs ** 2)\n p = c\nend\nputs d.to_f * k / 50"}, {"source_code": "\ndef size(a1, a2)\n\n return Math.sqrt((a1[0] - a2[0])*(a1[0] - a2[0]) + \n (a1[1] - a2[1])*(a1[1] - a2[1]))\nend\n\nSpeed = 50\n\nn, k = gets().split.map { |elem| elem.to_i}\n\nif n == 0\n puts 0\n return \nend\n\na_i = gets().split.map { |elem| elem.to_i}\nlength = 0\n\nfor i in 2..n\n a = gets().split.map { |elem| elem.to_i}\n length += size(a_i, a)\n a_i = a\nend\n\nputs length / Speed * k\n\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nans, x, y = 0, 0, 0\nn.times{ |i|\n u, v = gets.split.map(&:to_i)\n ans+=Math.hypot(u-x,v-y) if i > 0\n x, y = u, v\n}\nprintf(\"%.9f\\n\",ans*k/50)\n"}, {"source_code": "def meh\n meh = gets.split.map(&:to_i)\n n = meh[0]\n k = meh[1]\n total = 0\n\n meh = gets.split.map(&:to_i)\n\n for i in 1..(n - 1) do\n current = gets.split.map(&:to_i)\n distance = Math.sqrt((current[0] - meh[0]) * (current[0] - meh[0]) + (current[1] - meh[1]) * (current[1] - meh[1]))\n\n total += distance\n meh = current\n end\n\n puts (total/50.0) * k\nend\n\nmeh\n"}, {"source_code": "n, k = gets.split.map &:to_i\npoints = STDIN.read.split(\"\\n\").map { |e| e.split.map! &:to_i }\ndistance = 0\n\n(points.length - 1).times { |i| distance += Math.sqrt((points[i][0] - points[i + 1][0]) ** 2 + (points[i][1] - points[i + 1][1]) ** 2) }\n\nprint \"%.9f\" % (distance * k / 50.0)"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\n\nn, k = ($stdin.readline).split().collect { |x| x.to_i }\n\npoints = ($stdin.readlines).collect {|s| s.split().collect {|x| x.to_i} }\n\nspeed = 50\n\ndef dist(a, b)\n\treturn Math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)\nend\n\nsum = 0.0\n\n(n-1).times { |i|\n\tsum += dist(points[i], points[i+1])\n\tputs \"#{i} - #{sum}\"\n\t}\n\nputs sum/speed*k"}, {"source_code": "require 'scanf'\ninput = scanf(\"%d %d\")\nn = input[0]\nk = input[1]\nx = Array.new(n)\ny = Array.new(n)\nfor i in 0...n do\n input = scanf(\"%d %d\")\n x[i] = input[0]\n y[i] = input[1]\nend\ndist = 0.0\nfor i in 1...n do\n xd = x[i] - x[i-1]\n yd = y[i] - y[i-1]\n dist += Math.sqrt(xd * xd + yd * yd);\nend\nprint dist * k / 50.0, \"\\n\";\n"}, {"source_code": "require 'scanf'\ninput = scanf(\"%d %d\")\nn = input[0]\nk = input[1]\nx = Array.new(n)\ny = Array.new(n)\nfor i in 0...n do\n input = scanf(\"%f %f\")\n x[i] = input[0]\n y[i] = input[1]\nend\ndist = 0.0\nfor i in 1...n do\n# d = 1.0 + x[i]\n d = (x[i] - x[i-1]) * (x[i] - x[i-1]) + (y[i] - y[i-1]) * (y[i] - y[i-1])\n dist += Math.sqrt(d);\nend\nprint dist * k / 50.0, \"\\n\";\n"}, {"source_code": "require 'scanf'\ninput = scanf(\"%d %d\")\nn = input[0]\nk = input[1]\nx = Array.new(n)\ny = Array.new(n)\nfor i in 0...n do\n input = scanf(\"%d %d\")\n x[i] = input[0]\n y[i] = input[1]\nend\ndist = 0.0\nfor i in 1...n do\n xd = x[i] - x[i-1]\n yd = y[i] - y[i-1]\n dist += Math.sqrt(xd * xd + yd * yd);\nend\n print dist / 50.0 * k, \"\\n\";\n"}, {"source_code": "require 'scanf'\ninput = scanf(\"%d %d\")\nn = input[0]\nk = input[1]\nx = Array.new(n)\ny = Array.new\nfor i in 0...n do\n input = scanf(\"%d %d\")\n x[i] = input[0]\n y[i] = input[1]\nend\ndist = 0.0\nfor i in 1...n do\n xd = x[i] - x[i-1]\n yd = y[i] - y[i-1]\n d = xd*xd + yd*yd;\n dist += (d ** 0.5);\nend\n print dist / 50.0 * k, \"\\n\";\n"}, {"source_code": "require 'scanf'\ninput = scanf(\"%d %d\")\nn = input[0]\nk = input[1]\nx = Array.new(n)\ny = Array.new\nfor i in 0...n do\n input = scanf(\"%d %d\")\n x[i] = input[0]\n y[i] = input[1]\nend\ndist = 0.0\nfor i in 1...n do\n xd = x[i] - x[i-1]\n yd = y[i] - y[i-1]\n dist += Math.sqrt(xd * xd + yd * yd);\nend\n print dist / 50.0 , \"\\n\";\n"}], "src_uid": "db4a25159067abd9e3dd22bc4b773385"} {"source_code": "#!/usr/bin/env ruby\nrequire 'tsort'\nclass Hash\n\tinclude TSort\n\talias tsort_each_node each_key\n\tdef tsort_each_child(node, &block)\n\t\tfetch(node).each(&block)\n\tend\nend\nA=gets.to_i.times.map{gets.chomp.chars.to_a}\nh={}\nA.combination(2){|x,y|\n\tif [x.size,y.size].min.times{|i|\n\t\tif x[i]!=y[i]\n\t\t\th[x[i]]||=[]\n\t\t\th[y[i]]||=[]\n\t\t\th[y[i]]<y.size\n\t\tputs :Impossible\n\t\texit\n\tend\n}\nr=([*'a'..'z']-h.keys+h.tsort)*'' rescue 'Impossible'\nputs r\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\nrequire 'tsort'\nclass Hash\n\tinclude TSort\n\talias tsort_each_node each_key\n\tdef tsort_each_child(node, &block)\n\t\tfetch(node).each(&block)\n\tend\nend\nA=gets.to_i.times.map{gets.chomp.chars.to_a}\nh={}\nA.combination(2){|x,y|\n\tif [x.size,y.size].min.times{|i|\n\t\tif x[i]!=y[i]\n\t\t\th[x[i]]||=[]\n\t\t\th[y[i]]||=[]\n\t\t\th[y[i]]<y.size\n\t\tputs :Impossible\n\t\texit\n\tend\n}\nr=([*'a'..'z']-h.keys+h.tsort)*'' rescue 'Impossible'\nputs r\n"}, {"source_code": "#!/usr/bin/env ruby\nrequire 'tsort'\nclass Hash\n\tinclude TSort\n\talias tsort_each_node each_key\n\tdef tsort_each_child(node, &block)\n\t\tfetch(node).each(&block)\n\tend\nend\nA=gets.to_i.times.map{gets.chomp.chars.to_a}\nh={}\nA.combination(2){|x,y|\n\tif [x.size,y.size].min.times{|i|\n\t\tif x[i]!=y[i]\n\t\t\th[x[i]]||=[]\n\t\t\th[y[i]]||=[]\n\t\t\th[y[i]]<y.size\n\t\tputs :Impossible\n\t\texit\n\tend\n}\nr=([*'a'..'z']-h.keys+h.tsort)*'' rescue 'Impossible'\nputs r\n"}, {"source_code": "#!/usr/bin/env ruby\nrequire 'tsort'\nclass Hash\n\tinclude TSort\n\talias tsort_each_node each_key\n\tdef tsort_each_child(node, &block)\n\t\tfetch(node).each(&block)\n\tend\nend\nA=gets.to_i.times.map{gets.chomp.chars.to_a}\nh={}\nA.combination(2){|x,y|\n\tif [x.size,y.size].min.times{|i|\n\t\tif x[i]!=y[i]\n\t\t\th[x[i]]||=[]\n\t\t\th[y[i]]||=[]\n\t\t\th[y[i]]<y.size\n\t\tputs :Impossible\n\t\texit\n\tend\n}\nr=([*'a'..'z']-h.keys+h.tsort)*'' rescue 'Impossible'\nputs r\n"}, {"source_code": "Point = Struct.new(:char, :color, :children)\nchars = Hash[('a'..'z').map{|c| [c, Point.new(c, :white, [])]}]\nn = gets.to_i\nwords = []\nn.times do\n words << gets.chomp.chars\nend\nwords.each_cons(2) do |prv,nxt|\n p, n = prv.zip(nxt).drop_while{|p,n| p==n}.first\n if n == nil\n if p == nil\n next\n else\n puts \"Impossible\"\n exit\n end\n end\n (chars[p].children << chars[n]).uniq!{|v| v.char}\nend\ndef yoba(v,order)\n case v.color\n when :gray\n return false\n when :black\n return true\n end\n v.color = :gray\n v.children.each do |v|\n return false unless yoba(v, order)\n end\n v.color = :black\n order << v.char\n true\nend\norder = []\nchars.values.reverse.each do |v|\n unless yoba(v,order)\n puts \"Impossible\"\n exit\n end\nend\nputs order.reverse.join"}, {"source_code": "#!/usr/bin/env ruby\nrequire 'tsort'\nclass Hash\n\tinclude TSort\n\talias tsort_each_node each_key\n\tdef tsort_each_child(node, &block)\n\t\tfetch(node).each(&block)\n\tend\nend\nA=gets.to_i.times.map{gets.chomp.chars.to_a}\nh={}\nA.combination(2){|x,y|\n\tif [x.size,y.size].min.times{|i|\n\t\tif x[i]!=y[i]\n\t\t\th[x[i]]||=[]\n\t\t\th[y[i]]||=[]\n\t\t\th[y[i]]<y.size\n\t\tputs :Impossible\n\t\texit\n\tend\n}\nr=([*'a'..'z']-h.keys+h.tsort)*'' rescue 'Impossible'\nputs r"}, {"source_code": "#!/usr/bin/env ruby\nrequire 'tsort'\nclass Hash\n\tinclude TSort\n\talias tsort_each_node each_key\n\tdef tsort_each_child(node, &block)\n\t\tfetch(node).each(&block)\n\tend\nend\nA=gets.to_i.times.map{gets.chomp.chars.to_a}\nh={}\nA.combination(2){|x,y|\n\tif [x.size,y.size].min.times{|i|\n\t\tif x[i]!=y[i]\n\t\t\th[x[i]]||=[]\n\t\t\th[y[i]]||=[]\n\t\t\th[y[i]]<y.size\n\t\tputs :Impossible\n\t\texit\n\tend\n}\nr=([*'a'..'z']-h.keys+h.tsort)*'' rescue 'Impossible'\nputs r\n"}, {"source_code": "class Graph\n\tattr_reader :vertexSet, :edgeSet\n\tdef initialize(numberOfVertices) # adds vertices in a new blank graph by their numbers\n\t\t@vertexSet = Array.new()\n\t\t(0..(numberOfVertices - 1)).each do |i|\n\t\t\t@vertexSet.push(Vertex.new(i))\n\t\tend\n\tend\n\n\tdef addEdge(startVertex, endVertex)\n\t\tif !edgeExists?(startVertex, endVertex)\n\t\t\t@vertexSet[startVertex].addNbr(@vertexSet[endVertex])\n\t\t\t# puts \"#{startVertex} #{endVertex}\"\n\t\tend\n\tend\n\n\tdef edgeExists?(startVertex, endVertex)\n\t\t@vertexSet[startVertex].children.include?(@vertexSet[endVertex])\n\tend\n\n\tdef printEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef countEdges\n\t\tt = 0\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tt += 1\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tt\n\tend\n\n\tdef printParentEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size != 0)\n\t\t\t\tvertex.parents.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef returnSources\n\t\ttemp = Array.new()\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size == 0)\n\t\t\t\ttemp.push(vertex)\n\t\t\tend\n\t\tend\n\t\treturn temp\n\tend\n\n\tdef returnVertex(index)\n\t\t@vertexSet[index]\n\tend\n\n\tdef settleThings\n\t\tflag = 0\n\t\ttemp = Vertex.new(-1)\n\t\t@vertexSet.each do |vertex|\n\t\t\tif vertex.alone?\n\t\t\t\t# puts \"Gotcha #{vertex.index}!!!\"\n\t\t\t\tif flag == 0\n\t\t\t\t\t# puts \"Voila\"\n\t\t\t\t\ttemp = vertex\n\t\t\t\t\tflag = 1\n\t\t\t\telse\n\t\t\t\t\t# puts \"Temp.\"\n\t\t\t\t\ttemp.addNbr(vertex)\n\t\t\t\t\ttemp = vertex\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef DFS(index)\n\t\tvertex = returnVertex(index)\n\t\tprint \"#{index}.\"\n\t\tvertex.children.each do |v|\n\t\t\tDFS(v.index)\n\t\tend\n\tend\n\nend\n\n\nclass Vertex\n\tattr_reader :index, :children, :parents, :color\n\tdef initialize(index)\n\t\t@index = index\n\t\t@children = Array.new()\n\t\t@parents = Array.new()\n\t\t@color = 0\n\tend\n\n\tdef addNbr(index)\n\t\t@children.push(index)\n\t\tindex.parents.push(self)\n\tend\n\n\tdef changeColor(color)\n\t\t@color = color\n\tend\n\n\tdef alone?\n\t\treturn ((@parents.size == 0) and (@children.size == 0))\n\tend\nend\n\nclass Heap\n\tattr_accessor :heap_size, :array_rep\n\n\tdef initialize()\n\t\t@array_rep = Array.new()\n\t\t@heap_size = 0\n\tend\n\n\tdef parent(index)\n\t\t(index - 1)/2\n\tend\n\n\tdef parentKey(index)\n\t\t@array_rep[parent(index)]\n\tend\n\n\tdef leftChild(index)\n\t\t2*index + 1\n\tend\n\n\tdef rightChild(index)\n\t\t2*index + 2\n\tend\n\n\tdef leftChildKey(index)\n\t\t@array_rep[leftChild(index)]\n\tend\n\n\tdef rightChildKey(index)\n\t\t@array_rep[rightChild(index)]\n\tend\n\n\tdef leafNode?(index)\n\t\treturn index >= @heap_size/2\n\tend\n\n\tdef getMin\n\t\t@array_rep[0]\n\tend\n\n\tdef deleteMin\n\t\t@array_rep[@heap_size-1], @array_rep[0] = @array_rep[0], @array_rep[@heap_size-1]\n \t@heap_size -= 1\n\t\t@array_rep.delete_at(@heap_size)\n\t\tself.fixOneError(0)\n\tend\n\n\tdef extractMin\n\t\ttemp = getMin.to_i\n\t\tdeleteMin\n\t\treturn temp\n\tend\n\n\tdef fixOneError(index)\n\t\treturn if leafNode?(index) || satisfied?(index)\n\n\t leftChildKey = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t rightChildKey = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\n \tsmallerChild = if leftChildKey < rightChildKey then leftChild(index) else rightChild(index) end\n\n \t@array_rep[index], @array_rep[smallerChild] = @array_rep[smallerChild], @array_rep[index]\n\n \tfixOneError(smallerChild)\n \tend\n\n\tdef satisfied?(index)\n\t\t# puts \"\\nin , #{index} Verify :\"\n\t\t# displayStatus\n\t\tt1 = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t\tt2 = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\t\t@array_rep[index] <= t1 and @array_rep[index] <= t2\n \tend\n\n\tdef insert(value)\n\t\t@array_rep.push(value)\n\t\t@heap_size += 1\n\t\tindex = @heap_size - 1\n\n\t\twhile ((!(top?(index))) and (@array_rep[parent(index)] > @array_rep[index]))\n\t\t\t@array_rep[index], @array_rep[parent(index)] = @array_rep[parent(index)], @array_rep[index]\n\t\t\tindex = parent(index)\n\t\tend\n\tend\n\n\tdef top?(index)\n\t\treturn index == 0\n\tend\n\n\tdef displayStatus\n\t\tputs \"Status :\"\n\t\t@array_rep.each do |d|\n\t\t\tprint \"#{d}.\"\n\t\tend\n\tend\nend\n\ndef analyse(x, y)\n\tx = x.each_char.to_a\n\ty = y.each_char.to_a\n\t# puts \"x: #{x}\"\n\t# puts \"y: #{y}\"\n\tt = if x.size > y.size then y.size else x.size end\n\t(0..(t-1)).each do |i|\n\t\t# puts \"x: #{x[i]} y: #{y[i].ord}\"\n\t\tif x[i].ord != y[i].ord\n\t\t\treturn [(x[i].ord-97),(y[i].ord-97)]\n\t\tend\n\tend\n\tif x.size > y.size\n\t\treturn [-2, -2]\n\tend\n\treturn -1, -1\nend\n\n# code starts here :\n\nmyGraph = Graph.new(26)\nn = gets.chomp.to_i\nstr = gets.chomp\n\n(2..n).each do |j|\n\tstr2 = gets.chomp\n\tn1, n2 = analyse(str, str2)\n\tif (n1 == -2)\n\t\tputs \"Impossible\\n\"\n\t\texit\n\tend\n\tif (n1 != -1)\n\t\tmyGraph.addEdge(n1, n2)\n\tend\n\tstr = str2\nend\n\nmyGraph.settleThings()\n# puts \"#{myGraph.vertexSet.size - 1} #{myGraph.countEdges}\"\n# myGraph.printEdges\n#\n# if ((myGraph.vertexSet.size - 1) < myGraph.countEdges)\n# \tputs \"IMPOSSIBLE\"\n# \texit\n# end\n\nmyHeap = Heap.new()\n\nsources = myGraph.returnSources()\n\nsources.each do |z|\n\tmyHeap.insert(z.index)\n\tz.changeColor(1)\nend\na = Array.new()\nwhile (myHeap.heap_size != 0)\n\tcurrentVertex = myGraph.returnVertex(myHeap.extractMin)\n\tcurrentVertex.changeColor(2)\n\tcurrentVertex.children.each do |v|\n\t\tif (v.parents.all? {|y| y.color == 2 })\n\t\t\tmyHeap.insert(v.index)\n\t\t\tv.changeColor(1)\n\t\tend\n\tend\n\ta.push((currentVertex.index.to_i+97).chr)\nend\nif a.size == 26\n\tprint \"#{a.join(\"\")}\\n\"\nelse\n\tprint \"Impossible\\n\"\nend\n"}, {"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(letter1, letter2)\n if vertices[letter1].nil? then\n vertices[letter1] = List.new(letter2, nil)\n else\n vertices[letter1] = List.new(letter2, vertices[letter1])\n end\n end\n\n # def add_vertex(letter)\n # vertices[letter] = \"\" if vertices[letter].nil?\n # end\n\n def print_edges \n vertices.each do |letter, vertex| \n # next if vertex == \"\"\n while !vertex.nil? do \n puts \"edge #{letter} - #{vertex.element}\"\n vertex = vertex.next_elem \n end \n end \n end \n\n # def print_verteces\n # puts vertices.keys.join(\" \")\n # end\nend \n\ndef dfs(graph, letter, color)\n color[letter] = 'grey'\n next_vert = graph.vertices[letter]\n # puts \"Processing letter: #{letter}\"\n # p next_vert\n if next_vert.nil? \n # puts letter\n color[letter] = 'black'\n return [letter]\n end \n alphabet = []\n while !next_vert.nil? do \n if color[next_vert.element] == 'grey'\n # puts \"#{letter} color is grey and it means we have a cycle\"\n return \"Impossible\"\n elsif color[next_vert.element] == 'white'\n # puts \"#{next_vert.element}'s color is white\"\n new_letter = dfs(graph, next_vert.element, color)\n # puts new_letter\n if new_letter == \"Impossible\"\n return \"Impossible\"\n else\n alphabet = new_letter + alphabet\n end\n end\n next_vert = next_vert.next_elem\n end\n color[letter] = 'black'\n return [letter] + alphabet\nend\n\ndef permutation(sorted_letters)\n sorted_letters | (\"a\"..\"z\").to_a\nend\n\nnames = []\nn = gets.strip.to_i\nn.times{|i| names.push(gets.strip)}\nletters = Graph.new({})\nalphabet = []\n(n - 1).times do |i|\n length = names[i].length\n length.times do |j|\n if j >= names[i+1].length\n alphabet = \"Impossible\"\n break\n end\n if names[i][j] != names[i+1][j]\n letters.add_edge(names[i][j], names[i+1][j])\n break\n end \n end\nend\n\n# letters.print_edges\n\ncolor = {}\n(\"a\"..\"z\").each do |letter|\n color[letter] = 'white'\nend\n# puts \"All the letters in the graph: #{letters.vertices.keys}\"\n# alphabet = []\nif alphabet != \"Impossible\"\n letters.vertices.each_key do |letter| \n if color[letter] == 'white'\n ordered_letters = dfs(letters, letter, color)\n if ordered_letters == \"Impossible\"\n alphabet = \"Impossible\"\n break\n end\n alphabet = ordered_letters + alphabet\n end \n end\nend\nif alphabet == \"Impossible\"\n puts alphabet \nelse\n puts permutation(alphabet).join\nend\n"}, {"source_code": "#!/usr/bin/env ruby\nrequire 'tsort'\nclass Hash\n\tinclude TSort\n\talias tsort_each_node each_key\n\tdef tsort_each_child(node, &block)\n\t\tfetch(node).each(&block)\n\tend\nend\nA=gets.to_i.times.map{gets.chomp.chars.to_a}\nh={}\nA.combination(2){|x,y|\n\tif [x.size,y.size].min.times{|i|\n\t\tif x[i]!=y[i]\n\t\t\th[x[i]]||=[]\n\t\t\th[y[i]]||=[]\n\t\t\th[y[i]]<y.size\n\t\tputs :Impossible\n\t\texit\n\tend\n}\nr=([*'a'..'z']-h.keys+h.tsort)*'' rescue 'Impossible'\nputs r\n"}, {"source_code": "#!/usr/bin/env ruby\nrequire 'tsort'\nclass Hash\n\tinclude TSort\n\talias tsort_each_node each_key\n\tdef tsort_each_child(node, &block)\n\t\tfetch(node).each(&block)\n\tend\nend\nA=gets.to_i.times.map{gets.chomp.chars.to_a}\nh={}\nA.combination(2){|x,y|\n\tif [x.size,y.size].min.times{|i|\n\t\tif x[i]!=y[i]\n\t\t\th[x[i]]||=[]\n\t\t\th[y[i]]||=[]\n\t\t\th[y[i]]<y.size\n\t\tputs :Impossible\n\t\texit\n\tend\n}\nr=([*'a'..'z']-h.keys+h.tsort)*'' rescue 'Impossible'\nputs r\n"}, {"source_code": "#!/usr/bin/env ruby\nrequire 'tsort'\nclass Hash\n\tinclude TSort\n\talias tsort_each_node each_key\n\tdef tsort_each_child(node, &block)\n\t\tfetch(node).each(&block)\n\tend\nend\nA=gets.to_i.times.map{gets.chomp.chars.to_a}\nh={}\nA.combination(2){|x,y|\n\tif [x.size,y.size].min.times{|i|\n\t\tif x[i]!=y[i]\n\t\t\th[x[i]]||=[]\n\t\t\th[y[i]]||=[]\n\t\t\th[y[i]]<y.size\n\t\tputs :Impossible\n\t\texit\n\tend\n}\nr=([*'a'..'z']-h.keys+h.tsort)*'' rescue 'Impossible'\nputs r\n"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\nrequire 'tsort'\nclass Hash\n\tinclude TSort\n\talias tsort_each_node each_key\n\tdef tsort_each_child(node, &block)\n\t\tfetch(node).each(&block)\n\tend\nend\nA=gets.to_i.times.map{gets.chomp.chars.to_a}\nh={}\nA.combination(2){|x,y|\n\t[x.size,y.size].min.times{|i|\n\t\tif x[i]!=y[i]\n\t\t\th[x[i]]||=[]\n\t\t\th[y[i]]||=[]\n\t\t\th[y[i]]<y.size && [x.size,y.size].min.times{|i|\n\t\tif x[i]!=y[i]\n\t\t\th[x[i]]||=[]\n\t\t\th[y[i]]||=[]\n\t\t\th[y[i]]<= @heap_size/2\n\tend\n\n\tdef getMin\n\t\t@array_rep[0]\n\tend\n\n\tdef deleteMin\n\t\t@array_rep[@heap_size-1], @array_rep[0] = @array_rep[0], @array_rep[@heap_size-1]\n \t@heap_size -= 1\n\t\t@array_rep.delete_at(@heap_size)\n\t\tself.fixOneError(0)\n\tend\n\n\tdef extractMin\n\t\ttemp = getMin.to_i\n\t\tdeleteMin\n\t\treturn temp\n\tend\n\n\tdef fixOneError(index)\n\t\treturn if leafNode?(index) || satisfied?(index)\n\n\t leftChildKey = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t rightChildKey = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\n \tsmallerChild = if leftChildKey < rightChildKey then leftChild(index) else rightChild(index) end\n\n \t@array_rep[index], @array_rep[smallerChild] = @array_rep[smallerChild], @array_rep[index]\n\n \tfixOneError(smallerChild)\n \tend\n\n\tdef satisfied?(index)\n\t\t# puts \"\\nin , #{index} Verify :\"\n\t\t# displayStatus\n\t\tt1 = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t\tt2 = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\t\t@array_rep[index] <= t1 and @array_rep[index] <= t2\n \tend\n\n\tdef insert(value)\n\t\t@array_rep.push(value)\n\t\t@heap_size += 1\n\t\tindex = @heap_size - 1\n\n\t\twhile ((!(top?(index))) and (@array_rep[parent(index)] > @array_rep[index]))\n\t\t\t@array_rep[index], @array_rep[parent(index)] = @array_rep[parent(index)], @array_rep[index]\n\t\t\tindex = parent(index)\n\t\tend\n\tend\n\n\tdef top?(index)\n\t\treturn index == 0\n\tend\n\n\tdef displayStatus\n\t\tputs \"Status :\"\n\t\t@array_rep.each do |d|\n\t\t\tprint \"#{d}.\"\n\t\tend\n\tend\nend\n\ndef analyse(x, y)\n\tx = x.each_char.to_a\n\ty = y.each_char.to_a\n\t# puts \"x: #{x}\"\n\t# puts \"y: #{y}\"\n\tt = if x.size > y.size then y.size else x.size end\n\t(0..(t-1)).each do |i|\n\t\t# puts \"x: #{x[i]} y: #{y[i].ord}\"\n\t\tif x[i].ord != y[i].ord\n\t\t\treturn [(x[i].ord-97),(y[i].ord-97)]\n\t\tend\n\tend\n\tif x.size > y.size\n\t\treturn [-2, -2]\n\tend\n\treturn -1, -1\nend\n\n# code starts here :\n\nmyGraph = Graph.new(26)\nn = gets.chomp.to_i\nstr = gets.chomp\n(2..n).each do |j|\n\tstr2 = gets.chomp\n\tn1, n2 = analyse(str, str2)\n\tif (n1 == -2)\n\t\tputs \"Impossible2\\n\"\n\t\texit\n\tend\n\tif (n1 != -1)\n\t\tmyGraph.addEdge(n1, n2)\n\tend\n\tstr = str2\nend\n\nmyGraph.settleThings()\n# puts \"#{myGraph.vertexSet.size - 1} #{myGraph.countEdges}\"\n# myGraph.printEdges\n#\n# if ((myGraph.vertexSet.size - 1) < myGraph.countEdges)\n# \tputs \"IMPOSSIBLE\"\n# \texit\n# end\n\nmyHeap = Heap.new()\n\nsources = myGraph.returnSources()\n\nsources.each do |z|\n\tmyHeap.insert(z.index)\n\tz.changeColor(1)\nend\na = Array.new()\nwhile (myHeap.heap_size != 0)\n\tcurrentVertex = myGraph.returnVertex(myHeap.extractMin)\n\tcurrentVertex.changeColor(2)\n\tcurrentVertex.children.each do |v|\n\t\tif (v.parents.all? {|y| y.color == 2 })\n\t\t\tmyHeap.insert(v.index)\n\t\t\tv.changeColor(1)\n\t\tend\n\tend\n\ta.push((currentVertex.index.to_i+97).chr)\nend\nif a.size == 26\n\tprint \"#{a.join(\"\")}\\n\"\nelse\n\tprint \"Impossible\\n\"\nend\n"}, {"source_code": "class Graph\n\tattr_reader :vertexSet, :edgeSet\n\tdef initialize(numberOfVertices) # adds vertices in a new blank graph by their numbers\n\t\t@vertexSet = Array.new()\n\t\t(0..(numberOfVertices - 1)).each do |i|\n\t\t\t@vertexSet.push(Vertex.new(i))\n\t\tend\n\tend\n\n\tdef addEdge(startVertex, endVertex)\n\t\t@vertexSet[startVertex].addNbr(@vertexSet[endVertex])\n\tend\n\n\tdef printEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef countEdges\n\t\tt = 0\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tt += 1\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tt\n\tend\n\n\tdef printParentEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size != 0)\n\t\t\t\tvertex.parents.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef returnSources\n\t\ttemp = Array.new()\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size == 0)\n\t\t\t\ttemp.push(vertex)\n\t\t\tend\n\t\tend\n\t\treturn temp\n\tend\n\n\tdef returnVertex(index)\n\t\t@vertexSet[index]\n\tend\n\n\tdef settleThings\n\t\tflag = 0\n\t\ttemp = Vertex.new(-1)\n\t\t@vertexSet.each do |vertex|\n\t\t\tif vertex.alone?\n\t\t\t\t# puts \"Gotcha #{vertex.index}!!!\"\n\t\t\t\tif flag == 0\n\t\t\t\t\t# puts \"Voila\"\n\t\t\t\t\ttemp = vertex\n\t\t\t\t\tflag = 1\n\t\t\t\telse\n\t\t\t\t\t# puts \"Temp.\"\n\t\t\t\t\ttemp.addNbr(vertex)\n\t\t\t\t\ttemp = vertex\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef DFS(index)\n\t\tvertex = returnVertex(index)\n\t\tprint \"#{index}.\"\n\t\tvertex.children.each do |v|\n\t\t\tDFS(v.index)\n\t\tend\n\tend\n\nend\n\n\nclass Vertex\n\tattr_reader :index, :children, :parents, :color\n\tdef initialize(index)\n\t\t@index = index\n\t\t@children = Array.new()\n\t\t@parents = Array.new()\n\t\t@color = 0\n\tend\n\n\tdef addNbr(index)\n\t\t@children.push(index)\n\t\tindex.parents.push(self)\n\tend\n\n\tdef changeColor(color)\n\t\t@color = color\n\tend\n\n\tdef alone?\n\t\treturn ((@parents.size == 0) and (@children.size == 0))\n\tend\nend\n\nclass Heap\n\tattr_accessor :heap_size, :array_rep\n\n\tdef initialize()\n\t\t@array_rep = Array.new()\n\t\t@heap_size = 0\n\tend\n\n\tdef parent(index)\n\t\t(index - 1)/2\n\tend\n\n\tdef parentKey(index)\n\t\t@array_rep[parent(index)]\n\tend\n\n\tdef leftChild(index)\n\t\t2*index + 1\n\tend\n\n\tdef rightChild(index)\n\t\t2*index + 2\n\tend\n\n\tdef leftChildKey(index)\n\t\t@array_rep[leftChild(index)]\n\tend\n\n\tdef rightChildKey(index)\n\t\t@array_rep[rightChild(index)]\n\tend\n\n\tdef leafNode?(index)\n\t\treturn index >= @heap_size/2\n\tend\n\n\tdef getMin\n\t\t@array_rep[0]\n\tend\n\n\tdef deleteMin\n\t\t@array_rep[@heap_size-1], @array_rep[0] = @array_rep[0], @array_rep[@heap_size-1]\n \t@heap_size -= 1\n\t\t@array_rep.delete_at(@heap_size)\n\t\tself.fixOneError(0)\n\tend\n\n\tdef extractMin\n\t\ttemp = getMin.to_i\n\t\tdeleteMin\n\t\treturn temp\n\tend\n\n\tdef fixOneError(index)\n\t\treturn if leafNode?(index) || satisfied?(index)\n\n\t leftChildKey = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t rightChildKey = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\n \tsmallerChild = if leftChildKey < rightChildKey then leftChild(index) else rightChild(index) end\n\n \t@array_rep[index], @array_rep[smallerChild] = @array_rep[smallerChild], @array_rep[index]\n\n \tfixOneError(smallerChild)\n \tend\n\n\tdef satisfied?(index)\n\t\t# puts \"\\nin , #{index} Verify :\"\n\t\t# displayStatus\n\t\tt1 = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t\tt2 = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\t\t@array_rep[index] <= t1 and @array_rep[index] <= t2\n \tend\n\n\tdef insert(value)\n\t\t@array_rep.push(value)\n\t\t@heap_size += 1\n\t\tindex = @heap_size - 1\n\n\t\twhile ((!(top?(index))) and (@array_rep[parent(index)] > @array_rep[index]))\n\t\t\t@array_rep[index], @array_rep[parent(index)] = @array_rep[parent(index)], @array_rep[index]\n\t\t\tindex = parent(index)\n\t\tend\n\tend\n\n\tdef top?(index)\n\t\treturn index == 0\n\tend\n\n\tdef displayStatus\n\t\tputs \"Status :\"\n\t\t@array_rep.each do |d|\n\t\t\tprint \"#{d}.\"\n\t\tend\n\tend\nend\n\ndef analyse(x, y)\n\tx = x.each_char.to_a\n\ty = y.each_char.to_a\n\t# puts \"x: #{x}\"\n\t# puts \"y: #{y}\"\n\tt = if x.size > y.size then y.size else x.size end\n\t(0..(t-1)).each do |i|\n\t\t# puts \"x: #{x[i]} y: #{y[i].ord}\"\n\t\tif x[i].ord != y[i].ord\n\t\t\treturn [(x[i].ord-97),(y[i].ord-97)]\n\t\tend\n\tend\n\tif x.size > y.size\n\t\treturn [-2, -2]\n\tend\n\treturn -1, -1\nend\n\n# code starts here :\n\nmyGraph = Graph.new(26)\nn = gets.chomp.to_i\nstr = gets.chomp\n(2..n).each do |j|\n\tstr2 = gets.chomp\n\tn1, n2 = analyse(str, str2)\n\tif (n1 == -2)\n\t\tputs \"IMPOSSIBLE\"\n\t\texit\n\tend\n\tif (n1 != -1)\n\t\tmyGraph.addEdge(n1, n2)\n\tend\n\tstr = str2\nend\n\nmyGraph.settleThings()\n# puts \"#{myGraph.vertexSet.size - 1} #{myGraph.countEdges}\"\n# myGraph.printEdges\n#\n# if ((myGraph.vertexSet.size - 1) < myGraph.countEdges)\n# \tputs \"IMPOSSIBLE\"\n# \texit\n# end\n\nmyHeap = Heap.new()\n\nsources = myGraph.returnSources()\n\nsources.each do |z|\n\tmyHeap.insert(z.index)\n\tz.changeColor(1)\nend\na = Array.new()\nwhile (myHeap.heap_size != 0)\n\tcurrentVertex = myGraph.returnVertex(myHeap.extractMin)\n\tcurrentVertex.changeColor(2)\n\tcurrentVertex.children.each do |v|\n\t\tif (v.parents.all? {|y| y.color == 2 })\n\t\t\tmyHeap.insert(v.index)\n\t\t\tv.changeColor(1)\n\t\tend\n\tend\n\ta.push((currentVertex.index.to_i+97).chr)\nend\nif a.size == 26\n\tprint \"#{a.join(\"\")}\\n\"\nelse\n\tprint \"IMPOSSIBLE\\n\"\nend\n"}, {"source_code": "class Graph\n\tattr_reader :vertexSet, :edgeSet\n\tdef initialize(numberOfVertices) # adds vertices in a new blank graph by their numbers\n\t\t@vertexSet = Array.new()\n\t\t(0..(numberOfVertices - 1)).each do |i|\n\t\t\t@vertexSet.push(Vertex.new(i))\n\t\tend\n\tend\n\n\tdef addEdge(startVertex, endVertex)\n\t\tif !edgeExists?(startVertex, endVertex)\n\t\t\t@vertexSet[startVertex].addNbr(@vertexSet[endVertex])\n\t\tend\n\tend\n\n\tdef edgeExists?(startVertex, endVertex)\n\t\t@vertexSet[startVertex].children.include?(endVertex)\n\tend\n\n\tdef printEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef countEdges\n\t\tt = 0\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tt += 1\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tt\n\tend\n\n\tdef printParentEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size != 0)\n\t\t\t\tvertex.parents.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef returnSources\n\t\ttemp = Array.new()\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size == 0)\n\t\t\t\ttemp.push(vertex)\n\t\t\tend\n\t\tend\n\t\treturn temp\n\tend\n\n\tdef returnVertex(index)\n\t\t@vertexSet[index]\n\tend\n\n\tdef settleThings\n\t\tflag = 0\n\t\ttemp = Vertex.new(-1)\n\t\t@vertexSet.each do |vertex|\n\t\t\tif vertex.alone?\n\t\t\t\t# puts \"Gotcha #{vertex.index}!!!\"\n\t\t\t\tif flag == 0\n\t\t\t\t\t# puts \"Voila\"\n\t\t\t\t\ttemp = vertex\n\t\t\t\t\tflag = 1\n\t\t\t\telse\n\t\t\t\t\t# puts \"Temp.\"\n\t\t\t\t\ttemp.addNbr(vertex)\n\t\t\t\t\ttemp = vertex\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef DFS(index)\n\t\tvertex = returnVertex(index)\n\t\tprint \"#{index}.\"\n\t\tvertex.children.each do |v|\n\t\t\tDFS(v.index)\n\t\tend\n\tend\n\nend\n\n\nclass Vertex\n\tattr_reader :index, :children, :parents, :color\n\tdef initialize(index)\n\t\t@index = index\n\t\t@children = Array.new()\n\t\t@parents = Array.new()\n\t\t@color = 0\n\tend\n\n\tdef addNbr(index)\n\t\t@children.push(index)\n\t\tindex.parents.push(self)\n\tend\n\n\tdef changeColor(color)\n\t\t@color = color\n\tend\n\n\tdef alone?\n\t\treturn ((@parents.size == 0) and (@children.size == 0))\n\tend\nend\n\nclass Heap\n\tattr_accessor :heap_size, :array_rep\n\n\tdef initialize()\n\t\t@array_rep = Array.new()\n\t\t@heap_size = 0\n\tend\n\n\tdef parent(index)\n\t\t(index - 1)/2\n\tend\n\n\tdef parentKey(index)\n\t\t@array_rep[parent(index)]\n\tend\n\n\tdef leftChild(index)\n\t\t2*index + 1\n\tend\n\n\tdef rightChild(index)\n\t\t2*index + 2\n\tend\n\n\tdef leftChildKey(index)\n\t\t@array_rep[leftChild(index)]\n\tend\n\n\tdef rightChildKey(index)\n\t\t@array_rep[rightChild(index)]\n\tend\n\n\tdef leafNode?(index)\n\t\treturn index >= @heap_size/2\n\tend\n\n\tdef getMin\n\t\t@array_rep[0]\n\tend\n\n\tdef deleteMin\n\t\t@array_rep[@heap_size-1], @array_rep[0] = @array_rep[0], @array_rep[@heap_size-1]\n \t@heap_size -= 1\n\t\t@array_rep.delete_at(@heap_size)\n\t\tself.fixOneError(0)\n\tend\n\n\tdef extractMin\n\t\ttemp = getMin.to_i\n\t\tdeleteMin\n\t\treturn temp\n\tend\n\n\tdef fixOneError(index)\n\t\treturn if leafNode?(index) || satisfied?(index)\n\n\t leftChildKey = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t rightChildKey = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\n \tsmallerChild = if leftChildKey < rightChildKey then leftChild(index) else rightChild(index) end\n\n \t@array_rep[index], @array_rep[smallerChild] = @array_rep[smallerChild], @array_rep[index]\n\n \tfixOneError(smallerChild)\n \tend\n\n\tdef satisfied?(index)\n\t\t# puts \"\\nin , #{index} Verify :\"\n\t\t# displayStatus\n\t\tt1 = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t\tt2 = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\t\t@array_rep[index] <= t1 and @array_rep[index] <= t2\n \tend\n\n\tdef insert(value)\n\t\t@array_rep.push(value)\n\t\t@heap_size += 1\n\t\tindex = @heap_size - 1\n\n\t\twhile ((!(top?(index))) and (@array_rep[parent(index)] > @array_rep[index]))\n\t\t\t@array_rep[index], @array_rep[parent(index)] = @array_rep[parent(index)], @array_rep[index]\n\t\t\tindex = parent(index)\n\t\tend\n\tend\n\n\tdef top?(index)\n\t\treturn index == 0\n\tend\n\n\tdef displayStatus\n\t\tputs \"Status :\"\n\t\t@array_rep.each do |d|\n\t\t\tprint \"#{d}.\"\n\t\tend\n\tend\nend\n\ndef analyse(x, y)\n\tx = x.each_char.to_a\n\ty = y.each_char.to_a\n\t# puts \"x: #{x}\"\n\t# puts \"y: #{y}\"\n\tt = if x.size > y.size then y.size else x.size end\n\t(0..(t-1)).each do |i|\n\t\t# puts \"x: #{x[i]} y: #{y[i].ord}\"\n\t\tif x[i].ord != y[i].ord\n\t\t\treturn [(x[i].ord-97),(y[i].ord-97)]\n\t\tend\n\tend\n\tif x.size > y.size\n\t\treturn [-2, -2]\n\tend\n\treturn -1, -1\nend\n\n# code starts here :\n\nmyGraph = Graph.new(26)\nn = gets.chomp.to_i\nstr = gets.chomp\n# myFlag = 0\n# if n == 100\n# \tif str[0] == 'a'\n# \t\tmyFlag = 1\n# \tend\n# end\n(2..n).each do |j|\n\tstr2 = gets.chomp\n\tn1, n2 = analyse(str, str2)\n\tif (n1 == -2)\n\t\tputs \"Impossible\\n\"\n\t\texit\n\tend\n\tif (n1 != -1)\n\t\tmyGraph.addEdge(n1, n2)\n\tend\n\tstr = str2\nend\n\nmyGraph.settleThings()\n# puts \"#{myGraph.vertexSet.size - 1} #{myGraph.countEdges}\"\n# myGraph.printEdges\n#\n# if ((myGraph.vertexSet.size - 1) < myGraph.countEdges)\n# \tputs \"IMPOSSIBLE\"\n# \texit\n# end\n\nmyHeap = Heap.new()\n\nsources = myGraph.returnSources()\n\nsources.each do |z|\n\tmyHeap.insert(z.index)\n\tz.changeColor(1)\nend\na = Array.new()\nb = Array.new()\nwhile (myHeap.heap_size != 0)\n\tcurrentVertex = myGraph.returnVertex(myHeap.extractMin)\n\tcurrentVertex.changeColor(2)\n\tcurrentVertex.children.each do |v|\n\t\tif (v.parents.all? {|y| y.color == 2 })\n\t\t\tmyHeap.insert(v.index)\n\t\t\tv.changeColor(1)\n\t\tend\n\tend\n\ta.push((currentVertex.index.to_i+97).chr)\n\tb.push\nend\nif a.size == 26\n\tprint \"#{a.join(\"\")}\\n\"\nelse\n\tprint \"Impossible\\n\"\n\t# if myFlag == 1\n\t# \tprint \"#{a.join(\"\")}\\n\"\n\t# end\nend\n"}, {"source_code": "class Graph\n\tattr_reader :vertexSet, :edgeSet\n\tdef initialize(numberOfVertices) # adds vertices in a new blank graph by their numbers\n\t\t@vertexSet = Array.new()\n\t\t(0..(numberOfVertices - 1)).each do |i|\n\t\t\t@vertexSet.push(Vertex.new(i))\n\t\tend\n\tend\n\n\tdef addEdge(startVertex, endVertex)\n\t\t@vertexSet[startVertex].addNbr(@vertexSet[endVertex])\n\tend\n\n\tdef printEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef countEdges\n\t\tt = 0\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tt += 1\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tt\n\tend\n\n\tdef printParentEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size != 0)\n\t\t\t\tvertex.parents.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef returnSources\n\t\ttemp = Array.new()\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size == 0)\n\t\t\t\ttemp.push(vertex)\n\t\t\tend\n\t\tend\n\t\treturn temp\n\tend\n\n\tdef returnVertex(index)\n\t\t@vertexSet[index]\n\tend\n\n\tdef settleThings\n\t\tflag = 0\n\t\ttemp = Vertex.new(-1)\n\t\t@vertexSet.each do |vertex|\n\t\t\tif vertex.alone?\n\t\t\t\t# puts \"Gotcha #{vertex.index}!!!\"\n\t\t\t\tif flag == 0\n\t\t\t\t\t# puts \"Voila\"\n\t\t\t\t\ttemp = vertex\n\t\t\t\t\tflag = 1\n\t\t\t\telse\n\t\t\t\t\t# puts \"Temp.\"\n\t\t\t\t\ttemp.addNbr(vertex)\n\t\t\t\t\ttemp = vertex\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef DFS(index)\n\t\tvertex = returnVertex(index)\n\t\tprint \"#{index}.\"\n\t\tvertex.children.each do |v|\n\t\t\tDFS(v.index)\n\t\tend\n\tend\n\nend\n\n\nclass Vertex\n\tattr_reader :index, :children, :parents, :color\n\tdef initialize(index)\n\t\t@index = index\n\t\t@children = Array.new()\n\t\t@parents = Array.new()\n\t\t@color = 0\n\tend\n\n\tdef addNbr(index)\n\t\t@children.push(index)\n\t\tindex.parents.push(self)\n\tend\n\n\tdef changeColor(color)\n\t\t@color = color\n\tend\n\n\tdef alone?\n\t\treturn ((@parents.size == 0) and (@children.size == 0))\n\tend\nend\n\nclass Heap\n\tattr_accessor :heap_size, :array_rep\n\n\tdef initialize()\n\t\t@array_rep = Array.new()\n\t\t@heap_size = 0\n\tend\n\n\tdef parent(index)\n\t\t(index - 1)/2\n\tend\n\n\tdef parentKey(index)\n\t\t@array_rep[parent(index)]\n\tend\n\n\tdef leftChild(index)\n\t\t2*index + 1\n\tend\n\n\tdef rightChild(index)\n\t\t2*index + 2\n\tend\n\n\tdef leftChildKey(index)\n\t\t@array_rep[leftChild(index)]\n\tend\n\n\tdef rightChildKey(index)\n\t\t@array_rep[rightChild(index)]\n\tend\n\n\tdef leafNode?(index)\n\t\treturn index >= @heap_size/2\n\tend\n\n\tdef getMin\n\t\t@array_rep[0]\n\tend\n\n\tdef deleteMin\n\t\t@array_rep[@heap_size-1], @array_rep[0] = @array_rep[0], @array_rep[@heap_size-1]\n \t@heap_size -= 1\n\t\t@array_rep.delete_at(@heap_size)\n\t\tself.fixOneError(0)\n\tend\n\n\tdef extractMin\n\t\ttemp = getMin.to_i\n\t\tdeleteMin\n\t\treturn temp\n\tend\n\n\tdef fixOneError(index)\n\t\treturn if leafNode?(index) || satisfied?(index)\n\n\t leftChildKey = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t rightChildKey = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\n \tsmallerChild = if leftChildKey < rightChildKey then leftChild(index) else rightChild(index) end\n\n \t@array_rep[index], @array_rep[smallerChild] = @array_rep[smallerChild], @array_rep[index]\n\n \tfixOneError(smallerChild)\n \tend\n\n\tdef satisfied?(index)\n\t\t# puts \"\\nin , #{index} Verify :\"\n\t\t# displayStatus\n\t\tt1 = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t\tt2 = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\t\t@array_rep[index] <= t1 and @array_rep[index] <= t2\n \tend\n\n\tdef insert(value)\n\t\t@array_rep.push(value)\n\t\t@heap_size += 1\n\t\tindex = @heap_size - 1\n\n\t\twhile ((!(top?(index))) and (@array_rep[parent(index)] > @array_rep[index]))\n\t\t\t@array_rep[index], @array_rep[parent(index)] = @array_rep[parent(index)], @array_rep[index]\n\t\t\tindex = parent(index)\n\t\tend\n\tend\n\n\tdef top?(index)\n\t\treturn index == 0\n\tend\n\n\tdef displayStatus\n\t\tputs \"Status :\"\n\t\t@array_rep.each do |d|\n\t\t\tprint \"#{d}.\"\n\t\tend\n\tend\nend\n\ndef analyse(x, y)\n\tx = x.each_char.to_a\n\ty = y.each_char.to_a\n\t# puts \"x: #{x}\"\n\t# puts \"y: #{y}\"\n\tt = if x.size > y.size then y.size else x.size end\n\t(0..(t-1)).each do |i|\n\t\t# puts \"x: #{x[i]} y: #{y[i].ord}\"\n\t\tif x[i].ord != y[i].ord\n\t\t\treturn [(x[i].ord-97),(y[i].ord-97)]\n\t\tend\n\tend\n\tif x.size > y.size\n\t\treturn [-2, -2]\n\tend\n\treturn -1, -1\nend\n\n# code starts here :\n\nmyGraph = Graph.new(26)\nn = gets.chomp.to_i\nstr = gets.chomp\n(2..n).each do |j|\n\tstr2 = gets.chomp\n\tn1, n2 = analyse(str, str2)\n\tif (n1 == -2)\n\t\tputs \"Impossible\"\n\t\texit\n\tend\n\tif (n1 != -1)\n\t\tmyGraph.addEdge(n1, n2)\n\tend\n\tstr = str2\nend\n\nmyGraph.settleThings()\n# puts \"#{myGraph.vertexSet.size - 1} #{myGraph.countEdges}\"\n# myGraph.printEdges\n#\n# if ((myGraph.vertexSet.size - 1) < myGraph.countEdges)\n# \tputs \"IMPOSSIBLE\"\n# \texit\n# end\n\nmyHeap = Heap.new()\n\nsources = myGraph.returnSources()\n\nsources.each do |z|\n\tmyHeap.insert(z.index)\n\tz.changeColor(1)\nend\na = Array.new()\nwhile (myHeap.heap_size != 0)\n\tcurrentVertex = myGraph.returnVertex(myHeap.extractMin)\n\tcurrentVertex.changeColor(2)\n\tcurrentVertex.children.each do |v|\n\t\tif (v.parents.all? {|y| y.color == 2 })\n\t\t\tmyHeap.insert(v.index)\n\t\t\tv.changeColor(1)\n\t\tend\n\tend\n\ta.push((currentVertex.index.to_i+97).chr)\nend\nif a.size == 26\n\tprint \"#{a.join(\"\")}\\n\"\nelse\n\tprint \"Impossible\\n\"\nend\n"}, {"source_code": "class Graph\n\tattr_reader :vertexSet, :edgeSet\n\tdef initialize(numberOfVertices) # adds vertices in a new blank graph by their numbers\n\t\t@vertexSet = Array.new()\n\t\t(0..(numberOfVertices - 1)).each do |i|\n\t\t\t@vertexSet.push(Vertex.new(i))\n\t\tend\n\tend\n\n\tdef addEdge(startVertex, endVertex)\n\t\t@vertexSet[startVertex].addNbr(@vertexSet[endVertex])\n\tend\n\n\tdef printEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef countEdges\n\t\tt = 0\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tt += 1\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tt\n\tend\n\n\tdef printParentEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size != 0)\n\t\t\t\tvertex.parents.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef returnSources\n\t\ttemp = Array.new()\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size == 0)\n\t\t\t\ttemp.push(vertex)\n\t\t\tend\n\t\tend\n\t\treturn temp\n\tend\n\n\tdef returnVertex(index)\n\t\t@vertexSet[index]\n\tend\n\n\tdef settleThings\n\t\tflag = 0\n\t\ttemp = Vertex.new(-1)\n\t\t@vertexSet.each do |vertex|\n\t\t\tif vertex.alone?\n\t\t\t\t# puts \"Gotcha #{vertex.index}!!!\"\n\t\t\t\tif flag == 0\n\t\t\t\t\t# puts \"Voila\"\n\t\t\t\t\ttemp = vertex\n\t\t\t\t\tflag = 1\n\t\t\t\telse\n\t\t\t\t\t# puts \"Temp.\"\n\t\t\t\t\ttemp.addNbr(vertex)\n\t\t\t\t\ttemp = vertex\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef DFS(index)\n\t\tvertex = returnVertex(index)\n\t\tprint \"#{index}.\"\n\t\tvertex.children.each do |v|\n\t\t\tDFS(v.index)\n\t\tend\n\tend\n\nend\n\n\nclass Vertex\n\tattr_reader :index, :children, :parents, :color\n\tdef initialize(index)\n\t\t@index = index\n\t\t@children = Array.new()\n\t\t@parents = Array.new()\n\t\t@color = 0\n\tend\n\n\tdef addNbr(index)\n\t\t@children.push(index)\n\t\tindex.parents.push(self)\n\tend\n\n\tdef changeColor(color)\n\t\t@color = color\n\tend\n\n\tdef alone?\n\t\treturn ((@parents.size == 0) and (@children.size == 0))\n\tend\nend\n\nclass Heap\n\tattr_accessor :heap_size, :array_rep\n\n\tdef initialize()\n\t\t@array_rep = Array.new()\n\t\t@heap_size = 0\n\tend\n\n\tdef parent(index)\n\t\t(index - 1)/2\n\tend\n\n\tdef parentKey(index)\n\t\t@array_rep[parent(index)]\n\tend\n\n\tdef leftChild(index)\n\t\t2*index + 1\n\tend\n\n\tdef rightChild(index)\n\t\t2*index + 2\n\tend\n\n\tdef leftChildKey(index)\n\t\t@array_rep[leftChild(index)]\n\tend\n\n\tdef rightChildKey(index)\n\t\t@array_rep[rightChild(index)]\n\tend\n\n\tdef leafNode?(index)\n\t\treturn index >= @heap_size/2\n\tend\n\n\tdef getMin\n\t\t@array_rep[0]\n\tend\n\n\tdef deleteMin\n\t\t@array_rep[@heap_size-1], @array_rep[0] = @array_rep[0], @array_rep[@heap_size-1]\n \t@heap_size -= 1\n\t\t@array_rep.delete_at(@heap_size)\n\t\tself.fixOneError(0)\n\tend\n\n\tdef extractMin\n\t\ttemp = getMin.to_i\n\t\tdeleteMin\n\t\treturn temp\n\tend\n\n\tdef fixOneError(index)\n\t\treturn if leafNode?(index) || satisfied?(index)\n\n\t leftChildKey = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t rightChildKey = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\n \tsmallerChild = if leftChildKey < rightChildKey then leftChild(index) else rightChild(index) end\n\n \t@array_rep[index], @array_rep[smallerChild] = @array_rep[smallerChild], @array_rep[index]\n\n \tfixOneError(smallerChild)\n \tend\n\n\tdef satisfied?(index)\n\t\t# puts \"\\nin , #{index} Verify :\"\n\t\t# displayStatus\n\t\tt1 = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t\tt2 = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\t\t@array_rep[index] <= t1 and @array_rep[index] <= t2\n \tend\n\n\tdef insert(value)\n\t\t@array_rep.push(value)\n\t\t@heap_size += 1\n\t\tindex = @heap_size - 1\n\n\t\twhile ((!(top?(index))) and (@array_rep[parent(index)] > @array_rep[index]))\n\t\t\t@array_rep[index], @array_rep[parent(index)] = @array_rep[parent(index)], @array_rep[index]\n\t\t\tindex = parent(index)\n\t\tend\n\tend\n\n\tdef top?(index)\n\t\treturn index == 0\n\tend\n\n\tdef displayStatus\n\t\tputs \"Status :\"\n\t\t@array_rep.each do |d|\n\t\t\tprint \"#{d}.\"\n\t\tend\n\tend\nend\n\ndef analyse(x, y)\n\tx = x.each_char.to_a\n\ty = y.each_char.to_a\n\t# puts \"x: #{x}\"\n\t# puts \"y: #{y}\"\n\tt = if x.size > y.size then y.size else x.size end\n\t(0..(t-1)).each do |i|\n\t\t# puts \"x: #{x[i]} y: #{y[i].ord}\"\n\t\tif x[i].ord != y[i].ord\n\t\t\treturn [(x[i].ord-97),(y[i].ord-97)]\n\t\tend\n\tend\n\tif x.size > y.size\n\t\treturn [-2, -2]\n\tend\n\treturn -1, -1\nend\n\n# code starts here :\n\nmyGraph = Graph.new(26)\nn = gets.chomp.to_i\nstr = gets.chomp\n(2..n).each do |j|\n\tstr2 = gets.chomp\n\tn1, n2 = analyse(str, str2)\n\tif (n1 == -2)\n\t\tputs \"Impossible\\n\"\n\t\texit\n\tend\n\tif (n1 != -1)\n\t\tmyGraph.addEdge(n1, n2)\n\tend\n\tstr = str2\nend\n\nmyGraph.settleThings()\n# puts \"#{myGraph.vertexSet.size - 1} #{myGraph.countEdges}\"\n# myGraph.printEdges\n#\n# if ((myGraph.vertexSet.size - 1) < myGraph.countEdges)\n# \tputs \"IMPOSSIBLE\"\n# \texit\n# end\n\nmyHeap = Heap.new()\n\nsources = myGraph.returnSources()\n\nsources.each do |z|\n\tmyHeap.insert(z.index)\n\tz.changeColor(1)\nend\na = Array.new()\nwhile (myHeap.heap_size != 0)\n\tcurrentVertex = myGraph.returnVertex(myHeap.extractMin)\n\tcurrentVertex.changeColor(2)\n\tcurrentVertex.children.each do |v|\n\t\tif (v.parents.all? {|y| y.color == 2 })\n\t\t\tmyHeap.insert(v.index)\n\t\t\tv.changeColor(1)\n\t\tend\n\tend\n\ta.push((currentVertex.index.to_i+97).chr)\nend\nif a.size == 26\n\tprint \"#{a.join(\"\")}\\n\"\nelse\n\tprint \"Impossible\\n\"\nend\n"}, {"source_code": "class Graph\n\tattr_reader :vertexSet, :edgeSet\n\tdef initialize(numberOfVertices) # adds vertices in a new blank graph by their numbers\n\t\t@vertexSet = Array.new()\n\t\t(0..(numberOfVertices - 1)).each do |i|\n\t\t\t@vertexSet.push(Vertex.new(i))\n\t\tend\n\tend\n\n\tdef addEdge(startVertex, endVertex)\n\t\t@vertexSet[startVertex].addNbr(@vertexSet[endVertex])\n\tend\n\n\tdef printEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef countEdges\n\t\tt = 0\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.children.size != 0)\n\t\t\t\tvertex.children.each do |v|\n\t\t\t\t\tt += 1\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tt\n\tend\n\n\tdef printParentEdges\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size != 0)\n\t\t\t\tvertex.parents.each do |v|\n\t\t\t\t\tputs \"#{vertex.index} #{v.index}\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef returnSources\n\t\ttemp = Array.new()\n\t\t@vertexSet.each do |vertex|\n\t\t\tif (vertex.parents.size == 0)\n\t\t\t\ttemp.push(vertex)\n\t\t\tend\n\t\tend\n\t\treturn temp\n\tend\n\n\tdef returnVertex(index)\n\t\t@vertexSet[index]\n\tend\n\n\tdef settleThings\n\t\tflag = 0\n\t\ttemp = Vertex.new(-1)\n\t\t@vertexSet.each do |vertex|\n\t\t\tif vertex.alone?\n\t\t\t\t# puts \"Gotcha #{vertex.index}!!!\"\n\t\t\t\tif flag == 0\n\t\t\t\t\t# puts \"Voila\"\n\t\t\t\t\ttemp = vertex\n\t\t\t\t\tflag = 1\n\t\t\t\telse\n\t\t\t\t\t# puts \"Temp.\"\n\t\t\t\t\ttemp.addNbr(vertex)\n\t\t\t\t\ttemp = vertex\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\tdef DFS(index)\n\t\tvertex = returnVertex(index)\n\t\tprint \"#{index}.\"\n\t\tvertex.children.each do |v|\n\t\t\tDFS(v.index)\n\t\tend\n\tend\n\nend\n\n\nclass Vertex\n\tattr_reader :index, :children, :parents, :color\n\tdef initialize(index)\n\t\t@index = index\n\t\t@children = Array.new()\n\t\t@parents = Array.new()\n\t\t@color = 0\n\tend\n\n\tdef addNbr(index)\n\t\t@children.push(index)\n\t\tindex.parents.push(self)\n\tend\n\n\tdef changeColor(color)\n\t\t@color = color\n\tend\n\n\tdef alone?\n\t\treturn ((@parents.size == 0) and (@children.size == 0))\n\tend\nend\n\nclass Heap\n\tattr_accessor :heap_size, :array_rep\n\n\tdef initialize()\n\t\t@array_rep = Array.new()\n\t\t@heap_size = 0\n\tend\n\n\tdef parent(index)\n\t\t(index - 1)/2\n\tend\n\n\tdef parentKey(index)\n\t\t@array_rep[parent(index)]\n\tend\n\n\tdef leftChild(index)\n\t\t2*index + 1\n\tend\n\n\tdef rightChild(index)\n\t\t2*index + 2\n\tend\n\n\tdef leftChildKey(index)\n\t\t@array_rep[leftChild(index)]\n\tend\n\n\tdef rightChildKey(index)\n\t\t@array_rep[rightChild(index)]\n\tend\n\n\tdef leafNode?(index)\n\t\treturn index >= @heap_size/2\n\tend\n\n\tdef getMin\n\t\t@array_rep[0]\n\tend\n\n\tdef deleteMin\n\t\t@array_rep[@heap_size-1], @array_rep[0] = @array_rep[0], @array_rep[@heap_size-1]\n \t@heap_size -= 1\n\t\t@array_rep.delete_at(@heap_size)\n\t\tself.fixOneError(0)\n\tend\n\n\tdef extractMin\n\t\ttemp = getMin.to_i\n\t\tdeleteMin\n\t\treturn temp\n\tend\n\n\tdef fixOneError(index)\n\t\treturn if leafNode?(index) || satisfied?(index)\n\n\t leftChildKey = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t rightChildKey = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\n \tsmallerChild = if leftChildKey < rightChildKey then leftChild(index) else rightChild(index) end\n\n \t@array_rep[index], @array_rep[smallerChild] = @array_rep[smallerChild], @array_rep[index]\n\n \tfixOneError(smallerChild)\n \tend\n\n\tdef satisfied?(index)\n\t\t# puts \"\\nin , #{index} Verify :\"\n\t\t# displayStatus\n\t\tt1 = if @array_rep[leftChild(index)] != nil then @array_rep[leftChild(index)] else Float::INFINITY end\n\t\tt2 = if @array_rep[rightChild(index)] != nil then @array_rep[rightChild(index)] else Float::INFINITY end\n\t\t@array_rep[index] <= t1 and @array_rep[index] <= t2\n \tend\n\n\tdef insert(value)\n\t\t@array_rep.push(value)\n\t\t@heap_size += 1\n\t\tindex = @heap_size - 1\n\n\t\twhile ((!(top?(index))) and (@array_rep[parent(index)] > @array_rep[index]))\n\t\t\t@array_rep[index], @array_rep[parent(index)] = @array_rep[parent(index)], @array_rep[index]\n\t\t\tindex = parent(index)\n\t\tend\n\tend\n\n\tdef top?(index)\n\t\treturn index == 0\n\tend\n\n\tdef displayStatus\n\t\tputs \"Status :\"\n\t\t@array_rep.each do |d|\n\t\t\tprint \"#{d}.\"\n\t\tend\n\tend\nend\n\ndef analyse(x, y)\n\tx = x.each_char.to_a\n\ty = y.each_char.to_a\n\t# puts \"x: #{x}\"\n\t# puts \"y: #{y}\"\n\tt = if x.size > y.size then y.size else x.size end\n\t(0..(t-1)).each do |i|\n\t\t# puts \"x: #{x[i]} y: #{y[i].ord}\"\n\t\tif x[i].ord != y[i].ord\n\t\t\treturn [(x[i].ord-97),(y[i].ord-97)]\n\t\tend\n\tend\n\tif x.size > y.size\n\t\treturn [-2, -2]\n\tend\n\treturn -1, -1\nend\n\n# code starts here :\n\nmyGraph = Graph.new(26)\nn = gets.chomp.to_i\nstr = gets.chomp\nmyFlag = 0\nif n == 100\n\tif str[0] == 'a'\n\t\tmyFlag = 1\n\tend\nend\n(2..n).each do |j|\n\tstr2 = gets.chomp\n\tn1, n2 = analyse(str, str2)\n\tif (n1 == -2)\n\t\tputs \"Impossible\\n\"\n\t\texit\n\tend\n\tif (n1 != -1)\n\t\tmyGraph.addEdge(n1, n2)\n\tend\n\tstr = str2\nend\n\nmyGraph.settleThings()\n# puts \"#{myGraph.vertexSet.size - 1} #{myGraph.countEdges}\"\n# myGraph.printEdges\n#\n# if ((myGraph.vertexSet.size - 1) < myGraph.countEdges)\n# \tputs \"IMPOSSIBLE\"\n# \texit\n# end\n\nmyHeap = Heap.new()\n\nsources = myGraph.returnSources()\n\nsources.each do |z|\n\tmyHeap.insert(z.index)\n\tz.changeColor(1)\nend\na = Array.new()\nwhile (myHeap.heap_size != 0)\n\tcurrentVertex = myGraph.returnVertex(myHeap.extractMin)\n\tcurrentVertex.changeColor(2)\n\tcurrentVertex.children.each do |v|\n\t\tif (v.parents.all? {|y| y.color == 2 })\n\t\t\tmyHeap.insert(v.index)\n\t\t\tv.changeColor(1)\n\t\tend\n\tend\n\ta.push((currentVertex.index.to_i+97).chr)\nend\nif a.size == 26\n\tprint \"#{a.join(\"\")}\\n\"\nelse\n\tprint \"Impossible\\n\"\n\tif myFlag == 1\n\t\tprint \"#{a.join(\"\")}\\n\"\n\tend\nend\n"}, {"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(letter1, letter2)\n if vertices[letter1].nil? then\n vertices[letter1] = List.new(letter2, nil)\n else\n vertices[letter1] = List.new(letter2, vertices[letter1])\n end\n end\n\n # def add_vertex(letter)\n # vertices[letter] = \"\" if vertices[letter].nil?\n # end\n\n def print_edges \n vertices.each do |letter, vertex| \n # next if vertex == \"\"\n while !vertex.nil? do \n puts \"edge #{letter} - #{vertex.element}\"\n vertex = vertex.next_elem \n end \n end \n end \n\n # def print_verteces\n # puts vertices.keys.join(\" \")\n # end\nend \n\ndef dfs(graph, letter, color)\n color[letter] = 'grey'\n next_vert = graph.vertices[letter]\n if next_vert.nil? \n return [letter]\n end \n alphabet = []\n while !next_vert.nil? do \n if color[next_vert.element] == 'grey'\n return \"Impossible\"\n else\n new_letter = dfs(graph, next_vert.element, color)\n if new_letter == \"Impossible\"\n return \"Impossible\"\n else\n alphabet = new_letter + alphabet\n end\n end\n next_vert = next_vert.next_elem\n end\n color[letter] = 'black'\n return [letter] + alphabet\nend\n\ndef permutation(sorted_letters)\n sorted_letters | (\"a\"..\"z\").to_a\nend\n\nnames = []\nn = gets.strip.to_i\nn.times{|i| names.push(gets.strip)}\nletters = Graph.new({})\n\n(n - 1).times do |i|\n length = [names[i].length, names[i+1].length].min\n length.times do |j|\n if names[i][j] != names[i+1][j]\n letters.add_edge(names[i][j], names[i+1][j])\n break\n end \n end\nend\n\ncolor = {}\nletters.vertices.each_key do |letter|\n color[letter] = 'white'\nend\nalphabet = []\nletters.vertices.each_key do |letter| \n if color[letter] == 'white'\n ordered_letters = dfs(letters, letter, color)\n if ordered_letters == \"Impossible\"\n alphabet = \"Impossible\"\n break\n end\n alphabet += ordered_letters\n end \nend\nif alphabet == \"Impossible\"\n puts alphabet \nelse\n puts permutation(alphabet).join\nend\n"}, {"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(letter1, letter2)\n if vertices[letter1].nil? then\n vertices[letter1] = List.new(letter2, nil)\n else\n vertices[letter1] = List.new(letter2, vertices[letter1])\n end\n end\n\n # def add_vertex(letter)\n # vertices[letter] = \"\" if vertices[letter].nil?\n # end\n\n def print_edges \n vertices.each do |letter, vertex| \n # next if vertex == \"\"\n while !vertex.nil? do \n puts \"edge #{letter} - #{vertex.element}\"\n vertex = vertex.next_elem \n end \n end \n end \n\n # def print_verteces\n # puts vertices.keys.join(\" \")\n # end\nend \n\ndef dfs(graph, letter, color)\n color[letter] = 'grey'\n next_vert = graph.vertices[letter]\n puts \"Processing letter: #{letter}\"\n p next_vert\n if next_vert.nil? \n # puts letter\n color[letter] = 'black'\n return [letter]\n end \n alphabet = []\n while !next_vert.nil? do \n if color[next_vert.element] == 'grey'\n puts \"#{letter} color is grey and it means we have a cycle\"\n return \"Impossible\"\n elsif color[next_vert.element] == 'white'\n puts \"#{next_vert.element}'s color is white\"\n new_letter = dfs(graph, next_vert.element, color)\n puts new_letter\n if new_letter == \"Impossible\"\n return \"Impossible\"\n else\n alphabet = new_letter + alphabet\n end\n end\n next_vert = next_vert.next_elem\n end\n color[letter] = 'black'\n return [letter] + alphabet\nend\n\ndef permutation(sorted_letters)\n sorted_letters | (\"a\"..\"z\").to_a\nend\n\nnames = []\nn = gets.strip.to_i\nn.times{|i| names.push(gets.strip)}\nletters = Graph.new({})\nalphabet = []\n(n - 1).times do |i|\n length = names[i].length\n length.times do |j|\n if j >= names[i+1].length\n alphabet = \"Impossible\"\n break\n end\n if names[i][j] != names[i+1][j]\n letters.add_edge(names[i][j], names[i+1][j])\n break\n end \n end\nend\n\n# letters.print_edges\n\ncolor = {}\n(\"a\"..\"z\").each do |letter|\n color[letter] = 'white'\nend\n# puts \"All the letters in the graph: #{letters.vertices.keys}\"\n# alphabet = []\nif alphabet != \"Impossible\"\n letters.vertices.each_key do |letter| \n if color[letter] == 'white'\n ordered_letters = dfs(letters, letter, color)\n if ordered_letters == \"Impossible\"\n alphabet = \"Impossible\"\n break\n end\n alphabet = ordered_letters + alphabet\n end \n end\nend\nif alphabet == \"Impossible\"\n puts alphabet \nelse\n puts permutation(alphabet).join\nend\n"}, {"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(letter1, letter2)\n if vertices[letter1].nil? then\n vertices[letter1] = List.new(letter2, nil)\n else\n vertices[letter1] = List.new(letter2, vertices[letter1])\n end\n end\n\n # def add_vertex(letter)\n # vertices[letter] = \"\" if vertices[letter].nil?\n # end\n\n def print_edges \n vertices.each do |letter, vertex| \n # next if vertex == \"\"\n while !vertex.nil? do \n puts \"edge #{letter} - #{vertex.element}\"\n vertex = vertex.next_elem \n end \n end \n end \n\n # def print_verteces\n # puts vertices.keys.join(\" \")\n # end\nend \n\ndef dfs(graph, letter, color)\n color[letter] = 'grey'\n next_vert = graph.vertices[letter]\n # puts \"Processing letter: #{letter}\"\n # p next_vert\n if next_vert.nil? \n # puts letter\n color[letter] = 'black'\n return [letter]\n end \n alphabet = []\n while !next_vert.nil? do \n if color[next_vert.element] == 'grey'\n # puts \"#{letter} color is grey and it means we have a cycle\"\n return \"Impossible\"\n elsif color[next_vert.element] == 'white'\n # puts \"#{next_vert.element}'s color is white\"\n new_letter = dfs(graph, next_vert.element, color)\n # puts new_letter\n if new_letter == \"Impossible\"\n return \"Impossible\"\n else\n alphabet = new_letter + alphabet\n end\n end\n next_vert = next_vert.next_elem\n end\n color[letter] = 'black'\n return [letter] + alphabet\nend\n\ndef permutation(sorted_letters)\n sorted_letters | (\"a\"..\"z\").to_a\nend\n\nnames = []\nn = gets.strip.to_i\nn.times{|i| names.push(gets.strip)}\nletters = Graph.new({})\n\n(n - 1).times do |i|\n length = [names[i].length, names[i+1].length].min\n length.times do |j|\n if names[i][j] != names[i+1][j]\n letters.add_edge(names[i][j], names[i+1][j])\n break\n end \n end\nend\n\n# letters.print_edges\n\ncolor = {}\n(\"a\"..\"z\").each do |letter|\n color[letter] = 'white'\nend\n# puts \"All the letters in the graph: #{letters.vertices.keys}\"\nalphabet = []\nletters.vertices.each_key do |letter| \n if color[letter] == 'white'\n ordered_letters = dfs(letters, letter, color)\n if ordered_letters == \"Impossible\"\n alphabet = \"Impossible\"\n break\n end\n alphabet = ordered_letters + alphabet\n end \nend\nif alphabet == \"Impossible\"\n puts alphabet \nelse\n puts permutation(alphabet).join\nend\n"}, {"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(letter1, letter2)\n if vertices[letter1].nil? then\n vertices[letter1] = List.new(letter2, nil)\n else\n vertices[letter1] = List.new(letter2, vertices[letter1])\n end\n end\n\n # def add_vertex(letter)\n # vertices[letter] = \"\" if vertices[letter].nil?\n # end\n\n def print_edges \n vertices.each do |letter, vertex| \n # next if vertex == \"\"\n while !vertex.nil? do \n puts \"edge #{letter} - #{vertex.element}\"\n vertex = vertex.next_elem \n end \n end \n end \n\n # def print_verteces\n # puts vertices.keys.join(\" \")\n # end\nend \n\ndef dfs(graph, letter, color)\n color[letter] = 'grey'\n next_vert = graph.vertices[letter]\n # puts \"Processing letter: #{letter}\"\n # p next_vert\n if next_vert.nil? \n # puts letter\n color[letter] = 'black'\n return [letter]\n end \n alphabet = []\n while !next_vert.nil? do \n if color[next_vert.element] == 'grey'\n # puts \"#{letter} color is grey and it means we have a cycle\"\n return \"Impossible\"\n elsif color[next_vert.element] == 'white'\n # puts \"#{next_vert.element}'s color is white\"\n new_letter = dfs(graph, next_vert.element, color)\n # puts new_letter\n if new_letter == \"Impossible\"\n return \"Impossible\"\n else\n alphabet = new_letter + alphabet\n end\n end\n next_vert = next_vert.next_elem\n end\n color[letter] = 'black'\n return [letter] + alphabet\nend\n\ndef permutation(sorted_letters)\n sorted_letters | (\"a\"..\"z\").to_a\nend\n\nnames = []\nn = gets.strip.to_i\nn.times{|i| names.push(gets.strip)}\nletters = Graph.new({})\n\n(n - 1).times do |i|\n length = [names[i].length, names[i+1].length].min\n length.times do |j|\n if names[i][j] != names[i+1][j]\n letters.add_edge(names[i][j], names[i+1][j])\n break\n end \n end\nend\n\n# letters.print_edges\n\ncolor = {}\n(\"a\"..\"z\").each do |letter|\n color[letter] = 'white'\nend\n# puts \"All the letters in the graph: #{letters.vertices.keys}\"\nalphabet = []\nletters.vertices.each_key do |letter| \n if color[letter] == 'white'\n ordered_letters = dfs(letters, letter, color)\n if ordered_letters == \"Impossible\"\n alphabet = \"Impossible\"\n break\n end\n alphabet += ordered_letters\n end \nend\nif alphabet == \"Impossible\"\n puts alphabet \nelse\n puts permutation(alphabet).join\nend\n"}, {"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(letter1, letter2)\n if vertices[letter1].nil? then\n vertices[letter1] = List.new(letter2, nil)\n else\n vertices[letter1] = List.new(letter2, vertices[letter1])\n end\n end\n\n # def add_vertex(letter)\n # vertices[letter] = \"\" if vertices[letter].nil?\n # end\n\n def print_edges \n vertices.each do |letter, vertex| \n # next if vertex == \"\"\n while !vertex.nil? do \n puts \"edge #{letter} - #{vertex.element}\"\n vertex = vertex.next_elem \n end \n end \n end \n\n # def print_verteces\n # puts vertices.keys.join(\" \")\n # end\nend \n\ndef dfs(graph, letter, color)\n color[letter] = 'grey'\n next_vert = graph.vertices[letter]\n # puts \"Processing letter: #{letter}\"\n # p next_vert\n if next_vert.nil? \n # puts letter\n return [letter]\n end \n alphabet = []\n while !next_vert.nil? do \n if color[next_vert.element] == 'grey'\n return \"Impossible\"\n elsif color[next_vert.element] == 'white'\n # puts \"#{next_vert.element}'s color is white\"\n new_letter = dfs(graph, next_vert.element, color)\n # puts new_letter\n if new_letter == \"Impossible\"\n return \"Impossible\"\n else\n alphabet = new_letter + alphabet\n end\n end\n next_vert = next_vert.next_elem\n end\n color[letter] = 'black'\n return [letter] + alphabet\nend\n\ndef permutation(sorted_letters)\n sorted_letters | (\"a\"..\"z\").to_a\nend\n\nnames = []\nn = gets.strip.to_i\nn.times{|i| names.push(gets.strip)}\nletters = Graph.new({})\n\n(n - 1).times do |i|\n length = [names[i].length, names[i+1].length].min\n length.times do |j|\n if names[i][j] != names[i+1][j]\n letters.add_edge(names[i][j], names[i+1][j])\n break\n end \n end\nend\n\n# letters.print_edges\n\ncolor = {}\n(\"a\"..\"z\").each do |letter|\n color[letter] = 'white'\nend\n# puts \"All the letters in the graph: #{letters.vertices.keys}\"\nalphabet = []\nletters.vertices.each_key do |letter| \n if color[letter] == 'white'\n ordered_letters = dfs(letters, letter, color)\n if ordered_letters == \"Impossible\"\n alphabet = \"Impossible\"\n break\n end\n alphabet += ordered_letters\n end \nend\nif alphabet == \"Impossible\"\n puts alphabet \nelse\n puts permutation(alphabet).join\nend\n"}, {"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(letter1, letter2)\n if vertices[letter1].nil? then\n vertices[letter1] = List.new(letter2, nil)\n else\n vertices[letter1] = List.new(letter2, vertices[letter1])\n end\n end\n\n # def add_vertex(letter)\n # vertices[letter] = \"\" if vertices[letter].nil?\n # end\n\n def print_edges \n vertices.each do |letter, vertex| \n # next if vertex == \"\"\n while !vertex.nil? do \n puts \"edge #{letter} - #{vertex.element}\"\n vertex = vertex.next_elem \n end \n end \n end \n\n # def print_verteces\n # puts vertices.keys.join(\" \")\n # end\nend \n\ndef dfs(graph, letter, marked)\n marked[letter] = true\n next_vert = graph.vertices[letter]\n if next_vert.nil? \n return [letter]\n end \n alphabet = []\n while !next_vert.nil? do \n if marked[next_vert.element]\n return \"Impossible\"\n else\n new_letter = dfs(graph, next_vert.element, marked)\n if new_letter == \"Impossible\"\n return \"Impossible\"\n else\n alphabet = new_letter + alphabet\n end\n end\n next_vert = next_vert.next_elem\n end\n return [letter] + alphabet\nend\n\ndef permutation(sorted_letters)\n sorted_letters | (\"a\"..\"z\").to_a\nend\n\nnames = []\nn = gets.strip.to_i\nn.times{|i| names.push(gets.strip)}\nletters = Graph.new({})\n\n(n - 1).times do |i|\n length = [names[i].length, names[i+1].length].min\n length.times do |j|\n if names[i][j] != names[i+1][j]\n letters.add_edge(names[i][j], names[i+1][j])\n break\n end \n end\nend\n\nmarked = {}\nletters.vertices.each_key do |letter|\n marked[letter] = false\nend\nalphabet = []\nletters.vertices.each_key do |letter| \n if !marked[letter]\n ordered_letters = dfs(letters, letter, marked)\n if ordered_letters == \"Impossible\"\n alphabet = \"Impossible\"\n break\n end\n alphabet += ordered_letters\n end \nend\nif alphabet == \"Impossible\"\n puts alphabet \nelse\n puts permutation(alphabet).join\nend\n"}, {"source_code": "Point = Struct.new(:char, :color, :children)\nchars = Hash[('a'..'z').map{|c| [c, Point.new(c, :white, [])]}]\nn = gets.to_i\nwords = []\nn.times do\n words << gets.chomp.chars\nend\nwords.each_cons(2) do |prv,nxt|\n p, n = prv.zip(nxt).drop_while{|p,n| p==n}.first\n if n == nil\n if n == nil\n next\n else\n puts \"Impossible\"\n exit\n end\n end\n (chars[p].children << chars[n]).uniq!{|v| v.char}\nend\ndef yoba(v,order)\n case v.color\n when :gray\n return false\n when :black\n return true\n end\n v.color = :gray\n v.children.each do |v|\n return false unless yoba(v, order)\n end\n v.color = :black\n order << v.char\n true\nend\norder = []\nchars.values.reverse.each do |v|\n unless yoba(v,order)\n puts \"Impossible\"\n exit\n end\nend\nputs order.reverse.join"}], "src_uid": "12218097cf5c826d83ab11e5b049999f"} {"source_code": "tasks_numbers = gets.chomp\nallowed_lines = []\n(1..tasks_numbers.to_i).each do\n\trows_cols = gets.chomp\n\trows, cols = rows_cols.split(\" \").map{|e| e.to_i}\n\tall_pairs = rows + cols\n\tallowed_cols = (1..cols).to_a\n\tallowed_rows_qty = rows\n\t(1..rows).each do\n\t\tindex = 0\n\t\tisset_1 = false\n\t\tvalues = gets.chomp\n\t\tvalues.split(\" \").each do |value|\n\t\t\tindex += 1\n\t\t\tif value == '1'\n\t\t\t\tallowed_cols.delete(index)\n\t\t\t\tisset_1 = true\n\t\t\tend\n\t\tend\n\t\tallowed_rows_qty -= 1 if isset_1\n\tend\n\tallowed_lines.push [allowed_rows_qty, allowed_cols.length].min\nend\n\nallowed_lines.each do |allowed_line|\n\tif allowed_line == 0\n\t\tputs 'Vivek'\n\telse\n\t\tif allowed_line % 2 > 0\n\t\t\tputs 'Ashish'\n\t\telse\n\t\t\tputs 'Vivek'\n\t\tend\n\tend\nend\n", "positive_code": [{"source_code": "tests = gets.to_i\ntests.times do\n\trows, columns = gets.split(' ')\n\trows = rows.to_i\n\tcolumns = columns.to_i\n\ttable = Array.new(rows){Array.new(columns)}\n\tcnt_rows = Array.new(rows, 0)\n\tcnt_columns = Array.new(columns, 0)\n\trows.times do\n\t\t|row|\n\t\tline = gets.split(' ')\n\t\tcolumns.times do\n\t\t\t|column|\n\t\t\ttable[row][column] = line[column].to_i\n\t\t\tcnt_rows[row] += table[row][column]\n\t\t\tcnt_columns[column] += table[row][column]\n\t\tend\n\tend\n\tcnt_missing_rows = 0\n\tcnt_missing_columns = 0\n\trows.times do\n\t\t|idx|\n\t\tif cnt_rows[idx] == 0\n\t\t\tcnt_missing_rows += 1\n\t\tend\n\tend\n\n\tcolumns.times do\n\t\t|idx|\n\t\tif cnt_columns[idx] == 0\n\t\t\tcnt_missing_columns += 1\n\t\tend\n\tend\n\tres = [cnt_missing_rows, cnt_missing_columns].min\n\tif res%2 == 0\n\t\tputs \"Vivek\"\n\telse\n\t\tputs \"Ashish\"\n\tend\nend\n"}], "negative_code": [{"source_code": "tasks_numbers = gets.chomp\nallowed_lines = []\n(1..tasks_numbers.to_i).each do\n\trows_cols = gets.chomp\n\trows, cols = rows_cols.split(\" \").map{|e| e.to_i}\n\tall_pairs = rows + cols\n\tallowed_cols = (1..cols).to_a\n\tallowed_rows_qty = rows\n\t(1..rows).each do\n\t\tindex = 0\n\t\tisset_1 = false\n\t\tvalues = gets.chomp\n\t\tvalues.split(\" \").each do |value|\n\t\t\tindex += 1\n\t\t\tif value == '1'\n\t\t\t\tallowed_cols.delete(index)\n\t\t\t\tisset_1 = true\n\t\t\tend\n\t\tend\n\t\tallowed_rows_qty -= 1 if isset_1\n\tend\n\tallowed_lines.push(allowed_rows_qty + allowed_cols.length)\nend\n\nallowed_lines.each do |allowed_line|\n\tif allowed_line < 2\n\t\tputs 'Vivek'\n\telse\n\t\tallowed_line -= 1 if allowed_line % 2 > 0\n\t\tallowed_line = allowed_line / 2\n\t\tif allowed_line % 2 > 0\n\t\t\tputs 'Ashish'\n\t\telse\n\t\t\tputs 'Vivek'\n\t\tend\n\tend\nend\n"}], "src_uid": "3ccc98190189b0c8e58a96dd5ad1245d"} {"source_code": "n, d = gets.split.map &:to_i\nnQ = gets.to_i\nnQ.times do\n x, y = gets.split.map &:to_i\n f = true \n f &= x+y >= d\n f &= (n-x)+(n-y)>=d \n f &= x+(n-y)>=n-d\n f &= (n-x)+y>=n-d\n puts f ? \"YES\" : \"NO\"\nend\n\n", "positive_code": [{"source_code": "n, d=gets.strip.split.map(&:to_i)\n\nhsh = {}\n\ny1 = d\n0.upto(n-d).each do |x1|\n y = y1\n x = x1\n (d+1).times do\n hsh[\"#{x},#{y}\"]=true\n y -= 1\n x += 1\n end\n y1 += 1\nend\n\ny1 = d\n1.upto(n-d).each do |x1|\n y = y1\n x = x1\n d.times do\n hsh[\"#{x},#{y}\"]=true\n y -= 1\n x += 1\n end\n y1 += 1\nend\n\nm = gets.to_i\nm.times do\n x,y=gets.strip.split.map(&:to_i)\n puts (hsh[\"#{x},#{y}\"] ? \"YES\" : \"NO\")\nend"}, {"source_code": "def d(x,y,x1,y1,x2,y2,p)\n a = (y2-y1)/(x2-x1)\n b = (x2*y1-x1*y2)/(x2-x1)\n return ((p == 0) == (a*x+b < y)) || a*x+b == y\nend\n\nn,d = gets.split.map(&:to_i)\ngets.to_i.times do\n x,y = gets.split.map(&:to_i)\n puts d(x,y,0,d,d,0,0) && d(x,y,d,0,n,n-d,0) && d(x,y,n,n-d,n-d,n,1) && d(x,y,n-d,n,0,d,1) ? \"YES\" : \"NO\"\nend\n"}], "negative_code": [], "src_uid": "9c84eb518c273942650c7262e5d8b45f"} {"source_code": "n,*a=gets(p).split.map(&:to_i)<<$$;p (0...n).map{|x|y=x;1until a[y]= a[i-1] ? l[i-1] + 1 : 0);\n\ti+=1\nend\ni=n-2\nwhile i>=0\n\tr[i] = (a[i] >= a[i+1] ? r[i+1]+1 : 0)\n\ti-=1\nend\nn.times {|i| ans=l[i]+r[i]+1 if l[i]+r[i]+1>ans}\nputs ans"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nmax = 0\n(0...n).each do |i|\n left, right = i, i\n while left>0 and a[left-1] <= a[left]\n left-=1\n end\n while right max\nend\nputs max"}, {"source_code": "n,*a=gets(p).split.map(&:to_i)<<$$;p (0...n).map{|x|y=x;1until a[y]= map[pos - 1])\n count += 1\n pos -= 1\n cur_height = map[pos]\n end\n pos = center\n cur_height = map[pos]\n while (cur_height >= map[pos + 1])\n count += 1\n pos += 1\n cur_height = map[pos]\n end\n\n ret = count if ret < count\n}\nputs ret\n"}, {"source_code": "n,*a=gets(p).split.map(&:to_i)<<$$;p (0...n).map{|x|y=x;1until a[y]m then num=i; m=c; end\nend\n\nputs m"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\ndp_left = [0]\narr.each_cons(2) do |a,b|\n\tdp_left << 0\n\tif b >= a\n\t\tdp_left[-1] += dp_left[-2] + 1\n\tend\nend\n\ndp_right = [0]\n\n((n-2).downto(0)).each do |i|\n\tdp_right << 0\n\tif arr[i] >= arr[i+1]\n\t\tdp_right[-1] += dp_right[-2] + 1\n\tend\nend\ndp_right.reverse!\nans_list = dp_left.zip(dp_right).map { |x, y| x + y + 1 }\nputs \"#{ans_list.max}\"\n"}, {"source_code": "n=gets.chomp.to_i\na=gets.chomp.split(/ /).map{|x|x.to_i}\ndef toleft(a,k)\n x=a[k]\n i=0\n while a[k-i-1]<=x\n x=a[k-1-i]\n i+=1\n end\n i\nend\ndef toright(a,k)\n x=a[k]\n i=0\n while a[k+i+1]<=x\n x=a[k+1+i]\n i+=1\n end\n i\nend\na=a.unshift(a.max+1).push(a.max+1)\np (1..n).map{|x|1+toleft(a,x)+toright(a,x)}.max\n"}, {"source_code": "gets\nareas = gets.chomp.split.map(&:to_i)\n\nmax = 0\nareas.each_with_index do |a, i|\n cnt = 1\n\n (i - 1).downto(0).each do |l|\n break if l < 0\n if areas[l] <= areas[l + 1]\n cnt += 1\n else\n break\n end\n end\n\n (i.succ..areas.size - 1).each do |r|\n if areas[r] <= areas[r - 1]\n cnt += 1\n else\n break\n end\n end\n\n max = [max, cnt].max\nend\n\nputs max\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\ns1 = [0]*n\n(1..n-1).each do |i|\n if a[i] >= a[i-1]\n s1[i] = s1[i-1]+1\n end\nend\n\ns2 = [0]*n\n(n-2).downto(0) do |i|\n if a[i] >= a[i+1]\n s2[i] = s2[i+1]+1\n end\nend\n\np s1.zip(s2).map{|x,y| x+y+1}.max\n"}, {"source_code": "n,*a=gets(p).split.map(&:to_i)<<$$;p (0...n).map{|x|y=x;1until a[y] [\"a\",\"b\",\"c\"]\n#String # to_ia\n# \"1 2 3\".to_ia #=> [1,2,3]\n#\n#Array # rsort,rsort!\n# [1,3,2,4].rsort #=> [4,3,2,1]\n#\n#Integer # divisor\n# 24.divisor #=> [1,2,3,4,6,8,12,24]\n#\ninclude Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInfinity = 1/0.0\nclass Matrix;def inspect;empty? ? \"Matrix.empty(#{row_size}, #{column_size})\":\"Matrix[\\n#{@rows.map(&:inspect).join(\"\\n\")}\\n]\";end;end\ndef pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end\nclass String;def to_a;split(\"\");end;end\nclass String;def to_ia;split.map(&:to_i);end;end\ndef getia;gets.to_ia;end\ndef geti;gets.to_i;end\nclass Object;def dcopy;Marshal.load(Marshal.dump(self));end;end\nclass Array;def rsort;sort.reverse;end;def rsort!;sort!.reverse!;end;end\n\nn=geti\nls=getia\nans=0\nfor i in 0...n\n a=0\n for j in 1..i\n break if ls[i-j] > ls[i-j+1]\n a+=1\n end\n for j in 1...(n-i)\n break if ls[i+j] > ls[i+j-1]\n a+=1\n end\n ans=[a,ans].max\nend\np ans+1\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = gets.to_i\narr = gets.split.map(&:to_i)\nans = 0\narr.each_with_index { |v, i|\n\tleft = right = i\n\tleft -= 1 while left > 0 && arr[left-1] <= arr[left]\n\tright += 1 while right < n-1 && arr[right+1] <= arr[right]\n\tnum = right-left+1\n\tans = num if num > ans\n}\nputs ans\n"}, {"source_code": "n,*a=gets(p).split.map(&:to_i)<<$$;p (0...n).map{|x|y=x;1until a[y]= 0 && vl && vl <= old_vl\n cnt += 1 if vr && vr <= old_vr\n\n #p [l, r, cnt, max]\n\n l -= 1\n r += 1\n\n old_vl, old_vr = (l < 0 ? 10000 : vl), vr\n break if old_cnt == cnt\n end\n\n max = [max, cnt].max\n #puts\nend\n\nputs max\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\ns1 = [0]*n\n(1..n-1).each do |i|\n if a[i] >= a[i-1]\n s1[i] = s1[i-1]+1\n end\nend\n\ns2 = [0]*n\n(n-2).downto(1) do |i|\n if a[i] >= a[i+1]\n s2[i] = s2[i+1]+1\n end\nend\n\np s1.zip(s2).map{|x,y| x+y+1}.max\n"}], "src_uid": "5d11fa8528f1dc873d50b3417bef8c79"} {"source_code": "n, $m = readline.split.map(&:to_i)\nx = readline.split.map(&:to_i)\n\nx.sort!\n\nl = r = x[0]\ns = []\nfor xi in x[1..-1] do\n if xi > r + 1\n s << [l,r]\n l = xi\n end\n r = xi\nend\ns << [l,r]\n\n$d = 1\n$res = 0\n$y = []\ndef man(yi)\n $y << yi\n $m -= 1\n $res += $d\n if $m <= 0\n print($res, \"\\n\", $y.join(' '), \"\\n\")\n exit\n end\nend\nwhile $m > 0 do\n l,r = s[0]\n s1 = []\n man(l-1)\n man(r+1)\n for l1,r1 in s[1..-1] do\n if l1 > r + 2\n if l1 > r + 3\n s1 << [l-1,r+1]\n l = l1\n end\n man(l1-1)\n end\n r = r1\n man(r+1)\n end\n s1 << [l-1,r+1]\n s = s1\n $d += 1\nend\n", "positive_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a r + 1\n s << [l,r]\n l = xi\n end\n r = xi\nend\ns << [l,r]\n\n$d = 1\n$res = 0\n$y = []\ndef man(yi)\n $y << yi\n $m -= 1\n $res += $d\n if $m <= 0 then\n print($res, \"\\n\", $y.join(' '), \"\\n\")\n exit\n end\nend\nwhile $m > 0 do\n l,r = s[0]\n s1 = []\n man(l-1)\n man(r+1)\n for l1,r1 in s[1..-1] do\n if l1 > r + 2\n s1 << [l-1,r+1]\n l = l1\n man(l-1)\n end\n r = r1\n man(r+1)\n end\n s1 << [l-1,r+1]\n s = s1\n $d += 1\nend\n"}, {"source_code": "n, $m = readline.split.map(&:to_i)\nx = readline.split.map(&:to_i)\n\nx.sort!\n\nl = r = x[0]\ns = []\nfor xi in x[1..-1] do\n if xi > r + 1\n s << [l,r]\n l = xi\n end\n r = xi\nend\ns << [l,r]\n\n$d = 1\n$res = 0\n$y = []\ndef man(yi)\n $y << yi\n $m -= 1\n $res += $d\n if $m <= 0 then\n print($res, \"\\n\", $y.join(' '), \"\\n\")\n exit\n end\nend\nwhile $m > 0 do\n l,r = s[0]\n s1 = []\n man(l-1)\n for l1,r1 in s[1..-1] do\n man(r+1)\n if l1 > r + 2\n s1 << [l-1,r+1]\n l = l1\n man(l-1)\n end\n r = r1\n end\n man(r+1)\n s1 << [l-1,r+1]\n s = s1\n $d += 1\nend\n"}], "src_uid": "3a3666609b120d208c3e8366b186d89b"} {"source_code": "N, M, H = gets.split.map(&:to_i)\nA = gets.split.map(&:to_i)\nB = gets.split.map(&:to_i)\ngrid = N.times.map { gets.split.map(&:to_i) }\n\nB.each_with_index do |b, i|\n temp = grid.map(&:dup)\n\n temp[i].each_with_index do |h, j|\n if h >= 1 && b <= A[j]\n grid[i][j] = b\n end\n end\nend\n\nA.each_with_index do |a, i|\n temp = grid.map(&:dup)\n\n N.times do |j|\n h = temp[j][i]\n\n if h >= 1 && a <= B[j] && h <= a\n grid[j][i] = a\n end\n end\nend\n\nputs grid.map { |l| l.join(' ') }\n", "positive_code": [{"source_code": "N,M,H = gets.split.map(&:to_i)\nf = gets.split.map(&:to_i)\nl = gets.split.map(&:to_i)\nt = []\nN.times do \n t << gets.split.map(&:to_i)\nend\n\nN.times do |i|\n l[i] = [l[i],i]\nend\n#p l\nl.sort_by!{|a| a[0]}.reverse!\n\nans = Array.new(N){Array.new(M,nil)}\n\nd = []\nl.each do |h,i|\n tmp = 0\n M.times do |j|\n if f[j] >= h && t[i][j] != 0\n tmp = j \n break\n end\n end\n ans[i][tmp] = h\nend\n\nM.times do |j|\n l.each do |h,i|\n if t[i][j] != 0\n ans[i][j] = f[j]\n break\n end\n end\nend\nN.times do |i|\n M.times do |j|\n if ans[i][j].nil?\n ans[i][j] = t[i][j] == 0 ? 0 : 1\n end\n end\nend\n\nans.each do |a|\n puts a.join(\" \")\nend"}, {"source_code": "n, m, h = gets.chomp.split(\" \").map(&:to_i)\n\nfront = gets.chomp.split(\" \").map(&:to_i)\nleft = gets.chomp.split(\" \").map(&:to_i)\n\ntop = []\nn.times do\n top << gets.chomp.split(\" \").map(&:to_i)\nend\n\nret = Array.new(n){Array.new(m, -1)}\n\nm.times do |i|\n n.times do |j|\n ret[j][i] = front[i]\n end\nend\n\nn.times do |j|\n m.times do |i|\n ret[j][i] = [ret[j][i], left[j]].min\n end\nend\n\nm.times do |i|\n n.times do |j|\n if top[j][i] == 0\n ret[j][i] = 0\n end\n end\nend\n\nret.each{|line| puts line.join(\" \")}"}], "negative_code": [{"source_code": "N,M,H = gets.split.map(&:to_i)\nf = gets.split.map(&:to_i)\nl = gets.split.map(&:to_i)\nt = []\nN.times do \n t << gets.split.map(&:to_i)\nend\n\nN.times do |i|\n l[i] = [l[i],i]\nend\n#p l\nl.sort_by!{|a| a[0]}.reverse!\n\nans = Array.new(N){Array.new(M,nil)}\n\nd = []\nl.each do |h,i|\n tmp = nil\n N.times do |j|\n tmp = j if f[j] == h && t[i][j] != 0\n end\n if !tmp.nil?\n ans[i][tmp] = h\n d << tmp\n else\n d.each do |j|\n if t[i][j] != 0\n ans[i][j] = h\n break\n end\n end\n end\nend\nM.times do |i|\n if !d.include?(i)\n l.each do |h,j|\n if t[j][i] != 0\n ans[j][i] = f[i]\n break\n end\n end\n end\nend\nN.times do |i|\n M.times do |j|\n if ans[i][j].nil?\n ans[i][j] = t[i][j] == 0 ? 0 : 1\n end\n end\nend\n\nans.each do |a|\n puts a.join(\" \")\nend"}], "src_uid": "7361e8acf0d712c317e8b99211a7b548"} {"source_code": "n, k = gets.split.map{|e| e.to_i}\n\na = gets.split.map{|e| e.to_i}.to_a\n\nmn = 10**9\n\n(1..1000).each do |i|\n cur = 0\n (0...a.size).each do |j|\n if ((a[j] - (i + k * j)) != 0)\n cur += 1\n end\n end\n if (cur < mn) \n mn = cur\n end\nend\n\nputs mn\n\n(1..1000).each do |i|\n cur = 0\n (0...a.size).each do |j|\n if ((a[j] - (i + k * j)) != 0)\n cur += 1\n end\n end\n if (cur == mn)\n (0...a.size).each do |j|\n if (a[j] - (i + k * j) < 0)\n print '+ '\n puts (j + 1).to_s + ' ' + (a[j] - (i + k * j)).abs.to_s\n elsif (a[j] - (i + k * j) > 0)\n print '- '\n puts (j + 1).to_s + ' ' + (a[j] - (i + k * j)).abs.to_s\n end\n end\n break\n end\nend\n", "positive_code": [{"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nmn, c = 0x3f3f3f3f3f3f3f3f, 0\nn.times do |i|\n\tcc, tot = a[i]-i*k, 0\n\tnext if cc <= 0\n\tn.times{|j| cc,tot=cc+k,tot+(a[j]==cc ? 0 : 1)}\n\tmn, c = tot, a[i]-i*k if tot < mn\nend\np mn\nn.times do |i|\n\tputs \"- #{i+1} #{a[i]-c}\" if c < a[i]\n\tputs \"+ #{i+1} #{c-a[i]}\" if c > a[i]\n\tc += k\nend\n"}], "negative_code": [{"source_code": "n, k = gets.split.map{|e| e.to_i}\n\na = gets.split.map{|e| e.to_i}.to_a\n\nmn = 10**9\n\n(1...1000).each do |i|\n cur = 0\n (0...a.size).each do |j|\n if ((a[j] - (i + k * j)) != 0)\n cur += 1\n end\n end\n if (cur < mn) \n mn = cur\n end\nend\n\nputs mn\n\n(1...1000).each do |i|\n cur = 0\n (0...a.size).each do |j|\n if ((a[j] - (i + k * j)) != 0)\n cur += 1\n end\n end\n if (cur == mn)\n (0...a.size).each do |j|\n if (a[j] - (i + k * j) < 0)\n print '+ '\n puts (j + 1).to_s + ' ' + (a[j] - (i + k * j)).abs.to_s\n elsif (a[j] - (i + k * j) > 0)\n print '- '\n puts (j + 1).to_s + ' ' + (a[j] - (i + k * j)).abs.to_s\n end\n end\n break\n end\nend\n"}, {"source_code": "n, k = gets.split.map{|e| e.to_i}\n\na = gets.split.map{|e| e.to_i}.to_a\n\nmn = 10**9\n\n(0...1000).each do |i|\n cur = 0\n (0...a.size).each do |j|\n if ((a[j] - (i + k * j)) != 0)\n cur += 1\n end\n end\n if (cur < mn) \n mn = cur\n end\nend\n\nputs mn\n\n(0...1000).each do |i|\n cur = 0\n (0...a.size).each do |j|\n if ((a[j] - (i + k * j)) != 0)\n cur += 1\n end\n end\n if (cur == mn)\n (0...a.size).each do |j|\n if (a[j] - (i + k * j) < 0)\n print '+ '\n puts (j + 1).to_s + ' ' + (a[j] - (i + k * j)).abs.to_s\n elsif (a[j] - (i + k * j) > 0)\n print '- '\n puts (j + 1).to_s + ' ' + (a[j] - (i + k * j)).abs.to_s\n end\n end\n break\n end\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nmn, c = 0x3f3f3f3f3f3f3f3f, 0\n(-k..k).each do |i|\n\tcc, tot = a[0] + i, 0\n\tn.times{|j| cc,tot=cc+k,tot+(a[j]==cc ? 0 : 1)}\n\tmn, c = tot, a[0] + i if tot < mn\nend\np mn\nn.times do |i|\n\tif (c < a[i])\n\t\tputs \"- #{i+1} #{a[i]-c}\"\n\telsif (c > a[i])\n\t\tputs \"+ #{i+1} #{c-a[i]}\"\n\tend\n\tc += k\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nmn, c = 0x3f3f3f3f3f3f3f3f, 0\n(-k..k).each do |i|\n\tcc, tot = a[0] + i, 0\n\tnext if cc <= 0\n\tn.times{|j| cc,tot=cc+k,tot+(a[j]==cc ? 0 : 1)}\n\tmn, c = tot, a[0] + i if tot < mn\nend\np mn\nn.times do |i|\n\tputs \"- #{i+1} #{a[i]-c}\" if c < a[i]\n\tputs \"+ #{i+1} #{c-a[i]}\" if c > a[i]\n\tc += k\nend\n"}], "src_uid": "7f08e74945d6b58abde1d8002b8b686a"} {"source_code": "\ndef can_travel(alice_station, from_bob_metro, to_bob_metro)\n return \"NO\" if from_bob_metro[0] == 0\n \n return \"YES\" if from_bob_metro[alice_station - 1] == 1\n \n index = alice_station\n while index < from_bob_metro.length && from_bob_metro[index] + to_bob_metro[index] != 2\n index += 1\n end\n \n return \"NO\" if index == from_bob_metro.length\n return \"YES\" if to_bob_metro[alice_station - 1] == 1\n \"NO\"\nend\n\nnumber_of_stations, alice_station = gets.chomp.split(\" \").map(&:to_i)\nfrom_bob_metro = gets.chomp.split(\" \").map(&:to_i)\nto_bob_metro = gets.chomp.split(\" \").map(&:to_i)\n\nputs can_travel(alice_station, from_bob_metro, to_bob_metro)", "positive_code": [{"source_code": "\nn,s = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\n\nif(a[0]==0 || (a[s-1]==0 && b[s-1]==0)) then puts(\"NO\")\nelsif(a[s-1]==1) then puts(\"YES\")\nelsif(b[s-1]==0) then puts(\"NO\")\nelse\n\tflag = 0\n\tfor i in (s...n) do\n\t\tif(a[i]==1 && b[i]==1) then flag = 1; break; end\n\tend\n\tif(flag==1) then puts(\"YES\")\n\telse puts(\"NO\") end\nend\n"}, {"source_code": "n,s = gets.strip.split.map(&:to_i)\ns -= 1\n\na = gets.strip.split.map(&:to_i)\nb = gets.strip.split.map(&:to_i)\n\nli = -1\nposs = []\nif a[0]==1\n 0.upto(n-1).each do |i|\n if a[i]==1\n poss << i\n if b[i] == 1\n li = i\n end\n end\n end\nend\n\n# puts li\nif li>-1\n li.downto(0) do |i|\n if b[i] == 1\n poss << i\n end\n end\nend\n\nputs (poss.include?(s) ? \"YES\" : \"NO\")\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\nA = gets.split.map(&:to_i)\nB = gets.split.map(&:to_i)\nAd = A[s..n]\n\nif A[0] == 0\n print \"NO\"\nelsif A[s - 1] == 1\n print \"YES\"\nelsif B[s - 1] == 0\n print \"NO\"\nelsif !Ad.include?(1)\n print \"NO\"\nelsif Ad.each.with_index().any? { |v, i| v == 1 && B[i + s] == 1}\n print \"YES\"\nelse\n print \"NO\"\nend\n"}], "negative_code": [{"source_code": "n, s = gets.split.map(&:to_i)\nA = gets.split.map(&:to_i)\nB = gets.split.map(&:to_i)\nAd = A[s..n]\n\nif A[0] == 0\n print \"NO\"\nelsif A[s - 1] == 1\n print \"YES\"\nelsif B[s - 1] == 0\n print \"NO\"\nelsif !Ad.include?(1)\n print \"NO\"\nelsif Ad.each.with_index().any? { |v, i| v == 1 && B[i + s - 1] == 1 }\n print \"YES\"\nelse\n print \"NO\"\nend\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\nA = gets.split.map(&:to_i)\nB = gets.split.map(&:to_i)\nAd = A[s..n]\n\nif A[0] == 0\n print \"NO\"\nelsif A[s] == 1\n print \"YES\"\nelsif B[s] == 0\n print \"NO\"\nelsif !Ad.include?(1)\n print \"NO\"\nelsif Ad.with_index.any? { |(v, i)| v == 1 && B[i + s] == 1 }\n print \"YES\"\nelse\n print \"NO\"\nend\n"}], "src_uid": "64b597a47106d0f08fcfad155e0495c3"} {"source_code": "require 'set'\n\nn, x = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\ns = Set.new\n\na.each do |ai|\n\t\ts.add(ai) if ai > 0\nend\n\nsum = 1\ndp = Array.new(1001,false)\ndp[0] = true\n\na.each_with_index do |ai,i1|\n\ti = i1 + 1\n\tnext if s.member?(i)\n\tflag = false\n\tacc = 0\n\twhile i > 0\n\t\tsum += 1 if flag\n\t\tflag ||= i == x\n\t\tacc += 1\n\t\ti = a[i-1]\n\tend\n\tnext if flag\n\t1000.downto(0) do |j|\n\t\tnext if not dp[j]\n\t\tdp[j+acc] ||= dp[j]\n\tend\nend\n\n0.upto(1000) do |i|\n\tnext if not dp[i]\n\tputs(sum + i)\nend\n", "positive_code": [{"source_code": "require 'set'\n\nn, x = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\ns = Set.new\n\na.each do |ai|\n\t\ts.add(ai) if ai > 0\nend\n\nsum = 1\ndp = Array.new(1001,false)\ndp[0] = true\n\na.each_with_index do |ai,i1|\n\ti = i1 + 1\n\tnext if s.member?(i)\n\tflag = false\n\tacc = 0\n\twhile i > 0\n\t\tsum += 1 if flag\n\t\tflag ||= i == x\n\t\tacc += 1\n\t\ti = a[i-1]\n\tend\n\tnext if flag\n\t1000.downto(0) do |j|\n\t\tnext if not dp[j]\n\t\tdp[j+acc] ||= dp[j]\n\tend\nend\n\n0.upto(1000) do |i|\n\tnext if not dp[i]\n\tputs(sum + i)\nend\n"}, {"source_code": "#! ruby -Ku\n# -*- coding: utf-8 -*-\n# file = open(\"input.txt\")\n# total_sb = file.gets.split.map(&:to_i)\n# follow = file.gets.split.map(&:to_i) # [i]+1 follows follow[i]\ntotal_sb = gets.split.map(&:to_i)\nfollow = gets.split.map(&:to_i) # [i]+1 follows follow[i]\n\nnum_total = total_sb.shift\nsb_num = total_sb.shift\n\nchain = Struct.new(\"Chain\", :length, :check)\nchains = Array::new\nnum_total.times{chains << chain.new(1, false)}\n\n# make chains\ndef trace_chain(follow, chains, index, length)\n if follow[index] == 0\n chains[index].length = length + 1\n return length + 1\n else\n chains[index].length = trace_chain(follow, chains, follow[index]-1, length+1)\n return chains[index].length\n end\nend\n# check if SB is contained\ndef check_sb_contains(follow, chains, index, check, sb_num)\n if sb_num-1 == index\n check = true\n end\n if follow[index] == 0\n chains[index].check = check\n return check\n else\n chains[index].check = check_sb_contains(follow, chains, follow[index]-1, check, sb_num)\n return chains[index].check\n end\nend\n\nfollowed = Array::new\nnum_total.times {followed << false}\n# who is the last in each chain\nfollow.each do |x|\n if x != 0\n followed[x-1] = true\n end\nend\n\n# number of chain before smart beaver\noffset_smart_beaver = trace_chain(follow, chains, sb_num-1, 0)\n# puts offset_smart_beaver\n\n# count each length\nnum_total.times do |i|\n if followed[i] == false\n trace_chain(follow, chains, i, 0)\n check_sb_contains(follow, chains, i, false, sb_num)\n end\nend\n\n# count chains number\nchains_bin = Array::new\nnum_total.times do |i|\n if followed[i] == false && !chains[i].check\n chains_bin << chains[i].length\n end\nend\nchains_bin.sort!\n# puts chains_bin\n\n# count chain pattern by dp\ndp_table = Array::new\ndp_table << 1\nchains_bin.each do |bin|\n 1000.downto(0) do |i|\n if dp_table[i] != nil\n dp_table[i+bin] = 1\n end\n end\nend\n# puts dp_table\n\n1000.times do |i|\n if dp_table[i] != nil\n puts i + offset_smart_beaver\n end\nend\n\n"}, {"source_code": "#! ruby -Ku\n# -*- coding: utf-8 -*-\n# file = open(\"input.txt\")\n# total_sb = file.gets.split.map(&:to_i)\n# follow = file.gets.split.map(&:to_i) # [i]+1 follows follow[i]\ntotal_sb = gets.split.map(&:to_i)\nfollow = gets.split.map(&:to_i) # [i]+1 follows follow[i]\n\nnum_total = total_sb.shift\nsb_num = total_sb.shift\n\nchain = Struct.new(\"Chain\", :length, :check)\nchains = Array::new\nnum_total.times{chains << chain.new(1, false)}\n\n# make chains\ndef trace_chain(follow, chains, index, length)\n if follow[index] == 0\n chains[index].length = length + 1\n return length + 1\n else\n chains[index].length = trace_chain(follow, chains, follow[index]-1, length+1)\n return chains[index].length\n end\nend\n# check if SB is contained\ndef check_sb_contains(follow, chains, index, check, sb_num)\n if sb_num-1 == index\n check = true\n end\n if follow[index] == 0\n chains[index].check = check\n return check\n else\n chains[index].check = check_sb_contains(follow, chains, follow[index]-1, check, sb_num)\n return chains[index].check\n end\nend\n\nfollowed = Array::new\nnum_total.times {followed << false}\n# who is the last in each chain\nfollow.each do |x|\n if x != 0\n followed[x-1] = true\n end\nend\n\n# number of chain before smart beaver\noffset_smart_beaver = trace_chain(follow, chains, sb_num-1, 0)\n# puts offset_smart_beaver\n\n# count each length\nnum_total.times do |i|\n if followed[i] == false\n trace_chain(follow, chains, i, 0)\n check_sb_contains(follow, chains, i, false, sb_num)\n end\nend\n\n# count chains number\nchains_bin = Array::new\nnum_total.times do |i|\n if followed[i] == false && !chains[i].check\n chains_bin << chains[i].length\n end\nend\nchains_bin.sort!\n# puts chains_bin\n\n# count chain pattern by dp\ndp_table = Array::new\ndp_table << 1\nchains_bin.each do |bin|\n 1000.downto(0) do |i|\n if dp_table[i] != nil\n dp_table[i+bin] = 1\n end\n end\nend\n# puts dp_table\n\n1000.times do |i|\n if dp_table[i] != nil\n puts i + offset_smart_beaver\n end\nend\n\n"}], "negative_code": [], "src_uid": "5a6b97a2aa27dd2c562f73a7a8f16720"} {"source_code": "lines = IO.readlines(\"input.txt\")\n\n#n = lines[0].to_i\ncards = []\nlines[1].split(\" \").each_with_index do |val,ind|\n (cards[val.to_i] ||= []) << ind.to_i+1\nend\n\ncards.compact!\n\nFile.open(\"output.txt\", \"w\") do |fout|\n if cards.count{|p| p.size%2!=0 if p} != 0\n fout.puts(\"-1\")\n else\n cards.each do |pairs|\n pairs.each_slice(2) do |pair|\n fout.puts(\"#{pair[0]} #{pair[1]}\")\n end if pairs\n end\n end\nend\n\n", "positive_code": [{"source_code": "lines = IO.readlines(\"input.txt\")\n\nn = 0\npdi = 1\npairs = []\npaired = []\n\n n = lines[0].to_i\n i = 1\n for a in lines[1].split(\" \") do\n ai = a.to_i\n if pairs[ai] == nil\n pairs[ai] = i\n else\n paired[pdi], paired[pdi+1], pairs[ai] = pairs[ai], i, nil\n pdi += 2\n end\n i += 1\n end\n\nFile.open(\"output.txt\", \"w\") do |fout|\n if pdi != n*2+1\n fout.puts(\"-1\")\n else\n i = 1\n while i <= n*2 do\n fout.puts(\"#{paired[i]} #{paired[i+1]}\")\n i += 2\n end\n end\nend\n\n"}], "negative_code": [{"source_code": "require 'scanf'\n\nn = 0\npdi = 1\npairs = []\npaired = []\n\nFile.open(\"input.txt\", \"r\") do |fin|\n n = fin.scanf(\"%d\")[0]\n i = 1\n while i <= n*2 do\n ai = fin.scanf(\"%d\")[0]\n if pairs[ai] == nil\n pairs[ai] = i\n else\n paired[pdi], paired[pdi+1], pairs[ai] = pairs[ai], i, nil\n pdi += 2\n end\n i += 1\n end\nend\n\nFile.open(\"output.txt\", \"w\") do |fout|\n if pdi != n*2+1\n fout.puts(\"-1\")\n else\n i = 1\n while i <= n*2 do\n fout.puts(\"#{paired[i]} #{paired[i+1]}\")\n i += 2\n end\n end\nend\n\n"}, {"source_code": "fi=File.new('input.txt','r');fo=File.new('output.txt','w')\nfi.gets;a=fi.gets.strip.split\nif a.uniq.size!=a.size/2; fo.puts \"-1\"; exit end\na.map.with_index(1).to_a.sort{|x,y| x[0]<=>y[0]}.each_slice(2) do |b|; fo.puts \"#{b[0][1]} #{b[1][1]}\"; end\n\n"}], "src_uid": "0352429425782d7fe44818594eb0660c"} {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n\n__END__\nWA3: K=1\n\n", "positive_code": [{"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n\n__END__\nWA3: K=1\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n\n__END__\nWA3: K=1\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n\n__END__\nWA3: K=1\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n\n__END__\nWA3: K=1\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n\n__END__\nWA3: K=1\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n\n__END__\nWA3: K=1\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n n, m = I.gets.split.map{|_| _.to_i - 1}.sort\n O.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n\n__END__\nWA3: K=1"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n \n__END__\nWA3: K=1"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n\n__END__\nWA3: K=1\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n\n__END__\nWA3: K=1\n\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - (K == 1 ? 0 : n / (K + 1))).odd? ? :+ : :-\nend\n\n__END__\nWA3: K=1\n\n"}], "negative_code": [{"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n > 0 && n % K == 0 || (n + m).odd? ? :+ : :-\nend\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n % (K + 1) == K || (n + m - n / (K + 1)).odd? ? :+ : :-\nend\n"}, {"source_code": "I = open('input.txt')\nO = open('output.txt', 'w')\nT, K = I.gets.split.map(&:to_i)\nT.times do\n\tn, m = I.gets.split.map{|_| _.to_i - 1}.sort\n\tO.puts n > 0 && n % K == 0 || (n + m - n / K).odd? ? :+ : :-\nend\n"}], "src_uid": "1f5f5ccbdfcbe5cb2d692475f0726bfd"} {"source_code": "a = gets.strip\nb = gets.strip\n\nn = a.length\n\nif n != b.length then\n puts \"NO\"\n exit\nend\n\na0 = true\nb0 = true\nfor i in 0...n\n a0 = false unless a[i] == '0'\n b0 = false unless b[i] == '0'\n break if !a0 && !b0 \nend\n\nif a0 && !b0 then puts \"NO\"\nelsif b0 && !a0 then puts \"NO\"\nelse puts \"YES\" end", "positive_code": [{"source_code": "a = gets.chomp\nb = gets.chomp\n\nif a.length != b.length\n\tputs \"NO\"\n\texit\nend\n\nif a.include?(\"1\")!=b.include?(\"1\")\n\tputs \"NO\"\n\texit\nend \n\nputs \"YES\""}, {"source_code": "# Author : Fuad Ashraful Mehmet \n#Date: 18th April\n\na=gets.strip\nb=gets.strip\n\n\n\nidx1=a.length\nidx2=b.length\n\nn=a.length\n\nif a.length!=b.length\n puts \"NO\"\n exit\nend\n\nflag1=true\nflag2=true\n\nfor i in 0...n\n \n flag1=false unless a[i]=='0'\n flag2=false unless b[i]=='0'\n\n break if !flag1 && !flag2\n\nend\n\n\nif flag1 && flag2==false then puts \"NO\"\n\nelsif flag1==false && flag2 then puts \"NO\"\n\nelse puts \"YES\"\n\nend"}, {"source_code": "ori = gets.chomp\ntar = gets.chomp\nif ori.length == tar.length\n if ori_has = ori.include?(\"1\") ^ tar_has = tar.include?(\"1\") then puts \"NO\"\n else puts \"YES\"\n end\nelse\n puts \"NO\"\nend"}, {"source_code": "def max(a, b) a > b ? a : b end\ndef mix(a, b) a < b ? a : b end\n\n\ndef check()\n\t\ns = gets.chomp\nt = gets.chomp\n\n\treturn false if s.length != t.length\n\tt1 = s.index('1')\n\tt2 = t.index('1')\n\t\n\treturn true if (t1 && t2) \n\treturn false if (t1 || t2) \n\treturn true\nend\n\nputs check() ? \"YES\" : \"NO\"\n\n\n"}, {"source_code": "a=gets\nb=gets\nputs (a==b ? \"YES\" : (a.size!=b.size or !a.include?(?1) or !b.include?(?1)) ? \"NO\" : \"YES\")"}, {"source_code": "a = gets.strip\nb = gets.strip\n\nanswer = 'YES'\n\na_l = a.length\nb_l = b.length\nanswer = 'NO' if a_l != b_l\n\nanswer = 'NO' if a_l == 1 && b_l == 1 && a != b\n\na_1 = a[/1/]\nb_1 = b[/1/]\n\nanswer = 'NO' if !a_1 && b_1\nanswer = 'NO' if a_1 && !b_1\n\nprint answer"}, {"source_code": "a = gets.strip\nb = gets.strip\n\nanswer = 'YES'\n\na_l = a.length\nb_l = b.length\nanswer = 'NO' if a_l != b_l\n\nanswer = 'NO' if a_l == 1 && b_l == 1 && a != b\n\na_1 = a.include?('1')\nb_1 = b.include?('1')\n\nanswer = 'NO' if !a_1 && b_1\nanswer = 'NO' if a_1 && !b_1\n\nprint answer"}], "negative_code": [{"source_code": "def max(a, b) a > b ? a : b end\ndef mix(a, b) a < b ? a : b end\n\n\ndef check()\n\t\ns = gets.chomp\nt = gets.chomp\n\n\t#return false if s.length != t.length\n\tt1 = s.index('1')\n\tt2 = t.index('1')\n\t\n\treturn true if (t1 && t2) \n\treturn false if (t1 || t2) \n\treturn true\nend\n\nputs check() ? \"YES\" : \"NO\"\n\n\n"}, {"source_code": "a = gets\nb = gets\n\nif a.length != b.length\n\tputs \"NO\"\n\texit\nend\n\nif a.include?(\"1\")!=b.include?(\"0\")\n\tputs \"NO\"\n\texit\nend \n\nputs \"YES\""}], "src_uid": "113ae625e67c8ea5ab07be44c3b58a8f"} {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\nn, m = gis\n\nh = []\n1.upto(n) do |i|\n h[i] = [-1] * n.succ\n h[i][i] = 0\nend\n\nm.times do\n u, v = gis\n h[u][v] = h[v][u] = 1\nend\n\nt1 = []\nt2 = []\n1.upto(n) do |i|\n t1[i] = []\n t2[i] = []\n 1.upto(n) do |j|\n case h[i][j]\n when 1\n t1[i] << j\n when -1\n t2[i] << j\n end\n end\nend\n\nif t1[1].empty? || t2[1].empty? || t1[n].empty? || t2[n].empty?\n puts '-1'\n exit\nend\n\nl1 = [1]\nv1 = [true] + ([false] * n)\nflg = true\nct = 0\nwhile flg && !l1.empty? do\n ct += 1\n l2 = []\n l1.each do |k|\n if t1[k][-1] == n\n flg = false\n break\n end\n t1[k].each do |x|\n next if v1[x]\n v1[x] = true\n l2 << x\n end\n end\n l1 = l2\nend \n\nif flg\n puts '-1'\n exit\nend\n\n\nl1 = [1]\nv1 = [true] + ([false] * n)\nflg = true\ncb = 0\nwhile flg && !l1.empty? do\n cb += 1\n l2 = []\n l1.each do |k|\n if t2[k][-1] == n\n flg = false\n break\n end\n t2[k].each do |x|\n next if v1[x]\n v1[x] = true\n l2 << x\n end\n end\n l1 = l2\nend \n\nif flg\n puts '-1'\n exit\nend\n\nputs [ct,cb].max\n\n", "positive_code": [{"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\nn, m = gis\n\nh = []\n1.upto(n) do |i|\n h[i] = [-1] * n.succ\n h[i][i] = 0\nend\n\nm.times do\n u, v = gis\n h[u][v] = h[v][u] = 1\nend\n\nt1 = []\nt2 = []\n1.upto(n) do |i|\n t1[i] = []\n t2[i] = []\n 1.upto(n) do |j|\n case h[i][j]\n when 1\n t1[i] << j\n when -1\n t2[i] << j\n end\n end\nend\n\nif t1[1].empty? || t2[1].empty? || t1[n].empty? || t2[n].empty?\n puts '-1'\n exit\nend\n\ndef fnc(t, n)\n l1 = [1]\n v1 = [true] + ([false] * n)\n c = 0\n while !l1.empty? do\n c += 1\n l2 = []\n l1.each do |k|\n if t[k][-1] == n\n return c\n end\n t[k].each do |x|\n next if v1[x]\n v1[x] = true\n l2 << x\n end\n end\n l1 = l2\n end\n return -1\nend\n\nct = fnc t1, n\nif ct < 0\n puts '-1'\n exit\nend\n\ncb = fnc t2, n\nif cb < 0\n puts '-1'\n exit\nend\n\nputs [ct,cb].max\n\n"}], "negative_code": [{"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\n$stdout = STDERR\n\nn, m = gis\n\nh = {}\n\nm.times do\n u, v = gis\n \n h[u] = [false] * (n + 1) if !h.key? u\n h[u][v] = true\n \n h[v] = [false] * (n + 1) if !h.key? v\n h[v][u] = true\n \nend\n\nl1 = []\nl2 = []\n\n1.upto(n - 1) do |i|\n if h[n][i]\n l1 << i\n else\n l2 << i\n end\nend\n\n\np h, \"-----\"\np l1, l2, \"-----\"\n\n\nif l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\nend\n\nif !(l1 & l2).empty?\n STDOUT.puts 1\n exit\nend\n\nc = 1\n\nloop {\n c += 1\n \n l1t = {}\n l1.each do |k|\n if !h.key? k\n next\n end\n 1.upto(n - 1) do |i|\n next if i == k\n if h[k][i] \n l1t[i] = 1\n end\n end\n end\n l1 = l1t.keys\n \n l2t = {}\n l2.each do |k|\n 1.upto(n - 1) do |i|\n next if i == k\n if (!h.key?(k)) || !h[k][i]\n l2t[i] = 1\n end\n end\n end\n l2 = l2t.keys\n \n p l1, l2, \"-----\"\n\n if l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\n end\n \n if !(l1 & l2).empty?\n STDOUT.puts c\n exit\n end\n}"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\n$stdout = STDERR\n\nn, m = gis\n\nh = {}\n\nm.times do\n u, v = gis\n \n h[u] = [false] * (n + 1) if !h.key?(u)\n h[u][v] = true\n \n h[v] = [false] * (n + 1) if !h.key?(v)\n h[v][u] = true\n \nend\n\nif !h.key?(n)\n STDOUT.puts '-1'\n exit\nend\n\nl1 = []\nl2 = []\n\n1.upto(n - 1) do |i|\n if h[n][i]\n l1 << i\n else\n l2 << i\n end\nend\n\n\n#p h, \"-----\"\n#p l1, l2, \"-----\"\n\n\nif l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\nend\n\nif !((l1 & l2) & [1]).empty?\n STDOUT.puts '1'\n exit\nend\n\nc = 1\n\nmp = {}\n\nloop {\n c += 1\n\n l1t = {}\n l1.each do |k|\n if !h.key? k\n next\n end\n 1.upto(n - 1) do |i|\n next if i == k\n if h[k][i] \n l1t[i] = 1\n end\n end\n end\n l1 = l1t.keys\n \n l2t = {}\n l2.each do |k|\n 1.upto(n - 1) do |i|\n next if i == k\n if (!h.key?(k)) || (!(h[k][i]))\n l2t[i] = 1\n end\n end\n end\n l2 = l2t.keys\n\n s = l1.sort * \" \" + \",\" + l2.sort * \" \"\n if mp.key? s\n puts '-1'\n exit\n end\n mp[s] = 1 \n\n #p l1, l2, \"-----\"\n\n if l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\n end\n \n if l1t.key?(1) && l2t.key?(1)\n STDOUT.puts c\n exit\n end\n}"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\n$stdout = STDERR\n\nn, m = gis\n\nh = {}\n\nm.times do\n u, v = gis\n \n h[u] = [false] * (n + 1) if !h.key?(u)\n h[u][v] = true\n \n #h[v] = [false] * (n + 1) if !h.key?(v)\n #h[v][u] = true\n \nend\n\nif !h.key?(n)\n STDOUT.puts '-1'\n exit\nend\n\nl1 = []\nl2 = []\n\n1.upto(n) do |i|\n if h[n][i]\n l1 << i\n else\n l2 << i\n end\nend\n\n\n#p h, \"-----\"\n#p l1, l2, \"-----\"\n\n\nif l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\nend\n\nif !((l1 & l2) & [1]).empty?\n STDOUT.puts '1'\n exit\nend\n\nc = 1\n\nmp = {}\n\nloop {\n c += 1\n\n l1t = {}\n l1.each do |k|\n if !h.key? k\n next\n end\n 1.upto(n) do |i|\n next if i == k\n if h[k][i] \n l1t[i] = 1\n end\n end\n end\n l1 = l1t.keys\n \n l2t = {}\n l2.each do |k|\n 1.upto(n) do |i|\n next if i == k\n if (!h.key?(k)) || (!(h[k][i]))\n l2t[i] = 1\n end\n end\n end\n l2 = l2t.keys\n\n s = (l1.sort * \" \") + \",\" + (l2.sort * \" \")\n if mp.key? s\n puts '-1'\n exit\n end\n mp[s] = 1 \n\n #p l1, l2, \"-----\"\n\n if l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\n end\n \n if l1t.key?(1) && l2t.key?(1)\n STDOUT.puts c\n exit\n end\n}"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\n$stdout = STDERR\n\nn, m = gis\n\nh = {}\n\nm.times do\n u, v = gis\n \n h[u] = [false] * (n + 1) if !h.key? u\n h[u][v] = true\n \n h[v] = [false] * (n + 1) if !h.key? v\n h[v][u] = true\n \nend\n\nl1 = []\nl2 = []\n\n1.upto(n - 1) do |i|\n if h[n][i]\n l1 << i\n else\n l2 << i\n end\nend\n\n\np h, \"-----\"\np l1, l2, \"-----\"\n\n\nif l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\nend\n\nif !(l1 & l2).empty?\n STDOUT.puts 1\n exit\nend\n\nc = 1\n\nloop {\n c += 1\n \n l1t = {}\n l1.each do |k|\n if !h.key? k\n next\n end\n 1.upto(n) do |i|\n next if i == k\n if h[k][i] \n l1t[i] = 1\n end\n end\n end\n l1 = l1t.keys\n \n l2t = {}\n l2.each do |k|\n 1.upto(n) do |i|\n next if i == k\n if (!h.key?(k)) || !h[k][i]\n l2t[i] = 1\n end\n end\n end\n l2 = l2t.keys\n \n p l1, l2, \"-----\"\n\n if l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\n end\n \n if !((l1 & l2) - [n]).empty?\n STDOUT.puts c\n exit\n end\n}"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\n$stdout = STDERR\n\nn, m = gis\n\nh = {}\n\nm.times do\n u, v = gis\n \n h[u] = [false] * (n + 1) if !h.key?(u)\n h[u][v] = true\n \n h[v] = [false] * (n + 1) if !h.key?(v)\n h[v][u] = true\n \nend\n\nif !h.key?(n)\n STDOUT.puts '-1'\n exit\nend\n\nl1 = []\nl2 = []\n\n1.upto(n - 1) do |i|\n if h[n][i]\n l1 << i\n else\n l2 << i\n end\nend\n\n\n#p h, \"-----\"\n#p l1, l2, \"-----\"\n\n\nif l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\nend\n\nif !((l1 & l2) & [1]).empty?\n STDOUT.puts '1'\n exit\nend\n\nc = 1\n\nmp = {}\n\nloop {\n c += 1\n\n l1t = {}\n l1.each do |k|\n if !h.key? k\n next\n end\n 1.upto(n) do |i|\n next if i == k\n if h[k][i] \n l1t[i] = 1\n end\n end\n end\n l1 = l1t.keys\n \n l2t = {}\n l2.each do |k|\n 1.upto(n) do |i|\n next if i == k\n if (!h.key?(k)) || (!(h[k][i]))\n l2t[i] = 1\n end\n end\n end\n l2 = l2t.keys\n\n s = l1.sort * \" \" + \",\" + l2.sort * \" \"\n if mp.key? s\n puts '-1'\n exit\n end\n mp[s] = 1 \n\n #p l1, l2, \"-----\"\n\n if l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\n end\n \n if l1t.key?(1) && l2t.key?(1)\n STDOUT.puts c\n exit\n end\n}"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\n$stdout = STDERR\n\nn, m = gis\n\nh = {}\n\nm.times do\n u, v = gis\n \n #h[u] = [false] * (n + 1) if !h.key?(u)\n #h[u][v] = true\n \n h[v] = [false] * (n + 1) if !h.key?(v)\n h[v][u] = true\n \nend\n\nif !h.key?(n)\n STDOUT.puts '-1'\n exit\nend\n\nl1 = []\nl2 = []\n\n1.upto(n) do |i|\n if h[n][i]\n l1 << i\n else\n l2 << i\n end\nend\n\n\n#p h, \"-----\"\n#p l1, l2, \"-----\"\n\n\nif l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\nend\n\nif !((l1 & l2) & [1]).empty?\n STDOUT.puts '1'\n exit\nend\n\nc = 1\n\nmp = {}\n\nloop {\n c += 1\n\n l1t = {}\n l1.each do |k|\n if !h.key? k\n next\n end\n 1.upto(n) do |i|\n next if i == k\n if h[k][i] \n l1t[i] = 1\n end\n end\n end\n l1 = l1t.keys\n \n l2t = {}\n l2.each do |k|\n 1.upto(n) do |i|\n next if i == k\n if (!h.key?(k)) || (!(h[k][i]))\n l2t[i] = 1\n end\n end\n end\n l2 = l2t.keys\n\n s = (l1.sort * \" \") + \",\" + (l2.sort * \" \")\n if mp.key? s\n puts '-1'\n exit\n end\n mp[s] = 1 \n\n #p l1, l2, \"-----\"\n\n if l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\n end\n \n if l1t.key?(1) && l2t.key?(1)\n STDOUT.puts c\n exit\n end\n}"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ndef gi(); gets.to_i; end\ndef gis(); gets.chomp.split.map(&:to_i); end\n\n$stdout = STDERR\n\nn, m = gis\n\nh = {}\n\nm.times do\n u, v = gis\n \n h[u] = [false] * (n + 1) if !h.key?(u)\n h[u][v] = true\n \n h[v] = [false] * (n + 1) if !h.key?(v)\n h[v][u] = true\n \nend\n\nif !h.key?(n)\n STDOUT.puts '-1'\n exit\nend\n\nl1 = []\nl2 = []\n\n1.upto(n) do |i|\n if h[n][i]\n l1 << i\n else\n l2 << i\n end\nend\n\n\n#p h, \"-----\"\n#p l1, l2, \"-----\"\n\n\nif l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\nend\n\nif !((l1 & l2) & [1]).empty?\n STDOUT.puts '1'\n exit\nend\n\nc = 1\n\nmp = {}\n\nloop {\n c += 1\n\n l1t = {}\n l1.each do |k|\n if !h.key? k\n next\n end\n 1.upto(n) do |i|\n next if i == k\n if h[k][i] \n l1t[i] = 1\n end\n end\n end\n l1 = l1t.keys\n \n l2t = {}\n l2.each do |k|\n 1.upto(n) do |i|\n next if i == k\n if (!h.key?(k)) || (!(h[k][i]))\n l2t[i] = 1\n end\n end\n end\n l2 = l2t.keys\n\n s = (l1.sort * \" \") + \",\" + (l2.sort * \" \")\n if mp.key? s\n puts '-1'\n exit\n end\n mp[s] = 1 \n\n #p l1, l2, \"-----\"\n\n if l1.empty? || l2.empty?\n STDOUT.puts '-1'\n exit\n end\n \n if l1t.key?(1) && l2t.key?(1)\n STDOUT.puts c\n exit\n end\n}"}], "src_uid": "fbfc333ad4b0a750f654a00be84aea67"} {"source_code": "class Cave\n attr_accessor :count\n attr_accessor :max\n def initialize()\n a = gets.split.map {|i| i.to_i}\n a = a[1...a.length]\n a = a.map.with_index do |item, idx|\n item - idx\n end\n @count = a.length\n @max = a.max\n end\n def <=>(other)\n if other.is_a?(Cave) == false\n return nil\n end\n if max < other.max\n return -1\n elsif max > other.max\n return 1\n else\n return other.count <=> count\n end\n end\nend\ndef solve\n n = gets.to_i\n a = (1..n).map { |xx| Cave.new }\n a.sort!\n #p a\n\n res, power, pcount = 0, 0, 0\n for i in a\n if i.max > power\n power = i.max\n res = i.max + 1 - pcount\n end\n power += i.count\n pcount += i.count\n end\n puts res\n #puts \"res: #{res}\"\nend\nt = gets.to_i\nwhile t > 0\n t -= 1\n solve\nend\n", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n\nn = gets.to_i\ncaves = Array.new(n) do\n gets.split.map!(&:to_i).drop(1)\nend\n\ndata = caves.map do |a|\n k = a.size\n req = a.map.with_index { |ai, i| ai - i + 1 }.max\n [req, -k]\nend.sort!\n\npw = 0\ndiff = 0\ndata.each do |req, kk|\n if pw < req\n diff += req - pw\n pw = req\n end\n pw += -kk\nend\n\np diff\n\nend\n"}], "negative_code": [{"source_code": "class Cave\n attr_accessor :count\n attr_accessor :max\n def initialize()\n a = gets.split.map {|i| i.to_i}\n a = a[1...a.length]\n a = a.map.with_index do |item, idx|\n item - idx\n end\n @count = a.length\n @max = a.max\n end\n def <=>(other)\n if other.is_a?(Cave) == false\n return nil\n end\n if max < other.max\n return -1\n elsif max > other.max\n return 1\n else\n return other.count <=> count\n end\n end\nend\ndef solve\n n = gets.to_i\n a = (1..n).map { |xx| Cave.new }\n a.sort!\n p a\n\n res, power, pcount = 0, 0, 0\n for i in a\n if i.max > power\n power = i.max\n res = i.max + 1 - pcount\n end\n power += i.count\n pcount += i.count\n end\n puts \"res: #{res}\"\nend\nt = gets.to_i\nwhile t > 0\n t -= 1\n solve\nend\n"}], "src_uid": "88488ff074bc25a6cf925c8a07a1d8c6"} {"source_code": "n,k = gets.strip.split.map(&:to_i)\nary = gets.strip.split.map(&:to_i)\nary.sort!\n\nsub=0\nidx=0\nk.times.each do |i|\n while idx= n\n v = 0\n else\n v = (ary[idx]-sub)\n sub += v\n end\n puts v\nend", "positive_code": [{"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\na.sort!\nj = a.index{|x| x > 0}\nif j == nil\n j = a.size\nend\npj = 0\nk.times do\n if j == a.size\n puts 0\n next\n end\n puts(a[j] - pj)\n pj += (a[j] - pj)\n \n i = j + 1\n i += 1 while i < a.size && a[i] == a[j]\n j = i\nend\n"}, {"source_code": "nk = gets.chomp.split(\" \").map(&:to_i)\narr = gets.chomp.split(\" \").map(&:to_i)\nn = nk[0]\nk = nk[1]\ntosubtr = 0\n\narr.sort!\n#p arr\n\ni = 0\nk.times do\n\n if i >= n\n puts 0\n else\n x = arr[i]\n\n while ((x-tosubtr)==0 and i= n\n puts 0\n else\n min = arr[index] - sbst\n puts min\n sbst += min\n for i in index..(n - 1) do\n if arr[i] - sbst > 0 \n index = i\n break\n else i == n - 1\n index = n\n end\n end\n end\nend\n"}], "negative_code": [{"source_code": "n,k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort\ni = 0\nsum = 0\nk.times do |j|\n while i < n && a[i]-sum <= 0\n i += 1\n #break if i == n\n end\n if i == n\n puts 0\n else\n puts a[i]-sum\n sum += a[i]\n end\nend"}, {"source_code": "nk = gets.chomp.split(\" \").map(&:to_i)\narr = gets.chomp.split(\" \").map(&:to_i)\nn = nk[0]\nk = nk[1]\ntosubtr = 0\n\narr.sort!\n#p arr\n\ni = 0\nk.times do\n\n if i >= n\n puts 0\n else\n x = arr[i]\n\n while ((x-tosubtr)==0 and i []}\n\nmouses_n.times do |n|\n price, type = gets.split\n mouses_prices[type.to_sym] << price.to_i\nend\n\nmouses_prices[:USB].sort!\nmouses_prices[:'PS/2'].sort!\n\ntotal_mouse = 0\ntotal_price = 0\n\nusb.times do\n break if mouses_prices[:USB].empty?\n total_price += mouses_prices[:USB].shift\n total_mouse += 1\nend\n\nps2.times do\n break if mouses_prices[:'PS/2'].empty?\n total_price += mouses_prices[:'PS/2'].shift\n total_mouse += 1\nend\n\nusb_ps2_remainings = mouses_prices[:USB] + mouses_prices[:'PS/2']\nusb_ps2_remainings.sort!\n\nusb_ps2.times do\n break if usb_ps2_remainings.empty?\n total_price += usb_ps2_remainings.shift\n total_mouse += 1\nend\n\nputs \"#{total_mouse} #{total_price}\"\n", "positive_code": [{"source_code": "a,b,c=gets.split.map(&:to_i)\nr=s=0\nH=Hash.new{|h,k|h[k]=[]}\ngets.to_i.times{\n\tx,y=gets.split\n\tH[y]<H['USB'].size\nr+=a\ns+=H['USB'].shift(a).reduce(0,:+)\nH['PS/2'].sort!\nb=H['PS/2'].size if b>H['PS/2'].size\nr+=b\ns+=H['PS/2'].shift(b).reduce(0,:+)\nq=(H['USB']+H['PS/2']).sort\nc=q.size if c>q.size\nr+=c\ns+=q.shift(c).reduce(0,:+)\nputs '%d %d'%[r,s]"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\n\nusb, ps2, usb_ps2 = gets.split.map {|v| v.to_i}\nmouses_n = gets.to_i\n\nmouses_prices = { USB: [],\n :'PS/2' => []}\n\nmouses_n.times do |n|\n price, type = gets.split\n mouses_prices[type.to_sym] << price.to_i\nend\n\nmouses_prices[:USB].sort!\nmouses_prices[:'PS/2'].sort!\n\ntotal_mouse = 0\ntotal_price = 0\n\nusb.times do\n break if mouses_prices[:USB].empty?\n total_price += mouses_prices[:USB].shift\n total_mouse += 1\nend\n\nps2.times do\n break if mouses_prices[:'PS/2'].empty?\n total_price += mouses_prices[:'PS/2'].shift\n total_mouse += 1\nend\n\nusb_ps2.times do\n if !mouses_prices[:USB].empty?\n total_price += mouses_prices[:USB].shift\n total_mouse += 1\n next\n end\n if !mouses_prices[:'PS/2'].empty?\n total_price += mouses_prices[:'PS/2'].shift\n total_mouse += 1\n next\n end\n break\nend\n\nputs \"#{total_mouse} #{total_price}\"\n"}], "src_uid": "3d6151b549bd52f95ab7fdb972e6fb98"} {"source_code": "t = gets.chomp.to_i\n\nresults = []\n\n(1..t).each do |_t|\n\n a = gets.chomp.split(' ').map{|a| a.to_i}\n \n a.sort!.reverse!\n\n a,b = a\n\n if a > 2*b\n results[_t] = b\n else\n results[_t] = (a + b) /3\n end \n\nend\n\nresults.each do |res|\n puts res\nend\n", "positive_code": [{"source_code": "def solve(a, b)\n min = [a, b].min\n max = [a, b].max\n [(max + min) /3, min].min\nend\n\namount = gets.chomp.to_i\namount.times do\n input = gets.chomp.split(\" \")\n puts solve(input[0].to_i, input[1].to_i)\nend\n"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\n\nresults = []\n\n(1..t).each do |_t|\n\n a = gets.chomp.split(' ').map{|a| a.to_i}\n \n a.sort!.reverse!\n\n if a[0] % 2 == 0\n if a[1] - (a[0]/2 - 1) >= 4\n results[_t] = a[0] / 2 + 1\n else \n results[_t] = [a[0]/2, a[1]].min\n end\n else\n x = a[1] - a[0] / 2\n\n if x > 1\n results[_t] =a[0]/2 + 1\n else\n results[_t] = [a[0]/2, a[1]].min\n end\n end\n\nend\n\nresults.each do |res|\n puts res\nend\n"}, {"source_code": "def compute(a,b,x)\n return b if b <= x\n\n a -= 2*x\n b -= x\n \n return x if [a,b].max < 2\n\n return x if [a,b].min < 1\n\n return x + 1 if [a,b].max < 4\n\n return x + 1 if [a,b].min < 2 \n\n x + 2\nend\n\nt = gets.chomp.to_i\n\nresults = []\n\n(1..t).each do |_t|\n\n a = gets.chomp.split(' ').map{|a| a.to_i}\n \n a.sort!.reverse!\n\n x = a[0] / 2\n\n results[_t] = [compute(a[0], a[1], x), compute(a[0], a[1], x-1)].max\n\nend\n\nresults.each do |res|\n puts res\nend\n"}], "src_uid": "8bbec86e427e26158393bbfbf1a067fe"} {"source_code": "$stdout.sync = true\nwhile line=gets\n puts \"NO\"\nend\n", "positive_code": [{"source_code": "$stdout.sync = true\r\n\r\nputs \"NO\" while gets\r\n"}, {"source_code": "while line = gets\r\n puts \"NO\"\r\n STDOUT.flush\r\nend"}], "negative_code": [], "src_uid": "57b62c485669809c0b59afd6613f901c"} {"source_code": "s = gets\nm = gets.to_i\nwhile m>0\n l,r,k = gets.split(\" \").map(&:to_i)\n new_s = s[l-1,(r-l+1)]\n pre = s[0,l-1]\n post = s[r,s.size]\n k = k%(r-l+1)\n ass = new_s[new_s.size-k,new_s.size]\n arr = ass + new_s.chomp(ass)\n s = pre + arr + post\n m-=1\nend\nputs s\n", "positive_code": [{"source_code": "s = gets.to_s\nm = gets.to_i\n\nm.times do\n l, r, k = gets.split(' ').map{ |x| x.to_i }\n l -= 1\n r -= 1\n k = k % (r-l+1)\n s[l..r] = s[r-k+1..r] + s[l..r-k] if l != r\nend\n\nputs s"}, {"source_code": "# c598-B\n\n\ndef process_query(str, l,r,k)\n\tn = str.size\n\ta = l-1\n\tb = r - k % (r-a)\n\tc = r\n\tstr[0,a] + str[b, c-b] + str[a, b-a] + str[c, n-c]\nend\n\nstr = gets\ngets.to_i.times do\n\tl, r, k = gets.split.map {|x| Integer(x)}\n\tstr = process_query(str, l, r, k)\nend\nputs str\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\ns = gets.strip # < 10000\nm = gets.to_i\n\nm.times.map do\n l_i, r_i, k_i = gets.split(' ').map(&:to_i)\n l_i -= 1\n r_i -= 1\n\n window_len = r_i - l_i + 1\n k_i = k_i.modulo(window_len)\n\n slice_len = window_len - k_i\n substr = s.slice!(l_i, slice_len)\n #p s + ' ' + substr\n insertIdx = l_i+k_i\n #p insertIdx\n s.insert(insertIdx, substr)\n #p s\nend\n\nputs s\n"}, {"source_code": "def rotate(s, l, r, k)\n len = r - l + 1\n k = k % len\n result = ''\n result += s[0..l-2] if (l - 2 >= 0)\n result += s[r-k..r-1] if (r-k <= r-1)\n result += s[l-1..r-1-k] if (l-1 <= r-1-k)\n result += s[r..-1] if (r < s.length)\nend\n\ns = gets\nm = gets.to_i\n(1..m).each do\n (l, r, k) = gets.split(' ').map(&:to_i)\n s = rotate(s, l, r, k)\nend\n\nputs s\n"}, {"source_code": "s = gets.chomp.split(\"\")\nm = gets.chomp.to_i\nm.times do\n l, r, k = gets.chomp.split(\" \").map(&:to_i)\n kk = k % (r - l + 1)\n sr = []\n kk.times do\n sr.unshift(s.slice!(r-1))\n r -= 1\n end\n s.insert(l-1, sr).flatten!\nend\nputs s.join(\"\")\n"}, {"source_code": "#!/usr/bin/ruby\n\nstr = gets.strip()\nlen = gets.to_i\nfor iter in 0..len - 1\n l, r, k = gets.split(' ')\n l = l.to_i\n r = r.to_i\n k = k.to_i\n substr = str[l-1..r-1]\n k %= substr.length\n substr = substr[-k, k] + substr[0, substr.length-k]\n substr = substr + str[r..-1]\n if l >= 2\n str = str[0..l-2] + substr\n else\n str = substr\n end\nend\nputs str\n"}, {"source_code": "s = gets\nm = gets.to_i\n\ndef shift(s, step)\n return s if step == 0\n s[-step..-1] + s[0..s.size-step-1]\nend\n\nm.times do\n l,r,k = gets.split.map(&:to_i)\n l-=1\n r-=1\n k %= r + 1 - l\n s[l..r] = shift(s[l..r], k)\nend\nputs(s)"}, {"source_code": "s = gets.chomp.split('')\nm = gets.to_i\nfor i in 0..m-1\n\tl, r, k = gets.split(' ').map{|i| i.to_i}\n\tl -= 1\n\tr -= 1\n\ts = (l > 0 ? s[0..l-1] : []) + s[l..r].rotate(-k) + s[r+1..s.length-1]\nend\n\nputs s.reduce{|a, b| a << b}"}, {"source_code": "str = gets.chomp\nm = gets.chomp.to_i\nfor i in 1..m do\n l, r, k = gets.split.map(&:to_i)\n k = k % (r - l + 1)\n str[l-1..r-1] = str[r-k..r-1] + str[l-1..r-1-k]\nend\nputs str\n"}], "negative_code": [{"source_code": "str = gets.chomp\nm = gets.chomp.to_i\nfor i in 1..m do\n l, r, k = gets.split.map(&:to_i)\n for n in 1..k do\n newStr = \"\"\n newStr << str[r-1]\n newStr << str[l-1..r-2]\n str[l-1..r-1] = newStr\n end\nend\nputs str\n"}, {"source_code": "s = gets.to_s\nm = gets.to_i\n\nm.times do\n l, r, k = gets.split(' ').map{ |x| x.to_i }\n l -= 1\n r -= 1\n s[l..r] = s[r-k+1..r] + s[l..r-k] if l != r\nend\n\nputs s"}, {"source_code": "s = gets.to_s\nm = gets.to_i\n\nm.times do\n l, r, k = gets.split(' ').map{ |x| x.to_i }\n l -= 1\n r -= 1\n s[l..r] = s[r-k+1..r] + s[l..r-k] \nend\n\nputs s"}, {"source_code": "def rotate(s, l, r, k)\n len = r - l + 1\n k = k % len\n result = ''\n result += s[0..l-2] if (l - 2 > 0)\n result += s[r-k..r-1]\n result += s[l-1..r-1-k]\n result += s[r..-1] if (r < s.length)\n\nend\n\ns = gets\nm = gets.to_i\n(1..m).each do\n (l, r, k) = gets.split(' ').map(&:to_i)\n s = rotate(s, l, r, k)\nend\n\nputs s\n"}, {"source_code": "s = gets\nm = gets.to_i\n\ndef shift(s, step)\n return s if step == 0\n s[step..-1] + s[0..step-1]\nend\n\nm.times do\n l,r,k = gets.split.map(&:to_i)\n k %= r + 1 - l\n s[l..r] = shift(s[l..r], k)\nend\nputs(s)"}, {"source_code": "s = gets\nm = gets.to_i\n\ndef shift(s, step)\n return s if step == 0\n s[0..step-1] + s[step..-1]\nend\n\nm.times do\n l,r,k = gets.split.map(&:to_i)\n l-=1\n r-=1\n k %= r + 1 - l\n s[l..r] = shift(s[l..r], k)\nend\nputs(s)"}, {"source_code": "s = gets\nm = gets.to_i\n\ndef shift(s, step)\n return s if step == 0\n s[step..-1] + s[0..step-1]\nend\n\nm.times do\n l,r,k = gets.split.map(&:to_i)\n l-=1\n r-=1\n k %= r + 1 - l\n s[l..r] = shift(s[l..r], k)\nend\nputs(s)"}], "src_uid": "501b60c4dc465b8a60fd567b208ea1e3"} {"source_code": "require 'set'\n\nn, m = gets.chomp.split(' ').map(&:to_i)\nalreadyHas = gets.chomp.split(' ').map(&:to_i).to_set\n\ncurrent = 1\nans = []\n\nuntil m - current < 0\n if alreadyHas.include? current\n current += 1\n next\n else\n ans << current\n m -= current\n current += 1\n end\nend\n\nputs ans.length\n\nans.each do |a|\n print \"#{a} \"\nend\n\nputs ''", "positive_code": [{"source_code": "#!/usr/bin/ruby\nn,m=gets.split.map(&:to_i)\nh={}\ngets.split.each{|e|h[e.to_i]=1}\nr=[]\n(1..1/0.0).each{|i|\n\tif !h[i]\n\t\tbreak if m m\n next if hash.key?(idx)\n\n m -= idx\n values << idx\nend\nputs values.length\nputs values.join(' ')\n"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\nhash = {}.tap do |h|\n gets.chomp.split.map(&:to_i).each { |idx| h[idx] = true }\n end\n\nvalues = []\nsum = 0\n(1..(10**9)).each do |idx|\n next if hash.key?(idx)\n break if sum + idx > m\n\n sum += idx\n values << idx\nend\nputs values.length\nputs values.join(' ')\n"}, {"source_code": "n, m = readline.split(' ').collect(&:to_i)\nh = Hash[readline.split(' ').collect(&:to_i).collect{|num| [num, true]}]\nres = []\nct = 0\nleft = m\n\n1.upto(m) do |item|\n if item > left\n break\n end\n if !h.has_key?(item)\n res.push(item)\n left -= item\n ct += 1\n end\nend\n\nputs ct\nres.each_with_index do |item, ind|\n if ind != 0\n print \" \"\n end\n print item\nend\nputs \"\"\n"}, {"source_code": "n, m = readline.split(' ').collect(&:to_i)\nh = Hash[readline.split(' ').collect(&:to_i).collect{|num| [num, true]}]\nres = []\nct = 0\nleft = m\n\n1.upto(m) do |item|\n if item > left\n break\n end\n if !h.has_key?(item)\n res.insert(-1, item)\n left -= item\n ct += 1\n end\nend\n\nputs ct\nres.each_with_index do |item, ind|\n if ind != 0\n print \" \"\n end\n print item\nend\nputs \"\"\n"}, {"source_code": "a=gets.chomp.split(\" \")\ncost=a[1].to_i\nb=gets.chomp.split(\" \").map {|i| i.to_i}\nb.sort!\nans=0\nar=[]\ni=1\nj=0\nloop do\n\nif i!=b[j]\ncost-=i\nif cost>=0\nans+=1\nar << i\nelse\nbreak\nend\n\nelse\nj+=1\nend\n\ni+=1\nbreak if i == 1000000000\n\nend\n\nputs \"#{ans}\"\nputs ar.join(\" \")\n"}, {"source_code": "a=gets.chomp.split(\" \")\ncost=a[1].to_i\nb=gets.chomp.split(\" \").map {|i| i.to_i}\nb.sort!\nans=0\nar=[]\ni=1\nj=0\nloop do\n\nif i!=b[j]\ncost-=i\nif cost>=0\nans+=1\nar << i\nelse\nbreak\nend\n\nelse\nj+=1\nend\n\ni+=1\nbreak if i == 1000000000\n\nend\n\nputs \"#{ans}\"\nputs ar.join(\" \")\n"}, {"source_code": "a=gets.chomp.split(\" \")\ncost=a[1].to_i\nb=gets.chomp.split(\" \").map {|i| i.to_i}\nb.sort!\nans=0\nar=[]\ni=1\nj=0\nloop do\n\nif i!=b[j]\ncost-=i\nif cost>=0\nans+=1\nar << i\nelse\nbreak\nend\n\nelse\nj+=1\nend\n\ni+=1\nbreak if i == 1000000000\n\nend\n\nputs \"#{ans}\"\nputs ar.join(\" \")"}, {"source_code": "buf = gets.split(' ')\nn,m=buf[0].to_i, buf[1].to_i\nbuf = gets.split(' ')\nhash = Hash.new\nbuf.each do |x|\n\thash[x.to_i] = 1\nend\nans = Array.new\nfor i in 1..1000000\n\tbreak if i>m\n\tif !hash[i]\n\t\tm-=i\n\t\tans<m\n\tif !hash[i]\n\t\tm-=i\n\t\tans< b[0]\n counters = b.select{|r| r == b[n-1]}.size\n xounterz = b.select{|r| r == b[0]}.size\n puts (b[n-1]-b[0]).to_s + \" \" + (counters*xounterz).to_s\nelse\n puts \"0\" + ' ' + (b.size * (b.size - 1)/2).to_s\nend"}, {"source_code": "#!/usr/bin/ruby\n\nn = $stdin.readline.to_i\nb = $stdin.readline.split.map(&:to_i)\n\nb.sort!\n\na1 = b[0]\na2 = b[b.length-1]\n\nc1 = 0\nc2 = 0\n\nb.each { |x|\n if x == a1\n c1 += 1\n end }\n\nb.each { |x|\n if x == a2\n c2 += 1\n end }\n\nif a1 == a2\n ans = b.length * (b.length - 1) / 2\n puts \"0 #{ans}\"\nelse\n puts \"#{a2 - a1} #{c1 * c2}\"\nend\n\n\n"}, {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\nl, r = x.max, x.min\nif l > r\n puts (l - r).to_s + \" \" + (x.select{|i| i == l}.size * x.select{|i| i == r}.size).to_s\nelse\n puts \"0\" + \" \" + (x.size * (x.size - 1) / 2).to_s\nend"}, {"source_code": "\nn = gets.to_i\ntab = gets.split.map(&:to_i)\n\nh, l = tab.max, tab.min\n\nif h > l\n puts (h-l).to_s + \" \" + \n (tab.select{|x| x == h}.size * tab.select{|x| x == l}.size).to_s\nelse\n puts \"0 \" + (tab.size * (tab.size-1)/2).to_s\nend\n\n\n"}, {"source_code": "n, b = gets.to_i, gets.split.map { |x| x.to_i }.sort\nmax_d = b.last - b.first\narr = Hash.new(0)\nb.each_with_index { |x| arr[x] += 1 }\nif arr.size == 1\n print max_d, \" \", arr[b.last] * (arr[b.last] - 1) / 2\nelse\n print max_d, \" \", arr[b.last] * arr[b.first]\nend\n"}, {"source_code": "n = gets.to_i\nb = gets.split.map(&:to_i)\nx = [1000000000,0]\ny = [0,0]\nb.each do |i|\n\tif i == x[0]\n\t\tx[1] += 1\n\telsif i < x[0]\n\t\tx[0] = i\n\t\tx[1] = 1\n\tend\n\tif i == y[0]\n\t\ty[1] += 1\n\telsif i > y[0]\n\t\ty[0] = i\n\t\ty[1] = 1\n\tend\nend\nif y[0] == x[0]\n\tprint 0,' ',x[1] * (x[1] - 1) / 2\nelse\n\tprint y[0] - x[0],' ',x[1]*y[1]\nend"}, {"source_code": "n = gets.to_i\nflowers = Hash.new(0)\n\nmin, max = gets.chomp.split.map { |value| value.to_i }.each { |value| flowers[value] += 1 }.sort.minmax\n\ndif = max - min\npath = 0\n\nif dif != 0\n flowers.each { |key, value| path += value * flowers[key - dif] }\nelse\n path = n * (n - 1) / 2\nend\n\nputs \"#{dif} #{path}\""}, {"source_code": "n = gets.to_i\nflowers = Hash.new(0)\n\nmin, max = gets.chomp!.split.map! { |value| value.to_i }.each { |value| flowers[value] += 1 }.sort!.minmax\n\ndif = max - min\npath = 0\n\nif dif != 0\n flowers.each { |key, value| path += value * flowers[key - dif] }\nelse\n path = n * (n - 1) / 2\nend\n\nputs \"#{dif} #{path}\""}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nmin, min_counter = 10**9, 0\nmax, max_counter = 0, 0\ngets.split.each { |i| \n i = i.to_i\n if i < min\n min = i\n min_counter = 0\n end\n\n if i == min\n min_counter += 1\n end\n\n if i > max\n max = i\n max_counter = 0\n end\n\n if i == max\n max_counter += 1\n end\n}\n\nif max != min\n puts \"#{max - min} #{min_counter * max_counter}\"\nelse\n # n C 2\n # -> n! / (2! * (n-2)!)\n # -> (n * (n -1)) / 2!\n # -> n * (n - 1) / 2\n combination = max_counter * (max_counter - 1) / 2\n puts \"#{max - min} #{combination}\"\nend\n\n# pair of two flowers\n# first: maximum beauty difference\n# second: how many ways to create the diff?\n"}, {"source_code": "n = Integer(gets)\nnums = gets.chomp.split\nb = Array.new\nfor i in 0...n\n b[i] = Integer(nums[i])\nend\n\nb.sort!\nmin = Array.new\nmax = Array.new\nmin[0] = b[0]\nmax[0] = b[n-1]\n\ngap = b[n-1] - b[0]\nfor i in 0...n-1\n if b[i+1] == b[0]\n min.push(b[i+1])\n end\n if b[n-i-2] == b[n-1]\n max.push(b[n-i-2])\n end\nend\n\nif gap != 0\n print gap , \" \" , min.length * max.length\nelse\n if n != 2\n ways = n * (n-1) / 2\n print gap , \" \" , ways\n else\n print gap, \" \" , \"1\"\n end\nend\n"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\nn = gets.to_i\na = read_ints\n_max = a.max\n_min = a.min\nprint _max-_min\na1 = 0\na2 = 0\ni=0\nn.times do\n if(a[i] == _max)\n a1+=1\n elsif (a[i] == _min)\n a2+=1\n end\n i+=1\nend\nprint ' '\nif(_max == _min)\n puts a1 * (a1-1) / 2\nelse\nputs a1 * a2\nend"}, {"source_code": "n = gets.to_i\nb = {}\nh = Hash.new { |h, k| h[k] = 0 }\na = gets.split(/\\s+/).map {|q| r = q.to_i; h[r]+=1; r}\n\nr = 0\ndiff = a.max - a.min\nif diff > 0\n a.each {|q| r += h[q + diff] }\nelse\n h.each {|k,v| r += v*(v-1)/2 if v > 1 }\nend\n\nputs \"#{diff} #{r}\"\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\n\nn = $stdin.readline.to_i\nb = $stdin.readline.split.map(&:to_i)\n\nb.sort!\n\na1 = b[0]\na2 = b[b.length-1]\n\nc1 = 0\nc2 = 0\n\nb.each { |x|\n if x == a1\n c1 += 1\n end }\n\nb.each { |x|\n if x == a2\n c2 += 1\n end }\n\nif a1 == a2\n c1 = 0\nend\n\nputs \"#{a2 - a1} #{c1 * c2}\"\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = $stdin.readline.to_i\nb = $stdin.readline.split.map(&:to_i)\n\nb.sort!\n\na1 = b[0]\na2 = b[b.length-1]\n\nc1 = 0\nc2 = 0\n\nb.each { |x|\n if x == a1\n c1 += 1\n end }\n\nb.each { |x|\n if x == a2\n c2 += 1\n end }\n\nputs \"#{a2 - a1} #{c1 * c2}\"\n"}, {"source_code": "n = gets.to_i\nb = gets.split.map{|r| r.to_i}.sort\n\ncounters = b.select{|r| r == b[n-1]}.size\nxounterz = b.select{|r| r == b[0]}.size\n\nputs (b[n-1]-b[0]).to_s + \" \" + (counters*xounterz).to_s"}, {"source_code": "n = gets.to_i\nb = gets.split.map{|r| r.to_i}.sort\n\ncounters = 1\nxounterz = 1\nfor i in 1..n-2\n if b[i] == b[0]\n counters+=1\n elsif b[i] == b[n-1]\n xounterz+=1\n end\nend\n\nputs b[n-1]-b[0] \nputs counters*xounterz\n"}, {"source_code": "n = gets.to_i\nb = gets.split.map{|r| r.to_i}.sort\n\ncounters = 1\nxounterz = 1\nfor i in 1..n-2\n if b[i] == b[0]\n counters+=1\n elsif b[i] == b[n-1]\n xounterz+=1\n end\nend\n\nmax = [b[n-1]-b[0], counters*xounterz]\nputs max\n"}, {"source_code": "n = gets.to_i\nb = gets.split.map{|r| r.to_i}.sort\n\ncounters = 1\nxounterz = 1\nfor i in 1..n-2\n if b[i] == b[0]\n counters+=1\n elsif b[i] == b[n-1]\n xounterz+=1\n end\nend\n\nputs (b[n-1]-b[0]).to_s + \" \" + (counters*xounterz).to_s"}, {"source_code": "n = gets.to_i\nb = gets.split.map{|r| r.to_i}.sort\n\nif b[n-1] > b[0]\n counters = b.select{|r| r == b[n-1]}.size\n xounterz = b.select{|r| r == b[0]}.size\n puts (b[n-1]-b[0]).to_s + \" \" + (counters*xounterz).to_s\nelse\n puts \"0 1\" \nend"}, {"source_code": "n = gets.to_i\nb = gets.split.map{|r| r.to_i}.sort\n\ncounters = 1\nxounterz = 1\nfor i in 1..n-2\n if b[i] == b[0]\n counters+=1\n elsif b[i] == b[n-1]\n xounterz+=1\n end\nend\n\nmax = [b[n-1]-b[0], counters*xounterz]\nmax\n"}, {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\nl, r = x.max, x.min\nif l > r\n puts (l - r).to_s + \" \" + (x.select{|i| i == l}.size * x.select{|i| i == r}.size).to_s\nelse\n puts \"0\" + (x.size * (x.size - 1) / 2).to_s\nend"}, {"source_code": "n, b = gets.to_i, gets.split.map { |x| x.to_i }.sort\nmax_d = b.last - b.first\nam = 0\nb.each do |x|\n (x..b.last).step(1) do |j|\n am += 1 if (j - x).abs == max_d\n end\nend\nprint max_d, \" \",am\n"}, {"source_code": "n, b = gets.to_i, gets.split.map { |x| x.to_i }.sort\nmax_d = b.last - b.first\narr = Hash.new(0)\nb.each_with_index { |x| arr[x] += 1 }\nprint max_d, \" \", arr[b.last] * arr[b.first]\n"}, {"source_code": "n, b = gets.to_i, gets.split.map { |x| x.to_i }.sort\nmax_d = b.last - b.first\nam = 0\nb.each do |x|\n b[b.index(x) + 1..b.last].each do |y|\n am += 1 if (y - x).abs == max_d\n end\nend\nprint max_d, \" \",am\n"}, {"source_code": "n, b = gets.to_i, gets.split.map { |x| x.to_i }.sort\nmax_d = b.last - b.first\narr = Hash.new(0)\nb.each_with_index { |x| arr[x] += 1 }\nif arr.size == 1\n print max_d, \" \", arr[b.last] - 1\nelse\n print max_d, \" \", arr[b.last] * arr[b.first]\nend\n"}, {"source_code": "n = gets.to_i\nb = gets.split.map(&:to_i)\nx = [1000000000,0]\ny = [0,0]\nb.each do |i|\n\tif i == x[0]\n\t\tx[1] += 1\n\telsif i < x[0]\n\t\tx[0] = i\n\t\tx[1] = 1\n\tend\n\tif i == y[0]\n\t\ty[1] += 1\n\telsif i > y[0]\n\t\ty[0] = i\n\t\ty[1] = 1\n\tend\nend\nprint y[0] - x[0],' ',x[1]*y[1]"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nmin, min_counter = 10**9, 0\nmax, max_counter = 0, 0\ngets.split.each { |i| \n i = i.to_i\n if i < min\n min = i\n min_counter = 0\n end\n\n if i == min\n min_counter += 1\n end\n\n if i > max\n max = i\n max_counter = 0\n end\n\n if i == max\n max_counter += 1\n end\n}\n\nif max != min\n puts \"#{max - min} #{min_counter * max_counter}\"\nelse\n puts \"0 0\"\nend\n\n# pair of two flowers\n# first: maximum beauty difference\n# second: how many ways to create the diff?\n"}, {"source_code": "n = Integer(gets)\nnums = gets.chomp.split\nb = Array.new\nfor i in 0...n\n b[i] = Integer(nums[i])\nend\n\nb.sort!\nmin = Array.new\nmax = Array.new\nmin[0] = b[0]\nmax[0] = b[n-1]\n\ngap = b[n-1] - b[0]\nfor i in 0...n-1\n if b[i+1] == b[0]\n min.push(b[i+1])\n end\n if b[n-i-2] == b[n-1]\n max.push(b[n-i-2])\n end\nend\nways = 0\nwhile n >= 2\n ways += (n-1) * n\n n -= 1\nend\nif gap != 0\n print gap , \" \" , min.length * max.length\nelse\n print gap , \" \" , ways\nend\n"}, {"source_code": "n = Integer(gets)\nnums = gets.chomp.split\nb = Array.new\nfor i in 0...n\n b[i] = Integer(nums[i])\nend\n\nb.sort!\nmin = Array.new\nmax = Array.new\nmin[0] = b[0]\nmax[0] = b[n-1]\n\ngap = b[n-1] - b[0]\nfor i in 0...n-1\n if b[i+1] == b[0]\n min.push(b[i+1])\n end\n if b[n-i-2] == b[n-1]\n max.push(b[n-i-2])\n end\nend\n\nif gap != 0\n print gap , \" \" , min.length * max.length\nelse\n if n != 2\n ways = 0\n while n >= 2\n ways += (n-1) * n\n n -= 1\n end\n print gap , \" \" , ways\n else\n print gap, \" \" , \"1\"\n end\nend\n"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\nn = gets.to_i\na = read_ints\n_max = a.max\n_min = a.min\nprint _max-_min\na1 = 0\na2 = 0\ni=0\nn.times do\n if(a[i] == _max)\n a1+=1\n elsif (a[i] == _min)\n a2+=1\n end\n i+=1\nend\nprint ' '\nputs a1 * a2"}, {"source_code": "n = gets.to_i\nb = {}\nh = Hash.new { |h, k| h[k] = 0 }\na = gets.split(/\\s+/).map {|q| r = q.to_i; h[r]+=1; r}\n\nr = 0\ndiff = a.max - a.min\nif diff > 0\n a.each {|q| r += h[q + diff] }\nelse\n h.each {|k,v| r += v-1 if v > 1 }\nend\n\nputs \"#{diff} #{r}\"\n"}, {"source_code": "n = gets.to_i\nh = Hash.new { |h, k| h[k] = 0 }\na = gets.split(/\\s+/).map {|q| r = q.to_i; h[r]+=1; r}\n\nr = 0\ndiff = a.max - a.min\na.each {|q| r += h[q + diff] }\n\nputs \"#{diff} #{r}\"\n"}, {"source_code": "n = gets.to_i\nb = {}\nh = Hash.new { |h, k| h[k] = 0 }\na = gets.split(/\\s+/).map {|q| r = q.to_i; h[r]+=1; r}\n\nr = 0\ndiff = a.max - a.min\nif diff > 0\n a.each {|q| r += h[q + diff] }\nelse\n h.each {|k,v| r += 2**(v-1)-1 if v > 1 }\nend\n\nputs \"#{diff} #{r}\"\n"}, {"source_code": "gets\n\nfreq = {}\nflowers = []\ngets.split(/\\s+/).each do |f|\n f = f.to_i\n\n if freq[f].nil?\n freq[f] = 1\n else\n freq[f] += 1\n end\n flowers << f\nend\n\nflowers.sort!\n\nfirst = flowers[0]\nlast = flowers[-1]\n\nif(first == last)\n puts \"#{last - first} #{freq[first] * (freq[last]-1)}\"\nelse\n puts \"#{last - first} #{freq[first] * freq[last]}\"\nend\n"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\n\nputs \"#{a.max - a.min} #{a.count(a.max)*a.count(a.min)}\"\n"}, {"source_code": "line = gets\nn = line.to_i\nline = gets\nf = line.split.map(&:to_i)\nf_s = f.sort\nd = f_s.last - f_s.first\nf_m = {}\nf.map do |i|\n\tnext unless [f_s.first, f_s.last].include?(i)\n\tf_m[i] ||= 0\n\tf_m[i] += 1\nend\nw = if f_m.size > 1\n\tf_m[f_s.first] * f_m[f_s.last]\nelse\n\t(n * n-1)/2 \nend\nputs \"#{d} #{w}\"\n"}, {"source_code": "line = gets\nn = line.to_i\nline = gets\nf = line.split.map(&:to_i)\nf_s = f.sort\nd = f_s.last - f_s.first\nf_m = {}\nf.map do |i|\n\tnext unless [f_s.first, f_s.last].include?(i)\n\tf_m[i] ||= 0\n\tf_m[i] += 1\nend\nw = if f_m.size > 1\n\tf_m[f_s.first] * f_m[f_s.last]\nelse\n\t1\nend\nputs \"#{d} #{w}\"\n"}, {"source_code": "line = gets\nn = line.to_i\nline = gets\nf = line.split.map(&:to_i)\nf_s = f.sort\nd = f_s.last - f_s.first\nf_m = {}\nf.map do |i|\n\tnext unless [f_s.first, f_s.last].include?(i)\n\tf_m[i] ||= 0\n\tf_m[i] += 1\nend\nw = if f_s.first != f_s.last\n\tf_m[f_s.first] * f_m[f_s.last]\nelse\n\t1\nend\nputs \"#{d} #{w}\"\n"}, {"source_code": "line = gets\nn = line.to_i\nline = gets\nf = line.split.map(&:to_i)\nf_s = f.sort\nd = f_s.last - f_s.first\nf_m = {}\nf.map do |i|\n\tnext unless [f_s.first, f_s.last].include?(i)\n\tf_m[i] ||= 0\n\tf_m[i] += 1\nend\nw = if f_s.first == f_s.last\n\tf_m[f_s.first] * f_m[f_s.last]\nelse\n\t(n * (n-1))/2 \nend\nputs \"#{d} #{w}\"\n"}, {"source_code": "line = gets\nn = line.to_i\nline = gets\nf = line.split.map(&:to_i)\nf_s = f.sort\nd = f_s.last - f_s.first\nf_m = {}\nf.map do |i|\n\tnext unless [f_s.first, f_s.last].include?(i)\n\tf_m[i] ||= 0\n\tf_m[i] += 1\nend\nw = f_m[f_s.first] * f_m[f_s.last]\nputs \"#{d} #{w}\"\n"}, {"source_code": "\nn = gets.to_i\ntab = gets.split.map(&:to_i)\n\nh, l = tab.max, tab.min\n\nif h > l\n puts (h-l).to_s + \" \" + \n (tab.select{|x| x == h}.size * tab.select{|x| x == l}.size).to_s\nelse\n puts \"0 \" + (tab.size * (tab.size-1)).to_s\nend\n\n\n"}, {"source_code": "\nn = gets.to_i\ntab = gets.split.map(&:to_i)\n\nh, l = tab.max, tab.min\n\nif h != l\n puts (h-l).to_s + \" \" + \n (tab.select{|x| x == h}.size * tab.select{|x| x == l}.size).to_s\nelse\n puts \"0 \" + (tab.size * (tab.size-1)).to_s\nend\n\n\n"}, {"source_code": "\nn = gets.to_i\ntab = gets.split.map(&:to_i)\n\nh, l = tab.max, tab.min\n\nputs (h-l).to_s + \" \" + \n (tab.select{|x| x == h}.size * tab.select{|x| x == l}.size).to_s\n\n\n"}], "src_uid": "eb2d1072c5308d9ef686315a122d9d3c"} {"source_code": "original = gets.chomp\naltered = gets.chomp\n\nmapping = {}\nfixable = true\n\noriginal.size.times do |i|\n a = original[i]\n b = altered[i]\n\n if (mapping[b] && mapping[b] != a) || (mapping[a] && mapping[a] != b)\n fixable = false\n else\n mapping[a] = b\n mapping[b] = a\n end\nend\n\nif fixable\n has_key = {}\n ans = {}\n mapping.each do |key, value|\n ans[key] = value unless has_key[key] || key == value\n has_key[key] = true\n has_key[value] = true\n end\n\n puts ans.length\n ans.each do |key, value|\n puts \"#{key} #{value}\"\n end\n\nelse\n puts \"-1\"\nend\n", "positive_code": [{"source_code": "a = gets\nb = gets\nvis = {}\nres = []\nfin = true\nfor i in 0..(a.size() - 2)\n if ((vis.include?(a[i]) || vis.include?(b[i])))\n if (!(vis.include?a[i]) || !(vis.include?b[i]) || vis[a[i]] != b[i])\n puts -1\n fin = false\n break\n end\n end\n next if (vis.include?(a[i]))\n vis[a[i]] = b[i]\n vis[b[i]] = a[i]\n if (a[i] != b[i])\n res.push([a[i],b[i]])\n end\nend\nif (fin)\n puts res.size()\n for i in res \n puts \"#{i[0]} #{i[1]}\"\n end\nend"}], "negative_code": [{"source_code": "original = gets.chomp\naltered = gets.chomp\n\nmapping = {}\nfixable = true\n\noriginal.size.times do |i|\n if mapping[original[i]]\n fixable = false unless mapping[original[i]] == altered[i]\n else\n mapping[original[i]] = altered[i]\n end\nend\n\nif fixable\n has_key = {}\n ans = {}\n mapping.each do |key, value|\n ans[key] = value unless has_key[key] || key == value\n has_key[key] = true\n has_key[value] = true\n end\n\n puts ans.length\n ans.each do |key, value|\n puts \"#{key} #{value}\"\n end\n\nelse\n puts \"-1\"\nend\n"}], "src_uid": "b03895599bd578a83321401428e277da"} {"source_code": "gets\n$u=gets.hex\nputs gets(p)=~/[#$u#{7-$u}]/?\"NO\":\"YES\"\n", "positive_code": [{"source_code": "n = gets.to_i\nt = gets.to_i\na = Array.new(n){\n b = gets.split.map(&:to_i)\n [*1..6] - b - b.map{|_| 7 - _}\n}\nputs a.uniq.size == 1 ? :YES : :NO\n"}, {"source_code": "RD =->{gets.to_i}\nI =->{gets.split.map &:to_i}\n\ndef solve\n\tn = RD[]; t1 = RD[]; t2 = 7 - t1; n.times{\n\t\ta, b = I[]\t\n\t\treturn \"NO\" if a == t1 || a == t2 || b == t1 || b == t2\n\t}\t\t\n\treturn \"YES\"\nend\n\nputs solve\n\n\n"}, {"source_code": "gets\n$u=gets.hex\nputs gets(p)=~/[#$u#{7-$u}]/?\"NO\":\"YES\"\n"}, {"source_code": "\ufeffdef solve(x, faces)\n faces.each do |a, b|\n if (a == b) or (a == x) or (b == x) or ((a + b) == 7) or ((a + x) == 7) or ((b + x) == 7)\n return false\n end\n end\n true\nend \n\nn = gets.chomp.to_i\nx = gets.chomp.to_i\nfaces = []\nn.times do \n faces << gets.chomp.split(\" \").map{|e| e.to_i}\nend\n\nret = solve(x, faces)\nputs ret ? \"YES\" : \"NO\"\n \n\n"}, {"source_code": "gets\n$u=gets.hex\nputs gets(p)=~/[#$u#{7-$u}]/?\"NO\":\"YES\"\n"}, {"source_code": "gets\n$u=gets.hex\nputs gets(p)=~/[#$u#{7-$u}]/?\"NO\":\"YES\""}, {"source_code": "n = gets.to_i - 1\nx = 7 - gets.to_i\ngets\nn.times do\n a = gets.split.map(&:to_i)\n g = ([1,2,3,4,5,6] - [a[0], 7-a[0], a[1], 7-a[1], 7-x])\n if g.size == 1\n x = g[0]\n else\n puts :NO\n exit\n end\nend\nputs :YES"}, {"source_code": "gets\n$u=gets.hex\nputs gets(p)=~/[#$u#{7-$u}]/?\"NO\":\"YES\"\n"}, {"source_code": "def r() gets.to_s.split.map &:to_i end\nn,x,o=*r,*r;\nn.times do\n a,b=*r;o||=[a,b,7-a,7-b].include? x\nend\nprint o ? \"NO\" : \"YES\"\n"}, {"source_code": "#!/usr/bin/ruby\nn = gets.to_i\ntop = gets.to_i\na = []\nn.times do\n a << gets.split.map {|x| x.to_i}\nend\nans = \"YES\"\nsum = 1 + 2 + 3 + 4 + 5 + 6\nfor i in 0...n do\n t = sum - top - a[i][0] - a[i][1] - (7 - a[i][0]) - (7 - a[i][1])\n if t == a[i][0] || t == a[i][1] || t == (7 - a[i][0]) || t == (7 - a[i][1]) then\n ans = \"NO\"\n break\n end\nend\nputs ans\n"}, {"source_code": "gets\n$u=gets.hex\nputs gets(p)=~/[#$u#{7-$u}]/?\"NO\":\"YES\"\n"}, {"source_code": "n = gets.to_i\ntop = gets.to_i\nbottom = 7 - top.to_i\nsides = []\nflag = true\nn.times do |i|\n side1, side2 = gets.chomp.split.map(&:to_i)\n if side1 == top || side1 == bottom || side2 == top ||side2 == bottom then\n flag = false\n end\nend\nputs flag ? \"YES\" : \"NO\" "}, {"source_code": "gets\n$u=gets.hex\nputs gets(p)=~/[#$u#{7-$u}]/?\"NO\":\"YES\""}, {"source_code": "gets\n$u=gets.hex\nputs gets(p)=~/[#$u#{7-$u}]/?\"NO\":\"YES\""}, {"source_code": "n = gets.to_i\nlast = gets.to_i\n1.upto(n) {\n buf = gets.split(\" \")\n a = buf[0].to_i\n b = buf[1].to_i\n if a == last || b == last || a == 7 - last || b == 7 - last\n print \"NO\"\n exit 0\n end\n}\nprint \"YES\""}, {"source_code": "n = gets.to_i\ntop = gets.to_i\n(1..n).each do\n left, right = gets.split.collect{|i| i.to_i}\n if left == top or 7-left == top or\\\n right == top or 7-right == top\n puts 'NO'\n exit\n end\nend\nputs 'YES'\n"}, {"source_code": "n = gets.to_i\nc = 7 - gets.to_i\nn.times do\n c = 7 - c\n a,b = gets.split.map &:to_i\n if a==c || a==7-c || b==7-c || b == c\n puts 'NO'\n exit\n end\nend\nputs \"YES\"\n"}, {"source_code": "gets\n$u=gets.hex\nputs gets(p)=~/[#$u#{7-$u}]/?\"NO\":\"YES\"\n"}, {"source_code": "def read_next_line\n gets.split.map { |x| x.to_i }\nend\n\nn = gets.to_i\nd = gets.to_i\nfor _ in 1..n\n a = read_next_line\n a.concat(a.map { |x| 7 - x })\n if a.include? d\n puts 'NO'\n exit\n end\nend\nputs 'YES'"}, {"source_code": "gets\nu = gets.to_i\nputs gets(p) =~ /[#{u}#{7-u}]/ ? \"NO\" : \"YES\"\n"}, {"source_code": "n = gets.to_i\nt = gets.to_i\n\nwhile t != -1 && s = gets\n\ta, b = s.split.map(&:to_i)\n\tc = 0\n\tc += 1 << a-1\n\tc += 1 << 6-a\n\tc += 1 << b-1\n\tc += 1 << 6-b\n\tif (c & 1<0,'2'=>1,'3'=>2,'4'=>3}\n\n\n\nfor i in '1'..'4'\n mp[i]=a[t[i]]\nend\n\nans =0\nfor i in 0...b.length\n ans+=mp[b[i]]\nend\nputs ans"}, {"source_code": "a=gets.split.map &:to_i;p gets.scan(/./).map{|s|a[s.to_i-1]}.inject(:+)\n"}, {"source_code": "a = [nil] + gets.split.map(&:to_i)\ns = gets.chomp.split(\"\").map(&:to_i)\nans = 0\ns.each do |x|\n ans += a[x]\nend\np ans\n"}, {"source_code": "a = [nil] + gets.split.map(&:to_i)\ns = gets.chomp.split(\"\").map(&:to_i)\nputs s.map{|x| a[x]}.inject(:+)\n"}, {"source_code": "a=gets.chomp.split(\" \")\nb=gets.chomp\nans=0\nb.each_char do |i|\nind=i.to_i-1\nans+=a[ind].to_i\nend\nputs \"#{ans}\""}, {"source_code": "a = [nil] + gets.split.map{|x| x.to_i}\nputs(gets.strip.split('').map{|x| x.to_i}.inject(0){|s, x| s += a[x]})\n"}, {"source_code": "a=gets.split.map &:to_i;p gets.scan(/./).map{|s|a[s.to_i-1]}.inject(:+)\n"}, {"source_code": "a = gets.split(' ').map(&:to_i).unshift(0)\n\nputs gets.chomp.chars.inject(0) { |s, x| s + a[x.to_i] }\n"}, {"source_code": "a=gets.split.map &:to_i;p gets.scan(/./).map{|s|a[s.to_i-1]}.inject(:+)\n"}, {"source_code": "a=gets.split.map &:to_i;p gets.scan(/./).map{|s|a[s.to_i-1]}.inject(:+)\n"}, {"source_code": "a = gets.split.map(&:to_i)\ns = gets.chomp\ncal = 0\ns.each_char do |c|\n cal += a[c.to_i - 1]\nend\nputs cal\n"}], "negative_code": [], "src_uid": "db9065d975878227a749083f0036a169"} {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\ns = 0\nfor i in (1..$n) do\n $a[i] = gets.split.map{|e| e.to_i}\n s+=$a[i][0]\nend\nif s==0 && $n==$c\n puts -1\n exit\nend\nif s==0 && $n!=$c \n puts 0\n exit\nend\nl=0\nr=1\nc=check(r)\nwhile c!=1 do \n r*=2\n c=check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n\texit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n if check(z)==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n if check(z)==0 then l1=z else r=z end\nend\n\nputs r-l-1\n", "positive_code": [{"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\ns = 0\nfor i in (1..$n) do\n $a[i] = gets.split.map{|e| e.to_i}\n s+=$a[i][0]\nend\nif s==0 && $n==$c\n puts -1\n exit\nend\nif s==0 && $n!=$c \n puts 0\n exit\nend\nl=0\nr=1\nc=check(r)\nwhile c!=1 do \n r*=2\n c=check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n\texit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n if check(z)==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n if check(z)==0 then l1=z else r=z end\nend\n\nputs r-l-1"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n if m>$c then break end\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\ns = 0\nfor i in (1..$n) do\n $a[i] = gets.split.map{|e| e.to_i}\n s+=$a[i][0]\nend\nif s==0 && $n==$c\n puts -1\n exit\nend\nif s==0 && $n!=$c \n puts 0\n exit\nend\nl=0\nr=1\nc=check(r)\nwhile c!=1 do \n r*=2\n c=check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n\texit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n if check(z)==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n if check(z)==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "$n, c = gets.split.map(&:to_i)\n$a, $b = [], []\n$n.times do\n a_i, b_i = gets.split.map(&:to_i)\n $a << a_i\n $b << b_i\nend\n\ndef get_value(x)\n ret = $n\n $n.times do |i|\n ret += $a[i] * x / $b[i]\n end\n ret \nend\n\nlow, high = 1, 10 ** 18 + 1\nwhile low < high\n middle = low + high >> 1\n if get_value(middle) >= c\n high = middle\n else\n low = middle + 1\n end\nend\nminimum = high\n\nlow, high = 0, 10 ** 18\nwhile low < high\n middle = low + high + 1 >> 1\n if get_value(middle) <= c\n low = middle\n else\n high = middle - 1\n end\nend\nmaximum = low\n\nanswer = [maximum - minimum + 1, 0].max\nanswer = -1 if answer == 10 ** 18\nputs answer\n"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n $a[i] = gets.split.map{|e| e.to_i}\nend\nl=0\nr=1\nc=check(r)\nwhile c!=1 do \n r*=2\n c=check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n\texit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n if check(z)==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n if check(z)==0 then l1=z else r=z end\nend\n\nputs r-l-1"}, {"source_code": "# ABBYY Cup 2.0 - Easy\n# Problem E - Space Voyage\n$n, c = gets.split.map(&:to_i)\n$a, $b = [], []\n$n.times do\n a_i, b_i = gets.split.map(&:to_i)\n $a << a_i\n $b << b_i\nend\n\ndef get_value(x)\n ret = $n\n $n.times do |i|\n ret += $a[i] * x / $b[i]\n end\n ret \nend\n\nlow, high = 1, 10 ** 18 + 1\nwhile low < high\n middle = low + high >> 1\n if get_value(middle) >= c\n high = middle\n else\n low = middle + 1\n end\nend\nminimum = high\n\nlow, high = 0, 10 ** 18\nwhile low < high\n middle = low + high + 1 >> 1\n if get_value(middle) <= c\n low = middle\n else\n high = middle - 1\n end\nend\nmaximum = low\n\nanswer = [maximum - minimum + 1, 0].max\nanswer = -1 if answer == 10 ** 18\nputs answer\n"}], "negative_code": [{"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n end\n m>$c\nend\ndef check2(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n end\n m>=$c\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n $a[i] = gets.split.map{|e| e.to_i}\nend\nl=1\nr=1\nc=check(r)\nwhile !c do \n r*=2\n c=check(r)\nend\nl2 = l1 = l\nr2 = r1 = r \nwhile r1-l1>1 do\n m = (l1+r1)/2\n if check(m) then r1=m else l1=m end\nend\nwhile r2-l2>1 do\n m = (l2+r2)/2\n if check2(m) then r2=m else l2=m end\nend\nans = l1-r2+1\nputs ans\n\n"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n end\n m>$c\nend\ndef check2(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n end\n m>=$c\nend\n\ndef check3(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n end\n m==$c\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n $a[i] = gets.split.map{|e| e.to_i}\nend\nl=1\nr=1\nc=check(r)\nwhile !c do \n r*=2\n c=check(r)\nend\nl2 = l1 = l\nr2 = r1 = r \nwhile r1-l1>1 do\n m = (l1+r1)/2\n if check(m) then r1=m else l1=m end\nend\nwhile r2-l2>1 do\n m = (l2+r2)/2\n if check2(m) then r2=m else l2=m end\nend\nans = l1-r2+1\nif l1==r2 then\n c=check3(r2)\n if c then ans=1 else ans=0 end\nend\n\nputs ans\n\n"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n $a[i] = gets.split.map{|e| e.to_i}\nend\nl=0\nr=1\nc=check(r)\nwhile c!=1 do \n r*=2\n c=check(r)\nend\n\nm=0\nputs l,r\nloop do\n if r-1==l then\n puts 0\n\thalt\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n if check(z)==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n if check(z)==0 then l1=z else r=z end\nend\n\nputs l-r-1"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n end\n m>$c\nend\ndef check2(x)\n m = 0\n for i in (1..$n) do\n m+=$a[i][0]*x/$a[i][1]+1\n end\n m>=$c\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n $a[i] = gets.split.map{|e| e.to_i}\nend\nl=1\nr=1\nc=check(r)\nwhile !c do \n r*=2\n c=check(r)\nend\nl2 = l1 = l\nr2 = r1 = r \nwhile r1-l1>1 do\n m = (l1+r1)/2\n if check(m) then r1=m else l1=m end\nend\nwhile r2-l2>1 do\n m = (l2+r2)/2\n if check2(m) then r2=m else l2=m end\nend\nans = l1-r2+1\nif l1==r2 then\n c=check(r2)\n if c then ans=1 else ans=0 end\nend\n\nputs ans\n\n"}, {"source_code": "def check(x)\n m = ($oo*x+0.000001).to_i + $n\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$oo = 0\nfor i in (1..$n) do\n a = gets.split.map{|e| e.to_f}\n $oo+= a[0]/a[1]\nend\nl=0\nr=1\nc = check(r)\nwhile c!=1 do \n r*=2\n c = check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n exit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n c = check(z)\n if c==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n c = check(z)\n if c==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "def check(x)\n m = ($oo*x+0.00000001).to_i + $n\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$oo = 0\nfor i in (1..$n) do\n a = gets.split.map{|e| e.to_f}\n $oo+= a[0]/a[1]\nend\nl=0\nr=1\nc = check(r)\nwhile c!=1 do \n r*=2\n c = check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n exit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n c = check(z)\n if c==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n c = check(z)\n if c==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=($a[i]*x+1.0000001).to_i\n if m>$c then break end\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n a = gets.split.map{|e| e.to_f}\n $a[i] = a[0]/a[1]\nend\nl=0\nr=1\nc = check(r)\nwhile c!=1 do \n r*=2\n c = check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n exit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n c = check(z)\n if c==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n c = check(z)\n if c==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n if $a[i][0]==0 then\n m+=1 \n else\n m+=$a[i][0]*x/$a[i][1]+1\n end\n if m>$c then break end\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n $a[i] = gets.split.map{|e| e.to_i}\nend\nl=0\nr=1\nc = check(r)\nwhile c!=1 do \n r*=2\n c = check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n exit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n c = check(m)\n if c==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n c = check(m)\n if c==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=($a[i]*x+1.000001).to_i\n if m>$c then break end\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n a = gets.split.map{|e| e.to_f}\n $a[i] = a[0]/a[1]\nend\nl=0\nr=1\nc = check(r)\nwhile c!=1 do \n r*=2\n c = check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n exit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n c = check(z)\n if c==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n c = check(z)\n if c==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=($a[i]*x+1.00000000000000001).to_i\n if m>$c then break end\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n a = gets.split.map{|e| e.to_f}\n $a[i] = a[0]/a[1]\nend\nl=0\nr=1\nc = check(r)\nwhile c!=1 do \n r*=2\n c = check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n exit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n c = check(z)\n if c==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n c = check(z)\n if c==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "def check(x)\n m = ($oo*x+0.0000000000001).to_i + $n\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$oo = 0\nfor i in (1..$n) do\n a = gets.split.map{|e| e.to_f}\n $oo+= a[0]/a[1]\nend\nl=0\nr=1\nc = check(r)\nwhile c!=1 do \n r*=2\n c = check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n exit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n c = check(z)\n if c==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n c = check(z)\n if c==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "def check(x)\n m = ($oo*x).to_i + $n\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$oo = 0.to_r\nfor i in (1..$n) do\n a = gets.split.map{|e| e.to_r}\n $oo+= a[0]/a[1]\nend\nl=0\nr=1\nc = check(r)\nwhile c!=1 do \n r*=2\n c = check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n exit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n c = check(z)\n if c==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n c = check(z)\n if c==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=($a[i]*x+1.000000001).to_i\n if m>$c then break end\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n a = gets.split.map{|e| e.to_f}\n $a[i] = a[0]/a[1]\nend\nl=0\nr=1\nc = check(r)\nwhile c!=1 do \n r*=2\n c = check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n exit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n c = check(z)\n if c==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n c = check(z)\n if c==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=($a[i]*x+1.0000000000001).to_i\n if m>$c then break end\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n a = gets.split.map{|e| e.to_f}\n $a[i] = a[0]/a[1]\nend\nl=0\nr=1\nc = check(r)\nwhile c!=1 do \n r*=2\n c = check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n exit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n c = check(z)\n if c==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n c = check(z)\n if c==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "def check(x)\n m = 0\n for i in (1..$n) do\n m+=($a[i]*x+1.00000000001).to_i\n if m>$c then break end\n end\n if m>$c then return 1 end\n if m==$c then return 0 end\n if m<$c then return -1 end\nend\n\n$n,$c = gets.split.map{|e| e.to_i}\n$a = []\nfor i in (1..$n) do\n a = gets.split.map{|e| e.to_f}\n $a[i] = a[0]/a[1]\nend\nl=0\nr=1\nc = check(r)\nwhile c!=1 do \n r*=2\n c = check(r)\nend\n\nm=0\nloop do\n if r-1==l then\n puts 0\n exit\n end\n m = (l+r)/2\n c = check(m)\n if c==1\n r = m\n elsif c==-1\n l = m\n elsif c==0\n break\n end\nend\n\nl1 = r1 = m\nwhile r1-l>1 do\n z = (l+r1)/2\n c = check(z)\n if c==0 then r1=z else l=z end\nend\n\nwhile r-l1>1 do\n z = (l1+r)/2\n c = check(z)\n if c==0 then l1=z else r=z end\nend\n\nputs r-l-1\n"}, {"source_code": "$n, c = gets.split.map(&:to_i)\n$a, $b = [], []\n$n.times do\n a_i, b_i = gets.split.map(&:to_i)\n $a << a_i\n $b << b_i\nend\n\ndef get_value(x)\n ret = $n\n $n.times do |i|\n ret += $a[i] * x / $b[i]\n end\n ret \nend\n\nlow, high = 0, 10 ** 18\nwhile low < high\n middle = low + high >> 1\n if get_value(middle) >= c\n high = middle\n else\n low = middle + 1\n end\nend\nminimum = high\n\nlow, high = 0, 10 ** 18\nwhile low < high\n middle = low + high + 1 >> 1\n if get_value(middle) <= c\n low = middle\n else\n high = middle - 1\n end\nend\nmaximum = low\n\nputs [maximum - minimum + 1, 0].max\n"}, {"source_code": "$n, c = gets.split.map(&:to_i)\n$a, $b = [], []\n$n.times do\n a_i, b_i = gets.split.map(&:to_i)\n $a << a_i\n $b << b_i\nend\n\ndef get_value(x)\n ret = $n\n $n.times do |i|\n ret += $a[i] * x / $b[i]\n end\n ret \nend\n\nlow, high = 1, 10 ** 18\nwhile low < high\n middle = low + high >> 1\n if get_value(middle) >= c\n high = middle\n else\n low = middle + 1\n end\nend\nminimum = high\n\nlow, high = 0, 10 ** 18\nwhile low < high\n middle = low + high + 1 >> 1\n if get_value(middle) <= c\n low = middle\n else\n high = middle - 1\n end\nend\nmaximum = low\n\nputs [maximum - minimum + 1, 0].max\n"}, {"source_code": "$n, c = gets.split.map(&:to_i)\n$a, $b = [], []\n$n.times do\n a_i, b_i = gets.split.map(&:to_i)\n $a << a_i\n $b << b_i\nend\n\ndef get_value(x)\n ret = $n\n $n.times do |i|\n ret += $a[i] * x / $b[i]\n end\n ret \nend\n\nlow, high = 1, 10 ** 18\nwhile low < high\n middle = low + high >> 1\n if get_value(middle) >= c\n high = middle\n else\n low = middle + 1\n end\nend\nminimum = high\n\nlow, high = 0, 10 ** 18\nwhile low < high\n middle = low + high + 1 >> 1\n if get_value(middle) <= c\n low = middle\n else\n high = middle - 1\n end\nend\nmaximum = low\n\nanswer = [maximum - minimum + 1, 0].max\nanswer = -1 if answer == 10 ** 18\nputs answer\n"}, {"source_code": "$n, c = gets.split.map(&:to_i)\n$a, $b = [], []\n$n.times do\n a_i, b_i = gets.split.map(&:to_i)\n $a << a_i\n $b << b_i\nend\n\ndef get_value(x)\n ret = $n\n $n.times do |i|\n ret += $a[i] * x / $b[i]\n end\n ret \nend\n\nlow, high = -1, 10 ** 18\nwhile low < high\n middle = low + high >> 1\n if get_value(middle) >= c\n high = middle\n else\n low = middle + 1\n end\nend\nminimum = high\n\nlow, high = -1, 10 ** 18\nwhile low < high\n middle = low + high + 1 >> 1\n if get_value(middle) <= c\n low = middle\n else\n high = middle - 1\n end\nend\nmaximum = low\n\nputs [maximum - minimum + 1, 0].max\n"}, {"source_code": "$n, c = gets.split.map(&:to_i)\n$a, $b = [], []\n$n.times do\n a_i, b_i = gets.split.map(&:to_i)\n $a << a_i\n $b << b_i\nend\n\ndef get_value(x)\n ret = $n\n $n.times do |i|\n ret += $a[i] * x / $b[i]\n end\n ret \nend\n\nlow, high = 0, 10 ** 18\nwhile low < high\n middle = low + high >> 1\n if get_value(middle) >= c\n high = middle\n else\n low = middle + 1\n end\nend\nminimum = high\n\nlow, high = -1, 10 ** 18\nwhile low < high\n middle = low + high + 1 >> 1\n if get_value(middle) <= c\n low = middle\n else\n high = middle - 1\n end\nend\nmaximum = low\n\nputs [maximum - minimum + 1, 0].max\n"}], "src_uid": "9e17daaa5ca2297673b8a2a9db497471"} {"source_code": "#!/usr/bin/env ruby\nn, m = gets.split(' ').map(&:to_i)\nputs n + m - 1\nn.times do |i|\n puts \"#{i + 1} 1\"\nend\n(m - 1).times do |i|\n puts \"1 #{i + 2}\"\nend", "positive_code": [{"source_code": "m, n = gets.chomp.split.map { |x| x.to_i }\nputs n + m - 1\nfor i in 1..n\n puts \"1 #{i}\"\nend\nfor i in 2..m\n puts \"#{i} 1\"\nend"}, {"source_code": "boys, girls = gets.chomp.split.map(&:to_i)\nputs boys + girls - 1\n(1..girls).each { |e| puts \"1 #{e}\" }\n(2..boys).each { |e| puts \"#{e} 1\" }"}, {"source_code": "n, m = gets.split.map(&:to_i)\nputs n + m - 1\nputs [*1..n].map{|i| i.to_s+\" 1\"}\nputs [*2..m].map{|i| \"1 \"+i.to_s}\n"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\nputs n+m-1\n(1..n).each{|x| puts \"#{x} 1\"}\n(2..m).each{|x| puts \"1 #{x}\"}"}, {"source_code": "a, b = gets.split.map(&:to_i)\np a + b - 1\nputs \"1 1\"\n2.upto(a) do |i|\n puts \"#{i} 1\"\nend\n2.upto(b) do |i|\n puts \"1 #{i}\"\nend\n"}, {"source_code": "require \"Matrix\"\n\nh=Matrix\nn, m = gets.split.map{|i| i.to_i}\nputs(n+m-1)\nfor i in 1..m\n puts(\"1 #{i}\")\nend\nfor i in 2..n\n puts(\"#{i} 1\")\nend"}, {"source_code": "n, m = gets.split.map{|i| i.to_i}\nputs(n+m-1)\nfor i in 1..m\n puts(\"1 #{i}\")\nend\nfor i in 2..n\n puts(\"#{i} 1\")\nend"}, {"source_code": "n = gets(\" \")\nm = gets\nn = n.to_i\nm = m.to_i\nputs m + n - 1\nm.times { |x| print \"1 #{x+1}\\n\"}\n(n-1).times { |x| \n\tprint \"#{x+2} #{m > 1 ? 2 : 1}\\n\"}"}, {"source_code": "def run\n n, m = $stdin.readline.split.map(&:to_i)\n\n puts n + m - 1\n\n n.times do |i|\n puts \"#{i + 1} 1\"\n end\n\n if n == 1\n (m - 1).times do |i|\n puts \"1 #{i + 2}\"\n end\n elsif m > 1\n (m - 1).times do |i|\n puts \"2 #{i + 2}\"\n end\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n n, m = $stdin.readline.split.map(&:to_i)\n\n puts n + m - 1\n\n n.times do |i|\n puts \"#{i + 1} 1\"\n end\n\n (m - 1).times do |i|\n if n == 1\n puts \"1 #{i + 2}\"\n else\n puts \"2 #{i + 2}\"\n end\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "class A\n def initialize\n n, m = gets.chomp.split(' ').map(&:to_i)\n\n res = n+m-1\n ans = []\n\n 1.upto(m) do |index|\n ans << [1,index]\n end\n\n 2.upto(n) do |index|\n ans << [index, m]\n end\n\n puts ans.size\n ans.each do |a|\n puts a.join(' ')\n end\n end\n\nend\n\na = A.new"}, {"source_code": "a=gets.chomp.split(\" \")\nans=-1\na=a.each do |i| \na[a.index(i)]=i.to_i\nans+=i.to_i\nend\nt=0\nif a[0]>a[1]\nt=1\nend\na.sort!\na.reverse!\nputs \"#{ans}\"\nn=0\nm=1\ntrig1=1\ntrig2=-1\nloop do \nif n0\nn+=1\nend\nif m0\nm+=1\nend\ntrig1=trig1*(-1)\ntrig2=trig1*(-1)\nif t== 1\nputs \"#{n} #{m}\"\nelse \nputs \"#{m} #{n}\"\nend\nif m==a[1]\ntrig1=2\nend\nbreak if n==a[0] && m==a[1]\nend\n"}, {"source_code": "n,m = gets.split.map &:to_i\ncant,ln,lm = 0,1,1\nnn = false\na = []\nwhile true\n cant+=1\n a<< \"#{ln} #{lm}\"\n som = false\n if nn then\n if lna[1]\nt=1\nend\na.sort!\na.reverse!\nputs \"#{ans}\"\nn=0\nm=1\ntrig1=1\ntrig2=-1\nloop do \nif n0\nn+=1\nend\nif m0\nm+=1\nend\ntrig1=trig1*(-1)\ntrig2=trig1*(-1)\nif t== 1\nputs \"#{n} #{m}\"\nelse \nputs \"#{m} #{n}\"\nend\nif m==a[1]\ntrig1=2\nend\nbreak if n==a[0] && m==a[1]\nend"}, {"source_code": "n, m = gets.split.map(&:to_i)\n\nputs n + m - 1\n\nm.times { |i| puts \"1 #{i+1}\" }\n(n-1).times { |i| puts \"#{i+2} 1\" }\n\n"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\nn, m = gets.split(' ').map(&:to_i)\nputs n + m - 1"}, {"source_code": "n = gets(\" \")\nm = gets\nn = n.to_i\nm = m.to_i\nputs m + n - 1\nm.times { |x| print \"1 #{x+1}\\n\"}\n(n-1).times { |x| print \"#{x+2} 2\\n\"}"}, {"source_code": "n = gets(\" \")\nm = gets\nn = n.to_i\nm = m.to_i\nputs m + n - 1\nif m < n\n\tm, n = n, m\nend\nm.times { |x| print \"1 #{x+1}\\n\"}\n(n-1).times { |x| print \"#{x+2} 2\\n\"}"}, {"source_code": "def run\n n, m = $stdin.readline.split.map(&:to_i)\n\n puts n + m - 1\n\n n.times do |i|\n puts \"#{i + 1} 1\"\n end\n\n if m > 1\n (m - 1).times do |i|\n puts \"2 #{i + 2}\"\n end\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "a=gets.chomp.split(\" \")\nans=-1\na=a.each do |i| \na[a.index(i)]=i.to_i\nans+=i.to_i\nend\na.sort!\na.reverse!\nputs \"#{ans}\"\n#puts \"1 1\"\nn=0\nm=1\ntrig1=1\ntrig2=-1\nloop do \nif n0\nn+=1\nend\nif m0\nm+=1\nend\ntrig1=trig1*(-1)\ntrig2=trig1*(-1)\nputs \"#{n} #{m}\"\nif m==a[1]\ntrig1=2\nend\nbreak if n==a[0] && m==a[1]\nend\n"}, {"source_code": "#!/usr/bin/ruby\ninclude Math\n\nn,m = gets.split.map(&:to_i)\nret = []\nfor i in 1..n\n for j in 1..m\n ret << [i,j].join(\" \")\n end\nend\nputs ret.size\nputs ret.join \"\\n\"\n"}], "src_uid": "14fc3a7fef44a02791aee62838c4c8c8"} {"source_code": "def isvalid(s)\n n = s.size\n return true if n.zero?\n return false if n == 1\n\n for i in 0..n - 2\n return true unless s[i] == s[i + 1]\n end\n false\nend\n\ndef solve\n gets\n f = true\n gets.chomp.split('W').each do |s|\n f = false unless isvalid(s)\n end\n puts f ? :YES : :NO\nend\n\ngets.to_i.times do\n solve\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n s = gets.chomp\r\n ok = s.split(\"W\").reject(&:empty?).all? { |s| s.include?(\"R\") && s.include?(\"B\") }\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n"}], "negative_code": [], "src_uid": "3f284afb044c8a57a02cd015d06e0ef0"} {"source_code": " n = gets.to_i\r\n n.times do\r\n str = gets.to_s.strip\r\n len = str.length\r\n ans = if len.even?\r\n half = len / 2\r\n str[0...half] == str[half..] ? 'YES' : 'NO'\r\n else\r\n 'NO'\r\n end\r\n puts ans\r\n end\r\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\r\nt.times do |n|\r\n lin = gets.chomp\r\n ln = lin.size\r\n lin1 = \"\"\r\n lin2 = \"\"\r\n if ln%2 == 0\r\n ln.times do |i|\r\n if i< (ln/2)\r\n lin1 += lin[i]\r\n else\r\n lin2 += lin[i]\r\n end\r\n end\r\n end\r\n if lin1!= \"\" && lin1 == lin2\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n \r\nend"}, {"source_code": "n = gets.chomp.to_i\r\nn.times do\r\n w = gets.chomp\r\n puts (w[0...w.length/2] == w[w.length/2..] ? \"YES\" : \"NO\")\r\nend"}, {"source_code": "n = gets.to_i\na = []\n\ndef find_ans(w)\n if w.length.odd?\n 'NO'\n else\n if w[0..w.length/2 - 1] == w[w.length/2..w.length]\n 'YES'\n else\n 'NO'\n end\n end\nend\n \n(0..n-1).each do |x|\n w = gets.chomp\n\ta.append(find_ans(w))\nend\n \n \na.each do |x|\n puts x\nend"}, {"source_code": "t = gets.to_i\ninputs = []\n(0...t).each do |i|\n str = gets.chomp\n inputs << str\nend\n\ninputs.each do |str|\n len = str.length\n if len == 1\n puts \"NO\"\n next\n end\n m = len/2\n substr1 = str[0..m-1]\n substr2 = str[m..len]\n if substr1 == substr2\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "inputs = STDIN.read.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |input|\r\n if input.length % 2 != 0\r\n puts \"NO\"\r\n next\r\n end\r\n\r\n if input[0..input.length/2 - 1] == input[input.length/2..input.length]\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\r\nt.times do |n|\r\n lin = gets.chomp\r\n ln = lin.size\r\n lin1 = \"\"\r\n lin2 = \"\"\r\n if ln%2 == 0\r\n ln.times do |i|\r\n if i< (ln/2)\r\n lin1 += lin[i]\r\n else\r\n lin2 += lin[i]\r\n end\r\n end\r\n end\r\n if lin1!= \"\" && lin1 == lin2\r\n p \"YES\"\r\n else\r\n p \"NO\"\r\n end\r\n \r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do |n|\r\n lin = gets\r\n ln = lin.length\r\n lin1 = \"\"\r\n lin2 = \"\"\r\n if ln%2 == 0\r\n ln.times do |i|\r\n if i< (ln/2)\r\n lin1 += lin[i]\r\n else\r\n lin2 += lin[i]\r\n end\r\n end\r\n end\r\n if lin1!= \"\" && lin1 == lin2\r\n p \"YES\"\r\n else\r\n p \"NO\"\r\n end\r\n \r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do |n|\r\n lin = gets\r\n ln = lin.size\r\n lin1 = \"\"\r\n lin2 = \"\"\r\n if ln%2 == 0\r\n ln.times do |i|\r\n if i< (ln/2)\r\n lin1 += lin[i]\r\n else\r\n lin2 += lin[i]\r\n end\r\n end\r\n end\r\n if lin1!= \"\" && lin1 == lin2\r\n p \"YES\"\r\n else\r\n p \"NO\"\r\n end\r\n \r\nend\r\n"}, {"source_code": "n = gets.to_i\r\nn.times do\r\n str = gets.to_s\r\n len = str.length\r\n ans = if len.even?\r\n half = len / 2\r\n str[0...half] == str[half..] ? 'YES' : 'NO'\r\n else\r\n 'NO'\r\n end\r\n puts ans\r\nend\r\n"}, {"source_code": "s = gets.chomp\r\nputs (s[0...s.length/2] == s[s.length/2..] ? \"YES\" : \"NO\")"}, {"source_code": "n = gets.to_i\na = []\n\ndef find_ans(w)\n if w.length.odd?\n 'NO'\n else\n if w[0..w.length/2 - 1] == w[w.length/2..w.length]\n 'YES'\n else\n 'NO'\n end\n end\nend\n \n(0..n-1).each do |x|\n w = gets.chomp\n\ta.append(find_ans(w))\nend\n \n \na.each do |x|\n p x\nend"}], "src_uid": "9640b7197bd7b8a59f29aecf104291e1"} {"source_code": "n = gets.to_i\nl = Array.new(n)\nr = Array.new(n)\nn.times do |i|\n l[i], r[i] = gets.split.map(&:to_i)\nend\nk = gets.to_i\nputs r.count { |rr| rr >= k }\n", "positive_code": [{"source_code": "\nn = gets.to_i\nch = []\n(1..n).each do |i|\n ch << gets.split(\" \").map(&:to_i)\nend\nk = gets.to_i\n\nres = 0\n(0..n-1).each do |i|\n if k > ch[i][1]\n res += 1\n end\nend\n\nputs n-res\n"}, {"source_code": "n = gets.to_i\nl, r = [], []\nn.times do\n li, ri = gets.split.map(&:to_i)\n l << li\n r << ri\nend\nk = gets.to_i\ni = 0\nloop do\n break if k <= r[i]\n i += 1\nend\nputs n - i\n"}], "negative_code": [], "src_uid": "2545b6af730f99193041a8810b728cb3"} {"source_code": "s=gets.chomp\nn=gets.to_i\nputs s.sizes.size\n\tputs \"impossible\"\nelse\n\tn=s.chars.uniq.size\n\tputs [0, k-n].max\nend\n"}, {"source_code": "s=gets.chomp.chars\nk=gets.to_i\nputs k > s.size ? :impossible : [0, k - s.uniq.size].max"}, {"source_code": "s, k = gets.chomp.chars, gets.to_i\nputs k > s.size ? :impossible : [0, k - s.uniq.size].max"}], "negative_code": [{"source_code": "s=gets.chomp.chars\nk=gets.to_i\nputs k > s.size ? :impossible : [k - s.uniq.size].max"}, {"source_code": "s, cnt, k = gets.chomp, Array.new(26, 0), gets.to_i\ns.chars {|c| cnt[c.ord - 97] += 1}\ncnt.reject! {|c| c.zero?}\nputs k > s.length ? :impossible : k - cnt.length\n"}, {"source_code": "cnt = Array.new(26, 0)\ngets.chomp.chars {|c|\n cnt[c.ord - 97] += 1\n}\ncnt.reject! {|c| c.zero?}\nk = gets.to_i - cnt.length\nputs k > cnt.reduce(:+) ? :impossible : k"}, {"source_code": "cnt = Array.new(26, 0)\ngets.chomp.chars {|c|\n cnt[c.ord - 97] += 1\n}\ncnt.reject! {|c| c.zero?}\nk = gets.to_i\nputs k > cnt.reduce(:+) ? :impossible : k - cnt.length"}], "src_uid": "bd5912fe2c5c37658f28f6b159b39645"} {"source_code": "gets.to_i.times do\r\n gets\r\n s = gets.chomp\r\n answer = s.size\r\n 0.upto(s.size - 2).each do |i|\r\n if s[i] != s[i + 1]\r\n answer += i + 1\r\n end\r\n end\r\n p answer\r\nend\r\n", "positive_code": [{"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ngets.to_i.times do\r\n n = gets.to_i\r\n s = gets.chomp.chars\r\n\r\n ans = n\r\n i = 1\r\n while i < n\r\n if s[i] != s[i-1]\r\n ans += i\r\n end\r\n i += 1\r\n end\r\n\r\n puts ans\r\nend\r\n"}], "negative_code": [], "src_uid": "bc45b3b665ccef5c9451ff2ecc5198a8"} {"source_code": "r = proc {gets.split.map(&:to_i)}\nn = r.call[0]\nx, s = r.call\na = r.call\nb = r.call\nq1 = a.zip(b)\nc = r.call\nd = r.call\nq2 = c.zip(d)\nq2.reverse!\nc = q2.bsearch{|c, d| s>=d} || [0,0]\nsol = (n-c[0]) * x\n(q1.select{|a,b| b<=s}).each do |a,b|\n c = q2.bsearch{|c, d| (s-b)>=d} || [0,0]\n sol = [sol, (n-c[0])*a].min\nend\nputs sol\n", "positive_code": [{"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nab = a.zip(b).sort_by{|_, bi| bi}\ncd = c.zip(d).sort{|u, v|\n if u[1] != v[1]\n v[1] <=> u[1]\n else\n v[0] <=> u[0]\n end\n}\n\nres = n * x\n\nm.times do |i|\n bi = ab[i][1]\n break if bi > s\n ai = ab[i][0]\n res = [res, n * ai].min\n cj, _ = cd.bsearch{|_, dj| bi + dj <= s}\n next if cj.nil?\n if cj <= n\n res = [res, (n - cj) * ai].min\n else\n res = [res, ai].min\n end\nend\ncd.reverse.each do |cj, dj|\n break if dj > s\n if cj <= n\n res = [res, (n - cj) * x].min\n else\n res = [res, x].min\n end\nend\n\nputs res\n\n"}, {"source_code": "#!/bin/ruby\n\n# n m k n = total potions to produce, m = number of a/b, k = number of c/d\n# x s initial rate, manapoints available\n# a1 a2 a3... (new rate, # of seconds per potion)\n# b1 b2 b3... (cost to speed up rate)\n# c1 c2 c3... c1 <= c2, number of instant potions\n# d1 d2 d3... d1 <= d2, cost of instant potions\n\n# min total time spent to produce the potions\n# for picked zero or one spell of each type\n\ndef find_next_smallest(input, target)\n left = 0\n right = input.size - 1\n while right != left\n midpoint = (right + left) / 2\n if right - left == 1\n # adjacent\n if input[right] > target\n return left\n else\n return right\n end\n elsif input[midpoint] > target\n right = midpoint - 1\n else\n left = midpoint\n end\n end\n\n return left\nend\n\n# read input\nn, m, k = gets.strip.split(' ').map{ |x| x.to_i }\nx, s = gets.strip.split(' ').map{ |x| x.to_i }\na = gets.strip.split(' ').map{ |x| x.to_i }\nb = gets.strip.split(' ').map{ |x| x.to_i }\nc = gets.strip.split(' ').map{ |x| x.to_i }\nd = gets.strip.split(' ').map{ |x| x.to_i }\n\n# base case, no type 1 spell\nj = find_next_smallest(d, s)\nrem_potion = n\nrem_potion = n - c[j] if d[j] <= s\nbest_time = rem_potion * x\n\n# consider each type 1 spell\n0.upto(m-1) do |i|\n next if s < b[i]\n\n # find largest type 2 spell that can fit in remainder of s\n target = s - b[i]\n j = find_next_smallest(d, target)\n\n # compute timing\n rem_potion = n\n rem_potion = n - c[j] if d[j] <= target\n time = rem_potion * a[i]\n best_time = time if time < best_time\nend\n\nputs best_time\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nab = a.zip(b).sort_by{|_, bi| bi}\ncd = c.zip(d).sort{|u, v|\n if u[1] != v[1]\n v[1] <=> u[1]\n else\n v[0] <=> u[0]\n end\n}\n\nres = n * x\n\nm.times do |i|\n bi = ab[i][1]\n break if bi > s\n ai = ab[i][0]\n res = [res, n * ai].min\n cj, _ = cd.bsearch{|_, dj| bi + dj <= s}\n next if cj.nil?\n res = [res, (n - cj) * ai].min\nend\ncd.reverse.each do |cj, dj|\n break if dj > s\n res = [res, (n - cj) * x].min\nend\n\nputs res\n\n"}, {"source_code": "n, m, k = gets.strip.split.map(&:to_i)\nx, s = gets.strip.split.map(&:to_i)\nai = gets.strip.split.map(&:to_i)\nbi = gets.strip.split.map(&:to_i)\nci = gets.strip.split.map(&:to_i)\ndi = gets.strip.split.map(&:to_i)\n\ntype2 = []\n(k-1).downto(0).each do |i|\n type2 << [di[i], ci[i]]\nend\n\nans = n*x\n\nsp2 = type2.bsearch{|i| i[0]<=s}\nans = [ans, [n - sp2[1], 0].max * x].min if sp2\n\n0.upto(m-1).each do |i|\n if s >= bi[i]\n rem = s - bi[i]\n sp2 = type2.bsearch{|j| j[0]<=rem}\n if sp2\n ans = [ans, [n - sp2[1], 0].max * ai[i]].min\n else\n ans = [ans, n * ai[i]].min\n end\n end\nend\n\nputs ans"}], "negative_code": [{"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nab = a.zip(b).sort_by{|_, bi| bi}\ncd = c.zip(d).sort_by{|_, di| di}\n\nres = n * x\n\nk.times do |i|\n di = cd[i][1]\n break if di > s\n ci = cd[i][0]\n rm = n\n if ci >= n\n rm = 1\n res = [res, x].min\n else\n rm = n - ci\n res = [res, rm * x].min\n end\n m.times do |j|\n break if ab[j][1] + di > s\n res = [res, rm * ab[j][1]].min\n end\nend\nm.times do |j|\n break if ab[j][1] > s\n res = [res, n * ab[j][0]].min\nend\n\nputs res\n\n\n\n\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nab = a.zip(b).sort_by{|_, bi| bi}\ncd = c.zip(d).sort_by{|_, di| -di}\n\nres = n * x\n\nm.times do |i|\n bi = ab[i][1]\n break if bi > s\n ai = ab[i][0]\n res = [res, n * ai].min\n cj, _ = cd.bsearch{|_, dj| bi + dj <= s}\n next if cj.nil?\n res = [res, (n - cj) * ai].min\nend\ncd.reverse.each do |cj, dj|\n break if dj > s\n res = [res, (n - cj) * x].min\nend\n\nputs res\n\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nab = a.zip(b).sort_by{|_, bi| bi}\ncd = c.zip(d).sort_by{|ci, di| [-di, -ci] }\n\nres = n * x\n\nm.times do |i|\n bi = ab[i][1]\n break if bi > s\n ai = ab[i][0]\n res = [res, n * ai].min\n cj, _ = cd.bsearch{|_, dj| bi + dj <= s}\n next if cj.nil?\n if cj < n\n res = [res, (n - cj) * ai].min\n else\n res = [res, ai].min\n end\nend\ncd.reverse.each do |cj, dj|\n break if dj > s\n if cj < n\n res = [res, (n - cj) * x].min\n else\n res = [res, x].min\n end\nend\n\nputs res\n\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nab = a.zip(b) #.sort_by{|_, bi| bi}\ncd = c.zip(d).reverse #.sort_by{|ci, di| [-di, -ci] }\n\nres = n * x\n\nm.times do |i|\n bi = ab[i][1]\n break if bi > s\n ai = ab[i][0]\n res = [res, n * ai].min\n cj, _ = cd.bsearch{|_, dj| bi + dj <= s}\n next if cj.nil?\n if cj <= n\n res = [res, (n - cj) * ai].min\n else\n res = [res, ai].min\n end\nend\ncd.reverse.each do |cj, dj|\n break if dj > s\n if cj <= n\n res = [res, (n - cj) * x].min\n else\n res = [res, x].min\n end\nend\n\nputs res\n\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nab = a.zip(b).sort_by{|_, bi| bi}.reverse\ncd = c.zip(d).sort_by{|_, di| di}\n\nres = n * x\n\nk.times do |i|\n di = cd[i][1]\n break if di > s\n ci = cd[i][0]\n rm = n\n if ci >= n\n rm = 1\n res = [res, x].min\n else\n rm = n - ci\n res = [res, rm * x].min\n end\n ai, bi = ab.bsearch{|_, bi| bi + di <= s}\n res = [res, rm * ai].min\nend\nm.times do |j|\n break if ab[j][1] > s\n res = [res, n * ab[j][0]].min\nend\n\nputs res\n\n\n"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nab = a.zip(b).sort_by{|_, bi| bi}\ncd = c.zip(d).sort_by{|_, di| di}\n\nres = n * x\n\nk.times do |i|\n di = cd[i][1]\n break if di > s\n ci = cd[i][0]\n rm = n\n if ci >= n\n rm = 1\n res = [res, x].min\n next\n else\n rm = n - ci\n res = [res, rm * x].min\n end\n m.times do |j|\n break if ab[j][1] + di > s\n res = [res, rm * ab[j][1]].min\n end\nend\nm.times do |j|\n break if ab[j][1] > s\n res = [res, n * ab[j][0]].min\nend\n\nputs res\n\n\n\n\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nab = a.zip(b).sort_by{|_, bi| bi}\ncd = c.zip(d).sort_by{|_, di| -di}\n\nres = n * x\n\nm.times do |i|\n bi = ab[i][1]\n break if bi > s\n ai = ab[i][0]\n res = [res, n * ai].min\n cj, _ = cd.bsearch{|_, dj| bi + dj <= s}\n next if cj.nil?\n res = [res, (n - cj) * ai].min\nend\nk.times do |j|\n break if cd[j][1] > s\n res = [res, (n - cd[j][0]) * x].min\nend\n\nputs res\n\n"}, {"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nab = a.zip(b).sort_by{|_, bi| bi}\ncd = c.zip(d).sort_by{|_, di| -di}\n\nres = n * x\n\nm.times do |i|\n bi = ab[i][1]\n break if bi > s\n ai = ab[i][0]\n res = [res, n * ai].min\n cj, _ = cd.bsearch{|_, dj| bi + dj <= s}\n next if cj.nil?\n if cj < n\n res = [res, (n - cj) * ai].min\n else\n res = [res, ai].min\n end\nend\ncd.reverse.each do |cj, dj|\n break if dj > s\n res = [res, (n - cj) * x].min\nend\n\nputs res\n\n"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nres = n * x\n\nk.times do |i|\n di = d[i]\n break if di > s\n ci = c[i]\n rm = n\n if ci >= n\n rm = 1\n res = [res, x].min\n else\n rm = n - ci\n res = [res, rm * x].min\n end\n m.times do |j|\n break if b[j] + di > s\n res = [res, rm * a[j]].min\n end\nend\nm.times do |j|\n break if b[j] > s\n res = [res, n * a[j]].min\nend\n\nputs res\n\n\n\n\n"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nn, m, k = gis\nx, s = gis\na = gis # speed\nb = gis # cost\nc = gis # create\nd = gis # cost\n\nres = n * x\n\nk.times do |i|\n di = d[i]\n next if di > s\n ci = c[i]\n rm = n\n if ci >= n\n rm = 1\n res = [res, x].min\n else\n rm = n - ci\n res = [res, rm * x].min\n end\nend\nm.times do |j|\n next if b[j] > s\n res = [res, n * a[j]].min\nend\n\nputs res\n\n\n\n\n"}, {"source_code": "r = proc {gets.split.map(&:to_i)}\nn, m, k = r.call\nx, s = r.call\na = r.call\nb = r.call\nq1 = a.zip(b)\nc = r.call\nd = r.call\nq2 = c.zip(d)\nq2.reverse!\nsol = x * n\n(q1.select{|a,b| b<=s}).each do |a,b|\n c = q2.bsearch{|c, d| (s-b) > d} || [0,0]\n sol = [sol, (n-c[0])*a].min\nend\nputs sol\n"}, {"source_code": "r = proc {gets.split.map(&:to_i)}\nn, m, k = r.call\nx, s = r.call\na = r.call\nb = r.call\nq1 = a.zip(b)\nc = r.call\nd = r.call\nq2 = c.zip(d)\nsol = x * n\n(q1.select{|a,b| b<=s}).each do |a,b|\n c = q2.bsearch{|c, d| [(s-b)-d, 0].min} || [0,0]\n sol = [sol, (n-c[0])*a].min\nend\nputs sol\n"}, {"source_code": "r = proc {gets.split.map(&:to_i)}\nn = r.call[0]\nx, s = r.call\na = r.call\nb = r.call\nq1 = a.zip(b)\nc = r.call\nd = r.call\nq2 = c.zip(d)\nq2.reverse!\nc = q2.bsearch{|c, d| s>d} || [0,0]\nsol = (n-c[0]) * x\n(q1.select{|a,b| b<=s}).each do |a,b|\n c = q2.bsearch{|c, d| (s-b)>d} || [0,0]\n sol = [sol, (n-c[0])*a].min\nend\nputs sol\n"}], "src_uid": "2f9f2bdf059e5ab9c64e7b5f27cba0cb"} {"source_code": "class Solver\n\n def self.solve(string)\n result = {}\n height = 0\n result[0] = [0]\n index = 0\n string.each_char do |char|\n index += 1\n height = height + (char == '1' ? 1 : -1)\n if result.fetch(height, nil).nil?\n result[height] = [index]\n elsif result[height].size == 1\n result[height] << index\n else\n result[height].pop\n result[height].push index\n end\n # puts \"#{height}:#{index}\"\n # puts result\n end\n array_result = result.values\n array_result.select! { |pair| pair.size == 2 }\n # puts array_result.inspect\n return [] if array_result.empty?\n final = array_result.max_by { |pair| pair[1] - pair.first }\n final[1] = final[1] -= 1\n final\n end\n\n def self.size(string)\n result = self.solve(string)\n # puts result\n return 0 if result.empty?\n result[1] - result[0] + 1\n end\nend\n\nstring = ARGF.read\narr = string.split\n# puts arr.inspect\nputs Solver.size(arr[1])\n", "positive_code": [{"source_code": "gets\ni=1\nhs={}\na=0\nans=0\ngets.chomp.chars.each{|e|\n\ta+=1 if e==\"1\"\n\tb=i-a\n\tif b==a\n\t\tans=i\n\telse\n\t\tif hs.key?(b-a)\n\t\t\tans=[ans,i-hs[b-a]].max\n\t\tend\n\tend\n\tif hs.key?(b-a)==false\n\t\ths[b-a]=i\n\tend\n\ti+=1\n}\nputs ans"}], "negative_code": [{"source_code": "class Solver\n\n def self.solve(string)\n result = {}\n height = 0\n result[0] = [0]\n string.each_char_with_index do |char, index|\n index += 1\n height = height + (char == '1' ? 1 : -1)\n if result.fetch(height, nil).nil?\n result[height] = [index]\n elsif result[height].size == 1\n result[height] << index\n else\n result[height].pop\n result[height].push index\n end\n puts \"#{height}:#{index}\"\n puts result\n end\n array_result = result.values\n array_result.select! { |pair| pair.size == 2 }\n puts array_result\n return [] if array_result.empty?\n final = array_result.max_by { |pair| pair[1] - pair.first }\n final[1] = final[1] -= 1\n final\n end\n\n def self.size(string)\n result = self.solve(string)\n puts result\n return 0 if result.empty?\n result[1] - result[0] + 1\n end\nend\n"}, {"source_code": "class Solver\n\n def self.solve(string)\n result = {}\n height = 0\n result[0] = [0]\n index = 0\n string.each_char do |char|\n index += 1\n height = height + (char == '1' ? 1 : -1)\n if result.fetch(height, nil).nil?\n result[height] = [index]\n elsif result[height].size == 1\n result[height] << index\n else\n result[height].pop\n result[height].push index\n end\n # puts \"#{height}:#{index}\"\n # puts result\n end\n array_result = result.values\n array_result.select! { |pair| pair.size == 2 }\n # puts array_result\n return [] if array_result.empty?\n final = array_result.max_by { |pair| pair[1] - pair.first }\n final[1] = final[1] -= 1\n final\n end\n\n def self.size(string)\n result = self.solve(string)\n # puts result\n return 0 if result.empty?\n result[1] - result[0] + 1\n end\nend\n\nstring = ARGF.read\nputs Solver.size(string)\n"}, {"source_code": "class Solver\n\n def self.solve(string)\n result = {}\n height = 0\n result[0] = [0]\n index = 0\n string.each_char do |char|\n index += 1\n height = height + (char == '1' ? 1 : -1)\n if result.fetch(height, nil).nil?\n result[height] = [index]\n elsif result[height].size == 1\n result[height] << index\n else\n result[height].pop\n result[height].push index\n end\n # puts \"#{height}:#{index}\"\n # puts result\n end\n array_result = result.values\n array_result.select! { |pair| pair.size == 2 }\n # puts array_result.inspect\n return [] if array_result.empty?\n final = array_result.max_by { |pair| pair[1] - pair.first }\n final[1] = final[1] -= 1\n final\n end\n\n def self.size(string)\n result = self.solve(string)\n # puts result\n return 0 if result.empty?\n result[1] - result[0] + 1\n end\nend\n\nstring = ARGF.read\nputs Solver.size(string.strip)\n"}], "src_uid": "08fa04303060d38d6cd0f3a321a527ad"} {"source_code": "gets.to_i.times do\n moves = gets.split(' ').map(&:to_i)\n points = gets.split(' ').map(&:to_i)\n\n left = moves[0]\n right = moves[1]\n down = moves[2]\n up = moves[3]\n\n start_x, start_y = points[0], points[1]\n min_x, min_y = points[2], points[3]\n max_x, max_y = points[4], points[5]\n\n if ((start_x - left + right).between?(min_x, max_x) && (min_x < max_x || left + right == 0)) &&\n ((start_y - down + up).between?(min_y, max_y)) && (min_y < max_y || down + up == 0)\n \n puts \"Yes\"\n else\n puts \"No\"\n end\nend", "positive_code": [{"source_code": "gets.to_i.times do\n left, right, down, up = gets.split(' ').map(&:to_i)\n start_x, start_y, min_x, min_y, max_x, max_y = gets.split(' ').map(&:to_i)\n\n if (start_x - left + right).between?(min_x, max_x) && \n (start_y - down + up).between?(min_y, max_y) &&\n (min_x < max_x || left + right == 0) &&\n (min_y < max_y || down + up == 0) \n puts \"Yes\"\n else\n puts \"No\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\n\nn.times do\n a,b,c,d = gets.chomp.split.map(&:to_i)\n\n x,y,x1,y1,x2,y2 = gets.chomp.split.map(&:to_i)\n\n if x1 == x2 && (a > 0 || b > 0)\n puts 'No'\n next\n end\n\n if y1 == y2 && (c > 0 || d > 0)\n puts 'No'\n next\n end\n\n x += b - a\n y += d - c\n if x1 <= x && x <= x2 && y1 <= y && y <= y2\n puts 'Yes'\n else\n puts 'No'\n end\nend\n\n"}, {"source_code": "t = gets.to_i\nt.times do\n a, b, c, d = gets.split.map(&:to_i)\n x, y, x1, y1, x2, y2 = gets.split.map(&:to_i)\n ok = true\n ok = false unless (x1..x2).include?(x - a + b)\n ok = false unless (y1..y2).include?(y - c + d)\n ok = false if (a + b > 0) && (x1 == x2)\n ok = false if (c + d > 0) && (y1 == y2)\n puts ok ? \"YES\" : \"NO\"\nend\n"}, {"source_code": "def solve(d,r)\n d > r\nend\n\nt = gets.to_i\n\nt.times do\n \n l, r, d, u = gets.split.map(&:to_i)\n x, y, xl, yd, xr, yu = gets.split.map(&:to_i)\n \n rr = xr - x\n ll = x - xl\n uu = yu - y\n dd = y - yd\n \n m = rr\n m = ll if m > ll\n m = uu if m > uu\n m = dd if m > dd\n \n if l < r\n if solve(r-l, rr)\n puts \"No\"\n next\n end\n elsif l > r\n if solve(l-r, ll)\n puts \"No\"\n next\n end\n elsif l == r && l > 0\n if ll == 0 && rr == 0\n puts \"No\"\n next\n end\n end\n \n if d < u\n if solve(u-d,uu)\n puts \"No\"\n next\n end\n elsif d > u\n if solve(d-u,dd)\n puts \"No\"\n next\n end\n elsif d == u && d > 0\n if dd == 0 && uu == 0\n puts \"No\"\n next\n end\n end\n \n puts \"Yes\"\nend"}], "negative_code": [{"source_code": "def solve(d,r)\n d > r\nend\n\nt = gets.to_i\n\nt.times do\n \n l, r, d, u = gets.split.map(&:to_i)\n x, y, xl, yd, xr, yu = gets.split.map(&:to_i)\n \n rr = xr - x\n ll = x - xl\n uu = yu - y\n dd = y - yd\n \n m = rr\n m = ll if m > ll\n m = uu if m > uu\n m = dd if m > dd\n \n if l < r\n if solve(r-l, rr)\n puts \"No\"\n next\n end\n elsif l > r\n if solve(l-r, ll)\n puts \"No\"\n next\n end\n elsif l == r && l > 0\n if ll == 0 || rr == 0\n puts \"No\"\n next\n end\n end\n \n if d < u\n if solve(u-d,uu)\n puts \"No\"\n next\n end\n elsif d > u\n if solve(d-u,dd)\n puts \"No\"\n next\n end\n elsif d == u && d > 0\n if dd == 0 || uu == 0\n puts \"No\"\n next\n end\n end\n \n puts \"Yes\"\nend\n"}], "src_uid": "7224ffd4776af4129739e1b28f696050"} {"source_code": "gets\ndp,arr=[0],gets.split.map(&:to_i)\narr.each_with_index{|i,k|dp[k+1]=(dp[k]*2-dp[i-1]+2)%1000000007}\np dp[-1]\n", "positive_code": [{"source_code": "gets\ndp,arr=[0],gets.split.map(&:to_i)\narr.each_with_index{|i,k|dp[k+1]=(dp[k]*2-dp[i-1]+2)%1000000007}\np dp[-1]\n"}, {"source_code": "gets\ndp,arr=[0],gets.split.map(&:to_i)\narr.each_with_index{|i,k|dp[k+1]=(dp[k]*2-dp[i-1]+2)%1000000007}\np dp[-1]\n"}, {"source_code": "=begin\n , \\ / ,\n / \\ )\\__/( / \\\n / \\ (_\\ /_) / \\\n ____/_____\\__\\@ @/___/_____\\____\n | |\\../| |\n | \\VV/ |\n | ------hoi------- |\n |_________________________________|\n | /\\ / \\\\ \\ /\\ |\n | / V )) V \\ |\n |/ ` // ' \\|\n ` V '\n=end\n\ndp, n, arr = [],gets.to_i, gets.split.map(&:to_i)\ndp[0]=0\n(1..n).each{|i|dp[i] = (dp[i - 1] * 2 - dp[arr[i - 1] - 1] + 2) % 1000000007}\np dp[n]"}, {"source_code": "gets\ndp,arr=[0],gets.split.map(&:to_i)\narr.each_with_index{|i,k|dp[k+1]=(dp[k]*2-dp[i-1]+2)%1000000007}\np dp[-1]\n"}, {"source_code": "gets\ndp,arr=[0],gets.split.map(&:to_i)\narr.each_with_index{|i,k|dp[k+1]=(dp[k]*2-dp[i-1]+2)%1000000007}\np dp[-1]"}, {"source_code": "gets\ndp,arr=[0],gets.split.map(&:to_i)\narr.each_with_index{|i,k|dp[k+1]=(dp[k]*2-dp[i-1]+2)%1000000007}\np dp[-1]\n"}, {"source_code": "def f(x)\n if @d[x] != nil\n return @d[x]\n end\n sum = 1\n for i in @p[x]..x - 1\n sum += f(i)\n end\n sum += 1\n @d[x] = sum\n sum\nend\n\nn = Integer gets\n@p = gets.split.map { |x| (Integer x) - 1 }\n@d = Array.new(n, nil)\n@d[0] = 2\nsum = 0\nfor i in 0..n - 1\n sum += f i\nend\nputs sum % (10 ** 9 + 7)"}, {"source_code": "dp,n,arr=[],gets.to_i,gets.split.map(&:to_i)\ndp[0]=0\n(1..n).each{|i|dp[i]=(dp[i-1]*2-dp[arr[i-1]-1]+2)%1000000007}\np dp[n]"}, {"source_code": "dp,n=[],gets.to_i\narr=gets.split.map &:to_i\nMof=1000000007\ndp[0]=0\n(1..n).each{|i|dp[i]=(dp[i-1]*2-dp[arr[i-1]-1]+2)%Mof}\nputs dp[n]"}, {"source_code": "gets\ndp,arr=[0],gets.split.map(&:to_i)\narr.each_with_index{|i,k|dp[k+1]=(dp[k]*2-dp[i-1]+2)%1000000007}\np dp[-1]"}, {"source_code": "MOD = 1000000007\nn = STDIN.readline.to_i\np = [0] + STDIN.readline.split.map { |x| x.to_i }\n\nf = Array.new(n+2,0)\n2.upto(n+1) do |i|\n\tf[i] = f[i-1]+1\n\tt = i-1\n\twhile p[t] != t ;\n\t\tf[i] += f[t]-f[p[t]+1]+2\n\t\tflag = true\n\t\tt = p[t]\n\tend\n\tf[i] += 1\n\tf[i] %= MOD\nend\n\nprint f[n+1]\n"}, {"source_code": "gets\ndp,arr=[0],gets.split.map(&:to_i)\narr.each_with_index{|i,k|dp[k+1]=(dp[k]*2-dp[i-1]+2)%1000000007}\np dp[-1]\n"}, {"source_code": "gets\ndp,arr=[0],gets.split.map(&:to_i)\narr.each_with_index{|i,k|dp[k+1]=(dp[k]*2-dp[i-1]+2)%1000000007}\np dp[-1]\n"}, {"source_code": "gets\ndp,arr=[0],gets.split.map(&:to_i)\narr.each_with_index{|i,k|dp[k+1]=(dp[k]*2-dp[i-1]+2)%1000000007}\np dp[-1]\n"}], "negative_code": [{"source_code": "def f(x)\n if @d[x] != nil\n return @d[x]\n end\n sum = 1\n for i in @p[x]..x - 1\n sum += f(i)\n end\n sum += 1\n @d[x] = sum\n sum\nend\n\nn = Integer gets\n@p = gets.split.map { |x| (Integer x) - 1 }\n@d = Array.new(n, nil)\n@d[0] = 2\nsum = 0\nfor i in 0..n - 1\n sum += f i\nend\nputs sum"}], "src_uid": "7bb5df614d1fc8323eba51d04ee7bf2a"} {"source_code": "n = gets.to_i\nary = gets.strip.split.map(&:to_i).sort\n\nans = 0\nsz =ary.size\n\n1.upto(sz-1).each do |i|\n ans += (ary[i] - ary[i-1] - 1)\nend\n\nputs ans", "positive_code": [{"source_code": "n,*a=$<.read.split.map &:to_i\np a.max-a.min+1-n"}, {"source_code": "n,*a=$<.read.split.map &:to_i\np a.max-a.min+1-n"}, {"source_code": "# TEMPLATE BEGIN\ndef read_vector\n gets.chomp.split(/\\s+/)\nend\ndef read_vector_int\n read_vector.map(&:to_i)\nend\n# TEMPLATE END\n\ngets\na = read_vector_int\nputs a.max - a.min - a.size + 1\n"}, {"source_code": " n,*a=$<.read.split.map &:to_i\n p a.max-a.min+1-n"}, {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i).sort\n\nputs as[-1] - as[0] - n + 1"}, {"source_code": "remain_keyborads = gets.chomp.to_i\nvalues = gets.chomp\n\nremain_keybord_indicies = values.split(' ')\nremain_keybord_indicies.map!(&:to_i)\n\nmax = remain_keybord_indicies.max\nmin = remain_keybord_indicies.min\n\nputs max - min - remain_keyborads + 1"}, {"source_code": "gets\na = gets.split.map(&:to_i).sort\ni = 1\nans = 0\nwhile i < a.size\n ans += a[i] - a[i - 1] - 1\n i += 1\nend\nputs ans\n"}], "negative_code": [{"source_code": "n,*a=$<.read.split.map &:to_i\np n-a.max+a.min-1"}], "src_uid": "6469ed9f2486b498c9ffeb8270391e3a"} {"source_code": "#! ruby -Ku\n# -*- coding: UTF-8 -*-\na = gets\n\nstr_front = \"heavy\"\nstr_rear = \"metal\"\n\ncount_front = 0\nsum_substring = 0\n\noffset_front = 0\noffset_rear = 0\nwhile true\n offset_front_temp = a.index(str_front, offset_front)\n offset_rear_temp = a.index(str_rear, offset_rear)\n if offset_front_temp == nil\n offset_front_temp = 10 ** 6\n offset_front = 10 ** 6\n end\n if offset_rear_temp == nil\n break\n end\n if offset_front_temp < offset_rear_temp\n count_front += 1\n offset_front = offset_front_temp + 4\n else\n sum_substring += count_front\n offset_rear = offset_rear_temp + 4\n end\nend\n\nputs sum_substring\n", "positive_code": [{"source_code": "s = gets\ncount = 0\nheavy = 0\nfor i in 0..s.length-5\n\tif s[i..i+4] == \"heavy\"\n\t\theavy += 1\n\tend\n\n\tif s[i..i+4] == \"metal\"\n\t\tcount += heavy\n\tend\nend\n\nputs count"}, {"source_code": "#!/usr/bin/env ruby\nstr = gets\nharr = []\nmarr = []\nindex = -1\nloop do\n index = str.index('heavy', index + 1)\n break unless index\n harr << index\nend\nindex = -1\nloop do\n index = str.index('metal', index + 1)\n break unless index\n marr << index\nend\nret = 0\nmatch = 0\nharr.each do |hi|\n find = false\n for i in match...marr.size\n match = i\n if marr[i] > hi\n find = true\n break\n end\n end\n ret += marr.size - match if find\nend\nputs ret\n"}, {"source_code": "def get_pos(s, ss)\n x, l = [], ss.length\n i = -l\n while true\n i = s.index(ss, i + l)\n break if i.nil?\n x << i\n end\n x\nend\n\ns = gets.chomp\nx = get_pos(s, \"heavy\")\ny = get_pos(s, \"metal\")\ntotal, pox, poy, sx, sy = 0, 0, 0, x.size, y.size\nwhile pox < sx\n poy += 1 while poy < sy && y[poy] < x[pox]\n total += sy - poy\n pox += 1\nend\nputs total"}, {"source_code": "input = gets.chomp\nheavy = 0\nitr = 0\nlen = input.length\nans = 0\n\nuntil itr >= len\n\tif input[itr] == 'h'\n\t\tif input[itr..(itr+4)] == \"heavy\" \n\t\t\theavy += 1\n\t\t\titr += 5\n\t\telse itr += 1\n\t\tend\n\telsif input[itr] == 'm'\n\t\tif input[itr..(itr+4)] == \"metal\"\n\t\t\tans += heavy\n\t\t\titr += 5\n\t\telse \titr += 1\n\t\tend\n\telse\n\t\titr += 1\n\tend\nend\n\nputs ans\n\n\n\n\n"}, {"source_code": "s = gets.strip\nh = []\nm = []\noffset = 0\n\nwhile n = s.index(\"heavy\", offset) do\n h << n\n offset = n + 1\nend\n\nif h.size == 0 then\n puts 0\n exit\nend\n\noffset = 0\ntotal = 0\nh_idx = -1\nwhile n = s.index(\"metal\", offset) do\n while h_idx+1 < h.size and h[h_idx+1] < n do\n h_idx += 1\n end\n total += h_idx + 1\n offset = n + 1\nend\n\nputs total"}, {"source_code": "S = gets.chomp\n\nh = 0\nans = 0\n\n(0...S.length).each do |i|\n \n h += 1 if S[i,5] == \"heavy\"\n ans += h if S[i,5] == \"metal\"\n\nend\n\nputs ans"}, {"source_code": "s = gets\n\nres = 0\ni=-1\nh = []\nloop do\n i = s.index('heavy', i+1)\n break if i.nil?\n h << i\nend\n\ni=-1\nj=0\nloop do\n i = s.index('metal', i+1)\n break if i.nil?\n\n while j < h.size and h[j] < i\n j+=1\n end\n res += j\nend\n\nputs res\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef get_pos(s, ss)\n\tx, l = [], ss.length\n\ti = -l\n\twhile true\n\t\ti = s.index(ss, i + l)\n\t\tbreak if i.nil?\n\t\tx << i\n\tend\n\tx\nend\n\ns = gets.chomp\nx = get_pos(s, \"heavy\")\ny = get_pos(s, \"metal\")\ntot, px, py, sx, sy = 0, 0, 0, x.size, y.size\nwhile px < sx\n\tpy += 1 while py < sy && y[py] < x[px]\n\ttot += sy - py\n\tpx += 1\nend\nputs tot\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef get_pos(s, ss)\n\tx, ls, lss = [], s.length, ss.length\n\tls.times { |i| x << i if s[i..i+lss-1] == ss }\n\tx\nend\n\ns = gets.chomp\nx = get_pos(s, \"heavy\")\ny = get_pos(s, \"metal\")\ntot, px, py, sx, sy = 0, 0, 0, x.size, y.size\nwhile px < sx\n\tpy += 1 while py < sy && y[py] < x[px]\n\ttot += sy - py\n\tpx += 1\nend\nputs tot\n"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\nstr = gets\nharr = []\nmarr = []\nindex = -1\nloop do\n index = str.index('heavy', index + 1)\n break unless index\n harr << index\nend\nindex = -1\nloop do\n index = str.index('metal', index + 1)\n break unless index\n marr << index\nend\nret = 0\nharr.each do |hi|\n match = 0\n for i in match...marr.size\n match = i\n break if marr[i] >= hi\n end\n ret += marr.size - match\nend\nputs ret\n"}, {"source_code": "def get_pos(s,ss)\n x, l = [],ss.length\n i = -l\n while true\n i = s.index(ss,i+1)\n break if i.nil?\n x << i\n end\n x\nend\n\ns = gets.chomp\nx = get_pos(s,\"heavy\")\ny = get_pos(s,\"metal\")\ntotal,pox,poy,sx,sy = 0,0,0,x.size,y.size\nwhile pox < sx\n py += 1 while poy < sy && y[poy] < x[pox]\n total += sy - poy\n pox += 1\nend\nputs total"}, {"source_code": "def get_pos(s,ss)\n x, l = [],ss.length\n i = -l\n while true\n i = s.index(ss,i+1)\n break if i.nil?\n x << i\n end\n x\nend\n\ns = gets.chomp\nx = get_pos(s,\"heavy\")\ny = get_pos(s,\"metal\")\ntotal,pox,poy,sx,sy = 0,0,0,x.size,y.size\nwhile pox < sx\n py += 1 while poy < sy && y[py] < x[pox]\n total += sy - poy\n pox += 1\nend\nputs total"}, {"source_code": "#! ruby -Ku\n# -*- coding: UTF-8 -*-\na = gets\n# puts a\n\nstr_front = \"heavy\"\nstr_rear = \"metal\"\n\noffset_front = a.index(str_front)\noffset_front_array = [a.index(str_front)]\nwhile offset_front != nil\n offset_front = a.index(str_front, offset_front + 1)\n offset_front_array << offset_front\nend\n\noffset_rear = a.index(str_rear)\noffset_rear_array = [a.index(str_rear)]\nwhile offset_rear != nil\n offset_rear = a.index(str_rear, offset_rear + 1)\n offset_rear_array << offset_rear\nend\n\n# puts offset_front_array\n# puts offset_rear_array\n\ncount_front = 0\nsum_substring = 0\n\noffset_rear = offset_rear_array.first\nwhile offset_rear != nil\n count_front += 1\n val_front = offset_front_array.shift\n val2_front = offset_front_array.first\n offset_rear = offset_rear_array.shift\n if offset_rear == nil\n break\n elsif val2_front == nil\n while offset_rear != nil\n sum_substring += count_front\n offset_rear = offset_rear_array.shift\n end\n else\n while val_front < offset_rear && offset_rear < val2_front\n sum_substring += count_front\n offset_rear = offset_rear_array.first\n if offset_rear == nil\n break\n end\n end\n end\nend\n\nputs sum_substring"}, {"source_code": "#! ruby -Ku\n# -*- coding: UTF-8 -*-\na = gets\n\nstr_front = \"heavy\"\nstr_rear = \"metal\"\n\noffset_front = a.index(str_front)\noffset_front_array = [a.index(str_front)]\nwhile offset_front != nil\n offset_front = a.index(str_front, offset_front + 1)\n offset_front_array << offset_front\nend\n\noffset_rear = a.index(str_rear)\noffset_rear_array = [a.index(str_rear)]\nwhile offset_rear != nil\n offset_rear = a.index(str_rear, offset_rear + 1)\n offset_rear_array << offset_rear\nend\n\n# puts offset_front_array\n# puts offset_rear_array\n\ncount_front = 0\nsum_substring = 0\n\nwhile (offset_rear = offset_rear_array.first) != nil\n count_front += 1\n interval_front = offset_front_array.first(2)\n first_front = interval_front.shift\n second_front = interval_front.shift\n if first_front == nil\n first_front = -1\n end\n if second_front == nil\n second_front = 10**6\n end\n while (first_front < offset_rear) && (offset_rear < second_front)\n sum_substring += count_front\n offset_rear_array.shift\n offset_rear = offset_rear_array.first\n if offset_rear == nil\n break\n end\n end\n offset_front_array.shift\nend\n\nputs sum_substring\n"}, {"source_code": "s = gets\ncount = 0\nfor i in (0..s.length) do\n\ta = s.index(\"heavy\", i)\n\tif a and a == i\n\t\tb = s.index(\"metal\", i)\n\t\tif b and b > a\n\t\t\tcount = count + 1\n\t\tend\n\tend\nend\n\nprint count"}], "src_uid": "960e4c234666d2444b80d5966f1d285d"} {"source_code": "# @type [Integer]\nt = gets.chomp.to_i\n\ndef test_number\n # @type [Integer]\n n = gets.chomp.to_i\n\n if n < 10\n n\n else\n num_sets = (Math.log10 n).floor\n\n (9 * num_sets) + count_remaining_normals(n, num_sets + 1)\n end\nend\n\ndef count_remaining_normals(number, num_digits)\n # @type [String]\n digits = number.to_s\n\n close_guess = digits[0].to_i\n nearest_boundary = Array.new(num_digits, digits[0]).join.to_i\n\n if digits.chars.uniq.length == 1 || number > nearest_boundary\n # Number is ON the boundary, 222 for example\n close_guess\n else\n # Number is under the boundary, 200 for example\n close_guess - 1\n end\nend\n\n(1..t).each do\n puts test_number\nend\n", "positive_code": [{"source_code": "def ordinary_cnt(n)\n if n < 10\n return n\n end\n n_str = n.to_s\n x = (n_str[0 .. 0] * n_str.size).to_i\n if n >= x\n return n_str[0 .. 0].to_i + ordinary_cnt((\"9\" * (n_str.size - 1)).to_i)\n else\n return n_str[0 .. 0].to_i - 1 + ordinary_cnt((\"9\" * (n_str.size - 1)).to_i)\n end\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n printf(\"%d\\n\", ordinary_cnt(n))\nend\n"}, {"source_code": "def find_ordinaries(n)\n\tif(n < 10)\n\t\treturn n\n\tend\n\tnum_of_zeroes = find_num_of_0s(n)\n\ti = 0\n\tj = build_j(num_of_zeroes, n)\n\ti = j\n\tfirst_dig = 10**num_of_zeroes\n\tchange_first = 10**num_of_zeroes\n\tordinaries = num_of_zeroes * 9\n\twhile(true)\n\t\tif(first_dig + j <= n)\n\t\t\tordinaries += 1\n\t\telse\n\t\t\tbreak\n\t\tend\n\t\tj = j + i\n\t\tfirst_dig += change_first\n\tend\n\treturn ordinaries\nend\n\ndef find_num_of_0s(n)\n\tnum_of_zeroes = 0\n\twhile(true)\n\t\tn = n / 10\n\t\tnum_of_zeroes += 1\n\t\tif(n < 1)\n\t\t\tnum_of_zeroes -= 1\n\t\t\tbreak\n\t\tend\n\tend\n\treturn num_of_zeroes\nend\n\ndef build_j(zeroes, n)\n\ti = zeroes\n\tj = 0\n\twhile(i != 0)\n\t\tj += 10**(zeroes - i)\n\t\ti -= 1\n\tend\n\treturn j\nend\n\ntest_cases = gets.to_i\ntest_case_tab = []\n\nuntil(test_case_tab.size == test_cases)\n\ttest_case_tab.push(gets.to_i)\nend\n\ntest_case_tab.each do|val| \n\tord = find_ordinaries(val)\n\tputs ord\nend"}, {"source_code": "results = []\n\nt = gets.chomp\n(1..t.to_i).each do |iteration|\n\tn = gets.chomp.to_i\n\tc = 0\n\tif n > 9\n\t\trz = n.to_s.length\n\t\tc += 9 * (rz - 1)\n\t\thigh_rz = n.to_s[0].to_i\n\t\tc += high_rz\n\t\tc -= 1 if n < (high_rz.to_s * rz).to_i\n\telse\n\t\tc = n % 10\n\tend\n\tresults.push(c)\nend\nresults.each do |res|\n\tputs res\nend"}, {"source_code": "gets.to_i.times {\n n = gets.to_i\n ans = 0\n (1..9).each { |d|\n c = d\n while c <= n\n ans += 1\n c = c * 10 + d\n end\n }\n p ans\n}\n"}], "negative_code": [{"source_code": "results = []\n\nt = gets.chomp\n(1..t.to_i).each do |iteration|\n\tn = gets.chomp.to_i\n\tc = 0\n\tif n > 9\n\t\tc += n.to_s[-2..-1].to_i/11 + 9\n\t\tc += 9*(n/100) if n > 99\n\telse\n\t\tc = n % 10\n\tend\n\tresults.push(c)\nend\nresults.each do |res|\n\tputs res\nend"}, {"source_code": "results = []\n\nt = gets.chomp\n(1..t.to_i).each do |iteration|\n\tn = gets.chomp.to_i\n\tc = 0\n\tif n > 9\n\t\trzrd = n.to_s.split(\"\").length - 2\n\t\tc = n/11 + 9\n\t\tc -= rzrd if rzrd > 0\n\telse\n\t\tc = n % 10\n\tend\n\tresults.push(c)\nend\nresults.each do |res|\n\tputs res\nend"}, {"source_code": "results = []\n\nt = gets.chomp\n(1..t.to_i).each do |iteration|\n\tn = gets.chomp.to_i\n\tc = 0\n\tif n > 9\n\t\tc = n/11 + 9\n\telse\n\t\tc = n % 10\n\tend\n\tresults.push(c)\nend\nresults.each do |res|\n\tputs res\nend"}, {"source_code": "def find_ordinaries(n)\n\tif(n < 10)\n\t\treturn n\n\tend\n\tnum_of_zeroes = find_num_of_0s(n)\n\ti = 0\n\tj = build_j(num_of_zeroes, n)\n\tordinaries = num_of_zeroes * 9\n\twhile(true)\n\t\tif(10**num_of_zeroes + j + i <= n)\n\t\t\tordinaries += 1\n\t\telse\n\t\t\tbreak\n\t\tend\n\t\ti += 10**num_of_zeroes\n\t\tj += j\n\tend\n\treturn ordinaries\nend\n\ndef find_num_of_0s(n)\n\tnum_of_zeroes = 0\n\twhile(true)\n\t\tn = n / 10\n\t\tnum_of_zeroes += 1\n\t\tif(n < 1)\n\t\t\tnum_of_zeroes -= 1\n\t\t\tbreak\n\t\tend\n\tend\n\treturn num_of_zeroes\nend\n\ndef build_j(zeroes, n)\n\ti = zeroes\n\tj = 0\n\twhile(i != 0)\n\t\tj += 10**(zeroes - i)\n\t\ti -= 1\n\tend\n\treturn j\nend\n\ntest_cases = gets.to_i\ntest_case_tab = []\n\nuntil(test_case_tab.size == test_cases)\n\ttest_case_tab.push(gets.to_i)\nend\n\ntest_case_tab.each do|val| \n\tord = find_ordinaries(val)\n\tputs ord\nend"}, {"source_code": "def find_ordinaries(n)\n\tif(n < 10)\n\t\treturn n\n\tend\n\tnum_of_zeroes = find_num_of_0s(n)\n\ti = 0\n\tj = 10**(num_of_zeroes - 1) + 1\n\t(j == 2) ? j = 1 : j = j\n\tordinaries = num_of_zeroes * 9\n\twhile(true)\n\t\tif(10**num_of_zeroes + j + i <= n)\n\t\t\tordinaries += 1\n\t\telse\n\t\t\tbreak\n\t\tend\n\t\ti += 10**num_of_zeroes\n\t\tj += 1\n\tend\n\treturn ordinaries\nend\n\ndef find_num_of_0s(n)\n\tnum_of_zeroes = 0\n\twhile(true)\n\t\tn = n / 10\n\t\tnum_of_zeroes += 1\n\t\tif(n < 1)\n\t\t\tnum_of_zeroes -= 1\n\t\t\tbreak\n\t\tend\n\tend\n\treturn num_of_zeroes\nend\n\ntest_cases = gets.to_i\ntest_case_tab = []\n\nuntil(test_case_tab.size == test_cases)\n\ttest_case_tab.push(gets.to_i)\nend\n\ntest_case_tab.each do|val| \n\tord = find_ordinaries(val)\n\tputs ord\nend"}, {"source_code": "def find_ordinaries(n)\n\tif(n < 10)\n\t\treturn n\n\tend\n\tnum_of_zeroes = find_num_of_0s(n)\n\ti = 0\n\tj = 10**(num_of_zeroes - 1) + 1\n\t(j == 2) ? j = 1 : j = j\n\tordinaries = num_of_zeroes * 9\n\twhile(true)\n\t\tif(10**num_of_zeroes + j + i <= n)\n\t\t\tordinaries += 1\n\t\t\tp num_of_zeroes\n\t\telse\n\t\t\tbreak\n\t\tend\n\t\ti += 10**num_of_zeroes\n\t\tj += 1\n\tend\n\treturn ordinaries\nend\n\ndef find_num_of_0s(n)\n\tnum_of_zeroes = 0\n\twhile(true)\n\t\tn = n / 10\n\t\tnum_of_zeroes += 1\n\t\tif(n < 1)\n\t\t\tnum_of_zeroes -= 1\n\t\t\tbreak\n\t\tend\n\tend\n\treturn num_of_zeroes\nend\n\ntest_cases = gets.to_i\ntest_case_tab = []\n\nuntil(test_case_tab.size == test_cases)\n\ttest_case_tab.push(gets.to_i)\nend\n\ntest_case_tab.each do|val| \n\tord = find_ordinaries(val)\n\tputs ord\nend"}, {"source_code": "def find_ordinaries(n)\n\tif(n < 10)\n\t\treturn n\n\tend\n\tnum_of_zeroes = find_num_of_0s(n)\n\ti = 0\n\tordinaries = num_of_zeroes * 9\n\twhile(true)\n\t\tif(10**num_of_zeroes + 1 + i <= n)\n\t\t\tordinaries += 1\n\t\telse\n\t\t\tbreak\n\t\tend\n\t\ti += 10**num_of_zeroes\n\tend\n\treturn ordinaries\nend\n\ndef find_num_of_0s(n)\n\tnum_of_zeroes = 0\n\twhile(true)\n\t\tn = n / 10\n\t\tnum_of_zeroes += 1\n\t\tif(n < 1)\n\t\t\tnum_of_zeroes -= 1\n\t\t\tbreak\n\t\tend\n\tend\n\treturn num_of_zeroes\nend\n\ntest_cases = gets.to_i\ntest_case_tab = []\n\nuntil(test_case_tab.size == test_cases)\n\ttest_case_tab.push(gets.to_i)\nend\n\ntest_case_tab.each do|val| \n\tord = find_ordinaries(val)\n\tputs ord\nend"}], "src_uid": "ac7d117d58046872e9d665c9f99e5bff"} {"source_code": "t = gets.chomp.to_i\r\n\r\nfor i in (1..t)\r\n n = gets.chomp.to_i\r\n a = gets.chomp.split.map {|el| el.to_i}\r\n b = gets.chomp.split.map {|el| el.to_i}\r\n # maior = [a.max, b.max].max \r\n for j in (0..n-1)\r\n if a[j] < b[j]\r\n temp = a[j]\r\n a[j] = b[j]\r\n b[j] = temp\r\n end\r\n end\r\n puts a.max * b.max\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n xs = gets.split.map(&:to_i)\n ys = gets.split.map(&:to_i)\n\n (0...n).each do |i|\n if ys[i] > xs[i]\n t = ys[i]\n ys[i] = xs[i]\n xs[i] = t\n end\n end\n\n p(xs.max * ys.max)\nend\n"}], "negative_code": [], "src_uid": "56197d2468d8515e520c0d925874bf3b"} {"source_code": "n, k = gets.split.map(&:to_i)\nn.times do |i|\n line = [1]*i +[k-n+1] + [1]*(n-1-i)\n puts line.join(\" \")\nend\n", "positive_code": [{"source_code": "n,k=gets.split.map(&:to_i)\nn.times{|i|a=[0]*n;a[i]=k;puts a.join(' ')}\n\n"}, {"source_code": "n, k = gets.split.map { |x| x.to_i }\nfor i in 0...n\n a = Array.new(n, 0)\n a[i] = k\n puts a * ' '\nend"}, {"source_code": "line = gets.chomp.split(\" \").map { |e| e.to_i }\nn = line[0]\nk = line[1]\nfor i in 0...n\n for j in 0...n\n if (i == j)\n print(k.to_s + \" \")\n else\n print(\"0 \")\n end\n end\n print(\"\\n\")\nend\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nn.times{|i|a=[0]*n;a[i]=k;puts a.join(' ')}\n\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nn.times{|i|a=[0]*n;a[i]=k;puts a.join(' ')}\n\n"}, {"source_code": "#!/usr/bin/ruby\nn,k=gets.split.map(&:to_i)\na=[1]*(n-1)+[k-n+1]\nn.times{|i|puts a.rotate(i)*' '}"}, {"source_code": "n,k=gets.split.map(&:to_i)\nn.times{|i|a=[0]*n;a[i]=k;puts a.join(' ')}\n\n"}, {"source_code": "n,k=gets.split.map &:to_i\nmas=Array.new(n){Array.new(n)}\ni,j=0,0\nwhile(i0\n\tif a==n-1\n\t\tp -1\n\t\texit\n\telse\n\t\tc<<1\n\tend\nend\nb.times{|_|c<<2*2**_}\na.times{c<0\n\tif a==n-1\n\t\tp -1\n\t\texit\n\telse\n\t\tc<<1\n\tend\nend\nb.times{|_|c<<2*2**_}\na.times{c<0\n\tif a==n-1\n\t\tp -1\n\t\texit\n\telse\n\t\tc<<1\n\tend\nend\nb.times{|_|c<<2*2**_}\na.times{c< currSum)\n\t seq[i] = 1\n\t currSum += 1\n\telse\n\t seq[i] = currMax + 1\n\t currSum += (currMax + 1)\n\t currMax += 1\n\t numA += 1\n\tend\n else\n seq[i] = 1\n\tcurrSum += 1\n end\n if(seq[i] > 50000)\n can = false\n\tbreak\n end\nend\n\nif(can && numA == a && numB == b)\n puts seq.join(\" \")\nelse\n puts -1\nend"}, {"source_code": "n,a,b=gets.split.map &:to_i\nc=[1]\nif b==0&&a>0\n\tif a==n-1\n\t\tp -1\n\t\texit\n\telse\n\t\tc<<1\n\tend\nend\nb.times{|_|c<<2*2**_}\na.times{c< 0\n if a == n - 1\n p -1\n exit\n else\n c << 1\n end\nend\nb.times{c << c.inject(&:+) + 1}\na.times{c << c.max + 1}\nc << 1 while c.size < n\nputs c * ' '\n"}, {"source_code": "n,a,b=gets.split.map &:to_i\nc=[1]\nif b==0&&a>0\n\tif a==n-1\n\t\tp -1\n\t\texit\n\telse\n\t\tc<<1\n\tend\nend\nb.times{|_|c<<2*2**_}\na.times{c<0\n\tif a==n-1\n\t\tp -1\n\t\texit\n\telse\n\t\tc<<1\n\tend\nend\nb.times{|_|c<<2*2**_}\na.times{c<0 then\n puts -1\n exit\nend\nb.times{|i|\n sum=0\n (i+1).times{|j|\n sum+=result[j]\n }\n result[i+1]=sum+1\n}\nresult[0]=2 if b==0\nresult[1]=1 if b==0\nstart=b\nif b>0 then\n a.times{\n result[start+1]=result[start]+1\n start+=1\n }\nelse\n start=1\n result[1]=2\n a.times{\n result[start+1]=result[start]+1\n start+=1\n }\n result[1]=1\nend\nif result[start-1]>50000 then\n puts -1\n exit\nend\nn.times{|i| p result[i]}\n"}, {"source_code": "n,a,b=gets.split.map &:to_i\nc=[1]\nif b==0&&a>0\n\tif a==n-1\n\t\tp -1\n\t\texit\n\telse\n\t\tc<<1\n\tend\nend\nb.times{|_|c<<2*2**_}\na.times{c<0\n\tif a==n-1\n\t\tp -1\n\t\texit\n\telse\n\t\tc<<1\n\tend\nend\nb.times{|_|c<<2*2**_}\na.times{c< 0\n if a+1 == n\n puts -1\n exit\n end\n result.push(1)\nend\nb.times { result.push(2*result[-1]) }\na.times { result.push(result[-1]+1) }\nwhile result.length < n\n result.push(result[-1])\nend\nputs result.join ' '\n"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\nif n - (b > 0 ? b+1 : b) - (b > 0 ? a : ( a > 0 ? a+2:1)) < 0\n puts(-1)\nelse\n bb = [1] + (1..b).map {|x| 2**x}.to_a\n bb << 1 if b == 0 and a != 0\n last = bb[-1]\n a.times do |i|\n bb << bb[-1] + 1\n end\n (n-bb.size).times do\n bb << bb[-1]\n end\n puts bb*' '\nend"}, {"source_code": "n,a,b=gets.split.map &:to_i\nc=[1]\nif b==0&&a>0\n\tif a==n-1\n\t\tp -1\n\t\texit\n\telse\n\t\tc<<1\n\tend\nend\nb.times{|_|c<<2*2**_}\na.times{c<0\n if a==n-1\n p -1\n exit\n else\n c<<1\n end\nend\nb.times{|_|c<<2*2**_}\na.times{c<0 then\n a.times{\n result[start+1]=result[start]+1\n start+=1\n }\nelse\n start=1\n result[1]=2\n a.times{\n result[start+1]=result[start]+1\n start+=1\n }\n result[1]=1\nend\nif result[start-1]>50000 then\n puts -1\n exit\nend\nresult.each{|i| p i}\n"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\nresult=Array.new(n,1)\nif a+1==n && a>0 then\n puts -1\n exit\nend\nb.times{|i|\n sum=0\n (i+1).times{|j|\n sum+=result[j]\n }\n result[i+1]=sum+1\n}\nresult[0]=2 if b==0\nresult[1]=1 if b==0\nstart=b\nif b>0 then\n a.times{\n result[start+1]=result[start]+1\n start+=1\n }\nelse\n start=1\n result[1]=2\n a.times{\n result[start+1]=result[start]+1\n start+=1\n }\n result[1]=1\nend\nif result[start-1]>50000 then\n puts -1\n exit\nend\nresult.each{|i| p i}\n"}, {"source_code": "\nn,a,b=gets.split.map(&:to_i)\nresult=Array.new(n,1)\nb.times{|i|\n sum=0\n (i+1).times{|j|\n sum+=result[j]\n }\n result[i+1]=sum+1\n}\nresult[0]=2 if b==0\nstart=b\na.times{\n result[start+1]=result[start]+1\n start+=1\n}\nif result[start-1]>50000 then\n puts -1\n exit\nend\nresult.each{|i| p i}\n"}, {"source_code": "n,a,b=gets.split.map(&:to_i)\nresult=Array.new(n,1)\nb.times{|i|\n sum=0\n (i+1).times{|j|\n sum+=result[j]\n }\n result[i+1]=sum+1\n}\nstart=b\na.times{\n result[start+1]=result[start]+1\n start+=1\n}\nif result[start-1]>50000 then\n puts -1\n exit\nend\nresult.each{|i| p i}\n"}, {"source_code": "n, a, b = STDIN.readline.split.map {|s| s.to_i }\nif a > 0 and b == 0\n puts -1\n exit\nend\nresult = [1]\nb.times { result.push(2*result[-1]) }\na.times { result.push(result[-1]+1) }\nwhile result.length < n\n result.push(result[-1])\nend\nputs result.join ' '\n"}, {"source_code": "n, a, b = STDIN.readline.split.map {|s| s.to_i }\nif a > 0 and b == 0\n puts -1\n exit\nend\nresult = [1]\nb.times { result.push(2**result[-1]) }\na.times { result.push(result[-1]+1) }\nwhile result.length < n\n result.push(result[-1])\nend\nputs result.join ' '\n"}, {"source_code": "n, a, b = STDIN.readline.split.map {|s| s.to_i }\nresult = [1]\nb.times { result.push(2**result[-1]) }\na.times { result.push(result[-1]+1) }\nwhile result.length < n\n result.push(result[-1])\nend\nputs result.join ' '\n"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\nif n - (b > 0 ? b+1 : b) - (b > 0 ? a : ( a > 0 ? a+2:1)) < 0\n puts(-1)\nelse\n bb = [1] + (1..b).map {|x| 2**x}.to_a\n last = bb[-1]\n a.times do |i|\n bb << bb[-1] + 1\n end\n (n-a-b-1).times do\n bb << bb[-1]\n end\n puts bb*' '\nend\n"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\naa = [1] + (1..a+1).to_a\n(n-a-b-2).times do\n aa.unshift(1)\nend\nb.times do\n aa << (aa.inject(:+) + 1)\nend\nputs aa*' '"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\naa = [1] + (1..a+1).to_a\n(n-a-b-2).times do\n aa.unshift(1)\nend\nb.times do\n aa << (aa.inject(:+) + 1)\nend\np aa"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\nif a+b+2 > n\n puts(-1)\nelse\n bb = [1] + (1..b).map {|x| 2**x}.to_a\n last = bb[-1]\n a.times do |i|\n bb << bb[-1] + 1\n end\n (n-a-b-1).times do\n bb << bb[-1]\n end\n puts bb*' '\nend"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\nif n - (b > 0 ? b+1 : b) - (b > 0 ? a : a+2) < 0\n puts(-1)\nelse\n bb = [1] + (1..b).map {|x| 2**x}.to_a\n last = bb[-1]\n a.times do |i|\n bb << bb[-1] + 1\n end\n (n-a-b-1).times do\n bb << bb[-1]\n end\n puts bb*' '\nend"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\nif n - (b > 0 ? b+1 : b) - (b > 0 ? a : ( a > 0 ? a+2:1)) < 0\n puts(-1)\nelse\n bb = [1] + (1..b).map {|x| 2**x}.to_a\n bb << 1 if b == 0\n last = bb[-1]\n a.times do |i|\n bb << bb[-1] + 1\n end\n (n-bb.size).times do\n bb << bb[-1]\n end\n puts bb*' '\nend"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\nbb = [1] + (1..b).map {|x| 2**x}.to_a\nlast = bb[-1]\na.times do |i|\n bb << bb[-1] + 1\nend\n(n-a-b-1).times do\n bb << bb[-1]\nend\nputs bb*' '"}, {"source_code": "line = gets.split\nn = line[0].to_i\na = line[1].to_i\nb = line[2].to_i\n\nseq = Array.new(n)\nseq[0] = 1\n\ncurrSum = 1\ncurrMax = 1\nnumA = 0\nnumB = 0\ncan = true\n\nfor i in 1..(n-1)\n if(numB < b)\n seq[i] = currSum + 1\n\tcurrSum = (2*currSum) + 1 \n\tcurrMax = seq[i]\n\tnumB += 1\n elsif (numA < a)\n seq[i] = currMax + 1\n\tcurrSum += (currMax + 1)\n\tcurrMax += 1\n\tnumA += 1\n else\n seq[i] = 1\n\tcurrSum += 1\n end\n if(seq[i] > 50000)\n can = false\n\tbreak\n end\nend\n\nif(can && numA == a && numB == b)\n puts seq.join(\" \")\nelse\n puts -1\nend"}, {"source_code": "line = gets.split\nn = line[0].to_i\na = line[1].to_i\nb = line[2].to_i\n\nseq = Array.new(n)\nseq[0] = 1\n\ncurrSum = 1\ncurrMax = 1\nnumA = 0\nnumB = 0\ncan = true\n\nfor i in 1..(n-1)\n if(numB < b)\n seq[i] = currSum + 1\n\tcurrSum = (2*currSum) + 1 \n\tcurrMax = seq[i]\n\tnumB += 1\n elsif (numA < a)\n if(currMax + 1 > currSum)\n\t can = false\n\tend\n seq[i] = currMax + 1\n\tcurrSum += (currMax + 1)\n\tcurrMax += 1\n\tnumA += 1\n else\n seq[i] = 1\n\tcurrSum += 1\n end\n if(seq[i] > 50000)\n can = false\n\tbreak\n end\nend\n\nif(can && numA == a && numB == b)\n puts seq.join(\" \")\nelse\n puts -1\nend"}, {"source_code": "line = gets.split\nn = line[0].to_i\na = line[1].to_i\nb = line[2].to_i\n\nseq = Array.new(n)\nseq[0] = 1\n\ncurrSum = 1\ncurrMax = 1\nnumA = 0\nnumB = 0\ncan = true\n\nfor i in 1..(n-1)\n if(numB < b)\n seq[i] = currSum + 1\n\tcurrSum = (2*currSum) + 1 \n\tcurrMax = seq[i]\n\tnumB += 1\n elsif (numA < a)\n seq[i] = currMax + 1\n\tcurrSum += (currMax + 1)\n\tcurrMax += 1\n\tnumA += 1\n else\n seq[i] = 1\n\tcurrSum += 1\n end\n if(seq[i] > 50000)\n can = false\n\tbreak\n end\nend\n\nif(can)\n puts seq.join(\" \")\nelse\n puts -1\nend"}], "src_uid": "573995cbae2a7b28ed92d71c48cd9039"} {"source_code": "s = gets.chomp.chars\na = [0, 0]\ns.each do |x|\n case x\n when 'L'\n a[0] -= 1\n when 'R'\n a[0] += 1\n when 'U'\n a[1] += 1\n when 'D'\n a[1] -= 1\n end\nend\nc = a.map(&:abs).inject(&:+)\nputs s.size.even? && c.even? ? c / 2 : -1\n", "positive_code": [{"source_code": "s=gets.chomp\np s.size%2==1 ? -1 : (s.count(?L)-s.count(?R)).abs+(s.count(?U)-s.count(?D)).abs>>1"}, {"source_code": "s = gets\nx, y = 0, 0\ns.each_char do |c|\n\tif c == \"U\"\n\t\ty += 1\n\telsif c == \"D\"\n\t\ty -= 1\n\telsif c == \"L\"\n\t\tx -= 1\n\telsif c == \"R\"\n\t\tx += 1\n\tend\nend\nx, y = x.abs, y.abs\nputs ((x + y) % 2 == 0) ? (x + y) / 2 : -1\n\n"}, {"source_code": "q = gets.chomp.split(//)\nx,y = 0,0\n\nif q.size.even?\n q.each do |e|\n x += 1 if e == 'R'\n x -= 1 if e == 'L'\n y += 1 if e == 'U'\n y -= 1 if e == 'D'\n end\n puts (x.abs + y.abs) / 2\nelse\n puts -1\nend\n\n\n\n"}, {"source_code": "line = gets.strip.split('')\napsis = 0\nordinat = 0\nline.each do |x|\n if x == 'L'\n apsis -= 1\n elsif x == 'R'\n apsis += 1\n elsif x == 'U'\n ordinat += 1 \n else\n ordinat -= 1\n end\nend\nif (apsis + ordinat).even?\n puts (apsis.abs + ordinat.abs) / 2\nelse\n puts -1\nend"}, {"source_code": "a=b=0\ns=gets.chomp\ns.chars {|c|\n a+=1 if c==?L\n a-=1 if c==?R\n b+=1 if c==?U\n b-=1 if c==?D\n}\np s.size.odd? ? -1 : (a.abs+b.abs)/2\n"}, {"source_code": "s = gets.split('')\nlr = 0\nud = 0\ns.each do |c|\n lr -= 1 if c=='L'\n lr += 1 if c=='R'\n ud -= 1 if c=='D'\n ud += 1 if c=='U'\nend\n\nx = (lr.abs-ud.abs).abs\nputs x%2!=0 ? -1 : x/2+[lr.abs,ud.abs].min\n"}, {"source_code": "route = gets.chomp\nif route.length % 2 == 1\n puts -1\nelse\n no_u = 0\n no_r = 0\n route.split(\"\").each do |c|\n case c\n when \"U\"\n no_u = no_u + 1\n when \"D\"\n no_u = no_u - 1\n when \"R\"\n no_r = no_r + 1\n when \"L\"\n no_r = no_r - 1\n end\n end\n puts (no_u.abs + no_r.abs)/2\nend\n"}, {"source_code": "s=readline.strip\n\nif s.size%2 == 1\n puts -1\nelse\n lr = 0\n ud = 0\n (0...s.size).each do |i|\n if s[i] == 'L'\n lr += 1\n elsif s[i] == 'R'\n lr -= 1\n elsif s[i] == 'U'\n ud += 1\n elsif s[i] == 'D'\n ud -= 1\n end\n end\n sum = lr.abs + ud.abs\n puts sum/2\nend\n"}, {"source_code": "str = gets.chomp.split('')\n\nx = 0\ny = 0\n\nstr.each do |s|\n case s\n when 'L' then x -= 1\n when 'R' then x += 1\n when 'U' then y += 1\n when 'D' then y -= 1\n end\nend\n\nabsX = x.abs\nabsY = y.abs\n\nif absX == absY\n puts absX\nelse\n rest = [absX, absY].max - [absX, absY].min\n \n if rest % 2 == 0\n puts (rest / 2) + [absX, absY].min\n else\n puts -1\n end\nend"}], "negative_code": [{"source_code": "s=gets.chomp\np s.size%2==1 ? -1 : (s.count(?L)-s.count(?R)).abs+(s.count(?U)-s.count(?D)).abs/2"}, {"source_code": "s=gets.chomp\np s.size%2==1 ? -1 : (s.count(?L)-s.count(?R)).abs+(s.count(?U)-s.count(?D)).abs"}, {"source_code": "line = gets.strip.split('')\napsis = 0\nordinat = 0\nline.each do |x|\n if x == 'L'\n apsis -= 1\n elsif x == 'R'\n apsis += 1\n elsif x == 'U'\n ordinat += 1 \n else\n ordinat -= 1\n end\nend\nif ((apsis.even? and ordinat.even?) or (not apsis.even? and not ordinat.even?))\n puts (apsis + ordinat) / 2\nelse\n puts -1\nend"}, {"source_code": "route = gets.chomp\nif route.length % 2 == 1\n puts -1\nelse\n no_u = 0\n no_r = 0\n route.split(\"\").each do |c|\n case c\n when \"U\"\n no_u = no_u + 1\n when \"D\"\n no_u = no_u - 1\n when \"R\"\n no_r = no_r + 1\n when \"L\"\n no_r = no_r - 1\n end\n end\n puts (no_u + no_r)/2\nend\n"}, {"source_code": "route = gets.chomp\nif route.length % 2 == 1\n puts -1\nelse\n no_u = 0\n no_r = 0\n route.split(\"\").each do |c|\n case c\n when \"U\"\n no_u = no_u + 1\n when \"D\"\n no_u = no_u - 1\n when \"R\"\n no_r = no_r + 1\n when \"L\"\n no_r = no_r - 1\n end\n end\n puts (no_u + no_r).abs/2\nend\n"}, {"source_code": "str = gets.chomp.split('')\n\nx = 0\ny = 0\n\nstr.each do |s|\n case s\n when 'L' then x -= 1\n when 'R' then x += 1\n when 'U' then y += 1\n when 'D' then y -= 1\n end\nend\n\nabsX = x.abs\nabsY = y.abs\n\nif absX == absY\n puts absX\nelse\n puts -1\nend"}], "src_uid": "8237ac3f3c2e79f5f70be1595630207e"} {"source_code": "to_i_proc = Proc.new { |n| n.to_i }\nn, m, w = *gets.chomp.split.map!(&to_i_proc)\na = gets.chomp.split.map!(&to_i_proc)\n# n, m, w = *[1, 100000, 1]\n# a = [1000000000]\n\nclass Present\n def initialize(n, m, w, a)\n @n = n\n @m = m\n @w = w\n @a = a\n @record = Array.new(@n)\n solve\n puts @ans\n end\n\nprivate\n def solve\n upperbound = @a.max + @m\n lowerbound = @a.min\n while lowerbound <= upperbound do\n @mid = (lowerbound + upperbound) / 2\n if test\n @ans = @mid\n lowerbound = @mid + 1\n else\n upperbound = @mid - 1\n end\n end\n end\n\n def solvex(mid)\n @mid = mid\n puts test\n end\n\n def test\n sum = 0\n remain = @m\n for i in 0...@n do\n # \u7ef4\u62a4record\u548csum\n @record[i] = 0\n sum -= @record[i - @w] if i - @w >= 0\n\n return false if sum + remain + @a[i] < @mid\n if @a[i] + sum < @mid\n @record[i] = @mid - sum - @a[i]\n sum += @record[i]\n remain -= @record[i]\n end\n end\n return true\n end\nend\n\nPresent.new(n, m, w, a)\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\nn, m, w = STDIN.readline.split.map {|s| s.to_i }\nheights = STDIN.readline.split.map {|s| s.to_i }\n\ndef feasible(n, m, w, bumps)\n\tpressure = 0\n\tloss = (n+w).times.collect { 0 }\n\tn.times do |i|\n\t\tpressure -= loss[i]\n\t\tbumps[i] -= pressure\n\t\tif bumps[i] > 0\n\t\t\tpressure += bumps[i]\n\t\t\tloss[i+w] += bumps[i]\n\t\t\tm -= bumps[i]\n\t\t\treturn false if m < 0\n\t\tend\n\tend\n\treturn true\nend\n\nlow = heights.min\nhigh = heights.max + m\nwhile low != high\n\tmid = (low+high+1)/2\n\tdeficits = heights.map {|height| mid - height }\n\tif feasible(n, m, w, deficits)\n\t\tlow = mid\n\telse\n\t\thigh = mid-1\n\tend\nend\nputs low\n"}, {"source_code": "to_i_proc = Proc.new { |n| n.to_i }\nn, m, w = *gets.chomp.split.map!(&to_i_proc)\na = gets.chomp.split.map!(&to_i_proc)\n# n, m, w = *[1, 100000, 1]\n# a = [1000000000]\n\nclass Present\n def initialize(n, m, w, a)\n @n = n\n @m = m\n @w = w\n @a = a\n @record = Array.new(@n)\n solve\n puts @ans\n end\n\nprivate\n def solve\n upperbound = @a.max + @m\n lowerbound = @a.min\n while lowerbound <= upperbound do\n @mid = (lowerbound + upperbound) / 2\n if test\n @ans = @mid\n lowerbound = @mid + 1\n else\n upperbound = @mid - 1\n end\n end\n end\n\n def test\n sum = 0\n remain = @m\n for i in 0...@n do\n # \u7ef4\u62a4record\u548csum\n @record[i] = 0\n sum -= @record[i - @w] if i - @w >= 0\n\n return false if sum + remain + @a[i] < @mid\n if @a[i] + sum < @mid\n @record[i] = @mid - sum - @a[i]\n sum += @record[i]\n remain -= @record[i]\n end\n end\n return true\n end\nend\n\nPresent.new(n, m, w, a)"}], "negative_code": [{"source_code": "to_i_proc = Proc.new { |n| n.to_i }\nn, m, w = *gets.chomp.split.map!(&to_i_proc)\na = gets.chomp.split.map!(&to_i_proc)\n# n, m, w = *[6, 2, 3]\n# a = [2, 2, 2, 2, 1, 1]\n# n, m, w = *[2, 5, 1]\n# a = [5, 8]\n\nclass Present\n def initialize(n, m, w, a)\n @n = n\n @m = m\n @w = w\n @a = a\n @record = Array.new(@n)\n solve\n @ans = 766 if @ans = 352\n puts @ans\n end\n\nprivate\n def solve\n upperbound = @a.max + @w\n lowerbound = @a.min\n while lowerbound <= upperbound do\n @mid = (lowerbound + upperbound) / 2\n if test\n @ans = @mid\n lowerbound = @mid + 1\n else\n upperbound = @mid - 1\n end\n end\n end\n\n def test\n sum = 0\n remain = @m\n for i in 0...@n do\n # \u7ef4\u62a4record\u548csum\n @record[i] = 0\n sum -= @record[i - @w] if i - @w >= 0\n\n return false if sum + remain + @a[i] < @mid\n if @a[i] + sum < @mid\n @record[i] = @mid - sum - @a[i]\n sum += @record[i]\n remain -= @record[i]\n end\n end\n return true\n end\nend\n\nPresent.new(n, m, w, a)\n"}, {"source_code": "to_i_proc = Proc.new { |n| n.to_i }\nn, m, w = *gets.chomp.split.map!(&to_i_proc)\na = gets.chomp.split.map!(&to_i_proc)\n# n, m, w = *[6, 2, 3]\n# a = [2, 2, 2, 2, 1, 1]\n# n, m, w = *[2, 5, 1]\n# a = [5, 8]\n\nclass Present\n def initialize(n, m, w, a)\n @n = n\n @m = m\n @w = w\n @a = a\n @record = Array.new(@n)\n solve\n @ans = 766 if @ans == 352\n puts @ans\n end\n\nprivate\n def solve\n upperbound = @a.max + @w\n lowerbound = @a.min\n while lowerbound <= upperbound do\n @mid = (lowerbound + upperbound) / 2\n if test\n @ans = @mid\n lowerbound = @mid + 1\n else\n upperbound = @mid - 1\n end\n end\n end\n\n def test\n sum = 0\n remain = @m\n for i in 0...@n do\n # \u7ef4\u62a4record\u548csum\n @record[i] = 0\n sum -= @record[i - @w] if i - @w >= 0\n\n return false if sum + remain + @a[i] < @mid\n if @a[i] + sum < @mid\n @record[i] = @mid - sum - @a[i]\n sum += @record[i]\n remain -= @record[i]\n end\n end\n return true\n end\nend\n\nPresent.new(n, m, w, a)\n"}, {"source_code": "to_i_proc = Proc.new { |n| n.to_i }\nn, m, w = *gets.chomp.split.map!(&to_i_proc)\na = gets.chomp.split.map!(&to_i_proc)\n# n, m, w = *[6, 2, 3]\n# a = [2, 2, 2, 2, 1, 1]\n# n, m, w = *[2, 5, 1]\n# a = [5, 8]\n\nclass Present\n def initialize(n, m, w, a)\n @n = n\n @m = m\n @w = w\n @a = a\n @record = Array.new(@n)\n solve\n puts @ans\n end\n\nprivate\n def solve\n upperbound = @a.max + @w\n lowerbound = @a.min\n while lowerbound <= upperbound do\n @mid = (lowerbound + upperbound) / 2\n if test\n @ans = @mid\n lowerbound = @mid + 1\n else\n upperbound = @mid - 1\n end\n end\n end\n \n def test\n sum = 0\n remain = @m\n for i in 0...@n do\n # \u7ef4\u62a4record\u548csum\n @record[i] = 0\n sum -= @record[i - @w] if i - @w >= 0\n\n return false if sum + remain + @a[i] < @mid\n if @a[i] + sum < @mid\n @record[i] = @mid - sum - @a[i]\n sum += @record[i]\n remain -= @record[i]\n end\n end\n return true\n end\nend\n\nPresent.new(n, m, w, a)\n"}], "src_uid": "48c8dc603511fd3f0e6ad00dfc801a7e"} {"source_code": "def main\n t = gets.chomp.to_i\n t.times { solve }\nend\n\ndef solve\n n = gets.chomp.to_i # not used\n a = gets.chomp.split.map(&:to_i)\n b = gets.chomp.split.map(&:to_i)\n # S = gets.chomp.chars\n a.sort!\n b.sort!\n print a.join(\" \") + \"\\n\"\n print b.join(\" \") + \"\\n\"\nend\n\nmain\n", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i).sort\n b = gets.split.map(&:to_i).sort\n\n puts a.join(' ')\n puts b.join(' ')\nend\n"}, {"source_code": "t = gets.to_i\nwhile t > 0\n t -= 1\n n = gets.to_i\n a = gets.split.map(&:to_i).sort!\n b = gets.split.map(&:to_i).sort!\n puts a.join(' ')\n puts b.join(' ')\nend\n"}], "negative_code": [], "src_uid": "5c6af8ced2c4b8999abccfac5c4d0057"} {"source_code": "N = gets.chomp.to_i\n\nN.times do\n L = gets.chomp.to_i\n seq = gets.chomp\n if L == 2 and seq[1].to_i <= seq[0].to_i\n puts \"NO\"\n next\n end\n (0..L-2).each do |l|\n sub_a = seq[0..l]\n sub_b = seq[l+1..-1]\n if sub_b.to_i > sub_a.to_i\n puts \"YES\"\n puts 2\n puts \"#{sub_a} #{sub_b}\"\n break\n end\n end\nend", "positive_code": [{"source_code": "q = gets.to_i\n\nq.times do\n\n\tn = gets.to_i\n\n\ts = gets.chomp\n\n\tif n == 2 && s[0].to_i >= s[1].to_i\n\t\tputs \"NO\"\n\telse\n\t\tputs \"YES\"\n\t\tputs 2\n\t\tputs \"#{s[0]} #{s[1..s.length-1]}\"\n\tend\t\n\nend"}, {"source_code": "n=gets.to_i\nn.times{gets;s=gets.chomp;puts s[0].to_i>=s[1..-1].to_i ? :NO : \"YES\\n2\\n%s %s\"%[s[0],s[1..-1]]}"}, {"source_code": "def solve(s)\n if s.size == 1\n puts \"YES\"\n puts \"1\"\n puts s\n end\n if s[0].to_i < s.slice(1, s.size).to_i\n puts \"YES\"\n puts 2\n puts \"#{s[0]} #{s.slice(1, s.size)}\"\n else\n puts \"NO\"\n end\nend\n\ngets.strip.to_i.times do\n _ = gets.strip\n solve(gets.strip)\nend"}, {"source_code": "n=gets.to_i\nn.times{gets;s=gets.chomp;puts s[0].to_i>=s[1..-1].to_i ? :NO : \"YES\\n2\\n%s %s\"%[s[0],s[1..-1]]}"}, {"source_code": "gets.to_i.times do\n l = gets.to_i\n s = gets.chomp\n if l == 2 && s[0] >= s[1]\n puts \"NO\"\n next\n end\n puts \"YES\",2,\"#{s[0]} #{s[1..-1]}\"\nend"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nt = gets.to_i\nt.times do\n\tn = gets.to_i\n\tnum = gets.to_s\n\tif n>2 or num[1]>num[0]\n\t\tputs \"YES\"\n\t\tputs 2\n\t\tputs num[0]+\" \"+num[1..-1]\n\telse\n\t\tputs \"NO\"\n\tend\nend"}, {"source_code": "t=gets.to_i\nfor _ in 1..t\n n=gets.to_i\n s=gets.chomp\n if n==2&&s[0]>=s[1]\n puts 'NO'\n else\n puts 'YES'\n puts 2\n puts [s[0], s[1..-1]]*' '\n end\nend\n"}], "negative_code": [{"source_code": "q = gets.to_i\n\nq.times do\n\n\tn = gets.to_i\n\n\ts = gets.chomp\n\n\tif n == 2 && s[0].to_i >= s[1].to_i\n\t\tputs \"NO\"\n\telse\n\t\tputs \"YES\"\n\t\tputs \"#{s[0]} #{s[1..s.length-1]}\"\n\tend\t\n\nend"}, {"source_code": "N = gets.chomp.to_i\n\nN.times do\n L = gets.chomp.to_i\n seq = gets.chomp\n for l in (0..L-2) do\n sub_a = seq[0..l]\n sub_b = seq[l+1..-1]\n if sub_b.to_i > sub_a.to_i\n p \"YES\"\n p 2\n p \"#{sub_a} #{sub_b}\"\n break\n end\n end\nend"}, {"source_code": "N = gets.chomp.to_i\n\nN.times do\n L = gets.chomp.to_i\n seq = gets.chomp\n for l in (0..L-2) do\n sub_a = seq[0..l]\n sub_b = seq[l+1..-1]\n if sub_b.to_i > sub_a.to_i\n puts \"YES\"\n puts 2\n puts \"#{sub_a} #{sub_b}\"\n break\n end\n end\nend"}], "src_uid": "9f87a89c788bd7c7b66e51db9fe47e46"} {"source_code": "x = gets.to_i\n\nif x==1 or x==2\n puts \"No\"\n exit\nelse\n puts \"Yes\"\n \n if x%2==0\n print \"#{x/2} \"\n a = 1\n while (a<=x)\n print \"#{a} \"\n a += 2\n end\n\n puts\n print \"#{x/2} \"\n a = 2\n while (a<=x)\n print \"#{a} \"\n a += 2\n end\n\n else\n\n print \"#{x/2 +1} \"\n a = 1\n while (a<=x)\n print \"#{a} \"\n a += 2\n end\n\n puts\n print \"#{x/2 } \"\n a = 2\n while (a<=x)\n print \"#{a} \"\n a += 2\n end\n end\n puts\nend\n", "positive_code": [{"source_code": "def gcd(a,b)\n (b==0 ? a : gcd(b, a%b))\nend\n\nn = gets.strip.to_i\n\n# 44000.upto(45000).each do |n|\n# puts n if n%1000==0\nif n == 1 || n == 2\n # puts n\n puts \"No\"\nelse\n tot = (n*(n+1))/2\n 2.upto(n).each do |s1|\n s2 = tot - s1\n if gcd(s1,s2)>1\n puts \"Yes\"\n puts \"1 #{s1}\"\n others = (1..n).to_a - [s1]\n puts \"#{others.size} #{others.join(\" \")}\"\n exit 0\n end\n end\n puts \"No\"\nend\n# end"}], "negative_code": [{"source_code": "x = gets.to_i\n\nif x==1 or x==2\n puts \"No\"\n exit\nelse\n puts \"Yes\"\n \n if x%2==0\n print \"#{x/2} \"\n a = 1\n while (a<=x)\n print \"#{a} \"\n a += 2\n end\n\n puts\n print \"#{x/2 +1} \"\n a = 2\n while (a<=x)\n print \"#{a} \"\n a += 2\n end\n\n else\n\n print \"#{x/2 +1} \"\n a = 1\n while (a<=x)\n print \"#{a} \"\n a += 2\n end\n\n puts\n print \"#{x/2 } \"\n a = 2\n while (a<=x)\n print \"#{a} \"\n a += 2\n end\n end\n puts\nend\n"}], "src_uid": "bb7bace930d5c5f231bfc2061576ec45"} {"source_code": "\ninput=gets.split[0].bytes.to_a\nn=input.length\nd=0\nk=0\nn.times{|i|\n if input[i]==40 then\n d+=1\n else\n if d<=0 then\n k+=1\n else\n d-=1\n end\n end\n}\nputs n-d-k\n", "positive_code": [{"source_code": "sum = 0\nbalance = 0\ngets.chomp.chars { |c|\n if c == \")\"\n balance -= 1\n if balance >= 0\n sum += 2\n else\n balance = 0\n end\n else\n balance += 1\n end\n}\n\nputs sum"}, {"source_code": "stk=[]\n\np gets.rstrip.each_char.inject(0){|best,c|\n stk << c if c=='('\n\n if c==')' && stk.last == '('\n best += 2\n stk.pop\n end\n best\n}\n"}, {"source_code": "#Inf = Float::Infinity\n#\n#geti\n#getia(delimiter = \" \")\n#\n#Object # dcopy\n#\n#String # to_a\n# \"abc\".to_a #=> [\"a\",\"b\",\"c\"]\n#String # to_ia\n# \"1 2 3\".to_ia #=> [1,2,3]\n#\n\ninclude Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInf = Float::INFINITY\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\n#until (s = gets.chomp).length.zero?\n1.times do\n s = gets.chomp\n a = 0\n res = 0\n cnt = 0\n s.each_char do |c|\n if c == \"(\"\n a += 1\n cnt += 1\n else\n if a > 0\n a -= 1\n cnt += 1\n end\n end\n res = [res, cnt-a].max\n end\n p res\nend\n\n"}, {"source_code": "input = gets.chomp\nbra = 0\nres = 0\ninput.chars do |c|\n if c == \"(\"\n bra += 1 \n else \n if bra > 0\n bra -= 1\n res += 2\n end\n end\nend\nputs res\n"}, {"source_code": "ans,bal=0,0\ngets.chomp.chars{|c|\n if c==')'\n bal -= 1\n if bal>=0\n ans+=2\n else\n bal = 0\n end\n else\n bal += 1\n end\n}\np ans"}], "negative_code": [{"source_code": "sum = 0\nbalance = 0\ngets.chomp.chars { |c|\n if c == \")\"\n balance -= 1\n if balance >= 0\n sum += 2\n end\n else\n balance += 1\n end\n}\n\nputs sum"}, {"source_code": "s = gets\n\nwhile s.index(/\\(i*\\)/) != nil\n ind1 = s.index(/\\(i*\\)/)\n ind2 = s.index(\")\", ind1)\n s.sub!(/\\(i*\\)/, \"i\"*(ind2-ind1))\nend\n\nmax = 0\nwhile s.index(/(i+)/) != nil\n if $1.length > max\n max = $1.length\n end\n s.sub!(/i+/,\"\")\nend\n\nputs max*2"}, {"source_code": "s = gets\n\nwhile s.index(/\\(i*\\)/) != nil\n ind1 = s.index(/\\(i*\\)/)\n ind2 = s.index(\")\", ind1)\n s.sub!(/\\(i*\\)/, \"i\"*(ind2-ind1))\nend\n\nmax = -1\nwhile s.index(/(i+)/) != nil\n if $1.length > max\n max = $1.length\n end\n s.sub!(/i+/,\"\")\nend\n\nputs max*2"}], "src_uid": "2ce2d0c4ac5e630bafad2127a1b589dd"} {"source_code": "$<.each_with_index{|e,i|\nj=e.index('B')\nif j;c=e.count('B')/2+1;puts [i-1+c,j+c]*' ';break;end\n}", "positive_code": [{"source_code": "n,m=gets.strip.split.map(&:to_i)\n\nary = []\nn.times do\n ary << gets.strip\nend\n\nrf=-1\ncf=-1\nlen = 0\n0.upto(n-1).each do |i|\n 0.upto(m-1).each do |j|\n if ary[i][j]=='B'\n rf=i\n cf=j if cf==-1\n len+=1\n end\n end\n break if rf!=-1\nend\n\n# puts \"#{rf} #{cf} #{len}\"\nputs \"#{rf+1 + (len/2)} #{cf+1 + (len/2)}\""}, {"source_code": "n, m = gets.split.map(&:to_i)\ncs = []\n\nbf = []\nbl = []\n\nn.times do |i|\n gets.chomp.chars.each_with_index do |cell, j|\n if cell == 'B'\n if bf == []\n bf = [i, j]\n end\n bl = [i, j]\n end\n end\nend\n\nna = (bf[0]+bl[0])/2 + 1\nma = (bf[1]+bl[1])/2 + 1\n\nputs \"#{na} #{ma}\""}, {"source_code": "n, m = gets.split.map &:to_i\ns = []\nn.times { s << gets.chomp }\ni, j = 0, 0\ncatch :found do\n n.times do |y|\n m.times do |x|\n if s[y][x] == 'B'\n i, j = y, x\n throw :found\n end\n end\n end\nend\nd = (s[i].rindex('B') - s[i].index('B'))/2\nputs \"#{1 + i + d} #{1 + j + d}\"\n"}], "negative_code": [], "src_uid": "524273686586cdeb7827ffc1ad59d85a"} {"source_code": "s=gets.chomp\nn=gets.to_i\nh=Hash[s.each_char.group_by{|x|x}.map{|k,v|[k,v.size]}]\nif h.size>n\n p -1\n exit\nend\nr=Hash.new(0)\nwhile n>0\n m=h.max_by{|k,v|r.key?(k)?v.to_f/r[k]:2000}\n r[m[0]]+=1\n n-=1\nend\np h.map{|k,v|(v+r[k]-1)/r[k]}.max\nr.each{|k,v|print(k*v)}\n\n\n\n", "positive_code": [{"source_code": "s = gets.chomp.scan(/./)\nn = gets.to_i\na = [0] * 26\nfor x in s\n a[x.ord - 'a'.ord] += 1\nend\nl, r = 0, s.length\nwhile r - l > 1\n m = (r + l) / 2\n cnt = n\n for i in 0...26\n if a[i] != 0\n cnt -= (m + a[i] - 1) / m\n end\n end\n if cnt >= 0\n r = m\n else\n l = m\n end\nend\nans = ''\nfor i in 0...26\n if a[i] != 0\n ans += (i + 'a'.ord).chr * ((a[i] + r - 1) / r)\n end\nend\nif n >= ans.length\n ans += 'a' * (n - ans.length)\nelse\n puts -1\n exit\nend\nputs r\nputs ans"}, {"source_code": "s=gets.chomp\nn=gets.to_i\nh=Hash[s.each_char.group_by{|x|x}.map{|k,v|[k,v.size]}]\nif h.size>n\n p -1\n exit\nend\nr=Hash.new(0)\nwhile n>0\n m=h.max_by{|k,v|r.key?(k)?v.to_f/r[k]:2000}\n r[m[0]]+=1\n n-=1\nend\np h.map{|k,v|(v+r[k]-1)/r[k]}.max\nr.each{|k,v|print(k*v)}\n\n\n\n"}, {"source_code": "s=gets.chomp\nn=gets.to_i\nh=Hash[s.each_char.group_by{|x|x}.map{|k,v|[k,v.size]}]\nif h.size>n\n p -1\n exit\nend\nr=Hash.new(0)\nwhile n>0\n m=h.max_by{|k,v|r.key?(k)?v.to_f/r[k]:2000}\n r[m[0]]+=1\n n-=1\nend\np h.map{|k,v|(v+r[k]-1)/r[k]}.max\nr.each{|k,v|print(k*v)}\n\n\n\n"}, {"source_code": "#!/usr/bin/ruby\nh=Hash.new(0)\ngets.chomp.chars{|c|h[c]+=1}\nn=gets.to_i\nif h.size>n\n\tp -1\n\texit\nend\na=h.sort_by{|e|-e[1]}\nx=[1]*a.size\nz=n-a.size\nwhile z>0\n\tb=a.each_with_index.max_by{|e,i|e.last*1.0/(x[i])}\n\tx[b.last]+=1\n\tz-=1\nend\np a.each_with_index.map{|e,i|(e.last+x[i]-1)/x[i]}.max\nputs a.each_with_index.map{|e,i|e.first*x[i]}*''"}, {"source_code": "#!/usr/bin/ruby\nh=Hash.new(0)\ngets.chomp.chars{|c|h[c]+=1}\nn=gets.to_i\nif h.size>n\n\tp -1\n\texit\nend\na=h.sort_by{|e|-e[1]}\nx=[1]*a.size\n(n-a.size).times{x[a.each_with_index.max_by{|e,i|e.last*1.0/x[i]}.last]+=1}\np a.each_with_index.map{|e,i|(e.last+x[i]-1)/x[i]}.max\nputs a.each_with_index.map{|e,i|e.first*x[i]}*''"}, {"source_code": "s=gets.chomp\nn=gets.to_i\nh=Hash[s.each_char.group_by{|x|x}.map{|k,v|[k,v.size]}]\nif h.size>n\n p -1\n exit\nend\nr=Hash.new(0)\nwhile n>0\n m=h.max_by{|k,v|r.key?(k)?v.to_f/r[k]:2000}\n r[m[0]]+=1\n n-=1\nend\np h.map{|k,v|(v+r[k]-1)/r[k]}.max\nr.each{|k,v|print(k*v)}\n\n\n\n"}, {"source_code": "s=gets.chomp\nn=gets.to_i\nh=Hash[s.each_char.group_by{|x|x}.map{|k,v|[k,v.size]}]\nif h.size>n\n p -1\n exit\nend\nr=Hash.new(0)\nwhile n>0\n m=h.max_by{|k,v|r.key?(k)?v.to_f/r[k]:2000}\n r[m[0]]+=1\n n-=1\nend\np h.map{|k,v|(v+r[k]-1)/r[k]}.max\nr.each{|k,v|print(k*v)}\n\n\n\n"}, {"source_code": "s=gets.chomp\nn=gets.to_i\nh=Hash[s.each_char.group_by{|x|x}.map{|k,v|[k,v.size]}]\nif h.size>n\n p -1\n exit\nend\nr=Hash.new(0)\nwhile n>0\n m=h.max_by{|k,v|r.key?(k)?v.to_f/r[k]:2000}\n r[m[0]]+=1\n n-=1\nend\np h.map{|k,v|(v+r[k]-1)/r[k]}.max\nr.each{|k,v|print(k*v)}\n\n\n"}, {"source_code": "s=gets.chomp\nn=gets.to_i\nh=Hash[s.each_char.group_by{|x|x}.map{|k,v|[k,v.size]}]\nif h.size>n\n p -1\n exit\nend\nr=Hash.new(0)\nwhile n>0\n m=h.max_by{|k,v|r.key?(k)?v.to_f/r[k]:2000}\n r[m[0]]+=1\n n-=1\nend\np h.map{|k,v|(v+r[k]-1)/r[k]}.max\nr.each{|k,v|print(k*v)}\n\n\n\n"}, {"source_code": "s=gets.chomp\nn=gets.to_i\nh=Hash[s.each_char.group_by{|x|x}.map{|k,v|[k,v.size]}]\nif h.size>n\n p -1\n exit\nend\nr=Hash.new(0)\nwhile n>0\n m=h.max_by{|k,v|r.key?(k)?v.to_f/r[k]:2000}\n r[m[0]]+=1\n n-=1\nend\np h.map{|k,v|(v+r[k]-1)/r[k]}.max\nr.each{|k,v|print(k*v)}\n\n\n\n"}, {"source_code": "s=gets.chomp\nn=gets.to_i\nh=Hash[s.each_char.group_by{|x|x}.map{|k,v|[k,v.size]}]\nif h.size>n\n p -1\n exit\nend\nr=Hash.new(0)\nwhile n>0\n m=h.max_by{|k,v|r.key?(k)?v.to_f/r[k]:2000}\n r[m[0]]+=1\n n-=1\nend\np h.map{|k,v|(v+r[k]-1)/r[k]}.max\nr.each{|k,v|print(k*v)}\n\n\n"}, {"source_code": "s=gets.chomp\nn=gets.to_i\nh=Hash[s.each_char.group_by{|x|x}.map{|k,v|[k,v.size]}]\nif h.size>n\n p -1\n exit\nend\nr=Hash.new(0)\nwhile n>0\n m=h.max_by{|k,v|r.key?(k)?v.to_f/r[k]:2000}\n r[m[0]]+=1\n n-=1\nend\np h.map{|k,v|(v+r[k]-1)/r[k]}.max\nr.each{|k,v|print(k*v)}\n\n\n\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nh=Hash.new(0)\ngets.chomp.chars{|c|h[c]+=1}\nn=gets.to_i\nif h.size>n\n\tp -1\n\texit\nend\na=h.sort_by{|e|-e[1]}\nx=[1]*a.size\nz=n-a.size\nwhile z>0\n\tb=a.each_with_index.max_by{|e,i|e.last*1.0/(x[i]+1)}\n\tx[b.last]+=1\n\tz-=1\nend\np a.each_with_index.map{|e,i|(e.last*1.0/x[i]).ceil}.max\nputs a.each_with_index.map{|e,i|e.first*x[i]}*''"}, {"source_code": "#!/usr/bin/ruby\nh=Hash.new(0)\ngets.chomp.chars{|c|h[c]+=1}\nn=gets.to_i\nif h.size>n\n\tp -1\n\texit\nend\na=h.sort_by{|e|-e[1]}\nx=[1]*a.size\nz=n-a.size\nwhile z>0\n\tb=a.each_with_index.max_by{|e,i|e.last*1.0/(x[i]+1)}\n\tx[b.last]+=1\n\tz-=1\nend\np a.each_with_index.map{|e,i|(e.last+x[i]-1)/x[i]}.max\nputs a.each_with_index.map{|e,i|e.first*x[i]}*''"}, {"source_code": "s=gets.chomp\nn=gets.to_i\nh=Hash[s.each_char.group_by{|x|x}.map{|k,v|[k,v.size]}]\nif h.size>n\n p -1\n exit\nend\nr=Hash.new(0)\nwhile n>0\n m=h.max_by{|k,v|r.key?(k)?v/r[k]:2000}\n r[m[0]]+=1\n n-=1\nend\np h.map{|k,v|(v+r[k]-1)/r[k]}.max\nr.each{|k,v|print(k*v)}\n\n\n"}], "src_uid": "f16f00edbc0c2e984caa04f71ae0324e"} {"source_code": "def check_letter (line_num, board)\n\tdiagonals_letters = []\n\tother_letters = []\n\tboard.each_with_index do |letter_line, index|\n\t\tif (index == (line_num/2))\n\t\t\tdiagonals_letters << letter_line[index]\n\t\t\tletter_line.delete_at(index)\n\t\t\tletter_line.each { |c| other_letters << c }\n\t\telsif (index > (line_num/2))\n\t\t\tdiagonals_letters << letter_line[index]\n\t\t\tdiagonals_letters << letter_line[-(index+1)]\n\t\t\tletter_line.delete_at(index)\n\t\t\tletter_line.delete_at(-index)\n\t\t\tletter_line.each { |c| other_letters << c }\n\t\telse\n\t\t\tdiagonals_letters << letter_line[index]\n\t\t\tdiagonals_letters << letter_line[-(index+1)]\n\t\t\tletter_line.delete_at(index)\n\t\t\tletter_line.delete_at(-(index+1))\n\t\t\tletter_line.each { |c| other_letters << c }\n\t\tend\n\tend\n\n\tif ((diagonals_letters.uniq).length == 1) and ((other_letters.uniq).length == 1) and (diagonals_letters[0] != other_letters[0])\n\t\treturn \"YES\"\n\telse\n\t\treturn \"NO\"\n\tend\nend \n\nline_num = ((gets()).split().shift()).to_i\n\nletter_board = []\n\nfor i in 0..(line_num-1)\n\trow = []\n\trow = (gets()).split(//)\n\trow.delete(\"\\n\")\n\tletter_board << row\nend\n\nresult = check_letter(line_num, letter_board)\nputs result", "positive_code": [{"source_code": "n = gets.to_i\na = n.times.map{gets.chomp.chars}\nc = Array.new(123, 0)\na.each{|x| x.each{|y| c[y.ord] += 1}}\nb = c.each.with_index.sort.reverse\n\nans = true\nn.times do |i|\n ans = false if a[i][i] != a[i][n - 1 - i] || a[i][i] != a[0][0]\n ans = false if c[a[0][0].ord] != 2 * n - 1 || c[a[0][1].ord] != (n - 2) * n + 1\n# p c[a[0][0].ord], c[a[0][1].ord]\nend\n\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.chomp.chars}\nc = Array.new(123, 0)\na.each{|x| x.each{|y| c[y.ord] += 1}}\n\nans = true\nn.times do |i|\n ans = false if a[i][i] != a[i][n - 1 - i] || a[i][i] != a[0][0]\n ans = false if c[a[0][0].ord] != 2 * n - 1 || c[a[0][1].ord] != (n - 2) * n + 1\nend\n\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "def run(l)\n c1 = l[0][0]\n\n hv = l.size/2\n c2 = l[hv][0]\n\n return \"NO\" if c1 == c2\n\n (0...l.size).each do |i|\n (0...l.size).each do |j|\n if i == j\n return \"NO\" if l[i][j] != c1\n elsif i == l.size-1-j\n return \"NO\" if l[i][j] != c1\n else\n return \"NO\" if l[i][j] != c2\n end\n end\n end\n\n return \"YES\"\nend\n\nn = gets\nwhile n != nil\n l = []\n n.to_i.times do\n t = gets.split(//)[0...-1]\n l << t\n end\n puts run(l)\n n = gets\nend\n\n\n"}, {"source_code": "n = gets.to_i\na = (0...n).map { gets.chomp }\nx = a[0][0]\ns = a[0][1]\nif x == s\n puts 'NO'\n exit\nend\nputs((0...n).all? { |i| str = s * n; str[i] = str[n - 1 - i] = x; a[i] == str } ? 'YES' : 'NO')"}, {"source_code": "n = gets.to_i\na = (0...n).map { gets.chomp }\nx = a[0][0]\ns = a[0][1]\nif x == s\n puts 'NO'\n exit\nend\nputs((0...n).all? { |i| str = s * n; str[i] = str[n - 1 - i] = x; a[i] == str } ? 'YES' : 'NO')"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\ns=$<.map(&:chomp)\na=s[0][0,1]\nb=s[0][1,1]\nt=n.times.map{|i|\n\tz=b*n\n\tz[i,1]=a\n\tz[n-i-1,1]=a\n\tz\n}\nputs a!=b&&s==t ? 'YES' : 'NO'"}, {"source_code": "n=gets.chomp.to_i\na=[]\nn.times do\n\ta.push(gets.chomp.strip)\nend\nx=a[0][0]\ns=a[0][1]\nif x==s\n\tputs 'NO'\n\texit\nend\nputs((0...n).all? { |i| str = s * n; str[i] = str[n - 1 - i] = x; a[i] == str } ? 'YES' : 'NO')"}, {"source_code": "n = gets.to_i\nm = []\n\nn.times do\n\tm << gets.chop.split(//)\nend\n\ndef method matr, n\n\td = matr[0][0]\n\to = matr[0][1]\n\n\treturn 'NO' if o == d\n\n\tfor i in 0...n\n\t\tfor j in 0...n\n\t\t\tif i == j or i == n - j - 1\n\t\t\t\tif d != matr[i][j]\n\t\t\t\t\treturn 'NO'\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tif o != matr[i][j]\n\t\t\t\t\treturn \"NO\"\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\n\treturn 'YES'\nend\n\nputs method(m, n)"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @size = @dats[0].to_i\n end\n\n def solve\n return false if @size % 2 != 1 || @size >= 300 || @size < 3\n mtx = []\n (1..@size).each do |idx|\n mtx << @dats[idx]\n end\n mtx.flatten!\n mtx = mtx.join(\"\").split(//)\n diag_char = nil\n not_diag_char = nil\n\n mtx.each_with_index do |char,idx|\n row = idx / @size \n row_mod = row % @size\n \n if idx == row*@size + row_mod || idx == (row+1)*@size - row_mod - 1\n if diag_char.nil?\n diag_char = char\n else\n if diag_char != char\n return false\n end\n end\n else\n if not_diag_char.nil?\n not_diag_char = char\n return false if not_diag_char == diag_char \n else\n if not_diag_char != char\n return false\n end\n end\n end\n end\n return true\n end\nend\n\nsolver = ProblemA.new\nprint solver.solve ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.chomp.to_i\npaper = []\nuniq = []\nvalid = true\nn.times do\n line = gets.chomp.split(\"\")\n uniq << line.uniq if !uniq.include? line.uniq\n paper << line\n if uniq.length > 2\n valid = false\n break\n end\nend\npos = []\nx = 0\ny = n - 1\nui = uj = di = dj = 0\nwhile x < n && y >= 0 && valid\n ui = x\n uj = x\n di = y\n dj = x\n pos << [ui, uj] if !pos.include? [ui, uj]\n pos << [di, dj] if !pos.include? [di, dj]\n x += 1\n y -= 1\nend\nx = paper[0][0]\ny = paper[0][1]\npos.sort!\ncenter = (pos.length - 1) / 2\nvalid = x != y if valid\nstart = 0\nfin = start + 1\n(0...n).each do |i|\n break if !valid\n line = paper[i].clone\n d_index = 0\n pos.values_at(start..fin).each do |p|\n b = p[1]\n if x != paper[i][b]\n valid = false\n break\n elsif x == paper[i][b]\n line.delete_at( b - d_index )\n d_index += 1\n end\n end\n line.uniq!\n if line.length > 1\n valid = false\n break\n else\n if y != line[0]\n valid = false\n break\n end\n end\n start = fin + 1\n if start == center\n fin = start\n else\n fin = start + 1\n end\nend\nif valid\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n=gets.to_i\ns=STDIN.read.split.map{|e| e.chars.to_a}\nok=\"YES\"\nx=s[0][0]\nif n>1 then\n\ty=s[0][1]\n\tok=\"NO\" if y==x\n\tn.times{|i|\n\t\tok=\"NO\" if s[i][i]!=x || s[i][n-i-1]!=x\t\n\t\ts[i].delete_at([n-i-1,i].max)\n\t\tif i!=n-i-1 then\n\t\t\ts[i].delete_at([i,n-i-1].min)\n\t\tend\n\t\t\n\t\ts[i].delete(y)\n\t\tok=\"NO\" if s[i].size>0\n\t}\nend\nputs ok\n\n"}, {"source_code": "n=gets.to_i\nm=[]\n\nn.times do\n m<= 300 || @size < 3\n mtx = []\n (1..@size).each do |idx|\n mtx << @dats[idx]\n end\n mtx.flatten!\n mtx = mtx.join(\"\").split(//)\n diag_char = nil\n not_diag_char = nil\n\n mtx.each_with_index do |char,idx|\n row = idx / @size \n row_mod = row % @size\n \n if idx == row*@size + row_mod || idx == (row+1)*@size - row_mod - 1\n if diag_char.nil?\n diag_char = char\n else\n if diag_char != char\n return false\n end\n end\n else\n if not_diag_char.nil?\n not_diag_char = char \n else\n if not_diag_char != char\n return false\n end\n end\n end\n end\n return true\n end\nend\n\nsolver = ProblemA.new\nprint solver.solve ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.chomp.to_i\npaper = []\nuniq = []\nvalid = true\nn.times do\n line = gets.chomp.split(\"\")\n uniq << line.uniq if !uniq.include? line.uniq\n paper << line\n if uniq.length > 2\n valid = false\n break\n end\nend\npos = []\nx = 0\ny = n - 1\nui = uj = di = dj = 0\nwhile x < n && y >= 0 && valid\n ui = x\n uj = x\n di = y\n dj = x\n pos << [ui, uj] if !pos.include? [ui, uj]\n pos << [di, dj] if !pos.include? [di, dj]\n x += 1\n y -= 1\nend\nx = paper[0][0]\ny = paper[0][1]\npos.sort!\ncenter = (pos.length - 1) / 2\nvalid = x != y if valid\nstart = 0\nfin = start + 1\n(0...n).each do |i|\n break if !valid\n line = paper[i].clone\n d_index = 0\n puts pos.inspect\n pos.values_at(start..fin).each do |p|\n b = p[1]\n if x != paper[i][b]\n valid = false\n break\n elsif x == paper[i][b]\n line.delete_at( b - d_index )\n d_index += 1\n end\n end\n line.uniq!\n valid = false if line.length > 1\n start = fin + 1\n if start == center\n fin = start\n else\n fin = start + 1\n end\nend\nif valid\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\npaper = []\nn.times do\n paper << gets.chomp.split(\"\")\nend\npos = []\nx = 0\ny = n - 1\nui = uj = di = dj = 0\nwhile x < n && y >= 0\n ui = x\n uj = x\n di = y\n dj = x\n pos << [ui, uj] if !pos.include? [ui, uj]\n pos << [di, dj] if !pos.include? [di, dj]\n x += 1\n y -= 1\nend\nvalid = true\nx = paper[0][0]\ny = paper[0][1]\n(0...n).each do |i|\n break if !valid\n (0...n).each do |j|\n break if !valid\n if pos.include? [i, j]\n if x != paper[i][j]\n valid = false\n end\n else\n if y != paper[i][j]\n valid = false\n end\n end\n end\nend\nif valid\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\npaper = []\nuniq = []\nvalid = true\nn.times do\n line = gets.chomp.split(\"\")\n uniq << line.uniq if !uniq.include? line.uniq\n paper << line\n if uniq.length > 2\n valid = false\n break\n end\nend\nif valid\n pos = []\n x = 0\n y = n - 1\n ui = uj = di = dj = 0\n while x < n && y >= 0\n ui = x\n uj = x\n di = y\n dj = x\n pos << [ui, uj] if !pos.include? [ui, uj]\n pos << [di, dj] if !pos.include? [di, dj]\n x += 1\n y -= 1\n end\n x = paper[0][0]\n y = paper[0][1]\n valid = x != y\n pos.each do |p|\n break if !valid\n i = p[0]\n j = p[1]\n if x != paper[i][j]\n valid = false\n end\n end\nend\nif valid\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\npaper = []\nuniq = []\nvalid = true\nn.times do\n line = gets.chomp.split(\"\")\n uniq << line.uniq if !uniq.include? line.uniq\n paper << line\n if uniq.length > 2\n valid = false\n break\n end\nend\npos = []\nx = 0\ny = n - 1\nui = uj = di = dj = 0\nwhile x < n && y >= 0 && valid\n ui = x\n uj = x\n di = y\n dj = x\n pos << [ui, uj] if !pos.include? [ui, uj]\n pos << [di, dj] if !pos.include? [di, dj]\n x += 1\n y -= 1\nend\nx = paper[0][0]\ny = paper[0][1]\npos.sort!\ncenter = (pos.length - 1) / 2\nvalid = x != y if valid\nstart = 0\nfin = start + 1\n(0...n).each do |i|\n break if !valid\n line = paper[i].clone\n d_index = 0\n pos.values_at(start..fin).each do |p|\n b = p[1]\n if x != paper[i][b]\n valid = false\n break\n elsif x == paper[i][b]\n line.delete_at( b - d_index )\n d_index += 1\n end\n end\n line.uniq!\n valid = false if line.length > 1\n start = fin + 1\n if start == center\n fin = start\n else\n fin = start + 1\n end\nend\nif valid\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n=gets.to_i\ns=STDIN.read.split.map{|e| e.chars.to_a}\nok=\"YES\"\nx=s[0][0]\nif n>1 then\n\tn.times{|i|\n\t\tok=\"NO\" if s[i][i]!=x || s[i][n-i-1]!=x\t\n\t\ts[i].delete_at([n-i-1,i].max)\n\t\tif i!=n-i-1 then\n\t\t\ts[i].delete_at([i,n-i-1].min)\n\t\tend\n\t\tok=\"NO\" if s[i][0]==x\n\t\ts[i].delete(s[i][0])\n\t\tok=\"NO\" if s[i].size>0\n\t}\nend\nputs ok\n\n"}, {"source_code": "n=gets.to_i\nm=[]\n\nn.times do\n m< (line_num/2))\n\t\t\tdiagonals_letters << letter_line[index]\n\t\t\tdiagonals_letters << letter_line[-(index+1)]\n\t\t\tletter_line.delete_at(index)\n\t\t\tletter_line.delete_at(-index)\n\t\t\tletter_line.each { |c| other_letters << c }\n\t\telse\n\t\t\tdiagonals_letters << letter_line[index]\n\t\t\tdiagonals_letters << letter_line[-(index+1)]\n\t\t\tletter_line.delete_at(index)\n\t\t\tletter_line.delete_at(-(index+1))\n\t\t\tletter_line.each { |c| other_letters << c }\n\t\tend\n\tend\n\n\tif ((diagonals_letters.uniq).length == 1) and ((other_letters.uniq).length == 1)\n\t\treturn \"YES\"\n\telse\n\t\treturn \"NO\"\n\tend\nend \n\nline_num = ((gets()).split().shift()).to_i\n\nletter_board = []\n\nfor i in 0..(line_num-1)\n\trow = []\n\trow = (gets()).split(//)\n\trow.delete(\"\\n\")\n\tletter_board << row\nend\n\nresult = check_letter(line_num, letter_board)\nputs result"}, {"source_code": "def check_letter (line_num, board)\n\tdiagonals_letters = []\n\tother_letters = []\n\tboard.each_with_index do |letter_line, index|\n\t\tif (index == (line_num/2))\n\t\t\tdiagonals_letters << letter_line[index]\n\t\t\tletter_line.delete_at(index)\n\t\t\tletter_line.each { |c| other_letters << c }\n\t\telsif (index > (line_num/2))\n\t\t\tdiagonals_letters << letter_line[index]\n\t\t\tdiagonals_letters << letter_line[-(index+1)]\n\t\t\tletter_line.delete_at(index)\n\t\t\tletter_line.delete_at(-index)\n\t\t\tletter_line.each { |c| other_letters << c }\n\t\telse\n\t\t\tdiagonals_letters << letter_line[index]\n\t\t\tdiagonals_letters << letter_line[-(index+1)]\n\t\t\tletter_line.delete_at(index)\n\t\t\tletter_line.delete_at(-(index+1))\n\t\t\tletter_line.each { |c| other_letters << c }\n\t\tend\n\tend\n\n\tp diagonals_letters\n\tp other_letters\n\n\tif ((diagonals_letters.uniq).length == 1) and ((other_letters.uniq).length == 1)\n\t\treturn \"YES\"\n\telse\n\t\treturn \"NO\"\n\tend\nend \n\nline_num = ((gets()).split().shift()).to_i\n\nletter_board = []\n\nfor i in 0..(line_num-1)\n\trow = []\n\trow = (gets()).split(//)\n\trow.delete(\"\\n\")\n\tletter_board << row\nend\n\np check_letter(line_num, letter_board)"}, {"source_code": "n = gets.to_i\na = (0...n).map { gets.chomp }\nx = a[0][0]\ns = a[0][1]\nputs((0...n).all? { |i| str = s * n; str[i] = str[n - 1 - i] = x; a[i] == str } ? 'YES' : 'NO')"}], "src_uid": "02a9081aed29ea92aae13950a6d48325"} {"source_code": "n = gets.to_i\ntime = Time.now\ns = gets.chomp.split('')\ncl = ['R', 'G', 'B']\nmn = s.size\nres = s\ncl.permutation.each do |cur|\n t = 0\n str = s.dup\n str.each_with_index do |e, ind|\n if (e != cur[ind % 3])\n t += 1\n str[ind] = cur[ind % 3]\n end\n end\n if (t < mn)\n mn = t\n res = str\n end\nend\nputs mn\nputs res.join('')\n# puts Time.now - time", "positive_code": [{"source_code": "n = gets.to_i\ns = gets.chomp.chars\nputs %w[R G B].permutation.map { |rgb| (0...n).map { rgb[_1 % 3] } }.map { |t|\n\t\t[s.zip(t).count { _1 != _2 }, t.join]\n }.min\n"}, {"source_code": "class Strand\n\n def initialize\n @counts = {\n 'R' => 0,\n 'G' => 0,\n 'B' => 0,\n }\n end\n\n def increase(c)\n @counts[c] += 1\n end\n\n def moves_to_change_to(c)\n @counts.to_a.select{|k, _| k != c }.map{ |_, v| v }.reduce(0, :+)\n end\n\nend\n\ndef solution\n read_int\n gs = read_string\n\n def color_index(c)\n return 0 if c == \"R\"\n return 1 if c == \"G\"\n return 2 if c == \"B\"\n end\n\n s = [\n Strand.new,\n Strand.new,\n Strand.new\n ]\n\n for i in (0...gs.size)\n crt = gs[i]\n j = i % 3\n s[j].increase(crt)\n end\n\n min_moves = gs.size\n best = nil\n for three_cols in (\"RGB\".chars.permutation)\n total_moves = (0...3).map{ |i| s[i].moves_to_change_to(three_cols[i])}.reduce(0, :+)\n if min_moves > total_moves\n min_moves = total_moves\n best = three_cols\n end\n end\n\n final = (0...gs.size).map { |i| best[i % 3] }.join\n\n\n puts min_moves\n puts final\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']"}, {"source_code": "salts = %w(RGB RBG BRG BGR GRB GBR)\n\nn = Integer(gets)\ns = gets\n\ndef dif(s, t, n)\n d = 0\n n.times do |i|\n d = d + 1 if s[i] != t[i]\n end\n d\nend\n\nbest = \"\"\nbest_dif = s.size + 1\n\nsalts.each do |salt|\n t = (salt * (n / 3 + 2))[0..(n - 1)]\n d = dif(s, t, n)\n if d < best_dif\n best = t\n best_dif = d\n end\nend\n\nputs best_dif\nputs best\n"}], "negative_code": [{"source_code": "n = gets.to_i\ns = gets.chomp.chars\nputs (0...3).map { |k| (0...n).map { 'RGB'[(k + _1) % 3] } }.map { |t|\n\t\t[s.zip(t).count { _1 != _2 }, t.join]\n }.min\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp.split('')\narr = Array.new(3){{'R'=> 0, 'G'=> 0, 'B'=> 0}}\ns.each_with_index do |e, ind|\n arr[ind % 3][e] += 1\nend\n# puts arr.to_s\nres = Array.new(3){0}\n3.times do |i|\n res[i] = arr[i].max_by{|e, ee| ee}[1]\nend\n3.times do |i|\n res[i] = arr[i].select{|e, ee| ee == res[i]}.keys\nend\n# puts res.to_s\nbrr = []\narr.each_with_index do |e, ind|\n e.each do |k, v|\n brr << {'K'=> k, 'V' => v, 'I'=> ind}\n end\nend\nbrr = brr.sort_by{|e| e['V']}.reverse\n# puts brr.to_s\nans = Array.new(3){'_'}\ncolors = ['R', 'G', 'B']\nbrr.each do |e|\n if (ans[e['I']] == '_' && colors.include?(e['K']))\n ans[e['I']] = e['K']\n colors.delete(e['K'])\n end\nend\n\ncur = 0\ns.each_with_index do |e, ind|\n if (e != ans[ind % 3])\n cur += 1\n s[ind] = ans[ind % 3]\n end\nend\nputs cur\nputs s.join('')"}, {"source_code": "n = gets.to_i\ns = gets.chomp.split('')\narr = Array.new(3){{'R'=> 0, 'G'=> 0, 'B'=> 0}}\ns.each_with_index do |e, ind|\n arr[ind % 3][e] += 1\nend\n# puts arr.to_s\nbrr = []\narr.each_with_index do |e, ind|\n e.each do |k, v|\n brr << {'K'=> k, 'V' => v, 'I'=> ind}\n end\nend\nbrr = brr.sort_by{|e| e['V']}.reverse\n# puts brr\nans = Array.new(3){'_'}\ncolors = ['R', 'G', 'B']\nbrr.each do |e|\n if (ans[e['I']] == '_' && colors.include?(e['K']))\n ans[e['I']] = e['K']\n colors.delete(e['K'])\n end\nend\n\ncur = 0\ns.each_with_index do |e, ind|\n if (s[ind] != ans[ind % 3])\n cur += 1\n s[ind] = ans[ind % 3]\n end\nend\nputs cur\nputs s.join('')"}, {"source_code": "salts = %w(RGB RBG BRG BGR GRB GBR)\n\nn = Integer(gets)\ns = gets\n\ndef dif(s, t, n)\n d = 0\n n.times do |i|\n d = d + 1 if s[i] != t[i]\n end\n d\nend\n\nbest = \"\"\nbest_dif = s.size + 1\n\nsalts.each do |salt|\n t = (salt * (n / 3 + 2))[0..(n - 1)]\n puts t\n d = dif(s, t, n)\n if d < best_dif\n best = t\n best_dif = d\n end\nend\n\nputs best_dif\nputs best\n"}], "src_uid": "e67b79e39511b0107a51edc0179afb82"} {"source_code": "def min(a,b)\n a < b ? a : b\nend\n\ngets.to_i.times do\n x, y, p, q = gets.split(/\\s+/).map(&:to_i)\n\n if p == q\n ans = x == y ? 0 : -1\n elsif p == 0\n ans = x == 0 ? 0 : -1\n else\n d = p*y - q*x\n k = q - p\n if d == 0\n ans = 0\n elsif d > 0 && d % k == 0\n ans = d/k\n else\n k = ((y - x.to_f) / (q - p)).ceil\n if k*p < x\n k = x / p + min(x%p, 1)\n end\n\n if k * q - y < 0\n ans = -1\n else\n ans = q*k-y\n end\n end\n end\n\n puts ans\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n x, y, p, q=gets.split.map &:to_i\n \n if (x0 and p==0)\n puts -1\n elsif x*q==y*p\n puts 0\n elsif x*q>y*p\n b=64\n n=(1<0\n v=(n-a)*q-y\n n-=a if v>0 and x*q<=(v+y)*p\n a>>=1\n end\n puts n*q-y\n else\n b=64\n n=(1<0\n v=(n-a)*q-y\n n-=a if v>0 and (v+x)*q>=(v+y)*p\n a>>=1\n end\n puts n*q-y\n end\nend\n"}, {"source_code": "n = gets.to_i\nfor _ in 0 ... n\n x, y, p, q = gets.split.map(&:to_i)\n y -= x\n q -= p\n if p == 0 || q == 0\n if (x == 0 && p == 0) || (y == 0 && q == 0)\n puts 0\n else\n puts(-1)\n end\n next\n end\n a1 = (x + p - 1) / p\n a2 = (y + q - 1) / q\n a = [a1, a2].max\n r1 = a * p - x\n r2 = a * q - y\n puts r1 + r2\nend\n\n"}], "negative_code": [{"source_code": "n = gets.to_i\nfor i in 0 ... n\n x, y, p, q = gets.split.map(&:to_i)\n y -= x\n q -= p\n if p == 0 || q == 0\n puts(-1)\n next\n end\n a1 = (x + p - 1) / p\n a2 = (y + q - 1) / q\n a = [a1, a2].max\n r1 = a * p - x\n r2 = a * q - y\n puts r1 + r2\nend\n\n"}, {"source_code": "gets.to_i.times do\n x, y, p, q=gets.split.map &:to_i\n\n if xy*p\n n=(1<<60)-1\n a=1<<59\n while a>0\n v=(n-a)*q-y\n n-=a if v>0 and x*q<=(v+y)*p\n a>>=1\n end\n puts n*q-y\n else\n n=(1<<60)-1\n a=1<<59\n while a>0\n v=(n-a)*q-y\n n-=a if v>0 and (v+x)*q>=(v+y)*p\n a>>=1\n end\n puts n*q-y\n end\nend\n"}, {"source_code": "gets.to_i.times do\n x, y, p, q=gets.split.map &:to_i\n \n if xy*p\n b=64\n n=(1<0\n v=(n-a)*q-y\n n-=a if v>0 and x*q<=(v+y)*p\n a>>=1\n end\n puts n*q-y\n else\n b=64\n n=(1<0\n v=(n-a)*q-y\n n-=a if v>0 and (v+x)*q>=(v+y)*p\n a>>=1\n end\n puts n*q-y\n end\nend\n"}], "src_uid": "589f3f7366d1e0f9185ed0926f5a10bb"} {"source_code": "for i in 0..gets.to_i-1\r\n\tn=gets.to_i\r\n\ta=gets[..-2]\r\n\tb=gets[..-2]\r\n\tk=0\r\n\tfor i in 0..n-1 do\r\n\t\tif b[i]=='1'\r\n\t\t\tif a[i]=='0'\r\n\t\t\t\tk+=1\r\n\t\t\telsif i-1>=0 and a[i-1]=='1'\r\n\t\t\t\tk+=1\r\n\t\t\t\ta[i-1]='0'\r\n\t\t\telsif i+1 0\r\n c += 1\r\n ap[i - 1] = 0\r\n elsif ep[i] == 1 && ap[i + 1] == 1 && i < n - 1\r\n c +=1\r\n ap[i + 1] = 0\r\n elsif ep[i] == 0 && ap[i] == 1\r\n c += 1\r\n ap[i] = 0\r\n end\r\n end\r\n puts c\r\nend\r\n\r\ndef main\r\n gi.times { solve }\r\nend\r\n\r\nmain\r\n"}], "negative_code": [{"source_code": "for i in 0..gets.to_i-1\r\n n=gets.to_i\r\n a=gets[..-2]\r\n b=gets[..-2]\r\n k=0\r\n for i in 0..n-1 do\r\n \tif b[i]=='1'\r\n \t\tif a[i]=='0'\r\n \t\t\tk+=1\r\n \t\telsif i-1>=0 and a[i-1]=='1'\r\n \t\t\tk+=1\r\n \t\telsif i+10\nputs ans"}, {"source_code": "n = gets.to_i\ns = gets.split.map &:to_i\n\ns = s.sort.reverse\n\ni = 0\nj = s.size - 1\nwhile i < j\n if s[i] + s[j] > 4\n i += 1\n else\n j -= 1\n s[i] += s[j]\n end\nend\n\nputs i+1"}, {"source_code": "c=[0]*5\ngets\ngets.split.each{|_|c[_.to_i]+=1}\np ([0,c[1]-c[3]].max+2*c[2]+3)/4+c[3]+c[4]\n"}, {"source_code": "n = gets.to_i\n\ngroups = [0,0,0,0,0]\ncars = 0\n\ngets.split.map(&:to_i).each do |c|\n groups[c] += 1\nend\n\ncars += groups[4]\n\ncars += groups[3]\ngroups[1] -= groups[3]\n\ncars += groups[2] / 2\n\nif groups[2].odd?\n cars += 1\n groups[1] -= 2\nend\n\ncars += (groups[1].to_f / 4).ceil if groups[1] > 0\n\nputs cars"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c-b*2%4].max+3)/4--b/2+c+d"}, {"source_code": "gets\ns = gets.split.map(&:to_i)\na = s.count 4\nb = s.count 3\nc = s.count 2\nd = s.count 1\nputs a + b + (c+1)/2 + ([d - b - (c%2)*2, 0].max + 3)/4"}, {"source_code": "s=[*$<][1].split.map &:to_i\nb=s.count 3\nc=s.count 2\np s.count(4)+b+(c+1)/2+([s.count(1)-b-c*2%4,0].max+3)/4"}, {"source_code": "j = gets.chomp.to_i - 1\ng = gets.chomp.split(\" \").map(&:to_i).sort.reverse\ng.each_with_index do |e, i|\n\tif g[i] == 4\n\t\tnext\n\tend\n\n\tj.downto(i+1) do |b|\n\t\tif g[i] + g[b] > 4\n\t\t\tbreak\n\t\telse\n\t\t\tg[i] += g[b]\n\t\t\tg.delete_at(b)\n\t\t\tj -= 1\n\t\tend\n\tend\nend\nprint g.length"}, {"source_code": "j = gets.chomp.to_i - 1\ng = gets.chomp.split(\" \").map(&:to_i).sort.reverse\nt = 0\ng.each_with_index do |e, i|\n\tif g[i] == 4\n\t\tt += 1\n\t\tnext\n\tend\n\n\tj.downto(i+1) do |b|\n\t\tif g[i] + g[b] > 4\n\t\t\tbreak\n\t\telse\n\t\t\tg[i] += g[b]\n\t\t\tg[b] = 0\n\t\t\tj -= 1\n\t\tend\n\tend\nend\ng.reject! { |e| e == 0 }\nprint g.length"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d"}, {"source_code": "n = gets.to_i\ns = gets.split.map &:to_i\n\ncount = s.find_all{|e| e == 4}.size\ns = s.reject {|e| e == 4}\n\ns = s.sort.reverse\n\n\ni = 0\nj = s.size - 1\nwhile i < j && s[i] == 3 && s[j] == 1\n s[i] = nil\n s[j] = nil\n i += 1\n j -= 1\n count += 1\nend\n\ns = s.compact\n\nfor i in 0..s.size - 1 do\n next if s[i].nil?\n count += 1\n next if s[i] == 3\n sum = s[i]\n for j in i+1..s.size - 1 do\n next if s[j].nil?\n if sum + s[j] <= 4\n sum +=s[j]\n s[j] = nil\n end\n break if sum == 4\n end\nend\n\nputs count\n\n"}, {"source_code": "n = gets.to_i\ns = gets.split.map &:to_i\n\ns = s.sort.reverse\n\ni = 0\nj = s.size - 1\nwhile i < j\n if s[i] + s[j] > 4\n i += 1\n else\n j -= 1\n s[i] += s[j]\n end\nend\n\nputs i+1"}, {"source_code": "#!/usr/bin/env ruby -w\n\ngets\ngroups = gets.split(' ').map(&:to_i)\n\nq_groups= [0, 0, 0, 0, 0]\nn_taxis = 0\n\ngroups.each do |e|\n q_groups[e] += 1\nend\n\nn_taxis += q_groups[4]\n\nn_taxis += q_groups[3]\nq_groups[1] = [0, q_groups[1] - q_groups[3]].max\n\nn_taxis += q_groups[2] / 2\nq_groups[2] %= 2\n\nif q_groups[2] > 0\n n_taxis += q_groups[2]\n q_groups[1] = [0, q_groups[1] - 2].max\nend\n\nn_taxis += q_groups[1] / 4 + (q_groups[1] % 4 > 0 ? 1 : 0)\n\nprint n_taxis\n"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d"}, {"source_code": "c=[0]*5\ngets\ngets.split.each{|_|c[_.to_i]+=1}\np ([0,c[1]-c[3]].max+2*c[2]+3)/4+c[3]+c[4]"}, {"source_code": "gets\na = gets.split(/\\s+/).map{ |i| i.to_i }.inject(Array.new(5, 0)){ |a, i| a[i] += 1; a }\n\nres = a[4]\n\nres += a[3]\na[1] -= a[3];\n\ntwo = (a[2]+1)/2\nres += two\na[1] -= 2 if(a[2] % 2 == 1)\n\nres += (a[1]+3)/4 if(a[1] > 0)\n\nputs res\n"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d"}, {"source_code": "def get_number_of_cars(groups)\n size_distribution = groups.inject([0,0,0,0]) do |array, group| \n array[group - 1] += 1\n array\n end\n\n # for 4\n numbers_of_cars = size_distribution[3]\n size_distribution[3] = 0\n\n # for 2\n numbers_of_cars += size_distribution[1] / 2\n size_distribution[1] = size_distribution[1] % 2\n\n # for 2 1 1\n if size_distribution[1] > 0 and size_distribution[0] > 1\n cars_211 = [size_distribution[1], size_distribution[0]/2].min\n numbers_of_cars += cars_211\n size_distribution[1] -= cars_211\n size_distribution[0] -= cars_211*2\n end\n \n # for 3 1\n if size_distribution[2] > 0 and size_distribution[0] > 1\n cars_31 = [size_distribution[2], size_distribution[0]].min\n numbers_of_cars += cars_31\n size_distribution[2] -= cars_31\n size_distribution[0] -= cars_31\n end\n\n # for 1\n numbers_of_cars += size_distribution[0] / 4\n size_distribution[0] = size_distribution[0] % 4\n\n # the worst case is 111 2 and a lot of 3\n if size_distribution[1] > 0\n numbers_of_cars += 1\n size_distribution[1] = 0\n size_distribution[0] -= 2\n end\n\n if size_distribution[2] > 0\n numbers_of_cars += size_distribution[2]\n size_distribution[0] -= size_distribution[2]\n size_distribution[2] = 0\n end\n\n numbers_of_cars += 1 if size_distribution[0] > 0\n size_distribution[1..2].each { |g| numbers_of_cars += g if g > 0 }\n \n numbers_of_cars\nend\n\nnumber_of_groups = gets().split.map(&:to_i)\ngroups = gets().split.map(&:to_i)\n\nputs get_number_of_cars(groups)"}, {"source_code": "gets\na = Hash.new(0)\nk = 0\ngets.split.map(&:to_i).each { |elem| a[elem]+=1 }\nk += a[4]\nt = [a[3], a[1]].min\nk += t\na[3] -= t\na[1] -= t\nk += a[3]\nk += a[2]/2\na[2] %= 2\nif a[2] > 0\n k += 1\n a[2] = 0\n a[1] -= 2; a[1] = 0 if a[1] < 0\nend\nk += a[1]/4 + (a[1]%4 != 0 ? 1 : 0)\nputs k"}, {"source_code": "n = gets.to_i\ns = gets.chomp.split(\" \").map(&:to_i)\nr = 0\n\ns = s.inject(Hash.new(0)) {|h,i| h[i] += 1; h }\n\nr = s[4]\nt = [s[3],s[1]].min\ns[3]-=t\ns[1]-=t\nr += t + s[3]\nr+=s[2]/2\ns[2]%=2\n\nif s[2] > 0\n r+= 1\n s[1] -= s[2]*2\n s[2] = 0\nend\n\nif s[1]>0\n r+= s[1]/4 + (s[1]%4 != 0 ? 1 : 0)\nend\n\nputs r"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\nwhile three_num > 0 && one_num >0\n three_num -= 1\n one_num -= 1\n res +=1\nend\n\nif two_num % 2 ==0\n res = res + two_num/2\n two_num =0\nelse\n res = res + two_num/2\n two_num = 1\nend\n\nwhile one_num %2 ==0 && two_num >0 && one_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nwhile one_num > 3\n one_num = one_num -4\n res+=1\nend\n\nwhile one_num > 0 && two_num > 0\n res +=1\n one_num -=1\n two_num -=1\nend\n\nif three_num > 0\n res = res + three_num\nend\nif two_num > 0\n res = res + two_num\nend\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "n = gets.strip.to_i\ncount = 0\narr = gets.strip.split(\" \").map(&:to_i)\nfour = arr.count{|elem| elem == 4}\nthree = arr.count{|elem| elem == 3}\ntwo = arr.count{|elem| elem == 2}\none = arr.count{|elem| elem == 1}\ncount += four\none = one > three ? one - three : 0\ncount += three\ncount += two / 2\nif two % 2 == 1 then\n one = one > 1 ? one - 2 : one == 1 ? one - 1 : 0\n count += 1\nend\ncount += one / 4\ncount += 1 if one % 4 != 0\nputs count"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d\n"}, {"source_code": "#get input\nn = gets.chomp.to_i\n_input = gets.chomp.split(\" \")\ns = Hash.new\n# devide input into 4 groups: \n# those which contain 4 elements, 3 elements, 2 ..\ns[1] = Integer(0)\ns[2] = Integer(0)\ns[3] = Integer(0)\ns[4] = Integer(0)\n0.upto n-1 do |i|\n a = _input[i].to_i\n\ts[a]+=1\nend\n\nresult = Integer(0)\nresult += s[4] # groups of 4\nresult += s[3] # groups of 3\nif s[1] > s[3] then\n s[1] -= s[3]\nelse\n s[1] = 0\nend\nresult += s[2] / 2 # groups of 2\nif s[2] % 2 != 0 then s[1] += 2 end\nresult += s[1] / 4 # groups of 1\nif s[1] % 4 != 0 then result += 1 end\n\nputs result"}, {"source_code": "count = Hash.new(0)\n\n_ = gets\ngets.split(' ').each { |x| count[x.to_i] += 1 }\n\nanswer = count[4] + count[3]\ncount[1] = [0, count[1] - count[3]].max\nanswer += (count[2].to_f / 2).ceil\ncount[1] = [0, count[1] - (count[2] % 2) * 2].max\nanswer += (count[1].to_f / 4).ceil\n\nputs answer\n"}, {"source_code": "a=[0]*5\ngets\ngets.split.map {|x| a[x.to_i]+=1}\na[1]=[a[1]-a[3],0].max\nputs a[4]+a[3]+a[2]/2-(-(a[1]+a[2]%2*2))/4"}, {"source_code": "n = gets.chomp;\na = gets.split(\" \").map(&:to_i);\nf = Array.new(5, 0);\nfor i in 0...a.size\n f[a[i]] += 1;\nend\nres = 0\nres += f[4];\nres += f[2] / 2;\nf[2] %= 2;\nmi = [f[1], f[3]].min;\nres += mi;\nf[1] -= mi;\nf[3] -= mi;\nres += f[2];\nf[1] = [f[1] - f[2] * 2, 0].max;\nres += (f[1]/4.0).ceil;\nres += f[3];\nputs res;"}, {"source_code": "gets\nhashed = Hash.new(0)\ngroups = gets.chomp.split.map { |item| item.to_i }.each { |item| hashed[item] += 1 }\nif hashed[1] > hashed[3]\n puts hashed[4] + hashed[3] + ((2 * hashed[2] + (hashed[3] - hashed[1]).abs) / 4.0).ceil\nelse \n puts hashed[4] + hashed[3] + ((2 * hashed[2]) / 4.0).ceil\nend\n"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d\n"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d"}, {"source_code": "limit = gets.to_i\nx = gets.split(\" \").map{|x| x.to_i}\nx =x.sort.reverse\ni=0\nj=limit-1\nans =0\nwhile i<=j\n\tans+=1\n\tfour = 4-x[i]\n\twhile x[j]<=four and j>=i\n\t\tfour-=x[j]\n\t\tj-=1\n\tend\n\ti+=1\nend\nputs ans\n\n\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nfour=b.count('4')\nthree=b.count('3')\ntwo=b.count('2')\none=b.count('1')\nif (three>= one )\nres= four + three + (two/2.0).ceil\nputs \"#{res}\"\nelsif (three < one && two%2 == 0)\nres= four + two/2 + three+ ((one- three)/4.0).ceil\nputs \"#{res}\"\nelsif (three < one && two%2 == 1)\nif (one-three <= 2)\nres= four + (two/2.0).ceil + three\nputs \"#{res}\"\nend\nif (one-three >2)\nres=four+three+(two/2.0).ceil+ ((one-2-three)/4.0).ceil\nputs \"#{res}\"\nend\nend"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d"}, {"source_code": "gets\nca, c = [0] * 5, 0\nSTDIN.read.split.each {|i| ca[i.to_i] += 1}\n\nc += ca[4]\nc += ca[2] / 2\n\nca[2] = ca[2].odd? ? 1 : 0\n\nif ca[1] <= ca[3]\n\tc += ca[1]\n\tca[3] -= ca[1]\n\tca[1] = 0\nelse\n\tc += ca[3]\n\tca[1] -= ca[3]\n\tca[3] = 0\nend\n\nif ca[3] > 0\n\tc += ca[3]\nend\n\nif ca[2] > 0\n\tc += 1\n\tca[1] -= 1 if ca[1] >= 2\n\tca[1] -= 1 if ca[1] >= 1\nend\n\nc += (ca[1] / 4.0).ceil\n\nputs c"}, {"source_code": "gets\na = gets.split.map{|e|e.to_i}\n\n\nn1 = a.count(1)\nn2 = a.count(2)\nn3 = a.count(3)\nn4 = a.count(4)\n\ntotal = n4\n\nn1 -= n3\nn1 = 0 if n1 < 0\n\ntotal += n3\n\ntotal += n2/2\n\nif ( n2 % 2 == 1 )\n n1 -= 2\n n1 = 0 if n1 < 0\n total += 1\nend\n\nif( n1 > 0 )\n total += 1+ (n1-1)/4\nend\n\nputs total\n\n\n"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d\n"}, {"source_code": "def run(groups)\n @sit = 0\n @seats = [0,0,0,0,0]\n\n cars = 0\n groups.map(&:to_i).sort.reverse.each do |group|\n car_for_group(group.to_i)\n end\n @seats[0]\nend\n\ndef car_for_group(group)\n sit = can_sit?(group)\n if sit == 0\n @seats[sit] += 1\n @seats[4 - group] += 1 unless (4 - group) == 0\n else\n @seats[sit] -= 1\n @seats[sit - group] += 1 unless (sit - group) == 0\n end \nend\n\ndef can_sit?(group)\n (group..3).each do |s|\n return s if @seats[s] != 0\n end\n return 0\nend\n\n\nSTDIN.read.split(\"\\n\").each_with_index do |line,i|\n if i % 3 == 1\n groups = line.split(\" \")\n puts run(groups)\n end\nend\n\n"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d"}, {"source_code": "n = gets.chomp.to_i\ngroups = gets.split.collect{|x| x.to_i}\n\ncounts = Array.new(5) { 0 }\nn.times{|i|\n counts[groups[i]] += 1\n}\n\n# all groups of 3 or 4 need a separate car\n# groups of 3 can take extra groups of 1\ncars = counts[4] + counts[3]\ncounts[1] -= counts[3]\n\n# two groups of 2 fit into one car\n# if odd number of groups, the last group of 2 can be combined with two groups of 1\ncars += (counts[2] / 2.to_f).ceil\ncounts[1] -= 2 if counts[2] % 2 != 0\n\n# four groups of 1 fit into one car\ncars += (counts[1] / 4.to_f).ceil if counts[1] > 0\n\nputs cars"}, {"source_code": "t = [0] * 5\ngets\ngets.split.map(&:to_i).each{|_| t[_] += 1}\nputs ([0, t[1] - t[3]].max + 2 * t[2] + 3) / 4 + t[3] + t[4]"}, {"source_code": "limit = gets.to_i\nx = gets.split(\" \").map{|x| x.to_i}\nx =x.sort.reverse\ni=0\nj=limit-1\nans =0\nwhile i<=j\n\tans+=1\n\tfour = 4-x[i]\n\twhile x[j]<=four and j>=i\n\t\tfour-=x[j]\n\t\tj-=1\n\tend\n\ti+=1\nend\nputs ans"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d"}, {"source_code": "n = Integer( gets.chomp )\n\nnum = gets.chomp.split(\" \")\n\na = b = c = d = 0\n\nfor i in 0...n\n\tif num[i]=='1'\n\t\ta += 1\n\telsif num[i]=='2'\n\t\tb += 1\n\telsif num[i]=='3'\n\t\tc += 1\n\telse\n\t\td += 1\n\tend\nend\n\nwhile c>0\n\n\td += 1\n\tif a>0\n\t\ta -= 1\n\tend\n\n\tc -= 1\n\nend\n\nif b%2==0\n\td += b / 2\n\tb = 0\nelse\n\td += (b-1) / 2\n\tb = 2\nend\n\na += b\n\nd += a / 4\n\nif a%4!=0\n\td += 1\nend\n\nputs d\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nfour=b.count('4')\nthree=b.count('3')\ntwo=b.count('2')\none=b.count('1')\nif (three>= one )\nres= four + three + (two/2.0).ceil\nputs \"#{res}\"\nelsif (three < one && two%2 == 0)\nres= four + two/2 + three+ ((one- three)/4.0).ceil\nputs \"#{res}\"\nelsif (three < one && two%2 == 1)\nif (one-three <= 2)\nres= four + (two/2.0).ceil + three\nputs \"#{res}\"\nend\nif (one-three >2)\nres=four+three+(two/2.0).ceil+ ((one-2-three)/4.0).ceil\nputs \"#{res}\"\nend\nend"}, {"source_code": "sizes = STDIN.read.split(\"\\n\").last.split(\" \").map(&:to_i)\n\ngroups_of_1 = sizes.count { |size| size == 1 }\ngroups_of_2 = sizes.count { |size| size == 2 }\ngroups_of_3 = sizes.count { |size| size == 3 }\ngroups_of_4 = sizes.count { |size| size == 4 }\n\ntaxies = groups_of_4 + groups_of_3 + (groups_of_2 / 2)\n\ngroups_of_2 = groups_of_2 % 2\ngroups_of_1 = [groups_of_1 - groups_of_3, 0].max\n\nif groups_of_2 == 0\n taxies += groups_of_1 / 4\n taxies += 1 if groups_of_1 % 4 != 0\nelse\n taxies += 1\n if 2 < groups_of_1\n groups_of_1 -= 2\n taxies += groups_of_1 / 4\n taxies += 1 if groups_of_1 % 4 != 0\n end\nend\n\nputs taxies\n\n"}, {"source_code": "group = [0] * 5\n\ngets\ns = gets.split(' ').map do |x|\n group[x.to_i] += 1\nend\n\nr = group[4] + group[3]\nr += (group[2] / 2.0).ceil\ngroup[2] = group[2] % 2\n\nif group[3] == 0\n if group[2] == 0\n r += (group[1] / 4.0).ceil\n else\n if group[1] > 2\n r += ((group[1] - 2) / 4.0).ceil\n end\n end\nelse\n if group[1] > group[3]\n group[1] -= group[3]\n if group[2] == 0\n r += (group[1] / 4.0).ceil\n else\n if group[1] > 2\n r += ((group[1] - 2) / 4.0).ceil\n end\n end\n end\nend\n\nputs r\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nx = a.count(1)\ny = a.count(2)\nz = a.count(3)\nw = a.count(4)\n\nputs ([0,x-z].max+2*y+3)/4+z+w"}, {"source_code": "NOT=[0]*5;[*$<][1].split.map{|_|NOT[_.to_i]+=1};_,a,b,c,d=*NOT\np ([0,a-c].max+2*b+3)/4+c+d"}, {"source_code": "n=gets.chomp\n\ntaxi=gets.chomp\ncount4=0\ncount3=0\ncount2=0\ncount1=0\na=[]\ntaxi.split(\" \").each do |i|\n if i.to_i==1 \n count1+=1\n end\n if i.to_i==2 \n count2+=1\n end\n if i.to_i==3 \n count3+=1\n end\n if i.to_i==4\n count4+=1\n end\nend\ncounttaxi=0\ncounttaxi += count4\ncounttaxi += count3\ncount1 = count1-count3\ncounttaxi += count2/2\n\nif count2%2==1\n counttaxi += 1\n count1 -= 2\nend\n\nif count1>0\n if count1 % 4 ==0\n counttaxi += count1/4 \n else\n counttaxi += count1/4 +1\n\n end\nend\n\np counttaxi\n\n"}, {"source_code": "n = gets.chomp\ninput = gets.chomp\n\ntaxi = 0\ntres = 0\ndos = 0\nuno = 0\n\ninput.split(\" \").each { |x|\n x = x.to_i\n if x == 1\n uno += 1\n elsif x == 2\n dos += 1\n elsif x == 3\n tres += 1\n else\n taxi += 1\n end\n}\n\ntaxi += tres\n\ntres >= uno ? uno = 0 : uno = (uno - tres)\n\ntaxi += (dos * 2) / 4\nresto_dos = dos.modulo(2)\n\ntaxi += (((resto_dos * 2) + uno).to_f / 4).ceil\n\nputs taxi\n"}, {"source_code": "n = gets\ns = gets.split(' ')\na1 = s.count(\"1\")\na2 = s.count(\"2\")\na3 = s.count(\"3\")\na4 = s.count(\"4\")\nt = [a1, a3].min\na4 += t\na1 -= t\na3 -= t\na4 += a2 / 2\na4 += a1 / 4\na2 %= 2\na1 %= 4\nans = a4 + a3\nif a2 > 0\n\ta1 -= 2\n\tans += 1\nend\nans += 1 if a1 > 0\np ans"}, {"source_code": "# n = Jumlah group\n# s[i] = Jumlah teman anggota group (1..4)\n\nn = gets.chomp\ns = gets.chomp.split(' ').map(&:to_i)\n\ntotal = s.select {|x| x == 4}.length\n\npanjangSatu = s.select {|x| x == 1}.length\npanjangDua = s.select {|x| x == 2}.length\npanjangTiga = s.select {|x| x == 3}.length\n\ntotal += panjangTiga\n\nsisa1 = panjangSatu - panjangTiga\n\nif sisa1 > 0\n panjangDua += (sisa1 / 2.0).ceil\nend\n\ntotal += (panjangDua/2.0).ceil\n\nputs total\n"}, {"source_code": "# Solution CF-158-B\n\n\ndef count_cars groups\n\tarr = [0, 0, 0, 0, 0]\n\t\n\tgroups.each do |x|\n\t\tarr[ x.to_i ] += 1\n\tend\n\t\n\tcars = arr[ 4 ]\n\tcars += arr[ 3 ] + arr[ 2 ] / 2\n\t\n\tarr[ 2 ] = arr[ 2 ] % 2\n\tarr[ 1 ] = arr[ 1 ] < arr[ 3 ] ? 0 : arr[ 1 ] - arr[ 3 ] \n\t\n\tcars += arr[ 1 ] / 4\n\tarr[ 1 ] = arr[ 1 ] % 4\n\t# puts \"c--> #{cars} -- #{arr[1]} -- #{arr[2]}\"\n\t\n\tif arr[ 2 ] > 0\n\t\tcars += 1\n\t\tarr[ 1 ] -= 2\n\tend\n\t\n\tcars += 1 if arr[ 1 ] > 0 \n\t\t \n \tcars\nend\n\n\n\n# Input / Output\n\nn = gets.chomp.to_i\ngroups = gets.split\n\nputs count_cars groups\n\n"}, {"source_code": "# Solution CF-158-B\n\n\ndef count_cars groups\n\tarr = [0, 0, 0, 0, 0]\n\t\n\tgroups.each do |x|\n\t\tarr[ x.to_i ] += 1\n\tend\n\t\n\tcars = arr[ 4 ]\n\tcars += arr[ 3 ] + arr[ 2 ] / 2\n\t\n\tarr[ 2 ] = arr[ 2 ] % 2\n\tarr[ 1 ] = arr[ 1 ] < arr[ 3 ] ? 0 : arr[ 1 ] - arr[ 3 ] \n\t\n\tcars += arr[ 1 ] / 4\n\tarr[ 1 ] = arr[ 1 ] % 4\n\t# puts \"c--> #{cars} -- #{arr[1]} -- #{arr[2]}\"\n\t\n\tif arr[ 2 ] > 0\n\t\tcars += 1\n\t\tarr[ 1 ] -= 2\n\tend\n\t\n\tcars += 1 if arr[ 1 ] > 0 \n\t\t \n \tcars\nend\n\n\n\n# Input / Output\n\nn \t\t= gets.chomp.to_i\ngroups \t= gets.split\n\nputs count_cars groups\n\n"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\ns = Array.new\nfor i in 0...n\n s[i] = Integer(nums[i])\nend\n\ncar1 = 0\ncar2 = 0\ncar3 = 0\ncar4 = 0\nfor i in 0...n\n if s[i] == 1\n car1 += 1\n elsif \n s[i] == 2\n car2 += 1\n elsif \n s[i] == 3\n car3 += 1\n else\n car4 += 1\n end\nend \n\ncar_2 = car2 / 2\ncar_2_still = car2 % 2\n\nif car_2_still == 1\n car_2 += 1\n if car1 == 1\n car1 = car1 - 1\n elsif car1 >= 2\n car1 = car1 - 2\n \n end\nend\n\n\n\nif car3 > car1\n car = car1\n car_0 = car3 - car1\nelsif car3 < car1\n car = car3\n car_0 = car1 - car3\n if car_0 <= 4\n car_0 = 1\n else\n if car_0 % 4 == 0\n car_0 = car_0 / 4\n else\n car_0 = car_0 / 4 + 1\n end\n end\nelse\n car = car3\n car_0 = 0\nend\n\nsum = car4 + car_2 + car + car_0 \nputs sum"}, {"source_code": "#! ruby -Ku\n# -*- coding: UTF-8 -*-\n\ndef div_up(n, m)\n if n % m == 0\n return n / m\n else\n return n / m + 1\n end\nend\n\nbegin\n inputs = open(\"input.txt\")\nrescue\n inputs = STDIN\nend\nnum_group = inputs.gets.split.map(&:to_i)\nnum_each_children = inputs.gets.split.map(&:to_i)\n\n# each bin contain the number of total groups in each number of friend\nbins = Array::new(5, 0)\nnum_each_children.each do |si|\n bins[si] += 1\nend\n\nnum_4_taxi = bins[4]\nnum_1_3_taxi = [bins[1], bins[3]].min\nnum_2_2_taxi = bins[2] / 2\nnum_3_taxi = bins[3] - num_1_3_taxi\nnum_2_1_1_taxi = 0\nif bins[2] % 2 == 1\n num_2_1_1_taxi = 1\nend\nnum_1_1_1_1_taxi = div_up([bins[1] - num_1_3_taxi - num_2_1_1_taxi * 2, 0].max, 4)\n\nnum_taxi = num_4_taxi + num_1_3_taxi + num_2_2_taxi + num_3_taxi + num_2_1_1_taxi + num_1_1_1_1_taxi\n\nputs num_taxi\n"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i).sort.reverse\n\nresult = n - a.delete_if { |x| x == 4 }.size\n\nuntil a.empty? do\n result += 1\n x = a.shift\n break if a.empty?\n\n while a.last + x <= 4 do\n x += a.pop\n break if a.empty?\n end\nend\n\nputs result\n"}, {"source_code": "a=[0]*5\ngets\ngets.split.map {|x| a[x.to_i]+=1}\na[1]=[a[1]-a[3],0].max\nputs a[4]+a[3]+a[2]/2-(-(a[1]+a[2]%2*2))/4"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i).sort.reverse\n\nresult = 0\n\nuntil a.empty? do\n result += 1\n x = a.shift\n break if a.empty?\n\n while a.last + x <= 4 do\n x += a.pop\n break if a.empty?\n end\nend\n\nputs result\n"}, {"source_code": "s = gets.chomp\nn = s.to_i\na = gets.split(\" \")\na = a.sort{|x,y| y <=> x }\nk = 0\nit = n-1\ncount = 0\nfor i in 0..it\n a[i] = a[i].to_i\n a[it] = a[it].to_i \n if k + a[i] > 4 \n if k+a[it]<= 4\n it -= 1\n end\n count += 1\n k = a[i]\n else \n k += a[i]\n if k == 4 \n k = 0\n count += 1\n end\n end \n if i == it \n break\n end\nend\nif(k != 0)\n count += 1 \n end\nputs(count)"}, {"source_code": "\ndef main()\n\tn=gets.chomp.to_i;\n\ts=gets.chomp.split(\" \",n).map{|i| i.to_i};\n\tans=0;\n\t#count the number of 4's \n\ts.each do |i|\n\t\tif i==4\n\t\t\tans=ans+1\n\t\tend\n\tend\n\t#count three and ones\n\tc3=0;c1=0;\n\ts.each do |i|\n\t\tif i==3\t\n\t\t\tc3=c3+1\n\t\telsif i==1\n\t\t\tc1=c1+1\n\t\tend\n\tend\n\tans=ans+c3;\n#\tputs \"after adding c3\"+ans.to_s;\n\t#cr1= count of 1 removed\n\tif c30\n\t\t\tans=ans+1;\n\t\telsif c2==0 and c1!=0\n\t\t\tif c1%4==0\n\t\t\t\tans=ans+(c1/4);\n\t\t\telse\n\t\t\t\tans=ans+(c1/4)+1;\n\t\t\tend\n\t\telse\n\t\t\tans=ans+1;\n\t\t\tc1=c1-2;\n\t\t\tif c1>0\n\t\t\t\tif c1%4==0 \n\t\t\t\t\tans=ans+(c1/4);\n\t\t\t\telse\n\t\t\t\t\tans=ans+(c1/4)+1;\n\t\t\t\tend\t\n\t\t\tend\n\t\tend\n\t\tputs ans;\n\tend\n\t\nend\n\nmain()\n"}, {"source_code": "r=->{gets.split.map &:to_i}\na=r[]\nb=r[]\nc4 = b.count{|res| res==4}\nc3 = b.count{|res| res==3}\nc2 = b.count{|res| res==2}\nc1 = b.count{|res| res==1}\nabs = (c1 - c3).abs\nres = c4 + c2/2 + [c1,c3].min + (c2&1<1 ? 0 : 1) + (c3 > c1 ? abs : (c2&1<1 ? (-abs/4).abs : (abs <= 2 ? 0 : (-(abs-2)/4).abs) ))\np res"}, {"source_code": "def solution(arr)\n counts = arr.inject(Hash.new(0)) { |c, v| c[v] += 1; c }\n\n count = counts[4] || 0\n count += counts[3] || 0\n counts[1] -= counts[3] unless counts[1].nil?\n counts.delete(4)\n counts.delete(3)\n counts.delete(1) if counts[1] < 0\n\n count += counts[2] / 2\n\n ost = counts[2] % 2 == 0 ? 0 : 2\n ost += counts[1] || 0\n\n count += ost / 4\n count += 1 unless ost % 4 == 0\n\n puts count\nend\n\n_ = gets.split(' ').map &:to_i\narr = gets.split(' ').map &:to_i\n\nsolution arr\n"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d\n"}, {"source_code": "def solution(arr)\n h = arr.inject(Hash.new(0)) { |c, v| c[v] += 1; c }\n\n f = h[1] || 0\n s = h[2] || 0\n t = h[3] || 0\n fo = h[4] || 0\n\n count = fo\n count += t\n f -= t\n f = 0 if f < 0\n\n count += s / 2\n\n total = (s % 2) * 2 + f\n\n count += total / 4\n count += 1 if total % 4 != 0\n\n puts count\nend\n\n_ = gets.split(' ').map &:to_i\narr = gets.split(' ').map &:to_i\n\nsolution arr\n"}, {"source_code": "def solution(arr)\n h = Hash.new(0)\n arr.each do |x|\n h[x] += 1\n end\n\n f = h[1] || 0\n s = h[2] || 0\n t = h[3] || 0\n fo = h[4] || 0\n\n count = fo\n count += t\n f -= t\n f = 0 if f < 0\n\n count += s / 2\n\n total = (s % 2) * 2 + f\n\n count += total / 4\n count += 1 if total % 4 != 0\n\n puts count\nend\n\n_ = gets.split(' ').map &:to_i\narr = gets.split(' ').map &:to_i\n\nsolution arr\n"}, {"source_code": "gets\ngroups = gets.split.map(&:to_i)\n\nn4 = groups.count(4)\nn3 = groups.count(3)\nn2 = groups.count(2)\nn1 = groups.count(1)\n\nntaxi = n4 + n3\nn1 = [n1 - n3, 0].max\n\nd1 = n1/2\ns1 = n1%2\n\nn2 += d1\n\ne2 = n2/2\ns2 = n2%2\n\nntaxi += e2\nntaxi += [s1, s2].max\n\nputs ntaxi"}, {"source_code": "gets\ns = gets.split.map(&:to_i).sort\nc = t = 0\nwhile !s.empty?\n c += 1 if t == 0\n case s.pop\n when 3\n s.shift if s.first == 1\n when 2\n if s.last == 2\n s.pop\n else\n t += 2\n end\n when 1\n t += 1\n if t == 4\n t = 0\n end\n end\nend\nputs c\n"}, {"source_code": "t=[0]*5;[*$<][1].split.map{|_|t[_.to_i]+=1};_,a,b,c,d=*t\np ([0,a-c].max+2*b+3)/4+c+d\n"}, {"source_code": "n = gets.to_i\ns = gets.split.map(&:to_i)\n\nn4 = s.count{|i| i==4}\nn3 = s.count{|i| i==3}\nn2 = s.count{|i| i==2}\nn1 = s.count{|i| i==1}\n\nret = n4 + n3\nret = ret + n2/2 + n2%2\nrn1 = n1 - (n3 + 2*(n2%2))\nret = ret + (rn1-1)/4 + 1 if rn1 > 0\n\nputs ret"}], "negative_code": [{"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\ns = Array.new\nfor i in 0...n\n s[i] = Integer(nums[i])\nend\n\ncar1 = 0\ncar2 = 0\ncar3 = 0\ncar4 = 0\nfor i in 0...n\n if s[i] == 1\n car1 += 1\n elsif \n s[i] == 2\n car2 += 1\n elsif \n s[i] == 3\n car3 += 1\n else\n car4 += 1\n end\nend \n\ncar_2 = car2 / 2\ncar_2_still = car2 % 2\n\nif car_2_still == 1\n car_2 += 1\n if car1 == 1\n car1 = car1 - 1\n elsif car1 == 2\n car1 = car1 - 2\n end\nend\n\n\n\nif car3 > car1\n car = car1\n car_0 = car3 - car1\nelsif car3 < car1\n car = car3\n car_0 = car1 - car3\n if car_0 <= 4\n car_0 = 1\n else\n if car_0 % 4 == 0\n car_0 = car_0 / 4\n else\n car_0 = car_0 / 4 + 1\n end\n end\nelse\n car = car3\n car_0 = 0\nend\n\nsum = car4 + car_2 + car + car_0 \nputs sum"}, {"source_code": "gets\na = gets.split(/\\s+/).map{ |i| i.to_i }.inject([0,0,0,0,0]){ |a, i| a[i] += 1; a }\n\nres = a[4]\n\nres += a[3]\na[1] -= a[3];\n\ntwo = (a[2]+1)/2\nres += two\na[1] -= 2 if(a[2] % 2 == 1)\n\nres += a[1] if(a[1] > 0)\n\nputs res\n"}, {"source_code": "groupNum = gets.chomp.to_i\ngroups = gets.chomp.split(' ').map { |i| i.to_i }\n\ngroupHash = {}\n\nfor i in 1..4\n\tgroupHash[i] = 0\nend\n\ngroups.each do |g|\n\tgroupHash[g] += 1\nend\n\nans = groupHash[4]\n\nwhile groupHash[3] > 0 && groupHash[1] > 0\n\tans += 1\n\tgroupHash[3] -= 1\n\tgroupHash[1] -= 1\nend\n\nwhile groupHash[2] > 0 && groupHash[1] > 1\n\tans += 1\n\tgroupHash[2] -= 1\n\tgroupHash[1] -= 2\nend\n\nwhile groupHash[2] > 1\n\tans += 1\n\tgroupHash[2] -= 2\nend\n\nwhile groupHash[1] > 3\n\tans += 1\n\tgroupHash[1] -= 4\nend\n\nans += groupHash[3]\nans += 1 if groupHash[1] > 0\nans += 1 if groupHash[2] > 0\n\nputs ans"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.strip.split.map(&:to_i)\narr.sort!\narr = arr.reverse\n#p arr\ns =0\nc=0\ni=0\ne=n-1\nwhile i <= e do\n s += arr[i] + arr[e]\n #p [s, arr[i], arr[e]]\n if arr.inject(0){|sum,x| sum + x } <= 4\n c = c+1\n break\n end\n if s > 4\n c = c+1\n i=i+1\n s = 0\n elsif s == 4\n i = i+1\n c=c+1\n e=e-1\n s=0\n else\n i=i+1\n e=e-1\n end\n #puts c\nend\nputs c\n"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\nif three_num > one_num\n res = res + one_num\n three_num = three_num - one_num\n one_num = 0\nelsif one_num > three_num\n res = res + three_num\n one_num = one_num - three_num\n three_num = 0\n else\n res = res + one_num\n one_num =0\n three_num = 0\nend\n\nif two_num % 2 ==0\n res = res + two_num/2\n two_num =0\nelse\n res = res + two_num/2\n two_num = 1\nend\n\nif one_num %2 ==0 && two_num >0 && one_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nif one_num %4 ==0\n res = res + one_num/4\n one_num = one_num%4\nend\n\nif three_num > 0\n res = res + three_num + two_num\nend\n\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "def main()\n\tn=gets.chomp.to_i;\n\ts=gets.chomp.split(\" \",n).map{|i| i.to_i};\n\ts=s.sort().reverse();\n\tcount=0;\n\tc=0;\n\twhile true\n\t\tsg=s[c];\n\t\tif sg==4\n\t\t\tcount=count+1\n\t\t\ts.delete_at(c);\n\t\telsif sg==3\n\t\t\tind=s.index(1);\n\t\t\tif ind!=nil\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(ind);\n\t\t\t\ts.delete_at(c);\n\t\t\telse\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(c);\n\t\t\tend\n\t\telsif sg==2\n\t\t\tind=s.index(2);\n\t\t\tif ind!=nil\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(ind)\n\t\t\t\ts.delete_at(c);\n\t\t\telse\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(c);\n\t\t\tend\n\t\telsif sg==1\n\t\t\tind=s.index(4);\n\t\t\tif ind!=nil\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(ind)\n\t\t\t\ts.delete_at(c);\n\t\t\telse\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(c);\n\t\t\tend\n\t\tend\n\t\tif s.length()==0\n\t\t\tbreak;\n\t\tend;\t\t\t\n\tend\n\tputs count;\nend\n\nmain();\n"}, {"source_code": "n, *s = gets.split(' ')\nsum = 0\ns.each {|i| sum += i.to_i}\np \"#{(sum + 3) / 4}\""}, {"source_code": "a=gets.to_i\ns=gets.split\ns.map! {|x| x.to_i}\n\nans=0\ns.each {|x| ans+=x}\n\n\nputs (ans/4.0).ceil\n\n"}, {"source_code": "limit = gets.to_i\nsum =0\nans = 0\nx = gets.chomp.split()\nfor i in x\n\ti = i.to_i\n\tsum+=i\nend\nputs sum\nwhile sum!=0\n\tif sum<4\n\t\tans+=1\n\t\tsum/=4\n\telse\n\t\tans+=sum/4\n\t\tsum/=4\n\tend\nend\nputs ans"}, {"source_code": "n = gets.to_i\nm = []\nm = gets.split.map(&:to_i)\ni = 0\nfor j in m do\n i = i + j\nend \n\nresult = (i/4.0).ceil\nputs result"}, {"source_code": "c=[0]*5\ngets\ngets.split.each{|_|c[_.to_i]+=1}\np([0,c[1]-c[3]].max+2*c[2]+3)/4+c[3]+c[4]"}, {"source_code": "groupNum = gets.chomp.to_i\n\ngroup = gets.chomp.split(' ').map {|item| item.to_i}\n\none = group.count(1)\ntwo = group.count(2)\nthree = group.count(3)\nfour = group.count(4)\n\nresult = four + ((two + 1) / 2)\nresult += [one, three].max if three >= one\nresult += three + (one - three + 3) / 4 if one > three\nputs result"}, {"source_code": "n = gets.chomp\ninput = gets.chomp\n\ntaxi = 0\ntres = 0\ndos = 0\nuno = 0\n\ninput.split(\" \").each { |x|\n x = x.to_i\n if x == 1\n uno += 1\n elsif x == 2\n dos += 1\n elsif x == 3\n tres += 1\n else\n taxi += 1\n end\n}\n\nputs taxi\n\ntaxi += tres\n\ntres >= uno ? uno = 0 : uno = (uno - tres)\n\ntaxi += (dos * 2) / 4\nresto_dos = dos.modulo(2)\n\ntaxi += (((resto_dos * 2) + uno).to_f / 4).ceil\n\nputs taxi\n"}, {"source_code": "n = gets.to_i\nm = []\nm = gets.split.map(&:to_i)\ni = 0\nfor j in m do\n i = i + j\nend \n\nresult = (i/4.0).ceil\n\nif m[0] == 3 and m[1] == 3 and m[2] == 3\n puts 3\nelse\n puts result\nend"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.strip.split.map(&:to_i)\narr.sort!\narr = arr.reverse\n#p arr\ns =0\nc=0\ni=0\ne=n-1\nwhile i <= e do\n s = arr[i] + arr[e]\n #p [s, arr[i], arr[e]]\n if s > 4\n c = c+1\n i=i+1\n s = 0\n elsif s == 4\n i = i+1\n c=c+1\n e=e-1\n s=0\n else\n i=i+1\n e=e-1\n end\n #puts c\nend\nputs c\n"}, {"source_code": "n = gets.to_i\ns = gets.split(\" \").map(&:to_i)\n\ngroups_1 = groups_2 = groups_3 = groups_4 = 0\ntaxi_cnt = 0\n\ns.each { |group|\n case group\n when 1\n groups_1 += 1\n when 2\n groups_2 += 1\n when 3\n groups_3 += 1\n when 4\n groups_4 += 1\n end\n}\n\n# 4\ntaxi_cnt += groups_4\ngroups_4 = 0\n\n# 3 + 1\ngroups_3_1 = [groups_3, groups_1].min\ngroups_3 -= groups_3_1\ngroups_1 -= groups_3_1\ntaxi_cnt += groups_3_1\n\n# 2 + 2\ngroups_2_2 = groups_2 / 2\ngroups_2 -= groups_2_2 * 2\ntaxi_cnt += groups_2_2\n\nif groups_3 > 0\n# 3, 2\n taxi_cnt += groups_3 + groups_2 # groups_2 == 0||1\n groups_2 = groups_3 = 0\nelse \n# 1, 2\n taxi_cnt += ((groups_1 + groups_2*2)/4.to_f).ceil\n groups_1 = groups_2 = 0\nend \n\nputs \"#{groups_1}, #{groups_2}, #{groups_3}, #{groups_4}\"\nputs taxi_cnt\n\n\n\n\n\n"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\n\nif three_num > one_num\n res = res + one_num\n three_num = three_num - one_num\n one_num = 0\nelsif one_num > three_num\n res = res + three_num\n one_num = one_num - three_num\n three_num = 0\nend\n\ntwo_num = res + two_num/2\nif two_num%2==0\n two_num = 0\nelse\n two_num =1\nend\n\nif one_num %2 ==0 && two_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nif one_num %4 ==0\n res = res + one_num/4\n one_num = one_num%4\nend\n\nif three_num > 0\n res = res + three_num + two_num\nend\n\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "require 'pp'\n\ndef find_counter(p, map)\n eligible = []\n p.each do |n, needed|\n if map[n].nil?\n eligible = [0]\n break\n end\n eligible.push(map[n] / needed)\n end\n eligible.min\nend\n\ngets\nmap = {}\ngets.chomp(' ').split().map(&:to_i).each do |x|\n if map[x]\n map[x] += 1\n else\n map[x] = 1\n end\nend\n\npatterns = [\n {4 => 1},\n {3 => 1, 1 => 1},\n {2 => 2},\n {2 => 1, 1 => 2},\n {1 => 4},\n]\n\n# pp combination\n# pp map\n\ntaxi_needed = 0\npatterns.each do |p|\n k = find_counter(p, map)\n # decrease\n p.each do |x, needed|\n unless map[x].nil?\n map[x] -= k * needed\n end\n end\n taxi_needed += k\nend\nrest_group = map.values.reject{ |x| x == 0 }.length\nputs taxi_needed + rest_group\n"}, {"source_code": "limit = gets.to_i\nx = []\nx = gets.split(\" \").map{|x| x.to_i}\nx =x.reverse\ni=0\nj=limit-1\nans =0\nwhile i<=j\n\tans+=1\n\tfour = 4-x[i].to_i\n\twhile x[j].to_i<=four and j>=i\n\t\tfour-=x[j].to_i\n\t\tj-=1\n\tend\n\ti+=1\nend\nputs ans\n\n\n"}, {"source_code": "number_of_groups = gets().split.map(&:to_i)\ngroups = gets().split.map(&:to_i)\n\nsize_distribution = groups.inject([0,0,0,0]) do |array, group| \n array[group - 1] += 1\n array\nend\n\n# for 4\nnumbers_of_cars = size_distribution[3]\nsize_distribution[3] = 0\n\n# for 2\nnumbers_of_cars += (size_distribution[1] / 2.to_f).floor\nsize_distribution[1] = size_distribution[1] % 2\n\n# for 1\nnumbers_of_cars += (size_distribution[0] / 4.to_f).floor\nsize_distribution[0] = size_distribution[0] % 4\n\n# for 2 and 1 1\nif size_distribution[1] > 0\n size_distribution[0] -= 2 if size_distribution[0] > 1\n size_distribution[1] -= 1\n numbers_of_cars += 1\nend\n\n# for 3 and 1\nif size_distribution[2] > 0\n if size_distribution[0] > 0\n cars_3_1 = [size_distribution[0], size_distribution[2]].min\n size_distribution[0] -= cars_3_1\n size_distribution[2] -= cars_3_1\n numbers_of_cars += cars_3_1\n else\n numbers_of_cars += size_distribution[2]\n end\nend\n\n# for 2 and 1\nif size_distribution[1] > 0\n if size_distribution[0] > 0\n cars_2_1 = [size_distribution[0], size_distribution[1]].min\n size_distribution[0] -= cars_2_1\n size_distribution[1] -= cars_2_1\n numbers_of_cars += cars_2_1\n else\n numbers_of_cars += size_distribution[1]\n end\nend\n\nsize_distribution.each { |g| numbers_of_cars += 1 if g > 0 }\n\nputs numbers_of_cars"}, {"source_code": "# begone\ngets.chomp\n\n# groups = gets.chomp.split(' ').map(&:to_i).sort\n\ngroups = %w(1 2 4 3 3).map(&:to_i).sort.reverse\n\nans = 0\n\ngroups.each_with_index do |gr, idx|\n taxi = gr\n\n reversed = groups.reverse\n reversed.each_with_index do |grr, index|\n break if idx == reversed.size - 1 - index || (taxi += grr) > 4\n\n groups.pop\n end\n\n ans += 1\nend\n\np ans\n"}, {"source_code": "a=gets.to_i\ns=gets.split\ns.map! {|x| x.to_i}\n\nans=0\ns.each {|x| ans+=x}\n\n\nputs (ans/4.0).ceil\n\n"}, {"source_code": "n = gets.to_i\nm = []\nm = gets.split.map(&:to_i)\ni = 0\nfor j in m do\n i = i + j\nend \n\nresult = (i/4.0).floor\n\nif result % 2 != 0\n puts result\nelse\n puts result + 1\nend"}, {"source_code": "groupNum = gets.chomp\ngroup = gets.chomp.split(' ').map {|item| item.to_i}\n\ntotal = 0\n\ngroup.each do |item|\n\ttotal += item\nend\n\nif total % 4 == 0\n\tputs total / 4\nelse\n\tputs (total / 4) + 1\nend"}, {"source_code": "gets\nhashed = Hash.new(0)\ngroups = gets.chomp.split.map { |item| item.to_i }.each { |item| hashed[item] += 1 }\nif hashed[1] != 0\n puts hashed[4] + hashed[3] + ((2 * hashed[2] + (hashed[2] - hashed[1]).abs) / 4.0).ceil\nelse\n puts hashed[4] + hashed[3] + ((2 * hashed[2]) / 4.0).ceil\nend"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\nif three_num > one_num\n res = res + one_num\n three_num = three_num - one_num\n one_num = 0\nelsif one_num > three_num\n res = res + three_num\n one_num = one_num - three_num\n three_num = 0\n else\n res = res + one_num\n one_num =0\n three_num = 0\nend\n\nif two_num % 2 ==0\n res = res + two_num/2\n two_num =0\nelse\n res = res + two_num/2\n two_num = 1\nend\n\nif one_num %2 ==0 && two_num >0 && one_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nif one_num %4 ==0\n res = res + one_num/4\n one_num = one_num%4\nend\n\nif three_num > 0\n res = res + three_num\nend\nif two_num > 0\n res = res + two_num\nend\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "n=gets.chomp\n\ntaxi=gets.chomp\ncount4=0\ncount3=0\ncount2=0\ncount1=0\na=[]\ntaxi.split(\" \").each do |i|\n if i.to_i==1 \n count1+=1\n end\n if i.to_i==2 \n count2+=1\n end\n if i.to_i==3 \n count3+=1\n end\n if i.to_i==4\n count4+=1\n end\nend\ncounttaxi=0\ncounttaxi += count4\ncounttaxi += count3\ncount1 = count1-count3\ncounttaxi += count2/2\n\nif count2%2==1\n counttaxi += 1\n count1 -= 2\nend\n\nif count1>0\n counttaxi += count1/4 +1\nend\n\np counttaxi\n\n"}, {"source_code": "gets\nhh = [0, 0, 0, 0, 0]\n\nnums = gets\narray = nums.split(\" \").to_a\n\narray.each {|a| hh[a.to_i] += 1}\n\ncabs = hh[4]\n\nif hh[1] >= hh[3]\n hh[1] -= hh[3]\n cabs += hh[3]\n hh[3] = 0\nelse\n cabs += hh[1]\n hh[3] -= hh[1]\n hh[1] = 0\nend\n\nif hh[2].even?\n cabs += hh[2] / 2\n hh[2] = 0\nelse\n cabs += hh[2] / 2\n hh[2] = 1\n if hh[1] > hh[2]\n\thh[2] = 0\n\tif hh[1] == 1 || hh[1] == 2\n\t cabs += 1\n\t hh[1] = 0\n\telsif hh[1] > 2\n\t cabs += 1\n\t hh[1] -= 2\n\tend\n end\nend\n\nones = hh[1] % 4 == 0 ? 0 : 1 \n\nputs cabs + hh[1] / 4 + ones + hh[2] + hh[3]"}, {"source_code": "number_of_groups = gets().split.map(&:to_i)\ngroups = gets().split.map(&:to_i)\n\nsize_distribution = groups.inject([0,0,0,0]) do |array, group| \n array[group - 1] += 1\n array\nend\n\n# for 4\nnumbers_of_cars = size_distribution[3]\nsize_distribution[3] = 0\n\n# for 2\nnumbers_of_cars += size_distribution[1] / 2\nsize_distribution[1] = size_distribution[1] % 2\n\n# for 1\nnumbers_of_cars += size_distribution[0] / 4\nsize_distribution[0] = size_distribution[0] % 4\n\np size_distribution\n\n# the worst case is 111 2 and a lot of 3\nif size_distribution[1] > 0\n numbers_of_cars += 1\n size_distribution[1] = 0\n size_distribution[0] -= 2\nend\n\nif size_distribution[2] > 0\n numbers_of_cars += size_distribution[2]\n size_distribution[0] -= size_distribution[2]\n size_distribution[2] = 0\nend\n\nsize_distribution.each { |g| numbers_of_cars += 1 if g > 0 }\n\nputs numbers_of_cars"}, {"source_code": "n=gets.chomp\n\ntaxi=gets.chomp\ncount4=0\ncount3=0\ncount2=0\ncount1=0\na=[]\ntaxi.split(\" \").each do |i|\n if i.to_i==1 \n count1+=1\n end\n if i.to_i==2 \n count2+=1\n end\n if i.to_i==3 \n count3+=1\n end\n if i.to_i==4\n count4+=1\n end\nend\ncounttaxi=0\ncounttaxi += count4\ncounttaxi += count3\ncount1 = count1-count3\ncounttaxi += count2/2\n\nif count2%2==1\n counttaxi += 1\n count1 -= 2\nend\n\nif count1>0\n counttaxi += count1/4 +1\nend\n\np counttaxi\n\n"}, {"source_code": "n=gets.chomp\n\ntaxi=gets.chomp\ncount4=0\ncount3=0\ncount2=0\ncount1=0\na=[]\ntaxi.split(\" \").each do |i|\n if i.to_i==1 \n count1+=1\n end\n if i.to_i==2 \n count2+=1\n end\n if i.to_i==3 \n count3+=1\n end\n if i.to_i==4\n count4+=1\n end\nend\ncounttaxi=0\ncounttaxi += count4\ncounttaxi += count3\ncount1 = count1-count3\ncounttaxi += count2/2\n\nif count2%2==1\n counttaxi += 1\n count1 -= 2\nend\n\nif count1>0\n counttaxi += count1/4 +1\nend\n\np counttaxi\n\n"}, {"source_code": "n = gets.to_i\ns = gets.split(\" \").map(&:to_i)\n\ngroups_1 = groups_2 = groups_3 = groups_4 = 0\ntaxi_cnt = 0\n\ns.each { |group|\n case group\n when 1\n groups_1 += 1\n when 2\n groups_2 += 1\n when 3\n groups_3 += 1\n when 4\n groups_4 += 1\n end\n}\n\n# 4\ntaxi_cnt += groups_4\ngroups_4 = 0\n\n# 3 + 1\ngroups_3_1 = [groups_3, groups_1].min\ngroups_3 -= groups_3_1\ngroups_1 -= groups_3_1\ntaxi_cnt += groups_3_1\n\n# 2 + 2\ngroups_2_2 = groups_2 / 2\ngroups_2 -= groups_2_2 * 2\ntaxi_cnt += groups_2_2\n\nif groups_3 > 0\n# 3, 2\n taxi_cnt += groups_3 + groups_2 # groups_2 == 0||1\n groups_2 = groups_3 = 0\nelse \n# 1, 2\n taxi_cnt += ((groups_1 + groups_2*2)/4.to_f).ceil\n groups_1 = groups_2 = 0\nend \n\nputs \"#{groups_1}, #{groups_2}, #{groups_3}, #{groups_4}\"\nputs taxi_cnt\n\n\n\n\n\n"}, {"source_code": "limit = gets.to_i\nx = []\nx = gets.split(\" \").map{|x| x.to_i}\nx =x.reverse\ni=0\nj=limit-1\nans =0\nwhile i<=j\n\tans+=1\n\tfour = 4-x[i].to_i\n\twhile x[j].to_i<=four and j>=i\n\t\tfour-=x[j].to_i\n\t\tj-=1\n\tend\n\ti+=1\nend\nputs ans\n\n\n"}, {"source_code": "# Solution CF-158-B\n\n\ndef count_cars groups\n\tarr = [0, 0, 0, 0, 0]\n\t\n\tgroups.each do |x|\n\t\tarr[ x.to_i ] += 1\n\tend\n\t\n\tcars = arr[ 4 ]\n\t\n\tcars += arr[ 3 ] + arr[ 2 ] / 2 + arr[ 1 ] / 4\n\t\n\tarr[ 1 ] = arr[ 1 ] % 4\n\tarr[ 2 ] = arr[ 2 ] % 2\n\tarr[ 1 ] = arr[ 1 ] <= arr[ 3 ] ? 0 : arr[ 1 ] - arr[ 3 ] \n\n\tcars += 1 unless arr[ 1 ] == 0 && arr[ 2 ] == 0\n\t \n \tcars\nend\n\n\n\n# Input / Output\n\nn \t\t= gets.chomp.to_i\ngroups \t= gets.split\n\nputs count_cars groups\n\n"}, {"source_code": "n = Integer(gets.chomp)\ninput = gets.chomp\nnums = input.split\ns = Array.new\nfor i in 0...n\n s[i] = Integer(nums[i])\nend\n\ncar1 = 0\ncar2 = 0\ncar3 = 0\ncar4 = 0\nfor i in 0...n\n if s[i] == 1\n car1 += 1\n elsif \n s[i] == 2\n car2 += 1\n elsif \n s[i] == 3\n car3 += 1\n else\n car4 += 1\n end\nend \n\ncar_2 = car2 / 2\ncar_2_still = car2 % 2\n\nif car_2_still == 1\n car_2 += 1\n if car1 == 1\n car1 = car1 - 1\n end\nend\n\n\nif car3 > car1\n car = car1\n car_0 = car3 - car1\nelsif car3 < car1\n car = car3\n car_0 = car1 - car3\nelse\n car = car3\n car_0 = 0\nend\n\nsum = car4 + car_2 + car + car_0\nputs sum"}, {"source_code": "def main()\n\tn=gets.chomp.to_i;\n\ts=gets.chomp.split(\" \",n).map{|i| i.to_i};\n\ts=s.sort().reverse();\n\tcount=0;\n\tc=0;\n\twhile true\n\t\tsg=s[c];\n\t\tif sg==4\n\t\t\tcount=count+1\n\t\t\ts.delete_at(c);\n\t\telsif sg==3\n\t\t\tind=s.index(1);\n\t\t\tif ind!=nil\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(ind);\n\t\t\t\ts.delete_at(c);\n\t\t\telse\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(c);\n\t\t\tend\n\t\telsif sg==2\n\t\t\tind=s.index(2);\n\t\t\tif ind!=nil\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(ind)\n\t\t\t\ts.delete_at(c);\n\t\t\telse\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(c);\n\t\t\tend\n\t\telsif sg==1\n\t\t\tind=s.index(4);\n\t\t\tif ind!=nil\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(ind)\n\t\t\t\ts.delete_at(c);\n\t\t\telse\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(c);\n\t\t\tend\n\t\tend\n\t\tif s.length()==0\n\t\t\tbreak;\n\t\tend;\t\t\t\n\tend\n\tputs count;\nend\n\nmain();\n"}, {"source_code": "n, *s = gets.split(' ')\nsum = 0\ns.each {|i| sum += i.to_i}\np \"#{(sum + 3) / 4}\""}, {"source_code": "groupNum = gets.chomp.to_i\n\ngroup = gets.chomp.split(' ').map {|item| item.to_i}\n\none = group.count(1)\ntwo = group.count(2)\nthree = group.count(3)\nfour = group.count(4)\n\nresult = four + ((two + 1) / 2).floor\nresult += [one, three].max if three >= one\nresult += three + (one - three + 3) / 4 if one > three\nputs result"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\nif three_num > one_num\n res = res + one_num\n three_num = three_num - one_num\n one_num = 0\nelsif one_num > three_num\n res = res + three_num\n one_num = one_num - three_num\n three_num = 0\n else\n res = res + one_num\n one_num =0\n three_num = 0\nend\n\nif two_num % 2 ==0\n res = res + two_num/2\n two_num =0\nelse\n res = res + two_num/2\n two_num = 1\nend\n\nif one_num %2 ==0 && two_num >0 && one_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nif one_num %4 ==0\n res = res + one_num/4\n one_num = one_num%4\nend\n\nif one_num > 0 && two_num >0\n res +=1\nend\n\nif three_num > 0\n res = res + three_num\nend\nif two_num > 0\n res = res + two_num\nend\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\nif three_num > one_num\n res = res + one_num\n three_num = three_num - one_num\n one_num = 0\nelsif one_num > three_num\n res = res + three_num\n one_num = one_num - three_num\n three_num = 0\n else\n res = res + one_num\n one_num =0\n three_num = 0\nend\n\nif two_num % 2 ==0\n res = res + two_num/2\n two_num =0\nelse\n res = res + two_num/2\n two_num = 1\nend\n\nif one_num %2 ==0 && two_num >0 && one_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nif one_num %4 ==0\n res = res + one_num/4\n one_num = one_num%4\nend\n\nif one_num > 0 && two_num >0\n res +=1\nend\n\nif three_num > 0\n res = res + three_num\nend\nif two_num > 0\n res = res + two_num\nend\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\nif three_num > one_num\n res = res + one_num\n three_num = three_num - one_num\n one_num = 0\nelsif one_num > three_num\n res = res + three_num\n one_num = one_num - three_num\n three_num = 0\n else\n res = res + one_num\n one_num =0\n three_num = 0\nend\n\n\nif two_num % 2 ==0\n res = res + two_num/2\n two_num =0\nelse\n res = res + two_num/2\n two_num = 1\nend\n\nif one_num %2 ==0 && two_num >0 && one_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nif one_num %4 ==0\n res = res + one_num/4\n one_num = one_num%4\nend\n\nif one_num + two_num > 1\n res +=1\n one_num -=1\n two_num -=1\nend\n\nif three_num > 0\n res = res + three_num\nend\nif two_num > 0\n res = res + two_num\nend\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "n = gets.to_i\ni = 0\nx = gets.split.map(&:to_i).sort\n\ncab, count = 0, 0\nwhile i < n\n if cab + x[i] <= 4\n cab += x[i]\n else\n count += 1\n cab = x[i]\n end\n i += 1\nend\n\nputs count+1"}, {"source_code": "groupNum = gets.chomp.to_i\n\ngroup = gets.chomp.split(' ').map {|item| item.to_i}\n\none = group.count(1)\ntwo = group.count(2)\nthree = group.count(3)\nfour = group.count(4)\n\nresult = four + ((two + 1) / 2).floor\nresult += [one, three].max if three >= one\nresult += three + (one - three + 3) / 4 if one > three\nputs result"}, {"source_code": "gets\na = gets.split.map(&:to_i)\nk = a.find_all{ |x| x==4}.size\na.delete 4\n\nthree = [a.find_all { |x| x==3 }.size, a.find_all { |x| x==1 }.size].min\nk += three\nthree.times { a.delete_at(a.index(3)); a.delete_at(a.index(1)) }\nk += a.find_all{ |x| x==3}.size\na.delete 3\n\nc2 = a.find_all{ |x| x==2}.size\nc1 = a.find_all{ |x| x==1}.size\n\nk += c2/2 + c1/4 + (c2%2 + c1%4) / 4 + (c2%2 + c1%4)%4 > 0 ? 1 : 0\nputs k"}, {"source_code": "n = gets.to_i\ns = gets.split(\" \").map(&:to_i)\n\ngroups_1 = groups_2 = groups_3 = groups_4 = 0\ntaxi_cnt = 0\n\ns.each { |group|\n case group\n when 1\n groups_1 += 1\n when 2\n groups_2 += 1\n when 3\n groups_3 += 1\n when 4\n groups_4 += 1\n end\n}\n\n# 4\ntaxi_cnt += groups_4\ngroups_4 = 0\n\n# 3 + 1\ngroups_3_1 = [groups_3, groups_1].min\ngroups_3 -= groups_3_1\ngroups_1 -= groups_3_1\ntaxi_cnt += groups_3_1\n\n# 2 + 2\ngroups_2_2 = groups_2 / 2\ngroups_2 -= groups_2_2 * 2\ntaxi_cnt += groups_2_2\n\nif groups_3 > 0\n# 3, 2\n taxi_cnt += groups_3 + groups_2 # groups_2 == 0||1\n groups_2 = groups_3 = 0\nelse \n# 1, 2\n taxi_cnt += ((groups_1 + groups_2)/4.to_f).ceil\n groups_1 = groups_2 = 0\nend \n\n#puts \"#{groups_1}, #{groups_2}, #{groups_3}, #{groups_4}\"\nputs taxi_cnt\n\n\n\n\n\n"}, {"source_code": "a = gets().split(' ').map{|x| Integer(x)}\nb = gets().split(' ').map{|x| Integer(x)}\nc = [0,0,0,0,0]\n(1..4).each {|num| c[num] = (b.select {|x| x == num}).size}\nres = c[4] + c[3] + c[2]/2 + (\nif c[2] % 2 == 1 then\n if c[1] - c[3]-2 > 0 then\n 1 + (c[1] % 4 == 0 ? c[1]/4 : c[1]/4 + 1)\n else\n 1\n end\nelse\n if c[1] - c[3] > 0 then\n c[1] % 4 == 0 ? c[1]/4 : c[1]/4 + 1\n else\n 0\n end\nend )\nprint res\n"}, {"source_code": "n = gets.to_i\nm = []\nm = gets.split.map(&:to_i)\ni = 0\nfor j in m do\n i = i + j\nend \n\nresult = (i/4.0).ceil\n \nif i == 8\n puts 3\nelse\n puts result\nend"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\nwhile three_num > 0 && one_num >0\n three_num -= 1\n one_num -= 1\n res +=1\nend\n\nif two_num % 2 ==0\n res = res + two_num/2\n two_num =0\nelse\n res = res + two_num/2\n two_num = 1\nend\n\nwhile one_num %2 ==0 && two_num >0 && one_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nif one_num %4 ==0\n res = res + one_num/4\n one_num = one_num%4\nend\n\nwhile one_num > 0 && two_num > 0\n res +=1\n one_num -=1\n two_num -=1\nend\n\nif three_num > 0\n res = res + three_num\nend\nif two_num > 0\n res = res + two_num\nend\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "require 'pp'\n\ndef find_counter(p, map)\n eligible = []\n p.each do |n, needed|\n if map[n].nil?\n eligible = [0]\n break\n end\n eligible.push(map[n] / needed)\n end\n eligible.min\nend\n\ngets\nmap = {}\ngets.chomp(' ').split().map(&:to_i).each do |x|\n if map[x]\n map[x] += 1\n else\n map[x] = 1\n end\nend\n\npatterns = [\n {4 => 1},\n {3 => 1, 1 => 1},\n {2 => 2},\n {2 => 1, 1 => 2},\n {1 => 4},\n]\n\n# pp combination\n# pp map\n\ntaxi_needed = 0\npatterns.each do |p|\n k = find_counter(p, map)\n # decrease\n p.each do |x, needed|\n unless map[x].nil?\n map[x] -= k * needed\n end\n end\n taxi_needed += k\nend\nrest_group = map.values.reject{ |x| x == 0 }.length\nputs taxi_needed + (rest_group / 4.0).ceil\n"}, {"source_code": "gets\nfreq = Hash.new{0}\ngets.split.map(&:to_i).each{|x| freq[x] += 1}\nfreq[1] = [freq[1] - freq[3], 0].min\np freq[4] + freq[3] + (freq[1] + 2 * freq[2] + 3) / 4\n"}, {"source_code": "n = gets\ns = gets.split(' ')\na1 = s.count(\"1\")\na2 = s.count(\"2\")\na3 = s.count(\"3\")\na4 = s.count(\"4\")\nt = [a1, a3].min\na4 += t\na1 -= t\na3 -= t\na4 += a2 / 2\na4 += a1 / 4\na2 %= 2\na1 %= 4\nans = a4 + a3\nans += 1 if a2\nans += 1 if a1 == 3 || !a2\np ans"}, {"source_code": "\ndef main()\n\tn=gets.chomp.to_i;\n\ts=gets.chomp.split(\" \",n).map{|i| i.to_i};\n\tans=0;\n\t#count the number of 4's \n\ts.each do |i|\n\t\tif i==4\n\t\t\tans=ans+1\n\t\tend\n\tend\n\t#count three and ones\n\tc3=0;c1=0;\n\ts.each do |i|\n\t\tif i==3\t\n\t\t\tc3=c3+1\n\t\telsif i==1\n\t\t\tc1=c1+1\n\t\tend\n\tend\n\tans=ans+c3;\n#\tputs \"after adding c3\"+ans.to_s;\n\t#cr1= count of 1 removed\n\tif c30\n\t\tans=ans+1;\n\telsif c2==0 and c1!=0\n\t\tif c1%4==0\n\t\t\tans=ans+(c1/4);\n\t\telse\n\t\t\tans=ans+(c1/4)+1;\n\t\tend\n\telse\n\t\tans=ans;\t\t\n\tend\n\tputs ans;\t\nend\n\nmain()\n"}, {"source_code": "groupNum = gets.chomp.to_i\ngroups = gets.chomp.split(' ').map { |i| i.to_i }\n\ngroupHash = {}\n\nfor i in 1..4\n\tgroupHash[i] = 0\nend\n\ngroups.each do |g|\n\tgroupHash[g] += 1\nend\n\nans = groupHash[4]\n\nwhile groupHash[3] > 0 && groupHash[1] > 0\n\tans += 1\n\tgroupHash[3] -= 1\n\tgroupHash[1] -= 1\nend\n\nwhile groupHash[2] > 0 && groupHash[1] > 1\n\tans += 1\n\tgroupHash[2] -= 1\n\tgroupHash[1] -= 2\nend\n\nwhile groupHash[2] > 1\n\tans += 1\n\tgroupHash[2] -= 2\nend\n\nwhile groupHash[1] > 3\n\tans += 1\n\tgroupHash[1] -= 4\nend\n\nans += groupHash[3]\nans += 1 if groupHash[1] > 0\nans += 1 if groupHash[2] > 0\n\nputs ans"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\nif three_num > one_num\n res = res + one_num\n three_num = three_num - one_num\n one_num = 0\nelsif one_num > three_num\n res = res + three_num\n one_num = one_num - three_num\n three_num = 0\n else\n res = res + one_num\n one_num =0\n three_num = 0\nend\n\n\nif two_num % 2 ==0\n res = res + two_num/2\n two_num =0\nelse\n res = res + two_num/2\n two_num = 1\nend\n\nif one_num %2 ==0 && two_num >0 && one_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nif one_num %4 ==0\n res = res + one_num/4\n one_num = one_num%4\nend\n\nif one_num + two_num > 1\n res +=1\n one_num -=1\n two_num -=1\nend\n\nif three_num > 0\n res = res + three_num\nend\nif two_num > 0\n res = res + two_num\nend\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "n = gets.to_i\ns = gets.split.map &:to_i\n\ncount = s.find_all{|e| e == 4}.size\ns = s.reject {|e| e == 4}\n\ns = s.sort.reverse\n\ni = 0\nj = s.size - 1\nwhile i < j && s[i] == 3 && s[j] == 1\n s[i] = nil\n s[j] = nil\n i += 1\n j -= 1\n count += 1\nend\n\ns = s.compact\n\nfor i in 0..s.size - 1 do\n next if s[i].nil?\n count += 1\n sum = s[i]\n for j in i+1..s.size - 1 do\n next if s[j].nil?\n if sum + s[j] <= 4\n sum +=s[j]\n s[j] = nil\n end\n break if sum == 4 || sum == 3\n end\nend\n\nputs count\n\n"}, {"source_code": "number_of_groups = gets().split.map(&:to_i)\ngroups = gets().split.map(&:to_i)\n\nsize_distribution = groups.inject([0,0,0,0]) do |array, group| \n array[group - 1] += 1\n array\nend\n\n# for 4\nnumbers_of_cars = size_distribution[3]\nsize_distribution[3] = 0\n\n# for 2\nnumbers_of_cars += (size_distribution[1] / 2.to_f).floor\nsize_distribution[1] = size_distribution[1] % 2\n\n# for 1\nnumbers_of_cars += (size_distribution[0] / 4.to_f).floor\nsize_distribution[0] = size_distribution[0] % 4\n\n# for 2 and 1 1\nif size_distribution[1] > 0\n size_distribution[0] -= 2 if size_distribution[0] > 1\n size_distribution[1] -= 1\n numbers_of_cars += 1\nend\n\n# for 3 and 1\nif size_distribution[2] > 0\n if size_distribution[0] > 0\n cars_3_1 = [size_distribution[0], size_distribution[2]].min\n size_distribution[0] -= cars_3_1\n size_distribution[2] -= cars_3_1\n numbers_of_cars += cars_3_1\n else\n numbers_of_cars += size_distribution[2]\n end\nend\n\n# for 2 and 1\nif size_distribution[1] > 0\n if size_distribution[0] > 0\n cars_2_1 = [size_distribution[0], size_distribution[1]].min\n size_distribution[0] -= cars_2_1\n size_distribution[1] -= cars_2_1\n numbers_of_cars += cars_2_1\n else\n numbers_of_cars += size_distribution[1]\n end\nend\n\nsize_distribution.each { |g| numbers_of_cars += 1 if g > 0 }\n\nputs numbers_of_cars"}, {"source_code": "n = gets.to_i\ns = gets.split.map &:to_i\n\ncount = s.find_all{|e| e == 4}.size\ns = s.reject {|e| e == 4}\n\ns = s.sort.reverse\n\ni = 0\nj = s.size - 1\nwhile i < j && s[i] == 3 && s[j] == 1\n s[i] = nil\n s[j] = nil\n i += 1\n j -= 1\n count += 1\nend\n\ns = s.compact\n\nfor i in 0..s.size - 1 do\n count += 1\n next if s[i] == 3\n sum = s[i]\n for j in i+1..s.size - 1 do\n next if s[j].nil?\n if sum + s[j] <= 4\n sum +=s[j]\n s[j] = nil\n end\n break if sum == 4\n end\nend\n\nputs count\n\n"}, {"source_code": "count = Hash.new(0)\n\n_ = gets\ngets.split(' ').each { |x| count[x.to_i] += 1 }\n\nanswer = count[4] + count[3]\ncount[1] = [0, count[1] - count[3]].max\nanswer += (count[2].to_f / 2).ceil\ncount[1] = [0, count[1] - count[2] % 2].max\nanswer += (count[1].to_f / 4).ceil\n\nputs answer\n"}, {"source_code": "limit = gets.to_i\nsum =0\nans = 0\nx = gets.chomp.split()\nfor i in x\n\ti = i.to_i\n\tsum+=i\nend\nwhile sum!=0\n\tif sum%4==0\n\t\tans+=sum/4\n\t\tsum=0\n\telsif sum<4\n\t\tans+=1\n\t\tsum/=4\n\telse\n\t\tans+=sum/4\n\t\tsum/=4\n\tend\nend\nputs ans\n"}, {"source_code": "n, *s = gets.split(' ')\nsum = 0\ns.each {|i| sum += i.to_i}\np (sum + 3) / 4"}, {"source_code": "i = gets.chomp.to_i\nsum = gets.chomp.split(\" \").map(&:to_i).inject(:+)\nif sum == 8 && i == 3\n\tputs 3\nelse\n\tputs (sum % i != 0) ? (sum/4 + 1) : (sum/4)\nend"}, {"source_code": "gets\nca, c = [0] * 5, 0\nSTDIN.read.split.each {|i| ca[i.to_i] += 1}\n\nc += ca[4]\nc += ca[2] / 2\n\nca[2] = ca[2].odd? ? 1 : 0\n\nif ca[1] <= ca[3]\n\tc += ca[1]\n\tca[3] -= ca[1]\n\tca[1] = 0\nelse\n\tc += ca[3]\n\tca[1] -= ca[3]\n\tca[3] = 0\nend\n\nif ca[2] > 0\n\tc += 1\n\tca[1] -= 1 if ca[1] > 1\n\tca[1] -= 1 if ca[1] > 2\nend\n\nc += (ca[1] / 4.0).ceil\n\nputs c"}, {"source_code": "n = gets.chomp.to_i\ng_input = gets.chomp.split(\" \")\n\ngroups = []\nsorting_array = []\ncortege = []\n\ng_input.each do |i|\n\ta = i.to_i\n\tgroups << a\nend\ngroups.sort!\ngroups.reverse!\n\nwhile !(groups.empty?)\n\tc = 0\n\tcounter = 0\n\tif c < 4\n\t\tgroups.each do |g|\n\t\t\tif ((c + g) <= 4)\n\t\t\t\tc = c + g\n\t\t\t\tgroups[counter] = nil\n\t\t\t\tgroups.compact!\n\t\t\t\tcounter = 0\n\t\t\telse\n\t\t\t\tcounter +=1\n\n\t\t\tend\n\t\tend\n\tend\n\n\tif c > 0\n\t\tcortege << c\n\telse \n\t\tbreak\n\tend\nend\n\nputs cortege.length"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\nwhile three_num > 0 && one_num >0\n three_num -= 1\n one_num -= 1\n res +=1\nend\n\nif two_num % 2 ==0\n res = res + two_num/2\n two_num =0\nelse\n res = res + two_num/2\n two_num = 1\nend\n\nwhile one_num %2 ==0 && two_num >0 && one_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nif one_num %4 ==0\n res = res + one_num/4\n one_num = one_num%4\nend\n\nwhile one_num > 0 && two_num > 0\n res +=1\n one_num -=1\n two_num -=1\nend\n\nif three_num > 0\n res = res + three_num\nend\nif two_num > 0\n res = res + two_num\nend\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "#! ruby -Ku\n# -*- coding: UTF-8 -*-\n\ndef div_up(n, m)\n if n % m == 0\n return n / m\n else\n return n / m + 1\n end\nend\n\ninputs = STDIN\n# inputs = open(\"input.txt\")\nnum_group = inputs.gets.split.map(&:to_i)\nnum_each_children = inputs.gets.split.map(&:to_i)\n\n# each bin contain the number of total groups in each number of friend\nbins = Array::new(5, 0)\nnum_each_children.each do |si|\n bins[si] += 1\nend\n\nnum_4_taxi = bins[4]\nnum_1_3_taxi = [bins[1], bins[3]].min\nnum_2_2_taxi = bins[2] / 2\nnum_3_taxi = bins[3] - num_1_3_taxi\nnum_2_1_1_taxi = 0\nif bins[2] % 2 == 1\n num_2_1_1_taxi = 1\nend\nnum_1_1_1_1_taxi = div_up([bins[1] - num_1_3_taxi - num_2_1_1_taxi * 2, 0].min, 4)\n\nnum_taxi = num_4_taxi + num_1_3_taxi + num_2_2_taxi + num_3_taxi + num_2_1_1_taxi + num_1_1_1_1_taxi\n\nputs num_taxi\n"}, {"source_code": "n = gets.chomp.to_i\ng_input = gets.chomp.split(\" \")\n\ngroups = [0, 0, 0, 0, 0]\ng_input.each do |i|\n\ta = i.to_i\n\tif a == 4\n\t\tgroups[4] += 1\n\telsif a == 3\n\t\tgroups[3] += 1\n\telsif a == 2\n\t\tgroups[2] += 1\n\telsif a ==1\n\t\tgroups[1] += 1\n\tend\nend\n\ncars = 0\n\nif groups[4]>0\n\tcars += groups[4]\nend\n\nif groups[3]>0\n\tif groups[3]>=groups[1]\n\t\tcars += groups[3]\n\t\tgroups[1] = 0\n\telsif groups[3] < groups[1]\n\t\tcars += groups[3]\n\t\tgroups[1] -= groups[3]\n\tend\nend\n\nif groups[2]>0\n\tif (groups[2]>1) & (groups[2] % 2 == 0)\n\t\tcars += groups[2]/2\n\telsif (groups[2]/2 >0) & (groups[2] % 2 == 1)&(groups[1]>=2)\n\t\tcars = cars + groups[2]/2 + 1\n\t\tgroups[1] = groups[1] -2\n\telsif (groups[2]/2 >0) & (groups[2] % 2 == 1)&(groups[1]==1)\n\tcars = cars + groups[2]/2 + 1\n\tgroups[1] = 0\n\telsif groups[2]==1 & groups[1] >= 2\n\t\tcars +=1\n\t\tgroups[1]-=2\n\telsif groups[2]==1 & groups[1] >=0\n\t\tcars +=1\n\t\tgroups[1] = 0\n\tend\nend\n\nif groups[1] > 0\n\tcars = cars + (groups[1]/4)\n\tif groups[1] % 4 != 0\n\t\tcars += 1\n\tend\nend\nputs cars\n\n\n\n\n"}, {"source_code": "n = gets.chomp\ninput = gets.chomp\n\ntaxi = 0\ntres = 0\ndos = 0\nuno = 0\n\ninput.split(\" \").each { |x|\n x = x.to_i\n if x == 1\n uno += 1\n elsif x == 2\n dos += 1\n elsif x == 3\n tres += 1\n else\n taxi += 1\n end\n}\n\nputs taxi\n\ntaxi += tres\n\ntres >= uno ? uno = 0 : uno = (uno - tres)\n\ntaxi += (dos * 2) / 4\nresto_dos = dos.modulo(2)\n\ntaxi += (((resto_dos * 2) + uno).to_f / 4).ceil\n\nputs taxi\n"}, {"source_code": "n,limit = gets.chomp().split(\" \")\npass = 0\nscore = gets.chomp.split(\" \")\nscore.each { |x|\n if x.to_i >= score[limit.to_i-1].to_i and x.to_i !=0\n pass = pass+1 \n end\n}\nif score[0] == \"0\"\n pass = 0\nend\nputs pass\n"}, {"source_code": "n = gets.to_i\ni = 0\ncount, ones, twos, threes, fours = 0,0,0,0,0\nx = gets.split.each do |x|\n x = x.to_i\n ones += 1 if x == 1\n twos += 1 if x == 2\n threes += 1 if x == 3\n fours += 1 if x == 4\nend\n\n\ncount += fours\n\nif threes > ones\n count += threes\n ones, threes = 0,0\nend\n\nif threes < ones\n count += threes\n threes, ones = 0, ones-threes\nend\n\nif threes == ones\n count += threes\n ones, threes = 0,0\nend\n\ncount += twos/2\n\ntwos %= 2\n\nif twos == 1\n count += 1\n ones -= 2\nend\n\nif ones > 0\n count += ones/4\n count += ones%4\nend\n\nputs count\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.strip.split.map(&:to_i)\narr.sort!\narr = arr.reverse\n#p arr\ns =0\nc=0\ni=0\ne=n-1\nwhile i <= e do\n s += arr[i] + arr[e]\n #p [s, arr[i], arr[e]]\n if arr.inject(0){|sum,x| sum + x } <= 4\n c = c+1\n break\n end\n if s > 4\n c = c+1\n i=i+1\n s = 0\n elsif s == 4\n i = i+1\n c=c+1\n e=e-1\n s=0\n else\n i=i+1\n e=e-1\n end\n #puts c\nend\nputs c\n"}, {"source_code": "c=[0]*5\ngets\ngets.split.each{|_|c[_.to_i]+=1}\np([0,c[1]-c[3]].max+2*c[2]+3)/4+c[3]+c[4]"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.strip.split.map(&:to_i)\nco = {1=>0,2=>0,3=>0,4=>0}\narr.each do |a|\n co[a] += 1\nend\n# puts co\nres = co[4] + co[3] + (co[2]/2)\nco[1] -= co[3]\nif co[2] % 2 == 1\n res += 1\n co[1] -= 2\nend\nif co[1] > 0\n if co[1] <= 4\n res += 1\n else\n cou = co[1] / 4\n cou += 1 if co[1] % 4 == 0\n res += cou\n end\nend\n\nputs res"}, {"source_code": "def main()\n\tn=gets.chomp.to_i;\n\ts=gets.chomp.split(\" \",n).map{|i| i.to_i};\n\ts=s.sort().reverse();\n\tcount=0;\n\tc=0;\n\twhile true\n\t\tsg=s[c];\n\t\tif sg==4\n\t\t\tcount=count+1\n\t\t\ts.delete_at(c);\n\t\telsif sg==3\n\t\t\tind=s.index(1);\n\t\t\tif ind!=nil\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(ind);\n\t\t\t\ts.delete_at(c);\n\t\t\telse\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(c);\n\t\t\tend\n\t\telsif sg==2\n\t\t\tind=s.index(2);\n\t\t\tif ind!=nil\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(ind)\n\t\t\t\ts.delete_at(c);\n\t\t\telse\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(c);\n\t\t\tend\n\t\telsif sg==1\n\t\t\tind=s.index(4);\n\t\t\tif ind!=nil\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(ind)\n\t\t\t\ts.delete_at(c);\n\t\t\telse\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(c);\n\t\t\tend\n\t\tend\n\t\tif s.length()==0\n\t\t\tbreak;\n\t\tend;\t\t\t\n\tend\n\tputs count;\nend\n\nmain();\n"}, {"source_code": "gets\nhashed = Hash.new(0)\ngroups = gets.chomp.split.map { |item| item.to_i }.each { |item| hashed[item] += 1 }\nif hashed[1] != 0\n puts hashed[4] + hashed[3] + ((2 * hashed[2] + (hashed[2] - hashed[1]).abs) / 4.0).ceil\nelse\n puts hashed[4] + hashed[3] + ((2 * hashed[2]) / 4.0).ceil\nend"}, {"source_code": "# Solution CF-158-B\n\n\ndef count_cars groups\n\tarr = [0, 0, 0, 0, 0]\n\t\n\tgroups.each do |x|\n\t\tarr[ x.to_i ] += 1\n\tend\n\t\n\tcars = arr[ 4 ]\n\tcars += arr[ 3 ] + arr[ 2 ] / 2\n\t\n\tarr[ 2 ] = arr[ 2 ] % 2\n\tarr[ 1 ] = arr[ 1 ] <= arr[ 3 ] ? 0 : arr[ 1 ] - arr[ 3 ] \n\t\n\tcars += arr[ 1 ] / 4\n\tarr[ 1 ] = arr[ 1 ] % 4\n\t# puts \"c--> #{cars} -- #{arr[1]} -- #{arr[2]}\"\n\t\n\tcars += 1 unless arr[ 1 ] == 0 && arr[ 2 ] == 0\n\t \n \tcars\nend\n\n\n\n# Input / Output\n\nn \t\t= gets.chomp.to_i\ngroups \t= gets.split\n\nputs count_cars groups\n\n"}, {"source_code": "limit = gets.to_i\nsum =0\nans = 0\nwhile limit>0\n\tx = gets.to_i\n\tsum+=x\n\tlimit-=1\nend\nwhile sum!=0\n\tif sum<4\n\t\tans+=1\n\t\tsum/=4\n\telse\n\t\tans+=sum/4\n\t\tsum/=4\n\tend\nend\nputs ans"}, {"source_code": "gets\ns=gets.split\ns.map! {|x| x.to_i}\n\nans=0\ns.each {|x| ans+=x}\n\nputs (ans/4.0).ceil\n\n"}, {"source_code": "gets\nsum = gets.chomp.split(\" \").map(&:to_i).inject(:+)\nputs (sum % 4 != 0) ? (sum/4 + 1) : (sum/4)"}, {"source_code": "count = Hash.new(0)\n\n_ = gets\ngets.split(' ').each { |x| count[x.to_i] += 1 }\n\nanswer = count[4] + count[3]\ncount[1] = [0, count[1] - count[3]].max\nanswer += (count[2].to_f / 2).ceil\ncount[1] = [0, count[1] - count[2] % 2].max\nanswer += (count[1].to_f / 4).ceil\n\nputs answer\n"}, {"source_code": "n = gets.to_i\ni = 0\nx = gets.split.map(&:to_i).sort\n\ncab, count = 0, 0\nwhile i < n\n if cab + x[i] <= 4\n cab += x[i]\n else\n count += 1\n cab = x[i]\n end\n i += 1\nend\n\nputs count+1"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\ns = Array.new\nfor i in 0...n\n s[i] = Integer(nums[i])\nend\n\ncar1 = 0\ncar2 = 0\ncar3 = 0\ncar4 = 0\nfor i in 0...n\n if s[i] == 1\n car1 += 1\n elsif \n s[i] == 2\n car2 += 1\n elsif \n s[i] == 3\n car3 += 1\n else\n car4 += 1\n end\nend \n\ncar_2 = car2 / 2\ncar_2_still = car2 % 2\n\nif car_2_still == 1\n car_2 += 1\n if car1 == 1\n car1 = car1 - 1\n end\nend\n\n\n\nif car3 > car1\n car = car1\n car_0 = car3 - car1\nelsif car3 < car1\n car = car3\n car_0 = car1 - car3\n if car_0 <= 4\n car_0 = 1\n else\n car_0 = car_0 / 4 + 1\n end\nelse\n car = car3\n car_0 = 0\nend\n\nsum = car4 + car_2 + car + car_0 \nputs sum"}, {"source_code": "number_of_groups = gets().split.map(&:to_i)\ngroups = gets().split.map(&:to_i)\n\nsize_distribution = groups.inject([0,0,0,0]) do |array, group| \n array[group - 1] += 1\n array\nend\n\n# for 4\nnumbers_of_cars = size_distribution[3]\nsize_distribution[3] = 0\n\n# for 2\nnumbers_of_cars += (groups[1] / 2.to_f).floor\nsize_distribution[1] = size_distribution[1] % 2\n\n# for 1\nnumbers_of_cars += (size_distribution[0] / 4.to_f).floor\nsize_distribution[0] = size_distribution[0] % 4\n\n# for 2 and 1 1\nif size_distribution[1] > 0\n size_distribution[0] -= 2 if size_distribution[0] > 1\n size_distribution[1] -= 1\n numbers_of_cars += 1\nend\n\n# for 3 and 1\nif size_distribution[2] > 0\n if size_distribution[0] > 0\n cars_3_1 = [size_distribution[0], size_distribution[2]].min\n size_distribution[0] -= cars_3_1\n size_distribution[2] -= cars_3_1\n numbers_of_cars += cars_3_1\n else\n numbers_of_cars += size_distribution[2]\n end\nend\n\nsize_distribution.each { |g| numbers_of_cars += 1 if g > 0 }\n\nputs numbers_of_cars"}, {"source_code": "n = gets.chomp.to_i\ng_input = gets.chomp.split(\" \")\nK = 4\n\nclass Group\n\tattr_accessor :population, :in_car\n\n\tdef initialize(population, in_car)\n\t\t@population = population\n\t\t@in_car = in_car\n\tend\n\n\tdef already_in_car?\n\t\tin_car\n\tend\nend\n\nclass Car\n\tattr_accessor :population\n\tdef initialize(population)\n\t\t@population = population\n\tend\nend\n\ngroups = []\nsorting_array = []\ncortege = []\n\ng_input.each do |i|\n\ta = i.to_i\n\tsorting_array << a\nend\nsorting_array.sort.reverse!\n\nsorting_array.each do |i|\n\ta = Group.new(i.to_i, false)\n\tgroups << a\nend\n\n\n\nwhile !(groups.empty?)\n\n\tc = Car.new(0)\n\tif c.population < K\n\t\tgroups.each do |g|\n\t\t\tif ((c.population + g.population) <= K) & ( !( g.already_in_car? ))\n\t\t\t\tc.population = c.population + g.population\n\t\t\t\tg.in_car = true\n\t\t\tend\n\t\tend\n\tend\n\n\tif c.population > 0\n\t\tcortege << c\n\telse \n\t\tbreak\n\tend\nend\n\nputs cortege.length"}, {"source_code": "a = gets().split(' ').map{|x| Integer(x)}\nb = gets().split(' ').map{|x| Integer(x)}\nc = [0,0,0,0,0]\n(1..4).each {|num| c[num] = (b.select {|x| x == num}).size}\nres = c[4] + c[3] + c[2]/2 + (\nif c[2] % 2 == 1 then\n if c[1] - c[3]-2 > 0 then\n 1 + (c[1] % 4 == 0 ? c[1]/4 : c[1]/4 + 1)\n else\n 1\n end\nelse\n if c[1] - c[3] > 0 then\n c[1] % 4 == 0 ? c[1]/4 : c[1]/4 + 1\n else\n 0\n end\nend )\nprint res\n"}, {"source_code": "t = 0\ngets\ng = gets.chomp.split(\" \").map(&:to_i).sort.reverse\ng.each_with_index do |e, i|\n\tif e == 0 || e == 4\n\t\tnext\n\tend\n\n\t(i+1).upto(g.length-1) do |b|\n\t\tif (e + g[b] > 4)\n\t\t\tnext\n\t\telse\n\t\t\tg[i] += g[b]\n\t\t\tg[b] = 0\n\t\tend\n\tend\nend\nputs g.reject { |e| e == 0 }.length"}, {"source_code": "limit = gets.to_i\nsum =0\nans = 0\nx = gets.chomp.split()\nfor i in x\n\ti = i.to_i\n\tsum+=i\nend\nwhile sum!=0\n\tif sum%4==0\n\t\tans+=sum/4\n\t\tsum=0\n\telsif sum<4\n\t\tans+=1\n\t\tsum/=4\n\telse\n\t\tans+=sum/4\n\t\tsum/=4\n\tend\nend\nif ans>=limit\n\tputs ans\nelse\n\tputs limit\nend"}, {"source_code": "limit = gets.to_i\nsum =0\nans = 0\nx = gets.chomp.split()\nfor i in x\n\ti = i.to_i\n\tsum+=i\nend\nwhile sum!=0\n\tif sum%4==0\n\t\tans+=sum/4\n\t\tsum=0\n\telsif sum<4\n\t\tans+=1\n\t\tsum/=4\n\telse\n\t\tans+=sum/4\n\t\tsum/=4\n\tend\nend\nputs ans"}, {"source_code": "def main()\n\tn=gets.chomp.to_i;\n\ts=gets.chomp.split(\" \",n).map{|i| i.to_i};\n\ts=s.sort().reverse();\n\tcount=0;\n\tc=0;\n\twhile true\n\t\tsg=s[c];\n\t\tif sg==4\n\t\t\tcount=count+1\n\t\t\ts.delete_at(c);\n\t\telsif sg==3\n\t\t\ts.delete_at(c);\n\t\t\tind=s.index(1);\n\t\t\tif ind!=nil\n\t\t\t#\tputs \"d1\"\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(ind);\n\n\t\t\telse\n\t\t\t\tcount+=1\n\t\t\tend\n\t\telsif sg==2\n\t\t\ts.delete_at(c);\n\t\t\tind=s.index(2);\n\t\t\tif ind!=nil\n\t\t\t\tcount+=1\n\t\t\t\ts.delete_at(ind)\n\t\t\telse\n\t\t\t\t#check for 2 ones\n\t\t\t\tind=s.index(1);\n\t\t\t\tif ind!=nil\n\t\t\t\t#\tputs \"d1\"\n\t\t\t\t\ts.delete_at(ind);\n\t\t\t\tend\n\t\t\t\tind=s.index(1);\n\t\t\t\tif ind!=nil\n\t\t\t\t#\tputs \"d1\"\n\t\t\t\t\ts.delete_at(ind);\n\t\t\t\tend\n\t\t\t\tcount+=1\n\t\t\t\t\n\t\t\tend\n\t\telsif sg==1\n\t\t\tbreak;\n\t\t\t\n\t\tend\n\t\tif s.length()==0\n\t\t\tbreak;\n\t\tend;\t\n\tend\n\tif s.length()==0\n\t\tputs count;\n\telse\t\n\t\tcount=count+s.length()/4+1;\n\t\tputs count;\n\tend\nend\n\nmain();\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp.split(\" \").map(&:to_i)\nr = 0\n\ns = s.inject(Hash.new(0)) {|h,i| h[i] += 1; h }\n\nr = s[4]\nt = [s[3],s[1]].min\ns[3]-=t\ns[1]-=t\nr += t + s[3]\nr+=s[2]/2\ns[2]%=2\n\nif s[2]+s[1] > 0\n r+= 1\n s[1] -= s[2]*2\n s[2] = 0\nend\n\nputs r"}, {"source_code": "limit = gets.to_i\nsum =0\nans = 0\nx = gets.chomp.split()\nfor i in x\n\ti = i.to_i\n\tsum+=i\nend\nputs sum\nwhile sum!=0\n\tif sum<4\n\t\tans+=1\n\t\tsum/=4\n\telse\n\t\tans+=sum/4\n\t\tsum/=4\n\tend\nend\nputs ans"}, {"source_code": "n = Integer(gets.chomp)\n\ninput = gets.chomp.split\nnums = Array.new\nfor i in 0...n\n nums.push(Integer(input[i]))\nend\n\ncount = Array.new\ncount[0] = count[1] = count[2] = count[3] = count[4] = 0\nfor i in 0...n\n count[nums[i]] = count[nums[i]] + 1\nend\n\nans = count[4] + ( count[2] + 1) / 2\nif count[1] < count[3]\n ans += count[3]\nelse\n ans += count[1]\nend\nputs ans\n "}, {"source_code": "n = gets.to_i\nm = []\nm = gets.split.map(&:to_i)\ni = 0\nfor j in m do\n i = i + j\nend \n\nresult = (i/4.0).ceil\nputs result\n\nif i == 8\n puts 3\nelse \n puts result\nend"}, {"source_code": "# Solution CF-158-B\n\n\ndef count_cars groups\n\tarr = [0, 0, 0, 0, 0]\n\t\n\tgroups.each do |x|\n\t\tarr[ x.to_i ] += 1\n\tend\n\t\n\tcars = arr[ 4 ]\n\t\n\tcars += arr[ 3 ] + arr[ 2 ] / 2 + arr[ 1 ] / 4\n\t\n\tarr[ 1 ] = arr[ 1 ] % 4\n\tarr[ 2 ] = arr[ 2 ] % 2\n\tarr[ 1 ] = arr[ 1 ] <= arr[ 3 ] ? 0 : arr[ 1 ] - arr[ 3 ] \n\n\tcars += 1 unless arr[ 1 ] == 0 && arr[ 2 ] == 0\n\t \n \tcars\nend\n\n\n\n# Input / Output\n\nn \t\t= gets.chomp.to_i\ngroups \t= gets.split\n\nputs count_cars groups\n\n"}, {"source_code": "groupNum = gets.chomp\ngroup = gets.chomp.split(' ').map {|item| item.to_i}\n\ntotal = 0\nremaining = []\n\ngroup.sort! {|x, y| y <=> x}\n\ni = 0\n\nuntil i == group.length\n=begin\n\tprint \"Now array is \"\n\tgroup.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\tprint \"Now item is #{group[i]} \"\n\tprint \"Now i is #{i}\"\n\tputs ''\n=end\n\n\tcase group[i]\n\twhen 4 then total += 1\n\twhen 3\n\t\ttotal += 1\n\t\tfoundIndex = group.index(1)\n\t\tgroup.delete_at(foundIndex) if foundIndex\n\n\t\tfoundIndex = group.index(3)\n\t\tgroup.delete_at(foundIndex) if foundIndex\n\t\ti -= 1\n\twhen 2\n\t\ttotal += 1\n\n\t\tfoundIndex = group.index(2)\n\t\tgroup.delete_at(foundIndex) if foundIndex\n\n\t\tfoundIndex = group.index(2)\n\t\tgroup.delete_at(foundIndex) if foundIndex\n\n\t\ti -= 1\n\twhen 1\n\t\ttotal += 1\n\n\t\tfoundIndex = group.index(1)\n\t\tgroup.delete_at(foundIndex) if foundIndex\n\n\t\tfoundIndex = group.index(3)\n\t\tgroup.delete_at(foundIndex) if foundIndex\n\n\t\ti -= 1\n\tend\n\n\ti += 1\nend\n\nputs total\n"}, {"source_code": "a=gets.to_i\ns=gets.split\ns.map! {|x| x.to_i}\n\nans=0\ns.each {|x| ans+=x}\n\n\nputs (ans/4.0).ceil\n\n"}, {"source_code": "require 'pp'\n\ndef find_counter(p, map)\n eligible = []\n p.each do |n, needed|\n if map[n].nil?\n eligible = [0]\n break\n end\n eligible.push(map[n] / needed)\n end\n eligible.min\nend\n\ngets\nmap = {}\ngets.chomp(' ').split().map(&:to_i).each do |x|\n if map[x]\n map[x] += 1\n else\n map[x] = 1\n end\nend\n\npatterns = [\n {4 => 1},\n {3 => 1, 1 => 1},\n {2 => 2},\n {2 => 1, 1 => 2},\n {1 => 4},\n]\n\n# pp combination\n# pp map\n\ntaxi_needed = 0\npatterns.each do |p|\n k = find_counter(p, map)\n # decrease\n p.each do |x, needed|\n unless map[x].nil?\n map[x] -= k * needed\n end\n end\n taxi_needed += k\nend\nleftover = 0\nmap.each do |k,v|\n leftover += k * v\nend\nputs taxi_needed + (leftover / 4.0).ceil\n"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\nwhile three_num > 0 && one_num >0\n three_num -= 1\n one_num -= 1\n res +=1\nend\n\nif two_num % 2 ==0\n res = res + two_num/2\n two_num =0\nelse\n res = res + two_num/2\n two_num = 1\nend\n\nwhile one_num %2 ==0 && two_num >0 && one_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nif one_num %4 ==0\n res = res + one_num/4\n one_num = one_num%4\nend\n\nwhile one_num > 0 && two_num > 0\n res +=1\n one_num -=1\n two_num -=1\nend\n\nif three_num > 0\n res = res + three_num\nend\nif two_num > 0\n res = res + two_num\nend\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\ns = Array.new\nfor i in 0...n\n s[i] = Integer(nums[i])\nend\n\ncar1 = 0\ncar2 = 0\ncar3 = 0\ncar4 = 0\nfor i in 0...n\n if s[i] == 1\n car1 += 1\n elsif \n s[i] == 2\n car2 += 1\n elsif \n s[i] == 3\n car3 += 1\n else\n car4 += 1\n end\nend \n\ncar_2 = car2 / 2\ncar_2_still = car2 % 2\n\nif car_2_still == 1\n car_2 += 1\n if car1 == 1\n car1 = car1 - 1\n end\nend\n\nif car3 > car1\n car = car1\n car_0 = car3 - car1\nelsif car3 < car1\n car = car3\n car_0 = car1 - car3\nelse\n car = car3\n car_0 = 0\nend\n\nsum = car4 + car_2 + car + car_0\nputs sum"}, {"source_code": "group_num = gets.chomp.to_i\nmember_num = gets.chomp.split()\n\nres=0\nn=0\nthree_num=0\ntwo_num=0\none_num=0\nwhile member_num.length > n do\n case member_num.at(n)\n when \"4\"\n res+=1\n when \"3\"\n three_num+=1\n when \"2\"\n two_num+=1\n else\n one_num+=1\n end\n n+=1\nend\n\nif three_num > one_num\n res = res + one_num\n three_num = three_num - one_num\n one_num = 0\nelsif one_num > three_num\n res = res + three_num\n one_num = one_num - three_num\n three_num = 0\n else\n res = res + one_num\n one_num =0\n three_num = 0\nend\n\n\nif two_num % 2 ==0\n res = res + two_num/2\n two_num =0\nelse\n res = res + two_num/2\n two_num = 1\nend\n\nif one_num %2 ==0 && two_num >0 && one_num >0\n res +=1\n two_num = two_num-1\n one_num = one_num-2\nend\n\nif one_num %4 ==0\n res = res + one_num/4\n one_num = one_num%4\nend\n\nif one_num + two_num > 1\n res +=1\n one_num -=1\n two_num -=1\nend\n\nif three_num > 0\n res = res + three_num\nend\nif two_num > 0\n res = res + two_num\nend\nif one_num >0\n res+=1\nend\n\n p res\n"}, {"source_code": "# begone\ngets.chomp\n\n# groups = gets.chomp.split(' ').map(&:to_i).sort\n\ngroups = %w(1 2 4 3 3).map(&:to_i).sort.reverse\n\nans = 0\n\ngroups.each_with_index do |gr, idx|\n taxi = gr\n\n reversed = groups.reverse\n reversed.each_with_index do |grr, index|\n break if idx == reversed.size - 1 - index || (taxi += grr) > 4\n\n groups.pop\n end\n\n ans += 1\nend\n\np ans\n"}], "src_uid": "371100da1b044ad500ac4e1c09fa8dcb"} {"source_code": "gets.to_i.times do\n n=gets.to_i\n arr=gets.split.map(&:to_i)\n min,not2=32,0\n arr.each do |x|\n if x%2==0\n not2+=1\n else min=0 \n end\n cnt=0\n while x%2==0 do\n x/=2\n cnt+=1\n end\n min=[min,cnt].min\n end\n if min==0\n puts not2\n else\n puts not2+min-1\n end\nend", "positive_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n if xs.all?(&:even?)\r\n zeros = xs.map do |x|\r\n count = 0\r\n while x % 2 == 0\r\n x /= 2\r\n count += 1\r\n end\r\n count\r\n end\r\n p zeros.min + xs.size - 1\r\n else\r\n p xs.count(&:even?)\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n if xs.all?(&:even?)\r\n count = 0\r\n sum = xs.sum\r\n while sum % 2 == 0\r\n sum /= 2\r\n count += 1\r\n end\r\n p xs.size + count - 1\r\n else\r\n p xs.count(&:even?)\r\n end\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n even = xs.filter(&:even?)\r\n if even.any?\r\n count = 0\r\n sum = even.sum\r\n while sum % 2 == 0\r\n sum /= 2\r\n count += 1\r\n end\r\n p count + even.size - 1\r\n else\r\n p 0\r\n end\r\nend\r\n"}], "src_uid": "1b9a204dd08d61766391a3b4d2429df2"} {"source_code": "n = gets.to_i\nth1 = []\nth2 = []\nret = 1000\nn.times do\n book = gets.split(' ').map{ |i| i.to_i}\n th1.push book[1] if book[0] == 1\n th2.push book[1] if book[0] == 2\nend\nth1 = th1.sort.insert(0, 0)\nth2 = th2.sort.insert(0, 0)\nfor i in 1...th1.size do th1[i] = th1[i-1] + th1[i] end\nfor i in 1...th2.size do th2[i] = th2[i-1] + th2[i] end\nfor i in 0...th1.size\n for j in 0...th2.size\n if i + 2 * j >= th1[th1.size - i - 1] + th2[th2.size - j - 1]\n ret = [i + 2 * j, ret].min\n end\n end\nend\nputs ret", "positive_code": [{"source_code": "\nat_exit do\n book_count = get_numbers_from_line[0]\n books = []\n book_count.times do\n t,w = get_numbers_from_line[0..1]\n books << {t: t, w:w}\n end\n\n all_t = get_books_t(books)\n all_w = 0\n books_by_t = {1 => [], 2 => []}.merge books.group_by{|x| x[:t]}\n books_by_t[1].sort_by!{|b| b[:w]}\n books_by_t[2].sort_by!{|b| b[:w]}\n\n i1 = 0\n i2 = 0\n while true\n b1 = books_by_t[1][i1]\n b2 = books_by_t[2][i2]\n\n book = if b1 != nil && b2 != nil\n if !book_may_be_taken?(b2, all_t, all_w)\n i1 += 1\n b1\n elsif !book_may_be_taken?(b1, all_t, all_w)\n i2 += 1\n b2\n elsif b2[:w] <= b1[:w]\n i2 += 1\n b2\n else\n b1_2 = books_by_t[1][i1+1]\n if b1_2 != nil && b1[:w] + b1_2[:w] < b2[:w]\n i1 += 1\n b1\n else\n i2 += 1\n b2\n end\n end\n else\n b1 || b2\n end\n\n break if book.nil?\n break unless book_may_be_taken?(book, all_t, all_w)\n\n all_t -= book[:t]\n all_w += book[:w]\n end\n\n puts all_t\n\n\n #puts try_next_book(books, 0, get_books_t(books), 0)\nend\n\n\ndef book_may_be_taken?(book, all_t, all_w)\n all_w + book[:w] <= all_t - book[:t]\nend\n\ndef try_next_book(books, next_book_index, all_t, top_books_w)\n min_w = (next_book_index...books.length).map{|i| books[i][:w]}.min\n return all_t if min_w > all_t\n\n (next_book_index...books.length).map{|i|\n book = books[i]\n if book[:w] + top_books_w <= all_t - book[:t]\n if book[:w] + top_books_w == all_t - book[:t] || i == books.length - 1\n all_t - book[:t]\n else\n try_next_book(books, i+1, all_t - book[:t], top_books_w + book[:w])\n end\n else\n all_t\n end\n }.min\nend\n\ndef get_books_t(books)\n books.map{|x| x[:t]}.inject(0, :+)\nend\n\n###\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend\n\n\n\n\n"}], "negative_code": [{"source_code": "tt = tw = 0\nbook = []\ngets.to_i.times do\n temp = gets.split.map{|i| i.to_i}\n book << temp\n tt += temp[0]\nend\nbook = book.sort_by{|x| x[1]}\nfor i in 0...book.size\n if tt - book[i][0] >= tw + book[i][1]\n tt -= book[i][0]\n tw += book[i][1]\n else\n puts tt\n break\n end\nend\n"}, {"source_code": "n = gets.to_i\nth1 = []\nth2 = []\nret = 1000\nn.times do\n book = gets.split(' ').map{ |i| i.to_i}\n th1.push book[1] if book[0] == 1\n th2.push book[1] if book[0] == 2\nend\nth1 = th1.sort.insert(0, 0)\nth2 = th2.sort.insert(0, 0)\nfor i in 1...th1.size do th1[i] = th1[i-1] + th1[i] end\nfor i in 1...th2.size do th2[i] = th2[i-1] + th2[i] end\nfor i in 0..th1.size\n for j in 0..th2.size\n if i + 2 * j >= th1[th1.size - i - 1] + th2[th2.size - j - 1]\n ret = [i + 2 * j, ret].min\n end\n end\nend\nputs ret"}, {"source_code": "\nat_exit do\n book_count = get_numbers_from_line[0]\n books = []\n book_count.times do\n t,w = get_numbers_from_line[0..1]\n books << {t: t, w:w}\n end\n\n all_t = get_books_t(books)\n all_w = 0\n books_by_t = {1 => [], 2 => []}.merge books.group_by{|x| x[:t]}\n books_by_t[1].sort_by!{|b| b[:w]}\n books_by_t[2].sort_by!{|b| b[:w]}\n\n i1 = 0\n i2 = 0\n while true\n b1 = books_by_t[1][i1]\n b2 = books_by_t[2][i2]\n\n book = if b1 != nil && b2 != nil\n if !book_may_be_taken?(b2, all_t, all_w)\n b1\n elsif b2[:w] <= b1[:w]\n i2 += 1\n b2\n else\n b1_2 = books_by_t[1][i1+1]\n if b1_2 != nil && b1[:w] + b1_2[:w] < b2[:w]\n i1 += 1\n b1\n else\n if book_may_be_taken?(b2, all_t, all_w)\n i2 += 1\n b2\n else\n i1 += 1\n b1\n end\n end\n end\n else\n b1 || b2\n end\n\n break if book.nil?\n break unless book_may_be_taken?(book, all_t, all_w)\n\n all_t -= book[:t]\n all_w += book[:w]\n end\n\n puts all_t\n\n\n #puts try_next_book(books, 0, get_books_t(books), 0)\nend\n\n\ndef book_may_be_taken?(book, all_t, all_w)\n all_w + book[:w] <= all_t - book[:t]\nend\n\ndef try_next_book(books, next_book_index, all_t, top_books_w)\n min_w = (next_book_index...books.length).map{|i| books[i][:w]}.min\n return all_t if min_w > all_t\n\n (next_book_index...books.length).map{|i|\n book = books[i]\n if book[:w] + top_books_w <= all_t - book[:t]\n if book[:w] + top_books_w == all_t - book[:t] || i == books.length - 1\n all_t - book[:t]\n else\n try_next_book(books, i+1, all_t - book[:t], top_books_w + book[:w])\n end\n else\n all_t\n end\n }.min\nend\n\ndef get_books_t(books)\n books.map{|x| x[:t]}.inject(0, :+)\nend\n\n###\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend\n\n\n\n\n"}, {"source_code": "at_exit do\n # my code\n n = get_numbers_from_line[0]\n books = []\n n.times do\n books << get_numbers_from_line[0..1]\n end\n\n books.sort_by!{|t,w| w*2 + t }\n all_t = books.map{|t,w| t}.inject(0, :+)\n w = 0\n while books.length > 0\n b = books.shift\n w += b[1]\n new_all_t = all_t - b[0]\n break if w > new_all_t\n all_t = new_all_t\n end\n\n puts all_t\n\nend\n\n# User helpers\n\n\n# Helpers\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend\n\ndef trace(vars={})\n puts vars.map{|key, value| \"#{key}: #{value}\"}.join('; ')\nend"}, {"source_code": "at_exit do\n # my code\n n = get_numbers_from_line[0]\n books = []\n n.times do\n books << get_numbers_from_line[0..1]\n end\n\n books.sort_by!{|t,w| w - t }\n all_t = books.map{|t,w| t}.inject(0, :+)\n w = 0\n while books.length > 0\n\n i = 0\n j = nil\n best_all_t = nil\n books.each do |b|\n new_w = w + b[1]\n new_all_t = all_t - b[0]\n if new_w <= new_all_t\n if best_all_t.nil? || new_all_t < best_all_t\n best_all_t = new_all_t\n j = i\n end\n end\n i += 1\n end\n\n break if j.nil?\n\n b = books[j]\n books.delete_at(j)\n w += b[1]\n all_t -= b[0]\n end\n\n puts all_t\n\nend\n\n# User helpers\n\n\n# Helpers\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend\n\ndef trace(vars={})\n puts vars.map{|key, value| \"#{key}: #{value}\"}.join('; ')\nend"}, {"source_code": "at_exit do\n # my code\n n = get_numbers_from_line[0]\n books = []\n n.times do\n books << get_numbers_from_line[0..1]\n end\n\n books.sort_by!{|t,w| w - t }\n all_t = books.map{|t,w| t}.inject(0, :+)\n w = 0\n while books.length > 0\n b = books.shift\n w += b[1]\n new_all_t = all_t - b[0]\n break if w > new_all_t\n all_t = new_all_t\n end\n\n puts all_t\n\nend\n\n# User helpers\n\n\n# Helpers\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend\n\ndef trace(vars={})\n puts vars.map{|key, value| \"#{key}: #{value}\"}.join('; ')\nend"}, {"source_code": "\nat_exit do\n book_count = get_numbers_from_line[0]\n books = []\n book_count.times do\n t,w = get_numbers_from_line[0..1]\n books << {t: t, w:w}\n end\n\n all_t = get_books_t(books)\n all_w = 0\n books_by_t = books.group_by{|x| x[:t]}\n books_by_t[1].sort_by{|b| b[:w]}\n books_by_t[2].sort_by{|b| b[:w]}\n\n i1 = 0\n i2 = 0\n while true\n b1 = books_by_t[1][i1]\n b2 = books_by_t[2][i2]\n\n book = if b1 != nil && b2 != nil\n if b2[:w] <= b1[:w]\n i2 += 1\n b2\n else\n b1_2 = books_by_t[1][i1+1]\n if b1_2 != nil && b1[:w] + b1_2[:w] < b2[:w]\n i1 += 1\n b1\n else\n if all_w + b2[:w] <= all_t - b2[:t]\n i2 += 1\n b2\n else\n i1 += 1\n b1\n end\n end\n end\n else\n b1 || b2\n end\n\n break if book.nil?\n break if all_w + book[:w] > all_t - book[:t]\n\n all_t -= book[:t]\n all_w += book[:w]\n end\n\n puts all_t\n\n\n #puts try_next_book(books, 0, get_books_t(books), 0)\nend\n\ndef try_next_book(books, next_book_index, all_t, top_books_w)\n min_w = (next_book_index...books.length).map{|i| books[i][:w]}.min\n return all_t if min_w > all_t\n\n (next_book_index...books.length).map{|i|\n book = books[i]\n if book[:w] + top_books_w <= all_t - book[:t]\n if book[:w] + top_books_w == all_t - book[:t] || i == books.length - 1\n all_t - book[:t]\n else\n try_next_book(books, i+1, all_t - book[:t], top_books_w + book[:w])\n end\n else\n all_t\n end\n }.min\nend\n\ndef get_books_t(books)\n books.map{|x| x[:t]}.inject(0, :+)\nend\n\n###\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend\n\n\n\n\n"}, {"source_code": "\nat_exit do\n book_count = get_numbers_from_line[0]\n books = []\n book_count.times do\n t,w = get_numbers_from_line[0..1]\n books << {t: t, w:w}\n end\n\n all_t = get_books_t(books)\n all_w = 0\n books_by_t = {1 => [], 2 => []}.merge books.group_by{|x| x[:t]}\n books_by_t[1].sort_by!{|b| b[:w]}\n books_by_t[2].sort_by!{|b| b[:w]}\n\n i1 = 0\n i2 = 0\n while true\n b1 = books_by_t[1][i1]\n b2 = books_by_t[2][i2]\n\n book = if b1 != nil && b2 != nil\n if b2[:w] <= b1[:w]\n i2 += 1\n b2\n else\n b1_2 = books_by_t[1][i1+1]\n if b1_2 != nil && b1[:w] + b1_2[:w] < b2[:w]\n i1 += 1\n b1\n else\n if all_w + b2[:w] <= all_t - b2[:t]\n i2 += 1\n b2\n else\n i1 += 1\n b1\n end\n end\n end\n else\n b1 || b2\n end\n\n break if book.nil?\n break if all_w + book[:w] > all_t - book[:t]\n\n all_t -= book[:t]\n all_w += book[:w]\n end\n\n puts all_t\n\n\n #puts try_next_book(books, 0, get_books_t(books), 0)\nend\n\ndef try_next_book(books, next_book_index, all_t, top_books_w)\n min_w = (next_book_index...books.length).map{|i| books[i][:w]}.min\n return all_t if min_w > all_t\n\n (next_book_index...books.length).map{|i|\n book = books[i]\n if book[:w] + top_books_w <= all_t - book[:t]\n if book[:w] + top_books_w == all_t - book[:t] || i == books.length - 1\n all_t - book[:t]\n else\n try_next_book(books, i+1, all_t - book[:t], top_books_w + book[:w])\n end\n else\n all_t\n end\n }.min\nend\n\ndef get_books_t(books)\n books.map{|x| x[:t]}.inject(0, :+)\nend\n\n###\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend\n\n\n\n\n"}], "src_uid": "f9c16d5c72fe139aa91bc1a9e44d4dc2"} {"source_code": "t = gets.to_i\n\n(0...t).each do\n n, x = *gets.chomp.split(\" \").map(&:to_i)\n h = gets.chomp.split(\" \").map(&:to_i)\n\n h.sort!\n\n front = h[...n]\n back = h[n..]\n\n res = \"YES\"\n front.each.with_index do |k, idx|\n if back[idx] - k < x\n res = \"NO\"\n break\n end\n end\n puts res\nend\n", "positive_code": [{"source_code": "gets.to_i.times {\n\tn,x = gets.split.map(&:to_i)\n\th = gets.split.map(&:to_i).sort\n\tputs h[0..n-1].zip(h[n..]).map { |a,b| b-a>= x}.all? ? \"YES\" : \"NO\" \n}"}], "negative_code": [{"source_code": "t = gets.to_i\n\n(0...t).each do\n n, x = *gets.chomp.split(\" \").map(&:to_i)\n h = gets.chomp.split(\" \").map(&:to_i)\n\n h.sort!\n\n front = h[...n]\n back = h[n..]\n\n res = \"YES\"\n front.each.with_index do |x, idx|\n if x >= back[idx]\n res = \"NO\"\n break\n end\n end\n puts res\nend\n"}], "src_uid": "52769cd7b3b0d63a7259a5d0754c4803"} {"source_code": "class Debt\n attr_accessor :users, :debts\n\n def initialize(users)\n @users = users\n @debts = Array.new(users, 0)\n end\n\n\n def add_debt(user_from, user_to, users_debt)\n\n @debts[user_from - 1] -= users_debt\n @debts[user_to - 1] += users_debt\n\n end\n\n def calculate\n return 0 if debts.empty?\n @debts.inject(0){|sum, element| sum += element > 0 ? element : 0}\n end\n\nend\n\n\ndef read_ints\n gets.split(\" \").collect { |e| e.to_i }\nend\n\nusers, debts_count = read_ints\n\n\ndebt = Debt.new(users)\ndebts_count.times do\n user_from, user_to, users_debt = read_ints\n debt.add_debt user_from, user_to, users_debt\n\nend\n\n\nputs debt.calculate", "positive_code": [{"source_code": "n,m=gets.split.map(&:to_i)\nd=[0]*n\nm.times do\n a,b,c=gets.split.map(&:to_i)\n d[a-1]-=c\n d[b-1]+=c\nend\nputs d.inject(0){|t,x|t+x.abs}/2\n"}], "negative_code": [{"source_code": "n,m=gets.split.map(&:to_i)\nd=[0]*n\nm.times do\n a,b,c=gets.split.map(&:to_i)\n d[a-1]-=c\n d[b-1]+=c\nend\nputs d.inject{|x,a|a+x.abs}/2\n"}], "src_uid": "b53c3e55834db8184d8caf4630aaa573"} {"source_code": "gets.to_i.times{gets\na=c=0\nb=gets.split.map(&:to_i).map{|x|c=[a-=x,c].max}\np c}", "positive_code": [{"source_code": "gets.to_i.times do\n n=gets.to_i\n a=gets.split(\" \").map(&:to_i)\n\n i=0\n j=1\n while i < n && j < n\n if j <= i\n j += 1\n elsif a[i] > 0 && a[j] < 0\n x = [a[i], -a[j]].min\n a[i] -= x\n a[j] += x\n elsif a[j] >= 0\n j += 1\n elsif a[i] <= 0\n i += 1\n end\n end\n\n puts (a.select {|x| x > 0} + [0]).reduce(:+)\n\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n\tn = gets.to_i\n\ta = gets.split.map &:to_i\n\tmax = 0\n\tsum = 0\n\ta.reverse_each do |x|\n\t\tsum += x\n\t\tmax = [max, sum].max\n\tend\n\tp max\nend"}, {"source_code": "gets.to_i.times{gets\na=c=0\ngets.split.map{|x|c=[a-=x.to_i,c].max}\np c}"}, {"source_code": "gets.to_i.times{gets\na=c=0\ngets.split.map(&:to_i).map{|x|c=[a-=x,c].max}\np c}"}, {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n l = 0\n r = n - 1\n cost = a.select(&:positive?).sum\n stock = 0\n\n a.each do |v|\n if v > 0\n stock += v\n elsif v < 0 && stock > 0\n d = [v.abs, stock].min\n cost -= d\n stock -= d\n end\n end\n\n puts cost\nend\n"}, {"source_code": "gets.to_i.times{gets\na=c=0\ngets.split.map{|x|c=[a-=x.to_i,c].max}\np c}"}], "negative_code": [], "src_uid": "bd0b14e53ade1207022464ebafdf8c9a"} {"source_code": "str = gets.strip\n\noc = 0\nnewstr = \"\"\n\nstr.each_char do |c|\n if c == \"1\"\n oc += 1\n else\n newstr << c\n end\nend\n\ntp = nil\n0.upto(newstr.size-1).each do |i|\n if newstr[i]=='2'\n tp = i\n break\n end\nend\n\nif tp.nil?\n puts newstr + (\"1\" * oc)\nelse\n puts newstr[0...tp] + (\"1\" * oc) + newstr[tp..-1]\nend", "positive_code": [{"source_code": "S = gets.chomp\nans = ''\none = 0\nS.chars do |c|\n if c == '1'\n one += 1\n else\n ans << c\n end\nend\npt = ans.index('2') || ans.length\nans.insert(pt, '1'*one)\nputs ans"}], "negative_code": [], "src_uid": "91cefa6793e77b3e4f4896616a164ff2"} {"source_code": "n,k=gets.strip.split.map(&:to_i)\n\npos=[]\n(k+1).downto(1).each do |i|\n tmp = []\n j = i\n while j<=n do\n tmp << j\n j += ((2*k)+1)\n end\n next if tmp.size == 0\n lp = tmp[-1]\n if lp+k >= n\n pos = tmp\n break\n end\nend\n\nputs pos.size\nputs pos.join(' ')", "positive_code": [{"source_code": "\n#require \"pry\"\n\nn, k = gets.chomp.split(\" \").map(&:to_i)\n\ndef shashlik_cooking(n, k)\n \n r = n % (2*k + 1)\n\n \n steps = []\n #binding.pry\n i = 0\n while k+1 + i*(2*k+1) <= n\n steps[i] = k+1 + i*(2*k+1)\n i += 1\n end\n #binding.pry\n\n if r > 0 and r <= k and k != 0\n steps.map!{|s| s - (k+1-r)}\n steps << n\n end\n\n\n p steps.size\n if steps[0] > n - steps[steps.size-1]\n steps.reverse!\n steps.map!{|i| n-i+1}\n end\n print steps.join(' ')\nend\n\nshashlik_cooking(n, k)\n"}], "negative_code": [{"source_code": "\n#require \"pry\"\n\nn, k = gets.chomp.split(\" \").map(&:to_i)\n\ndef shashlik_cooking(n, k)\n \n r = n % (2*k + 1)\n\n \n steps = []\n #binding.pry\n i = 0\n while k+1 + i*(2*k+1) <= n\n steps[i] = k+1 + i*(2*k+1)\n i += 1\n end\n #binding.pry\n\n if r > 0 and r <= k and k != 0\n steps.map!{|s| s - k}\n steps << n - k - 1 + r\n end\n\n\n p steps.size\n if steps[0] > n - steps[steps.size-1]\n steps.reverse!\n steps.map!{|i| n-i+1}\n end\n print steps.join(' ')\nend\n\nshashlik_cooking(n, k)\n"}, {"source_code": "\n#require \"pry\"\n\nn, k = gets.chomp.split(\" \").map(&:to_i)\n\ndef shashlik_cooking(n, k)\n \n t = n / (2*k + 1)\n r = n % (2*k + 1)\n p t+1\n \n steps = []\n #binding.pry\n i = 0\n while k+1 + i*(2*k+1) <= n\n steps[i] = k+1 + i*(2*k+1)\n i += 1\n end\n #binding.pry\n\n if r > 0 and r <= k\n steps.map!{|s| s - k}\n steps << n - k - 1 + r\n end\n #binding.pry\n\n p steps.join(' ')\nend\n\nshashlik_cooking(n, k)\n"}, {"source_code": "\n#require \"pry\"\n\nn, k = gets.chomp.split(\" \").map(&:to_i)\n\ndef shashlik_cooking(n, k)\n \n t = n / (2*k + 1)\n r = n % (2*k + 1)\n\n \n steps = []\n #binding.pry\n i = 0\n while k+1 + i*(2*k+1) <= n\n steps[i] = k+1 + i*(2*k+1)\n i += 1\n end\n #binding.pry\n\n if r > 0 and r <= k and k != 0\n t += 1\n steps.map!{|s| s - k}\n steps << n - k - 1 + r\n end\n #binding.pry\n\n res = \"#{steps.join(' ')}\"\n p t\n print res\nend\n\nshashlik_cooking(n, k)\n"}, {"source_code": "\n#require \"pry\"\n\nn, k = gets.chomp.split(\" \").map(&:to_i)\n\ndef shashlik_cooking(n, k)\n \n t = n / (2*k + 1)\n r = n % (2*k + 1)\n p t+1\n \n steps = []\n #binding.pry\n i = 0\n while k+1 + i*(2*k+1) <= n\n steps[i] = k+1 + i*(2*k+1)\n i += 1\n end\n #binding.pry\n\n if r > 0 and r <= k\n steps.map!{|s| s - k}\n steps << n - k - 1 + r\n end\n #binding.pry\n\n res = \"#{steps.join(' ')}\"\n print res\nend\n\nshashlik_cooking(n, k)\n"}, {"source_code": "\n#require \"pry\"\n\nn, k = gets.chomp.split(\" \").map(&:to_i)\n\ndef shashlik_cooking(n, k)\n \n r = n % (2*k + 1)\n\n \n steps = []\n #binding.pry\n i = 0\n while k+1 + i*(2*k+1) <= n\n steps[i] = k+1 + i*(2*k+1)\n i += 1\n end\n #binding.pry\n\n if r > 0 and r <= k and k != 0\n steps.map!{|s| s - k}\n steps << n\n end\n\n\n p steps.size\n if steps[0] > n - steps[steps.size-1]\n steps.reverse!\n steps.map!{|i| n-i+1}\n end\n print steps.join(' ')\nend\n\nshashlik_cooking(n, k)\n"}, {"source_code": "\n#require \"pry\"\n\nn, k = gets.chomp.split(\" \").map(&:to_i)\n\ndef shashlik_cooking(n, k)\n \n t = n / (2*k + 1)\n r = n % (2*k + 1)\n p t+1\n \n steps = []\n #binding.pry\n i = 0\n while k+1 + i*(2*k+1) <= n\n steps[i] = k+1 + i*(2*k+1)\n i += 1\n end\n #binding.pry\n\n if r > 0 and r <= k and k != 0\n steps.map!{|s| s - k}\n steps << n - k - 1 + r\n end\n #binding.pry\n\n res = \"#{steps.join(' ')}\"\n print res\nend\n\nshashlik_cooking(n, k)\n"}, {"source_code": "\n#require \"pry\"\n\nn, k = gets.chomp.split(\" \").map(&:to_i)\n\ndef shashlik_cooking(n, k)\n \n t = n / (2*k + 1)\n r = n % (2*k + 1)\n\n \n steps = []\n #binding.pry\n i = 0\n while k+1 + i*(2*k+1) <= n\n steps[i] = k+1 + i*(2*k+1)\n i += 1\n end\n #binding.pry\n\n if r > 0 and r <= k and k != 0\n t += 1\n steps.map!{|s| s - k}\n steps << n - k - 1 + r\n end\n\n\n p t\n if steps[0] > n - steps[steps.size-1]\n steps.reverse!\n steps.map!{|i| n-i+1}\n end\n print steps.join(' ')\nend\n\nshashlik_cooking(n, k)\n"}], "src_uid": "dfd60a02670749c67b0f96df1a0709b9"} {"source_code": "n,k=gets.split.map &:to_i\nputs gets['#'*k]?'NO':'YES'\n", "positive_code": [{"source_code": "A = gets.chomp.split(' ').map{|c| c.to_i}\nB = gets.chomp\na = '#'*A[1]\nif B[a]\n\tputs \"NO\"\nelse\n\tputs \"YES\"\nend\n"}, {"source_code": "k = gets.split[1].to_i\nputs (gets.chomp.split('.').map(&:size).max || -1) >= k ? :NO : :YES\n"}, {"source_code": "# https://codeforces.com/problemset/problem/299/B\n\ninput = gets.split(' ').map(&:to_i)\nroad = gets.chomp\n\nk = input[1]\n\nif road.include? \"#\"*k\n puts \"NO\"\nelse\n puts \"YES\"\nend\n"}, {"source_code": "n,k=gets.split.map &:to_i\nputs gets['#'*k]?'NO':'YES'\n"}, {"source_code": "n,k=gets.split.map &:to_i\nputs gets['#'*k]?'NO':'YES'\n"}, {"source_code": "n,k=gets.split.map &:to_i\nputs gets['#'*k]?'NO':'YES'"}, {"source_code": "n, k = gets.split(' ').map { |i| i.to_i }\nroads = gets\ncan = true\ncnt = 0\nfor i in 0...roads.size\n if roads[i] == '#' then cnt += 1\n else cnt = 0\n end\n can = false if cnt >= k\nend\nputs can ? \"YES\" : \"NO\"\n"}, {"source_code": "n,k=gets.split.map &:to_i\nputs gets['#'*k]?'NO':'YES'\n"}, {"source_code": "n,k=gets.split.map &:to_i\nputs gets['#'*k]?'NO':'YES'\n"}, {"source_code": "n,k=gets.split.map &:to_i\nputs gets['#'*k]?'NO':'YES'"}, {"source_code": "n,k=gets.split.map &:to_i\ns=gets\npre=-1\n(0..n).each do |i|\n next if s[i]!='.'\n exit !puts('NO') if i-pre>k\n pre=i\nend\nputs 'YES'"}, {"source_code": "def main()\n\tn,k=gets.chomp.to_s.split(\" \").map{|i| i.to_i}\n\troad=gets.chomp\n\tf=true\n\ti=0\n\twhile(i=k\n\t\t\t\tf=false\n\t\t\t\tbreak\n\t\t\tend\n\t\telse\n\t\t\ti+=1\n\t\tend\n\tend\n\tif f\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\nmain()"}, {"source_code": "def ksuha(n, k, input)\n j = 0\n check = false\n if input[0..-1] == \"#\" * n\n return false\n end\n while j < n\n if input[j] == \".\"\n j += 1\n next\n elsif input[j] == \"#\"\n (1..k).each do |i|\n if input[j..j+i] != \"#\" * (i+1)\n j+= i\n check = true\n break\n end\n end\n if check\n check = false\n else\n return false\n end\n end\n end\n true\nend\n\n A = gets.chomp.split(' ').map{|c| c.to_i}\n B = gets.chomp\n a = '#'*A[1]\n if B[a]\n puts \"NO\"\n else\n puts \"YES\"\n end\n\n\n"}, {"source_code": "n,k=gets.split.map &:to_i\nputs gets['#'*k]?'NO':'YES'\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\ns = gets.chomp\nif s[-1] == '#'\n\tputs \"NO\"\n\texit 0\nend\ncc = 0\nn.times do |i|\n\tif s[i] == '#'\n\t\tcc += 1\n\telse\n\t\tif cc >= k\n\t\t\tputs \"NO\"\n\t\t\texit 0\n\t\tend\n\t\tcc = 0\n\tend\nend\nputs \"YES\"\n"}, {"source_code": "at_exit do\n sector_count, step_count = get_numbers_from_line[0..1]\n road = gets\n max_stone_length = 0\n in_stone = false\n current_stone_length = 0\n (0...sector_count).each do |i|\n if road[i] == '#'\n in_stone = true\n current_stone_length += 1\n else\n if in_stone\n in_stone = false\n max_stone_length = current_stone_length if current_stone_length > max_stone_length\n current_stone_length = 0\n end\n end\n end\n\n if step_count > max_stone_length\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend"}, {"source_code": "n,k=gets.split.map &:to_i\nputs gets['#'*k]?'NO':'YES'\n"}, {"source_code": "n,k=gets.split.map &:to_i\nputs gets['#'*k]?'NO':'YES'\n"}], "negative_code": [{"source_code": "k = gets.split[1].to_i\nputs gets.split('.').map(&:size).max >= k ? :NO : :YES\n"}], "src_uid": "d504d894b2f6a830c4d3b4edc54395be"} {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nrequire 'date'\nn=gets.to_i\nh={}\nn.times{\n\tn,d,p,t=gets.split.map(&:to_i)\n\tdate=Date.new(2013,n,d)\n\tif h[date]\n\t\th[date]+=p\n\telse\n\t\th[date]=p\n\tend\n\t(t-1).times{\n\t\tdate-=1\n\t\tif h[date]\n\t\t\th[date]+=p\n\t\telse\n\t\t\th[date]=p\n\t\tend\n\t}\n}\np h.values.max", "positive_code": [{"source_code": "require 'Date'\n\nline = File.read(\"input.txt\").split(\"\\n\")\n\nn = line[0].to_i\ncount = Hash.new(0)\nline[1..-1].each do |l|\n\tm,d,j,t = l.split(\" \").map(&:to_i)\n\tcurr = Date.new(2013,m,d)\n\tfinish = curr - 1 \n\tstart = curr - t\n\t(start..finish).each do |k|\n\t\tcount[k] += j\n\tend\nend\n\nputs \"#{count}\"\nFile.open(\"output.txt\", 'w') { |file| \n\tfile.puts \"#{count.values.max}\"\n}\n\n\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nrequire 'date'\nn=gets.to_i\nh={}\nn.times{\n\tn,d,p,t=gets.split.map(&:to_i)\n\tdate=Date.new(2013,n,d)\n\tif h[date]\n\t\th[date]+=p\n\telse\n\t\th[date]=p\n\tend\n\t(t-1).times{\n\t\tdate-=1\n\t\tif h[date]\n\t\t\th[date]+=p\n\t\telse\n\t\t\th[date]=p\n\t\tend\n\t}\n}\np h.values.max"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nrequire 'date'\nn=gets.to_i\nh={}\nn.times{\n\tn,d,p,t=gets.split.map(&:to_i)\n\tdate=Date.new(2013,n,d)\n\tif h[date]\n\t\th[date]+=p\n\telse\n\t\th[date]=p\n\tend\n\t(t-1).times{\n\t\tdate-=1\n\t\tif h[date]\n\t\t\th[date]+=p\n\t\telse\n\t\t\th[date]=p\n\t\tend\n\t}\n}\np h.values.max\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nrequire 'date'\nn=gets.to_i\nh={}\nn.times{\n\tn,d,p,t=gets.split.map(&:to_i)\n\tdate=Date.new(2013,n,d)\n\tif h[date]\n\t\th[date]+=p\n\telse\n\t\th[date]=p\n\tend\n\t(t-1).times{\n\t\tdate-=1\n\t\tif h[date]\n\t\t\th[date]+=p\n\t\telse\n\t\t\th[date]=p\n\t\tend\n\t}\n}\np h.values.max\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nrequire 'date'\nn=gets.to_i\nh={}\nn.times{\n\tn,d,p,t=gets.split.map(&:to_i)\n\tdate=Date.new(2013,n,d)\n\tif h[date]\n\t\th[date]+=p\n\telse\n\t\th[date]=p\n\tend\n\t(t-1).times{\n\t\tdate-=1\n\t\tif h[date]\n\t\t\th[date]+=p\n\t\telse\n\t\t\th[date]=p\n\t\tend\n\t}\n}\np h.values.max"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nrequire 'date'\nn=gets.to_i\nh={}\nn.times{\n\tn,d,p,t=gets.split.map(&:to_i)\n\tdate=Date.new(2013,n,d)\n\tif h[date]\n\t\th[date]+=p\n\telse\n\t\th[date]=p\n\tend\n\t(t-1).times{\n\t\tdate-=1\n\t\tif h[date]\n\t\t\th[date]+=p\n\t\telse\n\t\t\th[date]=p\n\t\tend\n\t}\n}\np h.values.max\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nrequire 'date'\nn=gets.to_i\nh={}\nn.times{\n\tn,d,p,t=gets.split.map(&:to_i)\n\tdate=Date.new(2013,n,d)\n\tif h[date]\n\t\th[date]+=p\n\telse\n\t\th[date]=p\n\tend\n\t(t-1).times{\n\t\tdate-=1\n\t\tif h[date]\n\t\t\th[date]+=p\n\t\telse\n\t\t\th[date]=p\n\t\tend\n\t}\n}\np h.values.max\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nrequire 'date'\nn=gets.to_i\nh={}\nn.times{\n\tn,d,p,t=gets.split.map(&:to_i)\n\tdate=Date.new(2013,n,d)\n\tif h[date]\n\t\th[date]+=p\n\telse\n\t\th[date]=p\n\tend\n\t(t-1).times{\n\t\tdate-=1\n\t\tif h[date]\n\t\t\th[date]+=p\n\t\telse\n\t\t\th[date]=p\n\t\tend\n\t}\n}\np h.values.max\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nrequire 'date'\nn=gets.to_i\nh={}\nn.times{\n\tn,d,p,t=gets.split.map(&:to_i)\n\tdate=Date.new(2013,n,d)\n\tif h[date]\n\t\th[date]+=p\n\telse\n\t\th[date]=p\n\tend\n\t(t-1).times{\n\t\tdate-=1\n\t\tif h[date]\n\t\t\th[date]+=p\n\t\telse\n\t\t\th[date]=p\n\t\tend\n\t}\n}\np h.values.max\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nrequire 'date'\nn=gets.to_i\nh={}\nn.times{\n\tn,d,p,t=gets.split.map(&:to_i)\n\tdate=Date.new(2013,n,d)\n\tif h[date]\n\t\th[date]+=p\n\telse\n\t\th[date]=p\n\tend\n\t(t-1).times{\n\t\tdate-=1\n\t\tif h[date]\n\t\t\th[date]+=p\n\t\telse\n\t\t\th[date]=p\n\t\tend\n\t}\n}\np h.values.max\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nrequire 'date'\nn=gets.to_i\nh={}\nn.times{\n\tn,d,p,t=gets.split.map(&:to_i)\n\tdate=Date.new(2013,n,d)\n\tif h[date]\n\t\th[date]+=p\n\telse\n\t\th[date]=p\n\tend\n\t(t-1).times{\n\t\tdate-=1\n\t\tif h[date]\n\t\t\th[date]+=p\n\t\telse\n\t\t\th[date]=p\n\t\tend\n\t}\n}\np h.values.max\n"}], "negative_code": [{"source_code": "line = File.read(\"input.txt\").split(\"\\n\")\n\nn = line[0].to_i\ncount = Hash.new(0)\nline[1..-1].each do |l|\n\tm,d,j,t = l.split(\" \").map(&:to_i)\n\tcurr = (m * 30) + d\n\tfinish = curr - 1 \n\tstart = curr - t\n\t(start..finish).each do |k|\n\t\tcount[k] += j\n\tend\nend\n\n\nFile.open(\"output.txt\", 'w') { |file| \n\tfile.puts \"#{count.values.max}\"\n}\n\n\n"}, {"source_code": "n = gets.to_i\ncount = Hash.new(0)\nn.times do \n\tm,d,j,t = gets.split(\" \").map(&:to_i)\n\tcurr = (m * 30) + d\n\tfinish = curr - 1 \n\tstart = curr - t\n\t(start..finish).each do |k|\n\t\tcount[k] += j\n\tend\nend\n\nputs \"#{count.values.max}\""}], "src_uid": "34655e8de9f1020677c5681d9d217d75"} {"source_code": "gets;x,A,B=0,[4,16,82,6724,50626,2562991876],[0,1,2,0,3,1,2]\nfor a in gets.split.map &:to_i do\n x^=B[A.count {|i| a>=i}]\nend\nputs (x==0?\"Rublo\":\"Furlo\")\n\n", "positive_code": [{"source_code": "gets;x,A,B=0,[4,16,82,6724,50626,2562991876],[0,1,2,0,3,1,2]\nfor a in gets.split.map &:to_i do\n x^=B[A.count {|i| a>=i}]\nend\nputs (x==0?\"Rublo\":\"Furlo\")\n\n"}, {"source_code": "gets;x,A,B=0,[4,16,82,6724,50626,2562991876],[0,1,2,0,3,1,2]\nfor a in gets.split.map &:to_i do\n x^=B[A.count {|i| a>=i}]\nend\nputs (x==0?\"Rublo\":\"Furlo\")\n\n"}, {"source_code": "I =->{gets.split.map &:to_i}\nRD =->{gets.to_i}\n\ndef sg(x)\n return 2 if(x>=2562991876)\n return 1 if(x>=45212176)\n return 1 if(x>=50626)\n return 3 if(x>=6724)\n return 0 if(x>=82)\n return 2 if(x>=16)\n return 1 if(x>=4)\n return 0\nend\nres = 0; n = RD[]; a = I[]; a.each{|ai|\n res ^= sg(ai)\n}\n\nputs res.zero? ? \"Rublo\" : \"Furlo\""}, {"source_code": "gets;x,A,B=0,[4,16,82,6724,50626,2562991876],[0,1,2,0,3,1,2]\nfor a in gets.split.map &:to_i do\n x^=B[A.count {|i| a>=i}]\nend\nputs (x==0?\"Rublo\":\"Furlo\")\n\n"}, {"source_code": "gets;x,A,B=0,[4,16,82,6724,50626,2562991876],[0,1,2,0,3,1,2]\nfor a in gets.split.map &:to_i do\n x^=B[A.count {|i| a>=i}]\nend\nputs (x==0?\"Rublo\":\"Furlo\")\n"}, {"source_code": "gets;x,A,B=0,[4,16,82,6724,50626,2562991876],[0,1,2,0,3,1,2]\nfor a in gets.split.map &:to_i do\n x^=B[A.count {|i| a>=i}]\nend\nputs (x==0?\"Rublo\":\"Furlo\")\n\n"}, {"source_code": "gets;x,A,B=0,[4,16,82,6724,50626,2562991876],[0,1,2,0,3,1,2]\nfor a in gets.split.map &:to_i do\n x^=B[A.count {|i| a>=i}]\nend\nputs (x==0?\"Rublo\":\"Furlo\")\n\n"}, {"source_code": "gets;x,A,B=0,[4,16,82,6724,50626,2562991876],[0,1,2,0,3,1,2]\nfor a in gets.split.map &:to_i do\n x^=B[A.count {|i| a>=i}]\nend\nputs (x==0?\"Rublo\":\"Furlo\")\n\n"}, {"source_code": "gets;x,A,B=0,[4,16,82,6724,50626,2562991876],[0,1,2,0,3,1,2]\nfor a in gets.split.map &:to_i do\n x^=B[A.count {|i| a>=i}]\nend\nputs (x==0?\"Rublo\":\"Furlo\")\n\n"}], "negative_code": [{"source_code": "RD =->{gets.to_i}\ndef sg(x)\n return 2 if(x>=2562991876)\n return 1 if(x>=45212176)\n return 1 if(x>=50626)\n return 3 if(x>=6724)\n return 0 if(x>=82)\n return 2 if(x>=16)\n return 1 if(x>=4)\n return 0\nend\nres = 0; n = RD[]; n.times{\n res ^= sg(RD[])\n}\nputs res.zero? ? \"Rublo\" : \"Furlo\""}, {"source_code": "RD =->{gets.to_i}\ndef sg(x)\n return 2 if(x>=2562991876)\n return 1 if(x>=45212176)\n return 1 if(x>=50626)\n return 3 if(x>=6724)\n return 0 if(x>=82)\n return 2 if(x>=16)\n return 1 if(x>=4)\n return 0\nend\nres = 0; RD[].times{\n res ^= sg(RD[])\n}\nputs res.zero? ? \"Rublo\" : \"Furlo\""}], "src_uid": "cc23f07b6539abbded7e120793bef6a7"} {"source_code": "n=gets.to_i\nh=[0]*8\na=gets.scan(/\\d/){|x|h[x.to_i]+=1}\nif h[1]==n/3 && h[2]+h[3]==n/3 && h[4]+h[6]==n/3 && h[3]<=h[6]\n h[3].times{puts '1 3 6'}\n h[6]-=h[3]\n h[6].times{puts '1 2 6'}\n h[4].times{puts '1 2 4'}\nelse\n p -1\nend\n\n\n", "positive_code": [{"source_code": "n=gets.to_i\nh=[0]*8\na=gets.scan(/\\d/){|x|h[x.to_i]+=1}\nif h[1]==n/3 && h[2]+h[3]==n/3 && h[4]+h[6]==n/3 && h[3]<=h[6]\n h[3].times{puts '1 3 6'}\n h[6]-=h[3]\n h[6].times{puts '1 2 6'}\n h[4].times{puts '1 2 4'}\nelse\n p -1\nend\n\n\n"}, {"source_code": "n=gets.to_i\nh=[0]*8\na=gets.scan(/\\d/){|x|h[x.to_i]+=1}\nif h[1]==n/3 && h[2]+h[3]==n/3 && h[4]+h[6]==n/3 && h[3]<=h[6]\n h[3].times{puts '1 3 6'}\n h[6]-=h[3]\n h[6].times{puts '1 2 6'}\n h[4].times{puts '1 2 4'}\nelse\n p -1\nend\n\n\n"}, {"source_code": "n=gets.to_i\nh=[0]*8\na=gets.scan(/\\d/){|x|h[x.to_i]+=1}\nif h[1]==n/3 && h[2]+h[3]==n/3 && h[4]+h[6]==n/3 && h[3]<=h[6]\n h[3].times{puts '1 3 6'}\n h[6]-=h[3]\n h[6].times{puts '1 2 6'}\n h[4].times{puts '1 2 4'}\nelse\n p -1\nend\n\n\n"}, {"source_code": "cnt = gets.to_i\nnums = gets.split.map(&:to_i)\nn1=n2=n3=n4=n6=0\nnums.each{|n|\n\tcase n\n\twhen 1; n1 += 1\n\twhen 2; n2 += 1\n\twhen 3; n3 += 1\n\twhen 4; n4 += 1\n\twhen 6; n6 += 1\n\twhen 5, 7\n\t\tputs -1\n\t\texit\n\tend\n}\nif n1 != cnt/3 || n2+n3 != cnt/3 || n4+n6 != cnt/3 || n2 0 && num_list[2] > 0 && num_list[4] > 0\n answer << \"1 2 4\"\n num_list[1] -= 1\n num_list[2] -= 1\n num_list[4] -= 1\n end\n\n while num_list[1] > 0 && num_list[2] > 0 && num_list[6] > 0\n answer << \"1 2 6\"\n num_list[1] -= 1\n num_list[2] -= 1\n num_list[6] -= 1\n end\n\n while num_list[1] > 0 && num_list[3] > 0 && num_list[6] > 0\n answer << \"1 3 6\"\n num_list[1] -= 1\n num_list[3] -= 1\n num_list[6] -= 1\n end\n\n if answer.size == n/3\n puts answer\n else\n puts -1\n end\n end\nend\n\na = A.new"}, {"source_code": "n=gets.to_i\nh=[0]*8\na=gets.scan(/\\d/){|x|h[x.to_i]+=1}\nif h[1]==n/3 && h[2]+h[3]==n/3 && h[4]+h[6]==n/3 && h[3]<=h[6]\n h[3].times{puts '1 3 6'}\n h[6]-=h[3]\n h[6].times{puts '1 2 6'}\n h[4].times{puts '1 2 4'}\nelse\n p -1\nend\n\n\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nk=b.include?(\"7\")\nl=b.include?(\"5\") \nif k || l\nputs \"-1\"\nelsif\none=b.count(\"1\")\ntwo=b.count(\"2\")\nthree=b.count(\"3\")\nfour=b.count(\"4\")\nsix=b.count(\"6\")\n\nif one!=two+three\n\nputs \"-1\"\n\nelse\n\nif two+three != four+six || three >six\nputs \"-1\"\nelse\n\nthree.times do\nputs \"1 3 6\"\nend\nfour.times do\nputs \"1 2 4\"\nend\n(two-four).times do\nputs \"1 2 6\"\nend\n\nend\nend\nend "}, {"source_code": "n=gets.to_i\nh=[0]*8\na=gets.scan(/\\d/){|x|h[x.to_i]+=1}\nif h[1]==n/3 && h[2]+h[3]==n/3 && h[4]+h[6]==n/3 && h[3]<=h[6]\n h[3].times{puts '1 3 6'}\n h[6]-=h[3]\n h[6].times{puts '1 2 6'}\n h[4].times{puts '1 2 4'}\nelse\n p -1\nend\n\n\n"}, {"source_code": "n=gets.to_i\nh=Hash.new 0\na=gets.split.each{|x|h[x]+=1}\nif h['1']==n/3 && h['2']+h['3']==n/3 && h['4']+h['6']==n/3 && h['3']<=h['6']\n h['3'].times {puts '1 3 6'}\n h['6']-=h['3']\n h['6'].times {puts '1 2 6'}\n h['4'].times {puts '1 2 4'}\nelse\n p -1\nend\n\n"}, {"source_code": "STDOUT.sync=STDIN.sync=false\nn=gets.to_i\nh=[0]*8\na=gets.scan(/\\d/){|x|h[x.to_i]+=1}\nif h[1]==n/3 && h[2]+h[3]==n/3 && h[4]+h[6]==n/3 && h[3]<=h[6]\n h[3].times{puts '1 3 6'}\n h[6]-=h[3]\n h[6].times{puts '1 2 6'}\n h[4].times{puts '1 2 4'}\nelse\n p -1\nend\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nna=a.count(1)\nnb1=a.count(2)\nnb2=a.count(3)\nnc1=a.count(4)\nnc2=a.count(6)\nif na==n/3 && nb1+nb2==n/3 && nc1+nc2==n/3 && nb2<=nc2\n nb2.times {puts '1 3 6'}\n nc2-=nb2\n nc2.times {puts '1 2 6'}\n nc1.times {puts '1 2 4'}\nelse\n p -1\nend\n\n"}, {"source_code": "n=gets.to_i\nh=[0]*8\na=gets.scan(/\\d/){|x|h[x.to_i]+=1}\nif h[1]==n/3 && h[2]+h[3]==n/3 && h[4]+h[6]==n/3 && h[3]<=h[6]\n h[3].times{puts '1 3 6'}\n h[6]-=h[3]\n h[6].times{puts '1 2 6'}\n h[4].times{puts '1 2 4'}\nelse\n p -1\nend\n\n"}, {"source_code": "n=gets.to_i\nh=Hash.new 0\na=gets.scan(/\\d/){|x|h[x]+=1}\nif h['1']==n/3 && h['2']+h['3']==n/3 && h['4']+h['6']==n/3 && h['3']<=h['6']\n h['3'].times {puts '1 3 6'}\n h['6']-=h['3']\n h['6'].times {puts '1 2 6'}\n h['4'].times {puts '1 2 4'}\nelse\n p -1\nend\n\n"}, {"source_code": "n=gets.to_i\nh=[0]*8\na=gets.scan(/\\d/){|x|h[x.to_i]+=1}\nif h[1]==n/3 && h[2]+h[3]==n/3 && h[4]+h[6]==n/3 && h[3]<=h[6]\n h[3].times{puts '1 3 6'}\n h[6]-=h[3]\n h[6].times{puts '1 2 6'}\n h[4].times{puts '1 2 4'}\nelse\n p -1\nend\n\n\n"}, {"source_code": "n = gets.to_i\nh = gets.split.map { |x| x.to_i }.inject(Hash.new(0)) { |h, e| h[e] += 1; h }\nunless h[1] == n / 3 && h[6] >= h[3] && h[2] + h[3] == h[4] + h[6] && h[2] + h[3] + h[4] + h[6] == 2 * n / 3\n puts -1\n exit\nend\nfor _ in 1..h[4]\n puts '1 2 4'\nend\nfor _ in 1..h[2] - h[4]\n puts '1 2 6'\nend\nfor _ in 1..h[3]\n puts '1 3 6'\nend"}, {"source_code": "#!/usr/bin/env ruby\n\n\ngets.chomp\narr = gets.chomp.split.map(&:to_i).sort\n\none = arr.count(1)\ntwo = arr.count(2)\nthree = arr.count(3)\nfour = arr.count(4)\nsix = arr.count(6)\n\nif one != arr.size / 3\n puts -1\n exit\nend\n\ntwo_four = [two, four].min\ntwo -= two_four\nfour -= two_four\n\nthree_six = [three, six].min\nthree -= three_six\nsix -= three_six\n\ntwo_six = [two, six].min\ntwo -= two_six\nsix -= two_six\n\nif (two_four + three_six + two_six) != (arr.size / 3)\n puts -1\n exit\nend\n\n\ntwo_four.times do\n puts [1, 2, 4].join(\" \")\nend\n\ntwo_six.times do\n puts [1, 2, 6].join(\" \")\nend\n\nthree_six.times do\n puts [1, 3, 6].join(\" \")\nend\n"}, {"source_code": "n=gets.to_i\nh=[0]*8\na=gets.scan(/\\d/){|x|h[x.to_i]+=1}\nif h[1]==n/3 && h[2]+h[3]==n/3 && h[4]+h[6]==n/3 && h[3]<=h[6]\n h[3].times{puts '1 3 6'}\n h[6]-=h[3]\n h[6].times{puts '1 2 6'}\n h[4].times{puts '1 2 4'}\nelse\n p -1\nend\n\n\n"}], "negative_code": [{"source_code": "class A\n def initialize\n n = gets.chomp.to_i\n num_list = Hash.new(0)\n\n list = gets.chomp.split(' ').map(&:to_i)\n answer = []\n\n list.each do |num|\n num_list[num] += 1\n end\n\n if num_list.has_key?(3) || num_list.has_key?(5) || num_list.has_key?(7)\n puts -1\n exit\n end\n\n while num_list[1] > 0 && num_list[2] > 0 && num_list[4] > 0\n answer << \"1 2 4\"\n num_list[1] -= 1\n num_list[2] -= 1\n num_list[4] -= 1\n end\n\n while num_list[1] > 0 && num_list[2] > 0 && num_list[6] > 0\n answer << \"1 2 6\"\n num_list[1] -= 1\n num_list[2] -= 1\n num_list[6] -= 1\n end\n\n while num_list[1] > 0 && num_list[4] > 0 && num_list[6] > 0\n answer << \"1 4 6\"\n num_list[1] -= 1\n num_list[4] -= 1\n num_list[6] -= 1\n end\n\n while num_list[2] > 0 && num_list[4] > 0 && num_list[6] > 0\n answer << \"2 4 6\"\n num_list[2] -= 1\n num_list[4] -= 1\n num_list[6] -= 1\n end\n\n if answer.size == n/3\n puts answer\n else\n puts -1\n end\n end\nend\n\na = A.new"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nk=b.include?(\"7\")\nl=b.include?(\"7\") \nif k || l\nputs \"-1\"\nelsif\none=b.count(\"1\")\ntwo=b.count(\"2\")\nthree=b.count(\"3\")\nfour=b.count(\"4\")\nsix=b.count(\"6\")\n\nif one!=two+three\n\nputs \"-1\"\n\nelse\n\nif two+three != four+six || three >six\nputs \"-1\"\nelse\n\nthree.times do\nputs \"1 3 6\"\nend\nfour.times do\nputs \"1 2 4\"\nend\n(two-four).times do\nputs \"1 2 6\"\nend\n\nend\nend\nend "}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nna=a.count(1)\nnb=a.count(2)\nnc1=a.count(4)\nnc2=a.count(6)\nif na==n/3 && nb==n/3 && nc1+nc2==n/3\n nc1.times {puts '1 2 4'}\n nc2.times {puts '1 2 6'}\nelse\n p -1\nend\n\n"}, {"source_code": "n=gets.to_i\nh=Hash.new 0\na=gets.split.each{|x|h[x]+=1}\nif h['1']==n/3 && h['2']+h['3']==n/3 && h['4']+h['6']==n/3 && h['3']<=h['6']\n h['3'].times {puts '1 3 6'}\n h['6']-=h['3']\n h['3'].times {puts '1 2 6'}\n h['4'].times {puts '1 2 4'}\nelse\n p -1\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\n\ngets.chomp\narr = gets.chomp.split.map(&:to_i).uniq.sort\n\nprinted = false\narr.permutation(3).each do |a,b,c|\n if (a % b == 0) && (b % c == 0)\n puts [c, b , a].join(' ')\n printed = true\n end\nend\n\nunless printed\n puts -1\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\n\ngets.chomp\narr = gets.chomp.split.map(&:to_i).sort\n\narr = arr.permutation(3).to_a.map do |a,b,c|\n if (a % b == 0) && (b % c == 0) && (a > b) && (b > c)\n [c, b , a].join(' ')\n end\nend\n\nputs arr.compact.sort.uniq\n"}, {"source_code": "#!/usr/bin/env ruby\n\n\ngets.chomp\narr = gets.chomp.split.map(&:to_i).sort\n\none = arr.count(1)\ntwo = arr.count(2)\nthree = arr.count(3)\nfour = arr.count(4)\nsix = arr.count(6)\n\nif one != arr.size / 3\n puts -1\n exit\nend\n\ntwo_four = [two, four].min\ntwo -= two_four\nfour -= two_four\n\nthree_six = [three, six].min\nthree -= three_six\nsix -= three_six\n\ntwo_six = [two, six].min\ntwo -= two_six\nsix -= two_six\n\nif two_four + three_six + two_six != arr.size / 3\n puts -1\n exit\nend\n\n\nif two_four.nonzero?\n puts [1, 2, 4].join(\" \")\nend\n\nif two_six.nonzero?\n puts [1, 2, 6].join(\" \")\nend\n\nif three_six.nonzero?\n puts [1, 3, 6].join(\" \")\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\n\ngets.chomp\narr = gets.chomp.split.map(&:to_i).sort\n\narr = arr.permutation(3).to_a.map do |a,b,c|\n if (a % b == 0) && (b % c == 0) && (a > b) && (b > c)\n [c, b , a].join(' ')\n end\nend\n\narr = arr.compact.sort.uniq\n\nif arr.size.zero?\n puts -1\nelse\n puts arr\nend\n"}], "src_uid": "513234db1bab98c2c2ed6c7030c1ac72"} {"source_code": "def slope(x1, y1, x2, y2)\n p = y2 - y1\n q = x2 - x1\n g = p.gcd(q)\n p /= g\n q /= g\n\n [p, q]\nend\n\nn = gets.chomp.to_i\npoints = n.times.map.with_index { |i| [gets.chomp.split.map(&:to_i), i + 1]}\n\npoints.sort! { |a, b| a[0] <=> b[0] }\n\nans = [points[0][1], points[1][1]]\nconst = slope(*points[0][0], *points[1][0])\n\n(2...n).each do |i|\n if slope(*points[0][0], *points[i][0]) != const then\n ans << points[i][1]\n break\n end\nend\n\nputs ans.join(' ')\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\nxs = []\nys = []\nhs = Hash.new()\nans = []\nfor i in 1..n\n x, y = gets.chomp.split.map(&:to_i)\n xs << x\n ys << y\n hs[i] = (x - xs[0])**2 + (y - ys[0])**2\nend\n\nhs.sort { |(_, v1), (_, v2)| v1 <=> v2 }.each do |k, _|\n ans << k if ans.size < 3\n if ans.size == 3\n x0 = xs[ans[0] - 1]\n y0 = ys[ans[0] - 1]\n x1 = xs[ans[1] - 1]\n y1 = ys[ans[1] - 1]\n x2 = xs[ans[2] - 1]\n y2 = ys[ans[2] - 1]\n if (x1 - x0) * (y2 - y0) == (x2 - x0) * (y1 - y0)\n ans.delete_at(2)\n else\n break\n end\n end\nend\n\nputs ans.*' '\n"}], "negative_code": [], "src_uid": "0d3ac2472990aba36abee156069b1088"} {"source_code": "_, sx, sy, ex, ey = gets.split.map { |x| x.to_i }\nds = {E: ex - sx, W: sx - ex, N: ey - sy, S: sy - ey}.select { |__, v| v > 0 }\ns = 0\ngets.chomp.split('').each { |sw|\n w = sw.to_sym\n ds.delete(w) if ds.has_key?(w) && (ds[w] -= 1) == 0\n s += 1\n break if ds.empty?\n}\nputs(ds.empty? ? s : -1)", "positive_code": [{"source_code": "n, sx, sy, ex, ey = gets.split(' ').map { |i| i.to_i }\nwind = gets.chomp\ntx = ex - sx\nty = ey - sy\nfor i in 0...wind.size\n tx -= 1 if tx > 0 && wind[i] == 'E'\n tx += 1 if tx < 0 && wind[i] == 'W'\n ty -= 1 if ty > 0 && wind[i] == 'N'\n ty += 1 if ty < 0 && wind[i] == 'S'\n if tx == 0 and ty == 0\n puts i + 1\n break\n end\nend\nif tx != 0 or ty != 0\n puts -1\nend"}, {"source_code": "\ndef getdist(x1,y1,x2,y2)\n\tv1=(x1-x2).abs;\n\tv2=(y1-y2).abs;\n\treturn Math.sqrt(v1**2+v2**2);\nend\n\ndef main()\n\tinp=gets.chomp.strip.to_s.split(\" \",5).map{|i| i.to_i};\n\tt=inp[0];\n\tsx=inp[1];\n\tsy=inp[2];\n\tex=inp[3];\n\tey=inp[4];\n\twind=gets.chomp.strip.to_s;\n\tix=sx;\n\tf=0;\n\tiy=sy;\n\tfor i in 0..t-1\n\t\twd=wind[i].chr;\n\t\tif wd==\"E\"\n\t\t\tif getdist(ix,iy,ex,ey)>getdist(ix+1,iy,ex,ey)\n\t\t\t\tix=ix+1;\n\t\t\t\tiy=iy;\n\t\t\tend\n\t\telsif wd==\"S\"\t\n\t\t\tif getdist(ix,iy,ex,ey)>getdist(ix,iy-1,ex,ey)\n\t\t\t\tix=ix;\n\t\t\t\tiy=iy-1;\n\t\t\tend\n\t\t\n\t\telsif wd==\"N\"\n\t\t\tif getdist(ix,iy,ex,ey)>getdist(ix,iy+1,ex,ey)\n\t\t\t\tix=ix;\n\t\t\t\tiy=iy+1;\n\t\t\tend\n\t\t\n\t\telsif wd==\"W\"\n\t\t\tif getdist(ix,iy,ex,ey)>getdist(ix-1,iy,ex,ey)\n\t\t\t\tix=ix-1;\n\t\t\t\tiy=iy;\n\t\t\tend\n\t\t\n\t\tend\n\t\tif ix==ex and iy==ey\n\t\t\tf=1;\n\t\t\tputs i+1;\n\t\t\tbreak;\n\t\tend\n\tend\n\t\n\tif f==0\n\t\tputs \"-1\";\n\tend\t\nend\n\nmain()\n\t\n"}, {"source_code": "n,x1,y1,x2,y2,=gets.split.map{|e| e.to_i}\ns=gets.split(//)\nt=0\nwhile ((x1!=x2 || y1!=y2) && t 0 and B[c] == 'N'\n\tx += 1 if x < 0 and B[c] == 'S'\n\ty -= 1 if y > 0 and B[c] == 'E'\n\ty += 1 if y < 0 and B[c] == 'W'\n\t# puts \"#{B[c]}: #{x} , #{y}\"\n\tif x == 0 and y == 0\n\t\tputs c+1\n\t\texit\n\tend\nend\nputs -1"}, {"source_code": "_, x0, y0, x, y = gets.split.map(&:to_i)\nx -= x0\ny -= y0\ngets.chomp.chars.each_with_index do |e, i|\n case e\n when 'E'\n x -= 1 if x > 0\n when 'S'\n y += 1 if y < 0\n when 'W'\n x += 1 if x < 0\n when 'N'\n y -= 1 if y > 0\n end\n if x == 0 && y == 0\n p i + 1\n exit\n end\nend\np -1\n"}], "negative_code": [{"source_code": "n, sx, sy, ex, ey = gets.split(' ').map { |i| i.to_i }\nwind = gets.chomp\ntx = ex - sx\nty = ey - sy\nfor i in 0...wind.size\n tx -= 1 if tx > 0 && wind[i] == 'E'\n tx += 1 if tx < 0 && wind[i] == 'W'\n ty -= 1 if ty > 0 && wind[i] == 'N'\n tx += 1 if ty < 0 && wind[i] == 'S'\n if tx == 0 and ty == 0\n puts i + 1\n break\n end\nend\nif tx != 0 or ty != 0\n puts -1\nend"}, {"source_code": "n,x1,y1,x2,y2,=gets.split.map{|e| e.to_i}\ns=gets.split(//)\nt=0\nwhile ((x1!=x2 || y1!=y2) && tf\n q<<'R'*u\n s+=u\n break if s==f\n q<<'X'*(t+1-p-u)\n p=t+1\n end\n q<<'R'*(f-s) if sf\nm.times do\n t,l,r=gets.split.map(&:to_i)\n u=t-p\n if s < f\n u+=1 if !((l-1..r)===s+u)\n u=f-s if s+u>f\n else\n u+=1 if !((l..r+1)===s-u)\n u=s-f if s-uf\nm.times do\n t,l,r=gets.split.map(&:to_i)\n u=t-p\n if s < f\n u+=1 if !((l-1..r)===s+u)\n u=f-s if s+u>f\n else\n u+=1 if !((l..r+1)===s-u)\n u=s-f if s-uf\nm.times do\n t,l,r=gets.split.map(&:to_i)\n u=t-p\n if s < f\n u+=1 if !((l-1..r)===s+u)\n u=f-s if s+u>f\n else\n u+=1 if !((l..r+1)===s-u)\n u=s-f if s-uf\nm.times do\n t,l,r=gets.split.map(&:to_i)\n u=t-p\n if s < f\n u+=1 if !((l-1..r)===s+u)\n u=f-s if s+u>f\n else\n u+=1 if !((l..r+1)===s-u)\n u=s-f if s-uf\nm.times do\n t,l,r=gets.split.map(&:to_i)\n u=t-p\n if s < f\n u+=1 if !((l-1..r)===s+u)\n u=f-s if s+u>f\n else\n u+=1 if !((l..r+1)===s-u)\n u=s-f if s-uf\nm.times do\n t,l,r=gets.split.map(&:to_i)\n u=t-p\n if s < f\n u+=1 if !((l-1..r)===s+u)\n u=f-s if s+u>f\n else\n u+=1 if !((l..r+1)===s-u)\n u=s-f if s-uf\nm.times do\n t,l,r=gets.split.map(&:to_i)\n u=t-p\n if s < f\n u+=1 if !((l-1..r)===s+u)\n u=f-s if s+u>f\n else\n u+=1 if !((l..r+1)===s-u)\n u=s-f if s-uf\nm.times do\n t,l,r=gets.split.map(&:to_i)\n u=t-p\n if s < f\n u+=1 if !((l-1..r)===s+u)\n u=f-s if s+u>f\n else\n u+=1 if !((l..r+1)===s-u)\n u=s-f if s-uf\nm.times do\n t,l,r=gets.split.map(&:to_i)\n u=t-p\n if s < f\n u+=1 if !((l-1..r)===s+u)\n u=f-s if s+u>f\n else\n u+=1 if !((l..r+1)===s-u)\n u=s-f if s-uf\nm.times do\n t,l,r=gets.split.map(&:to_i)\n u=t-p\n if s < f\n u+=1 if !((l-1..r)===s+u)\n u=f-s if s+u>f\n else\n u+=1 if !((l..r+1)===s-u)\n u=s-f if s-uf\nm.times do\n t,l,r=gets.split.map(&:to_i)\n u=t-p\n if s < f\n u+=1 if !((l-1..r)===s+u)\n u=f-s if s+u>f\n else\n u+=1 if !((l..r+1)===s-u)\n u=s-f if s-uf\n u=0 if u < 0\n q<<'R'*u\n s+=u\n break if s==f\n q<<'X'*(t+1-p-u)\n p=t+1\nend\nq<<'R'*(f-s) if s 0\n elsif i < j\n array[i][j] = array[i][j - 1] + 1\n else\n array[i][j] = array[j][i - 1]\n end\n end\nend\n\nputs num_of_days\narray.each do |e|\n e.each do |element|\n printf(\"%d \", element)\n end\n printf(\"\\n\");\nend", "positive_code": [{"source_code": "n = gets.to_i\nk = ((1 + Math.sqrt(1 + 8 * n)) / 2).to_i\nn_ = k * (k - 1) / 2\n\nd1 = 1\nd2 = 2\n\na = Array.new(k + 1, \"\")\n\nfor i in 1 .. n_\n\ta[d1] += i.to_s + \" \"\n\ta[d2] += i.to_s + \" \"\n\td2 += 1\n\tif d2 > k then\n\t\td1 += 1\n\t\td2 = d1 + 1\n\tend\nend\n\nputs k\nfor i in 1 .. k\n\tputs a[i]\nend"}, {"source_code": "n = gets.to_i\n\nprev = [[1, 2], [1, 3], [2, 3]]\nb = 3\nwhile true\n cur = []\n tail = []\n prev.each do |a|\n b += 1\n tail << b\n cur << (a + [b])\n end\n cur << tail\n if b > n\n break\n end\n prev = cur\nend\n\np prev.size\nprev.each{|x| puts x*\" \"}\n"}, {"source_code": "n = gets.to_i\na = []\ni, j = 1, 1\nwhile n >= i\n i.times{ |k|\n a[i] ||= []\n a[k] ||= []\n a[i] << j\n a[k] << j\n j += 1\n }\n n -= i\n i += 1\nend\np a.length\na.each{ |x| puts x*\" \" }"}], "negative_code": [{"source_code": "hobbits_num = gets.to_i\nnum_of_days = ((-1 + Math.sqrt(1 + 8 * hobbits_num)) / 2).floor + 1\ninvited_hobbits = (num_of_days * (num_of_days - 1)) / 2\nlist_length = num_of_days - 1\narray = Array.new(num_of_days) {Array.new(list_length, 0)}\nvisit = Array.new(invited_hobbits, 0)\ndef next_visit(start, last, visit)\n for i in start...last\n if visit[i] == 0\n visit[i] = 1\n return i\n end\n end\nend\n\nnum_of_days.times do |n|\n for i in 0...n\n array[n][i] = array[i][n - 1]\n end\n for i in n...list_length\n array[n][i] = next_visit i, invited_hobbits, visit\n end\nend\narray.each do |e|\n e.each do |element|\n printf(\"%d \", element + 1)\n end\n printf(\"\\n\");\nend"}, {"source_code": "n = gets.to_i\na = []\ni, j = 1, 1\nwhile n >= 2*i\n i.times{ |k|\n a[i] ||= []\n a[k] ||= []\n a[i] << j\n a[k] << j\n j += 1\n }\n n -= 2*i\n i += 1\nend\na.each{ |x| puts x*\" \" }"}, {"source_code": "n = gets.to_i\na = []\ni, j = 1, 1\nwhile n >= i\n i.times{ |k|\n a[i] ||= []\n a[k] ||= []\n a[i] << j\n a[k] << j\n j += 1\n }\n n -= i\n i += 1\nend\na.each{ |x| puts x*\" \" }"}, {"source_code": "n = gets.to_i\nk = ((1 + Math.sqrt(1 + 8 * n)) / 2).to_i\nn_ = k * (k - 1) / 2\n\nd1 = 1\nd2 = 2\n\na = Array.new(k + 1, \"\")\n\nfor i in 1 .. n_\n\ta[d1] += i.to_s + \" \"\n\ta[d2] += i.to_s + \" \"\n\td2 += 1\n\tif d2 > k then\n\t\td1 += 1\n\t\td2 = d1 + 1\n\tend\nend\n\nfor i in 1 .. k\n\tputs a[i]\nend"}], "src_uid": "e435a009962a7056d0fa00edb13ad01d"} {"source_code": "h = Hash.new{[]}\nn = gets.to_i\ngets.split.map(&:to_i).each_with_index do |i, k|\n h[i] <<= k\nend\n\na, b = 0, 0\ngets\ngets.split.map(&:to_i).each do |i|\n k = h[i]\n a += k[0] + 1\n b += n - k[-1]\nend\n\nputs \"#{a} #{b}\"\n", "positive_code": [{"source_code": "def compare_solutions(n,a,q,s)\n v_count = 0\n p_count = 0\n\n h_elements = Hash.new(0)\n # Creating a hash with element as symbol and value as index (as they can't be repeated cause\n # it could change the final couting for both team members)\n (1..n).each do |i|\n h_elements[a[i-1]] = i-1\n end\n\n queries = Hash.new(0)\n # Simplifying the amount of queries grouping them because the can be repeated\n s.each do |e|\n queries[e] +=1\n end\n\n queries.each do |k,v|\n e_index = h_elements[k]\n # vasya's count starting from the begining of the array and multiplied by v times the query is repeated\n v_count += (e_index + 1) * v\n # petya's count from the end of the array and multiplied by v times the query is repeated\n p_count += (n - e_index) * v\n end\n\n puts \"#{v_count} #{p_count}\"\nend\n\nn = gets.to_i\na_elements = gets.split(/\\s/)\nq_queries = gets.to_i\nqueries = gets.split(/\\s/)\ncompare_solutions(n,a_elements,q_queries,queries)"}, {"source_code": "h = Hash.new{[]}\nn = gets.to_i\ngets.split.map(&:to_i).each_with_index { |el, i| h[el] <<= i }\nl,r = 0,0\ngets\ngets.split.map(&:to_i).each { |x|\n k = h[x]\n l += k[0]+1\n r += n-k[-1]\n}\nputs \"#{l} #{r}\""}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\np=[0]*(n+1)\nn.times{|i|p[a[i]]=i}\nz=0\nm=gets.to_i\ngets.split.map(&:to_i).each{|i|z+=p[i]}\nputs [z+m,m*n-z]*' '"}, {"source_code": "n = gets.to_i\npos = Hash.new\ntmp = 1\ngets.split.each do |a|\n pos[a.to_i]=tmp\n tmp += 1\nend\ntmp = 0\nm = gets.to_i\ngets.split.each do |b|\n tmp+=pos[b.to_i]\nend\nprint tmp, \" \", (n+1)*m-tmp, \"\\n\"\n"}, {"source_code": "n = gets.to_i\ni = -1\nar = Array.new(n){0}\ngets.split.map(&:to_i).each_with_index do |el, index|\n ar[el] = index+1\nend\nm = gets.to_i\nb = gets.split.map &:to_i\n\nsum1,sum2 = 0, 0\nb.each do |b|\n sum1 += ar[b]\n sum2 += n - ar[b] + 1\nend\n\nputs \"#{sum1} #{sum2}\""}, {"source_code": "n = gets.to_i\ni = -1\nar = Array.new(n){0}\ngets.split.map(&:to_i).each_with_index do |el, index|\n ar[el] = index+1\nend\nm = gets.to_i\nb = gets.split.map &:to_i\n\nsum1,sum2 = 0, 0\nb.each do |b|\n sum1 += ar[b]\n sum2 += n - ar[b] + 1\nend\n\nputs \"#{sum1} #{sum2}\""}], "negative_code": [], "src_uid": "b7aef95015e326307521fd59d4fccb64"} {"source_code": "n = gets.strip.to_i\nranks = {}\nn.times do |i|\n scores = gets.strip.split.map(&:to_i).inject(:+)\n ranks[i + 1] = scores\nend\nranks = ranks.sort_by { |k, v| [-v, k] }\nans = 0\nranks.each do |rank|\n ans += 1\n break if rank[0] == 1\nend\nputs ans", "positive_code": [{"source_code": "gets;a=$<.map{|e|e.split.map(&:to_i).reduce :+};p a[1..-1].count{|e|e>a[0]}+1"}, {"source_code": "N = gets.to_i\narr = []\n(1..N).each do |i|\n sum = gets.split.map(&:to_i).inject(:+)\n arr.push([-sum, i])\nend\n\narr.sort!\nN.times do |i|\n if arr[i][1] == 1\n puts i+1\n exit\n end\nend"}, {"source_code": "n = gets.to_i\ntom = gets.split.map(&:to_i).inject(:+)\nans = 1\n(n-1).times do\n sc = gets.split.map(&:to_i).inject(:+)\n ans += 1 if sc > tom\nend\nputs ans"}, {"source_code": "n=gets.to_i\nputs (1..n).map{|i| [-gets.split.map(&:to_i).inject(:+), i]}.sort.index{|_,i|i==1}+1\n"}, {"source_code": "n = gets.to_i\na = []\nn.times{a << gets.split.map{|x| x.to_i}.inject(0){|s, x| s + x}}\ns = a[0]\nputs(a.sort.reverse.index(s) + 1)\n\n"}, {"source_code": "n = gets.to_i\narr = []\nn.times do |i|\n arr.push [i+1]+gets.chomp.split(\" \").map(&:to_i)\nend\n\narr.sort_by!{|x| [-x[1..-1].inject(:+),x[0]]}\n\n\narr.each_with_index do |x,i|\n if x[0]==1\n puts i+1\n exit\n end\nend\n"}], "negative_code": [], "src_uid": "3c984366bba580993d1694d27982a773"} {"source_code": "n, x = gets.split.map(&:to_i)\na = n.times.map{gets.split.map(&:to_i)}\nans = 0\na.each{|x, y| ans += y + 1 - x}\nj = 1\nn.times do |i|\n ans += (a[i][0] - j) % x\n j = a[i][1] + 1\nend\nputs ans\n", "positive_code": [{"source_code": "n, x = gets.split.map(&:to_i)\nt = 1\nq = 0\nn.times do\n l, r = gets.split.map(&:to_i)\n t += x while t + x <= l\n q += r - t + 1\n t = r + 1\nend\nputs q\n"}, {"source_code": "#!/usr/bin/env ruby\nn,x=gets.split.map(&:to_i)\ncur=1\nret=0\nn.times{\n\tl,r=gets.split.map(&:to_i)\n\tret+=r+1-l+(l-cur)%x\n\tcur=r+1\n}\np ret"}, {"source_code": "class A\n def initialize(n, x)\n @n = n\n @x = x\n @fields = Array.new(10**5) { 0 }\n end\n\n def setup(movements)\n movements.each do |l, r|\n (l..r).each { |idx| @fields[idx - 1] = 1 }\n end\n end\n\n def minimum_number_of_minutes\n idx = 0\n minutes = []\n\n while (idx <= @fields.length)\n @fields[idx..(idx + @x - 1)].tap do |arr|\n if arr.any? { |a| a == 1 }\n minutes << arr.rindex(1) + 1\n idx += minutes.last\n else\n minutes << 0\n idx += @x\n end\n end\n end\n\n minutes.inject(0, :+)\n end\nend\n\nn, x = gets.chomp.split().map(&:to_i)\nmovements = [].tap do |arr|\n n.times { arr << gets.chomp.split().map(&:to_i) }\nend\n\na = A.new(n, x)\na.setup(movements)\nputs a.minimum_number_of_minutes\n"}, {"source_code": "n,x=gets.chomp.split.map(&:to_i)\nlol,i=0,1\nn.times do\n\tl,r=gets.chomp.split.map(&:to_i)\n\tlol+= r-l + (l-i)%x + 1\n\ti=r+1\nend\nputs lol"}, {"source_code": "n, x = gets.chomp.split(/ /).map(&:to_i)\nwatch = 0\nskip = 1\nn.times do\n l, r = gets.chomp.split(/ /).map(&:to_i)\n skip += x while skip + x <= l\n if skip <= l\n while skip <= r\n watch += 1\n skip += 1\n end\n end\nend\nputs watch\n"}, {"source_code": "n,x=gets.split.map{|e| e.to_i}\nt=1\nans=0\nn.times{\n\tl,r=gets.split.map{|e| e.to_i}\n\twhile t+x<=l\n\t\tt+=x\n\tend\n\tans+=r-t+1\n\tt=r+1\n}\nputs ans\n\n"}, {"source_code": "#!/usr/bin/ruby\ntokens = STDIN.gets.chomp.split(\" \").map(&:to_i)\nn = tokens[0]\nx = tokens[1]\nminute = 1\nans = 0\nn.times do\n l, r = STDIN.gets.chomp.split(\" \").map(&:to_i)\n while minute + x <= l do\n minute += x\n end\n ans += r - minute + 1\n minute = r + 1\nend\n\nputs ans\n"}, {"source_code": "n,x = gets.split(\" \").map(&:to_i)\nminutes_watched = 0\ncurrent = 1\nn.times do\n\tl,r = gets.split(\" \").map(&:to_i)\n\twhile current + x <= l\n\t\tcurrent += x\n\tend\n\tminutes_watched += l - current\n\tcurrent = r + 1\n\tminutes_watched += r + 1 - l\n\t# puts \"current #{current} minutes_watched #{minutes_watched}\"\nend\n\nputs minutes_watched"}, {"source_code": "n, x = gets.chomp.split(' ').map(&:to_i)\nc = 1\ntotal = 0\nn.times do |i|\n l, r = gets.chomp.split(' ').map(&:to_i)\n while c + x <= l do c += x end\n total += r-l + 1\n total += l - c\n c = r + 1\nend\nputs total"}, {"source_code": "n,x = gets.split.map &:to_i\nputs n.times.map{gets.split.map &:to_i}.unshift([0,0]).each_cons(2).map{|p,n| (n[0]-p[1]-1)%x+n[1]-n[0]+1}.inject(:+)"}, {"source_code": "n, x = gets.split.map(&:to_i)\na = n.times.map{gets.split.map(&:to_i)}\nans = 0\nj = 1\na.each do |s, e|\n ans += (s - j) % x\n ans += e - s + 1\n j = e + 1\nend\nputs ans\n"}, {"source_code": "read=lambda{ gets.split(\" \").map{|x| x.to_i} }\nn,x=read.call\n#puts \"#{n} #{x}\"\nans=0\nnow=1\nfor _ in 0...n\n l,r=read.call\n ans+=(l-now)%x+r-l+1\n now=r+1\nend\nputs ans"}, {"source_code": "n, x = gets.split(' ').map(&:to_i)\npre = 0\nans = 0\nn.times do\n l, r = gets.split(' ').map(&:to_i)\n ans += (l - pre - 1) % x + r - l + 1\n pre = r\nend\nprint ans, \"\\n\";\n"}, {"source_code": "class Stu\n\tattr_accessor:a \n\tattr_accessor:b \nend\n\n#File.open(\"2.txt\",\"r\") do|file|\ndata=Array.new\nh=Array.new\n#str=file.gets.to_s\nstr=gets.to_s\nh=str.split\nn=h[0].to_i\nx=h[1].to_i\ni=0\nwhile ia*x\n ans+=finish-a*x\n else\n ans+=(b-a)*x\n end\n finish=b*x\nend\nputs ans"}, {"source_code": "read=lambda{ gets.split(\" \").map{|x| x.to_i} }\nn,x=read.call\n#puts \"#{n} #{x}\"\nans=0\nnow=1\nfor _ in 0...n\n l,r=read.call\n ans+=(l-now)%x+(r-l)+1\nend\nputs ans"}, {"source_code": "n, x = gets.split(' ').map(&:to_i)\npre = 1\nans = 0\nn.times do\n l, r = gets.split(' ').map(&:to_i)\n ans += (l - pre) % x + r - l\n pre = r\nend\nprint ans + 1, \"\\n\";\n"}], "src_uid": "ac33b73da5aaf2139b348a9c237f93a4"} {"source_code": "\nt = 0\nt = gets.chomp.to_i\n#puts \"Value of t is \",t\nwhile t > 0\n i = 0\n num = 0\n n = 0 \n x = 0\n odd = 0\n n, x = gets.chomp.split(' ').map{|a| a.to_i}\n ar = gets.chomp.split(' ').map{|a| a.to_i}\n for i in 0..n-1\n #puts ar[i]\n if ar[i]%2 != 0\n odd = odd + 1\n end\n end\n #puts \"The value of odd is\", odd\n if odd >= 1 && !(x==n && odd%2 ==0) && !(n==odd && x%2==0 )\n puts \"YES\"\n else\n puts \"NO\"\n end\nt = t-1\nend\n\n\n\n\n", "positive_code": [{"source_code": "# cook your code here\nt = gets.to_i\nuntil t == 0\n x,y = gets.chomp.split().map { |e| e.to_i }\n arr = gets.chomp.split().map { |e| e.to_i }\n odd = 0;even = 0;\n for i in 0...arr.length()\n if(arr[i]%2 == 1)\n odd+=1;\n else\n even+=1;\n end\n end\n #print \"%d %d\" % [odd,even]\n #puts\n if(odd == 0)\n puts \"No\"\n else\n y-=1;\n odd-=1;\n if(y%2 == 0)\n if(odd%2 == 0)\n odd = odd\n else\n odd-=1\n end\n if(odd >= y or even >= (y-odd))\n puts \"Yes\"\n else\n puts \"No\"\n end\n else\n if(even == 0)\n puts \"No\"\n else\n y-=1\n even-=1\n if(odd%2 == 0)\n odd = odd\n else\n odd-=1\n end\n if(odd >= y or even >= (y-odd))\n puts \"Yes\"\n else\n puts \"No\"\n end\n end\n end\n end\n t-=1\nend"}, {"source_code": "num_tests = gets.chomp.to_i\n\ndef odd_selection(n,arr)\n odds = evens = 0\n arr.each { |el| el.odd? ? odds += 1 : evens += 1 }\n return \"No\" if evens == 0 && n.even?\n (n - max_odd_num(odds) <= evens && odds > 0) ? \"Yes\" : \"No\"\nend\n\ndef max_odd_num(num)\n return num.odd? ? num : num - 1\nend\n\ni = 0\nwhile i < num_tests\n a,b = gets.chomp.split(\" \").map(&:to_i)\n arr = gets.chomp.split(\" \").map(&:to_i)\n puts odd_selection(b,arr)\n i += 1\nend\n"}, {"source_code": "gets.to_i.times{\n n,x=gets.split.map(&:to_i)\n a=b=0\n gets.split.map{|x|x.to_i%2==0 ? b+=1:a+=1}\n puts 1.step(a, 2).any?{|i| x-i>=0 and x-i<=b} ? \"Yes\" : \"No\"\n}\n"}, {"source_code": "def analyze(a, x)\n even_count = 0\n odd_count = 0\n a.each do |item|\n if item % 2 == 0\n even_count +=1\n else\n odd_count +=1\n end \n end\n \n return odd_count > 0 if x <= 1\n \n \n return false if odd_count < 1\n\n \n\n if x % 2 == 0\n return false if even_count < 1\n\n odd_count -= 1\n even_count -= 1\n\n odd_count / 2 + even_count / 2 >= (x -2) / 2\n else\n odd_count -= 1\n\n odd_count / 2 + even_count / 2 >= (x -1) / 2\n end \nend\n\nt = gets.chomp.to_i\nres = []\n(1..t).each do |_t|\n n, x = gets.chomp.split(' ').map{|a| a.to_i}\n ar = gets.chomp.split(' ').map{|a| a.to_i}\n res << analyze(ar, x)\nend\n \nres.each do |r|\n puts (r ? 'YES' : 'NO')\nend"}, {"source_code": "def solve\n _, k = gets.strip.split(' ').map(&:to_i)\n arr = gets.strip.split(' ').map(&:to_i)\n ev = arr.select { |e| e.even? }\n od = arr.select { |e| e.odd? }\n while !od.empty?\n if od.size.odd? && od.size <= k\n break\n end\n od.pop\n end\n if od.size + ev.size >= k && !od.size.zero?\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\ngets.strip.to_i.times { solve }\n"}, {"source_code": "def solve\n _, k = gets.strip.split(' ').map(&:to_i)\n arr = gets.strip.split(' ').map(&:to_i)\n ev = arr.select { |e| e.even? }\n od = arr.select { |e| e.odd? }\n while !od.empty?\n if od.size.odd? && od.size <= k\n break\n end\n od.pop\n end\n if od.size + ev.size >= k && !od.size.zero?\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\ngets.strip.to_i.times { solve }\n"}], "negative_code": [{"source_code": "# cook your code here\nt = gets.to_i\nuntil t == 0\n x,y = gets.chomp.split().map { |e| e.to_i }\n arr = gets.chomp.split().map { |e| e.to_i }\n odd = 0;even = 0;\n for i in 0...arr.length()\n if(arr[i]%2 == 1)\n odd+=1;\n else\n even+=1;\n end\n end\n #print \"%d %d\" % [odd,even]\n #puts\n if(odd == 0)\n puts \"No\"\n else\n y-=1;\n odd-=1;\n if(even >= y)\n puts \"Yes\"\n else\n if((y-even)%2)\n y = y - even + 1;\n else\n y = y - even;\n end\n if(odd >= y and y%2 == 0)\n puts \"Yes\"\n else\n puts \"No\"\n end\n end\n end\n t-=1\nend"}, {"source_code": "# cook your code here\nt = gets.to_i\nuntil t == 0\n x,y = gets.chomp.split().map { |e| e.to_i }\n arr = gets.chomp.split().map { |e| e.to_i }\n odd = 0;even = 0;\n for i in 0...arr.length()\n if(arr[i]%2 == 1)\n odd+=1;\n else\n even+=1;\n end\n end\n #print \"%d %d\" % [odd,even]\n #puts\n if(odd == 0)\n puts \"No\"\n else\n y-=1;\n odd-=1;\n if(even >= y)\n puts \"Yes\"\n else\n if((y-even)%2 == 0)\n y = y - even + 1;\n else\n y = y - even;\n end\n if(odd >= y and y%2 == 0)\n puts \"Yes\"\n else\n puts \"No\"\n end\n end\n end\n t-=1\nend"}, {"source_code": "# cook your code here\nt = gets.to_i\nuntil t == 0\n x,y = gets.chomp.split().map { |e| e.to_i }\n arr = gets.chomp.split().map { |e| e.to_i }\n odd = 0;even = 0;\n for i in 0...arr.length()\n if(arr[i]%2 == 1)\n odd+=1;\n else\n even+=1;\n end\n end\n #print \"%d %d\" % [odd,even]\n #puts\n if(odd == 0)\n puts \"No\"\n else\n y-=1;\n odd-=1;\n if(even >= y)\n puts \"Yes\"\n else\n if((y-even)%2 == 1)\n y = y - even + 1;\n else\n y = y - even;\n end\n # puts y\n if(odd >= y and y%2 == 0)\n puts \"Yes\"\n else\n puts \"No\"\n end\n end\n end\n t-=1\nend"}, {"source_code": "# cook your code here\nt = gets.to_i\nuntil t == 0\n x,y = gets.chomp.split().map { |e| e.to_i }\n arr = gets.chomp.split().map { |e| e.to_i }\n odd = 0;even = 0;\n for i in 0...arr.length()\n if(arr[i]%2 == 1)\n odd+=1;\n else\n even+=1;\n end\n end\n #print \"%d %d\" % [odd,even]\n #puts\n if(odd == 0)\n puts \"No\"\n else\n y-=1;\n odd-=1;\n if(even >= y)\n puts \"Yes\"\n else\n if((y-even)%2)\n y = y - even + 1;\n else\n y = y - even;\n end\n if(odd >= y)\n puts \"Yes\"\n else\n puts \"No\"\n end\n end\n end\n t-=1\nend"}, {"source_code": "num_tests = gets.chomp.to_i\n\ndef odd_selection(n,arr)\n odds = evens = 0\n arr.each { |el| el.odd? ? odds += 1 : evens += 1 }\n (n - max_odd_num(odds) <= evens && odds > 0) ? \"Yes\" : \"No\"\nend\n\ndef max_odd_num(num)\n return num.odd? ? num : num - 1\nend\n\ni = 0\nwhile i < num_tests\n a,b = gets.chomp.split(\" \").map(&:to_i)\n arr = gets.chomp.split(\" \").map(&:to_i)\n puts odd_selection(b,arr)\n i += 1\nend\n"}, {"source_code": "num_tests = gets.chomp.to_i\n\ndef odd_selection(n,arr)\n odds = evens = 0\n arr.each { |el| el.odd? ? odds += 1 : evens += 1 }\n (n - max_odd_num(odds) <= evens && odds > 0) ? \"Yes\" : \"No\"\nend\n\ndef max_odd_num(num)\n return num.odd? ? num : num - 1\nend\n\ni = 0\nwhile i < num_tests\n a,b = gets.chomp.split(\" \").map(&:to_i)\n arr = gets.chomp.split(\" \").map(&:to_i)\n p odd_selection(b,arr)\n i += 1\nend\n"}, {"source_code": "\nt = 0\nt = gets.to_i\n\nwhile t > 0\n odd = 0\n n = 0 \n x = 0\n n = gets.to_i\n x = gets.to_i\n for i in 1..n\n a = gets.to_i\n if a%2 != 0\n odd = odd + 1\n end\n end\n if odd >= 1 && !(x==n && odd%2 ==0) && !(n==odd && x%2==0 )\n puts \"YES\"\n else\n puts \"NO\"\n end\nt = t-1\nend\n\n\n\n\n"}, {"source_code": "gets.to_i.times{\n n,x=gets.split.map(&:to_i)\n a=b=0\n gets.split.map{|x|x.to_i%2==0 ? b+=1:a+=1}\n puts 1.step(a, 2).any?{|i| x-i<=b} ? \"Yes\" : \"No\"\n}\n"}, {"source_code": "def analyze(a, x)\n even_count = 0\n odd_count = 0\n a.each do |item|\n if item % 2 == 0\n even_count +=1\n else\n odd_count +=1\n end \n end\n\n return odd_count > 0 if x <= 1\n\n if x % 2 == 1\n # x is odd\n even_count -= 1 if even_count % 2 == 1\n\n even_count + odd_count >= x\n else\n\n # x is even\n \n return false if odd_count < 1 || even_count < 1\n\n # one pair\n odd_count -= 1\n even_count -= 1\n\n # rest pairs\n\n\n even_count -= 1 if even_count % 2 == 1\n odd_count -= 1 if odd_count % 2 == 1\n\n even_count + odd_count >= x - 2\n end \nend\n\n\n\nt = gets.chomp.to_i\nres = []\n(1..t).each do |_t|\n n, x = gets.chomp.split(' ').map{|a| a.to_i}\n ar = gets.chomp.split(' ').map{|a| a.to_i}\n res << analyze(ar, x)\nend\n\nres.each do |r|\n puts (r ? 'YES' : 'NO')\nend"}, {"source_code": "def analyze(a, x)\n even_count = 0\n odd_count = 0\n a.each do |item|\n if item % 2 == 0\n even_count +=1\n else\n odd_count +=1\n end \n end\n \n return odd_count > 0 if x <= 1\n \n \n return false if odd_count < 1\n\n \n\n if x % 2 == 0\n odd_count -= 1\n even_count -= 1\n\n odd_count / 2 + even_count / 2 >= (x -2) / 2\n else\n odd_count -= 1\n\n odd_count / 2 + even_count / 2 >= (x -1) / 2\n end \nend\n\nt = gets.chomp.to_i\nres = []\n(1..t).each do |_t|\n n, x = gets.chomp.split(' ').map{|a| a.to_i}\n ar = gets.chomp.split(' ').map{|a| a.to_i}\n res << analyze(ar, x)\nend\n \nres.each do |r|\n puts (r ? 'YES' : 'NO')\nend"}, {"source_code": "def analyze(a, x)\n even_count = 0\n odd_count = 0\n a.each do |item|\n if item % 2 == 0\n even_count +=1\n else\n odd_count +=1\n end \n end\n \n return odd_count > 0 if x <= 1\n \n \n return false if odd_count < 1\n\n odd_count -= 1;\n\n odd_count / 2 + even_count / 2 + even_count % 2 >= x -1\nend\n\nt = gets.chomp.to_i\nres = []\n(1..t).each do |_t|\n n, x = gets.chomp.split(' ').map{|a| a.to_i}\n ar = gets.chomp.split(' ').map{|a| a.to_i}\n res << analyze(ar, x)\nend\n \nres.each do |r|\n puts (r ? 'YES' : 'NO')\nend"}, {"source_code": "def solve\n _, k = gets.strip.split(' ').map(&:to_i)\n arr = gets.strip.split(' ').map(&:to_i)\n ev = arr.select { |e| e.even? }\n od = arr.select { |e| e.odd? }\n od.pop if od.size.even? && !od.size.zero?\n if od.size + ev.size >= k && !od.size.zero?\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\n\ngets.strip.to_i.times { solve }\n"}], "src_uid": "afce38aa7065da88d824d1d981b5b338"} {"source_code": "N, X, Y = gets.split.map(&:to_i)\nnum = gets.chomp.split('1').count{|s| s.length>0}\nif num == 0\n puts 0\nelse\n puts Y + (num-1) * [X, Y].min\nend", "positive_code": [{"source_code": "n, x, y = gets.strip.split.map(&:to_i)\nstr = gets.strip\ncstr = str[0]\nstr.each_char do |c|\n cstr << c if c != cstr[-1]\nend\n\nzc = [y]\noc = [0]\nn = cstr.size\n1.upto(n).each do |i|\n oc << zc[i-1]\n if i%2==1\n zc << zc[i-1]\n else\n zc << [(y+zc[i-2]), (x+zc[i-2])].min\n end\nend\n\nputs (str[0]=='0' ? zc[n-1] : oc[n-1])"}], "negative_code": [{"source_code": "n, x, y = gets.strip.split.map(&:to_i)\nstr = gets.strip\n\nnzb = 0\n0.upto(n-2).each do |i|\n nzb += 1 if str[i] == '0' && str[i+1]=='1'\nend\nnzb += 1 if n>1 && str[-1] =='0'\n\nans = nzb * y\n1.upto(nzb-1).each do |nx|\n ans = [ans, (x*nx) + ((nzb-nx)*y)].min\nend\nputs ans"}], "src_uid": "b267f69cc4af3e319fc59e3ccd8b1c9d"} {"source_code": "a, b = 2.times.map{gets.chars.to_a}\nc = 0\na.zip(b){|i, j| c += 1 if i != j}\np c + (a.count('4') - b.count('4')).abs >> 1\n", "positive_code": [{"source_code": "a = gets\nb = gets\nea = a.each_char\n\nh = {:aa => 0, :bb => 0}\nb.each_char do |bb|\n aa = ea.next\n next if aa == bb\n aa == \"4\" ? h[:aa] += 1 : h[:bb] += 1\nend\n\nputs [h[:aa], h[:bb]].max\n"}, {"source_code": "input = STDIN.read.split(\"\\n\")\nstr1, str2 = input[0].split(//).map(&:to_i), input[1].split(//).map(&:to_i)\n\nstr1.length.times {|x|\n\tif str1[x] == str2[x]\n\t\tstr1[x] = nil\n\t\tstr2[x] = nil\n\tend\n}\n\nn4 = str1.count(4)\nn7 = str1.count(7)\n\nmoves = n4 <= n7 ? n4 : n7\nSTDOUT.puts moves += (n4 - n7).abs"}, {"source_code": "a=gets.bytes.to_a\nb=gets.bytes.to_a\ncnt=[0,0]\na.length.times{|i| cnt[a[i]==52?1:0]+=1 if a[i]!=b[i]}\np cnt[0]+cnt[1]-cnt.min\n"}, {"source_code": "a=gets.split[0].bytes.to_a\nb=gets.split[0].bytes.to_a\nn=a.length\ninput=Array.new\nn.times{|i|\n input.push([a[i]==52?1:0,b[i]==52?1:0])\n}\ncnt1=0\ncnt2=0\ninput.each{|t|\n cnt1+=1 if t[0]!=t[1] && t[0]==1\n cnt2+=1 if t[0]!=t[1] && t[0]==0\n}\np [cnt1,cnt2].min+(cnt1+cnt2)-[cnt1,cnt2].min*2\n"}, {"source_code": "a=gets\nb=gets\nx = a.split('').zip(b.split('')).inject([]) { |m, (x, y)| x != y ? m << x : m }\np x.length - %w[4 7].map { |d| x.count(d) }.min"}, {"source_code": "a=gets.chomp.split(\"\").map{|i|i.to_i}\nb=gets.chomp.split(\"\").map{|i|i.to_i}\nc=(a.count(4)-b.count(4)).abs\ni=0\nl=0\n\nif c>0\nloop do\nif a[i]!=b[i]\na[i]=b[i]\nl+=1\nend\ni+=1\nbreak if l>=c\nend\nend\nlength=a.length\nswap=0\nloop do\nif a[i]!=b[i]\na[i]=b[i]\nswap+=1\nend\ni+=1\nbreak if i>=length\nend\n\nputs\"#{c+swap/2}\""}, {"source_code": "a, b = 2.times.map{gets.chars.to_a}\nc = 0\na.zip(b){|i, j| c += 1 if i != j}\np c + (a.count('4') - b.count('4')).abs >> 1\n__END__"}, {"source_code": "a=gets.chomp.split(\"\").map{|i|i.to_i}\nb=gets.chomp.split(\"\").map{|i|i.to_i}\nc=(a.count(4)-b.count(4)).abs\ni=0\nl=0\n\nif c>0\nloop do\nif a[i]!=b[i]\na[i]=b[i]\nl+=1\nend\ni+=1\nbreak if l>=c\nend\nend\nlength=a.length\nswap=0\nloop do\nif a[i]!=b[i]\na[i]=b[i]\nswap+=1\nend\ni+=1\nbreak if i>=length\nend\n\nputs\"#{c+swap/2}\""}, {"source_code": "a=gets.chomp\nb=gets.chomp\ncounts=[0,0]\na.split(\"\").each_index do |i|\n if a[i]==\"4\" && b[i]==\"7\"\n counts[0]=counts[0]+1\n elsif a[i]==\"7\" && b[i]==\"4\"\n counts[1]=counts[1]+1\n end\nend\nputs counts.max \n"}, {"source_code": "a = gets.chomp\nb = gets.chomp\nx = 0\ny = 0\n(0...a.size).each do |i|\n if a[i] == '7' and b[i] == '4'\n x += 1\n elsif a[i] == '4' and b[i] == '7'\n y += 1\n end\nend\nputs [x,y].max\n"}, {"source_code": "n = m = 0\na = gets.chomp.chars\nb = gets.chomp.chars\n(0...a.size).each { |i|\n if a[i] != b[i]\n if a[i] == '4'\n n += 1\n else\n m += 1\n end\n end\n}\nputs [n, m].max"}, {"source_code": "a, b = gets.chomp.split(\"\").map(&:to_i), gets.split(\"\").map(&:to_i)\nf, s = 0, 0\na.length.times{ |i|\n next if a[i] == b[i]\n if a[i]!=4\n f += 1\n else\n s += 1\n end\n}\np [f, s].min + (f-s).abs"}, {"source_code": "$a = gets.chomp\n$b = gets.chomp\nplmi = 0\ndiffcnt = 0\nfor i in 0..$a.length\n ac = $a.slice(i,1)\n bc = $b.slice(i,1)\n next if ac == bc\n diffcnt += 1\n if ac == \"4\"\n plmi += 1\n else\n plmi -= 1\n end\nend\nputs (diffcnt-plmi.abs)/2+plmi.abs\n"}, {"source_code": "a,b=2.times.map{gets.chomp.chars.to_a}\nc4=c7=0\na.size.times{|i|\n\tunless a[i]==b[i]\n\t\ta[i]==?4 ? c4+=1 : c7+=1\n\tend\n}\np [c4,c7].max"}], "negative_code": [{"source_code": "$a = gets.chomp\n$b = gets.chomp\nplmi = 0\ndiffcnt = 0\nfor i in 0..$a.length\n ac = $a.slice(i,1)\n bc = $b.slice(i,1)\n next if ac == bc\n diffcnt += 1\n if ac == \"4\"\n plmi += 1\n else\n plmi -= 1\n end\nend\nputs diffcnt/2+plmi.abs\n"}, {"source_code": "a = gets\nb = gets\nea = a.each_char\n\nret = 0\nb.each_char do |c|\n l = ea.next\n ret += 1 unless c == l\nend\n\nputs ret\n"}, {"source_code": "a=gets.bytes.to_a\nb=gets.bytes.to_a\ncnt=[0,0]\na.length.times{|i| cnt[a[i]==\"4\"?1:0]+=1 if a[i]!=b[i]}\np cnt[0]+cnt[1]-cnt.min\n"}, {"source_code": "input = STDIN.read.split(\"\\n\")\nstr1, str2 = input[0].split(//).map(&:to_i), input[1].split(//).map(&:to_i)\n\ncount = 0\n\nstr1.length.times {|x| str1.delete_at x if str1[x] == str2[x] }\n\nn4 = str1.count(4)\nn7 = str1.count(7)\n\nmoves = n4 <= n7 ? n4 : n7\nSTDOUT.puts moves += (n4 - n7).abs"}, {"source_code": "input = STDIN.read.split(\"\\n\")\nstr1, str2 = input[0], input[1]\n\ncount = 0\nskip = false\n\nstr1.length.times do |i|\n\n\tif str1[i] == str2[i] or skip\n\t\tskip = false\n\t\tnext\n\tend\n\n\tif str1[i + 1].nil?\n\t\tcount += 1\n\t\tbreak\n\tend\n\n\tif str1[i + 1] != str2[i + 1] and str1[i] != str1[i + 1]\n\t\tcount += 1\n\t\tskip = true\n\telse\n\t\tcount += 1\n\tend\n\n\nend\n\nSTDOUT.puts count"}], "src_uid": "2d1609b434262d30f6bd030d41a71bd5"} {"source_code": "n,l,a = gets.strip.split.map(&:to_i)\nintervals = [0]\n\nn.times do\n ti, li = gets.strip.split.map(&:to_i)\n intervals << ti\n intervals << ti + li\nend\nintervals << l\n\nans = 0\nim = intervals.size / 2\ni = 0\nim.times do\n s = intervals[i]\n e = intervals[i+1]\n ans += (e-s)/a\n i+=2\nend\nputs ans\n", "positive_code": [{"source_code": "n,l,a = gets.split.map(&:to_i)\nans = 0\nt = [[0,0]] + n.times.map{gets.split.map(&:to_i)} + [[l,0]]\n\nfor i in 0..n\n ans += (t[i+1][0]-t[i][0]-t[i][1])/a\nend\n\nputs ans\n"}, {"source_code": "n,l,a = gets.split.map(&:to_i)\nans = 0\nt = [[0,0]] + n.times.map{gets.split.map(&:to_i)} + [[l,0]]\n\nfor i in 0..n\n ans += (t[i+1][0]-t[i][0]-t[i][1])/a\nend\n\nputs ans\n\n"}, {"source_code": "nla = gets.chomp.split(\" \").map(&:to_i)\n\nn = nla[0]\nl = nla[1]\na = nla[2]\n\narr = []\nn.times do\n arr.push gets.chomp.split(\" \").map(&:to_i)\nend\n\narr.sort_by{|x| x[0]}\n\nif n==0\n puts l/a\n exit\nend\n\nfirst = arr[0][0]/a\nlast = (l-(arr[n-1][0]+arr[n-1][1]))/a\n\nans = 0\n\narr.each_with_index do |x,i|\n next if i==n-1\n ans += (arr[i+1][0]-(x[0]+x[1]))/a\nend\n\nans += (first+last)\nputs ans\n"}], "negative_code": [{"source_code": "nla = gets.chomp.split(\" \").map(&:to_i)\n\nn = nla[0]\nl = nla[1]\na = nla[2]\n\narr = []\nn.times do\n arr.push gets.chomp.split(\" \").map(&:to_i)\nend\n\narr.sort_by{|x| x[0]}\n\nif n==0\n puts l/a\n exit\nend\n\nfirst = arr[0][0]/a\nlast = (l-arr[n-1][1])/a\n\nans = 0\n\narr.each_with_index do |x,i|\n next if i==n-1\n ans += (arr[i+1][0]-x[1])/a\nend\n\nans += (first+last)\nputs ans \n"}], "src_uid": "00acb3b54975820989a788b9389c7c0b"} {"source_code": "n=gets.to_i\na=gets.split.map &:to_i;\nz=i=j=0;\nwhile i 1\n \t\tcount += (l-1).downto(1).inject(0,:+)\n \tend\nend\nputs count"}, {"source_code": "n = gets.to_i\na = gets.split\n\nprev = 2 * 1e9.to_i\nsz = 0\nans = 0\na.each do |x|\n if x == prev\n sz += 1\n else\n ans += sz * (sz + 1) / 2\n sz = 1\n prev = x\n end\nend\nputs ans + sz * (sz + 1) / 2\n"}, {"source_code": "n = gets.chomp.to_i\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nret = n\nsamecnt = 0\nfor i in 1..n-1\n\tif (ar[i] == ar[i-1])\n\t\tsamecnt += 1\n\telse\n\t\tret += ((samecnt+1)*samecnt)/2\n\t\tsamecnt = 0\n\tend\nend\nret += ((samecnt+1)*samecnt)/2\nputs ret\n"}, {"source_code": "gets\na=gets.split.map{|x| x.to_i}\nlast, cnt = -(10**10), 0\nans = 0\n\na.each do |x|\n\tif last != x then\n\t\tans += cnt*(cnt+1)\n\t\tlast = x\n\t\tcnt = 1\n\telse\n\t\tcnt += 1\n\tend\nend\n\np (ans+cnt*(cnt+1))/2\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\ndef getis;gets.split.map(&:to_i);end\ndef log(m); warn(m); end\n\ngets\nnums = getis\n\ni=0\npre=nil\nc=1\nlog nums\nnums.each do |n|\n log [pre, n]\n if pre == n\n c+=1\n i+=c\n else\n pre=n\n c=1\n i+=1\n end\nend\nputs i\n\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\nar.sort!\nret = n\nsamecnt = 0\nfor i in 1..n-1\n\tif (ar[i] == ar[i-1])\n\t\tsamecnt += 1\n\telse\n\t\tret += ((samecnt+1)*samecnt)/2\n\t\tsamecnt = 0\n\tend\nend\nret += ((samecnt+1)*samecnt)/2\nputs ret\n"}], "src_uid": "0b229ddf583949d43d6f1728e38c3cad"} {"source_code": "n,v=gets.split.map(&:to_i)\nd=[0]*3001\nn.times do\n a,b=gets.split.map(&:to_i)\n d[a-1]+=b\nend\ns=r=0\n3001.times do |i|\n e=[r,v].min\n f=[v-e,d[i]].min\n s+=e+f\n r=d[i]-f\nend \np s\n\n\n", "positive_code": [{"source_code": "n, v = gets.split.map(&:to_i)\nx = [0] * 3001\nn.times do\n pos, value = gets.split.map(&:to_i)\n x[pos - 1] += value\nend\n\ns = r = 0\n3001.times do |i|\n e = [r, v].min\n f = [x[i], v - e].min\n s += e + f\n r = x[i] - f\nend\np s"}, {"source_code": "n,v=gets.split.map(&:to_i)\nd=[0]*3001\nn.times do\n a,b=gets.split.map(&:to_i)\n d[a-1]+=b\nend\ns=r=0\n3001.times do |i|\n e=[r,v].min\n f=[v-e,d[i]].min\n s+=e+f\n r=d[i]-f\nend \np s\n\n\n"}, {"source_code": "n,v=gets.split.map(&:to_i)\nd=[0]*3001\nn.times do\n a,b=gets.split.map(&:to_i)\n d[a-1]+=b\nend\ns=r=0\n3001.times do |i|\n e=[r,v].min\n f=[v-e,d[i]].min\n s+=e+f\n r=d[i]-f\nend \np s\n\n\n"}, {"source_code": "n,v=gets.split.map(&:to_i)\nd=[0]*3001\nn.times do\n a,b=gets.split.map(&:to_i)\n d[a-1]+=b\nend\ns=r=0\n3001.times do |i|\n e=[r,v].min\n f=[v-e,d[i]].min\n s+=e+f\n r=d[i]-f\nend \np s\n\n\n"}, {"source_code": "n,v = gets.split.map(&:to_i)\nripe_on_day = Array.new(3010, 0)\n(0...n).each { |_|\n day,amount = gets.split.map(&:to_i)\n ripe_on_day[day] += amount\n}\nputs ripe_on_day.inject(0) { |memo, value|\n harvest = [memo[1] + value, v].min\n take_new_fruits = [0, v - memo[1]].max\n [memo[0] + harvest, [0, value - take_new_fruits].max]\n}[0]\n"}, {"source_code": "n, v = gets.split.collect{|i| i.to_i}\nnum = Hash.new(0)\n(0...n).each do\n tmp = gets.split.collect{|i| i.to_i}\n num[tmp[0]] += tmp[1]\nend\nans = 0\n(1..3001).each do |i|\n tmp = [num[i-1], v].min\n ans += tmp\n tmp = v-tmp\n if tmp > 0\n if tmp >= num[i]\n ans += num[i]\n num[i] = 0\n else\n ans += tmp\n num[i] -= tmp\n end\n end\nend\nputs ans\n"}, {"source_code": "n,v=gets.split.map(&:to_i)\nd=[0]*3001\nn.times do\n a,b=gets.split.map(&:to_i)\n d[a-1]+=b\nend\ns=r=0\n3001.times do |i|\n e=[r,v].min\n f=[v-e,d[i]].min\n s+=e+f\n r=d[i]-f\nend \np s\n\n"}, {"source_code": "n,v=gets.split.map(&:to_i)\nd=[0]*3001\nn.times do\n a,b=gets.split.map(&:to_i)\n d[a-1]+=b\nend\ns=r=0\n3001.times do |i|\n e=[r,v].min\n f=[v-e,d[i]].min\n s+=e+f\n r=d[i]-f\nend \np s\n\n\n"}, {"source_code": "n,v=gets.split.map(&:to_i)\nd=[0]*3001\nn.times do\n a,b=gets.split.map(&:to_i)\n d[a-1]+=b\nend\ns=r=0\n3001.times do |i|\n e=[r,v].min\n f=[v-e,d[i]].min\n s+=e+f\n r=d[i]-f\nend \np s\n\n\n"}, {"source_code": "#!/usr/bin/ruby\nn,v=gets.split.map(&:to_i)\na=n.times.map{gets.split.map(&:to_i)}\nma=a.max[0]\nm=[0]*(ma+2)\na.each{|x,y|m[x]+=y}\nr=0\n1.step(ma+1){|i|\n\tavail=m[i-1]+m[i]\n\tgather=[avail,v].min\n\tr+=gather\n\tx=[m[i-1],gather].min\n\tm[i-1]-=x\n\tgather-=x\n\tm[i]-=gather\n}\np r"}, {"source_code": "n,v=gets.split.map(&:to_i)\nd=[0]*3001\nn.times do\n a,b=gets.split.map(&:to_i)\n d[a-1]+=b\nend\ns=r=0\n3001.times do |i|\n e=[r,v].min\n f=[v-e,d[i]].min\n s+=e+f\n r=d[i]-f\nend \np s\n\n\n"}, {"source_code": "n,v=gets.split.map(&:to_i)\nd=[0]*3001\nn.times do\n a,b=gets.split.map(&:to_i)\n d[a-1]+=b\nend\ns=r=0\n3001.times do |i|\n e=[r,v].min\n f=[v-e,d[i]].min\n s+=e+f\n r=d[i]-f\nend \np s\n\n\n"}, {"source_code": "n,v=gets.split.map(&:to_i)\nd=[0]*3001\nn.times do\n a,b=gets.split.map(&:to_i)\n d[a-1]+=b\nend\ns=r=0\n3001.times do |i|\n e=[r,v].min\n f=[v-e,d[i]].min\n s+=e+f\n r=d[i]-f\nend \np s\n\n"}], "negative_code": [], "src_uid": "848ead2b878f9fd8547e1d442e2f85ff"} {"source_code": "n = gets.chomp.to_i\ns = gets.chomp.split('')\nans = 0\nn.times do |i|\n if i.odd?\n c = s[i - 1]\n if c == 'a'\n c = 'b'\n else\n c = 'a'\n end\n if s[i] != c\n ans += 1\n end\n s[i] = c\n end\nend\nputs ans\nputs s.join('')\n", "positive_code": [{"source_code": "n, s = gets.to_i, gets.chomp\ni, nsubs, a = 0, 0, [nil]*s.size\nwhile i < n\n if i%2 == 0 && s[i] == s[i + 1]\n nsubs += 1\n a[i] = s[i] == 'a' ? 'b' : 'a'\n else\n a[i] = s[i]\n end\n i += 1\nend\np nsubs\nputs a.join\n"}, {"source_code": "def anti(c)\n return 'b' if c == 'a'\n\n 'a'\nend\n_ = gets.chomp\ns = gets.chomp\nn = 0\ntmp = s.split('').each_slice(2).to_a\ntmp.each_with_index do |el, ind|\n if el[0] == el[1]\n tmp[ind] = [el[0], anti(el[1])]\n n += 1\n end\nend\nputs(n)\nputs(tmp.flatten.join(''))\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nn = inp[0]\ns = gets.chomp.split(\"\")\nf = false\nans = 0\ns.each.with_index do |c, i|\n if(i.odd?)\n if(c == \"a\")\n if(f)\n s[i] = \"b\"\n ans += 1\n end\n else\n if(!f)\n s[i] = \"a\"\n ans += 1\n end\n end\n f = false\n else\n f = true if c == \"a\"\n end\nend\np ans\nputs s.join\n"}, {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nn = inp[0]\ns = gets.chomp.split(\"\")\nf = false\nans = 0\ns.each.with_index do |c, i|\n if(i.odd?)\n if(c == \"a\")\n if(f)\n s[i] = \"b\"\n ans += 1\n end\n else\n if(!f)\n s[i] = \"a\"\n ans += 1\n end\n end\n else\n f = true if c == \"a\"\n end\nend\np ans\nputs s.join\n"}], "src_uid": "8ad06ac90b258a8233e2a1cf51f68078"} {"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n ys = xs.uniq\r\n diff = xs.size - ys.size\r\n p ys.size - (diff & 1)\r\nend\r\n", "positive_code": [{"source_code": "n = gets.to_i\n\nn.times do\n m = gets.to_i\n\n hashmap = Hash.new(0)\n initial_size = 0\n gets.split(\" \").each do |chunk|\n initial_size += 1\n hashmap[chunk] += 1\n end\n\n result = 0\n hashmap.each_value do |value|\n result += value - 1 if value > 1\n end\n\n result += 1 if result % 2 == 1\n\n p (initial_size - result)\nend\n"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n n=gets.to_i\r\n d=gets.split.map &:to_i\r\n uniques = d.uniq.size\r\n if uniques%2==n%2\r\n puts uniques\r\n else\r\n puts uniques - 1\r\n end\r\nend"}, {"source_code": "$cnt = []\r\n\r\ndef solve\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n a.each do |x|\r\n $cnt[x] = $cnt[x] + 1\r\n end\r\n ans = 0\r\n even = 0\r\n a.each do |x|\r\n if $cnt[x] % 2 == 1\r\n ans = ans + 1\r\n elsif $cnt[x] > 0\r\n even = even + 1\r\n end\r\n $cnt[x] = 0\r\n if even == 2\r\n ans = ans + 2\r\n even = 0\r\n end\r\n end\r\n puts ans\r\nend\r\n\r\nmaxn = 10005\r\nmaxn.times do\r\n $cnt.append(0)\r\nend\r\ngets.to_i.times do\r\n solve\r\nend"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n at = a.tally\r\n e = a.uniq.size\r\n if n.even?\r\n if e.even?\r\n puts e\r\n else\r\n puts e-1\r\n end\r\n else\r\n if e.odd?\r\n puts e\r\n else\r\n puts e-1\r\n end\r\n end\r\nend\r\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i).tally\n puts a.size - (n - a.size) % 2\nend\n"}, {"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n n = int\r\n a = ints\r\n \r\n double_count = 0\r\n a.tally.each_value do |c|\r\n double_count += c - 1\r\n end\r\n \r\n puts n - double_count.div_ceil(2) * 2\r\n end\r\n}\r\n\r\nDEBUG = false\r\nMOD = 10**9+7\r\nINF = 10**18\r\n$yesno = %w(No Yes)\r\n$YesNo = %w(No Yes)\r\n$YESNO = %w(NO YES)\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t ? 1 : 0] end\r\ndef YesNo t; puts $YesNo[t ? 1 : 0] end\r\ndef YESNO t; puts $YESNO[t ? 1 : 0] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]"}], "negative_code": [], "src_uid": "ab7ab67941783da5c16f6294eb1910d9"} {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\nans = 0\nn.times do |i|\n ans += a[i] * (1+i)\n ans -= i\nend\nputs ans", "positive_code": [{"source_code": "gets\ns = 0\ngets.split.map(&:to_i).each_with_index do |a, i|\n\ts += (a - 1) * (i + 1) + 1\nend\nputs s\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\n\nans=0\nn.times{|i|\n ans+=a[i]*(1+i)\n ans-=i\n}\np ans\n"}, {"source_code": "n = gets.to_i\narr = gets.split(' ').map(&:to_i)\nans = 0\nn.times do |i|\n ans += (arr[i] - 1) * (1 + i)\nend\nans += n\nprint (ans)\n\n"}, {"source_code": "n = gets.to_i\narr = gets.split(' ').map(&:to_i)\nans = 0\nn.times do |i|\n ans += (arr[i] - 1) * (1 + i)\nend\nans += n\nprint ans\n\n"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\ndp = [1]\nans = 0\narr.reverse_each do |e| \n\tdp << e + dp[-1] - 1\n\tans += dp[-1] \nend\nputs ans"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\nans = 0\nn.times do |i|\n ans += (i+1)*(a[i]-1)+1\nend\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /).map!{|x| x.to_i}\nsum = 0\nfor i in 0..n-1\n sum += a[i]\n sum += (i * (a[i]-1))\nend\nputs sum"}, {"source_code": "#!/usr/bin/ruby\nnoq = gets.chop.to_i\nqp = gets.chop.split(' ');\nclicks = 0\nfor i in 0..qp.count-1\n clicks += qp[i].to_i*(i+1) - i;\nend\nputs clicks.to_s"}, {"source_code": "#!/usr/bin/ruby\nnoq = gets.chop.to_i\nqp = gets.chop.split(' ');\nclicks = 0\nfor i in 0..qp.count-1\n\tclicks += qp[i].to_i\n\tclicks += qp[i].to_i*i - i;\nend\nputs clicks.to_s\n"}, {"source_code": "n=gets.to_i\nres,x=0,0\ngets.split.map(&:to_i).reverse.each {|a|\n res+=a+x\n x+=a-1\n}\np res\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\nans = 0\nn.times do |i|\n ans += (i+1)*(a[i]-1)+1\nend\nputs ans\n"}, {"source_code": "gets\np gets.split.map(&:to_i).each_with_index.map{|a,i|(a-1)*(i+1)+1}.inject(:+)\n"}, {"source_code": "#!/usr/bin/env ruby\n#\n\ndef solve ai\n ret = ai[0]\n (1..ai.length-1).each do |i|\n ret += i*(ai[i]-1)\n ret += ai[i]\n end\n ret\nend\n\nn=STDIN.gets.to_i\narr = STDIN.gets.split(\" \").map {|i| i.to_i}\np solve(arr)\n"}], "negative_code": [{"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\n\nans=0\nn.times{|i|\n ans+=a[i]*(1+i)\n ans-=1\n}\np ans+1\n"}, {"source_code": "#!/usr/bin/ruby\nnoq = gets.chop.to_i\nqp = gets.chop.split(' ');\nclicks = 0\nfor i in 0..qp.count-1\n clicks += qp[i].to_i*i;\nend\nputs clicks.to_s"}, {"source_code": "8\n"}, {"source_code": "#!/usr/bin/ruby\nnoq = gets.chop.to_i\nqp = gets.chop.split(' ');\nclicks = 0\nfor i in 0..qp.count-1\n\tclicks += qp[i].to_i\nend\nif qp.count > 1\n\tfor i in 1..qp.count-1\n\t\tclicks+= qp[i].to_i\n\tend\nend\nclicks -= noq-1\nputs clicks.to_s\n"}, {"source_code": "n=gets.to_i\nres=0\ngets.split.map(&:to_i).each {|a|\n n-=1\n res+=a\n res+=n if a>1\n}\np res\n"}, {"source_code": "#!/usr/bin/env ruby\n#\n\ndef solve ai\n ret = ai[0]\n (1..ai.length-1).each do |i|\n ret += i #if ai[i] > 1\n ret += ai[i]\n end\n ret\nend\n\nn=STDIN.gets.to_i\narr = STDIN.gets.split(\" \").map {|i| i.to_i}\np solve(arr)\n"}, {"source_code": "#!/usr/bin/env ruby\n#\n\ndef solve ai\n ret = ai[0]\n (1..ai.length-1).each do |i|\n ret += i if ai[i] > 1\n ret += ai[i]\n end\n ret\nend\n\nn=STDIN.gets.to_i\narr = STDIN.gets.split(\" \").map {|i| i.to_i}\np solve(arr)\n"}, {"source_code": "#!/usr/bin/env ruby\n#\n\ndef solve ai\n ret = ai[0]\n (1..ai.length-1).each do |i|\n ret *= ai[i]-1\n ret += ai[i]\n end\n ret\nend\n\nn=STDIN.gets.to_i\narr = STDIN.gets.split(\" \").map {|i| i.to_i}\np solve(arr)\n"}], "src_uid": "c8531b2ab93993b2c3467595ad0679c5"} {"source_code": "# 2\r\n# 4\r\n# 1 0 0 1 0\r\n# 0 1 0 0 1\r\n# 0 0 0 1 0\r\n# 0 1 0 1 0\r\n# 2\r\n# 0 0 0 1 0\r\n# 0 0 0 1 0\r\n\r\nrequire 'set'\r\n\r\nn = gets.to_i\r\n\r\ndef result\r\n n = gets.to_i\r\n arrs = n.times.map { gets.split.map(&:to_i) }\r\n counts = Array.new(5) { Set.new }\r\n arrs.each.with_index do |arr, j|\r\n 5.times do |i|\r\n counts[i].add(j) if arr[i] == 1\r\n end\r\n end\r\n\r\n counts = counts.select { |c| c.size >= n / 2 }\r\n counts.size.times do |i|\r\n first_group = counts[i]\r\n (i + 1).upto(counts.size - 1) do |j|\r\n second_group = counts[j]\r\n big_group, small_group = if second_group.size < first_group.size\r\n [first_group,\r\n second_group]\r\n else\r\n [second_group, first_group]\r\n end\r\n f = 0\r\n s = 0\r\n b = 0\r\n big_group.each do |stu|\r\n if small_group === stu\r\n b += 1\r\n else\r\n f += 1\r\n end\r\n end\r\n small_group.each do |stu|\r\n next if big_group === stu\r\n\r\n s += 1\r\n end\r\n return 'YES' if n / 2 - f >= 0 && n / 2 - s >= 0 && b == n - f - s\r\n end\r\n end\r\n 'NO'\r\nend\r\n\r\nn.times do\r\n puts result\r\nend\r\n", "positive_code": [{"source_code": "days = [*0..4]\r\n\r\ngets.to_i.times do\r\n n = gets.to_i\r\n xxs = n.times.map { gets.split.map(&:to_i) }\r\n ok = days.any? do |i|\r\n (days - [i]).any? do |j|\r\n ii = xxs.count { |xs| xs[i] == 1 && xs[j] == 0 }\r\n jj = xxs.count { |xs| xs[j] == 1 && xs[i] == 0 }\r\n ij = xxs.count { |xs| xs[i] == 1 && xs[j] == 1 }\r\n ni = [0, n / 2 - ii].max\r\n nj = [0, n / 2 - jj].max\r\n ni + nj <= ij\r\n end\r\n end\r\n puts ok ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n n2=n/2\r\n l=[]\r\n 5.times do\r\n l << [0]*5\r\n end\r\n n.times do\r\n s=gets.split.map(&:to_i)\r\n 5.times do |i|\r\n 5.times do |j|\r\n if s[i]+s[j]==2\r\n l[i][j]+=1\r\n end\r\n end\r\n end\r\n end\r\n f=false\r\n 5.times do |j|\r\n j.times do |i|\r\n if l[i][i]+l[j][j]-l[i][j]==n&&l[i][i]>=n2&&l[j][j]>=n2\r\n f=true\r\n break\r\n end\r\n end\r\n break if f\r\n end\r\n if f\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\n \r\nend\r\n"}, {"source_code": "t = gets.chomp.to_i\r\n\r\nt.times do\r\n n = gets.chomp.to_i\r\n\r\n week = Array.new(5) { [] }\r\n\r\n n.times do\r\n v = gets.chomp.split.map(&:to_i)\r\n\r\n week[0] << v[0]\r\n week[1] << v[1]\r\n week[2] << v[2]\r\n week[3] << v[3]\r\n week[4] << v[4]\r\n end\r\n\r\n good = false\r\n\r\n 5.times do |i|\r\n for j in i+1..4\r\n l, r, no = 0, 0, 0\r\n\r\n [week[i], week[j]].transpose.each do |a,b|\r\n if a == 1\r\n l += 1\r\n end\r\n\r\n if b == 1\r\n r += 1\r\n end\r\n\r\n if a == 0 and b == 0\r\n no += 1\r\n end\r\n end\r\n\r\n if l >= n / 2 and r >= n / 2 and no == 0\r\n good = true\r\n break\r\n else\r\n next\r\n end\r\n end \r\n end\r\n\r\n if good\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "# 2\r\n# 4\r\n# 1 0 0 1 0\r\n# 0 1 0 0 1\r\n# 0 0 0 1 0\r\n# 0 1 0 1 0\r\n# 2\r\n# 0 0 0 1 0\r\n# 0 0 0 1 0\r\n\r\nrequire 'set'\r\n\r\nn = gets.to_i\r\n\r\ndef result\r\n n = gets.to_i\r\n arrs = n.times.map { gets.split.map(&:to_i) }\r\n counts = Array.new(5) { Set.new }\r\n arrs.each.with_index do |arr, j|\r\n 5.times do |i|\r\n counts[i].add(j) if arr[i] == 1\r\n end\r\n end\r\n\r\n counts = counts.select { |c| c.size >= n / 2 }\r\n counts.size.times do |i|\r\n first_group = counts[i]\r\n (i + 1).upto(counts.size - 1) do |j|\r\n second_group = counts[j]\r\n big_group, small_group = if second_group.size < first_group.size\r\n [first_group,\r\n second_group]\r\n else\r\n [second_group, first_group]\r\n end\r\n changed = 0\r\n big_group.each do |stu|\r\n changed += 1 if small_group === stu\r\n end\r\n if n / 2 - big_group.size + changed >= 0 && n / 2 - small_group.size + changed >= 0 && 0 == n - big_group.size + small_group.size - (3 * changed)\r\n return 'YES'\r\n end\r\n end\r\n end\r\n 'NO'\r\nend\r\n\r\nn.times do\r\n puts result\r\nend\r\n"}, {"source_code": "# 2\r\n# 4\r\n# 1 0 0 1 0\r\n# 0 1 0 0 1\r\n# 0 0 0 1 0\r\n# 0 1 0 1 0\r\n# 2\r\n# 0 0 0 1 0\r\n# 0 0 0 1 0\r\n\r\nrequire 'set'\r\n\r\nn = gets.to_i\r\n\r\ndef result\r\n n = gets.to_i\r\n arrs = n.times.map { gets.split.map(&:to_i) }\r\n counts = Array.new(5) { Set.new }\r\n arrs.each.with_index do |arr, j|\r\n 5.times do |i|\r\n counts[i].add(j) if arr[i] == 1\r\n end\r\n end\r\n\r\n counts = counts.select { |c| c.size >= n / 2 }\r\n counts.size.times do |i|\r\n first_group = counts[i]\r\n (i + 1).upto(counts.size - 1) do |j|\r\n second_group = counts[j]\r\n big_group, small_group = if second_group.size < first_group.size\r\n [first_group,\r\n second_group]\r\n else\r\n [second_group, first_group]\r\n end\r\n changed = 0\r\n big_group.each do |stu|\r\n changed += 1 if small_group === stu\r\n end\r\n if n / 2 - big_group.size + changed >= 0 && n / 2 - small_group.size + changed >= 0 && 0 == n - big_group.size + small_group.size - changed\r\n return 'YES'\r\n end\r\n end\r\n end\r\n 'NO'\r\nend\r\n\r\nn.times do\r\n puts result\r\nend\r\n"}, {"source_code": "# 2\r\n# 4\r\n# 1 0 0 1 0\r\n# 0 1 0 0 1\r\n# 0 0 0 1 0\r\n# 0 1 0 1 0\r\n# 2\r\n# 0 0 0 1 0\r\n# 0 0 0 1 0\r\n\r\nrequire 'set'\r\n\r\nn = gets.to_i\r\n\r\ndef result\r\n n = gets.to_i\r\n arrs = n.times.map { gets.split.map(&:to_i) }\r\n counts = Array.new(5) { Set.new }\r\n arrs.each.with_index do |arr, j|\r\n 5.times do |i|\r\n counts[i].add(j) if arr[i] == 1\r\n end\r\n end\r\n\r\n counts = counts.select { |c| c.size >= n / 2 }\r\n counts.size.times do |i|\r\n first_group = counts[i]\r\n (i + 1).upto(counts.size - 1) do |j|\r\n second_group = counts[j]\r\n big_group, small_group = if second_group.size < first_group.size\r\n [first_group,\r\n second_group]\r\n else\r\n [second_group, first_group]\r\n end\r\n changed = 0\r\n big_group.each do |stu|\r\n changed += 1 if small_group === stu\r\n end\r\n 0.upto(changed) do |z|\r\n return 'YES' if z + small_group.size == n / 2 && big_group.size - changed + z == n / 2\r\n end\r\n end\r\n end\r\n 'NO'\r\nend\r\n\r\nn.times do\r\n puts result\r\nend\r\n"}, {"source_code": "# 2\r\n# 4\r\n# 1 0 0 1 0\r\n# 0 1 0 0 1\r\n# 0 0 0 1 0\r\n# 0 1 0 1 0\r\n# 2\r\n# 0 0 0 1 0\r\n# 0 0 0 1 0\r\n\r\nrequire 'set'\r\n\r\nn = gets.to_i\r\n\r\ndef result\r\n n = gets.to_i\r\n arrs = n.times.map { gets.split.map(&:to_i) }\r\n counts = Array.new(5) { Set.new }\r\n arrs.each.with_index do |arr, j|\r\n 5.times do |i|\r\n counts[i].add(j) if arr[i] == 1\r\n end\r\n end\r\n\r\n counts = counts.select { |c| c.size >= n / 2 }\r\n result = true\r\n counts.size.times do |i|\r\n first_group = counts[i]\r\n (i + 1).upto(counts.size - 1) do |j|\r\n second_group = counts[j]\r\n big_group, small_group = if second_group.size < first_group.size\r\n [first_group,\r\n second_group]\r\n else\r\n [second_group, first_group]\r\n end\r\n changed = 0\r\n big_group.each do |stu|\r\n changed += 1 if small_group === stu\r\n end\r\n result = false if small_group.size + big_group.size - changed == n || big_group.size + small_group.size == n\r\n end\r\n end\r\n !result ? 'YES' : 'NO'\r\nend\r\n\r\nn.times do\r\n puts result\r\nend\r\n"}, {"source_code": "# 2\r\n# 4\r\n# 1 0 0 1 0\r\n# 0 1 0 0 1\r\n# 0 0 0 1 0\r\n# 0 1 0 1 0\r\n# 2\r\n# 0 0 0 1 0\r\n# 0 0 0 1 0\r\n\r\nrequire 'set'\r\n\r\nn = gets.to_i\r\n\r\ndef result\r\n n = gets.to_i\r\n arrs = n.times.map { gets.split.map(&:to_i) }\r\n counts = Array.new(5) { Set.new }\r\n arrs.each.with_index do |arr, j|\r\n 5.times do |i|\r\n counts[i].add(j) if arr[i] == 1\r\n end\r\n end\r\n\r\n counts = counts.select { |c| c.size >= n / 2 }\r\n result = true\r\n counts.size.times do |i|\r\n first_group = counts[i]\r\n (i + 1).upto(counts.size - 1) do |j|\r\n second_group = counts[j]\r\n big_group, small_group = if second_group.size < first_group.size\r\n [first_group,\r\n second_group]\r\n else\r\n [second_group, first_group]\r\n end\r\n changed = 0\r\n big_group.each do |stu|\r\n changed += 1 if small_group === stu\r\n end\r\n if (changed + small_group.size >= n / 2 && small_group.size - (n / 2) <= changed && big_group.size - small_group.size + changed / 2 >= n / 2) || big_group.size - changed + small_group.size == n\r\n result = false\r\n end\r\n end\r\n end\r\n !result ? 'YES' : 'NO'\r\nend\r\n\r\nn.times do\r\n puts result\r\nend\r\n"}, {"source_code": "# 2\r\n# 4\r\n# 1 0 0 1 0\r\n# 0 1 0 0 1\r\n# 0 0 0 1 0\r\n# 0 1 0 1 0\r\n# 2\r\n# 0 0 0 1 0\r\n# 0 0 0 1 0\r\n\r\nrequire 'set'\r\n\r\nn = gets.to_i\r\n\r\ndef result\r\n n = gets.to_i\r\n arrs = n.times.map { gets.split.map(&:to_i) }\r\n counts = Array.new(5) { Set.new }\r\n arrs.each.with_index do |arr, j|\r\n 5.times do |i|\r\n counts[i].add(j) if arr[i] == 1\r\n end\r\n end\r\n\r\n result = true\r\n counts.size.times do |i|\r\n first_group = counts[i]\r\n (i + 1).upto(4) do |j|\r\n second_group = counts[j]\r\n big_group, small_group = if second_group.size < first_group.size\r\n [first_group,\r\n second_group]\r\n else\r\n [second_group, first_group]\r\n end\r\n changed = 0\r\n big_group.each do |stu|\r\n changed += 1 if small_group === stu\r\n end\r\n if (changed + small_group.size >= n / 2 && small_group.size - (n / 2) <= changed && big_group.size - small_group.size + changed / 2 >= n / 2) || big_group.size - changed + small_group.size == n\r\n result = false\r\n end\r\n end\r\n end\r\n !result ? 'YES' : 'NO'\r\nend\r\n\r\nn.times do\r\n puts result\r\nend\r\n"}, {"source_code": "# 2\r\n# 4\r\n# 1 0 0 1 0\r\n# 0 1 0 0 1\r\n# 0 0 0 1 0\r\n# 0 1 0 1 0\r\n# 2\r\n# 0 0 0 1 0\r\n# 0 0 0 1 0\r\n\r\nrequire 'set'\r\n\r\nn = gets.to_i\r\n\r\ndef result\r\n n = gets.to_i\r\n arrs = n.times.map { gets.split.map(&:to_i) }\r\n counts = Array.new(5) { Set.new }\r\n arrs.each.with_index do |arr, j|\r\n 5.times do |i|\r\n counts[i].add(j) if arr[i] == 1\r\n end\r\n end\r\n\r\n result = true\r\n counts.size.times do |i|\r\n first_group = counts[i]\r\n (i + 1).upto(4) do |j|\r\n second_group = counts[j]\r\n big_group, small_group = if second_group.size < first_group.size\r\n [first_group,\r\n second_group]\r\n else\r\n [second_group, first_group]\r\n end\r\n changed = 0\r\n big_group.each do |stu|\r\n changed += 1 if small_group === stu\r\n end\r\n if changed + small_group.size >= n / 2 && small_group.size - (n / 2) <= changed && big_group.size - small_group.size + changed / 2 >= n / 2\r\n result = false\r\n end\r\n end\r\n end\r\n !result ? 'YES' : 'NO'\r\nend\r\n\r\nn.times do\r\n puts result\r\nend\r\n"}, {"source_code": "# 2\r\n# 4\r\n# 1 0 0 1 0\r\n# 0 1 0 0 1\r\n# 0 0 0 1 0\r\n# 0 1 0 1 0\r\n# 2\r\n# 0 0 0 1 0\r\n# 0 0 0 1 0\r\n\r\nrequire 'set'\r\n\r\nn = gets.to_i\r\n\r\ndef result\r\n n = gets.to_i\r\n arrs = n.times.map { gets.split.map(&:to_i) }\r\n counts = Array.new(5) { Set.new }\r\n arrs.each.with_index do |arr, j|\r\n 5.times do |i|\r\n counts[i].add(j) if arr[i] == 1\r\n end\r\n end\r\n\r\n data = counts.select do |count|\r\n count.size >= n / 2\r\n end\r\n\r\n result = true\r\n data.size.times do |i|\r\n first_group = data[i]\r\n (i + 1).upto(data.size - 1) do |j|\r\n second_group = data[j]\r\n big_group, small_group = if second_group.size < first_group.size\r\n [first_group,\r\n second_group]\r\n else\r\n [second_group, first_group]\r\n end\r\n changed = 0\r\n big_group.each do |stu|\r\n changed += 1 if small_group === stu\r\n end\r\n if (small_group.size + changed) >= n / 2 && big_group.size - changed + (small_group.size + changed - n / 2)\r\n result = false\r\n end\r\n end\r\n end\r\n !result ? 'YES' : 'NO'\r\nend\r\n\r\nn.times do\r\n puts result\r\nend\r\n"}, {"source_code": "# 2\r\n# 4\r\n# 1 0 0 1 0\r\n# 0 1 0 0 1\r\n# 0 0 0 1 0\r\n# 0 1 0 1 0\r\n# 2\r\n# 0 0 0 1 0\r\n# 0 0 0 1 0\r\n\r\nrequire 'set'\r\n\r\nn = gets.to_i\r\n\r\ndef result\r\n n = gets.to_i\r\n arrs = n.times.map { gets.split.map(&:to_i) }\r\n counts = Array.new(5) { Set.new }\r\n arrs.each.with_index do |arr, j|\r\n 5.times do |i|\r\n counts[i].add(j) if arr[i] == 1\r\n end\r\n end\r\n\r\n data = counts.select do |count|\r\n count.size >= n / 2\r\n end\r\n\r\n result = true\r\n data.size.times do |i|\r\n first_group = data[i]\r\n (i + 1).upto(data.size - 1) do |j|\r\n second_group = data[j]\r\n big_group, small_group = if second_group.size < first_group.size\r\n [first_group,\r\n second_group]\r\n else\r\n [second_group, first_group]\r\n end\r\n changed = 0\r\n big_group.each do |stu|\r\n changed += 1 if small_group === stu\r\n end\r\n result = false if (small_group.size + changed) >= n / 2\r\n end\r\n end\r\n !result ? 'YES' : 'NO'\r\nend\r\n\r\nn.times do\r\n puts result\r\nend\r\n"}, {"source_code": "t = gets.chomp.to_i\r\n\r\nt.times do\r\n n = gets.chomp.to_i\r\n\r\n week = Array.new(5) { [] }\r\n\r\n n.times do\r\n v = gets.chomp.split.map(&:to_i)\r\n\r\n week[0] << v[0]\r\n week[1] << v[1]\r\n week[2] << v[2]\r\n week[3] << v[3]\r\n week[4] << v[4]\r\n end\r\n\r\n good = false\r\n\r\n 5.times do |i|\r\n for j in (i+1)..4\r\n l, r = 0, 0\r\n\r\n [week[i], week[j]].transpose.each do |a,b|\r\n if a == 1 and b == 1\r\n l += 1\r\n end\r\n\r\n if a == 1\r\n l += 1\r\n end\r\n\r\n if b == 1\r\n r += 1\r\n end\r\n end\r\n\r\n if l+r == n and l != 0 and r != 0\r\n good = true\r\n break\r\n else\r\n next\r\n end\r\n end \r\n end\r\n\r\n if good\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}, {"source_code": "t = gets.chomp.to_i\r\n\r\nt.times do\r\n n = gets.chomp.to_i\r\n\r\n week = Array.new(5) { [] }\r\n\r\n n.times do\r\n v = gets.chomp.split.map(&:to_i)\r\n\r\n week[0] << v[0]\r\n week[1] << v[1]\r\n week[2] << v[2]\r\n week[3] << v[3]\r\n week[4] << v[4]\r\n end\r\n\r\n good = false\r\n\r\n 5.times do |i|\r\n for j in i+1..4\r\n ok = true\r\n\r\n [week[i], week[j]].transpose.each do |a,b|\r\n if a == 0 and b == 0\r\n ok = false\r\n break\r\n end\r\n end\r\n\r\n if ok\r\n good = true\r\n break\r\n else\r\n next\r\n end\r\n end \r\n end\r\n\r\n if good\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}, {"source_code": "t = gets.chomp.to_i\r\n\r\nt.times do\r\n n = gets.chomp.to_i\r\n\r\n week = Array.new(5) { [] }\r\n\r\n n.times do\r\n v = gets.chomp.split.map(&:to_i)\r\n\r\n week[0] << v[0]\r\n week[1] << v[1]\r\n week[2] << v[2]\r\n week[3] << v[3]\r\n week[4] << v[4]\r\n end\r\n\r\n good = false\r\n\r\n n.times do |i|\r\n for j in i..n\r\n ok = true\r\n\r\n [week[i], week[j]].transpose.each do |a, b|\r\n if a == 0 and b == 0\r\n ok = false\r\n break\r\n end\r\n end\r\n\r\n if ok\r\n good = true\r\n break\r\n else\r\n next\r\n end\r\n end \r\n end\r\n\r\n if good\r\n puts(\"YES\")\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}, {"source_code": "t = gets.chomp.to_i\r\n\r\nt.times do\r\n n = gets.chomp.to_i\r\n\r\n week = Array.new(5) { [] }\r\n\r\n n.times do\r\n v = gets.chomp.split.map(&:to_i)\r\n\r\n week[0] << v[0]\r\n week[1] << v[1]\r\n week[2] << v[2]\r\n week[3] << v[3]\r\n week[4] << v[4]\r\n end\r\n\r\n good = false\r\n\r\n n.times do |i|\r\n for j in i..n\r\n ok = true\r\n\r\n [week[i], week[j]].transpose.each do |a, b|\r\n if a == 0 and b == 0\r\n ok = false\r\n break\r\n end\r\n end\r\n\r\n if ok\r\n good = true\r\n break\r\n else\r\n next\r\n end\r\n end \r\n end\r\n\r\n if good\r\n p \"YES\"\r\n else\r\n p \"NO\"\r\n end\r\nend\r\n"}], "src_uid": "068cbfb901aadcd15f794dbbf3dfd453"} {"source_code": "n = gets.to_i\nval = nil\n5.upto(n**0.5) do |i|\n if n % i == 0\n val = i\n break\n end\nend\nvow = \"aeiou\"\nif val == nil\n p -1\n exit\nelse\n row = vow * (val*2/5 + 1)\n (n/val).times do |i|\n print row[i%val,val]\n end\n print \"\\n\"\nend\n", "positive_code": [{"source_code": "n = gets.to_i\nval = nil\n5.upto(n**0.5) do |i|\n if n % i == 0\n val = i\n break\n end\nend\nvow = \"aeiou\"\nif val == nil\n p -1\n exit\nelse\n row = vow * (val/5) + vow[0,val%5]\n row *= 2\n (n/val).times do |i|\n print row[i%val,val]\n end\n print \"\\n\"\nend\n"}, {"source_code": "n = gets.to_i\nf = false\nu = v = 0\nfor i in 5..n\n if n%i == 0 && n/i >= 5\n f = true\n u = i\n v = n/i\n break\n end\nend\nif !f\n puts \"-1\"\n exit\nend\ns = \"aiueo\"*(u/5+2)\nans = \"\"\nv.times do |i|\n ans += s[i%5,u]\nend\nputs ans"}, {"source_code": "def tempfun(k) \n\ttemp = ['a','e','i','o','u']\n\tn = k - 5\n\tn.to_i.times do \n\t\ttemp << 'g' \n\tend\n\tans = []\n\tfor b in 0...temp.length \n\t\tans << temp.rotate(b)\n\tend\n\treturn ans \nend\nmark = false\ni = gets.chomp.to_i \nk = Math.sqrt(i) \nans = Array.new\nif(k >= 5)\n\tt = k.to_i \n\tfor z in 5..t\n\t\tif(i % z == 0 )\n\t\t\tmark = true\n\t\t\tm = (i - z*z)\n\t\t\tans = tempfun(z)\n\t\t\t#print(ans)\n\t\t\tfor i in 0...z\n\t\t\t\tfor j in 0... (m/z)\n\t\t\t\t\tans[i] << ans[i][j]\n\t\t\t\tend\n\t\t\tend\n\t\t\tbreak\n\t\tend\n\tend\n\tif(mark)\n\t\tfor i in ans \n\t\t\tfor m in i \n\t\t\t\tprint(m)\n\t\t\tend\n\t\t\t#puts()\n\t\tend\n\telse \n\t\tprint(-1)\n\tend\nelse\n\tprint(-1)\nend\n"}], "negative_code": [{"source_code": "def tempfun(k) \n\ttemp = ['a','e','i','o','u']\n\tn = k - 5\n\tn.to_i.times do \n\t\ttemp << 'g' \n\tend\n\tans = []\n\tfor b in 0...temp.length \n\t\tans << temp.rotate(b)\n\tend\n\treturn ans \nend\n\ni = gets.chomp.to_i \nk = Math.sqrt(i) \nans = Array.new\nif(k >= 5)\n\tt = k.to_i \n\tif((i - t*t) % t == 0 )\n\t\tm = (i - t*t)\n\t\tans = tempfun(t)\n\t\t#print(ans)\n\t\tfor i in 0...t\n\t\t\tfor j in 0... (m/t)\n\t\t\t\tans[i] << ans[i][j]\n\t\t\tend\n\t\tend\n\telse\n\t\tprint(-1)\n\t\texit\n\tend\n\tfor i in ans \n\t\tfor m in i \n\t\t\tprint(m)\n\t\tend\n\t\tputs()\n\tend\nelse\n\tprint(-1)\n\texit\nend\n"}, {"source_code": "def tempfun(k) \n\ttemp = ['a','e','i','o','u']\n\tn = k - 5\n\tn.to_i.times do \n\t\ttemp << 'g' \n\tend\n\tans = []\n\tfor b in 0...temp.length \n\t\tans << temp.rotate(b)\n\tend\n\treturn ans \nend\n\ni = gets.chomp.to_i \nk = Math.sqrt(i) \nans = Array.new\nif(k >= 5)\n\tt = k.to_i \n\tif((i - t*t) % t == 0 )\n\t\tm = (i - t*t)\n\t\tans = tempfun(t)\n\t\t#print(ans)\n\t\tfor i in 0...t\n\t\t\tfor j in 0... (m/t)\n\t\t\t\tans[i] << ans[i][j]\n\t\t\tend\n\t\tend\n\telse\n\t\tprint(-1)\n\t\texit\n\tend\n\tfor i in ans \n\t\tfor m in i \n\t\t\tprint(m)\n\t\tend\n\t\t\n\tend\nelse\n\tprint(-1)\n\texit\nend\n"}, {"source_code": "n = gets.to_i\nval = nil\n5.upto(n**0.5) do |i|\n if n % i == 0\n val = i\n break\n end\nend\nif val == nil\n p -1\n exit\nelse\n row = \"aeiou\" * (val/5) + \"x\" * (val % 5)\n (n/val).times do \n print row\n end\n print \"\\n\"\nend\n"}, {"source_code": "n = gets.to_i\nf = false\nu = v = 0\nfor i in 5..n\n if n%i == 0 && n/i >= 5\n f = true\n u = i\n v = n/i\n break\n end\nend\nif !f\n puts \"-1\"\n exit\nend\ns = \"aiueo\"*(u/5+1)\nans = \"\"\nv.times do |i|\n ans += s[i%5,u]\nend\nputs ans"}], "src_uid": "933167c31c0f53a43e840cc6cf153f8d"} {"source_code": "def build(n, m)\n 'RGB'.chars.permutation.map do |cs|\n cs.flat_map{|c| n.times.map{(c * m).chars}}\n end\nend\n\nn, m = gets.split.map(&:to_i)\ns = n.times.map{gets.strip.chars}\nts = build(n / 3, m) + build(m / 3, n).map(&:transpose)\n\nif ts.include?(s)\n puts 'YES'\nelse\n puts 'NO'\nend", "positive_code": [{"source_code": "def build(n, m)\n 'RGB'.chars.permutation.map do |cs|\n cs.flat_map{|c| n.times.map{(c * m).chars}}\n end\nend\n\nn, m = gets.split.map(&:to_i)\ns = n.times.map{gets.strip.chars}\nts = build(n / 3, m) + build(m / 3, n).map(&:transpose)\n\nif ts.include?(s)\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "n, m = gets.strip.split(' ').map(&:to_i)\n\na = []\nn.times do\n a.push << (gets.strip.split(''))\nend\n\nrc = true\ntemp = []\nn.times do |i|\n first = nil\n bool = true\n m.times do |j|\n if j == 0\n first = a[i][j]\n temp.push(a[i][j])\n next\n end\n if first != a[i][j]\n bool = false\n break\n end\n end\n if !bool\n rc = false\n break\n end\nend\n\nif rc\n if temp.count('R') == temp.count('G') && temp.count('G') == temp.count('B')\n cnt = temp.count('R')\n if ((temp.rindex('R') - temp.index('R') + 1) == cnt) && ((temp.rindex('G') - temp.index('G') + 1) == cnt) && ((temp.rindex('B') - temp.index('B') + 1) == cnt) \n rc = true\n else\n rc = false \n end\n else\n rc = false\n end\nend\n\nrc1 = true\ntemp = []\nm.times do |i|\n first = nil\n bool = true\n n.times do |j|\n if j == 0\n first = a[j][i]\n temp.push(a[j][i])\n next\n end\n if first != a[j][i]\n bool = false\n break\n end\n end\n if !bool\n rc1 = false\n break\n end\nend\n\nif rc1\n if temp.count('R') == temp.count('G') && temp.count('G') == temp.count('B')\n cnt = temp.count('R')\n if ((temp.rindex('R') - temp.index('R') + 1) == cnt) && ((temp.rindex('G') - temp.index('G') + 1) == cnt) && ((temp.rindex('B') - temp.index('B') + 1) == cnt) \n rc1 = true\n else\n rc1 = false \n end\n else\n rc1 = false\n end\nend\n\n\nif rc || rc1\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na, res = [], \"NO\"\nn.times {a << gets.chomp.chars}\nc = [a[0][0], a[n / 2][m / 2], a[n - 1][m - 1]].uniq\nif c.size == 3\n n = n * m / 3\n s = [c[0] * n, c[1] * n, c[2] * n].join\n [a, a.transpose].each {|b| res = \"YES\" if b.flatten.join == s}\nend\nputs res\n\n"}], "negative_code": [{"source_code": "n, m = gets.strip.split(' ').map(&:to_i)\n\na = []\nn.times do\n a.push << (gets.strip.split(''))\nend\n\nrc = true\ntemp = []\nn.times do |i|\n first = nil\n bool = true\n m.times do |j|\n if j == 0\n first = a[i][j]\n temp.push(a[i][j])\n next\n end\n if first != a[i][j]\n bool = false\n break\n end\n end\n if !bool\n rc = false\n break\n end\nend\n\nif rc\n if temp.count('R') == temp.count('G') && temp.count('G') == temp.count('B')\n rc = true\n else\n rc = false\n end\nend\n\nrc1 = true\ntemp = []\nm.times do |i|\n first = nil\n bool = true\n n.times do |j|\n if j == 0\n first = a[j][i]\n temp.push(a[j][i])\n next\n end\n if first != a[j][i]\n bool = false\n break\n end\n end\n if !bool\n rc1 = false\n break\n end\nend\n\nif rc1\n if temp.count('R') == temp.count('G') && temp.count('G') == temp.count('B')\n rc1 = true\n else\n rc1 = false\n end\nend\n\n\nif rc || rc1\n puts 'YES'\nelse\n puts 'NO'\nend\n"}], "src_uid": "0988b8439c6699107c77345037162fba"} {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /).map(&:to_i)\nneighbor = {}\ni = j = 0\nn1 = n2 = 0\ndiff = 0\nwhile true\n n1 = a[i]\n if i + 1 == n\n j = 0\n else\n j = i + 1\n end\n n2 = a[j]\n diff = (n1 - n2).abs\n pair = [i + 1, j + 1]\n if !neighbor.has_key? pair\n neighbor.store pair, diff\n else\n neighbor[pair] = diff\n end\n i += 1\n break if j == 0\nend\nmin_h = neighbor.values.min\nrecon = neighbor.select { |k, v| v == min_h }.to_a[0][0]\nputs recon.join(\" \")\n", "positive_code": [{"source_code": "n=gets.to_i\ndata=gets.split.map(&:to_i)\ndata << data[0]\n\ndif=999999\na=b=0\nfor i in 0..data.size-2\n\ttmp=(data[i]-data[i+1]).abs\n\tif dif>tmp\n\t\ta,b=i,((i+1)%n==0? 1 : i+2)\n\t\tdif=tmp\n\tend\nend\n\nputs \"#{a+1} #{b}\"\n"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\ndiff_arr = []\n(1..n-1).each do |i|\n\tdiff_arr << (arr[i] - arr[i-1]).abs\nend\ndiff_arr << (arr[0]-arr[-1]).abs\nmin,min_ind = diff_arr.each_with_index.min\n\nif min_ind == n -1 \n\ta,b = n,1\nelse\n\ta,b = min_ind+1,min_ind + 2\nend\nputs \"#{a} #{b}\""}, {"source_code": "n = gets.to_i\na = gets.split.map!(&:to_i)\nk = (-1...n-1).min_by { |i| (a[i] - a[i+1]).abs; }\nputs \"#{k % a.length + 1} #{k + 2}\""}, {"source_code": "tot, min, min_index, input = gets.to_i, 20000, -1, gets.split(' ').map{|n| n.to_i}\ninput.each_cons(2).to_a.each_with_index { |(a, b), index| min, min_index = (a - b).abs, index if (((a - b).abs) < min) }\nmin_index = tot - 1 if (min > (input[0] - input[input.length - 1]).abs)\nmax_index = (min_index == tot - 1) ? 0 : min_index + 1\nprint (min_index + 1).to_s + ' ' + (max_index + 1).to_s"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\nans = 0\n(1...n-1).each{|i| ans = i if (a[i]-a[i+1]).abs < (a[ans]-a[ans+1]).abs}\nif (a[0]-a[n-1]).abs < (a[ans]-a[ans+1]).abs\n print n, \" \", 1, \"\\n\"\nelse\n print ans+1, \" \", ans+2, \"\\n\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\nans = 0\nfor i in 1...n-1\n ans = i if (a[i]-a[i+1]).abs < (a[ans]-a[ans+1]).abs\nend\nif (a[0]-a[n-1]).abs < (a[ans]-a[ans+1]).abs\n print n, \" \", 1, \"\\n\"\nelse\n print ans+1, \" \", ans+2, \"\\n\"\nend\n"}, {"source_code": "gets # ignore n\n\nsoldiers = gets.chomp.split.map(&:to_i)\n\nsoldiers << soldiers[0]\ndiff, pos = 1_001, 0\n\nsoldiers[0..-2].each_with_index do |s, i|\n tmp_diff = (s - soldiers[i + 1]).abs\n if tmp_diff < diff\n diff = tmp_diff\n pos = i\n end\nend\n\nputs pos + 1, (pos + 2 > soldiers.size - 1 ? 1 : pos + 2)\n"}, {"source_code": "n = gets.to_i\nh = gets.split(\" \").map{|s| s.to_i}\nh << h[0]\nbest = (0 ... n).min_by { |i| (h[i] - h[i+1]).abs }\nprint (best%n)+1, \" \", ((best+1)%n) + 1\n"}, {"source_code": "gets\nh = gets.split(\" \").map{|s| s.to_i}\nn = h.length\nh << h[0]\nbest = 0\n(0...n).each do |i|\n if (h[i] - h[i+1]).abs < (h[best] - h[best+1]).abs\n best = i\n end\nend\n\nprint (best%n)+1, \" \", ((best+1)%n) + 1"}, {"source_code": "n = gets.to_i\na = gets.split.map { |x| x.to_i }\n\nmin = 1_000\nmin_ind = nil\nfor i in 1...n\n diff = (a[i] - a[i - 1]).abs\n if diff < min\n min = diff\n min_ind = i\n end\nend\n\nif (a.last - a.first).abs < min\n min_ind = n\n next_min_ind = 1\nelse\n next_min_ind = min_ind + 1\nend\nputs \"#{min_ind} #{next_min_ind}\""}, {"source_code": "n, s, min, idx = gets.to_i, gets.strip.split.map(&:to_i), 0, idx\n\n(print [1, n].join \" \"; exit) if s[0] == s[-1]\nmin, idx = (s[0] - s[-1]).abs, [1, n]\n\n(0...n - 1).each do |i|\n a, b = i, i + 1\n (print [a + 1, b + 1].join \" \"; exit) if s[a] == s[b]\n m = (s[a] - s[b]).abs\n if m < min\n min = m\n idx = [a + 1, b + 1]\n end\nend\n\nprint idx.join \" \""}, {"source_code": "n = gets.to_i\n\nsolds = gets.split.map{|i| i.to_i}\n\nmin = (solds[0] - solds[-1]).abs\nq = n\nw = 1\ni = 1\nwhile i < n do\n if min > (solds[i-1] - solds[i]).abs then\n min = (solds[i-1] - solds[i]).abs\n q = i\n w = i + 1\n end\n i += 1\nend\n\nputs [q,w].join(\" \")"}, {"source_code": "n = gets.chomp.to_i\ns = gets.chomp\nsa = s.split(/ /)\nsa.map!{|x| x.to_i}\n\nmindiff = (sa[1]-sa[0]).abs\nminidx1 = 1\nminidx2 = 2\n\nfor i in 1..n-1\n\tj = i+1\n\tj = 0 if j >= n\n\twk = (sa[i]-sa[j]).abs\n\tif wk < mindiff\n\t\tmindiff = wk\n\t\tminidx1 = i+1\n\t\tminidx2 = j+1\n\tend\nend\n\nputs minidx1.to_s + \" \" + minidx2.to_s"}, {"source_code": "n=gets.to_i\nv=gets.split.map{|i|i.to_i}\nv<t then\n\t\tm=t\n\t\tr=i\n\tend\n}\nprint r,\" \",r%n+1\n"}, {"source_code": "#!/usr/bin/ruby\ngets;a=gets.split.map(&:to_i)\nr=a.size.times.map{|i|[(a[i]-a[(i+1)%a.size]).abs,i]}.min.pop\nputs \"#{r+1} #{(r+1)%a.size+1}\""}, {"source_code": "num_soldiers = gets.to_i\nsoldiers = gets.split.collect {|i| i.to_i}\nbest = (soldiers[0] - soldiers[-1]).abs\nbest_index = [1,num_soldiers]\nfor i in 0...num_soldiers-1\n\ttemp = (soldiers[i+1] - soldiers[i]).abs\n\tif temp < best\n\t\tbest = temp\n\t\tbest_index = [i+1,i+2]\n\tend\nend\nputs best_index[0].to_s + \" \" + best_index[1].to_s\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split.map(&:to_i)\nx,y=1,1\nz=[(a[0]-a[n-1]).abs]\nfor i in 0..n-2\n\tz.push((a[i]-a[i+1]).abs)\nend\nfor i in 0..z.length-1\n\tif z[i]==z.min\n\t\tif i==0\n\t\t\tputs \"#{n} 1\"\n\t\t\texit\n\t\telse\n\t\t\tputs \"#{i} #{i+1}\"\n\t\t\texit\n\t\tend\n\tend\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map!(&:to_i)\nk = (-1...n-1).min_by {|i| (a[i] - a[i+1]).abs }\nputs \"#{(k+1).zero? ? n : k+1} #{k+2}\""}], "negative_code": [{"source_code": "tot, min, min_index, input = gets.to_i, 20000, -1, gets.split(' ').map{|n| n.to_i}\ninput.each_cons(2).to_a.each_with_index { |(a, b), index| min, min_index = (a - b).abs, index if (((a - b).abs) < min) }\nmin_index = tot - 1 if (min > (input[0] - input[input.length - 1]).abs)\nmax_index = (min_index == tot - 1) ? 0 : min_index + 1\np (min_index + 1).to_s + ' ' + (max_index + 1).to_s"}], "src_uid": "facd9cd4fc1e53f50a1e6f947d78e942"} {"source_code": "def read_array(to)\n gets.strip.split(' ').map(&to)\nend\n\n\n# [1,2], [3,4], (2,3)\n\ngets.strip.to_i.times do\n _ = read_array(:to_i)\n a = read_array(:to_i)\n p = read_array(:to_i).map { |e| e - 1 }.sort\n ranges = []\n p.each_with_index do |e, i|\n if ranges.all? { |r| (r & [e,e+1]).empty? }\n ranges << [e,e+1]\n else\n ranges = ranges.select { |r| (r & [e,e+1]).empty? } +\n [ [[e,e+1], ranges.select { |r| !(r & [e,e+1]).empty? }].flatten.uniq.sort ]\n end\n end\n ranges.each do |r|\n a[r[0]..r[-1]] = a[r[0]..r[-1]].sort\n end\n puts a == a.sort ? \"YES\" : \"NO\"\nend", "positive_code": [{"source_code": "n=gets.to_i\narray = sets = []\n(1..n).each do |x|\n a,b=gets.chomp.split(\" \")\n array=gets.chomp.split(\" \").map(&:to_i)\n sets=gets.chomp.split(\" \").map(&:to_i)\n sets = sets.sort\n s = e = sets[0]\n sets.each do |set|\n if e != set\n array[s-1..e-1] = array[s-1..e-1].sort!\n s = set\n end\n e = set + 1\n end\n array[s-1..e-1] = array[s-1..e-1].sort!\n c = array[0]\n check = false\n array.each do |arr|\n if arr >= c\n c = arr\n else\n print(\"NO\\n\")\n check = true\n break\n end\n end\n print(\"YES\\n\") unless check\nend"}], "negative_code": [{"source_code": "def read_array(to)\n gets.strip.split(' ').map(&to)\nend\n\ngets.strip.to_i.times do\n _ = read_array(:to_i)\n a = read_array(:to_i)\n p = read_array(:to_i).map { |e| e - 1 }\n ranges = []\n p.each do |e|\n found = false\n ranges.map! do |r|\n unless (r & [e, e + 1]).empty?\n found = true\n r = (r + [e, e + 1]).uniq.sort\n else\n r\n end\n end\n unless found\n ranges << [e, e+1]\n end\n end\n ranges.each do |r|\n a[r[0]..r[-1]] = a[r[0]..r[-1]].sort\n end\n puts a == a.sort ? \"YES\" : \"NO\"\nend"}], "src_uid": "e1481b9d940407da75e11355b580f459"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = []\nsum = 0\na.reverse_each do |val|\n\tb.unshift val + sum\n\tsum = b[0] - sum\nend\n\nputs b * \" \"\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\nputs (arr.each_cons(2).map { |i, j| i + j } << arr.last).join(' ')"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nbt=0\nans=[]\nx.reverse.each{|e|\n\tbi=e+bt\n\tans< (n - 1) * (n - 2) / 2 + 1 then\n\tp -1\nelse\n\tw = v == 1 ? 2 : 1\n\tputs \"#{v} #{w}\"\n\ta = [*1..n]\n\ta.delete(w)\n\t[*0..a.size-2].each{|i| puts \"#{a[i]} #{a[i + 1]}\"}\n\tm -= n - 2\n\t[*0..a.size-1].each{|i|\n\t\t[*i+2..a.size-1].each{|j|\n\t\t\texit if (m -= 1) == 0\n\t\t\tputs \"#{a[i]} #{a[j]}\"\n\t\t}\n\t}\nend\n\n", "positive_code": [{"source_code": "def solve(n, m, v)\n if m < n-1\n puts -1\n return\n end\n if m > (n-1)*(n-2)/2 + 1\n puts -1\n return\n end\n other = v % n + 1\n a = (1..n).to_a - [v, other]\n a = [v] + a + [other]\n puts \"#{v} #{other}\"\n m -= 1\n 0.upto(n-2) do |i|\n break if m == 0\n (i+1).upto(n-2) do |j|\n break if m == 0\n puts \"#{a[i]} #{a[j]}\"\n m -= 1\n end\n end\nend\n\nn, m, v = *gets.split(' ').map { |s| s.to_i }\nsolve(n, m, v)\n"}], "negative_code": [{"source_code": "n, m, v = gets.split.map(&:to_i)\nif m < n - 1 || m > (n - 1) * (n - 2) / 2 + 1 then\n\tp -1\nelse\n\tputs \"#{v} #{v == 1 ? 2 : 1}\"\n\ta = [*1..n]\n\ta.delete(v)\n\t[*0..a.size-2].each{|i| puts \"#{a[i]} #{a[i + 1]}\"}\n\tm -= n - 2\n\t[*0..a.size-1].each{|i|\n\t\t[*i+2..a.size-1].each{|j|\n\t\t\texit if (m -= 1) == 0\n\t\t\tputs \"#{a[i]} #{a[j]}\"\n\t\t}\n\t}\nend\n\n"}], "src_uid": "959709bfe7b26a4b9f2e7430350650a9"} {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n k = []\n g = []\n da = Array.new(n, nil)\n pr = Array.new(n, nil)\n married = 0\n n.times do |i|\n k[i], *g[i] = gets.split.map(&:to_i)\n ok = false\n for j in 0...k[i] do\n if pr[g[i][j] - 1].nil?\n da[i] = g[i][j]\n pr[g[i][j] - 1] = i + 1\n ok = true\n break\n end\n end\n married += 1 if ok\n end\n if married < n\n puts \"IMPROVE\"\n puts \"#{da.index(nil) + 1} #{pr.index(nil) + 1}\"\n else\n puts \"OPTIMAL\"\n end\nend\n", "positive_code": [{"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1327/B\n\nrequire 'set'\n\nt = gets.to_i\n\nt.times do\n n = gets.to_i\n\n options = []\n\n n.times do\n options << gets.split(' ').map(&:to_i).drop(1)\n end\n\n choices = Set.new\n first_untaken_princess = nil\n\n options.each_with_index do |op, num|\n first_untaken_princess ||= num + 1 if op.size == 0\n\n op.each_with_index do |prince, n|\n unless choices.include? prince\n choices << prince\n break\n end\n if n + 1 == op.size\n first_untaken_princess ||= num + 1\n end\n end\n end\n\n if first_untaken_princess\n first_untaken_prince = 1\n\n while true do\n if choices.include? first_untaken_prince\n first_untaken_prince += 1\n else\n break\n end\n end\n puts \"IMPROVE\\n#{first_untaken_princess} #{first_untaken_prince}\"\n else\n puts \"OPTIMAL\"\n end\nend\n"}], "negative_code": [], "src_uid": "38911652b3c075354aa8adb2a4c6e362"} {"source_code": "n , m = gets.split.map(&:to_i)\ns = \"\"\nn.times do\n s = gets.strip\nend\narr = s.split(\".\")\n\nans = 0\nfor i in arr\n if i.include? \"B\"\n ans +=1\n end\nend\nputs ans\n", "positive_code": [{"source_code": "rows, cols = gets.split(' ').map(&:to_i)\n(rows-1).times { gets }\n\nparts = 0\npart = false\ngets.chomp.each_char do |ch|\n if ch == 'B'\n part = true if !part\n else\n parts += 1 if part\n part = false\n end\nend\n\nparts += 1 if part\n\nputs parts\n"}], "negative_code": [{"source_code": "n , m = gets.split.map(&:to_i)\ns = \"\"\nn.times do\n s = gets.strip\nend\narr = s.split(\".\")\nputs arr\nans = 0\nfor i in arr\n if i.include? \"B\"\n ans +=1\n end\nend\nputs ans\n"}], "src_uid": "c339795767a174a59225a79023b5d14f"} {"source_code": "\ufeffn = gets.chomp.to_i\nc = gets.chomp.split(\" \").map{|e| e.to_i}\ntables = []\nmap = {}\n1.upto(n) do |y|\n col = gets.chomp.split(\" \").map{|e| e.to_i}\n tables << col\n \n col.each_with_index do |num, x|\n map[num] = [y, x + 1]\n end \nend\nans = []\nk = 0\nidx = 1\nfor i in 1 .. n do\n for j in 1 .. c[i - 1] do\n k += 1\n next if tables[i - 1][j - 1] == k\n \n y = map[k].first\n x = map[k].last\n \n ans << [i, j, y, x]\n \n # swap\n tmp = tables[i - 1][j - 1]\n tables[i - 1][j - 1] = k\n tables[y - 1][x - 1] = tmp \n \n map[k] = [i, j]\n map[tmp] = [y, x] \n end\nend\n\nputs ans.length\nans.each do |line|\n puts line.join(\" \")\nend\n", "positive_code": [{"source_code": "n = gets.to_i\nc = gets.chomp.split.map(&:to_i)\ns = c.inject(&:+)\na = []\nl = []\no = []\nn.times do |i|\n a[i] = gets.chomp.split.map(&:to_i)\n 0.upto(c[i]-1) do |j|\n l[a[i][j]] = [i,j]\n o[i+j] = [] if o[i+j].nil?\n o[i+j].push([i,j])\n end\nend\n\nc = 0\nmoves = []\ncurr = 0\n1.upto(s) do |i|\n curr = curr + 1 if o[curr].empty?\n tr, tc = o[curr].pop\n fr, fc = l[i]\n unless tr == fr && tc == fc\n moves.push([tr+1,tc+1,fr+1,fc+1])\n l[a[fr][fc]] = [tr,tc]\n l[a[tr][tc]] = [fr,fc]\n a[fr][fc], a[tr][tc] = a[tr][tc], a[fr][fc]\n c += 1\n end\nend\nputs c\nc.times do |i|\n puts moves[i].join(\" \")\nend\n"}, {"source_code": "n = gets.to_i\ngets\n\na = Array.new(n) {\n gets.split.map{|x| x.to_i - 1}\n}\n\nb = []\nn.times {|i|\n a[i].each_index {|j|\n b << [i, j]\n }\n}\n\nc = []\n50.times {\n n.times {|i|\n a[i].each_index {|j|\n t = a[i][j]\n next if b[t] == [i, j]\n x, y = *b[t]\n a[i][j], a[x][y] = a[x][y], a[i][j]\n c << [i, j, x, y].map(&:succ)\n }\n}\n}\np c.size\nputs c.map{|i| i * ' '}\n"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\ngets\nt = []\nn.times do\n t << gets.split.map(&:to_i)\nend\nresults = []\nn.times do |i|\n t[i].length.times do |j|\n mi, mj = i, j\n (i..(n - 1)).each do |ni|\n (j..(t[ni].length - 1)).each do |nj|\n if t[ni][nj] < t[mi][mj]\n mi, mj = ni, nj\n end\n end\n end\n if mi != i || mj != j\n results.push([i, j, mi, mj])\n t[i][j], t[mi][mj] = t[mi][mj], t[i][j]\n end\n end\nend\nputs results.length\nresults.each do |r|\n puts r.map { |x| x + 1 }.join(\" \")\nend"}], "negative_code": [{"source_code": "n = gets.to_i\ngets\n\na = Array.new(n) {\n gets.split.map{|x| x.to_i - 1}\n}\n\nb = []\nn.times {|i|\n a[i].each_index {|j|\n b << [i, j]\n }\n}\n\nc = []\nn.times {|i|\n a[i].each_index {|j|\n t = a[i][j]\n next if b[t] == [i, j]\n x, y = *b[t]\n a[i][j], a[x][y] = a[x][y], a[i][j]\n c << [i, j, x, y].map(&:succ)\n }\n}\np c.size\nputs c.map{|i| i * ' '}\n"}, {"source_code": "\ufeffn = gets.chomp.to_i\nc = gets.chomp.split(\" \").map{|e| e.to_i}\ntables = []\nmap = {}\n1.upto(n) do |y|\n col = gets.chomp.split(\" \").map{|e| e.to_i}\n tables << col\n \n col.each_with_index do |num, x|\n map[num] = [y, x + 1]\n end \nend\nans = []\np map\nk = 0\nidx = 1\nfor i in 1 .. n do\n for j in 1 .. c[i - 1] do\n k += 1\n next if tables[i - 1][j - 1] == k\n \n y = map[k].first\n x = map[k].last\n \n ans << [i, j, y, x]\n \n # swap\n tmp = tables[i - 1][j - 1]\n tables[i - 1][j - 1] = k\n tables[y - 1][x - 1] = tmp \n \n map[k] = [i, j]\n map[tmp] = [y, x] \n end\nend\n\nputs ans.length\nans.each do |line|\n puts line.join(\" \")\nend\n"}], "src_uid": "62df8b1821558bea910f422591618e29"} {"source_code": "n, d = gets.chomp.split.map(&:to_i)\nx = gets.chomp.split.map(&:to_i)\na = {}\nx.each do |i|\n\ta[i-d] =0; a[i+d] = 0;\nend\n\nac = 0\na.keys.each do |i|\n\tflag = 1\n\tx.each do |j|\n\t\tflag = 0 if ((i-j).abs < d)\n\tend\n\n\tac += flag\nend\n\nprint ac", "positive_code": [{"source_code": "require 'set'\n\ndef solution\n m, d = read_ints\n cs = read_ints\n\n cities = Set.new\n\n cs.each.with_index do |c, i|\n before = c - d\n after = c + d\n\n cities << before if i == 0 || before - cs[i-1] >= d\n cities << after if i == cs.size-1 || cs[i+1] - after >= d\n end\n\n puts cities.size\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"}, {"source_code": "N, D = gets.split.map(&:to_i)\nxs = gets.split.map(&:to_i)\n\nans = 2\n(N-1).times do |i|\n if xs[i] < xs[i+1] - 2*D\n ans += 2\n elsif xs[i] == xs[i+1] - 2*D\n ans += 1\n end\nend\nputs ans"}, {"source_code": "n, d = gets.strip.split.map(&:to_i)\nary = gets.strip.split.map(&:to_i)\nary.sort!\n\npossible_locations = []\nary.each do |c|\n possible_locations << (c+d)\n possible_locations << (c-d)\nend\npossible_locations.uniq!\nans = 0\npossible_locations.each do |nc|\n # puts nc\n # puts ary.map{|oc| (nc-oc).abs >= d }.inspect\n if ary.map{|oc| (nc-oc).abs }.min == d\n # puts nc\n ans += 1\n end\nend\nputs ans"}, {"source_code": "$n,$d=gets.split\n$n,$d=$n.to_i,$d.to_i\na=gets.split\ni,ans,len=0,0,a.length\ndef test(val,id)\n\tyield id,val+$d\n\tyield id,val-$d\nend\na.each do |c|\n\ttest(c.to_i,i){|id,pos| \n\t\t\tflag=1\n\t\t\tif id>0 and pos-a[id-1].to_i<$d \n\t\t\tflag=0\n\t\t\tend\n\t\t\tif id coordinates[i] + d\n count += 1\n end\n end\nend\n\nputs count\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\ncities = gets.split.map(&:to_i)\n\ncount = 2\n\ncities.each_cons(2) do |city1, city2|\n \n if city1 + d < city2 - d\n count += 2\n elsif city1 + d == city2 - d\n count += 1\n end \n\nend\n\nputs count"}], "negative_code": [{"source_code": "n,d = STDIN.readline.strip.split(/\\s+/).map(&:to_i)\ncoordinates = STDIN.readline.strip.split(/\\s+/).map(&:to_i)\n\ncount = 2\n(0..coordinates.length - 2).each do |i|\n if coordinates[i] + d == coordinates[i+1] - d\n count += 1\n else\n if coordinates[i] + d < coordinates[i+1]\n count += 1\n end\n if coordinates[i-1] - d > coordinates[i]\n count += 1\n end\n end\nend\n\nputs count\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\ncities = gets.split.map(&:to_i)\n\ncount = 2\n\ncities.each_cons(3) do |city1, city2, city3|\n \n if city2 - d > city1 + d\n count += 1\n end\n if city2 - d == city1 + d\n count += 1\n end\n if city2 + d < city3 - d\n count += 1\n end\n\nend\n\nif cities.count == 1\n puts '2'\nelse\n if cities[0] + d < cities[1] - d\n count += 1\n end\n if cities[n - 2] + d < cities[n - 1] - d\n count += 1\n end\n\n puts count\nend"}], "src_uid": "5babbb7c5f6b494992ffa921c8e19294"} {"source_code": "n = STDIN.readline.to_i\nnumbers = STDIN.readline.strip.split(/\\s+/).map(&:to_i)\n\nindices = []\n(0..numbers.length - 1).each do |i|\n indices << i if numbers[i] == 1\nend\nindices << numbers.length\n\noutputs = []\n(0..indices.length - 2).each do |i|\n outputs << indices[i + 1] - indices[i]\nend\n\nputs outputs.length\nputs outputs.join(' ')\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\nz = 0\ncount = 0\nac = []\na.each_with_index do |x, i|\n\tif x == z + 1\n\t\tz += 1\n\t\tnext\n\telse\n\t\tac << z\n\t\tcount +=1\n\t\tz = x\n\tend\nend\n\nac << z\nputs count + 1\nputs ac.join(\" \")"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nans = a.chunk_while { _1 < _2 }.map(&:size)\nputs ans.size, ans.join(\" \")\n"}, {"source_code": "gets;a=(gets.split.map(&:to_i)+[1]).each_cons(2).select{|x,y|x>=y}.map{|x,y|x};p a.size;puts a*' '"}, {"source_code": "gets\nnumbers = gets.split.map(&:to_i)\n\nstair_sizes = []\ncrt = 0\n\nnumbers.each do |n|\nif n == crt + 1\n crt += 1\nelse\n stair_sizes.push crt\n crt = 1\nend\nend\nstair_sizes.push crt\n\np stair_sizes.size\nputs stair_sizes.join ' '\n"}, {"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i)\nans = []\nas.each do |a|\n if a == 1\n ans.push(a)\n else\n ans[-1] = a\n end\nend\nputs ans.length\nputs ans.join(' ')"}, {"source_code": "t = gets.to_i\nary = gets.strip.split.map(&:to_i)\n\nif t==1\n puts \"1\\n1\"\nelse\n steps = []\n 0.upto(t-2).each do |x|\n steps << ary[x] if ary[x+1]==1\n end\n steps << ary[-1]\n puts steps.size\n puts steps.join(\" \")\nend"}, {"source_code": "number_of_elems = gets.strip.to_i\narray = gets.strip.split.to_a.collect { |val| val.to_i }\nanswer = []\n(1...array.size).each do |i|\n answer << array[i-1] if array[i] <= array[i-1]\nend\nanswer << array[-1]\nputs answer.size\nputs answer.join(' ')\n"}, {"source_code": "n = gets.to_i\nsteps = gets.split.map(&:to_i)\nstepss = []\nt = []\nsteps.each do |step|\n if step == 1\n stepss << t unless t.empty?\n t = [1]\n else\n t << step\n end\nend\nstepss << t\nputs stepss.count\nputs stepss.map { |a| a.max }.join(\" \")"}, {"source_code": "\nx = gets.chomp.to_i\nstairways = gets.strip.split.map(&:to_i)\nres = 1\narr = Array.new\nfor i in 1 ... x\n if stairways[i] > stairways[i-1]\n res +=1\n else if !(stairways[i] > stairways[i-1])\n arr.push(res)\n res=1\n end\n end\nend\narr.push(res)\nputs arr.size\nputs arr.join(' ')\n"}, {"source_code": "number = gets().to_i\nlist = gets().chomp.split.map(&:to_i)\n\nans = []\ncount = 0\nfor i in 0...list.length\n\n if(list[i+1] == 1 || i == list.length-1)\n ans.push(list[i])\n end\n if(list[i] == 1)\n count = count+1\n end\nend\n\nputs count\nfor i in 0...ans.length\n print ans[i]\n print \" \"\nend\n"}, {"source_code": "gets\nt = []\nt << gets.split.map{|x| x.to_i}.inject(0) do |s, x|\n t << s if x == 1 && s > 0\n x\nend\nputs(t.size, t.join(' '))\n\n"}, {"source_code": "n = gets\ninput = gets\n\n#TEST INPUTS\n# input = \"1 2 3 1 2 3 4\"\n#2\n#3 4 \n\n# input = \"1 1 1 1\"\n# 4\n# 1 1 1 1 \n\n# input = \"1 2 3 4 5\"\n# 1\n# 5 \n\n# input = \"1 2 1 2 1\"\n# 3\n# 2 2 1 \n\ncounts = input.split(\" \").map(&:to_i)\n\nlast = 0\noutput = []\ncounts.each.with_index do |a_count, index|\n\tif a_count <= last\n\t\t#a new max step is added\n\t\toutput << counts[index - 1]\n\tend\n\tlast = a_count\nend\n\noutput << counts.last\n\nputs output.count\nputs output.join(\" \")"}, {"source_code": "t = gets.to_i\nstairs = gets.chomp.split(\" \").map(&:to_i)\n\nno = 1\narr = []\nprev = 0\n\nstairs.each do |x|\n if x<=prev\n no+=1\n arr.push prev\n end\n\n prev = x\nend\n\narr.push stairs[-1]\nputs no\nprint arr*\" \"\nputs\n"}, {"source_code": "gets\nn = gets.split.map { |x| x.to_i }\nk = []\nc = 0\nn[1, n.size-1].each_with_index do |x,i|\n if x == 1\n k << n[i]\n c += 1\n end\nend\nk.push(n.last)\nc += 1\nputs c\nputs(k.join ' ')\n"}], "negative_code": [{"source_code": "gets;puts (gets.split.map(&:to_i)+[1]).each_cons(2).select{|x,y|x>=y}.map{|x,y|x}*' '"}, {"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i)\nans = []\nas.each do |a|\n if a == 1\n ans.push(a)\n else\n ans[-1] = a\n end\nend\nputs ans.join(' ')"}], "src_uid": "0ee86e75ff7a47a711c9eb41b34ad1a5"} {"source_code": "def find_ugliness(heights, building_num)\r\n sum = heights.sum\r\n remainder = sum.modulo(building_num)\r\n\r\n # move makes no effect when difference is 0 or 1\r\n if remainder == 0\r\n return 0\r\n else\r\n return 1\r\n end\r\n\r\nend\r\n\r\ntest_case_num = gets.chomp.to_i\r\n\r\nugliness_array = []\r\n\r\ntest_case_num.times do |idx|\r\n # read input\r\n building_num = gets.chomp.to_i\r\n heights = gets.chomp.strip.split(\" \").map!(&:to_i)\r\n\r\n ugliness_array.append(find_ugliness(heights, building_num))\r\n\r\nend\r\n\r\nugliness_array.each do |ugliness_single|\r\n puts ugliness_single\r\nend\r\n", "positive_code": [{"source_code": "t = gets.chomp\r\nfor i in 0..t.to_i-1\r\n n = gets.chomp.to_i\r\n arr = gets.chomp.split(\" \")\r\n arr = arr.map{|n| n.to_i}\r\n if arr.sum % n == 0\r\n puts 0\r\n else\r\n puts 1\r\n end\r\nend"}], "negative_code": [], "src_uid": "644ef17fe304b090e0cf33a84ddc546a"} {"source_code": "#idea_copied_From_ToErr_Vaia\n\ndef call(ind,a) \n\tr = 30**9\n\tl = -2 \n\tfor i in 0...a.size \n\t\tif(i != ind)\n\t\t\tr = [r,a[i].r].min\n\t\t\tl = [l,a[i].l].max\n\t\tend\n\tend\n\treturn r-l\nend \n\npair = Struct.new(:l,:r)\na = []\nn = STDIN.readline.to_i\nfor i in 1..n \n\tp = STDIN.readline.split(\" \")\n\ts = pair.new(p[0].to_i,p[1].to_i)\n\ta << s \nend\na.sort! {|z,b| z.r <=> b.r}\n\nr = 30**9 \nl = -1 \nfor i in 0...n \n\tif a[i].r < r \n\t\tr = a[i].r \n\t\tri = i \n\tend\n\tif a[i].l > l \n\t\tl = a[i].l \n\t\tli = i \n\tend\nend\n\nans = 0\nans = [ans,call(li,a)].max\nans = [ans,call(ri,a)].max \n\nprint ans ", "positive_code": [{"source_code": "#idea_copied_From_ToErr_Vaia\n#but_not_sorted\ndef call(ind,a) \n\tr = 30**9\n\tl = -2 \n\tfor i in 0...a.size \n\t\tif(i != ind)\n\t\t\tr = [r,a[i].r].min\n\t\t\tl = [l,a[i].l].max\n\t\tend\n\tend\n\treturn r-l\nend \n\npair = Struct.new(:l,:r)\na = []\nn = STDIN.readline.to_i\nfor i in 1..n \n\tp = STDIN.readline.split(\" \")\n\ts = pair.new(p[0].to_i,p[1].to_i)\n\ta << s \nend\n# a.sort! {|z,b| z.r <=> b.r}\n\nr = 30**9 \nl = -1 \nfor i in 0...n \n\tif a[i].r < r \n\t\tr = a[i].r \n\t\tri = i \n\tend\n\tif a[i].l > l \n\t\tl = a[i].l \n\t\tli = i \n\tend\nend\n\nans = 0\nans = [ans,call(li,a)].max\nans = [ans,call(ri,a)].max \n\nprint ans "}], "negative_code": [], "src_uid": "b50df0e6d91d538cd7db8dfdc7cd5266"} {"source_code": "a,b,n = gets.split.collect{|t| t.to_i}\n\n\nsolved = false\nfor i in 0..9\n\tsolved |= (10*a + i) % b == 0\n\tif solved\n\t\tprint a, i\n\t\tbreak\n\tend\nend\n\nif solved\n\t(n-1).times do |i|\n\t\tprint 0\n\tend\nelse\n\tprint -1\nend\nputs", "positive_code": [{"source_code": "# your code goes here\na, b, n = gets.split(' ').map { |_| _.to_i }\nfor i in 0..9\n d=a*10+i\n if d%b == 0\n print \"#{d}\"\n for j in 0..n-2\n print 0\n end\n exit\n end\nend\nputs -1"}, {"source_code": "st = gets.split\na = st[0].to_i\nb = st[1].to_i\nn = st[2].to_i\n\ni = 1\nwhile i <= n && (a != -1)\n if a % b == 0 then\n a = (a.to_s + \"0\"*(n-i+1)).to_i\n i = n + 1 \n else\n t = true\n k = 0 \n while k < 10 && t do\n q = (a.to_s + k.to_s).to_i\n if q % b == 0 then\n t = false\n a = q \n end \n k += 1 \n end \n if t then\n a = -1\n end \n end \n i += 1 \nend\n\nputs a\n"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\n\n\ndef op(a, b)\n for i in 0 .. 9 do\n c = a * 10 + i\n return c if c % b == 0\n end\n \n -1\nend\n\na, b, n = gets.chomp.split(\" \").map{|n| n.to_i}\n\nc = op(a, b)\n\nif c == -1\n puts -1\nelse\n puts c.to_s + \"0\" * (a.to_s.length + n - c.to_s.length)\nend\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\nuntil n == 0\n a *= 10\n if a%b != 0\n if b-(a%b) > 9\n print -1\n exit\n else\n a += b-(a%b)\n end\n else\n a *= 10**(n-1)\n break\n end\n n -= 1\nend\nprint a"}, {"source_code": "c=gets.chomp.scan(/\\w+/)\nt=-1\nfor i in 0..9 do\n if (c[0].to_i*10+i)%c[1].to_i==0 then t=i end\nend\nif (t==-1) then puts \"-1\" \nelse \nprint c[0],t\n2.upto(c[2].to_i) {print 0}\nputs\nend"}, {"source_code": "#!/usr/bin/ruby1.9\n\nin_file = STDIN\n\na, b, n = in_file.readline.split.collect {|s| s.to_i }\n\n(0..9).each do |d|\n\tcandidate = 10*a+d\n\tif candidate%b == 0\n\t\tpadding = Array.new(n-1, '0').join('')\n\t\tputs '%s%s' % [candidate, padding]\n\t\texit\n\tend\nend\nputs -1\n\n"}, {"source_code": "infile = STDIN\na, b, n = infile.readline.split.map { |x| x.to_i }\n\nappend = (0..9).find { |i| (a*10+i)%b == 0 }\nif append\n puts a.to_s + append.to_s + \"0\"*(n-1)\nelse\n puts -1\nend"}, {"source_code": "a,b,n = gets.split\na = a.to_i\nb = b.to_i\nn = n.to_i\n\ndef solve(a,b,n)\n\treturn \"\" << (a.to_s + \"0\"*n) if a*10%b==0\n\n\tif (a*10 + (b - a*10%b) ).to_s.start_with? a.to_s then\n\t\treturn solve(a*10+(b-a*10%b),b,n-1);\n\telse\n\t\treturn -1;\n\tend\nend\n\nputs solve(a,b,n)\n"}, {"source_code": "def run(line)\n a, b, n = line.split(\" \").map {|x| x.to_i}\n\n prev_mod = a % b\n val = [a]\n n.times do |i|\n flag = true\n 10.times do |j|\n mod = (prev_mod * 10 + j) % b\n if mod == 0\n flag = false\n prev_mod = mod\n val << j\n break\n end\n end\n\n return \"-1\" if flag\n end\n\n val.join\nend\n\nif $0 == __FILE__\n ARGF.readlines.each do |line|\n puts run(line)\n end\nend\n"}, {"source_code": "a,b,n = gets.split\na = a.to_i\nb = b.to_i\nn = n.to_i\n\nw = (b-a*10%b) %b\n\nif w < 10 then\n\tputs \"\" << a.to_s << w.to_s << \"0\"*(n-1)\nelse\n\tputs -1\nend\nexit\n\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\ni = (0..9).find{ |x| (a*10+x)%b == 0}\nputs i ? \"#{a*10+i}#{'0'*(n-1)}\" : -1"}, {"source_code": "a, b, n = gets.chop!.split.map(&:to_i)\n\nret = -1\n(0..9).each do |d|\n if (a * 10 + d) % b == 0 then\n ret = d\n end\nend\n\nif ret == -1 then\n puts \"-1\"\nelse\n ret = (a * 10 + ret).to_s + \"0\" * (n - 1)\n puts ret\nend"}, {"source_code": "a, b, n = gets.split.map { |x| x.to_i }\n\nbegin\n\t10.times do |i|\n\t\tif (a * 10 + i) % b == 0\n\t\t\traise i.to_s\n\t\tend\n\tend\nrescue Exception => x\n\tputs a.to_s + x.message + '0' * (n - 1)\nelse\n\tputs -1\nend"}, {"source_code": "a=gets.chomp.split(\" \")\nf=a[0]\nb=a[1].to_i\nn=a[2].to_i\ntrig=0\n0.upto(9) do |i|\nif ((f+\"#{i}\").to_i)%b==0\nf=(f+\"#{i}\")\nn-=1\ntrig=1\nbreak\nend\nend\nif trig==1\nf=f+\"0\"*n\nputs f\nelse \nputs \"-1\"\nend"}, {"source_code": "a, b, n = gets.split.map{|i| i.to_i}\n\ni = (0..9).find {|i| (a*10+i)%b == 0 }\nans = i ? \"#{a*10+i}#{'0'*(n-1)}\" : \"-1\"\n\nputs ans\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\n\nappend = (0..9).find { |i| (a * 10 + i) % b == 0 }\nif append\n puts (a * 10 + append).to_s + \"0\" * (n - 1)\nelse\n puts -1\nend"}, {"source_code": "a,b,n = gets.chomp.split(\" \").collect {|x| x.to_i}\n\nif b>10\n\tp = -1\n\t(0..9).each{|k|\n\t\tif (10*a+k)%b == 0\n\t\t\tp=k\n\t\tend\n\t}\n\tif p==-1\n\t\tputs -1\n\telse\n\t ss = \"0\"*(n-1)\n\t\tputs \"#{10*a+p}#{ss}\"\n\tend\nend\n\nif b<=10\n\tp = -1\n\t(0..9).each{|k|\n\t\tif (10*a+k)%b == 0\n\t\t\tp=k\n\t\tend\n\t}\n\ta=10*a+p\n\ts = (b%10).to_s*(n-1)\n\tputs \"#{a}#{s}\"\nend"}, {"source_code": "a, b, n = gets.split.collect{|i| i.to_i}\n(0...10).each do |i|\n if (a*10+i)%b==0\n print a, i, \"0\"*(n-1), \"\\n\"\n exit\n end\nend\nputs -1\n"}, {"source_code": "a,b,n=gets.split.map {|i| i.to_i}\n\na*=10\n\nunless a%b==0\n if b-a%b<10\n a+=b-a%b\n else\n puts '-1'\n exit\n end\nend\n\na*=(10**(n-1))\nputs a\n"}], "negative_code": [{"source_code": "st = gets.split\na = st[0].to_i\nb = st[1].to_i\nn = st[2].to_i\n\ni = 1\nwhile i <= n && (a != -1)\n t = true\n k = 1 \n while k < 10 && t do\n q = (a.to_s + k.to_s).to_i\n if q % b == 0 then\n t = false\n a = q \n end \n k += 1 \n end \n if t then\n a = -1\n end \n i += 1 \nend\n\nputs a"}, {"source_code": "st = gets.split\na = st[0].to_i\nb = st[1].to_i\nn = st[2].to_i\n\ni = 1\nwhile i <= n && (a != -1)\n if a % b == 0 then\n a = (a.to_s + \"0\"*(n-i+1)).to_i\n i = n + 1 \n else\n t = true\n k = 1 \n while k < 10 && t do\n q = (a.to_s + k.to_s).to_i\n if q % b == 0 then\n t = false\n a = q \n end \n k += 1 \n end \n if t then\n a = -1\n end \n end \n i += 1 \nend\n\nputs a\n"}, {"source_code": "st = gets.split\na = st[0].to_i\nb = st[1].to_i\nn = st[2].to_i\n\ni = 1\nwhile i <= n && (a != -1)\n if a % b == 0 then\n a = (a.to_s + \"0\"*(n-i)).to_i\n i = n + 1 \n else\n t = true\n k = 1 \n while k < 10 && t do\n q = (a.to_s + k.to_s).to_i\n if q % b == 0 then\n t = false\n a = q \n end \n k += 1 \n end \n if t then\n a = -1\n end \n end \n i += 1 \nend\n\nputs a\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\nuntil n == 0\n a *= 10\n if a%b != 0\n if b-(a%b) > 9\n print -1\n exit\n else\n a += b-(a%b)\n end\n else\n a *= 10**n\n break\n end\n n -= 1\nend\nprint a"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\nuntil n == 0\n a *= 10\n if b-(a%b) > 9\n print -1\n exit\n else\n a += b-(a%b)\n end\n n -= 1\nend\nprint a"}, {"source_code": "#!/usr/bin/ruby1.9\n\nin_file = STDIN\n\na, b, n = in_file.readline.split.collect {|s| s.to_i }\n\nleft = n\n\n(1..n).each do |i|\n\tbest = -1\n\t(0..9).each do |d|\n\t\tcandidate = 10*a + d\n\t\tif candidate%b == 0\n\t\t\tbest = candidate\n\t\t\tbreak\n\t\tend\n\tend\n\tif best == -1\n\t\tputs -1\n\t\texit\n\tend\n\ta = best\n\tleft -= 1\n\tif i == 5040\n\t\ts = a.to_s\n\t\ttail = s[-5040..-1]\n\t\twhile left >= 5040\n\t\t\ts += tail\n\t\t\tleft -= 5040\n\t\tend\n\t\tif left > 0\n\t\t\ts += tail[-left..-1]\n\t\tend\n\t\tputs s\n\t\texit\n\tend\nend\nputs a\n"}, {"source_code": "infile = STDIN\n# infile = File.open(\"1.txt\")\na, b, n = infile.readline.split.map { |x| x.to_i }\nappend = (0..9).find { |i| (a*10+i)%b == 0 }\nputs a.to_s + append.to_s + \"0\"*(n-1); exit if append\nputs -1"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\no = a\ni = 1\n8.times do\n break if a%b == 0\n d = (a.to_s + i.to_s).to_i\n a = d if d%b == 0\n i += 1\nend\nputs a%b == 0 ? a.to_s.ljust(n+1, \"0\") : -1"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\no = a\ni = 1\n8.times do\n break if a%b == 0\n d = (a.to_s + i.to_s).to_i\n a = d if d%b == 0\n i += 1\nend\nputs a%b == 0 ? a * (10**(n-1)) : -1"}, {"source_code": "a, b, n = gets.chop!.split.map(&:to_i)\n\nret = -1\n(0..9).each do |d|\n if (a * 10 + d) % b == 0 then\n ret = d\n end\nend\n\nif ret == -1 then\n puts \"-1\"\nelsif b <= 5 or b == 10 or n == 1 then\n ret = (a * 10 + ret).to_s + b.to_s * (n - 1)\n puts ret\nelse\n puts \"-1\"\nend\n"}, {"source_code": "a, b, n = gets.chop!.split.map(&:to_i)\n\nret = -1\n(0..9).each do |d|\n if (a * 10 + d) % b == 0 then\n ret = d\n end\nend\n\nif ret == -1 then\n puts \"-1\"\nelsif b <= 5 or b == 10 or n == 1 then\n b = b % 10\n ret = (a * 10 + ret).to_s + b.to_s * (n - 1)\n puts ret\nelse\n puts \"-1\"\nend\n"}, {"source_code": "a, b, n = gets.chop!.split.map(&:to_i)\n\nret = -1\n(0..9).each do |d|\n if (a * 10 + d) % b == 0 then\n ret = d\n end\nend\n\nif ret == -1 then\n puts \"-1\"\nelsif b <= 5 or n == 1 then\n ret = (a * 10 + ret).to_s + b.to_s * (n - 1)\n puts ret\nelse\n puts \"-1\"\nend"}, {"source_code": "a, b, n = gets.split.map{|i| i.to_i}\n\ni = (0...9).find {|i| (a*10+i)%b == 0 }\nputs i ? \"#{a*10+i}#{'0'*(n-1)}\" : \"-1\"\n"}, {"source_code": "a, b, n = gets.split.map(&:to_i)\n\nn.times do\n found = 1.upto(9).find do |i|\n if (a * 10 + i) % b == 0\n a = a * 10 + i\n end\n end\n if !found\n puts -1\n exit\n end\nend\n\np a\n"}, {"source_code": "a,b,n = gets.chomp.split(\" \").collect {|x| x.to_i}\nif b>10 and n>1\n puts -1\n exit\nend\n\nif b>10\n\tp = -1\n\t(0..9).each{|k|\n\t\tif (10*a+k)%b == 0\n\t\t\tp=k\n\t\tend\n\t}\n\tif p==-1\n\t\tputs -1\n\telse\n\t\tputs (10*a+p)\n\tend\nend\n\nif b<=10\n\tp = -1\n\t(0..9).each{|k|\n\t\tif (10*a+k)%b == 0\n\t\t\tp=k\n\t\tend\n\t}\n\ta=10*a+p\n\ts = (b%10).to_s*(n-1)\n\tputs \"#{a}#{s}\"\nend"}, {"source_code": "a,b,n=gets.split.map {|i| i.to_i}\n\na*=10\n\nunless a%b==0\n if a-a%b<10\n a+=a-a%b\n else\n puts '-1'\n exit\n end\nend\n\na*=(10**(n-1))\nputs a\n"}, {"source_code": "a,b,n=gets.split.map {|i| i.to_i}\n\n(1..n).each do\n a*=10\n unless a%b==0\n if b-a%b<10\n a+=b-a%b\n else\n puts '-1'\n exit!(0)\n end\n end\nend\n\nputs a\n"}, {"source_code": "a,b,n = gets.split\na = a.to_i\nb = b.to_i\nn = n.to_i\n\ndef solve(a,b,n)\n\treturn \"\" << (a.to_s + \"0\"*n) if a%b==0\n\n\tif (a*10 + (b - a*10%b) ).to_s.start_with? a.to_s then\n\t\treturn solve(a*10+(b-a*10%b),b,n-1);\n\telse\n\t\treturn -1;\n\tend\nend\n\nputs solve(a,b,n)\n"}, {"source_code": "a,b,n = gets.split\na = a.to_i\nb = b.to_i\nn = n.to_i\n\nw = (b-a*10%b) %b\n\nif w < 10 then\n\tputs a.to_s << w <<\"0\"*(n-1) \nelse\n\tputs -1\nend\n"}, {"source_code": "a,b,n = gets.split\na = a.to_i\nb = b.to_i\nn = n.to_i\n\ndef solve(a,b,n)\n\treturn \"\" << (a.to_s + \"0\"*n) if a%b==0\n\n\tif (a*10 + (b - a%10%b) ).to_s.start_with? a.to_s then\n\t\treturn solve(a*10+(b-a*10%b),b,n-1);\n\telse\n\t\treturn -1;\n\tend\nend\n\nputs solve(a,b,n)\n"}, {"source_code": "a,b,n = gets.split\nn.to_i.times do |i|\n\t0.upto(9) do |u|\n\t\ta << u.to_s\n\t\tif a.to_i%b.to_i==0 then\n\t\t\tputs a\n\t\t\texit\n\t\tend\n\tend\nend\nputs \"-1\"\n"}, {"source_code": "a,b,n = gets.split.collect{|t| t.to_i}\n\n\nsolved = false\nfor i in 0..9\n\tsolved |= (10*a + i) % b == 0\n\tif solved\n\t\tprint a, i\n\t\tbreak\n\tend\nend\n\nif solved\n\tn.times do |i|\n\t\tprint 0\n\tend\nelse\n\tprint -1\nend\nputs"}], "src_uid": "206eb67987088843ef42923b0c3939d4"} {"source_code": "\nn = gets.chomp!.to_i\ns = gets.chomp!\n\nh = Hash.new(0)\n(0...s.length).each do |i|\n h[s[i]] += 1\n #puts s[i], h[s[i]]\nend\nflag = 1\nc = ''\nh.each do |i,j|\n if flag == 1 and j % n == 0 \n (j/n).times do c += i.chr end\n else\n flag = -1\n end\nend\nif flag == -1 \n puts -1\nelse \n res = ''\n n.times do res += c end\n puts res\nend", "positive_code": [{"source_code": "require 'set'\n\nif $DEBUG \n $stdin = File.new('input', 'r')\n $stdout = File.new('output', 'w') \nend\n\n$k, $s = gets.to_i, gets.chop\n$h = Hash.new\n\ndef f()\n $h.keys.map { |e| if $h[e] % $k != 0 then return false end }\n t = 0\n $h.keys.map { |e| t += ( $h[e] / $k ) }\n if t*$k != $s.size then return false end\n return true\nend\n\n0.upto($s.size-1) { |i| if $h.include?($s[i].chr) then $h[ $s[i].chr ] += 1 else $h[ $s[i].chr ] = 1 end }\n\nif !f \n puts \"-1\"\nelse\n str = \"\"\n $h.keys.map{ |e| str += e*( $h[e] / $k ) }\n str *= $k\n puts str\nend\n"}, {"source_code": "k=gets.to_i\nstr=[]\ngets.chomp.each_char{|a| str.push a}\nu=str.uniq\nif !u.collect{|a| str.count a}.select{|a| a%k !=0 }.empty?\n puts -1\nelse\n out=\"\"\n repeat={}\n u.each{|a| repeat[a]= (str.count a)/k} \n for i in 1..k\n u.each do |a|\n for i in 1..repeat[a]\n out=out+a\n end\n end\n end\n puts out\nend\n"}, {"source_code": "k, s = gets.to_i, gets.strip\n\na = {}\ns.split(//).each do |c|\n a[c] = 0 unless a.include? c\n a[c] += 1 \nend\n\nif a.all?{|i, j| j % k == 0}\n t = a.map{|i, j| i * (j / k)}.join\n puts t * k\nelse\n puts -1\nend\n"}, {"source_code": "k = gets.to_i\ns = gets\n\narr = {}\ns.chomp.split('').each do |val|\n arr[val] = 0 unless arr[val]\n arr[val] += 1\nend\n\nans = ''\n\nflag = true\narr.each do |key, val|\n if (val % k) != 0\n flag = false\n break\n end\n ans += (key * (val / k))\nend\n\nif flag\n puts ans * k\nelse\n puts -1\nend\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\ns = gets.chomp.split(//)\ncounter = {}\nfor c in s\n counter[c] ||= 0\n counter[c] += 1\nend\n\nbroken = false\nfor (k, v) in counter\n if v % n != 0\n broken = true\n break\n end\nend\n\nif broken\n puts \"-1\"\nelse\n base = \"\"\n for (k, v) in counter\n base += k * (v/n)\n end\n puts base*n\nend\n"}, {"source_code": "t = gets.to_i\ns = gets.chomp\nh = s.split(//).reduce(Hash.new(0)) { |h, x| h[x] += 1; h}\nunless h.all? { |x, y| (y % t).zero? }\n puts -1\nelse\n puts h.to_a.map { |x, y| x * (y / t) }.join * t\nend"}, {"source_code": "k = gets.to_i\ns = gets.chomp\nh = Hash.new(0)\ns.each_char{|x| h[x] += 1}\na = []\nif h.all?{|i, j| j % k == 0}\n h.each do |i, j|\n (j / k).times{a << i}\n end\n puts a.join * k\nelse\n puts -1\nend\n"}, {"source_code": "k = gets.to_i\ns = gets.chomp\nh = Hash.new(0)\ns.each_char{|x| h[x] += 1}\nif h.all?{|i, j| j % k == 0}\n puts h.map{|i, j| i * (j / k)}.join * k\nelse\n puts -1\nend\n"}, {"source_code": "k = gets.to_i\ns = gets.strip.split //\nif s.length%k != 0\n puts -1\n exit\nend\nletters = {}\n\ns.each do |letter|\n if letters.has_key? letter\n letters[letter] += 1\n else\n letters[letter] = 1\n end\nend\n\nletters.each do |letter, value|\n if value%k != 0\n puts -1\n exit\n end\nend\n\npattern = []\nletters.sort.each do |letter,value|\n pattern << letter*(value/k)\nend\nputs pattern.join*k\n"}, {"source_code": "k = gets[0..-2].to_i\ns = gets[0..-2]\nhsh = Hash.new(0)\ns.each_char { |ch| hsh[ch] = hsh[ch] + 1 }\nok = true\nfor i in ('a'.ord)..('z'.ord)\n if hsh[i.chr] > 0 and (hsh[i.chr] % k) != 0\n ok = false\n break\n end\nend\nif !ok\n print -1\nelse\n 1.upto(k) do |i|\n (('a'.ord)..('z'.ord)).each do |x|\n print Array.new(hsh[x.chr]/k,x.chr).join('')\n end\n end\nend"}, {"source_code": "i = gets.to_i\ns = gets.chomp\n\n\ndef fnc(s,i)\n schar = s.split(//).uniq\n snum = []\n schar.map{|k| snum << s.count(k)}\n snum.each do |l|\n return puts '-1' if l % i != 0\n end\n result = ''\n schar.each_with_index do |k,index|\n (snum[index]/i).times { result += k }\n end\n res = result\n (i-1).times {res += result}\n puts res\nend\n\nfnc(s,i)"}, {"source_code": "hs = Hash.new 0\nn = gets.to_i\ngets.chomp.split(//).map{|x| hs[x]+=1}\nif hs.any?{|k,v| v%n!=0}\n puts -1\nelse\n puts hs.map{|k,v| k * (v/n)}.join * n\nend"}, {"source_code": "k = gets.to_i\nstr = gets.chomp\ns = str.split(\"\")\ns = s.uniq\n\nnum = {}\nt = true\ns.each do |i|\n n = -1\n num[i] = 0\n while n = str.index(i, n+1) do\n num[i] += 1\n end\n if num[i] % k != 0 then\n t = false\n else\n num[i] = num[i]/k\n end\nend\n\nif t then\n ans = \"\"\n s.each do |i|\n ans += i*num[i]\n end\n puts ans*k\nelse\n puts \"-1\"\nend"}, {"source_code": "k, s, a = gets.to_i, gets.strip, {}\n\ns.each_char { |c|\n a[c] = 0 unless a[c]\n a[c] += 1\n}\n\nif a.all?{ |i, j| j % k == 0 }\n t = a.map { |i, j| i * (j / k) }.join\n puts t * k\nelse\n puts -1\nend"}, {"source_code": "n = gets.to_i\ns = gets.strip\na = Array.new(26, 0)\nL = s.length\nfor i in 0...L\n a[s[i].ord - 97] += 1\nend\n\nfor i in 0...26\n if a[i]%n != 0\n print -1\n exit\n end\nend\n\ns = String.new\nfor i in 0...26\n (a[i]/n).times do\n s << (i+97).chr\n end\nend\n\nprint s*n"}, {"source_code": "def k_string? k, s\n s.split('').uniq.map { |c| s.count c }.all? { |c| c%k == 0 }\nend\nk, s = gets.to_i, gets.chomp\nputs k_string?(k,s) ? s.split('').uniq.map {|c| [c, s.count(c) ] }.inject(\"\") {|acc, a| acc + (a[0]*(a[1]/k)) }*k : \"-1\""}, {"source_code": "k = gets.to_i\ns = gets.chomp!\n\ncnt = []\n\ns.each_byte { |x|\n if cnt[x - 97] == nil then\n cnt[x - 97] = 1\n else\n cnt[x - 97] += 1\n end \n}\n\nflg = true;\ncnt.each { |x|\n if x && x % k != 0 then\n flg = false\n end\n}\n\nif !flg then\n puts -1\nelse\n t = \"\"\n cnt.each_index { |ix|\n if cnt[ix] then\n t += (97 + ix).chr * (cnt[ix] / k)\n end\n }\n puts t * k\nend"}, {"source_code": "def getunit(s,k)\n return s.join(\"\") if k == 1\n u = s.uniq\n c = {}\n ans = []\n u.each do |uu|\n c[uu] = s.count(uu)\n return -1 if c[uu] % k != 0\n (c[uu]/k).times { ans.push(uu) }\n end\n return ans.join(\"\")*k\nend\n\nk = gets.to_i\ns = gets.chomp.split(\"\")\nputs getunit(s,k)\n"}, {"source_code": "hs=Hash.new(0)\nn=gets.to_i\ngets.chomp.chars{|e|\n\ths[e]+=1\n}\ns=\"\"\nbad=false\nhs.each{|k,v|\n\tif v%n!=0 then\n\t\tbad=true\n\telse\n\t\ts+=(k*(v/n))\n\tend\n}\nif bad==true then\n\tputs -1\nelse\n\tputs s*n\nend"}, {"source_code": "k=gets.to_i\ncount_hash=Hash.new(0)\ngets.strip.split(\"\").each{|letter|count_hash[letter]+=1}\nflag=0\ncount_hash.each_value { |x| flag=1 if x%k!=0 }\nif flag==0\n string=''\n count_hash.each_key{|letter| string+=letter*(count_hash[letter]/k)}\n puts string*k\nelse\n puts'-1'\nend"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nk = gets.to_i\nchars = gets.strip\nhash = Hash.new( 0 )\n\nchars.split(//).each do |char|\n hash[char]+=1\nend\n\nans = \"\"\nhash.to_a.each do |char, count|\n (puts -1) & exit if count%k != 0\n \n ans += char*(count/k)\nend\n\nputs ans*k"}, {"source_code": "k = gets.to_i\ns = gets.chomp\n\nh = Hash.new(0)\ns.each_char do |c|\n h[c] += 1\nend\n\nr = ''\nok = true\nh.each_pair do |a, v|\n ok = false unless v % k == 0\n \n r += a * (v / k)\nend\n\n\nputs ok ? r*k : -1"}, {"source_code": "class Fixnum\n def multiple_of?(other)\n self % other == 0\n end\nend\n\nclass String\n def can_be_k_string?(k)\n chars_count.values.all? { |value| value.multiple_of?(k) }\n end\n\n def to_k_string(k)\n chars_count.inject(\"\") { |accum, elem| accum += elem.first * (elem.last / k) } * k\n end\n\n private\n\n def chars_count\n @chars_count ||= chars.inject(Hash.new(0)) { |counter, char| counter[char] += 1; counter }\n end\nend\n\nk, string = STDIN.read.split\nk = k.to_i\n\nputs string.can_be_k_string?(k) ? string.to_k_string(k) : -1\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn = $stdin.gets.to_i\ns = $stdin.gets.chomp\n\nif s.size % n != 0\n puts -1\n exit 0\nend\n\nh = Hash.new { 0 }\ns.chars.each do |c|\n h[c] += 1\nend\nans = ''\nh.each do |k, v|\n if v % n != 0\n puts -1\n exit 0\n end\n ans += k * (v/n)\nend\nputs ans*n\n"}, {"source_code": "k = gets.to_i\n\nstring = gets.chomp.split(//)\n\nmap = Hash.new(0)\n\nstring.each { |c| map[c] += 1 }\n\nif map.all? { |i, j| j%k == 0 }\n print map.map { |i, j| i * (j/k) }.join * k\n puts\nelse\n puts \"-1\"\nend\n\n"}], "negative_code": [{"source_code": "def k_string? k, s\n s.split('').uniq.map { |c| s.count c }.all? { |c| c%k == 0 }\nend\nk, s = gets.to_i, gets.chomp\np k_string?(k,s) ? s.split('').uniq.map {|c| [c, s.count(c) ] }.inject(\"\") {|acc, a| acc + (a[0]*(a[1]/k)) }*k : \"-1\""}, {"source_code": "k=gets.to_i\ncount_hash=Hash.new(0)\ngets.strip.split(\"\").each{|letter|count_hash[letter]+=1}\nflag=0\ncount_hash.each_value { |x| flag=1 if x%k!=0 }\nif flag==0\n string=''\n count_hash.each_key{|letter| string+=letter}\n puts string*k\nelse\n puts'-1'\nend"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nk = gets.to_i\nchars = gets.strip\nhash = Hash.new( 0 )\n\nchars.split(//).each do |char|\n hash[char]+=1\nend\n\nans = \"\"\nhash.to_a.each do |char, count|\n (puts -1) & exit if count%k != 0\n \n ans += char\nend\n\nputs ans*k"}, {"source_code": "k = gets.to_i\ns = gets.chomp\n\nh = Hash.new(0)\ns.each_char do |c|\n h[c] += 1\nend\n\nok = true\nh.values.each do |c|\n ok = false unless c % k == 0\nend\n\n\nr = s.scan(/./).uniq.sort.join\n\n\nputs ok ? r*k : -1"}, {"source_code": "k = gets.to_i\ns = gets.chomp\nr = s.gsub(/(.)(?=.*\\1)/, '')\n\nputs r.length % k == 0 ? r*k : -1"}, {"source_code": "k = gets.to_i\ns = gets.chomp\n\na = s.scan(/./)\nr = a.uniq * k\n\nputs r.sort == a.sort ? r.join : -1"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn = $stdin.gets.to_i\ns = $stdin.gets.chomp\n\nif s.size % n != 0\n puts -1\n exit 0\nend\n\nh = Hash.new { 0 }\ns.chars.each do |c|\n h[c] += 1\nend\nans = ''\nh.each do |k, v|\n if v % n != 0\n puts -1\n exit 0\n end\n ans += k\nend\nputs ans*n\n"}, {"source_code": "k = gets.to_i\nstr = gets.chomp.split(//)\nn = str.length/k\n\nx = str.permutation.map(&:join).uniq\n\nx.each do |string|\n if string == string[0...k]*n\n puts string\n exit\n end\nend\nputs '-1'\n"}, {"source_code": "k = gets.to_i\nstr = gets.chomp.split(//)\nary = []\n(0...str.length-k).map do |i|\n ary << str[i...i+k].join\nend\nlen = str.length/k\nflag = nil\nary.uniq.each do |substr|\n if str.join =~ /(?0\n raise \"we're screwed #{r}\"\n end\n #return 0 if r==0\n res = with_memo(FMemo, k*101+r) do\n (st..[r,S[k]].min).reduce(0) do |sum, x|\n ps = comb(S[k], x)\n #puts \"pre ps=#{ps}\"\n if r-x>0\n ps *= f(k+1, r-x)\n end\n #puts \"k=#{k} r=#{r} x=#{x} ps=#{ps}\"\n sum + ps\n end\n end\n #puts \"k=#{k} r=#{r} res=#{res}\"\n res\nend\n\ntot = f(0,n)\n#puts tot\nFMemo.clear\ngood = f(0,n,1)\n#puts good\nif tot==0\n puts \"-1\"\nelse\n puts 1_000_000_000*good/tot*1e-9\nend\n"}], "negative_code": [{"source_code": "n,m,h = readline.split(' ').map &:to_i\ns = readline.split(' ').map &:to_i\ns[h-1]-=1\nS=[s[h-1], s.reduce(&:+)-s[h-1]]\nM=1+(S[1]==0?0:1)\n#S[0],S[h-1]=S[h-1],S[0]\n#S[0]-=1\nn-=1\n\nCombMemo = {}\nFMemo = {}\n\ndef with_memo(memo, ix, &block)\n return memo[ix] if memo[ix]\n res = block.call\n memo[ix] = res\n res\nend\n\ndef comb(n,k)\n return 1 if k==0\n with_memo(CombMemo, n*101+k) do\n (n-k+1)*comb(n,k-1)/k\n end\nend\n\ndef f(k, r, st=0)\n if k==M\n return 1 if r==0\n return 0 if r>0\n raise \"we're screwed #{r}\"\n end\n #return 0 if r==0\n res = with_memo(FMemo, k*101+r) do\n (st..[r,S[k]].min).reduce(0) do |sum, x|\n ps = comb(S[k], x)\n #puts \"pre ps=#{ps}\"\n if r-x>0\n ps *= f(k+1, r-x)\n end\n #puts \"k=#{k} r=#{r} x=#{x} ps=#{ps}\"\n sum + ps\n end\n end\n #puts \"k=#{k} r=#{r} res=#{res}\"\n res\nend\n\ntot = f(0,n)\n#puts tot\nFMemo.clear\ngood = f(0,n,1)\n#puts good\nif tot==0\n puts \"-1\"\nelse\n puts 1.0*good/tot\nend\n"}, {"source_code": "\narg = STDIN.gets.split(\" \").map {|i| i.to_i} # players, departments, Herr's department\nstudents = STDIN.gets.split(\" \").map {|i| i.to_i}\nif arg[0] == 65 and arg[1] == 173 and arg[2] == 136\n i=0\n begin\n i += 1\n puts students[(i-1)*10..[i*10,students.length].min-1]\n end while i*10 < students.length\nend\nothers = 0\n(0..arg[1]-1).each do |i|\n others += students[i] unless i==(arg[2]-1)\nend\ntotal = others + students[arg[2]-1]-1\n\n\n\n\nif total+1 < arg[0]\n puts -1.0\n exit\nend\nif students[arg[2]-1] == 1\n puts 0.0\n exit\nend\n\n\nif others < arg[0]-1\n puts 1.0\n exit\nend\n# 1-C(others,players)/C(total,players)\nprob = 1.0\n(0..arg[0]-2).each do |i|\n prob *= (others-i)\n prob /= (total-i)\nend\nputs 1.0 - prob\n"}, {"source_code": "\narg = STDIN.gets.split(\" \").map {|i| i.to_i} # players, departments, Herr's department\nstudents = STDIN.gets.split(\" \").map {|i| i.to_i}\nif arg[0] == 65 and arg[1] == 173 and arg[2] == 136\n i=15\n begin\n i += 1\n p students[(i-1)*10..[i*10,students.length].min-1]\n end while i*10 < students.length\nend\nothers = 0\n(0..arg[1]-1).each do |i|\n others += students[i] unless i==(arg[2]-1)\nend\ntotal = others + students[arg[2]-1]-1\n\n\n\n\nif total+1 < arg[0]\n puts -1.0\n exit\nend\nif students[arg[2]-1] == 1\n puts 0.0\n exit\nend\n\n\nif others < arg[0]-1\n puts 1.0\n exit\nend\n# 1-C(others,players)/C(total,players)\nprob = 1.0\n(0..arg[0]-2).each do |i|\n prob *= (others-i)\n prob /= (total-i)\nend\nputs 1.0 - prob\n"}, {"source_code": "\narg = STDIN.gets.split(\" \").map {|i| i.to_i} # players, departments, Herr's department\nstudents = STDIN.gets.split(\" \").map {|i| i.to_i}\nif arg[0] == 65 and arg[1] == 173 and arg[2] == 136\n i=10\n begin\n i += 1\n p students[(i-1)*10..[i*10,students.length].min-1]\n end while i*10 < students.length\nend\nothers = 0\n(0..arg[1]-1).each do |i|\n others += students[i] unless i==(arg[2]-1)\nend\ntotal = others + students[arg[2]-1]-1\n\n\n\n\nif total+1 < arg[0]\n puts -1.0\n exit\nend\nif students[arg[2]-1] == 1\n puts 0.0\n exit\nend\n\n\nif others < arg[0]-1\n puts 1.0\n exit\nend\n# 1-C(others,players)/C(total,players)\nprob = 1.0\n(0..arg[0]-2).each do |i|\n prob *= (others-i)\n prob /= (total-i)\nend\nputs 1.0 - prob\n"}, {"source_code": "\narg = STDIN.gets.split(\" \").map {|i| i.to_i} # players, departments, Herr's department\nstudents = STDIN.gets.split(\" \").map {|i| i.to_i}\nif arg[0] == 65 and arg[1] == 173 and arg[2] == 136\n i=0\n begin\n i += 1\n p students[(i-1)*10..[i*10,students.length].min-1]\n end while i*10 < students.length\nend\nothers = 0\n(0..arg[1]-1).each do |i|\n others += students[i] unless i==(arg[2]-1)\nend\ntotal = others + students[arg[2]-1]-1\n\n\n\n\nif total+1 < arg[0]\n puts -1.0\n exit\nend\nif students[arg[2]-1] == 1\n puts 0.0\n exit\nend\n\n\nif others < arg[0]-1\n puts 1.0\n exit\nend\n# 1-C(others,players)/C(total,players)\nprob = 1.0\n(0..arg[0]-2).each do |i|\n prob *= (others-i)\n prob /= (total-i)\nend\nputs 1.0 - prob\n"}, {"source_code": "\narg = STDIN.gets.split(\" \").map {|i| i.to_i} # players, departments, Herr's department\nstudents = STDIN.gets.split(\" \").map {|i| i.to_i}\nif arg[0] == 65 and arg[1] == 173 and arg[2] == 136\n i=5\n begin\n i += 1\n p students[(i-1)*10..[i*10,students.length].min-1]\n end while i*10 < students.length\nend\nothers = 0\n(0..arg[1]-1).each do |i|\n others += students[i] unless i==(arg[2]-1)\nend\ntotal = others + students[arg[2]-1]-1\n\n\n\n\nif total+1 < arg[0]\n puts -1.0\n exit\nend\nif students[arg[2]-1] == 1\n puts 0.0\n exit\nend\n\n\nif others < arg[0]-1\n puts 1.0\n exit\nend\n# 1-C(others,players)/C(total,players)\nprob = 1.0\n(0..arg[0]-2).each do |i|\n prob *= (others-i)\n prob /= (total-i)\nend\nputs 1.0 - prob\n"}, {"source_code": "\narg = STDIN.gets.split(\" \").map {|i| i.to_i} # players, departments, Herr's department\nstudents = STDIN.gets.split(\" \").map {|i| i.to_i}\nif students[arg[2]-1] == 1\n puts -1.0\n exit\nend\n\nothers = 0\n(0..arg[1]-1).each do |i|\n others += students[i] unless i==(arg[2]-1)\nend\nif others < arg[0]-1\n puts 1.0\nend\ntotal = others + students[arg[2]-1]-1\n# 1-C(others,players)/C(total,players)\nprob = 1.0\n(0..arg[0]-2).each do |i|\n prob *= (others-i)\n prob /= (total-i)\nend\nputs 1.0 - prob\n"}, {"source_code": "\narg = STDIN.gets.split(\" \").map {|i| i.to_i} # players, departments, Herr's department\nstudents = STDIN.gets.split(\" \").map {|i| i.to_i}\nif arg[0] == 65 and arg[1] == 173 and arg[2] == 136\n puts students\nend\nothers = 0\n(0..arg[1]-1).each do |i|\n others += students[i] unless i==(arg[2]-1)\nend\ntotal = others + students[arg[2]-1]-1\n\n\n\n\nif total+1 < arg[0]\n puts -1.0\n exit\nend\nif students[arg[2]-1] == 1\n puts 0.0\n exit\nend\n\n\nif others < arg[0]-1\n puts 1.0\n exit\nend\n# 1-C(others,players)/C(total,players)\nprob = 1.0\n(0..arg[0]-2).each do |i|\n prob *= (others-i)\n prob /= (total-i)\nend\nputs 1.0 - prob\n"}, {"source_code": "\narg = STDIN.gets.split(\" \").map {|i| i.to_i} # players, departments, Herr's department\nstudents = STDIN.gets.split(\" \").map {|i| i.to_i}\nif arg[0] == 65 and arg[1] == 173 and arg[2] == 136\n i=4\n begin\n i += 1\n p students[(i-1)*10..[i*10,students.length].min-1]\n end while i*10 < students.length\nend\nothers = 0\n(0..arg[1]-1).each do |i|\n others += students[i] unless i==(arg[2]-1)\nend\ntotal = others + students[arg[2]-1]-1\n\n\n\n\nif total+1 < arg[0]\n puts -1.0\n exit\nend\nif students[arg[2]-1] == 1\n puts 0.0\n exit\nend\n\n\nif others < arg[0]-1\n puts 1.0\n exit\nend\n# 1-C(others,players)/C(total,players)\nprob = 1.0\n(0..arg[0]-2).each do |i|\n prob *= (others-i)\n prob /= (total-i)\nend\nputs 1.0 - prob\n"}], "src_uid": "ffafd385ec79aa28b8d30224baf6bcfe"} {"source_code": "n = gets.to_i\na = []\na = gets.split.map &:to_i\ncnt = 0\n(0...n).each do |i|\n if (a[i] % 2 == 1)\n cnt += 1\n end\nend\n\nif (cnt == 0)\n puts \"Second\"\nelse\n puts \"First\"\nend", "positive_code": [{"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\n\nx=true\na.each{|e| x&=e%2==0}\nif x\n puts 'Second'\nelse\n puts 'First'\nend\n\n"}, {"source_code": "gets\nfor i in gets.split.map(&:to_i)\nif i%2==1\n puts 'First'\n exit\nend\nend\nputs 'Second'"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\nsum_a = count_odd = count_even = 0\nn.times do |i|\n curr = a[i]\n count_odd += 1 if curr.odd?\n count_even += 1 if curr.even?\n sum_a += curr\nend\nif sum_a.odd?\n puts \"First\"\nelse\n if count_odd >= 2 && count_odd.even?\n puts \"First\"\n else\n puts \"Second\"\n end\nend\n"}], "negative_code": [{"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\n\nx=true\na.each{|e| x&=e%2==0}\nif x\n puts 'Second'\n exit 0\nend\n\ns=a.inject(:+)\nif s%2==1\n puts 'First'\nelse\n puts 'Second'\nend\n"}], "src_uid": "808611f86c70659a1d5b8fc67875de31"} {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split('')\n# p arr\nco = {'A'=>0,'D'=>0}\n\narr.each do |el|\n co[el] += 1\nend\n\n# p co\nif co['A'] > co['D']\n puts \"Anton\"\nelsif co['A'] < co['D']\n puts \"Danik\"\nelse\n puts \"Friendship\"\nend\n", "positive_code": [{"source_code": "n = gets.chomp\nword = gets.chomp\n\nanton = word.count(\"A\")\ndanik = word.count(\"D\")\n\nif anton > danik\n puts \"Anton\"\nelsif anton < danik\n puts \"Danik\"\nelse\n puts \"Friendship\"\nend\n"}, {"source_code": "\n# Anton and Danik\n# https://codeforces.com/problemset/problem/734/A\nclass ChessMatch\n def initialize(matches, result)\n @matches = matches\n @result = result\n end\n\n def winner\n wins_anton = @result.count('A')\n wins_danik = @matches - wins_anton\n\n if wins_anton > wins_danik\n 'Anton'\n elsif wins_anton < wins_danik\n 'Danik'\n else\n 'Friendship'\n end\n end\nend\n\n# Test case\n# 6\n# ADAAAA\n# Anton\nmatches = gets.to_i\nret = gets\n\nmatch = ChessMatch.new(matches, ret)\nputs match.winner\n"}, {"source_code": "s=$<.read;puts [:Friendship,:Anton,:Danik][s.count(?A)<=>s.count(?D)]"}, {"source_code": "# input from user\ndef Get_Input\n number_game = gets.chomp\n str = gets.chomp\n return str\nend\n\ndef check_char(str)\n anton=0\n danik=0\n #get count of char\n str.split('').each do |char|\n if char == 'A'\n anton +=1\n elsif char == 'D'\n danik +=1\n end\n end\n# to check who's win\n if anton > danik\n puts 'Anton'\n elsif anton < danik\n puts 'Danik'\n elsif anton == danik\n puts 'Friendship'\n end\nend\n\nstr = Get_Input()\ncheck_char(str)\n"}, {"source_code": "n = gets.chomp.to_i\nchars = gets.chomp.chars\n\nans = chars.count('A') - chars.count('D')\nif ans == 0\n puts \"Friendship\"\nelsif ans > 0\n puts \"Anton\"\nelse\n puts \"Danik\"\nend\n"}, {"source_code": "gets\na = gets().chomp.split(//)\ncnt = 0\na.map{|x| x == 'A'? cnt += 1 : cnt -= 1}\nputs cnt > 0 ? \"Anton\" : cnt == 0 ? \"Friendship\" : \"Danik\"\n"}, {"source_code": "#!/usr/bin/env ruby \ngets\na = gets().chomp.split(//)\ncnt = 0\na.map{|x| x == 'A'? cnt += 1 : cnt -= 1}\nputs cnt > 0 ? \"Anton\" : cnt == 0 ? \"Friendship\" : \"Danik\""}, {"source_code": "#!/usr/bin/env ruby \ngets \na = gets().strip.split(//) \ncnt = a.count(\"A\") - a.count(\"D\") \nputs cnt > 0 ? \"Anton\" : cnt == 0 ? \"Friendship\" : \"Danik\" "}, {"source_code": "#!/usr/bin/env ruby \ngets \na = gets().chomp.split(//) \ncnt = a.count(\"A\") - a.count(\"D\") \nputs cnt > 0 ? \"Anton\" : cnt == 0 ? \"Friendship\" : \"Danik\" "}, {"source_code": "s=$<.read;puts [:Friendship,:Anton,:Danik][s.count(?A)<=>s.count(?D)]"}, {"source_code": "x = gets.chomp.to_i\ns = gets\na = 0\nd = 0\nwhile x >= 0 \n if s[x]== 'A'\n a = a + 1\n elsif s[x]== 'D'\n d = d + 1\n end\n x = x - 1\nend\n\nif a > d \n puts \"Anton\"\nelsif a < d \n puts \"Danik\"\nelse\n puts \"Friendship\"\nend "}, {"source_code": "num = gets.chomp.to_i\ntabs = gets.chomp\nA = tabs.count(\"A\")\nD = tabs.count(\"D\")\nif A > D \n\tputs \"Anton\"\nelsif D > A\n\tputs \"Danik\"\nelse puts \"Friendship\"\nend\n"}, {"source_code": "total_play = gets.strip.to_i\nplay_string = gets.strip\nplay = play_string.split('')\n\nanton_counter = 0\ndanik_counter = 0\n\n0.upto(total_play - 1).each do |index|\n if play[index].eql?('A')\n anton_counter += 1\n else\n danik_counter += 1\n end\nend\n\nif anton_counter > danik_counter\n puts 'Anton'\nelsif danik_counter > anton_counter\n puts 'Danik'\nelse\n puts 'Friendship'\nend\n"}, {"source_code": "n = gets.to_i\narr = gets.chomp.chars.to_a\nd = a = 0\narr.each{|c|\n if c == 'D'\n d+=1\n else\n a+=1\n end\n}\nif a > d\n puts 'Anton'\nelsif d > a\n puts 'Danik'\nelse\n puts 'Friendship'\nend"}, {"source_code": "n = gets.to_i\nstr = gets.strip\nac = str.count(\"A\")\ndc = str.count(\"D\")\n\nputs \"Anton\" if ac > dc\nputs \"Danik\" if ac < dc\nputs \"Friendship\" if ac == dc\n"}, {"source_code": "class A\n\n def run\n n = $stdin.gets.to_i\n s = $stdin.gets\n a = d = 0\n n.times.each do |i|\n c = s[i] \n a += 1 if c == 'A'\n d += 1 if c == 'D'\n end\n puts 'Anton' if a > d\n puts 'Danik' if a < d\n puts 'Friendship' if a == d\n end\n\nend\n\nA.new.run"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nn = gi\ns = gs\n\nanton_won = s.count('A')\ndanik_won = n - anton_won\n\ncase\nwhen anton_won > danik_won\n puts :Anton\nwhen anton_won < danik_won\n puts :Danik\nelse\n puts :Friendship\nend"}, {"source_code": "# cook your code here\nn = gets.to_i \nresult = gets \nputs \"Anton\" if result.count(\"A\") > result.count(\"D\")\nputs \"Friendship\" if result.count(\"A\") == result.count(\"D\")\nputs \"Danik\" if result.count(\"D\") > result.count(\"A\")"}, {"source_code": "gets.chomp\nrounds = gets.chomp\n\nanton = rounds.count 'A'\ndanik = rounds.count 'D'\n\nputs \"Anton\" if anton > danik\nputs \"Danik\" if danik > anton \nputs \"Friendship\" if anton == danik"}, {"source_code": "n = gets.to_i\ngames = gets.chomp\nac = games.count('A')\ndc = n - ac\nif ac == dc\n puts 'Friendship'\nelsif ac > dc\n puts 'Anton'\nelse\n puts 'Danik'\nend"}, {"source_code": "s=$<.read;puts [:Friendship,:Anton,:Danik][s.count(?A)<=>s.count(?D)]\n"}, {"source_code": "n=gets.to_i\nv=gets.chars.count{|e|\n\te==\"A\"\n}\nans=\"\"\n\nif n%2==0 then\n\tif n/2 s.count('D')) + 1]\n"}, {"source_code": "gets\ns = gets.chomp\nn = 0\ns.each_char do |i| \n\tif i == 'A'\n\t\tn += 1\n\telse\n\t\tn -= 1\n\tend\nend\nif n == 0\n\tputs 'Friendship'\nelsif n > 0\n\tputs 'Anton'\nelse\n\tputs 'Danik'\nend\n\t\n"}, {"source_code": "gets\ns=gets.chomp\na=s.count ?A\nd=s.count ?D\nputs ad ? \"Anton\" : \"Friendship\"\n"}, {"source_code": "a= gets.chomp.to_i\nstr = gets.chomp \nstr = str.split('')\nif str.count(\"A\") > str.count(\"D\")\n puts \"Anton\"\nelsif str.count(\"D\") > str.count(\"A\")\n puts \"Danik\"\nelse\n puts \"Friendship\"\nend"}, {"source_code": "n = gets.to_i\ns = gets\na = s.count('A')\nb = s.count('D')\nputs a>b ? \"Anton\" : b>a ? \"Danik\" : \"Friendship\"\n"}, {"source_code": "numResults = gets.chomp.to_i\nresults = gets.chomp\n\nanton = 0\ndanik = 0\n\nresults.each_byte do |b|\n\tif b.chr == 'A'\n\t\tanton = anton + 1\n\telsif b.chr == 'D'\n\t\tdanik = danik + 1\n\tend\nend\n\nif anton == danik\n\tputs \"Friendship\"\nelsif anton > danik\n\tputs \"Anton\"\nelse\n\tputs \"Danik\"\nend\n"}, {"source_code": "games = gets.chomp\nw = gets.chomp\nwins = w.split(\"\")\n\ncount = 0\nwins.each do |win|\n\tif win == \"A\"\n\t\tcount += 1\n\telse\n\t\tcount -= 1\n\tend\nend\n\nif count > 0\n\tprint \"Anton\"\nelsif count < 0\n\tprint \"Danik\"\nelse\n\tprint \"Friendship\"\nend"}, {"source_code": "#puts \"Enter the number of game played\\n\"\nn = gets.to_i\ns = gets.to_s\na = d = 0\nfor i in 0...n do\n if s[i] == 'A'\n a += 1\n else\n d += 1\n end\nend\nif a > d\n puts \"Anton\\n\"\nelsif d > a\n puts \"Danik\\n\"\nelse\n puts \"Friendship\\n\"\nend"}, {"source_code": "int_value = gets.chomp\nstring_input = gets.chomp\nstring = string_input.split('')\nanton = 0\ndanik = 0\nstring.each do |char|\n if char == 'A'\n anton += 1\n else\n danik += 1\n end\nend\nif anton == danik\n puts 'Friendship'\nelsif anton > danik\n puts 'Anton'\nelse\n puts 'Danik'\nend"}, {"source_code": "gets\ns = gets\nputs s.count(\"A\") > s.count(\"D\") ? \"Anton\" : (s.count(\"A\") < s.count(\"D\") ? \"Danik\" : \"Friendship\")\n"}, {"source_code": "s=$<.read;puts [:Friendship,:Anton,:Danik][s.count(?A)<=>s.count(?D)]\n"}, {"source_code": "n = gets.to_i\ns = gets\na = s.count('A')\nb = s.count('D')\nputs a>b ? \"Anton\" : b>a ? \"Danik\" : \"Friendship\"\n"}, {"source_code": "#!/usr/bin/env ruby\n\ngets\ns = gets.strip\na = s.count('A')\nb = s.count('D')\n\nif a > b\n puts 'Anton'\nelsif a < b\n puts 'Danik'\nelse\n puts 'Friendship'\nend\n"}, {"source_code": "gets\ns = gets\nputs (a = s.count(\"A\")) > (d = s.count(\"D\")) ? \"Anton\" : a == d ? \"Friendship\" : \"Danik\"\n"}, {"source_code": "gets\ns = gets\nputs s.count(\"A\") > s.count(\"D\") ? \"Anton\" : s.count(\"A\") == s.count(\"D\") ? \"Friendship\" : \"Danik\"\n"}, {"source_code": "n = gets\nn = gets\na = n.count 'A'\nd= n.count 'D'\nif a > d\n puts \"Anton\"\nelsif a < d\n puts \"Danik\"\nelse\n puts \"Friendship\"\nend"}, {"source_code": "n = gets\ndata = gets.chomp\n\nan = data.chars.count { |c| c == 'A' }\ndn = data.chars.count { |c| c == 'D' }\n\nif an > dn\n puts 'Anton'\nelsif an < dn\n puts 'Danik'\nelse\n puts 'Friendship'\nend\n"}, {"source_code": "s=$<.read;puts [:Friendship,:Anton,:Danik][s.count(?A)<=>s.count(?D)]\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\nr = s.count('A') * 2\nif r > n\n printf(\"Anton\\n\")\nelsif r == n\n printf(\"Friendship\\n\")\nelse\n printf(\"Danik\\n\")\nend\n"}, {"source_code": "n = gets.chomp().to_i\ns = gets.chomp().split('')\nanton = s.select{|c| c if c=='A'}.length\ndanik = s.select{|c| c if c=='D'}.length\nputs ( anton == danik ) ? \"Friendship\" : (anton > danik) ? \"Anton\" : \"Danik\""}, {"source_code": "require 'set'\nparse_int = lambda{ gets.split.map{|el| el.to_i} }\nsign = lambda {|el| (el>0?1:0)-(el<0?1:0)}\n\ngets\nn = gets\na,d = n.count('A'), n.count('D')\n\nputs 'Anton' if a>d\nputs 'Danik' if d>a\nputs 'Friendship' if d==a\n\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "gets\na = gets().chomp.split(//)\nprint a.inspect\ncnt = 0\na.map{|x| x == 'A'? cnt += 1 : cnt -= 1}\nputs cnt > 0 ? \"Anton\" : cnt == 0 ? \"Friendship\" : \"Danik\"\n"}, {"source_code": "gets\na = gets().split(//)\ncnt = 0\na.map{|x| x == 'A'? cnt += 1 : cnt -= 1} \nputs cnt > 0 ? \"Anton\" : (cnt == 0 ? \"Friendship\" : \"Danik\")"}, {"source_code": "num = gets.chomp.to_i\ntabs = gets.chomp\nA_count = 0\nD_count = 0\nfor i in 0...num\n\tputs \"check\"\n\tif tabs[i] == \"A\"\n\t\tA_count += 1\n\telse\n\t\tD_count += 1\n\tend\nend\nif A_count > D_count \n\tputs \"Anton\"\nelsif D_count > A_count\n\tputs \"Danik\"\nelse puts \"Friendship\"\nend\n"}, {"source_code": "gets\ns = gets.chomp\nn = 0\ns.each_char do |i| \n\tif i == 'A'\n\t\tn += 1\n\telse\n\t\tn -= 1\n\tend\nend\nif n == 0\n\tputs 'Friendship'\nelsif n > 1\n\tputs 'Anton'\nelse\n\tputs 'Danik'\nend"}, {"source_code": "numResults = gets.to_i\nresults = gets\n\nanton = 0\ndanik = 0\n\nputs results.size\n\nresults.each_byte do |b|\n\tif b.chr == 'A'\n\t\tanton = anton + 1\n\telsif b.chr == 'D'\n\t\tdanik = danik + 1\n\tend\nend\n\nif anton == danik\n\tputs \"Friendship\"\nelsif anton > danik\n\tputs \"Anton\"\nelse\n\tputs \"Danik\"\nend\n"}, {"source_code": "input = $stdin.readlines\n\nnumResults = input[0].to_i\nresults = input[1]\n\nanton = 0\ndanik = 0\n\nputs results.size\n\nresults.each_byte do |b|\n\tif b.chr == 'A'\n\t\tanton = anton + 1\n\telsif b.chr == 'D'\n\t\tdanik = danik + 1\n\tend\nend\n\nif anton == danik\n\tputs \"Friendship\"\nelsif anton > danik\n\tputs \"Anton\"\nelse\n\tputs \"Danik\"\nend\n"}, {"source_code": "int_value = gets\nstring_input = gets\nstring = string_input.split('')\nanton = 0\ndanik = 0\nstring.each do |char|\n if char == 'A'\n anton += 1\n else\n danik += 1\n end\nend\nif anton == danik\n puts 'Friendship'\nelsif anton > danik\n puts 'Anton'\nelse\n puts 'Danik'\nend"}, {"source_code": "s = gets\nputs s.count(\"A\") > s.count(\"D\") ? \"Anton\" : (s.count(\"A\") < s.count(\"D\") ? \"Danik\" : \"Friendship\")\n"}, {"source_code": "#gets\n#s = gets\n#puts (a = s.count(\"A\")) > (d = s.count(\"D\")) ? \"Anton\" : a == d ? \"Friendship\" : \"Danik\"\n\ns=$<.read\np [:Friendship,:Anton,:Danik][s.count(?A)<=>s.count(?D)]\n"}, {"source_code": "s=$<.read;p [:Friendship,:Anton,:Danik][s.count(?A)<=>s.count(?D)]"}, {"source_code": "require 'set'\nparse_int = lambda{ gets.split.map{|el| el.to_i} }\nsign = lambda {|el| (el>0?1:0)-(el<0?1:0)}\n\ngets\nn = gets\na,d = n.count('A'), n.count('D')\n\nputs 'Antin' if a>d\nputs 'Danik' if d>a\nputs 'Friendship' if d==a\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "0de32a7ccb08538a8d88239245cef50b"} {"source_code": "gets.to_i.times do\r\n n, k = gets.split.map(&:to_i)\r\n as = gets.split.map(&:to_i)\r\n sorted = as.sort.zip(0..).to_h\r\n puts as.chunk_while { |a, b| sorted[a] == sorted[b] - 1 }.count <= k ? \"Yes\" : \"No\"\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times {\n n, k = gets.split.map(&:to_i)\n xs = gets.split.map(&:to_i)\n ys = (0...n).to_a.sort_by { xs[_1] }\n b = 1\n (1...n).each { |i|\n b += 1 if ys[i] - 1 != ys[i - 1]\n }\n puts(b <= k ? 'Yes' : 'No')\n}\n"}, {"source_code": "gets.to_i.times {\n n, k = gets.split.map(&:to_i)\n xs = gets.split.map(&:to_i)\n\n prev = {}\n ys = xs.sort\n ys.each_with_index { |x, i|\n prev[x] = ys[i - 1] if i > 0\n }\n\n blocks = 1\n (1...n).each { |i|\n blocks += 1 if prev[xs[i]] != xs[i - 1]\n }\n\n puts(blocks <= k ? 'Yes' : 'No')\n}\n"}, {"source_code": "#!/usr/bin/env ruby\r\n\r\ntc = gets.to_i\r\n\r\ndef order(ar)\r\n sorted = ar.sort;\r\n hsh = sorted.zip(0..).to_h\r\n return ar.map{|x| hsh[x]}\r\nend\r\n\r\ndef correct(ar)\r\n ar2 = ar.dup\r\n ar2.shift\r\n return ar.zip(ar2).map { |x| x[1] == x[0]+1 ? 1 : 0}.sum\r\nend\r\n\r\nfor t in 1..tc\r\n n, k = gets.split.map { |x| x.to_i };\r\n ar =order(gets.split.map {|x| x.to_i});\r\n \r\n#puts \"#{ar}, #{n-correct(ar)}\"\r\n puts \"#{n-correct(ar) <= k ? 'Yes' : 'No'}\"\r\nend\r\n"}, {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n, k = gets.chomp.split(\" \").map(&:to_i)\r\n a = gets.chomp.split(\" \").map(&:to_i)\r\n a_dup = a.dup\r\n a_dup = a_dup.sort\r\n hash = Hash.new(0)\r\n a_dup.each_with_index do |i,index|\r\n hash[i] = index\r\n end\r\n arr = []\r\n cnt = 0\r\n a.each do |i|\r\n if arr == []\r\n arr << i\r\n else\r\n if hash[arr[-1]] + 1 != hash[i]\r\n cnt += 1\r\n end\r\n arr << i\r\n end\r\n end\r\n if cnt + 1 <= k\r\n puts \"Yes\"\r\n else\r\n puts \"No\"\r\n end\r\nend\r\n"}, {"source_code": "END { load __FILE__ unless $stdin.eof? }\n\nt = gets.to_i\nt.times do\n\tn, k = gets.split.map!(&:to_i)\n\ta = gets.split.map!(&:to_i)\n\n\th = a.sort.each_with_index.to_h\n\ta.map!(&h)\n\n\tc = a.each_cons(2).count { |x, y| x + 1 != y }\n\tputs (k >= c + 1) ? :Yes : :No\nend\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n n, k = gets.split.map(&:to_i)\r\n as = gets.split.map(&:to_i)\r\n puts as.chunk_while { |a, b| a < b }.count <= k ? \"Yes\" : \"No\"\r\nend\r\n"}], "src_uid": "255d6fca1379ae40b03e761802f36664"} {"source_code": "#!/usr/bin/env ruby\n\nn, k = gets.split.collect{|i| i.to_i}\ntot = 0\nn.times do\n\tx, y = gets.split.collect{|i| i.to_i}\n\ttot = (tot + y - x + 1) % k\nend\n\nputs (tot == 0 ? 0 : k - tot)\n", "positive_code": [{"source_code": "n,k=gets.split.map(&:to_i)\nsum=0\nn.times do\n a,b=gets.split.map(&:to_i)\n sum+=b-a+1\nend\nputs sum%k==0?0:k-sum%k"}, {"source_code": "def run\n n, k = $stdin.readline.split.map(&:to_i)\n\n sum = 0\n $stdin.readlines.each do |line|\n l, r = line.split.map(&:to_i)\n sum += r - l + 1\n end\n\n puts (sum % k == 0) ? 0 : (k - sum % k)\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "class A\n def initialize\n n, k = $stdin.gets.chomp.split(' ').map(&:to_i)\n\n total = 0\n n.times do\n l, r = $stdin.gets.chomp.split(' ').map(&:to_i)\n count = r - l + 1\n total += count\n end\n\n if total%k == 0\n puts 0\n else\n puts k - (total%k)\n end\n end\nend\n\na = A.new"}, {"source_code": "a=gets.chomp.split(\" \")\nk=a[1].to_i\nx=0\n(a[0].to_i).times do\ntemp=gets.chomp.split(\" \")\nx+=temp[1].to_i-temp[0].to_i+1\nend\nputs \"#{(k-(x%k))%k}\""}, {"source_code": "n,k=gets.split.map(&:to_i)\ns=0\nn.times do\n l,r=gets.split.map(&:to_i)\n s+=r-l+1\nend\nputs (k-s%k)%k"}, {"source_code": "n, k = gets.split(' ').map { |x| x.to_i }\nt = 0\n(1..n).each do |x|\n a,b = gets.split(' ').map { |x| x.to_i }\n t += (b-a).abs + 1\nend\nputs (k - t % k) % k"}, {"source_code": "n, m = gets.split(' ').map!{ |i| i.to_i }\n\narr = Array.new\nsum = 0\nn.times {\n\tl, r = gets.split(' ').map!{ |i| i.to_i }\n\tarr << r - l + 1\n\tsum += arr[-1]\n}\n\nleft = sum % m\n\nans = left == 0 ? 0 : m - left\n\np ans"}, {"source_code": "n, k = gets.split.map(&:to_i)\nlrs = n.times.map { gets.split.map(&:to_i) }\ncount = lrs.sort_by(&:first).map { |(a, b)| b - a + 1 }.reduce(:+)\nif count % k == 0\n p 0\nelse\n p k - count % k\nend"}, {"source_code": "n,kp = gets.split(\" \").collect {|x| x.to_i}\nlast = -1\nrs = 0\nls = 0\ns = 0\n(0...n).each {|k|\n\tls,rs = gets.split(\" \").collect {|x| x.to_i}\n\ts+= (rs-ls+1)\n}\n\n\nputs (kp - s%kp)%kp"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\ncnt = 0\n(0...n).each do\n l, r = gets.split.collect{|i| i.to_i}\n cnt += r-l+1\nend\nif cnt%k == 0\n puts \"0\"\nelse\n puts k-cnt%k\nend\n"}, {"source_code": "n, k = gets.split(\" \").collect{|x| x.to_i}\n\nv = 0\nc = 0\nn.times do\n l, r = gets.split(\" \").collect{|x| x.to_i}\n v += r - l + 1\nend\n\nrest = v % k\nputs (k - rest) % k"}, {"source_code": "def read_next_line\n gets.split.map { |x| x.to_i }\nend\n\nn, k = read_next_line\nsum = 0\nfor _ in 1..n\n l, r = read_next_line\n sum += r - l + 1\nend\nrem = sum % k\nputs(rem == 0 ? 0 : k - rem)"}, {"source_code": "n,k = gets.strip.split.map(&:to_i)\n\nsegments = []\nn.times do\n segments << gets.strip.split.map(&:to_i)[0..1]\nend\n\nvalue = segments.map{|x| x[1] - x[0] + 1}.inject :+\nputs value % k == 0 ? 0 : ((value / k) + 1) * k - value\n\n"}], "negative_code": [{"source_code": "n, k = gets.split(' ').map { |x| x.to_i }\nm = (0..10000).to_a\n(1..n).each do |x|\n a,b = gets.split(' ').map { |x| x.to_i }\n (a..b).each { |i| m[i] = 1 }\nend\nt = 0\nm.each {|x| if x == 1 then t = t+1 end}\ns = 0\nwhile (t % k != 0 )\n t = t + 1\n s = s + 1\nend\nputs s"}, {"source_code": "n, k = gets.split(' ').map { |x| x.to_i }\nt = 0\n(1..n).each do |x|\n a,b = gets.split(' ').map { |x| x.to_i }\n t += b-a.abs + 1\nend\nif t <= k then puts k-t\nelse \n r = k\n while r <= t\n r += k\n end\n puts r - t\nend"}, {"source_code": "n, k = gets.split(' ').map { |x| x.to_i }\nt = 0\n(1..n).each do |x|\n a,b = gets.split(' ').map { |x| x.to_i }\n t += b-a.abs + 1\nend\nif t <= k then puts k-t\nelse \n r = k\n while r < t\n r += k\n end\n puts r - t\nend"}, {"source_code": "n, k = gets.split(' ').map { |x| x.to_i }\nm = Array.new(20001)\n(1..n).each do |x|\n a,b = gets.split(' ').map { |x| x.to_i }\n (a..b).each { |i| m[i+10000] = 1 }\nend\nt = 0\nm.each {|x| if x == 1 then t = t+1 end}\nif t <= k then puts k-t\nelse \n r = k\n while r <= t\n r = r + k\n end\n puts r-t\nend"}, {"source_code": "n, k = gets.split(' ').map { |x| x.to_i }\nt = 0\n(1..n).each do |x|\n a,b = gets.split(' ').map { |x| x.to_i }\n t += b-a.abs + 1\nend\nif t <= k then puts k-t\nelse \n puts k - (t % k)\nend"}], "src_uid": "3a93a6f78b41cbb43c616f20beee288d"} {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nstatus = (1..n).to_a\nleader = 0\na.each { |step|\n eliminate = (leader + step) % status.length\n print \"#{status[eliminate]} \"\n status = status.select.with_index { |v, i| i != eliminate }\n leader = eliminate\n}\nprint \"\\n\"\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\nn, k = gets.split.map(&:to_i)\nks = gets.split.map(&:to_i)\n\nouts = []\nchilds = Array.new(n)\nchilds.each_with_index { |v, i| childs[i] = i + 1 }\n\ncur = 0\nks.each do |k|\n k_i = (cur + (k % childs.size)) % childs.size\n outs << childs[k_i]\n childs.delete_at(k_i)\n cur = k_i % childs.size\nend\n\nputs outs.join(\" \")\n"}, {"source_code": "n,k=gets.split(\" \").map(&:to_i)\na=gets.split(\" \").map(&:to_i)\ndt=(1..n).to_a\n\nnow=0\n\nans=[]\n\nfor i in (0...k)\n\ttmp=a[i]%dt.length\n\tnow=(now+tmp)%dt.length\n\tans<= children.length\n \n first = false\nend\n\n\n\n"}], "negative_code": [], "src_uid": "5512fbe2963dab982a58a14daf805291"} {"source_code": "a, b = nil\nFile.open(\"input.txt\") do |f|\n a = f.gets.strip\n b = f.gets.strip\nend\n\nif (a == 'front' && b == '1') || (a == 'back' && b == '2')\n lr = 'L'\nelse\n lr = 'R'\nend\n\nFile.open(\"output.txt\", \"w\") do |f|\n f.puts lr\nend\n", "positive_code": [{"source_code": "p=open(\"input.txt\");open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]"}, {"source_code": "p=open(\"input.txt\");open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]\n"}, {"source_code": "p=open(\"input.txt\");open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]\n"}, {"source_code": "p=open(\"input.txt\");open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]"}, {"source_code": "open(\"input.txt\"){|p|open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]}\n"}, {"source_code": "p=open(\"input.txt\");open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]\n"}, {"source_code": "p=open(\"input.txt\");open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]\n"}, {"source_code": "f = File.open('input.txt', 'r') or die \"Unable to open file...\"\ninput = [] # start with an empty array\n f.each_line {|line|\n input.push line\n } \n \ndoor = input[0].chop\nside = input[1].to_i\nwhile door == 'front' or door == 'back'\n File.open('output.txt', 'w') do |o| \n o.puts \"#{(door == 'front')? ((side == 1)? 'L' : 'R') : ((side == 2)? 'L' : 'R')}\" \n end \nexit\nend\n"}, {"source_code": "solve = {['front', '1'] => 'L', ['front', '2'] => 'R', ['back', '1'] => 'R', ['back', '2'] => 'L'}\nFile.open('input.txt', 'r') do |input|\n\tFile.open('output.txt', 'w') do |output|\n\t\toutput.puts solve[[input.gets.chomp, input.gets.chomp]]\n\tend\nend\n\n"}, {"source_code": "p=open(\"input.txt\");open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]\n"}, {"source_code": "p=open(\"input.txt\");open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]\n"}, {"source_code": "p=open(\"input.txt\");open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]"}, {"source_code": "p=open(\"input.txt\");open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]\n"}, {"source_code": "p=open(\"input.txt\");open(\"output.txt\",\"w\").puts\"LR\"[p.gets.size+p.gets.to_i-7]\n"}], "negative_code": [], "src_uid": "77093f12ff56d5f404e9c87650d4aeb4"} {"source_code": "def ord_to_char(seq_ord)\r\n ('a'.ord+seq_ord-1).chr\r\nend\r\n\r\ndef decode(encoded_str,len)\r\n # Search from the tail is better.\r\n ptr=len-1\r\n res_str=[]\r\n while ptr>=0\r\n if encoded_str[ptr]=='0'\r\n res_str << ord_to_char(encoded_str[ptr-2...ptr].to_i)\r\n ptr-=3\r\n else\r\n res_str << ord_to_char(encoded_str[ptr].to_i)\r\n ptr-=1\r\n end\r\n end\r\n res_str.reverse.join('')\r\nend\r\n\r\nn_rounds=gets.to_i\r\n\r\nn_rounds.times do\r\n len=gets.to_i\r\n estr=gets\r\n puts decode(estr,len)\r\nend\r\n\r\n", "positive_code": [{"source_code": "c=Hash.new(nil);$stdin.each_line.with_index{|l, i|next if i==0||i%2==1;if c[l]!=nil;puts(c[l]);next;end;nt=0;o=\"\";l.chomp.each_char.with_index {|x, i|if nt!=0;nt-=1;next;end;if (i<(l.chomp.length-2))&&(l[i + 2]==\"0\")&&(i>l.chomp.length-4||l[i + 3]!=\"0\");nt=2;o+=(\"a\"..\"z\").to_a[(x+l[i+1]).to_i-1];next;end;o+=(\"a\"..\"z\").to_a[x.to_i-1]};c[l]=o;puts(o)}"}, {"source_code": "c = Hash.new(nil)\r\n$stdin.each_line.with_index do |l, i| next if i == 0 || i % 2 == 1\r\n if c[l] != nil\r\n puts c[l]\r\n next\r\n end\r\n nt = 0\r\n o = \"\"\r\n l.chomp.each_char.with_index do |x, i|\r\n if nt != 0\r\n nt -= 1\r\n next\r\n end\r\n if (i < (l.chomp.length - 2)) && (l[i + 2] == \"0\") && (i > l.chomp.length - 4 || l[i + 3] != \"0\")\r\n nt = 2\r\n o += (\"a\"..\"z\").to_a[(x + l[i + 1]).to_i - 1]\r\n next\r\n end\r\n o += (\"a\"..\"z\").to_a[x.to_i - 1]\r\n end\r\n c[l]=o\r\n puts o\r\nend"}, {"source_code": "\r\ndef solve(n, s)\r\n alphabets = ['@', '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']\r\n\r\n ans = ''\r\n i = n-1\r\n while i >= 0 do\r\n if s[i] == '0'\r\n ans += alphabets[s[(i-2)..(i-1)].to_i]\r\n i -= 3\r\n else\r\n ans += alphabets[s[i].to_i]\r\n # p alphabets[s[i].to_i]\r\n i -= 1\r\n end\r\n end\r\n ans.reverse!\r\n puts ans\r\nend\r\n\r\nt = gets.chomp.to_i\r\nfor i in 1..t\r\n n = gets.chomp.to_i\r\n s = gets.chomp\r\n solve(n, s)\r\nend\r\n"}, {"source_code": "\r\ndef debug(*arg)\r\n puts \"[DEBUG] #{arg.join \" \"}\"\r\nend\r\n\r\nt = gets.to_i\r\n\r\nalpha = ('a'.upto 'z').to_a\r\n\r\n\r\nt.times do\r\n n = gets.to_i\r\n s = gets.chomp.chars\r\n\r\n ans = []\r\n until s.empty?\r\n last = s.pop\r\n if last == '0'\r\n ans << alpha[s[-2..].join.to_i - 1]\r\n s.pop; s.pop\r\n else\r\n ans << alpha[last.to_i - 1]\r\n end\r\n\r\n end\r\n puts ans.reverse.join(\"\")\r\nend"}, {"source_code": "$stdin.readline\r\n\r\ncache = {}\r\n\r\nwhile !$stdin.eof do\r\n $stdin.readline\r\n codestr = $stdin.readline.chomp\r\n\r\n if cache[codestr]\r\n puts cache[codestr]\r\n next\r\n end\r\n\r\n str = codestr.reverse.scan(/0[0-9][1-9]|[1-9]/).map { |code|\r\n code = code.reverse.to_i\r\n code = code < 10 ? code : code / 10\r\n (\"a\"..\"z\").to_a[code - 1]\r\n }.join.reverse\r\n\r\n puts cache[codestr] = str\r\nend"}], "negative_code": [{"source_code": "c = Hash.new(nil)\r\n$stdin.each_line.with_index do |l, i| next if i == 0 || i % 2 == 1\r\n puts c[l] if c[l] != nil\r\n nt = 0\r\n o = \"\"\r\n l.chomp.each_char.with_index do |x, i|\r\n if nt != 0\r\n nt -= 1\r\n next\r\n end\r\n if (i < (l.chomp.length - 2)) && (l[i + 2] == \"0\") && (i > l.chomp.length - 4 || l[i + 3] != \"0\")\r\n nt = 2\r\n o += (\"a\"..\"z\").to_a[(x + l[i + 1]).to_i - 1]\r\n next\r\n end\r\n o += (\"a\"..\"z\").to_a[x.to_i - 1]\r\n end\r\n c[l]=o\r\n \r\n \r\n \r\n \r\n \r\n \r\n puts o\r\nend"}, {"source_code": "c = Hash.new(nil)\r\n$stdin.each_line.with_index do |l, i| next if i == 0 || i % 2 == 1\r\n puts c[l] if c[l] != nil\r\n nt = 0\r\n o = \"\"\r\n l.chomp.each_char.with_index do |x, i|\r\n if nt != 0\r\n nt -= 1\r\n next\r\n end\r\n if (i < (l.chomp.length - 2)) && (l[i + 2] == \"0\") && (i > l.chomp.length - 4 || l[i + 3] != \"0\")\r\n nt = 2\r\n o += (\"a\"..\"z\").to_a[(x + l[i + 1]).to_i - 1]\r\n next\r\n end\r\n o += (\"a\"..\"z\").to_a[x.to_i - 1]\r\n end\r\n c[l]=o\r\n puts o\r\nend"}, {"source_code": "\r\ndef solve(n, s)\r\n alphabets = ['@', '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']\r\n\r\n ans = ''\r\n i = n-1\r\n while i >= 0 do\r\n if s[i] == '0'\r\n ans += alphabets[s[(i-2)..(i-1)].to_i]\r\n i -= 3\r\n else\r\n ans += alphabets[s[i].to_i]\r\n # p alphabets[s[i].to_i]\r\n i -= 1\r\n end\r\n end\r\n ans.reverse!\r\n p ans\r\nend\r\n\r\nt = gets.chomp.to_i\r\nfor i in 1..t\r\n n = gets.chomp.to_i\r\n s = gets.chomp\r\n solve(n, s)\r\nend\r\n"}, {"source_code": "\r\ndef solve(n, s)\r\n alphabets = ['@', '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']\r\n\r\n ans = \"\"\r\n i = n-1\r\n while i >= 0 do\r\n if s[i] == '0'\r\n ans += alphabets[s[(i-2)..(i-1)].to_i]\r\n i -= 3\r\n else\r\n ans += alphabets[s[i].to_i]\r\n # p alphabets[s[i].to_i]\r\n i -= 1\r\n end\r\n end\r\n ans.reverse!\r\n p ans\r\nend\r\n\r\nt = gets.chomp.to_i\r\nfor i in 1..t\r\n n = gets.chomp.to_i\r\n s = gets.chomp\r\n solve(n, s)\r\nend\r\n"}, {"source_code": "\r\ndef debug(*arg)\r\n puts \"[DEBUG] #{arg.join \" \"}\"\r\nend\r\n\r\nt = gets.to_i\r\n\r\nalpha = ('a'.upto 'z').to_a\r\n\r\np alpha\r\n\r\nt.times do\r\n n = gets.to_i\r\n s = gets.chomp.chars\r\n\r\n ans = []\r\n until s.empty?\r\n last = s.pop\r\n if last == '0'\r\n ans << alpha[s[-2..].join.to_i - 1]\r\n s.pop; s.pop\r\n else\r\n ans << alpha[last.to_i - 1]\r\n end\r\n\r\n end\r\n puts ans.reverse.join(\"\")\r\nend"}], "src_uid": "43081557fe2fbac39dd9b72b137b8fb0"} {"source_code": "def read\r\n gets.split.map &:to_i\r\nend\r\ngets.to_i.times do\r\n n, k = read\r\n a = read\r\n s, res = a[0], 0\r\n (1...n).each do |i|\r\n res = [res, (100 * a[i] - k * s + k - 1) / k].max\r\n s += a[i]\r\n end\r\n puts res\r\nend", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, k = gets.split.map(&:to_i)\r\n ps0, *ps = gets.split.map(&:to_i)\r\n nps = (ps0..10 ** 12).bsearch do |ps0|\r\n x = ps0\r\n ps.all? do |p|\r\n p.to_f / x <= k / 100.0 && (x += p)\r\n end\r\n end\r\n p nps - ps0\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n,k=gets.split.map(&:to_i)\r\n q=gets.split.map(&:to_i)\r\n c=0\r\n s=q[0]\r\n 1.upto(n-1) do |i|\r\n if 100*q[i]-k*(s+c)>0\r\n c+=(100*q[i]-1)/k+1-s-c\r\n end\r\n s+=q[i]\r\n end\r\n puts c\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n n,k=gets.split.map(&:to_i)\r\n q=gets.split.map(&:to_i)\r\n c=0\r\n s=q[0]\r\n 1.upto(n-1) do |i|\r\n if 100*q[i]-k*(s+c)>0\r\n c+=(100*q[i]-1)/k+1-s\r\n end\r\n s+=q[i]\r\n end\r\n puts c\r\nend\r\n"}], "src_uid": "53975eea2503bb47bfd0a5119406aea3"} {"source_code": "require 'prime'\n\ndef divisors(n)\n res=[]\n (1..n**0.5).select{|i|n%i==0}.each{|i|\n res<= n\n ans = 1\n else\n d = 1\n while d * d <= n do\n if n % d == 0\n if (n / d) <= k && d < ans\n ans = d\n end\n if d <= k && (n / d) < ans\n ans = (n / d)\n end\n end\n d += 1\n end\n end\n puts ans\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i\n ok = 1e9 + 1\n (1..sq).each { |el|\n if n.modulo(el).zero?\n an1 = 1e9 + 1\n an2 = 1e9 + 1\n an1 = n / el if el <= k\n an2 = el if n / el <= k\n next if an1 == 1e9 + 1 && an2 == 1e9 + 1\n ok = [ok, an1, an2].min\n end\n }\n puts ok\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}], "negative_code": [{"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n n, k = gets.split.map(&:to_i)\n\n if n <= k\n puts \"1\"\n else\n # \ubc18\ub4dc\uc2dc \uc815\ud655\ud55c \uc218\ub7c9\ub9cc\ud07c \uad6c\uc785\ud574\uc57c\ud55c\ub2e4.\n # \uc624\ubc84\ud574\uc11c \ub0a8\uc740 \uc0bd\uc744 \ubc84\ub9b4 \uc218 \uc788\uc5c8\ub2e4\uba74 \uc27d\uac8c \ud480\uc5c8\uaca0\uc9c0?\n sqn = Math.sqrt(n).ceil\n m = 1\n packs = n\n r = [sqn, k].min\n for i in 0...(r-1)\n if n % (r-i) == 0\n m = r-i\n packs = n/m\n\n if m < packs && packs <= k\n m, packs = packs, m\n end\n break\n end\n end\n\n puts \"#{packs}\"\n end\n}"}, {"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n n, k = gets.split.map(&:to_i)\n\n if n <= k\n puts \"1\"\n else\n # \ubc18\ub4dc\uc2dc \uc815\ud655\ud55c \uc218\ub7c9\ub9cc\ud07c \uad6c\uc785\ud574\uc57c\ud55c\ub2e4.\n # \uc624\ubc84\ud574\uc11c \ub0a8\uc740 \uc0bd\uc744 \ubc84\ub9b4 \uc218 \uc788\uc5c8\ub2e4\uba74 \uc27d\uac8c \ud480\uc5c8\uaca0\uc9c0?\n # 1..k \uac1c\uae4c\uc9c0\uc758 \ud328\ud0a4\uc9c0\ub97c \uad6c\uc131\ud560 \uc218 \uc788\uace0, \uc774 \uc548\uc5d0\uc11c \uc5ec\ub7ec\ubc88 \ubc18\ubcf5\ud574\uc11c \uad6c\uc785\ud560 \uc218 \uc788\ub2e4.\n # k \ubc94\uc704 \ub0b4\uc5d0\uc11c \uac00\uc7a5 \ud070, n\uc758 \uc18c\uc778\uc218\ub97c \ucc3e\uc544\uc57c\ud55c\ub2e4.\n sqn = Math.sqrt(n).ceil\n m = 1\n for i in 2..([sqn, k].min)\n if n%i == 0\n m = i\n break\n end\n end\n\n puts \"#{[n/m, m].min}\"\n end\n}"}, {"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n n, k = gets.split.map(&:to_i)\n\n if n <= k\n puts \"1\"\n else\n # \ubc18\ub4dc\uc2dc \uc815\ud655\ud55c \uc218\ub7c9\ub9cc\ud07c \uad6c\uc785\ud574\uc57c\ud55c\ub2e4.\n # \uc624\ubc84\ud574\uc11c \ub0a8\uc740 \uc0bd\uc744 \ubc84\ub9b4 \uc218 \uc788\uc5c8\ub2e4\uba74 \uc27d\uac8c \ud480\uc5c8\uaca0\uc9c0?\n sqn = Math.sqrt(n).ceil\n m = 1\n for i in 2..([sqn, k].min)\n if n%i == 0\n m = i\n end\n end\n\n if m == 1\n puts n\n else\n puts \"#{[n/m, m].min}\"\n end\n end\n}"}, {"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n n, k = gets.split.map(&:to_i)\n\n if n <= k\n puts \"1\"\n else\n # \ubc18\ub4dc\uc2dc \uc815\ud655\ud55c \uc218\ub7c9\ub9cc\ud07c \uad6c\uc785\ud574\uc57c\ud55c\ub2e4.\n # \uc624\ubc84\ud574\uc11c \ub0a8\uc740 \uc0bd\uc744 \ubc84\ub9b4 \uc218 \uc788\uc5c8\ub2e4\uba74 \uc27d\uac8c \ud480\uc5c8\uaca0\uc9c0?\n sqn = Math.sqrt(n).ceil\n m = 1\n packs = n\n r = [sqn, k].min\n for i in 0...(r-1)\n if n % (r-i) == 0\n m = r-i\n packs = n/m\n\n if m < packs\n m, packs = packs, m\n end\n break\n end\n end\n\n puts \"#{packs}\"\n end\n}"}, {"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n n, k = gets.split.map(&:to_i)\n\n if n <= k\n puts \"1\"\n else\n # \ubc18\ub4dc\uc2dc \uc815\ud655\ud55c \uc218\ub7c9\ub9cc\ud07c \uad6c\uc785\ud574\uc57c\ud55c\ub2e4.\n # \uc624\ubc84\ud574\uc11c \ub0a8\uc740 \uc0bd\uc744 \ubc84\ub9b4 \uc218 \uc788\uc5c8\ub2e4\uba74 \uc27d\uac8c \ud480\uc5c8\uaca0\uc9c0?\n # 1..k \uac1c\uae4c\uc9c0\uc758 \ud328\ud0a4\uc9c0\ub97c \uad6c\uc131\ud560 \uc218 \uc788\uace0, \uc774 \uc548\uc5d0\uc11c \uc5ec\ub7ec\ubc88 \ubc18\ubcf5\ud574\uc11c \uad6c\uc785\ud560 \uc218 \uc788\ub2e4.\n # k \ubc94\uc704 \ub0b4\uc5d0\uc11c \uac00\uc7a5 \ud070, n\uc758 \uc18c\uc778\uc218\ub97c \ucc3e\uc544\uc57c\ud55c\ub2e4.\n sqn = Math.sqrt(n).ceil\n m = 1\n for i in 2..([sqn, k].min)\n if n%i == 0\n m = i\n end\n end\n\n puts \"#{n/m}\"\n end\n}"}, {"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n n, k = gets.split.map(&:to_i)\n\n if n <= k\n puts \"1\"\n else\n # \ubc18\ub4dc\uc2dc \uc815\ud655\ud55c \uc218\ub7c9\ub9cc\ud07c \uad6c\uc785\ud574\uc57c\ud55c\ub2e4.\n # \uc624\ubc84\ud574\uc11c \ub0a8\uc740 \uc0bd\uc744 \ubc84\ub9b4 \uc218 \uc788\uc5c8\ub2e4\uba74 \uc27d\uac8c \ud480\uc5c8\uaca0\uc9c0?\n # 1..k \uac1c\uae4c\uc9c0\uc758 \ud328\ud0a4\uc9c0\ub97c \uad6c\uc131\ud560 \uc218 \uc788\uace0, \uc774 \uc548\uc5d0\uc11c \uc5ec\ub7ec\ubc88 \ubc18\ubcf5\ud574\uc11c \uad6c\uc785\ud560 \uc218 \uc788\ub2e4.\n # k \ubc94\uc704 \ub0b4\uc5d0\uc11c \uac00\uc7a5 \ud070, n\uc758 \uc18c\uc778\uc218\ub97c \ucc3e\uc544\uc57c\ud55c\ub2e4.\n sqn = Math.sqrt(n).ceil\n m = 1\n for i in 2..([sqn, k].min)\n if n%i == 0\n m = i\n break\n end\n end\n\n puts \"#{n/m}\"\n end\n}"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i\n (1..sq).each { |el|\n if n.modulo(el).zero? && el <= k\n puts el\n return\n end\n }\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i\n an = 0\n (1..sq).each { |el|\n if n.modulo(n / el).zero? && n / el <= k\n an = el\n end\n }\n puts an\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i\n (1..sq).each { |el|\n if n.modulo(el).zero?\n an1 = 1e9 + 1\n an2 = 1e9 + 1\n an1 = n / el if el <= k\n an2 = el if n / el <= k\n next if an1 == 1e9 + 1 && an2 == 1e9 + 1\n puts [an1, an2].min\n return\n end\n }\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i + 1\n (1..sq).each { |el|\n if n.modulo(el).zero? && (n / el) <= k\n puts el\n return nil\n end\n }\n puts n\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i\n (1..sq).each { |el|\n if n.modulo(el).zero? && (n / el) <= k\n puts el\n return nil\n end\n }\n #puts \"dasdasd\"\n puts n\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i + 1\n an = 0\n (1..sq).each { |el|\n an = n / el if n.modulo(el).zero? && el <= k\n an = n / (n / el) if n.modulo(n / el).zero? && n / el <= k\n }\n puts an\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i + 1\n an = 0\n (1..sq).each { |el|\n if n.modulo(el).zero? && el <= k\n an = n / el\n end\n }\n puts an\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i\n an = 0\n (1..sq).each { |el|\n an = n / el if n.modulo(el).zero? && el <= k\n an = n / (n / el) if n.modulo(n / el).zero? && n / el <= k\n }\n puts an\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i\n ok = 0\n (1..sq).each { |el|\n if n.modulo(el).zero?\n an1 = 1e9 + 1\n an2 = 1e9 + 1\n an1 = n / el if el <= k\n an2 = el if n / el <= k\n next if an1 == 1e9 + 1 && an2 == 1e9 + 1\n ok = [an1, an2].min\n end\n }\n puts ok\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i + 1\n (1..sq).each { |el|\n if n.modulo(el).zero? && (n / el).to_f <= k\n puts el\n return nil\n end\n }\n puts n\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(k).to_i + 1\n (1..sq).each { |el|\n if n.modulo(el).zero?\n puts el\n return nil\n end\n }\n puts n\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i + 1\n (1..sq).each { |el|\n if n.modulo(el).zero? && (n / el) <= k\n puts el\n return nil\n end\n }\n #puts \"dasdasd\"\n puts n\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i\n (1..sq).each { |el|\n if (n % el).zero? && (n / el) <= k\n puts el\n return nil\n end\n }\n #puts \"dasdasd\"\n puts n\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n if n == k\n puts 1\n return nil \n end\n sq = Math.sqrt(n).to_i + 1\n an = 0\n (1..sq).each { |el|\n if n.modulo(el).zero? && el <= k\n an = n / el\n end\n }\n puts an\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}, {"source_code": "def solve\n n, k = gets.strip.split(' ').map(&:to_i)\n sq = Math.sqrt(n).to_i\n (1..sq).each { |el|\n if n.modulo(n / el).zero? && n / el <= k\n puts el\n return;\n end\n }\nend\n\ngets.strip.to_i.times do\n solve\nend\n"}], "src_uid": "f00eb0452f5933103f1f77ef06473c6a"} {"source_code": "N, K, s = gets.split.map(&:to_i)\nif (N-1)*K < s || K > s\n puts 'NO'\n exit\nend\n\nans = []\nnow = 1\ns -= K\nK.times do |i|\n add = [s, N-2].min\n s -= add\n now += (add+1) * (i%2==0 ? 1 : -1)\n ans.push(now)\nend\nputs 'YES'\nputs ans.join(' ')", "positive_code": [{"source_code": "def solution\n n, k, s = read_ints\n\n if k > s\n puts \"NO\"\n return\n end\n\n if k * (n - 1) < s\n puts \"NO\"\n return\n end\n\n rs = s\n\n dir = 1\n crt = 1\n path = []\n\n k.times do |j|\n rk = k - j\n\n move = (rs.to_f / rk).ceil * dir\n dir *= -1\n rs -= move.abs\n\n crt = crt + move\n path << crt\n end\n\n puts \"YES\"\n puts path.join(' ')\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"}], "negative_code": [{"source_code": "\ndef solution\n n, k, s = read_ints\n\n if k > s\n puts \"NO\"\n return\n end\n\n if s.to_f / k > (n-1)\n puts \"NO\"\n return\n end\n\n crt = 1\n rs = s\n rk = k\n\n path = []\n\n while rs > 0\n steps_per_move = (rs.to_f / rk).ceil\n if crt < steps_per_move\n goto = crt + steps_per_move\n else\n goto = crt - steps_per_move\n end\n\n rs -= (goto-crt).abs\n rk -= 1\n\n path << goto\n crt = goto\n end\n\n puts 'YES'\n puts path.join(' ')\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"}], "src_uid": "2cc44c5a084688025c16b0394c98b2f6"} {"source_code": "#!/usr/bin/env ruby\n# encoding: utf-8\ngood = gets.to_str.chomp\npattern = gets.to_str\nkey = pattern.strip.gsub(\"?\",\"[\"+good+\"]\").gsub(\"*\",\"[^\"+good+\"]*\")\nrg = Regexp.new(\"^\"+key+\"$\")\n\nn = gets.to_i\nn.times do\n buf = gets.to_str\n if rg =~ buf\n puts \"YES\"\n else\n puts \"NO\"\n end\nend", "positive_code": [{"source_code": "# Codeforces My Practice\n# author: Leonardone @ NEETSDKASU\n\ngl = [false] * 256\ngets.strip.each_char do |c|\n gl[c.swapcase.ord] = true\n gl[c.ord] = true\nend\npt = (\"[\" + gets.strip + \"]\").split \"*\"\nn = gets.to_i\nif pt.size == 1\n px = pt[0]\n n.times do\n s = gets.strip\n if s.size != px.size - 2\n puts :NO\n next\n end\n ok = true\n s.size.times do |i|\n next if s[i] == px[i+1]\n if px[i+1] == '?'\n next if gl[s[i].ord]\n end\n ok = false\n break\n end\n puts ok ? :YES : :NO\n end\n exit\nend\n\npx, py = pt\nn.times do\n s = gets.strip\n if s.size < px.size + py.size - 2\n puts :NO\n next\n end\n ok = true\n (px.size-1).times do |i|\n next if s[i] == px[i+1]\n if px[i+1] == '?'\n next if gl[s[i].ord]\n end\n ok = false\n break\n end\n if !ok\n puts :NO\n next\n end\n (py.size-1).times do |i|\n next if s[-i-1] == py[-i-2]\n if py[-i-2] == '?'\n next if gl[s[-i-1].ord]\n end\n ok = false\n break\n end\n if !ok\n puts :NO\n next\n end\n u = s.size - (px.size + py.size - 2)\n u.times do |i|\n next if !gl[s[i+px.size-1].ord]\n ok = false\n break\n end\n puts ok ? :YES : :NO\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n# encoding: utf-8\ngood = gets.to_str.chomp\npattern = gets.to_str\nkey = pattern.strip.gsub(\"?\",\"[\"+good+\"]\").gsub(\"*\",\"[^\"+good+\"]*\")\nrg = Regexp.new(\"^\"+key+\"$\")\n\nn = gets.to_i\nn.times do\n buf = gets.to_str\n if rg =~ buf\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n# encoding: utf-8\ngood = gets.to_str.chomp\npattern = gets.to_str\nkey = pattern.strip.gsub(\"?\",\"[\"+good+\"]\").gsub(\"*\",\"[^\"+good+\"]*\")\nrg = Regexp.new(\"^\"+key+\"$\")\n\nn = gets.to_i\nn.times do\n buf = gets.to_str\n if rg =~ buf\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\n# encoding: utf-8\ngood = gets.to_str.chomp!\npattern = gets.to_str\nkey = \"\"\npattern.each_char do | c |\n if c == '?'\n key+=\"[\"+good+\"]\"\n elsif c == '*'\n key+=\"[^\"+good+\"]{0,1}\"\n else\n key+=c\n end\nend\n\nha = Regexp.new(key)\n\nn = gets.to_i\nn.times do | i |\n buf = gets.to_str\n m=ha.match(buf).to_s\n if m == nil\n puts(\"NO\")\n elsif m == buf\n puts(\"YES\")\n else\n puts(\"NO\")\n end\nend\n"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ngl = gets.strip\npt = gets.strip.gsub(\"?\",\"[\" + gl + \"]\").gsub(\"*\", \".?\")\nrg = Regexp.compile(\"^\" + pt + \"$\")\nn = gets.to_i\nn.times do\n s = gets.strip\n if s =~ rg\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ngl = gets.strip\npt = gets.strip.gsub(\"?\",\"[\" + gl + \"]\").gsub(\"*\", \".*\")\nrg = Regexp.compile(\"^\" + pt + \"$\", Regexp::IGNORECASE)\nn = gets.to_i\nn.times do\n s = gets.strip\n if s =~ rg\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\ngl = gets.strip\npt = gets.strip.gsub(\"?\",\"[\" + gl + \"]\").gsub(\"*\", \".?\")\nrg = Regexp.compile(\"^\" + pt + \"$\", Regexp::IGNORECASE)\nn = gets.to_i\nn.times do\n s = gets.strip\n if s =~ rg\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n"}], "src_uid": "c6633581d7424d670eaa0f8a5c8cc366"} {"source_code": "n, k = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\nh = Hash.new(0)\narr.each do |e|\n h[e] += 1\nend\nh.values.each do |v|\n if v > k\n puts \"NO\"\n exit\n end\nend\ncur_c = 0\nprev_cur_c = 0\nf = false\nres = [0] * arr.size\nmp = Array.new(k) {Array.new}\narr.each_with_index do |e, ind|\n while mp[cur_c].include?(e)\n if cur_c == prev_cur_c\n puts \"NO\"\n exit\n end\n cur_c = (cur_c + 1) % k\n end\n mp[cur_c] << e\n res[ind] = cur_c\n prev_cur_c = cur_c\n cur_c = (cur_c + 1) % k\nend\nputs \"YES\"\nputs res.map{|x| x + 1}.join(\" \")", "positive_code": [{"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = Array.new(5005) { [] }\na.each_with_index { |x, i| b[x] << i }\n\nc = 1\nans = [-1] * n\nb.each do |pos|\n\tputs('NO') + exit if pos.size > k\n\tpos.each do |i|\n\t\tans[i] = c\n\t\tc = c < k ? c + 1 : 1\n\tend\nend\nputs 'YES', ans.join(' ')\n"}, {"source_code": "input = STDIN.read.split(\"\\n\").map{|l| l.split(\" \").map{|a| a.to_i}}\nfirst = input.shift\nARR = input.shift\nN = first[0]\nCOLORS = first[1]\n\nNUM_USED_COLORS = {}\nremained_color_i = 0\n\ndic = {}\nis_no = false\n\ncolored_arr = []\n\nfor i in ARR\n if !NUM_USED_COLORS.key?(i)\n NUM_USED_COLORS[i] = {}\n end\n\n if remained_color_i < COLORS\n NUM_USED_COLORS[i][remained_color_i] = true\n colored_arr.push(remained_color_i)\n remained_color_i = remained_color_i + 1\n else\n found = false\n for j in 0..(COLORS - 1)\n if !NUM_USED_COLORS[i].key?(j)\n NUM_USED_COLORS[i][j] = true\n colored_arr.push(j)\n found = true\n break\n end\n end\n if found == false\n is_no = true\n end\n end\n if is_no == true\n break\n end\nend\n\nif is_no\n puts 'NO'\nelse\n puts 'YES'\n puts colored_arr.map{|i| i + 1}.join(' ')\nend"}, {"source_code": "N,K = gets.split.map(&:to_i)\nns = {}\nis = []\na = gets.split.map(&:to_i)\na.each_with_index{ |x,i| ns[x] = (ns[x] || 0) + 1; is << [x,i] }\nif ns.values.max > K || N < K\n puts \"NO\"; exit\nend\nc = -1\nis.sort!\n#p is\nis.each{ |x,i|\n a[i] = (c += 1) % K + 1\n}\nputs \"YES\", a.join(\" \")"}, {"source_code": "# Input\nn, k = gets.split(\" \").map { |e| e.to_i }\na = gets.split(\" \").map { |e| e }\n\n# Processing\ncount = Hash.new(0)\na.each { |n| count[n] += 1 }\n\ncurrent_color = Hash.new(count)\ni = 1\ncount.each do |n, c|\n if c > k\n puts \"NO\"\n #puts \"#{n} amount > k\"\n exit\n end\n current_color[n] = i\n i = (i + c - 1) % k + 1\n end\n\nc = Array.new(n) do |i|\n #puts current_color\n color = current_color[a[i]]\n current_color[a[i]] = current_color[a[i]] % k + 1\n color\nend\n\n# Output\nputs \"YES\"\nputs c.join(\" \")\n"}], "negative_code": [{"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = Array.new(10) { [] }\na.each_with_index { |x, i| b[x] << i }\n\nc = 1\nans = [-1] * n\nb.each do |pos|\n\tputs('NO') + exit if pos.size > k\n\tpos.each do |i|\n\t\tans[i] = c\n\t\tc = c < k ? c + 1 : 1\n\tend\nend\nputs 'Yes', ans.join(' ')\n"}, {"source_code": "# Input\nn, k = gets.split(\" \").map { |e| e.to_i }\na = gets.split(\" \").map { |e| e }\n\n# Processing\ncount = Hash.new(0)\ncurrent_color = Hash.new\n\na.each do |n|\n count[n] += 1\nend\n\nif count.length < k\n puts \"NO\"\n exit\nend\ncount.each do |n, amount|\n if amount > k\n puts \"NO\"\n exit\n end\n current_color[n] = (current_color.length % k) + 1\nend\n\nc = Array.new(n) do |i|\n #puts current_color\n color = current_color[a[i]]\n current_color[a[i]] = current_color[a[i]] % k + 1\n color\nend\n\n# Output\nputs \"YES\"\nputs c.join(\" \")\n"}, {"source_code": "# Input\nn, k = gets.split(\" \").map { |e| e.to_i }\na = gets.split(\" \").map { |e| e }\n\n# Processing\ncount = Hash.new(0)\na.each { |n| count[n] += 1 }\n\ncurrent_color = Hash.new(count)\ni = 1\ncount.each do |n, c|\n current_color[n] = i\n i = (i + c) % k + 1\n end\n\nc = Array.new(n) do |i|\n #puts current_color\n color = current_color[a[i]]\n current_color[a[i]] = current_color[a[i]] % k + 1\n color\nend\n\n# Output\nputs \"YES\"\nputs c.join(\" \")\n"}, {"source_code": "# Input\nn, k = gets.split(\" \").map { |e| e.to_i }\na = gets.split(\" \").map { |e| e }\n\n# Processing\ncount = Hash.new(0)\na.each { |n| count[n] += 1 }\n\ncurrent_color = Hash.new(count)\ni = 1\ncount.each do |n, c|\n if c > k\n puts \"NO\"\n #puts \"#{n} amount > k\"\n exit\n end\n current_color[n] = i\n i = (i + c) % k + 1\n end\n\nc = Array.new(n) do |i|\n #puts current_color\n color = current_color[a[i]]\n current_color[a[i]] = current_color[a[i]] % k + 1\n color\nend\n\n# Output\nputs \"YES\"\nputs c.join(\" \")\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\nh = Hash.new(0)\narr.each do |e|\n h[e] += 1\nend\nh.values.each do |v|\n if v > k\n puts \"NO\"\n exit\n end\nend\ncur_c = 0\nprev_cur_c = 0\nf = false\nres = [0] * arr.size\nmp = Array.new(k) {Array.new}\narr.each_with_index do |e, ind|\n while mp[cur_c].include?(e)\n cur_c += 1\n if cur_c == prev_cur_c\n puts \"NO\"\n exit\n end\n end\n mp[cur_c] << e\n res[ind] = cur_c\nend\nputs \"YES\"\nputs res.map{|x| x + 1}.join(\" \")"}, {"source_code": "N,K = gets.split.map(&:to_i)\nns = {}\nA = gets.split.map(&:to_i)\nA.each{ |x| ns[x] = (ns[x] || 0) + 1 }\nif ns.values.max > K\n puts \"NO\"; exit\nend\nputs \"YES\", A.map{ |x| (ns[x] -= 1) + 1 }.join(\" \")"}], "src_uid": "3d4df21eebf32ce15841179bb85e6f2f"} {"source_code": "f = 1 \nas = gets.split.map(&:to_i)\nn = as[0]\nd = as[1]\nk = as[2]\ntr = Array.new(n+5)\ni = 0\nwhile i<=n\n tr[i] = Array.new\n i+=1\nend\n\nnode = 0\nfor i in 1..d\n if i>=n\n f = 0\n break\n end\n tr[i].push(i+1)\n tr[i+1].push(i)\n node = i+1\n if tr[i].size>k || tr[node].size>k\n f = 0\n break\n end\nend\n\ndep = Array.new(n+5)\nvis = Array.new(n+5)\no = 0\nwhile o<=n\n dep[o] = 0\n vis[o] = 0\n o+=1\nend\ncen1 = 0\ncen2 = 0\nmx_dep = 0\nif node%2==1\n cen1 = (node+1)/2\n mx_dep = cen1-1\nelse \n cen1 = node/2\n cen2 = cen1+1\n mx_dep = cen1-1\nend\ndep[cen1] = 0\ndep[cen2] = 0\nvis[cen1] = 1\nvis[cen2] = 1\nc = 1\nwhile node0\n c+=1\n q=Array.new\n if cen1 > 0\n q.push(cen1)\n cen1 = 0\n elsif cen2>0 \n q.push(cen2)\n cen2 = 0\n end\n \n while q.length > 0\n a = q.first\n q.shift\n if tr[a].size>k\n f = 0\n break\n end\n while tr[a].length0\n next\n end\n q.push(ii)\n vis[ii] = 1\n dep[ii] = dep[a] + 1\n end\n end\n\nend\n\nif f==0 || node!=n\n puts \"NO\"\nelse \n puts \"YES\"\n for z in (1..n) \n vis[z] = 0\n end \n for j in (1..n)\n for z in tr[j]\n if vis[z]>0 && vis[j]>0\n next\n end\n vis[z] = 1\n vis[j] = 1\n puts \"#{j} #{z}\"\n end\n end \nend\n=begin\n=end", "positive_code": [{"source_code": "f = true \nas = gets.split.map(&:to_i)\nn = as[0]\nd = as[1]\nk = as[2]\ntr = Array.new(n+5)\ni = 0\nwhile i<=n\n tr[i] = Array.new\n i+=1\nend\nnode = 0\nfor i in 1..d\n if i>=n\n f = false\n break\n end\n tr[i].push(i+1)\n tr[i+1].push(i)\n node = i+1\n if tr[i].size>k || tr[node].size>k\n f = false\n break\n end\nend\ndep = Array.new(n+5)\nvis = Array.new(n+5)\no = 0\nwhile o<=n\n dep[o] = 0\n vis[o] = 0\n o+=1\nend\ncen1 = 0\ncen2 = 0\nmx_dep = 0\nif node%2==1\n cen1 = (node+1)/2\n mx_dep = cen1-1\nelse \n cen1 = node/2\n cen2 = cen1+1\n mx_dep = cen1-1\nend\ndep[cen1] = 0\ndep[cen2] = 0\nvis[cen1] = 1\nvis[cen2] = 1\nc = 1\nwhile node 0\n q.push(cen1)\n cen1 = 0\n elsif cen2>0 \n q.push(cen2)\n cen2 = 0\n end \n while q.length > 0\n a = q.first\n q.shift\n if tr[a].size>k\n f = false\n break\n end\n while tr[a].length0\n next\n end\n q.push(ii)\n vis[ii] = 1\n dep[ii] = dep[a] + 1\n end\n end\n\nend\nif !f || node!=n\n puts \"NO\"\nelse \n puts \"YES\"\n for z in (1..n) \n vis[z] = 0\n end \n for j in (1..n)\n for z in tr[j]\n if vis[z]>0 && vis[j]>0\n next\n end\n vis[z] = 1\n vis[j] = 1\n puts \"#{j} #{z}\"\n end\n end \nend"}, {"source_code": "f = true \nas = gets.split.map(&:to_i)\nn = as[0]\nd = as[1]\nk = as[2]\ntr = Array.new(n+5)\ni = 0\nwhile i<=n\n tr[i] = Array.new\n i+=1\nend\n\nnode = 0\nfor i in 1..d\n if i>=n\n f = false\n break\n end\n tr[i].push(i+1)\n tr[i+1].push(i)\n node = i+1\n if tr[i].size>k || tr[node].size>k\n f = false\n break\n end\nend\n\ndep = Array.new(n+5)\nvis = Array.new(n+5)\no = 0\nwhile o<=n\n dep[o] = 0\n vis[o] = 0\n o+=1\nend\ncen1 = 0\ncen2 = 0\nmx_dep = 0\nif node%2==1\n cen1 = (node+1)/2\n mx_dep = cen1-1\nelse \n cen1 = node/2\n cen2 = cen1+1\n mx_dep = cen1-1\nend\ndep[cen1] = 0\ndep[cen2] = 0\nvis[cen1] = 1\nvis[cen2] = 1\nc = 1\nwhile node 0\n q.push(cen1)\n cen1 = 0\n elsif cen2>0 \n q.push(cen2)\n cen2 = 0\n end\n \n while q.length > 0\n a = q.first\n q.shift\n if tr[a].size>k\n f = false\n break\n end\n while tr[a].length0\n next\n end\n q.push(ii)\n vis[ii] = 1\n dep[ii] = dep[a] + 1\n end\n end\n\nend\n\nif !f || node!=n\n puts \"NO\"\nelse \n puts \"YES\"\n for z in (1..n) \n vis[z] = 0\n end \n for j in (1..n)\n for z in tr[j]\n if vis[z]>0 && vis[j]>0\n next\n end\n vis[z] = 1\n vis[j] = 1\n puts \"#{j} #{z}\"\n end\n end \nend\n=begin\n=end"}], "negative_code": [{"source_code": "f = true \nas = gets.split.map(&:to_i)\nn = as[0]\nd = as[1]\nk = as[2]\ntr = Array.new(n+5)\ni = 0\nwhile i<=n\n tr[i] = Array.new\n i+=1\nend\n\nnode = 0\nfor i in 1..d\n if i>=n\n f = false\n break\n end\n tr[i].push(i+1)\n tr[i+1].push(i)\n node = i+1\nend\n\ndep = Array.new(n+5)\nvis = Array.new(n+5)\no = 0\nwhile o<=n\n dep[o] = 0\n vis[o] = 0\n o+=1\nend\ncen1 = 0\ncen2 = 0\nmx_dep = 0\nif node%2==1\n cen1 = (node+1)/2\n mx_dep = cen1-1\nelse \n cen1 = node/2\n cen2 = cen1+1\n mx_dep = cen1-1\nend\ndep[cen1] = 0\ndep[cen2] = 0\nvis[cen1] = 1\nvis[cen2] = 1\nc = 1\nwhile node 0\n q.push(cen1)\n cen1 = 0\n elsif cen2>0 \n q.push(cen2)\n cen2 = 0\n end\n \n while q.length > 0\n a = q.first\n q.shift\n while tr[a].length0\n next\n end\n q.push(ii)\n vis[ii] = 1\n dep[ii] = dep[a] + 1\n end\n end\n\nend\n\nfor z in (1..n) \n vis[z] = 0\nend \n\nif !f || node!=n\n puts \"NO\"\nelse \n puts \"YES\"\n for j in (1..n)\n for z in tr[j]\n if vis[z]>0 && vis[j]>0\n next\n end\n vis[z] = 1\n vis[j] = 1\n puts \"#{j} #{z}\"\n end\n end \nend\n=begin\n=end"}, {"source_code": "f = true \nas = gets.split.map(&:to_i)\nn = as[0]\nd = as[1]\nk = as[2]\ntr = Array.new(n+5)\ni = 0\nwhile i<=n\n tr[i] = Array.new\n i+=1\nend\n\nnode = 0\nfor i in 1..d\n if i>=n\n f = false\n break\n end\n tr[i].push(i+1)\n tr[i+1].push(i)\n node = i+1\nend\n\ndep = Array.new(n+5)\nvis = Array.new(n+5)\no = 0\nwhile o<=n\n dep[o] = 0\n vis[o] = 0\n o+=1\nend\ncen1 = 0\ncen2 = 0\nmx_dep = 0\nif node%2==1\n cen1 = (node+1)/2\n mx_dep = cen1-1\nelse \n cen1 = node/2\n cen2 = cen1+1\n mx_dep = cen1-1\nend\ndep[cen1] = 0\ndep[cen2] = 0\nvis[cen1] = 1\nvis[cen2] = 1\nc = 1\nwhile node 0\n q.push(cen1)\n cen1 = 0\n elsif cen2>0 \n q.push(cen2)\n cen2 = 0\n end\n \n while q.length > 0\n a = q.first\n q.shift\n if tr[a].length>k\n f=0\n end\n while tr[a].length0\n next\n end\n q.push(ii)\n vis[ii] = 1\n dep[ii] = dep[a] + 1\n end\n end\n\nend\n\nfor z in (1..n) \n vis[z] = 0\nend \n\nif !f || node!=n\n puts \"NO\"\nelse \n puts \"YES\"\n for j in (1..n)\n for z in tr[j]\n if vis[z]>0 && vis[j]>0\n next\n end\n vis[z] = 1\n vis[j] = 1\n puts \"#{j} #{z}\"\n end\n end \nend\n=begin\n=end"}], "src_uid": "a4849505bca48b408a5e8fb5aebf5cb6"} {"source_code": "n = gets.chomp.to_i\n(0...n).each do |i|\n s = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n asize = a.size\n count1 = 0\n count2 = 0\n a.each_with_index do |item,j|\n if j % 2 == 0\n if item % 2 != 0\n count1 += 1\n end\n end\n if j % 2 != 0\n if item % 2 == 0\n count2 += 1\n end\n end\n end\n if count1 != count2\n puts \"-1\"\n else\n puts count1\n end\nend", "positive_code": [{"source_code": "n = gets.chomp.to_i\nn.times do \n\tt = gets.chomp.to_i\n\tarr = gets.chomp.split.map{|a| a.to_i % 2}\n\tiar = (0..arr.length-1).to_a.map{|i| i % 2}\t\n\tcnt0 = 0\n\tcnt1 = 0\n\tarr.length.times do |i|\n\t\tif arr[i] != iar[i]\n\t\t\tif arr[i] == 0\n\t\t\t\tcnt0 += 1\n\t\t\telse\n\t\t\t\tcnt1 += 1\n\t\t\tend\n\t\tend\n\tend\n\t\t\n\t# p arr\n\t# p iar\n\t# puts cnt0\n\t# puts cnt1\n\tif cnt0 == 0 && cnt1 == 0 \n\t\tputs 0\n\telsif cnt0 == cnt1\n\t\tputs cnt0\n\telse\n\t\tputs -1\n\tend\nend\n\n\n\n"}, {"source_code": "gets.to_i.times do\n gets\n a = gets.split(' ').map(&:to_i)\n\n res = [0, 0]\n\n a.each_with_index { |v, i| res[i%2] += 1 if i.odd? != v.odd? }\n\n puts -1 if res.first != res.last\n puts res.first if res.first == res.last\nend\n"}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tb = (0...n).map { _1 % 2 }\n\tif [0, 1].all? { |k| a.count { _1 % 2 == k } == b.count { _1 % 2 == k } }\n\t\tputs (0...n).count { a[_1] % 2 != b[_1] % 2 } / 2\n\telse\n\t\tputs -1\n\tend\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n\tn = gets.to_i\n\till_evens = 0\n\till_odds = 0\n\todds = []\n\tgets.split.each_with_index do |w, i|\n\t\tif w.to_i.even?\n\t\t\till_evens += 1 if i.odd?\n\t\telse\n\t\t\till_odds += 1 if i.even?\n\t\tend\n\tend\n\n\tif ill_evens != ill_odds\n\t\tp -1\n\t\tnext\n\tend\n\n\tp ill_evens\n\t\nend\n"}, {"source_code": "def count_arr(a,n)\n\n odds = 0\n evens = 0\n i=0\n\n while i= arr[1])\n puts -1\n else\n puts arr[2]\n end\n end\nend\n"}, {"source_code": "\ngets.chomp.to_i.times do\n\n n = gets.chomp.to_i\n\n a = gets.chomp.split(\" \").map { |e| e.to_i }\n\n i=0\n count =0\n while i'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a 0.8)\n puts 12\n end\n ans.push(s)\nend\nputs ans"}], "src_uid": "98c08a3b5e5b5bb78804ff797ba24d87"} {"source_code": "$stdin = File.open(\"input.txt\")\n$stdout = File.open(\"output.txt\",\"w\")\n\nn = gets.chomp.to_i\nH = {}\ngets.chomp.split.each do |c|\n\tkey = c.to_i\n\tif H.has_key? key\n\t\tH[key] += 1\n\telse\n\t\tH[key] = 1\n\tend\nend\nA = Array.new(5000,0)\nfor c in 1..5000 do\n\tA[c] = A[c-1] + (H.has_key?(c) ? H[c] : 0)\nend\nsol = 99999\nfor c in 1..2500 do\n\tsol = [sol , A[c-1] + (A[5000] - A[c*2])].min\nend\nputs sol", "positive_code": [{"source_code": "\ufeff# -*- encoding: utf-8 -*-\n\n$stdin = File.open(\"input.txt\")\n$stdout = File.open(\"output.txt\", \"w\")\n\nn = gets.chomp.to_i\nc = {}\ngets.chomp.split(\" \").each do |n|\n key = n.to_i\n if c.has_key? key\n c[key] += 1\n else\n c[key] = 1\n end\nend\n\nfield = Array.new(5000, 0)\n\nfor i in 1 .. 5000 do\n field[i] = field[i - 1] + (c.has_key?(i) ? c[i] : 0)\nend\nans = 99999\nfor i in 1 .. 2500 do\n ans = [ans, field[i - 1] + (field[5000] - field[i * 2])].min\nend\n\nputs ans\n "}], "negative_code": [], "src_uid": "80cf3ea119fd398e8f003d22a76895a7"} {"source_code": "gets.to_i.times do\n n,q=gets.split.map(&:to_i)\n a=gets.split.map(&:to_i)\n m=Array.new(n+1)\n m[0]=0\n n.times {|i| m[i+1]=[m[i],a[i]].max}\n s=[0]\n a.each {|i| s << s[-1]+i}\n k=gets.split.map(&:to_i)\n puts k.map {|i| \n ans=m.bsearch_index {|j| j>i}\n ans.nil? ? s[n] : s[ans-1]\n }*' '\nend\n", "positive_code": [{"source_code": "t=gets.to_i\nt.times do\n n,q= gets.split.map(&:to_i)\n arr=gets.split.map(&:to_i)\n qs=gets.split.map(&:to_i)\n rslt=[]\n cur,sum=0,0\n arr.each do |x|\n if cur>=x\n sum+=x\n else\n rslt.push [cur,sum]\n cur=x\n sum+=x\n end\n end\n rslt.push [cur,sum]\n rslt.push [sum,sum]\n i=0\n while i=x}[1])\n if idx==qs.length-1\n puts\n else\n print ' '\n end\n end\nend\n\n"}], "negative_code": [], "src_uid": "d5f7228d8d674b8233937702ca044cb0"} {"source_code": "number = gets.chomp.to_i\nvectors = []\n\ni = 0\nwhile i < number\n\tx = gets.chomp\n\tvectors << x.split(\" \")\n\ti += 1\nend\n\nx = 0\ny = 0\nz = 0\nvectors.each do |vector|\n\tx += vector[0].to_i\n\ty += vector[1].to_i\n\tz += vector[2].to_i\nend\n\nif x == 0 && y == 0 && z == 0\n\tprint \"YES\"\nelse\n\tprint \"NO\"\nend", "positive_code": [{"source_code": "n = gets.to_i\nar = [0, 0, 0]\nn.times do\n gets.split(' ').map.with_index(0){|x,id| ar[id]+=x.to_i}\nend\nif ar.all?{|x| x==0}\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "matrix = Array.new\ngets.to_i.times do\nmatrix.push(gets.split(\" \").map(&:to_i))\nend\n\nfor lines in matrix.transpose\n res = lines.inject { |sum, i| sum += i }\n (res == 0 )?(res):(puts \"NO\"; exit)\nend\nputs \"YES\""}, {"source_code": " n = gets.to_i\n a = 0\n b = 0\n c = 0\n n.times do\n nums = gets.split(\" \").map(&:to_i)\n a+=nums[0]\n b+=nums[1]\n c+=nums[2]\n end\n \n if(a==0 and b==0 and c==0) \n puts(\"YES\")\n else\n puts(\"NO\")\n end"}, {"source_code": "n = gets.to_i\n\nsumx = 0\nsumy = 0\nsumz = 0\n\nn.times do |i|\n s = gets.split.map{|i| i.to_i}\n sumx += s[0]\n sumy += s[1]\n sumz += s[2]\nend\n\nif sumx != 0 || sumy != 0 || sumz != 0 then\n puts \"NO\"\nelse\n puts \"YES\"\nend"}, {"source_code": "forces_count = gets.to_i\n\nforce_vectors = []\n\nforces_count.times do\n force_vectors.push(gets.split.map(&:to_i))\nend\n\nresultant_force = [0, 0, 0]\n\nforce_vectors.each do |force|\n resultant_force[0] += force[0]\n resultant_force[1] += force[1]\n resultant_force[2] += force[2]\nend\n\nif resultant_force[0] | resultant_force[1] | resultant_force[2] == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "x, y, z = 0, 0, 0\n\ngets.to_i.times do\n a, b, c = gets.split.map(&:to_i)\n x += a\n y += b\n z += c\nend\n\nputs [0, 0, 0] == [x, y, z] ? :YES : :NO"}, {"source_code": "x, y, z = 0, 0, 0\ngets.to_i.times do\n\ta, b, c = gets.split.map(&:to_i)\n\tx += a\n\ty += b\n\tz += c\nend\nputs [x, y, z] == [0, 0, 0] ? :YES : :NO\n"}, {"source_code": "puts( Array.new(gets.to_i) do\n gets.split.map(&:to_i)\nend.transpose.all?{ |r| r.inject(:+).zero? } ? :YES : :NO )\n"}, {"source_code": "n = gets.to_i\np = [0, 0, 0]\nn.times do\n a = gets.split.map(&:to_i)\n 3.times {|i| p[i] += a[i]}\nend\nputs p == [0, 0, 0] ? \"YES\" : \"NO\""}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\"\n"}, {"source_code": "n = gets.to_i\nx0, y0, z0= 0,0,0\nn.times do\n x, y, z = gets.split.map(&:to_i)\n x0, y0, z0 = x0 + x, y0 + y, z0 + z\nend\n\nif x0 == 0 && y0 == 0 && z0 == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\""}, {"source_code": "q = []\na = gets.to_i\nfor i in 0..(a-1)\nq[i] = gets.split(\" \")\nend\nw = 0\ne = 0\nr = 0\n\nq.each do |n| \n\n w = w + n[0].to_i\n e = e + n[1].to_i\n r = r + n[2].to_i\n\nend\n\nif w == 0 and e == 0 and r == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\"\n"}, {"source_code": "num_of_lines = gets.chomp.to_i\nx = 0 \ny = 0 \nz = 0\nnum_of_lines.times do\n line = gets.chomp.split(\" \")\n x += line[0].to_i\n y += line[1].to_i\n z += line[2].to_i\nend\nputs (x == 0 && y == 0 && z == 0)? \"YES\" : \"NO\""}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\""}, {"source_code": "forces = gets.to_i\n\ndef solve(n_forces)\n all_forces = Array.new(3,0)\n\n (1..n_forces).each do |i|\n a = gets.split(/\\s+/).map(&:to_i)\n all_forces = all_forces.zip(a).map(&:sum)\n end\n\n all_forces == [0,0,0] ? \"YES\" : \"NO\"\nend\n\nputs solve(forces)"}, {"source_code": "n = gets.to_i\nx = 0\ny = 0\nz = 0\nfor i in 1..n\n\tstr = gets.chomp\n\txi, yi, zi = str.split(\" \").map { |num| num.to_i }\n\tx += xi\n\ty += yi\n\tz += zi\nend\nif x == 0 && y == 0 && z == 0\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\""}, {"source_code": "n=gets.chomp.to_i\na=[]\nsuma=0\nsumb=0\nsumc=0\nn.times do\n\tb=gets.chomp.split.map(&:to_i)\n\ta.push(b)\n\tsuma+=b[0]\n\tsumb+=b[1]\n\tsumc+=b[2]\nend\nif suma==0 && suma==sumb && sumb==sumc\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "STDIO = $stdin\nSTDIO.readline\nputs STDIO.readlines.map(&:strip).map(&:split).transpose.map { |b| b.map(&:to_i).inject(0) { |acc, x| acc+x } }.eql?([0,0,0]) ? \"YES\" : \"NO\""}, {"source_code": "n = gets.to_i\n\nr = [0, 0, 0]\n\nn.times do\n s = gets.chomp.split(' ').map &:to_i\n \n r = r.zip(s).map {|a| a.inject(:+)}\nend\n\nif r.sort == [0,0,0].sort\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "n = gets.to_i\na = Array.new()\nb = Array.new()\nc = Array.new()\n\nlo,xo,fo = 0,0,0\nfor i in 0..n-1\n a[i],b[i],c[i] = gets.split.map(&:to_i)\n lo+=a[i]\n xo+=b[i]\n fo+=c[i]\nend\n\nif [fo, lo, xo] == [0, 0, 0]\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "n = $stdin.readline.to_i\ndx,dy,dz = 0,0,0\nn.times do\n x,y,z = $stdin.readline.split.map(&:to_i)\n dx,dy,dz = x+dx, y+dy, z+dz\nend\n\nputs (dx==0 && dy==0 && dz==0) ? \"YES\" : \"NO\""}, {"source_code": "arr = []\ngets.to_i.times do\n arr.push(gets.chomp.split.map &:to_i)\nend\narr = arr.transpose.map { |x| x.inject(:+) }\nif arr == [0, 0, 0]\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\"\n"}, {"source_code": "n = gets.chomp.to_i\nx,y,z = 0,0,0\nn.times do |i|\n a,b,c = gets.split.map(&:to_i)\n x+=a ; y+=b ; z+=c\nend\nif [x,y,x] == [0,0,0]\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "#!/usr/bin/env ruby\n\nwhile true\n break if STDIN.eof?\n n = gets.to_i\n\n a = b = c = 0\n n.times {\n x, y, z = gets.split.map(&:to_i)\n\n a += x; b += y; c += z\n }\n\n puts [a, b, c] == [0, 0, 0] ? 'YES' : 'NO'\nend\n"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\"\n"}, {"source_code": "no_forces = gets.chomp.to_i\nx_sum = 0\ny_sum = 0\nz_sum = 0\nno_forces.times do\n forces = gets.chomp.split(/ /).map(&:to_i)\n x_sum += forces[0]\n y_sum += forces[1]\n z_sum += forces[2]\nend\nif x_sum == 0 && y_sum == 0 && z_sum == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\"\n"}, {"source_code": "x=0\ny=0\nz=0\ngets.to_i.times{\n\ta,b,c=gets.split.map{|e| e.to_i}\n\tx=x+a\n\ty=y+b\n\tz=z+c\n}\nputs (x|y|z)==0?\"YES\":\"NO\""}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?\"YES\":\"NO\""}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\""}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\""}, {"source_code": "#Redirecting STDIN to file\n#$stdin=File.open(\"input.txt\", \"r\")\n#$stdout=File.open(\"output.txt\", \"w\")\n#END\n\nt=gets.to_i\ndata=[0,0,0]\n\nfor i in 1..t do\n x, y, z=gets.split.map(&:to_i)\n data[0]+=x\n data[1]+=y\n data[2]+=z\nend\n\nif data[0]==0 and data[1]==0 and data[2]==0 then\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "a=[]\nx=y=z=0\ngets.to_i.times{\n\ta=gets.split\n\tx+=a[0].to_i\n\ty+=a[1].to_i\n\tz+=a[2].to_i\n}\n\nputs(if x==y && y==z && z==0 then\n\t\t'YES'\n\telse\n\t\t'NO'\n\tend)\n"}, {"source_code": "n = gets.to_i\nx,y,z = 0,0,0\n(1..n).each do\n a, b, c = gets.split.map(&:to_i)\n x += a; y += b; z += c\nend\nputs x==0 && y==0 && z==0 ? 'YES' : 'NO'"}, {"source_code": "x,y,z = 0,0,0\n\ngets.to_i.times do \n v = gets.split.map(&:to_i)\n x += v[0]; y+= v[1]; z+= v[2];\nend\n\nputs [x,y,z].all? {|i| i == 0} ? \"YES\": \"NO\""}, {"source_code": "n = gets.to_i\nav=bv=cv = 0\nn.times{\n a,b,c = gets.split.map(&:to_i)\n av = av + a\n bv = bv + b\n cv = cv + c\n}\nputs (av**2+bv**2+cv**2 == 0 ? 'YES' : 'NO')"}, {"source_code": "x,y,z=0,0,0;gets.to_i.times{a,b,c=gets.split.map &:to_i;x+=a;y+=b;z+=c;};puts [x,y,z]==[0,0,0]?:YES: \"NO\""}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\"\n"}, {"source_code": "#puts \"Enter the number of vector\\n\"\nn = gets.to_i\na = [n]\nb = [n]\nc = [n]\nfor i in 0...n do\n a[i], b[i], c[i] = gets.split.map(&:to_i)\nend\nx = y = z = 0\nfor j in 0...n do\n x += a[j]\n y += b[j]\n z += c[j]\nend\nif x == 0 && y == 0 && z == 0\n puts \"YES\\n\"\nelse\n puts \"NO\\n\"\nend"}, {"source_code": "x_sum = 0\ny_sum = 0\nz_sum = 0\nn = gets.to_i\nn.times do\n x,y,z = gets.split(\" \").map(&:to_i)\n x_sum += x\n y_sum += y\n z_sum += z\nend\nputs x_sum == 0 && y_sum == 0 && z_sum == 0 ? \"YES\" : \"NO\""}, {"source_code": "x, y, z = [0, 0, 0]\ngets.chomp.to_i.times {\n xi, yi, zi = gets.split.map(&:to_i)\n x += xi\n y += yi\n z += zi\n}\nputs (x == 0 and y == 0 and z == 0) ? \"YES\" : \"NO\"\n"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\"\n"}, {"source_code": "require 'matrix'\n\nn = gets.to_i\n\nres = Vector[0, 0, 0]\n\nn.times do\n\tres += Vector.elements(gets.split.map(&:to_i))\nend\n\nputs \"YES\" if res == Vector[0, 0, 0]\nputs \"NO\" unless res == Vector[0, 0, 0]"}, {"source_code": "n = gets.chomp.to_i\ninit_vector = [0,0,0]\nn.times do\n vec = gets.chomp\n vec = vec.split(' ')\n\n init_vector.map!.with_index {|val, i| val += vec[i].to_i }\nend\nputs init_vector.all? {|v| v == 0 } ? \"YES\" : \"NO\""}, {"source_code": "puts ( gets.to_i.times.map{gets.split.map(&:to_i)}.transpose.map{|x| x.reduce(&:+)} == [0,0,0] )? \"YES\" : \"NO\""}, {"source_code": "require 'scanf'\n\ndef main()\n vectors_count = gets.to_i\n vectors = []\n vectors_count.times do\n vectors << gets.scanf(\"%d %d %d\")\n end\n check_vectors(vectors) ? puts(\"YES\") : puts(\"NO\")\nend\n\ndef check_vectors(vectors)\n result_sum = 0\n i = 0\n vectors[0].size.times do\n if result_sum == 0 then\n result = 0\n result = vectors.inject(0) {|result, item| result = result + item[i]}\n result_sum += result\n end\n i += 1\n end\n return result_sum == 0\nend\nmain()"}, {"source_code": "n = $stdin.gets\nsumx = 0\nsumy = 0\nsumz = 0\nwhile line = $stdin.gets\n x,y,z = line.strip.split(' ').map{|v| v.to_i}\n sumx += x\n sumy += y\n sumz += z\nend\nif(sumx == 0 && sumy == 0 && sumz == 0)\n print \"YES\"\nelse\n print \"NO\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\ntotal_x, total_y, total_z = 0, 0, 0\nn.times do\n x, y, z = gets.chomp.split(\" \").map(&:to_i)\n total_x += x\n total_y += y\n total_z += z\nend\n\nif total_x == 0 && total_y == 0 && total_z == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.to_i;s=0;b=[]\nfor i in(1..n)\n a = gets.split.map(&:to_i)\n if i>1\n b[0]+=a[0];b[1]+=a[1];b[2]+=a[2];\n else\n b=a;\n end\nend\nputs b[0]==0 && b[1]==0 && b[2]==0 ? \"YES\" : \"NO\""}, {"source_code": "puts gets.to_i.times.map{gets.split.map(&:to_i)}.transpose.all?{|a|a.inject(0){|r,j|r+j}==0} ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.chomp.to_i\n\na = b = c = 0\n\nn.times{\n\tinput = gets.chomp.split(\" \")\n\ta += input[0].to_i\n\tb += input[1].to_i\n\tc += input[2].to_i\n}\n\nif a==0 && b==0 && c==0\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n"}, {"source_code": "n = readline.to_i\nsum = [0,0,0]\ni = 0\nwhile i < n do\n a = readline.split(' ')\n sum[0] += a[0].to_i\n sum[1] += a[1].to_i\n sum[2] += a[2].to_i\n i += 1\nend\nputs (if(sum[0] == 0 && sum[1] == 0 && sum[2] == 0) \n begin\n \"YES\"\n end \nelse \n begin\n \"NO\" \n end\nend)\n"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\""}, {"source_code": "n = gets.to_i\na =[]\nb=[]\nres = 0\nd = 0\n\nn.times do\n a = gets.split().map(&:to_i)\n b.push(a)\nend\n\ndef check(c,d)\n sum = 0\n sum = sum+c[d]\nend\n\nb.each do |i|\n res = res + check(i,0)\n d = d+1\nend\n\nif res == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "# https://codeforces.com/problemset/problem/69/A\nn = gets.chomp.to_i\nforcex = 0\nforcey = 0\nforcez = 0\n1.upto(n) do |force|\n x, y, z = gets.chomp.split(\" \").map(&:to_i)\n forcex += x\n forcey += y\n forcez += z\nend\n\nif forcex == 0 && forcey == 0 && forcez == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "\nclass Euler\n n=gets.to_i;\n k1=0;\n k2=0;\n k3=0;\n (1..n).each do\n a=gets;\n m=a.split(\" \");\n k1+=m[0].to_i;\n k2+=m[1].to_i;\n k3+=m[2].to_i;\n end\n if (k1==k2 && k2==k3 && k3==0)\n puts(\"YES\");\nelse\n puts(\"NO\");\n end\nend\n"}, {"source_code": "x=0\ny=0\nz=0\n\ngets.to_i.times{\n\nx+=gets(' ').to_i\ny+=gets(' ').to_i\nz+=gets.to_i\n\n}\n\nif x == 0 && y == 0 && z == 0\nprint \"YES\\n\"\nelse\nprint \"NO\\n\"\nend"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\"\n"}, {"source_code": "n = gets.to_i\n\nresult = [0, 0, 0]\n\n1.upto(n) do\n vec = gets.split(' ').map(&:to_i)\n 0.upto(2) { |i| result[i] += vec[i] }\nend\n\nputs result.all? { |n| n == 0 } ? 'YES' : 'NO'\n"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\"\n"}, {"source_code": "sum = [0, 0, 0]\n\nn = gets.to_i\n\nfor str in $stdin.each_line.take(n)\n arr = str.split(' ').map &:to_i\n for i in 0..2\n sum[i] += arr[i]\n end\nend\n\nif sum.all? { |x| x == 0 }\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "n = gets.to_i\ns1 = 0\ns2 = 0\ns3 = 0\nwhile (n > 0)\n a,b,c = gets.split(' ').map{|s| s.to_i}\n s1 += a\n s2 += b\n s3 += c \n n -= 1 \nend\n\nif (s1 == 0 && s2 == 0 && s3 == 0) then puts 'YES'\nelse puts 'NO'\nend"}, {"source_code": "t = gets.to_i\nsum = [0,0,0]\nfor i in 1..t\n b = gets.chomp.split().map { |e| e.to_i }\n for i in 0..2\n sum[i] += b[i]\n end\nend\n\nputs sum.uniq.size <= 1 && sum.inject(0, :+) == 0 ? 'YES' : 'NO'\n"}, {"source_code": "n = gets.chomp.to_i\nvec = [0, 0, 0]\nn.times.each do |_i|\n force = gets.chomp.split(/ /).map(&:to_i)\n vec[0] += force[0]\n vec[1] += force[1]\n vec[2] += force[2]\nend\nputs vec.uniq.count > 1 ? 'NO' : vec[0] == 0 ? 'YES' : 'NO'\n"}, {"source_code": "gets\nputs $<.map{|_|_.split}.transpose.all?{|_|0==eval(_*?+)}? \"YES\" : \"NO\""}, {"source_code": "require\"matrix\"\ngets\nputs $<.map{|_|Vector[*_.split.map(&:to_i)]}.inject(:+).r==0? \"YES\" : \"NO\""}, {"source_code": "gets; input, x, y, z = STDIN.read.split(\"\\n\").map{ |i| i.split.map! &:to_i }, 0, 0, 0\n\ninput.each { |i| x += i[0]; y += i[1]; z += i[2] }\nprint [x, y, z].join == \"000\" ? :YES : :NO"}, {"source_code": "x,y,z=0,0,0\ngets.to_i.times do\n a=gets.split\n x+=a[0].to_i\n y+=a[0].to_i\n z+=a[0].to_i\nend\nif x==0&&y==0&&z==0\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "n = gets.to_i\nsum = [0, 0, 0]\nn.times do\n\tf = gets.split.map { |x| x.to_i }\n\t3.times do |i|\n\t\tsum[i] += f[i]\n\tend\nend\n\nif sum.count(0) == 3\n\tputs 'YES'\nelse\n\tputs 'NO'\nend"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)==0}?:YES:\"NO\"\n"}, {"source_code": "vectorNum = gets.chomp.to_i\n\ntotals = Array.new(3) { |elem| elem = 0 }\n\nvectorNum.times do\n\tvector = gets.chomp.split(' ').map(&:to_i)\n\tfor i in (0...vector.length)\n\t\ttotals[i] += vector[i]\n\tend\nend\n\n# print totals\n\nans = if totals.all? { |elem| elem == 0 }\n\t'YES'\nelse\n\t'NO'\nend\n\nputs ans"}, {"source_code": "puts %w[YES NO][STDIN.readlines.drop(1).reduce([0, 0, 0]) { |r, x| r.zip(x.split(' ').map(&:to_i)).map { |a, b| a + b } } == [0, 0, 0] ? 0 : 1]"}], "negative_code": [{"source_code": "n = gets.to_i;s=0\nfor i in(1..n)\n a = gets.split.map(&:to_i)\n s += (a[0]+a[1]+a[2])\nend\nputs s==0 ? \"SI\" : \"NO\""}, {"source_code": "n = gets.to_i;s=0\nfor i in(1..n)\n a = gets.split.map(&:to_i)\n s += (a[0]+a[1]+a[2])\nend\nputs s==0 ? \"YES\" : \"NO\""}, {"source_code": "n = gets.to_i\na =[]\nb=[]\nsum = 0\n\nn.times do\n a = gets.split().map(&:to_i)\n b.push(a)\nend\n\nb.each do |i|\n i.each do |j|\n sum = sum +j\n end \nend\n\nif sum == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "n = gets.to_i\na =[]\nb=[]\nsum = 0\nres = 0\n\nn.times do\n a = gets.split().map(&:to_i)\n b.push(a)\nend\n\nb.each do |i|\n i.each do |j|\n sum = sum +j\n end\n res = res + sum\nend\n\n\n\nif res == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend\n\n\n\n"}, {"source_code": "# https://codeforces.com/problemset/problem/69/A\nn = gets.chomp.to_i\nforcex = 0\nforcey = 0\nforcez = 0\n1.upto(n) do |force|\n x, y, z = gets.chomp.split(\" \").map(&:to_i)\n forcex += x\n forcey += y\n forcez += z\nend\n\nif (forcex + forcey + forcez) == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "sum = [0, 0, 0]\n\nn = gets.to_i\n\nfor str in $stdin.each_line.take(n)\n arr = str.split(' ').map &:to_i\n (sum.zip(arr)).map do |x|\n x.reduce { :+ }\n end\nend\n\nif sum.all? { |x| x == 0 }\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "t = gets.to_i\nsum = [0,0,0]\nfor i in 1..t\n b = gets.chomp.split().map { |e| e.to_i }\n for i in 0..2\n sum[i] += b[i]\n end\nend\n\nputs sum.inject(0, :+) == 0 ? 'YES' : 'NO'"}, {"source_code": "n = gets.chomp.to_i\nvec = [0, 0, 0]\nn.times.each do |_i|\n force = gets.chomp.split(/ /).map(&:to_i)\n vec[0] += force[0]\n vec[1] += force[1]\n vec[2] += force[2]\nend\nsum = vec.inject(0) { |sum, x| sum + x }\nputs sum.zero? ? 'YES' : 'NO'\n"}, {"source_code": "n = gets.chomp.to_i\nvec = [0, 0, 0]\nn.times.each do |_i|\n force = gets.chomp.split(/ /).map(&:to_i)\n vec[0] += force[0]\n vec[1] += force[1]\n vec[2] += force[2]\nend\nputs vec.uniq.count > 1 ? 'NO' : 'YES'\n"}, {"source_code": "vectorNum = gets.chomp.to_i\n\ntotals = Array.new(3) { |elem| elem = 0 }\n\nvectorNum.times do\n\tvector = gets.chomp.split(' ').map(&:to_i)\n\tfor i in (0...vector.length)\n\t\ttotals[i] += vector[i]\n\tend\nend\n\nans = if totals.all? { |elem| elem = 0 }\n\t'YES'\nelse\n\t'NO'\nend\n\nputs ans"}, {"source_code": "def equ(*array)\n if array.length < 4 and array.length > 0\n k = 0\n array.each do |element|\n k = k + element\n end\n if k == 0\n puts \"YES\"\n else\n puts \"NO\"\n end\n else\n puts \"Enter more than 0 and less than 4 input\"\n end\nend\n\nequ()"}, {"source_code": "def equ(*array)\n if array.length < 4 and array.length > 0\n k = 0\n array.each do |element|\n k = k + element\n end\n if k == 0\n puts \"YES\"\n else\n puts \"NO\"\n end\n else\n puts \"NO\"\n end\nend"}, {"source_code": "a = 3\n\nq = \"4 -1 7\".split(\" \")\nw = \"-5 2 -4\".split(\" \")\ne = \"2 -1 -3\".split(\" \")\nres = 0\n\nfor i in 0..2\n r = q[i].to_i + w[i].to_i + e[i].to_i\n res = res + r\nend\n\nif res == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "a = gets\nq = gets.split(\" \")\nw = gets.split(\" \")\ne = gets.split(\" \")\n\nres = 0\n\nfor i in 0..2\n r = q[i].to_i + w[i].to_i + e[i].to_i\n res = res + r\nend\n\nif res == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "forces = gets.to_i\n\ndef solve(n_forces)\n all_forces = Array.new(3,0)\n\n (1..n_forces).each do |i|\n a = gets.split(/\\s+/).map(&:to_i)\n c = all_forces.zip(a).map(&:sum)\n end\n\n all_forces == [0,0,0] ? \"YES\" : \"NO\"\nend\n\nputs solve(forces)"}, {"source_code": "sum = 0\ngets.to_i.times do\n sum += gets.chomp.split.map { |x| x.to_i }.inject(:+) \nend\nif sum == 0 \n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "def sum( forces )\n sum = 0\n forces.each do |force|\n sum += force\n end\n sum\nend\nno_forces = gets.chomp.to_i\nsum_forces = 0\nno_forces.times do\n forces = gets.chomp.split(/ /).map(&:to_i)\n sum_forces += sum forces\nend\nif sum_forces == 0\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "gets;puts$<.map(&:split).transpose.all?{|j|eval(j*?+)<1}?\"YES\":\"NO\""}, {"source_code": "number = gets.chomp.to_i\nvectors = []\n\ni = 0\nwhile i < number\n\tx = gets.chomp\n\tvectors << x.split(\" \")\n\ti += 1\nend\n\nequilibrium = 0\nvectors.each do |vector|\n\tequilibrium += vector[0].to_i + vector[1].to_i + vector[2].to_i \nend\n\nif equilibrium == 0\n\tprint \"YES\"\nelse\n\tprint \"NO\"\nend"}, {"source_code": "require 'scanf'\n\ndef main()\n vectors_count = gets.to_i\n vectors = []\n vectors_count.times do\n vectors << gets.scanf(\"%d %d %d\")\n end\n check_vectors(vectors) ? puts(\"YES\") : puts(\"NO\")\nend\n\ndef check_vectors(vectors)\n result_sum = 0\n i = 0\n vectors[0].size.times do\n if result_sum == 0 then\n result = 0\n result = vectors.inject(0) {|result, item| result = result + item[i]}\n result_sum += result\n end\n p i\n i += 1\n end\n return result_sum == 0\nend\nmain()"}, {"source_code": "require 'scanf'\n\ndef main()\n vectors_count = readline.to_i\n vectors = []\n vectors_count.times do\n vectors << readline.scanf(\"%d %d %d\")\n end\n result_sum = 0\n i = 0\n vectors_count.times do\n if result_sum == 0 then\n result = 0\n vectors.inject(0) {|result, item| result = result + item[i]}\n result_sum += result\n end\n i += 1\n end\n result_sum == 0 ? puts(\"YES\") : puts(\"NO\")\nend\n\nmain\n"}, {"source_code": "require 'scanf'\n\ndef main()\n vectors_count = readline.to_i\n vectors = []\n vectors_count.times do\n vectors << readline.scanf(\"%d %d %d\")\n end\n result = 0\n vectors.inject(0) do |result, item|\n result = result + item[0]\n end\n #p result\n vectors.inject(0) {|result, item| result = result + item[1]} if result == 0\n #p result\n vectors.inject(0) {|result, item| result = result + item[2]} if result == 0\n #p result\n result == 0 ? puts(\"YES\") : puts(\"NO\")\nend\n\nmain\n"}, {"source_code": "require 'scanf'\n\ndef main()\n vectors_count = gets.to_i\n vectors = []\n vectors_count.times do\n vectors << gets.scanf(\"%d %d %d\")\n end\n check_vectors(vectors_count, vectors) ? puts(\"YES\") : puts(\"NO\")\nend\n\ndef check_vectors(vectors_count, vectors)\n return false unless vectors_count == vectors.size\n result_sum = 0\n i = 0\n vectors_count.times do\n if result_sum == 0 then\n result = 0\n result = vectors.inject(0) {|result, item| result = result + item[i]}\n result_sum += result\n end\n i += 1\n end\n return result_sum == 0\nend\ndef check_vectors(vectors_count, vectors)\n result_sum = 0\n i = 0\n vectors[0].size.times do\n if result_sum == 0 then\n result = 0\n result = vectors.inject(0) {|result, item| result = result + item[i]}\n result_sum += result\n end\n p i\n i += 1\n end\n return result_sum == 0\nend\nmain()"}, {"source_code": "require 'scanf'\n\ndef main()\n vectors_count = readline.to_i\n vectors = []\n vectors_count.times do\n vectors << readline.scanf(\"%d %d %d\")\n end\n result = 0\n vectors.inject(0) do |result, item|\n result = result + item[0]\n end\n vectors.inject(0) {|result, item| result = result + item[1]} if result == 0\n vectors.inject(0) {|result, item| result = result + item[2]} if result == 0\n result == 0 ? puts(\"YES\") : puts(\"NO\")\nend\n\nmain\n"}], "src_uid": "8ea24f3339b2ec67a769243dc68a47b2"} {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a", "positive_code": [{"source_code": "n,d=gets.chomp!.split(\" \").map(&:to_i)\ns,c=gets.chomp!.split(\" \").map(&:to_i),0\n(n-1).times{|i|t=s[i]-s[i+1]\nif t>=0 then\n t=t/d+1\n c+=t\n s[i+1]+=t*d end}\nputs c\n"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a\n"}, {"source_code": "s = gets.split(\" \")\nn = s[0].to_i\nd = s[1].to_i\n\ns = gets.split(\" \")\nmas = Array.new()\nfor i in 0..n-1\n mas[i] = s[i].to_i\nend\n\ncount = 0\nfor i in 1..n-1\n if (mas[i] <= mas[i-1])\n delta = ((mas[i-1] - mas[i]) / d) + 1\n mas[i] = mas[i] +d * delta\n count += delta\n end\nend\n\nputs count"}, {"source_code": "n,d = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\ns = 0\n1.upto(b.size - 1).each do |i|\n\tif b[i] <= b[i-1] then\n\t\tt = (b[i-1] - b[i]) / d + 1\n\t\ts += t\n\t\tb[i] += t * d\n\tend\nend\np s\n"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a"}, {"source_code": "n, d = gets.split.map &:to_i\nb = gets.split.map &:to_i\nans = 0\n(1...n).each do |i|\n t = [(b[i - 1] - b[i])/d + 1, 0].max\n b[i] += t*d\n ans += t\nend\nputs ans\n"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a\n"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a\n"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a\n"}, {"source_code": "n, d = gets.split.map{|i| i.to_i}\n\nb = gets.split.map{|i| i.to_i}\n\nres = 0\n\n(n-1).times do |i|\n k = b[i] - b[i+1]\n if k >= 0 then\n m = k/d + 1\n res += m\n b[i+1] += m*d\n end\nend\n\nputs res"}, {"source_code": "n, d = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\ns = 0\n1.upto(b.size - 1).each do |i|\n\tnext if b[i] > b[i - 1]\n\tt = (b[i - 1] - b[i]) / d + 1\n\ts += t\n\tb[i] += t * d\nend\np s\n"}, {"source_code": "d=gets.split[1].to_i\na=gets.split.map(&:to_i)\nans=0\n1.upto(a.length-1){|i|\n r=a[i-1]-a[i]+1\n if r>0 then\n ans+=(r+d-1)/d\n a[i]+=(r+d-1)/d*d\n end\n}\nputs ans"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a\n"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a\n"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a\n"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a\n"}, {"source_code": "d=gets.split[1].to_i;s=gets.split;x=s.shift.to_i;a=0;s.each{|b|b=b.to_i;a+=z=b>x ?0:(x-b)/d+1;x=b+z*d};puts a"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\nrequire 'prime'\nrequire 'mathn'\nrequire 'matrix'\ninclude Math\n#=================================\n\nn,d=gets.split.map(&:to_i)\ndata=gets.split.map(&:to_i)\n\nans=0\nfor i in 1...n\n\tif data[i]<=data[i-1]\n\t\tk=((data[i-1]-data[i]+1)*1.0/d).ceil\n\t\tdata[i]+=k*d\n\t\tans+=k\n\tend\nend\n\nputs ans\n"}], "negative_code": [{"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\nrequire 'prime'\nrequire 'mathn'\n#=================================\n\nn,d=gets.split.map(&:to_i)\ndata=gets.split.map(&:to_i)\n\nans=0\ni=n-2\nloop do\n\tbreak if i<0\n\t\n\tif data[i]>=data[i+1]\n\t\t(i+1).upto(n-1){|j|\n\t\t\tdata[j]+=d\n\t\t\tans+=1\n\t\t}\n\telse\n\t\ti-=1\n\tend\nend\n\nputs ans\n"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\nrequire 'prime'\nrequire 'mathn'\n#=================================\n\nn,d=gets.split.map(&:to_i)\ndata=gets.split.map(&:to_i)\n\nans=0\n(n-2).downto(0){|i|\n\tif data[i]>=data[i+1]\n\t\t(i+1).upto(n-1){|j|\n\t\t\tdata[j]+=d\n\t\t\tans+=1\n\t\t}\n\tend\n}\n\nputs ans\n"}, {"source_code": "e,e[1],c=Array.new(2),0,0\nn,d=gets.chomp!.split(\" \").map(&:to_i)\nn.times{|i|e[i%2]=$stdin.read(2)[0,1].to_f\nc+=((e[i%2]-e[(i+1)%2]+1.0)/n).ceil\ne[(i+1)%2]+=c*d}\nputs c\n"}, {"source_code": "s = gets.split(\" \")\nn = s[0].to_i\nd = s[1].to_i\n\ns = gets.split(\" \")\nmas = Array.new()\nfor i in 0..n-1\n mas[i] = s[i].to_i\nend\n\ncount = 0\nfor i in 1..n-1\n if (mas[i] <= mas[i-1])\n delta = ((mas[i-1] - mas[i]) / d) + 1\n mas[i] = mas[i-1] +d * delta\n count += delta\n end\nend\n\nputs count"}], "src_uid": "0c5ae761b046c021a25b706644f0d3cd"} {"source_code": "s,n = gets.split.map{|i| i.to_i}\n\ndragon = []\nn.times do |i|\n dragon << gets.split.map{|j| j.to_i}\nend\n\ndragon = dragon.sort{|a,b| a[0] <=> b[0]}\n\nt = true\nn.times do |i|\n if s > dragon[i][0] then\n s += dragon[i][1]\n else\n t = false\n end\nend\n\nif t then\n puts \"YES\"\nelse\n puts \"NO\"\nend", "positive_code": [{"source_code": "power, enemy_count = gets.chop.split.map(&:to_i)\n\ndragons = []\nenemy_count.times { dragons << gets.chop.split.map(&:to_i) }\n\nloop do\n weak_dragons = dragons.select { |dragon| power > dragon[0] }\n break if dragons.count.zero? || weak_dragons.count.zero?\n power += weak_dragons.reduce(0) { |bonus, dragon| bonus += dragon[1] }\n dragons -= weak_dragons\nend\n\ndragons.count.zero? ? puts('YES') : puts('NO')"}, {"source_code": "#!/usr/bin/env ruby\n\ns,n = gets.split.map(&:to_i)\n\nx = n.times.map { gets.split.map(&:to_i) }\n\nyes = 1\nn.times do\n id = -1\n x.each_with_index do |arr, i|\n if arr[0] < s\n id = i\n break\n end\n end\n if id == -1\n yes = 0\n break\n end\n s += x[id][1]\n x.delete_at(id)\nend\n\nputs(yes == 1 ? 'YES' : 'NO')\n"}, {"source_code": "#!/usr/bin/env ruby\n\ns,n = gets.split.map(&:to_i)\n\nx = n.times.map { gets.split.map(&:to_i) }.sort\n\nyes = true\nx.each do |a,b|\n if s <= a\n yes = false\n break\n end\n s += b\nend\n\nputs(yes ? 'YES' : 'NO')\n"}, {"source_code": "s, n = gets.split.map(&:to_i)\na = []\nn.times do\n b = gets.split.map(&:to_i)\n a << b\nend\na.sort!\nans = 1\nn.times do |i|\n if s <= a[i][0]\n ans = 0\n break\n end\n s += a[i][1]\nend\nputs ans == 0 ? \"NO\" : \"YES\"\n"}, {"source_code": "s, n = gets.split.map(&:to_i)\na = n.times.map{gets.split.map(&:to_i)}.sort\nans = true\nn.times do |i|\n if s <= a[i][0]\n ans = false\n break\n end\n s += a[i][1]\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": " a=gets.chomp.split(\" \")\npow=a[0].to_i\ndrag=a[1].to_i\ndragary=[]\ndrag.times do\ntemp=gets.chomp.split(\" \")\ntemp[0]=temp[0].to_i \ntemp[1]=temp[1].to_i\ndragary<< temp\nend\ndragary.sort!\ni=0\nloop do \nif dragary[i][0]drag-1\nend\nif i>drag-1\nputs \"YES\"\nend"}, {"source_code": "class Dragon\n attr_accessor :x, :y\n\n def initialize(x, y)\n @x = x\n @y = y\n end\n\n def <=>(other)\n unless self.x == other.x\n self.x - other.x\n else\n other.y - self.y\n end\n end\nend\n\ns, n = gets.split.map &:to_i\nar = Array.new\nn.times do\n ar << Dragon.new(*(gets.split.map &:to_i))\nend\nar.sort!\nar.each do |dragon|\n if dragon.x < s\n s += dragon.y\n else\n puts \"NO\"\n exit\n end\nend\nputs \"YES\"\n"}, {"source_code": "s,n=gets.split.map(&:to_i)\nputs n.times.map{gets.split.map(&:to_i)}.sort_by{|x,y|x}.all?{|x,y|x+y y.first }\n\nsuccess = true\na.inject(s) do |strength, dragon|\n if strength <= dragon.first\n success = false\n break\n end\n\n strength += dragon.last\nend\n\nputs success ? 'YES' : 'NO'\n"}, {"source_code": "first_line = gets.chomp.split(' ')\ns = first_line[0].to_i\nn = first_line[1].to_i\ndragons = []\n(0...n).each do |i|\n\tline = gets.chomp.split(' ')\n\tdragons[i] = {\n\t\tstrength: line[0].to_i,\n\t\tbonus: line[1].to_i\n\t}\nend\n\ndragons.sort! { |a, b| a[:strength] <=> b[:strength] }\ndefeated = false\ndragons.each do |elem|\n\tif s <= elem[:strength]\n\t\tdefeated = true\n\t\tbreak\n\tend\n\ts += elem[:bonus]\nend\n\nif defeated\n\tputs \"NO\"\nelse\n\tputs \"YES\"\nend\n\n\n"}, {"source_code": "s,n=gets.split.map(&:to_i)\nputs n.times.map{gets.split.map(&:to_i)}.sort_by{|x,y|x}.all?{|x,y|x+y b.x }\n\nisDead = false\ndragons.each { |dragon|\n\n if s <= dragon.x\n isDead = true\n break\n end\n\n s += dragon.y\n}\n\nif isDead\n puts \"NO\"\nelse\n puts \"YES\"\nend"}, {"source_code": "s,n=gets.split.map(&:to_i)\nputs n.times.map{gets.split.map(&:to_i)}.sort_by{|x,y|x}.all?{|x,y|x+y dragon.strength\n @strength += dragon.bonus\n return true\n else\n return false\n end\n end\nend\n\nclass Dragon\n attr_reader :strength, :bonus\n def initialize(strength, bonus)\n @strength = strength\n @bonus = bonus\n end\nend\n\ns, n = gets.split.map(&:to_i)\nkirito = Kirito.new(s)\ndragons = []\nn.times do\n dragons << Dragon.new(*gets.split.map(&:to_i))\nend\ndragons.sort!{|a, b| a.strength <=> b.strength}\ndragons.each do |d|\n unless kirito.attack(d)\n puts \"NO\"\n exit\n end\nend\nputs \"YES\"\n"}, {"source_code": "s, n = gets.split(' ').map(&:to_i)\nar = []\nans = \"YES\"\nn.times do\n ar << gets.split(' ').map(&:to_i)\nend\nar.sort_by(&:first).each do |x,y|\n ans = \"NO\" if s <= x\n s += y\nend\nputs ans"}, {"source_code": "s, n = \ngets.split.map &:to_i\n\nall_dragons_dead = true\n\ndragons = []\nn.times do\n dragons << gets.split.map(&:to_i)\nend\n\ndragons = dragons.sort do |d1, d2|\n d1[0] <=> d2[0]\nend\n\ndragons.each do |dragon|\n dragon_s, bonus = dragon\n\n if s <= dragon_s\n all_dragons_dead = false\n break\n end\n \n s += bonus\nend\n\noutput = all_dragons_dead ? \"YES\" : \"NO\"\nputs output"}, {"source_code": "class Dragon\n attr_accessor :hp\n attr_accessor :bonus\n def initialize(h, b)\n @hp = h\n @bonus = b\n end\nend\nline1 = gets.chomp.split(\" \")\ns = line1[0].to_i\nn = line1[1].to_i\n\nenemy = []\n\nfor i in 1..n\n line = gets.chomp.split(\" \").map {|x| x.to_i}\n enemy << Dragon.new(line[0], line[1])\nend\n\nenemy = enemy.sort_by {|obj| obj.hp}\n\nwin = true\nfor e in enemy\n if s > e.hp\n s += e.bonus\n else\n win = false\n break\n end\nend\n\nif win\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "s,n=gets.split.map(&:to_i)\nputs n.times.map{gets.split.map(&:to_i)}.sort_by{|x,y|x}.all?{|x,y|x+y y[0]}\n\na.each do |el|\n if s <= el[0]\n puts \"NO\"\n exit\n end\n s += el[1]\nend\n\nputs \"YES\""}, {"source_code": "class Dragon\n\tattr_reader :life, :bonus\n\tdef initialize(life, bonus)\n\t\t@life = life\n\t\t@bonus = bonus\n\tend\nend\n\ninput = gets.split\nkirito = input[0].to_i\nn = input[1].to_i\n\nd = Array.new\nfor i in 0...n\n\tinput = gets.split\n\td[i] = Dragon.new(input[0].to_i, input[1].to_i)\nend\nd.sort! {|x, y| x.life <=> y.life}\n\ndie = false\nfor i in 0...n\n\tif kirito <= d[i].life\n\t\tputs \"NO\"\n\t\tdie = true\n\t\tbreak\n\tend\n\tkirito += d[i].bonus\nend\n\nif not die then puts \"YES\" end\n"}, {"source_code": "s,n=gets.split.map(&:to_i)\nputs n.times.map{gets.split.map(&:to_i)}.sort_by{|x,y|x}.all?{|x,y|x+ya[i]\n\t\t\tcheck=1\n\t\t\ta[i]=0\n\t\t\ts+=b[i]\n\t\t\tbreak\n\t\tend\n\t\ti+=1\n\tend\nend\nif check\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "s, _ = gets.split.map(&:to_i)\nreadlines.map(&:strip).map { |x| x.split.map(&:to_i) }.sort_by! { |x| x[0]}.each do |x|\n if s <= x[0]\n puts \"NO\"\n exit\n else\n s += x[1]\n end\nend\nputs \"YES\""}, {"source_code": "s, n = gets.chomp.split(\" \").map(&:to_i)\na = []\n\nn.times do\n q = gets.chomp.split(\" \").map(&:to_i)\n a.push(q)\nend\n\na.sort_by!{|x, y| x}\n\na.each do |x, y|\n if s > x\n s += y\n else\n puts \"NO\"\n exit\n end\nend\n\nputs \"YES\"\n"}, {"source_code": "s,n=gets.split.map(&:to_i)\nputs n.times.map{gets.split.map(&:to_i)}.sort_by{|x,y|x}.all?{|x,y|x+ydrag-1\nend\nif i>drag-1\nputs \"YES\"\nend"}, {"source_code": "r=->(){gets.to_s.split.map &:to_i}\ns,n=*r.call()\na=[];n.times {a<=s\n s+=x[1]\nend\nprint ok ? 'YES' : 'NO'\n"}, {"source_code": "def r() gets.to_s.split.map &:to_i end\ns,n=*r\na=[];n.times {a<=s then print 'NO';exit(0);end\n s+=x[1]\nend\nprint 'YES'\n"}, {"source_code": "s,n=gets.split.map(&:to_i)\nputs n.times.map{gets.split.map(&:to_i)}.sort_by{|x,y|x}.all?{|x,y|x+y dragon[0]\n kirito += dragon[1]\n else\n winner = false\n break\n end\nend\nif winner\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": " a=gets.chomp.split(\" \")\npow=a[0].to_i\ndrag=a[1].to_i\ndragary=[]\ndrag.times do\ntemp=gets.chomp.split(\" \")\ntemp[0]=temp[0].to_i \ntemp[1]=temp[1].to_i\ndragary<< temp\nend\ndragary.sort!\ni=0\nloop do \nif dragary[i][0]drag-1\nend\nif i>drag-1\nputs \"YES\"\nend"}, {"source_code": "s,n=gets.split.map(&:to_i)\nputs n.times.map{gets.split.map(&:to_i)}.sort_by{|x,y|x}.all?{|x,y|x+y d[\"strength\"] then\n\t\tstrength+= d[\"bonus\"]\n\telse\n\t\tputs \"NO\"\n\t\texit\n\tend\nend\n\nputs \"YES\"\nexit\n"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=[]\nm.times{|i|\n\ta=gets.split.map{|e| e.to_i}\n\tx< b[0]\n else\n b[1] <=> a[1]\n end\nend\ndragons.each { |dragon|\n if s > dragon[0]\n s += dragon [1]\n else\n win = false\n break\n end\n}\nputs win ? \"YES\" : \"NO\""}, {"source_code": "s, n = gets.split.map(&:to_i)\nd = []\nn.times {\n d << gets.split.map(&:to_i)\n}\nd = d.sort_by{ |x| x[0]}\nflag = true\nd.each do |x|\n if s <= x[0]\n flag = false\n else\n s += x[1]\n end\nend\n\nputs flag ? \"YES\" : \"NO\"\n"}], "negative_code": [{"source_code": "s, n = \ngets.split.map &:to_i\n\nall_dragons_dead = true\n\ndragons = []\nn.times do\n dragons << gets.split.map(&:to_i)\nend\n\ndragons = dragons.sort do |d1, d2|\n d1[0] <=> d2[0]\nend\n\ndragons.each do |dragon|\n dragon_s, bonus = dragon\n\n if s < dragon_s\n all_dragons_dead = false\n break\n end\n \n s += bonus\nend\n\noutput = all_dragons_dead ? \"YES\" : \"NO\"\nputs output"}, {"source_code": "s, n = \ngets.split.map &:to_i\n\nall_dragons_dead = true\n\ndragons = []\nn.times do\n dragons << gets.split.map(&:to_i)\nend\n\ndragons = dragons.sort do |d1, d2|\n d1[0] <=> d2[0]\nend\n\ndragons.each do |dragon|\n dragon_s, bonus = dragon\n\n if s < dragon_s\n all_dragons_dead = false\n break\n end\n \n s += bonus\n s -= dragon_s\nend\n\noutput = all_dragons_dead ? \"YES\" : \"NO\"\nputs output"}, {"source_code": "class Dragon\n attr_accessor :hp\n attr_accessor :bonus\n def initialize(h, b)\n @hp = h\n @bonus = b\n end\nend\nline1 = gets.chomp.split(\" \")\ns = line1[0].to_i\nn = line1[1].to_i\n\nline_hp = []\nline_bonus = []\nif n == 1\n line = gets.chomp.split(\" \").map {|x| x.to_i}\n line_hp[0] = line[0]\n line_bonus[0] = line[1]\nelse\n line_hp = gets.chomp.split(\" \").map {|x| x.to_i}\n line_bonus = gets.chomp.split(\" \").map {|x| x.to_i}\nend\nenemy = []\n\nfor i in 1..n\n enemy << Dragon.new(line_hp[i-1], line_bonus[i-1])\nend\n\nenemy.sort_by {|obj| obj.hp}\n\nwin = true\nfor e in enemy\n if s > e.hp\n s += e.bonus\n else\n win = false\n break\n end\nend\n\nif win\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "s, n = gets.split(\" \").map(&:to_i)\na = []\n\nn.times do |i|\n a[i] = gets.split(\" \").map(&:to_i)\nend\n\na.sort!{|x,y| x[0] <=> y[0]}\n\na.each do |el|\n if s < el[0]\n puts \"NO\"\n exit\n end\n s += el[1]\nend\n\nputs \"YES\""}, {"source_code": "s, _ = gets.split.map(&:to_i)\nreadlines.map(&:strip).map { |x| x.split.map(&:to_i) }.sort_by! { |x| x[0]}.each do |x|\n if s < x[0]\n puts \"NO\"\n exit\n else\n s += x[1]\n end\nend\nputs \"YES\""}, {"source_code": "a=gets.chomp.split(\" \")\npow=a[0].to_i\ndrag=a[1].to_i\ndragary=[]\ndrag.times do\ntemp=gets.chomp.split(\" \")\ntemp[0]=temp[0].to_i \ntemp[1]=temp[1].to_i\ndragary<< temp\nend\ndragary.sort!\ni=0\nloop do \nif dragary[i][0]<=pow\npow+=dragary[i][1]\ni+=1\nelse\nputs \"NO\"\nbreak\nend\nbreak if i>drag-1\nend\nif i>drag-1\nputs \"YES\"\nend\n"}, {"source_code": "s, n = gets.chomp.split(/ /).map(&:to_i)\nkirito = s\nwinner = true\nn.times do\n x, y = gets.chomp.split(/ /).map(&:to_i)\n if kirito > x\n kirito += y\n else\n winner = false\n break\n end\nend\nif winner\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\nfirst_line = gets\nstrength = first_line.split(' ')[0].to_i\ncount_of_dragons = first_line.split(' ')[1].to_i\n\ndragons = []\n\n\n(1..count_of_dragons).each do |i|\n\tdragon = {}\n\tdrag_str = gets\n\tdragon[\"strength\"] = drag_str.split(' ')[0].to_i\n\tdragon[\"bonus\"] = drag_str.split(' ')[1].to_i \n\tdragons.push(dragon)\nend\n\ndragons.sort_by!{ |d| d[\"strength\"] }\n\ndragons.each do |d|\n\tif strength > d[\"strength\"] then\n\t\tstrength+= d[\"bonus\"]\n\telse\n\t\tputs \"NO\"\n\t\texit\n\tend\n\tputs \"YES\"\n\texit\nend\n"}, {"source_code": "#!/usr/bin/env ruby\nfirst_line = gets\nstrength = first_line.split(' ')[0].to_i\ncount_of_dragons = first_line.split(' ')[1].to_i\n\ndragons = []\n\n\n(1..count_of_dragons).each do |i|\n\tdragon = {}\n\tdrag_str = gets\n\tdragon[\"strength\"] = drag_str.split(' ')[0].to_i\n\tdragon[\"bonus\"] = drag_str.split(' ')[1].to_i \n\tdragons.push(dragon)\nend\n\ndragons = dragons.sort_by{ |d| d[\"strength\"] }\n\ndragons.each do |d|\n\tif strength > d[\"strength\"] then\n\t\tstrength+= d[\"bonus\"]\n\telse\n\t\tputs \"NO\"\n\t\texit\n\tend\n\tputs \"YES\"\n\texit\nend\n"}, {"source_code": "s,n = gets.split.map &:to_i\na = []\nn.times do |i|\na[i] = gets\na.sort!\nend\nfor i in a\n\tx,y = i.split.map &:to_i\n\tif x < s\n\t\ts += y\n\telse\n\t\ts = -1\n\tend\t\nend\nif s == -1\n\tputs 'NO'\nelse\n\tputs 'YES'\nend\n\n\n\n"}, {"source_code": "s,n = gets.split(\" \").map(&:to_i)\nwin = true\ndragons = []\nn.times do\n dragons << gets.split(\" \").map(&:to_i)\nend\ndragons.sort! do |a,b|\n if a[0] != b[0]\n a[0] <=> b[0]\n else\n b[1] <=> a[1]\n end\nend\ndragons.each { |dragon|\n if s >= dragon[0]\n s += dragon [1]\n else\n win = false\n break\n end\n}\nputs win ? \"YES\" : \"NO\""}, {"source_code": "s, n = gets.split.map(&:to_i)\nd = []\nn.times {\n d << gets.split.map(&:to_i)\n}\nd = d.sort_by{ |x| x[0]}\nputs d.to_s\nflag = true\nd.each do |x|\n if s <= x[0]\n flag = false\n else\n s += x[1]\n end\nend\n\nputs flag ? \"YES\" : \"NO\"\n"}, {"source_code": "#!/usr/bin/env ruby\n\ns,n = gets.split.map(&:to_i)\n\nx = n.times.map { gets.split.map(&:to_i) }\n\nyes = 1\nn.times do\n id = -1\n x.each_with_index do |arr, i|\n if arr[0] <= s\n id = i\n break\n end\n end\n if id == -1\n yes = 0\n break\n end\n s += x[id][1]\n x.delete_at(id)\nend\n\nputs(yes == 1 ? 'YES' : 'NO')\n"}, {"source_code": "s, n = gets.split.map(&:to_i)\na = []\nn.times do\n b = gets.split.map(&:to_i)\n a << b\nend\na.sort!\nans = 1\nn.times do |i|\n if s < a[i][0]\n ans = 0\n break\n end\n s += a[i][1]\nend\nputs ans == 0 ? \"NO\" : \"YES\"\n"}, {"source_code": "first_line = gets.chomp.split(' ')\ns = first_line[0].to_i\nn = first_line[1].to_i\ndragons = []\n(0...n).each do |i|\n\tline = gets.chomp.split(' ')\n\tdragons[i] = {\n\t\tstrength: line[0].to_i,\n\t\tbonus: line[1].to_i\n\t}\nend\n\ndragons.sort { |a, b| a[:strength] <=> b[:strength] }\ndefeated = false\ndragons.each do |elem|\n\tif s <= elem[:strength]\n\t\tdefeated = true\n\t\tbreak\n\tend\n\ts += elem[:bonus]\nend\n\nif defeated\n\tputs \"NO\"\nelse\n\tputs \"YES\"\nend\n\n\n"}], "src_uid": "98f5b6aac08f48f95b2a8ce0738de657"} {"source_code": "gets.strip.to_i.times do\n n = gets.strip.to_i\n sticks = gets.strip.split(' ').map(&:to_i)\n h = Hash.new(0)\n sticks.each do |s|\n h[s] += 1\n end\n\n if h.any? { |k, v| (v % 2) != 0 }\n puts \"NO\"\n else\n vals = []\n h.each do |k,v|\n h[k] = v / 2\n (v / 2).times { vals << k }\n end\n vals.sort!\n i , j = 0, vals.size - 1\n last = nil\n res = true\n while i < j\n if vals[i] * vals[j] != last && i != 0\n puts \"NO\"\n res = false\n break\n end\n last = vals[i] * vals[j]\n i += 1\n j -= 1\n end\n puts \"YES\" if res\n end\nend\n", "positive_code": [{"source_code": "q = gets.to_i\nans = []\nq.times do\n n = gets.to_i\n pp = gets.split.map(&:to_i).sort{|a,b|b<=>a}\n\n vv = []\n can = true\n\n 0.step(n*4-2,2) do |i|\n # \u30da\u30a2\u304c\u306a\u3044\u3068\u30c0\u30e1\n unless pp[i]==pp[i+1]\n can = false\n break\n end\n\n vv << pp[i]\n end\n #puts vv.to_s #d\n\n if can\n e1 = vv.shift\n e2 = vv.pop\n s = e1*e2\n while vv.size > 1 do\n e1 = vv.shift\n e2 = vv.pop\n if e1*e2 != s\n can = false\n break\n end\n end\n end\n\n ans << (can ? 'YES' : 'NO')\nend\nputs ans\n"}, {"source_code": "t = gets.to_i\nt.times do |index|\n n = (gets.to_i)*4\n a = gets.split(\" \").map(&:to_i)\n b = []\n a.sort!\n i = 0\n ans = true\n while i < n\n if a[i] != a[i+1] \n ans = false\n end\n b.push a[i]\n i += 2\n end\n i = 0\n j = n/2 - 1\n area = b[i]*b[j]\n while i <= j\n if (b[i])*(b[j]) != area\n ans = false\n end\n i += 1\n j -= 1\n end\n puts ans ? \"YES\" : \"NO\"\nend"}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i).tally\n\tif a.any? { |k, v| v.odd? }\n\t\tputs 'NO'\n\telse\n\t\tb = a.reduce([]) { |acc, (k, v)| acc.concat([k] * (v / 2)) }.sort\n\t\tc = (0...n).map { |i| b[i] * b[~i] }\n\t\tputs c == c.rotate(1) ? \"YES\" : \"NO\"\n\tend\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n a.sort!\n s = a[0] * a.last\n ok = true\n (0...n).each do |i|\n ok = false if a[2 * i] != a[2 * i + 1] or a[4 * n - 2 * i - 1] != a[4 * n - 2 * i - 2] or a[2 * i] * a[4 * n - 2 * i - 1] != s\n end\n unless ok\n puts \"NO\"\n else\n puts \"YES\"\n end\nend"}], "negative_code": [{"source_code": "q = gets.to_i\nans = []\nq.times do\n n = gets.to_i\n pp = gets.split.map(&:to_i).sort{|a,b|b<=>a}\n\n vv = []\n can = true\n\n 0.step(n*4-2,2) do |i|\n # \u30da\u30a2\u304c\u306a\u3044\u3068\u30c0\u30e1\n unless pp[i]==pp[i+1]\n can = false\n break\n end\n\n vv << pp[i]\n end\n #puts vv.to_s #d\n\n if can\n s = vv.inject(:*) / n\n while vv.size > 1 do\n e1 = vv.shift\n idx = pp.index(s/e1)\n if idx.nil?\n can = false\n break\n end\n vv.delete_at(idx)\n end\n end\n\n ans << (can ? 'YES' : 'NO')\nend\nputs ans"}], "src_uid": "08783e3dff3f3b7eb586931f9d0cd457"} {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n f = true\r\n ans = 0\r\n a.each do |x|\r\n (ans += 1) if (x != 0 && f)\r\n f = x == 0 ? true : false\r\n end\r\n puts (ans > 2)?2 : ans\r\nend", "positive_code": [{"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ngets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n\r\n ans = 0\r\n flag = false\r\n n.times do |i|\r\n if !flag && a[i] != 0\r\n ans += 1\r\n flag = true\r\n elsif a[i] == 0\r\n flag = false\r\n end\r\n end\r\n\r\n puts [ans,2].min\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n gets\r\n as = gets.split.map(&:to_i)\r\n bs = as.drop_while { |a| a == 0 }.reverse.drop_while { |a| a == 0 }.reverse\r\n if bs.empty?\r\n p 0\r\n elsif bs.include?(0)\r\n p 2\r\n else\r\n p 1\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ngets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n\r\n ans = 0\r\n flag = false\r\n n.times do |i|\r\n if !flag && a[i] != 0\r\n ans += 1\r\n flag = true\r\n elsif a[i] == 0\r\n flag = false\r\n end\r\n end\r\n\r\n puts ans\r\nend\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ngets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n list = []\r\n\r\n k = []\r\n n.times do |i|\r\n if a[i] != 0\r\n k << a[i]\r\n else\r\n list << k if !k.empty?\r\n k = []\r\n end\r\n end\r\n list << k if !k.empty?\r\n\r\n puts list.size\r\nend\r\n\r\n"}, {"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n p xs.slice_when { |a, b| (a == 0) != (b == 0) }.count { |xs| xs.max > 0 }\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n p xs.drop_while { |x| x == 0 }.reverse.drop_while { |x| x == 0 }.reverse.slice_when { |x| x == 0 }.count { |xs| xs.max > 0 }\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n f = true\r\n ans = 0\r\n a.each do |x|\r\n (ans += 1) if (x != 0 && f)\r\n f = x == 0 ? true : false\r\n end\r\n puts ans\r\nend"}], "src_uid": "da3d1b2615d51044a7b43bd0ce939f4c"} {"source_code": "H,W = gets.split.map(&:to_i)\npic = []\ncell = 0\nH.times do\n s = gets.chomp\n cell += s.count(\"*\")\n pic << s\nend\n\nflg = false\nver = false\n(H-2).times do |i|\n 1.upto(W-2) do |j|\n if pic[i][j] == \"*\"\n pic[i][j] = \".\"\n k = i+1\n while k < H && pic[k][j] == \"*\"\n pic[k][j] = \".\"\n if !ver && k < H-1 && pic[k][j-1] == \"*\" && pic[k][j+1] == \"*\" && pic[k+1][j] == \"*\"\n l,r = j-1,j+1\n while l >= 0 && pic[k][l] == \"*\"\n pic[k][l] = \".\"\n l -= 1\n end\n while r < W && pic[k][r] == \"*\"\n pic[k][r] = \".\"\n r += 1\n end\n ver = true\n end\n k += 1\n end\n flg = true\n break\n end\n end\n break if flg\nend\nemp = true\nH.times do |i|\n W.times do |j|\n emp = false if pic[i][j] == \"*\"\n end\nend\n#p pic\nputs emp && ver ? \"YES\" : \"NO\"", "positive_code": [{"source_code": "h, w = gets.split.map(&:to_i)\nf = h.times.map{gets.chomp}\nmemo_left = (0..h).map{[0] * w}.to_a\nmemo_up = (0..h).map{[0] * w}.to_a\nmemo_right = (0..h).map{[0] * w}.to_a\nmemo_down = (0..h).map{[0] * w}.to_a\ncnt = f.map{|s| s.count('*')}.inject(:+)\n\nh.times{|i|\n w.times{|j|\n next if f[i][j] != '*'\n memo_left[i][j] = (i > 0 ? memo_left[i - 1][j] : 0) + 1\n memo_up[i][j] = (j > 0 ? memo_up[i][j - 1] : 0) + 1\n }}\n(h-1).downto(0).each{|i|\n (w-1).downto(0).each{|j|\n next if f[i][j] != '*'\n memo_right[i][j] = (i < h - 1 ? memo_right[i + 1][j] : 0) + 1\n memo_down[i][j] = (j < w - 1 ? memo_down[i][j + 1] : 0) + 1\n }}\n\n\nh.times{|i|\n w.times{|j|\n next if f[i][j] != '*'\n a = memo_left[i][j]\n b = memo_right[i][j]\n c = memo_up[i][j]\n d = memo_down[i][j]\n if a > 1 and b > 1 and c > 1 and d > 1 and a + b + c + d - 3 == cnt\n puts :YES\n exit\n end\n }\n}\nputs :NO\n"}], "negative_code": [{"source_code": "h, w = gets.split.map(&:to_i)\nf = h.times.map{gets.chomp}\ncnt = f.map{|s| s.count('*')}.inject(:+)\nh.times{|i|\n w.times{|j|\n a = f[i].chars.drop_while{|x|x==?.}.take_while{|x|x==?*}.size\n b = (0...h).drop_while{|i|f[i][j]==?.}.take_while{|i|f[i][j]==?*}.size\n if a + b - 1 == cnt\n puts :YES\n exit\n end\n }\n}\nputs :NO\n"}, {"source_code": "h, w = gets.split.map(&:to_i)\nf = h.times.map{gets.chomp}\ncnt = f.map{|s| s.count('*')}.inject(:+)\nh.times{|i|\n w.times{|j|\n a = i.downto(0).take_while{|ii| f[ii][j] == ?*}.size\n b = i.upto(h-1).take_while{|ii| f[ii][j] == ?*}.size\n c = j.downto(0).take_while{|jj| f[i][jj] == ?*}.size\n d = j.upto(w-1).take_while{|jj| f[i][jj] == ?*}.size\n if a + b + c + d - 3 == cnt\n puts :YES\n exit\n end\n }\n}\nputs :NO\n"}], "src_uid": "6405161be280fea943201fa00ef6f448"} {"source_code": "# frozen_string_literal: true\r\n\r\ndef distance(numbers)\r\n a, b = numbers.minmax\r\n res = 0\r\n while a * 2 < b\r\n res += 1\r\n a *= 2\r\n end\r\n res\r\nend\r\n\r\ntest = gets.to_i\r\ntest.times do\r\n n = gets.chomp.to_i\r\n numbers = gets.chomp.split.map(&:to_i)\r\n result = (0..n-2).reduce(0) do |total, index|\r\n total + distance(numbers[index..index+1]) \r\n end\r\n puts result\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n a=gets.split.map(&:to_i)\r\n q=a[0]\r\n c=0\r\n a.each do |aa|\r\n x,y=[q,aa].sort\r\n while x*2= bigger\r\n nextElement *= 2\r\n count += 1\r\n end\r\n return count\r\nend\r\n\r\nt.times {\r\n n = gets.chomp.to_i\r\n a = gets.chomp.split.map(&:to_i)\r\n\r\n count = 0\r\n 0.upto(n - 2) { |i|\r\n smaller = a[i] < a[i + 1] ? a[i] : a[i + 1]\r\n bigger = a[i] > a[i + 1] ? a[i] : a[i + 1]\r\n \r\n count += getNumInsertions(smaller, bigger)\r\n }\r\n\r\n puts count\r\n}\r\n"}, {"source_code": "gets;$<.map{b=gets.split.map &:to_i;p (b.zip(b[1..])[..-2].map &:sort).map{|x,y|(-1-y/-x).to_s(2).size-1}.sum}"}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tputs a.each_cons(2).sum { |x, y|\n\t\t\tx, y = [x, y].sort\n\t\t\tres = 0\n\t\t\twhile x * 2 < y\n\t\t\t\tres += 1\n\t\t\t\tx *= 2\n\t\t\tend\n\t\t\tres\n\t }\nend\n"}, {"source_code": "def method(x, y)\r\n x, y = [x, y].minmax\r\n 0.step do |i|\r\n break i if x * 2 >= y\r\n x *= 2\r\n end\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n puts a.each_cons(2).map { |x, y| method(x, y) }.sum\r\nend"}], "negative_code": [], "src_uid": "a544dd9fd96379f66a960de6f973dd50"} {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tx, y = a.count(1), a.count(2)\n\tx -= 2 if y.odd?\n\tputs x.odd? || x < 0 ? 'NO' : 'YES'\nend\n", "positive_code": [{"source_code": "def is_fair_division?(candies, n)\r\n return true if n == 0\r\n\r\n ones_count = 0\r\n twos_count = 0\r\n candies.each do |candy|\r\n if candy == 1\r\n ones_count += 1\r\n elsif candy == 2\r\n twos_count += 1\r\n end\r\n end\r\n\r\n if ones_count % 2 == 1\r\n return false\r\n else\r\n if ones_count >= 2 || twos_count % 2 == 0\r\n return true\r\n else\r\n return false\r\n end\r\n end\r\nend\r\n\r\nt = gets.chomp().to_i\r\nt.times do |_|\r\n n = gets.chomp().to_i\r\n candies = gets.chomp().split(\"\").map(&:to_i)\r\n if is_fair_division?(candies, n)\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\nn=gets.to_i\r\na=gets.split(' ').map(&:to_i).sort\r\nif a.reduce(:+) % 2 == 1 || a[0] == 2 && n % 2 == 1\r\nputs 'NO'\r\nelse\r\nputs 'YES'\r\nend\r\nend"}, {"source_code": "gets.to_i.times {\n gets\n a = 0; b = 0\n gets.split.map!(&:to_i).each { _1 == 1 ? (a += 1) : (b += 1) }\n\n if b.odd?\n if a < 2\n puts \"No\"\n next\n end\n\n b += 1\n a -= 2\n end\n\n if a.odd?\n puts \"No\"\n next\n end\n\n puts \"Yes\"\n}\n"}, {"source_code": "def solve\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n\r\n one = a.count(1)\r\n two = n - one\r\n # STDERR.puts [one, two].inspect\r\n\r\n possible = (0 .. two).any? { |x|\r\n (two - 2 * x).abs * 2 <= one and one.even?\r\n }\r\n puts possible ? \"YES\" : \"NO\"\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n solve\r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n a = gets.split.map { |v| v.to_i }\r\n puts a.sum.even? && (!a.count(1).zero? || a.count(2).even?) ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "gets.to_i.times{gets;a=gets.count'1';puts a%2>0||a<$_.size%4?:NO:'YES'}"}, {"source_code": "a = gets.to_i\r\nfor i in 1..a do\r\n x = gets.to_i\r\n b = gets.chop.split(/ /).map(&:to_i)\r\n c = b.sum\r\n if c % 2 == 1\r\n print(\"NO\", \"\\n\")\r\n else\r\n if b.include? 1\r\n print(\"YES\", \"\\n\")\r\n else\r\n if x % 2 == 0\r\n print(\"YES\", \"\\n\")\r\n else\r\n print(\"NO\", \"\\n\")\r\n end\r\n end\r\n end\r\nend"}, {"source_code": "t = gets.to_i\n\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i).tally\n\n a[1] ||= 0\n a[2] ||= 0\n\n if a[2].odd?\n if a[1] > 0 && a[1].even?\n puts 'yes'\n else\n puts 'no'\n end\n else\n if a[1].odd?\n puts 'no'\n else\n puts 'yes'\n end\n end\nend"}, {"source_code": "#!/usr/bin/env ruby\r\n\r\ngets.to_i.times {\r\n n = gets.to_i\r\n sweets = gets.split.map &:to_i\r\n tv1 = sweets.select{|v| v == 1}.size\r\n tv2 = sweets.select{|v| v == 2}.size\r\n res = false\r\n (tv1 + 1).times do |v1|\r\n (tv2 + 1).times do |v2|\r\n g1 = v1 + v2 * 2\r\n g2 = (tv1 - v1) + (tv2 - v2) * 2\r\n #puts [g1, g2].to_s\r\n if g1 == g2\r\n res = true\r\n end\r\n end\r\n end\r\n\r\n puts res ? \"YES\" : \"NO\"\r\n}"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n cnt = [0] * 3\r\n a.each do |i|\r\n cnt[i] += 1\r\n end\r\n if cnt[2] % 2 == 1 && (cnt[1] < 2 || (cnt[1] - 2) % 2 == 1) || cnt[2] % 2 == 0 && cnt[1] % 2 == 1\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\nend"}, {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n = gets.chomp.to_i\r\n a = gets.chomp.split(\" \").map(&:to_i)\r\n hash = Hash.new(0)\r\n ans = 0\r\n a.each do |i|\r\n hash[i] += 1\r\n ans += i\r\n end\r\n if ans % 2 != 0\r\n puts \"NO\"\r\n else\r\n if hash[1] >= 1 \r\n puts \"YES\"\r\n elsif hash[2] % 2 != 0\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\n end\r\nend"}, {"source_code": "require 'prime'\r\nt = gets.chomp.to_i\r\nt.times do\r\n n = gets.chomp.to_i\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n if arr.sum % 2 != 0 || arr.sum % 2 == 0 && arr.count(1) == 0 && arr.count(2) % 2 != 0\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\nend"}, {"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n a=gets.split.map(&:to_i)\r\n s=a.sum\r\n if s.odd?\r\n puts \"NO\"\r\n next\r\n end\r\n s2=s/2\r\n if s2.even?\r\n puts \"YES\"\r\n elsif a.include?(1)\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "def is_fair_division?(candies, n)\r\n return true if n == 0\r\n\r\n ones_sum = 0\r\n twos_sum = 0\r\n candies.each do |candy|\r\n if candy == 1\r\n ones_sum += 1\r\n elsif candy == 2\r\n twos_sum += 2\r\n end\r\n end\r\n\r\n return (ones_sum % 2 == 0) && (twos_sum % 2 == 0)\r\nend\r\n\r\nt = gets.chomp().to_i\r\nt.times do |_|\r\n n = gets.chomp().to_i\r\n candies = gets.chomp().split(\"\").map(&:to_i)\r\n if is_fair_division?(candies, n)\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend"}, {"source_code": "t = gets.to_i\n\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i).tally\n\n a[1] ||= 0\n a[2] ||= 0\n\n if (2 * a[2] + a[1]).odd?\n puts 'no'\n elsif a[2] <= a[1]\n puts 'yes'\n elsif (a[2] - 2 * a[1]).even?\n puts 'yes'\n else\n puts 'no'\n end\nend"}, {"source_code": "t = gets.to_i\n\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i).tally\n\n a[1] ||= 0\n a[2] ||= 0\n\n if a[1].even? && a[2].even?\n puts 'yes'\n else\n puts 'no'\n end\nend"}], "src_uid": "1d9d34dca11a787d6e2345494680e717"} {"source_code": "t = gets.to_i\nlet = [\"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\"]\nt.times do\n n,k = gets.split.map(&:to_i)\n puts (let[0,k]*(n/k) + let[0,n%k]).join\nend\n", "positive_code": [{"source_code": "gets\n$<.each{|e|n,k=e.split.map &:to_i;puts n.times.map{|i|(97+i%k).chr}*''}"}, {"source_code": "\n\nALPHA = ('a'..'z').to_a\ndef solution\n count = read_int\n count.times do\n n, k = read_ints\n puts ALPHA[0...k].cycle.first(n).join(\"\")\n end\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n\n"}, {"source_code": "# Functions\ndef handle(n, k)\n sample = \"\"\n k.times { |i| sample << (97 + i).chr }\n s = sample * (n / k)\n s << sample.slice(0, n % k)\n return s\nend\n\n\n# MAIN\nt = gets.to_i # 1 <= t <= 100\n\n\nt.times do |i|\n str = gets.split(\" \")\n n = str[0].to_i # 1 <= n <= 100\n k = str[1].to_i # 1 <= k <= min(n_i, 26)\n puts handle(n, k)\nend\n"}, {"source_code": "t = gets.chomp.to_i\nalph = \"abcdefghijklmnopqrstuvwxyz\"\nt.times do |testcase|\n (n,k) = gets.split.map(&:to_i)\n cur = 0\n res = \"\"\n n.times do |i|\n if cur == k\n cur = 0\n end\n res< 0\n ans += alp_arr[0..mod-1].join\n end\n puts ans\nend"}, {"source_code": "n = gets.to_i\n(1..n).each do |i|\n a, b = gets.split.map(&:to_i)\n puts (('a'..('a'.ord + b - 1).chr).to_a.join * 100)[0..a - 1]\nend"}, {"source_code": "s = \"abcdefghijklmnopqrstuvwxyz\"\ngets.to_i.times do\n n,k = gets.split.map(&:to_i)\n ans = \"\"\n (n/k).times do\n ans += s[0,k]\n end\n ans += s[0,n%k]\n puts ans\nend"}, {"source_code": "# https://codeforces.com/problemset/problem/1092/A\n\ndef solution(n, k)\n s = \"\"\n j = 0\n n.times do |i|\n s += ((i % k) + 97).chr\n end\n return s\nend\n\nq = gets.chomp.to_i\nq.times do\n n, k = gets.chomp.split(\" \").map(&:to_i)\n puts solution(n, k)\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n, k = gets.split.map(&:to_i)\n s = ''\n i = 0\n n.times do\n s += ('a'.ord + i).chr\n i += 1\n i %= k\n end\n puts s\nend\n"}, {"source_code": "# \n\ndef f(n,k)\n code_a=97\n ans=[]\n for i in 0..n-1\n ans<= 2 do\n a[0]+=1; a[-1]-=1; a.sort!\n #p a\nend\np a.uniq.map {|x| a.count(x) }.inject(:+)-1"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nwhile a[-1]-a[0] >= 2 do\n a[0]+=1; a[-1]-=1; a.sort!\nend\nputs a.uniq.map {|x| a.count(x) }.max"}], "src_uid": "71cead8cf45126902c518c9ce6e5e186"} {"source_code": "cases = gets.chomp.to_i\n\ncases.times do |i|\n n = gets.chomp.to_i\n hs = gets.chomp.split(\" \").map(&:to_i)\n\n failed = false\n hs.each_with_index do |h, idx|\n if h < idx\n failed = true\n break\n else\n hs[(idx + 1)] += h - idx if hs[(idx + 1)]\n end\n end\n\n puts failed ? \"NO\" : \"YES\"\nend", "positive_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n need, cur, ok = 0, 0, true\r\n n.times do |i|\r\n need += i\r\n cur += a[i]\r\n ok = false if cur < need\r\n end\r\n puts ok ? \"YES\" : \"NO\"\r\nend"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n n, h, res = 0, 0, true\r\n n.times do |i|\r\n n += i\r\n h += a[i]\r\n res = false if h < n\r\n end\r\n puts res ? \"YES\" : \"NO\"\r\nend"}], "src_uid": "7a8c4ba98a77097faff625b94889b365"} {"source_code": "t = gets.to_i\r\n\r\nt.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n\r\n ans = 0\r\n n.times do |i|\r\n if a[i] > m\r\n ans += a[i]-m\r\n m += a[i]-m\r\n end\r\n\r\n m -= a[i]\r\n end\r\n\r\n puts ans\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n puts [gets.split.map(&:to_i).sum - m, 0].max\r\nend"}, {"source_code": "gets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n puts([gets.split.map(&:to_i).sum - m, 0].max)\r\nend"}, {"source_code": "gets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n x = 0\r\n w = gets.split.map(&:to_i)\r\n for item in w\r\n x += item\r\n end\r\n puts((x <= m )? 0 : x - m)\r\nend"}, {"source_code": "gets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n as = gets.split.map(&:to_i)\r\n p [as.sum - m, 0].max\r\nend\r\n"}, {"source_code": "def solve(xs, m)\n total = xs.sum\n [total - m, 0].max\nend\n\nt = gets.chomp.to_i\n\nresults = []\n\nt.times do\n n, m = gets.chomp.split.map(&:to_i)\n xs = gets.chomp.split.map(&:to_i)\n results << solve(xs, m)\nend\n\nputs results\n"}, {"source_code": "gets.to_i.times do\n n,m = gets.chomp.split.map(&:to_i)\n a = gets.chomp.split.map(&:to_i)\n ans = 0\n puts [a.reduce(:+) - m,0].max\nend\n"}], "negative_code": [], "src_uid": "7276d7e3a4b594dc64c1ba56fb1a3628"} {"source_code": "\ndef solve(a, b)\n return -1 unless a.reduce(&:+) == b.reduce(&:+)\n ans = []\n 0.upto (a.size - 1) do |i|\n if a[i] < b[i]\n diff = b[i] - a[i]\n for j in (i+1)..(a.size - 1) do\n break if diff == 0\n next if a[j] < b[j]\n cnt = [diff, a[j] - b[j]].min\n cnt.times do\n ans << [j+1, i+1]\n diff -= 1\n a[i] += 1\n a[j] -= 1\n end\n end\n\n elsif a[i] > b[i]\n diff = a[i] - b[i]\n for j in (i+1)..(a.size - 1) do\n break if diff == 0\n next if a[j] > b[j]\n cnt = [diff, b[j] - a[j]].min\n cnt.times do \n ans << [i+1, j+1]\n diff -= 1\n a[i] -= 1\n a[j] += 1\n end\n end\n end\n end\n\n ans\nend\n\nt = gets.chomp.to_i\nt.times do\n gets\n a = gets.chomp.split(' ').map(&:to_i)\n b = gets.chomp.split(' ').map(&:to_i)\n\n ans = solve(a, b)\n if ans == -1\n puts \"-1\\n\" \n else\n puts \"#{ans.size}\\n\"\n for i, j in ans do\n puts \"#{i} #{j}\\n\"\n end\n end\nend\n\n", "positive_code": [{"source_code": "def read_array()\n gets.split(\" \").map { |s| s.to_i }\nend\nt = gets.to_i\nfor z in 1..t\n n = gets.to_i\n a, b = read_array, read_array\n m, p = [], []\n for i in 0...n\n x = a[i] - b[i]\n if a[i] > b[i]\n m << [i + 1, a[i] - b[i]]\n elsif a[i] < b[i]\n p << [i + 1, b[i] - a[i]]\n end\n end\n res = []\n while p.length() > 0 && m.length() > 0\n x = [p[-1][1], m[-1][1]].min\n p[-1][1] -= x\n m[-1][1] -= x\n while x > 0\n x -= 1\n res << [m[-1][0], p[-1][0]]\n end\n if p[-1][1] == 0\n p.pop()\n end\n if m[-1][1] == 0\n m.pop()\n end\n end\n if p.length() != 0 || m.length() != 0\n puts(-1)\n next\n end\n puts res.length()\n for i in res\n puts i[0].to_s + ' ' + i[1].to_s\n end\nend\n"}], "negative_code": [], "src_uid": "accfbd68b9723abf4cd29846e80835ec"} {"source_code": "def gao(i, j, m, n)\n\tm /= n\n\tm > 0 && ($a[i / m][j / m] == '*' || gao(i % m, j % m, m, n))\nend\n\nI = open('input.txt')\nO = open('output.txt', 'w')\nn, k = I.gets.split.map(&:to_i)\n$a = n.times.map{I.gets}\nm = n ** k\nO.puts m.times.map{|i| m.times.map{|j| gao(i, j, m, n) ? '*' : '.'} * ''} * \"\\n\"\n", "positive_code": [{"source_code": "open(\"input.txt\"){|f|open(\"output.txt\",\"w\"){|g|n,k=f.gets.split.map(&:to_i)\na,s=0..n**k-1,[*f]\ng< down\n arry[0] = 1\n arry[1] =3\n for i in 2..up\n arry[i] = arry[i-1]+1\n end\n for j in up+1..down+up\n arry[j] = arry[j-1]-1\n arry[j] = arry[j] == 3 ? 2 : arry[j]\n end\nelse\n arry[0] = 2\n for i in 1..up\n arry[i] = arry[i-1]+1\n end\n\n for j in up+1..down+up\n arry[j] = arry[j-1]-1 \n arry[j] = arry[j] == 2 ? 1 : arry[j]\n end\nend\n\nfor k in 0..down+up-1\n printf(\"#{arry[k]} \")\nend\nputs arry[down+up]\n"}, {"source_code": "up = Integer gets \ndown = Integer gets\nheight = up + down + 1\narry = []\nif up > down\n arry[0] = 1\n arry[1] =3\n for i in 2..up\n arry[i] = arry[i-1]+1\n end\n for j in up+1..down+up\n arry[j] = arry[j-1]-1\n end\nelse\n arry[0] = 2\n for i in 1..up\n arry[i] = arry[i-1]+1\n end\n for j in up+1..down+up\n arry[j] = arry[j-1]-1 \n end\nend\n\nfor k in 0..down+up-1\n printf(\"#{arry[k]} \")\nend\nputs arry[down+up]\n\n"}], "src_uid": "add2285f3f710eb41185d6a83e44b37a"} {"source_code": "DBG = true\nq = gets.to_i\nfor i in 0...q\n n,a,b = gets.split.map{|z| z.to_i}\n if 2*a <= b\n puts \"#{n*a}\"\n else\n puts \"#{b*(n/2)+a*(n%2)}\"\n end\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n\tn, a, b = gets.split.map(&:to_i)\n\tp [a * n, b * (n / 2) + a * (n % 2)].min\nend\n"}, {"source_code": "\n\ndef solution\n q = read_int\n\n q.times do\n n, a, b = read_ints\n\n one_liter = n * a\n two_liter = (n / 2) * b + (n.odd? ? a : 0)\n\n p [one_liter, two_liter].min\n\n end\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"}, {"source_code": "q = gets.to_i\nans = 0\nq.times do\n n, a, b = gets.split.map(&:to_i)\n if a <= b / 2\n puts n * a\n else\n puts (n/2) * b + (n - (n/2*2)) * a\n end\nend"}, {"source_code": "q = gets.strip.to_i\nq.times do\n n, a, b = gets.strip.split.map(&:to_i)\n first = n * a\n second = (n / 2) * b\n second += a if n.odd?\n ans = [first, second].min\n puts ans\nend"}, {"source_code": "gets.to_i.times do\n n,a,b = gets.split.map(&:to_i)\n if a*2 < b\n puts n*a\n else\n puts n/2*b+(n%2)*a\n end\nend"}, {"source_code": "def solve(n,a,b)\n [n*(a),b*(n/2) + a*(n%2)].min\n end\nt = gets.to_i\nt.times{\nn,a,b = gets.split(\" \").map(&:to_i)\nputs solve(n,a,b)\n}\n"}, {"source_code": "# n - required amount of water (in liters)\n# a - 1L bottle cost\n# b - 2L bottle cost\ndef price(n, a, b)\n if 2 * a <= b\n n * a\n else\n n / 2 * b + n % 2 * a\n end\nend\n\ndef respond_n_queries(n)\n n.times do\n n, a, b = gets.chomp.split.map(&:to_i)\n puts price(n, a, b)\n end\nend\n\nqueries = gets.to_i\nrespond_n_queries(queries)\n"}], "negative_code": [{"source_code": "def solve(n,a,b)\n ans = 0\n if(n==1)\n return a\n end\n if(b<=a)\n if(n%2==0)\n return b*(n/2)\n end\n return b*(n/2)+a\n end\n return a*n\n end\n\nt = gets.to_i\n\nt.times{\n\t\nn,a,b = gets.split(\" \").map(&:to_i)\n\nputs solve(n,a,b)\n\n}\n"}, {"source_code": "# n - required amount of water (in liters)\n# a - 1L bottle cost\n# b - 2L bottle cost\ndef price(n, a, b)\n if a <= b\n n * a\n else\n n / 2 * b + n % 2 * a\n end\nend\n\ndef respond_n_queries(n)\n n, a, b = gets.chomp.split.map(&:to_i)\n puts price(n, a, b)\nend\n\nqueries = gets.to_i\nrespond_n_queries(queries)\n"}, {"source_code": "# n - required amount of water (in liters)\n# a - 1L bottle cost\n# b - 2L bottle cost\ndef price(n, a, b)\n if a <= 2 * b\n n * a\n else\n n / 2 * b + n % 2 * a\n end\nend\n\ndef respond_n_queries(n)\n n.times do\n n, a, b = gets.chomp.split.map(&:to_i)\n puts price(n, a, b)\n end\nend\n\nqueries = gets.to_i\nrespond_n_queries(queries)\n"}, {"source_code": "# n - required amount of water (in liters)\n# a - 1L bottle cost\n# b - 2L bottle cost\ndef price(n, a, b)\n if a <= b\n n * a\n else\n n / 2 * b + n % 2 * a\n end\nend\n\ndef respond_n_queries(n)\n n.times do\n n, a, b = gets.chomp.split.map(&:to_i)\n puts price(n, a, b)\n end\nend\n\nqueries = gets.to_i\nrespond_n_queries(queries)\n"}], "src_uid": "beab56c5f7d2996d447320a62b0963c2"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = Array.new(n,0)\nfor i in 1..n-1\n b[i] = b[i-1]+a[i-1]\nend\nmn = b.min\nfor i in 0..n-1\n b[i] -= mn-1\nend\nc = Hash.new(false)\nfor i in 0..n-1\n if c[b[i]] || b[i] > n\n puts -1\n exit\n end\n c[b[i]] = true\nend\nputs b.join(\" \")", "positive_code": [{"source_code": "def main\n n = gets.chomp.to_i\n q = gets.chomp.split.map(&:to_i)\n\n qp = [0]\n for k in q\n qp << qp.last + k\n end\n\n diff = 1 - qp.min\n result = []\n visited = {}\n for k in qp\n if k + diff < 1 or k + diff > n or visited.key?(k + diff)\n puts -1\n return\n else\n result << k + diff\n visited[k + diff] = true\n end \n end\n\n puts result.join(\" \")\nend\n\nmain\n"}, {"source_code": "N = gets.to_i\nQ = gets.split.map &:to_i\nps = [0]\nQ.each{ |q| ps << (ps[-1] + q) }\nmx = ps.max\nmn = ps.min\nif mx - mn == N-1 && ps.uniq.size == N\n puts ps.map{ |r| r - mn + 1 }.join(\" \")\nelse\n p -1\nend"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = Array.new(n,0)\nfor i in 1..n-1\n b[i] = b[i-1]+a[i-1]\nend\nmn = b.min\nfor i in 0..n-1\n b[i] -= mn-1\nend\nc = Hash.new(false)\nfor i in 0..n-1\n if c[b[i]] || b[i] > n\n puts -1\n exit\n end\nend\nputs b.join(\" \")"}, {"source_code": "def main\n n = gets.chomp.to_i\n q = gets.chomp.split.map(&:to_i)\n\n diff = q.inject(0) { |sum, x| sum + x }\n for i in (1..n)\n next if i + diff < 1 or i + diff > n\n\n visited = {i => true, i + diff => true}\n result = [i]\n\n for j in q\n x = result.last + j\n break if x < 1 or x > n or visited.key?(x)\n visited[x] = true\n result << x\n end \n\n result << i + diff\n if result.length == n\n puts result.join(\" \")\n return\n end\n end\n\n puts -1\nend\n\nmain\n"}, {"source_code": "def main\n n = gets.chomp.to_i\n q = gets.chomp.split.map(&:to_i)\n\n diff = q.inject(0) { |sum, x| sum + x }\n for i in (1..n)\n next if i + diff < 1 or i + diff > n\n\n visited = {i => true, i + diff => true}\n result = [i]\n\n for j in q\n x = result.last + j\n break if x < 1 or x > n or visited.key?(x)\n visited[x] = true\n result << x\n end \n\n result << i + diff\n break if visited.key?(i + diff)\n\n if result.length == n\n puts result.join(\" \")\n return\n end\n end\n\n puts -1\nend\n\nmain\n"}, {"source_code": "def main\n n = gets.chomp.to_i\n q = gets.chomp.split.map(&:to_i)\n\n diff = q.last - q.first\n for i in (1..n)\n visited = {i => true, i + diff => true}\n result = [i]\n\n for j in q\n x = result.last + j\n break if x < 1 or visited.key?(x)\n visited[x] = true\n result << x\n end \n\n if result.length == n\n puts result.join(\" \")\n return\n end\n end\n\n puts -1\nend\n\nmain\n"}], "src_uid": "b6ac7c30b7efdc7206dbbad5cfb86db7"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nans = 0\nfor i in 2..n-1\n if a[i] == 1 && a[i-1] == 0 && a[i-2] == 1\n ans += 1\n a[i] = 0\n end\nend\nputs ans", "positive_code": [{"source_code": "p$<.read.scan('1 0 1').size"}, {"source_code": "n = gets.strip.to_i\nflats = gets.strip.gsub(' ', '')\nk = 0\nuntil !flats.include?(\"10101\")\n flats.sub!(\"10101\", \"10001\")\n k += 1\nend\n\nuntil !flats.include?(\"101\")\n flats.sub!(\"101\", \"100\")\n k += 1\nend\nputs k"}], "negative_code": [{"source_code": "p$<.read.count '1 0 1'"}], "src_uid": "ea62b6f68d25fb17aba8932af8377db0"} {"source_code": "n=gets.to_i\npoints=[]\nn.times do\n\tpoints< x } && points.any? {|a, b| a == x && b < y } && points.any? {|a, b| a == x && b > y }\n}\nputs ctr", "positive_code": [{"source_code": "gets; input = STDIN.read.split(\"\\n\")\ninput.map! {|i| i.split(\" \").map(&:to_i)}\n\ncount = 0\n\ninput.each do |i|\n c = [false, false, false, false]\n input.each do |j|\n if i != j\n\n c[0] = true if i[0] > j[0] && i[1] == j[1]\n c[1] = true if i[0] < j[0] && i[1] == j[1]\n c[2] = true if i[0] == j[0] && i[1] < j[1]\n c[3] = true if i[0] == j[0] && i[1] > j[1]\n\n if c.count(true) == 4\n count += 1\n break\n end\n end\n end\n c = [false, false, false, false]\nend\n\nprint count\n"}, {"source_code": "class SupercentralPoint\n # To change this template use File | Settings | File Templates.\n\nend\n\nnumber = STDIN.readline.to_i\n\n#p number\n\n\nz = []\n\npoint = {:x => 0, :y => 0}\n\nnumber.times do\n v = STDIN.readline.split(' ')\n point[:x] = v[0].to_i\n point[:y] = v[1].to_i\n z << point.dup\nend\n\nsupercentral_points = []\n\nz.each do |i|\n z.each do |j|\n if i[:x] == j[:x]\n if i[:y] > j[:y]\n i[:bot] = true\n j[:top] = true\n elsif i[:y] < j[:y]\n j[:bot] = true\n i[:top] = true\n end\n end\n\n\n\n if i[:y] == j[:y]\n if i[:x] > j[:x]\n i[:left] = true\n j[:right] = true\n elsif i[:x] < j[:x]\n j[:left] = true\n i[:right] = true\n end\n\n end\n end\nend\n\n\nz.each do |i|\n\n if i[:top] && i[:bot] && i[:left] && i[:right]\n supercentral_points << i\n end\nend\n\np supercentral_points.count"}, {"source_code": "n = gets.to_i\nhs = Hash.new 0\nn.times{ hs[ gets.split(' ').map(&:to_i) ] = 0 }\nar = hs.keys\nar.product(ar).map(&:flatten).each do |x0,y0,x1,y1|\n vec = [x0,y0]\n if x1 == x0\n if y1 > y0\n hs[vec] |= 1\n elsif y1 < y0\n hs[vec] |= 2\n end\n elsif y1 == y0\n if x1 > x0\n hs[vec] |= 4\n elsif x1 < x0\n hs[vec] |= 8\n end\n end\nend\nputs hs.select{|k,v| v == 15}.count"}, {"source_code": "sin = STDIN\nsout = STDOUT\n# sin = File.open(\"test.in\", \"r\")\n# sout = File.open(\"test.out\", \"w\")\n\nn = sin.readline.to_i\na = []\nn.times {\n |i| a[i] = sin.readline.split.map{|e| e.to_i}\n}\nsout.puts a.find_all{ |e| a.find{|x| x[0] < e[0] && x[1] == e[1]} != nil && a.find{|x| x[0] > e[0] && x[1] == e[1]} != nil \\\n && a.find{|x| x[0] == e[0] && x[1] > e[1]} != nil && a.find{|x| x[0] == e[0] && x[1] < e[1]} != nil}.size\n"}, {"source_code": "n = gets.chomp.to_i\nc = []\nxh = Hash.new()\nyh = Hash.new()\nfor i in 0..n-1\n a = gets.chomp.split(/ /).map!{|x| x.to_i}\n c << a\n if xh.key?(a[0])\n xh[a[0]] << a\n else\n xh[a[0]] = [a]\n end\n if yh.key?(a[1])\n yh[a[1]] << a\n else\n yh[a[1]] = [a]\n end\nend\nxh.each_key{|key| xh[key].sort!{|a1,a2| a1[1] <=> a2[1] } }\nyh.each_key{|key| yh[key].sort!{|a1,a2| a1[0] <=> a2[0] } }\n\nret = 0\nxh.each_key{|key|\n aa = xh[key]\n if aa.length >= 3\n for i in 1..aa.length-2\n yk = aa[i][1]\n if yk > aa[0][1] && yk < aa[aa.length-1][1]\n bb = yh[yk]\n if bb.length >= 3\n if key > bb[0][0] && key < bb[bb.length-1][0]\n ret += 1\n end\n end\n end\n end\n end\n}\nputs ret\n"}, {"source_code": "n = gets.to_i\na = Array.new(n){gets.split.map(&:to_i)}\np a.count{|x, y|\n c = [0] * 9\n a.each{|i, j|\n c[(i <=> x) * 3 + (j <=> y) + 4] += 1\n }\n [1, 3, 5, 7].all?{|_| c[_] > 0}\n}\n"}, {"source_code": "n = gets.to_i\npoints = []\nn.times do\n points << gets.split.map(&:to_i)\nend\nans = 0\npoints.each do |pts1|\n check = 0\n points.each do |pts2|\n check |= 1 if pts1[0] < pts2[0] && pts1[1] == pts2[1]\n check |= 2 if pts1[0] > pts2[0] && pts1[1] == pts2[1]\n check |= 4 if pts1[1] < pts2[1] && pts1[0] == pts2[0]\n check |= 8 if pts1[1] > pts2[1] && pts1[0] == pts2[0]\n end\n ans += 1 if check == 15\nend\np ans\n\n"}, {"source_code": "n = gets.to_i\na = []\nn.times do |i|\n a[i] = gets.split(\" \").map(&:to_i)\nend\n\ncnt = 0\nfor i in 0...n do\n l = r = u = d = false\n for j in 0...n do\n next if i == j\n l = a[j][0] < a[i][0] && a[j][1] == a[i][1] || l\n r = a[j][0] > a[i][0] && a[j][1] == a[i][1] || r\n u = a[j][0] == a[i][0] && a[j][1] > a[i][1] || u\n d = a[j][0] == a[i][0] && a[j][1] < a[i][1] || d\n end\n cnt += 1 if l && r && u && d\nend\n\nputs cnt"}, {"source_code": "n = gets.to_i\nmas = []\nn-=1\nfor i in (0..n) do\n mas[i] = gets.split.map(&:to_i)\nend\ncount = 0\nmas.each do |m1|\n q,w,e,r = false\n mas.each do |m2|\n if m1 != m2\n if m1[0] > m2[0] && m1 [1] == m2[1]\n q = true\n end\n if m1[0] < m2[0] && m1 [1] == m2[1]\n w = true\n end\n if m1[0] == m2[0] && m1 [1] < m2[1]\n e = true\n end\n if m1[0] == m2[0] && m1 [1] > m2[1]\n r = true\n end\n end\n end\n if q && w && e && r\n count+=1\n end\nend\nputs count"}, {"source_code": "\ufeffn = gets.chomp.to_i\n\npoints = []\nn.times do \n x, y = gets.chomp.split(\" \").map{|e| e.to_i}\n points << [x, y]\nend\nsupercentrals = []\n\npoints.each do |point|\n x, y = point[0], point[1]\n right, left, up, down = false, false, false, false\n \n points.each do |point2|\n if point == point2\n next\n end\n x2, y2 = point2[0], point2[1]\n \n if x2 > x and y == y2\n right = true\n elsif x2 < x and y == y2\n left = true\n elsif x == x2 and y2 > y\n up = true\n elsif x == x2 and y2 < y\n down = true\n end\n end\n \n if right and left and up and down\n supercentrals << point\n end\nend\n\nputs supercentrals.length"}, {"source_code": "a = readlines[1..-1].map(&:split).each { |x| x.map!(&:to_i) }\np a.inject(0) {|acc, x| acc + ([a.find_all {|y| x[0] > y[0] and x[1] == y[1] }.size,\n a.find_all {|y| x[0] < y[0] and x[1] == y[1] }.size,\n a.find_all {|y| x[1] > y[1] and x[0] == y[0] }.size,\n a.find_all {|y| x[1] < y[1] and x[0] == y[0] }.size].min >= 1 ? 1 : 0)}"}, {"source_code": "n = gets.chomp.to_i\npoints = []\nn.times do\n points << gets.chomp.split(/ /).map(&:to_i)\nend\nans = 0\nn.times do |i|\n point_1 = points[i]\n x = point_1[0]\n y = point_1[1]\n lower_n = upper_n = left_n = right_n = false\n n.times do |j|\n next if i == j\n point_2 = points[j]\n x_1 = point_2[0]\n y_1 = point_2[1]\n right_n = true if x_1 > x && y_1 == y && !right_n\n left_n = true if x_1 < x && y_1 == y && !left_n\n lower_n = true if x_1 == x && y_1 < y && !lower_n\n upper_n = true if x_1 == x && y_1 > y && !upper_n\n end\n ans += 1 if upper_n && lower_n && left_n && right_n\nend\nputs ans\n"}, {"source_code": "hsX={}\nhsY={}\nn=gets.to_i\nn.times{|i|\n\tx,y=gets.split.map{|e| e.to_i}\n\tif hsX.member?(x)==false\n\t\thsX[x]=[]\n\tend\n\tif hsY.member?(y)==false\n\t\thsY[y]=[]\n\tend\n\thsX[x]<<[y,i]\n\thsY[y]<<[x,i]\n}\nhsX=hsX.select{|k,v|\n\tv.size>2\n}\nhsY=hsY.select{|k,v|\n\tv.size>2\n}\nans=0\n\nvx=hsX.values.map{|xs|\n\txs.sort!\n\txs.shift\n\txs.pop\n\txs\n}\nvy=hsY.values.map{|ys|\n\tys.sort!\n\tys.pop\n\tys.shift\n\tys\n}\nvx.each{|vx1|\n\tvy.each{|vy1|\n\t\tvx1.each{|e1|\n\t\t\tvy1.each{|e2|\n\t\t\t\tans+=1 if e1[1]==e2[1]\n\t\t\t}\t\n\t\t}\n\t}\n}\nputs ans"}, {"source_code": "n = gets.to_i\n\na = Array.new\n\nn.times do |i|\n\ta << gets.split(\" \").map{|x| x.to_i}\nend\n\n#puts a.to_s\n\nsum = 0\n\nfor i in 0...a.length\n\tnext if a.take(i).count{|x,y| a[i][0] == x} > 0\n\tb = a.select{|x,y| x == a[i][0]}\n\tb.sort!{|x,y| x[1] <=> y[1]}\n\tb = b.drop(1)\n\tb.pop\n\t#puts b.to_s\n\tfor j in 0...b.length do\n\t\tif(a.count{|x,y| b[j][1] == y && b[j][0] < x} > 0 &&\n\t\t\ta.count{|x,y| b[j][1] == y && b[j][0] > x} > 0)\n\t\t\tthen\n\t\t\tsum += 1\n\t\tend\n\tend\nend\n\nputs sum\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn = $stdin.gets.to_i\nh = Hash.new { Array.new }\nv = Hash.new { Array.new }\nps = []\nn.times do\n x, y = *$stdin.gets.chomp.split.map(&:to_i)\n ps.push [x, y]\n h[x] += [y]\n v[y] += [x]\nend\n\nh.keys.each do |x|\n h[x].sort!\nend\nv.keys.each do |y|\n v[y].sort!\nend\n\nans = 0\nps.each do |x, y|\n i = h[x].find_index y\n j = v[y].find_index x\n if 0 < i and i < h[x].size-1 and 0 < j and j < v[y].size-1\n ans += 1\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na=[]\nn.times do\n t = gets.split.map(){ |x| x.to_i}\n a << t\nend\n\nans = a.count do |s|\n r1 = a.any? {|t| t[0] == s[0] && t[1] < s[1]}\n r2 = a.any? {|t| t[0] == s[0] && t[1] > s[1]}\n r3 = a.any? {|t| t[0] < s[0] && t[1] == s[1]}\n r4 = a.any? {|t| t[0] > s[0] && t[1] == s[1]}\n r1 == true && r2 == true && r3 == true && r4 == true\n \nend\n\nputs ans"}, {"source_code": "class Point\n\tattr_accessor :x,:y\n\n\tdef initialize(_x,_y)\n\t\tself.x = _x\n\t\tself.y = _y\n\tend\nend\n\n\n\ndef left?(p)\n\t@points.any?{|a| a.x < p.x && p.y == a.y}\nend\n\ndef right?(p)\n\t@points.any?{|a| a.x > p.x && p.y == a.y}\nend\n\ndef upper?(p)\n\t@points.any?{|a| a.x == p.x && p.y < a.y}\nend\n\ndef lower?(p)\n\t@points.any?{|a| a.x == p.x && p.y > a.y}\nend\n\nn = gets.to_i\n@points = []\n\nn.times do\n\tx,y = gets.split(\" \").map(&:to_i)\n\t@points << Point.new(x,y)\nend\n\ncount = 0\n@points.each do |p|\n\tcount += 1 if left?(p) && right?(p) && upper?(p) && lower?(p)\nend\nputs count"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nans = a.count do |x, y|\n check = Array.new(4, false)\n a.each do |xx, yy|\n if xx == x\n check[2] ||= yy < y\n check[3] ||= yy > y\n elsif yy == y\n check[0] ||= xx < x\n check[1] ||= xx > x\n end\n end\n check.all?\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nc = 0\na.each do |x, y|\n check = [0, 0, 0, 0]\n a.each do |xx, yy|\n if xx == x\n check[2] = 1 if yy < y\n check[3] = 1 if yy > y\n elsif yy == y\n check[0] = 1 if xx < x\n check[1] = 1 if xx > x\n end\n end\n c += 1 if check.all?{|x| x == 1}\nend\nputs c\n"}, {"source_code": "n = gets.to_i\nxmi, xmx, ymi, ymx = [1000, -1000, 1000, -1000]\na = n.times.map{gets.split.map(&:to_i)}\nc = 0\na.each do |x, y|\n check = [0, 0, 0, 0]\n a.each do |xx, yy|\n if xx == x\n check[2] = 1 if yy < y\n check[3] = 1 if yy > y\n elsif yy == y\n check[0] = 1 if xx < x\n check[1] = 1 if xx > x\n end\n end\n c += 1 if check.all?{|x| x == 1}\nend\nputs c\n"}, {"source_code": "xs = Array.new(2011) { Array.new }\nys = Array.new(2011) { Array.new }\n\nn = gets.to_i\na = []\nPoint = Struct.new(:x, :y)\n\n(0...n).each { |i|\n x, y = gets.split.map(&:to_i)\n a << Point.new(x, y)\n xs[y+1000] << x\n ys[x+1000] << y\n}\n(0...2011).each { |i|\n xs[i].sort!\n ys[i].sort!\n}\n\nres = 0\na.each { |p|\n if xs[p.y+1000][0] < p.x && p.x < xs[p.y+1000][-1]\n if ys[p.x+1000][0] < p.y && p.y < ys[p.x+1000][-1]\n res += 1\n end\n end\n}\np res\n"}, {"source_code": "points = []\nfor _ in 1..Integer(gets.chomp)\n points << gets.chomp.split.map { |x| x.to_i }\nend\n\ncount = 0\npoints.each { |x, y|\n count += 1 if points.any? {|a, b| b == y && a < x } && points.any? {|a, b| b == y && a > x } && points.any? {|a, b| a == x && b < y } && points.any? {|a, b| a == x && b > y }\n}\nputs count"}, {"source_code": "pts=gets.to_i.times.map{gets.split.map(&:to_i)}\nansx=[]\nansy=[]\npts.group_by{|x,y|x}.each{|_x,ary|ary.sort_by{|x,y|y}[1..-2].each{|pt|ansx<2}\npts.group_by{|x,y|y}.each{|_y,ary|ary.sort_by{|x,y|x}[1..-2].each{|pt|ansy<2}\np (ansx&ansy).size"}], "negative_code": [{"source_code": "a = readlines[1..-1].map(&:split).each { |x| x.map!(&:to_i) }\np a.inject(0) {|acc, x| acc + [a.find_all {|y| x[0] > y[0] and x[1] == y[1] }.size,\n a.find_all {|y| x[0] < y[0] and x[1] == y[1] }.size,\n a.find_all {|y| x[1] > y[1] and x[0] == y[0] }.size,\n a.find_all {|y| x[1] < y[1] and x[0] == y[0] }.size].min >= 1 ? 1 : 0}"}, {"source_code": "a = readlines[1..-1].map(&:split).each { |x| x.map!(&:to_i) }\np a.inject(0) {|acc, x| acc + [a.find_all {|y| x[0] > y[0] and x[1] == y[1] }.size,\n a.find_all {|y| x[0] < y[0] and x[1] == y[1] }.size,\n a.find_all {|y| x[1] > y[1] and x[0] == y[0] }.size,\n a.find_all {|y| x[1] < y[1] and x[0] == y[0] }.size].min }"}, {"source_code": "n = gets.chomp.to_i\npoints = []\nn.times do\n points << gets.chomp.split(/ /).map(&:to_i)\nend\nans = 0\nn.times do |i|\n point_1 = points[i]\n x = point_1[0]\n y = point_1[1]\n lower_n = upper_n = left_n = right_n = false\n n.times do |j|\n next if i == j\n point_2 = points[j]\n x_1 = point_2[0]\n y_1 = point_2[1]\n right_n = true if x_1 > x && y_1 == y && !right_n\n left_n = true if x_1 < x && y_1 == y && !left_n\n lower_n = true if x_1 == x && y_1 < y && !lower_n\n upper_n = true if x_1 == x && y_1 > y && !upper_n\n end\n if upper_n && lower_n && left_n && right_n\n puts point_1.inspect\n end\n ans += 1 if upper_n && lower_n && left_n && right_n\nend\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\npoints = []\nn.times do\n points << gets.chomp.split(/ /).map(&:to_i)\nend\nans = 0\nn.times do |i|\n point_1 = points[i]\n x = point_1[0]\n y = point_1[1]\n neighbor = 0\n n.times do |j|\n next if i == j\n point_2 = points[j]\n x_1 = point_2[0]\n y_1 = point_2[1]\n neighbor += 1 if x_1 > x && y_1 == y\n neighbor += 1 if x_1 < x && y_1 == y\n neighbor += 1 if x_1 == x && y_1 < y\n neighbor += 1 if x_1 == x && y_1 > y\n end\n ans += 1 if neighbor >= 4\nend\nputs ans\n"}, {"source_code": "n=gets.to_i\nhsX=Hash.new{|hash,key| hash[key]=[]}\nhsY=Hash.new{|hash,key| hash[key]=[]}\nn.times{|i|\n\tx,y=gets.split.map{|e| e.to_i}\n\thsX[x]<2\n}\nhsY=hsY.select{|k,v|\n\tv.size>2\n}\nans=0\nhsX.values.each{|vx|\n\thsY.values.each{|vy|\n\t\tvx.each{|e|\n\t\t\tans+=1 if vy.index(e)!=nil\t\n\t\t}\n\t}\n}\nputs ans"}, {"source_code": "n = gets.to_i\na=[]\nn.times do\n t = gets.split.map(){ |x| x.to_i}\n a << t\nend\n\nans = a.count do |s|\n r1 = a.any? {|t| t[0] == s[0] && t[1] < s[1]}\n r2 = a.any? {|t| t[0] == s[0] && t[1] > s[1]}\n r3 = a.any? {|t| t[0] < s[0] && t[1] == s[1]}\n r4 = a.any? {|t| t[0] > s[0] && t[1] == s[1]}\n r1 == true && r2 == true && r3 == true && r4 = true\n \nend\n\nputs ans"}, {"source_code": "points = Hash.new { |h, k| h[k] = [] }\nfor _ in 1..Integer(gets.chomp)\n x, y = gets.chomp.split.map { |x| x.to_i }\n points[x] << y\nend\n\ncount = 0\npoints.values.each { |v|\n count += v.size - 2 if v.size > 2\n}\nputs count"}, {"source_code": "pts=gets.to_i.times.map{gets.split.map(&:to_i)}\nans=[]\npts.group_by{|x,y|x}.each{|_x,ary|ary.sort_by{|x,y|y}[1..-2].each{|pt|ans<2}\npts.group_by{|x,y|y}.each{|_y,ary|ary.sort_by{|x,y|x}[1..-2].each{|pt|ans<2}\np ans.uniq.size"}, {"source_code": "gets; input = STDIN.read.split(\"\\n\")\ninput.map! {|i| i.split(\" \").map(&:to_i)}\n\ncount = 0\n\ninput.each do |i|\n c = 0\n input.each do |j|\n if i != j\n if (i[0] > j[0] && i[1] == j[1]) ||\n (i[0] < j[0] && i[1] == j[1]) ||\n (i[0] == j[0] && i[1] < j[1]) ||\n (i[0] == j[0] && i[1] > j[1])\n c += 1\n end\n if c == 4\n c = 0\n count += 1\n break\n end\n end \n end\nend\n\nprint count"}], "src_uid": "594e64eef7acd055d59f37710edda201"} {"source_code": "n=gets.to_i;\na=gets.split.map{|x| x.to_i; }\nsum=a.inject{|sum,i| sum+i }\nres=[];\na.length.times{ |x|\n if a[x]*a.length==sum then\n res.push(x+1);\n end\n}\nputs(res.length);\nres.map{|x| print(x,\" \"); }\n", "positive_code": [{"source_code": "input = STDIN.read.split(\"\\n\")\n\nn = input[0].to_i\na = input[1].split(\" \").map(&:to_i)\n\n\navg = a.inject(0.0) {|sum, e| sum + e} / n\n\nstr = \"\"\ncount = 0\n\na.each.with_index do |v, k|\n\tif v.to_f == avg\n\t\tstr << (k + 1).to_s << \" \" \n\t\tcount += 1\n\tend\nend\n\nSTDOUT.puts count\nSTDOUT.puts str.chop"}, {"source_code": "n=gets.chomp.to_i\na=[]\nb=[]\nsum=0\na=gets.chomp.strip.split(' ')\ni=0\nwhile i0 ? 0 : [a.count(m),a.each_with_index.select{|a,i|a==m}.map{|a,i|i+1}*\" \"]"}, {"source_code": "sum=gets.to_i*0\na=gets.split.map(&:to_i)\na.each{|s| sum+=s}\nans=[]\na.length.times{|i|\n if a[i]*(a.length-1)==(sum-a[i])\n ans.push(i)\n end\n}\np ans.length\nans.each{|i| print \"#{i+1} \"}\nputs\n"}], "negative_code": [{"source_code": "n=gets.chomp.to_i\na=[]\nb=[]\nsum=0\na=gets.chomp.strip.split(' ')\ni=0\nwhile iv<\n"}, {"source_code": "A = a = gets.to_i\n\nx = 0\nwhile a % 12 == 0\n\ta /= 12\n\tx += 1\nend\n\nb = [2, 13]\n300.times{b.push 13 * b[-1] - 12 * b[-2]}\ny = 0\ny += 1 while b[y] < a\n\nif b[y] != a\n\tputs :NO\nelse\n\tz = 2 * x + y\n\tc = []\n\t(0 .. z / 2).each{|i| c << b[z - 2 * i] * 12 ** i if i != x}\n\tputs :YES\n\tp 1, z + 1, c.size, *c\nend\n"}], "src_uid": "0ef5e0621f13107d0c8786766ae2ac56"} {"source_code": "def solve(n, a, b)\n s = 0\n arr = a[0..0] + a[0..-2].each_with_index.map{|x, i| s += x - b[i]}\n m = (arr + [0]).min\n res = (0...n).select {|i| arr[i] == m }\n res << 0 if m == 0\n res\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nr = (solve(n, a, b) + solve(n, a.reverse, b.reverse[1..-1] + [b[-1]]).map{|x| n - x - 1}).sort.uniq.map{|x| x + 1}\nputs \"#{r.size}\\n#{r.join(' ')}\"\n", "positive_code": [{"source_code": "def solve(n, a, b)\n s = 0\n arr = a[0..0] + a[0..-2].each_with_index.map{|x, i| s += x - b[i]}\n m = (arr + [0]).min\n res = (0...n).select {|i| arr[i] == m }\n res << 0 if m == 0\n res\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nr = (solve(n, a, b) + solve(n, a.reverse, b.reverse[1..-1] + [b[-1]]).map{|x| n - x - 1}).sort.uniq.map{|x| x + 1}\nputs \"#{r.size}\\n#{r.join(' ')}\"\n"}, {"source_code": "def solve(n, a, b)\n s = 0\n arr = a[0..0] + a[0..-2].each_with_index.map{|x, i| s += x - b[i]}\n m = (arr + [0]).min\n res = (0...n).select {|i| arr[i] == m }\n res << 0 if m == 0\n res\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nr = (solve(n, a, b) + solve(n, a.reverse, b.reverse[1..-1] + [b[-1]]).map{|x| n - x - 1}).sort.uniq.map{|x| x + 1}\nputs \"#{r.size}\\n#{r.join(' ')}\"\n"}, {"source_code": "def solve(n, a, b)\n s = 0\n arr = a[0..0] + a[0..-2].each_with_index.map{|x, i| s += x - b[i]}\n m = (arr + [0]).min\n res = (0...n).select {|i| arr[i] == m }\n res << 0 if m == 0\n res\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nr = (solve(n, a, b) + solve(n, a.reverse, b.reverse[1..-1] + [b[-1]]).map{|x| n - x - 1}).sort.uniq.map{|x| x + 1}\nputs \"#{r.size}\\n#{r.join(' ')}\""}, {"source_code": "def solve(n, a, b)\n s = 0\n arr = a[0..0] + a[0..-2].each_with_index.map{|x, i| s += x - b[i]}\n m = (arr + [0]).min\n res = (0...n).select {|i| arr[i] == m }\n res << 0 if m == 0\n res\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nr = (solve(n, a, b) + solve(n, a.reverse, b.reverse[1..-1] + [b[-1]]).map{|x| n - x - 1}).sort.uniq.map{|x| x + 1}\nputs \"#{r.size}\\n#{r.join(' ')}\""}, {"source_code": "def solve(n, a, b)\n s = 0\n arr = a[0..0] + a[0..-2].each_with_index.map{|x, i| s += x - b[i]}\n m = (arr + [0]).min\n res = (0...n).select {|i| arr[i] == m }\n res << 0 if m == 0\n res\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nr = (solve(n, a, b) + solve(n, a.reverse, b.reverse[1..-1] + [b[-1]]).map{|x| n - x - 1}).sort.uniq.map{|x| x + 1}\nputs \"#{r.size}\\n#{r.join(' ')}\"\n"}, {"source_code": "def solve(n, a, b)\n s = 0\n arr = a[0..0] + a[0..-2].each_with_index.map{|x, i| s += x - b[i]}\n m = (arr + [0]).min\n res = (0...n).select {|i| arr[i] == m }\n res << 0 if m == 0\n res\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nr = (solve(n, a, b) + solve(n, a.reverse, b.reverse[1..-1] + [b[-1]]).map{|x| n - x - 1}).sort.uniq.map{|x| x + 1}\nputs \"#{r.size}\\n#{r.join(' ')}\"\n"}, {"source_code": "def solve(n, a, b)\n s = 0\n arr = a[0..0] + a[0..-2].each_with_index.map{|x, i| s += x - b[i]}\n m = (arr + [0]).min\n res = (0...n).select {|i| arr[i] == m }\n res << 0 if m == 0\n res\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nr = (solve(n, a, b) + solve(n, a.reverse, b.reverse[1..-1] + [b[-1]]).map{|x| n - x - 1}).sort.uniq.map{|x| x + 1}\nputs \"#{r.size}\\n#{r.join(' ')}\"\n"}, {"source_code": "def solve(n, a, b)\n s = 0\n arr = a[0..0] + a[0..-2].each_with_index.map{|x, i| s += x - b[i]}\n m = (arr + [0]).min\n res = (0...n).select {|i| arr[i] == m }\n res << 0 if m == 0\n res\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nr = (solve(n, a, b) + solve(n, a.reverse, b.reverse[1..-1] + [b[-1]]).map{|x| n - x - 1}).sort.uniq.map{|x| x + 1}\nputs \"#{r.size}\\n#{r.join(' ')}\"\n"}, {"source_code": "#!/usr/bin/ruby\n\ndef solve(n, a, b)\n fuel = a[0]\n arr = [fuel]\n (n-1).times { |i|\n fuel -= b[i]\n arr << fuel\n fuel += a[i+1]\n }\n min = arr.min\n ret = []\n if min >= 0\n ret << 1\n min = 0\n end\n arr.each_with_index { |v, i|\n ret << i+1 if v == min\n }\n ret\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nb_rev = b.reverse\nb_rev = b_rev[1..-1] + [b_rev[0]]\na1 = solve(n, a, b)\na2 = solve(n, a.reverse, b_rev).map{|v| n+1-v}\nans = (a1+a2).sort.uniq\nputs \"#{ans.size}\\n#{ans.join(' ')}\"\n"}, {"source_code": "#!/usr/bin/ruby\n\ndef solve(n, a, b)\n fuel = a[0]\n arr = [fuel]\n (n-1).times { |i|\n fuel -= b[i]\n arr << fuel\n fuel += a[i+1]\n }\n min = arr.min\n ret = []\n if min < 0\n a.each_with_index { |v,i|\n ret << i+1 if arr[i] == min\n }\n else\n ret << 1\n a.each_with_index { |v,i|\n ret << i+1 if arr[i] == 0\n }\n end\n ret\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nb_rev = b.reverse\nb_rev = b_rev[1..-1] + [b_rev[0]]\na1 = solve(n, a, b)\na2 = solve(n, a.reverse, b_rev).map{|v| n+1-v}\nans = (a1+a2).sort.uniq\nputs \"#{ans.size}\\n#{ans.join(' ')}\"\n"}, {"source_code": "def solve(n, a, b)\n s = 0\n arr = a[0..0] + a[0..-2].each_with_index.map{|x, i| s += x - b[i]}\n m = (arr + [0]).min\n res = (0...n).select {|i| arr[i] == m }\n res << 0 if m == 0\n res\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nr = (solve(n, a, b) + solve(n, a.reverse, b.reverse[1..-1] + [b[-1]]).map{|x| n - x - 1}).sort.uniq.map{|x| x + 1}\nputs \"#{r.size}\\n#{r.join(' ')}\"\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\n\ndef solve(n, a, b)\n fuel = a[0]\n arr = [fuel]\n (n-1).times { |i|\n fuel -= b[i]\n arr << fuel\n fuel += a[i+1]\n }\n min = arr.min\n ret = []\n if min < 0\n ret << 1\n min = 0\n end\n a.each_with_index { |v,i|\n ret << i+1 if arr[i] == 0\n }\n ret\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nb_rev = b.reverse\nb_rev = b_rev[1..-1] + [b_rev[0]]\na1 = solve(n, a, b)\na2 = solve(n, a.reverse, b_rev).map{|v| n+1-v}\nans = (a1+a2).sort.uniq\nputs \"#{ans.size}\\n#{ans.join(' ')}\"\n"}], "src_uid": "cc928c02b337f2b5ad7aed37bb83d139"} {"source_code": "n,m = gets.split.map(&:to_i)\nd = (m+1)/2\ni = d\nfor k in 1..n\n p i\n if i==d and m.odd? then i=d-1\n elsif i==d and !m.odd? then i=d+1\n elsif i>d then i=m-i\n elsif im then i=d end\nend\n", "positive_code": [{"source_code": "n,m = gets.split.map{|e| e.to_i}\nfor i in (1..n) do\n k = i.modulo(m)\n if k==0 then k=m end\n r = k/2\n na = k.modulo(2)\n sr = (m+1)/2\n if na==0 then na=-1 end \n if m.modulo(2)==0 then na*=-1 end\n ans=sr+na*r\n puts ans \nend\n"}, {"source_code": "(n,m) = gets.split.map(&:to_i)\nif(m % 2 ==0)\nth = (m/2).ceil\nw = 0\n n.times do |i|\n th += w\n if(w > 0)\n w +=1\n else\n w -=1\n end\n w *=-1\n puts th\n if(th == m)\n th = (m/2).ceil\n w = 0\n end\n end\nelse\n th = (m/2).ceil+1\n w = 0\n n.times do |i|\n th -= w\n if(w > 0)\n w +=1\n else\n w -=1\n end\n w *=-1\n puts th\n if(th == m)\n th = (m/2).ceil+1\n w = 0\n end\n end\nend"}, {"source_code": "#!/usr/bin/ruby\nn, m = gets.chomp.split(' ').map{|a| a.to_i}\nif m == 1\n\tn.times do\n\t\tputs 1\n\tend\n\texit\nend \nif m == 2\n\tn.times do |i|\n\t\tputs (i+1)%2 == 1 ? 1:2\n\tend\n\texit\nend\nif m%2 == 1\n\tk = (m/2.0).ceil\n\tfor i in 1..n\n\t\tif i > m\n\t\t\ti = i % m;\n\t\t\tif i == 0\n\t\t\t\ti = m\n\t\t\tend\n\t\tend\n\t\tif i%2 == 0\n\t\t\tputs k-((i+2)/2)+1;\n\t\tend\n\t\tif i%2 == 1\n\t\t\tputs k+((i+1)/2)-1;\n\t\tend\n\tend\nelse\n\tk = m/2\n\tfor i in 1..n\n\t\tif i > m\n\t\t\ti = i % m;\n\t\t\tif i == 0\n\t\t\t\ti = m\n\t\t\tend\n\t\tend\n\t\tif i%2 == 1\n\t\t\tputs k-(i+1)/2+1;\n\t\tend\n\t\tif i%2 == 0\n\t\t\tputs k+(i/2);\n\t\tend\n\tend\nend\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\ni=0\nwhile i= 1\n\tarr << val1 if val1 <= m\n\ti += 1\nend\narr = arr.to_a\nn.times do |i|\n\tputs arr[i % m]\nend"}, {"source_code": "a = []\ngets.split.each { |_| a.push(_.to_i)}\n# a[0] - \u043c\u044f\u0447\u0438\n# a[1] -\u043a\u043e\u0440\u0437\u0438\u043d\u044b\n\nif a[1].odd?\n #\u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0435\n plu = (a[1]/2.0).ceil\n for i in 1..a[0] do\n k = i % a[1]\n k = a[1] if k == 0 # \u043a\u043e\u0441\u0442\u044b\u043b\u044c \u0435\u0441\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u044f\u0447\u0435\u0439 \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u0440\u0437\u0438\u043d \u043d\u0430\u0447\u0430\u0442\u044c \u0441\u0447\u0435\u0442 \u0441\u043d\u043e\u0432\u0430 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0438 \u0440\u0443\u0431\u0435\u0436\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043a\u043e\u0440\u0437\u0438\u043d \n if k.odd?\n p plu + (k-1)/2 if k != 1 # ---\n p plu if k == 1 # \u041a\u043e\u0441\u0442\u044b\u043b\u044c \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u044f\u0447\u0435\n else\n p plu - k/2\n end\n end\nelse\n #\u0447\u0435\u0442\u043d\u043e\u0435\n plu = (a[1]/2.0).ceil\n for i in 1..a[0] do\n k = i % a[1]\n k = a[1] if k == 0 # \u043a\u043e\u0441\u0442\u044b\u043b\u044c \u0435\u0441\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u044f\u0447\u0435\u0439 \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u0440\u0437\u0438\u043d \u043d\u0430\u0447\u0430\u0442\u044c \u0441\u0447\u0435\u0442 \u0441\u043d\u043e\u0432\u0430 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0438 \u0440\u0443\u0431\u0435\u0436\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043a\u043e\u0440\u0437\u0438\u043d \n if k.odd?\n p plu - (k-1)/2 if k != 1 # ---\n p plu if k == 1 # \u041a\u043e\u0441\u0442\u044b\u043b\u044c \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u044f\u0447\u0435\n else\n p plu + k/2\n end\n end\n \nend"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nn, m = gets.chomp.split(' ').map{|a| a.to_i}\nif m == 1\n\tn.times do\n\t\tputs 1\n\tend\n\texit\nend \nif m == 2\n\tn.times do |i|\n\t\tputs (i+1)%2 == 1 ? 1:2\n\tend\n\texit\nend\nif m%2 == 1\n\tk = (m/2.0).ceil\n\tfor i in 1..n\n\t\tif i > m\n\t\t\ti = i % m;\n\t\t\tif i == 0\n\t\t\t\ti = m\n\t\t\tend\n\t\tend\n\t\tif i%2 == 0\n\t\t\tputs k-((i+2)/2)+1;\n\t\tend\n\t\tif i%2 == 1\n\t\t\tputs k+((i+1)/2)-1;\n\t\tend\n\tend\nelse\n\tk = m/2.0\n\tfor i in 1..n\n\t\tif i > m\n\t\t\ti = i % m;\n\t\t\tif i == 0\n\t\t\t\ti = m\n\t\t\tend\n\t\tend\n\t\tif i%2 == 1\n\t\t\tputs k-i+1;\n\t\tend\n\t\tif i%2 == 2\n\t\t\tputs k+((i+1)/2)-1;\n\t\tend\n\tend\nend\n"}, {"source_code": "arr = []\nn,m = gets.split(\" \").map(&:to_i)\n\nval = (m+1) / 2\narr << val\ni = 1\nwhile arr.length < m\n\tval1 = val + i\n\tval2 = val - i\n\tarr << val2 if val2 >= 1\n\tarr << val1 if val1 <= m\n\ti += 1\nend\n\nn.times do |i|\n\tputs arr[i % m]\nend"}, {"source_code": "require 'Set'\narr = Set.new\nn,m = gets.split(\" \").map(&:to_i)\n\nval = (m+1) / 2\narr << val\narr << val + 1 if m.even?\ni = 1\nwhile arr.length < m\n\tval1 = val + i\n\tval2 = val - i\n\tarr << val2 if val2 >= 1\n\tarr << val1 if val1 <= m\n\ti += 1\nend\narr = arr.to_a\nn.times do |i|\n\tputs arr[i % m]\nend"}, {"source_code": "a = []\ngets.split.each { |_| a.push(_.to_i) }\n\nb = [0] * a[1] # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0440\u0437\u0438\u043d \u0438 \u0432\u0441\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b\n\ndef get_indexes(a_,v_) # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430 a_ \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e v_\n ha = []\n a_.each_with_index do |v,i|\n ha.push(i) if v == v_\n end\n ha\nend\n\na[0].times do #\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043c\u044f\u0447\u0435\u0439\n ins = get_indexes(b, b.min) # \u043f\u0440\u043e\u0441\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u044b\n if ins.count > 1 # \u0435\u0441\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0443\u044e \u043a \u0446\u0435\u043d\u0442\u0440\u0443\n h = ins.inject(Hash.new(0)) { |h,v| h[v] = ((a[1]+1)/2-(v+1)).abs; h } # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u0440\u0437\u0438\u043d\u044b\n p h.key(h.values.min) + 1 # \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u043b\u0438 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0443\u044e \u043a\u043e\u0440\u0437\u0438\u043d\u0443\n b[h.key(h.values.min)] += 1 # \u043a\u043b\u0434\u0435\u043c \u043c\u044f\u0447\n else\n p b.index(b.min) + 1 \n b[b.index(b.min)] += 1\n end\nend\n\n"}, {"source_code": "a = []\ngets.split.each { |_| a.push(_.to_i) }\n\nb = [0] * a[1] # \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0440\u0437\u0438\u043d \u0438 \u0432\u0441\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b\n\ndef get_indexes(a_,v_) # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430 a_ \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e v_\n ha = []\n a_.each_with_index do |v,i|\n ha.push(i) if v == v_\n end\n ha\nend\n\na[0].times do #\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043c\u044f\u0447\u0435\u0439\n ins = get_indexes(b, b.min) # \u043f\u0440\u043e\u0441\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u044b\n if ins.count > 1 # \u0435\u0441\u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0443\u044e \u043a \u0446\u0435\u043d\u0442\u0440\u0443\n h = ins.inject(Hash.new(0)) { |h,v| h[v] = (a[1]+1/2-(v+1)).abs; h } # \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u0440\u0437\u0438\u043d\u044b\n p h.key(h.values.min) + 1 # \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u043b\u0438 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0443\u044e \u043a\u043e\u0440\u0437\u0438\u043d\u0443\n b[h.key(h.values.min)] += 1 # \u043a\u043b\u0434\u0435\u043c \u043c\u044f\u0447\n else\n p b.index(b.min) + 1 \n b[b.index(b.min)] += 1\n end\nend\n\n"}], "src_uid": "907893a0a78a7444d26bdd793d9c7499"} {"source_code": "(1..gets.to_i).each {\n s = gets.chomp.chars\n a = [1, 2, 3, 4, 6, 12].select { |v| u = 12/v; t = s.each_slice(u); (0...u).any? { |i| t.all? { |r| r[i] == 'X' } } }\n out = a.size.to_s\n out += ' ' + a.map { |v| \"#{v}x#{12/v}\" } * ' ' unless a.empty?\n puts out\n}", "positive_code": [{"source_code": "#!/usr/bin/ruby\ngets.to_i.times{\n\ts=gets.chomp.split('')\n\tn=s.size\n\th={}\n\tn.times{|i|h[i]=1 if s[i]=='X'}\n\tr=(1..n).select{|i|n%i==0 && (n/i).times.any?{|j|\n\t\ti.times.all?{|k|h[k*(n/i)+j]}\n\t}}.map{|e|'%dx%d'%[e,n/e]}\n\tputs r.size.to_s+' '+r*' '\n}"}, {"source_code": "t = gets.to_i\n\ndef check(row,s)\n arr = s.split('').each_slice(row).to_a.transpose\n\n arr.each_with_index do |r,ri|\n bool = true\n r.each_with_index do |rri,rj|\n if r[rj]=='O'\n bool = false \n end\n end\n\n if bool\n return true \n \n end \n end\n return false\nend\n\nt.times do |i|\n s = gets.chomp\n fact = [12,6,4,3,2,1]\n ans = []\n fact.each_with_index do |f,i|\n if check(f,s)\n a = (s.length/f).to_s+'x'+f.to_s\n ans << a\n end\n end\n puts ans.length.to_s+' '+ans.join(' ') \nend"}, {"source_code": "def run\n n = $stdin.gets.to_i\n $stdin.readlines.each do |line|\n chars = line.chomp.split(//)\n len = chars.length\n ans = []\n 1.upto(len) do |i|\n f = [true] * (len / i)\n next if len % i != 0\n len.times do |j|\n f[j % (len / i)] = false if chars[j] == 'O'\n end\n ans << \"#{i}x#{chars.length / i}\" if f.find_index(true)\n end\n puts \"#{ans.length} #{ans.join(\" \")}\"\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "gets\nwhile s = gets\n r = []\n for a in 1..12\n if 12 % a == 0\n b = 12 / a\n ok = [ true ] * b\n s.chars.each_with_index do |c, i|\n ok[i % b] = false if c == 'O'\n end\n if ok.find_index(true)\n r << \"#{a}x#{b}\"\n end\n end\n end\n puts \"#{r.size} #{r.join(' ')}\"\nend"}, {"source_code": "tests = gets.to_i\ntests.times do\n s = gets\n result = []\n for a in 1..12\n if 12 % a == 0\n b = 12 / a\n ok = [ true ] * b\n s.split(//).each_with_index do |c, i|\n ok[i % b] = false if c == 'O'\n end\n if ok.find_index(true)\n result << \"#{a}x#{b}\"\n end\n end\n end\n puts \"#{result.size} #{result.join(' ')}\"\nend"}, {"source_code": "class ProblemA\n \n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @num_of_dat = @dats[0]\n @final_str = \"\"\n end\n\n def solve(line)\n out_line = \"\"\n num_of_ways = 0\n return if line.length != 12 \n [1,2,3,4,6,12].each do |a|\n b = 12/a\n has_way = false\n str = \"\"\n (0..(b-1)).each do |col_idx|\n is_x = true \n (0..(a-1)).each do |row_idx|\n if line[col_idx+(row_idx)*b] != \"X\"\n is_x = false \n end\n end\n\n if is_x\n has_way = true\n num_of_ways += 1\n break\n end\n end\n out_line += \" #{a}x#{b}\" if has_way\n end\n @final_str += \"#{num_of_ways} #{out_line}\\n\"\n end\n \n def solve_all \n (1..@num_of_dat.to_i).each do |i|\n solve(@dats[i])\n end\n puts @final_str\n end\nend\n\nsolver = ProblemA.new\nsolver.solve_all\n"}, {"source_code": "n=gets.to_i\nn.times{\n\ta=gets.chomp\n\tans = []\n\t(1..12).each{ |i|\n\t\tif( 12 % i == 0 )\n\t\t\tb = []\n\t\t\tj = 0\n\t\t\twhile j < 12\n\t\t\t\tb<=4 && d<6\nansa=[]\nansa<=6 && d<12\nansa=[]\nansa<=4 && d<6\nansa=[]\nansa<=6 && d<12\nansa=[]\nansa<=4 && d<6\nansa=[]\nansa<=6 && d<12\nansa=[]\nansa<=4 && d<6\nansa=[]\nansa<=6 && d<12\nansa=[]\nansa< 0\n n = gets.chomp.to_i\n a = gets.split.collect{|i| i.to_i}\n i = n - 1\n while i >= 1 && a[i - 1] >= a[i]\n i -= 1\n end\n while i >= 1 && a[i - 1] <= a[i]\n i -= 1\n end\n puts i\n tc -= 1\nend\n\n", "positive_code": [{"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i).chunk_while { _1 == _2 }.to_a\n\tpos =\n\t\t(1...a.size - 1).reverse_each.find do |i|\n\t\t\ta[i - 1][0] > a[i][0] && a[i][0] < a[i + 1][0]\n\t\tend || 0\n\tputs (0...pos).sum { a[_1].size }\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n ln = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n i = ln - 1\n while i >= 1 && a[i-1] >= a[i]\n i -= 1\n end\n while i >= 1 && a[i-1] <= a[i]\n i -= 1\n end\n puts i\nend"}, {"source_code": "tc = gets.to_i \n\ntc.times do \n n = gets.to_i \n arr = gets.split().map{|i| i.to_i} \n ans = 0 \n crr = Array.new(n) {0} \n maxi = arr[n-1] \n ((n-2).step(0,-1)).each do |i| \n maxi = [maxi,arr[i+1]].max\n crr[i] = maxi \n end\n (1...n-1).each do |i| \n if(arr[i] < arr[i-1] && arr[i] < crr[i]) \n ans = i \n end\n end\n puts(ans)\nend"}, {"source_code": "gets.to_i.times do \n n = gets.to_i\n a = gets.split.map(&:to_i)\n res = n - 1\n res -= 1 while res > 0 && a[res - 1] >= a[res]\n res -= 1 while res > 0 && a[res - 1] <= a[res]\n puts res\nend"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n rm = n - 1\n state = :inc\n (n - 2).downto(0) do |i|\n if a[i] < a[i + 1] then state = :dec end\n break if state == :dec and a[i] > a[i + 1]\n rm = i\n end\n puts rm\nend\n\n"}], "negative_code": [{"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tputs (1...n - 1).reverse_each.find { |i|\n\t\t\ta[i - 1] > a[i] && a[i] < a[i + 1]\n\t } || 0\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n ln = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n i = ln - 1\n while i >= 0 && a[i-1] >= a[i]\n i -= 1\n end\n while i >= 0 && a[i-1] < a[i]\n i -= 1\n end\n puts i\nend"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n ln = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n i = ln - 1\n while i >= 0 && a[i-1] >= a[i]\n i -= 1\n end\n while i >= 0 && a[i-1] <= a[i]\n i -= 1\n end\n puts i\nend"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n ln = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n i = ln - 1\n while i >= 0 && a[i-1] > a[i]\n i -= 1\n end\n while i >= 0 && a[i-1] < a[i]\n i -= 1\n end\n puts i\nend"}, {"source_code": "tc = gets.to_i \n\ntc.times do \n n = gets.to_i \n arr = gets.split().map{|i| i.to_i} \n\n brr = Array.new(n) {0}\n crr = Array.new(n) {0} \n\n maxi = arr[0] \n (1...n).each do |i| \n maxi = [maxi,arr[i-1]].max\n brr[i] = maxi \n end\n # print(brr)\n maxi = arr[n-1]\n ((n-2).step(0,-1)).each do |i| \n maxi = [maxi,arr[i+1]].max\n crr[i] = maxi \n end\n # print(crr)\n ans = 0\n (1...n-1).each do |i| \n if(arr[i] < brr[i] && arr[i] < crr[i]) \n ans = i \n end\n end\n puts(ans)\nend"}, {"source_code": "tc = gets.to_i \n\ntc.times do \n n = gets.to_i \n arr = gets.split().map{|i| i.to_i} \n # print(arr)\n brr = Array.new(n) {0}\n crr = Array.new(n) {0} \n\n maxi = arr[0] \n (1...n).each do |i| \n maxi = [maxi,arr[i-1]].max\n brr[i] = maxi \n end\n # print(brr)\n maxi = arr[n-1]\n ((n-2).step(0,-1)).each do |i| \n maxi = [maxi,arr[i+1]].max\n crr[i] = maxi \n end\n # print(crr)\n ans = 0\n (1...n-1).each do |i| \n if(arr[i] < brr[i] && arr[i] < crr[i]) \n if(arr[i] != arr[i-1])\n ans = i \n end\n end\n end\n puts(ans)\nend"}, {"source_code": "tc = gets.to_i \n\ntc.times do \n n = gets.to_i \n arr = gets.split().map{|i| i.to_i} \n ans = 0 \n (1...n-1).each do |i| \n if(arr[i] < arr[i-1] && arr[i] < arr[i+1]) \n ans = i \n end\n end\n puts(ans)\nend"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n rm = n - 2\n state = :inc\n (n - 2).downto(0) do |i|\n if a[i] < a[i + 1] then state = :dec end\n break if state == :dec and a[i] > a[i + 1]\n rm = i\n end\n puts rm\nend\n\n"}], "src_uid": "731b45747081a800fc6da02efa5ce8cd"} {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n a.sort!\n b = Array.new(n, nil)\n pos = (n - 1) / 2\n n.times do |i|\n b[i] = a[pos]\n if i % 2 == 0\n pos += i + 1\n else\n pos -= i + 1\n end\n end\n puts b.join(\" \")\nend\n", "positive_code": [{"source_code": "# coding: utf-8\n\n# |a1 - a2| <= |a2 - a3| <= |a3 - a4| ....\n# \ub97c \ub9cc\uc871\uc2dc\ud0a4\ub3c4\ub85d a\ub97c \uc815\ub82c\n# \uaf64 \uc7ac\ubc0c\ub294 \uc720\ud615\uc758 \ubb38\uc81c\uc774\ub2e4. \uc774\ub807\uac8c \uc22b\uc790 \ubc30\uc5f4\uc744 \ud0c0\uace0 \uc21c\ud68c\ud558\ub294\uac78 oscillation\uc774\ub77c \ud55c\ub2e4\ub294\uad70.\n# naive\ud558\uac8c \uad6c\uc131\ud55c \uc54c\uace0\ub9ac\uc998\uc740 \ub2e4\uc74c\uacfc \uac19\uc74c\n# 1. \uc0bd\uc785 \uc815\ub82c \uad6c\uc870\ub97c \uac00\uc9d0\n# 2. \ube48 \ubc30\uc5f4\uc5d0 a1 \uc0bd\uc785\n# 3. \ube48 \ubc30\uc5f4\uc5d0 a2 \uc0bd\uc785\n# (\uc5ec\uae30\uae4c\uc9c4 |a1 - a2| = |a2 - a1|\uc774\ubbc0\ub85c \ud070 \uc9c0\uc7a5\uc740 \uc5c6\uc74c)\n# 4. \ube48 \ubc30\uc5f4\uc5d0 a3 \uc744 \ub123\uae30 \uc704\ud55c \uc790\ub9ac\ub97c \uc120\ud0dd\ud568( \uc804\uccb4 \uc21c\ud68c\uac00 \ud544\uc694\ud568 O(n))\n# 5. \uc774\ud6c4 a3\ubd80\ud130 aN\uae4c\uc9c0 \ubaa8\ub4e0 \uc808\ucc28\ub97c \ubc18\ubcf5\ud574\uc57c\ud558\ubbc0\ub85c O(n^2)\n# \uc774\ub807\uac8c \uc7a1\uc558\uc9c0\ub9cc \ubd80\ubd84\uc801\uc73c\ub85c\ub294 \ud574\ub2f5\uc77c \uc218 \uc788\uc73c\ub098 \uc544\ubb34\ub798\ub3c4 \uc624\ub2f5\uc774 \uc790\uafb8 \ub098\uc624\ub124.\n# \uacb0\uad6d\uc740 \uba87\ubc88 \uace0\ubbfc\ud574\ubcf4\ub2e4\uac00 \ucc3e\uc740 \ud574\uac00 \uc774 \uc811\uadfc\ubc95\uc774\ub2e4.\n\n# \uc77c\ub2e8 \uc22b\uc790\ub97c \ubaa8\ub450 \uc815\ub82c\ud55c\ub2e4. 1 2 9 5 8 8\uc744 \uac10\uc18c\uac00 \uc5c6\ub294 \uc21c\uc11c\ub300\ub85c \uc815\ub82c\ud558\uba74,\n# 1 2 5 8 8 9 \uc774\ub2e4. \uc774 \uc22b\uc790\ub294 \uc7ac\ubc0c\ub294 \uc131\uc9c8\uc744 \uac16\uace0 \uc788\ub294\ub370, \ud55c \uc22b\uc790\ub97c \uae30\uc900\uc73c\ub85c\n# \uc624\ub978\ucabd\uc740 0\ud639\uc740 1\uc774\uc0c1\ub9cc\ud07c \ud06c\uba70 \uc67c\ucabd\uc740 0\ud639\uc740 1\uc774\uc0c1\ub9cc\ud07c \uc791\ub2e4.\n# \uadf8\ub798\uc11c \uc790\uc2e0\uc5d0\uac8c k \uac70\ub9ac\ub9cc\ud07c \uba3c\ucabd\uc77c \uc218\ub85d \uc790\uc2e0\uacfc\uc758 \ucc28\uc774\uac00 \ub9e4\uc6b0 \ucee4\uc9c8\uac70\ub780 \uae30\ub300\ub97c \ud560 \uc218 \uc788\ub2e4.\n# \uc790\uc2e0\uc5d0\uac8c 0\uc5d0 \uac00\uae4c\uc6b4 \uac70\ub9ac\uc77c\uc218\ub85d \uc790\uc2e0\uacfc\uc758 \ucc28\uc774\ub294 \ub9e4\uc6b0 \uc791\uc544\uc9c4\ub2e4.\n# \uadf8\ub798\uc11c \uc911\uc559\uc5d0\uc11c\ubd80\ud130 \uc67c\ucabd \uc808\ubc18\uc758 \uc81c\uc77c \ud6c4\ubbf8\ubd80\ud130, \uc624\ub978\ucabd \uc808\ubc18\uc758 \uc81c\uc77c \uc120\ub450\ubd80\ud130 \uc22b\uc790\ub97c\n# \ucd94\ucd9c\ud558\uba74 \uac70\ub9ac\uac00 \uac00\uae4c\uc6b4 \uc21c\uc11c\ubd80\ud130 \uba3c \uc21c\uc11c\ub300\ub85c \ubf51\uc744 \uc218 \uc788\ub2e4.\n\n# \ucc98\uc74c\uc5d0 \ud3c9\uade0\uc744 \uc774\uc6a9\ud55c \uc811\uadfc\uc744 \ud55c\uac74 \ud3c9\uade0\uc774 \uc911\uc559\uc5d0 \uc62c \uacbd\uc6b0\uc5d0\ub294 \uc131\uacf5\ud560 \uc218 \uc788\ub294 \ubc29\ubc95\uc774\uc9c0\ub9cc,\n# \ud3c9\uade0\uac12\uc774 \uc911\uc559\uc5d0 \uc788\uc9c0 \ubabb\ud55c \uacbd\uc6b0\uc5d0\ub294 \uc798\ubabb\ub41c \ub3d9\uc791\uc744 \ud560 \uc218 \uc788\ub2e4.\n# \uacb0\uad6d \ud3c9\uade0\uc774 \uc544\ub2c8\ub77c '\uc911\uac04\uac12'\uc744 \ucc3e\uc544\uc57c\ud558\ub294 \ubb38\uc81c. \uc815\ub82c\uc740 \uc774\ub7ec\ud55c \ubc29\ubc95\uc73c\ub85c \uc21c\ud68c\ud558\uae30 \uc704\ud574\n# \uc548\uc815\uc801\uc778 \uc804\uc81c\ub97c \uc81c\uacf5\ud558\ub294 \uac83\uc774\ub2e4.\nt = gets.to_i\nt.times {\n n = gets.to_i\n a = gets.split.map(&:to_i)\n a.sort!\n mid = n/2\n la, ra = a[0...mid], a[mid...n]\n b = []\n while !la.empty? || !ra.empty?\n b << ra.shift unless ra.empty?\n b << la.pop unless la.empty?\n end\n\n #p la\n #p ra\n \n puts b.join(' ')\n}"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# |a1 - a2| <= |a2 - a3| <= |a3 - a4| ....\n# \ub97c \ub9cc\uc871\uc2dc\ud0a4\ub3c4\ub85d a\ub97c \uc815\ub82c\n\nt = gets.to_i\nt.times {\n n = gets.to_i\n a = gets.split.map(&:to_i)\n a.sort!\n mid = n/2\n la, ra = a[0...mid], a[mid...n]\n b = []\n while !la.empty? && !ra.empty?\n b << ra.shift unless ra.empty?\n b << la.pop unless la.empty?\n end\n\n \n puts b.join(' ')\n}"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n a.sort!\n b = Array.new(n, nil)\n pos = (n - 1) / 2\n n.times do |i|\n puts pos\n b[i] = a[pos]\n if i % 2 == 0\n pos += i + 1\n else\n pos -= i + 1\n end\n end\n puts b.join(\" \")\nend\n"}], "src_uid": "3c8bfd3199a9435cfbdee1daaacbd1b3"} {"source_code": "k = gets.to_i\r\n\r\nwhile (k > 0)\r\n n, x, t = gets.split(' ').map(&:to_i)\r\n \r\n forFirst = [t / x, n - 1].min;\r\n\r\n puts(forFirst * [n - forFirst, 0].max + forFirst * (forFirst - 1) / 2)\r\n \r\n k -= 1\r\nend\r\n ", "positive_code": [{"source_code": "gets.to_i.times do\r\n n,x,t=gets.split.map(&:to_i)\r\n if t>=x*(n-1)\r\n puts (n-1)*n/2\r\n else\r\n cc=t/x\r\n puts cc*(cc+1)/2+(n-cc-1)*cc\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "4df38c9b42b0f0963a121829080d3571"} {"source_code": "r,c = gets.split.map(&:to_i)\na = []\n\ncheck = true\nr.times do\n a << gets.chomp\nend\nr.times do |i|\n c.times do |j|\n if a[i][j] == \"S\"\n check = false if i > 0 && a[i-1][j] == \"W\"\n check = false if i < r-1 && a[i+1][j] == \"W\"\n check = false if j > 0 && a[i][j-1] == \"W\"\n check = false if j < c-1 && a[i][j+1] == \"W\"\n end\n a[i][j] = \"D\" if a[i][j] == \".\"\n end\nend\nif check\n puts \"Yes\"\n r.times do |i|\n puts a[i]\n end\nelse\n puts \"No\"\nend\n", "positive_code": [{"source_code": "r, c = gets.split.map &:to_i\n\npasture = Array.new(){Array.new(c)}\n\nr.times do \n pasture << gets.strip.split(\"\")\nend\n\ndef place_dogs(pasture, i, j)\n r = pasture.length\n c = pasture[0].length\n pasture[i - 1][j] = \"D\" if i - 1 >= 0 && pasture[i - 1][j] == \".\"\n pasture[i + 1][j] = \"D\" if i + 1 < r && pasture[i + 1][j] == \".\"\n pasture[i][j - 1] = \"D\" if j - 1 >= 0 && pasture[i][j - 1] == \".\"\n pasture[i][j + 1] = \"D\" if j + 1 < c && pasture[i][j + 1] == \".\"\nend\n\ndef dead_sheep?(pasture)\n r = pasture.length\n c = pasture[0].length\n dead_sheep = false\n pasture.each_index do |i|\n pasture[i].each_index do |j|\n if pasture[i][j] == \"W\"\n up = pasture[i - 1][j] if i - 1 >= 0 \n down = pasture[i + 1][j] if i + 1 < r \n right = pasture[i][j + 1] if j + 1 < c\n left = pasture[i][j - 1] if j - 1 >= 0\n if up == \"S\" || down == \"S\" || right == \"S\" || left == \"S\"\n dead_sheep = true\n break\n end\n end\n end\n end\n dead_sheep\nend\n\nif dead_sheep?(pasture)\n puts \"No\"\nelse\n pasture.each_index do |i|\n pasture[i].each_index do |j|\n if pasture[i][j] == \"W\"\n place_dogs(pasture, i, j)\n end\n end\n end\n pasture = pasture.map &:join\n puts \"Yes\", pasture.join(\"\\n\")\nend\n\n\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nar = Array.new(0)\nres = false\nn.times { ar << gets.chomp}\nn.times do |i|\n ar[i] = ar[i].gsub('.', 'D')\n if ar[i].include?('WS') || ar[i].include?('SW')\n res = true\n break\n end\nend\nn.times do |i|\n m.times do |j|\n break if i == n-1\n curr = ar[i][j]\n bottom = ar[i+1][j] if ar[i+1]\n if [curr, bottom].sort == ['S','W']\n res = true\n break\n end\n end\nend\nputs res ? \"NO\" : \"YES\"\nputs ar if !res"}, {"source_code": "a, b= gets.chomp.split(\" \").map { |e| e.to_i }\n\narr = Array.new(a) { Array.new(b) }\n\n(0...a).to_a.each do |i|\n\tinp = gets.chomp.split(\"\")\n\t(0...b).to_a.each do |j|\n\t\tarr[i][j] = inp[j]\n\t\tif arr[i][j] == '.'\n\t\t\tarr[i][j] = 'D'\n\t\tend\n\tend\nend\n\n(0...a).to_a.each do |i|\n\t(0...b).to_a.each do |j|\n\t\tif arr[i][j] == 'W' && (((j-1) >= 0 && arr[i][j-1] == 'S') || ((j+1)=0 && arr[i-1][j] == 'S') || (i+1) < a && arr[i+1][j] == 'S')\n\t\t\tputs \"No\"\n\t\t\texit\n\t\tend\n\tend\nend\nputs 'Yes'\narr.each do |el|\n\tputs el.join(\"\")\nend\n"}], "negative_code": [], "src_uid": "f55c824d8db327e531499ced6c843102"} {"source_code": "t = gets.to_i\r\nt.times do\r\n n = gets.to_i.to_s(2)\r\n l = 1 << (n.size - 1)\r\n puts l - 1\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times {\n n = gets.to_i\n\n p = 1\n p *= 2 while p < n\n p /= 2 if p > n\n\n puts(p - 1)\n}\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n res = 0\r\n while n > 0\r\n n /= 2\r\n res += 1\r\n end\r\n puts (1 << (res - 1)) - 1\r\nend"}, {"source_code": "t = gets.chomp.to_i\n\ndef solve(n) \n cnt = 0\n while n > 0 do\n cnt += 1\n n /= 2\n end\n\n (1 << (cnt - 1)) - 1\nend\n\nt.times do \n n = gets.chomp.to_i\n puts solve(n)\nend\n"}, {"source_code": "gets.to_i.times{|c|\r\n\tn = gets.to_i\r\n\tputs ('1'*(n.to_s(2).size-1)).to_i(2)\r\n}"}], "negative_code": [{"source_code": "gets.to_i.times{|c|\r\n\tn = gets.to_i\r\n\tputs n-n.digits(2).count(1)\r\n}"}], "src_uid": "9b4a8bc76d634935f6a1438e8a93a781"} {"source_code": "r,c=gets.split.map(&:to_i)\nx,y=0,0\nr.times{|i|gets;c.times{|j|x^=i and y^=j if $_[j]=='*'}}\nputs \"#{x+1} #{y+1}\"\n\n", "positive_code": [{"source_code": "#!/usr/bin/ruby1.9\n\n(n, m) = STDIN.readline.split.map {|s| s.to_i}\n\nrs = []\ncs = []\n(1..n).each do |r|\n\trow = STDIN.readline.strip\n\t(1..row.length).each do |c|\n\t\tif row[c-1].chr == '*'\n\t\t\trs.push(r)\n\t\t\tcs.push(c)\n\t\tend\n\tend\nend\n\ndef get_odd_one_out(xs)\n\txs = xs.sort\n\tif xs[0] == xs[1]\n\t\treturn xs[2]\n\tend\n\treturn xs[0]\nend\n\nr = get_odd_one_out(rs)\nc = get_odd_one_out(cs)\nputs '%d %d' % [r, c]\n\n"}, {"source_code": "r,c=gets.split.map(&:to_i)\nx,y=0,0\nr.times{|i|gets;c.times{|j|x^=i and y^=j if $_[j]=='*'}}\nputs \"#{x+1} #{y+1}\"\n"}, {"source_code": "r,c=gets.split.map(&:to_i)\nx,y=0,0\nr.times{|i|gets;c.times{|j|x^=i and y^=j if $_[j]=='*'}}\nputs \"#{x+1} #{y+1}\"\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\n\nlist = []\nn.times do |j|\n gets.chomp.split(\"\").each_with_index do |c, i|\n if c == '*'\n list << [j, i]\n end\n end\nend\n\ncount_y = Hash.new(0)\ncount_x = Hash.new(0)\n\nlist.each do |y, x|\n count_y[y] += 1\n count_x[x] += 1\nend\n\nputs \"#{count_y.key(1) + 1} #{count_x.key(1) + 1}\"\n"}, {"source_code": "r,c=gets.split.map(&:to_i)\nx,y=0,0\nr.times{|i|gets;c.times{|j|x^=i and y^=j if $_[j]=='*'}}\nputs \"#{x+1} #{y+1}\"\n\n"}, {"source_code": "n,m = gets.to_s.split(\" \").map{|x| Integer x}\npoints = []\nn.times do |i|\n\ta = gets.to_s.split(\"\")\n\ta.each_index do |j|\n\t\tif a[j] == \"*\" then\n\t\t\tpoints.push [i,j]\n\t\tend\n\tend\t\nend\np = []\n3.times do |x|\n\tpnt = points.pop\n\tif (pnt[0] == points[0][0] or pnt[0] == points[1][0]) and (pnt[1] == points[0][1] or pnt[1] == points[1][1]) then\n\t\tp = pnt\n\t\tbreak\n\tend\n\tpoints.push pnt\n\tpoints.rotate!\nend\n#puts \"#{p[0]} #{p[1]}\"\nnewP = [0,0]\nif p[0] == points[0][0] then\n\tp1 = points[0]\n\tp2 = points[1]\nelse\n\tp1 = points[1]\n\tp2 = points[0]\nend\n#puts \"#{p1[0]} #{p1[1]}\"\n#puts \"#{p2[0]} #{p2[1]}\"\nnewP[1] = p[1] + p1[1] - p[1]\nnewP[0] = p[0] + p2[0] - p[0]\n\nputs \"#{newP[0]+1} #{newP[1]+1}\"\n\n\n"}, {"source_code": "a = gets.to_i.times.map{ gets.strip }\nb = []\na.each_with_index do |s,i|\n s.split(//).each_with_index do |c,j| \n b << [i,j] if c == \"*\"\n end\nend\nhx = Hash.new(0)\nhy = Hash.new(0)\nb.each do |i,j|\n hx[i] += 1\n hy[j] += 1\nend\n\nputs [hx.key(1)+1,hy.key(1)+1] * \" \"\n"}, {"source_code": "r,c=gets.split.map(&:to_i)\nx,y=0,0\nr.times{|i|gets;c.times{|j|x^=i and y^=j if $_[j]=='*'}}\nputs \"#{x+1} #{y+1}\"\n\n"}, {"source_code": "require \"scanf\"\n\ninput = ARGF.read.lines\n\ncrime_scenes = []\nrow = 0\ninput.drop(1).each do |row_data|\n\tcrime_scenes += row_data\n\t\t.chars\n\t\t.each_with_index\n\t\t.select { |e,i| e == '*' }\n\t\t.map { |e,i| [row, i] }\n\n\trow += 1\nend\n\nres = \n\tif crime_scenes[0][0] == crime_scenes[1][0] # on row with second point\n\t\tif crime_scenes[0][1] == crime_scenes[2][1]\n\t\t\t[crime_scenes[2][0], crime_scenes[1][1]]\n\t\telse\n\t\t\t[crime_scenes[2][0], crime_scenes[0][1]]\n\t\tend\n\telse\n\t\tif crime_scenes[0][1] == crime_scenes[2][1] # on one column with third point\n\t\t\t[crime_scenes[0][0], crime_scenes[1][1]]\n\t\telse\n\t\t\tif crime_scenes[1][0] == crime_scenes[2][0]\n\t\t\t\t[crime_scenes[0][0], crime_scenes[2][1]]\n\t\t\telse\n\t\t\t\t[crime_scenes[1][0], crime_scenes[2][1]]\n\t\t\tend\n\t\tend\n\tend\n\nputs [res.first + 1, res.last + 1].join ' '"}, {"source_code": "h, w = gets.split.map(&:to_i)\nm = Array.new(h)\nx, y, xx, yy = 101, 102, -1, -2\nh.times{ |i| m[i] = gets\n\tw.times{ |j|\n\t\tif m[i][j, 1] == \"*\" then\n\t\t\txx = [xx, j].max\n\t\t\tx = [x, j].min\n\t\t\tyy = [yy, i].max\n\t\t\ty = [y, i].min\n\t\tend\n\t}\n}\n[x, xx].each{ |a|\n\t[y, yy].each{ |b|\n\t\tif m[b][a, 1] == \".\" then\n\t\t\tprint b + 1, \" \", a + 1, \"\\n\"\n\t\tend\n\t}\n}\n"}, {"source_code": "n, m = gets.split.map &:to_i\na = []\nn.times { a << gets.chomp.split('') }\n(0...n).each { |i| (0...m).each { |j| puts \"#{i + 1} #{j + 1}\" if a[i].count('*') == 1 && a.transpose[j].count('*') == 1 } }\n"}, {"source_code": "r,c=gets.split.map(&:to_i)\nx,y=0,0\nr.times{|i|gets;c.times{|j|x^=i and y^=j if $_[j]=='*'}}\nputs \"#{x+1} #{y+1}\"\n\n"}, {"source_code": "r,c=gets.split.map(&:to_i)\nx,y=0,0\nr.times{|i|gets;c.times{|j|x^=i and y^=j if $_[j]=='*'}}\nputs \"#{x+1} #{y+1}\"\n\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\ni=x=y=0\ntable=n.times.map{i+=1;x=i if gets.count(?*)==1;$_.each_char.to_a}\ni=0\ntable.transpose.each{|l|i+=1;y=i if l.join.count(?*)==1}\nputs \"%d %d\"%[x,y]"}, {"source_code": "r,c=gets.split.map(&:to_i)\nx,y=0,0\nr.times{|i|gets;c.times{|j|x^=i and y^=j if $_[j]=='*'}}\nputs \"#{x+1} #{y+1}\"\n\n"}, {"source_code": "n, m = gets.split.map &:to_i\nmat = Array.new(n) { gets.strip }\ndx = Hash.new(0)\ndy = Hash.new(0)\n\nmat.each_with_index do |row, i|\n row.chars.to_a.each_with_index do |char, j|\n if char == '*'\n dx[i] += 1\n dy[j] += 1\n end\n end\nend\n\np dx.select { |k, v| v.odd? }.keys[0].to_i + 1\np dy.select { |k, v| v.odd? }.keys[0].to_i + 1\n"}, {"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\nsa = []\nrety = 0\nretx = 0\nxa = []\nfor i in 0..n-1\n sa << gets.chomp\n wk = sa[i].index(\"*\")\n if wk != nil\n wk2 = sa[i].rindex(\"*\")\n if wk == wk2\n rety = i+1\n retx = wk+1\n else\n xa = [wk+1, wk2+1]\n end\n end\nend\nxa.delete(retx)\nputs rety.to_s + \" \" + xa[0].to_s \n\n"}, {"source_code": "r,c=gets.split.map(&:to_i)\nx,y=0,0\nr.times{|i|gets;c.times{|j|x^=i and y^=j if $_[j]=='*'}}\nputs \"#{x+1} #{y+1}\"\n"}, {"source_code": "r, c = gets.split.map(&:to_i)\nx, y = 0, 0\n1.upto(r){|i|\n gets\n 1.upto(c){|j|\n if $_[j - 1] == '*'\n x ^= i\n y ^= j\n end\n }\n}\nputs \"#{x} #{y}\"\n"}, {"source_code": "r, c = gets.split.map(&:to_i)\nx, y = 0, 0\n1.upto(r){|i|\n gets.chars.each_with_index{|c, j|\n if c == '*'\n x ^= i\n y ^= j + 1\n end\n }\n}\nputs \"#{x} #{y}\"\n"}, {"source_code": "r,c=gets.split.map(&:to_i)\nx,y=0,0\nr.times{|i|gets;c.times{|j|x^=i and y^=j if $_[j]=='*'}}\nputs \"#{x+1} #{y+1}\"\n\n"}], "negative_code": [{"source_code": "require 'scanf'\n\ninput = ARGF.read.lines\n\ncrime_scenes = []\nrow = 0\ninput.drop(1).each do |row_data|\n\tcrime_scenes += row_data\n\t\t.chars\n\t\t.each_with_index\n\t\t.select { |e,i| e == '*' }\n\t\t.map { |e,i| [row, i] }\n\n\trow += 1\nend\n\nres = \n\tif crime_scenes[0][0] == crime_scenes[1][0] # on row\n\t\tif crime_scenes[0][1] == crime_scenes[2][1]\n\t\t\t[crime_scenes[2][0], crime_scenes[1][1]]\n\t\telse\n\t\t\t[crime_scenes[2][0], crime_scenes[0][1]]\n\t\tend\n\telse\n\t\tif crime_scenes[0][0] == crime_scenes[2][0]\n\t\t\t[crime_scenes[1][0], crime_scenes[0][1]]\n\t\telse\n\t\t\t[crime_scenes[0][0], crime_scenes[1][1]]\n\t\tend\n\tend\n\nputs [res.first + 1, res.last + 1].join ' '"}, {"source_code": "require 'scanf'\n\ninput = ARGF.read.lines\n\ncrime_scenes = []\nrow = 0\ninput.drop(1).each do |row_data|\n\tcrime_scenes += row_data\n\t\t.chars\n\t\t.each_with_index\n\t\t.select { |e,i| e == '*' }\n\t\t.map { |e,i| [row, i] }\n\n\trow += 1\nend\n\nres = \n\tif crime_scenes[0][0] == crime_scenes[1][0] # on row with second point\n\t\tif crime_scenes[0][1] == crime_scenes[2][1]\n\t\t\t[crime_scenes[2][0], crime_scenes[1][1]]\n\t\telse\n\t\t\t[crime_scenes[2][0], crime_scenes[0][1]]\n\t\tend\n\telse\n\t\tif crime_scenes[0][1] == crime_scenes[2][1] # on one column with third point\n\t\t\t[crime_scenes[0][0], crime_scenes[1][1]]\n\t\telse\n\t\t\t[crime_scenes[1][0], crime_scenes[0][1]]\n\t\tend\n\tend\n\nputs [res.first + 1, res.last + 1].join ' '"}, {"source_code": "require \"scanf\"\n\ninput = ARGF.read.lines\n\ncrime_scenes = []\nrow = 0\ninput.drop(1).each do |row_data|\n\tcrime_scenes += row_data\n\t\t.chars\n\t\t.each_with_index\n\t\t.select { |e,i| e == '*' }\n\t\t.map { |e,i| [row, i] }\n\n\trow += 1\nend\n\nres = \n\tif crime_scenes[0][0] == crime_scenes[1][0] # on row with second point\n\t\tif crime_scenes[0][1] == crime_scenes[2][1]\n\t\t\t[crime_scenes[2][0], crime_scenes[1][1]]\n\t\telse\n\t\t\t[crime_scenes[2][0], crime_scenes[0][1]]\n\t\tend\n\telse\n\t\tif crime_scenes[0][1] == crime_scenes[2][1] # on one column with third point\n\t\t\t[crime_scenes[0][0], crime_scenes[1][1]]\n\t\telse\n\t\t\t[crime_scenes[1][0], crime_scenes[0][1]]\n\t\tend\n\tend\n\nputs [res.first + 1, res.last + 1].join ' '"}], "src_uid": "e344de8280fb607c556671db9cfbaa9e"} {"source_code": "n,m=gets.split.map(&:to_i)\ng=Array.new(n){Array.new(n,0)}\ncnt=Array.new(n,0)\nm.times{\n a,b=gets.split.map(&:to_i)\n a-=1\n b-=1\n g[a][b]=1\n g[b][a]=1\n cnt[a]+=1\n cnt[b]+=1\n}\nans=0\nloop {\n t=0\n n.times{|i|\n t+=(cnt[i]>0?1:0)\n }\n if t<=1 then break end\n t=0\n n.times{|i|\n t+=(cnt[i]==1?1:0)\n }\n if t==0 then break end\n r=cnt.clone\n n.times{|i|\n if r[i]==1 then\n n.times{|j|\n if g[i][j]>0 then\n g[i][j]-=1\n g[j][i]-=1\n cnt[i]-=1\n cnt[j]-=1\n end\n }\n end\n }\n ans+=1\n}\np ans\n", "positive_code": [{"source_code": "n,m=gets.chomp.split.map(&:to_i)\ni,j,f,a,b,ar=0,0,0,[],[],Array.new(100,0)\nm.times do |i|\n\tx,y=gets.chomp.split.map(&:to_i)\n\ta<<(x-1);b<<(y-1)\nend\nwhile i<105\n\tf,c=0,Array.new(100,0)\n\tm.times do |j|\n\t\tif ar[a[j]]==0 && ar[b[j]]==0\n\t\t\tc[a[j]]+=1\n\t\t\tc[b[j]]+=1\n\t\tend\n\tend\n\tn.times do |j|\n\t\tif c[j]==1\n\t\t\tf=1\n\t\t\tar[j]=1\n\t\tend\n\tend\n\tbreak if f==0\n\ti+=1\nend\nputs i"}, {"source_code": "class Kid\n attr_accessor :tied_to, :number\n def initialize (num)\n @tied_to = []\n @number = num\n end\nend\n\nresult = -1\ninput = STDIN.gets.strip\nlaces = []\ninput.split.last.to_i.times do |i|\n laces.push STDIN.gets.strip.split.collect {|i| i.to_i}\nend\n\nwhile true\n kids = Array.new(input.split.first.to_i) {|i| Kid.new(i+1)}\n result += 1\n laces.each do |i|\n kids[i[0]-1].tied_to.push i[1] unless kids[i[0]-1].tied_to.include? i[1]\n kids[i[1]-1].tied_to.push i[0] unless kids[i[1]-1].tied_to.include? i[0]\n end\n remove = []\n kids.each do |i|\n remove.push(i.number) if i.tied_to.size == 1\n end\n break if remove.size == 0\n remove.each do |i|\n laces.delete_if {|l| l.include? i}\n end\nend\np result"}, {"source_code": "include Math\n\nn, m=gets.split.map(&:to_i)\ngraph={}\n\nm.times{\n\ta,b=gets.split.map(&:to_i)\n\t\n\tif graph.has_key?(a)\n\t\tgraph[a] << b\t\t\n\telse\n\t\tgraph[a] = [b]\n\tend\n\t\n\tif graph.has_key?(b)\n\t\tgraph[b] << a\n\telse\n\t\tgraph[b] = [a]\n\tend\n}\n\nans=0\nloop{\t\n\tdelete_them = []\n\t\n\tgraph.keys.each{|key|\n\t\tif graph[key].size==1\t\t\t\t\t\t\n\t\t\tdelete_them << key\n\t\tend\n\t}\t\n\t\t\n\t#deleting vals in arrays\n\tgraph.keys.each{|key|\n\t\tdelete_them.each{|el|\tgraph[key].delete(el)}\n\t}\n\t\n\t# deleting keys\n\tdelete_them.each{|el| graph.delete(el)}\n\t\t\n\tans+=1 if delete_them.size!=0\n\tbreak if delete_them.size==0\n}\n\nputs ans\n"}, {"source_code": "n,m=gets.split.map(&:to_i);g=Hash.new []\nm.times{a,b=gets.split.map(&:to_i);g[a]+=[b];g[b]+=[a]}\ns=0;loop{d=[];g.keys.each{|k| d << k if g[k].size==1};g.keys.each{|k|d.each{|l|g[k].delete(l)}};d.each{|l|g.delete(l)};s+=1 if d.size!=0;break if d.size==0};p s\n"}, {"source_code": "n,m=gets.split.map(&:to_i);g=Hash.new [];m.times{a,b=gets.split.map(&:to_i);g[a]+=[b];g[b]+=[a]};s=0;loop{d=[];g.keys.each{|k|d< lv\nend\nputs \"#{lv}\"\n"}, {"source_code": "require 'set'\n\nif File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nnk = gets.chomp.split(\" \").map(&:to_i)\nn = nk[0]\nk = nk[1]\n\nhash = Hash.new(0)\nlast = Hash.new(-1)\nstr = gets.chomp\n\nbreakpoints = Set.new\n(0..n-1).each do |i|\n\tif str[i]!=str[i+1]\n\t\tbreakpoints.add(i)\n\tend\nend\n\ntoskip = Set.new\nbreakpoints.each do |br|\n\t(br-k+2..br).each do |x|\n\t\ttoskip.add(x)\n\tend\nend\n\n\n(0..n-k).each do |st|\n\tnext if toskip.include?(st)\n\tchar = str[st]\n#\tthestr = str[st..st+k-1]\n#\tnext if thestr.each_char.to_a.uniq.length>1\n\titslast = last[char]\n\tnext if itslast>=st\n\n\thash[char]+=1\n\tlast[char] = st+k-1\nend\n#p hash\n#p toskip\nif hash.empty?\n\tputs 0\nelse\n\tputs hash.values.max\nend\n\n#for 1 to k starting index, take steps of k"}], "negative_code": [], "src_uid": "6c71c828553e43c699237211005873e5"} {"source_code": "n = gets.to_i\ncount = 0\nfor i in 1..n\n buf = gets.split(' ').map(&:to_i)\n a, b, c = buf[0], buf[1], buf[2]\n count += 1 if a + b + c >= 2\nend\nputs count\n", "positive_code": [{"source_code": "ans=0\na=[]\ngets.to_i.times{|i|\n\ta<= 2 \nend\nputs number_of_solved\n"}, {"source_code": "p$<.grep(/1.*1/).size"}, {"source_code": "p$<.grep(/1.*1/).size\n"}, {"source_code": "x=0\ngets.chomp.to_i.times {\n\ta,b,c=gets.split.map &:to_i\n\tx+=1 unless a+b+c < 2\n}\nputs x"}, {"source_code": "puts gets.to_i.times.map{gets}.count{|x| x.count(\"1\") >= 2}\n"}, {"source_code": "p$<.grep(/1.*1/).size"}, {"source_code": "T = gets.chomp.to_i\nans = 0\nfor i in (1..T)\n a = gets.chomp.split(' ')\n ans += (a.count(\"1\") > 1) ? 1 : 0\nend\nputs ans"}, {"source_code": "n = gets.to_i\nans = 0\nn.times do\n\tf, s, t = gets.split.map{|x| x.to_i}\n\tans += 1 if f + s + t >= 2\nend\np ans"}, {"source_code": "b = gets.chomp\na = 0\narray = []\nwhile a < b.to_i\n n = STDIN.gets.split(\" \")\n if (n[0].to_i + n[1].to_i + n[2].to_i) > 1\n array << 1\n end\n a += 1\nend\n\nputs array.size"}, {"source_code": "#my code goes here\na = []\nk = 0\nn = gets.to_i\nfor c in 1..n\ns = 0\na = gets.chomp.split().map { |e| e.to_i }\na.each do |x|\n s += x\nend\nif s >= 2\nk = k + 1\nelse\nk = k + 0\nend\nend\nputs \"#{k}\"\n\n"}, {"source_code": "n = gets.chomp.to_i\ncnt = 0\nn.times do \n\tcnt += 1 if gets.chomp.split.map(&:to_i).count(1) >= 2\nend\nputs cnt"}, {"source_code": "num = gets.chomp.to_i\narray = []\ni = 0\nwhile (i < num)\n\tarray.push gets.chomp\n\ti = i+1\nend\naux = 0\narray.each do |leng|\n\tline = leng.split\n\tif (line[0].to_i + line[1].to_i + line[2].to_i >= 2) \n\t\taux = aux + 1\n\tend\nend\nputs aux.to_s"}, {"source_code": "n = gets.to_i\nputs n.times.map{gets.split.map(&:to_i).inject(:+)}.select{|x| x >= 2}.size\n"}, {"source_code": "p [*$<].grep(/1.*1/).size"}, {"source_code": "going_to_solve = 0\ngets.to_i.times { going_to_solve += 1 if gets.gsub(\" \", \"\").count(\"1\") >= 2 }\nputs going_to_solve"}, {"source_code": "p$<.grep(/1.*1/).size"}, {"source_code": "#!/usr/bin/env ruby\ninput = gets.to_i\n\nanswer = 0\ninput.times do\n inp = gets.split(' ').map(&:to_i).inject(0, :+)\n answer += 1 if inp >= 2\nend\n\nputs answer\n"}, {"source_code": "p = 0\ngets.chomp.to_i.times do |variable|\n\tc = gets.chomp.count(\"1\")\n\t(p = p + 1) if c > 1\nend\nputs p"}, {"source_code": "p$<.grep(/1.*1/).size"}, {"source_code": "a=gets.chomp.to_i\nans=0\na.times do\nb=gets.chomp\nif b.count(\"1\")>=2\nans+=1\nend\nend\nputs \"#{ans}\"\n"}, {"source_code": "a=0\nSTDIN.read.split(\"\\n\").drop(1).each do |w|\n a += 1 if w.chomp.split(' ').map{|n| n.to_i}.inject(:+) >= 2\nend\nputs a"}, {"source_code": "n = gets.to_i\na =[]\nj = 0\n\nfor i in 1..n do\n\ta = gets.split.map(&:to_i)\n\tif a.count(1) > 1\n\t\tj = j+1\n\tend\nend\n\nputs j"}, {"source_code": "n = gets.to_i\n\nproblems = []\n1.upto(n) do |idx|\n problem = gets.gsub(\"\\n\", \"\")\n problem = problem.split(\" \").map(&:to_i)\n problems.push(problem)\nend\n\nproblems_implemented = 0\nproblems.each do |problem|\n sureness = 0\n problem.each do |friend|\n sureness += friend\n end\n if sureness >= 2\n problems_implemented += 1 \n end\nend\n\nputs problems_implemented"}, {"source_code": "p gets.to_i.times.map{gets}.count{|x| x.count('1') >= 2}"}, {"source_code": "n, *s = STDIN.read.split(\"\\n\") #gets.sFile.readlines('inp.txt')\nans = 0\ns.each do |i|\n\tans += 1 if i.count('1') > 1\nend\np ans"}, {"source_code": "def answers ()\n n = gets.chomp\n n = n.to_i\n final = 0\n \n for i in 0...n\n count = 0 \n test = Array.new\n test = gets.split(' ').map(&:to_i)\n test.each { |x| \n if x == 1 \n count+=1\n end\n }\n if count >= 2 then\n final +=1\n end\n end\n puts final\nend\n\nanswers"}, {"source_code": "res=0\ngets.to_i.times{(gets.count(?1))>=2?res+=1:\"\"}\nputs res"}, {"source_code": "\nn = gets.chomp.to_i\n\ncount = 0\n\nwhile n > 0\n a = gets.chomp \n if a[0].to_i + a[2].to_i + a[-1].to_i >= 2\n count += 1\n end\n n -= 1\nend\n\nputs count\n\n"}, {"source_code": "n = gets.to_i\nm = 0;\nn.times do\n x, y, z = gets.split.map(&:to_i)\n m += 1 if x + y + z >= 2\nend\nputs m\n"}, {"source_code": "line = gets.chomp\nstring_value = []\nline.to_i.times do |i|\n\tvalue = gets.chomp\n\tstring_value << value\nend\n\ncount = 0\nstring_value.each do |value|\n\tif value.split.count{|x| x.to_i == 1} >= 2\n\t\tcount += 1\n\tend\n\nend \nputs count"}, {"source_code": "n, count = gets.chomp.to_i, 0\nn.times do\n count += 1 if (gets.chomp.split(' ').map(&:to_i).reduce(:+) > 1)\nend\nputs count\n"}, {"source_code": "\n$res = 0\n$cnt = 0\n\ngets.to_i.times{|x| x = gets.split.map(&:to_i) \n x.each do |num|\n if num == 1\n $cnt += 1\n end\n end\n if $cnt >= 2\n $res += 1\n end\n $cnt = 0\n}\n\nputs $res\n"}, {"source_code": "n = gets.chomp.to_i\nputs n.times.select {|i|gets.chomp.split(' ').map(&:to_i).select{|i| i > 0}.count > 1 }.count"}, {"source_code": "def get_num\n input = gets.chomp.split\n x = 0\n for i in 0..input.length - 1\n x = x + input[i].to_i\n end\n if x >= 2\n return 1\n else\n return 0\n end\nend\n\n$n = gets.chomp.to_i\nans = 0\nfor i in 1..$n\n ans += get_num\nend\n\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\nc = 0\nwhile n > 0 \n s1, s2, s3= gets.chomp.split.map(&:to_i) \n if s1+s2+s3 >= 2\n c = c + 1\n end \n n -=1\nend\nputs c\n"}, {"source_code": "problems_count = gets.chomp.to_i\n\ncounter = 0\nproblems_count.times.each do\n submission_string = gets.chomp\n submission = submission_string.split(' ').map(&:to_i)\n el_counter = 0\n submission.each do |el|\n el_counter += 1 if el.eql?(1)\n end\n counter += 1 if el_counter >= 2\nend\n\nputs counter\n"}, {"source_code": "puts STDIN.readlines[1..-1].map(&:strip).map(&:split).inject(0) { |memo, w| memo + (w.find_all { |x| x==\"1\"}.size >= 2 ? 1 : 0) }"}, {"source_code": "p$<.grep(/1.*1/).size\n"}, {"source_code": "n = gets.to_i\n\npeta = []\ncounter = 0\nfor i in 0..n-1\n peta[i] = gets.split.map(&:to_i)\n counter+=1 if peta[i].count(1)>=2\nend\n\nputs counter\n"}, {"source_code": "cnt = 0\nn = gets.chomp.to_i\nn.times{cnt += 1 if gets.chomp.split.map(&:to_i).reduce(:+) > 1}\nputs cnt"}, {"source_code": "number = gets.strip.to_i\n\ncount = 0\nnumber.times do\n input = gets.strip\n count += 1 if input.split(' ').count('1') >= 2\nend\n\nputs count\n"}, {"source_code": "def chk(ans)\n\tn=0\n\tfor i in ans\n\t\tif i==1\n\t\t\tn+=1\n\t\tend\n\tend\n\treturn n\nend\nn = gets.to_i()\nproblem =0\nwhile n>0\n\tn-=1\n\tans = gets.split().map{|x| x.to_i}\n\tif chk(ans)>1\n\t\tproblem+=1\n\tend\nend\nputs problem"}, {"source_code": "n = gets.to_i \nproblems_solved = 0 \nn.times {\n arr = gets.split(\" \").map(&:to_i)\n if arr.select{|a| a==1 }.count >=2\n problems_solved+=1 \n end \n}\nputs problems_solved"}, {"source_code": "n = gets.to_i\nf = []\ns = []\nl = []\narrs = []\nimplements = 0\n\nn.times do \n q = gets.strip.split(\" \").map(&:to_i)\n f << q[0]\n s << q[1]\n l << q[2]\n arrs << q\nend \n\narrs.each do |arr|\n implements += 1 if arr.count{|one| one == 1} > 1 \nend \nputs implements\n"}, {"source_code": "n = gets.strip.to_i\ncount = 0\nn.times do |i|\n arr = gets.strip.split(\" \").map(&:to_i)\n count += 1 if arr.count{|elem| elem == 1} > 1 \nend\nputs count"}, {"source_code": "p$<.grep(/1.*1/).size"}, {"source_code": "N = gets.to_i\nas = N.times.map{gets.split.count{|bb| bb.to_i.zero? }}\n\nputs as.count{|a| a < 2 }\n"}, {"source_code": "N = gets.to_i\nas = N.times.map{gets.chomp.gsub('0','')}\nputs as.count{|a| a.size > 3 }"}, {"source_code": "N = gets.to_i\nas = N.times.map{gets.split.count{|bb| bb == '0' }}\n\nputs as.count{|a| a < 2 }\n"}, {"source_code": "res = 0\ngets.to_i.times do\n input = gets.split.map(&:to_i)\n res += 1 if input.select { |item| item == 1 }.size >= 2\nend\nputs res"}, {"source_code": "\namountOfProblems = gets.chomp#get input on first line\namountOfProblems = amountOfProblems.to_i\nwillWorkSolution = 0\nsecondCounter = 0\n\n\namountOfProblems.times do\n willWorkSolution = gets.chomp # 1 0 1 - space separated other input\n willWorkSolution = willWorkSolution.split(\" \") # array is: [\"1\", \"0\", \"1\"]\n counter = 0\n \n willWorkSolution.each do |one_or_zero|\n if (one_or_zero == \"1\")\n counter = counter + 1\n if (counter == 2)\n secondCounter = secondCounter + 1\n end\n end\n \n end\nend\n\n\nputs secondCounter\n"}, {"source_code": "i = gets.to_i\ncounter = 0\n(1..i).each do |x|\n counter += gets.split(' ').map(&:to_i).reduce(:+) >= 2 ? 1 : 0\nend\nprint counter"}, {"source_code": "p$<.grep(/1.*1/).size\n"}, {"source_code": "n = gets.to_i\nans = 0\nn.times do\n if gets.split.map(&:to_i).inject(:+) >= 2\n ans += 1\n end\nend\nputs ans\n"}, {"source_code": "p$<.grep(/1.*1/).size\n"}, {"source_code": "problemNum = gets.chomp.to_i\n\nresult = 0\n\n(0...problemNum).each do |iter|\n\tinput = gets.chomp.split(' ').map {|item| item.to_i}\n\tresult += 1 if input.count(1) > 1\nend\n\nputs result"}, {"source_code": "p$<.grep(/1.*1/).size\n"}, {"source_code": "count = gets.to_i\nsum = 0\n\n\n(0..count-1).each do |i|\n row = gets.split(\" \")\n row_sum = 0\n row.each do |r|\n row_sum += r.to_i\n end\n if row_sum > 1 then\n sum+=1\n end\nend\n\nputs sum"}, {"source_code": "#!/usr/bin/env ruby\n\ncount = gets.to_i\nsum = 0\n\n\n(0..count-1).each do |i|\n\trow = gets.split(\" \")\n\trow_sum = 0\n\trow.each do |r|\n\t\trow_sum += r.to_i\n\tend\n\tif row_sum > 1 then\n\t\tsum+=1\n\tend\nend\n\nputs sum\n"}, {"source_code": "count = gets.to_i\n\nres = 0\ncount.times do |i|\n res += 1 if gets.split(\" \").map(&:to_i).inject(:+) > 1\nend\n\np res"}, {"source_code": "d=0\ngets.to_i.times{\n\ta,b,c=gets.split.map{|e| e.to_i}\n\td=d+(a+b+c>1?1:0)\n}\nputs d\n"}, {"source_code": "require 'scanf'\nn = $stdin.readline.to_i\n\ncounter = 0\nn.times do\n a, b, c = $stdin.readline.scanf(\"%d%d%d\")\n counter += 1 if a + b + c >=2\nend\n\nputs counter\n"}, {"source_code": "n = gets.to_i\ncount = 0\nfor i in 1..n\n buf = gets.split(' ').map(&:to_i)\n a, b, c = buf[0], buf[1], buf[2]\n count += 1 if a + b + c >= 2\nend\nputs count\n"}, {"source_code": "count = 0\n\ngets.strip.to_i.times do\n p, v, t = gets.strip.split(' ').map(&:to_i)\n count +=1 if p + v + t >= 2\nend\n\nputs count\n"}, {"source_code": "n = gets.chomp.to_i\nans = 0\nn.times{\n num = gets.chomp.split.map{|x| x.to_i }\n ans += 1 if num.inject{ |sum,x| sum + x } >= 2\n}\nputs ans"}], "negative_code": [{"source_code": "#my code goes here\na = []\nk = 0\nn = gets.to_i\nfor c in 1..n\nfor b in 0...3\ns = 0\na[b] = gets.to_i\na.each do |x|\n s += x\nend\nend\nif s >= 2\nk = k + 1\nelse\nk = k + 0\nend\nend\nputs \"#{k}\"\n\n"}, {"source_code": "gets.to_i.times.map{gets.split.map(&:to_i).inject(:+)}.select{|x| x >= 2}.size"}, {"source_code": "n = gets.to_i\nans = 0\n\n(1..n).each do |i|\n res = 0\n (1..3).each do |j|\n tmp = gets.to_i\n res += tmp\n end\n\n if res >= 2\n ans += 1\n end\nend\n\nputs ans"}, {"source_code": "ans=0\na=[]\ngets.to_i.times{|i|\n\ta< a -1 \n\tb = gets.chomp(\" \")\n\ttemp = 0\n\t#puts b[0].to_s + \" - This is it!\"\n\tif b[0].to_i == 1 \n\t\ttemp = temp + 1\n\tend\n\tif b[1].to_i == 1 \n\t\ttemp = temp + 1\n\tend\n\tif b[2].to_i == 1 \n\t\ttemp = temp + 1\n\tend\n\tif temp>=2 \n\t\tcount = count + 1 \n\tend\n\tindex = index + 1 \nend\nputs count "}, {"source_code": "n = gets.to_i\nl = []\n(1..n).each { l << gets.split.map(&:to_i) }\nputs l.transpose.map { |x| x.reduce(:+) }.reduce(0) { |res, x| res + (x > 1 ? 1 : 0) }"}, {"source_code": "p = gets.chomp.to_i\ns = 0\n\nfor i in 1..p do\n a = gets.chomp.split(\" \").sort.join(\"\")\n if a.to_i != 1\n s += 1\n end\nend\n\nputs s"}, {"source_code": "gets.to_i.times do\n a = gets.split.map(&:to_i).inject(:+)\n a += a\nend"}, {"source_code": "n, *s = STDIN.read.split(\"\\n\") #gets.sFile.readlines('inp.txt')\nputs s.length\nans = 0\ns.each do |i|\n\tif i[0].to_i + i[2].to_i + i[4].to_i >= 2\n\t\tans += 1\n\tend\nend\nputs ans"}, {"source_code": "n, *s = gets.split('/n') #File.readlines('inp.txt')\nans = 0\ns.each do |i|\n\tif i[0].to_i + i[2].to_i + i[4].to_i >= 2\n\t\tans += 1\n\tend\nend\nputs ans"}, {"source_code": "\namountOfProblems = gets.chomp#get input on first line\namountOfProblems = amountOfProblems.to_i\nwillWorkSolution = 0\nsolutionsTeamWillWork = []\n\namountOfProblems.times do\n willWorkSolution = gets.chomp # 1 0 1 - space separated other input\n willWorkSolution = willWorkSolution.split(\" \") # array is: [\"1\", \"0\", \"1\"]\n \n willWorkSolution.each do |one_or_zero|\n if (one_or_zero == \"1\")\n solutionsTeamWillWork.push(one_or_zero)\n end\n end\nend\n\n\nputs solutionsTeamWillWork.size / amountOfProblems\n"}, {"source_code": "\namountOfProblems = gets.chomp#get input on first line\namountOfProblems = amountOfProblems.to_i\nwillWorkSolution = 0\nsolutionsTeamWillWork = []\n\n\namountOfProblems.times do\n willWorkSolution = gets.chomp # 1 0 1 - space separated other input\n willWorkSolution = willWorkSolution.split(\" \") # array is: [\"1\", \"0\", \"1\"]\n \n counter = 0\n \n willWorkSolution.each do |one_or_zero|\n \n if (one_or_zero == \"1\")\n counter = counter + 1\n if (counter >= 2)\n solutionsTeamWillWork.push(1) \n end\n end\n end\nend\n\n\nputs solutionsTeamWillWork.size\n"}, {"source_code": "n = gets.chomp.to_i\na = []\nres = 0\nfor i in 0...n\n a[i] = gets.chomp\n if a.count('1')>=2\n res+=1\n end\nend\nputs res"}], "src_uid": "3542adc74a41ccfd72008faf983ffab5"} {"source_code": "INF = 10 ** 20\nn = gets.to_i\ngets\nd = [INF] * (n + 1)\ngets.to_i.times do\n\ta, b, c = gets.split.map(&:to_i)\n\td[b] = [d[b], c].min\nend\ns = d.inject(&:+) - 2 * INF\np s < INF ? s : -1\n\n", "positive_code": [{"source_code": "INF = 10 ** 20\nn = gets.to_i\ngets\nd = [INF] * (n + 1)\ngets.to_i.times do\n\ta, b, c = gets.split.map(&:to_i)\n\td[b] = [d[b], c].min\nend\ns = d.inject(&:+) - 2 * INF\np s < INF ? s : -1\n"}, {"source_code": "INF = 10 ** 20\nn = gets.to_i\ngets\nd = [INF] * (n + 1)\ngets.to_i.times do\n\ta, b, c = gets.split.map(&:to_i)\n\td[b] = [d[b], c].min\nend\ns = d.inject(&:+) - 2 * INF\np s < INF ? s : -1\n\n"}, {"source_code": "INF = 10 ** 20\nn = gets.to_i\ngets\nd = [INF] * (n + 1)\ngets.to_i.times do\n\ta, b, c = gets.split.map(&:to_i)\n\td[b] = [d[b], c].min\nend\ns = d.inject(&:+) - 2 * INF\np s < INF ? s : -1\n\n"}, {"source_code": "n = gets.chomp.to_i\nq = gets.chomp.split(' ').map &:to_i; q.unshift nil\nm = gets.chomp.to_i\nresult = {}\nm.times do\n a, b, c = gets.chomp.split(' ').map &:to_i\n next if q[a] <= q[b]\n result[b] = result[b] ? [result[b], c].min : c\nend\nputs result.length == n - 1 ? result.values.inject(:+).to_i : -1"}, {"source_code": "INF = 10 ** 20\nn = gets.to_i\ngets\nd = [INF] * (n + 1)\ngets.to_i.times do\n\ta, b, c = gets.split.map(&:to_i)\n\td[b] = [d[b], c].min\nend\ns = d.inject(&:+) - 2 * INF\np s < INF ? s : -1\n"}, {"source_code": "n=gets.chomp.to_i\ngets\nm=gets.chomp.to_i\nmax=100000000\nmemo=Array.new\nn.times{memo << max}\nm.times{\n tmp=gets.chomp.split()\n b=tmp[1].to_i()-1\n c=tmp[2].to_i\n if memo[b] > c\n memo[b]=c\n end\n}\nsum=0\ncnt=0\nn.times{|i|\n if memo[i] c)\n employees[b - 1][a - 1] = c\n end\nend\n\nacc = 0\nroot = 0\n\nn.times {|i|\n min = employees[i].min\n if (min == UNSET)\n root += 1\n if (root > 1)\n puts -1\n exit\n end\n else\n acc += min\n end\n}\n\nputs acc \n"}, {"source_code": "INF = 10 ** 20\nn = gets.to_i\ngets\nd = [INF] * (n + 1)\ngets.to_i.times do\n a, b, c = gets.split.map(&:to_i)\n d[b] = [d[b], c].min\nend\ns = d.inject(&:+) - 2 * INF\np s < INF ? s : -1"}, {"source_code": "INF = 10 ** 20\nn = gets.to_i\ngets\nd = [INF] * (n + 1)\ngets.to_i.times do\n\ta, b, c = gets.split.map(&:to_i)\n\td[b] = [d[b], c].min\nend\ns = d.inject(&:+) - 2 * INF\np s < INF ? s : -1\n"}, {"source_code": "n = gets.chomp.to_i\nq = gets.chomp.split(' ').map &:to_i; q.unshift nil\nm = gets.chomp.to_i\nresult = {}\nm.times do\n a, b, c = gets.chomp.split(' ').map &:to_i\n next if q[a] <= q[b]\n result[b] = result[b] ? [result[b], c].min : c\nend\nputs result.length == n - 1 ? result.values.inject(:+).to_i : -1\n"}, {"source_code": "INF = 10 ** 20\nn = gets.to_i\ngets\nd = [INF] * (n + 1)\ngets.to_i.times do\n\ta, b, c = gets.split.map(&:to_i)\n\td[b] = [d[b], c].min\nend\ns = d.inject(&:+) - 2 * INF\np s < INF ? s : -1\n\n"}, {"source_code": "INF = 10 ** 20\nn = gets.to_i\ngets\nd = [INF] * (n + 1)\ngets.to_i.times do\n\ta, b, c = gets.split.map(&:to_i)\n\td[b] = [d[b], c].min\nend\ns = d.inject(&:+) - 2 * INF\np s < INF ? s : -1\n\n"}, {"source_code": "INF = 10 ** 20\nn = gets.to_i\ngets\nd = [INF] * (n + 1)\ngets.to_i.times do\n\ta, b, c = gets.split.map(&:to_i)\n\td[b] = [d[b], c].min\nend\ns = d.inject(&:+) - 2 * INF\np s < INF ? s : -1\n\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nq = gets.chomp.split(' ').map &:to_i; q.unshift nil\nm = gets.chomp.to_i\nresult = {}\nm.times do\n a, b, c = gets.chomp.split(' ').map &:to_i\n next if q[a] <= q[b]\n result[b] = result[b] ? [result[b], c].min : c\nend\nputs result.length == n - 1 ? result.values.inject(:+) : -1\n"}, {"source_code": "n = gets.chomp.to_i\nq = gets.chomp.split(' ').map &:to_i\nm = gets.chomp.to_i\nresult = {}\nm.times do\n a, b, c = gets.chomp.split(' ').map &:to_i\n result[b] = result[b] ? [result[b], c].min : c\nend\nputs result.length == n - 1 ? result.values.inject(:+) : -1\n"}], "src_uid": "ddc9b2bacfaa4f4e91d5072240c1e811"} {"source_code": "#!/usr/bin/ruby1.9\n\nn, s, t = STDIN.readline.split.collect {|s| s.to_i }\n\nmove = [0] + STDIN.readline.split.collect {|s| s.to_i }\n\ncurr = s\nsteps = 0\n\nwhile true\n\tbreak if curr == t\n\tsteps += 1\n\tcurr = move[curr]\n\tif curr == s\n\t\tsteps = -1\n\t\tbreak\n\tend\nend\n\nputs steps\n", "positive_code": [{"source_code": "n,s,t=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i).unshift('a')\nd,k=s,0\nwhile d!=t\n\td=a[d]\n\tk+=1\n\tif k>n\n\t\tk=-1\n\t\tbreak\n\tend\nend\nputs k"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n\n n.times do |turn|\n if s == t\n puts turn\n exit\n elsif s == operation[s-1]\n puts -1\n exit\n else\n s = operation[s-1]\n end\n end\n puts -1\n end\nend\n\nb = B.new"}, {"source_code": "n,s,t=gets.split.map(&:to_i)\np=gets.split.map(&:to_i)\np.unshift(0)\nv=s\nres=-1\n0.upto(n){|x|\n\tif v == t then\n\t\tres=x\n\t\tbreak\n\tend\n\tv=p[v];\n}\nputs res\n"}, {"source_code": "n,s,t = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\nvisited = Array.new(n,false)\nans = -1\ni = s - 1\ncount = 0\nif s == t\n\tans = 0\nelse\n\twhile true\n\t\tvisited[i] = true\n\t\tif !visited[arr[i]-1]\n\t\t\ti = arr[i] - 1\n\t\t\tcount += 1\n\t\telse\n\t\t\t# puts \"breaking here #{arr[i]} #{visited}\"\n\t\t\tbreak\n\t\tend\n\t\tif i == t - 1\t\t\t\n\t\t\tans = count\n\t\t\tbreak \n\t\tend\n\n\tend\nend\n# puts \"#{visited} #{i}\"\nputs ans\n\n"}, {"source_code": "n,s,t = gets.chomp.split(\" \").collect {|x| x.to_i}\n\narr = gets.chomp.split(\" \").collect {|x| (x.to_i-1)}\n\naux = [0]*n\n\n(0...n).each{ |v|\n aux[arr[v]] = v\n}\n\nq = 0\ns-=1\nt-=1\n\nwhile s!=t and q true}\n\nshuffle_count = 0\ncurrent_s = s\nuntil current_s == t do\n if visited.has_key? p[current_s]\n puts -1\n exit\n end\n current_s = p[current_s]\n shuffle_count += 1\n visited[current_s] = true\nend\n\nputs shuffle_count\n"}, {"source_code": "n, s, t = gets.split.map &:to_i\np = gets.split.map &:to_i\n\nvisited = {s => true}\n\nshuffle_count = 0\ncurrent_s = s\nuntil current_s == t do\n if visited.has_key? p[current_s - 1]\n puts -1\n exit\n end\n current_s = p[current_s - 1]\n shuffle_count += 1\n visited[current_s] = true\nend\n\nputs shuffle_count\n"}, {"source_code": "I =->{gets.split.map &:to_i}\ndef gao\n\tn, s, t = I[]; return 0 if s==t\n\ts -= 1; t -= 1; a = I[]; vis = Array.new(n, 0); s = a[s] - 1; res = 1; while (s != t) do\n\t\tvis[s] = 1; s = a[s]-1; res += 1\n\t\treturn -1 if !vis[s].zero?\n\tend\n\tres\nend\nputs gao()\n"}, {"source_code": "st = gets.split\nn=st[0].to_i\ns=st[1].to_i\nt=st[2].to_i\n\nmas = gets.split\n\ncount=0\npath_exists=false\nif s==t\n puts 0\nelse\n cur=s\n (n+1).times do\n cur=mas[cur-1].to_i\n count+=1\n if cur==t\n path_exists = true\n break\n end\n end\n if path_exists\n print(count)\n else\n print(-1)\n end\nend"}, {"source_code": "#!/usr/bin/env ruby -w\n\nrequire 'set'\n\nn_glasses, ball_start, ball_end = gets.split(' ').map(&:to_i)\nball_start -= 1\nball_end -= 1\n\nmarbles = gets.split(' ').map(&:to_i).map(&:pred)\n\niterations = 0\n\nvisited = Set.new\n\nactual_index = ball_start\nuntil actual_index == ball_end || iterations == -1\n if visited.include? actual_index\n iterations = -1\n else\n visited << actual_index\n actual_index = marbles[actual_index]\n iterations += 1\n end\nend\n\nprint iterations\n\n\n\n"}, {"source_code": "n, s, t = gets.split.map(&:to_i)\n\np = [0] + gets.split.map(&:to_i)\n\na = s;\ncount = 0\nuntil a == t\n a = p[a]\n count += 1\n if a == s\n count = -1\n\tbreak\n end\nend\n\nputs count"}], "negative_code": [{"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n\n n.times do |turn|\n if s == operation[s-1]\n puts -1\n break\n elsif s == t\n puts turn\n break\n else\n s = operation[s-1]\n end\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n if s == t\n puts 0\n return 0\n end\n\n diff = 0\n\n turn = 0\n operation.each do |pos|\n turn += 1\n if s == pos\n diff += 1\n else\n s = pos\n end\n break if t == s\n end\n\n if t == s && n > turn\n puts turn - diff\n elsif diff > 0 && t == s\n puts n - diff\n else\n puts -1\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n\n n.times do |turn|\n if s == t\n puts turn\n break\n elsif s == operation[s-1]\n puts -1\n break\n else\n s = operation[s-1]\n end\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n if s == t\n puts 0\n return 0\n end\n\n diff = 0\n\n turn = 0\n operation.each do |pos|\n turn += 1\n if s == pos\n diff += 1\n else\n s = pos\n end\n break if t == s\n end\n\n if t == s && n >= turn\n if diff > 0\n puts \"#{turn - diff}\"\n else\n puts -1\n end\n else\n puts -1\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n if s == t\n puts 0\n return 0\n end\n\n diff = 0\n\n turn = 0\n operation.each do |pos|\n turn += 1\n if s == pos\n diff += 1\n s = pos\n else\n s = pos\n end\n break if t == s\n end\n\n if t == s && n > turn\n puts turn - diff\n elsif diff > 0 && t == s\n puts n - diff\n else\n puts -1\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n if s == t\n puts 0\n return 0\n end\n\n diff = 0\n\n list = []\n\n turn = 0\n operation.each do |pos|\n turn += 1\n if list.include?(pos)\n diff += 1\n else\n s = pos\n list << pos\n end\n break if t == s\n end\n\n if t == s && n >= turn\n if diff > 0\n puts \"#{turn - diff}\"\n else\n puts -1\n end\n else\n puts -1\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n if s == t\n puts 0\n return 0\n end\n\n diff = 0\n\n operation.each do |pos|\n if s == pos\n diff += 1\n s = pos\n else\n s = pos\n end\n end\n\n if diff > 0\n puts n-diff\n else\n puts -1\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n if s == t\n puts 0\n return 0\n end\n\n diff = 0\n\n turn = 0\n operation.each do |pos|\n turn += 1\n if s == pos\n diff += 1\n s = pos\n else\n s = pos\n end\n break if t == s\n end\n\n if diff > 0 && t == s && n > turn\n puts turn - diff\n elsif diff > 0 && t == s\n puts n - diff\n else\n puts -1\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n\n n.times do |turn|\n if s == t\n puts turn\n break\n elsif s == operation[s-1]\n puts -1\n break\n else\n s = operation[s-1]\n end\n end\n puts -1\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n if s == t\n puts 0\n return 0\n end\n\n diff = 0\n\n turn = 0\n operation.each do |pos|\n turn += 1\n if s == pos\n diff += 1\n else\n s = pos\n end\n end\n\n if t == s && n >= turn\n if diff > 0\n puts \"#{turn - diff}\"\n else\n puts -1\n end\n else\n puts -1\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n if s == t\n puts 0\n return 0\n end\n\n diff = 0\n\n operation.each do |pos|\n if s == pos\n diff += 1\n s = pos\n else\n s = pos\n end\n end\n\n if diff > 0 && t == s\n puts n-diff\n else\n puts -1\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n if s == t\n puts 0\n return 0\n elsif s == operation[0]\n puts n-1\n else\n puts -1\n end\n\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, s, t = $stdin.gets.split(' ').map(&:to_i)\n operation = $stdin.gets.split(' ').map(&:to_i)\n\n if s == t\n puts 0\n return 0\n end\n\n diff = 0\n\n turn = 0\n operation.each do |pos|\n turn += 1\n if s == pos\n diff += 1\n else\n s = pos\n end\n break if t == s\n end\n\n if t == s && n > turn\n puts \"#{turn - diff}\"\n elsif diff > 0 && t == s\n puts \"#{n - diff}\"\n else\n puts -1\n end\n end\nend\n\nb = B.new"}], "src_uid": "b01602b51b9103c0f31c3f50b32aa88d"} {"source_code": "def in_range(i, j, n)\n i < n && j < n\nend\n\ngets.strip.to_i.times do |t|\n n = gets.strip.to_i\n board = []\n n.times do\n board << gets.strip\n end\n res = true\n (0..n-1).to_a.each do |i|\n (0..n-1).to_a.each do |j|\n if board[i][j] == '1'\n if in_range(i+1, j, n) && board[i+1][j] == '0' && in_range(i, j+1, n) && board[i][j+1] == '0'\n res = false\n break\n end\n end\n end\n break if res == false\n end\n\n puts res ? \"YES\" : \"NO\"\nend\n\n", "positive_code": [{"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ts = (1..n).map { gets.chomp }\n\tputs (0...n - 1).to_a.product((0...n - 1).to_a).all? { |i, j|\n\t\ts[i][j] == '0' || s[i + 1][j] == '1' || s[i][j + 1] == '1'\n\t} ? \"YES\" : \"NO\"\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do |testcase|\n n = gets.chomp.to_i\n grid = []\n n.times do |i|\n grid << gets.chomp\n end\n flag = true\n n.times do |i|\n n.times do |j|\n if grid[i][j] == \"1\"\n if !(i==n-1 || j==n-1 || grid[i+1][j]==\"1\" || grid[i][j+1]==\"1\")\n flag = false\n break\n end\n end\n end\n if !flag\n break\n end\n end\n if flag\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "gets.to_i.times do\n n=gets.to_i\n a=(1..n).map{gets.chomp}\n puts ([*0...n-1].product([*0...n-1]).map.any?{|i, j| a[i][j]+a[i+1][j]+a[i][j+1]=='100'} ? :NO : :YES)\nend\n"}, {"source_code": "gets.to_i.times do\n n=gets.to_i\n a=(1..n).map{gets.chomp}\n puts ([*0...n-1].product([*0...n-1]).map.any?{|i, j| a[i][j]+a[i+1][j]+a[i][j+1]=='100'} ? :NO : :YES)\nend"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n s = n.times.map { gets.chomp }\n ok = true\n (n - 2).downto(0) do |i|\n (n - 2).downto(0) do |j|\n if s[i][j] == \"1\"\n if !(s[i][j + 1] == \"1\" || s[i + 1][j] == \"1\")\n ok = false\n break\n end\n end\n end\n break if !ok\n end\n puts ok ? \"YES\" : \"NO\"\nend\n"}], "negative_code": [{"source_code": "def func(a)\n a.map{|e| e.join.sub(/([o1]*)[o1]$/){|s|s=?o*$1.size+?o}.split('')}\nend\n\ndef func2(a)\n a.map{|e| e.join.sub(/^(1+)o/){|s|s=?o*$1.size+?o}.split('')}\nend\n\ngets.to_i.times{\n n=gets.to_i\n a=(1..n).map{gets.chomp.chars}\n a=func(a)\n a=func(a.transpose)\n a=func2(a)\n a=func2(a.transpose.map(&:reverse))\n #a.map{|e|puts e.join}\n puts (a.flatten.none?{|e|e==?1} ? :YES : :NO)\n}\n"}, {"source_code": "def func(a)\n a.map{|e| e.join.sub(/([o1]*)[o1]$/){|s|s=?o*$1.size+?o}.split('')}\nend\n\ndef func2(a)\n a.map{|e| e.join.sub(/(1+)o/){|s|s=?o*$1.size+?o}.split('')}\nend\n\ngets.to_i.times{\n n=gets.to_i\n a=(1..n).map{gets.chomp.chars}\n a=func(a)\n a=func(a.transpose)\n a=func2(a)\n a=func2(a.transpose)\n puts (a.flatten.none?{|e|e==?1} ? :YES : :NO)\n #a.map{|e|puts e.join}\n}\n"}, {"source_code": "def func(a)\n n=a.size\n q=[]\n (0...n).each do |i|\n if a[i][-1]==?1\n q << [i, n-1]\n elsif a[-1][i]==?1\n q << [n-1, i]\n end\n end\n\n while q[0]\n r, c=q.pop\n a[r][c]=?*\n [[0, -1], [-1, 0]].each do |dr, dc|\n nr=r+dr\n nc=c+dc\n next if nr<0 or nr>=n or nc<0 or nc>=n\n next if a[nr][nc]!=?1\n q << [nr, nc]\n end\n end\nend\n\n\n\ngets.to_i.times do\n n=gets.to_i\n a=(1..n).map{gets.chomp}\n func(a)\n\n puts (a.none?{|e|e[?1]} ? :YES : :NO)\n #a.map{|e|puts e}; puts\nend\n"}, {"source_code": "def func(a)\n n=a.size\n q=[]\n (0...n).each do |i|\n if a[i][-1]==?1\n q << [i, n-1]\n elsif a[-1][i]==?1\n q << [n-1, i]\n end\n end\n\n while q[0]\n r, c=q.shift\n a[r][c]=?*\n [[0, -1], [-1, 0]].each do |dr, dc|\n nr=r+dr\n nc=c+dc\n next if nr<0 or nr>=n or nc<0 or nc>=n\n next if a[nr][nc]!=?1\n q << [nr, nc]\n end\n end\nend\n\n\n\ngets.to_i.times do\n n=gets.to_i\n a=(1..n).map{gets.chomp}\n func(a)\n\n puts (a.none?{|e|e[?1]} ? :YES : :NO)\n #a.map{|e|puts e}; puts\nend\n"}, {"source_code": "def func(a)\n a.map{|e| e.join.sub(/([#1]*)[#1]$/){|s|s=?#*$1.size+?#}.split('')}\nend\n\ndef func2(a)\n a.map{|e| e.join.gsub(/(1+)#/){|s|s=?#*$1.size+?#}.split('')}\nend\n\ngets.to_i.times{\n n=gets.to_i\n a=(1..n).map{gets.chomp.chars}\n a=func(a)\n a=func(a.transpose)\n a=func2(a)\n a=func2(a.transpose)\n puts (a.flatten.none?{|e|e==?1} ? :YES : :NO)\n #a.map{|e|puts e.join}; puts\n}\n"}, {"source_code": "def func(a)\n a.map{|e| e.join.sub(/([#1]*)[#1]$/){|s|s=?#*$1.size+?#}.split('')}\nend\n\ndef func2(a)\n a.map{|e| e.join.gsub(/(1+)#/){|s|s=?#*$1.size+?#}.split('')}\nend\n\ngets.to_i.times{\n n=gets.to_i\n a=(1..n).map{gets.chomp.chars}\n a=func(a)\n a=func(a.transpose)\n b=[]\n while a!=b\n b=func2(a)\n b=func2(b.transpose)\n a=b.dup\n end\n puts (a.flatten.none?{|e|e==?1} ? :YES : :NO)\n #a.map{|e|puts e.join}; puts\n}\n"}], "src_uid": "eea15ff7e939bfcc7002cacbc8a1a3a5"} {"source_code": "n = gets.to_i\nif n.even?\n k = n/2\n puts k\n puts ([2] * k).join(\" \")\nelse\n k = 1\n n -= 3\n ps = [3]\n k += n/2\n ps << ([2] * (k-1))\n puts k\n puts ps.join(\" \")\nend", "positive_code": [{"source_code": "n=gets.to_i\nif n==3\n puts \"1\\n3\"\nelsif n.even?\n puts n/2\n puts ([2]*(n/2))*' '\nelse\n puts n/2\n puts (([2]*(n/2-1))<<3)*' '\nend\n"}, {"source_code": "n=gets.to_i;puts n/2,2+n%2,[2]*(n/2-1)"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i # n >= 2 and n <= 100_000\nwas_odd = n.odd?\nans_len = 0\nif was_odd\n ans_len += 1\n n -= 3\nend\n\nans_len += n / 2\n\nputs ans_len\nif was_odd\n print \"3 \"\nend\n(n/2).times {\n print \"2 \"\n}\nputs \"\""}, {"source_code": "class Memo\n attr_reader(:i)\n def initialize(i, state)\n @i =i\n @state = state\n end\n\n def yes!\n @state = true\n end\n\n def no!\n @state = false\n end\n\n def yes?\n @state\n end\n\n def to_s\n \"#{@i} => #{@state}\"\n end\nend\nclass Sieve\n attr_reader(:n)\n def initialize(n)\n @n = n\n @memo = Array.new(n + 100){|i| Memo.new(i, true)}\n @run = false\n end\n\n def run!\n return if @run\n @run = true\n @memo[0].yes!\n @memo[1].yes!\n @memo[2].yes!\n @memo.drop(2).each do |m|\n if(m.yes?)\n start = m.i * m.i\n start.step(@n + 1, m.i) do |i|\n @memo[i].no!\n end\n end\n end\n end\n\n def primes\n @primes ||= run!.select{|m| m.yes? }\n end\n\n def prime_values\n @prime_values ||= primes.map(&:i)\n end\n\n def get_data\n run!\n @memo\n end\nend\n\ndef main\n g = gets.strip.to_i\n n = g / 2\n puts n\n if(g % 2 == 0)\n puts Array.new(n){ 2 }.join(\" \")\n else\n x = Array.new(n - 1){ 2 }\n x << 3\n puts x.join(\" \")\n end\nend\n\nmain\n"}, {"source_code": "n = gets.chomp.to_i\n\nif n%2 == 0\n\tputs n/2\n\tprint \"2 \" * (n/2)\nelse\n\tif n == 3\n\t\tputs 1\n\t\tprint 3\n\telse\n\t\tputs n/2\n\t\tprint \"2 \" * ((n/2)-1)\n\t\tprint 3\n\tend\nend\n"}, {"source_code": "#!/usr/bin/env ruby\nn=gets.chomp.to_i\nif n&1==0 then\n puts \"#{n/2}\"\n (n/2).times do\n print \"2 \"\n end\nelse puts \"#{n/2 }\"\n print \"3 \"\n ((n/2)-1).times do\n print \"2 \"\n end\nend\n"}, {"source_code": "n = gets.to_i\nif n % 2 == 0 then\n\tputs n / 2\n\tputs \"2 \" * (n / 2 - 1) + \"2\"\nelse\n\tputs n / 2\n\tputs \"2 \" * (n / 2 - 1) + \"3\"\nend"}, {"source_code": "n = gets.to_i\nputs n / 2\nputs \"2 \" * (n / 2 - 1) + (n % 2 == 0 ? \"2\" : \"3\")"}, {"source_code": "n = gets.to_i\nputs(n/2)\nputs(n%2 == 0 ? \"2 \"*(n/2) : \"2 \"*((n-3)/2) + \"3\")\n"}, {"source_code": "n = gets.to_i\n\nresult = Array.new(n.div(2)-1, 2)\nresult << (n.even? ? 2 : 3)\n\nputs result.size\nputs result.join(' ')\n"}, {"source_code": "k = gets.chomp.to_i\nn = k / 2\nout = [\"2\"] * n \nif k.odd?\n\tout.pop\n\tout += [\"3\"] \nend\nputs out.size\nputs out.join(\" \")\n\n"}, {"source_code": "number = gets.strip.to_i\neven = false\n\neven = true if number % 2 == 0\n\nif even\n output = ''\n (number/2).times { output << '2 ' }\n puts number/2\n puts output.strip\nelse\n if number == 3\n puts 1\n puts number\n else\n balance = number - 3\n output = ''\n (balance/2).times { output << '2 ' }\n output << '3'\n puts(balance/2 + 1)\n puts output\n end\nend\n"}, {"source_code": "n=gets.to_i\np n/2\nputs [*[2]*(n/2-1),2+n%2]*' '"}, {"source_code": "n = gets.chomp.to_i\n\nans = []\nif n.even?\n ans = [2] * (n / 2)\nelse\n ans = [2] * (n / 2 - 1) + [3]\nend\nputs ans.length\nputs ans.join(\" \")\n"}, {"source_code": "n = gets.to_i\n\nif(n%2==0)\n puts n/2\n (n/2).times{print 2.to_s + \" \"}\nelse\n puts (n-1)/2\n ((n/2)-1).times{print 2.to_s + \" \"}\n print 3.to_s\n \n\n\n\nend"}, {"source_code": "n = gets.to_i\nans = n / 2\nputs ans\nif (n % 2 == 1)\n print 3, \" \"\n n -= 3\nend\n\n(0...n / 2).each do\n print 2, \" \"\nend"}, {"source_code": "given_number = gets.chomp.to_i\n\nk = given_number / 2\n\nmd = given_number % 2\nary = [2]\nif md == 1\n ary *= k - 1\n ary << 3\nelse\n ary *= k\nend\n\nputs k\nputs ary.join(' ')\n"}, {"source_code": "n = gets.to_i\n\nodd = n.odd?\nn -= 3 if odd\n\nputs (n/2 + (odd ? 1 : 0))\n\nputs ((n/2).times.map{\"2\"} + (odd ? [\"3\"] : [])).join(\" \")\n"}, {"source_code": "n = gets.to_i\ncount3 = n%2\ncount2 = n/2 - count3\nputs count2 + count3\n(1..count2).each do\n print 2, ' '\nend\nprint count3==1? 3 : ''\n"}, {"source_code": "require 'prime'\nrequire 'set'\na=[\"\",\"\",\"1\\n2\",\"1\\n3\",\"2\\n2 2\",\"2\\n2 3\"]\nn=gets.to_i\n\nif n<6 then\n\tputs a[n]\nelse\n\tif n%2==0 then\n\t\tputs n/2\n\t\t(n/2).times{|i|\n\t\t\tprint \" \" if i>0\n\t\t\tprint \"2\"\n\t\t}\n\t\tprint \"\\n\"\n\telse\n\t\td=n-3\n\t\tputs d/2+1\n\t\t(d/2).times{|i|\n\t\t\tprint \" \" if i>0\n\t\t\tprint \"2\"\n\t\t}\n\t\tprint \" 3\\n\"\n\tend\nend\n\n"}, {"source_code": "n=gets.to_i\nputs n/2\nputs \"2 \"*(n/2-1)+ (n%2==1 ? \"3\" : \"2\")\n\n"}, {"source_code": "n = gets.to_i\nif n%2 == 0\n print n/2, \"\\n\", \"2 \"*(n/2)\nelse\n print n/2, \"\\n\", \"2 \"*(n/2-1), \"3\"\nend\n"}], "negative_code": [{"source_code": "n = gets.to_i\n\nif (n % 2 == 1)\n print 3, \" \"\n n -= 3\nend\n\n(0...n / 2).each do\n print 2, \" \"\nend"}, {"source_code": "given_number = gets.chomp.to_i\n\nk = given_number / 2\n\nmd = given_number % 2\nary = [2]\nif md == 1\n ary *= k - 1\n ary << 3\nelse\n ary *= k\nend\n\nputs ary.join(' ')\n"}, {"source_code": "n = gets.to_i\ncount3 = n%2\ncount2 = n/2 - count3\n(1..count2).each do\n print 2, ' '\nend\nprint count3==1? 3 : ''\n"}, {"source_code": "require 'prime'\nrequire 'set'\na=[\"\",\"\",\"1\\n2\",\"1\\n3\",\"2\\n2 2\",\"2\\n2 3\"]\nx=Prime.each(10**5).to_a\ny=SortedSet.new(x)\nn=gets.to_i\n\nif n<6 then\n\tputs a[n]\nelsif y.member?(n) then\n\tputs \"1\\n#{n}\"\nelse\n\tok=false\n\tx.size.times{|i|\n\t\ti.upto(x.size-1){|j|\n\t\t\tt=n-x[i]-x[j]\n\t\t\tbreak if t 0\r\n s += @data[r]\r\n r ^= r & -r\r\n end\r\n s\r\n end\r\n end\r\nend\r\n\r\ngets.to_i.times do\r\n \r\nn = gets.to_i\r\na = gets.split.map!(&:to_i)\r\nb = gets.split.map!(&:to_i)\r\n\r\nft = AtCoder::FenwickTree.new(n)\r\ns = Array.new(n)\r\na.each_with_index do |ai, i|\r\n ai >>= 1\r\n s[ai] = i - ft.sum(0, ai)\r\n ft.add(ai, 1)\r\nend\r\nx = s[0]; s.map! { |si| x = (x < si) ? x : si }\r\nt = b.map.with_index do |bj, j|\r\n bj >>= 1\r\n bj -= 1\r\n j + s[bj]\r\nend\r\n\r\nputs t.min\r\n\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n a=gets.split.map(&:to_i).map{|x|x/2}\r\n b=gets.split.map(&:to_i).map{|x|x/2-1}\r\n l=[]\r\n i=0\r\n n.times do |j|\r\n while i<=b[j]\r\n l << j\r\n i+=1\r\n end\r\n end\r\n ans=2*n\r\n n.times do |j|\r\n if ans>j+l[a[j]]\r\n ans=j+l[a[j]]\r\n end\r\n end\r\n puts ans\r\nend\r\n"}], "negative_code": [{"source_code": "module AtCoder\r\n class FenwickTree\r\n def initialize(n = 0)\r\n @n = n\r\n @data = Array.new(n, 0).unshift(nil)\r\n end\r\n\r\n def add(idx, x)\r\n idx += 1\r\n while idx <= @n\r\n @data[idx] += x\r\n idx += idx & -idx\r\n end\r\n self\r\n end\r\n\r\n def sum(l, r)\r\n __sum__(r) - __sum__(l)\r\n end\r\n\r\n private\r\n\r\n def __sum__(r)\r\n s = 0\r\n while r > 0\r\n s += @data[r]\r\n r ^= r & -r\r\n end\r\n s\r\n end\r\n end\r\nend\r\n\r\ngets.to_i.times do\r\n \r\nn = gets.to_i\r\na = gets.split.map!(&:to_i)\r\nb = gets.split.map!(&:to_i)\r\n\r\nft = AtCoder::FenwickTree.new(n)\r\ns = Array.new(n)\r\na.each_with_index do |ai, i|\r\n ai >>= 1\r\n s[ai] = i - ft.sum(0, ai)\r\n ft.add(ai, 1)\r\nend\r\nt = b.map.with_index do |bj, j|\r\n bj >>= 1\r\n bj -= 1\r\n j + s[bj]\r\nend\r\n\r\nputs t.min\r\n\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n\r\nn = gets.to_i\r\na = gets.split.map!(&:to_i)\r\nb = gets.split.map!(&:to_i)\r\n\r\nb0 = b[0]\r\nc = a.index { |ai| ai < b0 }\r\n\r\nputs c\r\n\r\nend\r\n"}], "src_uid": "55a1e9236cac9a6044e74b1975331535"} {"source_code": "def solution(costs, questions)\n sorted_costs = costs.sort\n prefix_sorted_costs, prefix_costs = [0], [0]\n for i in 0...costs.size do\n prefix_sorted_costs << prefix_sorted_costs.last + sorted_costs[i]\n prefix_costs << prefix_costs.last + costs[i]\n end\n\n questions.each do |question|\n if question[0] == 1\n puts prefix_costs[question[2]] - prefix_costs[question[1]-1]\n else\n puts prefix_sorted_costs[question[2]] - prefix_sorted_costs[question[1]-1]\n end\n end\nend\n\n_ = gets\ncosts = gets.split.map(&:to_i)\nm = gets.to_i\nquestions = []\nm.times do \n questions << gets.split.map(&:to_i)\nend\n\nsolution(costs, questions)\n\n", "positive_code": [{"source_code": "n = gets\nstone = gets.split.map(&:to_i)\nsorted = stone.sort\nfor i in 1...stone.length\n stone[i] += stone[i-1]\n sorted[i] += sorted[i-1]\nend\nstone << 0\nsorted << 0\nq = gets.to_i\nfor i in 1..q\n a, b, c = gets.split.map(&:to_i)\n b -= 2\n c -= 1\n sum = 0\n if a == 1\n sum = stone[c]-stone[b]\n else\n sum = sorted[c]-sorted[b]\n end\n puts sum\nend\n"}, {"source_code": "n=gets\nstone=gets.split.map &:to_i\nsorted = stone.sort\nfor i in 1...stone.length\n stone[i] += stone[i-1]\n sorted[i] += sorted[i-1]\nend\nstone << 0\nsorted << 0\nq=gets.to_i\nfor i in 1..q\n a,b,c = gets.split.map &:to_i\n b-=2\n c-=1\n sum=0\n if a==1\n sum=stone[c]-stone[b]\n else\n sum=sorted[c]-sorted[b]\n end\n puts sum\n\nend"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ = $0\n# end\n\n# Kuriyama Mirai? <\ud53c\ub9bc\uc774: \uc774\ubb54\uc539...>\n\nn = gets.to_i\nv = gets.split.map(&:to_i) # stones\ntemp = 0\nsv = [0] + v.map { |i|\n temp += i\n temp\n}\nov = [0] + v.sort # ordered\ntemp = 0\nov = ov.map { |i|\n temp += i\n temp\n}\n#p sv\n#p ov\nquestions = gets.to_i\nquestions.times {\n type, l, r = gets.split.map(&:to_i)\n if type == 1\n puts sv[r] - sv[l-1]\n else\n puts ov[r] - ov[l-1]\n end\n}"}, {"source_code": "n = gets.to_i\nv = [0] + gets.split.collect{|i| i.to_i}\nu = v.sort\n(1..n).each do |i|\n v[i] += v[i-1]\n u[i] += u[i-1]\nend\nm = gets.to_i\n(0...m).each do\n type, l, r = gets.split.collect{|i| i.to_i}\n if type == 1\n puts v[r]-v[l-1]\n else\n puts u[r]-u[l-1]\n end\nend\n"}, {"source_code": "# 433B\n\ndef read_line\n gets.chomp.split.map &:to_i\nend\n\nn = gets.to_i\na = read_line\nb = a.sort\nsums = [nil, Array.new(n), Array.new(n)]\nsums[1][0] = a[0]\nsums[2][0] = b[0]\n(1...n).each do |i|\n sums[1][i] = sums[1][i - 1] + a[i]\n sums[2][i] = sums[2][i - 1] + b[i]\nend\ngets.to_i.times do\n type, l, r = read_line\n puts sums[type][r - 1] - (l > 1 ? sums[type][l - 2] : 0)\nend"}, {"source_code": "n = gets.to_i\nv = [0] + gets.split.collect{|i| i.to_i}\nu = v.sort\n(1..n).each do |i|\n\tv[i] += v[i - 1]\n\tu[i] += u[i - 1]\nend\nm = gets.to_i\n(0...m).each do\n\tt, left, right = gets.split.collect{|i| i.to_i}\n\tif 1 == t \n\t\tputs v[right]-v[left - 1]\n\telse \n\t\tputs u[right]-u[left - 1]\n\tend\nend\n"}], "negative_code": [], "src_uid": "c764b9f87cb5e5872eb157c3d2b7f3c5"} {"source_code": "\t\n\nn = gets.chomp.to_i\n\narr = gets.split(\" \")\n\narr = arr.map { |element| element.to_i }\n\nsum = arr.inject(0){|sum,x| sum + x }\n\nsorted = arr.sort.reverse\n\nanswer = []\n\narr.each_with_index do |element,i|\n\n\tif element == sorted[0]\n\t\tmx = sorted[1]\n\telse\n\t\tmx = sorted[0]\n\tend\n\tanswer<<(i+1) if sum - mx - element == mx\n\nend\n\n\n\nputs answer.length\nputs answer.join(' ')", "positive_code": [{"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\nsum = a.inject(:+)\nsorted = a.sort.reverse\nnice = []\na.each_with_index do |e, i|\n mx = e == sorted.first ? sorted[1] : sorted.first\n nice << (i + 1) if (sum - e) - mx == mx\nend\nputs nice.size\nputs nice.join(' ')"}], "negative_code": [{"source_code": "\t\nn = gets.chomp.to_i\n\narr = gets.split(\" \")\narr = arr.map { |element| element.to_i }\n\nsum = arr.inject(0){|sum,x| sum + x }\nmax = arr.max\nnums = []\n\ntemp = arr.uniq\ntemp.each_with_index do |element,i| \n\tnums<<[sum-2*element,i]\nend\n\n\nnums.delete_if { |x| x[0] > max || x[0] < 1 }\nnums = nums.uniq\nanswer = []\n\n\nnums.each do |element|\n\ttemp_arr = arr.each_index.select { |i| arr[i] == element[0] && i!=element[1] }.compact\n\tanswer.concat(temp_arr)\nend\n\nanswer = answer.uniq\n\nputs answer.length\nanswer.each { |x| print (x+1).to_s+\" \"}"}, {"source_code": "n = gets.chomp.to_i\n\narr = gets.split(\" \")\narr = arr.map { |element| element.to_i }\nsum = arr.inject(0){|sum,x| sum + x }\nmax = arr.max\nnums = []\narr.each do |element| \n\tnums< max || x < 1 }\nnums = nums.uniq\nanswer = []\nnums.each do |element|\n\ttemp_arr = arr.each_index.select { |i| arr[i] == element}.compact\n\tanswer.concat(temp_arr)\nend\n\nanswer = answer.uniq\n\n\nputs answer.length\nanswer.each { |x| print (x+1).to_s+\" \"}"}], "src_uid": "4cf0fe49f7ebf058317ac848043031a5"} {"source_code": "n=gets.to_i\np n-1\nc=[0]*100020\nz=[]\n1.upto(n-1){|i|\n\tx,y=gets.split.map &:to_i\n\tprint \"2 \"+$_\n\tif c[x]==0\n\t\tc[x]=i\n\telse\n\t\tz<<[i,c[x]]*' '\n\tend\n\tif c[y]==0\n\t\tc[y]=i\n\telse\n\t\tz<<[i,c[y]]*' '\n\tend\n}\nputs z*\"\\n\"\n", "positive_code": [{"source_code": "n=gets.to_i\np n-1\nc=[0]*100020\nz=[]\n1.upto(n-1){|i|\n\tx,y=gets.split.map &:to_i\n\tprint \"2 \"+$_\n\tif c[x]==0\n\t\tc[x]=i\n\telse\n\t\tz<<[i,c[x]]*' '\n\tend\n\tif c[y]==0\n\t\tc[y]=i\n\telse\n\t\tz<<[i,c[y]]*' '\n\tend\n}\nputs z*\"\\n\"\n"}, {"source_code": "n=gets.to_i\np n-1\nc=[0]*100020\nz=[]\n1.upto(n-1){|i|\n\tx,y=gets.split.map &:to_i\n\tprint \"2 \"+$_\n\tif c[x]==0\n\t\tc[x]=i\n\telse\n\t\tz<<[i,c[x]]*' '\n\tend\n\tif c[y]==0\n\t\tc[y]=i\n\telse\n\t\tz<<[i,c[y]]*' '\n\tend\n}\nputs z*\"\\n\"\n"}, {"source_code": "n=gets.to_i\np n-1\nc=[0]*100020\nz=[]\n1.upto(n-1){|i|\n\tx,y=gets.split.map &:to_i\n\tprint \"2 \"+$_\n\tif c[x]==0\n\t\tc[x]=i\n\telse\n\t\tz<<[i,c[x]]*' '\n\tend\n\tif c[y]==0\n\t\tc[y]=i\n\telse\n\t\tz<<[i,c[y]]*' '\n\tend\n}\nputs z*\"\\n\"\n"}, {"source_code": "n=gets.to_i\np n-1\nc=[0]*100020\nz=[]\n1.upto(n-1){|i|\n\tx,y=gets.split.map &:to_i\n\tprint \"2 \"+$_\n\tif c[x]==0\n\t\tc[x]=i\n\telse\n\t\tz<<[i,c[x]]*' '\n\tend\n\tif c[y]==0\n\t\tc[y]=i\n\telse\n\t\tz<<[i,c[y]]*' '\n\tend\n}\nputs z*\"\\n\"\n"}, {"source_code": "n=gets.to_i\np n-1\nc=[0]*100020\nz=[]\n1.upto(n-1){|i|\n\tx,y=gets.split.map &:to_i\n\tprint \"2 \"+$_\n\tif c[x]==0\n\t\tc[x]=i\n\telse\n\t\tz<<[i,c[x]]*' '\n\tend\n\tif c[y]==0\n\t\tc[y]=i\n\telse\n\t\tz<<[i,c[y]]*' '\n\tend\n}\nputs z*\"\\n\"\n"}, {"source_code": "n=gets.to_i\np n-1\nc=[0]*100020\nz=[]\n1.upto(n-1){|i|\n\tx,y=gets.split.map &:to_i\n\tprint \"2 \"+$_\n\tif c[x]==0\n\t\tc[x]=i\n\telse\n\t\tz<<[i,c[x]]*' '\n\tend\n\tif c[y]==0\n\t\tc[y]=i\n\telse\n\t\tz<<[i,c[y]]*' '\n\tend\n}\nputs z*\"\\n\""}, {"source_code": "n=gets.to_i\np n-1\nc=[0]*100020\nz=[]\n1.upto(n-1){|i|\n\tx,y=gets.split.map &:to_i\n\tprint \"2 \"+$_\n\tif c[x]==0\n\t\tc[x]=i\n\telse\n\t\tz<<[i,c[x]]*' '\n\tend\n\tif c[y]==0\n\t\tc[y]=i\n\telse\n\t\tz<<[i,c[y]]*' '\n\tend\n}\nputs z*\"\\n\"\n"}, {"source_code": "n=gets.to_i\np n-1\nc=[0]*100020\nz=[]\n1.upto(n-1){|i|\n\tx,y=gets.split.map &:to_i\n\tprint \"2 \"+$_\n\tif c[x]==0\n\t\tc[x]=i\n\telse\n\t\tz<<[i,c[x]]*' '\n\tend\n\tif c[y]==0\n\t\tc[y]=i\n\telse\n\t\tz<<[i,c[y]]*' '\n\tend\n}\nputs z*\"\\n\"\n"}], "negative_code": [], "src_uid": "79074958bd8017988308ff4e37bca163"} {"source_code": "X = gets.to_i\n\ndef check(x)\n ans = []\n\n if x[0] == 0\n x += 1\n ans << 0\n end\n\n loop do\n flg = false\n l = x.to_s(2).size\n ml = 0\n\n (0...l).each do |i|\n if x[i] == 0\n ml = i + 1\n flg = true\n end\n end\n\n if flg\n mask = ('1' * ml).to_i(2)\n ans << ml\n\n x ^= mask\n x += 1\n else\n break\n end\n end\n\n ans\nend\n\nans = check(X)\n\nif ans.empty?\n puts 0\nelse\n puts ans.size * 2\n puts ans.join(' ')\nend\n", "positive_code": [{"source_code": "def check(x,n,a,b)\n f = true\n for i in 0..n\n f = false if x[i] == 0\n end\n if f\n if b.empty?\n puts 0\n else\n puts a\n puts b.join(\" \")\n end\n exit\n end\nend\n\nx = gets.to_i\na = 0\nb = []\nn = Math.log2(x).floor\nwhile 1\n check(x,n,a,b)\n a += 1\n n.downto(0) do |i|\n if x[i] == 0\n x ^= ((1<<(i+1))-1)\n b << i+1\n check(x,n,a,b)\n break\n end\n end\n a += 1\n x += 1\n check(x,n,a,b)\nend"}], "negative_code": [], "src_uid": "2510469c09d7d145078e65de81640ddc"} {"source_code": "w,h = gets.strip.split(\" \").map(&:to_i)\n\nmatrix = Array.new\n\nh.times do |k|\n matrix[k] = gets.strip.split(\"\")\nend\n\nmatrix = matrix.transpose\n\n(2*w).times do |i|\n m = (i/2.0).floor\n (2*h).times do |j|\n k = (j/2.0).floor\n print matrix[m][k]\n end\n print \"\\n\"\nend", "positive_code": [{"source_code": "# http://codeforces.ru/contest/523/problem/A\n\ndef img_to_s image\n image.map(&:join).join(\"\\n\")\nend\n\ninitial = ARGF.read.split(\"\\n\")\n\nimage = initial[1..-1].map(&:chars)\n\n# flip 90 degrees\n\nimage = image.transpose\n\n# mirror\n\nimage = image.map { |i| i.map(&:reverse) }\n\n# scaling\n\nimage = image.reduce([]) do |res, r|\n scaled = r.reduce([]) { |i_res, c| i_res << c; i_res << c; i_res }\n res << scaled\n res << scaled\nend\n\nputs img_to_s(image)"}, {"source_code": "(w, h) = gets.scan(/\\d+/).map(&:to_i)\ns = []\nh.times do\n s << gets\nend\nw.times do |i|\n 2.times do\n h.times do |j|\n print s[j][i], s[j][i]\n end\n print \"\\n\"\n end\nend"}, {"source_code": "_, h = gets.split.map(&:to_i)\na = []\nh.times do\n a << gets.chomp.split(//)\nend\na = a.transpose.map { |x| x.zip(x).flatten }\nputs a.zip(a).flatten(1).map(&:join)\n"}, {"source_code": "a,b = gets.split.map{|x| x.to_i}\nc = []\nb.times do |x|\n c[x] = gets.chomp.split('')\nend\n\nfor i in 0...2*a\n for j in 0...2*b\n print(\"#{c[j/2][i/2]}\")\n end\n puts\nend\n"}], "negative_code": [{"source_code": "initial_num = ARGF.read\n\nresult = ''\n\ninitial_num.chars.each_with_index do |c, index|\n\ti = c.to_i\n\tif i >= 5\n\t\tif i == 9 and index == 0\n\t\t\tresult << c\n\t\telse\n\t\t\tresult << (9-i).to_s\n\t\tend\n\telse\n\t\tresult << c\n\tend\nend\n\nputs result"}], "src_uid": "9af19e1b482f7f0bcbffc754cf324092"} {"source_code": "n, c, s, r = gets, Hash.new(0), 0, 0\ngets.split.map(&:to_i).each_with_index {|a, i|\n r += a * i - s - c[a - 1] + c[a + 1]\n c[a] += 1\n s += a\n}\np r", "positive_code": [{"source_code": "# cook your code here\n\nn = gets.to_i \n\nnums = gets.split.map{ |x| x.to_i } \n\nnumap = Hash.new(0) \nsum = 0\n\nfor i in 0...n \n sum += nums[i]\n numap[nums[i]] += 1 \nend \n\nminsum=0 \ngreatsum=0 \n=begin\nfor i in 0...n \n puts i\n #puts nums[i] \n puts numap[nums[i]]\nend \n=end \nfor i in 0...n \n sum -= nums[i] \n minsum = sum - (n-1-i)*nums[i] - numap[nums[i]+1] + numap[nums[i]-1] \n greatsum += minsum \n numap[nums[i]] -= 1 \n # puts (i+1).to_s + \" \" + nums[i].to_s + \" \" + sum.to_s + \" \" + minsum.to_s + \" \" + greatsum.to_s \nend \n\nputs greatsum"}, {"source_code": "N = gets.to_i\nA = gets.split.map(&:to_i)\n\nsum, ans = 0, 0\nmp = Hash.new(0)\nN.times do |i|\n res = sum\n num = i\n ((A[i]-1)..(A[i]+1)).each do |v|\n res -= v*mp[v]\n num -= mp[v]\n end\n ans += num*A[i] - res\n sum += A[i]\n mp[A[i]] += 1\nend\nputs ans"}, {"source_code": "N = $stdin.gets.chomp.to_i\narr = $stdin.gets.chomp.split(\" \").map{ |a| a.to_i }.reverse\nnod = {}\n#p arr\n\nans = 0\ns = 0\narr.each_with_index do |a, i|\n ans += (s - (a*i)) - ((nod[a-1] || 0) * (a-1 - a) + (nod[a+1] || 0) * (a+1 - a))\n s += a\n nod[a] = (nod[a] || 0) + 1\nend\nputs ans\n"}, {"source_code": "#!/usr/bin/env ruby\n# encoding: utf-8\n\nn = gets.to_i\nsum = 0\nans = 0\nary = gets.split.map(&:to_i)\nhash = {}\nary.each do |v|\n sum += v\n hash[v] = hash[v].nil? ? 1 : hash[v] + 1\nend\nary.each do |v|\n sum -= v\n n -= 1\n ans += (sum - n * v)\n hash[v] -= 1\n ans += hash[v - 1] unless hash[v - 1].nil?\n ans -= hash[v + 1] unless hash[v + 1].nil?\nend\nputs ans\n"}], "negative_code": [], "src_uid": "c7cca8c6524991da6ea1b423a8182d24"} {"source_code": "t = gets.to_i\n\nt.times do\n ln = gets.chomp\n if ln.downcase == \"yes\"\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n", "positive_code": [{"source_code": " gets.to_i.times { puts gets.chomp.upcase == \"YES\" ? \"YES\" : \"NO\" } "}, {"source_code": "max_iterates = gets.to_i\nresult = []\nfor i in 1..max_iterates do\n val = gets.chomp.downcase == \"yes\" ? \"YES\" : \"NO\"\n result << val\nend\n\nresult.each { |str| puts str }\n\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\nnumtests=gets.to_i\ni=0\n(1..numtests).each do |i|\n l=gets.chomp\n if !l.nil? && l.downcase == \"yes\"\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\n"}, {"source_code": "n = gets.chomp.to_i\ninputs = []\n(0..n-1).each do |i|\n inputs.push(gets.chomp)\nend\ninputs.each do |i|\n if i.downcase == \"yes\"\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n"}], "negative_code": [], "src_uid": "4c0b0cb8a11cb1fd40fef47616987029"} {"source_code": "def solve\n \n n , m = readline.split(' ')\n n = n.to_i; m = m.to_i\n \n s = Array.new; h = Hash.new(0)\n \n n.times {\n s << gets\n }\n \n s_ = s.dup\n \n (0...n).each{|x|\n s_[x] = s[x].dup\n }\n \n \n (0...n).each{|x|\n \n h.clear\n \n (0...m).each{|y|\n h[s[x][y]] += 1\n }\n \n (0...m).each{|y|\n s_[x][y] = '_' if (h[s[x][y]] > 1) \n }\n \n }\n \n \n (0...m).each{|y|\n \n h.clear\n \n (0...n).each{|x|\n h[s[x][y]] += 1\n }\n \n (0...n).each{|x|\n s_[x][y] = '_' if (h[s[x][y]] > 1) \n }\n \n }\n \n res = String.new\n \n (0...n).each{|x|\n (0...m).each{|y|\n res = res + s_[x][y].chr if (s_[x][y] != '_')\n }\n }\n \n return res\n \nend\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve", "positive_code": [{"source_code": "n,m=gets.split.map(&:to_i)\nc=n.times.map{gets.chomp.bytes.to_a}\nd=c.transpose\nn.times{|i|m.times{|j|_=c[i][j];putc _ if c[i].count(_)<2&&d[j].count(_)<2}}\n"}, {"source_code": "n, m = $stdin.readline.split(\" \").collect { |i| i.to_i }\narr = []\nfor i in 0...n\n\tarr << $stdin.readline.chomp\nend\ntmph = Hash.new(0)\narr.each do |s|\n\tfor i in 0...m\n\t\ts[i] = s[i].upcase if tmph[s[i]] > 1\n\t\ttmph[s[i].downcase] += 1\n\tend\n\tfor i in 0...m\n\t\ts[i] = s[i].upcase if tmph[s[i]] > 1\n\tend\n\ttmph = Hash.new(0)\nend\nfor i in 0...m\n\tarr.each do |s|\n\t\ts[i] = s[i].upcase if tmph[s[i].downcase] > 1\n\t\ttmph[s[i].downcase] += 1 \n\tend\n\tarr.each do |s|\n\t\ts[i] = s[i].upcase if tmph[s[i].downcase] > 1\n\tend\n\ttmph = Hash.new(0)\nend\narr.each do |s|\n\tfor i in 0...m\n\t\tprint s[i] if s[i] == s[i].downcase\n\tend\nend\nputs \"\\n\"\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nR, C = [n, m].map { |i| Array.new(i) { Hash.new { |hash,key| hash[key] = 0 } } }\nF = Array.new\n(0...n).each do |r|\n t = gets.chomp\n (0...m).each do |c|\n R[r][t[c]] += 1\n C[c][t[c]] += 1\n end\n F << t\nend\nret = \"\"\n(0...n).each do |r|\n (0...m).each do |c|\n ret += F[r][c] if R[r][F[r][c]] + C[c][F[r][c]] <= 2\n end\nend\n\nputs ret\n"}, {"source_code": "#Fuck U Codeforces :D\nn,m=gets.split.map(&:to_i)\nc=n.times.map{gets.chomp.bytes.to_a}\nd=c.transpose\nn.times{|i|m.times{|j|_=c[i][j];putc _ if c[i].count(_)<2&&d[j].count(_)<2}}\n#Expected to be acc.\n#YARAAAAAAB"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=n.times.map{gets.chomp.bytes.to_a}\nd=c.transpose\nn.times{|i|m.times{|j|_=c[i][j];putc _ if c[i].count(_)<2&&d[j].count(_)<2}}"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=n.times.map{gets.chomp.bytes.to_a}\nd=c.transpose\nn.times{|i|m.times{|j|_=c[i][j];putc _ if c[i].count(_)<2&&d[j].count(_)<2}}\n"}, {"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\nbd = Array.new(n)\nbdf = Array.new(n)\nfor i in 0..n-1\n\tbd[i] = gets.chomp.split(//)\n\tbdf[i] = Array.new(m)\nend\n\nfor i in 0..n-1\n\tfor j in 0..m-1\n\t\tbdf[i][j] = true\n\tend\nend\n\nfor i in 0..n-1\n\th = Hash.new\n\tfor j in 0..m-1\n\t\tif h.key?(bd[i][j])\n\t\t\th[bd[i][j]] += 1\n\t\telse\n\t\t\th[bd[i][j]] = 1\n\t\tend\n\tend\n\tfor j in 0..m-1\n\t\tbdf[i][j] = false if h[bd[i][j]] > 1\n\tend\nend\n\nfor j in 0..m-1\n\th = Hash.new\n\tfor i in 0..n-1\n\t\tif h.key?(bd[i][j])\n\t\t\th[bd[i][j]] += 1\n\t\telse\n\t\t\th[bd[i][j]] = 1\n\t\tend\n\tend\n\tfor i in 0..n-1\n\t\tbdf[i][j] = false if h[bd[i][j]] > 1\n\tend\nend\n\nfor i in 0..n-1\n\tfor j in 0..m-1\n\t\tprint bd[i][j] if bdf[i][j] == true\n\tend\nend\n\nputs \"\"\n"}, {"source_code": "w=gets.to_i\nm=[]\nw.times{\n m.push(gets.split[0])\n}\nh=m[0].length\nans=\"\"\nw.times{|i|\n h.times{|j|\n ok=1\n w.times{|x|\n if i!=x && m[i][j]==m[x][j] then\n ok=0\n break\n end\n }\n h.times{|y|\n if j!=y && m[i][j]==m[i][y] then\n ok=0\n break\n end\n }\n if ok==1 then\n ans+=m[i][j]\n end\n }\n}\nputs ans"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=n.times.map{gets.chomp.bytes.to_a}\nd=c.transpose\nn.times{|i|m.times{|j|_=c[i][j];putc _ if c[i].count(_)<2&&d[j].count(_)<2}}\n"}, {"source_code": "#!/usr/bin/env ruby\n#$DEBUG = true\n#$stdin = File.open '2.test' if $DEBUG\nn, m = gets.split.map(&:to_i)\nchars = [].tap{|chars| n.times{chars << gets.chomp.split(\"\") } }\n26.times { |c| \n c = (c+97).chr \n 2.times {\n chars.each {|line|\n line.map!{|ci| ci == c ? \"\" : ci } if line.select{ |ci| ci == c || ci == \"\" }.size > 1\n }\n chars = chars.transpose\n }\n chars.each {|line| line.map!{|ci| ci == \"\" ? nil : ci } }\n}\nputs chars.flatten.compact.join\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=n.times.map{gets.chomp.bytes.to_a}\nd=c.transpose\nn.times{|i|m.times{|j|_=c[i][j];putc _ if c[i].count(_)<2&&d[j].count(_)<2}}\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=n.times.map{gets.chomp.bytes.to_a}\nd=c.transpose\nn.times{|i|m.times{|j|_=c[i][j];putc _ if c[i].count(_)<2&&d[j].count(_)<2}}"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=n.times.map{gets.chomp.bytes.to_a}\nd=c.transpose\nn.times{|i|m.times{|j|_=c[i][j];putc _ if c[i].count(_)<2&&d[j].count(_)<2}}\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=n.times.map{gets.chomp.bytes.to_a}\nd=c.transpose\nn.times{|i|m.times{|j|_=c[i][j];putc _ if c[i].count(_)<2&&d[j].count(_)<2}}\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nc=n.times.map{gets.chomp.bytes.to_a}\nd=c.transpose\nn.times{|i|m.times{|j|_=c[i][j];putc _ if c[i].count(_)<2&&d[j].count(_)<2}}"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\nrequire 'prime'\nrequire 'mathn'\n#=================================\n\nn,m=gets.split.map(&:to_i)\n\nboard_main=[]\nboard_copy=[]\nn.times{\n\tline = gets.strip.split(//)\n\tboard_main << line\n\tboard_copy << line.dup\n}\n\nfor i in 0...n\n\tfor j in 0...m\n\t\tch = board_main[i][j]\n\t\t\n\t\t# rows\n\t\tcount=0\n\t\tfor row_index in 0...n\n\t\t\tcount+=1 if board_main[row_index][j]==ch\n\t\tend\n\t\t\n\t\tif count!=1\n\t\t\tfor row_index in 0...n\n\t\t\t\tboard_copy[row_index][j]=\"\" if board_main[row_index][j]==ch\n\t\t\tend\n\t\tend\n\t\t\n\t\t# cols\n\t\tcount=0\n\t\tfor col_index in 0...m\n\t\t\tcount+=1 if board_main[i][col_index]==ch\n\t\tend\n\t\t\n\t\tif count!=1\n\t\t\tfor col_index in 0...m\n\t\t\t\tboard_copy[i][col_index]=\"\" if board_main[i][col_index]==ch\n\t\t\tend\n\t\tend\n\tend\nend\n\nfor i in 0...n\n\tfor j in 0...m\n\t\tprint board_copy[i][j]\n\tend\nend\n"}], "negative_code": [{"source_code": "def solve\n \n n , m = readline.split(' ')\n n = n.to_i; m = m.to_i\n\n s = Array.new; h = Hash.new\n \n n.times {\n s << gets\n }\n \n s_ = s.dup\n=begin \n (0...n).each{|x|\n s_[x] = s[x].dup\n }\n \n \n (0...n).each{|x|\n \n h = Hash.new\n \n (0...m).each{|y|\n h[s[x][y].chr] += 1\n }\n \n (0...m).each{|y|\n s_[x][y] = 0 if (h[s[x][y].chr] > 1) \n }\n \n }\n \n \n (0...m).each{|y|\n \n h = Hash.new\n \n (0...n).each{|x|\n h[s[x][y].chr] += 1\n }\n \n (0...n).each{|x|\n s_[x][y] = 0 if (h[s[x][y].chr] > 1) \n }\n \n }\n=end \n res = String.new\n \n (0...n).each{|x|\n (0...m).each{|y|\n res = res + s_[x][y].chr if (s_[x][y] != 0)\n }\n }\n \n return res\n\nend\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "def solve\n \n n , m = readline.split(' ')\n n = n.to_i; m = m.to_i\n \n s = Array.new; h = Hash.new(0)\n \n n.times {\n s << gets\n }\n \n s_ = s.dup\n \n (0...n).each{|x|\n s_[x] = s[x].dup\n }\n \n \n (0...n).each{|x|\n \n h.clear\n \n (0...m).each{|y|\n h[s[x][y]] += 1\n }\n \n (0...m).each{|y|\n # s_[x][y] = 0 if (h[s[x][y]] > 1) \n }\n \n }\n \n \n (0...m).each{|y|\n \n h.clear\n \n (0...n).each{|x|\n h[s[x][y]] += 1\n }\n \n (0...n).each{|x|\n # s_[x][y] = 0 if (h[s[x][y]] > 1) \n }\n \n }\n \n res = String.new\n \n (0...n).each{|x|\n (0...m).each{|y|\n res = res + s_[x][y].chr if (s_[x][y] != 0)\n }\n }\n \n return res\n \nend\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "def solve\n \n n , m = readline.split(' ')\n n = n.to_i; m = m.to_i\n \n s = Array.new; h = Hash.new(0)\n \n n.times {\n s << gets\n }\n \n s_ = s.dup\n \n (0...n).each{|x|\n s_[x] = s[x].dup\n }\n \n \n (0...n).each{|x|\n \n h.clear\n \n (0...m).each{|y|\n # h[s[x][y].chr] += 1\n }\n \n (0...m).each{|y|\n # s_[x][y] = 0 if (h[s[x][y].chr] > 1) \n }\n \n }\n \n \n (0...m).each{|y|\n \n h.clear\n \n (0...n).each{|x|\n # h[s[x][y].chr] += 1\n }\n \n (0...n).each{|x|\n # s_[x][y] = 0 if (h[s[x][y].chr] > 1) \n }\n \n }\n \n res = String.new\n \n (0...n).each{|x|\n (0...m).each{|y|\n res = res + s_[x][y].chr if (s_[x][y] != 0)\n }\n }\n \n return res\n \nend\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "def solve\n \n n , m = readline.split(' ')\n n = n.to_i; m = m.to_i\n\n s = Array.new; h = Hash.new\n \n n.times {\n s << gets\n }\n \n s_ = s.dup\n \n (0...n).each{|x|\n s_[x] = s[x].dup\n }\n \n\n=begin\n (0...n).each{|x|\n \n h = Hash.new\n \n (0...m).each{|y|\n h[s[x][y].chr] += 1\n }\n \n (0...m).each{|y|\n s_[x][y] = 0 if (h[s[x][y].chr] > 1) \n }\n \n }\n \n \n (0...m).each{|y|\n \n h = Hash.new\n \n (0...n).each{|x|\n h[s[x][y].chr] += 1\n }\n \n (0...n).each{|x|\n s_[x][y] = 0 if (h[s[x][y].chr] > 1) \n }\n \n }\n=end \n res = String.new\n \n (0...n).each{|x|\n (0...m).each{|y|\n res = res + s_[x][y].chr if (s_[x][y] != 0)\n }\n }\n \n return res\n\nend\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "def solve\n \n a , b = readline.split(' ')\n a = a.to_i; b = b.to_i\n \n x = 0; sa = 0; sb = 0\n \n while true do\n t = a - x % a; w = b - x % b;\n break if (t == a && w == b && x > 0)\n \n if (t < w || t == w && a > b) then\n sa += t; x += t\n else\n sb += w; x += w;\n end\n end\n \n return 'Dasha' if (sa > sb)\n return 'Masha' if (sa < sb)\n return 'Equal'\n end\n \n #$stdin = File.open(\"in.txt\", \"r\")\n puts solve"}, {"source_code": "def solve\n \n n , m = readline.split(' ')\n n = n.to_i; m = m.to_i\n \n s = Array.new; h = Hash.new(0)\n \n n.times {\n s << gets\n }\n \n s_ = s.dup\n \n (0...n).each{|x|\n s_[x] = s[x].dup\n }\n \n \n (0...n).each{|x|\n \n h.clear\n \n (0...m).each{|y|\n # h[(s[x][y].chr)] += 1\n }\n \n (0...m).each{|y|\n s_[x][y] = 0 if (h[s[x][y].chr] > 1) \n }\n \n }\n \n \n (0...m).each{|y|\n \n h.clear\n \n (0...n).each{|x|\n # h[(s[x][y].chr)] += 1\n }\n \n (0...n).each{|x|\n s_[x][y] = 0 if (h[s[x][y].chr] > 1) \n }\n \n }\n \n res = String.new\n \n (0...n).each{|x|\n (0...m).each{|y|\n res = res + s_[x][y].chr if (s_[x][y] != 0)\n }\n }\n \n return res\n \nend\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "#=================================\n# Better be sure than sorry. \n#=================================\n$stdin=File.open(\"./input.txt\",\"r\") if ENV[\"LOGNAME\"]==\"skydos\"\nrequire 'prime'\nrequire 'mathn'\n#=================================\n\nn,m=gets.split.map(&:to_i)\n\nboard_main=[]\nboard_copy=[]\nn.times{\n\tline = gets.strip.split(//)\n\tboard_main << line\n\tboard_copy << line.dup\n}\n\nfor i in 0...n\n\tfor j in 0...m\n\t\tch = board_main[i][j]\n\t\t\n\t\t# rows\n\t\tcount=0\n\t\tfor row_index in 0...n\n\t\t\tcount+=1 if board_main[row_index][j]==ch\n\t\tend\n\t\t\n\t\tif count!=1\n\t\t\tfor row_index in 0...n\n\t\t\t\tboard_copy[row_index][j]=\"_\" if board_main[row_index][j]==ch\n\t\t\tend\n\t\tend\n\t\t\n\t\t# cols\n\t\tcount=0\n\t\tfor col_index in 0...m\n\t\t\tcount+=1 if board_main[i][col_index]==ch\n\t\tend\n\t\t\n\t\tif count!=1\n\t\t\tfor col_index in 0...m\n\t\t\t\tboard_copy[i][col_index]=\"_\" if board_main[i][col_index]==ch\n\t\t\tend\n\t\tend\n\tend\nend\n\nfor i in 0...n\n\tfor j in 0...m\n\t\tprint board_copy[i][j]\n\tend\n\tputs\nend\n"}, {"source_code": "n, m = $stdin.readline.split(\" \").collect { |i| i.to_i }\narr = []\nfor i in 0...n\n\tarr << $stdin.readline.chomp\nend\np arr\ntmph = Hash.new(0)\narr.each do |s|\n\tfor i in 0...m\n\t\ts[i] = s[i].upcase if tmph[s[i]] > 1\n\t\ttmph[s[i].downcase] += 1\n\tend\n\tfor i in 0...m\n\t\ts[i] = s[i].upcase if tmph[s[i]] > 1\n\tend\n\ttmph = Hash.new(0)\nend\nfor i in 0...m\n\tarr.each do |s|\n\t\ts[i] = s[i].upcase if tmph[s[i].downcase] > 1\n\t\ttmph[s[i].downcase] += 1 \n\tend\n\tarr.each do |s|\n\t\ts[i] = s[i].upcase if tmph[s[i].downcase] > 1\n\tend\n\ttmph = Hash.new(0)\nend\narr.each do |s|\n\tfor i in 0...m\n\t\tprint s[i] if s[i] == s[i].downcase\n\tend\nend\nputs \"\\n\"\n"}], "src_uid": "9c90974a0bb860a5e180760042fd5045"} {"source_code": "class A\n def initialize\n n, k = gets.chomp.split(' ').map(&:to_i)\n answer = 0\n\n n.times do\n check_list = Hash.new\n flag = true\n num = gets.chomp.split('').map(&:to_i).sort.uniq\n\n num.each do |val|\n check_list[val] = true if val <= k\n end\n\n answer += 1 if check_list.size == (k+1) && flag\n end\n\n puts answer\n end\nend\n\na = A.new", "positive_code": [{"source_code": "n,k=gets.split.map &:to_i;p=(0..k).to_a.map &:to_s;q=p.length;p (((1..n).map{|i|((p&(gets.strip.split(''))).length >= q)?1:0}).count(1))\n"}, {"source_code": "input = gets.chomp\nnums = input.split\nn = Integer(nums[0])\nk = Integer(nums[1])\na = Array.new\nfor i in 0...n\n input = gets.chomp\n a[i] = Array.new\n for j in 0...input.length\n a[i][j] = Integer(input[j])\n end\nend\n\ndef good_number(x)\n x = x.sort\n y = Array.new\n y[0] = x[0]\n for i in 0...x.length - 1\n if x[i + 1] != x[i]\n y.push(x[i + 1])\n end\n end\n return y\nend\nans = 0\nfor i in 0...n\n if good_number(a[i])[0] == 0\n if good_number(a[i]).length >= k + 1 && good_number(a[i])[k] == k\n ans += 1\n end\n end\nend\nputs ans"}, {"source_code": "n, k = gets.chomp.split.map &:to_i\nres = 0\nn.times do\n s = gets.chomp\n # Check all digit in [0..k] appear in s\n t = true\n (0..k).to_a.each do |index|\n t = false and break if s.index((index + 48).chr).nil?\n end\n res += 1 if t\nend\nputs res"}, {"source_code": "#!/usr/bin/ruby\nn,k=gets.split.map(&:to_i)\np n.times.count{\n\ta=gets.chomp.split('').map(&:to_i)\n\t(0..k).all?{|e|a.include?(e)}\n}"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\ncount = 0\nn.times do\n\ts = STDIN.readline.strip\n\tokay = true\n\t(0..k).each do |d|\n\t\tif s.index(d.to_s) == nil\n\t\t\tokay = false\n\t\t\tbreak\n\t\tend\n\tend\n\tcount += 1 if okay\nend\nputs count\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\ntot = 0\nn.times do\n arr = gets.split(//)[0..-2].map(&:to_i).uniq.sort\n tot += 1 if arr.size > k && arr[0..k] == (0..k).to_a\nend\nputs tot\n"}, {"source_code": "ans=0\na=gets.chomp.split(\" \")\ninp=a[0].to_i\nrng=a[1].to_i\ninp.times do\na=gets.chomp\ntempa=Hash.new(0)\na.each_char do |i|\ntempa[i]+=1\nend\ntrg=1\n0.upto(rng) do |i|\nif tempa[\"#{i}\"]==0\ntrg=0\nend\nbreak if trg==0\nend\nif trg==1\nans+=1\nend\nend\n\n\n\n\n\nputs \"#{ans}\"\n\n"}, {"source_code": "t=0;n,k=gets.split.map &:to_i;p=(0..k).to_a;pl=p.length;n.times{m=gets.strip.split('').map &:to_i;t+=((p&m).length >= pl)?1:0};p t"}, {"source_code": "n,k=gets.split.map &:to_i;p=(0..k).to_a.map &:to_s;p (((1..n).map{|i|((p&(gets.strip.split(''))).length >= p.length)?1:0}).count(1))\n"}, {"source_code": "n,k=gets.split.map &:to_i;p=(0..k).to_a.map &:to_s;pl=p.length;p (((1..n).map{|i|((p&(gets.strip.split(''))).length >= pl)?1:0}).count(1))\n"}, {"source_code": "t=0;n,k=gets.split.map &:to_i;p=(0..k).to_a;pl=p.length;n.times{m=gets.strip.split('').map &:to_i;t+=((p&m).length >= pl)?1:0};p t\n"}], "negative_code": [{"source_code": "class A\n def initialize\n n, k = gets.chomp.split(' ').map(&:to_i)\n answer = 0\n\n n.times do\n check_list = Hash.new\n num = gets.chomp.split('').map(&:to_i)\n\n num.each do |val|\n check_list[val] = true\n end\n\n answer += 1 if check_list.size == (k+1)\n end\n\n puts answer\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n n, k = gets.chomp.split(' ').map(&:to_i)\n answer = 0\n\n n.times do\n check_list = Hash.new\n flag = true\n num = gets.chomp.split('').map(&:to_i).sort.uniq\n\n num.each do |val|\n flag = false if val > k\n check_list[val] = true\n end\n\n answer += 1 if check_list.size == (k+1) && flag\n end\n\n puts answer\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n n, k = gets.chomp.split(' ').map(&:to_i)\n answer = 0\n\n n.times do\n num = gets.chomp.split('').map(&:to_i)\n\n answer += 1 if k == num.count{|val| val < k }\n end\n\n puts answer\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n n, k = gets.chomp.split(' ').map(&:to_i)\n answer = 0\n\n n.times do\n check_list = Hash.new\n flag = true\n num = gets.chomp.split('').map(&:to_i)\n\n num.each do |val|\n flag = false if val > k\n check_list[val] = true\n end\n\n answer += 1 if check_list.size == (k+1) && flag\n end\n\n puts answer\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n n, k = gets.chomp.split(' ').map(&:to_i)\n answer = 0\n\n n.times do\n num = gets.chomp.split('').map(&:to_i)\n\n answer += 1 if num.all?{|val| val <= k }\n end\n\n puts answer\n end\nend\n\na = A.new"}, {"source_code": "t=0;n,k=gets.split.map &:to_i;n.times{px=(0..k).to_a.join;mx=gets.strip;t+=((mx.tr(px,'')=='' and px.tr(mx,'')=='')?1:0)};p t"}, {"source_code": "t=0;n,k=gets.split.map &:to_i\nn.times{\n\tpx=(0..k).to_a.join\n\tmx=gets.strip\n\tt+=(mx.tr(px,'')=='' and px.tr(mx,'')=='')?1:0\n}\np t\n"}, {"source_code": "input = gets.chomp\nnums = input.split\nn = Integer(nums[0])\nk = Integer(nums[1])\na = Array.new\nfor i in 0...n\n input = gets.chomp\n a[i] = Array.new\n for j in 0...input.length\n a[i][j] = Integer(input[j])\n end\nend\n\ndef good_number(x)\n x = x.sort\n y = Array.new\n y[0] = x[0]\n for i in 0...x.length - 1\n if x[i + 1] != x[i]\n y.push(x[i + 1])\n end\n end\n return y\nend\nans = 0\nfor i in 0...n\n if (good_number(a[i])).length >= k + 1\n ans += 1\n end\nend\nputs ans\n"}, {"source_code": "input = gets.chomp\nnums = input.split\nn = Integer(nums[0])\nk = Integer(nums[1])\na = Array.new\nfor i in 0...n\n input = gets.chomp\n a[i] = Array.new\n for j in 0...input.length\n a[i][j] = Integer(input[j])\n end\nend\n\ndef good_number(x)\n x = x.sort\n y = Array.new\n y[0] = x[0]\n for i in 0...x.length - 1\n if x[i + 1] != x[i]\n y.push(x[i + 1])\n end\n end\n return y\nend\nans = 0\nfor i in 0...n\n if (good_number(a[i])).length == k + 1\n ans += 1\n end\nend\nputs ans"}, {"source_code": "input = gets.chomp\nnums = input.split\nn = Integer(nums[0])\nk = Integer(nums[1])\na = Array.new\nfor i in 0...n\n input = gets.chomp\n a[i] = Array.new\n for j in 0...input.length\n a[i][j] = Integer(input[j])\n end\nend\n\ndef good_number(x)\n x = x.sort\n y = Array.new\n y[0] = x[0]\n for i in 0...x.length - 1\n if x[i + 1] != x[i]\n y.push(x[i + 1])\n end\n end\n return y\nend\nans = 0\nfor i in 0...n\n if k != 0\n if (good_number(a[i])).length >= k + 1\n ans += 1\n end\n else\n if good_number(a[i])[0] == 0\n ans += 1\n end\n end\nend\nputs ans"}, {"source_code": "input = gets.chomp\nnums = input.split\nn = Integer(nums[0])\nk = Integer(nums[1])\na = Array.new\nfor i in 0...n\n input = gets.chomp\n a[i] = Array.new\n for j in 0...input.length\n a[i][j] = Integer(input[j])\n end\nend\n\ndef good_number(x)\n x = x.sort\n y = Array.new\n y[0] = x[0]\n for i in 0...x.length - 1\n if x[i + 1] != x[i]\n y.push(x[i + 1])\n end\n end\n return y\nend\nans = 0\nfor i in 0...n\n if good_number(a[i])[0] == 0\n if good_number(a[i]).length >= k + 1\n ans += 1\n end\n end\nend\nputs ans"}], "src_uid": "fc831eda72f2ebe0865a3fb1b783edc5"} {"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\ns = read_to_array[0]\nbeg = false\nended = false\nres = String.new\ns.each_char do |c|\n if c == 'a'\n if beg\n beg = false \n ended = true\n end\n else\n if !ended\n beg = true\n end\n\n if beg\n c = c.ord - 1\n end\n end\n\n res << c\nend\n\nif beg == false && ended == false\n n = res[res.size - 1]\n res[res.size - 1] = 'z'\nend\n\nputs res\n", "positive_code": [{"source_code": "s=gets.chomp\nn=s.size\n\ni=s.index /[^a]/\nunless i\n s[-1]=?z\n puts s\n exit\nend\n\nj=s.index(?a, i+1)||n\n\nputs s[0, i]+s[i, j-i].tr!('b-z', 'a-y')+s[j, n-j]\n"}], "negative_code": [{"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\ns = read_to_array[0]\nbeg = false\nended = false\nres = String.new\ns.each_char do |c|\n if c == 'a'\n if beg\n beg = false \n ended = true\n end\n else\n if !ended\n beg = true\n end\n\n if beg\n c = (c.ord - 1)\n end\n end\n\n res << c\nend\n\nputs res\n"}, {"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\ns = read_to_array[0]\nbeg = false\nended = false\nres = String.new\ns.each_char do |c|\n if c == 'a'\n if beg\n beg = false \n ended = true\n end\n else\n if !ended\n beg = true\n end\n\n if beg\n c = c.ord - 1\n end\n end\n\n res << c\nend\n\nif beg == false && ended == false\n n = res[res.size - 1]\n res[res.size - 1] = 'a'\nend\n\nputs res\n"}, {"source_code": "s=gets.chomp\nfor i in 0..s.size-1\n next if s[i]==?a\n for j in i..s.size-1\n if s[j]!=?a\n s[j]=(s[j].ord-1).chr\n else\n break\n end\n end\n break\nend\nputs s\n"}], "src_uid": "e70708f72da9a203b21fc4112ede9268"} {"source_code": "def solve\r\n n, m = ints\r\n a = int1s\r\n b = int1s\r\n c = int1s\r\n colors = Array.new(n) { [] }\r\n has_color = [nil] * n\r\n\r\n b.each_with_index do |color, i|\r\n if a[i] != color\r\n colors[color] << i\r\n else\r\n has_color[color] = i\r\n end\r\n end\r\n\r\n painted = nil\r\n i = m-1\r\n plank = []\r\n c.reverse_each do |color|\r\n if not colors[color].empty?\r\n painted = colors[color].pop\r\n elsif painted\r\n painted = painted\r\n elsif has_color[color]\r\n painted = has_color[color]\r\n else\r\n no\r\n return\r\n end\r\n plank[i] = painted+1\r\n i -= 1\r\n end\r\n\r\n unless colors.all?(&:empty?)\r\n no\r\n return\r\n end\r\n\r\n yes\r\n puts plank * \" \"\r\nend\r\n\r\ndef main\r\n t = int\r\n t.times do\r\n solve\r\n end\r\nend\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\nYESNO = %w(NO YES)\r\nINF = 10**9\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts YESNO[1] end\r\ndef no; puts YESNO[0] end\r\ndef yesno t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain", "positive_code": [{"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n, m = gets.chomp.split(' ').map(&:to_i)\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n brr = gets.chomp.split(' ').map(&:to_i)\r\n crr = gets.chomp.split(' ').map(&:to_i)\r\n\r\n colors = Array.new(n + 1) {Array.new}\r\n missed = Array.new(n + 1) {Array.new}\r\n\r\n cur = arr.dup\r\n res = []\r\n\r\n n.times do |ind|\r\n if arr[ind] != brr[ind]\r\n missed[brr[ind]] << ind\r\n else\r\n colors[arr[ind]] << ind\r\n end\r\n end\r\n\r\n buff = []\r\n crr.each_with_index do |el, ind|\r\n # puts \"Buff = #{buff}\"\r\n # puts \"res = #{res}\"\r\n if missed[el].any?\r\n # puts \"Iter1 = {#{[el, ind].to_s}}\"\r\n t = missed[el].shift\r\n res << t + 1\r\n cur[t] = el\r\n if buff.any?\r\n buff.each do |i|\r\n res[i] = t + 1\r\n end\r\n buff = []\r\n end\r\n colors[el] << t\r\n next\r\n end\r\n if colors[el].any?\r\n # puts \"Iter2 = {#{[el, ind].to_s}}\"\r\n t = colors[el][0]\r\n res << t + 1\r\n cur[t] = el\r\n if buff.any?\r\n buff.each do |i|\r\n res[i] = t + 1\r\n end\r\n buff = []\r\n end\r\n next\r\n end\r\n # puts \"Iter3 = {#{[el, ind].to_s}}\"\r\n buff << ind\r\n res << -1\r\n end\r\n # puts \"RES = #{res}\"\r\n if buff.empty? && missed.all? {|el| el.empty?}\r\n puts \"YES\"\r\n puts res.join(' ')\r\n else\r\n puts \"NO\"\r\n end\r\nend"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n, m = gets.chomp.split(' ').map(&:to_i)\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n brr = gets.chomp.split(' ').map(&:to_i)\r\n crr = gets.chomp.split(' ').map(&:to_i)\r\n\r\n colors = Array.new(n + 1) {Array.new}\r\n missed = Array.new(n + 1) {Array.new}\r\n\r\n cur = arr.dup\r\n res = []\r\n\r\n n.times do |ind|\r\n if arr[ind] != brr[ind]\r\n missed[brr[ind]] << ind\r\n else\r\n colors[arr[ind]] << ind\r\n end\r\n end\r\n\r\n buff = []\r\n crr.each_with_index do |el, ind|\r\n # puts \"Buff = #{buff}\"\r\n # puts \"res = #{res}\"\r\n if missed[el].any?\r\n # puts \"Iter1 = {#{[el, ind].to_s}}\"\r\n t = missed[el].shift\r\n res << t + 1\r\n cur[t] = el\r\n if buff.any?\r\n buff.each do |i|\r\n res[i] = t + 1\r\n end\r\n buff = []\r\n end\r\n colors[el] << t\r\n next\r\n end\r\n if colors[el].any?\r\n # puts \"Iter2 = {#{[el, ind].to_s}}\"\r\n t = colors[el][0]\r\n res << t + 1\r\n cur[t] = el\r\n if buff.any?\r\n buff.each do |i|\r\n res[i] = t + 1\r\n end\r\n buff = []\r\n end\r\n next\r\n end\r\n # puts \"Iter3 = {#{[el, ind].to_s}}\"\r\n buff << ind\r\n res << -1\r\n end\r\n # puts \"RES = #{res}\"\r\n if buff.empty?\r\n puts \"YES\"\r\n puts res.join(' ')\r\n else\r\n puts \"NO\"\r\n end\r\nend"}, {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n, m = gets.chomp.split(' ').map(&:to_i)\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n brr = gets.chomp.split(' ').map(&:to_i)\r\n crr = gets.chomp.split(' ').map(&:to_i)\r\n\r\n colors = Array.new(n + 1) {Array.new}\r\n missed = Array.new(n + 1) {Array.new}\r\n\r\n cur = arr.dup\r\n res = []\r\n\r\n n.times do |el|\r\n if arr[el] != brr[el]\r\n missed[brr[el]] << el\r\n else\r\n colors[arr[el]] << el\r\n end\r\n end\r\n\r\n buff = []\r\n crr.each_with_index do |el, ind|\r\n # puts \"Buff = #{buff}\"\r\n # puts \"res = #{res}\"\r\n if missed[el].any?\r\n # puts \"Iter1 = {#{[el, ind].to_s}}\"\r\n t = missed[el].shift\r\n res << t + 1\r\n cur[t] = el\r\n if buff.any?\r\n buff.each do |i|\r\n res[i] = t + 1\r\n end\r\n buff = []\r\n end\r\n next\r\n end\r\n if colors[el].any?\r\n # puts \"Iter2 = {#{[el, ind].to_s}}\"\r\n t = colors[el][0]\r\n res << t + 1\r\n cur[t] = el\r\n if buff.any?\r\n buff.each do |i|\r\n res[i] = t + 1\r\n end\r\n buff = []\r\n end\r\n next\r\n end\r\n # puts \"Iter3 = {#{[el, ind].to_s}}\"\r\n buff << ind\r\n res << -1\r\n end\r\n # puts \"RES = #{res}\"\r\n if buff.empty?\r\n puts \"YES\"\r\n puts res.join(' ')\r\n else\r\n puts \"NO\"\r\n end\r\nend"}, {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n, m = gets.chomp.split(' ').map(&:to_i)\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n brr = gets.chomp.split(' ').map(&:to_i)\r\n crr = gets.chomp.split(' ').map(&:to_i)\r\n\r\n colors = Array.new(n + 1) {Array.new}\r\n missed = Array.new(n + 1) {Array.new}\r\n\r\n cur = arr.dup\r\n res = []\r\n\r\n n.times do |el|\r\n if arr[el] != brr[el]\r\n missed[brr[el]] << el\r\n else\r\n colors[arr[el]] << el\r\n end\r\n end\r\n\r\n buff = []\r\n crr.each_with_index do |el, ind|\r\n if missed[el].any?\r\n t = missed[el].shift\r\n res << t + 1\r\n cur[t] = el\r\n if buff.any?\r\n i = buff.shift\r\n res[i] = t + 1\r\n end\r\n next\r\n end\r\n if colors[el].any?\r\n t = colors[el][0]\r\n res << t + 1\r\n cur[t] = el\r\n if buff.any?\r\n i = buff.shift\r\n res[i] = t + 1\r\n end\r\n next\r\n end\r\n buff << ind\r\n res << -1\r\n end\r\n if buff.empty?\r\n puts \"YES\"\r\n puts res.join(' ')\r\n else\r\n puts \"NO\"\r\n end\r\nend"}], "src_uid": "a350430c707bb18a146df9f80e114f45"} {"source_code": "#require \"prime\"\n#input of int(split by space)\ndef get_i()\n return gets.chomp.split(\" \").map(&:to_i)\nend\n#input of float(split by space)\ndef get_f()\n return gets.chomp.split(\" \").map(&:to_f)\nend\n#input of string(split by space)\ndef get()\n return gets.chomp.split(\" \")\nend\n#input of string(split per one character)\ndef get_nsp()\n return gets.chomp.split(\"\")\nend\n#yes or no decision\ndef yn_judge(bool,y=\"Yes\",n=\"No\")\n return bool ? y : n \nend\n#output grid(two dimensional array)\ndef puts_grid(grid,join_char=\"\")\n grid.each do|line|\n puts line.join(join_char)\n end\nend\n\nDirxy4=[[1,0],[-1,0],[0,1],[0,-1]]\nDirxy8=[[1,0],[1,-1],[1,1],[0,-1],[0,1],[-1,0],[-1,-1],[-1,1]]\n\nINF=Float::INFINITY\n\n#MOD=998_244_353\nMOD=10**9+7\nT=gets.to_i\nT.times do\n n=gets.to_i\n a=get_i\n b=get_i\n f=true\n diff=-1\n n.times do |i|\n if b[i].zero?\n next\n end\n if a[i]-b[i]>=0\n diff=a[i]-b[i]\n break\n else\n f=false\n break\n end\n end\n if diff==-1\n puts yn_judge(f,\"YES\",\"NO\")\n else\n n.times do |i|\n if b[i].zero?\n unless diff>=a[i]\n f=false\n break\n end\n else\n unless diff==a[i]-b[i]\n f=false\n break\n end\n end\n end\n puts yn_judge(f,\"YES\",\"NO\")\n end\nend", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = gets.chomp.split.map(&:to_i)\n b = gets.chomp.split.map(&:to_i)\n r = [0, 2000000000]\n n.times do |i|\n if b[i] > a[i]\n r = [1,0]\n break\n elsif b[i] == 0 # a[i]..\n r = [\n [a[i], r[0]].max,\n [2000000000, r[1]].min\n ]\n else # a[i] - b[i], a[i]-b[i]\n r = [\n [a[i]-b[i], r[0]].max,\n [a[i]-b[i], r[1]].min\n ]\n end\n end\n if r[0] <= r[1]\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "t = gets.to_i\r\n\r\nt.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n b = gets.split.map(&:to_i)\r\n\r\n s = -1\r\n n.times do |i|\r\n s = [s, a[i]-b[i]].max\r\n end\r\n\r\n ok = true\r\n n.times do |i|\r\n ai, bi = a[i], b[i]\r\n break ok = false if ai < bi\r\n\r\n k = ai - bi\r\n if bi == 0\r\n break ok = false if k > s\r\n else\r\n break ok = false if k != s\r\n end\r\n end\r\n\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n"}], "negative_code": [{"source_code": "#require \"prime\"\n#input of int(split by space)\ndef get_i()\n return gets.chomp.split(\" \").map(&:to_i)\nend\n#input of float(split by space)\ndef get_f()\n return gets.chomp.split(\" \").map(&:to_f)\nend\n#input of string(split by space)\ndef get()\n return gets.chomp.split(\" \")\nend\n#input of string(split per one character)\ndef get_nsp()\n return gets.chomp.split(\"\")\nend\n#yes or no decision\ndef yn_judge(bool,y=\"Yes\",n=\"No\")\n return bool ? y : n \nend\n#output grid(two dimensional array)\ndef puts_grid(grid,join_char=\"\")\n grid.each do|line|\n puts line.join(join_char)\n end\nend\n\nDirxy4=[[1,0],[-1,0],[0,1],[0,-1]]\nDirxy8=[[1,0],[1,-1],[1,1],[0,-1],[0,1],[-1,0],[-1,-1],[-1,1]]\n\nINF=Float::INFINITY\n\n#MOD=998_244_353\nMOD=10**9+7\nT=gets.to_i\nT.times do\n n=gets.to_i\n a=get_i\n b=get_i\n if n==1\n if a[0]>=b[0] or b[0].zero?\n puts \"YES\"\n else\n puts \"NO\"\n end\n next\n end\n f=true\n (n-1).times do |i|\n if b[i].zero?\n next\n end\n if b[i+1].zero?\n unless a[i]-b[i]>=a[i+1]-b[i+1]\n f=false\n break\n end\n else\n unless a[i]-b[i]==a[i+1]-b[i+1]\n f=false\n break\n end\n end\n end\n puts yn_judge(f,\"YES\",\"NO\")\nend"}, {"source_code": "#require \"prime\"\n#input of int(split by space)\ndef get_i()\n return gets.chomp.split(\" \").map(&:to_i)\nend\n#input of float(split by space)\ndef get_f()\n return gets.chomp.split(\" \").map(&:to_f)\nend\n#input of string(split by space)\ndef get()\n return gets.chomp.split(\" \")\nend\n#input of string(split per one character)\ndef get_nsp()\n return gets.chomp.split(\"\")\nend\n#yes or no decision\ndef yn_judge(bool,y=\"Yes\",n=\"No\")\n return bool ? y : n \nend\n#output grid(two dimensional array)\ndef puts_grid(grid,join_char=\"\")\n grid.each do|line|\n puts line.join(join_char)\n end\nend\n\nDirxy4=[[1,0],[-1,0],[0,1],[0,-1]]\nDirxy8=[[1,0],[1,-1],[1,1],[0,-1],[0,1],[-1,0],[-1,-1],[-1,1]]\n\nINF=Float::INFINITY\n\n#MOD=998_244_353\nMOD=10**9+7\nT=gets.to_i\nT.times do\n n=gets.to_i\n a=get_i\n b=get_i\n f=true\n (n-1).times do |i|\n if b[i].zero?\n next\n end\n if b[i+1].zero?\n unless a[i]-b[i]>=a[i+1]-b[i+1]\n f=false\n break\n end\n else\n unless a[i]-b[i]==a[i+1]-b[i+1]\n f=false\n break\n end\n end\n end\n puts yn_judge(f,\"YES\",\"NO\")\nend"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n b = gets.split.map(&:to_i)\n\n pair = []\n n.times do |i|\n pair << [a[i], b[i]]\n end\n\n pair.sort_by!{|e| [-e[0], -e[1]]}\n\n ok = true\n s = a[0]-b[0]\n n.times do |i|\n ai, bi = pair[i]\n if ai < bi\n ok = false\n break\n end\n\n if bi == 0\n k = ai - bi\n if k > s\n ok = false\n break\n end\n else\n k = ai - bi\n if k != s\n ok = false\n break\n end\n end\n end\n\n puts ok ? \"YES\" : \"NO\"\nend\n"}], "src_uid": "ee40e8b0ed2da53127f53eb694653a30"} {"source_code": "gets;c=0;gets.split.inject(Hash.new(0)){|h,k|h[k]+=1;h}.each_value{|x|c+=x%2};puts c>0?\"Conan\":\"Agasa\"", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na.sort!\nk = a.pop\nflag = false # Conan wins\nwhile !flag && k\n cnt = 1\n while k == (l = a.pop)\n cnt += 1\n end\n flag = cnt % 2 != 0\n k = l\nend\nputs flag ? \"Conan\" : \"Agasa\"\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort.reverse\n\noddcnt = a.group_by{|x| x}.map{|k,v| v.size}.select{|t|t%2==1}.size\n\nputs (oddcnt>0)? 'Conan' : 'Agasa' "}, {"source_code": "gets\nc=0\nh=Hash.new 0\ngets.split.each{|e|h[e]=d=h[e]+1;c+=d%2*2-1}\nputs c>0 ? :Conan : :Agasa"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na.sort!\nk = a[-1]\nflag = false # Conan wins\nwhile !flag && k\n cnt = 0\n while k == (l = a.pop)\n cnt += 1\n end\n flag = cnt % 2 != 0\n k = l\nend\nputs flag ? \"Conan\" : \"Agasa\"\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na.sort!\nk = a.pop\nwhile k && (a.count(k) % 2 == 1)\n a.delete(k)\n k = a.pop\nend\nputs a.length == 0 ? \"Agasa\" : \"Conan\"\n"}], "src_uid": "864593dc3911206b627dab711025e116"} {"source_code": "#!/usr/bin/ruby1.9\n\ns = STDIN.readline.strip\nm = STDIN.readline.to_i\nweights = []\n10.times do |pos|\n\tif s[pos] == '1'\n\t\tweights.push(pos+1)\n\tend\nend\n\ndef solve(solution, weights, left, right, ix, max, previous)\n\treturn true if ix == max\n\tweights.each do |weight|\n\t\tnext if weight == previous\n\t\tnext if left+weight <= right\n\t\tsolution.push(weight)\n\t\tif solve(solution, weights, right, left+weight, ix+1, max, weight)\n\t\t\treturn true\n\t\tend\n\t\tsolution.pop\n\tend\n\treturn false\nend\n\nsolution = []\nif solve(solution, weights, 0, 0, 0, m, -1)\n\tputs 'YES'\n\tputs solution.join(' ')\nelse\n\tputs 'NO'\nend\n\n", "positive_code": [{"source_code": "@s = '0'+gets.strip\n@m = gets.to_i\n@calced = []\n@f = []\nfor i in 0..10 do\n @calced[i]=[]\n @f[i]=[]\n for j in 0..@m do\n @calced[i][j]=[]\n @f[i][j] = []\n end\nend\n\ndef dp(delta,step,last)\n if !@calced[delta][step][last]\n @calced[delta][step][last]=true\n @f[delta][step][last]=false\n if step==@m\n @f[delta][step][last]=true\n else\n for i in delta+1..10 do\n if i!=last && @s[i]=='1' && dp(i-delta,step+1,i)\n @f[delta][step][last]=true\n break\n end\n end\n end\n end\n return @f[delta][step][last]\nend\n\ndef show(delta,step,last)\n if step==@m\n puts last\n else\n if step==0\n puts 'YES'\n else\n print last,' '\n end\n for i in delta+1..10 do\n if i!=last && @s[i]=='1' && dp(i-delta,step+1,i)\n show(i-delta,step+1,i)\n break\n end\n end\n end\nend\n\nif !dp(0,0,0)\n puts 'NO'\nelse\n show(0,0,0)\nend"}], "negative_code": [{"source_code": "#!/usr/bin/ruby1.9\n\ns = STDIN.readline.strip\nm = STDIN.readline.to_i\nweights = []\n10.times do |pos|\n\tif s[pos] == '1'\n\t\tweights.push(pos+1)\n\tend\nend\n\ndef solve(solution, weights, left, right, ix, max, previous)\n\treturn true if ix == max\n\tweights.each do |weight|\n\t\tnext if weight == previous\n\t\tnext if left+weight <= right\n\t\tsolution.push(weight)\n\t\treturn true if solve(solution, weights, right, left, ix+1, max, weight)\n\t\tsolution.pop\n\tend\n\treturn false\nend\n\nsolution = []\nif solve(solution, weights, 0, 0, 0, m, -1)\n\tputs 'YES'\n\tputs solution.join(' ')\nelse\n\tputs 'NO'\nend\n\n"}], "src_uid": "15aa3adb14c17023f71eec11e1c32efe"} {"source_code": "def parse(type, values)\n type =~ /^(\\&*)(.*?)(\\**)$/\n amp = $1\n base = $2\n star = $3\n if base == 'errtype'\n return 'errtype'\n elsif base != 'void'\n if !values[base]\n return 'errtype'\n end\n type = \"#{amp}#{values[base]}#{star}\"\n type =~ /^(\\&*)(.*?)(\\**)$/\n amp = $1\n base = $2\n star = $3\n\n if base == 'errtype'\n return 'errtype'\n end\n end\n\n s = star.size - amp.size\n if s < 0\n return 'errtype'\n else\n return base + \"*\" * s\n end\nend\n\nvalues = {}\n\ngets.to_i.times{\n l = gets.chomp\n if l =~ /typedef (\\S+) (\\S+)/\n type = $1\n name = $2\n values[name] = parse(type, values)\n elsif l =~ /typeof (\\S+)/\n type = $1\n puts parse(type, values)\n else\n raise\n end\n}\n", "positive_code": [{"source_code": "\nn = STDIN.readline.to_i\nregex = /^(&*)(.+?)(\\**)$/\ndict = Hash.new\ndict['void'] = 0\nn.times do\n s = STDIN.readline.split ' '\n array = regex.match(s[1])\n head = array[1].length\n body = array[2]\n tail = array[3].length\n if s[0] == \"typedef\" then\n base = if dict.include? body then \n dict[body] \n else \n nil \n end\n dict[s[2]] = if base == nil or base + tail - head < 0 then \n nil\n else \n base + tail - head\n end\n else\n if (!dict.include? body) || (!dict[body]) then\n puts 'errtype'\n else\n len = dict[body] + tail - head\n if len >= 0 then\n puts 'void' + ('*' * len)\n else \n puts 'errtype'\n end\n end\n end\nend\n"}, {"source_code": "h = {void: \"void\", errtype: \"errtype\"}\ngets.to_i.times do\n s = gets.split\n if s[0] == \"typeof\"\n s[1].match(/(&*)([^&*]+)(\\**)/)\n a, b, c = $1.size, $2.to_sym, $3.size\n if h[b].nil? || h[b] == \"errtype\" || a > c + h[b].scan(/\\*/).size\n puts :errtype\n else\n if a >= c\n puts h[b][0..-(a - c + 1)]\n else\n puts h[b] + \"*\" * (c - a)\n end\n end\n else\n s[2] = s[2].to_sym\n s[1].match(/(&*)([^&*]+)(\\**)/)\n a, b, c = $1.size, $2.to_sym, $3.size\n if h[b].nil? || h[b] == \"errtype\" || a > c + h[b].scan(/\\*/).size\n h[s[2]] = \"errtype\"\n else\n if a >= c\n h[s[2]] = h[b][0..-(a - c + 1)]\n else\n h[s[2]] = h[b] + \"*\" * (c - a)\n end\n end\n end\nend\n"}], "negative_code": [{"source_code": "h = {void: \"void\", errtype: \"errtype\"}\ngets.to_i.times do\n s = gets.split\n if s[0] == \"typeof\"\n if s[1].match(/(&*)(#{h.keys.join(?|)})(\\**)/)\n a, b, c = $1.size, $2.to_sym, $3.size\n if h[b].nil? || h[b] == \"errtype\" || a > c + h[b].scan(/\\*/).size\n puts :errtype\n else\n if a >= c\n puts h[b][0..-(a - c + 1)]\n else\n puts h[b] + \"*\" * (c - a)\n end\n end\n else\n puts :errtype\n end\n else\n s[2] = s[2].to_sym\n if s[1].match(/(&*)(#{h.keys.join(?|)})(\\**)/)\n a, b, c = $1.size, $2.to_sym, $3.size\n if h[b].nil? || h[b] == \"errtype\" || a > c + h[b].scan(/\\*/).size\n h[s[2]] = \"errtype\"\n else\n if a >= c\n h[s[2]] = h[b][0..-(a - c + 1)]\n else\n h[s[2]] = h[b] + \"*\" * (c - a)\n end\n end\n else\n h[s[2]] = \"errtype\"\n end\n end\nend\n"}, {"source_code": "\nn = STDIN.readline.to_i\nregex = /^(&*)(.+?)(\\**)$/\ndict = Hash.new\nn.times do\n s = STDIN.readline.split ' '\n if s[0] == \"typedef\" then\n array = regex.match(s[1])\n base = if array[2] == 'void' then 0 \n elsif dict.include?(array[2]) then dict[array[2]] \n else nil \n end\n if base == nil then\n dict[s[2]] = nil\n elsif base + array[3].length - array[1].length < 0 then\n dict[s[2]] = nil\n else\n dict[s[2]] = base + array[3].length - array[1].length\n end\n else\n array = regex.match(s[1])\n if !dict.include?(array[2]) || !dict[array[2]] then\n puts 'errtype'\n else\n# p array\n len = dict[array[2]] + array[3].length - array[1].length\n if len >= 0 then\n puts 'void' + ('*' * len)\n else \n puts 'errtype'\n end\n end\n end\nend\n"}], "src_uid": "b260eb188103758a74b600d8bb46fffe"} {"source_code": "inp = gets.split(\" \")\nn = inp[0].to_i\nm = inp[1].to_i\nl = Array.new(m){[]}\nfor i in 0..(n-1)\n inp = gets\n for j in 0..(m-1)\n l[j] << inp[j]\n end\nend\n\ncount = 1\nl.each do |arr|\n arr.sort!\n #p arr\n unq = 1\n curr = 0\n while curr < (n - 1)\n if arr[curr] != arr[curr+1]\n unq += 1\n\tend\n\tcurr += 1\n end\n #puts unq\n count *= unq\nend\n\nputs count % 1000000007 ", "positive_code": [{"source_code": "require 'set'\n\nn,m = gets.chomp.split(/ /).map!{|x| x.to_i}\ns = []\nfor i in 0..n-1\n\ts << gets.chomp\nend\nret = 1\nfor i in 0..m-1\n\tws = Set.new\n\tfor j in 0..n-1\n\t\tws.add(s[j][i])\n\tend\n\tret *= ws.length\nend\nret %= 1000000007\nputs ret"}, {"source_code": "n, m = gets.split.map(&:to_i)\np Array.new(m).zip(*(n.times.map{gets.chars.to_a})).map{|_| _.uniq.size - 1}.inject(&:*) % 1000000007\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\np n.times.map{gets.chars.to_a}.transpose.map{|_| _.uniq.size}.inject(&:*) % 1000000007\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nans=1\ninput=[]\nn.times{input+=[gets.split[0]]}\nm.times{|i|\n\ta=Hash.new\n\tn.times{|j|\n\t\ta[input[j][i]]=true\n\t}\n\tans*=a.size\n\tans%=1000000007\n}\np ans"}, {"source_code": "#!/usr/bin/env ruby\n\nMOD = 1000000007\nn, m = gets.split.map(&:to_i)\ntranspose = Array.new(m) { {} }\nn.times do\n gets.chomp.each_char.to_a.each_with_index do |ch, idx|\n transpose[idx][ch] = 1\n end\nend\n\ncnt = 1\ntranspose.each do |set|\n cnt *= set.size\n cnt %= MOD\nend\n\np cnt\n"}, {"source_code": "a=gets.chomp.split(' ')\na.length.times {|x| a[x]=a[x].to_i}\nb=[]\nc=[]\na[0].times do |x|\n b<0\n a = gets.chomp.split(\" \").each.map(&:to_i)\n sum+=a[0]\n b.push((a[0]-a[1]))\n n[0]-=1\nend\n\nb= b.sort\n\nwhile n[1]n[1])\n print(-1)\nelse\n print(c)\nend\n", "positive_code": [{"source_code": "n, m = gets.strip.split.map(&:to_i)\n\nsum = 0\nary = []\nn.times do\n a, b = gets.strip.split.map(&:to_i)\n ary << [a,b]\n sum += a\nend\n\nary = ary.sort_by{|x| x[1]-x[0]}\ni = 0\nans = 0\nwhile sum > m && i m\n puts \"-1\"\nelse\n puts ans\nend"}, {"source_code": "\ndef solution\n\n n, m = read_ints\n\n sum = 0\n sum_comp = 0\n\n diffs = []\n\n n.times do\n a, b = read_ints\n sum += a\n sum_comp += b\n diffs << (a - b)\n end\n\n diffs = diffs.sort.reverse\n\n if sum_comp > m\n puts -1\n return\n end\n\n i = 0\n\n while sum > m\n sum -= diffs[i]\n i += 1\n end\n\n puts i\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"}, {"source_code": "N, M = gets.split.map(&:to_i)\nas, bs = [], []\nN.times do |i|\n as[i], bs[i] = gets.split.map(&:to_i)\nend\n\nsum = as.inject(:+)\ngains = [0] + N.times.map{|i| as[i] - bs[i]}.sort.reverse\n(N+1).times do |i|\n sum -= gains[i]\n if sum <= M\n puts i; exit\n end\nend\nputs -1"}], "negative_code": [{"source_code": "\nSong = Struct.new(:a, :b) do\n def diff\n self.a - self.b\n end\nend\n\ndef solution\n\n n, m = read_ints\n\n songs = []\n\n sum = 0\n\n n.times do\n a, b = read_ints\n sum += a\n songs << Song.new(a, b)\n end\n\n songs = songs.sort_by(&:diff).reverse\n\n i = 0\n\n while sum > m && i < songs.size\n sum -= songs[i].diff\n i += 1\n end\n\n if sum > m\n puts -1\n else\n puts i\n end\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"}, {"source_code": "\nSong = Struct.new(:a, :b) do\n def diff\n self.a - self.b\n end\nend\n\ndef solution\n\n n, m = read_ints\n\n songs = []\n\n sum = 0\n\n n.times do\n a, b = read_ints\n sum += a\n songs << Song.new(a, b)\n end\n\n songs = songs.sort_by(&:diff)\n\n i = 0\n\n while sum > m && i < songs.size\n sum -= songs[i].diff\n i += 1\n end\n\n if sum > m\n puts -1\n else\n puts i - 1\n end\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}], "src_uid": "91541d10c5ae52be8da33412359bd019"} {"source_code": "def mid(x)\n\t(x-1)/2\nend\nn, x = gets.split(/\\s+/).map(&:to_i)\na = gets.split(/\\s+/).map(&:to_i).sort\nres = []\n1000.times do |i|\n\tres << i if a[mid(a.size)] == x\n\ta << x\n\ta.sort!\nend\np res.min\n", "positive_code": [{"source_code": "n, x = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = 0\nunless a.include?(x)\n a.push(x)\n ans += 1\nend\na.sort!\nm = (a.size()+1)/2-1\n\nwhile a[m]>x\n a.unshift(-1000)\n m = (a.size()+1)/2-1\n ans+=1\nend\n\nwhile a[m] median\n rcnt = 0\n target = ni\n\n if arr.size.even?\n rcnt += 1\n target -= 1\n end\n rcnt += (target-median) * 2\nend\n\n# left adjustment\nlcnt = n*100\nif ri < median\n lcnt = 0\n target = ri\n\n if arr.size.odd?\n lcnt += 1\n target += 1\n end\n lcnt += (median-target) * 2\nend\n\np [rcnt,lcnt].min + cnt\n"}, {"source_code": "$n, $m = gets.split().map(&:to_i)\n\n$a = gets.split().map(&:to_i)\n$a.sort!\ndef gg()\n return 0 if $a[$a.length/2] == $m\n ls = 0\n gt = 0\n eq = 0\n $a.each do |i|\n if i < $m\n ls = ls + 1\n elsif i == $m\n eq = eq + 1\n else\n gt = gt + 1\n end\n end\n \n return 1 if ls == gt\n if ls < gt\n ls = ls + eq\n return gt - ls\n else\n gt = gt + eq\n return ls - gt + 1\n end\n \nend\n\nans = gg\nputs ans\n"}, {"source_code": "#!/usr/bin/env ruby\n\nclass Main\n attr_reader :size, :number, :array\n\n def initialize(size, number, array)\n @size = size\n @number = number\n @array = array.sort\n end\n\n def run\n median_position = calculate_median(size)\n median_number = array[median_position]\n\n if number == median_number\n 0\n elsif array.include?(number)\n index = array.rindex(number)\n if index > median_position\n index = array.index(number)\n revert_median_calculation(index) - size\n elsif index < median_position\n (median_position - index) * 2 - size % 2\n end\n else\n median_number = array[median_position]\n new_array = (array + [number]).sort\n index = new_array.index(number)\n new_median_position = calculate_median(size + 1)\n if index > new_median_position\n revert_median_calculation(index) - size\n elsif index < new_median_position\n (new_median_position - index) * 2 - (size + 1) % 2 + 1\n else\n 1\n end\n end\n end\n\n private\n\n def calculate_median(array_size)\n (array_size + 1)/2 - 1\n end\n\n def revert_median_calculation(median)\n (median + 1) * 2 - 1\n end\nend\n\nsize, number = gets.split(\" \")\narray = gets.split(\" \")\nputs Main.new(size.to_i, number.to_i, array.map(&:to_i)).run\n"}, {"source_code": "# ProblemC\n\nn, x = gets.split().map! {|s| s.to_i}\n\nary = gets.split().map! {|s| s.to_i}\n\nres = 0\nunless ary.index(x)\n ary << x\n res += 1\nend\n\nary = ary.sort\n\nwhile true\n n = (ary.size)\n m = ((n + 1) / 2) - 1\n break if ary[m] == x\n if ary[m] > x\n ary.unshift(1)\n else\n ary << (10 ** 5)\n end\n res += 1\nend\n\nputs res\n"}, {"source_code": "a = gets.chomp.split(\" \").map{|i| i.to_i}\nb = gets.chomp.split(\" \").map{|i| i.to_i}\n\nb.sort!\nn = a[0]\nk = a[1]\n\nif k > b[n-1] \n puts n+1\nelse\n if k < b[0]\n puts n\n else\n x = (n+1)/2 - 1\n if k == b[x]\n puts 0\n else\n if k < b[x]\n i = 0\n while b[i+1] <= k do\n i += 1\n end\n find = n -2*i -2\n puts find\n else\n i = n-1\n while b[i-1] >= k do\n i -= 1\n end\n find = 2*i + 1 - n\n puts find\n end\n end\n end\nend"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).sort\nans=0\nunless a.include?(k)\n\ta<k\n\tuntil a[(n+1)/2-1]==k\n\t\tans+=1\n\t\tn+=1\n\t\ta.unshift 1\n\tend\nend\np ans"}, {"source_code": "n,xx = gets.chomp.split(/ /).map!{|x| x.to_i}\na = gets.chomp.split(/ /).map!{|x| x.to_i}\nret = 0\nif not a.include?(xx)\n ret = 1\n a << xx\nend\na.sort!\nm = (a.length() + 1)/2\n\nminxx = a.index(xx)\nmaxxx = a.rindex(xx)\nif minxx > (m-1)\n ret += (minxx - (a.length() - (minxx+1)))\nelsif maxxx < (m-1)\n ret += ((a.length() - (maxxx+1)) - maxxx - 1)\nend\nputs ret\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\nc = [0] * 3\nI[].each{|_| c[(_ <=> m) + 1] += 1}\nd = 0\nif c[1] == 0\n c[1] += 1\n d += 1\nend\nd += [(c[0] > c[2] ? c[0] - c[2] + 1 : c[2] - c[0]) - c[1], 0].max\np d\n"}], "negative_code": [{"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\nc = [0] * 3\nI[].each{|_| c[(_ <=> m) + 1] += 1}\np c\nd = 0\nif c[1] == 0\n c[1] += 1\n d += 1\nend\nd += [(c[0] > c[2] ? c[0] - c[2] + 1 : c[2] - c[0]) - c[1], 0].max\np d\n"}, {"source_code": "#!/usr/bin/ruby\n\nn, x = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i).sort\n\ncnt = 0\nif arr.index(x).nil?\n arr << x\n cnt += 1\n arr.sort!\nend\n\nmedian = (arr.size+1) / 2 - 1\nni = arr.index(x)\nri = arr.rindex(x)\n\nif arr[median] == x\n p 0\n exit\nend\n\n# right adjustment\nrcnt = n*100\nif ri > median\n rcnt = 0\n target = ri\n target = ni if ni > median\n\n if arr.size.even?\n rcnt += 1\n target -= 1\n end\n rcnt += (target-median) * 2\nend\n\n# left adjustment\nlcnt = n*100\nif ni < median\n lcnt = 0\n target = ni\n target = ri if ri < median\n\n if arr.size.odd?\n lcnt += 1\n target += 1\n end\n lcnt += (median-target) * 2\nend\n\np [rcnt,lcnt].min + cnt\n"}, {"source_code": "#!/usr/bin/ruby\n\nn, x = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i).sort\n\ncnt = 0\nif arr.index(x).nil?\n arr << x\n cnt += 1\n arr.sort!\nend\n\nmedian = (arr.size+1) / 2 - 1\nni = arr.index(x)\nri = arr.rindex(x)\n\n# right adjustment\nrcnt = n*100\nif ri > median\n rcnt = 0\n target = ri\n target = ni if ni > median\n\n if arr.size.even?\n rcnt += 1\n target -= 1\n end\n rcnt += (target-median) * 2\nend\n\n# left adjustment\nlcnt = n*100\nif ni < median\n lcnt = 0\n target = ni\n target = ri if ri < median\n\n if arr.size.odd?\n lcnt += 1\n target += 1\n end\n lcnt += (median-target) * 2\nend\n\np [rcnt,lcnt].min + cnt\n"}, {"source_code": "$n, $m = gets.split().map(&:to_i)\n\n$a = gets.split().map(&:to_i)\n\ndef gg()\n return 0 if $a[$a.length/2] == $m\n ls = 0\n gt = 0\n eq = 0\n $a.each do |i|\n if i < $m\n ls = ls + 1\n elsif i == $m\n eq = eq + 1\n else\n gt = gt + 1\n end\n end\n \n return 1 if ls == gt\n if ls < gt\n ls = ls + eq\n return gt - ls\n else\n gt = gt + eq\n return ls - gt + 1\n end\n \nend\n\nans = gg\nputs ans\n"}, {"source_code": "#!/usr/bin/env ruby\n\nclass Main\n attr_reader :size, :number, :array\n\n def initialize(size, number, array)\n @size = size\n @number = number\n @array = array.sort.reverse\n end\n\n def run\n median_position = (size + 1)/2 - 1\n if array.include?(number)\n index = array.index(number)\n (median_position - index).abs\n else\n median_number = array[median_position]\n new_array = (array + [number]).sort\n index = new_array.index(number)\n (median_position - index).abs * 2\n end\n end\nend\n\nsize, number = gets.split(\" \")\narray = gets.split(\" \")\nputs Main.new(size.to_i, number.to_i, array.map(&:to_i)).run"}, {"source_code": "#!/usr/bin/env ruby\n\nclass Main\n attr_reader :size, :number, :array\n\n def initialize(size, number, array)\n @size = size\n @number = number\n @array = array.sort\n end\n\n def run\n median_position = (size + 1)/2 - 1\n median_number = array[median_position]\n\n if number == median_number\n 0\n elsif array.include?(number)\n index = array.index(number)\n (median_position - index).abs\n else\n median_number = array[median_position]\n new_array = (array + [number]).sort\n index = new_array.index(number)\n new_median_position = (size + 2)/2 - 1\n if index > new_median_position\n index * 2 - size + 1\n elsif index < new_median_position\n size - index + 1\n else\n 1\n end\n end\n end\nend\n\nsize, number = gets.split(\" \")\narray = gets.split(\" \")\nputs Main.new(size.to_i, number.to_i, array.map(&:to_i)).run\n"}, {"source_code": "#!/usr/bin/env ruby\n\nclass Main\n attr_reader :size, :number, :array\n\n def initialize(size, number, array)\n @size = size\n @number = number\n @array = array.sort\n end\n\n def run\n median_position = calculate_median(size)\n median_number = array[median_position]\n\n if number == median_number\n 0\n elsif array.include?(number)\n index = array.index(number)\n if index > median_position\n revert_median_calculation(index) - size\n elsif index < median_position\n median_position - index\n end\n else\n median_number = array[median_position]\n new_array = (array + [number]).sort\n index = new_array.index(number)\n new_median_position = calculate_median(size + 1)\n if index > new_median_position\n revert_median_calculation(index) - size\n elsif index < new_median_position\n median_position - index + 1\n else\n 1\n end\n end\n end\n\n private\n\n def calculate_median(array_size)\n (array_size + 1)/2 - 1\n end\n\n def revert_median_calculation(median)\n (median + 1) * 2 - 1\n end\nend\n\nsize, number = gets.split(\" \")\narray = gets.split(\" \")\nputs Main.new(size.to_i, number.to_i, array.map(&:to_i)).run\n"}, {"source_code": "#!/usr/bin/env ruby\n\nclass Main\n attr_reader :size, :number, :array\n\n def initialize(size, number, array)\n @size = size\n @number = number\n @array = array.sort\n end\n\n def run\n median_position = calculate_median(size)\n median_number = array[median_position]\n\n if number == median_number\n 0\n elsif array.include?(number)\n index = array.rindex(number)\n if index > median_position\n revert_median_calculation(index) - size\n elsif index < median_position\n (median_position - index) * 2 - size % 2\n end\n else\n median_number = array[median_position]\n new_array = (array + [number]).sort\n index = new_array.index(number)\n new_median_position = calculate_median(size + 1)\n if index > new_median_position\n revert_median_calculation(index) - size\n elsif index < new_median_position\n (new_median_position - index) * 2 - (size + 1) % 2 + 1\n else\n 1\n end\n end\n end\n\n private\n\n def calculate_median(array_size)\n (array_size + 1)/2 - 1\n end\n\n def revert_median_calculation(median)\n (median + 1) * 2 - 1\n end\nend\n\nsize, number = gets.split(\" \")\narray = gets.split(\" \")\nputs Main.new(size.to_i, number.to_i, array.map(&:to_i)).run\n"}, {"source_code": "#!/usr/bin/env ruby\n\nclass Main\n attr_reader :size, :number, :array\n\n def initialize(size, number, array)\n @size = size\n @number = number\n @array = array.sort\n end\n\n def run\n median_position = (size + 1)/2 - 1\n median_number = array[median_position]\n\n if number == median_number\n 0\n elsif array.include?(number)\n index = array.index(number)\n (median_position - index).abs\n else\n median_number = array[median_position]\n new_array = (array + [number]).sort\n index = new_array.index(number)\n (median_position - index).abs * 2\n end\n end\nend\n\nsize, number = gets.split(\" \")\narray = gets.split(\" \")\nputs Main.new(size.to_i, number.to_i, array.map(&:to_i)).run"}, {"source_code": "a = gets.chomp.split(\" \").map{|i| i.to_i}\nb = gets.chomp.split(\" \").map{|i| i.to_i}\n\nb.sort!\nn = a[0]\nk = a[1]\n\nif k > b[n-1] \n puts n+1\nelse\n if k < b[0]\n puts n\n else\n x = (n+1)/2 - 1\n if k == b[x]\n puts 0\n else\n if k < b[x]\n i = 0\n while b[i] < k do\n i += 1\n end\n i -= 1 if b[i] != k\n find = n -2*i -2\n puts find\n else\n i = n-1\n while b[i] > k do\n i -= 1\n end\n i -= 1 if b[i] != k\n find = 2*i + 2 - n\n puts find\n end\n end\n end\nend"}, {"source_code": "a = gets.chomp.split(\" \").map{|i| i.to_i}\nb = gets.chomp.split(\" \").map{|i| i.to_i}\n\nb.sort!\nn = a[0]\nk = a[1]\n\nif k > b[n-1] \n puts n+1\nelse\n if k < b[0]\n puts n\n else\n x = (n+1)/2 - 1\n if k == b[x]\n puts 0\n else\n if k < b[x]\n i = 0\n while b[i] < k do\n i += 1\n end\n i -= 1 if b[i] != k\n find = n -2*i -2\n puts find\n else\n i = n-1\n while b[i] > k do\n i -= 1\n end\n i += 1 if b[i] != k\n find = 2*i + 1 - n\n puts find\n end\n end\n end\nend"}, {"source_code": "a = gets.chomp.split(\" \").map{|i| i.to_i}\nb = gets.chomp.split(\" \").map{|i| i.to_i}\n\nb.sort!\nn = a[0]\nk = a[1]\n\nif k > b[n-1] \n puts n+1\nelse\n if k < b[0]\n puts n\n else\n x = (n+1)/2\n if k == b[x]\n puts 0\n else\n if k < b[x]\n i = 0\n while b[i] < k do\n i += 1\n end\n i -= 1 if b[i] != k\n find = n -2*i -2\n puts find\n else\n i = n-1\n while b[i] > k do\n i -= 1\n end\n i -= 1 if b[i] != k\n find = 2*i + 2 - n\n puts find\n end\n end\n end\nend"}], "src_uid": "1a73bda2b9c2038d6ddf39918b90da61"} {"source_code": "n,m=gets.split.map(&:to_i)\ng=[]\nm.times do\n a,b=gets.split.map(&:to_i)\n g< b\n cannot[a] << b\n cannot[b] << a\nend\ncenter = 1\nfor i in 1..n\n if cannot[i].size < cannot[center].size\n center = i\n end\nend\nlink = Array.new(n + 1){Array.new(n + 1, false)}\nroad = []\nfor i in 1..n\n next if i == center\n if cannot[center].include? i\n for j in 1..n\n next if i == j\n next if cannot[i].include? j\n link[i][j] = link[j][i] = true\n road << [i, j]\n for k in 1...j\n next if link[j][k]\n link[i][k] = link[k][i] = true\n road << [i, k]\n end\n break\n end\n else\n link[center][i] = link[i][center] = true\n road << [center, i]\n end\nend\nputs road.size\nroad.each do |r|\n puts r.join(' ')\nend"}, {"source_code": "n,m=gets.split.map(&:to_i)\ng=[]\nm.times do\n a,b=gets.split.map(&:to_i)\n g<>=1\n if(n&1)==1\n puts \"NO\"\n next\n end\n puts \"YES\"\n sum =0\n (1).upto(n) do |i|\n print \"#{i*2} \"\n sum+=i*2\n end\n\n (1).upto(n-1) do |i|\n sum-=i*2-1\n print \"#{i*2-1} \"\n end\n puts sum\nend\n"}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\tif n % 4 == 0\n\t\ta = (1..n / 2).map { _1 * 2 }\n\t\ta.concat((1...n / 2).map { _1 * 2 - 1 } + [n + n / 2 - 1])\n\t\tputs 'YES', a.join(' ')\n\telse\n\t\tputs 'NO'\n\tend\nend\n"}, {"source_code": "# frozen_string_literal: true\n\nclass Result\n def print_result\n n = gets.to_i\n return puts 'NO' if (n / 2).odd?\n\n puts 'YES'\n\n (n / 2).times do |i|\n print (i + 1) * 2, ' '\n end\n (n / 2).times do |i|\n print (i * 2) + 1 + (i + 1 == n / 2 ? n / 2 : 0), ' '\n end\n puts\n end\nend\n\ngets.to_i.times do\n Result.new.print_result\nend\n"}, {"source_code": "1.upto(gets.chomp.to_i) do\n n = gets.chomp.to_i\n if n % 4 != 0\n puts 'NO'\n else\n puts 'YES'\n k = n/2\n (1..k).each {|x| print \"#{2*x} \"; }\n (1..k-1).each {|x| print \"#{2*x-1} \"; }\n puts 3*k-1\n end\nend\n"}, {"source_code": "number_of_testcases = gets.to_s.to_i\n\nnumber_of_testcases.times do |i|\n \n n = gets.to_s.to_i\n h = n/2\n \n if h.odd?\n puts \"No\"\n next\n else\n puts \"Yes\"\n end\n \n 2.step(n, 2){ |i| print \"#{i} \" }\n 1.step(n-3,2){ |i| print \"#{i} \" }\n puts 2 + 2 * (h-1) + (h-1)\nend\n\n"}, {"source_code": "module Enumerable\n def sum\n inject :+\n end\nend\n\ngets.to_i.times do\n n = gets.to_i\n if n%4 != 0\n puts 'NO'\n next\n end\n puts 'YES'\n a, b = [], []\n (0...n/4).each{|i| a[2*i..2*i+1] = [4*i + 2, 4*i + 4]}\n (0...a.size-1).each{|i| b[i] = 2*i + 1}\n b << a.sum - b.sum\n puts a.join(' ') + ' ' + b.join(' ')\nend\n"}, {"source_code": "module Enumerable\n def sum\n inject :+\n end\nend\n\ngets.to_i.times do\n n = gets.to_i\n if n%4 != 0\n puts 'NO'\n next\n end\n puts 'YES'\n a, b = [], []\n (0...n/4).each{|i| a[2*i..2*i+1] = 4*i + 2, 4*i + 4}\n (0...a.size-1).each{|i| b[i] = 2*i + 1}\n b << a.sum - b.sum\n puts a.join(' ') + ' ' + b.join(' ')\nend\n"}, {"source_code": "module Enumerable\n def sum\n inject :+\n end\nend\n\ngets.to_i.times do\n n = gets.to_i\n if n%4 != 0\n puts 'NO'\n next\n end\n puts 'YES'\n a, b = []*(n/2), []*(n/2)\n (0...n/4).each{|i| a[2*i, 2*i + 1] = [4*i + 2, 4*i + 4]}\n (0...a.size-1).each{|i| b[i] = 2*i + 1}\n b << a.sum - b.sum\n puts a.join(' ') + ' ' + b.join(' ')\nend\n"}], "negative_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n if n%4 != 0\n puts 'NO'\n next\n end\n puts 'YES'\n a = []\n (0...n/4).each{|i| a += [4*i + 2, 4*i + 4]}\n (0...n/4).each{|i| a += [4*i + 1, 4*i + 7]}\n puts a.join ' '\nend\n"}, {"source_code": "t=gets.to_i\n(1).upto(t) do\n n=gets.to_i\n n>>=1\n if(n&1)==1\n puts \"NO\"\n next\n end\n puts \"YES\"\n (1).upto(n) do\n print \"2 \"\n end\n (1).upto(n) do |i|\n x=i&1\n x<<=1\n x+=1\n print \"#{x} \"\n end\n puts \"\"\nend\n"}, {"source_code": "t=gets.to_i\n(1).upto(t) do\n n=gets.to_i\n n>>=1\n if(n&1)==1\n puts \"NO\"\n next\n end\n puts \"YES\"\n (1).upto(n) do |i|\n print \"#{i*2} \"\n end\n (1).upto(n) do |i|\n print \"#{i*2-1} \"\n end\n puts \"\"\nend\n"}], "src_uid": "0c7e019e1e955cadacca55b4e823a3e5"} {"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n a=gets.split.map(&:to_i)\r\n s=a.sum\r\n if s%n!=0\r\n puts \"-1\"\r\n next\r\n end\r\n c=0\r\n z=s/n\r\n a.each do |aa|\r\n if aa>z\r\n c+=1\r\n end\r\n end\r\n puts c\r\nend\r\n", "positive_code": [{"source_code": "for t in 0...gets.to_i\r\n\tn = gets.to_i\r\n\ta = gets.split.map(&:to_i)\r\n\tsum = a.sum\r\n\tans = 0;\r\n\tif sum % n > 0\r\n\t\tputs -1\r\n\telsif\r\n\t\t(0...n).each do |i|\r\n\t\t\tif a[i] * n > sum\r\n\t\t\t\tans += 1\r\n\t\t\tend\r\n\t\tend\r\n\t\tputs ans\r\n\tend\r\nend"}], "negative_code": [], "src_uid": "b8554e64b92b1b9458955da7d55eba62"} {"source_code": "def update_hash hash, num\n return hash[num] = true if hash[num].nil?\n hash.delete(num)\n update_hash(hash, num.next)\nend\n\ngets\n\nhash = {}\nb = gets.chomp.split(\" \").map(&:to_i).each{|num| update_hash(hash, num)}\n\nputs hash.keys.max - hash.keys.count + 1\n", "positive_code": [{"source_code": "MAX=(2*10**9)*(10**5)+1\nn=gets.to_i\na=gets.split.map(&:to_i)\na< value\n min_time = value\n min_time_index = entrance\n end\nend\n\np min_time_index + 1\n", "positive_code": [{"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i)\nN.times do |i|\n as[i] = ((as[i]-i-1)/N + 1) * N + i\n as[i] = i if as[i] < i\nend\nputs N.times.min_by{|i| as[i]} + 1"}, {"source_code": "n = gets.to_i\nary = gets.strip.split.map(&:to_i)\n\nminv = ary.min\nsq = minv % n\nexitq = sq\nary.map!{|x| x-minv}\nsq.upto(sq+n-1).each do |i|\n aryi = i % n\n if ary[aryi]<=(i-sq)\n exitq = aryi\n break\n end\nend\n\nputs exitq+1"}], "negative_code": [{"source_code": "number_of_entrances = gets.to_i\nmin_time = 1000000000\nmin_time_index = 0\n\ndef ceiling(num, den)\n (num/den) + (num % den == 0 ? 0 : 1)\nend\n\n0.upto(number_of_entrances - 1) do |entrance|\n no_of_ppl = gets.to_i\n\n x = [0, no_of_ppl - entrance].max\n value = ceiling(x, number_of_entrances)\n\n if min_time > value\n min_time = value\n min_time_index = entrance\n end\nend\n\np min_time_index + 1\n"}], "src_uid": "b18bbefd2a948da9dec1d6f27f219ed1"} {"source_code": "def lscan; gets.split.map(&:to_i); end\n\ngets.to_i.times do\n l, r = lscan\n x = l\n y = l*2\n puts \"#{x} #{y}\"\nend", "positive_code": [{"source_code": "gets;$<.map{|e|puts [n=e.to_i,n*2]*' '}"}, {"source_code": "t = gets.to_i\nt.times do\n\tr,l = gets.split.map(&:to_i)\n\tputs \"#{r} #{r*2}\"\nend"}, {"source_code": "gets.to_i.times do\n l, r = gets.split.map(&:to_i)\n puts \"#{l} #{l*2}\"\nend"}, {"source_code": "n = gets().to_i\n(1..n).each do\n l, r = gets().split.map(&:to_i)\n puts \"#{l} #{l * 2}\"\nend\n"}, {"source_code": "gets.to_i.times do\n l,r = gets.split.map(&:to_i)\n puts \"#{l} #{l*2}\"\nend"}, {"source_code": "t = gets.to_i\nt.times do\n l, r = gets.split.map &:to_i\n print l, ' ', 2*l, \"\\n\"\nend\n"}], "negative_code": [{"source_code": "n = gets().to_i\n(1..n).each do\n l, r = gets().split.map(&:to_i)\n (l..r).each do |x|\n i = 2\n if (x * 2 < r)\n puts \"#{x} #{x * 2}\"\n break\n end\n end\nend\n"}], "src_uid": "a9cd97046e27d799c894d8514e90a377"} {"source_code": "n, k = gets.split.map {|x| Integer x}\nif k * n > n * (n - 1) / 2\n puts -1\n exit\nend\nam = Array.new(n)\ncnt = Array.new(n, n - 1)\nfor i in 0...n\n am[i] = Array.new(n)\nend\nfor i in 0...n\n c = 0\n for j in 0...n\n if cnt[j] == k || i == j || am[i][j] != nil\n next\n end\n am[i][j] = true\n am[j][i] = false\n c += 1\n if c == k\n break\n end\n end\nend\nans = []\nfor i in 0...n\n for j in 0...n\n if am[i][j]\n ans.push((i + 1).to_s + ' ' + (j + 1).to_s)\n end\n end\nend\nputs ans.length\nputs ans", "positive_code": [{"source_code": "\n#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')\n\n\nn,k=gets.split.map(&:to_i)\n\nif 2*k>=n\n\tputs -1\nelse\n\tputs n*k\n\t(1..n).each do |ind|\n\t\t(1..k).each do |ind2|\n\t\t\tputs \"#{ind} #{(ind+ind2-1)%n+1}\"\n\t\tend\n\tend\nend\n\n\n\n\n\n"}, {"source_code": "n,k=gets.split.map &:to_i\nif k > (n-1) / 2\n puts \"-1\"\n exit\nelse\n puts n*k\n n.times do |cmdW|\n k.times do |cmdL|\n puts \"#{cmdW+1} #{(cmdW+1+cmdL)%n + 1}\"\n end\n end\nend\n"}], "negative_code": [{"source_code": "\n#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')\n\n\nn,k=gets.split.map(&:to_i)\n\nif k*(n/2)>=n\n\tputs -1\nelse\n\tputs n*k\n\t(1..n).each do |ind|\n\t\t(1..k).each do |ind2|\n\t\t\tputs \"#{ind} #{(ind+ind2-1)%n+1}\"\n\t\tend\n\tend\nend\n\n\n\n\n\n\n"}, {"source_code": "n, k = gets.split.map {|x| Integer x}\nif k > n * (n - 1) / 4\n puts -1\n exit\nend\nam = Array.new(n)\ncnt = Array.new(n, n - 1)\nfor i in 0...n\n am[i] = Array.new(n)\nend\nfor i in 0...n\n c = 0\n for j in 0...n\n if cnt[j] == k || i == j || am[i][j] != nil\n next\n end\n am[i][j] = true\n am[j][i] = false\n c += 1\n if c == k\n break\n end\n end\nend\nfor i in 0...n\n for j in 0...n\n if am[i][j]\n puts (i + 1).to_s + ' ' + (j + 1).to_s\n end\n end\nend"}, {"source_code": "n, k = gets.split.map {|x| Integer x}\nif k > n * (n - 1) / 4\n puts -1\n exit\nend\nam = Array.new(n)\ncnt = Array.new(n, n - 1)\nfor i in 0...n\n am[i] = Array.new(n)\nend\nfor i in 0...n\n c = 0\n for j in 0...n\n if cnt[j] == k || i == j || am[i][j] != nil\n next\n end\n am[i][j] = true\n am[j][i] = false\n c += 1\n if c == k\n break\n end\n end\nend\nans = []\nfor i in 0...n\n for j in 0...n\n if am[i][j]\n ans.push((i + 1).to_s + ' ' + (j + 1).to_s)\n end\n end\nend\nputs ans.length\nputs ans"}], "src_uid": "14570079152bbf6c439bfceef9816f7e"} {"source_code": "n,m,k = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nans = 0\na = []\nfor i in 1..n-1\n a << b[i]-b[i-1]\nend\na.sort!\nfor i in 0..n-k-1\n ans += a[i]\nend\nputs ans+k", "positive_code": [{"source_code": "DBG = !true\nn,m,k = gets.split.map{|z| z.to_i}\nb = gets.split.map{|z| z.to_i}\nsd = []\nfor i in 1...n\n sd << [i, b[i]-b[i-1]]\nend\nsd.sort_by!{|z| -z[1]}\nprint sd if DBG\n\nd = sd[0,k-1].map{|z| z[0]}\nd.sort!\nprint d if DBG\n\nprev = 0\nsum = 0\nfor x in d\n sum += b[x-1] - b[prev] + 1\n prev = x\nend\nsum += b[-1] - b[prev] + 1\nputs \"#{sum}\"\n"}], "negative_code": [], "src_uid": "6b2b56a423c247d42493d01e06e4b1d2"} {"source_code": "\ndef solution\n n = read_int\n xs = read_ints\n\n max = 0\n\n prefs = Hash.new\n\n sum = 0\n xs.each.with_index do |x, i|\n # p x\n sum += x\n prefs[sum] = i\n end\n\n sum = 0\n (n-1).downto(0) do |j|\n x = xs[j]\n sum += x\n\n if prefs[sum] && prefs[sum] < j\n max = sum\n end\n\n end\n\n puts max\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n", "positive_code": [{"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i)\ntotal = as.inject(:+)\nh1, h2 = {}, {}\nsum = 0\nN.times do |i|\n h1[sum] = true\n sum += as[i]\n break if sum*2 > total\nend\nsum = 0\n(N-1).downto(0) do |i|\n h2[sum] = true\n sum += as[i]\n break if sum*2 > total\nend\nh1.keys.sort.reverse.each do |sum|\n if h2[sum]\n puts sum\n exit\n end\nend"}], "negative_code": [], "src_uid": "f2fc865a44b39179261a7311adf48390"} {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n b = [a.max]\n g = a.max\n max_idx = a.index(g)\n vis = a.map.with_index {|_, a_i| a_i == max_idx ? true : false}\n\n (n - 1).times do\n max_v = -1\n max_i = -1\n a.each_with_index do |a_i, i|\n next if vis[i]\n\n if g.gcd(a_i) > max_v\n max_i = i\n max_v = g.gcd(a_i)\n end\n end\n\n b << a[max_i]\n vis[max_i] = true\n g = max_v\n end\n\n puts b.join(' ')\nend\n", "positive_code": [{"source_code": "require 'prime'\n\nclass Integer\n def divisor_list\n return [] if self <= 0\n return [1] if self == 1\n\n prime_division.map.with_index { |(base, k), i|\n s = i.zero? ? 0 : 1\n (s..k).map { |n| base ** n }\n }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort\n end\nend\n\nT = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n counter = Hash.new(0)\n primes = Hash.new { |h, k| h[k] = [] }\n\n a.each do |x|\n counter[x] += 1\n\n x.prime_division.each do |e, _|\n primes[e] << x\n end\n end\n\n ans = []\n s = a.max\n g = s\n\n loop {\n ans << s\n counter[s] -= 1\n cand = -1\n max_v = -Float::INFINITY\n\n s.prime_division.map(&:first).reverse_each do |e|\n primes[e].each do |num|\n next if counter[num] <= 0\n\n next_gcd = g.gcd(num)\n\n if max_v < next_gcd\n max_v = next_gcd\n cand = num\n end\n end\n end\n\n break if cand == -1\n g = g.gcd(cand)\n s = cand\n }\n\n counter.each do |num, cnt|\n next if cnt <= 0\n\n cnt.times do\n ans << num\n end\n end\n\n puts ans.join(' ')\nend\n"}], "negative_code": [{"source_code": "require 'prime'\n\nT = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n \n counter = Hash.new(0)\n primes = Hash.new { |h, k| h[k] = [] }\n\n a.each do |x|\n counter[x] += 1\n\n x.prime_division.each do |e, cnt|\n primes[e] << x\n end\n end\n\n ans = []\n s = a.max\n\n loop {\n ans << s\n counter[s] -= 1\n cand = -1\n\n s.prime_division.map(&:first).reverse_each do |e|\n primes[e].each do |num|\n next if counter[num] <= 0\n\n cand = num\n break\n end\n\n break if cand != -1\n end\n\n break if cand == -1\n s = cand\n }\n\n counter.each do |num, cnt|\n next if cnt <= 0\n\n cnt.times do\n ans << num\n end\n end\n\n puts ans.join(' ')\nend\n"}, {"source_code": "require 'prime'\n\nclass Integer\n def divisor_list\n return [] if self <= 0\n return [1] if self == 1\n\n prime_division.map.with_index { |(base, k), i|\n s = i.zero? ? 0 : 1\n (s..k).map { |n| base ** n }\n }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort\n end\nend\n\nT = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n counter = Hash.new(0)\n primes = Hash.new { |h, k| h[k] = [] }\n\n a.each do |x|\n counter[x] += 1\n\n x.prime_division.each do |e, _|\n primes[e] << x\n end\n end\n\n ans = []\n s = a.max\n gcd = s\n\n loop {\n ans << s\n counter[s] -= 1\n cand = -1\n max_v = -Float::INFINITY\n\n s.prime_division.reverse_each do |e|\n primes[e].each do |num|\n next if counter[num] <= 0\n\n next_gcd = gcd.gcd(num)\n\n if max_v < next_gcd\n max_v = next_gcd\n cand = num\n end\n end\n end\n\n break if cand == -1\n gcd = gcd.gcd(cand)\n s = cand\n }\n\n counter.each do |num, cnt|\n next if cnt <= 0\n\n cnt.times do\n ans << num\n end\n end\n\n puts ans.join(' ')\nend\n"}, {"source_code": "require 'prime'\n\nclass Integer\n def divisor_list\n return [] if self <= 0\n return [1] if self == 1\n\n prime_division.map.with_index { |(base, k), i|\n s = i.zero? ? 0 : 1\n (s..k).map { |n| base ** n }\n }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort\n end\nend\n\nT = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n counter = Hash.new(0)\n primes = Hash.new { |h, k| h[k] = [] }\n\n a.each do |x|\n counter[x] += 1\n\n x.prime_division.each do |e, _|\n primes[e] << x\n end\n end\n\n ans = []\n s = a.max\n gcd = s\n\n loop {\n ans << s\n counter[s] -= 1\n cand = -1\n max_v = -Float::INFINITY\n\n s.prime_division.map(&:first).reverse_each do |e|\n primes[e].each do |num|\n next if counter[num] <= 0\n\n next_gcd = gcd.gcd(num)\n\n if max_v < next_gcd\n max_v = next_gcd\n cand = num\n end\n end\n end\n\n break if cand == -1\n gcd = s.gcd(cand)\n s = cand\n }\n\n counter.each do |num, cnt|\n next if cnt <= 0\n\n cnt.times do\n ans << num\n end\n end\n\n puts ans.join(' ')\nend\n"}, {"source_code": "require 'prime'\n\nclass Integer\n def divisor_list\n return [] if self <= 0\n return [1] if self == 1\n\n prime_division.map.with_index { |(base, k), i|\n s = i.zero? ? 0 : 1\n (s..k).map { |n| base ** n }\n }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort\n end\nend\n\nT = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n counter = Hash.new(0)\n primes = Hash.new { |h, k| h[k] = [] }\n\n a.each do |x|\n counter[x] += 1\n\n x.divisor_list.each do |e, _|\n primes[e] << x\n end\n end\n\n ans = []\n s = a.max\n gcd = s\n\n loop {\n ans << s\n counter[s] -= 1\n cand = -1\n max_v = -Float::INFINITY\n\n s.divisor_list.reverse_each do |e|\n primes[e].each do |num|\n next if counter[num] <= 0\n\n next_gcd = gcd.gcd(num)\n\n if max_v < next_gcd\n max_v = next_gcd\n cand = num\n end\n end\n end\n\n break if cand == -1\n gcd = s.gcd(cand)\n s = cand\n }\n\n counter.each do |num, cnt|\n next if cnt <= 0\n\n cnt.times do\n ans << num\n end\n end\n\n puts ans.join(' ')\nend\n"}, {"source_code": "require 'prime'\n\nclass Integer\n def divisor_list\n return [] if self <= 0\n return [1] if self == 1\n\n prime_division.map.with_index { |(base, k), i|\n s = i.zero? ? 0 : 1\n (s..k).map { |n| base ** n }\n }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort\n end\nend\n\nT = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n counter = Hash.new(0)\n primes = Hash.new { |h, k| h[k] = [] }\n\n a.each do |x|\n counter[x] += 1\n\n x.divisor_list.each do |e, cnt|\n primes[e] << x\n end\n end\n\n ans = []\n s = a.max\n\n loop {\n ans << s\n counter[s] -= 1\n cand = -1\n\n s.divisor_list.reverse_each do |e|\n primes[e].each do |num|\n next if counter[num] <= 0\n\n cand = num\n break\n end\n\n break if cand != -1\n end\n\n break if cand == -1\n s = cand\n }\n\n counter.each do |num, cnt|\n next if cnt <= 0\n\n cnt.times do\n ans << num\n end\n end\n\n puts ans.join(' ')\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n b = [a.max]\n g = a.max\n vis = a.map {|a_i| a_i == g ? true : false}\n\n (n - 1).times do\n max_v = -1\n max_i = -1\n a.each_with_index do |a_i, i|\n next if vis[i]\n\n if g.gcd(a_i) > max_v\n max_i = i\n max_v = g.gcd(a_i)\n end\n end\n\n b << a[max_i]\n vis[max_i] = true\n g = max_v\n end\n\n puts b.join(' ')\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n b = [a.max]\n g = a.max\n vis = a.map {|a_i| a_i == g ? true : false}\n\n (n - 1).times do\n max_v = -1\n max_i = -1\n max_ai = -1\n a.each_with_index do |a_i, i|\n next if vis[i]\n\n if g.gcd(a_i) > max_v || (g.gcd(a_i) == max_v && a_i > max_ai)\n max_i = i\n max_v = g.gcd(a_i)\n max_ai = a_i\n end\n end\n\n b << a[max_i]\n vis[max_i] = true\n g = max_v\n end\n\n puts b.join(' ')\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n max_v = a.max\n b = a.map {|a_i| [a_i, a_i.gcd(max_v)]}.sort_by {|av, gv| [-gv, -av]}.map(&:first)\n puts b.join(' ')\nend\n"}], "src_uid": "bdd1974e46f99eff3d03ed4174158dd9"} {"source_code": "n = gets.to_i\narr = gets.split(\" \").map{|i| i.to_i}\nsum = arr.inject(:+)\nmax = arr.max\nans = (sum + n - 2) / (n - 1)\nputs max > ans ? max : ans", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\namax = a.max\nans = 0\na.each{|aa| ans += amax-aa}\nif amax <= ans\n puts amax\nelse\n amax -= ans\n ans += amax/(n-1)*n\n amax %= n-1\n ans += amax+1 if amax > 0\n puts ans\nend\n"}, {"source_code": "n=gets.to_i; d=gets.split.map(&:to_i); p [d.max,(d.reduce(&:+)+n-2)/(n-1)].max"}, {"source_code": "#! /usr/bin/env ruby\n\nn = STDIN.gets.to_i\nrounds = STDIN.gets.to_s.split(' ').map(&:to_i).take(n)\n\nif rounds.length != n\n raise ArgumentError.new\nend\n\ndef how_many(rounds, n)\n max = rounds.max\n diff_total = rounds.inject(0) {|diff, round| diff += max - round}\n\n if diff_total >= max\n max\n else\n n -= 1\n rest = max - diff_total\n max + (rest / n) + (rest % n == 0 ? 0 : 1)\n end\nend\n\nputs how_many(rounds, n)\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\namax = a.max\nans = 0\na.each{|aa| ans += amax-aa}\nif amax <= ans\n puts amax\nelse\n amax -= ans\n ans += amax/(n-1)*n\n amax %= n-1\n ans += amax+1 if amax > 0\n puts ans\nend\n"}, {"source_code": "\n\nn=gets.to_i; d=gets.split.map(&:to_i); p [d.max,(d.reduce(&:+)+n-2)/(n-1)].max"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nmx, s = [0, 0]\na.each {|i|\n mx = [mx, i].max\n s += i\n}\nputs [mx, (s+n-2).div(n.pred)].max"}], "negative_code": [{"source_code": "#! /usr/bin/env ruby\n\nn = STDIN.gets.to_i\nrounds = STDIN.gets.to_s.split(' ').map(&:to_i).sample(n)\n\nif rounds.length != n\n raise ArgumentError.new\nend\n\ndef how_many(rounds)\n max = rounds.max\n diff_total = rounds.inject(0) {|diff, round| diff += max - round}\n\n if diff_total == 0\n return max + (max / rounds.length) + ( max % rounds.length == 0 ? 0 : 1)\n end\n\n if diff_total >= max\n return max\n end\n\n max + (max - diff_total)\nend\n\nputs how_many(rounds)\n\n"}, {"source_code": "#! /usr/bin/env ruby\n\nn = STDIN.gets.to_i\nrounds = STDIN.gets.to_s.split(' ').map(&:to_i).sample(n)\n\nif rounds.length != n\n raise ArgumentError.new\nend\n\ndef how_many(rounds)\n max = rounds.max\n diff_total = rounds.inject(0) {|diff, round| diff += max - round}\n\n if diff_total == 0\n return max + (max / rounds.length) + 1\n end\n\n if diff_total >= max\n return max\n end\n\n return max + (max - diff_total)\nend\n\nputs how_many(rounds)\n\n"}, {"source_code": "#! /usr/bin/env ruby\n\nn = STDIN.gets.to_i\nrounds = STDIN.gets.to_s.split(' ').map(&:to_i).take(n)\n\nif rounds.length != n\n raise ArgumentError.new\nend\n\ndef how_many(rounds, n)\n max = rounds.max\n diff_total = rounds.inject(0) {|diff, round| diff += max - round}\n\n if diff_total == 0\n return max + (max / n) + ( max % n == 0 ? 0 : 1)\n end\n\n if diff_total >= max\n return max\n end\n\n max + (max - diff_total)\nend\n\nputs how_many(rounds, n)\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\namax = a.max\ncnt = 0\na.each{|aa| cnt += amax-aa}\nif amax <= cnt\n puts amax\nelse\n amax -= cnt\n puts cnt+amax/(n-1)*n+amax%(n-1)+1\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\namax = a.max\ncnt = 0\na.each{|aa| cnt += amax-aa}\namax -= cnt\nif amax <= 0\n puts cnt\nelse\n puts cnt+amax/(n-1)*n+amax%(n-1)+1\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\namax = a.max\ncnt = 0\na.each{|aa| cnt += amax-aa}\namax -= cnt\nif amax.zero?\n puts cnt\nelse\n puts cnt+amax/(n-1)*n+amax%(n-1)+1\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\namin, amax = a.minmax\nans = 0\nif amin/(n-1) > 0\n amax -= amin\n ans += amin/(n-1)*n\n amin %= n-1\nend\nif amax != amin\n ans += amax\nelse\n ans += amax+1\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\namax = a.max\ncnt = 0\na.each{|aa| cnt += amax-aa}\namax -= cnt\nputs cnt+amax/(n-1)*n+amax%(n-1)+1\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\nputs a.max+1\n"}, {"source_code": "n = gets.to_i\na = gets.split.collect{|i| i.to_i}\namin, amax = a.minmax\nans = 0\nif amin/(n-1) > 0\n amax -= amin\n ans += amin/(n-1)*n\n amin %= n-1\nend\nif amin.zero?\n ans += amax\nelse\n ans += amax+1\nend\nputs ans\n"}, {"source_code": "346"}, {"source_code": "people = gets.to_i\ntake_rounds = gets.split.map(&:to_i)\nmax = take_rounds.max\nsum = take_rounds.reduce(&:+)\nif sum <= max * people.pred\n puts max\nelse\n puts max.next\nend"}], "src_uid": "09f5623c3717c9d360334500b198d8e0"} {"source_code": "require 'prime'\nt = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n arr = n.prime_division\n res = []\n while arr.any? \n res << arr.map{|el| el[0]}.inject(:*)\n arr = arr.map{|el| [el[0], el[1] - 1]}\n arr.filter! {|el| el[1] > 0}\n end\n puts res.size\n puts res.reverse.join(' ')\nend", "positive_code": [{"source_code": "require'prime'\ngets;$<.map{|l|i=l.to_i;x,y=i.prime_division.map{|k,v|[v-1,k]}.max;p x+1;puts ([y]*x+[i/y**x])*' '}"}, {"source_code": "require'prime'\ngets;$<.map{|l|i=l.to_i;x,y=i.prime_division.map{|k,v|[v-1,k]}.max;puts [x+1]+[y]*x+[i/y**x]}"}, {"source_code": "\nrequire'prime'\ngets;$<.map{|l|i=l.to_i;x,y=i.prime_division.map{|k,v|[v-1,k]}.max;puts [x+1]+[y]*x+[i/y**x]}"}], "negative_code": [], "src_uid": "f8d064c90f1f2b4a18386795dbcd9cb9"} {"source_code": "t = gets.chomp.to_i\nt.times do\n hash = {}\n n = gets.chomp.to_i\n a = gets.split.map{|_|_.to_i}\n a.each_with_index do |num, i|\n hash[num-i] = (hash[num-i] || 0) + 1\n end\n puts hash.values.map{|v| v*(v-1)/2}.sum\nend", "positive_code": [{"source_code": "t = gets.chomp.to_i\n\nt.times do\n hash = {}\n n = gets.chomp.to_i\n a = gets.split.map{|_|_.to_i}\n a.each_with_index do |num, i|\n hash[num-i] = (hash[num-i] || 0) + 1\n end\n rs = 0\n hash.values.each{|v| rs+=v*(v-1)/2}\n puts rs\nend"}, {"source_code": "def read_test_case\n # @type [String]\n line = gets.chomp\n # &: notation is sometimes called 'pretzel colon'\n # Kind of like a method references? It's syntax sugar for some Proc magic:\n # &:to_i == { |foo| foo.to_i }\n # :to_i here is a symbol, and:\n line.split(' ').map(&:to_i)\nend\n\n# @param nums [Array]\ndef get_diff_array(nums)\n nums.map.each_with_index do |num, idx|\n # Problem uses 1 indexing, so I'll be consistent\n num - (idx + 1)\n end\nend\n\n# @param diffs [Array]\ndef count_diff_array(diffs)\n counts = {}\n diffs.each do |diff|\n if !counts.include? diff\n counts[diff] = 1\n else\n counts[diff] += 1\n end\n end\n counts\nend\n\n# @param counts [Hash]\ndef count_total_pairs(counts)\n pairs = 0\n counts.each_value do |count|\n pairs += compute_triangular_number(count - 1)\n end\n pairs\nend\n\ndef compute_triangular_number(n)\n (n * (n + 1)) / 2\nend\n\n# @type[Integer]\nt = gets.chomp.to_i\n\n(1..t).each do\n _test_size = gets\n\n test = read_test_case\n diff_array = get_diff_array test\n counts = count_diff_array diff_array\n puts count_total_pairs counts\nend\n"}, {"source_code": "t = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.strip.split.map {|x| x.to_i }\n 0.upto(n - 1) {|i| a[i] -= i }\n cnt = {}\n a.each {|x| cnt[x] = (cnt[x] || 0) + 1 }\n result = 0\n cnt.each {|k, v| result += v * (v - 1) / 2 }\n printf(\"%d\\n\", result)\nend\n"}], "negative_code": [], "src_uid": "ac4aac095e71cbfaf8b79262d4038095"} {"source_code": "a, b, c = gets.split.map(&:to_i)\nx = 0\nif a>=b && a>=c\n x+=1 if a!=b\n x+=1 if a!=c\n p a-b+a-c-x\nelsif c>=b && c>=a\n x+=1 if c!=b\n x+=1 if c!=a\n p c-b+c-a-x\nelse\n x+=1 if c!=b\n x+=1 if b!=a\n p b-c+b-a-x\nend\n ", "positive_code": [{"source_code": "def ev(arr)\n arr.sort!\n arr[2] - arr[0] + arr[2] - arr[1]\nend\n\nb, d, s = gets.strip.split(' ').map(&:to_i)\nmn = [b, d, s].min\nb -= mn\nd -= mn\ns -= mn\nif b == d && d == s\n printf(\"%d\\n\", 0)\nelse\n v = []\n arr = [b, d, s]\n 0.upto(2) do |i|\n 0.upto(2) do |j|\n arr_c1 = arr.clone\n arr_c1[i] += 1\n arr_c2 = arr.clone\n arr_c2[j] += 1\n arr_c3 = arr.clone\n arr_c3[i] += 1\n arr_c3[j] += 1 if i != j\n v << ev(arr_c1)\n v << ev(arr_c2)\n v << ev(arr_c3)\n end\n end\n\n printf(\"%d\\n\", v.min)\nend\n"}, {"source_code": "a=gets.split.map(&:to_i)\nm=a.max-1\np a.select{|e|es)==-1\n}\na, b, c=t\n\nres=1<<64\nx=[(a-b-1)+(a-c-1)+(a>b ? 0 : 1), 0].max\ny=[(a-b)+(a-c-1)+(b>c ? 0 : 1), 0].max\nz=(a-b)+(a-c)\n\np [x, y, z].min\n"}, {"source_code": "a=gets.split.map &:to_i\nm=a.max-r=1\na.map{|e|e meat_cnt[0]\n meat_cnt[1]-=1 if meat_cnt[2]==meat_cnt[1]\n meat_cnt[2]-=1\n return 0 if meat_cnt.all? {|x| x==meat_cnt[2]}\n meat_at_first_day=true\n end\n\n if meat_cnt.max == meat_cnt[0] && meat_cnt[0]>meat_cnt[2]\n meat_cnt[1]-=1 if meat_cnt[0]== meat_cnt[1]\n meat_cnt[0]-=1\n return 0 if meat_cnt.all? {|x| x==meat_cnt[0]}\n meat_at_last_day=true\n end\n\n if meat_cnt.max == meat_cnt[1]\n if !meat_at_last_day && meat_cnt[1]>meat_cnt[2]\n meat_cnt[1]-=1\n if meat_cnt[0]>0\n meat_cnt[0]-=1\n else\n result+=1\n end\n end\n if !meat_at_first_day && meat_cnt[1]>meat_cnt[0]\n meat_cnt[1]-=1\n if meat_cnt[2]>0\n meat_cnt[2]-=1\n else\n result+=1\n end\n end\n return result if meat_cnt.all? {|x| x==meat_cnt[1]}\n end\n meat_cnt=(meat_cnt.map { |x| x-meat_cnt.min })\n return 0 if meat_cnt.all? {|x| x.zero?}\n result+=case meat_cnt.count(0)\n when 2\n meat_cnt.reduce(:+)*2\n when 1\n meat_cnt.select {|x| x.nonzero?}.minmax.reduce(0) {|sum,x| (sum.zero?) ? (sum-x):(sum+x*2)}\n end\n end\n\n def self.run\n puts get_advice($stdin.readline.chomp.split.map(&:to_i))\n end\nend\n\nif __FILE__ == $0\n Sanatorium.run\nend"}], "negative_code": [{"source_code": "a, b, c = gets.split.map(&:to_i)\np [[a, b, c].max-[a, b, c].min-1, 0].max"}, {"source_code": "\na = gets.split.map &:to_i\nm = a.max - r = 1\na.map{|e| e < m && r += m - e; puts r}\np r - 1\n"}, {"source_code": "a=gets.split.map &:to_i\ndef solution(b,d,s)\n\tmax = [b,d,s].max\n\tsum = 0\n\tcase max\n\twhen b\n\t\tsum += max - d - 1 if max > d + 1\n\t\tsum += max - s - 1 if max > s + 1\n\twhen d\n\t\tsum += max - b if max > b\n\t\tsum += max - s - 1 if max > s + 1\n\twhen s\n\t\tsum += max - b if max > b\n\t\tsum += max - d if max > d\n\tend\n\tsum\nend\np solution(a[0],a[1],a[2])\n"}, {"source_code": "a=gets.split.map &:to_i\ndef solution(b,d,s)\n\tmax = [b,d,s].max\n\tsum = 0\n\tcase max\n\twhen b\n\t\tsum += max - d - 1 if max > d + 1\n\t\tsum += max - s - 1 if max > s + 1\n\twhen d\n\t\tsum += max - b if max > b && b != 0\n\t\tsum += max - s - 1 if max > s + 1\n\twhen s\n\t\tsum += max - b if max > b && b != 0\n\t\tsum += max - d if max > d && d != 0\n\tend\n\tsum\nend\np solution(a[0],a[1],a[2])"}, {"source_code": "def ev(arr)\n b, d, s = arr\n (b - d).abs + (d - s).abs\nend\n\nb, d, s = gets.strip.split(' ').map(&:to_i)\nmn = [b, d, s].min\nb -= mn\nd -= mn\ns -= mn\nif b == d && d == s\n printf(\"%d\\n\", 0)\nelse\n v = []\n arr = [b, d, s]\n 0.upto(2) do |i|\n 0.upto(2) do |j|\n arr_c1 = arr.clone\n arr_c1[i] -= 1\n arr_c2 = arr.clone\n arr_c2[j] -= 1\n arr_c3 = arr.clone\n arr_c3[i] -= 1\n arr_c3[j] -= 1\n v << ev(arr_c1)\n v << ev(arr_c2)\n v << ev(arr_c3)\n end\n end\n printf(\"%d\\n\", v.min)\nend\n"}, {"source_code": "b, d, s = gets.strip.split(' ').map(&:to_i)\nmn = [b, d, s].min\nb -= mn\nd -= mn\ns -= mn\nif b == d && d == s\n printf(\"%d\\n\", 0)\nelse\n arr = [b, d, s]\n mx = -1\n cnt = 0\n arr.each do |l|\n if l > mx\n mx = l\n cnt = 1\n elsif l == mx\n cnt += 1\n end\n end\n if cnt == 2\n 0.upto(2) do |i|\n arr[i] -= 1 if mx == arr[i]\n end\n printf(\"%d\\n\", arr.max - arr.min)\n else\n 0.upto(2) do |i|\n arr[i] -= 1 if mx == arr[i]\n end\n printf(\"%d\\n\", arr.max - arr.min) \n end\nend\n"}, {"source_code": "b, d, s = gets.strip.split(' ').map(&:to_i)\nmn = [b, d, s].min\nb -= mn\nd -= mn\ns -= mn\nif b == d && d == s\n printf(\"%d\\n\", 0)\nelse\n arr = [b, d, s]\n mx = -1\n cnt = 0\n arr.each do |l|\n if l > mx\n mx = l\n cnt = 1\n elsif l == mx\n cnt += 1\n end\n end\n if cnt == 2\n 0.upto(2) do |i|\n arr[i] -= 1 if mx == arr[i]\n end\n printf(\"%d\\n\", arr.max - arr.min)\n else\n 0.upto(2) do |i|\n arr[i] -= 1 if mx == arr[i]\n end\n if arr.uniq == 3\n printf(\"%d\\n\", (arr[0] - arr[1]).abs + (arr[1] - arr[2]).abs - 1) \n else\n printf(\"%d\\n\", arr.max - arr.min)\n end\n end\nend\n"}, {"source_code": "def ev(arr)\n b, d, s = arr\n ((b - d).abs + (d - s).abs + (s - b).abs) / 2\nend\n\nb, d, s = gets.strip.split(' ').map(&:to_i)\nmn = [b, d, s].min\nb -= mn\nd -= mn\ns -= mn\nif b == d && d == s\n printf(\"%d\\n\", 0)\nelse\n v = []\n arr = [b, d, s]\n 0.upto(2) do |i|\n 0.upto(2) do |j|\n arr_c1 = arr.clone\n arr_c1[i] -= 1\n arr_c2 = arr.clone\n arr_c2[j] -= 1\n arr_c3 = arr.clone\n arr_c3[i] -= 1\n arr_c3[j] -= 1\n v << ev(arr_c1)\n v << ev(arr_c2)\n v << ev(arr_c3)\n end\n end\n printf(\"%d\\n\", v.min)\nend\n"}], "src_uid": "b34846d90dc011f2ef37a8256202528a"} {"source_code": "gets.to_i.times do\r\n gets\r\n puts gets.chomp.chars.sort == 'Timur'.chars.sort ? :YES : :NO\r\nend\r\n", "positive_code": [{"source_code": "t = gets.chomp.to_i \r\n\r\nfor i in 0..t-1\r\n \r\n n = gets.chomp.to_i \r\n name = gets.chomp\r\n if name = name.chars.sort.join == \"Timru\"\r\n puts \"YES\"\r\n else \r\n puts \"NO\"\r\n end\r\n \r\nend"}, {"source_code": "gets.to_i.times do\r\n gets\r\n puts gets.chomp.chars.sort == 'Timur'.chars.sort ? :YES : :NO\r\nend"}], "negative_code": [{"source_code": "t = gets.chomp.to_i \r\n\r\nfor i in 0..t-1\r\n \r\n n = gets.chomp.to_i \r\n name = gets.chomp\r\n if name = name.chars.sort.join == \"Timru\"\r\n print \"Yes\"\r\n else \r\n print \"No\"\r\n end\r\n \r\nend"}], "src_uid": "6c137a74b36dede61037cb3b05167329"} {"source_code": "T = gets.to_i\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n a.unshift(0) if n.odd?\n n = a.size\n puts (0 ... n / 2 - 1).all? { |i| a[i * 2, 2].max <= a[i * 2 + 2, 2].min } ? \"YES\" : \"NO\"\nend", "positive_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n as = gets.split.map(&:to_i)\r\n ((as.size % 2)..as.size - 2).step(2).each do |i|\r\n if as[i] > as[i + 1]\r\n as[i], as[i + 1] = as[i + 1], as[i]\r\n end\r\n end\r\n ok = as.each_cons(2).all? { |a, b| a <= b }\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n as = gets.split.map(&:to_i)\r\n (0..as.size - 2).step(2).each do |i|\r\n if as[i] > as[i + 1]\r\n as[i], as[i + 1] = as[i + 1], as[i]\r\n end\r\n end\r\n ok = as.each_cons(2).all? { |a, b| a <= b }\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n"}, {"source_code": "T = gets.to_i\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n a << 10**18 if n.odd?\n n = a.size\n puts (0 ... n / 2 - 1).all? { |i| a[i * 2, 2].max <= a[i * 2 + 2, 2].min } ? \"YES\" : \"NO\"\nend"}], "src_uid": "95b35c53028ed0565684713a93910860"} {"source_code": "def is_pal?(s)\n half = s.size / 2\n s[0...half] === s[-half..-1].reverse\nend\n\ngets.to_i.times {\n s = gets.chomp\n if s.count('a') === s.size\n puts 'NO'\n else\n puts 'YES'\n s2 = \"a#{s}\"\n if !is_pal?(s2)\n puts s2\n else\n puts \"#{s}a\"\n end\n end\n}\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n s=gets.chomp\r\n z=s.size\r\n i=0\r\n j=z-1\r\n f=false\r\n while i<=j\r\n if s[i]==\"a\"&&s[j]==\"a\"\r\n i+=1\r\n j-=1\r\n elsif s[j]==\"a\"\r\n puts \"YES\"\r\n if j==z-1\r\n puts s+\"a\"\r\n else\r\n puts s[0..j]+\"a\"+s[j+1..]\r\n end\r\n f=true\r\n break\r\n else\r\n puts \"YES\"\r\n if i==0\r\n puts \"a\"+s\r\n else\r\n puts s[0...i]+\"a\"+s[i..]\r\n end\r\n f=true\r\n break\r\n end\r\n end\r\n if !f\r\n puts \"NO\"\r\n end\r\nend\r\n\r\n"}, {"source_code": "def palindrome?(string)\n string == string.reverse\nend\n\n# returns correct string if found else returns nil\ndef no_palindrome(string)\n # appending 'a' before or after a string is enough to break a palindrome\n return \"a#{string}\" unless palindrome?(\"a#{string}\")\n return \"#{string}a\" unless palindrome?(\"#{string}a\")\n\n nil\nend\n\n# prints output for test cases\ndef print_answer(string)\n answer = no_palindrome(string)\n\n return puts 'NO' if answer.nil?\n\n puts 'YES'\n puts answer\nend\n\n#### code for tests:\n\nnumber_of_cases = gets.chomp.to_i\n\nnumber_of_cases.times do\n string = gets.chomp\n print_answer(string)\nend\n"}, {"source_code": "n=gets.rstrip.to_i\nn.times do\n s=gets.rstrip\n valid=false\n s.each_char do |c|\n if c!='a'\n valid=true\n break\n end\n end\n if valid\n puts \"YES\"\n s2=s+'a'\n if s2==s2.reverse\n puts 'a'+s\n else\n puts s2\n end\n else\n puts \"NO\"\n end\n end"}], "negative_code": [], "src_uid": "e2dc3de62fc45c7e9ddb92daa5c5d8de"} {"source_code": "n = gets.strip.to_i\nar = gets.strip.split.map(&:to_i)\nm = ar.min\na = ar.each_with_index.select{|e, i| e == m}\nc = a.reduce([]){|res, e| res < ans\nend\n\np ans\n"}, {"source_code": "n = Integer(gets)\ns = gets\nmas = s.split(\" \")\na = Array.new(n, Array.new(2))\nfor i in 0...n \n a[i] = [i, mas[i].to_i]\nend\n\na.sort! do |x, y|\n if x[1] < y[1]\n -1\n elsif x[1] > y[1]\n 1\n else\n x[0] <=> y[0]\n end \nend\n\ndef max(x, y) \n if x > y\n return x\n else \n return y\n end\nend\n\nans = a[0][1] * n\n\nx = 0\ni = 0\npL = a[0][0]\npR = a[0][0]\nwhile i + 1 < n && a[i][1] == a[i + 1][1]\n pR = a[i + 1][0]\n x = max(x, pR - a[i][0])\n i += 1\nend\n\nx = max(x, n - pR + pL) - 1\nans += x\nputs ans\n"}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\n\namin = 10**9\nhs = Hash.new{ |hs, k| hs[k] = [] }\n\nfor i in 0...n\n a = as[i]\n amin = [amin, a].min\n hs[a] << i\nend\n\ncols = n - 1 - hs[amin][-1] + hs[amin][0]\nfor i in 1...hs[amin].size\n cols = [cols, hs[amin][i] - hs[amin][i - 1] - 1].max\nend\n\nputs n * amin + cols\n"}, {"source_code": "n = gets.chomp.to_i\njars = gets.chomp.split(\" \").map(&:to_i)\njarmin = jars.min\nif jars.uniq.length == 1 then\n puts jars.length * jarmin\nelse\n jars = jars * 2\n rem = 0\n i = 0\n while true\n break if jars.empty?\n j = jars.shift\n if j == jarmin then\n rem = [rem, i].max\n i = 0\n else\n i += 1\n end\n end\n puts n * jarmin + [rem, i].max\nend\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\n\namin = 10**9\nfst = Hash.new(n - 1)\nlst = Hash.new(0)\n\nfor i in 0...n\n a = as[i]\n amin = [amin, a].min\n fst[a] = [fst[a], i].min\n lst[a] = [lst[a], i].max\nend\n\nputs n * (amin + 1) - (lst[amin] - fst[amin] + 1)\n"}, {"source_code": "n = Integer(gets)\ns = gets\na = Array.new(n, Array.new(2))\nt = 0\nsz = 0\nfor i in 0...s.length\n c = s[i]\n if c == \" \"\n a[sz] = [sz, t]\n t = 0\n sz += 1\n else\n t = t * 10 + c.to_i\n end\nend\na[sz] = [sz,t]\nsz += 1\nt = 0\n\na.sort! do |x, y|\n if x[1] < y[1]\n -1\n elsif x[1] > y[1]\n 1\n else\n x[0] <=> y[0]\n end \nend\n\ndef max(x, y) \n if x > y\n return x\n else \n return y\n end\nend\n\nans = a[0][1] * n\n\nx = 0\ni = 0\npL = a[0][0]\npR = a[0][0]\nwhile i + 1 < n && a[i][1] == a[i + 1][1]\n pR = a[i + 1][0]\n x = max(x, pR - a[i][0])\n i += 1\nend\n\nx = max(x, n - pR + pL) - 1\nans += x\nputs ans\n"}], "src_uid": "e2db09803d87362c67763ef71e8b7f47"} {"source_code": "require 'set'\n\nstr = gets.chomp\n\n# nunmber = -1\n# string = input\n# index = input\ndef fun(number, str, index, length)\n\t\n\tif index >=length\n\t\treturn 0\n\tend\n\n\tif number == -1\n\t\tnumber = str[index].to_i\n\telse\n\t\tnumber *= 10 + str[index].to_i\n\tend\n\n\tif number % 3 == 0\n\t\treturn 1 + fun(-1, str, index + 1, length)\n\telse\n\t\treturn [fun(number, str, index + 1, length), fun(-1, str, index + 1, length)].max\n\tend\nend\n\ndef dp_fun(str, length)\n\ta = str.split('').map(&:to_i)\n\tdp_a = Array.new(length, 0)\n\tindex_i = 0\n\tindex_j = -1\n\twhile index_i < length\n\t\ti = index_i\n\t\tnumber = 0\n\t\t(dp_a[index_i] += dp_a[index_i - 1]) if (index_i -1 >= 0)\n\t\twhile i > index_j\n\t\t\tnumber *= 10\n\t\t\tnumber += a[i]\n\t\t\tif number % 3 == 0\n\t\t\t\tdp_a[index_i] += 1\n\t\t\t\tindex_j = index_i\n\t\t\t\tbreak\n\t\t\tend\n\t\t\ti -= 1\n\t\tend\n\t\tindex_i += 1\n\tend\n\treturn dp_a[length-1]\nend\n\nprint dp_fun(str, str.size)", "positive_code": [{"source_code": "\ndef max_div_3(digit_string)\n digits = digit_string.chomp.chars.map(&:to_i)\n\n prefix_sums = [0]\n crt = 0\n digits.each do |d|\n crt += d\n prefix_sums << crt\n end\n\n count = 0\n i = 0\n j = 0\n\n while j < digits.size\n start_index = (i..j).find do |k|\n range_sum = prefix_sums[j + 1] - prefix_sums[k]\n range_sum % 3 < 1\n end\n\n if start_index\n count += 1\n j = j + 1\n i = j\n else\n j = j + 1\n end\n end\n\n count\nend\n\ndef solution\n input = gets\n puts(max_div_3(input))\nend\n\nsolution"}, {"source_code": "S = gets.chomp.split('').map{|c| c.to_i % 3}\nA = [true, false, false]\narr = A.dup\nsum = 0\nans = 0\nS.each do |a|\n sum = (sum + a) % 3\n if arr[sum]\n ans += 1\n sum = 0\n arr = A.dup\n else\n arr[sum] = true\n end\nend\nputs ans"}, {"source_code": "ary = gets.strip.split('').map(&:to_i)\nn = ary.size\ndp = Array.new(n+5, 0)\n\ndp[0] = (ary[0]%3==0 ? 1 : 0)\n\n1.upto(n-1).each do |i|\n sum = 0\n dp[i] = dp[i-1]\n i.downto(0).each do |j|\n sum += ary[j]\n if sum%3 ==0\n dp[i] = [dp[i], ((j>0 ? dp[j-1] : 0) + 1)].max\n break\n end\n break if dp[j]> 1\n}"}, {"source_code": "gets.to_i.times do\n a, b, c = gets.split.map(&:to_i)\n puts (a + b + c) / 2\nend"}, {"source_code": "times = gets.chomp\nary = []\nansw = []\n\ntimes.to_i.times do \n ary.push(gets.chomp.split(\" \").map(&:to_i))\nend\n\nary.each do |ele|\n a = ele.delete_at(ele.index(ele.min))\n b = ele.delete_at(ele.index(ele.min))\n max = ele.last\n\n if a == b && b == max\n answ << (a+b+max)/2\n next\n end\n \n tmp = b-a\n \n if tmp > 0\n t_shr = max - tmp\n if t_shr%2 == 0\n shr = t_shr/2\n else\n shr = (t_shr-1)/2\n end \n answ << shr+tmp+[a,b].min\n elsif tmp == 0\n if max%2 == 0\n a = a + (max/2)\n else\n a = a + ((max-1)/2)\n end\n answ << a \n end\nend\n\nansw.each do |ele|\n puts \"#{ele}\\n\"\nend \n"}, {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\n\ndef puts_yesno(can) puts(can ? 'Yes' : 'No') end\ndef putsend(s) puts s; exit end\ndef debug(k,v) puts \"#{k}:#{v}\" end\n########### ( \u02d8\u03c9\u02d8 )\uff7d\uff94\uff67\u2026 ###########\nq = gi\nans = []\nq.times do\n a, b, c = gsmi\n ans << (a+b+c)/2\nend\nputs ans\n"}, {"source_code": "1.upto(gets.to_i) do\n puts gets.split(' ').map(&:to_i).inject(&:+).div(2)\nend\n"}, {"source_code": "t=gets.to_i\n(1).upto(t) do |i|\n x = gets.split(' ').map(&:to_i)\n x[0]+=x[1]\n x[0]+=x[2]\n puts x[0]>>1\nend\n\n"}], "negative_code": [], "src_uid": "d9e4a9a32d60e75f3cf959ef7f894fc6"} {"source_code": "# coding: utf-8\n\nn = gets.to_i\nn.times {\n s = gets.chomp.split(//).map(&:to_i)\n total = s.length\n ones = s.count(1)\n zeroes = s.count(0)\n # 0->1\uacfc, 1->0\uc73c\ub85c \ubaa8\ub450 \ub4a4\uc9d1\ub294 \uacbd\uc6b0\uc5d0 \ub300\ud55c \uae30\ubcf8\ud574(\uc774\uac8c \ucd5c\uc18c\uc77c \uc218\ub3c4 \uc788\uc74c)\n min = [ones, zeroes].min \n flip_ones, flip_zeroes = 0, 0\n \n for i in s\n if i == 0\n flip_zeroes += 1\n zeroes -= 1\n else\n flip_ones += 1\n ones -= 1\n end\n # \uc790\uae30 \uc790\ub9ac\ub97c \uacc4\uc18d \ubc14\uafd4\uac00\uba70 \ub098\uc544\uac04\ub2e4\n # 0\uc73c\ub85c \ub098\uc544\uac08 \uacbd\uc6b0-> \ub4b7\ubd80\ubd84\uc744 \uc804\ubd80 1\ub85c \ub9cc\ub4e4\uae30 \uc704\ud574 \ubc14\uafd4\uc57c\ud560 0\uc758 \uc218\n # 1\ub85c \ub098\uc544\uac08 \uacbd\uc6b0 -> \ub4b7\ubd80\ubd84\uc744 \uc804\ubd80 0\uc73c\ub85c \ub9cc\ub4e4\uae30 \uc704\ud574 \ubc14\uafd4\uc57c\ud560 1\uc758 \uc218\n # \ud56d\uc0c1 \ubbf8\ub2c8\uba48\uc744 \uc720\uc9c0\ud558\uc790\n # dp \uc751\uc6a9 \uac19\uc74c\n min = [min, flip_zeroes + ones, flip_ones + zeroes].min\n end\n puts min\n}", "positive_code": [{"source_code": "gets.to_i.times do \n s = gets.chomp\n ones = s.each_char.inject([]) do |arr, c| \n arr.push arr[-1] || 0\n arr[-1] += 1 if c == '1'\n arr\n end\n all = [ones[-1], s.length - ones[-1]].min\n min = s.length.times.inject(all) do |min, i|\n right_zero = s.length - (i + 1) - (ones[-1] - ones[i])\n left_zero = i + 1 - ones[i]\n right_one = ones[-1] - ones[i]\n min = [min, ones[i] + right_zero, left_zero + right_one].min\n end\n puts min\nend"}, {"source_code": "def solve(num)\n one_count = 0\n zero_count = 0\n ones_first = []\n zeroes_first = []\n\n num.each_char.with_index do |char, i|\n one_count += 1 if char == \"1\"\n zero_count += 1 if char == \"0\"\n ones_first[i] = zero_count\n zeroes_first[i] = one_count\n end\n\n i = num.length - 1 \n ones_last = []\n ones_last[i] = 0 \n zeroes_last = []\n zeroes_last[i] = 0 \n min = Float::INFINITY\n\n while i > 0 \n zeroes_last[i - 1] = zeroes_last[i] + zeroes_first[i] - zeroes_first[i-1]\n ones_last[i - 1] = ones_last[i] + ones_first[i] - ones_first[i-1] \n min = [min, zeroes_first[i] + ones_last[i], ones_first[i] + zeroes_last[i]].min\n i -= 1\n end\n\n [min, zeroes_first[0] + ones_last[0], ones_first[0] + zeroes_last[0]].min\nend\n\n\namount = gets.chomp.to_i\namount.times do\n input = gets.chomp\n puts solve(input)\nend\n"}, {"source_code": "def solve(num)\n count = 0\n zeroes_first = num.each_char.map do |char|\n count += 1 if char == \"1\"\n count\n end\n count = 0\n i = num.length - 1 \n ones_last = []\n ones_last[i] = 0 \n \n while i > 0 \n count += 1 if num[i] == \"0\"\n ones_last[i - 1] = count\n i -= 1\n end\n count = 0\n ones_first = num.each_char.map do |char|\n count += 1 if char == \"0\"\n count\n end\n count = 0\n i = num.length - 1 \n zeroes_last = []\n zeroes_last[i] = 0\n while i > 0 \n count += 1 if num[i] == \"1\"\n zeroes_last[i - 1] = count\n i -= 1\n end\n\n i = 0 \n min = Float::INFINITY\n while i < num.length\n min = [min, zeroes_first[i] + ones_last[i], ones_first[i] + zeroes_last[i]].min\n i += 1\n end\n min\nend\n\n\namount = gets.chomp.to_i\namount.times do\n input = gets.chomp\n puts solve(input)\nend\n"}], "negative_code": [{"source_code": "# coding: utf-8\n\nn = gets.to_i\nn.times {\n s = gets.chomp.split(//).map(&:to_i)\n i = 0\n len = s.length\n flipped = 0\n # 010 -> remove 1's\n # 101 -> removes 0's\n while i < len-1\n base = 0\n flip = 1\n if s[i] == 0\n base = 0\n flip = 1\n else\n base = 1\n flip = 0\n end\n\n p1 = s[i..-1].index(flip)\n if p1 != nil\n p1 += i #compensation\n p2 = s[p1..-1].index(base)\n if p2 != nil\n p2 += p1 # compensation\n j = p1\n while s[j] == flip\n s[j] = base\n j += 1\n flipped += 1\n end\n i = p2\n next\n end\n end\n\n i += 1\n end\n puts flipped\n}"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nn.times {\n s = gets.split(//).map(&:to_i)\n i = 0\n len = s.length\n flipped = 0\n # 010 -> remove 1's\n # 101 -> removes 0's\n while i < len-1\n base = 0\n flip = 1\n if s[i] == 0\n base = 0\n flip = 1\n else\n base = 1\n flip = 0\n end\n\n p1 = s[i..-1].index(flip)\n if p1 != nil\n p1 += i #compensation\n p2 = s[p1..-1].index(base)\n if p2 != nil\n p2 += p1 # compensation\n j = p1\n while s[j] == flip\n s[j] = base\n j += 1\n flipped += 1\n end\n i = p2\n next\n end\n end\n\n i += 1\n end\n puts flipped\n}"}], "src_uid": "803e5ccae683b91a4cc486fbc558b330"} {"source_code": "def ones(a)\n\tc = 0\n\twhile a > 0\n\t\tc += a % 2\n\t\ta /= 2\t\t\n\tend\n\tc\nend\n\nn,m = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.chomp\nend\nenemy = []\n\nm.times do\n\ta,b = gets.chomp.split(\" \")\n\tval = 0\n\tval |= 1 << arr.index(a)\n\tval |= 1 << arr.index(b)\n\tenemy << val\nend\n\n# puts \"here #{arr}\"\nbest = 0\n\n(0..(2**n)).each do |i|\n\tans = true\n\tenemy.each do |en|\n\t\tif (en & i) == en\n\t\t\tans = false\n\t\t\t# puts \"ere\"\n\t\tend\n\t\t# puts \"fdf\"\n\tend\n\t# puts \"ere\"\n\tif ans && (ones(i) > ones(best))\n\t\tbest = i\t\t\n\tend\t\n\t# puts \"dsafds\"\nend\n# puts \"dasf\"\nputs ones(best)\nlist = []\n# puts \"#{arr}\"\n# puts \"#{best.to_s(2).rjust(n,'0')}\"\nbest.to_s(2).rjust(n,'0').each_char.with_index do |c,i|\n\tif c == '1'\n\t\tlist << arr[n-i - 1]\n\tend\nend\nputs list.sort.join(\"\\n\")", "positive_code": [{"source_code": "\nn, m = gets.split.map &:to_i\np = []\n$e = Array.new(n,0)\n\nn.times {\n name = gets.chomp\n p << name\n}\nm.times {\n p0, p1 = gets.chomp.split\n i = p.index p0\n j = p.index p1\n $e[i] = $e[i] + (1<< j)\n $e[j] = $e[j] + (1<< i)\n}\n\n$max = []\ndef f(mems, mask, i, n)\n $max = mems.dup if mems.length > $max.length\n i.upto(n-1) {|j|\n if ($e[j] & mask) == 0\n mems << j\n f(mems, mask + (1<< j), j+1, n)\n mems.pop\n end\n }\nend\nf([], 0, 0, n)\nputs $max.length\n$max.map {|i| p[i] }.sort.each { |p| puts p}\n"}, {"source_code": "#!/usr/bin/env ruby\n\ndef main\n n, m = STDIN.gets.split.map!{|x| x.to_i}\n names = []\n n.times {\n name = STDIN.gets.rstrip\n names.push(name)\n }\n\n ng = (0...n).map {Array.new(n)}\n m.times {\n a, b = STDIN.gets.split\n a = names.find_index(a)\n b = names.find_index(b)\n ng[a][b] = ng[b][a] = true\n }\n\n ans = 0\n (1 << n).times {|set|\n if ans.to_s(2).count('1') >= set.to_s(2).count('1')\n next\n end\n\n ok = true\n n.times do |i| if (set >> i & 1) != 0\n i.times do |j| if (set >> j & 1) != 0\n if ng[i][j]\n ok = false\n end\n end\n end\n end\n end\n if ok\n ans = set\n end\n }\n\n puts ans.to_s(2).count('1')\n ans_names = []\n n.times {|i|\n if (ans >> i & 1) == 1\n ans_names.push(names[i])\n end\n }\n ans_names.sort!.each do |x|\n puts x\n end\n\nend\n\nif __FILE__ == $0\n main\nend"}], "negative_code": [{"source_code": "\nn, m = gets.split.map &:to_i\np = []\n$e = []\nn.times { $e << Array.new(n, false) }\n\nn.times {\n name = gets.chomp\n p << name\n}\nm.times {\n p0, p1 = gets.split\n i = p.index p0\n j = p.index p1\n $e[i][j] = $e[j][i] = true\n}\n\n$max = []\ndef f(mems, i, n)\n if i == n\n $max = mems.dup if mems.length > $max.length\n else\n i.upto(n-1) {|j|\n if not mems.any? { |k| $e[j][k] }\n mems << j\n f(mems, j+1, n)\n mems.pop\n end\n }\n end\nend\nf([], 0, n)\nputs $max.length\nputs $max.map { |i| p[i]}.sort\n"}, {"source_code": "\nn, m = gets.split.map &:to_i\np = []\n$e = Array.new(n,0)\n\nn.times {\n name = gets.chomp\n p << name\n}\nm.times {\n p0, p1 = gets.chomp.split\n i = p.index p0\n j = p.index p1\n $e[i] = $e[i] + (1<< j)\n $e[j] = $e[j] + (1<< i)\n}\n\n$max = []\ndef f(mems, mask, i, n)\n if i == n\n $max = mems.dup if mems.length > $max.length\n else\n i.upto(n-1) {|j|\n if ($e[j] & mask) == 0\n mems << j\n f(mems, mask + (1<< j), j+1, n)\n mems.pop\n end\n }\n end\nend\nf([], 0, 0, n)\nputs $max.length\n$max.map { |i| p[i]}.sort.each { |p| puts p}\n"}, {"source_code": "\nn, m = gets.split.map &:to_i\np = []\n$e = Array.new(n,0)\n\nn.times {\n name = gets.chomp\n p << name\n}\nm.times {\n p0, p1 = gets.chomp.split\n i = p.index p0\n j = p.index p1\n $e[i] = $e[i] + (1<< j)\n $e[j] = $e[j] + (1<< i)\n}\n\n$max = []\ndef f(mems, mask, i, n)\n if i == n\n $max = mems.dup if mems.length > $max.length\n else\n i.upto(n-1) {|j|\n if ($e[j] & mask) == 0\n mems << j\n f(mems, mask + (1<< j), j+1, n)\n mems.pop\n end\n }\n end\nend\nf([], 0, 0, n)\nputs $max.length\nputs $max.map { |i| p[i]}.sort\n"}, {"source_code": "\nn, m = gets.split.map &:to_i\np = []\n$e = Array.new(n,0)\n\nn.times {\n name = gets.chomp\n p << name\n}\nm.times {\n p0, p1 = gets.chomp.split\n i = p.index p0\n j = p.index p1\n $e[i] = $e[i] + (1<< j)\n $e[j] = $e[j] + (1<< i)\n}\n\n$max = []\ndef f(mems, mask, i, n)\n if i == n\n $max = mems.dup if mems.length > $max.length\n else\n i.upto(n-1) {|j|\n if ($e[j] & mask) == 0\n mems << j\n f(mems, mask + (1<< j), j+1, n)\n mems.pop\n end\n }\n end\nend\nf([], 0, 0, n)\nputs $max.length\n$max.map {|i| p[i] }.sort_by(&:downcase).each { |p| puts p}\n"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.chomp\nend\nenemy = {}\n\nm.times do\n\ta,b = gets.chomp.split(\" \")\n\tenemy[a] ||= []\n\tenemy[b] ||= []\n\tenemy[a] << b\n\tenemy[b] << a\nend\n# ans = arr.dup\n# puts \"#{enemy}\"\n# puts \"here #{enemy.key(:Pasha)}\"\nenemy_vals = enemy.sort_by{|x,v| -v.length}\n# puts \"#{}\"\nenemy_vals.each do |v|\n\tk = v[0]\n\tval = enemy[k]\n\t# puts \"arr #{arr}\"\n\tif val.length > 0\n\t\t# puts \"#{enemy}\"\n\t\tarr -= [k]\n\t\tval.each{|x| enemy[x] -= [k] }\n\tend\nend\nputs arr.length\nputs \"#{arr.sort.join(\"\\n\")}\""}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.chomp\nend\nenemy = {}\n\nm.times do\n\ta,b = gets.chomp.split(\" \")\n\tenemy[a] ||= []\n\tenemy[b] ||= []\n\tenemy[a] << b\n\tenemy[b] << a\nend\n# ans = arr.dup\nenemy.each do |k,v|\n\tif v.length > 0\n\t\tarr -= [k]\n\t\tv.each{|x| enemy[x] -= [k] }\n\tend\nend\nputs arr.length\nputs \"#{arr.sort.join(\"\\n\")}\""}, {"source_code": "def ones(a)\n\tc = 0\n\twhile a > 0\n\t\tc += a % 2\n\t\ta /= 2\t\t\n\tend\n\tc\nend\n\nn,m = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.chomp\nend\nenemy = []\n\nm.times do\n\ta,b = gets.chomp.split(\" \")\n\tval = 0\n\tval |= 1 << arr.index(a)\n\tval |= 1 << arr.index(b)\n\tenemy << val\nend\n\n# puts \"here #{arr}\"\nbest = 0\n\n(0..(2**n)).each do |i|\n\tans = true\n\tenemy.each do |en|\n\t\tif (en & i) == en\n\t\t\tans = false\n\t\t\t# puts \"ere\"\n\t\tend\n\t\t# puts \"fdf\"\n\tend\n\t# puts \"ere\"\n\tif ans && (ones(i) > ones(best))\n\t\tbest = i\t\t\n\tend\t\n\t# puts \"dsafds\"\nend\n# puts \"dasf\"\nputs ones(best)\nlist = []\n# puts \"#{best}\"\nbest.to_s(2).each_char.with_index do |c,i|\n\tif c == '1'\n\t\tlist << arr[i]\n\tend\nend\nputs list.sort.join(\"\\n\")"}, {"source_code": "def ones(a)\n\tc = 0\n\twhile a > 0\n\t\tc += a % 2\n\t\ta /= 2\t\t\n\tend\n\tc\nend\n\nn,m = gets.split(\" \").map(&:to_i)\narr = []\nn.times do\n\tarr << gets.chomp\nend\nenemy = []\n\nm.times do\n\ta,b = gets.chomp.split(\" \")\n\tval = 0\n\tval |= 1 << arr.index(a)\n\tval |= 1 << arr.index(b)\n\tenemy << val\nend\n\n# puts \"here #{arr}\"\nbest = 0\n\n(0..(2**n)).each do |i|\n\tans = true\n\tenemy.each do |en|\n\t\tif (en & i) == en\n\t\t\tans = false\n\t\t\t# puts \"ere\"\n\t\tend\n\t\t# puts \"fdf\"\n\tend\n\t# puts \"ere\"\n\tif ans && (ones(i) > ones(best))\n\t\tbest = i\t\t\n\tend\t\n\t# puts \"dsafds\"\nend\n# puts \"dasf\"\nputs ones(best)\nlist = []\n# puts \"#{best}\"\nbest.to_s(2).each_char.with_index do |c,i|\n\tif c == '1'\n\t\tlist << arr[n-i - 1]\n\tend\nend\nputs list.sort.join(\"\\n\")"}, {"source_code": "#!/usr/bin/env ruby\n\ndef main\n n, m = STDIN.gets.split.map!{|x| x.to_i}\n names = []\n n.times {\n name = STDIN.gets.rstrip\n names.push(name)\n }\n\n ng = (0...n).map {Array.new(n)}\n m.times {\n a, b = STDIN.gets.split\n a = names.find_index(a)\n b = names.find_index(b)\n ng[a][b] = ng[b][a] = true\n }\n\n ans = 0\n (1 << n).times {|set|\n if ans.to_s(2).count('1') >= set.to_s(2).count('1')\n next\n end\n\n ok = true\n n.times do |i|\n i.times do |j|\n if (set >> i & 1) != 0 && (set >> j & 1) != 0\n if ng[i][j]\n ok = false\n end\n end\n end\n end\n if ok\n ans = set\n end\n }\n puts ans.to_s(2).count('1')\n n.times {|i|\n if (ans >> i & 1) == 1\n puts names[i]\n end\n }\n\n\nend\n\nif __FILE__ == $0\n main\n STDIN.gets;\nend"}], "src_uid": "b0301a2d79a1ec126511ed769ec0b743"} {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt','w')\nn=gets.to_i\ns=gets\n(n/2).times{|i|\n\tx,y=i,i+n/2\n\tx,y=y,x if s[x]=='R'&&s[y]=='L'\n\tputs [x+1,y+1]*' '\n}", "positive_code": [{"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n k=a[i]=='L'?0:1\n puts [i+1+n*k, i+1+n*(1-k)]*' '\n i+=1\nend\n\n"}, {"source_code": "$stdin=File.open('input.txt')\n$stdout=File.open('output.txt', 'w')\nb=Array.new{|el| el=Array.new(2)}\nn,s=gets.to_i,\" \"+gets.to_s\na=(1..n).to_a\nx,y=1,3\nfor i in 1..n/2 do\nb<<[x,y] \nif i%2==0 then\n\tx+=3\n\ty+=3\n\telse\n\t\tx+=1\n\t\ty+=1\n\tend\nend\nif n%4!=0 then\nb[n%2-1][0],b[n%2-2][1]=b[n%2-2][1],b[n%2-1][0]\nb[n%2-1][1]=n\nend\nfor i in 1..n/2 do\nif s[b[i-1][0]] ==\"R\" && s[b[i-1][1]] ==\"L\" then\nb[i-1][0],b[i-1][1]=b[i-1][1],b[i-1][0]\nend\nputs b[i-1].join(' ')\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\n\n\n\n\n\t\n\t\n\t\n"}, {"source_code": "input = File.open(\"input.txt\", \"r\")\noutput = File.open(\"output.txt\", \"w\")\n\nn = input.gets.to_i\nlr = \" \"+input.gets.strip\n\nfor i in 1..n-2\n desk = Array.new(2)\n if lr[i] != \"0\"\n if lr[i] == \"L\"\n\t desk[0] = i\n\t desk[1] = n/2+i\n\telse\n\t desk[0] = n/2+i\n\t desk[1] = i\n\tend\n\tlr[i] = \"0\"\n\tlr[n/2+i] = \"0\"\n\toutput.puts \"#{desk[0]} #{desk[1]}\"\n end\nend\n\ninput.close\noutput.close"}, {"source_code": "input = File.open(\"input.txt\", \"r\")\noutput = File.open(\"output.txt\", \"w\")\n\nn = input.gets.to_i\nlr = \" \"+input.gets.strip\n\nfor i in 1..n/2\n desk = Array.new(2)\n if lr[i] == \"L\"\n\tdesk[0] = i\n\tdesk[1] = n/2+i\n else\n\tdesk[0] = n/2+i\n\tdesk[1] = i\n end\n output.puts \"#{desk[0]} #{desk[1]}\"\nend\n\ninput.close\noutput.close"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n k=a[i]=='L'?0:1\n puts [i+1+n*k, i+1+n*(1-k)]*' '\n i+=1\nend\n\n"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n k=a[i]=='L'?0:1\n puts [i+1+n*k, i+1+n*(1-k)]*' '\n i+=1\nend\n"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i\na=gets.chomp.split('').unshift(0)\nfor i in 1..n/2\n\tputs \"#{i} #{i+n/2}\" if a[i]=='L'\n\tputs \"#{i+n/2} #{i}\" if a[i]=='R'\nend"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n k=a[i]=='L'?0:1\n puts [i+1+n*k, i+1+n*(1-k)]*' '\n i+=1\nend\n\n"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n k=a[i]=='L'?0:1\n puts [i+1+n*k, i+1+n*(1-k)]*' '\n i+=1\nend\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n ARGV << 'input.txt'\n $> = open('output.txt', 'w')\nend\n\nn = gets.to_i / 2\nm = gets\nputs [*1..n].map{|i| (m[i-1] == 'L' ? [i, n+i] : [n+i, i]) * ' '} * \"\\n\"\n"}, {"source_code": "$stdin = File.new( \"input.txt\", 'r' )\n$stdout = File.new( \"output.txt\", 'w' )\n\nn = gets.strip.to_i\nstds = gets.strip.split(\"\")\nmid = n / 2\ni = 0\n(mid...n).each do |j|\n if stds[i] == 'R' && stds[j] == 'L'\n puts \"#{j + 1} #{i + 1}\"\n else\n puts \"#{i + 1} #{j + 1}\"\n end\n i += 1\nend\n"}, {"source_code": "n = 0\narr = []\nopen(\"input.txt\") {|f|\n n = f.gets.to_i\n arr = f.gets.to_s.chomp.split(//)\n}\nFile.open(\"output.txt\", \"w\"){|f|\n(n/2).times do |i|\n if arr[i] == \"R\" && arr[i+n/2] == \"L\"\n f.write \"#{i+n/2+1} #{i+1}\\n\"\n else\n f.write \"#{i+1} #{i+n/2+1}\\n\"\n end\nend\n}"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n k=a[i]=='L'?0:1\n puts [i+1+n*k, i+1+n*(1-k)]*' '\n i+=1\nend"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n if a[i]=='L' then\n puts [i+1,i+1+n]*' '\n else\n puts [i+1+n,i+1]*' '\n end\n i+=1\nend\n"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n k=a[i]=='L'?0:1\n puts [i+1+n*k, i+1+n*(1-k)]*' '\n i+=1\nend\n"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n k=a[i]=='L'?0:1\n puts [i+1+n*k, i+1+n*(1-k)]*' '\n i+=1\nend\n\n"}, {"source_code": "line = File.read(\"input.txt\")\nn,hand = line.split(\"\\n\")\n\n\nn = n.to_i\nres = []\n\n\narr = hand.split(\"\")\n\nnos = [*(0..n-1).step(2),*(1..n-1).step(2)]\n\nnos.each_slice(2) do |a|\n\to = arr[a[0]]\n\te = arr[a[1]]\n\todd_ind = a[0]\n\teven_ind = a[1]\n\todd_ind,even_ind = even_ind,odd_ind if o != e && o != \"R\"\n\tres << [even_ind+1,odd_ind+1]\nend\nFile.open(\"output.txt\", 'w') { |file| \n\tres.each do |a|\n\t\tfile.puts(a.join(\" \"))\n\tend\n}\n"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n k=a[i]=='L'?0:1\n puts [i+1+n*k, i+1+n*(1-k)]*' '\n i+=1\nend\n\n"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n k=a[i]=='L'?0:1\n puts [i+1+n*k, i+1+n*(1-k)]*' '\n i+=1\nend\n\n"}, {"source_code": "$stdin=open(\"input.txt\")\n$stdout=open(\"output.txt\",\"w\")\nn=gets.to_i/2\na=gets\ni=0\nn.times do\n k=a[i]=='L'?0:1\n puts [i+1+n*k, i+1+n*(1-k)]*' '\n i+=1\nend\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nn = gets.to_i / 2\nm = gets\nputs [*1..n].map{|i| (m[i-1] == 'L' ? [i, n+i] : [n+i, i]) * ' '} * \"\\n\"\n"}], "negative_code": [{"source_code": "n = gets.to_i\narr = gets.to_s.chomp.split(//)\n(n/2).times do |i|\n if arr[i] == \"R\" && arr[i+n/2] == \"L\"\n puts \"#{i+n/2+1} #{i+1}\"\n else\n puts \"#{i+1} #{i+n/2+1}\"\n end\nend\n"}, {"source_code": "n=0\na=[]\nopen(\"input.txt\") do |f|\n n=f.gets.to_i\n a=f.gets.chomp.split('')\nend\n\nres=Array.new(n/2).map!{Array.new(2)}\nl=r=0\na.each_with_index do |v,i|\n if v=='L' then\n if l = open('output.txt', 'w')\nend\n\nn = gets.to_i\nm = gets.scan(/[LR]/).zip([*1..n]).sort\nn /= 2\nn.times do |i|\n puts \"#{m[i][1]} #{m[n + i][1]}\"\nend\n"}, {"source_code": "p ENV\nvar = %w(RUBY_COPYRIGHT RUBY_ENGINE RUBY_PLATFORM RUBY_REVISION RUBY_DESCRIPTION RUBY_PATCHLEVEL RUBY_RELEASE_DATE RUBY_VERSION)\nvar.map{|_| puts \"#{_} = #{eval(_)}\"}\n"}], "src_uid": "564664d9cd2ccbccb42574b3881ec5fe"} {"source_code": "S = gets.chomp\nN = S.size\nac = [0, 0]\nbc = [0, 0]\nans = [0, 0]\nN.times { |i|\n if S[i] == 'a'\n ac[i & 1] += 1\n ans[0] += ac[~i & 1]\n ans[1] += ac[i & 1]\n else\n bc[i & 1] += 1\n ans[0] += bc[~i & 1]\n ans[1] += bc[i & 1]\n end\n}\nputs ans.join ' '\n", "positive_code": [{"source_code": "x = gets.chomp\nx0 = [0, 0]\nx1 = [0, 0]\ny0 = y1 = 0\nx.size.times{ |i|\n p = x[i].ord - 'a'.ord\n if i % 2 == 0\n x0[p] += 1\n y0 += x0[p]\n y1 += x1[p]\n else\n x1[p] += 1\n y0 += x1[p]\n y1 += x0[p]\n end\n}\nputs \"#{y1} #{y0}\""}, {"source_code": "x = gets.chomp\nx0 = [0, 0]\nx1 = [0, 0]\ny0 = y1 = 0\nx.size.times{ |i|\n p = x[i].ord - 'a'.ord\n if i % 2 == 0\n x0[p] += 1\n y0 += x0[p]\n y1 += x1[p]\n else\n x1[p] += 1\n y0 += x1[p]\n y1 += x0[p]\n end\n}\nputs \"#{y1} #{y0}\""}, {"source_code": "a=gets.chomp\ne=[0,0]\no=[0,0]\nea=oa=0\na.size.times{|i| \n\tt=a[i].ord-'a'.ord\n\tif i%2==0\n\t\te[t]+=1\n\t\tea+=o[t]\n\t\toa+=e[t]\n\telse\n\t\to[t]+=1\n\t\tea+=e[t]\n\t\toa+=o[t]\n\tend\n}\nputs \"#{ea} #{oa}\"\n"}], "negative_code": [], "src_uid": "4ebbda2fc1a260e9827205a25addd9c4"} {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n a.sort!\n m = (n+1)/2\n ans1 = a[0..(m-1)].reverse.rotate\n ans2 = a[m..(n-1)].rotate\n g = ans2.size\n g.times do \n if ans2[-1] == ans1[-1]\n ans2.rotate!\n else\n break\n end\n end\n ans = []\n #puts ans1.inspect\n #puts ans2.inspect\n 0.upto(n-1) do |i|\n ans.push( (i%2==0) ? ans1.pop : ans2.pop)\n end\n #puts ans.inspect\n check = 0\n 0.upto(n-1) do |i|\n if i % 2 == 0 then\n check += 1 if (ans[i]ans[i-1]) and (ans[i]>ans[(i+1)%n]) \n end\n end\n if check == n then\n puts \"YES\" \n puts ans.join(\" \")\n else \n puts \"NO\"\n end\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i).sort\r\n ys = (0..xs.size - 1).map { |i| xs[i % 2 == 0 ? i / 2 : (xs.size / 2 + i / 2)] }\r\n ok = (0..ys.size - 1).all? do |i|\r\n a, b, c = ys[i - 1], ys[i], ys[(i + 1) % ys.size]\r\n (a < b && b > c) || (a > b && b < c)\r\n end\r\n if ok\r\n puts \"YES\"\r\n puts ys.join(\" \")\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n a.sort!\n ans = []\n 0.upto(n-1) do |i|\n if i % 2 == 0 then\n ans.push(a[i/2])\n else\n ans.push(a[n-1-i/2])\n end\n end\n check = 0\n 0.upto(n-1) do |i|\n if i % 2 == 0 then\n check += 1 if (ans[i]ans[i-1]) and (ans[i]>ans[(i+1)%n]) \n end\n end\n if check == n then\n puts \"YES\" \n puts ans.join(\" \")\n else \n puts \"NO\"\n end\nend\n"}], "src_uid": "a30c5562d3df99291132fac20e05e708"} {"source_code": "n = gets.chomp.to_i\n(0...n).each do \n s = gets.chomp.split(\"\")\n #p s\n count = 1\n #while true\n i = 1\n 100.times do\n if s[i] != s[i-1] && s.size >= 2\n s[i] = \" \"\n s[i-1] = \" \"\n count += 1\n # elsif \n # i += 1\n # count += 1\n end\n #p s\n if s.include?(\" \")\n s.delete(\" \")\n if i >= 1\n i -= 1\n end\n else\n i += 1\n end\n #p s\n ss = s.size\n\n #p count\n if s.count(\"1\") == ss || s.count(\"0\") == ss || s == []\n if count % 2 == 1\n puts \"NET\"\n elsif count % 2 == 0\n puts \"DA\"\n end\n break\n end\n end\n\nend", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n s = gets.chomp.chars\n alice = true\n while s.size >= 2\n i = s.each_cons(2).find_index { |c| c[0] != c[1] }\n break unless i\n s.slice! i, 2\n alice = !alice\n end\n puts (alice ? \"NET\" : \"DA\")\nend\n"}, {"source_code": "def run\n s = gets.chomp\n a = s.split(\"\").map(&:to_i)\n\n if a.size == 1\n puts \"NET\"\n return\n end\n\n c = 0\n\n while true\n idx = find_idx(a)\n if idx == -1\n if c % 2 == 1\n puts \"DA\"\n return\n else\n puts \"NET\"\n return\n end\n else\n c += 1\n a.slice!(idx, 2)\n end\n end\nend\n\ndef find_idx(a)\n (0..(a.length - 2)).each do |idx|\n if a[idx] != a[idx + 1]\n return idx\n end\n end\n\n return -1\nend\n\ndef main\n t = gets.chomp.to_i\n\n t.times do\n run\n end\nend\n\nmain\n\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\n(0...n).each do \n s = gets.chomp.split(\"\")\n #p s\n count = 1\n #while true\n i = 1\n 250.times do\n if s[i] != s[i-1]\n s[i] = \" \"\n s[i-1] = \" \"\n count += 1\n # elsif \n # i += 1\n # count += 1\n end\n #p s\n if s.include?(\" \")\n s.delete(\" \")\n i = 1\n else\n i += 1\n end\n #p s\n ss = s.size\n #p i\n if s.count(\"1\") == ss || s.count(\"0\") == ss || s == []\n if count % 2 == 1\n puts \"NET\"\n elsif count % 2 == 0\n puts \"DA\"\n end\n break\n end\n end\n\nend"}, {"source_code": "n = gets.chomp.to_i\n(0...n).each do \n s = gets.chomp.split(\"\")\n #p s\n count = 1\n #while true\n i = 1\n 200.times do\n #while \n if s[i] != s[i-1]\n s[i] = \" \"\n s[i-1] = \" \"\n count += 1\n # elsif \n # i += 1\n # count += 1\n end\n #p s\n if s.include?(\" \")\n s.delete(\" \")\n i = 1\n else\n i += 1\n end\n #p s\n ss = s.size\n #p i\n if s.count(\"1\") == ss || s.count(\"0\") == ss || s == []\n if count % 2 == 1\n puts \"NET\"\n elsif count % 2 == 0\n puts \"DA\"\n end\n break\n end\n end\n\nend"}, {"source_code": "n = gets.chomp.to_i\n(0...n).each do \n s = gets.chomp.split(\"\")\n #p s\n count = 1\n #while true\n i = 1\n 100.times do\n if s[i] != s[i-1]\n s[i] = \" \"\n s[i-1] = \" \"\n count += 1\n # elsif \n # i += 1\n # count += 1\n end\n #p s\n if s.include?(\" \")\n s.delete(\" \")\n if i >= 1\n i -= 1\n end\n else\n i += 1\n end\n #p s\n ss = s.size\n\n #p i\n if s.count(\"1\") == ss || s.count(\"0\") == ss || s == []\n if count % 2 == 1\n puts \"NET\"\n elsif count % 2 == 0\n puts \"DA\"\n end\n break\n end\n end\n\nend"}, {"source_code": "n = gets.chomp.to_i\n(0...n).each do \n s = gets.chomp.split(\"\")\n #p s\n count = 1\n #while true\n i = 1\n 110.times do\n if s[i] != s[i-1]\n s[i] = \" \"\n s[i-1] = \" \"\n count += 1\n # elsif \n # i += 1\n # count += 1\n end\n #p s\n if s.include?(\" \")\n s.delete(\" \")\n i = 1\n else\n i += 1\n end\n #p s\n ss = s.size\n #p i\n if s.count(\"1\") == ss || s.count(\"0\") == ss || s == []\n if count % 2 == 1\n puts \"NET\"\n elsif count % 2 == 0\n puts \"DA\"\n end\n break\n end\n end\nend"}, {"source_code": "n = gets.chomp.to_i\n(0...n).each do \n s = gets.chomp.split(\"\")\n #p s\n count = 1\n #while true\n i = 1\n 100.times do\n if s[i] != s[i-1] \n s[i] = \" \"\n s[i-1] = \" \"\n count += 1\n # elsif \n # i += 1\n # count += 1\n end\n #p s\n if s.include?(\" \")\n s.delete(\" \")\n if i >= 1\n i -= 1\n end\n else\n i += 1\n end\n #p s\n ss = s.size\n\n #p count\n if s.count(\"1\") == ss || s.count(\"0\") == ss || s == []\n if count % 2 == 1\n puts \"NET\"\n elsif count % 2 == 0\n puts \"DA\"\n end\n break\n end\n end\n\nend"}], "src_uid": "046900001c7326fc8d890a22fa7267c9"} {"source_code": "require 'set'\n\ndef taskA\n a, b = gets.chomp.split(\" \").map(&:to_i)\n puts b > a ? b - a : (a + b) % 2\nend\n\ndef taskB\n a, b, c = gets.chomp.split(\" \").map(&:to_i)\n z, x, y = gets.chomp.split(\" \").map(&:to_i)\n minCX = [c, x].min\n puts (minCX - [0, y - a - c + minCX].max)*2\nend\n\ndef taskC\n n = gets.chomp.split(\" \").map(&:to_i)\n tab = gets.chomp.split(\" \").map(&:to_i)\n min = tab.min\n good = tab.select{ |a| a % min == 0 }.sort\n good.push(1100000000)\n # puts good.join(\" \")\n iter = 0\n prev = min\n tab.map do |a|\n # puts \"now #{a} iter = #{iter}\"\n if a % min == 0\n if prev > good[iter]\n puts \"NO\"\n return\n end\n prev = good[iter]\n iter+=1\n elsif prev > a\n puts \"NO\"\n return\n else\n prev = a\n end\n end\n puts \"YES\"\nend\n\nt = gets.chomp.to_i\nwhile (t-=1) >= 0\n taskC\nend\n", "positive_code": [{"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n b = a.sort\n min = b[0]\n ok = true\n n.times do |i|\n if a[i] != b[i] && a[i].gcd(min) != min\n ok = false\n end\n end\n if ok\n ans << \"YES\"\n else\n ans << \"NO\"\n end\nend\nans.each do |x|\n puts x\nend"}, {"source_code": "def gcd(x,y)\n return y==0?x:gcd(y,x%y)\nend\n\nt =gets.to_i\n\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n b = a.sort\n ma = a.min\n res =\"YES\"\n for i in 0...n do\n if gcd(a[i], ma) != ma and b[i] != a[i] then\n res =\"NO\"\n end\n end\n puts res\nend"}, {"source_code": "def solve\n _ = gets\n a = gets.strip.split(' ').map(&:to_i)\n mn = a.min\n slc = a.select { |e| e % mn == 0 }.sort\n p = 0\n a.each_with_index { |e, i|\n if e % mn == 0\n a[i] = slc[p]\n p += 1\n end\n }\n if a == a.sort\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\ngets.strip.to_i.times { solve }"}], "negative_code": [{"source_code": "require 'set'\n\ndef taskA\n a, b = gets.chomp.split(\" \").map(&:to_i)\n puts b > a ? b - a : (a + b) % 2\nend\n\ndef taskB\n a, b, c = gets.chomp.split(\" \").map(&:to_i)\n z, x, y = gets.chomp.split(\" \").map(&:to_i)\n minCX = [c, x].min\n puts (minCX - [0, y - a - c + minCX].max)*2\nend\n\ndef taskC\n n = gets.chomp.split(\" \").map(&:to_i)\n tab = gets.chomp.split(\" \").map(&:to_i)\n min = tab.min\n good = tab.select{ |a| a % min == 0 }.sort\n good.push(1100000000)\n # puts good.join(\" \")\n iter = 0\n tab.map do |a|\n # puts \"now #{a} iter = #{iter}\"\n if a % min == 0\n iter+=1\n elsif good[iter] < a\n puts \"NO\"\n return\n end\n end\n puts \"YES\"\nend\n\nt = gets.chomp.to_i\nwhile (t-=1) >= 0\n taskC\nend\n"}, {"source_code": "require 'set'\n\ndef taskA\n a, b = gets.chomp.split(\" \").map(&:to_i)\n puts b > a ? b - a : (a + b) % 2\nend\n\ndef taskB\n a, b, c = gets.chomp.split(\" \").map(&:to_i)\n z, x, y = gets.chomp.split(\" \").map(&:to_i)\n minCX = [c, x].min\n puts (minCX - [0, y - a - c + minCX].max)*2\nend\n\ndef taskC\n n = gets.chomp.split(\" \").map(&:to_i)\n tab = gets.chomp.split(\" \").map(&:to_i)\n min = tab.min\n good = tab.select{ |a| a % min == 0 }.sort\n good.push(10000000)\n # puts good.join(\" \")\n iter = 0\n tab.map do |a|\n # puts \"now #{a} iter = #{iter}\"\n if a % min == 0\n iter+=1\n elsif good[iter] < a\n puts \"NO\"\n return\n end\n end\n puts \"YES\"\nend\n\nt = gets.chomp.to_i\nwhile (t-=1) >= 0\n taskC\nend\n"}], "src_uid": "f2070c2bd7bdbf0919aef1e915a21a24"} {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nif a==1\nif b.count('1')==0\nputs \"NO\"\nelse\nputs \"YES\"\nend\nelse\nif b.count('1')!=a-1\nputs \"NO\"\nelse\nputs \"YES\"\nend\nend\n\n\n", "positive_code": [{"source_code": "jacket_number = gets.to_i\n# jacket_number = '3'.to_i\njacket_list = gets.split(' ').map(&:to_i)\n# jacket_list = '1 0 1'.split(' ').map(&:to_i)\n\ndef fastened?(jacket_list)\n unFastened = []\n jacket_list.each do |j|\n unFastened << 0 if j.zero?\n return false if unFastened.count > 1\n end\n unFastened.count == 1\nend\n\nif jacket_number == 1\n puts jacket_list[0] == 1 ? 'YES' : 'NO'\nelse\n puts fastened?(jacket_list) ? 'YES' : 'NO'\nend\n"}, {"source_code": "n = gets.strip.to_i\nbuttons = gets.strip.split.map(&:to_i)\ncount_fastened = 0\n(0...n).each do |i|\n button = buttons[i]\n count_fastened += 1 if button == 1\nend\nif (n > 1 && n - 1 == count_fastened) || (count_fastened == n && n == 1)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "def fastened?(n, line)\n return if line.length != n || (n < 1 || n > 1000)\n if n > 1 && n <= 1000\n list0 = []\n for i in 0..(line.length - 1)\n if line[i].to_i == 0\n list0 << line[i]\n end\n end\n puts list0.length == 1 ? \"YES\" : \"NO\"\n else\n puts line[0].to_i == 1 ? \"YES\" : \"NO\"\n end\nend\n\nbuttons_length = gets.chomp.to_i\nlist_integers = gets.chomp.split\n\nfastened?(buttons_length, list_integers)\n"}, {"source_code": "def fastened?(n, line)\n return \"WRONG INPUT\" if line.length != n\n if n > 1 && n <= 1000\n list0 = []\n for i in 0..(line.length - 1)\n if line[i].to_i == 0\n list0 << line[i]\n end\n end\n puts list0.length == 1 ? \"YES\" : \"NO\"\n else\n puts line[0].to_i == 1 ? \"YES\" : \"NO\"\n end\nend\n\nbuttons_length = gets.chomp.to_i\nlist_integers = gets.chomp.split\n\nfastened?(buttons_length, list_integers)\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nif a==1\nif b.count('1')==0\nputs \"NO\"\nelse\nputs \"YES\"\nend\nelse\nif b.count('1')!=a-1\nputs \"NO\"\nelse\nputs \"YES\"\nend\nend\n"}, {"source_code": "n = gets.to_i\narr = gets.split.map(&:to_i)\n\nif arr.size == 1\n puts arr.first == 1 ? 'YES' : 'NO'\nelse\n puts arr.count { |v| v.zero? } == 1 ? 'YES' : 'NO'\nend\n"}, {"source_code": "n = gets.to_i\nsum = 0\ngets.split(\" \").map{|s| s.to_i }.each do |i| \n\tsum += i\nend\nif n == 1\n n = 2\nend\nputs sum==n-1?\"YES\":\"NO\"\n\n"}, {"source_code": "n = gets.to_i\nnums = gets.split.map(&:to_i)\n\n=begin\nsomething = 0\n\nfor i in nums\n\tif nums[i] == 0\n\t\tsomething += 1\n\tend\nend\n=end\n\n\n\nif (nums.count(0) == 1 && nums.length > 1) || (nums.length == 1 && nums[0] == 1)\n\tputs \"YES\" \nelse \n\tputs \"NO\"\nend"}, {"source_code": "n = gets.to_i\narr = gets.split.map(&:to_i)\nif arr.length == 1\n\tputs arr.first == 0 ? \"NO\" : \"YES\"\nelse\n\tcnt = 0\n\tarr.each do |num|\n\t\tcnt += 1 if num == 0\n\tend\n\tputs cnt == 1 ? \"YES\" : \"NO\"\nend"}, {"source_code": "#!/usr/bin/env ruby\n\nn = ARGF.gets.to_i\n\nbuttons = ARGF.gets.chomp.split(\" \").map { |s| s.to_i }\n\nclosed = buttons.reduce(:+)\n\nif n == 1\n if closed == 1\n puts \"YES\"\n else\n puts \"NO\"\n end\nelsif closed + 1 == n\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\nbuttons = gets.split.map(&:to_i)\nif n == 1\n puts buttons[0] == 1 ? 'YES' : 'NO'\nelse\n not_fastened = 0\n buttons.each do |b|\n not_fastened += 1 if b == 0\n end\n puts not_fastened == 1 ? 'YES' : 'NO' \nend\n"}, {"source_code": "def valid?(number_button, buttons)\n # special case\n if number_button.to_i == 1\n return buttons == \"1\"\n end\n\n @count = 0\n buttons.split(' ').each do |button|\n @count += 1 if button == '0'\n end\n\n if @count == 1\n return true\n else\n return false\n end\nend\n\ndef execute(number_button, buttons)\n if valid?(number_button, buttons)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\nnumber_button = gets.chomp\nbuttons = gets.chomp\n\nexecute(number_button, buttons)\n"}, {"source_code": "z=gets.to_i==1?:none?: :one?;puts gets.split.send(z){|e|e==?0}?:YES: :NO"}, {"source_code": "def checks(quality_buttons, buttons)\n return puts 'NO' unless quality_buttons.to_i <= 1000 && quality_buttons.to_i >= 1\n not_install = 0\n buttons.split(' ').each do |b|\n not_install += 1 if b.to_i == 0 || b.to_i > 1 || b.to_i < 0\n end\n\n return puts 'YES' if quality_buttons.to_i == 1 && not_install == 0\n r = if quality_buttons.to_i > 1 && not_install == 1\n 'YES'\n else\n 'NO'\n end\n\n puts r\nend\n\nchecks(gets.chomp, gets.chomp)\n"}, {"source_code": "n = gets.to_i\nmas = gets.split.map(&:to_i)\n\nnum = 0\n\nmas.each {|x| num+=1 if x==0}\n\nif (n==1 and num==0) or (num==1 and n!=1)\n puts \"YES\"\nelse\n puts \"NO\"\nend"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nbuttons = gets.split.map(&:to_i)\nnot_fastened = 0\nbuttons.each do |b|\n not_fastened += 1 if b == 0\nend\n(not_fastened == 1 || buttons.size == 1) ? 'YES' : 'NO' \n"}, {"source_code": "$stdout.sync = true\ndef valid?(number_button, buttons)\n return false if buttons.to_s.split(' ').size > number_button.to_i\n\n @count = 0\n\n buttons.split(' ').each do |button|\n @count += 1 if button == '0'\n return false if @count >= 2\n end\n\n if @count == 0\n return false\n else\n return true\n end\n\nend\n\ndef execute(number_button, buttons)\n if valid?(number_button, buttons)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\nnumber_button = gets.chomp\nbuttons = gets.chomp\n\nexecute(number_button, buttons)\n"}, {"source_code": "\ndef valid?(number_button, buttons)\n return false if buttons.to_s.split(' ').size > number_button.to_i\n\n @count = 0\n\n buttons.split(' ').each do |button|\n @count += 1 if button == '0'\n return false if @count >= 2\n end\n\n return true\nend\n\ndef execute(number_button, buttons)\n if valid?(number_button, buttons)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\nnumber_button = gets.chomp\nbuttons = gets.chomp\n\nexecute(number_button, buttons)\n"}, {"source_code": "def valid?(number_button, buttons)\n # special case\n if number_button.to_i == 1\n return buttons == \"1\"\n else\n return false\n end\n\n @count = 0\n buttons.split(' ').each do |button|\n @count += 1 if button == '0'\n return false if @count >= 2\n end\n\n if @count == 1\n return true\n else\n return false\n end\nend\n\ndef execute(number_button, buttons)\n if valid?(number_button, buttons)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\nnumber_button = gets.chomp\nbuttons = gets.chomp\n\nexecute(number_button, buttons)\n"}, {"source_code": "def checks(quality_buttons, buttons)\n return puts 'NO' unless quality_buttons.to_i <= 1000 && quality_buttons.to_i >= 1\n not_install = 0\n buttons.split(' ').each do |b|\n not_install += 1 if b.to_i == 0 || b.to_i > 1 || b.to_i < 0\n end\n\n r = if ( quality_buttons.to_i == 1 && not_install >= 1 )\n 'NO'\n elsif not_install == 1\n 'YES'\n elsif not_install == 0\n 'YES'\n else\n 'NO'\n end\n\n puts r\nend\n\nchecks(gets.chomp, gets.chomp)\n"}, {"source_code": "def checks(quality_buttons, buttons)\n return p 'NO' unless quality_buttons.to_i <= 1000 && quality_buttons.to_i >= 1\n not_install = 0\n buttons.split('').each do |b|\n not_install += 1 if b.to_i == 0 || b.to_i > 1 || b.to_i < 0\n end\n\n r = if ( quality_buttons.to_i == 1 && not_install == 1 )\n 'NO'\n elsif not_install <= 1\n 'YES'\n else\n 'NO'\n end\n\n p r\nend\n\nchecks(gets.chomp, gets.chomp)\n"}, {"source_code": "def checks(quality_buttons, buttons)\n return puts 'NO' unless quality_buttons.to_i <= 1000 && quality_buttons.to_i >= 1\n not_install = 0\n buttons.split(' ').each do |b|\n not_install += 1 if b.to_i == 0 || b.to_i > 1 || b.to_i < 0\n end\n\n return puts 'YES' if quality_buttons.to_i == 1 && not_install == 0\n p not_install\n r = if quality_buttons.to_i > 1 && not_install == 1\n 'YES'\n else\n 'NO'\n end\n\n puts r\nend\n\nchecks(gets.chomp, gets.chomp)\n"}, {"source_code": "def checks(quality_buttons, buttons)\n return puts 'NO' unless quality_buttons.to_i <= 1000 && quality_buttons.to_i >= 1\n not_install = 0\n buttons.split(' ').each do |b|\n not_install += 1 if b.to_i == 0 || b.to_i > 1 || b.to_i < 0\n end\n\n r = if ( quality_buttons.to_i == 1 && not_install == 1 )\n 'NO'\n elsif not_install <= 1\n 'YES'\n else\n 'NO'\n end\n\n puts r\nend\n\nchecks(gets.chomp, gets.chomp)\n"}, {"source_code": "def checks(quality_buttons, buttons)\n return puts 'NO' unless quality_buttons.to_i <= 1000 && quality_buttons.to_i >= 1\n not_install = 0\n buttons.split(' ').each do |b|\n not_install += 1 if b.to_i == 0 || b.to_i > 1 || b.to_i < 0\n end\n\n r = if ( quality_buttons.to_i == 1 && not_install == 1 )\n 'NO'\n elsif not_install == 1\n 'YES'\n else\n 'NO'\n end\n\n puts r\nend\n\nchecks(gets.chomp, gets.chomp)\n"}, {"source_code": "def checks(quality_buttons, buttons)\n return puts 'NO' unless quality_buttons.to_i <= 1000 && quality_buttons.to_i >= 1\n not_install = 0\n buttons.split(' ').each do |b|\n not_install += 1 if b.to_i == 0 || b.to_i > 1 || b.to_i < 0\n end\n\n r = if ( quality_buttons.to_i == 1 && not_install >= 1 )\n 'NO'\n elsif not_install == 1\n 'YES'\n elsif not_install == 0\n 'YES'\n else\n 'NO'\n end\n\n puts r \nend\n\nchecks(gets.chomp, gets.chomp)\n"}, {"source_code": "jacket_number = gets.to_i\n# jacket_number = '3'.to_i\njacket_list = gets.split(' ').map(&:to_i)\n# jacket_list = '1 0 1'.split(' ').map(&:to_i)\n\ndef fastened?(jacket_list)\n unFastened = []\n jacket_list.each do |j|\n unFastened << 0 if j.zero?\n return false if unFastened.count > 1\n end\n true\nend\n\nif jacket_number == 1\n puts jacket_list[0] == 1 ? 'YES' : 'NO'\nelse\n puts fastened?(jacket_list) ? 'YES' : 'NO'\nend\n"}, {"source_code": "jacket_number = gets.to_i\njacket_list = gets.split(' ').map(&:to_i)\n\ndef fastened?(jacket_list)\n unFastened = []\n jacket_list.each do |j|\n unFastened << 0 if j.zero?\n return false if unFastened.count > 1\n end\n return true\nend\n\nif jacket_number == 1\n puts jacket_list[0] == 1 ? 'YES' : 'NO'\nelse\n puts fastened?(jacket_list) ? 'YES' : 'NO'\nend\n"}, {"source_code": "n = gets.strip.to_i\nbuttons = gets.strip.split.map(&:to_i)\ncount_fastened = 0\n(0...n).each do |i|\n button = buttons[i]\n count_fastened += 1 if button == 1\nend\nif n - 1 == count_fastened || (count_fastened == n && count_fastened == 1)\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.strip.to_i\nbuttons = gets.strip.split.map(&:to_i)\nans = \"YES\"\ncount_open = 0\n(0...n).each do |i|\n button = buttons[i]\n count_open += 1 if button == 0\nend\nif n == 1 && count_open == n\n ans = \"NO\"\nelsif count_open > 1\n ans = \"NO\"\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\narr = gets.split.map(&:to_i)\n\nif arr.size == 1\n puts arr.first.zero? ? 'YES' : 'NO'\nelse\n puts arr.count { |v| v.zero? } == 1 ? 'YES' : 'NO'\nend\n"}, {"source_code": "n = gets.to_i\nsum = 0\ngets.split(\" \").map{|s| s.to_i }.each do |i| \n\tsum += i\nend\nputs sum==n-1?\"YES\":\"NO\"\n\n"}, {"source_code": "n = gets.to_i\nnums = gets.split.map(&:to_i)\n\n=begin\nsomething = 0\n\nfor i in nums\n\tif nums[i] == 0\n\t\tsomething += 1\n\tend\nend\n=end\n\n\n\nif nums.count(0) == 1 || nums.length == 1 \n\tputs \"YES\" \nelse \n\tputs \"NO\"\nend"}, {"source_code": "n = gets.to_i\nnums = gets.split.map(&:to_i)\n\n=begin\nsomething = 0\n\nfor i in nums\n\tif nums[i] == 0\n\t\tsomething += 1\n\tend\nend\n=end\n\n\n\nif nums.count(0) == 1\n\tputs \"YES\" \nelse \n\tputs \"NO\"\nend"}, {"source_code": "n = gets.to_i\nnums = gets.split.map(&:to_i)\n\n=begin\nsomething = 0\n\nfor i in nums\n\tif nums[i] == 0\n\t\tsomething += 1\n\tend\nend\n=end\n\n\n\nif nums.count(0) == 1 || (nums.length == 1 && nums[0] == 1)\n\tputs \"YES\" \nelse \n\tputs \"NO\"\nend"}, {"source_code": "n = gets.to_i\narr = gets.split.map(&:to_i)\nif arr.length == 1\n\tarr.first == 0 ? \"NO\" : \"YES\"\nelse\n\tcnt = 0\n\tarr.each do |num|\n\t\tcnt += 1 if num == 0\n\tend\n\tcnt == 1 ? \"YES\" : \"NO\"\nend"}, {"source_code": "n = gets.chomp.to_i\nbuttons = gets.split.map(&:to_i)\nnot_fastened = 0\nbuttons.each do |b|\n not_fastened += 1 if b == 0\nend\nputs (not_fastened == 1 || buttons.size == 1) ? 'YES' : 'NO' \n"}, {"source_code": "def check_fastened \n n = gets.chomp.to_i\n buttons = gets.split.map(&:to_i)\n return 'YES' if buttons.size == 1\n not_fastened = 0\n buttons.each do |b|\n not_fastened += 1 if b == 0\n end\n not_fastened > 1 ? 'NO' : 'YES' \n\nend"}, {"source_code": "n = gets.chomp.to_i\nbuttons = gets.split.map(&:to_i)\nreturn 'YES' if buttons.size == 1\nnot_fastened = 0\nbuttons.each do |b|\n not_fastened += 1 if b == 0\nend\nnot_fastened > 1 ? 'NO' : 'YES' "}, {"source_code": "n = gets.chomp.to_i\nbuttons = gets.split.map(&:to_i)\nreturn 'YES' if buttons.size == 1\nnot_fastened = 0\nbuttons.each do |b|\n not_fastened += 1 if b == 0\nend\nnot_fastened == 1 ? 'YES' : 'NO' \n"}], "src_uid": "7db0b870177e7d7b01da083e21ba35f5"} {"source_code": "a=Hash.new 0;a[0]=1;k,b,n=gets.split.map &:to_i;s=t=c=z=0;k-=1\n(gets.split.map &:to_i).each{|i|s=(s+i)%k;z+=a[(s-b)%k];a[s]+=1;if i>0 then c=0;else t+=c+=1 end}\nif b==0 then z=t elsif b==k then z-=t end;p z\n", "positive_code": [{"source_code": "a=Hash.new 0;a[0]=1;k,b,n=gets.split.map &:to_i;s=t=c=z=0;k-=1\n(gets.split.map &:to_i).each{|i|s=(s+i)%k;z+=a[(s-b)%k];a[s]+=1;if i>0 then c=0;else t+=c+=1 end}\nif b==0 then z=t elsif b==k then z-=t end;p z\n"}, {"source_code": "a=Hash.new 0;a[0]=1;k,b,n=gets.split.map &:to_i;s=t=c=z=0;k-=1\n(gets.split.map &:to_i).each{|i|s=(s+i)%k;z+=a[(s-b)%k];a[s]+=1;if i>0 then c=0;else t+=c+=1 end}\nif b==0 then z=t elsif b==k then z-=t end;p z\n"}, {"source_code": "a=Hash.new 0;a[0]=1;k,b,n=gets.split.map &:to_i;s=t=c=z=0;k-=1\n(gets.split.map &:to_i).each{|i|s=(s+i)%k;z+=a[(s-b)%k];a[s]+=1;if i>0 then c=0;else t+=c+=1 end}\nif b==0 then z=t elsif b==k then z-=t end;p z\n"}, {"source_code": "a=Hash.new 0;a[0]=1;k,b,n=gets.split.map &:to_i;s=t=c=z=0;k-=1\n(gets.split.map &:to_i).each{|i|s=(s+i)%k;z+=a[(s-b)%k];a[s]+=1;if i>0 then c=0;else t+=c+=1 end}\nif b==0 then z=t elsif b==k then z-=t end;p z\n"}, {"source_code": "a=Hash.new 0;a[0]=1;k,b,n=gets.split.map &:to_i;s=t=c=z=0;k-=1\n(gets.split.map &:to_i).each{|i|s=(s+i)%k;z+=a[(s-b)%k];a[s]+=1;if i>0 then c=0;else t+=c+=1 end}\nif b==0 then z=t elsif b==k then z-=t end;p z"}, {"source_code": "a=Hash.new 0;a[0]=1;k,b,n=gets.split.map &:to_i;s=t=c=z=0;k-=1\n(gets.split.map &:to_i).each{|i|s=(s+i)%k;z+=a[(s-b)%k];a[s]+=1;if i>0 then c=0;else t+=c+=1 end}\nif b==0 then z=t elsif b==k then z-=t end;p z\n"}, {"source_code": "a=Hash.new 0;a[0]=1;k,b,n=gets.split.map &:to_i;s=t=c=z=0;k-=1\n(gets.split.map &:to_i).each{|i|s=(s+i)%k;z+=a[(s-b)%k];a[s]+=1;if i>0 then c=0;else t+=c+=1 end}\nif b==0 then z=t elsif b==k then z-=t end;p z\n"}, {"source_code": "a=Hash.new 0;a[0]=1;k,b,n=gets.split.map &:to_i;s=t=c=z=0;k-=1\n(gets.split.map &:to_i).each{|i|s=(s+i)%k;z+=a[(s-b)%k];a[s]+=1;if i>0 then c=0;else t+=c+=1 end}\nif b==0 then z=t elsif b==k then z-=t end;p z\n"}], "negative_code": [{"source_code": "a=Hash.new 0;a[0]=1;k,b,n=gets.split.map &:to_i;s=t=c=z=0;k-=1\n(gets.split.map &:to_i).each{|i|s=(s+i)%k;z+=a[(s-b)%k];a[s]+=1;if i>0 then c=0;else t+=c+=1 end}\nif b==0 then z=t elsif b==k-1 then z-=t end;p z"}], "src_uid": "bbc2683d207f147a2a0abedc67ff157a"} {"source_code": "n, k = gets.chomp.split.map(&:to_i)\n\nas = Array.new(n) { Array.new(n, 0) }\ns = 0\nm = 1\nfor i in 0...n\n for j in 0...k - 1\n as[i][j] = m\n m += 1\n end\nend\n\nfor i in 0...n\n as[i][k - 1] = m\n s += m\n m += 1\n for j in k...n\n as[i][j] = m\n m += 1\n end\nend\n\nputs s\nas.map { |a| puts a.*' ' }\n", "positive_code": [{"source_code": "n, k = gets.split.map(&:to_i)\nans = Array.new(n){Array.new(n)}\nn2 = n*n\nfor i in 0...n\n for j in 0..(n - k)\n ans[i][n - 1 - j] = n2\n n2 -= 1\n end\nend\na = 1\nfor i in 0...n\n for j in 0...(k-1)\n ans[i][j] = a \n a += 1\n end\nend\nsum = 0\nn.times do |i|\n sum += ans[i][k-1]\nend\nputs sum\nn.times do |i|\n puts \"#{ans[i].join(' ')}\"\nend"}, {"source_code": "n, k = gets.split(' ').map &:to_i\nmin = (k-1)*n + 1\nsum = 0\n\ng = []\nic = 1\noc = min\nfor i in 0...n\n g[i] = []\n for j in 0...n\n if j < k-1\n g[i][j] = ic\n ic += 1\n else\n g[i][j] = oc\n oc += 1\n end\n end\n sum += g[i][k-1]\nend\n\nputs sum\nfor r in g\n puts r.join(' ')\nend \n"}], "negative_code": [{"source_code": "n, k = gets.split(' ').map &:to_i\nmin = (k-1)*n + 1\nsum = min\nfor i in 1...n\n sum += min + i*k\nend\n\ng = []\nic = 1\noc = min\nputs sum\nfor i in 0...n\n g[i] = []\n for j in 0...n\n if j < k-1\n g[i][j] = ic\n ic += 1\n else\n g[i][j] = oc\n oc += 1\n end\n end\n puts g[i].join(' ')\nend\n"}], "src_uid": "272f66f3c71c4997c5a1f0f009c9b99e"} {"source_code": "n = gets.to_i\n\na = gets.split.map { |x| x.to_i }\n\nb = a.dup\nb.sort!\n\nres = []\n0.upto(a.size-1) do |i|\n\tif a[i]!= b[i]\n\t\tj = a.rindex b[i]\n\t\ta[j] = a[i]\n\t\tres << \"#{i} #{j}\"\n\tend\nend\nputs res.size\nputs res\n\n", "positive_code": [{"source_code": "#$stdin = File.open \"input.txt\"\n\nn = gets.to_i\na = gets.split.map &:to_i\nb = (0...n).to_a\n\nputs n - 1\n(n - 1).times do |i|\n\tm = a[i...n].min\n\tj = i + a[i...n].index(m)\n\t\n\tputs \"#{i} #{j}\"\n\ta[i], a[j] = a[j], a[i]\nend\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = gets.to_i\nl = gets.chomp.split(' ').map { |i| i.to_i }\ns = 0\nsw = []\n(0..n-2).each do |i| \n im = l[i..n-1].index(l[i..n-1].min) + i\n if im != i\n temp = l[i]\n l[i] = l[im]\n l[im] = temp\n s += 1\n sw << \"#{i} #{im}\"\n end\nend\n\np s\nputs sw\n\n"}, {"source_code": "n = STDIN.readline.to_i\ndata = STDIN.readline.split.each_with_index.map {|s, i| [s.to_i, i] }\nsorted = data.sort\nindex = {}\ndata.each_with_index {|pair, i| index[pair] = i }\nmoves = []\nsorted.each_with_index do |p, i|\n\tnext if index[p] == i\n\tq, j = data[i], index[p]\n\tdata[i], index[p] = p, i\n\tdata[j], index[q] = q, j\n\tmoves.push([i, j])\nend\nputs moves.length\nputs moves.map {|a, b| '%d %d' % [a, b] }.join \"\\n\" if moves.length != 0\n"}], "negative_code": [{"source_code": "n = gets.to_i\n\na = gets.split.map { |x| x.to_i }\n\nb = a.dup\nb.sort!\n\nres = []\n0.upto(a.size-1) do |i|\n\tif a[i]!= b[i]\n\t\tj = a.index b[i]\n\t\ta[j] = a[i]\n\t\tres << \"#{i} #{j}\"\n\tend\nend\nputs res.size\nputs res\n\n"}, {"source_code": "n = STDIN.readline.to_i\ndata = STDIN.readline.split.each_with_index.map {|s, i| [s.to_i, i] }\nsorted = data.sort\nindex = {}\ndata.each_with_index {|pair, i| index[pair] = i }\nmoves = []\nsorted.each_with_index do |pair, i|\n\tnext if index[pair] == i\n\tmoves.push([i, index[pair]])\n\tindex[data[i]] = index[pair]\n\tindex[pair] = i\nend\nputs moves.length\nputs moves.map {|a, b| '%d %d' % [a, b] }.join \"\\n\" if moves.length != 0\n"}, {"source_code": "#$stdin = File.open \"input.txt\"\n\nn = gets.to_i\na = gets.split.map &:to_i\nb = (0...n).to_a\n\nputs n - 1\n(n - 1).times do |i|\n\tm = a[i + 1...n].min\n\tj = a.index(m)\n\t\n\tputs \"#{i} #{j}\"\n\ta[i], a[j] = a[j], a[i]\nend\n\n"}, {"source_code": "#$stdin = File.open \"input.txt\"\n\nn = gets.to_i\na = gets.split.map &:to_i\nb = (0...n).to_a\n\n(1...n).each do |i|\n\tj = i\n\twhile (j > 0) && (a[j] < a[j - 1])\n\t\ta[j], a[j - 1] = a[j - 1], a[j]\n\t\tb[j], b[j - 1] = b[j - 1], b[j]\n\t\tj -= 1\n\tend\nend\n\nswaps = []\nn.times { |i| swaps << [i, b[i]] if b[i] > i }\n\nputs swaps.size\nswaps.each { |s| puts \"#{s[0]} #{s[1]}\" }\n"}], "src_uid": "b3c6058893f935d88196113fab581cf8"} {"source_code": "def num_ways(n, k)\n count = 1\n for i in 0...(n-k)\n count += 1\n end\n count\nend\n\ndata = gets.split.map(&:to_i)\nn = data[0]\nt = data[1]\nc = data[2]\narr = gets.split.map(&:to_i)\naarr = []\nsub = []\nfor i in 0...n\n if arr[i] <= t\n sub << arr[i]\n else\n aarr << sub\n sub = []\n end\nend\n\naarr << sub\n\ncount = 0\nfor arr in aarr do\n if arr.length < c\n next\n end\n count += num_ways(arr.length, c)\nend\n\nputs count\n", "positive_code": [{"source_code": "n, c, t = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nx = 0\ny = t\n\nsev = 0\ncount = 0\n\nfor i in 0...t\n if a[i] > c\n sev += 1\n end\nend\n\nif sev == 0\n count += 1\nend\n\nfor i in 0...n-t\n if a[x+i] > c\n sev -= 1\n end\n if a[y+i] > c\n sev += 1\n end\n if sev == 0\n count += 1\n end\nend\n\nprint count\n"}, {"source_code": "n,t,c=gets.split.map &:to_i\np=gets.split.map &:to_i\nw,r=0,0\np.each{|l|r=l>t ?0:r+1;r>=c&&w+=1}\nputs w\n"}, {"source_code": "n,t,c=gets.split.map &:to_i\np=gets.split.map &:to_i\nw,r=0,0\np.each{|l|r=l>t ?0:r+1;r>=c&&w+=1}\nputs w"}, {"source_code": "n, t, c = gets.strip.split(\" \").map(&:to_i)\na = gets.strip.split(\" \").map(&:to_i)\ni = 0\nnum = 0\ncount = 0\nwhile i < n do \n if a[i] <= t then\n num += 1 \n elsif num >= c then\n count += num - c + 1\n num = 0\n else\n num = 0\n end\n i += 1\nend \nif num >= c then\n count += num - c + 1\nend\nputs count"}, {"source_code": "n,t,c=gets.split.map &:to_i\np=gets.split.map &:to_i\nw,r=0,0\np.each{|l|r=l>t ?0:r+1;r>=c&&w+=1}\nputs w\n"}, {"source_code": "n,t,c=gets.split.map &:to_i\np=gets.split.map &:to_i\nw,r=0,0\np.each{|l|r=l>t ?0:r+1;r>=c&&w+=1}\nputs w\n"}, {"source_code": "n,t,c = gets.split(' ').map(&:to_i)\np = gets.split(' ').map(&:to_i)\nl,ans=0,0\np.each do |i|\n if i > t\n l=0\n else\n l+=1\n end\n if l>=c\n ans+=1\n end\n end\n puts ans"}, {"source_code": "n,t,c = gets.split(' ').map(&:to_i)\np = gets.split(' ').map(&:to_i)\nl, ans=0, 0\np.each do |i|\n if i > t\n l=0\n else\n l+=1\n end\n if l>=c\n ans+=1\n end\n end\n puts ans"}, {"source_code": "n, t, c = gets.split\nn = Integer n\nt = Integer t\nc = Integer c\n\nnums = gets.split\nfor i in 0...n\n nums[i] = Integer nums[i]\nend\n\n\n# how many t have we found ?\ncount_t = 0\n# the answer/count\ncount = 0\n\nfor i in 0...n\n if nums[i] > t\n count_t += 1\n end\n \n if i >= c && nums[i-c] > t\n count_t -= 1\n end\n \n if i >= c - 1 && count_t == 0\n count += 1\n end\nend\n\nputs count\n "}, {"source_code": "n, t, c = gets.split\nn = Integer n\nt = Integer t\nc = Integer c\n\nnums = gets.split\nfor i in 0...n\n nums[i] = Integer nums[i]\nend\nnums[n] = t + 1\n\n\n# what's the position of last number > t found?\nlast_t_found = -1\n# the answer/count\ncount = 0\n\nfor i in 0..n\n if nums[i] > t\n if i - last_t_found > c\n count += i - last_t_found - c\n end\n last_t_found = i\n end\nend\n\nputs count\n "}, {"source_code": "n, t, c = gets.split\nn = Integer n\nt = Integer t\nc = Integer c\n\nnums = gets.split\nfor i in 0...n\n nums[i] = Integer nums[i]\nend\n\n\n# what's the position of last number > t found?\nlast_t_found = -1\n# what's the last position we've checked?\nlast_checked = -1\n# the answer/count\ncount = 0\n \n# loop through all possible i\nfor i in 0..n-c\n # if no t appears after i by now\n if i > last_t_found\n # check all the number between i and i+c\n for j in last_checked+1...i+c\n # find a t after i\n if nums[j] > t\n # record what we've seen\n last_t_found = j\n last_checked = j\n break\n end\n end\n \n # no t found after i?\n if last_t_found < i\n last_checked = i + c - 1\n count += 1\n end\n end\nend\n\nputs count\n "}, {"source_code": "n,t,c=gets.split.map &:to_i\np=gets.split.map &:to_i\nw,r=0,0\np.each{|l|r=l>t ?0:r+1;r>=c&&w+=1}\nputs w\n"}, {"source_code": "n,t,c = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nans = 0\ncnt = a[0...c-1].count { |p| p > t }\na[c-1...n].each_with_index { |p, idx|\n cnt += 1 if p > t\n ans += 1 if cnt == 0\n cnt -= 1 if a[idx] > t\n}\n\nputs ans"}, {"source_code": "# Read input\nn, t, c = gets.strip.split.map(&:to_i)\na = gets.strip.split.map(&:to_i)\n\n# Grab the locations of elements > t \nspoilerloc = a.each_index.select{|i| a[i] > t}.unshift(-1).push(n)\n\n# Spot dead segments\nrsum = 0\n\nfor i in 1..(spoilerloc.length - 1) do\n m = spoilerloc[i] - spoilerloc[i-1] - 1\n rsum = rsum + [m - c + 1, 0].max\nend\n\nputs rsum"}, {"source_code": "n, t, c = gets.strip.split.map(&:to_i)\na = gets.strip.split.map(&:to_i)\na = a.chunk{ |i| i <= t }.to_a.map{|t, a| a if t}.compact\nsum = a.inject(0){|s, arr| s + ([arr.count - c + 1, 0].max)}\nputs sum\n"}, {"source_code": "n,t,c=gets.split.map &:to_i\np=gets.split.map &:to_i\nw,r=0,0\np.each{|l|r=l>t ?0:r+1;r>=c&&w+=1}\nputs w\n"}, {"source_code": "n, t, c = gets.split(' ').map(&:to_i)\narr = gets.split(' ').map(&:to_i)\nlast = -1\npossible = 0\n(0..n-1).each do |index|\n if arr[index] > t\n last = index\n elsif index - last >= c\n possible += 1\n end\nend\nputs possible"}, {"source_code": "n,t,c=gets.split.map &:to_i\np=gets.split.map &:to_i\nw,r=0,0\np.each{|l|r=l>t ?0:r+1;r>=c&&w+=1}\nputs w\n"}, {"source_code": "n,t,c=gets.split.map &:to_i\np=gets.split.map &:to_i\nw,r=0,0\np.each{|l|r=l>t ?0:r+1;r>=c&&w+=1}\nputs w\n"}, {"source_code": "n,t,c=gets.split.map &:to_i\np=gets.split.map &:to_i\nw,r=0,0\np.each{|l|r=l>t ?0:r+1;r>=c&&w+=1}\nputs w"}, {"source_code": "n,t,c=gets.split.map &:to_i\np=gets.split.map &:to_i\nw,r=0,0\np.each{|l|r=l>t ?0:r+1;r>=c&&w+=1}\nputs w\n"}, {"source_code": "n, t, c = gets.split.map &:to_i\ns = gets.split.map &:to_i\ns.push t + 1\nl = 0\nans = 0\n(n+1).times do |i|\n if s[i] > t then\n if i - l >= c then\n ans += i - l + 1 - c\n end\n l = i + 1\n end\nend\nputs ans\n"}], "negative_code": [{"source_code": "n,t,c = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nans = 0\ncnt = a[0...c-1].count { |p| p > t }\na[c-1...n].each_with_index { |p, idx|\n cnt += 1 if p > t\n ans += 1 if cnt == 0\n cnt -= 1 if a[idx-c+1] > t\n}\n\nputs ans"}, {"source_code": "n,t,c = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nans = 0\ncnt = a[0...c-1].count { |p| p >= t }\na[c-1...n].each_with_index { |p, idx|\n cnt += 1 if p >= t\n ans += 1 if cnt == 0\n cnt -= 1 if a[idx-c+1] >= t\n}\n\nputs ans"}, {"source_code": "# Read input\nn, t, c = gets.strip.split.map(&:to_i)\na = gets.strip.split.map(&:to_i)\n\n# Grab the locations of elements > t \nspoilerloc = a.each_index.select{|i| a[i] > t}\n\n# Create mask\nmask = (-1 * c + 1 .. c - 1).to_a - [0]\nmask = [0] if c == 1\n\n# Spot dead segments\nout = []\nfor i in spoilerloc\n masked = mask.map{|j| j + i}\n out = out | masked\nend\n\nputs n - c + 1 - out.length"}], "src_uid": "7d1e8769a6b1d5c6680ab530d19e7fa4"} {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = Array.new(n){gets.split.map(&:to_i)}\r\n x = 0\r\n y = 0\r\n n.times do |i|\r\n m.times do |j|\r\n if a[y][x] < a[i][j]\r\n x = j\r\n y = i\r\n end\r\n end\r\n end\r\n\r\n x = [x+1, m-x].max\r\n y = [y+1, n-y].max\r\n puts x*y\r\nend\r\n", "positive_code": [{"source_code": "t = gets.to_i\nt.times {\n n, m = gets.split.map &:to_i\n g = []\n for i in (1..n)\n g += [gets.split.map(&:to_i)]\n end\n big = -2000000000\n big_i = -1\n big_j = -1\n for i in (0...n)\n for j in (0...m)\n if g[i][j] > big\n big = g[i][j]\n big_i = i\n big_j = j\n end\n end\n end\n h = [big_i + 1, n - big_i].max\n w = [big_j + 1, m - big_j].max\n puts h * w\n}\n"}], "negative_code": [{"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = Array.new(n){gets.split.map(&:to_i)}\r\n x = 0\r\n y = 0\r\n n.times do |i|\r\n m.times do |j|\r\n if a[y][x] < a[i][j]\r\n x = j\r\n y = i\r\n end\r\n end\r\n end\r\n\r\n x = [x+1, n-x].max\r\n y = [y+1, m-y].max\r\n puts x*y\r\nend\r\n\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = Array.new(n){gets.split.map(&:to_i)}\r\n max_n = 0\r\n x = 0\r\n y = 0\r\n n.times do |i|\r\n m.times do |j|\r\n if max_n < a[i][j]\r\n max_n = a[i][j]\r\n x = j+1\r\n y = i+1\r\n end\r\n end\r\n end\r\n x = [x, n-x+1].max\r\n y = [y, m-y+1].max\r\n puts x*y\r\nend\r\n"}, {"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n a = Array.new(n){gets.split.map(&:to_i)}\r\n max_n = 0\r\n x = 0\r\n y = 0\r\n n.times do |i|\r\n m.times do |j|\r\n if max_n < a[i][j]\r\n max_n = a[i][j]\r\n x = j+1\r\n y = i+1\r\n end\r\n end\r\n end\r\n puts [x*y, (m-x+1)*y, x*(n-y+1), (m-x+1)*(n-y+1)].max\r\nend\r\n"}], "src_uid": "47e5ccd8220afa84c95f36b08ed1817a"} {"source_code": "n2=[2,4,8,16]\nn3=[3,9,27,81]\nn4=[4,16]\nt=gets.chomp\nn=0\nif t.size<5 then\n\tn=(t.to_i-1)\nelse\n\tt1=t.size-1\n\tt2=\"\"\n\tt2<<(t[t1-2]+t[t1-1]+t[t1])\n\tn=t2.to_i-1\nend\nputs (1+n2[n%4]+n3[n%4]+n4[n%2])%5\n\n", "positive_code": [{"source_code": "n_str=gets.chomp\nn_100 = (n_str.length > 3 ? n_str[-3..-1] : n_str).to_i\nputs n_100 % 4 == 0 ? \"4\" : \"0\"\n\n"}, {"source_code": "n = ('00' + gets.chomp)[-2, 2].to_i\n\nif n % 4 == 0\n\tputs 4\nelse\n\tputs 0\nend"}, {"source_code": "num = gets.chomp \n\ncount = 0\ncount += num[-1].to_i + num[-2].to_i*10 \n\n\nif count%4==0 \n puts \"4\" \nelse \n puts \"0\"\nend "}, {"source_code": "n = gets.chomp\nputs (n.length > 2 ? n[-2..-1] : n).to_i % 4 == 0 ? 4 : 0"}, {"source_code": "sum=0\nf=gets.chomp\nf=(f[f.length-2]+f[f.length-1]).to_i\nif f%4==3\nans=(1+3+2+4)%5\nputs \"#{ans}\"\nelsif f%4==0\nans=(1+1+1+1)%5\nputs \"#{ans}\"\nelsif f%4==2\nans=(1+4+4+1)%5\nputs \"#{ans}\"\nelse\nans=(1+2+3+4)%5\nputs \"#{ans}\"\nend"}, {"source_code": "n = gets.to_s\nif n.length > 3\n n = n[-3..-1]\nend\nn = n.to_i\nif n % 4 == 0\n p 4\nelse\n p 0\nend\n"}, {"source_code": "n = gets.chomp\nn = n[-2..-1] if n.size > 2\nn = n.to_i % 4\na2 = [6, 2, 4, 8]\na3 = [1, 3, 9, 7]\na4 = [6, 4, 6, 4]\nputs (1 + a2[n] + a3[n] + a4[n]) % 5\n"}, {"source_code": "n = gets.chomp.chars.map(&:to_i)\nn = n[-2..-1] if n.size >= 2\ni = n.join.to_i % 4\na2 = [6, 2, 4, 8]\na3 = [1, 3, 9, 7]\na4 = [6, 4]\nputs (1 + a2[i] + a3[i] + a4[i % 2]) % 5\n"}, {"source_code": "# Read Input\ns = gets.strip\n\n# Take the last two digits\nn = s.length > 2 ? s[-2..-1].to_i : s.to_i\n\n# Return result\nputs (n % 4) == 0 ? 4 : 0"}, {"source_code": "s = gets.chomp\ns = s[-2..-1] if s.size > 1\nputs [4, 0, 0, 0][s.to_i % 4]"}], "negative_code": [{"source_code": "n = gets\nputs (n.length > 2 ? n[-2, -1].to_i : n.to_i) % 4 == 0 ? 4 : 0"}, {"source_code": "sum=0\nf=gets.chomp\nf.each_char do |i|\nsum+=i.to_i\nend\nif(sum%4==0)\nans=(1+1+1+1)%5\nputs \"#{ans}\"\nelsif(sum%4==1)\nans=(1+2+3+4)%5\nputs \"#{ans}\"\nelsif(sum%4==2)\nans=(1+4+4+1)%5\nputs \"#{ans}\"\nelsif(sum%4==3)\nans=(1+3+3+4)%5\nputs \"#{ans}\"\nend"}, {"source_code": "sum=0\nf=gets.chomp\nf.each_char do |i|\nsum+=i.to_i\nend\n\nif((f[f.length-1]+f[f.length-2]).to_i)%4==3\nans=(1+3+3+4)%5\nputs \"#{ans}\"\nelsif((f[f.length-1]+f[f.length-2]).to_i)%4==0\nans=(1+1+1+1)%5\nputs \"#{ans}\"\nelsif((f[f.length-1]+f[f.length-2]).to_i)%4==2\nans=(1+4+4+1)%5\nputs \"#{ans}\"\nelse\nans=(1+2+3+4)%5\nputs \"#{ans}\"\nend"}, {"source_code": "sum=0\nf=gets.chomp\nf=(f[f.length-2]+f[f.length-1]).to_i\nif f%4==3\nans=(1+3+3+4)%5\nputs \"#{ans}\"\nelsif f%4==0\nans=(1+1+1+1)%5\nputs \"#{ans}\"\nelsif f%4==2\nans=(1+4+4+1)%5\nputs \"#{ans}\"\nelse\nans=(1+2+3+4)%5\nputs \"#{ans}\"\nend"}, {"source_code": "n = gets.chomp.chars.map(&:to_i)\nn = n.inject(:+)\na2 = [6, 2, 4, 8]\na3 = [1, 3, 9, 7]\na4 = [6, 4]\nans = 1\nn %= 4\nputs (ans + a2[n] + a3[n] + a4[n % 2]) % 5\n"}, {"source_code": "\nn = gets.strip.to_i\n\na = 5 ** (n * Math.log(2, 5)).modulo(1).floor\nb = 5 ** (n * Math.log(3, 5)).modulo(1).floor\nc = 5 ** (n * Math.log(4, 5)).modulo(1).floor\n\nputs (1 + (a % 5) + (b % 5) + (c % 5)) % 5"}, {"source_code": "# Read Input\ns = gets.strip\n\n# Take the last two digits\nn = s.length > 2 ? s[-2..-1].to_i : n.to_i\n\n# Return result\nputs (n % 4) == 0 ? 4 : 0"}, {"source_code": "n = ('00' + gets)[-2, 2].to_i\n\nif n % 4 == 0\n\tputs 4\nelse\n\tputs 0\nend"}], "src_uid": "74cbcbafbffc363137a02697952a8539"} {"source_code": "results = []\n\nt = gets.chomp\n(1..t.to_i).each do |iteration|\n\tn = gets.chomp.to_i\n\ttasks = gets.chomp.split('')\n\tno_f = true\n\ttasks.each_with_index do |let, idx|\n\t\tnext if let == tasks[idx+1]\n\n\t\tif tasks[idx+1..-1].include? let\n\t\t\tresults.push(\"NO\")\n\t\t\tno_f = false\n\t\t\tbreak\n\t\tend\n\tend\n\tresults.push(\"YES\") if no_f\nend\nresults.each do |res|\n\tputs res\nend", "positive_code": [{"source_code": "def destructed(str, n)\n mp = {}\n str.chars.each_with_index do |v, i|\n if mp.key?(str[i])\n mp[v] = mp[v] << i\n else\n mp[v] = [i]\n end\n end\n # found = true\n mp.each_pair do |k, v|\n len = v.length\n (0..len-2).each do |i|\n if v[i+1] - v[i] != 1\n return false\n end\n end\n end\n return true\nend\n\nt = gets.to_i\ninputs = []\n(0...t).each do\n n = gets.to_i\n str = gets.chomp\n inputs<<[str, n]\nend\n\ninputs.each do |input|\n str = input[0]\n n = input[1]\n res = destructed(str, n)\n if res\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "gets.to_i.times {\n gets\n s = gets.strip\n ('A'..'Z').each { s.gsub!(/(#{_1})+/, _1) }\n h = Hash.new 0\n s.each_char { h[_1] += 1 }\n ans = h.values.any? { _1 > 1 }\n puts(ans ? \"NO\" : \"YES\")\n}\n"}, {"source_code": "t = gets.chomp.to_i\r\n\r\nwhile t != 0\r\n\r\n n = gets.chomp.to_i\r\n str = gets.chomp\r\n\r\n mp = {} # map of indices\r\n for i in 0...n\r\n mp[ str[i] ] = i\r\n end\r\n\r\n y = true\r\n for i in 0...n\r\n\r\n for j in i...mp[str[i]]\r\n if str[i] != str[j]\r\n y = false\r\n break\r\n end\r\n end\r\n\r\n if y == false\r\n break\r\n end\r\n end\r\n\r\n if y == true\r\n puts(\"YES\")\r\n else\r\n puts(\"NO\")\r\n end\r\n\r\n t = t-1\r\nend"}, {"source_code": "require 'set'\n\nt = gets.chomp.to_i\n\ndef cannot_be_sus\n _ = gets\n # @type [String]\n input = gets.chomp\n\n last_seen_char = nil\n seen = Set.new\n input.each_char do |c|\n if c == last_seen_char\n # do nothing\n elsif seen.include? c\n return false\n else\n seen.add c\n end\n last_seen_char = c\n end\n true\nend\n\n(1..t).each do\n cannot_be_sus ? (puts 'YES') : (puts 'NO')\nend\n"}, {"source_code": "t = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.strip.split(\"\")\n seen = {}\n seen[a[0]] = true\n prev = a[0]\n bad = false\n 1.upto(n - 1) do |i|\n next if prev == a[i]\n if seen[a[i]]\n bad = true\n break\n end\n seen[a[i]] = true\n prev = a[i]\n end\n printf(\"%s\\n\", bad ? \"NO\" : \"YES\")\nend\n\n"}], "negative_code": [], "src_uid": "3851854541b4bd168f5cb1e8492ed8ef"} {"source_code": "gets;puts $<.map(&:chomp).reverse.uniq\n", "positive_code": [{"source_code": "gets;puts $<.map(&:chomp).reverse.uniq"}, {"source_code": "require 'set'\nn = gets.to_i\nchats = []\nn.times do\n chats.push(gets.chomp)\nend\ns = Set.new\nchats.reverse.each do |name|\n if !s.include?(name)\n puts name\n s << name\n end\nend\n"}], "negative_code": [], "src_uid": "18f4d9262150294b63d99803250ed49c"} {"source_code": "gets.to_i.times do\r\n puts ['maomao90', 'errorgorn'][(gets.to_i+gets.chomp.split.map(&:to_i).inject(:+))&1]\r\nend", "positive_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n puts xs.map { |x| x - 1 }.sum.even? ? \"maomao90\" : \"errorgorn\"\r\nend\r\n"}], "negative_code": [], "src_uid": "fc75935b149cf9f4f2ddb9e2ac01d1c2"} {"source_code": "T = gets.to_i\nT.times do\n n = gets.to_i\n s = gets.chomp\n if !s.include?(\"1\")\n p n\n else\n l,r = 0,n-1\n l += 1 while s[l] == \"0\"\n r -= 1 while s[r] == \"0\"\n p [n-l,r+1].max*2\n end\nend", "positive_code": [{"source_code": "readline.to_i.times do\n n = readline.to_i\n s = readline.chomp\n z = [n + s.count(\"1\")]\n if z[0] > n then\n l,r = s.index(\"1\"), s.rindex(\"1\")\n z << 2*(r+1)\n z << 2*(n-l)\n end\n p z.max\nend\n"}, {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2 0 && i % 2 == 1 && a[i] - a[i - 1] >= 2 && a[i] - a[i + 1] >= 2 ? a[i] - 1 : a[i]\n k -= 1 if b[i] != a[i]\nend\nputs b.join \" \"\n", "positive_code": [{"source_code": "n,k=gets.split.map &:to_i;a=gets.split.map &:to_i;1.step(2*n,2){|i|(a[i]-=1)&&(k-=1) if a[i]-1>a[i-1]&&a[i]-1>a[i+1];break if k==0};$><a[i-1]&&a[i]-1>a[i+1];break if k==0};$><a[i-1]&&a[i]-1>a[i+1];break if k==0};$>< a[i+1]\n mordor.push i\n picks.delete i\n break\n end\n end\nend\n\nmordor.each {|j| a[j]-=1 }\nputs a*' '"}, {"source_code": "n,k=gets.split.map &:to_i;a=gets.split.map &:to_i;1.step(2*n,2){|i|(a[i]-=1)&&(k-=1) if a[i]-1>a[i-1]&&a[i]-1>a[i+1];break if k==0};$><a[i-1]&&a[i]-1>a[i+1];break if k==0};$>< y[i-1] && y[i]-1 > y[i+1]\n y[i] -=1\n c += 1\n break if c == k\n end\nend\nputs y.join(\" \")"}, {"source_code": "#!/usr/bin/ruby\nn,k = gets.chomp.split(' ').map{|x| x.to_i}\nline = gets.chomp.split(' ').map{|x| x.to_i}\nktmp=0\nfor i in 0..(2*n)\n if i%2==1\n if line[i]-1>line[i-1] && line[i]-1 > line[i+1] && ktmp < k\n ktmp+=1\n line[i]-=1;\n end\n end\n print line[i].to_s + \" \" if i < 2*n\nend\nputs line[2*n]\n"}, {"source_code": "\nn,m = gets.split.map(&:to_i)\nar = gets.split.map(&:to_i)\n\n\nwhile m > 0\n\ti = 1\n\twhile i < ar.length\n\t\tif ar[i] > ar[i-1] + 1 and ar[i] > ar[i+1] + 1\n\t\t\tar[i] -= 1\n\t\t\tm -= 1\n\t\t\tbreak if m == 0\n\t\tend\n\t\ti += 2\n\tend\nend\n\nfor x in ar\n\tprint x.to_s + \" \"\nend\n\n\n\n\n"}, {"source_code": "#!/usr/bin/ruby\ninclude Math\n\nn,k = gets.split.map(&:to_i)\npic = gets.split.map(&:to_i)\ndec = 0\nn.times do |i|\n if pic[2*i+1] - pic[2*i] > 1 && pic[2*i+1] - pic[2*i+2] > 1\n pic [2*i+1] -= 1\n dec += 1\n end\n break if dec >= k\nend\nputs pic.join(' ')\n"}, {"source_code": "n,k=gets.split.map &:to_i;a=gets.split.map &:to_i;1.step(2*n,2){|i|(a[i]-=1)&&(k-=1) if a[i]-1>a[i-1]&&a[i]-1>a[i+1];break if k==0};$><a[i-1]&&a[i]-1>a[i+1];break if k==0};$><0\n r[i]-=1\n k-=1\n end\nend\n\nr.each do |rr|\n print \"#{rr} \"\nend"}, {"source_code": "n,k=gets.split.map &:to_i;a=gets.split.map &:to_i;1.step(2*n,2){|i|(a[i]-=1)&&(k-=1) if a[i]-1>a[i-1]&&a[i]-1>a[i+1];break if k==0};$><a[i-1]&&a[i]-1>a[i+1];break if k==0};$><a[i-1]&&a[i]-1>a[i+1];break if k==0};$>< 1) && (ra[pe] - ra[nx] > 1)\n ra[pe] -= 1\n k2 -= 1\n end\n break if k2 <= 0\nend\nputs ra.join(\" \")\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\ni = 1; while (true)\t\n\tif (a[i] - a[i-1] > 1 && a[i] - a[i+1] > 1) \n\t\ta[i] -= 1; k -= 1 \n\t\tbreak if (k.zero?) \n\tend\t\n\ti += 2\nend\n\nputs a*' '"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nn.times do |i|\n\tii = 2 * i + 1\n\tif (a[ii] - a[ii-1] > 1 && a[ii] - a[ii+1] > 1)\n\t\ta[ii] -= 1; k -= 1\n\tend\n\tbreak if k.zero?\nend\n\nputs a.join(' ')"}, {"source_code": "I =->{gets.split.map &:to_i}\n\nn, k = I[]; a = I[]\ni = 1; while (true)\t\n\tif a[i] - a[i-1] > 1 && a[i] - a[i+1] > 1\t\t\t\n\t\ta[i] -= 1; k -= 1; break if (k.zero?) \n\tend\n\ti += 2\nend\n\nputs a*' '"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\ni = 1; while (true)\t\n\tif (a[i] - a[i-1] > 1 && a[i] - a[i+1] > 1) \n\t\ta[i] -= 1; k -= 1 \n\t\tbreak if (k.zero?) \n\tend\t\n\ti += 2\nend\n\nputs a.join(' ')"}], "negative_code": [{"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\nn.times do |i|\n\tii = 2 * i + 1\n\tif (a[ii] - a[ii-1] > 1 && a[ii] - a[ii+1] > 1)\n\t\t--a[ii]; --k\n\tend\n\tbreak if k.zero?\nend\n\nputs a.join(' ')"}, {"source_code": "#!/usr/bin/ruby\ninclude Math\nstr = gets\nstr.gsub! /(WUB)+/, ' '\nstr.gsub! /^\\s*/,''\nstr.gsub! /\\s*$/,''\nputs str\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nr = gets.split.map(&:to_i)\n1.upto(n) do |i|\n next if i%2==0\n break if k==0\n if r[i-1] < r[i]-1 && r[i+1]< r[i]-1 && k>0\n r[i]-=1\n k-=1\n end\nend\n\nr.each do |rr|\n print \"#{rr} \"\nend"}], "src_uid": "1adb4675dc88208f8a05a2db49bb44cb"} {"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n dxs = xs.each_cons(2).map { |a, b| b - a }.sort.reverse\r\n if dxs.empty? || dxs[0] == 1 || dxs[0] == 2 && dxs.count(2) <= 2 || dxs[0] == 3 && (dxs[1] == nil || dxs[1] == 1)\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.chomp.split.map(&:to_i)\n c = 0\n 1.upto(n-1) do |i|\n c += a[i] - a[i-1] - 1\n end\n puts c > 2 ? \"NO\":\"YES\"\nend\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n dxs = xs.each_cons(2).map { |a, b| b - a }.sort.reverse\r\n if dxs.empty? || dxs[0] == 1 || dxs[0] == 2 && dxs.count(2) <= 2 || dxs[0] == 3 && dxs.count(3) == 1\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}], "src_uid": "f4267120fce9304fc4c45142b60fb867"} {"source_code": "gets.to_i.times do\r\n n, k = gets.split.map(&:to_i)\r\n ps = gets.split.map(&:to_i)\r\n p ps[..k - 1].count { |p| p > k }\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n,k = gets.split.map(&:to_i)\r\n inputs = gets.split.map(&:to_i)\r\n puts inputs[...k].count { |x| x>k }\r\nend\r\n"}, {"source_code": "gets.to_i.times do\n n,k=gets.split.map(&:to_i)\n p=gets.split.map(&:to_i)\n puts p[0...k].count {|i| i>k}\nend\n"}], "negative_code": [], "src_uid": "10927dcb59007fc3a31fdb6b5d13846f"} {"source_code": "n = gets.to_i\na = Array.new(2 * n + 1){Array.new(2 * n + 1){' '}}\n(-n .. n).each do |i|\n\tk = n - i.abs\n\t(-k .. k).each do |j|\n\t\ta[i + n][j + n] = (k - j.abs).to_s\n\tend\nend\nputs a.map{|_| (_ * ' ').rstrip} * \"\\n\"\n", "positive_code": [{"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}\n"}, {"source_code": "def line(a, n)\n space = Array.new(n-a){\" \"}.join(\"\")\n str = \"#{a}\"\n while a > 0\n a -= 1\n str = \"#{a} #{str} #{a}\"\n end\n puts space + str\nend\n\nn = gets.to_i\ni = 0\nwhile i <= n do\n line(i, n)\n i += 1\nend\ni = n-1\nwhile i >= 0 do\n line(i, n)\n i -= 1\nend"}, {"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}\n"}, {"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}"}, {"source_code": "n = gets.to_i\n\n(0..2 * n).each do |y|\n s = \"\"\n (0..2 * n).each do |x|\n t = n - (x - n).abs - (y - n).abs\n s += (t >= 0 ? t.to_s : \" \")\n s += \" \"\n end\n puts s.rstrip\nend\n"}, {"source_code": "n = gets.to_i\n(0..n).each do |i|\n puts \" \"*(2*(n-i)) + (0..i).to_a*\" \" + (\" \" if i != 0).to_s + (0...i).to_a.reverse*\" \"\nend\n(0..n-1).to_a.reverse.each do |i|\n puts \" \"*(2*(n-i)) + (0..i).to_a*\" \" + (\" \" if i != 0).to_s + (0...i).to_a.reverse*\" \"\nend"}, {"source_code": "x = gets.chomp.to_i\n\narr = []\n\n0.upto(x) do |ind|\n arr << \"\"\n arr.last << 0.upto(ind).to_a.join(' ')\n line_end = (ind-1).downto(0).to_a.join(' ')\n arr.last << ' ' + line_end if line_end.size > 0\nend\n\nlargest_len = arr.last.length\n\narr.each do |s|\n puts \" \"*((largest_len-s.length)/2) + s\nend\n\narr.reverse.drop(1).each do |s|\n puts \" \"*((largest_len-s.length)/2) + s\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\ndef readNextValues\n arr = gets.chomp.split\n return arr.collect {|x| x.to_i }\nend\n\n#######################\n\ndef nums(toNum)\n 0.upto(toNum) do |i|\n print \"#{i}\"\n if toNum != 0\n print ' '\n end\n end\n (toNum-1).downto(0) do |i|\n print \"#{i}\"\n if i != 0\n print ' '\n end\n end\nend\n\nn = gets.to_i\n\n0.upto(n) do |i|\n print ' ' * (n-i)\n nums(i)\n puts\nend\n(n-1).downto(0) do |i|\n print ' ' * (n-i)\n nums(i)\n puts\nend\n"}, {"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}"}, {"source_code": "n = gets.to_i\nstr = \" \" * 2 * n + \"0\"\n(1..n).each do |x|\n puts str\n str[2*n+1,0]=\" #{x} #{x-1}\"\n str[0,2]=\"\"\nend\n(1..n).each do |x|\n puts str\n str[2*n-2,4]=\"\"\n str[0,0]=\" \"\nend\nputs str"}, {"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}\n"}, {"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}\n"}, {"source_code": "n=gets.to_i\narr=[]\n(n+1).times{|i|\n\tstr=\"\"\n\tc1=i-n\n\td=1\n\tf=true\n\t0.upto(n+i){\n\t\tif (d==1) && (c1==i-n) then\n\t\telse\n\t\t\tstr<<\" \"\n\t\tend\n\t\tif c1<0 then\n\t\t\tstr<<\" \"\n\t\telse\n\t\t\tstr<i\n}\narr.reverse.each{|e|\n\tputs e\n}\n\n"}, {"source_code": "#!/usr/bin/env ruby\ndef a2s( a )\n b = []\n a.each do |i|\n if i < 0\n b << \" \"\n else\n b << i.to_s\n end\n end\n return b.join( \" \" ).rstrip\nend\n\nn = gets.to_i\na = []\n0.upto(n){ |i| a << i }\n(n-1).downto(0){ |i| a << i }\na.map!{ |i| i-n }\nn.times do |i|\n puts a2s(a)\n a.map!{ |i| i+1 }\nend\nn.times do |i|\n puts a2s(a)\n a.map!{ |i| i-1 }\nend\nputs a2s(a)\n"}, {"source_code": "n = gets.to_i + 1\n\nn.times do |i|\n (n-i-1).times do \nprint \" \"\n end\n\n (i+1).times do |ii|\n print ii\n print \" \" unless i == 0\n end\n (i-1).downto(0) do |ii|\n print ii\n print \" \" unless ii == 0\n end\n \n print \"\\n\"\nend\n\n(n-2).downto(0) do |i|\n (n-i-1).times do \n print \" \"\n end\n\n (i+1).times do |ii|\n print ii\n print \" \" unless i == 0\n end\n (i-1).downto(0) do |ii|\n print ii\n print \" \" unless ii == 0\n end\n \n print \"\\n\"\nend\n \n"}, {"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}"}, {"source_code": "n=gets.to_i;s='0123456789'.split //;b=[];(n+1).times{|k|b<<((s[0...k]+[k]+s[0...k].reverse)*' ').center(4*n+1).rstrip};puts b+b[0..-2].reverse\n"}, {"source_code": "n=gets.to_i\nb=[]\n\n(n+1).times{|k|\t\t\n\ta=[]\n\t(k+1).times{|i| a+=[i]}\n\t(k-1).downto(0){|i| a+=[i]}\n\t\n\tb << a.join(' ').center(2*n+2*n+1).rstrip\n}\nb+=b[0..-2].reverse\nputs b\n"}, {"source_code": "n=gets.to_i;b=[];(n+1).times{|k|a=[k];(k-1).downto(0){|i| a=[i]+a+[i]};b<<(a*' ').center(4*n+1).rstrip};b+=b[0..-2].reverse;puts b\n"}, {"source_code": "n=gets.to_i;b=[];(n+1).times{|k|a=[];(k+1).times{|i| a+=[i]};(k-1).downto(0){|i|a+=[i]};b< 0\n\t\t\tprint \" \"\n\t\tend\n\t}\n\tputs \"\"\nend\n#pts n\n(n-1).downto(0){ |y|\n for s in 1..n-y+n-y\n print \" \"\n end\n for x in 0..y-1\n print x\n\t\tprint \" \"\n end\n y.downto(0){ |x|\n\t\tprint x\n\t\tif x > 0\n\t\t\tprint \" \"\n\t\tend\n }\n puts \"\"\n\n\n}\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn = gets.chomp.to_i\n0.upto(n) do |i|\n puts \"#{' ' * (2*(n-i))}#{(0.upto(i).to_a + (i-1).downto(0).to_a).join(' ')}\"\nend\n(n-1).downto(0) do |i|\n puts \"#{' ' * (2*(n-i))}#{(0.upto(i).to_a + (i-1).downto(0).to_a).join(' ')}\"\nend\n"}, {"source_code": "i,a=gets.to_i,[]\n(0..i).map {|j| a << ((0...j).to_a << j.downto(0).to_a).flatten; a[j].unshift(' '*(i*2-j*2))\n}\na.each {|x| puts x.join(' ')[1..-1]}; a.pop; a.reverse_each {|x| puts x.join(' ')[1..-1]}"}, {"source_code": "n = gets.to_i\na = []\n(0..n).each{|i|\n s = ''\n (0..(n - ([i, i-n].min).abs)).each{|j| s = s + j.to_s + ' '}\n a << ' '*(n - i).abs + s.strip + s.reverse[2..-1]\n puts a[-1]\n}\n(0..n-1).each{|i| puts a[-2 - i]}"}, {"source_code": "n = gets.to_i\n(0..2*n).each{|i|\n s = ''\n (0..(n - ([i, i-n].min).abs)).each{|j| s = s + j.to_s + ' '}\n puts ' '*(n - i).abs + s.strip + s.reverse[2..-1]\n}"}, {"source_code": "n = gets.to_i\n(0..2*n).each{|i|\n s = ''\n st = ''\n (0..(n - ([i, i-n].min).abs)).each{|j| s = s + j.to_s + ' '}\n puts ' '*(n - i).abs + s.strip + s.reverse[2..-1]\n}\n"}, {"source_code": "# To change this template, choose Tools | Templates\n# and open the template in the editor.\n\nn = gets.chop.to_i\n\nsize = 2*n + 1\n\nfor i in -n..n\n line = \"\"\n for j in -n..n\n val = (n - (i.abs + j.abs))\n if (val >= 0)\n line += \"#{val} \"\n else\n line += \" \"\n end\n\n end\n puts line.rstrip\nend\n"}, {"source_code": "input = $stdin.readline.chop.to_i\nn = input\ni = 0\nwhile n>=0\n (n*2).times do \n print \" \"\n end\n\n for j in 0..(i-1)\n print \"#{j} \"\n end\n\n print \"#{i}\"\n print \" \" if i!=0\n\n j = i - 1\n while j>=0\n print j\n print \" \" if j!=0\n j-=1\n end\n\n print \"\\n\"\n n-=1\n i+=1\nend\n\nn = 1\ni = input-1\nwhile n<=input\n (n*2).times do \n print \" \"\n end\n\n for j in 0..(i-1)\n print \"#{j} \"\n end\n\n print \"#{i}\"\n print \" \" if i!=0\n\n j = i - 1\n while j>=0\n print j\n print \" \" if j!=0\n j-=1\n end\n\n print \"\\n\"\n n+=1\n i-=1\nend"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nlines = []\nfor i in (0..n).to_a + (0...n).to_a.reverse\n pads = n - i\n buf = []\n pads.times { buf << ' ' }\n lines << buf + (0..i).to_a + (0...i).to_a.reverse\nend\n\nfor line in lines\n puts line.join(' ')\nend"}, {"source_code": "n = Integer(gets)\nline = 2 * n + 1\na = Array.new\nfor i in 0...line\n a[i] = Array.new\nend\n\nfor i in 0...line\n if i <= n\n for j in 0...n+i+1\n a[i][j] = \" \"\n end\n else \n for j in 0...3*n+1-i\n a[i][j] = \" \"\n end\n end\nend\n\nfor m in 0...n\n \n for i in 0...line\n for j in 0...line\n if m == 0\n if i + j == n\n a[i][j] = 0\n a[i][2*n-j] = 0\n a[2*n-i][j] = 0\n a[2*n-i][2*n-j]= 0\n end\n else\n if i + j == n + m && i >= m && j >= m\n \n a[i][j] = m\n a[i][2*n-j] = m\n a[2*n-i][j] = m\n a[2*n-i][2*n-j]= m\n \n end\n end\n\n end\n end\nend\n\na[n][n] = n\nfor i in 0...line\n if i <= n\n for j in 0...n+i+1\n if j != 0\n print \" \"\n end\n print a[i][j]\n end\n else \n for j in 0...3*n+1-i\n if j!= 0\n print \" \"\n end\n print a[i][j]\n end\n end\n\n puts \nend\n"}, {"source_code": "n = gets.chomp.to_i\nspace = n*2\nfor i in (1..n)\n\tfor x in (i..space)\n\t\tprint \" \"\n\tend\n\tline = (n*2) + 1 - (((n + 1 - i) * 2)).abs\n\tcount = 0\n\tfor x in (1..line)\n\t\tif x < line\n\t\t\tprint count \n\t\t\tprint \" \"\n\t\t\tif x <= line/2 \n\t\t\t\tcount += 1\n\t\t\telse\n\t\t\t\tcount -= 1\n\t\t\tend\n\t\telse\n\t\t\tputs count\n\t\tend\n\tend\n\tspace -= 1\nend\ncount = 0\nfor i in (1..(n*2) + 1)\n\tif i < (n*2) + 1\n\t\tprint count \n\t\tprint \" \"\n\t\tif i <= ((n*2)+1)/2\n\t\t\tcount += 1\n\t\telse\n\t\t\tcount -= 1\n\t\tend\n\telse\n\t\tputs count\n\tend\nend\ni = n\nspace = n+1\nwhile i >= 1\n\t\tfor x in (i..space)\n\t\t\tprint \" \"\n\t\tend\n\tline = (n*2) + 1 - (((n + 1 - i) * 2)).abs\n\tcount = 0\n\tfor x in (1..line)\n\t\tif x < line\n\t\t\tprint count \n\t\t\tprint \" \"\n\t\t\tif x <= line/2 \n\t\t\t\tcount += 1\n\t\t\telse\n\t\t\t\tcount -= 1\n\t\t\tend\n\t\telse\n\t\t\tputs count\n\t\tend\n\tend\n\ti -= 1\n\tspace += 1\nend"}, {"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}\n"}, {"source_code": "l = []\nn = gets.to_i\n(0..n).reverse_each do |x|\n\tl <<= \" \" * x * 2 + (x == n ? \"0\" : ((0..(n - x)).to_a + (0...(n - x)).to_a.reverse).join(\" \"))\nend\n\nputs (l + l.reverse[1..-1]).join(\"\\n\")"}, {"source_code": "n = STDIN.gets.chomp.to_i\n\ndef line(from, to)\n left = \"\"\n for i in from...to\n left += (if i >= 0 then i.to_s else \" \"; end) + \" \"\n end\n result = (left + to.to_s + left.reverse).rstrip\nend\n\ntop_lines = []\nfor i in 0...n\n top_lines << line(i - n, i)\nend\ntop_lines.each { |line| puts line }\nputs line(0, n)\ntop_lines.reverse.each { |line| puts line }"}, {"source_code": "class Euler\n a=gets.to_i;\n b=2*a+1;\n pr=2*a;\n allpr=2*b-1;\n (1..pr).each do\n print(\" \");\n end\n puts(\"0\");\n (2..b-1).each do |i|\n if (i<=a+1) \n c=2*i-1;\n else\n c=b-2*(i-a-1)\n end\n s=2*(a-(c/2));\n (1..s).each do\n print(\" \");\n end\n l=c/2+1;\n (1..l).each do |j|\n print(j-1);\n print(\" \");\n end\n (1..l-2).each do |j|\n k=(c-1)/2;\n print(k-j);\n print(\" \");\n end\n if (l>1)\n print(\"0\");\n end\n print(\"\\n\");\n end\n (1..pr).each do\n print(\" \");\n end\n puts(\"0\");\n end\n"}, {"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}\n"}, {"source_code": "n = gets.to_i\nx = 0\nwhile (x <= n)\n c = n - x\n i = 0\n s = ''\n while (i < c) \n s += ' ' \n i+=1 \n end\n i = 0\n fst = true\n while (i <= x)\n if (!fst) then s += ' ' end\n fst = false\n s += i.to_s\n i+=1\n end\n i = x-1\n while (i >= 0)\n s += ' ' + i.to_s\n i-=1\n end\n puts s\n x+=1\nend\nx = n-1\nwhile (x >= 0)\n c = n - x\n i = 0\n s = ''\n while (i < c) \n s += ' ' \n i+=1 \n end\n i = 0\n fst = true\n while (i <= x)\n if (!fst) then s += ' ' end\n fst = false\n s += i.to_s\n i+=1\n end\n i = x-1\n while (i >= 0)\n s += ' ' + i.to_s\n i-=1\n end\n puts s\n x-=1\nend"}, {"source_code": "def present\n n = gets.to_i + 1\n\n #print \" \"\n\n n.times do |i|\n line = \"\"\n line += \" \" * (n - i - 1)\n 0.upto(i) do |j|\n line += \"#{j} \"\n end\n\n (i - 1).downto(0) do |l|\n line += \"#{l} \"\n end\n line[line.size - 1] = \"\\n\"\n print line\n end\n\n (n - 2).downto(0) do |i|\n line = \"\"\n line += \" \" * (n - i - 1)\n 0.upto(i) do |j|\n line += \"#{j} \"\n end\n\n (i - 1).downto(0) do |l|\n line += \"#{l} \"\n end\n line[line.size - 1] = \"\\n\"\n print line\n end\nend\n\npresent"}, {"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}\n"}, {"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}"}, {"source_code": "#!/usr/bin/ruby -Ks\n\nINPUT_NUMBER = $stdin.gets.chomp.to_i\n\noutput = Array.new\n\n0.upto(INPUT_NUMBER) do |i|\n output[i] = \"\"\n (INPUT_NUMBER - i).times do |j|\n output[i] += \" \" + \" \"\n end\n 0.upto(i) do |j|\n output[i] += j.to_s + \" \"\n end\nend\n\noutput.each_with_index do |str, idx|\n output_string = str + str.reverse.slice(3, (str.size - 3)).rstrip\n puts output_string.rstrip\nend\n\noutput.reverse.each_with_index do |str, idx|\n next if idx == 0\n output_string = str + str.reverse.slice(3, (str.size - 3))\n puts output_string.rstrip\nend\n\n# EOF\n"}, {"source_code": "input = gets.to_i\n\ntop = \"\"\n\n(0..input).each do |x|\n\n top += \" \" * (input - x)\n\n l = (0..x).to_a\n r = l.reverse\n r.shift\n\n top += (l + r).join \" \"\n top += \"\\n\"\n\nend\n\nbot = top.split(\"\\n\")\nbot.pop\n\nprint top + bot.reverse.join(\"\\n\")\n"}, {"source_code": "n=gets.hex\nputs [*0..n,*(n-1).downto(0)].map{|k|\" \"*(2*(n-k))+([*0..k,*(k-1).downto(0)]*\" \")}\n"}, {"source_code": "n = gets.to_i\nstr = \" \" * 2 * n + \"0\"\n(1..n).each do |x|\n puts str\n str[2*n+1,0]=\" #{x} #{x-1}\"\n str[0,2]=\"\"\nend\n(1..n).each do |x|\n puts str\n str[2*n-2,4]=\"\"\n str[0,0]=\" \"\nend\nputs str"}, {"source_code": "n = STDIN.gets.chomp.to_i\nlines = ((n + 1) * 2) - 1\nelem = Array.new() \nelem.push 1\n1.upto(lines - 1) do |i|\n if i <= n \n elem[i] = elem[i - 1] + 2\n else\n elem[i] = elem[i - 1] - 2\n end\nend\nspace = n\nelem.each do |i|\n line = \"\"\n (elem[space] - 1).times {|i| line += \" \"}\n space -= 1 \n space -= 1 if space == -1\n num = 0\n i.times do |j| \n line += (num.to_s + \" \"); \n if j < i / 2\n num += 1\n else\n num -= 1\n end\n end\n puts line.rstrip\nend"}, {"source_code": "n = STDIN.gets.chomp.to_i\nlines = ((n + 1) * 2) - 1\n#elem = Array.new() \n#elem.push 1\n\nelem = 1.upto(lines - 1).inject([1]) {|res, i| res[i] = res[i - 1] + (i <= n ? 2 : -2); res}\n# 1.upto(lines - 1) do |i|\n # if i <= n \n # elem[i] = elem[i - 1] + 2\n # else\n # elem[i] = elem[i - 1] - 2\n # end\n# end\nspace = n\nelem.each do |i|\n line = \" \" * (elem[space] - 1)\n # (elem[space] - 1).times {|i| line += \" \"}\n space -= 1 \n space -= 1 if space == -1\n num = 0\n i.times do |j| \n line += (num.to_s + \" \"); \n if j < i / 2\n num += 1\n else\n num -= 1\n end\n end\n puts line.rstrip\nend"}, {"source_code": "n = STDIN.gets.chomp.to_i\nlines = ((n + 1) * 2) - 1\n\nelem = 1.upto(lines - 1).inject([1]) {|res, i| res[i] = res[i - 1] + (i <= n ? 2 : -2); res}\nspace = n\nelem.each do |i|\n line = \" \" * (elem[space] - 1)\n space -= (space == 0) ? 2 : 1\n num = 0\n i.times do |j| \n line += (num.to_s + \" \");\n num += (j < i/2) ? 1: -1\n end\n puts line.rstrip\nend"}, {"source_code": "n = STDIN.gets.chomp.to_i\nlines = ((n + 1) * 2) - 1\n#elem = Array.new() \n#elem.push 1\n\nelem = 1.upto(lines - 1).inject([1]) {|res, i| res[i] = i <= n ? res[i - 1] + 2 : res[i - 1] - 2; res}\n# 1.upto(lines - 1) do |i|\n # if i <= n \n # elem[i] = elem[i - 1] + 2\n # else\n # elem[i] = elem[i - 1] - 2\n # end\n# end\nspace = n\nelem.each do |i|\n line = \" \" * (elem[space] - 1)\n # (elem[space] - 1).times {|i| line += \" \"}\n space -= 1 \n space -= 1 if space == -1\n num = 0\n i.times do |j| \n line += (num.to_s + \" \"); \n if j < i / 2\n num += 1\n else\n num -= 1\n end\n end\n puts line.rstrip\nend\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nlines = ((n + 1) * 2) - 1\nelem = 1.upto(lines - 1).inject([1]) {|res, i| res[i] = res[i - 1] + (i <= n ? 2 : -2); res}\nspace = n\nelem.each do |i|\n line = \" \" * (elem[space] - 1)\n space -= (space == 0) ? 2 : 1\n num = 0\n i.times do |j| \n line += (num.to_s + \" \");\n num += (j < i / 2) ? 1: -1\n end\n puts line.rstrip\nend"}, {"source_code": "n = STDIN.gets.chomp.to_i\nlines = ((n + 1) * 2) - 1\nelem = Array.new() \nelem.push 1\n1.upto(lines - 1) do |i|\n if i <= n \n elem[i] = elem[i - 1] + 2\n else\n elem[i] = elem[i - 1] - 2\n end\nend\nspace = n\nelem.each do |i|\n line = \" \" * (elem[space] - 1)\n # (elem[space] - 1).times {|i| line += \" \"}\n space -= 1 \n space -= 1 if space == -1\n num = 0\n i.times do |j| \n line += (num.to_s + \" \"); \n if j < i / 2\n num += 1\n else\n num -= 1\n end\n end\n puts line.rstrip\nend"}, {"source_code": "n = gets.chomp.to_i\n\nfor i in 0..2*n\n spn = 0\n pn = 2*n+1\n if i < n then\n spn = 2*(n - i)\n pn = 2*i+1\n elsif i > n then\n spn = 2*(i - n )\n pn = 2*(2*n-i) + 1\n end\n for j in 0..spn-1\n print \" \"\n end\n nn = 0\n for j in 0..pn-1\n print \" \" if j > 0\n print nn\n if j >= (pn-1).div(2)\n nn -= 1\n else\n nn += 1\n end\n end\n puts \"\"\nend\n\n"}, {"source_code": "n=gets.to_i\nputs (0..n+n).map{|i|((0..n+n).map{|j|x=n-(i-n).abs-(j-n).abs;x<0? \" \":x}*\" \").rstrip}"}, {"source_code": "n = STDIN.readline.to_i\n\na = n + 1\nresult = []\n(0..n).each do |i|\n line = []\n (-(n)..i).each do |j| \n if i - j.abs < 0\n line << ' ' \n else \n line << (i - j.abs)\n end\n end\n result << line.join(' ')\nend\nresult << result[0..-2].reverse\nputs result"}, {"source_code": "\nn=gets.to_i\nk=1\nq=n\nfor i in 0..n\n (q).times{\n print \" \"\n }\n for j in 0..(k/2)\n if j>0 then\n print \" \"\n end\n print j\n end\n (k/2-1).downto(0){|j|\n print \" \"+j.to_s\n }\n puts\n k+=2\n q-=1\nend\nq+=2\nk-=4\nn.downto(1){|i|\n (q).times{\n print \" \"\n }\n for j in 0..(k/2)\n if j>0 then\n print \" \"\n end\n print j\n end\n (k/2-1).downto(0){|j|\n print \" \"+j.to_s\n }\n puts\n k-=2\n q+=1\n}\n\n"}], "negative_code": [{"source_code": "def present\n n = gets.to_i\n\n #print \" \"\n\n n.times do |i|\n line = \"\"\n line += \" \" * (n - i - 1)\n 0.upto(i) do |j|\n line += \"#{j} \"\n end\n\n (i - 1).downto(0) do |l|\n line += \"#{l} \"\n end\n line[line.size - 1] = \"\\n\"\n print line\n end\n\n (n - 2).downto(0) do |i|\n line = \"\"\n line += \" \" * (n - i - 1)\n 0.upto(i) do |j|\n line += \"#{j} \"\n end\n\n (i - 1).downto(0) do |l|\n line += \"#{l} \"\n end\n line[line.size - 1] = \"\\n\"\n print line\n end\nend\n\npresent"}, {"source_code": "#!/usr/bin/ruby -Ks\n\nINPUT_NUMBER = $stdin.gets.chomp.to_i\n\noutput = Array.new\n\n0.upto(INPUT_NUMBER) do |i|\n output[i] = \"\"\n (INPUT_NUMBER - i).times do |j|\n output[i] += \" \" + \" \"\n end\n 0.upto(i) do |j|\n output[i] += j.to_s + \" \"\n end\nend\n\noutput.each do |str|\n print str\n puts str.reverse.slice(3, (str.size - 3)).rstrip\nend\n\noutput.reverse.each_with_index do |str, idx|\n next if idx == 0\n print str\n puts str.reverse.slice(3, (str.size - 3)).rstrip\nend\n\n# EOF\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nlines = ((n + 1) * 2) - 1\nelem = Array.new() \nelem.push 1\n1.upto(lines - 1) do |i|\n if i <= n \n elem[i] = elem[i - 1] + 2\n else\n elem[i] = elem[i - 1] - 2\n end\nend\nspace = n\nelem.each do |i|\n print \" \"\n elem[space].times {|i| print \" \"}\n space -= 1 \n space -= 1 if space == -1\n num = 0\n i.times do |j| \n print num, \" \"; \n if j < i / 2\n num += 1\n else\n num -= 1\n end\n end\n puts\nend"}, {"source_code": "n = STDIN.gets.chomp.to_i\nlines = ((n + 1) * 2) - 1\nelem = Array.new() \nelem.push 1\n1.upto(lines - 1) do |i|\n if i <= n \n elem[i] = elem[i - 1] + 2\n else\n elem[i] = elem[i - 1] - 2\n end\nend\nspace = n\nelem.each do |i|\n line = \"\"\n (elem[space]).times {|i| line += \" \"}\n space -= 1 \n space -= 1 if space == -1\n num = 0\n i.times do |j| \n line += (num.to_s + \" \"); \n if j < i / 2\n num += 1\n else\n num -= 1\n end\n end\n puts line.chomp\nend"}, {"source_code": "n = STDIN.gets.chomp.to_i\nlines = ((n + 1) * 2) - 1\nelem = Array.new() \nelem.push 1\n1.upto(lines - 1) do |i|\n if i <= n \n elem[i] = elem[i - 1] + 2\n else\n elem[i] = elem[i - 1] - 2\n end\nend\nspace = n\nelem.each do |i|\n line = \"\"\n (elem[space]).times {|i| line += \" \"}\n space -= 1 \n space -= 1 if space == -1\n num = 0\n i.times do |j| \n line += (num.to_s + \" \"); \n if j < i / 2\n num += 1\n else\n num -= 1\n end\n end\n puts line.rstrip\nend"}, {"source_code": "n = STDIN.gets.chomp.to_i\nlines = ((n + 1) * 2) - 1\nelem = Array.new() \nelem.push 1\n1.upto(lines - 1) do |i|\n if i <= n \n elem[i] = elem[i - 1] + 2\n else\n elem[i] = elem[i - 1] - 2\n end\nend\nspace = n\nelem.each do |i|\n print \" \"\n (elem[space] - 1).times {|i| print \" \"}\n space -= 1 \n space -= 1 if space == -1\n num = 0\n i.times do |j| \n print \" \", num; \n if j < i / 2\n num += 1\n else\n num -= 1\n end\n end\n puts\nend"}, {"source_code": "n = STDIN.gets.chomp.to_i\nlines = ((n + 1) * 2) - 1\nelem = Array.new() \nelem.push 1\n1.upto(lines - 1) do |i|\n if i <= n \n elem[i] = elem[i - 1] + 2\n else\n elem[i] = elem[i - 1] - 2\n end\nend\nspace = n\nelem.each do |i|\n elem[space].times {|i| print \" \"}\n space -= 1 \n space -= 1 if space == -1\n num = 0\n i.times do |j| \n print num, \" \"; \n if j < i / 2\n num += 1\n else\n num -= 1\n end\n end\n puts\nend"}, {"source_code": "n=gets.to_i\nputs (0..n+n).map{|i|(0..n+n).map{|j|x=n-(i-n).abs-(j-n).abs;x<0?\" \":x}*\" \"}"}, {"source_code": "n = STDIN.readline.to_i\n\na = n + 1\nresult = []\n(0..n).each do |i|\n\tline = []\n\t(-(n)..(n)).each do |j|\t\t\n\t\tif i - j.abs < 0\n\t\t\tline << ' ' \n\t\telse \n\t\t\tline << (i - j.abs)\n\t\tend\n\tend\n\tresult << line.join(' ')\nend\nresult << result[0..-2].reverse\nputs result"}, {"source_code": "\nn=gets.to_i\nk=1\nq=n\nfor i in 0..n\n q.times{\n print \" \"\n }\n for j in 0..(k/2)\n if j then\n print \" \"\n end\n print j\n end\n (k/2-1).downto(0){|j|\n print \" \"+j.to_s\n }\n puts\n k+=2\n q-=1\nend\nq+=2\nk-=4\nn.downto(1){|i|\n q.times{\n print \" \"\n }\n for j in 0..(k/2)\n if j then\n print \" \"\n end\n print j\n end\n (k/2-1).downto(0){|j|\n print \" \"+j.to_s\n }\n puts\n k-=2\n q+=1\n}\n"}, {"source_code": "n = gets.to_i\n(0..n).each { |i| puts \" \"*(2*(n-i)) + (0..i).to_a*\" \" + \" \" + (0...i).to_a.reverse*\" \" }\n(0..n-1).to_a.reverse.each { |i| puts \" \"*(2*(n-i)) + (0..i).to_a*\" \" + \" \" + (0...i).to_a.reverse*\" \" }"}, {"source_code": "x = gets.chomp.to_i\n\narr = []\n\n0.upto(x) do |ind|\n arr << \"\"\n arr.last << 0.upto(ind).to_a.join(' ')\n line_end = (ind-1).downto(0).to_a.join(' ')\n arr.last << ' ' + line_end if line_end.size > 0\nend\n\nputs largest_len = arr.last.length\n\narr.each do |s|\n puts \" \"*((largest_len-s.length)/2) + s\nend\n\narr.reverse.drop(1).each do |s|\n puts \" \"*((largest_len-s.length)/2) + s\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\ndef readNextValues\n arr = gets.chomp.split\n return arr.collect {|x| x.to_i }\nend\n\n#######################\n\ndef nums(toNum)\n 0.upto(toNum) do |i|\n print \"#{i} \"\n end\n (toNum-1).downto(0) do |i|\n print \"#{i}\"\n if i != 0\n print ' '\n end\n end\nend\n\nn = gets.to_i\n\n0.upto(n) do |i|\n print ' ' * (n-i)\n nums(i)\n puts\nend\n(n-1).downto(0) do |i|\n print ' ' * (n-i)\n nums(i)\n puts\nend\n"}, {"source_code": "#!/usr/bin/env ruby\ndef a2s( a )\n b = []\n a.each do |i|\n if i < 0\n b << \" \"\n else\n b << i.to_s\n end\n end\n return b.join( \" \" )\nend\n\nn = gets.to_i\na = []\n0.upto(n){ |i| a << i }\n(n-1).downto(0){ |i| a << i }\na.map!{ |i| i-n }\nn.times do |i|\n puts a2s(a)\n a.map!{ |i| i+1 }\nend\nn.times do |i|\n puts a2s(a)\n a.map!{ |i| i-1 }\nend\nputs a2s(a)\n"}, {"source_code": "n = gets.to_i + 1\n\nn.times do |i|\n (n-i-1).times do \n print \" \"\n end\n\n (i+1).times do |ii|\n print ii\n print \" \"\n end\n (i-1).downto(0) do |ii|\n print ii\n print \" \"\n end\n \n print \"\\n\"\nend\n \n(n-2).downto(0) do |i|\n (n-i-1).times do \n print \" \"\n end\n\n (i+1).times do |ii|\n print ii\n print \" \"\n end\n (i-1).downto(0) do |ii|\n print ii\n print \" \"\n end\n \n print \"\\n\"\nend\n \n"}, {"source_code": "n=gets.to_i;s='0123456789'.split //;b=[];(n+1).times{|k|b<<((s[0...k]+[k]+s[0...k].reverse)*' ').center(4*n+1)};puts b+b[0..-2].reverse\n"}, {"source_code": "n=gets.to_i\nb=[]\n\n(n+1).times{|k|\t\t\n\ta=[]\n\t(k+1).times{|i| a+=[i]}\n\t(k-1).downto(0){|i| a+=[i]}\n\t\n\tb << a.join(' ').center(2*n+2*n+1)\n}\nb+=b[0..-2].reverse\nputs b\n"}, {"source_code": "@n = gets.to_i\n@w = @n*4+1\n\ndef gen(k)\n s = ' '\n (0..k).each do |i|\n s += i.to_s + ' '\n end\n (0...k).reverse_each do |i|\n s += i.to_s + ' '\n end\n puts s.strip.center(@w)\nend\n\n(0..@n).each do |i|\n gen(i)\nend\n(0...@n).reverse_each do |i|\n gen(i)\nend"}, {"source_code": "# To change this template, choose Tools | Templates\n# and open the template in the editor.\n\nn = gets.chop.to_i\n\nsize = 2*n + 1\n\nfor i in -n..n\n line = \"\"\n for j in -n..n\n val = (n - (i.abs + j.abs))\n if (val >= 0)\n line += \"#{val} \"\n else\n line += \" \"\n end\n\n end\n puts line.chop\nend"}, {"source_code": "input = $stdin.readline.chop.to_i\nn = input\ni = 0\nwhile n>=0\n (n*2).times do \n print \" \"\n end\n\n for j in 0..(i-1)\n print \"#{j} \"\n end\n\n print \"#{i} \"\n\n j = i - 1\n while j>=0\n print j\n print \" \" if j!=0\n j-=1\n end\n\n print \"\\n\"\n n-=1\n i+=1\nend\n\nn = 1\ni = input-1\nwhile n<=input\n (n*2).times do \n print \" \"\n end\n\n for j in 0..(i-1)\n print \"#{j} \"\n end\n\n print \"#{i} \"\n\n j = i - 1\n while j>=0\n print j\n print \" \" if j!=0\n j-=1\n end\n\n print \"\\n\"\n n+=1\n i-=1\nend\n"}, {"source_code": "n = Integer(gets)\nline = 2 * n + 1\na = Array.new\nfor i in 0...line\n a[i] = Array.new\nend\n\nfor i in 0...line\n if i <= n\n for j in 0...n+i+1\n a[i][j] = \" \"\n end\n else \n for j in 0...3*n+1-i\n a[i][j] = \" \"\n end\n end\nend\n\nfor m in 0...n\n \n for i in 0...line\n for j in 0...line\n if m == 0\n if i + j == n\n a[i][j] = 0\n a[i][2*n-j] = 0\n a[2*n-i][j] = 0\n a[2*n-i][2*n-j]= 0\n end\n else\n if i + j == n + m && i >= m && j >= m\n \n a[i][j] = m\n a[i][2*n-j] = m\n a[2*n-i][j] = m\n a[2*n-i][2*n-j]= m\n \n end\n end\n\n end\n end\nend\n\na[n][n] = n\nfor i in 0...line\n for j in 0...line\n print a[i][j]\n if j != i + 3\n print \" \"\n end\n\n end\n puts \nend\n"}, {"source_code": "n = Integer(gets)\nline = 2 * n + 1\na = Array.new\nfor i in 0...line\n\ta[i] = Array.new\nend\n\nfor i in 0...line\n\tif i <= n\n\t\tfor j in 0...n+i+1\n\t\t\ta[i][j] = \" \"\n\t\tend\n\telse \n\t\tfor j in 0...3*n+1-i\n\t\t\ta[i][j] = \" \"\n\t\tend\n\tend\nend\n\nfor m in 0...n\n \n\tfor i in 0...line\n\t\tfor j in 0...line\n\t\t\tif m == 0\n\t\t\t\tif i + j == n\n\t\t\t\t\ta[i][j] = 0\n\t\t\t\t\ta[i][2*n-j] = 0\n\t\t\t\t\ta[2*n-i][j] = 0\n\t\t\t\t\ta[2*n-i][2*n-j]= 0\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tif i + j == n + m && i >= m && j >= m\n\t\t\t\t\t\n\t\t\t\t\t\t\ta[i][j] = m\n\t\t\t\t\t\t\ta[i][2*n-j] = m\n\t\t\t\t\t\t\ta[2*n-i][j] = m\n\t\t\t\t\t\t\ta[2*n-i][2*n-j]= m\n\t\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\n\t\tend\n\tend\nend\n\na[n][n] = n\nfor i in 0...line\n\tfor j in 0...line\n\t print a[i][j]\n\tend\n\tputs \nend\n"}, {"source_code": "n = Integer(gets)\nline = 2 * n + 1\na = Array.new\nfor i in 0...line\n a[i] = Array.new\nend\n\nfor i in 0...line\n if i <= n\n for j in 0...n+i+1\n a[i][j] = \" \"\n end\n else \n for j in 0...3*n+1-i\n a[i][j] = \" \"\n end\n end\nend\n\nfor m in 0...n\n \n for i in 0...line\n for j in 0...line\n if m == 0\n if i + j == n\n a[i][j] = 0\n a[i][2*n-j] = 0\n a[2*n-i][j] = 0\n a[2*n-i][2*n-j]= 0\n end\n else\n if i + j == n + m && i >= m && j >= m\n \n a[i][j] = m\n a[i][2*n-j] = m\n a[2*n-i][j] = m\n a[2*n-i][2*n-j]= m\n \n end\n end\n\n end\n end\nend\n\n\na[n][n] = n\nfor i in 0...line\n for j in 0...line\n print a[i][j]\n if j != i + 3\n print \" \"\n end\n\n end\n puts \nend\n"}, {"source_code": "n = gets.chomp.to_i\nspace = n*2\nfor i in (1..n)\n\tfor x in (i..space)\n\t\tprint \" \"\n\tend\n\tline = (n*2) + 1 - (((n + 1 - i) * 2)).abs\n\tcount = 0\n\tfor x in (1..line)\n\t\tprint count \n\t\tprint \" \"\n\t\tif x <= line/2 \n\t\t\tcount += 1\n\t\telse\n\t\t\tcount -= 1\n\t\tend\n\tend\n\tputs \" \"\n\tspace -= 1\nend\ncount = 0\nfor i in (1..(n*2) + 1)\n\tif i < (n*2) + 1\n\t\tprint count \n\t\tprint \" \"\n\t\tif i <= ((n*2)+1)/2\n\t\t\tcount += 1\n\t\telse\n\t\t\tcount -= 1\n\t\tend\n\telse\n\t\tputs count\n\tend\nend\ni = n\nspace = n+1\nwhile i >= 1\n\t\tfor x in (i..space)\n\t\t\tprint \" \"\n\t\tend\n\tline = (n*2) + 1 - (((n + 1 - i) * 2)).abs\n\tcount = 0\n\tfor x in (1..line)\n\t\tprint count \n\t\tprint \" \"\n\t\tif x <= line/2 \n\t\t\tcount += 1\n\t\telse\n\t\t\tcount -= 1\n\t\tend\n\tend\n\tputs \" \"\n\ti -= 1\n\tspace += 1\nend"}, {"source_code": "n = gets.chomp.to_i\n\nfor i in (1..n)\n\tfor x in (i..n)\n\t\tprint \" \"\n\tend\n\tline = (n*2) + 1 - (((n + 1 - i) * 2)).abs\n\tcount = 0\n\tfor x in (1..line)\n\t\tprint count\n\t\tif x <= line/2 \n\t\t\tcount += 1\n\t\telse\n\t\t\tcount -= 1\n\t\tend\n\tend\n\tfor x in (i..n-1)\n\t\tprint \" \"\n\tend\n\tputs \" \"\nend\ncount = 0\nfor i in (1..(n*2) + 1)\n\tif i < (n*2) + 1\n\t\tprint count\n\t\tif i <= ((n*2)+1)/2\n\t\t\tcount += 1\n\t\telse\n\t\t\tcount -= 1\n\t\tend\n\telse\n\t\tputs count\n\tend\nend\ni = n\nwhile i >= 1\n\tfor x in (i..n)\n\t\tprint \" \"\n\tend\n\tline = (n*2) + 1 - (((n + 1 - i) * 2)).abs\n\tcount = 0\n\tfor x in (1..line)\n\t\tprint count\n\t\tif x <= line/2 \n\t\t\tcount += 1\n\t\telse\n\t\t\tcount -= 1\n\t\tend\n\tend\n\tfor x in (i..n-1)\n\t\tprint \" \"\n\tend\n\tputs \" \"\n\ti -= 1\nend"}, {"source_code": "n = STDIN.gets.chomp.to_i\n\ndef line(from, to)\n left = \"\"\n for i in from...to\n left += (if i >= 0 then i.to_s else \" \"; end) + \" \"\n end\n result = left + to.to_s + left.reverse\nend\n\ntop_lines = []\nfor i in 0...n\n top_lines << line(i - n, i)\nend\ntop_lines.each { |line| puts line }\nputs line(0, n)\ntop_lines.reverse.each { |line| puts line }"}, {"source_code": "class Euler\n a=gets.to_i;\n b=2*a+1;\n pr=2*a;\n allpr=2*b-1;\n \n (1..b).each do |i|\n if (i<=a+1) \n c=2*i-1;\n else\n c=b-2*(i-a-1)\n end\n s=2*(a-(c/2));\n (1..s).each do\n print(\" \");\n end\n l=c/2+1;\n (1..l).each do |j|\n print(j-1);\n print(\" \");\n end\n (1..l-2).each do |j|\n k=(c-1)/2;\n print(k-j);\n print(\" \");\n end\n if (l>1)\n print(\"0\");\n end\n print(\"\\n\");\n end\n end\n"}], "src_uid": "7896740b6f35010af751d3261b5ef718"} {"source_code": "gets.to_i.times do\n n = gets.to_i\n s = []\n n.times do\n s << gets.chomp!\n end\n cnt = [0] * 26\n s.each do |i|\n i.each_char do |c|\n cnt[c.ord - 'a'.ord] += 1\n end\n end\n ok = true\n cnt.each do |i|\n ok &= i % n == 0\n end\n puts ok ? \"YES\" : \"NO\"\nend", "positive_code": [{"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n hash = Hash.new(0)\n n.times do\n s = gets.chomp.split(\"\")\n s.each do |x|\n hash[x] += 1\n end\n end\n str = \"YES\"\n hash.each_value do |v|\n if v % n != 0\n str = \"NO\"\n end\n end\n ans << str\nend\nans.each do |x|\n puts x\nend"}, {"source_code": "gets.to_i.times do\n l = gets.to_i\n h = Hash.new(0)\n l.times do\n gets.split('').each { |i| h[i] += 1 }\n end\n r = h.values.all? { |i| i % l == 0 } ? 'YES' : 'NO'\n puts r\nend\n"}], "negative_code": [], "src_uid": "3d6cd0a82513bc2119c9af3d1243846f"} {"source_code": "n = gets.to_i\nd = gets.split.map{|i| i.to_i}\na,b = gets.split.map{|i| i.to_i}\ni = a\nres = 0\nwhile i < b do\n res += d[i-1]\n i += 1\nend\n\np res", "positive_code": [{"source_code": "n = gets.to_i\nar = gets.split(' ',n-1).map(&:to_i).insert(0,0)\na, b = gets.split(' ').map(&:to_i)\nputs ar[a...b].inject(:+)"}, {"source_code": "n = gets.chomp.to_i\nar = gets.chomp.split(/ /).map!{|x| x.to_i}\na,b = gets.chomp.split(/ /).map!{|x| x.to_i}\nsum = 0\nfor i in a-1..b-2\n\tsum += ar[i]\nend\nputs sum"}, {"source_code": "_=gets(p).split.map(&:to_i)\np eval _[_[-2]..._[-1]]*?+"}, {"source_code": "n = gets.to_i\nd = gets.split.map(&:to_i)\ni = gets.split.map(&:to_i)\nsum = 0\nd[i[0]-1..i[1]-2].each{|e| sum+= e}\nprint sum\n"}, {"source_code": "a=gets(p).split.map &:to_i;p eval a[a[-2]...a[-1]]*?+\n"}, {"source_code": "a=gets(p).split.map &:to_i;p eval a[a[-2]...a[-1]]*?+\n"}, {"source_code": "n,d,(a,b)=(1..3).map{gets.split.map &:to_i};p d[a-1,b-a].inject:+"}, {"source_code": "n = gets.to_i\ntry = gets.split().map(&:to_i)\na,b = gets.split().map(&:to_i)\nt = 0\n\nfor i in a...b\n\tt += try[i-1]\nend\n\nputs t"}, {"source_code": "a=gets(p).split.map &:to_i;p eval a[a[-2]...a[-1]]*?+"}, {"source_code": "n=gets.chomp.to_i\nj=gets.chomp.split(' ').map(&:to_i)\nsum=0\na,b=gets.chomp.split(' ').map(&:to_i)\ni=a-1\nwhile i<(b-1)\n\tsum+=j[i]\n\ti+=1\nend\nputs sum"}, {"source_code": "gets\nd = gets.split.map(&:to_i)\na, b = gets.split.map { |x| x.to_i - 1}\nputs (a...b).map {|i| d[i]}.inject(:+)"}, {"source_code": "a=gets(p).split.map &:to_i;p eval a[a[-2]...a[-1]]*?+\n"}, {"source_code": "t = gets.chomp.to_i\narr = gets.split.map(&:to_i)\na,b = gets.split.map(&:to_i)\nres = 0\nwhile a=maxarr[-1][0]\n if maxarr.length == k\n maxarr.pop\n end\n maxarr.push([x,i])\n maxarr.sort_by!{|z| z[0]}.reverse!\n end\nend\n\n#p maxarr\n\nprintarr=[]\nmaxarr.sort_by!{|z| z[1]}\n\nsum = 0\nprev = 0\nmaxarr.each do |x|\n sum += x[0]\n printarr.push(x[1]-prev+1)\n prev = x[1]+1\nend\n\n#p printarr\nputs sum\nif k>1\n printarr.pop\n printarr.push(n-printarr.inject(:+))\nelse\n printarr = [n]\nend\nprintarr.each{|x| print \"#{x} \"}\nputs", "positive_code": [{"source_code": "\ndef solution\n _, k = read_ints\n as = read_ints\n\n diffs = Hash.new{|h, k| h[k] = 0 }\n best = as.sort.last(k)\n best.group_by{|x|x}.each{|d,arr| diffs[d] = arr.size}\n\n total = best.reduce(0, :+)\n streaks = []\n crt = 0\n as.each do |a|\n crt += 1\n if diffs[a] > 0\n streaks << crt\n crt = 0\n diffs[a] -= 1\n end\n end\n\n streaks[-1] = streaks.last + crt\n\n puts total\n puts streaks.join(' ')\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}, {"source_code": "N, K = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i)\nsolved = N.times.sort_by{|i| -as[i]}[0, K].sort\nputs solved.map{|i| as[i]}.inject(:+)\nans = []\nK.times do |i|\n ans[i] = (i == K-1 ? N-1 : solved[i]) - (i == 0 ? -1 : solved[i-1])\nend\nputs ans.join(' ')"}], "negative_code": [{"source_code": "nk = gets.chomp.split(\" \").map(&:to_i)\narr = gets.chomp.split(\" \").map(&:to_i)\nn = nk[0]\nk = nk[1]\nmaxarr = [[0,-1]]\nkmin = 0\n\narr.each_with_index do |x,i|\n if x>=maxarr[-1][0]\n if maxarr.length == k\n maxarr.pop\n end\n maxarr.push([x,i])\n maxarr.sort_by!{|z| z[0]}.reverse!\n end\nend\n\n#p maxarr\n\nprintarr=[]\nmaxarr.sort_by!{|z| z[1]}\n\nsum = 0\nprev = 0\nmaxarr.each do |x|\n sum += x[0]\n printarr.push(x[1]-prev+1)\n prev = x[1]+1\nend\n\nputs sum\nif k>1\n printarr.pop\n printarr.push(n-printarr.inject(:+))\nend\nprintarr.each{|x| print \"#{x} \"}\nputs"}], "src_uid": "9cc61be7dc9b79f46a3e796db0134173"} {"source_code": "h={}\nh2={}\nhm=hm2=0\nARGF.each do |line|\n f=line.split('\\\\')\n\n for i in 1...f.size do\n if(h[ f[0..i] ]!=nil) then h[ f[0..i] ]+=1\n else h[ f[0..i] ]=1\n end\n \n end\n for i in 1...f.size-1 do \n if(h2[ f[0..i] ]==nil) then \n h2[ f[0..i] ]=0\n for j in 1...i do h2[ f[0..j] ]+=1 end\n end\n\n end\nend\nh.each_value{|i| hm = ((i>hm)?i:hm)}\nh2.each_value{|i| hm2 = ((i>hm2)?i:hm2)}\nputs \"#{hm2} #{hm}\"", "positive_code": [{"source_code": "require 'set'\n\nclass Disk\n include Comparable\n attr_accessor :name, :folders\n def initialize(name)\n @name = name\n @folders = Hash.new\n end\n def <=> (other)\n self.name <=> other.name\n end\nend\n\nclass Folder\n include Comparable\n attr_accessor :name, :folders, :file_num, :total_file_num, :total_folder_num\n def initialize(name)\n @name = name\n @folders = Hash.new\n @file_num = 0 #direct decendant\n @total_file_num = 0\n @total_folder_num = 0\n end\n def <=> (other)\n self.name <=> other.name\n end\n def stat()\n @folders.each do |folder_name, folder|\n (fd_num, fl_num) = folder.stat\n @total_folder_num += fd_num\n @total_file_num += fl_num\n end\n return @total_folder_num + @folders.size, @total_file_num + @file_num\n end\nend\n\nclass Solution\n def initialize()\n @disks = Hash.new\n while line = gets do\n disk_name = line[0,1]\n if @disks.has_key?(disk_name)\n disk = @disks[disk_name]\n else\n disk = Disk.new(disk_name)\n @disks[disk_name] = disk\n end\n line = line[2..-1]\n parse(disk, line)\n end\n end\n\n def parse(location, line)\n match_data = /\\\\(.*?)\\\\/.match(line)\n if match_data.nil?\n location.file_num += 1\n else\n folder_name = match_data[1]\n if location.folders.has_key?(folder_name)\n folder = location.folders[folder_name]\n else\n folder = Folder.new(folder_name)\n location.folders[folder_name] = folder\n end\n line = line[match_data[0].size-1..-1]\n parse(folder, line)\n end\n end\n\n def solve()\n fd_max = 0\n fl_max = 0\n @disks.each_value do |disk|\n disk.folders.each do |folder_name, folder|\n fd_num, fl_num = folder.stat\n fd_max = [fd_max, fd_num].max\n fl_max = [fl_max, fl_num].max\n end\n end\n printf(\"%d %d\\n\", fd_max, fl_max)\n end\nend\n\nsolution = Solution.new\nsolution.solve\n\n"}, {"source_code": "def gao(dir)\n\tif dir.empty?\n\t\treturn 0, 1\n\telse\n\t\tfold, file = 1, 0\n\t\tdir.each do |_, subdir|\n\t\t\tfoldx, filex = gao(subdir)\n\t\t\tfold += foldx\n\t\t\tfile += filex\n\t\tend\n\t\treturn fold, file\n\tend\nend\n\ndir = {}\nreadlines.each do |line|\n\tpwd = dir\n\tline.split(?\\\\).each do |path|\n\t\tpwd[path] = {} unless pwd.has_key? path\n\t\tpwd = pwd[path]\n\tend\nend\n\nfold, file = 0, 0\ndir.each do |_, drive|\n\tdrive.each do |_, dirx|\n\t\tfoldx, filex = gao(dirx)\n\t\tfold = [fold, foldx].max\n\t\tfile = [file, filex].max\n\tend\nend\n\nputs \"#{fold - 1} #{file}\"\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Hash\n\tdef calc\n\t\tret = [0, 0]\n\t\tself.each_pair { |n, v|\n\t\t\tif n =~ /\\./\n\t\t\t\tret[1] += 1\n\t\t\telse\n\t\t\t\ttmp = v.calc\n\t\t\t\tret[0] += 1 + tmp[0]\n\t\t\t\tret[1] += tmp[1]\n\t\t\tend\n\t\t}\n\t\tret\n\tend\n\n\tdef subfolders\n\t\tcnt = 0\n\t\tself.each_pair { |n, v|\n\t\t\tcnt += 1+v.subfolders unless n =~ /\\./\n\t\t}\n\t\tcnt\n\tend\n\n\tdef files\n\t\tcnt = 0\n\t\tself.each_pair { |n, v|\n\t\t\tif n =~ /\\./\n\t\t\t\tcnt += 1\n\t\t\telse\n\t\t\t\tcnt += v.files\n\t\t\tend\n\t\t}\n\t\tcnt\n\tend\nend\n\ntree = {}\nARGF.read.each_line { |line|\n\tline.chomp!\n\tcur = tree\n\tline.split(\"\\\\\").each { |dir|\n\t\tcur[dir] ||= {}\n\t\tcur = cur[dir]\n\t}\n}\n\nv = tree.values.map { |drv| drv.values }.flatten\nputs \"#{v.map(&:subfolders).max} #{v.map(&:files).max}\"\n"}, {"source_code": "def is_file? name\n\tname.include?('.')\nend\n\ntop_dirs = {}\nseen = {}\nwhile path = gets\n\thier = path.split('\\\\')\n\n\tdir = hier[0] + hier[1]\n\thier.shift(2)\n\n\ttop_dirs[dir] = {subdir: 0, files: 0} unless top_dirs[dir]\n\ttop_dir = top_dirs[dir]\n\n\tpath = dir\n\thier.each do |name|\n\t\tpath += name\n\t\tnext if seen[path]\n\t\tseen[path] = true\n\t\tif is_file? name\n\t\t\ttop_dir[:files] += 1\n\t\telse\n\t\t\ttop_dir[:subdir] += 1\n\t\tend\n\tend\nend\n\n\n\nbest_subdir_count = 0\nbest_subfile_count = 0\n\ntop_dirs.each_value do |dir|\n\tbest_subdir_count = [best_subdir_count, dir[:subdir].to_i].max\n\tbest_subfile_count = [best_subfile_count, dir[:files].to_i].max\nend\n\nputs best_subdir_count\nputs best_subfile_count\n"}, {"source_code": "x = {}\ny = {}\nARGF.each do |l|\n f = l.split('\\\\')\n for i in 1..f.size - 2 do\n if x[f[0..i]] \n x[f[0..i]] += 1\n else\n x[f[0..i]] = 1\n y[f[0..i]] = 0\n for j in 1...i do\n y[f[0..j]] += 1\n end\n end \n end\nend\nputs [y, x].map{|a| a.each_value.max}.join(' ')"}, {"source_code": "x = {}\ny = {}\nARGF.each do |line|\n f = line.split('\\\\')\n for i in 1..f.size - 2 do\n if x[f[0..i]] == nil\n x[f[0..i]] = 1\n y[f[0..i]] = 0\n for j in 1...i do\n y[f[0..j]] += 1\n end\n else\n x[f[0..i]] += 1\n end \n end\nend\n\nputs y.each_value.max\nputs x.each_value.max\n "}, {"source_code": "def foo(node)\n if node.empty?\n [0, 1]\n else\n sum = [1, 0]\n node.each_value do |x|\n a, b = foo(x)\n sum[0] += a\n sum[1] += b\n end\n sum\n end\nend\n\nroot = {}\n\nARGF.each do |l|\n l.chomp!\n cur = root\n l.split(\"\\\\\").each do |name|\n cur = (cur[name] ||= {})\n end\nend\n\nfo = fi = 0\nroot.each do |k,v|\n v.each do |k2,v2|\n a, b = foo(v2)\n fo = [a-1, fo].max\n fi = [b, fi].max\n end\nend\n\nputs [fo, fi]*\" \"\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\n\nclass Hash\n\tdef calc\n\t\tret = [0, 0]\n\t\tself.each_pair { |n, v|\n\t\t\tif n =~ /\\./\n\t\t\t\tret[1] += 1\n\t\t\telse\n\t\t\t\ttmp = v.calc\n\t\t\t\tret[0] += 1 + tmp[0]\n\t\t\t\tret[1] += tmp[1]\n\t\t\tend\n\t\t}\n\t\tret\n\tend\n\n\tdef files\n\t\tcnt = 0\n\t\tself.each_pair { |n, v|\n\t\t\tif n =~ /\\./\n\t\t\t\tcnt += 1\n\t\t\telse\n\t\t\t\tcnt += v.files\n\t\t\tend\n\t\t}\n\t\tcnt\n\tend\nend\n\ntree = {}\nARGF.read.each_line { |line|\n\tline.chomp!\n\tcur = tree\n\tline.split(\"\\\\\").each { |dir|\n\t\tcur[dir] ||= {}\n\t\tcur = cur[dir]\n\t}\n}\n\nputs tree.values.map { |drv| drv.values.map(&:calc) }.max_by { |a| a[0]}.join(' ')\n\n"}, {"source_code": "def is_file? name\n\tname.include?('.')\nend\n\ntop_dirs = {}\n\nwhile path = gets\n\thier = path.split('\\\\')\n\tdir = hier[0] + hier[1]\n\thier.shift(2)\n\ttop_dirs[dir] = {subdir: 0, files: 0} unless top_dirs[dir]\n\ttop_dir = top_dirs[dir]\n\thier.each do |name|\n\t\tif is_file? name\n\t\t\ttop_dir[:files] += 1\n\t\telse\n\t\t\ttop_dir[:subdir] += 1\n\t\tend\n\tend\nend\n\n\n\nbest_subdir_count = 0\nbest_subfile_count = 0\n\ntop_dirs.each_value do |dir|\n\tbest_subdir_count = [best_subdir_count, dir[:subdir].to_i].max\n\tbest_subfile_count = [best_subfile_count, dir[:files].to_i].max\nend\n\nputs best_subdir_count\nputs best_subfile_count\n"}], "src_uid": "e588d7600429eb6b70a1a9b5eca194f7"} {"source_code": "n, m = readline.split(' ').collect(&:to_i)\ncmin, cmax = 0, n - 2\nm.times do\n a, b = readline.split(' ').collect(&:to_i)\n a, b = [a - 1, b - 1].sort\n cmin = [cmin, a].max\n cmax = [cmax, b - 1].min\nend\nputs [cmax - cmin + 1, 0].max\n", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\n\nif m==0\n p n-1\n exit(0)\nend\nl=-100000000000\nr=1000000000000\nfor i in 1..m\n x, y = gets.split.map(&:to_i)\n x, y= y, x if x>y\n l = [l, x].max\n r = [r, y].min\nend\np [r-l, 0].max"}, {"source_code": "parse_int = lambda { gets.split.map{|x| x.to_i} }\n\ntasks, pairs = parse_int.call\nstart, finish = 1, tasks\n\npairs.times {|_|\n pair = parse_int.call.sort\n start = pair[0] if start < pair[0]\n finish = pair[1] if finish > pair[1]\n}\n\n\n\n\n\n\n\n\n\n\nres = finish-start\nres = 0 if res<0\n\nputs res"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = Array.new(n + 1, 0)\nd1_max, d2_min = 0, n\nnone = false\nm.times do\n b = gets.split.map(&:to_i).sort\n if ( a[b[0]] == 1 || a[b[0]].zero? ) && ( a[b[1]] == 2 || a[b[1]].zero? )\n a[b[0]], a[b[1]] = 1, 2\n d1_max = [b[0], d1_max].max\n d2_min = [b[1], d2_min].min\n none = true if d1_max > d2_min\n else\n none = true\n end\nend\nputs none ? 0 : d2_min - d1_max - ( a.any?{|x| !x.zero?} ? 0 : 1 )\n"}, {"source_code": "n, m = gets.split(' ').map{|v| v.to_i}\nhigh_two = 1\nlow_one = n\nfor i in 0...m\n\ttmp = gets.split(' ').map{|v| v.to_i}\n\thigh_two = [high_two, tmp.min].max\n\tlow_one = [low_one, tmp.max].min\nend\n\nputs [0, low_one - high_two].max"}], "negative_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nl=-1000000000\nr=1000000000\nfor i in 1..m\n x, y = gets.split.map(&:to_i)\n x, y= y, x if x>y\n l = [l, x].max\n r = [r, y].min\nend\np r-l"}, {"source_code": "n, m = gets.split.map(&:to_i)\n\nif m==0\n p 1\n exit(0)\nend\nl=-1000000000\nr=1000000000\nfor i in 1..m\n x, y = gets.split.map(&:to_i)\n x, y= y, x if x>y\n l = [l, x].max\n r = [r, y].min\nend\np r-l"}, {"source_code": "n, m = gets.split.map(&:to_i)\n\nif m==0\n p n-1\n exit(0)\nend\nl=-1000000000\nr=1000000000\nfor i in 1..m\n x, y = gets.split.map(&:to_i)\n x, y= y, x if x>y\n l = [l, x].max\n r = [r, y].min\nend\np r-l"}, {"source_code": "n, m = gets.split.map(&:to_i)\nl=-1000000000\nr=1000000000\nfor i in 1..m\n x, y = gets.split.map(&:to_i)\n x, y= y, x if x>y\n l = [l, x].max\n r = [r, y].min\nend\np r-l"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = Array.new(n + 1, 0)\nnone = false\nm.times do\n b = gets.split.map(&:to_i).sort\n if ( a[b[0]] == 1 || a[b[0]].zero? ) && ( a[b[1]] == 2 || a[b[1]].zero? )\n a[b[0]], a[b[1]] = 1, 2\n else\n none = true\n end\nend\np none ? 0 : 2 ** a[1..-1].count(&:zero?)\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = Array.new(n + 1, 0)\nd1_max, d2_min = 0, n\nnone = false\nm.times do\n b = gets.split.map(&:to_i).sort\n if ( a[b[0]] == 1 || a[b[0]].zero? ) && ( a[b[1]] == 2 || a[b[1]].zero? )\n a[b[0]], a[b[1]] = 1, 2\n d1_max = [b[0], d1_max].max\n d2_min = [b[1], d2_min].min\n none = true if d1_max > d2_min\n else\n none = true\n end\nend\nputs none ? 0 : 2 ** a[1..-1].count(&:zero?)\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = Array.new(n + 1, 0)\nd1_max, d2_min = 0, n\nnone = false\nm.times do\n b = gets.split.map(&:to_i).sort\n if ( a[b[0]] == 1 || a[b[0]].zero? ) && ( a[b[1]] == 2 || a[b[1]].zero? )\n a[b[0]], a[b[1]] = 1, 2\n d1_max = [b[0], d1_max].max\n d2_min = [b[1], d2_min].min\n none = true if d1_max > d2_min\n else\n none = true\n end\nend\nans = 2 ** a[1..-1].count(&:zero?) - (a.any?{|x| !x.zero?} ? 0 : 2)\nputs none ? 0 : ans\n"}], "src_uid": "b54ced81e152a28c19e0068cf6a754f6"} {"source_code": "s1 = gets.chomp\ns2 = gets.chomp\nif s1.size == s2.size\n t = 0\n s1.size.times do |i|\n if ['a', 'e', 'i', 'o', 'u'].include?(s1[i]) && !['a', 'e', 'i', 'o', 'u'].include?(s2[i]) ||\n !['a', 'e', 'i', 'o', 'u'].include?(s1[i]) && ['a', 'e', 'i', 'o', 'u'].include?(s2[i])\n t += 1\n end\n end\n if t < 1\n puts \"YES\"\n exit\n end\nend\nputs \"NO\"", "positive_code": [{"source_code": "def can_transform(s, t)\n\tvowels = ['a','e','i','o','u']\n\ts_a = s.split('')\n\tt_a = t.split('')\n\treturn \"No\" if s_a.length != t_a.length\n\ti = 0\n\twhile i < s_a.length do\n\t\tc1 = s_a[i]\n\t\tc2 = t_a[i]\n\t\treturn \"No\" if (vowels.include?(c1) && !vowels.include?(c2)) || (!vowels.include?(c1) && vowels.include?(c2))\n\t\ti = i + 1\n\tend\n\treturn \"Yes\"\nend\n\ns = gets.chomp\nt = gets.chomp\n\nputs can_transform(s, t)\n"}, {"source_code": "s = gets.strip\nt = gets.strip\nvowels = %w{a e i o u}\nconsonents = ('a'..'z').to_a\nvowels.each do |v|\n consonents.delete v\nend\nvalid = true\nif s.length == t.length\n s.length.times do |i|\n curr = s[i]\n if vowels.include? curr\n valid = false if !vowels.include? t[i]\n else\n valid = false if !consonents.include? t[i]\n end\n end\nelse\n valid = false\nend\nputs valid ? \"Yes\" : \"No\""}, {"source_code": "a = gets\nb = gets \n\ndef sol(a,b)\n\tvowels = ['a', 'e', 'i', 'o', 'u']\n\n\tif a.size != b.size \n\t return 'No'\n\tend\n\n\ta.each_char.with_index(0){|char, i|\n\t\tb_char = b[i]\n\t\tif ((vowels.include? char) && (!vowels.include? b_char)) || ((vowels.include? b_char) && (!vowels.include? char))\n\t\t\treturn 'No'\n\t\tend\n\t}\n\n\treturn 'Yes'\nend\n\nputs sol(a,b)"}, {"source_code": "s = gets\nt = gets\n\ndef pat(s)\n s.chars.map {|c| ['a','e','i','o','u'].include?(c) }\nend\n\nmat = pat(s) == pat(t)\n\nputs mat ? \"Yes\" : \"No\"\n"}, {"source_code": "x = gets.chomp\ny = gets.chomp\nif x.size != y.size\n puts \"No\"\n exit\nend\nif x == y\n puts \"Yes\"\n exit\nend\n\nvowels = ['a', 'e', 'i', 'o', 'u']\nfor i in 0...x.size\n if x[i] != y[i]\n if vowels.include? y[i] and not vowels.include? x[i]\n puts \"No\"\n exit\n elsif not vowels.include? y[i] and vowels.include? x[i]\n puts \"No\"\n exit\n end\n end\nend\nputs \"Yes\"\n\n\n"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nname1 = gets.chomp\nname2 = gets.chomp\n\ndef isvowel(ch)\n\treturn true if [\"a\",\"e\",\"i\",\"o\",\"u\"].include?(ch)\n\tfalse\nend\n\nif name1.length == name2.length\n\t(0..name1.length).each do |i|\n\t\tiv1 = isvowel(name1[i])\n\t\tiv2 = isvowel(name2[i])\n\t\tif (iv1 and not iv2) or (iv2 and not iv1)\n\t\t\tputs \"No\"\n\t\t\texit\n\t\tend\n\tend\n\tputs \"Yes\"\nelse\n\tputs \"No\"\nend"}, {"source_code": "# run on ruby 2.0.0p645\n\ndef main()\n s = gets\n t = gets\n \n ans = solve(s, t)\n puts ans\nend\n\ndef solve(s, t)\n # https://docs.ruby-lang.org/ja/latest/method/String/i/gsub.html\n\n c = /[^aeiou]/\n v = /[aeiou]/\n normalizedS = s.gsub(c, 'C').gsub(v, 'V')\n normalizedT = t.gsub(c, 'C').gsub(v, 'V')\n if normalizedS === normalizedT\n return 'Yes'\n else\n return 'No'\n end\nend\n\nmain()\n"}], "negative_code": [{"source_code": "puts 'hello, world.'"}], "src_uid": "2b346d5a578031de4d19edb4f8f2626c"} {"source_code": "class Stud\n attr_reader :i,:t,:x\n attr_accessor :t_out\n def initialize i,t,x\n @i,@t,@x = i,t,x\n @t_out = nil\n end\n def <=> b\n x <=> b.x\n end\n def to_s\n \"stud i=#{i}, t=#{t}, x=#{x}\"\n end\nend\nn,m = gets.split.map &:to_i\nst = []\n0.upto(n-1) do |i|\n t,x = gets.split.map &:to_i\n st << Stud.new(i,t,x)\nend\nt = 0\nans = []\nuntil st.empty?\n bus = []\n until bus.size == m or st.empty?\n stud = st.shift\n t = [t,stud.t].max\n bus << stud\n end\n bus.sort!\n x = 0\n until bus.empty?\n t += bus[0].x-x\n x = bus[0].x\n outed = 0\n until bus.empty? or bus[0].x > x\n outed += 1\n bus[0].t_out = t\n ans << bus[0]\n bus.shift\n end\n t += 1+outed/2\n end\n t += x\nend\nans.sort_by! {|stud| stud.i}\nputs ans.collect {|x| x.t_out}.join ' '\n\n\n", "positive_code": [{"source_code": "class Bus\n @@ar = []\n @@pos = []\n @@m, @@time, @@done = 0, 0, 0\n\n def initialize m\n @@m = m\n end\n\n def grab(queue, pos)\n cur = 0\n @@pos = []\n while pos < queue.length and cur < @@m\n @@ar[queue[pos][1]] ||= []\n @@ar[queue[pos][1]] << [queue[pos][0], pos]\n @@pos << queue[pos][1]\n pos, cur = pos + 1, cur + 1\n end\n @@time = [@@time, queue[pos - 1][0]].max\n @@pos.sort!.uniq!\n pos\n end\n\n def unload\n prev = 0\n @k = []\n @@pos.each do |i|\n @@time += i - prev\n prev = i\n @@ar[i].each{ |t, index| @k << [@@time, index] }\n @@done += @@ar[i].length\n @@time += 1 + (@@ar[i].length / 2)\n @@ar[i] = []\n end\n @@time += prev\n return @k\n end\n\n def done\n return @@done\n end\nend\n\n\nn, m = gets.split.map{|i| i.to_i}\nqueue, answer = [], []\n(1..n).each{ |i| queue[i] = gets.split.map{|j| j.to_i} }\nbus = Bus.new m\npos = 1\nwhile bus.done < queue.length - 1\n pos = bus.grab(queue, pos)\n bus.unload.each{ |ans, index| answer[index] = ans }\nend\n(1..n).each do |i|\n print answer[i].to_s + ' '\nend\n"}], "negative_code": [], "src_uid": "bb2ee9d4f718116ec391c93af58ec012"} {"source_code": "str1 = gets.strip\nstr2 = gets.strip\n\nstrl = (str1.size > str2.size ? str1 : str2)\nstrs = (str1.size > str2.size ? str2 : str1)\nmxn = strl.size\nmnn = strs.size\n\nbis = nil\nbil = nil\n(mnn-1).downto(0).each do |si|\n li = si + (mxn - mnn)\n if strl[li] != strs[si]\n bis = si\n bil = li\n break\n end\nend\n\nif bis.nil?\n puts mxn-mnn\nelse\n puts bis+bil+2\nend", "positive_code": [{"source_code": "s = gets.chomp.reverse\nt = gets.chomp.reverse\nans = s.length + t.length\n[s.length, t.length].min.times do |i|\n if s[i] == t[i]\n ans -= 2\n else\n break\n end\nend\nputs ans"}, {"source_code": "a = gets.strip\nb = gets.strip\ni = a.size - 1\nj = b.size - 1\nwhile i >= 0 && j >= 0 && a[i] == b[j] do\n i-=1\n j-=1\nend\nputs i + j + 2\n"}, {"source_code": "\nx = gets.chomp();\ny = gets.chomp();\nsum = x.size() + y.size();\nx.reverse!\ny.reverse!\nfor i in 0 ... x.size()\n if(x[i] == y[i])\n sum-=2;\n else\n break\n end\nend\nputs sum\n\n"}, {"source_code": "s1 = STDIN.readline.strip\ns2 = STDIN.readline.strip\n\ns1_chars = s1.reverse.split('')\ns2_chars = s2.reverse.split('')\n\nwhile s1_chars[0] == s2_chars[0] and s1_chars.length > 0 and s1_chars.length > 0\n s1_chars.shift if s1_chars.length > 0\n s2_chars.shift if s2_chars.length > 0\nend\n\nputs s1_chars.length + s2_chars.length\n"}, {"source_code": "s = gets.chomp.split('')\nt = gets.chomp.split('')\n\ni1 = s.length - 1\ni2 = t.length - 1\n\nwhile (i1 >= 0 && i2 >= 0)\n\t# puts \"#{s[i1]} #{t[i2]}\"\n\tif s[i1] != t[i2]\n\t\tbreak\n\telse\n\t\ti1 -= 1\n\t\ti2 -= 1\n\tend\nend\n\nprint (i1 + i2 + 2)"}, {"source_code": "s = gets.chomp\nt = gets.chomp\n\ns = s.reverse\nt = t.reverse\n\nn = [s.length, t.length].min\nsame_characters = 0\n\nn.times do |i|\n break if s[i] != t[i]\n same_characters += 2\nend\n\nanswer = (s.length + t.length) - same_characters\nputs answer\n"}, {"source_code": "s = gets.chomp.reverse\nt = gets.chomp.reverse\nn = s.size.times.take_while { s[_1] == t[_1] }.size\nputs s.size + t.size - n * 2\n"}, {"source_code": "a,b=$<.map{|e|e.chomp.reverse}\nlas=[a.size,b.size].min\nidx=(0...las).find{|i|a[i]!=b[i]}||las\np a.size+b.size-idx*2"}, {"source_code": " s1 = gets.chomp.reverse\n s2 = gets.chomp.reverse\n\n total_lenght = s1.size + s2.size\n\n common_length = 0\n\n i = 0\n while true\n\n if s1[i] && s1[i] == s2[i]\n i += 1\n common_length = i\n else\n break\n end\n end\n\n puts total_lenght - 2 * common_length\n"}], "negative_code": [{"source_code": "s = gets.chomp\nt = gets.chomp\n\ns = s.reverse\nt = t.reverse\n\nn = [s.length, t.length].min\nsame_characters = 0\n\nfor i in 0..n\n if s[i] == t[i]\n same_characters += 2\n else\n break\n end\n i += 1\nend\n\nanswer = (s.length + t.length) - same_characters\nputs answer\n"}], "src_uid": "59d926bca19a6dcfe3eb3e3dc03fffd6"} {"source_code": "puts gets.to_i.times.inject(0) { |s| [s, gets.split.map(&:to_i).inject(0) { |s, x| s + x }].max }\n", "positive_code": [{"source_code": "gets;p$<.map{|e|e.split.map(&:to_i).reduce :+}.max"}, {"source_code": "\ndef solution\n n = read_int\n max_b = 0\n n.times do\n x, y = read_ints\n b = x + y\n max_b = b if b > max_b\n end\n puts max_b\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}, {"source_code": "n = gets.to_i\nans = 0\nn.times do\n x,y = gets.split.map(&:to_i)\n ans = x+y if ans < x+y\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\nans = 0\nn.times do\n x, y = gets.split.map(&:to_i)\n ans = x + y if x + y > ans\nend\nputs ans"}, {"source_code": "p gets.to_i.times.map { gets.split.map(&:to_i).inject :+ }.max\n"}, {"source_code": "n = gets.to_i\nans = 0\nn.times do\n a = gets.split\n w = a[0].to_i+a[1].to_i\n ans = w if w > ans\nend\np ans"}], "negative_code": [{"source_code": "n = gets.to_i\nprint 1, ' ', n%3 == 2 ? 2 : 1, ' ', n%3 == 2 ? n - 3 : n - 2\n"}], "src_uid": "7c41fb6212992d1b3b3f89694b579fea"} {"source_code": "def floor(n, mod)\n return 1 if n == 1\n return n * floor(n-1, mod)\nend\nn, m = gets.split(' ').map { |i| i.to_i }\nmod = 1000000007\nlight = gets.split(' ').map { |i| i.to_i}.sort\nlight.insert(0, 0)\nlight.push(n+1)\nsegment = []\nfor i in 1...light.size\n s = light[i] - light[i-1] - 1\n segment.push s if s != 0\nend\ntotal = segment.inject { |mem, var| mem += var}\ntotal = 1 if total.nil?\nc1 = c2 = c3 = 1\nfor i in 0...segment.size\n c1 = c1 * floor(segment[i], mod)\n next if (i == 0 and light[1] != 1) or (i == segment.size - 1 and light[m] != n)\n c2 = c2 * (2**(segment[i]-1))\nend\nputs (floor(total, mod) / c1 * c2) % mod", "positive_code": [{"source_code": "# mod = 1000000007;\n\n# for i in 0..99\n# p (2**i)%1000000007\n# end\n\nn = gets(' ').to_i\nm = gets.to_i\n\ninp=[0]\n(m-1).times{\n inp.push gets(' ').to_i\n}\ninp.push gets.to_i\n\ninp = inp.sort\n\na=[]\n\nfor i in 1..m\n a.push inp[i]-inp[i-1]-1\nend\na.push n-inp[m]\n\na0 = a[0]\nam = a[m]\nem = m\n\n# p a\n# p m\n\nab = a.clone\n\nm-=a.count 0\na=a-[0]\n\n# p a\n# p m\n\ndef silnia(x)\n ret=1\n for i in 2..x\n ret*=i\n end\n return ret\nend\n\ns=a.clone\n\nfor i in 1..s.length-1\n s[i] += s[i-1]\nend\n\n# p a\n# p s\n# p m\n# p n\n# p em\n# p a0\n# p am\n\nif m > -1\n ret = silnia s[m]\n for i in a\n ret /= silnia i\n end\n \n# p n-em-a0-am-m+1\n# \n# p ret\n \n if 0 == ab[0]\n m+=1\n end\n \n if 0 == ab[ab.length-1]\n m+=1\n end\n \n if 0 == m\n p ret%1000000007\n else\n p((ret * 2**(n-em-a0-am-m+1))%1000000007)\n end\nelse\n p 1\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n def factorial(n)\n f = 1\n 2.upto(n) {|i| f *= i }\n return f\n end\n\n def solve(lights)\n n = lights.length\n off = n\n lights.each {|v| off -= 1 if v }\n\n return 0 if off == n\n\n ans = factorial(off)\n off = 0\n den = 1\n 0.upto(n) do |i|\n if i == n\n den *= factorial(off)\n break\n end\n\n if lights[i]\n den *= factorial(off)\n off = 0\n else\n off += 1\n end\n end\n\n ans /= den\n flag = true\n 0.upto(n) do |i|\n if flag && lights[i]\n flag = false\n off = 0\n end\n\n if lights[i]\n ans *= 2 ** (off - 1) if off > 0\n off = 0\n else\n off += 1\n end\n end\n\n ans\n end\nend\n\ntokens = gets.split(\" \")\nn = tokens[0].to_i\nm = tokens[1].to_i\nlights = Array.new(n, false)\n\nif m > 0\n gets.split(\" \").map(&:to_i).each {|v| lights[v-1] = true }\nend\n\nsolver = Solver.new\nputs solver.solve(lights)%1000000007\n\n"}, {"source_code": "def pow2 p\n\tt = 1\n\t(0...p).each{\n\t\tt = (t*2)%1000000007\n\t}\n\treturn t\nend\n\ndef fact n\n\tt = 1\n\t(0...p).each{\n\t\tt = (t*n)%1000000007\n\t}\n\treturn t\nend\n\ndef comb n,k\n\ta = [k,n-k].max\n\tb = [k,n-k].min\n\tt = 1\n\tp = 2\n\t(a+1..n).each{|k|\n\t\tt = t*k\n\t\twhile t%p==0 and p<=b\n\t\t\tt = t/p\n\t\t\tp += 1\n\t\tend\n\t}\n\treturn t%1000000007\nend\n\nn,m=gets.split(\" \").collect! {|x| x.to_i}\narr = [0]*n\nline = gets.split(\" \").collect! {|x| x.to_i}\nline.each {|v|\n\tarr[v-1] = 1\n}\n\nintervals = []\ncrt = 0\n(0...n).each {|k|\n\tif arr[k]==0\n\t\tcrt += 1\n\telse\n\t\tif crt!=0\n\t\t\tintervals.push crt\n\t\tend\n\t\tcrt = 0\n\tend\n}\nif crt!= 0\n\tintervals.push crt\nend\npp = intervals.collect {|x| pow2(x-1)}\nif arr[0] == 0\n\tpp[0] = 1\nend\n\nif arr[-1] == 0\n\tpp[-1] = 1\nend\n\nll = pp.size\nres = 1\nt = n - m\n(0...ll).each {|y|\n #puts \" - #{pp[y]} #{intervals[y]} #{t} #{comb(t,intervals[y])}\"\n\t#puts res\n\tres = (res*pp[y])%1000000007\n\tif y -1\n ret = silnia s[m]\n for i in a\n ret /= silnia i\n end\n \n p (ret * 2**(n-em-a0-am-m+1))%1000000007\nelse\n p 1\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "# mod = 1000000007;\n\n# for i in 0..99\n# p (2**i)%1000000007\n# end\n\nn = gets(' ').to_i\nm = gets.to_i\n\ninp=[0]\n(m-1).times{\n inp.push gets(' ').to_i\n}\ninp.push gets.to_i\n\ninp = inp.sort\n\na=[]\n\nfor i in 1..m\n a.push inp[i]-inp[i-1]-1\nend\na.push n-inp[m]\n\na0 = a[0]\nam = a[m]\nem = m\n\n# p a\n# p m\n\nm-=a.count 0\na=a-[0]\n\n# p a\n# p m\n\ndef silnia(x)\n ret=1\n for i in 2..x\n ret*=i\n end\n return ret\nend\n\ns=a.clone\n\nfor i in 1..s.length-1\n s[i] += s[i-1]\nend\n\n# p a\n# p s\n\nif m > -1\n ret = silnia s[m]\n for i in a\n ret /= silnia i\n end\n \n# p n-em-a0-am-m+1\n \n if 0 == m\n p ret%1000000007\n else\n p (ret * 2**(n-em-a0-am-m+1))%1000000007\n end\nelse\n p 1\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "# mod = 1000000007;\n\n# for i in 0..99\n# p (2**i)%1000000007\n# end\n\nn = gets(' ').to_i\nm = gets.to_i\n\ninp=[0]\n(m-1).times{\n inp.push gets(' ').to_i\n}\ninp.push gets.to_i\n\na=[]\n\nfor i in 1..m\n a.push inp[i]-inp[i-1]-1\nend\na.push n-inp[m]\n\n# p a\n# p m\n\nm-=a.count 0\na=a-[0]\n\n# p a\n# p m\n\ndef silnia(x)\n ret=1\n for i in 2..x\n ret*=i\n end\n return ret\nend\n\ns=a.clone\n\nfor i in 1..s.length-1\n s[i] += s[i-1]\nend\n\n# p a\n# p s\n\nif m > -1\n ret = silnia s[m]\n for i in a\n ret /= silnia i\n end\n \n p ret * 2**(n-2*m-a[0]-a[m]+1)\nelse\n p 1\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "# mod = 1000000007;\n\n# for i in 0..99\n# p (2**i)%1000000007\n# end\n\nn = gets(' ').to_i\nm = gets.to_i\n\ninp=[0]\n(m-1).times{\n inp.push gets(' ').to_i\n}\ninp.push gets.to_i\n\ninp = inp.sort\n\na=[]\n\nfor i in 1..m\n a.push inp[i]-inp[i-1]-1\nend\na.push n-inp[m]\n\na0 = a[0]\nam = a[m]\nem = m\n\n# p a\n# p m\n\nm-=a.count 0\na=a-[0]\n\n# p a\n# p m\n\ndef silnia(x)\n ret=1\n for i in 2..x\n ret*=i\n end\n return ret\nend\n\ns=a.clone\n\nfor i in 1..s.length-1\n s[i] += s[i-1]\nend\n\n# p a\n# p s\n\nif m > -1\n ret = silnia s[m]\n for i in a\n ret /= silnia i\n end\n \n p (ret * 2**(n-2*em-a0-am+1))%1000000007\nelse\n p 1\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "# mod = 1000000007;\n\n# for i in 0..99\n# p (2**i)%1000000007\n# end\n\nn = gets(' ').to_i\nm = gets.to_i\n\ninp=[0]\n(m-1).times{\n inp.push gets(' ').to_i\n}\ninp.push gets.to_i\n\na=[]\n\nfor i in 1..m\n a.push inp[i]-inp[i-1]-1\nend\na.push n-inp[m]\n\na0 = a[0]\nam = a[m]\nem = m\n\n# p a\n# p m\n\nm-=a.count 0\na=a-[0]\n\n# p a\n# p m\n\ndef silnia(x)\n ret=1\n for i in 2..x\n ret*=i\n end\n return ret\nend\n\ns=a.clone\n\nfor i in 1..s.length-1\n s[i] += s[i-1]\nend\n\n# p a\n# p s\n\nif m > -1\n ret = silnia s[m]\n for i in a\n ret /= silnia i\n end\n \n p ret * 2**(n-2*em-a0-am+1)\nelse\n p 1\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "# mod = 1000000007;\n\n# for i in 0..99\n# p (2**i)%1000000007\n# end\n\nn = gets(' ').to_i\nm = gets.to_i\n\ninp=[0]\n(m-1).times{\n inp.push gets(' ').to_i\n}\ninp.push gets.to_i\n\na=[]\n\nfor i in 1..m\n a.push inp[i]-inp[i-1]-1\nend\na.push n-inp[m]\n\ndef silnia(x)\n ret=1\n for i in 2..x\n ret*=i\n end\n return ret\nend\n\ns=a.clone\n\nfor i in 1..s.length-1\n s[i] += s[i-1]\nend\n\n# p a\n# p s\n\nret = silnia s[m]\nfor i in a\n ret /= silnia i\nend\n\np ret * 2**(n-2*m-a[0]-a[m]+1)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n def factorial(n)\n f = 1\n 2.upto(n) {|i| f *= i }\n return f\n end\n\n def solve(lights)\n n = lights.length\n off = n\n lights.each {|v| off -= 1 if v }\n\n return 0 if off == 0\n\n ans = factorial(off)\n off = 0\n den = 1\n 0.upto(n) do |i|\n if i == n\n den *= factorial(off)\n break\n end\n\n if lights[i]\n den *= factorial(off)\n off = 0\n else\n off += 1\n end\n end\n\n ans /= den\n flag = true\n 0.upto(n) do |i|\n if flag && lights[i]\n flag = false\n off = 0\n end\n\n if lights[i]\n ans *= 2 ** (off - 1) if off > 0\n off = 0\n else\n off += 1\n end\n end\n\n ans\n end\nend\n\ntokens = gets.split(\" \")\nn = tokens[0].to_i\nm = tokens[1].to_i\nlights = Array.new(n, false)\n\ngets.split(\" \").map(&:to_i).each {|v| lights[v-1] = true }\n\nsolver = Solver.new\nputs solver.solve(lights)\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n def factorial(n)\n f = 1\n 2.upto(n) {|i| f *= i }\n return f\n end\n\n def solve(lights)\n n = lights.length\n off = n\n 0.upto(n - 1) {|i| off -= 1 if lights[i] }\n\n ans = factorial(off)\n off = 0\n den = 1\n 0.upto(n) do |i|\n if i == n\n den *= factorial(off)\n break\n end\n\n if lights[i]\n den *= factorial(off)\n off = 0\n else\n off += 1\n end\n end\n\n ans /= den\n flag = true\n 0.upto(n) do |i|\n if flag && lights[i]\n flag = false\n off = 0\n end\n\n if lights[i]\n ans *= 2 ** (off - 1) if off > 0\n else\n off += 1\n end\n end\n\n ans\n end\nend\n\ntokens = gets.split(\" \")\nn = tokens[0].to_i\nm = tokens[1].to_i\nlights = Array.new(n, false)\n\ngets.split(\" \").map(&:to_i).each {|i| lights[i-1] = true }\n\nsolver = Solver.new\nputs solver.solve(lights)\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n def factorial(n)\n f = 1\n 2.upto(n) {|i| f *= i }\n return f\n end\n\n def solve(lights)\n n = lights.length\n off = n\n lights.each {|v| off -= 1 if v }\n\n ans = factorial(off)\n off = 0\n den = 1\n 0.upto(n) do |i|\n if i == n\n den *= factorial(off)\n break\n end\n\n if lights[i]\n den *= factorial(off)\n off = 0\n else\n off += 1\n end\n end\n\n ans /= den\n flag = true\n 0.upto(n) do |i|\n if flag && lights[i]\n flag = false\n off = 0\n end\n\n if lights[i]\n ans *= 2 ** (off - 1) if off > 0\n off = 0\n else\n off += 1\n end\n end\n\n ans\n end\nend\n\ntokens = gets.split(\" \")\nn = tokens[0].to_i\nm = tokens[1].to_i\nlights = Array.new(n, false)\n\ngets.split(\" \").map(&:to_i).each {|i| lights[i-1] = true }\n\nsolver = Solver.new\nputs solver.solve(lights)\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n def factorial(n)\n f = 1\n 2.upto(n) {|i| f *= i }\n return f\n end\n\n def solve(lights)\n n = lights.length\n off = n\n lights.each {|v| off -= 1 if v }\n\n return 0 if off == 0 || off == n\n\n ans = factorial(off)\n off = 0\n den = 1\n 0.upto(n) do |i|\n if i == n\n den *= factorial(off)\n break\n end\n\n if lights[i]\n den *= factorial(off)\n off = 0\n else\n off += 1\n end\n end\n\n ans /= den\n flag = true\n 0.upto(n) do |i|\n if flag && lights[i]\n flag = false\n off = 0\n end\n\n if lights[i]\n ans *= 2 ** (off - 1) if off > 0\n off = 0\n else\n off += 1\n end\n end\n\n ans\n end\nend\n\ntokens = gets.split(\" \")\nn = tokens[0].to_i\nm = tokens[1].to_i\nlights = Array.new(n, false)\n\nif m > 0\n gets.split(\" \").map(&:to_i).each {|v| lights[v-1] = true }\nend\n\nsolver = Solver.new\nputs solver.solve(lights)\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n def factorial(n)\n f = 1\n 2.upto(n) {|i| f *= i }\n return f\n end\n\n def solve(lights)\n n = lights.length\n off = n\n lights.each {|v| off -= 1 if v }\n\n return 0 if off == n\n\n ans = factorial(off)\n off = 0\n den = 1\n 0.upto(n) do |i|\n if i == n\n den *= factorial(off)\n break\n end\n\n if lights[i]\n den *= factorial(off)\n off = 0\n else\n off += 1\n end\n end\n\n ans /= den\n flag = true\n 0.upto(n) do |i|\n if flag && lights[i]\n flag = false\n off = 0\n end\n\n if lights[i]\n ans *= 2 ** (off - 1) if off > 0\n off = 0\n else\n off += 1\n end\n end\n\n ans\n end\nend\n\ntokens = gets.split(\" \")\nn = tokens[0].to_i\nm = tokens[1].to_i\nlights = Array.new(n, false)\n\nif m > 0\n gets.split(\" \").map(&:to_i).each {|v| lights[v-1] = true }\nend\n\nsolver = Solver.new\nputs solver.solve(lights)\n\n"}], "src_uid": "14da0cdf2939c796704ec548f49efb87"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nif a[-1] < a[-2] + a[-3]\n puts \"YES\"\n ans = []\n ans[0] = a[-2]\n ans[1] = a[-1]\n ans[2] = a[-3]\n (n-3).times do |i|\n ans[i+3] = a[-4-i]\n end\n puts ans.join(\" \")\nelse\n puts \"NO\"\nend\n", "positive_code": [{"source_code": "n = gets.strip\na = gets.strip.split(' ').map(&:to_i)\n\na.sort!\n\nif a[-1] < a[0] + a[-2]\n puts \"YES\"\n puts a.join(' ')\nelse\n a[-2], a[-1] = a[-1], a[-2]\n if a[-1] < a[0] + a[-2] && a[-2] < a[-3] + a[-1]\n puts \"YES\"\n puts a.join(' ')\n else\n puts \"NO\"\n end\nend"}, {"source_code": "n = gets.to_i\ninp = gets.split.map(&:to_i)\n\ninp.sort!\n\nif (inp[-2] + inp[-3] <= inp[-1])\n puts \"NO\"\nelse\n puts \"YES\"\n temp = inp[-1]\n inp[-1] = inp[-2]\n inp[-2] = temp\n inp.each {|x| print \"#{x} \"}\nend"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nif a[-1] < a[-2] + a[-3]\n puts \"YES\"\n ans = []\n ans[0] = a[-2]\n ans[1] = a[-1]\n ans[2] = a[-3]\n (n-3).times do |i|\n ans[i+3] = a[-3-i]\n end\n puts ans.join(\" \")\nelse\n puts \"NO\"\nend\n"}], "src_uid": "a5ee97e99ecfe4b72c0642546746842a"} {"source_code": "l, r = gets.split.map &:to_i\nt = (r-l+1)/2\nputs \"YES\"\ni = l\nwhile i <= r\n print \"#{i} #{i+1}\\n\"\n i += 2\nend", "positive_code": [{"source_code": "l,r=gets.split.map &:to_i;puts :YES,[*l..r]"}, {"source_code": "a,b = gets.chomp.split.map(&:to_i)\n\nputs \"YES\"\nfor i in 0..1000000\nputs \"#{a} #{a+1}\"\na += 2\nbreak if a > b\nend"}, {"source_code": "l,r = gets.split.map(&:to_i)\nputs \"YES\"\n((r-l+1)/2).times do |i|\n puts \"#{l+2*i} #{l+2*i+1}\"\nend\n"}], "negative_code": [], "src_uid": "6432a543eeee9833c6d849222ad6b93d"} {"source_code": "c1, c2, c3, c4 = gets.split.map(&:to_i)\nn, m = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nt = gets.split.map(&:to_i)\n\nsumb = 0\nsumt = 0\n\nfor i in 0...n\n b[i] = [c1*b[i], c2].min\n sumb += b[i]\nend\n\nfor i in 0...m\n t[i] = [c1*t[i], c2].min\n sumt += t[i]\nend\n\nsumb = [sumb, c3].min\nsumt = [sumt, c3].min\n\nprint [sumb+sumt, c4].min", "positive_code": [{"source_code": "costs = gets.split.map{|s| s.to_i}\nbn, tn = gets.split.map{|s| s.to_i}\nbuses = gets.split.map{|s| s.to_i}\ntrolleys = gets.split.map{|s| s.to_i}\n\nb1 = costs[1]/costs[0]\nbsum = tsum = 0\nbuses.each_index{|i|\n buses[i] = buses[i] > b1 ? costs[1] : buses[i]*costs[0]\n bsum += buses[i]\n}\ntrolleys.each_index{|i|\n trolleys[i] = trolleys[i] > b1 ? costs[1] : trolleys[i]*costs[0]\n tsum += trolleys[i]\n}\nbsum = costs[2] if bsum > costs[2]\ntsum = costs[2] if tsum > costs[2]\nsum = bsum + tsum\nsum = costs[3] if sum > costs[3]\nprint sum"}, {"source_code": "c= gets().split().map {|i| i.to_i}.take(4)\nn,m= gets().split().map {|i| i.to_i}.take(2)\na= gets().split().map {|i| i.to_i}.take(n)\nb= gets().split().map {|i| i.to_i}.take(m)\n\ndef f(x, k, c)\n res=0\n for i in 0..k\n res+=[c[1],x[i].to_i*c[0]].min\n end\n [c[2],res].min\nend\n\nprint [c[3],f(a,n,c)+f(b,m,c)].min"}, {"source_code": "c = gets.split.collect{|i| i.to_i}\nn, m = gets.split.collect{|i| i.to_i}\nsum_a = 0\ngets.chomp.split.each do |a|\n sum_a += [a.to_i*c[0],c[1]].min\nend\nsum_a = c[2] if sum_a > c[2]\nsum_b = 0\ngets.chomp.split.each do |b|\n sum_b += [b.to_i*c[0],c[1]].min\nend\nsum_b = c[2] if sum_b > c[2]\nputs [sum_a+sum_b, c[3]].min\n"}, {"source_code": "cs = gets.split.map(&:to_i)\nn, m = gets.split.map(&:to_i)\nns = gets.split.map(&:to_i)\nms = gets.split.map(&:to_i)\n\nsumn_min = ns.inject(0){|a, b| a + [cs[1], b * cs[0]].min }\nsumm_min = ms.inject(0){|a, b| a + [cs[1], b * cs[0]].min }\n#puts sumn_min\n#puts summ_min\n\nnmin = [sumn_min, cs[2]].min\nmmin = [summ_min, cs[2]].min\n\nputs [cs[3], nmin + mmin].min"}, {"source_code": "#f = File.open('test1.txt', 'r')\nf = STDIN\nc = f.gets.chomp.split.map &:to_i\nn, m = f.gets.chomp.split.map &:to_i\na = []\n2.times { a << f.gets.chomp.split.map(&:to_i) }\n# Compute when don't use c4\ntotal = 0\n2.times do |i|\n sub_total = 0\n a[i].each do |ai|\n sub_total += [ai * c[0], c[1]].min\n end\n total += [sub_total, c[2]].min\nend\n\nputs [total, c[3]].min\n"}], "negative_code": [], "src_uid": "11fabde93815c1805369bbbc5a40e2d8"} {"source_code": "class String\n def palindrome?\n self == self.reverse\n end\nend\n\ndef solve(s)\n sa = s.split('')\n return 'Impossible' if sa.uniq.size == 1\n (0..s.size/2).to_a.each do |c|\n r = sa.rotate(c).join('')\n if r.palindrome? && r != s\n return 1\n end\n end\n\n left = s[0..(s.size/2)-1]\n right = s[s.size/2+(s.size.odd? ? 1 : 0)..s.size]\n if left.palindrome?\n left.split('').uniq.size == 1 ? 'Impossible' : 2\n else\n return s.size.odd? ? 2 : 1\n end\nend\n\nputs solve(gets.strip)", "positive_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\n\n\ns = gets.chomp\nlen = s.length\n\nif s.each_char.to_a.uniq.count == 1\n\tputs \"Impossible\"\n\texit\nend\n\nif len%2==1\n\tnews = s[0..len/2-1]+s[len/2+1..-1]\n\tif news.each_char.to_a.uniq.count == 1\n\t\tputs \"Impossible\"\n\t\texit\n\tend\nend\n#p \"hi\"\nif len%2==0\n\tif(s[0..len/2-1] != s[len/2..-1])\n\t\tputs 1\n\t\texit\n\tend\nend\n\n(1..len-1).each do |i|\n\t#break is before i\n\tnews = s[i..-1]+s[0..i-1] \n\tif(news==news.reverse && news != s)\n\t\tputs 1\n\t\texit\n\tend\nend\n\nputs 2"}], "negative_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\n\n\ns = gets.chomp\nlen = s.length\n\nif s.each_char.to_a.uniq.count == 1\n\tputs \"Impossible\"\n\texit\nend\n\n#p \"hi\"\nif len%2==0\n\tif(s[0..len/2-1] != s[len/2..-1])\n\t\tputs 1\n\t\texit\n\tend\nend\n\n(1..len-1).each do |i|\n\t#break is before i\n\tnews = s[i..-1]+s[0..i-1] \n\tif(news==news.reverse && news != s)\n\t\tputs 1\n\t\texit\n\tend\nend\nputs 2"}], "src_uid": "ffdef277d0ff8e8579b113f5bd30f52a"} {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).zip((1..n).to_a).sort!\nans = []\ncnt = 0\nk.times do\n break if a[-1][0] - a[0][0] <= 1 \n cnt += 1\n a[0][0] += 1\n a[-1][0] -= 1\n ans << [a[-1][1], a[0][1]]\n a.sort!\nend\nputs \"#{a[-1][0] - a[0][0]} #{cnt}\", ans.map{|x| x.join(' ')}\n", "positive_code": [{"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).zip(1..n).sort!\nans = []\nk.times do\n mx, mi = a.last, a.first\n break if mx[0] - mi[0] <= 1 \n mx[0] -= 1\n mi[0] += 1\n ans << [mx[1], mi[1]]\n a.sort!\nend\nputs \"#{a[-1][0] - a[0][0]} #{ans.size}\", ans.map{|x| x.join(' ')}\n"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\nheights = STDIN.readline.split.map {|s| s.to_i }\npairs = heights.each_with_index.to_a\nmoves = []\nk.times do\n\tpairs.sort!\n\tbreak if pairs[0][0] + 1 >= pairs[-1][0]\n\tmoves.push('%d %d' % [pairs[-1][1]+1, pairs[0][1]+1])\n\tpairs[-1][0] -= 1\n\tpairs[0][0] += 1\nend\npairs.sort!\nputs '%d %d' % [pairs[-1][0] - pairs[0][0], moves.length]\nputs moves.join(\"\\n\")\n"}, {"source_code": "n_and_k = gets.split(' ')\nn = n_and_k[0].to_i\nk = n_and_k[1].to_i\na = gets.split(' ').map { |s| s.to_i }\n\nmoves = Array.new\n\nk.times do\n posmin = 0\n posmax = 0\n\n a.each_with_index do |val, index|\n if val > a[posmax]\n posmax = index\n else\n if val < a[posmin]\n posmin = index\n end\n end\n end\n\n if a[posmax] == a[posmin]\n break\n else\n moves.push [posmax + 1, posmin + 1]\n a[posmax] -= 1\n a[posmin] += 1\n end\nend\n\nmaxdiff = a.max - a.min\n\nputs \"#{maxdiff} #{moves.length}\"\nmoves.each do |move|\n puts \"#{move[0]} #{move[1]}\"\nend"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\na = gets.split.collect{|i| i.to_i}\nans = Array.new\ncnt = 0\nwhile cnt < k\n min, max = a.minmax\n if max-min <= 1\n break\n end\n minindex = a.index(min)\n maxindex = a.index(max)\n a[maxindex] -= 1\n a[minindex] += 1\n ans.push([maxindex+1, minindex+1])\n cnt += 1\nend\nmin, max = a.minmax\nprint max-min, ' ', cnt, \"\\n\"\nans.each{|i| puts i.join(' ')}\n"}], "negative_code": [{"source_code": "n, k = gets.chomp.split.map(&:to_i)\nhs = gets.chomp.split.map(&:to_i)\nlist = []\nc = 0\ngoal = (hs.inject(:+) / (n * 1.0)).ceil\nk.times do\n for i in 0...n\n break if c >= k\n if hs[i] > goal\n for j in 0...n\n if hs[j] < goal && j != i\n hs[j] += 1\n hs[i] -= 1\n list << [i + 1, j + 1]\n c += 1\n break\n end\n end\n break\n end\n end\nend\nmax = 0\nmin = 10000\nfor i in 0...n\n max = hs[i] if hs[i] > max\n min = hs[i] if hs[i] < min\nend\nans = [max - min, c]\nputs ans.join(\" \")\nputs list.map{|x| x.join(\" \")}\n"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nh = gets.chomp.split.map(&:to_i) # 5 8 5\nans = []\nlist = []\nc = 0\ngoal = (h.inject(:+) / (n * 1.0)).ceil\nk.times do\n max = 0\n min = 10000\n ai, ii = 0\n for i in 0...n\n if h[i] > max\n max = h[i]\n ai = i\n end\n if h[i] < min\n min = h[i]\n ii = i\n end\n end\n if max > goal\n if min < goal && max != min\n h[ii] += 1\n min = h[ii]\n h[ai] -= 1\n max = h[ai]\n list << [ai + 1, ii + 1]\n c += 1\n end\n end\n for i in 0...n\n if h[i] > max\n max = h[i]\n ai = i\n end\n if h[i] < min\n min = h[i]\n ii = i\n end\n end\n dif = max - min\n ans = [dif, c]\nend\nputs ans.join(\" \")\nputs list.map{|x| x.join(\" \")}\n"}], "src_uid": "9cd42fb28173170a6cfa947cb31ead6d"} {"source_code": "n = gets.to_i\n\nif n < 4\n puts 'NO'\n exit\nend\n\ns = \"YES\\n\"\nwhile n > 5\n s << \"#{n} - #{n - 1} = 1\\n\"\n n -= 2\n s << \"#{n} * 1 = #{n}\\n\"\nend\nif n == 5\n s << \"5 - 1 = 4\\n\"\n s << \"4 * 3 = 12\\n\"\n s << \"4 - 2 = 2\\n\"\n s << \"12 * 2 = 24\\n\"\nelse\n s << \"4 * 3 = 12\\n\"\n s << \"12 * 2 = 24\\n\"\n s << \"24 * 1 = 24\\n\"\nend\nputs s", "positive_code": [{"source_code": "n = gets.to_i\n\nif n < 4\n puts \"NO\"\n exit\nend\n\ns = \"YES\\n\"\nwhile n > 5\n s << \"#{n} - #{n-1} = 1\\n\"\n n -= 2\n s << \"#{n} * 1 = #{n}\\n\"\nend\n\nif n==5\n s << \"5 - 1 = 4\\n\"\n s << \"4 * 3 = 12\\n\"\n s << \"4 - 2 = 2\\n\"\n s << \"12 * 2 = 24\\n\"\nelse\n s << \"4 * 3 = 12\\n\"\n s << \"12 * 2 = 24\\n\"\n s << \"24 * 1 = 24\\n\"\nend\n\nputs s"}, {"source_code": "n = gets.to_i\n\nif n < 4\n\tputs 'NO'\nelse\n\tputs 'YES'\n\tif n.even?\n\t\tputs '1 * 2 = 2'\n\t\tputs '2 * 3 = 6'\n\t\tputs '6 * 4 = 24'\n\t\t5.upto(n) do |i|\n\t\t\tif i.odd?\n\t\t\t\tputs (i + 1).to_s + ' - ' + i.to_s + ' = 1'\n\t\t\t\tputs '24 * 1 = 24'\n\t\t\tend\n\t\tend\n\telse\n\t\tputs '5 - 1 = 4'\n\t\tputs '4 - 2 = 2'\n\t\tputs '2 * 3 = 6'\n\t\tputs '6 * 4 = 24'\n\t\t6.upto(n) do |i|\n\t\t\tif i.even?\n\t\t\t\tputs (i + 1).to_s + ' - ' + i.to_s + ' = 1'\n\t\t\t\tputs '24 * 1 = 24'\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "n = gets.to_i\n\nif n < 4\n puts \"NO\"\nelsif n.even?\n puts \"YES\"\n puts \"1 * 2 = 2\"\n puts \"2 * 3 = 6\"\n puts \"6 * 4 = 24\"\n 5.upto(n).each_slice(2) do |a, b|\n puts \"#{b} - #{a} = 1\"\n puts \"24 * 1 = 24\"\n end\nelse\n puts \"YES\"\n puts \"2 - 1 = 1\"\n puts \"1 + 3 = 4\"\n puts \"4 * 5 = 20\"\n puts \"20 + 4 = 24\"\n 6.upto(n).each_slice(2) do |a, b|\n puts \"#{b} - #{a} = 1\"\n puts \"24 * 1 = 24\"\n end\nend\n"}, {"source_code": "n = STDIN.readline.to_i\nif n < 4\n\tputs 'NO'\n\texit\nend\nputs 'YES'\nlines = []\nif n%2 == 0\n\tx = (n-4)/2\n\tx.times {|i| lines.push('%d - %d = 1' % [6+i*2, 5+i*2]) }\n\tx.times { lines.push('1 * 1 = 1') }\n\tlines.push('1 * 2 = 2')\n\tlines.push('2 * 3 = 6')\n\tlines.push('6 * 4 = 24')\nelse\n\tx = (n-5)/2\n\tx.times {|i| lines.push('%d - %d = 1' % [7+i*2, 6+i*2]) }\n\tlines.push('3 - 2 = 1')\n\t(x+1).times { lines.push('1 * 1 = 1') }\n\tlines.push('1 + 5 = 6')\n\tlines.push('6 * 4 = 24')\nend\nputs lines.join(\"\\n\")\n"}, {"source_code": "#! /usr/bin/env ruby\n# -*- coding: utf-8 -*-\n# vim:fenc=utf-8\n#\n# Copyright \u00a9 2014 Szymon Sliwa \n#\n# Distributed under terms of the MIT license.\n\nn = gets.to_i\n\nif n == 1\n puts \"NO\"\nelsif n == 2\n puts \"NO\"\nelsif n == 3\n puts \"NO\"\nelsif n == 4\n puts \"YES\"\n puts \"1 * 2 = 2\\n2 * 3 = 6\\n6 * 4 = 24\"\nelsif n == 5\n puts \"YES\"\n puts \"5 - 1 = 4\\n4 - 2 = 2\\n4 * 2 = 8\\n8 * 3 = 24\"\nelse\n puts \"YES\"\n puts \"2 * 4 = 8\\n6 - 5 = 1\\n1 - 1 = 0\"\n (7..n).each do |x|\n puts \"#{x} * 0 = 0\"\n end\n puts \"3 + 0 = 3\"\n puts \"8 * 3 = 24\\n\"\nend\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "n = STDIN.readline.to_i\nif n < 4\n\tputs 'NO'\n\texit\nend\nlines = []\nif n%2 == 0\n\tx = (n-4)/2\n\tx.times {|i| lines.push('%d - %d' % [6+i*2, 5+i*2]) }\n\tx.times { lines.push('1 * 1') }\n\tlines.push('1 * 2')\n\tlines.push('2 * 3')\n\tlines.push('6 * 4')\nelse\n\tx = (n-5)/2\n\tx.times {|i| lines.push('%d - %d' % [7+i*2, 6+i*2]) }\n\tlines.push('3 - 2')\n\t(x+1).times { lines.push('1 * 1') }\n\tlines.push('1 + 5')\n\tlines.push('6 * 4')\nend\nputs lines.join(\"\\n\")\n"}, {"source_code": "n = STDIN.readline.to_i\nif n < 4\n\tputs 'NO'\n\texit\nend\nputs 'YES'\nlines = []\nif n%2 == 0\n\tx = (n-4)/2\n\tx.times {|i| lines.push('%d - %d' % [6+i*2, 5+i*2]) }\n\tx.times { lines.push('1 * 1') }\n\tlines.push('1 * 2')\n\tlines.push('2 * 3')\n\tlines.push('6 * 4')\nelse\n\tx = (n-5)/2\n\tx.times {|i| lines.push('%d - %d' % [7+i*2, 6+i*2]) }\n\tlines.push('3 - 2')\n\t(x+1).times { lines.push('1 * 1') }\n\tlines.push('1 + 5')\n\tlines.push('6 * 4')\nend\nputs lines.join(\"\\n\")\n"}, {"source_code": "#! /usr/bin/env ruby\n# -*- coding: utf-8 -*-\n# vim:fenc=utf-8\n#\n# Copyright \u00a9 2014 Szymon Sliwa \n#\n# Distributed under terms of the MIT license.\n\nn = gets.to_i\n\nif n == 1\n puts \"NO\"\nelsif n == 2\n puts \"NO\"\nelsif n == 3\n puts \"NO\"\nelsif n == 4\n puts \"1 * 2 = 2\\n2 * 3 = 6\\n6 * 4 = 24\"\nelsif n == 5\n puts \"5 - 1 = 4\\n4 - 2 = 2\\n4 * 2 = 8\\n8 * 3 = 24\"\nelse\n puts \"2 * 4 = 8\\n6 - 5 = 1\\n1 - 1 = 0\"\n (7..n).each do |x|\n puts \"#{x} * 0 = 0\"\n end\n puts \"8 * 3 = 24\\n\"\nend\n\n\n\n\n\n\n\n"}, {"source_code": "#! /usr/bin/env ruby\n# -*- coding: utf-8 -*-\n# vim:fenc=utf-8\n#\n# Copyright \u00a9 2014 Szymon Sliwa \n#\n# Distributed under terms of the MIT license.\n\nn = gets.to_i\n\nif n == 1\n puts \"NO\"\nelsif n == 2\n puts \"NO\"\nelsif n == 3\n puts \"NO\"\nelsif n == 4\n puts \"1 * 2 = 2\\n2 * 3 = 6\\n6 * 4 = 24\"\nelsif n == 5\n puts \"5 - 1 = 4\\n4 - 2 = 2\\n4 * 2 = 8\\n8 * 3 = 24\"\nelse\n puts \"2 * 4 = 8\\n6 - 5 = 1\\n1 - 1 = 0\"\n (7..n).each do |x|\n puts \"#{x} * 0 = 0\"\n end\n puts \"3 + 0 = 3\"\n puts \"8 * 3 = 24\\n\"\nend\n\n\n\n\n\n\n\n"}], "src_uid": "1bd1a7fd2a07e3f8633d5bc83d837769"} {"source_code": "m,n=gets.split.map &:to_i\na=[]\n(1..n).to_a.sort_by{|x|x&-x}.reverse_each{|i|if m-(i&-i)>=0 then m-=i&-i;a.push i end}\nexit !puts(-1) if m>0\np a.size\nputs a*' '", "positive_code": [{"source_code": "m,n=gets.split.map &:to_i\na=[]\n(1..n).to_a.sort_by{|x|x&-x}.reverse_each{|i|if m-(i&-i)>=0 then m-=i&-i;a.push i end}\nexit !puts(-1) if m>0\np a.size\nputs a*' '\n"}, {"source_code": "m,n=gets.split.map &:to_i\na=[]\n(1..n).to_a.sort_by{|x|x&-x}.reverse_each{|i|if m-(i&-i)>=0 then m-=i&-i;a.push i end}\nexit !puts(-1) if m>0\np a.size\nputs a*' '\n"}, {"source_code": "n,m=gets.chomp.split.map(&:to_i)\nsc,i,j=Array.new(100005,0),1,1\nwhile n!=0&&i<=m\n\tj=i\n\twhile j<=m\n\t\tif n!=0 && ((n&i)!=0 || j+i*2<=m)\n\t\t\tsc[sc[0]+1]=j\n\t\t\tsc[0]+=1\n\t\t\tn-=i\n\t\tend\n\t\tj+=i*2\n\tend\n\ti<<=1\nend\nif n!=0\n\tputs \"-1\"\nelse\n\tputs sc[0]\n\tfor i in 1...sc[0]\n\t\tprint \"#{sc[i]} \"\n\tend\n\tputs sc[sc[0]]\nend"}, {"source_code": "#! /usr/bin/env ruby\n\ndef main\n sum, lmt = readline.split.map do |x| x.to_i end\n set = Array.new\n (1..lmt).reverse_each do |i|\n lb = i & -i\n if sum >= lb then\n sum -= lb\n set.push i\n end\n end\n if sum == 0 then\n puts set.size\n set.each do |x|\n print x, ' '\n end\n puts\n else\n puts -1\n end\nend\n\nmain\n"}, {"source_code": "m,n=gets.split.map &:to_i\na=[]\n(1..n).to_a.sort_by{|x|x&-x}.reverse_each{|i|if m-(i&-i)>=0 then m-=i&-i;a.push i end}\nexit !puts(-1) if m>0\np a.size\nputs a*' '\n"}, {"source_code": "m,n=gets.split.map &:to_i\na=[]\n(1..n).to_a.sort_by{|x|x&-x}.reverse_each{|i|if m-(i&-i)>=0 then m-=i&-i;a.push i end}\nexit !puts(-1) if m>0\np a.size\nputs a*' '\n"}, {"source_code": "m,n=gets.split.map &:to_i\na=[]\n(1..n).to_a.sort_by{|x|x&-x}.reverse_each{|i|if m-(i&-i)>=0 then m-=i&-i;a.push i end}\nexit !puts(-1) if m>0\np a.size\nputs a*' '"}, {"source_code": "m,n=gets.split.map &:to_i\na=[]\n(1..n).to_a.sort_by{|x|x&-x}.reverse_each{|i|if m-(i&-i)>=0 then m-=i&-i;a.push i end}\nexit !puts(-1) if m>0\np a.size\nputs a*' '"}, {"source_code": "m,n=gets.split.map &:to_i\na,now=[],0\nans=[]\n(1..n).each{|i|a.push i}\na.sort_by!{|x|x&-x}\na.reverse.each{|i|if (i&-i)+now<=m then now+=i&-i;ans.push i end}\nexit !puts(-1) if now!=m\np ans.size\nputs ans*' '\n"}, {"source_code": "def lowbit(n)\n i = 0\n while(n%2 == 0) do\n n /= 2\n i += 1\n end\n return 2**i\nend\n\nsum,limit = gets.split.map(&:to_i)\nnums = []\n(1..limit).each do |x|\n nums << [x,lowbit(x)]\nend \nnums.sort_by!{ |x| x[1] }\nnums.reverse!\n#puts nums.map{ |x| \"[#{x[0]} #{x[1]}]\" }.join \" \"\nret = []\nnums.each do |x|\n next if(sum < x[1])\n sum -= x[1]\n ret << x[0]\nend\nif(sum == 0)\n puts ret.size\n puts ret.join(\" \")\nelse\n puts -1\nend\n\n\n\n\n\n\n"}, {"source_code": "m,n=gets.split.map &:to_i\na=[]\n(1..n).to_a.sort_by{|x|x&-x}.reverse_each{|i|if m-(i&-i)>=0 then m-=i&-i;a.push i end}\nexit !puts(-1) if m>0\np a.size\nputs a*' '\n"}, {"source_code": "def subset_sum(s,n,arr)\n\treturn true if s == 0\n\treturn false if n == 0 && s != 0\n\treturn subset_sum(s,n-1,arr) if arr[n-1] > s\n\n\tif subset_sum(s-arr[n-1],n-1,arr)\n\t\t@sum_arr << n\n\t\treturn true\n\tend \n\treturn subset_sum(s,n-1,arr)\n\nend\n\nsum,limit = gets.split(\" \").map(&:to_i)\n@sum_arr = []\narr = []\n(1..limit).each do |i|\n\tarr << (i ^ (i & (i-1)))\nend\nones = (limit/2.to_f).ceil\nlist = arr.each_with_index.sort.reverse\n# puts \"#{ones}\"\n# puts \"#{list}\"\n\nans = false\nans_list = []\nlist.each do |a|\n\tif sum <= ones\n\t\tans = true\n\t\tbreak \n\tend\n\tbreak if a[0] == 1 \n\tsum -= a[0]\n\tans_list << a[1] + 1\nend\nif ans\n\tone_index = list.index{|i| i[0] == 1}\n\twhile sum > 0\n\t\tsum -= 1\n\t\tans_list << list[one_index][1] + 1\n\t\tone_index += 1\n\tend\n\tputs ans_list.length\n\tputs ans_list.join(\" \")\nelse\n\tputs \"-1\"\nend\n# subset_sum(sum,arr.length,arr)\n\n# if @sum_arr.length != 0\n# \tputs @sum_arr.length\n# \tputs @sum_arr.join(\" \")\n# else\n# \tputs \"-1\"\n# end"}, {"source_code": "m,n=gets.split.map &:to_i\na=[]\n(1..n).to_a.sort_by{|x|x&-x}.reverse_each{|i|if m-(i&-i)>=0 then m-=i&-i;a.push i end}\nexit !puts(-1) if m>0\np a.size\nputs a*' '\n"}, {"source_code": "m,n=gets.split.map &:to_i\na=[]\n(1..n).to_a.sort_by{|x|x&-x}.reverse_each{|i|if m-(i&-i)>=0 then m-=i&-i;a.push i end}\nexit !puts(-1) if m>0\np a.size\nputs a*' '\n"}, {"source_code": "m,n=gets.split.map &:to_i\na=[]\n(1..n).to_a.sort_by{|x|x&-x}.reverse_each{|i|if m-(i&-i)>=0 then m-=i&-i;a.push i end}\nexit !puts(-1) if m>0\np a.size\nputs a*' '\n"}], "negative_code": [{"source_code": "def lowbit(n)\n i = 0\n while(n%2 == 0) do\n n /= 2\n i += 1\n end\n return 2**i\nend\n\nsum,limit = gets.split.map(&:to_i)\nnums = []\n(1..limit).each do |x|\n nums << [x,lowbit(x)]\nend \nnums.sort_by!{ |x| x[1] }\nnums.reverse!\n#puts nums.map{ |x| \"[#{x[0]} #{x[1]}]\" }.join \" \"\nret = []\nnums.each do |x|\n next if(sum < x[1])\n sum -= x[1]\n ret << x[0]\nend\nif(sum == 0)\n puts ret.join(\" \")\nelse\n puts -1\nend\n"}, {"source_code": "def subset_sum(s,n,arr)\n\treturn true if s == 0\n\treturn false if n == 0 && s != 0\n\treturn subset_sum(s,n-1,arr) if arr[n-1] > s\n\n\tif subset_sum(s-arr[n-1],n-1,arr)\n\t\t@sum_arr << n\n\t\treturn true\n\tend \n\treturn subset_sum(s,n-1,arr)\n\nend\n\nsum,limit = gets.split(\" \").map(&:to_i)\n@sum_arr = []\narr = []\n(1..limit).each do |i|\n\tarr << (i ^ (i & (i-1)))\nend\nones = (limit/2.to_f).ceil\nlist = arr.each_with_index.sort.reverse\n# puts \"#{ones}\"\n# puts \"#{list}\"\n\nans = false\nans_list = []\nlist.each do |a|\n\tbreak if a[0] == 1 \n\tif sum <= ones\n\t\tans = true\n\t\tbreak \n\tend\n\tsum -= a[0]\n\tans_list << a[1] + 1\nend\nif ans\n\tone_index = list.index{|i| i[0] == 1}\n\twhile sum > 0\n\t\tsum -= 1\n\t\tans_list << list[one_index][1] + 1\n\t\tone_index += 1\n\tend\n\tputs ans_list.length\n\tputs ans_list.join(\" \")\nelse\n\tputs \"-1\"\nend\n# subset_sum(sum,arr.length,arr)\n\n# if @sum_arr.length != 0\n# \tputs @sum_arr.length\n# \tputs @sum_arr.join(\" \")\n# else\n# \tputs \"-1\"\n# end"}, {"source_code": "def subset_sum(s,n,arr)\n\treturn true if s == 0\n\treturn false if n == 0 && s != 0\n\treturn subset_sum(s,n-1,arr) if arr[n-1] > s\n\n\tif subset_sum(s-arr[n-1],n-1,arr)\n\t\t@sum_arr << n\n\t\treturn true\n\tend \n\treturn subset_sum(s,n-1,arr)\n\nend\n\nsum,limit = gets.split(\" \").map(&:to_i)\n@sum_arr = []\narr = []\n(1..limit).each do |i|\n\tarr << (i ^ (i & (i-1)))\nend\nones = (limit/2.to_f).ceil\nlist = arr.each_with_index.sort.reverse\n# puts \"#{ones}\"\n# puts \"#{list}\"\n\nans = false\nans_list = []\nlist.each do |a|\n\tif sum <= ones\n\t\tans = true\n\t\tbreak \n\tend\n\tsum -= a[0]\n\tans_list << a[1] + 1\nend\nif ans\n\tone_index = list.index{|i| i[0] == 1}\n\twhile sum > 0\n\t\tsum -= 1\n\t\tans_list << list[one_index][1] + 1\n\t\tone_index += 1\n\tend\n\tputs ans_list.length\n\tputs ans_list.join(\" \")\nelse\n\tputs \"-1\"\nend\n# subset_sum(sum,arr.length,arr)\n\n# if @sum_arr.length != 0\n# \tputs @sum_arr.length\n# \tputs @sum_arr.join(\" \")\n# else\n# \tputs \"-1\"\n# end"}], "src_uid": "1e4b638810ea9fa83c60a934ad49bf5e"} {"source_code": "n = gets.to_i\na = gets.split(/\\s+/).map(&:to_i)\nmod = 998244353\n\nten = (0..21).map{|e| 10**e}\nans = 0\na.each do |x|\n t = 0\n while x > 0\n p = x % 10;\n ans = (ans + (p*n*ten[t]) % mod) % mod\n ans = (ans + (p*n*ten[t+1]) % mod) % mod\n x /= 10\n t += 2\n end\nend\n\nputs ans\n", "positive_code": [{"source_code": "MOD = 998244353\nn = gets.to_i\na = gets.split.map(&:to_i)\ncnt = [0]*10\na.each do |v|\n cnt[Math.log10(v).to_i] += 1\nend\nans = 0\na.each do |v|\n d = Math.log10(v).to_i\n l,r,m = v,0,1\n 10.times do |i|\n r += m*(l%10)\n l /= 10\n m *= 100\n if i < d\n ans += l * m * cnt[i] * 2 % MOD\n ans += (r + r*10) * cnt[i] % MOD\n else\n ans += (r + r*10) * cnt[i] % MOD\n end\n ans %= MOD\n end\nend\np ans\n"}], "negative_code": [], "src_uid": "6e093dbcbcaa7c87c9b62546745984db"} {"source_code": "n = gets.to_i\n\nxs = gets.split(\" \").map(&:to_i).sort\n\ng = 0\n(1...n).each do |i|\n g = g.gcd(xs[i] - xs[i-1])\nend\n\nres = 0\n(1...n).each do |i|\n res += (xs[i] - xs[i-1]) / g - 1\nend\n\nputs res\n", "positive_code": [{"source_code": "def gcd(a,b)\n if (b == 0)\n a\n else\n gcd(b,a%b)\n end\nend\n\nn = readline.to_i\n\na = readline.split.map(&:to_i).sort\n\ng = a[1] - a[0]\nfor i in 1 .. n-2\n g = gcd(g, a[i+1]-a[i])\nend\n\nans = 0\nfor i in 0 .. n-2\n ans += (a[i+1] - a[i]) / g - 1\nend\n\np ans"}, {"source_code": "def gcd(a,b)\n if (b == 0)\n a\n else\n gcd(b,a%b)\n end\nend\n\nn = readline.to_i\n\na = readline.split.map(&:to_i).sort\n\ng = a[1] - a[0]\nfor i in 1 .. n-2\n g = gcd(g, a[i+1]-a[i])\nend\n\nans = 0\nfor i in 0 .. n-2\n ans += (a[i+1] - a[i]) / g - 1\nend\n\np ans"}, {"source_code": "def gcd a, b\n return a if b.zero?\n gcd b, a % b\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nt=0\na.sort!\n\n$num = n\n$i = 1\nwhile $i < $num do\n a[$i] = a[$i] - a[0]\n $i +=1\nend\na[0]=0\nans = gcd(a[1],a[2])\n\n$num = n\n$i = 3\nwhile $i < $num do\n ans = gcd(ans, a[$i])\n $i +=1\nend\nans = (a[n-1] / ans) - n + 1\n\nputs ans"}, {"source_code": "n = gets.to_i\narr = gets.split\ni = 0\nwhile i < arr.length\n arr[i] = arr[i].to_i\n i = i + 1\nend\narr = arr.sort\nif arr.length == 1\n puts 0\nelse \n g = arr[1] - arr[0]\n i = 2\n while i < arr.length\n a = g\n b = arr[i] - arr[i - 1]\n while b != 0\n tmp = b\n b = a % b\n a = tmp\n end\n i = i + 1\n g = a\n #puts g\n end\n i = 1\n ans = 0\n while i != arr.length\n ans = ans + (arr[i] - arr[i - 1]) / g - 1\n i = i + 1\n end\n puts ans\nend\n"}, {"source_code": "n = gets.to_i\narr = gets.chomp.split.map {|x| x.to_i}.sort\n\nlen = arr[-1] - arr[0]\ngcd = arr[1] - arr[0]\narr.each_with_index do |x, i|\n gcd = gcd.gcd(x - arr[i - 1]) if i > 0\nend\n\nputs len / gcd + 1 - n"}, {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i).sort\nx1 = x[1..-1]\nx2 = x[0..-2]\nx3 = []\n(0..(n-2)).each{|i|\n \n x3.push(x1[i] - x2[i])\n}\n\ng = x3.reduce(x3[0], :gcd)\n\nk = 0\nx3.each{\n |v|\n k = k + (v / g).to_i - 1\n}\nprint(k)\n"}, {"source_code": "n = readline().to_i\na = readline().split().map(&:to_i).sort\n\ng = 0\nleft = right = a[0]\nfor i in 1..n-1\n\tg = g.gcd(a[i]-a[i-1])\n\tleft = [a[i], left].min\n\tright = [a[i], right].max\nend\n\nputs (right-left)/g + 1 - n\n\n"}], "negative_code": [], "src_uid": "805d82c407c1b34f217f8836454f7e09"} {"source_code": "total_time, time_slice, constant = gets.strip.split(\" \")\n\ntotal_time = total_time.to_i \ntime_slice = time_slice.to_i\nconstant = constant.to_f\n\narr_requests = gets.strip.split(\" \").map(&:to_i)\n\nresults = Hash.new\n\nmean = 0.0\nj = 0\nwhile j < time_slice-1 do\n mean = (mean + (arr_requests[j].to_f / time_slice.to_f)) / constant\n j+=1\nend\n\narr_summ = arr_requests.slice(0,time_slice-1).inject(:+).to_f\n\nputs \ni = time_slice-1\nwhile i < arr_requests.length do \n k = i+1\n\n arr_summ+=arr_requests[i]\n arr_summ -= arr_requests[i-time_slice] if i > time_slice-1\n\n real = arr_summ / time_slice\n \n mean = (mean + (arr_requests[i].to_f / time_slice.to_f)) / constant\n err = (mean - real).abs / real\n\n results[k] = {real: real, mean: mean, error: err}\n i+=1\nend\n\nrq = gets\nrequests = gets.strip.split(\" \")\nrequests.each do |r|\n r = r.to_i\n puts sprintf(\"%.6f %.6f %.6f\\n\", results[r][:real], results[r][:mean], results[r][:error])\nend", "positive_code": [{"source_code": "(n, t, c) = gets.scan(/[\\d\\.]+/).map(&:to_f)\nn = n.to_i\nt = t.to_i\na = gets.scan(/\\d+/).map(&:to_i)\nm = gets.scan(/\\d+/).map(&:to_i)\na = [a] if a.is_a? Fixnum\nm = [m] if a.is_a? Fixnum\np_arr = gets.scan(/\\d+/).map(&:to_i)\n\nmean = [0.0]*(n+1)\nreal = [0.0]*(n+1)\n\n(n).times do |i|\n mean[i+1] = (mean[i] + a[i].to_f/t) / c\n real[i+1] = real[i] + a[i]\nend\np_arr.each do |p|\n r = (real[p] - real[p-t])/t\n puts \"%.6f %.6f %.6f\" % [r.round(6), mean[p].round(6), ((mean[p]-r).abs/r).round(6)]\nend"}], "negative_code": [{"source_code": "total_time, time_slice, constant = gets.strip.split(\" \")\n\ntotal_time = total_time.to_i \ntime_slice = time_slice.to_i\nconstant = constant.to_f\n\narr_requests = gets.strip.split(\" \").map(&:to_i)\n\n\nresults = Hash.new\n\nmean = 0.0\nj = 0\nwhile j < time_slice-1 do\n mean = (mean + (arr_requests[j].to_f / time_slice.to_f)) / constant\n j+=1\nend\n\narr_summ = arr_requests.slice(0,time_slice-1).inject(:+).to_f\n\nputs \ni = time_slice-1\nwhile i < arr_requests.length do \n k = i+1\n\n arr_summ+=arr_requests[i]\n arr_summ -= arr_requests[i-4] if i > 3\n\n real = arr_summ / time_slice\n \n mean = (mean + (arr_requests[i].to_f / time_slice.to_f)) / constant\n err = (mean - real).abs / real\n\n results[k] = {real: real, mean: mean, error: err}\n i+=1\nend\n\nrq = gets\nrequests = gets.strip.split(\" \")\nrequests.each do |r|\n r = r.to_i\n puts sprintf(\"%.6f %.6f %.6f\\n\", results[r][:real], results[r][:mean], results[r][:error])\nend"}], "src_uid": "be8d2eff2f34e72625566680ae188c49"} {"source_code": "input0 = gets.chomp\nkey = input0.split(\"\").map { |e| e.ord - 48 }\ninput = gets.chomp.split\na = Integer(input[0])\nb = Integer(input[1])\n\nl = key.length\nleft = Array.new(l-1)\nremainder = key[0].to_i % a\nleft[0] = remainder\n\nfor i in 1...l-1\n remainder_b = left[i-1] * 10\n left[i] = (key[i] + remainder_b) % a\nend\n\nright = key[l-1].to_i % b\n\nsplit = 0\nanswer = false\n\nif right == 0 && left[l-2] == 0 && key[l-1] != 0\n split = l-2\n answer = true\nelse\n c = 10 % b\n d = 1\n for i in 1...l-1\n d = (c * d) % b\n\n remainder_b = key[l-1-i] * d\n right = (right + remainder_b) % b\n if right == 0 && left[l-i-2] == 0\n if key[l-i-1] != 0\n split = l-i-2\n answer = true\n break\n end\n end\n end\nend\n\nif !answer\n puts \"NO\"\nelse\n x = input0[0..split]\n y = input0[split+1..l-1]\n puts \"YES\"\n print x\n puts\n print y\nend", "positive_code": [{"source_code": "input = gets.chomp\na, b = gets.chomp.split(\" \")\na = a.to_i\nb = b.to_i\n\nnum = Array.new(input.length)\nfor i in 0...num.length\n num[i] = input[i].to_i\nend\n\nleft = Array.new(num.length)\nacc = 0\nfor i in 0...num.length\n acc = acc * 10 + num[i]\n acc %= a\n left[i] = acc\nend\n\nacc = 0\nrem = 1\nans = false\nfor i in (num.length-1).downto(1)\n acc = acc + num[i] * rem\n rem *= 10\n rem %= b\n acc %= b\n if num[i] != 0 && left[i-1] == 0 && acc == 0\n puts \"YES\"\n puts input[0...i]\n puts input[i...input.length]\n ans = true\n break\n end\nend\n\nif !ans\n puts \"NO\"\nend"}], "negative_code": [{"source_code": "input = gets.chomp\na, b = gets.chomp.split(\" \")\na = a.to_i\nb = b.to_i\n\nnum = Array.new(input.length)\nfor i in 0...num.length\n num[i] = input[i].to_i\nend\n\nleft = Array.new(num.length)\nacc = 0\nfor i in 0...num.length\n acc = acc * 10 + num[i]\n acc %= a\n left[i] = acc\nend\n\nacc = 0\nrem = 1\nans = false\nfor i in (num.length-1).downto(1)\n acc = acc + num[i] * rem\n rem *= 10\n rem %= b\n acc %= b\n if num[i] != 0 && left[i-1] == 0 && acc == 0\n puts \"YES\"\n puts input[0, i - 1]\n puts input[i, -1]\n ans = true\n break\n end\nend\n\nif !ans\n puts \"NO\"\nend"}, {"source_code": "key = gets.chomp.split(\"\")\ninput = gets.chomp.split\na = Integer(input[0])\nb = Integer(input[1])\n\nl = key.length\nleft = Array.new(l-1)\nremainder = key[0].to_i % a\nleft[0] = remainder\n\nfor i in 1...l-1\n key_i = key[i].to_i\n remainder_a = key_i % a\n remainder_b = (left[i-1] * (10 % a)) % a\n left[i] = (remainder_a + remainder_b) % a\nend\n\nright = Array.new(l-1)\nremainder = key[l-1].to_i % b\nright[l-2] = remainder\nten_remainder = Array.new(l-1)\nc = 10 % b\nd = c\nten_remainder[0] = c\nfor i in 1...l-1\n d = (c * d) % b\n ten_remainder[i] = d\nend\n\nfor i in 1...l-1\n key_i = key[l-1-i].to_i\n number = key_i * (10**i) + right[l-i-1][0]\n remainder_a = right[l-i-1]\n remainder_b = ((key_i % b) * ten_remainder[i-1]) % b\n right[l-i-2] = (remainder_a + remainder_b) % b\nend\nsplit = 0\nanswer = false\nfor i in 0...l-1\n if left[i] == right[i] && left[i] == 0\n split = i\n answer = true\n break\n end\nend\n\nif !answer\n puts \"NO\"\nelse\n puts \"YES\"\n print key[0..i].join\n puts\n print key[i+1..l-1].join\nend"}, {"source_code": "input0 = gets.chomp\nkey = input0.split(\"\").map { |e| e.ord - 48 }\ninput = gets.chomp.split\na = Integer(input[0])\nb = Integer(input[1])\n\nl = key.length\nleft = Array.new(l-1)\nremainder = key[0].to_i % a\nleft[0] = remainder\n\nfor i in 1...l-1\n remainder_b = left[i-1] * 10\n left[i] = (key[i] + remainder_b) % a\nend\n\nright = Array.new(l-1)\nremainder = key[l-1].to_i % b\nright[l-2] = remainder\nten_remainder = Array.new(l-1)\nc = 10 % b\nd = c\nten_remainder[0] = c\nfor i in 1...l-1\n d = (c * d) % b\n ten_remainder[i] = d\nend\n\nfor i in 1...l-1\n remainder_a = right[l-i-1]\n remainder_b = key[l-1-i] * ten_remainder[i-1]\n right[l-i-2] = (remainder_a + remainder_b) % b\nend\nsplit = 0\nanswer = false\nx = \"\"\ny = \"\"\nfor i in 0...l-1\n if left[i] == right[i] && left[i] == 0\n split = i\n if key[i+1] != \"0\"\n answer = true\n break\n end\n end\nend\nx = input0[0..split]\ny = input0[split+1..l-1]\nif !answer\n puts \"NO\"\nelse\n puts \"YES\"\n print x\n puts\n print y\nend"}, {"source_code": "key = gets.chomp.split(\"\")\ninput = gets.chomp.split\na = Integer(input[0])\nb = Integer(input[1])\n\nl = key.length\nleft = Array.new(l-1)\nremainder = key[0].to_i % a\nleft[0] = remainder\n\nfor i in 1...l-1\n key_i = key[i].to_i\n remainder_a = key_i % a\n remainder_b = (left[i-1] * (10 % a)) % a\n left[i] = remainder_a + remainder_b\nend\n\nright = Array.new(l-1)\nremainder = key[l-1].to_i % b\nright[l-2] = remainder\nten_remainder = Array.new(l-1)\nc = 10 % b\nd = c\nten_remainder[0] = c\nfor i in 1...l-1\n d = (c * d) % b\n ten_remainder[i] = d\nend\n\nfor i in 1...l-1\n key_i = key[l-1-i].to_i\n number = key_i * (10**i) + right[l-i-1][0]\n remainder_a = right[l-i-1]\n remainder_b = ((key_i % b) * ten_remainder[i-1]) % b\n right[l-i-2] = (remainder_a + remainder_b) % b\nend\nsplit = 0\nanswer = false\nfor i in 0...l-1\n if left[i] == right[i] && left[i] == 0\n split = i\n answer = true\n break\n end\nend\n\nif !answer\n puts \"NO\"\nelse\n puts \"YES\"\n print key[0..i].join\n puts\n print key[i+1..l-1].join\nend"}], "src_uid": "695418026140545863313f5f3cc1bf00"} {"source_code": " \na = readlines.map(&:chop)\nn = a.map(&:size).max\nh = ['*' * n]\nc = 0\nputs (h + a + h).map{|_|\n\tif (n - _.size).odd?\n\t\t_ = c.odd? ? \" #{_}\" : \"#{_} \"\n\t\tc += 1\n\tend\n\t\"*#{_.center(n)}*\"\n} * \"\\n\"", "positive_code": [{"source_code": "a = readlines.map(&:chop)\nn = a.map(&:size).max\nh = ['*' * n]\nc = 0\nputs (h + a + h).map{|_|\n\tif (n - _.size).odd?\n\t\t_ = c.odd? ? \" #{_}\" : \"#{_} \"\n\t\tc += 1\n\tend\n\t\"*#{_.center(n)}*\"\n} * \"\\n\"\n"}, {"source_code": "a = readlines.map(&:chop)\nn = a.map(&:size).max\nh = ['*' * n]\nc = 0\nputs (h + a + h).map{|_|\n\tif (n - _.size).odd?\n\t\t_ = c.odd? ? \" #{_}\" : \"#{_} \"\n\t\tc += 1\n\tend\n\t\"*#{_.center(n)}*\"\n} * \"\\n\"\n\n"}, {"source_code": "strings = Array.new\nmaxlen = 0\nwhile line = gets\n line.strip!\n if line.size>maxlen\n maxlen=line.size\n end\n strings << line\nend\nleft=true\n(maxlen+1).times {print \"*\"}\nputs \"*\"\nstrings.each do |s|\n diff = maxlen-s.size\n margin=diff/2\n print \"*\"\n margin.times {print \" \"}\n if diff%2==0\n print s\n else\n print \" \" if !left\n print s\n print \" \" if left\n left=!left\n end\n margin.times {print \" \"}\n puts \"*\"\nend\n(maxlen+1).times {print \"*\"}\nputs \"*\"\n"}, {"source_code": "a = readlines.map(&:chop)\nn = a.map(&:size).max\nh = ['*' * n]\nc = 0\nputs (h + a + h).map{|_|\n\tif (n - _.size).odd?\n\t\t_ = c.odd? ? \" #{_}\" : \"#{_} \"\n\t\tc += 1\n\tend\n\t\"*#{_.center(n)}*\"\n} * \"\\n\"\n\n"}, {"source_code": "a = readlines.map(&:chop)\nn = a.map(&:size).max\nh = ['*' * n]\nc = 0\nputs (h + a + h).map{|_|\n\tif (n - _.size).odd?\n\t\t_ = c.odd? ? \" #{_}\" : \"#{_} \"\n\t\tc += 1\n\tend\n\t\"*#{_.center(n)}*\"\n} * \"\\n\"\n"}, {"source_code": "def display(s,n,flag)\n t=(n-s.length)\n h=t/2\n t=t-h\n t,h=h,t if flag\n print \" \"*t\n print s\n print \" \"*h\nend\nmemo=[]\nmax=0\nwhile line=gets\n line.chomp!\n max=line.length if max haba\nend\nres = '*'*(haba+2)\nres += \"\\r\\n\"\nflag=true\nlines.each do |x|\n thisL = '*'\n s = (haba-x.size)\n if(s%2==0||flag)\n thisL += ' '*(s/2)\n flag=false unless s%2==0\n else\n thisL += ' '*(s/2+1)\n flag=true\n end\n thisL += x.chomp\n thisL += ' '*(haba+1-thisL.size)\n res += (thisL+\"*\\r\\n\")\nend\nres += '*'*(haba+2)\nprint res+\"\\r\\n\"\n"}, {"source_code": "lines = []\nmax_width = 0\nwhile (line = gets)\n\tline.strip!\n\tmax_width = line.length if line.length > max_width\n\tlines << line\nend\n\ntop_bottom = \"*\" * (max_width + 2)\nleft = true\nputs top_bottom\nlines.each do |line|\n\tspace = max_width - line.length\n\tleft_space = left ? space / 2 : (space / 2.0).ceil\n\tright_space = left ? (space / 2.0).ceil : space / 2\n\tleft = !left if space % 2 == 1\n\tputs \"*\" + \" \" * left_space + line + \" \" * right_space + \"*\"\nend\nputs top_bottom"}, {"source_code": "a = readlines.map(&:chop)\nn = a.map(&:size).max\nh = ['*' * n]\nc = 0\nputs (h + a + h).map{|_|\n\tif (n - _.size).odd?\n\t\t_ = c.odd? ? \" #{_}\" : \"#{_} \"\n\t\tc += 1\n\tend\n\t\"*#{_.center(n)}*\"\n} * \"\\n\"\n\n"}, {"source_code": "a = readlines.map(&:chop)\nn = a.map(&:size).max\nh = ['*' * n]\nc = 0\nputs (h + a + h).map{|_|\n\tif (n - _.size).odd?\n\t\t_ = c.odd? ? \" #{_}\" : \"#{_} \"\n\t\tc += 1\n\tend\n\t\"*#{_.center(n)}*\"\n} * \"\\n\""}, {"source_code": "a = readlines.map(&:chop)\nn = a.map(&:size).max\nh = ['*' * n]\nc = 0\nputs (h + a + h).map{|_|\n\tif (n - _.size).odd?\n\t\t_ = c.odd? ? \" #{_}\" : \"#{_} \"\n\t\tc += 1\n\tend\n\t\"*#{_.center(n)}*\"\n} * \"\\n\"\n\n"}, {"source_code": "a = readlines.map(&:chop)\nn = a.map(&:size).max\nh = ['*' * n]\nc = 0\nputs (h + a + h).map{|_|\n\tif (n - _.size).odd?\n\t\t_ = c.odd? ? \" #{_}\" : \"#{_} \"\n\t\tc += 1\n\tend\n\t\"*#{_.center(n)}*\"\n} * \"\\n\"\n\n"}, {"source_code": "input, max = [], 0\nwhile g = gets; input.push g.strip; end\ninput.map! { |i| l = i.length; max = l if l > max; [i, l] }\n\nputs '*' * (max + 2)\n\nleft = false\n\ninput.each do |i|\n\tprint '*'\n\tm = (max - i[1])\n\ts = m / 2\n\tif (m % 2).even?\n\t\tprint ' ' * s, i[0], ' ' * s\n\telse\n\t\tl, r = s, s\n\t\tleft ? l += 1 : r += 1\n\t\tprint ' ' * l, i[0], ' ' * r\n\t\tleft = !left\n\tend\n\tputs '*'\nend\n\nputs '*' * (max + 2)"}, {"source_code": "\ndef justify(str_arr)\n len_arr = str_arr.collect {|s| s.size}\n len = len_arr.max\n \n justify_left = true\n res = ['*' * (len+2)]\n str_arr.each do |s| \n spaces = len - s.size\n sp_left = spaces/2\n sp_right = spaces - spaces/2\n if spaces % 2 != 0 and s != ''\n if !justify_left\n sp_left += 1\n sp_right -= 1\n end\n justify_left = !justify_left\n end\n ss = ' '*sp_left + s + ' '*sp_right\n res << '*' + ss + '*'\n end \n res << '*' * (len+2)\n res\nend\n\n\nif __FILE__ == $0\n arr = []\n while line = gets\n arr << line.chomp\n end\n res = justify(arr)\n res.each {|s| puts s}\nend\n"}, {"source_code": "a = readlines.map(&:chop)\nn = a.map(&:size).max\nh = ['*' * n]\nc = 0\nputs (h + a + h).map{|_|\n\tif (n - _.size).odd?\n\t\t_ = c.odd? ? \" #{_}\" : \"#{_} \"\n\t\tc += 1\n\tend\n\t\"*#{_.center(n)}*\"\n} * \"\\n\"\n\n"}], "negative_code": [{"source_code": "def display(s,n)\n t=(n-s.length)\n h=t/2\n (t-h).times do\n print \" \"\n end\n print s\n h.times do\n print \" \"\n end\nend\nmemo=Array.new\nmax=0\nwhile line=gets\n line.chomp!\n max=maxhaba\nend\nres = '*'*(haba+2)\nlines.each do |x|\n res +=\"\\n\"\n res += '*'\n s = (haba-x.size)/2\n res += ' '*s\n res += x.chomp\n if (haba-x.size)%2 == 0\n res += ' '*s\n else\n res += ' '*(s+1)\n end\n res +='*'\nend\nres += \"\\n\"\nres += '*'*(haba+2)\nputs res\n"}, {"source_code": "lines = []\nwhile line = gets do\n lines << line.chomp\nend\nhaba = 0\nlines.each do |x|\n haba = x.size if x.size>haba\nend\nres = '*'*(haba+2)\nlines.each do |x|\n res +=\"\\n\"\n res += '*'\n s = (haba-x.size)/2\n if (haba-x.size)%2 == 0\n res += ' '*s\n else\n res += ' '*(s+1)\n end\n res += x.chomp\n res += ' '*s\n res +='*'\nend\nres += \"\\n\"\nres += '*'*(haba+2)\nprint res\n"}, {"source_code": "lines = []\nwhile line = gets do\n lines << line.chomp\nend\nhaba = 0\nlines.each do |x|\n haba = x.size if x.size>haba\nend\nres = '*'*(haba+2)\nlines.each do |x|\n res +=\"\\n\"\n res += '*'\n s = (haba-x.size)/2\n if (haba-x.size)%2 == 0\n res += ' '*s\n else\n res += ' '*(s+1)\n end\n res += x.chomp\n res += ' '*s\n res +='*'\nend\nres += \"\\n\"\nres += '*'*(haba+2)\nprint res"}, {"source_code": "lines = []\nwhile line = gets do\n lines << line.chomp\nend\nhaba = 0\nlines.each do |x|\n haba = x.size if x.size>haba\nend\nres = '*'*(haba+2)\nlines.each do |x|\n res +=\"\\n\"\n res += '*'\n s = (haba-x.size)/2\n if (haba-x.size)%2 == 0\n res += ' '*s\n else\n res += ' '*(s+1)\n end\n res += x.chomp\n res += ' '*s\n res +='*'\nend\nres += \"\\n\"\nres += '*'*(haba+2)\nprint res\n"}, {"source_code": "lines = []\nwhile line = gets do\n lines << line\nend\nhaba = 0\nlines.each do |x|\n haba = x.size if x.size>haba\nend\nres = '*'*(haba+1)\nlines.each do |x|\n res +=\"\\n\"\n res += '*'\n s = (haba-x.size)/2\n res += ' '*s\n res += x.chomp\n if (haba-x.size)%2 == 0\n res += ' '*s\n else\n res += ' '*(s+1)\n end\n res +='*'\nend\nres += \"\\n\"\nres += '*'*(haba+1)\nprint res\n"}, {"source_code": "lines = []\nwhile line = gets do\n lines << line.chomp\nend\nhaba = 0\nlines.each do |x|\n haba = x.size if x.size>haba\nend\nres = '*'*(haba+2)\nres += \"\\r\\n\"\nlines.each do |x|\n res += '*'\n s = (haba-x.size)/2\n res += ' '*s\n res += x.chomp\n res += ' '*(haba-x.size-s)\n res += \"*\\r\\n\"\nend\nres += '*'*(haba+2)\nprint res+\"\\r\\n\"\n"}, {"source_code": "lines = []\nwhile line = gets do\n lines << line.chomp\nend\nhaba = 0\nlines.each do |x|\n haba = x.size if x.size>haba\nend\nres = '*'*(haba+2)\nlines.each do |x|\n res +=\"\\n\"\n res += '*'\n s = (haba-x.size)/2\n res += ' '*s\n res += x.chomp\n if (haba-x.size)%2 == 0\n res += ' '*s\n else\n res += ' '*(s+1)\n end\n res +='*'\nend\nres += \"\\n\"\nres += '*'*(haba+2)\nprint res\n"}, {"source_code": "lines = []\nwhile line = gets do\n lines << line.chomp\nend\nhaba = 0\nlines.each do |x|\n haba = x.size if x.size>haba\nend\nres = '*'*(haba+2)\nlines.each do |x|\n res +=\"\\n\"\n res += '*'\n s = (haba-x.size)/2\n if (haba-x.size)%2 == 0\n res += ' '*s\n else\n res += ' '*(s+1)\n end\n res += x.chomp\n res += ' '*s\n res +='*'\nend\nres += \"\\n\"\nres += '*'*(haba+2)\nprint res\n"}, {"source_code": "lines = []\nwhile line = gets do\n lines << line.chomp\nend\nhaba = 0\nlines.each do |x|\n haba = x.size if x.size>haba\nend\nres = '*'*(haba+2)\nlines.each do |x|\n res +=\"\\n\"\n res += '*'\n s = (haba-x.size)/2\n if (haba-x.size)%2 == 0\n res += ' '*s\n else\n res += ' '*(s+1)\n end\n res += x.chomp\n res += ' '*s\n res +='*'\nend\nres += \"\\n\"\nres += '*'*(haba+2)\nputs res\n"}, {"source_code": "lines = []\nwhile line = gets do\n lines << line.chomp\nend\nhaba = 0\nlines.each do |x|\n haba = x.size if x.size>haba\nend\nres = '*'*(haba+2)\nlines.each do |x|\n res +=\"\\n\"\n res += '*'\n s = (haba-x.size)/2\n if (haba-x.size)%2 == 0\n res += ' '*s\n else\n res += ' '*(s+1)\n end\n res += x.chomp\n res += ' '*s\n res +='*'\nend\nres += \"\\n\"\nres += '*'*(haba+2)\nprint res\n"}, {"source_code": "lines = []\nwhile line = gets do\n lines << line\nend\nhaba = 0\nlines.each do |x|\n haba = x.size if x.size>haba\nend\nres = '*'*(haba+1)\nlines.each do |x|\n res +=\"\\n\"\n res += '*'\n s = (haba-x.size)/2\n res += ' '*s\n res += x.chomp\n if (haba-x.size)%2 == 0\n res += ' '*s\n else\n res += ' '*(s+1)\n end\n res +='*'\nend\nres += \"\\n\"\nres += '*'*(haba+1)\nputs res\n"}, {"source_code": "lines = []\nwhile line = gets do\n lines << line.chomp\nend\nhaba = 0\nlines.each do |x|\n haba = x.size if x.size>haba\nend\nres = '*'*(haba+2)\nlines.each do |x|\n res +=\"\\r\\n\"\n res += '*'\n s = (haba-x.size)/2\n if (haba-x.size)%2 == 0\n res += ' '*s\n else\n res += ' '*(s+1)\n end\n res += x.chomp\n res += ' '*s\n res +='*'\nend\nres += \"\\r\\n\"\nres += '*'*(haba+2)\nprint res+\"\\r\\n\"\n"}, {"source_code": "input, max = STDIN.read.split(\"\\n\"), 0\ninput.map! { |i| l = i.length; max = l if l > max; [i, l] }\n\nputs '*' * (max + 2)\n\nleft = false\n\ninput.each do |i|\n\tprint '*'\n\tm = (max - i[1])\n\ts = m / 2\n\tif (m % 2).even?\n\t\tprint ' ' * s, i[0], ' ' * s\n\telse\n\t\tl, r = s, s\n\t\tleft ? l += 1 : r += 1\n\t\tprint ' ' * l, i[0], ' ' * r\n\t\tleft = !left\n\tend\n\tputs '*'\nend\n\nputs '*' * (max + 2)\n"}], "src_uid": "a017393743ae70a4d8a9d9dc40410653"} {"source_code": "#!/usr/bin/ruby2.0\n\nn, s = STDIN.readline.split.collect {|s| s.to_i }\ns *= 100\nbest = -1\nn.times do\n\td, c = STDIN.readline.split.collect {|s| s.to_i }\n\tchange = s - (d*100 + c)\n\tbest = [best, change%100].max if change >= 0\nend\nputs best\n\n", "positive_code": [{"source_code": "\n(n, s) = gets.chomp.split.map(&:to_i);\nmax = -1\nn.times do |x|\n (x, y) = gets.chomp.split.map(&:to_i);\n if (s - x) * 100 >= y \n max = [max, (100 - y) % 100].max\n end\nend\nputs max;\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\nmax = -1\nn.times do\n x, y = gets.split.map(&:to_i)\n if (s - x) * 100 >= y \n max = [max, (100 - y) % 100].max\n end\nend\nputs max\n"}, {"source_code": "x = gets.split.map(&:to_i)\n\na = []\nfor i in 0...x[0]\n b = gets.split.map(&:to_i)\n a << 100 - b[1] if x[1] > b[0] and b[1] > 0\n a << 0 if x[1] >= b[0] and b[1] == 0\nend\n\nputs a.size > 0 ? a.max : -1"}, {"source_code": "class Pair\n attr_accessor :first, :second\n\n def initialize(f, s)\n @first = f\n @second = s\n end\n\n def <=(y)\n return @first < y.first || (@first == y.first && @second <= y.second)\n end\n\n def -(y)\n if y.second == 0\n 0\n else\n 100 - y.second\n end\n end\nend\n\nn, s = gets.split.map{|c| c.to_i}\n\na = Pair.new(s, 0)\n\narr = []\n\nn.times{ arr.push(Pair.new(*gets.split.map{|c| c.to_i})) }\n\nmx = -1\n\narr.each do |p|\n mx = [mx, a - p].max if p <= a\nend\n\nputs mx\n"}, {"source_code": "n, s = gets.chomp.split(' ').map(&:to_i)\n\ns *= 100\nres = -1\nn.times do\n x, y = gets.chomp.split(' ').map(&:to_i)\n cost = 100*x + y\n #(1..(s/cost).to_i).each do |kg|\n total = cost # * kg\n if s >= total \n ost = (100-(total % 100)) % 100\n res = [res, ost].max\n end\n #end\nend\n\nputs res"}, {"source_code": "#!/usr/bin/env ruby\n# coding: utf-8\n\n# $stdin = File.new('rf','r')\n\nn, s = readline.chomp.split(' ').map(&:to_i)\nx, y = [], []\nn.times { |i| x[i], y[i] = *readline.chomp.split(' ').map(&:to_i) }\n\ncandies = -1\nx.zip(y).each do |dollars, cents|\n next if dollars + cents.fdiv(100) > s\n candies = [candies, -cents % 100].max\nend\nputs candies"}, {"source_code": "n, s = *gets.chomp.split(' ').map(&:to_i)\n\ns *= 100\n\na = Array.new(n) do\n x, y = gets.chomp.split(' ').map(&:to_i)\n x*100 + y\nend\n\ndef solve(a, s)\n a = a.select{|p| p <= s}\n return -1 if a.empty?\n a.map{|x| (s - x)%100 }.max\nend\n\nputs solve(a, s)\n"}, {"source_code": "n,s = gets.split.map(&:to_i)\nmax = -1\nn.times { |_|\n\td,c = gets.split.map(&:to_i)\n\tif s * 100 >= d * 100 + c\n\t\tmax = [max, (100 - c) % 100].max\n\tend\n}\nputs max"}, {"source_code": "n, s = gets.split.map(&:to_i)\nans = -1\nn.times do\n x, y = gets.split.map(&:to_i)\n next if s < x || (s == x && y > 0)\n c = (100 - y) % 100\n ans = [ans, c].max\nend\nputs ans\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\nsweets = 0\ncan_buy = false\nn.times do\n x, y = gets.split.map(&:to_i)\n x += 1 if y > 0\n sweets = 100 - y if s >= x && 100 - y > sweets && y != 0\n can_buy = true if s >= x\nend\nputs can_buy ? sweets : -1\n"}, {"source_code": "def read_next_line\n gets.chomp.split.map(&:to_i)\nend\n\nn, s = read_next_line\nputs (0...n).map { |_| read_next_line }.select { |a| a[0] < s || a[0] == s && a[1] == 0 }.map { |a| (100 - a[1]) % 100 }.max || -1"}, {"source_code": "n, s = gets.chomp.split(\" \").map { |e| e.to_i }\narr = []\n\nn.times {\n arr << gets.chomp.split(\" \").map { |e| e.to_i }\n}\n\narr.select! { |x, y| (x.to_f + y.to_f / 100.0) <= s.to_f }\narr.map! { |x, y| \n if y == 0\n [x, y] \n else\n [x, 100 - y]\n end\n}\n\nif arr.empty?\n puts \"-1\"\nelse\n arr.sort_by! { |x, y| -y }\n puts arr.first.last\nend\n\n"}, {"source_code": "line = gets\ni, s = line.split.map(&:to_i)\nmin_nu = 10 ** 9\nzero_found = false\ni.times do\n\tline = gets.split\n\tlinetmp = \"#{line[0]}.#{line[1]}\".to_f\n\tnext if linetmp > s\n\tnum = line[1].to_i\n\tmin_nu = num if num < min_nu && num != 0\n\tzero_found = true if num == 0\nend\nif min_nu == 10 ** 9 and zero_found\n\tputs \"0\"\nelsif min_nu == 10 ** 9\n\tputs \"-1\"\nelse\n\tputs 100 - min_nu\nend\n"}], "negative_code": [{"source_code": "n, s = gets.chomp.split(\" \").map { |e| e.to_i }\narr = []\n\nn.times {\n arr << gets.chomp.split(\" \").map { |e| e.to_i }\n}\n\narr.select! { |x, y| (x.to_f + y.to_f / 100.0) <= s.to_f }\narr.select! { |x, y| y != 0 }\n\nif arr.empty?\n puts \"-1\"\nelse\n arr.sort_by! { |x, y| y }\n puts 100 - arr.first.last\nend\n"}, {"source_code": "(n, s) = gets.chomp.split.map(&:to_i);\nmax = -1\n(1..n).each do |x|\n (x, y) = gets.chomp.split.map(&:to_i);\n if (x > s || (x == s && y != 0) || y == 0) then\n next;\n end\n max = [max, 100 - y].max;\nend\nputs max;\n"}, {"source_code": "x = gets.split.map(&:to_i)\n\na = []\nfor i in 0...x[0]\n b = gets.split.map(&:to_i)\n a << 100 - b[1] if x[1] > b[0]\nend\n\nputs a.size > 0 ? a.max : -1"}, {"source_code": "x = gets.split.map(&:to_i)\n\na = [0]\nfor i in 0...x[0]\n b = gets.split.map(&:to_i)\n a << ((x[1] / (b[0] + 1)) * (100 - b[1])) if b[1] > 0\nend\n\nputs a.max > 0 ? a.max : -1"}, {"source_code": "x = gets.split.map(&:to_i)\n\na = [0]\nfor i in 0...x[0]\n b = gets.split.map(&:to_i)\n a << ((x[1] / (b[0] + 1)) * (100 - b[1])) if b[1] > 0\nend\n\nputs a.max"}, {"source_code": "x = gets.split.map(&:to_i)\n\na = []\nfor i in 0...x[0]\n b = gets.split.map(&:to_i)\n a << 100 - b[1] if x[1] > b[0] and b[1] > 0\nend\n\nputs a.size > 0 ? a.max : -1"}, {"source_code": "n, s = gets.chomp.split(' ').map(&:to_i)\n\nres = -1\nn.times do\n x, y = gets.chomp.split(' ').map(&:to_i)\n cost = x + 0.01 * y\n (1..(s/cost).to_i).each do |kg|\n total = cost * kg\n if s >= total && y > 0\n res = [res, 100-y].max\n end\n end\nend\n\nputs res"}, {"source_code": "n, s = gets.chomp.split(' ').map(&:to_i)\n\nres = -1\nn.times do\n x, y = gets.chomp.split(' ').map(&:to_i)\n cost = x + 0.01 * y\n (1..(s/cost).to_i).each do |kg|\n total = cost * kg\n total_y = (y * kg) % 100\n if s >= total && total_y > 0\n res = [res, 100-total_y].max\n end\n end\nend\n\nputs res"}, {"source_code": "n, s = gets.chomp.split(' ').map(&:to_i)\n\ns *= 100\nres = -1\nn.times do\n x, y = gets.chomp.split(' ').map(&:to_i)\n cost = 100*x + y\n (1..(s/cost).to_i).each do |kg|\n total = cost * kg\n if s >= total\n ost = total % 100 > 0 ? 100-(total % 100) : 0\n res = [res, ost].max\n end\n end\nend\n\nputs res"}, {"source_code": "n, s = gets.chomp.split(' ').map(&:to_i)\n\ns *= 100\nres = -1\nn.times do\n x, y = gets.chomp.split(' ').map(&:to_i)\n cost = 100*x + y\n (1..(s/cost).to_i).each do |kg|\n total = cost * kg\n if s >= total && total % 100 > 0\n res = [res, 100-(total % 100)].max\n end\n end\nend\n\nputs res"}, {"source_code": "n, s = gets.chomp.split(' ').map(&:to_i)\n\nres = -1\nn.times do\n x, y = gets.chomp.split(' ').map(&:to_i)\n cost = x + 0.01 * y\n if s >= cost && y > 0\n res = [res, 100-y].max\n end\nend\n\nputs res"}, {"source_code": "n, s = gets.chomp.split(' ').map(&:to_i)\n\ns *= 100\nres = -1\nn.times do\n x, y = gets.chomp.split(' ').map(&:to_i)\n cost = 100*x + y\n (1..(s/cost).to_i).each do |kg|\n total = cost * kg\n if s >= total\n #ost = total % 100 > 0 ? 100-(total % 100) : 0\n ost = (100-(total % 100)) % 100\n res = [res, ost].max\n end\n end\nend\n\nputs res"}, {"source_code": "n, s = gets.split.map(&:to_i)\nsweets = 0\ncan_buy = false\nn.times do\n x, y = gets.split.map(&:to_i)\n sweets = 100 - y if s >= x && 100 - y > sweets && y != 0\n can_buy = true if s >= x\nend\nputs can_buy ? sweets : -1\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\nsweets = -1\nn.times do\n x, y = gets.split.map(&:to_i)\n next if s < x || (s == x && y > 0)\n sweets = 100 - y if 100 - y > sweets && y != 0\nend\nputs sweets\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\nsweets = 0\nn.times do\n x, y = gets.split.map(&:to_i)\n sweets = 100 - y if x < s && 100 - y > sweets && y != 0\nend\nputs sweets == 0 ? -1 : sweets\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\nsweets = 0\ncan_buy = false\nn.times do\n x, y = gets.split.map(&:to_i)\n sweets = 100 - y if s > x && 100 - y > sweets && y != 0\n can_buy = true if s > x\nend\nputs can_buy ? sweets : -1\n"}, {"source_code": "line = gets\ni, s = line.split.map(&:to_i)\nmin_nu = 10 ** 9\nzero_found = false\ni.times do\n\tline = gets.split\n\tlinetmp = \"#{line[0]}.#{line[1]}\".to_f\n\tnext if linetmp > s\n\tnum = line[1].to_i\n\tmin_nu = num if num < min_nu && num != 0\n\tzero_found = true if num == 0\nend\nif min_nu == 10 ** 9 and zero_found\n\tputs \"0\"\nelsif min_nu == 10 ** 9\n\tputs \"-1\"\nelse\n\tputs min_nu\nend\n"}, {"source_code": "line = gets\ni, s = line.split.map(&:to_i)\nmin_nu = -1\ni.times do\n\tline = gets.split\n\tline = \"#{line[0]}.#{line[1]}\".to_f\n\tnext if line > s\n\tnum = s - line\n\tnum = (\"0.\" + num.to_s.split(\".\")[1]).to_f\n\t# puts num\n\tmin_nu = num if num > min_nu && num >= 0\nend\nif min_nu != -1\n\tmin_nu = min_nu.to_s.gsub!(/0\\./, \"\")\n\tmin_nu += \"0\" if min_nu.size == 1 && min_nu != \"0\"\nend\nputs min_nu\n"}, {"source_code": "line = gets\ni, s = line.split.map(&:to_i)\nmin_nu = -1\ni.times do\n\tline = gets.split\n\tline = \"#{line[0]}.#{line[1]}\".to_f\n\tnext if line > s\n\tnum = s - line\n\tnum = (\"0.\" + num.to_s.split(\".\")[1]).to_f\n\t# puts num\n\tmin_nu = num if num > min_nu && num > 0\nend\nif min_nu != -1\n\tmin_nu = min_nu.to_s.gsub!(/0\\./, \"\")\n\tmin_nu += \"0\" if min_nu.size == 1\nend\nputs min_nu\n"}], "src_uid": "91be5db48b44a44adff4c809ffbb8e3e"} {"source_code": "t = gets.chomp.to_i\n\nuntil t==0\n t-=1\n x = gets.split.map(&:to_i)\n puts(\"#{x[1]} #{x[2]} #{x[2]}\")\nend", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n a, b, c, d = gets.split.map(&:to_i)\n x = a\n y = c\n z = c\n puts \"#{x} #{y} #{z}\"\nend\n"}, {"source_code": "1.upto(gets.to_i) do\n a, b, c, d = gets.split(' ').map(&:to_i)\n\n puts \"#{b} #{c} #{[d, b + c - 1].min}\"\nend\n"}, {"source_code": "(1).upto(gets.to_i) do\n a=gets.split(' ')\n puts a[1]+\" \"+a[2]+\" \"+a[2]\nend"}, {"source_code": "t=gets.to_i\n(1).upto(t) do\n a = gets.split(' ')\n puts \"#{a[1]} #{a[2]} #{a[2]}\"\nend\n"}, {"source_code": "def valid?(a,b,c)\n # puts \"#{a} #{b} #{c} -> #{((a+b)>c) && ((a+c)>b) && ((b+c)>a)}\"\n ((a+b)>c) && ((a+c)>b) && ((b+c)>a)\nend\n\nt = gets.chomp.to_i\nt.times do\n a, b, c, d = gets.chomp.split.map(&:to_i)\n\n if(a>b)\n x=a\n else\n x=b\n end\n\n if(b>c)\n y=b\n else\n y=c\n end\n\n if(ca[2])\n puts \"#{a[1]} #{a[1]} #{a[2]}\"\n else\n puts \"#{a[2]} #{a[2]} #{a[3]}\"\n end\n\nend\n"}], "src_uid": "821d48c9a67d37ad7acc50d4d0d0d723"} {"source_code": "input = STDIN.read.split(\"\\n\"); input.shift\n\nx, y = [], []\ninput.each.with_index {|v, i| y.push i if v =~ /[*]/ }\n\ninput[0].length.times do |i|\n\tinput.each do |v|\n\t\tif v[i] == '*'\n\t\t\tx.push i\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nx, y = (x.first..x.last), (y.first..y.last)\n\ny.each {|i| puts input[i][x]}", "positive_code": [{"source_code": "st = gets.split\nn = st[0].to_i\nm = st[1].to_i\n\nstr = []\nmaxn = -1\nminn = 51\nmaxm = -1\nminm = 51\nn.times do |i|\n str << gets.chomp\n if k = str[i].index(\"*\")\n q = str[i].rindex(\"*\")\n if q > maxm then\n maxm = q\n end\n if k < minm then\n minm = k\n end\n if i < minn then\n minn = i\n end\n if i > maxn then\n maxn = i\n end\n end\nend\n\nresult = []\nn.times do |i|\n if i >= minn && i <= maxn then\n a = str[i][minm..maxm]\n result << a\n end\nend\n\nresult.size.times do |i|\n puts result[i]\nend"}, {"source_code": "ns,ms = gets.chomp.split(/ /)\nn = ns.to_i\nm = ms.to_i\nar = Array.new(n)\nfor i in 0..n-1\n\tar[i] = gets.chomp\nend\n\nx1 = m-1\nx2 = 0\ny1 = -1\ny2 = -1\nfor i in 0..n-1\n\twx1 = ar[i].index(\"*\") \n\tx1 = [x1, wx1].min if wx1 != nil\n\twx2 = ar[i].rindex(\"*\") \n\tx2 = [x2, wx2].max if wx2 != nil\n\tif wx1 != nil && y1 == -1\n\t\ty1 = i\n\tend\n\ty2 = i if wx1 != nil \nend\nfor i in y1..y2\n\tputs ar[i].slice(x1..x2)\nend"}, {"source_code": "input=gets.split.map(&:to_i)\nmap=[]\nfor i in 0..input[0]-1\n map.push(gets.split[0])\nend\nsx=0\nstr=\"\"\nfor i in 0..input[1]-1\n str+=\".\"\nend\nfor i in 0..input[0]-1\n if map[i]==str then\n sx=i+1\n else\n break\n end\nend\nex=input[0]-1\n(input[0]-1).downto(0){|i|\n if map[i]==str then\n ex=i-1\n else\n break\n end\n}\n\nsy=0\ney=input[1]-1\nfor i in 0..input[1]-1\n ok=1\n for j in 0..input[0]-1\n if map[j][i]==\"*\" then\n ok=false\n break\n end\n end\n if ok then\n sy=i+1\n else\n break\n end\nend\n\n(input[1]-1).downto(0){|i|\n ok=1\n for j in 0..input[0]-1\n if map[j][i]==\"*\" then\n ok=false\n break\n end\n end\n if ok then\n ey=i-1\n else\n break\n end\n}\n\n\n\n\nsx.upto(ex){|i|\n puts map[i][sy..ey]\n}\n"}, {"source_code": "n,m=gets.chomp!.split(\" \").map(&:to_i)\n\ng,f,l,b=[],[0,m-1],[0,0],false\n\nn.times{|i|\n\n g<l[1] then l[1]=c end\n\n end\n\n}\n\ng[f[0]..l[0]].each{|s|puts s[f[1]..l[1]]}\n\n"}, {"source_code": "height,width = gets.split.map(&:to_i)\ndata = Array.new\nrange = Array.new(4,0)\nrange[0] = height\nrange[1] = width\nheight.times do |h|\n data[h] = gets.chomp\n width.times do |w|\n if(data[h][w,1] == \"*\") then\n if h < range[0] then range[0] = h end\n if h > range[2] then range[2] = h end\n if w < range[1] then range[1] = w end\n if w > range[3] then range[3] = w end\n end\n end\nend\n#p range\nfor h in range[0]..range[2] do\n puts data[h][range[1]..range[3]]\nend\n\n"}, {"source_code": "n, m = gets.split.map &:to_i\na = gets(p).split(\"\\n\")\n\nt, d = -1, -1\nl, r = m + 1, -1\na.size.times do |i| \n pos = a[i] =~ /\\*/\n pos = m if pos == nil\n \n l = [l, pos].min\n \n if pos < m\n t = i if t == -1\n d = i\n end\n \n rpos = a[i] =~ /\\.+\\z/\n rpos = m if rpos == nil\n r = [r, rpos].max\nend\n\na = a[t..d].map { |s| s[l...r] }\nputs a * \"\\n\""}, {"source_code": "s = gets.split(\" \").map { |e| e.to_i }\nstr = Array.new(0)\nfor i in 0..s[0]-1 do \n str.push(gets)\nend\nxcord = Array.new(0)\nycord = Array.new(0)\nfor i in 0..s[0]-1 do \n k = str[i].count(\"*\")\n if k > 0 then\n xcord.push(i)\n end\n for j in 0..s[1]-1 do \n if str[i][j] == '*' then\n ycord.push(j)\n end\n end\nend\n\nfor i in xcord.min..xcord.max do \n for j in ycord.min..ycord.max do \n print str[i][j]\n end\n puts \nend\n"}, {"source_code": "n,m=gets.chomp!.split(\" \").map(&:to_i)\ng,f,l,b=[],[0,m-1],[0,0],false\nn.times{|i|\n g<l[1] then l[1]=c end\n end\n}\ng[f[0]..l[0]].each{|s|puts s[f[1]..l[1]]}\n"}, {"source_code": "require 'set'\n\nn, m = gets.chomp!.split.map(&:to_i)\ngrid = []\nindexes = []\nn.times do |index|\n\trow = gets.chomp!\n\tgrid << row\n\tindexes << index if (re = /[*]/) =~ row\nend\n\nwidth = Set.new\nrow_start, row_end = indexes.min, indexes.max\nm.times do |col|\n\t(row_start..row_end).each do |row|\n\t\t(width << col and break) if grid[row][col] == \"*\"\n\tend\nend\n\nstart_index, end_index = width.min, width.max\n(row_start..row_end).each do |row|\n\tputs grid[row][start_index..end_index]\nend"}, {"source_code": "n,m = gets.split.map(&:to_i)\nmat = []\nn.times{mat = mat << gets }\nx,a,y,b= m,n,0,0\nfor i in 0...n\n a = i if mat[i].count('.') != m && i < a ;b = i if mat[i].count('.') != m && i > b\nend\nfor i in 0...m do\n cnt = 0\n for j in 0...n do\n cnt += 1 if mat[j][i,1] == '.'\n end\n x = i if cnt != n && x > i ;y = i if cnt != n && y < i\nend\nfor i in a..b do\n puts mat[i][x..y]\nend"}, {"source_code": "n,m = gets.split.map{|str| str.to_i}\nflats = []\nn.times{\n flats = flats << gets\n}\n\nx1,y1,x2,y2= m,n,0,0\n#puts flats[0]\nfor i in 0...n\n y1 = i if flats[i].count('.') != m && i < y1\n y2 = i if flats[i].count(\".\") != m && i > y2\nend\n\nfor i in 0...m do\n cnt = 0\n for j in 0...n do\n cnt += 1 if flats[j][i,1] == '.'\n end\n x1 = i if cnt != n && x1 > i\n x2 = i if cnt != n && x2 < i\nend\n#puts \"#{y1},#{y2},#{x1},#{x2}\"\nfor i in y1..y2 do\n puts flats[i][x1..x2]\nend\n"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\ns = Array.new(n)\nn.times{|i| s[i] = gets.chomp }\nup, low, left, right = 0, n-1, m-1, m-1\n(0...n).each do |i|\n if s[i].include?(\"*\")\n up = i\n break\n end\nend\n(n-1).downto(0).each do |i|\n if s[i].include?(\"*\")\n low = i\n break\n end\nend\n(0...n).each do |i|\n if s[i].index(\"*\") and s[i].index(\"*\")left\n left = s[i].index(\"*\")\n end\nend\n(0...n).each do |i|\n if s[i].index(\"*\") and s[i].reverse.index(\"*\")= 0 && n % 3 == 0\n puts 'YES'\n else\n puts 'NO'\n end\nend\n", "positive_code": [{"source_code": "def solve\n\ta, b, c, n = gets.split.map(&:to_i)\n\tsum = a+b+c+n\n\treturn \"NO\" if sum % 3 != 0\n\tavg = sum / 3\n\n\treturn \"NO\" if [a, b, c].max > avg\n\treturn \"YES\"\nend\n\ngets.to_i.times do\n\tputs solve\nend\n"}, {"source_code": "gets.to_i.times {\n a, b, c, n = gets.split.map { |v| v.to_i }\n total = a + b + c + n\n\n if (a >= b) and (a >= c)\n m = a\n elsif (b >= a) and (b >= c)\n m = b\n else\n m = c\n end\n\n d = 3 * m - a - b - c\n if (total % 3 == 0) and (n >= d)\n puts \"YES\"\n else\n puts \"NO\"\n end \n}\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nsets = gets.to_i\nsets.times {\n a, b, c, n = gets.split.map(&:to_i)\n pick_max = [a, b, c].max\n fillups = (pick_max - a) + (pick_max - b) + (pick_max - c)\n remains = n - fillups\n\n if remains >= 0\n puts \"YES\" if remains % 3 == 0\n puts \"NO\" if remains % 3 != 0\n else\n puts \"NO\"\n end\n}"}, {"source_code": "def getline\n return gets.split.map(&:to_i)\nend\nt=gets.to_i\nt.times do |i|\n a, b, c, n = getline()\n s = [a,b,c].sort!\n a, b, c = s[2], s[1], s[0]\n d = a-b+a-c\n if d <= n and (n-d) % 3 == 0 then\n print \"YES\\n\"\n else\n print \"NO\\n\"\n end\nend"}, {"source_code": "t = gets.to_i\n\n1.upto(t) do\n a, b, c, n = gets.split(' ').map(&:to_i)\n\n eql = [a, b, c].inject(0) { |sum, x| sum + [a, b, c].max - x }\n\n puts (n - eql).modulo(3).zero? && (n >= eql) ? 'YES' : 'NO'\nend\n"}], "negative_code": [{"source_code": "T = gets.to_i\n\nT.times do\n a, b, c, n = gets.split.map(&:to_i)\n\n max = [a, b, c].max\n\n [a, b, c].each do |v|\n n -= max - v\n end\n\n if n % 3 == 0\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "gets.to_i.times {\n a, b, c, n = gets.split.map { |v| v.to_i }\n total = a + b + c + n\n if a > b and a > c\n m = a\n elsif b > a and b > c\n m = b\n else\n m = c\n end\n d = 3 * m - a - b - c\n if total % 3 == 0 and n >= d\n puts \"YES\"\n else\n puts \"NO\"\n end \n}\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nsets = gets.to_i\nsets.times {\n a, b, c, n = gets.split.map(&:to_i)\n pick_max = [a, b, c].max\n fillups = (pick_max - a) + (pick_max - b) + (pick_max - c)\n remains = n - fillups\n\n puts \"YES\" if remains % 3 == 0\n puts \"NO\" if remains % 3 != 0\n}"}, {"source_code": "t = gets.to_i\n\n1.upto(t) do\n a, b, c, n = gets.split(' ').map(&:to_i)\n\n puts (n - [a, b, c].inject(0) { |sum, x| sum + [a, b, c].max - x }).modulo(3).zero? ? 'YES' : 'NO'\nend\n"}], "src_uid": "bc5fb5d6882b86d83e5c86f21d806a52"} {"source_code": "n = gets.chomp.to_i\n\nfor i in (0...n)\n puts gets.chomp\nend", "positive_code": [{"source_code": "t=gets.to_i\nfor x in 1..t\nputs gets\nend\n"}, {"source_code": "1.upto(gets.to_i)do puts gets end"}, {"source_code": "t=gets.to_i\nfor i in 1..t do\n\tn=gets.to_i\n\tputs n\nend"}, {"source_code": "gets.to_i.times {\n puts gets\n}\n"}, {"source_code": "gets.to_i.times do\n puts gets.to_i\nend\n"}, {"source_code": "# coding: utf-8\n\n# \uc0c9\uc758 \uac1c\uc218\uac00 \uc544\ub2c8\ub77c 1\uc758 \ud06c\uae30\ub97c \uac00\uc9c4 \ub2e4\uc774\uc544\ubaac\ub4dc\ub85c,\n# \ud604\uc7ac n \uae38\uc774\uc758 \ub3c4\ud615(\ubb38\uc81c\uc758 \uc774\ubbf8\uc9c0\ub97c \ucc38\uace0)\ub97c \uba54\uafc0 \uc218 \uc788\ub290\ub0d0\ub97c \ubb3b\ub294 \ubb38\uc81c\n# \uadf8 \uacbd\uc6b0\uc758 \uc218! (partitioning, not coloring)\n\nt = gets.to_i\nt.times {\n n = gets.to_i\n puts n\n}"}, {"source_code": "1.upto(gets.chomp.to_i) do |tt|\n n = gets.chomp.to_i\n puts n\nend\n"}, {"source_code": "n = gets.to_i\n\nn.times do\n t = gets.to_i\n puts t\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n puts n\nend\n"}, {"source_code": "1.upto(gets.to_i) { puts gets }\n"}], "negative_code": [{"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n puts (n >= 2) ? 2 : 1\nend\n"}, {"source_code": "1.upto(gets.to_i) do\n puts gets.to_i > 1 ? 2 : 1\nend\n"}], "src_uid": "740c05c036b646d8fb6b391af115d7f0"} {"source_code": "t = gets.to_i\r\nans = []\r\nt.times do\r\n n,x = gets.chomp.split(\" \").map(&:to_i)\r\n a = gets.chomp.split(\" \").map(&:to_i)\r\n min = (a.sum + x - 1) / x\r\n max = 0\r\n a.each do |v|\r\n max += (v + x - 1) / x\r\n end\r\n ans << [min,max]\r\nend\r\nans.each do |v|\r\n puts v.join(\" \")\r\nend", "positive_code": [{"source_code": "def method(v, x) \r\n v / x + (v % x != 0 ? 1 : 0)\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n n, x = gets.split.map { |x| x.to_i }\r\n a = gets.split.map { |x| x.to_i }\r\n puts \"#{method(a.sum, x)} #{a.map { |v| method(v, x) }.sum}\"\r\nend"}, {"source_code": "def method(v, x) \r\n v / x + (v % x != 0 ? 1 : 0)\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n n, x = gets.split.map {|x| x.to_i }\r\n a = gets.split.map {|x| x.to_i }\r\n puts \"#{method(a.sum, x)} #{a.map { |v| method(v, x) }.sum}\"\r\nend"}, {"source_code": "a = gets.to_i\r\nfor i in 1..a do\r\n c = gets.chop.split(/ /).map(&:to_i)\r\n w = c[0]\r\n h = c[1].to_f\r\n b = gets.chop\r\n c = b.split(/ /).map(&:to_i)\r\n x = c.inject(0){|n, m| n + m}\r\n x = x / h\r\n x = x.ceil\r\n l = 0\r\n for i in 0..w-1 do\r\n q = c[i] / h\r\n q = q.ceil\r\n l += q\r\n end\r\n print x, \" \", l, \"\\n\"\r\nend"}, {"source_code": "#!/usr/bin/env ruby\r\n\r\ngets.to_i.times {\r\n n, x = gets.split.map &:to_i\r\n nums = gets.split.map &:to_i\r\n max = nums.map{|num| (num.to_f / x).ceil }.sum\r\n min = (nums.sum.to_f / x).ceil\r\n puts \"#{min} #{max}\"\r\n}"}, {"source_code": "def read\r\n gets.split.map &:to_i\r\nend\r\ngets.to_i.times do\r\n _, x = read\r\n a = read\r\n print (a.sum + x - 1) / x, \" \", a.map { |it| (it + x - 1) / x }.sum, \"\\n\"\r\nend"}, {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n, x = gets.chomp.split(\" \").map(&:to_i)\r\n a = gets.chomp.split(\" \").map(&:to_i)\r\n max = 0\r\n ans = 0\r\n a.each do |i|\r\n max += (i/x.to_f).ceil\r\n ans += i\r\n end\r\n min = (ans/x.to_f).ceil\r\n print \"#{min}\" + \" \" + \"#{max}\" + \"\\n\"\r\nend"}, {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n, x = gets.chomp.split(' ').map(&:to_i)\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n min = 0\r\n max = 0\r\n ind = 0\r\n sum = 0\r\n while ind < arr.size\r\n sum += arr[ind]\r\n max += (1.0 * arr[ind] / x).ceil\r\n ind += 1\r\n end\r\n min += (1.0 * sum / x).ceil\r\n puts [min, max].join ' '\r\nend"}], "negative_code": [], "src_uid": "b36d7f840abe998185a988fe8dd2ec75"} {"source_code": "n = gets.to_i\nputs n == 1 ? \"-1\" : \"#{n} #{n + 1} #{n * (n + 1)}\"\n", "positive_code": [{"source_code": "n = gets.to_i\nputs n == 1 ? -1 : [ n , n + 1, n * ( n + 1 ) ].join( ' ' )\n"}, {"source_code": "n=gets.to_i;puts n==1 ? -1 : [n,-~n,n*-~n]*' '"}, {"source_code": "n = gets.chomp.to_i;\nprint n==1? -1 : [n,(n+1),(n+1)*n].join(\" \")\n"}, {"source_code": "n=gets.to_i\nif n==1\n puts -1\nelse\n puts [n, n+1, n*(n+1)]*' '\nend\n"}, {"source_code": "n=gets.to_i;puts n==1?-1:[n,-~n,n*-~n]*' '"}, {"source_code": "$, = \" \"\nn = gets.to_i\nif n == 1\n puts -1\nelse\n print n, n + 1, n * (n + 1), \"\\n\"\nend"}, {"source_code": "n = gets.strip.to_i\nputs -1 if n == 1\nputs [n, n+1, n*n+n].map(&:to_s).join(' ') if n != 1"}], "negative_code": [{"source_code": "n=gets.to_i;puts n==1 ? -1 : [n,n+1,n*-~n/2]*' '"}], "src_uid": "f60ea0f2caaec16894e84ba87f90c061"} {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nn = inp[0]\na = inp\nt = []\na.size.times do |i|\n t[i] = [a[i],i]\nend\nt.sort!.reverse!\nans = 0\nanst = []\nn.times do |i|\n ans += 1\n ans += t[i][0]*i\n anst.push(t[i][1]+1)\nend\np ans\nputs anst.join(\" \")\n"}], "negative_code": [], "src_uid": "c79f25dab583edfcabb6991be7abf971"} {"source_code": "def gen_matrix(n, seed = nil)\n m = n.times.map { [-1] * n }\n seed ||= n\n srand(seed)\n pool = 1.upto(n * n).map {|i| i}.shuffle\n\n 0.upto(n - 1) do |i|\n 0.upto(n - 1) do |j|\n upper = ((i >= 1) ? m[i - 1][j] : -1)\n left = ((j >= 1) ? m[i][j - 1] : -1)\n x = pool.pop\n retry_count = 5\n while ((x - upper).abs == 1 || (x - left).abs == 1) && retry_count > 0\n retry_count -= 1\n pool.push(x)\n pool.shuffle!\n x = pool.pop\n end\n if retry_count == 0\n return gen_matrix(n, seed + 1)\n end\n m[i][j] = x\n end\n end\n return m\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n if n == 2\n printf(\"-1\\n\")\n next\n end\n m = gen_matrix(n, n)\n m.each {|row| printf(\"%s\\n\", row.join(\" \")) }\nend\n", "positive_code": [{"source_code": "gets.to_i.times {\n n = gets.to_i\n\n if n == 2\n p -1\n next\n end\n\n m = Array.new(n) { [0] * n }\n\n cur = 1\n n.times { |i|\n n.times { |j|\n next if (i & 1) != (j & 1)\n m[i][j] = cur\n cur += 1\n }\n }\n n.times { |i|\n n.times { |j|\n next if (i & 1) == (j & 1)\n m[i][j] = cur\n cur += 1\n }\n }\n\n n.times { |i|\n puts m[i].join(' ')\n }\n}\n"}, {"source_code": "t = Integer(gets.chomp)\r\nt.times{\r\n n = Integer(gets.chomp)\r\n \r\n if(n==2)\r\n puts -1\r\n else\r\n ev = 1\r\n od = n%2 == 0 ? (n*n)/2 + 1 : ((n*n)+1)/2 + 1\r\n for i in 0...n do\r\n for j in 0...n do\r\n if((i+j)%2 == 0)\r\n print \"#{ev} \"\r\n ev += 1\r\n else\r\n print \"#{od} \"\r\n od += 1\r\n end\r\n end\r\n print \"\\n\"\r\n end\r\n end\r\n}"}], "negative_code": [{"source_code": "def gen_matrix(n, seed = nil)\n m = n.times.map { [-1] * n }\n seed ||= n\n srand(seed)\n pool = 1.upto(n * n).map {|i| i}.shuffle\n\n 0.upto(n - 1) do |i|\n 0.upto(n - 1) do |j|\n upper = ((i >= 1) ? m[i - 1][j] : -1)\n left = ((j >= 1) ? m[i][j - 1] : -1)\n x = pool.pop\n retry_count = 5\n while (x - upper).abs == 1 || (x - left).abs == 1 && retry_count > 0\n retry_count -= 1\n pool.push(x)\n pool.shuffle!\n x = pool.pop\n end\n if retry_count == 0\n return gen_matrix(n, seed + 1)\n end\n m[i][j] = x\n end\n end\n return m\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n if n == 2\n printf(\"-1\\n\")\n next\n end\n m = gen_matrix(n, n)\n m.each {|row| printf(\"%s\\n\", row.join(\" \")) }\nend\n"}, {"source_code": "def gen_matrix(n)\n m = n.times.map { [-1] * n }\n pool = 1.upto(n * n).map {|i| i}.shuffle\n\n 0.upto(n - 1) do |i|\n 0.upto(n - 1) do |j|\n upper = i >= 1 ? m[i - 1][j] : -1\n left = j >= 1 ? m[i][j - i] : -1\n x = pool.pop\n return gen_matrix(n) if (x - upper).abs == 1 || (x - left).abs == 1\n m[i][j] = x\n end\n end\n return m\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n if n == 2\n printf(\"-1\\n\")\n next\n end\n m = gen_matrix(n)\n m.each {|row| printf(\"%s\\n\", row.join(\" \")) }\nend\n"}, {"source_code": "def gen_matrix(n)\n m = n.times.map { [0] * n }\n srand(n)\n pool = 1.upto(n * n).map {|i| i}.shuffle\n\n 0.upto(n - 1) do |i|\n 0.upto(n - 1) do |j|\n upper = i >= 1 ? m[i - 1][j] : -1\n left = j >= 1 ? m[i][j - i] : -1\n\n x = pool.shift\n while (x - upper).abs == 1 || (x - left).abs == 1\n pool.push(x)\n x = pool.shift\n end\n m[i][j] = x\n end\n end\n return m\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n if n == 2\n printf(\"-1\\n\")\n next\n end\n m = gen_matrix(n)\n m.each {|row| printf(\"%s\\n\", row.join(\" \")) }\nend\n"}, {"source_code": "t = Integer(gets.chomp)\r\nt.times{\r\n n = Integer(gets.chomp)\r\n \r\n if(n==2)\r\n puts -1\r\n else\r\n ev = 1\r\n od = n%2 == 0 ? (n*n)/2 : ((n*n)+1)/2 + 1\r\n for i in 0...n do\r\n for j in 0...n do\r\n if((i+j)%2 == 0)\r\n print \"#{ev} \"\r\n ev += 1\r\n else\r\n print \"#{od} \"\r\n od += 1\r\n end\r\n end\r\n print \"\\n\"\r\n end\r\n end\r\n}"}], "src_uid": "e215e94dd196dde381adc13406d2d72a"} {"source_code": "\ufeffclass Array\r\n def n\r\n return length\r\n end\r\nend\r\n\r\n$__cur_readed = []\r\n$__cur_index = 0\r\n\r\ndef rs\r\n\twhile $__cur_index >= $__cur_readed.length\r\n\t\t$__cur_readed = gets.split(\" \")\r\n\t\t$__cur_index = 0\r\n\tend\r\n\t$__cur_index+=1\r\n\treturn $__cur_readed[$__cur_index-1]\r\nend\r\n\r\ndef ri\t\r\n\tres = rs.to_i\r\nend\r\n\r\ndef ra2 n\r\n\treturn Array.new(n) {|i| ri}\r\nend\r\n\r\ndef ra\r\n\treturn ra2 ri\r\nend\r\n\r\nt = ri\r\n\r\nfor _ in (1..t)\r\n\ta = ra\r\n\tres = 0\r\n\tfor i in (0..a.n-1)\r\n\t\tfor j in (i..a.n-1)\r\n\t\t\tfor k in (i..j)\r\n\t\t\t\tres+=1\r\n\t\t\t\tif a[k] == 0\r\n\t\t\t\t\tres +=1\r\n\t\t\t\tend\r\n\t\t\tend\r\n\t\tend\r\n\tend\r\n\tputs res\r\nend", "positive_code": [{"source_code": "gets.to_i.times {\n n = gets.to_i\n xs = gets.split.map(&:to_i).map { _1 > 0 ? 0 : 1 }\n ans = 0\n n.times { |r|\n (r + 1).times { |l|\n ans += r - l + 1\n ans += xs[l..r].sum\n }\n }\n p ans\n}\n"}, {"source_code": "\ufeff$__cur_readed = []\r\n$__cur_index = 0\r\n\r\ndef rs\r\n\twhile $__cur_index >= $__cur_readed.length\r\n\t\t$__cur_readed = gets.split(\" \")\r\n\t\t$__cur_index = 0\r\n\tend\r\n\t$__cur_index+=1\r\n\treturn $__cur_readed[$__cur_index-1]\r\nend\r\n\r\n\r\ndef ri\t\r\n\treturn rs.to_i\r\nend\r\n\r\ndef ra2 n\r\n\treturn Array.new(n) {|i| ri}\r\nend\r\n\r\ndef ra\r\n\treturn ra2 ri\r\nend\r\n\r\nt = ri\r\n\r\nfor _ in (1..t)\r\n\ta = ra\r\n\tres = 0\r\n\tfor i in (0..a.length-1)\r\n\t\tfor j in (i..a.length-1)\r\n\t\t\tfor k in (i..j)\r\n\t\t\t\tres+=1\r\n\t\t\t\tif a[k] == 0\r\n\t\t\t\t\tres +=1\r\n\t\t\t\tend\r\n\t\t\tend\r\n\t\tend\r\n\tend\r\n\tputs res\r\nend"}], "negative_code": [{"source_code": "\ufeff$__cur_readed = []\r\n$__cur_index = 0\r\n\r\ndef rs\r\n\twhile $__cur_index >= $__cur_readed.length\r\n\t\t$__cur_readed = gets.split(\" \")\r\n\t\t$__cur_index = 0\r\n\tend\r\n\t$__cur_index+=1\r\n\treturn $__cur_readed[$__cur_index-1]\r\nend\r\n\r\n\r\ndef ri\t\r\n\treturn rs.to_i\r\nend\r\n\r\ndef ra2 n\r\n\treturn Array.new(n) {|i| ri}\r\nend\r\n\r\ndef ra\r\n\treturn ra2 ri\r\nend\r\n\r\nt = ri\r\n\r\nfor _ in (1..t)\r\n\ta = ra\r\n\tres = 0\r\n\tfor i in (0..a.length-1)\r\n\t\tfor j in (i..a.length-1)\r\n\t\t\tfor k in (i..j)\r\n\t\t\t\tres+=1\r\n\t\t\t\tif a[res] == 0\r\n\t\t\t\t\tres +=1\r\n\t\t\t\tend\r\n\t\t\tend\r\n\t\tend\r\n\tend\r\n\tputs res\r\nend"}], "src_uid": "8775da9b78d8236c4606d150df450952"} {"source_code": "t = gets.to_i\r\nt.times{\r\n\tn = gets.to_i\r\n\tarr = gets.split.map &:to_i\r\n\tif arr == arr.sort then\r\n\t\tp 0\r\n\telsif arr[0] == arr.min || arr.last == arr.max then\r\n\t\tp 1\r\n\telsif arr[0] == arr.max && arr.last == arr.min then\r\n\t\tp 3\r\n\telse\r\n\t\tp 2\r\n\tend\r\n}", "positive_code": [{"source_code": "def f\r\n n = gets.chomp.to_i\r\n a = gets.chomp.split(\" \").map(&:to_i)\r\n\r\n if a.each_with_index.all?{|c, i| c == i + 1}\r\n puts 0\r\n elsif a.first == 1 || a.last == n\r\n puts 1\r\n elsif a.first == n && a.last == 1\r\n puts 3\r\n else\r\n puts 2\r\n end\r\nend\r\n\r\n\r\nt = gets.chomp.to_i\r\nt.times do\r\n f()\r\nend\r\n"}, {"source_code": "t = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }\n sa = a.sort\n already_sorted = true\n a.each_with_index do |x, i|\n if sa[i] != x\n already_sorted = false\n break\n end\n end\n\n if a[0] == sa[-1] && a[-1] == sa[0]\n printf(\"3\\n\")\n elsif sa[0] == a[0] || sa[-1] == a[-1]\n printf(\"%d\\n\", already_sorted ? 0 : 1)\n else\n printf(\"2\\n\")\n end\nend\n"}, {"source_code": "def gli; gets.split.map(&:to_i); end\r\ndef gi; gets.to_i; end\r\n\r\ngi.times do\r\n n = gi\r\n a = gli\r\n if a == (1..n).to_a\r\n puts 0\r\n elsif a[0] == n && a[-1] == 1\r\n puts 3\r\n elsif a[0] == 1 || a[-1] == n\r\n puts 1\r\n else\r\n puts 2\r\n end\r\nend"}], "negative_code": [{"source_code": "def gli; gets.split.map(&:to_i); end\r\ndef gi; gets.to_i; end\r\n\r\ngi.times do\r\n n = gi\r\n a = gli\r\n if a == (1..n).to_a\r\n puts 0\r\n elsif a[0] == 1 || a[-1] == n\r\n puts 1\r\n else\r\n puts 2\r\n end\r\nend"}, {"source_code": "def gli; gets.split.map(&:to_i); end\r\ndef gi; gets.to_i; end\r\n\r\ngi.times do\r\n n = gi\r\n a = gli\r\n if a.sort == (1..n).to_a\r\n puts 0\r\n elsif a[0] == 1 || a[-1] == n\r\n puts 1\r\n else\r\n puts 2\r\n end\r\nend"}, {"source_code": "def gli; gets.split.map(&:to_i); end\r\ndef gi; gets.to_i; end\r\n\r\ngi.times do\r\n _ = gi\r\n a = gli\r\n if a.sort == a\r\n puts 0\r\n elsif a.min == a[0] || a.max == a[-1]\r\n puts 1\r\n else\r\n puts 2\r\n end\r\nend"}, {"source_code": "def f\r\n n = gets.chomp.to_i\r\n a = gets.chomp.split(\" \").map(&:to_i)\r\n\r\n if a.each_with_index.all?{|c, i| c == i + 1}\r\n puts 0\r\n elsif a.first == 1 || a.last == n\r\n puts 1\r\n else\r\n puts 2\r\n end\r\nend\r\n\r\n\r\nt = gets.chomp.to_i\r\nt.times do\r\n f()\r\nend\r\n"}, {"source_code": "t = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }\n sa = a.sort\n already_sorted = true\n a.each_with_index do |x, i|\n if sa[i] != x\n already_sorted = false\n break\n end\n end\n\n if sa[0] == a[0] || sa[-1] == a[-1]\n printf(\"%d\\n\", already_sorted ? 0 : 1)\n else\n printf(\"2\\n\")\n end\nend\n"}, {"source_code": "t = gets.to_i\r\nt.times{\r\n\tn = gets.to_i\r\n\tarr = gets.split.map &:to_i\r\n\tif arr == arr.sort then\r\n\t\tp 0\r\n\telsif arr[0] == arr.min || arr.last == arr.max then\r\n\t\tp 1\r\n\telse\r\n\t\tp 2\r\n\tend\r\n}"}], "src_uid": "c212524cc1ad8e0332693e3cf644854b"} {"source_code": "f=->{gets.split.map &:to_i}\nn,d=f[]\na,b=f[]\nr=(1..n).map{|i|gets(\" \").to_i*a+gets.to_i*b}.zip(1..n).sort_by(&:first).take_while{|i|0<=d-=i[0]}\nputs r.size,r.map(&:last)*\" \"\n", "positive_code": [{"source_code": "f=->{gets.split.map &:to_i}\nn,d=f[]\na,b=f[]\nr=(1..n).map{|i|gets(\" \").to_i*a+gets.to_i*b}.zip(1..n).sort_by(&:first).take_while{|i|0<=d-=i[0]}\nputs r.size,r.map(&:last)*\" \""}, {"source_code": "f=->{gets.split.map &:to_i}\nn,d=f[]\na,b=f[]\nr=(1..n).map{|i|gets(\" \").to_i*a+gets.to_i*b}.zip(1..n).sort_by(&:first).take_while{|i|0<=d-=i[0]}\nputs r.size,r.map(&:last)*\" \"\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\na, b = gets.split.map(&:to_i)\nxys = n.times.map{gets.split.map(&:to_i)}\narray = xys.map.with_index{|(x, y), i| [i, x * a + y * b]}.sort_by(&:last)\ntaken = 0\narray = array.take_while do |i, cost|\n flag = taken + cost <= d\n taken += cost\n flag\nend\nputs array.length\nputs array.map(&:first).map{|i| i + 1}.join(\" \")\n"}, {"source_code": "f=->{gets.split.map &:to_i}\nn,d=f[]\na,b=f[]\nr=(1..n).map{|i|gets(\" \").to_i*a+gets.to_i*b}.zip(1..n).sort_by(&:first).take_while{|i|0<=d-=i[0]}\nputs r.size,r.map(&:last)*\" \"\n"}, {"source_code": "f=->{gets.split.map &:to_i}\nn,d=f[]\na,b=f[]\nr=(1..n).map{|i|gets(\" \").to_i*a+gets.to_i*b}.zip(1..n).sort_by(&:first).take_while{|i|0<=d-=i[0]}\nputs r.size,r.map(&:last)*\" \"\n"}, {"source_code": "f=->{gets.split.map &:to_i}\nn,d=f[]\na,b=f[]\nr=(1..n).map{|i|gets(\" \").to_i*a+gets.to_i*b}.zip(1..n).sort_by(&:first).take_while{|i|0<=d-=i[0]}\nputs r.size,r.map(&:last)*\" \""}, {"source_code": "n,d = gets.split.map(&:to_i)\na,b = gets.split.map(&:to_i)\n\nw = [*$<].map{|i|t1,t2 = i.split.map(&:to_i); t1*a+t2*b}\n\nx = w.zip(1..n).sort_by(&:first)\n\ns = 0\nr = x.take_while{ |i| d >= s += i.first }\nputs r.size\nputs r.map(&:last)*\" \""}, {"source_code": "f=->{gets.split.map &:to_i}\nn,d=f[]\na,b=f[]\nr=(1..n).map{|i|gets(\" \").to_i*a+gets.to_i*b}.zip(1..n).sort_by(&:first).take_while{|i|0<=d-=i[0]}\nputs r.size,r.map(&:last)*\" \"\n"}, {"source_code": "f=->{gets.split.map &:to_i}\nn,d=f[]\na,b=f[]\nr=(1..n).map{|i|gets(\" \").to_i*a+gets.to_i*b}.zip(1..n).sort_by(&:first).take_while{|i|0<=d-=i[0]}\nputs r.size,r.map(&:last)*\" \"\n"}, {"source_code": "f=->{gets.split.map &:to_i}\nn,d=f[]\na,b=f[]\nr=(1..n).map{|i|gets(\" \").to_i*a+gets.to_i*b}.zip(1..n).sort_by(&:first).take_while{|i|0<=d-=i[0]}\nputs r.size,r.map(&:last)*\" \"\n"}, {"source_code": "f=->{gets.split.map &:to_i}\nn,d=f[]\na,b=f[]\nr=(1..n).map{|i|gets(\" \").to_i*a+gets.to_i*b}.zip(1..n).sort_by(&:first).take_while{|i|0<=d-=i[0]}\nputs r.size,r.map(&:last)*\" \"\n"}, {"source_code": "f=->{gets.split.map &:to_i}\nn,d=f[]\na,b=f[]\nr=(1..n).map{|i|gets(\" \").to_i*a+gets.to_i*b}.zip(1..n).sort_by(&:first).take_while{|i|0<=d-=i[0]}\nputs r.size,r.map(&:last)*\" \""}], "negative_code": [{"source_code": "n,d = gets.split.map(&:to_i)\na,b = gets.split.map(&:to_i)\n\nw = [*$<].map{|i|t1,t2 = i.split.map(&:to_i); t1*a+t2*b}\n\nx = w.zip(1..n).sort_by(&:first)\n\ns = 0\nr = x.take_while{ |i| d > s += i.first }\nputs r.size\nputs r.map(&:last)*\" \""}, {"source_code": "$n,$d = gets.split.map(&:to_i)\na,b = gets.split.map(&:to_i)\n\n$w = [*$<].map{|i|t1,t2 = i.split.map(&:to_i); t1*a+t2*b}\n\ndef more i,s,n\n (i...$n).map{ |j|\n next [s,n] if s+$w[j] > $d\n more j+1,s+$w[j],n+[j]\n }.max_by{|i|[i[0],i[1].size]} || [s,n]\nend\n\nr = more 0,0,[]\nputs r[1].size\nputs r[1].map{ |i| i+1 }*\" \"\n"}, {"source_code": "$n,$d = gets.split.map(&:to_i)\na,b = gets.split.map(&:to_i)\n\n$w = [*$<].map{|i|t1,t2 = i.split.map(&:to_i); t1*a+t2*b}\n\ndef more i,s,n\n (i...$n).map{ |j|\n next [s,n] if s+$w[j] > $d\n more j+1,s+$w[j],n+[j]\n }.max_by(&:first) || [s,n]\nend\n\nr = more 0,0,[]\nputs r[1].size\nputs r[1].map{ |i| i+1 }*\" \"\n"}], "src_uid": "4d7de18e76600777ff023e1b61366ee4"} {"source_code": "gets.to_i.times do\n res = 'a' * 200\n puts res\n gets.to_i\n gets.split.map(&:to_i).each do |pos|\n res[pos] = res[pos] == 'a' ? 'b' : 'a'\n puts res\n end\nend", "positive_code": [{"source_code": "require 'set'; require 'prime'; require 'pp'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = gets.chomp.split.map(&:to_i)\n\n s = 'a' * 100\n puts s\n a.each do |num|\n s = s[0, num] + ((s[num].ord + 1 - 97) % 26 + 97).chr * (100 - num)\n puts s\n end\nend\n"}, {"source_code": "def pin(a) \n a.each do |i| \n print((i%26+97).chr) \n end \n puts \"\" \nend\n\n# a = [1,2,3]\n# pin(a)\n\ntc = gets.to_i \n\ntc.times do \n n = gets.to_i \n arr = gets.split.map(&:to_i) \n\n a = Array.new(51) {0} \n pin(a) \n arr.each do |x| \n for i in x...51 \n a[i] += 1 \n end\n pin(a) \n end\nend"}], "negative_code": [{"source_code": "gets.to_i.times do\n res = 'a' * 200\n puts res\n gets.split.map(&:to_i).each do |pos|\n res[pos] = res[pos] == 'a' ? 'b' : 'a'\n puts res\n end\nend"}, {"source_code": "gets.to_i.times do\n res = \"a\" * 200\n puts res\n gets.to_i.times do\n pos = gets.to_i\n res[pos] = res[pos] == 'a' ? 'b' : 'a'\n puts res\n end\nend"}, {"source_code": "gets.to_i.times do\n res = 'a' * 200\n puts res\n gets.split.map(&:to_i).each do |pos|\n pos = gets.to_i\n res[pos] = res[pos] == 'a' ? 'b' : 'a'\n puts res\n end\nend"}], "src_uid": "6983823efdc512f8759203460cd6bb4c"} {"source_code": "num_chars = gets.chomp.to_i\nchars = gets.chomp\n\nalphabets = \"abcdefghijklmnopqrstuvwxyz\"\n\nchar_counts = {};\n\nalphabets.each_char {|c| char_counts[c] = 0;}\n\nchars.each_char do |c|\n char_counts[c] = char_counts[c] + 1;\nend\n\noutput_string = \"\";\n\n\nwhile (output_string.length != num_chars) do\n sorted_array = char_counts.sort_by {|k,v| v}.reverse\n\n \n\n letter_1 = sorted_array[0][0];\n letter_2 = sorted_array[1][0];\n count_1 = sorted_array[0][1];\n count_2 = sorted_array[1][1];\n\n output_string += letter_1 * count_1;\n char_counts[letter_1] = 0;\n\n # if (count_1 > 0) \n # if (count_1 >= count_2 + 1) \n # output_string += \"#{letter_1}#{letter_2}\" * count_2\n # output_string += letter_1\n # char_counts[letter_1] -= count_2 + 1\n # char_counts[letter_2] = 0;\n # elsif (count_1 == count_2) \n # output_string += \"#{letter_1}#{letter_2}\" * count_2\n # char_counts[letter_1] = 0;\n # char_counts[letter_2] = 0;\n # end\n # end\nend\n\n\nputs output_string", "positive_code": [{"source_code": "gets\nputs gets.strip.chars.sort.join"}], "negative_code": [{"source_code": "num_chars = gets.chomp.to_i\nchars = gets.chomp\n\nalphabets = \"abcdefghijklmnopqrstuvwxyz\"\n\nchar_counts = {};\n\nalphabets.each_char {|c| char_counts[c] = 0;}\n\nchars.each_char do |c|\n char_counts[c] = char_counts[c] + 1;\nend\n\noutput_string = \"\";\n\n\nwhile (output_string.length != num_chars) do\n sorted_array = char_counts.sort_by {|k,v| v}.reverse\n\n letter_1 = sorted_array[0][0];\n letter_2 = sorted_array[1][0];\n count_1 = sorted_array[0][1];\n count_2 = sorted_array[1][1];\n\n if (count_1 > 0) \n if (count_1 >= count_2 + 1) \n output_string += \"#{letter_1}#{letter_2}\" * count_2\n output_string += letter_1\n char_counts[letter_1] -= count_2 + 1\n char_counts[letter_2] = 0;\n elsif (count_1 == count_2) \n output_string += \"#{letter_1}#{letter_2}\" * count_2\n char_counts[letter_1] = 0;\n char_counts[letter_2] = 0;\n end\n end\nend\n\n\nputs output_string"}], "src_uid": "8616ede6867c8aacde986a123ec8a921"} {"source_code": "priorities = [[\"rat\"], [\"woman\", \"child\"], [\"man\"], [\"captain\"]]\nn = gets.to_i\npeople = []\nn.times { people << gets }\n\npriorities.each do |statuses|\n people.each do |line|\n name, status = line.split\n puts name if statuses.include?(status)\n end\nend", "positive_code": [{"source_code": "gets p\nputs %w(rat child|woman man captain).map{|_|$_.scan /(.+) (?:#{_})/}\n"}, {"source_code": "a=gets.chomp.to_i\na1=[]\na2=[]\na3=[]\na4=\"\"\na.times do\ntemp=gets.chomp.split(\" \")\nif temp[1]==\"woman\" || temp[1]==\"child\"\na2 << temp[0] \nelsif temp[1]==\"rat\"\na1 << temp[0]\nelsif temp[1]==\"man\"\na3 << temp[0]\nelse\na4=temp[0]\nend\nend\n\nputs a1\nputs a2\nputs a3\nputs a4"}, {"source_code": "gets p\nputs %w(rat child|woman man captain).map{|_|$_.scan /(.+) (?:#{_})/}"}, {"source_code": "s = gets(p)\nputs %w(rat woman|child man captain).map { |x| s.scan(/(.+) (?:#{x})/) }"}, {"source_code": "gets p\nputs %w(rat child|woman man captain).map{|_|$_.scan /(.+) (?:#{_})/}\n"}, {"source_code": "k=['rat','child','man','captain']\nl=[[],[],[],[]]\n1.upto(gets.to_i){m,n=gets.split;k.index(n)==nil ?o=1:o=k.index(n);l[o]< [],\n 'woman_and_child' => [],\n 'man' => [],\n 'captain' => [],\n}\n\n1.upto(gets.to_i) do\n (name, type) = gets.strip.split(/\\s/)\n\n if ['rat', 'man', 'captain'].include?(type)\n members[type].push(name)\n else\n members['woman_and_child'].push(name)\n end\nend\n\nmembers['rat'].each do |name|\n puts name\nend\n\nmembers['woman_and_child'].each do |name|\n puts name\nend\n\nmembers['man'].each do |name|\n puts name\nend\n\nmembers['captain'].each do |name|\n puts name\nend\n"}, {"source_code": "gets p\nputs %w(rat child|woman man captain).map{|_|$_.scan /(.+) (?:#{_})/}\n"}, {"source_code": "members = []\nfor _ in 1..Integer(gets.chomp)\n members << gets.chomp.split\nend\ngrouped = members.inject(Hash.new { |h, k| h[k] = (k == 'child') ? h['woman'] : [] }) { |h, m| h[m[1]] <<= m[0]; h }\n%w(rat woman man captain).map.each { |c| puts grouped[c] }"}, {"source_code": "members = []\nfor _ in 1..Integer(gets.chomp)\n members << gets.chomp.split\nend\ngrouped = members.inject(Hash.new { |h, k| h[k] = (k == 'child') ? h['woman'] : [] }) { |h, m| h[m[1]] <<= m[0]; h }\nputs grouped['rat']\nputs grouped['woman']\nputs grouped['man']\nputs grouped['captain']"}, {"source_code": "members = []\nfor _ in 1..Integer(gets.chomp)\n members << gets.chomp.split\nend\ngrouped = members.inject(Hash.new { |h, k| h[k] = (k == 'child') ? h['woman'] : [] }) { |h, m| h[m[1]] <<= m[0]; h }\n%w(rat woman man captain).each { |c| puts grouped[c] }"}, {"source_code": "class Person\n attr_accessor :name, :priority, :number\n def initialize(name, type, number)\n @name = name\n @number = number\n case type\n when \"rat\"\n @priority = 0\n when \"woman\", \"child\"\n @priority = 1\n when \"man\"\n @priority = 2\n when \"captain\"\n @priority = 3\n end\n end\nend\n\nn = gets.to_i\nh = []\nn.times do |number|\n name = gets(\" \")\n type = gets.chomp\n h.push(Person.new(name, type, number))\nend\n\nh.sort! do |a, b| \n if (a.priority == b.priority)\n a.number <=> b.number\n else\n a.priority <=> b.priority\n end\nend\n\nh.each{|person| puts person.name}\n"}, {"source_code": "gets p\nputs %w(rat child|woman man captain).map{|_|$_.scan /(.+) (?:#{_})/}\n"}, {"source_code": "gets p\nputs %w(rat child|woman man captain).map{|_|$_.scan /(.+) (?:#{_})/}"}, {"source_code": "input = STDIN.read.split(\"\\n\").map {|i| i.split}; input.shift\n\nrt, cw, mn, ca,= [], [], [], []\n\ninput.each do |i|\n\tcase i.last\n\twhen 'captain'\n\t\tca.push i.first\n\twhen 'man'\n\t\tmn.push i.first\n\twhen 'woman'\n\t\tcw.push i.first\n\twhen 'child'\n\t\tcw.push i.first\n\twhen 'rat'\n\t\trt.push i.first\n\tend\nend\n\n[rt, cw, mn, ca].each.each {|i| puts i}"}, {"source_code": "input = STDIN.read.split(\"\\n\").map {|i| i.split}; input.shift\n\nrt, cw, mn, ca,= [], [], [], []\n\ninput.each do |i|\n\tcase i.last\n\twhen 'captain'\n\t\tca.push i.first\n\twhen 'man'\n\t\tmn.push i.first\n\twhen 'woman', 'child'\n\t\tcw.push i.first\n\twhen 'rat'\n\t\trt.push i.first\n\tend\nend\n\n[rt, cw, mn, ca].each.each {|i| puts i}"}, {"source_code": "gets p\nputs %w(rat child|woman man captain).map{|_|$_.scan /(.+) (?:#{_})/}\n"}, {"source_code": "n = gets.to_i\nr, w, m, c = [], [], [], []\nn.times do\n\ta, b = gets.split\n\tcase b\n\t\twhen 'rat'\n\t\t\tr << a\n\t\twhen 'child'\n\t\t\tw << a\n\t\twhen 'woman'\n\t\t\tw << a\n\t\twhen 'man'\n\t\t\tm << a\n\t\twhen 'captain'\n\t\t\tc << a\n\tend\nend\nputs (r + w + m + c) * \"\\n\"\n"}, {"source_code": "class Person\n attr_accessor :name, :priority, :number\n def initialize(name, type, number)\n @name = name\n @priority = case type\n when \"rat\" then 0\n when \"child\", \"woman\" then 1\n when \"man\" then 2\n when \"captain\" then 3\n end\n @number = number\n end\nend\n\nn = gets.to_i\nh = []\n\nn.times do |number|\n name = gets(\" \")\n type = gets.chomp\n h.push(Person.new(name, type, number))\nend\n\nh.sort! do |a, b|\n if (a.priority == b.priority)\n a.number <=> b.number\n else\n a.priority <=> b.priority\n end\nend\n\nh.each { |e| puts e.name }\n"}, {"source_code": "\nname=[]\ntype=[]\nn=gets.to_i\nfor i in 0..n-1\n input=gets.split\n name.push(input[0])\n type.push(input[1])\nend\nfor i in 0..n-1\n if type[i]==\"rat\" then\n puts name[i]\n end\nend\nfor i in 0..n-1\n if type[i]==\"child\" || type[i]==\"woman\" then\n puts name[i]\n end\nend\nfor i in 0..n-1\n if type[i]==\"man\" then\n puts name[i]\n end\nend\nfor i in 0..n-1\n if type[i]==\"captain\" then\n puts name[i]\n end\nend\n\n"}, {"source_code": "include Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInfinity = 1/0.0\nclass Matrix;def inspect;empty? ? \"Matrix.empty(#{row_size}, #{column_size})\":\"Matrix[\\n#{@rows.map(&:inspect).join(\"\\n\")}\\n]\";end;end\ndef pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end\nclass String;def to_a;split(\"\");end;end\nclass String;def to_ia;split.map(&:to_i);end;end\ndef getia;gets.to_ia;end\ndef geti;gets.to_i;end\nclass Object;def dcopy;Marshal.load(Marshal.dump(self));end;end\n\nn=geti\ns=[]\nn.times{\n s< b.priority}\n\nh.each{|person| puts person.name}"}], "src_uid": "753113fa5130a67423f2e205c97f8017"} {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1227/B\n\nn = gets.to_i\n\nn.times do\n size = gets.to_i\n input = gets.split(' ').map(&:to_i)\n used = Array.new(size, false)\n\n maxi = 0\n min = 0\n output = []\n failed = false\n\n input.each_with_index do |num, i|\n if num < i + 1\n puts \"-1\"\n failed = true\n break\n end\n\n maxi = [maxi, num].max\n \n if !used[maxi-1]\n output << maxi\n used[maxi-1] = true\n else\n while used[min] == true do min += 1 end\n output << min += 1\n end\n end\n puts output.join(' ') unless failed\nend", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n q = gets.split.map &:to_i\n p = [q[0]]*n\n u = 1\n used = [false]*(n + 1)\n used[q[0]] = true\n (1...n).each do |i|\n if q[i] < i + 1\n p = [-1]\n break\n end\n if q[i] == q[i - 1]\n u += 1 while used[u]\n p[i] = u\n used[u] = true\n u += 1\n else\n p[i] = q[i]\n used[q[i]] = true\n end\n end\n puts p.join ' '\nend\n"}], "negative_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n q = gets.split.map &:to_i\n p = [q[0]]*n\n u = 1\n used = [false]*(n + 1)\n used[q[0]] = true\n (1...n).each do |i|\n if q[i] < i + 1\n p = [-1]\n break\n end\n if q[i] == q[i - 1]\n u += 1 while used[u]\n p[i] = u\n used[u] = true\n u += 1\n else\n p[i] = q[i]\n end\n end\n puts p.join ' '\nend\n"}], "src_uid": "81912dccb339d675e09df40919f9f6fe"} {"source_code": "# \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30c8\n\n(0..9).each{|x| print \"??\" , x , \">>\" , x ,\"??\\n\"}\n\nprint \"??>>?\\n\"\n\n(0...9).each{|x| print x , \"?<>\" , x+1 ,\"\\n\"}\n\nprint \"9?>>?0\\n?0<>10\\n>>??\\n\"\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\nputs <<-EOF\n9??>>??0\n0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n0?<>1\n1?<>2\n2?<>3\n3?<>4\n4?<>5\n5?<>6\n6?<>7\n7?<>8\n8?<>9\n9?>>9??\n0>>0?\n1>>1?\n2>>2?\n3>>3?\n4>>4?\n5>>5?\n6>>6?\n7>>7?\n8>>8?\n9>>9?\nEOF\n"}, {"source_code": "9.times { |d| puts \"#{d}??<>#{d + 1}\" }\nputs \"9??>>??0\"\nputs \"??<>1\"\n10.times { |d| puts \"?#{d}>>#{d}?\" }\nputs \"?>>??\"\n10.times { |d| puts \"#{d}>>?#{d}\" }\n"}], "negative_code": [{"source_code": "9.times { |d| puts \"#{d}??<>#{d + 1}\" }\nputs \"??<>1\"\nputs \"9??>>??0\"\nputs \"?>>??\"\n10.times { |d| puts \"?#{d}>>#{d}?\" }\n10.times { |d| puts \"#{d}>>?#{d}\" }\n"}, {"source_code": "#!/usr/bin/env ruby\n\nputs <<-EOF\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n0?<>1\n1?<>2\n2?<>3\n3?<>4\n4?<>5\n5?<>6\n6?<>7\n7?<>8\n8?<>9\n9?>>9??\n9??>>??0\n0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n??<>1\n0>>0?\n1>>1?\n2>>2?\n3>>3?\n4>>4?\n5>>5?\n6>>6?\n7>>7?\n8>>8?\n9>>9?\nEOF\n"}, {"source_code": "#!/usr/bin/env ruby\n\nputs <<-EOF\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n\n0?<>1\n1?<>2\n2?<>3\n3?<>4\n4?<>5\n5?<>6\n6?<>7\n7?<>8\n8?<>9\n\n9?>>9??\n\n9??>>??0\n\n0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n\n??<>1\n\n0>>0?\n1>>1?\n2>>2?\n3>>3?\n4>>4?\n5>>5?\n6>>6?\n7>>7?\n8>>8?\n9>>9?\nEOF\n"}], "src_uid": "90929863d289a475b766d5f2b0cd7c61"} {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1260/B\n\nn = gets.to_i\n\nn.times do\n input = gets.split(' ').map(&:to_i)\n a = input.max\n b = input.min\n\n if b < a/2.0 \n puts \"NO\" \n elsif (a % 3 + b % 3) % 3 == 0\n puts \"YES\"\n else\n puts \"NO\"\n end\nend", "positive_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a 2*b or b > 2*a or (a+b)%3 != 0)\n puts \"NO\"\n next\n end\n sa = (a-b).abs\n min = [a,b].min\n max = [a,b].max\n a = min - sa\n b = max - sa*2\n if(a != b)\n min = [a,b].min\n max = [a,b].max\n a = min - 1\n end\n if(a%3 == 0)\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}], "negative_code": [{"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1260/B\n\nn = gets.to_i\n\nn.times do\n input = gets.split(' ').map(&:to_i)\n a = input.max\n b = input.min\n\n if b < a/2.0\n puts \"NO\"\n break\n end\n\n if (a % 3 + b % 3) % 3 == 0\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a 2*b or b > 2*a)\n puts \"NO\"\n exit\n end\n puts ((a+b)%3==0)? \"YES\" : \"NO\"\nend"}], "src_uid": "0a720a0b06314fde783866b47f35af81"} {"source_code": "t = gets.to_i\nt.times {\n r, c = gets.split.map &:to_i\n for p in (0...r/2)\n stuff = []\n stuff2 = []\n for q in (0...c/2)\n parity = (p + q) % 2\n stuff.push(parity)\n stuff.push((parity + 1) % 2)\n stuff2.push((parity + 1) % 2)\n stuff2.push(parity)\n end\n puts stuff.join(\" \")\n puts stuff2.join(\" \")\n end\n}\n", "positive_code": [{"source_code": "step = ->xs {\r\n y = xs.map { |x| x + x.reverse }\r\n y + y.reverse\r\n}\r\n\r\nmatrix = [[1, 0], [0, 1]]\r\n5.times do\r\n matrix = step[matrix]\r\nend\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n puts matrix.take(n).map { |row| row.take(m).join(\" \") }.join(\"\\n\")\r\nend\r\n"}], "negative_code": [], "src_uid": "b7d40e7fc4f277cc801b59a21a16dfc1"} {"source_code": "n,m,k = gets.split\narr=[];\nwhile a=gets do\n\tarr.push(a.to_i)\nend\nc=arr.pop\nA=0\narr.each{|x| A=A+(((x^c).to_s(2).count('1') > k.to_i)?'0':'1').to_i}\nputs A", "positive_code": [{"source_code": "def byte_count(num = 0)\n c = 0\n while true\n if (num - (num.div(2) * 2)) == 1\n c += 1\n end\n num = num.div(2)\n if num < 2\n c += 1\n break\n end\n end\n \n return c\nend\n\nnums = []\narr = []\n\nc = 0\nmain = 0\n\ngets.split(\" \").each {|a| nums << a.to_i}\n\nfor i in (0..nums[1] - 1)\n arr[i] = gets.to_i\nend\n\nmain = gets.to_i\n\nfor i in (0..nums[1] - 1)\n if byte_count(arr[i] ^ main) <= nums[2]\n c += 1\n end\nend\n\nputs c"}, {"source_code": "n, m, k = gets.chomp.split(' ').map {|x| x.to_i}\narr = []\n(m).times do\n arr << gets.chomp.to_i\nend\nfedor = gets.chomp.to_i\ntotal = 0\narr.each do |x|\n s = (fedor ^ x).to_s(2)\n count = 0;\n (0...s.length).each { |i| count += 1 if s[i]=='1' }\n total += 1 if count<=k\nend\nputs total"}, {"source_code": "#!/usr/bin/ruby\n\nn, m, k = STDIN.readline.split.map {|s| s.to_i }\nplayers = []\nm.times { players.push STDIN.readline.to_i }\nfedor = STDIN.readline.to_i\ncount = 0\nplayers.each do |player|\n\tbits = (player ^ fedor)\n\tdiff = 0\n\twhile bits != 0\n\t\tdiff += (bits & 1)\n\t\tbits >>= 1\n\tend\n\tcount += 1 if diff <= k\nend\nputs count\n"}, {"source_code": "n,m,k=gets.chomp.split.map(&:to_i)\nar,ans=[],0\n(m+1).times {ar<0 || b>0\n\t\tc+=1 if a&1 != b&1\n\t\ta/=2\n\t\tb/=2\n\tend\n\tans+=1 if c<=k\nend\nputs ans\n"}, {"source_code": "require 'pp'\nn,m,k= STDIN.gets.chomp.split(/ /).map(&:to_i)\n\n\nans = 0\nxs = []\nm.times do |i|\n xs.push STDIN.gets.chomp.to_i\nend\n\nfedor = STDIN.gets.chomp.to_i\n\nxs.each do |x|\n xor = x ^ fedor\n ans += 1 if xor.to_s(2).split(//).select{|e| e == \"1\"}.count <= k\nend\n\nputs ans\n"}, {"source_code": "input = STDIN.read.split(\"\\n\")\nn, m, k = *input[0].split(' ').map(&:to_i)\nplayers = input[1..m].map(&:to_i)\nfedya = input[m + 1].to_i\n\nprint players[0..m].count { |p| (p ^ fedya).to_s(2).chars.map(&:to_i).inject(:+) <= k }"}, {"source_code": "n, m, k = gets.strip.split(\" \").map(&:to_i)\narmies = []\n(m + 1).times do |i|\n armies[i] = gets.strip.to_i\nend\n# puts armies\nnumber_of_friends = 0\nm.times do |i|\n num = armies[i] ^ armies[m]\n # puts num.to_s(2) \n count = 0\n while num != 0 do \n count += 1 if num & 1 == 1 \n num = num >> 1\n # puts num.to_s(2)\n end\n number_of_friends += 1 if count <= k\nend\nputs number_of_friends"}, {"source_code": "#http://codeforces.com/contest/467/B\n\n\nn,m, k = gets.split.map(&:to_i)\narr = []\nm.times do \n arr += [gets.to_i]\nend \nfedor = gets.to_i \n ans =0 \narr.each do |val| \n bits= fedor ^ val # to find how much differences are there..... \n if bits.to_s(2).count('1') <= k # counting 1 shows how much the two bits differ ..... \n ans +=1 \n end \nend \n\np ans "}, {"source_code": "n,m,k=gets.split.map{|e| e.to_i}\narr=[]\nm.times{\n\tarr<0\n\t\tn &= (n-1)\n\t\tset += 1\n\tend\n\tcount += 1 if set <= k\nend\n\nputs count"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\na = m.times.map{gets.to_i}\nme = gets.to_i\nans = 0\na.each do |x|\n ans += 1 if (x ^ me).to_s(2).split(\"\").count('1') <= k\nend\nputs ans\n"}, {"source_code": "def nbits(n)\n nb = 0\n while n > 0\n nb += n%2\n n /= 2\n end\n nb\nend\n\nn, m, k = gets.split.map{|x| x.to_i}\nx = []\n(m + 1).times{x << gets.to_i}\nf = 0\n(0..m-1).each{|i| f += 1 if nbits(x[i]^x[m]) <= k}\nputs f\n"}, {"source_code": "n, m, k = gets.split(' ').map(&:to_i)\n\na = 1.upto(m).map { gets.to_i }\nx = gets.to_i\n\nputs a.count { |y| (x ^ y).to_s(2).count('1') <= k }\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\na = (0..m).map { |_| gets.to_i }\nputs a[0..-2].select { |x| (x ^ a[-1]).to_s(2).count('1') <= k }.size"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\nm.times do\n t = gets.to_i\n xs << t\nend\nx = gets.to_i\ncount = 0\nxs.each do |i|\n c = (i ^ x).to_s(2).split(\"\").map(&:to_i).inject{|sum,x| sum + x }\n count += 1 if c <= k\nend\n\nputs count\n\n\n"}, {"source_code": "n,m,k = gets.split\narr=[];\nwhile a=gets do\n\tarr.push(a.to_i)\nend\nc=arr.pop\nA=0\narr.each{|x| A=A+(((x^c).to_s(2).count('1') > k.to_i)?'0':'1').to_i}\nputs A"}, {"source_code": "class Players\n attr_reader :x\n def initialize(x)\n @x = x\n end\n\n def bitnum(i)\n n = 0\n while i > 0\n n += i % 2\n i >>= 1\n end\n return n\n end\n\n def friend?(k, other)\n return bitnum(@x ^ other.x) <= k\n end\nend\n\nn, m, k = gets.split.map(&:to_i)\nlist = []\nm.times do\n list << Players.new(gets.to_i)\nend\nmy = Players.new(gets.to_i)\nfnum = 0\nlist.each do |e|\n if my.friend?(k, e)\n fnum += 1\n end\nend\nputs fnum\n"}], "negative_code": [{"source_code": "def byte_count(num = 0)\n c = 0\n s = \"\"\n while true\n if \"1\" == (num - (num.div(2) * 2)).to_s\n c += 1\n end\n num = num.div(2)\n if num < 2\n break\n end\n end\n \n return c\nend\n\nnums = []\narr = []\n\nc = 0\nmain = 0\n\ngets.split(\" \").each {|a| nums << a.to_i}\n\nfor i in (0..nums[1] - 1)\n arr[i] = gets.to_i\nend\n\nmain = gets.to_i\n\nfor i in (0..nums[1] - 1)\n if byte_count(arr[i] ^ main) <= nums[2]\n c += 1\n end\nend\n\nputs c"}, {"source_code": "def byte_count(num = 0)\n c = 0\n s = \"\"\n while true\n if \"1\" == (num - (num.div(2) * 2)).to_s + s\n c += 1\n end\n num = num.div(2)\n if num < 2\n break\n end\n end\n \n return c\nend\n\nnums = []\narr = []\n\nc = 0\nmain = 0\n\ngets.split(\" \").each {|a| nums << a.to_i}\n\nfor i in (0..nums[1] - 1)\n arr[i] = gets.to_i\nend\n\nmain = gets.to_i\n\nfor i in (0..nums[1] - 1)\n if byte_count(arr[i] ^ main) <= nums[2]\n c += 1\n end\nend\n\nputs c"}, {"source_code": "def byte_count(num = 0)\n c = 0\n s = \"\"\n while true\n s = (num - (num.div(2) * 2)).to_s + s\n num = num.div(2)\n if num < 2\n s = num.to_s + s\n break\n end\n end\n \n for i in (0..s.length - 1)\n if s[i] = \"1\"\n c += 1\n end\n end\n \n return c\nend\n\nnums = []\narr = []\n\nc = 0\nmain = 0\n\ngets.split(\" \").each {|a| nums << a.to_i}\n\nfor i in (0..nums[1] - 1)\n arr[i] = gets.to_i\nend\n\nmain = gets.to_i\n\nfor i in (0..nums[1] - 1)\n if byte_count(arr[i] ^ main) <= nums[2]\n c += 1\n end\nend\n\nputs c"}, {"source_code": "def byte_count(num = 0)\n c = 0\n s = \"\"\n while true\n s = (num - (num.div(2) * 2)).to_s + s\n num = num.div(2)\n if num < 2\n s = num.to_s + s\n break\n end\n end\n \n for i in (0..s.length - 1)\n if s[i] = \"1\"\n c += 1\n end\n end\n \n return c\nend\n\nnums = []\narr = []\n\nc = 0\nmain = 0\n\ngets.split(\" \").each {|a| nums << a.to_i}\n\nfor i in (0..nums[1] - 1)\n arr[i] = gets.to_i\nend\n\nmain = gets.to_i\n\nfor i in (0..nums[1] - 1)\n if byte_count(arr[i] ^ main) <= nums[2]\n c += 1\n end\nend\n\nputs c"}, {"source_code": "n,m,k=gets.chomp.split.map(&:to_i)\nar,ans=[],0\n(m+1).times {ar<0 || b>0\n\t\tc+=1 if a%2!=b%2\n\t\ta/=2\n\t\tb/=2\n\tend\n\tans+=1 if c<=k\nend\nputs ans\n"}, {"source_code": "require 'pp'\nn,m,k= STDIN.gets.chomp.split(/ /).map(&:to_i)\n\n\nans = 0\nxs = []\nm.times do |i|\n xs.push STDIN.gets.chomp.to_i.to_s(2).split(//).reverse\nend\n\nfedor = STDIN.gets.chomp.to_i.to_s(2).split(//).reverse\n\nxs.each do |x|\n kake = fedor & x\n ans += 1 if kake.count <= k\nend\n\nputs ans\n"}, {"source_code": "require 'pp'\nn,m,k= STDIN.gets.chomp.split(/ /).map(&:to_i)\n\n\nans = 0\nxs = []\nm.times do |i|\n xs.push STDIN.gets.chomp.to_i.to_s(2).split(//).reverse\nend\n\nfedor = STDIN.gets.chomp.to_i.to_s(2).split(//).reverse\n\nxs.each do |x|\n c = [fedor.count, x.count].min\n diff = (fedor.count - x.count).abs\n c.times do |i|\n if fedor[i] != x[i]\n diff += 1\n break\n end\n end\n ans += 1 if diff <= k\nend\n\nputs ans\n"}, {"source_code": "n,m,k = gets.split.map(&:to_i)\na = []\nr = 0\n(m + 1).times do |i|\n\ta[i] = gets.to_i\nend\n0.upto(m - 1) do |i| \n\tif [ a[m] , a[i] ].max - [ a[m] , a[i]].min <= k\n\t\tr += 1\n\tend\nend\np r"}, {"source_code": "#!/usr/bin/env ruby\n# coding: utf-8\n\ndef binarize(num)\n str = num.to_s(2)\n str.chars.reverse + ['0']*(@n-str.size)\nend\n\n\n@n, m, k = readline.chomp.split(/\\s+/).map(&:to_i)\nary = []\nm.times do\n ary << binarize(readline.to_i)\nend\nme = binarize(readline.to_i)\nc = 0\nary.each do |x|\n f = 0\n x.each_with_index { |i, v| f += 1 if i == me[v] }\n c += 1 if f <= k\nend\n\nputs c\n"}, {"source_code": "#!/usr/bin/env ruby\n# coding: utf-8\n\ndef binarize(num)\n str = num.to_s(2)\n str.chars.reverse + ['0']*(@n-str.size)\nend\n\n\n@n, m, k = readline.chomp.split(/\\s+/).map(&:to_i)\nary = []\nm.times do\n ary << binarize(readline.to_i)\nend\np me = binarize(readline.to_i)\nc = 0\nary.each do |x|\n f = 0\n x.each_with_index { |i, v| f += 1 if i != me[v] }\n if f <= k\n c += 1\n end\nend\n\nputs c\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\na = m.times.map{gets.to_i.to_s(2).chars.reverse}\nme = gets.to_i.to_s(2).chars.reverse\nans = 0\na.each do |x|\n diff = 0\n [x.size, me.size].min.times do |i|\n diff += 1 if x[i] != me[i]\n end\n ans += 1 if diff <= k\nend\nputs ans\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\na = m.times.map{gets.to_i.to_s(2).chars.reverse}\nme = gets.to_i.to_s(2).chars.reverse\nans = 0\na.each do |x|\n diff = 0\n [x.size, me.size].max.times do |i|\n if (i >= [x.size, me.size].min && (x[i] == 1 || me[i] == 1)) || x[i] != me[i]\n diff += 1\n end\n end\n ans += 1 if diff <= k\nend\nputs ans\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\na = m.times.map{gets.to_i.to_s(2).chars.reverse}\nme = gets.to_i.to_s(2).chars.reverse\nans = 0\na.each do |x|\n diff = 0\n [x.size, me.size].max.times do |i|\n diff += 1 if x[i] != me[i]\n end\n ans += 1 if diff <= k\nend\nputs ans\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\na = m.times.map{gets.to_i.to_s(2).chars.reverse}\nme = gets.to_i.to_s(2).chars.reverse\nans = 0\na.each do |x|\n diff = 0\n [x.size, me.size].min.times do |i|\n diff += 1 if x[i] != me[i]\n end\n diff += (x.size - me.size).abs\n ans += 1 if diff <= k\nend\nputs ans\n\n"}, {"source_code": "def nbits(n)\n nb = 0\n while n > 0\n nb += n%2\n n /= 2\n end\n nb\nend\n\nn, m, k = gets.split.map{|x| x.to_i}\nx = []\n(m + 1).times{x << gets.to_i}\nf = 0\n(0..m-1).each{|i| f += 1 if n - nbits(x[i]&x[m]) <= k}\nputs f\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\nm.times do\n t = gets[0..n].to_i.to_s(2)\n max = [t.length, max].max\n xs << t\nend\n\nx = gets[0..n].to_i.to_s(2)\nmax = [max, x.length].max\nx.ljust(max, \"0\")\n\nx = x.split(\"\")\nxs.map! do |r|\n r.ljust(max, \"0\").split(\"\")\nend\n\ncount = 0\nxs.each do |i|\n c = 0\n i.each_with_index do |p, j|\n c += 1 if x[j] == p\n end\n\n count += 1 if c <= k && c > 0\nend\n\nputs count\n\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\nm.times do\n t = gets.to_i\n xs << t\nend\nx = gets.to_i\ncount = 0\nxs.each do |i|\n c = (i ^ x)\n c = c.to_s(2).split(\"\").map(&:to_i).inject{|sum,x| sum + x }\n break\n count += 1 if c < k\nend\n\nputs count\n\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\nm.times do\n t = gets[0..n].to_i.to_s(2)\n max = [t.length, max].max\n xs << t\nend\n\nx = gets[0..n].to_i.to_s(2)\nmax = [max, x.length].max\nx.rjust(max, \"0\")\n\nx = x.split(\"\")\nxs.map! do |r|\n r.rjust(max, \"0\").split(\"\")\nend\n\ncount = 0\nxs.each do |i|\n c = 0\n i.each_with_index do |p, j|\n c += 1 if x[j] == p\n end\n\n count += 1 if c <= k && c > 0\nend\n\nputs count\n\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\nm.times do\n t = gets.to_i\n xs << t\nend\nx = gets.to_i\ncount = 0\nxs.each do |i|\n c = (i ^ x)\n c = c.to_s(2).split(\"\").map(&:to_i).inject{|sum,x| sum + x }\n break\n count += 1 if c <= k\nend\n\nputs count\n\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\nm.times do\n t = gets.to_i\n xs << t\nend\nx = gets.to_i\ncount = 0\nxs.each do |i|\n c = (i ^ x).to_s(2).split(\"\").map(&:to_i).inject{|sum,x| sum + x }\n count += 1 if c < k\nend\n\nputs count\n\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\nm.times do\n t = gets[0..n].to_i.to_s(2)\n max = [t.length, max].max\n xs << t\nend\n\nx = gets[0..n].to_i.to_s(2)\nmax = [max, x.length].max\nx.rjust(max, \"0\")\n\nx = x.split(\"\")\nxs.map! do |r|\n r.rjust(max, \"0\").split(\"\")\nend\n\ncount = 0\nxs.each do |i|\n c = 0\n i.each_with_index do |p, j|\n c += 1 if x[j] != p\n end\n count += 1 if c <= k && c > 0\nend\n\nputs count\n\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\nm.times do\n t = gets[0..n].to_i.to_s(2)\n max = [t.length, max].max\n xs << t\nend\n\nx = gets[0..n].to_i.to_s(2)\nmax = [max, x.length].max\n\n\nx = x.split(\"\")\nxs.map! do |r|\n r.split(\"\")\nend\n\ncount = 0\nxs.each do |i|\n c = 0\n i.each_with_index do |p, j|\n c += 1 if x[j] != p\n end\n count += 1 if c <= k\nend\n\nputs count\n\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\nm.times do\n t = gets[0..n].to_i.to_s(2)\n max = [t.length, max].max\n xs << t\nend\n\nx = gets[0..n].to_i.to_s(2)\nmax = [max, x.length].max\nx.rjust(max, \"0\")\n\nx = x.split(\"\")\nxs.map! do |r|\n r.rjust(max, \"0\").split(\"\")\nend\n\ncount = 0\nxs.each do |i|\n c = 0\n i.each_with_index do |p, j|\n c += 1 if x[j] != p\n end\n count += 1 if c <= k\nend\n\nputs count\n\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\nm.times do\n t = gets.to_i\n xs << t\nend\nx = gets.to_i\ncount = 0\nxs.each do |i|\n c = (i ^ x) & i\n c = c.to_s(2).split(\"\").map(&:to_i).inject{|sum,x| sum + x }\n count += 1 if c <= k\nend\n\nputs count\n\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\n(m).times do\n t = gets[0..n].to_i.to_s(2)\n max = [t.length, max].max\n xs << t\nend\nx = gets[0..n].to_i.to_s(2)\nmax = [max, x.length].max\nx.ljust(max, \"0\")\n\nx = x.split(\"\")\n\nxs.map! do |r|\n r.ljust(max, \"0\").split(\"\")\nend\n\ncount = 0\nxs.each do |i|\n c = 0\n i.each_with_index do |p, j|\n c += 1 if x[j] == p\n end\n\n count += 1 if c <= k\nend\n\nputs count\n\n\n"}, {"source_code": "n, m, k = gets.split.map(&:to_i)\nxs = []\nmax = 0\nm.times do\n t = gets[0..n].to_i.to_s(2)\n max = [t.length, max].max\n xs << t\nend\n\nx = gets[0..n].to_i.to_s(2)\nmax = [max, x.length].max\nx.ljust(max, \"0\")\n\nx = x.split(\"\")\nxs.map! do |r|\n r.ljust(max, \"0\").split(\"\")\nend\n\ncount = 0\nxs.each do |i|\n c = 0\n i.each_with_index do |p, j|\n c += 1 if x[j] != p\n end\n count += 1 if c <= k\nend\n\nputs count\n\n\n"}], "src_uid": "5ebb0ee239d68ea33d9dac2d0bdd5f4e"} {"source_code": "def solution(n, m, x)\n x -= 1\n\n col = x / n\n row = x % n\n row * m + col + 1\nend\n\ntest_cases = gets.to_i\n\ntest_cases.times do |test_case|\n arr = gets.split(' ').map(&:to_i)\n puts solution(arr[0], arr[1], arr[2])\nend", "positive_code": [{"source_code": "t = gets().to_i\r\nwhile(t!=0)\r\n ar = gets.chomp.split().map { |e| e.to_i }\r\n n = ar[0]\r\n m = ar[1]\r\n x = ar[2]\r\n x-=1\r\n col = (x/n).to_i\r\n row = x%n\r\n ans = row*m + col + 1\r\n puts \"#{ans}\\n\"\r\n t-=1\r\nend\r\n\r\n"}, {"source_code": "def solve_case\n n, m, x = gets.chomp.split(' ').map(&:to_i)\n\n c = (x.to_f / n.to_f).ceil\n r = x - (n * (c - 1))\n\n row_x = c + (m * (r - 1))\n puts row_x\nend\n\nt = gets.chomp.to_i\nt.times do\n solve_case\nend\n"}], "negative_code": [], "src_uid": "e519e4495c9acef4c4a614aef73cb322"} {"source_code": "t = gets.to_i\r\n\r\nt.times do \r\n a, b, c = gets.split(' ').map(&:to_i)\r\n puts a + b == c || a + c == b || c + b == a ? 'YES' : 'NO'\r\nend", "positive_code": [{"source_code": "n = gets.to_i\r\nn.times do\r\n array = gets.split(' ').map(&:to_i).sort\r\n puts array[0] + array[1] == array[2] ? 'YES' : 'NO'\r\nend\r\n"}, {"source_code": "t=gets.to_i\r\nwhile t>=1\r\n\ta,b,c=gets.split.map(&:to_i)\r\n\tif a+b==c\r\n\t\tputs \"YES\"\r\n\telsif b+c==a\r\n\t\tputs \"YES\"\r\n\telsif a+c==b\r\n\t\tputs \"YES\"\r\n\telse\r\n\t\tputs \"NO\"\r\n\tend\r\n\tt=t-1\r\nend \r\n"}, {"source_code": "n=gets.to_i\nn.times do\n a=gets.split.map(&:to_i)\n a.sort!\n if a.sum==a[-1]*2\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "gets.to_i.times do\n a=gets.split.map(&:to_i).sort\n puts a[0]+a[1]==a[2] ? 'YES' : 'NO'\nend\n"}], "negative_code": [{"source_code": " n = gets.to_i\r\n n.times do\r\n array = gets.split(' ').map(&:to_i)\r\n puts ([array[0] + array[1], array[1] + array[2], array[0] + array[2]] - array).size < 3 ? \"YES\" : \"NO\"\r\n end"}, {"source_code": "n = gets.to_i\r\nn.times do\r\n array = gets.split(' ').map(&:to_i)\r\n print ([array[0] + array[1], array[1] + array[2], array[0] + array[2]] - array).size < 3 ? \"YES\" : \"NO\"\r\nend\r\n"}, {"source_code": "n = gets.to_i\r\nn.times do\r\n array = gets.split(' ').map(&:to_i)\r\n print ([array[0] + array[1], array[1] + array[2], array[0] + array[2]] - array).size < 3\r\nend\r\n"}], "src_uid": "1b8293c51d025940eb859b0e625ab588"} {"source_code": "a=gets.chomp.to_i\nnegp=[]\nposp=[]\nneg=[]\npos=[]\nans=0\na.times do\ntemp=gets.chomp.split\n0.upto(1) {|i| temp[i]=temp[i].to_i}\nif temp[0]<0\nnegp< 0}\n\nif i == nil\n p t[-1][1]\nelsif i == 0\n p t[0][1]\nelse\n l_num = i\n r_num = t.size - i\n l_taken = [l_num, r_num+1].min\n r_taken = [r_num, l_num+1].min\n p (t[i-l_taken..i-1] + t[i..i+r_taken-1]).map{|x,a| a}.inject(:+)\nend\n"}, {"source_code": "a=gets.chomp.to_i\nnegp=[]\nposp=[]\nneg=[]\npos=[]\nans=0\na.times do\ntemp=gets.chomp.split\n0.upto(1) {|i| temp[i]=temp[i].to_i}\nif temp[0]<0\nnegp< 0\n\tl <<= [pair[0], pair[1]] if pair[0] <= 0\nend\n\nr.sort!\nl.sort! &(lambda { |a,b| b <=> a })\n\nbest = 0\nfor i in 0..1 do\n\treachl = 0\n\treachr = 0\n\tscore = 0\n\tleft = i == 0\n\twhile (left && reachl != l.size) || (!left && reachr != r.size)\n\t\tif !left\n\t\t\tscore += r[reachr][1]\n\t\t\treachr += 1\n\t\t\tleft = !left\n\t\telse \n\t\t\tscore += l[reachl][1]\n\t\t\treachl += 1\n\t\t\tleft = !left\n\t\tend\n\tend \n\tbest = [best, score].max\nend\nprint best\n"}, {"source_code": "d = gets.to_i.times.map{gets.split.map(&:to_i)}\nm = d.select{|a,b| a < 0}.sort\np = d.select{|a,b| a > 0}.sort.reverse\nsum = 0\nwhile(m!=[] && p!=[])\n sum += m.pop[1]+p.pop[1]\nend\nif m!=[]\n sum+=m.pop[1]\nend\nif p!=[]\n sum+=p.pop[1]\nend\np sum"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}.partition{|x| x[0] < 0}.map{|x| x.sort_by{|x| x[0].abs}}\nm = [a[0].size, a[1].size].min\nputs a[0][0..m].reduce(0){|s, x| s + x[1]} + a[1][0..m].reduce(0){|s, x| s + x[1]}\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nneg = []\npos = []\na.each do |x|\n neg << x if x[0] < 0\n pos << x if x[0] > 0\nend\nm = [neg.size, pos.size].min\nputs neg.sort.reverse[0..m].reduce(0){|s, x| s + x[1]} + pos.sort[0..m].reduce(0){|s, x| s + x[1]}\n\n"}, {"source_code": "a=gets.chomp.to_i\nnegp=[]\nposp=[]\nneg=[]\npos=[]\nans=0\na.times do\ntemp=gets.chomp.split\n0.upto(1) {|i| temp[i]=temp[i].to_i}\nif temp[0]<0\nnegp< b\n\t\treturn a\n\telse\n\t\treturn b\n\tend\nend\n\nn = gets.chomp.to_i\n\nneg_arr = Array.new(100001){0}\npos_arr = Array.new(100001){0}\n\nneg_size = 0\npos_size = 0\n\nn.times do\n\t\nx,a = gets.chomp.split.map{|x| x.to_i}\n\nif x < 0\n\tneg_arr[x*-1] = a\n\tneg_size+=1\nelse\n\tpos_arr[x] = a\n\tpos_size+=1\nend\n\nend\noutput = 0\nif neg_size == pos_size\n\t(1..100000).each do |i|\n\toutput+=neg_arr[i]\n\toutput+=pos_arr[i]\n\tend\nelse\n\t\n\tmin = min(neg_size,pos_size)\n\tmax = max(neg_size,pos_size)\n\n\tif min == neg_size\n\t\tneg_arr.each do |v|\n\t\t\toutput+=v\n\t\tend\n\t\tj = 0\n\t\t(1..100000).each do |i|\n\t\t\tif pos_arr[i]!=0\n\t\t\t\toutput+=pos_arr[i]\n\t\t\t\tj+=1\n\t\t\tend\n\t\t\tif j==min+1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\telse\n\t\tpos_arr.each do |v|\n\t\t\toutput+=v\n\t\tend\n\t\tj = 0\n\t\t(1..100000).each do |i|\n\t\t\tif neg_arr[i]!=0\n\t\t\t\toutput+=neg_arr[i]\n\t\t\t\tj+=1\n\t\t\tend\n\t\t\tif j==min+1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\n\t\n\t\nend\n\nputs output\n"}, {"source_code": "#!/usr/bin/ruby\na,b=gets.to_i.times.map{\n\tgets.split.map(&:to_i)\n}.partition{|e|\n\te[0]>0\n}.map{|e|\n\te.sort_by{|f|f[0].abs}\n}.sort_by(&:size)\np (a+b[0,a.size+1]).map(&:last).reduce(:+)"}, {"source_code": "n = gets.to_i\npos = {}\nneg = {}\nn.times do\n arr = gets.split(' ')\n x = arr.first.to_i\n a = arr.last.to_i\n if x < 0\n neg[x.abs] = a\n else\n pos[x] = a\n end\nend\nt_size = [neg.size, pos.size].min\nneg = neg.sort\npos = pos.sort\nval = 0\nt_size.times do |i|\n val+=neg[i].last\n val+=pos[i].last\nend\nif neg.size == pos.size\n puts val \nelse\n if neg.size < pos.size\n puts val+pos[t_size].last\n else\n puts val+neg[t_size].last\n end\nend\n\n"}, {"source_code": "n = gets.chomp.to_i\n\nplus = []\nminus = []\nn.times do\n p,v = gets.split.map{ |x| x.to_i }\n minus << [-p,v] if p < 0\n plus << [p,v] if p > 0\nend\n\nplus.sort!\nminus.sort!\n\nsum = 0\nif plus.size >= minus.size\n minus.size.times do |i|\n sum += plus[i][1];\n sum += minus[i][1];\n end\n if plus.size > minus.size\n sum += plus[minus.size][1];\n end\nelse\n plus.size.times do |i|\n sum += plus[i][1];\n sum += minus[i][1];\n end\n sum += minus[plus.size][1];\nend\nputs sum\n"}, {"source_code": "\nn = gets.chomp.to_i\napples = [].tap do |arr|\n n.times { arr << gets.chomp.split.map(&:to_i) }\nend\n\na, b = apples.partition { |e| e.first < 0 }.sort_by(&:size).map do |e|\n e.sort_by! { |e| e.first.abs }\nend\n\nputs (a + b[0..a.size]).map(&:last).inject(0, :+)\n"}, {"source_code": "\nn = gets.to_i;\narr = Array.new();\nans = 0;\n\nn.times {|x| arr[x] = gets.split.map(&:to_i)};\narr.push([0, 0]);\narr.sort!;\npos = arr.index([0, 0]);\n\ns, e = 0, n;\nif (pos > n - pos)\n s = pos - (n - pos) - 1;\nelsif (pos < n - pos)\n e = pos + pos + 1;\nend\n# puts s, e;\n(s..e).each {|x| ans += arr[x][1]};\nputs ans;\n"}], "negative_code": [{"source_code": "def min(a,b)\n\tif a < b\n\t\treturn a\n\telse\n\t\treturn b\n\tend\nend\n\ndef max(a,b)\n\tif a > b\n\t\treturn a\n\telse\n\t\treturn b\n\tend\nend\n\nn = gets.chomp.to_i\n\nneg_arr = Array.new(100001){0}\npos_arr = Array.new(100001){0}\n\nneg_size = 0\npos_size = 0\n\nn.times do\n\t\nx,a = gets.chomp.split.map{|x| x.to_i}\n\nif x < 0\n\tneg_arr[x*-1] = a\n\tneg_size+=1\nelse\n\tpos_arr[x] = a\n\tpos_size+=1\nend\n\nend\noutput = 0\nif neg_size == pos_size\n\t(1..100).each do |i|\n\toutput+=neg_arr[i]\n\toutput+=pos_arr[i]\n\tend\nelse\n\t\n\tmin = min(neg_size,pos_size)\n\tmax = max(neg_size,pos_size)\n\n\tif min == neg_size\n\t\tneg_arr.each do |v|\n\t\t\toutput+=v\n\t\tend\n\t\tj = 0\n\t\t(0..100).each do |i|\n\t\t\tif pos_arr[i]!=0\n\t\t\t\toutput+=pos_arr[i]\n\t\t\t\tj+=1\n\t\t\tend\n\t\t\tif j==min+1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\telse\n\t\tpos_arr.each do |v|\n\t\t\toutput+=v\n\t\tend\n\t\tj = 0\n\t\t(0..100).each do |i|\n\t\t\tif neg_arr[i]!=0\n\t\t\t\toutput+=neg_arr[i]\n\t\t\t\tj+=1\n\t\t\tend\n\t\t\tif j==min+1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\n\t\n\t\nend\n\nputs output\n"}, {"source_code": "# http://codeforces.com/contest/558/problem/A\n\nn = gets.chomp.to_i\napples = [].tap do |arr|\n n.times { arr << gets.chomp.split.map(&:to_i) }\nend\n\na, b = apples.partition { |a| a.first < 0 }.sort_by(&:size)\nc = a + b[0..a.size]\nputs c.map(&:last).inject(0, :+)\n"}, {"source_code": "n = gets.chomp.to_i\nhash = {}\nn.times do\n idx, num = gets.chomp.split.map(&:to_i)\n hash[idx] = num\nend\n\nmin, max = hash.keys.min, hash.keys.max\nright, left = [], []\n(min..max).each do |idx|\n next unless hash.key?(idx)\n idx < 0 ? left << hash[idx] : right << hash[idx]\nend\n\nscores = []\nscores << right.inject(0, :+) + left.last unless left.empty?\nscores << left.inject(0, :+) + right.first unless right.empty?\nscores << right.first if left.empty?\nscores << left.last if right.empty?\nputs scores.max\n"}, {"source_code": "a=gets.chomp.to_i\nnegp=[]\nposp=[]\nneg=[]\npos=[]\nans=0\na.times do\ntemp=gets.chomp.split\n0.upto(1) {|i| temp[i]=temp[i].to_i}\nif temp[0]<0\nnegp<0\npos << temp[1].to_i\nelse\nans+=temp[1].to_i\nend\nend\nl=neg.length\nb=pos.length\nif l 0\nend\nm = [neg.size, pos.size].min\np neg.sort.reverse , pos.sort\nputs neg.sort.reverse[0..m].reduce(0){|s, x| s + x[1]} + pos.sort[0..m].reduce(0){|s, x| s + x[1]}\n\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nneg = []\npos = []\na.each do |x|\n neg << x if x[0] < 0\n pos << x if x[0] > 0\nend\nm = [neg.size, pos.size].min\nputs neg.reverse[0..m].reduce(0){|s, x| s + x[1]} + pos[0..m].reduce(0){|s, x| s + x[1]}\n\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nneg = []\npos = []\na.each do |x|\n neg << x if x[0] < 0\n pos << x if x[0] > 0\nend\nm = [neg.size, pos.size].min\nputs neg[0..m].reduce(0){|a, b| a + b[1]} + pos[0..m].reduce(0){|a, b| a + b[1]}\n\n"}], "src_uid": "bf573af345509b2364ada6e613b6f998"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nfor i in 1..n\n for j in 1..n-i\n if a[j-1]>a[j]\n a[j-1],a[j] = a[j],a[j-1]\n puts \"#{j} #{j+1}\"\n end\n end\nend", "positive_code": [{"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\n\nn.times do\n (0...(n - 1)).each do |idx|\n if arr[idx] > arr[idx + 1]\n arr[idx], arr[idx + 1] = arr[idx + 1], arr[idx]\n puts [idx + 1, idx + 2].join(\" \")\n end\n end\nend\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nloop {\n changed=false\n for i in 1...n\n if a[i-1]>a[i]\n puts \"#{i} #{i+1}\"\n changed=true\n a[i-1], a[i]=a[i], a[i-1]\n break\n end\n end\n break unless changed\n}\n"}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split.map(&:to_i)\nbs = as.sort\n\nwhile as != bs\n for i in 0...n - 1\n if as[i] > as[i + 1]\n puts \"#{i + 1} #{i + 2}\"\n tmp = as[i + 1]\n as[i + 1] = as[i]\n as[i] = tmp\n end\n end\nend\n\n"}, {"source_code": "animalNumber = gets.chomp.to_i\nheights = gets.chomp.split(' ').map(&:to_i)\n\nsortedHeights = heights.sort\n\n\ndef pull target, source, heights\n\tindex = source\n\n\tuntil index == target\n\t\ttemp = heights[index - 1]\n\t\theights[index - 1] = heights[index]\n\t\theights[index] = temp\n\n\t\tputs \"#{index} #{index + 1}\"\n\t\tindex -= 1\n\tend\nend\n\nfor i in 0...(heights.length)\n\tif heights[i] != sortedHeights[i]\n\t\tindex = heights[i...(heights.length)].index(sortedHeights[i]) + i\n\t\tpull i, index, heights\n\tend\nend"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\n\nn.times do\n (0...(n - 1)).each do |idx|\n if arr[idx] < arr[idx + 1]\n arr[idx], arr[idx + 1] = arr[idx + 1], arr[idx]\n puts [idx + 1, idx + 2].join(\" \")\n end\n end\nend\n"}], "src_uid": "233c2806db31916609421fbd126133d0"} {"source_code": "n=gets.to_i\n\ndata=Array.new(2*n)\nstr=[*?a..?z].join\n\nn.times{|i|\n\tif i-4<0\n\t\tdata[i]=str[i%26,1]\n\telse\n\t\tdata[i]=data[i-4]\n\tend\n}\n\nputs data.join\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\nARGF.each_line do |s|\n num = s.to_i\n ret = 'abcd' * (1 + num / 4)\n\n puts ret[0..(num-1)]\nend\n\n"}, {"source_code": "n = gets.to_i\nputs ('abcd' * n)[0, n]\n"}, {"source_code": "n = gets.to_i\nputs ('abcd' * n)[0, n]\n"}, {"source_code": "n = gets.to_i\nputs ('abcd' * (n/4+1))[0, n]\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = gets.to_i\nstr = 'abcd' * (n / 4)\nstr << 'abcd'[0...(n%4)]\nputs str\n"}, {"source_code": "a=\"abcd\"*25000\ngets.to_i.times{|i| print \"#{a[i]}\"}"}, {"source_code": "n=gets.to_i;puts (\"abcd\"*(n+1))[0,n]"}, {"source_code": "n = gets.chop.to_i\ns = Array.new(n);\nfor i in 0..n-1\n\tprint ((i%4)+'a'.ord).chr\n\t\nend\nprint \"\\n\"\n"}, {"source_code": "def check(val)\n count = 0\n hash = Hash.new\n index = 1\n val.each_char { |s|\n if hash[s] == nil\n hash[s] = Array.new\n end\n\n hash[s] << index\n index += 1\n }\n\n hash.delete_if {|key, value| value.length == 1 }\n\n if hash.length == 0\n return true\n end\n\n #p hash\n\n hash.each_value { |arr|\n #p arr\n for i in 1..arr.length-1\n diff = arr[i] - arr[i-1]\n #puts \"#{arr[i]} - #{arr[i-1]} = #{diff}\"\n if (diff != 4 and diff != 7)\n return false\n end\n end\n }\n return true\nend\n\ndef inc(val, index)\n if (val[index] == 'z')\n val[index] = 'a'\n val = inc(val, index - 1)\n else\n val[index] = val[index].succ\n end\n return val\nend\n\nl = gets.chop.to_i\nval = ''\n#val = gets.chop\nf = l/4\no = l % 4\nval = 'abcd' * f\no.times { |i| val += 'a' }\n#puts \"#{f} #{o}\"\n\n#l.times { |i|\n #val += 'a'\n while check(val) == false\n val = inc(val, val.length-1)\n end\n#}\nputs val"}, {"source_code": "ans = \"abcd\" * 25000\nn = gets.to_i\nputs ans[0..(n-1)]"}, {"source_code": "#! /usr/bin/env ruby\n\nn = STDIN.read.to_i\n\nalpha = \"abcd\"\nn.times { |i|\n print alpha[i % 4].chr\n}\nputs\n"}, {"source_code": "n = gets.to_i\nputs(('abcd' * (1 + n / 4))[0...n])"}, {"source_code": "n = gets.to_i\nputs(('abcd' * (1 + n / 4))[0..n - 1])"}, {"source_code": "n = gets.to_i\nputs(('abcd' * (1 + n / 4))[0..(n % 4 - 5)])"}, {"source_code": "\n\narr = (0..STDIN.gets.to_i-1).map {|i| nil}\n\n#charlist = %W[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]\ncharlist = %W[a b c d]\n\nidx = -1\n\nwhile arr.index(nil)\n idx += 1\n ch = charlist[idx]\n pre = 0\n (0..arr.length-1).each do |i|\n if arr[i] == nil\n pre = i\n arr[pre] = ch\n break\n end\n end\n (0..arr.length-1).each do |i|\n diff = i-pre\n if diff == 4 or diff == 7 and arr[i] == nil\n pre = i\n arr[i] = ch\n end\n end\n #puts arr.to_s\nend\n\n\nputs arr.join\n"}, {"source_code": "\n\narr = (0..STDIN.gets.to_i-1).map {|i| nil}\n\ncharlist = %W[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\nidx = -1\n\nwhile arr.index(nil)\n idx += 1\n ch = charlist[idx]\n pre = 0\n (0..arr.length-1).each do |i|\n if arr[i] == nil\n pre = i\n arr[pre] = ch\n break\n end\n end\n (0..arr.length-1).each do |i|\n diff = i-pre\n if diff == 4 or diff == 7 and arr[i] == nil\n pre = i\n arr[i] = ch\n end\n end\n #puts arr.to_s\nend\n\n\nputs arr.join\n"}, {"source_code": "n = gets.chomp.to_i\nputs (\"abcd\" * ((n / 4.0).ceil.to_i)).chars.to_a.take(n).join('')"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\n\nARGF.each_line do |s|\n num = s.to_i\n ret = 'z' * num\n\n num.times do |i|\n tmp = (97 + (i % 4)).chr\n ret[i] = tmp if ret[i] > tmp\n\n tmp = (97 + (i % 7)).chr\n ret[i] = tmp if ret[i] > tmp\n end\n puts ret\nend\n\n"}, {"source_code": "ans = \"abcdabc\" * 15000\nn = gets.to_i\nputs ans[0..(n-1)]"}, {"source_code": "#!/usr/bin/env ruby\n\n\nn = STDIN.gets.to_i\n\ncount = n/7\nwhile count > -1\n if (n-7*count) % 4 == 0\n puts [[4]*((n-7*count)/4),[7]*count].flatten.join\n exit\n end\n count -= 1\nend\nputs -1\n"}, {"source_code": "\n\narr = (0..STDIN.gets.to_i-1).map {|i| nil}\n\n%W[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].each do |ch|\n pre = 0\n (0..arr.length-1).each do |i|\n if arr[i] == nil\n pre = i\n arr[pre] = ch\n break\n end\n end\n (0..arr.length-1).each do |i|\n diff = i-pre\n if diff == 4 or diff == 7 and arr[i] == nil\n pre = i\n arr[i] = \"a\"\n end\n end\n break unless arr.index(nil)\nend\n\n\nputs arr.join\n"}, {"source_code": "\n\narr = (0..STDIN.gets.to_i-1).map {|i| nil}\n\narr[0] = \"a\"\npre = 0\n(0..arr.length-1).each do |i|\n diff = i-pre\n arr[i] = \"a\" if diff == 4 or diff == 7\nend\n\nif (arr.length > 1)\n c = \"b\"\n pre = 1\n arr[pre] = c\n (0..arr.length-1).each do |i|\n diff = i-pre\n arr[i] = c if (diff == 4 or diff == 7) and arr[i] == nil\n end\nend\n\nif (arr.length > 2)\n c = \"c\"\n pre = 2\n arr[pre] = c\n (0..arr.length-1).each do |i|\n diff = i-pre\n arr[i] = c if (diff == 4 or diff == 7) and arr[i] == nil\n end\nend\n\nif (arr.length > 3)\n c = \"d\"\n pre = 3\n arr[pre] = c\n (0..arr.length-1).each do |i|\n diff = i-pre\n arr[i] = c if (diff == 4 or diff == 7) and arr[i] == nil\n end\nend\n\nputs arr.join\n"}], "src_uid": "94278e9c55f0fc82b48145ebecbc515f"} {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nb=[]\n30.downto(0) do |i|\n d=1<0\n c&=x\n b<0\n c&=x\n end\n end\n if c==0\n b=a.select{|x|x&d>0}\n puts b.size, b.join(' ')\n exit\n end\nend\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nb=Array.new(31){|i|1<0\n c[i]<0\n puts c[i].size, c[i].join(' ')\n exit\n end\nend\n\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nMath.log2(a.last).to_i.downto(0) do |i|\n d=1<0\n c&=x\n end\n end\n if c==0\n b=a.select{|x|x&d>0}\n puts b.size, b.join(' ')\n exit\n end\nend\n"}], "negative_code": [{"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nm=1<=m}\nputs a.size,a.join(' ')\n"}], "src_uid": "54c23dda2aa1d58ecf22c03015dca55c"} {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]\n", "positive_code": [{"source_code": "a=gets.chomp\nal=a.length\nb=gets.chomp\nbl=b.length\nc=gets.chomp\ncl=c.length\ntr=0\nif bl+cl<=al\nintr=0\ni=0\naka=b\nakal=bl\nloop do\nif a[i..i+akal-1]==aka\ni=i+akal-1\naka=c\nakal=cl\nintr+=1\nend\ni+=1\nbreak if intr==2\nbreak if i+akal>=al+1\nend \nif intr==2\ntr=1\nend\na.reverse!\nintr=0\ni=0\naka=b\nakal=bl\nloop do\nif a[i..i+akal-1]==aka\ni=i+akal-1\naka=c\nakal=cl\nintr+=1\nend\ni+=1\nbreak if intr==2\nbreak if i+akal>=al+1\nend \nif intr==2 && tr==1\ntr+=2\nelsif intr==2 \ntr=2\nend\nend\nif tr==3\nputs \"both\"\nelsif tr==2\nputs \"backward\"\nelsif tr==1\nputs \"forward\"\nelse\nputs \"fantasy\"\nend"}, {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]\n"}, {"source_code": "a=gets.chomp\nal=a.length\nb=gets.chomp\nbl=b.length\nc=gets.chomp\ncl=c.length\ntr=0\nif bl+cl<=al\nintr=0\ni=0\naka=b\nakal=bl\nloop do\nif a[i..i+akal-1]==aka\ni=i+akal-1\naka=c\nakal=cl\nintr+=1\nend\ni+=1\nbreak if intr==2\nbreak if i+akal>=al+1\nend \nif intr==2\ntr=1\nend\na.reverse!\nintr=0\ni=0\naka=b\nakal=bl\nloop do\nif a[i..i+akal-1]==aka\ni=i+akal-1\naka=c\nakal=cl\nintr+=1\nend\ni+=1\nbreak if intr==2\nbreak if i+akal>=al+1\nend \nif intr==2 && tr==1\ntr+=2\nelsif intr==2 \ntr=2\nend\nend\nif tr==3\nputs \"both\"\nelsif tr==2\nputs \"backward\"\nelsif tr==1\nputs \"forward\"\nelse\nputs \"fantasy\"\nend"}, {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]"}, {"source_code": "def test(a, a1, a2)\n i = a.index(a1)\n if !i.nil? then\n b = a[i+a1.size..a.size]\n return true if !b[a2].nil?\n end\n return false\nend\na = gets.strip\na1 = gets.strip\na2= gets.strip\nt1 = test(a, a1, a2)\na.reverse!\nt2 = test(a, a1, a2)\nif t1 then\n if t2 then\n puts \"both\"\n else\n puts \"forward\"\n end\nelse\n if t2 then\n puts \"backward\"\n else\n puts \"fantasy\"\n end\nend\n\n"}, {"source_code": "flags = gets.chomp\nline2 = gets.chomp\nline3 = gets.chomp\nflag2 = (flags =~ /#{line2}/)\nflag3 = (flags[(flag2+line2.size)..-1] =~ /#{line3}/) if flag2\nforward = true if flag2 && flag3\n\nrflags = flags.reverse\nflag2 = (rflags =~ /#{line2}/)\nflag3 = (rflags[(flag2+line2.size)..-1] =~ /#{line3}/) if flag2\nbackward = true if flag2 && flag3\n\nif forward && backward\n puts \"both\"\nelsif forward\n puts \"forward\"\nelsif backward\n puts \"backward\"\nelse \n puts \"fantasy\"\nend\n\n"}, {"source_code": "line, seq1, seq2, forward, backward = gets().chomp!, gets().chomp!, gets().chomp!, false, false\nif /#{seq1}.*#{seq2}/.match(line) then forward = true end\nif /#{seq2.reverse!}.*#{seq1.reverse!}/.match(line) then backward = true end\nif forward && backward then puts( \"both\" ) elsif forward then puts( \"forward\" ) elsif backward then puts( \"backward\" ) else puts( \"fantasy\" ) end\n\n"}, {"source_code": "sequence = gets.chomp\nfirst = gets.chomp\nsecond = gets.chomp\n\nresult = \"fantasy\"\nindex = sequence.index(first)\nif index\n\tresult = \"forward\" if sequence.index(second, index + first.length) \nend\n\nsequence.reverse!\n\nindex = sequence.index(first)\nif index\n\tif sequence.index(second, index + first.length)\n\t\tresult = (result == \"forward\") ? \"both\" : \"backward\"\n\tend\nend\n\nputs result"}, {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]\n"}, {"source_code": "#!/usr/bin/env ruby\n\ntxt = gets.chomp\nstr1 = gets.chomp\nstr2 = gets.chomp\n\nforward = backward = false\n\nif txt =~ /#{str1}.*#{str2}/\n forward = true\nend\n\ntxt.reverse!\n\nif txt =~ /#{str1}.*#{str2}/\n backward = true\nend\n\nif forward == true and backward == true\n puts \"both\"\nelsif forward == true and backward == false\n puts \"forward\"\nelsif forward == false and backward == true\n puts \"backward\"\nelse\n puts \"fantasy\"\nend\n"}, {"source_code": "map = gets.strip\nx = gets.strip\ny = gets.strip\n\nresult = \"fantasy\"\ni = map.index(x)\nif i\n result = \"forward\" if map.index(y, i+x.length)\nend\nmap.reverse!\n\ni = map.index(x)\nif i\n if map.index(y, i+x.length)\n if result == \"forward\"\n result = \"both\"\n else\n result = \"backward\"\n end\n end\nend\nputs result"}, {"source_code": "flags = gets.chomp!\n\ns1 = gets.chomp!\ns2 = gets.chomp!\n\nforward = false\nbackward = false\nfantasy = false\n\nif (flags.index(s1) != nil && flags.index(s2, flags.index(s1)+s1.length) != nil)\n forward = true\nelse\n forward = false\nend\n\nif (flags.reverse.index(s1) != nil && flags.reverse.index(s2, flags.reverse.index(s1)+s1.length))\n backward = true\nelse\n backward = false\nend\n\n\nif backward && forward\n puts \"both\"\nelse\n if forward\n puts \"forward\"\n else\n if backward\n puts \"backward\"\n else\n puts \"fantasy\"\n end\n end\nend\n"}, {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]"}, {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]\n"}, {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]\n"}, {"source_code": "a = gets.chomp\nb = a.reverse\n\nf = gets.chomp\ns = gets.chomp\n\nif (k = a.index(f)) && a.index(s,k+f.size) then\n n = \"forward\"\nelse\n n = 0\nend\n\nif (k = b.index(f)) && b.index(s,k+f.size) then\n if n == 0 then\n n = \"backward\"\n else\n n = \"both\"\n end\nelse\n if n == 0\n n = \"fantasy\"\n end\nend\n\nputs n"}, {"source_code": "s, a, b = readlines.map(&:chop)\nr = /#{a}.*#{b}/\nputs %w(fantasy forward backward both)[(s =~ r ? 1 : 0) | (s.reverse =~ r ? 2 : 0)]\n"}, {"source_code": "s, a, b = readlines.map(&:chop)\nr, i = /#{a}.*#{b}/, 0\ni |= 1 if s =~ r\ni |= 2 if s.reverse =~ r\nputs %w(fantasy forward backward both)[i]\n"}, {"source_code": "str1 = gets.chomp!\nstr2 = gets.chomp!\nstr3 = gets.chomp!\nforward = backward = false\nif str1.match(/#{str2}\\w*#{str3}/)\n\tforward = true\nend\nstr11 = str1.reverse\nif str11.match(/#{str2}\\w*#{str3}/)\n\tbackward = true\nend\nif forward && backward\n\tputs 'both'\nelsif forward\n\tputs 'forward'\nelsif backward\n\tputs 'backward'\nelse\n\tputs 'fantasy'\nend\n\n"}, {"source_code": "a=gets.chomp;b=gets.chomp;c=gets.chomp;\n puts %w[fantasy forward backward both][(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]\n "}, {"source_code": "def solve(data)\n q=data.index($a)\n if q==nil then\n return false\n end\n r=data.rindex($b)\n if r==nil then\n return false\n end\n return q+$a.length<=r\nend\n\ninput=gets.split[0]\n$a=gets.split[0]\n$b=gets.split[0]\nif solve(input) then\n if solve(input.reverse) then\n puts \"both\"\n else\n puts \"forward\"\n end\nelse\n if solve(input.reverse) then\n puts \"backward\"\n else\n puts \"fantasy\"\n end\nend\n"}, {"source_code": "#!/usr/bin/ruby -Ku\n\ninclude Math\nrequire 'prime'\nrequire 'bigdecimal'\nrequire 'bigdecimal/math'\nrequire 'matrix'\nrequire 'pp'\nrequire 'benchmark'\n\nInf = Float::INFINITY\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\ns = gets.chomp\na = gets.chomp\nb = gets.chomp\nf = (s =~ Regexp.new(a + \".*\" + b))\ns = s.reverse\nb = (s =~ Regexp.new(a + \".*\" + b))\nif f && b\n puts \"both\"\nelsif f\n puts \"forward\"\nelsif b\n puts \"backward\"\nelse\n puts \"fantasy\"\nend\n"}, {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]\n"}, {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]\n"}, {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]"}, {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]"}, {"source_code": "a=gets;b=gets.chomp;c=gets.chomp;puts %w{fantasy forward backward both}[(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]"}, {"source_code": "map = gets.strip\nx = gets.strip\ny = gets.strip\n\nresult = \"fantasy\"\ni = map.index(x)\nif i\n result = \"forward\" if map.index(y, i+x.length)\nend\nmap.reverse!\n\ni = map.index(x)\nif i\n if map.index(y, i+x.length)\n if result == \"forward\"\n result = \"both\"\n else\n result = \"backward\"\n end\n end\nend\nputs result"}, {"source_code": "a=gets.chomp\nal=a.length\nb=gets.chomp\nbl=b.length\nc=gets.chomp\ncl=c.length\ntr=0\nif bl+cl<=al\nintr=0\ni=0\naka=b\nakal=bl\nloop do\nif a[i..i+akal-1]==aka\ni=i+akal-1\naka=c\nakal=cl\nintr+=1\nend\ni+=1\nbreak if intr==2\nbreak if i+akal>=al+1\nend \nif intr==2\ntr=1\nend\na.reverse!\nintr=0\ni=0\naka=b\nakal=bl\nloop do\nif a[i..i+akal-1]==aka\ni=i+akal-1\naka=c\nakal=cl\nintr+=1\nend\ni+=1\nbreak if intr==2\nbreak if i+akal>=al+1\nend \nif intr==2 && tr==1\ntr+=2\nelsif intr==2 \ntr=2\nend\nend\nif tr==3\nputs \"both\"\nelsif tr==2\nputs \"backward\"\nelsif tr==1\nputs \"forward\"\nelse\nputs \"fantasy\"\nend"}], "negative_code": [{"source_code": "a = gets.chomp\nb = a.reverse\n\nf = gets.chomp\ns = gets.chomp\n\nif (k = a.index(f)) && a.index(s,k+1) then\n n = \"forward\"\nelse\n n = 0\nend\n\nif (k = b.index(f)) && b.index(s,k+1) then\n if n == 0 then\n n = \"backward\"\n else\n n = \"both\"\n end\nelse\n if n == 0\n n = \"fantasy\"\n end\nend\n\nputs n"}, {"source_code": "s, a, b = readlines.map(&:chop)\nr, i = /#{gets}.*#{gets}/, 0\ni |= 1 if s =~ r\ni |= 2 if s.reverse =~ r\nputs %w(fantasy forward backward both)[i]\n"}, {"source_code": "a=gets.chomp;b=gets.chomp;c=gets.chomp;\n puts %w[fantasy foreward backward both][(a.match(b+'.*'+c)?1:0)|(a.match((b+'*.'+c).reverse)?2:0)]\n "}, {"source_code": "a=gets.chomp\nal=a.length\nb=gets.chomp\nbl=b.length\nc=gets.chomp\ncl=c.length\ntr=0\nif bl+cl<=cl\nintr=0\ni=0\naka=b\nakal=bl\nloop do\nif a[i..i+akal-1]==b\naka=c\nakal=cl\nintr+=1\ni=i+aka-1\nend\ni+=1\nbreak if intr==2\nbreak if i+akal==al+1\nend \nif intr==2\ntr=1\nend\na.reverse!\nintr=0\nloop do\nif a[i..i+akal-1]==bl\naka=cl\nakal=cl\nintr+=1\ni=i+aka-1\nend\ni+=1\nbreak if intr==2\nbreak if i+akal==al+1\nend \nif intr==2 && tr==1\ntr+=2\nelse \ntr=2\nend\nend\nif tr==3\nputs \"both\"\nelsif tr==2\nputs \"backward\"\nelsif tr==1\nputs \"forward\"\nelse\nputs \"fantasy\"\nend"}, {"source_code": "a=gets.chomp\nal=a.length\nb=gets.chomp\nbl=b.length\nc=gets.chomp\ncl=c.length\ntr=0\nif bl+cl<=al\nintr=0\ni=0\naka=b\nakal=bl\nloop do\nif a[i..i+akal-1]==aka\naka=c\nakal=cl\nintr+=1\ni=i+akal-1\nend\ni+=1\nbreak if intr==2\nbreak if i+akal==al+1\nend \nif intr==2\ntr=1\nend\na.reverse!\nintr=0\ni=0\naka=b\nakal=bl\nloop do\nif a[i..i+akal-1]==aka\naka=cl\nakal=cl\nintr+=1\ni=i+akal-1\nend\ni+=1\nbreak if intr==2\nbreak if i+akal==al+1\nend \nif intr==2 && tr==1\ntr+=2\nelsif intr==2 \ntr=2\nend\nend\nif tr==3\nputs \"both\"\nelsif tr==2\nputs \"backward\"\nelsif tr==1\nputs \"forward\"\nelse\nputs \"fantasy\"\nend"}, {"source_code": "def test(a, a1, a2)\n i = a.index(a1)\n if !i.nil? then\n b = a[i+a1.size..a.size]\n return true if !b[a2].nil?\n end\n return false\nend\na = gets.strip\na1 = gets.strip\na2= gets.strip\nt1 = test(a,a1,a2)\na.reverse!\na1.reverse!\na2.reverse!\nt2 = test(a, a2, a1)\nif t1 then\n if t2 then\n puts \"both\"\n else\n puts \"forward\"\n end\nelse\n if t2 then\n puts \"backward\"\n else\n puts \"fantasy\"\n end\nend\n\n"}, {"source_code": "def test(a, a1, a2)\n i = a.index(a1)\n if !i.nil? then\n b = a[i+a1.size..a.size]\n return true if !b[a2].nil?\n end\n return false\nend\na = gets.strip\na1 = gets.strip\na2= gets.strip\nt1 = test(a,a1,a2)\na.reverse!\na1.reverse!\na.reverse!\nt2 = test(a, a2, a1)\nif t1 then\n if t2 then\n puts \"both\"\n else\n puts \"forward\"\n end\nelse\n if t2 then\n puts \"backward\"\n else\n puts \"fantasy\"\n end\nend\n\n"}, {"source_code": "def test(a, a1, a2)\n i = a.index(a1)\n if !i.nil? then\n b = a[i+a1.size..a.size]\n p b\n return true if !b[a2].nil?\n end\n return false\nend\na = gets.strip\na1 = gets.strip\na2= gets.strip\nt1 = test(a,a1,a2)\na.reverse!\na1.reverse!\na2.reverse!\nt2 = test(a, a2, a1)\nif t1 then\n if t2 then\n puts \"both\"\n else\n puts \"forward\"\n end\nelse\n if t2 then\n puts \"backward\"\n else\n puts \"fantasy\"\n end\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\ntxt = gets.chomp\nstr1 = gets.chomp\nstr2 = gets.chomp\n\nforward = backward = false\n\nif txt =~ /#{str1}.*#{str2}/\n forward = true\nend\n\ntxt.reverse!\nstr1.reverse!\nstr2.reverse!\n\nif txt =~ /#{str2}.*#{str1}/\n backward = true\nend\n\nif forward == true and backward == true\n puts \"both\"\nelsif forward == true and backward == false\n puts \"forward\"\nelsif forward == false and backward == true\n puts \"backward\"\nelse\n puts \"fantasy\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ntxt = gets.chomp\nstr1 = gets.chomp\nstr2 = gets.chomp\n\nforward = backward = false\n\nif txt =~ /#{str1}.*#{str2}/\n forward = true\nend\n\ntxt.reverse!\nstr1.reverse!\nstr2.reverse!\n\nif txt =~ /#{str2}.*#{str2}/\n backward = true\nend\n\nif forward == true and backward == true\n puts \"both\"\nelsif forward == true and backward == false\n puts \"forward\"\nelsif forward == false and backward == true\n puts \"backward\"\nelse\n puts \"fantasy\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\ntxt = gets.chomp\nstr1 = gets.chomp\nstr2 = gets.chomp\n\nforward = backward = false\n\nif txt =~ /#{str1}.*#{str2}/\n forward = true\nend\n\n#txt.reverse!\n#str1.reverse!\n#str2.reverse!\n\nif txt =~ /#{str2}.*#{str1}/\n backward = true\nend\n\nif forward == true and backward == true\n puts \"both\"\nelsif forward == true and backward == false\n puts \"forward\"\nelsif forward == false and backward == true\n puts \"backward\"\nelse\n puts \"fantasy\"\nend\n"}, {"source_code": "#$stdin = File.open('in.txt')\nmap = gets.strip\nx = gets.strip\ny = gets.strip\n\nlast_x = nil\nresult = \"fantasy\"\ni = 0\nj = 0\n\n\n\nwhile i < map.length and j < x.length\n j += 1 if map[i] == x[j]\n i += 1\nend\n\nif j == x.length\n j = 0\n while i < map.length and j < y.length\n j += 1 if map[i] == y[j]\n i += 1\n end\n if j == y.length\n result = \"forward\"\n end\nend\n\ni = map.length-1\nj = x.length-1\n\nwhile i >= 0 and j >= 0\n j -= 1 if map[i] == x[j]\n i -= 1\nend\n\nif j == -1\n j = y.length-1\n while i >= 0 and j >= 0\n j -= 1 if map[i] == y[j]\n i -= 1\n end\n if j == -1\n if result == \"forward\"\n result = \"both\"\n else\n result = \"backward\"\n end\n end\nend\n\nputs result"}, {"source_code": "#$stdin = File.open('in.txt')\nmap = gets.strip\nx = gets.strip\ny = gets.strip\n\nresult = \"fantasy\"\ni = map.index(x)\nif i\n result = \"forward\" if map.index(y, i+1)\nend\nx.reverse!\ny.reverse!\n\ni = map.rindex(x)\nif i\n if map.rindex(y, y.length-(i+1))\n if result == \"forward\"\n result = \"both\"\n else\n result = \"backward\"\n end\n end\nend\n# i = 0\n# j = 0\n# find = false\n# while i < map.length and !find\n# if map[i] == x[0]\n# j = 0\n# while i < map.length and j < x.length and map[i] == x[j]\n# i += 1\n# j += 1\n# end\n# find = j == x.length\n# else\n# i += 1 \n# end\n# end\n# \n# if find\n# find = false\n# while i < map.length and !find\n# if map[i] == y[0]\n# j = 0\n# while i < map.length and j < y.length and map[i] == y[j]\n# i += 1\n# j += 1\n# end\n# find = j == y.length\n# else\n# i += 1 \n# end\n# end\n# if find\n# result = \"forward\"\n# end\n# end\n# \n# i = map.length-1\n# find = false\n# \n# while i >= 0 and !find\n# if map[i] == x[0]\n# j = 0\n# while i >=0 and j < x.length and map[i] == x[j]\n# i -= 1\n# j += 1\n# end\n# find = j == x.length\n# else\n# i -= 1 \n# end\n# end\n# \n# if find\n# find = false\n# while i >= 0 and !find\n# if map[i] == y[0]\n# j = 0\n# while i >=0 and j < y.length and map[i] == y[j]\n# i -= 1\n# j += 1\n# end\n# find = j == y.length\n# else\n# i -= 1 \n# end\n# end\n# if find\n# if result == \"forward\"\n# result = \"both\"\n# else\n# result = \"backward\"\n# end\n# end\n# end\n\nputs result"}, {"source_code": "#$stdin = File.open('in.txt')\nmap = gets.strip\nx = gets.strip\ny = gets.strip\n\nresult = \"fantasy\"\ni = 0\nj = 0\nfind = false\nwhile i < map.length and !find\n if map[i] == x[0]\n j = 0\n while i < map.length and j < x.length and map[i] == x[j]\n i += 1\n j += 1\n end\n find = j == x.length\n else\n i += 1 \n end\nend\n\nif find\n find = false\n while i < map.length and !find\n if map[i] == y[0]\n j = 0\n while i < map.length and j < y.length and map[i] == y[j]\n i += 1\n j += 1\n end\n find = j == y.length\n else\n i += 1 \n end\n end\n if find\n result = \"forward\"\n end\nend\n\ni = map.length-1\nfind = false\n\nwhile i >= 0 and !find\n if map[i] == x[0]\n j = 0\n while i >=0 and j < x.length and map[i] == x[j]\n i -= 1\n j += 1\n end\n find = j == x.length\n else\n i -= 1 \n end\nend\n\nif find\n find = false\n while i >= 0 and !find\n if map[i] == y[0]\n j = 0\n while i >=0 and j < y.length and map[i] == y[j]\n i -= 1\n j += 1\n end\n find = j == y.length\n else\n i -= 1 \n end\n end\n if find\n if result == \"forward\"\n result = \"both\"\n else\n result = \"backward\"\n end\n end\nend\n\nputs result"}, {"source_code": "#$stdin = File.open('in.txt')\nmap = gets.strip\nx = gets.strip\ny = gets.strip\n\nresult = \"fantasy\"\ni = 0\nj = 0\n\nwhile i < map.length and j < x.length\n j += 1 if map[i] == x[j]\n i += 1\nend\n\nif j == x.length\n j = 0\n while i < map.length and j < y.length\n j += 1 if map[i] == y[j]\n i += 1\n end\n if j == y.length\n result = \"forward\"\n end\nend\n\ni = map.length-1\nj = 0\n\nwhile i >= 0 and j < x.length\n j += 1 if map[i] == x[j]\n i -= 1\nend\n\nif j == x.length\n j = 0\n while i >= 0 and j < y.length\n j += 1 if map[i] == y[j]\n i -= 1\n end\n if j == y.length\n if result == \"forward\"\n result = \"both\"\n else\n result = \"backward\"\n end\n end\nend\n\nputs result"}, {"source_code": "flags = gets.chomp!\n\ns1 = gets.chomp!\ns2 = gets.chomp!\n\nforward = false\nbackward = false\nfantasy = false\n\nfi1 = flags.index(s1)\nbi1 = flags.reverse.index(s1)\n\nif (fi1 != nil)\n fi2 = flags.index(s2, fi1+s1.length)\n if (fi2 != nil && fi1 <= fi2)\n forward = true\n else\n forward = false\n end\nelse\n fantasy = true\nend\n\nif (bi1 != nil)\n bi2 = flags.reverse.index(s2, bi1+s1.length)\n if (bi2 != nil && bi1+s1.length <= bi2)\n backward = true\n else\n backward = false\n end\nelse\n fantasy = true\nend\n\nif fantasy\n puts \"fantasy\"\nelse\n if backward && forward\n puts \"both\"\n else\n if forward\n puts \"forward\"\n else\n if backward\n puts \"backward\"\n else\n puts \"fantasy\"\n end\n end\n end\nend"}], "src_uid": "c3244e952830643938d51ce14f043d7d"} {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n = gets.chomp.to_i\r\n a = gets.chomp.split(\" \").map(&:to_i)\r\n arr = Array.new(n,0)\r\n max = 0\r\n n.downto(1) do |i|\r\n ans = 0\r\n ii = i.dup\r\n ans = ii + a[ii-1]\r\n if ans > n\r\n arr[ii-1] += (ans - ii)\r\n max = [arr[i-1],max].max\r\n else\r\n arr[ii-1] += (ans + arr[ans-1] - ii)\r\n max = [arr[i-1],max].max\r\n end\r\n #end\r\n end\r\n puts max\r\nend", "positive_code": [{"source_code": "gets.to_i.times {\n n = gets.to_i\n xs = gets.split.map!(&:to_i)\n ys = Array.new(n) { 0 }\n ans = 0\n (0...n).reverse_each { |i|\n ys[i] = xs[i]\n ys[i] += ys[i + xs[i]] if i + xs[i] < n\n ans = ys[i] if ys[i] > ans\n }\n p ans\n}\n"}, {"source_code": "def solve\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n\r\n dp = Array.new(n + 1, 0)\r\n (n - 1).downto(0) do |i|\r\n dp[i] = a[i]\r\n dp[i] += dp[i + a[i]] if i + a[i] < n\r\n end\r\n # STDERR.puts dp.inspect\r\n puts dp.max\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n solve\r\nend"}, {"source_code": "#!/usr/bin/env ruby\r\n\r\ngets.to_i.times {\r\n n = gets.to_i\r\n nums = gets.split.map &:to_i\r\n max_num = 0\r\n dp = Array.new(n)\r\n (n - 1).downto(0).each do |index|\r\n nk = index + nums[index]\r\n if nk >= dp.size\r\n dp[index] = nums[index]\r\n else\r\n nk = index + nums[index]\r\n #puts \"(#{index}, #{nk}) => (#{nums[index]}, #{nums[nk]})\"\r\n dp[index] = nums[index] + dp[nk]\r\n end\r\n end\r\n #puts nums.to_s\r\n #puts dp.to_s\r\n puts dp.max\r\n}"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n dp = a\r\n (0...n - 1).reverse_each do |i|\r\n dp[i] += dp[i + a[i]] if i + a[i] < n\r\n end\r\n puts dp.max\r\nend"}, {"source_code": "require 'prime'\r\nt = gets.chomp.to_i\r\nt.times do\r\n n = gets.chomp.to_i\r\n arr = gets.chomp.split(' ').map(&:to_i)\r\n brr = [0] * (arr.size + 1)\r\n arr.each_with_index do |el, ind|\r\n new_ind = [ind + el, arr.size].min\r\n brr[new_ind] = [brr[new_ind], brr[ind] + el].max \r\n end\r\n puts brr.last\r\nend"}, {"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n a=gets.split.map(&:to_i)\r\n (n-1).downto(0) do |i|\r\n if i+a[i] 1\n\n# if n.index(\"8888888888888888888888888888888888888888888888888888888888888888\")\n# \tputs \"#{final}\"\t\n# else\n\tputs ans\n# end\n\n\n# n = gets.chomp\n# arr = Array.new(n.length-1,0)\n\n# i = 1\n# while i < n.length\n# \tif n[i].to_i + n[i-1].to_i == 9\n# \t\tarr[i] = 1\n# \t\ti += 1 \n# \tend\n# \ti += 1\n# end\n\n\n# puts \"#{arr}\"\n# final = []\n# arr.chunk{|x| x}.each do |r|\n# \t# puts \"#{r}\"\n# \tl = r[1].length\n# \tif r[0] == 1\n# \t\tputs \"#{r}\"\n# \t\tif l.even?\n# \t\t\tc = (l/2) + 1\n# \t\telsif l == 1\n# \t\t\tc = 1\n# \t\telse\n# \t\t\tc = l/2\n# \t\tend\n# \t\tfinal << c\n# \tend\n# end\n# ans = 1\n# # puts \"#{final}\"\n# ans *= final.inject(1,:*) if final.length > 1\n# puts ans", "positive_code": [{"source_code": "def run(a)\n cnt = 0\n acm = 1\n a[0...-1].each_with_index do |x,i|\n if x + a[i+1] == 9\n cnt = cnt + 1\n elsif cnt > 0\n acm = acm*((cnt/2)+1) if cnt % 2 == 0\n cnt = 0\n end\n end\n acm = acm*((cnt/2)+1) if cnt > 0 and cnt % 2 == 0\n acm\nend\n\nSTDIN.read.split(\"\\n\").each_with_index do |line,i|\n puts run(line.split(//).map{|x| x.to_i}).to_s\nend"}], "negative_code": [{"source_code": "n = gets.chomp\narr = Array.new(n.length-1,0)\n\nn.chars.each_cons(2).each_with_index do |a,i|\n\t# puts \"#{a[0]} #{a[1]}\"\n\tif a[0].to_i + a[1].to_i == 9\n\t\tarr[i] = 1\n\tend\nend\n# puts \"#{arr}\"\nfinal = []\narr.chunk{|x| x}.each do |r|\n\t# puts \"#{r}\"\n\tl = r[1].length\n\tif r[0] == 1\n\t\t# puts \"#{l}\"\n\t\tif l.even?\n\t\t\tc = (l/2) + 1\n\t\telsif l == 1\n\t\t\tc = 1\n\t\telse\n\t\t\tc = l/2\n\t\tend\n\t\tfinal << c\n\tend\nend\nans = 1\n# puts \"#{final}\"\nans *= final.inject(1,:*) if final.length > 1\nputs ans"}, {"source_code": "n = gets.chomp\narr = Array.new(n.length,0)\n\nn.chars.each_cons(2).each_with_index do |a,i|\n\t# puts \"#{a[0]} #{a[1]}\"\n\tif a[0].to_i + a[1].to_i == 9\n\t\tarr[i] = 1\n\tend\nend\n# puts \"#{arr}\"\ncount = 1\narr.chunk{|x| x}.each do |r|\n\t# puts \"#{r}\"\n\tl = r[1].length\n\tif r[0] == 1 && l > 1\n\t\t# puts \"#{l}\"\n\t\tif l.even?\n\t\t\tcount *= (l/2) + 1\n\t\telse\n\t\t\tcount *= l/2\n\t\tend\n\tend\nend\nputs count"}, {"source_code": "n = gets.chomp\narr = Array.new(n.length-1,0)\n\nn.chars.each_cons(2).each_with_index do |a,i|\n\t# puts \"#{a[0]} #{a[1]}\"\n\tif a[0].to_i + a[1].to_i == 9\n\t\tarr[i] = 1\n\tend\nend\n# puts \"#{arr}\"\nfinal = []\narr.chunk{|x| x}.each do |r|\n\t# puts \"#{r}\"\n\tl = r[1].length + 1\n\tif r[0] == 1\n\t\t# puts \"#{r}\"\n\t\tif l.odd?\n\t\t\tc = l/2 + 1\t\t\t\n\t\telse\n\t\t\tc = 1\n\t\tend\n\t\tfinal << c\n\tend\nend\nans = 1\n# puts \"#{final}\"\nans *= final.inject(1,:*) if final.length > 1\n\nif n.index(\"8888888888888888888888888888888888888888888888888888888888888888\")\n\tputs \"#{final}\"\t\nelse\n\tputs ans\nend\n\n\n# n = gets.chomp\n# arr = Array.new(n.length-1,0)\n\n# i = 1\n# while i < n.length\n# \tif n[i].to_i + n[i-1].to_i == 9\n# \t\tarr[i] = 1\n# \t\ti += 1 \n# \tend\n# \ti += 1\n# end\n\n\n# puts \"#{arr}\"\n# final = []\n# arr.chunk{|x| x}.each do |r|\n# \t# puts \"#{r}\"\n# \tl = r[1].length\n# \tif r[0] == 1\n# \t\tputs \"#{r}\"\n# \t\tif l.even?\n# \t\t\tc = (l/2) + 1\n# \t\telsif l == 1\n# \t\t\tc = 1\n# \t\telse\n# \t\t\tc = l/2\n# \t\tend\n# \t\tfinal << c\n# \tend\n# end\n# ans = 1\n# # puts \"#{final}\"\n# ans *= final.inject(1,:*) if final.length > 1\n# puts ans"}, {"source_code": "n = gets.chomp\narr = Array.new(n.length-1,0)\n\nn.chars.each_cons(2).each_with_index do |a,i|\n\t# puts \"#{a[0]} #{a[1]}\"\n\tif a[0].to_i + a[1].to_i == 9\n\t\tarr[i] = 1\n\tend\nend\n# puts \"#{arr}\"\nfinal = []\narr.chunk{|x| x}.each do |r|\n\t# puts \"#{r}\"\n\tl = r[1].length + 1\n\tif r[0] == 1\n\t\t# puts \"#{r}\"\n\t\tif l.odd?\n\t\t\tc = l/2 + 1\t\t\t\n\t\telse\n\t\t\tc = 1\n\t\tend\n\t\tfinal << c\n\tend\nend\nans = 1\n# puts \"#{final}\"\nans *= final.inject(1,:*) if final.length > 1\nputs ans\n\n\n# n = gets.chomp\n# arr = Array.new(n.length-1,0)\n\n# i = 1\n# while i < n.length\n# \tif n[i].to_i + n[i-1].to_i == 9\n# \t\tarr[i] = 1\n# \t\ti += 1 \n# \tend\n# \ti += 1\n# end\n\n\n# puts \"#{arr}\"\n# final = []\n# arr.chunk{|x| x}.each do |r|\n# \t# puts \"#{r}\"\n# \tl = r[1].length\n# \tif r[0] == 1\n# \t\tputs \"#{r}\"\n# \t\tif l.even?\n# \t\t\tc = (l/2) + 1\n# \t\telsif l == 1\n# \t\t\tc = 1\n# \t\telse\n# \t\t\tc = l/2\n# \t\tend\n# \t\tfinal << c\n# \tend\n# end\n# ans = 1\n# # puts \"#{final}\"\n# ans *= final.inject(1,:*) if final.length > 1\n# puts ans"}, {"source_code": "def run(a)\n cnt = 0\n acm = 1\n a[0...-1].each_with_index do |x,i|\n if x + a[i+1] == 9\n cnt = cnt + 1\n elsif cnt > 0\n acm = acm*cnt if cnt % 2 == 0\n cnt = 0\n end\n end\n acm = acm*cnt if cnt > 0 and cnt % 2 == 0\n acm\nend\n\nSTDIN.read.split(\"\\n\").each_with_index do |line,i|\n puts run(line.split(//).map{|x| x.to_i}).to_s\nend"}, {"source_code": "def run(a)\n a = a.map{|x| x.to_i}\n cnt = 0\n acm = 1\n a[0...-1].each_with_index do |x,i|\n if x + a[i+1] == 9\n cnt = cnt + 1\n elsif cnt > 0\n acm = acm*cnt if cnt % 2 == 1\n cnt = 0\n end\n end\n acm = acm*cnt if cnt % 2 == 1\n acm\nend\n\nSTDIN.read.split(\"\\n\").each_with_index do |line,i|\n #puts run(line.split(//).map{|x| x.to_i}).to_s\nend\n\nputs run(\"18\".split(//)).to_s\nputs run(\"181\".split(//)).to_s\nputs run(\"1818\".split(//)).to_s\nputs run(\"18181\".split(//)).to_s\nputs run(\"181818\".split(//)).to_s\nputs run(\"1818181\".split(//)).to_s\nputs run(\"18181818\".split(//)).to_s\nputs run(\"181818181\".split(//)).to_s\n\n\n"}, {"source_code": "def run(a)\n cnt = 0\n acm = 1\n a[0...-1].each_with_index do |x,i|\n if x + a[i+1] == 9\n cnt = cnt + 1\n elsif cnt > 0\n acm = acm*cnt\n cnt = 0\n end\n end\n acm = acm*cnt if cnt > 0\n acm\nend\n\nSTDIN.read.split(\"\\n\").each_with_index do |line,i|\n puts run(line.split(//).map{|x| x.to_i}).to_s\nend"}], "src_uid": "bb1e110a7f53e6f7d43ddced7407f3d1"} {"source_code": "t = gets.to_i\nt.times do\n\tn = gets.to_i\n\tarr = gets.split('').map(&:to_i)\n\tcheckment = n%2\n\tflag = false\n\tfor i in 1..n\n\t\tflag = true if i%2 == checkment && arr[i-1]%2 == checkment\n\tend\n\n\tif checkment == 1\n\t\tif flag\n\t\t\tputs 1\n\t\telse\n\t\t\tputs 2\n\t\tend\n\telse\n\t\tif flag\n\t\t\tputs 2\n\t\telse\n\t\t\tputs 1\n\t\tend\n\tend\nend", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n l = gets.to_i\n n = gets.to_i\n\n if l.odd?\n exist_odd = false\n\n n.digits.reverse.each_with_index do |x, i|\n next if i.odd?\n\n exist_odd |= x.odd?\n end\n\n if exist_odd\n puts 1\n else\n puts 2\n end\n else\n exist_even = false\n\n n.digits.reverse.each_with_index do |x, i|\n next if i.even?\n\n exist_even |= x.even?\n end\n\n if exist_even\n puts 2\n else\n puts 1\n end\n end\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n d = gets.chomp\n arr = d.split('').map(&:to_i)\n if arr.length == 1\n if arr[0].odd?\n puts 1\n else\n puts 2\n end\n else\n indexes = (1..arr.length).to_a\n r_positions = indexes.select(&:odd?)\n b_positions = indexes.select(&:even?)\n\n r_positions = r_positions.sort_by { |pos| arr[pos - 1].odd? ? 1 : -1 }\n b_positions = b_positions.sort_by { |pos| arr[pos - 1].even? ? 1 : -1 }\n\n key = if r_positions.length > b_positions.length\n arr[r_positions.last - 1]\n else\n arr[b_positions.last - 1]\n end\n if key.odd?\n puts 1\n else\n puts 2\n end\n end\nend\n"}], "negative_code": [], "src_uid": "c9225c915669e183cbd8c20b848d96e5"} {"source_code": "def double_string(strs, n)\r\n hash = {}\r\n strs.each do |i|\r\n hash[i] = true\r\n end\r\n ans = \"\"\r\n strs.each do |str|\r\n j = 0\r\n len = str.length\r\n\r\n found = false\r\n while j < len\r\n x = str[0,j+1]\r\n y = str[j+1, len]\r\n if hash.key?(x) && hash.key?(y)\r\n ans << \"1\"\r\n found = true\r\n break\r\n end\r\n j += 1\r\n end\r\n if !found\r\n ans << \"0\"\r\n end\r\n end\r\n puts ans\r\n ans\r\nend\r\nt = gets.to_i\r\ninputs = []\r\n(0..t-1).each do\r\n n = gets.to_i\r\n arr = []\r\n (0..n-1).each do |j|\r\n s = gets.strip\r\n arr.push(s)\r\n end\r\n inputs.push([arr, n])\r\nend\r\n\r\ninputs.each do |input|\r\n double_string(input[0], input[1])\r\nend\r\n", "positive_code": [{"source_code": "require 'set'\n\nt = gets.to_i\n\nt.times do\n n = gets.to_i\n a = Array.new(n) { gets.chomp }\n s = a.to_set\n ans = \"\"\n a.each do |x|\n flag = false\n (1 ... x.size).each do |l|\n if s.include? x[0, l] and s.include? x[l .. -1]\n ans << \"1\"\n flag = true\n break\n end\n end\n ans << \"0\" if not flag\n end\n puts ans\nend\n"}], "negative_code": [{"source_code": "class StringLength\r\n attr_accessor :str, :len\r\n\r\n def initialize(str, len)\r\n @str = str\r\n @len = len\r\n end\r\nend\r\n\r\ndef double_string(sorted, arr, n)\r\n ans = \"\"\r\n hash = arr.tally\r\n arr.each do |str|\r\n check = false\r\n l = str.length\r\n sorted.each do |obj|\r\n if obj.len < l\r\n sub = str.sub(obj.str, \"\")\r\n if obj.str.length == 1 && (obj.str+sub != str || sub+obj.str != str)\r\n next\r\n end\r\n if hash.key?(sub) && str!=sub\r\n ans << \"1\"\r\n check = true\r\n break\r\n end\r\n else\r\n break\r\n end\r\n end\r\n if !check\r\n ans << \"0\"\r\n end\r\n end\r\n puts ans\r\nend\r\nt = gets.to_i\r\ninputs = []\r\n(0..t-1).each do\r\n n = gets.to_i\r\n arr = []\r\n (0..n-1).each do |j|\r\n s = gets.strip\r\n arr.push(s)\r\n end\r\n inputs.push([arr, n])\r\nend\r\n\r\ninputs.each do |input|\r\n sorted = []\r\n input[0].each do |str|\r\n sorted.push(StringLength.new(str, str.length))\r\n end\r\n sorted = sorted.sort_by!{|obj| obj.len}\r\n double_string(sorted, input[0], input[1])\r\nend\r\n"}], "src_uid": "9683d5960247359b6b9066e96897d6f9"} {"source_code": "n = gets.to_i\n\ns=\"aabb\"\nn.times{|i|\n print s[i%4]\n}", "positive_code": [{"source_code": "#!ruby\n$><<'abba'.chars.cycle.first(gets.to_i).join\n"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn = gi\n\nx = \"aabb\" * ((n + 3) / 4)\n\nputs x[0...n]\n"}, {"source_code": "# your code goes here\nn=gets.to_i\nif n==1 then\n\tputs \"a\"\nelsif n==2 then\n\tputs \"aa\"\nelse\n\tn=n-2\n\tprint \"aa\"\n\t[\"b\",\"b\",\"a\",\"a\"].cycle{|e|\n\t\tprint e\n\t\tn-=1\n\t\tbreak if n==0\n\t}\n\tprint \"\\n\"\nend\n\n"}, {"source_code": "n=gets.to_i\ns=\"aabb\"*((n+3)/4)\nputs s[0,n]\n"}, {"source_code": "n=gets.to_i\nm=n/4\nr=n%4\ns='aabb'*m+'aabb'[0...r]\nputs s"}], "negative_code": [{"source_code": "#!ruby\n$><<'abc'.chars.cycle.first(gets.to_i).join\n"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\n\nn = gi\n\nx = \"aabc\" * ((n + 3) / 4)\n\nputs x[0...n]\n"}, {"source_code": "n=gets.to_i\nm=n/3\nr=n%3\ns='abc'*m+'abc'[0...r]\nputs s"}], "src_uid": "fbde86a29f416b3d83bcc63fb3776776"} {"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map(&:to_i).sort\nmax = a.max\nleft = 0\nright = (max ** (1/(n-1).to_f)).floor + 2\nmin_sum = 0\nif n < 33\n while right - left > 1\n mid = left + (right - left) / 2\n sum1 = 0\n sum2 = 0\n v = 1\n v2 = 1\n n.times do |i|\n v *= mid if i != 0\n v2 *= (mid+1) if i != 0\n sum1 += (a[i]-v).abs\n sum2 += (a[i]-v2).abs\n end\n if sum1 > sum2\n left = mid\n min_sum = sum2\n else\n right = mid\n min_sum = sum1\n end\n end\nelse\n n.times do |i|\n min_sum += (a[i]-1).abs\n end\nend\nputs min_sum", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort!()\nmx = 10 ** 18\nif n <= 2\n puts a[0] - 1\nelse\n res = a.sum - n\n (1...10 ** 9).each do |i|\n cur, pow = 0, 1\n (0...n).each do |j|\n cur += (a[j] - pow).abs\n pow *= i\n break if pow > mx\n end\n break if pow > mx or pow / i > res + a[-1]\n res = [res, cur].min\n end\n puts res\nend"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map(&:to_i).sort\nmax = a.max\nleft = 0\nright = (max ** (1/(n-1).to_f)).floor + 2\nmin_sum = 0\nif n < 32\n while right - left > 1\n mid = left + (right - left) / 2\n sum1 = 0\n sum2 = 0\n v = 1\n v2 = 1\n n.times do |i|\n v *= mid if i != 0\n v2 *= (mid+1) if i != 0\n sum1 += (a[i]-v).abs\n sum2 += (a[i]-v2).abs\n end\n if sum1 > sum2\n left = mid\n min_sum = sum2\n else\n right = mid\n min_sum = sum1\n end\n end\nelse\n n.times do |i|\n min_sum += (a[i]-1).abs\n end\nend\nputs min_sum"}, {"source_code": "def pow(x,n)\n if n == 0\n 1\n elsif n % 2 == 0\n pow((x+x), n/2)\n else\n x + pow(x, n-1)\n end\nend\nn = gets.to_i\na = gets.chomp.split(\" \").map(&:to_i).sort\nleft = 0\nright = (a.max ** 0.5).floor + 2\nmin_sum = 1000000000000000\nwhile right - left > 1\n mid = left + (right - left) / 2\n\n sum = 0\n n.times do |i|\n v = mid.pow(i)\n sum += (a[i]-v).abs\n end\n\n if sum < min_sum\n min_sum = sum\n left = mid\n else\n right = mid\n end\nend\nputs min_sum"}], "src_uid": "54e9c6f24c430c5124d840b5a65a1bc4"} {"source_code": "t = gets.to_i\nt.times do\n n, k = gets.split.map(&:to_i)\n nums = gets.split.map(&:to_i)\n nums.map! {|num| k - (num % k)}\n nums.reject! {|num| num == k}\n \n if nums.count == 0\n puts 0\n else\n nums_t = nums.tally\n max_cnt = nums_t.values.max\n\n max_key = nums_t.select {|k, v| v == max_cnt}.map(&:first).max\n puts (max_cnt - 1) * k + max_key + 1\n end\nend\n", "positive_code": [{"source_code": "def run\n n, k = gets.chomp.split(\" \").map(&:to_i)\n a = gets.chomp.split(\" \").map(&:to_i)\n b = a.group_by{ |e| e % k }.reduce(Hash::new()){|acc, (k, v)| acc[k] = v.size; acc}\n b.delete(0)\n\n if b.size == 0\n puts 0\n return\n end\n\n m = b.values.max\n m_key = b.keys.sort.find{|key| b[key] == m}\n\n c = (m - 1) * k + k - m_key + 1\n\n puts c\nend\n\n\ndef main\n t = gets.chomp.to_i\n\n t.times do\n run\n end\nend\n\nmain\n"}, {"source_code": "gets.to_i.times do\n\tn, k = gets.split.map(&:to_i)\n\ta = gets.split.map(&:to_i)\n\tp a.map { -_1 % k }.tally.map { |val, cnt|\n\t\t\tval > 0 ? val + k * (cnt - 1) + 1 : 0\n\t }.max\nend\n"}], "negative_code": [], "src_uid": "a8b4c115bedda3847e7c2e3620e3e19b"} {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nm = {}\nused = {}\nnm = 0\nc = 0\nans = []\na.each do |x|\n if x > 0\n if m[x] || used[x]\n puts -1\n exit\n end\n m[x] = true\n nm += 1 \n end\n if x < 0\n if not m[-x]\n puts -1\n exit\n end\n m[-x] = false\n used[-x] = true\n nm -= 1\n end\n c += 1\n if nm == 0\n ans << c\n c = 0\n used = {}\n end\nend\nif nm == 0\n puts ans.size\n puts ans.join(' ')\nelse\n puts -1\nend\n", "positive_code": [{"source_code": "d = gets.chomp.to_i\nevents = gets.split(\" \")\ncp = []\njoin = []\nout = []\ncheck = false\nfix = 0\n\nsolution = []\nevents.map{|w|\nw=w.to_i\n\nif w.to_s[0]==\"-\"\nif join[w.to_s.split(\"-\")[1].to_i]\njoin[w.to_s.split(\"-\")[1].to_i] = false\nfix-=1\nelse\nputs \"-1\"\ncheck = true\nexit\nend\n\nend\n\nif w.to_s[0]!=\"-\"\nif join[w]\nputs \"-1\"\ncheck = true\nexit\nelse\nfix+=1\njoin[w] = true\nend\nend\n\ncp.push(w)\n\nif fix == 0\nif cp.size == cp.uniq.size\nsolution.push(cp)\ncp = []\nelse\nputs \"-1\"\ncheck = true\nexit\nend\nend\n\n}\nif solution.size > 0 and cp.size == 0\nputs solution.size\ns=[]\nsolution.map{|w|\ns.push(w.size)\n}\nputs s.join(\" \")\ncheck = true\nexit\nend\nif !check then puts \"-1\" end"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nentered = {}\ncnt = 0\nlen = 0\nans = []\nn.times do |i|\n v = a[i]\n len += 1\n if v > 0\n if !entered[v].nil?\n p -1\n exit\n else\n entered[v] = 1\n cnt += 1\n end\n else\n if entered[-v].nil? || entered[-v] != 1\n p -1\n exit\n else\n entered[-v] = -1\n cnt -= 1\n if cnt == 0\n ans << len\n len = 0\n entered = {}\n end\n end\n end\nend\nif cnt > 0\n p -1\nelse\n p ans.length\n puts ans.join(\" \")\nend"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nentered = {}\ncnt = 0\nlen = 0\nans = []\nn.times do |i|\n v = a[i]\n len += 1\n if v > 0\n if !entered[v].nil?\n p -1\n exit\n else\n entered[v] = 1\n cnt += 1\n end\n else\n if entered[-v].nil? || entered[-v] != 1\n p -1\n exit\n else\n entered[-v] = -1\n cnt -= 1\n if cnt == 0\n ans << len\n len = 0\n entered = {}\n end\n end\n end\nend\np ans.length\nputs ans.join(\" \")"}, {"source_code": "d = gets.chomp.to_i\nevents = gets.split(\" \").map{|x|x.to_i}\ncp = []\njoin = []\nout = []\n\nsolution = []\nevents.size.times{|w|\nif events[w].to_s[0]==\"-\"\nif join.include?(events[w].to_s.split(\"-\")[1].to_i)\njoin.delete(events[w].to_s.split(\"-\")[1].to_i)\nelse\nputs \"-1\"\nbreak\nend\nend\n\nif events[w].to_s[0]!=\"-\"\nif join.include?(events[w])\nputs \"-1\"\nbreak\nelse\njoin.push(events[w])\nend\nend\n\ncp.push(events[w])\n\nif join.size == 0\nif cp.size == cp.uniq.size\nsolution.push(cp)\ncp = []\nelse\nputs \"-1\"\nbreak\nend\nend\n\n}\nif solution.size > 0\nputs solution.size\ns=[]\nsolution.size.times{|w|\ns.push(solution[w].size)\n}\nputs s.join(\" \")\nend"}, {"source_code": "d = gets.chomp.to_i\nevents = gets.split(\" \").map{|x|x.to_s}\ncp = []\njoin = []\nout = []\n\nsolution = []\nevents.map{|w|\nif w[0]==\"-\"\nif join.include?(w.split(\"-\")[1])\njoin.delete(w.split(\"-\")[1])\nelse\nputs \"-1\"\nbreak\nend\nend\n\nif w[0]!=\"-\"\nif join.include?(w)\nputs \"-1\"\nbreak\nelse\njoin.push(w)\nend\nend\n\ncp.push(w)\n\nif join.size == 0\nif cp.size == cp.uniq.size\nsolution.push(cp)\ncp = []\nelse\nputs \"-1\"\nbreak\nend\nend\n\n}\nif solution.size > 0 and cp.size == 0\nputs solution.size\ns=[]\nsolution.size.times{|w|\ns.push(solution[w].size)\n}\nputs s.join(\" \")\nelse\nputs \"-1\"\nend"}, {"source_code": "d = gets.chomp.to_i\nevents = gets.split(\" \").map{|x|x.to_i}\ncp = []\njoin = []\nout = []\ncheck = false\n\nsolution = []\nevents.size.times{|w|\nif events[w].to_s[0]==\"-\"\nif join.include?(events[w].to_s.split(\"-\")[1].to_i)\njoin.delete(events[w].to_s.split(\"-\")[1].to_i)\nelse\nputs \"-1\"\ncheck = true\nbreak\nend\nend\n\nif events[w].to_s[0]!=\"-\"\nif join.include?(events[w])\nputs \"-1\"\ncheck = true\nbreak\nelse\njoin.push(events[w])\nend\nend\n\ncp.push(events[w])\n\nif join.size == 0\nif cp.size == cp.uniq.size\nsolution.push(cp)\ncp = []\nelse\nputs \"-1\"\ncheck = true\nbreak\nend\nend\n\n}\nif solution.size > 0\nputs solution.size\ns=[]\nsolution.size.times{|w|\ns.push(solution[w].size)\n}\nputs s.join(\" \")\ncheck = true\nend\nif !check then puts \"-1\" end"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nm = {}\nused = {}\nnm = 0\nc = 0\nans = []\na.each do |x|\n if x > 0\n if m[x] || used[x]\n puts -1\n exit\n end\n m[x] = true\n nm += 1 \n end\n if x < 0\n if not m[-x]\n puts -1\n exit\n end\n m[-x] = false\n used[-x] = true\n nm -= 1\n end\n c += 1\n if nm == 0\n ans << c\n c = 0\n used = {}\n end\nend\nputs ans.size\nputs ans.join(' ')\n"}], "src_uid": "17f73ae0347b551fb5e287322785c8a4"} {"source_code": "t = readline.chomp;\nss = t.gsub(\"a\", \"\");\nk = ss.length;\nif k % 2 == 0 && ss[0 ... k/2] == t[t.length - k/2 .. -1]\n puts t[0 ... t.length - k/2];\nelse\n puts \":(\"\nend\n", "positive_code": [{"source_code": "s = gets.chomp\nt = s.delete(\"a\")\nn = t.length\nif n.even? && t[0,n/2] == t[n/2,n/2] && !s[s.length-n/2,n/2].include?(\"a\")\n puts s[0,s.length-n/2]\nelse\n puts \":(\"\nend\n"}], "negative_code": [], "src_uid": "b5bcb6d78daacd56362fd76e35b903ac"} {"source_code": "n,b = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\ns = 0\ndiff = []\n(0..n-2).each do |i|\n\ta = arr[i]\n\tmax = arr[(i+1)..-1].max\n\tif a <= b\n\t\tstocks = b/a\n\t\tleft = b % a\n\t\tsell = stocks * max\n\t\tdiff << sell + left\n\tend\nend\ndiff << b\nputs diff.max", "positive_code": [{"source_code": "n,b = gets.chomp.split(/ /).map!{|x| x.to_i}\na = gets.chomp.split(/ /).map!{|x| x.to_i}\n\nar = Array.new\nfor i in 1..n-1\n\tif a[i] > a[i-1]\n\t\tar.push( [ a[i-1], a[i] ] )\n\tend\n\tfor j in 0..ar.length-1\n\t\tar[j][1] = a[i] if ar[j][1] < a[i]\n\tend\nend\n\nar.sort!{|x,y| (b / y[0]) * (y[1]-y[0]) <=> (b / x[0]) * (x[1]-x[0]) }\n\nif ar.length > 0\n\tb += (b / ar[0][0]) * (ar[0][1]-ar[0][0])\nend\nputs b\n"}, {"source_code": "n, b = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\nmx = b\n(1...a.length).each do |x|\n\t(0...x).each do |y|\n\t\tr = b % a[y]\n\t\tmx = [mx, r + (b / a[y]) * a[x]].max\n\tend\nend\nputs mx"}, {"source_code": "n, b = gets.split.map { |v| v.to_i }\na = gets.split.map { |v| v.to_i }\n\nbest = b\n\nn.times do |day|\n min, max = a[0, day + 1].min, a[day .. -1].max\n profit = max * (b / min) + b % min\n best = profit if profit > best\nend\n\nputs best\n"}], "negative_code": [], "src_uid": "2c9133650d831fa6ab4c11661bcb9cbb"} {"source_code": "gets.to_i.times do\n n, k = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n s = []\n (0...n).each do |j|\n s << j + 1 if a[j] % 2 != 0\n end\n sz = s.size\n if sz >= k and sz % 2 == k % 2\n puts \"YES\"\n print s[0...k-1].join(' '), ' ', n\n puts\n else\n puts \"NO\"\n end\nend\n", "positive_code": [{"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\n\ndef puts_yesno(can) puts(can ? 'Yes' : 'No') end\ndef putsend(s) puts s; exit end\ndef debug(k,v) puts \"#{k}:#{v}\" end\n########### ( \u02d8\u03c9\u02d8 )\uff7d\uff94\uff67\u2026 ###########\nq = gi\nans = []\nq.times do\n n, k = gsmi\n a = gsmi\n odd_c=0\n n.times do |i|\n odd_c+=1 if a[i]%2==1\n end\n str = ''\n if odd_c d\n\nprint ans"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\narr = [].tap do |a|\n m.times { a << (gets.chomp.chars.any? { |b| b != '1' }) }\nend\n\nif arr.all? { |a| a != true }\n puts 0\nelse\n puts arr.chunk { |a| a }.select { |a, _| a }.map { |_, a| a.length }.max\nend\n"}, {"source_code": "gets\np $<.read.lines.chunk{|s| s[?0]}.map{|_, a| a.size}.max || 0"}, {"source_code": "size , n = gets.split(\" \").map(&:to_i) \nwon = false \n max_count = -999 \nsteak = 0 \nn.times do \n \n \n\n \n values = gets \n \n if values.count(\"0\")>=1 \n \n \n steak+=1 \n \n else \n \n won =false \n steak = 0 \n end \n if max_countma)\nma=t\nend\nt=0\nelse \nt+=1\nend\nend\nif (t>ma)\nma=t\nend\nputs ma.inspect\n"}, {"source_code": "n,d = gets.split.map{|a| Integer(a)}\nas = (1..d).map{|_| gets.chomp}\n .slice_before{|x| x==\"1\"*n} \n .to_a\n .collect\n .with_index{|x,i| if i!=0 then x.drop(1) else x end}\n\nas[0].delete(\"1\"*n)\nputs as.map{|a| a.length}.max"}, {"source_code": "n, d = gets.split.map(&:to_i)\nans = 0\ncon = 0\nd.times do\n if gets.chomp.chars.include?('0')\n con += 1\n else\n con = 0\n end\n ans = [con, ans].max\nend\nputs ans"}, {"source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\nma=0\nt=0\ntemp=\"\"\na[1].times do\ntemp=gets.chomp.split(\"\")\nif(temp.count('1')==a[0])\n\nif(t>ma)\nma=t\nend\nt=0\nelse \nt+=1\nend\nend\nif (t>ma)\nma=t\nend\nputs ma.inspect"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nans=0\nc=0\nm.times{\n\ts=gets.chomp\n\tif s.index(\"0\") then\n\t\tc=c+1\n\telse\n\t\tc=0\n\tend\n\tans=[ans,c].max\n}\nputs ans\n\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nmax = 0\ncurrent_streak = 0\nd.times do |di|\n\ts = gets.chomp\n\tones = s.count('1')\n\tzeros = s.count('0')\n\t# puts ones\n\t# puts zeros\n\n\tif ones != n\n\t\tcurrent_streak += 1\n\telse\n\t\tcurrent_streak = 0\n\tend\n\n\tif max < current_streak\n\t\tmax = current_streak\t\t\n\tend\nend\n\nputs max"}, {"source_code": "c=0;maxc=0;gets\nwhile s=gets do\n if s.include?\"0\"\n c+=1\n maxc=c if c>maxc\n else\n c=0\n end\nend\nputs maxc\n"}, {"source_code": "n, d = gets.chomp.split.map(&:to_i)\ncnt = 0\nans = 0\nd.times do\n str = gets.chomp\n if str == '1' * n\n ans = [ans, cnt].max\n cnt = 0\n else\n cnt += 1\n end\n ans = [ans, cnt].max\nend\n\nputs ans\n"}, {"source_code": "nd = gets.chomp.split\nd = nd[1].to_i\n\na = []\nfor i in (0..d-1)\n\tx = gets.chomp\n\ta[i] = x.split(\"\")\nend\ncount = 0\narr = []\nfor i in (0..d-1)\n\tif a[i].include?(\"0\")\n\t\tcount += 1\n\t\tarr << count\n\telse \n\t\tcount = 0\n\t\tarr << count\n\tend\nend\n\nprint arr.max"}, {"source_code": "nd = gets.chomp.split\nd = nd[1].to_i\n\na = []\nfor i in (0..d-1)\n\tx = gets.chomp\n\ta[i] = x.split(\"\")\nend\ncount = 0\narr = []\nfor i in (0..d-1)\n\tif a[i].include?(\"0\")\n\t\tcount += 1\n\t\tarr << count\n\telse \n\t\tcount = 0\n\t\tarr << count\n\tend\nend\nprint arr.max"}, {"source_code": "gets\np $<.chunk{|s| s.include? '0'}.select(&:first).map(&:last).map(&:size).max || 0"}, {"source_code": "gets\np $<.read.lines.chunk{|s| s[?0]}.map{|_, a| a.size}.max || 0\n"}, {"source_code": "_, d = gets.split.map(&:to_i)\np d.times.map{gets}.chunk{|s| s[?0]}.map{|_, a| a.size}.max || 0\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\nans = 0\ncur = 0\nd.times do |i|\n cur = gets.chomp.include?('0') ? cur + 1 : 0\n ans = [ans, cur].max\nend\nputs ans\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\narr = []\ncnt = 0\nfor i in 0...d\n opp = gets.chomp\n if opp =~ /[0]/\n cnt += 1\n else\n arr << cnt\n cnt = 0\n end\nend\narr << cnt\n\nputs arr.max\n"}, {"source_code": "n, d = gets.split.map &:to_i\nans, c = 0, 0\nd.times do\n if gets.strip == '1'*n\n c = 0\n else\n c += 1\n end\n ans = [ans, c].max\nend\nputs ans\n"}, {"source_code": "n, d = gets.chomp.split(' ').map(&:to_i)\ndays = []\n\nd.times do\n\tdays << gets.chomp.split('').map(&:to_i)\nend\n\ncon = []\nnum = 0\n\ndays.each do |day|\n\tif day.index(0) != nil\n\t\tnum += 1\n\telse\n\t\tcon << num\n\t\tnum = 0\n\tend\nend\n\ncon << num\n\nputs con.max\n\n"}, {"source_code": "#!/usr/bin/ruby\ngets\na=$<.map{|e|e.count('0')==0}\nr=c=0\na.each{|e|\n\tif e\n\t\tc=0\n\telse\n\t\tr=[r,c+=1].max\n\tend\n}\np r"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\ngets\na=$<.map{|e|e.count('0')==0}\nr=c=0\na.each{|e|\n\tif e\n\t\tr=max[r,c+=1]\n\telse\n\t\tc=0\n\tend\n}\np r"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\narr = [].tap do |a|\n m.times { a << (gets.chomp.chars.any? { |b| b != '1' }) }\nend\n\nputs arr.chunk { |a| a }.select { |a, _| a }.map { |_, a| a.length }.max\n"}, {"source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\nma=0\nt=0\ntemp=\"\"\na[1].times do\ntemp=gets.chomp.split(\"\")\nif(temp.count('1')==a[0])\n\nif(t>ma)\nma=t\nend\nt=0\nelse \nt+=1\nend\nend\nputs ma.inspect\n"}, {"source_code": "n,d = gets.split.map{|a| Integer(a)}\nputs (1..d).map{|_| gets.chomp}\n .slice_before{|x| x==\"1\"*n} \n .to_a\n .collect\n .with_index{|x,i| if i!=0 then x.drop(1).length else x.length end}\n .max"}, {"source_code": "gets\np $<.map{|s| s.chomp.chars.min}.join.split('1').map(&:size).max"}, {"source_code": "gets\nputs $<.chunk{|s| s.include? '0'}.select(&:first).map(&:last).map(&:size).max"}, {"source_code": "gets\np $<.chunk{|s| s.include? '0'}.select(&:first).map(&:last).map(&:size).max rescue 0"}, {"source_code": "_, d = gets.split.map(&:to_i)\np d.times.map{gets}.chunk{|s| s[?0]}.map{|_, a| a.size}.max\n"}, {"source_code": "n, d = gets.split.map(&:to_i)\narr = []\ncnt = 0\nfor i in 0...d\n opp = gets.chomp\n if opp =~ /[0]/\n cnt += 1\n else\n arr << cnt\n cnt = 0\n end\nend\n\nputs (arr.empty? ? cnt : arr.max)\n"}], "src_uid": "a6ee741df426fd2d06fdfda4ca369397"} {"source_code": "gets.to_i.times do\n\ta, b = gets.split.map &:to_i\n\tx = (a + b - 1) / b * b\n\tputs x - a\nend", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n a, b = gets.split.map(&:to_i)\n res = 0\n if a%b ==0\n puts 0\n else\n puts b-a%b\n end\nend\n"}, {"source_code": "file = File.exist?('in.in') ? File.new('in.in', 'r') : STDIN\n\nt = file.gets.to_i\ni = 0\n\nwhile i < t\n a, b = file.gets.split.map(&:to_i)\n\n if (a % b) == 0\n puts 0 \n else\n factor = (a / b) + 1\n goal = factor * b\n moves = goal - a\n puts moves\n end\n i += 1\nend\n\n"}, {"source_code": "a = gets.to_i\nwhile a > 0\n x, y = gets.split\n x = x.to_i\n y = y.to_i\n puts (y-(x%y))%y\n a = a-1\nend\n"}, {"source_code": "N = gets.to_i\narr = N.times.map{gets.split.map(&:to_i)}\n\narr.each do |a|\n if a[0] % a[1] == 0\n puts 0\n else\n puts a[1] - a[0] % a[1]\n end\nend"}, {"source_code": "# Divisibility Problem\ngets.to_i.times do\n mult = gets.rstrip.split\n\n a = mult[0].to_i\n b = mult[1].to_i\n if a%b == 0\n puts 0\n else\n puts b - a%b\n end\nend\n"}, {"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n a, b = gets.split.map(&:to_i)\n q, r = a/b, a%b\n\n if r == 0\n puts \"0\"\n else\n puts (q+1)*b - a\n end\n}"}, {"source_code": "t = gets.to_i\nt.times do\n a, b = gets.split.map(&:to_i)\n r = a % b\n puts (r == 0) ? 0 : (b - r)\nend\n"}, {"source_code": "n = gets.to_i\n\nwhile n!=0\n split = gets.split\n a = split[0].to_i\n b = split[1].to_i\n puts a%b == 0 ? 0 : b-a%b\n n-=1\nend"}, {"source_code": "for run in 0...gets.to_i\n\tnums = gets.split(\" \").map { |i| i.to_i }\n\t(nums[0] % nums[1] != 0) ? (puts nums[1] - (nums[0] % nums[1])) : (puts \"0\")\nend"}, {"source_code": "gets.to_i.times do\n a, b = gets.split.map &:to_i\n puts (b - a%b)%b\nend\n"}, {"source_code": "n = gets.to_i\n\n1.upto(n) do \n a, b = gets.split(' ').map(&:to_i)\n puts a % b == 0 ? 0 : b - a%b\nend\n"}, {"source_code": "# frozen_string_literal: true\n\ntest = gets.to_i\ntest.times do\n a, b = gets.chomp.split.map(&:to_i)\n if (a % b).zero?\n puts 0\n else\n puts (a / b + 1) * b - a\n end\nend\n"}, {"source_code": "t = gets.to_i\n(1..t).each do\n arr = gets.split(' ')\n a = arr[0].to_i\n b = arr[1].to_i\n puts (b-(a.modulo(b))).modulo(b)\n\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n a, b = gets.split.map(&:to_i)\n res = 0\n if a%b ==0\n puts 0\n else\n puts b-a%b\n end\nend\n"}], "negative_code": [{"source_code": "n = gets.to_i\n\nwhile n!=0\n split = gets.split\n a = split[0].to_i\n b = split[1].to_i\n k = 0\n while a%b != 0\n a+=1\n k+=1\n end\n puts k\n n-=1\n puts 'n= ' + n.to_s\nend"}], "src_uid": "d9fd10700cb122b148202a664e7f7689"} {"source_code": "STR = ('WB' * 51).freeze\n\n1.upto(gets.to_i) do\n n, m = gets.split(' ').map(&:to_i)\n\n arr = 1.upto(n).map { |i| STR[i%2, m] }\n\n if arr.last.chars.last == 'W'\n arr.last[arr.last.length-1] = 'B'\n elsif arr.last.chars.first == 'W'\n arr.last[0] = 'B'\n end\n\n puts arr.join(\"\\n\")\nend\n", "positive_code": [{"source_code": "# https://codeforces.com/problemset/problem/1333/A\n\ngets.to_i.times do\n n, m = gets.split(' ').map(&:to_i)\n\n puts \"B\" * m\n (n-1).times do\n puts \"B\" * (m-1) + \"W\"\n end\nend"}, {"source_code": "1.upto(gets.chomp.to_i) do |t|\n n,m = gets.chomp.split.map(&:to_i)\n if n > 1 && m > 1\n puts 'W' + 'B' *(m-1)\n (n-1).times { puts 'B'*m }\n elsif n == 1 && m > 2\n puts 'BWB' + 'B'*(m-3)\n elsif m == 1 && n > 2\n puts %w(B W B) + ['B']*(n-3)\n end\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n, m = gets.split.map(&:to_i)\n for i in 0...n do\n s = \"\"\n for j in 0...m do\n if (n * m) % 2 == 0 && i == 0 && j == 1\n s += \"B\"\n else\n s += ((i + j) % 2 == 0) ? \"B\" : \"W\"\n end\n end\n puts s\n end\nend\n"}], "negative_code": [{"source_code": "STR = ('WB' * 51).freeze\n\n1.upto(gets.to_i) do\n n, m = gets.split(' ').map(&:to_i)\n\n 1.upto(n) do |i|\n s = STR[i%2, m]\n\n s[s.size - 1] = 'B' if i==n && (n*m).even?\n\n puts s\n end\nend\n"}], "src_uid": "2b37f27a98ec8f80d0bff3f7ae8f2cff"} {"source_code": "for i in gets.chomp.to_i.times do\n d = gets.chomp.to_i\n delta = d*d - 4*d\n if delta < 0\n puts 'N'\n else \n puts \"Y \" + ((d + Math.sqrt(delta))/2.0).to_s + \" \" + ((d - Math.sqrt(delta))/2.0).to_s\nend\nend", "positive_code": [{"source_code": "=begin\nn = gets.chomp.to_i\n\narr = gets.split(\" \")\narr = arr.map { |element| element.to_i }\nsum = arr.inject(0){|sum,x| sum + x }\n\n=end\n\nn = gets.chomp.to_i\narr = []\n\nn.times do |x|\n\tarr<= 0 \n\t\tb = (d + Math.sqrt(x))/2\n\t\ta = d/b\n\t\ta = 0.0 if b == 0\n\t\tputs \"Y \"+a.to_s+\" \"+b.to_s\n\telse\n\t\tputs \"N\"\n\tend\nend\n"}, {"source_code": "gets;$<.each{|e|\nn=e.to_i\nd=n*(n-4)\nputs d<0 ? :N : ('Y %.9f %.9f'%[n-x=(n-d**0.5)/2,x])\n}"}], "negative_code": [{"source_code": "=begin\nn = gets.chomp.to_i\n\narr = gets.split(\" \")\narr = arr.map { |element| element.to_i }\nsum = arr.inject(0){|sum,x| sum + x }\n\n=end\n\nn = gets.chomp.to_i\narr = []\n\nn.times do |x|\n\tarr<= 0 \n\t\tb = (d + Math.sqrt(x))/2\n\t\ta = d/b\n\t\ta = 0.0 if b == 0\n\t\tp \"Y \"+a.to_s+\" \"+b.to_s\n\telse\n\t\tp \"N\"\n\tend\nend\n"}, {"source_code": "=begin\nn = gets.chomp.to_i\n\narr = gets.split(\" \")\narr = arr.map { |element| element.to_i }\nsum = arr.inject(0){|sum,x| sum + x }\n\n=end\n\nn = gets.chomp.to_i\narr = []\n\nn.times do |x|\n\tarr<= 0 \n\t\tb = (d + Math.sqrt(x))/2\n\t\ta = d/b\n\t\ta = 0.0 if b == 0\n\t\tputs \"Y \"+a.to_s+\" \"+b.to_s\n\telse\n\t\tp \"N\"\n\tend\nend\n"}, {"source_code": "gets;$<.each{|e|\nn=e.to_i\nd=n*(n-4)\nputs d<0 ? :N : ('Y %f %f'%[x=(n-d**0.5)/2,n-x])\n}"}, {"source_code": "gets;$<.each{|e|\nn=e.to_i\nd=n*(n-4)\nputs d<0 ? :N : ('Y %f %f'%[n-x=(n-d**0.5)/2,x])\n}"}], "src_uid": "6f5d41346419901c830233b3bf5c9e65"} {"source_code": "class Solver\n\tdef main\n\t\tn = gets.to_i\n\t\th = gets.split.map { |x| x.to_i }\n\t\tpre_max = Array.new(n + 2, 0)\n\t\tsuf_min = Array.new(n + 2, 1e9.to_i)\n\t\t1.upto(n) do |i|\n\t\t\tpre_max[i] = [pre_max[i - 1], h[i - 1]].max\n\t\tend\n\t\tn.downto(1) do |i|\n\t\t\tsuf_min[i] = [suf_min[i + 1], h[i - 1]].min\n\t\tend\n\t\tgap = (1...n).count { |i| pre_max[i] <= suf_min[i + 1] }\n\t\tputs gap + 1\n\tend\nend\n\nSolver.new.main\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\nhs = gets.chomp.split.map(&:to_i)\nlmaxs = Array.new(n)\nrmins = Array.new(n)\n\nlmaxs[0] = hs[0]\nrmins[-1] = hs[-1]\nfor i in 1...n\n ri = n - i - 1\n lmaxs[i] = [lmaxs[i - 1], hs[i]].max\n rmins[ri] = [rmins[ri + 1], hs[ri]].min\nend\n\ncnt = 1\nfor i in 0...n - 1\n f = true\n f &&= lmaxs[i] <= rmins[i + 1]\n cnt += 1 if f\nend\nputs cnt\n"}, {"source_code": "n = gets.chomp.to_i\nh = gets.split(\" \").map{|i| i.to_i}\nh = [0]+h\nhmax = [0]*(n+1)\nhmin = [0]*(n+1)\nhmax[1] = h[1]\nhmin[n] = h[n]\nfor i in 2..n\n\thmax[i] = [hmax[i-1], h[i]].max\nend\nfor i in (1..(n-1)).to_a.reverse\n\thmin[i] = [hmin[i+1], h[i]].min\nend\ns = 1\nfor i in 1...n\n\tif hmax[i] <= hmin[i+1]\n\t\ts +=1\n\tend\nend\nputs s\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nhs = gets.chomp.split.map(&:to_i)\nlmins = Array.new(n)\nlmaxs = Array.new(n)\nrmins = Array.new(n)\nrmaxs = Array.new(n)\n\nlmins[0] = hs[0]\nlmaxs[0] = hs[0]\nrmins[-1] = hs[-1]\nrmaxs[-1] = hs[-1]\nfor i in 1...n\n ri = n - i - 1\n lmins[i] = [lmins[i - 1], hs[i]].min\n lmaxs[i] = [lmaxs[i - 1], hs[i]].max\n rmins[ri] = [rmins[ri + 1], hs[ri]].min\n rmaxs[ri] = [rmaxs[ri + 1], hs[ri]].max\nend\n\ncnt = 1\nfor i in 0...n - 1\n if lmins[i] <= rmins[i + 1] && rmaxs[i] <= rmaxs[i + 1]\n cnt += 1\n end\nend\nputs cnt\n"}, {"source_code": "n = gets.chomp.to_i\nhs = gets.chomp.split.map(&:to_i)\n\nis = Hash.new(-1)\nhs.each.with_index do |h, i|\n is[h] = [is[h], i].max\nend\n\ncnt = 0\nidx = -1\nhs.sort.uniq.each do |h|\n if idx < is[h]\n cnt += 1\n idx = is[h]\n end\nend\n\nputs cnt\n"}], "src_uid": "c1158d23d3ad61c346c345f14e63ede4"} {"source_code": "gets.to_i.times {\n a, b=gets.split.map(&:to_i).minmax\n puts [a+a, b].max**2\n}\n", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n\ta,b = gets.split.map(&:to_i)\n\tputs [[a,b].max, [a,b].min*2].max ** 2\nend"}, {"source_code": "gets.strip.to_i.times do |t|\n a, b = gets.strip.split(' ').map(&:to_i)\n puts [[2 * a, b].max ** 2, [2 * b, a].max ** 2].min\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do |testcase|\n (a,b) = gets.split.map(&:to_i)\n puts [[2*a , b].max , [2*b , a].max].min ** 2\nend"}, {"source_code": "n = gets.to_i\n\n1.upto n do\n a, b = gets.split.map(&:to_i)\n if a == b\n puts ((a * 2) ** 2)\n else\n if [a,b].max > ([a,b].min * 2)\n puts ([a,b].max ** 2)\n else\n puts (([a,b].min * 2) ** 2)\n end\n end\nend"}, {"source_code": "gets.to_i.times {\n a, b = gets.split.map { |v|\n v.to_i\n }\n if a == b\n puts (a * 2) ** 2\n else\n if a > b\n a, b = b, a\n end\n a2 = a * 2\n if a2 < b\n puts b * b\n else\n puts a2 * a2\n end\n end\n}\n"}, {"source_code": "i = gets.chomp.to_i\n\ndef minimalsquare(a, b)\n if a < b\n minimal = Math.sqrt((a * 2) ** 2).ceil\n minimal2 = Math.sqrt((a * b) * 2).ceil\n if (minimal * minimal) >= (minimal2 * minimal2)\n return minimal * minimal\n else\n if minimal2 >= b\n return minimal2 * minimal2\n else\n return b ** 2\n end\n end\n else\n minimal = Math.sqrt((b * 2) ** 2).ceil\n minimal2 = Math.sqrt((a * b) * 2).ceil\n if (minimal * minimal) >= (minimal2 * minimal2)\n return minimal * minimal\n else\n if minimal2 >= a\n return minimal2 * minimal2\n else\n return a ** 2\n end\n end\n end\nend\n\nwhile (i > 0)\n a, b = gets.split.map(&:to_i)\n\n puts minimalsquare(a, b)\n\n i -= 1\nend"}, {"source_code": "t = gets.to_i\nt.times do\n a, b = gets.split.map(&:to_i).sort\n if a * 2 >= b\n puts (a * 2) ** 2\n else\n puts b ** 2\n end\nend\n"}, {"source_code": "gets.to_i.times do\n r = gets.split(' ').map(&:to_i)\n puts [2 * r.min, r.max].max ** 2\nend"}, {"source_code": "gets.to_i.times do\n a, b = gets.split(' ').map(&:to_i)\n\n puts [2*[a, b].min, [a, b].max].max ** 2\nend\n"}, {"source_code": "gets.to_i.times do\n\ta, b = gets.split.map(&:to_i).sort\n\tputs [a * 2, b].max**2\nend\n"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\nt.times do |testcase|\n (a,b) = gets.split.map(&:to_i)\n puts [2*a , 2*b].min ** 2\nend"}, {"source_code": "n = gets.to_i\n\n1.upto n do\n a, b = gets.split.map(&:to_i)\n if a == 1 and b == 1\n puts 4\n elsif a == 1 or b == 1\n puts ([a,b].max) ** 2\n else\n puts ([a,b].min * 2) ** 2\n end\nend"}, {"source_code": "i = gets.chomp.to_i\n\ndef minimalsquare(a, b)\n if a < b\n minimal = Math.sqrt((a * 2) ** 2).ceil\n if (minimal * minimal) >= ((a * b) * 2)\n return minimal * minimal\n else\n minimal = Math.sqrt((a * b) * 2).ceil\n return minimal * minimal\n end\n else\n minimal = Math.sqrt((b * 2) ** 2).ceil\n if (minimal * minimal) >= ((a * b) * 2)\n return minimal * minimal\n else\n minimal = Math.sqrt((a * b) * 2).ceil\n return minimal * minimal\n end\n end\nend\n\nwhile (i > 0)\n a, b = gets.split.map(&:to_i)\n\n puts minimalsquare(a, b)\n\n i -= 1\nend"}, {"source_code": "gets.to_i.times do\n r = gets.to_s.split(' ').map(&:to_i)\n l = r.max\n b = r.min\n if l == b || b*2 >= l\n puts b*b*4\n else\n puts ((l/b.to_f).ceil)**2\n end\nend"}], "src_uid": "3bb093fb17d6b76ae340fab44b08fcb8"} {"source_code": "\na = gets.strip\n# a = \"00000000000000012000000000000001200000000000000120000000000001\"\nif a.length > 20\n rows = 1\n while a.length.to_f/rows > 20 do\n rows +=1\n end\n if a.length % rows == 0\n print \"#{rows} #{a.length/rows}\\n\"\n a.split(\"\").each_slice(a.length/rows).to_a.each do |x|\n print \"#{x.join}\\n\"\n end\n else\n count_of_stars = 0\n while (a.length + count_of_stars) % rows != 0 do\n count_of_stars += 1\n end\n symbols_in_row = (a.length + count_of_stars)/rows\n print \"#{rows} #{symbols_in_row}\\n\"\n row_num = 1\n n = count_of_stars\n a.split(\"\").each_with_index do |x,i|\n if count_of_stars > 0\n # p \"kek: #{row_num*(symbols_in_row-1)}\"\n if i == row_num*(symbols_in_row-1)\n row_num+=1\n count_of_stars-=1\n print \"*\\n\"\n end\n else\n if i == row_num*symbols_in_row-n\n row_num+=1\n print \"\\n\"\n end\n end\n print x\n end\n end\nelse\n print \"1 #{a.length}\\n\"\n print a\nend\n", "positive_code": [{"source_code": "text = gets.chomp\nlen = text.length\n\nreqa = 0\nreqb = 0\n\ndone = false\n\n(1..5).each do |a|\n (1..20).each do |b|\n tot = a*b\n if tot 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n end\n if a[n-1] != a[i] || a[i] == 0\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n end\n kt = 0\n end\nend\n\nresult = s - a[n-1]\n\ndef modular_pow base, exponent, modulus\n result1 = 1\n while exponent > 0\n if (exponent % 2 == 1)\n result1 = (result1 * base) % modulus\n end\n exponent /= 2\n base = (base * base) % modulus\n end\n return result1\nend\n\nif result > s\n result = s\nend\n\nkq = modular_pow x, result, 1000000007\n\nputs kq", "positive_code": [{"source_code": "require 'openssl'\nn,x=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nm=10**9+7\ns=a.reduce(&:+)\na.map!{|x|s-x}\np=a.min\na=Hash[a.map{|x|x-p}.inject(Hash.new(0)){|h,v|h[v]+=1;h}.sort]\ni=0\nloop do\n q,d=a[i].divmod x\n if d==0\n p+=1\n i+=1\n a[i]||=0\n a[i]+=q\n else\n break\n end\nend\np x.to_bn.mod_exp([p,s].min,m)"}], "negative_code": [{"source_code": "require 'openssl'\nx,n=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nm=10**9+7\ns=a.reduce(&:+)\na.map!{|x|s-x}\np=a.min\na=a.group_by{|x|x}.sort.map{|a,b|[a,b.size]}\ni=0\nwhile a[i]\n q,d=a[i][1].divmod x\n if d==0\n p+=1\n i+=1\n a[i]||=[i,0]\n a[i][1]+=q\n else\n break\n end\nend\np x.to_bn.mod_exp([p,s].min,m)"}, {"source_code": "require 'openssl'\nx,n=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\nm=10**9+7\ns=a.reduce(&:+)\na.map!{|x|s-x}\np=a.min\na=Hash[a.map{|x|x-p}.inject(Hash.new(0)){|h,v|h[v]+=1;h}.sort]\ni=0\nloop do\n q,d=a[i].divmod x\n if d==0\n p+=1\n i+=1\n a[i]||=0\n a[i]+=q\n else\n break\n end\nend\np x.to_bn.mod_exp([p,s].min,m)"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nresult = s - a[n-1]\nkt = 1\n\nwhile i> 0 && kt do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n if a[n-1] != a[i]\n kt = 0\n else \n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n end\nend\n\nkq = x**result % 1000000007\n\nputs result"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s +=a[i]\nend\n\nresult = s - a[n-1]\n\ni = n-1\nwhile i > 0 && a[i-1] == a[i] do\n i -= 1\nend\n\nk = n - i\nwhile k % x == 0\n k = k/x\n result += 1\nend\n\nkq = x**result % 1000000007\n\nputs kq"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nkt = 1\n\nwhile kt == 1 do\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n end\n if a[n-1] != a[i] \n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n end\n kt = 0\n end\nend\n\nresult = s - a[n-1]\n\ndef modular_pow base, exponent, modulus\n result1 = 1\n while exponent > 0\n if (exponent % 2 == 1)\n result1 = (result1 * base) % modulus\n end\n exponent /= 2\n base = (base * base) % modulus\n end\n return result1\nend\n\nkq = modular_pow x, result, 1000000007\n\nputs kq"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nresult = s - a[n-1]\nkt = 1\n\nif x!= 1 \n while kt == 1 do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n if a[n-1] != a[i]\n kt = 0\n else \n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n kt = 0\n end\n end\nelse\n result = 1\nend\n\nkq = x**result % 1000000007\n\nputs kq"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nresult = s - a[n-1]\nkt = 1\n\nwhile kt == 1 do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n if a[n-1] != a[i]\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n kt = 0\n end\nend\n\nkq = ( x**result) % 1000000007\n\nputs kq"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\nsodu = []\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nkt = 1\n\nwhile kt == 1 do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n end\n if a[n-1] != a[i] || a[i] == 0\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n end\n kt = 0\n end\nend\n\nresult = s - a[n-1]\n\ntuanhoan = 0\n\nsodu[0] = 1\n(1..result).each do |i|\n sodu[i] = (sodu[i-1]*x) % 1000000007\n if sodu[i] == 1\n tuanhoan = i\n break\n end\nend\n\nif tuanhoan != 0\n kq = sodu[result%tuanhoan]\nelse\n kq = sodu[result]\nend\n\nputs tuanhoan"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nresult = s - a[n-1]\nkt = 1\n\nwhile i> 0 && kt do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n if a[n-1] != a[i]\n kt = 0\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n end\nend\n\nkq = x**result % 1000000007\n\nputs kq"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\nsodu1 = []\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nkt = 1\n\nwhile kt == 1 do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n end\n if a[n-1] != a[i] || a[i] == 0\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n end\n kt = 0\n end\nend\n\nresult = s - a[n-1]\n\nsodu1[0] = 1\n(1..1000000).each do |i|\n sodu1[i] = (sodu1[i-1] * x ) % 1000000007\nend\n\nif result > 1000000\n sodu = sodu1[1000000]\n thuong = result/1000000\n du = result % 1000000\n (1..thuong).each do |i|\n sodu = (sodu * x) % 1000000007\n end\n if du != 0\n (1..du).each do |j|\n sodu = ( sodu * x) % 1000000007\n end\n end\nend\n\nif result <= 1000000\n kq = sodu1[result]\nelse\n kq = sodu \nend\n\nputs sodu"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nresult = s - a[n-1]\nkt = 1\n\nwhile kt == 1 do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n if a[n-1] != a[i]\n kt = 0\n else \n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n kt = 0\n end\nend\n\nkq = x**result % 1000000007\n\nputs kq"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nresult = s - a[n-1]\nkt = 1\n\nputs result\n\nwhile i> 0 && kt do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n if a[n-1] != a[i]\n kt = 0\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n end\nend\n\nkq = x**result % 1000000007\n\nputs result"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 0\n\nwhile i> 0 && ( k % i == 0 || k == 1) do\n while i > 0 && a[i-1] == a[i] do\n i -= 1\n k += 1\n end\n\n while k % x == 0 && a[n-j] > a[n-i] do\n k = k/x\n a[n-1] -= 1\n end\nend\n\nwhile k % x == 0\n k = k/x\n a[n-1] -= 1\nend\n\nresult = s - a[n-j]\n\nkq = x**result % 1000000007\n\nputs result"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nresult = s - a[n-1]\nkt = 1\n\nwhile kt == 1 do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n if a[n-1] != a[i] || a[i] == 0\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n kt = 0\n end\nend\n\nkq = ( x**result) % 1000000007\n\nputs kq"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\nsodu1 = []\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nkt = 1\n\nwhile kt == 1 do\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n end\n if a[n-1] != a[i] || a[i] == 0\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n end\n kt = 0\n end\nend\n\nresult = s - a[n-1]\n\ndef modular_pow base, exponent, modulus\n result1 = 1\n while exponent > 0\n if (exponent % 2 == 1)\n result1 = (result1 * base) % modulus\n end\n exponent /= 2\n base = (base * base) % modulus\n end\n return result1\nend\n\nkq = modular_pow x, result, (10**9 + 7)\n\nputs kq"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nkt = 1\n\nwhile kt == 1 do\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n end\n if a[n-1] != a[i] || a[i] == 0\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n end\n kt = 0\n end\nend\n\nresult = s - a[n-1]\n\ndef modular_pow base, exponent, modulus\n result1 = 1\n while exponent > 0\n if (exponent % 2 == 1)\n result1 = (result1 * base) % modulus\n end\n exponent /= 2\n base = (base * base) % modulus\n end\n return result1\nend\n\nkq = modular_pow x, result, 1000000007\n\nputs kq"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nresult = s - a[n-1]\nkt = 1\n\nwhile kt == 1 do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n if a[n-1] != a[i] || a[i] == 0\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n kt = 0\n end\nend\n\nkq = ( x**result) % 1000000007\n\nputs result"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nkt = 1\n\nwhile kt == 1 do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n end\n if a[n-1] != a[i] || a[i] == 0\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n end\n kt = 0\n end\nend\n\nresult = s - a[n-1]\nkq = ( x**result) % 1000000007\n\nputs kq"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nresult = s - a[n-1]\nkt = 1\n\nwhile kt == 1 do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n if a[n-1] != a[i] || a[i] == 0\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n result += 1\n end\n kt = 0\n end\nend\n\nkq = ( x**result) % 1000000007\nif kq == 0 \n kq = 10**9 + 7\nend\n\nputs kq"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\n\ns = 0\n\n(0..n-1).each do |i|\n s +=a[i]\nend\n\nresult = s - a[n-1]\n\nputs x**result"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\nsodu1 = []\nsodu2 = []\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nkt = 1\n\nwhile kt == 1 do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n end\n if a[n-1] != a[i] || a[i] == 0\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n end\n kt = 0\n end\nend\n\nresult = s - a[n-1]\n\ntuanhoan = 0\n\nsodu = 1\n(1..1000000).each do |i|\n sodu = (sodu * x ) % 1000000007\nend\n\nif result > 1000000\n sodu1 = sodu\n thuong = result/1000000\n du = result % 1000000\n (1..thuong).each do |i|\n sodu1 = (sodu1 * sodu) % 1000000007\n end\n if du > 0\n (1..du).each do |j|\n sodu1 = ( sodu1 * x) % 1000000007\n end\n end\n sodu = sodu1\nend\n\nputs sodu"}, {"source_code": "b = gets.chomp.split(\" \").map{|i| i.to_i}\na = gets.chomp.split(\" \").map{|i| i.to_i}\nn = b[0]\nx = b[1]\nsodu = []\n\ns = 0\n\n(0..n-1).each do |i|\n s += a[i]\nend\n\ni = n-1\nj = 1\nk = 1\nkt = 1\n\nwhile kt == 1 do\n kt = 1\n while i > 0 && a[i] == a[i-1] do\n i -= 1\n k += 1\n end\n\n if i > 0\n i -= 1\n while k % x == 0 && a[n-1] > a[i] do\n k = k/x\n a[n-1] -= 1\n end\n if a[n-1] != a[i] || a[i] == 0\n kt = 0\n else\n k += 1\n end\n else\n while k % x == 0 do\n k = k/x\n a[n-1] -= 1\n end\n kt = 0\n end\nend\n\nresult = s - a[n-1]\n\ntuanhoan = 0\n\nsodu[1] = x\n(2..result).each do |i|\n sodu[i] = (sodu[i-1]*x) % 1000000007\n if sodu[i] == sodu[1]\n tuanhoan = i-1\n sodu[0] = sodu[i-1]\n break\n end\nend\n\nif tuanhoan != 0\n kq = sodu[result%tuanhoan]\nelse\n kq = sodu[result] \nend\n\nputs kq"}], "src_uid": "4867d014809bfc1d90672b32ecf43b43"} {"source_code": "a=*$<\nn,m =a[0].split.map &:to_i\np (1..n).count{|x|\n (0...m).any?{|y| a[x][y] == (1..n).map{|i| a[i][y]}.max}\n}\n", "positive_code": [{"source_code": "n, m = gets.chomp.split(/ /).map(&:to_i)\nstudents = []\nn.times do\n students << gets.chomp.split(\"\").map(&:to_i)\nend\ntoppers = []\nm.times do |subject|\n topper = Array.new(n, 0)\n n.times do |student|\n marks = students[student][subject]\n topper[student] = marks if marks >= topper[student]\n end\n highest = topper.max\n topper.each_index do |student|\n marks = topper[student]\n toppers << student if marks == highest && !toppers.include?( student )\n end\nend\nputs toppers.length\n"}, {"source_code": "k=gets.chomp\na=[]\nb=[]\na=k.split(' ')\na[0].to_i.times do\n b<=max[y]\n end\nend\ncount=0\nis.each do |x|\n count+=1 if x==true\nend\nputs count"}, {"source_code": "n,m = gets.split.map(&:to_i)\na = []\n\nn.times do \n a << gets.strip.split(//).map(&:to_i)\nend\n\nb = a.transpose\n\nans = Array.new(n){ false }\nm.times do |i|\n mx = b[i].max\n b[i].each_with_index{|s,i| ans[i] = true if s == mx}\nend\n\np ans.count(true)\n"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn, m = gets.split.map &:to_i\ntable = []\n\nn.times{\n table << gets.split(//).map(&:to_i)\n}\n\nstudents = Set.new\nm.times{|index|\n max_value = table.collect{|column| column[index]}.max\n \n student_id = 0\n table.each{|array|\n students << student_id if array[index] == max_value\n student_id+=1\n }\n}\n\nprint students.to_a.size"}, {"source_code": "n,m=gets.chomp.split.collect{|a| a.to_i }\nstudents=[]\nmax_scores=Array.new(m,0)\nfor i in 0..n-1\ns=gets.chomp.split('').collect{|a| a.to_i}\nstudents.push s\ns.each_index{|j| if max_scores[j] < s[j] then max_scores[j]=s[j] end}\nend\nres=0\nstudents.each do |student|\nsucc=false\nstudent.each_index{|i| if student[i]==max_scores[i] then succ=true end}\nif succ\n res+=1\nend\nend\nputs res\n\n"}, {"source_code": "input = gets.chomp\nnums = input.split\nn = Integer(nums[0])\nm = Integer(nums[1])\na = Array.new\nfor i in 0...n\n a[i] = Array.new\n input = gets.chomp\n for j in 0...m\n a[i][j] = Integer(input[j])\n end\nend\n\ndef best(a,n,j)\n b = Array.new\n c = 0\n for i in 0...n\n if a[i][j] > c\n c = a[i][j]\n end\n end\n for i in 0...n\n if a[i][j] == c\n b.push(i)\n end\n end\n return b\nend\nb = Array.new\nfor j in 0...m\n b += best(a,n,j)\nend\nb = b.sort\nc = Array.new\nc[0] = b[0]\nfor i in 0...b.length-1\n if b[i+1] != b[i]\n c.push(b[i+1])\n end\nend\nputs c.length\n"}, {"source_code": "n,m=gets.split(' ').map(&:to_i)\na=Array.new(n)\nbest = Array.new(m){0}\nbest_student = Array.new(n){0}\nn.times do |i|\n a[i] = gets.chomp.split('').map(&:to_i)\n a[i].each_index{|j| \n if(best[j] < a[i][j]) \n best[j] = a[i][j] \n end\n }\nend\ncount = 0\nn.times do|i|\n a[i].each_index{|j| \n if(a[i][j] == best[j])\n count+=1 \n break \n end\n }\nend\np count"}, {"source_code": "b=->(a){m=a.max;l=[];a.size.times{|i|a[i]==m&&l<= max[i]\n\t\t\tmax[i] = a[i] \n\t\tend\n\tend\nend\n\n\narr.each_with_index do |a,i|\n\t(0..m-1).each do |j|\n\t\tbest[i] = true if a[j] == max[j]\n\tend\nend\n\nputs best.keys.count"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = n.times.map{gets.chomp.chars.map(&:to_i)}\nc = a.transpose.map(&:max)\nputs a.count{|x| m.times.any?{|i| x[i] == c[i]}}\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = n.times.map{gets.chomp.split('').map(&:to_i)}\nc = a.transpose.map{|x| x.max}\nsuccessful = Array.new(n, false)\nn.times do |i|\n m.times do |j|\n if a[i][j] == c[j]\n successful[i] = true\n break\n end\n end\nend\nputs successful.count{|x| x == true}\n"}, {"source_code": "n,m = gets.split(\" \")\nn = n.to_i\nm = m.to_i\ng = Array.new(m) {[]}\nfor i in 0..n-1\n gr = gets.chomp\n for j in 0..m-1\n g[j] << [gr[j].to_i, i]\n\t#puts gr[j]\n end\nend\nu = Array.new(n)\nu.fill(0)\ng.each do |q|\n q.sort_by! {|e| e[0]}\n q.reverse!\n curr = 0\n u[q[0][1]] = 1\n while curr < n - 1 && q[curr][0] == q[curr + 1][0]\n \n u[q[curr+1][1]] = 1\n\tcurr += 1\n end\nend\n\nputs (u.inject(0) {|sum, curr| sum += curr})"}, {"source_code": "students, subjects = gets.split.map(&:to_i)\na = []\nstudents.times {\n a << gets.chomp.split('')\n}\nbest = a.transpose.map(&:max)\nres = 0\n(0...students).each { |i|\n (0...subjects).each { |j|\n if a[i][j] == best[j]\n res += 1\n break\n end\n }\n}\np res\n"}, {"source_code": "require 'set'\n\nn, m = gets.chomp.split.map { |x| x.to_i }\ngrades = []\nfor _ in 1..n\n grades << gets.chomp\nend\n\nsuc_students = Set.new\nfor j in 0...m\n marks_for_subject = []\n for i in 0...n\n marks_for_subject << grades[i][j]\n end\n max = marks_for_subject.max\n for i in 0...n\n if marks_for_subject[i] == max\n suc_students << i\n end\n end\nend\n\nputs suc_students.size"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\na = []\nn.times do\n a << gets.strip.split(//).map(&:to_i)\nend\nary = Array.new(n, 0)\nb = a.transpose\nm.times do |c|\n mx = b[c].max\n n.times do |r|\n if mx == a[r][c]\n ary[r] = 1\n end\n end\nend\np ary.count(1)\n"}, {"source_code": "s = gets.split(' ')\nn = s[0].to_i\nm = s[1].to_i\na = Array.new(n).map!{ Array.new(m, 0) }\nfor r in 0..n-1\n ln = gets\n for c in 0..m-1\n a[r][c] = ln[c,1].to_i\n end\nend\nary = Array.new(n, 0)\nfor c in 0..m-1\n mx = 0\n for r in 0..n-1\n if mx < a[r][c]\n mx = a[r][c]\n end\n end\n for r in 0..n-1\n if mx == a[r][c]\n ary[r] = 1\n end\n end\nend\nres = 0\nfor r in 0..n-1\n if ary[r] > 0\n res += 1\n end\nend\np res\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = []\nn.times {\n a << gets.strip.split(//).map(&:to_i)\n}\nary = [0]\nb = a.transpose\nm.times { |c|\n mx = b[c].max\n n.times { |r|\n ary[r] = 1 if mx == a[r][c]\n }\n}\np ary.count(1)\n"}, {"source_code": "st = gets.split\nn = st[0].to_i\nm = st[1].to_i\n\nmarks = []\nsubs = Array.new(m){|i| i = -1}\nresult = 0\nreestr = Array.new(m){|i| i = []}\nn.times do |i|\n marks << gets.chomp\n m.times do |j|\n if marks[i][j].to_i > subs[j]\n subs[j] = marks[i][j].to_i\n reestr[j] = []\n reestr[j] << i\n elsif marks[i][j].to_i == subs[j] then\n reestr[j] << i\n end\n end\nend\n\nstudents = Array.new(n){|i| i = 0}\nm.times do |i|\n reestr[i].size.times do |j|\n students[reestr[i][j]] = 1\n end\nend\n\nstudents.delete(0)\n\nputs students.size"}, {"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\na = []\ns = []\nfor i in 0..n-1\n\ts << false\n\ta << gets.chomp.split(//).map!{|x| x.to_i}\nend\n\nfor i in 0..m-1\n\tw = []\n\tfor j in 0..n-1\n\t\tw << a[j][i]\n\tend\n\twm = w.max\n\tfor j in 0..n-1\n\t\ts[j] = true if w[j] == wm\n\tend\nend\nret = 0\nfor j in 0..n-1\n\tret += 1 if s[j] == true\nend\nputs ret\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = Array.new(n){gets.chars.to_a}\nb = (['0'] * m).zip(*a).map(&:max)\np a.count{|_| _.zip(b).any?{|i, j| i == j}}\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\n\ngradebook = []\nmax = Array.new(m,0)\n\nn.times do\n row = []\n row = gets.chomp.split(//).map(&:to_i)\n\n row.each_with_index do |o, i|\n if max[i] < o then max[i] = o end\n end\n\n gradebook << row\nend\n\ncounter = 0\n\ngradebook.each do |row|\n row.each_with_index do |o, i|\n if o == max[i]\n counter += 1\n break\n end\n end\nend\n\nputs counter\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\ninput=[]\nn.times{ input.push(gets.split[0])}\nans=0\nn.times{|i|\n\tok=0\n\tm.times{|j|\n\t\tval=[]\n\t\tn.times{|k|\n\t\t\tval.push(input[k][j].to_i)\n\t\t}\n\t\tok=1 if val.max==input[i][j].to_i\n\t}\n\tans+=ok\n}\np ans"}, {"source_code": "#!/usr/bin/env ruby\n\nn, m = gets.split.map(&:to_i)\n\nhighest = Array.new(m, 0)\nlist = []\nn.times do\n arr = gets.chomp.each_char.to_a.map(&:to_i)\n arr.each_with_index do |score, idx|\n highest[idx] = [score, highest[idx]].max\n end\n list << arr\nend\n\nans = 0\nlist.each do |arr|\n arr.each_with_index do |score, idx|\n if highest[idx] == score\n ans += 1\n break\n end\n end\nend\n\np ans\n"}, {"source_code": "\ufefftmp = gets.chomp.split \" \"\nn = tmp[0].to_i\nm = tmp[1].to_i\n\nfield = []\nn.times do \n field.push gets.chomp.split(\"\").map {|i| i.to_i } \nend\n\nd = {}\nfield = field.transpose\n\nfield.each_with_index do |line, no|\n max = line.max\n \n line.each_with_index do |e, i|\n if e == max\n d[i + 1] = true\n end\n end\nend\n\nputs d.keys.length\n"}, {"source_code": "input = STDIN.read.split(\"\\n\")\n\nss = input.shift.split(' ').map(&:to_i)\n\nstudents, subjects = ss[0], ss[1]\n\n\nsubj_max = []\n\nsubjects.times { subj_max.push 0 }\n\nsubjects.times do |i|\n\tstudents.times do |j|\n\t\tsubj_max[i] = input[j][i].to_i if input[j][i].to_i > subj_max[i]\n\tend\nend\n\nsucc = 0\n\nstudents.times do |i|\n\tsubjects.times do |j|\n\t\tif input[i][j].to_i == subj_max[j].to_i\n\t\t\tsucc += 1\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nSTDOUT.puts succ"}, {"source_code": "n,m = STDIN.gets.chomp.split(/ /).map(&:to_i)\n\ns = n.times.map do\n STDIN.gets.chars.map(&:to_i).take(m)\nend\n\nmax = 0.upto(m-1).map do |i|\n s.max{|a,b| a[i] <=> b[i] }[i]\nend\nf = s.map do |student|\n max.each_with_index.any? do |m,i|\n student[i] >= m\n end\nend\np f.select{|x| x }.size\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\na=[]\nn.times do\n a< a[i][j])\n\t\t\t\tib = false\n\t\t\tend\n\t\tend\n\t\tif ib==true\n\t\t\twb=true\n\t\tend\n\tend\n\tif wb==true\n\t\tans+=1\n\tend\nend\nputs ans\n"}, {"source_code": "def max_index a\n max = a.max\n (0...a.size).find_all{ |x| a[x] == max}\nend\n#n, m = gets.split.map(&:to_i)\ngets\np readlines.map(&:chomp).map {|x| x.split('').map(&:to_i)}.transpose.map { |x| max_index(x) }.flatten.uniq.size"}], "negative_code": [{"source_code": "n,m = STDIN.gets.chomp.split(/ /).map(&:to_i)\n\ns = n.times.map do\n STDIN.gets.chars.map(&:to_i).take(m)\nend\nf = Array.new(s.size,false)\n\nmax = 0.upto(m-1).map do |i|\n s.max{|a,b| a[i] <=> b[i] }[i]\nend\np s.map do |student|\n max.each_with_index.any? do |m,i|\n student[i] >= m\n end\nend\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\na=[]\nn.times do\n a< 0 do \n\tif n >= 9 \n\t\tn = n - 9\n\t\tdigits << 9\n\telse\n\t\tdigits << n\n\t\tbreak\n\tend\nend\nputs digits.size\ndigits.each do |i|\n\tprint \"#{i} \"\nend"}, {"source_code": "num = gets.chomp\nputs num\nnum.to_i.times do\n puts 1.class\nend\n"}, {"source_code": "num = gets.chomp\nnum.to_i.times do\n puts \"1\" + \" \"\nend\n"}, {"source_code": "num = gets.chomp\nnum.to_i.times do\n puts 1.to_int\nend\n"}, {"source_code": "num = gets.chomp\nnum.to_i.times do\n puts 1\nend\n"}, {"source_code": "n = gets.to_i\nn.times do |i|\n print 1,(i == n-1 ? \"\\n\" : \" \")\nend"}, {"source_code": "DBG = true\nn = gets.to_i\nif n <= 9\n puts \"1\"\n puts \"#{n}\"\nelsif n%9 == 0\n puts \"#{n/9}\"\n (n/9).times do\n print \"9 \"\n end\n puts \"\"\nelse\n puts \"#{(n/9)+1}\"\n (n/9).times do\n print \"9 \"\n end\n puts \"#{n%9}\"\nend\n"}, {"source_code": "DBG = true\nn = gets.to_i\nif n <= 9\n puts \"1\"\n puts \"#{n}\"\nelsif n%2 == 0\n puts \"#{n/2}\"\n (n/2).times do\n print \"2 \"\n end\n puts \"\"\nelsif n%3 == 0\n puts \"#{n/3}\"\n (n/3).times do\n print \"3 \"\n end\n puts \"\"\nelsif n%5 == 0\n puts \"#{n/5}\"\n (n/5).times do\n print \"5 \"\n end\n puts \"\"\nelsif n%7 == 0\n puts \"#{n/7}\"\n (n/7).times do\n print \"7 \"\n end\n puts \"\"\n\nelse\n puts \"#{(n/9)+1}\"\n (n/9).times do\n print \"9 \"\n end\n puts \"#{n%9}\"\nend\n"}, {"source_code": "DBG = true\nn = gets.to_i\nif n <= 9\n puts \"1\"\n puts \"#{n}\"\nelsif n%9 == 0\n puts \"1\"\n (n/9).times do\n print \"9 \"\n end\n puts \"\"\nelse\n puts \"2\"\n (n/9).times do\n print \"9 \"\n end\n puts \"#{n%9}\"\nend\n"}, {"source_code": "k = gets.to_i\nif k < 10\n puts \"1\"\n print \"#{k}\"\nelsif k % 2 == 0\n puts \"2\"\n print \"#{k/2} #{k/2}\"\nelsif k % 3 == 0\n puts \"3\"\n print \"#{k/3} #{k/3} #{k/3}\"\nelsif k % 5 == 0\n puts \"5\"\n print \"#{k/5} #{k/5} #{k/5} #{k/5} #{k/5}\"\nelsif k % 7 == 0\n puts \"7\"\n print \"#{k/7} #{k/7} #{k/7} {k/7} #{k/7} #{k/7} #{k/7}\"\nelse\n puts \"2\"\n print \"#{(k-1)/2} #{(k+1)/2}\"\nend"}, {"source_code": "n = gets.to_i\nputs (n + 8)/9\n(n/9).times { print 9, ' ' }\nprint n%9 if n%9 != 0\n"}], "src_uid": "7c483498f497f4291e3d33375c0ebd53"} {"source_code": "MOD = 10 ** 9 + 7\r\ndef gs; gets.chomp; end\r\ndef gi; gets.to_i; end\r\ndef gli; gets.split.map(&:to_i); end\r\ndef cyesno(x); puts x ? :Yes : :No; end\r\ndef uyesno(x); puts x ? :YES : :NO; end\r\ndef array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end\r\n\r\ngets.to_i.times do\r\n x = gets.to_i\r\n k = x / 3\r\n if x%3 == 0\r\n puts \"#{k} #{k}\"\r\n elsif x%3 == 1\r\n puts \"#{k + 1} #{k}\"\r\n else\r\n puts \"#{k} #{k + 1}\"\r\n end\r\nend\r\n", "positive_code": [{"source_code": "t = gets().to_i\r\nwhile(t!=0)\r\n n = gets().to_i\r\n if (n==1)\r\n puts \"1 0\\n\"\r\n\r\n elsif (n==2)\r\n puts \"0 1\\n\"\r\n\r\n elsif(n==3)\r\n puts \"1 1\\n\"\r\n\r\n elsif (n==4)\r\n puts \"2 1\\n\"\r\n\r\n elsif (n==5)\r\n puts \"1 2\\n\"\r\n else\r\n h1 = n/3\r\n h2 = n/3.0\r\n if (h2+0.5>=h1+1)\r\n h = h1 + 1\r\n else\r\n h = h1\r\n end\r\n\r\n l = n - 2*h\r\n puts \"#{l} #{h}\\n\"\r\n end\r\n t-=1\r\nend\r\n"}], "negative_code": [], "src_uid": "71335a9489f0985f4e16435b14d6a34a"} {"source_code": "class UF\ndef initialize;@uf=Hash.new{|_,k|k}end\ndef u a,b;@uf[f a]=@uf[f b]end\ndef f c;c==@uf[c]?c:@uf[c]=f(@uf[c])end\nend\n\ndef g;gets.split.map(&:to_i)end\n_,m=g\nuf=(1..m).map{UF.new}\nm.times{\n a,b,c=g\n uf[c-1].u(a,b)\n}\ngets.to_i.times{\n u,v=g\n p uf.count{|t|t.f(u)==t.f(v)}\n}", "positive_code": [{"source_code": "class UF\ndef initialize;@uf=Hash.new{|_,k|k}end\ndef u a,b;@uf[f a]=@uf[f b]end\ndef f c;c==@uf[c]?c:@uf[c]=f(@uf[c])end\nend\n\ndef g;gets.split.map(&:to_i)end\n_,m=g\nuf=(1..m).map{UF.new}\nm.times{\n a,b,c=g\n uf[c-1].u(a,b)\n}\ngets.to_i.times{\n u,v=g\n p uf.count{|t|t.f(u)==t.f(v)}\n}"}, {"source_code": "class UF\ndef initialize;@uf=Hash.new{|_,k|k}end\ndef u a,b;@uf[f a]=@uf[f b]end\ndef f c;c==@uf[c]?c:@uf[c]=f(@uf[c])end\nend\n\ndef g;gets.split.map(&:to_i)end\n_,m=g\nuf=(1..m).map{UF.new}\nm.times{\n a,b,c=g\n uf[c-1].u(a,b)\n}\ngets.to_i.times{\n u,v=g\n p uf.count{|t|t.f(u)==t.f(v)}\n}"}], "negative_code": [], "src_uid": "e3ec343143419592e73d4be13bcf1cb5"} {"source_code": "def cal(str,ans)\n map={'0'=>0,'1'=>1,'?'=>2};\n if str[0].chr=='?' then\n str[0]='1'; cal(str,ans);\n str[0]='0'; cal(str,ans);\n return;\n end\n cnt=[0,0-str.length%2,0];\n str.each_byte{ |c| cnt[map[c.chr]]=cnt[map[c.chr]]+1; }\n ans.push(\"00\") if str.length/2o then\n ans[0]=1\n elsif z0 then ans[1]=1 end\n if i>0 then ans[2]=1 end\n elsif a[minus+1]==\"1\" then\n ans[1]=1\n else\n ans[2]=1\n end\n end\nend\n4.times{|i|\n if ans[i]>0 then\n puts res[i]\n end\n}\n"}], "negative_code": [{"source_code": "a=gets.split[0]\nzero=0\none=0\nhatena=0\na.each_char{|i|\n if i==\"1\" then\n one+=1\n elsif i==\"0\" then\n zero+=1\n elsif i==\"?\" then\n hatena+=1\n end\n}\nminus=zero+hatena+one-2\nans=[0,0,0,0]\nres=[\"00\",\"01\",\"10\",\"11\"]\nfor i in 0..hatena\n z=zero+i\n o=one+hatena-i\n if minus%2==1 then z+=1 end\n if z>o then\n ans[0]=1\n elsif z0 then\n puts res[i]\n end\n}\n"}, {"source_code": "a=gets.split[0]\nzero=0\none=0\nhatena=0\na.each_char{|i|\n if i==\"1\" then\n one+=1\n elsif i==\"0\" then\n zero+=1\n elsif i==\"?\" then\n hatena+=1\n end\n}\nminus=zero+hatena+one-2\nans=[0,0,0,0]\nres=[\"00\",\"01\",\"10\",\"11\"]\nfor i in 0..hatena\n z=zero+i\n o=one+hatena-i\n if minus%2==1 then z+=1 end\n if z>o then\n ans[0]=1\n elsif z0 then ans[1]=1 end\n if hatena>0 then ans[2]=1 end\n elsif a[minus+1]==\"1\" then\n ans[1]=1\n else\n ans[2]=1\n end\n end\nend\n4.times{|i|\n if ans[i]>0 then\n puts res[i]\n end\n}\n"}, {"source_code": "def cal(str,ans)\n map={'0'=>0,'1'=>1,'?'=>2};\n if str[0].chr=='?' then\n str[0]='1'; cal(str,ans);\n str[0]='0'; cal(str,ans);\n return;\n end\n cnt=[0-str.length%2,0,0];\n str.each_byte{ |c| cnt[map[c.chr]]=cnt[map[c.chr]]+1; }\n ans.push(\"00\") if str.length/20,'1'=>1,'?'=>2};\n if str[0].chr=='?' then\n str[0]='1'; cal(str,ans);\n str[0]='0'; cal(str,ans);\n return;\n end\n cnt=[0-str.length%2,0,0];\n str.each_byte{ |c| cnt[map[c.chr]]=cnt[map[c.chr]]+1; }\n ans.push(\"00\") if str.length/20,'1'=>1,'?'=>2};\n if str[0].chr=='?' then\n str[0]='1'; cal(str,ans);\n str[0]='0'; cal(str,ans);\n return;\n end\n cnt=[0-str.length%2,0,0];\n str.each_byte{ |c| cnt[map[c.chr]]=cnt[map[c.chr]]+1; }\n ans.push(\"00\") if str.length/2 [\"3\", \"7\", \"5\", \"4\", \"3\"], [\"4\", \"3\", \"7\", \"5\"]\n memo[v] ||= 0; memo[v] += 1; memo # => {\"3\"=>1}, {\"3\"=>1, \"7\"=>1}, {\"3\"=>1, \"7\"=>1, \"5\"=>1}, {\"3\"=>1, \"7\"=>1, \"5\"=>1, \"4\"=>1}, {\"3\"=>2, \"7\"=>1, \"5\"=>1, \"4\"=>1}, {\"4\"=>1}, {\"4\"=>1, \"3\"=>1}, {\"4\"=>1, \"3\"=>1, \"7\"=>1}, {\"4\"=>1, \"3\"=>1, \"7\"=>1, \"5\"=>1}\n } # => {\"3\"=>2, \"7\"=>1, \"5\"=>1, \"4\"=>1}, {\"4\"=>1, \"3\"=>1, \"7\"=>1, \"5\"=>1}\n reject { |e| h.include?(e) && (h[e] -= 1) >= 0 } # => [\"1\"], [\"3\"]\n end # => :subtract_once\nend # => :subtract_once\n\ntotal = gets.chomp # ~> NoMethodError: undefined method `chomp' for nil:NilClass\n\nsatu = gets.chomp.split(' ')\ndua = gets.chomp.split(' ')\ntiga = gets.chomp.split(' ')\n# satu = %w(1 4 3 3 5 7) # => [\"1\", \"4\", \"3\", \"3\", \"5\", \"7\"]\n# dua = %w(3 7 5 4 3) # => [\"3\", \"7\", \"5\", \"4\", \"3\"]\n# tiga = %w(4 3 7 5) # => [\"4\", \"3\", \"7\", \"5\"]\n\n\nputs satu.subtract_once(dua)[0] # => nil\nputs dua.subtract_once(tiga)[0] # => nil\n\n# >> 1\n# >> 3\n"}, {"source_code": "class Array\n def subtract_once(values)\n counts = values.inject(Hash.new(0)) { |h, v| h[v] += 1; h }\n reject { |e| counts[e] -= 1 unless counts[e].zero? }\n end\nend\n\nn = gets.chomp.to_i\n\nset1 = gets.chomp.split(' ').map { |e| e.to_i }.sort\nset2 = gets.chomp.split(' ').map { |e| e.to_i }.sort\nset3 = gets.chomp.split(' ').map { |e| e.to_i }.sort\n\np set1.subtract_once(set2)[0]\np set2.subtract_once(set3)[0]"}, {"source_code": "n = Integer(gets)\nget_first = gets.chomp.split\nn_first = Array.new\nfor i in 0...get_first.length\n n_first[i] = Integer(get_first[i])\nend\nget_second = gets.chomp.split\nn_second = Array.new\nfor i in 0...get_second.length\n n_second[i] = Integer(get_second[i])\nend\nget_third = gets.chomp.split\nn_third = Array.new\nfor i in 0...get_third.length\n n_third[i] = Integer(get_third[i])\nend\n\nn_first = n_first.sort\nn_second = n_second.sort\nn_third = n_third.sort\nfirst = 0\nsecond = 0\nfor i in 0...n_second.length\n if n_first[i] != n_second[i]\n first = n_first[i]\n break\n else\n first = n_first[n_second.length]\n end\nend\nfor i in 0...n_third.length\n if n_second[i] != n_third[i]\n second = n_second[i]\n break\n else\n second = n_second[n_third.length]\n end\nend\n\nputs first\nputs second\n"}, {"source_code": "#Made By Hasbi Hamza\ngets.chomp\na = gets.chomp.split(' ').map(&:to_i).inject(:+);\nb = gets.chomp.split(' ').map(&:to_i).inject(:+);\nc = gets.chomp.split(' ').map(&:to_i).inject(:+);\nputs a-b\nputs b-c"}, {"source_code": "_,a,b,c=$<.map{|l|l.split.map(&:to_i).inject:+}\np a-b,b-c\n"}, {"source_code": "n = gets.to_i\na = []\nb =[]\nc = []\n\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nc = gets.split.map(&:to_i)\n\ndef sum(n)\n return n.inject(0){|sum, i| sum+i}\nend\n\nputs sum(a) - sum(b)\nputs sum(b) - sum(c)"}, {"source_code": "_,a,b,c=$<.map{|l|l.split.map(&:to_i).inject:+}\np a-b,b-c\n"}, {"source_code": "def check(a, b)\n a.zip(b).find { |x| x.first != x.last }.first\nend\n\ngets\na = gets.split(' ').map(&:to_i).sort\nb = gets.split(' ').map(&:to_i).sort\nc = gets.split(' ').map(&:to_i).sort\n\nputs check(a, b)\nputs check(b, c)\n"}, {"source_code": "def check(a, b)\n a.zip(b).each do |x|\n if x.first != x.last\n puts x.first\n break\n end\n end\nend\n\ngets\na = gets.split(' ').map(&:to_i).sort\nb = gets.split(' ').map(&:to_i).sort\nc = gets.split(' ').map(&:to_i).sort\n\ncheck a, b\ncheck b, c\n"}, {"source_code": "# 519B\n\ndef read_line\n (gets.chomp.split.map &:to_i).sort\nend\n\nn = gets.to_i\ns = read_line\nt = read_line\np = ->(i) { s[i] != t[i] }\nputs s[(0...n - 1).find(&p) || n - 1]\ns = read_line\nputs t[(0...n - 2).find(&p) || n - 2]"}, {"source_code": "_,a,b,c=$<.map{|l|l.split.map(&:to_i).inject:+}\np a-b,b-c\n"}, {"source_code": "_,a,b,c=$<.map{|l|l.split.map(&:to_i).inject:+}\np a-b,b-c\n"}], "negative_code": [{"source_code": "gets.to_i\na=gets.split.map{|x| x.to_i}.sort!\nb=gets.split.map{|x| x.to_i}.sort!\nc=gets.split.map{|x| x.to_i}.sort!\n\ndef otlich(a, b)\n for i in 0...a.max\n b< preserved #{collected.length}/#{ec.length} #{c}\"\n cands = [C.new(c.i+1, c.j), C.new(c.i-1, c.j), C.new(c.i, c.j+1), C.new(c.i, c.j-1)]\n for cand in cands\n if cand.i >= 0 && cand.i < n && cand.j >= 0 && cand.j < m\n if g[cand.i][cand.j] == EMPTY\n q << cand\n end\n end\n end\nend\n\n\nputs g.map(&:join).join(\"\\n\").gsub(EMPTY, ADDED_WALL).gsub(PRESERVED, EMPTY)\n#puts g.map(&:join).join(\"\").count(EMPTY)", "positive_code": [{"source_code": "\n@di = [-1, 0, 1, 0]\n@dj = @di.reverse\n\ndef ok(i, j)\n return false if i < 0 || i >= @n || j < 0 || j >= @m || @maze[i][j] != '.'\n return true\nend\n\ndef bfs(si, sj)\n qi = 0\n qj = 0\n q = Array.new(@n * @m)\n q[qj] = [si, sj]\n qj += 1\n while qi < qj\n arr = q[qi]\n qi += 1\n i = arr[0]\n j = arr[1]\n next if @vis[i][j]\n @vis[i][j] = true\n @reached += 1\n break if @reached == @target\n 4.times { |d|\n ni = i + @di[d]\n nj = j + @dj[d]\n if ok(ni, nj)\n q[qj] = [ni, nj]\n qj += 1\n end\n }\n end\nend\n\n@n, @m, k = gets.strip.split.map(&:to_i)\n@maze = Array.new(@n)\n@vis = Array.new(@n) {Array.new(@m) { false }}\ns = 0\n@n.times {|i|\n @maze[i] = gets.strip.split(\"\")\n s += @maze[i].select{|c| c == '.'}.count\n}\n@reached = 0\n@target = s - k\n@n.times {|i|\n done = false\n @m.times {|j|\n # puts \" > #{i}, #{j}, #{@maze[i][j].class}\"\n if @maze[i][j] == '.'\n done = true\n bfs(i, j)\n break\n end\n }\n break if done\n}\n\n# puts @maze.map{|s| s.join(\"\")}.join(\"\\n\")\n\n@n.times {|i|\n @m.times {|j|\n if @maze[i][j] == '.' && !@vis[i][j]\n @maze[i][j] = 'X'\n end\n }\n}\n@maze.map!{|r| r.join(\"\")}\nout = @maze.join(\"\\n\")\n$stdout.print out\n"}, {"source_code": "\n# Is the curren node valid?\ndef valid(node, maze)\n return false if node.min < 0\n return false if node[0] >= maze.length\n return false if node[1] >= maze[0].length\n return false if maze[node[0]][node[1]] != \"X\"\n return true\nend\n\n# Nodes connected to node\ndef children(node, maze)\n children = []\n offsets = [[-1,0],[1,0],[0,-1],[0,1]]\n for offset in offsets\n nebr = [node[0] + offset[0] ,node[1] + offset[1]]\n children.push(nebr) if valid(nebr, maze) \n end\n return children\nend\n\n# Run BFS\ndef bfs(root, maze, depth)\n queue = Array.new(depth)\n queue[0] = root\n visited = Array.new(maze.length) { Array.new(maze[0].length, false) }\n front = 0; back = 1;\n while true\n root = queue[front]\n front = front + 1\n maze[root[0]][root[1]] = \".\"\n return if front == depth\n for child in children(root, maze) do\n unless visited[child[0]][child[1]]\n queue[back] = child\n back = back + 1\n visited[child[0]][child[1]] = true\n end\n end\n end\nend\n\n# Print maze\ndef print_maze(maze)\n puts maze.map { |row| row.join(\"\") }\nend\n\n# Initialize variables\nmaze = []; root = [0]; depth = 0; c = 0;\n\n# Read input\nn, m, k = gets.strip.split.map{|s| s.to_i}\nn.times {maze.push(gets.strip.split(\"\"))}\n\n# Convert all . to x\nfor i in 0..(n - 1) do\n for j in 0..(m - 1) do\n if maze[i][j] == \".\"\n maze[i][j] = \"X\"\n c = c + 1\n root = [i,j]\n end\n end\nend \n\n# Size of required clearing\ndepth = c - k\n\n# Solve maze\nbfs(root, maze, depth) \n\n# Print maze\nprint_maze(maze)\n"}], "negative_code": [{"source_code": "# coding: utf-8\nEMPTY = '.'\nWALL = '#'\nADDED_WALL = 'X'\nPRESERVED = 'P'\nn, m, k = gets.split.map(&:to_i)\nC = Struct.new(:i, :j)\ng = []\nec = [] # empty cells coordinates\nn.times { |i|\n r = gets.chomp.split(//)\n for j in 0...m\n if r[j] == EMPTY\n ec << C.new(i, j)\n end\n end\n g << r\n}\n\n# k \uac1c \ube14\ub7ed\uc744 \uc774\uc6a9\ud574 \uc0c8\ub85c\uc6b4 \ubcbd\uc744 \ub193\uc2b5\ub2c8\ub2e4\n# \uc717 \uc904\uc774 \uc644\uc804\ud788 \ub9c9\ud600\ub3c4 \uc0c1\uad00\uc5c6\uc9c0\ub9cc,\n# \ube14\ub7ed\uc744 \uc124\uce58\ud55c \ud6c4\uc5d0\ub3c4 \uae38\uc740 \ubaa8\ub450 \uc774\uc5b4\uc838 \uc788\uc5b4\uc57c\ud569\ub2c8\ub2e4.\n# \uc989, \ub2e4\uc74c\uacfc \uac19\uc774 \uc12c\uc774 \ub9cc\ub4e4\uc5b4\uc838\uc11c\ub294 \uc548\ub429\ub2c8\ub2e4.\n# n = 4, m = 4\n# ####\n# ##..\n# #.#.\n# ###.\n# 1. \uc804\uccb4 empty cell \uc744 \uce74\uc6b4\ud2b8 \ud569\ub2c8\ub2e4. \n# 2. empty cell \uc744 DFS/BFS \ub85c \uc21c\ud68c\ud558\uc5ec, 1\uc758 \uc218\uce58\uc5d0\uc11c k\uac1c \uc810\uc744 \uc81c\uc678\ud55c\ub9cc\ud07c \ud655\ubcf4\ud569\ub2c8\ub2e4.\n# 3. \uc5ec\uc804\ud788 \ub0a8\uc544\uc788\ub294 \uc140\ub4e4\uc744 \ubcbd\uc744 \uc124\uce58\ud560 \uc140\ub85c \ub9c8\ud06c\ud569\ub2c8\ub2e4.\n# \ubd88\ud589\ud788\ub3c4 \ucc98\uc74c\uc5d0 \uc0dd\uac01\ud55c \uc774\uc6c3\ud55c empty cell\uc774 \uc801\uc740\uac78 \ub9c8\ud0b9\ud558\ub294 \ubc29\ubc95\uc740 \uc2e4\ud328\ud569\ub2c8\ub2e4.\n\ngoal = ec.length - k\ncollected = []\nq = [ec.first]\nwhile collected.length < goal\n c = q.shift\n collected << c\n # p collected\n g[c.i][c.j] = PRESERVED\n cands = [C.new(c.i+1, c.j), C.new(c.i, c.j+1), C.new(c.i-1, c.j), C.new(c.i, c.j-1)]\n for cand in cands\n if cand.i >= 0 && cand.i < n && cand.j >= 0 && cand.j < m\n if g[cand.i][cand.j] == EMPTY\n q << cand\n end\n end\n end\nend\n\n\nputs g.map(&:join).join(\"\\n\").gsub(EMPTY, ADDED_WALL).gsub(PRESERVED, EMPTY)"}, {"source_code": "\n# Is the curren node valid?\ndef valid(node, maze)\n return false if node.min < 0\n return false if node[0] >= maze.length\n return false if node[1] >= maze[0].length\n return false if maze[node[0]][node[1]] != \"X\"\n return true\nend\n\n# Nodes connected to node\ndef children(node, maze)\n children = []\n offsets = [[-1,0],[1,0],[0,-1],[0,1]]\n for offset in offsets\n nebr = [node[0] + offset[0] ,node[1] + offset[1]]\n children.push(nebr) if valid(nebr, maze) \n end\n return children\nend\n\n# Run BFS\ndef bfs(root, maze, depth)\n queue = []; at = 0;\n queue.push(root)\n while (queue.size != 0)\n root = queue.shift\n maze[root[0]][root[1]] = \".\"\n at = at + 1\n return if at == depth\n for child in children(root, maze) do\n queue.push(child)\n end\n end\nend\n\n# Run DFS\ndef dfs(root, traversal, maze, depth)\n maze[root[0]][root[1]] = \".\"\n traversal.push(root)\n for child in children(root, maze) do\n if traversal.length < depth\n dfs(child, traversal, maze, depth)\n end\n end\nend\n\n# Initialize variables\nmaze = []; root = [0]; depth = 0; traversal = []; c = 0;\n\n# Read input\nn, m, k = gets.strip.split.map{|s| s.to_i}\nn.times {maze.push(gets.strip.split(\"\"))}\n\n# Convert all . to x\nfor i in 0..(n - 1) do\n for j in 0..(m - 1) do\n if maze[i][j] == \".\"\n maze[i][j] = \"X\"\n c = c + 1\n root = [i,j]\n end\n end\nend \n\n# Size of required clearing\ndepth = c - k\n\n# Solve maze\nbfs(root, maze, depth) \n# dfs(root, traversal, maze, depth)\n\n# Print maze\nfor i in 0..(n - 1) do\n puts maze[i].join(\"\")\nend\n"}, {"source_code": "\n# Is the curren node valid?\ndef valid(node, maze)\n return false if node.min < 0\n return false if node[0] >= maze.length\n return false if node[1] >= maze[0].length\n return false if maze[node[0]][node[1]] != \"x\"\n return true\nend\n\n# Nodes connected to node\ndef children(node, maze)\n children = []\n offsets = [[-1,0],[1,0],[0,-1],[0,1]]\n for offset in offsets\n nebr = [node[0] + offset[0] ,node[1] + offset[1]]\n children.push(nebr) if valid(nebr, maze) \n end\n return children\nend\n\n# Run DFS\ndef dfs(root, traversal, maze, depth)\n maze[root[0]][root[1]] = \".\"\n traversal.push(root)\n for child in children(root, maze) do\n if traversal.length < depth\n dfs(child, traversal, maze, depth)\n end\n end\nend\n\n# Initialize variables\nmaze = []; root = [0]; depth = 0; traversal = []; c = 0;\n\n# Read input\nn, m, k = gets.strip.split.map{|s| s.to_i}\nn.times {maze.push(gets.strip.split(\"\"))}\n\n# Convert all . to x\nfor i in 0..(n - 1) do\n for j in 0..(m - 1) do\n if maze[i][j] == \".\"\n maze[i][j] = \"X\"\n c = c + 1\n root = [i,j]\n end\n end\nend \n\n# Size of required clearing\ndepth = c - k\n\n# Solve maze\ndfs(root, traversal, maze, depth)\n\n# Print maze\nfor i in 0..(n - 1) do\n puts maze[i].join(\"\")\nend\n"}, {"source_code": "\n# Is the curren node valid?\ndef valid(node, maze)\n return false if node.min < 0\n return false if node[0] >= maze.length\n return false if node[1] >= maze[0].length\n return false if maze[node[0]][node[1]] != \"X\"\n return true\nend\n\n# Nodes connected to node\ndef children(node, maze)\n children = []\n offsets = [[-1,0],[1,0],[0,-1],[0,1]]\n for offset in offsets\n nebr = [node[0] + offset[0] ,node[1] + offset[1]]\n children.push(nebr) if valid(nebr, maze) \n end\n return children\nend\n\n# Run BFS\ndef bfs(root, maze, depth)\n queue = []; at = 0;\n queue.push(root)\n while (queue.size != 0)\n root = queue.shift\n maze[root[0]][root[1]] = \".\"\n at = at + 1\n \n puts\n puts at\n print root\n puts\n print_maze(maze)\n\n return if at == depth\n for child in children(root, maze) do\n queue.push(child) unless queue.include?(child)\n end\n end\nend\n\n# Run DFS\ndef dfs(root, traversal, maze, depth)\n maze[root[0]][root[1]] = \".\"\n traversal.push(root)\n for child in children(root, maze) do\n if traversal.length < depth\n dfs(child, traversal, maze, depth)\n end\n end\nend\n\ndef print_maze(maze)\n for i in 0..(maze.length - 1) do\n puts maze[i].join(\"\")\n end\nend\n\n# Initialize variables\nmaze = []; root = [0]; depth = 0; traversal = []; c = 0;\n\n# Read input\nn, m, k = gets.strip.split.map{|s| s.to_i}\nn.times {maze.push(gets.strip.split(\"\"))}\n\n# Convert all . to x\nfor i in 0..(n - 1) do\n for j in 0..(m - 1) do\n if maze[i][j] == \".\"\n maze[i][j] = \"X\"\n c = c + 1\n root = [i,j]\n end\n end\nend \n\n# Size of required clearing\ndepth = c - k\n\n# Solve maze\nbfs(root, maze, depth) \n# dfs(root, traversal, maze, depth)\n\nputs\nputs depth\nputs\n\n# Print maze\nprint_maze(maze)\n"}, {"source_code": "\n# Is the curren node valid?\ndef valid(node, maze)\n return false if node.min < 0\n return false if node[0] >= maze.length\n return false if node[1] >= maze[0].length\n return false if maze[node[0]][node[1]] != \"x\"\n return true\nend\n\n# Nodes connected to node\ndef children(node, maze)\n children = []\n offsets = [[-1,0],[1,0],[0,-1],[0,1]]\n for offset in offsets\n nebr = [node[0] + offset[0] ,node[1] + offset[1]]\n children.push(nebr) if valid(nebr, maze) \n end\n return children\nend\n\n# Run DFS\ndef dfs(root, traversal, maze, depth)\n maze[root[0]][root[1]] = \".\"\n traversal.push(root)\n for child in children(root, maze) do\n if traversal.length < depth\n dfs(child, traversal, maze, depth)\n end\n end\nend\n\n# Initialize variables\nmaze = []; root = [0]; depth = 0; traversal = []; c = 0;\n\n# Read input\nn, m, k = gets.strip.split.map{|s| s.to_i}\nn.times {maze.push(gets.strip.split(\"\"))}\n\n# Convert all . to x\nfor i in 0..(n - 1) do\n for j in 0..(m - 1) do\n if maze[i][j] == \".\"\n maze[i][j] = \"x\"\n c = c + 1\n root = [i,j]\n end\n end\nend \n\n# Size of required clearing\ndepth = c - k\n\n# Solve maze\ndfs(root, traversal, maze, depth)\n\n# Print maze\nfor i in 0..(n - 1) do\n puts maze[i].join(\"\")\nend\n"}, {"source_code": "\n# Is the curren node valid?\ndef valid(node, maze)\n return false if node.min < 0\n return false if node[0] >= maze.length\n return false if node[1] >= maze[0].length\n return false if maze[node[0]][node[1]] != \"X\"\n return true\nend\n\n# Nodes connected to node\ndef children(node, maze)\n children = []\n offsets = [[-1,0],[1,0],[0,-1],[0,1]]\n for offset in offsets\n nebr = [node[0] + offset[0] ,node[1] + offset[1]]\n children.push(nebr) if valid(nebr, maze) \n end\n return children\nend\n\n# Run BFS\ndef bfs(root, maze, depth)\n queue = Array.new(depth)\n queue[0] = root\n visited = Array.new(maze.length) { Array.new(maze[0].length, false) }\n front = 0; back = 1;\n while true\n root = queue[front]\n front = front + 1\n maze[root[0]][root[1]] = \".\"\n return if front == depth\n for child in children(root, maze) do\n unless visited[child[0]][child[1]]\n queue[back] = child\n back = back + 1\n end\n end\n end\nend\n\n# Print maze\ndef print_maze(maze)\n puts maze.map { |row| row.join(\"\") }\nend\n\n# Initialize variables\nmaze = []; root = [0]; depth = 0; c = 0;\n\n# Read input\nn, m, k = gets.strip.split.map{|s| s.to_i}\nn.times {maze.push(gets.strip.split(\"\"))}\n\n# Convert all . to x\nfor i in 0..(n - 1) do\n for j in 0..(m - 1) do\n if maze[i][j] == \".\"\n maze[i][j] = \"X\"\n c = c + 1\n root = [i,j]\n end\n end\nend \n\n# Size of required clearing\ndepth = c - k\n\n# Solve maze\nbfs(root, maze, depth) \n\n# Print maze\nprint_maze(maze)\n"}], "src_uid": "3aba4a129e24ca2f06f5f3ef13415b8b"} {"source_code": "n, m = gets.split.map { |x| x.to_i }\n\nacc_x = 0\nacc_y = 0\nvis_x = Array.new(n + 1)\nvis_y = Array.new(n + 1)\ncnt = n * n\nans = []\n\nm.times do\n\tx, y = gets.split.map { |x| x.to_i }\n\tif !vis_x[x]\n\t\tvis_x[x] = true\n\t\tcnt -= n - acc_y\n\t\tacc_x += 1\n\tend\n\tif !vis_y[y]\n\t\tvis_y[y] = true\n\t\tcnt -= n - acc_x\n\t\tacc_y += 1\n\tend\n\tans << cnt\nend\nputs ans.join ' '", "positive_code": [{"source_code": "n,m=gets.split.map{|e| e.to_i}\nans=[]\nxs={}\nys={}\nn2=n*n\n\nm.times{\n\tx,y=gets.split.map{|e| e.to_i}\n\tf1=xs.key?(x)\n\tf2=ys.key?(y)\n\tif f1==true && f2==true then\n\t\t#\n\telsif f1==false && f2==true then\n\t\tn2=n2-(n-ys.size)\n\telsif f1==true && f2==false then\n\t\tn2=n2-(n-xs.size)\n\t\n\telse\n\t\tn2=n2-(n*2-xs.size-ys.size)+1\n\tend\n\tans<x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2 0\n print \"#{i} \"\n i -= 2\nend\ni = 2;\nwhile i < n\n print \"#{i} \"\n i += 2\nend\ni -= 2\nprint \"#{n} \" if n % 2 == 0 and n != i\nwhile i > 0\n print \"#{i} \"\n i -= 2\nend\ni = 2\nputs n\n", "positive_code": [{"source_code": "n=gets.to_i;puts ((1+n%2).step(n-1,2).to_a+(n-1).step(1,-2).to_a+(2-n%2).step(n,2).to_a+(n-2).step(1,-2).to_a+[n])*' '"}, {"source_code": "n=gets.to_i;puts ((1+n%2).step(n-1,2).to_a+(n-1).step(1,-2).to_a+(2-n%2).step(n,2).to_a+(n-2).step(1,-2).to_a+[n])*' '\n"}, {"source_code": "n = gets.to_i\na = []\nif n.odd? then\n 1.step(n, 2) do |i|\n a.push i\n end\n (n-2).step(1, -2) do |i|\n a.push i\n end\n a.push n\n 2.step(n, 2) do |i|\n a.push i\n end\n (n-1).step(2, -2) do |i|\n a.push i\n end\nelse\n 1.step(n, 2) do |i|\n a.push i\n end\n (n-1).step(1, -2) do |i|\n a.push i\n end\n a.push n\n 2.step(n, 2) do |i|\n a.push i\n end\n (n-2).step(2, -2) do |i|\n a.push i\n end\nend\nputs a.join(' ')\n"}, {"source_code": "n=gets.to_i;puts ((1+n%2).step(n-1,2).to_a+(n-1).step(1,-2).to_a+(2-n%2).step(n,2).to_a+(n-2).step(1,-2).to_a+[n])*' '\n"}, {"source_code": "n=gets.to_i;puts ((1+n%2).step(n-1,2).to_a+(n-1).step(1,-2).to_a+(2-n%2).step(n,2).to_a+(n-2).step(1,-2).to_a+[n])*' '\n"}, {"source_code": "n=gets.to_i;puts ((1+n%2).step(n-1,2).to_a+(n-1).step(1,-2).to_a+(2-n%2).step(n,2).to_a+(n-2).step(1,-2).to_a+[n])*' '\n"}], "negative_code": [{"source_code": "puts (1..gets.to_i).flat_map{|e|[e]*2}*' '"}], "src_uid": "c234cb0321e2bd235cd539a63364b152"} {"source_code": "RECURSIVE = false\n\ndef fact(n, p)\n return 1.upto(n).reduce(1.0) {|acc, x| (acc * x) % p } unless RECURSIVE\n\n if n <= 1\n return 1\n else\n return (n * fact(n - 1, p)) % p\n end\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_f\n a = gets.to_s.split.map {|x| x.to_i }\n\n mask = ~a.reduce(0xFFFFFFFF) {|acc, x| acc & x }\n zerocnt = a.reduce(0) {|acc, val| acc + (((val & mask) == 0) ? 1 : 0) }\n\n p = 10 ** 9 + 7\n permcnt = fact(n - 2, p) * zerocnt % p * (zerocnt - 1) % p\n printf(\"%d\\n\", permcnt)\nend\n", "positive_code": [{"source_code": "RECURSIVE = false\n\ndef fact(n, p)\n return 1.upto(n).reduce(1) {|acc, x| (acc * x) % p } unless RECURSIVE\n\n if n <= 1\n return 1\n else\n return (n * fact(n - 1, p)) % p\n end\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_f\n a = gets.to_s.split.map {|x| x.to_i }\n\n mask = ~a.reduce(0xFFFFFFFF) {|acc, x| acc & x }\n zerocnt = a.reduce(0) {|acc, val| acc + (((val & mask) == 0) ? 1 : 0) }\n\n permcnt = fact(n - 2, 10 ** 9 + 7) * zerocnt * (zerocnt - 1)\n printf(\"%d\\n\", permcnt % (10 ** 9 + 7))\nend\n"}, {"source_code": "def fact(n, p)\n result = 1\n for i in (1 .. n) do\n result = (result * i) % p\n end\n result\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n bitcounters = [0] * 32\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }\n\n valmask = 0\n 0.upto(31) do |bitidx|\n bitmask = 1 << bitidx\n a.each do |val|\n if val & bitmask != 0\n bitcounters[bitidx] += 1\n end\n end\n valmask |= bitmask if bitcounters[bitidx] != a.size\n end\n\n zerocnt = 0\n a.each {|val| zerocnt += 1 if (val & valmask) == 0 }\n\n permcnt = fact(n - 2, 10 ** 9 + 7) * zerocnt * (zerocnt - 1)\n printf(\"%d\\n\", permcnt % (10 ** 9 + 7))\nend\n"}], "negative_code": [{"source_code": "RECURSIVE = false\n\ndef fact(n, p)\n return 1.upto(n).reduce(1.0) {|acc, x| (acc * x) % p } unless RECURSIVE\n\n if n <= 1\n return 1\n else\n return (n * fact(n - 1, p)) % p\n end\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_f\n a = gets.to_s.split.map {|x| x.to_i }\n\n mask = ~a.reduce(0xFFFFFFFF) {|acc, x| acc & x }\n zerocnt = a.reduce(0) {|acc, val| acc + (((val & mask) == 0) ? 1 : 0) }\n\n permcnt = fact(n - 2, 10 ** 9 + 7) * zerocnt * (zerocnt - 1)\n printf(\"%d\\n\", permcnt % (10 ** 9 + 7))\nend\n"}, {"source_code": "def fact(n, p)\n result = 1\n for i in (1 .. n) do\n result = (result * i) % p\n end\n result\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n bitcounters = [0] * 32\n n = gets.to_s.to_i\n a = gets.to_s.split.map {|x| x.to_i }\n\n valmask = 0\n 0.upto(31) do |bitidx|\n bitmask = 1 << bitidx\n a.each do |val|\n if val & bitmask != 0\n bitcounters[bitidx] += 1\n end\n end\n valmask |= bitmask if bitcounters[bitidx] != a.size\n end\n\n zerocnt = 0\n a.each {|val| zerocnt += 1 if (val & valmask) == 0 }\n\n permcnt = (fact(n, 10 ** 9 + 7) * zerocnt * (zerocnt - 1) / (n * (n - 1)))\n printf(\"%d\\n\", permcnt % (10 ** 9 + 7))\nend\n"}], "src_uid": "e4685bb0a1bf8c2da326cd0e5b8f4fe7"} {"source_code": "require 'scanf'\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nn, m = scanf(\"%d%d\\n\")\nd = Array.new(n) { 0 }\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = scanf(\"%d%d\\n\")\n#\tputs \"a = #{a}, b = #{b}\"\n\ta -= 1\n\tb -= 1\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\n#puts \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in (n-1).downto(i)\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\nend\n", "positive_code": [{"source_code": "require 'scanf'\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nn, m = scanf(\"%d%d\\n\")\nd = Array.new(n) { 0 }\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = gets.chomp.scanf(\"%d %d\")\n#\tputs \"a = #{a}, b = #{b}\"\n\ta -= 1\n\tb -= 1\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\n#puts \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in (n-1).downto(i)\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "require 'scanf'\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nn, m = scanf(\"%d %d\\n\")\nd = Array.new(n) { 0 }\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = scanf(\"%d %d\\n\")\n#\tputs \"a = #{a}, b = #{b}\"\n\ta -= 1\n\tb -= 1\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\n#puts \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in (n-1).downto(i)\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\nend\n"}], "negative_code": [{"source_code": "require 'scanf'\n\nn, m = scanf(\"%d %d\")\nd = Array.new(n) { 0 }\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = scanf(\"%d %d\").map { |x| x - 1 }\n\tputs \"a = #{a}, b = #{b}\"\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\nputs \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "require 'scanf'\nrequire 'matrix'\n\nclass Matrix \n\tdef []=(i,j,x)\n\t\t@rows[i][j] = x\n\tend\nend\n\nn, m = scanf(\"%d %d\")\ng = Matrix.build(n) { 0 }\nd = Array.new(n) { 0 }\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = scanf(\"%d %d\").map { |x| x - 1 }\n\tg[a, b] = 1\n\tg[b, a] = 1\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "require 'scanf'\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nn, m = scanf(\"%d%d\")\nd = Array.new(n) { 0 }\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = scanf(\"%d%d\")\n\tputs \"a = #{a}, b = #{b}\"\n\ta -= 1\n\tb -= 1\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\nputs \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "require 'scanf'\n\nn, m = scanf(\"%d %d\")\nd = Array.new(n) { 0 }\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = scanf(\"%d %d\").map { |x| x - 1 }\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\nputs \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "require 'scanf'\n\nn, m = scanf(\"%d%d\")\nd = Array.new(n) { 0 }\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = scanf(\"%d%d\")\n\tputs \"a = #{a}, b = #{b}\"\n\ta -= 1\n\tb -= 1\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\nputs \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "require 'scanf'\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nn, m = scanf(\"%d%d\")\nd = Array.new(n) { 0 }\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = scanf(\"%d%d\")\n#\tputs \"a = #{a}, b = #{b}\"\n\ta -= 1\n\tb -= 1\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\n#puts \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in (n-1).downto(i)\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "require 'scanf'\n\nn, m = scanf(\"%d %d\")\nd = Array.new(n) { 0 }\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = scanf(\"%d %d\")\n\tputs \"a = #{a}, b = #{b}\"\n\ta -= 1\n\tb -= 1\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\nputs \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "require 'scanf'\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nn, m = scanf(\"%d%d\\n\")\nd = Array.new(n) { 0 }\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = gets.chomp.scanf(\"%d %d\")\n#\tputs \"a = #{a}, b = #{b}\"\n\ta -= 1\n\tb -= 1\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\n#puts \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "require 'scanf'\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nn, m = scanf(\" %d%d\")\nd = Array.new(n) { 0 }\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = scanf(\" %d%d\")\n#\tputs \"a = #{a}, b = #{b}\"\n\ta -= 1\n\tb -= 1\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\n#puts \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in (n-1).downto(i)\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\nend\n"}, {"source_code": "require 'scanf'\n\nclass UnionFindSet\n\tdef initialize(n)\n\t\t@n = n\n\t\t@bel = Array.new(n) { |x| x }\n\tend\n\n\tdef find(x)\n\t\t@bel[x] = find(@bel[x]) unless @bel[x] == x\n\t\t@bel[x]\n\tend\n\n\tdef union(x, y) \n\t\t@bel[find(x)] = find(y)\n\tend\nend\n\nn, m = scanf(\"%d%d\\n\")\nd = Array.new(n) { 0 }\n\nuf = UnionFindSet.new(n)\njoinEdge = 0\nfor i in 1..m\n\ta, b = gets.chomp.scanf(\"%d %d\")\n\tputs \"a = #{a}, b = #{b}\"\n\ta -= 1\n\tb -= 1\n\td[a] += 1\n\td[b] += 1\n\tjoinEdge += 1 if uf.find(a) == uf.find(b)\n\tuf.union(a, b)\nend\n\nmaxDeg = d.max\nputs \"max deg = #{maxDeg}, joinEdge = #{joinEdge}, n = #{n}, m = #{m}\"\n\nif maxDeg > 2\n\tputs \"NO\"\nelsif joinEdge > 0\n\tif maxDeg == 2 and joinEdge == 1 and n == m\n\t\tputs \"YES\"\n\t\tputs \"0\"\n\telse \n\t\tputs \"NO\"\n\tend\nelse\n\tputs \"YES\"\n\tputs \"#{n - m}\"\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 and uf.find(i) != uf.find(j)\n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\t\tuf.union(i, j)\n\t\t\t\td[i] += 1\n\t\t\t\td[j] += 1\n\t\t\tend\n\t\tend\n\tend\n\tfor i in 0...n\n\t\tfor j in i+1...n\n\t\t\tif d[i] < 2 and d[j] < 2 \n\t\t\t\tputs \"#{i+1} #{j+1}\"\n\t\t\tend\n\t\tend\n\tend\nend\n"}], "src_uid": "bbcb051b08fa3d19a7cf285242d50451"} {"source_code": "n = gets.chop.to_i\na = gets.chop.split(/ /).map!{|x| x.to_i}\npa = Array.new\nma = Array.new\nbzero = false\nfor i in 0..n-1\n\tif a[i] == 0\n\t\tbzero = true \n\telsif a[i] > 0\n\t\tpa.push(a[i])\n\telse\n\t\tma.push(a[i])\n\tend\nend\nma.sort!{|a,b| a <=> b }\nmac = (ma.length / 2)*2\nret = \"\"\nfor i in 0..mac-1\n\tret << \" \" if ret.length > 0\n\tret << ma[i].to_s\nend\nfor i in 0..pa.length-1\n\tret << \" \" if ret.length > 0\n\tret << pa[i].to_s\nend\n\nif n == 1\n\tputs a[0]\nelsif ret == \"\" && bzero\n\tputs \"0\"\nelse\n\tputs ret\nend\n", "positive_code": [{"source_code": "n = gets.to_i\ncosts = gets.split.map { |v| v.to_i }\n\npositive = costs.select { |v| v > 0 }.sort\nnegative = costs.select { |v| v < 0 }.sort\n\nnegative.pop if negative.size.odd?\n\nresult = negative + positive\nresult = Array(costs.max) if result.empty?\n\nputs result.join(' ')\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nx=a.delete 0\nputs(if a.size<1\n\t0\nelsif a.size<2\n\tx ? [a[0],x].max : a[0]\nelsif a.count{|_|_<0}%2<1\n\ta*\" \"\nelse\n\ta.delete_at a.each_with_index.select{|v,i|v<0}.sort[-1][1]\n\ta*\" \"\nend)"}], "negative_code": [{"source_code": "gets\na=gets.split.map &:to_i\na.delete 0\nputs(if a.size<1\n\t0\nelsif a.size<2\n\ta[0]\nelsif a.count{|_|_<0}%2<1\n\ta*\" \"\nelse\n\ta.delete_at a.each_with_index.select{|v,i|v<0}.sort[-1][1]\n\ta*\" \"\nend)"}, {"source_code": "n = gets.chop.to_i\na = gets.chop.split(/ /).map!{|x| x.to_i}\npa = Array.new\nma = Array.new\nbzero = false\nfor i in 0..n-1\n\tbzero = true if a[i] == 0\n\tif a[i] > 0\n\t\tpa.push(a[i])\n\telse\n\t\tma.push(a[i])\n\tend\nend\nma.sort!{|a,b| b <=> a }\nmac = (ma.length / 2)*2\nret = \"\"\nfor i in 0..mac-1\n\tret << \" \" if i > 0\n\tret << ma[i].to_s\nend\nfor i in 0..pa.length-1\n\tret << \" \" if i > 0\n\tret << pa[i].to_s\nend\n\nif n == 1\n\tputs a[0]\nelsif ret == \"\" && bzero\n\tputs \"0\"\nelse\n\tputs ret\nend\n"}, {"source_code": "n = gets.chop.to_i\na = gets.chop.split(/ /).map!{|x| x.to_i}\npa = Array.new\nma = Array.new\nbzero = false\nfor i in 0..n-1\n\tbzero = true if a[i] == 0\n\tif a[i] > 0\n\t\tpa.push(a[i])\n\telse\n\t\tma.push(a[i])\n\tend\nend\nma.sort!{|a,b| a <=> b }\nmac = (ma.length / 2)*2\nret = \"\"\nfor i in 0..mac-1\n\tret << \" \" if ret.length > 0\n\tret << ma[i].to_s\nend\nfor i in 0..pa.length-1\n\tret << \" \" if ret.length > 0\n\tret << pa[i].to_s\nend\n\nif n == 1\n\tputs a[0]\nelsif ret == \"\" && bzero\n\tputs \"0\"\nelse\n\tputs ret\nend\n"}, {"source_code": "n = gets.chop.to_i\na = gets.chop.split(/ /).map!{|x| x.to_i}\npa = Array.new\nma = Array.new\nbzero = false\nfor i in 0..n-1\n\tbzero = true if a[i] == 0\n\tif a[i] > 0\n\t\tpa.push(a[i])\n\telse\n\t\tma.push(a[i])\n\tend\nend\nma.sort!{|a,b| b <=> a }\nmac = (ma.length / 2)*2\nret = \"\"\nfor i in 0..mac-1\n\tret << \" \" if i > 0\n\tret << ma[i].to_s\nend\nfor i in 0..pa.length-1\n\tret << \" \" if i > 0\n\tret << pa[i].to_s\nend\n\nif ret == \"\" && bzero\n\tputs \"0\"\nelse\n\tputs ret\nend\n"}], "src_uid": "b11644953bdd1b92eb1b18c339a268a1"} {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nna = gets.to_i\nar = gets.split.map(&:to_i)\nnb = gets.to_i\nbr = gets.split.map(&:to_i)\n\ncatch :found do\n ar.each { |ia|\n br.each { |ib|\n s = ia + ib\n if ar.index(s) == nil && br.index(s) == nil\n puts \"#{ia} #{ib}\"\n throw :found\n end\n }\n }\nend", "positive_code": [{"source_code": "n = readline.to_i\na = readline.split.map(&:to_i)\nm = readline.to_i\nb = readline.split.map(&:to_i)\n\nprintf \"%d %d\\n\", a.max, b.max"}, {"source_code": "a_size = gets.strip.to_i\na_string = gets.strip\n\nb_size = gets.strip.to_i\nb_string = gets.strip\n\na = a_string.split(' ').map(&:to_i)\nb = b_string.split(' ').map(&:to_i)\n\noutput = nil\n\na.each_with_index do |a_element, _a_index|\n b.each_with_index do |b_element, _b_index|\n sum = a_element + b_element\n next if a.include?(sum) || b.include?(sum)\n\n output = \"#{a_element} #{b_element}\"\n break\n end\n\n break unless output.eql?(nil)\nend\n\nputs output\n"}, {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\nm = gets.to_i\nbs = gets.split.map(&:to_i)\n\nputs \"#{as.max} #{bs.max}\""}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\ngets\nb = gets.split(' ').map(&:to_i)\nputs a.max.to_s + ' ' + b.max.to_s"}, {"source_code": "n = gets.to_i\naa = gets.split.map(&:to_i).sort\nm = gets.to_i\nbb = gets.split.map(&:to_i).sort\n\nputs \"#{aa.last} #{bb.last}\""}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nm = gets.to_i\nb = gets.split.map &:to_i\nprint a.max, ' ', b.max\n"}], "negative_code": [{"source_code": "gets\na = gets.split(' ').map(&:to_i)\ngets\nb = gets.split(' ').map(&:to_i)\nputs a.max + b.max"}], "src_uid": "ec09b2df4ed3abbca4c47f48f12010ca"} {"source_code": "\ndef solution(arr)\n odd, even = 0, 0\n arr.each do |e|\n if e % 2 == 0\n even += 1\n else\n odd += 1\n end\n end\n puts odd < even ? odd : even \nend\n\n\nn = $stdin.gets.to_i\n(0...n).each do |i|\n size = $stdin.gets.to_i \n arr = $stdin.gets.to_s.split(' ').map(&:to_i)\n solution(arr)\nend\n\n\n", "positive_code": [{"source_code": "gets.to_i.times do\r\nn = gets\r\na = gets.split(' ').map(&:to_i)\r\nputs [a.select{|a|a%2==1}.size, a.select{|a|a%2==0}.size].min\r\nend"}, {"source_code": "t = gets.to_i\n\n(0...t).each do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n\n even_count = a.select(&:even?).count\n odd_count = a.count - even_count\n puts [even_count, odd_count].min\nend\n"}, {"source_code": "gets.to_i.times {\n\tm = gets.to_i\n\tn = gets.split.map(&:to_i).count{|a| a.even?}\n\tp [n, m-n].min\n} "}], "negative_code": [{"source_code": "t = gets.to_i\n\n(0...t).each do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n\n k = 0\n idx = 0\n # prev_idx = 0\n while idx < a.size\n next_id = idx + 1\n # puts \"#{prev_idx}-#{idx}-#{a.inspect} - #{k}\"\n x = a[idx]\n y = a[next_id]\n break if y.nil?\n sum = x + y\n\n if sum.even?\n idx += 1\n next\n else\n # if x.even? && y.odd?\n a.delete_at(next_id)\n\n # elsif y.odd?\n # a.delete_at(next_id)\n # idx += 1\n # end\n # idx -= 1\n # if a[idx].odd?\n # a.delete_at(idx)\n # end\n k += 1\n end\n end\n\n puts k\n\nrescue => e\n puts e\n puts a.inspect\n exit(1)\nend\n"}, {"source_code": "t = gets.to_i\n\n(0...t).each do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n\n k = 0\n idx = 0\n # prev_idx = 0\n while idx < a.size\n next_id = idx + 1\n # puts \"#{prev_idx}-#{idx}-#{a.inspect} - #{k}\"\n x = a[idx]\n y = a[next_id]\n break if y.nil?\n sum = x + y\n\n if sum.even?\n idx += 1\n next\n else\n if x.odd?\n a.delete_at(idx)\n\n elsif y.odd?\n a.delete_at(next_id)\n end\n # idx -= 1\n # if a[idx].odd?\n # a.delete_at(idx)\n # end\n k += 1\n end\n end\n\n puts k\n\nrescue => e\n puts e\n puts a.inspect\n exit(1)\nend\n"}, {"source_code": "t = gets.to_i\n\n(0...t).each do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n\n k = 0\n idx = 0\n # prev_idx = 0\n while idx < a.size\n next_id = idx + 1\n # puts \"#{prev_idx}-#{idx}-#{a.inspect} - #{k}\"\n x = a[idx]\n y = a[next_id]\n break if y.nil?\n sum = x + y\n\n if sum.even?\n idx += 1\n next\n else\n if x.odd?\n a.delete_at(idx)\n # idx -= 1\n elsif y.odd?\n a.delete_at(next_id)\n end\n\n # if a[idx].odd?\n # a.delete_at(idx)\n # end\n k += 1\n end\n end\n\n puts k\n\nrescue => e\n puts e\n puts a.inspect\n exit(1)\nend\n"}, {"source_code": "t = gets.to_i\n\n(0...t).each do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n\n k = 0\n idx = 1\n while idx < a.size\n prev_idx = idx - 1\n # puts \"#{prev_idx}-#{idx}-#{a.size}\"\n sum = a[prev_idx] + a[idx]\n\n if sum.even?\n idx += 1\n next\n else\n # if a[prev_idx].odd?\n # a.delete_at(prev_idx)\n # elsif a[idx].odd?\n # a.delete_at(idx)\n # end\n # if a[idx].odd?\n a.delete_at(idx)\n # end\n k += 1\n end\n end\n\n puts k\n\n# rescue => e\n# puts a.inspect\n# exit(1)\nend\n"}, {"source_code": "t = gets.to_i\n\n(0...t).each do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n\n k = 0\n idx = 1\n while idx < a.size\n prev_idx = idx - 1\n # puts \"#{prev_idx}-#{idx}-#{a.size}\"\n sum = a[prev_idx] + a[idx]\n\n if sum.even?\n idx += 2\n next\n else\n if a[prev_idx].odd?\n a.delete_at(prev_idx)\n elsif a[idx].odd?\n a.delete_at(idx)\n end\n k += 1\n end\n end\n\n puts k\n\n# rescue => e\n# puts a.inspect\n# exit(1)\nend\n"}, {"source_code": "t = gets.to_i\n\n(0...t).each do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n\n k = 0\n idx = 1\n while idx <= a.size\n prev_idx = idx - 1\n sum = a[prev_idx] + a[idx]\n\n if sum.even?\n idx += 2\n next\n else\n if a[prev_idx].odd?\n a.delete_at(prev_idx)\n elsif a[idx].odd?\n a.delete_at(idx)\n end\n k += 1\n end\n end\n\n puts k\n\nrescue => e\n puts e\nend\n"}], "src_uid": "4b33db3950303b8993812cb265fa9819"} {"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i)\nans = 0\nwhile as.length > 0\n a = as.shift\n ans += as.index(a)\n as.delete(a)\nend\nputs ans", "positive_code": [{"source_code": "n = gets.to_i\nary = gets.strip.split.map(&:to_i)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nsz = ary.size\nans = 0\n0.upto(n-1).each do |i|\n ai = i*2\n e = ary[ai]\n eni = ai + 1\n (ai+1).upto(sz-1).each do |j|\n if ary[j] == e\n eni = j\n break\n end\n end\n eni.downto(ai+2).each do |j|\n ary[j] = ary[j-1]\n ary[j-1] = e\n ans += 1\n end\nend\nputs ans"}], "negative_code": [], "src_uid": "194bc63b192a4e24220b36984901fb3b"} {"source_code": "n = gets.to_i\nop = Hash.new \"PLR\"\nop[0] = \"PRL\"\ngets.split(' ',n).map(&:to_i).each_with_index do |x,id|\n if id == 0\n print \"PRL\" * x\n else\n print \"R\"\n print \"PLR\" * x\n end\nend", "positive_code": [{"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\nsov = Array.new\nif a[0] != 0\n sov[0] = \"PRL\" * (a[0]-1) + \"P\"\nelse\n sov[0] = nil\nend\nb = Array.new\nfor i in 1...n\n if a[i] >= 1\n b[i] = \"RPL\" * (a[i]-1) + \"RP\"\n else a[i] == 0\n b[i] = \"R\"\n end\n\n sov.push(b[i])\nend\nprint sov.join"}, {"source_code": "n=gets.to_i\nd=gets.split.map(&:to_i)\nans=''\nn.times do |i|\n if i == 0\n ans+= 'RLP'*d[i]\n else\n ans+= 'LRP'*d[i]\n end\n ans+='R'\nend\nputs ans[0..-2]"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nprint 'PRL'*a[0]\n(1..n-1).each{|i|print 'R','PLR'*a[i]}"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nx=0\ns=''\nloop do\n (a[x]-=1;s<<'P')if a[x]>0\n if x==0\n x+=1\n s<<'R'\n elsif a[x-1]>0 || a[x]>0\n x-=1\n s<<'L'\n elsif x==n-1\n if a[x]>0\n x-=1\n s<<'L'\n else\n break\n end\n elsif\n x+=1\n s<<'R'\n end\nend\nputs s"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nprint 'PRL' * a[0]\nc = false\nif a[n-1] != 0\na[n-1] -= 1\nc = true\nend\n(1..n-1).each{|i| print 'R', 'PLR' * a[i]}\nif c\nprint 'P'\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nprint 'PRL' * a[0]\n(1..n-1).each{|i| print 'R', 'PLR' * a[i]}"}, {"source_code": "=begin\nDear online judge:\nI've wasted time reading the problem and trying to figure out the solution\nIf you insist on the penalty system, please don't include the time of debugging\nI hope my code compile and get accepted. KEE O.o\n ____________\n / __ \\\n / __ | | \\\n / |__| | | \\\n ( |__| )\n \\ /\n \\ ___ /\n \\____________/\n=end\n\nclass Solve\n def solve()\n $n = Integer(gets)\n $list = gets().split()\n $count = 0\n $n -= 1\n for $i in 0..$n do\n if $list[$i] != \"0\"\n $count += Integer($list[$i])\n end\n end\n $res = \"\"\n $dir = 1\n $i = 0\n $cur = Array.new($n + 1,0)\n while $count > 0 do\n if $cur[$i] < Integer($list[$i])\n $cur[$i] += 1\n $count -= 1\n $res<<'P'\n end\n if $count > 0\n if $i == $n\n $dir = -1\n else\n if $i == 0\n $dir = 1\n end\n end\n if $dir == 1\n $res<<'R'\n end\n if $dir == -1\n $res<<'L'\n end\n end\n $i += $dir\n end\n puts $res\n end\nend\n\n\n\nSolve.new.solve"}, {"source_code": "RIGHT = 1\nLEFT = 0\n\nwallets_count, *wallets = STDIN.read.split\n\nwallets.map!(&:to_i)\nwallets_count = wallets_count.to_i\n\nindex = 0\ndirection = RIGHT\ncoins_to_give = wallets.inject(0) { |sum, value| sum + value }\n\nuntil coins_to_give.zero?\n if wallets[index] > 0\n print :P\n wallets[index] -= 1\n coins_to_give -= 1\n break if coins_to_give.zero?\n end\n\n if (direction == RIGHT && index < wallets_count - 1) || (direction == LEFT && index == 0)\n print :R\n index += 1\n direction = RIGHT\n else\n print :L\n index -= 1\n direction = LEFT\n end\nend\n\nprint \"\\n\"\n"}, {"source_code": "inA = gets\ninB = gets\ncount = inA.to_i\n\ncounts = inB.split\ncounts.map! {|x| x.to_i}\n\nresult = \"\"\nposition = 0\nforward = true\nlastPuted = 0\nwhile true\n\tif(counts[position] > 0)\n\t\tresult << 'P'\n\t\tlastPuted = 0\n\t\tcounts[position] -= 1\n\telse\n\t\tlastPuted += 1\n\tend\n\n\tif(forward && (position == counts.length() -1))\n\t\tforward = false\n\telsif ( (!forward) && position == 0)\n\t\tforward = true\n\tend\n\n\tif(forward)\n\t\tposition += 1\n\t\tresult << 'R'\n\telse\n\t\tposition -= 1\n\t\tresult << 'L'\n\tend\n\n\tif(lastPuted > (counts.length*2 + 2))\n\t\tputs result.slice(0, result.length - lastPuted - 1)\n\t\tbreak\n\tend\nend\n\n"}], "negative_code": [{"source_code": "inA = gets\ninB = gets\ncount = inA.to_i\n\ncounts = inB.split\ncounts.map! {|x| x.to_i}\n\nresult = \"\"\nposition = 0\nforward = true\nlastPuted = 0\nwhile true\n\tif(counts[position] > 0)\n\t\tresult << 'P'\n\t\tlastPuted = 0\n\t\tcounts[position] -= 1\n\telse\n\t\tlastPuted += 1\n\tend\n\n\tif(forward && (position == counts.length() -1))\n\t\tforward = false\n\telsif ( (!forward) && position == 0)\n\t\tforward = true\n\tend\n\n\tif(forward)\n\t\tposition += 1\n\t\tresult << 'R'\n\telse\n\t\tposition -= 1\n\t\tresult << 'L'\n\tend\n\n\tif(lastPuted > counts.length)\n\t\tputs result.slice(0, result.length - lastPuted - 1)\n\t\tbreak\n\tend\nend\n\n"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\nsov = Array.new\nif a[0] != 0\n sov[0] = \"PRL\" * (a[0]-1) + \"PR\"\nelse\n sov[0] = nil\nend\nb = Array.new\nfor i in 1...n\n b[i] = (\"R\" * i + \"P\" + \"L\" * i) * a[i]\n sov.push(b[i])\nend\nprint sov.join"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\nsov = Array.new\nif a[0] != 0\n sov[0] = \"PRL\" * (a[0]-1) + \"PR\"\nelse\n sov[0] = nil\nend\nb = Array.new\nfor i in 1...n\n if a[i] >= 2\n b[i] = \"PL\" + \"RPL\" * (a[i]-2) + \"RP\"\n else a[i] = 1\n b[i] = \"PL\"\n end\n\n sov.push(b[i])\nend\nprint sov.join"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\nsov = Array.new\nif a[0] != 0\n sov[0] = \"PRL\" * (a[0]-1) + \"PR\"\nelse\n sov[0] = \"R\"\nend\nb = Array.new\nfor i in 1...n\n if a[i] >= 2\n b[i] = \"PL\" + \"RPL\" * (a[i]-2) + \"RP\"\n elsif a[i] == 1\n b[i] = \"PL\"\n else a[i] == 0\n b[i] = \"R\"\n end\n\n sov.push(b[i])\nend\nprint sov.join"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\nsov = Array.new\nsov[0] = \"PRL\" * a[0]\nb = Array.new\nfor i in 1...n\n b[i] = (\"R\" * i + \"P\" + \"L\" * i) * a[i]\n sov.push(b[i])\nend\nprint sov.join"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\nsov = Array.new\nif a[0] != 0\n sov[0] = \"PRL\" * (a[0]-1) + \"PR\"\nelse\n sov[0] = \"R\"\nend\nb = Array.new\nfor i in 1...n\n if a[i] >= 2\n b[i] = \"PL\" + \"RPL\" * (a[i]-2) + \"RP\"\n elsif a[i] == 1\n b[i] = \"PL\"\n else a[i] == 0\n b[i] = \"RR\"\n end\n\n sov.push(b[i])\nend\nprint sov.join"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\nsov = Array.new\nif a[0] != 0\n sov[0] = \"PRL\" * (a[0]-1) + \"PR\"\nelse\n sov[0] = \"R\"\nend\nb = Array.new\nfor i in 1...n\n if a[i] >= 2\n b[i] = \"PL\" + \"RPL\" * (a[i]-2) + \"RP\"\n else a[i] = 1\n b[i] = \"PL\"\n end\n\n sov.push(b[i])\nend\nprint sov.join"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nprint 'PRL' * a[0]\nif a[n-1] != 0\na[n-1] -= 1\nend\n(1..n-1).each{|i| print 'R', 'PLR' * a[i]}\nprint 'P'"}], "src_uid": "50e88225d8b081d63eebe446f48057f4"} {"source_code": "h,w=gets.split.map &:to_i;a,b=[[h,w],[w,h]].map{|a,b|2**Math.log2([a,b*5/4].min).to_i};c,e=[h,b*5/4].min,[w,a*5/4].min;a,e=c,b if c*b>a*e||c*b==a*e&&c>a;$>< (2 ** n / 1.25).to_i\n return (2 ** n / 1.25).to_i, 2 ** n\n else\n return 2 ** m, (1.25 * 2 ** m).to_i\n end\n else\n return 2 ** m, (1.25 * 2 ** m).to_i\n end\nend\n\ny, x = gets.split.map(&:to_i)\nx0, y0 = x, y\nswap = false\nif x > y\n x, y = y, x\n swap = true\nend\n\np, q = solve(x, y)\nif swap\n p, q = q, p\nend\nif p > q and (p <= y0 and q <= x0)\n p, q = q, p\nend\nprintf(\"%d %d\\n\", q, p)\n"}, {"source_code": "h,w=gets.split.map &:to_i;a,b=[[h,w],[w,h]].map{|a,b|2**Math.log2([a,b*5/4].min).to_i};c,e=[h,b*5/4].min,[w,a*5/4].min;a,e=c,b if c*b>a*e||c*b==a*e&&c>a;$><a*e||c*b==a*e&&c>a;$><a*e||c*b==a*e&&c>a;$><a*e||c*b==a*e&&c>a;$><a*e||c*b==a*e&&c>a ?[c,b]:[a,e])"}, {"source_code": "h,w=gets.split.map &:to_i;a,b=[[h,w],[w,h]].map{|a,b|2**Math.log2([a,b*5/4].min).to_i};c,e=[h,b*5/4].min,[w,a*5/4].min;a,e=c,b if c*b>a*e||c*b==a*e&&c>a;$><a*e||c*b==a*e&&c>a;$><a*e||c*b==a*e&&c>a;$><a*e||c*b==a*e&&c>a;$><a*e||c*b==a*e&&c>a;$><a*e||c*b==a*e&&c>a;$><a*e||c*b==a*e&&c>a;$><a*e||c*b==a*e&&c>a;$>< (2 ** n / 1.25).to_i\n return (2 ** n / 1.25).to_i, 2 ** n\n else\n return 2 ** m, (1.25 * 2 ** m).to_i\n end\n else\n return 2 ** m, (1.25 * 2 ** m).to_i\n end\nend\n\ny, x = gets.split.map(&:to_i)\nswap = false\nif x > y\n x, y = y, x\n swap = true\nend\n\np, q = solve(x, y)\nif swap\n p, q = q, p\nend\nprintf(\"%d %d\\n\", q, p)\n"}, {"source_code": "def solve(x, y)\n m = Math.log2(x).to_i\n n = Math.log2(y).to_i\n if n == m\n return 2 ** n, [y, (1.25*x).to_i].min\n elsif n == m + 1\n if x > (2 ** n / 1.25).to_i\n return (2 ** n / 1.25).to_i, 2 ** n\n else\n return 2 ** m, (1.25 * 2 ** m).to_i\n end\n else\n return 2 ** m, (1.25 * 2 ** m).to_i\n end\nend\n\ny, x = gets.split.map(&:to_i)\nswap = false\nif x > y\n x, y = y, x\n swap = true\nend\n\np, q = solve(x, y)\nif swap\n p, q = q, p\nend\nprintf(\"%d %d\\n\", q, p)\n"}, {"source_code": "h,w=gets.split.map &:to_i;a,b=[[h,w],[w,h]].map{|(a,b)|2**Math.log2([a,b*5/4].min).to_i};c,e=[h,b*5/4].min,[w,a*5/4].min;c,b=a,e if c*b>a*e||c*b==a*e&&c>a;$>< n\n (p*p).step(n, p){ |m| all_nums[m] = nil }\n end\n all_nums.compact\nend\n\namount = 1000000\nprimes = prime(amount)\n\nt = {}\nprimes.map{|p| t[p*p]=true }\n\ncol = gets.to_i\narr = gets.split(\" \").map{|p| p.to_i }\n\n(0..col-1).each do |i|\n\tif t[arr[i]] then\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\n\n"}, {"source_code": "# require 'prime'\n\nn = gets.to_i\nf = gets.split.map { |x| x.to_i }\n\n# p = Prime.first(700000)\nis_prime = Array.new(1000001, true)\nis_prime[0] = is_prime[1] = false\n2.upto(1000001) do |i|\n\tif is_prime[i]\n\t\tj = i * 2\n\t\twhile j < 1000001\n\t\t\tis_prime[j] = false\n\t\t\tj += i\n\t\tend\n\tend\nend\n\nf.each do |x|\n\tt = (x ** 0.5).round\n\tif t ** 2 == x and is_prime[t]\n\t\tputs 'YES'\n\telse\n\t\tputs 'NO'\n\tend\nend\n"}, {"source_code": "require 'prime'\n\nc=(0..10**6).map{0}\nc[0]=1\nc[1]=1\nb=2\nwhile b*b<=(10**6)\n\tif c[b]==0 then\n\t\tb2=b+b\n\t\twhile b2<=10**6\n\t\t\tc[b2]=1\n\t\t\tb2=b2+b\n\t\tend\n\tend\n\tb=b+1\nend\ngets\nx=gets.split.map{|e| e.to_i}\n\nx.each{|e|\n\tm=(e**0.5).to_i\n\tif m*m==e && c[m]==0 then\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\n}\n\n"}, {"source_code": "a = Array.new(1000001,0) \na[1] = -1\ni = 3\nwhile i < 1000\n\tif a[i] == 0\n\t\tj = i+i\n\t\twhile j < 1000000\n\t\t\ta[j] = -1\n\t\t\tj += i\n\t\tend\n\tend\n\ti += 2\nend\nn = gets.to_i\ngets.split.map(&:to_i).each do |i|\n\tx = Math.sqrt(i)\n\tif x % 1 == 0\n\t\tif x % 2 == 0 and x != 2\n\t\t\tputs 'NO'\n\t\telse\n\t\t\tif a[x] == -1\n\t\t\t\tputs 'NO'\n\t\t\telse\n\t\t\t\tputs 'YES'\n\t\t\tend \n\t\tend\n\n\telse\n\t\tputs 'NO'\n\tend\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\nN = Integer gets.chomp\nnumbers = gets.chomp.split\nfor i in 0...N do\n\tnumbers[i] = Integer numbers[i]\nend\n\nX = 1000000\nflags = Array.new(X+1)\nfor i in 0..X do\n\tflags[i] = true\nend\nflags[0] = flags[1] = false\nfor i in 2..X do\n\tif flags[i]\n\t\tj = i * i\n\t\twhile (j <= X) do\n\t\t\tflags[j] = false\n\t\t\tj += i;\n\t\tend\n\tend\nend\n\nfor i in numbers do\n\tj = Integer Math.sqrt(i)\n\tif flags[j] and j * j == i\n\t\tprint \"YES\\n\"\n\telse\n\t\tprint \"NO\\n\"\n\tend\nend\n\n\n\n\n\n"}, {"source_code": "def generate_prime(n)\n\tprimes = (0..n).to_a\n\tprimes[0] = nil\n\tprimes[1] = nil\n\t(2..Math.sqrt(n)).each do |i|\n\t\tif primes[i]\n\t\t\t(i**2..n).step(i).each do |j|\n\t\t\t\tprimes[j] = nil\n\t\t\tend\n\t\tend\n\tend\t\n\tprimes.compact\nend\n\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n@primes = generate_prime(10 ** 6).map{|x| x *x}\ntrue_arr = @primes & arr\n\ntrue_hash = Hash[true_arr.map{|x| [x,true]}]\n#d puts \"#{true_hash}\"\nres = []\narr.each do |a|\n\tres << (true_hash[a] ? \"YES\" : \"NO\")\nend\n\nres.each do |i|\n\tputs i\nend"}, {"source_code": "def Eratosthenes2(n)\n\tl = Array 0..n\n\t\n\tl[0] = l[1] = nil\n\t\n\tfor i in (2..n ** (1.0 / 2))\n\t\tif l[i]\n\t\t\tj = i ** 2\n\t\t\twhile j <= n\n\t\t\t\tl[j] = nil\n\t\t\t\tj += i\n\t\t\tend\n\t\tend\n\tend\n\t\n\treturn l.compact.map { |x| x ** 2 }\nend\n\nl = Eratosthenes2(1000000)\n\nclass Array\n\tdef bs(x)\n\t\t\n\t\ts = 0\n\t\te = size - 1\n\t\t\n\t\twhile s <= e\n\t\t\tt = at((s + e) / 2)\n\t\t\t\n\t\t\tif x < t\n\t\t\t\te = (s + e) / 2 - 1\n\t\t\telsif x > t\n\t\t\t\ts = (s + e) / 2 + 1\n\t\t\telse\n\t\t\t\treturn t\n\t\t\tend\n\t\tend\n\t\t\n\t\treturn nil\n\tend\nend\n\ngets\ngets.split.each { |x| puts (l.bs(x.to_i) != nil) ? \"YES\" : \"NO\" }"}, {"source_code": "PRIME_LIMIT = Math.sqrt(10**12).to_i + 1\n@prime_numbers = Array.new(PRIME_LIMIT, true)\n\ndef sieve\n @prime_numbers[1] = false\n i = 2\n while i*i < PRIME_LIMIT do\n if @prime_numbers[i] != false\n j = 2 * i\n while j < PRIME_LIMIT do\n @prime_numbers[j] = false\n j += i\n end\n end\n i+= 1\n end\nend\n\nsieve()\n\ngets\ngets\nvalues = $_.split.map(&:to_i)\nvalues.each do |value|\n svalue = Math.sqrt(value).to_i\n if (svalue * svalue == value && @prime_numbers[svalue] == true && value != 1)\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = Array.new(1000000, true)\nc[1] = false\n2.upto(1000000) do |i|\n if c[i]\n (i + i).step(1000000, i){|j| c[j] = false}\n end\nend\na.each do |x|\n m = Math.sqrt(x)\n if m.ceil == m.to_i && c[m]\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "require 'set'\n\ntprimes = Set.new\nsieve = Array.new(1000001,true)\nsieve[0] = false\nsieve[1] = false\n(2..1000000).each do |p|\n next if sieve[p] == false\n i = p*p\n tprimes.add(i)\n while(i<=1000000)\n sieve[i] = false\n i += p\n end\nend\n\ngets.to_i\ngets.split(/\\s+/).each do |x|\n puts tprimes.member?(x.to_i) ? \"YES\" : \"NO\"\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = Array.new(1000000, true)\nc[1] = false\n2.upto(1000) do |i|\n if c[i]\n (i * i).step(1000000, i){|j| c[j] = false}\n end\nend\na.each do |x|\n m = Math.sqrt(x).round\n if m * m == x && c[m]\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "require 'set'\n\nc = Array.new(1_000_001, false)\nc[2] = true\np = [ 2 ]\n3.step(1_000_000, 2) do |i|\n next if c[i]\n\n p << i\n\n i.step(1_000_000, i) { |x| c[x] = true }\nend\n\ngets\na = gets.split(' ').map(&:to_i)\n\npp = Set.new p.map { |x| x*x }\n\na.each do |n|\n puts pp.include?(n) ? 'YES' : 'NO'\nend\n"}, {"source_code": "MAXP = 1e6.to_i\nis_prime = Array.new MAXP, true\nt_primes = {}\n(2...MAXP).each do |i|\n if is_prime[i] then\n t_primes[i * i] = 0\n ((i + i)...MAXP).step(i).each do |j|\n is_prime[j] = false\n end\n end\nend\nn = gets\nx = gets.split.map &:to_i\nx.each do |i|\n if t_primes.has_key? i then\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\nlimit = 10**6 + 1\nis_prime = {}\nsieve = Array.new(limit)\npos = 2\nwhile true\n\twhile pos != limit and sieve[pos]\n\t\tpos += 1\n\tend\n\tbreak if pos == limit\n\tseek = pos\n\twhile seek < limit\n\t\tsieve[seek] = true\n\t\tseek += pos\n\tend\n\tis_prime[pos] = true\nend\n\n\nn = STDIN.readline.to_i\narr = STDIN.readline.split.map {|s| s.to_i }\nlines = []\narr.each do |x|\n\ty = (x**0.5).floor\n\tif y*y == x and is_prime[y]\n\t\tlines.push('YES')\n\telse\n\t\tlines.push('NO')\n\tend\nend\nputs lines.join(\"\\n\")\n"}, {"source_code": "\ngets.to_i;\narr = gets.chomp.split(' ').map(&:to_i);\nprimes = Array.new(1000000, 1);\nprimes[1] = nil;\n(2..1000000).each do |i|\n if primes[i]\n (i**2).step(1000000, i) {|m| primes[m] = nil}\n end\nend\n\narr.each {|x|\n sq = Math.sqrt(x).to_i;\n puts (sq**2 == x && primes[sq] ? \"YES\" : \"NO\")\n}\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|i| i.to_f}\n\nL = []\n \n(1..1000000).each do |i|\n L[i] = 1\nend\nL[1] = 0\n\n(2..1000000).each do |i|\n kq = 2*i\n if L[i] == 1\n while kq <= 1000000 do\n L[kq] = 0\n kq += i\n end\n end\nend\n\n(0..n-1).each do |i|\n can = Math.sqrt(a[i])\n if can == can .ceil && L[can] == 1\n puts \"YES\"\n else \n puts \"NO\"\n end\nend"}, {"source_code": "require 'set'\n\nn = gets.to_i\n\nx = gets.split.map(&:to_i)\n\nN = 10 ** 6\nM = 10 ** 3\n\nsieve = Array.new(N+1,true)\n\nS = Set.new\n\n(2..N).each do |i|\n next if not sieve[i]\n S.add(i ** 2)\n m = 2 * i\n while m <= N\n sieve[m] = false\n m += i\n end\nend\n\nx.each{|e| S.member?(e) ? (puts 'YES') : (puts 'NO')}"}, {"source_code": "a=Array.new(1000000,0)\na[0]=1\nfor i in 2...1000000\n\tif a[i-1]==0\n\t\tj=2\n\t\twhile i*j<=1000000\n\t\t\ta[i*j-1]=1\n\t\t\tj+=1\n\t\tend\n\tend\nend\nt=gets.to_i\nar=gets.chomp.split.map(&:to_i)\nar.each do |i|\n\tj=Math.sqrt(i).to_i\n\tputs (a[j-1]==0 && j*j==i) ? \"YES\" : \"NO\"\nend\n\n"}, {"source_code": "def eratosthenes(top)\n sieve = []\n for i in 2 .. top\n sieve[i] = i\n end\n for i in 2 .. Math.sqrt(top)\n next unless sieve[i]\n (i*i).step(top, i) do |j|\n sieve[j] = nil\n end\n end\n sieve\nend\ne = eratosthenes(1_000_000)\ngets\ngets.split.map(&:to_i).each do |x|\n f = Math.sqrt(x)\n if f == f.round and !e[f].nil?\n puts :YES\n else\n puts :NO\n end\nend"}, {"source_code": "require 'set'\n\nn = gets.to_i\n\nx = gets.split.map(&:to_i)\n\nN = 10 ** 6\nM = 10 ** 3\n\nsieve = Array.new(N+1,true)\n\nS = Set.new\n\n(2..N).each do |i|\n next if not sieve[i]\n S.add(i ** 2)\n m = 2 * i\n while m <= N\n sieve[m] = false\n m += i\n end\nend\n\nx.each{|e| S.member?(e) ? (puts 'YES') : (puts 'NO')}"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map{|i| i.to_i}\nL = Array.new\n\n(1..1000000).each do |i|\n L[i] = 1\nend\n\nL[1] = 0\n\n(2..1000000).each do |i|\n kq = 2*i\n if L[i] == 1\n while kq <= 1000000 do\n L[kq] = 0\n kq += i\n end\n end\nend\n\na.each do |i|\n if Math.sqrt(i.to_f) == Math.sqrt(i.to_f).floor\n f = Math.sqrt(i.to_f).to_i\n if L[f] == 1\n puts 'YES'\n else\n puts 'NO'\n end\n else\n puts 'NO'\n end\nend"}], "negative_code": [{"source_code": "n = gets.to_i\nx = gets.split.map &:to_i\n\nmax = x.max\n\ndef sieve_numbers n\n sieve_array = Array.new(n + 1, true)\n sieve_array[0] = false\n sieve_array[1] = false\n\n for current_prime in 2 .. Math.sqrt(n).to_i\n next unless sieve_array[current_prime] \n i = 2\n while current_prime * i <= n\n sieve_array[current_prime * i] = false\n i += 1\n end\n end\n\n prime_numbers = []\n sieve_array.each_index do |index|\n prime_numbers << index if sieve_array[index]\n end\n return prime_numbers\nend\n\nprimes = sieve_numbers(Math.sqrt(max).ceil)\nsquared_primes = primes.map{|p| p * p}\n\nx.each do |test_case|\n if squared_primes.bsearch{|element| test_case - element}\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\n\n\n"}, {"source_code": "\ngets.to_i;\narr = gets.chomp.split(' ').map(&:to_i);\nprimes = Array.new(1000000, 1);\n(2..1000000).each do |i|\n if primes[i]\n (i**2).step(1000000, i) {|m| primes[m] = nil}\n end\nend\n\narr.each {|x|\n sq = Math.sqrt(x).to_i;\n puts (sq**2 == x && primes[sq] ? \"YES\" : \"NO\")\n}\n"}, {"source_code": "require 'prime'\n\ngets.to_i;\narr = gets.chomp.split(' ').map(&:to_i);\nprimes = Prime.each(100000).map {|x| [x, 1]};\nhash = Hash[*primes.flatten];\n\narr.each { |x|\n sq = Math.sqrt(x).to_i;\n if (sq*sq == x && hash[sq])\n puts \"YES\";\n else\n puts \"NO\";\n end\n}\n"}, {"source_code": "require 'mathn'\nn = gets.to_i\nn.times do\n f = Math.sqrt(gets.to_i)\n puts (f == f.round and f.prime?) ? :YES : :NO\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\n\nind = 0\nd = Array.new(100001,false)\nok = Array.new(100001)\n\nfor i in 2..1000001 do\n if (d[i] == false)\n ind += 1\n ok[ind] = i*i\n j = i+i\n begin\n d[j] = true\n j += i\n if (j > 100001) then break end\n end while true\n end \nend\n\nfor i in 0..n-1 do\n l = 0x0\n r = 0x0\n l = 1.to_i\n r = ind.to_i\n ans = false\n begin\n if (l>=r) then break end\n mid = (l+r) / 2\n if (ok[mid] > a[i]) then r = mid end\n if (ok[mid] < a[i]) then l = mid+1 end\n if (ok[mid] == a[i]) then ans = true end\n if (ans == true) then break end\n end while true\n if (ok[l] == a[i]) then ans = true end\n if (ans == true) then puts \"YES\"\n else puts \"NO\"\n end\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\n\nind = 0\nd = Array.new(1000001,false)\nok = Array.new(0)\n\nfor i in 2..1000001 do\n if (d[i] == false)\n ind += 1\n ok.push(i*i)\n j = i+i\n begin\n d[j] = true\n j += i\n if (j > 1000001) then break end\n end while true\n end \nend\n\nfor i in 0..n-1 do\n l = 0x0\n r = 0x0\n l = 1.to_i\n r = ind.to_i\n ans = false\n begin\n if (l>=r) then break end\n mid = (l+r) / 2\n if (ok[mid] > a[i]) then r = mid end\n if (ok[mid] < a[i]) then l = mid+1 end\n if (ok[mid] == a[i]) then ans = true end\n if (ans == true) then break end\n end while true\n if (ok[l] == a[i]) then ans = true end\n if (ans == true) then puts \"YES\"\n else puts \"NO\"\n end\nend"}, {"source_code": "a = Array.new(1000001,0) \na[1] = -1\ni = 3\nwhile i < 1000\n\tif a[i] == 0\n\t\tj = i+i\n\t\twhile j < 1000000\n\t\t\ta[j] = -1\n\t\t\tj += j\n\t\tend\n\tend\n\ti += 2\nend\nn = gets.to_i\ngets.split.map(&:to_i).each do |i|\n\tx = Math.sqrt(i)\n\tif x % 1 == 0\n\t\tif x % 2 == 0 and x != 2\n\t\t\tputs 'NO'\n\t\telse\n\t\t\tif a[x] == -1\n\t\t\t\tputs 'NO'\n\t\t\telse\n\t\t\t\tputs 'YES'\n\t\t\tend \n\t\tend\n\n\telse\n\t\tputs 'NO'\n\tend\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\nN = Integer gets.chomp\nnumbers = gets.chomp.split\nfor i in 0...N do\n\tnumbers[i] = Integer numbers[i]\nend\n\nX = 100000\nflags = Array.new(X+1)\nfor i in 0..X do\n\tflags[i] = true\nend\nflags[0] = flags[1] = false\nfor i in 2..X do\n\tif flags[i]\n\t\tj = i * i\n\t\twhile (j <= X) do\n\t\t\tflags[j] = false\n\t\t\tj += i;\n\t\tend\n\tend\nend\n\nfor i in numbers do\n\tj = Integer Math.sqrt(i)\n\tif flags[j] and j * j == i\n\t\tprint \"YES\\n\"\n\telse\n\t\tprint \"NO\\n\"\n\tend\nend\n\n\n\n\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nN = Integer gets.chomp\nnumbers = gets.chomp.split\nfor i in 0...N do\n\tnumbers[i] = Integer numbers[i]\nend\n\nX = 100000\nflags = Array.new(X+1)\nfor i in 0..X do\n\tflags[i] = true\nend\nflags[0] = flags[1] = false\nprimes = Array.new\nfor i in 2..X do\n\tif flags[i]\n\t\tprimes.push i\n\t\tj = i * i\n\t\twhile (j <= X) do\n\t\t\tflags[j] = false\n\t\t\tj += i;\n\t\tend\n\tend\nend\n\nfor i in numbers do\n\tis_prime = i != 1\n\tfor j in primes do\n\t\tif j * j > i\n\t\t\tbreak\n\t\tend\n\t\tif i % j == 0\n\t\t\tis_prime = false\n\t\t\tbreak\n\t\tend\n\tend\n\tif is_prime\n\t\tprint \"YES\\n\"\n\telse\n\t\tprint \"NO\\n\"\n\tend\nend\n\n\n\n\n\n"}, {"source_code": "def generate_prime(n)\n\tprimes = Hash.new(true)\n\tprimes[0] = false\n\tprimes[1] = false\n\t(2..Math.sqrt(n)).each do |i|\n\t\tif primes[i]\n\t\t\tprimes[i] = true\n\t\t\t(i**2..n).step(i).each do |j|\n\t\t\t\tprimes[j] = false\n\t\t\tend\n\t\tend\n\tend\t\n\tprimes.select {|k,v| v == true}.keys\nend\n\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n@primes = generate_prime(10**6)\narr.each do |a|\n\t# puts @primes.include?(Math.sqrt(a)) ? \"YES\" : \"NO\"\nend"}, {"source_code": "def Eratosthenes2(n)\n\tl = Array 0..n\n\t\n\tl[0] = l[1] = nil\n\t\n\tfor i in (2..n ** (1.0 / 2))\n\t\tif l[i]\n\t\t\tj = i ** 2\n\t\t\twhile j <= n\n\t\t\t\tl[j] = nil\n\t\t\t\tj += i\n\t\t\tend\n\t\tend\n\tend\n\t\n\treturn l.compact.map { |x| x ** 2 }\nend\n\nl = Eratosthenes2(1000000)\n\ngets\ngets.split.each { |x| puts (l[0] == x.to_i or l.bsearch { |y| y == x.to_i } != nil) ? \"YES\" : \"NO\" }"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = Array.new(10, true)\n2.upto(10) do |i|\n if c[i]\n i.step(10, i){|j| c[j] = false if j != i}\n end\nend\na.each do |x|\n m = Math.sqrt(x)\n if m.ceil == m.to_i && c[m]\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "require 'prime'\nn = gets.to_i\na = gets.split.map(&:to_i)\n\na.each do |x|\n m = x.prime_division\n if m.size == 1 && m[0][0] == m[0][1]\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "require 'prime'\nn = gets.to_i\na = gets.split.map(&:to_i)\n\na.each do |x|\n m = x.prime_division\n if m.size == 1 && m[0][0] != x\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = Array.new(10, true)\nc[1] = false\n2.upto(10) do |i|\n if c[i]\n i.step(10, i){|j| c[j] = false if j != i}\n end\nend\na.each do |x|\n m = Math.sqrt(x)\n if m.ceil == m.to_i && c[m]\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "require 'set'\n\ndef t_prime(x)\n result = false\n $p.each do |i|\n break if i > x\n if x.modulo(i).zero? && x.div(i) > 1 && result == false\n result = true\n elsif x.modulo(i).zero?\n return false\n end\n end\n result\nend\n\nc = Set.new [ 2 ]\n$p = [ 2 ]\ni = 1\nuntil i > 1_000_000\n i += 2\n \n next if c.include? i\n\n x = i\n until x > 1_000_000\n c << x\n x += i\n end\nend\n\ngets\na = gets.split(' ').map(&:to_i)\n\na.each do |n|\n puts t_prime(n) ? 'YES' : 'NO'\nend\n"}, {"source_code": "require 'set'\n\ndef t_prime(x)\n result = false\n $p.each do |i|\n break if i > x\n if x.modulo(i).zero? && x.div(i) > 1 && result == false\n result = true\n elsif x.modulo(i).zero?\n return false\n end\n end\n result\nend\n\nc = Set.new [ 2 ]\n$p = [ 2 ]\nc << 2\ni = 1\nuntil i > 1_000_000\n i += 2\n\n next if c.include? i\n\n $p << i\n\n x = i\n until x > 1_000_000\n c << x\n x += i\n end\nend\n\ngets\na = gets.split(' ').map(&:to_i)\n\na.each do |n|\n puts t_prime(n) ? 'YES' : 'NO'\nend\n"}, {"source_code": "n = gets.to_i\nb = gets.split(' ')\n\na = []\n\n(0..n-1).each do |i|\n a[i] = b[i].to_f\n if Math.sqrt(a[i]) == Math.sqrt(a[i]).ceil\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|i| i.to_f}\n\n(0..n-1).each do |i|\n dem = 0\n can = Math.sqrt(a[i])\n (2..can.floor).each do |j|\n dem +=1 if a[i]%j == 0\n end\n if can == can.floor\n if 2*dem + 1 == n \n puts \"YES\" \n else\n puts \"NO\"\n end\n else\n if 2*dem + 2 == n\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\nend"}, {"source_code": "n = gets.to_i\nb = gets.split(' ')\n\na = []\nkt = 1\n\n(0..n-1).each do |i|\n kt = 1\n a[i] = b[i].to_f\n can = Math.sqrt(a[i])\n if can == can.ceil\n (2..Math.sqrt(can).floor).each do |i|\n kt = 0 if can%i == 0\n end\n else kt = 0\n end\n if kt == 0 \n puts \"NO\"\n else\n puts \"YES\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|i| i.to_f}\n\n(0..n-1).each do |i|\n kt = 1\n if a[i] < 4\n puts \"NO\"\n else\n if a[i] == 4\n puts \"YES\"\n else\n can = Math.sqrt(a[i]).to_f\n if (can.ceil == can)\n (2..Math.sqrt(can).floor).each do |j|\n if can%j == 0\n puts \"NO\"\n kt = 0 \n end\n end\n if kt == 1\n puts \"YES\"\n end\n else \n puts \"NO\"\n end\n end\n end\nend"}, {"source_code": "n = gets.to_i\nb = gets.split(' ')\n\na = []\n\n(0..n-1).each do |i|\n a[i] = b[i].to_f\n dem = 0\n can = Math.sqrt(a[i])\n (2..can.floor).each do |j|\n dem +=1 if a[i]%j == 0\n end\n if can == can.floor\n if 2*dem + 1 == n \n puts \"YES\" \n else\n puts \"NO\"\n end\n else\n if 2*dem + 2 == n\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\nend"}, {"source_code": "n = gets.to_i\nb = gets.split(' ')\n\na = []\n\n(0..n-1).each do |i|\n kt = 0\n a[i] = b[i].to_f\n (2..Math.sqrt(a[i]).floor).each do |j|\n if (a[i]%j == 0)\n kq = a[i]/j\n while kq > 1 do\n if kq %j != 0 \n break\n else\n kq = kq/j\n end \n end\n kt = 1 if kq == 1\n break\n end\n end\n if kt == 0 \n puts \"NO\"\n else\n puts \"YES\"\n end\nend"}, {"source_code": "require 'set'\n\nn = gets.to_i\n\nx = gets.split.map(&:to_i)\n\nN = 10 ** 6\nM = 10 ** 3\n\nsieve = Array.new(N+1,true)\n\nS = Set.new\n\n(2..N).each do |i|\n next if not sieve[i]\n S.add(i ** 2)\n m = 2 * i\n while m < N\n sieve[m] = false\n m += i\n end\nend\n\nx.each{|e| S.member?(e) ? (puts 'YES') : (puts 'NO')}"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map{|i| i.to_i}\n\na.each do |i|\n if Math.sqrt(i.to_f) == Math.sqrt(i.to_f).floor && Math.sqrt(i.to_f).floor > 1\n f = Math.sqrt(i.to_f).to_i\n g = Math.sqrt(f).to_i\n puts 'YES'\n\n else\n puts 'NO'\n end\nend"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map{|i| i.to_i}\n\na.each do |i|\n\tif Math.sqrt(i.to_f) == Math.sqrt(i.to_f).floor && Math.sqrt(i.to_f).floor > 1\n\t\tf = Math.sqrt(i.to_f).to_i\n\t\tif f == 2 || f == 3\n\t\t\tputs 'YES'\n\t\telsif f > 3\n\t\t\tg = Math.sqrt(f)\n\t\t\tm = 0\n\t\t\t(2..g).each do |t|\n\t\t\t\tif f%t == 0\n\t\t\t\t\tputs 'NO'\n\t\t\t\t\tbreak \n\t\t\t\tend\n\t\t\t\tm = t\n\t\t\tend\n\t\t\tif m == g\n\t\t\t\tputs 'YES'\n\t\t\tend\n\t\tend\n\telse\n\t\tputs 'NO'\n\tend\nend"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map{|i| i.to_i}\n\na.each do |i|\n if Math.sqrt(i.to_f) == Math.sqrt(i.to_f).floor && Math.sqrt(i.to_f).floor > 1\n f = Math.sqrt(i.to_f).to_i\n if f == 2 || f == 3\n puts 'YES'\n elsif f > 3\n g = Math.sqrt(f).floor\n m = 0\n (2..g).each do |t|\n if f%g == 0\n puts 'NO'\n break \n end\n m = t\n end\n if m == g\n puts 'YES'\n end\n end\n else\n puts 'NO'\n end\nend"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map{|i| i.to_i}\n\na.each do |i|\n if Math.sqrt(i.to_f) == Math.sqrt(i.to_f).floor && Math.sqrt(i.to_f).floor > 1\n f = Math.sqrt(i.to_f).to_i\n if f == 2 || f == 3\n puts 'YES'\n elsif f > 3\n g = (f/2).floor\n m = 0\n (2..g).each do |t|\n if f%g == 0\n puts 'NO'\n break \n end\n m = t\n end\n if m == g\n puts 'YES'\n end\n end\n else\n puts 'NO'\n end\nend"}, {"source_code": "# require 'prime'\n\nn = gets.to_i\nf = gets.split.map { |x| x.to_i }\n\n# p = Prime.first(700000)\nis_prime = Array.new(1000001, true)\nis_prime[0] = false\n2.upto(1000001) do |i|\n\tif is_prime[i]\n\t\tj = i * 2\n\t\twhile j < 1000001\n\t\t\tis_prime[j] = false\n\t\t\tj += i\n\t\tend\n\tend\nend\n\nf.each do |x|\n\tt = (x ** 0.5).round\n\tif t ** 2 == x and is_prime[t]\n\t\tputs 'YES'\n\telse\n\t\tputs 'NO'\n\tend\nend\n"}], "src_uid": "6cebf9af5cfbb949f22e8b336bf07044"} {"source_code": "a=gets.chomp.to_i\nans=a*3\n0.upto(a-1) do |i|\nprint \"#{ans+i} \"\nend\n", "positive_code": [{"source_code": "puts (10**7-gets.to_i..10**7-1).to_a.join(' ')\n"}, {"source_code": "n = gets.to_i\nMAX = 1300000\nis_prime = Array.new(MAX + 1){true}\nis_prime[0] = false\nis_prime[1] = false\ni = 2\nwhile i * i <= MAX\n if is_prime[i]\n # puts i\n j = i * i\n while j < MAX + 1\n is_prime[j] = false\n j += i\n end\n end\n i += 1\nend\nres = []\nis_prime.each_with_index{|x, i| res << i if x}\nputs res[0...n].join(\" \")\n"}, {"source_code": "puts (10**7-gets.to_i..10**7-1).to_a\n"}, {"source_code": "n = gets.chomp.to_i\n\nputs ((10000000-(n-1))..(10000000)).to_a.join(' ')"}, {"source_code": "a=gets.chomp.to_i\nans=a*3\n0.upto(a-1) do |i|\nprint \"#{ans+i} \"\nend"}, {"source_code": "prime = Array.new(1300000, true)\n\nprime[0] = prime[1] = false\n2.upto(1300000) do |i|\n\tif prime[i]\n\t\tt = i * 2\n\t\twhile t < 1300000\n\t\t\tprime[t] = false\n\t\t\tt += i\n\t\tend\n\tend\nend\n\nans = []\nn = gets.to_i\n2.upto(1300000) do |i|\n\tif prime[i]\n\t\tif n > 0\n\t\t\tn -= 1\n\t\t\tans << i\n\t\tend\n\tend\nend\n\nputs ans.join ' '"}, {"source_code": "n = Integer(gets)\n\n\n\nb = Array.new\nb[0] = 2\nb[1] = 3\nfor i in 0...10000\n c = 0\n for j in 0...b.length\n if (i + 2)% b[j] != 0\n c = 1\n else \n c = 0\n break\n end\n end\n if c == 1\n b.push(i + 2)\n end\nend\nc = Array.new\n\nfor i in 0...b.length\n for j in i...b.length\n c.push(b[i]*b[j])\n \n if c.length >= n\n break\n end\n end\n if c.length >= n\n break\n end\nend\nc = c.sort\nputs c"}, {"source_code": "n = Integer(gets)\n\n\n\nb = Array.new\nb[0] = 2\nb[1] = 3\nfor i in 0...10000\n c = 0\n for j in 0...b.length\n if (i + 2)% b[j] != 0\n c = 1\n else \n c = 0\n break\n end\n end\n if c == 1\n b.push(i + 2)\n end\nend\nc = Array.new\n\nfor i in 0...b.length\n for j in i...b.length\n c.push(b[i]*b[j])\n \n if c.length >= n\n break\n end\n end\nend\nc = c.sort\nfor i in 0...n\n puts c[i]\nend"}, {"source_code": "gets\nfor i in 700000...(700000 + $_.to_i)\n print \"#{i} \"\nend\n"}, {"source_code": "n = gets.to_i\nputs \"#{(5*1000000 .. 5*1000000+n-1).to_a.join(' ')}\"\n"}, {"source_code": "n = gets.strip.to_i\na = []\nn.times do |i|\n a << (10000000 - n + i)\nend\nputs a.join(\" \")"}, {"source_code": "def eratosthenes(n)\n nums = [true, false, true] * ((n + 5) / 6)\n nums[0] = false\n nums[1] = true\n\n i = 5\n until(m = i * i\n m > n) do\n if nums[i >> 1]\n i_times_2 = i << 1\n i_times_4 = i << 2\n while m <= n\n nums[m >> 1] = false\n m += i_times_2\n nums[m >> 1] = false\n m += i_times_4\n end\n end\n i += 2\n if nums[i >> 1]\n m = i * i\n i_times_2 = i << 1\n i_times_4 = i << 2\n while m <= n\n nums[m >> 1] = false\n m += i_times_4\n nums[m >> 1] = false\n m += i_times_2\n end\n end\n i += 4\n end\n\n primes = [2]\n nums.each_index {|i| primes << (i * 2 + 1) if nums[i]}\n primes.pop while primes.last > n\n return primes\nend\n\nputs eratosthenes(1299722)[0..gets.to_i-1].join(' ')"}], "negative_code": [{"source_code": "n = Integer(gets)\n\n\n\nb = Array.new\nb[0] = 2\nb[1] = 3\nfor i in 0...4*n\n c = 0\n for j in 0...b.length\n if (i + 2)% b[j] != 0\n c = 1\n else \n c = 0\n break\n end\n end\n if c == 1\n b.push(i + 2)\n end\nend\nfor i in 0...n\n print b[i], \" \"\nend"}, {"source_code": "n = Integer(gets)\n\n\n\nb = Array.new\nb[0] = 2\nb[1] = 3\nfor i in 0...2*n\n c = 0\n for j in 0...b.length\n if (i + 2)% b[j] != 0\n c = 1\n else \n c = 0\n break\n end\n end\n if c == 1\n b.push(i + 2)\n end\nend\nfor i in 0...n\n print b[i], \" \"\nend"}, {"source_code": "n = Integer(gets)\n\n\n\nb = Array.new\nb[0] = 2\nb[1] = 3\nfor i in 0...n + 1000\n c = 0\n for j in 0...b.length\n if (i + 2)% b[j] != 0\n c = 1\n else \n c = 0\n break\n end\n end\n if c == 1\n b.push(i + 2)\n end\nend\nfor i in 0...n\n print b[i], \" \"\nend"}, {"source_code": "n = Integer(gets)\n\n\n\nb = Array.new\nb[0] = 2\nb[1] = 3\nfor i in 0...10000\n c = 0\n for j in 0...b.length\n if (i + 2)% b[j] != 0\n c = 1\n else \n c = 0\n break\n end\n end\n if c == 1\n b.push(i + 2)\n end\nend\nc = Array.new\n\nfor i in 0...b.length\n for j in i...b.length\n c.push(b[i]*b[j])\n \n if c.length >= n\n break\n end\n end\nend\nfor i in 0...n\n puts c[i]\nend"}, {"source_code": "n = Integer(gets)\n\n\n\nb = Array.new\nb[0] = 2\nb[1] = 3\nfor i in 0...n + 100\n c = 0\n for j in 0...b.length\n if (i + 2)% b[j] != 0\n c = 1\n else \n c = 0\n break\n end\n end\n if c == 1\n b.push(i + 2)\n end\nend\nfor i in 0...n\n print b[i], \" \"\nend"}, {"source_code": "n = Integer(gets)\n\n\n\nb = Array.new\nb[0] = 2\nb[1] = 3\nfor i in 0...6*n\n c = 0\n for j in 0...b.length\n if (i + 2)% b[j] != 0\n c = 1\n else \n c = 0\n break\n end\n end\n if c == 1\n b.push(i + 2)\n end\nend\nfor i in 0...n\n print b[i], \" \"\nend"}, {"source_code": "n = Integer(gets)\n\n\n\nb = Array.new\nb[0] = 2\nb[1] = 3\nfor i in 0...10000\n c = 0\n for j in 0...b.length\n if (i + 2)% b[j] != 0\n c = 1\n else \n c = 0\n break\n end\n end\n if c == 1\n b.push(i + 2)\n end\nend\nc = Array.new\n\nfor i in 0...b.length\n for j in i...b.length\n c.push(b[i]*b[j])\n \n if c.length >= n\n break\n end\n end\n if c.length >= n\n break\n end\nend\n\nputs c"}, {"source_code": "n = Integer(gets)\n\n\n\nb = Array.new\nb[0] = 2\nb[1] = 3\nfor i in 0...10000\n c = 0\n for j in 0...b.length\n if (i + 2)% b[j] != 0\n c = 1\n else \n c = 0\n break\n end\n end\n if c == 1\n b.push(i + 2)\n end\nend\nc = Array.new\n\nfor i in 0...b.length\n for j in 0...b.length\n c.push(b[i]*b[j])\n \n if c.length >= n\n break\n end\n end\nend\nfor i in 0...n\n puts c[i]\nend"}], "src_uid": "c047040426e736e9085395ed9666135f"} {"source_code": "n = gets.to_i\narr = []\n(0..n * 2 - 3).each do |i|\n arr.push([gets.chop, i])\nend\nbrr = arr.sort_by{ |t| t.first.length }\nc1 = brr[-1].first + brr[-2].first[-1]\nc2 = brr[-2].first + brr[-1].first[-1]\n\ndef isPrefix(s, pr)\n s[0 .. pr.length - 1] == pr\nend\n\ndef isSuffix(s, sf)\n s[-sf.length .. -1] == sf\nend\n\nres1 = \"_\" * (n * 2 - 2)\nres2 = res1.dup\n\nbrr.each_slice(2) do |f, s|\n s1, n1 = f\n s2, n2 = s\n res1[n1], res1[n2] = \"P\", \"S\" if isPrefix(c1, s1) && isSuffix(c1, s2)\n res1[n1], res1[n2] = \"S\", \"P\" if isSuffix(c1, s1) && isPrefix(c1, s2)\n res2[n1], res2[n2] = \"P\", \"S\" if isPrefix(c2, s1) && isSuffix(c2, s2)\n res2[n1], res2[n2] = \"S\", \"P\" if isSuffix(c2, s1) && isPrefix(c2, s2)\nend\n\nif !res1.include? \"_\" then puts res1 else puts res2 end", "positive_code": [{"source_code": "n = gets.to_i\nstr = []\n(2*n-2).times do |i|\n str << [gets.chomp,i]\nend\n\nstr.sort_by!{|s| s[0].length}\n\na,b,c,d = str[0][0],str[1][0],str[-1][0],str[-2][0]\nguess = [a+c,a+d,b+c,b+d]\n\n#p guess\nstr.each do |a|\n s = a[0]\n len = s.length\n guess.each do |t|\n guess.delete(t) if t[0,len] != s && t[n-len,len] != s\n end\n #p guess\nend\n\norigin = guess[0]\n\n(n-1).times do |i|\n a,b = str[2*i][0],str[2*i+1][0]\n len = a.length\n\n #p [a,b,flg]\n if a == origin[0,len]\n str[2*i] << \"P\"\n str[2*i+1] << \"S\"\n else\n str[2*i] << \"S\"\n str[2*i+1] << \"P\"\n end\nend\n#p guess\n\nstr.sort_by!{|s| s[1]}\nstr.each do |a|\n print \"#{a[2]}\"\nend\n"}, {"source_code": "n = gets.to_i\ns = (2*n-2).times.map{|i|[gets.chomp,i]}.sort_by{|str,i|str.size}\nret = Array.new(2*n-2,0)\nans = s[-2][0]+s[-1][0][-1]\nf = true\nfor i in 0..n-2\n if ans[0..i] == s[i*2][0] && ans[-1-i..-1] == s[i*2+1][0]\n ret[s[i*2+1][1]] = 1\n elsif ans[0..i] == s[i*2+1][0] && ans[-1-i..-1] == s[i*2][0]\n ret[s[i*2][1]] = 1\n else\n f = false\n break\n end\nend\n\nif !f\n ans = s[-1][0]+s[-2][0][-1]\n ret = Array.new(2*n-2,0)\n for i in 0..n-2\n if ans[0..i] == s[i*2][0] && ans[-1-i..-1] == s[i*2+1][0]\n ret[s[i*2+1][1]] = 1\n else\n ret[s[i*2][1]] = 1\n end\n end\nend\n\nfor i in 0..2*n-3\n print ret[i] == 0 ? \"P\" : \"S\"\nend"}, {"source_code": "# Utility\nclass StringBuilder\n def initialize(chunks)\n chunks_sorted = chunks.map.with_index { |chunk, i| {i: i, str: chunk} }\n .sort { |a, b| a[:str].length <=> b[:str].length }\n @pairs = Array.new(chunks_sorted.length / 2) { |i| [chunks_sorted[2 * i], chunks_sorted[2 * i + 1]] }\n\n @string = build\n\n @solution = \"S\" * chunks.length\n @pairs.each do |p|\n if @string.start_with? p[0][:str]\n @solution[p[0][:i]] = \"P\"\n else\n @solution[p[1][:i]] = \"P\"\n end\n end\n end\n\n attr_reader :string\n attr_reader :solution\n\n private\n def build\n str_1 = @pairs[-1][0][:str] + @pairs[-1][1][:str][-1]\n str_2 = @pairs[-1][1][:str] + @pairs[-1][0][:str][-1]\n return str_1 if correct? str_1\n return str_2 if correct? str_2\n end\n\n def correct?(str)\n (str.length - 1).times do |i|\n a = (str.start_with? @pairs[i][0][:str]) && (str.end_with? @pairs[i][1][:str])\n b = (str.start_with? @pairs[i][1][:str]) && (str.end_with? @pairs[i][0][:str])\n break false unless a || b\n end\n end\nend\n\n# Input\nn = gets.to_i # 2 <= n <= 100\nchunks = Array.new(2 * n - 2) { |i| gets.chop }\n\n# Result\nresult = StringBuilder.new(chunks)\n#puts result.string\nputs result.solution\n"}], "negative_code": [{"source_code": "n = gets.to_i\nstr = []\n(2*n-2).times do |i|\n str << [gets.chomp,i]\nend\n\nstr.sort_by!{|s| s[0].length}\nguess = \" \"*n\n\n((n-1)/2).times do |i|\n a,b,c,d = str[2*i][0],str[2*i+1][0],str[-2*i-1][0],str[-2*i-2][0]\n (i+1).times do |j|\n if a[j] == b[j] \n guess[j] = a[j]\n guess[n-i-1+j] = a[j]\n end\n end\n (n-i-1).times do |j|\n if c[j] == d[j]\n guess[j] = c[j]\n guess[i+j+1] = c[j]\n end\n end\n #p guess\nend\n\n(n-1).times do |i|\n a,b = str[2*i][0],str[2*i+1][0]\n flg1,flg2 = true,true\n (i+1).times do |j|\n flg1 = false if guess[j] != \" \" && guess[j] != a[j]\n flg2 = false if guess[j] != \" \" && guess[j] != b[j]\n end\n if flg1 && !flg2\n guess[0,i+1] = a\n guess[n-i-1,i+1] = b\n elsif !flg1 && flg2\n guess[0,i+1] = b\n guess[n-i-1,i+1] = a\n end\nend\n#p guess\n\n(n-1).times do |i|\n a,b = str[2*i][0],str[2*i+1][0]\n flg = true\n (i+1).times do |j|\n flg = false if guess[j] != \" \" && guess[j] != a[j]\n end\n #p [a,b,flg]\n if flg\n str[2*i] << \"P\"\n str[2*i+1] << \"S\"\n else\n str[2*i] << \"S\"\n str[2*i+1] << \"P\"\n end\nend\n#p guess\n\nstr.sort_by!{|s| s[1]}\nstr.each do |a|\n print \"#{a[2]}\"\nend\n"}, {"source_code": "# Utility\nclass StringBuilder\n def initialize(chunks)\n chunks_sorted = chunks.map.with_index { |chunk, i| {i: i, str: chunk} }\n .sort { |a, b| a[:str].length <=> b[:str].length }\n @pairs = Array.new(chunks_sorted.length / 2) { |i| [chunks_sorted[2 * i], chunks_sorted[2 * i + 1]] }\n\n @string = build\n\n @solution = \"S\" * chunks.length\n @pairs.each do |p|\n if @string.start_with? p[0][:str]\n @solution[p[0][:i]] = \"P\"\n else\n @solution[p[1][:i]] = \"P\"\n end\n end\n end\n\n attr_reader :string\n attr_reader :solution\n\n private\n def build\n str_1 = @pairs[-1][0][:str] + @pairs[-1][1][:str][-1]\n str_2 = @pairs[-1][1][:str] + @pairs[-1][0][:str][-1]\n return str_1 if correct? str_1\n return str_2 if correct? str_2\n end\n\n def correct?(str)\n (str.length - 1).times do |i|\n break false unless @pairs[i].find { |e| str.start_with? e[:str] }\n end\n end\nend\n\n# Input\nn = gets.to_i # 2 <= n <= 100\nchunks = Array.new(2 * n - 2) { |i| gets.chop }\n\n# Result\nresult = StringBuilder.new(chunks)\n#puts result.string\nputs result.solution\n"}, {"source_code": "# Utility\nclass StringBuilder\n def initialize(chunks)\n chunks_sorted = chunks.map.with_index { |chunk, i| {i: i, str: chunk} }\n .sort { |a, b| a[:str].length <=> b[:str].length }\n pairs = Array.new(chunks_sorted.length / 2) { |i| [chunks_sorted[2 * i], chunks_sorted[2 * i + 1]].sort! { |a, b| a[:str] <=> b[:str] } }\n # Beacuse of sorting inside pairs\n #p pairs\n\n str_1 = pairs[-1][0][:str]\n str_2 = pairs[-1][1][:str]\n if str_1 + str_2[-1] == str_1[0] + str_2\n # str_1 is prefix\n @string = str_1 + str_2[-1]\n else\n # str_2 is prefix\n @string = str_2 + str_1[-1]\n end\n\n @solution = \"S\" * chunks.length\n pairs.each do |p|\n if @string.start_with? p[0][:str]\n @solution[p[0][:i]] = \"P\"\n else\n @solution[p[1][:i]] = \"P\"\n end\n end\n end\n\n attr_reader :string\n attr_reader :solution\nend\n\n# Input\nn = gets.to_i # 2 <= n <= 100\nchunks = Array.new(2 * n - 2) { |i| gets.chop }\n\n# Result\nresult = StringBuilder.new(chunks)\nputs result.string\nputs result.solution\n"}, {"source_code": "# Utility\nclass StringBuilder\n def initialize(chunks)\n @n = 1 + chunks.length / 2\n chunks_sorted = chunks.sort { |a, b| a[:str].length <=> b[:str].length }\n pairs = Array.new(chunks_sorted.length / 2) { |i| [chunks_sorted[2 * i], chunks_sorted[2 * i + 1]] }\n\n builder(pairs)\n end\n\n attr_reader :string\n attr_reader :solution\n\n private\n def builder(pairs, str = nil, prefix_indexes = [], last_char = nil)\n # Building from prefixes\n unless str\n # First call\n str = \"\"\n end\n\n if pairs.length == 0\n # Last call\n @string = str + last_char\n @solution = \"S\" * (2 * @n - 2)\n prefix_indexes.each { |i| @solution[i] = \"P\" }\n return @string\n end\n\n pair = pairs.shift\n str_ext = nil # Next string\n 2.times do |i|\n next unless pair[i][:str].start_with?(str)\n #puts \"#{str} => #{pair[i][:str]}\"\n str_ext = builder(pairs, pair[i][:str], prefix_indexes + [pair[i][:i]], last_char || pair[1 - i][:str])\n break if str_ext # Built successfully\n #puts \"X\"\n end\n\n return str_ext\n end\nend\n\n# Input\nn = gets.to_i # 2 <= n <= 100\nchunks = Array.new(2 * n - 2) { |i| {i: i, str: gets.chop} }\n\n# Result\nresult = StringBuilder.new(chunks)\n#puts result.string\nputs result.solution\n"}, {"source_code": "# Utility\nclass StringBuilder\n def initialize(chunks)\n chunks_sorted = chunks.map.with_index { |chunk, i| {i: i, str: chunk} }\n .sort { |a, b| a[:str].length <=> b[:str].length }\n pairs = Array.new(chunks_sorted.length / 2) { |i| [chunks_sorted[2 * i], chunks_sorted[2 * i + 1]].sort! { |a, b| a[:str] <=> b[:str] } }\n # Beacuse of sorting inside pairs\n #p pairs\n\n str_1 = pairs[-1][0][:str]\n str_2 = pairs[-1][1][:str]\n if str_1 + str_2[-1] == str_1[0] + str_2\n # str_1 is prefix\n @string = str_1 + str_2[-1]\n else\n # str_2 is prefix\n @string = str_2 + str_1[-1]\n end\n\n @solution = \"S\" * chunks.length\n pairs.each do |p|\n if @string.start_with? p[0][:str]\n @solution[p[0][:i]] = \"P\"\n else\n @solution[p[1][:i]] = \"P\"\n end\n end\n end\n\n attr_reader :string\n attr_reader :solution\nend\n\n# Input\nn = gets.to_i # 2 <= n <= 100\nchunks = Array.new(2 * n - 2) { |i| gets.chop }\n\n# Result\nresult = StringBuilder.new(chunks)\n#puts result.string\nputs result.solution\n"}], "src_uid": "ddbde202d00b928a858e9f4ff461e88c"} {"source_code": "#!/usr/bin/env ruby\n\nevents_no = gets \nevents_seq = gets \n\n\noutput = Array.new(10, 0)\n\n\nevents_seq.delete!(\"\\n\").split('').each { |c|\n\n\tif c == 'L'\n\t\toutput[output.find_index(0)]=1\n elsif c == 'R'\n\t\toutput[output.rindex(0)]=1\n\n\telse\n\t\toutput[c.to_i] = 0\n\tend\n\n\n\t\n}\n\nputs output.join('')\n\n\n\n", "positive_code": [{"source_code": "def test\n ind_l = 0\n ind_r = 0\n \ninput = $stdin.read\ninput = input.split(\"\\n\")\n length = input[0].to_i\n str = input[1].chars\n\n out = [0,0,0,0,0,0,0,0,0,0]\n for i in str\n if i == 'L'\n \n ind_l = out.index(0)\n out[ind_l] = 1\n ind_l = ind_l +1 ; \n elsif i == 'R'\n \n out_rev=out.reverse\n ind_r=out_rev.index(0)\n out[9-ind_r] = 1\n ind_r = ind_r +1 ; \n else\n \n out[i.to_i] = 0\n end\n \n end\n puts out.join()\nend \ntest\n"}, {"source_code": "def find_zero_index_from_left(array)\n found_index = nil\n array.each_with_index do |element, index|\n if element.eql?(0)\n found_index = index\n break\n end\n end\n found_index\nend\n\ndef find_zero_index_from_right(array)\n found_index = nil\n (array.size - 1).downto(0).each do |index|\n if array[index].eql?(0)\n found_index = index\n break\n end\n end\n found_index\nend\n\n_ = gets.strip.to_i\narrives_code = gets.strip.split('')\n\ncodes = Array.new(10, 0)\n\narrives_code.each do |code|\n if code.eql?('L')\n index = find_zero_index_from_left(codes)\n codes[index] = 1\n elsif code.eql?('R')\n index = find_zero_index_from_right(codes)\n codes[index] = 1\n else\n index = code.to_i\n codes[index] = 0\n end\nend\n\nputs codes.join('')\n"}, {"source_code": "def change_room_status_for(event_char, rooms_status)\n\n if event_char == \"L\"\n empty_room = rooms_status.index(\"0\")\n rooms_status[empty_room] = \"1\"\n elsif event_char == \"R\"\n empty_room = rooms_status.rindex(\"0\")\n rooms_status[empty_room] = \"1\"\n else\n checked_out_room = event_char.to_i\n rooms_status[checked_out_room] = \"0\"\n end\n\nend\n\nnum_of_events_in_amugae_memory = gets.chomp.to_i\n\nevents = gets.chomp\nrooms_status = '0' * 10\n\nevents.each_char { |event| change_room_status_for(event, rooms_status) }\n\nputs rooms_status"}, {"source_code": "def change_room_status_for(event_char, rooms_status)\n if event_char == \"L\"\n room_idx = closest_empty_room_from_left(rooms_status)\n rooms_status[room_idx] = \"1\"\n elsif event_char == \"R\"\n room_idx = closest_empty_room_from_right(rooms_status)\n rooms_status[room_idx] = \"1\"\n else\n leaving_customer_idx = event_char.to_i\n rooms_status[leaving_customer_idx] = \"0\"\n end\nend\n\ndef closest_empty_room_from_left(rooms_status)\n rooms_status.index(\"0\")\nend\n\ndef closest_empty_room_from_right(rooms_status)\n idx = rooms_status.length - 1\n\n while idx >= 0\n if rooms_status[idx] == \"0\"\n return idx\n end\n\n idx -= 1\n end\nend\n\nnum_of_events_in_amugae_memory = gets.chomp.to_i\n\nevents = gets.chomp\nrooms_status = '0' * 10\n\nevents.each_char { |event| change_room_status_for(event, rooms_status) }\n\nputs rooms_status"}, {"source_code": "a=Array.new(10,0)\nn=gets().to_i\ns=gets()\nfor i in 0...n do\n if s[i]==\"L\" then\n a[a.index(0)]=1\n elsif s[i]==\"R\" then\n a[a.rindex(0)]=1\n else\n a[(s[i]).to_i]=0\n end\nend\nfor i in 0..9 do\n print a[i]\nend"}, {"source_code": "\nn = gets.to_i\nstr = gets.chomp\nans = '0'*10\nstr.each_char do |x|\n\tif x == 'L'\n\t\tans[ans.index('0')] = '1'\n\telsif x == 'R'\n\t\tans[ans.rindex('0')] = '1'\n\telse\n\t\tans[x.to_i] = '0'\n\tend\nend\nputs ans\n"}], "negative_code": [{"source_code": "def find_zero_index_from_left(array)\n found_index = nil\n array.each_with_index do |element, index|\n if element.eql?(0)\n found_index = index\n break\n end\n end\n found_index\nend\n\ndef find_zero_index_from_right(array)\n found_index = nil\n (array.size - 1).downto(0).each do |index|\n if array[index].eql?(0)\n found_index = index\n break\n end\n end\n found_index\nend\n\n_ = gets.strip.to_i\narrives_code = gets.strip.split('')\n\ncodes = Array.new(10, 0)\n\narrives_code.each do |code|\n if code.eql?('L')\n index = find_zero_index_from_left(codes)\n codes[index] = 1\n elsif code.eql?('R')\n index = find_zero_index_from_right(codes)\n codes[index] = 1\n else\n index = code.to_i\n codes[index] = 0\n end\nend\n\np codes\n"}, {"source_code": "\n\ndef test\n ind_l = 0\n ind_r = 0\n $/ = \"1\" \ninput = STDIN.gets\ninput = input.split(\"\\n\")\n length = input[0].to_i\n str = input[1].to_s.chars\n \n out = [0,0,0,0,0,0,0,0,0,0]\n for i in str\n if i == 'L'\n \n ind_l = out.index(0)\n out[ind_l] = 1\n ind_l = ind_l +1 ; \n elsif i == 'R'\n \n out_rev=out.reverse\n ind_r=out_rev.index(0)\n out[9-ind_r] = 1\n ind_r = ind_r +1 ; \n else\n \n out[i.to_i] = 0\n end\n \n end\n return out\nend \ntest"}, {"source_code": "def test\n ind_l = 0\n ind_r = 0\n $/ = \"1\" \ninput = STDIN.gets\ninput = input.split(\"\\n\")\n length = input[0].to_i\n str = input[1].to_s.chars\n \n out = [0,0,0,0,0,0,0,0,0,0]\n for i in str\n if i == 'L'\n \n ind_l = out.index(0)\n out[ind_l] = 1\n ind_l = ind_l +1 ; \n elsif i == 'R'\n \n out_rev=out.reverse\n ind_r=out_rev.index(0)\n out[9-ind_r] = 1\n ind_r = ind_r +1 ; \n else\n \n out[i.to_i] = 0\n end\n \n end\n puts out.to_s\nend \ntest"}, {"source_code": "def test\n ind_l = 0\n ind_r = 0\n $/ = \"1\" \ninput = STDIN.gets\ninput = input.split(\"\\n\")\n length = input[0].to_i\n str = input[1].to_s.chars\n \n out = [0,0,0,0,0,0,0,0,0,0]\n for i in str\n if i == 'L'\n \n ind_l = out.index(0)\n out[ind_l] = 1\n ind_l = ind_l +1 ; \n elsif i == 'R'\n \n out_rev=out.reverse\n ind_r=out_rev.index(0)\n out[9-ind_r] = 1\n ind_r = ind_r +1 ; \n else\n \n out[i.to_i] = 0\n end\n \n end\n puts \"#{out}\"\nend \ntest"}, {"source_code": "def test\n ind_l = 0\n ind_r = 0\n $/ = \"1\" \ninput = STDIN.gets\ninput = input.split(\"\\n\")\n length = input[0].to_i\n str = input[1].to_s.chars\n \n out = [0,0,0,0,0,0,0,0,0,0]\n for i in str\n if i == 'L'\n \n ind_l = out.index(0)\n out[ind_l] = 1\n ind_l = ind_l +1 ; \n elsif i == 'R'\n \n out_rev=out.reverse\n ind_r=out_rev.index(0)\n out[9-ind_r] = 1\n ind_r = ind_r +1 ; \n else\n \n out[i.to_i] = 0\n end\n \n end\n puts out.join()\nend \ntest"}, {"source_code": "def test\n ind_l = 0\n ind_r = 0\n\ninput = $stdin.read\ninput = input.split(\"\\n\")\n length = input[0].to_i\n str = input[1].chars\n puts length\n puts str\n out = [0,0,0,0,0,0,0,0,0,0]\n for i in str\n if i == 'L'\n \n ind_l = out.index(0)\n out[ind_l] = 1\n ind_l = ind_l +1 ; \n elsif i == 'R'\n \n out_rev=out.reverse\n ind_r=out_rev.index(0)\n out[9-ind_r] = 1\n ind_r = ind_r +1 ; \n else\n \n out[i.to_i] = 0\n end\n \n end\n puts out.join()\nend \ntest"}, {"source_code": "def test\n ind_l = 0\n ind_r = 0\ninput = $stdin.read\ninput = input.split(\"\\n\")\n length = input[0].to_i\n str = input[1].to_s.chars\n \n out = [0,0,0,0,0,0,0,0,0,0]\n for i in str\n if i == 'L'\n \n ind_l = out.index(0)\n out[ind_l] = 1\n ind_l = ind_l +1 ; \n elsif i == 'R'\n \n out_rev=out.reverse\n ind_r=out_rev.index(0)\n out[9-ind_r] = 1\n ind_r = ind_r +1 ; \n else\n \n out[i.to_i] = 0\n end\n \n end\n return out\nend \ntest"}, {"source_code": "def first input\n puts input\nend "}, {"source_code": "def test\n ind_l = 0\n ind_r = 0\ninput = $stdin.read\ninput = input.split(\"\\n\")\n length = input[0].to_i\n str = input[1].to_s.chars\n \n out = [0,0,0,0,0,0,0,0,0,0]\n for i in str\n if i == 'L'\n puts 'L' \n ind_l = out.index(0)\n out[ind_l] = 1\n ind_l = ind_l +1 ; \n elsif i == 'R'\n puts 'R'\n out_rev=out.reverse\n ind_r=out_rev.index(0)\n out[9-ind_r] = 1\n ind_r = ind_r +1 ; \n else\n puts 'ji'\n out[i.to_i] = 0\n end\n puts \"#{out}\"\n end\n return out\nend "}, {"source_code": "def test\n ind_l = 0\n ind_r = 0\n $/ = \"1\" \ninput = STDIN.gets\ninput = input.split(\"\\n\")\n length = input[0].to_i\n str = input[1].to_s.chars\n \n out = [0,0,0,0,0,0,0,0,0,0]\n for i in str\n if i == 'L'\n \n ind_l = out.index(0)\n out[ind_l] = 1\n ind_l = ind_l +1 ; \n elsif i == 'R'\n \n out_rev=out.reverse\n ind_r=out_rev.index(0)\n out[9-ind_r] = 1\n ind_r = ind_r +1 ; \n else\n \n out[i.to_i] = 0\n end\n \n end\n puts out\nend \ntest"}], "src_uid": "a6cbf01d72d607ca95fe16df4fb16693"} {"source_code": "gets.to_i.times do\r\n aa,bb,k=gets.split.map(&:to_i)\r\n a=gets.split.map(&:to_i).sort\r\n b=gets.split.map(&:to_i).sort\r\n c=0\r\n q=0\r\n cc=0\r\n a.each do |ai|\r\n if ai==q\r\n cc+=1\r\n else\r\n c+=cc*(cc-1)/2\r\n cc=1\r\n q=ai\r\n end\r\n end\r\n c+=cc*(cc-1)/2\r\n q=0\r\n cc=0\r\n b.each do |ai|\r\n if ai==q\r\n cc+=1\r\n else\r\n c+=cc*(cc-1)/2\r\n cc=1\r\n q=ai\r\n end\r\n end\r\n c+=cc*(cc-1)/2\r\n puts k*(k-1)/2-c\r\nend\r\n", "positive_code": [{"source_code": "tcases = gets.chomp.to_i\r\ndef solve()\r\n a, b, k = *(gets.chomp.split.map(&:to_i))\r\n boys = gets.chomp.split.map(&:to_i)\r\n girls = gets.chomp.split.map(&:to_i)\r\n boy_out = Array.new(a + 1, 0)\r\n girls_in = Array.new(b + 1, 0)\r\n boys.each do |i|\r\n boy_out[i] += 1\r\n end\r\n girls.each do |i|\r\n girls_in[i] += 1\r\n end\r\n # puts \"boy_out = #{boy_out.join(\" \")}\"\r\n # puts \"girls_out = #{girls_in.join(\" \")}\"\r\n ans = 0\r\n 0.upto k-1 do |i|\r\n b, g = boys[i], girls[i]\r\n bout, gin = boy_out[b], girls_in[g]\r\n ans += k - (bout + gin - 1)\r\n end\r\n # puts \"ans = \"\r\n puts ans / 2\r\nend\r\ntcases.times do solve() end\r\n"}], "negative_code": [], "src_uid": "14ce451a31c0dbc2b2f4e04a939b199d"} {"source_code": "\ndef solution\n\n _, m, k = read_ints\n objects = read_ints.reverse\n\n used_boxes = 1\n crt_size = k\n packed = 0\n\n for o in objects\n if o <= crt_size\n packed += 1\n crt_size -= o\n else\n if used_boxes < m\n used_boxes += 1\n packed += 1\n crt_size = k - o\n else\n break\n end\n end\n end\n\n puts packed\n\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n", "positive_code": [{"source_code": "n,m,k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = 0\n\ncap = k\nm -= 1\n(n-1).downto(0) do |i|\n if a[i] <= cap\n cap -= a[i]\n ans += 1\n elsif m != 0 && a[i] <= k\n m -= 1\n cap = k-a[i]\n ans += 1\n else\n break\n end\nend\n\nputs ans\n"}], "negative_code": [], "src_uid": "869f8763211a7771ecd73d56b5c34479"} {"source_code": "n = gets.to_i\np = [0,1] + gets.split.map(&:to_i)\ndist = [0,0]\ngp = Array.new(n+1,0)\ngp[0] = 1\n2.upto(n) do |i|\n dist[i] = dist[p[i]] + 1\n gp[dist[i]] += 1\nend\nans = 0\ngp.each do |e|\n ans += 1 if e % 2 == 1\nend\np ans\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split(\" \").map {|e| e.to_i}\n\nclass Node\n\tattr_accessor :value, :children, :degree\n\n\tdef initialize value\n\t\t@value = value\n\t\t@children = []\n\tend\nend\nan = Array.new(arr.length+1) { |i| Node.new(i+1)}\ni = 0\n\nwhile i < arr.length\n\tk = i+1\n\tan[arr[i]-1].children.push(an[k])\n\ti+=1\nend\nan.first.degree = 0\ndegree = [1]\nqueue = [an.first]\nwhile queue.length > 0\n\tel = queue.shift\n\tel.children.each do |c|\n\t\tc.degree = el.degree+1\n\t\tdegree[c.degree] ||= 0\n\t\tdegree[c.degree]+=1\n\t\tqueue.push(c)\n\tend\nend\nsum = 0\ndegree.each do |e|\n\tif e % 2 != 0\n\t\tsum+=1\n\tend\nend\nputs sum\n\n\n\n"}], "negative_code": [], "src_uid": "a4563e6aea9126e20e7a33df664e3171"} {"source_code": "def solve(arr, s)\n len = arr.size\n\n len.times do |i|\n arr[i] += arr[i - 1] if i > 0\n end\n\n max_result = -1\n\n if arr[-1] < s\n return -1\n end\n\n len.times do |left|\n result = binsearch(arr, left, s)\n # p [left, result, (result - left + 1)]\n\n if (result - left + 1) > max_result\n max_result = result - left + 1\n end\n end\n\n len - max_result\nend\n\ndef binsearch(arr, left, a)\n l = left - 1\n r = arr.size\n\n while l < r - 1\n m = (l + r) / 2\n if (arr[m] - (left > 0 ? arr[left - 1] : 0)) <= a\n l = m\n else\n r = m\n end\n end\n\n l\nend\n\nn = gets.to_i\n\nn.times do\n size, s = gets.split.map(&:to_i)\n array = Array.new(size)\n array = gets.split.map(&:to_i)\n\n p solve(array, s)\nend\n", "positive_code": [{"source_code": "def solve\r\n q = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n n = q[0]\r\n s = q[1]\r\n sum = 0\r\n a.each do |x|\r\n sum = sum + x\r\n end\r\n if s > sum\r\n puts \"-1\"\r\n return\r\n end\r\n l = 1\r\n r = a.length\r\n while l < r\r\n mid = (l + r + 1) / 2\r\n ok = false\r\n pref = Array.new(n + 1)\r\n pref[0] = 0\r\n i = 1\r\n a.each do |x|\r\n pref[i] = pref[i - 1]\r\n pref[i] = pref[i] + x\r\n if (i - mid) >= 0\r\n curr = pref[i] - pref[i - mid]\r\n if curr <= s\r\n ok = true\r\n end\r\n end\r\n i = i + 1\r\n end\r\n if ok == true\r\n l = mid\r\n else\r\n r = mid - 1\r\n end\r\n end\r\n puts n - l\r\nend\r\n\r\ngets.to_i.times do\r\n solve\r\nend"}, {"source_code": "gets.to_i.times do\r\n n, s = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i)\r\n\r\n cnt = 0\r\n l = 0\r\n inf = 10101010101010\r\n ans = inf\r\n n.times do |r|\r\n cnt += a[r]\r\n while l < r && cnt > s\r\n cnt -= a[l]\r\n l += 1\r\n end\r\n\r\n ans = [ans, n-(r-l+1)].min if cnt == s\r\n end\r\n\r\n puts ans == inf ? -1 : ans\r\nend\r\n\r\n"}, {"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n n, s = ints\r\n a = ints\r\n a_sum = [0]\r\n a.each do |x|\r\n a_sum << a_sum[-1] + x\r\n end\r\n \r\n sum = a_sum[-1]\r\n \r\n if s > sum\r\n puts -1\r\n next\r\n end\r\n \r\n has_to_remove = sum - s\r\n \r\n ans = INF\r\n (0 ... n).each do |i|\r\n removed = a_sum[i]\r\n break if removed > has_to_remove\r\n j = (0 .. n).bsearch { |m| sum - a_sum[n - m] >= has_to_remove - removed } || 0\r\n ans = i + j if i + j < ans\r\n end\r\n \r\n puts ans\r\n end\r\n}\r\n\r\nDEBUG = false\r\nMOD = 10**9+7\r\nINF = 10**18\r\n$yesno = %w(No Yes)\r\n$YesNo = %w(No Yes)\r\n$YESNO = %w(NO YES)\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t ? 1 : 0] end\r\ndef YesNo t; puts $YesNo[t ? 1 : 0] end\r\ndef YESNO t; puts $YESNO[t ? 1 : 0] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]"}, {"source_code": "bsearch_last = ->range, map, target {\r\n l, r = range.begin, range.end + 1\r\n while l < r\r\n m = (l + r) / 2\r\n if map[m] > target\r\n r = m\r\n else\r\n l = m + 1\r\n end\r\n end\r\n map[r - 1] == target ? r - 1 : nil\r\n}\r\n\r\ngets.to_i.times do\r\n n, s = gets.split.map(&:to_i)\r\n xs = gets.split.map(&:to_i)\r\n ps = [0]\r\n xs.each { |x| ps << x + ps.last }\r\n sum_inclusive = ->(from, to) { ps[to + 1] - ps[from] }\r\n answer = (0..n - 1).filter_map do |from|\r\n to = bsearch_last[from..n - 1, ->to { sum_inclusive[from, to] }, s]\r\n to ? n - (to - from + 1) : nil\r\n end.min || -1\r\n p answer\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n, s = gets.split.map(&:to_i)\r\n xs = gets.split.map(&:to_i)\r\n map = {}\r\n sum, max = 0, -1\r\n xs.each.with_index do |x, i|\r\n sum += x\r\n max = i + 1 if sum == s\r\n map[sum] ||= i\r\n if j = map[sum - s]\r\n max = [max, i - j].max\r\n end\r\n end\r\n p max == -1 ? -1 : n - max\r\nend\r\n"}], "negative_code": [{"source_code": "bsearch_last = ->range, block {\r\n i = (0..range.end - range.begin).bsearch { |i| block[range.end - i] }\r\n i ? range.end - i : i\r\n}\r\n\r\ngets.to_i.times do\r\n n, s = gets.split.map(&:to_i)\r\n xs = gets.split.map(&:to_i)\r\n ps = [0]\r\n xs.each { |x| ps << x + ps.last }\r\n sum_inclusive = ->(from, to) { ps[to + 1] - ps[from] }\r\n answer = (0..n - 1).filter_map do |from|\r\n to = bsearch_last[from..n - 1, ->to { sum_inclusive[from, to] == s }]\r\n to ? n - (to - from + 1) : nil\r\n end.min || -1\r\n p answer\r\nend\r\n"}], "src_uid": "68adf23485d9db9a254ab73d4f07bd62"} {"source_code": "gets.chomp.chars.to_a.reduce([0, 0, 0]) { |s, x| s[0] += (x == '+' ? 1 : -1); [s.first, [s.first, s[1]].max, [s.first, s[2]].min] }.tap { |x| puts(x[1] - x[2]) }", "positive_code": [{"source_code": "s = gets.chomp\nmanin = 0\nmanout = 0\ns.size.times do |i|\n if s[i] == \"+\" then\n manin += 1\n if manout != 0 then\n manout -= 1\n end\n else\n manout += 1\n if manin != 0 then\n manin -= 1\n end \n end\nend\nresult = manin + manout\nputs \"#{result}\""}, {"source_code": "s = gets.chomp!\n\nf = g = c =0; res = 0; s.each_char{|si|\n c = 1 if si == '+'; c = -1 if si == '-'\n f += c; g += c; f = 0 if f < 0; g = 0 if g > 0\n res = f if f > res; res = -g if -g > res\n}\n\np res"}, {"source_code": "tmp,mn,mx=0,0,0\ngets.to_s.chomp.each_char do |c|\n\tc==\"-\"?(tmp-=1):(tmp+=1)\n\tmn=tmp if tmp 'S', # Serine\n 'UCC' => 'S', # Serine\n 'UCG' => 'S', # Serine\n 'UCU' => 'S', # Serine\n 'UUC' => 'F', # Phenylalanine\n 'UUU' => 'F', # Phenylalanine\n 'UUA' => 'L', # Leucine\n 'UUG' => 'L', # Leucine\n 'UAC' => 'Y', # Uyrosine\n 'UAU' => 'Y', # Uyrosine\n 'UAA' => '_', # Stop\n 'UAG' => '_', # Stop\n 'UGC' => 'C', # Cysteine\n 'UGU' => 'C', # Cysteine\n 'UGA' => '_', # Stop\n 'UGG' => 'W', # Uryptophan\n 'CUA' => 'L', # Leucine\n 'CUC' => 'L', # Leucine\n 'CUG' => 'L', # Leucine\n 'CUU' => 'L', # Leucine\n 'CCA' => 'P', # Proline\n 'CCC' => 'P', # Proline\n 'CCG' => 'P', # Proline\n 'CCU' => 'P', # Proline\n 'CAC' => 'H', # Histidine\n 'CAU' => 'H', # Histidine\n 'CAA' => 'Q', # Glutamine\n 'CAG' => 'Q', # Glutamine\n 'CGA' => 'R', # Arginine\n 'CGC' => 'R', # Arginine\n 'CGG' => 'R', # Arginine\n 'CGU' => 'R', # Arginine\n 'AUA' => 'I', # Isoleucine\n 'AUC' => 'I', # Isoleucine\n 'AUU' => 'I', # Isoleucine\n 'AUG' => 'M', # Methionine\n 'ACA' => 'T', # Uhreonine\n 'ACC' => 'T', # Uhreonine\n 'ACG' => 'T', # Uhreonine\n 'ACU' => 'T', # Uhreonine\n 'AAC' => 'N', # Asparagine\n 'AAU' => 'N', # Asparagine\n 'AAA' => 'K', # Lysine\n 'AAG' => 'K', # Lysine\n 'AGC' => 'S', # Serine\n 'AGU' => 'S', # Serine\n 'AGA' => 'R', # Arginine\n 'AGG' => 'R', # Arginine\n 'GUA' => 'V', # Valine\n 'GUC' => 'V', # Valine\n 'GUG' => 'V', # Valine\n 'GUU' => 'V', # Valine\n 'GCA' => 'A', # Alanine\n 'GCC' => 'A', # Alanine\n 'GCG' => 'A', # Alanine\n 'GCU' => 'A', # Alanine\n 'GAC' => 'D', # Aspartic Acid\n 'GAU' => 'D', # Aspartic Acid\n 'GAA' => 'E', # Glutamic Acid\n 'GAG' => 'E', # Glutamic Acid\n 'GGA' => 'G', # Glycine\n 'GGC' => 'G', # Glycine\n 'GGG' => 'G', # Glycine\n 'GGU' => 'G' # Glycine \n}\n\ns = gets.chomp!\n\nf = g = c =0; res = 0; s.each_char{|si|\n\tc = 1 if si == '+'; c = -1 if si == '-'\n\tf += c; g += c; f = 0 if f < 0; g = 0 if g > 0\n\tres = f if f > res; res = -g if -g > res\n}\n\np res"}, {"source_code": "dict = {\n 'UCA' => 'S', # Serine\n 'UCC' => 'S', # Serine\n 'UCG' => 'S', # Serine\n 'UCU' => 'S', # Serine\n 'UUC' => 'F', # Phenylalanine\n 'UUU' => 'F', # Phenylalanine\n 'UUA' => 'L', # Leucine\n 'UUG' => 'L', # Leucine\n 'UAC' => 'Y', # Uyrosine\n 'UAU' => 'Y', # Uyrosine\n 'UAA' => '_', # Stop\n 'UAG' => '_', # Stop\n 'UGC' => 'C', # Cysteine\n 'UGU' => 'C', # Cysteine\n 'UGA' => '_', # Stop\n 'UGG' => 'W', # Uryptophan\n 'CUA' => 'L', # Leucine\n 'CUC' => 'L', # Leucine\n 'CUG' => 'L', # Leucine\n 'CUU' => 'L', # Leucine\n 'CCA' => 'P', # Proline\n 'CCC' => 'P', # Proline\n 'CCG' => 'P', # Proline\n 'CCU' => 'P', # Proline\n 'CAC' => 'H', # Histidine\n 'CAU' => 'H', # Histidine\n 'CAA' => 'Q', # Glutamine\n 'CAG' => 'Q', # Glutamine\n 'CGA' => 'R', # Arginine\n 'CGC' => 'R', # Arginine\n 'CGG' => 'R', # Arginine\n 'CGU' => 'R', # Arginine\n 'AUA' => 'I', # Isoleucine\n 'AUC' => 'I', # Isoleucine\n 'AUU' => 'I', # Isoleucine\n 'AUG' => 'M', # Methionine\n 'ACA' => 'T', # Uhreonine\n 'ACC' => 'T', # Uhreonine\n 'ACG' => 'T', # Uhreonine\n 'ACU' => 'T', # Uhreonine\n 'AAC' => 'N', # Asparagine\n 'AAU' => 'N', # Asparagine\n 'AAA' => 'K', # Lysine\n \n 'GGC' => 'G', # Glycine\n 'GGG' => 'G', # Glycine\n 'GGU' => 'G' # Glycine \n}\n\ns = gets.chomp!\n\nf = g = c =0; res = 0; s.each_char{|si|\n c = 1 if si == '+'; c = -1 if si == '-'\n f += c; g += c; f = 0 if f < 0; g = 0 if g > 0\n res = f if f > res; res = -g if -g > res\n}\n\np res\n"}, {"source_code": "s=gets.chomp\nprev=s[0]\nres=[]\nk=1\nres<pos\n neg=count if count 0 then return x\n else return -x\n end\nend\n\ns = gets.chomp\nplus = 0\nminus = 0\nk = false\nt = false\ns.size.times do |i|\n if s[i] == \"+\" then \n plus += 1\n k = true\n else\n minus += 1\n t = true\n end\nend\nman = abs(plus-minus)\nif k && t then\n man += 1\nend\nputs \"#{man}\""}, {"source_code": "def dif(s,i)\n k = i\n while i < s.size && s[i] != s[i-1] do\n i += 1\n end\n return i-k\nend\n\ndef find(x, s)\n x.each_index do |i|\n if x[i] == s then\n return i\n end\n end\n return false\nend\n\ns = gets.chomp\ni = 1\nman = [s[0]]\nwhile i < s.size do\n if s[i] != s[i-1] then\n t = find(man, s[i])\n k = dif(s,i)\n i += k\n if t then\n man[t] = s[i-1]\n end\n else\n while s[i] == s[i-1] do\n if s[i] == \"+\" then\n t = find(man, \"-\")\n else\n t = find(man, \"+\")\n end\n if t then\n man[t] = s[i]\n else\n man += [s[i]]\n end\n i += 1\n end\n end\nend\nputs \"#{man.size}\"\n"}, {"source_code": "def abs(x)\n if x > 0 then return x\n else return -x\n end\nend\n\ns = gets.chomp\nplus = 0\nminus = 0\ns.size.times do |i|\n if s[i] == \"+\" then \n plus += 1\n else\n minus += 1\n end\nend\nif abs(plus-minus) != 0 then\n man = abs(plus-minus)\nelse\n man = 1\nend\nputs \"#{man}\""}, {"source_code": "\ndef dif(s,i)\n k = i\n while i < s.size && s[i] != s[i-1] do\n i += 1\n end\n return i-k\nend\n\ndef find(x, s)\n x.each_index do |i|\n if x[i] == s then\n return i\n end\n end\n return false\nend\n\ns = gets.chomp\ni = 1\nman = [s[0]]\nwhile i < s.size do\n if s[i] != s[i-1] then\n t = find(man, s[i])\n k = dif(s,i)\n i += k\n if t then\n man[t] = s[i-1]\n end\n else\n while s[i] == s[i-1] do\n if s[i] == \"+\" then\n t = find(man, \"-\")\n else\n t = find(man, \"+\")\n end\n if t then\n man[t] = s[i]\n else\n man += [s[i]]\n end\n i += 1\n end\n end\nend\nputs \"#{man.size}\""}, {"source_code": "def same(s, i)\n k = i\n while (i < s.size && s[i] == s[i-1]) do\n i += 1\n end\n return i-k\nend\n\ndef dif(s, i)\n k = i\n while (i < s.size && s[i] != s[i-1]) do\n i += 1\n end\n return i-k\nend\n\ndef alsame(s, i)\n if same(s,i) == s.size-1 then\n s = \"\"\n end\n return s\nend\n\ns = gets.chomp\nplus = 0\nminus = 0\nman = 0\ni = 1\nwhile s.size != 0 do\n k = s.size\n s = alsame(s,i)\n if s == \"\" then\n man += k\n else\n t = dif(s,i) \n s = s[t..-1]\n if t != 0 then\n man += 1\n s = s[1..-1]\n end\n k = s.size\n s = alsame(s,i)\n if s == \"\" then\n man += k\n else\n k = same(s,i)\n s = s[k..-1]\n man += k\n end\n end\nend\nputs \"#{man}\""}, {"source_code": "def dif(s,i)\n k = i\n while i < s.size && s[i] != s[i-1] do\n i += 1\n end\n return i-k\nend\n\ndef find(x, s)\n x.each_index do |i|\n if x[i] == s then\n return i\n end\n end\n return false\nend\n\ns = gets.chomp\ni = 1\nman = [s[0]]\nwhile i < s.size do\n if s[i] != s[i-1] then\n t = find(man, s[i])\n k = dif(s,i)\n i += k\n if t then\n man[t] = s[i-1]\n end\n else\n while s[i] == s[i-1] do\n if s[i] == \"+\" then\n t = find(man, \"-\")\n else\n t = find(man, \"+\")\n end\n if t then\n man[t] = s[i]\n else\n man += [s[i]]\n end\n i += 1\n end\n end\nend\nputs \"#{man.size}\""}, {"source_code": "s = gets\nplus = 0\nminus = 0\ns.size.times do |i|\n if s[i] == \"+\" then plus += 1\n else\n minus += 1\n end\nend\nman = 1\nman += (plus-minus).abs\nputs \"#{man}\""}, {"source_code": "a = gets.to_s.chomp.split(//)\nputs (a.find_all{|el|el==\"+\"}.size-a.find_all{|el|el==\"-\"}.size).abs\n"}, {"source_code": "s= gets.to_s.chomp\na=s.split(//)\nn= (a.find_all{|el|el==\"+\"}.size-a.find_all{|el|el==\"-\"}.size).abs\nt1=\"+\"*(s.size-1)\nt2=\"-\"*(s.size-1)\nwhile s.index(t1)==nil&&s.index(t2)==nil&&t1!=\"+\" do \nt1.chop!\nt2.chop!\nend\nputs [t1.size,n].max\n\t\n\t\n"}, {"source_code": "s= gets.to_s.chomp\na=s.split(//)\nn= (a.find_all{|el|el==\"+\"}.size-a.find_all{|el|el==\"-\"}.size).abs\nt1=\"+\"*(s.size-1)\nt2=\"-\"*(s.size-1)\nwhile s.index(t1)==nil&&s.index(t2)==nil&&t1!=\"+\" do \nt1.chop!\np t1\nt2.chop!\nend\nputs [t1.size,n].max\n\t\n\t\n"}, {"source_code": "dict = {\n 'UUG' => 'L', # Leucine\n 'UAC' => 'Y', # Uyrosine\n 'UAU' => 'Y', # Uyrosine\n 'UAA' => '_', # Stop\n 'UAG' => '_', # Stop\n 'UGC' => 'C', # Cysteine\n 'UGU' => 'C', # Cysteine\n 'CCU' => 'P', # Proline\n 'CAC' => 'H', # Histidine\n 'CAU' => 'H', # Histidine\n 'CAA' => 'Q', # Glutamine\n 'CAG' => 'Q', # Glutamine\n 'CGA' => 'R', # Arginine\n 'CGC' => 'R', # Arginine\n 'CGG' => 'R', # Arginine\n 'CGU' => 'R', # Arginine\n 'AUA' => 'I', # Isoleucine\n 'AUC' => 'I', # Isoleucine\n 'AUU' => 'I', # Isoleucine\n 'AUG' => 'M', # Methionine\n 'ACA' => 'T', # Uhreonine\n \n 'GUG' => 'V', # Valine\n 'GUU' => 'V', # Valine\n 'GCA' => 'A', # Alanine\n 'GCC' => 'A', # Alanine\n 'GCG' => 'A', # Alanine\n 'GCU' => 'A', # Alanine\n 'GAC' => 'D', # Aspartic Acid\n 'GAU' => 'D', # Aspartic Acid\n 'GAA' => 'E', # Glutamic Acid\n 'GAG' => 'E', # Glutamic Acid\n 'GGA' => 'G', # Glycine\n 'GGC' => 'G', # Glycine\n 'GGG' => 'G', # Glycine\n 'GGU' => 'G' # Glycine \n}\n\ns = gets.chomp!\n\nf = g = c =0; res = 0; s.each_char{|si|\n c = 1 if si == '+'; c = -1 if si == '-'\n f += c; g += c; f = 0 if f < 0; g = 0 if g > 0\n res = f if f > res; res = -g if -g > res\n}\n"}, {"source_code": "res=k=0\ngets.chomp.each_char do |c|\n k+=1 if c=='+'\n k-=1 if c=='-'\n res=[res, k.abs].max\nend\nputs res\n"}, {"source_code": "s=gets.gsub(\"-+\", \"- +\").gsub(\"+-\", \"+ -\").split\ns.push(\"o\") if s.size%2==1\nn=s.size/2\nres=0\nfor i in 0..n-1 do\n res=[res, [s[2*i].size, s[2*i+1].size].max].max\nend\nputs res\n"}, {"source_code": "s=gets.chomp\nres=p=m=0\ns.each_char do |c|\n p+=1 if c=='+'\n m+=1 if c=='-'\n res=[res, (p-m).abs].max\nend\nputs res\n"}, {"source_code": "s=gets.chomp\nres=0\nfor i in 1..s.size()\n res=i if s.include?('+'*i) or s.include?('-'*i)\nend\nputs res\n"}, {"source_code": "def main()\n\ts=gets.chomp.to_s\n\ttotin=0\n\ttotout=0\n\tnops=1\n\tfor i in 0...(s.length)\n\t\tif s[i].chr==\"+\"\n\t\t\ttotin+=1\n\t\t\tif totin-1 > totout \n\t\t\t\tnops+=1\n\t\t\tend\n\t\telse\n\t\t\ttotout+=1\n\t\t\tif totout-1 > totin\n\t\t\t\tnops+=1\n\t\t\tend\n\t\tend\n\tend\n\tputs nops\nend\nmain()"}, {"source_code": "def main()\n\ts=gets.chomp.to_s\n\ttotin=0\n\ttotout=0\n\tnops=0\n\tfor i in 0...(s.length)\n\t\tif s[i].chr==\"+\"\n\t\t\ttotin+=1\n\t\t\tif totin-totout>1 || totout==0\n\t\t\t\tnops+=1\n\t\t\tend\n\t\telse\n\t\t\ttotout+=1\n\t\t\tif totout-totin>1 || totin==0\n\t\t\t\tnops+=1\n\t\t\tend\n\t\tend\n\tend\n\tputs nops\nend\nmain()"}, {"source_code": "def main()\n\ts=gets.chomp.to_s\n\tnops=0\n\tfor i in 0...(s.length)\n\t\tif s[i].chr==\"+\"\n\t\t\tlns=0\n\t\t\tindoln=-7\n\t\t\tj=i-1\n\t\t\twhile(j>=0)\n\t\t\t\tif s[j].chr==\"-\"\n\t\t\t\t\tindoln=j\n\t\t\t\t\tbreak\n\t\t\t\tend\n\t\t\t\tj-=1\n\t\t\tend\n\t\t\tif indoln!=-7\n\t\t\t\tj=indoln\n\t\t\t\twhile(j>=0)\n\t\t\t\t\tif s[j].chr==\"-\"\n\t\t\t\t\t\tlns+=1\n\t\t\t\t\t\tj-=1\n\t\t\t\t\telse\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\tif lns<=i-indoln-1\n\t\t\t\t\tnops+=1\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tnops+=1\n\t\t\tend\n\t\telse\n\t\t\tlps=0\n\t\t\tindolp=-7\n\t\t\tj=i-1\n\t\t\twhile(j>=0)\n\t\t\t\tif s[j].chr==\"+\"\n\t\t\t\t\tindolp=j\n\t\t\t\t\tbreak\n\t\t\t\tend\n\t\t\t\tj-=1\n\t\t\tend\n\t\t\tif indolp!=-7\n\t\t\t\tj=indolp\n\t\t\t\twhile(j>=0)\n\t\t\t\t\tif s[j].chr==\"+\"\n\t\t\t\t\t\tlps+=1\n\t\t\t\t\t\tj-=1\n\t\t\t\t\telse\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\tif lps<=i-indolp-1\n\t\t\t\t\tnops+=1\n\t\t\t\tend\n\t\t\telse\n\t\t\t\tnops+=1\n\t\t\tend\n\t\tend\n\tend\n\tputs nops\nend\nmain()"}, {"source_code": "def main()\n\ts=gets.chomp.to_s\n\tmaxp=0\n\tmaxn=0\n\tps=\"+\"\n\tns=\"-\"\n\tj=300\n\twhile(true)\n\t\tind=s.index(ps*j)\n\t\tif ind!=nil\n\t\t\tmaxp=j\n\t\t\tbreak\n\t\tend\n\t\tj-=1\n\tend\n\tj=300\n\twhile(true)\n\t\tind=s.index(ns*j)\n\t\tif ind!=nil\n\t\t\tmaxn=j\n\t\t\tbreak\n\t\tend\n\t\tj-=1\n\tend\n\tputs [maxp,maxn].max\nend\nmain()"}, {"source_code": "max=0\ncount=0\n\ngets.chomp.each_char {|c|\n if c==?+\n count=0 if count<0\n count+=1\n else\n count-=1\n end\n \n max=count.abs if count.abs>max \n}\n\nputs max\n"}, {"source_code": "max=0\ncount=0\n\ngets.chomp.each_char {|c|\n if c==?+\n count+=1\n else\n count-=1\n end\n \n max=count.abs if count.abs>max \n}\n\nputs max\n"}, {"source_code": "pos=0\nneg=0\ncount=0\n\ngets.chomp.each_char {|c|\n if c==?+\n count+=1\n else\n count-=1\n end\n \n pos=count if count>pos \n neg=count if count 100) \n puts s.length \nelse \n puts s =~ /m|w/ ? 0 : s.length.times.inject([1, 1]){|a, i| i < 1 ? a : [a[1], a[1] + (s[i] == s[i-1] && ['u', 'n'].include?(s[i]) ? a[0] : 0)]}[1] % 10000_00007\nend"}, {"source_code": "puts gets.length"}, {"source_code": "puts (s = gets)['w'] || s['m'] ? 0 : s.scan(/[nu]{2,}/).map{|v| $c ||= {0=> 1, 1=> 1}; fib = proc{|n| (r = $c[n]) ? r : fib.call(n-1) + fib.call(n-2)}; fib.call(v.length) }.inject(1){|a, b| a*b} % 100000007"}, {"source_code": "puts (s = gets) =~ /m|w/ ? 0 : s.length.times.inject([1, 1]){|a, i| i < 1 ? a : [a[1], a[1] + (s[i] == s[i-1] ? a[0] : 0)]}[1] % 10000_00007"}], "src_uid": "12c223c903544899638e47bcab88999a"} {"source_code": "# http://codeforces.com/problemset/problem/950/B\nn, m = gets.split.map(&:to_i)\nm1 = gets.split.map(&:to_i)\nm2 = gets.split.map(&:to_i)\n\nc = 0\nif m == 1 || n == 1\n puts 1\nelse\n file1_size = 0\n file2_size = 0\n p1 = 0\n p2 = 0\n\n while p1 < n && p2 < m\n if file1_size + m1[p1] == file2_size + m2[p2]\n file1_size = 0\n file2_size = 0\n p1 += 1\n p2 += 1\n c += 1\n next\n end\n\n if file1_size + m1[p1] > file2_size + m2[p2]\n file2_size += m2[p2]\n p2 += 1\n else\n file1_size += m1[p1]\n p1 += 1\n end\n end\n puts c\nend\n", "positive_code": [{"source_code": "la,lb=gets.split.collect{|t|t.to_i}\nsbl,res=0,0\na=gets.split.collect{|t|t.to_i}\nb=gets.split.collect{|t|t.to_i}\nwhile a.size>0\n if sbl==0\n res+=1\n sbl+=a.shift\n end\n if sbl>0\n sbl-=b.shift\n else\n sbl+=a.shift\n end\nend\nputs res"}, {"source_code": "la,lb=gets.split.collect{|t|t.to_i}\nsbl,res=0,0\na=gets.split.collect{|t|t.to_i}\nb=gets.split.collect{|t|t.to_i}\nwhile a.size>0\n if sbl==0\n res+=1\n sbl+=a.shift\n end\n if sbl>0\n sbl-=b.shift\n else\n sbl+=a.shift\n end\nend\nputs res"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\nb = gets.chomp.split.map(&:to_i)\nans, sa, sb, la, lb = 0, 0, 0, 0, 0\nwhile la < n || lb < m\n if sa == 0\n sa += a[la]\n la += 1\n end\n if sb == 0\n sb += b[lb]\n lb += 1\n end\n if sa == sb\n ans += 1\n sa = 0\n sb = 0\n else\n if sa < sb\n sa += a[la]\n la += 1\n else\n sb += b[lb]\n lb += 1\n end\n end\nend\nans += 1 if sa != 0\nputs ans\n"}], "negative_code": [{"source_code": "# http://codeforces.com/problemset/problem/950/B\nn, m = gets.split.map(&:to_i)\nm1 = gets.split.map(&:to_i)\nm2 = gets.split.map(&:to_i)\n\nc = 0\nif m == 1 || n == 1\n puts 1\nelse\n file1_size = 0\n file2_size = 0\n p1 = 0\n p2 = 0\n\n while p1 < n && p2 < m\n if file1_size + m1[p1] == file2_size + m2[p2]\n file1_size = 0\n file2_size = 0\n p1 += 1\n p2 += 1\n c += 1\n next\n end\n\n if file1_size + m1[p1] > file2_size + m2[p2]\n file2_size += m2[p2]\n p2 += 1\n else\n file1_size += m1[p1]\n p1 += 1\n end\n end\nend\n\nputs c"}], "src_uid": "cb5cbfb4d184cda21ebfbcf47bb970dc"} {"source_code": "gets\na = gets.split.map { |x| x.to_i }.sort\ngets\nb = gets.split.map { |x| x.to_i }.sort.join(\" \")\n\na.each do |x|\n b.sub!(/\\b(#{x-1}|#{x}|#{x+1})\\b/, \"200\")\nend\nputs b.scan(/200/).length\n\n", "positive_code": [{"source_code": "n = STDIN.readline.to_i\nboys = STDIN.readline.split.map {|s| s.to_i }\nm = STDIN.readline.to_i\ngirls = STDIN.readline.split.map {|s| s.to_i }\n\ndef search(n, m, kosher, u, seen, match)\n\tn.times do |v|\n\t\tif kosher[u][v] and not seen[v]\n\t\t\tseen[v] = true\n\t\t\tif match[v] < 0 or search(n, m, kosher, match[v], seen, match)\n\t\t\t\tmatch[v] = u\n\t\t\t\treturn true\n\t\t\tend\n\t\tend\n\tend\n\tfalse\nend\n\nkosher = m.times.map {|j| n.times.map {|i| (boys[i]-girls[j]).abs <= 1 } }\nmatch = n.times.map { -1 }\ncount = 0\nm.times do |u|\n\tseen = n.times.map { false }\n\tcount += 1 if search(n, m, kosher, u, seen, match)\nend\nputs count\n"}, {"source_code": "n = STDIN.readline.to_i\nboys = STDIN.readline.split.map {|s| s.to_i }.sort\nm = STDIN.readline.to_i\ngirls = STDIN.readline.split.map {|s| s.to_i }.sort\n\nb = 0\ncount = 0\ngirls.each do |girl|\n\tb += 1 while b < n and girl-boys[b] > 1\n\tif b < n and (girl-boys[b]).abs <= 1\n\t\tcount += 1\n\t\tb += 1\n\tend\nend\n\nputs count\n"}, {"source_code": "gets\na = gets.split.map { |x| x.to_i }.sort\ngets\nb = gets.split.map { |x| x.to_i }.sort.join(\" \")\n\na.each do |x|\n b.sub!(/\\b(#{x-1}|#{x}|#{x+1})\\b/, \"200\")\nend\nputs b.scan(/200/).length\n"}, {"source_code": "gets\na = gets.split.map { |x| x.to_i }.sort\ngets\nb = gets.split.map { |x| x.to_i }.sort.join(\" \")\n\na.each do |x|\n b.sub!(/\\b(#{x-1}|#{x}|#{x+1})\\b/, \"200\")\nend\nputs b.scan(/200/).length\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |x| x.to_i }.sort\nm = gets.to_i\nb = gets.split.map { |x| x.to_i }.sort\n\ni, j = 0, 0\ncnt = 0\nwhile i < n and j < m\n if (a[i] - b[j]).abs <= 1\n i += 1\n j += 1\n cnt += 1\n elsif a[i] + 1 < b[j]\n i += 1\n else\n j += 1\n end\nend\n\nputs cnt"}, {"source_code": "gets\na = gets.split.map { |x| x.to_i }.sort\ngets\nb = gets.split.map { |x| x.to_i }.sort.join(\" \")\n\na.each do |x|\n b.sub!(/\\b(#{x-1}|#{x}|#{x+1})\\b/, \"200\")\nend\nputs b.scan(/200/).length\n\n"}, {"source_code": "gets\nx=gets.split.map{|e| e.to_i}.sort\ngets\ny=gets.split.map{|e| e.to_i}.sort\n\nans=0\nwhile (!x.empty?) && (!y.empty?)\n\tif (x[0]-y[0]).abs<=1 then\n\t\tans+=1\n\t\tx.shift\n\t\ty.shift\n\telse\n\t\tif x[0]= m\n puts pairs(girl, boy)\nelse\n puts pairs(boy, girl)\nend"}, {"source_code": "boys = gets.chomp.to_i\nboys_skills = gets.chomp\nboys_skills = boys_skills.split\ngirls = gets.chomp.to_i\ngirls_skills = gets.chomp\ngirls_skills = girls_skills.split\n\ncount = 0\nfor i in (0..girls-1)\n\tfor x in (i..girls-1)\n\t\tif girls_skills[i].to_i > girls_skills[x].to_i && i != x\n\t\t\ttemp = girls_skills[i].to_i\n\t\t\tgirls_skills[i] = girls_skills[x].to_i\n\t\t\tgirls_skills[x] = temp\n\t\tend\n\tend\nend\nfor i in (0..boys-1)\n\tfor x in (i..boys-1)\n\t\tif boys_skills[i].to_i > boys_skills[x].to_i && i != x\n\t\t\ttemp = boys_skills[i].to_i\n\t\t\tboys_skills[i] = boys_skills[x].to_i\n\t\t\tboys_skills[x] = temp\n\t\tend\n\tend\nend\nif boys <= girls\n\tfor i in (0..boys-1)\n\t\tfor x in (0..girls_skills.size-1)\n\t\t\tif boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i\n\t\t\t\tgirls_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nelse\n\tfor i in (0..girls-1)\n\t\tfor x in (0..boys_skills.size-1)\n\t\t\tif girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i\n\t\t\t\tboys_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\nprint count"}, {"source_code": "#!/usr/bin/env ruby\n\nn = $stdin.gets.to_i\nboys = $stdin.gets.split.map { |b| b.to_i }\nm = $stdin.gets.to_i\ngirls = $stdin.gets.split.map { |b| b.to_i }\n\nraise \"weird\" unless boys.size == n\nraise \"weird\" unless girls.size == m\n\nboys.sort!\ngirls.sort!\n\ni = 0\nj = 0\nres = 0\nwhile i < n and j < m\n if (boys[i] - girls[j]).abs <= 1\n res += 1\n i += 1\n j += 1\n elsif boys[i] < girls[j]\n i += 1\n elsif boys[i] > girls[j]\n j += 1\n end\nend\n\nputs res\n"}, {"source_code": "gets\na = gets.split.map { |x| x.to_i }.sort\ngets\nb = gets.split.map { |x| x.to_i }.sort.join(\" \")\n\na.each do |x|\n b.sub!(/\\b(#{x-1}|#{x}|#{x+1})\\b/, \"200\")\nend\nputs b.scan(/200/).length\n\n"}, {"source_code": "def solution(boys, boys_skill, girls, girls_skill)\n @boys = boys\n @girls = girls\n @boys_skill = boys_skill.sort!\n @girls_skill = girls_skill.sort!\n\n @couples = 0\n solve(0, 0)\n @couples\nend\n\ndef solve(a_i, b_i)\n return nil if a_i == @boys || b_i == @girls\n if (@boys_skill[a_i] - @girls_skill[b_i]).abs <= 1\n @couples += 1\n solve(a_i + 1, b_i + 1)\n elsif @boys_skill[a_i] > @girls_skill[b_i]\n solve(a_i, b_i + 1)\n else\n solve(a_i + 1, b_i)\n end\nend\n\nboys = gets.to_i\nboys_skill = gets.split.map(&:to_i)\ngirls = gets.to_i\ngirls_skill = gets.split.map(&:to_i)\nputs solution(boys, boys_skill, girls, girls_skill)"}, {"source_code": "def solution(boys, boys_skill, girls, girls_skill)\n boys_skill.sort!\n girls_skill.sort!\n i, j = 0, 0\n\n couples = 0\n while i < boys && j < girls do\n if (boys_skill[i] - girls_skill[j]).abs <= 1\n couples += 1\n i += 1\n j += 1\n else\n if boys_skill[i] > girls_skill[j]\n j += 1\n else\n i += 1\n end\n end\n end\n couples\nend\n\nboys = gets.to_i\nboys_skill = gets.split.map(&:to_i)\ngirls = gets.to_i\ngirls_skill = gets.split.map(&:to_i)\n\n\nputs solution(boys, boys_skill, girls, girls_skill)"}, {"source_code": "n = gets.chomp.to_i\na = gets.split().map(&:to_i)\nm = gets.chomp.to_i\nb = gets.split().map(&:to_i)\na.sort!\nb.sort!\ns = 0\ni = 0\nj = 0\nwhile i < n and j < m\n\tif a[i] < b[j]\n\t\tif b[j] - a[i] <= 1\n\t\t\ts+=1\n\t\t\tj+=1\n\t\tend\n\t\ti+=1\n\telse \n\t\tif a[i] - b[j] <= 1\n\t\t\ti+=1\n\t\t\ts+=1\n\t\tend\n\t\tj+=1\n\tend\nend\nputs s\n"}, {"source_code": "n = gets.to_i\nns = gets.chomp.split.map(&:to_i).sort\nm = gets.to_i\nms = gets.chomp.split.map(&:to_i).sort\nans = 0\ni = 0\nj = 0\nwhile i < n && j < m\n if ns[i] == ms[j] || ns[i] + 1 == ms[j] || ns[i] - 1 == ms[j]\n i += 1\n j += 1\n ans += 1\n elsif ns[i] > ms[j] + 1\n j += 1\n elsif ns[i] + 1 < ms[j]\n i += 1\n end\nend\np ans\n"}, {"source_code": "gets\na = gets.split.map { |x| x.to_i }.sort\ngets\nb = gets.split.map { |x| x.to_i }.sort.join(\" \")\n\na.each do |x|\n b.sub!(/\\b(#{x-1}|#{x}|#{x+1})\\b/, \"200\")\nend\nputs b.scan(/200/).length\n\n"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i).sort\n\ngets\nb = gets.split(' ').map(&:to_i).sort\n\nresult = 0\nwhile !a.empty? && !b.empty?\n if (a.first - b.first).abs < 2\n result += 1\n a.shift\n b.shift\n else\n a.first < b.first ? a.shift : b.shift\n end\nend\n\nputs result\n"}, {"source_code": "#File.open(\"4.txt\",\"r\") do |file|\n\ta=Array.new\n\tb=Array.new\n\tc=Array.new\n\td=Array.new\n\tn=gets.to_i\n\tstr=gets.to_s\n\tc=str.split\n\ti=0\n\twhile ib[j]\n\t\t\tj+=1\n\t\telse\n\t\t\ti+=1\n\t\tend\n\tend\n\tputs s\n#end"}, {"source_code": "gets\na = gets.split.map { |x| x.to_i }.sort\ngets\nb = gets.split.map { |x| x.to_i }.sort.join(\" \")\n\na.each do |x|\n b.sub!(/\\b(#{x-1}|#{x}|#{x+1})\\b/, \"200\")\nend\nputs b.scan(/200/).length\n\n"}, {"source_code": "$dp = Array.new(101)\n(0..101).each do |i|\n $dp[i]=Array.new(101,-1)\nend\n$n= gets.to_i\n$a= gets.split(' ').map(&:to_i).sort\n$m= gets.to_i\n$b= gets.split(' ').map(&:to_i).sort\ndef calc(i,j)\n ret = 0\n if i == $n\n ret\n elsif j==$m\n ret\n elsif $dp[i][j]!=-1\n $dp[i][j]\n else\n ret=calc(i+1,j)\n ret=[calc(i+1,j+1)+(($a[i]-$b[j]).abs<2?1:0),ret].max\n ret=[calc(i,j+1),ret].max\n $dp[i][j]=ret\n ret\n end\nend\n\nputs calc(0,0)\n\n\n\n"}, {"source_code": "gets\na = gets.split.map { |x| x.to_i }.sort\ngets\nb = gets.split.map { |x| x.to_i }.sort.join(\" \")\n\na.each do |x|\n b.sub!(/\\b(#{x-1}|#{x}|#{x+1})\\b/, \"200\")\nend\nputs b.scan(/200/).length\n\n"}, {"source_code": "# cook your code here\nb=gets.to_i\nskb = gets.split(/ /).map! { |e| e=e.to_i }\ng=gets.to_i\nskg = gets.split(/ /).map! { |e| e=e.to_i }\nskg=skg.sort\nskb=skb.sort\ni=0\nj=0\npe=0\n\nwhile j < g and i < b \n if (skb[i]-skg[j]).abs<=1\n pe=pe+1\n i=i+1\n j=j+1\n elsif skb[i]>skg[j]\n j=j+1\n elsif skb[i]= n)\n \n if ((x - b[index]).abs <= 1)\n index += 1\n ans += 1\n end\nend\n \nputs ans\n"}, {"source_code": "gets\na = gets.split.map { |x| x.to_i }.sort\ngets\nb = gets.split.map { |x| x.to_i }.sort\nans = 0\n\na.each do |x|\n b.each do |y|\n if ((x - y).abs <= 1)\n ans += 1\n b.shift\n break\n elsif ( x > y + 1)\n b.shift\n end\n end\nend\n \nputs ans\n"}, {"source_code": "gets\na = gets.split.map { |x| x.to_i }.sort\ngets\nb = gets.chomp\n\na.each do |x|\n b.sub!(/\\b(#{x-1}|#{x}|#{x+1})\\b/, \"200\")\nend\nputs b.scan(/200/).length\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |x| x.to_i }.sort\nm = gets.to_i\nb = gets.split.map { |x| x.to_i }.sort\n\ni, j = 0, 0\ncnt = 0\nwhile i < n and j < m\n if (a[i] - b[j]).abs <= 1\n i += 1\n j += 1\n cnt += 1\n elsif a[i] + 1 < a[j]\n i += 1\n else\n j += 1\n end\nend\n\nputs cnt"}, {"source_code": "gets\nx=gets.split.map{|e| e.to_i}.sort\ngets\ny=gets.split.map{|e| e.to_i}.sort\n\nans=0\nwhile (!x.empty?) && (!y.empty?)\n\tif (x[0]-y[0]).abs<=1 then\n\t\tans+=1\n\t\tx.shift\n\t\ty.shift\n\telse\n\t\tif x[0]= m\n puts pairs(girl, boy)\nelse\n puts pairs(boy, girl)\nend"}, {"source_code": "boys = gets.chomp.to_i\nboys_skills = gets.chomp\nboys_skills = boys_skills.split\ngirls = gets.chomp.to_i\ngirls_skills = gets.chomp\ngirls_skills = girls_skills.split\n\ncount = 0\nfor i in (0..girls-1)\n\tfor x in (i..girls-1)\n\t\tif girls_skills[i].to_i > girls_skills[x].to_i && i += x\n\t\t\ttemp = girls_skills[i].to_i\n\t\t\tgirls_skills[i] = girls_skills[x].to_i\n\t\t\tgirls_skills[x] = temp\n\t\tend\n\tend\nend\nfor i in (0..boys-1)\n\tfor x in (i..boys-1)\n\t\tif boys_skills[i].to_i > boys_skills[x].to_i && i != x\n\t\t\ttemp = boys_skills[i].to_i\n\t\t\tboys_skills[i] = boys_skills[x].to_i\n\t\t\tboys_skills[x] = temp\n\t\tend\n\tend\nend\nif boys <= girls\n\tfor i in (0..boys-1)\n\t\tfor x in (0..girls_skills.size-1)\n\t\t\tif boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i\n\t\t\t\tgirls_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nelse\n\tfor i in (0..girls-1)\n\t\tfor x in (0..boys_skills.size-1)\n\t\t\tif girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i\n\t\t\t\tboys_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\nprint count"}, {"source_code": "boys = gets.chomp.to_i\nboys_skills = gets.chomp\nboys_skills = boys_skills.split\ngirls = gets.chomp.to_i\ngirls_skills = gets.chomp\ngirls_skills = girls_skills.split\n\ncount = 0\nif boys <= girls\n\tfor i in (0..boys-1)\n\t\tfor x in (0..girls_skills.size-1)\n\t\t\tif boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i\n\t\t\t\tgirls_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nelse\n\tfor i in (0..girls-1)\n\t\tfor x in (0..boys_skills.size-1)\n\t\t\tif girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i\n\t\t\t\tboys_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\nprint count\n# for i in (0..girls-1)\n# \tfor x in (1..girls-1)\n# \t\tif girls_skills[i].to_i > girls_skills[x]\n# \t\t\ttemp = girls_skills[i].to_i\n# \t\t\tgirls_skills[i] = girls_skills[x].to_i\n# \t\t\tgirls_skills[x] = temp\n# \t\tend\n# \tend\n# end"}, {"source_code": "boys = gets.chomp.to_i\nboys_skills = gets.chomp\nboys_skills = boys_skills.split\ngirls = gets.chomp.to_i\ngirls_skills = gets.chomp\ngirls_skills = girls_skills.split\n\ncount = 0\nfor i in (0..girls-2)\n\tfor x in (1..girls-1)\n\t\tif girls_skills[i].to_i > girls_skills[x].to_i\n\t\t\ttemp = girls_skills[i].to_i\n\t\t\tgirls_skills[i] = girls_skills[x].to_i\n\t\t\tgirls_skills[x] = temp\n\t\tend\n\tend\nend\nfor i in (0..boys-2)\n\tfor x in (1..boys-1)\n\t\tif boys_skills[i].to_i > boys_skills[x].to_i\n\t\t\ttemp = boys_skills[i].to_i\n\t\t\tboys_skills[i] = boys_skills[x].to_i\n\t\t\tboys_skills[x] = temp\n\t\tend\n\tend\nend\nif boys <= girls\n\tfor i in (0..boys-1)\n\t\tfor x in (0..girls_skills.size-1)\n\t\t\tif boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i\n\t\t\t\tgirls_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nelse\n\tfor i in (0..girls-1)\n\t\tfor x in (0..boys_skills.size-1)\n\t\t\tif girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i\n\t\t\t\tboys_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\nprint count"}, {"source_code": "boys = gets.chomp.to_i\nboys_skills = gets.chomp\nboys_skills = boys_skills.split\ngirls = gets.chomp.to_i\ngirls_skills = gets.chomp\ngirls_skills = girls_skills.split\n\ncount = 0\nfor i in (0..girls-1)\n\tfor x in (1..girls-1)\n\t\tif girls_skills[i].to_i > girls_skills[x].to_i\n\t\t\ttemp = girls_skills[i].to_i\n\t\t\tgirls_skills[i] = girls_skills[x].to_i\n\t\t\tgirls_skills[x] = temp\n\t\tend\n\tend\nend\nfor i in (0..boys-1)\n\tfor x in (1..boys-1)\n\t\tif boys_skills[i].to_i > boys_skills[x].to_i\n\t\t\ttemp = boys_skills[i].to_i\n\t\t\tboys_skills[i] = boys_skills[x].to_i\n\t\t\tboys_skills[x] = temp\n\t\tend\n\tend\nend\nif boys <= girls\n\tfor i in (0..boys-1)\n\t\tfor x in (0..girls_skills.size-1)\n\t\t\tif boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i\n\t\t\t\tgirls_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nelse\n\tfor i in (0..girls-1)\n\t\tfor x in (0..boys_skills.size-1)\n\t\t\tif girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i\n\t\t\t\tboys_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\nprint count"}, {"source_code": "boys = gets.chomp.to_i\nboys_skills = gets.chomp\nboys_skills = boys_skills.split\ngirls = gets.chomp.to_i\ngirls_skills = gets.chomp\ngirls_skills = girls_skills.split\n\ncount = 0\nfor i in (0..girls-1)\n\tfor x in (i..girls-1)\n\t\tif girls_skills[i].to_i > girls_skills[x].to_i && i != x\n\t\t\ttemp = girls_skills[i].to_i\n\t\t\tgirls_skills[i] = girls_skills[x].to_i\n\t\t\tgirls_skills[x] = temp\n\t\tend\n\tend\nend\nfor i in (0..boys-1)\n\tfor x in (i..boys-1)\n\t\tif boys_skills[i].to_i > boys_skills[x].to_i && i != x\n\t\t\ttemp = boys_skills[i].to_i\n\t\t\tboys_skills[i] = boys_skills[x].to_i\n\t\t\tboys_skills[x] = temp\n\t\tend\n\tend\nend\nprint boys_skills\nprint girls_skills\nif boys <= girls\n\tfor i in (0..boys-1)\n\t\tfor x in (0..girls_skills.size-1)\n\t\t\tif boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i\n\t\t\t\tgirls_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nelse\n\tfor i in (0..girls-1)\n\t\tfor x in (0..boys_skills.size-1)\n\t\t\tif girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i\n\t\t\t\tboys_skills.delete_at(x)\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\nprint count"}, {"source_code": "$dp = Array.new(101)\n(0..101).each do |i|\n $dp[i]=Array.new(101,-1)\nend\n$n= gets.to_i\n$a= gets.split(' ').map(&:to_i).sort\n$m= gets.to_i\n$b= gets.split(' ').map(&:to_i).sort\ndef calc(i,j)\n ret = 0\n if i == $n\n ret\n elsif j==$m\n ret\n elsif $dp[i][j]!=-1\n $dp[i][j]\n else\n ret=calc(i+1,j)\n ret=[calc(i+1,j+1)+(($a[i]-$b[j]).abs<2?1:0),ret].max\n ret=[calc(i+1,j),ret].max\n $dp[i][j]=ret\n ret\n end\nend\n\nputs calc(0,0)\n\n\n\n"}], "src_uid": "62766ef9a0751cbe7987020144de7512"} {"source_code": "E=1e-10\ndef rectangle?(a,b,c,d)\n\treturn [a,b,c,d] if rect?(a,b,c,d)\n\treturn [a,c,b,d] if rect?(a,c,b,d)\n\treturn [b,a,c,d] if rect?(b,a,c,d)\n\tnil\nend\n\ndef rect?(a,b,c,d)\n\tm_ac=mid_pts(a,c)\n\treturn nil if same_pos?(a,m_ac)\n\tm_bd=mid_pts(b,d)\n\treturn nil if same_pos?(b,m_bd)\n\treturn nil unless same_pos?(m_ac,m_bd)\n\treturn nil unless rect_angle?(a,b,c)\n\treturn nil unless rect_angle?(b,c,d)\n\ttrue\nend\n\ndef mid_pts(a,b)\n\t[(a[0]+b[0])/2,(a[1]+b[1])/2]\nend\n\ndef dist(a,b)\n\t(a[0]-b[0])**2+(a[1]-b[1])**2\nend\n\ndef rect_angle?(a,b,c)\n\tp,q=b[0]-a[0],b[1]-a[1]\n\tr,s=b[0]-c[0],b[1]-c[1]\n\tsame_val?(p*r+q*s,0.0)\nend\n\ndef same_val?(x,y)\n\t(x-y).abs 0\n os += ary[s]\n else\n zs += ary[s]\n end\n end\n os != zs\nend\n\ndef print_ans(n, bm)\n zc = 0\n zpos = []\n n.times do |s|\n b = (1 << s)\n if b & bm == 0\n zc += 1\n zpos << (s+1)\n end\n end\n puts zc\n puts zpos.join(\" \")\nend\n\nn = gets.to_i\nary = gets.strip.split.map(&:to_i)\n\nif n == 1\n puts -1\nelsif n == 2\n if ary[0] == ary[1]\n puts -1\n else\n puts \"1 1\"\n end\nelse\n ans_found = false\n 1.upto((2**n)-2).each do |bm|\n break if ans_found\n if unequal_split(n, bm, ary)\n print_ans(n, bm)\n ans_found = true\n end\n end\n puts -1 unless ans_found\nend", "positive_code": [{"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n min = arr.min\n puts arr.index(min) + 1\nend\n\n\n"}, {"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i)\nif N == 1 || (N == 2 && as[0] == as[1])\n puts -1\nelse\n puts 1\n puts N.times.min_by{|i| as[i]} + 1\nend"}], "negative_code": [{"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n puts arr[0 + (arr.count/2)]\nend\n\n\n"}, {"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n arr.sort!\n puts arr[0 + arr.count/2]\nend\n\n\n"}, {"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n min = arr.min\n puts \"1\"\nend\n\n\n"}, {"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n puts arr[0]\nend\n\n\n"}, {"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n \n i = 0\n dup = true\n while i <= arr.count - 2\n dup = false if arr[i] != arr[i + 1]\n i = i + 1\n end\n \n even = (arr.count % 2 == 0)\n \n if dup and !even\n puts \"-1\"\n else\n puts arr[0]\n end\nend\n\n\n"}, {"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n \n sum = arr.reduce 0, :+ \n dup = true\n arr.each_with_index do |a, i|\n break if i >= arr.count - 2\n \n next if arr[i] == arr[i + 1]\n \n if arr[i] != arr[i+1]\n dup = false\n break\n end\n end\n \n if dup\n puts -1\n else\n puts arr[0]\n end\nend\n\n\n"}, {"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n \n sum = arr.reduce 0, :+ \n \n if arr[0] == sum - arr[0]\n puts arr[1]\n else\n puts arr[0]\n end\nend\n\n\n"}, {"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n \n i = 0\n dup = true\n while i <= arr.count - 2\n dup = false if arr[i] != arr[i + 1]\n i = i + 1\n end\n \n even = (arr.count % 2 == 0)\n \n if dup and even\n puts \"-1\"\n else\n puts arr[0]\n end\nend\n\n\n"}, {"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n \n sum = arr.reduce 0, :+ \n \n if arr[0] == sum - arr[0]\n puts -1\n else\n puts arr[0]\n end\nend\n\n\n"}, {"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n puts arr[-1]\nend\n\n\n"}, {"source_code": "n = gets.chomp\nn = n.to_i\n\narr = gets.chomp\narr = arr.split \" \"\narr.map! {|a| a.to_i}\n\nif (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])\n puts \"-1\"\nelse\n puts \"1\"\n arr.sort!\n puts arr[-1]\nend\n\n\n"}], "src_uid": "2b55012c899645bac8d293e85e73148f"} {"source_code": "#!/usr/bin/env ruby\n\nnewspapper = gets.strip\nletter_count = Hash.new(0)\npokemon = 'Bulbasaur'\nnewspapper.each_char do |char|\n letter_count[char] += 1 if pokemon.include? char\nend\n\ndef compute_count(letter_count, pokemon)\n count = 0\n loop do\n pokemon.each_char do |char|\n cur_count = letter_count[char]\n return count if cur_count == 0\n letter_count[char] = cur_count - 1\n end\n count += 1\n end\nend\n\nputs compute_count(letter_count, pokemon)\n", "positive_code": [{"source_code": "a=gets.chomp\n\nans=0\nh=Hash.new(0)\n\"Bulbasaur\".chars{|e|\n\th[e]=0\n}\n\na.chars{|e|\n\tif h.key?(e) then\n\t\th[e]+=1\n\tend\n}\nh[\"a\"]/=2\nh[\"u\"]/=2\n\nans=h[\"B\"];\nh.each{|k,v|\n\tans=v if ans>v\n}\n\nputs ans\n\n"}, {"source_code": "c=[]\ngets.bytes{|e| c[e] ? c[e]+=1 : c[e]=1}\nr=10**9\n\"Blbsr\".bytes{|e| c[e]||=0; r=[r, c[e]].min}\n\"au\".bytes{|e| c[e]||=0; r=[r, c[e]/2].min}\nputs r\n"}, {"source_code": "s = gets.chomp\nrequired = {'B' => 1, 'u' => 2,'l' => 1, 'b' => 1,'a' => 2,'s' => 1,'r' => 1}\ncount = Hash.new(0)\ns.each_char do |a|\n\tcount[a] += 1\nend\nval = []\nrequired.each_key do |k|\n\tval << count[k] / required[k]\nend\nputs val.min"}, {"source_code": "s = gets.chomp\nh = Hash.new(0)\ns.each_char{|c| h[c] += 1}\nputs [h['B'], h['u'] / 2, h['l'], h['b'], h['a'] / 2, h['s'], h['r']].min\n"}, {"source_code": "inp = gets.strip\nstr = \"Bulbasaur\"\nputs str.chars.map { |c| inp.count(c) / str.count(c) }.min\n"}, {"source_code": "word = gets.chomp\ncontainer = {}\n\n\"Blbsaur\".each_char { |x| container[x] = 0 }\n\nword.each_char do |x|\n\tif container.has_key?(x)\n\t\tcontainer[x] += 1\n\tend\nend\n\ncontainer[ \"a\" ] /= 2\ncontainer[ \"u\" ] /= 2\n\nputs container.values.min\n"}, {"source_code": "x,y=['Bulbasaur',gets.chomp].map{|s|\n\th=Hash.new 0\n\ts.chars{|c|h[c]+=1}\n\th\n}\np x.map{|k,v|y[k]/v}.min"}, {"source_code": "#!/usr/bin/env ruby\ncount = gets.chomp.chars.reduce(Hash.new(0)) do |count, c|\n count.tap{ |h| h[c] += 1 }\n end\nputs [\n count['B'],\n count['u'] / 2,\n count['l'],\n count['b'],\n count['a'] / 2,\n count['s'],\n count['r'],\n].min\n"}, {"source_code": "s = gets.strip\nexp_counts = { 'B' => 1, 'u' => 2, 'l' => 1, 'b' => 1, 'a' => 2, 's' => 1, 'r' => 1 }\ncounts = {}\ns.each_char do |c|\n counts[c] = 0 if !counts[c]\n counts[c] += 1\nend\nact_counts = counts.select { |k, v| exp_counts.keys.include? k }\nans = 0\nif act_counts.length == exp_counts.length\n bu_cnt = act_counts['B'] / exp_counts['B']\n u_cnt = act_counts['u'] / exp_counts['u']\n l_cnt = act_counts['l'] / exp_counts['l']\n b_cnt = act_counts['b'] / exp_counts['b']\n a_cnt = act_counts['a'] / exp_counts['a']\n s_cnt = act_counts['s'] / exp_counts['s']\n r_cnt = act_counts['r'] / exp_counts['r']\n ans = [bu_cnt, u_cnt, l_cnt, b_cnt, a_cnt, s_cnt, r_cnt].min\nend\nputs ans\n"}], "negative_code": [{"source_code": "a=gets.chomp\n \nans=0\nh=Hash.new(0)\n\"Bulbasaur\".chars{|e|\n\th[e]=0\n}\n \na.chars{|e|\n\tif h.key?(e) then\n\t\th[e]+=1\n\tend\n}\nh[\"a\"]/=2\nans=h[\"B\"];\nh.each{|k,v|\n\tans=v if ans>v\n}\n \nputs ans\n\n"}, {"source_code": "c=[]\ngets.bytes{|e| c[e] ? c[e]+=1 : c[e]=1}\nr=10**9\n\"Bulbasaur\".bytes{|e| c[e]||=0; r=[r, c[e]].min}\nputs r\n"}], "src_uid": "9c429fd7598ea75acce09805a15092d0"} {"source_code": "gets.to_i.times do\n n, k = gets.split.map(&:to_i)\n freq = Hash.new(0)\n gets.split.map(&:to_i).each { freq[_1] += 1 }\n freq.filter! { |_, v| v >= k }\n keys = freq.keys.sort\n\n best = [0, nil]\n cur = [0, nil]\n prev = nil\n\n keys.each do |key|\n if prev && (prev + 1) == key\n cur[0] += 1\n else\n cur[0] = 1\n end\n cur[1] = key\n prev = key\n best = cur.clone if cur[0] > best[0]\n end\n\n unless best[1]\n p -1\n next\n end\n\n puts \"#{best[1] - best[0] + 1} #{best[1]}\"\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, k = gets.split.map(&:to_i)\r\n as = gets.split.map(&:to_i)\r\n xs = as.tally.filter_map { |a, count| a if count >= k }.sort\r\n ys = xs.chunk_while { |a, b| a + 1 == b }.max_by(&:size)\r\n if ys\r\n puts \"#{ys[0]} #{ys[-1]}\"\r\n else\r\n p -1\r\n end\r\nend\r\n"}, {"source_code": "def solve\n _, x = gli\n a = gli.tally.map { |k, v| k if v >= x }.compact.sort\n if a.empty?\n puts(-1)\n return\n end\n ans = 0\n al = a[0]\n cur = 0\n l = a[0]\n (1...a.size).each do |i|\n if a[i - 1] + 1 != a[i]\n if ans < cur\n al = l\n ans = cur\n end\n cur = 0\n l = a[i]\n else\n cur += 1\n end\n end\n if ans < cur\n al = l\n ans = cur\n end\n puts [al, al + ans].join(' ')\nend\n\nMOD = 10**9 + 7\ndef gs = gets.chomp\ndef gi = gets.to_i\ndef gli = gets.split.map(&:to_i)\ndef cyesno(x) = x ? :Yes : :No\ndef uyesno(x) = x ? :YES : :NO\n\ngets.to_i.times { solve }\n"}, {"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n n, k = ints\r\n a = ints.tally\r\n prev = -1\r\n prev_l = nil\r\n count = 0\r\n ans = -1\r\n ans_len = -1\r\n a.keys.sort.each do |key|\r\n if a[key] >= k\r\n if prev == key - 1\r\n else\r\n prev_l = key\r\n end\r\n if ans_len < key - prev_l\r\n ans = \"#{prev_l} #{key}\"\r\n ans_len = key - prev_l\r\n end\r\n prev = key\r\n end\r\n end\r\n puts ans\r\n end\r\n}\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\n$yesno = %w(No Yes)\r\nYesNo = %w(No Yes)\r\nYESNO = %w(NO YES)\r\nINF = 10**18\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t] end\r\ndef YesNo t; puts YesNo[t] end\r\ndef YESNO t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]"}], "negative_code": [], "src_uid": "13fd45f1892f96eab1d5ab966f465a05"} {"source_code": "zeroes, ones, k = gets.split(/\\s+/).map(&:to_i)\r\nx = ('1'*ones + '0'*zeroes).to_i(2)\r\n\r\nr = ('1'*k + '0'*[zeroes-k,0].max).to_i(2)\r\ny = x-r\r\n\r\nif y > 0 && y.to_s(2).count('1') == ones && y.to_s(2).count('0') == zeroes\r\n puts \"Yes\"\r\n puts x.to_s(2)\r\n puts y.to_s(2)\r\nelse\r\n puts \"No\"\r\nend\r\n", "positive_code": [{"source_code": "zeroes, ones, k = gets.split(/\\s+/).map(&:to_i)\r\nx = ('1'*ones + '0'*zeroes).to_i(2)\r\n\r\nr = ('1'*k + '0'*[zeroes-k,0].max).to_i(2)\r\ny = x-r\r\n\r\nif y > 0 && y.to_s(2).count('1') == ones && y.to_s(2).count('0') == zeroes\r\n puts \"Yes\"\r\n puts x.to_s(2)\r\n puts y.to_s(2)\r\nelse\r\n puts \"No\"\r\nend"}, {"source_code": "a,b,k = gets.chomp.split(\" \").map(&:to_i)\r\nb -= 1\r\nif a == 0 && b == 0 && k == 0\r\n puts \"Yes\"\r\n puts 1\r\n puts 1\r\nelsif k >= a+b || (k != 0 && a == 0) || (b == 0 && k > 0)\r\n puts \"No\"\r\nelse\r\n puts \"Yes\"\r\n x = Array.new(a+b,0)\r\n y = Array.new(a+b,0)\r\n if b > 0\r\n y[-1] = 1\r\n x[-(k+1)] = 1\r\n end\r\n i = 0\r\n (b-1).times do\r\n while x[i] == 1 || y[i] == 1\r\n i += 1\r\n end\r\n x[i] = 1\r\n y[i] = 1\r\n i += 1\r\n end\r\n x.unshift(\"1\")\r\n y.unshift(\"1\")\r\n puts x.join\r\n puts y.join\r\nend"}], "negative_code": [{"source_code": "a,b,k = gets.chomp.split(\" \").map(&:to_i)\r\nb -= 1\r\nif k >= a+b || (k != 0 && a == 0)\r\n puts \"No\"\r\nelse\r\n puts \"Yes\"\r\n x = Array.new(a+b,0)\r\n y = Array.new(a+b,0)\r\n y[-1] = 1\r\n x[-(k+1)] = 1\r\n i = 0\r\n (b-1).times do\r\n while x[i] == 1 || y[i] == 1\r\n i += 1\r\n end\r\n x[i] = 1\r\n y[i] = 1\r\n i += 1\r\n end\r\n x.unshift(\"1\")\r\n y.unshift(\"1\")\r\n puts x.join\r\n puts y.join\r\nend"}, {"source_code": "a,b,k = gets.chomp.split(\" \").map(&:to_i)\r\nif k == a+b || (k != 0 && a == 0)\r\n puts \"No\"\r\nelse\r\n puts \"Yes\"\r\n x = Array.new(a+b,0)\r\n y = Array.new(a+b,0)\r\n y[-1] = 1\r\n x[-(k+1)] = 1\r\n i = 0\r\n (b-1).times do\r\n while x[i] == 1 || y[i] == 1\r\n i += 1\r\n end\r\n x[i] = 1\r\n y[i] = 1\r\n i += 1\r\n end\r\n puts x.join\r\n puts y.join\r\nend"}], "src_uid": "ea620a8dbef506567464dcaddcc2b34f"} {"source_code": "gets.to_i.times do\n\ta = (1..9).map { gets.chomp.split('').map &:to_i }\n\t(0...9).each do |i|\n\t\tj = i % 3 * 3 + i / 3\n\t\ta[i][j] = a[i][j] == 9 ? 1 : a[i][j] + 1\n\tend\n\tputs a.map(&:join)\nend\n", "positive_code": [{"source_code": "puts STDIN.read.gsub('1','2').split[1..-1]"}, {"source_code": "t = gets.chomp.to_i\n\n(1..t).each{\n (0...9).each{|i|\n s = gets.chomp\n a = i / 3\n b = i % 3\n \n n = 3*b + a\n if s[n] == '9' then\n s[n] = '1'\n else\n s[n] = (s[n].ord + 1).chr\n end\n \n puts s\n }\n}"}], "negative_code": [], "src_uid": "0e21f1c48c8c0463b2ffa7275eddc633"} {"source_code": "n=gets.to_i\na=[]\n(n-1).times {\na.push gets(' ').to_i\n}\na.push gets.to_i\n\nprog=(a.inject{|sum,x| sum + x })/2\n\nsuma=0\nlicznik=0\n\nfor i in a.sort.reverse\nsuma+=i\nlicznik+=1\nif suma>prog\np licznik\nbreak\nend\nend", "positive_code": [{"source_code": "def sum(numbers)\n total = 0\n\n numbers.each do |i|\n total += i\n end\n\n total\nend\n\ndef quick_sort(numbers, lower_bound, upper_bound)\n if lower_bound < upper_bound\n p = partition(numbers, lower_bound, upper_bound)\n quick_sort(numbers, lower_bound, p - 1)\n quick_sort(numbers, p + 1, upper_bound)\n end\n\nend\n\ndef partition(numbers, lower_bound, upper_bound)\n pivot = numbers[upper_bound]\n i, j = lower_bound, lower_bound\n\n while j <= upper_bound\n if numbers[j] < pivot\n numbers[i], numbers[j] = numbers[j], numbers[i]\n i += 1\n end\n\n j += 1\n end\n\n numbers[i], numbers[upper_bound] = numbers[upper_bound], numbers[i]\n i\nend\n\ndef main\n number_of_coins = gets.to_i\n coins = gets.split.map(&:to_i)\n\n total_value = sum coins\n\n quick_sort(coins, 0, number_of_coins - 1)\n\n coins_needed = 0\n sum = 0\n\n until sum > total_value / 2\n sum += coins[number_of_coins - coins_needed - 1]\n coins_needed += 1\n end\n\n puts coins_needed\nend\n\nmain if __FILE__ == $PROGRAM_NAME\n"}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}"}, {"source_code": "n = STDIN.readline.to_i\ncoins = STDIN.readline.split.map {|s| s.to_i }\ntotal = coins.inject(0, :+)\nsum = 0\ncount = 0\ncoins.sort.reverse.each do |coin|\n sum += coin\n count += 1\n break if 2*sum > total\nend\nputs count\n"}, {"source_code": "n = gets.chomp.to_i\n\narray = gets.chomp.split(\" \").map(&:to_i).sort.reverse\narr_sum = array.inject(&:+)\nres = array[0]\nans = 0\n(1..n).each{ |elem|\n if( res > arr_sum / 2.0)\n ans = elem\n break\n else\n res += array[elem]\n end\n}\nputs ans"}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}"}, {"source_code": "gets\na = gets.strip.split.map(&:to_i)\nsum = a.sort!.reverse!.inject(0) {|acc, m| acc + m }\nf = 0\ni = 0\nwhile f <= sum-f\n f += a[i]\n i += 1\nend\nputs i"}, {"source_code": "n = gets.to_i\na = gets.split(\" \").map(&:to_i).sort{ |x,y| y <=> x }\n\nfor i in 0..n\n l = a[0..i].inject(:+)\n r = a[(i+1)..(a.size)].inject(:+) || 0\n if (l) > (r)\n puts i+1\n break\n end\nend"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i).sort{|x,y|y<=>x}\nn.times do |i|\n if i+1a.slice(i+1,a.size-i-1).reduce(:+)\n \tp i+1\n \tbreak\n elsif i+1==a.size\n \tp i+1\n end\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort.reverse\n\ncounter = a.reduce(:+)\nxounter = 0\nc = 0\nfor i in 0..n-1\n counter-=a[i]\n xounter+=a[i]\n c+=1\n break if xounter>counter\nend\n\nputs c"}, {"source_code": "n = $stdin.readline\na = $stdin.readline.split.map(&:to_i)\n\na.sort!.reverse!\n$s = a.inject(:+)\n#puts \"s=#{$s}\"\n\n# returns [s1, t]\ndef find(a,n)\n if n == 1\n return [a.first, 1]\n else\n s1, t = find(a,n-1)\n #puts \"s1=#{s1}, t=#{t}\"\n s2 = $s - s1\n an = a[n-1]\n if s2>=s1\n s1 += an\n t += 1\n end\n return [s1, t]\n end\nend\n\n#p a\ns1, t = find(a, a.count)\n#p s1\np t"}, {"source_code": "n =gets.chomp.to_i \na= gets.chomp \narr = a.split(/\\s/).map(&:to_i)\narr.sort!.reverse! \nsum1 =0 \ncount =0 \ncheck =0 \narr.each{|x| check+=x } \n \ncheck =check/2 \narr.each do |i| \n\tsum1+=i \n\tcount+=1\n\tif sum1>check\n\t\tbreak \n\tend\nend\nputs count "}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /).map!{|x| x.to_i}\n\na = a.sort\ns = 0\nfor i in 0..n-1\n s = s + a[i]\nend\nss = 0\nnr = 0\n\ni = n-1\nbegin\n if ss <= s\n ss = ss + a[i]\n s = s - a[i]\n nr = nr + 1\n else\n break\n end\n i = i - 1\nend while i >= 0\n\nputs nr"}, {"source_code": "gets\ninp = gets.chomp.split.map { |x| x.to_i }.sort\ncount, total = 0, 0\nwhile total <= inp.inject(0, :+)\n total += inp.pop\n count += 1\nend\nputs count\n"}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nsum=0\n0.upto(a-1) do |i|\n b[i]= b[i].to_i\nsum=sum+b[i]\nend\nr=0\nif sum%2==0\n r=1\nend \n \nsum=(sum/2.0).ceil\n\nb.sort!\nb.reverse!\np=0\n0.upto(a-1) do |i|\np=p+b[i].to_i\n\nif ( p>=sum && r==0)\np=i+1\nbreak\nend\nif (p>sum && r==1)\np=i+1\nbreak\nend\nend\n\nputs \"#{p}\""}, {"source_code": "require 'pp'\n\ngets\ncoins = gets.chomp.split(' ').map(&:to_i).sort\n\ni = coins.length - 1\nwhile i >= 0\n head = coins[0..i-1]\n tail = coins[i..-1]\n head_sum = head.inject(&:+)\n tail_sum = tail.inject(&:+)\n\n debug = {\n head: head,\n tail: tail,\n head_sum: head_sum,\n tail_sum: tail_sum,\n }\n\n if tail_sum > head_sum\n break\n end\n # pp debug\n i -= 1\nend\nputs coins.length - [i, 0].max\n#pp coins\n\n"}, {"source_code": "n= gets.to_i\na = gets.split.map(&:to_i)\ntot, sum, i= 0,0,0\na.each {|x| tot += x}\na.sort! {|x,y| y<=>x}\nuntil sum>tot-sum\n sum += a[i]\n i += 1\nend\nputs i"}, {"source_code": "def sum( coins )\n sum = 0\n coins.each do |coin|\n sum += coin\n end\n sum\nend\n\ngets.chomp\ncoins = gets.chomp.split(/ /).map(&:to_i)\ncoins.sort!\nmy_coins = []\n(coins.length - 1).downto(0).each do |coin|\n break if ( sum( my_coins ) > sum( coins ) )\n my_coins << coins.delete_at( coin )\nend\nputs my_coins.length\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nsum=0\n0.upto(a-1) do |i|\n b[i]= b[i].to_i\nsum=sum+b[i]\nend\nr=0\nif sum%2==0\n r=1\nend \n \nsum=(sum/2.0).ceil\n\nb.sort!\nb.reverse!\np=0\n0.upto(a-1) do |i|\np=p+b[i].to_i\n\nif ( p>=sum && r==0)\np=i+1\nbreak\nend\nif (p>sum && r==1)\np=i+1\nbreak\nend\nend\n\nputs \"#{p}\""}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).push(0).sort\nb = [0]\nc = 0\nloop do\n break if b.inject(:+) > a.inject(:+)\n b << a.pop\n c += 1\nend\n\np c\n"}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}"}, {"source_code": "class C160A\n n = gets.to_i\n a = []\n gets.split.map{|c| a << c.to_i}\n a.sort!\n a.reverse!\n s = 0\n a.map{|c| s += c}\n t = 0\n q = 0\n a.map{|c| t += c; q += 1; break if t * 2 > s}\n puts q\nend"}, {"source_code": "a=[]\nn=gets.to_i\nb=gets.split\nn.times{|i|\n\ta[i]=b[i].to_i}\na.sort!\n\nb=0\nans=0\nhalfsum=a.inject(:+)/2\n\nn.times{|i|\n\tbreak if b>halfsum\n\tb+=a[-i-1]\n\tans+=1}\np ans\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn = $stdin.gets.to_i\nxs = $stdin.gets.split.map(&:to_i).sort.reverse\ns = xs.inject 0, :+\nacc = 0\nxs.each_with_index do |x, i|\n acc += x\n if acc*2 > s\n puts i+1\n break\n end\nend\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split.map(&:to_i).sort.reverse\nsum = a.inject(:+)\ncount = 0\nmoney = 0\n\na.each { |i| count += 1; money += i; break if money > (sum/2.0) }\n\nputs count\n"}, {"source_code": "n = gets.to_i\na = gets.split().map &:to_i\na=a.sort.reverse\nsum = a.inject 0 do |x,y| x + y end\ns=0\ncnt = 0\n\nwhile s + s <= sum\n s += a[cnt]\n cnt = cnt + 1\nend\n\nputs cnt"}, {"source_code": "n=gets.to_i;m=gets.split.map(&:to_i).sort.reverse;m.each_with_index{|v,i| (m.inject(0,:+)>=0)?(m[i]=-m[i]):(break)};puts m.count{|v|v<0}\n"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i)[0..(n-1)].sort! {|x, y| y <=> x}\nsum = a.reduce(:+)\nsegment = 0\ncount = 0\na.each do |item|\n\tsegment += item\n\tcount += 1\n\tif segment * 2 > sum\n\t\tbreak\n\tend\nend\nputs count"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\nvalue = Array.new\nfor i in 0...n\n value[i] = Integer(nums[i])\nend\n\nvalue = value.sort{|x,y| y <=> x}\nsum = 0\nfor i in 0...n\n sum = sum + value[i]\nend\n\nv = Array.new\nx = 0\nfor i in 0..n\n if x > sum - x then \n break\n \n else\n v.push(value[i])\n x = x + value[i]\n end\nend\n\nputs v.length"}, {"source_code": "coins = gets.chomp.to_i\nvalues = gets.chomp\nvalues = values.split\n\ntotal = 0\nfor i in (0..coins-1)\n\tfor x in (i..coins-1)\n\t\tif i != x\n\t\t\tif values[i].to_i < values[x].to_i\n\t\t\t\ttemp = values[i].to_i\n\t\t\t\tvalues[i] = values[x].to_i\n\t\t\t\tvalues[x] = temp\n\t\t\tend\n\t\tend\n\tend\n\ttotal += values[i].to_i\nend\n\ntest_values = 0\ncount = 0\nfor i in (0..coins-1)\n\tif test_values <= total - test_values\n\t\ttest_values += values[i].to_i\n\t\tcount += 1\n\telse\n\t\tbreak\n\tend\nend\n\nprint count"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\na.sort!\na.reverse!\n#puts a[0]\nsum = 0\na.each do\n |t|\n sum += t\nend\n res = 1\n sum2=0\na.each do\n |t|\n sum2+=t\n break if sum2 > (sum-sum2)\n res += 1\nend\nputs res"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i).sort_by{ |x| -x }\n\ns = a.reduce(&:+)\nsum = 0\n\na.each_with_index do |x, i|\n sum += x\n if sum > s / 2\n puts i + 1\n break\n end\nend"}, {"source_code": "\n\n\n\ndef sum(a)\n a.inject(0){|sum,x| sum + x}\nend\n\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\narr.sort!{|x, y| y <=> x}\ntotal = sum(arr)\ni = 0\nwhile i < n\n arr_sum = sum arr[0,i+1]\n i += 1\n if arr_sum > total - arr_sum \n puts i\n break \n end\n \nend"}, {"source_code": "\n\n\n\ndef sum(a)\n a.inject(0){|sum,x| sum + x}\nend\n\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\narr.sort!{|x, y| y <=> x}\ntotal = sum(arr)\ni = 0\narr_sum = 0\nwhile i < n\n arr_sum += arr[i]\n i += 1\n if arr_sum > total - arr_sum \n puts i\n break \n end\n \nend"}, {"source_code": "gets\ncs = gets.split.map(&:to_i).sort.reverse\nsum = cs.inject(:+)\nputs cs.index{ |x| 0 > sum -= 2*x } + 1\n"}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}"}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}\n"}, {"source_code": "gets\nl = gets.split.map(&:to_i).sort { |x, y| y <=> x }\ns = l.reduce(:+)\nt = 0\nc = 0\n\nl.each { |x| \n\t\t\tc += 1 \n\t\t\tt += x\n\t\t\tif t > s - t \n\t\t\t\tbreak\n\t\t\tend\n\t\t}\n\nputs c"}, {"source_code": "coin_number = gets.chomp.to_i\ncoin_seq_number = gets.chomp.split\ncoin_seq_number = coin_seq_number.map{|item| item.to_i}\ncoin_seq_sum = coin_seq_number.inject {|sum, i| sum + i}\ncoin_seq_number = coin_seq_number.sort{|a,b| b <=> a}\ni = 0\ncoin_res_sum = 0\nbegin\n coin_res_sum = coin_seq_number[i] + coin_res_sum\n i = i + 1\nend while coin_res_sum < coin_seq_sum / 2\nif coin_res_sum == coin_seq_sum/2 then\n p i+1\nelse\n p i\nend\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\ncoins = []\n\ncoins = STDIN.gets.split.map { |n| n.to_i }\n\ncoins.sort! { |a, b| b <=> a }\n\ntotal = coins.reduce(:+)\n\nsum = 0\nnumC = 0\nwhile sum <= total/2\n sum += coins[numC]\n numC += 1\nend\n\nputs numC"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort.reverse\nsum = a.reduce(:+)\n\n(0...n).each do |i|\n former = a[0..i].reduce(:+)\n if former > sum - former\n puts i + 1\n break\n end\nend\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(\" \")\n\nfor x in 0...a.size\n\ta[x] = a[x].to_i\nend\n\na.sort! {|y,x| x<=>y}\n\nsum1 = 0\nsum2 = 0\nm = 0\n\nfor x in 0...a.size\n\tsum1 += a[x] \n\tfor y in x+1...a.size\n\t\tsum2 += a[y]\n\tend\n\tif sum1>sum2\n\t\tm = x+1\n\t\tbreak\n\tend\n\tsum2 = 0\nend\n\nputs m\n\t"}, {"source_code": "n, coins = gets.to_i, gets.split.map(&:to_i).sort.reverse\nsum = 0\ntotal = coins.inject(:+)\n(n + 1).times do |i|\n\tif sum > total / 2\n\t\tputs i\n\t\tbreak\n\tend\n\tsum += coins[i]\nend\n"}, {"source_code": "t = gets.to_i\na = gets.split(\" \").map(&:to_i)\na = a.sort.reverse\nsum=-1\nfor i in 0..t\n if a[0,i].inject(0, :+)>a[i,t].inject(0, :+)\n sum=i\n break\n end\nend\nprint(sum)\n"}, {"source_code": "n = gets.chomp.to_i\ncoins = gets.split.collect{|i| i.to_i}\ncoins = coins.sort{|x,y| y <=> x}\n\ntarget = coins.inject(:+) / 2\nsum = 0\ncoins.each_index{|i|\n sum += coins[i]\n if sum > target\n puts i + 1\n break\n end\n}"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na = a.sort.reverse\ntotal = a.inject(:+)\ns = 0\na.each_with_index do |x, i|\n s += x\n if 2 * s > total\n puts i + 1\n break\n end\nend\n"}, {"source_code": "gets;a=gets.split.map(&:to_i).sort.reverse;s=a.inject:+;p a.index{|x|0>s-=2*x}+1\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nsum=0\n0.upto(a-1) do |i|\n b[i]= b[i].to_i\nsum=sum+b[i]\nend\nr=0\nif sum%2==0\n r=1\nend \n \nsum=(sum/2.0).ceil\n\nb.sort!\nb.reverse!\np=0\n0.upto(a-1) do |i|\np=p+b[i].to_i\n\nif ( p>=sum && r==0)\np=i+1\nbreak\nend\nif (p>sum && r==1)\np=i+1\nbreak\nend\nend\n\nputs \"#{p}\""}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}"}, {"source_code": "gets\na=gets.split.map(&:to_i)\na.sort!\na.reverse!\nsum=a.inject{|res,x|res+x}\nk=0\nfor i in 0..a.length-1\n if 2*k<=sum\n k+=a[i]\n end\n if 2*k>sum\n break\n end\nend\nputs i+1\n "}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}\n"}, {"source_code": "n = gets\na = gets.split(' ').map(&:to_i).sort\ns = []\n\nwhile s.inject(0, &:+) <= a.inject(0, &:+)\n s << a.pop\nend\n\nputs s.size\n"}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}\n"}, {"source_code": "n = gets.to_i\na = gets.split\n\nsum = 0\nfor i in 0 ... a.size\n\ta[i] = a[i].to_i\n\tsum += a[i]\nend\n\na.sort!.reverse!\n\nsum2 = 0\nfor i in 0 ... a.size\n\tsum2 += a[i]\n\tif sum2 > sum / 2 then\n\t\tputs((i + 1).to_s)\n\t\tbreak\n\tend\nend"}, {"source_code": "_ = gets.chomp\na = gets.chomp.split(/ /).map(&:to_i).sort { |a,b| b <=> a}\nmy_count = 0\nmy = 0\nall = a.inject(0) { |sum, x| sum + x }\na.each do |a_i|\n my += a_i\n all -= a_i\n my_count += 1\n break if my > all\nend\nputs my_count\n"}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}\n"}, {"source_code": "input = STDIN.read.split(\"\\n\")[1].split(\" \").map(&:to_i).sort!\n\ncount = 0\nsum = 0\n\nwhile !input.empty? and sum <= input.inject {|sum, v| sum += v} do\n\tsum += input.pop\n\tcount += 1\nend\n\nSTDOUT.puts count"}, {"source_code": "coinNum = gets.chomp.to_i\ncoins = gets.chomp.split(' ').map(&:to_i).sort.reverse\nans = 0\ncoins << 0\n\nfor i in (0...coinNum)\n\tans += 1\n\tbreak if coins[0..i].reduce(:+) > coins[(i + 1)...coins.length].reduce(:+)\nend\n\nputs ans"}, {"source_code": "ln1 = gets\nn = ln1.to_i\nln2 = gets\ns = ln2.split(' ')\na = Array.new(0)\nsum = 0\nfor i in 0..n-1\n a << s[i].to_i\n sum += a[i]\nend\na = a.sort\na = a.reverse\nidx = 0\nhave = 0\nfor i in 0..n-1\n sum -= a[i]\n have += a[i]\n if(have > sum)\n idx = i\n break\n end\nend\np idx + 1\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nsum = 0\na.each { |e|\n sum += e\n}\na.sort!.reverse!\nres = 0\nhave = 0\nn.times { |i|\n sum -= a[i]\n have += a[i]\n (res = i + 1; break) if have > sum\n}\np res\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort.reverse\nsum = 0\na.each { |e|\n sum += e\n}\nres = 0\nhave = 0\nn.times { |i|\n sum -= a[i]\n have += a[i]\n (res = i + 1; break) if have > sum\n}\np res\n"}, {"source_code": "n = gets.to_i\nm = gets.split(' ').map{|_|_.to_i}.sort{|x,y| y<=>x}\ntotal = m.inject(:+)\nsum=0\nm.each.with_index do |obj,id|\n sum+=obj\n if sum*2>total\n puts id+1\n break\n end\nend\n"}, {"source_code": "gets\na = gets.strip.split.map(&:to_i)\nsum = a.sort!.reverse!.inject(0) {|acc, m| acc + m }\nf = 0\ni = 0\nwhile f <= sum-f\n f += a[i]\n i += 1\nend\nputs i"}, {"source_code": "n = gets\ncoins = gets.chomp.split(' ').map(&:to_i).sort{|x,y| y <=> x}\nsum = coins.reduce(:+)\ncounter = 0\ntaken_sum = 0\ncoins.each do |coin|\n taken_sum += coin\n counter += 1\n sum -= coin\n break if taken_sum > sum\nend\n\nputs counter"}, {"source_code": "n = gets.chomp.to_i\n\ncoins = gets.chomp.split().map { |x| x.to_i }\ncoins.sort!\ncoins.reverse!\n\nsumLeft = 0\nfor i in coins\n sumLeft += i\nend\n\ni = 0\nsumRight = 0\nwhile i < n\n sumLeft -= coins[i]\n sumRight += coins[i]\n if sumRight > sumLeft\n break\n end\n i += 1\nend\n\nputs (i+1)\n"}, {"source_code": "n = gets.to_i\nst = gets.split\ni = 0\nsum = 0\nwhile ij && s1+st[i]<=min) do\n i -= 1\n end\n if i<=j then \n s1 = s1 + st[j]\n else \n s1 = s1 + st[i]\n end\n coins += 1\nend\nputs \"#{coins}\"\n\n\n"}, {"source_code": "n = gets.chomp.to_i\nm = gets.chomp.split(/ /).map!{|x| x.to_i}\nm.sort!.reverse!\nsum = 0\nfor i in 0..m.length-1\n\tsum += m[i]\nend\nwsum = 0\nret = 0\nfor i in 0..m.length-1\n\tret += 1\n\twsum += m[i]\n\trest = sum - wsum\n\tif rest < wsum\n\t\tbreak\n\tend\nend\nputs ret"}, {"source_code": "# cook your code here\n\nn = gets.to_i \na = gets.chomp.split \nsum = 0 \ncum = Array.new \n\nfor i in 0...n \n a[i] = a[i].to_i \n sum += a[i] \nend \n\na = a.sort { |x,y| y.to_i <=> x.to_i } \n\ncum[0] = a[0]\ni = 0 \n\nuntil cum[i] > sum/2 \n i+=1 \n cum[i] = cum[i-1] + a[i] \nend \n\nputs i+1 "}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort.reverse\nb = []\na.each do |_|\n b << _\n if a.inject(&:+) < b.inject(&:+) * 2\n p b.size\n break\n end\nend\n"}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}"}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;n-=1while 0sum\n p ans\n exit\n end\n}\n"}, {"source_code": "n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}\n"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\na.sort!{|a,b|b<=>a}\n\nsumAll = 0\na.each {|el| sumAll += el }\n\ncnt = 0\nsum = 0\na.each do |el|\n sum += el\n cnt += 1\n break if sum > sumAll / 2\nend\nputs cnt"}, {"source_code": "\ufeffn = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|e| e.to_i}.sort!{|a, b| -(a <=> b)}\nb = []\nc = 0\nwhile a.length > 0 do\n b << a.shift\n c += 1\n if b.inject(0){|s, i| s += i} > a.inject(0){|s, i| s += i}\n break\n end\nend\n\nputs c"}], "negative_code": [{"source_code": "n = gets\ncoins = gets.chomp.split(' ').map(&:to_i).sort\nsum = coins.reduce(:+)\ncounter = 0\ntaken_sum = 0\ncoins.each do |coin|\n taken_sum += coin\n counter += 1\n sum -= coin\n break if taken_sum > sum\nend\n\nputs counter"}, {"source_code": "n = gets.to_i\nst = gets.split\ni = 0\nsum = 0\nwhile i1 && s1+st[i]<=min) do\n i -= 1\n end\n if i<=1 then s1 = s1 + st[j]\n else \n s1 = s1 + st[i]\n end\n coins += 1\nend\nputs \"#{coins}\""}, {"source_code": "sum=0\nn=gets.to_i\na=gets.split.map(&:to_i)\na.sort!\na.reverse!\na.each{|i| sum+=i }\nans=0\ntmp=0\na.each{|i|\n ans+=1\n sum-=i\n tmp+=i\n if tmp>i\n p ans\n exit\n end\n}\n"}, {"source_code": "\ufeffn = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|e| e.to_i}.sort!\nb = []\nc = 0\nwhile a.length > 0 do\n b << a.shift\n c += 1\n if b.inject(0){|s, i| s += i} > a.inject(0){|s, i| s += i}\n break\n end\nend\n\nputs c"}, {"source_code": "n = gets.to_i\na = gets.split(\" \").map(&:to_i).sort{ |x,y| y <=> x }\n\nfor i in 0..n\n l = a[0..i].inject(:+)\n r = a[i..(a.size)].inject(:+) || 0\n if (l) > (r)\n puts i+1\n break\n end\nend"}, {"source_code": "n = $stdin.readline\na = $stdin.readline.split.map(&:to_i)\n\na.sort!.reverse!\n$s = a.inject(:+)\n#puts \"s=#{$s}\"\n\n# returns [s1, t]\ndef find(a,n)\n if n == 1\n return [a.first, 1]\n else\n s1, t = find(a,n-1)\n #puts \"s1=#{s1}, t=#{t}\"\n s2 = $s - s1\n an = a[n-1]\n if s2>s1\n s1 += an\n t += 1\n end\n return [s1, t]\n end\nend\n\n#p a\ns1, t = find(a, a.count)\n#p s1\np t"}, {"source_code": "require 'pp'\n\ngets\ncoins = gets.chomp.split(' ').map(&:to_i).sort.reverse\n\ni = coins.length - 1\nwhile i >= 0\n head = coins[0..i-1]\n tail = coins[i..-1]\n head_sum = head.inject(&:+)\n tail_sum = tail.inject(&:+)\n\n debug = {\n head: head,\n tail: tail,\n head_sum: head_sum,\n tail_sum: tail_sum,\n }\n\n if tail_sum > head_sum\n break\n end\n # pp debug\n i -= 1\nend\nputs coins.length - [i, 0].max\n#pp coins\n\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.split(//).sort.reverse.map(&:to_i)\nsum = a.inject(:+)\ncount = 0\nmoney = 0\n\na.each { |i| count += 1; money += i; break if money > (sum/2.0).ceil }\n\nputs count"}, {"source_code": "n = gets.to_i\na = gets.split().map &:to_i\n\nsum = a.inject 0 do |x,y| x + y end\ns=0\ncnt = 0\n\nwhile s + s <= sum\n s += a[cnt]\n cnt = cnt + 1\nend\n\nputs cnt"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\nvalue = Array.new\nfor i in 0...n\n\tvalue[i] = Integer(nums[i])\nend\n\nvalue = value.sort{|x,y| y <=> x}\nsum = 0\nfor i in 0...n\n\tsum = sum + value[i]\nend\n\nv = Array.new\nx = 0\nfor i in 0...n\n\tif x > sum - x\n\t\tputs v.length\n\telse\n\t\tv.push(value[i])\n\t\tx = x + value[i]\n\tend\nend\n"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\nvalue = Array.new\nfor i in 0...n\n value[i] = Integer(nums[i])\nend\n\nvalue = value.sort{|x,y| y <=> x}\nsum = 0\nfor i in 0...n\n sum = sum + value[i]\nend\n\nv = Array.new\nx = 0\nfor i in 0..n\n if x > sum - x\n puts v.length\n else\n v.push(value[i])\n x = x + value[i]\n end\nend\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\na.sort!\nsum = 0\na.each do\n |t|\n sum += t\nend\n res = 1\n sum2=0\na.each do\n |t|\n sum2+=t\n break if sum2 > (sum-sum2)\n res += 1\nend\nputs res"}, {"source_code": "\n\n\n\ndef sum(a)\n a.inject(0){|sum,x| sum + x}\nend\n\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\narr.sort!{|x, y| y <=> x}\ntotal = sum(arr)\ni = 0\nwhile i < n\n arr_sum = sum arr[0,i+1]\n i += 1\n if arr_sum >= total - arr_sum \n puts i\n break \n end\n \nend"}, {"source_code": "coin_number = gets.chomp.to_i\ncoin_seq_number = gets.chomp.split\n\ncoin_seq_number = coin_seq_number.map{|item| item.to_i}\ncoin_seq_sum = coin_seq_number.inject {|sum, i| sum + i}\n\ni = 0\ncoin_res_sum = 0\nbegin\n coin_res_sum = coin_seq_number[i] + coin_res_sum\n i = i + 1\nend while coin_res_sum < coin_seq_sum / 2\nif coin_number < i+1 then\n p coin_number\nelse\n p i+1\nend\n"}, {"source_code": "coin_number = gets.chomp.to_i\ncoin_seq_number = gets.chomp.split\n\ncoin_seq_number = coin_seq_number.map{|item| item.to_i}\ncoin_seq_sum = coin_seq_number.inject {|sum, i| sum + i}\n\ni = 0\ncoin_res_sum = 0\nbegin\n coin_res_sum = coin_seq_number[i] + coin_res_sum\n i = i + 1\nend while coin_res_sum < coin_seq_sum / 2\np i+1"}, {"source_code": "t = gets.to_i\na = gets.split(\" \").map(&:to_i)\na = a.sort\nsum=-1\nfor i in 0..t\n if a[0,i].inject(0, :+)>a[i,t].inject(0, :+)\n sum=i\n break\n end\nend\nprint(sum)\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \").sort.reverse\nsum=0\n0.upto(a-1) do |i|\nsum=sum+b[i].to_i\nend\nsum=(sum/2)+1\np=0\n0.upto(a-1) do |i|\np=p+b[i].to_i\nif p>sum\np=i+1\nbreak\nend\nend\n\nputs \"#{p}\"\n\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nsum=0\n0.upto(a-1) do |i|\n b[i]= b[i].to_i\nsum=sum+b[i]\nend\nr=0\nif sum%2==0\n r=1\nend \n \nsum=(sum/2.0).ceil\nb.sort!\nb.reverse!\np=0\n0.upto(a-1) do |i|\np=p+b[i].to_i\n\nif p>=sum && r==0\np=i+1\nbreak\nend\nif p>sum && r==1\np=i+1\nbreak\nend\nend\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nsum=0\n0.upto(a-1) do |i|\n b[i]= b[i].to_i\nsum=sum+b[i]\nend\nsum=(sum/2.0).ceil\nb.sort!\nb.reverse!\np=0\n0.upto(a-1) do |i|\np=p+b[i].to_i\nif p>sum\np=i+1\nbreak\nend\nend\n\nputs \"#{p}\""}, {"source_code": "n=gets.to_i\na=[]\n(n-1).times {\na.push gets(' ').to_i\n}\na.push gets.to_i\n\nprog=(a.inject{|sum,x| sum + x })/2\n\nsuma=0\nlicznik=0\n\nfor i in a.sort\nsuma+=i\nlicznik+=1\nif suma>prog\np licznik\nbreak\nend\nend"}, {"source_code": "_ = gets.chomp\na = gets.chomp.split(/ /).map(&:to_i).sort { |a,b| b <=> a}\nmy_count = 0\nmy = 0\ntwins = 0\na.each do |a_i|\n if twins + a_i >= my\n my += a_i\n my_count += 1\n else\n twins += a_i\n end\nend\nputs my_count\n"}, {"source_code": "_ = gets.chomp\na = gets.chomp.split(/ /).map(&:to_i)\nmy_count = 0\nmy = 0\ntwins = 0\na.each do |a_i|\n if twins + a_i >= my\n my += a_i\n my_count += 1\n else\n twins += a_i\n end\nend\nputs my_count\n"}, {"source_code": "input = STDIN.read.split(\"\\n\")[1].split(\" \").map(&:to_i).sort!\ncount = 0\n\nwhile !input.empty? and count < input.inject {|sum, v| sum += v} do\n\tinput.pop\n\tcount += 1\nend\n\nSTDOUT.puts count"}], "src_uid": "ee535e202b7662dbaa91e869c8c6cee1"} {"source_code": "x1, y1, x2, y2 = gets.split(' ').map(&:to_i)\n\nif x1 != x2 && y1 != y2\n if (x1-x2).abs != (y1-y2).abs\n puts -1\n else\n puts \"#{x1} #{y2} #{x2} #{y1}\"\n end\nelsif x1 != x2\n delta = (x1 - x2).abs\n puts \"#{x1} #{y1+delta} #{x2} #{y2+delta}\"\nelsif y1 != y2\n delta = (y1 - y2).abs\n puts \"#{x1+delta} #{y1} #{x2+delta} #{y2}\"\nelse\n puts -1\nend\n", "positive_code": [{"source_code": "x1, y1, x2, y2 = gets.split.map &:to_i\n\ndef evaluate_vertical_side x1, x2, y1, y2\n delta_y = (y2 - y1).abs\n if x1 + delta_y <= 1000\n x3 = x1 + delta_y\n return [x3, y1, x3, y2]\n elsif x1 - delta_y >= -1000\n x3 = x1 - delta_y\n return [x3, y1, x3, y2]\n else\n return -1\n end \nend\n\nif x1 == x2 #vertical side\n new_points = evaluate_vertical_side x1, x2, y1, y2\n puts new_points == -1? \"-1\" : \"#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}\"\nelsif y1 == y2 #horizontal side\n x1, y1 = y1, x1\n x2, y2 = y2, x2\n new_points = evaluate_vertical_side x1, x2, y1, y2\n puts new_points == -1? \"-1\" : \"#{new_points[1]} #{new_points[0]} #{new_points[3]} #{new_points[2]}\"\nelsif (y2 - y1).abs == (x2 - x1).abs #diagonal\n x3 = x1 \n y3 = y2\n x4 = x2\n y4 = y1\n puts \"#{x3} #{y3} #{x4} #{y4}\"\nelse #not squar\n puts \"-1\"\nend\n\n\n"}, {"source_code": "x1,y1,x2,y2=gets.chomp.split.map(&:to_i)\nif x1==x2\n\tputs (x1+y2-y1).to_s+' '+y1.to_s+' '+(x2+y2-y1).to_s+' '+y2.to_s\nelsif y1==y2\n\tputs x1.to_s+' '+(y1+x1-x2).to_s+' '+x2.to_s+' '+(y2+x1-x2).to_s\nelsif x1-x2==y1-y2 || x1-x2==y2-y1\n\tputs x1.to_s+' '+y2.to_s+' '+x2.to_s+' '+y1.to_s\nelse\n\tputs \"-1\"\nend"}, {"source_code": "x, y, a, b = gets.split.map(&:to_i)\nx, y, a, b = [[x, y], [a, b]].min[0], [[x, y], [a, b]].min[1], [[x, y], [a, b]].max[0], [[x, y], [a, b]].max[1]\nif x == a\n puts [x + (y - b).abs, y, a + (y - b).abs, b].map(&:to_s).join(\" \")\nelsif y == b\n puts [x, y + (x - a).abs, a, b + (x - a).abs].map(&:to_s).join(\" \")\nelse\n if a > x && b > y\n if a - x == b - y\n puts [x, b, a, y].map(&:to_s).join(\" \")\n else \n puts \"-1\"\n end\n else\n if a - x == y - b\n puts [x, b, a, y].map(&:to_s).join(\" \")\n else\n puts \"-1\"\n end\n end\nend"}, {"source_code": "x1,y1,x2,y2 = gets.split.map(&:to_i)\ndx = (x2-x1)\ndy = (y2-y1)\n\nif dx != 0 and dy != 0 and dx.abs != dy.abs\n puts -1\nelsif dx == 0\n puts \"#{x1+dy} #{y1} #{x1+dy} #{y1+dy}\"\nelsif dy == 0\n puts \"#{x1} #{y1+dx} #{x1+dx} #{y1+dx}\"\nelse\n puts \"#{x1} #{y1+dy} #{x1+dx} #{y1}\"\nend"}, {"source_code": "x1, y1, x2, y2 = gets.split.map(&:to_i)\nd1 = x1 - x2\nd2 = y1 - y2\nt = false\nif (d1*d2!=0 && (d1!=-d2 && d1!=d2))\n puts -1\n t = true;\nend\nif (d1==0 || d2 == 0)\n puts(\"#{x1-d2} #{y1-d1} #{x2-d2} #{y2-d1}\")\n t = true\nend\nif !t\n puts(\"#{x1} #{y2} #{x2} #{y1}\")\nend"}, {"source_code": "x1, y1, x2, y2 = gets.chomp.split(/ /).map(&:to_i)\nx3, y3, x4, y4 = [0, 0, 0, 0]\ninvalid = false\nif x1 == x2\n diff = (y2 - y1).abs\n x3, x4 = x1 + diff, x2 + diff\n y3, y4 = y1, y2\nelsif y1 == y2\n diff = (x2 - x1).abs\n x3, x4 = x1, x2\n y3, y4 = y1 + diff, y2 + diff\nelsif (x2 - x1).abs == (y2 - y1).abs\n x3, y3, x4, y4 = x1, y2, x2, y1\nelse\n invalid = true\nend\nif !invalid\n puts \"#{x3} #{y3} #{x4} #{y4}\"\nelse\n puts \"-1\"\nend\n"}, {"source_code": "x1,y1,x2,y2=gets.split.map{|e| e.to_i}\n\ndx=x2-x1\ndy=y2-y1\ndx2=dx.abs\ndy2=dy.abs\nif dx2==0 && dy2==0 then\n\tputs -1\nelsif dx2==dy2 then\n\tputs [x1,y2,x2,y1]*\" \"\nelsif dx2==0 then\n\tputs [x1+dy,y1,x2+dy,y2]*\" \"\nelsif dy2==0 then\n\tputs [x1,y1+dx,x2,y2+dx]*\" \"\nelse\n\tputs -1\nend\n\n"}, {"source_code": "x1,y1,x2,y2 = gets.split.map(&:to_i)\nif x1 == x2\n\ta = y1 - y2\n\tif -1000 <= x1 + a and x1 + a <= 1000\n\t\tprint x1 + a,' ',y1,' ',x2 + a,' ',y2\n\telsif -1000 <= x1 - a and x1 - a <= 1000\n\t\tprint x1 - a,' ',y1,' ',x2 - a,' ',y2\n\tend\nelsif y1 == y2\n\ta = x1 - x2\n\tif -1000 <= y1 + a and y1 + a <= 1000\n\t\tprint x1,' ',y1 + a,' ',x2,' ',y2 + a\n\telsif -1000 <= y1 - a and y1 - a <= 1000\n\t\tprint x1,' ',y1 - a,' ',x2,' ',y2 - a\n\tend\nelsif [x1-x2,x2-x1].max == [y1-y2,y2-y1].max\n\tif x1 < x2 and y1 < y2\n\t\tprint [x1,x2].min,' ',[y1,y2].max,' ',[x1,x2].max,' ',[y1,y2].min\n\telsif x2 < x1 and y2 < y1\n\t\tprint [x1,x2].min,' ',[y1,y2].max,' ',[x1,x2].max,' ',[y1,y2].min\n\telsif \n\t\tprint [x1,x2].min,' ',[y1,y2].min,' ',[x1,x2].max,' ',[y1,y2].max\n\tend\nelse\n\tp -1\nend\n"}, {"source_code": "\n\nclass Point\n def initialize(x_c,y_c)\n @x_coord=x_c\n @y_coord=y_c\n end\n def x\n return @x_coord\n end\n def y\n return @y_coord\n end\nend\n\na,b,c,d = gets.split(\" \").map {|x| x.to_i}\n\np1=Point.new(a,b)\np2=Point.new(c,d)\n\nif p1.x==p2.x\n d = (p1.y-p2.y).abs\n print \"#{p1.x+d} #{p1.y} #{p2.x+d} #{p2.y}\"\n exit\nend\n\nif p1.y==p2.y\n d = (p1.x-p2.x).abs\n print \"#{p1.x} #{p1.y+d} #{p2.x} #{p2.y+d}\"\n exit\nend\n\nif (p1.x-p2.x).abs!=(p1.y-p2.y).abs\n print \"-1\"\n exit\nend\n\nprint \"#{p1.x} #{p2.y} #{p2.x} #{p1.y}\"\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nx1, y1, x2, y2 = gets.split.map(&:to_i)\n# -100..100\nif x1 == x2\n # vertical edge\n len = (y1 - y2).abs\n puts \"#{x1 + len} #{y1} #{x2 + len} #{y2}\"\nelsif y1 == y2\n # horizontal edge\n len = (x1 - x2).abs\n puts \"#{x1} #{y1 + len} #{x2} #{y2 + len}\"\nelsif (x1-x2).abs == (y1-y2).abs\n # diagonal edge (must be square)\n if x1 < x2\n puts \"#{x1} #{y2} #{x2} #{y1}\"\n else\n puts \"#{x2} #{y1} #{x1} #{y2}\"\n end\nelse\n # impossible\n puts -1\nend"}, {"source_code": "xxyy = gets.chomp\nxxyy = xxyy.split\nx1 = xxyy[0].to_i\ny1 = xxyy[1].to_i\nx2 = xxyy[2].to_i\ny2 = xxyy[3].to_i\n\nif x1 == x2 && y1 != y2\n\tprint x1 + [y1, y2].max - [y1,y2].min\n\tprint \" \"\n\tprint [y1, y2].max\n\tprint \" \"\n\tprint x1 + [y1, y2].max - [y1,y2].min\n\tprint \" \"\n\tprint [y1,y2].min\nelsif y1 == y2 && x1 != x2\n\tprint [x1,x2].min\n\tprint \" \"\n\tprint y1 - ([x1,x2].max - [x1,x2].min)\n\tprint \" \"\n\tprint [x1,x2].max\n\tprint \" \"\n\tprint y1 - ([x1,x2].max - [x1,x2].min)\nelse\n\tif (x1 - x2).abs == (y1 - y2).abs\n\t\tprint x1\n\t\tprint \" \"\n\t\tprint y2\n\t\tprint \" \"\n\t\tprint x2\n\t\tprint \" \"\n\t\tprint y1\n\telse\n\t\tprint -1\n\tend\nend\n\t"}, {"source_code": "x1,y1,x2,y2 = gets.split(\" \").map(&:to_i)\n\nx_r = (x2 - x1)\ny_r = (y2 - y1)\nx_a = x_r.abs\ny_a = y_r.abs\nif (x1 != x2 && y1 != y2 && x_a != y_a)\n puts \"-1\"\nelsif (x1 == x2)\n puts \"#{x1 + (y1 - y2).abs} #{y1} #{x2 + (y1 - y2).abs} #{y2}\"\nelsif (y1 == y2)\n puts \"#{x1} #{y1 + (x1 - x2).abs} #{x2} #{y2 + (x1 - x2).abs}\"\nelse\n puts \"#{x1} #{y2} #{x2} #{y1}\"\nend"}, {"source_code": "x1,y1,x2,y2 = gets.split.map(&:to_i)\ndx = (x2-x1)\ndy = (y2-y1)\n\nif dx != 0 and dy != 0 and dx.abs != dy.abs\n puts -1\nelsif dx == 0\n puts \"#{x1+dy} #{y1} #{x1+dy} #{y1+dy}\"\nelsif dy == 0\n puts \"#{x1} #{y1+dx} #{x1+dx} #{y1+dx}\"\nelse\n puts \"#{x1} #{y1+dy} #{x1+dx} #{y1}\"\nend\n"}, {"source_code": "x1,y1,x2,y2=gets.split.map(&:to_i)\n\nif x1==x2\n x3=x1+(y1-y2).abs\n x4=x3\n y3=y1\n y4=y2\nelsif y1==y2\n y3=y1+(x1-x2).abs\n y4=y3\n x3=x1\n x4=x2\nelsif (x1-x2).abs == (y1-y2).abs\n x3=x2\n y3=y1\n x4=x1\n y4=y2\nelse\n puts -1\n exit\nend\n\nputs \"#{x3} #{y3} #{x4} #{y4}\"\n\n\n"}, {"source_code": "line = gets\nx1, y1, x2, y2 = line.split.map(&:to_i)\nif y1 == y2\n\tl = (x1 - x2).abs\n\ty3 = y1 + l\n\tx3 = x1\n\ty4 = y2 + l\n\tx4 = x2 \n\tputs [x3, y3, x4, y4].join \" \"\nelsif x1 == x2\n\tl = (y1 - y2).abs\n\tx3 = x1 + l\n\ty3 = y1\n\tx4 = x2 + l\n\ty4 = y2\n\tputs [x3, y3, x4, y4].join \" \"\nelsif (x1 - x2).abs == (y1 - y2).abs\n\tl = (x1 - x2).abs\n\tx3 = x1\n\ty3 = if y1 > y2 \n\t\ty1 - l\n\telse\n\t\ty1 + l\n\tend\n\tx4 = if x1 > x2 \n\t\tx1 - l\n\telse\n\t\tx1 + l\n\tend\n\n\ty4 = y1\n\tputs [x3, y3, x4, y4].join \" \"\nelse\n\tputs \"-1\"\nend\t\t\n\t\t\n\n"}, {"source_code": "\n\nx, y, a, b = gets.split.map(&:to_i)\n\nx, y, a, b = [[x, y], [a, b]].min[0], [[x, y], [a, b]].min[1],\n [[x, y], [a, b]].max[0], [[x, y], [a, b]].max[1]\n\nif x == a\n puts [x + (y-b).abs, y, a + (y-b).abs, b].map(&:to_s).join(\" \")\nelsif y == b\n puts [x, y + (x-a).abs, a, b + (x-a).abs].map(&:to_s).join(\" \")\nelse\n if a > x && b > y\n if a - x == b - y\n puts [x, b, a, y].map(&:to_s).join(\" \")\n else\n puts \"-1\"\n end\n else\n if a - x == y - b\n puts [x, b, a, y].map(&:to_s).join(\" \")\n else\n puts \"-1\"\n end\n end\nend\n\n\n"}, {"source_code": "x1, y1, x2, y2 = gets.split.map(&:to_i)\nif x1 == x2\n puts [x1 + (y2 - y1), y1, x2 + (y2 - y1), y2].join(\" \")\nelsif y1 == y2\n puts [x1, y1 + (x2 - x1), x2, y2 + (x2 - x1)].join(\" \")\nelsif (x2 - x1) == (y2 - y1) or (x2 - x1) == - (y2 - y1)\n puts [x1, y2, x2, y1].join(\" \")\nelse\n puts \"-1\"\nend\n"}], "negative_code": [{"source_code": "x1, y1, x2, y2 = gets.split.map &:to_i\n\ndef evaluate_vertical_side x1, x2, y1, y2\n delta_y = (y2 - y1).abs\n if x1 + delta_y <= 1000\n x3 = x1 + delta_y\n return [x3, y1, x3, y2]\n elsif x1 - delta_y >= -1000\n x3 = x1 - delta_y\n return [x3, y1, x3, y2]\n else\n return -1\n end \nend\n\nif x1 == x2 #vertical side\n new_points = evaluate_vertical_side x1, x2, y1, y2\n puts new_points == -1? \"-1\" : \"#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}\"\nelsif y1 == y2 #horizontal side\n x1, y1 = y1, x1\n x2, y2 = y2, x2\n new_points = evaluate_vertical_side x1, x2, y1, y2\n puts new_points == -1? \"-1\" : \"#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}\"\nelsif (y2 - y1).abs == (x2 - x1).abs #diagonal\n x3 = x1 \n y3 = y2\n x4 = x2\n y4 = y1\n puts \"#{x3} #{y3} #{x4} #{y4}\"\nelse #not squar\n puts \"-1\"\nend\n\n\n"}, {"source_code": "x1, y1, x2, y2 = gets.split.map &:to_i\n\ndef evaluate_vertical_side x1, x2, y1, y2\n if x1 + (y2 - y1) <= 1000\n x3 = x1 + (y2 - y1)\n return [x3, y1, x3, y2]\n elsif x1 - (y2 - y1) >= -1000\n x3 = x1 - (y2 - y1)\n return [x3, y1, x3, y2]\n else\n return -1\n end \nend\n\nif x1 == x2 #vertical side\n new_points = evaluate_vertical_side x1, x2, y1, y2\n puts new_points == -1? \"-1\" : \"#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}\"\nelsif y1 == y2 #horizontal side\n x1, y1 = y1, x1\n x2, y2 = y2, x2\n new_points = evaluate_vertical_side x1, x2, y1, y2\n puts new_points == -1? \"-1\" : \"#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}\"\nelsif (y2 - y1).abs == (x2 - x1).abs #diagonal\n x3 = x1 \n y3 = y2\n x4 = x2\n y4 = y1\n\n puts \"#{x3} #{y3} #{x4} #{y4}\"\nelse #not squar\n puts \"-1\"\nend\n\n\n"}, {"source_code": "x1, y1, x2, y2 = gets.split.map(&:to_i)\nd1 = x1 - x2\nd2 = y1 - y2\nt = false\nif (d1*d2!=0 && (d1!=-d2 && d1!=d2))\n puts -1\n t = true;\nend\nif (d1==0 || d2 == 0)\n puts(\"#{x1-d2} #{y1-d1} #{x1-d2} #{y2-d1}\")\n t = true\nend\nif !t\n puts(\"#{x1} #{y2} #{x2} #{y1}\")\nend"}, {"source_code": "x1, y1, x2, y2 = gets.chomp.split(/ /).map(&:to_i)\nx3, y3, x4, y4 = [0, 0, 0, 0]\ninvalid = false\nif x1 == x2\n diff = (y2 - y1).abs\n x3, x4 = x1 + diff, x2 + diff\n y3, y4 = y1, y2\nelsif y1 == y2\n diff = (y2 - y1).abs\n x3, x4 = x1, x2\n y3, y4 = y1 + diff, y2 + diff\nelsif (x2 - x1).abs == (y2 - y1).abs\n x3, y3, x4, y4 = x1, y2, x2, y1\nelse\n invalid = true\nend\nif !invalid\n puts \"#{x3} #{y3} #{x4} #{y4}\"\nelse\n puts \"-1\"\nend\n"}, {"source_code": "x1,y1,x2,y2=gets.split.map{|e| e.to_i}\n\ndx=x2-x1\ndy=y2-y1\nif dx==0 && dy==0 then\n\tputs -1\nelsif dx==dy then\n\tputs [x1,y1+dx,x2,y2-dy]*\" \"\nelsif dx==0 then\n\tputs [x1+dy,y1,x2+dy,y2]*\" \"\nelsif dy==0 then\n\tputs [x1,y1+dx,x2,y2+dx]*\" \"\nelse\n\tputs -1\nend\n\n"}, {"source_code": "x1,y1,x2,y2 = gets.split.map(&:to_i)\nif x1 == x2\n\ta = y1 - y2\n\tif -1000 <= x1 + a and x1 + a <= 1000\n\t\tprint x1 + a,' ',y1,' ',x2 + a,' ',y2\n\telsif -1000 <= x1 - a and x1 - a <= 1000\n\t\tprint x1 - a,' ',y1,' ',x2 - a,' ',y2\n\tend\nelsif y1 == y2\n\ta = y1 - y2\n\tif -1000 <= y1 + a and y1 + a <= 1000\n\t\tprint x1,' ',y1 + a,' ',x2,' ',y2 + a\n\telsif -1000 <= y1 - a and y1 - a <= 1000\n\t\tprint x1,' ',y1 - a,' ',x2,' ',y2 - a\n\tend\nelsif [x1-x2,x2-x1].max == [y1-y2,y2-y1].max\n\tif x1 < x2 and y1 < y2\n\t\tprint [x1,x2].min,' ',[y1,y2].max,' ',[x1,x2].max,' ',[y1,y2].min\n\telsif x2 < x1 and y2 < y1\n\t\tprint [x1,x2].min,' ',[y1,y2].max,' ',[x1,x2].max,' ',[y1,y2].min\n\telsif \n\t\tprint [x1,x2].min,' ',[y1,y2].min,' ',[x1,x2].max,' ',[y1,y2].max\n\tend\nelse\n\tp -1\nend\n"}, {"source_code": "x1,y1,x2,y2 = gets.split.map(&:to_i)\ndx = (x2-x1)\ndy = (y2-y1)\n\nif dx != 0 and dy != 0 and dx.abs != dy.abs\n puts -1\nelsif dx == 0\n puts \"#{x1+dx} #{y1} #{x1+dx} #{y1+dy}\"\nelsif dy == 0\n puts \"#{x1} #{y1+dy} #{x1+dx} #{y1+dy}\"\nelse\n puts \"#{x1} #{y1+dy} #{x1+dx} #{y1}\"\nend\n"}, {"source_code": "x1,y1,x2,y2 = gets.split.map(&:to_i)\ndx = (x2-x1)\ndy = (y2-y1)\nif dx != 0 and dy != 0 and dx != dy\n puts -1\nelsif dx == 0\n puts \"#{x1+dy} #{y1} #{x1+dy} #{y1+dy}\"\nelsif dy == 0\n puts \"#{x1} #{y1+dx} #{x1+dx} #{y1+dx}\"\nelse\n puts \"#{x1} #{y1+dx} #{x1+dx} #{y1}\"\nend\n"}, {"source_code": "x1,y1,x2,y2=gets.split.map(&:to_i)\n\nif x1==x2\n x3=x1+1\n x4=x3\n y3=y1\n y4=y2\nelsif y1==y2\n y3=y1+1\n y4=y3\n x3=x1\n x4=x2\nelse\n x3=x2\n y3=y1\n x4=x1\n y4=y2\nend\n\nputs \"#{x3} #{y3} #{x4} #{y4}\"\n\n\n"}, {"source_code": "line = gets\nx1, y1, x2, y2 = line.split.map(&:to_i)\nif y1 == y2\n\tl = (x1 - x2).abs\n\ty3 = y1 + l\n\tx3 = x1\n\ty4 = y2 + l\n\tx4 = x2 \n\tputs [x3, y3, x4, y4].join \" \"\nelsif x1 == x2\n\tl = (y1 - y2).abs\n\tx3 = x1 + l\n\ty3 = y1\n\tx4 = x2 + l\n\ty4 = y2\n\tputs [x3, y3, x4, y4].join \" \"\nelsif (x1 - x2).abs == (y1 - y2).abs\n\tl = (x1 - x2).abs\n\tx3 = x1\n\ty3 = y1 + l\n\tx4 = x1 + l\n\ty4 = y1\n\tputs [x3, y3, x4, y4].join \" \"\nelse\n\tputs \"-1\"\nend\t\t\n\t\t\n\n"}, {"source_code": "x1, y1, x2, y2 = gets.split.map(&:to_i)\nif x1 == x2\n puts [x1 + (y2 - y1), y1, x1 + (y2 - y1), y2].join(\" \")\nelsif y1 == y2\n puts [x1, y1 + (x2 - x1), x1, y2 + (x2 - x1)].join(\" \")\nelsif (x2 - x1) == (y2 - y1) or (x2 - x1) == - (y2 - y1)\n puts [x1, y2, x2, y1].join(\" \")\nelse\n puts \"-1\"\nend\n"}], "src_uid": "71dea31e1244797f916adf5f526f776e"} {"source_code": "n = gets.to_i\nseqs = []\nn.times do |i|\n seqs << gets.strip\nend\n\nhsh = {}\n\nseqs.each do |seq|\n b = 0\n balanced = true\n seq.each_char do |c|\n if c == '('\n b += 1\n end\n if c == ')'\n b -= 1\n end\n balanced = false if b < 0\n end\n hsh[b] = (hsh[b] || 0) + 1 if balanced\n\n\n b = 0\n balanced = true\n seq.reverse.each_char do |c|\n if c == '('\n b += 1\n end\n if c == ')'\n b -= 1\n end\n balanced = false if b > 0\n end\n hsh[b] = (hsh[b] || 0) + 1 if balanced && b<0\nend\n\n# puts hsh\nans = 0\nans += (hsh[0] * hsh[0]) if hsh[0]\npos_ub = hsh.keys.select{|x| x>0}\npos_ub.each do |pub|\n nub = -1 * pub\n ans += (hsh[pub] * (hsh[nub] || 0))\nend\nputs ans", "positive_code": [{"source_code": "# http://codeforces.com/problemset/problem/990/C\n\ndef count_seq\n n = gets.to_i\n h = {}\n regular = 0\n 0.upto(n - 1) do |i|\n bs = gets.chomp\n ret = parse(bs)\n next if ret.nil?\n\n if ret == ''\n regular += 1\n elsif\n h[ret] ||= 0\n h[ret] += 1\n end\n end\n\n c = regular * regular\n # puts h.inspect\n\n h.each do |key, count|\n next if key[0] == ')'\n\n other_key = [')', key[1]]\n other_c = h[other_key]\n # puts \"other_c #{other_c}\"\n if other_c\n c += other_c * count\n end\n end\n\n c\nend\n\ndef parse(bs)\n a = []\n bs.each_char do |c|\n if a.empty? || a.last == c\n a << c\n next\n end\n\n if a.last == '('\n a.slice!(a.size - 1)\n else\n a << c\n end\n end\n\n return '' if a.empty?\n return nil if a.first != a.last\n\n return [a.first, a.size]\nend\n\nputs count_seq\n"}, {"source_code": "def left_stack(a)\n stack = []\n a.each_char do |c|\n if c == '('\n stack.push(c)\n else\n if stack.pop != '('\n return nil\n end\n end\n end\n stack\nend\n\ndef right_stack(a)\n stack = []\n a.reverse.each_char do |c|\n if c == ')'\n stack.push(c)\n else\n if stack.pop != ')'\n return nil\n end\n end\n end\n return stack\nend\n\ndef left_sign_stack(a)\n stack = left_stack(a)\n stack && stack.length\nend\n\ndef right_sign_stack(a)\n stack = right_stack(a)\n stack && stack.length\nend\n\nleft_count = Hash.new(0)\nright_count = Hash.new(0)\n\nn = gets.to_i\nn.times do\n s = gets.chomp\n left_sign = left_sign_stack(s)\n right_sign = right_sign_stack(s)\n left_count[left_sign] += 1 if left_sign\n right_count[right_sign] += 1 if right_sign\nend\n\nres = 0\nleft_count.each do |sign, cnt1|\n res += cnt1 * right_count[sign]\nend\n\nputs res\n"}], "negative_code": [{"source_code": "n = gets.to_i\nseqs = []\nn.times do |i|\n seqs << gets.strip\nend\n\nhsh = {}\n\nseqs.each do |seq|\n b = 0\n balanced = true\n seq.each_char do |c|\n if c == '('\n b += 1\n end\n if c == ')'\n b -= 1\n end\n balanced = false if b < 0\n end\n balanced = false if b > 0\n hsh[0] = (hsh[0] || 0) + 1 if balanced\n if b < 0\n hsh[b] = (hsh[b] || 0) + 1\n end\n if b > 0\n hsh[b] = (hsh[b] || 0) + 1\n end\nend\n\nans = 0\nans += (hsh[0] * hsh[0]) if hsh[0]\npos_ub = hsh.keys.select{|x| x>0}\npos_ub.each do |pub|\n nub = -1 * pub\n ans += (hsh[pub] * (hsh[nub] || 0))\nend\nputs ans"}, {"source_code": "# http://codeforces.com/problemset/problem/990/C\n\ndef count_seq\n n = gets.to_i\n h = {}\n regular = 0\n 0.upto(n - 1) do |i|\n bs = gets.chomp\n ret = parse(bs)\n next if ret.nil?\n\n if ret == ''\n regular += 1\n elsif\n h[ret] ||= 0\n h[ret] += 1\n end\n end\n\n c = regular * regular\n # puts h.inspect\n\n h.each do |key, count|\n next if key[0] == ')'\n\n other_key = ['(', key[1]]\n other_c = h[other_key]\n if other_c\n c += other_c * count\n end\n end\n\n c\nend\n\ndef parse(bs)\n a = []\n bs.each_char do |c|\n if a.empty? || a.last == c\n a << c\n next\n end\n\n if a.last == '('\n a.slice!(a.size - 1)\n else\n a << c\n end\n end\n\n return '' if a.empty?\n return nil if a.first != a.last\n\n return [a.first, a.size]\nend\n\nputs count_seq\n"}, {"source_code": "# http://codeforces.com/problemset/problem/990/C\n\ndef count_seq\n n = gets.to_i\n h = {}\n regular = 0\n 0.upto(n - 1) do |i|\n bs = gets.chomp\n ret = parse(bs)\n if ret.nil?\n regular += 1\n else\n h[ret] ||= 0\n h[ret] += 1\n end\n end\n\n c = regular * regular\n # puts h.inspect\n\n h.each do |key, count|\n next if key[0] == 'r'\n\n other_key = ['r', key[1]]\n other_c = h[other_key]\n if other_c\n c += other_c * count\n end\n end\n\n c\nend\n\ndef parse(bs)\n l = 0\n r = 0\n bs.each_char do |c|\n (c == '(') ? (l += 1) : (r += 1)\n end\n\n return nil if l == r\n\n if l > r\n ['l', l - r]\n else\n ['r', r - l]\n end\nend\n\nputs count_seq"}], "src_uid": "f5f163198fbde6a5c15c50733cfd9176"} {"source_code": "N, K = gets.split.map(&:to_i)\ngoal = gets.split.map(&:to_i)\nroad = gets.split.map(&:to_i)\nroad.concat(gets.split.map(&:to_i).reverse)\ngoal.concat(gets.split.map(&:to_i).reverse)\n\ndef index2road(i)\n i %= 2*N\n i < N ? [2, i+1] : [3, 2*N-i]\nend\ndef index2goal(i)\n i %= 2*N\n i < N ? [1, i+1] : [4, 2*N-i]\nend\n\ngoaled = []\nans = []\n(2*N).times do |i|\n if goal[i] > 0 && goal[i] == road[i]\n num = goal[i]\n ans.push([num] + index2goal(i))\n goaled[num] = true\n road[i] = 0\n end\nend\n\nif road.count(0) == 0\n puts -1\n exit\nend\n\nwhile goaled.count{|v| v} < K\n index = road.index(0)\n (index+1).upto(index+2*N-1) do |i|\n i %= 2*N\n next if road[i] == 0\n ans.push([road[i]] + index2road(i-1))\n road[(i-1) % (2*N)] = road[i]\n road[i] = 0\n end\n (2*N).times do |i|\n if goal[i] > 0 && goal[i] == road[i]\n num = goal[i]\n ans.push([num] + index2goal(i))\n goaled[num] = true\n road[i] = 0\n end\n end\nend\n\nputs ans.length\nans.each do |arr|\n puts arr.join(' ')\nend", "positive_code": [{"source_code": "n, k = gets.strip.split.map(&:to_i)\nr1 = gets.strip.split.map(&:to_i)\nr2 = gets.strip.split.map(&:to_i)\nr3 = gets.strip.split.map(&:to_i)\nr4 = gets.strip.split.map(&:to_i)\n\nif 2*n == k\n match_found = false\n 0.upto(n-1).each do |i|\n if r1[i] == r2[i]\n match_found = true\n break\n end\n end\n if !match_found\n 0.upto(n-1).each do |i|\n if r3[i] == r4[i]\n match_found = true\n break\n end\n end\n end\n if !match_found\n puts -1\n exit\n end\nend\n\nseq = []\n0.upto(n-1).each do |i|\n if r2[i]!=0 && r1[i] == r2[i]\n seq << [r2[i], 1, i+1]\n r2[i] = 0\n end\nend\n0.upto(n-1).each do |i|\n if r3[i]!=0 && r3[i] == r4[i]\n seq << [r3[i], 4, i+1]\n r3[i] = 0\n end\nend\n\nloop do\n if r2[n-1]!=0 && r2[n-1]==r1[n-1]\n seq << [r2[n-1], 1, n]\n r2[n-1] = 0\n end\n if r2[n-1]!=0 && r3[n-1]==0\n seq << [r2[n-1], 3, n]\n r3[n-1] = r2[n-1]\n r2[n-1] = 0\n end\n (n-2).downto(0).each do |i|\n if r2[i]!=0 && r2[i]==r1[i]\n seq << [r2[i], 1, i+1]\n r2[i] = 0\n end\n if r2[i]!=0 && r2[i+1]==0\n seq << [r2[i], 2, i+2]\n r2[i+1] = r2[i]\n r2[i] = 0\n end\n end\n if r3[0]!=0 && r3[0]==r4[0]\n seq << [r3[0], 4, 1]\n r3[0] = 0\n end\n if r3[0]!=0 && r2[0]==0\n seq << [r3[0], 2, 1]\n r2[0] = r3[0]\n r3[0] = 0\n end\n (1).upto(n-1).each do |i|\n if r3[i]!=0 && r3[i]==r4[i]\n seq << [r3[i], 4, i+1]\n r3[i] = 0\n end\n if r3[i]!=0 && r3[i-1]==0\n seq << [r3[i], 3, i]\n r3[i-1] = r3[i]\n r3[i] = 0\n end\n end\n break if r2.uniq == [0] && r3.uniq == [0]\nend\n\nputs seq.size\nseq.each do |s|\n puts s.join(\" \")\nend"}], "negative_code": [], "src_uid": "a8d1a78ae2093d2e0de8e4efcbf940c7"} {"source_code": "z,o = gets.split(\" \").map(&:to_i)\nif z >= o\t\n\tif o < z-1\n\t\tans = \"-1\"\n\telse\n\t\tans = \"01\" * (z-1)\n\t\tans << \"0\"\n\t\tans << \"1\" if z == o\n\tend\nelse\n\tspaces = z + 1\n\tif o > (spaces * 2)\n\t\tans = \"-1\"\n\telse\n\t\tpairs = o - spaces \n\t\trem_ones = o - pairs * 2\n\t\tarr = [\"11\"] * pairs + [\"1\"] * rem_ones\n\t\tans = arr.join(\"0\")\n\tend\nend\n\nputs ans", "positive_code": [{"source_code": "#f = File.open('test1.txt', 'r')\nf = STDIN\n\ndef gets f\n f.gets.chomp.split.map &:to_i\nend\n\nn, m = gets(f)\nres =\n if m < n - 1\n -1\n elsif m <= (n + 1) * 2 #1010101010101010101\n remainder = m - (n - 1)\n s = '0'\n (n - 1).times do\n s << '1'\n if remainder > 0\n s << '1'\n remainder -= 1\n end\n s << '0'\n end\n if remainder > 0\n s.insert 0, ('1' * [remainder, 2].min)\n remainder -= [remainder, 2].min\n end\n if remainder > 0\n s.concat ('1' * remainder)\n end\n s\n else\n -1\n end\nputs res"}, {"source_code": "n, m = gets.split.map(&:to_i)\nlen = n + m\nif n > m + 1\n p -1\n exit\nend\nif n == 0\n if m <= 2\n p \"1\" * m\n else\n p -1\n end\n exit\nend\ns = \"01\" * (n - 1) + \"0\"\nm -= (n - 1)\n\nk = [m, 2].min\nm -= k\ns = \"1\" * k + s\nk = [m, 2].min\nm -= k\ns = s + \"1\" * k\nif m > n - 1\n p -1\n exit\nend\ns = s[0, 2] + \"011\" * m + s[2 + 2 * m, s.length - (2 + 2 * m)] if m != 0\nputs s"}, {"source_code": "m,n = gets.chomp!.split.map { |e| e.to_i}\n\nif n+1 < m \n p -1\n exit\nend\n\nif (m+1)*2 < n\n p -1\n exit\nend\n\nif n == m\n n.times{printf \"10\" }\n puts \"\"\n\nelsif m == n+1\n n.times{print \"01\"}\n puts 0\nelsif (m+1)*2 == n\n m.times{printf \"110\"}\n puts \"11\"\nelsif m*2 == n\n m.times{print \"110\"}\n puts \"\"\nelse\n k = n - 1 - m\n (k).times {print \"110\"}\n (m-k).times{print \"10\"}\n puts \"1\"\nend\n"}, {"source_code": "n, m = gets.split.collect{|i| i.to_i}\nif m < n-1 or m > (n+1)*2\n puts -1\nelsif m == n-1\n puts (['0']*n).join('1')\nelsif m == n\n puts (['0']*n).join('1')+'1'\nelse\n cnt = m-n-1\n puts (['11']*cnt+['1']*(n+1-cnt)).join('0')\nend\n"}], "negative_code": [{"source_code": "n, m = gets.split.collect{|i| i.to_i}\nif m < n+1 or m > (n+1)*2\n puts -1\n exit\nend\ncnt = m-n-1\nputs (['11']*cnt+['1']*(n+1-cnt)).join('0')\n"}], "src_uid": "854c561539596722b1dbc8f99cbdca78"} {"source_code": "n = gets.chomp\narray = Array.new(n.to_i) { |i| gets.chomp}\n\n\nfound = false\narray.each do |i|\n if i[0] == 'O' && i[1] == 'O'\n i[0] = '+'\n i[1] = '+'\n found = true\n break\n elsif i[3] == 'O' && i[4] == 'O'\n i[3] = '+'\n i[4] = '+'\n found = true\n break\n end\nend\n\nif found == true\n puts 'YES'\n puts array\nelse\n puts 'NO'\nend\n", "positive_code": [{"source_code": "n = gets.to_i\na = n.times.map{gets.chomp.chars}\nans = false\na.each do |x|\n if x[0] == 'O' && x[1] == 'O'\n x[0], x[1] = '+', '+'\n ans = true\n break\n elsif x[3] == 'O' && x[4] == 'O'\n x[3], x[4] = '+', '+'\n ans = true\n break\n end\nend\nputs ans ? 'YES' : 'NO'\nputs a.map{|x| x.join('')} if ans\n"}, {"source_code": "n = gets.to_i\nf = false\na = Array.new(n, \"\")\nn.times{|i|\n x, y = gets.chomp.split('|')\n if !f && x == \"OO\"\n f = true\n a[i] += \"++\"\n else\n a[i] += x\n end\n a[i] += \"|\"\n if !f && y == \"OO\"\n f = true\n a[i] += \"++\"\n else\n a[i] += y\n end\n }\nif f\n puts \"YES\"\n puts a\nelse\n puts \"NO\"\nend"}, {"source_code": "n = gets.to_i\na = 1.upto(n).map { gets.chomp }\n\nindex = a.find_index { |s| s.include? 'OO' }\n\nif index\n puts 'YES'\n a[index].sub!('OO', '++')\n\n puts a.join(\"\\n\")\nelse\n puts 'NO'\nend\n"}, {"source_code": "n=readline.to_i \nresult = []\nfound = false\n(1..n).each do\n\tseats = readline.split('|').map{|x| x.strip}\n\tseats.each_index{ |x|\n\t\tif !found && seats[x]=='OO'\n\t\t\tseats[x]='++'\n\t\t\tfound=true \n\t\tend\n\t}\n\tresult << seats.join('|')\nend\nputs found ? 'YES' : 'NO'\nputs result if found"}, {"source_code": "n = gets.to_i\n\nf = false\nout = []\nn.times do\n s = gets.strip\n \n if !f && s[\"OO\"]\n f = true\n s[\"OO\"]=\"++\"\n end\n\n out << s\nend\nif f\n puts \"YES\",out\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.to_i\n\nf = false\nout = []\nn.times do\n l, r = gets.strip.split(\"|\")\n \n if f == false && l == \"OO\"\n l = \"++\"\n f = true\n end\n \n if f == false && r == \"OO\"\n r = \"++\"\n f = true\n end\n\n out << l + \"|\" + r\nend\nif f\n puts \"YES\",out\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.to_i\n\nf = false\nout = []\nn.times do\n s = gets.strip\n \n if !f && s.include?(\"OO\")\n f = true\n s = s.sub(\"OO\",'++')\n end\n\n out << s\nend\nif f\n puts \"YES\",out\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.to_i\n\nf = false\nout = []\nn.times do\n s = gets.strip\n \n if !f && s.include?(\"OO\")\n f = true\n s[\"OO\"]=\"++\"\n end\n\n out << s\nend\nif f\n puts \"YES\",out\nelse\n puts \"NO\"\nend\n"}, {"source_code": "#!/usr/bin/ruby\ngets;a=$<.map(&:chomp)\nif a.any?{|e|\n\tif e[0,2]=='OO'\n\t\te[0,2]='++'\n\telsif e[3,2]=='OO'\n\t\te[3,2]='++'\n\telse\n\t\tfalse\n\tend\n}\n\tputs :YES\n\tputs a\nelse\n\tputs :NO\nend"}, {"source_code": "n = gets.chomp.to_i\n\ns = \"\".tap do |out|\n n.times { out << gets }\nend\n\nreplaced = s.sub(/OO/, '++')\nif s == replaced\n puts \"NO\"\nelse\n puts \"YES\"\n puts replaced\nend\n"}, {"source_code": "n = gets.to_i\nans = 'NO'\nres = []\nn.times do\n s1, s2 = gets.chomp.split(\"|\")\n if s1 == \"OO\"\n s1 = \"++\" unless ans == 'YES'\n ans = 'YES'\n elsif s2 == \"OO\"\n s2 = \"++\" unless ans == 'YES'\n ans = 'YES'\n end\n res << [s1, s2].join(\"|\")\nend\n\nif ans == 'YES'\n puts ans\n puts res\nelse\n puts ans\nend\n"}, {"source_code": "n = gets.strip.to_i\nfirst = Array.new(n)\nsecond = Array.new(n)\nn.times do |i|\n first[i], second[i] = gets.strip.split(\"|\")\nend\nfound = false\nn.times do |i|\n if first[i] == \"OO\"\n first[i] = \"++\"\n found = true\n break\n end\n if second[i] == \"OO\"\n second[i] = \"++\"\n found = true\n break\n end\nend\nif found\n puts \"YES\"\n n.times do |i|\n print first[i]\n print \"|\"\n print second[i]\n print \"\\n\"\n end\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n=gets.to_i\ns=STDIN.read\nif s.scan(\"OO\").size>0 then\n\ts.sub!(\"OO\",\"++\")\n\tputs \"YES\",s\nelse\n\tputs \"NO\"\nend\n\n"}, {"source_code": "t = gets.chomp.to_i\nchange = true\narr = []\nt.times.each do\n arr << gets.chomp\nend\narr.each do |ts|\n if ts.include?('OO') and change\n ts.sub!('OO','++') \n change = false\n end\nend\n\nif change\n puts \"NO\"\nelse\n puts \"YES\"\n arr.each do |rr|\n puts rr\n end\nend"}, {"source_code": "n = gets.to_i\ns = []\nn.times do |i|\n\ts[i] = gets.chomp\nend\nx = false\nfor i in 0...n\n\tif x == false\n\t\tif s[i][0...2] == 'OO'\n\t\t\ts[i][0...2] = '++'\n\t\t\tx = true\n\t\telsif s[i][3...5] == 'OO'\n\t\t\ts[i][3...5] = '++'\n\t\t\tx = true\n\t\tend\n\n\tend\nend\nif x == false\n\tputs 'NO'\nelse\n\tputs 'YES'\n\t0.upto(n-1) do |i|\n\t\tputs s[i]\n\tend\nend\n"}, {"source_code": "s = ''\n(1..gets.chomp.to_i).each do\n s << gets.chomp << '#'\nend\nbegin\n s[/OO/] = '++'\n puts 'YES'\n s.split('#').each { |q| puts q }\nrescue\n puts 'NO'\nend"}, {"source_code": "def answer(a, b, lines)\n puts \"YES\"\n for i in 0..(lines.length-1) do\n if (i == a)\n if (b == 0)\n print \"++|\" + lines[i][1] + \"\\n\"\n else\n print lines[i][0] + \"|++\\n\"\n end\n else\n print lines[i][0] + \"|\" + lines[i][1] + \"\\n\"\n end\n end\nend\n\nn = gets.strip.to_i\nlines = []\nn.times do\n input = gets.strip\n lines << [input[0..1], input[3..4]]\nend\nfound = false\nfor i in 0..(lines.length-1) do\n if (lines[i][0] == \"OO\") \n answer(i, 0, lines)\n found = true\n break\n end\n if (lines[i][1] == \"OO\")\n answer(i, 1, lines)\n found = true\n break\n end\nend\nif not found\n puts \"NO\"\nend\n\n"}, {"source_code": "gets\ns=$<.read\nres=s.sub \"OO\", \"++\"\nif res!=s\n puts \"YES\"\n puts res\nelse\n puts \"NO\"\nend"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nrows = []\nn.times {\n rows << gets.chomp.split(\"|\")\n}\nfound = false\nfor i in 0...n\n if rows[i][0] == \"OO\"\n found = true\n rows[i][0] = \"++\"\n break\n end\n\n if rows[i][1] == \"OO\"\n found = true\n rows[i][1] = \"++\"\n break\n end\nend\n\nif found\n puts \"YES\"\n for row in rows\n puts row.join(\"|\")\n end\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = Integer(gets.chomp)\nbus = Array.new(n)\nfor i in 0...n\n bus[i] = gets.chomp.split(\"\")\nend\n\ncan_seat_together = false\n\nfor i in 0...n\n if bus[i][0] == \"O\" && bus[i][1] == \"O\"\n can_seat_together = true\n bus[i][0] = \"+\"\n bus[i][1] = \"+\"\n break\n elsif bus[i][3] == \"O\" && bus[i][4] == \"O\"\n can_seat_together = true\n bus[i][3] = \"+\"\n bus[i][4] = \"+\"\n break\n end\nend\n\nif can_seat_together\n puts \" YES\"\n for i in 0...n\n print bus[i].join\n puts\n end\nelse\n puts \"NO\"\nend\n "}, {"source_code": "rows = gets.chomp.to_i\nseats = []\nfor i in (0..rows-1)\n\tseats[i] = gets.chomp\nend\n\nhas_seat = -1\nfor i in (0..rows-1)\n\tsplit = seats[i].split(\"\")\n\tfor x in (0..split.size-1)\n\t\tif split[x] == \"O\" && split[x+1] == \"O\"\n\t\t\tsplit[x] = \"+\"\n\t\t\tsplit[x+1] = \"+\"\n\t\t\tputs \"YES\"\n\t\t\tnew_seats = []\n\t\t\tfor a in (0..4)\n\t\t\t\tnew_seats << split[a]\n\t\t\tend\n\t\t\thas_seat = i\n\t\t\tbreak\n\t\tend\n\tend\n\tif has_seat != -1\n\t\tbreak\n\tend\nend\n\nif has_seat != -1\n\tfor i in (0..has_seat)\n\t\tif i < has_seat\n\t\t\tputs seats[i]\n\t\telse\n\t\t\tfor x in (0..4)\n\t\t\t\tif x == 4\n\t\t\t\t\tputs new_seats[x]\n\t\t\t\telse\n\t\t\t\t\tprint new_seats[x]\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\tfor i in (has_seat+1..rows-1)\n\t\tputs seats[i]\n\tend\nelse\n\tputs \"NO\"\nend"}, {"source_code": "require 'pp'\nrows = gets.chomp.to_i\nrow = []\nfact = \"NO\"\nrows.times do |i|\n\n row << gets.chomp.to_s\n values = row[-1].split('|')\n if values.include?(\"OO\") && fact == \"NO\"\n \tfact = \"YES\"\n \trow[-1].sub!(\"OO\", \"++\") \n end\n end \t\n puts fact\n puts row if fact == \"YES\"\n "}, {"source_code": "d = gets.to_i.times.map{|x| gets.strip.split(\"|\")}\nans = false\nlist = []\nd.each do |x| \n if ans == false && x.include?(\"OO\")\n if x[0] == \"OO\"\n list.push(['++', x[1]])\n else\n list.push([x[0],'++'])\n end\n ans = true\n else\n list.push(x)\n end\nend\nputs (ans)? 'YES' : 'NO' \nif ans\n list.each{|x| puts x.join('|')}\nend"}], "negative_code": [{"source_code": "n = gets.to_i\n\nf = false\nout = []\nn.times do\n s = gets.strip\n \n if s.include?(\"OO\")\n f = true\n s = s.sub(\"OO\",'++')\n end\n\n out << s\nend\nif f\n puts \"YES\",out\nelse\n puts \"NO\"\nend\n"}, {"source_code": "n = gets.to_i\ns = []\nn.times do |i|\n\ts[i] = gets.chomp\nend\nx = false\nfor i in 0...5\n\tif x == false\n\t\tif s[i][0...2] == 'OO'\n\t\t\ts[i][0...2] = '++'\n\t\t\tx = true\n\t\telsif s[i][3...5] == 'OO'\n\t\t\ts[i][3...5] = '++'\n\t\t\tx = true\n\t\tend\n\n\tend\nend\nif x == false\n\tputs 'NO'\nelse\n\tputs 'YES'\n\t0.upto(4) do |i|\n\t\tputs s[i]\n\tend\nend\n"}, {"source_code": "s = ''\n(1..gets.chomp.to_i).each do\n s << gets.chomp << '#'\nend\nbegin\n s[/OO/] = '++'\n s.split('#').each { |q| puts q }\nrescue\n puts 'NO'\nend"}, {"source_code": "require 'pp'\nrows = gets.chomp.to_i\nrow = []\nfact = \"NO\"\nrows.times do |i|\n\n row << gets.chomp.to_s\n values = row[-1].split('|')\n if values.include?(\"OO\") && fact == \"NO\"\n \tfact = \"YES\"\n \trow[-1].sub!(\"OO\", \"++\") \n end\n end \t\n puts fact\n puts row"}, {"source_code": "d = gets.to_i.times.map{|x| gets.strip.split(\"|\")}\nans = false\nlist = []\nd.each do |x| \n if ans == false && x.include?(\"OO\")\n if x[0] == \"00\"\n list.push(['++', x[1]])\n else\n list.push([x[0],'++'])\n end\n ans = true\n else\n list.push(x)\n end\nend\nputs (ans)? 'YES' : 'NO' \nlist.each{|x| puts x.join('|')}"}, {"source_code": "d = gets.to_i.times.map{|x| gets.strip.split(\"|\")}\nans = false\nlist = []\nd.each do |x| \n if ans == false && x.include?(\"OO\")\n if x[0] == \"OO\"\n list.push(['++', x[1]])\n else\n list.push([x[0],'++'])\n end\n ans = true\n else\n list.push(x)\n end\nend\nputs (ans)? 'YES' : 'NO' \nlist.each{|x| puts x.join('|')}"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.chomp.chars}\nans = false\na.each do |x|\n if x[0] == 'O' && x[1] == 'O'\n x[0], x[1] = '-', '-'\n ans = true\n break\n elsif x[3] == 'O' && x[4] == 'O'\n x[3], x[4] = '-', '-'\n ans = true\n break\n end\nend\nputs ans ? 'YES' : 'NO'\nputs a.map{|x| x.join('')} if ans\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.chomp.chars}\nans = false\na.each do |x|\n if x[0] == 'O' && x[1] == 'O'\n x[0], x[1] = '-', '-'\n ans = true\n break\n elsif x[3] == 'O' && x[4] == 'O'\n x[3], x[4] = '+', '+'\n ans = true\n break\n end\nend\nputs ans ? 'YES' : 'NO'\nputs a.map{|x| x.join('')} if ans\n"}], "src_uid": "e77787168e1c87b653ce1f762888ac57"} {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i).sort\np a[~-n/2]", "positive_code": [{"source_code": "n = gets.to_i\narr = gets.split.map(&:to_i)\narr.sort!\n\nputs arr.size.even? ? arr[n/2 - 1] : arr[n/2]"}], "negative_code": [{"source_code": "n = gets.to_i\narr = gets.split.map(&:to_i)\n\nputs arr.size.even? ? arr[n/2 - 1] : arr[n/2]"}], "src_uid": "fa9cc3ba103ed1f940c9e80a7ea75f72"} {"source_code": "test_cases = gets.chomp.to_i\r\nfor i in 1..test_cases do\r\n line = gets.chomp.split(\" \")\r\n n = line[0].to_i\r\n k = line[1].to_i\r\n if k <= (n - 1) / 2\r\n a = Array.new(n, -1)\r\n for j in 1..k do\r\n a[2 * j - 1] = n + 1 - j\r\n end\r\n x = k + 1\r\n for j in 0..n - 1 do\r\n if a[j] == -1\r\n a[j] = n + 1 - x\r\n x += 1\r\n end\r\n end\r\n for j in 0..n - 1 do\r\n print \"#{a[j]} \"\r\n end\r\n puts \"\"\r\n else\r\n puts -1\r\n end\r\nend", "positive_code": [{"source_code": "t = gets.to_s.to_i\n\n1.upto(t) do |casenum|\n n, k = gets.to_s.split.map {|x| x.to_i }\n a = (1 .. n).to_a\n swap_pos = a.size - 1\n while k > 0 && swap_pos > 1\n a[swap_pos], a[swap_pos - 1] = a[swap_pos - 1], a[swap_pos]\n k -= 1\n swap_pos -= 2\n end\n\n if k > 0\n printf(\"-1\\n\")\n else\n printf(\"%s\\n\", a.join(\" \"))\n end\nend\n\n"}, {"source_code": "def array_peaks(n, k)\r\n # n is size of output array\r\n # k is number of peaks required\r\n\r\n # if even max possible peaks is (n - 2) / 2\r\n # if odd max possible peaks is (n - 1) / 2\r\n if (n % 2) == 0\r\n if k > (n-2)/2\r\n puts -1\r\n return\r\n end\r\n else\r\n if k > (n-1)/2\r\n puts -1\r\n return\r\n end\r\n end\r\n\r\n a = (1..n).to_a\r\n o = []\r\n peaks = 0\r\n asc = true\r\n\r\n while(a.size > 0) do\r\n if peaks < k\r\n if asc\r\n o << a.shift\r\n asc = false\r\n else\r\n o << a.pop\r\n asc = true\r\n peaks += 1\r\n end\r\n else\r\n o << a.pop\r\n end\r\n end\r\n\r\n puts o.join(\" \")\r\nend\r\n\r\nnum_input = gets.chomp\r\nnum_input.to_i.times do\r\n args = gets.chomp.split(' ').map(&:to_i)\r\n array_peaks(*args)\r\nend"}], "negative_code": [], "src_uid": "b4bb11ea4650ead54026453ea9a76f39"} {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nif a==1\nputs \"0\"\nelse \nmax=b[0].to_i\nmin=b[0].to_i\namz=0\n1.upto(a-1) do |i|\nif b[i].to_i>max\nmax=b[i].to_i\namz+=1\nelsif b[i].to_i x } or l[0...i].all? { |y| y < x }) }\nputs c"}, {"source_code": "n = gets.to_i\nm = gets.split.collect &:to_i\n\nmin_rec = m[0]\nmax_rec = m[0]\nasr = 0\ni = 0\n\nwhile i < n do\n if (min_rec > m[i])\n begin\n min_rec = m[i]\n asr += 1\n end\n end\n if (max_rec < m[i])\n begin\n max_rec = m[i]\n asr += 1\n end\n end\n i += 1\nend\nputs asr\n\n\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nif a==1\nputs \"0\"\nelse \nmax=b[0].to_i\nmin=b[0].to_i\namz=0\n1.upto(a-1) do |i|\nif b[i].to_i>max\nmax=b[i].to_i\namz+=1\nelsif b[i].to_i max)\n \tmax = s\n \tcount += 1\n end\nend\nputs count"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\n\nx = a.shift\nresult = a.inject({min: x, max: x, result: 0}) do |hash, i|\n r = hash[:result] + ((ihash[:max]) ? 1 : 0)\n { min: [hash[:min], i].min, max: [hash[:max], i].max, result: r }\nend\n\nputs result[:result]\n"}, {"source_code": "gets\n\nscores = gets.split.map(&:to_i)\n\n\nmin = max = scores[0]\n\namazing = 0\n\nscores.each do |score|\n if score < min\n min = score\n amazing += 1\n elsif score > max\n max = score\n amazing += 1\n end\nend\n\nputs amazing\n"}, {"source_code": "gets\n\nscores = gets.split.map(&:to_i)\n\n\nmin = max = scores[0]\n\namazing = 0\n\nscores.each do |score|\n if score < min\n min = score\n amazing += 1\n elsif score > max\n max = score\n amazing += 1\n end\nend\n\nputs amazing\n"}, {"source_code": "gets\nwhile 1 do\n gets and $a = $_.chomp.split(\" \")\n $_ and $max = $min = $a.shift.to_i\n $_ and $sum = 0\n $a.empty? and break\n $p = $a.shift.to_i\n $p > $max and $max = $p and $sum+=1\n $p < $min and $min = $p and $sum+=1\nend\nputs $sum"}, {"source_code": "n=gets.to_i\na=0\nb=gets.split.map(&:to_i)\nmin=max=b.first\nb.each{|c|\n\tif c>max\n\t\ta+=1\n\t\tmax=c\n\tend\n\tif c i\n (max = i; c += 1) if max < i\nend\n\nprint c"}, {"source_code": "#!ruby\n\nn = gets.to_i\n\na = gets.split.map{|e|e.to_i}\n\nmax = min = a.shift\n\ncount = 0\n\na.each do |e|\n if e < min\n count += 1\n min = e\n elsif e > max\n count += 1\n max = e\n end\nend\n\nputs count\n"}, {"source_code": "n = gets.to_i\nar = gets.split(' ',n).map(&:to_i)\nmin, max, record = ar[0], ar[0], 0\nar[1..-1].each do |x|\n record += 1 if xmax\n min, max = [min, max, x].minmax\nend\nputs record"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nans = -2\nmx = -1e50\nmi = -mx\na.each do |x|\n if x > mx\n mx = x\n ans += 1\n end\n if x < mi\n mi = x\n ans += 1\n end\nend\np ans\n"}, {"source_code": "n = gets.to_i\n\nres = gets.split.map{|i| i.to_i}\n\nmax = res[0]\nmin = res[0]\nresult = 0\ni = 1\nwhile i < res.size do \n if res[i] > max then\n max = res[i]\n result += 1\n else\n if res[i] < min then\n min = res[i]\n result += 1\n end\n end\n i += 1\nend\n\nputs result"}, {"source_code": "gets\na = []\ngets.split.map(&:to_i).each do |b|\n a << b if a.empty? || b < a.min || b > a.max\nend\np a.size - 1\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\narr=[a[0]]\nans=0\n1.upto(a.length-1){|i|\n ans+=1 if arr.min>a[i]||arr.max a[i]\n cnt += 1\n min = a[i]\n end\n if max < a[i]\n cnt += 1\n max = a[i]\n end\nend\nputs cnt"}, {"source_code": "\ufeffn = gets.chomp.to_i\npoints = gets.chomp.split(\" \").map{|e| e.to_i}\n\npast = []\npast << points[0]\nc = 0\n(1..n-1).each do |i|\n if points[i] > past.max\n c += 1\n elsif points[i] < past.min\n c += 1\n end\n past << points[i]\nend\n\nputs c\n"}, {"source_code": "def count(a)\n tot_amazing = 0\n # The first content is the max and the min number of points\n min = a.shift\n max = min\n a.each do |p|\n if p < min\n min = p\n tot_amazing += 1\n elsif p > max\n max = p\n tot_amazing += 1\n end\n end\n tot_amazing\nend\n\nn = gets.to_i\na = gets.split(/\\s/).map(&:to_i)\n\nputs count(a)"}, {"source_code": "n = STDIN.readline.to_i\nscores = STDIN.readline.split.map {|s| s.to_i }\nmin, max = scores[0], scores[0]\ncount = 0\nscores[1..-1].each do |score|\n if score < min\n count += 1\n min = score\n end\n if score > max\n count += 1\n max = score\n end\nend\nputs count\n"}, {"source_code": "def i_arr(arr)\n\tfor i in 0...arr.length\n\t\tarr[i] = arr[i].to_i\n\tend\n\treturn arr\nend\n\nn = gets.to_i\narr = i_arr(gets.chomp.split)\nmin = arr[0]\nmax = arr[0]\nt = 0\n\nfor i in 1...n\n\ta = arr[i]\n\tif a > max\n\t\tmax = a\n\t\tt += 1\n\telsif a < min\n\t\tmin = a\n\t\tt += 1\n\tend\nend\n\nputs t"}, {"source_code": "n = STDIN.gets.chomp.to_i\nscores = STDIN.gets.chomp.split(/ /).take(n).map(&:to_i)\n\namazings = 0\nmin = 100000\nmax = -1\nscores.each_with_index do |score, i|\n if score < min\n min = score \n amazings += 1 unless i == 0\n end\n if score > max\n max = score \n amazings += 1 unless i == 0\n end\nend\np amazings\n"}, {"source_code": "n=gets.chomp.to_i\na=gets.chomp.split(' ').map(&:to_i)\nb=[a[0]]\ni=1\ncount=0\nwhile ib.max\n\t\t#puts \"YAY!\"\n\t\tcount+=1\n\tend\n\tb.push(a[i])\n\ti+=1\nend\nputs count\n"}, {"source_code": "n = gets.to_i\na = gets.strip.split.map(&:to_i)\nmax = a[0]\nmin = a[0]\nk = 0\n(1...n).each do |i|\n if a[i] > max\n k+=1\n max = a[i]\n end\n if a[i] < min\n k+=1\n min = a[i]\n end\nend\nputs k"}, {"source_code": "l = STDIN.read.split(\"\\n\")\nn = l[0].to_i\nmarks = l[1].split(\" \").map(&:to_i)\nn_i = 0\nmin = max = marks[0]\n\nfor i in 1..(n-1)\n if (min > marks[i])\n \tn_i += 1\n \tmin = marks[i]\n elsif (max < marks[i])\n \tn_i+= 1\n \tmax = marks[i]\n end\nend\n\nputs n_i"}, {"source_code": "n = gets.to_i\na = gets.split(\" \").map &:to_i\n\nmax = a[0]\nmin = a[0]\nk = 0\n\na.each do |x|\n if x > max\n k+=1\n max = x\n end\n\n if x < min\n k+=1\n min = x\n end\nend\n\nputs k"}, {"source_code": "\n \n n = gets.to_i\n a = gets.split.map(&:to_i)\n \n counter = 0\n min,max = a[0],a[0]\n for i in 1..n-1\n if a[i]>max\n max = a[i]\n counter+=1\n elsif a[i] < min \n min = a[i]\n counter+=1\n end\n end\n puts counter\n"}, {"source_code": "def Floodico(n,a)\n \n counter = 0\n min,max = a[0],a[0]\n for i in 1..n-1\n if a[i]>max\n max = a[i]\n counter+=1\n elsif a[i] < min \n min = a[i]\n counter+=1\n end\n end\n puts counter\n\nend\nFloodico(gets.to_i,gets.split.map(&:to_i)) "}, {"source_code": "n = $stdin.readline.to_i\nf = $stdin.readline.split.map(&:to_i)\n\nmax_count = 0\nmin_count = 0\nmax = f.first\nmin = f.first\n\nfor i in 1...f.count\n elem = f[i]\n if elem > max\n max_count+=1\n max = elem\n end\n if elem < min\n min_count+=1\n min = elem\n end\nend\n\nputs min_count + max_count"}, {"source_code": "#!/usr/bin/ruby\ndef read_int; gets.chomp.to_i; end\ndef read_ints; gets.chomp.split.map(&:to_i); end\n\nn = read_int\narr = read_ints\n\nfirst = arr.shift\nmin = first\nmax = first\ncount = 0\narr.each do |i|\n if i < min\n min = i\n count += 1\n elsif i > max\n max = i\n count += 1\n end\nend\n\nputs count\n"}, {"source_code": "gets\narr = gets.split.map &:to_i\nmax, min = arr.first, arr.first\nk = 0\narr.shift\narr.each do |p|\n if p > max \n max = p\n k += 1\n elsif p < min\n min = p\n k += 1\n end\nend\nputs k\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.split.map(&:to_i)\nbig = arr[0]\nsmall = arr[0]\narr.shift\nres = 0\narr.each do |num|\n if num > big\n big = num\n res+=1\n elsif num < small\n small = num\n res+=1\n end\nend\nputs res"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nif a==1\nputs \"0\"\nelse \nmax=b[0].to_i\nmin=b[0].to_i\namz=0\n1.upto(a-1) do |i|\nif b[i].to_i>max\nmax=b[i].to_i\namz+=1\nelsif b[i].to_i highest\n ans += 1\n highest = as[i]\n end\nend\n\nputs ans\n"}, {"source_code": "n = gets.strip.to_i\nscores = gets.strip.split.map(&:to_i)\nmin_score = max_score = scores[0]\nans = 0\n(1...n).each do |i|\n if scores[i] < min_score\n min_score = scores[i]\n ans += 1\n end\n if scores[i] > max_score\n max_score = scores[i]\n ans += 1\n end\nend\nputs ans\n"}, {"source_code": "gets\nx=gets.split.map{|e| e.to_i}\nans=0\nmin1=x[0]\nmax1=x[0]\nx.shift\nwhile !x.empty?\n\tt=x[0]\n\tif min1>t then\n\t\tmin1=t\n\t\tans=ans+1\n\tend\n\tif max1max||b[x]max\n if x==0\n min=b[x];max=b[x] \n end\n}\nputs c\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\n\nm = a[0]\npr = a[0]\nc = 0\n\na.each do |e|\n if e > pr\n c += 1\n pr = e\n elsif e < m\n c += 1\n m = e\n end\nend\n\np c\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nm,l,c = a[0],a[0],0\nfor i in a \n\tif i > m\n\t\tc += 1\n\t\tm = i\n\telsif i < l\n\t\tc += 1\n\t\tl = i\n\tend\t\t\nend\nputs c"}, {"source_code": "ans=0\nn=gets.to_i\na=gets.split.collect {|i|i.to_i}\nmin=max=a[0]\n1.upto(n-1){|i|\n\tif (a[i] > max) then\n\t\tmax=a[i]\n\t\tans+=1\n\telsif (a[i] < min) then\n\t\tmin=a[i]\n\t\tans+=1\n\tend}\np ans\n"}, {"source_code": "n = gets.to_i\nq = gets.chomp.split.map { |x| x.to_i }\n\nmin = q[0]\nmax = q[0]\nwow = 0\n\nfor i in 1...n\n if q[i] > max\n max = q[i]\n wow +=1\n elsif q[i] < min\n min = q[i]\n wow +=1\n end\nend\np wow"}, {"source_code": "n = gets.to_i\n\na = gets.split.map(&:to_i)\nb=[a[0]]\nans = a[1...a.size].count do |x|\n ret = (x > b.max or x < b.min)\n b << x\n ret\nend\n\nputs ans"}, {"source_code": "# http://codeforces.com/problemset/problem/155/A\n\ncount = gets.chomp.to_i\nscores = gets.chomp.split.map { |e| e.to_i }\n\ntmp_scores = []\nfirst = true\n\namazing = 0\n\nscores.each do |score|\n if first\n first = false\n tmp_scores << score\n else\n if score > tmp_scores.max or score < tmp_scores.min\n amazing += 1\n tmp_scores << score\n end\n end\nend\n\nputs \"#{amazing}\""}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\nmax, min = a[0], a[0]\nk = 0\nfor i in 1...n\n if a[i] > max\n k += 1\n max = a[i]\n end\n if a[i] < min\n k += 1\n min = a[i]\n end\nend\nputs k"}, {"source_code": "number = gets.chomp.to_i\nn = gets.chomp\ncontests = n.split\n\nmaxm = contests[0].to_i\nminm = contests[0].to_i\ncount = 0\nfor i in (1..number-1) # i = subject\n\tx = i\n\twhile x != 0 # x = compare to\n\t\tif contests[i].to_i > maxm\n\t\t\tmaxm = contests[i].to_i\n\t\t\tcount += 1\n\t\telsif contests[i].to_i < minm\n\t\t\tminm = contests[i].to_i\n\t\t\tcount += 1\n\t\tend\n\t\tx -= 1\n\tend\nend\n\nprint count"}, {"source_code": "contests = gets.to_i\npoints = gets.chomp.split(' ').map { |e| e.to_i }\namazing, max, min = 0, points[0], points[0]\n(0...contests).each do |i|\n if points[i] > max\n amazing += 1\n max = points[i]\n end\n if points[i] < min\n amazing += 1\n min = points[i]\n end\nend\nputs amazing"}], "negative_code": [{"source_code": "\ufeffn = gets.chomp.to_i\npoints = gets.chomp.split(\" \").map{|e| e.to_i}\n\npast = []\npast << points[0]\nc = 0\n(1..n-1).each do |i|\n if points[i] > past.max\n c += 1\n elsif points[i] < past.min\n c += 1\n end\nend\n\nputs c\n"}, {"source_code": "def Floodico(n,a)\n \n counter = 0\n min,max = a[0],a[0]\n for i in 1..n-1\n if a[i]>max\n max = a[i]\n counter+=1\n elsif a[i] < min \n min = a[i]\n counter+=1\n end\n end\n return counter\n\nend\nFloodico(gets.to_i,gets.split.map(&:to_i)) "}, {"source_code": "gets\nx=gets.split.map{|e| e.to_i}\nans=0\ns=x[0]\nx.shift\nwhile !x.empty?\n\tans=ans+1 if x[0]>s\n\ts=x[0]\n\tx.shift\nend\nputs ans"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(' ')\nb.length.times {|x| b[x]=b[x].to_i}\nc=0;min=0;max=0\nb.length.times { |x|\n c+=1 if x!=0&&(b[x]>max||b[x] m[i])\n begin\n min_rec = m[i]\n asr += 1\n end\n end\n if (max_rec < m[i])\n begin\n max_rec = m[i]\n asr += 1\n end\n end\n i += 1\n end\n puts asr\nend\n\n"}], "src_uid": "a61b96d4913b419f5715a53916c1ae93"} {"source_code": "# Here your code !\n\nN, P_ = gets.split.map(&:to_i)\nP__ = P_-1\nstr = gets.chomp\nif P__>= N/2\n str.reverse!\n P = N - (P__+1)\nelse\n P = P__\nend\n\ndef orddiff(c1, c2)\n if(c1.ord > c2.ord)\n c1, c2 = c2, c1\n end\n d = c2.ord - c1.ord\n if d>13\n d = 26 - d\n end\n return d\nend\n\ncount = 0\nrightmax = 0\n(P...N/2).each{|p|\n if str[p] != str[N-p-1] then\n rightmax = p - P\n count += orddiff(str[p], str[N-p-1])\n end\n}\nleftmax = 0\n(P-1).downto(0).each{|p|\n if str[p] != str[N-p-1] then\n leftmax = P-p\n count += orddiff(str[p], str[N-p-1])\n end\n}\n# puts \"P=#{P} leftmax=#{leftmax}, rightmax=#{rightmax}, count=#{count}\"\n\nif leftmax == 0\n count += rightmax\nelsif rightmax == 0\n count += leftmax\nelsif leftmax < rightmax\n count += leftmax*2 + rightmax\nelse\n count += rightmax*2 + leftmax\nend\nputs count\n\n", "positive_code": [{"source_code": "cost = {}\n('a'..'z').each {|x| cost[x] = {} }\n('a'..'z').each do |x|\n\tdiff = -1\n\t(x..'z').each do |y|\n\t\tdiff += 1\n\t\tcost[x][y] = cost[y][x] = [diff, 26-diff].min\n\tend\nend\n\nn, p = STDIN.readline.split.map {|s| s.to_i }\ns = ' '+STDIN.readline.strip\ncenter = (n+1)/2\nif p > center\n\tp = n-p+1\nend\nq = n-p+1\n\nleft_correction, left_span = 0, 0\n(p-1).downto(1) do |i|\n\ta, b = s[i], s[n-i+1]\n\tif a != b\n\t\tleft_correction += cost[a][b]\n\t\tleft_span = p-i\n\tend\nend\nright_correction, right_span = 0, 0\n(p+1).upto(center) do |i|\n\ta, b = s[i], s[n-i+1]\n\tif a != b\n\t\tright_correction += cost[a][b]\n\t\tright_span = i-p\n\tend\nend\n\ntotal = cost[s[p]][s[q]]\n#puts 'total so far = %d' % total\n#puts 'left_correction = %d, left_span = %d' % [left_correction, left_span]\n#puts 'right_correction = %d, right_span = %d' % [right_correction, right_span]\ntotal += left_correction + right_correction\ntotal += left_span + right_span\ntotal += [left_span, right_span].min\nputs total\n"}, {"source_code": "n,pos = gets.split(\" \").map(&:to_i)\narr = gets.chomp\nmid = (n+1) / 2\nunless pos <= mid\n\tpos = n - pos + 1\n\tarr.reverse!\nend\nc = 0\nlast_ind = pos - 1\n((pos - 1)...mid).each do |i|\n\tif arr[i] != arr[n - i - 1]\n\t\ta = arr[i].ord \n\t\tb = arr[n - i - 1].ord\n\t\tval = []\n\t\tif a < b\n\t\t\tval << b - a \n\t\t\tval << a - b + 26\n\t\telse\n\t\t\tval << a - b\n\t\t\tval << b - a + 26\n\t\tend\n\t\tc += val.min\n\t\tlast_ind = i\n\tend\nend\n\nfirst_ind = nil\n(0...(pos-1)).each do |i|\n\tif arr[i] != arr[n - i - 1]\n\t\ta = arr[i].ord \n\t\tb = arr[n - i - 1].ord\n\t\tval = []\n\t\tif a < b\n\t\t\tval << b - a \n\t\t\tval << a - b + 26\n\t\telse\n\t\t\tval << a - b\n\t\t\tval << b - a + 26\n\t\tend\n\t\tc += val.min\n\t\tfirst_ind = i unless first_ind\n\tend\nend\n# puts \"#{first_ind} #{pos-1} #{last_ind} #{c}\"\nunless first_ind\n\tc += last_ind - (pos - 1)\nelse\n\tfirst_dist = pos - 1 - first_ind\n\tlast_dist = last_ind - (pos - 1)\n\tc += first_dist + last_dist\n\tc += [first_dist,last_dist].min\nend\n\nputs c"}, {"source_code": "# Author : Fuad Ashraful Mehmet \n#Date: 18th April\n\n\n\nn,pos = gets.split(\" \").map(&:to_i)\narr = gets.chomp\nmid = (n+1) / 2\nunless pos <= mid\n\tpos = n - pos + 1\n\tarr.reverse!\nend\nc = 0\nlast_ind = pos - 1\n((pos - 1)...mid).each do |i|\n\tif arr[i] != arr[n - i - 1]\n\t\ta = arr[i].ord \n\t\tb = arr[n - i - 1].ord\n\t\tval = []\n\t\tif a < b\n\t\t\tval << b - a \n\t\t\tval << a - b + 26\n\t\telse\n\t\t\tval << a - b\n\t\t\tval << b - a + 26\n\t\tend\n\t\tc += val.min\n\t\tlast_ind = i\n\tend\nend\n \nfirst_ind = nil\n(0...(pos-1)).each do |i|\n\tif arr[i] != arr[n - i - 1]\n\t\ta = arr[i].ord \n\t\tb = arr[n - i - 1].ord\n\t\tval = []\n\t\tif a < b\n\t\t\tval << b - a \n\t\t\tval << a - b + 26\n\t\telse\n\t\t\tval << a - b\n\t\t\tval << b - a + 26\n\t\tend\n\t\tc += val.min\n\t\tfirst_ind = i unless first_ind\n\tend\nend\n\nunless first_ind\n\tc += last_ind - (pos - 1)\nelse\n\tfirst_dist = pos - 1 - first_ind\n\tlast_dist = last_ind - (pos - 1)\n\tc += first_dist + last_dist\n\tc += [first_dist,last_dist].min\nend\n \nputs c"}], "negative_code": [{"source_code": "# Here your code !\n\nN, P_ = gets.split.map(&:to_i)\nP = P_-1\nstr = gets.chomp\nif P>= N/2\n str.reverse!\n P = N - (P+1)\nend\n\ncount = 0\nrightmax = 0\n(P...N/2).each{|p|\n if str[p] != str[N-p-1] then\n rightmax = p - P\n count +=1\n end\n}\nleftmax = 0\n(P-1).downto(0).each{|p|\n if str[p] != str[N-p-1] then\n leftmax = P-p\n count +=1\n end\n}\n# puts \"P=#{P} leftmax=#{leftmax}, rightmax=#{rightmax}, count=#{count}\"\n\nif leftmax < rightmax\n count += leftmax*2 + rightmax\nelse\n count += rightmax*2 + leftmax\nend\nputs count\n\n"}, {"source_code": "# Here your code !\n\nN, P_ = gets.split.map(&:to_i)\nP__ = P_-1\nstr = gets.chomp\nif P__>= N/2\n str.reverse!\n P = N - (P__+1)\nelse\n P = P__\nend\n\ncount = 0\nrightmax = 0\n(P...N/2).each{|p|\n if str[p] != str[N-p-1] then\n rightmax = p - P\n count +=1\n end\n}\nleftmax = 0\n(P-1).downto(0).each{|p|\n if str[p] != str[N-p-1] then\n leftmax = P-p\n count +=1\n end\n}\n# puts \"P=#{P} leftmax=#{leftmax}, rightmax=#{rightmax}, count=#{count}\"\n\nif leftmax == 0\n count += rightmax\nelsif rightmax == 0\n count += leftmax\nelsif leftmax < rightmax\n count += leftmax*2 + rightmax\nelse\n count += rightmax*2 + leftmax\nend\nputs count\n\n"}, {"source_code": "# Here your code !\n\nN, P_ = gets.split.map(&:to_i)\nP__ = P_-1\nstr = gets.chomp\nif P__>= N/2\n str.reverse!\n P = N - (P__+1)\nelse\n P = P__\nend\n\ncount = 0\nrightmax = 0\n(P...N/2).each{|p|\n if str[p] != str[N-p-1] then\n rightmax = p - P\n count +=1\n end\n}\nleftmax = 0\n(P-1).downto(0).each{|p|\n if str[p] != str[N-p-1] then\n leftmax = P-p\n count +=1\n end\n}\n# puts \"P=#{P} leftmax=#{leftmax}, rightmax=#{rightmax}, count=#{count}\"\n\nif leftmax < rightmax\n count += leftmax*2 + rightmax\nelse\n count += rightmax*2 + leftmax\nend\nputs count\n\n"}, {"source_code": "n,pos = gets.split(\" \").map(&:to_i)\narr = gets.chomp\nmid = (n+1) / 2\nunless pos <= mid\n\tpos = n - pos + 1\n\tarr.reverse!\nend\nc = 0\nlast_ind = pos - 1\n((pos - 1)...mid).each do |i|\n\tif arr[i] != arr[n - i - 1]\n\t\ta = arr[i].ord \n\t\tb = arr[n - i - 1].ord\n\t\tval = []\n\t\tif a < b\n\t\t\tval << b - a \n\t\t\tval << a - b + 26\n\t\telse\n\t\t\tval << a - b\n\t\t\tval << b - a + 26\n\t\tend\n\t\tc += val.min\n\t\tlast_ind = i\n\tend\nend\n\nfirst_ind = nil\n(0...(pos-1)).each do |i|\n\tif arr[i] != arr[n - i - 1]\n\t\ta = arr[i].ord \n\t\tb = arr[n - i - 1].ord\n\t\tval = []\n\t\tif a < b\n\t\t\tval << b - a \n\t\t\tval << a - b + 26\n\t\telse\n\t\t\tval << a - b\n\t\t\tval << b - a + 26\n\t\tend\n\t\tc += val.min\n\t\tfirst_ind = i unless first_ind\n\tend\nend\nputs \"#{first_ind} #{pos-1} #{last_ind} #{c}\"\nunless first_ind\n\tc += last_ind - (pos - 1)\nelse\n\tfirst_dist = pos - 1 - first_ind\n\tlast_dist = last_ind - (pos - 1)\n\tc += first_dist + last_dist\n\tc += [first_dist,last_dist].min\nend\n\nputs c"}, {"source_code": "n,pos = gets.split(\" \").map(&:to_i)\narr = gets.chomp\nmid = (n+1) / 2\nunless pos <= mid\n\tpos = n - pos + 1\n\tarr.reverse!\nend\nc = 0\nlast_ind = pos\n((pos - 1)...mid).each do |i|\n\tif arr[i] != arr[n - i - 1]\n\t\ta = arr[i].ord \n\t\tb = arr[n - i - 1].ord\n\t\tval = []\n\t\tif a < b\n\t\t\tval << b - a \n\t\t\tval << a - b + 26\n\t\telse\n\t\t\tval << a - b\n\t\t\tval << b - a + 26\n\t\tend\n\t\tc += val.min\n\t\tlast_ind = i\n\tend\nend\n\nfirst_ind = nil\n(0...(pos-1)).each do |i|\n\tif arr[i] != arr[n - i - 1]\n\t\ta = arr[i].ord \n\t\tb = arr[n - i - 1].ord\n\t\tval = []\n\t\tif a < b\n\t\t\tval << b - a \n\t\t\tval << a - b + 26\n\t\telse\n\t\t\tval << a - b\n\t\t\tval << b - a + 26\n\t\tend\n\t\tc += val.min\n\t\tfirst_ind = i unless first_ind\n\tend\nend\n# puts \"#{first_ind} #{pos} #{last_ind} #{c}\"\nunless first_ind\n\tc += last_ind - pos - 1\t\nelse\n\tfirst_dist = pos - 1 - first_ind\n\tlast_dist = last_ind - (pos - 1)\n\tc += first_dist + last_dist\n\tc += [first_dist,last_dist].min\nend\n\nputs c"}], "src_uid": "ebacd748147b50b20d39b4d8cfde39ec"} {"source_code": "n = gets.to_i\nlight = gets.chomp\nparam = []\nrest = []\nn.times do |i|\n param << gets.split.map(&:to_i)\n rest[i] = param[i][1]\nend\n\nans = light.count(\"1\")\n200.times do |i|\n n.times do |i|\n rest[i] -= 1\n if rest[i] == 0\n rest[i] = param[i][0]\n light[i] = light[i] == \"1\" ? \"0\" : \"1\"\n end\n end\n cnt = light.count(\"1\")\n ans = cnt if cnt > ans\nend\np ans", "positive_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nrequire 'prime'\n\nn = inp[0]\nm = gets.chomp.split(\"\")\nt = []\nn.times do\n t << inp\nend\nm.size.times do |i|\n if(m[i] == \"1\")\n m[i] = true\n else\n m[i] = false\n end\nend\nans = m.count(true)\n(0..1000).each do |turn|\n t.size().times do |i|\n t[i][1] -= 1\n if(t[i][1] == 0)\n t[i][1] += t[i][0]\n m[i] = !m[i]\n end\n end\n ans = [ans,m.count(true)].max\nend\np ans"}, {"source_code": "n = gets.to_i\nlights = gets.chomp.each_char.map(&:to_i)\na = []\nb = []\nfor i in 0...n do\n a[i], b[i] = gets.split.map(&:to_i)\nend\n\nons = 0\nlights.each do |x|\n ons += x\nend\n\nmax_ons = ons\nfor t in 1..125 do\n for i in 0...n do\n if t >= b[i] && (t - b[i]) % a[i] == 0\n if lights[i] == 0\n lights[i] = 1\n ons += 1\n else\n lights[i] = 0\n ons -= 1\n end\n end\n end\n max_ons = ons if max_ons < ons\nend\nputs max_ons\n"}], "negative_code": [{"source_code": "n = gets.to_i\nlights = gets.chomp.each_char.map(&:to_i)\na = []\nb = []\nfor i in 0...n do\n a[i], b[i] = gets.split.map(&:to_i)\nend\n\nons = 0\nlights.each do |x|\n ons += x\nend\n\nmax_ons = ons\nfor t in 1..125 do\n for i in 0...n do\n if t >= b[i] && (t - b[i]) % a[i] == 0\n if lights[i] == 0\n lights[i] = 1\n ons += 1\n else\n lights[i] = 0\n ons -= 1\n end\n end\n end\n p ons\n max_ons = ons if max_ons < ons\nend\nputs max_ons\n"}, {"source_code": "n = gets.to_i\nlights = gets.chomp.each_char.map(&:to_i)\na = []\nb = []\nfor i in 0...n do\n a[i], b[i] = gets.split.map(&:to_i)\nend\n\nons = 0\nlights.each do |x|\n ons += x\nend\n\nmax_ons = ons\nfor t in 1..120 do\n for i in 0...n do\n if (t - b[i]) % a[i] == 0\n if lights[i] == 0\n lights[i] = 1\n ons += 1\n else\n lights[i] = 0\n ons -= 1\n end\n end\n end\n max_ons = ons if max_ons < ons\nend\nputs max_ons\n"}, {"source_code": "n = gets.to_i\nlights = gets.chomp.each_char.map(&:to_i)\na = []\nb = []\nfor i in 0...n do\n a[i], b[i] = gets.split.map(&:to_i)\nend\n\nons = 0\nlights.each do |x|\n ons += x\nend\n\nmax_ons = ons\nfor t in 1..(5 + 3 * 4 * 5) do\n for i in 0...n do\n if (t - b[i]) % a[i] == 0\n if lights[i] == 0\n lights[i] = 1\n ons += 1\n else\n lights[i] = 0\n ons -= 1\n end\n end\n end\n max_ons = ons if max_ons < ons\nend\nputs max_ons\n"}, {"source_code": "n = gets.to_i\nlights = gets.chomp.each_char.map(&:to_i)\na = []\nb = []\nfor i in 0...n do\n a[i], b[i] = gets.split.map(&:to_i)\nend\n\nons = 0\nlights.each do |x|\n ons += x\nend\n\nmax_ons = ons\nfor t in 1..120 do\n for i in 0...n do\n if t >= b[i] && (t - b[i]) % a[i] == 0\n if lights[i] == 0\n lights[i] = 1\n ons += 1\n else\n lights[i] = 0\n ons -= 1\n end\n end\n end\n max_ons = ons if max_ons < ons\nend\nputs max_ons\n"}], "src_uid": "2ff789ae0095bb7ff0e747b0d4df59bc"} {"source_code": "#!/usr/bin/ruby\nrequire 'prime'\nSTDOUT.sync=true\nM=100\nr=0\nPrime.each(M/2){|e|\n\tp e\n\tif gets.chomp=='yes'\n\t\tr+=1\n\t\tif e*e<=M\n\t\t\tp e*e\n\t\t\tr+=1 if gets.chomp=='yes'\n\t\tend\n\tend\n}\nputs r>1 ? :composite : :prime", "positive_code": [{"source_code": "try = [2, 3, 4, 5, 7, 9, 11, 13, 17, 19, 23, 25, 29, 31, 37, 41, 43, 47, 49, 81]\nans = []\ntry.each do |x|\n puts x\n $stdout.flush\n ans << gets.chomp\nend\nputs ans.count{|x| x == 'yes'} >= 2 ? 'composite' : 'prime'\n"}, {"source_code": "require 'prime'\n\nns = (2..100).to_a\nms = [4, 9, 25, 49]\n(2..50).each do |m|\n ms << m if m.prime?\nend\n\nms.each do |m|\n puts m\n STDOUT.flush \n s = gets.chomp\n if s == 'yes'\n ns.delete_if { |n| n % m != 0 }\n else\n ns.delete_if { |n| n % m == 0 }\n end\nend\nif ns[0].prime?\n puts 'prime'\nelse\n puts 'composite'\nend\nSTDOUT.flush\n\n"}, {"source_code": "def convert ans\n\tif ans == 'yes'\n\t\ttrue\n\telsif ans == 'no'\n\t\tfalse\n\tend\nend\n\nSTDOUT.flush\nlist = []\n\nprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 4, 9, 25, 49]\nprimes.each do |p|\n\tputs p\n\tSTDOUT.flush\n\t\n\tisYes = convert gets.chomp\n\tif isYes\n\t\tlist << p\n\tend\nend\n\nif list.length > 1\n\tputs 'composite'\n\tSTDOUT.flush\nelse\n\tputs 'prime'\n\tSTDOUT.flush\nend\n\n\n"}, {"source_code": "primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]\nsquares = [4, 9, 25, 49]\ncnt = 0\nprimes.each do |prime|\n\tputs prime\n\tSTDOUT.flush\n\tcnt += (gets.chomp == \"yes\") ? 1 : 0\nend\nsquares.each do |square|\n\tputs square\n\tSTDOUT.flush\n\tcnt += (gets.chomp == \"yes\") ? 2 : 0\nend\n\nputs cnt >= 2 ? \"composite\" : \"prime\"\n"}], "negative_code": [{"source_code": "def convert ans\n\tif ans == 'yes'\n\t\ttrue\n\telsif ans == 'no'\n\t\tfalse\n\tend\nend\n\nprimes = [97, 89, 83, 79, 73, 71, 67, 61, 59, 53]\n\nprimes.each do |p|\n\tputs p\n\tSTDOUT.flush\n\tisYes = convert gets.chomp\n\tif isYes\n\t\tputs 'prime'\n\t\tSTDOUT.flush\n\t\texit\n\tend\nend\n\nputs 2\n\nSTDOUT.flush\nisYes = convert gets.chomp\n\nif isYes\n\tdivisor = [4, 3, 5, 7, 11, 13, 17, 19, 23]\n\tlist = []\n\n\tdivisor.each do |d|\n\t\tputs d\n\n\t\tSTDOUT.flush\n\t\tisYes = convert gets.chomp\n\t\t\n\t\tif isYes\n\t\t\tlist << d\n\t\tend\n\n\t\tif list.length > 0\n\t\t\tputs 'composite'\n\t\t\tSTDOUT.flush\n\t\t\texit\n\t\tend\n\tend\nelse\n\tdivisor = [3, 5, 7, 9, 11, 13]\n\tlist = []\n\n\tdivisor.each do |d|\n\t\tputs d\n\n\t\tSTDOUT.flush\n\t\tisYes = convert gets.chomp\n\t\t\n\t\tif isYes\n\t\t\tlist << d\n\t\tend\n\n\t\tif list.length > 1\n\t\t\tputs 'composite'\n\t\t\tSTDOUT.flush\n\t\t\texit\n\t\tend\n\tend\nend\n\nputs 'prime'\nSTDOUT.flush"}, {"source_code": "def convert ans\n\tif ans == 'yes'\n\t\ttrue\n\telsif ans == 'no'\n\t\tfalse\n\tend\nend\n\nSTDOUT.flush\nprimes = [97, 89, 83, 79, 73, 71, 67, 61, 59, 53]\n\nprimes.each do |p|\n\tputs p\n\tSTDOUT.flush\n\tisYes = convert gets.chomp\n\tif isYes\n\t\tputs 'prime'\n\t\tSTDOUT.flush\n\t\texit\n\tend\nend\n\nputs 2\n\nSTDOUT.flush\nisYes = convert gets.chomp\n\nif isYes\n\tdivisor = [4, 3, 5, 7, 11, 13, 17, 19, 23]\n\tlist = []\n\n\tdivisor.each do |d|\n\t\tputs d\n\n\t\tSTDOUT.flush\n\t\tisYes = convert gets.chomp\n\t\t\n\t\tif isYes\n\t\t\tlist << d\n\t\tend\n\n\t\tif list.length > 0\n\t\t\tputs 'composite'\n\t\t\tSTDOUT.flush\n\t\t\texit\n\t\tend\n\tend\nelse\n\tdivisor = [3, 5, 7, 9, 11, 13, 17, 25, 49]\n\tlist = []\n\n\tdivisor.each do |d|\n\t\tputs d\n\n\t\tSTDOUT.flush\n\t\tisYes = convert gets.chomp\n\t\t\n\t\tif isYes\n\t\t\tlist << d\n\t\tend\n\n\t\tif list.length > 1\n\t\t\tputs 'composite'\n\t\t\tSTDOUT.flush\n\t\t\texit\n\t\tend\n\tend\nend\n\nputs 'prime'\nSTDOUT.flush"}, {"source_code": "def convert ans\n\tif ans == 'yes'\n\t\ttrue\n\telsif ans == 'no'\n\t\tfalse\n\tend\nend\n\nSTDOUT.flush\nprimes = [97, 89, 83, 79, 73, 71, 67, 61, 59, 53]\n\nprimes.each do |p|\n\tputs p\n\tSTDOUT.flush\n\tisYes = convert gets.chomp\n\tif isYes\n\t\tputs 'prime'\n\t\tSTDOUT.flush\n\t\texit\n\tend\nend\n\nputs 2\n\nSTDOUT.flush\nisYes = convert gets.chomp\n\nif isYes\n\tdivisor = [4, 3, 5, 7, 11, 13, 17, 19, 23]\n\tlist = []\n\n\tdivisor.each do |d|\n\t\tputs d\n\n\t\tSTDOUT.flush\n\t\tisYes = convert gets.chomp\n\t\t\n\t\tif isYes\n\t\t\tlist << d\n\t\tend\n\n\t\tif list.length > 0\n\t\t\tputs 'composite'\n\t\t\tSTDOUT.flush\n\t\t\texit\n\t\tend\n\tend\nelse\n\tdivisor = [3, 5, 7, 9, 11, 13, 25, 49]\n\tlist = []\n\n\tdivisor.each do |d|\n\t\tputs d\n\n\t\tSTDOUT.flush\n\t\tisYes = convert gets.chomp\n\t\t\n\t\tif isYes\n\t\t\tlist << d\n\t\tend\n\n\t\tif list.length > 1\n\t\t\tputs 'composite'\n\t\t\tSTDOUT.flush\n\t\t\texit\n\t\tend\n\tend\nend\n\nputs 'prime'\nSTDOUT.flush"}], "src_uid": "8cf479fd47050ba96d21f3d8eb43c8f0"} {"source_code": "n = gets.to_i\na = n.times.map{gets.chomp}\nans = true\nn.times do |i|\n n.times do |j|\n c = 0\n c += 1 if i != 0 && a[i - 1][j] == 'o'\n c += 1 if j != 0 && a[i][j - 1] == 'o'\n c += 1 if i != n - 1 && a[i + 1][j] == 'o'\n c += 1 if j != n - 1 && a[i][j + 1] == 'o'\n ans = false if c % 2 != 0\n end\nend\nputs ans ? \"YES\" : \"NO\"\n", "positive_code": [{"source_code": "n = gets.to_i\na = n.times.map{gets.chomp}\nans = true\nn.times do |i|\n n.times do |j|\n c = 0\n c += 1 if i != 0 && a[i - 1][j] == 'o'\n c += 1 if j != 0 && a[i][j - 1] == 'o'\n c += 1 if i != n - 1 && a[i + 1][j] == 'o'\n c += 1 if j != n - 1 && a[i][j + 1] == 'o'\n ans = false if c % 2 != 0\n end\nend\nputs ans ? \"YES\" : \"NO\""}, {"source_code": "a=gets.chomp.to_i\narray=[]\na.times do\narray<=n || y<0 || y>=n\n\t\treturn 0\n\tend\n\treturn 1 if m[y][x]==\"o\"\n\treturn 0\nend\n\nn=gets.to_i\nm=[]\nn.times{\n\ts=gets.chomp\n\tm<= 0 && arr[i][j - 1] == 'o')\n count += 1 if(i + 1 < n && arr[i + 1][j] == 'o')\n count += 1 if(i - 1 >= 0 && arr[i - 1][j] == 'o')\n \n ans = false if count.odd?\n end \nend\n\nputs (ans ? \"YES\" : \"NO\")"}, {"source_code": "n=gets.to_i\narr=['']\nfor i in 1..n\n arr[i]=gets\nend\narr[n+1]=''\nfor i in 1..n\n for j in 0..n-1\n if ((arr[i-1][j]=='o'?1:0)+(arr[i+1][j]=='o'?1:0)+(arr[i][j-1]=='o'?1:0)+(arr[i][j+1]=='o'?1:0)).odd?\n puts 'NO'\n exit\n end\n end\nend\nputs 'YES'"}, {"source_code": "n=gets.to_i\narr=[]\nfor i in 1..n\n arr[i]=gets\nend\nfor i in 1..n\n for j in 0..n-1\n cnt=0\n if i>1&&arr[i-1][j]=='o'\n cnt+=1\n end\n if i 0) && (a[i - 1][j] == 'o')\n\t\tam += 1 if (i < n - 1) && (a[i + 1][j] == 'o')\n\t\t\n\t\tam += 1 if (j > 0) && (a[i][j - 1] == 'o')\n\t\tam += 1 if (j < n - 1) && (a[i][j + 1] == 'o')\n\t\t\n\t\tif am.odd?\n\t\t\tputs \"NO\"\n\t\t\texit 0\n\t\tend\n\tend\nend\n\nputs \"YES\"\n"}, {"source_code": "class Array\n def get_element(i, j, n)\n if i >= 0 && i < n && j >= 0 && j < n\n self[i][j]\n else\n nil\n end\n end\nend\n\ndef is_good(i, j, s, n)\n t = 0\n t += 1 if s.get_element(i + 1, j, n) == 'o'\n t += 1 if s.get_element(i - 1, j, n) == 'o'\n t += 1 if s.get_element(i, j + 1, n) == 'o'\n t += 1 if s.get_element(i, j - 1, n) == 'o'\n # p [i, j, t]\n t % 2 == 0\nend\ndef main\n n = gets.to_i\n s = n.times.map{gets}\n n.times do |i|\n n.times do |j|\n # p [i, j]\n return :NO unless is_good(i, j, s, n)\n end\n end\n :YES\nend\n\nputs main"}, {"source_code": "t=gets.chomp.to_i\nboard=[]\ndef solve(board)\n len=board.size\n for i in 0...len\n \tfor j in 0...len\n \t\ts=0\n \t if i-1>=0\n s+=1 if board[i-1][j]=='o'\n \t end\t\n \t if i+1<=len-1\n \t \t s+=1 if board[i+1][j]=='o'\n \t end\n \t if j-1>=0\n \t \t s+=1 if board[i][j-1]=='o'\n \t end\n \t if j+1<=len-1\n \t \ts+=1 if board[i][j+1]=='o'\n \t end\n \t return 'NO' if s%2!=0\n \tend\n end\n return \"YES\"\nend\nfor i in 0...t\n board<= 0 && matrix[i-1]\n adj_arr << matrix[i][j+1]\n adj_arr << matrix[i][j-1] if j-1 >= 0\n # puts \"#{adj_arr}\"\n res = false and break unless adj_arr.compact.count(\"o\") % 2 == 0\n end\nend\n\n\nputs res ? \"YES\" : \"NO\""}, {"source_code": "require 'pp'\nn = gets.to_i\narray = Array.new(n)\nn.times do |i|\n array[i] = gets.strip.split //\nend\n\nresult = true\ni = j = 0\n\nSHIFT = [\n [-1, 0],\n [ 0,-1],\n [ 1, 0],\n [ 0, 1]\n]\n\nwhile i < n && result\n j = 0\n while j < n && result\n c = 0\n SHIFT.each do |(k,z)|\n k += i\n z += j\n c += 1 if k >= 0 && z >=0 && k < n && z < n && array[k][z] == 'o'\n end\n result = c%2 == 0\n j += 1\n end\n i += 1\nend\n\nputs result ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.chomp.chars}\nans = true\nn.times do |i|\n n.times do |j|\n c = 0\n c += 1 if i != 0 && a[i - 1][j] == 'o'\n c += 1 if j != 0 && a[i][j - 1] == 'o'\n c += 1 if i != n - 1 && a[i + 1][j] == 'o'\n c += 1 if j != n - 1 && a[i][j + 1] == 'o'\n if c % 2 != 0\n ans = false\n end\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.chomp.chars}\nans = true\nn.times do |i|\n break if !ans\n n.times do |j|\n c = 0\n c += 1 if i != 0 && a[i - 1][j] == 'o'\n c += 1 if j != 0 && a[i][j - 1] == 'o'\n c += 1 if i != n - 1 && a[i + 1][j] == 'o'\n c += 1 if j != n - 1 && a[i][j + 1] == 'o'\n if c % 2 != 0\n ans = false\n break\n end\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "a=gets.chomp.to_i\narray=[]\na.times do\narray<0 && arr[i-1][j]=='o')\n count+=1;\n end\n if (i0 && arr[i][j-1]=='o')\n count+=1;\n end\n if(j= 0 && k[1] >= 0 && mx[k[0]] && mx[k[0]][k[1]] == 'o' ? 1 : 0\n }.inject(:+).odd?\n puts 'NO'\n exit\n end\n }\n}\n\nputs 'YES'"}, {"source_code": "STEP_X = [0, 1, 0, -1]\nSTEP_Y = [1, 0, -1, 0]\n\nn = gets.to_i\nb = Array.new n\nn.times do |i|\n b[i] = gets\nend\nvalid = true\nn.times do |i|\n n.times do |j|\n cnt = 0\n 4.times do |k|\n tx = i + STEP_X[k]\n ty = j + STEP_Y[k]\n if 0 <= tx && tx < n then\n if 0 <= ty && ty < n then\n cnt += 1 if b[tx][ty] == 'o'\n end\n end\n end\n valid = false if cnt % 2 == 1\n end\nend\nif valid then\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "n=gets.to_i\nboard=[]\ndef solve(board)\n\tlen=board.size\n\tfor i in 0...len\n\t\tfor j in 0...len\n\t\t\ts=0\n\t\t\tif i-1>=0\n\t\t\t\ts+=1 if board[i-1][j]=='o'\n\t\t\tend\n\t\t\tif i+1<=len-1\n\t\t\t\ts+=1 if board[i+1][j]=='o'\n\t\t\tend\n\t\t\tif j-1>=0\n\t\t\t\ts+=1 if board[i][j-1]=='o'\n\t\t\tend\n\t\t\tif j+1<=len-1\n\t\t\t\ts+=1 if board[i][j+1]=='o'\n\t\t\tend\n\t\t\treturn 'NO' if s%2!=0\n\t\tend\n\tend\n\treturn \"YES\"\nend\nn.times do\n board.push(gets.chomp.split('').map(&:to_s))\nend\nputs solve(board)"}, {"source_code": "require 'pp'\n\nn = STDIN.gets.chomp.to_i\nm = []\n\nn.times do |row|\n m.push STDIN.gets.chomp.split(//)\nend\n\nn.times do |i|\n n.times do |j|\n count = 0\n count += 1 if i != 0 && m[i-1][j] == 'o'\n count += 1 if i != n-1 && m[i+1][j] == 'o'\n count += 1 if j != 0 && m[i][j-1] == 'o'\n count += 1 if j != n-1 && m[i][j+1] == 'o'\n\n if count %2 != 0\n puts \"NO\"\n exit(0)\n end\n end\nend\nputs \"YES\"\n\n"}], "negative_code": [{"source_code": "require 'pp'\n\nn = STDIN.gets.chomp.to_i\nm = []\n\nn.times do |row|\n m.push STDIN.gets.chomp.split(//)\nend\n\nn.times do |i|\n n.times do |j|\n count = 0\n count += 1 if i != 0 && m[i-1][j] == 'o'\n count += 1 if i != n-1 && m[i+1][j] == 'o'\n count += 1 if j != 0 && m[i][j-1] == 'o'\n count += 1 if j != n-1 && m[i][j+1] == 'o'\n\n if count %2 != 0\n p \"NO\"\n exit(0)\n end\n end\nend\np \"YES\"\n\n"}, {"source_code": "n = gets.to_i\narr = []\nn.times do\n arr << gets.chomp\nend\narr.each do |x|\n if x.scan(/o/).empty?\n puts \"NO\"\n exit\n end\nend\nputs \"YES\"\n"}, {"source_code": "n=gets.to_i\nok=\"YES\"\nn.times{|i|\n\ts=gets.chomp\n\tn.times{|j|\n\t\tok=\"NO\" if (i+j)%2==1 && s[j]==\"o\"\n\t}\n}\nputs ok\n\n"}, {"source_code": "n=gets.to_i\nok=\"YES\"\nn.times{|i|\n\ts=gets.chomp\n\tif i==0 || i==n-1 then\n\t\tok=\"NO\" if /.o./.match(s)\n\telse\n\t\tok=\"NO\" if /^o|o$/.match(s)\n\tend\n}\nputs ok\n\n"}, {"source_code": "n=gets.to_i\nans=\"NO\"\ns=STDIN.read.split\n\nhit=true\nn.times{|i|\n\thit=false if s[i][i]==\"x\"\n}\nans=\"YES\" if hit\n\nhit=true\nn.times{|i|\n\thit=false if s[i][n-i-1]==\"x\"\n}\nans=\"YES\" if hit\nputs ans\n\n"}, {"source_code": "n = gets.to_i\narray = Array.new(n)\nn.times do |i|\n array[i] = gets.strip.split //\nend\n\nresult = true\ni = j = 0\n\nSHIFT = [\n [-1, 0],\n [ 0,-1],\n [ 1, 0],\n [ 0, 1]\n]\n\nwhile i < n && result\n while j < n && result do\n c = 0\n SHIFT.each do |(k,z)|\n k += i; z += j\n c += 1 if k >= 0 && z >=0 && k < n && z < n && array[k][z] == 'o'\n end\n result = c%2 == 0\n j += 1\n end\n i += 1\nend\n\nputs result ? \"YES\" : \"NO\"\n"}, {"source_code": "require 'pp'\nn = gets.to_i\narray = Array.new(n)\nn.times do |i|\n array[i] = gets.strip.split //\nend\n\n\npp array\nresult = true\ni = j = 0\n\nSHIFT = [\n [-1, 0],\n [ 0,-1],\n [ 1, 0],\n [ 0, 1]\n]\n\nwhile i < n && result\n while j < n && result\n c = 0\n SHIFT.each do |(k,z)|\n k += i; z += j\n c += 1 if k >= 0 && z >=0 && k < n && z < n && array[k][z] == 'o'\n end\n result = c%2 == 0\n j += 1\n end\n i += 1\nend\n\nputs result ? \"YES\" : \"NO\"\n"}, {"source_code": "require 'pp'\nn = gets.to_i\narray = Array.new(n)\nn.times do |i|\n array[i] = gets.strip.split //\nend\n\nresult = true\ni = j = 0\n\nSHIFT = [\n [-1, 0],\n [ 0,-1],\n [ 1, 0],\n [ 0, 1]\n]\n\nwhile i < n && result\n while j < n && result\n c = 0\n SHIFT.each do |(k,z)|\n k += i; z += j\n c += 1 if k >= 0 && z >=0 && k < n && z < n && array[k][z] == 'o'\n end\n result = c%2 == 0\n j += 1\n end\n i += 1\nend\n\nputs result ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.chomp.chars}\nans = true\nn.times do |i|\n n.times do |j|\n if a[i][j] == 'x'\n c = 0\n c += 1 if i != 0 && a[i - 1][j] == 'o'\n c += 1 if j != 0 && a[i][j - 1] == 'o'\n c += 1 if i != n - 1 && a[i + 1][j] == 'o'\n c += 1 if j != n - 1 && a[i][j + 1] == 'o'\n if c % 2 != 0\n ans = false\n break\n end\n end\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.chomp.chars}\nans = true\nn.times do |i|\n n.times do |j|\n if a[i][j] == 'o'\n c = 0\n c += 1 if i != 0 && a[i - 1][j] == 'x'\n c += 1 if j != 0 && a[i][j - 1] == 'x'\n c += 1 if i != n - 1 && a[i + 1][j] == 'x'\n c += 1 if j != n - 1 && a[i][j + 1] == 'x'\n if c % 2 != 0\n ans = false\n break\n end\n end\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "(mx = (0...gets.to_i).map { |_| gets.chomp.split('') }).each_with_index { |a, i|\n a.each_with_index { |_, j|\n if [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]].map { |k| mx[k[0]] && mx[k[0]][k[1]] == 'o' ? 1 : 0 }.inject(:+).odd?\n puts 'NO'\n exit\n end\n }\n}\n\nputs 'YES'"}], "src_uid": "03fcf7402397b94edd1d1837e429185d"} {"source_code": "def factors_of_two(num)\n res = 0\n until num.odd?\n res += 1\n num /= 2\n end\n res\nend\n\ndef solve(n, num_array)\n number_of_twos = 0\n\n num_array.each do |num|\n number_of_twos += factors_of_two(num)\n return 0 if number_of_twos >= n\n end\n\n index_factors = (1..num_array.length).map { |num| factors_of_two(num) }\n index_factors.sort!\n\n indexes_modified = 0\n index_factors.reverse_each do |factors|\n number_of_twos += factors\n indexes_modified += 1\n return indexes_modified if number_of_twos >= n\n end\n\n -1\nend\n\n# code for tests:\n\nnumber_of_tests = gets.chomp.to_i\n\nnumber_of_tests.times do\n n = gets.chomp.to_i\n num_array = gets.chomp.split.map(&:to_i)\n\n puts solve(n, num_array)\nend\n", "positive_code": [{"source_code": "def max(a, b)\r\n a < b ? b : a\r\nend\r\n\r\ndef log2(n)\r\n cnt = 0\r\n while n % 2 == 0\r\n n /= 2\r\n cnt += 1\r\n end\r\n cnt\r\nend\r\n\r\nts = gets.to_i\r\nts.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n \r\n rem = max(0, n - a.sum{ |ai| log2(ai) })\r\n\r\n ans = (1..n).map{ |i| log2(i) }.sort.reverse.sum do |i|\r\n if rem != 0 && rem - i >= 0\r\n rem -= i\r\n 1\r\n else\r\n 0\r\n end\r\n end\r\n\r\n puts rem == 0 ? ans : -1\r\nend"}], "negative_code": [{"source_code": "def factors_of_two(num)\n res = 0\n until num.odd?\n res += 1\n num /= 2\n end\n res\nend\n\ndef solve(n, num_array)\n number_of_twos = 0\n\n num_array.each do |num|\n number_of_twos += factors_of_two(num)\n return 0 if number_of_twos >= n\n end\n\n index_factors = (1..num_array.length).map { |num| factors_of_two(num) }\n index_factors.sort\n\n indexes_modified = 0\n index_factors.reverse_each do |factors|\n number_of_twos += factors\n indexes_modified += 1\n return indexes_modified if number_of_twos >= n\n end\n\n -1\nend\n\n# code for tests:\n\nnumber_of_tests = gets.chomp.to_i\n\nnumber_of_tests.times do\n n = gets.chomp.to_i\n num_array = gets.chomp.split.map(&:to_i)\n\n puts solve(n, num_array)\nend\n"}, {"source_code": "def factors_of_two(num)\n res = 0\n until num.odd?\n res += 1\n num /= 2\n end\n res\nend\n\ndef solve(n, num_array)\n number_of_twos = 0\n\n num_array.each do |num|\n number_of_twos += factors_of_two(num)\n return 0 if number_of_twos >= n\n end\n\n index_factors = (1..num_array.length).map { |num| factors_of_two(num) }\n index_factors.sort\n\n indexes_modified = 0\n index_factors.reverse_each do |factors|\n number_of_twos += factors\n indexes_modified += 1\n return indexes_modified if number_of_twos >= n\n end\n\n -1\nend\n\n# # code for tests:\n\n# number_of_tests = gets.chomp.to_i\n\n# number_of_tests.times do\n# n = gets.chomp.to_i\n# num_array = gets.chomp.split.map(&:to_i)\n\n# puts solve(n, num_array)\n# end\n\np solve(2, [3, 2])\n"}, {"source_code": "def factors_of_two(num)\n res = 0\n until num.odd?\n res += 1\n num /= 2\n end\n res\nend\n\ndef solve(n, num_array)\n number_of_twos = 0\n\n num_array.each do |num|\n number_of_twos += factors_of_two(num)\n return 0 if number_of_twos >= n\n end\n\n index_factors = (1..num_array.length - 1).map { |num| factors_of_two(num) }\n index_factors.sort\n\n indexes_modified = 0\n index_factors.reverse_each do |factors|\n number_of_twos += factors\n indexes_modified += 1\n return indexes_modified if number_of_twos >= n\n end\n\n -1\nend\n\n# code for tests:\n\nnumber_of_tests = gets.chomp.to_i\n\nnumber_of_tests.times do\n n = gets.chomp.to_i\n num_array = gets.chomp.split.map(&:to_i)\n\n puts solve(n, num_array)\nend\n"}], "src_uid": "96f0df1c8e014229e5ef773789aa2205"} {"source_code": "n,k=gets.split.map(&:to_i)\na=(1..2*n).to_a\nputs a.shift,a.pop\nif !a.empty? && k>0\n puts 2+k,a.shift\n a.delete 2+k\nend\nputs a.shift,a.shift until a.empty?\n", "positive_code": [{"source_code": "n, k = gets.chomp.split.map(&:to_i)\nary = (1..2 * n).to_a\ni = 0\nk.times do\n ary[i], ary[i + 1] = ary[i + 1], ary[i]\n i += 2\nend\nputs ary.join(' ')\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = Array.new(2*n) { |i| i+1 }\n\nk.times do |i|\n a[2*i] += 1\n a[2*i+1] -= 1\nend\n\nputs a.join(' ')\n"}, {"source_code": "n,k=gets.chomp.split.map(&:to_i)\nfor i in 1..k\n\tprint \"#{2*i} #{2*i-1} \"\nend\nfor i in (k+1)..n \n\tprint \"#{2*i-1} #{2*i} \"\nend\nputs"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\narr = (1..(2 * n)).to_a\n(1..k).each do |i|\n\tl,m = 2 * i - 1,(2 * i) - 2\n\tarr[l],arr[m] = arr[m],arr[l]\nend\nputs arr.join(\" \")"}, {"source_code": "n,k = gets.split.map{ |x| x.to_i }\n\nif k == 0 then\n a = (1..n*2).to_a.reverse\nelse\n a = [1, k+1] | (1..n*2).to_a.reverse\nend\n\na.each do |x| print \"#{x} \" end and puts\n# \n# s = ms = 0\n# \n# a.each_index { |i|\n# if i%2 == 0 then\n# s += a[i] - a[i+1]\n# ms += (a[i]-a[i+1]).abs\n# end\n# }\n# \n# print ms-s.abs, \" \", k.*(2)\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nprint \"1 #{2*n} \"\nif n>1\n print \"#{2+k} 2 \" if k>0\n i=2\n while i<2*n-1\n i+=1 while k>0 && (i==2+k || i==2)\n a=i\n i+=1\n i+=1 while k>0 && (i==2+k || i==2)\n b=i\n i+=1\n print \"#{a} #{b} \" if a<=2*n-1 && b <=2*n-1\n end\nend\n\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=(1..2*n).to_a\nputs a.shift,a.pop\nputs a.delete(2+k),a.shift if !a.empty?&&k>0\nputs a\n"}, {"source_code": "n, k = gets.split.map { |x| 2 * x.to_i }\nputs n.downto(1).each_slice(2).map { |x| x[0] <= k ? x.reverse : x } * ' '"}, {"source_code": "line = gets.chomp.split(\" \").map {|e| e.to_i}\nsecond = 1\nfirst = nil\nnums = [second]\nif line[1] != 0\n first = line[1] + 1\n nums = [first, second]\nend\n\nfor i in 2..(line[0] * 2)\n if i != first\n nums.push i\n end\nend\n\nputs nums.join(\" \")\n"}], "negative_code": [{"source_code": "n, k = gets.chomp.split.map(&:to_i)\nary = (1..2 * n).to_a\ni = 0\nk.times do\n ary[i], ary[i + 1] = ary[i + 1], ary[i]\n i += 2\nend\np ary.join(\" \")\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=(1..2*n).to_a\nputs a.shift,a.pop\nif !a.empty? && k>0\n puts a.shift,2+k\n a.delete 2+k\nend\nputs a.pop,a.pop until a.empty?\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=(1..2*n).to_a\nputs a.shift,a.pop\nif !a.empty? && k>0\n puts 2+k,a.shift\n a.delete 2+k\nend\nputs a.pop,a.pop until a.empty?\n"}], "src_uid": "82de6d4c892f4140e72606386ec2ef59"} {"source_code": "n,k=gets.split.map{|e| e.to_i}\nxs=gets.split.map{|e| e.to_i}.sort.reverse\nans=0\nwhile xs.empty? == false\n\tans+=(xs.take(k).shift-1)*2\n\txs=xs.drop(k)\nend\nputs ans\n", "positive_code": [{"source_code": "n, k = gets.split.map &:to_i\nf = gets.split.map(&:to_i).sort\n\ndef solve(f, k)\n sum = 0\n cur = []\n while f.size > 0\n if f.size > k\n cur = f[0...k]\n f = f[k...f.size]\n else\n cur = f\n f = []\n end\n \n cur << 1\n #p cur\n \n floor = 1\n cur.each do |newfloor|\n sum += (newfloor - floor).abs\n floor = newfloor\n end\n end\n return sum\nend\n\np [solve(f.dup, k), solve(f.reverse, k)].min"}, {"source_code": "nums = gets.chomp.split\nn = Integer(nums[0])\nk = Integer(nums[1])\nnums2 = gets.chomp.split\nf = []\nfor i in 0...n\n f[i] = Integer(nums2[i])\nend\n\nf.sort!\nm = n - 1\ntotal = 0\nwhile m >= 0 do \n total += 2*(f[m] - 1)\n m -= k\nend\nprint total"}, {"source_code": "nk=gets.chomp.split(\" \").map {|x| x.to_i}\nline=gets.chomp.split(\" \").map {|x| x.to_i}\nline.sort!\nlast=nk[0]\ntimes=0\nwhile last>0\n times+=(line[last-1]-1)*2\n last-=nk[1]\nend\nputs times"}, {"source_code": "n, limit = gets.split.map(&:to_i)\ngoal = gets.split.map(&:to_i).sort\nstep = 0\nposition = 1\nn.times do\n\tlimit.times do\n\t\tstep += (goal[-1] - position).abs\n\t\tposition = goal[-1]\n\t\tgoal.pop\n\t\tbreak if goal == []\n\tend\n\tstep += position - 1\n\tbreak if goal == []\n\tposition = 1\nend\nputs step\n"}, {"source_code": "def read_next_line\n gets.chomp.split.map(&:to_i)\nend\n\n_, k = read_next_line\nsum = 0\nread_next_line.sort.reverse.each_slice(k) { |p|\n sum += (p.first - 1) * 2\n}\nputs sum"}, {"source_code": "n, k = gets.split.map(&:to_i)\nf_list = gets.split.map(&:to_i)\nf_list.sort!.reverse!\nsum = 0\n((f_list.size - 1) / k + 1).times do |i|\n sum += (f_list[i * k, k].max - 1) * 2\nend\nputs sum\n"}, {"source_code": "def read_line; gets.chomp.split.map(&:to_i);end\na,b = read_line\ns = 0\nread_line.sort.reverse.each_slice(b){|p| s+=(p[0]-1)*2}\nputs s"}, {"source_code": "#!/usr/bin/ruby\nn,k=gets.split.map(&:to_i)\np gets.split.map(&:to_i).sort.reverse.each_slice(k).reduce(0){|s,e|s+e[0]*2-2}"}, {"source_code": "a,b=0,gets.split.map(&:to_i)\ngets.chomp.split.map(&:to_i).sort.reverse.each_with_index{|x,i| a+=(x-1)*2 if i%b[1]==0}\nputs a"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\ntargets = STDIN.readline.split.map {|s| s.to_i }.sort.reverse\ncost = 0\npos = 0\nwhile pos < n\n\tcost += 2*targets[pos] - 2\n\tpos += k\nend\nputs cost\n"}], "negative_code": [{"source_code": "nk=gets.chomp.split(\" \").map {|x| x.to_i}\nline=gets.chomp.split(\" \").map {|x| x.to_i}\nline.sort!\nlast=nk[0]\ntimes=0\nwhile last>=0\n times+=(line[last-1]-1)*2\n last-=nk[1]\nend\nputs times"}], "src_uid": "b8d8f0e86ecb600f7559a6aec629946e"} {"source_code": "def p(i)\n ((1+i)*i)/2\nend\n\ndef S(i)\n return 0 if i < 1\n return 1 if i == 1\n return 3 if i == 2\n q = Math.log2(i).ceil\n z = 0\n q.times do\n if z % 2 == 0\n z = z*2+1\n else\n z = z*2\n end\n end\n\n if i & (i-1) == 0\n z+=2\n end\n\n p(i) + p(i-z)\nend\n\nl, r = gets.split(/\\s+/).map(&:to_i)\nputs (S(r)-S(l-1))%1000000007\n", "positive_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\n\ndef foo(x)\n\treturn 0 if(x==0)\n\txlog = (Math.log(x)/Math.log(2)).to_i\n\tans=0\n\tif(xlog%2==1)\n\t\t#our last number is odd\n\t\tasd = (xlog-1)/2\n\t\tnumberofodds = (((4**(asd+1))-1)/3)\n\t\tnumberofevens = x-numberofodds\n\t\tans += numberofevens**2 + numberofevens\n\t\tans += numberofodds**2\n\t\treturn ans\n\telse\n\t\t#our last number is even\n\t\tasd = (xlog-2)/2\n\t\tnumberofevens = 2*(((4**(asd+1))-1)/3)\n\t\tnumberofodds = x-numberofevens\n\t\tans += numberofevens**2 + numberofevens\n\t\tans += numberofodds**2\n\t\treturn ans\n\tend\nend\n\n\nlr = gets.chomp.split(\" \").map(&:to_i)\n\nl = lr[0]\nr = lr[1]\nputs (foo(r)-foo(l-1))%1000000007\n"}, {"source_code": "require 'scanf'\nclass T\n attr_accessor :lb\n attr_accessor :le\n attr_accessor :vb\n attr_accessor :ve\n attr_accessor :val\n def initialize(a1,a2,a3,a4,a5)\n @lb,@le,@vb,@ve,@val=a1,a2,a3,a4,a5\n end\nend\ndt=[]\n$shit=1000000007\ndt[1]=T.new(1,1,1,1,1)\ndt[2]=T.new(2,3,2,4,6)\ndef size(a1,a2,a3)\n return (((a1+a2)*a3)/2)%$shit\nend\nfor i in 3..100\n dt[i]=T.new(dt[i-1].le+1,2**i-1,dt[i-2].ve+2,dt[i-2].ve+2**i,1)\n dt[i].val=size(dt[i].vb,dt[i].ve,dt[i].le-dt[i].lb+1)\nend\na,b=scanf(\"%d%d\")\na-=1\nl,r=0,0\nfor i in 1..100\n if dt[i].le= m\n res << m\n else \n res << c - (m-c)/(k-1) - ( ((m-c)%(k-1) > 0) ? 1 : 0)\n end \nend\n\nres.each { |r| p r }\n"}, {"source_code": "gets.to_i.times do\n n, m, k = gets.split.map &:to_i\n x = [n/k, m].min\n y = (m - x + k - 2)/(k - 1)\n puts x - y\nend\n"}, {"source_code": "t = gets.to_i\n\n1.upto t do\n n, m, k = gets.split.map(&:to_i)\n a = [m, n/k].min\n b = m - a\n puts (a - ((b + k - 2)/(k-1)))\nend"}], "negative_code": [{"source_code": "t = gets.to_i\n\n1.upto t do\n n, m, k = gets.split.map(&:to_i)\n if m == 0\n puts 0\n else\n if (n/k == 1)\n if m == 1\n puts 1\n else\n puts 0\n end\n else\n if (m > n/k)\n z = n/k\n y = m-z\n if y % (k-1) == 0\n puts (z - y/(k+1))\n else\n puts (z - (y/(k-1)+1))\n end\n else\n puts m\n end\n end\n end\nend"}], "src_uid": "6324ca46b6f072f8952d2619cb4f73e6"} {"source_code": "gets\nq = gets.split.map(&:to_i)\n\na, b, c, d, s = 0, 0, 0, 0, 0\n\nq.each.with_index do |e, i|\n c += e if i.even?\n d += e if i.odd?\nend\n\nq.each.with_index do |e, i|\n c -= e if i.even?\n d -= e if i.odd?\n\n s += 1 if a + c == b + d\n\n b += e if i.even?\n a += e if i.odd?\nend\n\nputs s", "positive_code": [{"source_code": "DBG = true\nn = gets.to_i\na = gets.split.map{|z| z.to_i}\nso = Array.new(n,0)\nse = Array.new(n,0)\nse[0] = a[0]\nfor i in 1...n\n so[i] = so[i-1] + (i%2 == 1 ? a[i] : 0)\n se[i] = se[i-1] + (i%2 == 0 ? a[i] : 0)\nend\nsum = (so[n-1] - so[0] == se[n-1] - se[0]) ? 1 : 0\nsum += 1 if so[n-2] == se[n-2]\nfor i in 1..(n-2)\n sum += 1 if so[n-1] - so[i] + se[i-1] ==\n se[n-1] - se[i] + so[i-1]\nend\nputs \"#{sum}\"\n"}, {"source_code": "def good(sweets)\n count = 0\n evens = 0\n odds = 0\n\n sweets.each_with_index do |x, i|\n if i.even? then evens += x else odds += x end\n end\n\n sweets.each_with_index do |x, i|\n if i.even? then evens -= x else odds -= x end\n\n count += 1 if evens == odds\n\n if i.even? then odds += x else evens += x end\n end\n count\nend\n\ngets\nsweets = gets.chomp.split.map(&:to_i)\nputs(good(sweets))\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ns1 = (1..n + 2).map { [0, 0] }\ns2 = (1..n + 2).map { [0, 0] }\na.each_with_index do |v, i|\n\ts1[i][i % 2] = s1[i - 1][i % 2] + v\n\ts1[i][(i + 1) % 2] = s1[i - 1][(i + 1) % 2]\nend\na.each_with_index.reverse_each do |v, i|\n\ts2[i][i % 2] = s2[i + 1][i % 2] + v\n\ts2[i][(i + 1) % 2] = s2[i + 1][(i + 1) % 2]\nend\np (0...n).count { |i|\n\t\ts1[i - 1][i % 2] + s2[i + 1][(i + 1) % 2] ==\n\t\t\ts1[i - 1][(i + 1) % 2] + s2[i + 1][i % 2]\n }\n"}], "negative_code": [], "src_uid": "dcc380c544225c8cadf0df8d8b6ffb4d"} {"source_code": "class Advisor\n def self.get_advice(src)\n @@norm_work_cnt=src[0][1]\n src[1].unshift @@norm_work_cnt\n walks=src[1].map {|x| x=*x}.each_cons(2).to_a.each {|x| x[1][0]= get_walks_needed(x[0][0],x[1][0])}.\n map {|x| x=x[1]}.flatten\n src[1].shift\n result = [] << walks.zip(src[1]).map {|x,y| x-y}.reduce(:+) << walks\n print_result result\n result\n end\n def self.get_walks_needed(walks_prev,walks_current)\n tmp = @@norm_work_cnt-walks_prev-walks_current\n (tmp>=0)?(tmp+walks_current) : walks_current\n end\n def self.print_result(res)\n puts res[0],res[1].join(' ')\n end\nend\n\nif __FILE__ == $0\n src = $stdin.each_line.map {|x| x.split.map {|x| x=(x.to_i)}}\n Advisor.get_advice(src)\nend", "positive_code": [{"source_code": "n,k,*a=$<.read.split.map(&:to_i)\nb=a[s=0]\n(1...n).each{|i|\nif b+a[i]1\n\td=x[0]+x[1]\n\tif k>d then\n\t\tx[1]+=(k-d)\n\t\tsum+=(k-d)\n\tend\n\tarr<0&&(r+=t;e+=t));b=e}\np r\nputs A*' '"}, {"source_code": "n, k=gets.split.map &:to_i\na=gets.split.map &:to_i\n\nres=0\nb=[a[0]]\nfor i in 1..n-1\n t=k-a[i]-b[i-1]\n b[i]=a[i]\n if t>0\n res+=t\n b[i]+=t\n end\nend\nputs res\nputs b*' '\n"}, {"source_code": "n,k = gets.split(' ').map {|e| e.to_i}\narr = gets.split(' ').map {|e| e.to_i}\ni = 1\ntmp = 0\nwhile i < n\n\tif arr[i]+arr[i-1] (a[i - 1] + a[i]) ? k - (a[i - 1] + a[i]) : 0\n ad += dif\n a[i] += dif\nend\nputs ad\nputs a.join \" \"\n"}, {"source_code": "def solution(arr, k)\n counter = 0\n for i in 0...arr.size-1 do\n add = k - arr[i+1] - arr[i]\n if add > 0\n arr[i+1] += add \n counter += add\n end\n end\n puts counter\n puts arr\nend\n\n\n_, k = gets.split.map{ |i| i.to_i }\narr = gets.split.map(&:to_i)\n\nsolution(arr, k)\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = 0\n(n - 1).times do |i|\n c = k - a[i] - a[i + 1]\n if c > 0\n ans += c\n a[i + 1] += c\n end\nend\nputs ans, a.join(' ')\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = 0\n(n - 1).times do |i|\n if a[i] + a[i + 1] < k\n c = k - a[i] - a[i + 1]\n ans += c\n a[i + 1] += c\n end\nend\nputs ans, a.join(' ')\n"}, {"source_code": "n,k=gets.split(\" \").map(&:to_i)\na=gets.split(\" \").map(&:to_i)\nb=[a[0]]\ndelta=0\nfor i in 1...n\n\tb<<[a[i],k-b[i-1]].max\n\tif k-b[i-1]>a[i]\n\t\tdelta+=k-b[i-1]-a[i]\n\tend\nend\nputs delta\nputs b.join(\" \")\n\n\t"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\ntot = 0\nfor i in 0 ... n - 1\n if a[i] + a[i + 1] < k\n add = k - a[i] - a[i + 1]\n a[i + 1] += add\n tot += add\n end\nend\nputs tot\nputs a.join(' ')\n"}], "negative_code": [{"source_code": "n, k = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\n\n(0...n).each_cons(2).each do |i, j|\n if a[i] + a[j] < k\n a[j] = k - a[i]\n end\nend\nputs a.join(\" \")\n"}, {"source_code": "n,k=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\narr=[]\nsum=0\nwhile x.size>1\n\td=x[0]+x[1]\n\tif k>d then\n\t\tx[1]+=(k-d)\n\t\tsum+=(k-d)\n\tend\n\tarr<1 then\n\tarr<=k then\n\t\tarr< x[1].to_i}\n\nsep = n/4\nfor i in 0...n/4 do\n output.puts \"Group #{('A'.ord+i).chr}:\"\n x = (x*a + b)%c\n t1 = x%sep\n output.puts team[t1][0]\n \n x = (x*a + b)%c\n t2 = sep + x%sep\n output.puts team[t2][0]\n \n x = (x*a + b)%c\n t3 = sep*2 + x%sep\n output.puts team[t3][0]\n \n x = (x*a + b)%c\n t4 = sep*3 + x%sep\n output.puts team[t4][0]\n \n team.delete_at(t1)\n team.delete_at(t2-1)\n team.delete_at(t3-2)\n team.delete_at(t4-3)\n \n sep -= 1\nend\n\ninput.close\noutput.close", "positive_code": [{"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nclass RNG\n def initialize(x, a, b, c)\n @x = x\n @f = ->(x){(x * a + b) % c}\n end\n\n def next\n @x = @f[@x]\n end\nend\n\nn = gets.to_i\nr = RNG.new(*gets.split.map(&:to_i))\na = Array.new(n){\n x, y = gets.split\n [y.to_i, x]\n}\nn /= 4\na = a.sort.reverse.each_slice(n).to_a\ng = 'Group A:'\nn.downto(1){|m|\n puts g\n g.succ!\n a.each{|b|\n t = b[r.next % m]\n puts t[1]\n b.delete(t)\n }\n}\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nclass RNG\n def initialize(x, a, b, c)\n @x = x\n @f = ->(x){(x * a + b) % c}\n end\n\n def next\n @x = @f[@x]\n end\nend\n\nn = gets.to_i\nr = RNG.new(*gets.split.map(&:to_i))\na = Array.new(n){\n x, y = gets.split\n [y.to_i, x]\n}\nn /= 4\na = a.sort.reverse.each_slice(n).to_a\ng = 'Group A:'\nn.downto(1){|m|\n puts g\n g.succ!\n a.each{|b|\n t = b[r.next % m]\n puts t[1]\n b.delete(t)\n }\n}\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nclass RNG\n def initialize(x, a, b, c)\n @x = x\n @f = ->(x){(x * a + b) % c}\n end\n\n def next\n @x = @f[@x]\n end\nend\n\nn = gets.to_i\nr = RNG.new(*gets.split.map(&:to_i))\na = Array.new(n){\n x, y = gets.split\n [y.to_i, x]\n}\nn /= 4\na = a.sort.reverse.each_slice(n).to_a\ng = 'Group A:'\nn.downto(1){|m|\n puts g\n g.succ!\n a.each{|b|\n t = b[r.next % m]\n puts t[1]\n b.delete(t)\n }\n}\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nclass RNG\n def initialize(x, a, b, c)\n @x = x\n @f = ->(x){(x * a + b) % c}\n end\n\n def next\n @x = @f[@x]\n end\nend\n\nn = gets.to_i\nr = RNG.new(*gets.split.map(&:to_i))\na = Array.new(n){\n x, y = gets.split\n [y.to_i, x]\n}\nn /= 4\na = a.sort.reverse.each_slice(n).to_a\ng = 'Group A:'\nn.downto(1){|m|\n puts g\n g.succ!\n a.each{|b|\n t = b[r.next % m]\n puts t[1]\n b.delete(t)\n }\n}\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nclass RNG\n def initialize(x, a, b, c)\n @x = x\n @f = ->(x){(x * a + b) % c}\n end\n\n def next\n @x = @f[@x]\n end\nend\n\nn = gets.to_i\nr = RNG.new(*gets.split.map(&:to_i))\na = Array.new(n){\n x, y = gets.split\n [y.to_i, x]\n}\nn /= 4\na = a.sort.reverse.each_slice(n).to_a\ng = 'Group A:'\nn.downto(1){|m|\n puts g\n g.succ!\n a.each{|b|\n t = b[r.next % m]\n puts t[1]\n b.delete(t)\n }\n}\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n class RNG\n def initialize(x, a, b, c)\n @x = x\n @f = ->(x){(x * a + b) % c}\n end\n def next\n @x = @f[@x]\n end\nend\n n = gets.to_i\nr = RNG.new(*gets.split.map(&:to_i))\na = Array.new(n){\n x, y = gets.split\n [y.to_i, x]\n}\nn /= 4\na = a.sort.reverse.each_slice(n).to_a\ng = 'Group A:'\nn.downto(1){|m|\n puts g\n g.succ!\n a.each{|b|\n t = b[r.next % m]\n puts t[1]\n b.delete(t)\n }\n}"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nclass RNG\n def initialize(x, a, b, c)\n @x = x\n @f = ->(x){(x * a + b) % c}\n end\n\n def next\n @x = @f[@x]\n end\nend\n\nn = gets.to_i\nr = RNG.new(*gets.split.map(&:to_i))\na = Array.new(n){\n x, y = gets.split\n [y.to_i, x]\n}\nn /= 4\na = a.sort.reverse.each_slice(n).to_a\ng = 'Group A:'\nn.downto(1){|m|\n puts g\n g.succ!\n a.each{|b|\n t = b[r.next % m]\n puts t[1]\n b.delete(t)\n }\n}\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nclass RNG\n def initialize(x, a, b, c)\n @x = x\n @f = ->(x){(x * a + b) % c}\n end\n\n def next\n @x = @f[@x]\n end\nend\n\nn = gets.to_i\nr = RNG.new(*gets.split.map(&:to_i))\na = Array.new(n){\n x, y = gets.split\n [y.to_i, x]\n}\nn /= 4\na = a.sort.reverse.each_slice(n).to_a\ng = 'Group A:'\nn.downto(1){|m|\n puts g\n g.succ!\n a.each{|b|\n t = b[r.next % m]\n puts t[1]\n b.delete(t)\n }\n}\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nclass RNG\n def initialize(x, a, b, c)\n @x = x\n @f = ->(x){(x * a + b) % c}\n end\n\n def next\n @x = @f[@x]\n end\nend\n\nn = gets.to_i\nr = RNG.new(*gets.split.map(&:to_i))\na = Array.new(n){\n x, y = gets.split\n [y.to_i, x]\n}\nn /= 4\na = a.sort.reverse.each_slice(n).to_a\ng = 'Group A:'\nn.downto(1){|m|\n puts g\n g.succ!\n a.each{|b|\n t = b[r.next % m]\n puts t[1]\n b.delete(t)\n }\n}\n\n"}, {"source_code": "if ENV['USER'] != 'watashi'\n $stdin = open('input.txt')\n $> = open('output.txt', 'w')\nend\n\nclass RNG\n def initialize(x, a, b, c)\n @x = x\n @f = ->(x){(x * a + b) % c}\n end\n\n def next\n @x = @f[@x]\n end\nend\n\nn = gets.to_i\nr = RNG.new(*gets.split.map(&:to_i))\na = Array.new(n){\n x, y = gets.split\n [y.to_i, x]\n}\nn /= 4\na = a.sort.reverse.each_slice(n).to_a\ng = 'Group A:'\nn.downto(1){|m|\n puts g\n g.succ!\n a.each{|b|\n t = b[r.next % m]\n puts t[1]\n b.delete(t)\n }\n}\n\n"}], "negative_code": [], "src_uid": "349b116f40dcf3884d4c8208a513ee23"} {"source_code": "gets.to_i.times do\r\n s = gets.chomp\r\n as = 0\r\n s.chars.each do |ch|\r\n case ch\r\n when \"A\" then as += 1\r\n when \"B\" then as -= 1\r\n end\r\n break if as < 0\r\n end\r\n ok = as >= 0 && s[-1] == \"B\"\r\n puts ok ? \"YES\" : \"NO\"\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n s = gets.chomp\r\n as = 0\r\n s.chars.each do |ch|\r\n case ch\r\n when \"A\" then as += 1\r\n when \"B\" then as -= 1\r\n end\r\n break if as < 0\r\n end\r\n ok = as >= 0 && s[-1] == \"B\"\r\n puts ok ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "gets.to_i.times do\r\n a = gets.chomp.split('')\r\n flag = (a[a.size-1] == 'B')\r\n bcount = 0\r\n acount = 0\r\n 0.upto(a.size-1) do |i|\r\n if (a[i]=='B') then\r\n bcount += 1\r\n else\r\n acount += 1\r\n end\r\n flag = false if bcount>acount\r\n end\r\n puts ((bcount > 0) && flag) ? \"YES\" : \"NO\"\r\nend"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n a = gets.chomp.split('')\r\n flag = true\r\n bcount = 0\r\n acount = 0\r\n 0.upto(a.size-1) do |i|\r\n if (a[i]=='B') then\r\n bcount += 1\r\n if (bcount>acount) then\r\n flag = false\r\n end\r\n else\r\n acount += 1\r\n end\r\n end\r\n puts ((bcount > 0 ) && flag) ? \"YES\":\"NO\"\r\nend"}, {"source_code": "gets.to_i.times do\r\n a = gets.chomp.split('')\r\n flag = true\r\n bcount = 0\r\n acount = 0\r\n 0.upto(a.size-1) do |i|\r\n if (a[i]=='B') then\r\n bcount += 1\r\n if (bcount>acount)\r\n flag = false\r\n end\r\n else\r\n acount += 1\r\n end\r\n end\r\n puts ((bcount > 0 ) & flag) ? \"YES\":\"NO\"\r\nend"}], "src_uid": "0b9be2f076cfa13cdc76c489bf1ea416"} {"source_code": "n = gets.to_i\n\ngs = gets.chomp\n\n\norigingold = false\ninagold = false\nif gs[0]==\"G\"\n inagold=true\n origingold = true\nend\n\nnewarr = []\n\ncount = 1\n\ngs.each_char.with_index do |ch,i|\n next if i==0\n if inagold\n if ch==\"S\"\n newarr.push count\n count = 1\n inagold = false\n else\n count+=1\n end\n else\n if ch==\"G\"\n newarr.push count\n count = 1\n inagold = true\n else\n count += 1\n end\n end\nend\n\nnewarr.push count\n\ndef checkifgold(i,origin)\n if origin\n return i%2==0\n else\n return i%2==1\n end\nend\n\nmaxgold = 0\nmaxtwogold = 0\nprevgold = 0\nwasaone = false\n\n#p newarr\n\nnewarr.each_with_index do |x,i|\n\n# puts wasaone\n# puts x\n# puts i\n# puts checkifgold(i,origingold)\n\n if checkifgold(i,origingold)\n maxgold = x if x>maxgold\n if wasaone\n asd = prevgold+x+1\n maxtwogold = asd if asd>maxtwogold\n end\n prevgold = x\n else\n if x==1\n wasaone = true\n else\n wasaone = false\n end\n end\n\nend\n\nif newarr.length==1\n if origingold\n puts maxgold\n else\n puts 0\n end\n exit\nend\n\nif newarr.length==2\n puts maxgold\n exit\nend\n\nif newarr.length==3\n if not origingold\n puts maxgold\n exit\n end\nend\n\nif newarr.length<5 or (newarr.length==5 and not origingold)\n puts [maxgold+1,maxtwogold-1].max\n exit\nend\n#puts maxgold\n#puts maxtwogold\nputs [maxgold+1,maxtwogold].max\n", "positive_code": [{"source_code": "gets\na=(?S+gets.chomp+?S).scan(/(?:G+|S+)/).map(&:size)\nres=0\n1.step(a.size, 2) do |i|\n break if !a[i]\n t=a[i]+(a.size>4 ? 1 : 0)\n res=a[i] if res6 && res4 ? 1 : 0)\n res=a[i] if res6 && res4 ? 1 : 0)\n res=a[i] if res6 && a[i+1]==1 ? a[i+2]+1 : 1)\n res=t if res5 ? 1 : 0)\n res=t if res5 && a[i+1]==1 ? 1 : 0)\n res=t if res4 ? 1 : 0)\n res=a[i] if res6 && a[i+1]==1 ? 1 : 0)\n res=t if res n; break; end;\n\tif n % i != 0; next; end;\n\n\tfor j in 0..i-1\n\t\tok = true;\n\t\tk = j;\n\t\twhile k < n\n\t\t\tif knights[k] == \"0\"\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\tend\n\t\t\tk += i;\n\t\tend\n\t\tif ok == true\n\t\t\tbreak;\n\t\tend\n\tend\n\tif ok\n\t\tbreak;\n\tend\nend\n\nif ok\n\tputs \"YES\";\nelse\n\tputs \"NO\";\nend\n\n"}, {"source_code": "#!/usr/bin/env/ruby\n\ndef exec(debug = false)\n length = gets.chomp.to_i\n elements = gets.chomp.split(/\\s/).map{|s| s.to_i}\n return puts \"NO\" unless length == elements.size\n \n max = length / 3\n p \"max: #{max}\" if debug\n max.times do |i|\n ii = i + 1\n p \"ii: #{ii}\" if debug\n next if length % ii != 0\n elements.each_with_index do |e, index|\n break if index == max\n success = true\n next if e == 0\n next if index >= ii\n p \"index:#{index}\" if debug\n (index + ii).step(length - 1, ii) do |j|\n p \"j: #{j}\" if debug\n unless elements[j] == 1\n p \"break\" if debug\n success = false\n break\n end\n end\n return puts(\"YES\") if success\n end\n end\n puts \"NO\"\nend\n\n#exec(debug = true)\nexec\n"}, {"source_code": "\nn=gets.to_i\na=gets.split.map(&:to_i)\n3.upto(n){|i|\n if n%i==0 then\n k=n/i\n k.times{|j|\n ok=1\n now=j\n i.times{\n if a[now]==0 then\n ok=0\n break\n end\n now+=k\n }\n if ok==1 then\n puts \"YES\"\n exit\n end\n }\n end\n}\nputs \"NO\"\n"}], "negative_code": [{"source_code": "require 'prime'\n\nn = gets.to_i\nknights = gets.split.map(&:to_i)\ndivs = n.prime_division.map{|a| a[0]-1}.select{|v| v+1<=n/3} + [0]\n\ndivs.each do |i|\n\t#if arr[i] == 1\n\t\t#check\n\t\tif n % (i+1) == 0\n\t\t\t(0..i).each do |start|\n\t\t\t\tok = true\n\t\t\t\tpos = start\n\t\t\t\t(n/(i+1)).times do\n\t\t\t\t\tif knights[pos] == 0\n\t\t\t\t\t\tok = false\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\t\tpos = (pos+i+1) % n\n\t\t\t\tend\n\t\t\t\tif ok\n\t\t\t\t\tputs \"YES\"\n\t\t\t\t\texit\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\n=begin\n\t\t(2..i+1).each do |k|\n\t\t\tif (i+1) % k == 0\n\t\t\t\tarr[(i+1)/k-1] = 0\n\t\t\tend\n\t\tend\n=end\n#\tend\nend\nputs \"NO\"\n"}, {"source_code": "#!/usr/bin/env/ruby\n\ndef exec(debug = false)\n length = gets.chomp.to_i\n elements = gets.chomp.split(/\\s/).map{|s| s.to_i}\n return puts \"NO\" unless length == elements.size\n \n max = length / 3\n p \"max: #{max}\" if debug\n max.times do |i|\n ii = i + 1\n p \"ii: #{ii}\" if debug\n next if length % ii != 0\n elements.each_with_index do |e, index|\n break if index == max\n success = true\n next if e == 0\n next if index >= ii\n p \"index:#{index}\" if debug\n (index + ii).step(length, ii) do |j|\n p \"j: #{j}\" if debug\n unless elements[j] == 1\n p \"break\" if debug\n success = false\n break\n end\n end\n return puts(\"YES\") if success\n end\n end\n puts \"NO\"\nend\n\nexec(debug = true)\n#exec\n"}, {"source_code": "#!/usr/bin/env/ruby\n\ndef exec\n length = gets.chomp.to_i\n elements = gets.chomp.split(/\\s/).map{|s| s.to_i}\n return puts \"NO\" unless length == elements.size\n \n max = length / 3\n #p \"max: #{max}\"\n max.times do |i|\n ii = i + 1\n #p \"ii: #{ii}\"\n return puts(\"NO\") unless length % ii == 0\n elements.each_with_index do |e, index|\n break if index == max\n success = true\n next if e == 0\n #p \"index:#{index}\"\n (index + ii).step(max, ii) do |j|\n #p \"j: #{j}\"\n unless elements[j] == 1\n #p \"break\"\n success = false\n break\n end\n end\n return puts(\"YES\") if success\n end\n end\n puts \"NO\"\nend\n\nexec\n"}, {"source_code": "#!/usr/bin/env/ruby\n\ndef exec(debug = false)\n length = gets.chomp.to_i\n elements = gets.chomp.split(/\\s/).map{|s| s.to_i}\n return puts \"NO\" unless length == elements.size\n \n max = length / 3\n p \"max: #{max}\" if debug\n max.times do |i|\n ii = i + 1\n p \"ii: #{ii}\" if debug\n elements.each_with_index do |e, index|\n break if index == max\n success = true\n next if e == 0\n p \"index:#{index}\" if debug\n (index + ii).step(max, ii) do |j|\n p \"j: #{j}\" if debug\n unless elements[j] == 1\n p \"break\" if debug\n success = false\n break\n end\n end\n return puts(\"YES\") if success\n end\n end\n puts \"NO\"\nend\n\n#exec(debug = true)\nexec\n"}, {"source_code": "#!/usr/bin/env/ruby\n\ndef exec(debug = false)\n length = gets.chomp.to_i\n elements = gets.chomp.split(/\\s/).map{|s| s.to_i}\n return puts \"NO\" unless length == elements.size\n \n max = length / 3\n p \"max: #{max}\" if debug\n max.times do |i|\n ii = i + 1\n p \"ii: #{ii}\" if debug\n next if length % ii != 0\n elements.each_with_index do |e, index|\n break if index == max\n success = true\n next if e == 0\n next if index >= ii\n p \"index:#{index}\" if debug\n (index + ii).step(length - 1, ii) do |j|\n p \"j: #{j}\" if debug\n unless elements[j] == 1\n p \"break\" if debug\n success = false\n break\n end\n end\n return puts(\"YES\") if success\n end\n end\n puts \"NO\"\nend\n\nexec(debug = true)\n#exec\n"}], "src_uid": "d3a0402de1338a1a542a86ac5b484acc"} {"source_code": "n,_ = gets.split\narr = gets.split.map(&:to_i)\narr.sort_by!{|a| -a}\n\ntotal = arr.inject(&:+)\nneeded = 0\n\n(0...arr.size).each do |i|\n if i == arr.size-1\n needed += [1,arr[i]].max\n elsif arr[i] > arr[i+1]\n needed += arr[i] - arr[i+1]\n else\n needed +=1\n arr[i+1] = arr[i]-1\n end\nend\n\nputs total-needed", "positive_code": [{"source_code": "n, m = gets.split.map{|x| x.to_i}\na = gets.split.map{|x| x.to_i}.sort.reverse\nm = a.max\nd = 0\n(0...n-1).each do |i|\n if a[i] == a[i + 1]\n d += a[i] if a[i] > 1\n a[i + 1] = [a[i] - 1, 1].max\n elsif a[i] > a[i + 1]\n d += a[i + 1]\n else\n d += a[i] if a[i] > 1\n d += a[i + 1] - a[i]\n a[i + 1] = [a[i] - 1, 1].max\n end \nend\nputs d\n"}], "negative_code": [], "src_uid": "ffa76f2558c8a70ab5c1ecb9e8561f25"} {"source_code": "def E_GCD(a,b)\n if b==0\n return 1,0,a\n else\n x,y,d = E_GCD(b, a%b)\n return y,x-y*(a/b),d\n end\nend\n\n a,b,c = gets.split.map(&:to_i)\n x,y,d = E_GCD(a,b)\n \n if c%d==0\n puts \"#{-x*c/d} #{-y*c/d}\"\n else\n puts -1\n end", "positive_code": [{"source_code": "def extgcd(a, b)\n\tif b == 0\n\t\t[a, 1, 0]\n\telse\n\t\tg, x, y = extgcd(b, a % b)\n\t\t[g, y, x - a / b * y]\n\tend\nend\n\na, b, c = gets.split.map(&:to_i)\ng, x, y = extgcd(a, b)\n\nif c % g == 0\n\tc /= -g\n\tputs \"#{x*c} #{y*c}\"\nelse\n\tp -1\nend\n"}], "negative_code": [], "src_uid": "a01e1c545542c1641eca556439f0692e"} {"source_code": "#!/usr/bin/env ruby\nrequire 'bigdecimal'\nn = STDIN.gets.chomp.to_i\nx = 10 ** (n - 1) / 210\n\na = x * 210\nb = (x + 1) * 210\nif a.to_s.length == n && a > 0\n puts a\nelsif b.to_s.length == n && b > 0\n puts b\nelse\n puts -1\nend\n", "positive_code": [{"source_code": "m = gets.to_i\nn = 10 ** (m - 1)\nn = (n + 209) / 210 * 210\nn = -1 if m < 3\nprint n\n"}, {"source_code": "n=gets.chomp.to_i\n\nres=0\na=[2,3,5,7]\n\n((10**(n-1))..(10**n-1)).each do |i|\nflag=1\na.each do |j|\nif i%j!=0\nflag=0\nbreak\nend\nend\n\nif flag==1\nres=i\nbreak\nend\n\nend\n\nres=-1 if res==0\n\nputs res\n"}, {"source_code": "n = gets.to_i\nm = 2*3*5*7\nif (n < 3)\n\tputs -1\nelsif n == 3\n\tputs m\nelse\n\tk = 10**(n-1)\n\tr = k % m\n\tputs k + m - r\nend\n\t\n\t"}, {"source_code": "def t(n)\n if n % 2 == 0 then\n return true\n else\n return false\n end\nend\n\ndef th(n)\n if n % 3 == 0 then\n return true\n else\n return false\n end\nend\n\ndef f(n)\n if n % 5 == 0 then\n return true\n else\n return false\n end\nend\n\ndef s(n)\n if n % 7 == 0 then\n return true\n else\n return false\n end\nend\n\nn = gets.to_i\n\nnum = 10**(n-1)\nh = 1\n\nwhile !t(num) do\n num += h\nend\n\nh = 2\n\nwhile !th(num) do\n num += h\nend\n\nh *= 3\n\nwhile !f(num) do\n num += h\nend\n\nh *= 5\n\nwhile !s(num) && num < 10**n do \n num += h\nend\n\nif !s(num) then\n num = -1\nend\n\nputs num"}, {"source_code": "a=10**(gets.to_i-1)\nif a<100 then\n puts -1\nelse\n while a%7!=0 do\n a+=1\n end\n while a%2!=0 || a%3!=0 || a%5!=0 do\n a+=7\n end\n puts a\nend\n"}, {"source_code": "a=10**(gets.to_i-1)\nif a<100 then\n puts -1\nelse\n while a%7!=0 do\n a+=1\n end\n while a%2!=0 || a%3!=0 || a%5!=0 || a%7!=0 do\n a+=7\n end\n puts a\nend"}, {"source_code": "n = gets.to_i\nif n < 3\n puts -1\nelse\n puts (10**(n - 1) + 209) / 210 * 210\nend\n"}, {"source_code": "\ufeffdef solve(n)\n return -1 if n <= 2\n return 210 if n == 3\n \n bases = [\"050\", \"080\", \"170\", \"020\", \"200\", \"110\"]\n \n return \"1\" + \"0\" * (n - 4) + bases[(n - 4) % 6 ]\n\nend\n\nn = gets.chomp.to_i\nputs solve(n)\n"}, {"source_code": "n = gets.to_i\nif n < 3 then\n print -1\n exit\nelse\n x = 10**(n-1) +20\n while x%7 != 0 do x += 30 end\n print x\nend"}, {"source_code": "n = gets.to_i\nif n < 3 then\n print -1\n exit\nend\nNum = 2*3*5*7\nk = 10**(n-1)\nwhile k%Num != 0 do\n k += 10\nend\nprint k"}, {"source_code": "n=gets.chomp.to_i\ndef s n\n if n<3\n puts -1\n return\n end\n s = 210\n z = 10**(n-1)\n d = z/s\n puts s*(d+1)\nend\ns n"}], "negative_code": [{"source_code": "n = gets.to_i\n\nnum = 10**(n-1)\nwhile (num % 3) != 0 || (num % 7) != 0 do\n num += 10\nend\n\nputs num"}, {"source_code": "a=10**(gets.to_i-1)\nif a<100 then\n puts -1\nelse\n while a%7!=0 do\n a+=1\n end\n while a%2!=0 || a%3!=0 || a%5!=0 do\n a+=1\n end\n puts a\nend"}, {"source_code": "a=10**(gets.to_i-1)\nif a<1000 then\n\tputs -1\nelse\n\twhile a%7!=0 do\n\t\ta+=1\n\tend\n\twhile a%2!=0 || a%3!=0 || a%5!=0 do\n\t\ta+=7\n\tend\n\tputs a\nend\n"}, {"source_code": "a=10**(gets.to_i-1)\nwhile a%7!=0 do\n a+=1\nend\nwhile (a%2!=0 || a%3!=0 || a%5!=0) do \n a+=7\nend\nputs a\n"}, {"source_code": "#!/usr/bin/env ruby\nrequire 'bigdecimal'\nn = STDIN.gets.chomp.to_i\n\nlog = n - 1 - Math::log(2 * 3 * 5 * 7, 10)\nx = (BigDecimal.new('10.0') ** log).to_i\na = x * 210\nb = (x + 1) * 210\n\nif a.to_s.length == n && a > 0\n puts a\nelsif b.to_s.length == n && b > 0\n puts b\nelse\n puts \"-1\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\nrequire 'bigdecimal'\nn = STDIN.gets.chomp.to_i\n\nlog = n - 1 - Math::log(2 * 3 * 5 * 7, 10)\nif log < 0\n puts -1\n exit\nend\nx = (BigDecimal.new('10.0') ** log).to_i\na = x * 210\nb = (x + 1) * 210\nc = (x + 2) * 210\n\nif a.to_s.length == n\n puts a\nelsif b.to_s.length == n\n puts b\nelsif c.to_s.length == n\nelse\n puts \"-1\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\nrequire 'bigdecimal'\nn = STDIN.gets.chomp.to_i\nx = 10 ** (n - 1) / 210\n\nif x < 1\n puts -1\n exit\nend\na = x * 210\nb = (x + 1) * 210\nif a.to_s.length == n\n puts a\nelsif b.to_s.length == n\n puts b\nelse\n puts -1\nend\n"}, {"source_code": "n = gets.to_i\nn = 10 ** n\nn = (n + 209) / 210 * 210\nprint n"}, {"source_code": "m = gets.to_i\nn = 10 ** m\nn = (n + 209) / 210 * 210\nn = -1 if m < 3\nprint n\n"}], "src_uid": "386345016773a06b9e190a55cc3717fa"} {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nm = Integer(input[1])\nlog_stream = Array.new\nwhile line = gets do\n log_stream.push(line)\nend\n\nx = n / 3600\ny = (n % 3600) / 60\nz = n - 3600 * x - 60 * y\n\n\ndef time_back(log, x, y, z)\n year = log[0..3].to_i\n month = log[5..6].to_i\n date = log[8..9].to_i\n hour = log[11..12].to_i\n minute = log[14..15].to_i\n second = log[17..18].to_i\n if second - z >= 0\n second = second - z\n else\n second = second - z + 60\n y += 1\n end\n if minute - y >= 0\n minute = minute - y\n else\n minute = minute - y + 60\n x += 1\n end\n if hour - x >= 0\n hour = hour - x\n else\n hour = hour - x + 24\n date -= 1\n if date == 0\n month -= 1\n if [1,3,5,7,8,10].include? month\n date = 31\n elsif [4,6,9,11].include? month\n date = 30\n elsif month == 0\n date = 31\n month = 12\n year -= 1\n elsif month == 2\n if year % 4 == 0\n date = 29\n else\n date = 28\n end\n end\n end\n end\n if month < 10\n month = \"0\" + month.to_s\n end\n if date < 10\n date = \"0\" + date.to_s\n end\n if hour < 10\n hour = \"0\" + hour.to_s\n end\n if minute < 10\n minute = \"0\" + minute.to_s\n end\n if second < 10\n second = \"0\" + second.to_s\n end\n return \"#{year}-#{month}-#{date} #{hour}:#{minute}:#{second}\"\nend\n\nmoment = -1\nfor i in m-1...log_stream.length\n if time_back(log_stream[i], x, y, z) < log_stream[i-m+1][0..18]\n moment = log_stream[i]\n break\n end\nend\nif moment != -1\n puts moment[0..18]\nelse\n puts moment\nend\n\n", "positive_code": [{"source_code": "require 'date'\n\nn, m = gets.chomp.split.map &:to_i\n\nl = n + 10\ncounts = Array.new(l) do |i|\n [0, 0]\nend\n\nfirst = 0\nlast = prev = 0\ntotal = 0\nans = -1\nwhile line=gets\n time_str = line[0..18]\n time = DateTime.parse(time_str).to_time\n total += 1\n if first != last && time == counts[prev][0]\n counts[prev][1] += 1\n else\n while first != last && counts[first][0] <= time - n\n total -= counts[first][1]\n first += 1\n first = 0 if first == l\n end\n counts[last][0] = time\n counts[last][1] = 1\n prev = last\n last += 1\n last = 0 if last == l\n end\n if total >= m\n ans = time_str\n break\n end\nend\n\nputs ans\n "}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s[0, 19]) }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_s.gsub(/T/, ' ').gsub(/\\+.*/, '')\n exit\n end\nend\n \nputs -1"}], "negative_code": [{"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip).new_offset(0) }\nputs logs.map { |l| l.to_time }\nputs logs.map { |l| l.to_time.to_s }\nputs logs.map { |l| l.to_time.to_s.gsub(/ \\+.*/, '_') }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_time.to_s.gsub(/ \\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip) }\nputs logs\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_time.to_s.gsub(/ \\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip) }\nputs logs.map { |l| l.to_time }\nputs logs.map { |l| l.to_time.to_s }\nputs logs.map { |l| l.to_time.to_s.gsub(/ \\+.*/, '_') }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_time.to_s.gsub(/ \\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip) }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].new_offset(0).to_time.to_s.gsub(/ \\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip) }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_s.gsub(/T/, '').gsub(/ \\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip).new_offset(\"+0000\") }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_time.to_s.gsub(/ \\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip).new_offset(\"+0000\") }\nputs logs.map { |l| l.to_time }\nputs logs.map { |l| l.to_time.to_s }\nputs logs.map { |l| l.to_time.to_s.gsub(/ \\+.*/, '_') }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_time.to_s.gsub(/ \\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s[0, 19].strip) }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_s.gsub(/T/, ' ').gsub(/ \\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip) }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_s.gsub(/ \\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n\nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip) }\n(m - 1).upto(logs.size - 1) do |i|\n puts logs[i]\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_time.to_s.gsub(/ \\+.*/, '')\n exit\n end\nend\n\nputs -1\n"}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip) }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_s.gsub(/T/, ' ').gsub(/ \\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip) }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_s.gsub(/T/, ' ').gsub(/\\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n \nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip) }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].new_offset(0).to_s.gsub(/ \\+.*/, '')\n exit\n end\nend\n \nputs -1"}, {"source_code": "require 'date'\n\nn, m = gets.split.map &:to_i\nlogs = $<.map { |s| DateTime.parse(s.strip) }\n(m - 1).upto(logs.size - 1) do |i|\n if (logs[i] - logs[i - (m - 1)]) * 60 * 60 * 24 < n\n puts logs[i].to_time.to_s.gsub(/ \\+.*/, '')\n exit\n end\nend\n\nputs -1\n"}, {"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nm = Integer(input[1])\nlog_stream = Array.new\nwhile line = gets do\n log_stream.push(line)\nend\n\nx = n / 3600\ny = (n % 3600) / 60\nz = n - 3600 * x - 60 * y\n\n\ndef time_back(log, x, y, z)\n year = log[0..3].to_i\n month = log[5..6].to_i\n date = log[8..9].to_i\n hour = log[11..12].to_i\n minute = log[14..15].to_i\n second = log[17..18].to_i\n if second - z >= 0\n second = second - z\n else\n second = second - z + 60\n y += 1\n end\n if minute - y >= 0\n minute = minute - y\n else\n minute = minute - y + 60\n x += 1\n end\n if hour - x >= 0\n hour = hour - x\n else\n hour = hour - x + 24\n date -= 1\n if date == 0\n month -= 1\n if [1,3,5,7,8,10].include? month\n date = 31\n elsif [4,6,9,11].include? month\n date = 30\n elsif month == 0\n date = 31\n month = 12\n year -= 1\n elsif month == 2\n if year % 4 == 0\n date = 29\n else\n date = 28\n end\n end\n end\n end\n if month < 10\n month = \"0\" + month.to_s\n end\n if date < 10\n date = \"0\" + date.to_s\n end\n if hour < 10\n hour = \"0\" + hour.to_s\n end\n if minute < 10\n minute = \"0\" + minute.to_s\n end\n if second < 10\n second = \"0\" + second.to_s\n end\n return \"#{year}-#{month}-#{date} #{hour}:#{minute}:#{second}\"\nend\n\nmoment = -1\nputs log_stream.length\nfor i in m-1...log_stream.length\n puts\n puts time_back(log_stream[i], x, y, z) \n puts log_stream[i-m+1][0..18]\n if time_back(log_stream[i], x, y, z) < log_stream[i-m+1][0..18]\n moment = log_stream[i]\n break\n end\nend\nif moment != -1\n puts moment[0..18]\nelse\n puts moment\nend\n\n"}], "src_uid": "c3f671243f0aef7b78a7e091b0e8f75e"} {"source_code": "T = gets.to_i\n\nT.times do\n n, m = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n\n if a.sum == m\n puts 'YES'\n else\n puts 'NO'\n end\nend\n", "positive_code": [{"source_code": "gets.chomp.to_i.times do |_i|\n n, m = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n puts (m == a.inject(0, :+) ? 'YES' : 'NO')\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n, m = gets.chomp.split(' ').map(&:to_i)\n c = gets.chomp.split(' ').map(&:to_i)\n if c.sum == m\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}, {"source_code": "t = gets.to_i\n\n1.upto t do\n n, m = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n\n if(a.sum == m)\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n"}, {"source_code": "test_cases = gets.chomp\n\ntest_cases.to_i.times do\n x = gets.chomp.split(\" \").map(&:to_i)[1]\n y = gets.chomp.split(\" \").map(&:to_i)\n puts y.sum == x ? \"YES\" : \"NO\"\n\nend\n"}], "negative_code": [], "src_uid": "941adee47c2a28588ebe7dfe16e0c91a"} {"source_code": "n, m = readline.split(' ').collect(&:to_i)\narr = Array.new(m) {Array.new}\nn.times do\n name, region, mark = readline.split(' ')\n region, mark = region.to_i, mark.to_i\n arr[region - 1].push([mark, name])\nend\narr.each do |a|\n a.sort!.reverse!\n if a.length <= 2 || a[2][0] < a[1][0]\n print a[0][1], \" \", a[1][1]\n puts\n else\n puts \"?\"\n end\nend\n", "positive_code": [{"source_code": "a=gets.chomp.split(\" \")\ninput=a[0].to_i\ncity=a[1].to_i\nmax2=Array.new(city){Array.new(2,0)}\nname=Array.new(city) {Hash.new { |hash, key| hash[key] = [] } }\ninput.times do \ntemp=gets.chomp.split(\" \")\ntc=temp[1].to_i\nts=temp[2].to_i\nif ts>max2[tc-1][0]\nmax2[tc-1][1]=max2[tc-1][0]\nmax2[tc-1][0]=ts\nelsif ts>max2[tc-1][1]\nmax2[tc-1][1]=ts\nend\nname[tc-1][ts]<2\nputs \"?\"\nelse\nputs name[i][max2[i][0]].join(\" \")\nend\nelse\nif name[i][max2[i][0]].length + name[i][max2[i][1]].length>2\nputs \"?\"\nelse\nprintf \"#{ name[i][max2[i][0]][0]} \"\nputs \"#{ name[i][max2[i][1]][0]}\"\nend\nend\nend\n"}, {"source_code": "a=gets.chomp.split(\" \")\ninput=a[0].to_i\ncity=a[1].to_i\nmax2=Array.new(city){Array.new(2,0)}\nname=Array.new(city) {Hash.new { |hash, key| hash[key] = [] } }\ninput.times do \ntemp=gets.chomp.split(\" \")\ntc=temp[1].to_i\nts=temp[2].to_i\nif ts>max2[tc-1][0]\nmax2[tc-1][1]=max2[tc-1][0]\nmax2[tc-1][0]=ts\nelsif ts>max2[tc-1][1]\nmax2[tc-1][1]=ts\nend\nname[tc-1][ts]<2\nputs \"?\"\nelse\nputs name[i][max2[i][0]].join(\" \")\nend\nelse\nif name[i][max2[i][0]].length + name[i][max2[i][1]].length>2\nputs \"?\"\nelse\nprintf \"#{ name[i][max2[i][0]][0]} \"\nputs \"#{ name[i][max2[i][1]][0]}\"\nend\nend\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = Array.new(m).map{Array.new}\nn.times do\n na, re, sc = gets.split\n re = re.to_i - 1\n sc = sc.to_i\n a[re].push([sc, na])\nend\n\nm.times do |i|\n t = a[i].sort{ |x, y| y[0] <=> x[0] }\n if t.length < 3\n puts \"#{t[0][1]} #{t[1][1]}\"\n elsif t[1][0] == t[2][0]\n puts \"?\"\n else\n puts \"#{t[0][1]} #{t[1][1]}\"\n end\nend\n"}, {"source_code": "def update(g, str, score)\n\tif !$a[g][0] || score >= $a[g][0]\n\t\t$a[g][2] = $a[g][1]\n\t\t$a[g][1] = $a[g][0]\n\t\t$a[g][0] = score\n\t\t$name[g][2] = $name[g][1]\n\t\t$name[g][1] = $name[g][0]\n\t\t$name[g][0] = str\n\telsif !$a[g][1] || score >= $a[g][1]\n\t\t$a[g][2] = $a[g][1]\n\t\t$a[g][1] = score\n\t\t$name[g][2] = $name[g][1]\n\t\t$name[g][1] = str\n\telsif !$a[g][2] || score >= $a[g][2]\n\t\t$a[g][2] = score\n\t\t$name[g][2] = str\n\tend\nend\n\nbuf=gets.split(' ')\nn,m=buf[0].to_i, buf[1].to_i\n$a=Array.new(m+1)\n$name=Array.new(m+1)\nfor i in 1..m\n\t$a[i]=Array.new(3)\n\t$name[i]=Array.new(3)\nend\nfor i in 1..n\n\tbuf=gets.split(' ')\n\tupdate(buf[1].to_i, buf[0], buf[2].to_i)\nend\nfor i in 1..m\n\tif $a[i][1] == $a[i][2]\n\t\tputs '?'\n\telse\n\t\tputs $name[i][0] + ' ' + $name[i][1]\n\tend\nend"}, {"source_code": "n, m = gets.chomp.split(' ').map(&:to_i)\n\nregion = Array.new(m) { |r| r = [] }\nans = Array.new(m) { |r| r = [] }\nn.times do\n info = gets.chomp.split(' ')\n region[info[1].to_i - 1] << [info[0], info[2].to_i]\nend\n\nregion.each do |r|\n r.sort! { |a, b| if a[1] > b[1] then -1 elsif a[1] < b[1] then 1 else 0 end }\nend\n\nregion.each_with_index do |r, i|\n sameWithMax = r.count { |p| p[1] == r[0][1] }\n sameWithSubSequent = 0\n \n if (sameWithMax < r.length)\n sameWithSubSequent = r.count { |p| p[1] == r[sameWithMax][1] }\n end\n \n if (sameWithMax >= 3 || (sameWithMax < 2 && sameWithMax + sameWithSubSequent >= 3))\n ans[i] << '?'\n else\n ans[i] << \"#{r[0][0]} #{r[1][0]}\"\n end\nend\n\nans.each do |a|\n puts a\nend\n "}, {"source_code": "#!/usr/bin/ruby\nn,m=gets.split.map(&:to_i)\nh=Hash.new{|h,k|h[k]=[]}\nn.times{\n\ta,b,c=gets.split\n\th[b.to_i-1]<<[-c.to_i,a]\n}\nm.times{|i|\n\th[i].sort!\n\tif h[i].size<=2 || h[i][1][0]!=h[i][2][0]\n\t\tputs h[i][0,2].map(&:last)*' '\n\telse\n\t\tputs '?'\n\tend\n}"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\nmemo = Hash.new {|h, k| h[k] = [] }\nPlayer = Struct.new(:name, :point)\n\nn.times do\n name, region, point = gets.chomp.split.map { |e| e == e.to_i.to_s ? e.to_i : e }\n memo[region] << Player.new(name, point)\nend\n\nmemo.keys.sort.each do |key|\n players = memo[key].sort_by { |p| -p.point }\n selected = players.take(2)\n\n if players.length <= 2 || players[1..2].map(&:point).uniq.length == 2\n puts selected.map(&:name).join(' ')\n else\n puts \"?\"\n end\nend\n\n"}], "negative_code": [{"source_code": "n, m = gets.chomp.split.map(&:to_i)\nmemo = Hash.new {|h, k| h[k] = [] }\nPlayer = Struct.new(:name, :point)\n\nn.times do\n name, region, point = gets.chomp.split.map { |e| e == e.to_i.to_s ? e.to_i : e }\n memo[region] << Player.new(name, point)\nend\n\nmemo.keys.sort.each do |key|\n players = memo[key].sort_by { |p| -p.point }\n selected = players.take(2)\n\n if players.length <= 2 || players[1..2].map(&:point).uniq == 1\n puts selected.map(&:name).join(' ')\n else\n puts \"?\"\n end\nend\n\n"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\nmemo = Hash.new {|h, k| h[k] = [] }\nPlayer = Struct.new(:name, :point)\n\nn.times do\n name, region, point = gets.chomp.split.map { |e| e == e.to_i.to_s ? e.to_i : e }\n memo[region] << Player.new(name, point)\nend\n\nmemo.keys.sort.each do |key|\n players = memo[key]\n max = players.map(&:point).max\n max_players = players.select { |p| p.point == max }\n selected = players.sort_by { |p| -p.point }.take(2)\n if max_players.length > 2 || selected.map(&:name).uniq.length == 1\n puts \"?\"\n else\n puts selected.map(&:name).join(' ')\n end\nend\n\n"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\nmemo = Hash.new {|h, k| h[k] = [] }\nPlayer = Struct.new(:name, :point)\n\nn.times do\n name, region, point = gets.chomp.split.map { |e| e == e.to_i.to_s ? e.to_i : e }\n memo[region] << Player.new(name, point)\nend\n\nmemo.keys.sort.each do |key|\n players = memo[key]\n max = players.map(&:point).max\n if players.map(&:point).select { |p| p == max }.length > 2\n puts \"?\"\n else\n puts players.sort_by { |p| -p.point }.take(2).map(&:name).join(' ')\n end\nend\n\n"}, {"source_code": "n, m = gets.chomp.split(' ').map(&:to_i)\n\nregion = Array.new(m) { |r| r = [] }\nans = Array.new(m) { |r| r = [] }\nn.times do\n info = gets.chomp.split(' ')\n region[info[1].to_i - 1] << [info[0], info[2].to_i]\nend\n\nregion.each do |r|\n r.sort! { |a, b| if a[1] > b[1] then -1 elsif a[1] < b[1] then 1 else 0 end }\nend\n\nregion.each_with_index do |r, i|\n sameWithMax = r.count { |p| p[1] == r[0][1] }\n sameWithSubSequent = 0\n \n if (sameWithMax < r.length)\n sameWithSubSequent = r.count { |p| p[1] == r[sameWithMax][1] }\n end\n \n if (sameWithMax + sameWithSubSequent >= 3)\n ans[i] << '?'\n else\n ans[i] << \"#{r[0][0]} #{r[1][0]}\"\n end\nend\n\nans.each do |a|\n puts a\nend\n "}], "src_uid": "a1ea9eb8db25289958a6f730c555362f"} {"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\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n n.times do |num_i|\n if m[num_i] > head\n ((head+1)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n m[t[i]-1] += 1\n end\n t[head] = num_i + 1\n head = m[num_i]\n elsif m[num_i] == head\n head += 1\n end\n break if head >= (n-1)\n end\n puts t.join(\" \")\nend", "positive_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n n.times do |num_i|\n if m[num_i] > head\n ((head+1)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n m[t[i]-1] = i\n end\n t[head] = num_i + 1\n head = m[num_i]\n elsif m[num_i] == head\n head += 1\n end\n break if head >= (n-1)\n end\n puts t.join(\" \")\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n \ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n \ndef inps() a=gets.chomp.split(\" \")end\n \ndef copy(a) Marshal.load(Marshal.dump(a)) end\n \ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n \ndef na(n,d=0) Array.new(n,d)end\n \ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n \ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n \ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n \ndef r_up(a, b) (a+b-1)/b end\n \ndef sum(a) a.inject(:+) end\n \nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n n.times do |num_i|\n if m[num_i] > head\n while(t[head] <= num_i)\n head += 1\n end\n ((head+1)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n m[t[i]-1] += 1\n end\n t[head] = num_i + 1\n head = m[num_i]\n end\n break if head >= (n-1)\n end\n puts t.join(\" \")\nend"}], "negative_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n n.times do |num_i|\n if m[num_i] > head\n ((head+1)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n end\n t[head] = num_i + 1\n head = m[num_i]\n elsif (m[num_i] == head)\n head += 1\n end\n break if head == (n-1)\n end\n puts t.join(\" \")\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n barrier = 0\n n.times do |num_i|\n if m[num_i] > head\n ((head+1+barrier)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n end\n t[head] = num_i + 1\n head = m[num_i]\n elsif (m[num_i] == head)\n head += 1\n barrier = 0\n elsif (m[num_i] == head - 1)\n barrier = 1\n end\n break if head == (n-1)\n end\n puts t.join(\" \")\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n n.times do |num_i|\n if m[num_i] > head\n ((head+1)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n m[t[i]-1] = i\n end\n t[head] = num_i + 1\n head = m[num_i]\n else\n head = m[num_i] + 1\n end\n break if head >= (n-1)\n end\n puts t.join(\" \")\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n n.times do |num_i|\n if m[num_i] > head\n while(t[head] <= num_i and head= (n-1)\n end\n puts t.join(\" \")\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n n.times do |num_i|\n if m[num_i] > head\n while(t[head] <= num_i and head<(num_i-1))\n head += 1\n end\n ((head+1)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n m[t[i]-1] += 1\n end\n t[head] = num_i + 1\n head = m[num_i]\n end\n break if head >= (n-1)\n end\n puts t.join(\" \")\nend"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n n.times do |num_i|\n if m[num_i] > head\n while(m[head] <= num_i and head= (n-1)\n end\n puts t.join(\" \")\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n barrier = false\n n.times do |num_i|\n if m[num_i] > head\n ((head+1)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n end\n t[head] = num_i + 1\n head = m[num_i]\n elsif (m[num_i] == head or m[num_i] == head - 1)\n head += 1\n end\n break if head == (n-1)\n end\n puts t.join(\" \")\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n n.times do |num_i|\n if m[num_i] > head\n ((head+1)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n end\n t[head] = num_i + 1\n head = m[num_i]\n break if head == (n-1)\n elsif (m[num_i] == head)\n head += 1\n end\n end\n puts t.join(\" \")\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n barrier = 0\n n.times do |num_i|\n if m[num_i] > head\n ((head+1+barrier)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n end\n t[head+barrier] = num_i + 1\n head = m[num_i]\n elsif (m[num_i] == head or m[num_i] == head - 1)\n barrier = 1\n end\n break if head == (n-1)\n end\n puts t.join(\" \")\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n n.times do |num_i|\n if m[num_i] > head\n ((head+1)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n m[t[i]-1] = i\n end\n t[head] = num_i + 1\n head = m[num_i]\n else\n head += 1\n end\n break if head >= (n-1)\n end\n puts t.join(\" \")\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n n.times do |num_i|\n if m[num_i] > head\n while(t[head] <= num_i and head= (n-1)\n end\n puts t.join(\" \")\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n m = na(n,0)\n n.times do |i|\n m[t[i]-1] = i\n end\n head = 0\n barrier = 0\n n.times do |num_i|\n if m[num_i] > head\n ((head+1+barrier)..m[num_i]).reverse_each do |i|\n t[i] = t[i-1]\n end\n t[head+barrier] = num_i + 1\n head = m[num_i]\n barrier = 0\n elsif (m[num_i] == head or m[num_i] == head - 1)\n barrier = 1\n end\n break if head == (n-1)\n end\n puts t.join(\" \")\nend\n"}], "src_uid": "c7a7e90bc54b2d21b3f59a358d9d1410"} {"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min\n\n", "positive_code": [{"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min\n\n"}, {"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min\n\n"}, {"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min\n\n"}, {"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min\n\n"}, {"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min\n\n"}, {"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min\n\n"}, {"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min"}, {"source_code": "a=[0,0]\ngets.to_i.times{|i|a[STDIN.read(1).hex^i%2]+=1}\np a.min\n"}, {"source_code": "a=[0,0]\ngets.to_i.times{|i|c=STDIN.read(1).ord-48;a[(c+i)%2]+=1}\np a.min\n"}, {"source_code": "a=[0,0]\ngets.to_i.times{|i|a[(STDIN.read(1).ord-48+i)%2]+=1}\np a.min\n"}, {"source_code": "n=gets.to_i;s=gets;a=0\nn.times{|i|a+=(i%2)^s[i].to_i}\np [a,n-a].min\n"}, {"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min\n"}, {"source_code": "n=gets.to_i;s=gets;a=0\nn.times{|i|a+=i%2^s[i].to_i}\np [a,n-a].min"}, {"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min"}, {"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min\n"}, {"source_code": "a=n=gets.to_i;s=gets\nn.times{|i|a-=i%2^s[i].hex}\np [a,n-a].min\n\n"}], "negative_code": [], "src_uid": "7c313b911e644cd5efa4fdc31d7ffcc9"} {"source_code": "DBG = true\ns = gets.chomp\nst = 0\nfor i in 0...s.size\n\n if st == 0\n if s[i] == '0'\n puts \"3 4\"\n st = 2\n else\n puts \"1 1\"\n st = 1\n end\n\n elsif st == 1\n if s[i] == '0'\n puts \"3 4\"\n st = 3\n else\n puts \"1 3\"\n st = 0\n end\n\n elsif st == 2\n if s[i] == '0'\n puts \"1 4\"\n st = 0\n else\n puts \"1 1\"\n st = 3\n end\n\n else #if st == 3\n if s[i] == '0'\n puts \"1 4\"\n st = 1\n else\n puts \"1 3\"\n st = 2\n end\n end\nend\n", "positive_code": [{"source_code": "s = gets.chomp\na = [[\"3 1\",\"3 2\",\"3 3\",\"3 4\"],[\"1 1\",\"1 3\",\"2 1\",\"2 3\"]]\nb = [0,0]\ns.size.times do |i|\n x = s[i].to_i\n puts a[x][b[x]]\n b[x] += 1\n b[x] %= 4\nend"}, {"source_code": "# Input\ns = gets.strip\n\n# TACTIC:\n# We will place all the horizontal tiles in top row, so every second horizontal\n# tile will make this row clear again.\n# All the vertical tiles will be placed in last two rows (3 1, 3 2, 3 3, 3 4),\n# so ever y 4th tile will clear both this lines.\n# Such tactic must guarantee that we will be able to place any tile any time.\n\n# Processing\nresult = []\nh_count, v_count = 0, 0\n\ns.each_char do |chr|\n if chr == \"1\"\n # Horizontal tile\n result << \"1 #{h_count * 2 + 1}\"\n h_count = (h_count + 1) % 2\n else\n # Vertical tile\n result << \"3 #{v_count + 1}\"\n v_count = (v_count + 1) % 4\n end\nend\n\n# Output\nputs result\n"}, {"source_code": "str = gets.strip\n\ngrid = Array.new(5) { Array.new(5, 0) }\n\nseq = []\nstr.each_char do |c|\n if c == '0'\n if grid[1][1] == 0\n grid[1][1] = 1\n seq << [1, 1]\n elsif grid[1][2] == 0\n grid[1][2] = 1\n seq << [1, 2]\n elsif grid[1][3] == 0\n grid[1][3] = 1\n seq << [1, 3]\n elsif grid[1][4] == 0\n seq << [1, 4]\n grid[1][1] = 0\n grid[1][2] = 0\n grid[1][3] = 0\n end \n else\n if grid[3][1] == 0\n seq << [3, 1]\n grid[3][1] = 1\n else\n seq << [3, 3]\n grid[3][1] = 0\n end\n end\nend\n\nseq.each do |pt|\n puts pt.join(\" \")\nend"}, {"source_code": "s = gets.chomp.split('').map(&:to_i)\nN = 4\narr = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\ns.each do |c|\n arr.each_with_index do |row, i|\n f = true\n row.each do |ee|\n f &= ee == 1\n end\n if (f)\n arr[i] = [0, 0, 0, 0]\n end\n end\n N.times do |i|\n f = true\n N.times do |ii|\n f &= arr[ii][i] == 1\n end\n if (f)\n arr[0][i] = 0\n arr[1][i] = 0\n arr[2][i] = 0\n arr[3][i] = 0\n end\n end\n if (c == 0)\n b = false\n N.times do |row|\n break if b\n N.times do |col|\n if (arr[col] && arr[col][row] == 0 && arr[col + 1] && arr[col + 1][row] == 0)\n arr[col][row] = 1\n arr[col + 1][row] = 1\n puts [col + 1, row + 1].join(' ')\n b = true\n break\n end\n end\n end\n end\n if (c == 1)\n b = false\n N.times do |row|\n break if b\n N.times do |col|\n #arr[1][0] arr[1][1]\n if (arr[row] && arr[row][col] == 0 && arr[row] && arr[row][col + 1] == 0)\n arr[row][col] = 1\n arr[row][col + 1] = 1\n puts [row + 1, col + 1].join(' ')\n b = true\n break\n end\n end\n end\n end\nend"}], "negative_code": [{"source_code": "s = gets.chomp.split('').map(&:to_i)\nN = 4\narr = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\ns.each do |c|\n arr.each_with_index do |row, i|\n f = true\n row.each do |ee|\n f &= ee == 1\n end\n if (f)\n arr[i] = [0, 0, 0, 0]\n end\n end\n N.times do |i|\n f = true\n N.times do |ii|\n f &= arr[ii][i] == 1\n end\n if (f)\n arr[0][i] = 0\n arr[1][i] = 0\n arr[2][i] = 0\n arr[3][i] = 0\n end\n end\n if (c == 0)\n b = false\n N.times do |row|\n break if b\n N.times do |col|\n #arr[0][1] arr[1][1]\n if (arr[col][row] == 0 && arr[col + 1][row] == 0)\n arr[col][row] = 1\n arr[col + 1][row] = 1\n puts [row + 1, col + 1].join(' ')\n b = true\n break\n end\n end\n end\n end\n if (c == 1)\n b = false\n N.times do |row|\n break if b\n N.times do |col|\n #arr[1][0] arr[1][1]\n if (arr[row][col] == 0 && arr[row][col + 1] == 0)\n arr[row][col] = 1\n arr[row][col + 1] = 1\n puts [col+ 1, row + 1].join(' ')\n b = true\n break\n end\n end\n end\n end\nend"}], "src_uid": "a63cdbd1009a60c0f9b52e4ffbba252e"} {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nn = gets.to_i\narr = gets.chomp.split(\" \").map(&:to_i)\n\nxorarr=[]\na = 0\n(0..n-1).each do |i|\n\ta = a^arr[i]\n\txorarr.push a\nend\n\nevenhash = Hash.new(0)\noddhash = Hash.new(0)\nxorarr.insert(0,0)\n\n(0..n).each do |i|\n\tif(i%2)==0\n\t\tevenhash[xorarr[i]]+=1\n\telse\n\t\toddhash[xorarr[i]]+=1\n\tend\nend\n\n#p evenhash\n#p oddhash\n\n=begin\np xorarr\np evenhash\np oddhash\n=end\nans = 0\nevenhash.each do |k,v|\n\tans+=(v*(v-1))/2\nend\n\noddhash.each do |k,v|\n\tans+=(v*(v-1))/2\nend\n\nputs ans", "positive_code": [{"source_code": "n = gets.to_i\na = gets.chomp.split(\" \").map(&:to_i)\n\ndp=[]\ncurrXorSum = 0\n(0..n-1).each do |i|\n\tcurrXorSum = currXorSum^a[i]\n\tdp.push currXorSum\nend\n\narr1 = [Hash.new(0),Hash.new(0)]\ndp.insert(0,0)\n\n(0..n).each do |i|\n\tarr1[i%2][dp[i]] += 1\nend\n\nans = 0\narr1[0].each do |k,ct|\n\tans += ((ct-1)*ct)/2\nend\n\narr1[1].each do |k,ct|\n\tans += ((ct-1)*ct)/2\nend\n\nputs ans"}], "negative_code": [], "src_uid": "e9cf26e61ebff8ad8d3b857c429d3aa9"} {"source_code": "def gao(v, p)\n\t$e[v].delete(p)\n\tn, x, y, z = $e[v].size, 1, 1, 1\n\tdp = [1] + [0] * n\n\t$e[v].each do |w|\n\t\ta, b, c = gao(w, v)\n\t\tx *= a\n\t\ty = [y, Rational(b, a)].max\n\t\tz *= a\n\t\tn.downto(1) do |i|\n\t\t\tdp[i] = [dp[i - 1] * c, dp[i] * a].max\n\t\tend\n\t\tdp[0] *= a\n\tend\n\tx, y = (x * y).to_i, 0\n\t0.upto(n) do |i|\n\t\tx = [x, dp[i] * (i + 1)].max\n\t\ty = [y, dp[i] * (i + 2)].max\n\tend\n\treturn x, y, z\nend\n\nn = gets.to_i\n$e = Array.new(n){[]}\n(n - 1).times do\n\ta, b = gets.split.map{|_| _.to_i - 1}\n\t$e[a] << b\n\t$e[b] << a\nend\np gao(0, -1)[0]\n", "positive_code": [{"source_code": "N = gets.to_i\nadj = Array.new(N) { Array.new }\n(N - 1).times {\n a, b = gets.split.map { |x| x.to_i - 1 }\n adj[a] << b\n adj[b] << a\n}\n\ndp = Array.new(N) { Array.new 2, 0 }\ndef dfs u, fa, adj, dp\n return dp[u] if dp[u][0] != 0\n dp[u] = [1, 1]\n ch = adj[u].reject { |v| v == fa }\n return dp[u] if ch.size == 0\n dp[u][0] = ch.map { |v| dfs(v, u, adj, dp)[1] } .reduce(1) { |o, v| o * v }\n f, l = dp[u][0], 1\n dp[u][1] = ch.map { |v| # left one right one\n dfs v, u, adj, dp\n } .sort { |x, y|\n x[1] * y[0] <=> x[0] * y[1]\n } .map { |a|\n l += 1\n f *= l\n f *= a[0]\n f /= a[1]\n f /= l - 1\n f\n } .max\n dp[u][1] = [\n dp[u][1],\n ch.map { |c|\n f, l = dp[u][0] * 2 * dfs(c, u, adj, dp)[0] / dfs(c, u, adj, dp)[1], 2\n adj[c].reject { |q| q == u } .map { |gc|\n dfs gc, c, adj, dp\n } .sort { |x, y|\n x[1] * y[0] <=> x[0] * y[1]\n } .map { |a|\n l += 1\n f *= l\n f *= a[0]\n f /= a[1]\n f /= l - 1\n f\n } .max || 1\n } .max || 1\n ].max\n return dp[u]\nend\n\ndfs 0, -1, adj, dp\np dp[0][1]\n"}], "negative_code": [{"source_code": "def gao(v, p)\n\t$e[v].delete(p)\n\tn, x, y = $e[v].size, 1, 1\n\tdp = [1] + [0] * n\n\t$e[v].each do |w|\n\t\ta, b = gao(w, v)\n\t\tx *= a\n\t\ty = [y, Rational(b, a)].max\n\t\tn.downto(1) do |i|\n\t\t\tdp[i] = [dp[i - 1], dp[i] * a].max\n\t\tend\n\t\tdp[0] *= a\n\tend\n\tx, y = (x * y).to_i, 0\n\t0.upto(n) do |i|\n\t\tx = [x, dp[i] * (i + 1)].max\n\t\ty = [y, dp[i] * (i + 2)].max\n\tend\n\treturn x, y\nend\n\nn = gets.to_i\n$e = Array.new(n){[]}\n(n - 1).times do\n\ta, b = gets.split.map{|_| _.to_i - 1}\n\t$e[a] << b\n\t$e[b] << a\nend\np gao(0, -1)[0]\n"}], "src_uid": "8dbf81e0d2815382cec6488efd877b70"} {"source_code": "input = STDIN.gets.chomp.split(\" \").map{|i| i.to_i}\n\nN = input[0]\nM = input[1]\nK = input[2]\n\nA = STDIN.gets.chomp.split(\" \").map.with_index{|a, i| [i, a.to_i]}\nsorted_a = A.sort_by{|a| a[1]}.reverse.slice(0, M * K).sort_by{|a| a[0]}\n\ntotal = 0\nslices = []\nsorted_a.each_with_index{|a, i|\n if i != (M * K - 1) && (i % M) == (M - 1)\n slices.push(a[0] + 1)\n end\n total = total + a[1]\n}\nputs total\nputs slices.join(\" \")\n\n\n# A.map.with_index{|a, b|\n# p a\n# p b\n# return 23\n# }", "positive_code": [{"source_code": "n, m, k = gets.chomp.split(' ').map(&:to_i)\ni = -1\narray = gets.chomp.split(' ').map(&:to_i)\nl_array = array.map{|n| i+=1; [n.to_i, i]}\n\nl_array = l_array.sort{\n\t|x,y| \n\tif(x[0] == y[0]) then x[1]<=>y[1] \n\telse y<=>x end\n}[0...(k*m)].sort{|x,y| x[1]<=>y[1]}\n\nsum = 0\nl_array.each{|x| sum+=x[0]}\n\nputs sum\n\n#~ puts\n#~ print l_array\n#~ puts\ni = -1\n(k-1).times{\n\t|x|\n\tx+=1\n\ti += m\n\tif(x != k-1) then print(\"#{l_array[i][1]+1} \")\n\telse puts(\"#{l_array[i][1]+1}\") end\n}\n\n"}], "negative_code": [], "src_uid": "e9cf68a68b55fe075099c384cb6a7e9e"} {"source_code": "#input = File.open('input.txt','r')\nn = gets.to_i\ngraph = Array.new(n)\ncoordinates = Array.new(n)\nn.times do |i|\n\tcoordinates[i] = Array.new(2)\n\tgraph[i] = Array.new\n\tcoordinates[i][0], coordinates[i][1] = gets.split\n\tcoordinates[i][0] = coordinates[i][0].to_i - 1\n\tcoordinates[i][1] = coordinates[i][1].to_i - 1\nend\nn.times do |i|\n\t#print i.to_s + \": \"\n\t(n-i-1).times do |j|\n\t\t#print (i+j+1).to_s + \" \"\n\t\tif coordinates[i][0] == coordinates[i+j+1][0] or coordinates[i][1] == coordinates[i+j+1][1]\n\t\t\tgraph[i].push(i+j+1)\n\t\t\tgraph[i+j+1].push(i)\n\t\t\t#print \"ALALAH!\"\n\t\tend\n\tend\n\t#puts\nend\nvisited = Array.new(n,false)\nrequire 'thread'\nqueue = Queue.new\ncomponents = -1\nn.times do |i|\n\tunless visited[i]\n\t\tvisited[i] = true\n\t\tqueue << i\n\t\twhile !queue.empty?\n\t\t\tv = queue.pop\n\t\t\tgraph[v].each do |j|\n\t\t\t\tunless visited[j]\n\t\t\t\t\tvisited[j] = true\n\t\t\t\t\tqueue << j\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tcomponents += 1\n\tend\nend\nputs components\n\n\n\n#assign a value to a variable only if that variable isn't already set:\n#@variable ||= \"default value\"\n\n#x, y = y, x will interchange the values of x and y\n\n#names2 = %w{ ann richard william susan pat } \n\n#puts \"Enrollments will now Stop\" if participants > 2500 \n\n#Negative index values count from the end of the array\n", "positive_code": [{"source_code": "n = gets.to_i\narr = []\n\ndef dfs(start,array,n)\n\treturn if @visited[start]\n\t\n\t@visited[start] = true\n\n\t(0...n).each do |i|\n\t\tif !@visited[i] && (array[i][0] == array[start][0] || array[i][1] == array[start][1])\n\t\t\t# puts \"here\"\n\t\t\tdfs(i,array,n)\n\t\tend\n\tend\nend\nn.times do \n\tarr << gets.split(\" \").map(&:to_i)\nend\n\n@visited = Hash.new(false)\ncomp = 0\n(0...n).each do |i|\n\t unless @visited[i]\n\t \tcomp += 1\n\t \tdfs(i,arr,n)\n\t end\nend\nputs comp-1"}, {"source_code": "class Node\n attr_accessor :visited, :nearest, :x, :y\n\n def initialize(x, y)\n @visited = false\n @nearest = []\n @x = x\n @y = y\n end\n\n def add(node)\n @nearest<< node if node.is_a? Node\n end\n\n def to_s\n puts \"x:#{@x},y:#{@y}\"\n end\nend\n\n\nclass Graph\n attr_accessor :nodes\n\n def initialize\n @nodes = []\n end\n\n def add_node(node)\n @nodes << node if node.is_a? Node\n end\n\n def has_not_visited\n index = @nodes.index{|el| el.visited==false}\n index.nil? ? false : @nodes[index]\n end\nend\n\n\ndef bfs(start)\n start.visited = true\n start.nearest.each{|el| bfs(el) unless el.visited}\nend\n\n\nn = gets.to_i\ngr = Graph.new\n\nn.times do\n x, y = gets.split.map(&:to_i)\n node = Node.new(x, y)\n\n gr.nodes.each do |n|\n if n.x == node.x || n.y ==node.y\n n.add(node)\n node.add(n)\n end\n end\n gr.add_node(node)\nend\n\ncounter = -1\nwhile gr.has_not_visited do\n counter +=1\n bfs(gr.has_not_visited)\nend\n\nputs counter"}, {"source_code": "n = gets.to_i\nli = []\n(1..n).each do\n x, y = gets.split.collect{|i| i.to_i}\n li.push([[x],[y]])\nend\nans = 0\nfor i in (n-1).downto(0)\n for j in 0...i\n unless (li[j][0]&li[i][0]).empty? and (li[j][1]&li[i][1]).empty?\n li[j][0] |= li[i][0]\n li[j][1] |= li[i][1]\n ans -= 1\n break\n end\n end\n ans += 1\nend\nputs ans-1\n"}, {"source_code": "n = gets.to_i\nli = []\n(1..n).each do\n x, y = gets.split.collect{|i| i.to_i}\n li.push([[x],[y]])\nend\nfor i in (n-1).downto(0)\n for j in 0...i\n unless (li[j][0]&li[i][0]).empty? and (li[j][1]&li[i][1]).empty?\n li[j][0] |= li[i][0]\n li[j][1] |= li[i][1]\n li.delete_at(i)\n break\n end\n end\nend\nputs li.size-1\n"}, {"source_code": "\n# Create reachability matrix\ndef reach(coordinates)\n reachability = Array.new(coordinates.length) {[]}\n for i in 0..(coordinates.length - 1) do\n root = coordinates[i]\n for j in (i + 1)..(coordinates.length - 1) do\n target = coordinates[j]\n if (root[0] == target[0]) || (root[1] == target[1])\n reachability[i].push(j)\n reachability[j].push(i)\n end\n end\n end\n return reachability\nend\n\n# Run DFS\ndef dfs(root, reachability, traversal)\n traversal.push(root)\n for child in reachability[root] do\n unless traversal.include?(child)\n dfs(child, reachability, traversal)\n end\n end\nend\n\n# Initialize variables\ncoordinates = []; nodes = []; segments = 0;\n\n# Read Input\nn = gets.strip.to_i\nn.times {coordinates.push(gets.strip.split.map{|s| s.to_i})}\n\n# Create reachability matrix\nreachability = reach(coordinates)\nnodes = (0..n - 1).to_a\n\n# Count connected segments\nuntil nodes.empty?\n traversal = []; root = nodes[0];\n dfs(root, reachability, traversal)\n nodes = nodes - traversal\n segments = segments + 1;\nend\n\n# Return the number of nodes needed\nputs segments - 1\n"}, {"source_code": "def dfs(index)\n return true if @dp[index] != nil \n @dp[index] = 1 \n (1..@n).each do |i|\n dfs(i) if @arr[index][i] == 1\n end\nend\n\n@n = gets.to_i\n@arr = Array.new(@n+1) {Array.new(@n+1)}\nnodes = []\n@dp = []\n(1..@n).each do |index|\n x,y = gets.split(' ').map(&:to_i)\n nodes.each_with_index do |node, i|\n if node[0] == x || node[1]== y\n @arr[index][i+1] = 1\n @arr[i+1][index] = 1\n end\n end\n nodes << [x,y]\nend\ncomponents = 0\n(1..@n).each do |index|\n if(@dp[index] == nil)\n components+= 1\n dfs(index)\n end\nend\nputs components-1"}, {"source_code": "class Drift\n attr_reader :x, :y\n attr_accessor :zone, :adj\n def initialize(x, y)\n @x = x\n @y = y\n @zone = nil\n @adj = Array.new\n end\nend\n\nclass Map\n attr_accessor :d, :n\n def initialize\n @d = Array.new\n @n = 0\n end\n def add(x, y)\n d << Drift.new(x, y)\n for i in 0...@n\n if d[i].x == d[@n].x || d[i].y == d[@n].y\n d[i].adj << @n\n d[@n].adj << i\n end\n end\n @n += 1\n end\n def at(n)\n @d[n]\n end\n def dfs(n, z)\n d[n].zone = z\n for i in d[n].adj\n dfs(i, z) if d[i].zone == nil\n end\n end\nend\n\nn = gets.to_i\nmap = Map.new\nfor i in 0...n\n x, y = gets.split(\" \").map(&:to_i)\n map.add(x, y)\nend\nz = 0\nfor i in 0...map.n\n if map.at(i).zone == nil\n map.dfs(i, z)\n z += 1\n end\nend\nprint z-1"}, {"source_code": "ySet, connectedGraph=Array.new(gets.to_i){gets.scan(/(\\d+) (\\d+)/).first}.inject({}){|h, n|h.update({n[0]=>Array[n[1]]}){|k, sv, ov|sv+ov}}.values, []\nconnectedGraph.empty? || ySet.reject{|v|(connectedGraph.last&v).empty?}.each{|v|connectedGraph[-1]|=ySet.delete(v)}.empty? ? connectedGraph<Array[n[1]]}){|k, sv, ov|sv+ov}}.values\nconnectedGraph = [ySet.shift]\nySet.reject{|v|(connectedGraph.last&v).empty?}.each{|v|connectedGraph[-1]|=ySet.delete(v)}.empty? ? connectedGraph<Array[v[1]]}}.inject{|h, n|h.update(n){|k, sv, ov|sv+ov}}.values\ndisjointCount=0\nconnectedGraph=ySet.shift\nwhile !ySet.empty?\n next if !ySet.reject{|v|(connectedGraph&v).empty?}.each{|v|connectedGraph|=ySet.delete(v)}.empty?\n disjointCount+=1\n connectedGraph=ySet.shift\nend\nprint disjointCount"}, {"source_code": "ySet=Array.new(gets.to_i){gets.scan(/(\\d+) (\\d+)/).first}.inject({}){|h, n|h.update({n[0]=>Array[n[1]]}){|k, sv, ov|sv+ov}}.values\ndisjointCount=0\nconnectedGraph=ySet.shift\nwhile !ySet.empty?\n next unless ySet.reject{|v|(connectedGraph&v).empty?}.each{|v|connectedGraph|=ySet.delete(v)}.empty?\n disjointCount+=1\n connectedGraph=ySet.shift\nend\nprint disjointCount"}, {"source_code": "xMap=Hash.new([])\ngets.to_i.times{\n Hash[*gets.scan(/(\\d+) (\\d+)/)]\n xMap[$1.to_i]+=Array[$2.to_i]\n}\n\ndisjointCount=0\nset=xMap.delete(xMap.keys.first)\nwhile !xMap.empty?\n next if !xMap.values.select{|v|!(set&v).empty?}.each{|v|set|=xMap.delete(xMap.key(v))}.empty?\n disjointCount+=1\n set=xMap.delete(xMap.keys.first)\nend\nprint disjointCount"}], "negative_code": [{"source_code": "class Drift\n attr_reader :x, :y\n attr_accessor :zone\n def initialize(x, y)\n @x = x\n @y = y\n @zone = nil;\n end\nend\n\nn = gets.to_i\nmap = Array.new(n)\nfor i in 0...n\n input = gets.split\n map[i] = Drift.new(input[0].to_i, input[1].to_i)\nend\n\nz = 0\nfor i in 0...n\n if map[i].zone == nil\n map[i].zone = z\n for j in (i+1)...n\n map[j].zone = z unless map[i].x != map[j].x && map[i].y != map[j].y\n end\n z += 1\n end\nend\nprint z-1"}, {"source_code": "ys=Array.new(gets.to_i){gets.scan(/(\\d+) (\\d+)/).first}.map{|v|{v[0]=>Array[v[1]]}}.inject{|h, n|h.update(n){|k, sv, ov|sv+ov}}.values\nprint ys.map{|v|ys.reject{|ov|(v&ov).empty?}.inject(:|)}.uniq.size-1"}, {"source_code": "n = gets.to_i\nli = []\n(1..n).each do\n x, y = gets.split.collect{|i| i.to_i}\n li.push([[x],[y]])\nend\nans = 0\nfor i in (n-1).downto(0)\n for j in 0...i\n unless (li[j][0]&li[i][0]).empty? and (li[j][1]&li[i][1]).empty?\n li[i][0] |= li[j][0]\n li[i][1] |= li[j][1]\n ans -= 1\n break\n end\n end\n ans += 1\nend\nputs ans-1\n"}], "src_uid": "cb4dbff31d967c3dab8fe0495eb871dc"} {"source_code": "tc = gets.to_i \n\ntc.times do \n n = gets.to_i \n arr = gets.split().map(&:to_i) \n\n i = 0 \n while(i < n) \n if(arr[i] > 1) \n i += 1 \n break \n end\n i += 1\n end\n i -= 1\n if(i% 2 == 0) \n puts \"First\"\n else\n puts \"Second\"\n end\nend", "positive_code": [{"source_code": "t = gets.to_i\n\n1.upto t do |z|\n n = gets.to_i\n a = gets.split.map(&:to_i)\n c = 0\n \n if n == 1\n c = 0\n else\n 0.upto n-1 do |i|\n if a[i] == 1\n c += 1\n else\n break\n end\n end\n end\n\n if c == n\n if c.odd?\n puts \"First\"\n else\n puts \"Second\"\n end\n else\n if c.even? or c == 0\n puts \"First\"\n else\n puts \"Second\"\n end\n end\nend"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map &:to_i\n k = 0\n k += 1 while k < n && a[k] == 1\n if k == n\n res = k % 2 == 0 ? \"Second\" : \"First\"\n else\n res = k % 2 == 0 ? \"First\" : \"Second\"\n end\n puts res\nend"}], "negative_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map &:to_i\n k = 0\n k += 1 while k < n && a[k] == 1\n if k == n\n res = k % 2 == 0 ? \"Secobd\" : \"First\"\n else\n res = k % 2 == 0 ? \"First\" : \"Second\"\n end\n puts res\nend"}], "src_uid": "0c9030689394ad4e126e5b8681f1535c"} {"source_code": "n = gets.chomp.to_i\nn2 = gets.chomp\n\narr = n2.split(\" \")\narr2 = arr.collect{|i| i.to_i}\n\ndef thanatus(input, n)\n\tif isSorted(input, n)\n\t\tputs input.length\n\telse\n\t\tif snap(input.slice(0, n/2), n/2) > snap(input.slice(n/2, n), n/2)\n\t\t\tthanatus(input.slice(0, n/2), n/2)\n\t\telse\n\t\t\tthanatus(input.slice(n/2, n), n/2)\n\t\tend\n\tend\nend\n\ndef snap(a, b)\n\tif isSorted(a, b)\n\t\treturn a.length\n\telse\n\t\treturn 1\n\tend\nend\n\ndef isSorted(arr, n)\n\t\tfor i in (1...n)\n\t\t\t\tif arr[i-1] > arr[i]\n\t\t\t\t\treturn false\n\t\t\t\tend\n\t\t\tend\n\t\treturn true\nend\n\nthanatus(arr2, n)", "positive_code": [{"source_code": " def test \n input = $stdin.read\n input = input.split(\"\\n\")\n length = input[0].to_i\n array = input[1].split(\" \").map(&:to_i)\n return array\n end \n def check(array,out)\n \n if array == array.sort\n out.push(array.length) \n \n return array,out\n else\n array1 = array.slice(0,(array.length/2))\n array2 = array.slice((array.length/2),array.length)\n array,out = check(array1,out)\n array,out = check(array2,out)\n end\n return array , out \n end\n array = test\n array5,out = check(array,[])\n puts out.max"}, {"source_code": "# http://codeforces.com/problemset/problem/1145/A\ngets\narr = gets.split.map &:to_i\n\ndef sorted?(arr)\n return true if arr.length == 1\n\n arr.each_cons(2).all? do |(l, r)|\n l <= r\n end\nend\n\ndef max_length(arr)\n\n if sorted?(arr)\n return arr.length\n else\n return [max_length(arr.slice(0, arr.length / 2)), max_length(arr.slice(arr.length / 2, arr.length))].max\n end\nend\n\nputs max_length(arr)\n"}, {"source_code": "def tanos_sort(array)\n n = array.size\n\n return n if sorted?(array)\n\n a1 = array.take(n / 2)\n a2 = array.last(n / 2)\n\n res1 = tanos_sort(a1)\n res2 = tanos_sort(a2)\n\n res1 > res2 ? res1 : res2\nend\n\ndef sorted?(array)\n array == array.sort\nend\n\n_n = gets.to_i\narray = gets.split(\" \").map(&:to_i)\nputs tanos_sort(array)"}, {"source_code": "@result = 0\n\ndef snap(array)\n @result = array.count if array == array.sort && array.count > @result\n return array.count if array == array.sort\n\n head, tail = array.each_slice(array.count / 2).to_a\n snap(head)\n snap(tail)\nend\n\nsnap(STDIN.read.split(\"\\n\").last.split.map(&:to_i))\nputs @result\n"}], "negative_code": [{"source_code": "# http://codeforces.com/problemset/problem/1145/A\ngets\narr = gets.split.map &:to_i\n\ndef sorted?(arr)\n return true if arr.length == 1\n\n arr.each_cons(2).all? do |(l, r)|\n l <= r\n end\nend\n\ndef max_length(arr)\n if sorted?(arr)\n return arr.length\n else\n return [max_length(arr[0, arr.length / 2]), max_length(arr[arr.length / 2 + 1, arr.length])].max\n end\nend\n\nputs max_length(arr)\n"}, {"source_code": "def snap(array)\n return array.count if array == array.sort\n\n head, tail = array.each_slice(array.count / 2).to_a\n snap(head)\n snap(tail)\nend\n\narray = STDIN.read.split(\"\\n\").last.split.map(&:to_i)\nputs snap(array)\n"}, {"source_code": "def test \n input = $stdin.read\n input = input.split(\"\\n\")\n length = input[0].to_i\n array = input[1].split(\" \").map(&:to_i)\n return array\n end \n def check array \n if array == array.sort\n puts array.length\n return\n else\n array = array.slice(0,(array.length/2)) \n array = check(array)\n end\n \n end\n array = test\n array = check(array)"}, {"source_code": " def test \n input = $stdin.read\n input = input.split(\"\\n\")\n length = input[0].to_i\n array = input[1].split(\" \").map(&:to_i)\n return array\n end \n def check array \n if array == array.sort\n puts array.length\n return\n else\n array = array.slice(0,(array.length/2)-1) \n check(array)\n end\n \n end\n array = test\n array = check(array)"}, {"source_code": "n = gets.chomp.to_i\nn2 = gets.chomp\n\narr = n2.split(\" \")\narr2 = arr.collect{|i| i.to_i}\n\ndef thanatus(input, n)\n\tif n == 2\n\t\tif input[0] > input[1]\n\t\t\tputs 1\n\t\telse\n\t\t\tputs 2\n\t\tend\n\telse\n\t\tif isSorted(input, n)\n\t\t\tputs input.length\n\t\telse\n\t\t\tif input[0] == 41\n\t\t\t\tthanatus(input.slice(0, n/2), n/2)\n\t\t\telsif input[0] == 78\n\t\t\t\tthanatus(input.slice(n/2, n), n/2)\n\t\t\telsif input[0] == 73\n\t\t\t\tthanatus(input.slice(0, n/2), n/2)\n\t\t\telsif input[0] % 2 != 0\n\t\t\t\tthanatus(input.slice(n/2, n), n/2)\n\t\t\telsif\n\t\t\t\tthanatus(input.slice(0, n/2), n/2)\n\t\t\tend\n\t\tend\n\tend\nend\n\ndef isSorted(arr, n)\n\t\tfor i in (1...n)\n\t\t\t\tif arr[i-1] > arr[i]\n\t\t\t\t\treturn false\n\t\t\t\tend\n\t\t\tend\n\t\treturn true\nend\n\nthanatus(arr2, n)\n"}, {"source_code": "n = gets.chomp.to_i\nn2 = gets.chomp\n\narr = n2.split(\" \")\narr2 = arr.collect{|i| i.to_i}\n\ndef thanatus(input, n)\n\tif n == 2\n\t\tif input[0] > input[1]\n\t\t\tputs 1\n\t\telse\n\t\t\tputs 2\n\t\tend\n\telse\n\t\tif isSorted(input, n)\n\t\t\tputs input.length\n\t\telse\n\t\t\tthanatus(input.slice(0, n/2), n/2)\n\t\tend\n\tend\nend\n\ndef isSorted(arr, n)\n\t\tfor i in (1...n)\n\t\t\t\tif arr[i-1] > arr[i]\n\t\t\t\t\treturn false\n\t\t\t\tend\n\t\t\tend\n\t\treturn true\nend\n\nthanatus(arr2, n)"}, {"source_code": "n = gets.chomp.to_i\nn2 = gets.chomp\n\narr = n2.split(\" \")\narr2 = arr.collect{|i| i.to_i}\n\ndef thanatus(input, n)\n\tputs input[0]\n\tif n == 2\n\t\tif input[0] > input[1]\n\t\t\tputs 1\n\t\telse\n\t\t\tputs 2\n\t\tend\n\telse\n\t\tif isSorted(input, n)\n\t\t\tputs input.length\n\t\telse\n\t\t\tif input[0] == 41\n\t\t\t\tthanatus(input.slice(0, n/2), n/2)\n\t\t\telsif input[0] == 78\n\t\t\t\tthanatus(input.slice(n/2, n), n/2)\n\t\t\telsif input[0] % 2 != 0\n\t\t\t\tthanatus(input.slice(n/2, n), n/2)\n\t\t\telsif\n\t\t\t\tthanatus(input.slice(0, n/2), n/2)\n\t\t\tend\n\t\tend\n\tend\nend\n\ndef isSorted(arr, n)\n\t\tfor i in (1...n)\n\t\t\t\tif arr[i-1] > arr[i]\n\t\t\t\t\treturn false\n\t\t\t\tend\n\t\t\tend\n\t\treturn true\nend\n\nthanatus(arr2, n)\n"}, {"source_code": "n = gets.chomp.to_i\nn2 = gets.chomp\n\narr = n2.split(\" \")\narr2 = arr.collect{|i| i.to_i}\n\ndef thanatus(input, n)\n\tif n == 2\n\t\tif input[0] > input[1]\n\t\t\tputs 1\n\t\telse\n\t\t\tputs 2\n\t\tend\n\telse\n\t\tif isSorted(input, n)\n\t\t\tputs input.length\n\t\telse\n\t\t\tif n == 16\n\t\t\t\tthanatus(input.slice(n/2, n), n/2)\n\t\t\telse\n\t\t\t\tthanatus(input.slice(0, n/2), n/2)\n\t\t\tend\n\t\tend\n\tend\nend\n\ndef isSorted(arr, n)\n\t\tfor i in (1...n)\n\t\t\t\tif arr[i-1] > arr[i]\n\t\t\t\t\treturn false\n\t\t\t\tend\n\t\t\tend\n\t\treturn true\nend\n\nthanatus(arr2, n)\n"}, {"source_code": "n = gets.chomp.to_i\nn2 = gets.chomp\n\narr = n2.split(\" \")\narr2 = arr.collect{|i| i.to_i}\n\ndef thanatus(input, n)\n\tif n == 2\n\t\tif input[0] > input[1]\n\t\t\tputs 1\n\t\telse\n\t\t\tputs 2\n\t\tend\n\telse\n\t\tif isSorted(input, n)\n\t\t\tputs input.length\n\t\telse\n\t\t\tif input[0] == 41\n\t\t\t\tthanatus(input.slice(0, n/2), n/2)\n\t\t\telsif input[0] == 78\n\t\t\t\tthanatus(input.slice(n/2, n), n/2)\n\t\t\telsif input[0] % 2 != 0\n\t\t\t\tthanatus(input.slice(n/2, n), n/2)\n\t\t\telsif\n\t\t\t\tthanatus(input.slice(0, n/2), n/2)\n\t\t\tend\n\t\tend\n\tend\nend\n\ndef isSorted(arr, n)\n\t\tfor i in (1...n)\n\t\t\t\tif arr[i-1] > arr[i]\n\t\t\t\t\treturn false\n\t\t\t\tend\n\t\t\tend\n\t\treturn true\nend\n\nthanatus(arr2, n)\n"}], "src_uid": "e5c68be38968fbc9677f3c1adddaff58"} {"source_code": "s = [nil] + gets.chomp.chars\nn = gets.to_i\nc = Array.new(s.size / 2 + 1, 0)\na = gets.split.map(&:to_i).each{|x| c[x] += 1}\nfor i in 2...c.size do\n c[i] += c[i - 1]\nend\nfor i in 1...c.size do\n if c[i] % 2 == 0\n next\n else\n s[i], s[s.size - i] = s[s.size - i], s[i]\n end\nend\nputs s.join(\"\")\n", "positive_code": [{"source_code": "s = gets.chomp.split('')\nm = gets.to_i\ncnt = Array.new((s.length+1)/2+1,0)\ngets.split.collect{|i| cnt[i.to_i]+=1}\nfor i in 1..(s.length+1)/2\n cnt[i] = (cnt[i-1]+cnt[i])%2\n if cnt[i] > 0\n s[i-1], s[s.length-i] = s[s.length-i], s[i-1]\n end\nend\nputs s.join\n"}, {"source_code": "# f = File.open 'input.txt', 'r'\nf = STDIN\n\ndef compute(s, positions)\n marked_positions = Hash.new(0)\n positions.each do |pos|\n marked_positions[pos] += 1\n end\n be_changed = false\n 1.upto(s.length/2) do |index|\n # index - 1 && s.length - index\n be_changed = !be_changed if marked_positions[index].odd?\n if be_changed\n tmp = s[index - 1]\n s[index - 1] = s[s.length - index]\n s[s.length - index] = tmp\n end\n end\n s\nend\n\nwhile true\n raw_s = f.gets\n break unless raw_s\n s = raw_s.chomp\n m = f.gets.chomp.to_i\n positions = f.gets.chomp.split.map &:to_i\n puts compute(s, positions)\nend\n"}], "negative_code": [{"source_code": "s = [nil] + gets.chomp.chars\nn = gets.to_i\nc = Array.new(s.size / 2 + 1, 0)\na = gets.split.map(&:to_i).each{|x| c[x] += 1}\nfor i in 2...c.size do\n c[i] += c[i - 1]\nend\np c\nfor i in 1...c.size do\n if c[i] % 2 == 0\n next\n else\n s[i], s[s.size - i] = s[s.size - i], s[i]\n end\nend\nputs s.join(\"\")\n"}, {"source_code": "# f = File.open 'input.txt', 'r'\nf = STDIN\n\ndef compute(s, positions)\n marked_positions = Hash.new(0)\n positions.each do |pos|\n marked_positions[pos] += 1\n end\n be_changed = false\n 1.upto(s.length/2) do |index|\n # index - 1 && s.length - index\n be_changed = !be_changed if marked_positions[index].odd?\n if be_changed\n tmp = s[index - 1]\n s[index - 1] = s[s.length - index]\n s[s.length - index] = tmp\n end\n end\n s\nend\n\nwhile true\n raw_s = f.gets\n break unless raw_s\n s = raw_s.chomp\n m = f.gets.chomp.to_i\n positions = f.gets.chomp.split.map &:to_i\n p compute(s, positions)\nend\n"}], "src_uid": "9d46ae53e6dc8dc54f732ec93a82ded3"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).map do |x|\n x /= 2 while x % 2 == 0\n x /= 3 while x % 3 == 0\n x\nend\na = a.sort\nputs a[0] == a[-1] ? 'Yes' : 'No'\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nn.times do |i|\n a[i] /= 2 while a[i] % 2 == 0\n a[i] /= 3 while a[i] % 3 == 0\nend\nputs a.uniq.one? ? 'Yes' : 'No'\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nn.times do |i|\n while a[i] % 2 == 0 || a[i] % 3 == 0\n if a[i] % 6 == 0\n a[i] /= 6\n elsif a[i] % 3 == 0\n a[i] /= 3\n elsif a[i] % 2 == 0\n a[i] /= 2\n end\n end\nend\nputs a.uniq.one? ? 'Yes' : 'No'\n"}, {"source_code": "def function(x)\n while x%2==0\n x/=2\n end\n while x%3==0\n x/=3\n end\n return x\nend \n\n\nn = gets\narr = gets.split.map(&:to_i)\nnew = []\narr.each do|x|\n new << function(x)\nend\nnew.sort!\nif new[0]==new[-1]\n puts 'Yes'\nelse\n puts 'No'\nend "}, {"source_code": "def f(x)\n x /= 2 until x % 2 > 0\n x /= 3 until x % 3 > 0\n x\nend\n\nn = gets.to_i\nx, *a = gets.split.map &:to_i\nx = f(x)\nputs a.all?{|y| f(y) == x} ? 'Yes' : 'No'\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nm1=x.max\nok=\"No\"\nif x.all?{|e|\n\te2=m1.lcm(e)/m1.gcd(e)\n\twhile e2%2==0\n\t\te2/=2\n\tend\n\twhile e2%3==0\n\t\te2/=3\n\tend\n\te2==1\n} then\n\tok=\"Yes\"\nend\nputs ok\n\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nar = gets.split.map(&:to_i)\n\n# ar\ub0b4\uc758 \ubaa8\ub4e0 n\uc5d0 \ub300\ud574\uc11c 2\ubc30, 3\ubc30\ub97c \ud574\uc11c \uac19\uc740 \uc22b\uc790\ub97c \uc5bb\uc73c\ub824\uba74\n# 2\uc640 3\uc744 \ubaa8\ub450 \uc81c\uac70\ud588\uc744 \ub54c \ub0a8\uc740 \uc218\uac00 \ubaa8\ub450 \uac19\uc544\uc57c\ud55c\ub2e4.\nsay_yes = true\ndef remove_2s_3s(num)\n loop do\n if num%2 == 0\n num = num/2\n next\n elsif num%3 == 0\n num = num/3\n next\n else\n break\n end\n end\n return num\nend\n\nbase = remove_2s_3s(ar.first)\n\nar.each { |i|\n if base != remove_2s_3s(i)\n say_yes = false\n end\n}\n\nif say_yes\n puts \"Yes\"\nelse\n puts \"No\"\nend"}, {"source_code": "#!/usr/bin/ruby\n\ndef solution(n, arr)\n uniq = arr.uniq do |n|\n while n % 2 == 0\n n /= 2\n end\n while n % 3 == 0\n n /= 3\n end\n n\n end\n\n puts uniq.size == 1 ? 'Yes' : 'No'\n\nend\n\nn = gets.to_i\narr = gets.split(' ').map{|i| i.to_i}\nsolution n, arr\n#\n# solution 4, [75, 150, 75, 50]\n# solution 3, [100, 150, 250]"}, {"source_code": "gets\nmas = gets.split(\" \").map(&:to_i)\n\nfor k in 0...mas.size do\n mas[k]/=2 while mas[k]%2==0\n mas[k]/=3 while mas[k]%3==0\nend\n\nchk = 1\nfor k in 1...mas.size do\n chk = 0 if mas[k]!=mas[0]\nend\n\nprint chk==1 ? \"YES\" : \"NO\"\n"}, {"source_code": "def divide23(n)\n\tn /= 2 while n%2 == 0\n\tn /= 3 while n%3 == 0\n\treturn n\nend\nn = gets.chomp.to_i\narr = gets.chomp.split(\" \").map {|val| val = val.to_i}\narr.map!{ |val| val = divide23(val)}\nallsame=true\narr.each { |val| allsame = false unless val == arr[0]}\nputs \"Yes\" if allsame\nputs \"No\" unless allsame\n"}, {"source_code": "n = gets.chomp.to_i;\narr = gets.chomp.split.map(&:to_i);\n\nn.times do |x|\n arr[x] /= 2 while (arr[x] % 2 == 0)\n arr[x] /= 3 while (arr[x] % 3 == 0);\nend\nputs (arr.uniq.size == 1 ? \"Yes\" : \"No\");"}, {"source_code": "#!/usr/bin/ruby\n\ndef check(l, a)\n k = l / a\n while k % 2 == 0\n k /= 2\n end\n while k % 3 == 0\n k /= 3\n end\n k == 1 ? true : false\nend\n\ndef gcd(a, b)\n a, b = b, a if a < b\n # return a if b == 0\n # gcd(b, a % b)\n while b != 0\n a, b = b, a % b\n end\n a\nend\n\ndef lcm(a, b)\n (a * b) / gcd(a, b)\nend\n\ndef algo\n n = gets.to_i\n v = gets.split(' ').map { |e| e.to_i }\n p = v[0]\n flag = 1\n for i in v\n l = lcm(p, i)\n if not (check(l, p) && check(l, i))\n flag = 0\n break\n end\n p = i\n end\n puts flag == 1 ? \"Yes\" : \"No\"\nend\n\nalgo\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).map do |x|\n x /= 2 while x % 2 == 0\n x /= 3 while x % 3 == 0\n x\nend\nputs a.max == a.min ? 'Yes' : 'No'\n"}, {"source_code": "k = gets.to_i\n\nq = gets.split.map(&:to_i)\no = []\n\nq.each do |e|\n n = e.to_i\n\n status = true\n\n loop do\n if n % 2 == 0\n n /= 2\n elsif n % 3 == 0\n n /= 3\n else\n status = false if n > 1\n o << n\n break\n end\n end\n\nend\n\no.uniq!\n\nputs o.size == 1 ? 'Yes' : 'No'"}, {"source_code": "n = gets.to_i\nres = -1\na = gets.split(' ').map(&:to_i)\na.each do |i|\n while i % 2 == 0\n i /= 2\n end\n while i % 3 == 0\n i /= 3\n end\n if res == -1\n res = i\n elsif res != i\n puts \"No\"\n exit\n end\nend\nputs \"Yes\""}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split(' ').map(&:to_i)\n\nbs = []\nas.each do |a|\n b = a\n while b % 2 == 0\n b /= 2\n end\n while b % 3 == 0\n b /= 3\n end\n bs << b\nend\n\nbs.sort!\nif bs[0] == bs[-1]\n puts 'Yes'\nelse\n puts 'No'\nend\n"}], "negative_code": [{"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nm1=x.max\nok=\"No\"\nif x.all?{|e|\n\te2=e/m1.gcd(e)\n\twhile e2%2==0\n\t\te2/=2\n\tend\n\twhile e2%3==0\n\t\te2/=3\n\tend\n\te2==1\n} then\n\tok=\"Yes\"\nend\nputs ok\n\n\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nm1=x.max\nm2=m1\nok=\"No\"\n2.times{\n\tif x.all?{|e|\n\t\t(m1%e==0) && (m1/e<4)\n\t} then\n\t\tok=\"Yes\"\n\tend\n\tm1+=m2\n}\nputs ok\n\n"}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\nm1=x.max\nok=\"No\"\nif x.all?{|e|\n\te2=m1/m1.gcd(e)\n\twhile e2%2==0\n\t\te2/=2\n\tend\n\twhile e2%3==0\n\t\te2/=3\n\tend\n\te2==1\n} then\n\tok=\"Yes\"\nend\nputs ok\n\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\nar = gets.split.map(&:to_i)\n\n# for every n...\n# how many 2's, 3's ? and remains?\nar_max = ar.max\nsay_yes = true\nar.each { |i| \n r = ar_max%i\n if r > 0\n say_yes = false\n break\n end\n}\n\nif say_yes\n puts \"Yes\"\nelse\n puts \"No\"\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).map do |x|\n x /= 2 if x % 2 == 0\n x /= 3 if x % 3 == 0\n x\nend\na = a.sort\nputs a[0] == a[-1] ? 'Yes' : 'No'\n"}], "src_uid": "2bb893703cbffe9aeaa0bed02f42a05c"} {"source_code": "n=gets.to_i\nputs$<.map{|e|e.split.map &:to_i}.transpose.map{|e|e.reduce(:+)/n}*' '", "positive_code": [{"source_code": "def solution\n n = read_int\n sumx = 0\n sumy = 0\n (n * 2).times do\n x, y = read_ints\n sumx += x\n sumy += y\n end\n tx = sumx / n\n ty = sumy / n\n\n puts \"#{tx} #{ty}\"\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"}], "negative_code": [], "src_uid": "ba526a7f29cf7f83afa0b71bcd06e86b"} {"source_code": "N = gets.to_i\nN.times {\n n = gets.to_i\n s = gets.chomp\n p [s.match(/^<*/)[0].size, s.match(/>*$/)[0].size].min\n}\n", "positive_code": [{"source_code": "gets.to_i.times{\n\tn = gets.to_i;\n\ts = gets.chomp;\n\tif s =~ /^<*<>|<>>*$/\n\t\tp [ s[/^<*/]||'', s[/>*$/]||'' ].map(&:length).min;\n\telse\n\t\tp 0;\n\tend\n}\n\n\n# <<<<<<<<<<<<>>>>>>>>>>>>><>>>>>>>>>>\n\n#\u00a0< > <\n"}], "negative_code": [{"source_code": "N = gets.to_i\nN.times {\n n = gets.to_i\n s = gets.chomp\n p (s[0] == \">\" || s[-1] == \"<\") ? 0 : 1\n}\n"}, {"source_code": "gets.to_i.times{\n\tn = gets.to_i;\n\ts = gets.chomp;\n\tputs s =~ /^<*<>|<>>*$/ ? 1 : 0;\n}\n\n\n# <<<<<<<<<<<<>>>>>>>>>>>>><>\n"}, {"source_code": "gets.to_i.times{\n\tn = gets.to_i;\n\ts = gets.chomp;\n\tputs s =~ /<>/ ? 1 : 0;\n}\n"}, {"source_code": "gets.to_i.times{\n\tn = gets.to_i;\n\ts = gets.chomp;\n\tputs s =~ /^[^>]*<>[^<]*$/ ? 1 : 0;\n}\n"}], "src_uid": "0ba97bcfb5f539c848f2cd097b34ff33"} {"source_code": "num_friends = STDIN.gets.chomp(\"\\n\").to_i\nprefs = Hash.new\nfor i in (1..num_friends)\n prefs[i] = STDIN.gets.chomp(\"\\n\").split(\" \")\nend\n\nown_prefs = STDIN.gets.chomp(\"\\n\").split(\" \")\n\noutput = []\nfor i in (1..num_friends)\n possible = []\n prev = 1000\n own_prefs.each{|val|\n val = val.to_i\n next if val == i or val > prev\n prev = val\n possible << val\n }\n \n prefs[i].each{|val|\n val = val.to_i\n if possible.index(val)\n output << val\n break\n end\n }\nend\n\nputs output.join(\" \")", "positive_code": [{"source_code": "#! /usr/bin/ruby\n\nnum_friends = STDIN.gets.chomp(\"\\n\").to_i\nprefs = Hash.new\nfor i in (1..num_friends)\n prefs[i] = STDIN.gets.chomp(\"\\n\").split(\" \")\nend\n\nown_prefs = STDIN.gets.chomp(\"\\n\").split(\" \")\n\noutput = []\nfor i in (1..num_friends)\n possible = []\n prev = 1000\n own_prefs.each{|val|\n val = val.to_i\n next if val == i or val > prev\n prev = val\n possible << val\n }\n \n prefs[i].each{|val|\n val = val.to_i\n if possible.index(val)\n output << val\n break\n end\n }\nend\n\nputs output.join(\" \")"}, {"source_code": "n = gets.chomp.to_i\nna = []\nfor i in 0..n-1\n wk = gets.chomp.split(/ /).map!{|x| x.to_i}\n wk.delete(i+1)\n na << wk\nend\naa = gets.chomp.split(/ /).map!{|x| x.to_i}\nfor i in 0..n-1\n x = aa[i]\n j = i-1\n revcnt = 0\n revx = 0\n while j >= 0 && revcnt <= 2\n if aa[j] < x\n revcnt += 1\n revx = aa[j]\n end\n j -= 1\n end\n for k in 0..n-1\n if revcnt >= 2 || (revcnt == 1 && (k+1) != revx)\n na[k].delete(x)\n end\n end\nend\nret = []\nfor i in 0..n-1\n ret << na[i][0]\nend\nputs ret.join(\" \")\n"}, {"source_code": "n = gets.to_i\nt_preference = Array.new(n + 1)\ncard_pref = Array.new(n + 1)\nalex = Array.new(n + 1)\nfor i in 1 .. n\n\tt_preference[i] = Array.new(n + 1)\n\tcard_pref[i] = Array.new(n + 1)\n\t\n\ta = gets.split\n\tfor j in 1 .. n\n\t\tt_preference[i][a[j - 1].to_i] = j\n\tend\nend\n\na = gets.split\nfor j in 1 .. n\n\talex[j] = a[j - 1].to_i\nend\n\nfor i in 1 .. n\n\tfirst = 0\n\tsecond = 0\n\tfor j in 1 .. n\n\t\tif alex[j] <= i then\n\t\t\tif first == 0 then first = alex[j]\n\t\t\telse\n\t\t\t\tsecond = alex[j]\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\n\t\n\tfor j in 1 .. n\n\t\tif j == first then card = second\n\t\telse card = first end\n\t\tif card == 0 then card_pref[i][j] = 0\n\t\telse card_pref[j][i] = t_preference[j][card] end\n\tend\nend\n\nans = Array.new(n)\n\nfor i in 1 .. n\n\tmin = n + 1\n\tidx = 0\n\tfor j in 1 .. n\n\t\tif card_pref[i][j] != 0 then\n\t\t\tif card_pref[i][j] < min then\n\t\t\t\tmin = card_pref[i][j]\n\t\t\t\tidx = j\n\t\t\tend\n\t\tend\n\tend\n\tans[i - 1] = idx\nend\n\nputs ans.join(\" \")"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn = $stdin.gets.to_i\nm = Array.new(n) { Array.new(n) }\nn.times do |i|\n $stdin.gets.split(/\\s+/).map(&:to_i).each_with_index do |x, j|\n m[i][x-1] = j\n end\nend\nalex = Array.new n\n$stdin.gets.split(/\\s+/).map(&:to_i).each_with_index do |x, j|\n alex[x-1] = j\nend\n\nans = Array.new n\nc1 = nil\nc2 = nil\nn.times do |i|\n if c1.nil?\n c1 = i\n elsif c2.nil?\n if alex[i] < alex[c1]\n c1, c2 = i, c1\n else\n c2 = i\n end\n elsif alex[i] < alex[c1]\n c1, c2 = i, c1\n elsif alex[i] < alex[c2]\n c2 = i\n end\n\n ans.each_with_index do |a, j|\n c = c1 == j ? c2 : c1\n next if c.nil?\n if ans[j].nil? or m[j][ans[j]] > m[j][c]\n ans[j] = c\n end\n end\nend\nputs ans.map(&:succ).join(' ')\n"}], "negative_code": [{"source_code": "#! /usr/bin/ruby\n\nnum_friends = STDIN.gets.chomp(\"\\n\").to_i\nprefs = Hash.new\nfor i in (1..num_friends)\n prefs[i] = STDIN.gets.chomp(\"\\n\").split(\" \")\nend\n\nown_prefs = STDIN.gets.chomp(\"\\n\").split(\" \")\n\noutput = []\nfor i in (1..num_friends)\n possible = []\n prev = 1000\n own_prefs.each{|val|\n val = val.to_i\n next if val == i\n break if val > prev\n prev = val\n possible << val\n }\n \n prefs[i].each{|val|\n val = val.to_i\n if possible.index(val)\n output << val\n break\n end\n }\nend\n\nputs output.join(\" \")"}], "src_uid": "d8f8be420c1d9553240708f28f8ba4b2"} {"source_code": "#!/usr/bin/env ruby\n\nm, n = gets.split.map(&:to_i)\nans = 0.0\n(1..m).each do |k|\n ans += k * (((k.to_f/m) ** n) - ((k-1.to_f) / m) ** n)\nend\n\nprintf \"%.8f\\n\", ans\n", "positive_code": [{"source_code": "# E = Sum(k=1..m, P(k)), where P(k) - probability k is max of n throws\n# k = max x(i)\n# P(k) = P(x <= k) - P(x < k) (at least on x = k achieved)\n# P(x <= k) = (k/m)^n\n# P(x < k) = ((k-1)/m)^n\n\nclass C\n\n def c(n, k)\n\n end\n\n def run\n m, n = $stdin.gets.split(' ').map &:to_i\n e = 0.0\n\n (1..m).each do |k|\n pk = (1.0 * k / m) ** n - (1.0 * (k - 1) / m) ** n\n e += k * pk\n end\n\n puts e\n end\n\nend\n\nC.new.run if __FILE__ == $0"}, {"source_code": "m, n = gets.split.map &:to_i\n\nans = m\n\n1.upto(m - 1) do |i|\n ans -= (i.to_f / m) ** n\nend\nputs ans\n"}, {"source_code": "m, n = gets.split.map{|x| x.to_i}\np (1..m).map{|x| 1.0 * x * ( ( 1.0 * x / m ) ** n - ( 1.0 * ( x - 1 ) / m ) ** n )}.inject(:+)\n"}, {"source_code": "m, n = gets.chomp.split.map{|i| i.to_i}\n\n\nans = 0\npnow = 0.0\n\nm.downto(1).each do |i|\n\tlower = 1 - ((m-i)/m.to_f)**n\n\tans += (lower - pnow) * i\n\tpnow = lower\nend\n\nputs ans\n"}, {"source_code": "def bin_pow(a,b)\n\ta=a.to_i\n\tb=b.to_i\n\tr=1\n\twhile (b>0)\n\t\tif (b&1!=0)\n\t\t\tr*=a\n\t\tend\n\t\ta*=a\n\t\tb>>=1\n\tend\n\treturn r\nend\n\n(m,n)=gets.split.map{|x| x.to_i}\nm=m.to_f\nans=m\ni=1\nwhile (i 10000000000\n }\n return true\nend\n\ndef solve(m, n)\n if m == 1\n return 1.0\n end\n p \"@solve: m = #{m}, n = #{n}\"\n res = 0.0\n (1..m).each {|x|\n if x == 1\n res += 1.0\n elsif x == m\n else\n t = 1.0 * x / m\n p t\n end\n }\n return -1\n return (1..m).map{|x| x * ( x ** n - ( x - 1 ) ** n )}.inject(:+) * ( 1.0 / m ** n )\nend\n\nputs solve *gets.split.map{|x| x.to_i}\n\n# m, n = gets.split.map{|x| x.to_i}\n# puts (1..m).map{|x| x * ( x ** n - ( x - 1 ) ** n )}.inject(:+) * ( 1.0 / m ** n )\n"}], "src_uid": "f70ac2c4e0f62f9d6ad1e003aedd86b2"} {"source_code": "total_goals = gets.chomp.to_i\nteams = {}\ntotal_goals.times do\n team = gets.chomp\n if !teams.has_key? team\n teams.store team, 1\n else\n teams[team] += 1\n end\nend\nmax_goals = teams.values.max\nwinner = teams.select { |k, v| v == max_goals }.to_a[0][0]\nputs winner\n", "positive_code": [{"source_code": "$><<(s=$<.sort)[s.size/2]"}, {"source_code": "n=gets.to_i\nx=gets.chomp\na=[1,0]\ny=nil\nn-=1\nn.times do\n\tl=gets.chomp\n\tif x==l\n\t\ta[0]+=1\n\telse\n\t\ta[1]+=1\n\t\tif !y\n\t\t\ty=l\n\t\tend\n\tend\nend\nputs a[0]>a[1]? x : y"}, {"source_code": "gets\nputs (a = gets(p).split).max_by { |x| a.count x }"}, {"source_code": "n = gets.to_i\na = Array.new(n)\n\nfor i in 0..n-1\n a[i] = gets.to_s.chomp\nend\nif n == 1 \n puts a[0]\nelse\n counter = 0\n for i in 1..n-1\n if a[i] != a[0]\n d = a[i]\n counter +=1\n end\n end\n\n f = a.length\n if counter > f/2\n puts d \n else\n puts a[0]\n end\n end"}, {"source_code": "$><<(s=$<.sort)[s.size/2]\n"}, {"source_code": "$><<(s=$<.sort)[s.size/2]\n"}, {"source_code": "n=gets.to_i\nh=Hash.new(0)\nn.times{\n\ts=gets.chomp\n\th[s]+=1\n}\nc=0\nans=\"\"\nh.each{|k,v|\n\tif c<<(s=$<.sort)[s.size/2]"}, {"source_code": "n=gets.to_i\n\nhs=Hash.new(0)\nn.times{\n\ths[gets.chomp]+=1\n}\n\nmaxy=hs.values.max\nputs hs.invert[maxy]\n"}, {"source_code": "s = gets(p).split.sort\nputs s[s.size/2]"}, {"source_code": "n = 1\nt1, t2 = nil, nil\ngets.to_i.times do\n if t1\n t = gets.chomp\n n += t == t1 ? 1 : -1\n t2 = t if t != t1\n else\n t1 = gets.chomp\n end\nend\n\nputs n > 0 ? t1 : t2"}, {"source_code": "goals = STDIN.read.split\ngoals.shift\n\nresult = goals.inject(Hash.new(0)) { |score, team| score[team] += 1; score }\nputs result.max_by { |k,v| v } .first\n"}, {"source_code": "n = gets.to_i\nh = Hash.new\n(1..n).each do |x|\n s = gets\n if h[s] == nil then h[s] = 1 else h[s] = h[s] + 1 end\nend\nputs h.sort { |x,y| y[1] <=> x[1] }[0][0]"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nteams = {}\nn.times {\n name = gets.chomp\n teams[name] ||= 0\n teams[name] += 1\n}\nwinner_score = teams.values.max\nteams.each_pair { |k, v|\n if v == winner_score\n puts k\n end\n}"}, {"source_code": "$><<(s=$<.sort)[s.size/2]\n"}, {"source_code": "n = gets.to_i\ncount = Hash.new(0)\nn.times { \n\ta = gets.chomp\n\tcount[a] += 1\n}\nputs count.key(count.values.max)"}, {"source_code": "k=gets.to_i\nl=gets\nn=''\nmas=[1,0] \n(k-1).times{ m=gets\n m==l ?mas[0]+=1 :mas[1]+=1\n m==l ?l=m :n=m \n }\nputs mas[0]>mas[1] ?l:n"}, {"source_code": "n = gets.to_i\n\nmas = {\"abacabaabacaba\" => -1}\nfor i in 0..n-1\n s = gets\n if mas.has_key?(s)\n mas[s] += 1\n else\n mas[s] = 0\n end\nend\n\nresult = \"\"\nmax = -1\nmas.each do |key,value|\n if value > max\n max = value\n result = key\n end\nend\n\nputs result"}, {"source_code": "n = gets.to_i\nputs n.times.map{gets.chomp}.sort[(n - 1)/2]\n"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\nn.times{h[gets.chomp] += 1}\nputs h.max_by{|x, y| y}.first\n"}, {"source_code": "lines = []\n#\u8aad\u307f\u8fbc\u307f\nn = gets.chomp.to_i\nn.times {\n lines << gets.chomp\n}\n\n#\u30c1\u30fc\u30e0\u540d\u3092\u51fa\u3059\nteams = []\nlines.each { |str|\n if teams == []\n teams[0] = str\n elsif teams[0] != str\n teams[1] = str\n end\n}\n\n#\u5f97\u70b9\u3092\u51fa\u3059\nscores = [0, 0]\nlines.each { |str|\n if str == teams[0]\n scores[0] = scores[0] + 1\n elsif str == teams[1]\n scores[1] = scores[1] + 1\n end\n}\n\n#\u8868\u793a\nputs (if scores[0] > scores[1] then teams[0] else teams[1] end)\n"}, {"source_code": "goals = gets.chomp.to_i.times.map { gets.chomp }\na, b = 0, 0\ngoals.each { |team| team == goals[0] ? a += 1 : b += 1 }\nputs a > b ? goals[0] : (goals - [goals[0]])[0]"}, {"source_code": "c=Hash.new 0\n[*$<].drop(1).each{|w| c[w] += 1}\nputs c.max_by{|k,v| v}[0]"}, {"source_code": "$><<(s=$<.sort)[s.size/2]\n"}, {"source_code": "a = 1.upto(gets.to_i).map { gets.chomp }\n\nputs a.uniq.max { |p, q| a.count(p) <=> a.count(q) }\n"}, {"source_code": "commands = []\nfor _ in 1..Integer(gets.chomp)\n commands << gets.chomp\nend\nputs commands.inject(Hash.new(0)) { |h, e| h[e] += 1; h }.max_by { |k, v| v }.first"}, {"source_code": "$><<(s=$<.sort)[s.size/2]\n"}, {"source_code": "n = gets.to_i\n\ninput = Array.new(n) { gets.strip }\n\nteams = input.sort.uniq\ncount = teams.map { |team| input.count(team) }\n\nputs teams.max_by { |team| count[teams.index(team)] }\n"}, {"source_code": "gets\na=gets(p).split\n$><<<(s=$<.sort)[s.size/2]\n"}, {"source_code": "goals = gets.to_i\nh = {}\ngoals.times do |i|\n name = gets.chomp\n if h[name] then \n h[name] += 1\n else\n h[name] = 1\n end\nend\nmas = h.keys\nif mas.size > 1 then\n if h[mas[0]] > h[mas[1]] then\n puts mas[0]\n else\n puts mas[1]\n end\nelse\n puts mas[0]\nend\n"}, {"source_code": "h=Hash.new(0)\ngets.to_i.times{s=gets\nh[s]+=1}\nputs h.max{|x,y|x[1]<=>y[1]}[0]\n"}, {"source_code": "n=gets.to_i\nc={}\nfor i in 1..n do\n\tr=gets\n\tc[r]=c[r].to_i+1\nend\nmax=0\nmaxc=\"\"\nc.keys.each {|k| \n\tif c[k]>max\n\t\tmaxc=k\n\t\tmax=c[k]\n\tend\n}\nputs maxc"}, {"source_code": "puts [*$<][1..-1].group_by{|i|i}.max_by{|i,j|j.size}[0]"}, {"source_code": "$><<(s=$<.sort)[s.size/2]"}, {"source_code": "$><<(s=$<.sort)[s.size/2]\n"}, {"source_code": "$><<(s=$<.sort)[s.size/2]\n"}, {"source_code": "\ncount = gets.to_i\nr = {}\ncount.times{|n|\n s = gets\n if r[s] then\n r[s] += 1\n else\n r[s] = 1\n end\n}\n\nanswer = ''\ntmp = 0\nr.each {|team,point|\n if tmp <= point then\n answer = team\n tmp = point\n end\n}\n\nputs answer \n"}], "negative_code": [{"source_code": "\ncount = gets.to_i\nr = {}\ncount.times{|n|\n s = gets\n if r.value?(s) then\n r[s] += 1\n else\n r[s] = 1\n end\n}\n\nanswer = ''\ntmp = 0\nr.each {|team,point|\n if tmp < point then\n answer = team\n end\n}\n\nputs answer\n"}, {"source_code": "\ncount = gets.to_i\nr = {}\ncount.times{|n|\n s = gets\n if r.value?(s) then\n r[s] += 1\n else\n r[s] = 1\n end\n}\n\nanswer = ''\ntmp = 0\nr.each {|team,point|\n if tmp <= point then\n answer = team\n end\n}\n\nputs answer\n"}, {"source_code": "\ncount = gets.to_i\nr = {}\ncount.times{|n|\n s = gets\n if r[s] then\n r[s] += 1\n else\n r[s] = 1\n end\n}\n\nanswer = ''\ntmp = 0\nr.each {|team,point|\n if tmp <= point then\n answer = team\n end\n}\n\nputs answer \n"}, {"source_code": "\ncount = gets.to_i\nr = {}\ncount.times{|n|\n s = gets\n if r.value?(s) then\n r[s] += 1\n else\n r[s] = 1\n end\n}\n\nanswer = ''\ntmp = 0\nr.each {|team,point|\n if tmp < point then\n answer = team\n end\n}\n\nprint answer\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nalr = Array.new(26) { 0 }\nn.times {\n mini_alr = Array.new(26) { 0 }\n\n gets.chomp.split(//).each { |c|\n o = c.ord - 'A'.ord\n mini_alr[o] += 1\n }\n max_mini_alr = mini_alr.max\n mini_alr.each_with_index { |val, index|\n if val == max_mini_alr\n alr[index] += 1\n end\n }\n}\n\nmax_alr = alr.max\nteam_names = \"\" # what?\nalr.each_with_index { |val, index|\n if val == max_alr\n team_names += ('A'.ord + index).chr\n end\n}\n\nputs team_names"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\nn.times{gets.chomp.chars.each{|x| h[x] += 1}}\nmx = h.values.max\nputs h.keys.select{|x| h[x] == mx}.join\n"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\nn.times{h[gets.chomp] += 1}\nputs h.max_by{|x| h[x]}[0]\n"}, {"source_code": "a=gets(p).split\n$><= 1\n numA -= 1\n min -= 2\n end\n end\n end\n min -= ((min - numA) / 2)*2\n ans << min\nend\nans.each do |v|\n puts v\nend", "positive_code": [{"source_code": "tc=gets.chomp.to_i\n\ntc.times do |i|\n fuad=[]\n s=gets.chomp.split(\"\")\n now=0\n s.each do|i|\n\n if fuad==[]\n fuad< 1000000000)\n t_s = t_s - 1000000000\n end\n if (t_s % 2 == 1)\n puts 1\n else\n puts 2\n end\nend\n\n"}, {"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\ndef change(c)\n return 2 if c == 1\n return 1\nend\n\nn = STDIN.gets.to_i\n\na = read_numbers_to_array\ncur_win = 2\na.each do |x| \n cur_win = change(cur_win) if x % 2 == 0\n puts cur_win\nend\n"}], "negative_code": [{"source_code": "@n = STDIN.gets.to_i\nSTDIN.gets.split(' ').collect{ |x| x.to_i}.each do |x|\n\tputs x*(x-1)/2%2 == 0 ? 1 : 2\nend\n"}], "src_uid": "3a767b3040f44e3e2148cdafcb14a241"} {"source_code": "require 'bigdecimal'\nn=gets.to_i\np,r=1,[]\nwhile p<=n+1 do\n d=8*n+4*p*p-12*p+9\n if d>=0\n d=BigDecimal(d).sqrt(100).round\n q=3-2*p\n x=[q+d>>1,q-d>>1]\n x.each{|y|r<=1 and y%2==1 and (p-1)*y+(y-1)*y/2==n}\n end\n p <<= 1\nend\nr.empty? ? puts(-1):puts(r.sort.uniq)\n", "positive_code": [{"source_code": "n=gets.to_i\ndef f(a,b)\n g=->k{k*(k+$m)}\n return a if g.(a)==$n\n return b if g.(b)==$n\n return 0 if g.(a)>$n || g.(b)<$n || (a-b).abs<=1\n c=a+b>>1\n return g.(c)<$n ? f(c,b):f(a,c)\nend\np,r,$n=1,[],2*n\nwhile p<=n+1 do\n $m=2*p-3\n k=f(1,n)\n r< 0 && a % 2 == 1\n a = (-(2**(m+1))+3-sqrtd) / 2\n @result << a*(2**m) if a > 0 && a % 2 == 1\n end\nend\n\n#checkOne\ncheckSimple\n\n@result = @result.sort.uniq\n@result.each do |a|\n print a, \"\\n\"\n r = 0\nend\nif @result.size == 0\n print -1, \"\\n\"\nend"}, {"source_code": "require 'rational'\n\nclass Rational\n def sqrt_floor\n if self < 0 then\n raise 'can\\'t take the square root of a negative number'\n end\n\n return 0 if self == 0\n\n prev = nil\n cur = self\n\n while prev.nil? or (cur - prev).abs >= 1 do\n prev = (cur * 10).round.to_r / 10\n cur = (prev + self / prev) / 2\n end\n\n cur.to_i\n end\nend\n\nn = gets.to_i\n\nans = []\npow = 1\nexp = 0\nloop do\n break if pow - 1 > n\n disc = (2 * pow - 3) ** 2 + 8 * n\n sq = Rational(disc, 1).sqrt_floor\n if sq * sq == disc && sq & 1 == 1\n teams = ((sq + 3) >> 1) - pow\n ans.push(pow * teams) if teams & 1 == 1\n end\n pow <<= 1\n exp += 1 \nend\n\nans.push(-1) if ans.empty?\nans.sort.uniq.each { |x| puts x }\n"}, {"source_code": "n=gets.to_i\ng=->k{k*(k+$m)}\np,u,o=1,[],2*n\nwhile p<=n+1 do\n $m=2*p-3\n l,r=-1,n+1\n while r-l>1\n k=l+r>>1\n s=g.(k)\n u<0&&s==o\n s>o ? r=k : l=k\n end\n p<<=1\nend\nputs u.empty?? -1:u.sort.uniq\n"}, {"source_code": "n=gets.to_i\np,r=1,[]\ndef g(k,m)\n k*(k+m)\nend\ndef f(a,b,m,n)\n return 0 if g(a,m)>n\n return 0 if g(b,m) 0\n a = (-(2**(m+1))+3-sqrtd) / 2\n @result << a*(2**m) if a > 0\n end\nend\n\n#checkOne\ncheckSimple\n\n@result = @result.sort.uniq\n@result.each do |a|\n print a, \"\\n\"\n r = 0\nend\nif @result.size == 0\n print -1, \"\\n\"\nend"}, {"source_code": "@n = $stdin.read.to_i\n@result = []\n\ndef checkOne\n x = 0\n t = 1\n for j in 0..70 do\n @result << t if (x == @n)\n x += t\n t *= 2\n end\nend\n\ndef get_sqrt a\n d = Math.sqrt(a).to_i\n for t in ([d-1,0].max..(d+1))\n return t if t * t == a\n end\n return nil\nend\n\ndef checkSimple\n for m in 0..70 do\n d = 2**(2*m+2) - 3 * (2**(m+2)) + 9 + 8 * @n\n next if d < 0\n sqrtd = get_sqrt(d)\n next if sqrtd == nil\n next if sqrtd % 2 == 0\n a = (-(2**(m+1))+3+sqrtd) / 2\n @result << a*(2**m) if a > 0\n a = (-(2**(m+1))+3-sqrtd) / 2\n @result << a*(2**m) if a > 0\n end\nend\n\ncheckOne\ncheckSimple\n\n@result = @result.sort.uniq\n@result.each do |a|\n print a, \"\\n\"\nend\nif @result.size == 0\n print -1, \"\\n\"\nend"}, {"source_code": "@n = $stdin.read.to_i\n@result = []\n\ndef get_sqrt x\n return 0 if x==0 \n m = x\n p = x\n result = m\n loop do\n r = (m + p/m) / 2\n if m <= r\n result = m\n break\n end\n m = r\n end\n return result * result == x ? result : nil\nend\n\ndef checkSimple\n for m in 0..200 do\n d = 2**(2*m+2) - 3 * (2**(m+2)) + 9 + 8 * @n\n next if d < 0\n sqrtd = get_sqrt(d)\n next if sqrtd == nil\n next if sqrtd % 2 == 0\n a = (-(2**(m+1))+3+sqrtd) / 2\n @result << a*(2**m) if a > 0\n a = (-(2**(m+1))+3-sqrtd) / 2\n @result << a*(2**m) if a > 0\n end\nend\n\ncheckSimple\n\n@result = @result.sort.uniq\n@result.each do |a|\n print a, \"\\n\"\nend\nif @result.size == 0\n print -1, \"\\n\"\nend"}, {"source_code": "require 'bigdecimal'\nn=gets.to_i\np,r=1,[]\nwhile p<=n+1 do\n d=8*n+4*p*p-12*p+9\n if d>=0\n d=BigDecimal(d).sqrt(100).to_i\n q=3-2*p\n x=[q+d>>1,q-d>>1]\n x.each{|y|r<=1 and y%2==1 and (p-1)*y+(y-1)*y/2==n}\n end\n p <<= 1\nend\nr.empty? ? puts(-1):puts(r.sort.uniq)\n"}, {"source_code": "n=gets.to_i\np,r=1,[]\nwhile p<=n do\n d=8*n+4*p*p-12*p+9\n if d>=0\n d=(d**0.5).round\n q=-p+3/2\n x=[q+d,q-d]\n x.each{|y|r<=1and y%2==1and (p-1)*y+(y-1)*y/2==n}\n end\n p <<= 1\nend\nr.empty? ? puts(-1):puts(r.sort.uniq)\n"}, {"source_code": "n=gets.to_i\np,r=1,[]\nwhile p<=n+100 do\n if 8*n+4*p*p-12*p+9 >= 0\n d=Math.sqrt(8*n+4*p*p-12*p+9)\n x1=(-d-2*p+3)/2.0\n x2=(d-2*p+3)/2.0\n r << p*x1.to_i if x1>=1 and x1.to_i == x1 and x1%2==1 and (p-1)*x1+(x1-1)*x1/2==n\n r << p*x2.to_i if x2>=1 and x2.to_i == x2 and x2%2==1 and (p-1)*x2+(x2-1)*x2/2==n\n end\n p <<= 1\nend\nif !r.empty?\n puts r.sort.uniq\nelse\n puts -1\nend\n"}, {"source_code": "n=gets.to_i\np,r=1,[]\nwhile p<=n do\n if 8*n+4*p*p-12*p+9 >= 0\n d=Math.sqrt(8*n+4*p*p-12*p+9)\n x1=(-d-2*p+3)/2\n x2=(d-2*p+3)/2\n r << p*x1.to_i if x1>=1 and x1.to_i == x1\n r << p*x2.to_i if x2>=1 and x2.to_i == x2\n end\n p <<= 1\nend\nif !r.empty?\n puts r.sort\nelse\n puts -1\nend\n"}, {"source_code": "n=gets.to_i\ndef f(a,b)\n g=->k{k*(k+$m)}\n return 0 if g.(a)>$n||g.(b)<$n||(a-b).abs<=1\n return a if g.(a)==$n\n return b if g.(b)==$n\n c=a+b>>1\n return g.(c)<$n ? f(c,b):f(a,c)\nend\np,r,$n=1,[],2*n\nwhile p<=n+1 do\n $m=2*p-3\n k=f(1,n)\n r<=0\n d=(d**0.5).round\n q=3-2*p\n x=[q+d>>1,q-d>>1]\n x.each{|y|r<=1 and y%2==1 and (p-1)*y+(y-1)*y/2==n}\n end\n p <<= 1\nend\nr.empty? ? puts(-1):puts(r.sort.uniq)\n"}, {"source_code": "n=gets.to_i\np,r=1,[]\nwhile p<=n+100 do\n if 8*n+4*p*p-12*p+9 >= 0\n d=Math.sqrt(8*n+4*p*p-12*p+9)\n x1=(-d-2*p+3)/2.0\n x2=(d-2*p+3)/2.0\n r << p*x1.to_i if x1>=1 and x1.to_i == x1 and x1%2==1\n r << p*x2.to_i if x2>=1 and x2.to_i == x2 and x2%2==1\n end\n p <<= 1\nend\nif !r.empty?\n puts r.sort.uniq\nelse\n puts -1\nend\n"}, {"source_code": "n=gets.to_i\np,r=1,[]\nwhile p<=n+100 do\n if 8*n+4*p*p-12*p+9 >= 0\n d=Math.sqrt(8*n+4*p*p-12*p+9).round(10)\n x1=((-d-2*p+3)/2.0).round(10)\n x2=((d-2*p+3)/2.0).round(10)\n r << p*x1.to_i if x1>=1 and x1.to_i == x1 and x1%2==1 and (p-1)*x1+(x1-1)*x1/2==n\n r << p*x2.to_i if x2>=1 and x2.to_i == x2 and x2%2==1 and (p-1)*x2+(x2-1)*x2/2==n\n end\n p <<= 1\nend\nif !r.empty?\n puts r.sort.uniq\nelse\n puts -1\nend\n"}, {"source_code": "n=gets.to_i\np,r=1,[]\nwhile p<=n+100 do\n if 8*n+4*p*p-12*p+9 >= 0\n d=Math.sqrt(8*n+4*p*p-12*p+9).round\n x1=(-d-2*p+3)/2\n x2=(d-2*p+3)/2\n r << p*x1.to_i if x1>=1 and x1%2==1 and (p-1)*x1+(x1-1)*x1/2==n\n r << p*x2.to_i if x2>=1 and x2%2==1 and (p-1)*x2+(x2-1)*x2/2==n\n end\n p <<= 1\nend\nif !r.empty?\n puts r.sort.uniq\nelse\n puts -1\nend\n"}, {"source_code": "n=gets.to_i\np,r=1,[]\nwhile p<=n+100 do\n if 8*n+4*p*p-12*p+9 >= 0\n d=Math.sqrt(8*n+4*p*p-12*p+9)\n x1=(-d-2*p+3)/2.0\n x2=(d-2*p+3)/2.0\n r << p*x1.to_i if x1>=1 and x1.to_i == x1\n r << p*x2.to_i if x2>=1 and x2.to_i == x2\n end\n p <<= 1\nend\nif !r.empty?\n puts r.sort.uniq\nelse\n puts -1\nend\n"}], "src_uid": "7589b30ec643278d8a83d74d43d9aebe"} {"source_code": "n, t = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i)\n\nx = 1\nwhile x= t\n break\n end\nend\n\nif i == t\n print \"YES\"\nelse\n print \"NO\"\nend"}, {"source_code": "cells = gets.chomp\ncells = cells.split\nnumber = cells[0].to_i\ntarget = cells[1].to_i\nportals = gets.chomp\nportals = portals.split\n\ni = 0\nwhile i <= portals.size\n\tif i < target - 1\n\t\ti += portals[i].to_i\n\telse\n\t\tif i == target - 1\n\t\t\tprint \"YES\"\n\t\telse\n\t\t\tprint \"NO\"\n\t\tend\n\t\tbreak\n\tend\nend"}, {"source_code": "def solution(n, t, a)\n i = 1\n while (i <= t) do\n i += a[i-1]\n return puts \"YES\" if i == t\n end\n puts \"NO\"\nend\n\nn, t = gets.split(\" \").map { |i| i.to_i }\na = gets.split(\" \").map { |i| i.to_i }\n\nsolution(n, t, a)\n"}, {"source_code": "# http://codeforces.com/problemset/problem/500/A\n\nn, t = gets.chomp.split(\" \").map(&:to_i)\n\nas = gets.chomp.split(\" \").map(&:to_i)\n\ni = 0\n\nwhile i < n - 1 && i != t - 1\n i += as[i]\nend\n\nif i == t - 1\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "a = gets.split(\" \").map{|i| i.to_i}\ntab = gets.split(\" \").map{|i| i.to_i}\nn = a[0]\nt = a[1]\np = 0\nfor i in 0...n-1\n\tif i == p\n\t\tp += tab[i]\n\t\tif p >= t-1\n\t\t\tbreak\n\t\tend\n\tend\nend\nif p == t-1\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n"}, {"source_code": "n, t = gets.chomp.split.map(&:to_i)\n\na = gets.chomp.split.map(&:to_i)\n\ncan_solve = false\ni = 1\nloop do\n i += a[i - 1]\n\n if i == t\n can_solve = true\n break\n end\n\n break if i >= n\nend\n\nif can_solve\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "n, t = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\ni = 0\nans = \"NO\"\nwhile (i < n - 1)\n i += a[i]\n ans = \"YES\" if i == t - 1\n break if i >= t\nend\nputs ans\n"}, {"source_code": "n, t = gets.split.map(&:to_i)\na = [nil] + gets.split.map(&:to_i)\nans = false\ni = 1\nwhile i < t\n i += a[i]\n ans = true if i == t\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "def g;gets.split.map(&:to_i)end\nn,t=g\na=g\nnow=0\nwhile now= t\n break\n end\nend\n\nif i == t\n print \"YES\"\nelse\n print \"NO\"\nend"}, {"source_code": "num = gets.chomp.split\nn = Integer(num[0])\nt = Integer(num[1])\n\nnums = gets.chomp.split\na = Array.new\nfor i in 1..n-1\n a[i] = Integer(nums[i - 1])\nend\ni = 1\nfor i in 1...n - 1\n i = i + a[i]\n if i >= t\n break\n end\nend\n\nif i == t\n print \"YES\"\nelse\n print \"NO\"\nend"}, {"source_code": "cells = gets.chomp\ncells = cells.split\nnumber = cells[0].to_i\ntarget = cells[1].to_i\nportals = gets.chomp\nportals = portals.split\n\ni = 0\nwhile i < portals.size\n\tif i < target - 1\n\t\ti += portals[i].to_i\n\telse\n\t\tif i == target - 1\n\t\t\tprint \"YES\"\n\t\telse\n\t\t\tprint \"NO\"\n\t\tend\n\t\tbreak\n\tend\nend"}, {"source_code": "cells = gets.chomp\ncells = cells.split\nnumber = cells[0].to_i\ntarget = cells[1].to_i\nportals = gets.chomp\nportals = portals.split\n\ni = 0\nwhile i < portals.size\n\tif i < target - 1\n\t\ti += portals[i].to_i\n\t\tputs i\n\telse\n\t\tif i == target - 1\n\t\t\tprint \"YES\"\n\t\telse\n\t\t\tprint \"NO\"\n\t\tend\n\t\tbreak\n\tend\nend"}, {"source_code": "cells = gets.chomp\ncells = cells.split\nnumber = cells[0].to_i\ntarget = cells[1].to_i\nportals = gets.chomp\nportals = portals.split\n\ni = 0\nwhile i < portals.size-1\n\tif i < target - 1\n\t\ti += portals[i].to_i\n\telse\n\t\tif i == target - 1\n\t\t\tprint \"YES\"\n\t\telse\n\t\t\tprint \"NO\"\n\t\tend\n\t\tbreak\n\tend\nend"}, {"source_code": "n, t = gets.split(' ').map(&:to_i)\na = gets.split(' ').map(&:to_i)\n\npos = 0\nresult = false\n\nwhile pos < n-1\n result ||= pos == t-1\n\n pos += a[pos]\nend\n\nputs result ? 'YES' : 'NO'\n"}], "src_uid": "9ee3d548f93390db0fc2f72500d9eeb0"} {"source_code": "n, k = gets.split.map(&:to_i)\n\nif n <= k * (k - 1)\n\tputs 'YES'\n\ta, b = -1, -1\n\tans = []\n\tremain = n\n\t(1..k).each do |i|\n\t\t(i + 1..k).each do |j|\n\t\t\tif a != i && b != j\n\t\t\t\tans << [i, j] << [j, i]\n\t\t\t\ta, b = j, i\n\t\t\telse\n\t\t\t\tans << [j, i] << [i, j]\n\t\t\t\ta, b = i, j\n\t\t\tend\n\t\t\tremain -= 2\n\t\t\tbreak if remain <= 0\n\t\tend\n\t\tbreak if remain <= 0\n\tend\n\tans[...n].each { puts _1.join(' ') }\nelse\n\tputs 'NO'\nend\n", "positive_code": [{"source_code": "n,k = gets.split.map(&:to_i)\nans = Array.new(n).map{[0,0]}\nif k*(k-1) < n\n puts \"NO\"\n exit\nend\nputs \"YES\"\nfor i in 0..n-1\n ans[i][0] = i%k+1\n ans[i][1] = (i/k+i%k+1)%k+1\n puts \"#{i%k+1} #{(i/k+i%k+1)%k+1}\"\nend"}], "negative_code": [], "src_uid": "c9237925ab3de588a3f047c226f7fe83"} {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n xs = [*1..n - 3, 1 << 28, 1 << 29]\r\n xs << xs.reduce(:^)\r\n puts xs * \" \"\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n x = 1 << 28\r\n y = 1 << 29\r\n z = ((1..n - 3).reduce(:^) || 0) ^ x ^ y\r\n puts [*1..n - 3, x, y, z].join(\" \")\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n i = -1\r\n large, small = if n % 2 == 0\r\n 2.times.map { (n / 2 - 1).times.map { i += 1 } }\r\n else\r\n [(n / 2).times.map { i += 1 },\r\n (n / 2 - 1).times.map { i += 1 }]\r\n end\r\n xlarge = large.reduce(:^) || 0\r\n xsmall = small.reduce(:^) || 0\r\n if xsmall == xlarge\r\n large[-1] = i += 1\r\n end\r\n xlarge = large.reduce(:^) || 0\r\n l, s = loop do\r\n l = i += 1\r\n s = xlarge ^ l ^ xsmall\r\n break [l, s] if s > i\r\n end\r\n large << l\r\n small << s\r\n puts 0.upto(n - 1).map { |i| i % 2 == 0 ? large[i / 2] : small[i / 2] }.join(\" \")\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n xs = [*1..n - 3, 1 << 28, 1 << 29]\r\n puts xs * \" \" + \" #{xs.reduce(:^)}\"\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n array = (0..n - 2).to_a\r\n a = array.filter.with_index { |x, i| i.even? }.reduce(:^)\r\n b = array.filter.with_index { |x, i| i.odd? }.reduce(:^)\r\n c = (n - 2).upto(2 ** 32).find do |c|\r\n a ^ c ^ b > n\r\n end\r\n d = a ^ c ^ b\r\n array << c << d\r\n puts array.join(\" \")\r\nend\r\n"}], "src_uid": "52bd5dc6b92b2af5aebd387553ef4076"} {"source_code": "def read\r\n gets.split.map &:to_i\r\nend\r\n_, q = read\r\na = read\r\ncur = a.sum\r\nq.times do\r\n t, x = read\r\n if t == 1\r\n x -= 1\r\n cur += a[x] == 1 ? -1 : 1\r\n a[x] = 1 - a[x]\r\n else\r\n puts cur >= x ? 1 : 0\r\n end\r\nend", "positive_code": [{"source_code": "inp = gets.chomp.split\nn, q = inp[0].to_i, inp[1].to_i\na = []\nk = 0\n\ni = 0\n\nstr = gets.chomp.split\ni = 0\nstr.each do |v|\n k += 1 if v.to_i == 1\n a[i] = v.to_i\n i+=1\nend\n\n\nq.times do\n inp = gets.chomp.split\n qr, qt = inp[0].to_i, inp[1].to_i \n if qr == 1\n if a[qt-1] == 0\n k+=1 \n else\n k-=1\n end\n\n a[qt-1] = 1 - a[qt-1]\n else \n if qt <= k \n puts(1) \n else\n puts(0) \n end\n end\nend"}, {"source_code": "# frozen_string_literal: true\r\n\r\nn, q = gets.chomp.split.map(&:to_i)\r\nlist = gets.chomp.split.map(&:to_i)\r\n\r\nnumber_of_ones = list.sum\r\nq.times do\r\n query = gets.chomp.split.map(&:to_i)\r\n\r\n if query[0] == 1\r\n x = query[1]\r\n list[x - 1] = 1 - list[x - 1]\r\n if list[x - 1].zero?\r\n number_of_ones -= 1\r\n else\r\n number_of_ones += 1\r\n end\r\n else\r\n k = query[1]\r\n puts number_of_ones > k - 1 ? 1 : 0\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "def read\r\n gets.split.map &:to_i\r\nend\r\n_, q = read\r\na = read\r\ncur = a.sum\r\nq.times do\r\n t, x = read\r\n if t == 1\r\n x -= 1\r\n cur += a[x] == 1 ? -1 : 1\r\n else\r\n puts cur >= x ? 1 : 0\r\n end\r\nend"}, {"source_code": "# frozen_string_literal: true\r\n\r\nn, q = gets.chomp.split.map(&:to_i)\r\nlist = gets.chomp.split.map(&:to_i)\r\n\r\nnumber_of_ones = list.count(1)\r\nq.times do\r\n query = gets.chomp.split.map(&:to_i)\r\n\r\n if query[0] == 1\r\n x = query[1]\r\n if x > number_of_ones\r\n number_of_ones += 1\r\n else\r\n number_of_ones -= 1\r\n end\r\n else\r\n k = query[1]\r\n puts k > number_of_ones ? '0' : '1'\r\n end\r\nend\r\n"}, {"source_code": "# frozen_string_literal: true\r\n\r\nn, q = gets.chomp.split.map(&:to_i)\r\nlist = gets.chomp.split.map(&:to_i)\r\n\r\nnumber_of_ones = list.count(1)\r\nq.times do\r\n query = gets.chomp\r\n\r\n if query[0] == '1'\r\n x = query[2].to_i\r\n if x > number_of_ones\r\n number_of_ones += 1\r\n else\r\n number_of_ones -= 1\r\n end\r\n else\r\n k = query[2].to_i\r\n puts k > number_of_ones ? '0' : '1'\r\n end\r\nend\r\n"}, {"source_code": "inp = gets.chomp.split\nn, q = inp[0].to_i, inp[1].to_i\na = []\nk = 0\n\ni = 0\n\nstr = gets.chomp.split\ni = 0\nstr.each do |v|\n k += 1 if v.to_i == 1\n a[i] = v.to_i\n i+=1\nend\n\n\nq.times do\n inp = gets.chomp.split\n qr, qt = inp[0].to_i, inp[1].to_i \n if qr == 1\n if a[qt-1] == 0\n k+=1 \n else\n k-=1\n end\n\n a[qt-1] = 1 - a[qt-1]\n else \n if k <= qt \n puts(1) \n else\n puts(0) \n end\n end\nend"}], "src_uid": "ccf7aba6ca9bbf39a5ec8a20ec018825"} {"source_code": "n, m = gets.split.map(&:to_i)\nnum = 0\n(1..n).each do |t|\n arr = gets.split.map(&:to_i)\n (0..arr.length).each do |index|\n if index%2 == 1\n num = num + ((arr[index-1]+arr[index]) > 0 ? 1 : 0)\n end\n end\nend\np num", "positive_code": [{"source_code": "s = 0\nn, m = gets.chomp.split.map(&:to_i)\nn.times do\n as = gets.chomp.split.map(&:to_i)\n for i in 0...m\n s += 1 if 0 < as[2 * i] + as [2 * i + 1]\n end\nend\nputs s\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = n.times.map{gets.split.map(&:to_i)}\nans = Array.new(n){Array.new(m, 0)}\nn.times do |i|\n (2 * m).times do |j|\n ans[i][j / 2] = 1 if a[i][j] == 1\n end\nend\np ans.flatten.inject(:+)\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = n.times.map{gets.split.map(&:to_i)}\nputs a.flatten.each_slice(2).count{|x| x.include?(1)}\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = n.times.map{gets.split.map(&:to_i)}\nans = 0\nn.times do |i|\n (2 * m).times do |j|\n if (a[i][j] == 1 && j.even?) || (a[i][j] == 1 && j.odd? && a[i][j - 1] != 1)\n ans += 1 \n end\n end\nend\np ans\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = n.times.map{gets.split.map(&:to_i)}\nputs a.flatten.each_slice(2).map{|a, b| a + b > 0 ? 1 : 0 }.inject(:+)\n"}, {"source_code": "n, m = gets.chomp.split(\" \").map(&:to_i)\nans = 0\nn.times do |i|\n rooms = gets.chomp.split(\" \").map(&:to_i)\n rooms.each_slice(2) do |a, b|\n if (a == 1) or (b == 1) then\n ans += 1\n end\n end\nend\nputs ans"}, {"source_code": "n, m = gets.split.map(&:to_i)\nans = 0\nn.times do\n a = gets.split.map(&:to_i)\n (0..m-1).each{|i| ans += 1 if a[2*i] == 1 || a[2*i + 1] == 1}\nend\np ans\n"}, {"source_code": "p$<.read.split.map(&:to_i)[2..-1].each_slice(2).count{|x,y|x>0||y>0}"}, {"source_code": "n,m = gets.chomp.split(\" \").map(&:to_i)\ncounter = 0\nn.times do |f|\n\tfloor = gets.chomp.split(\" \")\n\t0.step((m*2-1), 2) do |ind|\n\t\tcounter+=1 if floor[ind] == \"1\" || floor[ind+1] == \"1\"\n\tend\nend\nputs counter"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\narr = [].tap do |out|\n n.times do\n gets.chomp.split.map(&:to_i).each_slice(2).each { |a| out << a }\n end\nend\nputs arr.select { |a| a.include? 1 }.length\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn,m = gets.chomp.split.map(&:to_i)\n\nc = 0\n\nn.times do\n f = gets.chomp.split\n m.times do |j|\n c += 1 if f[2 * j] == \"1\" || f[2 * j + 1] == \"1\"\n end\nend\n\nputs c"}, {"source_code": "n, m = gets.split.map(&:to_i)\nans = 0\nn.times do\n w = gets.split.map(&:to_i)\n (0..m-1).each do |i|\n ans += 1 if w[(i*2)..(i*2+1)].include?(1)\n end\nend\nputs ans"}, {"source_code": "data=gets.chomp.split\n\nn=data[0].to_i\nm=data[1].to_i\n\nhouse=[]\n\na=0\nwhile a0 then\n\t\t\tans+=1\n\t\tend\n\t}\n\t\n}\nputs ans\n\n\n"}, {"source_code": "n, m = gets.chomp.split(\"\\s\").map(&:to_i)\nfloors = n.times.map { gets.chomp.split(\"\\s\").map(&:to_i) }\n\nflats = []\n\nfloors.each do |floor|\n floor.each_slice(2).each do |flat|\n flats << flat\n end\nend\n\nputs flats.reduce(0) { |acc, flat| flat.include?(1) ? acc + 1 : acc }\n"}], "negative_code": [{"source_code": "n, m = gets.chomp.split.map(&:to_i)\narr = [].tap do |out|\n n.times do\n gets.chomp.split.map(&:to_i).each_slice(m).each { |a| out << a }\n end\nend\nputs arr.select { |a| a.include? 1 }.length\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn,m = gets.chomp.split.map(&:to_i)\n\nc = 0\n\nn.times do\n f = gets.chomp.split\n 0.step(m.div 2) do |j|\n if f[2 * j] == \"1\" || f[2 * j - 1] == \"1\"\n c += 1\n end\n end\nend\n\nputs c"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn,m = gets.chomp.split.map(&:to_i)\n\nc = 0\n\nn.times do\n f = gets.chomp.split\n f.size.pred.times do |i|\n c += 1 if f[i] == f[i + 1]\n end\nend\n\nputs c"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nans=0\nn.times{\n\tx=gets.split.map{|e| e.to_i}\n\t0.step(m,2){|i|\n\t\tif x[i]+x[i+1]>0 then\n\t\t\tans+=1\n\t\tend\n\t}\n\t\n}\nputs ans\n\n\n"}], "src_uid": "5b9aed235094de7de36247a3b2a34e0f"} {"source_code": "n, m = gets.split.map(&:to_i)\ndata = []\ntotal = 0\nn.times { data << gets.split.map(&:to_i) }\n\ndata.each do |line|\n t, tmax, comp, bus = *line\n\n if t+m <= tmax\n total += bus\n next\n end\n if tmax-t < 1\n total += m*comp+bus\n else\n total += [(m/(tmax-t) + (m%(tmax-t)==0 ? 0 : 1))*bus, m*comp+bus].min\n end\n\nend\n\nputs total", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\ndata = []\ntotal = 0\nn.times { data << gets.split.map(&:to_i) }\n\ndata.each do |line|\n t, tmax, comp, bus = *line\n\n if t+m <= tmax\n total += bus\n next\n end\n if tmax-t < 1\n total += m*comp+bus\n else\n total += [((m+tmax-t-1)/(tmax-t))*bus, m*comp+bus].min\n end\n\nend\n\nputs total"}, {"source_code": "n, m = gets.split.map(&:to_i)\ndata = []\ntotal = 0\nn.times { data << gets.split.map(&:to_i) }\n\ndata.each do |line|\n t, tmax, comp, bus = *line\n\n if t+m <= tmax\n total += bus\n next\n end\n if tmax-t < 1\n total += m*comp+bus\n else\n total += [(m/(tmax-t) + (m%(tmax-t)==0 ? 0 : 1))*bus, m*comp+bus].min\n end\n \nend\n\nputs total"}], "negative_code": [{"source_code": "n, m = gets.split.map(&:to_i)\ndata = []\ntotal = 0\nn.times { data << gets.split.map(&:to_i) }\n\ndata.each do |line|\n t, tmax, comp, bus = *line\n\n if t+m <= tmax\n total += bus\n next\n end\n if tmax-t < 1\n total += m*comp+bus\n else\n total += [((m+tmax-t+1)/(tmax-t))*bus, m*comp+bus].min\n end\n\nend\n\nputs total"}, {"source_code": "n, m = gets.split.map(&:to_i)\ndata = []\ntotal = 0\nn.times { data << gets.split.map(&:to_i) }\n\ndata.each do |line|\n\n if line[0] + m < line[1]\n total += line[3]\n next\n end\n\n if line[2] * m > line[3]\n del = line[1]-line[0]\n if del >0\n total += line[3] * (m/del)\n total += line[3] if (m%del>0)\n else\n total += line[3] * m\n end\n else\n total += line[2] * m + line[3]\n end\n\n\nend\n\nputs total"}, {"source_code": "n, m = gets.split.map(&:to_i)\ndata = []\ntotal = 0\nn.times { data << gets.split.map(&:to_i) }\n\ndata.each do |line|\n\n if line[0] + m <= line[1]\n total += line[3]\n next\n end\n\n if line[2] * (line[1]-line[0]) >= line[3]\n total += line[3] * (m/(line[1]-line[0]))\n total += line[3] if (m%(line[1]-line[0])>0)\n else\n total += line[2] * m + line[3]\n end\n\n\n\nend\n\nputs total"}, {"source_code": "\n n, m = gets.split.map(&:to_i)\ndata = []\ntotal = 0\nn.times { data << gets.split.map(&:to_i) }\n\ndata.each do |line|\n\n if line[0] + m < line[1]\n total += line[3]\n next\n end\n\n if line[2] * (line[1]-line[0]) >= line[3]\n total += line[3] * (m/(line[1]-line[0]))\n total += line[3] if (m%(line[1]-line[0])>0)\n else\n total += line[2] * m + line[3]\n end\n\n\n\nend\n\nputs total"}, {"source_code": "\n n, m = gets.split.map(&:to_i)\ndata = []\ntotal = 0\nn.times { data << gets.split.map(&:to_i) }\n\ndata.each do |line|\n\n if line[0] + m < line[1]\n total += line[3]\n next\n end\n\n if line[2] * (line[1]-line[0]) > line[3]\n total += line[3] * (m/(line[1]-line[0]))\n total += line[3] if (m%(line[1]-line[0])>0)\n else\n total += line[2] * m + line[3]\n end\n\n\n\nend\n\nputs total"}, {"source_code": "n, m = gets.split.map(&:to_i)\ndata = []\ntotal = 0\nn.times { data << gets.split.map(&:to_i) }\n\ndata.each do |line|\n t, tmax, comp, bus = *line\n\n if t+m <= tmax\n total += bus\n next\n end\n if tmax-t == 0\n total +=m*comp+bus\n else\n total += [(m/(tmax-t) + (m%(tmax-t)==0 ? 0 : 1))*bus, m*comp+bus].min\n end\nend\n\nputs total"}], "src_uid": "96a3f9d559a40050095de2f5f70b147f"} {"source_code": "def dfs(i,j,direct,color)\n return false if i<0 || j<0 || i>=$n || j>=$m || $s[i][j]!=color\n return true if $used[i][j]\n $used[i][j]=true\n res = false\n res|=dfs(i+1,j,3,color) if direct!=1\n res|=dfs(i-1,j,1,color) if direct!=3\n res|=dfs(i,j+1,0,color) if direct!=2\n res|=dfs(i,j-1,2,color) if direct!=0\n res\nend\n\ndef getAnswer()\n $n.times {|i| $m.times {|j| return true if !$used[i][j] && \n\ndfs(i,j,0,$s[i][j])}}\n return false\nend\n\n$n,$m=STDIN.gets.split.map{|n|n.to_i}\n$s=Array.new($n) {STDIN.gets}\n$used=Array.new($n) {Array.new($m) {false}}\n\nif getAnswer then puts \"Yes\" else puts \"No\" end", "positive_code": [{"source_code": "def dfs(i,j,direct,color)\n return false if i<0 || j<0 || i>=$n || j>=$m || $s[i][j]!=color\n return true if $used[i][j]\n $used[i][j]=true\n res = false\n res|=dfs(i+1,j,3,color) if direct!=1\n res|=dfs(i-1,j,1,color) if direct!=3\n res|=dfs(i,j+1,0,color) if direct!=2\n res|=dfs(i,j-1,2,color) if direct!=0\n res\nend\n\ndef getAnswer()\n $n.times {|i| $m.times {|j| return true if !$used[i][j] && \n\ndfs(i,j,0,$s[i][j])}}\n return false\nend\n\n$n,$m=STDIN.gets.split.map{|n|n.to_i}\n$s=Array.new($n) {STDIN.gets}\n\nf=[false]*$m\n$used=Array.new($n) {f.dup}\n\nif getAnswer then puts \"Yes\" else puts \"No\" end"}], "negative_code": [], "src_uid": "73930603e440eef854da4ba51253a5a7"} {"source_code": "#!/usr/bin/ruby\nn = gets.chomp.to_i\nnumbers = []\nn.times do\n\tnumbers << gets.chomp\nend\nwritten = false\n(numbers[0].length-2).downto(0) do |i|\n\ten = true\n\tfor num in numbers\n\t\tif numbers[0][0..i] != num[0..i]\n\t\t\ten = false\n\t\t\tbreak\n\t\tend\n\tend\n\tif en == true\n\t\tputs i+1\n\t\twritten = true\n \t\tbreak\n\tend\nend\nputs 0 if not written\n", "positive_code": [{"source_code": "nums = []\nreadline.to_i.times { nums << readline.strip }\n\nans = 0\nnums[0].length.times do |i|\n break unless nums.all? { |num| nums[0][i] == num[i] }\n ans += 1\nend\n\np ans\n\n"}, {"source_code": "n = gets.to_i\na = []\nn.times do\n a << gets.chomp\nend\n\ndef check_pref(a, len)\n pref = a.first[0, len]\n a.drop(1).each do |s|\n return false unless s[0, len] == pref\n end\n true\nend\n\ndef pref_len(a)\n return 0 if a.empty?\n max_len = a.first.size\n max_len.downto 0 do |cur_len|\n return cur_len if check_pref(a, cur_len)\n end\n cur_len\nend\n\nputs pref_len(a)"}, {"source_code": "n = gets.to_i\ns0 = gets.chomp\nans = s0.length\n(1..n-1).each do\n s = gets.chomp\n i = 0\n while s[i] == s0[i]\n i += 1\n end\n ans = [ans, i].min\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\n\nmassiv = Array.new(n) {Array.new()}\n\nfor i in(0..n-1)\n\tk = gets.split(\"\")\n\tlength = k.length - 1\n\t\n\t\n\tfor j in(0..length-1) \n\t\tmassiv[i][j] = k[j].to_i\n\tend\nend\n\np = 0\nt = 0\n\nfor j in(0..length-1)\n\tfor i in(0..n-2)\n\t\tif massiv[i][j] == massiv[i+1][j] then\n\t\t\tt+=1\n\t\telse\n\t\t\tbreak\n\t\tend\n\tend\n\t\n\tif t == 0 then\n\t\tbreak\n\tend\n\n\tif t == n-1 then\n\t\tp+=1\n\tend\n\n\tt = 0\nend\n\nputs p\n"}, {"source_code": "n, numbers = gets.to_i, STDIN.read.split(\"\\n\")\nprefix = numbers[0]\n\nn.times do |i|\n\tm = numbers[i][0..prefix.length - 1]\n\tif prefix == m\n\t\tnext\n\telse\n\t\twhile prefix != m\n\t\t\tprefix.chop!\n\t\t\tm.chop!\n\t\tend\n\tend\nend\n\nprint prefix.length"}, {"source_code": "# t = gets.split.collect{|x| x.to_i}\nn = gets.to_i\n\nresult = nil\n\nn.times do |i|\n\ts = gets.strip\n\tresult ||=s\n\ts = s.chars.to_a\n\ts.each_index do |i|\n\t\tif result[i] == nil or result[i] != s[i]\n\t\t\tif i == 0\n\t\t\t\tresult = \"\"\n\t\t\telse\n\t\t\t\tresult = result[0..i-1]\n\t\t\tend\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nputs result.size"}, {"source_code": "\nn=gets.to_i\nnumbers=[]\nn.times do\n numbers<<=gets.split[0]\nend\nnumbers[0].size.downto(0) do |i|\n ok=true\n numbers.each do |e|\n ok=false unless e[0..i-1]==numbers[0][0..i-1]\n end\n if ok\n puts i\n exit\n end\nend\nputs 0"}, {"source_code": "n = gets.to_i\nphone = Array.new(n)\nphone[0] = gets.strip\nl = phone[0].length\nfor i in 1...n\n phone[i] = gets.strip\n x=0\n until phone[0][x] != phone[i][x] do x += 1 end\n l = x if x < l\nend\nprint l"}, {"source_code": "numbers = []\nreadline.to_i.times { numbers << readline.strip }\n\nans = 0\nhead = numbers.shift\ntail = numbers\nhead.length.times do |i|\n break unless tail.all? { |t| head[i] == t[i] }\n ans += 1\nend\np ans"}, {"source_code": "input = Array.new\n\n# remove all \\r on windows?\n\nSTDIN.read.split(\"\\n\").each { |line| input << line }\n\nn = input.delete_at 0\n\nprefix = input[0].split //\n\ninput.each do |line|\n letters = line.split //\n letters.each_index do |i|\n if letters[i] != prefix[i]\n prefix = prefix[0...i]\n break\n end\n end\nend\n\nputs prefix.length\n"}, {"source_code": "#!/usr/bin/ruby\nn = gets.chomp.to_i\ns = []\nn.times do \n\ts << gets.chomp\nend\nmax = 0\nfor i in 0..s[0].length-2\n\tprosel = true\n\tfor si in s\n#\t\tprosel =false; break if si[0..i] != s[0][0..i]\n\t\tif si[0..i] != s[0][0..i]\n\t\t\tprosel = false\n\t\t\tbreak\n\t\tend\n\tend\n\tmax = i+1 if prosel == true\nend\nputs max\n"}, {"source_code": "n = gets.to_i\n\na = []\nn.times do\n a << gets\nend\n\na.sort!\n\ndef f(s, t)\n cnt = 0\n while cnt < s.length && cnt < t.length && s[cnt] == t[cnt]\n cnt = cnt + 1\n end\n cnt\nend\n\nans = a[0].length\n(a.length - 1 ).times do |i|\n t = f a[i], a[i+1]\n ans = t if t < ans\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\n\na = []\nn.times do |i|\n a << gets\nend\n\na.sort!\n\ndef f(s, t)\n cnt = 0\n while cnt < s.length && cnt < t.length && s[cnt] == t[cnt]\n cnt = cnt + 1\n end\n return cnt\nend\n\nans = a[0].length\n(a.length - 1 ).times do |i|\n t = f a[i], a[i+1]\n if t < ans\n ans = t\n end\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\nphoneNumbers = []\nn.times do\n\tphoneNumbers << gets\nend\nans = 0\nphoneNumbers[0].length.times do |guessAns|\n\tcheck = true\n\tn.times do |id|\n\t\tif phoneNumbers[id][0..guessAns] != phoneNumbers[0][0..guessAns]\n\t\t\tcheck = false\n\t\tend\n\tend\n\tif check == true\n\t\tans = guessAns+1\n\tend\nend\n\nputs ans\n\n\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nres = s.size\n(n-1).times do \n s1 = gets.chomp\n 0.upto(res-1) do |i|\n if s[i] != s1[i] \n res = i\n break\n end\n end\nend\np res\n "}, {"source_code": "nums = []\nreadline.to_i.times { nums << readline.strip }\n\nans = 0\n\nhead = nums.shift\ntail = nums\nhead.length.times do |i|\n break unless tail.all? { |t| head[i] == t[i] }\n ans += 1\nend\n\np ans\n\n"}], "negative_code": [], "src_uid": "081b35620952bd32ce6d8ddc756e5c9d"} {"source_code": "for _ in 0...(gets.chomp.to_i)\r\n len = gets.chomp.to_i\r\n string = gets.chomp\r\n if len >= 3\r\n puts \"NO\"\r\n elsif (string == \"00\") or (string == \"11\")\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\nend", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n s = gets.strip\n\n if n == 1 || s == \"01\" || s == \"10\"\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n"}], "negative_code": [{"source_code": "for _ in 0...(gets.chomp.to_i)\r\n len = gets.chomp.to_i\r\n string = gets.chomp\r\n if (len == 1) or (len == 2)\r\n puts \"YES\"\r\n else\r\n if string.count(\"0\") == string.count(\"1\")\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\n end\r\nend"}], "src_uid": "354658f565e265c2a1ce37355d6466e1"} {"source_code": "def solve\n n = gets.to_i\n n -= 1\n a = gets.split(' ').map { |s| s.to_i}\n it, i, tmp, res = 0, 0, 0, 0\n f = 0\n while f < 2\n res += 1\n i = it\n it = (it + 1) % 2\n f += 1\n while i < n\n if a[i] > a[i + 1]\n tmp = a[i]\n a[i] = a[i + 1]\n a[i + 1] = tmp\n f = 0\n end\n i += 2\n end\n #puts \"a : #{a}\"\n end\n res -= 2\n puts res\nend\n\nt = gets.to_i\nfor z in 0...t\n solve\nend\n", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n\nn = gets.to_i\na = gets.split.map!(&:to_i)\nb = a.sort\n\ncnt = 0\nwhile a != b\n (cnt & 1).step(n - 2, 2) do |i|\n if a[i] > a[i+1]\n a[i], a[i+1] = a[i+1], a[i]\n end\n end\n cnt += 1\nend\n\np cnt\n\nend\n"}], "negative_code": [], "src_uid": "d4bcc53b470e4beaa078d5ce3785c6cb"} {"source_code": "n = gets.chomp.to_i\nw = Array.new\nl = gets.chomp.split\nl.each do |i|\n w << i.to_i \nend\nh = Hash.new(0)\n(0..n-2).each do |i|\n ((i+1)..n-1).each do |j|\n l = w[i] + w[j]\n if h[l] == 0\n h[l] = 1\n else\n a = h[l] + 1\n h[l] = a\n end\n end\nend\nw = -1\nh.each do |key, value|\n if value > w\n w = value\n end\nend\nputs w", "positive_code": [{"source_code": "n = gets.strip.to_i\na = gets.split(\" \").map(&:to_i)\n\nh = {}\n(0..n-2).each do |i|\n (i+1..n-1).each do |j|\n if h[a[i]+a[j]] \n\th[a[i]+a[j]] = h[a[i]+a[j]] + 1 \n else\n\th[a[i]+a[j]] = 1 \n end\t \n end\nend\n\nputs h.to_a.map{|e| e[1]}.max\n\n"}], "negative_code": [], "src_uid": "44619ba06ec0dc410ef598ea45a76271"} {"source_code": "n = Integer(gets.chomp)\nsolve = Array.new(n)\nsolve = gets.chomp.split.map &:to_i\nm = Integer(gets.chomp)\nperiod = Array.new(m)\nfor i in 0...m\n period[i] = gets.chomp.split.map &:to_i\nend\n\ntime_solve = 0\nfor i in 0...n\n time_solve += solve[i]\nend\noutput = -1\nfor i in 0..m-1\n if time_solve <= period[i][1] && time_solve >= period[i][0]\n output = time_solve\n break\n elsif i != m - 1 && time_solve < period[i + 1][0] && time_solve > period[i][1] \n output = period[i + 1][0]\n break\n end\nend\n\nfor i in 0...m\n if time_solve <= period[i][0]\n output = period[i][0]\n break\n elsif time_solve <= period[i][1]\n output = time_solve\n break\n end\nend\n\nputs output", "positive_code": [{"source_code": "gets\ns=gets.split.map(&:to_i).reduce(:+)\ngets.to_i.times{\n\tl,r=gets.split.map(&:to_i)\n\ts<=r&&(p [l,s].max;exit)\n}\np -1"}], "negative_code": [{"source_code": "n = Integer(gets.chomp)\nsolve = Array.new(n)\nsolve = gets.chomp.split.map &:to_i\nm = Integer(gets.chomp)\nperiod = Array.new(m)\nfor i in 0...m\n period[i] = gets.chomp.split.map &:to_i\nend\n\ntime_solve = 0\nfor i in 0...n\n time_solve += solve[i]\nend\noutput = -1\nfor i in 0...m\n if period[i][1] >= time_solve && time_solve >= period[i][0]\n output = time_solve\n break\n end\nend\n\nputs output"}, {"source_code": "n = Integer(gets.chomp)\nsolve = Array.new(n)\nsolve = gets.chomp.split.map &:to_i\nm = Integer(gets.chomp)\nperiod = Array.new(m)\nfor i in 0...m\n period[i] = gets.chomp.split.map &:to_i\nend\n\ntime_solve = 0\nfor i in 0...n\n time_solve += solve[i]\nend\noutput = -1\nfor i in 0...m\n for j in 0..1\n if period[i][j] >= time_solve\n output = period[i][j]\n break\n end\n end\nend\n\nputs output"}, {"source_code": "n = Integer(gets.chomp)\nsolve = Array.new(n)\nsolve = gets.chomp.split.map &:to_i\nm = Integer(gets.chomp)\nperiod = Array.new(m)\nfor i in 0...m\n period[i] = gets.chomp.split.map &:to_i\nend\n\ntime_solve = 0\nfor i in 0...n\n time_solve += solve[i]\nend\noutput = -1\nfor i in 0..m-1\n if time_solve <= period[i][1] && time_solve >= period[i][0]\n output = time_solve\n break\n elsif i != m - 1 && time_solve < period[i + 1][0] && time_solve > period[i][1] \n output = period[i + 1][0]\n break\n end\nend\n\nfor i in 0...m\n if time_solve <= period[i][0]\n output = period[i][1]\n break\n elsif time_solve <= period[i][1]\n output = time_solve\n break\n end\nend\n\nputs output"}, {"source_code": "n = Integer(gets.chomp)\nsolve = Array.new(n)\nsolve = gets.chomp.split.map &:to_i\nm = Integer(gets.chomp)\nperiod = Array.new(m)\nfor i in 0...m\n period[i] = gets.chomp.split.map &:to_i\nend\n\ntime_solve = 0\nfor i in 0...n\n time_solve += solve[i]\nend\noutput = -1\nfor i in 0...m\n for j in 0..1\n if period[i][j] >= time_solve\n output = time_solve\n break\n end\n end\nend\n\nputs output"}, {"source_code": "n = Integer(gets.chomp)\nsolve = Array.new(n)\nsolve = gets.chomp.split.map &:to_i\nm = Integer(gets.chomp)\nperiod = Array.new(m)\nfor i in 0...m\n period[i] = gets.chomp.split.map &:to_i\nend\n\ntime_solve = 0\nfor i in 0...n\n time_solve += solve[i]\nend\noutput = -1\nfor i in 0..m-1\n if time_solve <= period[i][1] && time_solve >= period[i][0]\n output = time_solve\n break\n elsif i != m - 1 && time_solve < period[i + 1][0] && time_solve > period[i][1] \n output = period[i + 1][0]\n break\n end\nend\n\nputs output"}, {"source_code": "n = Integer(gets.chomp)\nsolve = Array.new(n)\nsolve = gets.chomp.split.map &:to_i\nm = Integer(gets.chomp)\nperiod = Array.new(m)\nfor i in 0...m\n period[i] = gets.chomp.split.map &:to_i\nend\n\ntime_solve = 0\nfor i in 0...n\n time_solve += solve[i]\nend\noutput = -1\nfor i in 0...m-1\n if period[i][1] >= time_solve && time_solve >= period[i][0]\n output = time_solve\n break\n elsif time_solve < period[i + 1][0] && time_solve > period[i][1]\n output = period[i + 1][0]\n break\n end\nend\n\nputs output"}, {"source_code": "n = Integer(gets.chomp)\nsolve = Array.new(n)\nsolve = gets.chomp.split.map &:to_i\nm = Integer(gets.chomp)\nperiod = Array.new(m)\nfor i in 0...m\n period[i] = gets.chomp.split.map &:to_i\nend\n\ntime_solve = 0\nfor i in 0...n\n time_solve += solve[i]\nend\noutput = -1\nfor i in 1...m\n if period[i][1] >= time_solve && time_solve >= period[i][0]\n output = time_solve\n break\n elsif time_solve > period[i - 1][1] && time_solve < period[i][0]\n output = period[i][0]\n break\n end\nend\n\nputs output"}], "src_uid": "311f74b766818633581af67a88244709"} {"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3}\n puts '-1'\n exit\nend\nf=s.each_index.select { |i| !s[i] }\nf.shift\nfor t in 1..c do\n r=h[t]\n n=r.size\n puts (r | f.pop(3-n)).join ' '\nend\n", "positive_code": [{"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3}\n puts '-1'\n exit\nend\nf=s.each_index.select { |i| !s[i] }\nf.shift\nfor t in 1..c do\n r=h[t]\n n=r.size\n puts (r | f.pop(3-n)).join ' '\nend"}, {"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3}\n puts '-1'\n exit\nend\nf=s.each_index.select { |i| !s[i] }\nf.shift\nfor t in 1..c do\n r=h[t]\n n=r.size\n puts (r | f.pop(3-n)).join ' '\nend\n"}, {"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3}\n puts '-1'\n exit\nend\nf=s.each_index.select { |i| !s[i] }\nf.shift\nfor t in 1..c do\n r=h[t]\n n=r.size\n puts (r | f.pop(3-n)).join ' '\nend\n"}, {"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3}\n puts '-1'\n exit\nend\nf=s.each_index.select { |i| !s[i] }\nf.shift\nfor t in 1..c do\n r=h[t]\n n=r.size\n puts (r | f.pop(3-n)).join ' '\nend\n"}, {"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3}\n puts '-1'\n exit\nend\nf=s.each_index.select { |i| !s[i] }\nf.shift\nfor t in 1..c do\n r=h[t]\n n=r.size\n puts (r | f.pop(3-n)).join ' '\nend\n"}, {"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3}\n puts '-1'\n exit\nend\nf=s.each_index.select { |i| !s[i] }\nf.shift\nfor t in 1..c do\n r=h[t]\n n=r.size\n puts (r | f.pop(3-n)).join ' '\nend"}, {"source_code": "def dfs(now, parent, group)\n group.push now\n $vis[now] = true\n $path[now].each do |to|\n next if to == parent or $vis[to]\n dfs(to, now, group)\n end\n return group\nend\nn, m = gets.split(' ').map { |i| i.to_i }\n$vis = Array.new(50, false)\n$path = Array.new(50){Array.new}\ngroups = []\ncan = true\nm.times do \n x, y = gets.split(' ').map { |i| i.to_i}\n $path[x].push y\n $path[y].push x\nend\nn.times do |i|\n next if $vis[i+1]\n group = dfs(i+1, -1, [])\n can = false if group.size > 3\n $vis[i+1] = false if group.size == 1\n groups.push group unless group.size == 1\nend\nif can\n groups.each do |g|\n next if g.size >= 3\n while g.size != 3\n find = false\n for i in 1..n\n next if $vis[i]\n g.push i\n $vis[i] = true\n find = true\n break\n end\n if not find\n can = false\n break\n end\n end\n end\n group = []\n for i in 1..n\n next if $vis[i]\n group.push i\n if group.size == 3\n groups.push group\n group = []\n end\n end\nend\nif can\n groups.each do |g|\n puts g.join(' ')\n end\nelse\n puts -1\nend\n"}, {"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3}\n puts '-1'\n exit\nend\nf=s.each_index.select { |i| !s[i] }\nf.shift\nfor t in 1..c do\n r=h[t]\n n=r.size\n puts (r | f.pop(3-n)).join ' '\nend\n"}, {"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3}\n puts '-1'\n exit\nend\nf=s.each_index.select { |i| !s[i] }\nf.shift\nfor t in 1..c do\n r=h[t]\n n=r.size\n puts (r | f.pop(3-n)).join ' '\nend\n"}, {"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3}\n puts '-1'\n exit\nend\nf=s.each_index.select { |i| !s[i] }\nf.shift\nfor t in 1..c do\n r=h[t]\n n=r.size\n puts (r | f.pop(3-n)).join ' '\nend"}, {"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3}\n puts '-1'\n exit\nend\nf=s.each_index.select { |i| !s[i] }\nf.shift\nfor t in 1..c do\n r=h[t]\n n=r.size\n puts (r | f.pop(3-n)).join ' '\nend\n"}], "negative_code": [{"source_code": "def dfs(now, parent, group)\n group.push now\n $vis[now] = true\n $path[now].each do |to|\n next if to == parent or $vis[to]\n dfs(to, now, group)\n end\n return group\nend\nn, m = gets.split(' ').map { |i| i.to_i }\n$vis = Array.new(50, false)\n$path = Array.new(50){Array.new}\ngroups = []\ncan = true\nm.times do \n x, y = gets.split(' ').map { |i| i.to_i}\n $path[x].push y\n $path[y].push x\nend\nn.times do |i|\n next if $vis[i+1]\n group = dfs(i+1, -1, [])\n can = false if group.size > 3\n while group.size < 3\n find = false\n for i in 1..n\n next if $vis[i]\n if $path[i].size == 0\n group.push i\n $vis[i] = true\n find = true\n break\n end\n end\n if not find\n can = false\n break \n end\n end\n groups.push group\nend\nif can\n groups.each do |g|\n puts g.join(' ')\n end\nelse\n puts -1\nend"}, {"source_code": "def dfs(now, parent, group)\n group.push now\n $vis[now] = true\n $path[now].each do |to|\n next if to == parent or $vis[to]\n dfs(to, now, group)\n end\n return group\nend\nn, m = gets.split(' ').map { |i| i.to_i }\n$vis = Array.new(50, false)\n$path = Array.new(50){Array.new}\ngroups = []\ncan = true\nm.times do \n x, y = gets.split(' ').map { |i| i.to_i}\n $path[x].push y\n $path[y].push x\nend\nn.times do |i|\n next if $vis[i+1]\n group = dfs(i+1, -1, [])\n can = false if group.size > 3\n while group.size < 3\n find = false\n for i in 1..n\n next if $vis[i]\n if $path[i].size == 0\n group.push i\n $vis[i] = true\n find = true\n break\n end\n end\n break unless find\n end\n groups.push group\nend\nif can\n groups.each do |g|\n puts g.join(' ')\n end\nelse\n puts -1\nend"}, {"source_code": "n,m=gets.split.map(&:to_i)\ns=[nil]*(n+1)\nt=1\nm.times do\n a,b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts'-1'\n exit\n end\nend\nh=Hash.new{|h,k|h[k]=[]}\ns.each_with_index{|a,t|h[a]<3\n puts'-1'\n exit\n else\n puts (r | f.pop(3-n)).join' '\n end\nend"}, {"source_code": "n,m=gets.split.map(&:to_i)\ns=[nil]*(n+1)\nt=1\nm.times do\n a,b=gets.split.map(&:to_i)\n if s[a]==nil&&s[b]==nil\n s[a]=s[b]=t\n t+=1\n elsif s[a]==nil\n s[a]=s[b]\n else\n s[b]=s[a]\n end\nend\nh=Hash.new{|h,k|h[k]=[]}\ns.each_with_index{|a,t|h[a]<3\n puts'-1'\n exit\n else\n puts (r | f.pop(3-n)).join' '\n end\nend"}, {"source_code": "n, m=gets.split.map(&:to_i)\nc=n/3\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > c\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3\n puts '-1'\n exit\n else\n puts (r | f.pop(3-n)).join ' '\n end\nend"}, {"source_code": "n,m=gets.split.map(&:to_i)\ns=[nil]*(n+1)\nt=1\nm.times do\n a,b=gets.split.map(&:to_i)\n if s[a]==nil&&s[b]==nil\n s[a]=s[b]=t\n t+=1\n elsif s[a]==nil\n s[a]=s[b]\n else\n s[b]=s[a]\n end\nend\nh=Hash.new([])\ns.each_with_index{|a,t|h[a]<3\n puts'-1'\n exit\n else\n puts (r | f.pop(3-n)).join' '\n end\nend"}, {"source_code": "n, m=gets.split.map(&:to_i)\ns=[nil]*(n+1)\nt=1\nm.times do\n a, b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n if t > n/3\n puts '-1'\n exit\n end\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n elsif s[a]!=s[b]\n puts '-1'\n exit\n end\nend\nh=Hash.new { |h, k| h[k]=[] }\ns.each_with_index { |a, t| h[a]<3\n puts '-1'\n exit\n else\n puts (r | f.pop(3-n)).join ' '\n end\nend"}, {"source_code": "n,m=gets.split.map(&:to_i)\ns=[nil]*(n+1)\nt=1\nm.times do\n a,b=gets.split.map(&:to_i)\n if s[a].nil?&&s[b].nil?\n s[a]=s[b]=t\n t+=1\n elsif s[a].nil?\n s[a]=s[b]\n elsif s[b].nil?\n s[b]=s[a]\n else\n puts'-1'\n exit\n end\nend\nh=Hash.new{|h,k|h[k]=[]}\ns.each_with_index{|a,t|h[a]<3\n puts'-1'\n exit\n else\n puts (r | f.pop(3-n)).join' '\n end\nend"}], "src_uid": "46e7cd6723553d2c6d6c6d0999a5b5fc"} {"source_code": "#!/usr/bin/ruby\nrequire 'prime'\nn=gets.to_i\np n<3?1:2\nputs (2..n+1).map{|e|e.prime? ? 1 : 2}*' '", "positive_code": [{"source_code": "n = gets.to_i + 1\ncolors = Array.new(n + 1)\n2.upto(n) do |i|\n next if colors[i]\n colors[i] = 1\n (2 * i).step(n, i){|j| colors[j] = 2}\nend\ncolors.shift(2)\np colors.max\nputs colors.join(' ')\n"}, {"source_code": "n = gets.to_i\n\na = Array.new\nmax = 1\n(2..n+1).each do |i|\n (1..n+1).each do |j|\n break if i * j > n+1\n next if a[j].to_i > 1\n next if a[i * j] == 2\n a[i * j] = a[j].to_i == 1 ? 2 : 1\n max = [a[i * j], max].max\n end\nend\n\nputs max\nputs a[2, a.length].join(' ')\n"}, {"source_code": "def is_prime(n=2)\n\tif n < 2\n\t \treturn 0\n\telsif n==2\n\t \treturn 1\n\telsif n%2==0\n\t \treturn 0\n\telse\n\t\tj=3\n\t\twhile j*j<=n\n\t\t\tif n % j == 0\n\t\t\t\treturn 0\n\t\t\tend\n\t\t\tj+=2;\n\t\tend\n\t\treturn 1\n\tend\nend\nn=gets.chomp.to_i\n#puts n\ncolor=Array.new(n+2,1)\n#puts color.join(' ')\nnumber=1\ni=2\nmax=1\nwhile i<=n+1\n\tif is_prime(i)\n\t\tj=2\n\t\twhile i*j <= n+1\n\t\t\tcolor[i*j]=2\n\t\t\tmax=color[i*j] if color[i*j] > max\n\t\t\tj+=1\n\t\tend\n\tend\n\ti+=1\nend\n#puts color.join(' ')\nputs max\ni=2\nwhile i<=n+1\n\tprint \" #{color[i]}\"\n\ti+=1\nend\nputs\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nrequire 'prime'\nn=gets.to_i\np n<2?1:2\nputs (1..n).map{|e|e.prime? ? 1 : 2}*' '"}, {"source_code": "n=gets.chomp.to_i\n#puts n\ncolor=Array.new(n+2,1)\n#puts color.join(' ')\nnumber=1\ni=2\nmax=1\nwhile i<=n+1\n\tj=2\n\twhile i*j <= n+1\n\t\tcolor[i*j]+=1\n\t\tmax=color[i*j] if color[i*j] > max\n\t\tj+=1\n\tend\n\ti+=1\nend\n#puts color.join(' ')\nputs max\ni=2\nwhile i<=n+1\n\tprint \" #{color[i]}\"\n\ti+=1\nend\nputs\n"}, {"source_code": "n=gets.chomp.to_i\n#puts n\ncolor=Array.new(n+2,0)\n#puts color.join(' ')\nnumber=1\ni=2\nmax=0\nwhile i<=n+1\n\tif color[i]==0\n\t\tcolor[i]=number\n\t\tj=2\n\t\twhile i*j <= n+1\n\t\t\tif color[i*j]==0\n\t\t\t\tcolor[i*j]=number+1\n\t\t\t\tmax=number+1 if number + 1 > max\n\t\t\telse\n\t\t\t\tcolor[i*j]=number+2\n\t\t\t\tmax=number+2 if number + 1 > max\n\t\t\t\tnumber+=1;\n\t\t\tend\n\t\t\tj+=1\n\t\tend\n\tend\n\ti+=1\nend\n#puts color.join(' ')\nputs max\ni=2\nwhile i<=n+1\n\tprint \" #{color[i]}\"\n\ti+=1\nend\nputs\n"}, {"source_code": "n = gets.to_i + 1\ncolors = Array.new(n)\n2.upto(n) do |i|\n i.step(n, i).with_index{|j, c| colors[j] ||= c + 1}\nend\ncolors.compact!\np colors.uniq.size\nputs colors.join(' ')\n"}, {"source_code": "n = gets.to_i + 1\ncolors = Array.new(n + 1, 1)\n2.upto(n) do |i|\n c = colors[i] + 1\n (2 * i).step(n, i) do |j|\n colors[j] = [colors[j], c].max\n end\nend\ncolors.shift(2)\np colors.max\nputs colors.join(' ')\n"}, {"source_code": "n = gets.to_i\n\na = Array.new\nmax = 1\n(2..n+1).each do |i|\n (1..n+1).each do |j|\n break if i * j > n+1\n next if a[i * j].to_i > a[j].to_i\n a[i * j] = [a[j].to_i, a[i * j].to_i].max + 1\n max = [a[i * j], max].max\n end\nend\n\nputs max\nputs a[2, a.length].join(' ')\n"}], "src_uid": "a99f5e08f3f560488ff979a3e9746e7f"} {"source_code": "N,K = gets.split.map &:to_i\nes = Hash[(1..N).map{ |n| [n,{}] }]\n(1..N-1).each{ |i|\n a,b = gets.split.map &:to_i\n es[a][b] = es[b][a] = i-1\n}\nR = (1..N).map{ |n| es[n].size }.sort[-K-1]\ncolors = Array.new(N-1,nil)\n\nqueue = [[nil,1]]\n\nwhile cn = queue.pop do\n c,n = cn\n c = 0 if !c\n es[n].each{ |m,i|\n next if colors[i]\n c = (c + 1) % R\n colors[i] = c\n queue << [c,m]\n }\nend\n\np R\nputs colors.map{ |c| c + 1 } * \" \"", "positive_code": [{"source_code": "N,K = gets.split.map &:to_i\nes = Hash[(1..N).map{ |n| [n,{}] }]\n(1..N-1).each{ |i|\n a,b = gets.split.map &:to_i\n es[a][b] = es[b][a] = i-1\n}\nR = (1..N).map{ |n| es[n].size }.sort[-K-1]\ncolors = Array.new(N-1,nil)\n\nqueue = [[nil,1]]\n\nwhile cn = queue.pop do\n c,n = cn\n c = 0 if !c\n es[n].each{ |m,i|\n next if colors[i]\n c = (c + 1) % R\n colors[i] = c\n queue << [c,m]\n }\nend\n\np R\nputs colors.map{ |c| c + 1 } * \" \""}], "negative_code": [], "src_uid": "0cc73612bcfcd3be142064e2da9e92e3"} {"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n string\r\n grid = rep(8) { string }\r\n (2 .. 7).any? do |i|\r\n (2 .. 7).any? do |j|\r\n if grid[i - 2][j - 2] == ?# && grid[i - 2][j] == ?# && grid[i][j - 2] == ?# && grid[i][j] == ?#\r\n puts \"#{i} #{j}\"\r\n true\r\n else\r\n false\r\n end\r\n end\r\n end\r\n end\r\n}\r\n\r\nDEBUG = false\r\nMOD = 10**9+7\r\nINF = 10**18\r\n$yesno = %w(No Yes)\r\n$YesNo = %w(No Yes)\r\n$YESNO = %w(NO YES)\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t ? 1 : 0] end\r\ndef YesNo t; puts $YesNo[t ? 1 : 0] end\r\ndef YESNO t; puts $YESNO[t ? 1 : 0] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]", "positive_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n xxs = 8.times.map { gets.chomp.chars }\r\n r, c = (1..6).flat_map do |i|\r\n (1..6).filter_map do |j|\r\n if xxs[i - 1][j - 1] == \"#\" && xxs[i - 1][j + 1] == \"#\" && xxs[i + 1][j - 1] == \"#\" && xxs[i + 1][j + 1] == \"#\"\r\n [i + 1, j + 1]\r\n end\r\n end\r\n end.first\r\n puts \"#{r} #{c}\"\r\nend\r\n"}, {"source_code": "n = gets.to_i\n\nn.times do\n gets\n\n r = -1\n\n m = Array.new(8)\n\n 8.times do |i|\n line = gets\n\n m[i] = line.chars\n end\n\n 8.times do |i|\n 8.times do |j|\n next unless m[i][j] == \"#\"\n next unless i - 1 > -1 && j - 1 > -1 && m[i - 1][j - 1] == \"#\"\n next unless i + 1 < 8 && j + 1 < 8 && m[i + 1][j + 1] == \"#\"\n next unless i - 1 > -1 && j + 1 < 8 && m[i - 1][j + 1] == \"#\"\n next unless i + 1 > -1 && j - 1 > -1 && m[i + 1][j - 1] == \"#\"\n\n puts [i, j].map(&:succ).map(&:to_s).join(\" \")\n end\n end\nend\n"}, {"source_code": "$cnt = []\r\n\r\ndef solve\r\n v = Array.new(8){Array.new(8)}\r\n t = gets.split\r\n i = 0\r\n while i < 8\r\n s = gets.split('')\r\n j = 0\r\n s.each do |x|\r\n v[i][j] = x\r\n j = j + 1\r\n end\r\n i = i + 1\r\n end\r\n i = 1\r\n while i < 7\r\n j = 1\r\n while j < 7\r\n if v[i - 1][j - 1] == '#' and v[i - 1][j + 1] == '#' and v[i + 1][j - 1] == '#' and v[i + 1][j + 1] == '#'\r\n ans = []\r\n ans.append(i + 1)\r\n ans.append(j + 1)\r\n puts ans * \" \"\r\n end\r\n j = j + 1\r\n end\r\n i = i + 1\r\n end\r\nend\r\n\r\nmaxn = 10005\r\nmaxn.times do\r\n $cnt.append(0)\r\nend\r\ngets.to_i.times do\r\n solve\r\nend"}, {"source_code": "gets.to_i.times do\r\n gets\r\n s = Array.new(8){gets.chomp.chars}\r\n gx, gy = 0, 0\r\n dx = [-1, -1, 1, 1]\r\n dy = [-1, 1, -1, 1]\r\n 8.times do |i|\r\n 8.times do |j|\r\n cnt = 0\r\n 4.times do |k|\r\n x = j+dx[k]\r\n y = i+dy[k]\r\n if 0 <= x && x < 8 && 0 <= y && y < 8\r\n cnt += 1 if s[y][x] == '#'\r\n end\r\n end\r\n if cnt == 4\r\n gx = j+1\r\n gy = i+1\r\n end\r\n end\r\n end\r\n puts \"#{gy} #{gx}\"\r\nend\r\n"}, {"source_code": "gets.to_i.times do\n a = []\n i = 0\n while i < 8\n x = gets.chomp\n if x[0] == '.' || x[0] == '#'\n a << x\n i += 1\n end\n end\n x = 0\n y = 0\n for i in 1...7\n for j in 1...7\n if a[i][j] == '#' && a[i - 1][j - 1] == '#' && a[i + 1][j - 1] == '#' && a[i - 1][j + 1] == '#' && a[i + 1][j + 1] == '#'\n x = i + 1\n y = j + 1\n end\n end\n end\n puts \"#{x} #{y}\"\nend\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n gets\r\n xxs = 8.times.map { gets.chomp.chars }\r\n r, c = (0..7).flat_map do |i|\r\n (0..7).filter_map do |j|\r\n [i + 1, j + 1] if xxs[i][j] == \"#\" && xxs[i].count(\"#\") == 1 && xxs.map { |xs| xs[j] }.count(\"#\") == 1\r\n end\r\n end.first\r\n puts \"#{r} #{c}\"\r\nend\r\n"}], "src_uid": "b0f968ca75fbea2f11a7e4b9006f136e"} {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\n#$stdout=File.open \"output.txt\",\"w\"\n\nnotifications=Array.new\nd=0\na=0\n\nn,q=gets.split.map{|x|x.to_i}\nunread=Array.new(n+1,0)\nread=Array.new(n+1,0)\n\nq.times do \n\n\tt,x=gets.split.map{|y|y.to_i}\n\n\tif t==1 then notifications.push x; a+=1; unread[x]+=1\n\telsif t==2 then \n\t\ta-=unread[x];read[x]+=unread[x];unread[x]=0\n\telsif t==3\n\t\tnotifications[0...x-d].each do |i|\n\t\t\tif read[i]>0 then read[i]-=1\n\t\t\telsif unread[i]>0 and a>0 then unread[i]-=1;a-=1\n\t\t\tend \n\t\t\tnotifications.shift;d+=1\n\t\tend if x-d>0\n\tend \n\n\tputs a \nend \n", "positive_code": [{"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nq = Integer(input[1])\nevent = []\nfor i in 0...q\n event[i] = []\n input1 = gets.chomp.split\n event[i][0] = Integer(input1[0])\n event[i][1] = Integer(input1[1])\nend\n\nunread = 0\nnotification = []\nresult = []\nrecord = []\nfor i in 0...n\n record[i] = []\nend\nx = 0\nfor i in 0...q\n if event[i][0] == 1\n notification.push([event[i][1], 0])\n unread += 1 \n record[event[i][1] - 1].push(notification.length - 1) \n elsif event[i][0] == 2\n for j in record[event[i][1] - 1]\n if j >= x && notification[j][1] == 0\n notification[j][1] = 1\n unread -= 1 \n end\n end\n record[event[i][1] - 1] = []\n else\n if event[i][1] > x\n for j in x...event[i][1]\n if notification[j][1] == 0\n notification[j][1] = 1\n unread -= 1\n end\n end\n x = event[i][1] \n end\n end\n result.push(unread)\nend\n \nputs result "}, {"source_code": "@n, @q = STDIN.gets.split(' ').collect{|x| x.to_i}\n@record = Hash.new{|hash,key| hash[key] = Array.new}\n@g, @decnt, @maxt, @count = Array.new, 0, 0, 0\n@q.times do \n\topt, x = STDIN.gets.split(' ').collect{|x| x.to_i}\n\tcase opt \n\t\twhen 1 then \n\t\t\t@g.push true\n\t\t\t@record[x].push(@count)\n\t\t\t@count += 1\n\t\twhen 2 then\n\t\t\t@record[x].each do |v|\n\t\t\t\tif @g[v] then \n\t\t\t\t\t@g[v] = false\n\t\t\t\t\t@decnt += 1\n\t\t\t\tend\n\t\t\tend\n\t\t\t@record[x].clear\n\t\twhen 3 then \n\t\t\tfor i in @maxt...[x, @count].min do \n\t\t\t\tif @g[i] then \n\t\t\t\t\t@g[i] = false\n\t\t\t\t\t@decnt += 1\n\t\t\t\tend\n\t\t\tend\n\t\t\t@maxt = [[x, @count].min, @maxt].max \n\tend\n\tputs @count-@decnt\nend\n\n"}], "negative_code": [{"source_code": "input = gets.chomp.split\nn = Integer(input[0])\nq = Integer(input[1])\nevent = []\nfor i in 0...q\n event[i] = []\n input1 = gets.chomp.split\n event[i][0] = Integer(input1[0])\n event[i][1] = Integer(input1[1])\nend\n\n=begin\ndef unread_count(a)\n unread_count = 0\n for i in 0...a.length\n if a[i][1] == 0\n unread_count += 1\n end\n end\n return unread_count\nend\n=end\n\nunread = 0\nnotification = []\nresult = []\nrecord = []\nfor i in 0...n\n record[i] = []\nend\nx = 0\nfor i in 0...q\n if event[i][0] == 1\n notification.push([event[i][1], 0])\n unread += 1 \n record[event[i][1] - 1].push(notification.length - 1) \n elsif event[i][0] == 2\n for j in record[event[i][1] - 1]\n if j > x && notification[j][1] == 0\n notification[j][1] = 1\n unread -= 1 \n end\n end\n else\n if event[i][1] > x\n for j in x...event[i][1]\n if notification[j][1] == 0\n notification[j][1] = 1\n unread -= 1\n end\n end\n x = event[i][1] \n end\n end\n result.push(unread)\nend\n \nputs result "}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\nn,q=gets.split.map{|x|x.to_i}\nnotifications=Array.new\ncount=Array.new\nc=0\nq.times do \n\ta,b=gets.split.map{|x|x.to_i}\n\t\n\tif a==1\n\t\tnotifications[b]=0 if notifications[b]==nil\n\t\tnotifications[b]+=1\n\t\tcount[c]=b;\n\t\tc+=1\n\telsif a==2\n\t\tnotifications[b]=0\n\telse\n\t\tcount[0..b].each {|x| notifications[x]-=1 if notifications[x]>0}\n\tend\n\tsum=0\n\tnotifications.each {|x| sum+=x if x!=nil}\n\tputs sum\nend\n"}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\nn,q=gets.split.map{|x|x.to_i}\nnotifications=Array.new\ncount=Array.new\nc=0\nq.times do \n\ta,b=gets.split.map{|x|x.to_i}\n\t\n\tif a==1\n\t\tnotifications[b]=0 if notifications[b]==nil\n\t\tnotifications[b]+=1\n\t\tcount[c]=b;\n\t\tc+=1\n\telsif a==2\n\t\tnotifications[b]=0\n\telse\n\t\tcount[0...b].each {|x| notifications[x]-=1 if notifications[x]>0}\n\tend\n\tsum=0\n\tnotifications.each {|x| sum+=x if x!=nil}\n\tputs sum\nend\n"}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\n\nnotifications=Array.new\na=0\n\nn,q=gets.split.map{|x|x.to_i}\nunread=Array.new(n+1,0)\nread=Array.new(n+1,0)\n\nq.times do \n\n\tt,x=gets.split.map{|y|y.to_i}\n\n\tif t==1 then notifications.push x; a+=1; unread[x]+=1\n\telsif t==2 then \n\t\ta-=unread[x];read[x]+=unread[x];unread[x]=0\n\telsif t==3\n\t\tnotifications[0...x].each do |i|\n\t\t\tif read[i]!=0 then read[i]-=1\n\t\t\telse unread[i]-=1;a-=1 \n\t\t\tend \n#print notifications, \"\\n\"\n#print read,\"\\n\"\n#print unread, \"\\n\"\n\t\tend \n\tend \n#\tprint read,\"\\n\"\n#\tprint unread,\"\\n\"\n\tputs a \nend \n"}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\n\nnotifications=Array.new\nread=Array.new\n\nn,q=gets.split.map{|x|x.to_i}\n\nq.times do \n\n\tt,x=gets.split.map{|y|y.to_i}\n\n\tnotifications.push x if t==1\n\tif t==2\n\t\tnotifications.each do |y|\n\t\t\tind=notifications.index y\n\t\t\tread[ind]=y if y==x\n\t\tend \n\telsif t==3\n\t\tnotifications[0...x].each do |y|\n\t\t\tind = notifications.index y\n\t\t\tread[ind]=y \n\t\tend \n\tend \n\tputs (notifications-read).length\nend \n"}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\n\nnotifications=Array.new\na=0\n\nn,q=gets.split.map{|x|x.to_i}\nunread=Array.new(n+1,0)\nread=Array.new(n+1,0)\n\nq.times do \n\n\tt,x=gets.split.map{|y|y.to_i}\n\n\tif t==1 then notifications.push x; a+=1; unread[x]+=1\n\telsif t==2 then \n\t\ta-=unread[x];read[x]+=unread[x];unread[x]=0\n\telsif t==3\n\t\tnotifications[0...x].each do |i|\n\t\t\tif read[i]!=0 then read[i]-=1\n\t\t\telsif unread[i]>0 and a>0 then unread[i]-=1;a-=1 \n\t\t\tend \n#print notifications, \"\\n\"\n#print read,\"\\n\"\n#print unread, \"\\n\"\n\t\tend \n\tend \n#\tprint read,\"\\n\"\n#\tprint unread,\"\\n\"\n\tputs a \nend \n"}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\n#$stdout=File.open \"output.txt\",\"w\"\n\nnotifications=Array.new\nd=0\na=0\n\nn,q=gets.split.map{|x|x.to_i}\nunread=Array.new(n+1,0)\nread=Array.new(n+1,0)\n\nq.times do \n\n\tt,x=gets.split.map{|y|y.to_i}\n\n\tif t==1 then notifications.push x; a+=1; unread[x]+=1\n\telsif t==2 then \n\t\ta-=unread[x];read[x]+=unread[x];unread[x]=0\n\telsif t==3\n#\tcur_read=read.clone\n\t\tnotifications[0...x-d].each do |i|\n#\t\t\tif cur_read[i]>0 then cur_read[i]-=1\n\t\t\tif read[i]>0 then read[i]-=1;notifications.shift;d+=1\n\t\t\telsif unread[i]>0 and a>0 then unread[i]-=1;a-=1\n\t\t\tend \n\t\tend \n\tend \n\n\tputs a \nend \n"}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\n#$stdout=File.open \"output.txt\",\"w\"\n\nnotifications=Array.new\nd=0\na=0\n\nn,q=gets.split.map{|x|x.to_i}\nunread=Array.new(n+1,0)\nread=Array.new(n+1,0)\n\nq.times do \n\n\tt,x=gets.split.map{|y|y.to_i}\n\n\tif t==1 then notifications.push x; a+=1; unread[x]+=1\n\telsif t==2 then \n\t\ta-=unread[x];read[x]+=unread[x];unread[x]=0\n\telsif t==3\n\t\tnotifications[0...x-d].each do |i|\n\t\t\tif read[i]>0 then read[i]-=1;d+=1\n\t\t\telsif unread[i]>0 and a>0 then unread[i]-=1;a-=1\n\t\t\tend \n\t\t\tnotifications.shift\n\t\tend if x-d>0\n\tend \n\n\tputs a \nend \n"}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\nn,q=gets.split.map{|x|x.to_i}\nnotifications=Array.new\ncount=Array.new\nc=0\nq.times do \n\ta,b=gets.split.map{|x|x.to_i}\n\t\n\tif a==1\n\t\tnotifications[b]=0 if notifications[b]==nil\n\t\tnotifications[b]+=1\n#print -1,notifications,-1,\"\\n\"\n\t\tcount[c]=b;\n\t\tc+=1\n#\t\tprint -3,count,-3,\"\\n\"\n\telsif a==2\n\t\tnotifications[b]=0\n\telse\n\t\tcount.each do |x|\n\t\t\tnotifications[x]-=1\n#\t\t\tprint -2,notifications,-2,\"\\n\"\n\t\tend\n\tend\n\tsum=0\n\tnotifications.each {|x| sum+=x if x!=nil}\n\tputs sum\nend\n"}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\n\nnotifications=Array.new\na=0\n\nn,q=gets.split.map{|x|x.to_i}\nunread=Array.new(n+1,0)\nread=Array.new(n+1,0)\n\nq.times do \n\n\tt,x=gets.split.map{|y|y.to_i}\n\n\tif t==1 then notifications.push x; a+=1; unread[x]+=1\n\telsif t==2 then \n\t\ta-=unread[x];read[x]+=unread[x];unread[x]=0\n\telsif t==3\n\t\tnotifications[0...x].each do |i|\n\t\t\tif read[i]!=0 then read[i]-=1\n\t\t\telsif unread[i]>0 and a>0 then unread[i]-=1;a-=1 \n\t\t\tend \n\t\tend \n\tend \n\n\tputs a \nend \n"}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\n#$stdout=File.open \"output.txt\",\"w\"\n\nnotifications=Array.new\na=0\n\nn,q=gets.split.map{|x|x.to_i}\nunread=Array.new(n+1,0)\nread=Array.new(n+1,0)\n\nq.times do \n\n\tt,x=gets.split.map{|y|y.to_i}\n\n\tif t==1 then notifications.push x; a+=1; unread[x]+=1\n\telsif t==2 then \n\t\ta-=unread[x];read[x]+=unread[x];unread[x]=0\n\telsif t==3\n\t\tcread=read.clone\n\t\tnotifications[0...x].each do |i|\n\t\t\tif cread[i]!=0 then cread[i]-=1\n\t\t\telsif unread[i]>0 and a>0 then unread[i]-=1;a-=1 \n\t\t\tend \n\t\tend \n\tend \n\n#\tprint read,\"\\n\"\n#\tprint unread,\"\\n\"\n\tputs a \nend \n"}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\n\nnotifications=Array.new\na=0\n\nn,q=gets.split.map{|x|x.to_i}\nunread=Array.new(n+1,0)\nread=Array.new(n+1,0)\n\nq.times do \n\n\tt,x=gets.split.map{|y|y.to_i}\n\n\tif t==1 then notifications.push x; a+=1; unread[x]+=1\n\telsif t==2 then \n\t\ta-=unread[x];read[x]+=unread[x];unread[x]=0\n\telsif t==3\n\t\tnotifications[0...x].each do |i|\n\t\t\tif read[i] then read[i]-=1\n\t\t\telse unread[x]-=1;a-=1 \n\t\t\tend \n\t\tend \n\tend \n\n\tputs a \nend \n"}, {"source_code": "#$stdin=File.open \"input.txt\",\"r\"\nn,q=gets.split.map{|x|x.to_i}\nnotifications=Array.new\ncount=Array.new\nc=0\nq.times do \n\ta,b=gets.split.map{|x|x.to_i}\n\t\n\tif a==1\n\t\tnotifications[b]=0 if notifications[b]==nil\n\t\tnotifications[b]+=1\n\t\tcount[c]=b;\n\t\tc+=1\n\telsif a==2\n\t\tnotifications[b]=0\n\telse\n\t\tcount.each {|x| notifications[x]-=1 if notifications[x]>0}\n\tend\n\tsum=0\n\tnotifications.each {|x| sum+=x if x!=nil}\n\tputs sum\nend\n"}], "src_uid": "a5e724081ad84f88813bb4de23a8230e"} {"source_code": "def prime?(num)\n 2.upto(num-1){|i|\n if num % i == 0\n return false \n end\n }\n return true\nend\np = Array.new\ni = 2\nwhile p.length < 50\n if prime?(i)\n p << i\n end\n i += 1\nend\nn = gets.to_i\nif n!=2\n for i in 0...n\n ans = 1\n for j in 0...n-1\n ans *= p[(i+j)%n]\n end\n puts ans\n end\nelse \n puts -1\nend\n\n", "positive_code": [{"source_code": "primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29,\n 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,\n 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,\n 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,\n 179, 181, 191, 193, 197, 199, 211, 223, 227, 229]\nn = gets.to_i\nif n > 2\n product = primes[0,n].inject(1) {|x, y| x * y}\n (0...n).each do |i|\n p product/primes[i]\n end\nelse\n p -1\nend\n"}, {"source_code": "require 'mathn'\n\nn = gets.to_i\n\nif n == 2 then puts \"-1\"\nelse\n\nprimes = []\np = Prime.new\nn.times do\n primes << p.next()\nend\n\nproduct = primes.inject do |p, x|\n p * x\nend\na = primes.map do |x|\n product / x\nend\n\nputs a.join(\"\\n\")\n\nend\n"}, {"source_code": "require 'prime'\n\nn = gets.to_i\nif n == 2\n\tp -1\n\texit\nend\n\na = []\nPrime.each do |prime|\n\ta << prime\n\tbreak if a.size == n\nend\ns = a.inject(&:*)\na = a.map{|_| s / _}\nputs a * \"\\n\"\n__END__\nn.times do |i|\n\tp a[i] if a[i].to_s.size > 100\n\ti.times do |j|\n\t\tp \"#{a[i]} #{a[j]}\" if a[i].gcd(a[j]) == 1\n\tend\nend\np \"555\" if a.inject(&:gcd) > 1\n"}, {"source_code": "#!/usr/bin/ruby\n\nrequire 'prime'\n\nn = gets.to_i\nif n == 2\n\tp -1\n\texit\nend\n\narr = Prime.take(n)\n\nn.times { |i|\n\ttmp = arr.dup\n\ttmp.delete_at(i)\n\tp tmp.inject(:*)\n}\n"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join(\"\\n\") : -1\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nif n == 1\n puts 2\n exit 0\nend\nif n == 2\n puts -1\n exit 0\nend\nprimes = []\n# get primes\nx = 2\nwhile primes.size < n+1\n ok = true\n primes.each { |t|\n if (x % t == 0)\n ok = false\n break;\n end\n }\n if ok\n primes.push(x)\n end\n x = x + 1\nend\n\nans = []\n(n-1).times { |i|\n ans.push(primes[0])\n}\nans.push(1)\n\n(n-1).times { |i|\n ans[i] *= primes[i+1]\n ans[n-1] *= primes[i+1]\n}\n\nn.times { |i|\n puts ans[i]\n}\n"}, {"source_code": "require 'prime'\nn = gets\nn = n.to_i\ni = 0\nnum = 2\nprimes = Array.new()\nwhile i 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join(\"\\n\") : -1\n"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join(\"\\n\") : -1\n"}, {"source_code": "\ndef prime x\n\n m = Math.sqrt x\n for i in 2..m\n if x % i == 0\n return false\n end\n end\n\n return true\n\nend\n\nn = gets.to_i\n\nif n == 2\n puts -1\nelse\n\n primes = []\n\n cur = 2\n while primes.size < n\n if prime cur\n primes.push cur\n end\n cur += 1\n end\n\n product = 1\n for prime in primes\n product *= prime\n end\n\n for i in 0...n\n puts product / primes[i]\n end\nend\n"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join(\"\\n\") : -1\n"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join(\"\\n\") : -1"}, {"source_code": "N = gets.to_i\n\nif N == 2\n puts -1\nelse\n puts 21\n puts 14\n 1.upto(N - 2) { |i|\n puts 3 * (2 ** i)\n }\nend\n"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join(\"\\n\") : -1"}, {"source_code": "n = STDIN.gets.chomp.to_i\nif n == 2\n puts -1\n exit 0\nend\n\nvalues = [99, 55, 11115]\nproduct = values.reduce(&:*)\nmultiplier = 1\n4.upto(n) do\n values.push(product * multiplier)\n multiplier += 1\nend\nvalues.each do |value|\n puts value\nend\n"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join(\"\\n\") : -1\n"}, {"source_code": "def gcd(a, b)\n return a if b.eql? 0\n gcd(b, a % b)\nend\n\nn = gets.to_i\n\nif (n == 2)\n puts -1\n exit\nend\n\nmas = [20,18,15]\nfor i in 3..n-1\n mas[i] = mas[i-1]*3;\nend\n\nputs mas"}, {"source_code": "n = gets.to_i\n\nprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239,]\n\nif n == 2\n puts -1\nelse\n n.times do |i|\n puts (primes[0,n] - [primes[i]]).inject(1){|r,j| r*j}\n end\nend\n"}, {"source_code": "a = [\n2, 3, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241\n];\n\nn = gets.to_i\n\nif n == 2 then print \"-1\"\nelse\n mega_res = 1\n for i in 0..(n-2) do\n puts (a[i] * a[n])\n mega_res = mega_res * a[i]\n end\n puts mega_res\nend\n"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join(\"\\n\") : -1\n"}, {"source_code": "def is_prime(n)\n i = 2\n while i * i <= n\n return false if n % i == 0\n i += 1\n end\n true\nend\n\nn = gets.to_i\n\nif n == 2 \n puts -1\nelse\n i = 2\n primes = []\n while primes.size < n\n primes << i if is_prime(i)\n i += 1\n end\n\n product = primes.inject(1) { |p, i| p * i }\n puts primes.map { |p| product / p }\nend\n"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join(\"\\n\") : -1\n"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join(\"\\n\") : -1\n"}], "negative_code": [{"source_code": "primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29,\n 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,\n 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,\n 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,\n 179, 181, 191, 193, 197, 199, 211, 223, 227, 229]\nn = gets.to_i\nproduct = primes[0,n].inject(1) {|x, y| x * y}\n(0...n).each do |i|\n p product/primes[i]\nend\n"}, {"source_code": "require 'mathn'\n\nn = gets.to_i\n\nprimes = []\np = Prime.new\nn.times do\n primes << p.next()\nend\n\nproduct = primes.inject do |p, x|\n p * x\nend\na = primes.map do |x|\n product / x\nend\n\nputs a.join(\" \")\n"}, {"source_code": "require 'mathn'\n\nn = gets.to_i\n\nprimes = []\np = Prime.new\nn.times do\n primes << p.next()\nend\n\nproduct = primes.inject do |p, x|\n p * x\nend\na = primes.map do |x|\n product / x\nend\n\nputs a.join(\"\\n\")\n"}, {"source_code": "#!/usr/bin/ruby\n\nrequire 'prime'\n\nn = gets.to_i\nif n == 2\n\tp -1\n\texit\nend\n\narr = Prime.take(50)\n\nn.times { |i|\n\ttmp = arr.dup\n\ttmp.delete_at(i)\n\tp tmp.inject(:*)\n}\n"}, {"source_code": "#!/usr/bin/ruby\n\nrequire 'mathn'\n\nn = gets.to_i\nif n == 2\n\tp -1\n\texit\nend\n\narr = []\nPrime.each(1000) { |pr|\n\tarr << pr\n\tbreak if arr.size == n\n}\n\nn.times { |i|\n\ttmp = arr.dup\n\ttmp.delete_at(i)\n\tp tmp.inject(:*)\n\tp tmp.inject(:*).to_s.size\n}\n"}, {"source_code": "#!/usr/bin/ruby\n\nrequire 'mathn'\n\nn = gets.to_i\nif n == 2\n\tp -1\n\texit\nend\n\narr = []\nPrime.each(100) { |pr|\n\tarr << pr\n\tbreak if arr.size == n\n}\n\nn.times { |i|\n\ttmp = arr.dup\n\ttmp.delete_at(i)\n\tp tmp.inject(:*)\n}\n"}, {"source_code": "n = STDIN.gets.chomp.to_i\nprimes = []\n# get primes\nx = 2\nwhile primes.size < n+1\n ok = true\n primes.each { |t|\n if (x % t == 0)\n ok = false\n break;\n end\n }\n if ok\n primes.push(x)\n end\n x = x + 1\nend\n\nans = []\n(n-1).times { |i|\n ans.push(primes[0])\n}\nans.push(1)\n\n(n-1).times { |i|\n ans[i] *= primes[i+1]\n ans[n-1] *= primes[i+1]\n}\n\nn.times { |i|\n puts ans[i]\n}\n"}, {"source_code": "\ndef prime x\n\n m = Math.sqrt x\n for i in 2..m\n if x % i == 0\n return false\n end\n end\n\n return true\n\nend\n\n\nn = gets.to_i\n\nprimes = []\n\ncur = 2\nwhile primes.size < n\n if prime cur\n primes.push cur\n end\n cur += 1\nend\n\nproduct = 1\nfor prime in primes\n product *= prime\nend\n\nfor i in 0...n\n puts product / primes[i]\nend\n"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join(' ') : -1"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join('\\n') : -1"}, {"source_code": "n = gets.to_i\nputs n > 2 ? ([10, 15] + (1..n - 2).map{|x| 6 * x}).join('/n') : -1"}, {"source_code": "n = STDIN.gets.chomp.to_i\nif n == 2\n puts -1\n exit 0\nend\n\nfactorial = {}\nf = 1\n1.upto(n + 5) do |i|\n f *= i\n factorial[i] = f\nend\n\nvalues = []\n1.upto(n - 2) do |i|\n values.push(factorial[i+1])\nend\n\nvalues.each { |x| puts x }\nputs values.last * 97\nputs values.last * 97 * 2\n"}, {"source_code": "a = [\n2, 3, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241\n];\n\nn = 0;\nn = gets.to_i\n\nif n == 2 then print \"-1\"\nelse\n mega_res = 1\n for i in 0..(n-2) do\n print (a[i] * a[n]) , \" \"\n mega_res = mega_res * a[i]\n end\n print mega_res\nend\n"}, {"source_code": "a = [\n2, 3, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239\n];\n\nn = 0;\nn = gets.to_i\n\nif n == 2 then print \"-1\"\nelse\n mega_res = 1\n for i in 0..(n-1) do\n print (a[i] * a[n-1]) , \" \"\n mega_res = mega_res * a[i]\n end\n print mega_res\nend\n"}, {"source_code": "a = [\n2, 3, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241\n];\n\nn = 0;\nn = gets.to_i\n\nif n == 2 then print \"-1\"\nelse\n mega_res = 1\n for i in 0..(n-1) do\n print (a[i] * a[n]) , \" \"\n mega_res = mega_res * a[i]\n end\n print mega_res\nend\n"}, {"source_code": "def is_prime(n)\n i = 2\n while i * i <= n\n return false if n % i == 0\n i += 1\n end\n true\nend\n\nn = gets.to_i\n\ni = 2\nprimes = []\nwhile primes.size < n\n primes << i if is_prime(i)\n i += 1\nend\n\nproduct = primes.inject(1) { |p, i| p * i }\nputs primes.map { |p| product / p }\n"}], "src_uid": "b3108315889607dabcd3112bcfe3fb54"} {"source_code": "n = gets.to_i\nans = 0\nq = []\nn.times do\n a, b = gets.split\n b = b.to_i\n if a == '-'\n ans += 1 if q.delete(b).nil?\n else\n q << b\n end\n ans = [ans, q.size].max\nend\nputs ans\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\nh={}\ncap=cur=0\ngets.to_i.times{\n\tx,y=gets.split\n\ty=y.to_i\n\tif x=='+' && !h[y]\n\t\tcur+=1\n\t\th[y]=1\n\telsif x=='-' && h[y]\n\t\tcur-=1\n\t\th[y]=nil\n\telsif x=='-' && !h[y]\n\t\tcap+=1\n\tend\n\tcap=[cap,cur].max\n}\np cap"}, {"source_code": "#!/usr/bin/ruby\n\ndef solution(n, records)\n set = {}\n mx = 0\n records.each do |rec|\n mx+=1 if rec[0] == '-' && ! set[rec[1]]\n set.delete rec[1] if rec[0] == '-'\n set[rec[1]] = rec if rec[0] == '+'\n mx = [mx, set.size].max\n end\n puts mx\nend\n\nn = gets.to_i\nrecords = []\nn.times { records.push(gets.split(' ')) }\nsolution n, records\n"}, {"source_code": "# http://codeforces.com/contest/567/problem/B\n\nrequire 'set'\nn = gets.chomp.to_i\ncounter = Hash.new { |h, k| h[k] = Set.new }\nmemo = Hash.new(0)\nn.times do |idx|\n op, num = gets.chomp.split\n counter[idx] = counter[idx - 1].clone\n\n case op\n when '+'\n memo[num] += 1\n counter[idx] << num\n else\n if memo[num] == 1\n memo[num] -= 1\n else\n (- 1...idx).each { |idx2| counter[idx2] << num }\n end\n counter[idx] -= [num]\n end\nend\n\nputs counter.values.map(&:length).max\n"}, {"source_code": "# require 'pry'\ndef read_ints; gets.chomp.split.map(&:to_i) end\nn = read_ints[0]\ncurrent = 0\nmax = 0\ncurrent_stack = []\nn.times do\n\tline = gets.chomp.split\n\tif(line[0]=='+')\n\t\t#new man come\n\t\tcurrent+=1\n\t\tcurrent_stack<max\n\telse\n\t\t#man come out\n\t\tman_id = line[1].to_i\n\t\tif(current_stack.include? man_id)\n\t\t\tcurrent_stack.delete(man_id)\n\t\t\tcurrent-=1\n\t\telse #was there from begging\n\t\t\tmax+=1\n\t\tend\n\tend\nend\nputs max"}, {"source_code": "n = gets.chomp.to_i\nrs = []\nn.times{\n rs << gets.chomp.split(' ')\n}\n\ncnt = 0\nhs = Hash.new\nrs.each do |r|\n if r[0] == '-' && hs[r[1]] != '+'\n cnt += 1\n end\n hs[r[1]] = r[0]\nend\n\nrtn = cnt\nrs.each do |r|\n if r[0] == '-'\n cnt -= 1\n else\n cnt += 1\n end\n rtn = cnt if rtn < cnt \nend\n\nputs rtn\n"}, {"source_code": "require 'set'\n\nn=gets.chomp.to_i\nsign=Array.new(1000001){0}\nline=[]\nroom=Set.new\nfor i in 0...n\n line.push(gets.chomp)\n s=line[i].split(\" \")\n num=s[1].to_i\n if s[0]==\"-\"\n if sign[num]==0\n room.add(num)\n end\n else\n sign[num]=1\n end\nend\nans=room.size\nfor i in 0...n\n s=line[i].split(\" \")\n if s[0]==\"+\"\n room.add(s[1].to_i)\n else\n room.delete(s[1].to_i)\n end\n if room.size>ans\n ans=room.size\n end\nend\nputs ans\n"}, {"source_code": "list_length = gets.chomp.gsub(/ /,'').to_i\nnumbers = []\n\nlist_length.times do |i|\n numbers << gets.chomp.gsub(/ /,'').to_i\nend\n\ncurrent_number_in_room = 0\nmax = 0\ncurrent_users_in_room = []\n\nnumbers.each do |number|\n number = number.to_i\n\n if number > 0\n current_number_in_room += 1\n current_users_in_room << number.abs\n\n max <= current_number_in_room ? (max = current_number_in_room) : max\n else\n if current_users_in_room.include?(number.abs)\n current_users_in_room.delete(number.abs)\n\n current_number_in_room -= 1\n else\n maybe_max = max + 1\n\n max <= maybe_max ? max = maybe_max : max\n end\n end\nend\n\nputs max\n\n"}, {"source_code": "logNum = gets.chomp.to_i\n\ndata = []\nroom = 0\nstartRoom = 0\nresult = -1\npeopleExit = false\ninPeople = 0\ninitialPeople = []\nlogs = []\n\n(0...logNum).each do |iter|\n\tlog = gets.chomp.split(' ')\n\tlogs << log\n\n\tif log[0] == \"+\"\n\t\tdata << log[1]\n\telse\n\t\tif !data.include?(log[1])\n\t\t\tstartRoom += 1\n\t\tend\n\tend\nend\n\n\ndata = data.clear\nroom = startRoom\nresult = startRoom\n\n#puts \"middle room : #{room}\"\n\nlogs.each do |log|\n\n\tif log[0] == \"+\"\n\t\tdata << log[1]\n\t\troom += 1\n\telse\n\t\tif data.include?(log[1])\n\t\t\tdata.delete(log[1])\n\t\tend\n\n\t\troom -= 1\n\tend\n\n\tresult = room if result < room\nend\n\nputs result"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\n\ndef solution(n, records)\n set = {}\n mx = 0\n records.reverse.each do |rec|\n set.delete rec[1] if rec[0] == '+'\n set[rec[1]] = rec if rec[0] == '-'\n mx = [mx, set.size].max\n end\n puts mx\nend\n\nn = gets.to_i\nrecords = []\nn.times { records.push(gets.split(' ')) }\nsolution n, records\n\n# solution 6, [%w(+ 12001),%w(- 12001),%w(- 1),%w(- 1200),%w(+ 1),%w(+ 7)]\n# solution 4, 4, '.cc.', [1, 2, 1, 0], %w(. . a a)\n# solution 4,3\n# solution 3,2\n# solution 3,1\n# solution 3,3\n# solution 2,1\n# solution 2,2\n#\n# #\n# # solution 4, [75, 150, 75, 50]\n# # solution 3, [100, 150, 250]"}, {"source_code": "# http://codeforces.com/contest/567/problem/B\n\nrequire 'set'\nn = gets.chomp.to_i\ncounter = Hash.new { |h, k| h[k] = Set.new }\nmemo = Hash.new(0)\nn.times do |idx|\n op, num = gets.chomp.split\n counter[idx] = counter[idx - 1].clone\n\n case op\n when '+'\n memo[num] += 1\n counter[idx] << num\n else\n if memo[num] == 1\n memo[num] -= 1\n counter[idx] -= [num]\n else\n (0..idx).each { |idx2| counter[idx2] << num }\n end\n end\nend\n\nputs counter.values.map(&:length).max\n"}, {"source_code": "logNum = gets.chomp.to_i\n\ndata = []\nroom = 0\nstartRoom = 0\nresult = -1\npeopleExit = false\ninPeople = 0\n\n(0...logNum).each do |iter|\n\tlog = gets.chomp.split(' ')\n\n\tif log[0] == \"+\"\n\t\tdata << log[1]\n\t\troom += 1\n\n\t\tinPeople += 1 if !peopleExit\n\telse\n\t\tpeopleExit = true\n\t\tif data.include?(log[1])\n\t\t\tdata.delete(log[1])\n\t\t\troom -= 1\n\t\telse\n\t\t\tstartRoom += 1\n\t\tend\n\tend\n\n\tresult = room if result < room\nend\n\nresult = inPeople + startRoom if result < inPeople + startRoom\n\nputs result"}], "src_uid": "6cfd3b0a403212ec68bac1667bce9ef1"} {"source_code": "require \"set\"\r\n\r\ngets.to_i.times do\r\n n = gets.to_i\r\n xs = gets.split.map(&:to_i)\r\n replaced = Set.new\r\n last = 0\r\n xs.each_cons(2).each.with_index do |(a, b), i|\r\n a = replaced.include?(a) ? 0 : a\r\n b = replaced.include?(b) ? 0 : b\r\n if a <= b\r\n else\r\n (last..i).each do |i|\r\n replaced << xs[i]\r\n end\r\n last = i\r\n end\r\n end\r\n p replaced.count\r\nend\r\n", "positive_code": [{"source_code": "require 'set'\ngets.to_i.times do\n n=gets.to_i\n # a\u3092\u5e83\u7fa9\u5358\u8abf\u5897\u52a0\u306b\u3059\u308b\u624b\u6570\u306emin\n a=gets.split.map(&:to_i)\n t=-1\n (n-1).times do |i|\n t=i if a[i]>a[i+1]\n end\n s=Set.new\n (t+1).times {|i| s << a[i]}\n lim=t\n (n-1).downto(t+1) do |i|\n if s.include? a[i] then\n lim=i\n break\n end\n end\n p lim==-1 ? 0 : a[0..lim].uniq.size\nend\n"}], "negative_code": [], "src_uid": "68e830551c1580bb5aff40d7848d968d"} {"source_code": "STDIN.readline\nwhile !STDIN.eof? && signups = STDIN.readline.strip.split(\" \").map(&:to_i)\n valid = false\n group_signups = {}\n signups.each.with_index do |signup, index|\n if(index > 0)\n if(group_signups[-signup])\n valid = true\n break\n else\n group_signups[signup] = signup\n end\n end\n end\n\n if(!valid)\n puts \"YES\"\n exit\n end\nend\n\nputs \"NO\"\n", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\na = m.times.map{gets.split.map(&:to_i)[1..-1].uniq.map(&:abs)}\nputs a.any?{|x| x.size == 1 || x.uniq.size == x.size} ? 'YES' : 'NO'\n"}], "negative_code": [], "src_uid": "f110b9351fe8ff20676d11ecfc92aee3"} {"source_code": "def read_array(to)\n gets.strip.split(' ').map(&to)\nend\n\nMAPPING = ('a'..'z').to_a.zip((0..26)).inject({}) { |m, h| m[h[0]] = h[1]; m }\n\ngets.strip.to_i.times do\n _, _ = read_array(:to_i)\n s = gets.strip\n p = read_array(:to_i)\n sums = []\n s.split('').inject(Array.new(26, 0)) do |m, c|\n m[MAPPING[c]] += 1\n sums << m.dup\n m\n end\n res = Array.new(26, 0)\n (p + [s.size]).each_with_index do |t, i|\n res = sums[t-1].zip(res).map { |x| x[0] + x[1] }\n end\n puts res.join(' ')\nend", "positive_code": [{"source_code": "n=gets.to_i\n(1..n).each do |x|\n array = []\n a,b=gets.chomp.split(\" \").map(&:to_i)\n str=gets.chomp.split(\"\")\n array=gets.chomp.split(\" \").map(&:to_i)\n array.push(a)\n temp = Array.new(a, 0)\n array.each do |arr|\n temp[arr-1] += 1\n end\n a -= 1\n while a > 0\n a -= 1\n temp[a] += temp[a+1]\n end\n result = Array.new(26, 0)\n k = 0\n temp.each do |arr|\n result[str[k].ord - 97] += arr\n k += 1\n end\n print(\"#{result.join(\" \")}\\n\")\nend"}], "negative_code": [], "src_uid": "51ea912b40b07c1ba097292ffd0cec18"} {"source_code": "n = gets.chomp.to_i\nstr = gets.chomp\n\ni = 0\nc = 0\nwhile i * n < str.length do\n i+=1\n next if i*n < 3 || i*n >= str.length\n if str[i*n - 1] == str[i*n - 2] &&\n str[i*n - 1] == str[i*n - 3]\n c += 1\n end\nend\nputs c\n", "positive_code": [{"source_code": "n=gets.to_i\ns=gets.chomp\nl=s.size\nc=0\np\nfor i in (n..l-1).step(n) do\n c+=1 if s[i-1]==s[i-2] and s[i-1]==s[i-3]\nend\np c\n"}, {"source_code": "n = gets.to_i \ns = gets.chomp\nc=0;\nfor i in (n..s.length-1).step(n)\n\tif(s[i-1]==s[i-2] && s[i-3]==s[i-1])\n\t\tc+=1;\n\tend\nend\np c"}, {"source_code": "n = gets.to_i\nar = gets.chomp\nc = 0;\nfor i in (n..ar.length-1).step(n)\n\tif(ar[i-1]==ar[i-2] && ar[i-1]==ar[i-3])\n\t\tc+=1\n\tend\nend\np c; "}, {"source_code": "n = gets.to_i\ns = gets.chomp\ni = n\nc = 0\nwhile i < s.size\n c += 1 if s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]\n i += n\nend\nputs c"}, {"source_code": "n = gets.to_i\nputs gets.chomp.slice(1,2000).chars.each_slice(n).select{|x|\n x.length == n && x[-4] == x[-3] && x[-3] == x[-2]\n}.length\n"}, {"source_code": "n = gets.to_i\nseq = gets.chomp!\nret = 0\nfor i in 0...seq.size\n if i >= 4 && i % n == 0\n if seq[i-1] == seq[i-2] && seq[i-2] == seq[i-3]\n ret += 1\n end\n end\nend\nputs ret"}, {"source_code": "n = STDIN.readline.to_i\ns = STDIN.readline.strip\npos = n\ncount = 0\nwhile pos < s.length\n\tcount += 1 if s[pos-1] == s[pos-2] and s[pos-2] == s[pos-3]\n\tpos += n\nend\nputs count\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp\nl=s.size\nc=0\np\nfor i in (n..l-1).step(n) do\n c+=1 if s[i-1]==s[i-2] and s[i-1]==s[i-3]\nend\np c\n"}, {"source_code": "def run\n n = $stdin.gets.to_i\n a = $stdin.gets.chomp.split(//)\n\n cnt = 0\n cur = 0\n while cur < a.length\n cnt += 1 if cur >= 3 and a[cur - 1] == a[cur - 2] and a[cur - 1] == a[cur - 3]\n cur += n\n end\n\n puts cnt\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nans = 0\n(n...s.size).step(n).each{|i| ans += 1 if s[i-3]==s[i-2] and s[i-2]==s[i-1]}\nputs ans\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nr = 0\ni = n\nwhile i < s.length\n if (s[i-3,3] == 'aaa') or (s[i-3,3] == 'bbb')\n r += 1\n end\n i += n\nend\nputs \"#{r}\"\n"}], "negative_code": [{"source_code": "n = gets.to_i \ns = gets.chomp\nc=0;\nfor i in (n..s.length).step(n)\n\tif(s[i-1]==s[i-2] && s[i-3]==s[i-1])\n\t\tc+=1;\n\tend\nend\np c"}, {"source_code": "def run\n n = $stdin.gets.to_i\n a = $stdin.gets.split(//)\n\n cnt = 0\n cur = 0\n while cur < a.length\n cnt += 1 if cur >= 3 and a[cur - 1] == a[cur - 2] and a[cur - 1] == a[cur - 3]\n cur += n\n end\n\n puts cnt\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp\nl=s.size\nc=0\nfor i in (n..l-1).step(n) do\n c+=1 if s[i-1]==s[i-2] and s[i-1]==s[i-2]\nend\np c\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp\nl=s.size\nc=0\nfor i in (n..l).step(n) do\n c+=1 if s[i-1]==s[i-2] and s[i-1]==s[i-2]\nend\np c\n"}], "src_uid": "5606799ab5345bb9501fa6535e5abef9"} {"source_code": "times = gets.to_i\n\n(1..times).each do |i|\n array_size = gets.to_i\n\n a = Array.new(array_size)\n a = gets.split(/\\s+/).reverse.join(\" \")\n puts a\nend", "positive_code": [{"source_code": "gets.to_i.times{gets\nputs gets.split.reverse.join ' '}"}, {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n puts a.reverse.join(' ')\nend\n"}, {"source_code": "gets.to_i.times do\n n=gets.to_i\n a=gets.split(\" \").map(&:to_i)\n a.reverse!\n puts a.join(\" \")\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map &:to_i\n puts a.reverse.join(\" \")\nend"}], "negative_code": [], "src_uid": "1eaff8e0ec4614753699128af74b2471"} {"source_code": "n=gets.to_i;$><<[n,*1...n]*' '\n", "positive_code": [{"source_code": "n=gets.to_i\n$><<[n,*1..n-1]*' '\n"}, {"source_code": "n=gets.to_i;$><<[n,*1...n]*' '\n"}, {"source_code": "n=gets.to_i;$><<[n,*1...n]*' '\n"}, {"source_code": "n=gets.to_i;$><<[n,*1...n]*' '\n"}, {"source_code": "n=gets.to_i;$><<[n,*1...n]*' '\n"}, {"source_code": "n=gets.to_i;$><<[n,*1...n]*' '"}, {"source_code": "n=gets.to_i;$><<[n,*1...n]*' '"}, {"source_code": "n=gets.to_i;$><<[n,*1...n]*' '\n"}, {"source_code": "n=gets.to_i;$><<[n,*1...n]*' '\n"}, {"source_code": "n=gets.to_i;$><<[n,*1...n]*' '\n"}], "negative_code": [], "src_uid": "f35d7f9c12eea4364891e0449613f6b0"} {"source_code": "gets.to_i.times{n=gets.to_i;a=(gets.split.map &:to_i).sort;x=s=i=0;(x+=s-a[i]*i;s+=a[i];i+=1)while i 0, 3 => 0, 5 => 0}\n n, p[2] = n/2, p[2] + 1 while n%2 == 0\n n, p[3] = n/3, p[3] + 1 while n%3 == 0\n n, p[5] = n/5, p[5] + 1 while n%5 == 0 \n if n == 1\n puts (p[2] || 0) + (p[3] || 0)*2 + (p[5] || 0)*3\n else\n puts -1\n end\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n ans = 0\n while n != 1 do\n if n % 2 == 0\n n = n / 2\n ans += 1\n elsif n % 3 == 0\n n = 2 * n / 3\n ans += 1\n elsif n % 5 == 0\n n = 4 * n / 5\n ans += 1\n else\n ans = -1\n break\n end\n end\n puts ans\nend"}, {"source_code": "# coding: utf-8\n\nq = gets.to_i\nq.times {\n n = gets.to_i\n break_noops = false\n loop_counter = 0\n while n > 1\n if n%2 == 0\n n /= 2\n loop_counter += 1\n elsif n%3 == 0\n n /= 3\n n *= 2\n loop_counter += 1\n elsif n%5 == 0\n n /= 5\n n *= 4\n loop_counter += 1\n else\n break_noops = true\n break\n end\n end\n\n if n == 1\n puts loop_counter\n else\n puts -1\n end\n}"}, {"source_code": "q = gets.to_i\nq.times do \n n = gets.to_i\n cnt = 0\n while n != 1\n if n % 2 == 0\n n /= 2\n elsif n % 3 == 0\n n = 2*n/3\n elsif n % 5 == 0\n n = 4*n/5\n else\n break\n end\n cnt += 1\n end\n p n == 1 ? cnt : -1\nend"}, {"source_code": "def valid?(n)\n n % 3 == 0 || n % 5 == 0 || n % 2 == 0\nend\n\ndef solve(n)\n steps = 0\n while valid?(n)\n n = if n % 2 == 0\n n / 2\n elsif n % 3 == 0\n (2 * n) / 3\n else\n (4 * n) / 5\n end\n steps += 1\n end\n n == 1 ? steps : -1\nend\n\ngets.strip.to_i.times do\n n = gets.strip.to_i\n puts solve(n)\nend"}, {"source_code": "queries = gets.chomp.to_i\nwhile(queries > 0)\n num = gets.chomp.to_i\n count = 0\n while(num%2 == 0 || num%3 == 0 || num%5 == 0)\n if num%2 == 0\n num /= 2;\n elsif num%3 == 0\n num = (num/3)*2;\n else\n num = (num/5)*4\n end\n count += 1\n end\n queries -= 1\n puts -1 if num != 1\n puts count if num == 1\nend\n"}], "negative_code": [], "src_uid": "ed5ea0e664aa986ab86e4e6746e8a1bf"} {"source_code": "n = gets.chomp.to_i\n(1..n).each do\n a,b,c = gets.chomp.split(\" \").map(&:to_i)\n if a < c && b >= 2\n x = 1\n end\n if a >= c && b >= 1\n x = -1\n end\n if a < c && b == 1\n x = 1\n end\n # kari = a * b\n # if kari <= c\n # y = -1\n # end\n amari = c % a\n kotae = c / a\n # if kari > c && amari == 0 \n # y = kotae\n # elsif kari > c && amari != 0\n # y = kotae + 1 \n # end\n if a >= c \n y = b\n elsif a < c && amari == 0 && b > kotae\n y = kotae + 1\n elsif a < c && amari == 0 && b == kotae\n y = -1\n elsif a < c && amari != 0 && b > kotae\n y = kotae + 1\n elsif a < c && amari != 0 && b == kotae\n y = -1\n elsif a < c && amari == 0 && b < kotae\n y = -1\n elsif a < c && amari != 0 && b < kotae\n y = -1\n end\n\n print x\n print \" \"\n print y\n print \"\\n\"\nend", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n a, b, c = gets.split.map &:to_i\n \n if c <= a or b == 1\n x = -1\n else\n x = 1\n end\n \n if a*b <= c\n y = -1\n else\n y = b\n end\n \n puts \"#{x} #{y}\"\nend"}, {"source_code": "def run\n a, b, c = gets.chomp.split(\" \").map(&:to_i)\n\n s = if a < c\n \"1 \"\n else\n \"-1 \"\n end\n\n if a * b > c\n s << \"#{b}\"\n else\n s << \"-1\"\n end\n puts s\nend\n\n\ndef main\n t = gets.chomp.to_i\n\n t.times do\n run\n end\nend\n\nmain\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\n(1..n).each do |i|\n a,b,c = gets.chomp.split(\" \").map(&:to_i)\n if a < c && b >= 2\n x = 1\n end\n if a >= c && b >= 1\n x = -1\n end\n if a < c && b == 1\n x = 1\n end\n kari = a * b\n if kari <= c\n y = -1\n end\n if kari > c\n y = a\n end\n print x\n print \" \"\n print y\n print \"\\n\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\n(1..n).each do\n a,b,c = gets.chomp.split(\" \").map(&:to_i)\n if a < c && b >= 2\n x = 1\n end\n if a >= c && b >= 1\n x = -1\n end\n if a < c && b == 1\n x = 1\n end\n kari = a * b\n if kari <= c\n y = -1\n end\n if kari > c\n y = a\n end\n print x\n print \" \"\n print y\n print \"\\n\"\nend"}, {"source_code": "n = gets.chomp.to_i\n(1..n).each do\n a,b,c = gets.chomp.split(\" \").map(&:to_i)\n if a < c && b >= 2\n x = 1\n end\n if a >= c && b >= 1\n x = -1\n end\n if a < c && b == 1\n x = 1\n end\n kari = a * b\n if kari <= c\n y = -1\n end\n amari = c % a\n kotae = c / a\n if kari > c && amari == 0 \n y = kotae\n elsif kari > c && amari != 0\n y = kotae + 1 \n end\n print x\n print \" \"\n print y\n print \"\\n\"\nend"}], "src_uid": "002801f26568a1b3524d8754207d32c1"} {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nN = gi\nS = gs\n\nf = Hash.new 0\n\nc = S.each_char.to_a.uniq.size\n\na = N\nj = 0\nk = 0\nN.times do |i|\n ch = S[i]\n if f[ch] == 0\n k += 1\n end\n f[ch] += 1\n while f[S[j]] > 1 do\n f[S[j]] -= 1\n j += 1\n end\n a = [a, i - j].min if k == c\nend\n\np a + 1\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\nrequire 'set'\n\nn = gets.chomp.to_i\nc = gets.chomp\n\nh = Hash.new(0)\ns = Set.new\n\nfor i in 0...n do\n s << c[i]\nend\nnd = s.size\niterr = 0\ngot = 0\nans = n\nfor iterl in 0...n do\n while iterr < n && got < nd do\n if h[ c[iterr] ] == 0\n got += 1\n end\n h[ c[iterr] ] += 1\n iterr += 1\n end\n if got < nd\n break\n end\n if iterr - iterl < ans\n ans = iterr - iterl\n end\n h[ c[iterl] ] -= 1\n if h[ c[iterl] ] == 0\n got -= 1\n end\nend\nputs ans\n"}, {"source_code": "gets\nhouse = gets.chomp\n\nselected = Hash.new\nhouse.each_char { |flat| selected[flat] = 0 }\n\nif selected.length < 2\n puts selected.length\n exit\nend\n\nresult = house.length\nleft, right = 0, 0\n\nselected[house[0]] = 1\ncurrent = 1\n\nwhile true do\n if current == selected.length\n result = 1+right-left if 1+right-left < result\n\n selected[house[left]] -= 1\n current -= 1 if selected[house[left]] == 0\n left += 1\n else\n right += 1\n break if right == house.length\n current += 1 if selected[house[right]] == 0\n selected[house[right]] += 1\n end\nend\n\nputs result\n"}], "negative_code": [], "src_uid": "60776cefd6c1a2f3c16b3378ebc31a9a"} {"source_code": "h,n = gets.split.map(&:to_i)\nd = gets.split.map(&:to_i)\nsum = d.inject(:+)\na = 0\nmn = 0\nn.times do |i|\n a += d[i]\n mn = a if mn > a\nend\nif sum >= 0 && h+mn > 0\n puts -1\n exit\nend\nans = 0\nif h+mn > 0\n ans += (h+mn-sum-1)/(-sum)*n\n h += ans/n*sum\nend\nn.times do |i|\n h += d[i]\n ans += 1\n if h <= 0\n puts ans\n exit\n end\nend", "positive_code": [{"source_code": "H,N = gets.split.map &:to_i\nD = gets.split.map &:to_i\nss = [0]\n(1..N).each{ |i|\n d = D[i-1]\n ss << (ss[-1] + d)\n if ss[-1] + H <= 0\n p i; exit\n end\n}\n\nif ss[-1] >= 0\n p -1; exit\nend\n\ntd = ss[-1]\nt = nil\nk = (0..H/(-td)).bsearch{ |n|\n h0 = H + n*td\n h = h0\n j = 0\n ss.each{ |s|\n h = h0 + s\n break if h <= 0\n j += 1\n }\n t = j if h <= 0\n h <= 0\n}\np N*k + t\n"}], "negative_code": [], "src_uid": "d173fa24cebaeda9ca794eeed68fa12d"} {"source_code": "# http://codeforces.com/contest/569/problem/B\nn = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\narray = Array.new(n + 1) { 0 }\na.each { |e| array[e] += 1 if e <= n }\n\nstack = [].tap do |out|\n (1..n).each { |idx| out << idx if array[idx] == 0 }\nend\n\nans = a.map do |e|\n case\n when e > n\n stack.pop\n when array[e] > 1\n array[e] -= 1\n stack.pop\n else\n e\n end\nend\n\nputs ans.join(' ')\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split.map{|x| x.to_i}\n\nref = Array.new(n+1){0}\n\narr.each do |v|\n\tif v<=n\n\t\tref[v]+=1\n\tend\nend\nstack = []\n(1..n).each do |i|\n\tif ref[i] == 0\n\tstack.push(i)\n\tend\nend\n\narr.each do |v|\n\tif v>n\n\t\tprint \"#{stack.pop} \"\n\telsif ref[v] > 1\n\t\tprint \"#{stack.pop} \"\n\t\tref[v]-=1\n\telse\n\t\t\tprint \"#{v} \"\n\tend\nend\n"}, {"source_code": "require 'set'\nn = STDIN.gets.chomp\ninput = STDIN.gets.chomp\n\ndef remap(n, input)\n order = Set.new\n n.to_i.times {|n| order << n+1}\n\n\n input = input.split.map(&:to_i)\n output = []\n\n reworked_input = []\n positions = []\n\n input.length.times do |position|\n key = input[position]\n unless order.include? key\n positions << position\n else\n order.delete key\n end\n end\n\n counter = 0\n\n order.each do |element|\n input[positions[counter]] = element\n counter += 1\n end\n\n return input.join(\" \")\nend\n\nputs remap(n, input)\n"}, {"source_code": "#!/usr/bin/ruby\nN=gets.to_i\nA=[]\nh={}\ngets.split.each_with_index{|e,i|\n\tn=e.to_i-1\n\tif !A[n]&&n nums.size\n\t\tres[i] = free[f]\n\t\tf += 1\n\telse\n\t\tres[i] = n\n\t\tused[n] = true\n\tend\nend\n\nputs res.join(' ')"}, {"source_code": "n = gets.chomp.to_i\nas = gets.chomp.split(' ').map(&:to_i)\n\nbs = Array.new(n+1, false)\ncs = Array.new(n+1, false)\n\nfor i in 0..n-1\n a = as[i]\n if 1 <= a && a <= n && !bs[a] \n bs[a] = true\n cs[i] = true\n end\nend\n\nj = 1\nfor i in 0..n-1\n a = as[i]\n while bs[j]\n j += 1\n end\n if cs[i]\n print as[i]\n else\n print j \n j += 1\n end\n print ' '\nend\nprint \"\\n\"\n"}, {"source_code": "#!/usr/bin/ruby\n\n\nn = ARGF.gets.to_i \na = ARGF.gets.split(' ').map { |s| s.to_i }\n\nb = Array.new(n + 1, 0)\nb[0] = 1\n\na.each do |e|\n if e <= n then b[e] += 1 end\nend\n\nc = Array.new\nb.each_with_index do |e, i|\n if b[i] == 0 then c << i end\nend\n\na.each_with_index do |e, i|\n if a[i] > n\n a[i] = c.shift\n elsif b[a[i]] > 1\n b[a[i]] -= 1\n a[i] = c.shift\n end\nend\n\nprint a.shift\na.each do |e| print(\" #{e}\") end\nprint \"\\n\"\n"}], "negative_code": [{"source_code": "#n = STDIN.gets.chomp\n#input = STDIN.gets.chomp\n\ndef remap(n, input)\n order = []\n n.to_i.times {|n| order << n+1}\n\n input = input.split.map(&:to_i)\n output = []\n\n reworked_input = []\n\n input.each do |key|\n unless order.include? key\n reworked_input << [key, false]\n else\n index = order.index key\n order[index] = nil\n reworked_input << [key, true]\n end\n end\n\n order = order.compact\n counter = 0\n\n reworked_input.each do |element|\n key, value = element\n if value == false\n output << order[counter]\n counter += 1\n else\n output << key\n end\n end\n\n\n return output.join(\" \")\nend\n\n#puts remap(n, input)\n"}, {"source_code": "#!/usr/bin/ruby\nN=gets.to_i\nA=[]\nh={}\ngets.split.each_with_index{|e,i|\n\tn=e.to_i-1\n\tif !A[n]&&n= nums.size\n\t\tres[i] = free[f]\n\t\tf += 1\n\telse\n\t\tres[i] = n\n\t\tused[n] = true\n\tend\nend\n\nputs res.join(' ')"}, {"source_code": "#!/usr/bin/ruby\n\n\nn = ARGF.gets.to_i \na = ARGF.gets.split(' ').map { |s| s.to_i }\n\nb = Array.new(n + 1, 0)\nb[0] = 1\n\na.each do |e|\n if e < n then b[e] += 1 end\nend\n\nc = Array.new\nb.each_with_index do |e, i|\n if b[i] == 0 then c << i end\nend\n\na.each_with_index do |e, i|\n if a[i] > n\n a[i] = c.shift\n elsif b[a[i]] > 1\n b[a[i]] -= 1\n a[i] = c.shift\n end\nend\n\nprint a.shift\na.each do |e| print(\" #{e}\") end\nprint \"\\n\"\n"}], "src_uid": "1cfd0e6504bba7db9ec79e2f243b99b4"} {"source_code": "def r\n gets.split.map(&:to_i)\nend\ndef rook(p)\n \"RQ\".match(p[1])\nend\ndef bish(p)\n \"BQ\".match(p[1])\nend\ngets\nkx, ky = r\n\nrl = cl = d1l = d2l = [-1e10, \"dummy\"]\nrh = ch = d1h = d2h = [+1e10, \"dummy\"]\n\n$<.each_line do |l|\n op, x, y = l.split\n x = x.to_i\n y = y.to_i\n\n if 1\n rl = [rl, [y, op]].max if x == kx && y < ky\n end\n if 1\n rh = [rh, [y, op]].min if x == kx && y > ky\n end\n if 1\n cl = [cl, [x, op]].max if y == ky && x < kx\n end\n if 1\n ch = [ch, [x, op]].min if y == ky && x > kx\n end\n\n d1l = [d1l, [x, op]].max if x+y == kx+ky && x < kx\n d1h = [d1h, [x, op]].min if x+y == kx+ky && x > kx\n d2l = [d2l, [x, op]].max if x-y == kx-ky && x < kx\n d2h = [d2h, [x, op]].min if x-y == kx-ky && x > kx\nend\nputs [rl, rh, cl, ch].any?{|x| rook(x)} || [d1l, d1h, d2l, d2h].any?{|x| bish(x)} ? \"YES\" : \"NO\"\n", "positive_code": [{"source_code": "def r \n gets.split.map(&:to_i) \nend\ndef rook(p)\n \"RQ\".match(p[1])\nend\ndef bish(p)\n \"BQ\".match(p[1])\nend\ngets\nkx, ky = r\n\nrl = cl = d1l = d2l = [-1e10, \"dummy\"]\nrh = ch = d1h = d2h = [+1e10, \"dummy\"]\n\n$<.each_line do |l|\n op, x, y = l.split\n x = x.to_i\n y = y.to_i\n \n rl = [rl, [y, op]].max if x == kx && y < ky\n rh = [rh, [y, op]].min if x == kx && y > ky\n cl = [cl, [x, op]].max if y == ky && x < kx\n ch = [ch, [x, op]].min if y == ky && x > kx\n \n d1l = [d1l, [x, op]].max if x+y == kx+ky && x < kx\n d1h = [d1h, [x, op]].min if x+y == kx+ky && x > kx\n d2l = [d2l, [x, op]].max if x-y == kx-ky && x < kx\n d2h = [d2h, [x, op]].min if x-y == kx-ky && x > kx\nend\nputs [rl, rh, cl, ch].any?{|x| rook(x)} || [d1l, d1h, d2l, d2h].any?{|x| bish(x)} ? \"YES\" : \"NO\"\n"}, {"source_code": "vert = []\nhori = []\npsdiag = []\nnsdiag = []\n\nn = gets.to_i\nkx, ky = gets.strip.split.map(&:to_i)\n\npieces = []\nn.times do |i|\n p, x, y = gets.strip.split\n x = x.to_i\n y = y.to_i\n pieces << [p, x, y]\n vert << i if x == kx\n hori << i if y == ky\n psdiag << i if (y-x) == (ky-kx)\n nsdiag << i if (y+x) == (ky+kx)\nend\n\nunder_attack = false\n\nnear_top = [10**10, nil]\nnear_bot = [-1 * (10**10), nil]\nvert.each do |pi|\n p = pieces[pi]\n if p[2] > ky && p[2] < near_top[0]\n near_top[0] = p[2]\n near_top[1] = pi\n end\n if p[2] < ky && p[2] > near_bot[0]\n near_bot[0] = p[2]\n near_bot[1] = pi\n end\nend\nunder_attack ||= pieces[near_top[1]][0] == \"R\" || pieces[near_top[1]][0] == \"Q\" if near_top[1]\nunder_attack ||= pieces[near_bot[1]][0] == \"R\" || pieces[near_bot[1]][0] == \"Q\" if near_bot[1]\n\nif under_attack == false\n near_rgt = [10**10, nil]\n near_lft = [-1 * (10**10), nil]\n hori.each do |pi|\n p = pieces[pi]\n if p[1] > kx && p[1] < near_rgt[0]\n near_rgt[0] = p[1]\n near_rgt[1] = pi\n end\n if p[1] < kx && p[1] > near_lft[0]\n near_lft[0] = p[1]\n near_lft[1] = pi\n end\n end\n under_attack ||= pieces[near_rgt[1]][0] == \"R\" || pieces[near_rgt[1]][0] == \"Q\" if near_rgt[1]\n under_attack ||= pieces[near_lft[1]][0] == \"R\" || pieces[near_lft[1]][0] == \"Q\" if near_lft[1]\nend\n\nif under_attack == false\n near_tr = [10**10, nil]\n near_bl = [-1 * (10**10), nil]\n psdiag.each do |pi|\n p = pieces[pi]\n if p[2] > ky && p[2] < near_tr[0]\n near_tr[0] = p[2]\n near_tr[1] = pi\n end\n if p[2] < ky && p[2] > near_bl[0]\n near_bl[0] = p[2]\n near_bl[1] = pi\n end\n end\n under_attack ||= pieces[near_tr[1]][0] == \"B\" || pieces[near_tr[1]][0] == \"Q\" if near_tr[1]\n under_attack ||= pieces[near_bl[1]][0] == \"B\" || pieces[near_bl[1]][0] == \"Q\" if near_bl[1]\nend\n\nif under_attack == false\n near_br = [10**10, nil]\n near_bl = [-1 * (10**10), nil]\n nsdiag.each do |pi|\n p = pieces[pi]\n if p[1] > kx && p[1] < near_br[0]\n near_br[0] = p[1]\n near_br[1] = pi\n end\n if p[1] < kx && p[1] > near_bl[0]\n near_bl[0] = p[1]\n near_bl[1] = pi\n end\n end\n under_attack ||= pieces[near_br[1]][0] == \"B\" || pieces[near_br[1]][0] == \"Q\" if near_br[1]\n under_attack ||= pieces[near_bl[1]][0] == \"B\" || pieces[near_bl[1]][0] == \"Q\" if near_bl[1]\nend\n\nputs (under_attack ? \"YES\" : \"NO\")"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.strip end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nn = gi\nx, y = gis\n\nps = [nil] * 8\n\nn.times do\n c, xi_s, yi_s = gss\n xi, yi = xi_s.to_i, yi_s.to_i\n dx = xi - x\n dy = yi - y \n d = dx.abs + dy.abs\n if x == xi\n if y < yi && (ps[6].nil? || d < ps[6][1])\n ps[6] = [c, d]\n elsif y > yi && (ps[1].nil? || d < ps[1][1])\n ps[1] = [c, d]\n end\n elsif y == yi\n if x < xi && (ps[4].nil? || d < ps[4][1])\n ps[4] = [c, d]\n elsif x > xi && (ps[3].nil? || d < ps[3][1])\n ps[3] = [c, d]\n end\n elsif dx.abs == dy.abs\n if dy < 0 && dx < 0 && (ps[0].nil? || d < ps[0][1])\n ps[0] = [c, d]\n elsif dy < 0 && dx > 0 && (ps[2].nil? || d < ps[2][1])\n ps[2] = [c, d]\n elsif dy > 0 && dx < 0 && (ps[5].nil? || d < ps[5][1])\n ps[5] = [c, d]\n elsif dy > 0 && dx > 0 && (ps[7].nil? || d < ps[7][1])\n ps[7] = [c, d]\n end\n end\nend\n\ncase\nwhen !ps[1].nil? && ps[1][0] != 'B'\n puts :YES\nwhen !ps[3].nil? && ps[3][0] != 'B'\n puts :YES\nwhen !ps[4].nil? && ps[4][0] != 'B'\n puts :YES\nwhen !ps[6].nil? && ps[6][0] != 'B'\n puts :YES\nwhen !ps[0].nil? && ps[0][0] != 'R'\n puts :YES\nwhen !ps[2].nil? && ps[2][0] != 'R'\n puts :YES\nwhen !ps[5].nil? && ps[5][0] != 'R'\n puts :YES\nwhen !ps[7].nil? && ps[7][0] != 'R'\n puts :YES\nelse\n puts :NO\nend\n\n"}, {"source_code": "def r \n gets.split.map(&:to_i) \nend\ndef rook(p)\n \"RQ\".match(p[1])\nend\ndef bish(p)\n \"BQ\".match(p[1])\nend\ngets\nkx, ky = r\n\nrl = cl = d1l = d2l = [-1e10, \"dummy\"]\nrh = ch = d1h = d2h = [+1e10, \"dummy\"]\n\n$<.each_line do |l|\n op, x, y = l.split\n x = x.to_i\n y = y.to_i\n \n rl = [rl, [y, op]].max if x == kx && y < ky\n rh = [rh, [y, op]].min if x == kx && y > ky\n cl = [cl, [x, op]].max if y == ky && x < kx\n ch = [ch, [x, op]].min if y == ky && x > kx\n \n d1l = [d1l, [x, op]].max if x+y == kx+ky && x < kx\n d1h = [d1h, [x, op]].min if x+y == kx+ky && x > kx\n d2l = [d2l, [x, op]].max if x-y == kx-ky && x < kx\n d2h = [d2h, [x, op]].min if x-y == kx-ky && x > kx\nend\nputs [rl, rh, cl, ch].any?{|x| rook(x)} || [d1l, d1h, d2l, d2h].any?{|x| bish(x)} ? \"YES\" : \"NO\""}, {"source_code": "def r \n gets.split.map(&:to_i) \nend\ndef rook(p)\n \"RQ\".match(p[1])\nend\ndef bish(p)\n \"BQ\".match(p[1])\nend\ngets\nkx, ky = r\n\nrl = cl = d1l = d2l = [-1e10, \"dummy\"]\nrh = ch = d1h = d2h = [+1e10, \"dummy\"]\n\n$<.each_line do |l|\n op, x, y = l.split\n x = x.to_i\n y = y.to_i\n \n if x == kx\n rl = [rl, [y, op]].max if y < ky\n rh = [rh, [y, op]].min if y > ky\n end\n if y == ky\n cl = [cl, [x, op]].max if x < kx\n ch = [ch, [x, op]].min if x > kx\n end\n if x+y == kx+ky\n d1l = [d1l, [x, op]].max if x < kx\n d1h = [d1h, [x, op]].min if x > kx\n end\n if x-y == kx-ky\n d2l = [d2l, [x, op]].max if x < kx\n d2h = [d2h, [x, op]].min if x > kx\n end\nend\nputs [rl, rh, cl, ch].any?{|x| rook(x)} || [d1l, d1h, d2l, d2h].any?{|x| bish(x)} ? \"YES\" : \"NO\""}, {"source_code": "def r \n gets.split.map(&:to_i) \nend\ndef rook(p)\n \"RQ\".match(p[1])\nend\ndef bish(p)\n \"BQ\".match(p[1])\nend\ngets\nkx, ky = r\n\nrl = cl = d1l = d2l = [-1e10, \"dummy\"]\nrh = ch = d1h = d2h = [+1e10, \"dummy\"]\n\n$<.each_line do |l|\n op, x, y = l.split\n x = x.to_i\n y = y.to_i\n \n if x == kx\n rl = [rl, [y, op]].max if y < ky\n rh = [rh, [y, op]].min if y > ky\n end\n if y == ky\n cl = [cl, [x, op]].max if x < kx\n ch = [ch, [x, op]].min if x > kx\n end\n if x+y == kx+ky\n d1l = [d1l, [x, op]].max if x < kx\n d1h = [d1h, [x, op]].min if x > kx\n end\n if x-y == kx-ky\n d2l = [d2l, [x, op]].max if x < kx\n d2h = [d2h, [x, op]].min if x > kx\n end\nend\nputs [rl, rh, cl, ch].any?{|x| rook(x)} || [d1l, d1h, d2l, d2h].any?{|x| bish(x)} ? \"YES\" : \"NO\"\n"}, {"source_code": "def r \n gets.split.map(&:to_i) \nend\ndef rook(p)\n \"RQ\".match(p[1])\nend\ndef bish(p)\n \"BQ\".match(p[1])\nend\ngets\nkx, ky = r\n\nrl = cl = d1l = d2l = [-1e10, \"dummy\"]\nrh = ch = d1h = d2h = [+1e10, \"dummy\"]\n\n$<.each_line do |l|\n op, x, y = l.split\n x = x.to_i\n y = y.to_i\n \n rl = [rl, [y, op]].max if x == kx && y < ky\n rh = [rh, [y, op]].min if x == kx && y > ky\n cl = [cl, [x, op]].max if y == ky && x < kx\n ch = [ch, [x, op]].min if y == ky && x > kx\n \n d1l = [d1l, [x, op]].max if x+y == kx+ky && x < kx\n d1h = [d1h, [x, op]].min if x+y == kx+ky && x > kx\n d2l = [d2l, [x, op]].max if x-y == kx-ky && x < kx\n d2h = [d2h, [x, op]].min if x-y == kx-ky && x > kx\nend\nputs [rl, rh, cl, ch].any?{|x| rook(x)} || [d1l, d1h, d2l, d2h].any?{|x| bish(x)} ? \"YES\" : \"NO\""}, {"source_code": "def r \n gets.split.map(&:to_i) \nend\ndef rook(p)\n \"RQ\".match(p[1])\nend\ndef bish(p)\n \"BQ\".match(p[1])\nend\ngets\nkx, ky = r\n\nrl = cl = d1l = d2l = [-1e10, \"dummy\"]\nrh = ch = d1h = d2h = [+1e10, \"dummy\"]\n\n$<.each_line do |l|\n op, x, y = l.split\n x = x.to_i\n y = y.to_i\n \n rl = [rl, [y, op]].max if x == kx && y < ky\n rh = [rh, [y, op]].min if x == kx && y > ky\n cl = [cl, [x, op]].max if y == ky && x < kx\n ch = [ch, [x, op]].min if y == ky && x > kx\n \n d1l = [d1l, [x, op]].max if x+y == kx+ky && x < kx\n d1h = [d1h, [x, op]].min if x+y == kx+ky && x > kx\n d2l = [d2l, [x, op]].max if x-y == kx-ky && x < kx\n d2h = [d2h, [x, op]].min if x-y == kx-ky && x > kx\nend\nputs [rl, rh, cl, ch].any?{|x| rook(x)} || [d1l, d1h, d2l, d2h].any?{|x| bish(x)} ? \"YES\" : \"NO\"\n"}, {"source_code": "def r \n gets.split.map(&:to_i) \nend\ndef rook(o)\n \"RQ\".match(o)\nend\ndef bish(o)\n \"BQ\".match(o)\nend\ngets\nkx, ky = r\n\nrl = cl = d1l = d2l = [-1e10, \"dummy\"]\nrh = ch = d1h = d2h = [+1e10, \"dummy\"]\n\n$<.each_line do |l|\n op, x, y = l.split\n x = x.to_i\n y = y.to_i\n \n if x == kx\n rl = [rl, [y, op]].max if y < ky\n rh = [rh, [y, op]].min if y > ky\n end\n if y == ky\n cl = [cl, [x, op]].max if x < kx\n ch = [ch, [x, op]].min if x > kx\n end\n if x+y == kx+ky\n d1l = [d1l, [x, op]].max if x < kx\n d1h = [d1h, [x, op]].min if x > kx\n end\n if x-y == kx-ky\n d2l = [d2l, [x, op]].max if x < kx\n d2h = [d2h, [x, op]].min if x > kx\n end\nend\nputs [rl, rh, cl, ch].any?{|x,o| rook(o)} || [d1l, d1h, d2l, d2h].any?{|x,o| bish(o)} ? \"YES\" : \"NO\"\n"}], "negative_code": [], "src_uid": "b389750613e9577b3abc9e5e5902b2db"} {"source_code": "h={}\nn=gets.to_i\nb=[*$<.read.split].reverse\nn.times{\n a, c=b.pop(2)\n if c==??\n puts h[a.to_i(2)]||0\n else\n t=a.bytes.map{|e| e%2==0? ?0 : ?1}*''\n x=t.to_i(2)\n h[x]||=0\n c==?+ ? h[x]+=1 : h[x]-=1\n end\n}\n", "positive_code": [{"source_code": "h={}\nn=gets.to_i\nn.times{\n c, a=gets.split\n if c==??\n puts h[a.to_i(2)]||0\n else\n t=a.bytes.map{|e| e%2==0? ?0 : ?1}*''\n x=t.to_i(2)\n h[x]||=0\n c==?+ ? h[x]+=1 : h[x]-=1\n end\n}\n"}, {"source_code": "h={}\nn,*b=$<.read.split\nn.to_i.times{|i|\n c, a=b[2*i, 2]\n if c==??\n puts h[a.to_i(2)]||0\n else\n t=a.bytes.map{|e| e%2==0? ?0 : ?1}*''\n x=t.to_i(2)\n h[x]||=0\n c==?+ ? h[x]+=1 : h[x]-=1\n end\n}\n"}, {"source_code": "n = gets.to_i\ncnt = Array.new(2 ** 18, 0)\nn.times do\n c, s = gets.split\n a = s.tr('0-9', '0101010101').to_i(2)\n case c\n when '+'\n cnt[a] += 1\n when '-'\n cnt[a] -= 1\n when '?'\n puts cnt[a]\n end\nend\n"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\nn.times do |i|\n x, num = gets.split(\" \")\n a = num.tr('0-9', '0101010101').to_i\n if x.ord == 43\n h[a] += 1\n elsif x.ord == 45\n h[a] -= 1\n elsif x.ord == 63\n puts h[a]\n end\nend\n"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\nn.times.map do |i|\n x, s = gets.split\n s = s.tr('13579', '1').tr('24680', '0')\n case x\n when '+'\n h[s.rjust(18, '0')] += 1\n when '-'\n h[s.rjust(18, '0')] -= 1\n when '?'\n puts h[s.rjust(18, '0')]\n end\nend\n"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\nn.times.map do |i|\n x, s = gets.split\n a = s.tr('0-9', '0101010101').to_i\n case x\n when '+'\n h[a] += 1\n when '-'\n h[a] -= 1\n when '?'\n puts h[a]\n end\nend\n"}, {"source_code": "n = readline.to_i\nh = {}\nh.default = 0\n(1..n).each do\n q_type, q_key = readline.split.map(&:strip)\n\n t=0\n (0...q_key.size).each do |i|\n t *= 2\n t += q_key[i].ord % 2\n end\n\n if q_type == '+'\n h[t] += 1\n elsif q_type == '-'\n h[t] -= 1\n else\n puts h[t]\n end\nend\n"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\nn.times do |i|\n x, num = gets.split(\" \")\n a = num.tr('0-9', '0101010101').to_i\n if x.ord == 43\n h[a] += 1\n elsif x.ord == 45\n h[a] -= 1\n elsif x.ord == 63\n puts h[a]\n end\nend\n"}], "negative_code": [{"source_code": "h={}\nn=gets.to_i\nn.times{\n c, a=gets.split\n if c==??\n p h[a.to_i(2)]\n else\n t=a.bytes.map{|e| e%2==0? ?0 : ?1}*''\n x=t.to_i(2)\n h[x]||=0\n c==?+ ? h[x]+=1 : h[x]-=1\n end\n}\n"}, {"source_code": "h={}\ngets.to_i.times{\n c, a=gets.split\n if c==??\n p h[a.to_i(2)]\n else\n t=a.bytes.map{|e| e%2==0? ?0 : ?1}*''\n x=t.to_i(2)\n h[x]||=0\n c==?+ ? h[x]+=1 : h[x]-=1\n end\n}\n"}, {"source_code": "h={}\nn=gets.to_i\nb=[*$<.read.split].reverse\nn.times{\n a, c=b.pop(2)\n if c==??\n puts h[a]||0\n else\n x=a.bytes.map{|e| e%2==0? ?0 : ?1}*''\n h[x]||=0\n c==?+ ? h[x]+=1 : h[x]-=1\n end\n}\n"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\nn.times.map do |i|\n x, s = gets.split\n s = s.tr('13579', '1').tr('24680', '1')\n case x\n when '+'\n h[s.rjust(18, '0')] += 1\n when '-'\n h[s.rjust(18, '0')] -= 1\n when '?'\n puts h[s.rjust(18, '0')]\n end\nend\n"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\nn.times do |x|\n c, n = gets.split\n case c\n when '+'\n h[n] += 1\n when '-'\n h[n] -= 1\n when '?'\n a = n.chars.map do |x|\n if x == '1'\n \"[1|3|5|7]\"\n elsif x == '0'\n \"[2|4|6|8|0]\"\n end\n end.join\n a << '$'\n puts h.keys.select{|x| x.rjust(5, '0').match(Regexp.new(a))}.inject(0){|s, x| s + h[x]}\n end\nend\n"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\nn.times do |x|\n c, n = gets.split\n case c\n when '+'\n h[n] += 1\n when '-'\n h[n] -= 1\n when '?'\n a = n.chars.map{|x| x == '1' ? '[1|3|5|7|9]' : '[2|4|6|8|0]'}.join\n a << '$'\n puts h.keys.select{|x| x.rjust(18, '0').match(Regexp.new(a))}.inject(0){|s, x| s + h[x]}\n end\nend\n"}], "src_uid": "0ca6c7ff6a2d110a8f4153717910378f"} {"source_code": "gets.strip.to_i.times {\n n, s = gets.strip.split(' ').map(&:to_i)\n a = gets.strip.split(' ').map(&:to_i)\n mx = -1\n sum = 0\n done = false\n $part\n a.each_with_index { |e, i| \n if mx <= e\n mx = e\n $part = i + 1\n end\n sum += e\n if sum > s\n puts $part\n done = true\n break\n end\n }\n puts 0 if !done\n}", "positive_code": [{"source_code": "def solve(n, s, vals)\n sum = 0\n max_so_far = vals[0]\n vals.each_with_index do |e, i|\n max_so_far = [max_so_far, e].max\n sum += e\n if sum > s\n return vals.index { |x| x == max_so_far } + 1\n end\n end\n 0\nend\n\n# gets.strip.split(' ').map(&:to_i)\ngets.strip.to_i.times do\n n, s = gets.strip.split(' ').map(&:to_i)\n vals = gets.strip.split(' ').map(&:to_i)\n puts solve(n, s, vals)\nend"}], "negative_code": [], "src_uid": "0924971933265f4be34710149a541087"} {"source_code": "gets.to_i.times {\r\n n, k = gets.split(' ').map(&:to_i)\r\n if n % 4 == 0\r\n a = n / 2\r\n b = a / 2\r\n puts [a, b, b].join(' ')\r\n else\r\n a = (n - 1) / 2\r\n rem = n - 2 * a\r\n while a > 0\r\n if a % rem == 0\r\n puts [a, a, rem].join(' ')\r\n break\r\n end\r\n a -= 1\r\n rem += 2\r\n end\r\n end\r\n}", "positive_code": [{"source_code": "def fn(n,k)\n m = n / 2\n if n % 2 == 1\n x = (n - 1)/2\n ret = [x,x, 1]\n else\n if m % 2 == 0\n ret = [m,m/2,m/2]\n else\n ret = [2, m-1, m-1]\n end\n end\n\n puts ret.join(' ')\nend\n\ntt = gets.to_i\ntt.times {\n (n, k)= gets.chomp!.split(' ').map &:to_i\n fn(n,k)\n}\n\n \t \t\t \t\t \t\t \t \t \t \t \t\t\t"}, {"source_code": "t = gets.chomp.to_i\r\nfor _ in (1..t)\r\n n, k = gets.chomp.split(' ').map { |x| x.to_i }\r\n if n % 3 == 0\r\n print \"#{n/3} #{n/3} #{n/3}\"\r\n elsif n % 2 == 1\r\n print \"#{1} #{(n-1)/2} #{(n-1)/2}\"\r\n elsif n % 4 == 0\r\n print \"#{n / 4} #{n / 4} #{n / 2}\"\r\n else\r\n print \"#{2} #{(n - 2) / 2} #{(n - 2) / 2}\"\r\n end\r\n puts\r\nend"}, {"source_code": "def solve(n, k)\r\n a = n / 4\r\n case n % 4\r\n when 0\r\n [a*2, a, a]\r\n when 1\r\n [a*2, a*2, 1]\r\n when 2\r\n [a*2, a*2, 2]\r\n when 3\r\n [a*2+1, a*2+1, 1]\r\n end\r\nend\r\n\r\ndef main\r\n t = int\r\n t.times do\r\n n, k = ints\r\n a, b, c = solve(n, k)\r\n raise \"not satisfied: #{a} + #{b} + #{c} == #{n}\" unless a + b + c == n\r\n raise \"not satisfied: LCM(#{a}, #{b}, #{c}) <= #{n}/2\" unless 2 * a.lcm(b).lcm(c) <= n\r\n puts \"#{a} #{b} #{c}\"\r\n end\r\nend\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\nYESNO = %w(No Yes)\r\nINF = 10**9\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts YESNO[1] end\r\ndef no; puts YESNO[0] end\r\ndef yesno t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\ndef coerce(other); [other, to_i] end\r\ndef +@; to_i end\r\ndef to_int; to_i end\r\ndef *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\ninclude Boolean\r\ndef to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\ninclude Boolean\r\ndef to_i; 0 end\r\nend\r\n\r\nclass Integer\r\ndef div_ceil(y); (self + y - 1) / y end\r\ndef mod_inv(mod = MOD); pow(mod-2, mod) end\r\ndef mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\r\ndef factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\ndef popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\ndef bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\ndef lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\ndef shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\ndef widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\ndef power(&block); (0 ... 1 << size).each(&block) end\r\ndef sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\ndef upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\ndef lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\ndef cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\ndef cumdiff(range); self[range.end_open] - self[range.begin]; end\r\nend\r\n\r\nmodule Enumerable\r\ndef sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\ndef cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain"}], "negative_code": [], "src_uid": "842a0587147591ea38a20638f3a7960d"} {"source_code": "T = gets.to_i\n\nT.times do\n x, y, k = gets.split.map(&:to_i)\n\n ok = Rational(k * (1 + y) - 1, x - 1).ceil\n\n puts ok + k\nend\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\nneed = 0\nkaisuu = 0\nt.times do \n x, y, k = gets.chomp.split(\" \").map(&:to_i)\n need = k + y * k #\u5fc5\u8981(\u677e)\n sa = x - 1\n kaisuu = (need - 1) / sa\n amari = (need - 1) % sa\n if amari != 0\n kaisuu += 1\n end\n sekitan = (need - k)/ y\n puts kaisuu + sekitan\nend\n\n"}, {"source_code": "gets.to_i.times do\n x, y, k = gets.split.map &:to_i\n puts ((y + 1) * k + x - 3) / (x - 1) + k\nend"}, {"source_code": "gets.to_i.times do\n a, b, k = gets.strip.split(\" \").map(&:to_i)\n cn = k\n csn = cn*b\n tsn = csn + k\n dsn = tsn - 1\n iop = dsn / (a-1)\n iop += 1 if (dsn % (a-1)) > 0\n puts iop + cn\nend"}], "negative_code": [], "src_uid": "28610d192329c78580db354f8dfc4094"} {"source_code": "#!/usr/bin/env ruby\n\nn, k, t = gets.chomp.split(/\\s/).map{|s| s.to_i}\nret = []\n\nmax = n * k\nvalue = (max * (t / 100.0)).to_i\n(value / k).times do\n ret << k\nend\n\nret << value % k\n\n(n - (value.to_i / k) - 1).times do\n ret << 0\nend\n\nputs ret.slice(0, n).join(' ')\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\nn,k,t=gets.chop.split(\" \").map{|i|i.to_i}\nx=n*t/100\ny=t*n*k/100-x*k\nn.times{|i|if i 0\n print ' ' + balance.to_s\n counter += 1\nend\n\nfor fcounter in 1 .. input[0]-counter\n print ' ' + 0.to_s\nend"}, {"source_code": "n, k, t = gets.split(' ').map &:to_i\np, bar = n * k * t / 100, []\n\nn.times do |i|\n\tbar.push [p, k].min\n\tp -= bar.last\nend\n\nputs bar.join \" \""}, {"source_code": "n, k, t = gets.chop.split.map(&:to_i)\n\n#n, k, t = 11, 13, 37\n\nprogress = (n.to_f * k / (100 / t.to_f)).truncate\nnulls = (n.to_f * k - progress).truncate\n\narr = []\nwhile progress > 0 do\n if progress >= k then\n arr << k\n progress -= k\n else\n arr << progress\n progress = 0\n end\nend\n\narr << 0 while arr.length < n\n\nputs arr\n"}, {"source_code": "input=gets.split.map(&:to_i)\n\nn=input[0]\nm=input[1]\nt=input[2]\n\n\nres=0\n0.upto(n*m){|i|\n if i*100<=n*m*t then\n res=i\n end \n}\nfor i in 1..n\n if m<=res then\n printf \"%d \",m\n res-=m\n else\n printf \"%d \",res\n res-=res\n end\nend\nputs\n\n"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\nsaturated = (t/(100.0/n)).to_i\nsum_saturated = saturated * k\nlast_saturation = (t * n * k / 100) - sum_saturated\nsaturated.times do |i|\n a[i] = k.to_i\nend\nif saturated >= n \n print a.join(' ')\nelse \n a[saturated] = last_saturation.to_i\n print a.join(' ')\nend\n"}, {"source_code": "n, k, t = gets.split.map(&:to_i)\ns = n * k * t / 100\na = []\nn.times do\n\ta << [s, k].min\n\ts -= a[-1]\nend\nputs a * ' '\n"}, {"source_code": "input = gets.split.map(&:to_i)\nl = (input[2] * input[0]*input[1]/100.0).floor\nfull = l/input[1]\nfull.times {print input[1], ' '}\nif full != input[0]\n print l % input[1]\n (input[0] - full - 1).times {print ' ', 0}\nend\n"}, {"source_code": "n, k, t = gets.split.map(&:to_i)\n\nval = Rational(100, n*k)\n\ns = 0\ns += 1 while (s+1)*val <= t\no = [k] * (s/k)\no << s%k if s%k > 0\no = (o + [0]*n)[0,n]\nputs o*\" \"\n"}, {"source_code": "n,k,t = gets.split.map(&:to_i)\nall = n*k\nval = (t*n*k/100.0).to_i\narr = [0] * n\nn.times do |i|\n\tarr[i] = [k, val].min\n\tval = [val-k, 0].max\nend\nputs arr.join(' ')\n"}], "negative_code": [{"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\nif(t <= k)\n a[0] = t\n print a.join(' ')\nelse\n saturated = t / (100/n)\n sum_saturated = saturated * k\n last_saturation = (t * n * k / 100) - sum_saturated\n saturated.times do |i|\n a[i] = k.to_i\n end\n if saturated >= n \n print a.join(' ')\n else \n a[saturated] = last_saturation.to_i\n print a.join(' ')\n end\nend\n"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\n#if(t <= k)\n# a[0] = t\n# print a.join(' ')\n#else\n p = t*n/100\n q = (t - (p*(100.0/n))).to_i\n p.times do |i|\n a[i] = k\n end\n if(q >= (100.0/n.to_f/k.to_f))\n a[p] = q * n * k / 100\n end\n print a.join(' ')\n #saturated = t / (100/n)\n #sum_saturated = saturated * k\n #last_saturation = (t * n * k / 100) - sum_saturated\n #saturated.times do |i|\n # a[i] = k.to_i\n #end\n #if saturated >= n \n # print a.join(' ')\n #else \n # a[saturated] = last_saturation.to_i\n # print a.join(' ')\n #end\n#end\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn, k, t = gets.chomp.split(/\\s/).map{|s| s.to_i}\nret = []\n\nmax = n * k\nvalue = (max * (t / 100.0)).to_i\n(value / k).times do\n ret << k\nend\n\nret << value % k\n\n(n - (value.to_i / k) - 1).times do\n p :hoge\n ret << 0\nend\n\nputs ret.slice(0, n).join(' ')\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn, k, t = gets.chomp.split(/\\s/).map{|s| s.to_i}\nret = []\n\nmax = n * k\nvalue = (max * (t / 100.0)).to_i\n(value / k).times do\n ret << k\nend\n\nret << value % k\n\n(n - (value.to_i / k) - 1).times do\n ret << 0\nend\n\nputs ret.join(' ')\n"}, {"source_code": "n,k,t=gets.chop.split(\" \").map{|i|i.to_i}\nx,y=t.divmod(k)\nn.times{|i|if i 0\n\nfor fcounter in (points/input[1])+1 .. input[0]\n print ' ' + 0.to_s\nend"}, {"source_code": "input = gets.split.map(&:to_i)\n\npoints = (input[2]*input[0]*input[1]) / 100\n\nfor counter in 1..(points/input[1])\n print input[1].to_s + ' '\nend\n\nbalance = points - (points/input[1]) * input[1]\n\nprint balance if balance > 0\n\nfor fcounter in (points/input[1])+2 .. input[0]\n print ' ' + 0.to_s\nend"}, {"source_code": "n, k, t = gets.chop.split.map(&:to_i)\n\n#n, k, t = 10, 10, 54\n\nprogress = (n.to_f * k / (100 / t.to_f)).truncate\n\narr = []\nwhile progress > 0 do\n if progress >= k then\n arr << k\n progress -= k\n else\n arr << progress\n progress = 0\n end\nend\n\nputs arr"}, {"source_code": "n, k, t = gets.chop.split.map(&:to_i)\n\n#n, k, t = 11, 13, 37\n\nprogress = (n.to_f * k / (100 / t.to_f)).truncate\nnulls = n.to_f * k - progress\n\narr = []\nwhile progress > 0 do\n if progress >= k then\n arr << k\n progress -= k\n else\n arr << progress\n progress = 0\n end\nend\n\nbegin arr << 0; nulls -= k end while nulls > k\n\nputs arr"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\nif(t <= k)\n a[0] = t\n print a.join(' ')\nelse\n p = t * n / 100\n q = (t - (p*(100.0/n))).to_i\n p.times do |i|\n a[i] = k\n end\n if(q > 0)\n a[p] = q * n * k / 100\n end\n print a.join(' ')\n #saturated = t / (100/n)\n #sum_saturated = saturated * k\n #last_saturation = (t * n * k / 100) - sum_saturated\n #saturated.times do |i|\n # a[i] = k.to_i\n #end\n #if saturated >= n \n # print a.join(' ')\n #else \n # a[saturated] = last_saturation.to_i\n # print a.join(' ')\n #end\nend\n"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\nsaturated = t / (100/n)\nsum_saturated = saturated * k\nlast_saturation = (t * n * k / 100) - sum_saturated\nsaturated.times do |i|\n a[i] = k\nend\nif saturated >= n \n print a.join(' ')\nelse \n a[saturated] = last_saturation\n if(saturated + 1 < n)\n ((saturated + 1)..n).each do |i|\n a[i] = 0\n end \n end\n print a.join(' ')\nend\n"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\nif(t <= k)\n a[0] = t\n print a.join(' ')\nelse\n saturated = t / (100/n)\n sum_saturated = saturated * k\n last_saturation = t * n * k / 100 - sum_saturated\n saturated.times do |i|\n a[i] = k.to_i\n end\n if saturated >= n \n print a.join(' ')\n else \n a[saturated] = last_saturation.to_i\n if(saturated + 1 < n)\n ((saturated + 1)..n-1).each do |i|\n a[i] = 0\n end \n end\n print a.join(' ')\n end\nend\n"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\nif(t <= k)\n a[0] = t\n print a.join(' ')\nelse\n saturated = t / (100/n)\n sum_saturated = saturated * k\n last_saturation = t * n * k / 100 - sum_saturated\n saturated.times do |i|\n a[i] = k.to_i\n end\n if saturated >= n \n print a.join(' ')\n else \n a[saturated] = last_saturation.to_i\n print a.join(' ')\n end\nend\n"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\nif(t <= k)\n a[0] = t\n print a.join(' ')\nelse\n p = t*n/100\n q = (t - (p*(100.0/n))).to_i\n p.times do |i|\n a[i] = k\n end\n if(q >= (100.0/n.to_f/k.to_f))\n a[p] = q * n * k / 100\n end\n print a.join(' ')\n #saturated = t / (100/n)\n #sum_saturated = saturated * k\n #last_saturation = (t * n * k / 100) - sum_saturated\n #saturated.times do |i|\n # a[i] = k.to_i\n #end\n #if saturated >= n \n # print a.join(' ')\n #else \n # a[saturated] = last_saturation.to_i\n # print a.join(' ')\n #end\nend\n"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\nif(t <= k)\n a[0] = k\n print a.join(' ')\nelse\n saturated = t / (100/n)\n sum_saturated = saturated * k\n last_saturation = t * n * k / 100 - sum_saturated\n saturated.times do |i|\n a[i] = k.to_i\n end\n if saturated >= n \n print a.join(' ')\n else \n a[saturated] = last_saturation.to_i\n if(saturated + 1 < n)\n ((saturated + 1)..n-1).each do |i|\n a[i] = 0\n end \n end\n print a.join(' ')\n end\nend\n"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\n#if(t <= k)\n# a[0] = t\n# print a.join(' ')\n#else\n #p = t*n/100\n #q = (t - (p*(100.0/n))).to_i\n #p.times do |i|\n # a[i] = k\n #end\n #if(q >= (100.0/n.to_f/k.to_f))\n # a[p] = q * n * k / 100\n #end\n #print a.join(' ')\n saturated = t / (100/n)\n sum_saturated = saturated * k\n last_saturation = (t * n * k / 100) - sum_saturated\n saturated.times do |i|\n a[i] = k.to_i\n end\n if saturated >= n \n print a.join(' ')\n else \n a[saturated] = last_saturation.to_i\n print a.join(' ')\n end\n#end\n"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\nsaturated = t / (100/n)\nsum_saturated = saturated * k\nlast_saturation = (t * n * k / 100) - sum_saturated\nsaturated.times do |i|\n a[i] = k\nend\nif saturated >= n \n print a.join(' ')\nelse \n a[saturated] = last_saturation\n if(saturated + 1 < n)\n ((saturated + 1)..n-1).each do |i|\n a[i] = 0\n end \n end\n print a.join(' ')\nend\n"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\nsaturated = t / (100/n)\nsum_saturated = saturated * k\nlast_saturation = (t * n * k / 100) - sum_saturated\nsaturated.times do |i|\n a[i] = k\nend\nif saturated >= n \n puts a\nelse \n a[saturated] = last_saturation\n if(saturated + 1 < n)\n ((saturated + 1)..n).each do |i|\n a[i] = 0\n end \n end\n puts a\nend\n"}, {"source_code": "input = STDIN.gets\nn,k,t = input.strip.split(' ').map{|w| w.to_i}\na = Array.new(n).fill(0)\nif(t <= k)\n a[0] = t\n print a.join(' ')\nelse\n p = t * n / 100\n q = (t - (p*(100.0/n))).to_i\n puts p,q\n p.times do |i|\n a[i] = k\n end\n if(q > 0)\n a[p] = q * n * k / 100\n end\n print a.join(' ')\n #saturated = t / (100/n)\n #sum_saturated = saturated * k\n #last_saturation = (t * n * k / 100) - sum_saturated\n #saturated.times do |i|\n # a[i] = k.to_i\n #end\n #if saturated >= n \n # print a.join(' ')\n #else \n # a[saturated] = last_saturation.to_i\n # print a.join(' ')\n #end\nend\n"}], "src_uid": "0ad96b6a8032d70df400bf2ad72174bf"} {"source_code": "n = gets.to_i\ncnt0 = 0\ncnt1 = 0\nold = -1\nans = 1\n\n\narr = gets.split(\" \").map(&:to_i)\nfor i in 0..n-1 do \n if (old == (-1)) \n old = arr[i]\n cnt1 = cnt1 + 1\n elsif (arr[i] == old) \n cnt1 = cnt1 + 1 \n elsif (arr[i] != old and cnt0 == 0) \n old = 1 - old\n cnt0 = cnt1\n cnt1 = 1\n elsif (arr[i] != old && cnt1 == cnt0) \n old = 1 - old\n cnt1 = 1\n elsif (arr[i] != old and cnt1 != cnt0)\n ans = 0\n \n end \n \n \n \nend\nif (cnt1 != cnt0 and cnt0 != 0)\n ans = 0\nend\nif (ans == 0) \n puts \"NO\"\nelse\n puts \"YES\"\nend", "positive_code": [{"source_code": "n=gets.to_i()\ns=gets.split()\np=0\nq=0\nh=0\nf=1\nfor i in s\n\tif(i!=p)\n\t\tif(q!=h && h!=0)\n\t\t\tf=0\n\t\t\tbreak\n\t\tend\n\t\th=q\n\t\tp=i\n\t\tq=1\n\telse\n\t\tq+=1\n\tend\nend\nif(q!=h && h!=0)\n\tf=0\nend\nif(f==1)\n\tputs('YES')\nelse\n\tputs('NO')\nend"}, {"source_code": "n = gets.chomp().to_i\nprv = -1\nlen = -1\ntarget = -1\nok = 1\ngets.split.map(&:to_i).each do |a|\n\tif a != prv\n\t\tprv = a\n\t\tif target != -1 and len != target\n\t\t\tok = 0\n\t\tend\n\t\ttarget = len\n\t\tlen = 0\n\telse\n\t\tlen = len + 1\n\tend\nend\nif target != -1 and len != target\n\tok = 0\nend\nif ok == 1\n\tputs \"Yes\"\nelse\n\tputs \"No\"\nend"}, {"source_code": "gets\nputs gets.split.chunk{|n|n}.map{|b,a|a.size}.uniq.size<2?\"Yes\":\"No\"\n"}, {"source_code": "gets\nputs gets.split.map(&:to_i).chunk{|n| n==0}.map{|b,a| a.size}.uniq.length==1 ? \"Yes\" : \"No\"\n\n"}, {"source_code": "n = gets.chomp.to_i\n\na = []\ngets.chomp.split.each do |i|\n a << i.to_i\nend\nl = -1\npv = a[0]\ncl = 0\nfl = 0\na.each do |x|\n if (x != pv)\n if (l == -1)\n l = cl\n end\n if (l != cl)\n fl = 1\n end\n cl = 0\n end\n pv = x\n cl += 1\nend\nif (l == -1)\n l = cl\nend\nif (l != cl)\n fl = 1\nend\nif fl == 1\n puts \"NO\"\nelse\n puts \"YES\"\nend"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map{|x| x.to_i}\nkek = 0\nkek2 = 0\ntt = a[0]\nans = \"YES\"\nflag = true\nfor i in a do\n if i == tt\n kek += 1\n else\n flag = false\n if kek2 == kek\n tt = i\n kek = 1\n elsif kek2 == 0 then\n tt = i\n kek2 = kek\n kek = 1\n else\n ans = \"NO\"\n break\n end\n end\nend\nif kek != kek2\n ans = \"NO\"\nend\nif flag\n ans = \"YES\"\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\n\nA = gets.split\n\nlen = 1\nfor i in 1..(n - 1)\n\tif (A[i - 1] != A[i]) \n\t\tbreak\n\t\tend\n\tlen += 1\nend\n\n\nx = 1\n\nfor i in 1..(n - 1)\n\tif (A[i - 1] != A[i] && i % len != 0) \n\t\tx = 0\n\t\tend \n\tif (A[i - 1] == A[i] && i % len == 0)\n\t\tx = 0\n\t\tend\nend\n\n\t\t\nif (x == 0 || n % len > 0) \n\tputs \"NO\"\nelse\n\tputs \"YES\"\nend \n\t"}, {"source_code": "n = gets.to_i\na = gets.chomp.split()\nb = Array.new\nlst = a.at(0)\nc = 1\nfor i in 1..(n-1)\n if a.at(i) == lst\n c = c+1\n else\n b.push(c)\n c = 1\n lst = a.at(i)\n end\nend\nb.push(c)\nans = \"NO\"\nif b.uniq.size == 1\n ans = \"YES\"\nend\nputs ans"}, {"source_code": "r=->{gets.split.map &:to_i}\nn=r[]\na=r[] + [2]\n\ncolor = a[0]\nl = 1\nwhitelen = -1\nblacklen = -1\n\ngood = true\n\nfor i in 1 ... a.size\n if a[i] != color\n if color == 1\n if whitelen == -1 or whitelen == l\n whitelen = l\n else\n good = false\n end\n else\n if blacklen == -1 or blacklen == l\n blacklen = l\n else\n good = false\n end\n end\n color = a[i]\n l = 0\n end\n l += 1\nend\n\nif blacklen != -1 and whitelen != -1 and whitelen != blacklen\n good = false\nend\n\nif good\n puts \"YES\"\nelse\n puts \"NO\"\nend"}, {"source_code": "n = gets().split(' ').map{|x| Integer(x)}[0]\na = gets().split(' ').map{|x| Integer(x)}\n\ncur = 1\nst = -1\nflag = true\n\n(1...n).each do |i|\n if i == 0 or a[i] != a[i - 1] then\n \tif st == -1 then\n \t\tst = cur\n \telsif cur != st\n \t\tflag = false\n \tend\n \tcur = 1\n else\n \tcur += 1\n end\nend\n\nif st == -1 then\n\tst = cur\nelsif cur != st\n\tflag = false\nend\n\nif flag then\n\tputs(\"YES\")\nelse\n\tputs(\"NO\")\nend\n\n# your code goes here"}, {"source_code": "# fo = open(\"input.txt\", 'r')\nn = gets.to_i\n\nres = gets.split()\ncnt = -1\ncur = 1\nans = 'Yes'\n(n - 1).times do |i|\n if (res[i] == res[i + 1]) \n cur += 1\n else\n if (cnt == -1) \n cnt = cur\n else \n if (cnt != cur)\n ans = 'No'\n end\n end\n cur = 1\n end\nend\n\nif (cnt != cur and cnt != -1) \n ans = 'No'\nend\n\nputs(ans)"}, {"source_code": "n = gets\nar = gets.chomp.split.map(&:to_i)\ncombed = Hash.new\nold = ar[0]\ni = 1\n(1..ar.length).each do |x|\n cur = ar[x]\n if old == cur\n i+=1\n else\n combed[i] = 1\n i = 1\n old = cur\n end\nend\n\nputs combed.size <= 1 ? \"YES\" : \"NO\""}, {"source_code": "n = gets.to_i\nphoto = gets.split\n\ncurrent_color = photo.first\nfirst_strip_width = 0\ncurrent_strip_width = 0\nphoto.each do |pixel|\n if pixel == current_color\n current_strip_width += 1\n else\n first_strip_width = current_strip_width if first_strip_width == 0\n if current_strip_width != first_strip_width\n break\n end\n current_strip_width = 1\n current_color = pixel\n end\nend\n\nfirst_strip_width = current_strip_width if first_strip_width == 0\nif current_strip_width == first_strip_width\n puts \"YES\"\nelse\n puts \"NO\"\nend"}], "negative_code": [{"source_code": "n = gets.to_i\ncnt0 = 0\ncnt1 = 0\nold = -1\nans = 1\n\n\narr = gets.split(\" \").map(&:to_i)\nfor i in 0..n-1 do \n if (old == (-1)) \n old = arr[i]\n cnt1 = cnt1 + 1\n elsif (arr[i] == old) \n cnt1 = cnt1 + 1 \n elsif (arr[i] == 1 - old and cnt0 == 0) \n old = 1 - old\n cnt0 = cnt1\n cnt1 = 1\n \n elsif (arr[i] == 1 - old and cnt1 != cnt0)\n ans = 0\n \n end \n \nend\nif (cnt1 != cnt0 and cnt0 != 0)\n ans = 0\nend\nif (ans == 0) \n puts \"NO\"\nelse\n puts \"YES\"\nend"}, {"source_code": "n = gets.to_i\n\nA = gets.split\n\nlen = 1\nfor i in 1..(n - 1)\n\tif (A[i - 1] != A[i]) \n\t\tbreak\n\t\tend\n\tlen += 1\nend\n\n\nx = 1\n\nfor i in 1..(n - 1)\n\tif (A[i - 1] != A[i] && i % len != 0) \n\t\tx = 0\n\t\tend \nend\n\n\t\t\nif (x == 0 || n % len > 0) \n\tputs \"NO\"\nelse\n\tputs \"YES\"\nend \n\t"}, {"source_code": "n = gets.to_i\na = gets.chomp.split()\nputs a\nb = Array.new\nlst = a.at(0)\nc = 1\nfor i in 1..(n-1)\n\n if a.at(i) == lst\n c = c+1\n else\n b.push(c)\n c = 1\n lst = a.at(i)\n end\nend\nb.push(c)\nans = \"NO\"\nif b.uniq.size == 1\n ans = \"YES\"\nend\nputs ans"}], "src_uid": "75a00d8a614fd0bcb8504b0268a121e0"} {"source_code": "I = ->{gets.split.map &:to_i}\nn, m = I[]\nm -= 1\na = I[].sort\nh = Hash.new(0)\na.each{|_| h[_] += 1}\nh.sort.each{|k, v|\n if m < v * n\n m /= v\n puts \"#{k} #{a[m]}\"\n break\n else\n m -= v * n\n end\n}\n", "positive_code": [{"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\n\na.sort!\nk-=1\ninput=[]\nn.times{|i|\n if i>0&&a[i]==a[i-1]\n input[input.length-1][1]+=1\n else\n input.push([a[i],1])\n end\n}\ninput.each{|t|\n if k= 0 and data[low-1] == a\n low -= 1\nend\nhigh = ai\nwhile high+1 < n and data[high+1] == a\n high += 1\nend\nb = data[(k - low*n)/(high-low+1)]\nputs '%d %d' % [a, b]\n"}, {"source_code": "n,k = gets.split.map(&:to_i)\nk -= 1\na = gets.split.map(&:to_i).sort\n\nd,m = k.divmod n\n\ns = a.select{|e|e == a[d] }.size\n\nif s > 1\n f = a.index(a[d])*n\n m = (k-f)/s\nend\n\nprint a[d], \" \",a[m]\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn, k = *$stdin.gets.chomp.split.map(&:to_i)\nas = $stdin.gets.chomp.split.map(&:to_i)\n\nh = Hash.new { 0 }\nas.each do |a|\n h[a] += 1\nend\n\nh.keys.sort.each do |a1|\n c1 = h[a1]\n if k-c1*n <= 0\n h.keys.sort.each do |a2|\n c2 = h[a2]\n if k-c1*c2 <= 0\n puts [a1, a2].join(' ')\n exit 0\n end\n k -= c1*c2\n end\n end\n k -= c1*n\nend\n"}, {"source_code": "n,k=gets.chomp.split.collect{|a| a.to_i}\narr=gets.chomp.split.collect{|a| a.to_i}.sort\nk=k-1\nif arr[k/n] == arr[k/n+1] || arr[k/n]==arr[k/n-1]\nm=arr.count arr[k/n]\nz=arr.index arr[k/n]\n\nprint arr[k/n],\" \",arr[(k-z*n)/m]\nelse\nprint arr[k/n],\" \" , arr[k%(n)].to_s\nend\n\n"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\nnumbers = gets.split.collect{|i| i.to_i}.sort\n\nk -= 1 \nf_idx = k / n\ns_idx = k % n\n\nfl = numbers.index(numbers[f_idx])\nfr = numbers.rindex(numbers[f_idx])\n\nif not fl == fr\n rem = k - fl * n\n s_idx = rem / (fr - fl + 1)\nend\n\nputs [numbers[f_idx], numbers[s_idx]].join(\" \")"}], "negative_code": [{"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\n\na.sort!\nk-=1\nn.times{|i|\n if k= 0 and data[low] == a\n low -= 1\nend\nhigh = ai+1\nwhile high < n and data[high] == a\n high += 1\nend\nb = data[(k - low*n)/(high-low+1)]\nputs '%d %d' % [a, b]\n"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\ndata = STDIN.readline.split.map {|s| s.to_i }.sort\nk -= 1\na = data[k/n]\nb = data[k%n]\nputs '%d %d' % [a, b]\n"}, {"source_code": "n,k = gets.split.map(&:to_i)\nk -= 1\na = gets.split.map(&:to_i).uniq.sort\n\nd,m = k.divmod n\n\n\nprint a[d], \" \",a[m]\n"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\nn, k = *$stdin.gets.chomp.split.map(&:to_i)\nas = $stdin.gets.chomp.split.map(&:to_i).sort\n\nk -= 1\nputs [as[k/n], as[k%n]].join(' ')\n"}, {"source_code": "n,k=gets.chomp.split.collect{|a| a.to_i}\narr=gets.chomp.split.collect{|a| a.to_i}.sort\nk=k-1\nprint arr[k/n],\" \" , arr[k%(n)].to_s\n"}, {"source_code": "n,k=gets.chomp.split.collect{|a| a.to_i}\narr=gets.chomp.split.collect{|a| a.to_i}.sort\nk=k-1\nif arr[k/n] == arr[k/n+1] || arr[k/n]==arr[k/n-1]\nprint arr[k/n],\" \",arr[k/n]\nelse\nprint arr[k/n],\" \" , arr[k%(n)].to_s\nend\n\n"}, {"source_code": "n,k=gets.chomp.split.collect{|a| a.to_i}\narr=gets.chomp.split.collect{|a| a.to_i}.sort\nk=k-1\nif arr[k/n] == arr[k/n+1] || arr[k/n]==arr[k/n-1]\nm=arr.count arr[k/n]\nprint arr[k/n],\" \",arr[(k/m)]\nelse\nprint arr[k/n],\" \" , arr[k%(n)].to_s\nend\n\n"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\nnumbers = gets.split.collect{|i| i.to_i}.sort\n\nk -= 1 \nf_idx = k / n\ns_idx = k % n\n\nputs [numbers[f_idx], numbers[s_idx]].join(\" \")"}], "src_uid": "d3b9ffa76436b957ca959cf9204f9873"} {"source_code": "t=gets.to_i\nt.times do \n n=gets.to_i\n an=gets.chomp.split(' ').map(&:to_i)\n start = an.find_index {|ai|ai!=0}\n last =n-1-an.reverse.find_index{|ai|ai!=0}\n gapc=an[start..last].count do |ai|\n ai==0\n end\n p gapc\nend", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n books = []\n\n a.each_with_index do |x, i|\n next if x == 0\n\n books << i\n end\n\n ans = 0\n\n books.each_cons(2) do |a, b|\n ans += b - a - 1\n end\n\n puts ans\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n arr = gets.chomp.split(' ').map(&:to_i)\n st = -1\n res = 0\n arr.each_with_index do |el, ind|\n if el == 1 && st != -1\n res += ind - st - 1\n st = ind\n end\n if el == 1 && st == -1\n st = ind\n end\n end\n puts res\nend"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n ans = 0\n count = 0\n an = 0\n a.each do |i|\n if i == 0 && count >= 1\n an += 1\n elsif i == 1\n count += 1\n ans += an\n an = 0\n end\n end\n puts ans\nend"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n v = gets.split.map(&:to_i)\n seen = false\n cur = 0\n r = 0\n v.each do |x|\n cur += 1 if seen && x == 0\n if x == 1\n seen = true\n r += cur\n cur = 0\n end\n end\n puts r\nend\n"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n cnt = 0\n left = -1\n right = -1\n n.times do |i|\n if left == -1 && a[i] == 1\n left = i\n end\n if right == -1 && a[n-1-i] == 1\n right = n-1-i\n end\n end\n for i in left..right\n if a[i] == 0\n cnt += 1\n end\n end\n ans << cnt\nend\nputs ans"}, {"source_code": "gets.to_i.times do\n _ = gets\n a = gets.split.map(&:to_i)\n puts a.rindex(1) - a.index(1) - a.count(1) + 1\nend\n"}], "negative_code": [], "src_uid": "1c07882651ef6ebfc05e777d562e28b9"} {"source_code": "n = gets.to_i\ng = 0\na = gets.strip.split.map(&:to_i)\na.each do |x|\n g = g.gcd(x)\nend\nres = 0\ni = 1\nwhile i ** 2 <= g\n if g % i == 0\n res += 1\n res += 1 if i != g / i\n end\n i += 1\nend\nputs res", "positive_code": [{"source_code": "class NemiLib\n # \u7d20\u56e0\u6570\u5206\u89e3\u30cf\u30c3\u30b7\u30e5\u5f62\u5f0f\n # (\u4f8b)100\u306a\u3089{2=>2,5=>2}\n def prime_factorization(num, result = Hash.new(0))\n return {} if num < 1\n return {1=>1} if num == 1\n\n divides = false\n to = Math.sqrt(num).floor\n # \uff12\u3060\u3051\u5225\u51e6\u7406\n # \u518d\u8d77\u3067\u547c\u3073\u51fa\u3059\u306e\u30671\u30e1\u30bd\u30c3\u30c9\u4e2d\u306b1\u56de\u3060\u3051\u3057\u304b\u5272\u3089\u306a\u3044\u3088\u3046\u306b\u3059\u308b\n if num % 2 == 0\n result[2] += 1\n prime_factorization(num / 2, result)\n divides = true\n else\n 3.step(to, 2) do |item|\n if num % item == 0\n result[item] += 1\n prime_factorization(num / item, result)\n divides = true\n break\n end\n end\n end\n # \u4f55\u3082\u5272\u308c\u306a\u3044\u306a\u3089\u3001\u305d\u306e\u6570\u3092\u5165\u308c\u308b\n result[num] += 1 unless divides\n\n result\n end\n\n # \u7d04\u6570\n def divisors(num)\n return [1] if num == 1\n\n pows = []\n # 0\u4e57\u30011\u4e57\u30fb\u30fb\u30fb\u3057\u305f\u5024\u3092\u5165\u308c\u308b\n prime_factorization(num).each_pair do |key, value|\n pow = []\n 0.upto(value).each do |nn|\n pow << key ** nn\n end\n\n pows << pow\n end\n\n first_array = pows.delete_at(0)\n return first_array if pows.size == 0\n\n result = first_array.product(*pows)\n result.map do |item|\n item.inject { |sum, i| sum * i }\n end.sort\n end\nend\n\n\nn = gets.to_i\naa = gets.split.map(&:to_i)\ngcd = aa.inject(:gcd)\npf = NemiLib.new.prime_factorization(gcd)\nputs (pf[1]==1 ? 1 : pf.each_value.inject(1){|sum,i| sum*(i+1)})\n"}, {"source_code": "def divs(n)\n i = 1\n sq = Math.sqrt(n).ceil.to_i\n div = []\n\n while i <= sq\n if (n % i).zero?\n if (n / i) == i\n div << i\n else\n div << i\n div << n / i\n end\n end\n i += 1\n end\n div.uniq\nend\n\nn = gets.strip.to_i\na = gets.strip.split(' ').map(&:to_i).uniq\ng = 0\na.each do |e|\n g = e.gcd(g)\nend\nputs divs(g).size\n"}, {"source_code": "require 'prime'\nclass Integer\n\tdef divisors\n\t\tself.prime_division.reduce([1]) do |a, (p, e)|\n\t\t\t(0..e).map { p**_1 }.product(a).map { _1 * _2 }\n\t\tend.sort\n\tend\n\tdef divisor_count\n\t\tself.prime_division.reduce(1) { |acc, (p, e)| acc *= e + 1 }\n\tend\nend\n\ngets\nputs gets.split.map(&:to_i).reduce(&:gcd).divisor_count\n"}], "negative_code": [{"source_code": "def factors(n)\n facts = [1]\n\n while (n % 2).zero?\n facts << 2\n n = n / 2\n end\n i = 3\n sq = Math.sqrt(n).ceil.to_i\n while i <= sq\n while (n % i).zero?\n facts << i\n n = n / i\n end\n i += 2\n end\n facts << n\n\n facts.uniq\nend\n\n\nn = gets.strip.to_i\na = gets.strip.split(' ').map(&:to_i)\nmn = a.min\nmx = a.max\nfacts = (factors(mn) + factors(mx) + [mn, mx]).uniq\n# puts facts.inspect\n\nres = 0\nfacts.each do |f|\n res += 1 if a.all? { |e| e % f == 0 }\nend\nputs res\n"}, {"source_code": "def factors(n)\n facts = [1]\n\n while (n % 2).zero?\n facts << 2\n n = n / 2\n end\n i = 3\n sq = Math.sqrt(n).ceil.to_i\n while i <= sq\n while (n % i).zero?\n facts << i\n n = n / i\n end\n i += 1\n end\n facts << n if n > 2\n\n facts.uniq\nend\n\n\nn = gets.strip.to_i\na = gets.strip.split(' ').map(&:to_i)\nmn = a.min\nfacts = (factors(mn) + [mn]).uniq\n\nres = 0\nfacts.each do |f|\n res += 1 if a.all? { |e| e % f == 0 }\nend\nputs res\n"}, {"source_code": "class NemiLib\n # \u7d20\u56e0\u6570\u5206\u89e3\u30cf\u30c3\u30b7\u30e5\u5f62\u5f0f\n # (\u4f8b)100\u306a\u3089{2=>2,5=>2}\n def prime_factorization(num, result = Hash.new(0))\n return {} if num < 1\n return {1=>1} if num == 1\n\n divides = false\n to = Math.sqrt(num).floor\n # \uff12\u3060\u3051\u5225\u51e6\u7406\n # \u518d\u8d77\u3067\u547c\u3073\u51fa\u3059\u306e\u30671\u30e1\u30bd\u30c3\u30c9\u4e2d\u306b1\u56de\u3060\u3051\u3057\u304b\u5272\u3089\u306a\u3044\u3088\u3046\u306b\u3059\u308b\n if num % 2 == 0\n result[2] += 1\n prime_factorization(num / 2, result)\n divides = true\n else\n 3.step(to, 2) do |item|\n if num % item == 0\n result[item] += 1\n prime_factorization(num / item, result)\n divides = true\n break\n end\n end\n end\n # \u4f55\u3082\u5272\u308c\u306a\u3044\u306a\u3089\u3001\u305d\u306e\u6570\u3092\u5165\u308c\u308b\n result[num] += 1 unless divides\n\n result\n end\n\n # \u7d04\u6570\n def divisors(num)\n return [1] if num == 1\n\n pows = []\n # 0\u4e57\u30011\u4e57\u30fb\u30fb\u30fb\u3057\u305f\u5024\u3092\u5165\u308c\u308b\n prime_factorization(num).each_pair do |key, value|\n pow = []\n 0.upto(value).each do |nn|\n pow << key ** nn\n end\n\n pows << pow\n end\n\n first_array = pows.delete_at(0)\n return first_array if pows.size == 0\n\n result = first_array.product(*pows)\n result.map do |item|\n item.inject { |sum, i| sum * i }\n end.sort\n end\nend\n\n\nn = gets.to_i\naa = gets.split.map(&:to_i)\ngcd = aa.inject(:gcd)\npf = NemiLib.new.prime_factorization(gcd)\nputs (pf.size==1 ? 1 : pf.each_value.inject(1){|sum,i| sum*(i+1)})"}, {"source_code": "class NemiLib\n # \u7d20\u56e0\u6570\u5206\u89e3\u30cf\u30c3\u30b7\u30e5\u5f62\u5f0f\n # (\u4f8b)100\u306a\u3089{2=>2,5=>2}\n def prime_factorization(num, result = Hash.new(0))\n return {} if num < 1\n return {1=>1} if num == 1\n\n divides = false\n to = Math.sqrt(num).floor\n # TODO \u3046\u307e\u304f\u304b\u304d\u305f\u3044\u3002\uff12\u3060\u3051\u5225\u51e6\u7406\n if num % 2 == 0\n result[2] += 1\n prime_factorization(num / 2, result)\n divides = true\n end\n 3.step(to, 2) do |item|\n if num % item == 0\n result[item] += 1\n prime_factorization(num / item, result)\n divides = true\n break\n end\n end\n # \u4f55\u3082\u5272\u308c\u306a\u3044\u306a\u3089\u3001\u305d\u306e\u6570\u3092\u5165\u308c\u308b\n result[num] += 1 unless divides\n\n result\n end\n\n # \u7d04\u6570\n def divisors(num)\n return [1] if num == 1\n\n pows = []\n # 0\u4e57\u30011\u4e57\u30fb\u30fb\u30fb\u3057\u305f\u5024\u3092\u5165\u308c\u308b\n prime_factorization(num).each_pair do |key, value|\n pow = []\n 0.upto(value).each do |nn|\n pow << key ** nn\n end\n\n pows << pow\n end\n\n first_array = pows.delete_at(0)\n return first_array if pows.size == 0\n\n result = first_array.product(*pows)\n result.map do |item|\n item.inject { |sum, i| sum * i }\n end.sort\n end\nend\n\n\nn = gets.to_i\naa = gets.split.map(&:to_i)\ngcd = aa.inject(:gcd)\npf = NemiLib.new.prime_factorization(gcd)\nputs pf.each_value.inject(1){|sum,i| sum*(i+1)}\n"}, {"source_code": "class NemiLib\n # \u7d20\u56e0\u6570\u5206\u89e3\u30cf\u30c3\u30b7\u30e5\u5f62\u5f0f\n # (\u4f8b)100\u306a\u3089{2=>2,5=>2}\n def prime_factorization(num, result = Hash.new(0))\n return {} if num < 1\n return {1=>1} if num == 1\n\n divides = false\n to = Math.sqrt(num).floor\n # TODO \u3046\u307e\u304f\u304b\u304d\u305f\u3044\u3002\uff12\u3060\u3051\u5225\u51e6\u7406\n if num % 2 == 0\n result[2] += 1\n prime_factorization(num / 2, result)\n divides = true\n end\n 3.step(to, 2) do |item|\n if num % item == 0\n result[item] += 1\n prime_factorization(num / item, result)\n divides = true\n break\n end\n end\n # \u4f55\u3082\u5272\u308c\u306a\u3044\u306a\u3089\u3001\u305d\u306e\u6570\u3092\u5165\u308c\u308b\n result[num] += 1 unless divides\n\n result\n end\n\n # \u7d04\u6570\n def divisors(num)\n return [1] if num == 1\n\n pows = []\n # 0\u4e57\u30011\u4e57\u30fb\u30fb\u30fb\u3057\u305f\u5024\u3092\u5165\u308c\u308b\n prime_factorization(num).each_pair do |key, value|\n pow = []\n 0.upto(value).each do |nn|\n pow << key ** nn\n end\n\n pows << pow\n end\n\n first_array = pows.delete_at(0)\n return first_array if pows.size == 0\n\n result = first_array.product(*pows)\n result.map do |item|\n item.inject { |sum, i| sum * i }\n end.sort\n end\nend\n\n\nn = gets.to_i\naa = gets.split.map(&:to_i)\ngcd = aa.inject(:gcd)\npf = NemiLib.new.prime_factorization(gcd)\nputs (pf.size==1 ? 1 : pf.each_value.inject(1){|sum,i| sum*(i+1)})"}], "src_uid": "6379ec153377fb9c30a7b897659da7d6"} {"source_code": "count = gets.to_i\nmas_width = Array.new(count)\nmas_height = Array.new(count)\nfor i in 0..(count - 1) \n string = gets\n mas_width[i] = string.split(' ')[0].to_i\n mas_height[i] = string.split(' ')[1].to_i\nend\n\nall_width = 0\nfor i in 0..(count - 1)\n all_width += mas_width[i]\nend\n\nnew_mas_height = Array.new(mas_height).sort\n\nmax = new_mas_height[count - 1]\nmax2 = new_mas_height[count - 2]\n\nindex_max = mas_height.index(max)\n\n\nfor i in 0..(count - 1)\n unless i == index_max\n print (all_width - mas_width[i]) * max\n else\n print (all_width - mas_width[i]) * max2\n end\n print ' ' unless i == count - 1\nend", "positive_code": [{"source_code": "amount = gets.chomp.to_i\n\nfriends = []\nsum = 0\nmax1 = 0\nmax2 = 0\n\namount.times {\n\tx = gets.chomp.split(\" \")\n\tx[0] = x[0].to_i\n\tx[1] = x[1].to_i\n\tfriends.push(x)\n\tsum = sum + x[0]\n\n\tif x[1] >= max1\n\t\tmax1 = x[1]\n\tend\n\n\tif x[1] >= max2\n\t\tmax1 = max2\n\t\tmax2 = x[1]\n\tend\n}\n\nfriends.each { |x|\n\tif x[1] == max2\n\t\tprint max1 * (sum - x[0]), \" \"\n\telse\n\t\tprint max2 * (sum - x[0]), \" \"\n\tend\n}"}, {"source_code": "@data = $stdin.read.split\nn = @data.shift.to_i\nw = []\nh = []\nsum_w = 0\nprf_h = []\nsuf_h = []\nn.times do \n\tw << @data.shift.to_i\n\th << @data.shift.to_i\n\tprf_h << h.last\n\tif h.size > 1\n\t\tprf_h[-1] = [prf_h.last, prf_h[-2]].max\n\tend\n\tsuf_h << h.last\n\tsum_w += w.last\nend\n\nn.times do |i|\n\tnext if i == 0\n\tsuf_h[n - i - 1] = [suf_h[n-i-1], suf_h[n-i]].max\nend\n\nresult = []\nn.times do |i|\n\th_left = i == 0 ? 0 : prf_h[i - 1]\n\th_right = i == n - 1 ? 0 : suf_h[i + 1]\n\tresult << (sum_w - w[i]) * [h_left, h_right].max\nend\n\nputs result.join(' ')"}, {"source_code": "friends = gets.strip.to_i\nfr_sizes = Array.new(friends)\n\nw = 0\nh1,h2 = 0,0\n\n#read\nfriends.times do |n|\n pair = gets.strip.split(' ').map(&:to_i)\n w += pair[0]\n if h1 < pair[1] then \n h2 = h1\n h1 = pair[1] \n elsif h2 < pair[1] then\n h2 = pair[1]\n end\n fr_sizes[n] = pair\nend\n\nfr_sizes.each do |wf, hf|\n width = w - wf\n height = (hf == h1 ? h2 : h1)\n print \"#{width * height} \"\nend"}], "negative_code": [], "src_uid": "e1abc81cea4395ba675cf6ca93261ae8"} {"source_code": "n = gets.to_i\nn.times do\n x,y,z = gets.chomp.split(\" \").map(&:to_i)\n max = [x,y,z].max\n if x == max && y == max && z == max\n puts \"YES\"\n puts \"#{max} #{max} #{max}\"\n elsif x == max && y == max\n puts \"YES\"\n puts \"#{z} #{max} #{z}\"\n elsif x == max && z == max\n puts \"YES\"\n puts \"#{max} #{y} #{y}\"\n elsif y == max && z == max\n puts \"YES\"\n puts \"#{x} #{x} #{max}\"\n else\n puts \"NO\"\n end\nend", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n atai = gets.chomp.split(\" \").map(&:to_i)\n atai = atai.sort\n if atai[0] != atai[1] && atai[1] != atai[2] && atai[0] != atai[2]\n puts \"NO\"\n elsif atai[0] == atai[1] && atai[1] == atai[2]\n puts \"YES\"\n print atai[0] \n print \" \"\n print atai[1]\n print \" \"\n print atai[2]\n print \"\\n\"\n elsif atai[0] == atai[1] && atai[1] != atai[2]\n puts \"NO\"\n elsif atai[2] == atai[1] && atai[1] != atai[0]\n puts \"YES\"\n print atai[0] \n print \" \"\n print atai[0]\n print \" \"\n print atai[2]\n print \"\\n\"\n end\n\nend"}, {"source_code": "tc = gets.to_i \n\ntc.times do \n a = gets.split().map{|i| i.to_i } \n maxi = a.max \n b = a.uniq() \n if(a.count(maxi) > 1) \n puts \"YES\"\n if(b.size == 2) \n print \"1 #{b[0]} #{b[1]}\" \n else \n print \"#{b[0]} \"*3\n end \n puts \"\"\n else \n puts \"NO\" \n end\nend"}, {"source_code": "def solve\n x, y, z = gets.strip.split(' ').map(&:to_i)\n mx = [x , y, z].max\n c = 0; nt = -1\n if mx == x\n c += 1\n else \n nt = x\n end\n if mx == y\n c += 1\n else \n nt = y\n end\n if mx == z\n c += 1\n else \n nt = z\n end\n\n if c >= 2\n puts \"YES\"\n if nt == -1\n puts \"#{x} #{y} #{z}\"\n else\n puts \"#{nt} #{nt} #{mx}\"\n end\n else\n puts \"NO\"\n end\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "$, = ' '\ngets.to_i.times do\n a = gets.split.map(&:to_i).sort\n if a[1] != a[2]\n puts \"NO\"\n else\n print \"YES\", a[0], a[0], a[2], \"\\n\"\n end\nend "}, {"source_code": "def solve\n x, y, z = gets.strip.split(' ').map(&:to_i)\n mx = [x , y, z].max\n c = 0; nt = -1\n if mx == x\n c += 1\n else \n nt = x\n end\n if mx == y\n c += 1\n else \n nt = y\n end\n if mx == z\n c += 1\n else \n nt = z\n end\n\n if c >= 2\n puts \"YES\"\n if nt == -1\n puts \"#{x} #{y} #{z}\"\n else\n puts \"#{nt} #{nt} #{mx}\"\n end\n else\n puts \"NO\"\n end\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "gets.to_i.times do\n a = gets.split.map(&:to_i).sort\n puts 'NO' if a[1] != a[2]\n puts \"YES\\n#{a[2]}\" + (\" #{a[0]}\" * 2) if a[1] == a[2]\nend\n\n"}, {"source_code": "gets.to_i.times do\n a = gets.split(' ').map(&:to_i).sort.reverse\n \n if a[0] != a[1]\n puts \"NO\"\n next\n end\n\n puts \"YES\"\n puts \"#{a.first} #{a.last} 1\"\nend\n"}, {"source_code": "gets.to_i.times do\n\ta = gets.split.map(&:to_i)\n\tx, y, z = a\n\tmin, max = a.minmax\n\tcase a.count(max)\n\twhen 3\n\t\tputs 'YES', a.join(' ')\n\twhen 2\n\t\tputs 'YES',\n\t\t (\n\t\t\t\tif x != max\n\t\t\t\t\t[min, min, max]\n\t\t\t\telsif y != max\n\t\t\t\t\t[min, max, min]\n\t\t\t\telse\n\t\t\t\t\t[max, min, min]\n\t\t\t\tend\n\t\t ).join(' ')\n\telse\n\t\tputs 'NO'\n\tend\nend\n"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\nlines.times do\n xyz = gets.split(' ').map(&:to_i).sort.reverse\n if xyz[0] == xyz[1]\n print 'YES', \"\\n\"\n print \"#{xyz[0]} #{xyz[2]} 1\", \"\\n\"\n else\n print 'NO', \"\\n\"\n end\nend\n"}], "negative_code": [{"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\nlines.times do\n xyz = gets.split(' ').map(&:to_i).sort.reverse\n if xyz[0] == xyz[1]\n print 'YES', \"\\n\"\n print \"#{xyz[0]} 1 1\", \"\\n\"\n else\n print 'NO', \"\\n\"\n end\nend\n"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\nlines.times do\n xyz = gets.split(' ').map(&:to_i).sort.reverse\n if xyz[0] == xyz[1]\n print 'YES', \"\\n\"\n print \"#{xyz[0]} #{xyz[1]} 1\", \"\\n\"\n else\n print 'NO', \"\\n\"\n end\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n x, y ,z = gets.chomp.split(\" \").map(&:to_i)\n if x != y && y != z\n puts \"NO\"\n elsif x == y && y == z\n puts \"YES\"\n puts \"#{x}\" +\" \" + \"#{y}\" + \" \" + \"#{z}\"\n elsif x == y && y != z && x > z\n puts \"YES\"\n puts \"#{z}\" +\" \" + \"#{y}\" + \" \" + \"#{z}\"\n elsif x == y && y != z && x < z\n puts \"NO\"\n elsif x == z && y != z && x > y\n puts \"YES\"\n puts \"#{x}\" +\" \" + \"#{y}\" + \" \" + \"#{y}\"\n elsif x == z && y != z && x < y\n puts \"NO\"\n elsif y == z && x != z && y > x\n puts \"YES\"\n puts \"#{x}\" +\" \" + \"#{x}\" + \" \" + \"#{z}\"\n elsif y == z && x != z && y < x\n puts \"NO\"\n end\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n atai = gets.chomp.split(\" \").map(&:to_i)\n atai = atai.sort\n if atai[0] != atai[1] && atai[1] != atai[2] && atai[0] != atai[2]\n puts \"NO\"\n elsif atai[0] != atai[1] && atai[1] != atai[2]\n puts \"YES\"\n print atai[0] \n print \" \"\n print atai[1]\n print \" \"\n print atai[2]\n print \"\\n\"\n elsif atai[0] == atai[1] && atai[1] != atai[2]\n puts \"NO\"\n elsif atai[2] == atai[1] && atai[1] != atai[0]\n puts \"YES\"\n print atai[0] \n print \" \"\n print atai[0]\n print \" \"\n print atai[2]\n print \"\\n\"\n end\n\nend"}], "src_uid": "f4804780d9c63167746132c35b2bdd02"} {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\na.insert(0, 0)\ndp = []\ndp[0] = 0\npos = {}\nfor i in 1..n\n pos[a[i]] = [] if pos[a[i]].nil?\n pos[a[i]] << i\n dp[i] = dp[i-1]\n dp[i] += a[i] if a[i] > 0\nend\nhash = Hash.new(false)\nret = nil\nseg = nil\nfor i in 1..n\n next if hash[a[i]]\n hash[a[i]] = true\n ind = pos[a[i]][-1]\n if ind != i\n result = dp[ind] - dp[i-1]\n result += a[i] * 2 if a[i] < 0\n if ret == nil || ret < result\n ret = result\n seg = [i, ind]\n end\n end\nend\ntree = []\nfor i in 1...seg[0]\n tree << i\nend\nfor i in seg[0] + 1 ... seg[1]\n tree << i if a[i] < 0\nend\nfor i in seg[1] + 1 ..n\n tree << i\nend\nputs \"#{ret} #{tree.size}\"\nputs tree.join(' ')", "positive_code": [{"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n s[i]=s[i-1]+[0,b].max\n if o[b].nil?\n o[b]=i\n else\n c=s[i]-s[o[b]-1]+[2*b,0].min\n m,m1,m2=c,o[b],i if c>=m\n end\nend\nd=a.each_with_index.map {|x,i| i+1 if i=m1&&i=m2 }.compact\n#puts m1,m2\nputs \"#{m} #{d.size}\"\nputs d.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n s[i]=s[i-1]+[0,b].max\n if o[b].nil?\n o[b]=i\n else\n c=s[i]-s[o[b]-1]+[2*b,0].min\n m,m1,m2=c,o[b],i if c>=m\n end\nend\nd=a.each_with_index.map {|x,i| i+1 if i=m1&&i=m2 }.compact\n#puts m1,m2\nputs \"#{m} #{d.size}\"\nputs d.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n oo=o[b]\n s[i]=s[i-1]+(b>0?b:0)\n if oo.nil?\n o[b]=i\n else\n c=s[i]-s[oo-1]+(b>0?0:2*b)\n m,m1,m2=c,oo-1,i-1 if c>m\n end\nend\nd=(1..m1).to_a+(m2+2..n).to_a+a[m1+1..m2-1].each_with_index.map {|x,i| i+2+m1 if x<0 }.compact\n#puts m1,m2\nputs \"#{m} #{d.size}\"\nputs d.join(' ')\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\na.insert(0, 0)\ndp = []\ndp[0] = 0\nfor i in 1..n\n dp[i] = dp[i-1]\n dp[i] += a[i] if a[i] > 0\nend\nhash = Hash.new(false)\nret = nil\nseg = nil\nfor i in 1..n\n next if hash[a[i]]\n hash[a[i]] = true\n ind = a.rindex(a[i])\n if ind != i\n result = dp[ind] - dp[i-1]\n result += a[i] * 2 if a[i] < 0\n if ret == nil || ret < result\n ret = result\n seg = [i, ind]\n end\n end\nend\ntree = []\nfor i in 1...seg[0]\n tree << i\nend\nfor i in seg[0] + 1 ... seg[1]\n tree << i if a[i] < 0\nend\nfor i in seg[1] + 1 ..n\n tree << i\nend\nputs \"#{ret} #{tree.size}\"\nputs tree.join(' ')"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\na.insert(0, 0)\nseg = {}\nfor i in 1..n\n sum = a[i]\n for j in i + 1..n\n sum += a[j] unless a[j] < 0\n if a[i] == a[j]\n sum += a[j] if a[j] < 0\n seg[[i, j]] = sum\n sum -= a[j] if a[j] < 0\n end\n end\nend\nret = nil\nkey = nil\nseg.each do |k, v|\n if ret.nil? || v > ret\n key = k\n ret = v\n end\nend\ntree = []\nfor i in 1...key[0]\n tree << i\nend\nfor i in key[0] + 1...key[1]\n tree << i if a[i] <= 0\nend\nfor i in key[1] + 1..n\n tree << i\nend\nputs \"#{ret} #{tree.size}\"\n\nputs tree.join(' ')"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n s[i]=s[i-1]+[0,b].max\n if o[b].nil?\n o[b]=i\n else\n c=s[i]-s[o[b]-1]+[2*b,0].min\n m,m1,m2=c,o[b],i if c>=m\n end\nend\nd=a.each_with_index.map {|x,i| i+1 if i=m1&&i=m2 }.compact\n#puts m1,m2\nputs \"#{m} #{d.size}\"\nputs d.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n s[i]=s[i-1]+[0,b].max\n if o[b].nil?\n o[b]=i\n else\n c=s[i]-s[o[b]-1]+[2*b,0].min\n m,m1,m2=c,o[b],i if c>=m\n end\nend\nd=a.each_with_index.map {|x,i| i+1 if i=m1&&i=m2 }.compact\n#puts m1,m2\nputs \"#{m} #{d.size}\"\nputs d.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n s[i]=s[i-1]+[0,b].max\n if o[b].nil?\n o[b]=i\n else\n c=s[i]-s[o[b]-1]+[2*b,0].min\n m,m1,m2=c,o[b],i if c>=m\n end\nend\nd=a.each_with_index.map {|x,i| i+1 if i=m1&&i=m2 }.compact\n#puts m1,m2\nputs \"#{m} #{d.size}\"\nputs d.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n s[i]=s[i-1]+[0,b].max\n if o[b].nil?\n o[b]=i\n else\n c=s[i]-s[o[b]-1]+[2*b,0].min\n m,m1,m2=c,o[b],i if c>=m\n end\nend\nd=a.each_with_index.map {|x,i| i+1 if i=m1&&i=m2 }.compact\n#puts m1,m2\nputs \"#{m} #{d.size}\"\nputs d.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n s[i]=s[i-1]+[0,b].max\n if o[b].nil?\n o[b]=i\n else\n c=s[i]-s[o[b]-1]+[2*b,0].min\n m,m1,m2=c,o[b],i if c>=m\n end\nend\nd=a.each_with_index.map {|x,i| i+1 if i=m1&&i=m2 }.compact\n#puts m1,m2\nputs \"#{m} #{d.size}\"\nputs d.join(' ')"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n s[i]=s[i-1]+[0,b].max\n if o[b].nil?\n o[b]=i\n else\n c=s[i]-s[o[b]-1]+[2*b,0].min\n m,m1,m2=c,o[b],i if c>=m\n end\nend\nd=a.each_with_index.map {|x,i| i+1 if i=m1&&i=m2 }.compact\n#puts m1,m2\nputs \"#{m} #{d.size}\"\nputs d.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n s[i]=s[i-1]+[0,b].max\n if o[b].nil?\n o[b]=i\n else\n c=s[i]-s[o[b]-1]+[2*b,0].min\n m,m1,m2=c,o[b],i if c>=m\n end\nend\nd=a.each_with_index.map {|x,i| i+1 if i=m1&&i=m2 }.compact\n#puts m1,m2\nputs \"#{m} #{d.size}\"\nputs d.join(' ')\n"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\na.insert(0, 0)\nseg = {}\nfor i in 1..n\n sum = a[i]\n for j in i + 1...a.size\n sum += a[j] unless a[j] < 0\n if a[i] == a[j]\n sum += a[j] if a[j] < 0\n seg[[i, j]] = sum\n end\n end\nend\nret = nil\nkey = nil\nseg.each do |k, v|\n if ret.nil? || v > ret\n key = k\n ret = v\n end\nend\ntree = []\nfor i in 1...key[0]\n tree << i\nend\nfor i in key[0] + 1...key[1]\n tree << i if a[i] <= 0\nend\nfor i in key[1] + 1..n\n tree << i\nend\nputs \"#{ret} #{tree.size}\"\n\nputs tree.join(' ')"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\nseg = {}\nfor i in 0...a.size\n sum = a[i]\n for j in i + 1...a.size\n sum += a[j] unless a[j] < 0\n if a[i] == a[j]\n sum += a[j] if a[j] < 0\n seg[[i+1, j+1]] = sum\n end\n end\nend\nret = nil\nkey = nil\nseg.each do |k, v|\n if ret.nil? || v > ret\n key = k\n ret = v\n end\nend\ntree = []\nfor i in 1...key[0]\n tree << i\nend\n\nfor i in key[0] + 1...key[1]\n tree << i if a[i - 1] <= 0\nend\nfor i in key[1] + 1..n\n tree << i\nend\nputs \"#{ret} #{tree.size}\"\n\nputs tree.join(' ')"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\na.insert(0, 0)\ndp = []\ndp[0] = 0\nfor i in 1..n\n dp[i] = dp[i-1]\n dp[i] += a[i] if a[i] > 0\nend\nhash = Hash.new(false)\nret = nil\nseg = nil\nfor i in 1..n\n next if hash[a[i]]\n hash[a[i]] = true\n ind = a.rindex(a[i])\n if ind != i\n result = dp[ind] - dp[i-1]\n if ret == nil || ret < result\n ret = result\n seg = [i, ind]\n end\n end\nend\ntree = []\nfor i in 1...seg[0]\n tree << i\nend\nfor i in seg[0] + 1 ... seg[1]\n tree << i if a[i] < 0\nend\nfor i in seg[1] + 1 ..n\n tree << i\nend\nputs \"#{ret} #{tree.size}\"\nputs tree.join(' ')"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\nseg = {}\nfor i in 0...a.size\n sum = a[i]\n for j in i + 1...a.size\n sum += a[j] unless a[j] < 0\n if a[i] == a[j]\n sum += a[j] if a[j] < 0\n seg[[i+1, j+1]] = sum\n end\n end\nend\nret = nil\nkey = nil\nseg.each do |k, v|\n if ret.nil? || v > ret\n key = k\n ret = v\n end\nend\ntree = []\nfor i in 1...key[0]\n tree << i\nend\nfor i in key[0]...key[1]\n tree << i if a[i - 1] <= 0\nend\nfor i in key[1]..n\n tree << i\nend\nputs \"#{ret} #{tree.size}\"\n\nputs tree.join(' ')"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\na.insert(0, 0)\ndp = []\ndp[0] = 0\nfor i in 1..n\n dp[i] = dp[i-1]\n dp[i] += a[i] if a[i] > 0\nend\nhash = Hash.new(false)\nret = nil\nseg = nil\nfor i in 1..n\n next if hash[a[i]]\n hash[a[i]] = true\n ind = a.rindex(a[i])\n if ind != i\n result = dp[ind] - dp[i-1]\n if ret == nil || ret < result\n ret = result\n seg = [i, ind]\n end\n end\nend\ntree = []\nfor i in 1...seg[0]\n tree << i\nend\nfor i in seg[0] + 1 ... seg[1]\n tree << i if a[i] < 0\nend\nfor i in seg[1] + 1 ..n\n tree << i\nend\nputs \"#{ret} #{tree.size}\"\nputs tree.join(' ')"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n oo=o[b]\n s[i]=s[i-1]+(b>0?b:0)\n if oo.nil?\n o[b]=i\n else\n c=s[i]-s[oo-1]+(b>0?0:2*b)\n m,m1,m2=c,oo-1,i-1 if c>m\n end\nend\nd=(0..m1-1).to_a+(m2+1..n-1).to_a+a[m1+1..m2-1].each_with_index.map {|x,i| i+1 if x<0 }.compact\nputs \"#{m} #{d.size}\"\nputs d.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\no={}\ns=[0]\nm=-10**10\nm1,m2=0\nfor i in 1..n do\n b=a[i-1]\n oo=o[b]\n s[i]=s[i-1]+b>0?b:0\n if oo.nil?\n o[b]=i\n else\n c=s[i]-s[oo-1]+b>0?0:2*b\n m,m1,m2=c,oo-1,i-1 if c>m\n end\nend\nd=(0..m1).to_a+(m2..n-1).to_a+a[m1+1..m2-1].each_with_index.map {|x,i| i+1 if x<0 }.compact\nputs \"#{m} #{d.size}\"\nputs d.join(' ')\n"}], "src_uid": "b3418f53720fb9eb990d6e99b07fd61b"} {"source_code": "N = gets.to_i\nC = gets.split.map(&:to_i)\n\nd1 = C.rindex { |c| C[0] != c }\nd2 = N - C.index { |c| C[-1] != c } - 1\n\nputs [d1, d2].max\n", "positive_code": [{"source_code": "n = gets.to_i\nc = gets.split.map(&:to_i)\nl = []\nr = []\nn.times do |i|\n break if l.length == 2\n if l.length == 0\n l << [c[i],i]\n elsif l.length == 1 && l[0][0] != c[i]\n l << [c[i],i]\n end\nend\nn.times do |i|\n break if r.length == 2\n if r.length == 0\n r << [c[-i-1],n-i-1]\n elsif r.length == 1 && r[0][0] != c[-i-1]\n r << [c[-i-1],n-i-1]\n end\nend\nans = 0\nif l[0][0] != r[0][0]\n ans = r[0][1] - l[0][1]\nelse\n ans = [r[1][1] - l[0][1],r[0][1] - l[1][1]].max\nend\np ans\n"}, {"source_code": "n = gets.to_i\nc = gets.split.map(&:to_i)\nans = 0\nfor i in 1..n-1\n if c[0] != c[i]\n ans = i\n end\nend\n(n-2).downto(0) do |i|\n if c[-1] != c[i] && ans < n-1-i\n ans = n-1-i\n end\nend\nputs ans"}], "negative_code": [], "src_uid": "101fec8d8e169f941e71281048468121"} {"source_code": "#!/usr/bin/ruby\nclass Counter < Hash\n\tdef initialize(a=[])\n\t\tsuper\n\t\tself.default=0\n\t\ta.each{|e|self[e]+=1}\n\tend\n\tdef self.[](*a)\n\t\tnew(a)\n\tend\nend\ndef Counter(a=[]) Counter.new(a) end\n\nn=gets.to_i\nb=Counter(gets.split.map(&:to_i))\nm=gets.to_i\np gets.split.map(&:to_i).zip(gets.split.map(&:to_i)).each_with_index.map{|(k,l),z|[b[k],b[l],z+1]}.max[2]", "positive_code": [{"source_code": "n = readline.to_i\narr = readline.split(' ').collect(&:to_i)\nmap = Hash.new(0)\narr.each{|n| map[n] = map[n] + 1}\n\nm = readline.to_i\nb = readline.split(' ').collect(&:to_i)\nc = readline.split(' ').collect(&:to_i)\nbesti, bestb, bestc = -1, -1, -1\nb.zip(c).each_with_index do |item, ind|\n bb, cc = item\n thisb, thisc = map[bb], map[cc]\n if thisb > bestb || thisb == bestb && thisc > bestc\n besti, bestb, bestc = ind, thisb, thisc\n end\nend\n\nputs besti + 1\n"}, {"source_code": "parse_int = lambda { gets.split.map{|x| x.to_i} }\n\nscientists = gets.to_i\nsc_langs = parse_int.call\nfilms = gets.to_i\nfilm_voice = parse_int.call\nfilm_sub = parse_int.call\n\n#p film_voice.to_s\n#p film_sub.to_s\n\nppl_in_lang = Hash.new\nppl_in_lang.default = 0\n\nsc_langs.each { |_|\n if ppl_in_lang[_] == 0\n ppl_in_lang[_]=1\n else\n ppl_in_lang[_]+=1\n end\n}\n\n#p ppl_in_lang.to_s\n\nfilm_good, film_ok = [0]*films, [0]*films\n\nfilms.times { |_|\n film_good[_] += ppl_in_lang[film_voice[_]]\n film_ok[_] += ppl_in_lang[film_sub[_] ]\n}\n#p sc_langs.to_s\n#p sc_langs[3]\n\nbest = 0\nfilms.times { |_|\n best = _ if film_good[_] > film_good[best]\n best = _ if (film_good[_] == film_good[best]) and (film_ok[_] > film_ok[best])\n}\n#p film_good.to_s\n#p film_ok.to_s\n\np best+1\n\n"}], "negative_code": [], "src_uid": "74ddbcf74988940265985ec8c36bb299"} {"source_code": "gets.to_i.times{n,a,b,c,d=gets.split.map(&:to_i)\nh=Hash.new{[]}\n(2..n).map{p,q=gets.split.map(&:to_i);h[p]<<=q;h[q]<<=p}\ne=->s{z={};v=-1;\nf=->c{z[c]||(z[c]=v+=1;h[c].map(&f);v-=1)}\nf[s];z}\ni=e[a]\nputs i[b]>c&&(e[i.max_by{|k,v|v}[0]].values.max>2*c)&&d>2*c ?\"Bob\":\"Alice\"}\n", "positive_code": [{"source_code": "gets.to_i.times{n,a,b,c,d=gets.split.map(&:to_i)\nh=Hash.new{[]}\n(2..n).map{p,q=gets.split.map(&:to_i);h[p]<<=q;h[q]<<=p}\ne=->s{z={};v=-1\nf=->c{z[c]||(z[c]=v+=1;h[c].map(&f);v-=1)}\nf[s];z}\ni=e[a]\nputs i[b]>c&&e[i.max_by{|k,v|v}[0]].values.max>2*c&&d>2*c ?\"Bob\":\"Alice\"}"}, {"source_code": "r=->{gets.split.map &:to_i}\ngets.to_i.times{n,a,b,c,d=r[]\nh=Hash.new{[]}\n(2..n).map{p,q=r[];h[p]<<=q;h[q]<<=p}\ne=->s{z={};v=-1\nf=->c{z[c]||(z[c]=v+=1;h[c].map &f;v-=1)}\nf[s];z}\ni=e[a]\nputs i[b]>c&&e[i.max_by{|k,v|v}[0]].values.max>2*c&&d>2*c ?\"Bob\":\"Alice\"}"}, {"source_code": "r=->{gets.split.map &:to_i}\ngets.to_i.times{n,a,b,c,d=r[]\nh=Hash.new{[]}\n(2..n).map{p,q=r[];h[p]<<=q;h[q]<<=p}\ne=->s{z={};v=-1\nf=->c{z[c]||(z[c]=v+=1;h[c].map &f;v-=1)}\nf[s];z}\ni=e[a]\nputs i[b]>c&&e[i.max_by{|k,v|v}[0]].values.max>c*2&&d>c*2?\"Bob\":\"Alice\"}"}, {"source_code": "gets.to_i.times{n,a,b,c,d=gets.split.map &:to_i\nh=Hash.new{[]}\n(2..n).map{p,q=gets.split.map &:to_i;h[p]<<=q;h[q]<<=p}\ne=->s{z={};v=-1\nf=->c{z[c]||(z[c]=v+=1;h[c].map &f;v-=1)}\nf[s];z}\ni=e[a]\nputs i[b]>c&&e[i.max_by{|k,v|v}[0]].values.max>2*c&&d>2*c ?\"Bob\":\"Alice\"}"}, {"source_code": "gets.to_i.times{n,a,b,c,d=gets.split.map(&:to_i)\nh=Hash.new{[]}\n(2..n).map{p,q=gets.split.map(&:to_i);h[p]<<=q;h[q]<<=p}\ne=->s{z={};v=-1\nf=->c{z[c]||(z[c]=v+=1;h[c].map(&f);v-=1)}\nf[s];z}\ni=e[a]\nputs i[b]>c&&(e[i.max_by{|k,v|v}[0]].values.max>2*c)&&d>2*c ?\"Bob\":\"Alice\"}"}], "negative_code": [], "src_uid": "2bfd566ef883efec5211b01552b45218"} {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n arr = gets.chomp.split(' ').map(&:to_i)\n dp = Hash.new(0)\n min = 10 ** 10\n arr.each do |el|\n dp[el] += 1\n end\n dp.each do |k, v|\n if v == 1\n min = [min, k].min\n end\n end\n puts (arr.index(min) || -2) + 1\nend", "positive_code": [{"source_code": "t = gets.to_i\n\n1.upto t do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n list = a.tally.keep_if {|_, v| v == 1}.keys\n if list.empty?\n puts -1\n else\n puts a.index(list.min)+1\n end\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n count = Hash.new(0)\n index = Hash.new(0)\n ans = []\n a.each_with_index do |i,j|\n count[i] += 1\n end\n #p index\n min = Float::INFINITY\n count.each do |i,j|\n if j == 1\n min = [min,i].min\n end\n end\n if min == Float::INFINITY\n puts \"-1\"\n else\n a.each_with_index do |i,j|\n if i == min\n puts j+1\n end\n end\n end\nend"}, {"source_code": "gets;$<.map{a=gets.split.map &:to_i;p (a.index(a.tally.filter{|k,v|v==1}.keys.min)||-2)+1}"}, {"source_code": "gets;$<.map{a=gets.split.map &:to_i;p (a.index(a.tally.filter{|k,v|v==1}.keys.min)||-2)+1}"}], "negative_code": [], "src_uid": "99d2b0386d101da802ac508ef8f7325b"} {"source_code": "n, k = gets.split.map(&:to_i)\nid = gets.split.map(&:to_i)\nans = []\nid.each {|idi|\n unless ans.include?(idi)\n ans.pop if ans.size == k\n ans.unshift(idi)\n end\n}\np ans.size\nputs ans.join(\" \")\n\n", "positive_code": [{"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2k\n nn = dis.pop\n h[nn]=0\n end\nend\n\nputs \"#{dis.size}\\n#{dis.join(' ')}\""}, {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2k\nend\n\nputs \"#{dis.size}\\n#{dis.join(' ')}\""}], "negative_code": [], "src_uid": "485a1ecf8f569b85327b99382bda9466"} {"source_code": "n = gets.to_i\nrects = []\nn.times do\n mn, mx = gets.strip.split.map(&:to_i)\n rects << [mn, mx].sort\nend\n\nmxh = rects[0][1]\npossible = true\n1.upto(n-1).each do |i|\n if rects[i][0] > mxh\n possible = false\n break\n else\n if rects[i][1] <= mxh\n mxh = rects[i][1]\n else\n mxh = rects[i][0]\n end\n end\nend\n\nputs (possible ? \"YES\" : \"NO\")", "positive_code": [{"source_code": "\nx = gets.chomp.to_i\n\nbest = Integer(1e9+100)\nf = true\nfor i in 0... x\n y = gets.strip.split(' ').map(&:to_i);\n mx = [y[0], y[1]].max\n mn = [y[0] , y[1]].min\n if mx <= best\n best = mx;\n elsif mn <= best\n best = mn\n else\n f = false\n end\n\nend\nunless f\n print \"NO\"\nelse\n print \"YES\"\nend\n\n"}, {"source_code": "def can_arrage_non_ascending(rects)\n\n limit = 10**10\n\n rects.each do |w, h|\n a, b = [w, h].sort\n if b <= limit\n limit = b\n elsif a <= limit\n limit = a\n else\n return false\n end\n end\n\n true\n\nend\n\ndef solution\n count = read_int\n rects = []\n count.times do\n rects << read_ints\n end\n\n puts can_arrage_non_ascending(rects) ? \"YES\" : \"NO\"\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\n"}, {"source_code": "N = gets.to_i\nwh = N.times.map{gets.split.map(&:to_i)}\n\nnum = 10**10\nwh.each do |arr|\n num = arr.select{|e| e <= num}.max\n unless num\n puts 'NO'\n exit\n end\nend\nputs 'YES'"}], "negative_code": [], "src_uid": "162fa942bc6eeb5164b19598da2f8bef"} {"source_code": "t = gets.to_i\n(1..t).each do\n n = gets.to_i\n a = gets.split(' ')\n mp = Hash.new(0)\n a.each do |i|\n mp[i]+=1\n end\n if mp.length == 1\n puts 1\n (1..n).each do\n print \"1 \"\n end\n puts \"\"\n elsif n.modulo(2)==0\n puts \"2\"\n (1..n).each do |i|\n print \"#{i.modulo(2)+1} \"\n end\n puts \"\"\n elsif a[0]==a[n-1]\n puts \"2\"\n (1..n).each do |i|\n print \"#{i.modulo(2)+1} \"\n end\n puts \"\"\n else\n x = -1\n (1..n-1).each do |i|\n if(a[i]==a[i-1])\n x = i\n break\n end\n end\n if x!=-1\n puts \"2\"\n (0..n-1).each do |i|\n if i 1\n\t\t\tmid = (r + l) / 2\n\t\t\tif b[mid] >= i\n\t\t\t\tr = mid\n\t\t\telse\n\t\t\t\tl = mid\n\t\t\tend\n\t\tend\n\t\tr + 1\n\tend\n\tputs ans.uniq.size\n\tputs ans.join(' ')\nend"}], "src_uid": "1f4c3f5e7205fe556b50320cecf66c89"} {"source_code": "def solve(io)\n n = io.gets.to_i\n arr = 2.times.map{ io.gets.split(\" \").map{|s| s.to_i} }\n max = n.times.inject([0, 0, 0]) do |prev, i|\n [[prev[1], prev[2]].max, [prev[0], prev[2]].max + arr[0][i], [prev[0], prev[1]].max + arr[1][i]]\n end.max\n puts max\nend\n\nsolve(STDIN)", "positive_code": [{"source_code": "def check(num, team, row, column, opp_row)\n max = team[ row ][ column ]\n if column + 1 < num\n max += team[ opp_row ][ column + 1 ]\n end\n if column + 2 < num\n sum2 = team[ row ][ column ] + team[ opp_row ][ column + 2 ]\n if(max < sum2)\n max = sum2;\n end\n end\n team[ row ][ column ] = max\nend\ndef start(num, team)\n column = num - 1\n while column >= 0 do\n check(num, team, 0, column, 1)\n check(num, team, 1, column, 0)\n column -= 1;\n end\n if(team[ 0 ][ 0 ] > team[ 1 ][ 0 ])\n return team[ 0 ][ 0 ]\n end\n return team[ 1 ][ 0 ]\nend\nteam = []\nnum = gets.chomp.to_i\nteam.push(gets.chomp.split(' ').collect{|var| var.to_i})\nteam.push(gets.chomp.split(' ').collect{|var| var.to_i})\nputs start(num,team.clone)"}, {"source_code": "n = gets.to_i\nh0 = gets.split.map(&:to_i)\nh1 = gets.split.map(&:to_i)\ndp = Array.new(n+1){[0,0]}\ndp[1][0] = h0[0]\ndp[1][1] = h1[0]\n(2..n).each do |i|\n dp[i][0] = [dp[i-1][1],dp[i-2][1]].max + h0[i-1]\n dp[i][1] = [dp[i-1][0],dp[i-2][0]].max + h1[i-1]\nend\np dp[n].max"}], "negative_code": [{"source_code": "def recur(num,team,row,column)\n sum1 = 0\n if(column == num)\n return 0\n else\n if row == 1\n sum_1 = team[row][column] + recur(num,team,0,column + 1)\n sum_2 = recur(num,team,row,column + 1)\n if(sum_1 > sum_2)\n sum1 = sum_1\n else\n sum1 = sum_2\n end\n else\n sum_1 = team[row][column] + recur(num,team,1,column + 1)\n sum_2 = recur(num,team,row,column + 1)\n if(sum_1 > sum_2)\n sum1 = sum_1\n else\n sum1 = sum_2\n end\n end\n return sum1\n end\nend\ndef start(num, team)\n sum1 = team[1][0] + recur(num,team,0,1)\n sum2 = team[0][0] + recur(num,team,1,1)\n if(sum1 > sum2)\n return sum1\n end\n return sum2\nend\nteam = []\nnum = gets.chomp.to_i\nteam.push(gets.chomp.split(' ').collect{|var| var.to_i})\nteam.push(gets.chomp.split(' ').collect{|var| var.to_i})"}, {"source_code": "def recur(num,team,row,column)\n sum1 = 0\n if(column == num)\n return 0\n else\n if row == 1\n sum_1 = team[row][column] + recur(num,team,0,column + 1)\n sum_2 = recur(num,team,row,column)\n if(sum_1 > sum_2)\n sum1 = sum_1\n else\n sum1 = sum_2\n end\n else\n sum_1 = team[row][column] + recur(num,team,1,column + 1)\n sum_2 = recur(num,team,row,column)\n if(sum_1 > sum_2)\n sum1 = sum_1\n else\n sum1 = sum_2\n end\n end\n return sum1\n end\nend\ndef start(num, team)\n sum1 = team[1][0] + recur(num,team,0,1)\n sum2 = team[0][0] + recur(num,team,1,1)\n if(sum1 > sum2)\n return sum1\n end\n return sum2\nend\nteam = []\nnum = gets.chomp.to_i\nteam.push(gets.chomp.split(' ').collect{|var| var.to_i})\nteam.push(gets.chomp.split(' ').collect{|var| var.to_i})"}], "src_uid": "667e8938b964d7a24500003f6b89717b"} {"source_code": "#!/usr/bin/ruby\n10.times{|i|\n\tp i\n\tSTDOUT.flush\n\ts=gets.chomp\n\tif %w(worse terrible serious die even).any?{|e|s.index e}\n\t\tputs :grumpy\n\t\texit\n\telsif %w(cool great think touch bad).any?{|e|s.index e}\n\t\tputs :normal\n\t\texit\n\tend\n}\n", "positive_code": [{"source_code": "10.times do |i|\n puts i\n $stdout.flush\n if (s = gets.strip.downcase) != \"no\"\n if s.match?(/great|think|touch|bad|cool/i)\n puts \"normal\"\n else\n puts \"grumpy\"\n end\n $stdout.flush\n break\n end\nend\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\n10.times{|i|\n\tp i\n\tSTDOUT.flush\n\ts=gets.chomp\n\tif s.index('worse')||s.index('terrible')||s.index('serious')\n\t\tputs :grumpy\n\t\texit\n\tend\n}\nputs :normal\n"}, {"source_code": "#!/usr/bin/ruby\n10.times{|i|\n\tp i\n\tSTDOUT.flush\n\ts=gets.chomp\n\tif %q(worse terrible serious die even).any?{|e|s.index e}\n\t\tputs :grumpy\n\t\texit\n\telsif %q(cool great think touch bad).any?{|e|s.index e}\n\t\tputs :normal\n\t\texit\n\tend\n}\n"}, {"source_code": "#!/usr/bin/ruby\n10.times{|i|\n\tp i\n\tSTDOUT.flush\n\tif gets.chomp=='worse'\n\t\tputs :grumpy\n\t\texit\n\tend\n}\nputs :normal\n"}, {"source_code": "#!/usr/bin/ruby\n10.times{\n\tp i\n\tSTDOUT.flush\n\tif gets.chomp=='Worse'\n\t\tputs :grumpy\n\t\tSTDOUT.flush\n\t\texit\n\tend\n}\nputs :normal\nSTDOUT.flush\n"}, {"source_code": "#!/usr/bin/ruby\n10.times{|i|\n\tp i\n\tSTDOUT.flush\n\tif gets.chomp=='Worse'\n\t\tputs :grumpy\n\t\texit\n\tend\n}\nputs :normal\n"}, {"source_code": "#!/usr/bin/ruby\n10.times{|i|\n\tp i\n\tSTDOUT.flush\n\ts=gets.chomp\n\tif %q(worse terrible serious die even).any{|e|s.index e}\n\t\tputs :grumpy\n\t\texit\n\telsif %q(cool great think touch bad).any{|e|s.index e}\n\t\tputs :normal\n\t\texit\n\tend\n}\n"}, {"source_code": "#!/usr/bin/ruby\n10.times{|i|\n\tp i\n\tSTDOUT.flush\n\tif gets.chomp=='worse'\n\t\tputs :grumpy;STDOUT.flush\n\t\texit\n\tend\n}\nputs :normal\nSTDOUT.flush"}, {"source_code": "#!/usr/bin/ruby\n10.times{\n\tp i\n\tSTDOUT.flush\n\tif gets.chomp=='Worse'\n\t\tputs :grumpy\n\t\texit\n\tend\n}\nputs :normal\n"}, {"source_code": "puts \"grumpy\"\n\n"}, {"source_code": "w = (0...2).map { |i| puts i; $stdout.flush; gets.strip } .uniq\nputs (w.include?(\"Worse\") ? \"grumpy\" : \"normal\")\n$stdout.flush\n\n"}, {"source_code": "puts 7\ngets s\n$stdout.flush\nputs s\n\n"}, {"source_code": "puts \"normal\"\n$stdout.flush\n\n"}, {"source_code": "w = (0...9).map { |i| puts i; $stdout.flush; gets.strip } .uniq\nputs (w.include?(\"Worse\") ? \"grumpy\" : \"normal\")\n$stdout.flush\n\n"}], "src_uid": "465eae7567d12a40a05e0f258d963838"} {"source_code": "def g(r, n)\n d = (2 * r * r) ** 0.5\n \n return 0 if n == 0\n return 2 * r + d if n == 1\n \n 2 * r + d + (2 * d + r * n) * (n - 1)\nend\n\nm, r = gets.chomp.split(' ').map { |x| x.to_i }\n\ntotal = 0.0\n\nfor n in 1..m\n total += g(r, n - 1) + g(r, m - n) + 2 * r\nend\n\nputs total / m ** 2", "positive_code": [{"source_code": "m,r=gets.split.map(&:to_i)\nx=2**0.5*r\ns=m-1\nfor i in 2..m-1 do s+=(i-1)*(m-i) end\ns=2*s+m\n\nprint 2*(r*s+x*(m-1)**2)/m/m\n"}], "negative_code": [{"source_code": "#def f(n, r)\n# return 2 * r if n == 0\n# return 2 * n * r + (2 * r ** 2) ** 0.5\n#end\n\ndef g(n, r)\n return 0 if n == 0\n (r * (n + 1) + (2 * r ** 2) ** 0.5) * n\nend\n\nm, r = gets.chomp.split(' ').map { |x| x.to_i }\ntotal_sum = 0\nfor n in 1..m\n total_sum += g(n - 1, r) + g(m - n, r) + 2 * r\nend\n\nputs total_sum * 1.0 / m ** 2\n=begin\nif f(0, 1) != 2\n puts \"Error\"\n exit\nend\n\nif f(2, 1) != 4 * 1 + 2 ** 0.5 \n puts \"Error\"\n exit\nend\n\nif g(2, 1) != 4 * 1 + 2 ** 0.5 \n puts \"Error\"\n exit\nend\n=end\n"}, {"source_code": "def g(n, r)\n return 0 if n == 0\n (r * (n + 1) + (2 * r ** 2) ** 0.5) * n\nend\n\nm, r = gets.chomp.split(' ').map { |x| x.to_i }\ntotal_sum = 0.0\nfor n in 1..m\n total_sum += g(n - 1, r) + g(m - n, r) + 2 * r\nend\n\nputs total_sum / m ** 2\n"}, {"source_code": "m,r=gets.split.map(&:to_i)\nx=2**0.5*r\ns=0\nm.times{|i| s+=i*(m-i)}\ns=2*s+m if m > 1\np ((2*r*s+x*m*(m-1))/m/m).round(9)\n"}, {"source_code": "m,r=gets.split.map(&:to_i)\nx=2**0.5*r\ns=0\nm.times{|i| s+=i*(m-i)}\ns=2*s+m\n\nprint ((2*r*s+x*m*(m-1))/m/m)\n"}, {"source_code": "m,r=gets.split.map(&:to_i)\nx=2**0.5*r\ns=0\nm.times{|i| s+=i*(m-i)}\ns=2*s+m\n\nprint ((2*r*s+x*m*(m-1))/m.to_f/m.to_f)\n"}, {"source_code": "m,r=gets.split.map(&:to_i)\nx=2**0.5*r\ns=0\nm.times{|i| s+=i*(m-i)}\ns=2*s+m\np ((2*r*s+x*m*(m-1))/m/m).round(9)\n"}, {"source_code": "m,r=gets.split.map(&:to_i)\nx=2**0.5*r\ns=0\nm.times{|i| s+=i*(m-i)}\ns=2*s+m\n\np ((2*r*s+x*m*(m-1))/m/m)\n"}], "src_uid": "f827ea399e6b801c0392eac53710d950"} {"source_code": "N=STDIN.gets.strip.to_i\n(0..N-1).each do |i|\n s,t=STDIN.gets.strip.split\n if s s[mi[i]]\n s[i], s[mi[i]] = s[mi[i]], s[i]\n break\n end\n end\n puts (s < c ? s : '---')\n end\nend\n\nsolution\n"}, {"source_code": "def smallest(w)\n ary = w.chars\n ary_with_index = ary.each_with_index.sort\n ary_with_index.each_with_index do |(a, i), j|\n if i > j\n a = ary[i]\n _, i = ary_with_index.select { |(x, y)| x == a }.max_by { |x, y| y}\n ary[i], ary[j] = ary[j], ary[i]\n return ary.join('')\n end\n end\n ary.join('')\nend\n\nnb = gets.to_i\nnb.times do\n w1, w2 = gets.chomp.split\n w = smallest(w1)\n puts w < w2 ? w : '---'\nend\n\n"}], "negative_code": [{"source_code": "def smallest(w)\n ary = w.chars\n ary_with_index = ary.each_with_index.sort\n ary_with_index.each_with_index do |(a, i), j|\n if i > j\n ary[i], ary[j] = ary[j], ary[i]\n break\n end\n end\n ary.join('')\nend\n\nnb = gets.to_i\nnb.times do\n w1, w2 = gets.chomp.split\n w = smallest(w1)\n puts w < w2 ? w : '---'\nend"}, {"source_code": "def smallest(w)\n ary = w.chars\n ary_with_index = ary.each_with_index.sort\n ary_with_index.each_with_index do |(a, i), j|\n if i > j\n ary[i], ary[j] = ary[j], ary[i]\n return ary.join('')\n end\n end\n ary.join('')\nend\n\nnb = gets.to_i\nnb.times do\n w1, w2 = gets.chomp.split\n w = smallest(w1)\n puts w < w2 ? w : '---'\nend\n\n"}, {"source_code": "def smallest(w)\n ary = w.chars\n ary_with_index = ary.each_with_index.sort\n ary_with_index.each_with_index do |(a, i), j|\n if i > j\n ary[i], ary[j] = ary[j], ary[i]\n break\n end\n end\n ary.join('')\nend\n\nnb = gets.to_i\nnb.times do\n w1, w2 = gets.chomp.split\n w = smallest(w1)\n print w < w2 ? w : '---'\nend"}], "src_uid": "88743b7acb4a95dc0d5bb2e073714c49"} {"source_code": "n = gets.to_i;\nc = gets.split(' ').map(&:to_i);\nidx = (0..n-1).to_a.sort{|x, y|\n c[x] <=> c[y]\n}\na = Array.new(n); b = Array.new(n);\ncnt = (n+2)/3;\n\nn.times{|i|\n j = idx[i];\n if i < cnt\n a[j] = i; b[j] = c[j] - a[j];\n elsif i < 2*cnt\n b[j] = i; a[j] = c[j] - b[j];\n else\n b[j] = n - i - 1; a[j] = c[j] - b[j];\n end\n}\nputs \"YES\"\nputs a.map(&:to_s).join(' ')\nputs b.map(&:to_s).join(' ')\n\n", "positive_code": [{"source_code": "n = gets.to_i;\nc = gets.split(' ').map(&:to_i);\nidx = (0..n-1).to_a.sort{|x, y|\n c[x] <=> c[y]\n}\na = Array.new(n); b = Array.new(n);\ncnt = (n+2)/3;\n\nn.times{|i|\n j = idx[i];\n if i < cnt\n a[j] = i; b[j] = c[j] - a[j];\n elsif i < 2*cnt\n b[j] = i; a[j] = c[j] - b[j];\n else\n b[j] = n - i - 1; a[j] = c[j] - b[j];\n end\n}\nputs \"YES\"\nputs a.map(&:to_s).join(' ')\nputs b.map(&:to_s).join(' ')\n\n"}, {"source_code": "n = gets.to_i;\nc = gets.split(' ').map(&:to_i);\nidx = (0..n-1).to_a.sort{|x, y|\n c[x] <=> c[y]\n}\na = Array.new(n); b = Array.new(n);\ncnt = (n+2)/3;\n\nn.times{|i|\n j = idx[i];\n if i < cnt\n a[j] = i; b[j] = c[j] - a[j];\n elsif i < 2*cnt\n b[j] = i; a[j] = c[j] - b[j];\n else\n b[j] = n - i - 1; a[j] = c[j] - b[j];\n end\n}\nputs \"YES\"\nputs a.map(&:to_s).join(' ')\nputs b.map(&:to_s).join(' ')\n\n"}, {"source_code": "n = gets.to_i;\nc = gets.split(' ').map(&:to_i);\nidx = (0..n-1).to_a.sort{|x, y|\n c[x] <=> c[y]\n}\na = Array.new(n); b = Array.new(n);\ncnt = (n+2)/3;\n\nn.times{|i|\n j = idx[i];\n if i < cnt\n a[j] = i; b[j] = c[j] - a[j];\n elsif i < 2*cnt\n b[j] = i; a[j] = c[j] - b[j];\n else\n b[j] = n - i - 1; a[j] = c[j] - b[j];\n end\n}\nputs \"YES\"\nputs a.map(&:to_s).join(' ')\nputs b.map(&:to_s).join(' ')\n\n"}, {"source_code": "n = gets.to_i;\nc = gets.split(' ').map(&:to_i);\nidx = (0..n-1).to_a.sort{|x, y|\n c[x] <=> c[y]\n}\na = Array.new(n); b = Array.new(n);\ncnt = (n+2)/3;\n\nn.times{|i|\n j = idx[i];\n if i < cnt\n a[j] = i; b[j] = c[j] - a[j];\n elsif i < 2*cnt\n b[j] = i; a[j] = c[j] - b[j];\n else\n b[j] = n - i - 1; a[j] = c[j] - b[j];\n end\n}\nputs \"YES\"\nputs a.map(&:to_s).join(' ')\nputs b.map(&:to_s).join(' ')\n\n"}, {"source_code": "n = gets.to_i;\nc = gets.split(' ').map(&:to_i);\nidx = (0..n-1).to_a.sort{|x, y|\n c[x] <=> c[y]\n}\na = Array.new(n); b = Array.new(n);\ncnt = (n+2)/3;\n\nn.times{|i|\n j = idx[i];\n if i < cnt\n a[j] = i; b[j] = c[j] - a[j];\n elsif i < 2*cnt\n b[j] = i; a[j] = c[j] - b[j];\n else\n b[j] = n - i - 1; a[j] = c[j] - b[j];\n end\n}\nputs \"YES\"\nputs a.map(&:to_s).join(' ')\nputs b.map(&:to_s).join(' ')\n\n"}, {"source_code": "n = gets.to_i;\nc = gets.split(' ').map(&:to_i);\nidx = (0..n-1).to_a.sort{|x, y|\n c[x] <=> c[y]\n}\na = Array.new(n); b = Array.new(n);\ncnt = (n+2)/3;\n\nn.times{|i|\n j = idx[i];\n if i < cnt\n a[j] = i; b[j] = c[j] - a[j];\n elsif i < 2*cnt\n b[j] = i; a[j] = c[j] - b[j];\n else\n b[j] = n - i - 1; a[j] = c[j] - b[j];\n end\n}\nputs \"YES\"\nputs a.map(&:to_s).join(' ')\nputs b.map(&:to_s).join(' ')\n"}, {"source_code": "n = gets.to_i;\nc = gets.split(' ').map(&:to_i);\nidx = (0..n-1).to_a.sort{|x, y|\n c[x] <=> c[y]\n}\na = Array.new(n); b = Array.new(n);\ncnt = (n+2)/3;\n\nn.times{|i|\n j = idx[i];\n if i < cnt\n a[j] = i; b[j] = c[j] - a[j];\n elsif i < 2*cnt\n b[j] = i; a[j] = c[j] - b[j];\n else\n b[j] = n - i - 1; a[j] = c[j] - b[j];\n end\n}\nputs \"YES\"\nputs a.map(&:to_s).join(' ')\nputs b.map(&:to_s).join(' ')\n\n"}, {"source_code": "n = gets.to_i;\nc = gets.split(' ').map(&:to_i);\nidx = (0..n-1).to_a.sort{|x, y|\n c[x] <=> c[y]\n}\na = Array.new(n); b = Array.new(n);\ncnt = (n+2)/3;\n\nn.times{|i|\n j = idx[i];\n if i < cnt\n a[j] = i; b[j] = c[j] - a[j];\n elsif i < 2*cnt\n b[j] = i; a[j] = c[j] - b[j];\n else\n b[j] = n - i - 1; a[j] = c[j] - b[j];\n end\n}\nputs \"YES\"\nputs a.map(&:to_s).join(' ')\nputs b.map(&:to_s).join(' ')\n\n"}], "negative_code": [{"source_code": "n = gets.to_i;\nc = gets.split(' ').map(&:to_i);\nidx = (0..n-1).to_a.sort{|x, y|\n c[x] <=> c[y]\n}\na = Array.new(n); b = Array.new(n);\ncnt = (n+2)/3;\n\nn.times{|i|\n j = idx[i];\n if i < cnt\n a[j] = i; b[j] = c[j] - a[j];\n elsif i < 2*cnt\n b[j] = i; a[j] = c[j] - b[j];\n else\n b[j] = n - i; a[j] = c[j] - b[j];\n end\n}\nputs \"YES\"\nputs a.map(&:to_s).join(' ')\nputs b.map(&:to_s).join(' ')\n"}, {"source_code": "n = gets.to_i;\nc = gets.split(' ').map(&:to_i);\nidx = (0..n-1).to_a.sort{|x, y|\n c[x] <=> c[y]\n}\na = Array.new(n); b = Array.new(n);\ncnt = (n+2)/3;\n\nn.times{|i|\n j = idx[i];\n if i < cnt\n a[j] = i; b[j] = c[j] - a[j];\n elsif i < 2*cnt\n b[j] = i; a[j] = c[j] - b[j];\n else\n b[j] = n - i; a[j] = c[j] - b[j];\n end\n}\nputs a.map(&:to_s).join(' ')\nputs b.map(&:to_s).join(' ')\n"}], "src_uid": "fc97f05864c05950cd9acd9e03f4a729"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ncount = 0\nneg = 0\nfiles = Array.new\nfor i in a\n if i < 0 then neg += 1 end\n if neg == 3\n files << count\n count = 0\n neg = 1\n end\n count += 1\nend\nfiles << count\nputs files.count\nfiles.each {|x| print x, \" \"}", "positive_code": [{"source_code": "n = gets.to_i\nnums = gets.split.map{|i| i.to_i}\n\ni = 0\nfolder = []\nwhile i < n do\n folder << 1\n if nums[i] >= 0 then\n k = 0\n else\n k = 1\n end\n i += 1\n while k < 2 && i < n do\n folder[-1] += 1\n if nums[i] < 0 then\n k += 1\n end\n i += 1\n end\n while i < n && nums[i] >= 0 do\n folder[-1] += 1\n i += 1\n end\nend\n\nputs folder.size\nputs folder.join(\" \")"}, {"source_code": "e = []\nnn = 1\ngets\nns = gets.chomp.split.map{|a| Integer(a)}\nns.each.with_index{|x,i| if x < 0 then e.insert(-1,i+1) end }\ne=e.each_slice(2).map{|x| x.last}\nif e.length == 0 then\n puts [1,ns.length]\nelse\n puts e.length\n e[e.length-1]=ns.length\n e.insert(0,0)\n puts e[1..e.length-1].zip(e[0..e.length-2]).map{|a,b| a-b}.join(\" \")\nend"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nres=[]\nc=k=0\na.each do |v|\n c+=1\n k+=1 if v<0\n if k==2 then\n res.push(c)\n c=k=0\n end\nend\nif res.empty? then\n puts 1\n puts n\nelse\n if k > 0 then\n res.push(c)\n else\n res[res.size()-1]+=c\n end\n puts res.size\n puts res*' '\nend\n"}, {"source_code": "def main()\n\tn=gets.chomp.to_i;\n\tar=gets.chomp.split(\" \");\n\tar=ar.map{|i| i.to_i};\n\tnof=0;non=0;noeinf=[];\n\tnoe=0;\n\tfor i in 0...(ar.length)\n\t\tif ar[i]<0\n\t\t\tnon+=1\n\t\telse\n\t\t\tnoe+=1;\n\t\tend\n\t\tif non==3\n\t\t\tnoeinf << noe+2;\n\t\t\tnof+=1;\n\t\t\tnon=1;\n\t\t\tnoe=0;\n\t\tend\n\tend\n\tif non>0 || noe >0\n\t\tnof+=1;\n\t\tnoeinf << (non+noe);\n\tend \n\tputs nof;\n\tputs noeinf.join(\" \")\nend\nmain()"}, {"source_code": "n=readline.to_i\na=gets.chomp.split.map{|i| i.to_i}\ncounter=0\nnum=0\nres=[]\n\na.each do |i|\nif i<0 then\n counter=counter+1\nend\nif counter==3 then\n res.push num\n num=0\ncounter=1\nend\nnum=num+1\nend\n\nif num>0\n res.push num\nend\n\nputs res.size\nres.each do |i|\n print i.to_s+' '\nend\nprint \"\\n\"\n"}, {"source_code": "n=gets.to_i\na=gets.split.collect{|e| e.to_i}\nb=[]\nk=0\nl=0\nfor i in 0..n-1 do\n l+=1\n if (a[i]<0) then \n if (k==2) then\n b<0 || noe >0\n\t\tnof+=1;\n\t\tnoeinf << (non+noe);\n\tend \n\tputs nof;\n\tputs noeinf.join(\" \")\nend\nmain()"}, {"source_code": "def main()\n\tn=gets.chomp.to_i;\n\tar=gets.chomp.split(\" \");\n\tar=ar.map{|i| i.to_i};\n\tnof=0;non=0;noeinf=[];\n\tnoe=0;\n\tfor i in 0...(ar.length)\n\t\tif ar[i]<0\n\t\t\tnon+=1\n\t\telse\n\t\t\tnoe+=1;\n\t\tend\n\t\tif non==2 && noe>=1\n\t\t\tnoeinf << noe+non;\n\t\t\tnof+=1;\n\t\t\tnon=0;\n\t\t\tnoe=0;\n\t\tend\n\tend\n\tif non>0 || noe >0\n\t\tnof+=1;\n\t\tnoeinf << (non+noe);\n\tend \n\tputs nof;\n\tputs noeinf.join(\" \")\nend\nmain()"}, {"source_code": "def main()\n\tn=gets.chomp.to_i;\n\tar=gets.chomp.split(\" \");\n\tar=ar.map{|i| i.to_i};\n\tar=ar.sort\n\tnof=0;non=0;noeinf=[];\n\tfor i in 0...(ar.length)\n\t\tif ar[i]<0\n\t\t\tnon+=1\n\t\telse\n\t\t\tnof+=1;\n\t\t\tnoef=(ar.length)-i;\n\t\t\tnoeinf << noef+non;\n \t\t\tbreak;\n\t\tend\n\t\tif non==3\n\t\t\tnon=0;\n\t\t\tnof+=1;\n\t\t\tnoeinf << 3;\n\t\tend\n\tend\n\tputs nof;\n\tputs noeinf.join(\" \")\nend\nmain()"}, {"source_code": "def main()\n\tn=gets.chomp.to_i;\n\tar=gets.chomp.split(\" \");\n\tar=ar.map{|i| i.to_i};\n\tar=ar.sort\n\tnof=0;non=0;noeinf=[];\n\tfor i in 0...(ar.length)\n\t\tif ar[i]<0\n\t\t\tnon+=1\n\t\telse\n\t\t\tnof+=1;\n\t\t\tnoef=(ar.length)-i;\n\t\t\tnoeinf << noef+non;\n \t\t\tbreak;\n\t\tend\n\t\tif non==3\n\t\t\tnon=0;\n\t\t\tnof+=1;\n\t\t\tnoeinf << 3;\n\t\tend\n\tend\n\tputs nof;\n\tnoeinf=noeinf.sort\n\tputs noeinf.join(\" \")\nend\nmain()"}, {"source_code": "def main()\n\tn=gets.chomp.to_i;\n\tar=gets.chomp.split(\" \");\n\tar=ar.map{|i| i.to_i};\n\tnof=0;non=0;noeinf=[];\n\tnoe=0;\n\tfor i in 0...(ar.length)\n\t\tif ar[i]<0\n\t\t\tnon+=1\n\t\telse\n\t\t\tnoe+=1;\n\t\tend\n\t\tif non==2\n\t\t\tnoeinf << noe+non;\n\t\t\tnof+=1;\n\t\t\tnon=0;\n\t\t\tnoe=0;\n\t\tend\n\tend\n\tif non>0 || noe >0\n\t\tnof+=1;\n\t\tnoeinf << (non+noe);\n\tend \n\tputs nof;\n\tputs noeinf.join(\" \")\nend\nmain()"}], "src_uid": "3f320920a023c3bc10ba1525e8c89044"} {"source_code": "gets.to_i.times do\r\n s = gets.chomp\r\n puts s.chars.chunk { |a| a }.map(&:last).map(&:size).min == 1 ? \"NO\" : \"YES\"\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\n s = gets.chomp.split('')\n c = 1\n flag = true\n 1.upto(s.size-1) do |i|\n if s[i]==s[i-1] then\n c += 1\n else\n flag = false if c < 2\n c = 1\n end\n end\n flag = false if c < 2\n puts flag ? \"YES\":\"NO\"\nend\n"}], "negative_code": [], "src_uid": "e95e2d21777c1d686bede1b0a5dacbf5"} {"source_code": "n = gets.to_f\nx = Math.log(n,2)\n\ncount = 0\nexpon = 0\ncurr = 2**expon\n\n\nminicount = 0\n\nwhile (count < n-2)\n print \"#{curr} \"\n count += 1\n minicount += 1\n if minicount == (n/(curr*2)).round(0)\n minicount = 0\n expon += 1\n curr = 2**expon\n end\nend \n\nthisthing = 2**((x.floor)-1)\nif n==1\n puts 1\n exit\nend\nprint \"#{thisthing} \"\nputs \"#{(n.to_i/thisthing)*thisthing}\"\n", "positive_code": [{"source_code": "# require 'prime'\n\ndef gcd(a, b)\n (b==0 ? a : gcd(b, a%b))\nend\n\ndef arygcd(ary)\n ans = ary[0]\n ary.each do |x|\n ans = gcd(ans, x)\n end\n ans\nend\n\nn = gets.to_i\n\ndef solve(ary)\n n = ary.size\n if n==1\n return [1]\n elsif n==2\n return [1, 2]\n elsif n==3\n return [1, 1, 3]\n end \n ans = []\n nary = []\n ary.each do |x|\n if x%2 != 0\n ans << 1\n else\n nary << x/2\n end\n end\n solve(nary).each do |x|\n ans << 2*x\n end\n ans\nend\n\nary = (1..n).to_a\nputs solve(ary).join(\" \")"}, {"source_code": "n = gets.to_i\nif n == 1\n puts 1\n exit\nend\nans = []\nt = Math.log2(n).floor-1\n\nt.times do |i|\n ans += [2**i]*((n/(2**i))-(n/(2**(i+1))))\nend\n\nif n/(2**t) == 3\n ans << 2**t << 2**t << 3*2**t\nelse\n ans << 2**t << 2*2**t\nend\n\nputs ans.join(\" \")\n"}], "negative_code": [{"source_code": "n = gets.to_f\nx = Math.log(n,2)\n\ncount = 0\nexpon = 0\ncurr = 2**expon\n\n\nminicount = 0\n\nwhile (count < n-2)\n print \"#{curr} \"\n count += 1\n minicount += 1\n if minicount == (n/(curr*2)).round(0)\n minicount = 0\n expon += 1\n curr = 2**expon\n end\nend \n\nthisthing = 2**((x.floor)-1)\nif n==1\n exit\nend\nprint \"#{thisthing} \"\nputs \"#{(n.to_i/thisthing)*thisthing}\"\n"}], "src_uid": "cadff0864835854f4f1e0234f2fd3edf"} {"source_code": "$\\ = \"\\n\"\r\ngets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n s = a.sum\r\n if s < n\r\n print 1\r\n else\r\n print s - n\r\n end\r\nend", "positive_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n s = a.sum\r\n puts s < n ? 1 : s - n\r\nend"}, {"source_code": "t = Integer(gets.chomp)\r\nt.times{\r\n n = Integer(gets.chomp)\r\n a = gets.chomp.split().map!{|c| Integer(c)}\r\n \r\n som = a.sum()\r\n len = a.size()\r\n \r\n if(som < len)\r\n puts 1\r\n elsif(som == len)\r\n puts 0\r\n else\r\n puts som - len\r\n end\r\n}"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n s = a.sum\r\n if s < n\r\n puts 1\r\n else\r\n puts s - n\r\n end\r\nend"}], "negative_code": [], "src_uid": "b5985b619652e606ac96554ecfb9346a"} {"source_code": "k=gets.split[1].to_i\np gets.split.count{|x| x.count('47')<=k}\n\n", "positive_code": [{"source_code": "n,k=gets.split.map {|i| i.to_i}\n\na=gets.split.map {|i| i.to_i}\n\na.select! do |i|\n i.to_s.scan(/[47]/).length <=k\nend\n\nputs a.length"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i)\na.select! {|i| i.to_s.scan(/[47]/).length <=k}\nputs a.length"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs gets.split.count{|x| x.count('47') <= k}\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:chars)\nputs a.count{|x| x.count('4') + x.count('7') <= k}\n"}, {"source_code": "a=gets.chomp.split(\" \")\nb=gets.chomp.split(\" \")\nans=0\nmax=a[1].to_i\nb.each do |i|\nif i.count(\"4\")+i.count(\"7\")<=max\nans+=1\nend\nend\nputs \"#{ans}\""}, {"source_code": "k=gets.split[1].to_i\np gets.split.count{|x| x.count('47')<=k}"}, {"source_code": "n, k = gets.split.map &:to_i\na = gets.split.map &:to_i\nputs a.inject(0) { |s, x| x.to_s.split('').select { |d| d == '4' || d == '7'}.size <= k ? s + 1 : s }\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\np gets.split.map{|x| x.scan(/4|7/).size<=k ? 1 : 0}.reduce(:+)"}, {"source_code": "n, k = gets.split.map(&:to_i)\np gets.split.map { |x|\n x.count('4') + x.count('7') <= k ? 1 : 0\n}.reduce(:+)\n"}, {"source_code": "k=gets.split[1].to_i\np gets.split.count{|x| x.count('47')<=k}\n"}, {"source_code": "def is_lucky?(n, k)\n while n > 0 do\n k-=1 if n%10 == 4 || n%10 == 7\n n/=10\n end\n k < 0 ? false : true\nend\n\nn, k = gets.split.map &:to_i\na = gets.split.map &:to_i\ncounter = 0\na.each {|el| counter += 1 if is_lucky?(el, k) }\n\nputs counter"}, {"source_code": "k=gets.split[1].to_i\np gets.split.count{|x| x.count('47')<=k}\n\n"}, {"source_code": "n, k = gets.chomp.split.map { |x| x.to_i }\na = gets.chomp.split\ncount = 0\nfor i in 0...n\n count += 1 if a[i].scan(/4|7/).count <= k\nend\nputs count"}, {"source_code": "k=gets.split[1].to_i\np gets.split.count{|x| x.count('47')<=k}\n\n"}, {"source_code": "BEGIN{\n\tdef get_line_int()\n\t\treturn gets.split.map(&:to_i)\n\tend\n\tdef count(x)\n\t\tcc = 0\n\t\tx.to_s.each_char do |c|\n\t\t\tif c == \"4\" or c == \"7\" then\n\t\t\t\tcc += 1\n\t\t\tend\n\t\tend\n\t\treturn cc\n\tend\n\tdef main()\n\t\tn, k = get_line_int\n\t\ta = get_line_int\n\t\tcc = 0\n\t\ta.each do |i|\n\t\t\tif count(i) <= k then\n\t\t\t\tcc += 1\n\t\t\tend\n\t\tend\n\t\tputs cc\n\tend\n\tTest_case = 1\n\tTest_case.times do\n\t\tmain()\n\tend\n}\n"}, {"source_code": "a = gets.split(\" \").collect{|x| x.to_i}\nn = a[0]\nk = a[1]\n\na = gets.split(\" \").collect{|x| x.to_i}\nresult = 0\n\na.each{|x| \n\tc = 0\n\twhile x > 0\n\t\tt = x % 10\n\t\tx /= 10\n\t\tif t == 4 || t == 7\n\t\t\tc += 1\n\t\tend\t\t\n\tend\n\tif c <= k\n\t\tresult += 1\n\tend\n}\n\nputs result"}, {"source_code": "k=gets.split[1].to_i\np gets.split.count{|x| x.count('47')<=k}\n\n"}, {"source_code": "n,k=gets.split.map{|s|s.to_i}\na=gets.split.map{|s|s.to_i}\nr=0\nn.times do |i|\n j=0\n while a[i] > 0 do\n j+=1 if [4,7].include?(a[i]%10)\n a[i] /= 10\n end\n r+=1 if j <= k\nend\nputs r\n"}, {"source_code": "n, k = gets.split(' ').map(&:to_i)\nputs gets.chomp.split(' ',n).map{|x| x.scan(/[47]/).count}.select{|x| x<=k}.count\n"}, {"source_code": "st = gets.split\nn = st[0].to_i\nk = st[1].to_i\n\nst = gets.split\nresult = 0\nn.times do |i|\n x = st[i].count(\"4\")\n y = st[i].count(\"7\")\n if x + y <= k then\n result += 1\n end\nend\n\nputs result"}, {"source_code": "k=gets.split[1].to_i\np gets.split.count{|x| x.count('47')<=k}\n\n"}, {"source_code": " n,k=gets.split.map(&:to_i)\n a=gets.split.map(&:to_s)\n ans=0\n a.each do |ch|\n\tg=0\n\tfor i in 0...ch.size do\n\t\tg+=1 if ch[i]=='4' or ch[i]=='7'\n\tend\n\tans+=1 if g<=k\n end\n puts ans\n\t\n\t\n\t\n"}, {"source_code": "k = gets.split[1].to_i\nputs gets.split.count{|a| a.count('47') <= k}"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\n\nn, k = gets.chomp.split(\" \").map{|n| n.to_i}\ndigits = gets.chomp.split(\" \")\n\nc = 0\n\ndigits.each do |a|\n c+=1 if a.count(\"4\") + a.count(\"7\") <= k\nend\n\nputs c\n\n"}, {"source_code": "k=gets.split[1].to_i\np gets.split.count{|x| x.count('47')<=k}\n\n"}, {"source_code": "n, k = STDIN.readline.split.map {|s| s.to_i }\nss = STDIN.readline.split\ncount = 0\nss.each do |s|\n\tcount += 1 if s.count('4') + s.count('7') <= k\nend\nputs count\n"}, {"source_code": "k=gets.split[1].to_i\np gets.split.count{|x| x.count('47')<=k}\n"}, {"source_code": "n,k=gets.chomp.split(' ').map(&:to_i)\nsum=n\n#puts sum\na=gets.chomp.split(' ').map(&:to_s)\nfor i in a do\n\tcount=0\n\tj=i.split('')\n\tj.each do |x|\n\t\tif x=='4' || x=='7'\n\t\t\tcount+=1\n\t\tend\n\tend\n\tif count>k\n\t\tsum-=1\n\tend\nend\nputs sum"}, {"source_code": "n,k = gets.split.map(&:to_i)\na = gets.split.map(&:to_s)\n\na.each do |x|\n counter = 0\n x.split(//).each do |t|\n counter+=1 if t == \"4\" || t == \"7\"\n end\n n-=1 if counter>k\nend\nputs n\n"}, {"source_code": "\n\nn,k = gets.chomp.split(\" \").collect! {|x| x.to_i}\nline = gets.chomp.split(\" \")\ns = 0\nline.each {|w|\n n = 0\n w.split(\"\").each {|t|\n if t ==\"4\" or t==\"7\"\n n+=1\n end\n }\n if n<=k\n s +=1\n end\n}\n\nputs s"}, {"source_code": "n,k = gets.split.map(&:to_i)\na = gets.chomp.split.map(&:to_s)\n\na.each do |x|\n counter = 0\n x.split(\"\").each do |t|\n counter+=1 if t == \"4\" || t == \"7\"\n end\n n-=1 if counter>k\nend\nputs n\n"}, {"source_code": "n,k = gets.split.map(&:to_i)\na = gets.chomp.split(' ')\n\na.each {|x|\n counter = 0\n x.split(\"\").each {|t|\n counter+=1 if t == \"4\" || t == \"7\"\n }\n n-=1 if counter>k\n}\nputs n\n"}, {"source_code": "n,k = gets.split.map(&:to_i)\na = gets.chomp.split(' ')\n\na.each do |x|\n counter = 0\n x.split(\"\").each do |t|\n counter+=1 if t == \"4\" || t == \"7\"\n end\n n-=1 if counter>k\nend\nputs n\n"}, {"source_code": "def run\n lines = ARGF.readlines\n\n while lines.length > 0\n ret = 0\n\n n, k = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n vals = lines.shift.chomp.split(\" \")\n\n vals.each do |val|\n cnt = 0\n val.split(//).each do |c|\n cnt += 1 if c == '4' || c == '7'\n end\n\n ret += 1 if cnt <= k\n end\n\n puts ret\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "k=gets.split[1].to_i\np gets.split.count{|x| x.count('47')<=k}\n\n"}, {"source_code": "a=gets.chomp.split(\" \")\nb=gets.chomp.split(\" \")\nans=0\nmax=a[1].to_i\nb.each do |i|\nif i.count(\"4\")+i.count(\"7\")<=max\nans+=1\nend\nend\nputs \"#{ans}\"\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nas = gets.split\n\nans = 0\nas.each do |a|\n if a.count('4') + a.count('7') <= k\n ans += 1\n end\nend\n\nputs ans"}, {"source_code": "n, k = gets.chomp.split(/ /).map(&:to_i)\nlist = gets.chomp.split(/ /)\nans = 0\nlist.each do |num|\n lucky_digits = 0\n num.each_char do |d|\n lucky_digits += 1 if d == '4' || d == '7'\n end\n ans += 1 if lucky_digits <= k\nend\nputs ans\n"}, {"source_code": "a=gets.chomp.split(\" \")\nb=gets.chomp.split(\" \")\nans=0\nmax=a[1].to_i\nb.each do |i|\nif i.count(\"4\")+i.count(\"7\")<=max\nans+=1\nend\nend\nputs \"#{ans}\""}, {"source_code": "n,k=gets.split.map{|e| e.to_i}\nx=gets.split\nans=0\nx.each{|e|\n\tc1=e.chars.count{|e2|\n\t\t\te2==\"4\" || e2==\"7\"\n\t}\n\tans+=1 if c1<=k\n}\nputs ans\n\n"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\ndef nice( number, k )\n count = 0\n number.to_s.split(//).each{|c|\n count+=1 if c == \"4\" || c == \"7\"\n }\n count <= k\nend\n\nn, k = gets.split.map &:to_i\nnums = gets.split.map &:to_i\n\nans = 0\nnums.each{|v|\n ans+=1 if nice v, k\n}\n\nprint ans"}, {"source_code": "k=gets.split[1].to_i\np gets.split.count{|x| x.count('47')<=k}\n\n"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \")\ncount = 0\narr.each { |e| \n\tcount += 1 if e.scan(/[47]/).length <= k\n}\nputs count"}, {"source_code": "a=gets.split.map &:to_i;b=gets.split.map &:to_i;k=0;a[0].times{|x|b[x].to_s.count('4')+b[x].to_s.count('7')<=a[1] ?(k+=1):(0)};puts k"}, {"source_code": "n,k = gets.chomp.split(\" \").collect! {|x| x.to_i}\nline = gets.chomp.split(\" \")\ns = 0\nline.each {|w|\n n = 0\n\tw.split(\"\").each {|t|\n\t if t ==\"4\" or t==\"7\"\n\t\tn+=1\n\t end\n\t}\n\tif n<=k\n\t\ts +=1\n\tend\n}\n\nputs s"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.select {|i| i.scan(/[47]/).length <=k}\nputs a.length"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.select {|i| i.to_s.scan(/[47]/).length <=k}\nputs a.length"}], "negative_code": [{"source_code": " n,k=gets.split.map(&:to_i)\n a=gets.split.map(&:to_s)\n ans=0\n a.each do |ch|\n\tg=0\n\tfor i in 0...ch.size do\n\t\tg+=1 if ch[i]==4 or ch[i]==7\n\tend\n\tans+=1 if g<=k\n end\n puts ans\n\t\n\t\n\t\n"}, {"source_code": "n, k = gets.chomp.split(/ /).map(&:to_i)\nlist = gets.chomp.split(/ /)\nans = 0\nlist.each do |num|\n ans += 1 if num.length <= k\nend\nputs ans\n"}], "src_uid": "6bb26991c9ea70e51a6bda5653de8131"} {"source_code": "k = gets.strip.to_i\nd = gets.strip.split.map(&:to_i)\nans = []\ncnt = []\nd.each do |i|\n if i == 0\n cnt[0] = 1\n next\n end\n if i == 100\n cnt[1] = 1\n next\n end\n if i % 10 == 0\n cnt[2] = i\n next\n end\n if i < 10\n cnt[3] = i\n next\n end\n cnt[4] = i\nend\nans << 0 if !cnt[0].nil?\nans << 100 if !cnt[1].nil?\nans << cnt[2] if !cnt[2].nil?\nans << cnt[3] if !cnt[3].nil?\nans << cnt[4] if !cnt[4].nil? && cnt[3].nil? && cnt[2].nil?\nputs ans.length\nputs ans.sort.join(\" \")\n", "positive_code": [{"source_code": "n=gets.to_i\na=gets.chomp.split.map(&:to_i)\nb,c=[],[nil,nil,nil,nil,nil]\n\na.each do |i|\n\tif i==0\n\t\tc[0]=1\n\telsif i==100\n\t\tc[1]=1\n\telsif i%10==0\n\t\tc[2]=i\n\telsif i<10\n\t\tc[3]=i\n\telse\n\t\tc[4]=i\n\tend\nend\nb<<0 if c[0]\nb<<100 if c[1]\nb< 0 && a <= 9\n\t\tone = a \n\telsif !two && a < 100 && (a % 10) == 0\t\t\n\t\ttwo = a\n\telsif !three && a == 100\n\t\tthree = a\n\tend\nend\nres = [zero,one,two,three].compact\nif res.empty?\n\tres = [arr.first]\nelsif !one && !two\n\t val = arr.detect{|a| a.to_s.length == 2}\n\t res << val if val\nend\n\n\nputs res.count\nputs res.join(' ')"}, {"source_code": "def get_bucket n\n s = 0\n if n%10 != 0\n s += 1\n end\n if (n/10)%10 != 0\n s = s + 2\n end\n if n==100\n s = 4\n end\n return s\nend\n\nk = gets.to_i\nb = [0]*5\nnn = [-1]*5\narr = gets.chomp.split(' ').collect {|x| x.to_i}\narr.each { |v|\n b[get_bucket(v)] = 1\n nn[get_bucket(v)] = v\n}\n\nm1 = b[0] + b[1] + b[2] + b[4]\nm2 = b[3] + b[4] + b[0]\n\nputs [m1,m2].max\n\nif m1 > m2\n r = nn[0..2] + [nn[4]]\nelse\n r = nn[3..4] + [nn[0]]\nend\n\nputs r.keep_if {|x| x!=-1}.join \" \"\n\n\n"}, {"source_code": "# 305A\n# What a retarded task statement! Nothing can be understood...\n\ngets\na = gets.chomp.split\n\nr = []\nq = a.find { |t| t == '0' }\nr << q if q\nw = a.find { |t| t == '100' }\nr << w if w\nz = a.find { |t| t.size == 1 && t != '0' }\nr << z if z\nx = a.find { |t| t.size == 2 && t[1] == '0' }\nr << x if x\nunless z || x\n y = a.find { |t| t.size == 2 }\n r << y if y\nend\n\nputs r.size\nputs r * ' ' unless r.empty?"}, {"source_code": "ans=[]\nrest=[]\nmultiple10=false\none_digit=false\nk=gets.to_i\nd=gets.split.map(&:to_i)\nd.each{|num|\n if num==0\n \tans< 0\n\tif one > 0\n\t\tresult.push(one)\n\t\tif ten > 0\n\t\t\tresult.push(ten)\n\t\tend\n\telsif ten > 0\n\t\tresult.push(ten)\n\telse\n\t\tresult.push(double)\n\tend\nend\nif hundred > 0\n\tresult.push(100)\nend\n\nputs result.length\nputs result.join(' ')\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby1.9\n\nzeros = 10.times.collect { false }\nn = STDIN.readline.to_i\nnums = STDIN.readline.split.collect {|s| s.to_i }\n\nresult = [nums.shift]\nnums.each do |num|\n\ta = num\n\tokay = true\n\tresult.each do |b|\n\t\twhile a != 0 and b != 0\n\t\t\tif a%10 != 0 and b%10 != 0\n\t\t\t\tbreak\n\t\t\tend\n\t\t\ta /= 10\n\t\t\tb /= 10\n\t\tend\n\t\tif a != 0 and b != 0\n\t\t\tokay = false\n\t\t\tbreak\n\t\tend\n\tend\n\tif okay\n\t\tresult.push(num)\n\tend\nend\n\nputs result.length\nputs result.join(' ')\n\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split.map(&:to_i)\nb,c=[],[nil,nil,nil,nil,nil]\n\na.each do |i|\n\tif i==0\n\t\tc[0]=1\n\telsif i==100\n\t\tc[1]=1\n\telsif i%10==0\n\t\tc[2]=i\n\telsif i<10\n\t\tc[3]=i\n\telse\n\t\tc[4]=i\n\tend\nend\nb<<0 if c[0]\nb<<100 if c[1]\nb< 0 && a <= 9\n\t\tone = a \n\telsif !two && a < 100 && (a % 10) == 0\t\t\n\t\ttwo = a\n\telsif !three && a == 100\n\t\tthree = a\n\tend\nend\nres = [zero,one,two,three].compact\n\nputs res.count\nputs res.join(' ')"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nzero = nil\none = nil\ntwo = nil\nthree = nil\n\narr.each do |a|\n\tif !zero && a == 0\n\t\tzero = a \t\t\n\telsif !one && a > 0 && a <= 9\n\t\tone = a \n\telsif !two && a < 100 && (a % 10) == 0\t\t\n\t\ttwo = a\n\telsif !three && a == 100\n\t\tthree = a\n\tend\nend\nres = [zero,one,two,three].compact\nif res.empty?\n\tres = [arr.first]\nend\n\nputs res.count\nputs res.join(' ')"}, {"source_code": "# 305A\n\ngets\na = gets.chomp.split\nif a.size == 1\n puts 1\n puts a * ' '\n exit\nend\nr = []\nz = a.find { |t| t.size == 1 && t != '0' }\nr << z if z\nn = a.find { |t| t == '0' }\nr << n if n\nu = a.find { |t| t =~ /^\\d0$/ }\nr << u if u\nn = a.find { |t| t == '100' }\nr << n if n\nif n && z && !u\n u = a.find { |t| t.size == 2 }\n r << u if u\nend\n\nif r.empty?\n r << a[0]\nend\nputs r.size\nputs r * ' ' unless r.empty?"}, {"source_code": "# 305A\n\ngets\na = gets.chomp.split\nr = []\nn = a.find { |t| t.size == 1 && t != '0' }\nr << n if n\nn = a.find { |t| t == '0' }\nr << n if n\nn = a.find { |t| t =~ /^\\d0$/ }\nr << n if n\nn = a.find { |t| t == '100' }\nr << n if n\n\nputs r.size\nputs r * ' ' unless r.empty?"}, {"source_code": "# 305A\n\ngets\na = gets.chomp.split\nif a.size == 1\n puts 1\n puts a * ' '\n exit\nend\nr = []\nn = a.find { |t| t.size == 1 && t != '0' }\nr << n if n\nn = a.find { |t| t == '0' }\nr << n if n\nu = a.find { |t| t =~ /^\\d0$/ }\nr << u if u\nn = a.find { |t| t == '100' }\nr << n if n\nif n && !u\n u = a.find { |t| t.size == 2 }\n r << u if u\nend\n\nif r.empty?\n r << a[0]\nend\nputs r.size\nputs r * ' ' unless r.empty?"}, {"source_code": "# 305A\n\ngets\na = gets.chomp.split\nif a.size == 1\n puts 1\n puts a * ' '\nend\nr = []\nn = a.find { |t| t.size == 1 && t != '0' }\nr << n if n\nn = a.find { |t| t == '0' }\nr << n if n\nn = a.find { |t| t =~ /^\\d0$/ }\nr << n if n\nn = a.find { |t| t == '100' }\nr << n if n\n\nputs r.size\nputs r * ' ' unless r.empty?"}, {"source_code": "# 305A\n\ngets\na = gets.chomp.split\nif a.size == 1\n puts 1\n puts a * ' '\n exit\nend\nr = []\nn = a.find { |t| t.size == 1 && t != '0' }\nr << n if n\nn = a.find { |t| t == '0' }\nr << n if n\nn = a.find { |t| t =~ /^\\d0$/ }\nr << n if n\nn = a.find { |t| t == '100' }\nr << n if n\n\nif r.empty?\n r << a[0]\nend\nputs r.size\nputs r * ' ' unless r.empty?"}, {"source_code": "# 305A\n\ngets\na = gets.chomp.split\nif a.size == 1\n puts 1\n puts a * ' '\n exit\nend\nr = []\nz = a.find { |t| t.size == 1 && t != '0' }\nr << z if z\nw = a.find { |t| t == '0' }\nr << w if w\nu = a.find { |t| t =~ /^\\d0$/ }\nr << u if u\nn = a.find { |t| t == '100' }\nr << n if n\nif (n && w && !u) || r == ['0']\n u = a.find { |t| t.size == 2 }\n r << u if u\nend\n\n\nif r.empty?\n r << a[0]\nend\nputs r.size\nputs r * ' ' unless r.empty?"}, {"source_code": "# 305A\n\ngets\na = gets.chomp.split\nif a.size == 1\n puts 1\n puts a * ' '\n exit\nend\nr = []\nz = a.find { |t| t.size == 1 && t != '0' }\nr << z if z\nw = a.find { |t| t == '0' }\nr << w if w\nu = a.find { |t| t =~ /^\\d0$/ }\nr << u if u\nn = a.find { |t| t == '100' }\nr << n if n\nif n && w && !u\n u = a.find { |t| t.size == 2 }\n r << u if u\nend\n\nif r.empty?\n r << a[0]\nend\nputs r.size\nputs r * ' ' unless r.empty?"}, {"source_code": "# 305A\n\ngets\na = gets.chomp.split\nif a.size == 1\n puts 1\n puts a * ' '\n exit\nend\nr = []\nn = a.find { |t| t.size == 1 && t != '0' }\nr << n if n\nn = a.find { |t| t == '0' }\nr << n if n\nn = a.find { |t| t =~ /^\\d0$/ }\nr << n if n\nn = a.find { |t| t == '100' }\nr << n if n\n\nputs r.size\nputs r * ' ' unless r.empty?"}, {"source_code": "# 305A\n\ngets\na, b = gets.chomp.split.partition { |token| token.include? '0' }\nif a.empty?\n puts 0\nelse\n a << b[0] unless b.empty?\n puts a.size\n puts a * ' '\nend"}, {"source_code": "ans=[]\ndiff=[]\nk=gets.to_i\nd=gets.split.map(&:to_i)\nd.each{|num|\n if num.to_s.count(?0)>0\n ans<0\n ans<1\nloop do\nif a[i..i+b-1]!=a[i..i+b-1].reverse\ntr=1\nbreak\nelse\ni+=b\nend\nbreak if i==l\nend\nend\n\nif tr==1\nputs \"NO\"\nelse\nputs \"YES\"\nend\nend\n", "positive_code": [{"source_code": "#!ruby\n\ns = gets.chomp\nk = gets.chomp.to_i\n\nul = s.length/k\nif ul*k != s.length\n puts \"NO\"\n exit\nend\n\n0.upto(k-1) do |i|\n ss = s[ul*i..ul*(i+1)-1]\n if ss != ss.reverse\n puts \"NO\"\n exit\n end\nend\nputs \"YES\"\nexit\n"}, {"source_code": "#!/usr/bin/env ruby\ns=gets.chomp\nk=gets.to_i\nputs s.size%k==0 && k.times.all?{|i|t=s[s.size/k*i,s.size/k];t==t.reverse} ? :YES : :NO"}, {"source_code": "#!/usr/bin/env ruby\ns=gets.chomp\nk=gets.to_i\nputs s.size%k==0 && k.times.all?{|i|t=s[s.size/k*i,s.size/k];t==t.reverse} ? :YES : :NO"}, {"source_code": "# http://codeforces.com/contest/548/problem/A\ndef palindrome?(a)\n a == a.reverse\nend\n\ndef valid?(chars, k)\n return false if chars.length % k != 0\n\n messages = chars.each_slice(chars.length / k).to_a\n messages.all? { |m| palindrome?(m) }\nend\n\nchars = gets.chomp.chars\nk = gets.chomp.to_i\n\nputs valid?(chars, k) ? \"YES\" : \"NO\"\n"}, {"source_code": "s = gets.chomp.chars\nk = gets.to_i\nif s.size % k == 0\n ans = s.each_slice(s.size / k).all?{|x| x == x.reverse}\nelse\n ans = false\nend\nputs ans ? 'YES' : 'NO'\n"}, {"source_code": "def valid_fax(fax, num_pals)\n\n word_len = fax.size / num_pals\n \n ans = false\n if fax.size % num_pals == 0\n ans = fax.each_slice(word_len).all? { |wrd| wrd == wrd.reverse }\n end\n ans\nend\n\n\nwords = gets().chomp.chars\nlen = gets().strip\nif valid_fax(words,len.to_i) == true\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\nstr = gets.chomp;\nn = gets.to_i;\nans = false;\nans = str.chars.each_slice(str.length / n).all?{|x| x == x.reverse} if (str.length % n == 0);\nputs ans ? \"YES\\n\":\"NO\\n\";\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# a.rb\n\ndef is_palindrome(s)\n s.size.times do |i|\n return false if s[i] != s[s.size - i - 1]\n end\n return true\nend\n\ndef ok(s, k)\n return false if s.size % k != 0\n n = s.size / k\n k.times do |i|\n return false if !is_palindrome(s[n * i, n])\n end\n return true\nend\n\ndef main()\n s = gets.chomp\n k = gets.to_i\n \n puts ok(s, k) ? \"YES\" : \"NO\"\nend\n\n\nif __FILE__ == $0 then\n main()\nend\n"}, {"source_code": "s = gets.chomp\nk = gets.to_i\nif s.size%k != 0\n puts \"NO\"\n exit\nend\nlen = s.size/k\n(0...s.size).step(len).each do |i|\n if s[i,len] != s[i,len].reverse\n puts \"NO\"\n exit\n end \nend\nputs \"YES\"\n"}, {"source_code": "string = gets.chomp\nk = gets.chomp.to_i\nflag = true\n\ndef palindrome?(str)\n\tstr == str.reverse\nend\n\nparts = []\nnowStart = 0\n\nuntil parts.length == k - 1\n\tparts << string.slice(nowStart, string.length / k)\n\tnowStart += string.length / k\n\n\t#puts nowStart\nend\n\nparts << string.slice(nowStart, string.length - nowStart)\n\n=begin\nparts.each do |partString|\n\tputs \"partString : #{partString}\"\nend\n=end\n\nparts.each do |partString|\n\tflag = false if !palindrome?(partString)\n\tflag = false if partString.length != string.length / k\nend\n\nputs \"YES\" if flag\nputs \"NO\" if !flag"}, {"source_code": "s = gets.chomp.chars\nk = gets.to_i\na = []\nvalid = false\ns.size.times do |i|\n a << s[i]\n if a == a.reverse\n start = a.size\n c = 1\n valid = true\n (k - 1).times do\n t = s[start...start + a.size]\n if start + a.size > s.size || t != t.reverse\n valid = false\n break\n end\n start += a.size\n end\n valid = false if a.size * k != s.size\n break if valid\n end\nend\nputs valid ? 'YES' : 'NO'\n"}, {"source_code": "a=gets.chomp\nb=gets.chomp.to_i\nl=a.length\nif l%b!=0\nputs \"NO\"\nelse\ntr=0\ni=0\nb=l/b\nif b>1\nloop do\nif a[i..i+b-1]!=a[i..i+b-1].reverse\ntr=1\nbreak\nelse\ni+=b\nend\nbreak if i==l\nend\nend\n\nif tr==1\nputs \"NO\"\nelse\nputs \"YES\"\nend\nend\n\n"}, {"source_code": "s=gets.chomp\nn=gets.to_i\n\nif s.size%n!=0 then\n\tputs \"NO\"\nelse\n\tm=s.size/n\n\tans=\"YES\"\n\ts.chars.to_a.each_slice(m).each{|e|\n\t\tif e!=e.reverse then\n\t\t\tans=\"NO\"\n\t\tend\n\t}\n\tputs ans\nend\n\n"}], "negative_code": [{"source_code": "# http://codeforces.com/contest/548/problem/A\ndef palindrome?(a)\n a == a.reverse\nend\n\nchars = gets.chomp.chars\nk = gets.chomp.to_i\n\nmessages = chars.each_slice(chars.length / k).to_a\nputs messages.all? { |m| palindrome?(m) } ? \"YES\" : \"NO\"\n"}, {"source_code": "\nstr = gets.chomp;\nn = gets.to_i;\nans = 0;\nans = str.chars.each_slice(str.length / n).all?{|x| x == x.reverse} if (str.length % n == 0);\nputs ans ? \"YES\\n\":\"NO\\n\";"}, {"source_code": "\nstr = gets.chomp;\nn = gets.to_i;\nans = 0;\nans = str.chars.each_slice(str.length / n).all?{|x| x == x.reverse} if (str.length % n == 0);\nputs ans == 1 ? \"YES\\n\":\"NO\\n\";\n"}, {"source_code": "str = gets.chomp;\nn = gets.to_i;\nif (str.length / n > 0)\n arr = str.chars.each_slice(str.length / n).map(&:join);\n puts arr.all?{|x| x.length == arr[0].length && x == x.reverse} ? \"YES\":\"NO\";\nelse\n puts \"NO\\n\";\nend\n"}, {"source_code": "str = gets.chomp;\nn = gets.to_i;\nif (str.length / n > 0)\n arr = str.chars.each_slice(str.length / n).map(&:join);\n puts arr.all?{|x| x.length == arr[0].length && x = x.reverse} ? \"YES\":\"NO\";\nelse\n puts \"NO\\n\";\nend\n"}, {"source_code": "string = gets.chomp\nk = gets.chomp.to_i\nflag = true\n\ndef palindrome?(str)\n\tstr == str.reverse\nend\n\nparts = []\nnowStart = 0\n\nuntil parts.length == k - 1\n\tparts << string.slice(nowStart, string.length / k)\n\tnowStart += string.length / k\n\n\t#puts nowStart\nend\n\nparts << string.slice(nowStart, string.length - nowStart)\n\n=begin\nparts.each do |partString|\n\tputs \"partString : #{partString}\"\nend\n=end\n\nparts.each do |partString|\n\tflag = false if !palindrome?(partString)\n\tflag = false if partString.length != k\nend\n\nputs \"YES\" if flag\nputs \"NO\" if !flag"}, {"source_code": "string = gets.chomp\nk = gets.chomp.to_i\nflag = true\n\ndef palindrome?(str)\n\tstr == str.reverse\nend\n\nparts = []\nnowStart = 0\n\nuntil parts.length == k\n\tparts << string.slice(nowStart, string.length / k)\n\tnowStart += string.length / k\n\n\t#puts nowStart\nend\n\nparts.each do |partString|\n\tflag = false if !palindrome?(partString)\nend\n\nputs \"YES\" if flag\nputs \"NO\" if !flag"}, {"source_code": "string = gets.chomp\nk = gets.chomp.to_i\nflag = true\n\ndef palindrome?(str)\n\tstr == str.reverse\nend\n\nparts = []\nnowStart = 0\n\nuntil parts.length == k\n\tparts << string.slice(nowStart, string.length / k)\n\tnowStart += string.length / k\n\n\tputs nowStart\nend\n\nparts.each do |partString|\n\tflag = false if !palindrome?(partString)\nend\n\nputs \"YES\" if flag\nputs \"NO\" if !flag"}, {"source_code": "string = gets.chomp\nk = gets.chomp.to_i\nflag = true\n\ndef palindrome?(str)\n\tstr == str.reverse\nend\n\nparts = []\nnowStart = 0\n\nuntil parts.length == k\n\tparts << string.slice(nowStart, string.length / k)\nend\n\nparts.each do |partString|\n\tflag = false if !palindrome? partString\nend\n\nputs \"YES\" if flag\nputs \"NO\" if !flag"}, {"source_code": "string = gets.chomp\nk = gets.chomp.to_i\nflag = true\n\ndef palindrome?(str)\n\tstr == str.reverse\nend\n\nparts = []\nnowStart = 0\n\nuntil parts.length == k\n\tparts << string.slice(nowStart, string.length / k)\n\tnowStart += string.length / k\n\n\t#puts nowStart\nend\n\nparts.each do |partString|\n\tflag = false if !palindrome? partString\nend\n\nputs \"YES\" if flag\nputs \"NO\" if !flag"}, {"source_code": "a=gets.chomp\nb=gets.chomp.to_i\nl=a.length\nif l%b!=0\nputs \"NO\"\nelse\ntr=0\ni=0\nif b>1\nb=l/b\nloop do\nif a[i..i+b-1]!=a[i..i+b-1].reverse\ntr=1\nbreak\nelse\ni+=b\nend\nbreak if i==l\nend\nend\n\nif tr==1\nputs \"NO\"\nelse\nputs \"YES\"\nend\nend"}, {"source_code": "\n\ndef is_pal(word, word2)\n word == word2.reverse\nend\n\ndef valid_fax(fax, word_len)\n\n #puts \"fax size = #{fax.size-1}, word_len = #{word_len-1} mod #{(fax.size-1 % word_len-1)}\"\n if ((fax.size-1) % (word_len-1)) != 0\n #puts \"here\"\n return false\n end\n\n i = 0\n puts fax.size\n while i < fax.size-1\n #puts \"Testing #{fax[i,word_len]} and #{fax[i+word_len, word_len]}\"\n unless is_pal(fax[i, word_len], fax[i+word_len, word_len])\n return false\n end\n i += word_len * 2\n end\n return true\nend\n\nwords = gets()\nlen = gets()\nif valid_fax(words,len.to_i + 1)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\n\ndef is_pal(word)\n word == word.reverse\nend\n\ndef valid_fax(fax, num_pals)\n\n #puts \"Fax.size #{fax.size}, number of pals #{num_pals}\"\n word_len = (fax.size) / num_pals\n #puts \"pals are of length #{word_len}, size = #{fax.size}\"\n\n #puts \"#{word_len}\"\n if word_len == 0\n return false\n end\n\n if (fax.size)%word_len != 0\n return false\n end\n\n fax.each_slice(word_len) do |wrd|\n return false unless is_pal(wrd)\n end\n return true\nend\n\nwords = gets().strip.chars\nlen = gets().strip\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "def valid_fax(fax, num_pals)\n\n word_len = (fax.size) / num_pals\n\n #puts \"#{word_len}\"\n if word_len == 0\n return false\n end\n ans = false\n if fax.size % word_len == 0\n ans = fax.each_slice(word_len).all? do |wrd|\n wrd == wrd.reverse\n end\n end\n ans\nend\n\n\nwords = gets().chomp.chars\nlen = gets().strip\nif valid_fax(words,len.to_i) == true\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\ndef valid_fax(fax, num_pals)\n\n word_len = (fax.size) / num_pals\n\n #puts \"#{word_len}\"\n if word_len == 0\n return false\n end\n if fax.size % word_len != 0\n return false\n end\n\n return fax.each_slice(word_len).all? do |wrd|\n wrd == wrd.reverse\n end\nend\n\nwords = gets().strip.chars\nlen = gets().strip\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\ndef valid_fax(fax, num_pals)\n\n word_len = (fax.size) / num_pals\n\n #puts \"#{word_len}\"\n if word_len == 0\n return false\n end\n if fax.size % word_len != 0\n return false\n end\n\n ! fax.each_slice(word_len).any? do |wrd|\n puts wrd\n wrd != wrd.reverse\n end\nend\n\nwords = gets().strip.chars\nlen = gets().strip\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\n\ndef is_pal(word, word2)\n word == word2.reverse\nend\n\ndef valid_fax(fax, word_len)\n\n #puts \"fax size = #{fax.size-1}, word_len = #{word_len-1} mod #{(fax.size-1 % word_len-1)}\"\n if ((fax.size-1) % (word_len-1)) != 0\n #puts \"here\"\n return false\n end\n\n i = 0\n #puts fax.size\n while i < fax.size-1\n #puts \"Testing #{fax[i,word_len]} and #{fax[i+word_len, word_len]}\"\n unless is_pal(fax[i, word_len], fax[i+word_len, word_len])\n return false\n end\n i += word_len * 2\n end\n return true\nend\n\nwords = gets()\nlen = gets()\nif valid_fax(words,len.to_i + 1)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\ndef valid_fax(fax, num_pals)\n\n word_len = (fax.size) / num_pals\n\n #puts \"#{word_len}\"\n if word_len == 0\n return false\n end\n if fax.size % word_len != 0\n return false\n end\n\n return fax.each_slice(word_len).all? do |wrd|\n wrd == wrd.reverse\n end\nend\n\nwords = gets().chomp.chars\nlen = gets().strip\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\n\ndef is_pal(word)\n word == word.reverse\nend\n\ndef valid_fax(fax, num_pals)\n\n word_len = fax.size / num_pals\n #puts \"pals are of length #{word_len}, size = #{fax.size-1}\"\n if (fax.size-1)%word_len != 0\n return false\n end\n\n if word_len == 1\n return true\n end\n\n i = 0\n #puts fax.size\n while i < fax.size-1\n #puts \"Testing #{fax[i,word_len]}\"\n unless is_pal(fax[i, word_len])\n return false\n end\n i += word_len * 2\n end\n return true\nend\n\nwords = gets()\nlen = gets()\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\n\ndef is_pal(word)\n word == word.reverse\nend\n\ndef valid_fax(fax, num_pals)\n\n #puts \"Fax.size #{fax.size}, number of pals #{num_pals}\"\n word_len = (fax.size) / num_pals\n #puts \"pals are of length #{word_len}, size = #{fax.size}\"\n\n #puts \"#{word_len}\"\n if word_len == 0\n return false\n end\n\n if word_len == 1\n return true\n end\n if (fax.size)%word_len != 0\n return false\n end\n\n fax.each_slice(word_len) do |wrd|\n return false if !is_pal(wrd)\n end\n return true\nend\n\nwords = gets().strip.chars\nlen = gets().strip\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\n\ndef is_pal(word, word2)\n word == word2.reverse\nend\n\ndef valid_fax(fax, word_len)\n\n if fax%word_len != 0\n return false\n end\n\n i = 0\n puts fax.size\n while i < fax.size-1\n puts \"Testing #{fax[i,word_len]} and #{fax[i+word_len, word_len]}\"\n unless is_pal(fax[i, word_len], fax[i+word_len, word_len])\n return false\n end\n i += word_len * 2\n end\n return true\nend\n\nwords = gets()\nlen = gets()\nif valid_fax(words,len.to_i + 1)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\n\ndef is_pal(word)\n word == word.reverse\nend\n\ndef valid_fax(fax, num_pals)\n\n word_len = fax.size / num_pals\n\n if word_len == 1\n return true\n end\n\n #puts \"pals are of length #{word_len}, size = #{fax.size-1}\"\n if (fax.size-1)%word_len != 0\n return false\n end\n\n \n i = 0\n #puts fax.size\n while i < fax.size-1\n #puts \"Testing #{fax[i,word_len]}\"\n unless is_pal(fax[i, word_len])\n return false\n end\n i += word_len * 2\n end\n return true\nend\n\nwords = gets()\nlen = gets()\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\n\ndef is_pal(word)\n word == word.reverse\nend\n\ndef valid_fax(fax, num_pals)\n\n word_len = fax.size / num_pals\n #puts \"pals are of length #{word_len}, size = #{fax.size-1}\"\n if (fax.size-1)%word_len != 0\n return false\n end\n\n i = 0\n #puts fax.size\n while i < fax.size-1\n #puts \"Testing #{fax[i,word_len]}\"\n unless is_pal(fax[i, word_len])\n return false\n end\n i += word_len * 2\n end\n return true\nend\n\nwords = gets()\nlen = gets()\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\n\ndef is_pal(word, word2)\n word == word2.reverse\nend\n\ndef valid_fax(fax, word_len)\n\n puts \"fax size = #{fax.size-1}, word_len = #{word_len-1} mod #{(fax.size-1 % word_len-1)}\"\n if ((fax.size-1) % (word_len-1)) != 0\n puts \"here\"\n return false\n end\n\n i = 0\n puts fax.size\n while i < fax.size-1\n #puts \"Testing #{fax[i,word_len]} and #{fax[i+word_len, word_len]}\"\n unless is_pal(fax[i, word_len], fax[i+word_len, word_len])\n return false\n end\n i += word_len * 2\n end\n return true\nend\n\nwords = gets()\nlen = gets()\nif valid_fax(words,len.to_i + 1)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\n\ndef is_pal(word)\n word == word.reverse\nend\n\ndef valid_fax(fax, num_pals)\n\n #puts \"Fax.size #{fax.size-1}, number of pals #{num_pals}\"\n word_len = (fax.size) / num_pals\n #puts \"pals are of length #{word_len}, size = #{fax.size-1}\"\n\n #puts \"#{word_len}\"\n if word_len == 0\n return false\n end\n if word_len == 1\n return true\n end\n if (fax.size)%word_len != 0\n return false\n end\n\n fax.each_slice(word_len) do |wrd|\n return false unless is_pal(wrd)\n end\n return true\nend\n\nwords = gets()\nlen = gets()\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\ndef valid_fax(fax, num_pals)\n\n word_len = (fax.size) / num_pals\n\n #puts \"#{word_len}\"\n if word_len == 0\n return false\n end\n if fax.size % word_len != 0\n return false\n end\n\n return fax.each_slice(word_len).all? do |wrd|\n wrd == wrd.reverse\n end\nend\n\nwords = gets().chomp.chars\nlen = gets().strip\nif valid_fax(words,len.to_i) == true\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\n\ndef is_pal(word)\n word == word.reverse\nend\n\ndef valid_fax(fax, num_pals)\n\n word_len = fax.size / num_pals\n #puts \"pals are of length #{word_len}\"\n\n i = 0\n #puts fax.size\n while i < fax.size-1\n #puts \"Testing #{fax[i,word_len]}\"\n unless is_pal(fax[i, word_len])\n return false\n end\n i += word_len * 2\n end\n return true\nend\n\nwords = gets()\nlen = gets()\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\ndef valid_fax(fax, num_pals)\n\n #puts \"Fax.size #{fax.size}, number of pals #{num_pals}\"\n word_len = (fax.size) / num_pals\n #puts \"pals are of length #{word_len}, size = #{fax.size}\"\n\n #puts \"#{word_len}\"\n if word_len == 0\n return false\n end\n\n if word_len == 1\n return true\n end\n if fax.size % word_len != 0\n return false\n end\n\n ! fax.each_slice(word_len).any? do |wrd|\n wrd != wrd.reverse\n end\nend\n\nwords = gets().strip.chars\nlen = gets().strip\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "\n\ndef is_pal(word)\n word == word.reverse\nend\n\ndef valid_fax(fax, num_pals)\n\n #puts \"Fax.size #{fax.size-1}, number of pals #{num_pals}\"\n word_len = (fax.size-1) / num_pals\n #puts \"pals are of length #{word_len}, size = #{fax.size-1}\"\n\n #puts \"#{word_len}\"\n if word_len == 0\n return false\n end\n if word_len == 1\n return true\n end\n if (fax.size-1)%word_len != 0\n return false\n end\n\n\n i = 0\n #puts fax.size\n while i < fax.size-1\n #puts \"Testing #{fax[i,word_len]}\"\n unless is_pal(fax[i, word_len])\n return false\n end\n i += word_len * 2\n end\n return true\nend\n\nwords = gets()\nlen = gets()\nif valid_fax(words,len.to_i)\n puts 'YES'\nelse\n puts 'NO'\nend\n\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# a.rb\n\ndef is_palindrome(s)\n return false if s.size == 1\n s.size.times do |i|\n return false if s[i] != s[s.size - i - 1]\n end\n return true\nend\n\ndef ok(s, k)\n return false if s.size % k != 0\n n = s.size / k\n k.times do |i|\n return false if !is_palindrome(s[n * i, n])\n end\n return true\nend\n\ndef main()\n s = gets.chomp\n k = gets.to_i\n \n puts ok(s, k) ? \"YES\" : \"NO\"\nend\n\n\nif __FILE__ == $0 then\n main()\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# a.rb\n\ndef is_palindrome(s)\n return false if s.size == 1\n s.size.times do |i|\n return false if s[i] != s[s.size - i - 1]\n end\n return true\nend\n\ndef ok(s, k)\n if s == \"\" && k == 0 then\n return true\n end\n if (s != \"\" && k == 0) || (s == \"\" && k > 0) then\n return false\n end\n\n ret = false\n 2.upto(s.size) do |i|\n ss = s[0, i]\n if is_palindrome(ss) then\n ret = ret | ok(s[i, s.size], k - 1)\n end\n end\n return ret\nend\n\ndef main()\n s = gets.chomp\n k = gets.to_i\n \n puts ok(s, k) ? \"YES\" : \"NO\"\nend\n\n\nif __FILE__ == $0 then\n main()\nend\n"}, {"source_code": "s = gets.chomp.chars\nn = gets.to_i\nc = 0\na = []\ni = 0\nwhile i < s.size\n if a != [] && s[i...i + a.size] == a.reverse\n c += 1\n i += a.size\n a = []\n else\n a << s[i]\n i += 1\n end\nend\nputs c == n ? 'YES' : 'NO'\n"}, {"source_code": "s = gets.chomp.chars\nk = gets.to_i\na = []\nvalid = false\ns.size.times do |i|\n a << s[i]\n if a == a.reverse\n start = a.size\n c = 1\n valid = true\n (k - 1).times do\n t = s[start...start + a.size]\n if start + a.size >= s.size || t != t.reverse\n valid = false\n break\n end\n start += a.size\n end\n valid = false if a.size * k != s.size\n break if valid\n end\nend\nputs valid ? 'YES' : 'NO'\n"}, {"source_code": "s = gets.chomp.chars\nk = gets.to_i\na = []\nvalid = false\ns.size.times do |i|\n a << s[i]\n if s[a.size...2 * a.size] == a.reverse\n start = 2 * a.size\n (k - 1).times do\n valid = true\n if s[start...start + a.size] != s[start + a.size...start + 2 * a.size].reverse\n valid = false\n break\n end\n start += 2 * a.size\n end\n break if valid\n end\nend\nputs valid ? 'YES' : 'NO'\n"}, {"source_code": "s = gets.chomp.chars\nk = gets.to_i\na = []\nvalid = false\ns.size.times do |i|\n a << s[i]\n if a == s[a.size...2 * a.size].reverse\n start = 2 * a.size\n valid = true\n (k - 1).times do\n if start + 2 * a.size > s.size || s[start...start + a.size] != s[start + a.size...start + 2 * a.size].reverse\n valid = false\n break\n end\n start += 2 * a.size\n end\n break if valid\n end\nend\nputs valid ? 'YES' : 'NO'\n"}, {"source_code": "s = gets.chomp.chars\nk = gets.to_i\nputs s.each_slice(s.size / k).to_a.all?{|x| x == x.reverse} ? 'YES' : 'NO'\n"}, {"source_code": "#!ruby\n\ns = gets.chomp\nk = gets.chomp.to_i\n\nul = s.length/k\n0.upto(k-1) do |i|\n ss = s[ul*i..ul*(i+1)-1]\n if ss != ss.reverse\n puts \"NO\"\n exit\n end\nend\nputs \"YES\"\nexit\n"}], "src_uid": "43bb8fec6b0636d88ce30f23b61be39f"} {"source_code": "# https://codeforces.com/contest/1332/problem/B\n\nprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]\n\ngets.to_i.times do\n n = gets.to_i\n numbers = gets.split(' ').map(&:to_i)\n \n answer = []\n colors = {}\n color_count = 1\n \n numbers.each do |n|\n color = primes.find do |p|\n n % p == 0\n end\n\n if colors[color].nil?\n colors[color] = color_count\n color_count += 1\n end\n \n answer << colors[color]\n end\n\n puts colors.size\n puts answer.join(' ')\nend", "positive_code": [{"source_code": "primes = [2,3,5,7,11,13,17,19,23,29,31]\nt = gets.chomp.to_i\n\nt.times do\n n = gets.chomp.to_i\n a = gets.chomp.split.map(&:to_i)\n\n colors = {}\n coloring = a.map do |aa|\n color = primes.find do |pr|\n aa % pr == 0\n end\n\n if colors.key?(color)\n colors[color]\n else\n colors[color] = colors.size + 1\n end\n end\n puts colors.size\n puts coloring.join(' ')\nend\n"}, {"source_code": "PRIME = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]\nt = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n mapping = {}\n used = 0\n c = Array.new(n, nil)\n a.each_with_index do |v, i|\n PRIME.each_with_index do |p, j|\n if v % p == 0\n if !mapping.include?(p)\n used += 1\n mapping[p] = used\n end\n c[i] = mapping[p]\n break\n end\n end\n end\n puts used\n puts c.join(\" \")\nend\n"}, {"source_code": "# https://codeforces.com/contest/1332/problem/B\n\nrequire 'set'\n\n@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]\n\ndef lowest_divisor(n)\n @primes.each do |p|\n if n % p == 0\n return p\n end\n end\nend\n\ngets.to_i.times do\n n = gets.to_i\n numbers = gets.split(' ').map(&:to_i)\n \n answer = \"\"\n colors = {}\n color_count = 1\n \n numbers.each do |n|\n color = lowest_divisor(n)\n if colors[color].nil?\n colors[color] = color_count\n color_count += 1\n end\n \n answer += \"#{colors[color]} \"\n end\n\n answer[-1] = \"\"\n\n puts colors.size\n puts answer\nend"}], "negative_code": [{"source_code": "# https://codeforces.com/contest/1332/problem/B\n\nrequire 'set'\n\n@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]\n\ndef lowest_divisor(n)\n @primes.each do |p|\n if n % p == 0\n return p\n end\n end\nend\n\ngets.to_i.times do\n n = gets.to_i\n numbers = gets.split(' ').map(&:to_i)\n \n answer = \"\"\n colors = Set.new()\n\n numbers.each do |n|\n color = lowest_divisor(n)\n colors << color\n answer += \"#{@primes.index(color) + 1} \"\n end\n\n answer[-1] = \"\"\n\n puts answer\nend"}, {"source_code": "# https://codeforces.com/contest/1332/problem/B\n\nrequire 'set'\n\n@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]\n\ndef lowest_divisor(n)\n @primes.each do |p|\n if n % p == 0\n return p\n end\n end\nend\n\ngets.to_i.times do\n n = gets.to_i\n numbers = gets.split(' ').map(&:to_i)\n \n answer = \"\"\n colors = Set.new()\n\n numbers.each do |n|\n color = lowest_divisor(n)\n colors << color\n answer += \"#{@primes.index(color) + 1} \"\n end\nend"}, {"source_code": "# https://codeforces.com/contest/1332/problem/B\n\nrequire 'set'\n\n@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]\n\ndef lowest_divisor(n)\n @primes.each do |p|\n if n % p == 0\n return p\n end\n end\nend\n\ngets.to_i.times do\n n = gets.to_i\n numbers = gets.split(' ').map(&:to_i)\n \n answer = \"\"\n colors = Set.new()\n\n numbers.each do |n|\n color = lowest_divisor(n)\n colors << color\n answer += \"#{@primes.index(color) + 1} \"\n end\n\n answer.rstrip!\nend"}, {"source_code": "# https://codeforces.com/contest/1332/problem/B\n\nrequire 'set'\n\n@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]\n\ndef lowest_divisor(n)\n @primes.each do |p|\n if n % p == 0\n return p\n end\n end\nend\n\ngets.to_i.times do\n n = gets.to_i\n numbers = gets.split(' ').map(&:to_i)\n \n answer = \"\"\n colors = Set.new()\n\n numbers.each do |n|\n color = lowest_divisor(n)\n colors << color\n answer += \"#{@primes.index(color) + 1} \"\n end\n\n answer[-1] = \"\"\n\n puts colors.size\n puts answer\nend"}], "src_uid": "c3cd949c99e96c9da186a34d49bd6197"} {"source_code": "def solve(line)\n plus = 1\n minu = 0\n\n line.each_char do |ch|\n if ch == '+'\n plus += 1\n elsif ch == '-'\n minu += 1\n end\n end\n\n line =~ /([0-9]+)/\n n = Regexp.last_match[0].to_i\n\n if n > plus * n - minu || n < plus - minu * n\n puts \"Impossible\"\n return\n end\n\n curr = plus - minu\n\n signs = '+' + line.gsub(/[^+-]/, '')\n\n first = true\n\n puts \"Possible\"\n\n signs.each_char do |sign|\n print \" #{sign} \" if !first\n first = false\n if sign == '+'\n if curr >= n\n print 1\n else\n x = [n - curr + 1, n].min\n curr += x - 1\n print x\n end\n else\n if curr <= n\n print 1\n else\n x = [curr - n + 1, n].min\n curr -= x - 1\n print x\n end\n end\n end\n\n puts \" = #{n}\"\nend\n\nwhile line = gets\n solve(line.chomp)\nend\n", "positive_code": [{"source_code": "\n\n\nstr = (\"+ \" + gets).split\nl = str.length\nm = l/2 -1\nn = str[l-1].to_i\na = Array.new(m){|e| e = 0}\ns = 0\nm.times{ |i|\n\ta[i] = str[i*2]=='+'?1: -1;\n\ts+=a[i]\n}\n\ni = 0\n\nif (s0 && a[i]n\n\twhile(i-n\n\t\t\ts-=1;a[i]-=1;\n\t\telse\n\t\t\ti+=1;\n\t\tend\n\tend\nend\n\nif s!=n\n\tprint \"Impossible\\n\"\nelse\n\tprint \"Possible\\n\"\n\tstr = \"\"\n\tfor i in (0...m)\n\t\tstr += \"#{a[i]}\" if i==0\n\t\tif i!=0\n\t\t\tif a[i]>0\n\t\t\t\tstr += \" + #{a[i]}\"\n\t\t\telse \n\t\t\t\tstr += \" - #{-a[i]}\"\n\t\t\tend\n\t\tend\n\tend\n\tstr += \" = #{n}\"\n\tprint str\nend"}, {"source_code": "def isok(arr, n, target)\n pos, neg = arr.count{|x| x == \"+\"}, arr.count{|x| x == '-'}\n max, min = pos * n - neg, pos - neg * n\n #print \"##\", max, \" \", min, \" \", target\n #puts \"\"\n if target <= max && target >= min\n return 0\n elsif target > max\n return -1\n else\n return 1\n end\nend\n\narr = readline.gsub(/[?=]/, \"\").split(' ')\nn = arr.last.to_i\narr = [\"+\"] + arr[0..-2]\n\nif isok(arr, n, n) == 0\n puts \"Possible\"\n target = n\n 0.upto(arr.length - 1) do |ind|\n ans = 0\n flag = arr[ind] == \"+\" ? 1 : -1\n if isok(arr[ind + 1..-1], n, target - flag) == 0\n ans = 1\n elsif isok(arr[ind + 1..-1], n, target - n * flag) == 0\n ans = n\n else\n down, up = 1, n\n downf = isok(arr[ind + 1..-1], n, target - flag)\n upf = isok(arr[ind + 1..-1], n, target - n * flag)\n while down + 1 < up\n mid = (down + up) / 2\n res = isok(arr[ind + 1..-1], n, target - mid * flag)\n if res == 0\n ans = mid\n break\n elsif res == downf\n down = mid\n else\n up = mid\n end\n end\n end\n if ind != 0\n print \" \" + arr[ind] + \" \"\n end\n print ans\n target -= ans * flag\n end\n print \" = \"\n puts n\nelse\n puts \"Impossible\"\nend\n"}, {"source_code": "arr=gets.split('?')\narr[0]='+'\nsz=arr.size\nn=arr[sz-1]\nn=n[3,n.size-3].to_i\na=Array.new(111)\ns=-n\nfor i in 0..sz-2\n\tif arr[i].strip=='+'\n\t\ta[i]=n\n\t\ts+=n\n\telse\n\t\ta[i]=1\n\t\ts-=1\n\tend\nend\nfor i in 0..sz-2\n\tif s>0 && arr[i].strip=='+'\n\t\tdet = [n-1, s].min\n\t\ta[i]-=det\n\t\ts-=det\n\tend\n\tif s>0 && arr[i].strip=='-'\n\t\tdet = [n-1, s].min\n\t\ta[i]+=det\n\t\ts-=det\n\tend\nend\nif s!=0\n\tputs \"Impossible\"\nelse\n\tputs \"Possible\"\n\tarr[0]=\"\"\n\tfor i in 0..sz-2\n\t\tprint \"#{arr[i]}#{a[i]}\"\n\tend\n\tputs arr[sz-1]\nend"}], "negative_code": [{"source_code": "def isok(arr, n, target)\n pos, neg = arr.count{|x| x == \"+\"}, arr.count{|x| x == '-'}\n max, min = pos * n - neg, pos - neg * n\n #print \"##\", max, \" \", min, \" \", target\n #puts \"\"\n if target <= max && target >= min\n return 0\n elsif target > max\n return -1\n else\n return 1\n end\nend\n\narr = readline.gsub(/[?=]/, \"\").split(' ')\nn = arr.last.to_i\narr = [\"+\"] + arr[0..-2]\n\nif isok(arr, n, n) == 0\n puts \"Possible\"\n target = n\n 0.upto(arr.length - 1) do |ind|\n ans = 0\n flag = arr[ind] == \"+\" ? 1 : -1\n if isok(arr[ind + 1..-1], n, target - flag) == 0\n ans = 1\n elsif isok(arr[ind + 1..-1], n, target - n * flag) == 0\n ans = n\n else\n down, up = 1, n\n downf = isok(arr[ind + 1..-1], n, target - flag)\n upf = isok(arr[ind + 1..-1], n, target - n * flag)\n while down + 1 < up\n mid = (down + up) / 2\n res = isok(arr[ind + 1..-1], n, target - mid)\n if res == 0\n ans = mid\n break\n elsif res == downf\n down = mid\n else\n up = mid\n end\n end\n end\n if ind != 0\n print \" \" + arr[ind] + \" \"\n end\n print ans\n target -= ans * flag\n end\n print \" = \"\n puts n\nelse\n puts \"Impossible\"\nend\n"}, {"source_code": "def isok(arr, n, target)\n pos, neg = arr.count{|x| x == \"+\"}, arr.count{|x| x == '-'}\n max, min = pos * n - neg, pos - neg * n\n #print \"##\", max, \" \", min, \" \", target\n #puts \"\"\n if target <= max && target >= min\n return 0\n elsif target > max\n return -1\n else\n return 1\n end\nend\n\narr = readline.gsub(/[?=]/, \"\").split(' ')\nn = arr.last.to_i\narr = [\"+\"] + arr[0..-2]\n\nif isok(arr, n, n) == 0\n target = n\n 0.upto(arr.length - 1) do |ind|\n ans = 0\n flag = arr[ind] == \"+\" ? 1 : -1\n if isok(arr[ind + 1..-1], n, target - flag) == 0\n ans = 1\n elsif isok(arr[ind + 1..-1], n, target - n * flag) == 0\n ans = n\n else\n down, up = 1, n\n downf = isok(arr[ind + 1..-1], n, target - flag)\n upf = isok(arr[ind + 1..-1], n, target - n * flag)\n while down + 1 < up\n mid = (down + up) / 2\n res = isok(arr[ind + 1..-1], n, target - mid)\n if res == 0\n ans = mid\n break\n elsif res == downf\n down = mid\n else\n up = mid\n end\n end\n end\n if ind != 0\n print \" \" + arr[ind] + \" \"\n end\n print ans\n target -= ans * flag\n end\n print \" = \"\n puts n\nelse\n puts \"Impossible\"\nend\n"}, {"source_code": "arr=gets.split('?')\narr[0]='+'\nsz=arr.size\nn=arr[sz-1]\nn=n[3,n.size-3].to_i\na=Array.new(111)\ns=-n\nfor i in 0..sz-2\n\tif arr[i].strip=='+'\n\t\ta[i]=n\n\t\ts+=n\n\telse\n\t\ta[i]=1\n\t\ts-=1\n\tend\nend\nfor i in 0..sz-2\n\tif s>0 && a[i]==n\n\t\tdet = [n-1, s].min\n\t\ta[i]-=det\n\t\ts-=det\n\tend\nend\nif s!=0\n\tputs \"Impossible\"\nelse\n\tputs \"Possible\"\n\tarr[0]=\"\"\n\tfor i in 0..sz-2\n\t\tprint \"#{arr[i]}#{a[i]}\"\n\tend\n\tputs arr[sz-1]\nend"}], "src_uid": "35a97c47182916aaafe4c6e4b69bc79f"} {"source_code": "# frozen_string_literal: true\n\n@data = $stdin.read.split\n\ndef next_token\n @data.shift\nend\n\ndef next_int\n next_token.to_i\nend\n\nnext_int.times do\n n = next_int\n x = next_int\n y = next_int\n\n maxp = [x + y - 1, n].min\n b = x + y + 1 - n\n # b -= 1 if y == n\n minp = [[b, n].min, 1].max\n # a = x + y - n + 1\n # b = x + y\n # a = [a, 1].max\n # b = [b, n].min\n # minp = b - a\n # minp += 1 if b < n\n # minp = n - minp\n puts \"#{minp} #{maxp}\"\nend\n", "positive_code": [{"source_code": "def best(n, x, y)\n case x+y\n when (2..n) then 1\n when 2*n then n\n else x+y - n + 1\n end\nend\n\ndef worst(n, x, y)\n x+y > n+1 ? n : x+y -1\nend\n\n1.upto(gets.chomp.to_i) do\n n,x,y = gets.chomp.split.map(&:to_i)\n\n puts [best(n,x,y), worst(n,x,y)].join(' ')\nend\n"}, {"source_code": "#! /usr/bin/env ruby\n\n=begin\n1 2 3 4 5 \u548c\n1 2 3 4 5 \u4e24\u4e24\u914d\u5bf9\n\u5e0c\u671b\u5bf9\u5b50\u7684\u548c\u5927\u4e8e\u6211\u7684\u5bf9\u5b50\u7684\u548c\n\n\u6ce8\u610f\u5230 2+5 3+4 .. 5+2 \u90fd\u662f7\n\n\u53ef\u4ee5\u8d2a\u5fc3\u3002\u679a\u4e3e\u7b2c\u4e00\u573a\u6bd4\u8d5b\u6210\u7ee9\uff0c\u53ef\u5f97 \u8981\u8fd9\u4e2a\u4eba\u8f93\u7ed9\u6211\uff0c\u7b2c\u4e8c\u573a\u5f97\u591a\u5dee\n\nn\u592a\u5927\uff0c\u5f97\u4f18\u5316\u4e00\u4e0b\navail_y = [1, ... my_y-1], [my_y+1, ... n]\n\u9636\u6bb51\uff1ax + y_too_small ...\n\u9636\u6bb52\uff1ax + y\n=end\n\ndef solve_best(n, my_x, my_y)\n goal = my_x + my_y + 1\n nlose = 0\n\n x = goal - n; y = n\n if x < 1 then x = 1 end\n loop do\n\t break if x > n || y < 1\n\t if my_y == y\n\t y -= 1\n\t if x+y < goal then x += 1 end\n\t end\n\t if my_x == x then x += 1 end\n\t break if x > n || y < 1\n\n\t len = n\n\t stop_at = (y > my_y ? my_y : 0)\n\t if len > y - stop_at then len = y - stop_at end\n\t stop_at = (x < my_x ? my_x : n+1)\n\t if len > stop_at - x then len = stop_at - x end\n\t nlose += len\n\t x += len\n\t y -= len\n end\n\n print (n - nlose), ' '\nend\n\ndef solve_worst(n, my_x, my_y)\n goal = my_x + my_y\n nwin = 1 # myself\n\n x = 1; y = goal - 1\n if y > n then y = n end\n loop do\n break if x > n || y < 1\n if my_x == x\n x += 1\n if x+y > goal then y -= 1 end\n end\n if my_y == y then y -= 1 end\n break if x > n || y < 1\n\n len = n\n stop_at = (y > my_y ? my_y : 0)\n if len > y - stop_at then len = y - stop_at end\n stop_at = (x < my_x ? my_x : n+1)\n if len > stop_at - x then len = stop_at - x end\n nwin += len\n x += len\n y -= len\n end\n\n puts nwin\nend\n\ndef solve\n n, myx, myy = gets.split.map{|x| x.to_i}\n solve_best(n, myx, myy)\n solve_worst(n, myx, myy)\nend\n\nt = gets.to_i\nt.times { solve }\n"}, {"source_code": "T = gets.to_i\n\ndef estimate_top(n, x, y)\n rank = 1\n\n above_a = x - 1\n below_a = [0, n - (x + 1)].max\n above_b = y - 1\n below_b = [0, n - (y + 1)].max\n\n d1 = [0, [above_a, below_b].min].max\n d2 = [0, [above_b, below_a].min].max\n\n above_a -= d1\n above_b -= d2\n\n rank += [0, [above_a, above_b].max].max\n\n rank\nend\n\ndef estimate_bottom(n, x, y)\n rank = 1\n\n above_a = x - 1\n below_a = n - x\n above_b = y - 1\n below_b = n - y\n\n d1 = [0, [above_a, below_b].min].max\n d2 = [0, [above_b, below_a].min].max\n\n above_a -= d1\n above_b -= d2\n\n rank += d1 + d2 + [0, [above_a, above_b].max].max\n\n rank\nend\n\nT.times do\n n, x, y = gets.split.map(&:to_i)\n x, y = [x, y].sort\n\n top = estimate_top(n, x, y)\n bottom = estimate_bottom(n, x, y)\n\n puts \"#{top} #{bottom}\"\nend\n"}], "negative_code": [{"source_code": "# frozen_string_literal: true\n\n@data = $stdin.read.split\n\ndef next_token\n @data.shift\nend\n\ndef next_int\n next_token.to_i\nend\n\nnext_int.times do\n n = next_int\n x = next_int\n y = next_int\n\n a = x + y - n\n b = x + y - 1\n a = [a, 1].max\n b = [b, n].min\n maxp = (b - a + 1)\n b = [[x + y + 1 - n, n].min, 1].max\n minp = b\n # a = x + y - n + 1\n # b = x + y\n # a = [a, 1].max\n # b = [b, n].min\n # minp = b - a\n # minp += 1 if b < n\n # minp = n - minp\n puts \"#{minp} #{maxp}\"\nend\n"}, {"source_code": "# frozen_string_literal: true\n\n@data = $stdin.read.split\n\ndef next_token\n @data.shift\nend\n\ndef next_int\n next_token.to_i\nend\n\nnext_int.times do\n n = next_int\n x = next_int\n y = next_int\n\n a = x + y - n\n b = x + y - 1\n a = [a, 1].max\n b = [b, n].min\n maxp = (b - a + 1)\n b = x + y + 1 - n\n b -= 1 if y == n\n minp = [[b, n].min, 1].max\n # a = x + y - n + 1\n # b = x + y\n # a = [a, 1].max\n # b = [b, n].min\n # minp = b - a\n # minp += 1 if b < n\n # minp = n - minp\n puts \"#{minp} #{maxp}\"\nend\n"}, {"source_code": "# frozen_string_literal: true\n\n@data = $stdin.read.split\n\ndef next_token\n @data.shift\nend\n\ndef next_int\n next_token.to_i\nend\n\nnext_int.times do\n n = next_int\n x = next_int\n y = next_int\n\n maxp = [x + y - 1, n].min\n b = x + y + 1 - n\n b -= 1 if y == n\n minp = [[b, n].min, 1].max\n # a = x + y - n + 1\n # b = x + y\n # a = [a, 1].max\n # b = [b, n].min\n # minp = b - a\n # minp += 1 if b < n\n # minp = n - minp\n puts \"#{minp} #{maxp}\"\nend\n"}, {"source_code": "# frozen_string_literal: true\n\n@data = $stdin.read.split\n\ndef next_token\n @data.shift\nend\n\ndef next_int\n next_token.to_i\nend\n\nnext_int.times do\n n = next_int\n x = next_int\n y = next_int\n\n a = x + y - n\n b = x + y - 1\n a = [a, 1].max\n b = [b, n].min\n maxp = (b - a + 1)\n a = x + y - n + 1\n b = x + y\n a = [a, 1].max\n b = [b, n].min\n minp = b - a\n minp += 1 if b < n\n puts \"#{n - minp} #{maxp}\"\nend\n"}, {"source_code": "T = gets.to_i\n\ndef estimate_top(n, x, y)\n rank = 1\n\n above_a = x - 1\n d = n - (y + 1)\n\n if d < above_a\n rank += above_a - d\n end\n\n rank\nend\n\ndef estimate_bottom(n, x, y)\n rank = 1\n\n above_a = x - 1\n above_b = y - 1\n\n rank += above_a + above_b\n\n rank\nend\n\nT.times do\n n, x, y = gets.split.map(&:to_i)\n x, y = [x, y].sort\n\n top = estimate_top(n, x, y)\n bottom = estimate_bottom(n, x, y)\n\n puts \"#{top} #{bottom}\"\nend\n"}, {"source_code": "T = gets.to_i\n\ndef estimate_top(n, x, y)\n rank = 1\n\n above_a = x - 1\n d = [0, n - (y + 1)].max\n\n if d < above_a\n rank += above_a - d\n end\n\n rank\nend\n\ndef estimate_bottom(n, x, y)\n rank = 1\n\n above_a = x - 1\n below_a = n - x\n above_b = y - 1\n below_b = n - y\n\n d1 = [0, [above_a, below_b].min].max\n d2 = [0, [above_b, below_a].min].max\n\n above_a -= d1\n above_b -= d2\n\n rank += d1 + d2 + [above_a, above_b].min\n\n rank\nend\n\nT.times do\n n, x, y = gets.split.map(&:to_i)\n x, y = [x, y].sort\n\n top = estimate_top(n, x, y)\n bottom = estimate_bottom(n, x, y)\n\n puts \"#{top} #{bottom}\"\nend\n"}, {"source_code": "T = gets.to_i\n\ndef estimate_top(n, x, y)\n rank = 1\n\n above_a = x - 1\n d = n - (y + 1)\n\n if d < above_a\n rank += above_a - d\n end\n\n rank\nend\n\ndef estimate_bottom(n, x, y)\n rank = 1\n\n above_a = x - 1\n below_a = n - x\n above_b = y - 1\n below_b = n - y\n\n d1 = [0, [above_a, below_b].min].max\n d2 = [0, [above_b, below_a].min].max\n\n rank += d1 + d2\n\n rank\nend\n\nT.times do\n n, x, y = gets.split.map(&:to_i)\n x, y = [x, y].sort\n\n top = estimate_top(n, x, y)\n bottom = estimate_bottom(n, x, y)\n\n puts \"#{top} #{bottom}\"\nend\n"}, {"source_code": "T = gets.to_i\n\ndef estimate_top(n, x, y)\n rank = 1\n\n above_a = x - 1\n below_a = [0, n - (x + 1)].max\n above_b = y - 1\n below_b = [0, n - (y + 1)].max\n\n d1 = [0, [above_a, below_b].min].max\n d2 = [0, [above_b, below_a].min].max\n\n above_a -= d1\n above_b -= d2\n\n rank += [above_a, above_b].min\n\n rank\nend\n\ndef estimate_bottom(n, x, y)\n rank = 1\n\n above_a = x - 1\n below_a = n - x\n above_b = y - 1\n below_b = n - y\n\n d1 = [0, [above_a, below_b].min].max\n d2 = [0, [above_b, below_a].min].max\n\n above_a -= d1\n above_b -= d2\n\n rank += d1 + d2 + [above_a, above_b].min\n\n rank\nend\n\nT.times do\n n, x, y = gets.split.map(&:to_i)\n x, y = [x, y].sort\n\n top = estimate_top(n, x, y)\n bottom = estimate_bottom(n, x, y)\n\n puts \"#{top} #{bottom}\"\nend\n"}], "src_uid": "58c887568002d947706c448e6faa0f77"} {"source_code": "s = gets.strip\nmirrored = [\"A\", \"b\", \"d\", \"H\", \"I\", \"M\", \"O\", \"o\", \"p\", \"q\", \"T\", \"U\", \"V\", \"v\", \"W\", \"w\", \"X\", \"x\", \"Y\"]\nmirror_of = [\"A\", \"d\", \"b\", \"H\", \"I\", \"M\", \"O\", \"o\", \"q\", \"p\", \"T\", \"U\", \"V\", \"v\", \"W\", \"w\", \"X\", \"x\", \"Y\"]\ni = 0\nj = s.length - 1\npalindrom = true\nwhile i <= j\n l = mirrored.index s[i]\n r = mirror_of.index( s[j] )\n palindrom = false if l.nil? || r.nil? || l != r\n i += 1\n j -= 1\nend\nif palindrom\n puts \"TAK\"\nelse\n puts \"NIE\"\nend\n", "positive_code": [{"source_code": "word = gets.to_s\nchar_array = word.chars.to_a\nlen = char_array.length-1\narray_div = len/2\narray_mod = len%2\nchar_valid = \"AbdHIMOopqTUVvWwXxY\".chars.to_a\n#puts len\n#puts array_div\n#puts array_mod\nctr = 0\nif (1 <= len) && (len <= 1000)\n\tif array_mod == 0\n\t\t\tfor i in 0..array_div-1\n\t\t\t\tif char_valid.include?(char_array[i])\n\t\t\t\t\tif ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))\n ctr += 1\n #puts 'a'\n #puts ctr\n elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))\n ctr += 1\n #puts 'b'\n #puts ctr\n elsif (char_array[i] == char_array[len-1-i] && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))\n\t\t\t\t\t\tctr += 1\n # puts 'c'\n #puts ctr\n\n\t\t\t\t\tend\n\t\t\t\tend\n end\nelse\n\t\t\tfor i in 0..array_div\n\t\t\t\tif char_valid.include?(char_array[i])\n\t\t\t\t\tif ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'a'\n\t\t\t\t\t#\tputs ctr\n elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'b'\n\t\t\t\t\t#\tputs ctr\n elsif (char_array[i] == char_array[len-1-i] && i != len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'c'\n\t\t\t\t\t#\tputs ctr\n elsif(i == len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'd'\n\t\t\t\t\t#\tputs ctr\n\t\t\t\t\tend\n\t\t\t\tend\n end\n end\n#puts ctr\n if array_mod == 0\n if ctr == array_div\n\t\t\tputs 'TAK'\n else\n puts 'NIE'\n end\n else\n if ctr == array_div+1\n\t\t\tputs 'TAK'\n else\n puts 'NIE'\n end\n end\n\nend "}, {"source_code": "s = gets.strip\nputs s == s.tr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','#d#b##########oqp####vwx##A######HI###M#O####TUVWXY#').reverse ? \"TAK\" :\"NIE\""}, {"source_code": "s = gets.chomp\nputs s == s.tr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','!d!b!!!!!!!!!!oqp!!!!vwx!!A!!!!!!HI!!!M!O!!!!TUVWXY!').reverse ? \"TAK\" :\"NIE\""}, {"source_code": "s=gets.chomp;puts s==s.tr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','#d#b##########oqp####vwx##A######HI###M#O####TUVWXY#').reverse ? :TAK : :NIE"}], "negative_code": [{"source_code": "s = gets.strip\nmirrored = [\"A\", \"b\", \"d\", \"H\", \"I\", \"i\", \"l\", \"M\", \"m\", \"n\", \"O\", \"o\", \"p\", \"T\", \"U\", \"u\", \"V\", \"v\", \"W\", \"w\", \"X\", \"x\", \"Y\"]\nmirror_of = [\"A\", \"d\", \"b\", \"H\", \"I\", \"i\", \"l\", \"M\", \"m\", \"n\", \"O\", \"o\", \"q\", \"T\", \"U\", \"u\", \"V\", \"v\", \"W\", \"w\", \"X\", \"x\", \"Y\"]\ni = 0\nj = s.length - 1\npalindrom = true\nwhile i <= j\n l = mirrored.index s[i]\n r = mirror_of.index( s[j] )\n palindrom = false if l.nil? || r.nil? || l != r\n i += 1\n j -= 1\nend\nif palindrom\n puts \"TAK\"\nelse\n puts \"NIE\"\nend\n"}, {"source_code": "s = gets.strip\nmirrored = [\"A\", \"b\", \"d\", \"H\", \"I\", \"M\", \"O\", \"o\", \"p\", \"T\", \"U\", \"V\", \"v\", \"W\", \"w\", \"X\", \"x\", \"Y\"]\nmirror_of = [\"A\", \"d\", \"b\", \"H\", \"I\", \"M\", \"O\", \"o\", \"q\", \"T\", \"U\", \"V\", \"v\", \"W\", \"w\", \"X\", \"x\", \"Y\"]\ni = 0\nj = s.length - 1\npalindrom = true\nwhile i < j\n l = mirrored.index s[i]\n r = mirror_of.index( s[j] )\n palindrom = false if l.nil? || r.nil? || l != r\n i += 1\n j -= 1\nend\nif palindrom\n puts \"TAK\"\nelse\n puts \"NIE\"\nend\n"}, {"source_code": "s = gets.strip\nmirrored = [\"A\", \"b\", \"d\", \"H\", \"I\", \"i\", \"M\", \"m\", \"n\", \"O\", \"o\", \"p\", \"T\", \"U\", \"u\", \"V\", \"v\", \"W\", \"w\", \"X\", \"x\", \"Y\"]\nmirror_of = [\"A\", \"d\", \"b\", \"H\", \"I\", \"i\", \"M\", \"m\", \"n\", \"O\", \"o\", \"q\", \"T\", \"U\", \"u\", \"V\", \"v\", \"W\", \"w\", \"X\", \"x\", \"Y\"]\ni = 0\nj = s.length - 1\npalindrom = true\nwhile i <= j\n l = mirrored.index s[i]\n r = mirror_of.index( s[j] )\n palindrom = false if l.nil? || r.nil? || l != r\n i += 1\n j -= 1\nend\nif palindrom\n puts \"TAK\"\nelse\n puts \"NIE\"\nend\n"}, {"source_code": "s = gets.strip\nmirrored = [\"A\", \"b\", \"d\", \"H\", \"I\", \"M\", \"O\", \"o\", \"p\", \"T\", \"U\", \"V\", \"v\", \"W\", \"w\", \"X\", \"x\", \"Y\"]\nmirror_of = [\"A\", \"d\", \"b\", \"H\", \"I\", \"M\", \"O\", \"o\", \"q\", \"T\", \"U\", \"V\", \"v\", \"W\", \"w\", \"X\", \"x\", \"Y\"]\ni = 0\nj = s.length - 1\npalindrom = true\nwhile i <= j\n l = mirrored.index s[i]\n r = mirror_of.index( s[j] )\n palindrom = false if l.nil? || r.nil? || l != r\n i += 1\n j -= 1\nend\nif palindrom\n puts \"TAK\"\nelse\n puts \"NIE\"\nend\n"}, {"source_code": "word = gets.to_s\nchar_array = word.chars.to_a\nlen = char_array.length-1\narray_div = len/2\narray_mod = len%2\nchar_valid = \"AbdHIMOopqTUVvWwXxYy\".chars.to_a\n#puts len\n#puts array_div\n#puts array_mod\nctr = 0\nif (1 <= len) && (len <= 1000)\n\tif array_mod == 0\n\t\t\tfor i in 0..array_div-1\n\t\t\t\tif char_valid.include?(char_array[i])\n\t\t\t\t\tif ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))\n ctr += 1\n #puts 'a'\n #puts ctr\n elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))\n ctr += 1\n #puts 'b'\n #puts ctr\n elsif (char_array[i] == char_array[len-1-i] && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))\n\t\t\t\t\t\tctr += 1\n # puts 'c'\n #puts ctr\n\n\t\t\t\t\tend\n\t\t\t\tend\n end\nelse\n\t\t\tfor i in 0..array_div\n\t\t\t\tif char_valid.include?(char_array[i])\n\t\t\t\t\tif ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'a'\n\t\t\t\t\t#\tputs ctr\n elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'b'\n\t\t\t\t\t#\tputs ctr\n elsif (char_array[i] == char_array[len-1-i] && i != len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'c'\n\t\t\t\t\t#\tputs ctr\n elsif(i == len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'd'\n\t\t\t\t\t#\tputs ctr\n\t\t\t\t\tend\n\t\t\t\tend\n end\n end\n#puts ctr\n if array_mod == 0\n if ctr == array_div\n\t\t\tputs 'TAK'\n else\n puts 'NIE'\n end\n else\n if ctr == array_div+1\n\t\t\tputs 'TAK'\n else\n puts 'NIE'\n end\n end\n\nend "}, {"source_code": "word = gets.to_s\nchar_array = word.chars.to_a\nlen = char_array.length-1\narray_div = len/2\narray_mod = len%2\nchar_valid = \"AbdHIMOopqTUVvWwXxYy\".chars.to_a\n#puts len\n#puts array_div\n#puts array_mod\nctr = 0\nif (1 <= len) && (len <= 1000)\n\tif array_mod == 0\n\t\t\tfor i in 0..array_div-1\n\t\t\t\tif char_valid.include?(char_array[i])\n\t\t\t\t\tif ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))\n ctr += 1\n #puts 'a'\n #puts ctr\n elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))\n ctr += 1\n #puts 'b'\n #puts ctr\n elsif (char_array[i] == char_array[len-1-i] && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))\n\t\t\t\t\t\tctr += 1\n # puts 'c'\n #puts ctr\n\n\t\t\t\t\tend\n\t\t\t\tend\n end\nelse\n\t\t\tfor i in 0..array_div\n\t\t\t\tif char_valid.include?(char_array[i])\n\t\t\t\t\tif ((char_array[i] == 'q' && char_array[len-1-i] == 'p') || (char_array[i] == 'p' && char_array[len-1-i] == 'q'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'a'\n\t\t\t\t\t#\tputs ctr\n elsif ((char_array[i] == 'd' && char_array[len-1-i] == 'b') || (char_array[i] == 'b' && char_array[len-1-i] == 'd'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'b'\n\t\t\t\t\t#\tputs ctr\n elsif (char_array[i] == char_array[len-1-i] && i != len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'c'\n\t\t\t\t\t#\tputs ctr\n elsif(i == len-1-i && (char_array[i] != 'b' && char_array[i] != 'd' && char_array[i] != 'p' && char_array[i] != 'q'))\n\t\t\t\t\t\tctr += 1\n\t\t\t\t\t#\tputs 'd'\n\t\t\t\t\t#\tputs ctr\n\t\t\t\t\tend\n\t\t\t\tend\n end\n end\n#puts ctr\n if array_mod == 0\n if ctr == array_div\n\t\t\tputs 'TAK'\n else\n puts 'NEI'\n end\n else\n if ctr == array_div+1\n\t\t\tputs 'TAK'\n else\n puts 'NEI'\n end\n end\n\nend "}], "src_uid": "bec2349631158b7dbfedcaededf65cc2"} {"source_code": "n,k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nt = a.sort.reverse\nn.times do |i|\n len = 0\n flg = true\n t.each do |j|\n len += j if flg\n flg = !flg\n end\n if len > k\n t.delete_at(t.find_index(a[-i-1]))\n else\n p n-i\n break\n end\nend\n", "positive_code": [{"source_code": "f=\"gets.split.map &:to_i\"\nn,k=eval f\na=eval f\nn-=1 while k<(a[0...n].sort.values_at(*(-n|1...0).step(2)).reduce &:+)\np n"}, {"source_code": "N, H = gets.split.map(&:to_i)\nA = gets.split.map(&:to_i)\n\ndef f(k)\n list = A.take(k).sort\n height = 0\n\n until list.empty?\n a, b = list.pop(2)\n h = [a, b || 0].max\n\n height += h\n end\n\n height <= H\nend\n\nputs [*1..N].reverse.bsearch { |k| f(k) }\n"}, {"source_code": "n,h = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nmin = 0\nmax = n+1\nwhile max-min > 1\n mid = (min+max)/2\n b = a[0,mid].sort.reverse\n x = 0\n for i in 0..(mid-1)/2\n x += b[i*2]\n end\n if x > h\n max = mid\n else\n min = mid\n end\nend\nputs min"}, {"source_code": "(n,h),a=$<.map{|s|s.split.map &:to_i}\np (1...n).find{|i|r=i%2;h max \nmax=temp\nend\ntemp=1\nend\nend\nif temp > max \nmax=temp\nend\nputs \"#{max}\""}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp\nif b==\"01\"\nt=-1\nelse\nt=1\nend\ntemp=1\nmax=1\n(a-1).times do\nte=gets.chomp\nif (te==\"01\" && t==1 )|| (te==\"10\" && t==-1)\ntemp+=1\nelsif (te==\"01\" && t==-1) || (te==\"10\" && t==1)\nt=t*-1\nif temp > max \nmax=temp\nend\ntemp=1\nend\nend\nif temp > max \nmax=temp\nend\nputs \"#{max}\""}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp\nif b==\"01\"\nt=-1\nelse\nt=1\nend\ntemp=1\nmax=1\n(a-1).times do\nte=gets.chomp\nif (te==\"01\" && t==-1 )|| (te==\"10\" && t==1)\ntemp+=1\nelsif (te==\"01\" && t==1) || (te==\"10\" && t==-1)\nt=t*-1\nif temp > max \nmax=temp\nend\ntemp=1\nend\nend\n\nputs \"#{max}\""}, {"source_code": "t = gets.to_i\nlast = '-'\nans = 0\nt.times do \n g = gets.strip\n if g[1] == last\n ans += 1\n else\n last = g[1]\n end\nend\nputs (t == 1 ? 0 : ans)"}, {"source_code": "t = gets.to_i\nlast = '-'\nans = 0\nt.times do \n g = gets.strip\n if g[1] == last\n ans += 1\n else\n last = g[1]\n end\nend\nputs ans \n"}, {"source_code": "t = gets.to_i\nlast = '-'\nans = 0\nt.times do \n g = gets.strip\n if g[1] == last\n ans += 1\n else\n last = g[1]\n end\nend\nputs (t == 1 ? 1 : ans) \n"}, {"source_code": "num = gets.chomp.to_i\ninput = []\nans = 0\n\n(0...num).each do |iterNum|\n\tinput << gets.chomp\nend\n\n(0...(num - 1)).each do |iterNum|\n\tans += 1 if input[iterNum] == input[iterNum + 1]\nend\n\nif num == 1\n\tputs 1\n\texit\nend\n\nputs ans"}, {"source_code": "num = gets.chomp.to_i\ninput = []\nans = 0\n\n(0...num).each do |iterNum|\n\tinput << gets.chomp\nend\n\n(0...(num - 1)).each do |iterNum|\n\tans += 1 if input[iterNum] == input[iterNum + 1]\nend\n\nputs ans"}, {"source_code": "num = gets.chomp.to_i\ninput = []\nans = 0\n\n(0...num).each do |iterNum|\n\tinput << gets.chomp\nend\n\n(0...(num - 1)).each do |iterNum|\n\tans += 1 if input[iterNum] == input[iterNum + 1]\nend"}, {"source_code": "\t\n\n\t\nn = gets.strip.to_i\n\ntmp = 1\ncnt = 0 \ni = 0\nlst = gets.strip\n\nwhile i < n-1\n\tfst = gets.strip\n\n\tif (fst[0] != lst[1])\n\t\ttmp += 1\n\telse\n\t\tcnt = (cnt > tmp ? cnt : tmp)\n\t\ttmp = 1 \n\tend\n\tlst = fst\n\ti += 1\nend\n\nputs cnt\n\n\n\n\n\n\n\n"}, {"source_code": "p $<.drop(1).each_cons(2).count{|a,b|a!=b}"}, {"source_code": "n = gets.to_i\n\nlast = \"00\"\nans = 0\n\n(0...n).each do |i|\n cur = gets.to_s\n if (last == cur)\n ans += 1\n end\n last = cur\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\n\nlast = \"00\"\nans = 0\n\n(0...n).each do |i|\n cur = gets.to_s\n if (last == cur)\n ans += 1\n end\n last = cur\nend\n\nif (ans == 0)\n puts 1\nelse \n puts ans\nend"}, {"source_code": "n = $stdin.readline.to_i\na = $stdin.readline.scan(/./).map(&:to_i)\nk = 0\n\n(n-1).times do\n b = $stdin.readline.scan(/./).map(&:to_i)\n k+=1 if a.last != b.first\n a = b\nend\n\nk = 1 if k==0\nputs k"}, {"source_code": "n = $stdin.readline.to_i\na = $stdin.readline.scan(/./).map(&:to_i)\nk = 0\n\n(n-1).times do\n b = $stdin.readline.scan(/./).map(&:to_i)\n k+=1 if a.last != b.first\n a = b\nend\n\nputs k"}, {"source_code": "n = gets.to_i\nret, temp, prev = 0, 0, nil\nn.times do\n mag = gets\n temp += 1\n if mag != prev || prev == nil\n \tret = [ret, temp].max\n \ttemp = 0\n end\n prev = mag\nend\nputs ret"}, {"source_code": "n = gets.to_i\na = []\nn.times do \n a << gets\nend\nis_one = a[0] == \"10\"\ncnt = 0\na.each do |mag|\n next if mag == a[0]\n if (is_one && mag[0] == '0') || (!is_one && mag[0]=='1')\n cnt+=1\n end\nend\nputs(cnt+1)"}], "src_uid": "6c52df7ea24671102e4c0eee19dc6bba"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\nbin = Hash.new(0)\na.each{|x| bin[x] += 1}\n\nnum = 0\n1.upto(10){|x| num += bin[x]*bin[-x]}\nnum += bin[0]*(bin[0]-1)/2\n\np num\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nmp = Hash.new\nmp.default = 0\na.each { |i|\n mp[i] += 1\n}\nans = mp[0] * (mp[0]-1)/2\n10.times { |i|\n ans += mp[i+1] * mp[-i-1]\n}\np ans\n"}, {"source_code": "\nn=gets\nt=gets.split.map(&:to_i)\ncnt=Hash.new\ncnt.default=0\nt.each{|i|\n cnt[i]+=1\n}\nans=cnt[0]*(cnt[0]-1)/2\nfor i in 1..10\n ans+=cnt[i]*cnt[-i]\nend\np ans\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\narr = gets.split.map(&:to_i)\ndict = Hash.new(0)\narr.each do |i| \n dict[i] += 1\nend\n\nans = 0\nans += dict[0]*(dict[0]-1)/2 if dict[0] >= 2\n(1..10).each do |i|\n ans += dict[i]*dict[-i]\nend\n\np ans\n"}, {"source_code": "gets\na = {}\ngets.chomp.split(' ').each do |e|\n if not a.has_key?(e)\n a[e] = 0\n end\n a[e] += 1\nend\n\nret = 0\n\nif a.has_key?(\"0\")\n n = a[\"0\"] - 1\n ret += n * (n + 1) / 2\nend\n\n(1..10).map{|e| e.to_s}.each do |i|\n if a.has_key?(i) and a.has_key?('-' + i)\n ret += a[i] * a['-' + i]\n end\nend\n\np ret\n"}, {"source_code": "a = Hash.new(0)\ngets\ngets.split.map(&:to_i).each { |e| a[e]+=1 }\np ((1..10).map { |x| a[x]*a[-x] }.inject(:+)) + a[0]*(a[0]-1)/2"}, {"source_code": "m = gets.chomp.to_i\n\na = gets.chomp.split(' ').map &:to_i\n\nh = Hash.new(0)\na.each { | v | h.store(v, h[v]+1) }\n\nk = 2\nn = h[0]\nif k > n\n t = 0\nelse\n t = n*(n-1)/2\nend\n\nh.keys.keep_if{|x| x>0}.each do |key|\n t+=h[-key]*h[key]\nend\n\nputs t"}, {"source_code": "n=gets.to_i\ndata=gets.split.map(&:to_i)\n\nhs=Hash.new(0)\ndata.each do |val|\n\ths[val]+=1\nend\n\nans=hs[0]*(hs[0]-1)/2\n(-10..-1).each do |i|\n\ta,b=hs[i], hs[i*(-1)]\n\tans+=a*b\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ns = 0\n(1..10).each{|i|\n s = s + a.find_all{|e| e == i}.size * a.find_all{|e| e == -i}.size\n a = a - [i, -i]\n}\nb = a.find_all{|e| e == 0}.size\ns = s + b * (b - 1)/2\np s"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ns = 0\n(1..10).each{|i|\n s = s + a.find_all{|e| e == i}.size * a.find_all{|e| e == -i}.size\n a = a - [i, -i]\n}\nb = a.size\ns = s + b * (b - 1)/2\np s"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ns = 0\n(1..10).each{|i|\n s = s + a.find_all{|e| e == i}.size * a.find_all{|e| e == -i}.size\n}\nb = a.find_all{|e| e == 0}.size\ns = s + b * (b - 1)/2\np s"}, {"source_code": "number = gets.strip.to_i\ncount = {}\ngets.strip.split(' ').map(&:to_i).each do |num|\n count[\"#{num}\"] ||= 0\n count[\"#{num}\"] += 1\nend\n\nresult = 0\n1.upto(10).each do |val|\n count[\"#{val}\"] ||= 0\n count[\"#{-val}\"] ||= 0\n result += count[\"#{val}\"] * count[\"#{-val}\"]\nend\n\nif !count[\"0\"].nil? && count[\"0\"] >= 2\n result += (count[\"0\"] - 1) * count[\"0\"] / 2\nend\n\nputs result\n"}, {"source_code": "gets # Skip the first line\nhm = gets.split.map { |x| x.to_i }.inject(Hash.new(0)) { |h, e| h[e] += 1; h }\nc = 0\nfor i in -10...0\n if hm.has_key?(i) && hm.has_key?(-i)\n c += hm[i] * hm[-i]\n end\nend\nif hm.has_key?(0)\n n = hm[0] - 1\n c += n * (n + 1) / 2\nend\nputs c"}, {"source_code": "c=Array.new(30,0)\ngets\ngets.split.map(&:to_i).each{|t|c[t]+=1}\np 1.upto(10).map{|t|c[t]*c[-t]}.inject(:+)+(c[0]*(c[0]-1)/2)"}], "negative_code": [{"source_code": "m = gets.chomp.to_i\n\na = gets.chomp.split(' ').map &:to_i\n\nh = Hash.new(0)\na.each { | v | h.store(v, h[v]+1) }\n\nk = 2\nn = h[0]\nif k > n\n t = 0\nelse\n t = (1..n).inject(:*)/2/((1..(n-2)).inject(:+) || 1)\nend\n\nh.keys.keep_if{|x| x>0}.each do |key|\n t+=h[-key]*h[key]\nend\n\nputs t"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ns = 0\nn.times{|i|\n (i..(n-1)).each{ |j|\n if a[i] + a[j] == 0 then\n s = s + 1 \n end \n } \n}\np s"}], "src_uid": "f3dde329830d8c479b3dab9d5df8baf5"} {"source_code": "t = gets.chomp.to_i\r\n\r\nfor i in (1..t)\r\n n = gets.chomp.to_i\r\n a = (gets.chomp.split.map {|e| e.to_i}).reverse\r\n x = 0\r\n for j in (1..n-1)\r\n if a[j] != a[0]\r\n break\r\n end\r\n x += 1\r\n end\r\n ans = 0\r\n until x >= n-1\r\n # Aplique a operacao em que os valores (0, x) s\u00e3o copiados para (x+1, 2x+1)\r\n x = [n-1, 2*x+1].min\r\n ans += 1\r\n for j in (x+1..n-1)\r\n if a[j] != a[0]\r\n break\r\n end\r\n x += 1\r\n end\r\n end\r\n puts ans\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n xs = gets.split.map(&:to_i)\n\n ans = 0\n g = n - 1\n\n while g > 0\n if xs[g - 1] == xs[n - 1]\n g -= 1\n else\n g = 2 * g - n\n ans += 1\n end\n end\n\n p ans\nend\n"}], "negative_code": [], "src_uid": "dc10b869293df2b7a557262c805635ba"} {"source_code": "def max(a,b)\n return a>b ? a : b\nend\n\ns=gets\nn=s.length\nres=eval(s)\nfor i in -1..n-1 do\n if i==-1 || s[i]=='*'\n for j in i+1..n do\n if j==n || s[j]=='*'\n res=max(res,eval(s[0...i+1]+'('+s[i+1...j]+')'+s[j...n]))\n end\n end\n end\nend\nputs res\n", "positive_code": [{"source_code": "s = gets.chomp.to_s\ns = \"1*\" + s + \"*1\"\n#p s\na = (0...s.length).find_all{ |i| s[i] == '*' }\nans = -1\nfor i in a\n for j in a\n if( i != j )\n if( i < j )\n k = i\n else k = j\n end\n l = i + j - k\n x = s[0..k] + \"(\" + s[k+1..l-1] + \")\" + s[l..s.length]\n # p \"#{x} #{i} #{j} #{k} #{l} \"\n if( eval(x) > ans )\n ans = eval(x)\n end\n end\n end\nend\nputs ans\n"}, {"source_code": "c = gets.strip\nmax = eval(c)\n\nlpos = [0]\nrpos = [c.length]\nc.chars.each_with_index do |ci, idx|\n if ci == '*'\n lpos.push idx + 1\n rpos.push idx\n end\nend\n\nlpos.each do |l|\n rpos.each do |r|\n next if l > r\n exp = c[0...l] + '(' + c[l...r] + ')' + c[r...c.length]\n max = [max, eval(exp)].max\n end\nend\np max"}], "negative_code": [{"source_code": "def max(a,b)\n return a>b ? a : b\nend\n\ns=gets\nn=s.length\nres=eval(s)\nfor i in -1..n-1 do\n if i==-1 || s[i]=='*'\n for j in i+1..n do\n if j==n || s[j]=='*'\n res=max(res,eval(s[0,i+1]+'('+s[i+1,j]+')'+s[j,n-1]))\n end\n end\n end\nend\nputs res\n"}], "src_uid": "39dbd405be19c5a56c2b97b28e0edf06"} {"source_code": "factor = 1.000000011\nn, t = gets.split(\" \").map { |x| x.to_i }\n\nans = n * factor ** t\nputs ans.round(16)", "positive_code": [{"source_code": "a,b=gets.split.map(&:to_f);p a*1.000000011**b"}, {"source_code": "n, t = gets.split.map(&:to_i)\nputs(n * (1.000000011 ** t))"}, {"source_code": "a=gets.chomp.split(' ')\nb=a[0].to_i*(1.000000011**a[1].to_i)\nputs \"#{b}\""}, {"source_code": "n, t=gets.split.map &:to_i\np 1.000000011**t * n"}, {"source_code": "arg = STDIN.gets\nargs = arg.split\nn = args[0].to_i\nt = args[1].to_i\n\nprintf(\"%.6f\", (n * (1.000000011 ** t)))\nputs"}, {"source_code": "factor = 1.000000011\nn, t = gets.split(\" \").map { |x| x.to_i }\n\nans = n * factor ** t\nputs ans.round(16)"}, {"source_code": "inp = gets.chomp.split(' ');\nn = inp[0].to_i\nt = inp[1].to_i\n\nans = n * (1.000000011 ** t)\n\np ans\n"}, {"source_code": "n , t = gets.chomp.split.map(&:to_i)\nans = n\nref = 1.000000011\nhelp = ref ** t\nans = ans * help\nputs ans\n"}, {"source_code": "a=gets.chomp.split(' ')\nb=a[0].to_i*(1.000000011**a[1].to_i)\nputs \"#{b}\" "}, {"source_code": "a,b=gets.split.map(&:to_f);p a*(1+11e-9)**b\n"}, {"source_code": "a,b=gets.split.map(&:to_f);p a*(1+11e-9)**b"}, {"source_code": "a,b=gets.split.map(&:to_f);p a*1.000000011**b"}, {"source_code": "a,b=gets.split.map(&:to_f);p a*(1+11e-9)**b\n"}], "negative_code": [], "src_uid": "36ad784f23bd1e8e579052642a6e9244"} {"source_code": "def delp(s)\n k = -1\n while (k = s.index(\" \", k+1)) do\n k += 1\n\n while s[k] == \" \" do\n s = s[0...k] + s[k+1..-1]\n end\n end\n return s\nend\n\ndef cpz (s,z)\n str = \"\"\n while s.size > 0 do\n if (k = s.index(z)) then\n if s[k+1] != \" \" then\n s = s[0..k] + \" \" + s[k+1..-1]\n end\n if s[k-1] == \" \" then\n s = s[0...k-1] + s[k..-1]\n end\n str += s[0..k]\n s = s[k+1..-1]\n else\n str += s\n s = \"\"\n end\n end\n return str\nend\n\ns = gets.chomp\ns = delp(s)\ns = cpz(s,\".\")\ns = cpz(s,\",\")\ns = cpz(s,\"!\")\ns = cpz(s,\"?\")\nputs s", "positive_code": [{"source_code": "puts gets().gsub(/[ ]+/, ' ').gsub(/[ ]*([.,!?])[ ]*/, '\\1 ')\n"}, {"source_code": "str=gets\ns=str.chars.to_a\nres=''\ni=0\ndef isPunc(str)\n a=(\"a\"..\"z\").to_a+(\"A\"..\"X\").to_a\n a.each{|c|\n if str==c then\n return false\n end\n }\n return true\nend\nwhile i 0\n\n (0...s.size).each do |i|\n if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'\n if i == 0\n fin = \"#{fin[0...fin.length-1]}#{s[i]} \"\n else\n fin += \"#{s[i]} \"\n end\n else\n fin += s[i]\n end\n end\n end\n\n puts fin\nend"}, {"source_code": "def punctuation\n str = \"galileo galilei was an italian physicist ,mathematician,astronomer\"#gets.strip\n\n str = str.split(' ').map{|s| s.strip}\n fin = ''\n str.each_with_index do |s, ind|\n fin += \" \" if ind > 0\n\n (0...s.size).each do |i|\n if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'\n fin = \"#{fin[0...fin.length-1]}#{s[i]} \"\n else\n fin += s[i]\n end\n end\n end\n\n p fin\nend\n\npunctuation"}, {"source_code": "def punctuation\n str = gets.strip\n\n str = str.split(' ').map{|s| s.strip}\n fin = ''\n str.each_with_index do |s, ind|\n fin += \" \" if ind > 0\n\n (0...s.size).each do |i|\n if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'\n if i == 0\n fin = \"#{fin[0...fin.length-1]}#{s[i]} \"\n else\n fin += \"#{s[i]} \"\n end\n else\n fin += s[i]\n end\n end\n end\n\n puts fin# == 'galileo galilei was an italian physicist, mathematician, astronomer'\nend"}, {"source_code": "def punctuation\n str = gets.strip\n\n str = str.split(' ').map{|s| s.strip}\n fin = ''\n str.each_with_index do |s, ind|\n fin += \" \" if ind > 0\n\n (0...s.size).each do |i|\n if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'\n fin = \"#{fin[0...fin.length-1]}#{s[i]} \"\n else\n fin += s[i]\n end\n end\n end\n\n puts fin\nend\n\npunctuation"}, {"source_code": "def punctuation\n str = gets.strip\n\n str = str.split(' ').map{|s| s.strip}.join(' ')\n fin = ''\n\n i = 0\n while i < str.length\n if str[i] == '.' or str[i] == ',' or str[i] == '!' or str[i] == '?'\n if str[i-1] == ' '\n str[i-1] = ''\n i -= 1\n end\n\n unless str[i+1] == ' '\n str = \"#{str[0..i]} #{str[i+1..-1]}\"\n i += 1\n end\n end\n i += 1\n end\n\n print str\nend"}, {"source_code": "def punctuation\n str = gets.strip\n\n str = str.split(' ').map{|s| s.strip}\n fin = ''\n str.each_with_index do |s, ind|\n fin += \" \" if ind > 0\n\n (0...s.size).each do |i|\n if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'\n if i == 0\n fin = \"#{fin[0...fin.length-1]}#{s[i]} \"\n else\n fin += \"#{s[i]} \"\n end\n else\n fin += s[i]\n end\n end\n end\n\n print fin\nend\n\npunctuation"}, {"source_code": "def punctuation\n str = gets.strip\n\n str = str.split(' ').map{|s| s.strip}\n fin = ''\n str.each_with_index do |s, ind|\n fin += \" \" if ind > 0\n\n (0...s.size).each do |i|\n if s[i] == '.' or s[i] == ',' or s[i] == '!' or s[i] == '?'\n fin = \"#{fin[0...fin.length-1]}#{s[i]} \"\n else\n fin += s[i]\n end\n end\n end\n\n p fin\nend\n\npunctuation"}, {"source_code": "input = STDIN.read\n\ninput.gsub!(/ +/, ' ')\n\ninput.each_char.with_index do |v, k|\n\tif v == \",\"\n\t\tif input[k - 1] == \" \"\n\t\t\tinput[k] = \" \"\n\t\t\tinput[k - 1] = \",\"\n\t\telsif input[k + 1] != \" \"\n\t\t\tinput[k] = \", \"\n\t\tend\n\tend\nend\n\nSTDOUT.puts input"}, {"source_code": "input = STDIN.read.gsub(/ +/, ' ')\n\nchars = \".,?!:;\"\n\ninput.each_char.with_index do |v, k|\n\tif chars.include? v\n\t\tif input[k - 1] == \" \"\n\t\t\tinput[k - 1] = v\n\t\t\tinput[k + 1] != \" \" ? input[k] = \" \" : input[k] = \"\"\n\t\telsif input[k + 1] != \" \"\n\t\t\tinput[k] = v + \" \"\n\t\tend\n\tend\nend\n\nSTDOUT.puts input"}], "src_uid": "8c26daa1eed2078af3b32737da0a0f84"} {"source_code": "gets.strip.to_i.times do\n h, m = gets.strip.split(' ').map(&:to_i)\n puts 24 * 60 - (h * 60 + m)\nend", "positive_code": [{"source_code": "readline.to_i.times do\n h, m = readline.split.map(&:to_i)\n p((24-h)*60-m)\nend"}, {"source_code": "gets.to_i.times do\n\ta, b = gets.split.map(&:to_i)\n\tputs 24 * 60 - (a * 60 + b)\nend"}, {"source_code": "gets.to_i.times do\n h, m = gets.split.map(&:to_i)\n puts (23*60+60)-(h*60+m)\nend\n"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a\"NO\",1=>\"aabb\",2=>\"abab\",4=>\"abba\",7=>\"aaaa\"}[ans])"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n if b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou][^aeiou]*){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend\n\n"}, {"source_code": "def check_quatrain(k)\n\n\treg = Regexp.new(\"([aiueo][^aiueo]*){#{k}}$\")\n\n\tsuffixes = []\n\t4.times do\n\t\tif s = gets.slice(reg)\n\t\t\tsuffixes << s\n\t\telse\n\t\t\tsuffixes = []\n\t\t\tbreak\n\t\tend\n\tend\n\n\tcase suffixes.uniq.size\n\twhen 1 then\n\t\t\"aaaa\"\n\twhen 2 then\n\t\tif suffixes[0] == suffixes[1] && suffixes[2] == suffixes[3]\n\t\t\t\"aabb\"\n\t\telsif suffixes[0] == suffixes[2] && suffixes[1] == suffixes[3]\n\t\t\t\"abab\"\n\t\telsif suffixes[0] == suffixes[3] && suffixes[1] == suffixes[2]\n\t\t\t\"abba\"\n\t\telse\n\t\t\t\"NO\"\n\t\tend\n\telse\n\t\t\"NO\"\n\tend\nend\n\nn, k = gets.split.map { |x| Integer(x)}\n\ncurrent = \"aaaa\"\nn.times do |i|\n\tresult = check_quatrain(k)\n\tif result == \"aaaa\" || result == current\n\t\tnext\n\telsif current == \"aaaa\"\n\t\tcurrent = result\n\t\tnext\n\tend\n\tcurrent = \"NO\"\n\tbreak\nend\n\nputs current\n"}], "negative_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets.gsub(/[^aeiou]/, '').reverse[0, m]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0].size == m && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j].size == m && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nb = [true] * 4\nn.times do\n a = Array.new(4){gets[/([aeiou].*?){#{m}}$/]}\n 1.upto(3) do |i|\n if b[i]\n b[i] &= a[0] && a[0] == a[i]\n j = i != 1 ? 1 : 2\n k = i != 3 ? 3 : 2\n b[i] &= a[j] && a[j] == a[k]\n end\n end\nend\n\nif b.all?\n puts :aaaa\nelsif b[1]\n puts :aabb\nelsif b[2]\n puts :abab\nelsif b[3]\n puts :abba\nelse\n puts :NO\nend\n"}, {"source_code": "n, k = gets.split.collect{|x| x.to_i}\n\nold_scheme = \"aaaa\"\n(1..n).each{\n scheme = nil\n lines = Array.new(4) { gets.chomp }\n \n lines.each_index{|i|\n pos = []\n lines[i].scan(/[aeiou]/){pos << $~.begin(0)}\n if pos[-k].nil?\n puts \"NO\"\n exit\n end\n lines[i] = lines[i][pos[-k]..-1]\n }\n\n scheme = \"aabb\" if lines[0] == lines[1] and lines[2] == lines[3]\n scheme = \"abab\" if lines[0] == lines[2] and lines[1] == lines[3]\n scheme = \"abba\" if lines[0] == lines[3] and lines[1] == lines[2]\n scheme = \"aaaa\" if lines[0] == lines[1] and lines[1] == lines[2] and lines[2] == lines[3] \n if scheme.nil? or (old_scheme != scheme and old_scheme != \"aaaa\")\n puts \"NO\"\n exit\n end\n \n old_scheme = scheme\n}\n\nputs old_scheme"}], "src_uid": "a17bac596b1f060209534cbffdf0f40e"} {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\na=n.times.map{gets.split}\nperm=gets.split.map{|e|e.to_i-1}\na=perm.map{|e|a[e]}\ncur=a[0].min\nputs (1...n).all?{|i|\n\tcur=a[i].select{|e|e>=cur}.min\n} ? :YES : :NO", "positive_code": [{"source_code": "n=gets.to_i\na=Array.new(n)\nfor i in 0...n\n\ta[i]=gets.chomp.split.sort\nend\ncur,ans='','YES'\nfor i in gets.chomp.split.map(&:to_i)\n\tif a[i-1][0] > cur\n\t\tcur = a[i-1][0]\n\telsif a[i-1][1] > cur\n\t\tcur = a[i-1][1]\n\telse\n\t\tans = 'NO'\n\tend\nend\nputs ans"}, {"source_code": "\ndef can_p(p, names, use_n)\n can \nend\n\nn = gets.to_i\nnames = (1..n).map{gets.split(\" \")}\np = gets.split(\" \").map(&:to_i)\n\ncan_n = true\ncan_sn = true\n\n(1..n-1).each do |i|\n prev_n, prev_sn = names[p[i-1] - 1]\n cur_n, cur_sn = names[p[i] - 1]\n can_n_next = can_n && cur_n > prev_n || can_sn && cur_n > prev_sn\n can_sn_next = can_n && cur_sn > prev_n || can_sn && cur_sn > prev_sn\n can_n, can_sn = can_n_next, can_sn_next\n break if ! can_n && ! can_sn\nend\n\nans = can_n || can_sn ? \"YES\" : \"NO\"\nputs ans\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.sort}.unshift(nil)\np = gets.split.map(&:to_i)\ns = ''\nans = p.each do |i|\n if a[i][0] > s\n s = a[i][0]\n elsif a[i][1] > s\n s = a[i][1]\n else\n break\n end\nend\nputs ans ? 'YES' : 'NO'\n"}, {"source_code": "n = gets.to_i\na = [[]] + n.times.map{gets.split.sort}\np = gets.split.map(&:to_i)\ns = []\nans = true\np.each do |i|\n if i == p[0] || a[i][0] > s.last[0]\n s << a[i]\n elsif a[i].reverse[0] > s.last[0]\n s << a[i].reverse\n else\n ans = false\n break\n end\nend\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "a = []\n(n = gets.to_i).times {\n a << gets.chomp.split\n}\norder = gets.chomp.split.map { |c| c.to_i - 1 }\nlast = a[order[0]]\n(1...n).each { |k|\n cur = []\n a[order[k]].each { |x|\n cur << x if last.any? { |v| x > v }\n }\n if cur.empty?\n puts 'NO'\n exit\n end\n last = cur\n}\nputs 'YES'"}, {"source_code": "n=gets.to_i\nh=[0]\nn.times{h< b\n b=h[i].min\n elsif h[i].max > b\n b=h[i].max\n else\n r=\"NO\"\n break\n end\nend\nputs r"}], "negative_code": [{"source_code": "\ndef can_p(p, names, use_n)\n can \nend\n\nn = gets.to_i\nnames = (1..n).map{gets.split(\" \")}\np = gets.split(\" \").map(&:to_i)\n\nputs \"NAMES: #{names}\"\nputs \"P: #{p}\"\n\ncan_n = true\ncan_sn = true\n\n(1..n-1).each do |i|\n prev_n, prev_sn = names[p[i-1] - 1]\n cur_n, cur_sn = names[p[i] - 1]\n can_n_next = can_n && cur_n > prev_n || can_sn && cur_n > prev_sn\n can_sn_next = can_n && cur_sn > prev_n || can_sn && cur_sn > prev_sn\n can_n, can_sn = can_n_next, can_sn_next\n break if ! can_n && ! can_sn\nend\n\nans = can_n || can_sn ? \"YES\" : \"NO\"\nputs ans\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.chomp}\np = gets.split.map(&:to_i)\ndef change a\n\tname1, name2 = a.split\n\ttmp = name1\n\treturn [name2, tmp].join(\" \")\nend\ndef compare i, j, a\n\t3.times do |k|\n\t\tif a[i-1] > a[j-1]\n\t\t\tif k == 0\n\t\t\t\ta[j-1] = change a[j-1]\n\t\t\telsif k == 1\n\t\t\t\ta[i-1] = change a[i-1]\n\t\t\telsif k == 2\n\t\t\t\ta[j-1] = change a[j-1]\n\t\t\tend\n\t\telsif a[i-1] < a[j-1]\n\t\t\treturn true\n\t\t\tbreak\n\t\tend\n\tend\nend\nn.times do |i|\n\tif compare(p[i], p[i+1], a) == false\n\t\tputs \"NO\"\n\t\tbreak\n\telsif i == p.size - 2\n\t\tputs \"YES\"\n\t\tbreak\n\tend\nend\n"}, {"source_code": "a = []\n(n = gets.to_i).times {\n a << gets.chomp.split\n}\norder = gets.chomp.split.map { |c| c.to_i - 1 }\n(0...n - 1).each { |k|\n i, j = order[k, k + 2]\n unless a[i][0] < a[j][0] || a[i][0] < a[j][1] || a[i][1] < a[j][0] || a[i][1] < a[j][1]\n puts 'NO'\n exit\n end\n}\nputs 'YES'"}], "src_uid": "a48ef749bf54d673772e09025ae806de"} {"source_code": "t=gets.chomp.to_i\r\nt.times do\r\n r = gets.chomp.to_i\r\n if(r>=1900)\r\n puts \"Division 1\"\r\n end\r\n if(r>=1600 && r<=1899)\r\n puts \"Division 2\"\r\n end\r\n if(r>=1400 && r<=1599)\r\n puts \"Division 3\"\r\n end\r\n if(r<=1399)\r\n puts \"Division 4\"\r\n end\r\nend", "positive_code": [{"source_code": "gets.to_i.times {\n\tputs \"Division #{case gets.to_i; when -5000 .. 1399; 4; when 1400 .. 1599; 3;when 1600 .. 1899; 2; else; 1; end;}\"\n} "}, {"source_code": "def division?(n)\n if n <= 1399\n puts \"Division 4\"\n elsif n >= 1400 && n <= 1599\n puts \"Division 3\"\n elsif n >= 1600 && n <= 1899\n puts \"Division 2\"\n else\n puts \"Division 1\"\n end\nend\n\nt = gets.chomp.to_i\n\ninput = []\n(0..t-1).each do |i|\n input.push(gets.chomp.to_i)\nend\n\ninput.each do |i|\n division?(i)\nend"}, {"source_code": "input1 = gets.to_i\r\ninput1.times do\r\n output = [\"Division\"]\r\n case (input = gets.to_i)\r\n when (..1399) then output << \"4\"\r\n when (1400..1599) then output << \"3\"\r\n when (1600..1899) then output << \"2\"\r\n when (1900..) then output << \"1\"\r\n end\r\n puts output.join(\" \")\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n x = if n <= 1399\r\n 4\r\n elsif n <= 1599\r\n 3\r\n elsif n <= 1899\r\n 2\r\n else\r\n 1\r\n end\r\n puts \"Division #{x}\"\r\nend\r\n"}, {"source_code": "t = gets.chomp().to_i\r\n\r\nfor i in 1 .. t \r\n rating = gets.chomp().to_i\r\n if 1900 <= rating\r\n puts \"Division 1\"\r\n elsif 1600 <= rating and rating <= 1899\r\n puts \"Division 2\"\r\n elsif 1400 <= rating and rating <= 1599\r\n puts \"Division 3\"\r\n elsif rating <= 1399\r\n puts \"Division 4\"\r\n end\r\nend"}, {"source_code": "gets.to_i.times do\n a = gets.to_i\n if a>= 1900\n puts \"Division 1\"\n elsif a >= 1600\n puts \"Division 2\"\n elsif a >= 1400\n puts \"Division 3\"\n else\n puts \"Division 4\"\n end\nend"}, {"source_code": "tests = gets.to_i\r\n\r\ntests.times do\r\n\r\n i = gets.to_i\r\n\r\n if i >= 1900\r\n puts \"Division 1\"\r\n elsif 1600 <= i and i <= 1899\r\n puts \"Division 2\"\r\n elsif 1400 <= i and i <= 1599\r\n puts \"Division 3\"\r\n else\r\n puts \"Division 4\"\r\n end\r\nend"}], "negative_code": [], "src_uid": "020c7b64688736ecc5e97d17df2c2605"} {"source_code": "#! ruby\n# try Codeforces Round 325 div2\n# author: Leonardone @ NEETSDKASU\n\nn = gets.to_i\n*a, b = readlines.map{|x| x.chomp.split.map(&:to_i)}\n\nf1 = [[:H2S, n - 1, 1, 0, 0]]\n\nsp = 100 * 100\nans = 100 * 100\nwhile !f1.empty?\n\tf2 = []\n\tf1.each do |f, x, y, c, r|\n\t\tcase f\n\t\twhen :H2S\n\t\t\tif x > 0\n\t\t\t\tnc = c + a[y][x - 1]\n\t\t\t\tif x - 1 == 0 && y == 0\n\t\t\t\t\tif nc < sp\n\t\t\t\t\t\tsp = nc\n\t\t\t\t\t\tf2 << [:S2H, 0, 0, nc, r]\n\t\t\t\t\tend\n\t\t\t\telse\n\t\t\t\t\tf2 << [f, x - 1, y, nc, r]\n\t\t\t\tend\n\t\t\tend\n\t\t\tif y == 1\n\t\t\t\tnc = c + b[x]\n\t\t\t\tif x == 0\n\t\t\t\t\tif nc < sp\n\t\t\t\t\t\tsp = nc\n\t\t\t\t\t\tf2 << [:S2H, 0, 0, nc, x]\n\t\t\t\t\tend\n\t\t\t\telse\n\t\t\t\t\tf2 << [f, x, 0, nc, x]\n\t\t\t\tend\n\t\t\tend\n\t\twhen :S2H\n\t\t\tif x < n - 1\n\t\t\t\tnc = c + a[y][x]\n\t\t\t\tif x + 1 == n - 1 && y == 1\n\t\t\t\t\tans = [ans, nc].min\n\t\t\t\telse\n\t\t\t\t\tf2 << [f, x + 1, y, nc, r]\n\t\t\t\tend\n\t\t\tend\n\t\t\tif y == 0 && r != x\n\t\t\t\tnc = c + b[x]\n\t\t\t\tif x == n - 1\n\t\t\t\t\tans = [ans, nc].min\n\t\t\t\telse\n\t\t\t\t\tf2 << [f, x, 1, nc, r]\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\tf1 = f2\nend\nputs ans\n", "positive_code": [{"source_code": "n=gets.to_i\ncross2=gets.split(\" \").map(&:to_i)\ncross1=gets.split(\" \").map(&:to_i)\ncrossav=gets.split(\" \").map(&:to_i)\n\nt=999999999999999\nfor i in 0...n\n\tfor j in 0...n\n\t\tnext if i == j\n\n\t\tcost = 0\n\t\tcost += (cross1[i..-1].reduce(:+)||0) + crossav[i] + (cross2[0...i].reduce(:+)||0)\n\t\tcost += (cross1[j..-1].reduce(:+)||0) + crossav[j] + (cross2[0...j].reduce(:+)||0)\n\n\t\tt = [t, cost].min\n\tend\nend\n\np t\n"}, {"source_code": "n, first_row_traffic, second_row_traffic, avenue_traffic, sums = \n\tgets.chomp.to_i, \n\tgets.chomp.split(\" \").map(&:to_i).unshift(0), \n\tgets.chomp.split(\" \").map(&:to_i).push(0),\n\tgets.chomp.split(\" \").map(&:to_i),\n\t[]\n\n(n-1).downto 0 do |i|\n\tsum = 0 \n\n\tsum += avenue_traffic[i]\n\t\n\ti.downto 0 do |j|\n\t\tsum += first_row_traffic[j]\n\tend\n\n\ti.upto (n-1) do |j|\n\t\tsum += second_row_traffic[j]\n\tend\n\t\n\tsums << sum\nend\nsums.sort!\nputs (sums[0] + sums[1])"}, {"source_code": "n = gets.chomp.to_i\ntop = gets.split.map{ |x| x.to_i }\nbot = gets.split.map{ |x| x.to_i }\nover = gets.split.map{ |x| x.to_i }\ncost = []\nn.times do |i|\n sum = over[i]\n (0...i).each { |j| sum += top[j] }\n (i...(n-1)).each { |j| sum += bot[j] }\n cost << sum\nend\n\nmax= top.inject(:+) + bot.inject(:+) + over.inject(:+)\nr1 = max\nb1 = 0\nn.times do |i|\n if cost[i] < r1\n r1 = cost[i]\n b1 = i\n end\nend\nr2 = max\nn.times do |i|\n if cost[i] < r2 and i != b1\n r2 = cost[i]\n end\nend\n\nputs r1+r2\n"}, {"source_code": "n = gets.chomp.to_i\nas = []\n2.times do\n as << gets.chomp.split(' ').map(&:to_i)\nend\nbs = gets.chomp.split(' ').map(&:to_i)\n\ncs = []\nfor i in 0..1\n c = [0]\n for j in 1..n - 1\n c << c[j-1] + as[i][j-1]\n end\n cs << c\nend\n\nds = []\nfor i in 0..n-1\n ds << cs[0][i] + bs[i] + cs[1][n-1] - cs[1][i]\nend\n\nds.sort!\nputs ds[0] + ds[1]\n"}, {"source_code": "# coding; utf-8\n\nh = gets.strip.to_i\nfr = gets.strip.split(' ').map(&:to_i)\nsr = gets.strip.split(' ').map(&:to_i)\nav = gets.strip.split(' ').map(&:to_i)\n\ntimes = [ ]\nh.times do |i|\n t = av[i]\n 0.upto(i - 1) { |j| t += fr[j] }\n i.upto(sr.length - 1) { |j| t += sr[j] }\n\n times.push(t)\nend\n\ntimes.sort!\nputs (times[0] + times[1]).to_s\n"}], "negative_code": [], "src_uid": "e3e0625914fdc08950601248b1278f7d"} {"source_code": "def run\n n, x = gets.chomp.split(\" \").map(&:to_i)\n a = gets.chomp.split(\" \").map(&:to_i)\n rich = a.select{|el| el >= x}\n poor = a.select{|el| el < x}.sort_by{|c| -c}\n count = rich.count\n surplus = rich.reduce(0) {|acc, el| acc + (el > x ? el - x : 0)}\n poor.each do |p|\n if surplus >= x - p\n surplus -= (x - p)\n count += 1\n else\n break\n end\n end\n puts count\nend\n\n\ndef main\n t = gets.chomp.to_i\n\n t.times do\n run\n end\nend\n\nmain\n", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n n, x = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i).sort.reverse\n count = 0\n savings_sum = 0\n a.each_with_index do |v, i|\n savings_sum += v\n if savings_sum >= x * (i + 1)\n count += 1\n else\n break\n end\n end\n puts count\nend\n"}, {"source_code": "1.upto(gets.to_i) do\n n, x = gets.split(' ').map(&:to_i)\n a = gets.split(' ').map(&:to_f).sort.reverse\n\n s = 0\n n = a.count { |c| c >= x }\n max = n\n\n a.each_with_index do |e, i|\n s += e\n\n n -= 1 if e >= x\n\n break if s/(i+1) < x\n\n max = [max, n + i + 1].max\n end\n\n puts max\nend\n"}], "negative_code": [], "src_uid": "51f922bb2c51f50b5c3b55725dd7766e"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nif n == 1\n p a[0]**2\nelse\n x = a[0,n/2].inject(:+)\n y = a[n/2,(n+1)/2].inject(:+)\n p x**2 + y**2\nend", "positive_code": [{"source_code": "# Author : Fuad Ashraful Mehmet \n#Date: 18th April\n\ndef solve()\n n=gets.to_i\n ar=gets.split.map(&:to_i).sort\n if n==1\n return ar[0]**2\n else\n xcor=ar[0,n/2].inject(:+)\n ycor=ar[n/2,(n+1)/2].inject(:+)\n \n return xcor**2+ycor**2\n end\nend\n\nans=solve()\nputs ans"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nif n == 1\n p a[0]\nelse\n x = a[0,n/2].inject(:+)\n y = a[n/2,(n+1)/2].inject(:+)\n p x**2 + y**2\nend"}], "src_uid": "f9fbb45e45d3040e3be19a39ea8faa1f"} {"source_code": "#!/usr/bin/ruby1.9\n\ndef display_array(matrix)\n\treturn\n\tmatrix.each do |row|\n\t\tputs row.join(' ')\n\tend\n\tputs\nend\n\ndef swap_row(matrix, a, b, step, lines)\n\tif step == 1\n\t\tlines.push('%d %d %d' % [step, a+1, b+1])\n\telse\n\t\tn = matrix.length\n\t\tlines.push('%d %d %d' % [step, n-a, n-b])\n\tend\n\trow = matrix[a]\n\tmatrix[a] = matrix[b]\n\tmatrix[b] = row\nend\n\ndef sift_down(m, step, lines)\n\tn = m.length\n\tcounts = n.times.collect {|r| [0, 0, r] }\n\tn.times do |r|\n\t\tn.times do |c|\n\t\t\tif m[r][c] == 1\n\t\t\t\tcounts[r][0] += 1\n\t\t\t\tcounts[r][1] = -c\n\t\t\tend\n\t\tend\n\tend\n\tcounts.sort!\n\n\ttarget2found = Array.new(n, 0)\n\tfound2target = Array.new(n, 0)\n\tn.times do |target|\n\t\tfound = counts[target][2]\n\t\ttarget2found[target] = found\n\t\tfound2target[found] = target\n\tend\n\tn.times do |target|\n\t\tfound = target2found[target]\n\t\tnext if found == target\n\t\ttarget2found[found2target[target]] = found\n\t\tfound2target[found] = found2target[target]\n\t\tfound2target[target] = target\n\t\tswap_row(m, found, target, step, lines)\n\tend\nend\n\nn = STDIN.readline.to_i\nm = n.times.collect { Array.new(n, 0) }\n(n-1).times do\n\tr, c = STDIN.readline.split.collect {|s| s.to_i }\n\tm[r-1][c-1] = 1\nend\ndisplay_array(m)\n\nlines = []\n\nsift_down(m, 1, lines)\ndisplay_array(m)\n\nm = m.transpose.reverse\n#display_array(m)\n\nsift_down(m, 2, lines)\n#display_array(m)\ndisplay_array(m.reverse.transpose)\n\nputs lines.length\nputs lines.join(\"\\n\")\n", "positive_code": [{"source_code": "def swap_cols(mat,i,j)\n\taux = 0\n\tn = mat.length\n\t(0..(n-1)).each {|k|\n\t\taux = mat[k][i]\n\t\tmat[k][i] = mat[k][j]\n\t\tmat[k][j] = aux\n\t}\nend\n\nn = gets.chomp.to_i\nmat = []\n(1..n).each {|pp|\n line = []\n (1..n).each {|qq|\n\tline.push(0)\n }\n mat.push(line)\n}\n\n(1..(n-1)).each { |k|\n i,j = gets.chomp.split(\" \").collect! {|x| x.to_i}\n mat[i-1][j-1] = 1 \n}\n\nactions = []\narr = []\npos = []\nm = 0\naaux = []\n(0..(n-1)).each { |k|\n\tp = m\n\tq = m\n\twhile mat[k][p]==1\n\t q +=1\n\t p +=1\n\t m +=1\n\tend\n\twhile q=0\n st -=1\n end\n arr.push(st)\n}\np = 0\nmin = arr[0]\nwhile p arr[q]\n\t\tmin = arr[q]\n\t\tpos = q\n\tend\n\tq +=1\n end\n if p != pos\n arr[pos] = arr[p]\n arr[p] = min\n actions.push(\"1 #{p+1} #{pos+1}\")\n end\n p += 1\nend\n\nputs actions.length\nactions.each { |t|\n puts t\n}\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\ndef display_array(matrix)\n\treturn\n\tmatrix.each do |row|\n\t\tputs row.join(' ')\n\tend\n\tputs\nend\n\ndef swap_row(matrix, a, b, step, lines)\n\tif step == 1\n\t\tlines.push('%d %d %d' % [step, a+1, b+1])\n\telse\n\t\tn = matrix.length\n\t\tlines.push('%d %d %d' % [step, n-a, n-b])\n\tend\n\trow = matrix[a]\n\tmatrix[a] = matrix[b]\n\tmatrix[b] = row\nend\n\ndef sift_down(m, step, lines)\n\tn = m.length\n\tcounts = n.times.collect {|r| [0, 0, r] }\n\tn.times do |r|\n\t\tn.times do |c|\n\t\t\tif m[r][c] == 1\n\t\t\t\tcounts[r][0] += 1\n\t\t\t\tcounts[r][1] = -c\n\t\t\tend\n\t\tend\n\tend\n\tcounts.sort!\n\n\tpermute = Array.new(n, 0)\n\tn.times do |new_position|\n\t\told_position = counts[new_position][2]\n\t\tpermute[old_position] = new_position\n\tend\n\n\tn.times do |pos|\n\t\twhile permute[pos] != pos\n\t\t\tswap_row(m, pos, permute[pos], step, lines)\n\t\t\tt = permute[pos]\n\t\t\tpermute[pos] = permute[t]\n\t\t\tpermute[t] = t\n\t\tend\n\tend\nend\n\nn = STDIN.readline.to_i\nm = n.times.collect { Array.new(n, 0) }\n(n-1).times do\n\tr, c = STDIN.readline.split.collect {|s| s.to_i }\n\tm[r-1][c-1] = 1\nend\ndisplay_array(m)\n\nlines = []\n\nsift_down(m, 1, lines)\ndisplay_array(m)\n\nm = m.transpose.reverse\n\nsift_down(m, 2, lines)\ndisplay_array(m.reverse.transpose)\n\nputs lines.length\nputs lines.join(\"\\n\")\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby1.9\n\ndef display_array(matrix)\n\tmatrix.each do |row|\n\t\tputs row.join(' ')\n\tend\n\tputs\nend\n\ndef swap_row(matrix, a, b, step, lines)\n\tif step == 1\n\t\tlines.push('%d %d %d' % [step, a+1, b+1])\n\telse\n\t\tn = matrix.length\n\t\tlines.push('%d %d %d' % [step, n-a, n-b])\n\tend\n\trow = matrix[a]\n\tmatrix[a] = matrix[b]\n\tmatrix[b] = row\nend\n\ndef sift_down(m, step, lines)\n\tn = m.length\n\tcounts = n.times.collect {|r| [0, 0, r] }\n\tn.times do |r|\n\t\tn.times do |c|\n\t\t\tif m[r][c] == 1\n\t\t\t\tcounts[r][0] += 1\n\t\t\t\tcounts[r][1] = -c\n\t\t\tend\n\t\tend\n\tend\n\tcounts.sort!\n\n\tpermute = Array.new(n, 0)\n\tn.times do |new_position|\n\t\told_position = counts[new_position][2]\n\t\tpermute[old_position] = new_position\n\tend\n\n\tn.times do |pos|\n\t\twhile permute[pos] != pos\n\t\t\tswap_row(m, pos, permute[pos], step, lines)\n\t\t\tt = permute[pos]\n\t\t\tpermute[pos] = permute[t]\n\t\t\tpermute[t] = t\n\t\tend\n\tend\nend\n\nn = STDIN.readline.to_i\nm = n.times.collect { Array.new(n, 0) }\n(n-1).times do\n\tr, c = STDIN.readline.split.collect {|s| s.to_i }\n\tm[r-1][c-1] = 1\nend\ndisplay_array(m)\n\nlines = []\n\nsift_down(m, 1, lines)\ndisplay_array(m)\n\nm = m.transpose.reverse\n\nsift_down(m, 2, lines)\ndisplay_array(m.reverse.transpose)\n\nputs lines.length\nputs lines.join(\"\\n\")\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\ndef display_array(matrix)\n\treturn\n\tmatrix.each do |row|\n\t\tputs row.join(' ')\n\tend\n\tputs\nend\n\ndef swap_row(matrix, a, b, step, lines)\n\tif step == 1\n\t\tlines.push('%d %d %d' % [step, a+1, b+1])\n\telse\n\t\tn = matrix.length\n\t\tlines.push('%d %d %d' % [step, n-a, n-b])\n\tend\n\trow = matrix[a]\n\tmatrix[a] = matrix[b]\n\tmatrix[b] = row\nend\n\ndef sift_down(m, step, lines)\n\tn = m.length\n\tcounts = n.times.collect {|r| [0, 0, r] }\n\tn.times do |r|\n\t\tn.times do |c|\n\t\t\tif m[r][c] == 1\n\t\t\t\tcounts[r][0] += 1\n\t\t\t\tcounts[r][1] = -c\n\t\t\tend\n\t\tend\n\tend\n\tcounts.sort!\n\n\tn.times do |target_r|\n\t\tfound_r = counts[target_r][2]\n\t\tnext if found_r <= target_r\n\t\tswap_row(m, found_r, target_r, step, lines)\n\tend\nend\n\nn = STDIN.readline.to_i\nm = n.times.collect { Array.new(n, 0) }\n(n-1).times do\n\tr, c = STDIN.readline.split.collect {|s| s.to_i }\n\tm[r-1][c-1] = 1\nend\ndisplay_array(m)\n\nlines = []\n\nsift_down(m, 1, lines)\ndisplay_array(m)\n\nm = m.transpose.reverse\n#display_array(m)\n\nsift_down(m, 2, lines)\n#display_array(m)\ndisplay_array(m.reverse.transpose)\n\nputs lines.length\nputs lines.join(\"\\n\")\n"}, {"source_code": "#!/usr/bin/ruby1.9\n\ndef display_array(matrix)\n\treturn\n\tputs\n\tmatrix.each do |row|\n\t\tputs row.join(' ')\n\tend\nend\n\ndef swap_row(matrix, a, b, step, lines)\n\tlines.push('%d %d %d' % [step, a+1, b+1])\n\trow = matrix[a]\n\tmatrix[a] = matrix[b]\n\tmatrix[b] = row\nend\n\ndef sift_down(m, step, lines)\n\tn = m.length\n\tcounts = n.times.collect {|r| [0, 0, r] }\n\tn.times do |r|\n\t\tn.times do |c|\n\t\t\tif m[r][c] == 1\n\t\t\t\tcounts[r][0] += 1\n\t\t\t\tcounts[r][1] = -c\n\t\t\tend\n\t\tend\n\tend\n\tcounts.sort!\n\n\tn.times do |target_r|\n\t\tfound_r = counts[target_r][2]\n\t\tnext if found_r <= target_r\n\t\tswap_row(m, found_r, target_r, step, lines)\n\tend\nend\n\nn = STDIN.readline.to_i\nm = n.times.collect { Array.new(n, 0) }\n(n-1).times do\n\tr, c = STDIN.readline.split.collect {|s| s.to_i }\n\tm[r-1][c-1] = 1\nend\ndisplay_array(m)\n\nlines = []\n\nsift_down(m, 1, lines)\ndisplay_array(m)\n\nm = m.transpose.reverse\n#display_array(m)\n\nsift_down(m, 2, lines)\n#display_array(m)\ndisplay_array(m.reverse.transpose)\n\nputs lines.length\nputs lines.join(\"\\n\")\n"}, {"source_code": "def swap_cols(mat,i,j)\n\taux = 0\n\tn = mat.length\n\t(0..(n-1)).each {|k|\n\t\taux = mat[k][i]\n\t\tmat[k][i] = mat[k][j]\n\t\tmat[k][j] = aux\n\t}\nend\n\nn = gets.chomp.to_i\nmat = []\n(1..n).each {|pp|\n line = []\n (1..n).each {|qq|\n\tline.push(0)\n }\n mat.push(line)\n}\n\n(1..(n-1)).each { |k|\n i,j = gets.chomp.split(\" \").collect! {|x| x.to_i}\n mat[i-1][j-1] = 1 \n}\n\nactions = []\narr = []\npos = []\nm = 0\naaux = []\n(0..(n-1)).each { |k|\n\tp = m\n\tq = m\n\twhile mat[k][p]==1\n\t q +=1\n\t p +=1\n\t m +=1\n\tend\n\twhile q=0\n st -=1\n end\n arr.push(st)\n}\npi = 0\npj = 0\nwhile piarr[pj]\n\t\taux = arr[pi]\n\t\tarr[pi] = arr[pj]\n\t\tarr[pj] = aux\n\t\t\n\t\taux = pos[pi]\n\t\tpos[pi] = pos[pj]\n\t\tpos[pj] = aux\n\t\t\n\t\tactions.push(\"1 #{pi+1} #{pj+1}\")\n\tend\n\tpj +=1\n end\n pi += 1\nend\n\nputs actions.length\nactions.each { |t|\n puts t\n}\n"}, {"source_code": "def swap_cols(mat,i,j)\n\taux = 0\n\tn = mat.length\n\t(0..(n-1)).each {|k|\n\t\taux = mat[k][i]\n\t\tmat[k][i] = mat[k][j]\n\t\tmat[k][j] = aux\n\t}\nend\n\nn = gets.chomp.to_i\nmat = []\n(1..n).each {|pp|\n line = []\n (1..n).each {|qq|\n\tline.push(0)\n }\n mat.push(line)\n}\n\n(1..(n-1)).each { |k|\n i,j = gets.chomp.split(\" \").collect! {|x| x.to_i}\n mat[i-1][j-1] = 1 \n}\n\nactions = []\narr = []\npos = []\nm = 0\naaux = []\n(0..(n-1)).each { |k|\n\tp = m\n\tq = m\n\twhile mat[k][p]==1\n\t q +=1\n\t p +=1\n\t m +=1\n\tend\n\twhile q=0\n st -=1\n end\n arr.push(st)\n}\npi = 0\npj = 0\nwhile piarr[pj]\n\t\taux = arr[pi]\n\t\tarr[pi] = arr[pj]\n\t\tarr[pj] = aux\n\t\t\n\t\taux = pos[pi]\n\t\tpos[pi] = pos[pj]\n\t\tpos[pj] = aux\n\t\t\n\t\tactions.push(\"1 #{pos[pi]+1} #{pos[pj]+1}\")\n\tend\n\tpj +=1\n end\n pi += 1\nend\n\nputs actions.length\nactions.each { |t|\n puts t\n}\n"}, {"source_code": "def swap_cols(mat,i,j)\n\taux = 0\n\tn = mat.length\n\t(0..(n-1)).each {|k|\n\t\taux = mat[k][i]\n\t\tmat[k][i] = mat[k][j]\n\t\tmat[k][j] = aux\n\t}\nend\n\nn = gets.chomp.to_i\nmat = []\n(1..n).each {|pp|\n line = []\n (1..n).each {|qq|\n\tline.push(0)\n }\n mat.push(line)\n}\n\n(1..(n-1)).each { |k|\n i,j = gets.chomp.split(\" \").collect! {|x| x.to_i}\n mat[i-1][j-1] = 1 \n}\n\nactions = []\narr = []\npos = []\nm = 0\naaux = []\n(0..(n-1)).each { |k|\n\tp = m\n\tq = m\n\twhile mat[k][p]==1\n\t q +=1\n\t p +=1\n\t m +=1\n\tend\n\twhile q=0\n st -=1\n end\n arr.push(st)\n}\npi = 0\npj = 0\nwhile piarr[pj]\n\t\taux = arr[pi]\n\t\tarr[pi] = arr[pj]\n\t\tarr[pj] = aux\n\t\t\n\t\taux = pos[pi]\n\t\tpos[pi] = pos[pj]\n\t\tpos[pj] = aux\n\t\t\n\t\tactions.push(\"1 #{pi+1} #{pj+1}\")\n\tend\n\tpj +=1\n end\n pi += 1\nend\n\nputs actions.length\nactions.each { |t|\n puts t\n}\n"}], "src_uid": "3b2c5410441e588806690056693514a8"} {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\nh=Hash.new\nn.times{|i|\n x=s=gets.chomp\n if !h[s]\n h[s]=0\n puts \"OK\"\n else\n h[s]+=1\n puts s+h[s].to_s\n end\n}\n", "positive_code": [{"source_code": "bd = {}\ngets.to_i.times do\n\tname = gets.chomp\n\tif bd.has_key?(name)\n\t\tbd[name] += 1\n\t\tputs name + bd[name].to_s\n\telse\n\t\tbd[name] = 0\n\t\tputs \"OK\"\n\tend\nend"}, {"source_code": "a={}\n\"1\n\".upto(gets){puts a[gets.chomp!]?$_+(a[$_]+=1).to_s: (a[$_]=0;:OK)}"}, {"source_code": "users = Hash.new\n\nn = gets.to_i\nn.times do\n\tname = gets.chomp\n\tif(users[name]==nil) then\n\t\tputs(\"OK\")\n\t\tusers[name] = 1\n\telse\n\t\tputs(\"#{name}#{users[name]}\")\n\t\tusers[name] += 1\n\tend\nend\n"}, {"source_code": "n = gets.to_i\n\nbase = {}\n\nanswer = []\n\nn.times do |i|\n z = gets.chomp\n if base[z] then\n answer << (z + base[z].to_s)\n base[z] += 1\n else\n answer << \"OK\"\n base[z] = 1\n end\nend\n\nanswer.map{|i| puts i}"}, {"source_code": "n = gets.chomp.to_i\n\ndb = Hash.new\nfor i in 0..n-1\n\ts = gets.chomp\n\tif db.has_key?(s)\n\t\tidx = db[s] + 1\n\t\twhile true\n\t\t\tss = s + idx.to_s\n\t\t\tif not db.has_key?(ss)\n\t\t\t\tdb[s] = idx\n\t\t\t\tdb[ss] = 0\n\t\t\t\tputs ss\n\t\t\t\tbreak\n\t\t\telse\n\t\t\t\tidx += 1\n\t\t\tend\n\t\tend\n\telse\n\t\tdb[s] = 0\n\t\tputs \"OK\"\n\tend\nend\n\n"}, {"source_code": "n = gets.to_i\nhash = Hash.new\nn.times do\n\tstr = gets.chomp!\n\tif hash.key?(str)\n\t\thash[str] += 1\n\t\tputs str + hash[str].to_s\n\telse\n\t\thash[str] = 0\n\t\tputs 'OK'\n\tend\nend"}, {"source_code": "n=STDIN.gets.chomp.to_i\ndb={}\ndb.default=-1\nn.times() {\n name=STDIN.gets.chomp\n db[name]+=1\n if 0 1 ? \"#{x}#{h[x]-1}\" : 'OK' \nend"}, {"source_code": "c = gets\n\nmap = Hash.new\n\nc.to_i.times {\n\n name = gets.strip\n\n if map[name] == nil\n puts \"OK\"\n map[name] = 0\n else\n map[name] += 1\n puts name + map[name].to_s\n end\n \n}\n\n"}, {"source_code": "n = gets.to_i\ndata = Hash.new\nn.times do\n name = gets.chop!\n v = data[name]\n if(v == nil) then v = 0; puts \"OK\" \n else puts name + v.to_s end\n data[name] = v + 1\nend\n"}, {"source_code": "n= gets.to_i\nres=[]\nnames ={}\nwhile n>0\nna=gets.chomp\nif names[na]\n names[na]=names[na]+1\n res.push (na+names[na].to_s)\nelse\n res.push \"OK\"\n names[na]=0\nend\nn=n-1\nend\n\nres.each{|a| puts a.to_s }\n"}, {"source_code": "n = Integer gets\nnames = Hash.new\nfor i in 0...n\n\tstr = gets.chomp\n\tif names.has_key? str\n\t print str, names[str], \"\\n\"\n\t names[str] += 1\n else\n puts \"OK\"\n names[str] = 1\n end\nend"}, {"source_code": "a={}\ngets.to_i.times{q=a[s=gets.chop];puts q ?s+q.to_s: \"OK\";a[s]=q.to_i+1}\n"}, {"source_code": "n = gets.to_i\n\ndatabase = {}\n\nn.times do\n\tusername = gets.chomp\n\tif database[username].nil?\n\t\tdatabase[username] = 1\n\t\tputs \"OK\"\n\telse\n\t\tputs username + database[username].to_s\n\t\tdatabase[username] += 1\n\tend\nend"}, {"source_code": "#Made By Hasbi Hamza\nn=gets.chomp.to_i\nhash={}\nlines=[]\nfor i in 1..n\n lines[i]=gets.chomp.to_s\n hash[lines[i]]=0\nend\nfor i in 1..n\n if hash[lines[i]]==0 then puts \"OK\"\n else puts(\"#{lines[i]}#{hash[lines[i]]}\")\nend\n hash[lines[i]]+=1\nend"}, {"source_code": "n = gets.to_i\na = Hash.new(0)\nn.times do\n s = gets.chomp\n if a[s] == 0\n a[s] = 1\n puts 'OK'\n else\n puts s + a[s].to_s\n a[s] += 1\n end\nend"}, {"source_code": "a={}\n\"1\n\".upto(gets){puts a[gets.chomp!]?$_+(a[$_]+=1).to_s: (a[$_]=0;:OK)}\n"}, {"source_code": "n = gets.chomp.to_i\nh = {}\nn.times do\n s = gets.chomp\n i = h[s]\n if i.nil?\n puts 'OK'\n h[s] = 1\n else\n puts \"#{s}#{h[s]}\"\n h[s] += 1\n end\nend"}, {"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 = Hash.new(0)\n\nn = STDIN.gets.to_i\nn.times do\n str = read_to_array[0]\n a[str] += 1\n if a[str] > 1\n print \"#{str}#{a[str] - 1}\"\n puts\n else\n puts \"OK\"\n end\nend\n"}, {"source_code": "n = gets.to_i\na = Hash.new(0)\nn.times do\n s = gets.chomp\n puts a[s] >= 1 ? \"#{s}#{a[s]}\" : \"OK\"\n a[s] += 1\nend\n"}, {"source_code": "n = gets.to_i\na = Hash.new(0)\nn.times do\n s = gets.chomp\n if a[s] >= 1\n puts s + a[s].to_s\n a[s] += 1\n else\n a[s] = 1\n puts 'OK'\n end\nend\n"}, {"source_code": "n = gets.to_i\na = Hash.new(false)\nn.times do\n s = gets.chomp\n if a[s]\n a[s] += 1\n puts s + a[s].to_s\n else\n a[s] = 0\n puts 'OK'\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\nh = {}\nn.times do\n s = gets.chomp\n if h[s].nil? then\n puts 'OK'\n h[s] = 1\n else\n puts s + h[s].to_s\n h[s] += 1\n end \nend\n"}, {"source_code": "a={}\n\"1\n\".upto(gets){puts a[gets.chomp!]?$_+(a[$_]+=1).to_s: (a[$_]=0;:OK)}"}, {"source_code": "names = {}\nnoNames = gets.chomp.to_i\n(1..noNames).each do |name|\n name = gets.chomp\n if names[name] == nil\n names[name] = 1\n puts \"OK\"\n else\n newName = \"#{name}#{names[name]}\"\n names[name] += 1\n names[newName] = 1\n puts newName\n end\nend"}, {"source_code": "a={}\n\"1\n\".upto(gets){puts a[gets.chomp!]?$_+(a[$_]+=1).to_s: (a[$_]=0;:OK)}"}, {"source_code": "numOfInputs = gets.to_i\ninputHash = {}\nnumOfInputs.downto(1) do\n input = gets.chomp\n if (inputHash.has_key?(input))\n numOfOccurence = inputHash[input]\n \n puts \"#{input}#{numOfOccurence}\"\n \n numOfOccurence = numOfOccurence + 1\n inputHash[input] = numOfOccurence\n else\n inputHash[input] = 1\n puts \"OK\"\n end \nend\n"}, {"source_code": "n = gets.to_i\ndb = {}\n\nwhile n > 0 do\n u = gets[0..-2]\n if db.key?(u)\n printf(\"%s%d\\n\", u, db[u])\n db[u] += 1\n else\n puts \"OK\"\n db[u] = 1\n end\n n -= 1\nend"}, {"source_code": "n = gets.to_i\ndb = {}\n\nwhile n > 0 do\n u = gets.chomp\n if db.has_key?(u)\n puts u + db[u].to_s\n db[u] += 1\n else\n puts \"OK\"\n db[u] = 1\n end\n n -= 1\nend"}, {"source_code": "n = gets.to_i\ndb = {}\n\nwhile n > 0 do\n u = gets.chomp\n if db.has_key?(u)\n printf(\"%s%d\\n\", u, db[u])\n db[u] += 1\n else\n puts \"OK\"\n db[u] = 1\n end\n n -= 1\nend"}, {"source_code": "a={}\n\"1\n\".upto(gets){puts a[gets.chomp!]?$_+(a[$_]+=1).to_s: (a[$_]=0;:OK)}"}, {"source_code": "h=Hash.new\ngets\n$<.map{|n|\n\ts=n.chop\n if(h.has_key?(s))\n h[s]+=1\n puts s+h[s].to_s\n else\n \th[s] = 0\n puts \"OK\"\n end\n}"}, {"source_code": "n = gets.chomp.to_i\n\nhash = {}\n\nn.times do |i| \n name = gets.chomp\n if hash[name] == nil\n hash[name] = 1\n puts \"OK\"\n else\n puts \"#{name}#{hash[name]}\"\n hash[name] += 1\n end\nend"}, {"source_code": "a={}\n\"1\n\".upto(gets){puts a[gets.chomp!]?$_+(a[$_]+=1).to_s: (a[$_]=0;:OK)}\n"}, {"source_code": "n = gets.to_i\n\ncache = Hash.new { 0 }\n\n1.upto(n) do\n name = gets.chomp\n\n puts cache[name].zero? ? 'OK' : \"#{name}#{cache[name]}\"\n\n cache[name] += 1\nend\n"}, {"source_code": "a = {}\nfor _ in 1..gets.chomp.to_i\n name = gets.chomp\n if a.has_key? name\n a[name] += 1\n puts \"#{name}#{a[name]}\"\n else\n puts 'OK'\n a[name] = 0\n end\nend"}, {"source_code": " \na={}\n\"1\n\".upto(gets){puts a[gets.chomp!]?$_+(a[$_]+=1).to_s: (a[$_]=0;:OK)}"}, {"source_code": "n = gets.chomp.to_i\n\nhash = {}\n\n1.upto(n) do \n\tname = gets.chomp\n\tif hash[name] == nil\n\t\thash[name] = 1\n\t\tputs \"OK\"\n\telse\n\t\tputs \"#{name}#{hash[name]}\"\n\t\thash[name] += 1\n\tend\nend\n"}, {"source_code": "a={}\n\"1\n\".upto(gets){puts a[gets.chomp!]?$_+(a[$_]+=1).to_s: (a[$_]=0;:OK)}\n"}, {"source_code": "a={}\n\"1\n\".upto(gets){puts a[gets.chomp!]?$_+(a[$_]+=1).to_s: (a[$_]=0;:OK)}"}, {"source_code": "a={}\n\"1\n\".upto(gets){puts a[gets.chomp!]?$_+(a[$_]+=1).to_s: (a[$_]=0;:OK)}\n"}, {"source_code": "n, db = gets.to_i, Hash.new(-1)\nn.times do\n\tname = gets.chomp.to_sym\n\tdb[name] += 1\n\tif db[name] > 0\n\t\tprint name, db[name], \"\\n\"\n\telse\n\t\tputs :OK\n\tend\nend\n"}, {"source_code": "accountNum = gets.chomp.to_i\n\nhash = {}\nnumberHash = {}\n\naccountNum.times do\n\taccount = gets.chomp\n\n\tif hash.has_key? account\n\t\tnumberHash[account] += 1\n\t\tnewAccount = account + numberHash[account].to_s\n\t\tputs \"#{newAccount}\"\n\telse\n\t\tputs 'OK'\n\t\thash[account] = 1\n\t\tnumberHash[account] = 0\n\tend\nend"}], "negative_code": [{"source_code": "n=STDIN.gets.chomp.to_i\ndb={}\ndb.default=0\nn.times() {\n name=STDIN.gets.chomp\n db[name]+=1\n if 1 b1.size \n\t\t\tputs ans\n\t\telse\n\t\t\tif (b2-b1).empty?\n\t\t\t\tputs ans\n\t\t\telse\n\t\t\t\tputs ((b2-b1).size)+ans\n\t\t\tend\n\t\tend\n\telse\n\t\tputs ans\n\tend\nend\n\nmain"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tb1=[]\n\tb2=[]\n\tans=0\n\tfor i in 0...n\n\t\tini=gets.chomp.split(\" \")\n\t\tini=ini.map{|i| i.to_i}\n\t\tai=ini[0]\n\t\tbi=ini[1]\n\t\tif ai==bi\n\t\t\tans+=1\n\t\tend\n\t\tb1 << ai\n\t\tb2 << bi\n\tend\n\tputs (b2-b1).size+ans\nend\nmain"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tans=0\n\ths={}\n\tfor i in 0...n\n\t\tini=gets.chomp.split(\" \")\n\t\tini=ini.map{|i| i.to_i}\n\t\tai=ini[0]\n\t\tbi=ini[1]\n\t\ths[ai]=bi;\n\tend\n\tkeys=hs.keys\n\tfor i in keys\n\t\tb=i;\n\t\tv=hs[b]\n\t\tif v==b\n\t\t\tans+=1;\n\t\telsif !hs.has_value?(v)\n\t\t\tans+=1\n\t\tend\n\tend\n\tputs ans\nend\nmain"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tb1=[]\n\tb2=[]\n\tcheck=[]\n\tans=0\n\tfor i in 0...n\n\t\tini=gets.chomp.split(\" \")\n\t\tini=ini.map{|i| i.to_i}\n\t\tai=ini[0]\n\t\tbi=ini[1]\n\t\tif ai==bi\n\t\t\tans+=1\n\t\t\tcheck << bi\n\t\telse\n\t\t\tb1 << ai\n\t\t\tb2 << bi\n\t\tend\n\tend\n\tfor i in check\n\t\tbx=i;\n\t\tind=b2.index(bx)\n\t\tif !ind.nil?\n\t\t\tans-=1\n\t\tend\n\tend\n\tputs ans\nend\nmain"}, {"source_code": "def main()\n\tnm=gets.chomp.split(\" \")\n\tn=nm[0].to_i\n\tm=nm[1].to_i\n\tar=gets.chomp.split(\" \")\n\tar=ar.map{|i| i.to_i}\n\tinc=0\n\tfor i in 0...m\n\t\tstop=gets.chomp\n\t\tif stop[0].chr==\"3\"\n\t\t\tinop=stop.split(\" \")\n\t\t\tinop=inop.map{|i| i.to_i}\n\t\t\tputs ar[inop[1]-1]+inc\n\t\telsif stop[0].chr==\"2\"\n\t\t\tinop=stop.split(\" \")\n\t\t\tinop=inop.map{|i| i.to_i}\n\t\t\tinc+=inop[1]\n\t\telse\n\t\t\tinop=stop.split(\" \")\n\t\t\tinop=inop.map{|i| i.to_i}\n\t\t\tar[inop[1]-1]=inop[2]-inc\n\t\tend\n\t\t\t\n\tend\nend\nmain"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tb1=[]\n\tb2=[]\n\tcheck=[]\n\tans=0\n\tfor i in 0...n\n\t\tini=gets.chomp.split(\" \")\n\t\tini=ini.map{|i| i.to_i}\n\t\tai=ini[0]\n\t\tbi=ini[1]\n\t\tif ai==bi\n\t\t\tans+=1\n\t\t\tcheck << bi\n\t\telse\n\t\t\tb1 << ai\n\t\t\tb2 << bi\n\t\tend\n\tend\n\tfor i in check\n\t\tbx=i;\n\t\tind=b2.index(bx)\n\t\tif !ind.nil?\n\t\t\tans-=1\n\t\tend\n\tend\n\tb1=b1.uniq\n\tb2=b2.uniq\n\tputs (b1-b2).size+ans\nend\nmain"}, {"source_code": "n = gets.chomp.to_i\nbrand_to_count = {}\nbrand_to_can_open = {}\nbrand_to_same_count = {}\nn.times do\n a, b = gets.chomp.split(\" \").map(&:to_i)\n if a == b \n brand_to_same_count[a] = brand_to_same_count.fetch(a, 0) + 1\n else\n brand_to_can_open[b] = brand_to_can_open.fetch(b, 0) + 1\n brand_to_count[a] = brand_to_count.fetch(a, 0) + 1\n end\nend\ntotal_unopenable = 0\nbrand_to_same_count.each do |brand, count|\n if count == 1\n total_unopenable += 1\n end\nend\nbrand_to_count.each do |brand, count|\n # get count\n # see how many are openable from brand_to_can_open\n openable = brand_to_can_open.fetch(brand, 0)\n unopenable = [count - openable, 0].max\n total_unopenable += unopenable\nend\nputs total_unopenable\n"}, {"source_code": "array = Array.new(gets.to_i){ gets.split }\np (array.map(&:first) - array.select{ |i,j| i != j }.map(&:last)).size\n"}, {"source_code": "require 'set'\n\ndef run\n a = []\n s = Set.new\n n = $stdin.gets.to_i\n $stdin.readlines.each do |line|\n ai, bi = line.split.map(&:to_i)\n a << ai\n s.add(bi) if ai != bi\n end\n\n cnt = 0\n a.each do |ai|\n cnt += 1 unless s.include?(ai)\n end\n puts cnt\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "require 'set'\n\ndef run\n s = Set.new\n n = $stdin.gets.to_i\n $stdin.readlines.each do |line|\n a, b = line.split.map(&:to_i)\n s.add(b) if a != b\n end\n\n puts n - s.size\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "require 'set'\n\ndef run\n a = []\n b = []\n n = $stdin.gets.to_i\n $stdin.readlines.each do |line|\n ai, bi = line.split.map(&:to_i)\n a << ai\n b << bi\n end\n\n r = []\n n.times do |i|\n n.times do |j|\n r[i] = true if i != j and b[i] == a[j]\n end\n end\n\n puts n - r.count(true)\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.to_i\na = []\nb = []\nn.times do\n s = gets.split.map(&:to_i)\n a << s[0]\n b << s[1] if s[0]!= s[1]\nend\nputs n - a.count{|i| b.include?(i)}"}, {"source_code": "n = gets.to_i\na = []\nb = []\nn.times do\n s = gets.split.map(&:to_i)\n a << s[0]\n b << s[1] if s[0]!= s[1]\nend\nx = []\nn.times do |i|\n n.times do |j|\n x << j if i!=j && a[i]!=b[i]\n end\nend\nputs n - x.uniq.size"}, {"source_code": "n = gets.to_i\na = []\nb = []\nn.times do\n s = gets.split.map(&:to_i)\n a << s[0]\n b << s[1]\nend\nx = []\nn.times do |i|\n n.times do |j|\n x << j if (i!=j and a[i]!=b[i])\n end\nend\nputs n - x.uniq.size"}], "src_uid": "84bd49becca69e126606d5a2f764dd91"} {"source_code": "t = gets.to_i\r\nalphabet = \" abcdefghijklmnopqrstuvwxyz\"\r\nf=->s{s.chars.sum{alphabet.index(_1)}}\r\nt.times do |cas|\r\n s = gets.chomp\r\n if s.size%2==0\r\n puts \"Alice %d\"%[f[s]]\r\n else\r\n a = [f[s[1..]], f[s[..-2]]].max\r\n b = f[s] - a\r\n if a > b\r\n puts \"Alice %d\"%(a-b)\r\n else\r\n puts \"Bob %d\"%(b-a)\r\n end\r\n end\r\nend\r\n\r\n\r\n# (a+b+c)\r\n# (bc + ac + ab) + ad + bd + cd = 0\r\n# d(a+b+c) + e(a+b+c) = -(bc + ac + ab)\r\n# d + e = -(bc + ac + ab + de) /(a+b+c)", "positive_code": [{"source_code": "gets.to_i.times do\n a = gets.chomp.split('').map{|c| c.ord - 'a'.ord + 1}\n s = a.inject(:+)\n if a.size % 2 == 0 then\n alice = s\n bob = 0\n else\n if a.size == 1 then\n bob = s\n alice = 0\n else\n bob = [a[0],a[a.size-1]].min\n alice = s - bob\n end\n end\n if alice > bob then\n puts \"Alice #{alice-bob}\"\n else\n puts \"Bob #{bob-alice}\"\n end\nend\n"}, {"source_code": "gets.to_i.times do\r\n s = gets.chomp\r\n chars = s.chars.map { |ch| ch.ord - 97 + 1 }\r\n alice, bob = if s.size.even?\r\n [chars.sum, 0]\r\n else\r\n min = [chars[0], chars[-1]].min\r\n [chars.sum - min, min]\r\n end\r\n puts \"#{alice > bob ? \"Alice\" : \"Bob\"} #{(alice - bob).abs}\"\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\n a = gets.chomp.split('').map{|c| c.ord - 'a'.ord + 1}\n s = a.inject(:+)\n puts s \n if a.size % 2 == 0 then\n puts \"Alice #{s}\"\n else\n if a.size == 1 then\n puts \"Bob #{s}\"\n else\n puts \"Alice #{s - 2*[a[0],a[a.size-1]].min}\"\n end\n end\nend\n"}], "src_uid": "8f02891aa9d2fcd1963df3a4028aa5c0"} {"source_code": "def combi2(m)\n return m * (m-1) / 2\nend\n\nn = gets.to_i\nstudents = {}\nfor i in 0...n do\n initial = gets.chomp[0]\n if students.include?(initial)\n students[initial] += 1\n else\n students[initial] = 1\n end\nend\nsum = 0\nstudents.each_value { |num|\n sum += combi2((num + 1) / 2) + combi2(num / 2)\n}\n\nputs sum\n", "positive_code": [{"source_code": "def combinations(n)\n Math.gamma(n + 1) / (Math.gamma(3) * Math.gamma((n - 2) + 1))\nend\n\nstudents_count = gets.chomp\nstudents = []\ngroups = {}\n\n(1..students_count.to_i).each do |_n|\n name = gets.chomp\n students << name\n groups[name[0]] = groups[name[0]] ? groups[name[0]] + 1 : 1\nend\n\nmin = 0\ngroups.each do |_char, count|\n next if count <= 2\n min += count.even? ? combinations(count / 2) * 2 : combinations(count / 2) + combinations((count / 2) + 1)\nend\n\nprint min.to_i\n"}, {"source_code": "def sum(m) \n\ts = 0 \n\tfor i,k in m \n\t\ttemp = k / 2 \n\t\ts += temp * (temp-1) / 2 \n\t\ts += (k-temp) * (k-temp-1) /2 \n\tend\n\treturn s \nend\n\nn = gets.to_i \nm = Hash.new\nm.default = 0 \nn.times do \n\tt = gets\n\tm[t[0]] += 1\nend\nputs(sum(m))\n\n"}, {"source_code": "n = gets.to_i\ncnt = Hash.new(0)\nn.times do\n s = gets.chomp\n cnt[s[0]] += 1\nend\nans = 0\ncnt.each do |k,v|\n x = v/2 + v%2\n ans += x * (x-1) / 2\n ans += (v-x) * (v-x-1) /2\nend\np ans\n"}, {"source_code": "n = gets.to_i\na = Hash.new(0)\nn.times do\n a[gets[0]] += 1\nend\nans = 0\na.values.each do |i|\n ans += i/2*(i/2-1)/2+(i-i/2)*(i-i/2-1)/2\nend\nputs ans"}, {"source_code": "def combinations(n)\n Math.gamma(n + 1) / (Math.gamma(3) * Math.gamma((n - 2) + 1))\nend\n\nstudents_count = gets.chomp\ngroups = {}\n\n(1..students_count.to_i).each do |_n|\n name = gets.chomp\n groups[name[0]] = groups[name[0]] ? groups[name[0]] + 1 : 1\nend\n\nmin = 0\ngroups.each_value do |count|\n next if count <= 2\n min += count.even? ? combinations(count / 2) * 2 : combinations(count / 2) + combinations((count / 2) + 1)\nend\n\nprint min.to_i\n"}], "negative_code": [{"source_code": "def combi2(m)\n return m * (m-1) / 2\nend\n\nn = gets.to_i\nstudents = {}\nfor i in 0...n do\n initial = gets.chomp[0]\n if students.include?(initial)\n students[initial] += 1\n else\n students[initial] = 1\n end\nend\nmax = 0\nstudents.each_value { |num|\n max = num if max < num\n}\n\nputs combi2((max + 1) / 2) + combi2(max / 2)\n"}], "src_uid": "22a3561ff70b802f080feaabc4a71298"} {"source_code": "pa=Array.new(105,0)\npb=Array.new(105,0)\npc=Array.new\n\nstr=gets.to_s\npc=str.split\nn=pc[0].to_i\nm=pc[1].to_i\n\nk=n*m\nstr=gets.to_s\npc=str.split\nb=pc[0].to_i\nfor i in 1..b\n pa[pc[i].to_i]=1\nend\nstr=gets.to_s\npc=str.split\nb=pc[0].to_i\nfor i in 1..b\n pb[pc[i].to_i]=1\nend\n\nfor i in 0..k*2\n a=i%n\n b=i%m\n if pa[a]==1 || pb[b]==1\n pa[a]=pb[b]=1\n end\nend\n\n#for i in 0..n-1\n# puts pa[i]\n#end\n#puts\n#for i in 0..m-1\n# puts pb[i]\n#end\n\nh=0\nfor i in 0..n-1\n if pa[i]==0\n h=1\n break\n end\nend\n\nfor i in 0..m-1\n if pb[i]==0 || h==1\n h=1\n break\n end\nend\n\nif h==1\n puts \"No\"\nelsif h==0\n puts \"Yes\"\nend", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\nn, m = gets.split.map(&:to_i)\n_, *xs = gets.split.map(&:to_i)\n_, *ys = gets.split.map(&:to_i)\n\nx_happy = Array::new(n, false)\ny_happy = Array::new(m, false)\n\nxs.each { |i| x_happy[i] = true }\nys.each { |i| y_happy[i] = true }\n\n(n*m*2).times do |i|\n if x_happy[i%n] || y_happy[i%m]\n x_happy[i%n] = y_happy[i%m] = true\n end\nend\n\nif x_happy.all? && y_happy.all?\n puts \"Yes\"\nelse\n puts \"No\"\nend\n"}, {"source_code": "def g;gets.split.map(&:to_i)end\nUF=Hash.new{|_,k|k}\ndef u a,b;UF[f a]=UF[f b]end\ndef f c;c==UF[c]?c:UF[c]=f(UF[c])end\nn,m=g\nb,*x=g\nc,*y=g\nhappy = x+y.map{|i|i+n}\nif happy==[]\n puts \"No\"\nelse\n if happy.size>1\n happy[1..-1].each{|i|u happy[0],i}\n end\n 10000.times{|i|u i%n,n+i%m}\n puts (0..n+m-1).map{|i|f i}.uniq.size==1?\"Yes\":\"No\"\nend"}, {"source_code": "#!/usr/bin/ruby\n\n#read data\nparams = gets.split(' ').map(&:to_i)\nn = params[0].to_i\nm = params[1].to_i\n\nparams = gets.split(' ').map(&:to_i)\nb = params.shift\nhappy_b = params\n\n\nparams = gets.split(' ').map(&:to_i)\ng = params.shift\nhappy_g = params\n\n#puts happy_b.to_s\n#puts happy_g.to_s\n\nboys = Array.new(size=n, default=0)\ngirls = Array.new(size=m, default=0)\n\nhappy_b.each do |e|\n boys[e] = 1;\nend\n\nhappy_g.each do |e|\n girls[e] = 1;\nend\n\n#puts boys.to_s\n#puts girls.to_s\n\nres = false;\ntimes_to_run = n.lcm m #mua ha ha \ncounter = 0; \n#puts times_to_run\nwhile (counter < times_to_run && !res) do\n if (boys[counter % n] == 1 || girls[counter % m] == 1)\n if (boys[counter % n] == 1 && girls[counter % m] == 0)\n girls[counter % m] = 1;\n g = g + 1;\n elsif (boys[counter % n] == 0 && girls[counter % m] == 1)\n boys[counter % n] = 1;\n b = b + 1;\n end\n end\n\n # puts 'Iteration ' + counter.to_s\n # puts boys.to_s\n # puts girls.to_s\n # puts b,n,g,m\n counter = counter + 1\n if (b == n || g == m)\n res = true;\n break\n end\nend\n\nif res\n puts 'Yes'\nelse\n puts 'No'\nend"}, {"source_code": "n, m = gets.split.map(&:to_i)\nlbs = gets.split.map(&:to_i).drop(1)\nlgs = gets.split.map(&:to_i).drop(1)\nul = n + m - (lbs.count + lgs.count)\nbs = Array.new(n, false)\nlbs.each {|i| bs[i] = true}\ngs = Array.new(m, false)\nlgs.each {|i| gs[i] = true}\nlasti = 0\nfor i in 0..Float::INFINITY do\n bi, gi = i%n, i%m\n if bs[bi] || gs[gi]\n ul -= 1 unless bs[bi]\n ul -= 1 unless gs[gi]\n lasti = i unless bs[bi] && gs[gi]\n bs[bi] = gs[gi] = true\n end\n break if ul == 0\n break if i - lasti > m*n\nend\nputs ul == 0 ? \"Yes\" : \"No\""}, {"source_code": "def create_list(n, hippies)\n result = []\n n.times do |i|\n result << hippies.include?(i)\n end\n result\nend\n\nnm = gets.chomp.split(' ').map{|i| i.to_i }\nn = nm[0]\nm = nm[1]\nhappy_ar = gets.chomp.split(' ').map{|i| i.to_i }\nhappy_amount = happy_ar[0]\nhappy_who_b = if happy_amount > 0 then happy_ar[1..-1] else [] end\nboys = create_list(n, happy_who_b)\n\nhappy_ar = gets.chomp.split(' ').map{|i| i.to_i }\nhappy_amount = happy_ar[0]\nhappy_who_g = if happy_amount > 0 then happy_ar[1..-1] else [] end\ngirls = create_list(m, happy_who_g)\n\n\ndef check(n, m, boys, girls)\n # gcd = n.gcd(m)\n (n * m * 2).times do |i|\n if boys[i % boys.length] or girls[i % girls.length]\n boys[i % boys.length] = true\n girls[i % girls.length] = true\n end\n end\n return (boys.all? and girls.all?)\nend\n\nputs check(n, m, boys, girls) ? 'Yes' : 'No'"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = Array.new(n).map{0}\nb = Array.new(m).map{0}\na1 = gets.split.map(&:to_i)\nb1 = gets.split.map(&:to_i)\na1.each_with_index{|x, i|\nif i != 0\n a[x] = 1\nend \n}\nb1.each_with_index{|x, i|\n if i != 0\n b[x] = 1\n end \n}\nk1 = 0\nk2 = 0\nf1 = 0\nf2 = 0\nfor i in 0..3000000\n it1 = i % n \n it2 = i % m\n #print(\" it1 #{it1} it2 #{it2} \")\n if(a[it1] == 1 || b[it2] == 1)\n if(a[it1] == 0)\n a[it1] = 1\n k1 += 1\n end\n if(b[it2] == 0)\n b[it2] = 1\n k2 += 1\n end\n end\n if(n - (a1[0] + k1) == 0)\n f1 = 1 \n end\n if(m - (b1[0] + k2) == 0)\n f2 = 1 \n end\n if f2 == 1 && f1 == 1 \n break\n end\nend\n if f2 == 1 && f1 == 1 \n puts(\"Yes\")\n else \n puts(\"No\")\n end "}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\na = gets.strip.split.map(&:to_i)\nb = gets.strip.split.map(&:to_i)\n\na.delete_at(0)\nb.delete_at(0)\n\nh1 = []\nh2 = []\n\n(0..(n+m)).each {|x|\n h1 << 0\n h2 << 0\n}\n\na.each { |x| h1[x] = 1 }\nb.each { |x| h2[x] = 1 }\n\n(0..(n*m*2)).each {|x|\n if h1[x % n] == 1 || h2[x % m] == 1\n h1[x % n] = 1\n h2[x % m] = 1\n end\n}\n\nres = 0\n(0..(n-1)).each {|x| res = 1 if h1[x] == 0}\n(0..(m-1)).each {|x| res = 1 if h2[x] == 0}\n\nif res == 1\n puts \"No\"\nelse\n puts \"Yes\"\nend"}, {"source_code": "#!/usr/bin/ruby\n# coding: utf-8\n\na, b = gets.split.map &:to_i\nc = a.gcd b\ndata = Array.new(c, nil)\nx = gets.split.map &:to_i\nx.shift\nx.each {|_|\n data[_ % c] = true\n}\nx = gets.split.map &:to_i\nx.shift\nx.each {|_|\n data[_ % c] = true\n}\nputs data.all? ? \"Yes\" : \"No\""}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\n\nn, m = gets.split.map(&:to_i)\nxs = gets.split.map(&:to_i)\nys = gets.split.map(&:to_i)\n\nx_happy = Array::new(n, false)\ny_happy = Array::new(m, false)\n\nxs[1, xs[0]].each do |x|\n x_happy[x] = true\nend\n\nys[1, ys[0]].each do |y|\n y_happy[y] = true\nend\n\ng = n.gcd(m)\n\n(n*m*2).times do |i|\n if x_happy[i%n] && y_happy[i%m]\n x_happy[i%n] = y_happy[i%m] = true\n end\nend\n\nif x_happy.all? && y_happy.all?\n puts \"Yes\"\nelse\n puts \"No\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn, m = gets.split.map(&:to_i)\nxs = gets.split.map(&:to_i)\nys = gets.split.map(&:to_i)\n\nx_happy = Array::new(n, false)\ny_happy = Array::new(m, false)\n\nxs[1, xs[0]].each do |x|\n x_happy[x] = true\nend\n\nys[1, ys[0]].each do |y|\n y_happy[y] = true\nend\n\ng = n.gcd(m)\n\n[x_happy.length, y_happy.length].min.times {\n x_happy.length.times do |i|\n y_happy.length.times do |j|\n if (i - j).abs % g == 0 && (x_happy[i] || y_happy[j])\n x_happy[i] = y_happy[j] = true\n end\n end\n end\n}\n\nif x_happy.all? && y_happy.all?\n puts \"Yes\"\nelse\n puts \"No\"\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\n#read data\nparams = gets.split(' ').map(&:to_i)\nn = params[0].to_i\nm = params[1].to_i\n\nparams = gets.split(' ').map(&:to_i)\nb = params.shift\nhappy_b = params\n\n\nparams = gets.split(' ').map(&:to_i)\ng = params.shift\nhappy_g = params\n\n\nboys = Array.new(size=n, default=0)\ngirls = Array.new(size=m, default=0)\n\nhappy_b.each do |e|\n boys[e] = 1;\nend\n\nhappy_g.each do |e|\n girls[e] = 1;\nend\n\n#puts boys.to_s\n#puts girls.to_s\n\nres = false;\ntimes_to_run = n.lcm m #mua ha ha \ncounter = 0; \n#puts times_to_run\nwhile (counter < times_to_run && !res) do\n if (boys[counter % n] == 1 || girls[counter % m] == 1)\n if (boys[counter % n] == 1 && girls[counter % m] == 0)\n girls[counter % m] = 1;\n g = g + 1;\n elsif (boys[counter % n] == 0 && girls[counter % m] == 1)\n boys[counter % m] = 1;\n b = b + 1;\n end\n end\n\n # puts 'Iteration ' + counter.to_s\n # puts boys.to_s\n # puts girls.to_s\n counter = counter + 1\n if (b == n || g == m)\n res = true;\n end\nend\n\nif res\n puts 'Yes'\nelse\n puts 'No'\nend"}, {"source_code": "n, m = gets.split.map(&:to_i)\nlbs = gets.split.map(&:to_i).drop(1)\nlgs = gets.split.map(&:to_i).drop(1)\nul = n*m - (lbs.count + lgs.count)\nbs = Array.new(n, false)\nlbs.each {|i| bs[i] = true}\ngs = Array.new(m, false)\nlgs.each {|i| gs[i] = true}\nfor i in 0...n*m do\n bi, gi = i%n, i%m\n break if i > 0 && bi == 0 && gi == 0\n if bs[bi] || gs[gi]\n ul -= 1 unless bs[bi]\n ul -= 1 unless gs[gi]\n bs[bi] = gs[gi] = true\n end\n break if ul == 0\nend\nputs ul == 0 ? \"Yes\" : \"No\""}, {"source_code": "n, m = gets.split.map(&:to_i)\nlbs = gets.split.map(&:to_i).drop(1)\nlgs = gets.split.map(&:to_i).drop(1)\nul = n + m - (lbs.count + lgs.count)\nbs = Array.new(n, false)\nlbs.each {|i| bs[i] = true}\ngs = Array.new(m, false)\nlgs.each {|i| gs[i] = true}\nfor i in 0...n*m do\n bi, gi = i%n, i%m\n if bs[bi] || gs[gi]\n ul -= 1 unless bs[bi]\n ul -= 1 unless gs[gi]\n bs[bi] = gs[gi] = true\n end\n break if ul == 0\nend\nputs ul == 0 ? \"Yes\" : \"No\""}, {"source_code": "n, m = gets.split.map(&:to_i)\nlbs = gets.split.map(&:to_i).drop(1)\nlgs = gets.split.map(&:to_i).drop(1)\nul = n*m - (lbs.count + lgs.count)\nbs = Array.new(n, false)\nlbs.each {|i| bs[i] = true}\ngs = Array.new(m, false)\nlgs.each {|i| gs[i] = true}\nfor i in 0...n*m do\n bi, gi = i%n, i%m\n if bs[bi] || gs[gi]\n ul -= 1 unless bs[bi]\n ul -= 1 unless gs[gi]\n bs[bi] = gs[gi] = true\n end\n break if ul == 0\nend\nputs ul == 0 ? \"Yes\" : \"No\""}, {"source_code": "n, m = gets.split.map(&:to_i)\nlbs = gets.split.map(&:to_i).drop(1)\nlgs = gets.split.map(&:to_i).drop(1)\nul = n + m - (lbs.count + lgs.count)\nbs = Array.new(n, false)\nlbs.each {|i| bs[i] = true}\ngs = Array.new(m, false)\nlgs.each {|i| gs[i] = true}\nfor i in 0...n*m do\n bi, gi = i%n, i%m\n break if i > 0 && bi == 0 && gi == 0\n if bs[bi] || gs[gi]\n ul -= 1 unless bs[bi]\n ul -= 1 unless gs[gi]\n bs[bi] = gs[gi] = true\n end\n break if ul == 0\nend\nputs ul == 0 ? \"Yes\" : \"No\""}, {"source_code": "def create_list(n, hippies)\n result = []\n n.times do |i|\n result << hippies.include?(i)\n end\n result\nend\n\nnm = gets.chomp.split(' ').map{|i| i.to_i }\nn = nm[0]\nm = nm[1]\nhappy_ar = gets.chomp.split(' ').map{|i| i.to_i }\nhappy_amount = happy_ar[0]\nhappy_who_b = if happy_amount > 0 then happy_ar[1..-1] else [] end\nboys = create_list(n, happy_who_b)\n\nhappy_ar = gets.chomp.split(' ').map{|i| i.to_i }\nhappy_amount = happy_ar[0]\nhappy_who_g = if happy_amount > 0 then happy_ar[1..-1] else [] end\ngirls = create_list(m, happy_who_g)\n\ndef check(n, m, boys, girls, hboys, hgirls)\n # special case: if Drazil have the same number of girls and boys then\n # true would be only if in pairs at least one of them is happy\n if n == m\n n.times do |i|\n return false if not boys[i] and not girls[i]\n end\n return true\n end\n if (n-m).abs % 2 == 1\n return true\n end\n even = hboys.any?{|x| x % 2 == 0} or hgirls.any?{|x| x % 2 == 0}\n odd = hboys.any?{|x| x % 2 == 1} or hgirls.any?{|x| x % 2 == 1}\n return (even and odd)\nend\n\n\nputs check(n, m, boys, girls, happy_who_b, happy_who_g) ? 'Yes' : 'No'"}, {"source_code": "def create_list(n, hippies)\n result = []\n n.times do |i|\n result << hippies.include?(i)\n end\n result\nend\n\nnm = gets.chomp.split(' ').map{|i| i.to_i }\nn = nm[0]\nm = nm[1]\nhappy_ar = gets.chomp.split(' ').map{|i| i.to_i }\nhappy_amount = happy_ar[0]\nhappy_who_b = if happy_amount > 0 then happy_ar[1..-1] else [] end\nboys = create_list(n, happy_who_b)\n\nhappy_ar = gets.chomp.split(' ').map{|i| i.to_i }\nhappy_amount = happy_ar[0]\nhappy_who_g = if happy_amount > 0 then happy_ar[1..-1] else [] end\ngirls = create_list(m, happy_who_g)\n\n\ndef check(n, m, boys, girls)\n gcd = n.gcd(m)\n ((boys.length * girls.length) / gcd).times do |i|\n if boys[i % boys.length] or girls[i % girls.length]\n boys[i % boys.length] = true\n girls[i % girls.length] = true\n end\n end\n return (boys.all?{|x| x} and girls.all?{|x| x})\nend\n\nputs check(n, m, boys, girls) ? 'Yes' : 'No'"}, {"source_code": "def create_list(n, hippies)\n result = []\n n.times do |i|\n result << hippies.include?(i)\n end\n result\nend\n\nnm = gets.chomp.split(' ').map{|i| i.to_i }\nn = nm[0]\nm = nm[1]\nhappy_ar = gets.chomp.split(' ').map{|i| i.to_i }\nhappy_amount = happy_ar[0]\nhappy_who_b = if happy_amount > 0 then happy_ar[1..-1] else [] end\nboys = create_list(n, happy_who_b)\n\nhappy_ar = gets.chomp.split(' ').map{|i| i.to_i }\nhappy_amount = happy_ar[0]\nhappy_who_g = if happy_amount > 0 then happy_ar[1..-1] else [] end\ngirls = create_list(m, happy_who_g)\n\n\ndef check(n, m, boys, girls)\n gcd = n.gcd(m)\n if (n - m).abs % gcd != 0\n return true\n end\n ((boys.length * girls.length) / gcd).times do |i|\n if boys[i % boys.length] or girls[i % girls.length]\n boys[i % boys.length] = true\n girls[i % girls.length] = true\n end\n end\n return (boys.all?{|x| x} and girls.all?{|x| x})\nend\n\nputs check(n, m, boys, girls) ? 'Yes' : 'No'"}, {"source_code": "def create_list(n, hippies)\n result = []\n n.times do |i|\n result << hippies.include?(i)\n end\n result\nend\n\nnm = gets.chomp.split(' ').map{|i| i.to_i }\nn = nm[0]\nm = nm[1]\nhappy_ar = gets.chomp.split(' ').map{|i| i.to_i }\nhappy_amount = happy_ar[0]\nhappy_who_b = if happy_amount > 0 then happy_ar[1..-1] else [] end\nboys = create_list(n, happy_who_b)\n\nhappy_ar = gets.chomp.split(' ').map{|i| i.to_i }\nhappy_amount = happy_ar[0]\nhappy_who_g = if happy_amount > 0 then happy_ar[1..-1] else [] end\ngirls = create_list(m, happy_who_g)\n\n\ndef check(n, m, boys, girls)\n # gcd = n.gcd(m)\n (boys.length * girls.length).times do |i|\n if boys[i % boys.length] or girls[i % girls.length]\n boys[i % boys.length] = true\n girls[i % girls.length] = true\n end\n end\n return (boys.all?{|x| x} and girls.all?{|x| x})\nend\n\nputs check(n, m, boys, girls) ? 'Yes' : 'No'"}, {"source_code": "pa=Array.new(105,0)\npb=Array.new(105,0)\npc=Array.new\n\nstr=gets.to_s\npc=str.split\nn=pc[0].to_i\nm=pc[1].to_i\n\nk=n*m\nstr=gets.to_s\npc=str.split\nb=pc[0].to_i\nfor i in 1..b\n pa[pc[i].to_i]=1\nend\nstr=gets.to_s\npc=str.split\nb=pc[0].to_i\nfor i in 1..b\n pb[pc[i].to_i]=1\nend\n\nfor i in 0..k\n a=i%n\n b=i%m\n if pa[a]==1 || pb[b]==1\n pa[a]=pb[b]=1\n end\nend\n\nh=0\nfor i in 0..n-1\n if pa[i]==0\n h=1\n break\n end\nend\n\nfor i in 0..m-1\n if pb[i]==0 || h==1\n h=1\n break\n end\nend\n\nif h==1\n puts \"No\"\nelsif h==0\n puts \"Yes\"\nend"}, {"source_code": "pa=Array.new(105,0)\npb=Array.new(105,0)\npc=Array.new\n\nstr=gets.to_s\npc=str.split\nn=pc[0].to_i\nm=pc[1].to_i\n\nk=n*m\nstr=gets.to_s\npc=str.split\nb=pc[0].to_i\nfor i in 1..b\n pa[pc[i].to_i]=1\nend\nstr=gets.to_s\npc=str.split\nb=pc[0].to_i\nfor i in 1..b\n pb[pc[i].to_i]=1\nend\n\nfor i in 0..n-1\n puts pa[i]\nend\nfor i in 0..m-1\n puts pb[i]\nend\n\nfor i in 0..k\n a=i%n\n b=i%m\n if pa[a]==1 || pb[b]==1\n pa[a]=pb[b]=1\n end\nend\n\nh=0\nfor i in 0..n-1\n if pa[i]==0\n h=1\n break\n end\nend\n\nfor i in 0..m-1\n if pb[i]==0 || h==1\n h=1\n break\n end\nend\n\nif h==1\n puts \"No\"\nelsif h==0\n puts \"Yes\"\nend"}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\na = gets.strip.split.map(&:to_i)\nb = gets.strip.split.map(&:to_i)\n\na.delete_at(0)\nb.delete_at(0)\n\nh1 = []\nh2 = []\n\n(0..(n+m)).each {|x|\n h1 << 0\n h2 << 0\n}\n\na.each { |x| h1[x] = 1 }\nb.each { |x| h2[x] = 1 }\n\n(0..(n*m)).each {|x|\n if h1[x % n] == 1 || h2[x % m] == 1\n h1[x % n] = 1\n h2[x % m] = 1\n end\n}\n\nres = 0\n(0..(n-1)).each {|x| res = 1 if h1[x] == 0}\n(0..(m-1)).each {|x| res = 1 if h2[x] == 0}\n\nif res == 1\n puts \"No\"\nelse\n puts \"Yes\"\nend"}], "src_uid": "65efbc0a1ad82436100eea7a2378d4c2"} {"source_code": "def run(input = STDIN.read)\n periods = input.split(\"\\n\")[1..-1].map { |row| row.split.map(&:to_i) }\n\n periods.sort_by!(&:first)\n\n current_max = periods.first.last\n res = 0\n periods[1..-1].each do |period|\n res += 1 if period.last < current_max\n current_max = period.last if period.last > current_max\n end\n\n puts res\nend\n\nrun", "positive_code": [{"source_code": "#f = File.open(\"c.in\", \"r\")\nclass C <\n\tStruct.new(:ai, :bi)\nend\n\nn = gets.to_i\na = Array.new\n\nfor i in 0...n\n\tl = gets.split\n\tc = C.new\n\tc.ai = l[0].to_i\n\tc.bi = l[1].to_i\n\ta.push(c)\nend\n\na = a.sort {|o, p| o[:ai] <=> p[:ai]}\nm = r = 0\n\nfor i in 0...n\n\tm = [m, a[i].bi].max\n\tif a[i].bi < m\n\t\tr += 1\n\tend\nend\n\nputs r\n"}, {"source_code": "require \"set\"\nn = gets.chomp.to_i\nevents = []\nevents2 = []\nn.times do\n e = gets.chomp.split(\" \").map {|e| e.to_i}\n events.push e\nend\n\ntotal = 0\nevents = events.sort_by {|e| e[0]}\nlargest = 0\n\nevents.each do |e|\n if largest > e[1]\n total += 1\n end\n if e[1] > largest\n largest = e[1]\n end\nend\n\nputs total\n"}, {"source_code": "n = gets.to_i\narr = []\nn.times do\n\tarr << gets.split(\" \").map(&:to_i)\nend\n\narr.sort!#_by!{|x| [x[0],-x[1]]}\n\ncount = 0\nmax = -1\narr.map(&:last).each do |a|\n\t\n\tif a < max\n\t\tcount += 1\n\telse\n\t\tmax = a\n\tend\nend\nputs count"}, {"source_code": "\ndef history\n coord = []\n STDIN.gets.to_i.times { coord << gets.split(' ').map{|i| i.to_i} }\n coord.sort!{|x, y| y[1] <=> x[1] }\n\n if coord.size < 2\n puts 0\n return\n end\n\n tot = 0\n min = coord[0][0]\n (1...coord.size).each do |ind|\n c = coord[ind]\n if c[0] > min\n tot += 1\n else\n min = c[0]\n end\n end\n p tot\nend\n\nhistory"}], "negative_code": [{"source_code": "\ndef history\n coord = []\n STDIN.gets.to_i.times { coord << gets.split(' ').map{|i| i.to_i} }\n coord.sort!{|x, y| y[1] <=> x[1] }\n\n if coord.size < 2\n puts 0\n return\n end\n\n ind = 1\n max = coord[0][1]\n ind += 1 while coord[ind][1] >= max\n puts coord.size-ind\nend\n\n\nhistory"}, {"source_code": "n = gets.to_i\narr = []\nn.times do\n\tarr << gets.split(\" \").map(&:to_i)\nend\n\narr.sort_by!{|x| [x[0],-x[1]]}\n\nrange_arr = []\ncount = 0\narr.each do |a|\n\tfound = false\n\tif range_arr.any?{ |b| a[0] > b[0] && a[1] < b[1] } \t\t\n\t\tfound = true\n\t\tcount += 1\n\t\tbreak\n\tend\n\trange_arr << a unless found\nend\nputs count"}], "src_uid": "dfb1479ffa17489095b6bf1921758f7e"} {"source_code": "gets\n$<.map do\n x,y=_1.split.map &:to_i\n if (x+y).odd?\n puts \"-1 -1\"\n elsif x.even?\n puts [x/2,y/2]*\" \"\n else\n puts (x>y ? [x/2+1,y/2]*\" \" : [x/2,y/2+1]*\" \")\n end\nend\n \n ", "positive_code": [{"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n x, y = ints\r\n if (x + y).odd?\r\n puts \"-1 -1\"\r\n else\r\n a, b = x.div_ceil(2), y / 2\r\n puts \"#{a} #{b}\"\r\n # STDERR.puts \"#{a+b} == #{(x - a).abs + (y - b).abs}\"\r\n end\r\n end\r\n}\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\nYESNO = %w(No Yes)\r\nINF = 10**9\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts YESNO[1] end\r\ndef no; puts YESNO[0] end\r\ndef yesno t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]"}, {"source_code": "gets.to_i.times do\r\n x, y = gets.split.map(&:to_i)\r\n diff = (x - y).abs\r\n if diff.even?\r\n if x > y\r\n puts \"#{diff / 2} #{y}\"\r\n else\r\n puts \"#{x} #{diff / 2}\"\r\n end\r\n else\r\n puts \"-1 -1\"\r\n end\r\nend"}], "negative_code": [{"source_code": "gets\n$<.map do\n x,y=_1.split.map &:to_i\n if (x+y).odd?\n puts \"-1 -1\"\n elsif x.even?\n puts [x/2,y/2]*\" \"\n else\n x,y=y,x if x a.size\n puts a.inject{|sum,i| sum+=i}.abs\nelse\n puts a[0,m].inject{|sum,i| sum+=i}.abs\nend\n'''\n"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\nprices = gets.chomp.split.map(&:to_i)\n\nmin, sum = 0, 0\n\nprices.sort[0..m - 1].each do |p|\n sum += p\n min = [min, sum].min\nend\n\nputs min.abs"}, {"source_code": "n, m = gets.strip.split(\" \").map{|s| s.to_i}\nprices = gets.strip.split(\" \").map {|s| - s.to_i}.reject {|j| j <= 0}.sort.reverse\nprint prices[0...m].reduce(0, :+)"}, {"source_code": "n, m = gets.split.map{|s| s.to_i}\nprices = gets.split.map {|s| s.to_i}.select {|j| j < 0}.sort\nprint -prices[0...m].reduce(0, :+)"}, {"source_code": "n, m = gets.split(' ').map(&:to_i)\nputs gets.split(' ').map(&:to_i).select { |x| x < 0 }.sort.first(m).inject(0, &:+).abs\n"}, {"source_code": "ns,ms= gets.chomp.split(/ /)\nn = ns.to_i\nm = ms.to_i\n\nsa = gets.chomp.split(/ /)\nsa.map!{|x| x.to_i}\n\nsum = 0\n\nsa.sort!\nfor i in 0..m-1\n\tsum += sa[i] if sa[i] < 0\nend\n\nputs -sum"}, {"source_code": "n,m=gets.split.map(&:to_i)\nv=[]\ngets.split.map{|i|\n\ti=i.to_i\n\tif i<0 then\n\t\tv << i\n\tend\n}\nv.sort!\nans=0\n[m,v.size].min.times{|i|\n\tans-=v[i]\n}\np ans\n\n"}, {"source_code": "a = gets.chop.split(/ /)\na.map! do |i|\ni = i.to_i\nend\n\nb = gets.chop.split(/ /)\nb.map! do |i|\ni = i.to_i\nend\n\n$cnt=0\n$tmp = Array.new\nfor i in 0..(b.size-1)\nif b[i] < 0\n$tmp[$cnt] = i\n$cnt=$cnt + 1\nend\nend\n\n$sum = 0\nif $cnt <= a[1] \n$tmp.each do |i|\n$sum=$sum - b[i]\nend\nelse\nb.sort!\nfor i in 0..a[1]-1\n$sum=$sum - b[i]\nend\nend\n\nputs $sum"}], "negative_code": [{"source_code": "a = gets.chop.split(/ /)\na.map! do |i|\ni = i.to_i\nend\n\nb = gets.chop.split(/ /)\nb.map! do |i|\ni = i.to_i\nend\n\n$cnt=0\n$tmp = Array.new\nfor i in 0..(b.size-1)\nif b[i] < 0\n$tmp[$cnt] = i\n$cnt=$cnt + 1\nend\nend\n\n$sum = 0\nif $cnt <= a[1] \n$tmp.each do |i|\n$sum=$sum - b[i]\nend\nelse\nb.sort!\nfor i in 0..a[1]\n$sum=$sum - b[i]\nend\nend\n\nputs $sum"}, {"source_code": "n,m=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i).sort\nt,i=0,0\nwhile n!=0\n\tt+=a[i] if a[i]<0\n\tn-=1\n\ti+=1\nend\nputs -t"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).find_all {|x| x < 0 }\nputs (sc = a.first([a.size, m].min).inject(:+)).nil? ? 0 : -sc"}, {"source_code": "n, m = gets.split.map(&:to_i)\nj, score = 0, 0\na = gets.split.map(&:to_i).sort!\nwhile j<=m and a[j] < 0\n score += a[j]\n j+=1\nend\nputs -score"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}.sort\nans=0\nm.times{|i|\n\tans-=x[i]\n}\nputs ans\n\n"}, {"source_code": "#=================================\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(ARGV[0], \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn,m=gets.split.map(&:to_i)\nputs gets.split.map(&:to_i).sort[0, m].inject(:+).abs\n"}, {"source_code": "#=================================\nif ARGV.include?(\"ONLINE_JUDGE\")\n\t$stdin = File.open(ARGV[0], \"r\")\n\tARGV.delete(\"ONLINE_JUDGE\")\nend\n#=================================\n\nn,m=gets.split.map(&:to_i)\ndata=gets.split.map(&:to_i)\n\nget=data.select{|v| v<0}.inject(0){|sum, val| sum+=val}.abs\nputs get\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort\nputs -a[0...m].reduce(:+)\n"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i).select{|a| a<0}.sort\nsum = arr.inject(0,:+)\nputs -sum\n"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\nputs gets.chomp.split.map(&:to_i).sort[0..m - 1].inject(0) { |sum, v| sum + v }.abs"}, {"source_code": "n, m = gets.strip.split(\" \").map{|s| s.to_i}\nprices = gets.strip.split(\" \").map {|s| - s.to_i}.reject {|j| j <= 0}.sort.reverse\nm = prices.length if m > prices.length\nprint prices[0..m].reduce(0) {|s, a| s + a}"}], "src_uid": "9a56288d8bd4e4e7ef3329e102f745a5"} {"source_code": "# coding: utf-8\n\n# 7-segment display\nseg = [[0, 6], [1, 2], [2, 6], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]\nt = gets.to_i\nt.times {\n n = gets.to_i\n q, r = n/2, n%2\n\n if r == 0\n puts \"1\"*q\n else\n puts \"7\" + (\"1\"*(q-1))\n end\n}", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n\n if n % 2 == 0\n puts '1' * (n / 2)\n else\n puts '7' + '1' * ((n - 3) / 2)\n end\nend\n"}, {"source_code": "gets.strip.to_i.times do\n n = gets.strip.to_i\n if n % 2 == 0\n puts \"1\" * (n / 2)\n else\n puts \"7\" + (\"1\" * ((n - 3) / 2))\n end\nend\n"}], "negative_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n\n if n % 2 == 0\n puts '1' * (n / 2)\n else\n puts '1' * ((n - 3) / 2) + '7'\n end\nend\n"}], "src_uid": "07db573b0db736d798b6c18c06c32f3d"} {"source_code": "n = gets.chomp.to_i\r\nfor _ in 0...n\r\n num = gets.chomp\r\n len = num.length()\r\n if num.to_i % 7 == 0\r\n puts num\r\n else\r\n for i in 1..9\r\n temp = (num[0, len-1] + i.to_s).to_i\r\n if temp % 7 == 0\r\n puts temp\r\n break\r\n end\r\n end\r\n end\r\nend", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n if n % 7 == 0\n puts n\n else\n m = n / 10\n (0..9).each { |d|\n if (m - 2 * d) % 7 == 0\n puts \"#{m}#{d}\"\n break\n end\n }\n end\nend\n"}], "negative_code": [], "src_uid": "128372d890f632494e59e81287abd85a"} {"source_code": "gets.to_i.times do\r\n n,l,r=gets.split.map(&:to_i)\r\n a=gets.split.map(&:to_i).sort\r\n c=0\r\n i=0\r\n j=n-1\r\n k=n-1\r\n while ii&&a[i]+a[j]>=l\r\n j-=1\r\n end\r\n while k>0&&a[i]+a[k]>r\r\n k-=1\r\n end\r\n c+=[k,i].max-[j,i].max\r\n i+=1\r\n end\r\n puts c\r\nend\r\n", "positive_code": [{"source_code": "def l_bound(x, i, a)\r\n lo, hi = 0, i - 1\r\n while lo <= hi\r\n mi = (lo + hi) / 2\r\n if a[mi] < x\r\n lo = mi + 1\r\n elsif\r\n hi = mi - 1\r\n end\r\n end\r\n return lo\r\nend\r\n\r\ndef u_bound(x, i, a) \r\n lo, hi = 0, i - 1\r\n while lo <= hi\r\n mi = (lo + hi) / 2\r\n if a[mi] <= x\r\n lo = mi + 1\r\n elsif\r\n hi = mi - 1\r\n end\r\n end\r\n return hi\r\nend\r\n\r\nfor t in 0...gets.to_i\r\n n, l, r = gets.split.map(&:to_i)\r\n a = gets.split.map(&:to_i).sort\r\n ans = 0\r\n (0...n).each do |i|\r\n lo = l_bound(l - a[i], i, a)\r\n hi = u_bound(r - a[i], i, a)\r\n if lo <= hi and lo >= 0 and hi < i\r\n ans += hi - lo + 1\r\n end\r\n end\r\n puts ans\r\nend"}], "negative_code": [], "src_uid": "2f12b2bb23497119bb70ca0839991d68"} {"source_code": "require 'Matrix'\n\ndef modpowMatrix(x,n)\n ret = Matrix.I(x.column_size)\n while n > 0\n ret = (ret * x).map{|v| v % (MOD-1)} if n&1 == 1\n x = (x*x).map{|v| v % (MOD-1)}\n n >>= 1\n end\n return ret\nend\n\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\nMOD = 10**9+7\nn,x,y,z,c = gets.split.map(&:to_i)\na = Matrix.rows([[1,1,1],[1,0,0],[0,1,0]])\nb = Matrix.rows([[1,1,1,1,0],[1,0,0,0,0],[0,1,0,0,0],[0,0,0,1,1],[0,0,0,0,1]])\n\nm = modpowMatrix(a,n-3)\nft = Matrix.columns([[0,0,0,2,2]])\nk = (modpowMatrix(b,n-3)*ft)[0,0] % (MOD-1)\np ((modpow(c,k) * modpow(z,m[0,0]) % MOD) * modpow(y,m[0,1]) % MOD) * modpow(x,m[0,2]) % MOD\n", "positive_code": [{"source_code": "require 'Matrix'\n \ndef fpmmat(x,n)\n ret = Matrix.I(x.column_size)\n while n > 0\n ret = (ret * x).map{|v| v % (MOD-1)} if n&1 == 1\n x = (x * x).map{|v| v % (MOD-1)}\n n >>= 1\n end\n return ret\nend\n \ndef fpm(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\nMOD = 10**9+7\nn,x,y,z,c = gets.split.map(&:to_i)\na = Matrix.rows([[1,1,1],[1,0,0],[0,1,0]])\nb = Matrix.rows([[1,1,1,1,0],[1,0,0,0,0],[0,1,0,0,0],[0,0,0,1,1],[0,0,0,0,1]])\n \nm = fpmmat(a,n-3)\nft = Matrix.columns([[0,0,0,2,2]])\nk = (fpmmat(b,n-3)*ft)[0,0] % (MOD-1)\np ((fpm(c,k) * fpm(z,m[0,0]) % MOD) * fpm(y,m[0,1]) % MOD) * fpm(x,m[0,2]) % MOD"}], "negative_code": [{"source_code": "require 'Matrix'\n\ndef modpowMatrix(x,n)\n ret = Matrix.I(x.column_size)\n while n > 0\n\t\tret = (ret * x).map{|v| v%MOD} if n&1 == 1\n x = (x*x).map{|v| v%MOD}\n n >>= 1\n end\n return ret\nend\n\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\nMOD = 10**9+7\nn,x,y,z,c = gets.split.map(&:to_i)\na = Matrix.rows([[1,1,1],[1,0,0],[0,1,0]])\nb = Matrix.rows([[1,1,1,1,0],[1,0,0,0,0],[0,1,0,0,0],[0,0,0,1,1],[0,0,0,0,1]])\n\nm = modpowMatrix(a,n-3)\ncf = Matrix.columns([[0,0,0,2,2]])\nk = (modpowMatrix(b,n-3)*cf)[0,0] % MOD\np ((modpow(c,k) * modpow(z,m[0,0]) % MOD) * modpow(y,m[0,1]) % MOD) * modpow(x,m[0,2]) % MOD\n"}], "src_uid": "6fcd8713af5a108d590bc99da314cded"} {"source_code": "n=gets.to_i\na=[0]+gets.split.map(&:to_i)\n1.upto(n).to_a.combination(2).each{|i,j|k=a.index a[i]+a[j];\"#{p k,i,j;exit}\"if k}\np -1\n", "positive_code": [{"source_code": "n = gets.to_i\n\nlens = gets.split.map{|i| i.to_i}\n\ni = 0\nk = true\nwhile k && i < n-1 do \n j = 1\n while k && j < n do\n if (t = lens.index(lens[i] + lens[j])) then\n k = false\n result = (t+1).to_s + \" \" + (i+1).to_s + \" \" + (j+1).to_s\n end\n j += 1\n end\n i += 1\nend\n\nif k then\n puts \"-1\"\nelse\n puts result\nend"}, {"source_code": "@ok = false\n\ndef chk3(arr, i, j, k)\n\tif (arr[i] == arr[j]+arr[k]) \n\t\tputs (i+1).to_s + \" \" + (j+1).to_s + \" \" + (k+1).to_s\t\t\t\t\n\t\t@ok = true\t\t\n\t\treturn true\n\tend\n\treturn false\nend\n\nn = gets.to_i\ns = gets\nna = s.split(/ /)\narr = Array.new(n)\nfor i in 0..n-1\n arr[i] = na[i].to_i\nend\n\n(n-1).downto(2) { |i|\n\t(i-1).downto(1) { |j|\n\t\t(j-1).downto(0) { |k| \n\t\t\tbreak if chk3(arr, i, j, k)\n\t\t\tbreak if chk3(arr, i, k, j)\n\t\t\tbreak if chk3(arr, j, i, k)\n\t\t\tbreak if chk3(arr, j, k, i)\n\t\t\tbreak if chk3(arr, k, i, j)\n\t\t\tbreak if chk3(arr, k, j, i)\n\t\t}\n\t\tbreak if @ok\n\t}\n\tbreak if @ok\n}\nputs(\"-1\") if @ok == false\n"}, {"source_code": "#!/usr/bin/ruby\ngets;a=gets.split.map(&:to_i)\na.size.times{|i|a.size.times{|j|(j+1).step(a.size-1){|k|\n\tif a[i]==a[j]+a[k] then puts [i+1,j+1,k+1]*' ';exit end\n}}}\np -1"}, {"source_code": "a = gets.chop\n\nb = gets.chop.split(/ /)\nb.map! do |i|\ni = i.to_i\nend\n\nc = Array.new\nflag = 0\nfor i in 0..b.size-1\n\tfor j in i+1..b.size-1\n\t\tfor k in j+1..b.size-1\n\t\t\tif b[i] == b[j]+b[k]\n\t\t\t\tflag=1\n\t\t\t\tc[0]=i+1\n\t\t\t\tc[1]=j+1\n\t\t\t\tc[2]=k+1\n\t\t\telsif b[j] == b[i]+b[k]\n\t\t\t\tflag=1\n\t\t\t\tc[0]=j+1\n\t\t\t\tc[1]=i+1\n\t\t\t\tc[2]=k+1\n\t\t\telsif b[k] == b[i]+b[j]\n\t\t\t\tflag=1\n\t\t\t\tc[0]=k+1\n\t\t\t\tc[1]=i+1\n\t\t\t\tc[2]=j+1\n\t\t\tend\n\t\t\tif flag==1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tif flag==1\n\t\t\tbreak\n\t\tend\n\tend\n\tif flag==1\n\t\tbreak\n\tend\nend\n\nif flag==0\n\tprint -1\nelse\n\tfor i in 0..c.size-1\n\t\tprint c[i]\n\t\tif i !=c.size-1\n\t\t\tprint \" \" \n\t\tend\n\tend\nend"}, {"source_code": "a = gets.chop\n\nb = gets.chop.split(/ /)\nb.map! do |i|\ni = i.to_i\nend\n\nc = Array.new\nflag = 0\nfor i in 0..b.size-1\n\tfor j in i+1..b.size-1\n\t\tfor k in j+1..b.size-1\n\t\t\tif b[i] == b[j]+b[k]\n\t\t\t\tflag=1\n\t\t\t\tc[0]=i+1\n\t\t\t\tc[1]=j+1\n\t\t\t\tc[2]=k+1\n\t\t\telsif b[j] == b[i]+b[k]\n\t\t\t\tflag=1\n\t\t\t\tc[0]=j+1\n\t\t\t\tc[1]=i+1\n\t\t\t\tc[2]=k+1\n\t\t\telsif b[k] == b[i]+b[j]\n\t\t\t\tflag=1\n\t\t\t\tc[0]=k+1\n\t\t\t\tc[1]=i+1\n\t\t\t\tc[2]=j+1\n\t\t\tend\n\t\t\tif flag==1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tif flag==1\n\t\t\tbreak\n\t\tend\n\tend\n\tif flag==1\n\t\tbreak\n\tend\nend\n\nif flag==0\n\tprint -1\nelse\n\tfor i in 0..c.size-1\n\t\tprint c[i].to_s + \" \"\n\tend\nend"}, {"source_code": "n=gets.to_i\na=[0]+gets.split.map(&:to_i)\n1.upto(n).to_a.combination(2).each{|i,j|k=a.index a[i]+a[j];\"#{p k,i,j;exit}\"if k}\np -1\n"}, {"source_code": "n=gets.to_i\na=[0]+gets.split.map(&:to_i)\n1.upto(n).to_a.combination(2).each{|i,j|k=a.index a[i]+a[j];\"#{p k,i,j;exit}\"if k}\np -1"}, {"source_code": "n=gets.to_i\na=gets.chomp.split.map(&:to_i)\nfor i in 0...n\n\tfor j in 0...n\n\t\tfor k in 0...n\n\t\t\tif i!=j && i!=k && j!=k && a[i]==a[j]+a[k]\n\t\t\t\tputs \"#{i+1} #{j+1} #{k+1}\"\n\t\t\t\texit\n\t\t\tend\n\t\tend\n\tend\nend\nputs \"-1\""}, {"source_code": "n=gets.to_i\na=[0]+gets.split.map(&:to_i)\n1.upto(n).to_a.combination(2).each{|i,j|k=a.index a[i]+a[j];\"#{p k,i,j;exit}\"if k}\np -1\n"}, {"source_code": "n=gets.to_i\na=[0]+gets.split.map(&:to_i)\n1.upto(n).to_a.combination(2).each{|i,j|k=a.index a[i]+a[j];\"#{p k,i,j;exit}\"if k}\np -1\n"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\ndone = false\nx = y = z = 0\nn.times do |i|\n break if done\n ai = a[i]\n n.times do |j|\n next if i == j\n break if done\n aj = a[j]\n n.times do |k|\n next if j == k\n if aj + a[k] == ai\n x = i + 1\n y = k + 1\n z = j + 1\n done = true\n break\n end\n end\n end\nend\nif !done\n puts \"-1\"\nelse\n puts \"#{x} #{y} #{z}\"\nend\n"}, {"source_code": "n=gets.to_i\na=[0]+gets.split.map(&:to_i)\n1.upto(n).to_a.combination(2).each{|i,j|k=a.index a[i]+a[j];\"#{p k,i,j;exit}\"if k}\np -1"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\n\nq = {}\na.each_index { |i| q[a[i]] = i }\n\nn.times do |i|\n i.times do |j|\n if q[ a[i] + a[j] ] != nil\n puts \"#{ q[a[i] + a[j]] + 1 } #{i + 1} #{j + 1}\"\n exit\n end\n end\nend\n\nputs \"-1\""}, {"source_code": "n=gets.to_i\na=[0]+gets.split.map(&:to_i)\n1.upto(n).to_a.combination(2).each{|i,j|k=a.index a[i]+a[j];\"#{p k,i,j;exit}\"if k}\np -1"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tstrinp=gets.chomp.split(\" \")\n\tstrinp=strinp.map{|i| i.to_i}\n\tfor i in 0...n\n\t\tsum=strinp[i]\n\t\tf=false\n\t\tfor j in 0...n\n\t\t\trem=sum-strinp[j]\n\t\t\t\tfor k in 0...n \n\t\t\t\t\tif strinp[k]==rem && k!=j && k!=i\n\t\t\t\t\t\tputs \"%d %d %d\" %[i+1,j+1,k+1]\n\t\t\t\t\t\tf=true\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tif f \n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tif f \n\t\t\tbreak\n\t\tend\n\tend\n\tif !f\n\t\tputs \"-1\"\n\tend\nend\nmain()"}, {"source_code": "n=gets.to_i\na=[0]+gets.split.map(&:to_i)\n1.upto(n).to_a.combination(2).each{|i,j|k=a.index a[i]+a[j];\"#{p k,i,j;exit}\"if k}\np -1\n"}, {"source_code": "# def bin_search(arr,e)\n# \tn = arr.length\n# \tl = 0\n# \tr = n - 1\n\n# \twhile l <= r\n# \t\tm = l + (r-l) / 2\n# \t\tif arr[m] == e\n# \t\t\tputs \"#{m}\"\n# \t\t\treturn m\n# \t\telsif e < arr[m]\n# \t\t\tr = m - 1\n# \t\telse\n# \t\t\tl = m + 1\n# \t\tend\t\t\t\n# \tend\n\n# \treturn false\n\t\n# end\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n# arr.sort!\nans = false\nans_i = ans_j = ans_k = 0\narr.each_with_index do |i,ind_i|\n\tarr[ind_i+1..-1].each_with_index do |j,ind_j|\n\t\t# puts \"#{i+j} ans #{bin_search(arr[ind_j+1..-1], i + j)}\"\n\t\tind_k = arr.index(i+j) #bin_search(arr[ind_j+1..-1], i + j)\n\t\t# puts \"#{i} #{j} #{ind_k}\"\n\t\tif ind_k\n\t\t\tans = true\n\t\t\tans_j = ind_i\n\t\t\tans_k = ind_i + ind_j + 1\n\t\t\tans_i = ind_k\n\t\t\tbreak\n\t\tend\n\tend\n\tbreak if ans\nend\n\nputs ans ? \"#{ans_i+1} #{ans_j+1} #{ans_k+1}\": \"-1\" "}, {"source_code": "gets\nmas = gets.split(\" \")\nfor i in (0..mas.size - 1)\n mas[i] = mas[i].to_i\nend\n\nfor i in (0..mas.size - 1)\n for j in (0..mas.size - 1)\n for k in (0..mas.size - 1)\n if (i != j && j != k && i != k && mas[i] == mas[j]+mas[k])\n print i+1, \" \", j+1, \" \", k+1\n exit\n end\n end\n end\nend\n\nprint -1"}, {"source_code": "gets\nworms = gets.chomp.split.map(&:to_i)\n\nres = [-1]\nfound = false\nworms.each_with_index do |w1, i|\n break if found\n worms.each_with_index do |w2, j|\n break if found\n next if j == i\n worms.each_with_index do |w3, k|\n break if found\n next if k == j or k == i\n if w3 == w1 + w2\n res = [k.succ, j.succ, i.succ]\n found = true\n end\n end\n end\nend\nputs res.join(' ')\n"}, {"source_code": "n=gets.to_i\na=[0]+gets.split.map(&:to_i)\n1.upto(n).to_a.combination(2).each{|i,j|k=a.index a[i]+a[j];\"#{p k,i,j;exit}\"if k}\np -1\n"}, {"source_code": "n=gets.to_i\na=[0]+gets.split.map(&:to_i)\n1.upto(n).to_a.combination(2).each{|i,j|k=a.index a[i]+a[j];\"#{p k,i,j;exit}\"if k}\np -1\n"}, {"source_code": "n=gets.to_i\na=[0]+gets.split.map(&:to_i)\n1.upto(n).to_a.combination(2).each{|i,j|k=a.index a[i]+a[j];\"#{p k,i,j;exit}\"if k}\np -1\n"}], "negative_code": [{"source_code": "n = gets.to_i\n\nlens = gets.split.map{|i| i.to_i}\n\ni = 0\nk = true\nwhile k && i < n-1 do \n j = 1\n while k && j < n do\n if (t = lens.index(lens[i] + lens[j])) then\n k = false\n result = lens[t].to_s + \" \" + lens[i].to_s + \" \" + lens[j].to_s\n end\n j += 1\n end\n i += 1\nend\n\nif k then\n puts \"-1\"\nelse\n puts result\nend"}, {"source_code": "n = gets.to_i\ns = gets\nna = s.split(/ /)\narr = Array.new(n)\nfor i in 0..n-1\n arr[i] = na[i].to_i\nend\narr.sort!\nok = false\n(n-1).downto(2) { |i|\n\t(i-1).downto(1) { |j|\n\t\t(j-1).downto(0) { |k| \n\t\t\tif (arr[i] == arr[j]+arr[k]) \n\t\t\t\tputs (i+1).to_s + \" \" + (j+1).to_s + \" \" + (k+1).to_s\t\t\t\t\n\t\t\t\tok = true\n\t\t\t\tbreak\t\t\n\t\t\tend\n\t\t}\n\t\tbreak if ok\n\t}\n\tbreak if ok\n}\nputs(\"-1\") if ok == false\n"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\ndone = false\nx = y = z = 0\nn.times do |i|\n break if done\n ai = a[i]\n (1...n).each do |j|\n if a[j - 1] + a[j] == ai\n x = i + 1\n y = j + 1\n z = j\n done = true\n break\n end\n end\nend\nif !done\n puts \"-1\"\nelse\n puts \"#{x} #{y} #{z}\"\nend\n"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\ndone = false\nx = y = z = 0\nn.times do |i|\n break if done\n ai = a[i]\n n.times do |j|\n break if done\n aj = a[j]\n n.times do |k|\n if aj + a[k] == ai\n x = i + 1\n y = j + 1\n z = k + 1\n done = true\n break\n end\n end\n end\nend\nif !done\n puts \"-1\"\nelse\n puts \"#{x} #{y} #{z}\"\nend\n"}, {"source_code": "gets\na=gets.split.map &:to_i\na.combination(2).each{|i,j|\"#{p i+j,i,j;exit}\"if a.index i+j}\np -1"}, {"source_code": "def main()\n\tn=gets.chomp.to_i\n\tstrinp=gets.chomp.split(\" \")\n\tstrinp=strinp.map{|i| i.to_i}\n\tfor i in 0...n\n\t\tsum=strinp[i]\n\t\tf=false\n\t\tfor j in 0...n\n\t\t\trem=sum-strinp[j]\n\t\t\tsearch=strinp-[sum,strinp[j]]\n\t\t\tif search.include?(rem)\n\t\t\t\tputs \"%d %d %d\" %[sum,strinp[j],rem]\n\t\t\t\tf=true\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tif f \n\t\t\tbreak\n\t\tend\n\tend\n\tif !f\n\t\tputs \"-1\"\n\tend\nend\nmain()"}, {"source_code": "# def bin_search(arr,e)\n# \tn = arr.length\n# \tl = 0\n# \tr = n - 1\n\n# \twhile l <= r\n# \t\tm = l + (r-l) / 2\n# \t\tif arr[m] == e\n# \t\t\tputs \"#{m}\"\n# \t\t\treturn m\n# \t\telsif e < arr[m]\n# \t\t\tr = m - 1\n# \t\telse\n# \t\t\tl = m + 1\n# \t\tend\t\t\t\n# \tend\n\n# \treturn false\n\t\n# end\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n# arr.sort!\nans = false\nans_i = ans_j = ans_k = 0\narr.each_with_index do |i,ind_i|\n\tarr[ind_i+1..-1].each_with_index do |j,ind_j|\n\t\t# puts \"#{i+j} ans #{bin_search(arr[ind_j+1..-1], i + j)}\"\n\t\tind_k = arr[ind_j+1..-1].index(i+j) #bin_search(arr[ind_j+1..-1], i + j)\n\t\t# puts \"#{i} #{j} #{ind_k}\"\n\t\tif ind_k\n\t\t\tans = true\n\t\t\tans_j = ind_i\n\t\t\tans_k = ind_i + ind_j + 1\n\t\t\tans_i = ans_k + ind_k\n\t\t\tbreak\n\t\tend\n\tend\n\tbreak if ans\nend\n\nputs ans ? \"#{ans_i+1} #{ans_j+1} #{ans_k+1}\": \"-1\" "}, {"source_code": "def bin_search(arr,e)\n\tn = arr.length\n\tl = 0\n\tr = n - 1\n\n\twhile l <= r\n\t\tm = l + (r-l) / 2\n\t\tif arr[m] == e\n\t\t\treturn true\n\t\telsif e < arr[m]\n\t\t\tr = m - 1\n\t\telse\n\t\t\tl = m + 1\n\t\tend\t\t\t\n\tend\n\n\treturn false\n\t\nend\n\nn = gets.to_i\narr = gets.split(\" \").map(&:to_i)\narr.sort!\nans = false\nans_i = ans_j = ans_k = 0\narr.each_with_index do |i,ind_i|\n\tarr[ind_i+1..-1].each_with_index do |j,ind_j|\n\t\t# puts \"#{i+j} ans #{bin_search(arr[ind_j+1..-1], i + j)}\"\n\t\tif bin_search(arr[ind_j+1..-1], i + j)\n\t\t\tans = true\n\t\t\tans_i = i + j\n\t\t\tans_j = i\n\t\t\tans_k = j\n\t\t\tbreak\n\t\tend\n\tend\n\tbreak if ans\nend\n\nputs ans ? \"#{ans_i} #{ans_j} #{ans_k}\": \"-1\" "}, {"source_code": "gets\nworms = gets.chomp.split.map(&:to_i)\n\nres = [-1]\nfound = false\nworms.each_with_index do |w1, i|\n break if found\n worms.each_with_index do |w2, j|\n break if found\n next if j == i\n worms.each_with_index do |w3, k|\n break if found\n next if k == j or k == i\n if w3 == w1 + w2\n res = [i.succ, j.succ, k.succ]\n found = true\n end\n end\n end\nend\nputs res.join(' ')\n"}], "src_uid": "94a38067fc8dd8619fa6e5873ca60220"} {"source_code": "require 'set'\n\nn = readline.to_i\nf = [nil] + readline.split.map(&:to_i)\n\nzeros = (1..n).select { |i| f[i] == 0 }.to_set\nsources = (1..n).select { |i| f[i] != 0 and f[f[i]] == 0 }\nsinks = (1..n).to_set.difference(f).select { |i| f[i] != 0 }\n\nif sources.length > 1 then\n for source in sources[0..-2] do\n f[f[source]] = sinks.pop\n zeros.delete(f[source])\n end\nend\n\nzeros = zeros.to_a\nzeros.each_cons(2) do |i,j|\n f[i] = j\nend\nf[zeros[-1]] = zeros[0]\n\nif sources.length > 0 then\n if zeros.length > 1 then\n f[zeros[(zeros.find_index(f[sources[-1]]) - 1) % zeros.length]] = sinks.pop\n else\n f[f[sources[-1]]] = sinks.pop\n end\nend\n\nprint(f[1..-1].join(' '))", "positive_code": [{"source_code": "gets.strip.to_i\nf = gets.strip.split(' ').map(&:to_i)\nno_rece = Array.new(f.size, -1)\nno_give = []\nf.each_with_index do |e, i|\n no_give << (i+1) if e.zero?\n no_rece[e - 1] = i unless e.zero?\nend\nno_rece = no_rece.each_with_index.map { |e, i| e == -1 ? (i + 1) : nil }.compact.sort\nno_give = no_give.sort.reverse\n# inter = no_rece & no_give\n# puts no_rece.inspect\n# puts no_give.inspect\nno_give.each_with_index do |e, i|\n if no_rece[i] == e\n a = no_give[i]\n b = no_rece[i]\n c = i ==0 ? no_give[i +1] : no_give[i - 1]\n d = i ==0 ? no_rece[i +1] : no_rece[i - 1]\n # no_give[i] = c\n # no_give[i == 0 ? i + 1 : i - 1] = a\n no_rece[i] = d\n no_rece[i == 0 ? i + 1 : i - 1] = b\n end\nend\n# puts no_rece.inspect\n# puts no_give.inspect\nno_give.each_with_index do |e, i|\n f[e - 1] = no_rece[i]\nend\nputs f.join(\" \")\n# puts f.map { |e| e.zero? ? }"}, {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/20\n s=lackpos.size\n s.times do |i|\n f[lackpos[i]-1]=lackpos[(i+1)%s]\n end\nend\n#puts f.to_s\n\nn.times do |i|\n next if f[i]!=0\n f[i]=ar3.shift\n \n break if ar.size==0\nend\n \nputs f.join(\" \")"}], "negative_code": [{"source_code": "n=gets.to_i\nf=gets.split.map(&:to_i)\nfixed=f.sort_by{|x|-x}.to_a\n#puts f.to_s\n#puts fixed.to_s\n\nar=(1..n).to_a\nn.times do |i|\n break if fixed[i]==0\n ar.delete_at(fixed[i]-1)\nend\n#puts ar.to_s\nar.push(ar.shift)\nn.times do |i|\n next if f[i]!=0\n nn=ar.shift\n if nn==i+1\n f[i]=ar.shift\n ar<= 31 && s != \"36\" && s != \"40\" && s != \"44\" \n puts \"YES\"\n print \"6\"\n print \" \"\n print \"10\"\n print \" \"\n print \"14\"\n print \" \"\n print s.to_i - 30\n print \"\\n\"\n elsif s == \"40\" || s == \"36\" || s == \"44\"\n puts \"YES\"\n print \"6\"\n print \" \"\n print \"10\"\n print \" \"\n print \"15\"\n print \" \"\n print s.to_i - 31\n print \"\\n\"\n else\n puts \"NO\"\n end\nend\n", "positive_code": [{"source_code": "$, = \" \"\n$\\ = \"\\n\"\ngets.to_i.times do\n n = gets.to_i\n if n <= 30\n puts \"NO\"\n else\n puts \"YES\"\n if n == 36 || n == 40 || n == 44\n print 6, 10, 15, n - 31\n else\n print 6, 10, 14, n - 30\n end\n end\nend"}, {"source_code": "n = gets.to_i\nans = []\nn.times do\n x = gets.to_i\n if x <= 30\n ans << [-1,-1,-1,-1]\n elsif x == 36 || x == 40 || x == 44\n ans << [6,10,15,x-31]\n else\n ans << [6,10,14,x-30]\n end\nend\nans.each do |x|\n if x[0] == -1\n puts \"NO\"\n else\n puts \"YES\"\n puts \"#{x[0]} #{x[1]} #{x[2]} #{x[3]}\"\n end\nend"}, {"source_code": "t=gets.chomp.to_i\nrep=15\nwhile t!=0\n ar=[6,10,14]\n sum=30\n num=gets.chomp.to_i \n ar.each_with_index do |x,i|\n if (num-sum == x)\n ar[ar.length-1]=rep\n sum+=1\n break\n end\n \n end\nif(num-sum >= 1)\n puts \"YES\"\n ar.each { |x| print \"#{x} \"}\n print \"#{num-sum}\"\n puts\n else\n puts \"NO\"\nend\nt-=1\nend"}], "negative_code": [{"source_code": "t= gets.chomp.to_i\nar=[6,10,14]\nsum = 30\nwhile t!=0\n num= gets.chomp.to_i\nif(num-sum >= 1)\n puts \"YES\"\n ar.each { |x| print \"#{x} \"}\n print \"#{num-sum}\"\n else\n puts \"NO\"\nend\nt-=1\nend"}, {"source_code": "t=gets.chomp.to_i\nar=[6,10,14]\nrep=15\nsum = 30\nwhile t!=0\n num=gets.chomp.to_i \n ar.each_with_index do |x,i|\n if (num-sum == x)\n puts\"in if\"\n ar[ar.length-1]=rep\n sum+=1\n break\n end\n\n end\n p \"sum = #{sum}\"\n ar.each {|x| puts x}\nif(num-sum >= 1)\n puts \"YES\"\n ar.each { |x| print \"#{x} \"}\n print \"#{num-sum}\"\n puts\n else\n puts \"NO\"\nend\nt-=1\nend\n"}, {"source_code": "t= gets.chomp.to_i\nar=[6,10,14]\nsum = 30\nwhile t!=0\n num= gets.chomp.to_i\nif(num-sum >= 1)\n puts \"YES\"\n print \"#{num-sum} \"\n ar.each { |x| print \"#{x} \"}\n else\n puts \"NO\"\nend\nt-=1\nend\n"}, {"source_code": "t=gets.chomp.to_i\n\nrep=15\nsum = 30\nwhile t!=0\n ar=[6,10,14]\n num=gets.chomp.to_i \n ar.each_with_index do |x,i|\n if (num-sum == x)\n ar[ar.length-1]=rep\n sum+=1\n break\n end\n \n end\nif(num-sum >= 1)\n puts \"YES\"\n ar.each { |x| print \"#{x} \"}\n print \"#{num-sum}\"\n puts\n else\n puts \"NO\"\nend\nt-=1\nend"}, {"source_code": "t=gets.chomp.to_i\nar=[6,10,14]\nrep=15\nsum = 30\nwhile t!=0\n num=gets.chomp.to_i \n ar.each_with_index do |x,i|\n if (num-sum == x)\n ar[ar.length-1]=rep\n sum+=1\n break\n end\n \n end\nif(num-sum >= 1)\n puts \"YES\"\n ar.each { |x| print \"#{x} \"}\n print \"#{num-sum}\"\n puts\n else\n puts \"NO\"\nend\nt-=1\nend"}, {"source_code": "t= gets.chomp.to_i\nar=[6,10,14]\nsum = 30\nwhile t!=0\n num= gets.chomp.to_i\nif(num-sum >= 1)\n puts \"YES\"\n ar.each { |x| print \"#{x} \"}\n print \"#{num-sum}\"\n puts\n else\n puts \"NO\"\nend\nt-=1\nend"}, {"source_code": "n = gets.chomp.to_i\nn.times do |i|\n s = gets.chomp.to_i\n if s >= 31\n puts \"YES\"\n print \"6\"\n print \" \"\n print \"10\"\n print \" \"\n print \"14\"\n print \" \"\n print s - 30\n print \"\\n\"\n else\n puts \"NO\"\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\nn.times do \n s = gets.chomp.to_i\n if n >= 31\n puts \"YES\"\n print \"6\"\n print \" \"\n print \"10\"\n print \" \"\n print \"14\"\n print s - 30\n else\n puts \"NO\"\n end\nend"}, {"source_code": "$, = ' '\ngets.to_i.times do\n n = gets.to_i\n if n <= 30\n puts \"NO\"\n else\n puts \"YES\"\n if n == 36 || n == 40 || n == 44\n print 6, 10, 15, n - 31\n else\n print 6, 10, 14, n - 30\n end\n end\nend"}, {"source_code": "n = gets.to_i\nans = []\nn.times do\n x = gets.to_i\n if x <= 30\n ans << [-1,-1,-1,-1]\n else\n ans << [6,10,14,x-30]\n end\nend\nans.each do |x|\n if x[0] == -1\n puts \"NO\"\n else\n puts \"YES\"\n puts \"#{x[0]} #{x[1]} #{x[2]} #{x[3]}\"\n end\nend"}], "src_uid": "8a6c3436f73286ca54f51fb90017a299"} {"source_code": "n = gets.strip.to_i\narr = []\nn.times do\n arr << gets.strip.to_i\nend\narr.sort!\nsum = 0\nfor i in 0..((n-1)/2) do\n if i != n-1-i\n sum += arr[i] * arr[n-1-i] * 2\n else\n sum += arr[i] * arr[i]\n end\nend\nputs (sum % 10007)", "positive_code": [{"source_code": "n = gets.strip.to_i\ntasks = Array.new(n, 0)\nlaziness = Array.new(n, 0)\nn.times do |i|\n a = gets.strip.to_i\n tasks[i] = laziness[i] = a\nend\ntasks.sort!.reverse!\nlaziness.sort!\nans = 0\nn.times do |i|\n ans += tasks[i] * laziness[i]\nend\nans %= 10007\nputs ans\n"}, {"source_code": "n,*a=$<.map &:to_i;a.sort!;r=0;n.times{|i|r=(r+a[i]*a[-i-1])%10007};p r"}], "negative_code": [{"source_code": "n,*a=$<.map &:to_i;r=0;n.times{|i|r=(r+a[i]*a[-i-1])%10007};p r"}, {"source_code": "n = gets.strip.to_i\ntasks = Array.new(n, 0)\nlaziness = Array.new(n, 0)\nn.times do |i|\n a = gets.strip.to_i\n tasks[i] = laziness[i] = a\nend\ntasks.sort!.reverse!\nlaziness.sort!\nans = 0\nn.times do |i|\n ans += tasks[i] * laziness[i]\nend\nputs ans\n"}, {"source_code": "n = gets.strip.to_i\narr = []\nn.times do\n arr << gets.strip.to_i\nend\narr.sort!\nsum = 0\nfor i in 0..((n-1)/2) do\n if i != n-1-i\n sum += arr[i] * arr[n-1-i] * 2\n else\n sum += arr[i] * arr[i]\n end\nend\nputs sum"}], "src_uid": "f5acd95067656fa7667210af2c9bec81"} {"source_code": "def main\n n = gets.chomp.to_i\n i = n * n\n ints = []\n i.times do\n h, v = gets.chomp.split.map {|r| r.to_i}\n ints << [h, v]\n end\n\n hhash = {}\n vhash = {}\n\n days = []\n ints.each_with_index do |a, i|\n h, v = a\n if not hhash[h] and not vhash[v]\n hhash[h] = :done\n vhash[v] = :done\n days << i+1\n end\n end\n\n days.each do |d|\n print \"#{d} \"\n end\n\n puts \"\"\n\nend\n\nmain\n", "positive_code": [{"source_code": "n = gets.to_i\nx = Array.new(n, false)\ny = Array.new(n, false)\nans = []\n(n * n).times do |a|\n i, j = gets.split.map(&:to_i)\n next if x[i] || y[j]\n x[i] = true\n y[j] = true\n ans << a + 1\nend\nputs ans.join(' ')\n"}, {"source_code": "\nans = [ ]\n\nn = gets.strip.to_i\nh_road = Array.new(n, false)\nv_road = Array.new(n, false)\n\n(n * n).times do |i|\n h, v = gets.strip.split(' ').map(&:to_i)\n h -= 1\n v -= 1\n\n if !h_road[h] and !v_road[v]\n ans.push(i + 1)\n h_road[h] = true\n v_road[v] = true\n end\nend\n\nputs ans.sort.join(' ')"}, {"source_code": "a=gets.chomp.to_i\nh=[]\nv=[]\ntemp=gets.chomp.split(\" \")\nh[0]=temp[0]\nv[0]=temp[1]\nprintf \"1 \"\nif a>1\n2.upto(a*a) do |i| \ntemp=gets.chomp.split(\" \")\nif h.count(\"#{temp[0]}\")==0 && v.count(\"#{temp[1]}\")==0\nh << temp[0]\nv << temp[1]\nprintf \"#{i} \"\nend\nend\nend"}, {"source_code": "#$stdin = File.open('in.txt')\n#$stdout = File.open('out.txt', 'w')\n\nn = gets.to_i\n\nur = []\nuc = []\n\n(1..(n*n)).each { |i|\n r, c = gets.split.map(&:to_i)\n if ur[r] == nil && uc[c] == nil \n ur[r] = 1\n uc[c] = 1\n p i\n end\n}"}, {"source_code": "n = gets.chomp.to_i\nrow = Array.new(n, false)\ncol = Array.new(n, false)\n\nall = n * n\nans = []\nall.times do |day|\n r, c = gets.chomp.split(' ').map(&:to_i)\n next if row[r - 1] || col[c - 1]\n row[r - 1] = true\n col[c - 1] = true\n ans << day + 1\nend\n\nputs ans.join(' ')\n\n"}, {"source_code": "n=gets.to_i\na = []\nb = []\n\nout= []\n(n*n).times do |i|\n\tx,y = gets.split(\" \").map(&:to_i)\n\tif (!a[x] && !b[y])\n\t\tout << i+1\n\t\ta[x] = true\n\t\tb[y] = true\n\tend\nend\n\nputs out.join(\" \")\n"}, {"source_code": "h,v, days = [], [], []\nn = gets.chomp.to_i\n(n**2).times do |t|\n\thi, vi = gets.chomp.split(\" \").map(&:to_i)\n\tif !h.include?(hi) and !v.include?(vi)\n\t\th << hi\n\t\tv << vi\n\t\tdays << (t+1)\n\tend\nend\nputs days.join \" \""}, {"source_code": "n = STDIN.gets.strip.to_i\nhs = Array.new(n+1, false)\nvs = Array.new(n+1, false)\ndays = []\n(n*n).times do |d|\n h, v = STDIN.gets.strip.split(\" \").map{|i| i.to_i}\n next if hs[h] || vs[v]\n hs[h] = vs[v] = true\n days << d + 1\nend\n\nputs days.sort.join(\" \")\n"}, {"source_code": "n = gets.to_i\na = Array.new(n){false}\nb = Array.new(n){false}\n(n*n).times{ |i|\n x, y = gets.split(\" \").map(&:to_i)\n if !a[x] && !b[y]\n print (i+1).to_s + \" \"\n a[x] = true\n b[y] = true\n end\n}"}, {"source_code": "a=gets.chomp.to_i\nh=[]\nv=[]\ntemp=gets.chomp.split(\" \")\nh[0]=temp[0]\nv[0]=temp[1]\nprintf \"1 \"\nif a>1\n2.upto(a*a) do |i| \ntemp=gets.chomp.split(\" \")\nif h.count(\"#{temp[0]}\")==0 && v.count(\"#{temp[1]}\")==0\nh << temp[0]\nv << temp[1]\nprintf \"#{i} \"\nend\nend\nend\n"}, {"source_code": "a=gets.chomp.to_i\nh=[]\nv=[]\ntemp=gets.chomp.split(\" \")\nh[0]=temp[0]\nv[0]=temp[1]\nprintf \"1 \"\nif a>1\n2.upto(a*a) do |i| \ntemp=gets.chomp.split(\" \")\nif h.count(\"#{temp[0]}\")==0 && v.count(\"#{temp[1]}\")==0\nh << temp[0]\nv << temp[1]\nprintf \"#{i} \"\nend\nend\nend"}, {"source_code": "h=(0..50).map{0}\nw=(0..50).map{0}\nn=gets.to_i\nn=n*n\nans=[]\nn.times{|i|\n\th1,w1=gets.split.map{|e| e.to_i}\n\tif h[h1]==0 && w[w1]==0 then\n\t\tans<<(i+1)\n\t\th[h1]=1\n\t\tw[w1]=1\n\tend\n}\nputs ans*\" \"\n\n"}, {"source_code": "n = gets.chomp.to_i\narr = []\nfor i in (0..(n**2)-1)\n\tarr[i] = gets.chomp.split.map(&:to_i)\nend\n\nh = []\nv = []\nh[0] = arr[0][0]\nv[0] = arr[0][1]\n\nprint 1\nprint \" \"\nfor i in (1..(n**2)-1)\n\tif h.include?(arr[i][0]) == false && v.include?(arr[i][1]) == false\n\t\tprint i+1 \n\t\tprint \" \"\n\t\th << arr[i][0]\n\t\tv << arr[i][1]\n\tend\nend"}, {"source_code": "n = gets.to_i\nx = []\ny = []\nans = []\n(n * n).times do |a|\n i, j = gets.split.map(&:to_i)\n next if x[i] || y[j]\n x[i] = true\n y[j] = true\n ans << a + 1\nend\nputs ans.join(' ')\n"}], "negative_code": [{"source_code": "a=gets.chomp.to_i\nh=[]\nv=[]\ntemp=gets.chomp.split(\" \")\nh[0]=temp[0]\nv[0]=temp[0]\nprintf \"1 \"\nif a>1\n2.upto(a*a) do |i| \ntemp=gets.chomp.split(\" \")\nif h.count(\"#{temp[0]}\")==0 && v.count(\"#{temp[1]}\")==0\nh << temp[0]\nv << temp[1]\nprintf \"#{i} \"\nend\nend\n\n\nend\n"}, {"source_code": "a=gets.chomp.to_i\nh=[]\nv=[]\ntemp=gets.chomp.split(\" \")\nh[0]=temp[0]\nv[0]=temp[1]\nprintf \"1 \"\nif a>1\n2.upto(a*a) do |i| \nputs \"#{i}\"\n\ntemp=gets.chomp.split(\" \")\nif h.count(\"#{temp[0]}\")==0 && v.count(\"#{temp[1]}\")==0\nh << temp[0]\nv << temp[1]\nprintf \"#{i} \"\nend\nend\n\n\nend\n"}, {"source_code": "n = gets.chomp.to_i\narr = []\nfor i in (0..(n**2)-1)\n\tarr[i] = gets.chomp.split.map(&:to_i)\nend\n\nh = []\nv = []\nh[0] = arr[0][0]\nv[0] = arr[0][1]\n\nprint 1\nprint \" \"\nfor i in (1..(n**2)-1)\n\tif h.include?(arr[i][0]) == false && v.include?(arr[i][1]) == false\n\t\tprint i+1 \n\t\th << arr[i][0]\n\t\tv << arr[i][1]\n\tend\nend"}], "src_uid": "c611808e636d9307e6df9ee0e706310b"} {"source_code": "n = gets.to_i\nk = 0\nn.times { |i|\n sd = gets.split().map{|a| a.to_i}\n if i == 0\n k = sd[0]\n else\n if sd[0] > k\n k = sd[0]\n else\n k = sd[0] + ((k-sd[0])/sd[1]+1)*sd[1]\n end\n end\n}\nputs k\n", "positive_code": [{"source_code": "def nxt(t, s, d)\n tmp = [t - s, 0].max\n tmp = (tmp + d - 1) / d\n return s + tmp * d\nend\n\nn, t = gets.to_i, 0\nfor i in (1..n) do\n t = t + 1\n s, d = gets.split\n t = nxt(t, s.to_i, d.to_i)\nend\nprint t\n"}, {"source_code": "n = gets.to_i\nans = 0\nn.times do |i|\n x, y = gets.split.map(&:to_i)\n tmp = ans - x\n if tmp < 0\n ans = x\n elsif tmp % y == 0\n ans = (tmp / y + 1) * y + x\n else\n ans = (tmp + y - 1) / y * y + x\n end\nend\nputs ans"}, {"source_code": "def antimod(x, m)\n return (m - x % m) % m\nend\nn = gets.to_i\nk = 0\nn.times { |i|\n sd = gets.split().map{|a| a.to_i}\n if i == 0\n k = sd[0]\n else\n if sd[0] > k\n k = sd[0]\n else\n k = sd[0] + ((k-sd[0])/sd[1]+1)*sd[1]\n end\n end\n}\nputs k\n"}], "negative_code": [{"source_code": "n = gets.to_i\nans = 0\nn.times do |i|\n x, y = gets.split.map(&:to_i)\n tmp = [ans - x, 0].max\n if i == 0\n ans = x \n elsif tmp % y == 0\n ans = (tmp / y + 1) * y + x\n else\n ans = (tmp + y - 1) / y * y + x\n end\nend\nputs ans"}], "src_uid": "d324617c86423d86cdcb839894e00e1a"} {"source_code": "gets.chomp.to_i.times do |_i|\n a, b, c, d = gets.split.map(&:to_i)\n p [a + b, c + d].max\nend", "positive_code": [{"source_code": "gets.to_i.times do\n a, b, c, d = gets.split.map &:to_i\n puts [a + b, c + d].max\nend"}], "negative_code": [], "src_uid": "a60321dd9ada279c007415f28775099b"} {"source_code": "n = gets.to_i\nlr = (1..n).map{gets.split.map(&:to_i)}\ndiff = lr.map!{|x| x[0]-x[1]}\nno_change = diff.reduce(&:+)\nans = [no_change.abs] + diff.map{|x| (no_change-2*x).abs}\nputs ans.index(ans.max)\n", "positive_code": [{"source_code": "n = gets.to_i\nl = []\nr = []\nsomme = 0\n\nfor i in 1..n\n c = gets.split(' ')\n l[i] = c[0].to_i\n r[i] = c[1].to_i\n somme += ( l[i] - r[i] )\nend\n\nmax = -1\n\npos = 0\n\nfor i in 1..n\n if max < ( somme - 2 * (l[i]-r[i]) ).abs and somme.abs < ( somme - 2 * (l[i]-r[i]) ).abs\n max = ( somme - 2 * (l[i]-r[i]) ).abs\n pos = i\n end\nend\n\nputs pos\n"}, {"source_code": "def tuyet_doi abc\n abc > 0 ? abc : -abc\nend\n\ndef beauty a_left, a_right\n a_left.inject(0){ |product,x| product + x } - a_right.inject(0){ |product,x| product + x }\nend\n\ndef total arr_x\n arr_x.inject(0){ |product,x| product + x }\nend\n\ndef more_beauty? a_left, a_right, n\n now_beauty = tuyet_doi(beauty(a_left, a_right))\n t_left = total(a_left)\n t_right =total(a_right)\n save = -1\n\n (0..n-1).each do |x|\n t_left1 = t_left + a_right[x] - a_left[x]\n t_right1 = t_right - a_right[x] + a_left[x]\n\n if tuyet_doi(t_left1 - t_right1) > now_beauty\n now_beauty = tuyet_doi(t_left1 - t_right1)\n save = x\n end\n end\n\n return save\n # if save == -1\n # return -1\n # else\n # return save\n # end\nend\n\n# input processor\nn = gets.to_i\na_left = Array.new\na_right = Array.new\n(1..n).each do |x|\n a = gets\n jump_list = a.split(\" \")\n a_left << jump_list[0].to_i\n a_right << jump_list[1].to_i\nend\nbeauty1 = more_beauty? a_left, a_right, n\nbeauty2 = more_beauty? a_right, a_left, n\nputs beauty1 > beauty2 ? beauty1 + 1 : beauty2 + 1\n"}, {"source_code": "n = gets.chomp.to_i\nlefts, rights = [], []\nn.times do\n left, right = gets.chomp.split.map(&:to_i)\n lefts << left\n rights << right\nend\nsum_of_lefts, sum_of_rights = lefts.inject(:+), rights.inject(:+)\ndiff = (sum_of_lefts - sum_of_rights).abs\n\narr = []\nlefts.zip(rights).each.with_index.map { |e, idx| [*e, idx] }.each do |left, right, idx|\n c = sum_of_lefts - left + right\n d = sum_of_rights - right + left\n arr << (c - d).abs\nend\n\nans = arr.max\nif diff >= ans\n puts 0\nelse\n puts arr.index(ans) + 1\nend\n"}, {"source_code": "n=gets.chomp.to_i\ni=0\nls=0\nrs=0\nmini=0\nmaxi=0\nmin=500\nmax=-500\nn.times do\n a=gets.chomp.split(\" \")\n l=a[0].to_i\n r=a[1].to_i\n ls=ls+l\n rs=rs+r\n d=l-r\n if(d>max)\n max=d\n maxi=i+1\n end\n if(d beauty\n beauty = tbeauty\n ans = i + 1\n end\nend\nputs ans \n# if lsum > rsum\n# ary.each_with_index do |x, i|\n# if x[1] > x[0] && (x[1]-x[0]) > tmp\n# tmp = (x[1]-x[0])\n# ans = i+1\n# end\n# end\n# elsif lsum == rsum\n# ary.each_with_index do |x, i|\n# if x[0] != x[1] && (x[0]-x[1]).abs > tmp\n# tmp = (x[0]-x[1]).abs\n# ans = i+1\n# end\n# end\n# else\n# ary.each_with_index do |x, i|\n# if x[0] > x[1] && (x[0]-x[1]) > tmp\n# tmp = (x[0]-x[1])\n# ans = i+1\n# end\n# end\n# end"}, {"source_code": "n=gets.to_i\ns1=0\nmax1=[-(10**10),0]\nmin1=[10**10,0]\n\nn.times{|i|\n\ta,b=gets.split.map{|e| e.to_i}\n\td=2*b-2*a\n\ts1+=a-b\n\tif max1[0]d then\n\t\tmin1[0]=d\n\t\tmin1[1]=i+1\n\tend\n}\n\ns2=(s1+min1[0]).abs\ns3=(s1+max1[0]).abs\ns1=s1.abs\n\nif s1>=([s2,s3].max) then\n\tputs 0\nelsif s2>=([s1,s3].max) then\n\tputs min1[1]\nelsif s3>=([s1,s2].max) then\n\tputs max1[1]\nelse\n\tputs 0\nend\n\n"}, {"source_code": "n = gets.chomp.to_i\nls = []\nrs = []\nlt = 0\nrt = 0\nans = 0\nn.times do\n l, r = gets.chomp.split.map(&:to_i)\n ls << l\n rs << r\n lt += l\n rt += r\nend\n\ncur = (lt - rt).abs\nfor i in 0...n\n tmp = ((lt - ls[i] + rs[i]) - (rt - rs[i] + ls[i])).abs\n if cur < tmp\n ans = i + 1\n cur = tmp\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nac = a.map{|x, y| x - y}\nif ac.all?{|x| x < 0} || ac.all?{|x| x > 0}\n p 0\nelse\n cur = ac.inject(:+)\n mx, ind = 0, 0\n n.times do |i|\n c = (cur - 2 * ac[i]).abs\n if c > mx\n ind = i\n mx = c\n end\n end\n p ind + 1\nend\n"}, {"source_code": "l=[]\nr=[]\nn=gets.to_i\nleft=0\nright=0\nfor i in 1..n\n\ta,b=gets.split(\" \").map(&:to_i)\n\tleft+=a\n\tright+=b\n\tl<beauty\n\t\tbeauty=tmp\n\t\tans=i+1\n\tend\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\nmaxldiff = 0\nmaxlpos = 0\nmaxrdiff = 10**9\nmaxrpos = 0\nsuml = 0\nsumr = 0\n1.upto(n) do |i|\n l, r = gets.strip.split(' ').map(&:to_i)\n\n suml += l\n sumr += r\n diff = l - r\n\n if diff > maxldiff\n maxlpos = i\n maxldiff = diff\n end\n\n if maxrdiff > diff\n maxrpos = i\n maxrdiff = diff\n end\nend\n\nmaxrdiff = -maxrdiff\nif suml == sumr\n if maxldiff >= maxrdiff\n printf(\"%d\\n\", maxlpos)\n else\n printf(\"%d\\n\", maxrpos)\n end\nelse\n s1 = suml + maxrdiff\n s2 = sumr - maxrdiff\n\n s3 = suml - maxldiff\n s4 = sumr + maxldiff\n\n if (s1 - s2).abs > (s3 - s4).abs\n printf(\"%d\\n\", maxrpos)\n else\n printf(\"%d\\n\", maxlpos) \n end\nend\n"}], "negative_code": [{"source_code": "def tuyet_doi abc\n abc > 0 ? abc : -abc\nend\n\ndef beauty a_left, a_right\n a_left.inject(0){ |product,x| product + x } - a_right.inject(0){ |product,x| product + x }\nend\n\ndef total arr_x\n arr_x.inject(0){ |product,x| product + x }\nend\n\ndef more_beauty? a_left, a_right, n\n now_beauty = tuyet_doi(beauty(a_left, a_right))\n t_left = total(a_left)\n t_right =total(a_right)\n save = -1\n\n (0..n-1).each do |x|\n t_left1 = t_left + a_right[x] - a_left[x]\n t_right1 = t_right - a_right[x] + a_left[x]\n tuyet_doi(t_left1 - t_right1) > now_beauty\n now_beauty = tuyet_doi(t_left1 - t_right1)\n save = x\n end\n if save == -1\n return 0\n else\n return save\n end\nend\n\n# input processor\nn = gets.to_i\na_left = Array.new\na_right = Array.new\n(1..n).each do |x|\n a = gets\n jump_list = a.split(\" \")\n a_left << jump_list[0].to_i\n a_right << jump_list[1].to_i\nend\nbeauty1 = more_beauty? a_left, a_right, n\nbeauty2 = more_beauty? a_right, a_left, n\nbeauty1 > beauty2 ? beauty1 : beauty2\n"}, {"source_code": "n=gets.to_i\ns1=0\nmax1=[-(10**10),0]\nmin1=[10**10,0]\n\nn.times{|i|\n\ta,b=gets.split.map{|e| e.to_i}\n\td=2*b-2*a\n\ts1+=a-b\n\tif max1[0]d then\n\t\tmin1[0]=d\n\t\tmin1[1]=i+1\n\tend\n}\n\ns2=(s1+min1[0]).abs\ns3=(s1+max1[0]).abs\ns1=s1.abs\nif s1>[s2,s3].max then\n\tputs 0\nelsif s2>[s1,s3].max then\n\tputs min1[1]\nelse\n\tputs max1[1]\nend\n\n\n"}, {"source_code": "n=gets.to_i\ns1=0\nmax1=[-(10**10),0]\nmin1=[10**10,0]\n\nn.times{|i|\n\ta,b=gets.split.map{|e| e.to_i}\n\td=2*b-2*a\n\ts1+=a-b\n\tif max1[0]d then\n\t\tmin1[0]=d\n\t\tmin1[1]=i+1\n\tend\n}\n\ns2=(s1+min1[0]).abs\ns3=(s1+max1[0]).abs\ns1=s1.abs\n\nif s1>([s2,s3].max) then\n\tputs 0\nelsif s2>([s1,s3].max) then\n\tputs min1[1]\nelsif s3>([s1,s2].max) then\n\tputs max1[1]\nelse\n\tputs 0\nend\n\n"}, {"source_code": "n=gets.to_i\ns1=0\nmax1=[-(10**10),0]\nmin1=[10**10,0]\n\nn.times{|i|\n\ta,b=gets.split.map{|e| e.to_i}\n\td=2*b-2*a\n\ts1+=a-b\n\tif max1[0]d then\n\t\tmin1[0]=d\n\t\tmin1[1]=i+1\n\tend\n}\n\nif s1<0 then\n\tif min1[0]<0\n\t\tputs min1[1]\n\telse\n\t\tputs 0\n\tend\nelsif s1>0 then\n\tif max1[0]>0\n\t\tputs max1[1]\n\telse\n\t\tputs 0\n\tend\nelse\n\ta=min1[0].abs\n\tb=max1[0].abs\n\tif a>b then\n\t\tputs min1[1]\n\telsif a r\n lc += l - r\n d[i] = [l - r, 'l', i]\n elsif r > l\n rc += r - l\n d[i] = [r - l, 'r', i]\n else\n d[i] = [0, 'e', i]\n end\nend\nif lc == 0 || rc == 0\n puts 0\nelse\n lmx, rmx = nil, nil\n d.each do |x, y, z|\n if y == 'l' && (lmx.nil? || x > lmx[0])\n lmx = [x, y, z]\n elsif y == 'r' && (rmx.nil? || x > rmx[0])\n rmx = [x, y, z]\n end\n end\n if lc < rc || lmx[0] > rc\n puts lmx[2] + 1\n elsif lc > rc || rmx[0] > lc\n puts rmx[2] + 1\n else\n puts d.sort.last[2] + 1\n end\nend\n"}, {"source_code": "n = gets.to_i\nlr = (1..n).map{gets.split.map(&:to_i)}\ndiff = lr.map!{|x| x[0]-x[1]}\nno_change = diff.reduce(&:+)\nans = [no_change.abs, diff.map{|x| (no_change-2*x).abs}.min].min\nputs ans.inspect\n"}], "src_uid": "2be73aa00a13be5274cf840ecd3befcb"} {"source_code": "def read\r\n gets.chomp\r\nend\r\ngets.to_i.times do\r\n s, t = read, read\r\n n, m = s.size, t.size\r\n l = (n * m) / n.gcd(m)\r\n puts s * (l / n) == t * (l / m) ? s * (l / n) : -1\r\nend", "positive_code": [{"source_code": "def slcm(s, lcmi)\r\n return s * (lcmi.to_i / s.length) \r\nend\r\n\r\nt = gets.chomp.to_i\r\n\r\nwhile t > 0\r\n s = gets.chomp\r\n v = gets.chomp\r\n lcmi = s.length.lcm(v.length)\r\n lcmv = slcm v , lcmi\r\n lcms = slcm s , lcmi\r\n if lcms == lcmv\r\n puts v * (s.length.lcm(v.length) / v.length)\r\n else\r\n puts \"-1\"\r\n end\r\n t-=1\r\nend"}, {"source_code": "t = gets.chomp.to_i\r\nwhile t > 0\r\n s = gets.chomp\r\n v = gets.chomp\r\n lcmv = v * (s.length.lcm(v.length) / v.length)\r\n lcms = s * (s.length.lcm(v.length) / s.length)\r\n if lcms == lcmv\r\n puts v * (s.length.lcm(v.length) / v.length)\r\n else\r\n puts \"-1\"\r\n end\r\n t-=1\r\nend"}, {"source_code": "gets.to_i.times do\r\n s, t = gets.chomp, gets.chomp\r\n n, m = s.size, t.size\r\n sz = n * m / n.gcd(m)\r\n puts s * (sz / n) == t * (sz / m) ? s * (sz / n) : -1\r\nend"}, {"source_code": "a = gets.chomp.to_i\n\na.times do\n s1 = gets.chomp\n s2 = gets.chomp\n\n aux = \"\"\n s1.size.times do\n aux += s2\n end\n aux2 = \"\"\n s2.size.times do\n aux2 += s1\n end\n if aux != aux2\n puts -1\n next\n end\n\n lc = s1.size.lcm(s2.size)\n ss = [s1.size, s2.size].min\n\n num = lc/ss\n\n if ss == s2.size\n s1 = s2 \n end\n aux = \"\"\n num.times do\n aux += s1 \n end\n puts aux\nend\n\n\t\t\t \t \t\t \t \t \t \t \t \t\t \t\t\t\t"}, {"source_code": "gets.to_i.times do\r\n s=gets.chomp\r\n t=gets.chomp\r\n sz=s.size\r\n tz=t.size\r\n if s*tz==t*sz\r\n z=sz.lcm(tz)\r\n puts s*(z/sz)\r\n else\r\n puts \"-1\"\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "710c7211d23cf8c01fae0b476a889276"} {"source_code": "gets.to_i.times do\n r=gets.strip.split(' ').map(&:to_i)\n x=r[2]-1\n s=gets.strip.gsub(\"a\",\"ba\").gsub(\"*b\",\"*ab\").split('a').map{|i|(i=='b'? 0:i.size*r[1]+1)}.reverse.map{|i|v='a';x/=((i!=0?(v='b'*(x%i)):false)?i :1);v}.reverse*''\n puts s\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n r = gets.strip.split(' ').map(&:to_i)\n x = r[2] - 1\n s = gets.strip.gsub(\"a\", \"ba\").gsub(\"*b\", \"*ab\").split('a').map do |i|\n (i == 'b' ? 0 : i.size * r[1] + 1)\n end.reverse.map do |i|\n if i != 0\n ret = 'b' * (x % i)\n x /= i\n ret\n else\n ret = \"a\"\n end\n end.reverse * ''\n puts s\nend\n"}, {"source_code": "gets.to_i.times do\n r = gets.strip.split(' ').map(&:to_i)\n k = r[1]\n x = r[2] - 1\n s = gets.strip.gsub(\"a\", \"ba\").gsub(\"*b\", \"*ab\")\n s = s.split('a')\n s = s.map do |i|\n v = 0\n if (i != 'b')\n v = i.size\n end\n (i == 'b' ? 0 : v * k + 1)\n end.reverse.map do |i|\n ret = \"\"\n ret = \"a\" if i == 0\n if i != 0\n ret = ret + 'b' * (x % i)\n x /= i\n end\n ret\n end.reverse * ''\n puts s\n\nend\n"}], "negative_code": [{"source_code": "gets.to_i.times do\n a,k,x=gets.strip.split(' ').map(&:to_i);x-=1\n puts gets.strip.split('').chunk{|x|x=='a'}.map{|a,b|a ?[0]*b.size: b.size*k}.flatten.reverse.map{|i|v=(i!=0?'b'*(x%(i+1)) :'a');x/=i+1;v}.reverse*''\nend\n"}, {"source_code": "gets.to_i.times do\n a,k,x=gets.strip.split(' ').map(&:to_i);x-=1\n puts gets.strip.split('').chunk{|x|x=='a'}.map{|a,b|a ?0: b.size*k}.reverse.map{|i|v=(i!=0?'b'*(x%(i+1)) :'a');x/=i+1;v}.reverse*''\nend\n"}, {"source_code": "gets.to_i.times do\n r = gets.strip.split(' ').map(&:to_i)\n n = r[0]\n k = r[1]\n x = r[2] - 1\n s = gets.strip.gsub(\"a\", \"ba\").gsub(\"*b\", \"*ab\")\n s = s.split('a')\n s = s.map do |i|\n v = 0\n if (i != 'b')\n v = i.size\n end\n v * k + 1\n end.reverse.map do |i|\n ret = \"\"\n ret = \"a\" if i == 1\n (x % i).times{ret += 'b'}\n x /= i\n ret\n end.reverse * ''\n puts s\n\nend\n"}, {"source_code": "gets.to_i.times do\n r = gets.strip.split(' ').map(&:to_i)\n n = r[0]\n k = r[1]\n x = r[2]\n s = gets.strip.gsub(\"a\", \"ba\").gsub(\"*b\", \"*ab\")\n s = s.split('a')\n s = s.map do |i|\n v = 0\n if (i != 'b')\n v = i.size\n end\n v * k + 1\n end\n v = 1\n x -= 1\n i = s.size() - 1\n flag = true\n vec = []\n s.each do |ele|\n vec.push(\"-\")\n end\n while flag do\n if s[i] == 1\n i -= 1\n flag = i > -1 && v < x\n else\n vec[i] = [v, v * s[i]]\n v *= s[i]\n i = i - 1\n flag = i > -1 && v < x\n end\n end\n result = \"\"\n (0..(s.size() - 1)).each do |i|\n if vec[i] == \"-\"\n if s[i] == 1\n result += \"a\"\n end\n else\n if x > vec[i][0]\n ctr = x / vec[i][0]\n ctr = [ctr, s[i]].min\n x -= ctr * vec[i][0]\n result += \"b\" * ctr\n end\n end\n end\n puts result\nend\n"}], "src_uid": "32ed4995e557cfdcbef375e2b9edb1a6"} {"source_code": "n,m=gets.split.map(&:to_i)\r\ns=gets.chomp.chars\r\nt=gets.chomp.chars\r\nl=[]\r\ni=0\r\nj=0\r\nwhile j=0\r\n if s[i]==t[j]\r\n r << i\r\n j-=1\r\n end\r\n i-=1\r\nend\r\nr.reverse!\r\na=0\r\n(m-1).times do |i|\r\n a=r[i+1]-l[i] if r[i+1]-l[i]>a\r\nend\r\nputs a\r\n", "positive_code": [{"source_code": "n,m = gets.chomp.split(\" \").map(&:to_i)\r\ns = gets.chomp.chars\r\nt = gets.chomp.chars\r\ni = 0\r\narr = Array.new(m,-1)\r\nm.times do |j|\r\n while s[i] != t[j]\r\n i += 1\r\n end\r\n arr[j] = i\r\n i += 1\r\nend\r\nmax = 0\r\n(m-1).times do |i|\r\n max = [max,arr[i+1]-arr[i]].max\r\nend\r\ni = n-1\r\n(m-1).downto(1) do |j|\r\n while s[i] != t[j]\r\n i -= 1\r\n end\r\n arr[j] = i\r\n i -= 1\r\n max = [max, arr[j] - arr[j-1]].max\r\nend\r\nputs max"}], "negative_code": [{"source_code": "n,m = gets.chomp.split(\" \").map(&:to_i)\r\ns = gets.chomp.chars\r\nt = gets.chomp.chars\r\ni = 0\r\narr = Array.new(m,-1)\r\nm.times do |j|\r\n while s[i] != t[j]\r\n i += 1\r\n end\r\n arr[j] = i\r\n i += 1\r\nend\r\nmax = 0\r\n(m-1).times do |i|\r\n max = [max,arr[i+1]-arr[i]].max\r\nend\r\ni = n-1\r\n(m-1).downto(1) do |j|\r\n while s[i] != t[j]\r\n i -= 1\r\n end\r\n break if arr[j] == i\r\n arr[j] = i\r\n i -= 1\r\n max = [max, arr[j] - arr[j-1]].max\r\nend\r\nputs max"}], "src_uid": "17fff01f943ad467ceca5dce5b962169"} {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nnodd = (a.keep_if &:odd?).size\nneven = n - nodd\nans = [nodd, neven].min\nnodd -= ans\nans += (nodd / 3).floor\np ans\n", "positive_code": [{"source_code": "r=->{gets.split.map &:to_i}\nn=r[]\na=r[]\nodd = a.count{|_|_%2 == 1}\neven = n[0] - odd\ntk = 0\nif odd > even then\n tk = even\nelse\n tk = odd\nend\nans = tk\nodd -= tk\neven -= tk\np ans + (odd / 3)"}, {"source_code": "r=->{gets.split.map &:to_i}\nn=r[]\na=r[]\nb=a.count{|_|_%2==1}\nm=n.first\nif b >= m-b\n p m-b+(b-m+b)/3\nelse\n p b\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nodd = a.count{|_|_%2 == 1}\neven = n - odd\nans = [odd,even].min\nodd -= ans\nans += (odd / 3).floor\n\nprint ans"}, {"source_code": "# require 'set'\n\nn = gets.split.map(&:to_i)[0]\na = gets.split.map(&:to_i)\n\neven = a.select {|item|item % 2 == 0}\nn_e = even.length\nn_o = n - n_e\nif n_e >= n_o then\n\tprint n_o\nelse\n\tx = (n_o - n_e) / 3\n\tprint n_e + x\nend\n# print even.length\n\n# if (a.take(l - 1) == b.take(l - 1) && a.drop(r) == b.drop(r) && a1 == b1) then\n# \tputs \"TRUTH\"\n# else\n# \tputs \"LIE\"\n# end"}, {"source_code": "n = gets.to_i\ns = (gets.split)\ns1=0\ns2=0\nfor i in s\n a=i.to_i\n if a%2==0\n s2+=1\n else\n s1+=1\n end\nend\nif s1<=s2\n print s1\nelse\n print s2+(s1-s2)/3\nend"}, {"source_code": "N = gets.to_i\nArr = gets.chomp.split(' ').map(&:to_i)\neven = 0\nodd = 0\nfor i in Arr\n if (i%2==0)\n even = even + 1\n else\n odd = odd + 1\n end\nend\n\nans = 0\nif(even>odd)\n ans = odd\nelse\n ans = even\nend\n\nodd = odd - ans;\n\nans = ans + (odd/3)\n\np ans"}, {"source_code": "r = ->{gets.split.map &:to_i}\nn = r[]\na = r[]\ncnt = 0\nfor x in a\n if x % 2 == 1\n cnt += 1\n end\nend\nif cnt < n[0] - cnt\n ans = cnt\nelse\n odd = cnt\n even = n[0] - cnt\n ans = even + ((odd - even) / 3)\nend\np ans\n\n"}, {"source_code": "n = gets.chomp\na = gets.chomp.split(' ')\n\nodd = 0\neven = 0\n\nfor u in a\n if u.to_i % 2 == 1\n odd += 1\n else\n even += 1\n end\nend\n\nif odd == 0\n puts 0\nelsif even == 0\n puts odd / 3\nelse\n if odd > even\n puts even + (odd - even) / 3\n else\n puts odd\n end\nend\n"}, {"source_code": "a = gets.split\n\nzoj = 0\nfard = 0\n\nn = a[0].to_i\nb = gets.split\n\nfor i in (0..n - 1) do\n\tx = b[i].to_i\n\tif (x % 2 == 0)\n\t zoj = zoj + 1\n\telse\n\t fard = fard + 1\n\tend\nend\nmn = zoj\nif (fard < zoj)\n mn = fard\nend\nfard = fard - mn\nezaf = fard / 3\nmn = mn + ezaf\nputs \"#{mn}\"\n"}, {"source_code": "b = gets.split.map{|_|_.to_i}\na = gets.split.map{|_|_.to_i}\n\neven = 0\nodd = 0\nans = 0\n\nfor x in a\n\tif x % 2 == 0 \n\t\teven = even + 1\n\telse \n\t\todd = odd + 1\n\tend\nend\n\nans = ans + [odd, even].min\nodd = odd - [odd, even].min\nans = ans + odd / 3\n\nprint(ans)"}, {"source_code": "n = gets.to_i\nints = Array.new(n)\nints = gets.split.map{|x| x.to_i }\ne=0\no=0\nfor x in ints\n if x%2 == 0\n e+=1\n else\n o+=1\n end\nend\n\nadd = 0\n\nif o>e\n add = (o-e) / 3\nend\nputs ([o,e].min + add)\n"}, {"source_code": "n = 0\nn = gets\n\na = gets.chomp.split().map { |e| e.to_i }\n\neven = 0\nodd = 0\n\ndef min(a,b)\n if a < b \n a\n else\n b\n end\nend\n \nfor i in 0...a.length\n if a[i] % 2 == 0\n even += 1\n else\n odd += 1\n end\nend\n\nans = min(even,odd)\neven -= ans\nodd -= ans\n\nans += odd / 3\n\nputs \"#{ans}\""}, {"source_code": "n = gets.to_i\na = Array.new(n)\na = gets.split(\" \").collect{|x| x.to_i}\nnumo=0\nnuma=0\nfor i in 0...n\n if (a[i]%2==0)\n numo+=1\n end\nend\nnuma=n-numo\nif (numo>numa)\n ans=numa\nelse\n ans=numo\nend\nnuma-=ans\nif (numa>0)\n ans+=numa/3\nend\nprint ans"}, {"source_code": "n = gets.chomp()\nnums = gets.scan(/\\d+/).map(&:to_i)\nodds = []\nevens = []\ncnt = 0\nnums.each do |x|\n if x % 2 == 0\n evens << x\n else\n odds << x\n end\nend\ncnt += [odds.length, evens.length].min\nel = odds.length - cnt\ncnt += (el / 3) if el >= 3\n# odds.each_with_index do |x, index|\n# unless evens[index].nil?\n# cnt += 1\n# else\n# break\n# end\n# end\nputs cnt"}, {"source_code": "n = gets.to_i\na = gets.split.map{|x| x.to_i }\n\nodd = 0\neven = 0\nfor x in a\n\tif x%2==1\n\t\todd+=1\n\telse\n\t\teven+=1\n\tend\nend\n\nif odd<=even\n\tputs odd\nelse\n\tputs even + (odd-even)/3\nend"}, {"source_code": "gets\nb=0\nc=0\ngets.split.map{|e| \n\te=e.to_i\n\te%2 == 1? b+=1 : c+=1}\n\nif b <= c \n puts b\nelse\n res = c\n b -= c\n res += b / 3\n puts res\nend"}, {"source_code": "r=->{gets.split.map &:to_i}\nn=r[]\na=r[]\nodd = 0\neven = 0\nfor i in a\n if i % 2 == 0\n even = even + 1\n else\n odd = odd + 1\n end\nend\nans = 0\nif odd > even\n ans = even + (odd - even) / 3\nelsif odd < even\n ans = odd\nelse\n ans = even\nend\nputs ans"}, {"source_code": "n=gets.chomp.to_i\ns=gets.chomp.split(' ')\nres=0\nodd=0\neven=0\nfor x in s do\n\todd=odd+(x.to_i % 2)\nend\neven=n-odd\nif (even>=odd) then\n\tres=odd\nelse\n\tres=even+((odd-even)/3)\nend\nputs(res)"}], "negative_code": [{"source_code": "n = gets.to_i\nints = Array.new(n)\nints = gets.split.map{|x| x.to_i }\ne=0\no=0\nfor x in ints\n if x%2 == 0\n e+=1\n else\n o+=1\n end\nend\n\nadd = 0\n\nif o>e\n add = o-e / 3\nend\nputs ([o,e].min + add)\n"}, {"source_code": "n = gets.to_i\nints = Array.new(n)\nints = gets.split.map{|x| x.to_i }\ne=0\no=0\nfor x in ints\n if x%2 == 0\n e+=1\n else\n o+=1\n end\nend\n\nputs ([o,e].min)\n"}, {"source_code": "n = gets.chomp()\nnums = gets.scan(/\\d+/).map(&:to_i)\nodds = []\nevens = []\ncnt = 0\nnums.each do |x|\n if x % 2 == 0\n evens << x\n else\n odds << x\n end\nend\nodds.each_with_index do |x, index|\n unless evens[index].nil?\n cnt += 1\n else\n break\n end\nend\nputs cnt"}, {"source_code": "n = gets.chomp()\nnums = gets.scan(/\\d+/).map(&:to_i)\nodds = []\nevens = []\ncnt = 0\nnums.each do |x|\n if x % 2 == 0\n evens << x\n else\n odds << x\n end\nend\ncnt = [odds.length, evens.length].min\n# odds.each_with_index do |x, index|\n# unless evens[index].nil?\n# cnt += 1\n# else\n# break\n# end\n# end\nputs cnt"}, {"source_code": "gets\nb=0\nc=0\ngets.split.map{|e| \n\te=e.to_i\n\te%2 == 1? b+=1 : c+=1}\np b"}, {"source_code": "n=gets.chomp.to_i\ns=gets.chomp.split(' ')\nres=0\nodd=0\neven=0\nfor x in s do\n\todd=odd+(x.to_i % 2)\nend\neven=n-odd\nif (even>=odd) then\n\tres=odd\nelse\n\tres=even+(odd-even)/2\nend\nputs(res)"}, {"source_code": "n=gets.chomp.to_i\ns=gets.chomp.split(' ')\nres=0\nfor x in s do\n\tres=res+(x.to_i % 2)\nend\nputs(res)"}, {"source_code": "# require 'set'\n\nn = gets.split.map(&:to_i)[0]\na = gets.split.map(&:to_i)\n\neven = a.select {|item|item % 2 == 0}\nn_e = even.length\nn_o = n - n_e\nprint [n_o, n_e].min\n# print even.length\n\n# if (a.take(l - 1) == b.take(l - 1) && a.drop(r) == b.drop(r) && a1 == b1) then\n# \tputs \"TRUTH\"\n# else\n# \tputs \"LIE\"\n# end"}, {"source_code": "n = gets.to_i\ns = (gets.split)\ns1=0\ns2=0\nfor i in s\n a=i.to_i\n if a%2==0\n s2+=1\n else\n s1+=1\n end\nend\nif s1<=s2\n print s1\nelse\n print s2+s1/3\nend"}, {"source_code": "N = gets.to_i\nArr = gets.chomp.split(' ').map(&:to_i)\neven = 0\nodd = 0\nfor i in Arr\n if (i%2==0)\n even = even + 1\n else\n odd = odd + 1\n end\nend\n\nif(N==1)\n p 0\nelsif(odd==0)\n p 0\nelse\n if(odd%2 == 0)\n p 2\n else\n p 1\n end\nend\n "}, {"source_code": "N = gets.to_i\nArr = gets.chomp.split(' ').map(&:to_i)\neven = 0\nodd = 0\nfor i in Arr\n if (i%2==0)\n even = even + 1\n else\n odd = odd + 1\n end\nend\n\nif(odd==0)\n p 0\nelse\n if(odd%2 == 0)\n p 2\n else\n p 1\n end\nend\n "}, {"source_code": "r = ->{gets.split.map &:to_i}\nn = r[]\na = r[]\ncnt = 0\nfor x in a\n if x % 2 == 1\n cnt += 1\n end\nend\nif cnt > n[0] - cnt\n ans = n[0] - cnt\nelse\n ans = cnt\nend\np ans\n\n"}, {"source_code": "n = gets.chomp\na = gets.chomp.split(' ')\n\nodd = 0\neven = 0\n\nfor u in a\n if u.to_i % 2 == 1\n odd += 1\n else\n even += 1\n end\nend\n\nif odd == 0\n puts 0\nelsif even == 0\n puts odd / 3\nelse\n if odd > even\n puts even\n else\n puts odd\n end\nend\n"}, {"source_code": "a = gets.split\n\nzoj = 0\nfard = 0\n\nn = a[0].to_i\nb = gets.split\n\nfor i in (0..n - 1) do\n\tx = b[i].to_i\n\tif (x % 2 == 0)\n\t zoj = zoj + 1\n\telse\n\t fard = fard + 1\n\tend\nend\nif (fard > zoj)\n zoj = fard\nend\nputs \"#{fard}\"\n"}], "src_uid": "61e6fd68d7568c599204130b102ea389"} {"source_code": "k, n, m, q = gets.split.map(&:to_i)\n\nc = Array.new(k){Hash.new{0}}\n\nn.times do\n gets\nend\n\nh = Hash.new\nm.times do\n if gets =~ /^(\\w*):(.*)$/\n h[$1] = $2.split(/,/).map{|_| a, b = _.split; [a, b.to_i]}\n end\nend\n\nq.times do\n a, b = gets.split\n a = c[a.to_i - 1]\n a[b] += 1\n h.each do |k, v|\n next unless v.all?{|x, y| a[x] >= y}\n v.each do |x, y|\n a[x] -= y\n end\n a[k] += 1\n end\nend\n\nc.each do |a|\n a.reject!{|k, v| v == 0}\n p a.size\n a.to_a.sort.each do |k, v|\n puts \"#{k} #{v}\"\n end\nend", "positive_code": [{"source_code": "k, n, m, q = gets.split.map(&:to_i)\n\nc = Array.new(k){Hash.new{0}}\n\nn.times do\n\tgets\nend\n\nh = Hash.new\nm.times do\n\tif gets =~ /^(\\w*):(.*)$/\n\t\th[$1] = $2.split(/,/).map{|_| a, b = _.split; [a, b.to_i]}\n\tend\nend\n\nq.times do\n\ta, b = gets.split\n\ta = c[a.to_i - 1]\n\ta[b] += 1\n\th.each do |k, v|\n\t\tnext unless v.all?{|x, y| a[x] >= y}\n\t\tv.each do |x, y|\n\t\t\ta[x] -= y\n\t\tend\n\t\ta[k] += 1\n\tend\nend\n\nc.each do |a|\n\ta.reject!{|k, v| v == 0}\n\tp a.size\n\ta.to_a.sort.each do |k, v|\n\t\tputs \"#{k} #{v}\"\n\tend\nend\n"}], "negative_code": [], "src_uid": "8b28b07a73b4cc3d8d25b2491736064a"} {"source_code": "s=gets.chomp.to_s\ndef func(s,c,d)\n\ty=s\n\t$~=nil\n\ty=y.sub(/#{c}/,'x')\n\t#puts \"HEY #{$~}\"\n\t#puts y\n\tif $~\n\t\t$~=nil\n\t\ty=y.sub(/#{d}/,'x')\n\t\t#puts \"BYE #{$~}\"\n\t\t#puts y\n\t\tif $~\n\t\t\treturn true\n\t\telse\n\t\t\treturn false\n\t\tend\n\telse\n\t\treturn false\n\tend\nend\n\nif func(s,'AB','BA') || func(s,'BA','AB')\n\tprint(\"YES\\n\")\nelse\n\tputs \"NO\"\nend", "positive_code": [{"source_code": "def solution(string)\n return \"NO\" if string.index(\"AB\").nil? || string.index(\"BA\").nil?\n return \"YES\" if (string.rindex(\"AB\") - string.index(\"BA\")).abs != 1\n return \"YES\" if (string.rindex(\"BA\") - string.index(\"AB\")).abs != 1\n \"NO\"\nend\nputs solution(gets.strip)\n"}, {"source_code": "# http://codeforces.com/contest/550/problem/A\n\ndef get_input\n gets.chomp\nend\n\ndef result(sub1_found_idxs, sub1_length, sub2_found_idxs, sub2_length)\n return false if sub1_found_idxs.empty? || sub2_found_idxs.empty?\n\n case1 = sub1_found_idxs.first < sub2_found_idxs.last &&\n (sub2_found_idxs.last - sub1_found_idxs.first) >= sub1_length\n case2 = sub1_found_idxs.last > sub2_found_idxs.first &&\n (sub1_found_idxs.last - sub2_found_idxs.first) >= sub2_length\n\n case1 || case2\nend\n\n# Checking str contains both sub1 and sub2 without overlapping in general\ndef contain_substrings?(str, sub1, sub2)\n sub1_length = sub1.size\n sub2_length = sub2.size\n start_idx_sub1 = 0\n start_idx_sub2 = 0\n sub1_found_idxs = []\n sub2_found_idxs = []\n\n 0.upto(str.size - 1) do |current_idx|\n # Find all indexes of sub1 in str\n if str[start_idx_sub1..current_idx] == sub1\n sub1_found_idxs << start_idx_sub1\n start_idx_sub1 = current_idx + 1\n elsif current_idx - start_idx_sub1 >= sub1_length - 1\n start_idx_sub1 += 1\n end\n\n # Find all indexes of sub2 in str\n if str[start_idx_sub2..current_idx] == sub2\n sub2_found_idxs << start_idx_sub2\n start_idx_sub2 = current_idx + 1\n elsif current_idx - start_idx_sub2 >= sub2_length - 1\n start_idx_sub2 += 1\n end\n end\n\n result(sub1_found_idxs, sub1_length, sub2_found_idxs, sub2_length) ? 'YES' : 'NO'\nend\n\n# puts contain_substrings?('ABA', 'AB', 'BA') => NO\n# puts contain_substrings?('BACFAB', 'AB', 'BA') => YES\n# puts contain_substrings?('AXBYBXA', 'AB', 'BA') => NO\n\nputs contain_substrings?(get_input, 'AB', 'BA')"}, {"source_code": "s = gets.chomp.chars\nc = [false, false]\nabab = 0\ni = 0\nwhile c.include?(false) && i < s.size\n if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'A') ||\n (s[i] == 'B' && s[i + 1] == 'A' && s[i + 2] == 'B')\n abab += 1\n i += 3\n elsif s[i] == 'A' && s[i + 1] == 'B' && !c[0]\n c[0] = true\n i += 2\n elsif s[i] == 'B' && s[i + 1] == 'A' && !c[1]\n c[1] = true\n i += 2\n else\n i += 1\n end\nend\nputs c.all?{|x| x} || c.count(false) <= abab ? 'YES' : 'NO'\n"}, {"source_code": "a=gets.chomp\n\nif a.length>3\n\ti=0\n\tab=0\n\tba=0\n\tabab=0\n\tloop do\n\t\tif a[i..i+2]==\"ABA\" || a[i..i+2]==\"BAB\"\n\t\tabab+=1\n\t\ti+=2\n\t\telsif a[i..i+1]==\"AB\"\n\t\tab+=1\n\t\ti+=1\n\t\telsif a[i..i+1]==\"BA\"\n\t\tba+=1\n\t\ti+=1\n\t\tend\n\t\ti+=1\n\t\tbreak if i==a.length\n\t\tbreak if abab>1\n\t\tbreak if ab>0 && ba>0\n\t\tbreak if (abab>0 && ba>0) || (abab>0 && ab>0)\n\t\t\n\tend\n if ab>0 && ba>0\n\tputs \"YES\"\n\telsif (abab>0 && ba>0) || (abab>0 && ab>0) \n\tputs \"YES\"\n\telsif abab>1\n\tputs \"YES\"\n\telse \n\tputs \"NO\"\n\tend\nelse \n\n\tputs \"NO\"\n\t\nend "}, {"source_code": "s=gets.chomp\nx=s.index(\"AB\")\ny=s.rindex(\"BA\")\n\nif x==nil || y==nil then\n\tputs \"NO\"\nelsif (x-y).abs>1 then\n\tputs \"YES\"\nelse\n\tx=s.rindex(\"AB\")\n\ty=s.index(\"BA\")\n\tif x==nil || y==nil then\n\t\tputs \"NO\"\n\telsif (x-y).abs>1 then\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\n\n"}, {"source_code": "strings = gets.strip\n\ndef solve(strings)\n i = 0\n while i < strings.size\n if strings[i..i+1] == 'AB'\n i += 2\n while i < strings.size\n if strings[i..i+1] == 'BA'\n puts 'YES'\n return\n end\n i += 1\n end\n end\n i += 1\n end\n i = 0\n while i < strings.size\n if strings[i..i+1] == 'BA'\n i += 2\n while i < strings.size\n if strings[i..i+1] == 'AB'\n puts 'YES'\n return\n end\n i += 1\n end\n end\n i += 1\n end\n puts 'NO'\nend\n\nsolve(strings)\n"}, {"source_code": "a=gets.chomp\n\nif a.length>3\n\ti=0\n\tab=0\n\tba=0\n\tabab=0\n\tloop do\n\t\tif a[i..i+2]==\"ABA\" || a[i..i+2]==\"BAB\"\n\t\tabab+=1\n\t\ti+=2\n\t\telsif a[i..i+1]==\"AB\"\n\t\tab+=1\n\t\ti+=1\n\t\telsif a[i..i+1]==\"BA\"\n\t\tba+=1\n\t\ti+=1\n\t\tend\n\t\ti+=1\n\t\tbreak if i==a.length\n\t\tbreak if abab>1\n\t\tbreak if ab>0 && ba>0\n\t\tbreak if (abab>0 && ba>0) || (abab>0 && ab>0)\n\t\t\n\tend\n if ab>0 && ba>0\n\tputs \"YES\"\n\telsif (abab>0 && ba>0) || (abab>0 && ab>0) \n\tputs \"YES\"\n\telsif abab>1\n\tputs \"YES\"\n\telse \n\tputs \"NO\"\n\tend\nelse \n\n\tputs \"NO\"\n\t\nend "}, {"source_code": "\nstr=gets.chomp\n\nputs ((a=str.index('AB')) and (b=str.rindex('BA')) and b-a>1) || ((a=str.index('BA')) and (b=str.rindex('AB')) and b-a>1) ? 'YES' : 'NO'"}, {"source_code": "# http://codeforces.com/contest/550/problem/A\ns = gets.chomp\n\nn = s.length\nl_ab, l_ba, r_ab, r_ba = 0, 0, n - 1, n - 1\n\nwhile l_ab < n - 1 && r_ba >= 1\n first = s[l_ab] + s[l_ab + 1]\n last = s[r_ba - 1] + s[r_ba]\n\n if first == \"AB\"\n break if last == \"BA\"\n r_ba -= 1\n else\n l_ab += 1\n end\nend\n\nwhile l_ba < n - 1 && r_ab >= 1\n first = s[l_ba] + s[l_ba + 1]\n last = s[r_ab - 1] + s[r_ab]\n\n if first == \"BA\"\n break if last == \"AB\"\n r_ab -= 1\n else\n l_ba += 1\n end\nend\n\nputs (r_ba - l_ab - 1 > 1) || (r_ab - l_ba - 1 > 1) ? \"YES\" : \"NO\"\n"}, {"source_code": "s = gets\nd = s.dup\n\nif s.sub!('AB', 'XX').nil? || d.sub!('BA', 'XX').nil?\n puts 'NO'\nelsif (s && s.sub!('BA', 'XX')) || (d && d.sub!('AB', 'XX'))\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "str = gets.chomp\n\ndef occurences(str)\n flag = false\n\n str.each_char.each_with_index.inject([]) do |result, (c, index)|\n if c == 'A'\n flag = true\n elsif c == 'B' && flag\n result << index - 1\n flag = false\n else\n flag = false\n end\n\n result\n end\nend\n\narray = occurences(str)\nreverse_array = occurences(str.reverse).map do |item|\n str.size - item - 1\nend.sort\n\nresult = nil\n\narray.each do |item|\n result = reverse_array.find do |other_item|\n (other_item - item > 2) || (other_item < item)\n end\n\n if result\n break\n end\nend\n\nif result.nil? || array.empty? || reverse_array.empty?\n puts 'NO'\nelse\n puts 'YES'\nend\n"}, {"source_code": "s=gets.to_s\nif s.index('AB').nil? || s.index('BA').nil?\n puts :NO\nelse\n puts (s.rindex('AB')-s.index('BA')>1||s.rindex('BA')-s.index('AB')>1)?:YES: :NO\nend"}, {"source_code": "input = gets.chomp\n\ndef val(input)\n ab_index = []\n ba_index = []\n i = 0\n while i < input.length - 1\n ab_index << i if input[i..i + 1] == 'AB'\n i += 1\n end\n\n i = input.length - 1\n while i >= 0\n ba_index << i if input[i..i + 1] == 'BA'\n i -= 1\n end\n\n if !ba_index.first.nil? &&\n !ab_index.first.nil? &&\n (ba_index.first - ab_index.first > 1 ||\n ab_index.last - ba_index.last > 1)\n puts 'YES'\n return\n end\n\n puts 'NO'\nend\n\nval(input)\n"}, {"source_code": "#!/usr/bin/env ruby\ns=gets.chomp\nputs ((x=s.index('AB'))&&(y=s.rindex('BA'))&&y-x>1) || ((x=s.index('BA'))&&(y=s.rindex('AB'))&&y-x>1) ? :YES : :NO"}, {"source_code": "# http://codeforces.com/contest/550/problem/A\ndef match?(s, matchers)\n a = s.clone\n matchers.all? do |w|\n b = a.clone\n a.sub!(/#{w}/, '--')\n\n a != b\n end\nend\n\ns = gets.chomp\n\nputs (match?(s, %w(AB BA)) || match?(s, %w(BA AB))) ? 'YES' : 'NO'\n"}, {"source_code": "#!/usr/bin/ruby\ns = gets.chomp\n2.times do\n fab = s.index('AB')\n fba = s.rindex('BA')\n s.reverse!\n s.tr!('AB', 'BA')\n next if fab.nil? || fba.nil?\n next if fab + 1 >= fba\n\n puts \"YES\"\n exit\nend\nputs \"NO\"\n"}, {"source_code": "n = gets.chomp.split(\"\")\n\ncount = 0\n\nif n.size > 3\n\tarr = []\n\tarr1 = []\n\tfor i in (0..n.size-1)\n\t\tif n[i] == \"A\" && n[i+1] == \"B\"\n\t\t\tarr << [[i,i+1], \"AB\"]\n\t\tend\n\tend\n\ti = n.size-1\n\twhile i > 0\n\t\tif n[i] == \"A\" && n[i-1] == \"B\"\n\t\t\tarr1 << [[i-1,i], \"BA\"]\n\t\tend\n\t\ti -= 1\n\tend\n\n\tif arr.size > 0 && arr1.size > 0\n\t\tif arr.size <= arr1.size\n\t\t\tfor i in (0..arr.size-1)\n\t\t\t\tfor x in (0..arr1.size-1)\n\t\t\t\t\tif arr[i][0][0] != arr1[x][0][0] && arr[i][0][1] != arr1[x][0][0] && arr[i][0][0] != arr1[x][0][1] && arr[i][0][1] != arr1[x][0][1]\n\t\t\t\t\t\tcount += 1\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\telse\n\t\t\tfor i in (0..arr1.size-1)\n\t\t\t\tfor x in (0..arr.size-1)\n\t\t\t\t\tif arr1[i][0][0] != arr[x][0][0] && arr1[i][0][1] != arr[x][0][0] && arr1[i][0][0] != arr[x][0][1] && arr1[i][0][1] != arr[x][0][1]\n\t\t\t\t\t\tcount += 1\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\nend\n\nif count > 0\n\tprint 'YES'\nelse\n\tprint 'NO'\nend"}, {"source_code": "#!/bin/ruby\n\nrequire 'json'\nrequire 'stringio'\n\ndef twoSubstrings(str)\n\tif str.include?('AB') && str.include?('BA')\n\t\ttmp_str = str.split(\"AB\", 2)\n\t\tif(tmp_str[0].include?('BA') || tmp_str[1].include?('BA'))\n\t\t\treturn true;\n\t\tend\n\t\ttmp_str = str.split(\"BA\", 2)\n\t\tif(tmp_str[0].include?('AB') || tmp_str[1].include?('AB'))\n\t\t\treturn true;\n\t\tend\n\t\treturn false\n\telse\n\t\treturn false\n\tend\nend\n\nstr = gets.rstrip\n\nputs twoSubstrings(str) ? \"YES\" : \"NO\" "}, {"source_code": "#!/bin/ruby\n\nrequire 'json'\nrequire 'stringio'\n\ndef twoSubstrings(str)\n\tif str.include?('AB') && str.include?('BA')\n\t\ttmp_str = str.split(\"AB\", 2)\n\t\treturn true if(tmp_str[0].include?('BA') || tmp_str[1].include?('BA'))\n\t\ttmp_str = str.split(\"BA\", 2)\n\t\treturn true if(tmp_str[0].include?('AB') || tmp_str[1].include?('AB'))\n\t\treturn false\n\telse\n\t\treturn false\n\tend\nend\n\nstr = gets.rstrip\n\nputs twoSubstrings(str) ? \"YES\" : \"NO\" "}, {"source_code": "input = gets.chomp\ninput_copy = input\n\na = input.index(\"AB\")\nb = input.index(\"BA\")\n\nif a != nil\n input = input[0,a] + \"XX\" + input[a+2,input.length]\n if input.index(\"BA\") != nil\n puts(\"YES\")\n exit(0)\n end\nend\n\ninput = input_copy\n\nif b != nil\n input = input[0,b] + \"XX\" + input[b+2,input.length]\n if input.index(\"AB\") != nil\n puts(\"YES\")\n exit(0)\n end\nend\n\nputs(\"NO\")"}, {"source_code": "a=gets.chomp\n\nif a.length>3\n\ti=0\n\tab=0\n\tba=0\n\tabab=0\n\tloop do\n\t\tif a[i..i+2]==\"ABA\" || a[i..i+2]==\"BAB\"\n\t\tabab+=1\n\t\ti+=2\n\t\telsif a[i..i+1]==\"AB\"\n\t\tab+=1\n\t\ti+=1\n\t\telsif a[i..i+1]==\"BA\"\n\t\tba+=1\n\t\ti+=1\n\t\tend\n\t\ti+=1\n\t\tbreak if i==a.length\n\t\tbreak if abab>1\n\t\tbreak if ab>0 && ba>0\n\t\tbreak if (abab>0 && ba>0) || (abab>0 && ab>0)\n\t\t\n\tend\n if ab>0 && ba>0\n\tputs \"YES\"\n\telsif (abab>0 && ba>0) || (abab>0 && ab>0) \n\tputs \"YES\"\n\telsif abab>1\n\tputs \"YES\"\n\telse \n\tputs \"NO\"\n\tend\nelse \n\n\tputs \"NO\"\n\t\nend "}], "negative_code": [{"source_code": "# http://codeforces.com/contest/550/problem/A\ns = gets.chomp\n\nflag = %w(AB BA).all? do |w|\n old = s.clone\n s.gsub!(/#{w}/, '')\n\n (s.length != old.length) && ((old.length - s.length) % 2).even?\nend\n\nputs flag ? 'YES' : 'NO'\n"}, {"source_code": "# http://codeforces.com/contest/550/problem/A\ns = gets.chomp\n\nflag = %w(AB BA).all? do |w|\n old = s.clone\n s.sub!(/#{w}/, '')\n\n (s.length != old.length) && ((old.length - s.length) % 2).even?\nend\n\nputs flag ? 'YES' : 'NO'\n"}, {"source_code": "# http://codeforces.com/contest/550/problem/A\ndef match?(s, matchers)\n a = s.clone\n matchers.all? do |w|\n b = a.clone\n a.sub!(/#{w}/, '')\n\n b.length - a.length == w.length\n end\nend\n\ns = gets.chomp\nputs (match?(s, %w(AB BA)) || match?(s, %w(BA AB))) ? 'YES' : 'NO'\n"}, {"source_code": "# http://codeforces.com/contest/550/problem/A\ns = gets.chomp\n\nflag = %w(AB BA).all? do |w|\n s2 = s.delete(w)\n\n return false if s2.length == s.length\n ((s2.length - s.length) % 2).even?\nend\n\nputs flag ? 'YES' : 'NO'\n"}, {"source_code": "#!/usr/bin/ruby\ns = gets.chomp\n2.times do\n s.reverse!\n fab = s.index('AB')\n fba = s.rindex('BA')\n next if fab.nil? || fba.nil?\n next if fab + 1 >= fba\n\n puts \"YES\"\n exit\nend\nputs \"NO\"\n"}, {"source_code": "#!/bin/ruby\n\nrequire 'json'\nrequire 'stringio'\n\ndef twoSubstrings(str)\n\tif str.include?('AB') && str.include?('BA')\n\t\ttmp_str = str.split(\"AB\", 2)\n\t\treturn false unless (tmp_str[0].include?('BA') || tmp_str[1].include?('BA'))\n\t\ttmp_str = str.split(\"BA\", 2)\n\t\treturn false unless (tmp_str[0].include?('AB') || tmp_str[1].include?('AB'))\n\t\treturn true\n\telse\n\t\treturn false\n\tend\nend\n\nstr = gets.rstrip\n\nputs twoSubstrings(str) ? \"YES\" : \"NO\""}, {"source_code": "#!/bin/ruby\n\nrequire 'json'\nrequire 'stringio'\n\ndef twoSubstrings(str)\n\tif str.include?('AB') && str.include?('BA')\n\t\ttmp_str = str.split(\"AB\", 2)\n\t\treturn false unless (tmp_str[0].include?('BA') || tmp_str[1].include?('BA'))\n\t\ttmp_str = str.split(\"BA\", 2)\n\t\treturn false unless (tmp_str[0].include?('AB') || tmp_str[1].include?('AB'))\n\t\treturn true\n\telse\n\t\treturn false\n\tend\nend\n\nstr = gets.rstrip\n\nputs twoSubstrings str"}, {"source_code": "#!/bin/ruby\n\nrequire 'json'\nrequire 'stringio'\n\ndef twoSubstrings(str)\n\treturn false if str.include?('ABA')\n\tif str.include?('AB') && str.include?('BA')\n\t\ttmp_str = str.split(\"AB\", 2)\n\t\treturn false unless (tmp_str[0].include?('BA') || tmp_str[1].include?('BA'))\n\t\ttmp_str = str.split(\"BA\", 2)\n\t\treturn false unless (tmp_str[0].include?('AB') || tmp_str[1].include?('AB'))\n\t\treturn true\n\telse\n\t\treturn false\n\tend\nend\n\nstr = gets.rstrip\n\nputs twoSubstrings(str) ? \"YES\" : \"NO\" "}, {"source_code": "a=gets.chomp\n\nif a.length>3\n\ti=0\n\tab=0\n\tba=0\n\tabab=0\n\tloop do\n\t\tif a[i..i+2]==\"ABA\" || a[i..i+2]==\"BAB\"\n\t\tabab+=1\n\t\ti+=2\n\t\telsif a[i..i+1]==\"AB\"\n\t\tab+=1\n\t\ti+=1\n\t\telsif a[i..i+1]==\"BA\"\n\t\tba+=1\n\t\ti+=1\n\t\tend\n\t\ti+=1\n\t\tbreak if i==a.length\n\t\tbreak if abab>1\n\t\tbreak if ab>0 && ba>0\n\t\tbreak if (abab>0 && ba>0) || (abab>0 && ab>0)\n\t\t\n\tend\n if ab>0 && ba>0\n\tputs \"YES\"\n\telsif (abab>0 && ba>1) || (abab>0 && ab>1) \n\tputs \"YES\"\n\telse \n\tputs \"NO\"\n\tend\nelse \n\n\tputs \"NO\"\n\t\nend "}, {"source_code": "a=gets.chomp\n\nif a.length>3\n\ti=0\n\tab=0\n\tba=0\n\tabab=0\n\tloop do\n\t\tif a[i..i+2]==\"ABA\" || a[i..i+2]==\"BAB\"\n\t\tabab+=1\n\t\ti+=2\n\t\telsif a[i..i+1]==\"AB\"\n\t\tab+=1\n\t\ti+=1\n\t\telsif a[i..i+1]==\"BA\"\n\t\tba+=1\n\t\ti+=1\n\t\tend\n\t\ti+=1\n\t\tbreak if i==a.length\n\t\tbreak if abab>1\n\t\tbreak if ab>0 && ba>0\n\t\tbreak if (abab>0 && ba>0) || (abab>0 && ab>0)\n\t\t\n\tend\n if ab>0 && ba>0\n\tputs \"YES\"\n\telsif (abab>0 && ba>1) || (abab>0 && ab>1) \n\tputs \"YES\"\n\telsif abab>1\n\tputs \"YES\"\n\telse \n\tputs \"NO\"\n\tend\nelse \n\n\tputs \"NO\"\n\t\nend \n"}, {"source_code": "a=gets.chomp\ni=0\nf=0\np=\"ab\"\nloop do \nif p==\"ab\"\n\n\tif a[i..i+1]==\"AB\" || a[i..i+1]==\"BA\"\n\t\tif a[i..i+1]==\"AB\"\n\t\tp=\"b\"\n\t\telse \n\t\tp=\"a\"\n\t\tend\n\tf+=1\n\ti+=1\n\tend\nelsif p==\"a\"\n\n\tif a[i..i+1]==\"AB\"\n\tf+=1\n\ti+=1\n\tp=\"b\"\n\tend\nelsif p==\"b\"\n\n\tif a[i..i+1]==\"BA\"\n\tf+=1\n\ti+=1\n\tend\nend\n\ti+=1\n\tbreak if i==a.length\nend\n\nif f==2 \nputs \"YES\"\nelse\nputs \"NO\"\nend"}, {"source_code": "a=gets.chomp\n\nif a.length>3\n\ti=0\n\tab=0\n\tba=0\n\tabab=0\n\tloop do\n\t\tif a[i..i+2]==\"ABA\" || a[i..i+2]==\"BAB\"\n\t\tabab+=1\n\t\tend\n\t\tif a[i..i+1]==\"AB\"\n\t\tab+=1\n\t\ti+=1\n\t\telsif a[i..i+1]==\"BA\"\n\t\tba+=1\n\t\ti+=1\n\t\tend\n\t\ti+=1\n\t\tbreak if i==a.length\n\t\tbreak if abab>1\n\t\tbreak if ab>0 && ba>0\n\t\tbreak if (abab>0 && ba>1) || (abab>0 && ab>1)\n\t\t\n\tend\n if ab>0 && ba>0\n\tputs \"YES\"\n\telsif (abab>0 && ba>1) || (abab>0 && ab>1) \n\tputs \"YES\"\n\telse \n\tputs \"NO\"\n\tend\nelse \n\n\tputs \"NO\"\n\t\nend "}, {"source_code": "# http://codeforces.com/contest/550/problem/A\n\ndef get_input\n gets.chomp\nend\n\n# Checking str contains both sub1 and sub2 without overlapping in general\ndef contain_substrings?(str, sub1, sub2)\n sub1_length = sub1.size\n sub2_length = sub2.size\n start_idx_sub1 = 0\n start_idx_sub2 = 0\n sub1_found_idxs = []\n sub2_found_idxs = []\n\n 0.upto(str.size - 1) do |current_idx|\n # Find all indexes of sub1 in str\n if str[start_idx_sub1..current_idx] == sub1\n sub1_found_idxs << start_idx_sub1\n start_idx_sub1 = current_idx + 1\n elsif current_idx - start_idx_sub1 >= sub1_length - 1\n start_idx_sub1 += 1\n end\n\n # Find all indexes of sub2 in str\n if str[start_idx_sub2..current_idx] == sub2\n sub2_found_idxs << start_idx_sub2\n start_idx_sub2 = current_idx + 1\n elsif current_idx - start_idx_sub2 >= sub2_length - 1\n start_idx_sub2 += 1\n end\n end\n\n if sub1_found_idxs.empty? || sub2_found_idxs.empty?\n 'NO'\n elsif sub1_found_idxs.first < sub2_found_idxs.last\n sub2_found_idxs.last - sub1_found_idxs.first >= sub1_length ? 'YES' : 'NO'\n elsif sub1_found_idxs.last > sub2_found_idxs.first\n sub1_found_idxs.last - sub2_found_idxs.first >= sub2_length ? 'YES' : 'NO'\n else\n 'NO'\n end\nend\n\n# puts contain_substrings?('ABA', 'AB', 'BA') => NO\n# puts contain_substrings?('BACFAB', 'AB', 'BA') => YES\n# puts contain_substrings?('AXBYBXA', 'AB', 'BA') => NO\n\nputs contain_substrings?(get_input, 'AB', 'BA')\n"}, {"source_code": "# http://codeforces.com/contest/550/problem/A\n\ndef get_input\n gets.chomp\nend\n\ndef result(sub1_found_idxs, sub1_length, sub2_found_idxs, sub2_length)\n return 'NO' if sub1_found_idxs.empty? || sub2_found_idxs.empty?\n\n case1 = sub1_found_idxs.first < sub2_found_idxs.last &&\n (sub2_found_idxs.last - sub1_found_idxs.first) >= sub1_length\n case2 = sub1_found_idxs.last > sub2_found_idxs.first &&\n (sub1_found_idxs.last - sub2_found_idxs.first) >= sub2_length\n\n case1 || case2\nend\n\n# Checking str contains both sub1 and sub2 without overlapping in general\ndef contain_substrings?(str, sub1, sub2)\n sub1_length = sub1.size\n sub2_length = sub2.size\n start_idx_sub1 = 0\n start_idx_sub2 = 0\n sub1_found_idxs = []\n sub2_found_idxs = []\n\n 0.upto(str.size - 1) do |current_idx|\n # Find all indexes of sub1 in str\n if str[start_idx_sub1..current_idx] == sub1\n sub1_found_idxs << start_idx_sub1\n start_idx_sub1 = current_idx + 1\n elsif current_idx - start_idx_sub1 >= sub1_length - 1\n start_idx_sub1 += 1\n end\n\n # Find all indexes of sub2 in str\n if str[start_idx_sub2..current_idx] == sub2\n sub2_found_idxs << start_idx_sub2\n start_idx_sub2 = current_idx + 1\n elsif current_idx - start_idx_sub2 >= sub2_length - 1\n start_idx_sub2 += 1\n end\n end\n\n result(sub1_found_idxs, sub1_length, sub2_found_idxs, sub2_length) ? 'YES' : 'NO'\nend\n\n# puts contain_substrings?('ABA', 'AB', 'BA') => NO\n# puts contain_substrings?('BACFAB', 'AB', 'BA') => YES\n# puts contain_substrings?('AXBYBXA', 'AB', 'BA') => NO\n\nputs contain_substrings?(get_input, 'AB', 'BA')"}, {"source_code": "s=gets.chomp\nx=s.index(\"AB\")\ny=s.rindex(\"BA\")\nif x==nil || y==nil then\n\tputs \"NO\"\nelsif (x-y).abs>1 then\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n\n"}, {"source_code": "strings = gets.strip\n\nab = nil\nba = nil\n\ni = 0\n\nyes = false\nwhile i < strings.size\n if !ab && strings[i..i+1] == 'AB' && ([i, i+1]&ba.to_a).empty?\n ab = [i, i+1]\n elsif !ba && strings[i..i+1] == 'BA' && ([i, i+1]&ab.to_a).empty?\n ba = [i, i+1]\n end\n\n if ab && ba && (ab&ba).empty?\n yes = true\n break\n end\n\n i += 1\nend\n\nputs yes ? 'YES' : 'NO'\n"}, {"source_code": "strings = gets.strip\n\nab = nil\nba = nil\n\ni = 0\n\nyes = false\nwhile i < strings.size\n if strings[i..i+1] == 'AB' && ([i, i+1]&ba.to_a).empty?\n ab = [i, i+1]\n elsif strings[i..i+1] == 'BA' && ([i, i+1]&ba.to_a).empty?\n ba = [i, i+1]\n end\n\n if ab && ba && (ab&ba).empty?\n yes = true\n break\n end\n\n i += 1\nend\n\nputs yes ? 'YES' : 'NO'\n"}, {"source_code": "strings = gets.strip\n\nab = nil\nba = nil\n\ni = 0\n\nwhile i < strings.size\n ab = [i, i+1] if strings[i..i+1] == 'AB'\n ba = [i, i+1] if strings[i..i+1] == 'BA'\n break if ab && ba\n i += 1\nend\n\nputs ab && ba && (ab&ba).empty? ? 'YES' : 'NO'\n"}, {"source_code": "strings = gets.strip\n\nflags = 0\nstrings.each_char do |c|\n flags ^= 1 << c.ord - 65\nend\n\ncount = 0\nwhile flags != 0\n flags &= flags - 1\n count += 1\nend\n\nputs count > 1 ? 'YES' : 'NO'\n"}, {"source_code": "strings = gets.strip\n\ndef solve(strings)\n i = 0\n while i < strings.size\n if strings[i..i+1] == 'AB'\n i += 2\n while i < strings.size\n if strings[i..i+1] == 'BA'\n puts 'YES'\n return\n end\n i += 1\n end\n elsif strings[i..i+1] == 'BA'\n i += 2\n while i < strings.size\n if strings[i..i+1] == 'AB'\n puts 'YES'\n return\n end\n i += 1\n end\n end\n i += 1\n end\n puts 'NO'\nend\n\nsolve(strings)\n"}, {"source_code": "strings = 'AXBYBXA'\n\nflags = 0\nstrings.each_char do |c|\n flags ^= 1 << c.ord - 65\nend\n\ncount = 0\nwhile flags != 0\n flags &= flags - 1\n count += 1\nend\n\nputs count > 1 ? 'YES' : 'NO'"}, {"source_code": "\nstr=gets.chomp\n\nputs ((a=str.index('AB')) and (b=str.index('BA')) and b-a>1) || ((a=str.index('BA')) and (b=str.rindex('AB')) and b-a>1) ? 'YES' : 'NO'"}, {"source_code": "s=gets.chomp.to_s\ns=s.sub(/AB/,'')\nputs s\nunless $~\n\tputs \"NO\"\nelse\n\ts=s.sub(/BA/,'')\n\tputs s\n\tunless $~\n\t\tputs (\"NO\")\n\telse\n\t\tputs \"YES\"\n\tend\nend\n"}, {"source_code": "s=gets.chomp.to_s\ndef func(s,c,d)\n\ty=s\n\ty=y.sub(/#{c}/,'')\n\tif $~\n\t\ty=y.sub(/#{d}/,'')\n\t\tif $~\n\t\t\treturn true\n\t\telse\n\t\t\treturn false\n\t\tend\n\telse\n\t\treturn false\n\tend\nend\n\t\t\t\nif func(s,'AB','BA') || func(s,'BA','AB')\n\tprint(\"YES\\n\")\nelse\n\tputs \"NO\"\nend"}, {"source_code": "s=gets.chomp.to_s\ns=s.sub(/AB/,'')\n#puts s\nunless $~\n\tputs \"NO\"\nelse\n\ts=s.sub(/BA/,'')\n\t#puts s\n\tunless $~\n\t\tputs (\"NO\")\n\telse\n\t\tputs \"YES\"\n\tend\nend\n"}, {"source_code": "str = gets.chomp\n\nflag = false\narray = []\n\nstr.each_char.each_with_index do |c, index|\n if c == 'A'\n flag = true\n elsif c == 'B' && flag\n array << index - 1\n else\n flag = false\n end\nend\n\nreverse_array = []\nflag = false\nsize = str.size\n\nstr.reverse.each_char.each_with_index do |c, index|\n if c == 'A'\n flag = true\n elsif c == 'B' && flag\n reverse_array << size - index\n else\n flag = false\n end\nend\n\nresult = nil\n\narray.each do |item|\n result = reverse_array.bsearch { |other_item| other_item > item && other_item - item < 3 }\n\n if result\n break\n end\nend\n\nif result || array.empty? || reverse_array.empty?\n puts 'NO'\nelse\n puts 'YES'\nend\n"}, {"source_code": "str = gets.chomp\n\ndef occurences(str)\n flag = false\n\n str.each_char.each_with_index.inject([]) do |result, (c, index)|\n if c == 'A'\n flag = true\n elsif c == 'B' && flag\n result << index - 1\n else\n flag = false\n end\n\n result\n end\nend\n\narray = occurences(str)\nreverse_array = occurences(str.reverse).map do |item|\n str.size - item - 1\nend.sort\n\nresult = nil\n\nputs \"#{array} #{reverse_array}\"\narray.each do |item|\n result = reverse_array.bsearch { |other_item| (other_item - item).abs > 2 }\n\n if result\n break\n end\nend\n\nif result.nil? || array.empty? || reverse_array.empty?\n puts 'NO'\nelse\n puts 'YES'\nend\n"}, {"source_code": "str = gets.chomp\n\ndef occurences(str)\n flag = false\n\n str.each_char.each_with_index.inject([]) do |result, (c, index)|\n if c == 'A'\n flag = true\n elsif c == 'B' && flag\n result << index - 1\n else\n flag = false\n end\n\n result\n end\nend\n\narray = occurences(str)\nreverse_array = occurences(str.reverse).map do |item|\n str.size - item - 1\nend.sort\n\nresult = nil\n\narray.each do |item|\n result = reverse_array.bsearch do |other_item|\n (other_item - item > 2) || (other_item < item)\n end\n\n if result\n break\n end\nend\n\nif result.nil? || array.empty? || reverse_array.empty?\n puts 'NO'\nelse\n puts 'YES'\nend\n"}, {"source_code": "str = gets.chomp\n\ndef occurences(str)\n flag = false\n\n str.each_char.each_with_index.inject([]) do |result, (c, index)|\n if c == 'A'\n flag = true\n elsif c == 'B' && flag\n result << index - 1\n else\n flag = false\n end\n\n result\n end\nend\n\narray = occurences(str)\nreverse_array = occurences(str.reverse).map do |item|\n str.size - item - 1\nend.sort\n\nresult = nil\n\narray.each do |item|\n result = reverse_array.bsearch { |other_item| (other_item - item).abs > 2 }\n\n if result\n break\n end\nend\n\nif result.nil? || array.empty? || reverse_array.empty?\n puts 'NO'\nelse\n puts 'YES'\nend\n"}, {"source_code": "str = gets.chomp\n\ndef occurences(str)\n flag = false\n\n str.each_char.each_with_index.inject([]) do |result, (c, index)|\n if c == 'A'\n flag = true\n elsif c == 'B' && flag\n result << index - 1\n flag = false\n else\n flag = false\n end\n\n result\n end\nend\n\narray = occurences(str)\nreverse_array = occurences(str.reverse).map do |item|\n str.size - item - 1\nend.sort\n\nresult = nil\n\narray.each do |item|\n result = reverse_array.bsearch do |other_item|\n (other_item - item > 2) || (other_item < item)\n end\n\n if result\n break\n end\nend\n\nif result.nil? || array.empty? || reverse_array.empty?\n puts 'NO'\nelse\n puts 'YES'\nend\n"}, {"source_code": "input = 'AXBYBXA'\n\ndef validate(input)\n return false unless input.include?('AB') && input.include?('BA')\n input.each_char.with_index do |_, index|\n break if index > input.length - 2\n if input[index..index + 1] == 'AB' || input[index..index + 1] == 'BA'\n # back and forward word should not overlap\n\n unless input[index..index + 2] == 'ABA' ||\n input[index..index + 2] == 'ABA' ||\n input[index - 1..index + 1] == 'ABA' ||\n input[index - 1..index + 1] == 'ABA'\n return true\n end\n end\n end\n\n true\nend\n\ndef output(input)\n if validate(input)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\noutput(input)\n"}, {"source_code": "input = gets.chomp\n\ndef validate(input)\n return false unless input.include?('AB') || input.include?('BA')\n input.each_char.with_index do |_, index|\n break if index > input.length - 1\n if input[index..index + 1] == 'AB' || input[index..index + 1] == 'BA'\n # back and forward word should not overlap\n\n unless input[index..index + 2] == 'ABA' ||\n input[index..index + 2] == 'ABA' ||\n input[index - 1..index + 1] == 'ABA' ||\n input[index - 1..index + 1] == 'ABA'\n return true\n end\n end\n end\n\n true\nend\n\ndef output(input)\n if validate(input)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\noutput(input)\n"}, {"source_code": "input = gets.chomp\n\ndef validate(input)\n return false unless input.include?('AB') || input.include?('BA')\n input.each_char.with_index do |_, index|\n break if index > input.length - 1\n if input[index..index + 1] == 'AB' || input[index..index + 1] == 'BA'\n # back and forward word should not overlap\n\n unless input[index..index + 2] == 'ABA' ||\n input[index..index + 2] == 'ABA' ||\n input[index - 1..index + 1] == 'ABA' ||\n input[index - 1..index + 1] == 'ABA'\n return true\n end\n end\n end\n\n false\nend\n\ndef output(input)\n if validate(input)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\noutput(input)\n"}, {"source_code": "def read\n #gets.chomp\n 'ABAAB'\nend\n\ndef validate\n input = read\n return false unless input.include?('AB') || input.include?('BA')\n input.each_char.with_index do |_, index|\n break if index > input.length - 3\n if input[index..index + 2] == 'ABA' || input[index..index + 2] == 'BAB'\n return false\n end\n end\n\n true\nend\n\ndef output\n if validate\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\noutput\n"}, {"source_code": "input = gets.chomp\n\ndef validate(input)\n return false unless input.include?('AB') || input.include?('BA')\n input.each_char.with_index do |_, index|\n break if index > input.length - 1\n if input[index..index + 1] == 'AB' || input[index..index + 1] == 'BA'\n # back and forward word should not overlap\n\n puts input[index..index + 1]\n unless input[index..index + 2] == 'ABA' ||\n input[index..index + 2] == 'ABA' ||\n input[index - 1..index + 1] == 'ABA' ||\n input[index - 1..index + 1] == 'ABA'\n return true\n end\n end\n end\n\n false\nend\n\ndef output(input)\n if validate(input)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\noutput(input)\n"}, {"source_code": "def read\n gets.chomp\nend\n\ndef validate\n input = read\n return false unless input.include?('AB') || input.include?('BA')\n input.each_char.with_index do |_, index|\n break if index > input.length - 3\n if input[index..index + 3] == 'ABA' || input[index..index + 3] == 'BAB'\n return false\n end\n end\n\n true\nend\n\ndef output\n if validate\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\noutput\n"}, {"source_code": "input = gets.chomp\n\ndef val(input)\n ab_index = []\n ba_index = []\n i = 0\n while i < input.length - 1\n ab_index << i if input[i..i + 1] == 'AB'\n i += 1\n end\n\n i = input.length - 1\n while i >= 0\n ba_index << i if input[i..i + 1] == 'BA'\n i -= 1\n end\n\n if !ba_index.first.nil? &&\n !ab_index.first.nil? &&\n (ba_index.first - ab_index.first > 1 ||\n ab_index.first - ba_index.first > 1)\n puts 'YES'\n return\n end\n\n puts 'NO'\nend\n\nval(input)\n"}, {"source_code": "input = gets.chomp\n\ndef val(input)\n ab_index = []\n ba_index = []\n i = 0\n while i < input.length - 1\n ab_index << i if input[i..i + 1] == 'AB'\n i += 1\n end\n\n i = input.length - 1\n while i >= 0\n ba_index << i if input[i..i + 1] == 'BA'\n i -= 1\n end\n\n if !ba_index.last.nil? &&\n !ab_index.first.nil? &&\n (ba_index.last - ab_index.first > 1 ||\n ab_index.first - ba_index.last > 1)\n puts 'YES'\n return\n end\n\n puts 'NO'\nend\n\nval(input)\n"}, {"source_code": "input = 'ABAAHBA'\n\ndef validate(input)\n return false unless input.include?('AB') && input.include?('BA')\n input.each_char.with_index do |_, index|\n break if index > input.length - 2\n if input[index..index + 1] == 'AB' || input[index..index + 1] == 'BA'\n # back and forward word should not overlap\n\n unless input[index..index + 2] == 'ABA' ||\n input[index..index + 2] == 'ABA' ||\n input[index - 1..index + 1] == 'ABA' ||\n input[index - 1..index + 1] == 'ABA'\n return true\n end\n end\n end\n\n false\nend\n\ndef output(input)\n if validate(input)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\noutput(input)\n"}, {"source_code": "input = gets.chomp\n\ndef validate(input)\n return false unless input.include?('AB') && input.include?('BA')\n input.each_char.with_index do |_, index|\n break if index > input.length - 3\n if input[index..index + 2] == 'ABA' || input[index..index + 2] == 'BAB'\n return false\n end\n end\n\n true\nend\n\ndef output(input)\n if validate(input)\n puts 'YES'\n else\n puts 'NO'\n end\nend\n\noutput(input)\n"}, {"source_code": "n = gets.chomp.split(\"\")\n\nab = 0\nba = 0\n\nwhile n.size > 1 || (ab > 0 && ba > 0) \n\tif n.index(\"A\") != nil && n.index(\"B\") != nil && n.index(\"A\") == n.index(\"B\")-1 && n.size >= 2\n\t\tab += 1\n\t\tn.delete_at(n.index(\"A\"))\n\t\tn.delete_at(n.index(\"B\"))\n\telsif n.index(\"A\") != nil && n.index(\"B\") != nil && n.index(\"B\") == n.index(\"A\")-1 && n.size >= 2\n\t\tba += 1\n\t\tn.delete_at(n.index(\"B\"))\n\t\tn.delete_at(n.index(\"A\"))\n\telse\n\t\tbreak\n\tend\nend\nif ab > 0 && ba > 0\n\tprint \"YES\"\nelse\n\tprint \"NO\"\nend"}, {"source_code": "n = gets.chomp.split(\"\")\n\ncount = 0\n\nif n.size > 3\n\tarr = []\n\tarr1 = []\n\tfor i in (0..n.size-1)\n\t\tif n[i] == \"A\" && n[i+1] == \"B\"\n\t\t\tarr << [i+1, \"AB\"]\n\t\tend\n\tend\n\ti = n.size-1\n\twhile i > 1\n\t\tif n[i] == \"A\" && n[i-1] == \"B\"\n\t\t\tarr1 << [i-1, \"BA\"]\n\t\tend\n\t\ti -= 1\n\tend\n\t\n\tif arr.size > 0 && arr1.size > 0\n\t\tif arr.size <= arr1.size\n\t\t\tfor i in (0..arr.size-1)\n\t\t\t\tfor x in (0..arr1.size-1)\n\t\t\t\t\tif arr[i][0] != arr1[x][0]\n\t\t\t\t\t\tcount += 1\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\telse\n\t\t\tfor i in (0..arr1.size-1)\n\t\t\t\tfor x in (0..arr.size-1)\n\t\t\t\t\tif arr1[i][0] != arr[x][0]\n\t\t\t\t\t\tcount += 1\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\nend\n\nif count > 0\n\tprint 'YES'\nelse\n\tprint 'NO'\nend"}, {"source_code": "n = gets.chomp.split(\"\")\n\ncount = 0\n\nif n.size > 3\n\tarr = []\n\tarr1 = []\n\tfor i in (0..n.size-1)\n\t\tif n[i] == \"A\" && n[i+1] == \"B\"\n\t\t\tarr << [i+1, \"AB\"]\n\t\tend\n\tend\n\ti = n.size-1\n\twhile i > 0\n\t\tif n[i] == \"A\" && n[i-1] == \"B\"\n\t\t\tarr1 << [i, \"BA\"]\n\t\tend\n\t\ti -= 1\n\tend\n\t\n\tif arr.size > 0 && arr1.size > 0\n\t\tfor i in (0..arr.size-1)\n\t\t\tif arr[i][0] != arr1[i][0]\n\t\t\t\tcount += 1\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\n\nif count > 0\n\tprint 'YES'\nelse\n\tprint 'NO'\nend"}, {"source_code": "n = gets.chomp.split(\"\")\n\ncount = 0\n\nif n.size > 3\n\tarr = []\n\tarr1 = []\n\tfor i in (0..n.size-1)\n\t\tif n[i] == \"A\" && n[i+1] == \"B\"\n\t\t\tarr << [i+1, \"AB\"]\n\t\tend\n\tend\n\ti = n.size-1\n\twhile i > 0\n\t\tif n[i] == \"A\" && n[i-1] == \"B\"\n\t\t\tarr1 << [i-1, \"BA\"]\n\t\tend\n\t\ti -= 1\n\tend\n\n\tif arr.size > 0 && arr1.size > 0\n\t\tif arr.size <= arr1.size\n\t\t\tfor i in (0..arr.size-1)\n\t\t\t\tfor x in (0..arr1.size-1)\n\t\t\t\t\tif arr[i][0] != arr1[x][0]\n\t\t\t\t\t\tcount += 1\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\telse\n\t\t\tfor i in (0..arr1.size-1)\n\t\t\t\tfor x in (0..arr.size-1)\n\t\t\t\t\tif arr1[i][0] != arr[x][0]\n\t\t\t\t\t\tcount += 1\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\nend\n\nif count > 0\n\tprint 'YES'\nelse\n\tprint 'NO'\nend"}, {"source_code": "input = gets.chomp\ninput_copy = input\n\na = input.index(\"AB\")\nb = input.index(\"BA\")\n\nif a != nil\n input = input[0,a] + input[a+2,input.length]\n if input.index(\"BA\") != nil\n puts(\"YES\")\n exit(0)\n end\nend\n\ninput = input_copy\n\nif b != nil\n input = input[0,b] + input[b+2,input.length]\n if input.index(\"AB\") != nil\n puts(\"YES\")\n exit(0)\n end\nend\n\nputs(\"NO\")"}, {"source_code": "def solution(string)\n return \"NO\" if string.index(\"AB\").nil? || string.index(\"BA\").nil?\n return \"YES\" if (string.rindex(\"AB\") - string.index(\"BA\")).abs != 1\n \"NO\"\nend\nputs solution(gets.strip)\n"}, {"source_code": "s = gets.chomp.chars\nc = [false, false]\ni = 0\nwhile c.include?(false) && i < s.size\n if s[i] == 'A' && s[i + 1] == 'B' && !c[0]\n c[0] = true\n i += 2\n elsif s[i] == 'B' && s[i + 1] == 'A' && !c[1]\n c[1] = true\n i += 2\n else\n i += 1\n end\nend\nputs c.all?{|x| x} ? 'YES' : 'NO'\n"}, {"source_code": "s = gets.chomp\nputs s.include?('AB') && s.include?('BA') && !s.include?('ABA') && !s.include?('BAB') ? 'YES' : 'NO'\n"}, {"source_code": "s = gets.chomp.chars\nc = [false, false]\ni = 0\nwhile c.include?(false) && i < s.size\n if s[i] == 'A' && s[i + 1] == 'B'\n c[0] = true\n i += 2\n elsif s[i] == 'B' && s[i + 1] == 'A'\n c[1] = true\n i += 2\n else\n i += 1\n end\nend\nputs c.all?{|x| x} ? 'YES' : 'NO'\n"}, {"source_code": "s = gets.chomp\nputs s.slice!('AB') && s.slice!('BA') ? 'YES' : 'NO'\n"}, {"source_code": "s = gets.chomp\nputs (s.slice!('AB') && s.slice!('BA')) || (s.slice!('BA') && s.slice!('AB')) ? 'YES' : 'NO'\n"}, {"source_code": "# http://codeforces.com/contest/550/problem/A\n\ns = gets.chomp\n\nn = s.length\nl, r = 0, n - 1\n\nwhile l < n - 1\n first = s[l] + s[l + 1]\n if first == \"AB\" || first == \"BA\"\n break l\n else\n l += 1\n end\nend\n\nwhile r >= 1\n last = s[r] + s[r - 1]\n if last == \"AB\" || last == \"BA\"\n break r -= 1\n else\n r -= 1\n end\nend\n\nputs r - l > 1 ? \"YES\" : \"NO\"\n"}, {"source_code": "# http://codeforces.com/contest/550/problem/A\ns = gets.chomp\n\nn = s.length\nl, r = 0, n - 1\n\nwhile l < n - 1 && r >= 1\n first = s[l] + s[l + 1]\n last = s[r - 1] + s[r]\n if first == \"AB\"\n break if last == \"BA\"\n r -= 1\n elsif first == \"BA\"\n break if last == \"AB\"\n r -= 1\n else\n l += 1\n end\nend\n\nputs r - l - 1 > 1 ? \"YES\" : \"NO\"\n"}, {"source_code": "s = gets\nd = s.dup\n\nif s.sub!('AB', '').nil? || d.sub!('BA', '').nil?\n puts 'NO'\nelsif (s && s.sub!('BA', '')) || (d && d.sub!('AB', ''))\n puts 'YES'\nelse\n puts 'NO'\nend\n"}, {"source_code": "begin\n throw 'Error' if gets.sub!('AB', '').sub!('BA', '').nil?\n puts 'YES'\nrescue\n puts 'NO'\nend\n"}], "src_uid": "33f7c85e47bd6c83ab694a834fa728a2"} {"source_code": "@n, m, d = gets.chomp.split(' ').map(&:to_i)\n\n@d_down = Array.new(@n+1) { -1 }\n@d_up = Array.new(@n+1) { -1 }\n\n@marked = Array.new(@n+1)\n@marked_points = gets.chomp.split(' ').map(&:to_i)\n@marked_points.each do |m| \n\t@marked[m] = true \n\t@d_down[m] = 0\nend\n\n@d_up[1] = @marked[1] ? 0 : -1\n\n@map = Array.new(@n+1) {|i| []}\n(2..@n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\t@map[a] << b\n\t@map[b] << a\nend\n\n@way_down = Array.new(@n+1) {|i| []}\n@way_up = Array.new(@n+1) {|i| []}\n@traverse = []\n\n@deep_points = []\n\ngo = [1]\nwhile go.size > 0\n\tnew_go = []\t\n\tgo.each do |from|\n\t\t@traverse << from\n\t\tadded = false\n\t\t@map[from].each do |to|\n\t\t\tnext if @way_up[from].include? to\n\t\t\t@way_down[from] << to\n\t\t\t@way_up[to] << from\n\t\t\tnew_go << to\n\t\t\tadded = true\n\t\tend\t\t\n\t\t@deep_points << from unless added\n\tend\n\tgo = new_go\nend\n\n#p @way_down\n#p @way_up\n#p @deep_points\n\ndef dist_down_alt2\n\t(@traverse.size-1).downto(0).each do |i|\n\t\tparent = @traverse[i]\n\t\t@way_down[parent].each do |child|\n\t\t\tif @d_down[child] != -1\n\t\t\t\ttmp = @d_down[child] + 1\n\t\t\t\t@d_down[parent] = tmp if tmp > @d_down[parent]\n\t\t\tend\n\t\tend\n\tend\nend\n\ndef dist_up\n\ttarget = [1]\n\tvisited = Array.new(@n+1) { false }\n\n\twhile target.size > 0\n\t\tnew_target = []\n\t\ttarget.each do |to|\n\t\t\tnext if visited[to]\n\t\t\tvisited[to] = true\n\n\t\t\tmax1 = -1\n\t\t\tmax2 = -1\n\t\t\t@way_down[to].each do |child|\n\t\t\t\tif @d_down[child] > max1\n\t\t\t\t\tmax2 = max1\n\t\t\t\t\tmax1 = @d_down[child]\n\t\t\t\telsif @d_down[child] > max2\n\t\t\t\t\tmax2 = @d_down[child]\n\t\t\t\tend\n\t\t\tend\n\n\t\t\t@way_down[to].each do |child|\t\n\t\t\t\tsibling = @d_down[child] == max1 ? max2 : max1\n\t\t\t\t@d_up[child] = sibling + 2 if sibling != -1\n\n\t\t\t\tif @d_up[to] != -1 \n\t\t\t\t\ttmp = @d_up[to] + 1\n\t\t\t\t\t@d_up[child] = tmp if tmp > @d_up[child]\n\t\t\t\tend\n\n\t\t\t\tif @marked[child]\n\t\t\t\t\t@d_up[child] = 0 if @d_up[child] < 0\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\tnew_target << child\n\t\t\t\t#dist_up(child, to, @d_up, @d_down)\t\t\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\nend\n\n#dist_down\ndist_down_alt2\ndist_up\n\nsum = 0\n(1..@n).each do |i|\n\tsum += 1 if @d_down[i] <= d and @d_up[i] <= d\nend\np sum", "positive_code": [{"source_code": "@n, m, @d = gets.chomp.split(' ').map(&:to_i)\n\n@d_down = Array.new(@n+1) { -1 }\n@d_up = Array.new(@n+1) { -1 }\n\n@marked = Array.new(@n+1)\ngets.chomp.split(' ').map(&:to_i).each do |m| \n\t@marked[m] = true\n\t@d_down[m] = 0\nend\n\n@d_up[1] = @marked[1] ? 0 : -1\n\n@map = Array.new(@n+1) {|i| []}\n(2..@n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\t@map[a] << b\n\t@map[b] << a\nend\n\n@way_down = Array.new(@n+1) {|i| []}\n@way_up = Array.new(@n+1) {|i| []}\n@traverse = []\n\ngo = [1]\nwhile go.size > 0\n\tnew_go = []\t\n\tgo.each do |from|\n\t\t@traverse << from\n\t\t@map[from].each do |to|\n\t\t\tnext if @way_up[from].include? to\n\t\t\t@way_down[from] << to\n\t\t\t@way_up[to] << from\n\t\t\tnew_go << to\n\t\tend\t\t\n\tend\n\tgo = new_go\nend\n\ndef dist_down\n\t(@traverse.size-1).downto(0).each do |i|\n\t\tparent = @traverse[i]\n\t\t@way_down[parent].each do |child|\n\t\t\tif @d_down[child] != -1\n\t\t\t\ttmp = @d_down[child] + 1\n\t\t\t\t@d_down[parent] = tmp if tmp > @d_down[parent]\n\t\t\tend\n\t\tend\n\tend\nend\n\ndef dist_up\n\tsum = 0\n\t@traverse.each do |to|\n\t\tmax1 = -1\n\t\tmax2 = -1\n\t\t@way_down[to].each do |child|\n\t\t\tif @d_down[child] > max1\n\t\t\t\tmax2 = max1\n\t\t\t\tmax1 = @d_down[child]\n\t\t\telsif @d_down[child] > max2\n\t\t\t\tmax2 = @d_down[child]\n\t\t\tend\n\t\tend\n\n\t\t@way_down[to].each do |child|\t\n\t\t\tsibling = @d_down[child] == max1 ? max2 : max1\n\t\t\t@d_up[child] = sibling + 2 if sibling != -1\n\n\t\t\tif @d_up[to] != -1 \n\t\t\t\ttmp = @d_up[to] + 1\n\t\t\t\t@d_up[child] = tmp if tmp > @d_up[child]\n\t\t\tend\n\n\t\t\tif @marked[child]\n\t\t\t\t@d_up[child] = 0 if @d_up[child] < 0\n\t\t\tend\t\t\t\t\t\t\t\n\t\tend\n\t\tsum += 1 if @d_down[to] <= @d and @d_up[to] <= @d\n\tend\t\t\n\tsum\nend\n\ndist_down\nsum = dist_up\n\np sum"}], "negative_code": [{"source_code": "@n, m, d = gets.chomp.split(' ').map(&:to_i)\n@marked = Array.new(@n+1)\ngets.chomp.split(' ').map(&:to_i).each { |m| @marked[m] = true }\n\n@map = Hash.new { |h,k| h[k] = [] }\n(2..@n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\t@map[a] << b\n\t@map[b] << a\nend\n\n@way_down = Array.new(@n+1) {|i| []}\n@way_up = Array.new(@n+1) {|i| []}\n\n@deep_points = []\n\ngo = [1]\nwhile go.size > 0\n\tnew_go = []\n\tgo.each do |from|\n\t\tadded = false\n\t\t@map[from].each do |to|\n\t\t\tnext if @way_up[from].include? to\n\t\t\t@way_down[from] << to\n\t\t\t@way_up[to] << from\n\t\t\tnew_go << to\n\t\t\tadded = true\n\t\tend\t\t\n\t\t@deep_points << from unless added\n\tend\n\tgo = new_go\nend\n\n#p @way_down\n#p @way_up\n#p @deep_points\n\ndef dist_down(dist)\n\t\n\t(1..@n).each do |i|\n\t\tif @marked[i]\n\t\t\tdist[i] = 0\n\t\tend\n\tend\n\n\ttarget = @deep_points\n\twhile target.size > 0\n\t\tnew_target = []\t\n\t\t\n\t\ttarget.each do |from|\n\t\t\t@way_up[from].each do |to|\n\t\t\t\tif dist[from] != -1\n\t\t\t\t\tdist[to] = dist[from] + 1\n\t\t\t\tend\n\t\t\t\tnew_target << to\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\t\t\t\nend\n\ndef dist_up(to, d_up, d_down)\t\n\ttarget = [to]\n\n\twhile target.size > 0 and target[0].size > 0\n\t\tnew_target = []\n\t\ttarget.each do |to|\n\t\t\t\n\t\t\tmax1 = -1\n\t\t\tmax2 = -1\n\t\t\t@way_down[to].each do |child|\n\t\t\t\tif d_down[child] > max1\n\t\t\t\t\tmax2 = max1\n\t\t\t\t\tmax1 = d_down[child]\n\t\t\t\telsif d_down[child] > max2\n\t\t\t\t\tmax2 = d_down[child]\n\t\t\t\tend\n\t\t\tend\n\n\t\t\t@way_down[to].each do |child|\t\n\t\t\t\tsibling = d_down[child] == max1 ? max2 : max1\n\t\t\t\td_up[child] = sibling + 2 if sibling != -1\n\n\t\t\t\tif d_up[to] != -1 \n\t\t\t\t\td_up[child] = [d_up[to] + 1, d_up[child]].max\n\t\t\t\tend\n\n\t\t\t\tif @marked[child]\n\t\t\t\t\td_up[child] = [0, d_up[child]].max\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\tnew_target << child\n\t\t\t\t#dist_up(child, to, d_up, d_down)\t\t\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\nend\n\ndd = Array.new(@n+1) { -1 }\ndu = Array.new(@n+1) { -1 }\ndu[1] = @marked[1] ? 0 : -1\n\ndist_down(dd)\ndist_up(1, du, dd)\n\nsum = 0\n(1..@n).each do |i|\n\tsum += 1 if dd[i] <= d and du[i] <= d\nend\np sum"}, {"source_code": "\nn, m, d = gets.chomp.split(' ').map(&:to_i)\nmarked = Array.new(n+1)\ngets.chomp.split(' ').map(&:to_i).each { |m| marked[m] = true }\n\nh = Hash.new { |h,k| h[k] = [] }\n(2..n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\th[a] << b\n\th[b] << a\nend\n\ndef dist_down(to, from, dist, map, marked)\n\tdist[to] = 0 if marked[to]\t\t\n\t\n\tmap[to].each do |child|\n\t\tnext if child == from\n\t\tdist[to] = [dist[to], dist_down(child, to, dist, map, marked)+1].max\n\tend\n\n\tdist[to]\nend\n\ndef dist_up(to, from, d_up, d_down, map, marked)\t\n\n\tmax1 = -1\n\tmax2 = -1\n\tmap[to].each do |child|\n\t\tnext if child == from\n\n\t\tif d_down[child] > max1\n\t\t\tmax2 = max1\n\t\t\tmax1 = d_down[child]\n\t\telsif d_down[child] > max2\n\t\t\tmax2 = d_down[child]\n\t\tend\n\tend\n\n\tmap[to].each do |child|\n\t\tnext if child == from\n\n\t\tsibling = d_down[child] == max1 ? max2 : max1\n\t\td_up[child] = sibling + 2 if sibling != -1\n\n\t\tif d_up[to] != -1 \n\t\t\td_up[child] = [d_up[to] + 1, d_up[child]].max\n\t\tend\n\n\t\tif marked[child]\n\t\t\td_up[child] = [0, d_up[child]].max\n\t\tend\n\t\t\n\t\tdist_up(child, to, d_up, d_down, map, marked)\t\t\n\tend\nend\t\n\ndd = Array.new(n+1) { -1 }\ndu = Array.new(n+1) { -1 }\ndu[1] = marked[1] ? 0 : -1\n\ndist_down(1, -1, dd, h, marked)\ndist_up(1, -1, du, dd, h, marked)\n\nsum = 0\n(1..n).each do |i|\n\tsum += 1 if dd[i] <= d and du[i] <= d\nend\np sum"}, {"source_code": "$global_map = {}\n\ndef find(res, map, from, deep, level)\n\ttodo = []\n\tif deep > 0\n\t\tfrom.each do |from_p|\n\t\t\tmap[from_p].each do |dst|\t\t\t\t\n\t\t\t\tkey = \"#{level}-#{dst}\"\n\t\t\t\tif !$global_map[key]\t\t\t\t\n\t\t\t\t\ttodo << dst\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tres[dst] += 1\n\t\t\t\t\t$global_map[key] = true\n\t\t\t\tend\t\t\t\t\t\t\t\n\t\t\tend\n\t\tend\n\tend\n\ttodo\nend\n\nn, m, d = gets.chomp.split(' ').map(&:to_i)\npp = gets.chomp.split(' ').map(&:to_i)\n\nh = Hash.new { |h,k| h[k] = [] }\n(2..n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\th[a] << b\n\th[b] << a\nend\n\nif n=100000\n puts 777\n exit\nend\n\nres = Hash.new(0)\npp.each_with_index do |p, index|\n\tres[p] += 1\n\t$global_map[\"#{index+1}-#{p}\"] = true\n\t\n\ttodo = [p]\n\td_in = d\n\twhile !todo.empty?\t\t\n\t\ttodo = find(res, h, todo, d_in, index+1)\n\t\td_in -= 1\n\tend\n\n\t# if res.nil?\n\t# \tres = tmp\n\t# else\n\t# \t#res = res & tmp\n\t# \tres = Hash[(res.each_key.to_a & tmp.each_key.to_a).map {|x| [x,nil]}]\n\t# end\n\n\t# break if res.empty?\nend\n\n#puts res.inspect\nputs res.select {|k,v| v == m}.size"}, {"source_code": "\nn, m, d = gets.chomp.split(' ').map(&:to_i)\n@marked = Array.new(n+1)\ngets.chomp.split(' ').map(&:to_i).each { |m| @marked[m] = true }\n\nh = Hash.new { |h,k| h[k] = [] }\n(2..n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\th[a] << b\n\th[b] << a\nend\n\n@way_down = Array.new(n+1) {|i| []}\n@way_up = Array.new(n+1) {|i| []}\n\n@deep_points = []\n\ngo = [1]\nwhile go.size > 0\n\tnew_go = []\n\tgo.each do |from|\n\t\tadded = false\n\t\th[from].each do |to|\n\t\t\tnext if @way_up[from].include? to\n\t\t\t@way_down[from] << to\n\t\t\t@way_up[to] << from\n\t\t\tnew_go << to\n\t\t\tadded = true\n\t\tend\n\t\t@deep_points << from unless added\n\tend\n\tgo = new_go\nend\n\n#p @way_down\n#p @way_up\n#p @deep_points\n\ndef dist_down(dist)\n\t\n\t(1..@marked.size-1).each do |i|\n\t\tdist[i] = 0 if @marked[i]\n\tend\n\n\ttarget = @deep_points\n\twhile target.size > 0\n\t\tnew_target = []\t\n\t\t\n\t\ttarget.each do |from|\n\t\t\t@way_up[from].each do |to|\n\t\t\t\tif dist[from] != -1\n\t\t\t\t\tdist[to] = dist[from] + 1\n\t\t\t\tend\n\t\t\t\tnew_target << to\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\t\t\t\nend\n\ndef dist_up(d_up, d_down)\t\n\n\ttarget = [1]\n\n\twhile target.size > 0\n\t\tnew_target = []\n\n\t\ttarget.each do |to|\n\t\t\tmax1 = -1\n\t\t\tmax2 = -1\n\t\t\t@way_down[to].each do |child|\t\t\t\t\n\t\t\t\tif d_down[child] > max1\n\t\t\t\t\tmax2 = max1\n\t\t\t\t\tmax1 = d_down[child]\n\t\t\t\telsif d_down[child] > max2\n\t\t\t\t\tmax2 = d_down[child]\n\t\t\t\tend\n\t\t\tend\n\n\t\t\t@way_down[to].each do |child|\t\t\t\t\n\t\t\t\tsibling = d_down[child] == max1 ? max2 : max1\n\t\t\t\td_up[child] = sibling + 2 if sibling != -1\n\n\t\t\t\tif d_up[to] != -1 \n\t\t\t\t\td_up[child] = [d_up[to] + 1, d_up[child]].max\n\t\t\t\tend\n\n\t\t\t\tif @marked[child]\n\t\t\t\t\td_up[child] = [0, d_up[child]].max\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\tnew_target << child\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\nend\t\n\ndd = Array.new(n+1) { -1 }\ndu = Array.new(n+1) { -1 }\ndu[1] = @marked[1] ? 0 : -1\n\ndist_down dd\ndist_up du, dd\n\nsum = 0\n(1..n).each do |i|\n\tsum += 1 if dd[i] != -1 and du[i] != -1 and dd[i] <= d and du[i] <= d\nend\n\n#p dd\n#p du\np sum"}, {"source_code": "def find(res, map, from, deep, level)\n\ttodo = []\n\tif deep > 0\n\t\tfrom.each do |from_p|\n\t\t\tmap[from_p].each do |dst|\t\t\t\t\n\t\t\t\tif res[dst] < level\n\t\t\t\t\ttodo << dst\t\t\t\t\n\t\t\t\tend\n\t\t\t\tres[dst] += 1\n\t\t\tend\n\t\tend\n\tend\n\ttodo\nend\n\nn, m, d = gets.chomp.split(' ').map(&:to_i)\npp = gets.chomp.split(' ').map(&:to_i)\n\nh = Hash.new { |h,k| h[k] = [] }\n(2..n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\th[a] << b\n\th[b] << a\nend\n\nres = Hash.new(0)\npp.each_with_index do |p, index|\n\tres[p] += 1\n\t\n\ttodo = [p]\n\td_in = d\n\twhile !todo.empty?\t\t\n\t\ttodo = find(res, h, todo, d_in, index+1)\n\t\td_in -= 1\n\tend\n\n\t# if res.nil?\n\t# \tres = tmp\n\t# else\n\t# \t#res = res & tmp\n\t# \tres = Hash[(res.each_key.to_a & tmp.each_key.to_a).map {|x| [x,nil]}]\n\t# end\n\n\t# break if res.empty?\nend\n\n#puts res.inspect\nputs res.select {|k,v| v == m}.size"}, {"source_code": "\nn, m, d = gets.chomp.split(' ').map(&:to_i)\n@marked = Array.new(n+1)\ngets.chomp.split(' ').map(&:to_i).each { |m| @marked[m] = true }\n\nh = Hash.new { |h,k| h[k] = [] }\n(2..n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\th[a] << b\n\th[b] << a\nend\n\n@way_down = Array.new(n+1) {|i| []}\n@way_up = Array.new(n+1) {|i| []}\n\n@deep_points = []\n\ngo = [1]\nwhile go.size > 0\n\tnew_go = []\n\tgo.each do |from|\n\t\tadded = false\n\t\th[from].each do |to|\n\t\t\tnext if @way_up[from].include? to\n\t\t\t@way_down[from] << to\n\t\t\t@way_up[to] << from\n\t\t\tnew_go << to\n\t\t\tadded = true\n\t\tend\n\t\t@deep_points << from unless added\n\tend\n\tgo = new_go\nend\n\n#p @way_down\n#p @way_up\n#p @deep_points\n\ndef dist_down(dist)\n\t\n\t(1..@marked.size-1).each do |i|\n\t\tdist[i] = 0 if @marked[i]\n\tend\n\n\ttarget = @deep_points\n\twhile target.size > 0\n\t\tnew_target = []\t\n\t\t\n\t\ttarget.each do |from|\n\t\t\t@way_up[from].each do |to|\n\t\t\t\tif dist[from] != -1\n\t\t\t\t\tdist[to] = dist[from] + 1\n\t\t\t\tend\n\t\t\t\tnew_target << to\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\t\t\t\nend\n\ndef dist_up(d_up, d_down)\t\n\n\ttarget = [1]\n\n\twhile target.size > 0\n\t\tnew_target = []\n\n\t\ttarget.each do |to|\n\t\t\tmax1 = -1\n\t\t\tmax2 = -1\n\t\t\t@way_down[to].each do |child|\t\t\t\t\n\t\t\t\tif d_down[child] > max1\n\t\t\t\t\tmax2 = max1\n\t\t\t\t\tmax1 = d_down[child]\n\t\t\t\telsif d_down[child] > max2\n\t\t\t\t\tmax2 = d_down[child]\n\t\t\t\tend\n\t\t\tend\n\n\t\t\t@way_down[to].each do |child|\t\t\t\t\n\t\t\t\tsibling = d_down[child] == max1 ? max2 : max1\n\t\t\t\td_up[child] = sibling + 2 if sibling != -1\n\n\t\t\t\tif d_up[to] != -1 \n\t\t\t\t\td_up[child] = [d_up[to] + 1, d_up[child]].max\n\t\t\t\tend\n\n\t\t\t\tif @marked[child]\n\t\t\t\t\td_up[child] = [0, d_up[child]].max\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\tnew_target << child\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\nend\t\n\ndd = Array.new(n+1) { -1 }\ndu = Array.new(n+1) { -1 }\ndu[1] = @marked[1] ? 0 : -1\n\ndist_down dd\ndist_up du, dd\n\nsum = 0\n(1..n).each do |i|\n\tsum += 1 if dd[i] <= d and du[i] <= d\nend\n\n#p dd\n#p du\np sum"}, {"source_code": "def find(res, map, from, deep)\n\tif deep > 0\n\t\tmap[from].each do |dst|\n\t\t\tif !res.include? dst\n\t\t\t\tres << dst\n\t\t\t\tfind(res, map, dst, deep-1)\n\t\t\tend\n\t\tend\n\tend\nend\n\nn, m, d = gets.chomp.split(' ').map(&:to_i)\npp = gets.chomp.split(' ').map(&:to_i)\n\nh = Hash.new { |h,k| h[k] = [] }\n(2..n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\th[a] << b\n\th[b] << a\nend\n\nres = nil\npp.each do |p|\n\ttmp = []\n\tfind(tmp, h, p, d)\n\tif res.nil?\n\t\tres = tmp\n\telse\n\t\tres = res & tmp\n\tend\n\n\tbreak if res.empty?\nend\n\nres = res - pp\n\nputs res.size"}, {"source_code": "\nn, m, d = gets.chomp.split(' ').map(&:to_i)\n@marked = Array.new(n+1)\ngets.chomp.split(' ').map(&:to_i).each { |m| @marked[m] = true }\n\nh = Hash.new { |h,k| h[k] = [] }\n(2..n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\th[a] << b\n\th[b] << a\nend\n\n@way_down = Array.new(n+1) {|i| []}\n@way_up = Array.new(n+1) {|i| []}\n\n@deep_points = []\n\ngo = [1]\nwhile go.size > 0\n\tnew_go = []\n\tgo.each do |from|\n\t\tadded = false\n\t\th[from].each do |to|\n\t\t\tnext if @way_up[from].include? to\n\t\t\t@way_down[from] << to\n\t\t\t@way_up[to] << from\n\t\t\tnew_go << to\n\t\t\tadded = true\n\t\tend\t\t\n\t\t@deep_points << from unless added\n\tend\n\tgo = new_go\nend\n\n#p @way_down\n#p @way_up\n#p @deep_points\n\ndef dist_down(dist)\n\t\n\t(1..@marked.size-1).each do |i|\n\t\tif @marked[i]\n\t\t\tdist[i] = 0\n\t\tend\n\tend\n\n\ttarget = @deep_points\n\twhile target.size > 0\n\t\tnew_target = []\t\n\t\t\n\t\ttarget.each do |from|\n\t\t\t@way_up[from].each do |to|\n\t\t\t\tif dist[from] != -1\n\t\t\t\t\tdist[to] = dist[from] + 1\n\t\t\t\tend\n\t\t\t\tnew_target << to\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\t\t\t\nend\n\ndef dist_up(d_up, d_down)\t\n\n\ttarget = [1]\n\n\twhile target.size > 0\n\t\tnew_target = []\n\n\t\ttarget.each do |to|\n\t\t\tmax1 = -1\n\t\t\tmax2 = -1\n\t\t\t@way_down[to].each do |child|\t\t\t\t\n\t\t\t\tif d_down[child] > max1\n\t\t\t\t\tmax2 = max1\n\t\t\t\t\tmax1 = d_down[child]\n\t\t\t\telsif d_down[child] > max2\n\t\t\t\t\tmax2 = d_down[child]\n\t\t\t\tend\n\t\t\tend\n\n\t\t\t@way_down[to].each do |child|\t\t\t\t\n\t\t\t\tsibling = d_down[child] == max1 ? max2 : max1\n\t\t\t\td_up[child] = sibling + 2 if sibling != -1\n\n\t\t\t\tif d_up[to] != -1 \n\t\t\t\t\td_up[child] = [d_up[to] + 1, d_up[child]].max\n\t\t\t\tend\n\n\t\t\t\tif @marked[child]\n\t\t\t\t\td_up[child] = [0, d_up[child]].max\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\tnew_target << child\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\nend\t\n\ndd = Array.new(n+1) { -1 }\ndu = Array.new(n+1) { -1 }\ndu[1] = @marked[1] ? 0 : -1\n\ndist_down dd\ndist_up du, dd\n\nsum = 0\n(1..n).each do |i|\t\n\tsum += 1 if dd[i] <= d and du[i] <= d\nend\n\n#p dd\n#p du\np sum"}, {"source_code": "\nn, m, d = gets.chomp.split(' ').map(&:to_i)\n@marked = Array.new(n+1)\ngets.chomp.split(' ').map(&:to_i).each { |m| @marked[m] = true }\n\nh = Hash.new { |h,k| h[k] = [] }\n(2..n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\th[a] << b\n\th[b] << a\nend\n\n@way_down = Array.new(n+1) {|i| []}\n@way_up = Array.new(n+1) {|i| []}\n\n@deep_points = []\n\ngo = [1]\nwhile go.size > 0\n\tnew_go = []\n\tgo.each do |from|\n\t\tadded = false\n\t\th[from].each do |to|\n\t\t\tnext if @way_up[from].include? to\n\t\t\t@way_down[from] << to\n\t\t\t@way_up[to] << from\n\t\t\tnew_go << to\n\t\t\tadded = true\n\t\tend\n\t\t@deep_points << from unless added\n\tend\n\tgo = new_go\nend\n\n#p @way_down\n#p @way_up\n#p @deep_points\n\ndef dist_down(dist)\n\t\n\t(1..@marked.size-1).each do |i|\n\t\tdist[i] = 0 if @marked[i]\n\tend\n\n\ttarget = @deep_points\n\twhile target.size > 0\n\t\tnew_target = []\t\n\t\t\n\t\ttarget.each do |from|\n\t\t\t@way_up[from].each do |to|\n\t\t\t\tif dist[from] != -1\n\t\t\t\t\tdist[to] = dist[from] + 1\n\t\t\t\tend\n\t\t\t\tnew_target << to\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\t\t\t\nend\n\ndef dist_up(d_up, d_down)\t\n\n\ttarget = [1]\n\n\twhile target.size > 0\n\t\tnew_target = []\n\n\t\ttarget.each do |to|\n\t\t\tmax1 = -1\n\t\t\tmax2 = -1\n\t\t\t@way_down[to].each do |child|\t\t\t\t\n\t\t\t\tif d_down[child] > max1\n\t\t\t\t\tmax2 = max1\n\t\t\t\t\tmax1 = d_down[child]\n\t\t\t\telsif d_down[child] > max2\n\t\t\t\t\tmax2 = d_down[child]\n\t\t\t\tend\n\t\t\tend\n\n\t\t\t@way_down[to].each do |child|\t\t\t\t\n\t\t\t\tsibling = d_down[child] == max1 ? max2 : max1\n\t\t\t\td_up[child] = sibling + 2 if sibling != -1\n\n\t\t\t\tif d_up[to] != -1 \n\t\t\t\t\td_up[child] = [d_up[to] + 1, d_up[child]].max\n\t\t\t\tend\n\n\t\t\t\tif @marked[child]\n\t\t\t\t\td_up[child] = [0, d_up[child]].max\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\tnew_target << child\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\nend\t\n\ndd = Array.new(n+1) { -1 }\ndu = Array.new(n+1) { -1 }\ndu[1] = @marked[1] ? 0 : -1\n\ndist_down dd\ndist_up du, dd\n\nsum = 0\n(1..n).each do |i|\t\n\tnext if dd[i] == -1 and du[i] == -1\n\tsum += 1 if dd[i] <= d and du[i] <= d\nend\n\n#p dd\n#p du\np sum"}, {"source_code": "$global_map = {}\n\ndef find(res, map, from, deep, level)\n\ttodo = []\n\tif deep > 0\n\t\tfrom.each do |from_p|\n\t\t\tmap[from_p].each do |dst|\t\t\t\t\n\t\t\t\tkey = \"#{level}-#{dst}\"\n\t\t\t\tif !$global_map[key]\t\t\t\t\n\t\t\t\t\ttodo << dst\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tres[dst] += 1\n\t\t\t\t\t$global_map[key] = true\n\t\t\t\tend\t\t\t\t\t\t\t\n\t\t\tend\n\t\tend\n\tend\n\ttodo\nend\n\nn, m, d = gets.chomp.split(' ').map(&:to_i)\npp = gets.chomp.split(' ').map(&:to_i)\n\nh = Hash.new { |h,k| h[k] = [] }\n(2..n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\th[a] << b\n\th[b] << a\nend\n\nif n==100000\n puts 777\n exit\nend\n\nres = Hash.new(0)\npp.each_with_index do |p, index|\n\tres[p] += 1\n\t$global_map[\"#{index+1}-#{p}\"] = true\n\t\n\ttodo = [p]\n\td_in = d\n\twhile !todo.empty?\t\t\n\t\ttodo = find(res, h, todo, d_in, index+1)\n\t\td_in -= 1\n\tend\n\n\t# if res.nil?\n\t# \tres = tmp\n\t# else\n\t# \t#res = res & tmp\n\t# \tres = Hash[(res.each_key.to_a & tmp.each_key.to_a).map {|x| [x,nil]}]\n\t# end\n\n\t# break if res.empty?\nend\n\n#puts res.inspect\nputs res.select {|k,v| v == m}.size"}, {"source_code": "\nn, m, d = gets.chomp.split(' ').map(&:to_i)\n@marked = Array.new(n+1)\ngets.chomp.split(' ').map(&:to_i).each { |m| @marked[m] = true }\n\nh = Hash.new { |h,k| h[k] = [] }\n(2..n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\th[a] << b\n\th[b] << a\nend\n\n@way_down = Array.new(n+1) {|i| []}\n@way_up = Array.new(n+1) {|i| []}\n\n@deep_points = []\n\ngo = [1]\nwhile go.size > 0\n\tnew_go = []\n\tgo.each do |from|\n\t\tadded = false\n\t\th[from].each do |to|\n\t\t\tnext if @way_up[from].include? to\n\t\t\t@way_down[from] << to\n\t\t\t@way_up[to] << from\n\t\t\tnew_go << to\n\t\t\tadded = true\n\t\tend\n\t\t@deep_points << from unless added\n\tend\n\tgo = new_go\nend\n\n# p @way_down\n# p @way_up\n# p @deep_points\n\ndef dist_down(dist)\n\t\n\t(1..@marked.size-1).each do |i|\n\t\tdist[i] = 0 if @marked[i]\n\tend\n\n\ttarget = @deep_points\n\twhile target.size > 0\n\t\tnew_target = []\t\n\t\t\n\t\ttarget.each do |from|\n\t\t\t@way_up[from].each do |to|\n\t\t\t\tif dist[from] != -1\n\t\t\t\t\tdist[to] = dist[from] + 1\n\t\t\t\t\tnew_target << to\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\t\t\t\nend\n\ndef dist_up(d_up, d_down)\t\n\n\ttarget = [1]\n\n\twhile target.size > 0\n\t\tnew_target = []\n\n\t\ttarget.each do |to|\n\t\t\tmax1 = -1\n\t\t\tmax2 = -1\n\t\t\t@way_down[to].each do |child|\t\t\t\t\n\t\t\t\tif d_down[child] > max1\n\t\t\t\t\tmax2 = max1\n\t\t\t\t\tmax1 = d_down[child]\n\t\t\t\telsif d_down[child] > max2\n\t\t\t\t\tmax2 = d_down[child]\n\t\t\t\tend\n\t\t\tend\n\n\t\t\t@way_down[to].each do |child|\t\t\t\t\n\t\t\t\tsibling = d_down[child] == max1 ? max2 : max1\n\t\t\t\td_up[child] = sibling + 2 if sibling != -1\n\n\t\t\t\tif d_up[to] != -1 \n\t\t\t\t\td_up[child] = [d_up[to] + 1, d_up[child]].max\n\t\t\t\tend\n\n\t\t\t\tif @marked[child]\n\t\t\t\t\td_up[child] = [0, d_up[child]].max\n\t\t\t\tend\n\t\t\t\t\n\t\t\t\tnew_target << child\n\t\t\tend\n\t\tend\n\t\ttarget = new_target\n\tend\nend\t\n\ndd = Array.new(n+1) { -1 }\ndu = Array.new(n+1) { -1 }\ndu[1] = @marked[1] ? 0 : -1\n\ndist_down dd\ndist_up du, dd\n\nsum = 0\n(1..n).each do |i|\n\tsum += 1 if dd[i] <= d and du[i] <= d\nend\n\n# p dd\n# p du\np sum"}, {"source_code": "$global_map = Hash.new(0)\n\ndef find(res, map, from, deep)\n\ttodo = []\n\tif deep > 0\n\t\tfrom.each do |from_p|\n\t\t\tmap[from_p].each do |dst|\t\t\t\t\n\t\t\t\t\t\n\t\t\t\tif !res.include? dst\n\t\t\t\t\tres[dst] = nil\n\t\t\t\t\t\n\t\t\t\t\tkey = \"#{from_p}-#{dst}\"\t\t\t\t\n\t\t\t\t\tif $global_map[key] < deep\n\t\t\t\t\t\ttodo << dst\t\t\t\t\n\t\t\t\t\t\t$global_map[key] = deep\n\t\t\t\t\tend\t\t\t\t\t\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\ttodo\nend\n\nn, m, d = gets.chomp.split(' ').map(&:to_i)\npp = gets.chomp.split(' ').map(&:to_i)\n\nh = Hash.new { |h,k| h[k] = [] }\n(2..n).each do \n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\th[a] << b\n\th[b] << a\nend\n\nres = nil\npp.each do |p|\n\ttmp = Hash[p,nil]\n\t\n\ttodo = [p]\n\td_in = d\n\twhile !todo.empty?\t\t\n\t\ttodo = find(tmp, h, todo, d_in)\n\t\td_in -= 1\n\tend\n\n\tif res.nil?\n\t\tres = tmp\n\telse\n\t\tres = Hash[(res.each_key.to_a & tmp.each_key.to_a).map {|x| [x,nil]}]\n\tend\n\n\tbreak if res.empty?\nend\n\nputs res.size"}], "src_uid": "52863d45ad223687e6975344ab9d3124"} {"source_code": "gets.to_i.times do\r\n s=gets.chomp.chars\r\n s.size.times do |i|\r\n if i.even?\r\n if s[i]==\"a\"\r\n s[i]=\"b\"\r\n else\r\n s[i]=\"a\"\r\n end\r\n else\r\n if s[i]==\"z\"\r\n s[i]=\"y\"\r\n else\r\n s[i]=\"z\"\r\n end\r\n end\r\n end\r\n puts s.join\r\nend\r\n", "positive_code": [{"source_code": "t = gets.to_i\r\nt.times do\r\n s = gets.chomp\r\n s.length.times do |i|\r\n if i % 2 == 0\r\n s[i] = s[i] != \"a\" ? \"a\" : \"b\"\r\n else\r\n s[i] = s[i] != \"z\" ? \"z\" : 'y'\r\n end\r\n end\r\n puts s\r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n s = gets.chomp\r\n s.length.times do |i|\r\n if i % 2 == 0\r\n s[i] = s[i] != \"a\" ? \"a\" : \"b\"\r\n else\r\n s[i] = s[i] = s[i] != \"z\" ? \"z\" : \"y\"\r\n end\r\n end\r\n puts s\r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n s = gets.chomp\r\n s.length.times do |i|\r\n if i % 2 == 0\r\n s[i] = s[i] != \"a\" ? \"a\" : \"b\"\r\n else\r\n s[i] = (s[i] = s[i] != \"z\" ? \"z\" : \"y\")\r\n end\r\n end\r\n puts s\r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n s = gets.chomp\r\n s.length.times do |i|\r\n if i % 2 == 0\r\n s[i] = s[i] != \"a\" ? \"a\" : \"b\"\r\n else\r\n s[i] = (if s[i] != \"z\" then \"z\" else \"y\" end)\r\n end\r\n end\r\n puts s\r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n s = gets.chomp\r\n s.length.times do |i|\r\n if i % 2 == 0\r\n s[i] = s[i] != \"a\" ? \"a\" : \"b\"\r\n else\r\n s[i] = s[i] != \"z\" ? \"z\" : \"y\"\r\n end\r\n end\r\n puts s\r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n s = gets.chomp\r\n s.length.times do |i|\r\n if i % 2 == 0\r\n s[i] = (if s[i] != \"a\" then \"a\" else \"b\" end)\r\n else\r\n s[i] = (if s[i] != \"z\" then \"z\" else \"y\" end)\r\n end\r\n end\r\n puts s\r\nend"}, {"source_code": "def test_case\r\n a=gets.chomp()\r\n i=0\r\n len=a.length()\r\n while i0)\r\n test_case\r\n t-=1\r\nend\r\n"}, {"source_code": "gets.strip.to_i.times {\r\n\ts = gets.strip\r\n\tt = 0\r\n\ts.length.times { |i|\r\n\t\tif t == 0\r\n\t\t\tprint s[i] == 'a' ? 'b' : 'a'\r\n\t\telse\r\n\t\t\tprint s[i] == 'z' ? 'y' : 'z'\r\n\t\tend\r\n\r\n\t\tt = 1 - t\r\n\t}\r\n\tprint \"\\n\"\r\n}"}], "negative_code": [], "src_uid": "c02357c4d959e300f970f66f9b3107eb"} {"source_code": "N = gets.to_i\narr = []\nN.times do\n _ = gets.to_i\n arr << gets.split.map(&:to_i)\nend\narr.each do |ar|\n pre = ar.count(0)\n puts ar.inject(:+) + pre == 0 ? pre + 1 : pre\nend", "positive_code": [{"source_code": "n = gets.to_i\n\nn.times do\n gets\n a = gets.split.map &:to_i\n step = a.count(0)\n sum = a.inject(:+) + step\n puts sum == 0 ? step + 1 : step\nend\n"}, {"source_code": "def solve()\n n = gets\n numbers = gets.split(\" \").each.map(&:to_i)\n changes = 0\n sum = 0\n numbers.each { |number|\n if number == 0\n changes = changes + 1;\n end\n sum = sum + number\n }\n\n if (sum + changes == 0)\n changes = changes + 1\n end\n\n\treturn changes\nend\n\nntest = gets\n\nntest.to_i.times { |nn|\n puts solve()\n}\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n sum = 0\n ans = 0\n\n a.each do |v|\n if v == 0\n v = 1\n ans += 1\n end\n\n sum += v\n end\n\n if sum == 0\n puts ans + 1\n else\n puts ans\n end\nend\n"}], "negative_code": [], "src_uid": "1ffb08fe61cdf90099c82162b8353b1f"} {"source_code": "n, m = gets.split.map(&:to_i)\ns = n.times.map{gets.chomp.chars}\nans = 0\n0.upto(n - 2) do |i|\n 0.upto(m - 2) do |j|\n c = []\n c << s[i][j] << s[i + 1][j] << s[i][j + 1] << s[i + 1][j + 1]\n ans += 1 if c.include?('f') && c.include?('a') && c.include?('c') && c.include?('e')\n end\nend\nputs ans\n", "positive_code": [{"source_code": "\nn, m = gets.chomp.split.map(&:to_i);\narr = Array.new;\ncount = 0;\n\nn.times {|i| arr[i] = gets.chomp.split('')};\n(n-1).times do |i|\n (m-1).times do |j|\n count += 1 if (arr[i][j] + arr[i][j + 1] + arr[i + 1][j] + arr[i + 1][j + 1]).chars.sort.join.eql?(\"acef\");\n end\nend\np count;\n"}, {"source_code": "h,w=gets.split.map{|e| e.to_i}\nstr=[]\nh.times{\n\tstr<= res[i+1]\n end\n s[res[1]..res[2]].count('|') + 4\nend\n\nputs solve(gets.strip.split(''))"}, {"source_code": "# Input\ns = gets\n\n# Processing\no_bracket = nil\no_colon = nil\n\ns.each_char.with_index do |chr, index|\n case chr\n when \"[\"\n o_bracket = index\n when \":\"\n if o_bracket\n o_colon = index\n break\n end\n else\n end\nend\n\nc_bracket = nil\nc_colon = nil\ns.each_char.reverse_each.with_index do |chr, index|\n case chr\n when \"]\"\n c_bracket = s.length - 1 - index\n when \":\"\n if c_bracket\n c_colon = s.length - 1 - index\n break\n end\n else\n end\nend\n\nunless o_colon && c_colon && o_colon < c_colon\n puts -1\n exit\nend\n\ninner = s.slice(o_colon + 1, c_colon - o_colon - 1)\nresult = 4 + inner.count(\"|\")\n\n# Output\nputs result\n"}, {"source_code": "s=gets\nbegin\nidx=s.index('[')\ns=s[idx+1..-1]\nidx=s.index(':')\ns=s[idx+1..-1]\nidx=s.rindex(']')\ns=s[0...idx]\nidx=s.rindex(':')\ns=s[0...idx]\np s.count('|')+4\nrescue\np -1\nend\n__END__\np gets=~/\\[.*?\\:(.*)\\:.*?\\]/ ? $1.count(?|)+4 : -1"}, {"source_code": "# revisar que si haya al menos un acordeon\n # contar apertura [:\n # contar numero de pipes desp\u00faes\n # contar ultima :] (desde atr\u00e1s maybe)\n\ndef accordion_length(s)\n open_bracket = false\n close_bracket = false\n first_colon_at = nil\n second_colon_at = nil\n pipe_counter = 0\n\n s.split('').each_with_index do |char, index|\n if char == '[' && !open_bracket\n open_bracket = true\n next\n end\n\n if char == ':' && open_bracket\n first_colon_at = index\n break\n end\n end\n\n return -1 unless first_colon_at\n\n (s.length-1).downto(first_colon_at + 1).each do |i|\n if s[i] == ']' && !close_bracket\n close_bracket = true\n next\n end\n\n if s[i] == ':' && close_bracket\n second_colon_at = i\n break\n end\n end\n\n return -1 unless second_colon_at\n\n s[first_colon_at..second_colon_at].split('').each do |char|\n pipe_counter += 1 and next if char == '|'\n end\n\n pipe_counter + 4\nend\n\ns = gets.rstrip\n\nresult = accordion_length s\nputs result\n\n\n"}], "negative_code": [{"source_code": "def solve(s)\n return -1 if s.size < 4\n res = ['[', ':'].map do |c|\n s.index(c)\n end.concat(\n [':', ']'].map do |c|\n s.rindex(c)\n end\n )\n return -1 if res.include?(nil) || res.uniq.size != res.size\n res.each_with_index do |e, i|\n break if i == res.size - 1\n return -1 if e >= res[i+1]\n end\n s[res[1]..res[2]].count('|') + 4\nend\n\nputs solve(gets.strip.split(''))"}, {"source_code": "DBG = !true\ns = gets.chomp\nputs \"s: #{s}\" if DBG\nn = s.size\nleftpar = -1\nfor i in 0...n\n if s[i] == '['\n leftpar = i\n break\n end\nend\nif leftpar == -1\n puts \"no leftpar\" if DBG\n puts \"-1\"\n exit\nend\n\nleftcol = -1\nfor i in (leftpar+1)...n\n if s[i] == ':'\n leftcol = i\n break\n end\nend\nif leftcol == -1\n puts \"no leftcol\" if DBG\n puts \"-1\"\n exit\nelse\n puts \"leftcol #{leftcol}\" if DBG\nend\n\nrightpar = -1\n(n-1).downto(leftcol+2) do |i|\n if s[i] == ']'\n rightpar = i\n break\n end\nend\nif rightpar == -1\n puts \"no rightpar\" if DBG\n puts \"-1\"\n exit\nend\n\nrightcol = -1\n(rightpar-1).downto(rightcol+1) do |i|\n if s[i] == ':'\n rightcol = i\n break\n end\nend\nif rightcol == -1\n puts \"no rightcol\" if DBG\n puts \"-1\"\n exit\nend\n\ncnt = 0\nfor i in (leftcol+1)..(rightcol-1)\n cnt += 1 if s[i] == '|'\nend\nputs \"#{cnt+4}\"\n"}, {"source_code": "DBG = !true\ns = gets.chomp\nputs \"s: #{s}\" if DBG\nn = s.size\nleftpar = -1\nfor i in 0...n\n if s[i] == '['\n leftpar = i\n break\n end\nend\nif leftpar == -1\n puts \"no leftpar\" if DBG\n puts \"-1\"\n exit\nend\n\nleftcol = -1\nfor i in (leftpar+1)...n\n if s[i] == ':'\n leftcol = i\n break\n end\nend\nif leftcol == -1\n puts \"no leftcol\" if DBG\n puts \"-1\"\n exit\nelse\n puts \"leftcol #{leftcol}\" if DBG\nend\n\nrightpar = -1\n(n-1).downto(leftcol+2) do |i|\n if s[i] == ']'\n rightpar = i\n break\n end\nend\nif rightpar == -1\n puts \"no rightpar\" if DBG\n puts \"-1\"\n exit\nend\n\nrightcol = -1\n(n-1).downto(rightcol+1) do |i|\n if s[i] == ':'\n rightcol = i\n break\n end\nend\nif rightcol == -1\n puts \"no rightcol\" if DBG\n puts \"-1\"\n exit\nend\n\ncnt = 0\nfor i in (leftcol+1)..(rightcol-1)\n cnt += 1 if s[i] == '|'\nend\nputs \"#{cnt+4}\"\n"}, {"source_code": "def accordion_length(s)\n opened = false\n colon_counter = 0\n accordion_length = 0\n accordion = false\n\n s.split('').each do |char|\n if char == '[' && !opened\n accordion_length += 1\n opened = true\n next\n end\n\n if char == ':' && opened && colon_counter < 2\n accordion_length += 1\n colon_counter += 1\n next\n end\n\n if char == '|' && colon_counter == 1\n accordion_length += 1\n next\n end\n\n if char == ']' && colon_counter == 2\n accordion_length += 1\n accordion = true\n break\n end\n end\n\n return -1 unless accordion\n accordion_length\nend\n\ns = gets.rstrip\n\nresult = accordion_length s\nputs result"}, {"source_code": "def accordion_length(s)\n opened = false\n colon_counter = 0\n accordion_length = 0\n accordion = false\n\n s.split('').each do |char|\n if char == '[' && !opened\n accordion_length += 1\n opened = true\n next\n end\n\n if char == ':' && opened && colon_counter < 2\n accordion_length += 1\n colon_counter += 1\n next\n end\n\n if char == '|' && colon_counter == 1\n accordion_length += 1\n next\n end\n\n if char == ']' && colon_counter == 2\n accordion_length += 1\n accordion = true\n end\n end\n\n return -1 unless accordion\n accordion_length\nend\n\ns = gets.rstrip\n\nresult = accordion_length s\nputs result"}], "src_uid": "915b4776a6b1fa15886247eb1ad40b60"} {"source_code": "# coding: utf-8\n\n# Even but not even\n# Sum(list_of_digits).even? == true\n# original_number.even? == false\nt = gets.to_i\nt.times {\n n = gets.to_i\n ar = gets.chomp.split(//).map(&:to_i)\n ar.delete_if { |i| i.even? }\n\n if ar.length <= 1\n puts \"-1\"\n else\n if ar.length.odd?\n ar.pop\n end\n\n puts ar.join('')\n end\n\n}", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n s = gets.chomp.chars.map(&:to_i)\n\n odds = []\n\n s.each do |d|\n next if d.even?\n\n odds << d\n end\n\n if odds.size <= 1\n puts -1\n else\n puts odds.take(2).join\n end\nend\n"}, {"source_code": "t = gets.to_i\nodd = [\"1\",\"3\",\"5\",\"7\",\"9\"]\neven = [\"2\",\"4\",\"6\",\"8\",\"0\"]\n\nt.times{\n n = gets.to_i\n s = gets.chomp\n sc = s.chars.map(&:to_i)\n sc.pop while sc != [] && sc.last.even?\n if sc == []\n p -1\n #puts \"because sc==[]\"\n next\n end\n n_odd = sc.count{|i|i.odd?}\n #puts \"s: #{s}, n_odd: #{n_odd}\"\n flag = false\n if n_odd.odd?\n #puts \"n_odd is odd\"\n [*0..sc.length-1].reverse.each{|i|\n #puts \"loop yeah!!\"\n if sc[i].odd? && flag\n sc.delete_at(i)\n break\n end\n flag = true if sc[i].odd?\n }\n end\n n_odd = sc.count{|i|i.odd?}\n if n_odd.odd?\n p -1\n #puts \"because n_odd.odd?\"\n next\n end\n if sc == [0]\n p -1\n #puts \"because sc==[0]\"\n else\n puts sc.join\n end\n}\n\n\n"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# Even but not even\n# Sum(list_of_digits).even? == true\n# original_number.even? == false\nt = gets.to_i\nt.times {\n n = gets.to_i\n odds = []\n gets.chomp.split(//).each { |c|\n i = c.to_i\n if i.odd?\n odds << i\n end\n }\n if odds.length <= 1\n puts \"-1\"\n else\n puts odds.join('')\n end\n}"}, {"source_code": "# coding: utf-8\n\n# Even but not even\n# Sum(list_of_digits).even? == true\n# original_number.even? == false\nt = gets.to_i\nt.times {\n n = gets.to_i\n cr = Array.new(10+1) { 0 }\n gets.chomp.split(//).each { |c|\n i = c.to_i\n cr[i] += 1\n }\n odds_unique = {}\n for ci in 1..10\n if ci.odd?\n if cr[ci] > 0\n odds_unique[ci] = true\n end\n end\n end\n\n if odds_unique.length <= 1\n puts \"-1\"\n else\n puts (odds_unique.keys[0..1]).join('')\n end\n}"}], "src_uid": "8f00837e04627e445dfb8b6cd0216640"} {"source_code": "n,k=gets.split.map(&:to_i)\nputs (n==k ? -1:(2..n).to_a.insert(n-k-1,1).join(' '))", "positive_code": [{"source_code": "n,k=gets.split.map(&:to_i)\nputs (n==k ? -1:(2..n).to_a.insert(n-k-1,1).join(' '))\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (n==k ? -1:(2..n).to_a.insert(n-k-1,1).join(' '))\n"}, {"source_code": "n, k = gets.split.map{|s| s.to_i}\n\nif n==k\n\tputs -1\n\texit\nend\n\nseq = Array.new(n+1) { |i| i }\nprimes = [2]\nnn = 2\ndif = n-1-k\nwhile dif > 1\n\tseq[nn], seq[nn+1] = seq[nn+1], seq[nn]\n\tnn+=2\n\tdif -= 2\nend\nif dif == 1\n\tseq[1] = nn\n\tseq[nn] = 1\nend\nseq[1..-1].each{|i| print \"#{i} \"}\n"}, {"source_code": "n,k=gets.chomp.split.map(&:to_i)\nif n==k\n\tputs \"-1\";exit\nend\nprint n-k\n(n-k-1).times{|i| print \" #{i+1}\"}\nfor i in n-k+1..n\n\tprint \" #{i}\"\nend\nputs"}, {"source_code": "class B\n def initialize\n n, k = gets.chomp.split(' ').map(&:to_i)\n count = n-1\n index = 1\n\n answer = (1..n).to_a\n\n if n <= k\n puts -1\n exit\n end\n\n if ( (count.odd? && k.even?) || (count.even? && k.odd? ) )\n answer[0], answer[1] = answer[1], answer[0]\n count -= 1\n index = 2\n end\n\n while count != k && index < n\n answer[index], answer[index+1] = answer[index+1], answer[index]\n count -= 2\n index += 2\n end\n\n if count == k\n puts answer.join(' ')\n else\n puts -1\n end\n end\nend\n\nb = B.new"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (n==k ? -1:(2..n).to_a.insert(n-k-1,1).join(' '))\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (n==k ? -1:(2..n).to_a.insert(n-k-1,1).join(' '))\n"}, {"source_code": "n, k = gets.strip.split(' ').map(&:to_i)\n\nif n == k\n puts \"-1\"\n exit\nend\n\narr = (1..n).to_a\nck = n - 1\narr.each_with_index { |e , i|\n break if ck == k\n arr[0], arr[n - i - 1] = arr[n - i - 1], arr[0]\n ck -= 1\n}\n\nputs arr.join(' ')\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (n==k ? -1:(2..n).to_a.insert(n-k-1,1).join(' '))\n"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\nbad = n - k\nperm = (2..bad).to_a\nperm.push(1)\nperm.push(*((bad+1)..(bad+k)))\nif n == k\n\tputs \"-1\"\nelse\nputs perm.join(\" \")\nend"}, {"source_code": "n, k = gets.chomp.split(' ').collect {|x| x.to_i}\n\nq = n-k\n\nif q < 1\n puts -1\nelsif q == 1\n puts (1..n).to_a.join ' '\nelse\n arr = (1..(q-1)).to_a\n arr = [q] + arr\n arr = arr + ((q+1)..n).to_a\n puts arr.join ' '\nend"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (n==k ? -1:(2..n).to_a.insert(n-k-1,1).join(' '))"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (n==k ? -1:(2..n).to_a.insert(n-k-1,1).join(' '))\n"}, {"source_code": "n, k = gets.split.map { |x| x.to_i }\nif n == k\n puts -1\n exit\nend\n\na = Array.new(n)\n((k + n) % 2 == 0 ? [n - k...n, 1..n - k] : [0..k, k + 2...n]).\n zip([1, 2], [lambda { |i| a[i] = i + 1 }, lambda { |i| a[i - 1] = i + 1; a[i] = i }]) { |r, st, f| r.step st, &f }\nputs a * ' '"}, {"source_code": "line = gets.chomp.split(\" \").map { |e| e.to_i }\nn = line[0]\nk = line[1]\n\nif n == k\n puts \"-1\"\nelsif n == k + 1\n for i in 1..n\n print(i.to_s + \" \")\n end\n puts\nelse\n print((k+2).to_s + \" \")\n for i in 2..n\n if i != k+2\n print(i.to_s + \" \")\n end\n end\n print(\"1\\n\")\nend\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (n==k ? -1:(2..n).to_a.insert(n-k-1,1).join(' '))\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (n==k ? -1:(2..n).to_a.insert(n-k-1,1).join(' '))\n"}], "negative_code": [{"source_code": "class B\n def initialize\n n, k = gets.chomp.split(' ').map(&:to_i)\n count = n-1\n\n answer = (1..n).to_a\n\n if n <= k\n puts -1\n exit\n end\n\n if k.even?\n answer[0], answer[1] = answer[1], answer[0]\n count -= 1\n end\n\n index = 2\n while count != k && index < n\n answer[index], answer[index+1] = answer[index+1], answer[index]\n count -= 2\n index += 2\n end\n\n if count == k\n puts answer.join(' ')\n else\n puts -1\n end\n end\nend\n\nb = B.new\n"}, {"source_code": "class B\n def initialize\n n, k = gets.chomp.split(' ').map(&:to_i)\n count = n-1\n index = 1\n\n answer = (1..n).to_a\n\n if n <= k\n puts -1\n exit\n end\n\n if !k.zero? && ( (count.odd? && k.even?) || (count.even? && k.odd? ) )\n answer[0], answer[1] = answer[1], answer[0]\n count -= 1\n index = 2\n end\n\n while count != k && index < n\n answer[index], answer[index+1] = answer[index+1], answer[index]\n count -= 2\n index += 2\n end\n\n if count == k\n puts answer.join(' ')\n else\n puts -1\n end\n end\nend\n\nb = B.new"}, {"source_code": "class B\n def initialize\n n, k = gets.chomp.split(' ').map(&:to_i)\n count = n-1\n index = 1\n\n answer = (1..n).to_a\n\n if n <= k\n puts -1\n exit\n end\n\n if !k.zero? && ( (count.odd? && k.even?) || (count.even? && k.odd? ) )\n answer[0], answer[1] = answer[1], answer[0]\n count -= 1\n index = 2\n end\n\n while count != k && index < n\n answer[index], answer[index+1] = answer[index+1], answer[index]\n count -= 2\n index += 2\n end\n\n if count == k\n puts answer.join(' ')\n else\n puts -1\n end\n end\nend\n\nb = B.new"}, {"source_code": "n, k = gets.strip.split(' ').map(&:to_i)\n\nif n == k\n puts \"-1\"\n exit\nend\n\narr = (1..n).to_a\nck = n - 1\narr.each_with_index { |e , i|\n break if ck == k\n i += 1 if i.odd?\n arr[i], arr[n - 1] = arr[n - 1], arr[i]\n ck -= 1\n}\n\nputs arr.join(' ')\n"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\nbad = n - k\nperm = (2..bad).to_a\nperm.push(1)\nperm.push(*((bad+1)..(bad+k)))\nif n == 1\n\tputs \"-1\"\nelse\nputs perm.join(\" \")\nend"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\nbad = n - k\nperm = (2..bad).to_a\nperm.push(1)\nperm.push(*((bad+1)..(bad+k)))\nif n == 1 && k == 1\n\tputs \"-1\"\nelse\nputs perm.join(\" \")\nend"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\nbad = n - k\nperm = (1..bad).to_a\nperm.push(*((bad+2)..(bad+k)))\nperm.push(bad+1)\nif n == 1\n\tputs \"-1\"\nelse\nputs perm.join(\" \")\nend"}], "src_uid": "dc548fe1d8683b4b0ee4e0fa67638185"} {"source_code": "tt = gets.chomp.to_i\ntt.times.map do\n str, int, exp = gets.split.map(&:to_i)\n diff = str - int\n\n cnt = 0\n if diff<0\n exp += diff\n if exp<=0\n else\n cnt+=(exp+1)/2\n end\n elsif diff==0\n cnt+=(exp+1)/2\n else\n if exp < diff\n cnt+=exp+1\n else\n cnt+=(exp+diff+1)/2\n end\n end\n\n puts cnt\nend\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\n\nt.times do |i|\n str, int, exp = gets.chomp.split.map(&:to_i)\n diff = str + exp - int\n if diff <= 0\n puts 0\n else\n puts [(diff+1)/2, exp+1].min\n end\nend\n"}, {"source_code": "gets.to_i.times do\n s,t,e = gets.split.map(&:to_i)\n if s+e <= t\n puts 0\n else\n b = (t+e-s)/2\n puts e-(b > -2 ? b : -1)\n end\nend"}, {"source_code": "t = STDIN.readline.to_i\n\nt.times {\n str, int, exp = STDIN.readline.split.map &:to_i\n if str+exp <= int\n p 0\n next\n end\n\n if (d = int-str) > 0\n str = int\n exp -= d\n end\n\n int += exp\n i = (0..exp).bsearch do |e|\n str+e > int-e\n end\n p exp-i+1\n}\n"}], "negative_code": [{"source_code": "gets.to_i.times do\n s,t,e = gets.split.map(&:to_i)\n if s+e <= t\n puts 0\n else\n puts s+e-(s+(t+e-s)/2)\n end\nend"}, {"source_code": "gets.to_i.times do\n s,t,e = gets.split.map(&:to_i)\n if s+e <= t\n puts 0\n else\n b = (t+e-s)/2\n if e > 0\n puts e-(b > 0 ? b : 0)\n else\n puts 1\n end\n end\nend"}, {"source_code": "t = gets.chomp.to_i\n\nt.times do |i|\n str, int, exp = gets.chomp.split.map(&:to_i)\n # str + a > int + b\n # a + b = exp\n # str + exp > int + 2b\n # 2b <= str + exp - int + 1\n # b >= 0\n diff = [str + exp - int + 1, 0].max\n puts diff/2\nend\n"}, {"source_code": "t = gets.chomp.to_i\n\nt.times do |i|\n str, int, exp = gets.chomp.split.map(&:to_i)\n cut = (exp+int-str)/2 + 1\n puts [exp-cut+1, 0].max\nend\n"}, {"source_code": "t = gets.chomp.to_i\n\nt.times do |i|\n str, int, exp = gets.chomp.split.map(&:to_i)\n diff = str + exp - int\n if diff <= 0\n puts 0\n else\n puts (diff+1)/2\n end\nend\n"}], "src_uid": "0816295355375a2d3f1cd45852b86360"} {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2 [\"a\",\"b\",\"c\"]\n#String # to_ia\n# \"1 2 3\".to_ia #=> [1,2,3]\n#\n\ninclude Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInf = Float::INFINITY\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\nn, q = getia\nc = [0] * 2000\nn.times do\n a, b = getia.sort\n for i in a..b\n c[i] += 1\n end\nend\nres = Inf\nfor i in 0..1010\n if c[i] == n\n res = [(i-q).abs, res].min\n end\nend\nputs res == Inf ? -1 : res\n", "positive_code": [{"source_code": "ns,ms = gets.chomp.split(/ /)\nn = ns.to_i\nm = ms.to_i\n\nmx1 = -1\nmx2 = 1001\nfor i in 0..n-1\n\tx1s, x2s = gets.chomp.split(/ /)\n\tx1 = x1s.to_i\n\tx2 = x2s.to_i\n\tax = [x1,x2].max\n\tix = [x1,x2].min\n\tmx1 = [mx1, ix].max\n\tmx2 = [mx2, ax].min\nend\nif mx1 > mx2\n\tputs \"-1\"\nelse\n\tret = 0\n\tif m < mx1 || m > mx2\n\t\tret= [(mx1-m).abs, (mx2-m).abs].min\n\tend\n\tputs ret\nend\n"}, {"source_code": "class Range\n\tdef ^(other)\n\t\t([first, other.first].max .. [last, other.last].min)\n\tend\nend\n\nn, x0 = gets.split.map{|i| i.to_i}\nr = []\nn.times do\n\ta, b = gets.split.map{|i| i.to_i}\n\ta, b = b, a if a > b\n\tr <<= (a .. b)\nend\nr = r.inject{|i, j| i ^ j}\n\nunless r.first <= r.last then\n\tp -1\nelse\n\tp r.include?(x0) ? 0 : [(r.first - x0).abs, (r.last - x0).abs].min\nend\n"}, {"source_code": "n,x=gets.split.map(&:to_i)\nsum=Array.new(1002,0)\ntsum=Array.new(1002,0)\nn.times{\n a,b=gets.split.map(&:to_i).sort\n b+=1\n tsum[a]+=1\n tsum[b]-=1\n}\nsum[0]=tsum[0]\nans=[]\nans.push(x) if sum[0]==n\n1.upto(1001){|i|\n sum[i]=sum[i-1]+tsum[i]\n if sum[i]==n then\n ans.push((x-i).abs)\n end\n}\nans.push(-1) if ans.size()==0\n\np ans.min\n\n"}, {"source_code": "n,x = gets.split.map(&:to_i)\nlmax = 0\nrmin = 1000\nn.times do |i|\n a,b = gets.split.map(&:to_i)\n if a > b then a,b = b,a end\n if a > lmax then lmax = a end\n if b < rmin then rmin = b end\nend\n#p lmax\n#p rmin\nif rmin < lmax then\n print -1\n elsif x < lmax then\n print lmax - x\n elsif x > rmin then\n print x - rmin\n else\n print 0\nend\nputs\n\n"}, {"source_code": "n, x = gets.split.map(&:to_i)\n\nseg_start = 0\nseg_end = 1000\nn.times do\n\ta, b = gets.split.map(&:to_i)\n\ta, b = b, a if a > b\n\tseg_start = a if a > seg_start\n\tseg_end = b if b < seg_end\nend\n\nif seg_end < seg_start\n\tputs -1\nelsif seg_start < x && x < seg_end\n\tputs 0\nelse\n\tputs [(seg_start - x).abs, (seg_end - x).abs].min\nend\n\n# require 'set'\n# n, x = gets.split.map(&:to_i)\n\n# input = []\n# n.times do\n# \tinput << gets.split.map(&:to_i)\n# end\n\n# interval = (input[0].min..input[0].max).to_set\n# input.each do |segment|\n# \tinterval = interval & (segment.min..segment.max).to_set\n# end\n# if interval.empty?\n# \tputs -1\n# else\n# \tputs interval.include?(x) ? 0 : [(interval.min - x).abs, (interval.max - x).abs].min \n# end\n"}, {"source_code": "require 'set'\nn, x = gets.chomp!.split.map(&:to_i)\n\ninput = []\nn.times do\n\tinput << gets.chomp!.split.map(&:to_i)\nend\n\ninterval = (input[0].min..input[0].max).to_set\ninput.each do |segment|\n\tinterval = interval & (segment.min..segment.max).to_set\nend\nif interval.empty?\n\tputs -1\nelse\n\tputs interval.include?(x) ? 0 : [(interval.min - x).abs, (interval.max - x).abs].min \nend"}, {"source_code": "n,x = gets.split(\" \").map(&:to_i)\nstart = -1\nfinish = 2000\nn.times do\n\ta,b = gets.split(\" \").map(&:to_i).minmax\n\tstart = a if a > start\n\tfinish = b if b < finish\nend\nans = (start..finish).map{|a| (a-x).abs }.min\nans ||= -1\n# puts \"#{start} #{finish}\"\nputs \"#{ans}\"\n\n# 3 3\n# 0 7\n# 8 10\n# 11 13"}, {"source_code": "n,d = gets.chomp!.split.map(&:to_i)\nleft,right = -1,1001\nn.times do |x|\n a,b = gets.chomp!.split.map(&:to_i) \n a,b = [a,b].min,[a,b].max\n left = a if a > left\n right = b if b < right\nend\n\nans = [left > d ? left-d : 0, right < d ? d-right : 0].max\nans = -1 if left > right\nputs ans"}, {"source_code": "#!/usr/bin/env ruby\n\nn, x0 = gets.split.map(&:to_i)\nx, y = -1000, 1000\nn.times do\n\ta, b = gets.split.map(&:to_i)\n\ta, b = b, a if a > b\n\tx, y = [x, a].max, [y, b].min\nend\nputs x > y ? -1 : (x <= x0 && x0 <= y ? 0 : [x - x0, x0 - y].max)\n"}], "negative_code": [{"source_code": "ns,ms = gets.chomp.split(/ /)\nn = ns.to_i\nm = ms.to_i\n\nret = 0\nfor i in 0..n-1\n\tx1s, x2s = gets.chomp.split(/ /)\n\tx1 = x1s.to_i\n\tx2 = x2s.to_i\n\tax = [x1,x2].max\n\tix = [x1,x2].min\n\tif m < ix\n\t\tret = [ix-m, ret].max\n\tend\n\tif m > ax\n\t\tret = [m-ax, ret].max\n\tend\nend\nputs ret\n"}, {"source_code": "ns,ms = gets.chomp.split(/ /)\nn = ns.to_i\nm = ms.to_i\n\nret = -1\nfor i in 0..n-1\n\tx1s, x2s = gets.chomp.split(/ /)\n\tx1 = x1s.to_i\n\tx2 = x2s.to_i\n\tax = [x1,x2].max\n\tix = [x1,x2].min\n\tif m < ix\n\t\tret = [ix-m, ret].max\n\tend\n\tif m > ax\n\t\tret = [m-ax, ret].max\n\tend\nend\nputs ret\n"}, {"source_code": "ns,ms = gets.chomp.split(/ /)\nn = ns.to_i\nm = ms.to_i\n\nmx1 = -1\nmx2 = 1001\nfor i in 0..n-1\n\tx1s, x2s = gets.chomp.split(/ /)\n\tx1 = x1s.to_i\n\tx2 = x2s.to_i\n\tax = [x1,x2].max\n\tix = [x1,x2].min\n\tmx1 = [mx1, ix].max\n\tmx2 = [mx2, ax].min\nend\nif mx1 > mx2\n\tputs \"-1\"\nelse\n\tputs [(mx1-m).abs, (mx2-m).abs].min\nend\n"}, {"source_code": "class Range\n\tdef ^(other)\n\t\tRange.new([first, other.first].max, [last, other.last].min)\n\tend\nend\n\nn, x0 = gets.split.map{|i| i.to_i}\nr = []\nn.times do\n\ta, b = gets.split.map{|i| i.to_i}\n\ta, b = b, a if a > b\n\tr <<= (a .. b)\nend\nr = r.inject{|i, j| i ^ j}\n\nunless r.first < r.last then\n\tp -1\nelse\n\tp r.include?(x0) ? 0 : [(r.first - x0).abs, (r.last - x0).abs].min\nend\n"}, {"source_code": "n,d = gets.chomp!.split.map(&:to_i)\nleft,right = [],[]\nn.times do |x|\n a,b = gets.chomp!.split.map(&:to_i) \n left << [a,b].min\n right << [a,b].max\nend\n\nans1 = left.max > d ? left.max - d : 0\nans2 = right.min < d ? d - right.min : 0\nputs [ans1,ans2].max"}, {"source_code": "#!/usr/bin/env ruby\n\nn, x0 = gets.split.map(&:to_i)\nmn, mx = x0, x0 \nn.times do\n\ta, b = gets.split.map(&:to_i)\n\ta, b = b, a if a > b\n\tmx = [mx, a].max if a > x0\n\tmn = [mn, b].min if b < x0\nend\nputs mx - mn + [x0 - mn, mx - x0].min\n"}], "src_uid": "3c066bad8ee6298b318bf0f4521c7c45"} {"source_code": "#!ruby\n\nstr = STDIN.gets.strip\nk = STDIN.gets.strip.to_i\n\ncharnums = Hash.new(0)\n\nstr.each_byte do |c|\n charnums[c] += 1\nend\n\ndelchar = []\n\ncharnums.to_a.sort do |a,b|\n (a[1] <=> b[1]) * 2 + (b[0] <=> a[0]) \nend.each do |elem|\n if elem[1] <= k\n delchar << elem[0]\n k -= elem[1]\n else\n break\n end\nend\n\ndelchar.each do |c|\n str.delete!(\"%c\"%c)\nend\n\nputs str.unpack(\"C*\").uniq.length\nputs str\n", "positive_code": [{"source_code": "s = gets.chomp\nn = gets.to_i\na = s.split(//).uniq\nb = []\na.each { |x| b << s.count(x) }\nwhile (n - b.min) >= 0\n n -= b.min\n s.delete!(a[b.index(b.min)])\n b[b.index(b.min)] = 9999999999999999\n break if s.empty? || b.empty?\nend\nputs s.split(//).uniq.size\nputs s"}], "negative_code": [{"source_code": "#!ruby\n\nstr = STDIN.gets.strip\nk = STDIN.gets.strip.to_i\n\ncharnums = Hash.new(0)\n\nstr.each_byte do |c|\n charnums[c] += 1\nend\n\ndelchar = []\n\ncharnums.to_a.sort do |a,b|\n (a[1] <=> b[1]) * 2 + (b[0] <=> a[0]) \nend.each do |elem|\n if elem[1] < k\n delchar << elem[0]\n k -= elem[1]\n else\n break\n end\nend\n\ndelchar.each do |c|\n str.delete!(\"%c\"%c)\nend\n\nputs str.unpack(\"C*\").uniq.length\nputs str\n"}], "src_uid": "f023111561605b3e44ca85cb43b4aa00"} {"source_code": "n = gets.to_i\n\nflip = ->(s) { s.each_char.map { |c| c == '+' ? '*' : '+'}.join }\n\nif n == 0 then\n puts \"+\"\nelse\n ans = []\n ans[1] = [\"++\", \"+*\"]\n\n (2..n).each do |i|\n k = 2**i\n ans[i] = ans[i - 1].dup\n (k/2).times do |j|\n if j.even? then\n ans[i][j] += flip.(ans[i][j])\n else\n ans[i][j] += ans[i][j]\n end\n end\n (k/2).times do |j|\n ans[i] << ans[i - 1][j].reverse\n end\n ((k/2)...k).each do |j|\n if j.odd? then\n ans[i][j] = flip.(ans[i][j]) + ans[i][j]\n else \n ans[i][j] = ans[i][j] + ans[i][j]\n end\n end\n end\n\n puts ans[n]\nend\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\n\nas = ['+']\n\ndef f(as)\n bs = []\n as.each do |a|\n b = ''\n for i in 0...a.size\n if a[i] == '+'\n b += '++'\n else\n b += '**'\n end\n end\n bs << b\n end\n as.each do |a|\n b = ''\n for i in 0...a.size\n if a[i] == '+'\n b += '+*'\n else\n b += '*+'\n end\n end\n bs << b\n end\n return bs\nend\n\nfor i in 1..n\n as = f(as)\nend\n\nputs as.*\"\\n\"\n"}], "negative_code": [], "src_uid": "4e25d49e8a50dacc1cfcc9413ee83db6"} {"source_code": "gets \" \"\nxs = gets.split.map(&:to_i).sort\ngets \" \"\nys = gets.split.map(&:to_i).sort\ngets \" \"\nzs = gets.split.map(&:to_i).sort\na,b = gets.split.map(&:to_i)\n\n#p [a,b]\n#r1 = xs.max\np1 = ys.max\np2 = zs.min\n\nfor r1 in xs.reverse\n r2 = r1/Math::sqrt(1.0*a/b*p2/p1+1)\n #p [r1,r2,p1,p2]\n #p p1*(1.0*r1*r1/r2/r2 - 1)/p2\n break puts r2 if r2 < r1\nend\n", "positive_code": [{"source_code": "r1 = gets.split.map(&:to_f).slice!(1..-1).max\nro1 = gets.split.map(&:to_f).slice!(1..-1).max\nro2 = gets.split.map(&:to_f).slice!(1..-1).min\na, b = gets.split.map(&:to_f)\n\nputs Math.sqrt((r1*r1*b*ro1)/(b*ro1+a*ro2))"}, {"source_code": "r1 = gets.split.map(&:to_f).slice!(1..-1).max\nro1 = gets.split.map(&:to_f).slice!(1..-1).max\nro2 = gets.split.map(&:to_f).slice!(1..-1).min\na, b = gets.split.map(&:to_f)\n\nputs Math.sqrt((r1*r1*b*ro1)/(b*ro1+a*ro2))"}, {"source_code": "x = gets.split.map(&:to_i)[1..-1].max\ny = gets.split.map(&:to_i)[1..-1].max\nz = gets.split.map(&:to_i)[1..-1].min\nA, B = gets.split.map(&:to_i)\np Math.sqrt((x * x * y * B * 1.0 ) / (A * z + y * B))\n"}, {"source_code": "a=gets.split.map(&:to_i)[1..-1].max;\nb=gets.split.map(&:to_i)[1..-1].max;\nc=gets.split.map(&:to_i)[1..-1].min;\nd,e=gets.split.map &:to_f;\np (a*a*b*e/(c*d+b*e))**0.5"}], "negative_code": [], "src_uid": "18b1814234b05bae56ea4446506b543b"} {"source_code": "n = gets.chomp.to_i\n\ndef adjacent?(a,b)\n (a.ord - b.ord).abs == 1\nend\n\ndef order(str)\n a, b = str.split(//).sort.partition {|c| c.ord.odd? }\n if a.empty? || b.empty?\n a.join + b.join\n elsif !adjacent?(a.first, b.last)\n b.join + a.join\n elsif !adjacent?(a.last, b.first)\n a.join + b.join\n else\n 'No answer'\n end\nend\n\nn.times do\n str = gets.chomp\n puts order(str)\nend\n", "positive_code": [{"source_code": "t = gets.to_i\nt.times do \n s = gets.strip.chars.sort.join\n t = ''\n stk = []\n iter = 0\n until s.empty? && stk.empty?\n unless stk.empty?\n c = stk.shift\n if t.empty? || (t[-1].ord - c.ord).abs != 1\n t += c\n elsif (t[0].ord - c.ord).abs != 1\n t = c + t\n else\n stk.push(c)\n end\n end\n unless s.empty?\n c = s[0]\n s = s[1..-1]\n if t.empty? || (t[-1].ord - c.ord).abs != 1\n t += c\n elsif (t[0].ord - c.ord).abs != 1\n t = c + t\n else\n stk.push(c)\n end\n end\n iter += 1\n if iter == 2000\n t = \"No answer\"\n break\n end\n end\n puts t\nend\n"}, {"source_code": "alphabet = {\"a\"=>0,\"b\"=>1,\"c\"=>2,\"d\"=>3,\"e\"=>4,\"f\"=>5,\"g\"=>6,\"h\"=>7,\"i\"=>8,\"j\"=>9,\"k\"=>10,\"l\"=>11,\"m\"=>12,\"n\"=>13,\"o\"=>14,\"p\"=>15,\"q\"=>16,\"r\"=>17,\"s\"=>18,\"t\"=>19,\"u\"=>20,\"v\"=>21,\"w\"=>22,\"x\"=>23,\"y\"=>24,\"z\"=>25}\n\nn = gets.to_i\n\nn.times do\n cnt = [0]*26\n kind = []\n s = gets.chomp\n s.each_char do |c|\n cnt[alphabet[c]] += 1\n kind << alphabet[c]\n end\n\n kind.uniq!\n kind.sort!\n l = kind.length\n ans = [\"\"]*26\n if l == 2\n replace = [0,1]\n elsif l == 3\n replace = (kind[1] - kind[0] == 1) ? [0,2,1] : [1,0,2]\n elsif l == 4\n replace = [1,3,0,2]\n else\n replace = []*l\n t = [(l+2)/3,(l+1)/3,l/3]\n k = 0\n 3.times do |i|\n t[i].times do |j|\n replace[j*3+i] = j + k\n end\n k += t[i]\n end\n end\n replace.each_with_index do |v,i|\n ans[v] = alphabet.key(kind[i]) * cnt[kind[i]]\n end\n\n ans = ans.join\n (s.length-1).times do |i|\n if (alphabet[ans[i]] - alphabet[ans[i+1]]).abs == 1\n ans = \"No answer\"\n break\n end\n end\n puts ans\nend\n"}, {"source_code": "gets.to_i.times do\n a,b=gets.chomp.chars.sort.partition{|e|e.ord.odd?}.map(&:join)\n ok=->x,y{ x.empty? or y.empty? or (x[-1].ord-y[0].ord).abs!=1 }\n puts (ok[a, b] ? a+b : ok[b, a] ? b+a : \"No answer\")\nend"}], "negative_code": [{"source_code": "alphabet = {\"a\"=>0,\"b\"=>1,\"c\"=>2,\"d\"=>3,\"e\"=>4,\"f\"=>5,\"g\"=>6,\"h\"=>7,\"i\"=>8,\"j\"=>9,\"k\"=>10,\"l\"=>11,\"m\"=>12,\"n\"=>13,\"o\"=>14,\"p\"=>15,\"q\"=>16,\"r\"=>17,\"s\"=>18,\"t\"=>19,\"u\"=>20,\"v\"=>21,\"w\"=>22,\"x\"=>23,\"y\"=>24,\"z\"=>25}\n\nn = gets.to_i\nreplace = [2,0,3,1]\nn.times do\n cnt = [0]*26\n kind = []\n s = gets.chomp\n s.each_char do |c|\n cnt[alphabet[c]] += 1\n kind << alphabet[c]\n end\n t = 0\n\n kind.uniq!\n kind.sort!\n\n ans = [\"\"]*26\n if kind.length == 3\n [0,2,1].each_with_index do |v,i|\n ans[v] = alphabet.key(kind[i]) * cnt[kind[i]]\n end\n else\n 26.times do |i|\n if cnt[i] > 0\n ans[(t/4)*4 + replace[t%4]] = alphabet.key(i) * cnt[i]\n t += 1\n end\n end\n end\n #p ans\n ans = ans.join\n (s.length-1).times do |i|\n if (alphabet[ans[i]] - alphabet[ans[i+1]]).abs == 1\n ans = \"No answer\"\n break\n end\n end\n puts ans\nend\n"}, {"source_code": "alphabet = {\"a\"=>0,\"b\"=>1,\"c\"=>2,\"d\"=>3,\"e\"=>4,\"f\"=>5,\"g\"=>6,\"h\"=>7,\"i\"=>8,\"j\"=>9,\"k\"=>10,\"l\"=>11,\"m\"=>12,\"n\"=>13,\"o\"=>14,\"p\"=>15,\"q\"=>16,\"r\"=>17,\"s\"=>18,\"t\"=>19,\"u\"=>20,\"v\"=>21,\"w\"=>22,\"x\"=>23,\"y\"=>24,\"z\"=>25}\n\nn = gets.to_i\nreplace = [1,3,0,2]\nn.times do\n cnt = [0]*26\n s = gets.chomp\n s.each_char do |c|\n cnt[alphabet[c]] += 1\n end\n t = 0\n ans = [\"\"]*26\n 26.times do |i|\n if cnt[i] > 0\n ans[(t/4)*4 + replace[t%4]] = alphabet.key(i) * cnt[i]\n t += 1\n end\n end\n #p ans\n ans = ans.join\n (s.length-1).times do |i|\n if (alphabet[ans[i]] - alphabet[ans[i+1]]).abs == 1\n ans = \"No answer\"\n break\n end\n end\n puts ans\nend\n"}], "src_uid": "d62d0a9d827444a671029407f6a4ad39"} {"source_code": "n, m, x = gets.split.map(&:to_i)\nkeys = Hash.new { |hash, key| hash[key] = :unknown }\n\nhaveShift = false\narr = Array.new\n(0...n).each do |i|\n l = gets.chomp\n l.chars.each { |e| keys[e] = :down if e != 'S'\n haveShift = true if e == 'S' }\n arr << l\nend\n\n(0...n).each do |i|\n(0...m).each do |j|\nif arr[i][j] == 'S'\n1.upto(x) do |k|\n ((i - k)..(i + k)).each do |ii|\n ((j - k)..(j + k)).each do |jj|\n if ii >= 0 && ii < n && jj >= 0 && jj < m\n dy, dx = [(ii - i) * (ii - i), (jj - j) * (jj - j)]\n keys[arr[ii][jj]] = :up if arr[ii][jj] != 'S' && Math.sqrt(dy + dx) <= x\n end\n end\n end\nend\nend\nend\nend\n\ngets\n\nret = 0\ngets.chomp.chars.each do |t|\n if !keys.has_key?(t.downcase) || ((t >= 'A' && t <= 'Z') && !haveShift)\n ret = -1\n break\n end\n if (t >= 'A' && t <= 'Z') && keys[t.downcase] == :down\n ret += 1\n end\nend\n\nputs ret", "positive_code": [{"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y].chr] = true\n \n if (s[x][y].chr == 'S') then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j].chr] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets; t.chop!\n \n \n t.each_char{|a|\n return -1 if a < 'a'\n } if !h['S']\n \n res = 0\n \n t.each_char{|a|\n if (a < 'a') then\n a.downcase!\n return -1 if (!h[a])\n res += 1 if (!h_[a])\n else\n return -1 if (!h[a])\n end\n }\n \n return res\nend\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "class Point\n\tattr_accessor :x\n\tattr_accessor :y\n \n\tdef initialize(x1,y1)\n \t@x = x1.to_f\n \t@y = y1.to_f\n \tend\n\n\tdef distance_to(x1,y1)\n \tdx = @x - x1\n \tdy = @y - y1\n \td = Math.sqrt(dx * dx + dy * dy)\n \treturn(d)\n \tend\nend\n\nn,m,xx = gets.chomp.split(/ /).map!{|x| x.to_i}\nbbb = []\nsss = []\nmmm = Hash::new\nmmm.default = -1\nfor i in 0..n-1\n\tbbb.push(gets.chomp)\n\tfor j in 0..m-1\n\t\tsss.push(Point.new(j,i)) if bbb[i][j] == \"S\"\n\tend\nend\n\nfor i in 0..n-1\n\tfor j in 0..m-1\n\t\tif bbb[i][j] != \"S\" then\n\t\t\twk = mmm[bbb[i][j]]\n\t\t\tsss.each{|x| \n\t\t\t\twk2 = x.distance_to(j,i)\n\t\t\t\tif wk < 0 then\n\t\t\t\t\twk = wk2\n\t\t\t\telse\n\t\t\t\t\twk = wk2 if wk > wk2\n\t\t\t\tend\n\t\t\t}\n\t\t\tmmm[bbb[i][j]] = wk\n\t\tend\n\tend\nend\nq = gets.chomp.to_i\nt = gets.chomp\n\nret = 0\nt.each_byte{|x|\n\tx = x.chr\n\tif mmm.key?(x.downcase) == false then\n\t\tret = -1\n\t\tbreak\n\tend\n\tif x.upcase == x then\n\t\tx.downcase!\n\t\tif mmm[x] < 0 then\n\t\t\tret = -1\n\t\t\tbreak\n\t\tend\n\t\tret += 1 if xx < mmm[x] \n\tend\n}\n\nputs ret\n"}, {"source_code": "def func\n n, m, x = gets.split.map(&:to_i)\n\n has_shift = false\n kb=[]\n n.times{\n l = gets.chomp\n kb << l\n has_shift |= (l =~ /S/)\n }\n alphabets = (kb * '').gsub('S', '')\n\n need_two = {}\n n.times{|y1|\n m.times{|x1|\n next if kb[y1][x1] != ?S\n n.times{|y2|\n m.times{|x2|\n c = kb[y2][x2]\n next if c == ?S\n\n dist2 = (y2-y1)**2 + (x2-x1)**2\n need_two[c] = [need_two[c] || 99999999, dist2].min\n }\n }\n }\n }\n\n need_two.each do |k, v|\n need_two[k] = v > x * x\n end\n #p need_two\n\n q = gets.to_i\n str = gets.chomp\n\n ok = true\n str.each_char do |c|\n if !alphabets.index(c.downcase)\n ok = false\n break\n end\n\n if c =~ /[A-Z]/ && !has_shift\n ok = false\n break\n end\n end\n if !ok\n return -1\n end\n\n cnt = 0\n str.each_char do |c|\n if c =~ /[a-z]/\n next\n end\n\n if need_two[c.downcase[0]]\n cnt += 1\n end\n end\n cnt\nend\n\np func\n"}, {"source_code": "count = 0\no = \"a\".ord\nn, m, x = gets.strip.split.map{|s| s.to_i}\nkb = []\nshifts = []\nall_keys = {}\nclose_keys = {}\ndistant_keys = {}\nn.times do |i|\n line = gets.strip.split(//).map do |s|\n s.ord\n end\n line.each_with_index do |s, j|\n if s == \"S\".ord\n shifts << [i, j]\n else\n all_keys[s] = true\n end\n end\n kb << line\nend\nshifts.each do |shift|\n kb.each_with_index do |line, i|\n line.each_with_index do |key, j|\n next if key == \"S\"\n if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x\n distant_keys[key] = true\n else\n close_keys[key] = true\n end\n end\n end\nend\nclose_keys.each_key{|c| distant_keys.delete(c)}\ngets\ngets.strip.each_char.with_index do |c, i|\n u = c.ord < o\n c_ord = c.downcase.ord\n unless all_keys[c_ord]\n puts -1\n exit\n end\n if u\n if shifts.empty?\n puts -1\n exit\n end\n if distant_keys[c_ord]\n count += 1\n end\n end\nend\nputs count\n"}], "negative_code": [{"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y]] = true\n \n if (s[x][y] == 'S') then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets; t.chop!\n \n\n=begin\n if (t.length > 1) then\n puts t\n p h\n end\n=end\n\n \n t.each_char{|a|\n return -1 if a < 'a'\n } if !h['S']\n \n \n\n \n res = 0\n \n t.each_char{|a|\n if (a < 'a') then\n a.upcase!\n return -1 if (!h[a])\n res += 1 if (!h_[a])\n else\n return -1 if (!h[a])\n end\n }\n \n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "#$stdin = File.open(\"in.txt\", \"r\")\n\ndef solve\n return '-1'\nend\n\nputs solve"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y]] = true\n \n if (s[x][y] == 83) then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets;\n \n \n \n \n t.each_byte{|a|\n return -1 if a < 97\n } if !h[83]\n \n \n res = 0\n \n t.each_byte{|a|\n if (a < 97) then\n a += 32\n return -1 if !h[a]\n res += 1 if !h_[a]\n else\n return -1 if !h[a]\n end\n }\n \n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nprintf(\"%d\", solve)"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y]] = true\n \n if (s[x][y] == 83) then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets; t.chop!\n \n t.each_byte{|a|\n return -1 if a < 97\n } if !h[83]\n \n res = 0\n \n \n if (t.length > 1) then puts t end\n \n t.each_byte{|a|\n if (a < 97) then\n a += 32\n return -1 if (!h[a])\n res += 1 if (!h_[a])\n else\n return -1 if (!h[a])\n end\n }\n \n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y]] = true\n \n if (s[x][y] == 83) then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets; t.chop!\n \n t.each_byte{|a|\n return -1 if a < 97\n } if !h[83]\n \n res = 0\n \n t.each_byte{|a|\n if (a < 97) then\n a += 32\n return -1 if !h[a]\n res += 1 if !h_[a]\n else\n return -1 if !h[a]\n end\n }\n \n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nprintf(\"%d\", solve)"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << readline\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n if (s[x][y] == 83) then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n h[s[x][y]] = true\n end\n }\n }\n \n \n \n gets; t = gets;\n \n puts t if (t.length > 1) \n t.each_char{|a|\n return -1 if a < 'a'\n } if !h['S']\n\n res = 0\n \n t.each_char{|a|\n if (t[i] < 'a') then\n t[i] += 32\n return -1 if !h[a]\n res += 1 if !h_[a]\n else\n return -1 if !h[a]\n end\n }\n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nprintf(\"%d\", solve)"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << readline\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n if (s[x][y] == 83) then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n h[s[x][y]] = true\n end\n }\n }\n \n \n \n gets; t = gets;\n \n puts t\n\n t.each_char{|a|\n return -1 if a < 'a'\n } if !h['S']\n\n res = 0\n \n t.each_char{|a|\n if (t[i] < 'a') then\n t[i] += 32\n return -1 if !h[a]\n res += 1 if !h_[a]\n else\n return -1 if !h[a]\n end\n }\n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nprintf(\"%d\", solve)"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y]] = true\n \n if (s[x][y] == 'S') then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets; t.chop!\n\n \n t.each_char{|a|\n return -1 if a < 'a'\n } if !h[\"S\"]\n \n \n=begin\n if (t.length > 1) then\n puts t\n p h\n end\n=end\n \n res = 0\n \n t.each_char{|a|\n if (a < 'a') then\n a.upcase!\n return -1 if (!h[a])\n res += 1 if (!h_[a])\n else\n return -1 if (!h[a])\n end\n }\n \n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y]] = true\n \n if (s[x][y] == 'S') then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets; t.chop!\n \n\n=begin\n if (t.length > 1) then\n puts t\n p h\n end\n=end\n\n\n \n t.each_char{|a|\n if a < 'a' then\n p h; p h['S'];\n p h[\"S\"];\n p h[87];\n return -1;\n end\n } if !h['S']\n \n\n res = 0\n \n t.each_char{|a|\n if (a < 'a') then\n a.upcase!\n return -1 if (!h[a])\n res += 1 if (!h_[a])\n else\n return -1 if (!h[a])\n end\n }\n \n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y]] = true\n \n if (s[x][y] == 'S') then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets; t.chop!\n \n \n if (t.length > 1) then\n puts t\n p h\n end\n \n t.each_char{|a|\n return -1 if a < 'a'\n } if !h[\"87\"]\n\n res = 0\n \n t.each_char{|a|\n if (a < 'a') then\n a += 32\n return -1 if (!h[a])\n res += 1 if (!h_[a])\n else\n return -1 if (!h[a])\n end\n }\n \n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y]] = true\n \n if (s[x][y] == 83) then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets; t.chop!\n \n \n if (t.length > 1) then \n puts t\n p h\n end\n \n t.each_byte{|a|\n return -1 if a < 97\n } if !h[83]\n \n res = 0\n \n \n \n t.each_byte{|a|\n if (a < 97) then\n a += 32\n return -1 if (!h[a])\n res += 1 if (!h_[a])\n else\n return -1 if (!h[a])\n end\n }\n \n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << readline\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n if (s[x][y] == 83) then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n h[s[x][y]] = true\n end\n }\n }\n \n \n \n q = readline; q = q.to_i; t = readline;\n \n puts t\n\n t.each_char{|a|\n return -1 if a < 'a'\n } if !h['S']\n\n res = 0\n \n t.each_char{|a|\n if (t[i] < 'a') then\n t[i] += 32\n return -1 if !h[a]\n res += 1 if !h_[a]\n else\n return -1 if !h[a]\n end\n }\n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nprintf(\"%d\", solve)"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y]] = true\n \n if (s[x][y] == 'S') then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets; t.chop!\n \n \n if (t.length > 1) then\n puts t\n p h\n end\n \n t.each_char{|a|\n return -1 if a < 'a'\n } if !h[87]\n\n res = 0\n \n t.each_char{|a|\n if (a < 'a') then\n a += 32\n return -1 if (!h[a])\n res += 1 if (!h_[a])\n else\n return -1 if (!h[a])\n end\n }\n \n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "#$stdin = File.open(\"in.txt\", \"r\")\nputs '1'"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y]] = true\n \n if (s[x][y] == 'S') then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets; t.chop!\n \n \n if (t.length > 1) then\n puts t\n p h\n end\n \n t.each_char{|a|\n return -1 if a < 'a'\n } if !h[83]\n \n res = 0\n \n t.each_char{|a|\n if (a < 'a') then\n a += 32\n return -1 if (!h[a])\n res += 1 if (!h_[a])\n else\n return -1 if (!h[a])\n end\n }\n \n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "def solve\n \n def sqr(x)\n return x * x\n end\n \n n , m , x = readline.split(' ')\n n = n.to_i; m = m.to_i; x = x.to_i; xx = sqr(x)\n \n s = Array.new; h = Hash.new(false); h_ = Hash.new(false)\n \n n.times {\n s << gets\n }\n \n (0...n).each{|x|\n (0...m).each{|y|\n \n h[s[x][y]] = true\n \n if (s[x][y] == 'S') then\n (0...n).each{|i|\n (0...m).each{|j|\n if (sqr(i-x) + sqr(j-y) <= xx) then\n h_[s[i][j]] = true\n end\n }\n }\n \n else\n end\n }\n }\n \n \n \n gets; t = gets; t.chop!\n \n\n=begin\n if (t.length > 1) then\n puts t\n p h\n end\n=end\n\n\n \n t.each_char{|a|\n if a < 'a' then\n if (t.length > 1) then \n p h; p h['S'];\n p h[\"S\"];\n p h[87];\n end\n return -1;\n end\n } if !h['S']\n \n\n res = 0\n \n t.each_char{|a|\n if (a < 'a') then\n a.upcase!\n return -1 if (!h[a])\n res += 1 if (!h_[a])\n else\n return -1 if (!h[a])\n end\n }\n \n return res\nend\n\n\n#$stdin = File.open(\"in.txt\", \"r\")\nputs solve"}, {"source_code": "n, m, x = gets.split.map(&:to_i)\nkeys = Hash.new { |hash, key| hash[key] = :unknown }\n\narr = Array.new\n(0...n).each do |i|\n l = gets.chomp\n l.chars.each { |e| keys[e] = :down if e != 'S' }\n arr << l\nend\n\n(0...n).each do |i|\n(0...m).each do |j|\nif arr[i][j] == 'S'\n1.upto(x) do |k|\n ((i - k)..(i + k)).each do |ii|\n ((j - k)..(j + k)).each do |jj|\n if ii >= 0 && ii < n && jj >= 0 && jj < m\n dy, dx = [(ii - i) * (ii - i), (jj - j) * (jj - j)]\n keys[arr[ii][jj]] = :up if arr[ii][jj] != 'S' && Math.sqrt(dy + dx) <= x\n end\n end\n end\nend\nend\nend\nend\n\ngets\n\nret = 0\ngets.chomp.chars.each do |t|\n if !keys.has_key?(t.downcase)\n ret = -1\n break\n end\n if (t >= 'A' && t <= 'Z') && keys[t.downcase] == :down\n ret += 1\n end\nend\n\nputs ret"}, {"source_code": "n, m, x = gets.strip.split.map{|s| s.to_i}\nkb = []\nshifts = []\ncount = 0\nn.times do |i|\n line = gets.strip.split(//).map do |s|\n s.ord\n end\n line.each_with_index do |s, j|\n shifts << [i, j] if s == \"S\".ord\n end\n kb << line\nend\nif shifts.empty?\n gets\n gets\n puts \"-1\"\n exit\nend\ngets\ngets.gsub(/[A-Z]/) do |c|\n c = c.downcase\n catch(:a) do\n kb.each_with_index do |line, i|\n line.each_with_index do |key, j|\n if key == c.ord \n shifts.each do |s|\n d = Math.sqrt((s[0] - i).abs**2 + (s[1] - j).abs**2)\n throw :a if d <= x\n end\n count += 1\n throw :a\n end\n end\n end\n end\nend\nputs count == 0 ? -1 : count\n"}, {"source_code": "count = 0\no = \"a\".ord\nn, m, x = gets.strip.split.map{|s| s.to_i}\nkb = []\nshifts = []\nall_keys = []\nn.times do |i|\n line = gets.strip.split(//).map do |s|\n s.ord\n end\n line.each_with_index do |s, j|\n if s == \"S\".ord\n shifts << [i, j]\n else\n all_keys << s\n end\n end\n kb << line\nend\nclose_keys = []\ndistant_keys = []\nshifts.each do |shift|\n kb.each_with_index do |line, i|\n line.each_with_index do |key, j|\n next if key == \"S\"\n if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x\n distant_keys << key\n else\n close_keys << key\n end\n end\n end\nend\nall_keys.uniq!\ndistant_keys.uniq!\ndistant_keys = distant_keys - close_keys\n\ngets\ngets.strip.each_char do |c|\n u = c.ord < o\n c_ord = c.downcase.ord\n unless all_keys.include?(c_ord)\n p all_keys\n p c_ord\n puts -1\n exit\n end\n if u\n if shifts.empty?\n puts -1\n exit\n end\n if distant_keys.include?(c_ord)\n count += 1\n end\n end\nend\nputs count\n"}, {"source_code": "count = 0\no = \"a\".ord\nn, m, x = gets.strip.split.map{|s| s.to_i}\nkb = []\nshifts = []\nall_keys = []\nn.times do |i|\n line = gets.strip.split(//).map do |s|\n s.ord\n end\n line.each_with_index do |s, j|\n if s == \"S\".ord\n shifts << [i, j]\n else\n all_keys << s\n end\n end\n kb << line\nend\nclose_keys = []\ndistant_keys = []\nshifts.each do |shift|\n kb.each_with_index do |line, i|\n line.each_with_index do |key, j|\n next if key == \"S\"\n if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x\n distant_keys << key\n else\n close_keys << key\n end\n end\n end\nend\nall_keys.uniq!\ndistant_keys.uniq!\ndistant_keys = distant_keys - close_keys\n\ngets\ngets.strip.each_char do |c|\n u = c.ord < o\n c_ord = c.downcase.ord\n unless all_keys.include?(c_ord)\n puts -1\n exit\n end\n if u && distant_keys.include?(c_ord)\n count += 1\n end\nend\nputs count\n"}, {"source_code": "o = \"a\".ord\nn, m, x = gets.strip.split.map{|s| s.to_i}\nkb = []\nshifts = []\ncount = 0\nn.times do |i|\n line = gets.strip.split(//).map do |s|\n s.ord\n end\n line.each_with_index do |s, j|\n shifts << [i, j] if s == \"S\".ord\n end\n kb << line\nend\nall_keys = []\nclose_keys = []\ndistant_keys = []\nshifts.each do |shift|\n kb.each_with_index do |line, i|\n line.each_with_index do |key, j|\n next if key == \"S\"\n key = key.ord\n all_keys << key\n if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x\n distant_keys << key\n else\n close_keys << key\n end\n end\n end\nend\nall_keys.uniq!\ndistant_keys.uniq!\ndistant_keys = distant_keys - close_keys\n\ngets\ngets.strip.each_char do |c|\n u = c.ord < o\n c_ord = c.downcase.ord\n unless all_keys.include?(c_ord)\n puts -1\n exit\n end\n if u && distant_keys.include?(c_ord)\n count += 1\n end\nend\nputs count\n"}, {"source_code": "o = \"a\".ord\nn, m, x = gets.strip.split.map{|s| s.to_i}\nkb = []\nshifts = []\ncount = 0\nn.times do |i|\n line = gets.strip.split(//).map do |s|\n s.ord\n end\n line.each_with_index do |s, j|\n shifts << [i, j] if s == \"S\".ord\n end\n kb << line\nend\ngets\ngets.strip.split(//).each do |c|\n u = c.ord < o\n c.downcase!\n if u && shifts.empty?\n puts \"-1\"\n exit\n end\n catch(:a) do\n kb.each_with_index do |line, i|\n line.each_with_index do |key, j|\n if key == c.ord \n throw :a unless u\n shifts.each do |s|\n d = Math.sqrt((s[0] - i).abs**2 + (s[1] - j).abs**2)\n #puts \"#{d}(#{x})\"\n throw :a if d <= x\n end\n count += 1\n throw :a\n end\n end\n end\n puts \"-1\"\n exit\n end\nend\nputs count\n"}, {"source_code": "n, m, x = gets.strip.split.map{|s| s.to_i}\nkb = []\nshifts = []\ncount = 0\nn.times do |i|\n line = gets.strip.split(//).map do |s|\n s.ord\n end\n line.each_with_index do |s, j|\n shifts << [i, j] if s == \"S\".ord\n end\n kb << line\nend\ngets\ngets.gsub(/[A-Z]/) do |c|\n c = c.downcase\n catch(:a) do\n kb.each_with_index do |line, i|\n line.each_with_index do |key, j|\n if key == c.ord \n shifts.each do |s|\n d = Math.sqrt((s[0] - i).abs**2 + (s[1] - j).abs**2)\n throw :a if d <= x\n end\n count += 1\n throw :a\n end\n end\n end\n end\nend\nputs count == 0 ? -1 : count\n"}, {"source_code": "count = 0\no = \"a\".ord\nn, m, x = gets.strip.split.map{|s| s.to_i}\nkb = []\nshifts = []\nall_keys = {}\nclose_keys = {}\ndistant_keys = {}\nn.times do |i|\n line = gets.strip.split(//).map do |s|\n s.ord\n end\n line.each_with_index do |s, j|\n if s == \"S\".ord\n shifts << [i, j]\n else\n all_keys[s] = true\n end\n end\n kb << line\nend\nshifts.each do |shift|\n kb.each_with_index do |line, i|\n line.each_with_index do |key, j|\n next if key == \"S\"\n if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x\n distant_keys[key] = true\n else\n close_keys[key] = true\n end\n end\n end\nend\nclose_keys.each{|c| distant_keys.delete(c)}\ngets\ngets.strip.each_char.with_index do |c, i|\n u = c.ord < o\n c_ord = c.downcase.ord\n unless all_keys[c_ord]\n puts -1\n exit\n end\n if u\n if shifts.empty?\n puts -1\n exit\n end\n if distant_keys[c_ord]\n count += 1\n end\n end\nend\nputs count\n"}, {"source_code": "time = Time.now\ncount = 0\no = \"a\".ord\nn, m, x = gets.strip.split.map{|s| s.to_i}\nno_51 = (n == 30 && m == 30 && x = 1)\nkb = []\nshifts = []\nall_keys = []\nn.times do |i|\n line = gets.strip.split(//).map do |s|\n s.ord\n end\n line.each_with_index do |s, j|\n if s == \"S\".ord\n shifts << [i, j]\n else\n all_keys << s\n end\n end\n kb << line\nend\nclose_keys = []\ndistant_keys = []\nshifts.each do |shift|\n kb.each_with_index do |line, i|\n line.each_with_index do |key, j|\n next if key == \"S\"\n if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x\n distant_keys << key\n else\n close_keys << key\n end\n end\n end\nend\nall_keys.uniq!\ndistant_keys.uniq!\ndistant_keys = distant_keys - close_keys\ngets\ngets.strip.each_char do |c|\n if no_51 && Time.now - time == 1900\n raise StandardError.new(\"#{c}(#{i})\")\n end\n u = c.ord < o\n c_ord = c.downcase.ord\n unless all_keys.include?(c_ord)\n puts -1\n exit\n end\n if u\n if shifts.empty?\n puts -1\n exit\n end\n if distant_keys.include?(c_ord)\n count += 1\n end\n end\nend\nputs count\n"}, {"source_code": "time = Time.now\ncount = 0\no = \"a\".ord\nn, m, x = gets.strip.split.map{|s| s.to_i}\nno_51 = (n == 30 && m == 30 && x = 1)\nkb = []\nshifts = []\nall_keys = []\nn.times do |i|\n line = gets.strip.split(//).map do |s|\n s.ord\n end\n line.each_with_index do |s, j|\n if s == \"S\".ord\n shifts << [i, j]\n else\n all_keys << s\n end\n end\n kb << line\nend\nclose_keys = []\ndistant_keys = []\nshifts.each do |shift|\n kb.each_with_index do |line, i|\n line.each_with_index do |key, j|\n next if key == \"S\"\n if Math.sqrt((shift[0] - i).abs**2 + (shift[1] - j).abs**2) > x\n distant_keys << key\n else\n close_keys << key\n end\n end\n end\nend\nall_keys.uniq!\ndistant_keys.uniq!\ndistant_keys = distant_keys - close_keys\ngets\ngets.strip.each_char.with_index do |c, i|\n if no_51 && Time.now - time == 1900\n raise Exception(\"#{c}(#{i})\")\n end\n u = c.ord < o\n c_ord = c.downcase.ord\n unless all_keys.include?(c_ord)\n puts -1\n exit\n end\n if u\n if shifts.empty?\n puts -1\n exit\n end\n if distant_keys.include?(c_ord)\n count += 1\n end\n end\nend\nputs count\n"}], "src_uid": "0870110338a84f76d4870d06dc9da2df"} {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n puts(n == 1 ? 2 : (n + 2) / 3)\nend\n", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n puts((n + 2) / 3 + (n == 1 ? 1 : 0))\nend\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n if n == 1\r\n p 2\r\n else\r\n p (n / 3.0).ceil\r\n end\r\nend\r\n"}], "negative_code": [], "src_uid": "208e285502bed3015b30ef10a351fd6d"} {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2{gets.split.map(&:to_i)}\nn, m = I[]\na = Array.new(n){I[]}.sort_by{|i, j| -i * 1000 + j}\np a.count(a[m - 1])\n\n", "positive_code": [{"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\na = Array.new(n){I[]}.sort_by{|i, j| -i * 1000 + j}\np a.count(a[m - 1])"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\na = Array.new(n){I[]}.sort_by{|i, j| -i * 1000 + j}\np a.count(a[m - 1])\n\n"}, {"source_code": "def read_next_line\n gets.chomp.split.map { |x| x.to_i }\nend\n\ndef count_places(p, a, r)\n count = 0\n for i in r\n if a[i] == a[p]\n count += 1\n else\n break\n end\n end\n count\nend\n\nn, k = read_next_line\na = []\nfor i in 0...n\n a[i] = read_next_line\nend\na.sort! { |u, w| r = w[0] <=> u[0]; r == 0 ? u[1] <=> w[1] : r }\n\nputs 1 + count_places(k - 1, a, (k - 2).downto(0)) + count_places(k - 1, a, k...n)"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\na = Array.new(n){I[]}.sort_by{|i, j| -i * 1000 + j}\np a.count(a[m - 1])\n\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=n.times.map{p,t=gets.split.map(&:to_i);51*p+51-t}.sort.reverse\np a.group_by{|_|_}[a[k-1]].size"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\na = Array.new(n){I[]}.sort_by{|i, j| -i * 1000 + j}\np a.count(a[m - 1])\n\n"}, {"source_code": "n,k = gets.chomp.split(/ /).map!{|x| x.to_i}\na = []\nfor i in 0..n-1\n p,t = gets.chomp.split(/ /).map!{|x| x.to_i}\n a << [p,t]\nend\na.sort!{|a1,a2|\n if a1[0] == a2[0]\n a1[1] <=> a2[1]\n else\n a2[0] <=> a1[0]\n end\n}\n\nsamecnt = 1\nfor i in 0..n-1\n if i > 0\n if a[i-1][0] == a[i][0] && a[i-1][1] == a[i][1]\n samecnt += 1\n else\n if (k-1) < i\n break\n end\n samecnt = 1\n end\n end\nend\nputs samecnt\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\na = Array.new(n){I[]}.sort_by{|i, j| -i * 1000 + j}\np a.count(a[m - 1])\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = []\nn.times do\n tmp = gets.split.map(&:to_i)\n tmp[0] *= -1\n a <<= tmp\nend\na.sort!\nk-=1;\nans = 0\na.each do |tmp|\n ans += 1 if tmp == a[k]\nend\np ans"}, {"source_code": "#!/usr/bin/ruby\n\nn, k = gets.split.map(&:to_i)\narr = []\nn.times do\n p, t = gets.split.map(&:to_i)\n arr << [p, t]\nend\narr.sort!{|a,b| a[0]!=b[0] ? a[0]<=>b[0] : b[1]<=>a[1]}\narr.reverse!\np arr.count(arr[k-1])\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\na = Array.new(n){I[]}.sort_by{|i, j| -i * 1000 + j}\np a.count(a[m - 1])\n\n"}, {"source_code": "\ufeffn, k = gets.chomp.split(\" \").map{|e| e.to_i}\n\nresults = []\nn.times do \n results << gets.chomp.split(\" \").map{|e| e.to_i}\nend\n\nresults.sort!{|a, b|\n if (a[0] > b[0])\n 1\n elsif (a[0] == b[0] and a[1] < b[1])\n 1\n else\n -1\n end\n}.reverse!\n\ntmp = results[k - 1]\nputs results.count(tmp)\n \n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\na = Array.new(n){I[]}.sort_by{|i, j| -i * 1000 + j}\np a.count(a[m - 1])\n\n"}, {"source_code": "n, k = gets.split(/\\s+/).map(&:to_i)\nsolved = []\nn.times do\n\tp, t = gets.split(/\\s+/).map(&:to_i)\n\tsolved << [p, -t]\nend\nsolved.sort!.reverse!\nputs solved.count(solved[k-1])\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\na = Array.new(n){I[]}.sort_by{|i, j| -i * 1000 + j}\np a.count(a[m - 1])\n"}, {"source_code": "def comp a,b\n return 1 if a[0] > b[0]\n return -1 if a[0] < b[0]\n return 0 if a[0] == b[0] and a[1] == b[1]\n return 1 if a[0] == b[0] and a[1] < b[1]\n -1 if a[0] == b[0] and a[1] > b[1]\nend\n_, k = gets.split.map(&:to_i)\na = readlines.map(&:chomp).map(&:split).each{|x| x.map!(&:to_i)}\na.sort! { |x,y| comp(x,y) }.reverse!\nputs a.count(a[k-1])"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\na = Array.new(n){I[]}.sort_by{|i, j| -i * 1000 + j}\np a.count(a[m - 1])\n\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, m = I[]\na = Array.new(n){I[]}.sort_by{|i, j| -i * 1000 + j}\np a.count(a[m - 1])\n\n"}], "negative_code": [{"source_code": "n, k = gets.split.map(&:to_i)\na = []\nn.times do\n tmp = gets.split.map(&:to_i)\n tmp[0] *= -1\n a <<= tmp\nend\na.sort\nk-=1;\nans = 0\na.each do |tmp|\n ans += 1 if tmp == a[k]\nend\np ans"}, {"source_code": "#!/usr/bin/ruby\n\nn, k = gets.split.map(&:to_i)\narr = []\nn.times do\n p, t = gets.split.map(&:to_i)\n arr << [p, t]\nend\narr.sort!{|a,b| a[0]!=b[0] ? a[0]<=>b[0] : a[1]<=>b[1]}\narr.reverse!\np arr.count(arr[k-1])\n"}, {"source_code": "\ufeffn, k = gets.chomp.split(\" \").map{|e| e.to_i}\n\nresults = []\nn.times do \n results << gets.chomp.split(\" \").map{|e| e.to_i}\nend\n\nresults.sort!{|a, b|\n if (a[0] > b[0])\n 1\n elsif (a[0] == b[0] and a[1] < b[1])\n 1\n else\n -1\n end\n}.reverse!\n\ntmp = results[k]\nputs results.count(tmp)\n \n"}, {"source_code": "n, k = gets.split(/\\s+/).map(&:to_i)\nsolved = []\nn.times do\n\tp, t = gets.split(/\\s+/).map(&:to_i)\n\tsolved << [p, t]\nend\nsolved.sort!.reverse!\nputs solved.count(solved[k-1])\n"}, {"source_code": "def comp a,b\n return 1 if a[0] > b[0]\n return -1 if a[0] < b[0]\n return 0 if a[0] == b[0] and a[1] == b[1]\n return 1 if a[0] == b[0] and a[1] > b[1]\n -1 if a[0] == b[0] and a[1] < b[1]\nend\n_, k = gets.split.map(&:to_i)\na = readlines.map(&:chomp).map(&:split).each{|x| x.map!(&:to_i)}\na.sort! { |x,y| comp(x,y) }.reverse!\nputs a.count(a[k])"}, {"source_code": "def comp a,b\n return 1 if a[0] > b[0]\n return -1 if a[0] < b[0]\n return 0 if a[0] == b[0] and a[1] == b[1]\n return 1 if a[0] == b[0] and a[1] > b[1]\n -1 if a[0] == b[0] and a[1] < b[1]\nend\n_, k = gets.split.map(&:to_i)\na = readlines.map(&:chomp).map(&:split).each{|x| x.map!(&:to_i)}\na.sort! { |x,y| comp(x,y) }.reverse!\nputs a.count(a[k-1])"}, {"source_code": "def comp a,b\n return 1 if a[0] > b[0]\n return -1 if a[0] < b[0]\n return 0 if a[0] == b[0] and a[1] == b[1]\n return 1 if a[0] == b[0] and a[1] < b[1]\n -1 if a[0] == b[0] and a[1] > b[1]\nend\n_, k = gets.split.map(&:to_i)\na = readlines.map(&:chomp).map(&:split).each{|x| x.map!(&:to_i)}\na.sort! { |x,y| comp(x,y) }.reverse!\np a\nputs a.count(a[k-1])"}, {"source_code": "def read_next_line\n gets.chomp.split.map { |x| x.to_i }\nend\n\ndef count_places(k, a, r)\n count = 0\n for i in r\n if a[i] == a[k]\n count += 1\n else\n break\n end\n end\n count\nend\n\nn, k = read_next_line\na = []\nfor i in 0...n\n a[i] = read_next_line\nend\na.sort! { |u, w| r = w[0] <=> u[0]; r == 0 ? w[1] <=> u[1] : r }\n\nputs 1 + count_places(k, a, (k - 1).downto(0)) + count_places(k, a, k + 1...n)"}], "src_uid": "63e03361531999db408dc0d02de93579"} {"source_code": "n, k = gets.split.map(&:to_i)\nans = n.times.map do\n f, t = gets.split.map(&:to_i)\n f - [t - k, 0].max\nend.max\nputs ans\n", "positive_code": [{"source_code": "class Joy\n attr_accessor :best\n def initialize(k)\n @k = k\n end\n def refresh(x,y)\n x -= y-@k>0 ? y-@k : 0\n @best = @best ? [@best,x].max : x\n end\nend\nn, k = gets.split(' ').map(&:to_i)\njoy = Joy.new k\nn.times do\n f, t = gets.split(' ').map(&:to_i)\n joy.refresh(f,t)\nend\nputs joy.best"}, {"source_code": "n,k=gets.split.map &:to_i;p n.times.map{f,t=gets.split.map &:to_i;(t>k)?f-(t-k):f}.max\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = []\nans = []\nn.times {a << gets.split.map(&:to_i)}\na.each do |res|\n\tif res[1] > k then\n\t\tans << res[0] - (res[1] - k)\n\t\telse\n\t\t\tans << res[0]\n\tend\nend\nputs ans.max\n\t\t\t\n\t\n\n\n\n\n"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\nn, k = gets.chomp.split(\" \").map{ |e| e.to_i }\n\nans = -10000000000\nn.times do\n f, t = gets.chomp.split(\" \").map{ |e| e.to_i }\n tmp = nil\n if t > k\n tmp = f - (t - k)\n else\n tmp = f\n end\n ans = tmp if ans < tmp\nend\n\nputs ans\n \n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nmax = -(2**31)\nn.times do\n f, t = gets.split.map(&:to_i)\n if t > k then f -= t-k end\n if f > max then max = f end\nend\nputs max"}, {"source_code": "n,k=gets.split.map &:to_i;p n.times.map{f,t=gets.split.map &:to_i;(t>k)?f-(t-k):f}.max\n\n"}, {"source_code": "\nn, k =gets.chomp.split.map(&:to_i);\nans = -1e9;\n\nn.times do\n x, y = gets.chomp.split.map(&:to_i);\n x = x - y + k if (y > k);\n ans = [ans, x].max;\nend\np ans;\n"}, {"source_code": "n,k=gets.split.map &:to_i;p n.times.map{f,t=gets.split.map &:to_i;(t>k)?f-(t-k):f}.max\n"}, {"source_code": "n,k=gets.chomp.split.map(&:to_i)\nm=[]\nn.times do\n\ta,b=gets.chomp.split.map(&:to_i)\n\tif b>k\n\t\tm.push(a-b+k)\n\telse\n\t\tm.push(a)\n\tend\nend\nputs m.max"}, {"source_code": "def run\n n, k = ARGF.readline.split.map(&:to_i)\n\n max = -(1 << 30)\n ARGF.readlines.each do |line|\n f, t = line.split.map(&:to_i)\n\n score = t > k ? (f - t + k) : f\n max = [score, max].max\n end\n\n puts max\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n,k=gets.split.map &:to_i;p n.times.map{f,t=gets.split.map &:to_i;(t>k)?f-(t-k):f}.max\n\n"}, {"source_code": "n,k=gets.split.map &:to_i;p n.times.map{f,t=gets.split.map &:to_i;(t>k)?f-(t-k):f}.max\n\n"}, {"source_code": "n, k = gets.chomp.split(/ /).map(&:to_i)\njoys = []\nn.times do\n f, t = gets.chomp.split(/ /).map(&:to_i)\n if t > k\n joys << f - (t - k)\n else\n joys << f\n end\nend\nputs joys.max\n"}, {"source_code": "n,k=gets.split.map{|e| e.to_i}\nans=-(10**20)\nn.times{\n\tf,t=gets.split.map{|e| e.to_i}\n\tf=f-(t-k) if k k then\n ans = [ans, fi - (ti - k)].max\n else\n ans = [ans, fi].max\n end\nend\n\nprint ans"}, {"source_code": "n,k=gets.split.map(&:to_i)\nres=-100000000000\nn.times do\n f,t=gets.split.map(&:to_i)\n if t > k then\n x=f-(t-k)\n else\n x=f\n end\n res = x if res < x\nend\nputs res\n"}, {"source_code": "def joy(rest,k)\n\tif rest[1] > k\n\t\trest[0] -(rest[1] - k)\n\telse\n\t\trest[0]\n\tend\nend\n\ndef do_stuff(k,rests)\n\tjoys = rests.map { |x| joy(x,k) }\n\tputs joys.max\nend\n\nline1 = gets.chomp.split(' ').map { |str| str.to_i }\nrests = []\nline1[0].times { |rest| rests << gets.chomp.split(' ').map { |str| str.to_i } }\n\n\ndo_stuff(line1[1],rests)"}, {"source_code": "n,k=gets.split.map &:to_i;p n.times.map{f,t=gets.split.map &:to_i;(t>k)?f-(t-k):f}.max\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn, k = gets.split.map(&:to_i)\nmax_joy = -10**10\nn.times {\n f, t = gets.split.map(&:to_i)\n joy = 0\n if t <= k\n joy = f\n else\n joy = f - (t - k)\n end\n\n if joy > max_joy\n max_joy = joy\n end\n}\n\nputs max_joy\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\nt = []\nmax = -10000000000\nn.times do |i|\n\tf, t = gets.split(' ').collect!{|i| i.to_i}\n\tif t > k\n\t\tnewf = f - (t - k) \n\telse\n\t\tnewf = f\n\tend\n\tmax = newf if newf > max\nend\n\np max\n"}, {"source_code": "n,k=gets.split.map &:to_i;p n.times.map{f,t=gets.split.map &:to_i;(t>k)?f-(t-k):f}.max\n\n"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\n\nf,t = gets.split(\" \").map(&:to_i)\nval = t <= k ? f : f - (t-k)\nmax_joy = val\n\n(n-1).times{\n f,t = gets.split(\" \").map(&:to_i)\n val = t <= k ? f : f - (t-k)\n max_joy = val if val > max_joy\n}\nputs max_joy"}, {"source_code": "n,k = gets.split(\" \").collect! {|x| x.to_i};\n\nf,t = gets.split(\" \").collect! {|x| x.to_i};\nmax = (t>k) ? (f-(t-k)) : f;\nm = 0\n(2..n).each {\n f,t = gets.split(\" \").collect! {|x| x.to_i};\n m = (t>k) ? (f-(t-k)) : f;\n if m > max \n max = m\n end\n}\n\nputs max"}, {"source_code": "require 'scanf'\nst = gets\nn, k = st.scanf(\"%d%d\")\nstr = gets\nf, t = str.scanf(\"%d%d\")\nans = f\nif( t > k)\n ans -= (t-k)\nend\nn-=1\nwhile n > 0\n n -= 1\n str = gets\n f, t = str.scanf(\"%d%d\")\n anst = f\n if(t > k)\n anst -= (t-k)\n end\n if( ans < anst)\n ans = anst\n end\nend\nputs ans\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nans = -Float::INFINITY\nn.times do\n f, t = gets.split.map(&:to_i)\n ans = [ans, f - [t - k, 0].max].max\nend\nputs ans\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nans = -Float::INFINITY\nn.times do\n f, t = gets.split.map(&:to_i)\n if t > k\n ans = [ans, f - (t - k)].max\n else\n ans = [ans, f].max\n end\nend\nputs ans\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nans = -Float::INFINITY\nn.times do\n f, t = gets.split.map(&:to_i)\n minus = [t - k, 0].max\n ans = [ans, f - minus].max\nend\nputs ans\n"}, {"source_code": "n,k=gets.split.map &:to_i\nz = -100000000000\nn.times do \n f,t=gets.split.map &:to_i\n temp=f\n if (t>k)\n temp=f-(t-k)\n end\n if temp>z\n z=temp\n end\nend\nputs z"}, {"source_code": "n,k=gets.split.map &:to_i\np n.times.map{\n f,t=gets.split.map &:to_i\n (t>k)?f-(t-k):f\n}.max\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\np (1..n).each.map{\n f,t=gets.split.map(&:to_i)\n (t>k)?f-(t-k):f\n}.max\n"}, {"source_code": "i=[*$<]\nn,k=i[0].split.map(&:to_i)\nres=-10**9\n(1..n).each{|j|\n f,t=i[j].split.map(&:to_i)\n res=[(t>k)?f-(t-k):f,res].max\n}\np res\n"}, {"source_code": "i=[*$<]\nn, k = i[0].split.map(&:to_i)\ndef get(f, t, k)\n (t>k)?f-(t-k):f\nend\nres = -10**9\n(1..n).each{|j|\n f, t = i[j].split.map(&:to_i)\n res = [get(f,t,k),res].max\n}\np res\n"}, {"source_code": "n,k=gets.split.map &:to_i;p n.times.map{f,t=gets.split.map &:to_i;(t>k)?f-(t-k):f}.max\n\n"}, {"source_code": "n, k = gets.chomp.split.map { |x| x.to_i }\nmax = -1_000_000_001\nfor _ in 1..n\n f, t = gets.chomp.split.map { |x| x.to_i }\n j = f + k - t\n j = f if j > f\n max = j if j > max\nend\nputs max"}, {"source_code": "# Codeforces Round #169\n# Problem A -- Lunch Rush\nn, k = gets.split.map(&:to_i)\nputs([*1..n].map do\n f, t = gets.split.map(&:to_i)\n if t <= k\n f\n else\n f - (t - k)\n end\nend.max)\n"}, {"source_code": "n,k = gets.split.map(&:to_i)\nans = -100000000000\nn.times do \n\tf,t = gets.split.map(&:to_i)\n\tans = [ (t>k)? (f-t+k) : (f), ans].max\t\nend\nputs ans"}, {"source_code": "n,k=gets.split.map &:to_i;p n.times.map{f,t=gets.split.map &:to_i;(t>k)?f-(t-k):f}.max\n\n"}, {"source_code": "n, k = gets.chomp.split(\" \")\nn = n.to_i\nk = k.to_i\n \n f, t = gets.chomp.split(\" \")\n f = f.to_i\n t = t.to_i\n if t>k\n max = f-t+k\n else\n max = f\n end\n \n(n-1).times do\n f, t = gets.chomp.split(\" \")\n f = f.to_i\n t = t.to_i\n if t>k\n m = f-t+k\n else\n m = f\n end\n if m>max\n max=m\n end\n \nend\nputs max"}, {"source_code": "n,k=gets.split.map &:to_i;p n.times.map{f,t=gets.split.map &:to_i;(t>k)?f-(t-k):f}.max\n\n"}], "negative_code": [{"source_code": "\ufeff# -*- encoding: utf-8 -*-\nn, k = gets.chomp.split(\" \").map{ |e| e.to_i }\n\nans = -1\nn.times do\n t, f = gets.chomp.split(\" \").map{ |e| e.to_i }\n if f <= k and ans < t\n ans = t\n end \nend\n\nputs ans\n \n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nmax = 0\nn.times do\n f, t = gets.split.map(&:to_i)\n if t > k then f -= t-k end\n if f > max then max = f end\nend\nputs max"}, {"source_code": "n,k=gets.split.map{|e| e.to_i}\nans=-1\nn.times{\n\ta,b=gets.split.map{|e| e.to_i}\n\tif b<=k && ans max_joy\n}\nputs max_joy"}, {"source_code": "n,k=gets.split.map &:to_i\nz = -10000000\nn.times do \n f,t=gets.split.map &:to_i\n temp=f\n if (t>k)\n temp=f-(t-k)\n end\n if temp>z\n z=temp\n end\nend\nputs z"}, {"source_code": "n,k = gets.split.map(&:to_i)\nans = -100000000\nn.times do \n\tf,t = gets.split.map(&:to_i)\n\tans = [ (t>k)? (f-t+k) : (f), ans].max\t\nend\nputs ans"}], "src_uid": "1bb5b64657e16fb518d49d3c799d4823"} {"source_code": "n = gets.to_i\npe = [nil] + gets.split.map(&:to_i)\npos = []*(n+1)\nn.times do |i|\n pos[pe[i+1]] = i+1\nend\n#p pos\n\nnum = 0\ncmd = []\n\nla,lb,ra,rb = 1,n/2,n/2+1,n\n2.upto(lb) do |i|\n from = pos[i]\n next if from==i\n if from < ra\n cmd << [from,rb]\n cmd << [i,rb]\n pe[from] = pe[rb]\n pe[rb] = pe[i]\n pos[pe[from]] = from\n pos[pe[rb]] = rb\n num += 2\n elsif from < rb\n cmd << [from,la]\n cmd << [la,rb]\n cmd << [i,rb]\n pe[from] = pe[la]\n pe[la] = pe[rb]\n pe[rb] = pe[i]\n pos[pe[from]] = from\n pos[pe[la]] = la\n pos[pe[rb]] = rb\n num += 3\n else\n cmd << [i,rb]\n pe[rb] = pe[i]\n pos[pe[rb]] = rb\n num += 1\n end\n #p [i,from,num]\n #p pe\n #p pos\nend\nra.upto(rb-1) do |i|\n from = pos[i]\n next if from==i\n if from > lb\n cmd << [from,la]\n cmd << [i,la]\n pe[from] = pe[la]\n pe[la] = pe[i]\n pos[pe[from]] = from\n pos[pe[la]] = la\n num += 2\n else\n cmd << [i,la]\n pe[la] = pe[i]\n pos[pe[la]] = la\n num += 1\n end\nend\n#p pe\nif pe[1] != 1\n cmd << [1,n]\n num += 1\nend\np num\ncmd.each do |a,b|\n puts \"#{a} #{b}\"\nend\n", "positive_code": [{"source_code": "def swap(pe,pos,cmd,a,b)\n tmp = pe[a]\n pe[a] = pe[b]\n pe[b] = tmp\n tmp = pos[pe[a]]\n pos[pe[a]] = pos[pe[b]]\n pos[pe[b]] = tmp\n cmd << [a,b]\nend\n\nn = gets.to_i\npe = [nil] + gets.split.map(&:to_i)\npos = []*(n+1)\n\nn.times do |i|\n pos[pe[i+1]] = i+1\nend\n\nnum = 0\ncmd = []\n\nla,lb,ra,rb = 1,n/2,n/2+1,n\n2.upto(lb) do |i|\n from = pos[i]\n next if i==from\n if from < ra\n swap(pe,pos,cmd,from,rb)\n swap(pe,pos,cmd,i,rb)\n num += 2\n elsif from >= ra && from < rb\n swap(pe,pos,cmd,from,la)\n swap(pe,pos,cmd,la,rb)\n swap(pe,pos,cmd,i,rb)\n num += 3\n else\n swap(pe,pos,cmd,i,rb)\n num += 1\n end\n #p pe\n #p pos\n #puts\nend\n\nra.upto(rb-1) do |i|\n from = pos[i]\n next if i==from\n if from > lb\n swap(pe,pos,cmd,from,la)\n swap(pe,pos,cmd,i,la)\n num += 2\n else\n swap(pe,pos,cmd,i,la)\n num += 1\n end\nend\n\nif pe[1] != 1\n swap(pe,pos,cmd,1,n)\n num += 1\nend\np num\ncmd.each do |a,b|\n puts \"#{a} #{b}\"\nend\n\n"}], "negative_code": [{"source_code": "n = gets.to_i\npe = [nil] + gets.split.map(&:to_i)\npos = []*(n+1)\nn.times do |i|\n pos[pe[i+1]] = i+1\nend\n#p pos\n\nnum = 0\ncmd = []\n\nla,lb,ra,rb = 1,n/2,n/2+1,n\n2.upto(lb) do |i|\n from = pos[i]\n if from < ra\n cmd << [from,rb]\n cmd << [i,rb]\n pe[from] = pe[rb]\n pe[rb] = pe[i]\n pos[pe[from]] = from\n pos[pe[rb]] = rb\n num += 2\n elsif from < rb\n cmd << [from,la]\n cmd << [la,rb]\n cmd << [i,rb]\n pe[from] = pe[la]\n pe[la] = pe[rb]\n pe[rb] = pe[la]\n pos[pe[from]] = from\n pos[pe[la]] = la\n pos[pe[rb]] = rb\n num += 3\n else\n cmd << [i,rb]\n pe[rb] = pe[i]\n pos[pe[rb]] = rb\n num += 1\n end\n #p pe\n #p pos\nend\nra.upto(rb-1) do |i|\n from = pos[i]\n if from > lb\n cmd << [from,la]\n cmd << [i,la]\n pe[from] = pe[la]\n pe[la] = pe[i]\n pos[pe[from]] = from\n pos[pe[la]] = la\n num += 2\n elsif from > la\n cmd <<[from,rb]\n cmd <<[rb,la]\n cmd <<[i,la]\n pe[from] = pe[rb]\n pe[rb] = pe[la]\n pe[la] = pe[rb]\n pos[pe[from]] = from\n pos[pe[rb]] = rb\n pos[pe[la]] = la\n num += 3\n else\n cmd << [i,la]\n pe[la] = pe[i]\n pos[pe[la]] = la\n num += 1\n end\nend\n#p pe\nif pe[1] != 1\n cmd << [1,n]\n num += 1\nend\np num\ncmd.each do |a,b|\n puts \"#{a} #{b}\"\nend\n\n"}, {"source_code": "n = gets.to_i\npe = [nil] + gets.split.map(&:to_i)\npos = []*(n+1)\nn.times do |i|\n pos[pe[i+1]] = i+1\nend\n#p pos\n\nnum = 0\ncmd = []\n\nla,lb,ra,rb = 1,n/2,n/2+1,n\n2.upto(lb) do |i|\n from = pos[i]\n if from < ra\n cmd << [from,rb]\n cmd << [i,rb]\n pe[from] = pe[rb]\n pe[rb] = pe[i]\n pos[pe[from]] = from\n pos[pe[rb]] = rb\n num += 2\n else\n cmd << [from,la]\n cmd << [la,rb]\n cmd << [i,rb]\n pe[from] = pe[la]\n pe[la] = pe[rb]\n pe[rb] = pe[la]\n pos[pe[from]] = from\n pos[pe[la]] = la\n pos[pe[rb]] = rb\n num += 3\n end\n #p pe\n #p pos\nend\nra.upto(rb-1) do |i|\n from = pos[i]\n if from > lb\n cmd << [from,la]\n cmd << [i,la]\n pe[from] = pe[la]\n pe[la] = pe[i]\n pos[pe[from]] = from\n pos[pe[la]] = la\n num += 2\n else\n cmd <<[from,rb]\n cmd <<[rb,la]\n cmd <<[i,la]\n pe[from] = pe[rb]\n pe[rb] = pe[la]\n pe[la] = pe[rb]\n pos[pe[from]] = from\n pos[pe[rb]] = rb\n pos[pe[la]] = la\n num += 3\n end\nend\n#p pe\nif pe[1] != 1\n cmd << [1,n]\n num += 1\nend\np num\ncmd.each do |a,b|\n puts \"#{a} #{b}\"\nend\n\n"}], "src_uid": "b1706815238eb940060231848e43ffa8"} {"source_code": "def solve\n _ = gets\n a = gets.strip.split(' ').map(&:to_i)\n b = gets.strip.split(' ').map(&:to_i)\n x = 0\n y = 0\n b.each { |e|\n x += 1 if e.zero?\n y += 1 if !e.zero?\n }\n if !x.zero? && !y.zero? || a == a.sort\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\n\n\n\ngets.strip.to_i.times { solve }\n", "positive_code": [{"source_code": "tasks_numbers = gets.chomp\nanswers = []\n(1..tasks_numbers.to_i).each do\n\tnumbers_qty = gets.chomp\n\tnumbers = gets.chomp.split(\" \")\n\ttypes = gets.chomp.split(\" \")\n\n\tis_types_not_different = true\n\tindex = 1\n\tprev_type = types.first\n\twhile is_types_not_different && types.length > index do\n\t\tif prev_type != types[index]\n\t\t\tis_types_not_different = false\n\t\tend\n\t\tprev_type = types[index]\n\t\tindex += 1\n\tend\n\tif is_types_not_different == false\n\t\tanswers.push 'Yes'\n\t\tnext\n\tend\n\tis_sort_asc = true\n\tindex = 1\n\tprev_number = numbers.first.to_i\n\twhile is_sort_asc && numbers.length > index do\n\t\tif prev_number > numbers[index].to_i\n\t\t\tis_sort_asc = false\n\t\tend\n\t\tprev_number = numbers[index].to_i\n\t\tindex += 1\n\tend\n\tif is_sort_asc == true\n\t\tanswers.push 'Yes'\n\telse\n\t\tanswers.push 'No'\n\tend\n\n\t\nend\n\nanswers.each do |answer|\n\tputs answer\nend\n"}, {"source_code": "def solve\n _ = gets\n a = gets.strip.split(' ').map(&:to_i)\n b = gets.strip.split(' ').map(&:to_i)\n x = 0\n y = 0\n b.each { |e|\n x += 1 if e.zero?\n y += 1 if !e.zero?\n }\n if !x.zero? && !y.zero? || a == a.sort\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\ngets.strip.to_i.times { solve }\n"}], "negative_code": [], "src_uid": "4bf3a94119d08a9cd6075a67d0014061"} {"source_code": "t = gets.to_i\n(1..t).each do\n arr = gets.split(' ')\n n = arr[0].to_i\n k = arr[1].to_i\n x = 1\n v = 0\n loop do\n if v+x < k\n v+=x\n x+=1\n else\n v+=x\n break\n end\n end\n ans = []\n (1..n-x-1).each do\n print \"a\"\n end\n rem = x-1\n print \"b\"\n (1..v-k).each do\n print \"a\"\n rem-=1\n end\n print \"b\"\n (1..rem).each do\n print \"a\"\n end\n puts(\"\")\n\nend\n", "positive_code": [{"source_code": "def tri(n)\n\tn * (n + 1) / 2\nend\n\ngets.to_i.times do\n\tn, k = gets.split.map &:to_i\n\tx = (1..10**9).bsearch{|i| tri(i) >= k}\n\ty = tri(x) - k\n\tans = 'a' * n\n\tans[n - x - 1] = 'b'\n\tans[n - x + y] = 'b'\n\tputs ans\nend"}, {"source_code": "t = gets.to_i\nt.times do\n n, k = gets.split.map(&:to_i)\n kk = 0\n for i in 1..(n-1) do\n if (kk + i) >= k\n j = k - kk - 1\n break\n end\n kk += i\n end\n s = \"a\" * n\n s[-1 - i] = \"b\"\n s[-1 - j] = \"b\"\n puts s\nend\n"}, {"source_code": "for run in 0...gets.to_i\n\tnums = gets.split(\" \").map { |i| i.to_i }\n\tlen = nums[0]\n\tloc = nums[1]\n\tt = 1\n\ti = 2\n\tuntil t >= loc\n\t\tt += i\n\t\ti += 1\n\tend\n\trem = t - loc\n\tstr = \"a\" * (len - i) + \"b\" + \"a\" * rem + \"b\" + \"a\" * (len - (len - i) - 1 - rem - 1)\n\tputs str\nend"}, {"source_code": "t = gets.to_i\n\n1.upto(t) do\n n, k = gets.split(' ').map(&:to_i)\n\n sum = 0\n pos = 1\n i = 1\n while sum < k do\n sum += i\n pos += 1\n i += 1\n end\n\n result = 'a'*n\n result[-pos] = 'b'\n result[-(k - sum + i - 1)] = 'b'\n\n puts result\nend\n"}, {"source_code": "# frozen_string_literal: true\n\ndef total(n, a)\n b = n - a\n tmp = (a + 1).upto(n).inject(:*) || 1\n 2.upto(n - a) { |i| tmp /= i }\n tmp\nend\n\ntest = gets.to_i\ntest.times do\n n, k = gets.chomp.split.map(&:to_i)\n a = n - 2\n n.downto(1) do |current|\n if current == 1\n if a > 0\n print 'a'\n else\n print 'b'\n end\n elsif a.zero?\n print 'b'\n elsif total(current - 1, a - 1) >= k\n print 'a'\n a -= 1\n else\n k -= total(current - 1, a - 1)\n print 'b'\n end\n end\n puts\nend\n"}], "negative_code": [], "src_uid": "e32f0615541d97a025bc99c3cbf5380e"} {"source_code": "gets.to_i.times do\n n,k = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i).sort\n if a[0]+k < a[-1]-k\n puts \"-1\"\n else\n puts a[0]+k\n end\nend", "positive_code": [{"source_code": "q = gets.chomp.to_i\n\nfor ii in 1..q\n _min = 100000000\n _max = 0\n\n (n,k) = gets.chomp.split(\" \")\n k = k.to_i\n gets.chomp.split(\" \").each do |num|\n num = num.to_i\n _min = _min > num ? num : _min\n _max = _max > num ? _max : num\n end\n\n if _max - _min > k*2\n puts -1\n else\n puts _min + k\n end\nend"}, {"source_code": "t = gets.to_i\n(1..t).each do\n res = 0\n read = gets.split(\" \").map{|c| c.to_i}\n n = read[0]\n k = read[1]\n prices = gets.split(\" \").map{|c| c.to_i}\n mini = 1000000000\n maxi = 0\n prices.each do |price|\n mini = price if price < mini\n maxi = price if price > maxi\n end\n if (mini-maxi).abs > k * 2\n res = -1\n else\n res = mini + k\n end\n puts res\nend"}, {"source_code": "q = gets.to_i\nq.times do\n n,k = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n if a.min + k < a.max - k\n p -1\n else\n p a.min + k\n end\nend\n"}, {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort{|x,y|y<=>x} end##\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/22*k\n puts -1\n next\n end\n\n puts min+k\n end"}, {"source_code": "def test_cases(testCase)\n for interator in (0...testCase)\n (no_of_products, differ) = gets.chomp.split(' ').collect{|var| var.to_i}\n products = gets.chomp.split(' ').collect{|var| var.to_i}\n greatest_number = products.max\n smallest_number = products.min\n if(greatest_number - differ <= smallest_number + differ)\n puts smallest_number + differ\n else\n puts -1\n end\n end\nend\ntestCase = gets.chomp.to_i\ntest_cases(testCase)"}], "negative_code": [], "src_uid": "3b158306d335459ff55dcf29e46010e8"} {"source_code": "def norm(s)\n s.gsub('u', 'oo').gsub('oo', 'u').gsub(/k+h/, 'h')\nend\n\nn = gets.to_i\nws = n.times.map{gets.strip}\nputs ws.map{|w| norm(w)}.uniq.size\n", "positive_code": [{"source_code": "#! /usr/bin/env ruby\n\nn = gets.to_i\na = (1..n).map { gets.gsub(/k+h/, 'h').gsub('u', 'oo') }.sort.uniq\nputs a.size\n"}, {"source_code": "number = ''\nnumber = gets.chomp\nn = number.to_i\nres = {}\nn.times do \n str = gets.chomp\n str.gsub!(/u/, 'oo')\n str.gsub!(/k+h/, 'h')\n res[str] = 1\nend\nputs res.size"}], "negative_code": [], "src_uid": "63430b7b85e67cc3539b63c84ee7c57f"} {"source_code": "a,b,n=gets.split.map &:to_i\n-1000.upto(1000){|_|\n\tif a*_**n==b then\n\t\tp _\n\t\texit\n\tend\n}\nprint 'No solution'\n", "positive_code": [{"source_code": "s = gets\nn1,n2,n3 = s.split(/ /)\nA=n1.to_i\nB=n2.to_i\nn=n3.to_i\nret = \"No solution\"\n\nfor x in -1000..1000\n\tif A*(x**n) == B then\n\t\tret = x\n\t\tbreak\t\n\tend\nend\nputs ret\n\n\n"}, {"source_code": "#!/usr/bin/ruby\na,b,n=gets.split.map(&:to_i)\nif a==0\n\tputs b==0 ? 1 : 'No solution'\n\texit\nend\nif a<0 then a=-a;b=-b end\nsign=1\nif b<0\n\tsign=-1 if n.odd?\n\tb=-b\nend\nr=(b.to_f/a)**(1.0/n)+1e-9\nif (r-r.to_i).abs>1e-8 then puts 'No solution';exit end\np r.to_i*sign"}, {"source_code": "input=gets.split.map(&:to_i)\na=input[0]\nb=input[1]\nn=input[2]\n-1000.upto(1000){|ans|\n if a*(ans**n)==b then\n puts ans\n exit\n end \n}\nputs \"No solution\"\n"}, {"source_code": "a,b,n=gets.split.map &:to_i\n-1000.upto(1000){|_|\n\tif a*_**n==b then\n\t\tp _\n\t\texit\n\tend\n}\nprint 'No solution'\n"}, {"source_code": "a,b,n=gets.split.map &:to_i\n-1000.upto(1000){|_|\n\tif a*_**n==b then\n\t\tp _\n\t\texit\n\tend\n}\nprint 'No solution'\n"}, {"source_code": "a,b,n=gets.split.map &:to_i\n-1000.upto(1000){|_|\n\tif a*_**n==b then\n\t\tp _\n\t\texit\n\tend\n}\nprint 'No solution'"}, {"source_code": "a,b,n=gets.split.map &:to_i\n-1000.upto(1000){|_|\n\tif a*_**n==b then\n\t\tp _\n\t\texit\n\tend\n}\nprint 'No solution'\n"}, {"source_code": "a,b,n=gets.split.map &:to_i\n-1000.upto(1000){|_|\n if a*_**n==b then\n p _\n exit\n end\n}\nprint 'No solution'"}, {"source_code": "#!/usr/bin/ruby\n\n(a,b,n) = gets.split(\" \")\na = a.to_i()\nb = b.to_i()\nn = n.to_i()\n\nfor x in -1000..1000\n if a * (x**n) == b\n puts x\n exit()\n end\nend\n\nputs \"No solution\"\nexit()\n"}, {"source_code": "a,b,n=gets.split.map &:to_i\n-1000.upto(1000){|_|\n\tif a*_**n==b then\n\t\tp _\n\t\texit\n\tend\n}\nprint 'No solution'"}, {"source_code": "a,b,n=gets.split.map &:to_i\n-1000.upto(1000){|_|\n\tif a*_**n==b then\n\t\tp _\n\t\texit\n\tend\n}\nprint 'No solution'\n"}, {"source_code": "def pow(x,p)\n res = 1\n 1.upto(p){\n res = res*x\n }\n return res\nend\n\ndef bsearch(l, r, n, a, b)\n if (b%a != 0)\n return 0, true\n end\n\n c = b/a\n\n l.upto(r) { |i|\n return i, false if pow(i,n)==c\n }\n return 0, true\nend\n\nv = gets.split(' ')\nA,B,n = v[0].to_i, v[1].to_i, v[2].to_i\nno_solution = false\nx=0\nif n==0\n no_solution = true\n else\n x=0\n end if ((A==0) && (B==0))\n\nno_solution = true if ((A==0) && (B!=0))\n\nif n==0\n no_solution = true\n else\n x=0\n end if ((A>0) && (B==0))\n\nif n.even?\n no_solution = true\n else\n x, no_solution = bsearch(-1001, 1001, n, A, B)\n end if ((A>0) && (B<0))\n\nx, no_solution = bsearch(-1001, 1001, n, A, B) if ((A>0) && (B>0))\n\nx, no_solution = bsearch(-1001, 1001, n, A, B) if ((A<0)&&(B<0))\n\nif n==0\n no_solution = true\n else\n x=0\n end if ((A<0)&&(B==0))\n\nif ((A<0)&&(B>0))\n if n.even?\n no_solution = true\n else\n x, no_solution = bsearch(-1001, 1001, n, A, B)\n end\nend\n\nif no_solution\n puts \"No solution\"\nelse\n puts x\nend"}, {"source_code": "mas = gets.split(\" \")\na = mas[0].to_i\nb = mas[1].to_i\nn = mas[2].to_i\n\nif (a == 0 && b == 0)\n puts 5\n exit\nend\n\nif ((a == 0) || (b % a != 0) || (b / a < 0 && n % 2 == 0))\n puts \"No solution\"\n exit\nend\n\nresult = ((b/a).abs)**(1.0/n)\n\n# /b/erd\nif (result - result.round).abs < 0.000000001\n if (b/a < 0)\n print \"-\"\n end\n print result.round.to_s.split(\".\")[0]\nelse\n puts \"No solution\"\nend\n"}, {"source_code": "a,b,n=gets.split.map &:to_i\n-1000.upto(1000){|_|\n\tif a*_**n==b then\n\t\tp _\n\t\texit\n\tend\n}\nprint 'No solution'\n"}, {"source_code": "a,b,n=gets.split.map &:to_i\n-1000.upto(1000){|_|\n\tif a*_**n==b then\n\t\tp _\n\t\texit\n\tend\n}\nprint 'No solution'\n"}, {"source_code": "a,b,n=gets.split.map &:to_i\n-1000.upto(1000){|_|\n\tif a*_**n==b then\n\t\tp _\n\t\texit\n\tend\n}\nprint 'No solution'\n"}], "negative_code": [{"source_code": "s = gets\nn1,n2,n3 = s.split(/ /)\nA=n1.to_i\nB=n2.to_i\nn=n3.to_i\n\nif(A==0)\n\tif(B==0) \n\t\tputs \"1\"\n\telse\n\t\tputs \"No solution\"\n\tend\nelse\n\tc = (Float(B)/A).abs**(1.0/n)\n\t c = -c if (n%2>0 && (B/A)<0) \n\twk = c.floor\n\tif (Float(wk) < c)\n\t\tputs \"No solution\"\n\telse\n\t\tputs wk\n\tend\nend\n"}, {"source_code": "s = gets\nn1,n2,n3 = s.split(/ /)\nA=n1.to_i\nB=n2.to_i\nn=n3.to_i\n\nif(A==0)\n\tif(B==0) \n\t\tputs \"5\"\n\telse\n\t\tputs \"No solution\"\n\tend\nelse\n\tc = (Float(B)/A).abs**(1.0/n)\n\t c = -c if (n%2>0 && (B/A)<0) \n\twk = c.floor\n\tif (Float(wk) < c)\n\t\tputs \"No solution\"\n\telse\n\t\tputs wk\n\tend\nend\n"}, {"source_code": "#!/usr/bin/ruby\na,b,n=gets.split.map(&:to_i)\nif a==0 then p 1;exit end\nif a<0 then a=-a;b=-b end\nsign=1\nif b<0\n\tsign=-1 if n.odd?\n\tb=-b\nend\nr=(b.to_f/a)**(1.0/n)\nif r!=r.to_i then puts 'No solution';exit end\np r.to_i*sign"}, {"source_code": "#!/usr/bin/ruby\na,b,n=gets.split.map(&:to_i)\nif a==0\n\tputs b==0 ? 1 : 'No solution'\n\texit\nend\nif a<0 then a=-a;b=-b end\nsign=1\nif b<0\n\tsign=-1 if n.odd?\n\tb=-b\nend\nr=(b.to_f/a)**(1.0/n)\nif r!=r.to_i then puts 'No solution';exit end\np r.to_i*sign"}, {"source_code": "#!/usr/bin/ruby\na,b,n=gets.split.map(&:to_i)\nif a==0\n\tputs b==0 ? 1 : 'No solution'\n\texit\nend\nif a<0 then a=-a;b=-b end\nsign=1\nif b<0\n\tsign=-1 if n.odd?\n\tb=-b\nend\nr=(b.to_f/a)**(1.0/n)+1e-7\nif (r-r.to_i).abs>1e-7 then puts 'No solution';exit end\np r.to_i*sign"}, {"source_code": "mas = gets.split(\" \")\na = mas[0].to_i\nb = mas[1].to_i\nn = mas[2].to_i\n\nif (a == 0 && b == 0)\n puts 5\n exit\nend\n\nif ((a == 0) || (b % a != 0) || (b / a < 0 && n % 2 == 0))\n puts \"No solution\"\n exit\nend\n\nresult = ((b/a).abs)**(1.0/n)\n\n# /b/erd\nif result.to_s.split(\".\")[1].to_f == 0\n if (b/a < 0)\n print \"-\"\n end\n print result.to_s.split(\".\")[0]\nelse\n puts \"No solution\"\nend\n"}, {"source_code": "mas = gets.split(\" \")\na = mas[0].to_i\nb = mas[1].to_i\nn = mas[2].to_i\n\nif (a == 0 && b == 0)\n puts 5\n exit\nend\n\nif ((a == 0) || (b % a != 0) || (b / a < 0 && n % 2 == 0))\n puts \"No solution\"\n exit\nend\n\nresult = ((b/a).abs)**(1.0/n)\n\n# /b/erd\nif (result.to_s.split(\".\")[1].to_f).abs < 0.000000001\n if (b/a < 0)\n print \"-\"\n end\n print result.to_s.split(\".\")[0]\nelse\n if (a == 1 && b == 1000 && n == 3)\n puts result.to_s.split(\".\")[1].to_f\n end\n puts \"No solution\"\n\nend\n"}, {"source_code": "mas = gets.split(\" \")\na = mas[0].to_i\nb = mas[1].to_i\nn = mas[2].to_i\n\nif (a == 0 && b == 0)\n puts 5\n exit\nend\n\nif ((a == 0) || (b % a != 0) || (b / a < 0 && n % 2 == 0))\n puts \"No solution\"\n exit\nend\n\nresult = ((b/a).abs)**(1.0/n)\n\n# /b/erd\nif (result.to_s.split(\".\")[1].to_f).abs < 0.000000001\n if (b/a < 0)\n print \"-\"\n end\n print result.to_s.split(\".\")[0]\nelse\n puts \"No solution\"\nend\n"}, {"source_code": "mas = gets.split(\" \")\na = mas[0].to_i\nb = mas[1].to_i\nn = mas[2].to_i\n\nif (a == 0 && b == 0)\n puts 5\n exit\nend\n\nif ((a == 0) || (b % a != 0) || (b / a < 0 && n % 2 == 0))\n puts \"No solution\"\n exit\nend\n\nresult = ((b/a).abs)**(1.0/n)\n\n# /b/erd\nif (result - result.round).abs < 0.000000001\n if (b/a < 0)\n print \"-\"\n end\n print result.to_s.split(\".\")[0]\nelse\n if (a == 1 && b == 1000 && n == 3)\n result - result.round\n end\n puts \"No solution\"\n\nend\n"}, {"source_code": "mas = gets.split(\" \")\na = mas[0].to_i\nb = mas[1].to_i\nn = mas[2].to_i\n\nif (a == 0 && b == 0)\n puts 5\n exit\nend\n\nif ((a == 0) || (b % a != 0) || (b / a < 0 && n % 2 == 0))\n puts \"No solution\"\n exit\nend\n\nresult = ((b/a).abs)**(1.0/n)\n\n# /b/erd\nif (result.to_s.split(\".\")[1].to_f).abs < 0.000000001\n if (b/a < 0)\n print \"-\"\n end\n print result.to_s.split(\".\")[0]\nelse\n if (a == 1 && b == 1000 && n == 3)\n result.to_s.split(\".\")[1].to_f\n end\n puts \"No solution\"\n\nend\n"}], "src_uid": "8a9adc116abbd387a6a64dd754436f8a"} {"source_code": "p,q,l,r=gets.chomp.split.map(&:to_i)\na,b,c,ans=[],[],Array.new(1005,0),0\np.times do\n\tx,y=gets.chomp.split.map(&:to_i)\n\ta<=l && j<=r && c[j]==0\n\t\t\t\tans+=1\n\t\t\t\tc[j]=1\n\t\t\tend\n\t\t\tj+=1\n\t\tend\n\tend\nend\nputs ans", "positive_code": [{"source_code": "p, q, l, r = gets.chomp.split(' ').map(&:to_i)\n\nx = []\np.times do\n a, b = gets.chomp.split(' ').map(&:to_i)\n #puts \">> #{a} #{b} #{a..b}\"\n x.concat (a..b).to_a\nend\n\ny = []\nq.times do\n c, d = gets.chomp.split(' ').map(&:to_i)\n y.concat (c..d).to_a\nend\nhy = {}\ny.each { |e| hy[e] = true }\n\nres = 0\n(l..r).each do |i|\n found = false\n x.each do |xi|\n if hy[xi-i]\n found = true\n break\n end\n end\n\n res += 1 if found\nend\n\nputs res"}, {"source_code": "p,q,l,r = gets.split(\" \").map(&:to_i)\nfirst = []\nsecond = []\np.times do\n\tx,y = gets.split(\" \").map(&:to_i)\n\tfirst << (x..y).to_a\nend\nfirst.flatten!\n\nq.times do\n\tx,y = gets.split(\" \").map(&:to_i)\n\tsecond << (x..y).to_a\nend\nsecond.flatten!\n# puts \"first #{first}\"\n# puts \"sec #{second}\"\ncount = 0\n(l..r).each do |i|\n\tcount += 1 unless (first & second.map{|a| a + i}).empty?\nend\nputs count"}, {"source_code": "def read_next_line\n gets.chomp.split.map &:to_i\nend\n\np, q, l, r = read_next_line\na = (p + q).times.map { read_next_line }\nx, y = a[0...p], a[p..-1]\nputs (l..r).to_a.select { |m|\n s = t = 0\n res = false\n while s < p\n t += 1 while t < q && x[s][0] > y[t][1] + m\n if t == q\n break\n elsif x[s][1] >= y[t][0] + m\n res = true\n break\n end\n s += 1\n end\n res\n}.count"}, {"source_code": "p, q, l, r = gets.split.map(&:to_i)\nps, qs = [], []\np.times {ps << gets.split.map(&:to_i)}\nq.times {qs << gets.split.map(&:to_i)}\ncount = 0 \ncan = false\nl.upto(r).each do |t|\n can = false\n ps.each do |pp|\n qs.each do |qq|\n next if pp[0] > qq[1] + t\n break if pp[1] < qq[0] + t\n if pp[0].between?((qq[0]+t), (qq[1]+t)) || pp[1].between?((qq[0]+t), (qq[1]+t)) || (qq[0]+t).between?(pp[0], pp[1]) || (qq[1]+t).between?(pp[0], pp[1])##(pp[0] <= (qq[0]+t) && pp[1] >= (qq[0]+t)) || (pp[0] <= (qq[1]+t) && pp[1] >= (qq[1]+t)) #((pp[0]..pp[1]).to_a & ((qq[0]+t)..(qq[1]+t)).to_a).any?\n can = true \n break\n end\n end\n break if can\n end\n count += 1 if can \nend\n# qs.each do |qq|\n# ps.each do |pp|\n# if pp[1] >= qq[0] && qq[0].between?(pp[0], pp[1])\n# count += 1 \n# elsif pp[1] >= qq[0]\n# c = pp[0] - qq[1] \n# if c.between?(l, r)\n# count += 1 \n# end\n# end\n# end\n# end\n\nputs count"}, {"source_code": "p, q, l, r = gets.chomp.split(' ').map(&:to_i)\n\nstr1 = '0' * 1001\nstr2 = '0' * 1001\n\np.times do\n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\tstr1[a..b]='1' * (b-a+1)\nend\n\nq.times do\n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\tstr2[a..b]='1' * (b-a+1)\nend\n\nstr2.prepend('0' * l)\n\nans = 0\n(r-l+1).times do\n\t\n\tfor i in 0..(-1+str1.length)\n\t\tif (str1[i]=='1' and str2[i]=='1')\n\t\t\tans=ans+1\n\t\t\tbreak\n\t\tend\n\tend\n\t\n\tstr2.prepend('0')\n\t\nend\nputs ans\n"}, {"source_code": "#! /usr/bin/env ruby\n# -*- coding: utf-8 -*-\n# vim:fenc=utf-8\n#\n# Copyright \u00a9 2014 Szymon Sliwa \n#\n# Distributed under terms of the MIT license.\n\np, q, l, r = gets.split.map(&:to_i)\n\ntab_p, tab_q = [], []\np.times do\n tab_p << gets.split.map(&:to_i)\nend\nq.times do\n tab_q << gets.split.map(&:to_i)\nend\n\np_present = {}\ntab_p.each do |x|\n (x[0]..x[1]).each do |y|\n p_present[y] = true\n end\nend\n\npossible_diffs = {}\ntab_q.each do |x|\n (x[0]..x[1]).each do |y|\n p_present.to_a.map do |a|\n possible_diffs[a[0]-y] = true\n end\n end\nend\n\nputs possible_diffs.to_a.select{|a| a[0] >= l && a[0] <= r}.size\n\n\n\n\n\n"}, {"source_code": "p, q, l, r = STDIN.readline.split.map {|s| s.to_i }\nx_pairs, z_pairs = [], []\np.times { x_pairs.push(STDIN.readline.split.map {|s| s.to_i }) }\nx_bits = Array.new(1001, false)\nx_pairs.each do |a, b|\n\t(a..b).each {|i| x_bits[i] = true }\nend\nq.times { z_pairs.push(STDIN.readline.split.map {|s| s.to_i }) }\ncount = 0\n(l..r).each do |t|\n\tfound = false\n\tz_pairs.each do |c, d|\n\t\t(c..d).each do |i|\n\t\t\tif x_bits[i+t]\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\t\tbreak if found\n\tend\n\tcount += 1 if found\nend\nputs count\n"}, {"source_code": "p, q, l, r = STDIN.readline.split.map {|s| s.to_i }\nx_pairs, z_pairs = [], []\np.times { x_pairs.push(STDIN.readline.split.map {|s| s.to_i }) }\nx = 0\nx_pairs.each do |a, b|\n\t(a..b).each {|i| x |= (1 << i) }\nend\nq.times { z_pairs.push(STDIN.readline.split.map {|s| s.to_i }) }\nz = 0\nz_pairs.each do |c, d|\n\t(c..d).each {|i| z |= (1 << i) }\nend\ncount = 0\n(l..r).each {|t| count += 1 if (x & (z << t)) != 0 }\nputs count\n"}, {"source_code": "def check(ztime, xtime, t)\n ztime.each do |a, b|\n xtime.each do |c, d|\n break if c + t > b\n next if b < c + t\n return true if (c + t).between?(a, b) || (d + t).between?(a, b)\n return true if a.between?(c + t, d + t) || b.between?(c + t, d + t)\n end\n end\n\n false\nend\n\np, q, l, r = gets.split.map(&:to_i)\n\nztime = []\np.times { ztime << gets.split.map(&:to_i) }\n\nxtime = []\nq.times { xtime << gets.split.map(&:to_i) }\n\nputs l.upto(r).select { |t| check(ztime, xtime, t) }.size\n"}], "negative_code": [{"source_code": "def check(xtime, ztime, getup)\n xtime.each do |a, b|\n ztime.each do |c, d|\n return true if (c + getup).between?(a, b) || (d + getup).between?(a, b)\n end\n end\n\n false\nend\n\np, q, l, r = gets.split.map(&:to_i)\n\nxtime = []\np.times { xtime << gets.split.map(&:to_i) }\n\nztime = []\nq.times { ztime << gets.split.map(&:to_i) }\n\nputs l.upto(r).select { |getup| check(xtime, ztime, getup) }.size\n"}, {"source_code": "p, q, l, r = gets.split.map(&:to_i)\nps, qs = [], []\np.times {ps << gets.split.map(&:to_i)}\nq.times {qs << gets.split.map(&:to_i)}\ncount = 0 \n(l..r).each do |t|\n can= false\n qs.each do |qq|\n ps.each do |pp|\n if (pp[0] <= (qq[0]+t) && pp[1] >= (qq[0]+t)) #((pp[0]..pp[1]).to_a & ((qq[0]+t)..(qq[1]+t)).to_a).any?\n can = true \n break\n end\n end\n break if can\n end\n count += 1 if can \nend\n\nputs count"}, {"source_code": "p, q, l, r = gets.split.map(&:to_i)\nps, qs = [], []\np.times {ps << gets.split.map(&:to_i)}\nq.times {qs << gets.split.map(&:to_i)}\ncount = 0 \n(l..r).each do |t|\n can= false\n qs.each do |qq|\n ps.each do |pp|\n if (pp[0] <= (qq[0]+t) && pp[1] >= (qq[0]+t)) || (pp[0] <= (qq[1]+t) && pp[1] >= (qq[1]+t)) #((pp[0]..pp[1]).to_a & ((qq[0]+t)..(qq[1]+t)).to_a).any?\n can = true \n break\n end\n end\n break if can\n end\n count += 1 if can \nend\n\nputs count"}, {"source_code": "p, q, l, r = gets.chomp.split(' ').map(&:to_i)\n\nstr1 = '0' * 40\nstr2 = '0' * 40\n\np.times do\n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\tstr1[(a-1)..(b-1)]='1' * (b-a+1)\nend\n\nq.times do\n\ta, b = gets.chomp.split(' ').map(&:to_i)\n\tstr2[(a-1)..(b-1)]='1' * (b-a+1)\nend\n\nstr2.prepend('0' * l)\n\nans = 0\n(r-l+1).times do\n\t\n\tfor i in 0..(-1+str1.length)\n\t\tif (str1[i]=='1' and str2[i]=='1')\n\t\t\tans=ans+1\n\t\t\tbreak\n\t\tend\n\tend\n\t\n\tstr2.prepend('0')\n\t\nend\nputs ans\n"}], "src_uid": "aa77158bf4c0854624ddd89aa8b424b3"} {"source_code": "n = gets.chomp.to_i\nl = gets.chomp.split.map(&:to_i)\nans, cmp = 0, n\n(n - 1).downto(0) do |i|\n ans += (i < cmp) ? 1 : 0\n cmp = [cmp, i - l[i]].min\nend\nprint ans", "positive_code": [{"source_code": "gets\nar = gets.split.map(&:to_i)\n\nptr = ar.length\nans = 0\n\n(ar.length-1).downto(0).each do |i|\n if ptr > i\n ans += 1 \n end\n ptr = [ptr, i-ar[i]].min\nend\n\nputs ans\n"}, {"source_code": "gets\nar = gets.split.map(&:to_i)\n\nptr = ar.length\nans = 0\n\n(ar.length-1).downto(0).each do |i|\n ans += 1 if ptr > i\n ptr = [ptr, i-ar[i]].min\nend\n\nputs ans\n"}], "negative_code": [], "src_uid": "beaeeb8757232b141d510547d73ade04"} {"source_code": "t = gets.chomp.to_i\nt.times do \n n = gets.chomp.to_i\n arr = gets.chomp.split(' ').map(&:to_i)\n brr = arr.reverse\n brr.each_with_index do |_, i|\n brr[i] *= -1 if i % 2 == 0\n end\n puts brr.join ' '\nend ", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n b = Array.new(n)\n\n (n / 2).times do |i|\n b[2 * i] = -a[2 * i + 1]\n b[2 * i + 1] = a[2 * i]\n end\n\n puts b.join(' ')\nend\n"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n arr = []\n (n/2).times do |i|\n lcm = a[i*2].lcm(a[i*2+1])\n arr << lcm / a[i*2]\n arr << -(lcm / a[i*2+1])\n end\n ans << arr\nend\nans.each do |ar|\n ar.each do |v|\n print \"#{v} \"\n end\n puts \"\"\nend"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n b = []\n (n / 2).times do |i|\n b.push(-a[i * 2 + 1])\n b.push(a[i * 2])\n end\n puts b.join(\" \")\nend\n"}], "negative_code": [], "src_uid": "d5e09a8fb7eeeba9a41daa2b565866ba"} {"source_code": "N, B, A = gets.split.map(&:to_i)\nS = gets.chomp.split\n\nans = 0\n\nb = B\na = A\n\nS.each do |s|\n case s\n when '0'\n if a > 0\n a -= 1\n elsif b > 0\n b -= 1\n else\n break\n end\n when '1'\n if b > 0 && a < A\n b -= 1\n a += 1\n elsif a > 0\n a -= 1\n elsif b > 0\n b -= 1\n else\n break\n end\n end\n\n ans += 1\nend\n\nputs ans\n", "positive_code": [{"source_code": "n,a,b = gets.split.map(&:to_i)\ns = gets.split.map(&:to_i)\nc = b*1\nn.times do |i|\n if s[i] == 0\n if c > 0\n c -= 1\n elsif a > 0\n a -= 1\n else\n puts i\n exit\n end\n else\n if a > 0 && c < b\n a -= 1\n c += 1\n elsif c > 0\n c -= 1\n else\n puts i\n exit\n end\n end\nend\nputs n"}], "negative_code": [{"source_code": "n,a,b = gets.split.map(&:to_i)\ns = gets.split.map(&:to_i)\nc = b\nn.times do |i|\n if s[i] == 0\n if c > 0\n c -= 1\n elsif a > 0\n a -= 1\n else\n puts i\n exit\n end\n else\n if a > 0\n a -= 1\n c += 1\n c -= 1 if c > b\n else\n puts i\n exit\n end\n end\nend\nputs n"}], "src_uid": "75ef1f52ef3a86992159eef566dddc89"} {"source_code": "gets.to_i.times{k=gets.split[1].to_i\na=[nil]*k\nputs gets.chop.chars.zip(0..).map{|x,i|i%=k;x==??||a[i]==x||!a[i]&&a[i]=x}.all?&&a.compact.tally.values.push(0).max<=k/2 ?\"YES\":\"NO\"}", "positive_code": [{"source_code": "gets.to_i.times{k=gets.split[1].to_i\na=[nil]*k\nputs gets.chop.chars.zip(0..).map{|x,i|i%=k;x==??||a[i]==x||!a[i]&&a[i]=x}.all?&&[?0,?1].map{|x|a.take(k).count x}.max<=k/2 ?\"YES\":\"NO\"}"}], "negative_code": [], "src_uid": "8e448883014bf7cd35fcca3fe0128af0"} {"source_code": "gets # Skip the first line\nfp = gets.chomp\nif fp.include?('R')\n if fp.include?('L')\n puts \"#{fp.index('R') + 1} #{fp.rindex('R') + 1}\"\n else\n puts \"#{fp.index('R') + 1} #{fp.rindex('R') + 2}\"\n end\nelse\n puts \"#{fp.rindex('L') + 1} #{fp.index('L')}\"\nend", "positive_code": [{"source_code": "n = gets.to_i\npath = gets.chomp.split('')\ns = nil\nr = nil\nt = nil\nl = nil\n0.upto(n-1) do |i|\n\ts = i+1 if(path[i]=='R')&&(s.nil?)\n \tr = i+1 if(path[i]!='R')&&(!s.nil?)&&(r.nil?)\t\n\tt = i if(path[i]=='L')&&(t.nil?)\n\tl = i if(path[i]!='L')&&(!t.nil?)&&(l.nil?)\nend\ns = l if s.nil?\nt = r if t.nil?\nputs \"#{s} #{t}\"\n"}, {"source_code": "n = gets.chomp.to_i\npath = gets.chomp\nls = []\nrs = []\nn.times do |i|\n c = path[i]\n ls << i + 1 if c == 'L'\n rs << i + 1 if c == 'R'\nend\ns = t = 0\nif ls.length == 0\n s = rs.min\n t = rs.max + 1\nelsif rs.length == 0\n s = ls.max\n t = ls.min - 1\nelse\n s = rs.min\n t = rs.max + 1\nend\nputs \"#{s} #{t}\"\n"}, {"source_code": "gets.to_i\ns = gets\nif s.index('R').nil?\n b = s.index('L')\n a = s.index('.', b)\nelsif s.index('L').nil?\n a = s.index('R') + 1\n b = s.index('.', a - 1) + 1\nelse\n a = s.index('R') + 1\n b = s.index('L')\nend\nputs \"#{a} #{b}\"\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\ns,t=a.rindex('R'),a.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\"\n"}, {"source_code": "n = gets.to_i\narr = gets.split(\"\")\nl_index = arr.index(\"L\")\nr_index = arr.index(\"R\")\nl_last_index = arr.rindex(\"L\")\nr_last_index = arr.rindex(\"R\")\n\nans = false\n\nunless l_index\n\ts,t = r_index,r_last_index+1\n\tans = true\nend\n\nunless r_index\n\ts,t = l_last_index,l_index - 1\n\tans = true\nend\n\nif !ans\t\n\ts,t = r_index,r_last_index\nend\n\nputs \"#{s+1} #{t+1}\""}, {"source_code": "#!/usr/bin/ruby -w\nn = gets\ns = gets\ni = 0\nwhile s[i] == '.' do\n i = i + 1\nend\nprint i + 1\nprint \" \"\nwhile s[i] != 'L' && s[i] != '.' do\n i = i + 1\nend\nif(s[i] == '.') \nprint i + 1\nelse\n print i\nend\nputs"}, {"source_code": "n = gets.to_i\nblocks = gets.chomp\ns = blocks.index(\"R\")\nif s\n puts [s+1, n-blocks.reverse.index(\"R\")+1].join(\" \")\n exit\nend\nt = blocks.index(\"L\")\nif t\n puts [n-blocks.reverse.index(\"L\"),t].join(\" \")\nend\n"}, {"source_code": "l=gets.to_i\ns=gets.split(//)\ni=0\nx=-1\ny=-1\nwhile (i=0) do\n if (s[i]=='L') then x=i; end\n i-=1\nend\nif (x==-1) then print(y+1,\" \",y+2,\"\\n\");\nelse\n if (y==-1) then print(x+1,\" \",x,\"\\n\");\n else print(x+1,\" \",x+1,\"\\n\"); \n end \nend"}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\ns,t=a.rindex('R'),a.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\"\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\ns,t=a.rindex('R'),a.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\"\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\ns,t=a.rindex('R'),a.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\"\n"}, {"source_code": "gets\ngets\nif x = $_ =~ /R+[^L]?/\n puts \"#{x + 1} #{x + $&.size}\"\nelsif x = $_ =~ /L+/\n puts \"#{x + $&.size} #{x}\"\nend\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\ns,t=a.rindex('R'),a.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\"\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\ns,t=a.rindex('R'),a.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\"\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\ns,t=a.rindex('R'),a.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\""}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\ns,t=a.rindex('R'),a.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\""}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\nen,st=0,0\nfor i in 0...a.length\n\tbreak if a[i]!='.'\nend\nif a[i]=='R'\n\tst=i\n\ti+=1 while a[i]=='R'\n\ten = (a[i]=='L')? i-1 : i\nelse\n\ten=i-1\n\ti+=1 while a[i]=='L'\n\tst=i-1\nend\nputs \"#{st+1} #{en+1}\""}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\ns,t=a.rindex('R'),a.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\""}, {"source_code": "n = gets.to_i\nmoves = gets\nstrs = moves.index 'R'\nends = moves.rindex 'R'\nif strs.nil?\n strs = moves.rindex 'L'\n ends = moves.index 'L'\n ends -= 1\nelse \n ends += 1\nend\nputs \"#{strs + 1} #{ends + 1}\""}, {"source_code": "def run\n n = $stdin.gets.to_i\n str = $stdin.gets.split(//)\n\n s = str.rindex('R')\n t = str.index('L')\n\n if s != nil\n puts \"#{s + 1} #{s + 2}\"\n else\n puts \"#{t + 1} #{t}\"\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.to_i\ni = gets.split(//)\ns = i.rindex('R')\nt = i.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\""}, {"source_code": "class A\n def initialize\n n = $stdin.gets.chomp.to_i\n step = $stdin.gets.chomp.split('')\n\n s = t = 0\n s_flag = true\n t_flag = true\n r_max = 0\n l_max = 0\n\n step.each_with_index do |ch, index|\n if ch == 'R' && s_flag\n s = index+1\n s_flag = false\n elsif ch == 'L' && t_flag \n t = index\n t_flag = false\n end\n\n if ch == 'R'\n r_max = index+1\n elsif ch == 'L'\n l_max = index+1\n end\n end\n\n if s_flag \n s = l_max\n end\n\n if t_flag \n t = r_max + 1\n end\n\n puts \"#{s} #{t}\"\n end\nend\n\na = A.new"}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\ns,t=a.rindex('R'),a.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\"\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\ns,t=a.rindex('R'),a.index('L')\nputs s ? \"#{s+1} #{s+2}\" : \"#{t+1} #{t}\"\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\npath = gets.chomp\ns = t = 0\ndir = nil\nn.times do |c|\n s = c + 1 if path[c] != '.' && s == 0\n dir = path[c] if dir.nil? && path[c] != '.'\n t = c - 1 if !dir.nil? && path[c] != '.' && dir != path[c]\nend\nputs \"#{s} #{t}\"\n"}, {"source_code": "gets.chomp.to_i\npath = gets.chomp\nindex = 0\npos = []\nfinish = false\nwhile !finish\n c = path[index]\n if c != '.'\n if c == 'R'\n index += 1\n if !pos.include?( index )\n pos << index\n else\n finish = true\n end\n else\n index -= 1\n if !pos.include?( index )\n pos << index\n else\n finish = true\n end\n end\n next\n end\n index += 1\nend\ns = pos.min\nt = pos.max\nputs \"#{s} #{t}\"\n"}, {"source_code": "n = gets.chomp.to_i\npath = gets.chomp\nls = []\nrs = []\nn.times do |i|\n c = path[i]\n ls << i + 1 if c == 'L'\n rs << i + 1 if c == 'R'\nend\ns = t = 0\nif ls.length == 0\n s = rs.min\n t = rs.max\nelsif rs.length == 0\n s = ls.max\n t = ls.min\nelse\n s = rs.min\n t = rs.max\nend\nputs \"#{s} #{t}\"\n"}, {"source_code": "n = gets.to_i\narr = gets.split(\"\")\nl_index = arr.index(\"L\")\nr_index = arr.index(\"R\")\nl_last_index = arr.rindex(\"L\")\nr_last_index = arr.rindex(\"R\")\n\nans = false\n\nunless l_index\n\ts,t = r_index,r_last_index\n\tans = true\nend\n\nunless r_index\n\ts,t = l_last_index,l_index\n\tans = true\nend\n\nif !ans\t\n\ts,t = r_index,r_last_index\nend\n\nputs \"#{s+1} #{t+1}\""}, {"source_code": "n = gets.to_i\narr = gets.split(\"\")\nl_index = arr.index(\"L\")\nr_index = arr.index(\"R\")\nl_last_index = arr.rindex(\"L\")\nr_last_index = arr.rindex(\"R\")\n\nans = false\n\nunless l_index\n\ts,t = r_index,r_last_index+1\n\tans = true\nend\n\nunless r_index\n\ts,t = l_last_index-1,l_index\n\tans = true\nend\n\nif !ans\t\n\ts,t = r_index,r_last_index\nend\n\nputs \"#{s+1} #{t+1}\""}, {"source_code": "n = gets.to_i\narr = gets.split(\"\")\nl_index = arr.index(\"L\")\nr_index = arr.index(\"R\")\nl_last_index = arr.rindex(\"L\")\nr_last_index = arr.rindex(\"R\")\n\nans = false\n\nunless l_index\n\ts,t = r_index,r_last_index+1\n\tans = true\nend\n\nunless r_index\n\ts,t = l_last_index,l_index\n\tans = true\nend\n\nif !ans\t\n\ts,t = r_index,r_last_index\nend\n\nputs \"#{s+1} #{t+1}\""}, {"source_code": "l=gets.to_i\ns=gets.split(//)\ni=0\nx=-1\ny=-1\nwhile (i=0) do\n if (s[i]=='L') then x=i; end\n i-=1\nend\nif (x==-1) then print(y+1,\" \",y+1,\"\\n\");\nelse print(x+1,\" \",x+1,\"\\n\");end"}, {"source_code": "l=gets.to_i\ns=gets.split(//)\ni=0\nx=-1\ny=-1\nwhile (i=0) do\n if (s[i]=='L') then x=i; end\n i-=1\nend\nif (x==-1) then print(y+1,\" \",y,\"\\n\");\nelse\n if (y==-1) then print(x+1,\" \",x+2,\"\\n\");\n else print(x+1,\" \",x+1,\"\\n\"); \n end \nend"}, {"source_code": "gets\ngets\nif x = $_ =~ /R+[^L]?/\n puts \"#{x + 1} #{x + $&.size}\"\nelsif x = $_ =~ /L+/\n puts \"#{x + $&.size - 1} #{x - 1}\"\nend\n"}, {"source_code": "gets\ngets\nif x = $_ =~ /R+/\n puts \"#{x + 1} #{x + $&.size}\"\nelse x = $_ =~ /L+/\n puts \"#{x + $&.size - 1} #{x - 1}\"\nend\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split('')\nb=[]\na.each do |i|\n\tb<=p.floor+0.5\n\tk = p.floor+1\nelse\n\tk = p.floor\nend\n\nres = \"G\"*k+\"A\"*(n-k)\n\nputs res"}, {"source_code": "n = gets.to_i\n\n# a = []\n# g = []\n\nanswer = ''\na_cur = 0\ng_cur = 0\n\nn.times do |i|\n\ta, g = gets.split(' ').collect!{|i| i.to_i}\n\tif (a_cur + a - g_cur).abs <= 500\n\t\tanswer << \"A\"\n\t\ta_cur += a\n\telse\n\t\tanswer << \"G\"\n\t\tg_cur += g\n\tend\nend\n\n# answer = -1 if (a_cur - g_cur).abs > 500\n\nprint answer"}], "negative_code": [{"source_code": "def run\n n = $stdin.gets\n sa = 0\n sg = 0\n ret = \"\"\n $stdin.readlines.each do |line|\n a, g = line.split.map(&:to_i)\n if sa <= sg + 500\n sa += a\n ret += \"A\"\n else\n sg += g\n ret += \"G\"\n end\n end\n\n if (sa - sg).abs <= 500\n puts ret\n else\n puts \"-1\"\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n n = $stdin.gets.to_i\n sum = 0\n $stdin.readlines.each do |line|\n a, g = line.split.map(&:to_i)\n sum += a\n end\n\n i = n - (sum + 499) / 1000\n puts \"A\" * i + \"G\" * (n - 1)\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n n = $stdin.gets\n sa = 0\n sg = 0\n ret = \"\"\n $stdin.readlines.each do |line|\n a, g = line.split.map(&:to_i)\n if sa < sg\n sa += a\n ret += \"A\"\n else\n sg += g\n ret += \"G\"\n end\n end\n\n if (sa - sg).abs <= 500\n puts ret\n else\n puts \"-1\"\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n n = $stdin.gets\n sa = 0\n sg = 0\n ret = \"\"\n $stdin.readlines.each do |line|\n a, g = line.split.map(&:to_i)\n if sa <= sg\n sa += a\n ret += \"A\"\n else\n sg += g\n ret += \"G\"\n end\n end\n\n if (sa - sg).abs <= 500\n puts ret\n else\n puts \"-1\"\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.to_i\n\na = []\ng = []\n\na_sum = 0\ng_sum = 0\n\nn.times do |i|\n\ta[i], g[i] = gets.split(' ').collect!{|i| i.to_i}\n\ta_sum += a[i]\n\tg_sum += g[i]\nend\n\n# a_sr = a_sum / n\n# g_sr = g_sum / n\n\nanswer = ''\na_cur = 0\ng_cur = 0\n\n# n.times do |i|\n# \tif a_cur + a[i] < g_sr\n# \t\tanswer << \"A\"\n# \t\ta_cur += a[i]\n# \telsif g_cur + g[i] < a_sr\n# \t\tanswer << \"G\"\n# \t\tg_cur += g[i]\n# \telsif (a_cur + a_sum - g_cur - g_sum + g[i]).abs <= 500\n# \t\tanswer << \"A\"\n# \t\ta_cur += a[i]\n# \telsif (g_cur + g_sum - a_cur -a_sum + a[i]).abs <= 500\n# \t\tanswer << \"G\"\n# \t\tg_cur += g[i]\n# \telse\n# \t\tanswer = -1\n# \t\tbreak\n# \tend\n\n# \ta_sum -= a[i]\n# \tg_sum -= g[i]\n# end\n\nn.times do |i|\n\ta_sum -= a[i]\n\tg_sum -= g[i]\n\tif (a_cur + a[i] + a_sum - g_cur - g_sum).abs <= 500\n\t\tanswer << \"A\"\n\t\ta_cur += a[i]\n\telse\n\t\tanswer << \"G\"\n\t\tg_cur += g[i]\n\tend\nend\n# print answer\nanswer = -1 if (a_cur - g_cur).abs > 500\n\nprint answer"}, {"source_code": "n = gets.to_i\n\na = []\ng = []\n\n# a_sum = 0\n# g_sum = 0\n\nanswer = ''\na_cur = 0\ng_cur = 0\n\nn.times do |i|\n\ta[i], g[i] = gets.split(' ').collect!{|i| i.to_i}\n\t# a_sum += a[i]\n\t# g_sum += g[i]\n\n\tif g_cur >= a_cur\n\t\tanswer << \"A\"\n\t\ta_cur += a[i]\n\telse\n\t\tanswer << \"G\"\n\t\tg_cur += g[i]\n\tend\nend\n\nanswer = -1 if (a_cur - g_cur).abs > 500\n\nprint answer"}, {"source_code": "n = gets.to_i\n\na = []\ng = []\n\na_sum = 0\ng_sum = 0\nn.times do |i|\n\ta[i], g[i] = gets.split(' ').collect!{|i| i.to_i}\n\ta_sum += a[i]\n\tg_sum += g[i]\nend\n\nanswer = -1\n\nif (a_sum/n - g_sum/n).abs <= 500\n\tanswer = ''\n\ta.sort!.reverse!\n\tg.sort!.reverse!\n\ta_cur = 0\n\tg_cur = 0\n\n\tn.times do |i|\n\t\tif g_cur >= a_cur\n\t\t\tanswer << \"A\"\n\t\t\ta_cur += a[i]\n\t\telse\n\t\t\tanswer << \"G\"\n\t\t\tg_cur += g[i]\n\t\tend\n\tend\nend\n\nprint answer"}, {"source_code": "n = gets.to_i\n\na = []\ng = []\n\na_sum = 0\ng_sum = 0\n\nn.times do |i|\n\ta[i], g[i] = gets.split(' ').collect!{|i| i.to_i}\n\ta_sum += a[i]\n\tg_sum += g[i]\nend\n\na_sr = a_sum / n\ng_sr = g_sum / n\n\nanswer = ''\na_cur = 0\ng_cur = 0\n\nn.times do |i|\n\tif a_cur + a[i] < g_sr\n\t\tanswer << \"A\"\n\t\ta_cur += a[i]\n\telsif g_cur + g[i] < a_sr\n\t\tanswer << \"G\"\n\t\tg_cur += g[i]\n\telsif (a_cur + a_sum - g_cur - g_sum + g[i]).abs <= 500\n\t\tanswer << \"A\"\n\t\ta_cur += a[i]\n\telsif (g_cur + g_sum - a_cur -a_sum + a[i]).abs <= 500\n\t\tanswer << \"G\"\n\t\tg_cur += g[i]\n\telse\n\t\tanswer = -1\n\t\tbreak\n\tend\n\n\ta_sum -= a[i]\n\tg_sum -= g[i]\nend\n\nanswer = -1 if (a_cur - g_cur).abs > 500\n\nprint answer"}, {"source_code": "n = gets.to_i\ns_a = 0\ns_g = 0\nans = \"\"\nif n < 1000\nn.times do\n\ta,b = gets.split(\" \").map(&:to_i)\n\tif (s_a + a - s_g) <= 500\n\t\ts_a += a\n\t\tans << \"A\"\n\telse\n\t\ts_g += b\n\t\tans << \"G\"\n\tend\nend\nelse\n\tn.times do\n\t\ta,b = gets.split(\" \").map(&:to_i)\n\t\t(s_a + a - s_g) <= 500\n\tend\n\nend\nif (s_a - s_g).abs <= 500\n\tputs ans\nelse\n\tputs \"-1\"\nend\n"}, {"source_code": "n = gets.to_i\ns_a = 0\ns_g = 0\nans = \"A\"*n\nif n < 1000\nn.times do |i|\n\ta,b = gets.split(\" \").map(&:to_i)\n\tif (s_a + a - s_g) <= 500\n\t\ts_a += a\n\t\t# ans << \"A\"\n\telse\n\t\ts_g += b\n\t\tans[i] = \"G\"\n\tend\nend\nelse\nn.times do\n\ta,b = gets.split(\" \").map(&:to_i)\n\tif (s_a + a - s_g) <= 500\n\t\ts_a += a\n\t\t# ans << \"A\"\n\telse\n\t\ts_g += b\n\t\tans << \"G\"\n\tend\nend\n\nend\nif (s_a - s_g).abs <= 500\n\tputs ans\nelse\n\tputs \"-1\"\nend\n"}, {"source_code": "n = gets.to_i\ns_a = 0\ns_g = 0\nans = \"\"\nif n < 1000\nn.times do\n\ta,b = gets.split(\" \").map(&:to_i)\n\tif (s_a + a - s_g) <= 500\n\t\ts_a += a\n\t\tans << \"A\"\n\telse\n\t\ts_g += b\n\t\tans << \"G\"\n\tend\nend\nelse\nn.times do\n\ta,b = gets.split(\" \").map(&:to_i)\n\tif (s_a + a - s_g) <= 500\n\t\ts_a += a\n\t\t# ans << \"A\"\n\telse\n\t\ts_g += b\n\t\tans << \"G\"\n\tend\nend\n\nend\nif (s_a - s_g).abs <= 500\n\tputs ans\nelse\n\tputs \"-1\"\nend\n"}, {"source_code": "n = gets.to_i\ns_a = 0\ns_g = 0\nans = \"\"\nif n < 1000\nn.times do\n\ta,b = gets.split(\" \").map(&:to_i)\n\tif (s_a + a - s_g) <= 500\n\t\ts_a += a\n\t\tans << \"A\"\n\telse\n\t\ts_g += b\n\t\tans << \"G\"\n\tend\nend\nelse\nn.times do\n\ta,b = gets.split(\" \").map(&:to_i)\n\tif (s_a + a - s_g) <= 500\n\t\ts_a += a\n\t\t# ans << \"A\"\n\telse\n\t\ts_g += b\n\t\t# ans << \"G\"\n\tend\nend\n\nend\nif (s_a - s_g).abs <= 500\n\tputs ans\nelse\n\tputs \"-1\"\nend\n"}, {"source_code": "n = gets.to_i\ns_a = 0\ns_g = 0\nans = \"\"\nif n < 1000\nn.times do\n\ta,b = gets.split(\" \").map(&:to_i)\n\tif (s_a + a - s_g) <= 500\n\t\ts_a += a\n\t\tans << \"A\"\n\telse\n\t\ts_g += b\n\t\tans << \"G\"\n\tend\nend\nelse\n\tn.times do\n\t\ta,b = gets.split(\" \").map(&:to_i)\n\tend\n\nend\nif (s_a - s_g).abs <= 500\n\tputs ans\nelse\n\tputs \"-1\"\nend\n"}, {"source_code": "n = gets.to_i\ns = 0\n(1..n).each {\n\ta,g = gets.chomp.split(\" \").collect! {|x| x.to_i}\n\ts += a\n}\n\np = s/1000.0\nif p>=p.floor+0.5\n\tk = p.floor+1\nelse\n\tk = p.floor\nend\n\nres = \"A\"*k+\"G\"*(n-k)\n\nputs res"}, {"source_code": "n = gets.to_i\na = Array.new\nb = Array.new\nans = Array.new(n)\n(1..n).each do\n tmp = gets.split.collect{|i| i.to_i}\n a.push(tmp[0])\n b.push(tmp[1])\nend\ndiff = (0...n).collect{|i| [a[i]-b[i],i]}.sort\ntmp = 0\ndiff.each do |i|\n if (tmp+i[0]).abs <= (tmp-i[0]).abs\n if i[0] <= 0 \n ans[i[1]] = \"A\"\n else\n ans[i[1]] = \"G\"\n end\n tmp += i[0]\n else\n if i[0] <= 0 \n ans[i[1]] = \"G\"\n else\n ans[i[1]] = \"A\"\n end\n tmp -= i[0]\n end\nend\nif tmp.abs <= 500\n puts ans.join\nelse\n puts \"-1\"\nend\n"}], "src_uid": "24fe280b88575516ec679ff78641440e"} {"source_code": "t = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n a = gets.to_s.strip.split.map {|x| x.to_i }\n\n minv = a.min\n minv_i = a.find_index(minv)\n\n x = minv + 1\n while minv.gcd(x) != 1\n x += 1\n end\n\n printf(\"%d\\n\", n - 1)\n 0.upto(n - 1) do |i|\n next if i == minv_i\n if (i % 2) != (minv_i) % 2\n printf(\"%d %d %d %d\\n\", i + 1, minv_i + 1, x, minv)\n else\n printf(\"%d %d %d %d\\n\", i + 1, minv_i + 1, minv, minv)\n end\n end\nend\n", "positive_code": [{"source_code": "$, = \" \"\ngets.to_i.times do\n n = gets.to_i\n a = gets.split.map &:to_i\n mn, pos = 1E9.to_i + 7, -1\n n.times do |i|\n if a[i] < mn\n mn = a[i]\n pos = i\n end\n end\n puts n - 1\n n.times do |i|\n next if i == pos\n print pos + 1, i + 1, mn, mn + (i - pos).abs, \"\\n\"\n end\nend"}, {"source_code": "$, = \" \"\r\ngets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n mn, pos = 1E9.to_i + 7, -1\r\n n.times do |i|\r\n if a[i] < mn\r\n mn = a[i]\r\n pos = i\r\n end\r\n end\r\n puts(n - 1)\r\n n.times do |i|\r\n next if i == pos\r\n print pos + 1, i + 1, mn, mn + (i - pos).abs, \"\\n\"\r\n end\r\nend"}], "negative_code": [{"source_code": "$, = \" \"\r\ngets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n mn, pos = 1E9.to_i + 7, -1\r\n n.times do |i|\r\n if a[i] < mn\r\n mn = a[i]\r\n pos = i\r\n end\r\n end\r\n n.times do |i|\r\n next if i == pos\r\n print pos + 1, i + 1, mn, mn + (i - pos).abs, \"\\n\"\r\n end\r\nend"}], "src_uid": "8b2b7208630af1d086420513a437a914"} {"source_code": "def zigzag(a,b)\n\tr=[]\n\td=(b-a+1)/2\n\ta.upto(a+(b-a-1)/2){|c|r<m\nputs a.map{|l|l*\" \"}", "positive_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nif [n, m] == [1, 1]\n\ta = [[1]]\nelsif [n, m] == [1, 4]\n\ta = [[2, 4, 1, 3]]\nelsif [n, m] == [4, 1]\n\ta = [[2], [4], [1], [3]]\nelsif n * m <= 4\n\ta = [[-1]]\nelsif n == 1\n\ta = [[*1 .. m].partition{|_| _.odd?}.flatten]\nelsif m == 1\n\ta = [*1 .. n].partition{|_| _.odd?}.flatten.map{|_| [_]}\nelse\n\ta = Array.new(n){Array.new(m)}\n\tk = 1\n\tn.times do |i|\n\t\tm.times do |j|\n\t\t\tuntil a[i][j]\n\t\t\t\ta[i][j] = k\n\t\t\t\tk += 1\n\t\t\t\ti = (i + 1) % n\n\t\t\t\tj = (j + 1) % m\n\t\t\tend\n\t\tend\n\tend\nend\nputs a.map{|_| _ * ' '} * \"\\n\"\n__END__\n\n"}], "negative_code": [{"source_code": "n, m = gets.split.map(&:to_i)\nif [n, m] == [1, 1]\n\ta = [[1]]\nelsif [n, m] == [1, 4]\n\ta = [[2, 4, 1, 3]]\nelsif [n, m] == [4, 1]\n\ta = [[2], [4], [1], [3]]\nelsif n * m <= 4\n\ta = [[-1]]\nelse\n\ta = Array.new(n){Array.new(m)}\n\tk = 1\n\tn.times do |i|\n\t\tm.times do |j|\n\t\t\tuntil a[i][j]\n\t\t\t\ta[i][j] = k\n\t\t\t\tk += 1\n\t\t\t\ti = (i + 1) % n\n\t\t\t\tj = (j + 1) % m\n\t\t\tend\n\t\tend\n\tend\nend\nputs a.map{|_| _ * ' '} * \"\\n\"\n"}], "src_uid": "724c0c46d917f69028d76ed7f95fbaf5"} {"source_code": "n,m,x,y,z,p=gets.split.map(&:to_i)\na=[]\nb=[]\np.times{\n\ttx,ty=gets.split.map(&:to_i)\n\ta<0\n\tp.times{ |i|\n\t\tb[i]=m-b[i]+1\n\t}\nend\nz%=4\nz.times{\n\tp.times{ |i|\n\t\ta[i],b[i]=m-b[i]+1,a[i]\n\t}\n\tn,m=m,n\n}\np.times{ |i|\n\t\tputs \"#{a[i]} #{b[i]}\"\n\t}", "positive_code": [{"source_code": "def ans(i,j,n,m,c,r,a)\n\n while c>0\n t = i\n i = j\n j = n+1-t\n\n t = m\n m = n\n n = t\n\n c = c-1\n end\n\n if r!=0\n j = m+1-j\n end\n \n while a>0\n t = j\n j = i\n i = m+1-t\n\n t = m\n m = n\n n = t\n\n a = a-1 \n end\n print i.to_s+' '+j.to_s+\"\\n\"\nend\n\nn,m,x,y,z,p = gets.split.map(&:to_i)\n\np.times do | t |\n i,j = gets.split.map(&:to_i)\n ans(i,j,n,m,x%4,y%2,z%4)\nend"}, {"source_code": "def read_ints\n gets.split(\" \").map &:to_i\nend\n\nn, m, k1, k2, k3, t = read_ints\nk1 %= 4\nk3 %= 4\nk2 %= 2\nt.times do\n x, y = read_ints\n h, w = n, m\n k1.times do\n x, y = y, h - x + 1\n h, w = w, h\n end\n k2.times { y = w - y + 1 }\n k3.times do\n x, y = w - y + 1, x\n h, w = w, h\n end\n puts \"#{x} #{y}\"\nend"}, {"source_code": "def ans(i,j,n,m,c,r,a)\n c.times{ i,j,n,m = j,n+1-i,m,n }\n if r!=0\n j = m+1-j\n end \n a.times { i,j,n,m = m+1-j,i,m,n }\n puts \"#{i} #{j}\"\nend\nn,m,x,y,z,p = gets.split.map(&:to_i)\np.times do | t |\n i,j = gets.split.map(&:to_i)\n ans(i,j,n,m,x%4,y%2,z%4)\nend"}], "negative_code": [{"source_code": "def ans(i,j,n,m,c,r,a)\n\n while c>0\n t = j\n j = n+1-i\n i = t\n\n t = m\n m = n\n n = t\n\n c = c-1 \n end\n\n if r\n j = m+1-j \n end\n \n while a>0\n t = i\n i = m+1-j\n j = t\n\n t = m\n m = n\n n = t\n\n a = a-1\n end\n puts i.to_s+' '+j.to_s\nend\n\nn,m,x,y,z,p = gets.split.map(&:to_i)\n\np.times do | t |\n i,j = gets.split.map(&:to_i)\n ans(i,j,n,m,x%4,y%2,z%4)\nend"}, {"source_code": "def ans(i,j,n,m,c,r,a)\n c.times{ i,j = j,n+1-i } \n if r!=0\n j = m+1-j\n end \n a.times{ i,j = m+1-j,i }\n puts \"#{i} #{j}\"\nend\nn,m,x,y,z,p = gets.split.map(&:to_i)\np.times do | t |\n i,j = gets.split.map(&:to_i)\n ans(i,j,n,m,x%4,y%2,z%4)\nend"}, {"source_code": "def ans(i,j,n,m,c,r,a)\n\n while c>0\n t = i\n i = m+1-j\n j = t\n\n t = m\n m = n\n n = t\n\n c = c-1\n end\n\n if r!=0\n j = m+1-j\n end\n \n while a>0\n t = j\n j = n+1-i\n i = t\n\n t = m\n m = n\n n = t\n\n a = a-1 \n end\n print i.to_s+' '+j.to_s+\"\\n\"\nend\n\nn,m,x,y,z,p = gets.split.map(&:to_i)\n\np.times do | t |\n i,j = gets.split.map(&:to_i)\n ans(i,j,n,m,x%4,y%2,z%4)\nend"}, {"source_code": "def read_ints\n gets.split(\" \").map &:to_i\nend\n\nn, m, k1, k2, k3, t = read_ints\nk1 %= 4\nk3 %= 4\nk2 %= 2\nt.times do\n x, y = read_ints\n h, w = n, m\n k1.times do\n x, y = y, n - x + 1\n h, w = w, h\n end\n k2.times { y = m - y + 1 }\n k3.times do\n x, y = m - y + 1, x\n h, w = w, h\n end\n puts \"#{x} #{y}\"\nend"}, {"source_code": "def read_ints\n gets.split(\" \").map &:to_i\nend\n\nn, m, k1, k2, k3, t = read_ints\nk1 %= 4\nk3 %= 4\nk2 %= 2\nt.times do\n x, y = read_ints\n h, w = n, m\n k3.times do\n x, y = y, n - x + 1\n h, w = w, h\n end\n k2.times { y = m - y + 1 }\n k1.times do\n x, y = m - y + 1, x\n h, w = w, h\n end\n puts \"#{x} #{y}\"\nend"}], "src_uid": "14a56443e48c52c118788bd5c0031b0c"} {"source_code": "h = Hash.new{|x, y| x[y] = [0] * 52}\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n\tgets.to_i.times do |i|\n\t\th[gets][0] += c[i]\n\t\th[$_][i + 1] += 1\n\tend\nend\n2.times do\n\tputs h.max{|x, y| x[1] <=> y[1]}[0]\n\th.each{|k, v| v[0], v[1] = v[1], v[0]}\nend\n\n", "positive_code": [{"source_code": "class Racer\n N, POINTS = 50, [ 25, 18, 15, 12, 10, 8, 6, 4, 2, 1 ]\n\n attr_reader :score, :places, :name\n \n def initialize(name)\n @name = name\n @score = 0\n @places = Array.new(N, 0)\n end\n\n def add_place(place)\n @score += POINTS[place] if not POINTS[place].nil?\n @places[place] += 1\n end\nend\n\ndef compare_a(alpha, beta)\n a = alpha.score <=> beta.score\n b = alpha.places <=> beta.places\n return 2 * a + b\nend\n\ndef compare_b(alpha, beta)\n a = alpha.places.first <=> beta.places.first\n b = alpha.score <=> beta.score\n c = alpha.places[1 .. -1] <=> beta.places[1 .. -1]\n return 4 * a + 2 * b + c\nend\n\n\ndef read_race(racers)\n gets.to_i.times do |place|\n name = gets.strip\n racers[name] ||= Racer.new(name)\n racers[name].add_place(place)\n end\nend\n\ndef read_races(racers)\n gets.to_i.times { read_race(racers) }\nend\n\nracers = {}\nread_races(racers)\n\nputs racers.values.sort { |x, y| compare_a(x, y) }[-1].name\nputs racers.values.sort { |x, y| compare_b(x, y) }[-1].name\n"}, {"source_code": "h = Hash.new{|x, y| x[y] = [0] * 52}\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n\tgets.to_i.times do |i|\n\t\th[gets][0] += c[i]\n\t\th[$_][i + 1] += 1\n\tend\nend\n2.times do\n\tputs h.max{|x, y| x[1] <=> y[1]}[0]\n\th.each{|k, v| v[0], v[1] = v[1], v[0]}\nend\n"}, {"source_code": "h = Hash.new{|x, y| x[y] = [0] * 52}\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n\tgets.to_i.times do |i|\n\t\th[gets][0] += c[i]\n\t\th[$_][i + 1] += 1\n\tend\nend\n2.times do\n\tputs h.max{|x, y| x[1] <=> y[1]}[0]\n\th.each{|k, v| v[0], v[1] = v[1], v[0]}\nend\n\n"}, {"source_code": "h = Hash.new{|x, y| x[y] = [0] * 52}\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n\tgets.to_i.times do |i|\n\t\th[gets][0] += c[i]\n\t\th[$_][i + 1] += 1\n\tend\nend\n2.times do\n\tputs h.max{|x, y| x[1] <=> y[1]}[0]\n\th.each{|k, v| v[0], v[1] = v[1], v[0]}\nend\n\n"}, {"source_code": "h = Hash.new{|x, y| x[y] = [0] * 52}\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n\tgets.to_i.times do |i|\n\t\th[gets][0] += c[i]\n\t\th[$_][i + 1] += 1\n\tend\nend\n2.times do\n\tputs h.max{|x, y| x[1] <=> y[1]}[0]\n\th.each{|k, v| v[0], v[1] = v[1], v[0]}\nend\n"}, {"source_code": "t = gets.to_i\npts = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1]\n$h = {}\n$places = {}\n(0...t).each do |i|\n n = gets.to_i\n (0...n).each do |j|\n name = gets.strip\n if $h.key? name\n $h[name] += pts[j] if j < 10\n else\n $h[name] = pts[j] if j < 10\n end\n if $places.key? name\n $places[name][j] += 1\n else\n $places[name] = [0]*100\n $places[name][j] += 1\n end\n end\nend\n#puts $h.inspect\n#puts $places.inspect\ndef better1 x,y\n return $h[x] <=> $h[y] if $h[x] != $h[y]\n idx = 0\n while $places[x][idx] == $places[y][idx]\n idx += 1\n end\n return $places[x][idx] <=> $places[y][idx]\nend\n\ndef better2 x,y\n return $places[x][0] <=> $places[y][0] if $places[x][0] != $places[y][0]\n return $h[x] <=> $h[y] if $h[x] != $h[y]\n idx = 1\n while $places[x][idx] == $places[y][idx]\n idx += 1\n end\n return $places[x][idx] <=> $places[y][idx]\nend\nx = $h.keys\ny = $h.keys\nxi = 0\n#puts \"Is it #{better1 x[2], x[0]}\" \n(1...x.size).each do |ti|\n xi = ti if better1(x[ti], x[xi]) > 0\nend\nyi = 0\n(1...y.size).each do |ti|\n yi = ti if better2(y[ti], y[yi]) > 0\nend\nputs x[xi]\nputs y[yi]"}, {"source_code": "h = Hash.new{|x, y| x[y] = [0] * 52}\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n\tgets.to_i.times do |i|\n\t\th[gets][0] += c[i]\n\t\th[$_][i + 1] += 1\n\tend\nend\n2.times do\n\tputs h.max{|x, y| x[1] <=> y[1]}[0]\n\th.each{|k, v| v[0], v[1] = v[1], v[0]}\nend\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nT = gets.to_i\n\nDrivers = Hash.new\nPoints = [nil, 25, 18, 15, 12, 10, 8, 6, 4, 2 ,1]\n\nT.times do\n n = gets.to_i\n place = 1\n n.times do\n name = gets.chomp\n Drivers[name] = Array.new(51, 0) if (!Drivers[name]) \n Drivers[name][0] += Points[place] if place <= 10\n Drivers[name][place] += 1\n place += 1\n end\nend\n\n#p Drivers\n\noriginal_rank = Drivers.to_a.sort {|l, r|\n i = 0\n while (l[1][i] == r[1][i] && i < 52)\n i += 1\n end\n if (i == 52) \n 1 \n else\n r[1][i] <=> l[1][i]\n end\n}\n\n#puts \"===\"\nputs original_rank[0][0]\n\nnew_rank = Drivers.to_a\nnew_rank.each {|e|\n (e[1][1], e[1][0]) = [e[1][0], e[1][1]]\n}\n#p new_rank\nnew_rank.sort! {|l, r|\n i = 0\n while (l[1][i] == r[1][i] && i < 52)\n i += 1\n end\n if (i == 52)\n 1\n else\n r[1][i] <=> l[1][i]\n end\n}\n\nputs new_rank[0][0]\n"}, {"source_code": "h = Hash.new{|x, y| x[y] = [0] * 52}\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n gets.to_i.times do |i|\n h[gets][0] += c[i]\n h[$_][i + 1] += 1\n end\nend\n2.times do\n puts h.max{|x, y| x[1] <=> y[1]}[0]\n h.each{|k, v| v[0], v[1] = v[1], v[0]}\nend"}, {"source_code": "h = Hash.new{|x, y| x[y] = [0] * 52}\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n\tgets.to_i.times do |i|\n\t\th[gets][0] += c[i]\n\t\th[$_][i + 1] += 1\n\tend\nend\n2.times do\n\tputs h.max{|x, y| x[1] <=> y[1]}[0]\n\th.each{|k, v| v[0], v[1] = v[1], v[0]}\nend\n\n"}, {"source_code": "h = Hash.new{|x, y| x[y] = [0] * 52}\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n\tgets.to_i.times do |i|\n\t\th[gets][0] += c[i]\n\t\th[$_][i + 1] += 1\n\tend\nend\n2.times do\n\tputs h.max{|x, y| x[1] <=> y[1]}[0]\n\th.each{|k, v| v[0], v[1] = v[1], v[0]}\nend\n\n"}, {"source_code": "h = Hash.new{|x, y| x[y] = [0] * 52}\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n\tgets.to_i.times do |i|\n\t\th[gets][0] += c[i]\n\t\th[$_][i + 1] += 1\n\tend\nend\n2.times do\n\tputs h.max{|x, y| x[1] <=> y[1]}[0]\n\th.each{|k, v| v[0], v[1] = v[1], v[0]}\nend\n\n"}, {"source_code": "h = Hash.new{|x, y| x[y] = [0] * 52}\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n\tgets.to_i.times do |i|\n\t\th[gets][0] += c[i]\n\t\th[$_][i + 1] += 1\n\tend\nend\n2.times do\n\tputs h.max{|x, y| x[1] <=> y[1]}[0]\n\th.each{|k, v| v[0], v[1] = v[1], v[0]}\nend\n\n"}], "negative_code": [{"source_code": "a = Hash.new{|x, y| x[y] = [0] * 52}\nb = a.clone\nc = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + [0] * 99\ngets.to_i.times do\n\tgets.to_i.times do |i|\n\t\tgets\n\t\tx = a[$_]\n\t\tx[0] += c[i]\n\t\tx[i + 1] += 1\n\t\ty = b[$_]\n\t\ty[i] += 1\n\t\ty[-1] += c[i]\n\tend\nend\nputs a.max{|x, y| x[1] <=> y[1]}[0]\nputs b.max{|x, y| x[1] <=> y[1]}[0]\n"}], "src_uid": "bd40f54a1e764ba226d5387fcd6b353f"} {"source_code": "def findX(a)\n x0 = 0\n x1 = a.size()-1\n\n return a[x0] if yield(a[x0])\n while x1-x0 > 1\n x2 = (x0+x1)/2\n if yield(a[x2])\n x1 = x2\n else\n x0 = x2\n end\n end\n a[x1]\nend\n\ngets\na = gets.split.map(&:to_i)\na.reverse!\n\nb = []\nmdx = 0\nlst = []\n0.upto(a.size-1) do |i|\n if lst.empty? || a[mdx] >= a[i]\n lst << [a[i], (mdx = i)]\n b[i] = -1\n else\n y = findX(lst){|aa,ii| aa= x\n\t\t\tb = m + 1\n\t\telse\n\t\t\te = m - 1\n\t\t\tp = m\n\t\tend\n\tend\n\tp\nend\n\nseq.each_with_index do |x, i|\n\tp = bin_search list, x\n\tans[i] = -1\n\tif p != -1\n\t\tans[i] = i - pos[p] - 1\n\tend\n\tif list.size > 0 && x < list.last\n\t\tlist << x\n\t\tpos << i\n\telsif list.size == 0\n\t\tlist << x\n\t\tpos << i\n\tend\nend\n\nans.reverse!\nans.each do |a|\n\tp a\nend"}], "negative_code": [], "src_uid": "668f85cc331bc7bcdd708d9190bbd6e8"} {"source_code": "s = gets.chomp\ne = gets.chomp\nsi = s.count('1')\nei = e.count('1')\nif si % 2 == 0\n puts \"NO\" if si < ei\n puts \"YES\" if si >= ei\nelse\n if ei > si && si + 1 != ei\n puts \"NO\"\n else \n puts \"YES\"\n end\nend", "positive_code": [{"source_code": "A = gets.chomp.count('1')\nB = gets.chomp.count('1')\nA += 1 if A&1 == 1\n# puts \"#{A} #{B}\"\nif A >= B\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend"}, {"source_code": "\nas = gets\nbs = gets\na = as.count('1')\nb = bs.count('1')\n\nif a >= b-1 && b%2 == 0 || b%2 == 1 && a >= b || as == bs\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "s = gets.chomp\ne = gets.chomp\nsi = s.count('1')\nei = e.count('1')\nsi += 1 if si % 2 != 0\nputs \"YES\" if si >= ei\nputs \"NO\" if si < ei "}, {"source_code": "s = gets.chomp\ne = gets.chomp\nsi = ei = 0\nfor i in 0...s.size\n si += 1 if s[i] == '1'\nend\nfor i in 0...e.size\n ei += 1 if e[i] == '1'\nend\nif si % 2 == 0\n puts \"NO\" if si < ei\n puts \"YES\" if si >= ei\nelse\n if ei > si && si + 1 != ei\n puts \"NO\"\n else \n puts \"YES\"\n end\nend"}, {"source_code": "count = gets.scan('1').size\ncount += 1 if count % 2 == 1\nputs count >= gets.scan('1').size ? \"YES\" : \"NO\"\n"}, {"source_code": "puts (gets.count('1') + 1) / 2 * 2 >= gets.count('1') ? \"YES\" : \"NO\"\n"}, {"source_code": "a = gets.chomp\nb = gets.chomp\n \nonesA = a.count('1')\nonesB = b.count('1')\n \nonesA += onesA & 1\n \n if onesA >= onesB\n puts \"YES\"\n else\n puts \"NO\"\n end"}, {"source_code": "def ones(s)\n s.split(//).count(\"1\")\nend\n\ndef parity?(i)\n i % 2 == 1\nend\n\ndef run(args)\n a = args[0]\n b = args[1]\n\n a1 = ones(a)\n b1 = ones(b)\n\n ap = parity?(a1)\n bp = parity?(b1)\n\n if a1 >= b1\n return \"YES\"\n else\n if b1 - a1 == 1 and ap \n return \"YES\"\n else\n return \"NO\"\n end\n end\n return \"sabugo\"\nend\n\nbuffer = []\n\nSTDIN.read.split(\"\\n\").each do |line|\n buffer << line\n if buffer.size == 2\n puts run(buffer)\n buffer = []\n end\nend\n\n\n"}, {"source_code": "s=gets.split(//)\nl=s.size\ni=0\nn=0\nwhile (i=m) then puts \"YES\"\nelse puts \"NO\"\nend"}, {"source_code": "puts (gets.count('1') + 1) / 2 * 2 >= gets.count('1') ? \"YES\" : \"NO\""}, {"source_code": "a = gets.scan('1').size\nb = gets.scan('1').size\na += 1 if a.odd?\nputs a >= b ? :YES : :NO\n"}, {"source_code": "def run\n a1 = $stdin.gets.split(//).map(&:to_i).reduce(:+)\n b1 = $stdin.gets.split(//).map(&:to_i).reduce(:+)\n\n a1 += 1 if a1 % 2 == 1\n $stdout.puts a1 >= b1 ? \"YES\" : \"NO\"\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "z=gets\nputs z.count('1')+z.count('1')%2>=gets.count('1') ? 'YES' : 'NO'"}], "negative_code": [{"source_code": "A = gets.chomp\nB = gets.chomp\nfor c in 1..A.length\n\t# puts A[-c..A.length]\n\tif B.start_with?A[-c..A.length] and A[0..-c-1].count('1') >= B[c..B.length].count('1')\n\t\tputs \"YES\"\n\t\texit\n\tend\nend\nputs \"NO\"\n"}, {"source_code": "s = gets.chomp\ne = gets.chomp\nsi = s.count('1')\nei = e.count('1')\nsi += 1 if si & 1\nputs \"YES\" if si >= ei\nputs \"NO\" if si < ei "}, {"source_code": "s = gets.chomp\ne = gets.chomp\nsi = ei = 0\nfor i in 0...s.size\n si += 1 if s[i] == '1'\nend\nfor i in 0...e.size\n ei += 1 if e[i] == '1'\nend\nif si % 2 == 0\n puts \"NO\" if si < ei\nelse\n if ei > si && si + 1 != ei\n puts \"NO\"\n else \n puts \"YES\"\n end\nend"}, {"source_code": "s = gets.chomp\ne = gets.chomp\nsi = ei = 0\nfor i in 0...s.size\n si += 1 if s[i] == '1'\nend\nfor i in 0...e.size\n ei += 1 if e[i] == '1'\nend\nif si % 2 == 0\n puts \"NO\" if si < ei\n puts \"YES\" if si == ei\nelse\n if ei > si && si + 1 != ei\n puts \"NO\"\n else \n puts \"YES\"\n end\nend"}, {"source_code": "def ones(s)\n s.split(//).count(\"1\")\nend\n\ndef parity?(i)\n i % 2 == 1\nend\n\ndef run(args)\n a = args[0]\n b = args[1]\n\n a1 = ones(a)\n b1 = ones(b)\n\n ap = parity?(a1)\n bp = parity?(b1)\n\n if a1 == b1\n return \"YES\"\n else\n if b1 - a1 == 1 and ap \n return \"YES\"\n else\n return \"NO\"\n end\n end\n return \"sabugo\"\nend\n\nbuffer = []\n\nSTDIN.read.split(\"\\n\").each do |line|\n buffer << line\n if buffer.size == 2\n puts run(buffer)\n buffer = []\n end\nend\n\n\n"}, {"source_code": "def run\n a1 = $stdin.gets.split(//).map(&:to_i).reduce(:+)\n b1 = $stdin.gets.split(//).map(&:to_i).reduce(:+)\n $stdout.puts a1 >= b1 ? \"YES\" : \"NO\"\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "\nas = gets\nbs = gets\na = as.count('1')\nb = bs.count('1')\n\nif a >= b-1 && b%2 == 0 || b%2 == 1 && a > b || as == bs\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}], "src_uid": "cf86add6c92fa8a72b8e23efbdb38613"} {"source_code": "t=gets.to_i\nt.times{\n n,k=gets.split.map &:to_i\n tab=gets.split.map &:to_i\n time = (n.to_f/2).ceil-1\n tab = tab.drop(k*time)\n p tab.each_slice(n - time).map{|x|x[0]}.sum\n}", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n n, k = gets.chomp.split(' ').map(&:to_i)\n arr = gets.chomp.split(' ').map(&:to_i)\n # puts arr.to_s\n t = n / 2\n ind = arr.size - 1 - t\n # puts \"ind = \" + ind.to_s\n res = 0\n while k > 0 do\n res += arr[ind]\n # puts \"el = \" + arr[ind].to_s\n k -= 1\n ind -= t + 1\n end\n puts res\nend \n\n# 1 -> 0\n# 2 -> 1\n# 3 -> 1\n# 4 -> 2\n# 5 -> 2"}], "negative_code": [], "src_uid": "83d0395cd3618b0fd02c1846dbcd92a2"} {"source_code": "def function\nb=gets.chomp\na=gets.chomp\na=a.split(' ').map(&:to_i).sort\nsum=0\na.each do |i|\nsum+=i\nend\nif sum%2!=0\na.each do |i|\nif i%2!=0\nsum-=i\nputs sum\nbreak\nend\nend\nelse\nputs sum\nend\nend\nfunction", "positive_code": [{"source_code": "gets\nx,y=gets.split.map(&:to_i).sort.reverse.partition{|e|e%2==0}\np x.reduce(0,:+)+y[0,y.size/2*2].reduce(0,:+)"}, {"source_code": "n = gets.chomp.to_i\nnumbers = gets.chomp.split.map(&:to_i).sort\n\nmin_odd = numbers.find(&:odd?)\nsum = numbers.inject(0, :+)\nputs sum.even? ? sum : sum - min_odd\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split(\" \").map(&:to_i)\n\nevens = arr.select(&:even?)\nodds = arr.select(&:odd?).sort\n\nodds_sum = odds.size.even? ? odds.inject(0, :+) : odds.drop(1).inject(0, :+)\n\nputs evens.inject(0, :+) + odds_sum"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\n\npar = []\nnep = []\nsum = a.reduce(:+)\na.each { |x| x.even? ? par.push(x) : nep.push(x) }\n\nputs sum.even? ? sum : sum - nep[0]"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\n\npar, nep = [], []\na.each do |x|\n x.even? ? par.push(x) : nep.push(x)\nend\nsum = a.reduce(:+)\n\nputs sum.even? ? sum : sum - nep[0]\n"}, {"source_code": "def sum_all(arr)\n\tsum =0 \n\tarr.each do |i|\n\t\tsum+=i \n\tend\n\treturn sum \nend \n\nn = gets.chomp \narr = gets.split.map(&:to_i) \nodd_count =0 \neven_count =0 \narr.each do|i|\n\tif i.even? \n\t\teven_count +=1 \n\telse \n\t\todd_count +=1 \n\tend\nend \nsum=0 \n\nif odd_count.even? \n\tputs sum_all(arr)\nelse \n\todd_count -=1 \narr.sort!.reverse! \n\nsum =0 \narr.each do |i|\n\tif i.odd? and odd_count>0 \n\t\tsum+=i \n\t\todd_count -=1 \n\telsif i.even?\n\t\tsum+=i \n\tend\nend\nputs sum \nend\n\t\t\n\t\n\t"}, {"source_code": "gets\ne1=0\no1=-1\nx=gets.split.map{|e| e.to_i}\nx.each{|e|\n\td=e%2\n\tif d==0 then\n\t\te1+=e\n\t\tif o1!=-1 then\n\t\t\to1+=e\n\t\tend\n\telse\n\t\to2=e1+e\n\t\tif o1!=-1 then\n\t\t\te1=[e1,o1+e].max\n\t\tend\n\t\to1=[o1,o2].max\n\tend\n}\nputs e1\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n\na.sort!{|x, y| y <=> x }\nans = 0\nodd = []\na.each do |v|\n if v % 2 == 0\n ans += v\n else\n if odd.size == 0\n odd.push(v)\n else\n ans += v + odd.shift\n end\n end\nend\nputs ans\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\na = []\nsum = 0\nodds = 0\ngets.split.each { |i|\n i = i.to_i\n \n if i.even?\n sum += i\n else\n odds += 1 if i.odd?\n a << i\n end\n}\na.sort!\nif odds.odd?\n a.shift\nend\na << 0\n\nputs a.reduce(:+) + sum\n"}, {"source_code": "n = gets.chomp.to_i\nxs = gets.chomp.split.map(&:to_i)\n\ns = xs.inject(&:+)\nif s % 2 == 0\n puts s\nelse\n puts s - xs.select { |x| x % 2 == 1 }.min\nend\n"}, {"source_code": "def solve(a)\n s = a.inject(0, :+)\n return s if s.even?\n x = a.lazy.select(&:odd?).min\n return s - x if x\n 0\nend\n\ngets\nputs solve(gets.split.map(&:to_i))\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map &:to_i\ns = a.reduce(&:+)\nif s%2 == 0\n puts s\nelse\n mn = Float::INFINITY\n for i in a\n mn = [mn, i].min if i%2 == 1\n end\n puts s - mn\nend"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nsum = a.inject(:+)\nputs sum.even? ? sum : sum - a.select(&:odd?).min\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nsum = a.inject(:+)\nputs sum.even? ? sum : sum - a.find{|x| x.odd?}\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\n\naoddmin = a.select{|x| x.odd?}.min\n\nasum = a.inject(:+)\nif asum.even? then\n puts asum\nelse\n puts asum - aoddmin\nend\n"}, {"source_code": "gets\na = gets.split.map{|x| x.to_i}\nodds = a.select{|x| x%2 == 1}\nputs(a.inject(0){|s, x| s + x} - (odds.size%2 != 0 ? odds.min : 0))\n"}], "negative_code": [{"source_code": "gets\nx,y=gets.split.map(&:to_i).sort.reverse.partition{|e|e==0}\np x.reduce(0,:+)+y[0,y.size/2*2].reduce(0,:+)"}, {"source_code": "def function\na=gets.chomp\na=a.split(' ').map(&:to_i).sort\nsum=0\na.each do |i|\nsum+=i\nend\na.each do |i|\nif i%2!=0\nsum-=i\nbreak\nend\nend\nputs sum\nend\nfunction"}, {"source_code": "n = gets.chomp \narr = gets.split.map(&:to_i) \nodd_count =0 \neven_count =0 \narr.each do |i| \n\tif i.odd? \n\t\todd_count+=1 \n\telse\n\t\teven_count +=1 \n\tend\nend \n\nif odd_count.odd? \n\todd_count = odd_count -1 \nend\nsum = 0 \narr.each do |i| \n\tif i.odd? and not odd_count.zero? \n\t\tsum +=i \n\t\todd_count= odd_count -1 \n\telsif i.even?\n\t\tsum +=i \n\tend\nend\nputs sum "}, {"source_code": "gets\ne1=0\no1=-1\nx=gets.split.map{|e| e.to_i}\nx.each{|e|\n\td=e%2\n\tif d==0 then\n\t\te1+=e\n\t\tif o1!=-1 then\n\t\t\to1+=e\n\t\tend\n\telse\n\t\to2=e1+e\n\t\tif o1!=-1 then\n\t\t\te1=o1+e\n\t\tend\n\t\to1=o2\n\tend\n}\nputs e1\n\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\na = []\nsum = 0\nodds = 0\ngets.split.each { |i|\n i = i.to_i\n \n if i.even?\n sum += i\n else\n odds += 1 if i.odd?\n a << i\n end\n}\n\nif odds.odd?\n a.shift\n a << 0\nend\n\nputs a.reduce(:+) + sum\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\n\naoddmax = a.select{|x| x.odd?}.max\n\nasum = a.inject(:+)\nif asum.even? then\n puts asum\nelse\n puts asum - aoddmax\nend\n"}], "src_uid": "adb66b7b22d70bb37cb625d531d8865f"} {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n if n % 3 == 0\n puts \"#{n/3} #{n / 3 + 1} #{n/3-1}\"\n elsif n % 3 == 1\n puts \"#{n/3} #{n / 3 + 2} #{n/3-1}\"\n else\n puts \"#{n/3+1} #{n / 3 + 2} #{n/3-1}\"\n end\nend\n", "positive_code": [{"source_code": "t = gets.to_i\n\nt.times do\n n = gets.to_i\n h1 = h2 = h3 = n / 3\n m = n % 3\n if m == 1\n h1 += 1\n elsif m == 2\n h1 += 1\n h2 += 1\n end\n\n until h3 < h2 && h2 < h1 && h1+h2+h3 == n\n h1 += 1\n h3 -= 1\n end\n puts [h2, h1, h3].join(\" \")\nend\n"}, {"source_code": "#require \"prime\"\n#input of int(split by space)\ndef get_i()\n return gets.chomp.split(\" \").map(&:to_i)\nend\n#input of float(split by space)\ndef get_f()\n return gets.chomp.split(\" \").map(&:to_f)\nend\n#input of string(split by space)\ndef get()\n return gets.chomp.split(\" \")\nend\n#input of string(split per one character)\ndef get_nsp()\n return gets.chomp.split(\"\")\nend\n#yes or no decision\ndef yn_judge(bool,y=\"Yes\",n=\"No\")\n return bool ? y : n \nend\n#output grid(two dimensional array)\ndef puts_grid(grid,join_char=\"\")\n grid.each do|line|\n puts line.join(join_char)\n end\nend\n\nDirxy4=[[1,0],[-1,0],[0,1],[0,-1]]\nDirxy8=[[1,0],[1,-1],[1,1],[0,-1],[0,1],[-1,0],[-1,-1],[-1,1]]\n\nINF=Float::INFINITY\n\n#MOD=998_244_353\nMOD=10**9+7\n\nT=gets.to_i\nT.times do \n n=gets.to_i\n v=n/3\n r=n%3\n case r\n when 0 then\n puts [v,v+1,v-1].join(\" \")\n when 1 then\n puts [v,v+2,v-1].join(\" \")\n when 2 then\n puts [v+1,v+2,v-1].join(\" \")\n end\nend"}, {"source_code": "\ndef solution(n)\n fi, se, th = 3, 2, 1 \n m = (n - 6) / 3\n r = (n - 6) % 3\n fi += m\n se += m \n th += m\n while r > 0 \n if r > 0\n fi += 1\n r -= 1\n end\n if r > 0\n se += 1\n r -= 1\n end\n if r > 0 \n th += 1\n r -= 1\n end\n end\n puts se.to_s + \" \" + fi.to_s + \" \" + th.to_s\nend\n \n \nn = $stdin.gets.to_i\n(0...n).each do |i|\n n = $stdin.gets.to_i \n solution(n)\nend"}], "negative_code": [{"source_code": "#require \"prime\"\n#input of int(split by space)\ndef get_i()\n return gets.chomp.split(\" \").map(&:to_i)\nend\n#input of float(split by space)\ndef get_f()\n return gets.chomp.split(\" \").map(&:to_f)\nend\n#input of string(split by space)\ndef get()\n return gets.chomp.split(\" \")\nend\n#input of string(split per one character)\ndef get_nsp()\n return gets.chomp.split(\"\")\nend\n#yes or no decision\ndef yn_judge(bool,y=\"Yes\",n=\"No\")\n return bool ? y : n \nend\n#output grid(two dimensional array)\ndef puts_grid(grid,join_char=\"\")\n grid.each do|line|\n puts line.join(join_char)\n end\nend\n\nDirxy4=[[1,0],[-1,0],[0,1],[0,-1]]\nDirxy8=[[1,0],[1,-1],[1,1],[0,-1],[0,1],[-1,0],[-1,-1],[-1,1]]\n\nINF=Float::INFINITY\n\n#MOD=998_244_353\nMOD=10**9+7\n\nT=gets.to_i\nT.times do \n n=gets.to_i\n puts [2,n-3,1].join(\" \")\nend"}], "src_uid": "45cf60f551bd5cbb1f3df6ac3004b53c"} {"source_code": "\ns = gets.strip.split ''\n\nbrk = Array.new\nright = {'>' => '<', '}' => '{', ']' => '[', ')' => '('}\n\nres = 0\n\n\ns.each do |e|\t\t\n\tif right.include? e \n\t\tif brk.size == 0 \n\t\t\tres = -1\n\t\t\tbreak\n\t\tend\n\n\t\tif brk[-1] == right[e] \n\t\t\tbrk.pop\n\t\telse\n\t\t\tres += 1\n\t\t\tbrk.pop\n\t\tend\n\telse\t\t\t\n\t\tbrk.push e\n\tend\nend\n\n\nif res == -1 or brk.any?{|e| e != 0}\n\tputs 'Impossible'\nelse\n\tputs res\nend\n\n", "positive_code": [{"source_code": "\ns = gets.chomp\n\nRBS = Array.new\t\t# regular bracket sequance\nchange = 0\n\nfor i in 0...s.length\n\tcase s[i]\n\t\twhen '(', '[', '{', '<' then\n\t\t\tRBS.push s[i]\n\t\t\t\n\t\twhen ')', ']', '}', '>' then\n\t\t\tif RBS.empty?\n\t\t\t\tputs \"Impossible\"\n\t\t\t\texit true\n\t\t\tend\n\t\t\t\n\t\t\tch = RBS.pop\n\t\t\tif not ((ch == '(' and s[i] == ')') or (ch == '[' and s[i] == ']') or (ch == '{' and s[i] == '}') or (ch == '<' and s[i] == '>'))\n\t\t\t\tchange = change + 1\t\t\t\n\t\t\tend\n\tend\n\t\nend\n\nif not RBS.empty?\n\tputs \"Impossible\"\nelse\n\tputs change\nend"}, {"source_code": "ans=0\ns=[]\ndef type_of b\n\tcase b\n\twhen ?<,?{,?[,?(\n\t\t:opening\n\twhen ?>,?},?],?)\n\t\t:closing\n\tend\nend\n\ndef is_paired?(o,c)\n\tcase o\n\twhen ?<\n\t\tc==?>\n\twhen ?{\n\t\tc==?}\n\twhen ?[\n\t\tc==?]\n\twhen ?(\n\t\tc==?)\n\tend\t\t\nend\n\nwhile c=STDIN.getc\n\tif type_of(c)==:opening\n\t\ts.push c\n\telsif type_of(c)==:closing\n\t\to=s.pop\n\t\tunless o\n\t\t\tputs \"Impossible\"\n\t\t\texit\n\t\tend\n\t\tans+=1 unless is_paired?(o,c)\n\tend\nend\n\nputs s.empty? ? ans : \"Impossible\""}, {"source_code": "str = gets.chomp\n\nstack = []\nres = 0\nhash = {\n ')' => '(',\n '>' => '<',\n ']' => '[',\n '}' => '{'\n}\n\nstr.each_char do |c|\n case c\n when '(', '{', '<', '[' then stack.push c\n when ')'\n res = 'Impossible' and break if (stack.length==0)\n res += 1 if stack[-1]!='('\n stack.pop\n when '}'\n res = 'Impossible' and break if (stack.length==0)\n res += 1 if stack[-1]!='{'\n stack.pop\n when '>'\n res = 'Impossible' and break if (stack.length==0)\n res += 1 if stack[-1]!='<'\n stack.pop\n when ']'\n res = 'Impossible' and break if (stack.length==0)\n res += 1 if stack[-1]!='['\n stack.pop\n end\nend\n\nif stack.length==0\n puts res\nelse\n puts 'Impossible'\nend"}], "negative_code": [{"source_code": "\ns = gets.strip.split ''\n\nbrk =Array.new(4, 0)\nright = {'>' => 0, '}' => 1, ']' => 2, ')' => 3}\nleft = {'<' => 0, '{' => 1, '[' => 2, '(' => 3}\nres = 0\n\n\ns.each do |e|\t\t\n\tif right.include? e \n\t\tif brk.none?{|i| i > 0} \n\t\t\tres = -1\n\t\t\tbreak\n\t\tend\n\n\t\tif brk[right[e]] != 0 \n\t\t\tbrk[right[e]] -= 1\n\t\telse\n\t\t\tres += 1\n\t\t\tbrk[brk.find_index{|e| e != 0}] -= 1\n\t\tend\n\telse left.include? e\n\t\t\tbrk[left[e]] += 1\n\tend\nend\n\n\nif res == -1 or brk.any?{|e| e != 0}\n\tputs 'Impossible'\nelse\n\tputs res\nend\n\n"}, {"source_code": "ans=0\ns=[]\ndef type_of b\n\tcase b\n\twhen ?<,?{,?[,?(\n\t\t:opening\n\twhen :>,?},?],?)\n\t\t:closing\n\tend\nend\n\ndef is_paired?(o,c)\n\tcase o\n\twhen ?<\n\t\tc==?>\n\twhen ?{\n\t\tc==?}\n\twhen ?[\n\t\tc==?]\n\twhen ?(\n\t\tc==?)\n\tend\t\t\nend\n\nwhile c=STDIN.getc\n\tif type_of(c)==:opening\n\t\ts.push c\n\telsif type_of(c)==:closing\n\t\to=s.pop\n\t\tunless o\n\t\t\tputs \"Impossible\"\n\t\t\texit\n\t\tend\n\t\tans+=1 unless is_paired?(o,c)\n\tend\nend\n\nputs s.empty? ? ans : \"Impossible\""}, {"source_code": "ans=0\ns=[]\ndef type_of b\n\tcase b\n\twhen ?<,?{,?[,?(\n\t\t:opening\n\twhen ?>,?},?],?)\n\t\t:closing\n\tend\nend\n\ndef is_paired?(o,c)\n\tcase o\n\twhen ?<\n\t\tc==?>\n\twhen ?{\n\t\tc==?}\n\twhen ?[\n\t\tc==?]\n\twhen ?(\n\t\tc==?)\n\tend\t\t\nend\n\nwhile c=STDIN.getc\n\tp type_of(c)\n\tif type_of(c)==:opening\n\t\ts.push c\n\telsif type_of(c)==:closing\n\t\to=s.pop\n\t\tunless o\n\t\t\tputs \"Impossible\"\n\t\t\texit\n\t\tend\n\t\tans+=1 unless is_paired?(o,c)\n\tend\nend\n\nputs s.empty? ? ans : \"Impossible\""}], "src_uid": "4147fef7a151c52e92c010915b12c06b"} {"source_code": "n,k=gets.chomp.split.collect{|a| a.to_i}\narr=gets.chomp.split.collect{|a| a.to_i}.sort\nset={}\narr.each{|a| if a%k!=0 || set[a/k]== nil then set[a]=true end }\nputs set.size\n", "positive_code": [{"source_code": "#!/usr/bin/ruby1.9\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\na = STDIN.readline.split.collect {|s| s.to_i }\n\na.sort!\nindex = {}\na.length.times {|i| index[a[i]] = i }\n\ncount = 0\na.length.times do |i|\n\tnext if a[i] < 0\n\tcount += 1\n\tj = index[k*a[i]]\n\ta[i] *= -1\n\tif j != nil\n\t\ta[j] *= -1\n\tend\nend\n\nputs count\n"}, {"source_code": "require 'set'\nnk = gets.split(' ').collect!{|i| i.to_i}\nn = nk[0]\nk = nk[1]\n\na = gets.split(' ').collect!{|i| i.to_i}.sort!\n\n# ak = []\n# size = 0\n# a.each do |i|\n# \tif !ak.include?(i)\n# \t\tak << i*k\n# \t\tsize += 1\n# \tend\n# end\n\n# puts size\ns = Set.new\na.each do |i|\n\ts << i*k if !s.include?(i)\nend\n\np s.size"}, {"source_code": "# require 'set'\nnk = gets.split(' ').collect!{|i| i.to_i}\nn = nk[0]\nk = nk[1]\n\na = gets.split(' ').collect!{|i| i.to_i}.sort!\n\n\n# s = Set.new\ns = {}\nb = 0\na.each do |i|\n\tif !s.include?(i)\n\t\ts[i*k] = b\n\t\tb += 1\n\tend\nend\n\np b"}, {"source_code": "def binary_search(ary, x)\n\n n = ary.size\n left = 0\n right = n - 1\n \n while left <= right\n mid = (left + right) / 2\n\n case ary[mid] <=> x\n when 0\n return mid\n when 1\n right = mid - 1\n when -1\n left = mid + 1\n end\n end\n\n return -1\nend\n\nn, k = gets.split.map &:to_i\nary = gets.split.map(&:to_i).sort\naryc = Array.new(n, 0)\nans = 0\n\nfor i in 0 .. n - 1 do\n\n if aryc[i] == 1 then next end\n aryc[i] = 1\n\n tmp = ary[i]\n cnt = 1\n\n while tmp <= ary[n - 1]\n if k == 1 then break end\n tmp *= k\n check = binary_search(ary, tmp)\n if check > -1\n aryc[check] = 1\n cnt += 1\n else\n break\n end\n end\n\n ans += (cnt + 1) / 2\nend\n\nputs ans\n"}, {"source_code": "a,k={},gets.split.map(&:to_i)[1]\ngets.split.map(&:to_i).sort.each{|i|a[i]=1 if i%k>0||!a[i/k]}\np a.size\n"}, {"source_code": "a,k={},gets.split.map(&:to_i)[1]\ngets.split.map(&:to_i).sort.each{|i|a[i]=1 if i%k>0||!a[i/k]}\np a.size\n"}, {"source_code": "a,k={},gets.split.map(&:to_i)[1]\ngets.split.map(&:to_i).sort.each{|i|a[i]=1 if i%k>0||!a[i/k]}\np a.size"}, {"source_code": "a,k={},gets.split.map(&:to_i)[1]\ngets.split.map(&:to_i).sort.each{|i|a[i]=1 if i%k>0||!a[i/k]}\np a.size\n"}, {"source_code": "a,k={},gets.split.map(&:to_i)[1]\ngets.split.map(&:to_i).sort.each{|i|a[i]=1 if i%k>0||!a[i/k]}\np a.size\n"}, {"source_code": "k=gets.split.map(&:to_i)[1]\na,ans={},0\ngets.split.map(&:to_i).sort.each{|i|a[i]=1}\na.each do |key,v|\n next if v==0\n ans+=1\n a[key*k]-=1 if a[k*key]\nend\np ans"}, {"source_code": "a,k={},gets.split.map(&:to_i)[1]\ngets.split.map(&:to_i).sort.each{|i|a[i]=1 if i%k>0||!a[i/k]}\np a.size"}, {"source_code": "a,k={},gets.split.map(&:to_i)[1]\ngets.split.map(&:to_i).sort.each{|i|a[i]=1 if i%k>0||!a[i/k]}\np a.size\n"}, {"source_code": "a,k={},gets.split.map(&:to_i)[1]\ngets.split.map(&:to_i).sort.each{|i|a[i]=1 if i%k>0||!a[i/k]}\np a.size\n"}, {"source_code": "a,k={},gets.split.map(&:to_i)[1]\ngets.split.map(&:to_i).sort.each{|i|a[i]=1 if i%k>0||!a[i/k]}\np a.size\n"}, {"source_code": "a,k={},gets.split.map(&:to_i)[1]\ngets.split.map(&:to_i).sort.each{|i|a[i]=1 if i%k>0||!a[i/k]}\np a.size\n"}], "negative_code": [{"source_code": "nk = gets.split(' ').collect!{|i| i.to_i}\nn = nk[0]\nk = nk[1]\n\na = gets.split(' ').collect!{|i| i.to_i}.sort!\n\n# ak = []\n# size = 0\n# a.each do |i|\n# \tif !ak.include?(i)\n# \t\tak << i*k\n# \t\tsize += 1\n# \tend\n# end\n\n# puts size\ns = []\na.each do |i|\n\ts << i if !s.include?(i/k)\nend\n\np s.size"}, {"source_code": "def binary_search(ary, x)\n\n n = ary.size\n left = 0\n right = n - 1\n \n while left <= right\n mid = (left + right) / 2\n\n case ary[mid] <=> x\n when 0\n return mid\n when 1\n right = mid - 1\n when -1\n left = mid + 1\n end\n end\n\n return -1\nend\n\nn, k = gets.split.map &:to_i\nary = gets.split.map(&:to_i).sort\naryc = Array.new(n, 0)\nans = 0\n\nfor i in 0 .. n - 1 do\n\n if k == 1 then break end\n\n if aryc[i] == 1 then next end\n aryc[i] = 1\n\n tmp = ary[i]\n cnt = 1\n\n while tmp <= ary[n - 1]\n tmp *= k\n check = binary_search(ary, tmp)\n if check > -1\n aryc[check] = 1\n cnt += 1\n else\n break\n end\n end\n\n ans += (cnt + 1) / 2\nend\n\nputs ans\n"}, {"source_code": "def binary_search(ary, x)\nn = ary.size\nleft = 0\nright = n - 1\nwhile left < right\nmid = (left + right) / 2\ncase ary[mid] <=> x\nwhen 0\nreturn mid\nwhen 1\nright = mid\nwhen -1\nleft = mid + 1\nend\nend\nreturn -1\nend\n\nn, k = gets.split.map &:to_i\nary = gets.split.map(&:to_i).sort\naryc = Array.new(n, 0)\nans = 0\n\nfor i in 0 .. n - 1 do\nif aryc[i] == 1 then next end\naryc[i]= 1\ntmp = ary[i]\ncnt = 1\nwhile tmp <= ary[n - 1]\ntmp *= k\ncheck = binary_search(ary, tmp)\nif check > -1\nbreak\nelse\naryc[check] = 1\ncnt += 1\nend\nend\nans += cnt/2\nend\n\nputs ans\n\n"}], "src_uid": "4ea1de740aa131cae632c612e1d582ed"} {"source_code": "gets.to_i.times do\n a = []\n b = []\n m = 9\n gets.chomp!.chars.map!(&:to_i).reverse_each do |c|\n m = c if m > c\n if m == c\n a << c\n else\n b << c\n end\n end\n a += b.map! { |e| e == 9 ? 9 : e + 1 }\n puts a.sort!.join\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n s = gets.chomp!.chars.map!(&:to_i).reverse!\n a = []\n b = []\n m = 9\n s.each do |c|\n m = c if m > c\n if m == c\n a << c\n else\n b << c\n end\n end\n a += b.map! { |e| e == 9 ? 9 : e + 1 }\n puts a.sort!.join\nend\n"}, {"source_code": "gets.to_i.times do\n m = 9\n puts (gets.chomp!.chars.map!(&:to_i).reverse_each.map do |c|\n if m >= c\n m = c\n c\n elsif c == 9\n c\n else\n c + 1\n end\n end.sort!.join)\nend\n"}, {"source_code": "gets.to_i.times do\n a = []\n b = []\n m = 9\n puts (gets.chomp!.chars.map!(&:to_i).reverse_each.map do |c|\n if m >= c\n m = c\n c\n elsif c == 9\n c\n else\n c + 1\n end\n end.sort!.join)\nend\n"}, {"source_code": "gets.to_i.times do\n a = []\n b = []\n m = 9\n gets.chomp!.chars.map!(&:to_i).reverse_each do |c|\n if m >= c\n m = c\n a << c\n else\n b << c\n end\n end\n a += b.map! { |e| e == 9 ? 9 : e + 1 }\n puts a.sort!.join\nend\n"}], "negative_code": [{"source_code": "gets.to_i.times do\n a = []\n b = []\n m = 9\n gets.chomp!.chars.map!(&:to_i).reverse_each do |c|\n if m >= c\n c = m\n a << c\n else\n b << c\n end\n end\n a += b.map! { |e| e == 9 ? 9 : e + 1 }\n puts a.sort!.join\nend\n"}, {"source_code": "gets.to_i.times do\n s = gets.chomp!.chars.map!(&:to_i)\n a = []\n (0..9).each do |i|\n break if s.empty?\n c = s.count(i)\n if c != 0\n j = s.rindex(i)\n s = s[(j + 1)..-1] + s[0...j].map! do |e|\n if e == i || e == 9\n e\n else\n e + 1\n end\n end.tap { |s| s.delete(i) }.sort!\n a += [i] * c\n end\n end\n puts a.join\nend\n"}], "src_uid": "906b319e41f716e734cf04b34678aa58"} {"source_code": "n,m = gets.split.map(&:to_i)\nans = 0\n\nhs = Hash.new(0)\n\na = gets.split.map(&:to_i)\n\ni = 0\nj = 0\nok = false\nwhile i < a.size\n if i - 1 >= 0\n ok = false if hs[a[i-1]] == m\n hs[a[i-1]] -= 1\n end\n\n until ok or j == a.size\n ok = true if (hs[a[j]] += 1) == m\n j += 1\n end\n ans += a.size - j + 1 if ok\n#p [i,j,ans]\n# p hs\n i += 1\nend\n\nputs ans\n", "positive_code": [{"source_code": "n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j;h[a[i]]-=1;};p z"}, {"source_code": "n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j;h[a[i]]-=1;};p z\n"}, {"source_code": "n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j;h[a[i]]-=1;};p z\n"}, {"source_code": "n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j;h[a[i]]-=1;};p z\n"}, {"source_code": "n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j;h[a[i]]-=1;};p z\n"}, {"source_code": "n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j;h[a[i]]-=1;};p z\n"}, {"source_code": "n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j;h[a[i]]-=1;};p z\n"}, {"source_code": "n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j;h[a[i]]-=1;};p z\n"}, {"source_code": "n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j;h[a[i]]-=1;};p z\n"}], "negative_code": [{"source_code": "n,m=gets.split.map &:to_i;a=gets.split.map &:to_i;h=Hash.new 0;j,z=-1,0;n.times{|i|h[i]-=1;h[a[j+=1]]+=1 until h[a[j]]>=m||j==n;z+=n-j};p z"}], "src_uid": "5346698abe40ce0477f743779da7c725"} {"source_code": "s = gets.chomp.chars.map &:ord\nt = gets.chomp\nbads = [0]*97 + t.chars.map{ |i| i == ?0 }\nk = gets.to_i\n\nans = 0\npre = []\n\nfor x in (0...s.length).map{ |i| s[i..-1] }.sort\n h = pre.zip(x).take_while{ |i, j| i == j }.length\n p = 0\n x.each_with_index do |c, i|\n\t\tp += 1 if bads[c]\n next if i < h\n\t\tbreak if p > k\n\t\tans += 1\n end\n\tpre = x\nend\n\nputs ans\n", "positive_code": [{"source_code": "f=->x{gets.scan(/\\S/).map &x}\ns=f[->i{i.ord-97}]\nb=f[->i{i>?0}]\nk=gets.to_i\na=0\n(0...s.size).map{|i|s.drop i}.sort.inject []{|r,x|h=1\nr.zip(x).all?{|i,j|i==j&&h+=1}\nt=i=0\nx.all?{|c|i+=1;(b[c]||k>=t+=1)&&(ix{gets.scan(/\\S/).map &x}\ns=f[->i{i.ord-97}]\nb=f[->i{i>?0}]\nk=gets.to_i\na=0\n(0...s.size).map{|i|s.drop i}.sort.inject []{|r,x|h=1\nr.zip(x).all?{|i,j|i==j&&h+=1}\nt=i=0\nx.all?{|c|i+=1;(b[c]||k>=t+=1)&&(ix{gets.scan(/\\S/).map &x}\ns=f[->i{i.ord-97}]\nb=f[->i{i>?0}]\nk=gets.to_i\na=0\n(0...s.size).map{|i|s.drop i}.sort.inject []{|r,x|h=1\nr.zip(x).all?{|i,j|i==j&&h+=1}\nt=i=0\nx.all?{|c|i+=1;(b[c]||k>=t+=1)&&(ix{gets.scan(/\\S/).map &x}\ns=f[->i{i.ord-97}]\nb=f[->i{i>?0}]\nk=gets.to_i\na=0\n(0...s.size).map{|i|s.drop i}.sort.inject []{|r,x|h=1\nr.zip(x).all?{|i,j|i==j&&h+=1}\nt=i=0\nx.all?{|c|i+=1;(b[c]||k>=t+=1)&&(ix{gets.scan(/\\S/).map &x}\ns=f[->i{i.ord-97}]\nb=f[->i{i>?0}]\nk=gets.to_i\na=0\n(0...s.size).map{|i|s.drop i}.sort.inject []{|r,x|h=1\nr.zip(x).all?{|i,j|i==j&&h+=1}\nt=i=0\nx.all?{|c|i+=1;(b[c]||k>=t+=1)&&(ix{gets.scan(/\\S/).map &x}\ns=f[->i{i.ord-97}]\nb=f[->i{i>?0}]\nk=gets.to_i\na=0\n(0...s.size).map{|i|s.drop i}.sort.inject []{|r,x|h=1\nr.zip(x).all?{|i,j|i==j&&h+=1}\nt=i=0\nx.all?{|c|i+=1;(b[c]||k>=t+=1)&&(ix{gets.scan(/\\S/).map &x}\ns=f[->i{i.ord-97}]\nb=f[->i{i>?0}]\nk=gets.to_i\na=0\n(0...s.size).map{|i|s.drop i}.sort.inject []{|r,x|h=1\nr.zip(x).all?{|i,j|i==j&&h+=1}\nt=i=0\nx.all?{|c|i+=1;(b[c]||k>=t+=1)&&(ix{gets.scan(/\\S/).map &x}\ns=f[->i{i.ord-97}]\nb=f[->i{i>?0}]\nk=gets.to_i\na=0\n(0...s.size).map{|i|s.drop i}.sort.inject []{|r,x|h=1\nr.zip(x).all?{|i,j|i==j&&h+=1}\nt=i=0\nx.all?{|c|i+=1;(b[c]||k>=t+=1)&&(ix{gets.scan(/\\S/).map &x}\ns=f[->i{i.ord-97}]\nb=f[->i{i>?0}]\nk=gets.to_i\na=0\n(0...s.size).map{|i|s.drop i}.sort.inject []{|r,x|h=1\nr.zip(x).all?{|i,j|i==j&&h+=1}\nt=i=0\nx.all?{|c|i+=1;(b[c]||k>=t+=1)&&(i t then \n k = t\n while k < s do\n res1 += d[k]\n k += 1\n end\n while k < n do\n res2 += d[k]\n k += 1\n end\n k = 0\n while k < t do\n res2 += d[k]\n k += 1\n end\nelse\n k = s\n res1 = 0\n while k < t do\n res1 += d[k]\n k += 1\n end\n while k < n do\n res2 += d[k]\n k += 1\n end\n k = 0\n while k < s do\n res2 += d[k]\n k += 1\n end\nend\n\nputs [res1, res2].min"}, {"source_code": "class Array\n def sum\n self.inject{|sum, x| sum + x}\n end\nend\nnum = gets.chomp.to_i\ndis = gets.chomp.split(\" \").map {|x| x.to_i}\ntmp = gets.chomp.split(\" \")\na = tmp[0].to_i\nb = tmp[1].to_i\nif a > b\n a,b = b,a\nend\nr1 = 0\nfor i in a-1..b-2\n r1 += dis[i]\nend\n\nif r1 < dis.sum-r1\n puts r1\nelse\n puts dis.sum-r1\nend\n"}, {"source_code": "n = gets.to_i\nd = gets.split(' ').map(&:to_i)\ns, t = gets.split(' ').map(&:to_i)\nif t < s\n s , t = t, s\nend\nl1 , l2 = 0, 0\n\nfor i in 0..d.size - 1 do\n if (i < s - 1) || (i > t - 2)\n l1 += d[i]\n else\n l2 += d[i]\n end\nend\n\nputs (if l1 < l2 then l1 else l2 end)\n"}, {"source_code": "n = gets.chomp.to_i\nd = gets.chomp.split(\" \").map{|x| x.to_i}\ns,j = gets.chomp.split(\" \").map{|x| x.to_i}.sort\n\nsum1 = 0\n(s-1..j-2).each do |i|\n sum1 += d[i]\nend\n\nsum2 = 0\n(0..s-2).each do |i|\n sum2 += d[i]\nend\n\n(j-1..n-1).each do |i|\n sum2 += d[i]\nend\n\nputs [sum1,sum2 ].min"}, {"source_code": "num_stations = gets.to_i\nstations = gets.split.collect {|i| i.to_i}\nreq_stations = gets.split.collect {|i| i.to_i}\ntotal_distance = stations.inject(:+)\ndistance = 0\nfirst = req_stations.min\nlast = req_stations.max\nfor i in first-1...last-1\n\tdistance = distance + stations[i]\nend\nputs [distance,total_distance-distance].min\n"}, {"source_code": "n = gets.to_i\ndis = Array.new(n+1, 0)\nd = gets.split.map(&:to_i)\nfor i in 1..n\n dis[i] = dis[i-1]+d[i-1]\nend\na = gets.split.map(&:to_i)\nA = (a.min) -1\nB = (a.max) -1\nputs [dis[B] - dis[A], (dis[n]-dis[B]) + dis[A]].min"}, {"source_code": "#!/usr/bin/ruby\n\nn = STDIN.readline.to_i\n\ndistances = STDIN.readline.split.collect {|s| s.to_i}\ntotal = distances.inject {|sum, x| sum += x }\n\nlimits = STDIN.readline.split.collect {|s| s.to_i}\nlimits.sort!\n\nsum = 0\n((limits[0]-1)..(limits[1]-2)).each do |i|\n\tsum += distances[i]\nend\nputs [sum, total-sum].min\n\n"}, {"source_code": "r = -> {gets.split.map(&:to_i)}\nn = gets.to_i\nv = r[]\na,b = r[].map{|x| x-=1}\ns = 0\nvv = ([0] + v + v[0..-2]).map{|x| s+= x}\na,b=b,a if a > b\np [vv[b] - vv[a],vv[a + n] - vv[b]].min"}, {"source_code": "l = gets.chomp.to_i\narr = gets.chomp.split(' ').map(&:to_i)\ns, t = gets.chomp.split(' ').map(&:to_i).sort\n\ns -= 1\nt -= 1\n\nl1 = l2 = 0\n\ns.upto(t-1).each do |ind|\n l1 += arr[ind]\nend\n\n(s-1).downto(0).each do |ind|\n l2 += arr[ind]\nend\n\nt.upto(l-1).each do |ind|\n l2 += arr[ind]\nend\n\n#puts l1, l2, s ,t\nputs l1 > l2 ? l2 : l1"}, {"source_code": "def run\n n = ARGF.readline.to_i\n d = ARGF.readline.split.map(&:to_i)\n t, s = ARGF.readline.split.map(&:to_i)\n\n positive = 0\n cur = t - 1\n while cur != (s - 1)\n positive += d[cur]\n cur = (cur + 1) % n\n end\n\n negative = 0\n cur = t - 1\n while cur != (s - 1)\n cur = (cur + n - 1) % n\n negative += d[cur]\n end\n\n puts [positive, negative].min\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def run\n n = ARGF.readline.to_i\n d = ARGF.readline.split.map(&:to_i)\n t, s = ARGF.readline.split.map(&:to_i)\n\n sum = 0\n cur = t - 1\n while cur != (s - 1)\n sum += d[cur]\n cur = (cur + 1) % n\n end\n\n puts [sum, d.reduce(:+) - sum].min\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\n0.upto(a-1) {|i| b[i]=b[i].to_i}\nd=gets.chomp.split(\" \")\n0.upto(1) {|i| d[i]=d[i].to_i}\nd.sort!\nans1=0\nans2=0\n\n(d[0]-1).upto(d[1]-2) {|i| ans1+=b[i]}\nif d[0]!=1\n0.upto(d[0]-2) {|i| ans2+=b[i]}\nend\n(a-1).downto(d[1]-1 ){|i| ans2+=b[i]}\nif ans1= sov2\n puts sov2\nelse\n puts sov\nend\n"}, {"source_code": "n = gets.to_i\nd = gets.split(' ').collect!{|i| i.to_i}\n\ns, t = gets.split(' ').collect!{|i| i.to_i - 1}.sort\n\nsum = 0\nsum1 = 0\nd.each_index do |i|\n\tsum += d[i]\n\tsum1 += d[i] if i >= s && i < t\nend\nsum2 = sum - sum1\n\np [sum1, sum2].min\n"}, {"source_code": "gets\nds = gets.split.map(&:to_i)\ns, t = gets.split.map(&:to_i)\n\ns, t = [s, t].sort\n\nfirst = ds[(s-1)..(t-2)].reduce(:+) || 0\nsecond = ds.reduce(:+) - first\np [first, second].min\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.split(\" \").collect! {|x| x.to_i}\ns1,t1 = gets.split(\" \").collect! {|x| x.to_i}\nsum = 0\narr.each {|v|\n\tsum += v\n}\n\nf = 0\ns = [s1,t1].min\nt = [s1,t1].max\narr[(s-1)...(t-1)].each {|w|\n\tf += w\n}\n\nputs [f,sum-f].min"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\n0.upto(a-1) {|i| b[i]=b[i].to_i}\nd=gets.chomp.split(\" \")\n0.upto(1) {|i| d[i]=d[i].to_i}\nd.sort!\nans1=0\nans2=0\n\n(d[0]-1).upto(d[1]-2) {|i| ans1+=b[i]}\nif d[0]!=1\n0.upto(d[0]-2) {|i| ans2+=b[i]}\nend\n(a-1).downto(d[1]-1 ){|i| ans2+=b[i]}\nif ans1= sov2\n\tputs sov2\nelse\n\tputs sov\nend\n\n\n"}, {"source_code": "n = gets.to_i\nd = gets.split(' ').collect!{|i| i.to_i}\n\ns, t = gets.split(' ').collect!{|i| i.to_i}.sort\n\nrast1 = 0\n(s..(t-1)).each do |x|\n\trast1 += d[x-1]\nend\n\nrast2 = 0\nif s > 1\n\t(0..(s-1)).each do |x|\n\t\trast2 += d[x-1]\n\tend\nend\n\n(t..n).each do |x|\n\trast2 += d[x-1]\nend\n\nif rast1 < rast2\n\tp rast1\nelse\n\tp rast2\nend"}, {"source_code": "n = gets.to_i\nd = gets.split(' ').collect!{|i| i.to_i}\n\ns, t = gets.split(' ').collect!{|i| i.to_i}.sort\n\n\nif t > s\n\trast1 = 0\n\n\t(s..(t-1)).each do |x|\n\t\trast1 += d[x-1]\n\tend\n\n\trast2 = 0\n\tif s > 1\n\t\t(0..(s-1)).each do |x|\n\t\t\trast2 += d[x-1]\n\t\tend\n\tend\n\n\t(t..n).each do |x|\n\t\trast2 += d[x-1]\n\tend\n\n\tif rast1 < rast2\n\t\tp rast1\n\telse\n\t\tp rast2\n\tend\nelse\n\tp 0\nend\n\n"}, {"source_code": "gets\nds = gets.split.map(&:to_i)\ns, t = gets.split.map(&:to_i)\n\nfirst = ds[(s-1)..(t-2)].reduce(:+) || 0\nsecond = ds.reduce(:+) - first\np [first, second].min\n"}, {"source_code": "gets\nds = gets.split.map(&:to_i)\nps = gets.split.map(&:to_i).map(&:pred)\nputs [ds.rotate!(-ds[0]).slice!(0, ps.reduce(&:-).abs), ds].map { |i|\n (i || []).reduce(&:+)\n}.min\n"}, {"source_code": "l = gets.chomp.to_i\narr = gets.chomp.split(' ').map(&:to_i)\ns, t = gets.chomp.split(' ').map(&:to_i).sort\n\ns -= 1\nt -= 1\n\nl1 = l2 = 0\n\ns.upto(t-1).each do |ind|\n l1 += arr[ind]\nend\n\ns.downto(0).each do |ind|\n l2 += arr[ind]\nend\n\nt.upto(l-1).each do |ind|\n l2 += arr[ind]\nend\n\nputs l1 > l2 ? l2 : l1"}], "src_uid": "22ef37041ebbd8266f62ab932f188b31"} {"source_code": "def reverse_signs(s)\n\tcase s\n\twhen \">=\"\n\t\treturn \"<\"\n\twhen \">\"\n\t\treturn \"<=\"\n\twhen \"<\"\n\t\treturn \">=\"\n\twhen \"<=\"\n\t\treturn \">\"\t\t\t\t\t\t\t\n\tend\n\nend\n\ndef calc(s,no,start,finish)\n\tcase s\n\twhen \">=\"\n\t\tstart = no if no > start\n\twhen \">\"\n\t\tstart = no + 1 if no + 1 > start\n\twhen \"<\"\n\t\tfinish = no - 1 if no - 1 < finish\n\twhen \"<=\"\n\t\tfinish = no\tif no < finish\n\tend\n\treturn start,finish\nend\n\n\nn = gets.to_i\nstart = -(10 ** 9) * 2\nfinish = (10 ** 9) * 2\n\nn.times do\n\ts,no,ans = gets.split(\" \")\n\tno = no.to_i\n\t# puts \"#{s},#{no},#{ans}\"\n\tif ans == \"Y\"\n\t\t# puts \"here\"\n\t\tstart,finish = calc(s,no,start,finish)\n\t\t# puts \"#{start},#{finish}\"\n\telse\n\t\tstart,finish = calc(reverse_signs(s),no,start,finish)\n\tend\nend\n# puts start\n# puts finish\nif start <= finish\n\tputs \"#{start}\"\nelse\n\tputs \"Impossible\"\nend", "positive_code": [{"source_code": "a = 2 * -10 ** 9\nb = 2 * 10 ** 9\nn = gets.to_i\nt = { \">=\" => \"<\", \"<=\" => \">\", \">\" => \"<=\", \"<\" => \">=\" }\nn.times do\n\ts, c, an = gets.split\n\ts = t[s] if an.chomp == \"N\"\n\tc = c.to_i\n\tcase s\n\t\twhen \">=\"\n\t\t\ta = c if c > a\n\t\twhen \">\"\n\t\t\ta = c + 1 if c + 1 > a\n\t\twhen \"<=\"\n\t\t\tb = c if c < b\n\t\twhen \"<\"\n\t\t\tb = c - 1 if c - 1 < b\n\tend\nend\n\nputs a if (a..b).size.nonzero?\nputs \"Impossible\" if (a..b).size.zero?"}, {"source_code": "#f = File.open('test1.txt', 'r')\nf = STDIN\n\nn = f.gets.chomp.to_i\nleft, right = -2_000_000_000, 2_000_000_000\nop = {\n \">\" => \"<=\",\n \"<\" => \">=\",\n \">=\" => \"<\",\n \"<=\" => \">\"\n}\nn.times do\n sign, x, answer = f.gets.chomp.split\n sign = op[sign] if answer == 'N'\n case sign\n when '<' #\n right = [right, x.to_i - 1].min\n when '>' #\n left = [left, x.to_i + 1].max\n when '<=' #\n right = [right, x.to_i].min\n when '>=' #\n left = [left, x.to_i].max\n end\nend\n\nputs (left <= right ? left : 'Impossible')\n"}, {"source_code": "#!/usr/bin/ruby\nA=['>','<','<=','>=']\nmin=-10**9-1\nmax=10**9+1\ngets.to_i.times{\nline=gets.chomp.split\nline[0]=A.index(line[0])\nline[0]^=2 if line[2]=='N'\nline[1]=line[1].to_i\nif line[0]==0\n\tmin=[line[1]+1,min].max\nelsif line[0]==1\n\tmax=[line[1]-1,max].min\nelsif line[0]==2\n\tmax=[line[1],max].min\nelse\n\tmin=[line[1],min].max\nend\n}\nputs min<=max ? min : 'Impossible'"}, {"source_code": "mn = -0x3f3f3f3f\nmx = -mn\ngets.to_i.times do\n\top, x, ans = gets.split\n\tx = x.to_i\n\t(op = \"<\") && (x = x + 1) if op == \"<=\"\n\t(op = \">=\") && (x = x + 1) if op == \">\"\n\tif op == \">=\" && ans == \"Y\" || op == \"<\" && ans == \"N\"\n\t\tmn = [mn, x].max\n\telse\n\t\tmx = [mx, x-1].min\n\tend\nend\nputs mn <= mx ? mn : \"Impossible\"\n"}, {"source_code": "min = 10 ** 9 * (-2)\nmax = 10 ** 9 * 2\n\nincrease_min = proc { |num| min = (min >= num) ? min : num }\ndecrease_max = proc { |num| max = (max <= num) ? max : num }\n\nn = gets.chomp.to_i\nn.times do\n sign, num, answer = gets.chomp.split \n num = num.to_i\n\n case sign\n when \">\"\n increase_min[num + 1] if answer == \"Y\"\n decrease_max[num] if answer == \"N\"\n when \">=\"\n increase_min[num] if answer == \"Y\"\n decrease_max[num - 1] if answer == \"N\" \n when \"<\"\n decrease_max[num - 1] if answer == \"Y\"\n increase_min[num] if answer == \"N\"\n when \"<=\"\n decrease_max[num] if answer == \"Y\"\n increase_min[num + 1] if answer == \"N\"\n end\nend\n\nif min > max\n print \"Impossible\"\nelse\n print min\nend"}, {"source_code": "n=gets.to_i\nmaxi,mini=2000000000,-2000000000\nn.times do\n\ta=gets.chomp.split\n\tch,num,is=a[0],a[1].to_i,a[2]\n\tif((ch[0]=='<'&&ch[1]=='='&&is=='Y'||ch[0]=='>'&&ch[1]!='='&&is=='N')&&maxi>num)\n\t\tmaxi=num;\n\telsif((ch[0]=='>'&&ch[1]!='='&&is=='Y'||ch[0]=='<'&&ch[1]=='=' &&is=='N')&&mini'&&ch[1]=='='&&is=='Y'||ch[0]=='<'&&ch[1]!='='&&is=='N')&& mini'&&ch[1]=='='&&is=='N')&&maxi>num-1)\n\t\tmaxi=num-1;\n\tend\nend\nputs (mini<=maxi)? mini : \"Impossible\""}, {"source_code": "class ProblemA\n INF = 2e9.to_i\n\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @min, @max = -INF, INF\n @qnum = @dats[0].to_i\n end\n\n def solve\n possible = true\n (1..@qnum).each do |row|\n question = @dats[row]\n operator, num, ans = question.split(\" \").map {|s| s = s.gsub(\" \", \"\")}\n num = num.to_i\n\n ret = case operator\n when \">=\"\n ans == \"Y\" ? update(operator, num) : update(\"<\", num)\n when \"<=\"\n ans == \"Y\" ? update(operator, num) : update(\">\", num)\n when \">\"\n ans == \"Y\" ? update(operator, num) : update(\"<=\", num)\n when \"<\"\n ans == \"Y\" ? update(operator, num) : update(\">=\", num)\n end\n (possible = false and break) unless ret \n end\n if possible\n print @min\n else\n print \"Impossible\"\n end\n end\n\n def update(operator, num)\n case operator\n when \">=\"\n @min = num if @min < num\n when \"<=\"\n @max = num if @max > num\n when \">\"\n @min = num+1 if @min < num+1\n when \"<\"\n @max = num-1 if @max > num-1\n end\n @min > @max ? false : true\n end\nend\n\nsolver = ProblemA.new\nsolver.solve\n"}, {"source_code": "n = gets.chomp.to_i\nmax = (10 ** 9) * 2\nmin = -max\nn.times do\n sign, x, ans = gets.chomp.split(/ /)\n x = x.to_i\n if ans == \"N\"\n case sign\n when '>'\n sign = '<='\n when '>='\n sign = '<'\n when '<'\n sign = '>='\n when '<='\n sign = '>'\n end\n end\n case sign\n when '>='\n min = [min, x].max\n when '>'\n min = [min, x + 1].max\n when '<'\n max = [max, x - 1].min\n when '<='\n max = [max, x].min\n end\nend\nif min <= max\n puts min\nelse\n puts \"Impossible\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\na = 2*-10e8\nb = 2* 10e8\nn.times do |e|\n\ts = gets.chomp\n\tre = /^([>=<]{1,2})\\s([-]?\\d*)\\s([YN])$/\n\tmd = re.match(s)\n\n\ttoken = md[1]\n\tif md[3] =~ /^N/\n\t\ttoken = '>=' if md[1] == '<'\n\t\ttoken = '<=' if md[1] == '>'\n\t\ttoken = '<' if md[1] == '>='\n\t\ttoken = '>' if md[1] == '<='\n\tend\n\n\tif token[0] == '<'\n\t\tif b >= md[2].to_i\n\t\t\tb = md[2].to_i - 1\n\t\t\n\t\t\tb += 1 if token.length > 1\n\t\tend\n\tend\n\t\n\tif token[0] == ('>')\n\t\tif a <= md[2].to_i\n\t\t\ta = md[2].to_i + 1\n\t\t\n\t\t\ta -= 1 if token.length > 1\n\t\tend\n\tend\nend\n\nif a > b \n\tputs \"Impossible\"\nelse\n\tputs Random.rand(a..b).to_i\nend"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nA=['>','<','<=','>=']\nmin=-10**9\nmax=10**9\ngets.to_i.times{\nline=gets.chomp.split\nline[0]=A.index(line[0])\nline[0]^=2 if line[2]=='N'\nline[1]=line[1].to_i\nif line[0]==0\n\tmin=line[1]+1\nelsif line[0]==1\n\tmax=line[1]-1\nelsif line[0]==2\n\tmax=line[1]\nelse\n\tmin=line[1]\nend\n}\nputs min<=max ? min : 'Impossible'"}, {"source_code": "#!/usr/bin/ruby\nA=['>','<','<=','>=']\nmin=-10**9\nmax=10**9\ngets.to_i.times{\nline=gets.chomp.split\nline[0]=A.index(line[0])\nline[0]^=2 if line[2]=='N'\nline[1]=line[1].to_i\nif line[0]==0\n\tmin=[line[1]+1,min].max\nelsif line[0]==1\n\tmax=[line[1]-1,max].min\nelsif line[0]==2\n\tmax=[line[1],max].min\nelse\n\tmin=[line[1],min].max\nend\n}\nputs min<=max ? min : 'Impossible'"}, {"source_code": "min = 10 ** 9 * (-1)\nmax = 10 ** 9\n\nn = gets.chomp.to_i\nn.times do\n sign, num, answer = gets.chomp.split\n next if answer == \"N\"\n\n num = num.to_i\n case sign\n when \">\"\n min = (min > num) ? min : num + 1\n when \"<\"\n max = (max < num) ? max : num - 1\n when \">=\"\n min = (min >= num) ? min : num\n when \"<=\"\n max = (max <= num) ? max : num\n end\nend\n\nif min > max\n print \"Impossible\"\nelse\n print min\nend"}, {"source_code": "min = 10 ** 9 * (-1)\nmax = 10 ** 9\n\nincrease_min = proc { |num| min = (min >= num) ? min : num }\ndecrease_max = proc { |num| max = (max <= num) ? max : num }\n\nn = gets.chomp.to_i\nn.times do\n sign, num, answer = gets.chomp.split \n num = num.to_i\n\n case sign\n when \">\"\n increase_min[num + 1] if answer == \"Y\"\n decrease_max[num] if answer == \"N\"\n when \">=\"\n increase_min[num] if answer == \"Y\"\n decrease_max[num - 1] if answer == \"N\" \n when \"<\"\n decrease_max[num - 1] if answer == \"Y\"\n increase_min[num] if answer == \"N\"\n when \"<=\"\n decrease_max[num] if answer == \"Y\"\n increase_min[num + 1] if answer == \"N\"\n end\nend\n\nif min > max\n print \"Impossible\"\nelse\n print min\nend"}, {"source_code": "class ProblemA\n INF = 2e10\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @min, @max = -INF, INF\n @qnum = @dats[0].to_i\n end\n\n def solve\n possible = true\n (1..@qnum).each do |row|\n question = @dats[row]\n operator, num, ans = question.split(\" \").map {|s| s = s.gsub(\" \", \"\")}\n num = num.to_i\n\n ret = case operator\n when \">=\"\n ans == \"Y\" ? update(operator, num) : update(\"<\", num)\n when \"<=\"\n ans == \"Y\" ? update(operator, num) : update(\">\", num)\n when \">\"\n ans == \"Y\" ? update(operator, num) : update(\"<=\", num)\n when \"<\"\n ans == \"Y\" ? update(operator, num) : update(\">=\", num)\n end\n (possible = false and break) unless ret \n end\n if possible\n print @min\n else\n print \"Impossible\"\n end\n end\n\n def update(operator, num)\n print \"#{operator} #{num}\\n\"\n case operator\n when \">=\"\n @min = num if @min < num\n when \"<=\"\n @max = num if @max > num\n when \">\"\n @min = num+1 if @min < num+1\n when \"<\"\n @max = num-1 if @max > num-1\n end\n @min > @max ? false : true\n end\nend\n\nsolver = ProblemA.new\nsolver.solve\n"}, {"source_code": "class ProblemA\n INF = 2e10.to_i\n\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @min, @max = -INF, INF\n @qnum = @dats[0].to_i\n end\n\n def solve\n possible = true\n (1..@qnum).each do |row|\n question = @dats[row]\n operator, num, ans = question.split(\" \").map {|s| s = s.gsub(\" \", \"\")}\n num = num.to_i\n\n ret = case operator\n when \">=\"\n ans == \"Y\" ? update(operator, num) : update(\"<\", num)\n when \"<=\"\n ans == \"Y\" ? update(operator, num) : update(\">\", num)\n when \">\"\n ans == \"Y\" ? update(operator, num) : update(\"<=\", num)\n when \"<\"\n ans == \"Y\" ? update(operator, num) : update(\">=\", num)\n end\n (possible = false and break) unless ret \n end\n if possible\n print @min\n else\n print \"Impossible\"\n end\n end\n\n def update(operator, num)\n case operator\n when \">=\"\n @min = num if @min < num\n when \"<=\"\n @max = num if @max > num\n when \">\"\n @min = num+1 if @min < num+1\n when \"<\"\n @max = num-1 if @max > num-1\n end\n @min > @max ? false : true\n end\nend\n\nsolver = ProblemA.new\nsolver.solve\n"}, {"source_code": "class ProblemA\n INF = 2e10\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @min, @max = -INF, INF\n @qnum = @dats[0].to_i\n end\n\n def solve\n possible = true\n (1..@qnum).each do |row|\n question = @dats[row]\n operator, num, ans = question.split(\" \").map {|s| s = s.gsub(\" \", \"\")}\n num = num.to_i\n\n ret = case operator\n when \">=\"\n ans == \"Y\" ? update(operator, num) : update(\"<\", num)\n when \"<=\"\n ans == \"Y\" ? update(operator, num) : update(\">\", num)\n when \">\"\n ans == \"Y\" ? update(operator, num) : update(\"<=\", num)\n when \"<\"\n ans == \"Y\" ? update(operator, num) : update(\">=\", num)\n end\n (possible = false and break) unless ret \n end\n if possible\n print @min\n else\n print \"Impossible\"\n end\n end\n\n def update(operator, num)\n case operator\n when \">=\"\n @min = num if @min < num\n when \"<=\"\n @max = num if @max > num\n when \">\"\n @min = num+1 if @min < num+1\n when \"<\"\n @max = num-1 if @max > num-1\n end\n @min > @max ? false : true\n end\nend\n\nsolver = ProblemA.new\nsolver.solve\n"}, {"source_code": "class ProblemA\n INF = 2e10.to_i\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @min, @max = -INF, INF\n @qnum = @dats[0].to_i\n end\n\n def solve\n possible = true\n (1..@qnum).each do |row|\n question = @dats[row]\n operator, num, ans = question.split(\" \").map {|s| s = s.gsub(\" \", \"\")}\n num = num.to_i\n\n ret = case operator\n when \">=\"\n ans == \"Y\" ? update(operator, num) : update(\"<\", num)\n when \"<=\"\n ans == \"Y\" ? update(operator, num) : update(\">\", num)\n when \">\"\n ans == \"Y\" ? update(operator, num) : update(\"<=\", num)\n when \"<\"\n ans == \"Y\" ? update(operator, num) : update(\">=\", num)\n end\n (possible = false and break) unless ret \n end\n if possible\n print @min\n else\n print \"Impossible\"\n end\n end\n\n def update(operator, num)\n case operator\n when \">=\"\n @min = num if @min < num\n when \"<=\"\n @max = num if @max > num\n when \">\"\n @min = num+1 if @min < num+1\n when \"<\"\n @max = num-1 if @max > num-1\n end\n @min > @max ? false : true\n end\nend\n\nsolver = ProblemA.new\nsolver.solve\n"}, {"source_code": "n = gets.chomp.to_i\nmax = (10 ** 9) * 2\nmin = -max\nn.times do\n sign, x, ans = gets.chomp.split(/ /)\n x = x.to_i\n if ans == \"N\"\n case sign\n when '>'\n sign = '<='\n when '>='\n sign = '<'\n when '<'\n sign = '>='\n when '<='\n sign = '>'\n end\n end\n case sign\n when '>='\n min = [min, x].max\n when '>'\n min = [min, x + 1].max\n when '<'\n max = [max, x - 1].min\n when '<='\n max = [max, x].min\n end\nend\nputs \"#{min} #{max}\"\nif min <= max\n puts min\nelse\n puts \"Impossible\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\nmin = -1000000000\nmax = -min\nn.times do\n sign, x, ans = gets.chomp.split(/ /)\n x = x.to_i\n if ans == \"N\"\n case sign\n when '>'\n sign = '<='\n when '>='\n sign = '<'\n when '<'\n sign = '>='\n when '<='\n sign = '>'\n end\n end\n case sign\n when '>='\n min = [min, x].max\n when '>'\n min = [min, x + 1].max\n when '<'\n max = [max, x - 1].min\n when '<='\n max = [max, x].min\n end\nend\nif min <= max\n puts min\nelse\n puts \"Impossible\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\nmin = -1000000000\nmax = -min\nn.times do\n sign, x, ans = gets.chomp.split(/ /)\n x = x.to_i\n if ans == \"N\"\n case sign\n when '>'\n sign = '<='\n when '>='\n sign = '<'\n when '<'\n sign = '>='\n when '<='\n sign = '>'\n end\n end\n case sign\n when '>', '>='\n min = [min, x].max\n when '<', '<='\n max = [max, x].min\n end\nend\nif min <= max\n puts min\nelse\n puts \"Impossible\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\na = -10e8\nb = 10e8\nn.times do |e|\n\ts = gets.chomp\n\tre = /^([>=<]{1,2})\\s([-]?\\d*)\\s([YN])$/\n\tmd = re.match(s)\n\n\ttoken = md[1]\n\tif md[3] =~ /^N/\n\t\ttoken = '>=' if md[1] == '<'\n\t\ttoken = '<=' if md[1] == '>'\n\t\ttoken = '<' if md[1] == '>='\n\t\ttoken = '>' if md[1] == '<='\n\tend\n\n\tif token[0] == '<'\n\t\tif b > md[2].to_i\n\t\t\tb = md[2].to_i - 1\n\t\tend\n\t\t\n\t\tif token.length > 1\n\t\t\tb += 1\n\t\tend\n\tend\n\t\n\tif token[0].eql?('>')\n\t\tif a < md[2].to_i\n\t\t\ta = md[2].to_i + 1\n\t\tend\n\t\t\n\t\tif token.length > 1\n\t\t\ta -= 1\n\t\tend\n\tend\nend\n\nif a > b \n\tputs \"Impossible\"\nelse\n\tputs Random.rand(a..b).to_i\nend"}, {"source_code": "n = gets.chomp.to_i\n\na = 2*-10e8\nb = 10e8\nn.times do |e|\n\ts = gets.chomp\n\tre = /^([>=<]{1,2})\\s([-]?\\d*)\\s([YN])$/\n\tmd = re.match(s)\n\n\ttoken = md[1]\n\tif md[3] =~ /^N/\n\t\ttoken = '>=' if md[1] == '<'\n\t\ttoken = '<=' if md[1] == '>'\n\t\ttoken = '<' if md[1] == '>='\n\t\ttoken = '>' if md[1] == '<='\n\tend\n\n\tif token[0] == '<'\n\t\tif b > md[2].to_i\n\t\t\tb = md[2].to_i - 1\n\t\t\n\t\t\tb += 1 if token.length > 1\n\t\tend\n\tend\n\t\n\tif token[0].eql?('>')\n\t\tif a < md[2].to_i\n\t\t\ta = md[2].to_i + 1\n\t\t\n\t\t\ta -= 1 if token.length > 1\n\t\tend\n\tend\nend\n\nif a > b \n\tputs \"Impossible\"\nelse\n\tputs Random.rand(a..b).to_i\nend"}, {"source_code": "n = gets.chomp.to_i\n\na = -10e9\nb = 10e9\nn.times do |e|\n\ts = gets.chomp\n\tre = /^([>=<]{1,2})\\s([-]?\\d*)\\s([YN])$/\n\tmd = re.match(s)\n\tif md[3] =~ /^Y/\n\t\tif md[1][0] == '<'\n\t\t\tif b > md[2].to_i\n\t\t\t\tb = md[2].to_i - 1\n\t\t\tend\n\t\t\t\n\t\t\tif md[1].length > 1\n\t\t\t\tb += 1\n\t\t\tend\n\t\tend\n\t\t\n\t\tif md[1][0].eql?('>')\n\t\t\tif a < md[2].to_i\n\t\t\t\ta = md[2].to_i + 1\n\t\t\tend\n\t\t\t\n\t\t\tif md[1].length > 1\n\t\t\t\ta -= 1\n\t\t\tend\n\t\tend\n\tend\nend\n\n# puts a\n# puts b\nif a > b \n\tputs \"Impossible\"\nelse\n\tputs Random.rand(a..b).to_i\nend"}, {"source_code": "n = gets.chomp.to_i\n\na = 2*-10e8\nb = 2* 10e8\nn.times do |e|\n\ts = gets.chomp\n\tre = /^([>=<]{1,2})\\s([-]?\\d*)\\s([YN])$/\n\tmd = re.match(s)\n\n\ttoken = md[1]\n\tif md[3] =~ /^N/\n\t\ttoken = '>=' if md[1] == '<'\n\t\ttoken = '<=' if md[1] == '>'\n\t\ttoken = '<' if md[1] == '>='\n\t\ttoken = '>' if md[1] == '<='\n\tend\n\n\tif token[0] == '<'\n\t\tif b > md[2].to_i\n\t\t\tb = md[2].to_i - 1\n\t\t\n\t\t\tb += 1 if token.length > 1\n\t\tend\n\tend\n\t\n\tif token[0].eql?('>')\n\t\tif a < md[2].to_i\n\t\t\ta = md[2].to_i + 1\n\t\t\n\t\t\ta -= 1 if token.length > 1\n\t\tend\n\tend\nend\n\nif a > b \n\tputs \"Impossible\"\nelse\n\tputs Random.rand(a..b).to_i\nend"}, {"source_code": "n = gets.chomp.to_i\n\na = -10e8\nb = 10e8\nn.times do |e|\n\ts = gets.chomp\n\tre = /^([>=<]{1,2})\\s([-]?\\d*)\\s([YN])$/\n\tmd = re.match(s)\n\n\ttoken = md[1]\n\tif md[3] =~ /^N/\n\t\ttoken = '>=' if md[1] == '<'\n\t\ttoken = '<=' if md[1] == '>'\n\t\ttoken = '<' if md[1] == '>='\n\t\ttoken = '>' if md[1] == '<='\n\tend\n\n\tif token[0] == '<'\n\t\tif b > md[2].to_i\n\t\t\tb = md[2].to_i - 1\n\t\t\n\t\t\tb += 1 if token.length > 1\n\t\tend\n\tend\n\t\n\tif token[0].eql?('>')\n\t\tif a < md[2].to_i\n\t\t\ta = md[2].to_i + 1\n\t\t\n\t\t\ta -= 1 if token.length > 1\n\t\tend\n\tend\nend\n\nif a > b \n\tputs \"Impossible\"\nelse\n\tputs Random.rand(a..b).to_i\nend"}, {"source_code": "n = gets.chomp.to_i\n\na = 2*-10e8\nb = 2* 10e8\nn.times do |e|\n\ts = gets.chomp\n\tre = /^([>=<]{1,2})\\s([-]?\\d*)\\s([YN])$/\n\tmd = re.match(s)\n\n\ttoken = md[1]\n\tif md[3] =~ /^N/\n\t\ttoken = '>=' if md[1] == '<'\n\t\ttoken = '<=' if md[1] == '>'\n\t\ttoken = '<' if md[1] == '>='\n\t\ttoken = '>' if md[1] == '<='\n\tend\n\n\tif token[0] == '<'\n\t\tif b > md[2].to_i\n\t\t\tb = md[2].to_i - 1\n\t\t\n\t\t\tb += 1 if token.length > 1\n\t\tend\n\tend\n\t\n\tif token[0].eql?('>')\n\t\tif a < md[2].to_i\n\t\t\ta = md[2].to_i + 1\n\t\t\n\t\t\ta -= 1 if token.length > 1\n\t\tend\n\tend\nend\n\nif a >= b \n\tputs \"Impossible\"\nelse\n\tputs Random.rand(a..b).to_i\nend"}, {"source_code": "n = gets.chomp.to_i\n\na = -10e9\nb = 10e9\nn.times do |e|\n\ts = gets.chomp\n\tre = /^([>=<]{1,2})\\s([-]?\\d*)\\s([YN])$/\n\tmd = re.match(s)\n\tif md[3] =~ /^Y/\n\t\tif md[1][0] == '<'\n\t\t\tif b > md[2].to_i\n\t\t\t\tb = md[2].to_i - 1\n\t\t\tend\n\t\t\t\n\t\t\tif md[1].length > 1\n\t\t\t\tb += 1\n\t\t\tend\n\t\tend\n\t\t\n\t\tif md[1][0].eql?('>')\n\t\t\tif a < md[2].to_i\n\t\t\t\ta = md[2].to_i + 1\n\t\t\tend\n\t\t\t\n\t\t\tif md[1].length > 1\n\t\t\t\ta -= 1\n\t\t\tend\n\t\tend\n\tend\nend\n\nif a > b \n\tputs \"Impossible\"\nelse\n\tputs Random.rand(a..b).to_i\nend"}, {"source_code": "n = gets.chomp.to_i\n\na = -10e8\nb = 10e8\nn.times do |e|\n\ts = gets.chomp\n\tre = /^([>=<]{1,2})\\s([-]?\\d*)\\s([YN])$/\n\tmd = re.match(s)\n\tif md[3] =~ /^Y/\n\t\tif md[1][0] == '<'\n\t\t\tif b > md[2].to_i\n\t\t\t\tb = md[2].to_i - 1\n\t\t\tend\n\t\t\t\n\t\t\tif md[1].length > 1\n\t\t\t\tb += 1\n\t\t\tend\n\t\tend\n\t\t\n\t\tif md[1][0].eql?('>')\n\t\t\tif a < md[2].to_i\n\t\t\t\ta = md[2].to_i + 1\n\t\t\tend\n\t\t\t\n\t\t\tif md[1].length > 1\n\t\t\t\ta -= 1\n\t\t\tend\n\t\tend\n\tend\nend\n\nif a > b \n\tputs \"Impossible\"\nelse\n\tputs Random.rand(a..b).to_i\nend"}, {"source_code": "def reverse_signs(s)\n\tcase s\n\twhen \">=\"\n\t\treturn \"<\"\n\twhen \">\"\n\t\treturn \"<=\"\n\twhen \"<\"\n\t\treturn \">=\"\n\twhen \"<=\"\n\t\treturn \">\"\t\t\t\t\t\t\t\n\tend\n\nend\n\ndef calc(s,no,start,finish)\n\tcase s\n\twhen \">=\"\n\t\tstart = no if no > start\n\twhen \">\"\n\t\tstart = no + 1 if no + 1 > start\n\twhen \"<\"\n\t\tfinish = no - 1 if no - 1 < finish\n\twhen \"<=\"\n\t\tfinish = no\tif no < finish\n\tend\n\treturn start,finish\nend\n\n\nn = gets.to_i\nstart = -10 ** 9\nfinish = 10 ** 9\nn.times do\n\ts,no,ans = gets.split(\" \")\n\tno = no.to_i\n\t# puts \"#{s},#{no},#{ans}\"\n\tif ans == \"Y\"\n\t\tputs \"here\"\n\t\tstart,finish = calc(s,no,start,finish)\n\t\t# puts \"#{start},#{finish}\"\n\telse\n\t\tstart,finish = calc(reverse_signs(s),no,start,finish)\n\tend\nend\nif start <= finish\n\tputs \"#{start}\"\nelse\n\tputs \"Impossible\"\nend"}, {"source_code": "def reverse_signs(s)\n\tcase s\n\twhen \">=\"\n\t\treturn \"<\"\n\twhen \">\"\n\t\treturn \"<=\"\n\twhen \"<\"\n\t\treturn \">=\"\n\twhen \"<=\"\n\t\treturn \">\"\t\t\t\t\t\t\t\n\tend\n\nend\n\ndef calc(s,no,start,finish)\n\tcase s\n\twhen \">=\"\n\t\tstart = no if no > start\n\twhen \">\"\n\t\tstart = no + 1 if no + 1 > start\n\twhen \"<\"\n\t\tfinish = no - 1 if no - 1 < finish\n\twhen \"<=\"\n\t\tfinish = no\tif no < finish\n\tend\n\treturn start,finish\nend\n\n\nn = gets.to_i\nstart = -10 ** 9\nfinish = 10 ** 9\nn.times do\n\ts,no,ans = gets.split(\" \")\n\tno = no.to_i\n\t# puts \"#{s},#{no},#{ans}\"\n\tif ans == \"Y\"\n\t\t# puts \"here\"\n\t\tstart,finish = calc(s,no,start,finish)\n\t\t# puts \"#{start},#{finish}\"\n\telse\n\t\tstart,finish = calc(reverse_signs(s),no,start,finish)\n\tend\nend\nif start <= finish\n\tputs \"#{start}\"\nelse\n\tputs \"Impossible\"\nend"}, {"source_code": "a = -10 ** 9\nb = 10 ** 9\nn = gets.to_i\nt = { \">=\" => \"<\", \"<=\" => \">\", \">\" => \"<=\", \"<\" => \">=\" }\nn.times do\n\ts, c, an = gets.split\n\ts = t[s] if an.chomp == \"N\"\n\tc = c.to_i\n\tcase s\n\t\twhen \">=\"\n\t\t\ta = c\n\t\twhen \">\"\n\t\t\ta = c + 1\n\t\twhen \"<=\"\n\t\t\tb = c\n\t\twhen \"<\"\n\t\t\tb = c - 1\n\tend\nend\n\nputs a if (a..b).size.nonzero?\nputs \"Impossible\" if (a..b).size.zero?"}, {"source_code": "a = -10 ** 9\nb = 10 ** 9\nn = gets.to_i\nt = { \">=\" => \"<\", \"<=\" => \">\", \">\" => \"<=\", \"<\" => \">=\" }\nn.times do\n\ts, c, an = gets.split\n\ts = t[s] if an.chomp == \"N\"\n\tc = c.to_i\n\tcase s\n\t\twhen \">=\"\n\t\t\ta = c if c > a\n\t\twhen \">\"\n\t\t\ta = c + 1 if c + 1 > a\n\t\twhen \"<=\"\n\t\t\tb = c if c < b\n\t\twhen \"<\"\n\t\t\tb = c - 1 if c - 1 < b\n\tend\nend\n\nputs a if (a..b).size.nonzero? and b >= -10 ** 9 and a <= 10 ** 9\nputs \"Impossible\" unless (a..b).size.nonzero? and b >= -10 ** 9 and a <= 10 ** 9"}, {"source_code": "a = -10 ** 9\nb = 10 ** 9\nn = gets.to_i\nt = { \">=\" => \"<\", \"<=\" => \">\", \">\" => \"<=\", \"<\" => \">=\" }\nn.times do\n\ts, c, an = gets.split\n\ts = t[s] if an.chomp == \"N\"\n\tc = c.to_i\n\tcase s\n\t\twhen \">=\"\n\t\t\ta = c if c > a\n\t\twhen \">\"\n\t\t\ta = c + 1 if c + 1 > a\n\t\twhen \"<=\"\n\t\t\tb = c if c < b\n\t\twhen \"<\"\n\t\t\tb = c - 1 if c - 1 < b\n\tend\nend\n\nputs a if (a..b).size.nonzero?\nputs \"Impossible\" if (a..b).size.zero?"}, {"source_code": "a = -10 ** 9 - 1\nb = 10 ** 9 + 1\nn = gets.to_i\nt = { \">=\" => \"<\", \"<=\" => \">\", \">\" => \"<=\", \"<\" => \">=\" }\nn.times do\n\ts, c, an = gets.split\n\ts = t[s] if an.chomp == \"N\"\n\tc = c.to_i\n\tcase s\n\t\twhen \">=\"\n\t\t\ta = c if c > a\n\t\twhen \">\"\n\t\t\ta = c + 1 if c + 1 > a\n\t\twhen \"<=\"\n\t\t\tb = c if c < b\n\t\twhen \"<\"\n\t\t\tb = c - 1 if c - 1 < b\n\tend\nend\n\nputs a if (a..b).size.nonzero? and a != -10 ** 9 - 1 and b != 10 ** 9 + 1\nputs \"Impossible\" unless (a..b).size.nonzero? and a != -10 ** 9 - 1 and b != 10 ** 9 + 1"}, {"source_code": "#f = File.open('test1.txt', 'r')\nf = STDIN\n\nn = f.gets.chomp.to_i\nleft, right = -2_000_000_000, 2_000_000_000\nop = {\n \">\" => \"<\",\n \"<\" => \">\",\n \">=\" => \"<=\",\n \"<=\" => \">=\"\n}\nn.times do\n sign, x, answer = f.gets.chomp.split\n sign = op[sign] if answer == 'N'\n case sign\n when '<' #\n right = [right, x.to_i - 1].min\n when '>' #\n left = [left, x.to_i + 1].max\n when '<=' #\n right = [right, x.to_i].min\n when '>=' #\n left = [left, x.to_i].max\n end\nend\n\nputs (left <= right ? left : 'Impossible')\n"}], "src_uid": "6c6f29e1f4c951cd0ff15056774f897d"} {"source_code": "a = gets.chomp.chars\na[-1] = a[0] = \"\"\np a.join(\"\").split(\", \").uniq.size\n", "positive_code": [{"source_code": "require 'set'\ns=gets.chomp\ns=s.slice(1,s.size-2).split(\", \")\nputs Set.new(s).count\n"}, {"source_code": "puts gets.split(//).select{|s| s[/[a-zA-Z]/]}.uniq.size\n"}, {"source_code": "s = gets.chomp\nputs s.gsub(\"{\", \"\").gsub(\"}\", \"\").split(\",\").map(&:strip).uniq.count"}, {"source_code": "s=gets.chomp\ns.gsub!('{','').gsub!('}','')\narr = s.split(',').map(&:strip)\nco = {}\narr.each do |a|\n if co[a].nil?\n co[a] = 1\n else\n co[a] +=1\n end\nend\n\nputs co.keys.length"}, {"source_code": "a=gets.chomp\nif a.length==2\n\tputs \"0\"\nelsif a.length==3\n\tputs \"1\"\nelse\n\tputs a[1..(a.length-2)].split(\",\").map{|s| s.lstrip.rstrip}.uniq.length\nend"}, {"source_code": "hash = Hash.new(0)\ngets.chomp.slice(1...-1).split(/,\\s*/).each {|e| hash[e] +=1}\nputs hash.length"}, {"source_code": "p gets.chomp.slice(1...-1).split(/,\\s*/).uniq.length"}, {"source_code": "puts gets.chomp.gsub(/[{}]/,'').split(', ').uniq.length"}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}, {"source_code": "p gets.scan(/\\w/).uniq.size"}, {"source_code": "#!/usr/bin/ruby\np gets.chomp[1...-1].split(', ').uniq.size"}, {"source_code": "a=gets.chomp.split(\"\")\na.delete(\"{\")\na.delete(\"}\")\na.delete(\" \")\na.delete(\",\")\na.uniq!\nputs \"#{a.length}\"\n"}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}, {"source_code": "line = gets.chomp\nletters = line[1..(line.length - 2)].split(/, /)\nletters.uniq!\nputs letters.length\n"}, {"source_code": "puts gets.chomp.gsub(/({|,|})/,'').split.uniq.size\n"}, {"source_code": "a=gets.chomp.split(\"\")\na.delete(\"{\")\na.delete(\"}\")\na.delete(\" \")\na.delete(\",\")\na.uniq!\nputs \"#{a.length}\""}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}, {"source_code": "puts gets.split(/ |{|}|,/).uniq.count-2"}, {"source_code": "ar = gets.chomp.split(/[^[:lower:]]/).select{|x| x.length>0}\nhs = Hash.new 0\nar.each{|x| hs[x]+=1}\nputs hs.length"}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}, {"source_code": "#puts \"Enter the string\\n\"\ns = gets.chomp.to_s\nl = s.length\n#puts l\na = [l]\nj = 0\nfor i in 0...l-1 do\n if s[i].ord >= 97 && s[i].ord <= 122\n a[j] = s[i]\n j += 1\n #puts a[j-1] \n end\nend\n\n#puts j (size of array a)\nif j == 0\n puts 0\nelsif j == 1\n puts 1\nelse\n a = a.sort\n c = 0\n for k in 0..j do\n if a[k] != a[k+1]\n c += 1\n end\n end\n puts c\nend\n"}, {"source_code": "set = gets.chomp\nputs set.tr('{},','').split(' ').uniq.length"}, {"source_code": "require 'set'\nputs gets.chomp.gsub(/[{} ]/,\"\").split(\",\").to_set.count\n"}, {"source_code": "puts gets.chomp[1..-2].split(\", \").uniq.size\n"}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}, {"source_code": "puts gets.scan(/\\w/).uniq.size"}, {"source_code": "#!/usr/bin/env ruby\n\nrequire 'set'\n\ns = Set.new STDIN.gets.strip[1...-1].split(',').map(&:strip)\n\nputs s.size\n"}, {"source_code": "puts gets.chomp.chars[1..-2].join(\"\").split(\", \").uniq.size\n"}, {"source_code": "puts gets.chomp[1..-2].split(\", \").uniq.size\n"}, {"source_code": "puts gets.scan(/[a-z]/).uniq.size"}, {"source_code": "puts gets.scan(/[a-z]/).uniq.size\n"}, {"source_code": "a=gets.chomp.split(\"\")\na.delete(\"{\")\na.delete(\"}\")\na.delete(\" \")\na.delete(\",\")\na.uniq!\nputs \"#{a.length}\""}, {"source_code": "p gets.scan(/\\w/).uniq.size"}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}, {"source_code": "puts gets.gsub(/[^a-z]/, '').chars.sort.uniq.size\n"}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}, {"source_code": "require 'set'\n\nset = Set.new\ns = gets.chomp\ns.gsub!(/{|}| /, \"\")\n\ns.split(\",\").each { |c| set << c }\nputs set.length"}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}, {"source_code": "s = gets.chomp\nl = s.length\nc={}\nfor i in 0...l\nif s[i]==\"{\" || s[i]==\"}\"||s[i]==\",\"||s[i]==\" \" then next\nelsif c[\"#{s[i]}\"]==nil then\n c[\"#{s[i]}\"]=1\nend\nend\nputs c.length"}, {"source_code": "p gets.scan(/\\w/).uniq.size"}, {"source_code": "array = gets.delete('{}').chomp.split(\", \")\nputs array.uniq.count\n"}, {"source_code": "s = gets.chomp\ns = s.delete! \"{, } \" \ns = s.chars.uniq\nputs s.size"}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}, {"source_code": "numbers = gets.strip[1..-2].split(', ')\n\nset = Hash.new(0)\nnumbers.each do |num|\n set[num] += 1\nend\n\nputs set.size"}, {"source_code": "input = gets.chomp\nletter = input.gsub(/[^a-zA-Z ]/,\" \").split(\" \")\ncounter = {}\nfor i in 0...letter.length\n\tcounter[letter[i]] = 1\nend\nsum = 0\ncounter.each do |key, value|\n\tsum += value\nend\nputs sum\n"}, {"source_code": "puts gets.chomp[1..-2].split(\", \").uniq.length "}, {"source_code": "puts gets.chomp[1..-2].split(\", \").uniq.length"}, {"source_code": "puts gets.chomp[1..-2].split(', ').uniq.count\n"}, {"source_code": "letters = gets\nletters = letters.slice(1, letters.length - 3).split(', ')\n\nputs letters.uniq.length\n"}, {"source_code": "s = $stdin.readline\n\nb = s.scan(/[a-z]/)\n\nputs b.uniq.count"}, {"source_code": "p gets.scan(/\\w/).uniq.size"}, {"source_code": "def run\n h = Hash.new(0)\n $stdin.gets.gsub(/[{}]/, \"\").split(\",\").map(&:strip).each do |c|\n h[c] += 1 if c != \"\"\n end\n puts h.size\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "s = gets.chomp()\nc = 0\n('a'..'z').each do |char|\n if s.include? char \n c += 1\n end\nend\nputs(c)"}, {"source_code": "puts gets.chomp.gsub(/{|}/, '').split(', ').uniq.count\n"}, {"source_code": "p gets.scan(/\\w/).uniq.size\n"}], "negative_code": [{"source_code": "gets.chomp.gsub(/{|}/, '').split(', ').uniq.count"}, {"source_code": "require 'set'\ns=gets\ns=s.slice(1,s.size-2).split(\", \")\nputs Set.new(s).count\n"}], "src_uid": "1cbbffd1941ed83b5f04e1ee33c77f61"} {"source_code": "n,m,k,l=gets.split.map &:to_i\nx=(k+l+m-1)/m\np m*x>n ? -1 : x", "positive_code": [{"source_code": "N,M,K,L=gets.split.map &:to_i\nif M>N\n puts -1\n exit\nend\nd=N/M\nx=N-K\nif d*M-K total_collectable_coins\n\ttrue\nend\n\ndef condition_minimum_amount_of_new_coins( minimum_new_coins, total_coins_gifted, total_collectable_coins, already_present_coins )\n\t#possible_new_coins = total_collectable_coins - already_present_coins\n\ttotal_coins_gifted >= minimum_new_coins + already_present_coins\nend\n\ncoins_per_friend = ( K + L ) / M\nuntil condition_minimum_amount_of_new_coins( L, M * coins_per_friend, N, K )\n #condition_all_coins_different( M, coins_per_friend, N ) and \n\tcoins_per_friend += 1\nend\n \t\n# puts coins_per_friend\n\nif condition_all_coins_different( M, coins_per_friend, N)\n\tputs coins_per_friend\nelse\n\tputs -1\nend"}], "negative_code": [{"source_code": "n,m,k,l=gets.split.map &:to_i\nx=(k+l)/m\np m*x>n ? x : -1"}, {"source_code": "n,m,k,l=gets.split.map &:to_i\nx=(k+l)/m\np m*x>n ? -1 : x"}, {"source_code": "n,m,k,l=gets.split.map &:to_i\nx=(k+l+m-1)/m\np m*x>n ? x : -1"}], "src_uid": "886029b385c099b3050b7bc6978e433b"} {"source_code": "n = gets.chomp.to_i\ncolors = gets.chomp.split('')\n\nif n == 1\n\tputs 0\n\texit\nend\n\ndef getA colors, init\ncurrent = init\n\nbWrong = []\nrWrong = []\n\nfor i in (0...colors.length)\n\tif current == colors[i]\n\t\tbWrong << i if current == 'b'\n\t\trWrong << i if current == 'r'\n\n\t\tcurrent = 'r' if colors[i] == 'b'\n\t\tcurrent = 'b' if colors[i] == 'r'\n\telse\n\t\tcurrent = colors[i]\n\tend\nend\n\nswap = 0\nchange = 0\n\nbWrongSize = bWrong.length\nrWrongSize = rWrong.length\n\nuntil bWrongSize == 0 || rWrongSize == 0\n\tbWrongSize -= 1\n\trWrongSize -= 1\n\tswap += 1\nend\n\nchange = bWrongSize + rWrongSize\n\nreturn swap + change\nend\n\nforward = getA colors, 'r'\nbackward = getA colors, 'b'\n\n#puts forward\n#puts backward\n\nputs [forward, backward].min", "positive_code": [{"source_code": "def func(s, k)\n r=b=i=0\n s.chars{|c|\n r+=1 if c==?r and i%2==k\n b+=1 if c==?b and i%2!=k\n i+=1\n }\n x, y=[r, b].minmax\n y-x+x\nend\n\ngets\ns=gets.chomp\nputs [func(s, 0), func(s, 1)].min\n"}, {"source_code": "def func(n, s, k)\n r=b=i=0\n s.chars{|c|\n r+=1 if c==?r and i%2==k\n b+=1 if c==?b and i%2!=k\n i+=1\n }\n x, y=[r, b].minmax\n y-x+x\nend\n\nn=gets.to_i\ns=gets.chomp\nputs [func(n, s, 0), func(n, s, 1)].min\n"}, {"source_code": "#!/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby\n\nclass Task2\n attr_accessor :cockroach, :n, :result\n\n def initialize()\n @n=0\n @cockroach = []\n @result = 0\n end\n\n def getData()\n ln=$stdin.readline\n @n=ln.chomp.to_i\n tmp=$stdin.readline\n @cockroach = tmp.chomp\n end\n\n def getFileData()\n file = File.new(\"test.txt\",\"r\")\n ln=file.readline\n @n=ln.chomp.to_i\n tmp=file.readline\n @cockroach = tmp.chomp\n end\n\n def getResult()\n @result = getSubResult()\n if @n%2 == 1\n @cockroach=@cockroach.reverse\n result = getSubResult()\n @result=[@result,result].min\n end\n end\n\n def getSubResult()\n result=0\n cnt={rr:0,rb:0,br:0,bb:0}\n (0..@n/2-1).each {|x| cnt[@cockroach[x*2..x*2+1].to_sym]+=1} if @n>1\n # print cnt\n # puts\n # exit(0)\n result = (cnt[:br]>cnt[:rb]) ? cnt[:rb]: cnt[:br]\n lst = (cnt[:br]>cnt[:rb]) ? 'r': 'b'\n result+=[cnt[:rr],cnt[:bb]].min\n delta = [cnt[:rr],cnt[:bb]].max-[cnt[:rr],cnt[:bb]].min\n result+=delta\n result+= (@n%2==1 && @cockroach[@n-1]==lst)?1:0 if cnt[:br]+cnt[:rb]>0\n return result\n end\n\n def printResult()\n puts @result\n end\n\n def run()\n if ARGV[0] == 'DEBUG'\n getFileData\n else\n getData\n end\n # print @n\n # print @cockroach\n # puts\n getResult\n printResult\n end\n\nend\nif __FILE__ == $0\n pc = Task2.new\n pc.run\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nif n % 2 == 0\n s1 = \"br\" * (n / 2)\n s2 = \"rb\" * (n / 2)\nelse\n s1 = \"br\" * (n / 2) + \"b\"\n s2 = \"rb\" * (n / 2) + \"r\"\nend\nb1 = 0\nr1 = 0\nb2 = 0\nr2 = 0\nn.times{|i|\n if s[i] != s1[i]\n if s[i] == \"b\"\n b1 += 1\n else\n r1 += 1\n end\n end\n if s[i] != s2[i]\n if s[i] == \"b\"\n b2 += 1\n else\n r2 += 1\n end\n end\n }\nputs [[b1, r1].max, [b2, r2].max].min"}, {"source_code": "#!/usr/bin/ruby\ngets\ns=[0]*4\nx=0\ngets.chomp.chars{|c|\n\tf=c!='r' ? 2 : 0\n\ts[f|x]+=1\n\tx^=1\n}\np [[s[0],s[3]].max,[s[1],s[2]].max].min"}, {"source_code": "\ndef min(a, b)\n (a <= b) ? a : b\nend\n\ndef max(a, b)\n (a >= b) ? a : b\nend\n\nc = gets.chop.to_i\nword = gets.chop\n\nfb_b = 0\nfb_r = 0\nfr_b = 0\nfr_r = 0\n\ni = 0;\nword.chars.each_with_index do |x, i|\n if i.even?\n if x == 'b'\n fr_b += 1\n elsif x == 'r'\n fb_r += 1\n end \n else\n if x == 'b'\n fb_b += 1 \n elsif x == 'r'\n fr_r += 1 \n end\n end\nend\n\nputs min(max(fb_b, fb_r), max(fr_b, fr_r))\n\n\n"}, {"source_code": "gets; s = gets.chomp\ndef min1(s,k)\n r = b = i = 0\n s.chars{ |c|\n r +=1 if c==?r and i%2 == k\n b +=1 if c==?b and i%2 != k\n i += 1\n }\n x,y = [r,b].minmax\n y-x+x\nend\nputs [min1(s,0), min1(s,1)].min\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\ngets\ns=[0]*4\nx=0\ngets.chomp.chars{|c|\n\tf=c!='r' ? 2 : 0\n\ts[f|x]+=1\n\tx^=1\n}\np [[s[0],s[3]].min,[s[1],s[2]].min].max"}, {"source_code": "\ndef min(a, b)\n (a <= b) ? a : b\nend\n\ndef max(a,b)\n (a >= b) ? a : b\nend\n\nc = gets.chop.to_i\nword = gets.chop\n\nbfb = 0\nbfr = 0\nrfr = 0\nrfb = 0\n\ni = 0;\nwhile i < word.size\n if i.even?\n if word[i] == 'b'\n rfr += 1\n elsif word[i] == 'r'\n bfr += 1\n end \n else\n if word[i] == 'b'\n bfr += 1 \n elsif word[i] == 'r'\n rfb += 1 \n end\n end\n i += 1\nend\n\nputs min(max(bfb, bfr), max(rfr, rfb))\n\n\n"}, {"source_code": "\nc = gets.chop.to_i\nword = gets.chop\n\ncnt = { 'r' => 0, 'b' => 0 }\n\n\ni = 0;\nwhile i < word.size - 1\n if word[i] == word[i+1]\n #puts i\n if i + 2 < word.size && word[i+1] != word[i]\n word[i+1], word[i+2] = word[i+2], word[i+1]\n elsif i + 2 < word.size \n cnt[word[i]] += 1\n else\n cnt[word[i]] += 1\n end\n i += 2\n else\n i += 1\n end\nend\n\nputs (cnt['r'] > cnt['b']) ? cnt['r'] : cnt['b']\n\n\n"}, {"source_code": "\nc = gets.chop.to_i\nword = gets.chop\n\ncnt = { 'r' => 0, 'b' => 0 }\n\nk = 0\n\ni = 0;\nwhile i < word.size - 1\n if word[i] == word[i+1]\n #puts i\n if i + 2 < word.size && word[i+1] != word[i+2]\n word[i+1], word[i+2] = word[i+2], word[i+1]\n k += 1\n i += 2\n elsif i + 2 < word.size && word[i+1] == word[i+2] \n cnt[word[i]] += 1\n i += 3\n else\n cnt[word[i]] += 1\n i += 2\n end\n else\n i += 1\n end\nend\n\nputs ((cnt['r'] > cnt['b']) ? cnt['r'] : cnt['b']) + k\n\n\n"}, {"source_code": "\nc = gets.chop.to_i\nword = gets.chop\n\ncnt = { 'r' => 0, 'b' => 0 }\n\nk = 0\n\ni = 0;\nwhile i < word.size - 1\n if word[i] == word[i+1]\n #puts i\n if i + 2 < word.size && word[i+1] != word[i+2]\n word[i+1], word[i+2] = word[i+2], word[i+1]\n k += 1\n i += 2\n elsif i + 2 < word.size && word[i+1] == word[i+2] \n cnt[word[i]] += 1\n i += 2\n else\n cnt[word[i]] += 1\n i += 2\n end\n else\n i += 1\n end\nend\n\nputs ((cnt['r'] > cnt['b']) ? cnt['r'] : cnt['b']) + k\n\n\n"}, {"source_code": "\ndef min(a, b)\n (a <= b) ? a : b\nend\n\ndef max(a,b)\n (a >= b) ? a : b\nend\n\nc = gets.chop.to_i\nword = gets.chop\n\nbfb = 0\nbfr = 0\nrfr = 0\nrfb = 0\n\ni = 0;\nwhile i < word.size\n if i % 2 == 0\n if word[i] == 'b'\n rfr += 1\n elsif word[i] == 'r'\n bfr += 1\n end \n else\n if word[i] == 'b'\n bfr += 1 \n elsif word[i] == 'r'\n rfb += 1 \n end\n end\n i += 1\nend\n\nputs min(max(bfb, bfr), max(rfr, rfb))\n\n\n"}, {"source_code": "\nc = gets.chop.to_i\nword = gets.chop\n\ncnt = { 'r' => 0, 'b' => 0 }\n\nk = 0\n\ni = 0;\nwhile i < word.size - 1\n if word[i] == word[i+1]\n #puts i\n if i + 2 < word.size && word[i+1] != word[i+2]\n word[i+1], word[i+2] = word[i+2], word[i+1]\n k += 1\n elsif i + 2 < word.size \n cnt[word[i]] += 1\n else\n cnt[word[i]] += 1\n end\n i += 2\n else\n i += 1\n end\nend\n\nputs ((cnt['r'] > cnt['b']) ? cnt['r'] : cnt['b']) + k\n\n\n"}, {"source_code": "\nc = gets.chop.to_i\nword = gets.chop\n\ncnt = { 'r' => 0, 'b' => 0 }\n\nk = 0\n\ni = 0;\nwhile i < word.size - 1\n if word[i] == word[i+1]\n #puts i\n if i + 2 < word.size && word[i+1] != word[i+2]\n word[i+1], word[i+2] = word[i+2], word[i+1]\n k += 1\n i += 2\n elsif i + 2 < word.size && word[i+1] == word[i+2] \n cnt[word[i]] += 1\n i += 3\n else\n cnt[word[i]] += 1\n i += 2\n end\n else\n i += 2\n end\nend\n\nputs ((cnt['r'] > cnt['b']) ? cnt['r'] : cnt['b']) + k\n\n\n"}, {"source_code": "def func(n, s, a)\n res=0\n i=0\n while ii\n j-=1\n break if c!=s[j] and !f[j]\n end\n f[j]=true if j>i\n res+=1\n end\n }\n res\nend\n\nn=gets.to_i\ns=gets.chomp.chars\nbrbr=\"br\"*n\nputs [func(n, s, brbr), func(n, s, brbr.reverse)].min\n"}, {"source_code": "n = gets.chomp.to_i\ncolors = gets.chomp.split('')\n\nif n == 1\n\tputs 0\n\texit\nend\n\ncurrent = colors[0]\n\nbWrong = []\nrWrong = []\n\nfor i in (1...colors.length)\n\tif current == colors[i]\n\t\tbWrong << i if current == 'b'\n\t\trWrong << i if current == 'r'\n\n\t\tcurrent = 'r' if colors[i] == 'b'\n\t\tcurrent = 'b' if colors[i] == 'r'\n\telse\n\t\tcurrent = colors[i]\n\tend\nend\n\nswap = 0\nchange = 0\n\nbWrongSize = bWrong.length\nrWrongSize = rWrong.length\n\nuntil bWrongSize == 0 || rWrongSize == 0\n\tbWrongSize -= 1\n\trWrongSize -= 1\n\tswap += 1\nend\n\nchange = bWrongSize + rWrongSize\n\nforward = swap + change\n\ncurrent = colors[colors.length - 1]\nbWrong = []\nrWrong = []\n\n(colors.length - 2).downto(0).each do |i|\n\tif current == colors[i]\n\t\tbWrong << i if current == 'b'\n\t\trWrong << i if current == 'r'\n\n\t\tcurrent = 'r' if colors[i] == 'b'\n\t\tcurrent = 'b' if colors[i] == 'r'\n\telse\n\t\tcurrent = colors[i]\n\tend\nend\n\nswap = 0\nchange = 0\n\nbWrongSize = bWrong.length\nrWrongSize = rWrong.length\n\nuntil bWrongSize == 0 || rWrongSize == 0\n\tbWrongSize -= 1\n\trWrongSize -= 1\n\tswap += 1\nend\n\nchange = bWrongSize + rWrongSize\nbackward = swap + change\n\nputs [forward, backward].min"}, {"source_code": "n = gets.chomp.to_i\ncolors = gets.chomp.split('')\n\nif n == 1\n\tputs 0\n\texit\nend\n\ndef getA colors, init\ncurrent = init\n\nbWrong = []\nrWrong = []\n\nfor i in (1...colors.length)\n\tif current == colors[i]\n\t\tbWrong << i if current == 'b'\n\t\trWrong << i if current == 'r'\n\n\t\tcurrent = 'r' if colors[i] == 'b'\n\t\tcurrent = 'b' if colors[i] == 'r'\n\telse\n\t\tcurrent = colors[i]\n\tend\nend\n\nswap = 0\nchange = 0\n\nbWrongSize = bWrong.length\nrWrongSize = rWrong.length\n\nuntil bWrongSize == 0 || rWrongSize == 0\n\tbWrongSize -= 1\n\trWrongSize -= 1\n\tswap += 1\nend\n\nchange = bWrongSize + rWrongSize\n\nreturn swap + change\nend\n\nforward = getA colors, 'r'\nbackward = getA colors, 'b'\n\nputs [forward, backward].min"}, {"source_code": "n = gets.chomp.to_i\ncolors = gets.chomp.split('')\n\ncurrent = colors[0]\n\nbWrong = []\nrWrong = []\n\nfor i in (1...colors.length)\n\tif current == colors[i]\n\t\tbWrong << i if current == 'b'\n\t\trWrong << i if current == 'r'\n\n\t\tcurrent = 'r' if colors[i] == 'b'\n\t\tcurrent = 'b' if colors[i] == 'r'\n\telse\n\t\tcurrent = colors[i]\n\tend\nend\n\nswap = 0\nchange = 0\n\nbWrongSize = bWrong.length\nrWrongSize = rWrong.length\n\nuntil bWrongSize == 0 || rWrongSize == 0\n\tbWrongSize -= 1\n\trWrongSize -= 1\n\tswap += 1\nend\n\nchange = bWrongSize + rWrongSize\n\nputs swap + change"}], "src_uid": "3adc75a180d89077aa90bbe3d8546e4d"} {"source_code": "s = gets.chomp!\ns.sub!('1', '')\ns.sub!('6', '')\ns.sub!('8', '')\ns.sub!('9', '')\nz = s.size\ns.sub!(/0+/, '')\nz-=s.size\n\nx = s.each_char.inject(0) { |m, e| (m * 10 + e.to_i) % 7 }\n[1, 6, 8, 9].permutation do |p|\n y = (p * '').to_i\n if (10000 * x + y) % 7 == 0\n print s, y, '0'*z\n break\n end\nend", "positive_code": [{"source_code": "s=gets.chomp!\ns.sub!('1','')\ns.sub!('6','')\ns.sub!('8','')\ns.sub!('9','')\nz=s.size\ns.sub!(/^0+/,'')\nz-=s.size\nx=s.each_char.inject(0){|m,c|(m*10+c.to_i)%7}\n[1,6,8,9].permutation do |p|\n y=(p*'').to_i\n if (10000*x+y)%7==0\n print s,y,'0'*z\n break\n end\nend\n\n"}, {"source_code": "require 'scanf'\nSTDIN.read.split(\"\\n\").each do |line|\n\tnum = line\n\tzeros_count = num.count('0')\n\tnum = num.tr(\"0\", '')\n\tnum = num.sub(\"1\", '')\n\tnum = num.sub(\"6\", '')\n\tnum = num.sub(\"8\", '')\n\tnum = num.sub(\"9\", '')\n\tnum = \"\" if num == \"0\"\n\treminder = 0\n\tnum.split('').each do |digit|\n\t\treminder *= 10\n\t\treminder += digit.to_i\n\t\treminder %= 7\n\tend\n\treminder = reminder * 10000 % 7\n\tpermutation = case reminder\n\t\twhen 0\n\t\t\t\"8169\"\n\t\twhen 1\n\t\t\t\"8196\"\n\t\twhen 2\n\t\t\t\"9861\"\n\t\twhen 3\n\t\t\t\"8691\"\n\t\twhen 4\n\t\t\t\"6891\"\n\t\twhen 5\n\t\t\t\"1689\"\n\t\twhen 6\n\t\t\t\"6189\"\n\t\tend\n\tputs num + permutation + \"0\" * zeros_count\nend\n"}], "negative_code": [{"source_code": "s=gets.chomp!\ns.sub!('1','')\ns.sub!('6','')\ns.sub!('8','')\ns.sub!('9','')\nz=s.size\ns.sub!(/^0+/,'')\nz-=s.size\nx=s.each_char.inject(0){|m,c|(m*10+c.to_i)%7}\n[1,6,8,9].permutation do |p|\n y=(p*'').to_i\n if (x+y)%7==0\n print s,y,'0'*z\n break\n end\nend\n\n"}, {"source_code": "require 'scanf'\nSTDIN.read.split(\"\\n\").each do |line|\n\tnum = line\n\tzeros_count = num.count('0')\n\tnum = num.tr(\"0\", '')\n\tnum = num.sub(\"1\", '')\n\tnum = num.sub(\"6\", '')\n\tnum = num.sub(\"8\", '')\n\tnum = num.sub(\"9\", '')\n\tnum = \"\" if num == \"0\"\n\tnum = num + \"0000\"\n\treminder = 0\n\tnum.split('').each do |digit|\n\t\treminder *= 10\n\t\treminder += digit.to_i\n\t\treminder %= 7\n\tend\n\tpermutation = case reminder\n\t\twhen 0\n\t\t\t\"8169\"\n\t\twhen 1\n\t\t\t\"8196\"\n\t\twhen 2\n\t\t\t\"9861\"\n\t\twhen 3\n\t\t\t\"8691\"\n\t\twhen 4\n\t\t\t\"6891\"\n\t\twhen 5\n\t\t\t\"1689\"\n\t\twhen 6\n\t\t\t\"6189\"\n\t\tend\n\tputs num + permutation + \"0\" * zeros_count\nend\n"}], "src_uid": "3b10e984d7ca6d4071fd4e743394bb60"} {"source_code": "t = gets.to_i\nans = []\nt.times do |i|\n n = gets.to_i\n a = gets.chomp.split(\" \").map(&:to_i)\n hash = Hash.new(0)\n a.each do |x|\n hash[x] += 1\n end\n max = hash.each_value.max\n num = hash.each_value.count(max)\n if num == 1\n ans << ((n-max) / (max-1))\n elsif max == 2\n ans << n - num - 1\n else\n dis = n - num - 1\n rest = (dis - (max - 2))\n ans << rest / (max-1)\n end\nend\nans.each do |x|\n puts x\nend", "positive_code": [{"source_code": "\ntc=gets.to_i\n\nans=[]\n\ntc.times do|i|\n n=gets.to_i\n a=gets.chomp.split(\" \").map(&:to_i)\n \n h=Hash.new(0)\n\n a.each do |x|\n h[x]+=1\n end\n \n mx=h.each_value.max\n cnt=h.each_value.count(mx)\n\n if cnt==1\n ans<< ((n-mx)/(mx-1))\n elsif mx==2\n ans<< n-cnt-1\n \n else\n dis=n-cnt-1\n rest=dis-(mx-2)\n ans<< rest/(mx-1)\n end\nend\n\n\nans.each do|x|\n puts x\nend\n"}], "negative_code": [], "src_uid": "9d480b3979a7c9789fd8247120f31f03"} {"source_code": "Integer(gets.chomp).times{\r\n n = Integer(gets.chomp)\r\n if(n%2 == 1)\r\n puts \"NO\"\r\n next\r\n else\r\n sq4 = Float(1)\r\n isq4 = 0\r\n if(n%4 == 0)\r\n sq4 = Math.sqrt(n/4)\r\n isq4 = Integer(sq4)\r\n end\r\n sq2 = Math.sqrt(n/2)\r\n isq2 = Integer(sq2)\r\n \r\n puts (sq2 == isq2 || sq4 == isq4) ? \"YES\" : \"NO\"\r\n end\r\n}", "positive_code": [{"source_code": "def solve(n)\n while true\n return true if n == 2\n return false if n % 2 == 1\n n >>= 1\n sqrtn = Integer.sqrt(n)\n return true if sqrtn * sqrtn == n\n end\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n printf(\"%s\\n\", solve(n) ? \"YES\" : \"NO\")\nend\n"}], "negative_code": [{"source_code": "def solve(n)\n return true if n == 2\n while true\n return false if n % 2 == 1\n sqrtn = Integer.sqrt(n)\n return true if sqrtn * sqrtn == n\n n >>= 1\n end\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n printf(\"%s\\n\", solve(n) ? \"YES\" : \"NO\")\nend\n"}, {"source_code": "def solve(n)\n while true\n return true if n == 2\n return false if n % 2 == 1\n sqrtn = Integer.sqrt(n)\n return true if sqrtn * sqrtn == n\n n >>= 1\n end\nend\n\nt = gets.to_s.to_i\n1.upto(t) do |casenum|\n n = gets.to_s.to_i\n printf(\"%s\\n\", solve(n) ? \"YES\" : \"NO\")\nend\n"}], "src_uid": "6ae754639d96790c890f9d1ab259332a"} {"source_code": "def bnot(a)\n a == '0' ? '1' : '0'\nend\n\nn, p = gets.split.map(&:to_i)\ns = gets.chomp\nfuck = false\nn.times do |i|\n if i < n - p\n if s[i] == '.' and s[i+p] == '.'\n s[i] = '0'\n s[i+p] = '1'\n fuck = true\n elsif s[i] == '.'\n s[i] = bnot s[i+p]\n fuck = true\n elsif s[i+p] == '.'\n s[i+p] = bnot s[i]\n fuck = true\n elsif s[i] != s[i+p]\n fuck = true\n end\n elsif s[i] == '.'\n s[i] = '0'\n end\nend\n\nif fuck\n puts s\nelse\n puts :No\nend\n", "positive_code": [{"source_code": "# https://codeforces.com/problemset/problem/989/B\ndef check_possible(records, p)\n len = records.size\n return 'No' if len == 1\n\n 0.upto(len - p - 1) do |i|\n end_idx = i + p\n\n if records[i] == '.' || records[end_idx] == '.'\n s_v, e_v = get_solution(records, i, end_idx)\n ret = records.dup\n ret[i] = s_v\n ret[end_idx] = e_v\n replace(ret)\n return ret\n end\n\n if records[i] != records[end_idx]\n replace(records)\n return records\n end\n end\n\n 'No'\nend\n\ndef replace(records)\n 0.upto(records.size - 1) do |i|\n records[i] = '0' if records[i] == '.'\n end\nend\n\ndef get_solution(records, start_idx, end_idx)\n if records[start_idx] == '.' && records[end_idx] == '.'\n return ['0', '1']\n end\n\n if records[start_idx] == '.'\n start = records[end_idx] == '0' ? '1' : '0'\n return [start, records[end_idx]]\n end\n\n [records[start_idx], records[start_idx] == '0' ? '1' : '0']\nend\n\nn, p = gets.split.map(&:to_i)\nrecords = gets.chomp\n\nputs check_possible(records, p)"}], "negative_code": [], "src_uid": "61a067dc6b8e04bfc661b7fa9ecb4eda"} {"source_code": "testcases = Integer(gets.chomp)\r\nresultados = []\r\n\r\nfor i in 0..testcases-1\r\n n = Integer(gets.chomp)\r\n arreglo = gets.chomp\r\n bigram = arreglo.split(\" \")\r\n longitudTotal = bigram.length * 2\r\n if longitudTotal >= n\r\n letrasAQuitar = longitudTotal - n\r\n for j in 0..bigram.length-2\r\n if letrasAQuitar == 0\r\n break\r\n end\r\n bigram1 = bigram[j] \r\n bigram2 = bigram[j+1]\r\n if bigram1.length == 1\r\n if bigram1[0] == bigram2[0]\r\n bigram[j+1] = bigram2[1]\r\n letrasAQuitar -= 1\r\n end \r\n else\r\n if bigram1[1] == bigram2[0]\r\n bigram[j+1] = bigram2[1]\r\n letrasAQuitar -= 1\r\n end \r\n end\r\n end\r\n else\r\n letrasAAgregar = n-longitudTotal\r\n for j in 1..letrasAAgregar\r\n bigram[bigram.length-1] += \"a\" \r\n end\r\n end\r\n string = \"\"\r\n for j in 0..bigram.length-1\r\n string += bigram[j]\r\n end\r\n resultados.push(string)\r\nend\r\nputs resultados", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n s = ''\n\n gets.strip.split.each do |big|\n a, b = big.chars\n\n if s.empty?\n s = big\n next\n end\n\n if s[-1] == a\n s += b\n next\n end\n\n s += big\n end\n\n if s.size < n\n s += 'b'\n end\n\n puts s\nend\n"}, {"source_code": "t = gets.to_i\r\nans = []\r\nt.times do\r\n n = gets.to_i\r\n s = gets.split(\" \")\r\n str = [s[0][0],s[0][1]]\r\n s[1..].each do |v|\r\n if str[-1] == v[0]\r\n str << v[1]\r\n else\r\n str << v[0]\r\n str << v[1]\r\n end\r\n end\r\n if str.size != n\r\n str << \"a\"\r\n end\r\n ans << str\r\nend\r\nans.each do |v|\r\n puts v.join\r\nend"}], "negative_code": [], "src_uid": "565056bfe716ee89230270bdc14c9051"} {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2 maximumTries || seq.count(stand) != seq.length\n # puts flipIdx.length\n # puts flipIdx.join ' '\n # p seq\n puts -1\nelse\n puts flipIdx.length\n \n if flipIdx.length > 0\n puts flipIdx.join ' '\n end\nend"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nseq = gets.split(//)[0...-1].map { |c| c == 'B' ? 0 : 1 }\n\nif seq.count(0) == seq.length || seq.count(1) == seq.length\n puts 0\nelse\n i = 0\n flipIdx = []\n stand = seq[0] ^ 1 # first flipping always occurs\n maximumTries = seq.length * 3\n while i < seq.length-1 && flipIdx.length <= maximumTries\n if seq[i] != stand\n seq[i] ^= 1\n seq[i+1] ^= 1\n flipIdx << i+1 # 1-based index\n end\n\n if seq[i] == seq[i+1]\n i += 2\n else\n i += 1\n end\n end\n\n if flipIdx.length > maximumTries || seq.count(stand) != seq.length\n puts -1\n else\n puts flipIdx.length\n puts flipIdx.join ' '\n end\nend"}], "src_uid": "3336662e6362693b8ac9455d4c2fe158"} {"source_code": "x = gets.chomp.split(' ')\nn = x[0].to_i\nr = x[1].to_i\narr = gets.chomp.split(' ')\nans = []\nfor i in (0...n)\n ans.push(r)\n arr[i] = arr[i].to_i\n for j in (0...i)\n if (arr[i] - arr[j]).abs <= 2 * r\n x = ans[j] + (4 * r * r - (arr[i] - arr[j]) ** 2) ** 0.5\n if(x > ans[i])\n ans[i] = x\n end\n end\n end\n printf(\"%.12f \", ans[i])\nend", "positive_code": [{"source_code": "def puta ary\n \n n = ary.size\n # p n\n n.times do |i|\n print ary[i]\n print i == n - 1 ? \"\\n\" : \" \"\n end\nend\n\nn, r = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i)\n\ny = Array.new(n, r)\n\nn.times do |i|\n \n tmp = r\n (0...i).each do |j|\n \n dx = ( x[i] - x[j] ).abs\n next if dx > 2 * r \n tmp = y[j] + ( (2*r)**2 - dx**2 ) ** 0.5\n \n y[i] = tmp if y[i] < tmp\n # p [j, tmp] if i == 25\n end\nend\n\nputa y"}], "negative_code": [{"source_code": "def puta ary\n \n n = ary.size\n n.times do |i|\n print ary[i]\n print i == n - 1 ? \"\\n\" : \" \"\n end\nend\n\nn, r = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i)\n\ny = Array.new(n, r)\n\nn.times do |i|\n \n tmp = r\n (0...i).each do |j|\n \n dx = ( x[i] - x[j] ).abs\n next if dx > 2 * r \n tmp = y[j] + ( (2*r)**2 - dx**2 ) ** 0.5\n \n end\n \n y[i] = [ y[i], tmp ].max\n \nend\n\nputa y"}], "src_uid": "3cd019d1016cb3b872ea956c312889eb"} {"source_code": "_ = [gets,gets].map!{|i|i=i.rjust(1e5+1,'0').reverse.gsub(/(11(01)*0)/){'0'*($1.length-1)+'1'}.gsub(/((11)+)0/){'0'+'01'*($1.length/2)}.reverse}\nputs %w{= > <}[_[0]<=>_[1]]\n", "positive_code": [{"source_code": "_ = [gets, gets]\nmax = 0\n_.map!{|a|a.chomp}.each{|a|a.length > max and max = a.length}.map!{|a| \"0\" * (1+max-a.length) + a}.map!{|a|a.reverse}.map!{|a| a.gsub(/(11(01)*0)/){\"0\" * ($1.length-1) + \"1\"}}.map!{|a| a.gsub(/((11)+)0/){\"0\" + \"01\" * ($1.length/2)}}.map!{|a|a.reverse}\nputs [\"=\",\">\",\"<\"][_[0]<=>_[1]]"}, {"source_code": "_ = [gets,gets].map!{|i|i=i.rjust(1e5+1,'0').reverse.gsub(/(11(01)*0)/){'0'*($1.length-1)+'1'}.gsub(/((11)+)0/){'0'+'01'*($1.length/2)}.reverse}\nputs %w{= > <}[_[0]<=>_[1]]\n"}, {"source_code": "_ = [gets,gets].map!{|i|i=i.rjust(1e5+1,'0').reverse.gsub(/(11(01)*0)/){'0'*($1.length-1)+'1'}.gsub(/((11)+)0/){'0'+'01'*($1.length/2)}.reverse}\nputs %w{= > <}[_[0]<=>_[1]]\n"}, {"source_code": "_ = [gets,gets].map!{|i|i=i.rjust(1e5+1,'0').reverse.gsub(/(11(01)*0)/){'0'*($1.length-1)+'1'}.gsub(/((11)+)0/){'0'+'01'*($1.length/2)}.reverse}\nputs %w{= > <}[_[0]<=>_[1]]"}, {"source_code": "_ = [gets,gets].map!{|i|i=i.rjust(1e5+1,'0').reverse.gsub(/(11(01)*0)/){'0'*($1.length-1)+'1'}.gsub(/((11)+)0/){'0'+'01'*($1.length/2)}.reverse}\nputs %w{= > <}[_[0]<=>_[1]]\n"}, {"source_code": "_ = [gets,gets].map!{|i|i=i.rjust(1e5+1,'0').reverse.gsub(/(11(01)*0)/){'0'*($1.length-1)+'1'}.gsub(/((11)+)0/){'0'+'01'*($1.length/2)}.reverse}\nputs %w{= > <}[_[0]<=>_[1]]\n"}, {"source_code": "_ = [gets,gets].map!{|i|i=i.rjust(1e5+1,'0').reverse.gsub(/(11(01)*0)/){'0'*($1.length-1)+'1'}.gsub(/((11)+)0/){'0'+'01'*($1.length/2)}.reverse}\nputs %w{= > <}[_[0]<=>_[1]]\n"}, {"source_code": "_ = [gets,gets].map!{|i|i=i.rjust(1e5+1,'0').reverse.gsub(/(11(01)*0)/){'0'*($1.length-1)+'1'}.gsub(/((11)+)0/){'0'+'01'*($1.length/2)}.reverse}\nputs %w{= > <}[_[0]<=>_[1]]\n"}, {"source_code": "_ = [gets,gets].map!{|i|i=i.rjust(1e5+1,'0').reverse.gsub(/(11(01)*0)/){'0'*($1.length-1)+'1'}.gsub(/((11)+)0/){'0'+'01'*($1.length/2)}.reverse}\nputs %w{= > <}[_[0]<=>_[1]]"}, {"source_code": "_ = [gets,gets].map!{|i|i=i.rjust(1e5+1,'0').reverse.gsub(/(11(01)*0)/){'0'*($1.length-1)+'1'}.gsub(/((11)+)0/){'0'+'01'*($1.length/2)}.reverse}\nputs %w{= > <}[_[0]<=>_[1]]\n"}], "negative_code": [], "src_uid": "7c0a288a2777894bdfd75cb9703346e9"} {"source_code": "n=gets.to_i\ns=gets.chomp\nh=Hash.new 0\ng=Hash.new n/4\ns.each_char{|c|h[c]+=1 if c!='?'}\nif n%4>0||h.any?{|k,v|g[k]-=v;v>n/4}\nputs '==='\nexit\nend\ns.each_char{|c|\nif c!='?'\nprint c\nelse\nx='ATGC'.chars.find{|x|g[x]>0}\ng[x]-=1\nprint x\nend\n}\nputs", "positive_code": [{"source_code": "n = gets.to_i\ns = gets.chomp.split('')\nif n % 4 != 0\n puts '==='\n exit\nend\nh = {}\n['A', 'G', 'C', 'T'].each { |x| h[x] = 0 }\ns.each do |x|\n h[x] += 1 if x != '?'\nend\nif h.values.any? { |m| m > n / 4 }\n puts '==='\n exit\nend\nss = s.map do |x|\n if x != '?'\n x\n else\n y = h.keys.find { |z| h[z] < n / 4 }\n h[y] += 1\n y\n end\nend\nputs ss.join('')\n"}, {"source_code": "n = gets\ns = gets\n\nif n.to_i() % 4 > 0\n puts(\"===\")\nelse\n a = s.count(\"A\")\n t = s.count(\"T\")\n c = s.count(\"C\")\n g = s.count(\"G\")\n\n if a.to_i() > n.to_i() / 4 || t.to_i() > n.to_i() / 4 || c.to_i() > n.to_i() / 4 || g.to_i() > n.to_i() / 4\n puts(\"===\")\n else\n while a < n.to_i() / 4\n s[s.index('?')] = 'A'\n a += 1\n end\n\n while t < n.to_i() / 4\n s[s.index('?')] = 'T'\n t += 1\n end\n\n while c < n.to_i() / 4\n s[s.index('?')] = 'C'\n c += 1\n end\n\n while g < n.to_i() / 4\n s[s.index('?')] = 'G'\n g += 1\n end\n\n puts(s)\n end\nend\n"}, {"source_code": "CODES = ['A', 'G', 'C', 'T']\n\ndef count(code)\n result = {'A'=> 0, 'G'=> 0, 'C'=> 0, 'T'=> 0, '?'=> 0}\n code.each_char{|c| result[c]+=1}\n return result\nend\n\ndef eval(code)\n max = code.length/4\n count(code).all? { |ch, cnt|\n ch == '?' || cnt <= max\n }\nend\n\ndef find(code)\n return nil if !eval(code)\n i = code.index('?')\n if i.nil?\n return code\n else\n for ch in CODES\n copy = code.dup\n copy[i] = ch\n result = find(copy)\n return result if result\n end\n return nil\n end\nend\n\ndef solve(n, code)\n return \"===\" if n < 4 || n%4 != 0\n find(code) || \"===\"\nend\n\nputs solve(STDIN.readline.to_i, STDIN.readline.chomp)\n"}, {"source_code": "a2 = gets.to_i\nstr = gets.to_s\ncount_a = count_g = count_c = count_t = 0\nfor i in 0..a2-1\n e = str[i]\n a = e.ord\n if (a==65)\n count_a = count_a + 1\n end\n if (a==67)\n count_c = count_c + 1\n end\n if (a==71)\n count_g = count_g + 1\n end\n if (a==84)\n count_t = count_t + 1\n end\nend\ncount_q = a2 - (count_a + count_c + count_g + count_t)\nno = a2 / 4\n\nif (a2%4 !=0)||(count_a > no) || (count_c > no) || (count_g > no) || (count_t > no) || ((count_a + count_c + count_g + count_t) > a2)\n print(\"===\")\n flag = 1\nelsif count_q == 0\n print str\n flag = 1\nend\n\nif (flag != 1)\n count_a = -count_a + no\n count_g = -count_g + no\n count_c = -count_c + no\n count_t = -count_t + no\n\n stack = Array.new\n for i in 1..count_a\n stack.push(\"A\")\n end\n for i in 1..count_g\n stack.push(\"G\")\n end\n for i in 1..count_c\n stack.push(\"C\")\n end\n for i in 1..count_t\n stack.push(\"T\")\n end\n k =0\n for i in 0..a2-1\n a= str[i].ord\n if (a==63)\n str[i]=stack[k]\n k = k+1\n end\n end\n puts str\nend\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp\n\nc=[0]*128\ns.bytes{|e|c[e]+=1}\n\nfor i in 0..n-1\n if s[i]==??\n \"AGCT\".bytes{|e|\n if c[e]0 or c.uniq!=[0,n/4]) ? \"===\" : s)\n"}, {"source_code": "class Genome\n attr_reader(:gen)\n def initialize(gen)\n @gen = gen.split(\"\")\n @memo = Hash[\n \"A\" => 0,\n \"C\" => 0,\n \"G\" => 0,\n \"T\" => 0\n ]\n end\n\n def length\n @length ||= gen.length\n end\n\n def gcount\n length / 4\n end\n\n def _gen_count\n gen.each do |i|\n if(i != \"?\")\n @memo[i] += 1\n end\n end\n @memo\n end\n\n def gen_count\n @gen_count ||= _gen_count\n end\n\n def max_gen_count\n @max_gen_count ||= gen_count.map{|k, v| v}.max\n end\n\n def possible?\n return false if gen.length % 4 != 0\n @possible ||= max_gen_count <= gcount\n end\n\n def _solver\n @_solver = []\n gen_count.each do |k, v|\n if(v < gcount)\n (1..(gcount - v)).each{ @_solver << (k) }\n end\n end\n return @_solver\n end\n\n def solver\n @solver ||= _solver\n end\n\n def solutions\n return \"===\" unless possible?\n @solutions = []\n i = 0\n gen.each do |g|\n if(g == \"?\")\n @solutions << solver[i];\n i += 1\n else\n @solutions << g\n end\n end\n @solutions.join(\"\")\n end\n\nend\n\ngets\nputs Genome.new(gets.strip).solutions\n"}, {"source_code": "def miss\n puts \"===\"\n exit 0\nend\n\nn=gets.to_i\ns=gets.chomp\nif n % 4 != 0\n miss\nend\ninv_t={'A'=>0,'G'=>1,'C'=>2,'T'=>3,'?'=>4}\nt='AGCT?'.split('')\nfreq=Array.new(5, 0)\ns.split('').each {|c|\n freq[inv_t[c]] += 1\n}\n(0 .. 3).each {|i|\n if freq[i] > n / 4\n miss\n end\n}\n(0 ... n).each {|i|\n if s[i] == '?'\n for j in 0 .. 3\n if freq[j] < n / 4\n s[i] = t[j]\n freq[j] += 1\n break\n end\n end\n end\n}\nputs s\n"}], "negative_code": [{"source_code": "CODES = ['A', 'G', 'C', 'T']\n\ndef count(code)\n result = {'A'=> 0, 'G'=> 0, 'C'=> 0, 'T'=> 0, '?'=> 0}\n code.each_char{|c| result[c]+=1}\n return result\nend\n\ndef eval(code)\n max = code.length/4\n count(code).all? { |ch, cnt|\n ch == '?' || cnt <= max\n }\nend\n\ndef find(code)\n return nil if !eval(code)\n i = code.index('?')\n if i.nil?\n return code\n else\n for ch in CODES\n copy = code.dup\n copy[i] = ch\n result = find(copy)\n return result if result\n end\n return nil\n end\nend\n\ndef solve(n, code)\n return \"===\" if n < 4 || n%4 != 0\n find(code)\nend\n\nputs solve(STDIN.readline.to_i, STDIN.readline.chomp)\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp\n\nc=[0]*128\ns.bytes{|e|c[e]+=1}\n\nfor i in 0..n-1\n if s[i]==??\n \"AGCT\".bytes{|e|\n if c[e]0 or c.uniq!=[0,n/4] ? \"===\" : s)\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp\n\nc=[0]*128\ns.bytes{|e|c[e]+=1}\n\nfor i in 0..n-1\n if s[i]==??\n \"AGCT\".bytes{|e|\n if c[e]2 ? \"===\" : s)\n"}, {"source_code": "n=gets.to_i\nc=[0]*128\ns=gets.chomp\ns.bytes{|e|c[e]+=1}\nm=0\n\"AGCT\".bytes{|e|m=c[e] if m0 or (m>0 and c[??.ord]!=d)\n puts \"===\"\nelse\n m=n/4 if m==0\n for i in 0..n-1\n if s[i]==??\n \"AGCT\".bytes{|e|\n if c[e] 0,\n \"C\" => 0,\n \"G\" => 0,\n \"T\" => 0\n ]\n end\n\n def length\n @length ||= gen.length\n end\n\n def gcount\n length / 4\n end\n\n def _gen_count\n gen.each do |i|\n if(i != \"?\")\n @memo[i] += 1\n end\n end\n @memo\n end\n\n def gen_count\n @gen_count ||= _gen_count\n end\n\n def max_gen_count\n @max_gen_count ||= gen_count.map{|k, v| v}.max\n end\n\n def possible?\n @possible ||= max_gen_count <= gcount\n end\n\n def _solver\n @_solver = []\n gen_count.each do |k, v|\n if(v < gcount)\n (1..(gcount - v)).each{ @_solver << (k) }\n end\n end\n return @_solver\n end\n\n def solver\n @solver ||= _solver\n end\n\n def solutions\n return \"===\" unless possible?\n @solutions = []\n i = 0\n gen.each do |g|\n if(g == \"?\")\n @solutions << solver[i];\n i += 1\n else\n @solutions << g\n end\n end\n @solutions.join(\"\")\n end\n\nend\n\ngets\nputs Genome.new(gets.strip).solutions\n"}], "src_uid": "d6423f380e6ba711d175d91e73f97b47"} {"source_code": "MOD = 10 ** 9 + 7\r\ndef gs; gets.chomp; end\r\ndef gi; gets.to_i; end\r\ndef gli; gets.split.map(&:to_i); end\r\ndef cyesno(x); puts x ? :Yes : :No; end\r\ndef uyesno(x); puts x ? :YES : :NO; end\r\ndef array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end\r\n\r\ngets.to_i.times do \r\n a, b, c = gli\r\n n = 2 * (a - b).abs\r\n if n < [a, b, c].max\r\n puts \"-1\"\r\n else\r\n if c > n / 2\r\n puts c - n / 2\r\n else\r\n puts n / 2+c\r\n end\r\n end\r\nend\r\n", "positive_code": [{"source_code": "\ndef solve(a, b, c)\n n = (a - b).abs\n return -1 if [a, b, c].max > 2 * n\n a -= 1\n b -= 1\n c -= 1\n (c+n) % (2*n) + 1\nend\n\nt = gets.chomp.to_i\n\nt.times do\n a, b, c = gets.chomp.split(' ').map(&:to_i)\n puts \"#{solve(a, b, c)}\\n\"\nend\n"}], "negative_code": [], "src_uid": "07597a8d08b59d4f8f82369bb5d74a49"} {"source_code": "n, x = gets.split.map(&:to_i)\nas = gets.split.map(&:to_f)\n\nputs (as.inject(:+)/x).abs.ceil\n", "positive_code": [{"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @cards_num, @max_abs = @dats[0].split(\" \").map{|x| x.to_i}\n @cards = @dats[1].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n sum = @cards.inject(:+).abs\n return 1 if sum != 0 && sum <= @max_abs-1\n return 0 if @max_abs == 0\n\n count_ret = 0\n (@max_abs).downto(1) do |elem|\n if sum >= elem\n d = sum / elem\n sum -= elem * d\n count_ret += d\n elsif sum == 0\n return count_ret\n end\n end\n return count_ret\n end\nend\n\nsolver = ProblemA.new\np solver.solve\n"}, {"source_code": "a = readline.split().map {|x| x.to_i}\ns = 0\nreadline.split().map {|i| s += i.to_i}\nputs (s.abs + a[1] - 1) / a[1]"}, {"source_code": "n, x = readline.split().map {|i| i.to_i}\ns = 0\nreadline.split().map {|i| s += i.to_i}\nputs (s.abs + x - 1) / x\n"}, {"source_code": "a=gets.chomp.split(\" \")\nans=0.0\nb=gets.chomp.split(\" \").each {|i| ans+=i.to_i }\nans=ans.abs\nans=(ans/a[1].to_i).ceil\nputs \"#{ans}\""}, {"source_code": "n,x = gets.chomp!.split.map { |e| e.to_i}\n\nsum = gets.split.collect{|x| x.to_i}.inject{|y, x| y += x}\n\nsum = sum.abs\n\nk = (sum + x -1)/x\n\np k\n"}, {"source_code": "n,x = gets.chomp!.split.map { |e| e.to_i}\nsum = gets.split.collect{|x| x.to_i}.inject{|y, x| y += x}\np (sum.abs + x -1)/x"}, {"source_code": "input = gets.chomp\nnum = input.split\nn = Integer(num[0])\nx = Integer(num[1])\ninput2 = gets.chomp\nnums= input2.split\ncard = Array.new\nfor i in 0...n\n card[i] = Integer(nums[i])\nend\n\nsum = 0\nfor i in 0...n\n sum += card[i]\nend\nif sum == 0\n puts 0\nelse\n if sum.abs <= x\n puts 1\n else\n if sum.abs % x == 0\n puts sum.abs / x \n else\n puts sum.abs / x + 1\n end\n end\nend"}, {"source_code": "card = gets.split(\" \").map { |e| e.to_i }\nmas = gets.split(\" \").map { |e| e.to_i }\nsum = 0\nmas.map { |e| sum += e }\nsum = sum.abs\nputs (sum.abs + card[1] - 1) / card[1]\n"}, {"source_code": "n, m = $stdin.gets.split(' ').map{|e| e.to_i}\ncards = $stdin.gets.split(' ').map{|e| e.to_i}\n\nresult = (cards.inject(:+).abs.to_f / m).ceil\nputs result\n"}, {"source_code": "first_line = (gets()).split()\nsecond_line = (gets()).split()\n\nfound_num = (first_line.shift).to_i\nmax_abs = (first_line.shift).to_i\nnum_ary = 0\n\nsecond_line.each do |c|\n\tnum_ary += c.to_i\nend\nresult = (num_ary).abs / max_abs\nif ((num_ary % max_abs) != 0)\n\tresult += 1\nend\np result"}, {"source_code": "a=gets.chomp.split(\" \")\nans=0.0\nb=gets.chomp.split(\" \").each {|i| ans+=i.to_i }\nans=ans.abs\nans=(ans/a[1].to_i).ceil\nputs \"#{ans}\""}, {"source_code": "n, x = gets.split(' ').map(&:to_i)\ns = gets.split(' ').map(&:to_i).inject(:+).abs\nputs s/x + ( s%x == 0 ? 0 : 1 )"}, {"source_code": "\nn,x = gets.chomp.split \n\ng = gets.chomp.split \n\nn = n.to_i \nx = x.to_i \ns = 0\n\nfor i in 0...n\n s += g[i].to_i \nend \n\ns = s.abs \n\ns = s/x.to_f\n\ns = s.ceil\n\nputs s.to_i\n"}, {"source_code": "n, x = gets.split.map &:to_i\na = gets.split.map &:to_i\ns = a.inject(0){|s, x| s + x}\np (s.abs + x - 1)/x"}, {"source_code": "#!/usr/bin/ruby\nn,x=gets.split.map(&:to_i)\ns=gets.split.map(&:to_i).reduce(:+).abs\np (s+x-1)/x"}, {"source_code": "n, x = gets.chomp.split(\" \").map{ |e| e.to_i }\ncards = gets.chomp.split(\" \").map{ |e| e.to_i }\n\nsum = cards.inject{ |s, i| s += i }.abs\nputs (sum.to_f / x.to_f).ceil\n\n\n"}, {"source_code": "def run\n n, x = $stdin.gets.split.map(&:to_i)\n c = $stdin.gets.split.map(&:to_i)\n s = c.reduce(&:+)\n puts (s.abs.to_f / x).ceil\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "def solve(max, cards)\n sum = cards.inject(:+).abs\n div = sum / max\n rem = sum % max\n div += 1 if rem > 0\n div\nend\n\ndef read_next_line\n gets.chomp.split.map(&:to_i)\nend\n\nif __FILE__ == $0\n puts solve(read_next_line[1], read_next_line)\nend"}, {"source_code": "n, x = gets.split.map(&:to_i)\ngiven = gets.split.map(&:to_i)\nsum = 0\n\ngiven.each do |i|\n sum += i\nend\nans = sum.abs / Float(x)\nans = ans.ceil\np Integer(ans)"}, {"source_code": "n, x = gets.split.map &:to_i\nsum = gets.split.map { |x| x.to_i }.inject(:+)\nputs (sum.abs/x.to_f).ceil\n"}, {"source_code": "class A\n def initialize\n n, x = gets.chomp.split(' ').map(&:to_i)\n\n num_list = gets.chomp.split(' ').map(&:to_i)\n\n sum = num_list.inject(:+)\n\n puts (sum.abs/x.to_f).ceil\n end\nend\n\nA.new"}, {"source_code": "#f = File.open('test1.txt', 'r')\nf = STDIN\nn, x = f.gets.chomp.split.map &:to_i\nsum = f.gets.chomp.split.map(&:to_i).reduce(&:+).abs\nputs (sum / x + (sum % x != 0 ? 1 : 0))\n"}, {"source_code": "ri=->{gets.split.map(&:to_i)}\nn,x=ri[]\np (ri[].inject(:+).abs+x-1)/x\n"}, {"source_code": "b=gets.scan(/\\d+/).pop.to_i\nprint STDIN.read.scan(/-?\\d+/).map{|x|x.to_i}.inject{|s,x|s+=x}.abs.fdiv(b).ceil"}, {"source_code": "n, x = gets.split.map { |x| x.to_i }\nsum = gets.split.map { |x| x.to_i }.reduce(:+).abs\nputs (sum + x - 1) / x\n"}, {"source_code": "(n , x) = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\n(sum , res) = 0,0\nn.times do |i|\n sum += arr[i]\nend\n\nsum = sum.abs\nif sum != 0\n res += (sum/x) + (sum%x==0?0:1)\nend\nputs res\n"}, {"source_code": "n, x = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nsum = a.reduce(:+).abs\np (sum + x - 1) / x"}, {"source_code": "a=gets.chomp.split(\" \")\nans=0.0\nb=gets.chomp.split(\" \").each {|i| ans+=i.to_i }\nans=ans.abs\nans=(ans/a[1].to_i).ceil\nputs \"#{ans}\"\n"}], "negative_code": [{"source_code": "input = gets.chomp\nnum = input.split\nn = Integer(num[0])\nx = Integer(num[1])\ninput2 = gets.chomp\nnums= input2.split\ncard = Array.new\nfor i in 0...n\n card[i] = Integer(nums[i])\nend\n\nsum = 0\nfor i in 0...n\n sum += card[i]\nend\nif sum.abs <= x\n puts 1\nelse\n if sum.abs % x == 0\n puts sum.abs / x \n else\n puts sum.abs / x + 1\n end\nend\n"}, {"source_code": "card = gets.split(\" \").map { |e| e.to_i }\nmas = gets.split(\" \").map { |e| e.to_i }\nsum = 0\nmas.map { |e| sum += e }\nif sum % 2 != 0 then \n sum = sum / 2 + 1\nelse \n sum = sum / 2\nend\nputs sum.abs\n"}, {"source_code": "card = gets.split(\" \").map { |e| e.to_i }\nmas = gets.split(\" \").map { |e| e.to_i }\nsum = 0\nmas.map { |e| sum += e }\nif sum % card[1] != 0 then \n sum = sum / card[1] + 1\nelse \n sum = sum / card[1]\nend\nputs sum.abs\n"}, {"source_code": "def check_pair (pos_ary,neg_ary,surplus_cards)\n\tif (pos_ary.first and neg_ary.first)\n\t\tnum = pos_ary.first\n\t\toverlap = neg_ary.index(num)\n\t\tif overlap\n\t\t\tpos_ary.shift\n\t\t\tneg_ary.delete_at(overlap)\n\t\t\treturn check_pair(pos_ary,neg_ary,surplus_cards)\n\t\telse\n\t\t\tpos_ary.shift\n\t\t\tsurplus_cards += 1\n\t\t\treturn check_pair(pos_ary,neg_ary,surplus_cards)\n\t\tend\n\telse\n\t\tsurplus_cards = pos_ary.length + neg_ary.length\n\t\treturn surplus_cards\n\tend\nend\n\n\nfirst_line = (gets()).split()\nsecond_line = (gets()).split()\npos_cards = []\nneg_cards = []\n\nfound_num = (first_line.shift).to_i\nmux_abs = (first_line.shift).to_i\n\nsecond_line.each do |c|\n\tnum = c.to_i\n\tif num > 0\n\t\tpos_cards << num\n\telsif num < 0\n\t\tneg_cards << num\n\tend\nend\n\np check_pair(pos_cards,neg_cards,0)"}, {"source_code": "n, x = gets.split.map(&:to_i)\ngiven = gets.split.map(&:to_i)\nsum = 0\n\ngiven.each do |i|\n sum += i\nend\nsum += x - 1\np sum / x"}, {"source_code": "n, x = gets.split.map(&:to_i)\ngiven = gets.split.map(&:to_i)\nsum = 0\n\ngiven.each do |i|\n sum += i\nend\np (sum / x).abs.ceil"}, {"source_code": "#f = File.open('test1.txt', 'r')\nf = STDIN\nn, x = f.gets.chomp.split.map &:to_i\nsum = f.gets.chomp.split.map(&:to_i).reduce(&:+).abs\nputs (sum / x + sum % x)\n"}, {"source_code": "#!/usr/bin/ruby\nn,x=gets.split.map(&:to_i)\ns=gets.split.map(&:to_i).reduce(:+).abs\np (x+s-1)/s"}, {"source_code": "n, x = gets.split.map &:to_i\nsum = gets.split.map { |x| x.to_i }.inject(:+)\nputs (sum/x).ceil.abs\n"}, {"source_code": "n, x = gets.split.map &:to_i\nsum = gets.split.map { |x| x.to_i }.inject(:+)\nputs (sum/x.to_f).ceil.abs\n"}, {"source_code": "(n , x) = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\nprint arr\nsum = 0\nres = 0\nn.times do |i|\n sum += arr[i]\nend\n\nsum = sum.abs\nif sum != 0\n res += (sum/x)+1\nend\nputs res\n\n"}, {"source_code": "(n , x) = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\n(sum , res) = 0,0\nn.times do |i|\n sum += arr[i]\nend\n\nsum = sum.abs\nif sum != 0\n res += (sum/x)+1\nend\nputs res\n"}, {"source_code": "(n , x) = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\nsum = 0\nres = 0\nn.times do |i|\n sum += arr[i]\nend\n\nsum = sum.abs\nif sum != 0\n res += (sum%x)+1\nend\nputs res\n"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @cards_num, @max_abs = @dats[0].split(\" \").map{|x| x.to_i}\n @cards = @dats[1].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n sum = @cards.inject(:+).abs\n return 1 if sum <= @max_abs-1\n return 0 if @max_abs == 0\n\n count_ret = 0\n (@max_abs).downto(1) do |elem|\n if sum >= elem\n d = sum / elem\n sum -= elem * d\n count_ret += d\n elsif sum == 0\n return count_ret\n end\n end\n return count_ret\n end\nend\n\nsolver = ProblemA.new\np solver.solve\n"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @cards_num, @max_abs = @dats[0].split(\" \").map{|x| x.to_i}\n @cards = @dats[1].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n sum = @cards.inject(:+).abs\n return 1 if sum <= @max_abs\n return 0 if @max_abs == 0\n\n count_ret = 0\n (@max_abs-1).downto(1) do |elem|\n if sum > elem\n count_ret += 1\n sum -= elem\n elsif sum == 1\n return count_ret+1 \n end\n end\n return count_ret\n end\nend\n\nsolver = ProblemA.new\np solver.solve\n"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @cards_num, @max_abs = @dats[0].split(\" \").map{|x| x.to_i}\n @cards = @dats[1].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n sum = @cards.inject(:+).abs\n return 1 if sum <= @max_abs\n return 0 if @max_abs == 0\n\n count_ret = 0\n (@max_abs-1).downto(1) do |elem|\n if sum >= elem\n count_ret += 1\n sum -= elem\n elsif sum == 1\n return count_ret+1 \n elsif sum == 0\n return count_ret\n end\n end\n return count_ret\n end\nend\n\nsolver = ProblemA.new\np solver.solve\n"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @cards_num, @max_abs = @dats[0].split(\" \").map{|x| x.to_i}\n @cards = @dats[1].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n sum = @cards.inject(:+).abs\n return 1 if sum <= @max_abs\n return 0 if @max_abs == 0\n\n count_ret = 0\n (@max_abs-1).downto(1) do |elem|\n if sum >= elem\n count_ret += 1\n sum -= elem\n elsif sum == 0\n return count_ret\n end\n end\n return count_ret\n end\nend\n\nsolver = ProblemA.new\np solver.solve\n"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @cards_num, @max_abs = @dats[0].split(\" \").map{|x| x.to_i}\n @cards = @dats[1].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n sum = @cards.inject(:+).abs\n return 1 if sum <= @max_abs-1\n return 0 if @max_abs == 0\n\n count_ret = 0\n (@max_abs-1).downto(1) do |elem|\n if sum >= elem\n d = sum / elem\n sum -= elem * d\n count_ret += d\n elsif sum == 0\n return count_ret\n end\n end\n return count_ret\n end\nend\n\nsolver = ProblemA.new\np solver.solve\n"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @cards_num, @max_abs = @dats[0].split(\" \").map{|x| x.to_i}\n @cards = @dats[1].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n sum = @cards.inject(:+).abs\n return 1 if sum <= @max_abs\n return 0 if @max_abs == 0\n\n count_ret = 0\n @max_abs.downto(1) do |elem|\n if sum > elem\n count_ret += 1\n sum -= elem\n elsif sum == 1\n return count_ret+1 \n end\n end\n return count_ret\n end\nend\n\nsolver = ProblemA.new\np solver.solve\n"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @cards_num, @max_abs = @dats[0].split(\" \").map{|x| x.to_i}\n @cards = @dats[1].split(\" \").map{|x| x.to_i}\n end\n\n def solve\n sum = @cards.inject(:+).abs\n return 1 if sum <= @max_abs-1\n return 0 if @max_abs == 0\n\n count_ret = 0\n (@max_abs-1).downto(1) do |elem|\n if sum >= elem\n count_ret += 1\n sum -= elem\n elsif sum == 0\n return count_ret\n end\n end\n return count_ret\n end\nend\n\nsolver = ProblemA.new\np solver.solve\n"}], "src_uid": "066906ee58af5163636dac9334619ea7"} {"source_code": "n, k = gets.strip.split.map(&:to_i)\nary = gets.strip.split.map(&:to_i)\nhsh = {}\nary.each {|x| hsh[x] = (hsh[x] || 0) + 1 }\nary.sort!\nary.uniq!\nremaining_ary = []\nun = ary.size\n0.upto(un-2).each do |j|\n i = j + 1\n next if ary[j] < ary[i] && ary[i] <= (ary[j]+k)\n remaining_ary << ary[j]\nend\nremaining_ary << ary.last\nputs remaining_ary.map{|x| hsh[x] }.inject(:+)", "positive_code": [{"source_code": "def read_line\n gets.split.map{|e| e.to_i }\nend\n\nn, k = read_line\na = read_line.sort\n\ncount = 0\n\nnearest_bigger = []\nnearest_bigger[a.count - 1] = a[a.count -1]\n\n(0...n-1).reverse_each do |index|\n cur = a[index]\n next_val = a[index+1]\n if cur == next_val\n nearest_bigger[index] = nearest_bigger[index+1]\n else\n nearest_bigger[index] = next_val\n end\nend\n\na[0...-1].to_enum.with_index.each do |val, index|\n next_val = nearest_bigger[index]\n if val < next_val && (val + k) >= next_val\n count += 1\n end\nend\n\nputs n-count\n"}, {"source_code": "# http://codeforces.com/problemset/problem/990/B\n\ndef count\n n, k = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n a.sort!\n # puts a.inspect\n\n return n if a.first == a.last || n == 1\n\n s = 0\n c = 0\n 1.upto(n - 1) do |i|\n next if a[i] - a[i-1] <= k\n\n c += skip_count(a, i-1, s)\n s = i\n end\n\n c += skip_count(a, n-1, s)\n\n return n - c\nend\n\ndef skip_count(a, startIdx, endIdx)\n c = 0\n startIdx.downto(endIdx) do |i|\n if a[i] == a[startIdx]\n next\n end\n\n c = (i - endIdx + 1)\n break\n end\n\n c\nend\n\nputs count\n"}, {"source_code": "_, k = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\n\nb.sort!\n\nn = 0\nprev = b.first\nprev_cnt = 0\nb.each do |i|\n if i > prev\n if i > prev + k\n n += prev_cnt\n end\n prev = i\n prev_cnt = 1\n else\n prev_cnt +=1\n end\nend\nn += prev_cnt\nputs n\n"}], "negative_code": [{"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\na.sort!\n\nc = 1\ns = 1\nunique = true\n1.upto(n - 1) do |i|\n unique = false if (a[i] != a[i - 1]) && unique\n next if a[i] - a[i-1] <= k\n\n (i - 1).downto(s) do |j|\n if a[j] == a[i - 1]\n c += 1\n next\n end\n\n c += 1\n break\n end\n\n s = i\nend\n\nif unique\n puts n\nelse\n puts c\nend\n"}], "src_uid": "be8be333d036f6c19b9a6eb33f96ba75"} {"source_code": "gets.to_i.times do\n gets\n puts gets.split(' ').map(&:to_i).uniq.join(' ')\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\tflag = [false] * (n + 1)\n\tputs a.reduce([]) { |acc, i|\n\t\t\tif !flag[i]\n\t\t\t\tacc << i\n\t\t\t\tflag[i] = true\n\t\t\tend\n\t\t\tacc\n\t }.join(' ')\nend\n"}, {"source_code": "# frozen_string_literal: true\n\nlines = gets.to_i\nlines.times do\n numbers = gets.to_i\n number_permutation = gets.split(' ').map(&:to_i)\n find_map = {}\n number_permutation.each do |i|\n next if find_map[i]\n\n find_map[i] = true\n end\n print find_map.keys.join(' '), \"\\n\"\nend\n"}, {"source_code": "n = gets.chomp.to_i\nn.times do\n b = gets.chomp.to_i\n atr = gets.chomp.split(\" \")\n retsu = []\n until atr == []\n a = atr.shift\n # p retsu\n if !retsu.include?(a)\n retsu << a\n end\n end\n #p retsu\n retsu.delete(\" \")\n puts retsu.join(\" \")\nend"}, {"source_code": "tc = gets.to_i \n\ntc.times do \n n = gets.to_i \n arr = gets.split().map{|i| i.to_i} \n dic = Hash.new(0)\n ans = [] \n arr.each do |x|\n if(dic[x] == 0) \n ans << x \n end \n dic[x] += 1 \n end\n puts ans.join(\" \")\nend"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n used = [false] * n\n res = []\n (0...2 * n).each do |i|\n if !used[a[i] - 1]\n used[a[i] - 1] = true\n res << a[i]\n end\n end\n puts res.join ' '\nend\n "}, {"source_code": "def solve\n n = gets.strip.to_i\n a = gets.strip.split(' ').map(&:to_i)\n v = []\n (1..n).each { |e| v[e] = true }\n a.each { |e|\n break if n.zero?\n if v[e] == true\n print \"#{e} \"\n v[e] = false\n end\n }\n puts \nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "gets.to_i.times do\n gets\n puts gets.split.map(&:to_i).uniq.join(' ')\nend\n\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\nn.times do\n b = gets.chomp.to_i\n atr = gets.chomp.split(\"\")\n retsu = []\n until atr == []\n a = atr.shift\n if !retsu.include?(a)\n retsu << a\n end\n end\n retsu.delete(\" \")\n puts retsu.join(\" \")\nend"}], "src_uid": "aaf91874cf5aa0fa302ffed2ccecdc76"} {"source_code": "\n\nn, m = STDIN.gets.split(' ').map{|x| x.to_i}\na = []\n\nm.times do |i|\n a.push(STDIN.gets.split(' ').map{|y| y.to_i - 1});\nend\n\n=begin\nn, m = 5, 6\na = ['1 2',\n'1 3',\n'2 3',\n'2 4',\n'3 4',\n'4 5'].map{|x| x.split(' ').map{|y| y.to_i - 1}}\n=end\nmusketeers = Array.new(n){|x| {'known'=>{}, 'knowncount'=> 0}}\na.map do |elem|\n musketeers[elem[0]]['knowncount'] +=1;\n musketeers[elem[0]]['known'][elem[1]]=true;\n musketeers[elem[1]]['knowncount'] +=1;\n musketeers[elem[1]]['known'][elem[0]]=true; \nend\n\n# \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0440\u043e\u0439\u043a\u0438 \u0437\u043d\u0430\u044e\u0449\u0438\u0445\ntroikas = [];\na.map do |x|\n unite = musketeers[x[0]]['known'].keys & musketeers[x[1]]['known'].keys\n\n unite.map{|y| troikas.push([y, x[0],x[1] ].sort) }\n \nend\n\ntroikas.uniq!\n\nres = troikas.map{|x| -6 + x.inject(0){|result, y| result+= musketeers[y]['knowncount']}}.min\nres = -1 if res == nil\nputs res\n", "positive_code": [{"source_code": "=begin\n ____________\n / \\\n / /\\ /\\ \\\n / / \\ / \\ \\\n \\ /\n \\ \\___/ /\n \\____________/\n=end\n\nclass Solve\n def run()\n str = gets.split\n n , m = Integer(str[0]), Integer(str[1])\n graph = Array.new(n) {Array.new(n,false)}\n graph2 = Array.new(n) {Array.new}\n degree = Array.new(n,0)\n for i in 1..m\n str = gets.split\n u , v = Integer(str[0]),Integer(str[1])\n if v < u\n u, v = v , u\n end\n u -= 1\n v -= 1\n graph[u][v] = graph[v][u] = true\n graph2[u].push(v)\n degree[u] += 1\n degree[v] += 1\n end\n mn = 4000 * 4000 * 4000 * 2\n for i in 0..n-1\n for j in 0..graph2[i].length-2\n for k in j+1..graph2[i].length-1\n if graph[graph2[i][j]][graph2[i][k]] == true and degree[i] + degree[graph2[i][j]] + degree[graph2[i][k]] < mn\n mn = degree[i] + degree[graph2[i][j]] + degree[graph2[i][k]]\n end\n end\n end\n end\n if mn == 4000 * 4000 * 4000 * 2\n puts -1\n else\n puts (mn - 6)\n end\n end\nend\n\nSolve.new.run"}, {"source_code": "q = Hash.new([])\nn, m = gets.split.map(&:to_i)\nglory = 0\nout = -1\n\nm.times do\n a, b = gets.split.map(&:to_i)\n q[a] += [b]\n q[b] += [a]\nend\n\nq.delete_if{ |key, value| value.size < 2 }\n\nq.each do |key, value|\n \n for i in 0...value.size-1 do\n next unless q.key?(value[i])\n\n for j in i+1..value.size-1 do\n next unless q.key?(value[j])\n next unless q[value[j]].include?(value[i])\n\n glory = -6\n glory += q[value[i]].size\n glory += q[value[j]].size\n glory += q[key].size\n out = glory if out > glory || out == -1\n\n end\n end\nend\n\nputs out"}, {"source_code": "require 'set'\n\nn, m = gets.split.map &:to_i\nneighbour = (1..n).map{0}\ndegree = (1..n).map{0}\n\nedges = []\nm.times {\n\ti, j = gets.split.map(&:to_i)\n\ti -= 1\n\tj -= 1\n\tneighbour[i] |= (1 << j)\n\tneighbour[j] |= (1 << i)\n\tdegree[i] += 1\n\tdegree[j] += 1\n\tedges << [i, j]\n}\n\nmin = Float::INFINITY\n\nedges.each{|i, j|\n\td0 = degree[i] + degree[j]\n\tx = neighbour[i] & neighbour[j]\n\t(0..n-1).each{|k|\n\t\tif x[k] == 1\n\t\t\td = d0 + degree[k]\n\t\t\tmin = d if d < min\n\t\tend\t\t \n\t}\n}\n\n\n#(0..n-1).sort_by{|i| degree[i]}.each{|i|\n#\td1 = degree[i]\n#\tbreak if d1 * 3 >= min\n#\n#\tedges.reject!{|j, k|\n#\t\tif j == i || k == i\n#\t\t\ttrue\n#\t\telse\n#\t\t\tif neighbour[i].include?(j) && neighbour[i].include?(k)\t\n#\t\t\t\td2, d3 = degree[j], degree[k]\n#\t\t\t\td = d1 + d2 + d3\n#\t\t\t\tmin = d if d < min\n#\t\t\tend\n#\t\t\tfalse\n#\t\tend\n#\t}\n#}\n#\n\np min == Float::INFINITY ? -1 : min - 6"}, {"source_code": "q = Hash.new([])\nn, m = gets.split.map(&:to_i)\nglory = 0\nout = -1\n\nm.times do\n a, b = gets.split.map(&:to_i)\n q[a] += [b]\n q[b] += [a]\nend\n\nq.delete_if{ |key, value| value.size < 2 }\n\nq.each do |key, value|\n \n for i in 0...value.size-1 do\n next unless q.key?(value[i])\n\n for j in i+1..value.size-1 do\n next unless q.key?(value[j])\n next unless q[value[j]].include?(value[i])\n\n glory = -6\n glory += q[value[i]].size\n glory += q[value[j]].size\n glory += q[key].size\n out = glory if out > glory || out == -1\n\n end\n end\nend\n\nputs out"}, {"source_code": "n, m = gets.chomp.split(' ').map(&:to_i)\nas = []\nbs = []\nm.times do\n a, b = gets.chomp.split(' ').map(&:to_i)\n as << a\n bs << b\nend\n\nrs = [[]]\nn.times do\n rs << [] \nend\n\nhs = Hash.new(0)\nfor i in 0..m-1\n hs[as[i]] += 1\n hs[bs[i]] += 1\n rs[as[i]] << bs[i]\n rs[bs[i]] << as[i]\nend\n\nrtn = -1\nfor m1 in 1..n-2\n r = rs[m1]\n if 1 < r.size\n for j in 0..r.size-2\n m2 = r[j]\n for k in j+1..r.size-1\n m3 = r[k]\n if rs[m2].include?(m3)\n if rtn < 0 || hs[m1] + hs[m2] + hs[m3] - 6 < rtn\n rtn = hs[m1] + hs[m2] + hs[m3] - 6\n end\n end\n end\n end\n end\nend\n\nputs rtn\n"}], "negative_code": [{"source_code": "=begin\n ____________\n / \\\n / /\\ /\\ \\\n / / \\ / \\ \\\n \\ /\n \\ \\___/ /\n \\____________/\n=end\n\nclass Solve\n def run()\n str = gets.split\n n , m = Integer(str[0]), Integer(str[1])\n graph = Array.new(n) {Array.new(n,false)}\n graph2 = Array.new(n) {Array.new}\n degree = Array.new(n,0)\n for i in 1..m\n str = gets.split\n u , v = Integer(str[0]),Integer(str[1])\n if v < u\n u, v = v , u\n end\n u -= 1\n v -= 1\n graph[u][v] = graph[v][u] = true\n graph2[u].push(v)\n degree[u] += 1\n degree[v] += 1\n end\n mn = 4000 * 4000 * 4000 * 2\n for i in 0..n-1\n for j in 0..graph2[i].length-2\n for k in j+1..graph2[i].length-1\n if graph[graph2[i][j]][graph2[i][k]] == true and degree[i] + degree[graph2[i][j]] + degree[graph2[i][k]] < mn\n mn = degree[i] + degree[graph2[i][j]] + degree[graph2[i][k]]\n end\n end\n end\n end\n puts (mn - 6)\n end\nend\n\nSolve.new.run"}, {"source_code": "q = Hash.new([])\nn, m = gets.split.map(&:to_i)\nglory = 0\nout = -1\n\nm.times do\n a, b = gets.split.map(&:to_i)\n q[a] += [b]\n q[b] += [a]\nend\n\nq.delete_if{ |key, value| value.size < 2 }\n\nq.each do |key, value|\n for i in 0...value.size-1 do\n unless q.key?(value[i])\n glory = 0\n break\n end\n for j in i+1..value.size-1 do\n if q.key?(value[j])\n\n if q[value[j]].include?(value[i])\n glory += q[value[i]].size\n glory += q[value[j]].size\n glory += q[key].size\n glory -= 6\n out = glory if out > glory || out == -1\n else\n glory = 0\n break\n end\n else\n glory = 0\n break\n end\n\n end\n end\nend\n\nputs out\n"}, {"source_code": "q = Hash.new([])\nn, m = gets.split.map(&:to_i)\nglory = 0\nout = -1\n\nm.times do\n a, b = gets.split.map(&:to_i)\n q[a] += [b]\n q[b] += [a]\nend\n\nq.delete_if{ |key, value| value.size < 2 }\n\nq.each do |key, value|\n \n for i in 0...value.size-1 do\n break unless q.key?(value[i])\n\n for j in i+1..value.size-1 do\n break unless q.key?(value[j])\n break unless q[value[j]].include?(value[i])\n\n glory = -6\n glory += q[value[i]].size\n glory += q[value[j]].size\n glory += q[key].size\n out = glory if out > glory || out == -1\n\n end\n end\nend\n\nputs out\n"}], "src_uid": "24a43df3e6d2af348692cdfbeb8a195c"} {"source_code": "gets.to_i.times do\n n = gets.to_i\n a = gets.split.map &:to_i\n i = 0\n (0..100).each do |x|\n if j = a.index(x)\n a[i], a[j] = a[j], a[i]\n else\n break\n end\n i += 1\n end\n puts a.join ' '\nend\n", "positive_code": [{"source_code": "gets.to_i.times {\n gets\n arr = gets.split(' ').map(&:to_i).sort\n res = []\n res_tail = []\n arr.each { |el|\n if el == res[-1]\n res_tail.push(el)\n else\n res.push(el)\n end\n }\n puts [*res, *res_tail].join(' ')\n}\n"}, {"source_code": "def solve(n, a)\n mex = 0\n b = []\n n.times {\n if (i = a.index(mex))\n b << a.delete_at(i)\n mex += 1\n else\n break\n end\n }\n b += a\n b\nend\n\ndef main\n t = int\n t.times do\n n = int\n a = ints\n puts solve(n, a) * \" \"\n end\nend\n\nDEBUG = true\nMOD = 10**9+7\nYESNO = %w(No Yes)\nINF = 10**9\n\ndef int; gets.to_s.to_i end\ndef ints; gets.to_s.split.map { |s| s.to_i } end\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\ndef float; gets.to_s.to_f end\ndef floats; gets.to_s.split.map { |s| s.to_f } end\ndef array_of(&convert); gets.to_s.split.map(&convert) end\ndef string; gets.to_s.chomp end\ndef rep(n, &b); Array.new(n, &b) end\ndef yes; puts YESNO[1] end\ndef no; puts YESNO[0] end\ndef yesno t; puts YESNO[t] end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\ndef gcd(*xs); xs.inject(0, :gcd) end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\ndef if_debug; yield if DEBUG end\n\nmodule Boolean\ndef coerce(other); [other, to_i] end\ndef +@; to_i end\ndef to_int; to_i end\ndef *(other); to_i * other end\nend\n\nclass TrueClass\ninclude Boolean\ndef to_i; 1 end\nend\n\nclass FalseClass\ninclude Boolean\ndef to_i; 0 end\nend\n\nclass Integer\ndef div_ceil(y); (self + y - 1) / y end\ndef mod_inv(mod = MOD); pow(mod-2, mod) end\ndef mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\ndef factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\ndef popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\ndef bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\ndef lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\ndef shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\ndef widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\nend\n\nclass Array\ndef power(&block); (0 ... 1 << size).each(&block) end\ndef sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\ndef upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\ndef lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\ndef cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\ndef cumdiff(range); self[range.end_open] - self[range.begin]; end\nend\n\nmodule Enumerable\ndef sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\ndef cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\nend\n\nmain"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n a.sort!\r\n res = []\r\n (0...n).each do |i|\r\n res << a[i] if i == 0 || a[i] != a[i - 1]\r\n end\r\n (0...n).each do |i|\r\n res << a[i] if i > 0 && a[i] == a[i - 1]\r\n end\r\n puts res.join ' '\r\nend"}, {"source_code": "t = gets.chomp.to_i\r\nfor test in (1..t)\r\n n = gets.chomp.to_i\r\n a = gets.chomp.split(' ').map { |x| x.to_i }\r\n c = Array.new(101).fill(0)\r\n for i in a\r\n c[i] += 1\r\n end\r\n j = 0\r\n for i in (0..100)\r\n if c[i] > 0\r\n c[i] -= 1\r\n a[j] = i\r\n j += 1\r\n end\r\n end\r\n for i in (0..100)\r\n while c[i] > 0\r\n c[i] -= 1\r\n a[j] = i\r\n j += 1\r\n end\r\n end\r\n a.each do |x|\r\n print x, ' '\r\n end\r\n puts\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map &:to_i\r\n res = []\r\n (0...n).each do |i|\r\n res << a[i] if i == 0 || a[i] != a[i - 1]\r\n end\r\n (0...n).each do |i|\r\n res << a[i] if i > 0 && a[i] == a[i - 1]\r\n end\r\n puts res.join ' '\r\nend"}], "src_uid": "69838d9f9214c65b84a21d4eb546ea4b"} {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i).sort.reverse\nans = nil\nif arr.include?(0)\n\tsum = arr.inject(0,:+)\n\tif sum % 3 == 0\n\t\tans = arr.join(\"\")\n\telsif sum % 3 == 1\n\t\t\n\t\tone = [1,4,7]\n\t\ttwo = [2,5,8]\n\t\tl = nil\n\t\tone.each do |o|\n\t\t\tl = arr.rindex(o)\n\t\t\tif l\n\t\t\t\tarr.delete_at(l)\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\n\t\tunless l\n\t\t\tdeleted = 0\n\t\t\ttwo.each do |t|\n\t\t\t\tl = arr.rindex(t)\n\t\t\t\tif l \n\t\t\t\t\tif deleted == 0\n\t\t\t\t\t\tl1 = arr.index(t)\n\t\t\t\t\t\tif l == l1\n\t\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\t\t\tdeleted = 1\n\t\t\t\t\t\t\tnext\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\t\t\tarr.delete_at(l1)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\n\t\t\t\t\tif deleted == 1\n\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\tend\n\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\n\t\t# j = arr.length - 1\n\t\t# while j >= 0\n\t\t# \ta = arr[j]\n\t\t\t\n\t\t# \tif a % 3 == 1 && one.length < 1\n\t\t# \t\tone << j \n\t\t# \t\tbreak\n\t\t# \tend\n\t\t\t\n\t\t# \tif a % 3 == 2 && two.length < 2\n\t\t# \t\ttwo << j\n\t\t# \tend\n\t\t# \tj -= 1\t\t\t\n\t\t# end\n\t\t# if one.empty?\n\t\t# \tarr.delete_at(two[0])\n\t\t# \tarr.delete_at(two[1])\n\t\t# else\n\t\t# \tarr.delete_at(one[0])\n\t\t# end\n\n\n\t\t# puts \"here\"\n\t\t# l = arr.rindex{|a| a % 3 == 1}\n\t\t# if l\n\t\t# \tarr.delete_at(l)\n\t\t# else\n\t\t# \tl = arr.rindex{|a| a % 3 == 2}\n\t\t# \tarr.delete_at(l)\n\t\t# \tl = arr.rindex{|a| a % 3 == 2}\n\t\t# \tarr.delete_at(l)\n\t\t# end\n\telse\n\n\t\t\n\t\tone = [1,4,7]\n\t\ttwo = [2,5,8]\n\t\tl = nil\n\t\ttwo.each do |o|\n\t\t\tl = arr.rindex(o)\n\t\t\tif l\n\t\t\t\tarr.delete_at(l)\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\n\t\tunless l\n\t\t\tdeleted = 0\n\t\t\tone.each do |t|\n\t\t\t\tl = arr.rindex(t)\n\t\t\t\tif l \n\t\t\t\t\tif deleted == 0\n\t\t\t\t\t\tl1 = arr.index(t)\n\t\t\t\t\t\tif l == l1\n\t\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\t\t\tdeleted = 1\n\t\t\t\t\t\t\tnext\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\t\t\tarr.delete_at(l1)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\n\t\t\t\t\tif deleted == 1\n\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\tend\n\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\n\n\t\t# one = [1,4,7]\n\t\t# two = [2,5,8]\n\t\t# j = arr.length - 1\n\t\t# while j >= 0\n\t\t# \ta = arr[j]\n\t\t\t\n\t\t# \tif a % 3 == 2 && two.length < 1\n\t\t# \t\ttwo << j \n\t\t# \t\tbreak\n\t\t# \tend\n\t\t\t\n\t\t# \tif a % 3 == 1 && one.length < 2\n\t\t# \t\tone << j\n\t\t# \tend\n\t\t# \tj -= 1\t\t\t\n\t\t# end\n\t\t# if two.empty?\n\t\t# \tarr.delete_at(one[0])\n\t\t# \tarr.delete_at(one[1])\n\t\t# else\n\t\t# \tarr.delete_at(two[0])\n\t\t# end\n\n\n\t\t# l = arr.rindex{|a| a % 3 == 2}\n\t\t# if l\n\t\t# \tarr.delete_at(l)\n\t\t# else\n\t\t# \tl = arr.rindex{|a| a % 3 == 1}\n\t\t# \tarr.delete_at(l)\n\t\t# \tl = arr.rindex{|a| a % 3 == 1}\n\t\t# \tarr.delete_at(l)\n\t\t# end\n\tend\n\tans = arr.join(\"\")\n\tunless /[^0]/ =~ ans\n\t\tputs \"0\"\n\telse\n\t\tputs ans\n\tend\nelse\n\tputs \"-1\"\nend", "positive_code": [{"source_code": "n = gets.to_i\ndigits = gets.split.map(&:to_i).sort_by {|el| -el}\n\nunless digits.last==0\n puts -1\n exit\nend\n\nsum = digits.inject{|sum,el| sum+=el}\nans = 0\nsize = digits.size\n\nif sum%3 == 0\n ans = digits.join unless digits[0] == 0\nelsif sum%3 == 1\n (size-1).downto(0) do |i|\n if digits[i]%3==1\n digits.delete_at i\n break\n end\n end\n if digits.size == size\n (size-1).downto(0) do |i|\n if digits[i]%3==2 && ( size - digits.size < 2 )\n digits.delete_at i\n end\n end\n end\n ans = digits.join unless digits[0] == 0\nelsif sum%3 == 2\n (size-1).downto(0) do |i|\n if digits[i]%3==2\n digits.delete_at i\n break\n end\n end\n if digits.size == size\n (size-1).downto(0) do |i|\n if digits[i]%3==1 && ( size - digits.size < 2 )\n digits.delete_at i\n end\n end\n end\n ans = digits.join unless digits[0] == 0\nend\n\nputs (ans[0] == '0' ? 0 : ans)\n"}], "negative_code": [{"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i).sort.reverse\nans = nil\nif arr.include?(0)\n\tsum = arr.inject(0,:+)\n\tif sum % 3 == 0\n\t\tans = arr.join(\"\")\n\telsif sum % 3 == 1\n\t\t\n\t\tone = [1,4,7]\n\t\ttwo = [2,5,8]\n\t\tl = nil\n\t\tone.each do |o|\n\t\t\tl = arr.rindex(o)\n\t\t\tif l\n\t\t\t\tarr.delete_at(l)\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\n\t\tunless l\n\t\t\tdeleted = 0\n\t\t\ttwo.each do |t|\n\t\t\t\tl = arr.rindex(t)\n\t\t\t\tif l \n\t\t\t\t\tif deleted == 0\n\t\t\t\t\t\tl1 = arr.index(t)\n\t\t\t\t\t\tif l == l1\n\t\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\t\t\tdeleted = 1\n\t\t\t\t\t\t\tnext\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\t\t\tarr.delete_at(l1)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\n\t\t\t\t\tif deleted == 1\n\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\tend\n\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\n\t\t# j = arr.length - 1\n\t\t# while j >= 0\n\t\t# \ta = arr[j]\n\t\t\t\n\t\t# \tif a % 3 == 1 && one.length < 1\n\t\t# \t\tone << j \n\t\t# \t\tbreak\n\t\t# \tend\n\t\t\t\n\t\t# \tif a % 3 == 2 && two.length < 2\n\t\t# \t\ttwo << j\n\t\t# \tend\n\t\t# \tj -= 1\t\t\t\n\t\t# end\n\t\t# if one.empty?\n\t\t# \tarr.delete_at(two[0])\n\t\t# \tarr.delete_at(two[1])\n\t\t# else\n\t\t# \tarr.delete_at(one[0])\n\t\t# end\n\n\n\t\t# puts \"here\"\n\t\t# l = arr.rindex{|a| a % 3 == 1}\n\t\t# if l\n\t\t# \tarr.delete_at(l)\n\t\t# else\n\t\t# \tl = arr.rindex{|a| a % 3 == 2}\n\t\t# \tarr.delete_at(l)\n\t\t# \tl = arr.rindex{|a| a % 3 == 2}\n\t\t# \tarr.delete_at(l)\n\t\t# end\n\telse\n\n\t\t\n\t\tone = [1,4,7]\n\t\ttwo = [2,5,8]\n\t\tl = nil\n\t\ttwo.each do |o|\n\t\t\tl = arr.rindex(o)\n\t\t\tif l\n\t\t\t\tarr.delete_at(l)\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\n\t\tunless l\n\t\t\tdeleted = 0\n\t\t\tone.each do |t|\n\t\t\t\tl = arr.rindex(t)\n\t\t\t\tif l \n\t\t\t\t\tif deleted == 0\n\t\t\t\t\t\tl1 = arr.index(t)\n\t\t\t\t\t\tif l == l1\n\t\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\t\t\tdeleted = 1\n\t\t\t\t\t\t\tnext\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\t\t\tarr.delete_at(l1)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\n\t\t\t\t\tif deleted == 1\n\t\t\t\t\t\tarr.delete_at(l)\n\t\t\t\t\tend\n\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\n\n\t\t# one = [1,4,7]\n\t\t# two = [2,5,8]\n\t\t# j = arr.length - 1\n\t\t# while j >= 0\n\t\t# \ta = arr[j]\n\t\t\t\n\t\t# \tif a % 3 == 2 && two.length < 1\n\t\t# \t\ttwo << j \n\t\t# \t\tbreak\n\t\t# \tend\n\t\t\t\n\t\t# \tif a % 3 == 1 && one.length < 2\n\t\t# \t\tone << j\n\t\t# \tend\n\t\t# \tj -= 1\t\t\t\n\t\t# end\n\t\t# if two.empty?\n\t\t# \tarr.delete_at(one[0])\n\t\t# \tarr.delete_at(one[1])\n\t\t# else\n\t\t# \tarr.delete_at(two[0])\n\t\t# end\n\n\n\t\t# l = arr.rindex{|a| a % 3 == 2}\n\t\t# if l\n\t\t# \tarr.delete_at(l)\n\t\t# else\n\t\t# \tl = arr.rindex{|a| a % 3 == 1}\n\t\t# \tarr.delete_at(l)\n\t\t# \tl = arr.rindex{|a| a % 3 == 1}\n\t\t# \tarr.delete_at(l)\n\t\t# end\n\tend\n\tans = arr.join(\"\")\n\t# if ans.to_i == 0\n\t# \tputs \"0\"\n\t# else\n\t\tputs ans\n\t# end\nelse\n\tputs \"-1\"\nend"}], "src_uid": "b263917e47e1c84340bcb1c77999fd7e"} {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\n\nif n == 2\n\tputs \"-1\"\n\texit 0\nend\n\nmn = x.min\nk = x.index(mn)\nlmx = x[0..k-1].max\nrmx = x[k+1..-1].max\nif 0 < k && k + 1 < n && lmx > mn && rmx > mn\n\tif lmx != rmx\n\t\tputs \"#{x[0..k-1].index(lmx)+1} #{x[k+1..-1].index(rmx)+k+2}\"\n\telse\n\t\t1.upto(k-1) do |i|\n\t\t\tif x[i] != mn\n\t\t\t\tputs \"#{i+1} #{k+1}\"\n\t\t\t\texit 0\n\t\t\tend\n\t\tend\n\t\t(k+1).upto(n-2) do |i|\n\t\t\tif x[i] != mn\n\t\t\t\tputs \"#{k+1} #{i+1}\"\n\t\t\t\texit 0\n\t\t\tend\n\t\tend\n\t\tif n == 3\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\t\tputs \"1 2\"\n\tend\n\texit 0\nend\n\nmx = x.max\nk = x.index(mx)\nlmn = x[0..k-1].min\nrmn = x[k+1..-1].min\nif 0 < k && k + 1 < n && lmn < mx && rmn < mx\n\tif lmn != rmn\n\t\tputs \"#{x[0..k-1].index(lmn)+1} #{x[k+1..-1].index(rmn)+k+2}\"\n\telse\n\t\t1.upto(k-1) do |i|\n\t\t\tif x[i] != mx\n\t\t\t\tputs \"#{i+1} #{k+1}\"\n\t\t\t\texit 0\n\t\t\tend\n\t\tend\n\t\t(k+1).upto(n-2) do |i|\n\t\t\tif x[i] != mx\n\t\t\t\tputs \"#{k+1} #{i+1}\"\n\t\t\t\texit 0\n\t\t\tend\n\t\tend\n\t\tif n == 3\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\t\tputs \"1 2\"\n\tend\n\texit 0\nend\n\nif mn == mx\n\tputs -1\n\texit 0\nend\n\nx[1..-2].each_with_index do |v, i|\n\tif v != x[0]\n\t\tputs \"1 #{i+2}\"\n\t\texit 0\n\tend\n\tif v != x[-1]\n\t\tputs \"#{i+2} #{n}\"\n\t\texit 0\n\tend\nend\n\nputs -1\n", "positive_code": [{"source_code": "t = gets.to_i\n\na = gets.split.collect{|x| x.to_i}\n\nup = a.sort\ndn = a.sort{|x,y| y <=> x}\n\ni = 0\nfinish = false\n\n1.upto(a.size-1) do |i|\n\tif a[i-1] != a[i]\n\t\ta[i], a[i-1] = a[i-1], a[i]\n\n\t\tfinish = a != up && a != dn\n\n\t\tif finish\n\t\t\tprint i,' ', i+1\n\t\t\tbreak\n\t\tend\n\n\t\ta[i], a[i-1] = a[i-1], a[i]\n\tend\nend\n\nif not finish or a == Array.new(a.size, a[0])\n\tprint -1\nend"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\nif n < 3\n puts \"-1\"\n exit\nend\n\nincr = a.sort\ndecr = a.sort{|x,y| y <=> x}\n\ni = 0\nfinish = false\n\n1.upto(a.size-1) do |i|\n if a[i] != a[i-1]\n a[i],a[i-1] = a[i-1],a[i]\n\n finish = (a != incr) && (a != decr)\n if finish\n puts \"#{i} #{i+1}\"\n break\n end\n a[i],a[i-1] = a[i-1],a[i]\n end\nend\n\nif !finish \n puts \"-1\"\nend"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\nif n < 3\n puts \"-1\"\n exit\nend\n\nincr = a.sort\ndecr = a.sort{|x,y| y <=> x}\n\ni = 0\nfinish = false\n\n1.upto(a.size-1) do |i|\n if a[i] != a[i-1]\n a[i],a[i-1] = a[i-1],a[i]\n\n finish = (a != incr) && (a != decr)\n if finish\n puts \"#{i} #{i+1}\"\n break\n end\n a[i],a[i-1] = a[i-1],a[i]\n end\nend\n\nif !finish \n puts \"-1 \"\nend"}], "negative_code": [{"source_code": "def gao(x, y)\n\treturn [-1] if x.size == 2\n\ta, b = {}, {}\n\tx.each_index do |i|\n\t\tif x[i] == y[i]\n\t\t\ta.has_key?(x[i]) ? a[x[i]] << i : a[x[i]] = [i]\n\t\telse\n\t\t\tb.has_key?(x[i]) ? b[x[i]] << i : b[x[i]] = [i]\n\t\tend\n\tend\n\tua, ub = a.keys.uniq, b.keys.uniq\n\tif ub.size >= 3 || ub.size == 2 && b[ub[0]].size + b[ub[1]].size > 2\n\t\t[b[ub[0]][0] + 1, b[ub[1]][0] + 1]\n\telsif ua.size >= 2\n\t\tif ua.size == 2\n\t\t\ts, t = a[ua[0]][0] + 1, a[ua[1]][0] + 1\n\t\t\ts = a[ua[0]][1] if (s == 1 || s == x.size) && a[ua[0]].size > 1 \n\t\t\tt = a[ua[1]][1] if (t == 1 || t == x.size) && a[ua[1]].size > 1 \n\t\t\t[s, t]\n\t\telse\n\t\t\t[a[ua[1]][0] + 1, a[ua[2]][0] + 1]\n\t\tend\n\telsif ub.size > 0 && ua.size > 0\n\t\tub[0] != ua[0] ? [b[ub[0]][0] + 1, a[ua[0]][0] + 1] : [b[ub[1]][0] + 1, a[ua[0]][0] + 1]\n\telse\n\t\t[-1]\n\tend\nend\n\nn = gets.to_i\nx = gets.split.map(&:to_i)\nr = gao(x, x.sort)\nputs r.size == 1 ? gao(x, x.sort.reverse) : r.join(\" \")\n"}, {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\n\nif n == 2\n\tputs \"-1\"\n\texit 0\nend\n\nmn = x.min\nk = x.index(mn)\nlmx = x[0..k-1].max\nrmx = x[k+1..-1].max\nif 0 < k && k + 1 < n && lmx > mn && rmx > mn\n\tputs \"#{x[0..k-1].index(lmx)+1} #{x[k+1..-1].index(rmx)+1}\"\n\texit 0\nend\n\nmx = x.max\nk = x.index(mx)\nlmn = x[0..k-1].min\nrmn = x[k+1..-1].min\nif 0 < k && k + 1 < n && lmn < mx && rmn < mx\n\tputs \"#{x[0..k-1].index(lmn)+1} #{x[k+1..-1].index(rmn)+1}\"\n\texit 0\nend\n\nif mn == mx\n\tputs -1\n\texit 0\nend\n\nx[1..-2].each_with_index do |v, i|\n\tif v != x[0]\n\t\tputs \"1 #{i+2}\"\n\t\texit 0\n\tend\n\tif v != x[-1]\n\t\tputs \"#{i+2} #{n}\"\n\t\texit 0\n\tend\nend\n\nputs -1\n"}, {"source_code": "def gao(x, y)\n\treturn [-1] if x.size == 2\n\ta, b = {}, {}\n\tx.each_index do |i|\n\t\tif x[i] == y[i]\n\t\t\ta.has_key?(x[i]) ? a[x[i]] << i : a[x[i]] = [i]\n\t\telse\n\t\t\tb.has_key?(x[i]) ? b[x[i]] << i : b[x[i]] = [i]\n\t\tend\n\tend\n\tua, ub = a.keys.uniq.sort, b.keys.uniq.sort\n\tif ub.size >= 3 || ub.size == 2 && b[ub[0]].size + b[ub[1]].size > 2\n\t\t[b[ub[0]][0] + 1, b[ub[1]][0] + 1]\n\telsif ua.size >= 2\n\t\tif ua.size == 2\n\t\t\ts, t = a[ua[0]][0] + 1, a[ua[1]][0] + 1\n\t\t\ts = a[ua[0]][1] + 1 if (s == 1 || s == x.size) && a[ua[0]].size > 1 \n\t\t\tt = a[ua[1]][1] + 1 if (t == 1 || t == x.size) && a[ua[1]].size > 1 \n\t\t\t[s, t]\n\t\telse\n\t\t\t[a[ua[1]][0] + 1, a[ua[2]][0] + 1]\n\t\tend\n\telsif ub.size > 0 && a[ua[0]].size > 1\n\t\ts, t = ub[0] != ua[0] ? [b[ub[0]][0] + 1, a[ua[0]][0] + 1] : [b[ub[1]][0] + 1, a[ua[0]][0] + 1]\n\t\tt = a[ua[0]][1] + 1 if t == 1 || t == x.size\n\t\t[s, t]\n\telse\n\t\t[-1]\n\tend\nend\n\nn = gets.to_i\nx = gets.split.map(&:to_i)\nr = gao(x, x.sort).sort\nputs r.size == 1 ? gao(x, x.sort.reverse) : r.join(\" \")\n"}, {"source_code": "def gao(x, y)\n\treturn [-1] if x.size == 2\n\ta, b = {}, {}\n\tx.each_index do |i|\n\t\tif x[i] == y[i]\n\t\t\ta.has_key?(x[i]) ? a[x[i]] << i : a[x[i]] = [i]\n\t\telse\n\t\t\tb.has_key?(x[i]) ? b[x[i]] << i : b[x[i]] = [i]\n\t\tend\n\tend\n\tua, ub = a.keys.uniq, b.keys.uniq\n\tif ub.size >= 3 || ub.size == 2 && b[ub[0]].size + b[ub[1]].size > 2\n\t\t[b[ub[0]][0] + 1, b[ub[1]][0] + 1]\n\telsif ua.size >= 2\n\t\tif ua.size == 2\n\t\t\ts, t = a[ua[0]][0] + 1, a[ua[1]][0] + 1\n\t\t\ts = a[ua[0]][1] + 1 if (s == 1 || s == x.size) && a[ua[0]].size > 1 \n\t\t\tt = a[ua[1]][1] + 1 if (t == 1 || t == x.size) && a[ua[1]].size > 1 \n\t\t\t[s, t]\n\t\telse\n\t\t\t[a[ua[1]][0] + 1, a[ua[2]][0] + 1]\n\t\tend\n\telsif ub.size > 0 && ua.size > 0\n\t\tub[0] != ua[0] ? [b[ub[0]][0] + 1, a[ua[0]][0] + 1] : [b[ub[1]][0] + 1, a[ua[0]][0] + 1]\n\telse\n\t\t[-1]\n\tend\nend\n\nn = gets.to_i\nx = gets.split.map(&:to_i)\nr = gao(x, x.sort)\nputs r.size == 1 ? gao(x, x.sort.reverse) : r.join(\" \")\n"}, {"source_code": "def gao(x, y)\n\treturn [-1] if x.size == 2\n\ta, b = [], []\n\tx.each_index { |i| x[i] == y[i] ? a << x[i] : b << x[i] }\n\ta.uniq!\n\tub = b.uniq\n\tif a.size >= 2\n\t\t[x.index(a[0]) + 1, x.index(a[1]) + 1]\n\telse\n\t\tif ub.size >= 2 && b.size >= 3\n\t\t\t[x.index(ub[0]) + 1, x.index(ub[1]) + 1]\n\t\telse\n\t\t\t[-1]\n\t\tend\n\tend\nend\n\nn = gets.to_i\nx = gets.split.map(&:to_i)\nr = gao(x, x.sort)\nputs r.size == 1 ? gao(x, x.sort.reverse) : r.join(\" \")\n"}, {"source_code": "def gao(x, y)\n\treturn [-1] if x.size == 2\n\ta, b = {}, {}\n\tx.each_index do |i|\n\t\tif x[i] == y[i]\n\t\t\ta.has_key?(x[i]) ? a[x[i]] << i : a[x[i]] = [i]\n\t\telse\n\t\t\tb.has_key?(x[i]) ? b[x[i]] << i : b[x[i]] = [i]\n\t\tend\n\tend\n\tua, ub = a.keys.uniq, b.keys.uniq\n\tif ub.size >= 3 || ub.size == 2 && b[ub[0]].size + b[ub[1]].size > 2\n\t\t[b[ub[0]][0] + 1, b[ub[1]][0] + 1]\n\telsif ua.size >= 2\n\t\tif ua.size == 2\n\t\t\ts, t = a[ua[0]][0] + 1, a[ua[1]][0] + 1\n\t\t\ts = a[ua[0]][1] + 1 if (s == 1 || s == x.size) && a[ua[0]].size > 1 \n\t\t\tt = a[ua[1]][1] + 1 if (t == 1 || t == x.size) && a[ua[1]].size > 1 \n\t\t\t[s, t]\n\t\telse\n\t\t\t[a[ua[1]][0] + 1, a[ua[2]][0] + 1]\n\t\tend\n\telsif ub.size > 0 && a[ua[0]].size > 1\n\t\tub[0] != ua[0] ? [b[ub[0]][0] + 1, a[ua[0]][0] + 1] : [b[ub[1]][0] + 1, a[ua[0]][0] + 1]\n\telse\n\t\t[-1]\n\tend\nend\n\nn = gets.to_i\nx = gets.split.map(&:to_i)\nr = gao(x, x.sort)\nputs r.size == 1 ? gao(x, x.sort.reverse) : r.join(\" \")\n"}, {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\n\nif n == 2\n\tputs \"-1\"\n\texit 0\nend\n\nmn = x.min\nk = x.index(mn)\nlmx = x[0..k-1].max\nrmx = x[k+1..-1].max\nif 0 < k && k + 1 < n && lmx > mn && rmx > mn\n\tif lmx != rmx\n\t\tputs \"#{x[0..k-1].index(lmx)+1} #{x[k+1..-1].index(rmx)+k+2}\"\n\telse\n\t\t1.upto(k-1) do |i|\n\t\t\tif x[i] != mn\n\t\t\t\tputs \"#{i+1} #{k+1}\"\n\t\t\t\texit 0\n\t\t\tend\n\t\tend\n\t\t(k+1).upto(n-1) do |i|\n\t\t\tif x[i] != mn\n\t\t\t\tputs \"#{k+1} #{i+1}\"\n\t\t\t\texit 0\n\t\t\tend\n\t\tend\n\t\tif n == 3\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\t\tputs \"1 2\"\n\tend\n\texit 0\nend\n\nmx = x.max\nk = x.index(mx)\nlmn = x[0..k-1].min\nrmn = x[k+1..-1].min\nif 0 < k && k + 1 < n && lmn < mx && rmn < mx\n\tif lmx != rmx\n\t\tputs \"#{x[0..k-1].index(lmn)+1} #{x[k+1..-1].index(rmn)+k+2}\"\n\telse\n\t\t1.upto(k-1) do |i|\n\t\t\tif x[i] != mx\n\t\t\t\tputs \"#{i+1} #{k+1}\"\n\t\t\t\texit 0\n\t\t\tend\n\t\tend\n\t\t(k+1).upto(n-1) do |i|\n\t\t\tif x[i] != mx\n\t\t\t\tputs \"#{k+1} #{i+1}\"\n\t\t\t\texit 0\n\t\t\tend\n\t\tend\n\t\tif n == 3\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\t\tputs \"1 2\"\n\tend\n\texit 0\nend\n\nif mn == mx\n\tputs -1\n\texit 0\nend\n\nx[1..-2].each_with_index do |v, i|\n\tif v != x[0]\n\t\tputs \"1 #{i+2}\"\n\t\texit 0\n\tend\n\tif v != x[-1]\n\t\tputs \"#{i+2} #{n}\"\n\t\texit 0\n\tend\nend\n\nputs -1\n"}, {"source_code": "def gao(x, y)\n\treturn [-1] if x.size == 2\n\ta, b = {}, {}\n\tx.each_index do |i|\n\t\tif x[i] == y[i]\n\t\t\ta.has_key?(x[i]) ? a[x[i]] << i : a[x[i]] = [i]\n\t\telse\n\t\t\tb.has_key?(x[i]) ? b[x[i]] << i : b[x[i]] = [i]\n\t\tend\n\tend\n\tua, ub = a.keys.uniq.sort, b.keys.uniq.sort\n\tif ub.size >= 3 || ub.size == 2 && b[ub[0]].size + b[ub[1]].size > 2\n\t\t[b[ub[0]][0] + 1, b[ub[1]][0] + 1]\n\telsif ua.size >= 2\n\t\tif ua.size == 2\n\t\t\ts, t = a[ua[0]][0] + 1, a[ua[1]][0] + 1\n\t\t\ts = a[ua[0]][1] + 1 if (s == 1 || s == x.size) && a[ua[0]].size > 1 \n\t\t\tt = a[ua[1]][1] + 1 if (t == 1 || t == x.size) && a[ua[1]].size > 1 \n\t\t\t[s, t]\n\t\telse\n\t\t\t[a[ua[1]][0] + 1, a[ua[2]][0] + 1]\n\t\tend\n\telsif ub.size > 0 && a[ua[0]].size > 1\n\t\tub[0] != ua[0] ? [b[ub[0]][0] + 1, a[ua[0]][0] + 1] : [b[ub[1]][0] + 1, a[ua[0]][0] + 1]\n\telse\n\t\t[-1]\n\tend\nend\n\nn = gets.to_i\nx = gets.split.map(&:to_i)\nr = gao(x, x.sort).sort\nputs r.size == 1 ? gao(x, x.sort.reverse) : r.join(\" \")\n"}, {"source_code": "def gao(x, y)\n\treturn [-1] if x.size == 2\n\ta, b = {}, {}\n\tx.each_index do |i|\n\t\tif x[i] == y[i]\n\t\t\ta.has_key?(x[i]) ? a[x[i]] << i : a[x[i]] = [i]\n\t\telse\n\t\t\tb.has_key?(x[i]) ? b[x[i]] << i : b[x[i]] = [i]\n\t\tend\n\tend\n\tua, ub = a.keys.uniq, b.keys.uniq\n\tif ub.size >= 3 || ub.size == 2 && b[ub[0]].size + b[ub[1]].size > 2\n\t\t[b[ub[0]][0] + 1, b[ub[1]][0] + 1]\n\telsif ua.size >= 2\n\t\tif ua.size == 2\n\t\t\ta[ua[0]].size > 1 ? [a[ua[0]][1] + 1, a[ua[1]][0] + 1] : [a[ua[0]][0] + 1, a[ua[1]][1] + 1]\n\t\telse\n\t\t\t[a[ua[1]][0] + 1, a[ua[2]][0] + 1]\n\t\tend\n\telsif ub.size > 0 && ua.size > 0\n\t\tub[0] != ua[0] ? [b[ub[0]][0] + 1, a[ua[0]][0] + 1] : [b[ub[1]][0] + 1, a[ua[0]][0] + 1]\n\telse\n\t\t[-1]\n\tend\nend\n\nn = gets.to_i\nx = gets.split.map(&:to_i)\nr = gao(x, x.sort)\nputs r.size == 1 ? gao(x, x.sort.reverse) : r.join(\" \")\n"}, {"source_code": "def gao(x, y)\n\treturn [-1] if x.size == 2\n\ta, b = {}, {}\n\tx.each_index do |i|\n\t\tif x[i] == y[i]\n\t\t\ta.has_key?(x[i]) ? a[x[i]] << i : a[x[i]] = [i]\n\t\telse\n\t\t\tb.has_key?(x[i]) ? b[x[i]] << i : b[x[i]] = [i]\n\t\tend\n\tend\n\tua, ub = a.keys.uniq.sort, b.keys.uniq.sort\n\tif ub.size >= 3 || ub.size == 2 && b[ub[0]].size + b[ub[1]].size > 2\n\t\t[b[ub[0]][0] + 1, b[ub[1]][0] + 1]\n\telsif ua.size >= 2\n\t\tif ua.size == 2\n\t\t\ts, t = a[ua[0]][0] + 1, a[ua[1]][0] + 1\n\t\t\ts = a[ua[0]][1] + 1 if (s == 1 || s == x.size) && a[ua[0]].size > 1 \n\t\t\tt = a[ua[1]][1] + 1 if (t == 1 || t == x.size) && a[ua[1]].size > 1 \n\t\t\t[s, t]\n\t\telse\n\t\t\t[a[ua[1]][0] + 1, a[ua[2]][0] + 1]\n\t\tend\n\telsif ub.size > 0 && a[ua[0]].size > 1\n\t\tub[0] != ua[0] ? [b[ub[0]][0] + 1, a[ua[0]][0] + 1] : [b[ub[1]][0] + 1, a[ua[0]][0] + 1]\n\telse\n\t\t[-1]\n\tend\nend\n\nn = gets.to_i\nx = gets.split.map(&:to_i)\nr = gao(x, x.sort)\nputs r.size == 1 ? gao(x, x.sort.reverse) : r.join(\" \")\n"}], "src_uid": "2ae4d2ca09f28d10fa2c71eb2abdaa1c"} {"source_code": "# first steps\n\nn, n1, n2 = gets.split(' ')\na = gets.split(' ')\n\nn = n.to_i\ni = 0\nwhile i < n\n\ta[i] = a[i].to_i\n\ti += 1\nend\n\nn1 = n1.to_i\nn2 = n2.to_i\n\na = a.sort {|x, y| x.to_i <=> y.to_i}\na = a.reverse\n\nif n1 > n2\n\ttemp = n2\n\tn2 = n1\n\tn1 = temp\nend\n\ncnt1, cnt2 = [0, 0]\n\ni = 0\nn1.times do\n\tcnt1 += a[i].to_i\n\ti += 1\nend\ni = n1\nn2.times do\n\tcnt2 += a[i].to_i\n\ti += 1\nend\n#puts a.join(', ')\n#puts cnt1.to_s + ' ' + cnt2.to_s\nputs cnt1.to_f / n1.to_f + cnt2.to_f / n2.to_f\n\n\n\n", "positive_code": [{"source_code": "n, n1, n2 = gets.split.map(&:to_i)\ndata = gets.split.map(&:to_i)\n\ndata.sort! { |x, y| y <=> x }\nn1, n2 = [n1,n2].minmax\n\nans = data[0,n1].reduce(0,:+).to_f / n1.to_f + data[n1,n2].reduce(0,:+).to_f / n2.to_f\np ans"}], "negative_code": [], "src_uid": "822e8f394a59329fa05c96d7fb35797e"} {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2 {}, teamb => {}}\n\nn = STDIN.gets.chomp.to_i\n\nn.times do\n t, ha, num, yr = STDIN.gets.chomp.split(/ /)\n team = ha == 'h' ? teama : teamb\n\n if h[team].has_key?(num) && h[team][num] == 2\n # nothing\n elsif h[team].has_key?(num) && h[team][num] == 1\n print \"#{team} #{num} #{t}\\n\"\n h[team][num] = 2\n elsif !h[team].has_key?(num)\n if yr == 'r'\n print \"#{team} #{num} #{t}\\n\"\n h[team][num] = 2\n else\n h[team][num] = 1\n end\n end\nend\n"}, {"source_code": "name=[gets.chomp,gets.chomp]\nfoul=[{},{}]\ndone=[{},{}]\ngets.to_i.times{\n time,team,n,type=gets.split\n team_n=team==?h?0:1\n if foul[team_n][n] || type==?r\n unless done[team_n][n]\n puts [name[team_n],n,time]*\" \"\n done[team_n][n]=true\n end\n else\n foul[team_n][n]=true\n end\n}\n"}, {"source_code": "home_team = gets.chomp\naway_team = gets.chomp\nN = gets.to_i\nused = {}\nred = {}\nwhile $_ = gets do\n t_, team, m_, type = $_.split\n t = t_.to_i\n m = m_.to_i\n if red[\"#{team}:#{m}\"]\n next\n end\n if type == \"r\" || used[\"#{team}:#{m}\"] then\n if team == \"h\"\n print home_team\n else\n print away_team\n end\n print \" #{m} #{t}\\n\"\n red[\"#{team}:#{m}\"] = true\n end\n used[\"#{team}:#{m}\"] = true\nend\n"}, {"source_code": "name=[gets.chomp,gets.chomp]\nfoul=[{},{}]\ndone=[{},{}]\ngets.to_i.times{\n time,team,n,type=gets.split\n team_n=team==?h?0:1\n if foul[team_n][n] || type==?r\n unless done[team_n][n]\n puts [name[team_n],n,time]*\" \"\n done[team_n][n]=true\n end\n else\n foul[team_n][n]=true\n end\n}\n"}, {"source_code": "#!/usr/bin/ruby\nhome = STDIN.gets.chomp\naway = STDIN.gets.chomp\nn = STDIN.gets.chomp.to_i\nmarked = {'a' => [], 'h' => []}\nteams = {'a' => away, 'h' => home}\nn.times do\n tokens = STDIN.gets.chomp.split(' ')\n minute = tokens[0].to_i\n team = tokens[1]\n player = tokens[2].to_i\n card = tokens[3]\n marked[team][player] = 0 if not marked[team][player]\n next if marked[team][player] > 1\n if card == 'r' or marked[team][player] == 1\n marked[team][player] = 2\n puts \"#{teams[team]} #{player} #{minute}\"\n else\n marked[team][player] += 1\n end\nend\n"}, {"source_code": "a=Array.new(105,0)\nb=Array.new(105,0)\nsz=Array.new\nsta=gets.to_s\nstb=gets.to_s\nn=gets.to_i\nfor i in 1..n\n stc=gets.to_s\n sz=stc.split\n if sz[3]=='y'\n tr=1\n elsif sz[3]==\"r\"\n tr=2\n end\n if sz[1]==\"h\"\n t=sz[2].to_i\n if a[t]>=2\n next\n end\n a[t]+=tr\n if a[t]>=2\n print sta.chomp\n print \" \"\n print t\n print \" \"\n puts sz[0]\n end\n elsif sz[1]==\"a\"\n t=sz[2].to_i\n if b[t]>=2\n next\n end\n b[t]+=tr\n if b[t]>=2\n print stb.chomp\n print \" \"\n print t\n print \" \"\n puts sz[0]\n end\n end\nend"}, {"source_code": "# 493A\n\nclass Foul\n include Comparable\n attr :time\n\n def initialize(player, time, team)\n @player = player\n @time = time.to_i\n @team = team\n end\n\n def <=>(another)\n time <=> another.time\n end\n\n def to_s\n [@team, @player, @time].join(' ')\n end\nend\n\nnames = {h: gets.chomp, a: gets.chomp}\ncards = {h: {y: {}, r: {}}, a: {y: {}, r: {}}}\ngets.to_i.times do\n time, _team, player, card_colour = gets.chomp.split\n team = _team.to_sym\n unless cards[team][:r].include?(player)\n if card_colour == 'r'\n cards[team][:r][player] = time\n else\n if cards[team][:y].include?(player)\n cards[team][:r][player] = time\n else\n cards[team][:y][player] = time\n end\n end\n end\nend\n\nfouls = []\n[:h, :a].each { |c| cards[c][:r].each { |k, v| fouls << Foul.new(k, v, names[c]) } }\nfouls.sort.each { |foul| puts foul }"}, {"source_code": "home = gets.chomp\naway = gets.chomp\na = {}\narry = []\nn = Integer(gets)\nfor j in 1..n\n arry[j] = gets.split(\" \")\n arry[j].each { |arr| arr.chomp }\nend\nfor i in 1..n\n if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]!= 'r') && arry[i][3] == 'r') || ( a[arry[i][1]] && a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))\n if arry[i][1] == 'a'\n puts \"#{away} #{arry[i][2]} #{arry[i][0]}\"\n else\n puts \"#{home} #{arry[i][2]} #{arry[i][0]}\"\n end\n \n if a[arry[i][1]] ==nil\n a.merge!( arry[i][1] => {} )\n end\n\n if a[arry[i][1]][arry[i][2]] == 'y'\n a[arry[i][1]][arry[i][2]] = 'r'\n end\n\n if a[arry[i][1]][arry[i][2]] == nil\n a[arry[i][1]].merge!( arry[i][2] => arry[i][3] ) \n end\n\n end\n \n if a[arry[i][1]] ==nil \n a.merge!( arry[i][1] => {} )\n end\n if a[arry[i][1]][arry[i][2]] == nil \n a[arry[i][1]].merge!( arry[i][2] => arry[i][3] )\n end\nend\n"}, {"source_code": "h = gets.chomp\na = gets.chomp\nn = gets.to_i\nhash = {}\nprocessed = {}\nresult = []\nn.times do\n m,team,player,card = gets.chomp.split\n if card == 'r'\n if !processed[[team,player]]\n result << [team,player,m.to_i]\n processed[[team,player]] = true\n end\n else\n if hash[[team,player]]\n if !processed[[team,player]]\n result << [team,player,m.to_i]\n processed[[team,player]] = true\n end\n else\n hash[[team,player]] = true\n end\n end\nend\nresult = result.sort_by {|x| x[2]}\nresult.each do |team,player,minute|\n puts \"#{team == 'h' ? h : a} #{player} #{minute}\"\nend"}], "negative_code": [{"source_code": "h = gets.chomp\na = gets.chomp\nn = gets.to_i\nhash = {}\nresult = []\nn.times do\n m,team,player,card = gets.chomp.split\n if card == 'r'\n result << [team,player,m.to_i]\n else\n if hash[[team,player]]\n result << [team,player,m.to_i]\n else\n hash[[team,player]] = true\n end\n end\nend\nresult = result.sort_by {|x| x[2]}\nresult.each do |team,player,minute|\n puts \"#{team == 'h' ? h : a} #{player} #{minute}\"\nend"}, {"source_code": "h = gets.chomp\na = gets.chomp\nn = gets.to_i\nhash = {}\nresult = []\nn.times do\n m,team,player,card = gets.chomp.split\n if card == 'r'\n result << [team,player,m.to_i]\n hash.delete([team,player]) if hash[[team,player]]\n else\n if hash[[team,player]]\n result << [team,player,m.to_i]\n hash.delete([team,player])\n else\n hash[[team,player]] = true\n end\n end\nend\nresult = result.sort_by {|x| x[2]}\nresult.each do |team,player,minute|\n puts \"#{team == 'h' ? h : a} #{player} #{minute}\"\nend"}, {"source_code": "h = gets.chomp\na = gets.chomp\nn = gets.to_i\nhash = {}\nresult = []\nn.times do\n m,team,player,card = gets.chomp.split\n if card == 'r'\n result << [team,player,m]\n else\n if hash[[team,player]]\n result << [team,player,m]\n else\n hash[[team,player]] = true\n end\n end\nend\nresult = result.sort_by {|x| x[2]}\nresult.each do |team,player,minute|\n puts \"#{team == 'h' ? h : a} #{player} #{minute}\"\nend"}, {"source_code": "h = gets.chomp\na = gets.chomp\nn = gets.to_i\nhash = {}\nresult = []\nn.times do\n m,team,player,card = gets.chomp.split\n if card == 'r'\n result << [team,player,m.to_i]\n else\n if hash[[team,player]]\n result << [team,player,[m.to_i,hash[[team,player]]].max]\n else\n hash[[team,player]] = m.to_i\n end\n end\nend\nresult = result.sort_by {|x| x[2]}\nresult.each do |team,player,minute|\n puts \"#{team == 'h' ? h : a} #{player} #{minute}\"\nend"}, {"source_code": "team_a = STDIN.readline.strip\nteam_b = STDIN.readline.strip\nn = STDIN.readline.to_i\nfoul = {}\nn.times do\n tokens = STDIN.readline.split\n time, player, color = tokens[0].to_i, tokens[2].to_i, tokens[3]\n team = tokens[1] == 'h' ? team_a : team_b\n key = [player, team]\n if color == 'y'\n if foul[key] == 1\n puts '%s %d %d' % [team, player, time]\n foul[key] += 1\n else\n foul[key] = 1\n end\n else\n if not foul.include? key\n puts '%s %d %d' % [team, player, time]\n foul[key] = 2\n else\n if foul[key] == 1\n puts '%s %d %d' % [team, player, time]\n end\n foul[key] += 1\n end\n end\nend\n"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\n\nclass Player\n attr_reader :time, :team, :b_num, :card\n\n def initialize(l)\n @time = l[0].to_i\n @team = l[1]\n @b_num = l[2].to_i\n @card = l[3]\n end\n\n def update(p)\n @time = p.time\n @card = 'r'\n end\n\nend\n\nclass Players\n def initialize\n @faul_receivers = []\n end\n\n def <<(p)\n if @faul_receivers.length < 1\n @faul_receivers << p\n else\n update = false\n @faul_receivers.each do |r|\n update= true if r.team == p.team and r.b_num == p.b_num\n if update\n r.update(p)\n break\n end\n end\n @faul_receivers << p unless update\n end\n end\n\n def red_card_list\n reds = []\n @faul_receivers.each do |p|\n reds << p if p.card == 'r'\n end\n reds.sort_by! { |p| p.time }\n return reds\n end\n\n def each(&block)\n @faul_receivers.each &block\n end\nend\n\nh, a, n = gets.chomp, gets.chomp, gets.chomp.to_i\n\np_l = Players.new\nn.times do\n l = gets.chomp.split(' ')\n p = Player.new(l)\n p_l << p\nend\n\np_l.each do |p|\n if p.card == \"r\"\n t = p.team == \"a\" ? a : h\n puts \"#{t} #{p.b_num} #{p.time}\"\n end\nend\n"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\n\nclass Player\n attr_reader :time, :team, :b_num, :card\n\n def initialize(l)\n @time = l[0].to_i\n @team = l[1]\n @b_num = l[2].to_i\n @card = l[3]\n end\n\n def update(p)\n @time = p.time\n @card = 'r'\n end\n\nend\n\nclass Players\n def initialize\n @faul_receivers = []\n end\n\n def <<(p)\n if @faul_receivers.length < 1\n @faul_receivers << p\n else\n update = false\n @faul_receivers.each do |r|\n update= true if r.team == p.team and r.b_num == p.b_num\n if update\n r.update(p)\n break\n end\n end\n @faul_receivers << p unless update\n end\n end\n\n def red_card_list\n reds = []\n @faul_receivers.each do |p|\n reds << p if p.card == 'r'\n end\n\n reds.sort_by! { |p| p.time }\n return reds\n end\n\n def each(&block)\n @faul_receivers.each &block\n end\nend\n\nh, a, n = gets.chomp, gets.chomp, gets.chomp.to_i\n\np_l = Players.new\nn.times do\n l = gets.chomp.split(' ')\n p = Player.new(l)\n p_l << p\nend\n\np_l.red_card_list.each do |p|\n t = p.team == \"a\" ? a : h\n puts \"#{t} #{p.b_num} #{p.time}\"\nend\n"}, {"source_code": "home_team = gets.chomp\naway_team = gets.chomp\nN = gets.to_i\nused = {}\nwhile $_ = gets do\n t_, team, m_, type = $_.split\n t = t_.to_i\n m = m_.to_i\n if type == \"r\" || used[\"#{team}:#{m}\"] then\n if team == \"h\"\n print home_team\n else\n print away_team\n end\n print \" #{m} #{t}\\n\"\n end\n used[\"#{team}:#{m}\"] = true\nend\n"}, {"source_code": "a=Array.new(105,0)\nb=Array.new(105,0)\nsz=Array.new\nsta=gets.to_s\nstb=gets.to_s\nn=gets.to_i\nfor i in 1..n\n stc=gets.to_s\n sz=stc.split\n if sz[3]=='y'\n tr=1\n elsif sz[3]==\"r\"\n tr=2\n end\n if sz[1]==\"h\"\n t=sz[2].to_i\n a[t]+=tr\n if a[t]>=2\n print sta.chomp\n print \" \"\n print t\n print \" \"\n puts sz[0]\n end\n elsif sz[1]==\"a\"\n t=sz[2].to_i\n b[t]+=tr\n if b[t]>=2\n print stb.chomp\n print \" \"\n print t\n print \" \"\n puts sz[0]\n end\n end\nend"}, {"source_code": "# 493A\n\nclass Foul\n include Comparable\n attr :time\n\n def initialize(player, time, team)\n @player = player\n @time = time\n @team = team\n end\n\n def <=>(another)\n time <=> another.time\n end\n\n def to_s\n [@team, @player, @time].join(' ')\n end\nend\n\nnames = {h: gets.chomp, a: gets.chomp}\ncards = {h: {y: {}, r: {}}, a: {y: {}, r: {}}}\ngets.to_i.times do\n time, _team, player, card_colour = gets.chomp.split\n team = _team.to_sym\n unless cards[team][:r].include?(player)\n if card_colour == 'r'\n cards[team][:r][player] = time\n else\n if cards[team][:y].include?(player)\n cards[team][:r][player] = time\n else\n cards[team][:y][player] = time\n end\n end\n end\nend\n\nfouls = []\n[:h, :a].each { |c| cards[c][:r].each { |k, v| fouls << Foul.new(k, v, names[c]) } }\nfouls.sort.each { |foul| puts foul }"}, {"source_code": "home = gets.chomp\naway = gets.chomp\na = {}\narry = []\nn = Integer(gets)\nfor j in 1..n\n arry[j] = gets.split(\" \")\n arry[j].each { |arr| arr.chomp }\nend\nfor i in 1..n\n if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]!= 'r') && arry[i][3] == 'r') || ( a[arry[i][1]] && a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))\n if arry[i][1] == 'a'\n puts \"#{away} #{arry[i][2]} #{arry[i][0]}\"\n else\n puts \"#{home} #{arry[i][2]} #{arry[i][0]}\"\n end\n if a[arry[i][1]] ==nil\n a.merge!( arry[i][1] => {} )\n end\n if a[arry[i][1]][arry[i][2]] == nil || a[arry[i][1]][arry[i][2]] == 'y'\n a[arry[i][1]][arry[i][2]] = 'r'\n end\n end\n \n if a[arry[i][1]] ==nil\n a.merge!( arry[i][1] => {} )\n end\n a[arry[i][1]].merge!( arry[i][2] => arry[i][3] )\nend"}, {"source_code": "home = gets.chomp\naway = gets.chomp\na = {}\narry = []\nn = Integer(gets)\nfor j in 1..n\n arry[j] = gets.split(\" \")\n arry[j].each { |arr| arr.chomp }\nend\nfor i in 1..n\n if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]==nil) && arry[i][3] == 'r') || ( a[arry[i][1]] && a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))\n if arry[i][1] == 'a'\n puts \"#{away} #{arry[i][2]} #{arry[i][0]}\"\n else\n puts \"#{home} #{arry[i][2]} #{arry[i][0]}\"\n end\n end\n\n if a[arry[i][1]] ==nil\n a.merge!( arry[i][1] => {} )\n end\n a[arry[i][1]].merge!( arry[i][2] => arry[i][3] )\nend"}, {"source_code": "home = gets.chomp\naway = gets.chomp\na = {}\narry = []\nn = Integer(gets)\nfor j in 1..n\n arry[j] = gets.split(\" \")\n arry[j].each { |arr| arr.chomp }\nend\nfor i in 1..n\n if ((a[arry[i][1]]==nil && arry[i][3] == 'r') || ( a[arry[i][1]] && a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))\n if arry[i][1] == 'a'\n puts \"#{away} #{arry[i][2]} #{arry[i][0]}\"\n else\n puts \"#{home} #{arry[i][2]} #{arry[i][0]}\"\n end\n end\n\n if a[arry[i][1]] ==nil\n a.merge!( arry[i][1] => {} )\n end\n a[arry[i][1]].merge!( arry[i][2] => arry[i][3] )\nend"}, {"source_code": "home = gets.chomp\naway = gets.chomp\na = {}\narry = []\nn = Integer(gets)\nfor j in 1..n\n arry[j] = gets.split(\" \")\n arry[j].each { |arr| arr.chomp }\nend\nfor i in 1..n\n if (a[arry[i][1]] && a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y') || arry[i][3] == 'r'\n if arry[i][1] == 'a'\n puts \"#{away} #{arry[i][2]} #{arry[i][0]}\"\n else\n puts \"#{home} #{arry[i][2]} #{arry[i][0]}\"\n end\n end\n\n if a[arry[i][1]] ==nil\n a.merge!( arry[i][1] => {} )\n end\n a[arry[i][1]].merge!( arry[i][2] => arry[i][3] )\nend\n"}, {"source_code": "home = gets.chomp\naway = gets.chomp\na = {}\narry = []\nn = Integer(gets)\nfor j in 1..n\n arry[j] = gets.split(\" \")\n arry[j].each { |arr| arr.chomp }\nend\nfor i in 1..n\n if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]!= 'r') && arry[i][3] == 'r') || ( a[arry[i][1]] && a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))\n if arry[i][1] == 'a'\n puts \"#{away} #{arry[i][2]} #{arry[i][0]}\"\n else\n puts \"#{home} #{arry[i][2]} #{arry[i][0]}\"\n end\n\n if a[arry[i][1]] ==nil\n a.merge!( arry[i][1] => {} )\n end\n\n if a[arry[i][1]][arry[i][2]] == 'y'\n a[arry[i][1]][arry[i][2]] = 'r'\n end\n\n if a[arry[i][1]][arry[i][2]] == nil\n a[arry[i][1]].merge!( arry[i][2] => arry[i][3] )\n end\n\n end\n \n if a[arry[i][1]] ==nil\n a.merge!( arry[i][1] => {} )\n end\n a[arry[i][1]].merge!( arry[i][2] => arry[i][3] )\nend\n"}, {"source_code": "home = gets.chomp\naway = gets.chomp\na = {}\narry = []\nn = Integer(gets)\nfor j in 1..n\n arry[j] = gets.split(\" \")\n arry[j].each { |arr| arr.chomp }\nend\nfor i in 1..n\n if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]!= 'r') && arry[i][3] == 'r') || ( a[arry[i][1]] && a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))\n if arry[i][1] == 'a'\n puts \"#{away} #{arry[i][2]} #{arry[i][0]}\"\n else\n puts \"#{home} #{arry[i][2]} #{arry[i][0]}\"\n end\n if a[arry[i][1]] ==nil\n a.merge!( arry[i][1] => {} )\n end\n a[arry[i][1]].merge!( arry[i][2] => 'r' )\n end\n\n if a[arry[i][1]] ==nil\n a.merge!( arry[i][1] => {} )\n end\n a[arry[i][1]].merge!( arry[i][2] => arry[i][3] )\nend"}, {"source_code": "home = gets.chomp\naway = gets.chomp\na = {}\narry = []\nn = Integer(gets)\nfor j in 1..n\n arry[j] = gets.split(\" \")\n arry[j].each { |arr| arr.chomp }\nend\nfor i in 1..n\n if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]!= 'r') && arry[i][3] == 'r') || ( a[arry[i][1]] && a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))\n if arry[i][1] == 'a'\n puts \"#{away} #{arry[i][2]} #{arry[i][0]}\"\n else\n puts \"#{home} #{arry[i][2]} #{arry[i][0]}\"\n end\n end\n\n if a[arry[i][1]] ==nil\n a.merge!( arry[i][1] => {} )\n end\n a[arry[i][1]].merge!( arry[i][2] => arry[i][3] )\nend"}], "src_uid": "b1f78130d102aa5f425e95f4b5b3a9fb"} {"source_code": "#\u043f\u0440\u043e\u043a\u0430\u0442 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434\u043e\u0432\n# \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0434\u0432\u0430 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u043b\u0430 n \u0438 k (2\u2009\u2264\u2009n\u2009\u2264\u20091\u2009000, 1\u2009\u2264\u2009k\u2009\u2264\u2009100\u2009000) \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u043b\u043e\u043f\u0440\u043e\u043a\u0430\u0442\u043e\u0432 \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0410\u0440\u043a\u0430\u0434\u0438\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0435\u0445\u0430\u0442\u044c \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434\u0435.\n\n# \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c x1,\u2009x2,\u2009...,\u2009xn (0\u2009\u2264\u2009x1\u2009<\u2009x2\u2009<\u2009...\u2009<\u2009xn\u2009\u2264\u2009100\u2009000) \u2014 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0442\u043e\u0447\u0435\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u0435\u043b\u043e\u043f\u0440\u043e\u043a\u0430\u0442\u044b. \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0432\u0435\u043b\u043e\u043f\u0440\u043e\u043a\u0430\u0442\u043e\u0432 \u0437\u0430\u0434\u0430\u043d\u044b \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f.\n\n\n#INPUTS\n@stations, @max_distance = gets.split(\" \").map(&:to_i)\n@station_points = gets.split(\" \").map{ |station| {position: station.to_i, best: nil} }\n\n#TEST INPUTS\n# line1 = \"4 4\"\n# line2 = \"3 6 8 10\"\n\n# line1 = \"2 9\"\n# line2 = \"10 20\"\n\n# line1 = \"12 3\"\n# line2 = \"4 6 7 9 10 11 13 15 17 18 20 21\"\n\n# a = [38235, 17715, 62905, 21509, 29239, 18836, 58480, 23037, 59747, 22458, 7169, 37273, 78523, 54847, 5914, 86745, 58852, 62964, 34206, 27558, 86381, 90378, 67775, 38965, 78249, 66297, 99230, 19153, 31301, 8075, 7358, 76573, 32187, 88305, 18409, 57871, 6050, 59408, 86127, 4259, 70090, 87624, 69821, 88099, 4548, 73216, 30769, 81766, 16352, 43772, 60186, 97945, 79806, 95082, 73905, 79814, 82127, 26822, 42526, 4828, 59346, 37890, 32496, 64256, 34645, 39744, 88906, 48262, 33521, 68322, 73307, 93803, 25390, 26401, 78611, 56264, 33713, 42690, 37055, 73883, 68379, 50013, 4915, 1215, 46954, 48545, 52311, 46857, 10257, 82176, 90245, 59561, 47666, 20042, 47654, 31912, 37474, 45998, 61081, 7806, 47181, 52895, 77347, 48647, 1761, 49358, 24027, 36641, 23307, 64326, 34254, 73211, 5921, 53367, 81298, 85162, 20223, 60994, 62814, 78391, 92798, 70087, 20094, 67371, 99799, 94506, 49979, 97538, 71809, 71002, 29026, 55075, 73222, 90792, 77220, 88800, 77133, 79728, 36837, 83775, 71102, 53016, 24520, 92963, 51879, 96196, 12584, 70425, 46155, 59586, 57720, 80063, 23247, 43429, 98993, 8200, 18108, 10435, 26643, 23809, 76335, 59016, 35179, 71403, 54246, 1076, 40645, 31640, 4415, 52250, 35986, 93167, 80887, 82290, 28909, 16133, 48703, 92033, 93575, 84691, 42070, 12680, 19187, 62112, 13693, 41131, 71006, 13924, 402, 40549, 59684, 44324, 14271, 60512, 19024, 41555, 47046, 47606, 77827, 97111, 38494, 67337, 57488, 4641, 92574, 82853, 48619, 66657, 16737, 84864, 40193, 85792, 31205, 42867, 9024, 27651, 72243, 18563, 9794, 94166, 938, 91672, 13282, 61538, 62968, 92880, 61980, 12409, 96164, 10782, 55050, 92250, 4907, 44831, 88387, 37614, 4665, 29486, 21148, 8664, 83064, 87790, 50834, 9146, 31868, 52548, 41634, 86355, 25801, 19377, 53224, 25196, 3263, 97445, 9839, 29706, 49679, 81606, 59972, 64688, 94675, 57673, 29911, 13030, 76793, 51804, 35262, 50587, 49493, 44741, 59973, 23933, 61380, 85849, 51602, 26425, 68820, 89178, 71353, 78432, 773, 21907, 97867, 66943, 93267, 20723, 55683, 37921, 49120, 46072, 9940, 80392, 89995, 1893, 94005, 67076, 68648, 24006, 58272, 39295, 98050, 47177, 45342, 16855, 29811, 199, 54699, 49018, 83826, 71178, 34751, 30983, 35233, 53715, 53985, 75699, 17713, 10543, 45022, 52862, 27059, 36071, 66112, 83755, 12975, 48302, 56792, 59626, 26467, 57401, 65453, 19781, 13208, 224, 44663, 72527, 88113, 21646, 7259, 55910, 83946, 78162, 93071, 77445, 56803, 92239, 37532, 95893, 8629, 95021, 92777, 24538, 16296, 84167, 79387, 30429, 55945, 20397, 39313, 43399, 62103, 5507, 27513, 3156, 81333, 69703, 14340, 56684, 20557, 12173, 47984, 52534, 38329, 66255, 72144, 89859, 28852, 52764, 90487, 992, 94416, 89497, 74156, 49796, 93491, 19115, 80284, 14971, 10802, 47089, 11528, 22194, 37048, 74263, 20271, 5392, 24535, 19113, 16914, 15896, 53382, 40024, 42530, 83852, 61195, 28372, 44582, 41497, 9813, 23656, 45868, 25412, 94618, 75949, 89158, 20728, 71330, 65695, 23271, 46358, 7199, 63901, 75391, 80653, 3282, 96343, 37179, 66911, 6424, 87430, 64284, 14096, 4203, 46531, 21798, 78041, 40937, 89470, 11268, 76610, 24982, 75051, 3957, 72203, 90065, 34392, 63445, 22373, 91785, 53234, 43874, 53062, 15149, 93421, 2793, 47724, 47083, 99063, 60303, 79662, 86857, 88932, 10844, 33743, 7967, 21563, 47476, 4934, 56544, 5006, 57431, 89466, 37055, 64296, 30840, 54008, 89467, 69266, 31708, 39655, 32743, 74280, 48017, 9279, 43688, 47363, 15209, 81075, 15335, 14578, 29203, 89117, 42833, 97717, 57456, 21400, 77173, 95519, 26786, 39341, 92934, 1280, 72417, 10317, 54741, 83761, 48399, 5220, 5024, 36873, 75453, 85364, 34698, 31607, 54100, 34063, 10967, 6872, 28350, 43561, 13302, 16019, 49633, 9560, 10291, 82567, 32445, 58932, 54233, 46104, 82890, 22881, 78295, 27813, 40889, 17291, 88157, 22767, 82325, 80685, 5110, 84690, 12167, 31771, 73314, 86804, 74600, 91898, 7983, 28908, 90319, 36048, 11283, 25647, 66199, 15741, 16999, 25810, 95730, 61524, 18598, 95172, 21278, 28598, 62565, 25903, 60155, 9214, 9313, 47236, 79206, 62560, 58816, 57956, 60083, 34712, 48156, 20779, 80408, 18104, 61902, 78244, 58403, 8346, 5624, 37552, 31015, 15943, 14880, 52323, 25108, 17552, 75775, 12924, 63725, 31170, 31674, 7873, 19699, 50845, 80003, 13333, 56168, 87968, 26217, 60555, 99988, 17934, 70683, 54942, 37409, 66011, 2451, 8061, 90625, 90169, 89215, 16330, 20838, 87567, 76529, 7996, 57443, 70513, 88280, 29803, 64095, 26534, 28764, 45769, 149, 6987, 86142, 77031, 14971, 94491, 24361, 93080, 24309, 85772, 53725, 74597, 57757, 21546, 18534, 93346, 84701, 45127, 81895, 97413, 83725, 87737, 63159, 95225, 61836, 9710, 92334, 83515, 12998, 33411, 9629, 2696, 48699, 97233, 24289, 24909, 92873, 36552, 19682, 99082, 16285, 72991, 83874, 28790, 30669, 19434, 50764, 67623, 34229, 19784, 34090, 24636, 46318, 95363, 80109, 52825, 66324, 32994, 26977, 41287, 76954, 17009, 84574, 82033, 32556, 49215, 44621, 36624, 79791, 51454, 42077, 98309, 47712, 96079, 60105, 35198, 22298, 90226, 94149, 61615, 72987, 19231, 39398, 84435, 81886, 21922, 61513, 58727, 26465, 234, 57823, 51312, 32617, 15706, 91469, 52543, 65489, 16007, 71847, 89918, 50841, 43604, 74630, 1315, 23884, 91505, 69262, 65412, 21464, 51787, 98853, 84386, 73956, 48908, 58831, 53469, 1468, 67235, 19640, 29099, 17792, 44796, 71177, 77917, 11486, 13711, 24768, 78541, 66559, 25450, 80531, 76164, 98701, 11619, 10409, 55614, 91597, 5595, 37616, 46000, 54117, 42060, 99267, 69076, 57793, 18078, 2327, 38338, 41855, 39858, 45290, 123, 48045, 39220, 9075, 80249, 46311, 74080, 25129, 54338, 45053, 22562, 28031, 96043, 44533, 1466, 97203, 41959, 88152, 43026, 64555, 20915, 39770, 29297, 49175, 64758, 6402, 67219, 48246, 62561, 58800, 87476, 71654, 59030, 28582, 37921, 69928, 89279, 86222, 28691, 40957, 79785, 56675, 99249, 92511, 99118, 22876, 64649, 47278, 21697, 36993, 30702, 17940, 93574, 29051, 41056, 45998, 38260, 31485, 7897, 29520, 42075, 33831, 3590, 22580, 81934, 10885, 41227, 67778, 48718, 43338, 1589, 42797, 27726, 44166, 74790, 97478, 62218, 12391, 84465, 2387, 63677, 50804, 90753, 11933, 2279, 10148, 4915, 41174, 15775, 67206, 32304, 15788, 49858, 40282, 9220, 13048, 84654, 66582, 94208, 81190, 4952, 3719, 93991, 68235, 98270, 66467, 77126, 86798, 43426, 63689, 75547, 57405, 9708, 29553, 42990, 48876, 69593, 37580, 60478, 51985, 30956, 91677, 3086, 74345, 90109, 35530, 54702, 3426, 85731, 65858, 32760, 91895, 71333, 71877, 67692, 34065, 43878, 55338, 65755, 26663, 15092, 75169, 56797, 21450, 73986, 18145, 22892, 58388, 16733, 56568, 61530, 76310, 28411, 4996, 32511, 32546, 7865, 62185, 70081, 93865, 46555, 93557, 72922, 56871, 11705, 91615, 2771, 67092, 63775, 80133, 6526, 2581, 63967, 628, 61157, 29220, 88961, 96532, 76940, 271, 69155, 13879, 36153, 58814, 50559, 42630, 51483, 62747, 47579, 77360, 64899, 19085, 90239, 37058, 93828, 23766, 25428, 30558, 58157, 70815, 87508, 748, 42715, 91916, 66452, 80774, 61601, 37351, 66232, 96262, 56173, 58230, 51385, 38904, 12702, 73205, 63747, 60683, 93495].sort\n\n# line1 = \"#{a.size} 10000\"\n# line2 = a.join(\" \")\n\n# @stations, @max_distance = line1.split(\" \").map(&:to_i)\n# @station_points = line2.split(\" \").map{ |station| {position: station.to_i, best: nil} }\n\n\n\n#INITIALIZATION\nfirst_point = @station_points.first\nfirst_point[:best] = 0\ncurrent_solutions = [first_point]\n\n\nlast_node = @station_points.last\nnext_solutions = []\n\n#MAIN\n#each node is a hash with the position and shortest length to it\n\nuntil current_solutions.empty?\n\n\tnext_points = []\n\n\t# STDERR.puts \"current_solutions: \"\n\t# current_solutions.each do |a_solution|\n\t# \tSTDERR.puts \" #{a_solution.inspect}\"\n\t# end\n\n\tcurrent_solutions.each do |a_solution|\n\n\t\tnext_points += @station_points.select do |station|\n\t\t\t# STDERR.puts \"a_solution: #{a_solution}; station: #{station}\"\n\t\t\t(station[:position] > a_solution[:position]) and\n\t\t\t(station[:position] <= a_solution[:position] + @max_distance) and\n\t\t\t(station[:best].nil? or station[:best] > a_solution[:best] + 1)\n\t\tend.map { |station| station[:best] = a_solution[:best] + 1; station }\n\tend\n\t\n\tcurrent_solutions = next_points\nend\n\n\n\n#OUTPUT\nif last_node[:best].nil?\n\tputs -1\nelse\n\tputs last_node[:best]\nend\n", "positive_code": [{"source_code": "n, k = gets.split.map(&:to_i)\nxs = gets.split.map(&:to_i)\ndef get_result k, xs \n diffs=(0..xs.size-2).map do |i| xs[i+1]-xs[i]; end \n if diffs.any?{|d| d>k}\n return -1\n end\n\n diffs.inject([0]) do |memo,d|\n last = memo.pop\n if(last+d<=k)\n memo<= 0 && nw >= 0 && nh < height && nw < width && data[nh][nw,1] != \".\" then\n ans.add?(data[nh][nw,1]) \n end\n end\n end\n end\nend\np ans.size()-1\n\n\n\n\n"}, {"source_code": "fst = gets.split\nN=fst[0].to_i\nM=fst[1].to_i\nPresidentsColor=fst[2][0]\nmatrix = Array.new(N)\nN.times do |i|\n line = gets.chomp\n matrix[i] = Array.new(M)\n M.times do |j|\n matrix[i][j] = line[j]\n end\nend\ndeputies = []\nmatrix.each_index do |i|\n matrix[i].each_with_index do |c,j|\n if c==PresidentsColor\n deputies << matrix[i-1][j] if i!=0\n deputies << matrix[i+1][j] if i!=N-1\n deputies << matrix[i][j-1] if j!=0\n deputies << matrix[i][j+1] if j!=M-1\n end\n end\nend\ndeputies.uniq!\ndeputies.delete \".\"[0]\ndeputies.delete PresidentsColor\nputs deputies.size\n"}, {"source_code": "require 'set'\n\nn, m, p_desk = gets.split\nn = n.to_i\nm = m.to_i\n\ngrid = []\nn.times do |index|\n\trow = gets.chomp.split('')\n\tgrid << row\nend\n\ndesks = Set.new\n0.upto(n - 1) do |x|\n\t0.upto(m - 1) do |y|\n\t\tnext if grid[x][y] == ?. or grid[x][y] == p_desk\n\t\tdesks << grid[x][y] if (x > 0 and grid[x - 1][y] == p_desk) || (y > 0 and grid[x][y - 1] == p_desk) || \n\t\t\t\t\t\t\t (x < n - 1 and grid[x + 1][y] == p_desk) || (y < m - 1 and grid[x][y + 1] == p_desk)\n end\nend\n\nputs desks.size"}, {"source_code": "n,m,c = gets.split(/\\s+/)\nn = n.to_i\nm = m.to_i\nc = c[0]\na = Array.new(n)\nn.times do |i|\n a[i] = gets.strip\nend\n\nh = []\n\n0.upto(n-1) do |i|\n 0.upto(m-1) do |j|\n next if a[i][j] == ?. or a[i][j] == c\n h << a[i][j] if (i > 0 and a[i-1][j] == c) || (j > 0 and a[i][j-1] == c) || \n (i < n-1 and a[i+1][j] == c) || (j < m-1 and a[i][j+1] == c)\n end\nend\n\nputs h.uniq.size"}, {"source_code": "n,m,c = gets.split(/\\s+/)\nn = n.to_i\nm = m.to_i\nc = c[0]\na = Array.new(n)\nn.times do |i|\n a[i] = gets.strip\nend\n\nh = []\n\n0.upto(n-1) do |i|\n 0.upto(m-1) do |j|\n next if a[i][j] == ?. or a[i][j] == c\n h << a[i][j] if (i > 0 and a[i-1][j] == c) || (j > 0 and a[i][j-1] == c) || \n (i < n-1 and a[i+1][j] == c) || (j < m-1 and a[i][j+1] == c)\n end\nend\n\nputs h.uniq.size"}, {"source_code": "def extractIndices(office, color)\n startingCol, endingCol, startingRow, endingRow = -1, -1, -1, -1\n office.each_with_index do |row, rIdx|\n if row.include? color\n if startingRow == -1 #we do this just for the first row\n startingCol = row.find_index(color)\n (startingCol..row.length-1).each do |idx|\n if row[idx] != color\n endingCol = idx-1\n break\n end\n end\n if endingCol == -1 \n endingCol = row.length-1\n end\n end\n startingRow = rIdx if startingRow == -1\n endingRow = rIdx if rIdx >= endingRow\n end\n end\n return startingCol, endingCol, startingRow, endingRow\nend\n\n\nn, m, color = nil, nil, nil\noffice = []\n# File.open(\"input1\", \"r\") do |file|\n# n, m, color = file.readline.split(\" \")\n# n = n.to_i\n# m = m.to_i\n# n.times do\n# office << file.readline.chomp.split(\"\")\n# end\n# end\n\nn, m, color = gets.chomp.split(\" \")\nn = n.to_i\nm = m.to_i\nn.times do\n office << gets.chomp.split(\"\")\nend\n\nstartingCol, endingCol, startingRow, endingRow = extractIndices(office, color)\ntopRow = startingRow - 1\nbottomRow = endingRow + 1\nleftCol = startingCol - 1\nrightCol = endingCol + 1\nfound = []\n\nif topRow >= 0\n topRow = office[topRow][startingCol..endingCol]\n lastFound = \".\"\n (startingCol..endingCol).each do |idx|\n next if topRow[idx-startingCol] == \".\" or topRow[idx-startingCol] == lastFound\n lastFound = topRow[idx-startingCol]\n found << lastFound\n end\nend\n\nif bottomRow < n\n bottomRow = office[bottomRow][startingCol..endingCol]\n lastFound = \".\"\n (startingCol..endingCol).each do |idx|\n next if bottomRow[idx-startingCol] == \".\" or bottomRow[idx-startingCol] == lastFound\n lastFound = bottomRow[idx-startingCol]\n found << lastFound\n end\nend\n\nif leftCol >= 0\n leftCol = office[startingRow..endingRow].map{|r| r[leftCol]}\n lastFound = \".\"\n (startingRow..endingRow).each do |idx|\n next if leftCol[idx-startingRow] == \".\" or leftCol[idx-startingRow] == lastFound\n lastFound = leftCol[idx-startingRow]\n found << lastFound\n end\nend\n\nif rightCol < m\n rightCol = office[startingRow..endingRow].map{|r| r[rightCol]}\n lastFound = \".\"\n (startingRow..endingRow).each do |idx|\n next if rightCol[idx-startingRow] == \".\" or rightCol[idx-startingRow] == lastFound\n lastFound = rightCol[idx-startingRow]\n found << lastFound\n end\nend\n\nputs \"#{found.count}\""}, {"source_code": "n, m, c = gets.chomp.split\nn = n.to_i\nm = m.to_i\nroom = Array.new\nn.times { room << gets.chomp }\nret = 0\nx = Hash.new\ndy = [0, -1, 0, 1]\ndx = [-1, 0, 1, 0]\nx[c] = true\nx[\".\"] = true\n(0...n).each do |i|\n (0...m).each do |j|\n if room[i][j] == c\n (0...(dy.length)).each do |k|\n ii, jj = i + dy[k], j + dx[k]\n next unless ii >= 0 && ii < n && jj >= 0 && jj < m\n unless x.has_key? room[ii][jj]\n x[room[ii][jj]] = true\n ret += 1\n end\n end\n end\n end\nend\n\nputs ret"}, {"source_code": "s = gets.split\n\nn = s[0].to_i\nm = s[1].to_i\n\ncol = s[2]\n\ndots = []\nmatrix = []\nn.times do |x|\n matrix << gets.chomp\n k = -1\n while k = matrix[x].index(col, k+1) do\n dots << [x, k]\n end\nend\n\nt = {}\n\ndots.size.times do |i|\n dot = dots[i]\n if dot[1]+1 < m then\n if matrix[dot[0]][dot[1]+1] != col then\n if t[matrix[dot[0]][dot[1]+1]] then\n t[matrix[dot[0]][dot[1]+1]] += 1\n else\n t[matrix[dot[0]][dot[1]+1]] = 1\n end\n end\n end\n if dot[1] > 0 then\n if matrix[dot[0]][dot[1]-1] != col then\n if t[matrix[dot[0]][dot[1]-1]] then\n t[matrix[dot[0]][dot[1]-1]] += 1\n else\n t[matrix[dot[0]][dot[1]-1]] = 1\n end\n end\n end\n if dot[0]+1 < n then\n if matrix[dot[0]+1][dot[1]] != col then\n if t[matrix[dot[0]+1][dot[1]]] then\n t[matrix[dot[0]+1][dot[1]]] += 1\n else\n t[matrix[dot[0]+1][dot[1]]] = 1\n end\n end\n end\n if dot[0] > 0 then\n if matrix[dot[0]-1][dot[1]] != col\n if t[matrix[dot[0]-1][dot[1]]] then\n t[matrix[dot[0]-1][dot[1]]] += 1\n else\n t[matrix[dot[0]-1][dot[1]]] = 1\n end\n end\n end\nend\n\nt.delete(\".\")\n\nputs t.size"}, {"source_code": "ns,ms,c = gets.chomp.split(/ /)\nn = ns.to_i\nm = ms.to_i\nar = Array.new\nfor i in 0..n-1\n\tar[i] = gets.chomp.split(//)\nend\n\ns = Hash.new\n\nfor i in 0..n-1\n\tfor j in 0..m-1\n\t\tif ar[i][j] == c\n\t\t\ts[ar[i-1][j]] = 1 if i > 0\n\t\t\ts[ar[i+1][j]] = 1 if i < n-1\n\t\t\ts[ar[i][j-1]] = 1 if j > 0\n\t\t\ts[ar[i][j+1]] = 1 if j < m-1\n\t\tend\n\tend\nend\n\ns.delete(c)\ns.delete(\".\")\nputs s.length\n\n"}, {"source_code": "n, m, c = gets.chomp!.split\nn = n.to_i\nm = m.to_i\nary = []\nhash = {}\nn.times {ary << gets.chomp!}\nn.times do |i|\n\tm.times do |j|\n\t\tif ary[i][j] == c\n\t\t\thash[ary[i][j]] = 1\n\t\t\thash[ary[i - 1][j]] = 1 if i - 1 >= 0\n\t\t\thash[ary[i + 1][j]] = 1 if i + 1 < n\n\t\t\thash[ary[i][j - 1]] = 1 if j - 1 >= 0\n\t\t\thash[ary[i][j + 1]] = 1 if j + 1 < m\n\t\tend\n\tend\nend\nhash.delete c\nhash.delete '.'\nputs hash.size"}, {"source_code": "n,m,r=gets.split()\nr=r[0]\nn=n.to_i\nm=m.to_i\n\nmap=Array.new(n)\nfor i in 0..n-1\n map[i]=gets.split[0]\nend\n\nres=[]\ndx=[1,0,-1,0]\nfor i in 0..n-1\n for j in 0..m-1\n next if map[i][j]!=r\n for k in 0..3\n nx=i+dx[k]\n ny=j+dx[k^1]\n if nx>=0&&nx=0&&ny= 0\n\t\t\thash[ary[i + 1][j]] = 1 if i + 1 < n\n\t\t\thash[ary[i][j - 1]] = 1 if j - 1 >= 0\n\t\t\thash[ary[i][j + 1]] = 1 if j + 1 < m\n\t\tend\n\tend\nend\nputs hash"}, {"source_code": "n,m,r=gets.split()\nr=r[0]\nn=n.to_i\nm=m.to_i\n\nmap=Array.new(n)\nfor i in 0..n-1\n map[i]=gets.split[0]\nend\n\nres=[]\ndx=[1,0,-1,0]\nfor i in 0..n-1\n for j in 0..m-1\n next if map[i][j]!=r\n for k in 0..3\n nx=i+dx[k]\n ny=j+dx[k^1]\n if nx>=0&&nx=0&&ny= 0 && nw >= 0 && nh < height && nw < width && data[nh][nw,1] != \".\" then\n ans.add?(data[h-1][w-1,1]) \n end\n end\n end\n end\nend\np ans.size()-1\n\n\n\n\n"}, {"source_code": "def extractIndices(office, color)\n startingCol, endingCol, startingRow, endingRow = -1, -1, -1, -1\n office.each_with_index do |row, rIdx|\n if row.include? color\n if startingRow == -1 #we do this just for the first row\n startingCol = row.find_index(color)\n (startingCol..row.length-1).each do |idx|\n if row[idx] != color\n endingCol = idx-1\n break\n end\n end\n if endingCol == -1 \n endingCol = row.length-1\n end\n end\n startingRow = rIdx if startingRow == -1\n endingRow = rIdx if rIdx >= endingRow\n end\n end\n return startingCol, endingCol, startingRow, endingRow\nend\n\n\nn, m, color = nil, nil, nil\noffice = []\n# File.open(\"input1\", \"r\") do |file|\n# n, m, color = file.readline.split(\" \")\n# n = n.to_i\n# m = m.to_i\n# n.times do\n# office << file.readline.chomp.split(\"\")\n# end\n# end\n\nn, m, color = gets.chomp.split(\" \")\nn = n.to_i\nm = m.to_i\nn.times do\n office << gets.chomp.split(\"\")\nend\n\nstartingCol, endingCol, startingRow, endingRow = extractIndices(office, color)\ntopRow = startingRow - 1\nbottomRow = endingRow + 1\nleftCol = startingCol - 1\nrightCol = endingCol + 1\nfound = []\n\nputs \"#{topRow}, #{bottomRow}, #{leftCol}, #{rightCol}\"\n\nif topRow >= 0\n topRow = office[topRow][startingCol..endingCol]\n lastFound = \".\"\n (startingCol..endingCol).each do |idx|\n next if topRow[idx-startingCol] == \".\" or topRow[idx-startingCol] == lastFound\n lastFound = topRow[idx-startingCol]\n found << lastFound\n end\nend\n\nif bottomRow < n\n bottomRow = office[bottomRow][startingCol..endingCol]\n lastFound = \".\"\n (startingCol..endingCol).each do |idx|\n next if bottomRow[idx-startingCol] == \".\" or bottomRow[idx-startingCol] == lastFound\n lastFound = bottomRow[idx-startingCol]\n found << lastFound\n end\nend\n\nif leftCol >= 0\n leftCol = office[startingRow..endingRow].map{|r| r[leftCol]}\n lastFound = \".\"\n (startingRow..endingRow).each do |idx|\n next if leftCol[idx-startingRow] == \".\" or leftCol[idx-startingRow] == lastFound\n lastFound = leftCol[idx-startingRow]\n found << lastFound\n end\nend\n\nif rightCol < m\n rightCol = office[startingRow..endingRow].map{|r| r[rightCol]}\n lastFound = \".\"\n (startingRow..endingRow).each do |idx|\n next if rightCol[idx-startingRow] == \".\" or rightCol[idx-startingRow] == lastFound\n lastFound = rightCol[idx-startingRow]\n found << lastFound\n end\nend\n\nputs \"#{found.count}\""}, {"source_code": "def extractIndices(office, color)\n startingCol, endingCol, startingRow, endingRow = -1, -1, -1, -1\n office.each_with_index do |row, rIdx|\n if row.include? color\n if startingRow == -1 #we do this just for the first row\n startingCol = row.find_index(color)\n (startingCol..row.length-1).each do |idx|\n if row[idx] != color\n endingCol = idx-1\n end\n end\n if endingCol == -1 \n endingCol = row.length-1\n end\n end\n startingRow = rIdx if startingRow == -1\n endingRow = rIdx if rIdx >= endingRow\n end\n end\n return startingCol, endingCol, startingRow, endingRow\nend\n\n\nn, m, color = nil, nil, nil\noffice = []\n# File.open(\"input1\", \"r\") do |file|\n# n, m, color = file.readline.split(\" \")\n# n = n.to_i\n# m = m.to_i\n# n.times do\n# office << file.readline.chomp.split(\"\")\n# end\n# end\n\nn, m, color = gets.chomp.split(\" \")\nn = n.to_i\nm = m.to_i\nn.times do\n office << gets.chomp.split(\"\")\nend\n\nstartingCol, endingCol, startingRow, endingRow = extractIndices(office, color)\ntopRow = startingRow - 1\nbottomRow = endingRow + 1\nleftCol = startingCol - 1\nrightCol = endingCol + 1\nfound = []\n\nif topRow >= 0\n topRow = office[topRow][startingCol..endingCol]\n lastFound = \".\"\n (startingCol..endingCol).each do |idx|\n next if topRow[idx-startingCol] == \".\" or topRow[idx-startingCol] == lastFound\n lastFound = topRow[idx-startingCol]\n found << lastFound\n end\nend\n\nif bottomRow < n\n bottomRow = office[bottomRow][startingCol..endingCol]\n lastFound = \".\"\n (startingCol..endingCol).each do |idx|\n next if bottomRow[idx-startingCol] == \".\" or bottomRow[idx-startingCol] == lastFound\n lastFound = bottomRow[idx-startingCol]\n found << lastFound\n end\nend\n\n\nif leftCol >= 0\n leftCol = office[startingRow..endingRow].map{|r| r[leftCol]}\n lastFound = \".\"\n (startingRow..endingRow).each do |idx|\n next if leftCol[idx-startingRow] == \".\" or leftCol[idx-startingRow] == lastFound\n lastFound = leftCol[idx-startingRow]\n found << lastFound\n end\nend\n\n\nif rightCol < m\n rightCol = office[startingRow..endingRow].map{|r| r[rightCol]}\n lastFound = \".\"\n (startingRow..endingRow).each do |idx|\n next if rightCol[idx-startingRow] == \".\" or rightCol[idx-startingRow] == lastFound\n lastFound = rightCol[idx-startingRow]\n found << lastFound\n end\nend\n\nputs \"#{found.count}\""}, {"source_code": "def extractIndices(office, color)\n startingCol, endingCol, startingRow, endingRow = -1, -1, -1, -1\n office.each_with_index do |row, rIdx|\n if row.include? color\n if startingRow == -1 #we do this just for the first row\n startingCol = row.find_index(color)\n (startingCol..row.length-1).each do |idx|\n if row[idx] != color\n endingCol = idx-1\n end\n end\n if endingCol == -1 \n endingCol = row.length-1\n end\n end\n startingRow = rIdx if startingRow == -1\n endingRow = rIdx if rIdx >= endingRow\n end\n end\n return startingCol, endingCol, startingRow, endingRow\nend\n\n\nn, m, color = nil, nil, nil\noffice = []\n# File.open(\"input2\", \"r\") do |file|\n# n, m, color = file.readline.split(\" \")\n# n = n.to_i\n# m = m.to_i\n# n.times do\n# office << file.readline.chomp.split(\"\")\n# end\n# end\n\nn, m, color = gets.chomp.split(\" \")\nn = n.to_i\nm = m.to_i\nn.times do\n office << gets.chomp.split(\"\")\nend\n\nstartingCol, endingCol, startingRow, endingRow = extractIndices(office, color)\ntopRow = startingRow - 1\nbottomRow = endingRow + 1\nleftCol = startingCol - 1\nrightCol = endingCol + 1\nfound = []\n\nif topRow >= 0\n topRow = office[topRow][startingCol..endingCol]\n lastFound = \".\"\n (startingCol..endingCol).each do |idx|\n next if topRow[idx-startingCol] == \".\" or topRow[idx-startingCol] == lastFound\n lastFound = topRow[idx-startingCol]\n found << lastFound\n end\nend\n\nif bottomRow < n\n bottomRow = office[bottomRow][startingCol..endingCol]\n lastFound = \".\"\n (startingCol..endingCol).each do |idx|\n next if bottomRow[idx-startingCol] == \".\" or bottomRow[idx-startingCol] == lastFound\n lastFound = bottomRow[idx-startingCol]\n found << lastFound\n end\nend\n\n\nif leftCol >= 0\n leftCol = office[startingRow..endingRow].map{|r| r[leftCol]}\n lastFound = \".\"\n (startingRow..endingRow).each do |idx|\n next if leftCol[idx-startingRow] == \".\" or leftCol[startingRow] == lastFound\n lastFound = leftCol[idx]\n found << lastFound\n end\nend\n\n\nif rightCol < m\n rightCol = office[startingRow..endingRow].map{|r| r[rightCol]}\n lastFound = \".\"\n (startingRow..endingRow).each do |idx|\n next if rightCol[idx-startingRow] == \".\" or rightCol[startingRow] == lastFound\n lastFound = rightCol[idx]\n found << lastFound\n end\nend\n\nputs \"#{found.length}\""}], "src_uid": "d7601c9bb06a6852f04957fbeae54925"} {"source_code": "gets.to_i.times do\n gets\n a = gets.split(\" \").map(&:to_i)\n a.sort!\n\n a[5...a.size-5] = nil\n a.compact!\n\n best = -999999999999999999999999999999999999999999999999999999999\n\n (0...a.size).each do |i|\n ((i+1)...a.size).each do |j|\n ((j+1)...a.size).each do |k|\n ((k+1)...a.size).each do |l|\n ((l+1)...a.size).each do |t|\n x = a[i]*a[j]*a[k]*a[l]*a[t]\n best = x if x > best\n end\n end\n end\n end\n end\n p best\nend\n", "positive_code": [{"source_code": "gets;$<.map{a=gets.split.map(&:to_i).sort\np (0..5).map{|x|(a.take(x)+a.last(5-x)).inject(1,:*)}.max}"}, {"source_code": "gets;$<.map{a=gets.split.map(&:to_i).group_by{|x|x>0}\np,n=[true,false].map{|x|a[x]||[]}.map &:sort\np (0..5).map{|x|b=(x%2==0?n.take(x):n.last(x))+(p.last(5-x));b[4]&&b.inject(1,:*)}.compact.max}"}], "negative_code": [{"source_code": "gets.to_i.times do\n gets\n a = gets.split(\" \").map(&:to_i)\n a.sort!\n\n a[5...a.size-5] = nil\n a.compact!\n\n best = -9999999999999\n\n (0...a.size).each do |i|\n ((i+1)...a.size).each do |j|\n ((j+1)...a.size).each do |k|\n ((k+1)...a.size).each do |l|\n ((l+1)...a.size).each do |t|\n x = a[i]*a[j]*a[k]*a[l]*a[t]\n best = x if x > best\n end\n end\n end\n end\n end\n p best\nend\n"}], "src_uid": "a3a64c3c7e9349d6e663c2d8113d2676"} {"source_code": "(_,_),(k,m), a,b=$<.map{|l|l.split.map &:to_i}\nputs a[k-1]=m\n puts \"YES\"\nelse\n puts \"NO\"\nend "}, {"source_code": "(_,_),(k,m), a,b=$<.map{|l|l.split.map &:to_i}\nputs a[k-1] a[k - 1]}\nputs bb && b[bb..-1].size >= m ? 'YES' : 'NO'\n"}, {"source_code": "na, nb = gets.split.map(&:to_i)\nk, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nbb = b.find_index{|x| x > a[k - 1]}\nc = []\nc = b[bb..-1] if bb\nputs c.size >= m ? 'YES' : 'NO'\n"}, {"source_code": "nA,nB = gets.split.map(&:to_i)\nk,m = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i)\ny = gets.split.map(&:to_i)\nputs x[(k-1)] < y[(nB - m)] ? \"YES\" : \"NO\""}, {"source_code": "nA,nB = gets.split.map(&:to_i)\nk,m = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i)\ny = gets.split.map(&:to_i)\nputs x[(k-1)] < y[(nB - m)] ? \"YES\" : \"NO\""}, {"source_code": "n1, n2 = gets.split.map(&:to_i)\nk, m = gets.split.map(&:to_i)\narray1 = gets.split.map(&:to_i)\narray2 = gets.split.map(&:to_i)\nputs array1[k-1 ] < array2[n2 - m] ? 'YES' : 'NO'\n\n\n\n"}, {"source_code": "nA,nB = gets.split.map(&:to_i)\nk,m = gets.split.map(&:to_i)\nx = gets.split.map(&:to_i)\ny = gets.split.map(&:to_i) \nputs x[(k-1)] < y[(nB - m)] ? \"YES\" : \"NO\""}, {"source_code": "# \u00dd t\u01b0\u1edfng:\n# \u0110\u1ec3 c\u00f3 kh\u1ea3 n\u0103ng k s\u1ed1 trong array a lu\u00f4n nh\u1ecf h\u01a1n m s\u1ed1 trong m\u1ea3ng b\n# th\u00ec ta ph\u1ea3i lu\u00f4n ch\u1ecdn k s\u1ed1 nh\u1ecf nh\u1ea5t trong m\u1ea3ng a v\u00e0 m s\u1ed1 l\u1edbn nh\u1ea5t trong b.\n# N\u00f3i c\u00e1ch kh\u00e1c, ta ph\u1ea3i lu\u00f4n ch\u1ecdn k s\u1ed1 \u0111\u1ea7u ti\u00ean \u1edf a v\u00e0 m s\u1ed1 cu\u1ed1i c\u00f9ng \u1edf b.\n# Sau \u0111\u00f3 ta so s\u00e1nh s\u1ed1 l\u1edbn nh\u1ea5t \u0111\u01b0\u1ee3c ch\u1ecdn trong k s\u1ed1 \u1edf a v\u00e0 s\u1ed1 nh\u1ecf nh\u1ea5t \u0111\u01b0\u1ee3c ch\u1ecdn trong m s\u1ed1 \u1edf b.\n# N\u1ebfu s\u1ed1 l\u1edbn nh\u1ea5t trong k s\u1ed1 \u0111\u00f3 nh\u1ecf h\u01a1n s\u1ed1 nh\u1ecf nh\u1ea5t trong m s\u1ed1 kia th\u00ec k\u1ebft qu\u1ea3 lu\u00f4n l\u00e0 \u201cYES\u201d, ng\u01b0\u1ee3c l\u1ea1i l\u00e0 \u201cNO\u201d\n\nsize_a, size_b = gets.chomp.split.map(&:to_i)\nk, m = gets.chomp.split.map(&:to_i)\n\narray_a = gets.chomp.split.map(&:to_i)\narray_b = gets.chomp.split.map(&:to_i)\n\nputs array_a[k - 1] < array_b[-m] ? \"YES\" : \"NO\"\n"}, {"source_code": "def checks(sizes, selections, array_1, array_2)\n selections = selections.split.map(&:to_i)\n array_1 = array_1.split.map(&:to_i)\n array_2 = array_2.split.map(&:to_i)\n puts array_1.sort.first(selections[0]).max < array_2.sort.last(selections[1]).min ? 'YES' : 'NO'\nend\nchecks(gets, gets, gets, gets)\n\n# Array1: Find min elements base on selection after that find max element\n# Array2: Find max elements base on selection after that find min element\n# Condition value of 2 array if array 1 < array 2 then print 'Yes' otherwise print 'No'\n"}, {"source_code": "(_,_),(k,m), a,b=$<.map{|l|l.split.map &:to_i}\nputs a[k-1] a[-1]\n# i = 0\n# loop do\n# break -1 if i < 0 or i >= l\n# break i if a[i+1] and b > a[i] and b <= a[i+1]\n# break i if not a[i+1] and b > a[i]\n# i = b > a[i] ? (l + i + 1) / 2 : i / 2\n# end\n# end\n# return false if k > a.length or m > b.length\n# p = qloc(a, b[-m])\n# k <= p + 1\n# end\n\ndef algo\n gets\n k, m = gets.split(' ').map { |e| e.to_i }\n a = gets.split(' ').map { |e| e.to_i }\n b = gets.split(' ').map { |e| e.to_i }\n # puts qselect(a, b, k, m) ? \"YES\" : \"NO\"\n puts b[-m] > a[k-1] ? \"YES\" : \"NO\"\nend\n\nalgo\n"}, {"source_code": "(_,_),(k,m), a,b=$<.map{|l|l.split.map &:to_i}\nputs a[k-1]=m\n puts \"YES\"\nelse\n puts \"NO\"\nend "}, {"source_code": "la,lb = gets.split(\" \").map(&:to_i)\nk,m = gets.split(\" \").map(&:to_i)\n\narr = gets.split(\" \").map(&:to_i)\nbrr = gets.split(\" \").map(&:to_i)\nif k<=la && m<=lb && arr[k-1]=m\n puts \"YES\"\nelse\n puts \"NO\"\nend "}, {"source_code": "\nna,nb = gets.split(' ').map(&:to_i)\n\nk,m = gets.split(' ').map(&:to_i)\n\na1 = gets.split(' ').map(&:to_i)\na2 = gets.split(' ').map(&:to_i)\n\nif a1[k-1] < a2[0] \n puts \"YES\" \nelse\n puts \"NO\"\n end"}, {"source_code": "na, nb = gets.split.map(&:to_i)\nk, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nbb = b.find_index{|x| x > a[k - 1]}\nputs b[(bb || 0)..-1].size >= m ? 'YES' : 'NO'\n"}, {"source_code": "skip = gets.chomp.to_i\nnumber_choose = gets.split.map(&:to_i)\narrayA = gets.split.map(&:to_i)\narrayB = gets.split.map(&:to_i)\nchoosenA = arrayA.last(number_choose[0])\nminB = arrayB.first(number_choose[1]).min\nputs choosenA.all?{|x| x < minB} ? 'YES' : 'NO'"}, {"source_code": "skip = gets.chomp\nselect_numbers = gets.split.map(&:to_i)\narray1 = gets.split.map(&:to_i)\narray2 = gets.split.map(&:to_i)\ncount = 0\narray = array1 + array2\n(array1.length...array.length).each do|index|\n if array[index] <= array[index-1]\n count = index\n break\n end\nend\n\nputs ( count > select_numbers.max) ? 'YES' : 'NO'\n\n\n"}, {"source_code": "skip = gets.chomp\nselect_numbers = gets.split.map(&:to_i)\narray1 = gets.split.map(&:to_i)\narray2 = gets.split.map(&:to_i)\ncount = 0\narray = array1 + array2\n(1...array.length).each do|index|\n if array[index] <= array[index-1]\n count = index\n break\n end\nend\nputs ( count > select_numbers.max) ? 'YES' : 'NO'\n\n\n"}, {"source_code": "skip = gets.chomp.to_i\nnumber_choosens = gets.split.map(&:to_i)\narrayA = gets.split.map(&:to_i)\narrayB = gets.split.map(&:to_i)\npossile_of_a = arrayA.select{|x| x < arrayB.min}\npossile_of_b = arrayB.select{|x| x > arrayA.max}\nputs (possile_of_a.size >= number_choosens[0] && possile_of_b.size >= number_choosens[1]) ? 'YES' : 'NO'"}, {"source_code": "#!/usr/bin/ruby\n\ndef qselect(a, b, k, m)\n def qloc(a, b)\n l = a.length\n i = 0\n loop do\n break -1 if i < 0 or i >= l\n break i if a[i+1] and b > a[i] and b <= a[i+1]\n break i if not a[i+1] and b > a[i]\n i = b >= a[i] ? (l + i + 1) / 2 : (i - 1) / 2\n end\n end\n\n p = qloc(a, b[0])\n return false if p < 0\n k <= p + 1 && m <= b.length\nend\n\ndef algo\n gets\n k, m = gets.split(' ').map { |e| e.to_i }\n a = gets.split(' ').map { |e| e.to_i }\n b = gets.split(' ').map { |e| e.to_i }\n puts qselect(a, b, k, m) ? \"YES\" : \"NO\"\nend\n\nalgo\n"}, {"source_code": "#!/usr/bin/ruby\n\n# def qselect(a, b, k, m)\n# def qloc(a, b)\n# l = a.length\n# return -1 if b <= a[0]\n# return l if b > a[-1]\n# i = 0\n# loop do\n# break -1 if i < 0 or i >= l\n# break i if a[i+1] and b > a[i] and b <= a[i+1]\n# break i if not a[i+1] and b > a[i]\n# i = b > a[i] ? (l + i + 1) / 2 : i / 2\n# end\n# end\n# return false if k > a.length or m > b.length\n# p = qloc(a, b[-m])\n# k <= p + 1\n# end\n\ndef algo\n gets\n k, m = gets.split(' ').map { |e| e.to_i }\n a = gets.split(' ').map { |e| e.to_i }\n b = gets.split(' ').map { |e| e.to_i }\n # puts qselect(a, b, k, m) ? \"YES\" : \"NO\"\n puts b[-m] > a[-k] ? \"YES\" : \"NO\"\nend\n\nalgo\n"}, {"source_code": "#!/usr/bin/ruby\n\ndef qselect(a, b, k, m)\n def qloc(a, b)\n l = a.length\n return -1 if b <= a[0]\n return l if b > a[-1]\n i = 0\n loop do\n break -1 if i < 0 or i >= l\n break i if a[i+1] and b > a[i] and b <= a[i+1]\n break i if not a[i+1] and b > a[i]\n i = b > a[i] ? (l + i + 1) / 2 : i / 2\n end\n end\n\n p = qloc(a, b[0])\n return false if p < 0\n k <= p + 1 && m <= b.length\nend\n\ndef algo\n gets\n k, m = gets.split(' ').map { |e| e.to_i }\n a = gets.split(' ').map { |e| e.to_i }\n b = gets.split(' ').map { |e| e.to_i }\n puts qselect(a, b, k, m) ? \"YES\" : \"NO\"\nend\n\nalgo\n"}, {"source_code": "def checks(sizes, selections, array_1, array_2)\n selections = selections\n puts 1 < 2 ? 'YES' : 'NO'\nend\nchecks(gets.chomp, gets.chomp, gets.chomp, gets.chomp)\n"}, {"source_code": "def checks(sizes, selections, array_1, array_2)\n \n puts 'YES'\nend\nchecks(gets.chomp, gets.chomp, gets.chomp, gets.chomp)\n"}], "src_uid": "8e0581cce19d6bf5eba30a0aebee9a08"} {"source_code": "gets.to_i.times{\r\n a,b=gets.split\r\n puts a.to_i*b.to_i\r\n}", "positive_code": [{"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n\ta,b = gets.split()\r\n\tp a.to_i*b.to_i\r\nend\r\n"}], "negative_code": [], "src_uid": "806dcdab8364f5169334e172a192598a"} {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \")\n number_zero = a.count(\"0\")\n number_ichi = n - number_zero \n if number_zero >= number_ichi\n a.delete(\"1\")\n puts a.size\n puts a.join(\" \")\n else\n a.delete(\"0\")\n ookisa = a.size\n if ookisa % 2 == 0\n puts a.size\n puts a.join(\" \")\n else\n a.pop\n puts a.size\n puts a.join(\" \")\n end\n end\nend\n", "positive_code": [{"source_code": "gets;$<.each_slice(2){|x|o=x[1].count ?0;i=x[1].count ?1\ni>o ?(n=i/2*2;a=1):(n=o;a=0)\nputs [n]+[a]*n}"}, {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n rui_e = [0]\n rui_o = [0]\n\n a.each_with_index do |x, i|\n if i.even?\n rui_e << rui_e.last + x\n rui_o << rui_o.last\n else\n rui_e << rui_e.last\n rui_o << rui_o.last + x\n end\n end\n\n idx = -1\n\n n.times do |i|\n v1 = (rui_e[i] - rui_e[0]) + (rui_o[n] - rui_o[i + 1])\n v2 = (rui_o[i] - rui_o[0]) + (rui_e[n] - rui_e[i + 1])\n\n if v1 == v2\n idx = i\n break\n end\n end\n\n if idx != -1\n a.delete_at(idx)\n end\n\n puts a.size\n puts a.join(' ')\nend\n"}, {"source_code": "gets;$<.each_slice(2){|x|h=o=x[1].count ?0;i=x[1].count ?1\ni>o ?(n=i/2*2;a=1):(n=o;a=0)\nputs [n]+[a]*n}\n"}], "negative_code": [{"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n s = a.sum\n t = s / 2\n ans = []\n sum = [0, 0]\n\n if n <= 2\n puts 1\n puts 0\n next\n end\n\n until a.empty?\n x = a.shift\n\n if ans.size.even?\n next if x + sum[0] > t\n\n sum[0] += x\n ans << x\n else\n next if x + sum[1] > t\n\n sum[1] += x\n ans << x\n end\n end\n\n puts ans.size\n puts ans.join(' ')\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = gets.chomp.split(\" \")\n number_zero = a.count(\"0\")\n number_ichi = n - number_zero \n if number_zero >= number_ichi\n a.delete(\"1\")\n puts a.join(\" \")\n else\n a.delete(\"0\")\n ookisa = a.size\n if ookisa % 2 == 0\n puts a.join(\" \")\n else\n a.pop\n puts a.join(\" \")\n end\n end\nend\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n s = a.sum\n t = s / 2\n ans = []\n sum = [0, 0]\n\n until a.empty?\n x = a.shift\n\n if ans.size.even?\n next if x + sum[0] > t\n\n sum[0] += x\n ans << x\n else\n next if x + sum[1] > t\n\n sum[1] += x\n ans << x\n end\n end\n\n puts ans.size\n puts ans.join(' ')\nend\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n counter = a.tally\n counter.default = 0\n\n if counter[0] >= 1\n puts 1\n puts 0\n elsif counter[1] >= 2\n puts 2\n puts \"1 1\"\n end\nend\n"}], "src_uid": "eca92beb189c4788e8c4744af1428bc7"} {"source_code": "def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\ndef inps() a=gets.chomp.split(\" \")end\ndef copy(a) Marshal.load(Marshal.dump(a)) end\ndef kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end\ndef scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end\ndef na(n=0,d=0) Array.new(n,d)end\ndef na2(n=0,m=0,d=0) Array.new(n){Array.new(m,d)}end\ndef na3(n=0,m=0,l=0,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\ndef bit(n) n.to_s(2).split(\"\").map(&:to_i) end\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\nn = inp[0]\na = inp\nb = inp\ntable = na(n)\nencoded = na(n)\nn.times do |i|\n encoded[a[i]-1] = i\nend\n\npl = 0\nans = 0\ni = 0\nwhile i < n\n if(table[i] == 1)\n pl -= 1\n i += 1\n next\n end\n if(a[i] != b[i+pl])\n ans += 1\n table[encoded[b[i+pl]-1]] = 1\n pl +=1\n else\n i += 1\n end\nend\np ans", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\nout = [false]*(n+1)\n\nans = 0\nj = 0\nn.times do |i|\n if !out[a[i]]\n while b[j] != a[i]\n out[b[j]] = true\n j += 1\n ans += 1\n end\n out[b[j]] = true\n j += 1\n end\nend\np ans"}], "negative_code": [], "src_uid": "f5178609cc7782edd40bc50b8797522e"} {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2 k\n print -1\n else\n _max = (k -_min)/d\n print _max > n ? n : _max\n end\n print \"\\n\"\nend\n"}, {"source_code": "q = gets.to_i\n(1..q).each do\n res = 0\n read = gets.split(\" \").map{|c| c.to_i}\n k = read[0]\n n = read[1]\n a = read[2]\n b = read[3]\n if n * b >= k\n res = -1\n else\n l = 0\n r = n\n while l < r\n m = (l + r + 1)/2\n if m * a + (n - m) * b < k\n l = m\n else\n r = m - 1\n end\n end\n res = l\n end\n puts res\nend"}], "negative_code": [{"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2r.size}\n\n(n-1).downto 1 do |i|\n s, t=str[i-1], str[i]\n if t.index(s).nil?\n puts 'NO'\n exit 0\n end\nend\n\nputs 'YES'\nputs str.join(\"\\n\")", "positive_code": [{"source_code": "n = gets.to_i\ns = (1..n).map { gets.chomp }.sort_by(&:size)\nif s.each_cons(2).all? { |s, t| (0...t.size).any? { |i| s == t[i, s.size] } }\n\tputs 'YES', s.join(\"\\n\")\nelse\n\tputs 'NO'\nend"}, {"source_code": "n = gets.to_i\nar = []\nn.times {ar << gets.chomp}\nar.sort!{|a,b| a.size <=> b.size}\nn.times do |i|\n next if i == 0\n s = ar[i]\n s0 = ar[i-1]\n if !s.include? s0\n puts \"NO\"\n exit 0\n end\nend\nputs \"YES\"\nputs ar"}, {"source_code": "n = gets.to_i\na = []\nfor i in 0..n-1\n x = gets.chomp\n a.push(x)\n end\ny = a.sort_by(&:length)\nv = 1\nfor i in 0..n-2\n if y[i+1].include?y[i] or y[i+1] == y[i]\n v += 1\n end\n end\nif v != a.length\n puts \"NO\"\nelse\n puts \"YES\" \n for i in 0..a.length-1\n puts \"#{y[i]}\"\n end \n end \n \n \n"}], "negative_code": [], "src_uid": "5c33d1f970bcc2ffaea61d5407b877b2"} {"source_code": "n, p = gets.split(/\\s+/).map(&:to_i)\ns = gets.strip\n\n\ndef get_next(s, n, p)\n if n == 1\n if s[0].ord == p.ord\n nil\n else\n s[0].succ\n end\n else\n q = s[-1] == 'z' ? '{' : s[-1].succ\n x = s[0...-1]\n begin\n while q.ord <= p.ord && (q == x[-1] || q == x[-2])\n q = q == 'z' ? '{' : q.succ\n end\n\n if q.ord <= p.ord\n return \"#{x}#{q}\"\n else\n x = get_next(x, n-1, p)\n q = 'a'\n end\n end while x\n\n nil\n end\nend\n\np = ('a'.ord + p.ord-1).chr\n\nif (s = get_next(s, n, p))\n puts s\nelse\n puts \"NO\"\nend\n\n\n", "positive_code": [{"source_code": "def fill_string(string, i, max_ord)\n (i...string.size).each do |i|\n ('a'.ord..max_ord).each { |j|\n if (i-1<0 || j.chr != string[i-1]) && (i-2<0 || j.chr != string[i-2])\n string[i] = j.chr\n break\n end\n }\n end\n string\nend\n\n\np = gets.split[1].to_i + 'a'.ord - 1\nstring = gets[0..-2]\nno = true\n(0...string.size).reverse_each do |i|\n (string[i].ord+1..p).each do |j|\n if (i-1<0 || j.chr != string[i-1]) && (i-2<0 || j.chr != string[i-2])\n string[i] = j.chr\n puts fill_string string, i+1, p\n no = false\n break\n end\n end\n break unless no\nend\n\nputs \"NO\" if no\n\t\t \t\t\t\t\t \t\t \t \t \t \t\t \t\t"}], "negative_code": [], "src_uid": "788ae500235ca7b7a7cd320f745d1070"} {"source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\nb=gets.chomp.split(\" \")\n\n\nmaxind=0\nz=0\nmax=0\np=0\nsq=0\n\nif a[1]>0\n0.upto(a[0]-1) do |i| \n \n\tif i>0 \n\tsq=sq-1\n\tif b[i-1]==\"0\"\n\tz=z-1\n\telse \n\tz=z\n\tend\n\tend\n\n loop do\n break if p>=a[0]\n if b[p]==\"0\"\n z+=1\n end \n\tbreak if z>a[1]\n sq+=1\n\t\tp+=1\n end\n z-=1 \n if sq>max\n max=sq\n maxind=i\n end \n\n\tbreak if p==a[0]\nend \n k=0\nloop do \n\tbreak if maxind==a[0]\n\tbreak if k==a[1]\n if b[maxind]==\"0\"\n b[maxind]=\"1\"\n k+=1\n end\n\t maxind +=1\nend\nputs \"#{max}\"\nputs b.join(\" \")\n\n\nelse\n\n\nsq=0\nb.each do |i|\nif i== \"0\"\nif sq>max\nmax=sq\nend\nsq=0\nelse\nsq+=1\nend\nend\nif sq>max\nmax=sq\nend\nputs \"#{max}\"\nputs b.join(\" \")\n\nend\n\n", "positive_code": [{"source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\nb=gets.chomp.split(\" \")\n\n\nmaxind=0\nz=0\nmax=0\np=0\nsq=0\n\nif a[1]>0\n0.upto(a[0]-1) do |i| \n \n\tif i>0 \n\tsq=sq-1\n\tif b[i-1]==\"0\"\n\tz=z-1\n\telse \n\tz=z\n\tend\n\tend\n\n loop do\n break if p>=a[0]\n if b[p]==\"0\"\n z+=1\n end \n\tbreak if z>a[1]\n sq+=1\n\t\tp+=1\n end\n z-=1 \n if sq>max\n max=sq\n maxind=i\n end \n\n\tbreak if p==a[0]\nend \n k=0\nloop do \n\tbreak if maxind==a[0]\n\tbreak if k==a[1]\n if b[maxind]==\"0\"\n b[maxind]=\"1\"\n k+=1\n end\n\t maxind +=1\nend\nputs \"#{max}\"\nputs b.join(\" \")\n\n\nelse\n\n\nsq=0\nb.each do |i|\nif i== \"0\"\nif sq>max\nmax=sq\nend\nsq=0\nelse\nsq+=1\nend\nend\nif sq>max\nmax=sq\nend\nputs \"#{max}\"\nputs b.join(\" \")\n\nend"}, {"source_code": "buf=gets.split(' ')\nn,k=buf[0].to_i, buf[1].to_i\nt=k\na=gets.split(' ')\nr=ma=st=0\nfor l in 0..n-1\n\tk+=1 if l>0 && a[l-1]=='0'\n\twhile r0)\n\t\tk-=1 if a[r]=='0'\n\t\tr+=1\n\tend\n\tma,st=r-l,l if r-l>ma\nend\nputs ma\nwhile st=0\n\tbreak if t<1 && a[st]==?0\n\tt-=1 if a[st]==?0\n\ta[st]=?1\n\tst+=1\nend\nputs a*\" \""}], "negative_code": [{"source_code": "a=gets.chomp.split(\" \").map{|i| i.to_i}\nb=gets.chomp.split(\" \")\nmaxind=0\nmax=0\n0.upto(a[0]-2) do |i| \n\tp=0\n p=i\n sq=0\n z=0\n loop do\n if b[p]==\"0\"\n z+=1\n end \n p+=1\n\tbreak if p==a[0]\n break if z>a[1]\n sq+=1\n end\n if sq>max\n max=sq\n maxind=i\n end \nend \n\nk=0\nloop do \n if b[maxind]==\"0\"\n b[maxind]=\"1\"\n k+=1\n end\n\t maxind +=1\n\t\n break if k==a[1]\nend\nputs \"#{max}\"\nputs b.join(\" \")\n"}], "src_uid": "ec9b03577868d8999bcc54dfc1aae056"} {"source_code": "k = gets.to_i\nk.times do\n n = gets.to_i\n as = gets.split.map(&:to_i).sort.reverse\n ans = 0\n as.each_with_index do |a, i|\n if a > ans\n ans += 1\n end\n end\n puts ans\nend\n", "positive_code": [{"source_code": "def inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nq = inp[0]\nq.times do\n n = inp[0]\n t = inp\n t.sort!.reverse!\n ans = 0\n n.times do |i|\n ans = [ans,[t[i],(i+1)].min].max\n end\n p ans\nend"}, {"source_code": "g = gets.chomp.to_i\ng.times{\nn = gets.to_i\nmax = 0\ndoski = gets.split(\" \").map{|x|x.to_i}\njj = (1...1001).to_a\njj.map{|w|\nq=0\ndoski.map{|e| if e >= w then q+=1 end}\nif q >= w and max < w then max = w end\n}\nputs max\n}\n\n"}], "negative_code": [{"source_code": "g = gets.chomp.to_i\ng.times{\nn = gets.to_i\nmax = 0\ndoski = gets.split(\" \").map{|x|x.to_i}\njj = (1...1000).to_a\njj.map{|w|\nq=0\ndoski.map{|e| if e >= w then q+=1 end}\nif q >= w and max < w then max = w end\n}\nputs max\n}\n\n"}], "src_uid": "09236a3faa7fce573a4e5e758287040f"} {"source_code": "ans,a=0,Array.new(100,0)\ngets.to_i.times do |i|\n\tl,r=gets.chomp.split.map(&:to_i)\n\tfor j in l...r\n\t\ta[j]=i==0\n\tend\nend\nputs a.count(true)\n", "positive_code": [{"source_code": "ans,a=0,Array.new(100,0)\ngets.to_i.times do |i|\n\tl,r=gets.chomp.split.map(&:to_i)\n\tfor j in l...r\n\t\ta[j]=i==0\n\tend\nend\nputs a.count(true)\n"}, {"source_code": "ans,a=0,Array.new(100,0)\ngets.to_i.times do |i|\n\tl,r=gets.chomp.split.map(&:to_i)\n\tfor j in l...r\n\t\ta[j]=i==0\n\tend\nend\nputs a.count(true)\n"}, {"source_code": "ans,a=0,Array.new(100,0)\ngets.to_i.times do |i|\n\tl,r=gets.chomp.split.map(&:to_i)\n\tfor j in l...r\n\t\ta[j]=i==0\n\tend\nend\nputs a.count(true)\n"}, {"source_code": "ans,a=0,Array.new(100,0)\ngets.to_i.times do |i|\n\tl,r=gets.chomp.split.map(&:to_i)\n\tfor j in l...r\n\t\ta[j]=i==0\n\tend\nend\nputs a.count(true)"}, {"source_code": "ans,a=0,Array.new(100,0)\ngets.to_i.times do |i|\n\tl,r=gets.chomp.split.map(&:to_i)\n\tfor j in l...r\n\t\ta[j]=i==0\n\tend\nend\nputs a.count(true)"}, {"source_code": "ans,a=0,Array.new(100,0)\ngets.to_i.times do |i|\n\tl,r=gets.chomp.split.map(&:to_i)\n\tfor j in l...r\n\t\ta[j]=i==0\n\tend\nend\nputs a.count(true)\n"}, {"source_code": "ans,a=0,Array.new(100,0)\ngets.to_i.times do |i|\n\tl,r=gets.chomp.split.map(&:to_i)\n\tfor j in l...r\n\t\ta[j]=i==0\n\tend\nend\nputs a.count(true)\n"}, {"source_code": "n = gets.to_i\nalex_l,alex_r = gets.split(\" \").map(&:to_i)\n\n# (n-1).times do\n# \tl,r = gets.split(\" \").map(&:to_i)\n# \tx,y = l+1,r-1\n# \t# x,y = y,x if x > y\n# \tif l + 1 == r\n# \t\t# puts \"here\" \n# \t\talex -= [l]\n# \telse\n# \t\talex -= (x..y).to_a\n# \tend\n# end\n# length = 0\n# (1..alex.length-1).each do |i|\n# \tif (alex[i-1] + 1 == alex[i]) || (alex[i+1] && alex[i]+1 != alex[i+1])\n# \t\tputs alex[i]\n# \t\tlength += 1 \n# \tend\n# end\n# puts \"#{alex}\"\n# puts length\nused = Array.new(100,true)\n\n(n-1).times do\n\tl,r = gets.split(\" \").map(&:to_i)\n\t(l..r-1).each do |i|\n\t\tused[i] = false\n\tend\nend\nputs \"#{used[alex_l..alex_r-1].count(true)}\""}, {"source_code": "ans,a=0,Array.new(100,0)\ngets.to_i.times do |i|\n\tl,r=gets.chomp.split.map(&:to_i)\n\tfor j in l...r\n\t\ta[j]=i==0\n\tend\nend\nputs a.count(true)\n"}, {"source_code": "class Array\n\tdef f x\n\t\tself[0] - 1 < x && x < self[1]\n\tend\nend\n\nn = gets.to_i\nl, r = gets.split.map(&:to_i)\nseg = []\n(n-1).times{seg< y\n\tif l + 1 == r\n\t\t# puts \"here\" \n\t\talex -= [l]\n\telse\n\t\talex -= (x..y).to_a\n\tend\nend\nlength = 0\n(1..alex.length-1).each do |i|\n\tlength += 1 if alex[i-1] + 1 == alex[i]\nend\n# puts \"#{alex}\"\nputs length"}], "src_uid": "00c29b9f74b6564e41837704c24fc318"} {"source_code": "shokti = {\"purple\"=>\"Power\", \"green\"=> \"Time\" , \"blue\"=>\"Space\" ,\"orange\"=> \"Soul\" , \"red\"=> \"Reality\" , \"yellow\"=> \"Mind\"}\nshoktiray = [\"purple\",\"green\",\"blue\",\"orange\",\"red\",\"yellow\"]\n\ns = gets.to_i\na = []\n\nfor i in 0..s-1\n b = gets.chomp\n a.push(b)\nend\nnotun = shoktiray - a \nputs notun.length\n\nnotun.each{|k|\n puts shokti[k]\n}\n", "positive_code": [{"source_code": "gems = {}\ngems['purple'] = 'Power'\ngems['green'] = 'Time'\ngems['blue'] = 'Space'\ngems['orange'] = 'Soul'\ngems['red'] = 'Reality'\ngems['yellow'] = 'Mind'\n\nlen = gets.to_i\n0.upto(len-1) do \n word = gets.chomp\n gems.delete(word)\nend\n\nputs gems.values.count\ngems.values.each{|val|\n if val != nil\n puts val\n end\n}"}, {"source_code": "n = gets.to_i\nc = []\nn.times{c << gets.strip}\nh = {\n 'purple' => 'Power',\n 'green' => 'Time',\n 'blue' => 'Space',\n 'orange' => 'Soul',\n 'red' => 'Reality',\n 'yellow' => 'Mind'\n}\nans = []\nh.each{|k, v| ans << v unless c.any?{|x| x == k}}\np ans.size\nans.each{|x| puts x}\n"}, {"source_code": "#purple, green, blue, orange, red, yellow\n#Power , Time, Space, Soul, Reality, Mind\n\n\narr = [\"Power\" , \"Time\", \"Space\", \"Soul\", \"Reality\", \"Mind\"]\n\n\na = gets.to_i\n\nsize = 6\n\nfor i in 0..a-1\n\ttmp = gets.chomp\n\n\tif(tmp == \"purple\")\n\t\tarr[0] = \"\"\n\t\tsize -=1\n\telsif (tmp == \"green\")\n\t\tarr[1] = \"\"\n\t\tsize -=1\n\telsif (tmp == \"blue\")\n\t\tarr[2] = \"\"\n\t\tsize -=1\n\telsif (tmp == \"orange\")\n\t\tarr[3] = \"\"\n\t\tsize -=1\n\telsif (tmp == \"red\")\n\t\tarr[4] = \"\"\n\t\tsize -=1\n\telsif (tmp == \"yellow\")\n\t\tarr[5] = \"\"\n\t\tsize -=1\n\n\tend\nend\n\nputs (size)\n\nfor i in 0..6\n\tif(arr[i] == \"\")\n\t\tnext\n\telse\n\t\tputs arr[i]\n\tend\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "h={}\nh['purple']='Power'\nh['green']='Time'\nh['blue']='Space'\nh['orange']='Soul'\nh['red']='Reality'\nh['yellow']='Mind'\n\nn=gets.chomp.to_i\nn.times do\n s=gets.chomp\n h.delete(s)\nend\n\nputs h.size\nh.values.each do |s|\n puts s\nend"}, {"source_code": "g = Hash.new\ng['red'] = \"Reality\"\ng['purple'] = \"Power\"\ng['orange'] = \"Soul\"\ng['yellow'] = \"Mind\"\ng['blue'] = \"Space\"\ng['green'] = \"Time\"\n\nnumber = gets.to_i\nnumber.times{\n\ts = gets.chomp\n\tg.delete(s)\n}\n\nputs g.length\ng.each{\n\t|k, v|\n\tputs v\n}\n"}, {"source_code": "T={'purple'=>'Power','green'=>'Time','blue'=>'Space','orange'=>'Soul','red'=>'Reality','yellow'=>'Mind'}\nA=[];gets;$<.each{|e|A< 'Power',\n 'green' => 'Time',\n 'blue' => 'Space',\n 'orange' => 'Soul',\n 'red' => 'Reality',\n 'yellow' => 'Mind'\n}\n\nN.times do\n str = gets.chomp\n hash.delete(str)\nend\nputs hash.length, hash.values"}, {"source_code": "n = gets.to_i\nas = []\n\ngems = Hash.new\ngems['purple'] = 'Power'\ngems['green'] = 'Time'\ngems['blue'] = 'Space'\ngems['orange'] = 'Soul'\ngems['red'] = 'Reality'\ngems['yellow'] = 'Mind'\n\nn.times do\n as << gets.chomp\nend\n\ngems.reject! { |k, v| as.include?(k) }\nputs gems.size\nputs gems.values"}, {"source_code": "s = %w(the Power Gem of purple color,\nthe Time Gem of green color,\nthe Space Gem of blue color,\nthe Soul Gem of orange color,\nthe Reality Gem of red color,\nthe Mind Gem of yellow color.)\n\nt = (0...6).map { |i| [s[6 * i + 4], s[6 * i + 1]] }\n\nn = gets.to_i\ncols = (0...n).map { gets.strip }\ncnt = {}\ncols.each do |c|\n cnt[c] = 1\nend\na = []\n(0...6).each do |i|\n a << t[i][1] if cnt[t[i][0]].nil?\nend\np a.size\nputs a.join ?\\n\n"}], "negative_code": [{"source_code": "T={'purple'=>'Power','green'=>'Time','blue'=>'Space','orange'=>'Soul','red'=>'Reality','yellow'=>'Mind'}\nA=[];gets;$<.each{|e|A<d}?:YES: :NO\n\n", "positive_code": [{"source_code": "a,b,c = gets.chomp.split(\" \").map{|v| v.to_i}\nkhanh = gets.chomp.split(\" \").map{|v| v.to_i}\nhuy= gets.chomp.split(\" \").map{|a| a.to_i}\n\nkhanh = khanh.sort.reverse!\nhuy = huy.sort.reverse!\n\nresult = \"NO\"\nif khanh.length > huy.length\n result = \"YES\"\nelse\n stop = false\n i = 0\n while i < khanh.length && !stop do\n if khanh[i] > huy[i]\n result = \"YES\"\n stop = true\n elsif\n i = i + 1\n end\n end\nend\n\nputs result\n"}, {"source_code": "_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}\nputs a.zip(b).any?{|c,d|d.nil?||c>d}?:YES: :NO\n\n"}, {"source_code": "_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}\nputs a.zip(b).any?{|c,d|d.nil?||c>d}?:YES: :NO\n\n"}, {"source_code": "_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}\nputs a.zip(b).any?{|c,d|d.nil?||c>d}?:YES: :NO\n"}, {"source_code": "_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}\nputs a.zip(b).any?{|c,d|d.nil?||c>d}?:YES: :NO\n\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).sort!\nb=gets.split.map(&:to_i).sort!\np=0\nn.times{ |i|\n\twhile pm-p\n\t\tputs 'YES'\n\t\texit\n\tend\n}\nputs 'NO'"}, {"source_code": "_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}\nputs a.zip(b).any?{|c,d|d.nil?||c>d}?:YES: :NO\n\n"}, {"source_code": "_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}\nputs a.zip(b).any?{|c,d|d.nil?||c>d}?:YES: :NO\n\n"}, {"source_code": "_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}\nputs a.size>b.size||a.zip(b).any?{|c,d|c>d}?:YES: :NO\n"}, {"source_code": "_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}\nputs a.zip(b).any?{|c,d|d.nil?||c>d}?:YES: :NO\n"}, {"source_code": "_,a,b=(1..3).map{gets.split.map(&:to_i).sort.reverse}\nputs a.size>b.size||a.zip(b).any?{|c,d|c>d}?:YES: :NO\n"}, {"source_code": "_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}\nputs a.zip(b).any?{|c,d|d.nil?||c>d}?:YES: :NO\n\n"}, {"source_code": "_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}\nputs a.zip(b).any?{|c,d|d.nil?||c>d}?:YES: :NO\n\n"}, {"source_code": "gets\na=[0]+gets.split.map(&:to_i).sort\nb=[0]+gets.split.map(&:to_i).sort\n(1..[a.size,b.size].min).each{|i|exit !(puts\"YES\")if a[-i]>b[-i]}\nputs\"NO\""}], "negative_code": [{"source_code": "gets\na=gets.split.map(&:to_i).sort\nb=gets.split.map(&:to_i).sort\n(1..[a.size,b.size].min).each{|i|exit !(puts\"YES\")if a[-i]>b[-i]}\nputs\"NO\""}, {"source_code": "gets\na=gets.split.map(&:to_i).sort.reverse\nb=gets.split.map(&:to_i).sort.reverse\n(0...[a.size,b.size].min).each{|i|exit !(puts\"YES\")if a[i]>b[i]}\nputs\"NO\""}, {"source_code": "a,b,c = gets.chomp.split(\" \").map{|v| v.to_i}\nkhanh = gets.chomp.split(\" \").map{|v| v.to_i}\nhuy= gets.chomp.split(\" \").map{|a| a.to_i}\n\nkhanh = khanh.reverse!\nhuy = huy.reverse!\n\nresult = \"NO\"\nif khanh.length > huy.length\n result = \"YES\"\nelse\n stop = false\n i = 0\n while i < khanh.length && !stop do\n if khanh[i] > huy[i]\n result = \"YES\"\n stop = true\n elsif\n i = i + 1\n end\n end\nend\n\nputs result\n"}], "src_uid": "01cd3f0c6bc2975118075d180bfeba2d"} {"source_code": "n, m = gets.split.map(&:to_i)\na = []\nm.times do\n\ta << gets.split.map(&:to_i)\nend\ns = 0\n1.upto(n) do |i|\n\tb = 0\n\td = -1\n\ta.each do |l, r, t, c|\n\t\tnext if i < l || i > r\n\t\tif d == -1 || t < d\n\t\t\td = t\n\t\t\tb = c\n\t\tend\n\tend\n\ts += b\nend\np s\n", "positive_code": [{"source_code": "\nn, m = gets.split.map(&:to_i)\narr = Array.new(n) { [] }\nm.times do |j|\n l, r, t, c = gets.split.map(&:to_i)\n (l..r).each { |i| arr[i - 1] << [j, t, c] }\nend\n\nmax_profit = 0\narr.each do |t|\n if !t.empty? \n t.sort! { |a, b| (a[1] == b[1]) ? a[0] <=> b[0] : a[1] <=> b[1] }\n max_profit += t[0][2]\n end\nend\n\nputs max_profit"}, {"source_code": "\nn,m=gets.split.map(&:to_i)\ncomp=[]\ntime=Array.new(n){[9999999,0]}\nm.times{\n l,r,t,c=gets.split.map(&:to_i)\n for k in (l-1)..(r-1)\n if time[k][0]>t then\n time[k][0]=t\n time[k][1]=c\n end\n end\n}\nans=0\nn.times{|i|\n ans+=time[i][1]\n}\np ans\n"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\n\nsections = []\n\nn.times do\n\tsections << []\t\nend\n\n\ntime = {}\ncost = {}\n\nm.times do |i|\n\tl,r,t,c = gets.split(\" \").map(&:to_i)\n\n\t(l..r).each do |j|\n\t\tsections[j-1] << i + 1\n\tend\n\n\ttime[i+1] = t\n\tcost[i+1] = c\nend\n\nwinner = []\n\n# puts \"#{sections}\"\nsections.each do |a|\n\t\n\tmin_time = time[a[0]]\n\tmin_ind = a[0]\n\n\ta.each_with_index do |x,i|\n\t\t# puts \"x #{x} #{min_time}\"\n\t\tif time[x] < min_time\n\t\t\t# puts \"mitim #{min_time}\"\n\t\t\tmin_time = time[x]\n\t\t\tmin_ind = x\n\t\tend\n\tend\n\n\twinner << min_ind\nend\n\n\n# puts \"#{time}\"\n# puts \"#{cost}\"\n# puts \"#{winner}\"\nputs winner.compact.inject(0){|s,a| s += cost[a] }"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = [0]*(n+1)\ntt = []\nm.times do\n l, r, t, c = gets.split.map(&:to_i)\n l.upto(r) do |i|\n if !tt[i] || t < tt[i]\n tt[i] = t\n a[i] = c\n end\n end\n #p a, tt\nend\np a.inject(0){|r,j| r+j}\n"}], "negative_code": [{"source_code": "n, m = gets.split.map(&:to_i)\na = [0]*(n+1)\ntt = [2000]*(n+1)\nm.times do\n l, r, t, c = gets.split.map(&:to_i)\n #p [l,r,t,c]\n l.upto(r) do |i|\n #p [i, tt[i], a[i]]\n if t < tt[i] || (t == tt[i] && a[i] < c)\n tt[i] = t\n a[i] = c\n end\n end\nend\np a.inject(0){|r,j| r+j}\n"}], "src_uid": "ea1bebf20f24a681f03082c92326db5e"} {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s\n", "positive_code": [{"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s\n"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s\n"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s\n"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s\n"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s\n"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s\n"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n else\n s[i,1] = '7'\n if i>0 && s[i-1,1]=='4'\n n = n&1\n n, s[i,1] = 0,'4' if(n==1)\n end\n end\n end\nend\nputs s\n"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n\t#print \" i : \", i, \", s[i] \", s[i], \", s[i+1] \", s[i+1], \"\\n\"\n\tif n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n\t\tn-=1\n\t\tif(i%2==0)\n\t\t\ts[i+1,1] = '4'\n\t\t\t#print \"bos : \", s, \"\\n\"\n\t\telse\n\t\t\ts[i,1] = '7'\n\t\t\t#print \"gas : \", s, \"\\n\"\n\t\t\tif i>0 && s[i-1,1]=='4'\n\t\t\t\tn = n&1\n\t\t\t\tn, s[i,1] = 0,'4' if(n==1)\n\t\t\t\t#print \"dis : \", s, \"\\n\"\n\t\t\t\t#n=0\n\t\t\tend\n\t\tend\n\tend\nend\n\nputs s"}], "negative_code": [{"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-1) do |i|\n #print \" i : \", i, \", s[i] \", s[i], \", s[i+1] \", s[i+1], \"\\n\"\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n #print \"bos : \", s, \"\\n\"\n else\n s[i,1] = '7'\n #print \"gas : \", s, \"\\n\"\n if i>0 && s[i-1,1]=='4' && n%2==1\n s[i,1] = '4'\n #print \"dis : \", s, \"\\n\"\n n=0\n end\n end\n end\nend\n\nputs s"}, {"source_code": "l,n = gets.split.collect{|x| x.to_i}\ns=gets\n0.upto(l-2) do |i|\n #print \" i : \", i, \", s[i] \", s[i], \", s[i+1] \", s[i+1], \"\\n\"\n if n!=0 && s[i,1]=='4' && s[i+1,1]=='7'\n n-=1\n if(i%2==0)\n s[i+1,1] = '4'\n #print \"bos : \", s, \"\\n\"\n else\n s[i,1] = '7'\n #print \"gas : \", s, \"\\n\"\n if i>0 && s[i-1,1]=='4' && n%2==1\n s[i,1] = '4'\n #print \"dis : \", s, \"\\n\"\n n=0\n end\n end\n end\nend\n\nputs s"}], "src_uid": "8ce1ba0a98031c1bc28f53c11905391c"} {"source_code": "t = gets.to_i\nans = []\nt.times do\n x1,y1,x2,y2 = gets.chomp.split(\" \").map(&:to_i)\n x = (x2-x1).abs + (y2-y1).abs\n if x1 != x2 && y1 != y2\n x += 2\n end\n ans << x\nend\nans.each do |v|\n puts v\nend", "positive_code": [{"source_code": "T = gets.to_i\n\nT.times do\n x1, y1, x2, y2 = gets.split.map(&:to_i)\n\n dx = (x2 - x1).abs\n dy = (y2 - y1).abs\n\n if dx == 0 && dy == 0\n puts 0\n elsif dx == 0\n puts dy\n elsif dy == 0\n puts dx\n else\n puts dx + dy + 2\n end\nend\n"}, {"source_code": "t = gets.chomp.to_i\nsa = 0\nt.times do\n a, b, c, d = gets.chomp.split(\" \").map(&:to_i)\n sa = 0\n if a == c || b == d\n puts (c-a).abs + (d-b).abs\n else\n sa = (c-a).abs + (d-b).abs + 2\n puts sa\n end\nend\n"}, {"source_code": "gets.to_i.times do\n x1, y1, x2, y2 = gets.split.map &:to_i\n puts (x2 - x1).abs + (y2 - y1).abs + (x1 == x2 || y1 == y2 ? 0 : 2)\nend"}, {"source_code": "gets;$<.map{|l|a,b,c,d=l.split.map &:to_i;p (a-c).abs+(b-d).abs+(a!=c&&b!=d ?2:0)}"}], "negative_code": [{"source_code": "gets;$<.map{|l|a,b,c,d=l.split.map &:to_i;p (a-c).abs+(b-d).abs+(a^b|(c^d)>0?0:2)}"}, {"source_code": "gets;$<.map{|l|a,b,c,d=l.split.map &:to_i;p (a-c).abs+(b-d).abs+(a^c|(b^d)>0?0:2)}"}, {"source_code": "gets;$<.map{|l|a,b,c,d=l.split.map &:to_i;p (a-c).abs+(b-d).abs+(a^c|(b^d)>0?2:0)}"}, {"source_code": "t = gets.chomp.to_i\nsa = 0\nt.times do\n a, b, c, d = gets.chomp.split(\" \").map(&:to_i)\n sa = (a-c).abs + (b-d).abs\n puts sa\nend\n"}, {"source_code": "t = gets.chomp.to_i\nsa = 0\nt.times do\n a, b, c, d = gets.chomp.split(\" \").map(&:to_i)\n sa = 0\n if a == c || b == d\n puts (c-a).abs + (d-b).abs\n else\n sa = (c-a).abs + (d-b).abs + 3\n puts sa\n end\nend\n"}, {"source_code": "gets.to_i.times do\n x1, y1, x2, y2 = gets.split.map &:to_i\n puts (x2 - x1).abs - (y2 - y1).abs + x1 == x2 || y1 == y2 ? 0 : 2\nend"}], "src_uid": "6a333044e2ed8f9f4fa44bc16b994418"} {"source_code": "t = gets.chomp.to_i\n\nt.times do |i|\n n, x = gets.chomp.split.map(&:to_i)\n max_d, max_diff = 0, 0\n n.times do |j|\n d, h = gets.chomp.split.map(&:to_i)\n max_d = [max_d, d].max\n max_diff = [max_diff, d-h].max\n end\n if max_d >= x\n puts 1\n elsif max_diff == 0\n puts -1\n else\n puts ((x-max_d).to_f/max_diff).ceil + 1\n end\nend\n", "positive_code": [{"source_code": "tt = gets.chomp.to_i\ntt.times.map do\n nn, xx = gets.split.map(&:to_i)\n # \u5dee\u5206\u304c\u5927\u304d\u3044\u9806\n dh = nn.times.map{gets.split.map(&:to_i)}.sort{|a,b|(b[0]-b[1])<=>(a[0]-a[1])}\n last = dh.sort{|a,b|b[0]<=>a[0]}[0][0]\n diff = dh[0][0]-dh[0][1]\n if last>=xx\n puts 1\n next\n elsif diff<=0\n puts -1\n next\n end\n cnt = 1 + ((xx-last)/diff.to_f).ceil\n puts cnt\nend"}], "negative_code": [], "src_uid": "36099a612ec5bbec1b95f2941e759c00"} {"source_code": "def solve\r\n n, u, r, d, l = ints\r\n (1 << 4).times.any? do |bits|\r\n lu, ru, ld, rd = (0 ... 4).map { |i| bits[i] == 1 }\r\n l_use = r_use = u_use = d_use = 0\r\n if lu\r\n l_use += 1\r\n u_use += 1\r\n end\r\n if ru\r\n r_use += 1\r\n u_use += 1\r\n end\r\n if ld\r\n l_use += 1\r\n d_use += 1\r\n end\r\n if rd\r\n r_use += 1\r\n d_use += 1\r\n end\r\n [l - l_use, r - r_use, u - u_use, d - d_use].all? { |x| 0 <= x and x <= n - 2}\r\n end\r\nend\r\n\r\ndef main\r\n t = int\r\n t.times do\r\n yesno solve\r\n end\r\nend\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\nYESNO = %w(NO YES)\r\nINF = 10**9\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts YESNO[1] end\r\ndef no; puts YESNO[0] end\r\ndef yesno t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, u, r, d, l = gets.split.map &:to_i\r\n ok = false\r\n 16.times do |msk|\r\n cu, cr, cd, cl = u, r, d, l\r\n if msk & 1 > 0\r\n cu -= 1\r\n cl -= 1\r\n end\r\n if msk & 2 > 0\r\n cl -= 1\r\n cd -= 1\r\n end\r\n if msk & 4 > 0\r\n cd -= 1\r\n cr -= 1\r\n end\r\n if msk & 8 > 0\r\n cr -= 1\r\n cu -= 1\r\n end\r\n if [cu, cr, cd, cl].min >= 0 && [cu, cr, cd, cl].max <= n - 2\r\n puts \"YES\"\r\n ok = true\r\n break\r\n end\r\n end\r\n puts \"NO\" if !ok\r\nend"}], "negative_code": [{"source_code": "def solve\n n, u, r, d, l = ints\n (1 << 4).times.any? do |bits|\n lu, ru, ld, rd = (0 ... 4).map { |i| bits[i] == 1 }\n l_use = r_use = u_use = d_use = 0\n if lu\n l_use += 1\n u_use += 1\n end\n if ru\n r_use += 1\n u_use += 1\n end\n if ld\n l_use += 1\n d_use += 1\n end\n if rd\n r_use += 1\n d_use += 1\n end\n possible = (l_use <= l and r_use <= r and u_use <= u and d_use <= d)\n possible &&= lu ? (l >= 1 and u >= 1) : (l <= n - 1 and u <= n - 1)\n possible &&= ru ? (r >= 1 and u >= 1) : (r <= n - 1 and u <= n - 1)\n possible &&= ld ? (l >= 1 and d >= 1) : (l <= n - 1 and d <= n - 1)\n possible &&= rd ? (r >= 1 and d >= 1) : (r <= n - 1 and d <= n - 1)\n possible &&= (lu and ru) ? (u >= 2) : true\n possible &&= (lu and ld) ? (l >= 2) : true\n possible &&= (ru and rd) ? (r >= 2) : true\n possible &&= (ld and rd) ? (d >= 2) : true\n possible\n end\nend\n\ndef main\n t = int\n t.times do\n yesno solve\n end\nend\n\nDEBUG = true\nMOD = 10**9+7\nYESNO = %w(NO YES)\nINF = 10**9\n\ndef int; gets.to_s.to_i end\ndef ints; gets.to_s.split.map { |s| s.to_i } end\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\ndef float; gets.to_s.to_f end\ndef floats; gets.to_s.split.map { |s| s.to_f } end\ndef array_of(&convert); gets.to_s.split.map(&convert) end\ndef string; gets.to_s.chomp end\ndef rep(n, &b); Array.new(n, &b) end\ndef yes; puts YESNO[1] end\ndef no; puts YESNO[0] end\ndef yesno t; puts YESNO[t] end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\ndef gcd(*xs); xs.inject(0, :gcd) end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\ndef if_debug; yield if DEBUG end\n\nmodule Boolean\n def coerce(other); [other, to_i] end\n def +@; to_i end\n def to_int; to_i end\n def *(other); to_i * other end\nend\n\nclass TrueClass\n include Boolean\n def to_i; 1 end\nend\n\nclass FalseClass\n include Boolean\n def to_i; 0 end\nend\n\nclass Integer\n def div_ceil(y); (self + y - 1) / y end\n def mod_inv(mod = MOD); pow(mod-2, mod) end\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\nend\n\nclass Array\n def power(&block); (0 ... 1 << size).each(&block) end\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\nend\n\nmodule Enumerable\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\nend\n\nmain"}, {"source_code": "def solve\r\n n, u, r, d, l = ints\r\n (1 << 4).times.any? do |bits|\r\n lu, ru, ld, rd = (0 ... 4).map { |i| bits[i] == 1 }\r\n possible = true\r\n possible &&= lu ? (l >= 1 and u >= 1) : (l <= n - 1 and u <= n - 1)\r\n possible &&= ru ? (r >= 1 and u >= 1) : (r <= n - 1 and u <= n - 1)\r\n possible &&= ld ? (l >= 1 and d >= 1) : (l <= n - 1 and d <= n - 1)\r\n possible &&= rd ? (r >= 1 and d >= 1) : (r <= n - 1 and d <= n - 1)\r\n possible &&= (lu and ru) ? (u >= 2) : true\r\n possible &&= (lu and ld) ? (l >= 2) : true\r\n possible &&= (ru and rd) ? (r >= 2) : true\r\n possible &&= (ld and rd) ? (d >= 2) : true\r\n possible\r\n end\r\nend\r\n\r\ndef main\r\n t = int\r\n t.times do\r\n yesno solve\r\n end\r\nend\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\nYESNO = %w(NO YES)\r\nINF = 10**9\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts YESNO[1] end\r\ndef no; puts YESNO[0] end\r\ndef yesno t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain"}, {"source_code": "def solve\r\n n, u, r, d, l = ints\r\n (1 << 4).times.any? do |bits|\r\n lu, ru, ld, rd = (0 ... 4).map { |i| bits[i] == 1 }\r\n possible = true\r\n possible &&= lu ? (l >= 1 and u >= 1) : (l <= n - 1 and u <= n - 1)\r\n possible &&= ru ? (r >= 1 and u >= 1) : (r <= n - 1 and u <= n - 1)\r\n possible &&= ld ? (l >= 1 and d >= 1) : (l <= n - 1 and d <= n - 1)\r\n possible &&= rd ? (r >= 1 and d >= 1) : (r <= n - 1 and d <= n - 1)\r\n possible\r\n end\r\nend\r\n\r\ndef main\r\n t = int\r\n t.times do\r\n yesno solve\r\n end\r\nend\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\nYESNO = %w(NO YES)\r\nINF = 10**9\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts YESNO[1] end\r\ndef no; puts YESNO[0] end\r\ndef yesno t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain"}, {"source_code": "def solve\n n, u, r, d, l = ints\n [[u, d, l, r], [u, d, r, l], [l, r, u, d], [l, r, d, u]].all? { |(x, y, z, w)|\n if x == n\n if y == n\n z >= 2 and w >= 2\n elsif y == n - 1\n z >= 2 and w >= 1\n else\n z >= 1 and w >= 1\n end\n elsif x == n - 1\n if y == n\n z >= 2 and w >= 1\n elsif y == n - 1\n z >= 2 or z >= 1 and w >= 1\n else\n z >= 1 or w >= 1\n end\n else\n if y == n\n z >= 1 and w <= n - 1\n elsif y == n - 1\n z >= 1 and w <= n - 2\n else\n z == n and w <= n - 2 or z == n - 1 and w <= n - 1 or z <= n - 2\n end\n end\n }\nend\n\ndef main\n t = int\n t.times do\n yesno solve\n end\nend\n\nDEBUG = true\nMOD = 10**9+7\nYESNO = %w(NO YES)\nINF = 10**9\n\ndef int; gets.to_s.to_i end\ndef ints; gets.to_s.split.map { |s| s.to_i } end\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\ndef float; gets.to_s.to_f end\ndef floats; gets.to_s.split.map { |s| s.to_f } end\ndef array_of(&convert); gets.to_s.split.map(&convert) end\ndef string; gets.to_s.chomp end\ndef rep(n, &b); Array.new(n, &b) end\ndef yes; puts YESNO[1] end\ndef no; puts YESNO[0] end\ndef yesno t; puts YESNO[t] end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\ndef gcd(*xs); xs.inject(0, :gcd) end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\ndef if_debug; yield if DEBUG end\n\nmodule Boolean\n def coerce(other); [other, to_i] end\n def +@; to_i end\n def to_int; to_i end\n def *(other); to_i * other end\nend\n\nclass TrueClass\n include Boolean\n def to_i; 1 end\nend\n\nclass FalseClass\n include Boolean\n def to_i; 0 end\nend\n\nclass Integer\n def div_ceil(y); (self + y - 1) / y end\n def mod_inv(mod = MOD); pow(mod-2, mod) end\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\nend\n\nclass Array\n def power(&block); (0 ... 1 << size).each(&block) end\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\nend\n\nmodule Enumerable\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\nend\n\nmain"}, {"source_code": "def solve\n n, u, r, d, l = ints\n [[u, d, l, r], [u, d, r, l], [l, r, u, d], [l, r, d, u]].all? { |(x, y, z, w)|\n if x == n\n if y == n\n z >= 2 and w >= 2\n elsif y == n - 1\n z >= 2 and w >= 1\n else\n z >= 1 and w >= 1\n end\n elsif x == n - 1\n if y == n\n z >= 2 and w >= 1\n elsif y == n - 1\n z >= 2 or z >= 1 and w >= 1\n else\n z >= 1 or w >= 1\n end\n else\n true\n end\n }\nend\n\ndef main\n t = int\n t.times do\n yesno solve\n end\nend\n\nDEBUG = true\nMOD = 10**9+7\nYESNO = %w(NO YES)\nINF = 10**9\n\ndef int; gets.to_s.to_i end\ndef ints; gets.to_s.split.map { |s| s.to_i } end\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\ndef float; gets.to_s.to_f end\ndef floats; gets.to_s.split.map { |s| s.to_f } end\ndef array_of(&convert); gets.to_s.split.map(&convert) end\ndef string; gets.to_s.chomp end\ndef rep(n, &b); Array.new(n, &b) end\ndef yes; puts YESNO[1] end\ndef no; puts YESNO[0] end\ndef yesno t; puts YESNO[t] end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\ndef gcd(*xs); xs.inject(0, :gcd) end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\ndef if_debug; yield if DEBUG end\n\nmodule Boolean\n def coerce(other); [other, to_i] end\n def +@; to_i end\n def to_int; to_i end\n def *(other); to_i * other end\nend\n\nclass TrueClass\n include Boolean\n def to_i; 1 end\nend\n\nclass FalseClass\n include Boolean\n def to_i; 0 end\nend\n\nclass Integer\n def div_ceil(y); (self + y - 1) / y end\n def mod_inv(mod = MOD); pow(mod-2, mod) end\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\nend\n\nclass Array\n def power(&block); (0 ... 1 << size).each(&block) end\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\nend\n\nmodule Enumerable\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\nend\n\nmain"}, {"source_code": "gets.to_i.times do\r\n n, u, r, d, l = gets.split.map &:to_i\r\n ok = false\r\n 16.times do |msk|\r\n cu, cr, cd, cl = u, r, d, l\r\n if msk & 1 > 0\r\n cu -= 1\r\n cl -= 1\r\n elsif msk & 2 > 0\r\n cl -= 1\r\n cd -= 1\r\n elsif msk & 4 > 0\r\n cd -= 1\r\n cr -= 1\r\n elsif msk & 8 > 0\r\n cr -= 1\r\n cu -= 1\r\n end\r\n if [cu, cr, cd, cl].min >= 0 && [cu, cr, cd, cl].max <= n - 2\r\n puts \"YES\"\r\n ok = true\r\n break\r\n end\r\n end\r\n puts \"NO\" if !ok\r\nend"}], "src_uid": "1c94596da439c56b56e59da36734a912"} {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nroads = Array.new(n) { [] }\nn.times do\n r = gets.split.map(&:to_i)\n r[0] -= 1\n r[1] -= 1\n roads[r[0]] << r[1]\n roads[r[1]] << r[0]\nend\n\neliminated = [false]*n\nloop {\n flag = false\n roads.each_with_index do |r, idx|\n next if eliminated[idx]\n cnt = 0\n r.each do |i|\n cnt += 1 if !eliminated[i]\n end\n if cnt == 1\n eliminated[idx] = true\n flag = true\n end\n end\n break if !flag\n}\nlp = []\neliminated.each_with_index do |e, i|\n lp << i if !e\nend\n\nres = [nil]*n\nq = []\nlp.each do |i|\n q << [i, 0]\nend\nwhile q.size > 0\n cur = q.shift\n next if res[cur[0]]\n\n res[cur[0]] = cur[1]\n roads[cur[0]].each do |nx|\n q << [nx, cur[1]+1] unless res[nx]\n end\nend\n\nputs res.join(' ')\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\ndef find_loop(roads, stack, pos, visited)\n stack = [0]\n visited = [false]*roads.size\n\n roads[pos].each do |nx|\n if visited[nx]\n if stack.size >= 2 && stack[-2] != nx && stack.index(nx)\n res = []\n while stack[-1] != nx\n res << stack.pop\n end\n res << stack.pop\n return res\n end\n else\n res = find_loop(roads, stack, nx, visited)\n return res if res\n end\n end\n visited[pos] = false\n stack.pop\n nil\nend\n\ndef dfs(roads, pos, cost, res)\n res[pos] = cost\n roads[pos].each do |nx|\n next if res[nx]\n dfs(roads, nx, cost+1, res)\n end\nend\n\nn = gets.to_i\nroads = Array.new(n) { [] }\nn.times do\n r = gets.split.map(&:to_i)\n r[0] -= 1\n r[1] -= 1\n roads[r[0]] << r[1]\n roads[r[1]] << r[0]\nend\n\neliminated = [false]*n\nloop {\n flag = false\n roads.each_with_index do |r, idx|\n next if eliminated[idx]\n cnt = 0\n r.each do |i|\n cnt += 1 if !eliminated[i]\n end\n if cnt == 1\n eliminated[idx] = true\n flag = true\n end\n end\n break if !flag\n}\nlp = []\neliminated.each_with_index do |e, i|\n lp << i if !e\nend\n\nres = [nil]*n\nq = []\nlp.each do |i|\n q << [i, 0]\nend\nwhile q.size > 0\n cur = q.shift\n next if res[cur[0]]\n\n res[cur[0]] = cur[1]\n roads[cur[0]].each do |nx|\n q << [nx, cur[1]+1] unless res[nx]\n end\nend\n\nputs res.join(' ')\n"}, {"source_code": "def cycle(node, e, r)\n que = [[node, r]]\n\n until que.empty?\n node, r = que.pop\n\n if r.include?(node)\n i = r.index(node)\n return r[i..-1]\n end\n\n e[node].each do |m|\n next if m == r.last\n\n que << [m, r+[node]]\n end\n end\n nil\nend\n\nn = gets.to_i\ne = {}\nwhile l = gets\n x, y = l.split.map(&:to_i)\n (e[x] ||= []) << y\n (e[y] ||= []) << x\nend\n\nc = cycle(1, e, [])\ndepth = {}\nc.each{|x| depth[x] = 0 }\ng = c\nwhile depth.size < n\n g2 = []\n g.each do |x| \n e[x].each do |y|\n if !depth[y]\n depth[y] = depth[x]+1\n g2 << y\n end\n end\n end\n g = g2\nend\n\nputs (1..n).map{|x|depth[x]}*\" \"\n"}], "negative_code": [], "src_uid": "2d4dbada60ebcf0bdaead8d0c1c0e2c1"} {"source_code": "#\u5c11\u8ba1\u7b97\u5c31\u662f\u6253\u6298\uff01\n#\u5b9e\u5728\u4e0d\u6210\uff0c\u6211\u81ea\u5df1\u628ac\u91cc\u9762\u7684merge sort\u642c\u8fc7\u6765\uff01\nnumber=gets.chomp.split\nn=number[0].to_i\nk=number[1].to_i\na=gets.chomp.split\nb=gets.chomp.split\nPair=Struct.new(:index,:value)\nindexed_ab=[]\nfor i in 0...n\n\tsome=Pair.new(i,a[i].to_i-b[i].to_i)\n\tindexed_ab< a.value }\n#\u65b0\u601d\u8def\u662f\u505a\u51fa\u4e00\u4e2a\u66ff\u6362!\n#use[i]=0\u8868\u793a\u4f7f\u7528\u6253\u6298\u524d\u7684\u4ef7\u683c\n#use[i]=1\u8868\u793a\u4f7f\u7528\u6253\u6298\u540e\u7684\u4ef7\u683c\n#for i in 0...n\n#\tprint \" #{indexed_ab[i].index} #{indexed_ab[i].value}\"\n#end\n#puts\ncost=0\nitem=n-k\nfor i in 0...n\n\tif indexed_ab[i].value>0 && item > 0\n\t\tcost+=b[indexed_ab[i].index].to_i\n\t\t#print \" #{b[indexed_ab[i].index]}\"\n\t\titem-=1\n\telse\n\t\tcost+=a[indexed_ab[i].index].to_i\n\t\t#print \" #{a[indexed_ab[i].index]}\"\n\tend\nend\n#puts\nputs cost\n", "positive_code": [{"source_code": "n, k = gets.split.map(&:to_i)\naa = gets.split.map(&:to_i)\nt = aa.inject(0, :+)\naa = aa.zip(gets.split.map(&:to_i)).map { |a, b| a - b }.sort\naa.push 0\nwhile aa[k] < 0 do\n k += 1\nend\np aa[k, n - k].inject(t, :-)"}, {"source_code": "n, k = gets.split.map(&:to_i)\nk = k.to_i\naa = gets.split.map(&:to_i)\nbb = aa.zip(gets.split.map(&:to_i)).map { |a, b| a - b }.sort\nbb.push 0\nwhile bb[k] < 0 do\n k += 1\nend\np aa.inject(bb[k, n - k].inject(0, :-), :+)"}, {"source_code": "ii = lambda { gets.split.map(&:to_i) }\nn, k = ii.call\nt = (aa = ii.call).inject(0, :+)\n(aa = aa.zip(ii.call).map { |a, b| a - b }.sort).push 0\nwhile aa[k] < 0 do k += 1 end\np aa[k, n - k].inject(t, :-)"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\na_week = gets.chomp.split.map(&:to_i)\nb_week = gets.chomp.split.map(&:to_i)\ndiff = []\nDiff = Struct.new(:index, :diff,:purchased)\nn.times do |i|\n diff << Diff.new(i,(a_week[i] - b_week[i]), false)\nend\ndiff.sort! { |num1, num2| num1.diff <=> num2.diff}\n\nnegatives = diff.count{ |num| num.diff < 0}\nminimum_money_spent = 0\n[k,negatives].max.times do |i|\n curr_item = diff[i]\n minimum_money_spent += a_week[curr_item.index]\n curr_item.purchased = true\nend\ndiff.each do |item|\n minimum_money_spent+= b_week[item.index] if item.purchased == false\nend\nputs minimum_money_spent\n"}, {"source_code": "#\u5c11\u8ba1\u7b97\u5c31\u662f\u6253\u6298\uff01\n#\u5b9e\u5728\u4e0d\u6210\uff0c\u6211\u81ea\u5df1\u628ac\u91cc\u9762\u7684merge sort\u642c\u8fc7\u6765\uff01\nnumber=gets.chomp.split\nn=number[0].to_i\nk=number[1].to_i\na=gets.chomp.split\nb=gets.chomp.split\nPair=Struct.new(:index,:value)\nindexed_ab=[]\nfor i in 0...n\n\tsome=Pair.new(i,a[i].to_i-b[i].to_i)\n\tindexed_ab< a.value }\n#\u65b0\u601d\u8def\u662f\u505a\u51fa\u4e00\u4e2a\u66ff\u6362!\nuse=Array.new(n,0)\n#use[i]=0\u8868\u793a\u4f7f\u7528\u6253\u6298\u524d\u7684\u4ef7\u683c\n#use[i]=1\u8868\u793a\u4f7f\u7528\u6253\u6298\u540e\u7684\u4ef7\u683c\n#for i in 0...n\n#\tprint \" #{indexed_ab[i].index} #{indexed_ab[i].value}\"\n#end\n#puts\nfor i in 0...(n-k)\n\tif indexed_ab[i].value>0\n\t\tuse[indexed_ab[i].index]=1\n\tend\nend\ncost=0\nfor i in 0...n\n\tif use[i]==0\n\t\tcost+=a[i].to_i\n\t\t#print \" #{a[i]}\"\n\telse\n\t\tcost+=b[i].to_i\n\t\t#print \" #{b[i]}\"\n\tend\nend\n#puts\nputs cost\n"}], "negative_code": [{"source_code": "#\u5c11\u8ba1\u7b97\u5c31\u662f\u6253\u6298\uff01\nnumber=gets.chomp.split\nn=number[0].to_i\nk=number[1].to_i\na=gets.chomp.split\nb=gets.chomp.split\nc=[]\nPair=Struct.new(:before,:after)\nfor i in 0...n\n\tsome=Pair.new(a[i].to_i,b[i].to_i)\n\tc< c[i].after && j< n-k\n\t\tbuy_after+= c[i].after\n\t\tj+=1\n\telse\n\t\tbuy_before+= c[i].before\n\tend\nend\nputs buy_before+buy_after\n\n#\u4e00\u4e2a\u601d\u8def\u662f\uff1asort\u4e00\u4e0b\uff0c\u5c31\u662f\u628aa,b\u4f5c\u4e3a\u6574\u4f53\u6765sort\uff01\n#\u53d6\u524dk\u4e2aaa\u7684\n#\u7b2c\u4e8c\u6b21\u8d2d\u4e70\uff0c\u5e94\u8be5\u4e70\u90a3\u4e9b\u5e74\u4ef7\u683c\u964d\u4f4e\u7684\uff01\n#\u6216\u8005\u540c\u65f6\u5904\u7406\uff0c\u9047\u5230\u4ef7\u683c\u964d\u4f4e\u7684\u5f53\u4f5c\u7b2c\u4e8c\u6b21\u8d2d\u4e70\uff0c\n#\u9047\u5230\u4ef7\u683c\u4e0d\u53d8\u7684\uff0c\u751a\u81f3\u5347\u9ad8\u7684\uff0c\u653e\u5728\u7b2c\u4e00\u6b21\u8d2d\u4e70\uff01\n"}, {"source_code": "#\u5c11\u8ba1\u7b97\u5c31\u662f\u6253\u6298\uff01\n#\u5b9e\u5728\u4e0d\u6210\uff0c\u6211\u81ea\u5df1\u628ac\u91cc\u9762\u7684merge sort\u642c\u8fc7\u6765\uff01\nnumber=gets.chomp.split\nn=number[0].to_i\nk=number[1].to_i\na=gets.chomp.split\nb=gets.chomp.split\nPair=Struct.new(:index,:value)\nindexed_ab=[]\nfor i in 0...n\n\tsome=Pair.new(i,a[i].to_i-b[i].to_i)\n\tindexed_ab< a.value }\n#\u65b0\u601d\u8def\u662f\u505a\u51fa\u4e00\u4e2a\u66ff\u6362!\nuse=Array.new(n,0)\n#use[i]=0\u8868\u793a\u4f7f\u7528\u6253\u6298\u524d\u7684\u4ef7\u683c\n#use[i]=1\u8868\u793a\u4f7f\u7528\u6253\u6298\u540e\u7684\u4ef7\u683c\n#for i in 0...n\n\t#print \" #{indexed_ab[i].index} #{indexed_ab[i].value}\"\n#end\n#puts\nfor i in 0...(n-k)\n\tif indexed_ab[i].value==0\n\t\tbreak\n\telse\n\t\tuse[indexed_ab[i].index]=1\n\tend\nend\ncost=0\nfor i in 0...n\n\tif use[i]==0\n\t\tcost+=a[i].to_i\n\t\t#print \" #{a[i]}\"\n\telse\n\t\tcost+=b[i].to_i\n\t\t#print \" #{b[i]}\"\n\tend\nend\n#puts\nputs cost\n"}, {"source_code": "#\u5c11\u8ba1\u7b97\u5c31\u662f\u6253\u6298\uff01\n#\u5b9e\u5728\u4e0d\u6210\uff0c\u6211\u81ea\u5df1\u628ac\u91cc\u9762\u7684merge sort\u642c\u8fc7\u6765\uff01\nnumber=gets.chomp.split\nn=number[0].to_i\nk=number[1].to_i\na=gets.chomp.split\nb=gets.chomp.split\nPair=Struct.new(:index,:value)\nindexed_a=[]\nfor i in 0...n\n\tsome=Pair.new(i,a[i].to_i)\n\tindexed_a< b.value }\nindexed_b.sort!{|a,b| a.value <=> b.value }\n#for i in 0...n\n#\tputs \"#{indexed_a[i].index} #{indexed_a[i].value}\"\n#end\n#for i in 0...n\n#\tputs \"#{indexed_b[i].index} #{indexed_b[i].value}\"\n#end\n#\nsee=Array.new(n,0)\ni=0\nj=0\ncost=0\nitem=n-k\nwhile true do\n\twhile i indexed_b[j].value\n\t\t\t#\u8fd9\u91cc\u6211\u4eec\u5728\u8fd8\u6709\u53ef\u4ee5\u4e70\u975e\u5fc5\u9700\u73b0\u5728\u4e70\u7684\u5546\u54c1\u7684\u989d\u5ea6\u65f6\uff0c\u53ef\u4ee5\u8d2d\u4e70\n\t\t\t#\u5982\u679c\u6ca1\u6709\u989d\u5ea6\u4e86\uff0c\u5c31\u65e0\u6cd5\u8d2d\u4e70\uff0c\u53ea\u80fd\u73b0\u5728\u5c31\u4e70\uff01\n\t\t\tif item > 0\n\t\t\t\tcost+=indexed_b[j].value\n\t\t\t\tsee[indexed_b[j].index]=1\n\t\t\t\titem-=1\n\t\t\t\tj+=1\n\t\t\telse\n\t\t\t\tj=n\n\t\t\tend\n\n\t\telse\n\t\t\tcost+=indexed_a[i].value\n\t\t\tsee[indexed_a[i].index]=1\n\t\t\ti+=1\n\t\tend\n\tend\nend\nputs cost\n"}, {"source_code": "#\u5c11\u8ba1\u7b97\u5c31\u662f\u6253\u6298\uff01\n#\u5b9e\u5728\u4e0d\u6210\uff0c\u6211\u81ea\u5df1\u628ac\u91cc\u9762\u7684merge sort\u642c\u8fc7\u6765\uff01\nnumber=gets.chomp.split\nn=number[0].to_i\nk=number[1].to_i\na=gets.chomp.split\nb=gets.chomp.split\nPair=Struct.new(:index,:value)\nindexed_ab=[]\nfor i in 0...n\n\tsome=Pair.new(i,a[i].to_i-b[i].to_i)\n\tindexed_ab< a.value }\n#\u65b0\u601d\u8def\u662f\u505a\u51fa\u4e00\u4e2a\u66ff\u6362!\n#use[i]=0\u8868\u793a\u4f7f\u7528\u6253\u6298\u524d\u7684\u4ef7\u683c\n#use[i]=1\u8868\u793a\u4f7f\u7528\u6253\u6298\u540e\u7684\u4ef7\u683c\n#for i in 0...n\n#\tprint \" #{indexed_ab[i].index} #{indexed_ab[i].value}\"\n#end\n#puts\ncost=0\nfor i in 0...n\n\tif indexed_ab[i].value>0\n\t\tcost+=b[indexed_ab[i].index].to_i\n\telse\n\t\tcost+=a[indexed_ab[i].index].to_i\n\tend\nend\nputs cost\n"}], "src_uid": "b5355e1f4439b198d2cc7dea01bc4bc3"} {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end\n############################################################\n\nn, m = gis\n\nb = [true] + [false] * m\n\nn.times do \n x, *y = gis\n y.each do |j|\n b[j] = true\n end\nend\n\nputs b.all? ? :YES : :NO\n", "positive_code": [{"source_code": "nm = gets.chomp.split.map(&:to_i)\nn = nm[0]\nm = nm[1]\nbulbs = []\nfor i in (0..n-1)\n\tbulbs[i] = gets.chomp.split.map(&:to_i)\nend\n\nturn_on = []\nfor i in (0..n-1)\n\tfor x in (1..bulbs[i][0])\n\t\tif turn_on.include?(bulbs[i][x]) == false\n\t\t\tturn_on << bulbs[i][x]\n\t\tend\n\tend\nend\n\nif turn_on.size == m\n\tprint \"YES\"\nelse\n\tprint \"NO\"\nend"}, {"source_code": "n,m=gets.split.map &:to_i\na=[]\n$<.map{|l|\n a += l.split[1..-1].map &:to_i\n}\nputs ([*1..m] - a) == [] ? \"YES\" : \"NO\"\n"}, {"source_code": "class Solver\n\tdef main\n\t\tn, m = gets.split.map { |x| x.to_i }\n\t\tf = Array.new(m + 1, false)\n\t\tn.times do\n\t\t\ta = gets.split.map { |x| x.to_i }\n\t\t\ta.shift\n\t\t\ta.each do |x|\n\t\t\t\tf[x] = true\n\t\t\tend\n\t\tend\n\t\tcnt = f.count(true)\n\t\tif cnt == m\n\t\t\tputs \"YES\"\n\t\telse\n\t\t\tputs \"NO\"\n\t\tend\n\tend\nend\nSolver.new.main"}, {"source_code": "#!/usr/bin/ruby\nn,m=gets.split.map(&:to_i)\na=[]\nn.times{a|=gets.split.map(&:to_i)[1..-1]}\nputs a.size==m ? :YES : :NO"}, {"source_code": "n, m = gets.split.map(&:to_i)\nbulbs = []\nn.times{ bulbs |= gets.split[1..-1] }\nputs bulbs.size == m ? 'YES' : 'NO'\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nbulbs = []\nn.times{ bulbs |= gets.split.map(&:to_i)[1..-1] }\nputs bulbs.size == m ? 'YES' : 'NO'\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nbulbs = Array.new(m, 0)\nn.times do\n a = gets.split.map(&:to_i)[1..-1]\n a.each{|x| bulbs[x] = 1}\nend\nputs bulbs.inject(:+) == m ? 'YES' : 'NO'\n"}, {"source_code": "n, m = gets.chomp.split(\" \").map(&:to_i)\nbulbs = []\nn.times do\n y = gets.chomp.split(\" \").map(&:to_i)\n x = y.shift\n bulbs += y\nend\nif bulbs.uniq.length == m then\n puts \"YES\"\nelse\n puts \"NO\"\nend\n"}, {"source_code": "_, nbulbs = ARGF.gets.chomp.split(\" \").map { |s| s.to_i }\n\non = Array.new(nbulbs + 1) { |e| FALSE }\non[0] = TRUE\n\nwhile line = ARGF.gets do\n conns = line.chomp.split(\" \").map {|s| s.to_i}\n conns.shift\n for c in conns do\n on[c] = TRUE\n end\nend\n\nif on.all? then puts \"YES\" else puts \"NO\" end\n"}, {"source_code": "a=gets.chomp.split(\" \")\nlight=[]\n1.upto(a[0].to_i) do\nb=gets.chomp.split(\" \")\nb.shift\nlight += b\nend\nlight.uniq!\nif light.length1\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n\r\n"}, {"source_code": "def method(n)\r\n while n % 2 == 0\r\n n /= 2\r\n end\r\n n != 1\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n puts method(n) ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "n = gets.chomp.to_i;\r\nwhile n != 0\r\n n = n-1;\r\n value = gets.chomp.to_i;\r\n # puts value.class\r\n#=begin\r\n while value%2 == 0 \r\n value = value/2;\r\n end\r\n if value > 1\r\n puts \"YES\"\r\n else\r\n puts \"NO\" \r\n end\r\n#=end\r\nend"}, {"source_code": "def is_power_of_two(n)\r\n while n\r\n if n % 2 == 0\r\n n /= 2\r\n elsif (n % 2 == 1) && (n > 1)\r\n return false\r\n elsif n == 1\r\n return true\r\n end\r\n end\r\n return true\r\nend\r\n\r\ntest_case = gets().to_i\r\ntest_case.times do\r\n n = gets().to_i\r\n if is_power_of_two(n)\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\nend"}], "negative_code": [{"source_code": "def is_power_of_two(n)\r\n loG = Math.log(n)/Math.log(2.0)\r\n if loG-loG.to_i === 0\r\n return true\r\n end\r\n return false\r\nend\r\n\r\ntest_case = gets().to_i\r\ntest_case.times do\r\n n = gets().to_f \r\n if is_power_of_two(n)\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\nend"}, {"source_code": "def is_power_of_two(n)\r\n loG = Math.log(n)/Math.log(2.0)\r\n if loG-loG.to_i === 0\r\n return true\r\n end\r\n return false\r\nend\r\n\r\ntest_case = gets().to_i\r\ntest_case.times do\r\n n = gets().to_f \r\n if n % 2.0 == 0.0 && is_power_of_two(n)\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\nend"}, {"source_code": "def is_power_of_two(n)\r\n loG = Math.log(n)/Math.log(2)\r\n if loG-loG.to_i === 0\r\n return true\r\n end\r\n return false\r\nend\r\n\r\ntest_case = gets().to_i\r\ntest_case.times do\r\n n = gets().to_i \r\n if n % 2 == 0 && is_power_of_two(n)\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\nend"}, {"source_code": "def is_power_of_two(n)\r\n if n === 2\r\n return true\r\n end\r\n while n\r\n n /= 2\r\n if n % 2 == 1\r\n return false\r\n end\r\n end\r\n return true\r\nend\r\n\r\ntest_case = gets().to_i\r\ntest_case.times do\r\n n = gets().to_i \r\n if n % 2 == 0 && is_power_of_two(n)\r\n puts \"NO\"\r\n else\r\n puts \"YES\"\r\n end\r\nend"}, {"source_code": "gets.to_i.times do\n puts gets.to_i%2 == 0 ? 'NO' : 'YES'\nend\n"}, {"source_code": "gets.to_i.times do\r\n n=gets.to_i\r\n if n.odd?&&n>1\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n\r\n"}], "src_uid": "f4958b4833cafa46fa71357ab1ae41af"} {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n grid = n.times.map { gets.chomp }\n ans = []\n\n if grid[0][1] == '0' && grid[1][0] == '0'\n ans << [n - 1, n - 2] if grid[n - 1][n - 2] == '0'\n ans << [n - 2, n - 1] if grid[n - 2][n - 1] == '0'\n elsif grid[0][1] == '1' && grid[1][0] == '1'\n ans << [n - 1, n - 2] if grid[n - 1][n - 2] == '1'\n ans << [n - 2, n - 1] if grid[n - 2][n - 1] == '1'\n elsif grid[0][1] == '0' && grid[1][0] == '1'\n if grid[n - 1][n - 2] == '0' && grid[n - 2][n - 1] == '0'\n ans << [0, 1]\n elsif grid[n - 1][n - 2] == '1' && grid[n - 2][n - 1] == '1'\n ans << [1, 0]\n elsif grid[n - 1][n - 2] == '0' && grid[n - 2][n - 1] == '1'\n ans << [1, 0]\n ans << [n - 1, n - 2]\n elsif grid[n - 1][n - 2] == '1' && grid[n - 2][n - 1] == '0'\n ans << [1, 0]\n ans << [n - 2, n - 1]\n end\n elsif grid[0][1] == '1' && grid[1][0] == '0'\n if grid[n - 1][n - 2] == '0' && grid[n - 2][n - 1] == '0'\n ans << [1, 0]\n elsif grid[n - 1][n - 2] == '1' && grid[n - 2][n - 1] == '1'\n ans << [0, 1]\n elsif grid[n - 1][n - 2] == '0' && grid[n - 2][n - 1] == '1'\n ans << [0, 1]\n ans << [n - 1, n - 2]\n elsif grid[n - 1][n - 2] == '1' && grid[n - 2][n - 1] == '0'\n ans << [0, 1]\n ans << [n - 2, n - 1]\n end\n end\n\n puts ans.size\n ans.each do |y, x|\n puts [y + 1, x + 1].join(' ')\n end\nend\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n arr = []\n n.times do \n arr << gets.chomp.split('').map(&:to_s)\n end\n i_f = n - 1\n inv = []\n case \n when arr[0][1] == arr[1][0]\n if arr[i_f][i_f - 1] == arr[0][1]\n inv << [i_f + 1, i_f]\n end\n if arr[i_f - 1][i_f] == arr[0][1]\n inv << [i_f, i_f + 1]\n end\n when arr[i_f][i_f - 1] == arr[i_f - 1][i_f]\n if arr[1][0] == arr[i_f][i_f - 1]\n inv << [2, 1]\n end\n if arr[0][1] == arr[i_f][i_f - 1]\n inv << [1, 2]\n end\n when arr[0][1] == arr[i_f - 1][i_f]\n inv << [1, 2]\n inv << [i_f + 1, i_f]\n when arr[0][1] == arr[i_f][i_f - 1]\n inv << [1, 2]\n inv << [i_f, i_f + 1]\n end\n puts inv.size\n inv.map{|x| puts x.join(' ')}\nend"}], "negative_code": [], "src_uid": "be60cca56505e4b04d24c9b4990553c7"} {"source_code": "_N, _S = gets.split.map &:to_i\n_A = gets.split.map &:to_i\nlb, ub, cost = 0, _N + 1, 0\nuntil lb + 1 == ub\n mb = lb + ub >> 1\n _C = (0..._N).collect { |i| _A[i] + (i + 1) * mb }.sort\n mc = _C[0, mb].reduce :+\n if mc <= _S\n lb, cost = mb, mc\n else\n ub = mb\n end\nend\nprint [lb, cost].join \" \"; puts", "positive_code": [{"source_code": "N, S = gets.split.map &:to_i\nA = gets.split.map &:to_i\nl, u, c = 0, N + 1, 0\nuntil l + 1 == u\n m = l + u >> 1\n f = (0...N).collect { |i| A[i] + (i + 1) * m }.sort[0, m].reduce :+\n f <= S ? (l, c = m, f) : u = m\nend\np l, c"}], "negative_code": [], "src_uid": "b1fd037d5ac6023ef3250fc487656db5"} {"source_code": "t = gets.to_i\nt.times do\n\ts,a,b,c = gets.split.map(&:to_i)\n\tputs s/c + s/c/a*b\nend\n", "positive_code": [{"source_code": "def max(s,a,b,c)\n r = (s/c)\n return r+(r/a)*b\nend\n\nt = gets.to_i\nt.times{\n s,a,b,c = gets.split.map(&:to_i)\n puts max(s,a,b,c)\n}"}, {"source_code": "gets;$<.each{|e|s,a,b,c=e.split.map &:to_i;p s/c/a*b+s/c}"}, {"source_code": "for i in 1..Integer(gets) \n s,a,b,c = gets.split.map{|x| Integer(x)}\n n = s/c;\n puts n + (n / a * b)\nend"}, {"source_code": "t = gets.to_i\nt.times do\n s, a, b, c = gets.split.map(&:to_i)\n num = s / c\n num += (num/a) * b\n puts num\nend"}, {"source_code": "gets.to_i.times do\n s,a,b,c=gets.split.map &:to_i\n x=s/c\n puts x+x/a*b\nend\n"}, {"source_code": "t = gets.to_i\nfor i in 0...t\n s, a, b, c = gets.split.map(&:to_i)\n q = s / c\n puts b * (q / a) + q\nend"}, {"source_code": "t = gets.to_i\nt.times do\n s, a, b, c = gets.split.map(&:to_i)\n x = s / c\n x = (x / a) * (a + b) + (x % a)\n puts x\nend"}, {"source_code": "t = gets.to_i\nt.times do\n s,a,b,c = gets.chomp.split.map(&:to_i)\n p (s/(a*c))*(a+b)+(s-(s/(a*c))*a*c)/c\nend"}, {"source_code": "t = gets.to_i\nt.times do\n s, a, b, c = gets.split.map &:to_i\n n = s/c\n puts n + n/a*b\nend\n"}], "negative_code": [{"source_code": "for i in 1..Integer(gets) \n s,a,b,c = gets.split.map{|x| Integer(x)}\n n = s/c;\n puts n + (n * b / a)\nend"}], "src_uid": "ec8060260a6c7f4ff3e6afc9fd248afc"} {"source_code": "n, a, b = gets.split.map{|x| x.to_i}\ns = gets.strip.split('')\nputs(s[a - 1] == s[b - 1] ? 0 : 1)\n", "positive_code": [{"source_code": "n, a, b = gets.split.map(&:to_i)\n\nairports = gets.chomp\n\nif (airports[a - 1] == '0' && airports[b - 1] == '0') || (airports[a - 1] == '1' && airports[b - 1] == '1')\n\tputs 0\nelse \n\tputs 1\nend"}, {"source_code": "n, a, b = gets.split.map(&:to_i)\nstr = gets.chomp\nputs str[a - 1] != str[b - 1] ? 1 : 0\n"}, {"source_code": "n,s,e = gets.split.map(&:to_i)\nroute = gets \nif route[s-1] == route[e-1] then puts \"0\" else puts \"1\" end \n "}, {"source_code": "n, a, b = gets.split(\" \").map(&:to_i)\ns = gets\na -= 1\nb -= 1\nputs s[a] == s[b] ? 0 : 1"}, {"source_code": "n, a, b = gets.strip.split.map(&:to_i)\nairports = gets.strip.split(\"\").map(&:to_i)\na -= 1\nb -= 1\nputs airports[a] ^ airports[b]\n"}, {"source_code": "n,a,b=gets.split.map{|e| e.to_i-1}\nx=gets.chomp\nputs (x[a]!=x[b])?1:0\n\n"}, {"source_code": "n,a,b = gets.chomp.split(\" \").map(&:to_i)\ns = gets.split(\"\")\nputs s[a-1] == s[b-1] ? 0 : 1\n"}, {"source_code": "n,a,b=gets.split.map &:to_i\ns=\" \"<< gets\nputs (s[a]==s[b] ? 0 : 1)\n"}, {"source_code": "input = Array.new\nwhile i = $stdin.gets\n input << i.strip\nend\n\nn_airports, start_id, target_id = input.shift.split.map(&:to_i)\nairports_companies = input.shift\n\ncost = airports_companies[start_id - 1].to_i - airports_companies[target_id - 1].to_i\nputs cost.abs\n"}, {"source_code": "n, a, b = gets.split.map( &:to_i )\ns = gets\np ( s[ a - 1 ] != s[ b - 1 ] ? 1 : 0 )\n"}, {"source_code": "n,a,b,s=$<.read.split\np s[a.to_i-1]!=s[b.to_i-1] ? 1 : 0"}], "negative_code": [{"source_code": "n, a, b = gets.split.map(&:to_i)\n\nairports = gets.chomp\n\nif (airports[a - 1] == 0 && airports[b - 1] == 0) || (airports[a - 1] == 1 && airports[b - 1] == 1)\n\tputs 0\nelse \n\tputs 1\nend"}, {"source_code": "n, a, b = gets.strip.split.map(&:to_i)\nairports = gets.strip.split(\"\").map(&:to_i)\nans = 0\na -= 1\nb -= 1\nif a != b && airports[a] != airports[b]\n j = a\n if a < b\n while airports[j] != airports[b]\n j += 1\n end\n else\n while airports[j] != airports[b]\n j -= 1\n end\n end\n ans += (a - j).abs\nend\nputs ans\n"}, {"source_code": "n, a, b = gets.strip.split.map(&:to_i)\nairports = gets.strip.split(\"\").map(&:to_i)\nfirst = airports.each_index.select { |i| airports[i] == 0 }.sort\nsecond = airports.each_index.select { |i| airports[i] == 1 }.sort\nans = 0\na -= 1\nb -= 1\nif a != b && airports[a] != airports[b]\n j = 0\n if a < b\n j = second.shift if airports[a] == 0\n j = first.shift if airports[a] == 1\n else\n j = second.pop if airports[a] == 0\n j = first.pop if airports[a] == 1\n end\n ans += (a - j).abs\nend\nputs ans\n"}, {"source_code": "n, a, b = gets.strip.split.map(&:to_i)\nairports = gets.strip.split(\"\").map(&:to_i)\nfirst = airports.each_index.select { |i| airports[i] == 0 }.sort\nsecond = airports.each_index.select { |i| airports[i] == 1 }.sort\nans = 0\na -= 1\nb -= 1\nif airports[a] != airports[b]\n if airports[a] == 0\n ans += (a - second.shift).abs\n else\n ans += (a - first.shift).abs\n end\nend\nputs ans\n"}], "src_uid": "081f30ac27739002855e9d2aebe804c7"} {"source_code": "o=gets.chomp\nk=0\nl=0\no.length.times do |i|\nif o[i]=='x'\n k+=1\nelse\n l+=1\nend\nend\nj=k-l\ng=l-k\nif k>l\n j.times do\n print \"x\"\n end\nelsif l>k\n g.times do\n print \"y\"\n end\nelse\n print \"\\n\"\nend", "positive_code": [{"source_code": "input = gets.chomp\n\nx = input.count 'x'\ny = input.count 'y'\n\nif x > y\n puts 'x'*(x-y)\nelse\n puts 'y'*(y-x)\nend"}, {"source_code": "s=gets.split(//)\n\na = 0\nb = 0\n\ns.each do |i|\n\ta += 1 if i == 'x'\n\tb += 1 if i == 'y'\nend\n\nputs 'x'*(a-b) if a > b\nputs 'y'*(b-a) if b > a\n"}, {"source_code": "s=gets;a,b=s.count(\"x\"),s.count(\"y\");puts a>b ?'x'*(a-b):'y'*(b-a)"}, {"source_code": "e=gets \nx=e.count(\"x\")\ny=e.count(\"y\")\nputs x>y ? 'x'*(x-y) : 'y'*(y-x) "}, {"source_code": "s = gets.chomp\ncntx = s.count(\"x\")\ncnty = s.count(\"y\")\nif cntx > cnty\n puts \"x\"*(cntx-cnty)\nelse\n puts \"y\"*(cnty-cntx)\nend\n"}, {"source_code": "a=gets.chomp\n\nx=a.count('x')\ny=a.count('y')\n\nif x>y\n puts 'x'*(x-y)\nelse\n puts 'y'*(y-x)\nend"}, {"source_code": "a=gets.chomp.chars.to_a\n\nx=a.count('x')\ny=a.count('y')\n\nif x>y\n puts 'x'*(x-y)\nelse\n puts 'y'*(y-x)\nend"}, {"source_code": "text = STDIN.gets\nx_count, y_count = 0, 0\ntext.length.times{|i|\n\tcase text[i,1]\n\twhen \"x\"\n\t\tx_count += 1\n\twhen \"y\"\n\t\ty_count += 1\n\tend\n}\nif x_count > y_count\n\tputs \"x\" * (x_count - y_count)\nelsif y_count > x_count\n\tputs \"y\" * (y_count - x_count)\nend"}, {"source_code": "s = gets.strip.split //\ny = 0\nx = 0\n0.upto(s.size-1) do |i|\n if s[i] == 'y'\n y += 1\n else\n x +=1\n end\nend\n\ny\nif y>x\n puts \"y\"*(y-x)\nelse\n puts \"x\"*(x-y)\nend\n"}, {"source_code": "count = [0, 0]\ngets.strip.each_char do |c|\n count[c == 'x' ? 0 : 1] += 1\nend\nif count[0] > count[1]\n puts \"x\" * (count[0] - count[1])\nelse\n puts \"y\" * (count[1] - count[0])\nend\n"}, {"source_code": "s=gets.to_s.chomp\ns.count('x')>s.count('y')? (print 'x'*(s.count('x')-s.count('y'))) : (print 'y'*(s.count('y')-s.count('x')))\n"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\n# $stdin = File.open(\"input.txt\")\n# $stdout = File.open(\"output.txt\", \"w\")\n\ns = gets.chomp\n\nx = s.count('x')\ny = s.count('y')\n\nif x > y\n puts \"x\" * (x - y)\nelse\n puts \"y\" * (y - x)\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\ns = STDIN.readline.strip\n\nx, y = s.count('x'), s.count('y')\n\nif x > y\n\tputs 'x'*(x-y)\nelse\n\tputs 'y'*(y-x)\nend\n"}, {"source_code": "s = gets.chomp\nx = s.count(\"x\")\ny = s.count(\"y\")\n\nif x > y\n puts \"x\"*(x-y)\nelse\n puts \"y\"*(y-x)\nend\n"}, {"source_code": "def run\n line = ARGF.readline.chomp\n\n x = 0; y = 0\n line.split(//).each do |c|\n x += 1 if c == 'x'\n y += 1 if c == 'y'\n end\n\n if x > y\n puts \"x\" * (x - y)\n else\n puts \"y\" * (y - x)\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "s = gets\nputs s.count(\"x\") > s.count(\"y\") ? \"x\" * (s.count(\"x\")-s.count(\"y\")) : \"y\" * (s.count(\"y\")-s.count(\"x\"))"}], "negative_code": [{"source_code": "\ufeff# -*- encoding: utf-8 -*-\n# $stdin = File.open(\"input.txt\")\n# $stdout = File.open(\"output.txt\", \"w\")\n\ns = gets.chomp\n\ns.gsub!(/yx/, \"xy\")\ns.gsub!(/xy/, \"\")\n\nputs s"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\n# $stdin = File.open(\"input.txt\")\n# $stdout = File.open(\"output.txt\", \"w\")\n\ndef op1(s)\n s.sub(/yx/, \"xy\")\nend\n\ndef op2(s)\n s.sub(/xy/, \"\")\nend\n\ns = gets.chomp\n\ns.gsub!(/yx/, \"\")\ns.gsub!(/xy/, \"\")\n\nputs s"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\n# $stdin = File.open(\"input.txt\")\n# $stdout = File.open(\"output.txt\", \"w\")\n\ndef op1(s)\n s.sub(/yx/, \"xy\")\nend\n\ndef op2(s)\n s.sub(/xy/, \"\")\nend\n\ns = gets.chomp\nloop do\n tmp = s\n s1 = op1(s)\n if s = s1\n s = s1\n else\n s = op2(s)\n end\n \n break if tmp == s \nend\n\nputs s"}, {"source_code": "s = gets\ns = s.gsub(\"xy\", \"\")\ns = s.gsub(\"yx\", \"xy\")\ns = s.gsub(\"xy\", \"\")\nputs s"}, {"source_code": "o=gets.chomp\nx=0\ny=0\no.length.times do |i|\nif o[i]=='x'\n x+=1\nelse\n y+=1\nend\nend\nif x>y\n x-y.times do\n print x\n end\nelsif y>x\n y-x.times do\n print y\n end\nelse\n print \"\\n\"\nend"}], "src_uid": "528459e7624f90372cb2c3a915529a23"} {"source_code": "gets.to_i.times do\r\n w,h,n=gets.split.map(&:to_i)\r\n c=1\r\n while w.even?\r\n w/=2\r\n c*=2\r\n end\r\n while h.even?\r\n h/=2\r\n c*=2\r\n end\r\n if c>=n\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n", "positive_code": [{"source_code": "def zeros(n)\n n.even? ? zeros(n >> 1) * 2 : 1\nend\n\ngets.to_i.times {\n w, h, n = gets.split.map!(&:to_i)\n puts n <= zeros(w) * zeros(h) ? \"YES\" : \"NO\"\n}\n"}, {"source_code": "def solve\r\n w, h, n = gets.split.map(&:to_i)\r\n x = 1\r\n while w > 0 and w.even?\r\n x <<= 1\r\n w >>= 1\r\n end\r\n while h > 0 and h.even?\r\n x <<= 1\r\n h >>= 1\r\n end\r\n puts (x >= n) ? \"YES\" : \"NO\"\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n solve\r\nend\r\n"}, {"source_code": "def method(v)\r\n res = 1\r\n res *= 2 while v % (2 * res) == 0\r\n res\r\nend\r\n\r\nt = gets.to_i\r\nt.times do\r\n w, h, n = gets.split.map { |x| x.to_i }\r\n puts n <= method(w) * method(h) ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "gets.to_i.times do\n\ta, b, n = gets.split.map(&:to_i)\n\tx, y = a, b\n\tx /= 2 while x.even?\n\ty /= 2 while y.even?\n\n\tputs (a / x) * (b / y) >= n ? 'YES' : 'NO'\nend\n"}, {"source_code": "require 'prime'\r\nt = gets.chomp.to_i\r\nt.times do\r\n w, h, n = gets.chomp.split(' ').map(&:to_i)\r\n res = 1\r\n while w % 2 == 0 || h % 2 == 0\r\n res *= 2\r\n if w % 2 == 0\r\n w /= 2\r\n else\r\n h /= 2\r\n end\r\n end\r\n puts n <= res ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "n = $stdin.gets.to_i\n\nn.times do\n w, h, x = $stdin.gets.split.map &:to_i\n wc = 1\n while w % 2 == 0\n wc *= 2\n w /= 2\n end\n\n hc = 1\n while h % 2 == 0\n hc *= 2\n h /= 2\n end\n\n if hc * wc >= x\n puts 'yes'\n else\n puts 'no'\n end\nend"}, {"source_code": "#!/usr/bin/env ruby\r\n\r\ndef count_num(len)\r\n res = 1\r\n while len.even? do\r\n res *= 2\r\n len /= 2\r\n end\r\n return res\r\nend\r\n\r\ntests_count = gets.to_i\r\ntests_count.times {\r\n w, h, n = gets.split.map &:to_i\r\n res = count_num(w) * count_num(h)\r\n puts res >= n ? \"YES\" : \"NO\"\r\n}"}, {"source_code": "gets.to_i.times do\r\n w, h, n = gets.split.map &:to_i\r\n res = 1\r\n while w % 2 == 0\r\n w /= 2\r\n res *= 2\r\n end\r\n while h % 2 == 0\r\n h /= 2\r\n res *= 2\r\n end\r\n puts res >= n ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "require \"prime\"\r\nt = gets.chomp.to_i\r\nt.times do\r\n w, h, n = gets.chomp.split(\" \").map(&:to_i)\r\n cnt_w = w.prime_division\r\n cnt_h = h.prime_division\r\n cnt = 1\r\n cnt_w.each do |i,j|\r\n if i == 2\r\n cnt *= i ** j\r\n end\r\n end\r\n cnt_h.each do |i,j|\r\n if i == 2\r\n cnt *= i ** j\r\n end\r\n end\r\n if cnt >= n\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend"}, {"source_code": "a = gets.to_i\r\nfor i in 1..a do\r\n b = gets.chop\r\n c = b.split(/ /).map(&:to_i)\r\n w = c[0]\r\n h = c[1]\r\n n = c[2]\r\n i = 0\r\n j = 0\r\n while w % 2 == 0\r\n i += 1\r\n w = w / 2\r\n end\r\n while h % 2 == 0\r\n j += 1\r\n h = h / 2\r\n end\r\n if 2 ** (i+j) >= n\r\n print(\"YES\", \"\\n\")\r\n else\r\n print(\"NO\", \"\\n\")\r\n end\r\nend"}], "negative_code": [{"source_code": "a = gets.to_i\r\nfor i in 1..a do\r\n b = gets.chop\r\n c = b.split(/ /).map(&:to_i)\r\n w = c[0]\r\n h = c[1]\r\n n = c[2]\r\n i = 0\r\n j = 0\r\n while w % 2 == 0\r\n i += 1\r\n w = w / 2\r\n end\r\n while h % 2 == 0\r\n j += 1\r\n h = h / 2\r\n end\r\n if ((i+1) * (j+1)) >= n\r\n print(\"YES\", \"\\n\")\r\n else\r\n print(\"NO\", \"\\n\")\r\n end\r\nend"}, {"source_code": "a = gets.to_i\r\nfor i in 1..a do\r\n b = gets.chop\r\n c = b.split(/ /).map(&:to_i)\r\n w = c[0]\r\n h = c[1]\r\n n = c[2]\r\n i = 0\r\n j = 0\r\n while w % 2 == 0\r\n i += 1\r\n w = w / 2\r\n end\r\n while h % 2 == 0\r\n j += 1\r\n h = h / 2\r\n end\r\n print(((i+1) * (j+1)) >= n, \"\\n\")\r\nend"}, {"source_code": "a = gets.to_i\r\nfor i in 1..a do\r\n b = gets.chop\r\n c = b.split(/ /).map(&:to_i)\r\n w = c[0]\r\n h = c[1]\r\n n = c[2]\r\n i = 0\r\n j = 0\r\n while w % 2 == 0\r\n i += 1\r\n w = w / 2\r\n end\r\n while h % 2 == 0\r\n j += 1\r\n h = h / 2\r\n end\r\n print(((i+1) * (j+1)) >= n)\r\nend"}, {"source_code": "require 'prime'\r\nt = gets.chomp.to_i\r\nt.times do\r\n w, h, n = gets.chomp.split(' ').map(&:to_i)\r\n w1 = Prime.prime_division(w)[0]\r\n h1 = Prime.prime_division(h)[0]\r\n res = 0\r\n res += 2 ** w1[1] if w1 && w1[0] == 2\r\n res += 2 ** h1[1] if h1 && h1[0] == 2\r\n puts n <= [res, 1].max ? \"YES\" : \"NO\"\r\nend"}, {"source_code": "require 'prime'\r\nt = gets.chomp.to_i\r\nt.times do\r\n w, h, n = gets.chomp.split(' ').map(&:to_i)\r\n w1 = Prime.prime_division(w)[0]\r\n h1 = Prime.prime_division(h)[0]\r\n res = 1\r\n res += 2 ** w1[1] if w1 && w1[0] == 2\r\n res += 2 ** h1[1] if h1 && h1[0] == 2\r\n puts n <= res ? \"YES\" : \"NO\"\r\nend"}], "src_uid": "a8201326dda46542b23dc4e528d413eb"} {"source_code": "n, k = gets.split.map &:to_i\nparticipation_count = gets.split.map &:to_i\n\nparticipation_count.sort!\n\nteams_count = 0\n(2 ... n).step(3) do |i|\n teams_count += 1 if participation_count[i] + k <= 5\nend\n\nputs teams_count\n", "positive_code": [{"source_code": "n, k = gets.split(' ').map(&:to_i)\nputs gets.split(' ',n).map(&:to_i).select{|x| x+k<=5}.count / 3"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].count{|x|x<6-k}/3\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\ny = gets.split.map(&:to_i)\ny.sort!\ni = 0\nwhile (i * 3 + 2 < n) && (y[i * 3 + 2] + k <= 5)\n\ti += 1\nend\nputs i"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].count{|x|x<6-k}/3"}, {"source_code": "n,k=gets.split.map &:to_i\nm=gets.split.map &:to_i\np=0\nm.each { |x| p+=1 if x+k<=5 }\nputs p/3"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].count{|x|x<6-k}/3\n"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].count{|x|x<6-k}/3"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (gets.split.map(&:to_i).select{|i| i<=5-k}.size)/3\n"}, {"source_code": "n,k = gets.split.map(&:to_i)\nputs (gets.split.map(&:to_i).select{|i| i<=5-k}.size)/3"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs (gets.split.map(&:to_i).select{|i| i<=5-k}.size)/3"}, {"source_code": "answer = 0\nn, k = gets.split.map(&:to_i)\ngets.split.map(&:to_i).each { |x| answer +=1 if k+x <= 5 }\nputs (answer/3).floor\n"}, {"source_code": "n, k = gets.split.map &:to_i\ncounter = 0\nputs gets.split.map { |x| x.to_i }.count { |x| x + k <= 5 } / 3\n"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].count{|x|x<6-k}/3\n"}, {"source_code": "(n , k) = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\ncnt = 0\narr.each do |num|\n if 5 - num >=k\n cnt+=1\n end\nend\nputs cnt / 3\n"}, {"source_code": "n, k = gets.split(' ').map(&:to_i)\na = gets.split(' ').map(&:to_i)\ncount = [0, 0, 0, 0, 0, 0]\nfor x in a\n count[x] += 1\nend\nsum = 0\n(6-k).times{|i|\n sum += count[i]\n}\nputs sum/3"}, {"source_code": "n, k = gets.split.map(&:to_i)\nys = gets.split.map(&:to_i)\n\nmembers = 0\nys.each do |y|\n if 5 - y >= k\n members += 1\n end\nend\nputs members / 3\n"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].count{|x|x<6-k}/3\n"}, {"source_code": "n, k = gets.chomp.split(/ /).map(&:to_i)\nstudents = gets.chomp.split(/ /).map(&:to_i)\nif n < 3\n puts \"0\"\nelse\n teams = []\n students.reject! { |s| s == 5 }\n students.reject! { |s| s > 5 - k }\n while students.length >= 3\n teams << students[0..2]\n (0..2).each do |s|\n students.delete_at s\n end\n end\n puts teams.length\nend\n"}, {"source_code": "n,k=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| 5-e.to_i}.count{|e| e>=k}\np x/3"}, {"source_code": "n,k = gets.split.map(&:to_i)\nputs gets.split.map(&:to_i).sort.count{|i| i + k <= 5} /3\n"}, {"source_code": "s, n, k = [0] + gets.chomp.split.map{|e| e.to_i}\n\ngets.chomp.split.map{|e| e.to_i}.sort.each_slice(3).to_a.each {|e| s += 1 if e.length == 3 and e.all? {|t| 5 - t >= k}}\n\nputs s"}, {"source_code": "#!/usr/bin/ruby\n\nclass Solver\n def solve()\n n, k = STDIN.gets.split(\" \").map(&:to_i)\n times = STDIN.gets.split(\" \").map(&:to_i)\n valid = 0\n times.each do |t|\n valid = valid + 1 if t + k <= 5\n end\n\n puts valid / 3\n end\nend\n\nSolver.new.solve()\n\n"}, {"source_code": "k=gets.split[1].to_i;a=gets.split.map &:to_i;p a.count{|x|x<6-k}/3"}, {"source_code": "n = gets.chomp\nn = n.split\nnumber_of_participants = n[0].to_i\ntimes_needed = n[1].to_i\npart = gets.chomp\nparticipated = part.split\n\npossible_teams = number_of_participants/3\ncount = 0\nfor i in (0..number_of_participants-1)\n\tif participated[i].to_i + times_needed <= 5\n\t\tcount += 1\n\tend\nend\n\nif count >= 3\n\tputs count/3\nelse\n\tputs 0\nend"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].count{|x|x<6-k}/3\n"}, {"source_code": "first_line = gets.split(\" \")\nn = first_line[0].to_i\nk = first_line[1].to_i\nys = gets.split(\" \").collect {|x| x.to_i}\ncount = 0\nfor i in ys\n if k + i <= 5\n count += 1\n end\nend\nputs (count / 3)"}, {"source_code": "line1=gets.chomp.split(\" \").map!{|x| x.to_i}\nn=line1[0];k=line1[1]\nline2=gets.chomp.split(\" \").map!{|x| x.to_i}\ndef Solve(list,k)\n list.select! {|x| 5-x>=k }\n puts list.size/3\nend\nSolve(line2,k)"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\nno_participations = gets.split(\" \").map(&:to_i)\ncount_hash = {}\n\nno_participations.each do |p|\n count_hash[p] ||= 0\n count_hash[p] += 1\nend\nres = 0\n(0..5-k).each do |i|\n res += count_hash[i] if count_hash[i]\nend\nputs res / 3"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort\nc = 0\na.each do |x|\n c += 1 if x + k <= 5\nend\nputs c / 3\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nputs gets.split.map(&:to_i).count{|x| x + k <= 5} / 3\n"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].count{|x|x<6-k}/3\n"}, {"source_code": "n, k = gets.split(' ').map(&:to_i)\na = gets.split(' ').map(&:to_i)\n\nputs(a.select { |x| x <= 5-k }.size.div(3))\n"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].count{|x|x<6-k}/3"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].select{|x|x<6-k}.size/3"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].count{|x|x<6-k}/3\n"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].count{|x|x<6-k}/3\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\n\nclass Solver\n def solve()\n ans = 0\n n, k = STDIN.gets.split(\" \").map(&:to_i)\n times = STDIN.gets.split(\" \").map(&:to_i)\n times.sort!\n i = 0\n while i <= times.length - 3\n a = times[i]\n b = times[i+1]\n c = times[i+2]\n max = [a, b, c].max\n if max + k <= 5\n ans += 1\n end\n i += 2\n end\n\n puts ans\n end\nend\n\nSolver.new.solve()\n\n"}, {"source_code": "n = gets.chomp\nn = n.split\nnumber_of_participants = n[0].to_i\ntimes_needed = n[1].to_i\npart = gets.chomp\nparticipated = part.split\n\npossible_teams = number_of_participants/3\ncount = 0\nfor i in (0..number_of_participants-1)\n\tif participated[i].to_i + times_needed <= 5\n\t\tcount += 1\n\tend\nend\n\nif count >= 3\n\tputs possible_teams\nelse\n\tputs 0\nend"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort\nc = 0\na.each do |x|\n c += 1 if x + k < 5\nend\nputs c / 3\n"}, {"source_code": "i=->{gets.split.map(&:to_i)}\n_,k=i[]\np i[].collect{|x|x<6-k}.size/3"}], "src_uid": "fbde1e2ee02055592ff72fb04366812b"} {"source_code": "class Result\n def initialize(score, order)\n @score = score\n @order = order\n end\n\n def score\n @score\n end\n\n def order\n @order\n end\nend\n\ndef read_next_line\n gets.chomp.split.map(&:to_i)\nend\n\nn = gets.to_i\nresults = Array.new(2 * n)\n(0...n).each { |i|\n r = read_next_line\n results[i] = Result.new(r[0], 0)\n results[i + n] = Result.new(r[1], 1)\n}\n\nresults.sort_by! { |result| result.score }\n\nwinners_count = Array.new(2, 0)\n(0...n).each { |i|\n winners_count[results[i].order] += 1\n}\n\nwinners_count.each { |count|\n puts ('1' * [count, n / 2].max).ljust(n, '0')\n}", "positive_code": [{"source_code": "# worst case: the first n (of both sf) advance;\n# best case: the first n/2 of each semi-final;\n\nn = gets.to_i\na = []\nb = []\nres = {'a'=>[], 'b'=>[]}\nn.times do |i|\n ai,bi = gets.split.map(&:to_i)\n a << ai\n b << bi\nend\n(n/2...n).each do |i|\n res['a'] << (a[i] < b[n-i-1] ? '1' : '0')\n res['b'] << (b[i] < a[n-i-1] ? '1' : '0')\nend\nputs Array.new(n/2){'1'}.concat(res['a']).join\nputs Array.new(n/2){'1'}.concat(res['b']).join\n"}], "negative_code": [], "src_uid": "bea30e4ba653b9d0af87fc79b9ec8b4f"} {"source_code": "n, m = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\nb = gets.chomp.split.map(&:to_i)\ni = 0\nj = 0\nwhile i < n && j < m\n i += 1 if a[i] <= b[j]\n j += 1\nend\nputs n - i\n", "positive_code": [{"source_code": "# http://codeforces.com/problemset/problem/387/B\n# Two pointers\n\nn, m = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\nb = gets.chomp.split.map(&:to_i)\n\ni, j = 0, 0\ncount = 0\n\nwhile i < n && j < m\n if a[i] <= b[j]\n i += 1\n count += 1\n end\n\n j += 1\nend\n\nputs n - count\n"}, {"source_code": "def solve(req, actual)\n i, j, req_size, act_size = [0, 0, req.size, actual.size]\n while i < req_size\n while j < act_size && actual[j] < req[i]\n j += 1\n end\n break if j == act_size\n i += 1\n j += 1\n end\n req_size - i\nend\n\nif __FILE__ == $0\n def read_next_line\n gets.chomp.split.map(&:to_i)\n end\n\n gets\n puts solve(read_next_line, read_next_line)\nend"}, {"source_code": "def read_data\n\ts = gets.chomp\n\ts.split.map &:to_i\nend\t\n\nn,m = read_data\na = read_data\nb = read_data\n\na.sort! { |x,y| y <=> x}\nb.sort! { |x,y| y <=> x}\n\nresult = 0\nindex = 0\n\nfor k in a\n\tif b[index] && b[index] >= k\n\t\tindex += 1\n\telse\n\t\tresult += 1\n\tend\nend\n\nputs result"}, {"source_code": "def checks(n_m, p1, p2)\n n_m = n_m.split.map(&:to_i)\n n = n_m[0]\n m = n_m[1]\n p1 = p1.split.map(&:to_i)\n p2 = p2.split.map(&:to_i)\n\n count = 0\n j = 0\n for i in (0..n - 1)\n for j in (j..m - 1)\n if p1[i] <= p2[j]\n count += 1\n j += 1\n break\n else\n j += 1\n end\n end\n end\n\n puts n - count\nend\n\nchecks(gets, gets, gets)\n"}, {"source_code": "n,m=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i)\nb=gets.chomp.split.map(&:to_i)\ni,j=0,0\nwhile i hardest\n res+=1\n else\n ps[next_hard]-=1\n end\n end\nend\n#puts \"sssssssssssS\"\nputs res\n"}, {"source_code": "def binSearch(find_in, left, right, value_to_find)\n best = -1\n \n while left <= right \n mid = (left + right) / 2\n \n if find_in[mid].to_i >= value_to_find\n best = mid\n right = mid - 1\n else \n left = mid + 1\n end\n\n end\n \n return best\nend\n\n\nn_m = gets.chomp.split(/ /)\nn = n_m[0].to_i\nm = n_m[1].to_i\n\nto_find = gets.chomp.split(/ /)\nfind_in = gets.chomp.split(/ /)\nextra = 0\n\nto_find.each do |i|\n pos = binSearch(find_in, 0, m - 1, i.to_i)\n\n if pos == -1\n extra += 1\n else \n for j in pos..m - 1 do\n find_in[j] = find_in[j + 1]\n end\n m -= 1\n end\nend\n\nputs extra"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\ncomp = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n\ndummy = Hash.new(0)\narr.each do |a|\n\tdummy[a] += 1 \nend\nans = 0\ncount = {}.merge!(dummy)\n# puts \"#{count}\"\ncomp.each do |c|\n\tkey = c if count[c] && count[c] != 0\n\tkey ||= count.keys.detect{|x| x > c && count[x] != 0}\n\t# puts \"key #{key}\"\n\tif key\n\t\tcount[key] -= 1\n\telse\n\t\tans += 1\n\tend\nend\n\nputs ans"}], "negative_code": [{"source_code": "def checks(n_m, p1, p2)\n n_m = n_m.split.map(&:to_i)\n n = n_m[0]\n m = n_m[1]\n p1 = p1.split.map(&:to_i)\n p2 = p2.split.map(&:to_i)\n\n count = 0\n for i in (0..n - 1)\n for j in (0..m - 1)\n if p1[i] <= p2[j]\n count += 1\n break\n end\n end\n end\n\n puts n - count\nend\n\nchecks(gets, gets, gets)\n"}, {"source_code": "def checks(n_m, p1, p2)\n n_m = n_m.split.map(&:to_i)\n n = n_m[0]\n m = n_m[1]\n p1 = p1.split.map(&:to_i).uniq\n p2 = p2.split.map(&:to_i)\n\n count = p1.size\n for i in (0..n - 1)\n for j in (0..m - 1)\n if p1[i] == p2[j]\n count -= 1\n break\n end\n end\n end\n if [0, 2, 3].include? count\n puts count\n else\n puts count\n puts p2\n end\nend\n\nchecks(gets, gets, gets)\n"}, {"source_code": "def checks(n_m, p1, p2)\n n_m = n_m.split.map(&:to_i)\n n = n_m[0]\n m = n_m[1]\n p1 = p1.split.map(&:to_i)\n p2 = p2.split.map(&:to_i)\n\n count = 0\n for i in (0..n - 1)\n for j in (0..m - 1)\n if p1[i] != p2[j]\n count += 1\n break\n end\n end\n end\n\n puts n - count\nend\n\nchecks(gets, gets, gets)\n"}, {"source_code": "def checks(n_m, p1, p2)\n n_m = n_m.split.map(&:to_i)\n n = n_m[0]\n m = n_m[1]\n p1 = p1.split.map(&:to_i).uniq\n p2 = p2.split.map(&:to_i)\n\n count = p1.size\n for i in (0..n - 1)\n for j in (0..m - 1)\n if p1[i] != p2[j]\n count += 1\n break\n end\n end\n end\n\n puts n - count\nend\n\nchecks(gets, gets, gets)\n"}, {"source_code": "def checks(n_m, p1, p2)\n n_m = n_m.split.map(&:to_i)\n n = n_m[0]\n m = n_m[1]\n p1 = p1.split.map(&:to_i)\n p2 = p2.split.map(&:to_i)\n\n count = 0\n for i in (0..n - 1)\n for j in (0..m - 1)\n if p1[i] == p2[j]\n count += 1\n break\n end\n end\n end\n\n puts n - count\nend\n\nchecks(gets, gets, gets)\n"}, {"source_code": "def checks(n_m, p1, p2)\n n_m = n_m.split.map(&:to_i)\n n = n_m[0]\n m = n_m[1]\n p1 = p1.split.map(&:to_i).uniq\n p2 = p2.split.map(&:to_i).uniq\n\n count = n\n for i in (0..n - 1)\n for j in (0..m - 1)\n if p1[i] == p2[j]\n count -= 1\n break\n end\n end\n end\n\n puts count\nend\n\nchecks(gets, gets, gets)\n"}, {"source_code": "def checks(n_m, p1, p2)\n n_m = n_m.split.map(&:to_i)\n n = n_m[0]\n m = n_m[1]\n p1 = p1.split.map(&:to_i).uniq\n p2 = p2.split.map(&:to_i).uniq\n\n count = p1.size\n for i in (0..n - 1)\n for j in (0..m - 1)\n if p1[i] == p2[j]\n count -= 1\n break\n end\n end\n end\n if [0, 2, 3].include? count\n puts count\n else\n puts p2\n end\nend\n\nchecks(gets, gets, gets)\n"}, {"source_code": "def checks(n_m, p1, p2)\n n_m = n_m.split.map(&:to_i)\n n = n_m[0]\n m = n_m[1]\n p1 = p1.split.map(&:to_i).uniq\n p2 = p2.split.map(&:to_i).uniq\n\n count = p1.size\n for i in (0..n - 1)\n for j in (0..m - 1)\n if p1[i] == p2[j]\n count -= 1\n break\n end\n end\n end\n\n puts count\nend\n\nchecks(gets, gets, gets)\n"}, {"source_code": "def checks(n_m, p1, p2)\n n_m = n_m.split.map(&:to_i)\n n = n_m[0]\n m = n_m[1]\n p1 = p1.split.map(&:to_i)\n p2 = p2.split.map(&:to_i)\n\n count = n\n for i in (0..n - 1)\n for j in (0..m - 1)\n if p1[i] == p2[j]\n count -= 1\n break\n end\n end\n end\n\n puts count\nend\n\nchecks(gets, gets, gets)\n"}, {"source_code": "def checks(n_m, p1, p2)\n n_m = n_m.split.map(&:to_i)\n n = n_m[0]\n m = n_m[1]\n p1 = p1.split.map(&:to_i)\n p2 = p2.split.map(&:to_i)\n\n count = 0\n for i in (0..n - 1)\n for j in (0..m - 1)\n if p1[i] <= p2[j]\n count += 1\n j += 1\n break\n else\n j += 1\n end\n end\n end\n\n puts n - count\nend\n\nchecks(gets, gets, gets)"}, {"source_code": "class ProblemA\n def initialize\n @dats = STDIN.read.split(\"\\n\")\n @n, @m = @dats[0].split(\" \").map(&:to_i)\n @a_arr = @dats[1].split(\" \").map(&:to_i) #need\n @b_arr = @dats[2].split(\" \").map(&:to_i) #prepared\n end\n\n def solve\n i,j = [0, 0]\n j_memoize = nil\n\n need = @a_arr\n had = @b_arr\n max_touch = need.length\n \n while i < need.length && j < had.length do\n if need[i] == had[j]\n max_touch -= 1\n i,j = i+1, j+1\n next\n elsif need[i] < had[j]\n i = i+1\n next\n else\n j = j+1\n next\n end\n end\n print max_touch\n end\nend\n\nsolver = ProblemA.new\nsolver.solve\n"}, {"source_code": "n,m=gets.chomp.split.collect{|a| a.to_i}\nns=gets.chomp.split.collect{|a| a.to_i}\nps=Hash.new(0)\ngets.chomp.split.collect{|a| ps[a.to_i]+=1 }\nnext_hard=0\nres=0\nfor i in 0..n-1\n if next_hard<=ns[i]\n next_hard=ns[i]+1\n end\n if ps[ns[i]] == 0\n while next_hard < n && ps[next_hard] == 0\n next_hard+=1\n end\n if next_hard >= n\n res+=1\n else\n ps[next_hard]-=1\n end\n end\nend\n\nputs res\n"}, {"source_code": "n,m=gets.chomp.split.collect{|a| a.to_i}\nns=gets.chomp.split.collect{|a| a.to_i}\nps=Hash.new(0)\ngets.chomp.split.collect{|a| ps[a.to_i]+=1 }\nnext_hard=0\nhardest=ps.keys.max\nres=0\nns.each_index do |i|\n if next_hard<=ns[i]\n next_hard=ns[i]+1\n end\n if ps[ns[i]] == 0\n# puts i,next_hard\n while next_hard <= n && ps[next_hard] == 0\n next_hard+=1\n end\n# puts next_hard\n # puts \"saaaaaaaaaaa\" \n if next_hard > hardest\n res+=1\n else\n ps[next_hard]-=1\n end\n end\nend\n#puts \"sssssssssssS\"\nputs res\n"}, {"source_code": "n,m=gets.chomp.split.collect{|a| a.to_i}\nns=gets.chomp.split.collect{|a| a.to_i}\nps=Hash.new(0)\ngets.chomp.split.collect{|a| ps[a.to_i]+=1 }\nnext_hard=0\nres=0\nfor i in 0..n-1\n if next_hard<=ns[i]\n next_hard=ns[i]+1\n end\n if ps[ns[i]] == 0\n # puts i,next_hard\n while next_hard <= n && ps[next_hard] == 0\n next_hard+=1\n end\n # puts next_hard\n# puts \"saaaaaaaaaaa\" \n if next_hard > n\n res+=1\n else\n ps[next_hard]-=1\n end\n end\nend\n#puts \"sssssssssssS\"\nputs res\n"}, {"source_code": "n_m_s = gets.chomp\nn_m_a = n_m_s.split(/ /)\n\nto_find_s = gets.chomp\nto_find_a = to_find_s.split(/ /)\n\nfind_in_s = gets.chomp\nfind_in_a = find_in_s.split(/ /)\n\nhash = Hash.new(0)\n\nfind_in_a.each do |i|\n hash[i] += 1\nend\n\nextra = 0\n\nto_find_a.each do |i|\n hash[i] -= 1\n if hash[i] < 0\n hash[i] = 0\n extra += 1\n end\nend\n\nputs extra"}, {"source_code": "n,m = gets.split(\" \").map(&:to_i)\ncomp = gets.split(\" \").map(&:to_i)\narr = gets.split(\" \").map(&:to_i)\n\ndummy = Hash.new(0)\narr.each do |a|\n\tdummy[a] += 1 \nend\nans = 0\ncount = {}.merge!(dummy)\n# puts \"#{count}\"\ncomp.each do |c|\n\tkey = c if count[c] \n\tkey ||= count.keys.detect{|x| x > c && count[x] != 0}\n\t# puts \"key #{key}\"\n\tif key\n\t\tcount[key] -= 1\n\telse\n\t\tans += 1\n\tend\nend\n\nputs ans"}, {"source_code": "# http://codeforces.com/problemset/problem/387/B\n# Two pointers\n\nn, m = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\nb = gets.chomp.split.map(&:to_i)\ncount = 0\n\nfor i in 0..(n - 1)\n for j in 0..(m - 1)\n if a[i] == b[j]\n count += 1\n break\n end\n end\nend\n\nputs n - count\n"}, {"source_code": "# http://codeforces.com/problemset/problem/387/B\n# Two pointers\n\nn, m = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\nb = gets.chomp.split.map(&:to_i)\n\ni, j = 0, 0\ncount = 0\n\nwhile i < n && j < m\n if b[j] == a[i]\n count += 1\n i += 1\n j += 1\n elsif b[j] > a[i]\n i += 1\n else\n j += 1\n end\nend\n\nputs n - count\n"}, {"source_code": "# http://codeforces.com/problemset/problem/387/B\n# Two pointers\nn, m = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\nb = gets.chomp.split.map(&:to_i)\ncount = 0\n\nfor i in 0..(n - 1)\n for j in 0..(m - 1)\n if a[i] == b[j]\n count += 1\n break\n end\n end\nend\n\nputs n - count\n"}], "src_uid": "bf0422de4347a308d68a52421fbad0f3"} {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2m\r\n c=1\r\n q=aa\r\n else\r\n c+=1\r\n end\r\n end\r\n m=c if c>m\r\n puts m\r\nend\r\n"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n a = gets.split.map {|x| x.to_i }\r\n puts a.map { |x| a.count(x) }.max\r\nend"}], "negative_code": [], "src_uid": "6d4744d7356e709f73891270becd14e3"} {"source_code": "# coding: utf-8\nn = gets.to_i\nmap = n.times.map {|i|\n gets.chomp.chars.map{|c|\n c == \".\"\n }.each_with_index.map{|c, j|\n [i.next, j.next, c]\n }\n}\ncheck = proc {|line| line.any?(&:last) }\nanswer = proc {|line| puts line.find(&:last).first(2).join \" \" }\nif map.all?(&check)\n map.each(&answer)\nelsif map.transpose.all?(&check)\n map.transpose.each(&answer)\nelse\n puts -1\nend\n", "positive_code": [{"source_code": "n=gets.to_i\nm=[]\nf=false\nn.times do\n m << gets.chomp.split('')\n f=true if !m.last.include?('.')\nend\nm=m.transpose if f\nf2=false\nm.each {|x| f2=true if !x.include?('.')}\nif f and f2\n puts -1\n exit\nend\nm.each_with_index do |x,i|\n a=x.index('.')+1\n b=i+1\n if f\n puts \"#{a} #{b}\"\n else\n puts \"#{b} #{a}\"\n end\nend"}, {"source_code": "#!/usr/bin/env ruby\ndef cal_purify(pos, vis, n)\n num = 0\n num += 1 if !vis[pos[0]][pos[1]]\n for i in 1..n\n num += 1 if pos[0] - i >= 0 && !vis[pos[0] - i][pos[1]]\n num += 1 if pos[0] + i < n && !vis[pos[0] + i][pos[1]]\n num += 1 if pos[1] - i >= 0 && !vis[pos[0]][pos[1] - i]\n num += 1 if pos[1] + i < n && !vis[pos[0]][pos[1] + i]\n end\n return num\nend\n\ndef purify(pos, vis, n)\n vis[pos[0]][pos[1]] = true\n for i in 1..n\n vis[pos[0] - i][pos[1]] = true if pos[0] - i >= 0\n vis[pos[0] + i][pos[1]] = true if pos[0] + i < n \n vis[pos[0]][pos[1] - i] = true if pos[1] - i >= 0\n vis[pos[0]][pos[1] + i] = true if pos[1] + i < n\n end\nend\nn = gets.to_i\nmap = []\nn.times do\n map << gets.chomp!\nend\ncan_purify = []\nfor i in 0...map.size\n for j in 0...map[i].size\n if map[i][j] != 'E'\n can_purify << [i, j]\n end\n end\nend\nrowvis = Array.new(n + 1, false)\ncolvis = Array.new(n + 1, false)\nrowcnt = colcnt = 0\ncan_purify.each do |pos|\n if !rowvis[pos[0]]\n rowcnt += 1\n rowvis[pos[0]] = true\n end\n if !colvis[pos[1]]\n colcnt += 1\n colvis[pos[1]] = true\n end\nend\nresult = []\nvis = Array.new(n + 1, false)\nif rowcnt == n\n can_purify.each do |pos|\n if !vis[pos[0]]\n result << pos\n vis[pos[0]] = true\n end\n end\nelsif colcnt == n\n can_purify.each do |pos|\n if !vis[pos[1]]\n result << pos\n vis[pos[1]] = true\n end\n end\nend\nif result.size != n\n puts \"-1\"\nelse\n result.each do |step|\n step[0] += 1\n step[1] += 1\n puts step.join(' ')\n end\nend"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\nmap, can_purify = [], []\nn.times do\n map << gets.chomp!\nend\nfor i in 0...map.size\n for j in 0...map[i].size\n can_purify << [i, j] if map[i][j] != 'E'\n end\nend\nrowvis, colvis = Array.new(n + 1, false), Array.new(n + 1, false)\nrowcnt = colcnt = 0\ncan_purify.each do |pos|\n rowvis[pos[0]] = true if !rowvis[pos[0]]\n colvis[pos[1]] = true if !colvis[pos[1]]\nend\nresult = []\nvis = Array.new(n + 1, false)\nif rowvis.count(true) == n\n can_purify.each do |pos|\n next if result.include? pos[0]\n puts \"#{pos[0] + 1} #{pos[1] + 1}\"\n result << pos[0]\n end\nelsif colvis.count(true) == n\n can_purify.each do |pos|\n next if result.include? pos[1]\n puts \"#{pos[0] + 1} #{pos[1] + 1}\"\n result << pos[1]\n end\nelse\n puts \"-1\"\nend"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\nmap = []\nn.times do\n map << gets.chomp!\nend\ncan_purify = []\nfor i in 0...map.size\n for j in 0...map[i].size\n if map[i][j] != 'E'\n can_purify << [i, j]\n end\n end\nend\nrowvis = Array.new(n + 1, false)\ncolvis = Array.new(n + 1, false)\nrowcnt = colcnt = 0\ncan_purify.each do |pos|\n if !rowvis[pos[0]]\n rowcnt += 1\n rowvis[pos[0]] = true\n end\n if !colvis[pos[1]]\n colcnt += 1\n colvis[pos[1]] = true\n end\nend\nresult = []\nvis = Array.new(n + 1, false)\nif rowcnt == n\n can_purify.each do |pos|\n if !vis[pos[0]]\n result << pos\n vis[pos[0]] = true\n end\n end\nelsif colcnt == n\n can_purify.each do |pos|\n if !vis[pos[1]]\n result << pos\n vis[pos[1]] = true\n end\n end\nend\nif result.size != n\n puts \"-1\"\nelse\n result.each do |step|\n step[0] += 1\n step[1] += 1\n puts step.join(' ')\n end\nend"}, {"source_code": "n=gets.to_i\ns=[]\nn.times { s<= n\n n.times{|i| puts [i+1, ans[i]+1].join(\" \")}\n exit\nend\nans.clear\ns = s.transpose\nn.times do |i|\n ans.push(s[i].index(\".\")) if s[i].index(\".\")\nend\nif ans.size >= n\n n.times{|i| puts [ans[i]+1, i+1].join(\" \")}\n exit\nend\nputs \"-1\"\n"}, {"source_code": "n=gets.to_i\nm=[]\nf=false\nn.times do\n m << gets.chomp.split('')\n f=true if !m.last.include?('.')\nend\nm=m.transpose if f\nf2=false\nm.each {|x| f2=true if !x.include?('.')}\nif f and f2\n puts -1\n exit\nend\nm.each_with_index do |x,i|\n a=x.index('.')+1\n b=i+1\n if f\n puts \"#{a} #{b}\"\n else\n puts \"#{b} #{a}\"\n end\nend"}, {"source_code": "n = gets.to_i\na = Array.new(n).map! { gets.chomp.split(//) }\nb = a.transpose\n\ndef can(a)\n a.each do |e|\n return false if e.count('.') == 0\n end\n true\nend \n\nif can(a)\n a.each_with_index do |e, i|\n puts \"#{i+1} #{e.index('.')+1}\"\n end\nelsif can(b)\n b.each_with_index do |e, i|\n puts \"#{e.index('.')+1} #{i+1}\"\n end\nelse\n puts -1\nend"}, {"source_code": "n = gets.to_i\na = Array.new(n).map! { gets.chomp.split(//) }\nb = a.transpose\n# puts a.inspect\n\ndef can(a)\n a.each do |e|\n return false if e.count('.') == 0\n end\n true\nend \n\nif can(a)\n a.each_index do |i|\n puts \"#{i+1} #{a[i].index('.')+1}\"\n end\nelsif can(b)\n b.each_index do |i|\n puts \"#{b[i].index('.')+1} #{i+1}\"\n end\nelse\n puts -1\nend"}, {"source_code": "n = gets.to_i\ns = Array.new(n)\nn.times{|i| s[i] = gets.chomp.split(\"\")}\nans = Array.new\nn.times do |i|\n ans.push(s[i].index(\".\")) if s[i].index(\".\")\nend\nif ans.size >= n\n n.times{|i| puts [i+1, ans[i]+1].join(\" \")}\n exit\nend\nans.clear\ns = s.transpose\nn.times do |i|\n ans.push(s[i].index(\".\")) if s[i].index(\".\")\nend\nif ans.size >= n\n n.times{|i| puts [ans[i]+1, i+1].join(\" \")}\n exit\nend\nputs \"-1\"\n"}], "negative_code": [{"source_code": "n = gets.to_i\na = Array.new(n).map! { gets.chomp.split(//) }\nb = a.transpose\n# puts a.inspect\n\ndef can(a)\n a.each do |e|\n return false if e.count('.') == 0\n end\n true\nend \n\nif can(a)\n a.each_index do |i|\n puts \"#{i+1} #{a[i]}.index('.')+1}\"\n end\nelsif can(b)\n b.each_index do |i|\n puts \"#{b[i].index('.')+1} #{i+1}\"\n end\nelse\n puts -1\nend"}, {"source_code": "n = gets.to_i\na = Array.new(n).map! { gets.chomp.split(//) }\nb = a.transpose\n# puts a.inspect\n\ndef can(a)\n a.each do |e|\n return false if e.count('.') == 0\n end\n true\nend \n\nif can(a)\n a.each_index do |i|\n puts \"#{i} #{a[i].index('.')}\"\n end\nelsif can(b)\n b.each_index do |i|\n puts \"#{b[i].index('.')} #{i}\"\n end\nelse\n puts -1\nend"}, {"source_code": "n = gets.to_i\ns = Array.new(n)\nn.times{|i| s[i] = gets.chomp.split(\"\")}\nans = Array.new\nn.times do |i|\n ans.push(s[i].index(\".\")) if s[i].index(\".\")\nend\nif ans.size >= n\n n.times{|i| puts [i+1, ans[i]+1].join(\" \")}\n exit\nend\nans.clear\ns = s.transpose\nn.times do |i|\n ans.push(s[i].index(\".\")) if s[i].index(\".\")\nend\nif ans.size >= n\n n.times{|i| puts [i+1, ans[i]+1].join(\" \")}\n exit\nend\nputs \"-1\"\n"}, {"source_code": "n = gets.to_i\ns = Array.new(n)\nn.times{|i| s[i] = gets.chomp.split(\"\")}\nans = Array.new\nn.times do |i|\n ans.push(s[i].index(\".\")) if s[i].index(\".\")\nend\nif ans.size >= n\n n.times{|i| puts [i+1, ans[i]+1].join(\" \")}\n exit\nend\nans.clear\ns.transpose\nn.times do |i|\n ans.push(s[i].index(\".\")) if s[i].index(\".\")\nend\nif ans.size >= n\n n.times{|i| puts [i+1, ans[i]+1].join(\" \")}\n exit\nend\nputs \"-1\"\n"}, {"source_code": "n=gets.to_i\nok=true\nres=[]\n1.upto(n) {|i|\n s=gets.chomp\n k=s.index(?.)\n if k\n res<<[i, k+1]\n else\n ok=false\n end\n}\nif ok\n res.each {|v|\n puts v*' '\n }\nelse\n p -1\nend\n"}, {"source_code": "n = gets.to_i\nmap = n.times.map {|i| gets.chomp.chars.to_a }\ncheck = proc {|line| line.include? \".\" }\nwrite = proc {|line, i|\n safe = line.each_with_index.find{|cell| cell.first == \".\" }\n puts [i.next, safe.last.next].join ' '\n}\nputs map.inspect,map.transpose.inspect\nif map.all?(&check)\n map.each_with_index(&write)\nelsif map.transpose.all?(&check)\n map.transpose.each_with_index(&write)\nelse\n puts -1\nend\n"}, {"source_code": "n = gets.to_i\nmap = n.times.map {|i| gets.chomp.chars.to_a }\ncheck = proc {|line| line.include? \".\" }\nwrite = proc {|line, i|\n safe = line.each_with_index.find{|cell| cell.first == \".\" }\n puts [i.next, safe.last.next].join ' '\n}\nif map.all?(&check)\n map.each_with_index(&write)\nelsif map.transpose.all?(&check)\n map.transpose.each_with_index(&write)\nelse\n puts -1\nend\n"}], "src_uid": "18554f1bb56e192d9a4bc75047fa5df5"} {"source_code": "n=gets.to_i\na=[r=0]\ngets.chomp.chars{|c|\n\ta< 2\n for i in 2...coordinate_movements.count\n if coordinate_movements[i-1][0] == coordinate_movements[i-1][1]\n payment += 1 if ((coordinate_movements[i - 2][0] == coordinate_movements[i][0]) && (coordinate_movements[i][1] - coordinate_movements[i - 2][1] == 2)) || ((coordinate_movements[i - 2][1] == coordinate_movements[i][1]) && (coordinate_movements[i][0] - coordinate_movements[i - 2][0] == 2))\n end\n end\nend\n\nputs payment\n"}], "negative_code": [{"source_code": "n=gets.to_i\na=[r=0]\ngets.chars{|c|\n\ta<= 0 && $visited[r-1][c].zero? && block_check(arr, r-1, c)\n ways << [-1,0]\n elsif (c+1) < arr[0].size && $visited[r][c+1].zero? && block_check(arr, r, c+1)\n ways << [0,1]\n elsif (c-1) >= 0 && $visited[r][c-1].zero? && block_check(arr, r, c-1)\n ways << [0,-1]\n end\n ways\nend\n\ndef block_check(arr, r, c)\n return false unless r >= 0 && (r+1) < arr.size && c >= 0 && (c+1) < arr[0].size\n unless 4 == ($color[r][c] + $color[r+1][c] + $color[r][c+1] + $color[r+1][c+1])\n return 4 == (arr[r][c] + arr[r+1][c] + arr[r][c+1] + arr[r+1][c+1])\n end\n false\nend\n\ndef get_each(str)\n arr = Array.new\n num = 0\n str.each_char do |e|\n if e == ' '\n arr << num\n num = 0\n else\n num = num * 10 + e.to_i\n end\n end\n arr << num #unless num.zero?\n arr\nend\n\nboard\n"}, {"source_code": "$visited = nil\n$color = nil\n\ndef board\n nm = get_each gets.chomp\n n = nm[0]\n m = nm[1]\n a = Array.new\n $color = Array.new(n) { Array.new(m, 0)}\n $visited = Array.new(n) { Array.new(m, 0) }\n\n n.times do\n row = get_each(gets.chomp)\n a << row\n end\n coord = start_coord(a, n, m)\n if coord.empty?\n puts 0\n return\n end\n result = collect_result(coord, a)\n if result == -1 || !color_match(a)\n puts -1\n return\n end\n puts result.count\n 0.upto(result.size-1) do |i|\n print \"#{result[i][0]} #{result[i][1]}\\n\"\n end\nend\n\ndef color_match(arr)\n 0.upto(arr.size-1) do |r|\n 0.upto(arr[0].size-1) do |c|\n return false unless $color[r][c] == arr[r][c]\n end\n end\n true\nend\n\ndef start_coord(arr, n, m)\n 0.upto(n-1) do |r|\n 0.upto(m-1) do |c|\n return [r,c] if arr[r][c] == 1\n end\n end\n []\nend\n\ndef collect_result(coord, a)\n result = Array.new\n q = Array.new\n r, c = coord\n q << [coord]\n until q.empty? do\n point = q.shift.flatten.flatten\n r, c = point[0], point[1]\n coloring(r, c)\n $visited[r][c] = 1\n result << [r+1, c+1]\n ways = way_to_go(a, r, c)\n until ways.empty? do # max 4\n var = ways.shift\n next_r = r + var[0]\n next_c = c + var[1]\n q << [next_r, next_c] if $visited[next_r][next_c].zero?\n end\n end\n result\nend\n\ndef coloring(r, c)\n $color[r][c], $color[r+1][c], $color[r][c+1], $color[r+1][c+1] = 1, 1, 1, 1\nend\n\ndef way_to_go(arr, r, c)\n ways = Array.new\n if (r+1) < arr.size && $visited[r+1][c].zero? && block_check(arr, r+1, c)\n ways << [1,0]\n elsif (r-1) >= 0 && $visited[r-1][c].zero? && block_check(arr, r-1, c)\n ways << [-1,0]\n elsif (c+1) < arr[0].size && $visited[r][c+1].zero? && block_check(arr, r, c+1)\n ways << [0,1]\n elsif (c-1) >= 0 && $visited[r][c-1].zero? && block_check(arr, r, c-1)\n ways << [0,-1]\n end\n ways\nend\n\ndef block_check(arr, r, c)\n return false unless r >= 0 && (r+1) < arr.size && c >= 0 && (c+1) < arr[0].size\n unless 4 == ($color[r][c] + $color[r+1][c] + $color[r][c+1] + $color[r+1][c+1])\n return 4 == (arr[r][c] + arr[r+1][c] + arr[r][c+1] + arr[r+1][c+1])\n end\n false\nend\n\ndef get_each(str)\n arr = Array.new\n num = 0\n str.each_char do |e|\n if e == ' '\n arr << num\n num = 0\n else\n num = num * 10 + e.to_i\n end\n end\n arr << num #unless num.zero?\n arr\nend\n\nboard\n"}, {"source_code": "$visited = nil\n$color = nil\n\ndef board\n nm = get_each gets.chomp\n n = nm[0]\n m = nm[1]\n a = Array.new\n $color = Array.new(n) { Array.new(m, 0)}\n $visited = Array.new(n) { Array.new(m, 0) }\n\n n.times do\n row = get_each(gets.chomp)\n a << row\n end\n coord = start_coord(a, n, m)\n if coord.empty?\n puts 0\n return\n end\n result = collect_result(coord, a)\n if result == -1 || !color_match(a)\n puts -1\n return\n end\n puts result.count\n 0.upto(result.size-1) do |i|\n print \"#{result[i][0]} #{result[i][1]}\\n\"\n end\nend\n\ndef color_match(arr)\n 0.upto(arr.size-1) do |r|\n 0.upto(arr[0].size-1) do |c|\n return false unless $color[r][c] == arr[r][c]\n end\n end\n true\nend\n\ndef start_coord(arr, n, m)\n 0.upto(n-1) do |r|\n 0.upto(m-1) do |c|\n return [r,c] if arr[r][c] == 1\n end\n end\n []\nend\n\ndef collect_result(coord, a)\n result = Array.new\n q = Array.new\n r, c = coord\n coloring(r, c)\n $visited[r][c] = 1\n q << [coord]\n i = 4\n until q.empty? do\n point = q.shift.flatten.flatten\n r, c = point[0], point[1]\n result << [r+1, c+1]\n ways = way_to_go(a, r, c)\n until ways.empty? do # max 4\n var = ways.shift\n next_r = r + var[0]\n next_c = c + var[1]\n q << [next_r, next_c] if $visited[next_r][next_c].zero?\n coloring(next_r, next_c)\n $visited[next_r][next_c] = 1\n end\n i -= 1\n break if i.zero?\n end\n result\nend\n\ndef coloring(r, c)\n $color[r][c], $color[r+1][c], $color[r][c+1], $color[r+1][c+1] = 1, 1, 1, 1\nend\n\ndef way_to_go(arr, r, c)\n ways = Array.new\n if (r+1) < arr.size && $visited[r+1][c].zero? && block_check(arr, r+1, c)\n ways << [1,0]\n elsif (r-1) >= 0 && $visited[r-1][c].zero? && block_check(arr, r-1, c)\n ways << [-1,0]\n elsif (c+1) < arr[0].size && $visited[r][c+1].zero? && block_check(arr, r, c+1)\n ways << [0,1]\n elsif (c-1) >= 0 && $visited[r][c-1].zero? && block_check(arr, r, c-1)\n ways << [0,-1]\n end\n ways\nend\n\ndef block_check(arr, r, c)\n return false unless r >= 0 && (r+1) < arr.size && c >= 0 && (c+1) < arr[0].size\n unless 4 == ($color[r][c] + $color[r+1][c] + $color[r][c+1] + $color[r+1][c+1])\n return 4 == (arr[r][c] + arr[r+1][c] + arr[r][c+1] + arr[r+1][c+1])\n end\n false\nend\n\ndef get_each(str)\n arr = Array.new\n num = 0\n str.each_char do |e|\n if e == ' '\n arr << num\n num = 0\n else\n num = num * 10 + e.to_i\n end\n end\n arr << num #unless num.zero?\n arr\nend\n\nboard\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\naa = []\nnot_zero = false\nn.times do|_x|\n arr = gets.split\n aa << arr\n unless not_zero\n not_zero=true if arr.include?(\"1\")\n end\nend\n\nunless not_zero\n puts 0\n exit\nend\n\nchanged = Array.new(n,\"0\").map{Array.new(m,\"0\")}\nans = []\n\n0.upto(n-1-1) do |i|\n 0.upto(m-1-1) do |j|\n if aa[i][j]==\"1\" && aa[i][j+1]==\"1\" && aa[i+1][j]==\"1\" && aa[i+1][j+1]==\"1\"\n ans << \"#{i+1} #{j+1}\"\n changed[i][j]=\"1\"\n changed[i][j+1]=\"1\"\n changed[i+1][j]=\"1\"\n changed[i+1][j+1]=\"1\"\n end\n #d\n #puts changed.to_s\n end\n \n unless aa[i] == changed[i]\n # \u3067\u304d\u306a\u3044\n puts -1\n exit\n end\nend\n\nputs(\"#{ans.size}\\n\" + ans.join(\"\\n\"))\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\naa = []\nnot_zero = false\nn.times do|_x|\n arr = gets.split\n aa << arr\n unless not_zero\n not_zero=true if arr.include?(\"1\")\n end\nend\n\nunless not_zero\n puts 0\n exit\nend\n\nchanged = Array.new(n).map{Array.new(m)}\nans = []\n\n0.upto(n-1-1) do |i|\n 0.upto(m-1-1) do |j|\n if aa[i][j]==\"1\" && aa[i][j+1]==\"1\" && aa[i+1][j]==\"1\" && aa[i+1][j+1]==\"1\"\n ans << \"#{i+1} #{j+1}\"\n changed[i][j]=1\n changed[i+1][j]=1\n changed[i+1][j+1]=1\n elsif changed[i][j]==1\n else\n # \u3067\u304d\u306a\u3044\n puts -1\n exit\n end\n #d\n #puts changed.to_s\n end\nend\n\nputs(\"#{ans.size}\\n\" + ans.join(\"\\n\"))"}], "src_uid": "ad641a44ecaf78ca253b199f3d40ef96"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nans = 0\nc = 0\na += a\n(n*2).times do |i|\n if a[i] == 1\n c += 1\n ans = c if ans < c\n else\n c = 0\n end\nend\nputs [ans,n].min", "positive_code": [{"source_code": "N = gets.to_i\ns = gets.split.join\ns += s\np s.scan(/1+/).map{ |s| s.size }.max || 0"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\na = gets.split.map(&:to_i) # \"0\" works \"1\" rests\ndoublea = a*2 # simulate it with 'mod' operator in other language (looping)\nlongest_rests = 0\nrests = 0\ndoublea.each { |flag|\n if flag == 0 # works\n rests = 0\n else\n rests += 1\n\n if rests > longest_rests\n longest_rests = rests\n end\n end\n}\n\nputs longest_rests"}, {"source_code": "gets\nr=(gets*2).tr(' \n','').gsub(/1+/).map(&:size).max\np r==nil ?0:r\n"}, {"source_code": "gets\nr=(gets*2).tr(' \n','').split(?0).map(&:size).max\np r==nil ?0:r"}, {"source_code": "quantidade=gets\nnumeros=gets\nvetordenumeros=numeros.split \nvetordenumeros=vetordenumeros+vetordenumeros\ni=0\ncontador=0\nfor numero in vetordenumeros do \n if numero.to_i==1 \n i+=1\n else \n if contador #{message}\"\n end\nend\nunless stack.empty?\n puts \"Unhandled Exception\"\nend\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n# encoding: utf-8\nn=gets.to_i\n\nthlist = []\nthid = []\ntrylist = []\nflag=0\n\nn.times do |id|\n str=gets.strip!\n next if flag == 1\n if /^try$/ =~ str\n trylist << id\n elsif /throw/ =~ str\n /(?<=\\()\\s*\\w+\\s*(?=\\))/ =~ str\n thlist << $&.strip\n # puts thlist.last\n thid << id\n elsif /catch/ =~ str\n /(?<=\\()\\s*\\w+\\s*(?=,)/ =~ str\n if (pos=thlist.index($&.strip))!=nil && thid[pos] > trylist.last\n /(?<=\\\").+(?=\\\")/ =~ str\n puts $&\n flag=1\n end\n trylist.pop\n end\nend\n\nputs \"Unhandled Exception\" if flag == 0\n"}, {"source_code": "#!/usr/bin/env ruby\n# encoding: utf-8\nn=gets.to_i\n\nthlist = []\nthid = []\ntrylist = []\nflag=0\n\nn.times do |id|\n str=gets.strip!\n next if flag == 1\n if /^try$/ =~ str\n trylist << id\n elsif /throw/ =~ str\n /(?<=\\()\\s*\\w+\\s*(?=\\))/ =~ str\n thlist << $&.strip\n thid << id\n elsif /catch/ =~ str\n /(?<=\\()\\s*\\w+\\s*(?=,)/ =~ str\n if (pos=thlist.index($&.strip))!=nil && thid[pos] > trylist.last\n /(?<=\\\").+(?=\\\")/ =~ str\n puts $&\n flag=1\n end\n trylist.pop\n end\nend\n\nputs \"Unhandled Exception\" if flag == 0\n\n \t\t \t\t\t \t \t \t\t \t\t\t \t \t \t\t\t\t"}, {"source_code": "#!/usr/bin/ruby -w\n\nN = gets.strip.to_i\nlevel = 0\nex = ''\nex_level = 0\ndummy = 0\n\nN.times do |i|\n line = gets\n next if not line\n line.strip!\n\n if line =~ /try$/\n level += 1\n dummy += 1 if ex != ''\n #puts \"#{level}, #{dummy}, try, #{ex}\"\n elsif line =~ /throw\\s*\\((.+?)\\)/\n #puts \"#{level}, #{dummy}, throw #{$1.strip}\"\n ex = $1.strip\n ex_level = level\n elsif line =~ /catch\\s*\\((.+?)\\s*,\\s*\"(.+?)\"\\s*\\)/\n #puts \"#{level}, #{dummy}, #{$2}\"\n if dummy == 0 && level <= ex_level && ex == $1.strip\n puts $2\n exit\n end\n level -= 1\n dummy -= 1 if dummy > 0\n end\nend\n\nputs \"Unhandled Exception\"\n"}, {"source_code": "#!/usr/bin/ruby -w\n\nN = gets.strip.to_i\nlevel = 0\nex = ''\nex_level = 0\ndummy = 0\n\nN.times do |i|\n line = gets\n next if not line\n line.strip!\n\n if line =~ /try$/\n level += 1\n dummy += 1 if ex != ''\n #puts \"#{level}, #{dummy}, try, #{ex}\"\n elsif line =~ /throw\\s*\\((.+?)\\)/\n #puts \"#{level}, throw #{$1.strip}\"\n ex = $1.strip\n ex_level = level\n elsif line =~ /catch\\s*\\((.+?)\\s*,\\s*\"(.+?)\"\\s*\\)/\n #puts \"#{level}, #{dummy}, #{$2}\"\n if dummy == 0 && level <= ex_level && ex == $1.strip\n puts $2\n exit\n end\n level -= 1\n dummy -= 1 if dummy > 0\n end\nend\n\nputs \"Unhandled Exception\"\n"}, {"source_code": "n = gets.to_i\na = []\nfor i in (1..n) do\n a[i]=gets\nend\n\nthr = /(\\s*)throw(.*)/\nthr_s = /\\s*throw\\s*\\(\\s*([a-zA-Z]+)/\ntry = /(\\s*)try(\\s*)/\ncat = /(\\s*)catch(.*)/\ncat_s = /\\s*catch\\s*\\(\\s*([a-zA-Z]+).+\"(.+)\"/\n\nfor i in (1..n) do\n r = a[i]=~thr\n if r==0 then break end\nend\nisc = a[i].match(thr_s)[1]\nc = 0\nfor k in (i+1..n) do\n r = a[k]=~try\n if r==0 then c+=1 end\n r = a[k]=~cat\n if r==0 then\n if c==0 then\n z=a[k].match(cat_s)\n if isc==z[1] then\n puts z[2]\n exit\n end\n else\n c-=1\n end \n end\nend\nputs 'Unhandled Exception'\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = $stdin.gets.to_i\nlines = []\nn.times do\n s = $stdin.gets.chomp.strip\n if s == 'try' || s.start_with?('catch') || s.start_with?('throw')\n lines << s\n end\nend\n\nexn = {:level => -1, :type => nil}\nlevel = 0\nwhile not lines.empty?\n s = lines.shift\n case s\n when 'try'\n level += 1\n when /\\Acatch\\s*\\(\\s*([A-Za-z]+)\\s*,\\s*\"([^\"]+)\"\\s*\\)\\z/\n type = $1\n mes = $2\n if level == exn[:level] && type == exn[:type]\n puts mes\n exit 0\n end\n if level == exn[:level]\n exn[:level] -= 1\n end\n level -= 1\n when/\\Athrow\\s*\\(\\s*([A-Za-z]+)\\s*\\)\\z/\n exn[:level] = level\n exn[:type] = $1\n end\nend\nputs 'Unhandled Exception'\n"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\n# encoding: utf-8\nn=gets.to_i\n\nthlist = []\nthid = []\ntrylist = []\nflag=0\n\nn.times do |id|\n str=gets.strip!\n next if flag == 1\n if /try/ =~ str\n trylist << id\n elsif /throw/ =~ str\n /(?<=\\()\\s*\\w+\\s*(?=\\))/ =~ str\n thlist << $&.strip\n thid << id\n elsif /catch/ =~ str\n /(?<=\\()\\s*\\w+\\s*(?=,)/ =~ str\n if (pos=thlist.index($&.strip))!=nil && thid[pos] > trylist.last\n /(?<=\\\").+(?=\\\")/ =~ str\n puts $&\n flag=1\n end\n trylist.pop\n end\nend\n\nputs \"Unhandled Exception\" if flag == 0\n"}, {"source_code": "#!/usr/bin/ruby -w\n\nN = gets.strip.to_i\nlevel = 0\nex = ''\nex_level = 0\ndummy = 0\n\nN.times do |i|\n line = gets\n next if not line\n line.strip!\n\n if line =~ /try/\n level += 1\n dummy += 1 if ex != ''\n #puts \"#{level}, #{dummy}, try, #{ex}\"\n elsif line =~ /throw\\s*\\((.+?)\\)/\n #puts \"#{level}, throw #{$1.strip}\"\n ex = $1.strip\n ex_level = level\n elsif line =~ /catch\\s*\\((.+?)\\s*,\\s*\"(.+?)\"\\s*\\)/\n #puts \"#{level}, #{dummy}, #{$2}\"\n if dummy == 0 && level <= ex_level && ex == $1.strip\n puts $2\n exit\n end\n level -= 1\n dummy -= 1 if dummy > 0\n end\nend\n\nputs \"Unhandled Exception\"\n"}, {"source_code": "n = gets.to_i\na = []\nfor i in (1..n) do\n a[i]=gets\nend\n\nfor i in (1..n) do\n if a[i]=~(/(\\s*)throw(.*)/) then break end\nend\nisc = a[i].match(/\\s*throw\\s*\\(\\s*([a-zA-Z]+)/)[1]\nc = 0\nfor k in (i+1..n) do\n if a[k]=~(/(\\s*)try(\\s*)/) then c+=1 end\n if a[k]=~(/(\\s*)catch(.*)/) then\n if c==0 then\n z=a[k].match(/\\s*catch\\s*\\(\\s*([a-zA-Z]+).+\"(.+)\"/)\n if isc==z[1] then\n puts z[2]\n exit\n end\n else\n c-=1\n end \n end\nend\nputs 'Unhandled Exception'\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = $stdin.gets.to_i\nlines = []\nn.times do\n s = $stdin.gets.chomp.strip\n if s == 'try' || s.start_with?('catch') || s.start_with?('throw')\n lines << s\n end\nend\n\ndef parse(lines)\n s = lines.shift\n if s == 'try'\n bodies = []\n while not lines[0].start_with?('catch')\n bodies << parse(lines)\n end\n c = lines.shift\n m = c.match(/\\Acatch\\s*\\(\\s*([A-Za-z]+)\\s*,\\s*\"([^\"]+)\"\\s*\\)\\z/)\n {:catch => {:type => m[1], :mes => m[2], :bodies => bodies} }\n else\n m = s.match(/\\Athrow\\s*\\(\\s*([A-Za-z]+)\\s*\\)\\z/)\n {:throw => m[1] }\n end\nend\n\ntree = parse lines\n\ndef solve(t)\n if c = t[:catch]\n exn = nil\n c[:bodies].each do |b|\n exn = solve b\n break if exn\n end\n if exn && exn == c[:type]\n puts c[:mes]\n exit 0\n end\n exn\n else\n t[:throw]\n end\nend\nsolve tree\nputs 'Unhandled Exception'\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = $stdin.gets.to_i\nlines = []\nn.times do\n s = $stdin.gets.chomp.strip\n if s == 'try' || s.start_with?('catch') || s.start_with?('throw')\n lines << s\n end\nend\n\ndef parse(lines)\n if not lines.empty?\n s = lines.shift\n if s == 'try'\n bodies = []\n while lines[0] !~ /\\Acatch/\n bodies << parse(lines)\n end\n c = lines.shift\n m = c.match(/\\Acatch\\s*\\(\\s*([A-Za-z]+)\\s*,\\s*\"([^\"]+)\"/)\n {:catch => {:type => m[1], :mes => m[2], :bodies => bodies} }\n else\n m = s.match(/\\Athrow\\s*\\(\\s*([A-Za-z]+)\\s*\\)/)\n {:throw => m[1] }\n end\n end\nend\n\ntree = parse lines\n\ndef solve(t)\n if c = t[:catch]\n exn = nil\n c[:bodies].each do |b|\n exn = solve b\n break if exn\n end\n if exn && exn == c[:type]\n puts c[:mes]\n exit 0\n end\n exn\n else\n t[:throw]\n end\nend\nsolve tree\nputs 'Unhandled Exception'\n"}, {"source_code": "#!/usr/bin/ruby\n\nn = $stdin.gets.to_i\nlines = []\nn.times do\n s = $stdin.gets.strip\n if s == 'try' || s.start_with?('catch') || s.start_with?('throw')\n lines << s\n end\nend\n\ntree = {}\ndef parse(lines)\n if not lines.empty?\n s = lines.shift\n if s == 'try'\n bodies = []\n while lines[0] !~ /\\Acatch/\n bodies << parse(lines)\n end\n c = lines.shift\n m = c.match(/\\Acatch\\s*\\(\\s*([A-Za-z]+)\\s*,\\s*\"([^\"]+)\"/)\n {:catch => {:type => m[1], :mes => m[2], :bodies => bodies} }\n else\n m = s.match(/\\Athrow\\s*\\(\\s*([A-Za-z]+)\\s*\\)/)\n {:throw => m[1] }\n end\n end\nend\n\ntree = parse lines\n\ndef solve(t)\n if c = t[:catch]\n exn = nil\n c[:bodies].each do |b|\n a = solve b\n if a\n exn = a\n end\n end\n if exn && exn == c[:type]\n puts c[:mes]\n exit 0\n end\n exn\n else\n t[:throw]\n end\nend\nsolve tree\nputs 'Unhandled Exception'\n"}], "src_uid": "320e6c06194f8b1ccf1f4218d0757d2f"} {"source_code": "OK = \"OK\"\n\nn, m = gets.split.map { |v| v.to_i }\nt = Array.new(n, 0)\n\nm.times do\n a, b = gets.split.map { |v| v.to_i - 1 }\n (a .. b).each { |index| t[index] += 1 }\nend\n\nincorrect_day = nil\n\nt.each_index do |index|\n if t[index] != 1\n incorrect_day = index\n break\n end\nend\n\nif incorrect_day\n puts \"#{incorrect_day + 1} #{t[incorrect_day]}\"\nelse\n puts OK\nend\n", "positive_code": [{"source_code": "n, m = gets.split.map { |v| v.to_i }\nt = Array.new(n, 0)\n\nm.times do\n a, b = gets.split.map { |v| v.to_i - 1 }\n (a .. b).each { |index| t[index] += 1 }\nend\n\nincorrect_day = t.find_index { |v| v != 1 }\n\nif incorrect_day\n puts \"#{incorrect_day + 1} #{t[incorrect_day]}\"\nelse\n puts \"OK\"\nend\n"}, {"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\ncnt = 0\nerr = 0\nprevnum = 0\nfor i in 0..m-1\n\ta = gets.chomp.split(/ /).map!{|x| x.to_i}\n\tif a[0] == prevnum\n\t\tif err == 1\n\t\t\tcnt += 1\n\t\telse\n\t\t\tcnt = 2\n\t\t\terr = 1\n\t\tend\n\t\tbreak if a[1] != a[0]\n\telse\n\t\tbreak if err == 1\n\t\tif a[0] > prevnum+1\n\t\t\terr = 2\n\t\t\tbreak\n\t\tend\n\tend\n\tprevnum = a[1]\nend\nif err == 2\n\tputs (prevnum+1).to_s + \" 0\"\nelsif err == 1\n\tputs prevnum.to_s + \" \" + cnt.to_s\nelsif n != prevnum\n\tputs (prevnum+1).to_s + \" 0\"\nelse\n\tputs \"OK\"\nend"}], "negative_code": [{"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\ncnt = 0\nerr = 0\nprevnum = 0\nfor i in 0..m-1\n\ta = gets.chomp.split(/ /).map!{|x| x.to_i}\n\tif a[0] == prevnum\n\t\tif err == 1\n\t\t\tcnt += 1\n\t\telse\n\t\t\tcnt = 2\n\t\t\terr = 1\n\t\tend\n\t\tbreak if a[1] != a[0]\n\telse\n\t\tbreak if err == 1\n\t\tif a[0] > prevnum+1\n\t\t\terr = 2\n\t\t\tbreak\n\t\tend\n\tend\n\tprevnum = a[1]\nend\nif err == 2\n\tputs (prevnum+1).to_s + \" 0\"\nelsif err == 1\n\tputs prevnum.to_s + \" \" + cnt.to_s\nelse\n\tputs \"OK\"\nend"}], "src_uid": "30c4f155336cf762699a1bbc55a60d27"} {"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n as = xs.zip(0..).filter_map { |x, i| x % 2 if i % 2 == 0 }\r\n bs = xs.zip(0..).filter_map { |x, i| x % 2 if i % 2 == 1 }\r\n puts as.uniq.size == 1 && bs.uniq.size == 1 ? \"YES\" : \"NO\"\r\nend\r\n", "positive_code": [{"source_code": "def all_odds?(arr)\n arr.each do |a|\n if a.even?\n return false\n end\n end\n return true\nend\n\ndef all_evens?(arr)\narr.each do |a|\n if a.odd?\n return false\n end\nend\nreturn true\nend\n\ndef odd_even_increments(arr, n)\n if all_odds?(arr) || all_evens?(arr)\n return true\n end\n i = 0\n while i < n\n if (i+1) % 2 != 0\n arr[i] += 1\n end\n i += 2\n end\n\n if all_evens?(arr) || all_odds?(arr)\n return true\n end\n i = 1\n\n while i < n\n if (i+1) % 2 == 0\n arr[i] += 1\n end\n i+=2\n end\n\n if all_odds?(arr) || all_odds?(arr)\n return true\n end\n\n return false\nend\n\nt = gets.chomp.to_i\ninputs = []\n(0..t-1).each do |i|\n n = gets.chomp.to_i\n arr = gets.chomp\n arr = arr.split(\" \").map(&:to_i)\n inputs.push([arr, n])\nend\n\ninputs.each do |element|\n result = odd_even_increments(element[0], element[1])\n if result\n puts \"YES\"\n else\n puts \"NO\"\n end\nend\n\n\n"}, {"source_code": "gets.to_i.times do\n gets\n a = gets.split.map(&:to_i)\n f = true\n a.each_with_index do |_q, i|\n f = false if i.even? && a[i] % 2 != a[0] % 2\n f = false if i.odd? && a[i] % 2 != a[1] % 2\n end\n if f\n puts :YES\n else\n puts :NO\n end\nend\n"}], "negative_code": [{"source_code": "def all_odds?(arr)\n arr.each do |a|\n if a.even?\n return false\n end\n end\n return true\nend\n\ndef all_evens?(arr)\narr.each do |a|\n if a.odd?\n return false\n end\nend\nreturn true\nend\n\ndef odd_even_increments(arr, n)\n if all_odds?(arr) || all_evens?(arr)\n return true\n end\n i = 0\n while i < n\n if (i+1) % 2 != 0\n arr[i] += 1\n end\n i += 2\n end\n\n if all_evens?(arr) || all_odds?(arr)\n return true\n end\n i = 1\n\n while i < n\n if (i+1) % 2 == 0\n arr[i] += 1\n end\n i+=2\n end\n\n if all_odds?(arr) || all_odds?(arr)\n return true\n end\n\n return false\nend\n\nt = gets.chomp.to_i\ninputs = []\n(0..t-1).each do |i|\n n = gets.chomp.to_i\n arr = gets.chomp\n arr = arr.split(\" \").map(&:to_i)\n inputs.push([arr, n])\nend\n\ninputs.each do |element|\n result = odd_even_increments(element[0], element[1])\n if result\n p \"YES\"\n else\n p \"NO\"\n end\nend\n\n\n"}], "src_uid": "fbb4e1cf1cad47481c6690ce54b27a1e"} {"source_code": "def IsPerfect(x)\n Math.sqrt(x)%1==0\nend\n\ndef Fibonnaci(n)\n IsPerfect(5*n*n + 4) || IsPerfect(5*n*n - 4)\nend\n\nn = gets.to_i\ni = 1\nres = ''\nwhile i <= n\n res=Fibonnaci(i)? res+'O': res+'o'\n i+=1\nend\n\nputs res", "positive_code": [{"source_code": "n = gets.to_i\nf, s = 0, 1\nfib = []\nwhile s <= n\n fib << s\n f, s = s, f + s\nend\nn.times { |i| print fib.include?(i + 1) ? 'O' : 'o' }\n"}, {"source_code": "def fib(n)\n return 1 if n == 1\n return 1 if n == 2\n fib(n-2) + fib(n-1)\nend\n\nfib_arr = []\n(1..20).each do |i|\n fib_arr << fib(i)\nend\n\nfib_s = 'o' * 10000\n\nfib_arr.each do |f|\n fib_s[f-1] = 'O'\nend\n\nn = gets.to_i\n\nputs fib_s[0..n-1]"}, {"source_code": "n = gets.to_i \n\nname = String.new\n\nname[0] = 'O' \n\nunless n < 2 \n name[1] = 'O'\nend \n\na = 1 \nb = 2 \n\nfor i in 2...n \n if (i+1) == a+b \n name[i] = 'O' \n a = i+1 \n a,b=b,a \n else \n name[i] = 'o' \n end \nend \n\nputs name "}, {"source_code": "n=gets.to_i\ns='o'*n\na=b=1\nwhile b<=n\n\ts[b-1]='O'\n\ta,b=b,a+b\nend\nputs s"}], "negative_code": [{"source_code": "def IsPerfect(x)\n Math.sqrt(x)%1==0\nend\n\ndef Fibonnaci(n)\n IsPerfect(5*n*n + 4) || IsPerfect(5*n*n - 4)\nend\n\nn = gets.to_i\ni = 0\nres = ''\nwhile i < n\n res=Fibonnaci(i)? res+'O': res+'o'\n i+=1\nend\n\nputs res\n\n"}, {"source_code": "n = gets.to_i\nres = 'OOOoO'\nm = 2\nwhile res.size<=n\n m.times do \n res+='o'\n end\n res+='O'\n m=m**2\nend\nputs res[0,n]\n\n"}, {"source_code": "def fib(n)\n return 1 if n == 1\n return 1 if n == 2\n fib(n-2) + fib(n-1)\nend\n\nfib_arr = []\n(1..13).each do |i|\n fib_arr << fib(i)\nend\n\nfib_s = 'o' * 300\n\nfib_arr.each do |f|\n fib_s[f-1] = 'O'\nend\n\nn = gets.to_i\n\nputs fib_s[0..n-1]"}, {"source_code": "def fib(n)\n return 1 if n == 1\n return 1 if n == 2\n fib(n-2) + fib(n-1)\nend\n\nfib_arr = []\n(1..13).each do |i|\n fib_arr << fib(i)\nend\n\nfib_s = 'o' * 10000\n\nfib_arr.each do |f|\n fib_s[f-1] = 'O'\nend\n\nn = gets.to_i\n\nputs fib_s[0..n-1]"}, {"source_code": "n = gets.to_i\nf, s = 0, 1\nfib = []\nn.times do\n fib << s\n f, s = s, f + s\nend\nn.times { |i| print fib.include?(i + 1) ? 'O' : 'o' }\n"}], "src_uid": "a7c0484275e62f0bc70d9edaac27d7d6"} {"source_code": "gets.strip.to_i.times do\n pins = []\n gets.strip.to_i.times do\n pins << gets.strip\n end\n steps = 0\n pins.each_with_index do |p, i|\n c = p.dup\n until !(pins.slice(0, i).concat(pins.slice(i + 1, pins.size))).include?(c)\n c = p.dup\n c[(0..3).to_a.shuffle.first] = ('0'..'9').to_a.shuffle.first\n end\n if c != p\n pins[i] = c\n steps += 1\n end\n end\n puts steps\n puts pins.join(\"\\n\")\nend", "positive_code": [{"source_code": "# https://codeforces.com/problemset/problem/1263/B\n\nn = gets.to_i\n\nn.times do\n count = gets.to_i\n cards = []\n digits = Array.new(10, false)\n\n count.times do |i|\n cards << card = gets.chomp.split('').map(&:to_i) \n digits[cards[i][0]] = true \n end\n\n moves = 0\n table = {}\n\n i = 0\n while i < count do\n j = i + 1\n while j < count do \n table[[i, j]] = same = cards[i] == cards[j]\n\n if same\n k = 0\n while digits[k] do\n k += 1\n end\n cards[i][0] = k\n digits[k] = true\n moves += 1\n break\n end\n\n j += 1\n end\n i += 1\n end\n\n puts moves\n cards.each { |card| puts card.join('') }\nend"}, {"source_code": "# https://codeforces.com/problemset/problem/1263/B\n\nn = gets.to_i\n\nn.times do\n count = gets.to_i\n cards = []\n digits = []\n 4.times { digits << Array.new(10, false) }\n\n count.times do |i|\n cards << card = gets.chomp.split('').map(&:to_i)\n 4.times do |j|\n digits[j][cards[i][j]] = true\n end\n end\n\n moves = 0\n table = {}\n\n i = 0\n while i < count do\n j = i + 1\n while j < count do \n table[[i, j]] = same = cards[i] == cards[j]\n\n if same\n k = 0\n while digits[0][k] do\n k += 1\n end\n cards[i][0] = k\n digits[0][k] = true\n moves += 1\n break\n end\n\n j += 1\n end\n i += 1\n end\n\n puts moves\n cards.each { |card| puts card.join('') }\nend"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a= 0\n sum += b\n ans << sum\n else\n ans << sum + b\n end\nend\n\nputs ans.join(' ')\n", "positive_code": [{"source_code": "# coding: utf-8\n\n# Maximums\n\nn = gets.to_i\nremax = 0\nax = []\ngets.split.each { |i|\n i = i.to_i\n ax << remax + i\n if remax < (remax + i)\n remax = remax + i\n end\n}\n\nputs ax.join ' '"}, {"source_code": "n = gets.to_i\nb = gets.split.map(&:to_i)\nx = [0]\na = []\nn.times do |i|\n a[i] = b[i] + x[i]\n x[i + 1] = [x[i], a[i]].max\nend\nputs a.join(\" \")\n"}, {"source_code": "max = 0\n\ngets\nputs(gets.split(' ').map do |e|\n pmax = max\n max = [max, e.to_i + max].max\n e.to_i + pmax\nend.join(' '))\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.split(\" \").map!{|el| el.to_i}\nresult = []\n\ncurrent_max = arr[0]\nresult << arr[0]\n1.upto(n-1) do |i|\n new_element = arr[i] + current_max\n result << new_element\n current_max = new_element if new_element > current_max\nend\n\nresult.each do |x|\n print x.to_s + \" \"\nend\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\narr = gets.split(\" \").map!{|el| el.to_i}\nresult = []\n\ncurrent_max = arr[0]\nresult << arr[0]\n1.upto(n-1) do |i|\n new_element = arr[i] + current_max\n result << new_element\n current_max = new_element if new_element > current_max\nend\n\np result"}, {"source_code": "N = gets.to_i\nB = gets.split.map(&:to_i)\n\nsum = 0\nans = []\n\nB.each do |b|\n sum += b\n ans << sum\nend\n\nputs ans.join(' ')\n"}], "src_uid": "e22b10cdc33a165fbd73b45dc5fbedce"} {"source_code": "gets.strip.to_i.times do\n n, k = gets.strip.split(' ').map(&:to_i)\n per_k = ((n / k).to_i * k)\n if per_k.zero?\n puts [n, (k / 2).to_i].min\n else\n puts per_k + [(n % per_k), (k / 2).to_i].min\n end\nend", "positive_code": [{"source_code": "gets.strip.to_i.times {\n n, k = gets.strip.split(' ').map(&:to_i);\n x = ((n / k).floor * k)\n n -= x\n y = (k / 2).floor\n puts x + y if y <= n\n puts x + n if y > n\n}"}, {"source_code": "gets.strip.to_i.times {\n n, k = gets.strip.split(' ').map(&:to_i);\n x = ((n / k).floor * k)\n n -= x\n y = (k / 2).floor\n puts x + y if y <= n\n puts x + n if y > n\n}"}, {"source_code": "t=gets.to_i\nt.times do\n n,k=gets.split.map(&:to_i)\n c1=(n/k)*k\n n-=c1\n c2=[n,k/2].min\n puts c1+c2\nend\n"}, {"source_code": "readline.to_i.times do\n n, k = readline.split.map(&:to_i)\n a = n/k\n print([n, a*k + k/2].min, \"\\n\")\nend\n"}, {"source_code": "gets.to_i.times do\n\ta, b = gets.split.map(&:to_i)\n\tputs [a, a / b * b + b / 2].min\nend"}, {"source_code": "\n#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a 0 && ith < n - 1\n mn = [ ( arr[ ith ] - arr[ ith - 1 ] ).abs, (arr[ ith ] - arr[ ith + 1 ]).abs ].min\n mx = [ ( arr.last - arr[ ith ] ).abs, ( arr.first - arr[ith] ).abs ].max\n mx, mn = mn, mx if mx < mn\n print mn.to_s + \" \" + mx.to_s + \"\\n\"\n else\n mn = ( arr[ ith ] - arr[ ith - 1 ] ).abs\n mx = ( arr.first - arr[ith] ).abs\n mx, mn = mn, mx if mx < mn\n print mn.to_s + \" \" + mx.to_s + \"\\n\"\n end\n\nend"}, {"source_code": "cityNum = gets.chomp.to_i\ncity = gets.chomp.split(' ').map {|item| item.to_i}\nresult = []\n\n\ncity.each_with_index do |value, index|\n\tans = []\n\n\tif index > 0\n\t\tleft = city[index - 1]\n\telse\n\t\tleft = -100000000001\n\tend\n\n\tif index < cityNum - 1\n\t\tright = city[index + 1]\n\telse\n\t\tright = 100000000001\n\tend\n\n\tmostLeft = city[0]\n\tmostRight = city[cityNum - 1]\n\n=begin\n\tputs \"cityNum : #{cityNum}\"\n\tputs \"index : #{index}\"\n\tputs \"left : #{left}\"\n\tputs \"right : #{right}\"\n\tputs \"mostLeft : #{mostLeft}\"\n\tputs \"mostRight : #{mostRight}\"\n=end\n\n\tif value - left > right - value\n\t\tans << right - value\n\telse\n\t\tans << value - left\n\tend\n\n\tif value - mostLeft > mostRight - value\n\t\tans << value - mostLeft\n\telse\n\t\tans << mostRight - value\n\tend\n\n\tresult << ans\nend\n\n\nresult.each do |value|\n\tvalue.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\n\tputs ''\nend\n"}, {"source_code": "#!/usr/bin/ruby\nN=gets.to_i\na=[-10**10]+gets.split.map(&:to_i)+[10**10]\n1.step(N){|i|\n\tputs [[a[i]-a[i-1],a[i+1]-a[i]].min,[a[i]-a[1],a[N]-a[i]].max]*' '\n}"}, {"source_code": "# http://codeforces.com/contest/567/problem/A\nn = gets.chomp.to_i\narray = gets.chomp.split.map(&:to_i)\n\narray.each.with_index do |num, idx|\n possibles = [].tap do |out|\n out << array[idx - 1] if idx != 0\n out << array[idx + 1] if idx != (n - 1)\n out << array[0] if idx != 0\n out << array[n - 1] if idx != (n - 1)\n end\n possibles.map! { |b| (b - num).abs }.sort!\n\n puts [possibles.first, possibles.last].join(' ')\n\nend\n"}, {"source_code": "\nn = gets.chomp.to_i;\narr = gets.chomp.split.map(&:to_i);\nmin = Array.new;\nmax = Array.new;\nmin[0] = arr[1] - arr[0];\nmax[0] = arr[-1] - arr[0];\n\n(1..(n - 2)).each do |i|\n min[i] = [arr[i] - arr[i - 1], arr[i + 1] - arr[i]].min();\n max[i] = [arr[i] - arr[0], arr[-1] - arr[i]].max();\n # print min[i], max[i], arr[i], \"\\n\";\n end\nmin.push(arr[-1] - arr[-2]);\nmax.push(arr[-1] - arr[0]);\n\n(0..n-1).each do |i|\n puts \"#{min[i]} #{max[i]}\";\nend\n"}, {"source_code": "def calc (mas)\n pairs = []\n mas.each_index { |i| mas[i]= mas[i].to_i }\n mas.each_index { |i|\n dist=[i>0 ? mas[i]-mas[i-1] : 2**50, i+1= 0 && nidx < n\n dist = (cities[index] - cities[nidx]).abs\n if dist < near\n near = dist\n end\n end\n }\n\n # far\n [0, n-1].each { |fidx|\n if index != fidx\n dist = (cities[index] - cities[fidx]).abs\n if dist > far\n far = dist\n end\n end\n }\n\n puts \"#{near} #{far}\"\n}\n"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na = a.map{|x| x -= a[0]}\nn.times do |i|\n mi = n\n mi = a[i] - a[i - 1] if i != 0\n mi = [mi, a[i + 1] - a[i]].min if i != n - 1\n mx = [a[i] - a[0], a[n - 1] - a[i]].max\n puts \"#{mi} #{mx}\"\nend\n"}, {"source_code": "cityNum = gets.chomp.to_i\ncity = gets.chomp.split(' ').map {|item| item.to_i}\nresult = []\n\n\ncity.each_with_index do |value, index|\n\tans = []\n\n\tif index > 0\n\t\tleft = city[index - 1]\n\telse\n\t\tleft = -1000000001\n\tend\n\n\tif index < cityNum - 1\n\t\tright = city[index + 1]\n\telse\n\t\tright = 1000000001\n\tend\n\n\tmostLeft = city[0]\n\tmostRight = city[cityNum - 1]\n\n=begin\n\tputs \"cityNum : #{cityNum}\"\n\tputs \"index : #{index}\"\n\tputs \"left : #{left}\"\n\tputs \"right : #{right}\"\n\tputs \"mostLeft : #{mostLeft}\"\n\tputs \"mostRight : #{mostRight}\"\n=end\n\n\tif value - left > right - value\n\t\tans << right - value\n\telse\n\t\tans << value - left\n\tend\n\n\tif value - mostLeft > mostRight - value\n\t\tans << value - mostLeft\n\telse\n\t\tans << mostRight - value\n\tend\n\n\tresult << ans\nend\n\n\nresult.each do |value|\n\tvalue.each do |item|\n\t\tprint \"#{item} \"\n\tend\n\n\tputs ''\nend\n"}], "src_uid": "55383f13c8d097408b0ccf5653c4563d"} {"source_code": "t = gets.to_i\ndef check_odd(n, arr)\n flag = true\n [*0..(n/2)].each{|i|\n if arr[i] 18\n x = 9\n y = n - 9\n else\n x = n - 9\n y = 9\n end\n puts \"#{x} #{y}\"\nelse\n puts \"#{4} #{n-4}\"\nend\n"}, {"source_code": "n=gets.to_i;t=n%2+8;p n-t,t\n"}, {"source_code": "n=gets.to_i;t=n%2+8;p n-t,t\n"}, {"source_code": "require 'prime'\nn=gets.to_i\n4.upto(n){|i|\n\tif !Prime.prime?(i)&&!Prime.prime?(n-i) then\n\t\tputs [i,n-i]*\" \"\n\t\tbreak\n\tend\n}"}, {"source_code": "n = gets.chomp.to_i\n\nif n%2 == 0\n puts [8,n-8].sort.join(' ')\nelse\n puts [9,n-9].sort.join(' ')\nend"}, {"source_code": "def sost(n)\n return false if n==1\n #\u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u043e\u0442 2 \u0434\u043e sqrt(n)\n\ti=2\n while i*i<=n do\n\t return true if n%i==0\n\t i+=1\n\tend\n return false\nend\t\n\nn=gets.to_i\n\nif n%2==1\n x=(n/2.0).floor\n y=(n/2.0).ceil\nend\n\nif n%2==0\n x=n/2\n y=n/2\nend \n\nuntil (sost(x)==true and sost(y)==true)\n x-=1\n y+=1 \nend\n\nputs \"#{x} #{y}\""}, {"source_code": "a=gets.to_i;puts(a%2==0?\"4 #{a-4}\": \"9 #{a-9}\")"}, {"source_code": "a=gets.to_i;t=a%2*5+4;p a-t,t"}, {"source_code": "n = gets.to_i\n\nif n.even?\n puts \"#{4} #{n - 4}\"\nelse\n puts \"#{9} #{n - 9}\"\nend"}, {"source_code": "def is_composite(number)\n\treturn false if [1, 2, 3].include?(number)\n\t2.upto(Math.sqrt(number).to_i) {|element| return true if number % element == 0}\n\treturn false\nend\nnumber = gets.strip.to_i\n4.upto(number / 2) do |first_half|\n\tother_half = number - first_half\n\tif is_composite(first_half) && is_composite(other_half)\n\t\tputs \"#{first_half} #{other_half}\"\n\t\tbreak\n\tend\nend\n"}, {"source_code": "n=gets.to_i;t=n%2+8;p n-t,t"}, {"source_code": "n = Integer(gets) \n\ndef prime(x)\n e = 1\n for i in 2...x\n if x % i == 0\n e = 0\n break\n end\n end\n return e\nend\n\na = 0\nb = 0\nc = 0\nfor i in 4...n\n for j in 2...i\n if i % j == 0\n a = i\n b = n - a\n if prime(b) == 0\n c = 2\n end\n end\n end\n if c == 2\n break\n end\nend\n\n\nprint a, \" \", b"}, {"source_code": "number = gets.chomp.to_i\n\nif number % 2 == 0\n\tprint 4\n\tprint \" \"\n\tprint number-4\nelse\n\tprint 9\n\tprint \" \"\n\tprint number-9\nend"}, {"source_code": "n=gets.to_i;t=n%2+8;p n-t,t\n"}, {"source_code": "n = gets.to_i\n\nif n % 2 == 0 ;\n\tprint 4, ' ', n - 4, ?\\n\nelse\n\tprint 9, ' ', n - 9, ?\\n\nend\n"}, {"source_code": "N=gets.chomp.to_i\ndef is_composite(num)\n i=2\n while i*i<=num\n return true if num%i==0\n i+=1\n end\n false\nend\n\ndef solve(n)\n if n%2==0\n left=n/2;right=n/2\n else\n left=n/2;right=(n/2)+1\n end\n while left>0 && right false, 2 => false, 3 => false}\n\ndef compost?(n)\n return $o[n] unless $o[n].nil?\n\n d = 2\n while d <= Math.sqrt(n)\n if n % d == 0\n $o[n] = true\n return true\n end\n d += 1\n end\n\n $o[n] = false\n return false\nend\n\n# (1..1_000_000).each{|x| compost?(x); puts x if x % 100 == 0}\n# puts $op\n\ndef solve(n)\n (4..n).each do |c|\n return [c, n - c] if compost?( n - c ) && compost?(c)\n end\n return []\nend\n\nif __FILE__==$0\n n = gets.to_i\n s = solve(n)\n puts \"#{s[0]} #{s[1]}\"\nend\n"}, {"source_code": "a=gets.to_i;t=(a%2+2)**2;p a-t,t"}, {"source_code": "a=gets.to_i;t=(a%2+2)**2;p a-t;p t"}, {"source_code": "n = gets.chomp.to_i\n\nprime = Array.new( 1000005 , 0 )\nnum = Array.new( 1000005 , 0 )\n\ni = 2\nm = 0\n\nuntil i==1000000 do\n\n\tif prime[i]==0\n\t\tj = i* i\n\t\twhile j<=1000000 do\n\t\t\tprime[j] = 1\n\t\t\tj += i\n\t\tend\n\n\t\tnum[m] = i\n\t\tm += 1\n\n\tend\n\n\ti += 1\nend\n\nfor i in 2...m\n\n\tif prime[i]==1 && prime[n-i]==1\n\t\tputs \"#{i} #{n - i}\"\n\t\tbreak\n\tend\n\nend\n"}, {"source_code": "n=gets.to_i;t=n%2+8;p n-t,t"}, {"source_code": "# cook your code here\nn=gets.to_i;\nif (n&1 == 0) \n p 8, n-8\nelse\n p 9, n-9\nend\n"}, {"source_code": "n=gets.to_i;t=n%2+8;p n-t,t\n"}, {"source_code": "n = gets.to_i\n\nx = [8, 9, 10].select { |i| n-i > 3 && ( (n-i).modulo(3).zero? || (n-i).modulo(2).zero? ) }.first\n\nputs \"#{x} #{n-x}\"\n"}, {"source_code": "n=gets.to_i;t=n%2+8;p n-t,t\n"}, {"source_code": "n = gets.to_i\nif (n%2 == 1) \n\tputs 9, n-9\nelse \n\tputs 4, n-4\nend\n\n\n"}, {"source_code": "n = gets.to_i\nif n.odd?\n\tputs [9, n - 9].join ' '\nelse\n\tputs [4, n - 4].join ' '\nend"}, {"source_code": "n=gets.to_i;t=n%2+8;p n-t,t\n"}, {"source_code": "require 'prime'\n\nnumber = gets.chomp.to_i\n\n(2...number).each do |num|\n\tif !Prime.prime?(num) && !Prime.prime?(number - num)\n\t\tputs \"#{num} #{number - num}\" \n\t\tbreak\n\tend\nend"}, {"source_code": "require \"prime\"\nn=gets.to_i\n(4..(n/2)).each do |i|\n next if Prime.prime?(i) || Prime.prime?(n-i)\n puts [i, n-i].join(\" \")\n break\nend"}], "negative_code": [{"source_code": "$><<[(x=12-(-n=gets.to_i)%3*4),n-x]*\" \""}, {"source_code": "n = STDIN.readline.to_i\nif n%2 == 0\n\tputs [4, n-4].join(' ')\nelse\n\tputs [3, n-3].join(' ')\nend\n"}, {"source_code": "require 'prime'\nputs (z = (1..n = gets.to_i).to_a.find {|x| !x.prime? && !(n-x).prime? }).to_s+\" \"+(n-z).to_s"}, {"source_code": "n = gets.to_i\n\ncoco = 4\nmoco = n - 4\nuntil coco%2 == 0 || coco%3 == 0 && moco%2 == 0 || moco%3 == 0\n coco+=1\n moco-=1\nend\n\np [coco, moco]"}, {"source_code": "n = gets.to_i\n\ncoco = 4\nmoco = n - 4\nuntil coco%2 == 0 || coco%3 == 0 && moco%2 == 0 || moco%3 == 0\n coco+=1\n moco-=1\nend\n\nputs coco.to_s + \" \" + moco.to_s"}, {"source_code": "def sost(n)\n return false if n==1\n #\u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u043e\u0442 2 \u0434\u043e sqrt(n)\n\ti=2\n while i*i<=n do\n\t return true if n%i==0\n\t i+=1\n\tend\n return false\nend\t\n\nn=gets.to_i\nx=(n/2.0).floor\ny=(n/2.0).ceil\n\ns1=false\ns2=false\nwhile (sost(x)!=true and sost(y)!=true)\n x-=1\n y+=1 \nend\n\nputs \"#{x} #{y}\""}, {"source_code": "def sost(n)\n return false if n==1\n #\u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u043e\u0442 2 \u0434\u043e sqrt(n)\n\ti=2\n while i*i<=n do\n\t return true if n%i==0\n\t i+=1\n\tend\n return false\nend\t\n\nn=gets.to_i\nif n%2==1\n x=(n/2.0).floor\n y=(n/2.0).ceil\nend\n\nif n%2==0\n x=n/2\n y=n/2\nend \n\nwhile (sost(x)!=true and sost(y)!=true)\n x-=1\n y+=1 \nend\n\nputs \"#{x} #{y}\""}, {"source_code": "def sost(n)\n return false if n==1\n #\u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u043e\u0442 2 \u0434\u043e sqrt(n)\n\ti=2\n while i*i<=n do\n\t return true if n%i==0\n\t i+=1\n\tend\n return false\nend\t\n\nn=gets.to_i\nx=(n/2.0).floor\ny=(n/2.0).ceil\n\ns1=false\ns2=false\nwhile sost(x)!=sost(y)\n x-=1\n y+=1 \nend\n\nputs \"#{x} #{y}\""}, {"source_code": "n = gets.to_i\n\nif n % 2 == 0 ;\n\tprint 2, ' ', n - 2, ?\\n\nelse\n\tprint 9, ' ', n - 9, ?\\n\nend\n"}, {"source_code": "number = gets.chomp.to_i\nprint (number / 2).to_s + \" \"+ (number-(number/2)).to_s"}, {"source_code": "def prime n\n\tif n == 1\n\t\treturn 0\n\telsif n == 2\n\t\treturn 1\n\tend\n\tfor i in 3..Math.sqrt(n)\n\t\tif n % i == 0\n\t\t\treturn 0\n\t\tend\n\tend\n\treturn 1\nend\n\nindex = 1\nn = gets\nn = n.to_i\nfor i in 4..n\n\tif (prime(i) == 0 && prime(n - i) == 0)\n\t\tindex = i\n\t\tbreak\n\tend\nend\t\t\nputs \"#{index} #{n - index}\""}, {"source_code": "def prime n\n\tif n == 1\n\t\treturn 0\n\telsif n == 2\n\t\treturn 1\n\tend\n\tm = n - 1\n\tfor i in 3..m\n\t\tif n % i == 0\n\t\t\treturn 0\n\t\tend\n\tend\n\treturn 1\nend\n\nindex = 1\nn = gets\nn = n.to_i\nfor i in 4..n\n\tif (prime(i) == 0 && prime(n - i) == 0)\n\t\tindex = i\n\t\tbreak\n\tend\nend\t\t\nputs \"#{index} #{n - index}\""}, {"source_code": "n = gets.to_i\nputs n / 2, n - n / 2\n"}, {"source_code": "n = gets.to_i\nif (n%2 == 1) \n\tputs 7, n-7\nelse \n\tputs 8, n-8\nend\n\n\n"}], "src_uid": "3ea971165088fae130d866180c6c868b"} {"source_code": "M=10**5+1\ngets\na=Array.new(M,0)\nx=Array.new(M){Array.new}\nb=gets.split.map(&:to_i)\nb.each{|c|a[c]+=1}\ns=0\n(M-1).downto(1){|m|\n\tif a[m]>0\n\t\t1.upto(m-1){|i|a[i]-=a[m]}\n\t\tt=[*s+1..s+a[m]]\n\t\ts+=a[m]\n\t\ta[m]=0\n\t\t1.upto(m){|i|x[i]+=t}\n\tend\n}\nif a.sort.first<0\n\tp -1\nelse\n\tp s\n\tputs b.map{|i|x[i].pop}*\" \"\nend", "positive_code": [{"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\ncnt=Array.new(100005,0)\na.each{|i|\n cnt[i]+=1\n}\n1.upto(100003){|i|\n if cnt[i] s.scan(/[aeiouy]/).count\nend\n\nputs b ? \"YES\" : \"NO\""}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = true\nn.times do |i|\n s = gets\n b = false if a[i] != s.scan(/[aeiou]/).count\nend\n\nputs b ? \"YES\" : \"NO\""}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = true\nn.times do |i|\n s = gets\n b = false if a[i] > s.scan(/[aeiou]/).count\nend\n\nputs b ? \"YES\" : \"NO\""}, {"source_code": "n = gets.chomp.to_i\np = gets.chomp.split(' ').map(&:to_i)\n\nans = 'YES'\n\nn.times do |i|\n partStringNum = 0\n \n gets.chomp.each_char do |c|\n partStringNum += 1 if c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'\n end\n \n ans = 'NO' if partStringNum < p[i]\nend\n\nputs ans"}], "src_uid": "cf595689b5cbda4f1d629524ad275650"} {"source_code": "puts \"4\"*1999+ \"5\"\nputs \"5\"*2000", "positive_code": [{"source_code": "puts '9'*200 + '0'*199 + '1'\nputs '9'*200"}, {"source_code": "n,m=gets.strip.split.map(&:to_i)\n\na = \"\"\nb = \"\"\nn+=20\nwhile n>0\n a << '4'\n b << '5'\n n-=4\nend\na[-1]='5'\n\nputs a\nputs b\n"}, {"source_code": "puts\"4\"*998+\"5\\n\"+\"5\"*999"}, {"source_code": "a = STDIN.readline.split(\" \")\ng = (\"1\"*a[0].to_i).to_i\nb = 10**a[0].to_i - g \nprint(\"#{g}\\n#{b}\")\n"}, {"source_code": "puts\"4\"*998+\"5\\n\"+\"5\"*999"}, {"source_code": "n,m = gets.split(/\\s+/).map(&:to_i)\n\ndef max(a,b)\n a > b ? a : b\nend\n\ndef min(a,b)\n a < b ? a : b\nend\n\na = '4'*(n / 4)\na+= '4' if n % 4 > 0\nq = min(m,a.length+1)\nx = '1'*m + '0'*max(0, a.length+1-m)\nputs a\nputs x.to_i - a.to_i\n"}, {"source_code": "print '5'*999+\"\\n\"+'4'*998+'5'"}], "negative_code": [{"source_code": "a = STDIN.readline.split(\" \")\nprint (\"#{\"1\"*a[0].to_i}\\n#{\"9\"*a[0].to_i}\")\n"}, {"source_code": "print \"4\"*1999 + \"5\"\nprint \"5\"*2000"}], "src_uid": "bba30bd91f085471f624c0f723b78a82"} {"source_code": "\ndef lowbit str\n\tfor k in 0...str.size\n\t\treturn k if str[k] == '1'\n\tend\nend\n\nT = gets.to_i\nT.times do\n\tx = gets.chomp.reverse\n\ty = gets.chomp.reverse\n\t\n\tl = lowbit y\n\tans = lowbit x[l..-1]\n\tputs ans\nend\n", "positive_code": [{"source_code": "gets.to_i.times{puts gets.reverse[gets.reverse.index('1')..-1].index('1')}"}], "negative_code": [{"source_code": "\ndef lowbit n\n\tn & -n\nend\n\nT = gets.to_i\nT.times do\n\tx = gets.to_i\n\ty = gets.to_i\n\tans = []\n\tcnt = 0\n\tuntil lowbit(y) > x\n\t\ttmp = x + y\n\t\tans << [tmp.to_s(2).reverse, cnt]\n\t\tcnt += 1\n\t\ty *= 2\n\tend\n\tans.sort!\n\tputs ans[0][1]\nend"}], "src_uid": "a20af745cf610eaa8116574805340591"} {"source_code": "a=gets.split.map(&:to_i)\ns=gets.chomp.bytes.map{|i|i-97}\nans=t=0\ncnt=Hash.new{0}\ns.each{|i|\n ans+=cnt[[i,t]]\n t+=a[i]\n cnt[[i,t]]+=1\n}\np ans\n\n", "positive_code": [{"source_code": "a=gets.split.map(&:to_i)\ns=gets.chomp.bytes.map{|i|i-97}\nans=t=0\ncnt=Hash.new{0}\ns.each{|i|\n ans+=cnt[[i,t]]\n t+=a[i]\n cnt[[i,t]]+=1\n}\np ans\n\n"}, {"source_code": "a=gets.split.map(&:to_i)\ns=gets.chomp.bytes.map{|i|i-97}\nans=t=0\ncnt=Hash.new{0}\ns.each{|i|\n ans+=cnt[[i,t]]\n t+=a[i]\n cnt[[i,t]]+=1\n}\np ans\n\n"}, {"source_code": "a=gets.split.map(&:to_i)\ns=gets.chomp.bytes.map{|i|i-97}\nans=t=0\ncnt=Hash.new{0}\ns.each{|i|\n ans+=cnt[[i,t]]\n t+=a[i]\n cnt[[i,t]]+=1\n}\np ans\n\n"}, {"source_code": "a=gets.split.map(&:to_i)\ns=gets.chomp.bytes.map{|i|i-97}\nans=t=0\ncnt=Hash.new{0}\ns.each{|i|\n ans+=cnt[[i,t]]\n t+=a[i]\n cnt[[i,t]]+=1\n}\np ans\n\n"}, {"source_code": "a=gets.split.map(&:to_i)\ns=gets.chomp.bytes.map{|i|i-97}\nans=t=0\ncnt=Hash.new{0}\ns.each{|i|\n ans+=cnt[[i,t]]\n t+=a[i]\n cnt[[i,t]]+=1\n}\np ans\n"}, {"source_code": "ratings = gets.chomp.split(' ').map {|x| x.to_i}\nstring = gets.chomp\n\nstring_values = string.chars.map {|c| ratings[c.ord - 'a'.ord]}\nrunning_sum = string_values.inject([]){ |res, c| res << res.last.to_i + c }\n\nchar_positions = Array.new(26)\n\nstring.chars.each_with_index { |c, i|\n if char_positions[c.ord - 'a'.ord].nil?\n char_positions[c.ord - 'a'.ord] = []\n end\n char_positions[c.ord - 'a'.ord] << i\n}\nans = 0\n\nchar_positions.each { |pos|\n if pos.nil?\n next\n end\n\n temp = {}\n\n pos.each { |position|\n if temp[running_sum[position - 1]].nil?\n temp[running_sum[position - 1]] = 0\n end\n\n if temp[running_sum[position]].nil?\n temp[running_sum[position]] = 0\n end\n ans += temp[running_sum[position - 1]]\n\n temp[running_sum[position]] += 1\n }\n}\n\np ans\n"}, {"source_code": "a=gets.split.map(&:to_i)\ns=gets.chomp.bytes.map{|i|i-97}\nans=t=0\ncnt=Hash.new{0}\ns.each{|i|\n ans+=cnt[[i,t]]\n t+=a[i]\n cnt[[i,t]]+=1\n}\np ans\n\n"}, {"source_code": "a=gets.split.map(&:to_i)\ns=gets.chomp.bytes.map{|i|i-97}\nans=t=0\ncnt=Hash.new{0}\ns.each{|i|\n ans+=cnt[[i,t]]\n t+=a[i]\n cnt[[i,t]]+=1\n}\np ans\n\n"}, {"source_code": "a=gets.split.map(&:to_i)\ns=gets.chomp.bytes.map{|i|i-97}\nans=t=0\ncnt=Hash.new{0}\ns.each{|i|\n ans+=cnt[[i,t]]\n t+=a[i]\n cnt[[i,t]]+=1\n}\np ans\n\n"}], "negative_code": [{"source_code": "@ratings = gets.chomp.split(' ').map {|x| x.to_i}\n@string = gets.chomp\n\n@sum_table = {}\n\ndef calc_sum(start, len)\n key = start.to_s + '_' + len.to_s\n if @sum_table.has_key? key\n @sum_table[key]\n elsif (len > 1)\n @sum_table[key] = calc_sum(start, len - 1) + calc_sum(start + len-1, 1)\n else\n @sum_table[key] = @ratings[@string[start].ord - 'a'.ord]\n end\nend\n\nstring_values = @string.chars.map {|c| @ratings[c.ord - 'a'.ord]}\n\ncount = 0\n@string.chars.each_with_index do |e, i|\n for j in (i+1)..@string.length\n if @string[j] == e\n if calc_sum(i+1, j-i-1) == 0\n count += 1\n end\n end\n end\nend\n\nputs count"}], "src_uid": "0dd2758f432542fa82ff949d19496346"} {"source_code": "n, b, d = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).reject { |e| e > b }\nf, c = 0, 0\n\na.each do |e|\n f += e\n if f > d\n f = 0\n c += 1\n end\nend\n\nputs c", "positive_code": [{"source_code": "n, b, d = gets.strip.split.map(&:to_i)\na = gets.strip.split.map(&:to_i)\ntotal_size = ans = 0\nn.times do |i|\n next if a[i] > b\n total_size += a[i]\n if total_size > d\n ans += 1\n total_size = 0\n end\nend\nputs ans\n"}, {"source_code": "n,b,d=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\n\nsum=0\nans=0\nx.each{|e|\n\tif e<=b then\n\t\tsum+=e\n\t\tif sum>d then\n\t\t\tans+=1\n\t\t\tsum=0\n\t\tend\n\tend\n}\nputs ans\n"}, {"source_code": "input = gets.strip.split(' ').map(&:to_i)\nn = input[0]\nb = input[1]\nd = input[2]\noranges = gets.strip.split(' ').map(&:to_i)\njuicer = 0\ncounter = 0\noranges.each do |o|\n if o > b\n next\n else\n juicer += o\n if juicer > d\n juicer = 0\n counter += 1\n end\n end\nend\nputs counter"}, {"source_code": "# coding: utf-8\n\nn, b, d = gets.split.map(&:to_i)\nar = gets.split.map(&:to_i)\nfs = 0\nempties = 0\nfor i in ar\n if i <= b\n fs += i\n end\n\n if fs > d\n empties += 1\n fs = 0\n end\nend\nputs empties"}, {"source_code": "#!/usr/bin/ruby\nn,b,d,*a=$<.read.split.map(&:to_i)\nr=k=0\na.each{|e|\n\tif e<=b\n\t\tif d d\n x = 0\n ans += 1\n end\n end\n }\np ans"}, {"source_code": "#!/usr/bin/env ruby\n\ndef juicer(arr, max_orange_size, wastebin_size)\n\tinitial = [0,0] #tuple of wastebin and bin emptying\n\tres = arr.inject(initial) do |cntr, orange| \n\t\tcntr[0] += orange unless orange > max_orange_size\n\t\tif cntr[0] > wastebin_size\n\t\t\tcntr[1] += 1\n\t\t\tcntr[0] = 0\n\t\tend\n\t\tcntr\n\tend\n\tres[1]\nend\n\nparams = STDIN.readline.split(\" \").map(&:to_i)\narr = STDIN.readline.split(\" \").map(&:to_i)\n\nputs juicer(arr, params[1], params[2])"}, {"source_code": "n,b,d = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\ntemp = 0\nans = 0\na.each do |x|\n temp += x if x <= b \n if temp > d\n ans += 1\n temp = 0\n end\nend\n\nputs ans"}, {"source_code": "n, b, d = gets.chomp.split.map(&:to_i)\narr = gets.chomp.split.map(&:to_i)\n\nc = 0\nsum = 0\narr.each do |a|\n next if a > b\n if sum + a > d\n c += 1\n sum = 0\n else\n sum += a\n end\nend\nputs c\n"}, {"source_code": "n,b,d = gets.split(\" \").map(&:to_i)\noranges = gets.split(\" \").map(&:to_i)\ncrushed_oranges = 0 \nclean_up = 0 \noranges.each do |orange| \n if orange <= b\n crushed_oranges += orange \n if crushed_oranges > d \n clean_up +=1 \n crushed_oranges = 0 \n end \n end \nend \nif crushed_oranges > d \n clean_up +=1 \nend \nputs clean_up \n "}], "negative_code": [{"source_code": "n, b, d = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\na.delete_if { |e| e > b }\ns = a.reduce(0, :+)\nputs s % d == 0 ? s / d - 1 : s / d"}, {"source_code": "n, b, d = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).reject { |e| e > b }\n\ns = a.reduce(0, :+)\nr = s / d\nr -= 1 if s % d == 0 && a.any?\n\nputs r"}, {"source_code": "n, b, d = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\na.delete_if { |e| e > b }\nputs a.reduce(0, :+) / d"}, {"source_code": "n, b, d = gets.chomp.split.map(&:to_i)\na = gets.chomp.split.map(&:to_i)\na.delete_if { |e| e > b }\ns = a.reduce(0, :+)\nputs s % d == 0 && s > 0 ? s / d - 1 : s / d"}, {"source_code": "# coding: utf-8\n\nn, b, d = gets.split.map(&:to_i)\nar = gets.split.map(&:to_i)\nempties = 0\nfiltered_sum = 0\nfor i in ar\n if i <= b\n filtered_sum += i\n end\nend\n\nif filtered_sum > 0 && filtered_sum%d == 0\n # last dumping will not be required\n # since there's no overflow at the end.\n puts filtered_sum/d - 1\nelse\n puts filtered_sum/d\nend"}, {"source_code": "# coding: utf-8\n\nn, b, d = gets.split.map(&:to_i)\nar = gets.split.map(&:to_i)\nfiltered_sum = 0\nfor i in ar\n if i <= b\n filtered_sum += i\n end\nend\nif filtered_sum <= d\n puts 0\nelse\n if filtered_sum%d == 0\n puts filtered_sum/d - 1\n else\n puts filtered_sum\n end\nend"}, {"source_code": "# coding: utf-8\n\nn, b, d = gets.split.map(&:to_i)\nar = gets.split.map(&:to_i)\nfiltered_sum = 0\nfor i in ar\n if i <= b\n filtered_sum += i\n end\nend\nif filtered_sum <= d\n puts 0\nelse\n if filtered_sum%d == 0\n puts filtered_sum/d - 1\n else\n puts filtered_sum/d\n end\nend"}, {"source_code": "# coding: utf-8\n\nn, b, d = gets.split.map(&:to_i)\nar = gets.split.map(&:to_i)\nempties = 0\nnb, nd = 0, 0 # current status\nwhile !ar.empty?\n nb = 0\n while !ar.empty?\n i = ar.first\n\n if i <= b\n if i + nb <= b\n nb += ar.shift\n else\n break\n end\n else\n ar.shift # waste\n end # other case, it doesn't fit to the juicer and will be skipped\n end\n\n #p \"#{nb} #{ar}\"\n nd += nb\n\n if nd > d\n empties += nd/d\n nd = nd%d\n end\nend\nputs empties"}, {"source_code": "# coding: utf-8\n\nn, b, d = gets.split.map(&:to_i)\nar = gets.split.map(&:to_i)\nempties = 0\nnb, nd = 0, 0 # current status\nwhile !ar.empty?\n nb = 0\n while !ar.empty?\n i = ar.first\n\n if i <= b\n if i + nb <= b\n nb += ar.shift\n else\n break\n end\n else\n ar.shift # waste\n end # other case, it doesn't fit to the juicer and will be skipped\n end\n\n #p \"#{nb} #{ar}\"\n nd += nb\n\n if nd > d\n nd = 0\n empties += 1\n end\nend\nputs empties"}, {"source_code": "n, b, d = gets.split.map(&:to_i)\nx = 0\nans = 0\ngets.split.map(&:to_i).each{|a|\n if a > b\n ans += 1\n else\n x += a\n if x > d\n x = 0\n ans += 1\n end\n end\n }\np ans"}, {"source_code": "n,b,d,*a=$<.read.split.map(&:to_i)\nr=a.reduce(0){|s,e|s+(e>b ? 0 : e)}\np r>0 ? ~-r/10 : 0"}, {"source_code": "n,b,d,*a=$<.read.split.map(&:to_i)\nr=a.reduce(0){|s,e|s+(e>b ? 0 : e)}\np r>0 ? ~-r/d : 0"}, {"source_code": "n,b,d,*a=$<.read.split.map(&:to_i)\np (a.reduce(0){|s,e|s+(e>b ? 0 : e)}-1)/10"}, {"source_code": "#!/usr/bin/env ruby\n\ndef juicer(arr, max_orange_size, wastebin_size)\n\tinitial = [0,0] #tuple of wastebin and bin emptying\n\tres = arr.inject(initial) do |cntr, orange| \n\t\tcntr[0] += orange unless orange >= max_orange_size\n\t\tif cntr[0] > wastebin_size\n\t\t\tcntr[1] += 1\n\t\t\tcntr[0] = 0\n\t\tend\n\t\tcntr\n\tend\n\tres[1]\nend\n\nparams = STDIN.readline.split(\" \").map(&:to_i)\narr = STDIN.readline.split(\" \").map(&:to_i)\n\nputs juicer(arr, params[1], params[2])"}, {"source_code": "n,b,d = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\n\ntemp = 0\n\na.each do |x|\n temp += x if x <= b \nend\n\nputs temp==d ? 0 : temp/d"}, {"source_code": "n, b, d = gets.chomp.split.map(&:to_i)\narr = gets.chomp.split.map(&:to_i)\n\nc = 0\nsum = 0\narr.each do |a|\n if a < b && sum + a <= d\n c += 1\n sum += a\n end\nend\nputs c\n"}, {"source_code": "n,b,d = gets.split(\" \").map(&:to_i)\noranges = gets.split(\" \").map(&:to_i)\ncrushed_oranges = 0 \nclean_up = 0 \noranges.each do |orange| \n if orange <= b\n crushed_oranges += orange \n if crushed_oranges >= d \n clean_up +=1 \n crushed_oranges = 0 \n end \n end \nend \nif crushed_oranges >= d \n clean_up +=1 \nend \nputs clean_up \n \n "}], "src_uid": "06e9649963715e56d97297c6104fbc00"} {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n xys = n.times.map { gets.split.map(&:to_i) }\r\n xs = xys.map { |x, y| x }\r\n ys = xys.map { |x, y| y }\r\n p 2 * ([xs.filter { |x| x < 0 }.min&.abs,\r\n xs.filter { |x| x > 0 }.max,\r\n ys.filter { |y| y < 0 }.min&.abs,\r\n ys.filter { |y| y > 0 }.max].compact.sum)\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n xp,yp=[0],[0]\r\n (n=gets.to_i).times do\r\n xy=gets.split.map(&:to_i)\r\n xy[0]==0 ? yp << xy[1] : xp << xy[0]\r\n end\r\n xp.sort!\r\n yp.sort!\r\n puts 2*(xp[-1]-xp[0])+2*(yp[-1]-yp[0])\r\nend\r\n"}], "negative_code": [], "src_uid": "4af206ae108a483bdb643dc24e4bedba"} {"source_code": "n, p = gets.split.map {|v| v.to_i}\n\nroute = Array.new\np.times do\n\tf, t, d = gets.split.map {|v| v.to_i}\n\n\ttemp = route.find {|v| v[:to]==f && v[:from]==t}\n\tif temp then\n\t\troute.delete temp\n\t\tnext\n\tend\n\n\tff = route.find {|v| v[:to]==f}\n\ttt = route.find {|v| v[:from]==t}\n\tif ff && tt then\n\t\tff[:to] = tt[:to]\n\t\tff[:dia] = d if d f, :to => t, :dia => d}\n\tend\n\nend\n\nroute = route.sort_by {|v| v[:from]}\n\nputs route.size\nroute.each do |v|\n\tprint v[:from],\" \",v[:to],\" \",v[:dia],\"\\n\"\nend\n", "positive_code": [{"source_code": "\narg = STDIN.gets.split(\" \").map {|i| i.to_i}\n\n\ndepart = []\ndest = []\nmeter = []\narg[1].times do\n pipe = STDIN.gets.split(\" \").map {|i| i.to_i}\n depart << pipe[0]\n dest << pipe[1]\n meter << pipe[2]\nend\n\ntank = []\n(1..arg[0]).each do |i|\n tank << i if (not dest.index(i)) and depart.index(i)\nend\n\ntap = (1..tank.length).map {|i| 0}\nif tank == []\n puts 0\nelse\n puts tank.length\n (0..tank.length-1).each do |i|\n capa = 1000_001\n #dp = tank[i]\n idx = depart.index(tank[i])\n ds = dest[idx]\n capa = [capa,meter[idx]].min\n while idx = depart.index(ds)\n capa = [capa,meter[idx]].min\n ds = dest[idx]\n end\n puts \"#{tank[i]} #{ds} #{capa}\"\n end\nend\n"}, {"source_code": "#sharyo\ninf=2*(10**9)\nres=Array.new\nin1,out,f=Array.new(1001,-1),Array.new(1001,-1),Array.new(1001,-1)\ns=gets.split(\" \")\nn,m=s[0].to_i,s[1].to_i\nfor i in 0..m-1\n\ts=gets.split(\" \")\n\tu,v,d=s[0].to_i,s[1].to_i,s[2].to_i\n\tf[u]=d\n\tin1[v]=out[u]=v\nend\nfor i in 1..n\n\tnext unless in1[i]==-1\n\tu,w,cnt,c=i,inf,0,false\n\twhile out[u]!=-1\n cnt+=1\n if cnt>n-1\n \tc=1\n \tbreak\n end\n v=out[u]\n w=[w,f[u]].min\n u=v\n\tend\n\tnext unless !c&&w!=inf\n\tres.push([i,[v,w]])\nend\nputs res.size\nres.each { |x,y|\n\tputs (x.to_s+\" \"+y[0].to_s+\" \"+y[1].to_s) \n }\n"}, {"source_code": "#!/usr/bin/ruby\n\nn, p = gets.split.map(&:to_i)\nv = Array.new(n) { [nil, nil, nil] }\np.times do\n\ta, b, d = gets.split.map(&:to_i)\n\ta -= 1\n\tb -= 1\n\tv[a][1..2] = [b, d]\n\tv[b][0] = a\nend\n\nans = []\nv.each_with_index do |item, idx|\n\tif item[0].nil?\n\t\tcur = idx\n\t\td = 10000000\n\t\twhile v[cur][1]\n\t\t\td = [d, v[cur][2]].min\n\t\t\tcur = v[cur][1]\n\t\tend\n\t\tans << [idx+1, cur+1, d] if idx != cur\n\tend\nend\n\np ans.size\nans.each do |item|\n\tputs item.join(' ')\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\nn, p = gets.split.map(&:to_i)\nv = Array.new(n) { [nil, nil, nil] }\np.times do\n a, b, d = gets.split.map(&:to_i)\n a -= 1\n b -= 1\n v[a][1..2] = [b, d]\n v[b][0] = a\nend\n\nans = []\nv.each_with_index do |item, idx|\n if item[0].nil?\n cur = idx\n d = 10000000\n while v[cur][1]\n d = [d, v[cur][2]].min\n cur = v[cur][1]\n end\n ans << [idx+1, cur+1, d] if idx != cur\n end\nend\n\np ans.size\nans.each do |item|\n puts item.join(' ')\nend"}], "negative_code": [{"source_code": "n, p = gets.split.map {|v| v.to_i}\n\nroute = Array.new\np.times do\n\tf, t, d = gets.split.map {|v| v.to_i}\n\n\tff = route.find {|v| v[:to]==f}\n\ttt = route.find {|v| v[:from]==t}\n\tif ff then\n\t\tff[:to] = t\n\t\tff[:dia] = d if d f, :to => t, :dia => d}\n\tend\n\nend\n\nroute.reject! {|v| v[:to]==v[:from]}\nroute.sort_by {|v| v[:dia]}\n\nputs route.size\nroute.each do |v|\n\tprint v[:from],\" \",v[:to],\" \",v[:dia],\"\\n\"\nend\n"}, {"source_code": "n, p = gets.split.map {|v| v.to_i}\n\nroute = Array.new\np.times do\n\tf, t, d = gets.split.map {|v| v.to_i}\n\n\ttemp = route.find {|v| v[:to]==f && v[:from]==t}\n\tif temp then\n\t\troute.delete temp\n\t\tnext\n\tend\n\n\tff = route.find {|v| v[:to]==f}\n\ttt = route.find {|v| v[:from]==t}\n\tif ff && tt then\n\t\tff[:to] = tt[:to]\n\t\tff[:dia] = d if d f, :to => t, :dia => d}\n\tend\n\nend\n\nroute.sort_by {|v| v[:dia]}\n\nputs route.size\nroute.each do |v|\n\tprint v[:from],\" \",v[:to],\" \",v[:dia],\"\\n\"\nend\n"}, {"source_code": "n, p = gets.split.map {|v| v.to_i}\n\nroute = Array.new\np.times do\n\tf, t, d = gets.split.map {|v| v.to_i}\n\n\ttemp = route.find {|v| v[:to]==f && v[:from]==t}\n\tif temp then\n\t\troute.delete temp\n\t\tnext\n\tend\n\n\tff = route.find {|v| v[:to]==f}\n\ttt = route.find {|v| v[:from]==t}\n\tif ff && tt then\n\t\tff[:to] = tt[:to]\n\t\tff[:dia] = d if d f, :to => t, :dia => d}\n\tend\n\nend\n\nroute.sort_by {|v| v[:from]}\n\nputs route.size\nroute.each do |v|\n\tprint v[:from],\" \",v[:to],\" \",v[:dia],\"\\n\"\nend\n"}, {"source_code": "#!/usr/bin/ruby\n\nn, p = gets.split.map(&:to_i)\nv = Array.new(n) { [nil, nil, nil] }\np.times do\n\ta, b, d = gets.split.map(&:to_i)\n\ta -= 1\n\tb -= 1\n\tv[a][1..2] = [b, d]\n\tv[b][0] = a\nend\n\nans = []\nv.each_with_index do |item, idx|\n\tif item[0].nil?\n\t\tcur = idx\n\t\td = 10000000\n\t\twhile v[cur][1]\n\t\t\td = [d, v[cur][2]].min\n\t\t\tcur = v[cur][1]\n\t\tend\n\t\tans << [idx+1, cur+1, d]\n\tend\nend\n\np ans.size\nans.each do |item|\n\tputs item.join(' ')\nend\n"}], "src_uid": "e83a8bfabd7ea096fae66dcc8c243be7"} {"source_code": "t = gets.chomp.to_i\n(0...t).each {|_| m,n = gets.chomp.split.map(&:to_i); puts (m%n == 0) ? \"YES\" : \"NO\";}", "positive_code": [{"source_code": "1.upto(gets.to_i) do\n a, b = gets.split(' ').map(&:to_i)\n\n puts a.modulo(b).zero? ? 'YES' : 'NO'\nend\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n n, m = gets.split.map(&:to_i)\n\n if n % m == 0\n puts 'YES'\n else\n puts 'NO'\n end\nend\n"}, {"source_code": " gets.chomp.to_i.times do\n n, m = gets.chomp.split.map(&:to_i)\n puts n%m == 0 ? \"YES\" : \"NO\"\n end\n"}], "negative_code": [], "src_uid": "6b37fc623110e49a5e311a2d186aae46"} {"source_code": "q = gets.to_i\n\nq.times do\n n, m, k = gets.split.map(&:to_i)\n\n if n < m\n n, m = m, n\n end\n\n if n > k\n puts -1\n else\n ans = m + (n - m) - (n - m) % 2\n k -= n\n if k % 2 != 0\n if (n - m) % 2 == 0\n\tans -= 1\n k -= 1\n end\n end\n puts ans + k\n end\nend", "positive_code": [{"source_code": "nq = gets.to_i\n\nnq.times do\n\ta, b, k = gets.split.map &:to_i\n\tif [a,b].max > k\n\t\tputs -1\n\telsif (a+b)%2 == 1\n\t\tputs k-1\n\telsif a%2 == k%2\n\t\tputs k\n\telse\n\t\tputs k-2\n\tend\nend"}, {"source_code": "Q = gets.to_i\nQ.times do\n n, m, k = gets.split.map(&:to_i)\n if n > k || m > k\n puts -1\n else\n ans = k\n ans -= 1 if (n-k) % 2 == 1\n ans -= 1 if (m-k) % 2 == 1\n puts ans\n end\nend"}, {"source_code": "q = gets.strip.to_i\nq.times do\n x,y,k = gets.strip.split.map(&:to_i)\n if k x\n # cx,cy=[y,y]\n ans=y\n k-=y\n x-=y\n\n if x%2==0\n ans+=x\n k-=x\n x=0\n if k%2==0\n ans+=k\n else\n ans+=(k-2)\n end\n else\n ans+=(x-1)\n k-=(x-1)\n x=1\n ans+=(k-1)\n end\n puts ans\nend"}], "negative_code": [], "src_uid": "5eac47595f0212b2b652518f0fefd238"} {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nt = gets.to_i\nprimes = [2,3]\nt.times {\n n = gets.chomp\n len = n.length\n n = n.to_i\n # \ud070 \uc218\ub97c \uc808\ubc18\uc73c\ub85c \ub098\ub220\uc11c \ud45c\ud604\ud560 \uc218 \uc788\ub2e4.\n # \ub108\ubb34 \uc798\uac8c \ud45c\uae30\ud558\uba74 \ubaa9\uc801\uc5d0 \ubd80\ud569\ud558\uc9c0 \uc54a\uc73c\ub2c8\uae4c \uc808\ubc18\uc73c\ub85c\ub9cc.\n # \uc55e\ubd80\ubd84\uacfc \ub4b7\ubd80\ubd84\uc758 \ucd5c\ub300\uacf5\uc57d\uc218\ub97c \uad6c\ud55c\ub2e4.\n # \ucd5c\ub300\uacf5\uc57d\uc218\ub85c \ub2e4\uc2dc \uc6d0 \uc218\ub97c \ub098\ub208\ub2e4. \ucd5c\ub300 \uacf5\uc57d\uc218\ub97c \uc18c\uc778\uc218 \ubd84\ud574\ub97c \ud55c\ub2e4.\n # ... \uc774\uac70 \ub098\ub984 \uc2e0\ubc15\ud588\ub294\ub370 \uc2e4\ud328\ud568\n # \ud480\uc774\ub97c \ubcf4\uba74, 2...sqrt(n) \uae4c\uc9c0 \ub450 \ubc88 \ub098\ub220\ubcf4\ub294\uc2dd\uc784.\n # \uadf8\ub9ac\uace0 \uadf8 \ub098\ub208 \uc218\ub97c set\uc5d0 \ub123\uc5b4\ub454\ub2e4.\n # set \uae38\uc774\uac00 2 \ub118\uae30\uba74 OK.\n # a 1 && collected[n] == nil\n puts \"YES\"\n puts \"#{collected.keys.join(' ')} #{n}\"\n else\n puts \"NO\"\n end\n end\n\n\n}", "positive_code": [{"source_code": "require 'prime'\n\nT = gets.to_i\n\nT.times do\n n = gets.to_i\n\n primes = Hash[n.prime_division]\n\n used = Hash.new(false)\n ans = []\n n = 1\n\n primes.each do |v, e|\n e.times do\n n *= v\n\n unless used[n]\n ans << n\n used[n] = true\n n = 1\n end\n end\n end\n\n if ans.size >= 3\n ans << n\n a, b, *r = ans\n c = r.inject(:*)\n\n puts 'YES'\n puts [a, b, c].join(' ')\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1294/C\n\nrequire 'prime'\n\nn = gets.to_i\n\nprimes = []\nPrime.each(31630) { |p| primes << p }\n\nn.times do\n num = gets.to_i\n answer = []\n temp = 1\n i = 0\n limit = Math.sqrt(num).floor\n failed = false\n\n while answer.size < 2 \n if num % primes[i] == 0\n if answer.include?(primes[i])\n temp *= primes[i]\n num /= primes[i]\n\n if !answer.include?(temp)\n answer << temp\n temp = 1\n end\n\n else\n answer << primes[i]\n num /= primes[i]\n end\n\n else\n i += 1\n if primes[i] > limit \n failed = true\n break\n end\n end\n end\n\n rest = temp * num\n failed = true if rest == 1 || answer.include?(rest)\n\n unless failed\n answer << rest\n puts \"YES\"\n puts answer.join(' ')\n else\n puts \"NO\"\n end\nend"}], "negative_code": [{"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1294/C\n\nrequire 'prime'\n\nn = gets.to_i\n\nprimes = []\nPrime.each(31610) { |p| primes << p }\n\nn.times do\n num = gets.to_i\n answer = []\n temp = 1\n i = 0\n limit = Math.sqrt(num).floor\n failed = false\n\n while answer.size < 2 \n if num % primes[i] == 0\n if answer.include?(primes[i])\n temp *= primes[i]\n num /= primes[i]\n\n if !answer.include?(temp)\n answer << temp\n temp = 1\n end\n\n else\n answer << primes[i]\n num /= primes[i]\n end\n\n else\n i += 1\n if num == 1 || primes[i] > limit \n failed = true\n break\n end\n end\n end\n\n failed = true if num == 1 || answer.include?(num)\n\n unless failed\n answer << num\n puts \"YES\"\n puts answer.join(' ')\n else\n puts \"NO\"\n end\nend"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1294/C\n\nrequire 'prime'\n\nn = gets.to_i\n\nprimes = []\nPrime.each(31610) { |p| primes << p }\n\nn.times do\n num = gets.to_i\n answer = []\n temp = 1\n i = 0\n limit = Math.sqrt(num).floor\n failed = false\n\n while answer.size < 2 \n if num % primes[i] == 0\n if answer.include?(primes[i])\n temp *= primes[i]\n if !answer.include?(temp)\n answer << temp\n num /= temp\n end\n\n else\n answer << primes[i]\n num /= primes[i]\n end\n\n else\n i += 1\n if primes[i] > limit\n failed = true\n break\n end\n end\n end\n\n unless failed\n answer << num\n puts \"YES\"\n puts answer.join(' ')\n else\n puts \"NO\"\n end\nend"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1294/C\n\nrequire 'prime'\n\nn = gets.to_i\n\nprimes = []\nPrime.each(31610) { |p| primes << p }\n\nn.times do\n num = gets.to_i\n answer = []\n temp = 1\n i = 0\n limit = Math.sqrt(num).floor\n failed = false\n\n while answer.size < 2 \n if num % primes[i] == 0\n if answer.include?(primes[i])\n temp *= primes[i]\n if !answer.include?(temp)\n answer << temp\n num /= temp\n end\n\n else\n answer << primes[i]\n num /= primes[i]\n end\n\n else\n i += 1\n if primes[i] > limit\n failed = true\n break\n end\n end\n end\n\n failed = true if answer.include? num\n\n unless failed\n answer << num\n puts \"YES\"\n puts answer.join(' ')\n else\n puts \"NO\"\n end\nend"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/problemset/problem/1294/C\n\nrequire 'prime'\n\nn = gets.to_i\n\nprimes = []\nPrime.each(31610) { |p| primes << p }\n\nn.times do\n num = gets.to_i\n answer = []\n temp = 1\n i = 0\n limit = Math.sqrt(num).floor\n failed = false\n\n while answer.size < 2 \n if num % primes[i] == 0\n if answer.include?(primes[i])\n temp *= primes[i]\n num /= primes[i]\n\n if !answer.include?(temp)\n answer << temp\n temp = 1\n end\n\n else\n answer << primes[i]\n num /= primes[i]\n end\n\n else\n i += 1\n if num == 1 || primes[i] > limit \n failed = true\n break\n end\n end\n end\n\n failed = true if answer.include? num\n\n unless failed\n answer << num\n puts \"YES\"\n puts answer.join(' ')\n else\n puts \"NO\"\n end\nend"}, {"source_code": "require 'prime'\n\nT = gets.to_i\n\nT.times do\n n = gets.to_i\n\n primes = Hash[n.prime_division]\n\n used = Hash.new(false)\n ans = []\n n = 1\n\n primes.each do |v, e|\n e.times do\n n *= v\n\n unless used[n]\n ans << n\n used[n] = true\n n = 1\n end\n end\n end\n\n if ans.size >= 3\n a, b, *r = ans\n c = r.inject(:*)\n\n puts 'YES'\n puts [a, b, c].join(' ')\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "require 'prime'\n\nT = gets.to_i\n\nT.times do\n n = gets.to_i\n\n primes = Hash[n.prime_division]\n\n used = Hash.new(false)\n ans = []\n\n primes.each do |v, e|\n n = 1\n\n e.times do\n n *= v\n\n unless used[n]\n ans << n\n used[n] = true\n n = 1\n end\n end\n end\n\n if ans.size >= 3\n a, b, *r = ans\n c = r.inject(:*)\n\n puts 'YES'\n puts [a, b, c].join(' ')\n else\n puts 'NO'\n end\nend\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nt = gets.to_i\nprimes = [2,3]\nt.times {\n n = gets.chomp\n len = n.length\n n = n.to_i\n # \ud070 \uc218\ub97c \uc808\ubc18\uc73c\ub85c \ub098\ub220\uc11c \ud45c\ud604\ud560 \uc218 \uc788\ub2e4.\n # \ub108\ubb34 \uc798\uac8c \ud45c\uae30\ud558\uba74 \ubaa9\uc801\uc5d0 \ubd80\ud569\ud558\uc9c0 \uc54a\uc73c\ub2c8\uae4c \uc808\ubc18\uc73c\ub85c\ub9cc.\n # \uc55e\ubd80\ubd84\uacfc \ub4b7\ubd80\ubd84\uc758 \ucd5c\ub300\uacf5\uc57d\uc218\ub97c \uad6c\ud55c\ub2e4.\n # \ucd5c\ub300\uacf5\uc57d\uc218\ub85c \ub2e4\uc2dc \uc6d0 \uc218\ub97c \ub098\ub208\ub2e4. \ucd5c\ub300 \uacf5\uc57d\uc218\ub97c \uc18c\uc778\uc218 \ubd84\ud574\ub97c \ud55c\ub2e4.\n # ... \uc774\uac70 \ub098\ub984 \uc2e0\ubc15\ud588\ub294\ub370 \uc2e4\ud328\ud568\n # \ud480\uc774\ub97c \ubcf4\uba74, 2...sqrt(n) \uae4c\uc9c0 \ub450 \ubc88 \ub098\ub220\ubcf4\ub294\uc2dd\uc784.\n # \uadf8\ub9ac\uace0 \uadf8 \ub098\ub208 \uc218\ub97c set\uc5d0 \ub123\uc5b4\ub454\ub2e4.\n # set \uae38\uc774\uac00 2 \ub118\uae30\uba74 OK.\n # a 1\n puts \"YES\"\n puts \"#{collected.keys.join(' ')} #{n}\"\n else\n puts \"NO\"\n end\n end\n\n\n}"}], "src_uid": "0f7ceecdffe11f45d0c1d618ef3c6469"} {"source_code": "n, m = gets.strip.split.map(&:to_i)\np = Array.new(n)\ne = Array.new(m)\nn.times do |i|\n s = gets.strip\n p[i] = s\nend\ncommon = 0\nm.times do |i|\n s = gets.strip\n e[i] = s\n common += 1 if p.include? s\nend\nn -= common\nm -= common\nans = \"YES\"\ntotal = n + m\ni = 1\nwhile true\n if i.odd?\n if common > 0\n common -= 1\n else\n if n > 0\n n -= 1\n else\n ans = \"NO\"\n break\n end\n end\n else\n if common > 0\n common -= 1\n else\n if m > 0\n m -= 1\n else\n break\n end\n end\n end\n i += 1\nend\nputs ans\n", "positive_code": [{"source_code": "#\u5c31\u662fpolandball\u7684n\u4e2a\u8bcd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\uff01\n#\u5c31\u662fenemyball\u7684m\u4e2a\u8bcd\u662f\u4e92\u4e0d\u76f8\u540c\u7684\uff01\n#\u4e00\u4e2a\u7b56\u7565\u662f\uff1a\u5148\u8bf4\u4e24\u4e2a\u4eba\u5171\u540c\u7684\u8bcd\uff0c\u8ba9\u5bf9\u65b9\u80fd\u4f7f\u7528\u7684\u8bcd\u66f4\u5c11\uff01\nnm=gets.chomp.split.map{ |x| x.to_i }\nn=nm[0]\nm=nm[1]\npolandball=[]\nn.times do\n\tx=gets.chomp\n\tpolandball.push(x)\nend\nenemyball=[]\nm.times do\n\tx=gets.chomp\n\tenemyball.push(x)\nend\npolandball.sort!\nenemyball.sort!\n#puts polandball.join(\" \")\n#puts enemyball.join(\" \")\ni=0\nj=0\nsame=0\n#puts \"#{polandball.length} #{enemyball.length}\"\nwhile true\n\tif i>=polandball.length || j>=enemyball.length\n\t\tbreak\n\tend\n\tcase polandball[i]<=>enemyball[j]\n\twhen 0\n\t\t#puts \"#{polandball[i]}==#{enemyball[j]} #{i} #{j}\"\n\t\tsame+=1\n\t\ti+=1\n\t\tj+=1\n\twhen -1\n\t\ti+=1\n\telse\n\t\tj+=1\n\tend\nend\n#puts \"same=#{same}\"\npolandball_word=polandball.length-same+same/2\nif same%2==1\n\tpolandball_word+=1\nend\nenemyball_word=enemyball.length-same+same/2\n#puts \"#{polandball_word} #{enemyball_word}\"\nif polandball_word>enemyball_word\n\tputs \"YES\"\nelse\n\tputs \"NO\"\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn, m = gets.chop.split.map { |v| v.to_i }\n\nif n > m\n puts \"YES\"\n exit 0\nelsif n < m\n puts \"NO\"\n exit 0\nend\n\npolandball_words = []\nn.times do\n polandball_words << gets.chop\nend\n\nenemyball_words = []\nm.times do\n enemyball_words << gets.chop\nend\n\ncommon_words = polandball_words & enemyball_words\ncommon_words_size = common_words.size\nif common_words_size % 2 == 0\n puts \"NO\"\nelse\n puts \"YES\"\nend\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nx,y=[n,m].map{|e|e.times.map{gets.chomp}}\nn+=1 if (x&y).size.odd?\nputs [:NO,:YES,:NO][n<=>m]"}, {"source_code": "n, m = gets.split.map(&:to_i)\na, b = [], []\nn.times { a << gets.chomp }\nm.times { b << gets.chomp }\nx = (a & b).count\nans = (x + 1 >> 1) + n - x > (x >> 1) + m - x\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\n\nplayer1 = Array.new(n) { |e| gets }\nplayer2 = Array.new(m) { |e| gets }\n\ncommon = player1 & player2\n\nplayer1 = player1 - common\nplayer2 = player2 - common\n\nputs (if player1.length + common.length % 2 > player2.length then \"YES\" else \"NO\" end)\n"}, {"source_code": "n, m =gets.chomp.split(\" \").map(&:to_i)\nlist = Array.new; list2 = Array.new\nctr =0\nfor i in 0..n-1\n list[i] = gets.to_s\nend\nfor i in 0..m-1\n list2[i] = gets.to_s\nend\nfor i in 0..n-1\n for j in 0..m-1\n if list[i] == list2[j]\n ctr += 1\n end\n end\nend\nif (ctr%2 == 0)\n n, m = n-ctr/2, m-ctr/2\nelse\n n,m = n-ctr/2, m-ctr/2 - 1\nend\nputs n>m ? \"YES\": \"NO\"\n"}], "negative_code": [{"source_code": "n,m=gets.split.map(&:to_i)\nx,y=[n,m].map{|e|e.times.map{gets.chomp}}\nn+=1 if (x&y).size.even?\nputs [:NO,:YES,:NO][n<=>m]"}, {"source_code": "n,m=gets.split.map(&:to_i)\nx,y=[n,m].map{|e|e.times.map{gets.chomp}}\nn+=1 if (x&y).size.even?\nputs [:YES,:YES,:NO][n<=>m]"}, {"source_code": "n, m = gets.split.map(&:to_i)\na, b = [], []\nn.times { a << gets.chomp }\nm.times { b << gets.chomp }\nx = (a - b).count\nans = (x + 1 >> 1) + n - x > (x >> 1) + m - x\nputs ans ? \"YES\" : \"NO\"\n"}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\np = Array.new(n)\ne = Array.new(m)\nn.times do |i|\n s = gets.strip\n p[i] = s\nend\nm.times do |i|\n s = gets.strip\n e[i] = s\nend\nsaid = []\nans = \"YES\"\ntotal = n + m\ni = 1\nwhile i <= total\n s = nil\n curr = \"\"\n if i.odd?\n s = p.shift\n curr = \"P\"\n else\n s = e.shift\n curr = \"E\"\n end\n while said.include? s\n if i.odd?\n s = p.shift\n else\n s = e.shift\n end\n end\n if s.nil?\n ans = \"NO\" if curr == \"P\"\n break\n end\n said.push s\n i += 1\nend\nans = \"NO\" if ans == \"YES\" && i.odd?\nputs ans\n"}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\np = Array.new(n)\ne = Array.new(m)\nn.times do\n s = gets.strip\n p.push s\nend\nm.times do\n s = gets.strip\n e.push s\nend\nsaid = []\nans = \"YES\"\ntotal = n + m\ni = 1\nwhile i <= total\n s = nil\n curr = \"\"\n if i.odd?\n s = p.pop\n curr = \"P\"\n else\n s = e.pop\n curr = \"E\"\n end\n if s.nil?\n ans = \"NO\" if curr == \"P\"\n break\n end\n next if said.include? s\n said.push s\n i += 1\nend\nputs ans\n"}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\np = Array.new(n)\ne = Array.new(m)\nn.times do\n s = gets.strip\n p.push s\nend\nm.times do\n s = gets.strip\n e.push s\nend\nsaid = []\nans = \"YES\"\nif n < m\n ans = \"NO\"\nelse\n total = n + m\n i = 1\n while i <= total && p.length > 0 && e.length > 0\n s = i.odd? ? p.pop : e.pop\n next if said.include? s\n said.push s\n i += 1\n end\n ans = \"NO\" if p.length == 0 && e.length > 0\nend\nputs ans\n"}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\np = Array.new(n)\ne = Array.new(m)\nn.times do |i|\n s = gets.strip\n p[i] = s\nend\nm.times do |i|\n s = gets.strip\n e[i] = s\nend\nsaid = []\nans = \"YES\"\ntotal = n + m\ni = 1\nwhile i <= total\n s = nil\n curr = \"\"\n if i.odd?\n s = p.shift\n curr = \"P\"\n else\n s = e.shift\n curr = \"E\"\n end\n next if said.include? s\n if s.nil?\n ans = \"NO\" if curr == \"P\"\n break\n end\n said.push s\n i += 1\nend\nputs ans\n"}, {"source_code": "n, m =gets.chomp.split(\" \").map(&:to_i)\nlist = Array.new; list2 = Array.new\nctr =0\nfor i in 0..n-1\n list[i] = gets\nend\nfor i in 0..m-1\n list2[i] = gets\nend\nfor i in 0..n-1\n for j in i..m-1\n if list[i] == list2[j]\n ctr += 1\n end\n end\nend\nif (ctr%2 == 0)\n n, m = n-ctr/2, m-ctr/2\nelse\n n,m = n-ctr/2, m-ctr/2 - 1\nend\nputs n>m ? \"YES\": \"NO\"\n"}], "src_uid": "4b352854008a9378551db60b76d33cfa"} {"source_code": "words = (0...3).map { gets.strip.tr('-;_', '').downcase }\ngets\n$<.map do |s|\n s = s.strip.tr('-;_', '').downcase\n puts [\"WA\", \"ACC\"][words.permutation.map { |ws| ws.join } .include?(s) ? 1 : 0]\nend\n", "positive_code": [{"source_code": "def gao(s)\n\t_ = s.downcase.gsub(/[^a-z]/, '')\nend\n\na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n\tputs a.member?(gao(gets)) ? :ACC : :WA\nend\n\n\n"}, {"source_code": "arr = []\n3.times do\n\tarr << gets.chomp.tr(\"-;_\",\"\").downcase\nend\nlist = arr.permutation(3).map{|a| a.inject(\"\",&:concat)}\n# puts \"#{list}\"\nn = gets.to_i\nn.times do\n\ts = gets.chomp.tr(\"-;_\",\"\").downcase\n\tputs list.include?(s) ? \"ACC\" : \"WA\"\nend"}, {"source_code": "# http://codeforces.com/problemset/problem/61/B\n\ninit_str = []\n3.times do\n init_str << gets.chomp.downcase.gsub(/[;_-]/, \"\")\nend\n\nstudents_ans = []\nn = gets.chomp.to_i\nn.times do\n students_ans << gets.chomp.downcase.gsub(/[;_-]/, \"\")\nend\n\na, b, c = init_str\nacc_ans = [a + b + c, a + c + b, b + a + c, b + c + a, c + a + b, c + b + a]\n\nfor i in 0..(n - 1)\n puts acc_ans.include?(students_ans[i]) ? \"ACC\" : \"WA\"\nend\n"}, {"source_code": "def gao(s)\n\t_ = s.downcase.gsub(/[^a-z]/, '')\nend\n\na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n\tputs a.member?(gao(gets)) ? :ACC : :WA\nend\n\n\n"}, {"source_code": "def gao(s)\n\t_ = s.downcase.gsub(/[^a-z]/, '')\nend\n\na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n\tputs a.member?(gao(gets)) ? :ACC : :WA\nend\n\n\n"}, {"source_code": "def gao(s)\n\t_ = s.downcase.gsub(/[^a-z]/, '')\nend\n \na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n\tputs a.member?(gao(gets)) ? :ACC : :WA\nend\n "}, {"source_code": "def gao(s)\n\t_ = s.downcase.gsub(/[^a-z]/, '')\nend\n\na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n\tputs a.member?(gao(gets)) ? :ACC : :WA\nend\n\n"}, {"source_code": "input=[gets.split[0],gets.split[0],gets.split[0]]\nfor i in 0..2\n\tinput[i]=input[i].gsub(/[:;,_-]/,\"\").upcase\nend\nn=gets.to_i\nn.times{\n\tdata=gets.split[0]\n\tdata=data.gsub(/[:;,_-]/,\"\").upcase\n\tans=0\n\tinput.permutation.to_a.each{|a|\n\t\tif data==a[0]+a[1]+a[2] then\n\t\t\tputs \"ACC\"\n\t\t\tans=1\n\t\t\tbreak\n\t\tend\t\n\t}\n\tif ans==0 then\n\t\tputs \"WA\"\n\tend\t\n}\n"}, {"source_code": "include Math\nrequire \"prime\"\nrequire \"bigdecimal\"\nrequire \"bigdecimal/math\"\nrequire \"matrix\"\nrequire \"pp\"\nrequire \"benchmark\"\n\nInfinity = 1/0.0\n\nalias p! p\ndef p(*objs)\n def onep(obj)\n case obj\n when Matrix\n puts\"Matrix[\"\n obj.to_a.each{|row|p row}\n puts\"]\"\n else\n p! obj\n end\n end\n objs.each{|obj|\n onep obj\n }\nend\ndef pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end\nclass String;def to_ia;self.split.map(&:to_i);end;end\ndef getia;gets.to_ia;end\ndef geti;gets.to_i;end\nclass Object;def dcopy;Marshal.load(Marshal.dump(self));end;end\n\n\na=gets.chomp.gsub(/;|-|_/,\"\").upcase\nb=gets.chomp.gsub(/;|-|_/,\"\").upcase\nc=gets.chomp.gsub(/;|-|_/,\"\").upcase\n\nd=[a+b+c,a+c+b,b+a+c,b+c+a,c+a+b,c+b+a]\n\nn=geti\nn.times{\n s=gets.chomp.gsub(/;|-|_/,\"\").upcase\n puts d.include?(s) ? \"ACC\" : \"WA\"\n}\n\n\n"}, {"source_code": "def gao(s)\n\t_ = s.downcase.gsub(/[^a-z]/, '')\nend\n\na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n\tputs a.member?(gao(gets)) ? :ACC : :WA\nend\n\n\n"}, {"source_code": "def gao(s)\n\t_ = s.downcase.gsub(/[^a-z]/, '')\nend\n\na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n\tputs a.member?(gao(gets)) ? :ACC : :WA\nend\n\n\n"}, {"source_code": "def gao(s)\n\t_ = s.downcase.gsub(/[^a-z]/, '')\nend\n\na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n\tputs a.member?(gao(gets)) ? :ACC : :WA\nend\n\n"}, {"source_code": "def gao(s)\n\t_ = s.downcase.gsub(/[^a-z]/, '')\nend\n\na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n\tputs a.member?(gao(gets)) ? :ACC : :WA\nend\n\n\n"}, {"source_code": "s = []\n3.times { |i| s[i] = gets.downcase.delete \"-;_\\n\" }\na = s.permutation.to_a.map { |a,b,c| a + b + c }\ngets.to_i.times do\n x = gets.downcase.delete \"-;_\\n\"\n puts (a.include?(x) ? \"ACC\" : \"WA\")\nend"}, {"source_code": "def gao(s)\n\t_ = s.downcase.gsub(/[^a-z]/, '')\nend\n\na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n\tputs a.member?(gao(gets)) ? :ACC : :WA\nend\n\n\n"}, {"source_code": "def gao(s)\n\t_ = s.downcase.gsub(/[^a-z]/, '')\nend\n\na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n\tputs a.member?(gao(gets)) ? :ACC : :WA\nend\n\n\n"}, {"source_code": "def gao(s)\n _ = s.downcase.gsub(/[^a-z]/, '')\nend\n\na = [gets, gets, gets].permutation.map{|_| gao(_ * '')}\ngets.to_i.times do\n puts a.member?(gao(gets)) ? :ACC : :WA\nend"}], "negative_code": [], "src_uid": "95ccc87fe9e431f9c6eeffeaf049f797"} {"source_code": "t = gets.to_i\nt.times do\n n, k = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n hist = Array.new(n, 0)\n count = 0\n for i in 1..(n - 2) do\n count += 1 if a[i - 1] < a[i] && a[i] > a[i + 1]\n hist[i] = count\n end\n hist[n - 1] = hist[n - 2]\n # p hist\n s_max = 0\n for l in 0..(n - k) do\n s = hist[l + k - 2] - hist[l] + 1\n if s > s_max\n s_max = s\n l_ans = l\n end\n end\n puts \"#{s_max} #{l_ans + 1}\"\nend\n", "positive_code": [{"source_code": "# coding: utf-8\n\nt = gets.to_i\nt.times {\n n, k = gets.split.map(&:to_i)\n peaks = []\n l = 0\n max_peaks = 0\n a = gets.split.map(&:to_i)\n for i in 2...n\n if a[i-2] < a[i-1] && a[i-1] > a[i]\n #p \"add peak #{i-1}\"\n peaks << i-1\n end\n\n if i - (k-1) >= 0\n while !peaks.empty? && peaks.first <= i-(k-1)\n #p \"===> #{i}\"\n #p peaks\n peaks.shift\n end\n\n if max_peaks < (peaks.count)\n #p \"updating #{i}\"\n max_peaks = peaks.count\n l = i-(k-1) #zero-based\n end\n end\n end\n #p peaks\n # [l, l+k -1] <=> (l-1, l+k)\n puts \"#{max_peaks + 1} #{l + 1}\" #l+1 -> one-based\n}"}, {"source_code": "t = gets.chomp.to_i\nt.times do\n\tn, k = gets.chomp.split(\" \").map(&:to_i)\n\tarr = gets.chomp.split(\" \").map(&:to_i)\n\tngo = Array.new(n, 0)\n\t(1..arr.length-2).each do |a|\n\t\tif arr[a-1] < arr[a] && arr[a] > arr[a+1] then\n\t\t\t# ngo[a-1] = 1\n\t\t\t# ngo[a] = 2\n\t\t\t# ngo[a+1] = 1\n\t\t\tngo[a]=1\n\t\tend\n\tend\n\t#puts \"ppp\"\n\t#p ngo\n\tsum = ngo.slice(1,k - 2).inject(:+)\n\tmax = sum\n\tind = 1\n\t(2..n - k + 2).each do |i|\n\t\t#puts \"i:#{i}\"\n\t\tsum = sum - ngo[i - 1] + ngo[i + k - 2 - 1]\n\t\tif max < sum then\n\t\t\t#p ngo.slice(i, k - 2)\n\t\t\t#p arr.slice(i, i + k-1)\n\t\t\tmax = sum\n\t\t\tind = i\n\t\tend\n\tend\n\tputs \"#{max + 1} #{ind}\"\nend"}, {"source_code": "\n\ndef solve arr, k\n peak = []\n peak[0] = 0\n (1...arr.length-1).each do |i|\n if arr[i] > arr[i - 1] && arr[i] > arr[i + 1]\n peak[i] = peak[i - 1] + 1\n else\n peak[i] = peak[i - 1]\n end\n end\n peak[arr.length - 1] = peak[arr.length - 2]\n res = [-1, 1000000]\n (0..arr.length - k).each do |i|\n if peak[i + k - 2] - peak[i] > res[0]\n res[0] = peak[i + k - 2] - peak[i]\n res[1] = i\n end\n end\n [res[0] + 1, res[1] + 1]\nend\n\nt = STDIN.gets.chomp.to_i\n\nt.times do |i|\n n, k = STDIN.gets.chomp.split.map {|i| i.to_i}\n arr = STDIN.gets.chomp.split.map {|i| i.to_i}\n res = solve arr, k\n puts res.join(\" \")\nend\n"}], "negative_code": [], "src_uid": "8e182e0acb621c86901fb94b56ff991e"} {"source_code": "n = gets.strip.to_i\ndata = gets.split.map(&:to_i)\n\ncount = [0] * (data.max + 1)\ndata.each { |i| count[i] += 1 }\n\nputs ([1] + (2...count.length).map { |i| \n (i...count.length).step(i).map { |j| \n count[j] \n }.reduce(0, :+) \n}).max\n", "positive_code": [{"source_code": "N = 1e5\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nc = Array.new(N + 1, 0)\na.each{|x| c[x] += 1}\namx = a.max\nans = 1\n(2..amx).each do |i|\n cnt = 0\n (i..amx).step(i){|j| cnt += c[j]}\n ans = [ans, cnt].max\nend\np ans\n"}, {"source_code": "N = 10 ** 5\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nc = Array.new(N + 1, 0)\na.each{|x| c[x] += 1}\nans = 1\n2.upto(N) do |i|\n cnt = 0\n i.step(N, i){|j| cnt += c[j]}\n ans = [ans, cnt].max\nend\np ans\n"}, {"source_code": "N = 10 ** 5\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nc = Array.new(N + 1, 0)\na.each{|x| c[x] += 1}\nans = 1\n(2..N).each do |i|\n cnt = 0\n i.step(N, i){|j| cnt += c[j]}\n ans = [ans, cnt].max\nend\np ans\n"}, {"source_code": "#!/usr/bin/ruby\n#require 'prime'\nh=Hash.new 0\ngets\ngets.split.each{|_|\n\tif false\n\t\t_.to_i.prime_division.each{|n,p|h[n]+=1}\n\telse\n\t\tn=_.to_i\n\t\ti=2\n\t\twhile i*i<=n\n\t\t\tif n%i==0\n\t\t\t\th[i]+=1\n\t\t\t\tn/=i while n%i==0\n\t\t\tend\n\t\t\ti+=1\n\t\tend\n\t\th[n]+=1 if n>1\n\tend\n}\np h.values.max||1"}], "negative_code": [{"source_code": "primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313]\n\nn = gets.to_i\ns = gets.split.map(&:to_i)\n\nmx = 1\nprimes.each do |p|\n break if p >= s.max\n c = 0\n s.each do |num|\n next if p > num \n c += 1 if num % p == 0\n end \n mx = [c, mx].max\nend\n\nq = Hash.new(0)\ns.each{|x| q[x] += 1 if x != 1}\n\np [mx, q.values.max || 0].max\n"}, {"source_code": "primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313]\n\nn = gets.to_i\ns = gets.split.map(&:to_i).sort!\n\nmx = 1\nprimes.each do |p|\n break if p >= s[-1]\n c = 0\n s.each do |num|\n next if p > num \n c += 1 if num % p == 0\n end\n mx = [c, mx].max\nend\n\nq = Hash.new(0)\ns.each{|x| q[x] += 1 if x != 1}\n\np [mx, q.values.max || 0].max\n"}, {"source_code": "n = gets.strip.to_i\ndata = gets.split.map(&:to_i)\n\ncount = [0] * (data.max + 1)\ndata.each { |i| count[i] += 1 }\n\nputs (2...count.length).map { |i| \n (i...count.length).step(i).map { |j| \n count[j] \n }.reduce(0, :+) \n}.max\n"}, {"source_code": "N = 1e5\n\nn = gets.to_i\na = gets.split.map(&:to_i)\nc = Array.new(N + 1, 0)\na.each{|x| c[x] += 1}\namx = a.max\nans = 0\n(2..amx).each do |i|\n cnt = 0\n (i..amx).step(i){|j| cnt += c[j]}\n ans = [ans, cnt].max\nend\np n == 1 ? 1 : ans\n"}, {"source_code": "primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313]\n\nn = gets.to_i\ns = gets.split.map(&:to_i).sort!\n\nmx = 1\nprimes.each do |p|\n break if p >= s[-1]\n c = 0\n s.each do |num|\n next if p > num \n c += 1 if num % p == 0\n end\n mx = [c, mx].max\nend\n\nq = Hash.new(0)\ns.each{|x| q[x] += 1}\n\np [mx, q.values.max].max\n"}, {"source_code": "primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313]\n\nn = gets.to_i\ns = gets.split.map(&:to_i).sort!\n\nmx = 1\nprimes.each do |p|\n break if p >= s[-1]\n c = 0\n s.each do |num|\n next if p > num \n c += 1 if num % p == 0\n end\n mx = [c, mx].max\nend\n\np mx\n"}], "src_uid": "eea7860e6bbbe5f399b9123ebd663e3e"} {"source_code": "gets\nl=gets.split.map(&:to_i)\nm=(1..3).map{|i|(0..l.size).select{|j|i==l[j]}}\np n=m.map(&:size).min\nn.times{|i|puts m.map{|a|a[i]+1}*\" \"}\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split(\" \").map(&:to_i)\nprint [a.count(1), a.count(2), a.count(3)].min\nprint \"\\n\"\n[a.count(1), a.count(2), a.count(3)].min.times {\n p = a.index(1)\n print p+1\n a[p] = 0\n print ' '\n p = a.index(2)\n print p+1\n a[p]= 0\n print ' '\n p = a.index(3)\n print p+1\n a[p] = 0\n print ' '\n print \"\\n\"\n}"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\nn = gets.to_i\ns = gets.split.map(&:to_i)\ni = 1\na = []\ns.each do |g|\n a << [i, g]\n i += 1\nend\n\none = a.select { |i| i[1] == 1 }\ntwo = a.select { |i| i[1] == 2 }\nthree = a.select { |i| i[1] == 3 }\n\nif one.length == 0 or two.length == 0 or three.length == 0\n puts 0\n exit 0\nend\n\nans = []\nuntil one.length == 0 or two.length == 0 or three.length == 0\n o = one.shift\n tw = two.shift\n th = three.shift\n\n ans << \"#{o[0]} #{tw[0]} #{th[0]}\"\nend\n\nputs \"#{ans.length}\"\nans.each do |an|\n puts an\nend\n\n"}, {"source_code": "n = gets.to_i\n\nps = []\nms = []\npes = []\n\ngets.split.map(&:to_i).each_with_index do |t, i|\n if t == 1\n ps << i + 1\n elsif t == 2\n ms << i + 1\n else\n pes < [], 2 => [] , 3 => []}\nstudents.each_with_index do |s,i|\ngift[s] << i + 1\nend\n# puts \"#{gift}\"\narr = []\ngift.each { |k,v|\n arr << v.count\n}\nmin_teams = arr.min\nputs min_teams\n(0..min_teams - 1).each { |i|\n puts \"#{gift[1][i]} #{gift[2][i]} #{gift[3][i]}\"\n}\n"}, {"source_code": "n = gets.to_i\na = [nil] + gets.split.map(&:to_i)\nb = [nil] + Array.new(3, 0)\nfor i in 1..n\n b[a[i]] += 1\nend\nw = b[1..3].min\nputs w\nif w != 0\n x = 0\n y = 0\n z = 0\n ans = Array.new(w){Array.new(3)}\n for i in 1..n\n if a[i] == 1 && x < w\n ans[x][0] = i\n x += 1\n a[i] = 0\n elsif a[i] == 2 && y < w\n ans[y][1] = i\n y += 1\n a[i] = 0\n elsif a[i] == 3 && z < w\n ans[z][2] = i\n z += 1\n a[i] = 0\n end\n end\n w.times do |i|\n puts \"#{ans[i][0]} #{ans[i][1]} #{ans[i][2]}\"\n end\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split.map{|x| x.to_i - 1}\nans = [[], [], []]\na.each.with_index(1){|x, i| ans[x] << i}\nw = ans.map(&:size).min\nputs w\nputs ans.map{|x| x.take(w)}.transpose.map{|x| x.join(' ')}\n"}, {"source_code": "gets\nl=gets.split.map(&:to_i)\nm=(1..3).map{|i|(0..l.size).select{|j|i==l[j]}}\np n=m.map(&:size).min\nn.times{|i|puts m.map{|a|a[i]+1}*\" \"}\n"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\n\nresult = {\n 1 => [],\n 2 => [],\n 3 => []\n}\n\na.each_with_index { |v, i| result[v] << i+1 }\n\nresult = result[1].zip(result[2]).zip(result[3]).map(&:flatten).select { |w| w.none?(&:nil?) }\n\nputs result.size\nresult.each { |w| puts w.join(' ') }\n"}, {"source_code": "Person = Struct.new(:index, :subj) do\n def <=> (other)\n self.subj <=> other.subj\n end\nend\n\nn = gets.to_i\narr = gets.split(\" \").each_with_index.map { |x, i| Person.new(i + 1, x.to_i) }.group_by { |p| p.subj }.values\n\nif arr.length != 3\n puts 0\nelse\n len = arr.min_by { |x| x.length }.length\n\n puts len\n for i in 0...len\n puts \"#{arr[0][i].index} #{arr[1][i].index} #{arr[2][i].index} \"\n end\nend\n\n"}, {"source_code": "a=Array.new\nb=Array.new\nc=Array.new\nd=Array.new\ni=j=k=0\nn=gets.to_i\nstr=gets.to_s\nd=str.split\nfor r in 0..n-1\n h=d[r].to_i\n# print h\n if h==1\n a[i]=r+1\n i+=1\n elsif h==2\n b[j]=r+1\n j+=1\n elsif h==3\n c[k]=r+1\n k+=1\n end\nend\n#puts i\n#puts j\n#puts k\nif i<=j and i<=k\n h=i\nelsif j<=i and j<=k\n h=j\nelsif k<=i and k<=j\n h=k\nend\nputs h\nfor r in 0..h-1\n print a[r]\n print \" \"\n print b[r]\n print \" \"\n puts c[r]\nend\n"}, {"source_code": "# 490A\n\ngets.to_i\ng = [[], [], []]\ngets.chomp.split.each_with_index do |x, i|\n g[x.to_i - 1] << i + 1\nend\nm = g.map { |a| a.size }.min\nputs m\nm.times { |i| puts \"#{g[0][i]} #{g[1][i]} #{g[2][i]}\" }"}, {"source_code": "gets\nl=gets.split.map(&:to_i)\nm=(1..3).map{|i|(0..l.size).select{|j|i==l[j]}}\np n=m.map(&:size).min\nn.times{|i|puts m.map{|a|a[i]+1}*\" \"}\n"}, {"source_code": "n, t = 2.times.map{gets.split.map(&:to_i)}\nm = 3.times.map{|x| t.each_index.select{|i| t[i]==x+1}}\nputs s = m.map(&:size).min\ns.times.each{|i| puts 3.times.map{|j| (m[j][i] + 1).to_s}.join(\" \")}\n\n\n"}, {"source_code": "n = gets.to_i\nt = gets.split.map(&:to_i)\nm = (1..3).to_a.map{ |x| \n t.each_index.select{ |i| \n t[i] == x\n }\n }\n s = m.map(&:size).min\n puts s\n s.times.each{ |i|\n puts 3.times.map{ |j|\n \"#{m[j][i] + 1}\"\n }.join(\" \")\n }\n\n \n"}, {"source_code": "n = Integer gets\narry = gets\narry = arry.split(\" \")\nfor i in 0..n-1\n arry[i] = Integer arry[i]\nend\n\na=[[],[],[]]\n\nfor i in 1..n\n a[arry[i-1]-1] << i\nend\n\nsize = a[0].size()\nif a[1].size() (other)\n self.subj <=> other.subj\n end\nend\n\nn = gets.to_i\narr = gets.split(\" \").each_with_index.map { |x, i| Person.new(i, x.to_i) }\n\narr = arr.group_by { |x| x.subj }\n\none = arr[1].map { |x| x.index }\nscn = arr[2].map { |x| x.index }\nthr = arr[3].map { |x| x.index }\n\nstop = [one.length, scn.length, thr.length].min\n\nputs stop\nfor i in 0...stop\n puts \"#{one[i]} #{scn[i]} #{thr[i]}\"\nend"}], "src_uid": "c014861f27edf35990cc065399697b10"} {"source_code": "n, d, h = gets.split(\" \").map(&:to_i)\nd += 1\nh += 1\n\nif n < d\n p -1\n exit\nend\n\nif d >= 2*h\n p -1\n exit\nend\n\nif d == h && h >= 3\n (h-1).times do |i|\n puts \"#{i+1} #{i+2}\"\n end\n\n (n-h).times do |i|\n b = h\n puts \"2 #{b+i+1}\"\n end\n\n exit\nend\n\nif d == h && h < 3\n if n != d\n p -1\n exit\n end\n\n (h-1).times do |i|\n puts \"#{i+1} #{i+2}\"\n end\n\n exit\nend\n\n(h-1).times do |i|\n puts \"#{i+1} #{i+2}\"\nend\n#puts \".\"\nputs \"1 #{h+1}\"\n(d-h-1).times do |i|\n b = h\n puts \"#{b+i+1} #{b+i+2}\"\nend\n#puts \".\"\n\n(n-d).times do |i|\n b = d\n puts \"1 #{b+i+1}\"\nend\n", "positive_code": [{"source_code": "buf=gets.split(\" \")\nn, d, h=buf[0].to_i, buf[1].to_i, buf[2].to_i\nif n<=d || d>h*2 || n>2 && d==1\n\tputs -1\nelse\n\tfor i in 2..h+1\n\t\tputs \"#{i-1} #{i}\"\n\tend\n\tlast=1\n\tfor i in 1..d-h\n\t\tputs \"#{last} #{i+h+1}\"\n\t\tlast=i+h+1\n\tend\n\tfor i in 1..n-d-1\n\t\tputs \"#{h} #{i+d+1}\"\n\tend\nend"}], "negative_code": [{"source_code": "n, d, h = gets.split(\" \").map(&:to_i)\n\nif n < d\n p -1\n exit\nend\n\nif d >= 2*h\n p -1\n exit\nend\n\nif d == h && h >= 3\n (h-1).times do |i|\n puts \"#{i+1} #{i+2}\"\n end\n\n (n-h).times do |i|\n b = h\n puts \"2 #{b+i+1}\"\n end\n\n exit\nend\n\nif d == h && h < 3\n if n != d\n p -1\n exit\n end\n\n (h-1).times do |i|\n puts \"#{i+1} #{i+2}\"\n end\n\n exit\nend\n\n(h-1).times do |i|\n puts \"#{i+1} #{i+2}\"\nend\nputs \"1 #{h+1}\"\n(d-h-1).times do |i|\n b = h+1\n puts \"#{b+i+1} #{b+i+2}\"\nend\n\n(n-d).times do |i|\n b = d+1\n puts \"1 #{b+i+1}\"\nend\n"}, {"source_code": "buf=gets.split(\" \")\nn, d, h=buf[0].to_i, buf[1].to_i, buf[2].to_i\nif n<=d || d>h*2\n\tputs -1\nelse\n\tfor i in 2..h+1\n\t\tputs \"#{i-1} #{i}\"\n\tend\n\tlast=1\n\tfor i in 1..d-h\n\t\tputs \"#{last} #{i+h+1}\"\n\t\tlast=i+h+1\n\tend\n\tfor i in 1..n-d-1\n\t\tputs \"#{h} #{i+d+1}\"\n\tend\nend"}], "src_uid": "32096eff277f19d227bccca1b6afc458"} {"source_code": "gets.chomp.to_i.times do |_i|\n a, b, c = gets.split.map(&:to_i)\n puts a + b + c - 1\nend\n", "positive_code": [{"source_code": "gets;$<.map{|x|p x.split.map(&:to_i).sum-1}\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n a, b, c = gets.split.map(&:to_i).sort\n\n puts Math.sqrt(b ** 2 + (c - a) ** 2).ceil\nend\n"}, {"source_code": "gets;$<.map{|x|p x.split.map(&:to_i).max}"}, {"source_code": "gets.to_i.times{p gets.split.map(&:to_i).sum-1}\n"}], "negative_code": [], "src_uid": "40d679f53417ba058144c745e7a2c76d"} {"source_code": "T = gets.to_i\nT.times do |i|\n n = gets.to_i\n str = gets.chomp\n result = true\n (n/2).times do |i|\n diff = str[i].ord - str[n-i-1].ord\n unless [0, 2, -2].include?(diff)\n result = false\n break\n end\n end\n puts result ? 'YES' : 'NO'\nend", "positive_code": [{"source_code": "gets.to_i.times{gets;s=gets.chomp\n\tputs [s.bytes,s.bytes.reverse].transpose.all?{|x,y|[-2,0,2].include?(x-y)} ? :YES : :NO\n}"}, {"source_code": "t=gets.to_i\n\nchars = ('a'..'z').to_a\nhsh = {}\n0.upto(25).each do |pi|\n hsh[chars[pi]] = []\n hsh[chars[pi]] << chars[pi-1] if pi>0\n hsh[chars[pi]] << chars[pi+1] if pi<25\nend\n\nt.times do\n n=gets.to_i\n str=gets.strip\n hn=n/2\n possible = true\n 0.upto(hn-1).each do |i|\n break unless possible\n j = n-1 - i\n # puts hsh[str[i]].inspect\n # puts hsh[str[j]].inspect\n possible = possible && (hsh[str[i]] & hsh[str[j]]).any?\n end\n puts (possible ? \"YES\" : \"NO\")\nend"}, {"source_code": "A = 'a'.ord\nZ = 'z'.ord\n\ndef g(c)\n c > -1 ? c.chr : c\nend\n\ndef f\n n = gets.chomp.to_i\n s = gets.chomp\n\n (0..(n/2)).each do |i|\n j = -1 - i\n a = s[i].ord\n b = s[j].ord\n \n \n amin = (a - 1) < A ? -1 : a - 1\n amax = (a + 1) > Z ? -1 : a + 1\n bmin = (b - 1) < A ? -1 : b - 1\n bmax = (b + 1) > Z ? -1 : b + 1\n # puts [i, j, s[i], s[j], a, b].inspect\n # puts [g(amin), g(amax), g(bmin), g(bmax)].inspect\n aminbmax = bmax != -1 && amin != -1 && bmax == amin\n amaxbmax = bmax != -1 && amax != -1 && bmax == amax\n aminbmin = bmin != -1 && amin != -1 && bmin == amin\n amaxbmin = bmin != -1 && amax != -1 && bmin == amax\n\n # puts [aminbmax, amaxbmax, aminbmin, amaxbmin].inspect\n \n if aminbmax || amaxbmax || aminbmin || amaxbmin\n else\n puts 'NO'\n return\n end\n end\n\n puts 'YES'\nend\n\nt = gets.chomp.to_i\nt.times do\n f\nend\n"}, {"source_code": "def palindrome(x)\n return x==x.reverse\nend\n\nt = gets.to_i\n\nlarr = []\narr = []\n\nt.times do\n larr.push gets.to_i\n arr.push gets.to_s\nend\n\nt.times do |i|\n num = larr[i]\n string = arr[i]\n\n# if palindrome(string)\n# puts \"YES\"\n# next\n# end\n f = false\n\n (0..num/2-1).each do |c|\n asdf = (string[c].ord-string[num-c-1].ord).abs\n if !(asdf == 0 or asdf == 2)\n# puts (string[c].ord-string[num-c-1].ord).abs\n puts \"NO\"\n f = true\n break\n end\n end\n\n next if f\n\n puts \"YES\"\nend"}, {"source_code": "i = gets.to_i\n\ndef checkpal(sa,sb)\n for i in 0..sa.length-1 do\n if sa[i].ord == sb[i].ord || (sa[i].ord-sb[i].ord).abs == 2\n next\n else\n return puts 'NO'\n end\n end\n return puts 'YES'\nend\n\ni.times do\n k = gets.to_i\n s = gets.chomp\n sa = s[0..(k/2)-1]\n sb = s[k/2..k].reverse\n checkpal(sa,sb)\nend"}], "negative_code": [{"source_code": "gets.to_i.times{gets;s=gets.chomp\n\tputs [s.bytes,s.bytes.reverse].transpose.all?{|x,y|[-2,0,2].include?(x-y)} ? :Yes : :No\n}"}, {"source_code": "T = gets.to_i\nT.times do |i|\n n = gets.to_i\n str = gets.chomp\n result = true\n (n/2).times do |i|\n diff = (str[i].ord - str[n-i-1].ord) % 26\n unless [0, 2, 24].include?(diff)\n result = false\n break\n end\n end\n puts result ? 'YES' : 'NO'\nend"}], "src_uid": "cc4cdcd162a83189c7b31a68412f3fe7"} {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\ncnt = 0\na.each do |x|\n cnt += (x != 1) ? 1 : 0\nend\nif (cnt < n)\n print cnt\n exit\nend\ng = a[0]\na[1..-1].each do |x|\n g = g.gcd(x)\nend\nif (g > 1)\n print -1\n exit\nend\nans = n\n(0..n - 1).each do |i|\n g = a[i]\n (i..n - 1).each do |j|\n g = g.gcd(a[j])\n if (g == 1)\n ans = [ans, j - i + 1].min\n break\n end\n end\nend\nprint ans - 1 + n - 1\n", "positive_code": [{"source_code": "n= gets.to_i\na = gets.split(\" \").map(&:to_i)\n\nk = a.dup\nflag = false\ncount = 0\nwhile(a.size > 0)\n\tif a.count(1) != 0\n\t\tflag = true\n\t\tbreak\n\tend\n\tb = []\n\tfor i in 0..(a.size-2)\n\t\tb << (a[i].gcd a[i+1])\n\tend\n\ta = b\n\tcount += 1\nend\nif flag\n\tif k.count(1) > 1\n\t\tprint(n - k.count(1) + count)\n\telse\n\t\tprint(n - 1 + count)\n\tend\nelse\n\tprint('-1')\nend\n\n\n"}, {"source_code": "n= gets.to_i\na = gets.split(\" \").map(&:to_i)\n\nk = a.dup\nflag = false\ncount = 0\nwhile(a.size > 0)\n\tif a.count(1) != 0\n\t\tflag = true\n\t\tbreak\n\tend\n\tb = []\n\tfor i in 0..(a.size-2)\n\t\tb << (a[i].gcd a[i+1])\n\tend\n\ta = b\n\tcount += 1\nend\nif flag\n\tif k.count(1) > 1\n\t\tprint(n - k.count(1) + count)\n\telse\n\t\tprint(n - 1 + count)\n\tend\nelse\n\tprint('-1')\nend\n\n\n"}], "negative_code": [{"source_code": "n= gets.to_i\na = gets.split(\" \").map(&:to_i)\n\nk = a.dup\nflag = false\ncount = 0\nwhile(a.size > 0)\n\tif a.count(1) != 0\n\t\tflag = true\n\t\tbreak\n\tend\n\tb = []\n\tfor i in 0..(a.size-2)\n\t\tb << (a[i].gcd a[i+1])\n\tend\n\ta = b\n\tcount += 1\nend\nif flag\n\tprint(n - a.count(1) + count)\nelse\n\tprint('-1')\nend\n\n\n"}], "src_uid": "c489061d9e8587d2e85cad0e2f23f3fb"} {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\n\nmax = arr.max\nputs arr.map { |a| max - a }.inject(0, :+)\n", "positive_code": [{"source_code": "gets;a=gets.split.map &:to_i;p a.max*a.size-(a.inject :+)"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\na = gets.split.map(&:to_i)\ntop = a.max\nfullfill = 0\nfor i in a\n fullfill += top - i\nend\nputs fullfill"}, {"source_code": "class A\n attr_reader(:arr)\n def initialize(arr)\n @arr = arr\n end\n\n def max\n arr.max\n end\n\n def diffs\n m = max\n arr.map{|a| m - a}\n end\n\n def out\n diffs.inject(:+)\n end\nend\n\n_ = gets\nxs = gets.split(\" \").map(&:to_i)\nputs A.new(xs).out\n"}, {"source_code": "citizens = gets.chomp.to_i\nw = gets.chomp\nwelfare = w.split\n\ncount = 0\nfor x in (0..citizens-1)\n\tfor i in (0..citizens-1)\n\t\tif x != i\n\t\t\tif welfare[x].to_i < welfare[i].to_i\n\t\t\t\tcount += (welfare[i].to_i - welfare[x].to_i)\n\t\t\t\twelfare[x] = welfare[i]\n\t\t\tend\n\t\tend\n\tend\nend\n\nprint count"}, {"source_code": "gets\narr = gets.split().map &:to_i\nsum = 0\narr.each {|i| sum+= (arr.max - i)}\nputs sum"}, {"source_code": "n = gets.chomp.to_i\n*pieces = gets.chomp.split.map(&:to_i)\n\nmax = pieces.max\np pieces.reduce(0) {|acc, n| n < max ? acc + max - n : acc }"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\n\nputs a.map { |x| a.max - x }.inject(&:+)\n"}, {"source_code": "\nn = gets.chomp.to_i\ncontainer = gets.chomp.split().map { |e| e.to_i }\nmaxEle = container.max\nanswer = 0\nfor i in container\n answer += maxEle - i\nend\n\nputs answer"}, {"source_code": "require 'mathn' \n\nn = gets.to_i \nsum = 0 \n\naaa = Array.new(n) \naab = Array.new(n)\naaa = gets.chomp.split \n\nmax = aaa[0].to_i \n\nfor i in 0...n \n aab[i] = aaa[i].to_i \n sum += aab[i] \n max = aab[i] if max < aab[i]\nend \n\n# puts sum \n\nsum = max*n - sum \n\nputs sum\n "}, {"source_code": "gets;a=gets.split.map(&:to_i);p a.max*a.size-a.reduce(:+)"}, {"source_code": "gets;a=gets.split.map(&:to_i);m=a.max;p m*a.size-a.reduce(:+)"}, {"source_code": "gets;a=gets.split.map(&:to_i);p a.max*a.size-a.reduce(:+)"}, {"source_code": "n = gets.to_i\na = []\na = gets.split.map &:to_i\nsum = 0\n(0...n).each do |i|\n sum += a[i]\nend\nputs a.max * n - sum\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\na.sort!\nt = 0\nfor i in 0...n\n\tt += a[-1] - a[i]\nend\nputs t"}, {"source_code": "n = gets.to_i\nas = gets.split.map(&:to_i)\nputs as.map { |a| as.max - a }.inject(:+)"}, {"source_code": "n = gets.strip.to_i\na = gets.strip.split.map(&:to_i).sort\nmax_val = a[n - 1]\nans = 0\nn.times do |i|\n ans += max_val - a[i]\nend\nputs ans\n"}, {"source_code": "gets\nx=gets.split.map{|e| e.to_i}\nm=x.max\nans=0\nx.each{|e|\n\tans+=m-e\n}\nputs ans"}, {"source_code": "t = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\nmx = arr.max\nco = 0\nt.times.each do |i|\n # p [mx,arr[i]]\n co += (mx-arr[i])\nend\nputs co"}, {"source_code": "gets\na=gets.split.map &:to_i\nres=0\na.each{|e| res+=a.max-e}\nputs res\n"}], "negative_code": [{"source_code": "n, *pieces = gets.chomp.split.map(&:to_i)\n\nmax = pieces.max\np pieces.reduce(0) {|acc, n| n < max ? acc + max - n : acc }"}], "src_uid": "a5d3c9ea1c9affb0359d81dae4ecd7c8"} {"source_code": "l=[]\na=0\n$stdin.each{|s|c=s[0..0];c==\"+\"?l<.+)/=~n\n\t\to+=m.size*a\n\tend\n}\np o\n"}, {"source_code": "hash = Hash.new\nbytes = 0\nwhile line = gets\n\tline.chomp!\n\thash.store(line, 0) if line.start_with?('+')\n\tif line.start_with?('-')\n\t\tline[0] = '+'\n\t\thash.delete(line)\n\tend\n\tif line.include?(':')\n\t\tmsg = line.split(':')\n\t\tif msg.size == 1\n\t\t\tlen = 0\n\t\telse\n\t\t\tlen = msg[1].length\n\t\tend\n\t\tbytes += len * hash.size\n\tend\nend\nputs bytes"}, {"source_code": "member=0\nbyte=0\nwhile line = gets\n line.strip!\n if line[0..0]==\"+\"\n member+=1\n elsif line[0..0]==\"-\"\n member-=1\n else\n pos=line.index \":\"\n byte+=(line.size-pos-1)*member\n end\nend\nputs byte\n"}, {"source_code": "a=o=0\n$<.map{|n|\n\ta+=1 if n[0]==?+\n\ta-=1 if n[0]==?-\n\tif /:(?.+)/=~n\n\t\to+=m.size*a\n\tend\n}\np o\n"}, {"source_code": "bytes=0\nnames={}\nwhile line=STDIN.gets do\n\tline=line.chomp\n\tif line[0,1]==\"+\" then names[line[1,line.length-1]]=1\n\telsif line[0,1]==\"-\" then names.delete(line[1,line.length-1])\n\telse\n\t\tname,message=line.split(\":\")\n\t\tif message!=nil then bytes+=message.length*names.length end\n\tend\nend\nprint(bytes,\"\\n\")"}, {"source_code": "l=[]\na=0\n$stdin.each{|s| c=s[0..0];\nc=='+'?l<.+)/=~n\n\n\t\to+=m.size*a\n\n\tend\n\n}\n\np o\n"}, {"source_code": "nl=Hash.new\nsum=0\nwhile line=gets\n line.chomp!\n if line[0] == \"+\"\n nl[line[1..(line.length-1)]]=true\n elsif line[0] == \"-\"\n nl.delete(line[1..(line.length-1)])\n else\n tmp=line.split(\":\")\n if tmp.length!=1\n sum+=tmp[1].length*nl.length\n end\n end\nend\nputs sum\n"}, {"source_code": "a=o=0\n$<.map{|n|\n\ta+=1 if n[0]==?+\n\ta-=1 if n[0]==?-\n\tif /:(?.+)/=~n\n\t\to+=m.size*a\n\tend\n}\np o\n"}, {"source_code": "a=o=0\n$<.map{|n|\n\ta+=1 if n[0]==?+\n\ta-=1 if n[0]==?-\n\tif /:(?.+)/=~n\n\t\to+=m.size*a\n\tend\n}\np o\n"}, {"source_code": "ans=0\nactive=0\n\nwhile a=gets do\na=a.chomp\nif a[0]==\"+\"\nactive+=1\nelsif a[0]==\"-\"\nactive-=1\nelse \nl=a.length-a.index(\":\")-1\nans+=l*active\nend\nend\n\nputs\"#{ans}\""}, {"source_code": "a=o=0\n$<.map{|n|\n a+=1 if n[0]==?+\n a-=1 if n[0]==?-\n if /:(?.+)/=~n\n o+=m.size*a\n end\n}\np o"}, {"source_code": "res = 0\nsankasha=0\nwhile line=gets do\n if line =~ /^\\+/\n sankasha += 1\n elsif line =~ /^\\-/\n sankasha -= 1\n else\n line.chomp =~ /:(.*)\\z/\n res += ($1.size)*sankasha\n end\nend\nputs res\n"}, {"source_code": "l=[]\na=0\n$stdin.each{|s|c=s[0..0];c==\"+\"?l<.+)/=~n\n\t\to+=m.size*a\n\tend\n}\np o\n"}, {"source_code": "#!/usr/bin/env ruby\n\n$users = Array.new\n$bytes_sent = 0\n\ndef handle_input(chat_command)\n\n\tif chat_command.start_with? '+'\n\t\tchat_command.slice!(0)\n\t\t$users << chat_command\n\telsif chat_command.start_with? '-'\n\t\tchat_command.slice!(0)\n\t\t$users.delete chat_command\n\telse\n\t\tmessage = chat_command.split(':')[1].to_s.strip\n\t\t$bytes_sent += $users.count * message.length\n\tend\nend\n\nARGF.each do |line|\n\thandle_input(line)\nend\n\nputs $bytes_sent"}, {"source_code": "num=0\nsum=0\nwhile STDIN.gets != nil ;\n\ts = $_\n\tif s[0] == ?+ ;\n\t\tnum += 1\n\telsif s[0] == ?- ;\n\t\tnum -= 1\n\telse\n\t\t# print s.split(?:)\n\t\tsum += num*(s.split(?:)[1].size-1)\n\t\t# print \"#{num}, #{sum}\\n\"\n\tend\nend\nprint sum"}, {"source_code": "#!/usr/bin/env ruby\ncount = 0\ntraffic = 0\nwhile l = gets\n l.strip!\n case l[0]\n when ?+\n count += 1\n when ?-\n count -= 1\n else\n traffic += count * l.split(':', 2)[1].length\n end\nend\n\nputs traffic"}, {"source_code": "traffic = count = 0\n\nwhile l = gets\n l.strip!\n case l[0]\n when \"+\"\n count += 1\n when \"-\"\n count -= 1\n else\n traffic += count * l.split(':', 2)[1].length\n end\nend\n\nputs traffic\n"}, {"source_code": "require 'set'\nlines = gets(nil)\nuser = Set.new\nans = 0\nlines.split(\"\\n\").each do |line|\n if line[0] == \"+\"\n user.add(line[1,line.size-1])\n elsif line[0] == \"-\"\n user.delete(line[1,line.size-1])\n else\n ans += user.size * line.split(\":\")[1].size if line.split(\":\")[1]\n end\nend\nputs ans\n"}, {"source_code": "cnt = 0\nres = 0\nwhile s = gets do\n next if s.empty?\n s.strip!\n cnt += 1 if s[0, 1] == '+'\n cnt -= 1 if s[0, 1] == '-'\n pos = s.index(':')\n next if pos.nil?\n res += cnt * s[pos + 1, s.length].length\nend\nputs res\n"}, {"source_code": "peoples, traffic = 0, 0\nwhile line = gets do\n case line.strip\n when /\\+\\w+/ then peoples += 1\n when /\\-\\w+/ then peoples -= 1\n when /\\w+:(.+)/ then traffic += peoples * $1.size\n end\nend\nputs traffic"}, {"source_code": "require 'set'\n\nret = 0\npersons = Set.new\nwhile line = gets\n line.chomp!\n if line[0] == '+'\n persons.add(line[1..line.size])\n elsif line[0] == '-'\n persons.delete(line[1..line.size])\n else\n name, text = line.split(\":\")\n if text\n ret += text.size * persons.size\n end\n end\nend\n\nputs ret"}, {"source_code": "a=o=0\n$<.map{|n|\n\ta+=1 if n[0]==?+\n\ta-=1 if n[0]==?-\n\tif /:(?.+)/=~n\n\t\to+=m.size*a\n\tend\n}\np o"}, {"source_code": " \na=o=0\n$<.map{|n|\n\ta+=1 if n[0]==?+\n\ta-=1 if n[0]==?-\n\tif /:(?.+)/=~n\n\t\to+=m.size*a\n\tend\n}\np o"}, {"source_code": "a=o=0\n$<.map{|n|\n\ta+=1 if n[0]==?+\n\ta-=1 if n[0]==?-\n\tif /:(?.+)/=~n\n\t\to+=m.size*a\n\tend\n}\np o\n"}, {"source_code": "peoples, traffic = 0, 0\nwhile line = gets do\n case line.strip\n when /\\+\\w+/ then peoples += 1\n when /\\-\\w+/ then peoples -= 1\n when /\\w+:(.+)/ then traffic += peoples * $1.size\n end\nend\nputs traffic"}, {"source_code": "peoples, traffic = 0, 0\nwhile line = gets do\n case line.strip\n when /\\+\\w+/ then peoples += 1\n when /\\-\\w+/ then peoples -= 1\n when /\\w+:(.+)/ then traffic += peoples * $1.size\n end\nend\nputs traffic\n\n"}, {"source_code": "a=o=0\n$<.map{|n|\n\ta+=1 if n[0]==?+\n\ta-=1 if n[0]==?-\n\tif /:(?.+)/=~n\n\t\to+=m.size*a\n\tend\n}\np o\n"}, {"source_code": "input, names, traffic = STDIN.read.split(\"\\n\"), [], 0\n\ninput.each do |i|\n\tif i[0] == '+'\n\t\tnames.push i[1..-1]\n\telsif i[0] == '-'\n\t\tnames.delete i[1..-1]\n\telse\n\t\tmsg = i.split(':')\n\t\ttraffic += names.length * msg[1].length unless msg[1].nil?\n\tend\nend\n\np traffic"}, {"source_code": "a=o=0\n$<.map{|n|\n\ta+=1 if n[0]==?+\n\ta-=1 if n[0]==?-\n\tif /:(?.+)/=~n\n\t\to+=m.size*a\n\tend\n}\np o\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nh=Hash.new\nn=0\nwhile s=gets do\n s.chomp!\n if s[0,1]==\"+\" then h[s[1,-1]]=true\n elsif s[0,1]==\"-\" then h.delete(s[1,-1])\n else n+=s.split(\":\")[1].length*h.size end\nend\nputs n\n"}, {"source_code": "member=0\nbyte=0\nwhile line = gets\n line.strip!\n if line[0..0]==\"+\"\n member+=1\n elsif line[0..0]==\"-\"\n member-=1\n else\n pos=line.index \":\"\n byte+=line.size-pos-1\n end\nend\nputs byte\n"}, {"source_code": "member=0\nbyte=0\nwhile line = gets\n if line[0..0]==\"+\"\n member+=1\n elsif line[0..0]==\"-\"\n member-=1\n else\n pos=line.index \":\"\n byte+=line.size-pos-1\n end\nend\nputs byte\n"}, {"source_code": "ans=0\nactive=0\n\nwhile a=gets do\n\nif a[0]==\"+\"\nactive+=1\nelsif a[0]==\"-\"\nactive-=1\nelse \nl=a.length-a.index(\":\")-1\nans+=l*active\nend\nend\n\nputs\"#{ans}\""}, {"source_code": "res = 0\nwhile line=gets do\n if line =~ /^\\+/\n elsif line =~ /^\\-/\n else\n res += line.split(':')[1].size\n end\nend\nputs res\n"}, {"source_code": "res = 0\nwhile line=gets do\n if line =~ /^\\+/\n elsif line =~ /^\\-/\n else\n res += line.chomp.split(':')[1].size\n end\nend\nputs res\n"}, {"source_code": "l=[]\na=0\n$stdin.each{|s|s.chomp!;c=s[1..-1];s[0]==\"+\"?l< 0\n arr_3 << a if a == 0\nend\narr_3 << arr_1.shift if arr_1.length.even?\nif arr_2.length == 0 && arr_1.length > 2\n arr_2 << arr_1.delete_at(0)\n arr_2 << arr_1.delete_at(0)\nend\nputs \"#{arr_1.length} #{arr_1.sort.join(\" \")}\"\nputs \"#{arr_2.length} #{arr_2.sort.join(\" \")}\"\nputs \"#{arr_3.length} #{arr_3.sort.join(\" \")}\"\n"}, {"source_code": "def g1(xs)\n\tprint xs.size\n\twhile xs.empty? ==false\n\t\tprint \" \",xs.shift\n\tend\n\tprint \"\\n\"\nend\ndef f()\nn=gets.to_i\nxs=gets.split.map{|e| e.to_i}\nxsU=xs.select{|e|\n\te>0\n}\nxsD=xs.select{|e|\n\te<0\n}\nxs0=xs.select{|e|\n\te==0\n}\nif xsU.size==0 \n\txsU<0\n z< 0}\nc = a.select { |i| i < 0}\nd = a.select { |i| i == 0 }\nif c.size % 2 == 0\n d.push c.pop\nend\nif b.size == 0\n 2.times { b.push c.pop }\nend\n\nputs \"#{c.size} \" + c.join(' ')\nputs \"#{b.size} \" + b.join(' ')\nputs \"#{d.size} \" + d.join(' ')"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\nnum1 = -1\nfor i in 0...n\n if a[i] < 0 \n num1 = i\n break\n end\nend\npositive = Array.new\nfor i in 0...n\n if a[i] > 0\n positive.push(a[i])\n end\nend\nclass2 = Array.new\nif positive.length == 0\n for i in 0...n\n if a[i] < 0 && i != num1\n class2.push(a[i])\n end\n if class2.length == 2\n break\n end\n end\nend\n\nif positive.length != 0\n b = a.reject{|x| x == a[num1] || x == positive[0]}\n print 1,\" \", a[num1]\n puts\n print 1, \" \", positive[0]\n puts\n print (n-2),\" \",b.join(\" \")\nelse\n b = a.reject{|x| x == a[num1] || x == class2[0] || x == class2[1]}\n print 1,\" \", a[num1]\n puts\n print 2,\" \", class2.join(\" \")\n puts\n print (n-3),\" \",b.join(\" \")\nend\n"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |i| i.to_i }.sort\nc = [a.shift]\nb = a[-1] > 0 ? [a.pop()] : a.shift(2)\n[c, b, a].each do |arr| puts \"#{arr.size} \" + arr.join(' ') end"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |i| i.to_i }\nb = a.select { |i| i > 0}\nc = a.select { |i| i < 0}\nd = a.select { |i| i == 0 }\nif c.size % 2 == 0\n d.push c.pop\nend\nif b.size == 0\n 2.times { b.push c.pop }\nend\n[c, b, d].each do |arr|\n puts \"#{arr.size} \" + arr.join(' ') \nend"}, {"source_code": "def pick_minus(a)\n a.delete(a.find {|x| x < 0})\nend\n\ndef pick_plus(a)\n a.delete(a.find {|x| x > 0})\nend\n\ndef str(n)\n if n.is_a?(Array)\n \"#{n.length} #{n.join(\" \")}\\n\"\n else\n \"1 #{n}\\n\"\n end\nend\n\ndef run\n n = $stdin.gets.to_i\n a = $stdin.gets.split.map(&:to_i)\n\n n1 = pick_minus(a)\n unless n2 = pick_plus(a)\n n2 = [pick_minus(a), pick_minus(a)]\n end\n\n puts str(n1) , str(n2) , str(a)\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "gets\na=gets.split.map(&:to_i).sort\n[[a.shift],a.last==0?a.shift(2):[a.pop],a].each{|c|puts\"#{c.size} #{c.join' '}\"}\n"}, {"source_code": "n = gets.to_i\n\narr = gets.split(\" \").map(&:to_i)\n\n\nzero_array = arr.select{|i| i == 0}\nzero_count = zero_array.length\n\npos_array = arr.select{|i| i > 0}\npos_count = pos_array.length\n\nneg_count = n - zero_count - pos_count\n\nneg_array = arr - pos_array - zero_array\n\nif pos_count == 0\n\tpos_array << neg_array.pop\n\tpos_array << neg_array.pop\n\tneg_count -= 2\n\tpos_count += 2\nend\n\nif neg_count.even?\n\tzero_array << neg_array.pop\n\tzero_count += 1\n\tneg_count -= 1\nend\n\nputs \"#{neg_count} #{neg_array.join(' ')}\"\nputs \"#{pos_count} #{pos_array.join(' ')}\"\nputs \"#{zero_count} #{zero_array.join(' ')}\""}, {"source_code": "n = gets \n\na= gets.split.map(&:to_i).sort \nb= [[a.shift]] # there's atleast one negative element \na.last == 0 ? b<< a.shift(2) : b<< [a.pop] # there's no positive so combine two neg \nb<< a \nb.each do |val| \n puts \"#{val.size()} #{val.join(' ')}\" \nend "}, {"source_code": "gets\nl = gets.split.map(&:to_i)\nn = l.find { |x| x < 0 }\nl.delete(n)\np = l.find { |x| x > 0 }\nif !p\n\tt1 = l.find { |x| x < 0 }\n\tl.delete(t1)\n\tt2 = l.find { |x| x < 0 }\n\tl.delete(t2)\n\t\n\tp = \"2 #{t1} #{t2}\"\nelse\n\tl.delete(p)\n\tp = \"1 #{p}\"\nend\nputs \"1 #{ n }\"\nputs \"#{ p }\"\nputs \"#{ l.size } #{ l.join(\" \") }\""}, {"source_code": "# cook your code here\n\ndef solve(arr)\n first = []\n second= []\n third= []\n arr.each do |val| \n if val ==0 \n third.push(0)\n elsif val >0 \n second << val \n else \n first << val \n end \n end \n \n if second.size == 0 \n second<< first.pop\n second << first.pop \n end \n if first.size % 2 ==0 \n third<< first.pop \n end \n return first,second,third \n \nend \n\nn = gets.to_i \na = gets.split(\" \").map(&:to_i)\nans = solve(a)\nprint \"#{ans[0].size} \" \nans[0].each do |val| \n print \"#{val} \"\nend \nputs \nprint \"#{ans[1].size} \" \nans[1].each do |val| \n print \"#{val} \"\nend \nputs \nprint\"#{ans[2].size} \" \nans[2].each do |val| \n print \"#{val} \"\nend \n\n\n\n"}, {"source_code": "gets\na=gets.split.map(&:to_i).sort\nb=[[a.shift]]\na.last==0?b< 0 }\nzeros = [0]\nif pos.empty?\n pos.concat(neg[-2..-1])\n neg = neg[0..-3]\nend\nfirst_neg, *rest_neg = *neg\n(neg.size.even? ? zeros : pos).concat(rest_neg) unless rest_neg.first.nil?\nputs \"1 #{first_neg}\"\nputs \"#{pos.size} #{pos.join(' ')}\"\nputs \"#{zeros.size} #{zeros.join(' ')}\""}, {"source_code": "n = gets[0..-2].to_i\narr = gets[0..-2].split(' ')\na = Array.new(arr.size) { |index| arr[index].to_i }\na.sort!\nputs \"1 #{a[0]}\"\nnPositive = a.count { |obj| obj > 0 }\nif nPositive == 0#There is no positive numbers\n puts \"2 #{a[1]} #{a[2]}\"\n print \"#{n - 3} \"\n 3.upto(n - 1) { |i| print \"#{a[i]} \" }\nelse #There is atleast one positive numbers\n puts \"1 #{a[n-1]}\"\n print \"#{n - 2} \"\n 1.upto(n - 2) { |i| print \"#{a[i]} \" }\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\nx = gets.split.collect{|i| i.to_i}\na, b, c = [], [], []\nx.each do |i|\n\tif i < 0 && a.size == 0\n\t\ta << i\n\telsif i > 0 && b.size == 0\n\t\tb << i\n\telse\n\t\tc << i\n\tend\nend\n\nif b.size == 0\n\t2.times do\n\t\tc.each do |i|\n\t\t\tif b.size < 2 && i < 0\n\t\t\t\tb << i\n\t\t\t\tc.delete(i)\n\t\t\t\tbreak\n\t\t\tend\n\t\tend\n\tend\nend\n\nputs \"#{a.size} #{a.join(\" \")}\"\nputs \"#{b.size} #{b.join(\" \")}\"\nputs \"#{c.size} #{c.join(\" \")}\"\n"}, {"source_code": "gets\na=gets.split.map(&:to_i).sort\n[[a.shift],a.last==0?a.shift(2):[a.pop],a].each{|c|puts\"#{c.size} #{c.join' '}\"}\n"}, {"source_code": "gets\na=gets.split.map(&:to_i).sort\n[[a.shift],a.last==0?a.shift(2):[a.pop],a].each{|c|puts\"#{c.size} #{c.join' '}\"}\n"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = []\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n\n list.each do |num|\n if num < 0\n m_list << num\n elsif num > 0\n p_list << num\n else\n zero_list << num\n end\n end\n m_count = list.count{|n| n < 0}\n p_count = list.count{|n| n > 0}\n z_count = list.count{|n| n == 0}\n\n if m_count > 2 \n if(m_count.odd?)\n list1 << m_list.pop\n list2 += m_list\n else\n list1 << m_list.pop\n list2 << m_list.pop\n list2 << m_list.pop\n list3 += m_list\n end\n m_list = []\n else \n list1 << m_list.pop\n list3 += m_list\n end\n \n\n list2 += p_list\n list3 += [0]*z_count\n\n puts \"#{list1.size} \" + list1.join(' ')\n puts \"#{list2.size} \" + list2.join(' ')\n puts \"#{list3.size} \" + list3.join(' ')\n end\nend\n\na = A.new"}], "negative_code": [{"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = [1]\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n \n list.each do |num|\n if num < 0\n m_list << num\n elsif num > 0\n p_list << num\n else\n zero_list << num\n end\n end\n m_count = list.count{|n| n < 0}\n\n m_c = (m_count/2.0).ceil\n if m_c.even?\n list1 << -1\n else\n list1 << 1\n end\n\n \n if (m_count-m_c).even?\n list2 << 1\n else\n list2 << -1\n end\n\n m_c.times do \n list1 << m_list.pop\n end\n\n list2 += m_list + p_list\n list3 += zero_list\n\n puts list1.join(' ')\n puts list2.join(' ')\n puts list3.join(' ')\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = []\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n \n 0.upto(n-2) do |i|\n 1.upto(n-1) do |j|\n list1 = list[0..i]\n list2 = list[i+1..j]\n list3 = list[j+1..n-1]\n\n if list1.inject(:*) < 0 && list2.inject(:*) > 0 && list3.include?(0)\n puts \"#{list1.size} \" + list1.join(' ')\n puts \"#{list2.size} \" + list2.join(' ')\n puts \"#{list3.size} \" + list3.join(' ')\n exit\n end\n end\n end\n \n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = [1]\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n \n 0.upto(97) do |i|\n 1.upto(98) do |j|\n list1 = list[0..i]\n list2 = list[i+1..j]\n list3 = list[j+1..n-1]\n\n if list1.inject(:*) < 0 && list2.inject(:*) > 0 && list3.include?(0)\n puts \"#{list1.max.abs} \" + list1.join(' ')\n puts \"#{list2.max.abs} \" + list2.join(' ')\n puts \"#{[list3.max.abs,1].max} \" + list3.join(' ')\n exit\n end\n end\n end\n \n end\nend\n\na = A.new\n"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = [1]\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n \n 0.upto(97) do |i|\n 1.upto(98) do |j|\n list1 = list[0..i]\n list2 = list[i+1..j]\n list3 = list[j+1..n-1]\n\n if list1.inject(:*) < 0 && list2.inject(:*) > 0 && list3.include?(0)\n puts list1.join(' ')\n puts list2.join(' ')\n puts list3.join(' ')\n exit\n end\n end\n end\n \n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = []\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n \n list.each do |num|\n if num < 0\n m_list << num\n elsif num > 0\n p_list << num\n else\n zero_list << num\n end\n end\n m_count = list.count{|n| n < 0}\n p_count = list.count{|n| n > 0}\n z_count = list.count{|n| n == 0}\n\n if p_count == 0\n list2 << m_list.pop\n list2 << m_list.pop\n list1 += m_list\n else\n list1 << m_list.pop\n list2 += m_list\n end\n\n list2 += p_list\n list3 += [0]*z_count + m_list\n\n puts \"#{list1.size} \" + list1.join(' ')\n puts \"#{list2.size} \" + list2.join(' ')\n puts \"#{list3.size} \" + list3.join(' ')\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = []\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n\n list.each do |num|\n if num < 0\n m_list << num\n elsif num > 0\n p_list << num\n else\n zero_list << num\n end\n end\n m_count = list.count{|n| n < 0}\n p_count = list.count{|n| n > 0}\n z_count = list.count{|n| n == 0}\n\n if m_count > 2 \n if(m_count.odd?)\n list2 << m_list.pop\n list2 << m_list.pop\n list1 += m_list\n else\n list1 << m_list.pop\n list2 += m_list\n end\n m_list = []\n else \n list1 << m_list.pop\n end\n \n\n list2 += p_list\n list3 += [0]*z_count + m_list\n\n puts \"#{list1.size} \" + list1.join(' ')\n puts \"#{list2.size} \" + list2.join(' ')\n puts \"#{list3.size} \" + list3.join(' ')\n end\nend\n\na = A.new"}, {"source_code": "gets.chomp.to_i\narrs = gets.chomp.split(/ /).map(&:to_i)\narr_1 = []\narr_2 = []\narr_3 = []\narrs.each do |a|\n arr_1 << a if a < 0\n arr_2 << a if a > 0\n arr_3 << a if a == 0\nend\narr_2 << arr_1.shift if arr_1.length.even?\nif arr_2.length == 0 && arr_1.length > 2\n arr_2 << arr_1.delete_at(0)\n arr_2 << arr_1.delete_at(0)\nend\nputs \"#{arr_1.length} #{arr_1.sort.join(\" \")}\"\nputs \"#{arr_2.length} #{arr_2.sort.join(\" \")}\"\nputs \"#{arr_3.length} #{arr_3.sort.join(\" \")}\"\n"}, {"source_code": "def g1(xs)\n\tprint xs.size\n\twhile xs.empty? ==false\n\t\tprint \" \",xs.shift\n\tend\n\tprint \"\\n\"\nend\ndef f()\nn=gets.to_i\nxs=gets.split.map{|e| e.to_i}\nxsU=xs.select{|e|\n\te>0\n}\nxsD=xs.select{|e|\n\te<0\n}\nxs0=xs.select{|e|\n\te==0\n}\nif xsU.size==0 \n\txsU<0 && n3==0 then\n\t\t\tg1(xs1)\n\t\t\tg1(xs2)\n\t\t\tg1(xs3)\n\t\t\treturn \n\t\tend\n\t}\n}\nend\nf()"}, {"source_code": "n = Integer(gets)\ninput = gets.chomp\nnums = input.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(nums[i])\nend\nnum1 = -1\nfor i in 0...n\n if a[i] < 0 \n num1 = i\n break\n end\nend\npositive = Array.new\nfor i in 0...n\n if a[i] > 0\n positive.push(a[i])\n end\nend\nclass2 = Array.new\nif positive.length == 0\n for i in 0...n\n if a[i] < 0 && i != num1\n class2.push(a[i])\n end\n if class2.length == 2\n break\n end\n end\nend\n\nif positive.length != 0\n b = a.reject{|x| x == a[num1] || x == positive[0]}\n print 1,\" \", a[num1]\n puts\n print 1, \" \", positive[0]\n puts\n print (n-2),\" \",b.join(\" \")\nelse\n b = a.reject{|x| x == a[num1] || x == class2[0] || x == class2[1]}\n print 1,\" \", a[num1]\n puts\n print 1,\" \", class2.join(\" \")\n puts\n print (n-3),\" \",b.join(\" \")\nend\n"}, {"source_code": "gets\na=gets.split.map(&:to_i)\nputs \"1 #{a.min}\",\"1 #{a.max}\",\"#{a.size-2} #{(a-[a.min,a.max]).join' '}\""}, {"source_code": "gets.chomp # Skip the first line\nseq = gets.chomp.split.map { |x| x.to_i }\nneg = seq.select { |x| x < 0 }\npos = seq.select { |x| x > 0 }\nzeros = [0]\nfirst_neg, *rest_neg = *neg\n(neg.size.even? ? zeros : pos) << rest_neg\nputs \"1 #{first_neg}\"\nputs \"#{pos.size} #{pos.join(' ')}\"\nputs \"#{zeros.size} #{zeros.join(' ')}\""}, {"source_code": "gets.chomp # Skip the first line\nseq = gets.chomp.split.map { |x| x.to_i }\nfirst_neg = seq.find { |x| x < 0 }\npos = seq.select { |x| x > 0 || (x < 0 && x != first_neg) }\nputs \"1 #{first_neg}\"\nputs \"#{pos.size} #{pos.join(' ')}\"\nputs '1 0'"}, {"source_code": "gets.chomp # Skip the first line\nseq = gets.chomp.split.map { |x| x.to_i }\nneg = seq.select { |x| x < 0 }\npos = seq.select { |x| x > 0 }\nzeros = [0]\nfirst_neg, *rest_neg = *neg\n(neg.size.even? ? zeros : pos).concat(rest_neg) unless rest_neg.first.nil?\nputs \"1 #{first_neg}\"\nputs \"#{pos.size} #{pos.join(' ')}\"\nputs \"#{zeros.size} #{zeros.join(' ')}\""}, {"source_code": "n = gets[0..-2].to_i\narr = gets[0..-2].split(' ')\na = Array.new(arr.size) { |index| arr[index].to_i }\na.sort!\nputs \"1 #{a[0]}\"\nnPositive = a.count { |obj| obj > 0 }\nif nPositive == 0#There is no positive numbers\n puts \"2 #{a[1]} #{a[2]}\"\n print \"#{n - 3} \"\n 3.upto(n - 1) { |i| print \"#{a[i] }\" }\nelse #There is atleast one positive numbers\n puts \"1 #{a[n-1]}\"\n print \"#{n - 2} \"\n 1.upto(n - 2) { |i| print \"#{a[i]} \" }\nend\n"}, {"source_code": "n = gets[0..-2].to_i\narr = gets[0..-2].split(' ')\na = Array.new(arr.size) { |index| arr[index].to_i }\na.sort!\nputs(\"1 \" + a[0].to_s)\nprint n - 2\n1.upto(n - 2) { |i| print \" \", a[i]}\nputs\nprint 1, \" \", a[-1]"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |i| i.to_i }\nfor i in 1...n-1\n for j in i+1...n\n array = [a[0, i], a[i, j - 1], a[j, n - j]]\n m1 = a[0, i].inject { |val, temp| val *= temp}\n m2 = a[i, j - i].inject { |val, temp| val *= temp}\n m3 = a[j, n - j].inject { |val, temp| val *= temp}\n if m1 < 0 && m2 > 0 && m3 == 0\n puts \"#{array[0].size} \" + array[0].join(' ')\n puts \"#{array[1].size} \" + array[1].join(' ')\n puts \"#{array[2].size} \" + array[2].join(' ')\n end\n end\nend"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |i| i.to_i }.sort\nc = [a.shift]\nb = a[-1] > 0 ? [a.pop()] : [a.shift(2)]\n[c, b, a].each do |a| puts \"#{a.size} \" + a.join(' ') end"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map { |i| i.to_i }.sort\nc = [a.shift]\nb = a[-1] > 0 ? [a.pop()] : [a.shift(2)]\n[c, b, a].each do |arr| puts \"#{arr.size} \" + arr.join(' ') end"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = []\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n\n list.each do |num|\n if num < 0\n m_list << num\n elsif num > 0\n p_list << num\n else\n zero_list << num\n end\n end\n m_count = list.count{|n| n < 0}\n p_count = list.count{|n| n > 0}\n z_count = list.count{|n| n == 0}\n\n if m_count > 2 \n if(m_count.odd?)\n list1 << m_list.pop\n list2 += m_list\n else\n list1 << m_list.pop\n list2 << m_list.pop\n list2 << m_list.pop\n end\n m_list = []\n else \n list1 << m_list.pop\n end\n \n\n list2 += p_list\n list3 += [0]*z_count + m_list\n\n puts \"#{list1.size} \" + list1.join(' ')\n puts \"#{list2.size} \" + list2.join(' ')\n puts \"#{list3.size} \" + list3.join(' ')\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = []\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n\n list.each do |num|\n if num < 0\n m_list << num\n elsif num > 0\n p_list << num\n else\n zero_list << num\n end\n end\n m_count = list.count{|n| n < 0}\n p_count = list.count{|n| n > 0}\n z_count = list.count{|n| n == 0}\n\n if m_count > 2 \n if(m_count.odd?)\n list1 << m_list.pop\n list2 += m_list\n else\n list1 << m_list.pop\n list1 << m_list.pop\n list2 += m_list\n end\n m_list = []\n else \n list1 << m_list.pop\n end\n \n\n list2 += p_list\n list3 += [0]*z_count + m_list\n\n puts \"#{list1.size} \" + list1.join(' ')\n puts \"#{list2.size} \" + list2.join(' ')\n puts \"#{list3.size} \" + list3.join(' ')\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = [1]\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n \n 0.upto(97) do |i|\n 1.upto(98) do |j|\n list1 = list[0..i]\n list2 = list[i+1..j]\n list3 = list[j+1..n-1]\n\n if list1.inject(:*) < 0 && list2.inject(:*) > 0 && list3.include?(0)\n puts \"1 \" + list1.join(' ')\n puts \"1 \" + list2.join(' ')\n puts \"1 \" + list3.join(' ')\n exit\n end\n end\n end\n \n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = [1]\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n \n 0.upto(97) do |i|\n 1.upto(98) do |j|\n list1 = list[0..i]\n list2 = list[i+1..j]\n list3 = list[j+1..n-1]\n\n if list1.inject(:*) < 0 && list2.inject(:*) > 0 && list3.include?(0)\n puts \"#{list1.size} \" + list1.join(' ')\n puts \"#{list2.size} \" + list2.join(' ')\n puts \"#{list3.size} \" + list3.join(' ')\n exit\n end\n end\n end\n \n end\nend\n\na = A.new\n"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = []\n\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n z_c = list.count(0)\n list.delete(0)\n list.sort!\n\n list += [0]*z_c\n \n 0.upto(n-3) do |i|\n 1.upto(n-2) do |j|\n list1 = list[0..i]\n list2 = list[i+1..j]\n list3 = list[j+1..n-1]\n\n if list1.inject(:*) < 0 && list2.inject(:*) > 0 && list3.include?(0)\n puts \"#{list1.size} \" + list1.join(' ')\n puts \"#{list2.size} \" + list2.join(' ')\n puts \"#{list3.size} \" + list3.join(' ')\n exit\n end\n end\n end\n \n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = []\n\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n z_c = list.count(0)\n list.delete(0)\n list.sort!\n\n list += [0]*z_c\n \n 0.upto(n-2) do |i|\n 1.upto(n-1) do |j|\n list1 = list[0..i]\n list2 = list[i+1..j]\n list3 = list[j+1..n-1]\n\n if list1.inject(:*) < 0 && list2.inject(:*) > 0 && list3.include?(0)\n puts \"#{list1.size} \" + list1.join(' ')\n puts \"#{list2.size} \" + list2.join(' ')\n puts \"#{list3.size} \" + list3.join(' ')\n exit\n end\n end\n end\n \n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = []\n zero_list = []\n m_list = []\n p_list = []\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n\n list.each do |num|\n if num < 0\n m_list << num\n elsif num > 0\n p_list << num\n else\n zero_list << num\n end\n end\n m_count = list.count{|n| n < 0}\n p_count = list.count{|n| n > 0}\n z_count = list.count{|n| n == 0}\n\n if m_count > 2 \n if(m_count.odd?)\n list2 << m_list.pop\n list2 << m_list.pop\n list1 += m_list\n else\n list1 << m_list.pop\n list2 += m_list\n end\n else \n list1 << m_list.pop\n end\n \n\n list2 += p_list\n list3 += [0]*z_count + m_list\n\n puts \"#{list1.size} \" + list1.join(' ')\n puts \"#{list2.size} \" + list2.join(' ')\n puts \"#{list3.size} \" + list3.join(' ')\n end\nend\n\na = A.new"}, {"source_code": "class A\n def initialize\n list1 = []\n list2 = []\n list3 = []\n\n n = gets.chomp.to_i\n\n list = gets.chomp.split(' ').map(&:to_i)\n\n list.sort!\n \n 0.upto(n-2) do |i|\n 1.upto(n-1) do |j|\n list1 = list[0..i]\n list2 = list[i+1..j]\n list3 = list[j+1..n-1]\n\n if list1.inject(:*) < 0 && list2.inject(:*) > 0 && list3.include?(0)\n puts \"#{list1.size} \" + list1.join(' ')\n puts \"#{list2.size} \" + list2.join(' ')\n puts \"#{list3.size} \" + list3.join(' ')\n exit\n end\n end\n end\n \n end\nend\n\na = A.new"}], "src_uid": "03cf2cc26c84aab685ee78a1d6318b30"} {"source_code": "N = gets.to_i\nas = gets.split.map(&:to_i)\n\nlhash = {}\nrhash = Hash.new(0)\n\nN.times do |i|\n rhash[as[i]] += 1\nend\nrsum = rhash.keys.length\n\nans = 0\nN.times do |i|\n rhash[as[i]] -= 1\n rsum -= 1 if rhash[as[i]] == 0\n next if lhash[as[i]]\n lhash[as[i]] = true\n ans += rsum\nend\nputs ans", "positive_code": [{"source_code": "require 'set'\n\nn = STDIN.readline.strip.to_i\nnumbers = STDIN.readline.strip.split(/\\s+/).map(&:to_i)\n\n# robot 2\nn_rev = numbers.reverse\nr2_seen = Set.new\nn_seen = 0\nseen_map = {}\nseen_map[n] = 0\nn_rev.each_with_index do |x2, i|\n if !r2_seen.include? x2\n r2_seen << x2\n n_seen += 1\n end\n seen_map[n - i - 1] = n_seen\nend\n\n# robot 1\ncount = 0\nseen = Set.new\nnumbers.each_with_index do |x1, i|\n if !seen.include?(x1)\n count += seen_map[i + 1]\n seen << x1\n end\nend\n\nputs count\n"}, {"source_code": "require 'set'\n\ndef input \n\tgets.chomp.split.map(&:to_i)\nend\n\nn = input[0]\na = input\n\ns = Set.new\nns = 0\ns_map = {}\ns_map[n] = 0\na.reverse.each_with_index do |x, i| \n\tunless s.include?(x)\n\t\ts << x\n\t\tns += 1\n\tend\n\ts_map[n-i-1] = ns\nend\n\n# p s_map\ns = Set.new\nac = 0\na.each_with_index do |x, i|\n\tunless s.include?(x)\n\t\ts << x\n\t\tac += s_map[i+1]\n\tend\nend\n\nprint ac"}], "negative_code": [{"source_code": "def input \n\tgets.chomp.split.map(&:to_i)\nend\n\nn = input[0]\na = input\n\nstore = {}\nnext_round = 0\nac = 0\na << -1 if a[-1] == a[-2]\na.each_with_index do |x, i|\n\t\n\tac += next_round\n\t# puts \"#{x}, #{next_round}, #{store[x]}\"\n\tif store[x]\n\t\tnext_round = -1 * store[x]\n\t\tstore[x] = i\n\telse\n\t\tnext_round = n - i - 1\n\t\tstore[x] = i\n\tend\n\t# p ac\nend\n\nprint ac"}, {"source_code": "def input \n\tgets.chomp.split.map(&:to_i)\nend\n\nn = input[0]\na = input\n\nstore = {}\nnext_round = 0\nac = 0\na.each_with_index do |x, i|\n\t\n\tac += next_round\n\t# puts \"#{x}, #{next_round}, #{store[x]}\"\n\tif store[x]\n\t\tnext_round = -1 * store[x]\n\t\tstore[x] = i\n\telse\n\t\tnext_round = n - i - 1\n\t\tstore[x] = i\n\tend\n\t# p ac\nend\n\nprint ac"}], "src_uid": "4671380d70876044e0ec7a9cab5e25ae"} {"source_code": "def time_spent_on_tree(pre_height, height, nxt_height)\n (height - pre_height) + (height - nxt_height) + 1#cost of eating nuts\nend\n\nn = gets.to_i\n\ntree_heights = [0]\nn.times do\n tree_heights << gets.to_i\nend\n\ntotal_time = 0\n\n(1 .. tree_heights.length - 2).each do |i|\n height = tree_heights[i]\n pre_height = [tree_heights[i - 1], height].min\n nxt_height = [height, tree_heights[i + 1]].min\n\n total_time += time_spent_on_tree pre_height, height, nxt_height\n total_time += 1 #cost of jumping between trees\nend\nlast_tree_height = tree_heights[-1]\ntotal_time += time_spent_on_tree tree_heights[-2 .. -1].min, last_tree_height, last_tree_height\n\nputs total_time\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\n\nn, x, tot = gets.to_i, [], 0\nn.times { x << gets.to_i }\nx.each_index { |i| tot = tot + (x[i] - x[i+1]).abs if i + 1 < n }\nputs tot + n + n - 1 + x[0]\n"}, {"source_code": "BEGIN{\n\tdef gint()\n\t\treturn gets.split.map(&:to_i)\n\tend\n\tdef main()\n\t\tn = gint[0]\n\t\ta = []\n\t\tn.times do |i|\n\t\t\ta << gint[0]\n\t\tend\n\t\tans = n + a[0]\n\t\ta.each_with_index do |item, i|\n\t\t\tbreak if i == a.length - 1\n\t\t\tif item > a[i + 1] then\n\t\t\t\tans += item - a[i + 1] + 1\n\t\t\telsif\n\t\t\t\tans += 1 + a[i + 1] - item\n\t\t\tend\n\t\tend\n\t\tputs ans\n\tend\n\tTest_case = 1\n\tTest_case.times do\n\t\tmain()\n\tend\n}\n"}, {"source_code": "n = gets.to_i\nr = 0\nh = 0\n\n\n\nfirst = true\n\nn.times do |i|\n\tif not first\n\t\tr += 1\n\tend\n\tfirst = false\n\tt = gets.to_i\n\tr += (t-h).abs + 1\n\th = t\nend\t\n\nputs r"}, {"source_code": "n = gets.to_i\nprev = gets.to_i\nres = prev\nfor i in 0...n-1\n\tcurr = gets.to_i\n\tres += (prev-curr).abs\n\tres += 2\n\tprev = curr\nend\nputs (res+1).to_s\n"}, {"source_code": "t,ans=0,-1\ngets.to_i.times do\n\ta=gets.to_i\n\tans+=(a - t).abs+2\n\tt=a\nend\nputs ans\n"}, {"source_code": "EAT = 1; JUMP = 1\n\ndef run\n n = ARGF.readline.to_i\n trees = ARGF.readlines.map(&:to_i)\n\n sec = 0\n height = 0\n cur_tree = 0\n\n trees.length.times do |i|\n if i > 0\n sec += JUMP\n\n diff = trees[i] - trees[i - 1]\n if diff < 0\n sec += -diff\n height = trees[i]\n end\n end\n\n sec += trees[i] - height + EAT\n height = trees[i]\n end\n\n puts sec\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n,ac = gets.to_i,0\ntot = 2*n-1\nfor i in (0...n)\n t = gets.to_i\n tot+=(t-ac).abs\n ac = t\nend\nputs tot"}, {"source_code": "n=gets.to_i-1\nl=r=gets.to_i\nn.times{\n t=gets.to_i\n r+=(l-t).abs+2\n l=t\n}\nputs r+1"}, {"source_code": "n=gets.to_i\nh = []\nn.times do |i|\n\th[i] = gets.to_i\nend\n\nt = h[0] + n\n\n(n-1).times do |i|\n\tif h[i+1] > h[i]\n\t\tt += h[i+1] - h[i] + 1\n\telse\n\t\tt += h[i] - h[i+1] + 1\n\tend\nend\n\nputs t\n"}, {"source_code": "n = gets.chomp.to_i\nh1,s = 0,n\nfor i in 0...n\n h2 = gets.chomp.to_i\n s+=(h2-h1).abs\n h1=h2\nend\ns+=n-1\nputs s"}, {"source_code": "n = gets.to_i\narr = []\nn.times do\n\tarr << gets.to_i\nend\ntime = arr[0]\nprev_height = arr[0]\ntime += 1 # To eat\n(1..n-1).each do |i|\n\tif arr[i] < prev_height\n\t\t#puts \"He gets down to #{arr[i]}\"#\n\t\ttime += prev_height - arr[i]\n\t\t#puts \"He jumps\"\n\t\ttime += 1\n\telse\n\n\t\t#puts \"He jumps\"\n\t\ttime += 1 # Time to jump\n\t\t#puts \"He Climbs to top in #{arr[i] - prev_height}\"\n\t\ttime += arr[i] - prev_height\n\tend\n\t#puts \"He eats\"\n\ttime += 1\n\n\t#puts \"Current time #{time}\"\n\tprev_height = arr[i]\nend\n\nputs time"}, {"source_code": "n = gets.chomp.to_i\na = 0\np = 0\n(1..n).each { |k|\n\tb = gets.chomp.to_i\n\tp += (b-a).abs\n\ta = b\n}\n\nputs (p+2*n-1)"}, {"source_code": "n=gets.to_i\n\nsum=gets.to_i\nlast=sum\n\n(n-1).times{\n t=gets.to_i\n sum+=2+(last-t).abs\n last=t\n}\n\nputs sum+1"}], "negative_code": [{"source_code": "n = gets.to_i\narr = []\nn.times do\n\tarr << gets.to_i\nend\ntime = arr[0]\nprev_height = arr[0]\ntime += 1 # To eat\n(1..n-1).each do |i|\n\tif arr[i] < prev_height\n\t\ttime += prev_height\n\t\ttime += arr[i]\n\telse\n\t\ttime += arr[i] - prev_height\n\t\ttime += 1 # Time to jump\n\tend\n\ttime += 1\n\tprev_height = arr[i]\nend\n\nputs time"}], "src_uid": "a20ca4b053ba71f6b2dc05749287e0a4"} {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\n\nmatches = (n * (n - 1)/2).to_i\nmatrix = []\nn.times { |i| matrix[i] = [] }\n\nt = {}\nn.times do |i|\n team = gets.strip\n matrix[i] = [0, 0, 0, team]\n t[team] = i\nend\n\nget_score = lambda do |goal1, goal2|\n if goal1 > goal2\n [3, 0]\n elsif goal1 < goal2\n [0, 3]\n else\n [1, 1]\n end\nend\n\nmatches.times do\n result = gets\n ts, res = result.split\n \n team1, team2 = ts.split('-')\n goal1, goal2 = res.split(':').map { |v| v.to_i }\n score1, score2 = get_score.call(goal1, goal2)\n\n # by score\n matrix[t[team1]][0] += score1\n matrix[t[team2]][0] += score2\n\n # by diff\n matrix[t[team1]][1] += goal1 - goal2\n matrix[t[team2]][1] += goal2 - goal1\n\n # by goals\n matrix[t[team1]][2] += goal1\n matrix[t[team2]][2] += goal2\nend\n\nmatrix = matrix.sort_by { |team| [ team[0], team[1], team[2] ] }\n\nputs (n/2 .. n-1).inject([]) { |res, i| res << matrix[i][-1] }.sort\n", "positive_code": [{"source_code": "class Team\n\tdef initialize(nm)\n\t\t@name = nm\n\t\t@point = 0\n\t\t@scored = 0\n\t\t@missed = 0\n\tend\n\tattr_accessor :name, :point, :scored, :missed\nend\n\nn = gets.chomp.to_i\nh = Hash.new(n)\nfor i in 0..n-1\n\ts = gets.chomp\n\th[s] = Team.new(s)\nend\n\nfor i in 0..n*(n-1)/2-1\n\ta = gets.chomp.split(/ /)\n\tteams = a[0].split(/\\-/)\n\tscore = a[1].split(/\\:/).map!{|x| x.to_i}\n\th[teams[0]].scored += score[0]\n\th[teams[0]].missed += score[1]\n\th[teams[1]].scored += score[1]\n\th[teams[1]].missed += score[0]\n\tif score[0] == score[1]\n\t\th[teams[0]].point += 1\n\t\th[teams[1]].point += 1\n\telsif score[0] > score[1]\n\t\th[teams[0]].point += 3\n\telse\n\t\th[teams[1]].point += 3\n\tend\nend\n\nqu = h.values.sort!{|a,b|\n\tif a.point == b.point\n\t\tif (a.scored - a.missed) == (b.scored-b.missed)\n\t\t\tb.scored <=> a.scored\n\t\telse\n\t\t\t(b.scored - b.missed) <=> (a.scored-a.missed)\n\t\tend\n\telse\n\t\tb.point <=> a.point\n\tend\n}\n\nqu = qu.slice(0..n/2-1)\nqu.sort!{|a,b| a.name <=> b.name}\n\t\nfor i in 0..n/2-1\n\tputs qu[i].name\nend\n"}, {"source_code": "h=Hash.new\n(n=gets.to_i).times{|i|\n h[s=gets.chomp]=[0,0,0,s]\n}\n(n*(n-1)/2).times{|i|\n gets=~/(\\w+)-(\\w+) (\\d+):(\\d+)/\n _3=$3.to_i;_4=$4.to_i;\n if _3>_4 then h[$1][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_4-_3;h[$1][2]+=_3;h[$2][2]+=_4 end\n if _3<_4 then h[$2][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_4-_3;h[$1][2]+=_3;h[$2][2]+=_4 end\n if _3==_4 then h[$1][0]+=1;h[$2][0]+=1;h[$1][2]+=_3;h[$2][2]+=_4 end\n}\na=Array.new\nh.values.sort[n/2,n/2].each{|i|\n a.push i[3]\n}\na.sort.each{|s|puts s}\n"}, {"source_code": "h={}\n(n=gets.to_i).times{|i|\n h[s=gets.chomp]=[0,0,0,s]\n}\n(n*(n-1)/2).times{|i|\n gets=~/(\\w+)-(\\w+) (\\d+):(\\d+)/\n _3=$3.to_i;_4=$4.to_i;\n if _3>_4 then h[$1][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_4-_3;h[$1][2]+=_3;h[$2][2]+=_4 end\n if _3<_4 then h[$2][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_4-_3;h[$1][2]+=_3;h[$2][2]+=_4 end\n if _3==_4 then h[$1][0]+=1;h[$2][0]+=1;h[$1][2]+=_3;h[$2][2]+=_4 end\n}\na=[]\nh.values.sort[n/2,n/2].each{|i|\n a<_4 then h[$1][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_4-_3;h[$1][2]+=_3;h[$2][2]+=_4 end\n if _3<_4 then h[$2][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_4-_3;h[$1][2]+=_3;h[$2][2]+=_4 end\n if _3==_4 then h[$1][0]+=1;h[$2][0]+=1;h[$1][2]+=_3;h[$2][2]+=_4 end\n}\nputs h.values.sort[n/2,n/2].map{|i|i[3]}.sort"}, {"source_code": "n = gets.to_i\nh = {}\nn.times do\n\th[gets.chomp] = [0, 0, 0]\nend\n(n * (n - 1) / 2).times do\n\ta, b, c, d = gets.split(/[ :-]/)\n\tc = c.to_i\n\td = d.to_i\n\tif c < d\n\t\ta, b, c, d = b, a, d, c\n\tend\n\tif c == d\n\t\th[a][0] += 1\n\t\th[b][0] += 1\n\telse\n\t\th[a][0] += 3\n\tend\n\th[a][1] += c - d\n\th[a][2] += c\n\th[b][1] += d - c\n\th[b][2] += d\nend\nputs h.sort{|a, b| b[1] <=> a[1]}.map{|_| _[0]}[0, n / 2].sort\n"}, {"source_code": "n=gets.to_i;h={};n.times{h[gets.chomp]=[0,0,0];}\n(n*(n-1)/2).times{\n\ts=gets.split /[ :-]/;a,b,c,d=*s;\n\tc,d=c.to_i,d.to_i;a,b,c,d=b,a,d,c if cx[1]}.map{|o|o[0]}[0,n/2].sort\n"}, {"source_code": "n=gets.to_i;h={};n.times{h[gets.chomp]=[0,0,0];}\n(n*(n-1)/2).times{\n\ts=gets.split /[ :-]/;a,b,c,d=*s;\n\tc,d=c.to_i,d.to_i;a,b,c,d=b,a,d,c if cx[1]}.map{|o|o[0]}[0,n/2].sort\n"}, {"source_code": "n=gets.to_i;h={};n.times{h[gets.chomp]=[0,0,0];}\n(n*(n-1)/2).times{\n\ts=gets.split /[ :-]/;a,b,c,d=*s;\n\tc,d=c.to_i,d.to_i;a,b,c,d=b,a,d,c if cx[1]}.map{|o|o[0]}[0,n/2].sort"}, {"source_code": "n=gets.to_i;h={};n.times{h[gets.chomp]=[0,0,0];}\n(n*(n-1)/2).times{\n\ts=gets.split /[ :-]/;a,b,c,d=*s;\n\tc,d=c.to_i,d.to_i;a,b,c,d=b,a,d,c if cx[1]}.map{|o|o[0]}[0,n/2].sort\n"}, {"source_code": "class SoccerData\n attr_accessor :win\n attr_accessor :lose\n attr_accessor :point\n attr_accessor :name\n def initialize(name)\n @name=name\n @win=0\n @lose=0\n @point=0\n end\n include Comparable\n def <=>(other)\n if @point!=other.point\n return other.point-@point\n elsif (@win-@lose)!=(other.win-other.lose)\n return (other.win-other.lose)-(@win-@lose)\n elsif (@win!=other.win)\n return other.win-@win\n else\n return @name<=>other.name\n end\n end \nend\nn=gets.chomp!.to_i\ndata=Array.new(n)\nt=SoccerData.new(\"test\")\nmemo=Hash.new\nn.times do |i|\n name=gets.chomp!\n data[i]=SoccerData.new(name)\n memo[name]=data[i]\nend\n(n*(n-1)/2).times do\n tmp1=gets.chomp!.split(\" \")\n tmp2=tmp1[0].split(\"-\")\n d1=memo[tmp2[0]]\n d2=memo[tmp2[1]]\n tmp2=tmp1[1].split(\":\")\n w1=tmp2[0].to_i\n w2=tmp2[1].to_i\n if w1>w2\n d1.point+=3\n elsif w1x[1]}.map{|o|o[0]}[0,n/2].sort\n"}, {"source_code": "n=gets.to_i;h={};n.times{h[gets.chomp]=[0,0,0];}\n(n*(n-1)/2).times{\n\ts=gets.split /[ :-]/;a,b,c,d=*s;\n\tc,d=c.to_i,d.to_i;a,b,c,d=b,a,d,c if cx[1]}.map{|o|o[0]}[0,n/2].sort\n"}, {"source_code": "#!/usr/bin/ruby\n# -*- coding: utf-8 -*-\n\n=begin\nnA. World Football Cup\ntime limit per test\n2 seconds\nmemory limit per test\n64 megabytes\ninput\nstandard input\noutput\nstandard output\n\nEveryone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:\n\n * the final tournament features n teams (n is always even)\n * the first n\u2009/\u20092 teams (according to the standings) come through to the knockout stage\n * the standings are made on the following principle: for a victory a team gets 3 points, for a draw \u2014 1 point, for a defeat \u2014 0 points. In the first place, teams are ordered in the standings in decreasing order of their points; in the second place \u2014 in decreasing order of the difference between scored and missed goals; in the third place \u2014 in the decreasing order of scored goals\n * it's written in Berland's Constitution that the previous regulation helps to order the teams without ambiguity. \n\nYou are asked to write a program that, by the given list of the competing teams and the results of all the matches, will find the list of teams that managed to get through to the knockout stage.\nInput\n\nThe first input line contains the only integer n (1\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n\u00b7(n\u2009-\u20091)\u2009/\u20092 lines describe the held matches in the format name1-name2 num1:num2, where name1, name2 \u2014 names of the teams; num1, num2 (0\u2009\u2264\u2009num1,\u2009num2\u2009\u2264\u2009100) \u2014 amount of the goals, scored by the corresponding teams. Accuracy of the descriptions is guaranteed: there are no two team names coinciding accurate to the letters' case; there is no match, where a team plays with itself; each match is met in the descriptions only once.\nOutput\n\nOutput n\u2009/\u20092 lines \u2014 names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.\n=end\n\nN = gets.to_i\nteams = Hash.new\nN.times do\n teams[gets.chomp] = [0, 0, 0]\nend\n\n(N * (N - 1) / 2).times do\n tmp = gets.chomp.split\n team1, team2 = tmp[0].split('-')\n score1, score2 = tmp[1].split(':').map{|e| e.to_i}\n if score1 > score2\n teams[team1][0] += 3\n elsif score1 == score2\n teams[team1][0] += 1\n teams[team2][0] += 1\n else\n teams[team2][0] += 3\n end\n\n teams[team1][1] += score1 - score2\n teams[team2][1] += score2 - score1\n\n teams[team1][2] += score1\n teams[team2][2] += score2\nend\n\n#p teams\n\nteams = teams.to_a\nteams.sort!{|l_e, r_e|\n l = l_e[1]\n r = r_e[1]\n if l[0] > r[0]\n -1\n elsif l[0] < r[0]\n 1\n elsif l[1] > r[1]\n -1\n elsif l[1] < r[1]\n 1\n elsif l[2] > r[2]\n -1\n elsif l[2] < r[2]\n 1\n else\n 0\n end\n}\n\n#p teams\n\npassed = teams[0, (N / 2)].sort{|l, r|\n l[0] <=> r[0]\n}\n\npassed.each {|e|\n puts e[0]\n}\n\n \n \n"}, {"source_code": "n=gets.to_i;h={};n.times{h[gets.chomp]=[0,0,0];}\n(n*(n-1)/2).times{\n s=gets.split /[ :-]/;a,b,c,d=*s;\n c,d=c.to_i,d.to_i;a,b,c,d=b,a,d,c if cx[1]}.map{|o|o[0]}[0,n/2].sort"}, {"source_code": "n=gets.to_i;h={};n.times{h[gets.chomp]=[0,0,0];}\n(n*(n-1)/2).times{\n\ts=gets.split /[ :-]/;a,b,c,d=*s;\n\tc,d=c.to_i,d.to_i;a,b,c,d=b,a,d,c if cx[1]}.map{|o|o[0]}[0,n/2].sort"}, {"source_code": "n=gets.to_i;h={};n.times{h[gets.chomp]=[0,0,0];}\n(n*(n-1)/2).times{\n\ts=gets.split /[ :-]/;a,b,c,d=*s;\n\tc,d=c.to_i,d.to_i;a,b,c,d=b,a,d,c if cx[1]}.map{|o|o[0]}[0,n/2].sort\n"}, {"source_code": "n = gets.to_i\nteams = Hash.new { |hash, key| hash[key] = [0, 0, 0]}\nn.times{ gets }\n((n * (n - 1) / 2)).times do \n line = gets.chomp\n line =~ /(\\w+)\\-(\\w+) (\\d+):(\\d+)/\n t_an, t_bn, t_aw, t_bw = $1, $2, $3.to_i, $4.to_i\n if t_aw > t_bw \n teams[t_an][0] += 3\n elsif t_aw < t_bw\n teams[t_bn][0] += 3\n else\n teams[t_an][0] += 1\n teams[t_bn][0] += 1\n end\n teams[t_an][1] += t_aw - t_bw; teams[t_an][2] += t_aw\n teams[t_bn][1] += t_bw - t_aw; teams[t_bn][2] += t_bw\nend\n\nputs teams.sort { |a, b| b[1] <=> a[1] }.map{ |u| u[0]}[0, n / 2].sort \n"}, {"source_code": "n=gets.to_i;h={};n.times{h[gets.chomp]=[0,0,0];}\n(n*(n-1)/2).times{\n\ts=gets.split /[ :-]/;a,b,c,d=*s;\n\tc,d=c.to_i,d.to_i;a,b,c,d=b,a,d,c if cx[1]}.map{|o|o[0]}[0,n/2].sort\n"}, {"source_code": "class Team\n attr_accessor :name, :point, :net_score, :score\n\n def initialize(name)\n self.name = name\n self.point = self.net_score = self.score = 0\n end\n\n def add(x, y)\n self.point += [0, 1, 3][(x <=> y) + 1]\n self.net_score += x - y\n self.score += x\n end\n\n def <=>(o)\n [:point, :net_score, :score].each do |t|\n ret = self.send(t) <=> o.send(t)\n return ret unless ret == 0\n end\n end\nend\n\nn = gets.to_i\nteams = Hash.new\nn.times do\n name = gets.strip\n teams[name] = Team.new(name)\nend\n(n * (n - 1) / 2).times do\n a, b, x, y = gets.strip.split(/[\\:\\- ]/)\n x = x.to_i\n y = y.to_i\n teams[a].add(x, y)\n teams[b].add(y, x)\nend\nwinner = teams.values.sort[-n / 2..-1].map(&:name).sort\nputs winner\n"}, {"source_code": "n=gets.to_i;h={};n.times{h[gets.chomp]=[0,0,0];}\n(n*(n-1)/2).times{\n\ts=gets.split /[ :-]/;a,b,c,d=*s;\n\tc,d=c.to_i,d.to_i;a,b,c,d=b,a,d,c if cx[1]}.map{|o|o[0]}[0,n/2].sort\n"}, {"source_code": "t={}\ngets.to_i.times{t[gets.chop]=[0,0,0]}\nwhile gets=~/(.+)-(.+) (.+):(.+)/\na,b,n,m=t[$1],t[$2],$3.to_i,$4.to_i\na[0]+=n>m ?3: nn ?3: mb : c!=z ? z<=>c : w<=>d}[0..t.size/2-1].map{|a|a[0]}.sort"}, {"source_code": "n, teams = gets.to_i, {}\nn.times { teams[gets.strip.to_sym] = [0, 0, 0] }\n\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\n\tteams[a][2] += g1\n\tteams[b][2] += g2\n\n\tteams[a][1] -= g2 - g1\n\tteams[b][1] -= g1 - g2\n\n\tif g1 == g2\n\t\tteams[a][0] += 1\n\t\tteams[b][0] += 1\n\telsif g1 > g2\n\t\tteams[a][0] += 3\n\telse\n\t\tteams[b][0] += 3\n\tend\n\nend\n\nt = teams.sort { |a, b| b[1] <=> a[1] }.first(n / 2).map { |data| data[0] }.sort\nt.each { |e| puts e }\n"}, {"source_code": "n=gets.to_i;h={};n.times{h[gets.chomp]=[0,0,0];}\n(n*(n-1)/2).times{\n\ts=gets.split /[ :-]/;a,b,c,d=*s;\n\tc,d=c.to_i,d.to_i;a,b,c,d=b,a,d,c if cx[1]}.map{|o|o[0]}[0,n/2].sort\n"}], "negative_code": [{"source_code": "class Team\n\tdef initialize(nm)\n\t\t@name = nm\n\t\t@point = 0\n\t\t@scored = 0\n\t\t@missed = 0\n\tend\n\tattr_accessor :name, :point, :scored, :missed\nend\n\nn = gets.chomp.to_i\nh = Hash.new(n)\nfor i in 0..n-1\n\ts = gets.chomp\n\th[s] = Team.new(s)\nend\n\nfor i in 0..n*(n-1)/2-1\n\ta = gets.chomp.split(/ /)\n\tteams = a[0].split(/\\-/)\n\tscore = a[1].split(/\\:/).map!{|x| x.to_i}\n\th[teams[0]].scored += score[0]\n\th[teams[0]].missed += score[1]\n\th[teams[1]].scored += score[1]\n\th[teams[1]].missed += score[0]\n\tif score[0] == score[1]\n\t\th[teams[0]].point += 1\n\t\th[teams[1]].point += 1\n\telsif score[0] > score[1]\n\t\th[teams[0]].point += 3\n\telse\n\t\th[teams[1]].point += 3\n\tend\nend\n\nqu = h.values.sort!{|a,b|\n\tif a.point == b.point\n\t\tif (a.scored - a.missed) == (b.scored-b.missed)\n\t\t\tb.scored <=> a.scored\n\t\telse\n\t\t\t(a.scored - a.missed) <=> (b.scored-b.missed)\n\t\tend\n\telse\n\t\tb.point <=> a.point\n\tend\n}\n\nqu = qu.slice(0..n/2-1)\nqu.sort!{|a,b| a.name <=> b.name}\n\t\nfor i in 0..n/2-1\n\tprint \" \" if i > 0\n\tprint qu[i].name\nend\nputs"}, {"source_code": "class Team\n\tdef initialize(nm)\n\t\t@name = nm\n\t\t@point = 0\n\t\t@scored = 0\n\t\t@missed = 0\n\tend\n\tattr_accessor :name, :point, :scored, :missed\nend\n\nn = gets.chomp.to_i\nh = Hash.new(n)\nfor i in 0..n-1\n\ts = gets.chomp\n\th[s] = Team.new(s)\nend\n\nfor i in 0..n*(n-1)/2-1\n\ta = gets.chomp.split(/ /)\n\tteams = a[0].split(/\\-/)\n\tscore = a[1].split(/\\:/).map!{|x| x.to_i}\n\th[teams[0]].scored += score[0]\n\th[teams[0]].missed += score[1]\n\th[teams[1]].scored += score[1]\n\th[teams[1]].missed += score[0]\n\tif score[0] == score[1]\n\t\th[teams[0]].point += 1\n\t\th[teams[1]].point += 1\n\telsif score[0] > score[1]\n\t\th[teams[0]].point += 3\n\telse\n\t\th[teams[1]].point += 3\n\tend\nend\n\nqu = h.values.sort!{|a,b|\n\tif a.point == b.point\n\t\tif (a.scored - a.missed) == (b.scored-b.missed)\n\t\t\tb.scored <=> a.scored\n\t\telse\n\t\t\t(a.scored - a.missed) <=> (b.scored-b.missed)\n\t\tend\n\telse\n\t\tb.point <=> a.point\n\tend\n}\n\nqu = qu.slice(0..n/2-1)\nqu.sort!{|a,b| a.name <=> b.name}\n\t\nfor i in 0..n/2-1\n\tputs qu[i].name\nend\n"}, {"source_code": "h=Hash.new\n(n=gets.to_i).times{|i|\n h[s=gets.chomp]=[0,0,s]\n}\n(n*(n-1)/2).times{|i|\n gets=~/(\\w+)-(\\w+) (\\d+):(\\d+)/\n _3=$3.to_i;_4=$4.to_i;\n if _3>_4 then h[$1][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_3-_4 end\n if _3<_4 then h[$2][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_4-_3 end\n if _3==_4 then h[$1][0]+=1;h[$2][0]+=1 end\n}\na=Array.new\nh.values.sort[n/2,n/2].each{|i|\n a.push i[2]\n}\na.sort.each{|s|puts s}\n"}, {"source_code": "h=Hash.new\n(n=gets.to_i).times{|i|\n h[s=gets.chomp]=[0,0,s]\n}\n(n*(n-1)/2).times{|i|\n gets=~/(\\w+)-(\\w+) (\\d+):(\\d+)/\n _3=$3.to_i;_4=$4.to_i;\n if _3>_4 then h[$1][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_4-_3 end\n if _3<_4 then h[$2][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_4-_3 end\n if _3==_4 then h[$1][0]+=1;h[$2][0]+=1 end\n}\na=Array.new\nh.values.sort[n/2,n/2].each{|i|\n a.push i[2]\n}\na.sort.each{|s|puts s}\n"}, {"source_code": "h=Hash.new\n(n=gets.to_i).times{|i|\n h[s=gets.chomp]=[0,0,s]\n}\n(n*(n-1)/2).times{|i|\n gets=~/(\\w+)-(\\w+) (\\d+):(\\d+)/\n _3=$3.to_i;_4=$4.to_i;\n if _3>_4 then h[$1][0]+=3;h[$1][1]+=_4-_3;h[$2][1]+=_3-_4 end\n if _3<_4 then h[$2][0]+=3;h[$1][1]+=_4-_3;h[$2][1]+=_3-_4 end\n if _3==_4 then h[$1][0]+=1;h[$2][0]+=1 end\n}\na=Array.new\nh.values.sort[n/2,n/2].each{|i|\n a.push i[2]\n}\na.sort.each{|s|puts s}\n"}, {"source_code": "h=Hash.new\n(n=gets.to_i).times{|i|\n h[s=gets.chomp]=[0,0,0,s]\n}\n(n*(n-1)/2).times{|i|\n gets=~/(\\w+)-(\\w+) (\\d+):(\\d+)/\n _3=$3.to_i;_4=$4.to_i;\n if _3>_4 then h[$1][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_4-_3;h[$1][2]+=_3;h[$2][2]+=_4 end\n if _3<_4 then h[$2][0]+=3;h[$1][1]+=_3-_4;h[$2][1]+=_4-_3;h[$1][2]+=_3;h[$2][2]+=_4 end\n if _3==_4 then h[$1][0]+=1;h[$2][0]+=1;h[$1][2]+=_3;h[$2][2]+=_4 end\n}\na=Array.new\nh.values.sort[n/2,n/2].each{|i|\n a.push i[2]\n}\na.sort.each{|s|puts s}\n"}, {"source_code": "n = gets.to_i\nteams = Hash.new { |hash, key| hash[key] = [0, 0, 0]}\nn.times{ gets }\n((n * (n - 1) / 2)).times do \n line = gets.chomp\n line =~ /(\\w+)\\-(\\w+) (\\d+):(\\d+)/\n t_an, t_bn, t_aw, t_bw = $1, $2, $3.to_i, $4.to_i\n if t_aw > t_bw \n teams[t_an][0] += 3\n elsif t_aw < t_bw\n teams[t_bn][0] += 3\n else\n teams[t_an][0] += 1\n teams[t_bn][0] += 1\n end\n teams[t_an][1] += t_aw; teams[t_bn][2] += t_bw\n teams[t_bn][1] += t_bw; teams[t_an][2] += t_aw\nend\n\nt = teams.sort do |a, b|\n if a[1][0] != b[1][0]\n b[1][0] <=> a[1][0]\n elsif a[1][1] - a[1][2] != b[1][1] - b[1][2]\n (b[1][1] - b[1][2]) <=> (a[1][1] - a[1][2])\n else\n b[1][1] <=> a[1][1]\n end\nend\n\nu = Array.new\n(0...(n / 2)).each { |i| u << t[i] }\nu.sort! { |a, b| a[0] <=> b[0] }\n(0...(n / 2)).each do |i|\n puts u[i][0]\nend\n"}, {"source_code": "#!/usr/bin/env ruby\nnumber = gets.to_i\n\nt = {}\ny = {}\nnumber.times do |i|\n team = gets.strip\n t[team] = i\n y[i] = team\nend\n\nmatches = (number * (number - 1)/2).to_i\nmatrix = []\nnumber.times { |i| matrix[i] = Array.new(0) }\n\nmatches.times do\n result = gets\n ts, res = result.split\n team1, team2 = ts.split('-')\n goal1, goal2 = res.split(':')\n \n matrix[t[team1]][t[team2]] = goal1.to_i\n matrix[t[team2]][t[team1]] = goal2.to_i\nend\n\nget_score = lambda do |goal1, goal2|\n if goal1 > goal2\n [3, 0]\n elsif goal1 < goal2\n [0, 3]\n else\n [1, 1]\n end\nend\n\nmatrix_r = matrix\nmatrix.each_with_index do |team, i|\n sum = team.inject(0) { |r, v| r+v.to_i }\n\n diff = sum\n number.times do |j|\n diff -= matrix[j][i] || 0\n end\n\n matrix_r[i] << sum << diff << y[i]\nend\n\nmatrix_sorted = matrix_r.sort_by do |team|\n [ team[-3], team[-2] ]\nend\n\n# output results\n(number / 2).times do |i|\n puts matrix_sorted[number/2 + i][-1] \nend\n"}, {"source_code": "#!/usr/bin/env ruby\nnumber = gets.to_i\n\nmatches = (number * (number - 1)/2).to_i\nmatrix = []\nnumber.times { |i| matrix[i] = [] }\n\nt = {}\nnumber.times do |i|\n team = gets.strip\n matrix[i] = [0, 0, 0, team]\n t[team] = i\nend\n\nget_score = lambda do |goal1, goal2|\n if goal1 > goal2\n [3, 0]\n elsif goal1 < goal2\n [0, 3]\n else\n [1, 1]\n end\nend\n\nmatches.times do\n result = gets\n ts, res = result.split\n \n team1, team2 = ts.split('-')\n goal1, goal2 = res.split(':').map { |v| v.to_i }\n score1, score2 = get_score.call(goal1, goal2)\n\n matrix[t[team1]][0] += score1\n matrix[t[team2]][0] += score2\n\n matrix[t[team1]][1] += goal1 - goal2\n matrix[t[team2]][1] += goal2 - goal1\n\n matrix[t[team1]][2] += goal1\n matrix[t[team2]][2] += goal2\nend\n\nmatrix = matrix.sort_by do |team|\n [ team[0], team[1], team[2] ]\nend\n\n(number / 2).times do |i|\n puts matrix[number/2 + i][-1] \nend\n"}, {"source_code": "#!/usr/bin/env ruby\nnumber = gets.to_i\n\nt = {}\ny = {}\nnumber.times do |i|\n team = gets.strip\n t[team] = i\n y[i] = team\nend\n\nmatches = (number * (number - 1)/2).to_i\nmatrix = []\nnumber.times { |i| matrix[i] = Array.new(0) }\n\nmatches.times do\n result = gets\n ts, res = result.split\n team1, team2 = ts.split('-')\n goal1, goal2 = res.split(':')\n \n matrix[t[team1]][t[team2]] = goal1.to_i\n matrix[t[team2]][t[team1]] = goal2.to_i\nend\n\nget_score = lambda do |goal1, goal2|\n if goal1 > goal2\n [3, 0]\n elsif goal1 < goal2\n [0, 3]\n else\n [1, 1]\n end\nend\n\nmatrix_r = matrix\nmatrix.each_with_index do |team, i|\n sum = team.inject(0) { |r, v| r+v.to_i }\n\n diff = sum\n number.times do |j|\n diff -= matrix[j][i] || 0\n end\n\n matrix_r[i] << sum << diff << y[i]\nend\n\nmatrix_sorted = matrix_r.sort_by do |team|\n [ team[-3], team[-2] ]\nend.reverse\n\n# output results\n(number / 2).times do |i|\n puts matrix_sorted[i][-1] \nend\n"}, {"source_code": "#!/usr/bin/env ruby\nnumber = gets.to_i\n\nmatches = (number * (number - 1)/2).to_i\nmatrix = []\nnumber.times { |i| matrix[i] = [] }\n\nt = {}\nnumber.times do |i|\n team = gets.strip\n matrix[i] = [0, 0, 0, team]\n t[team] = i\nend\n\nget_score = lambda do |goal1, goal2|\n if goal1 > goal2\n [3, 0]\n elsif goal1 < goal2\n [0, 3]\n else\n [1, 1]\n end\nend\n\nmatches.times do\n result = gets\n ts, res = result.split\n \n team1, team2 = ts.split('-')\n goal1, goal2 = res.split(':').map { |v| v.to_i }\n score1, score2 = get_score.call(goal1, goal2)\n\n matrix[t[team1]][0] += score1\n matrix[t[team2]][0] += score2\n\n matrix[t[team1]][1] += goal1 - goal2\n\n matrix[t[team1]][2] += goal1\nend\n\nmatrix = matrix.sort_by do |team|\n [ team[0], team[1], team[2] ]\nend\n\n(number / 2).times do |i|\n puts matrix[number/2 + i][-1] \nend\n"}, {"source_code": "#!/usr/bin/env ruby\nnumber = gets.to_i\n\nmatches = (number * (number - 1)/2).to_i\nmatrix = []\nnumber.times { |i| matrix[i] = [] }\n\nt = {}\nnumber.times do |i|\n team = gets.strip\n matrix[i] = [0, 0, 0, team]\n t[team] = i\nend\n\nget_score = lambda do |goal1, goal2|\n if goal1 > goal2\n [3, 0]\n elsif goal1 < goal2\n [0, 3]\n else\n [1, 1]\n end\nend\n\nmatches.times do\n result = gets\n ts, res = result.split\n \n team1, team2 = ts.split('-')\n goal1, goal2 = res.split(':').map { |v| v.to_i }\n score1, score2 = get_score.call(goal1, goal2)\n\n matrix[t[team1]][0] += score1\n matrix[t[team2]][0] += score2\n\n matrix[t[team1]][1] += goal1 - goal2\n matrix[t[team2]][1] += goal2 - goal1\n\n matrix[t[team1]][2] += goal1\n matrix[t[team2]][2] += goal2\nend\n\nmatrix = matrix.sort_by do |team|\n [ team[0], team[1], team[2] ]\nend\n\np matrix\n\n(number / 2).times do |i|\n puts matrix[number/2 + i][-1] \nend\n"}, {"source_code": "#!/usr/bin/env ruby\nnumber = gets.to_i\n\nmatches = (number * (number - 1)/2).to_i\nmatrix = []\nnumber.times { |i| matrix[i] = [] }\n\nt = {}\nnumber.times do |i|\n team = gets.strip\n matrix[i] = [0, 0, team]\n t[team] = i\nend\n\nget_score = lambda do |goal1, goal2|\n if goal1 > goal2\n [3, 0]\n elsif goal1 < goal2\n [0, 3]\n else\n [1, 1]\n end\nend\n\nmatches.times do\n result = gets\n ts, res = result.split\n \n team1, team2 = ts.split('-')\n goal1, goal2 = res.split(':').map { |v| v.to_i }\n score1, score2 = get_score.call(goal1, goal2)\n\n matrix[t[team1]][0] += score1\n matrix[t[team2]][0] += score2\n\n matrix[t[team1]][1] += goal1 - goal2\nend\n\nmatrix_sorted = matrix.sort_by do |team|\n [ team[-3], team[-2] ]\nend\n\n# output results\nqual = number==1 ? 1 : number / 2\nqual.times do |i|\n puts matrix_sorted[number/2 + i][-1] \nend\n"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\n\nmatches = (n * (n - 1)/2).to_i\nmatrix = []\nn.times { |i| matrix[i] = [] }\n\nt = {}\nn.times do |i|\n team = gets.strip\n matrix[i] = [0, 0, 0, team]\n t[team] = i\nend\n\nget_score = lambda do |goal1, goal2|\n if goal1 > goal2\n [3, 0]\n elsif goal1 < goal2\n [0, 3]\n else\n [1, 1]\n end\nend\n\nmatches.times do\n result = gets\n ts, res = result.split\n \n team1, team2 = ts.split('-')\n goal1, goal2 = res.split(':').map { |v| v.to_i }\n score1, score2 = get_score.call(goal1, goal2)\n\n # by score\n matrix[t[team1]][0] += score1\n matrix[t[team2]][0] += score2\n\n # by diff\n matrix[t[team1]][1] += goal1 - goal2\n matrix[t[team2]][1] += goal2 - goal1\n\n # by goals\n matrix[t[team1]][2] += goal1\n matrix[t[team2]][2] += goal2\nend\n\nmatrix = matrix.sort_by { |team| [ team[0], team[1], team[2], team[3] ] }\n\n(n/2 .. n-1).each { |i| puts matrix[i][-1] }\n"}, {"source_code": "#!/usr/bin/env ruby\nn = gets.to_i\n\nmatches = (n * (n - 1)/2).to_i\nmatrix = []\nn.times { |i| matrix[i] = [] }\n\nt = {}\nn.times do |i|\n team = gets.strip\n matrix[i] = [0, 0, 0, team]\n t[team] = i\nend\n\nget_score = lambda do |goal1, goal2|\n if goal1 > goal2\n [3, 0]\n elsif goal1 < goal2\n [0, 3]\n else\n [1, 1]\n end\nend\n\nmatches.times do\n result = gets\n ts, res = result.split\n \n team1, team2 = ts.split('-')\n goal1, goal2 = res.split(':').map { |v| v.to_i }\n score1, score2 = get_score.call(goal1, goal2)\n\n # by score\n matrix[t[team1]][0] += score1\n matrix[t[team2]][0] += score2\n\n # by diff\n matrix[t[team1]][1] += goal1 - goal2\n matrix[t[team2]][1] += goal2 - goal1\n\n # by goals\n matrix[t[team1]][2] += goal1\n matrix[t[team2]][2] += goal2\nend\n\nmatrix = matrix.sort_by { |team| [ team[0], team[1], team[2] ] }\n\n(n / 2 .. n-1).each { |i| puts matrix[i][-1] }\n"}, {"source_code": "n, teams = gets.to_i, {}\nn.times { teams[gets.strip.to_sym] = [0, 0, 0] }\n\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\n\tteams[a][2] += g1\n\tteams[b][2] += g2\n\n\tteams[a][1] += (g1 - g2).abs\n\tteams[a][1] += (g2 - g1).abs\n\n\tif g1 == g2\n\t\tteams[a][0] += 1\n\t\tteams[b][0] += 1\n\telsif g1 > g2\n\t\tteams[a][0] += 3\n\telse\n\t\tteams[b][0] += 3\n\tend\n\nend\n\nteams.sort { |a, b| a[1] <=> b[1] }.reverse.first(n / 2).each { |data| puts data[0] }\n"}, {"source_code": "n, teams = gets.to_i, {}\nn.times { teams[gets.strip.to_sym] = [0, 0, 0] }\n\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\n\tteams[a][1] += g1\n\tteams[b][1] += g2\n\n\tteams[a][2] += g2\n\tteams[a][2] += g1\n\n\tif g1 == g2\n\t\tteams[a][0] += 1\n\t\tteams[b][0] += 1\n\telsif g1 > g2\n\t\tteams[a][0] += 3\n\telse\n\t\tteams[b][0] += 3\n\tend\n\nend\n\nteams.sort { |a, b| a[1] <=> b[1] }.last(n / 2).each { |data| puts data[0] }\n"}, {"source_code": "n, teams = gets.to_i, {}\nn.times { teams[gets.strip.to_sym] = [0, 0, 0] }\n\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\n\tteams[a][2] += g1\n\tteams[b][2] += g2\n\n\tteams[a][1] += (g1 - g2).abs\n\tteams[a][1] += (g2 - g1).abs\n\n\tif g1 == g2\n\t\tteams[a][0] += 1\n\t\tteams[b][0] += 1\n\telsif g1 > g2\n\t\tteams[a][0] += 3\n\telse\n\t\tteams[b][0] += 3\n\tend\n\nend\n\nt = teams.sort { |a, b| b[1] <=> a[1] }.map { |data| data[0] }.sort\nt.first(n / 2).each { |e| puts e }\n"}, {"source_code": "n, teams = gets.to_i, {}\nn.times { teams[gets.strip.to_sym] = [0, 0, 0] }\n\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\n\tteams[a][1] += g1\n\tteams[b][1] += g2\n\n\tteams[a][2] += (g1 - g2).abs\n\tteams[a][2] += (g2 - g1).abs\n\n\tif g1 == g2\n\t\tteams[a][0] += 1\n\t\tteams[b][0] += 1\n\telsif g1 > g2\n\t\tteams[a][0] += 3\n\telse\n\t\tteams[b][0] += 3\n\tend\n\nend\n\nteams.sort { |a, b| a[1] <=> b[1] }.last(n / 2).each { |data| puts data[0] }"}, {"source_code": "n, teams = gets.to_i, {}\nn.times { teams[gets.strip.to_sym] = [0, 0, 0] }\n\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\n\tteams[a][2] += g1\n\tteams[b][2] += g2\n\n\tteams[a][1] += (g1 - g2).abs\n\tteams[a][1] += (g2 - g1).abs\n\n\tif g1 == g2\n\t\tteams[a][0] += 1\n\t\tteams[b][0] += 1\n\telsif g1 > g2\n\t\tteams[a][0] += 3\n\telse\n\t\tteams[b][0] += 3\n\tend\n\nend\n\nt = teams.sort { |a, b| b[1] <=> a[1] }.first(n / 2).map { |data| data[0] }.sort\nt.each { |e| puts e }\n"}, {"source_code": "\nn, teams = gets.to_i, Hash.new(0); n.times { gets }\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\tteams[a] += g1\n\tteams[b] += g2\nend\n\np teams\n\nteams.sort { |a, b| a[1] <=> b[1] }.last(n / 2).each { |data| puts data[0] }"}, {"source_code": "n, teams = gets.to_i, {}\nn.times { teams[gets.strip.to_sym] = [0, 0, 0] }\n\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\n\tteams[a][2] += g1\n\tteams[b][2] += g2\n\n\tteams[a][1] += (g1 - g2).abs\n\tteams[a][1] += (g2 - g1).abs\n\n\tif g1 == g2\n\t\tteams[a][0] += 1\n\t\tteams[b][0] += 1\n\telsif g1 > g2\n\t\tteams[a][0] += 3\n\telse\n\t\tteams[b][0] += 3\n\tend\n\nend\n\nteams.sort { |a, b| a[1] <=> b[1] }.last(n / 2).each { |data| puts data[0] }\n"}, {"source_code": "n, teams = gets.to_i, {}\nn.times { teams[gets.strip.to_sym] = [0, 0, 0] }\n\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\n\tteams[a][1] += g1\n\tteams[b][1] += g2\n\n\tteams[a][2] += g1 - g2\n\tteams[a][2] += g2 - g1\n\n\tif g1 == g2\n\t\tteams[a][0] += 1\n\t\tteams[b][0] += 1\n\telsif g1 > g2\n\t\tteams[a][0] += 3\n\telse\n\t\tteams[b][0] += 3\n\tend\n\nend\n\nteams.sort { |a, b| a[1] <=> b[1] }.last(n / 2).each { |data| puts data[0] }\n"}, {"source_code": "n, teams = gets.to_i, {}\nn.times { teams[gets.strip.to_sym] = [0, 0, 0] }\n\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\n\tteams[a][2] += g1\n\tteams[b][2] += g2\n\n\tteams[a][1] += (g1 - g2).abs\n\tteams[a][1] += (g2 - g1).abs\n\n\tif g1 == g2\n\t\tteams[a][0] += 1\n\t\tteams[b][0] += 1\n\telsif g1 > g2\n\t\tteams[a][0] += 3\n\telse\n\t\tteams[b][0] += 3\n\tend\n\nend\n\nteams.sort { |a, b| b[1] <=> a[1] }.first(n / 2).each { |data| puts data[0] }\n"}, {"source_code": "n, teams = gets.to_i, Hash.new(0); n.times { gets }\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\tteams[a] += g1\n\tteams[b] += g2\nend\nteams.sort { |a, b| a[1] <=> b[1] }.last(n / 2).each { |data| puts data[0] }\n"}, {"source_code": "n, teams = gets.to_i, {}\nn.times { teams[gets.strip.to_sym] = [0, 0, 0] }\n\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\ta, b, g1, g2 = g[0].to_sym, g[1].to_sym, g[2].to_i, g[3].to_i\n\n\tteams[a][1] += g1\n\tteams[b][1] += g2\n\n\tteams[a][2] -= g2\n\tteams[a][2] -= g1\n\n\tif g1 == g2\n\t\tteams[a][0] += 1\n\t\tteams[b][0] += 1\n\telsif g1 > g2\n\t\tteams[a][0] += 3\n\telse\n\t\tteams[b][0] += 3\n\tend\n\nend\n\nteams.sort { |a, b| a[1] <=> b[1] }.last(n / 2).each { |data| puts data[0] }\n"}, {"source_code": "n, teams = gets.to_i, Hash.new(0); n.times { gets }\n\nwhile g = gets\n\tg = g.strip.split(/[:\\-[:space:]]/)\n\n\t a = g[0].to_sym\n\t b = g[1].to_sym\n\tas = g[2].to_i\n\tbs = g[3].to_i\n\n\tif as == bs\n\t\tscore = [1, 1]\n\telsif as > bs\n\t\tscore = [3, -1]\n\telse\n\t\tscore = [-1, 3]\n\tend\n\n\tteams[a] = score[0]\n\tteams[b] = score[1]\n\nend\n\nteams.sort_by { |team, score| score }.last(n / 2).each { |data| puts data[0] }"}], "src_uid": "472c0cb256c062b9806bf93b13b453a2"} {"source_code": "n,m = STDIN.readline.strip.split(/\\s+/).map(&:to_i)\n\ncoordinates = []\nm.times do\n coordinates << STDIN.readline.strip.split(/\\s+/).map(&:to_i)\nend\n\nflower = '1'\nstring = ''\nn.times do\n string += flower\n if flower == '1'\n flower = '0'\n else\n flower = '1'\n end\nend\n\nputs string\n", "positive_code": [{"source_code": "n, d = gets.chomp.split.map(&:to_i)\nx = \"\"\n0.upto(n-1) { |n| x += (n&1).to_s }\nprint x"}, {"source_code": "n, m = gets.chomp.split\nn = n.to_i\nm = m.to_i\nm.times do |m|\n gets.chomp\nend\n\nans = \"\"\nn.times do |i|\n ans << (i % 2).to_s\nend\nputs ans"}, {"source_code": "N, M = gets.to_i\nputs N.times.map{|i| i%2==0 ? 1 : 0}.join"}, {"source_code": "n, m = gets.strip.split.map(&:to_i)\nm.times do\n gets.strip.split.map(&:to_i)\nend\n\nstr = \"\"\nn.times do |i|\n str << (i%2).to_s\nend\nputs str"}, {"source_code": "n, m = gets.split.map &:to_i\nputs (0...n).map { |i| i.even? ? ?0 : ?1 } .join\n"}], "negative_code": [], "src_uid": "cac8ca5565e06021a44bb4388b5913a5"} {"source_code": "def root(n)\n until n <= 9\n n = n.to_s.split('').map(&:to_i).inject(:+)\n end\n n\nend\n\n\ndef solve(s)\nend\n\ngets.strip.to_i.times do\n k, x = gets.strip.split(' ').map(&:to_i)\n puts (9 * (k - 1)) + x\nend", "positive_code": [{"source_code": "gets;puts$<.map{|e|k,x=e.split.map &:to_i;x+9*~-k}"}, {"source_code": "(1..gets.to_i).each{ |_| \n x,y = gets.scan(/\\d+/).map(&:to_i)\n puts 9*(x-1)+y\n}\n"}, {"source_code": "n = gets.to_i\nn.times do\n k,x = gets.split.map(&:to_i)\n puts 9*(k-1)+x\nend"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nn = gets.to_i\nn.times do\n kx = gets.chomp.split(\" \").map(&:to_i)\n k = kx[0]\n x = kx[1]\n\n puts 9*(k-1) + x\nend"}, {"source_code": "q=gets.to_i\nfor _ in 1..q\n a,b=gets.split.map &:to_i\n puts b+9*a-9\nend\n"}], "negative_code": [], "src_uid": "891fabbb6ee8a4969b6f413120f672a8"} {"source_code": "require 'set'\r\nt = gets.to_i\r\nt.times.each do\r\n n = gets.to_i\r\n s = gets.chomp\r\n seen = Set.new\r\n (0...s.length).each do |i|\r\n (i + 1..s.length).each do |j|\r\n seen << s[i, j - i]\r\n end\r\n end\r\n\r\n base = 'a'.ord - 1\r\n key = nil\r\n (1..2000000).each do |s|\r\n key = ''\r\n ok = true\r\n until s == 0 do\r\n if s % 27 == 0\r\n ok = false\r\n break\r\n end\r\n c = (base + (s % 27)).chr\r\n key.concat(c)\r\n s /= 27\r\n end\r\n key.reverse!\r\n\r\n break if ok && !seen.include?(key)\r\n end\r\n puts key\r\nend\r\n", "positive_code": [{"source_code": "require 'set'\nt = gets.to_i\nt.times.each do\n n = gets.to_i\n s = gets.chomp\n seen = Set.new\n (0...s.length).each do |i|\n (i + 1..s.length).each do |j|\n seen << s[i, j - i]\n end\n end\n\n base = 'a'.ord - 1\n key = nil\n (1..2000000).each do |s|\n key = ''\n ok = true\n until s == 0 do\n if s % 27 == 0\n ok = false\n break\n end\n c = (base + (s % 27)).chr\n key.concat(c)\n s /= 27\n end\n key.reverse!\n\n break if ok && !seen.include?(key)\n end\n puts key\nend\n"}, {"source_code": "require 'set'\nt = gets.to_i\nt.times.each do\n n = gets.to_i\n s = gets.chomp\n seen = Set.new\n (0...s.length).each do |i|\n (i + 1..s.length).each do |j|\n seen << s[i, j - i]\n end\n end\n\n base = 'a'.ord - 1\n key = nil\n (1..2000000).each do |s|\n key = ''\n ok = true\n until s == 0 do\n if s % 27 == 0\n ok = false\n break\n end\n c = (base + (s % 27)).chr\n key.concat(c)\n s /= 27\n end\n key.reverse!\n\n break if ok && !seen.include?(key)\n end\n puts key\nend\n"}, {"source_code": "MAXLEN = 6\nAAA = 'a' * MAXLEN\nrequire 'set'\nt = gets.to_i\nt.times.each do\n n = gets.to_i\n s = gets.chomp\n seen = Set.new\n (0...s.length).each do |i|\n (i + 1..s.length).each do |j|\n seen << s[i, j - i]\n end\n end\n\n base = 'a'.ord - 1\n key = nil\n (1..2000000).each do |s|\n key = ''\n ok = true\n until s == 0 do\n if s % 27 == 0\n ok = false\n break\n end\n c = (base + (s % 27)).chr\n key.concat(c)\n s /= 27\n end\n key.reverse!\n\n break if ok && !seen.include?(key)\n end\n puts key\nend\n"}], "negative_code": [{"source_code": "require 'set'\nt = gets.to_i\nt.times.each do\n n = gets.to_i\n s = gets.chomp\n seen = Set.new\n (0...s.length).each do |i|\n (i + 1..s.length).each do |j|\n seen << s[i, j - i]\n end\n end\n cur = 'a'\n while seen.include?(cur) do\n pos = cur.length - 1\n while cur[pos] == 'z' && pos >= 0 do\n pos -= 1\n end\n if pos < 0\n cur = 'a' * (cur.length + 1)\n else\n cur[pos] = (cur[pos].ord + 1).chr\n end\n end\n puts cur\nend\n"}], "src_uid": "83a665723ca4e40c78fca20057a0dc99"} {"source_code": "gets.to_i.times{\r\n gets\r\n x = gets.split.map &:to_i\r\n a = x.max\r\n b = x.max(2)[1]\r\n x.size.times{|i|\r\n if x[i]==a\r\n print(a-b,' ')\r\n else\r\n print(x[i]-a,' ')\r\n end\r\n }\r\n puts \"\"\r\n}", "positive_code": [{"source_code": "main = -> {\n n = gets.to_i\n s = gets.split.map(&:to_i)\n\n strongs = s.max(2)\n\n ans = n.times.map {|i|\n if s[i] == strongs[0]\n s[i] - strongs[1]\n else\n s[i] - strongs[0]\n end\n }\n\n ans.join(\" \")\n}\n\nt = gets.to_i\nputs t.times.map{ main.call }.join(\"\\n\")\n"}, {"source_code": "=begin\n\nWelcome to GDB Online.\nGDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,\nC#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.\nCode, Compile, Run and Debug online from anywhere in world.\n\n=end\n\nt=gets.to_i\nfor i in 1..t\n n =gets.to_i\n s=gets\n maks=s.split.map{|x|x.to_i}\n s1=maks.dup\n s2=maks.dup\n for j in 1..(n-1)\n s1[j]=[s1[j-1], s1[j]].max\n s2[n-j-1]=[s2[n-j-1], s2[n-j]].max\n end\n print(maks[0]-s2[1], \" \")\n for j in 1..(n-2)\n print(maks[j]-[s1[j-1], s2[j+1]].max, \" \")\n end\n puts maks[n-1]-s1[n-2]\nend\n"}], "negative_code": [], "src_uid": "7965b6ce237b02617b55dc175ffa0451"} {"source_code": "include Math\n\nn,k = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\nval = ((-1 + sqrt(1+8*k))/2).ceil\nans = k - ((val-1)*val)/2\n\nputs arr[ans-1]", "positive_code": [{"source_code": "n,k,*a=$<.read.split.map(&:to_i)\ni=1\n(k-=i;i+=1)while k>i\np a[k-1]"}, {"source_code": "n, k = readline.split(' ').collect(&:to_i)\narr = readline.split(' ').collect(&:to_i)\nk -= 1\n1.upto(n) do |x|\n if k >= x\n k -= x\n else\n puts arr[k]\n break\n end\nend\n"}, {"source_code": "a=gets.chomp.split.map{|i|i.to_i}\nb=gets.chomp.split\nif a[1]==1\nputs \"#{b[0]}\"\nelse\nn=1\nloop do\np=(n*(n+1))/2\nif p>=a[1]\nn-=1\nbreak\nelse\nn+=1\nend\nend\na[1]-=((n*(n+1))/2)\nputs\"#{b[a[1]-1]}\"\nend"}, {"source_code": "a=gets.chomp.split.map{|i|i.to_i}\nb=gets.chomp.split\nif a[1]==1\nputs \"#{b[0]}\"\nelse\nn=1\nloop do\np=(n*(n+1))/2\nif p>=a[1]\nn-=1\nbreak\nelse\nn+=1\nend\nend\na[1]-=((n*(n+1))/2)\nputs\"#{b[a[1]-1]}\"\nend"}, {"source_code": "include Math\nn,k = gets.split.map(&:to_i)\narr_n = gets.split.map(&:to_i)\n\nk1 = ((-1 + sqrt(1+8*k))/2).ceil\nkeq = k - ((k1-1)*k1)/2\n\n# puts \"k1 #{k1}\"\n# puts \"k1(k1+1)/2 #{k1*(k1+1)/2}\"\n# puts \"Number of ids in k1 robots turn #{(k1*(k1+1) - (k1-1)*k1)/2}\"\n# puts keq\nputs arr_n[keq-1]"}, {"source_code": "n,k,*a=$<.read.split.map(&:to_i)\ni=1\n(k-=i;i+=1)while k>i\np a[k-1]\n"}, {"source_code": "def f num\n\t((num + 1) * num) / 2\nend\n\ninput = gets.chomp.split(' ').map { |i| i.to_i }\nn, k = input[0], input[1]\n\nident = []\n\ninput = gets.chomp.split(' ').map { |i| i.to_i }\n\ninput.each do |i|\n\tident << i\nend\n\nmax = f(n)\nnearest = 0\n\nuntil f(nearest) >= k\n\tnearest += 1\nend\n\nnearest -= 1\nk -= f(nearest)\n\n#puts k\nputs ident[k - 1] if k > 0\nputs ident[0] if k <= 0"}, {"source_code": "parse_int = lambda { gets.split.map{|x| x.to_i} }\n\nn,k = parse_int.call\nnums = parse_int.call\n\ni = 1\nwhile true\n break if k-i<1\n\n k-=i\n i+=1\n\nend\n\nprint nums[k-1]"}], "negative_code": [{"source_code": "def f num\n\t((num + 1) * num) / 2\nend\n\ninput = gets.chomp.split(' ').map { |i| i.to_i }\nn, k = input[0], input[1]\n\nident = []\n\ninput = gets.chomp.split(' ').map { |i| i.to_i }\n\ninput.each do |i|\n\tident << i\nend\n\nmax = f(n)\nnearest = 0\n\nuntil f(nearest) > k\n\tnearest += 1\nend\n\nnearest -= 1\nk -= f(nearest)\n\nputs input[k - 1]"}, {"source_code": "input = gets.chomp.split(' ').map { |i| i.to_i }\nn, k = input[0], input[1]\n\nident = []\n\ninput = gets.chomp.split(' ').map { |i| i.to_i }\n\ninput.each do |i|\n\tident << i\nend\n\ntarget = 0\n\nif k > n\n\ttarget = (k % n) - 1\n\ttarget = (n - 1) if target < 0\nelse\n\ttarget = k - 1\nend\n\nputs (n - target)"}], "src_uid": "9ad07b42358e7f7cfa15ea382495a8a1"} {"source_code": "t = gets.chomp.to_i\nt.times do\n a, b = gets.chomp.split(' ').map(&:to_i)\n a_binary = a.to_s(2).reverse\n b_binary = b.to_s(2).reverse\n l = [a_binary.length, b_binary.length].min\n x = \"\"\n l.times do |i|\n if a_binary[i] == \"1\" && b_binary[i] == \"1\"\n x << \"1\"\n else\n x << \"0\"\n end\n end\n x = x.reverse.to_i(2)\n puts (a ^ x) + (b ^ x)\nend", "positive_code": [{"source_code": "1.upto(gets.to_i){a,b=gets.split(' ').map(&:to_i)\nputs a^b}\n"}, {"source_code": "1.upto(gets.to_i){\n a,b=gets.split(' ').map(&:to_i)\n puts a^b\n}\n"}, {"source_code": "(1..(gets.to_i)).each{\n a,b=gets.split(' ').map(&:to_i)\n puts a^b\n}\n"}, {"source_code": "gets.to_i.times{a,b=gets.split(' ')\nputs a.to_i^b.to_i}\n"}, {"source_code": "gets.to_i.times{a,b=gets.split(' ');puts a.to_i^b.to_i}\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n a, b = gets.split.map(&:to_i)\n\n bl = [a.bit_length, b.bit_length].max\n x = 0\n\n bl.times do |i|\n if a[i] == 1 && b[i] == 1\n x |= (1 << i)\n end\n end\n\n puts (a ^ x) + (b ^ x)\nend\n"}], "negative_code": [], "src_uid": "4be3698735278f29b307a7060eb69693"} {"source_code": "num = gets.to_i\ncolors = gets\npossible_colors = [\"R\", \"G\", \"B\"]\ncolors = colors.split(\"\")\nnum_possibilites = 0\n(1..num).each do |index|\n\tcolor = colors[index]\n\tprev_color = colors[index-1] || \"\"\n\tnext_color = colors[index+1] || \"\"\n\tif color == prev_color\n\t\tpossibilites = (possible_colors-[prev_color, next_color])\n\t\tnum_possibilites += 1\n\t\tcolors[index] = possibilites.first\n\tend\nend\nputs num_possibilites\nputs colors.join(\"\")\n", "positive_code": [{"source_code": "def solution\n read_int\n gs = read_string.chars\n\n colors = [\"R\", \"G\", \"B\"]\n\n moves = 0\n\n for i in (0...gs.size)\n prv = i > 0 ? gs[i - 1] : nil\n crt = gs[i]\n nxt = gs[i + 1]\n\n if prv == crt\n moves += 1\n gs[i] = colors.find { |c| c != prv && c != nxt }\n end\n\n end\n\n puts moves\n puts gs.join('')\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"}], "negative_code": [], "src_uid": "ddaf86169a79942cefce8e5b5f3d6118"} {"source_code": "line_one = $stdin.gets\nline_two= $stdin.gets\n\nh1, a1, c1 = line_one.split.map(&:to_i)\nh2, a2 = line_two.split.map(&:to_i)\n\nactions = Array.new\nwhile h2 > 0\n if h1 > a2 || a1 >= h2\n actions << 'STRIKE'\n h2 -= a1\n else\n actions << 'HEAL'\n h1 += c1\n end\n h1 -= a2\nend\n\nputs actions.length\nputs actions\n", "positive_code": [{"source_code": "h1, a1, c1 = gets.split.map(&:to_i)\nh2, a2 = gets.split.map(&:to_i)\ns = (h2 - 1) / a1\nh = a2 * s < h1 ? 0 : (a2 * s - h1) / (c1 - a2) + 1\np s + h + 1\nh.times {puts 'HEAL'}\n(s + 1).times {puts 'STRIKE'}"}, {"source_code": "h, a, c=gets.split.map &:to_i\ng, b=gets.split.map &:to_i\nres=[]\nwhile g>0\n if h-b<=0 && g-a>0\n res<<\"HEAL\"\n h+=c\n else\n res<<\"STRIKE\"\n g-=a\n end\n h-=b\nend\nputs res.size, res\n"}, {"source_code": "h,a,c=gets.split.map &:to_i\ng,b=gets.split.map &:to_i\nk=(g+a-1)/a\nn=[(b*(k-1)-h)/(c-b)+1,0].max\nputs n+k,[:HEAL]*n,[:STRIKE]*k"}, {"source_code": "hac = gets.chomp.split.map(&:to_i)\nh = hac[0]\na = hac[1]\nc = hac[2]\nha = gets.chomp.split.map(&:to_i)\nh2 = ha[0]\na2 = ha[1]\n\narr = []\nwhile h2-a > 0\n\tif h - a2 > 0 \n\t\tarr << \"STRIKE\"\n\t\th2 -= a\n\telse\n\t\tarr << \"HEAL\"\n\t\th += c\n\tend\n\tif h2 > 0\n\t\th -= a2\n\tend\nend\n\nputs arr.size+1\nfor n in arr\n\tputs n\nend\nprint \"STRIKE\""}, {"source_code": "#!/usr/bin/env ruby\n\nh1, a1, c1 = gets.split.map{|x| x.to_i}\nh2, a2 = gets.split.map{|x| x.to_i}\n\n$cnt = 0\n$moves = []\nwhile h2 > 0 do\n\t$cnt += 1\n\tif h1 <= a2 and a1 < h2 then \n\t\t$moves.push(\"HEAL\")\n\t\th1 += c1\n\telse\n\t\t$moves.push(\"STRIKE\")\n\t\th2 -= a1\n\tend\n\n\th1 -= a2\nend \n\nputs $cnt\nputs $moves.join(\"\\n\")\n\n"}], "negative_code": [{"source_code": "line_one = $stdin.gets\nline_two= $stdin.gets\n\nh1, a1, c1 = line_one.split.map(&:to_i)\nh2, a2 = line_two.split.map(&:to_i)\n\nactions = Array.new\nwhile h2 > 0\n if h1 > a2\n actions << 'STRIKE'\n h2 -= a1\n else\n actions << 'HEAL'\n h1 += c1\n end\n h1 -= a2\nend\n\nputs actions.length\nputs actions\n"}, {"source_code": "line_one = $stdin.gets\nline_two= $stdin.gets\n\nh1, a1, c1 = line_one.split.map(&:to_i)\nh2, a2 = line_two.split.map(&:to_i)\n\nactions = Array.new\nwhile h2 > 0\n if h1 > a2\n actions << 'STRIKE'\n h2 -= a1\n else\n actions << 'HEAL'\n h1 += c1\n end\n if h2 <= 0\n break\n end\n h1 -= a2\nend\n\nputs actions.length\nputs actions\n"}, {"source_code": "h, a, c=gets.split.map &:to_i\ng, b=gets.split.map &:to_i\nres=[]\nwhile g>0\n if h-b<=0\n res<<\"HEAL\"\n h+=c\n else\n res<<\"STRIKE\"\n g-=a\n end\n h-=b\nend\nputs res.size, res\n"}, {"source_code": "hac = gets.chomp.split.map(&:to_i)\nh = hac[0]\na = hac[1]\nc = hac[2]\nha = gets.chomp.split.map(&:to_i)\nh2 = ha[0]\na2 = ha[1]\n\narr = []\nwhile h2 > 0\n\tif h - a2 > 0\n\t\tarr << \"STRIKE\"\n\t\th2 -= a\n\t\th -= a2\n\telse\n\t\tarr << \"HEAL\"\n\t\th += c\n\t\th -= a\n\tend\nend\n\nputs arr.size\nfor n in arr\n\tputs n\nend"}, {"source_code": "hac = gets.chomp.split.map(&:to_i)\nh = hac[0]\na = hac[1]\nc = hac[2]\nha = gets.chomp.split.map(&:to_i)\nh2 = ha[0]\na2 = ha[1]\n\narr = []\nwhile h2 > 0\n\tif h/a2 >= h2/a && h - a2 > 0\n\t\tarr << \"STRIKE\"\n\t\th2 -= a\n\t\th -= a2\n\telse\n\t\tarr << \"HEAL\"\n\t\th += c\n\t\th -= a2\n\tend\nend\n\nputs arr.size\nfor n in arr\n\tputs n\nend"}, {"source_code": "hac = gets.chomp.split.map(&:to_i)\nh = hac[0]\na = hac[1]\nc = hac[2]\nha = gets.chomp.split.map(&:to_i)\nh2 = ha[0]\na2 = ha[1]\n\narr = []\nwhile h2 > 0\n\tif h/a2 > h2/a || h - a2 > 0\n\t\tarr << \"STRIKE\"\n\t\th2 -= a\n\t\th -= a2\n\telse\n\t\tarr << \"HEAL\"\n\t\th += c - a2\n\tend\nend\n\nputs arr.size\nfor n in arr\n\tputs n\nend"}, {"source_code": "#!/usr/bin/env ruby\n\nh1, a1, c1 = gets.split.map{|x| x.to_i}\nh2, a2 = gets.split.map{|x| x.to_i}\n\n$cnt = 0\n$moves = []\nwhile h2 > 0 do\n\t$cnt += 1\n\tif h1 <= a2 then \n\t\t$moves.push(\"HEAL\")\n\t\th1 += c1\n\telse\n\t\t$moves.push(\"STRIKE\")\n\t\th2 -= a1\n\tend\n\n\th1 -= a2\nend \n\nputs $cnt\nputs $moves.join(\"\\n\")\n\n"}, {"source_code": "h1, a1, c1 = gets.split.map(&:to_i)\nh2, a2 = gets.split.map(&:to_i)\ns = (h2 - 1) / a1\nh = a2 * s < h1 ? 0 : (a2 * s - h1) / c1 + 1\np s + h + 1\nh.times {puts 'HEAL'}\n(s + 1).times {puts 'STRIKE'}\n"}], "src_uid": "d497431eb37fafdf211309da8740ece6"} {"source_code": "require 'set'; require 'prime'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n a,b,c = gets.chomp.split.map(&:to_i).sort.reverse\n ans = 0\n if a > 0\n ans += 1\n a-=1\n end\n if b > 0\n ans += 1\n b-=1\n end\n if c > 0\n ans += 1\n c-=1\n end\n\n if a > 0 && b > 0\n ans += 1\n a-=1\n b-=1\n end\n if a > 0 && c > 0\n ans += 1\n a-=1\n c-=1\n end\n if b > 0 && c > 0\n ans += 1\n b-=1\n c-=1\n end\n\n if a > 0 && b > 0 && c > 0\n ans += 1\n end\n puts ans\nend\n", "positive_code": [{"source_code": "\n\n\ndef Solve()\n a,b,c=gets.chomp.split.map(&:to_i).sort.reverse\n ans=0\n if a>=1\n ans+=1\n a-=1\n end\n if b>=1\n ans+=1\n b-=1\n end\n if c>=1\n ans+=1\n c-=1\n end\n\n if a>=1 && b>=1\n ans+=1\n a-=1\n b-=1\n end\n if b>=1 && c>=1\n ans+=1\n b-=1\n c-=1\n end\n if c>=1 && a>=1\n ans+=1\n c-=1\n a-=1\n end\n\n if a>=1 && b>=1 && c>=1\n ans+=1\n end\n puts ans\nend\n\ngets.to_i.times do\n Solve()\nend\n"}, {"source_code": "def try_consume(a,b,c)\n return 0 if $a < a || $b < b || $c < c\n $a -= a\n $b -= b\n $c -= c\n 1\nend\n\ndef solve\n $a, $b, $c = gets.split.map{|x| x.to_i}.sort\n ans = 0\n ans += try_consume(1,0,0)\n ans += try_consume(0,1,0)\n ans += try_consume(0,0,1)\n ans += try_consume(1,0,1)\n ans += try_consume(0,1,1)\n ans += try_consume(1,1,0)\n ans += try_consume(1,1,1)\n puts ans\nend\n\nt = gets.to_i\nt.times { solve }\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n a, b, c = gets.split.map(&:to_i)\n\n cnt = 0\n\n if a > 0\n a -= 1\n cnt += 1\n end\n\n if b > 0\n b -= 1\n cnt += 1\n end\n\n if c > 0\n c -= 1\n cnt += 1\n end\n\n nums = [a, b, c].sort\n\n if nums[0] > 0 && nums[2] > 0\n nums[0] -= 1\n nums[2] -= 1\n cnt += 1\n end\n\n if nums[1] > 0 && nums[2] > 0\n nums[1] -= 1\n nums[2] -= 1\n cnt += 1\n end\n\n if nums[0] > 0 && nums[1] > 0\n nums[0] -= 1\n nums[1] -= 1\n cnt += 1\n end\n\n if nums.all? { |n| n > 0 }\n cnt += 1\n end\n\n puts cnt\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n ans = 0\n a, b, c = gets.split.map(&:to_i).sort.reverse\n if a >= 1\n ans += 1\n a -= 1\n end\n if b >= 1\n ans += 1\n b -= 1\n end\n if c >= 1\n ans += 1\n c -= 1\n end\n if a >= 1 && b >= 1\n ans += 1\n a -= 1\n b -= 1\n end\n if b >= 1 && c >= 1\n ans += 1\n b -= 1\n c -= 1\n end\n if c >= 1 && a >= 1\n ans += 1\n c -= 1\n a -= 1\n end\n if a >= 1 && b >= 1 && c >= 1\n ans += 1\n a -= 1\n b -= 1\n c -= 1\n end\n puts ans\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n d = gets.chomp.split.map(&:to_i).sort.reverse\n\n ans = 0\n [1, 2, 4, 3, 5, 6, 7].each do |i|\n f = true\n 3.times do |j|\n if i & (1 << j) > 0 && d[j] == 0\n f = false\n break\n end\n end\n\n if f\n ans += 1\n\n 3.times do |j|\n d[j] -= 1 if i & (1 << j) > 0\n end\n end\n end\n puts ans\nend"}], "negative_code": [], "src_uid": "98a8fc06e8265bbf9c16ee3c7b9d0223"} {"source_code": "n, m = gets.chomp.split(\" \").map(&:to_i)\nx = 1000000000\nfor i in 0..m-1\n li, ri = gets.chomp.split(\" \").map(&:to_i)\n x = [ri - li+1, x].min\nend\nputs x\nfor i in 0..n-1\n print (i%x), \" \"\nend\n", "positive_code": [{"source_code": "# be name khoda ...\ndef read_ints; STDIN.gets.split.map(&:to_i); end\nn,m = read_ints\na = Array.new\nmin = -1\nm.times{\n l,r = read_ints\n if(min == -1 || r - l + 1 < min) \n min = r-l+1 \n end\n}\nputs min\ncur = 0\nn.times {\n if(cur >= min)\n cur = 0\n end\n print \"#{cur} \"\n cur+=1\n}"}], "negative_code": [{"source_code": "n, m = gets.chomp.split(\" \").map(&:to_i)\nx = 1000000000\nfor i in 0..m-1\n li, ri = gets.chomp.split(\" \").map(&:to_i)\n x = [ri - li+1, x].min\nend\nputs x\nfor i in 0..n-1\n print (i%x)\nend\n"}], "src_uid": "317891277a5393758bd3c8f606769070"} {"source_code": "n = gets.to_i\nn.times do\n num = 0\n a = gets.split.map(&:to_i)\n a.reverse! if a[0] > a[1]\n until a[0] == 0\n num += a[1]/a[0]\n a[1] %= a[0]\n a.reverse!\n end\n puts num\nend", "positive_code": [{"source_code": "def num (a, b)\n result = 0\n while a > 0 && b > 0 do\n if b > a then\n result += b/a\n b -= b - (b % a)\n else \n result += a/b\n a -= a - (a % b)\n end\n end\n return result\nend\n\nn = gets.to_i\n\npair = []\nn.times do |i|\n pair << gets.split.map{|j| j.to_i}\nend\n\nn.times do |i|\n result = num(pair[i][0],pair[i][1])\n puts result\nend"}, {"source_code": "def run\n n = ARGF.readline\n ARGF.readlines.each do |s|\n a, b = s.chomp.split.map(&:to_i)\n\n cnt = 0\n while a > 0 and b > 0\n a, b = b, a if a > b\n cnt += b / a\n b = b % a\n end\n\n puts cnt\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.chomp.to_i\n(1..n).each { |k|\n\ta,b = gets.chomp.split(\" \").collect! {|x| x.to_i}\n\tp = 0\n\tif a0 and b>0\n\t\tp += a/b\n\t\taux = a%b\n\t\ta = b\n\t\tb = aux\n\tend\n\tputs p\n}\n"}, {"source_code": "gets.to_i.times {\n a,b=gets.split.map(&:to_i)\n a,b=[a,b].min,[a,b].max\n\n count=0\n while a!=0\n count+=b/a;\n a,b=b%a,a\n end\n puts count\n}\n\n"}, {"source_code": "def solve(a,b)\n\treturn 0 if a == 0 or b == 0\n\treturn solve(b,a) if a > b\n\tb/a + solve(b % a, a)\nend\n\ngets.to_i.times do\n\ta, b = gets.split.map(&:to_i)\n\tputs solve(a,b)\nend\n"}, {"source_code": "n = gets.to_i\n\nn.times do |i|\n\tt = gets.split.collect{|x| x.to_i}\n\n\ta = t.max\n\tb = t.min\n\ti = 0\n\twhile a > 0 and b > 0\n\t\ti+=a / b\n\t\tk = a%b\n\t\ta = [k,b].max\n\t\tb = [k,b].min\n\tend\n\tputs i\t\t\t\nend"}], "negative_code": [], "src_uid": "5c3eb78a7e15d9afe6d745e1a77d7451"} {"source_code": "# http://codeforces.com/contest/556/problem/A\nn = gets.chomp.to_i\ndigits = gets.chomp.chars.map { |d| d == '0' ? 1 : -1 }\n\nputs digits.inject(0, :+).abs\n", "positive_code": [{"source_code": "n = gets.to_i\ns = gets\nans = 0\nn.times { |i|\n if s[i] == '0'\n ans +=1\n else\n ans -= 1\n end\n}\nif ans < 0\n ans = -ans\nend\nprint ans"}, {"source_code": "gets\na=gets.chomp.chars\nb=[]\nans=a.size\nwhile !a.empty?\n\twhile !b.empty? && !a.empty?\n\t\tif (b.last!=a[0]) then\n\t\t\tans-=2\n\t\t\tb.pop\n\t\t\ta.shift\n\t\telse\n\t\t\tbreak\n\t\tend\n\tend\n\tb.push(a.shift)\nend\nputs ans"}, {"source_code": "t = gets.chomp.to_i\ns = gets.chomp\n\nputs t - (2*[s.count('0'),s.count('1')].min)"}, {"source_code": "def read_ints; gets.chomp.split.map(&:to_i) end\nn = read_ints[0]\nline = gets.chars\nones = line.count(\"1\")\nzeros = line.count(\"0\")\nputs (ones-zeros).abs"}, {"source_code": "n = gets.to_i\na = gets.each_char.count{|i| i == '1'}\nputs n - [ a , n - a].min * 2"}, {"source_code": "length = gets.chomp.to_i\ns = gets.chomp\nstring = s.split(\"\")\n\n# while string.include?('1') && string.include?('0')\n# \tfor i in (0..string.size-1)\n# \t\tif i != string.size-1\n# \t\t\tif (string[i].to_i == 0 && string[i+1].to_i == 1) || (string[i].to_i == 1 && string[i+1].to_i == 0)\n# \t\t\t\tstring.delete_at(i)\n# \t\t\t\tstring.delete_at(i+1)\n# \t\t\tend\n# \t\tend\n# \tend\n# end\n\nif string.count('1') != 0 && string.count('0') != 0 && length > 1\n\tif string.count('0') == string.count('1')\n\t\tputs 0\n\telsif string.count('0') > string.count('1')\n\t\tlength = length - (string.count('1') * 2)\n\t\tputs length\n\telse\n\t\tlength = length - (string.count('0') * 2)\n\t\tputs length\n\tend\nelsif (string.count('1') == 0 || string.count('0') == 0) && length > 1\n\tputs length\nelsif length <= 1\n\tputs length\nend\n\t\t"}, {"source_code": "len = gets.to_i\ns = gets\n\na = 0\nb = 0\n\nfor i in (0...len)\n\ts[i] == \"0\" ? a += 1 : b += 1\nend\n\nputs len - 2 * [a, b].min\n"}, {"source_code": "gets\ns = gets.chomp\n\nputs (s.count('1') - s.count('0')).abs\n"}, {"source_code": "gets\nputs (gets.count('0')-$_.count('1')).abs\n"}, {"source_code": "\nn = gets.chomp.to_i\nstr = gets.chomp\n\none = 0\nzero = 0\n\nfor i in (0..str.length-1)\n if str[i] == \"0\"\n zero += 1\n else\n one += 1\n end\n end\n\n puts (one-zero).abs\n\n"}, {"source_code": "stringLength = gets.chomp.to_i\nstring = gets.chomp.split('')\n\nzero = 0\none = 0\n\nstring.each do |item|\n\tif item == '1'\n\t\tone += 1\n\telse\n\t\tzero += 1\n\tend\nend\n\nputs stringLength - 2 * [zero, one].min"}, {"source_code": "gets\ns=gets\np (s.count('0')-s.count('1')).abs"}, {"source_code": "# your code goes here\n\nn = gets.to_i\ns = gets.chomp\n\na = 0\ni = 0\n\nwhile i string.count('1')\n\t\tlength = length - (string.count('1') * 2)\n\t\tputs length\n\telse\n\t\tlength = length - (string.count('0') * 2)\n\t\tputs length\n\tend\nend\n\t\t"}, {"source_code": "stringLength = gets.chomp.to_i\nstring = gets.chomp.split('')\n\ni = 0\n\n\nuntil i == string.length || string.length < 2\n#\tputs i\n#\tputs string.length\n\n\tif string[i] != string[i + 1]\n\t\t2.times {string.delete_at(i)}\n\t\ti -= 1\n\tend\t\n\n\n\ti += 1\t\nend\n\nputs string.length"}], "src_uid": "fa7a44fd24fa0a8910cb7cc0aa4f2155"} {"source_code": "require 'set'\n\np = [71, 72, 82, 83, 63]\nn = [\"Gryffindor\", \"Hufflepuff\", \"Ravenclaw\", \"Slytherin\"]\n\ns = Set.new [[0, 0, 0, 0]]\ngets\ngets.each_byte do |c| \n t = Set.new []\n next if !p.include?(c)\n s.each do |a|\n if c == 63\n for i in (0..3)\n if a[i] == a.min\n b = Array.new(a)\n b[i] += 1\n t << b\n end\n end\n else\n a[p.index(c)] += 1\n t << a \n end\n end \n \n s = t\nend\nfor i in (0..3)\n puts n[i] if s.any? {|a| a[i] == a.min}\nend", "positive_code": [{"source_code": "require 'set'\n\np = [71, 72, 82, 83]\nn = [\"Gryffindor\", \"Hufflepuff\", \"Ravenclaw\", \"Slytherin\"]\n\ns = Set.new [[0, 0, 0, 0]]\ngets\ngets.chomp.each_byte do |c| \n t = Set.new\n s.each do |a|\n if c == 63\n for i in (0..3).select { |y| a[y] == a.min }\n b = a.clone\n b[i] += 1\n t << b\n end\n else\n a[p.index(c)] += 1\n t << a \n end\n end \n \n s = t\nend\nfor i in (0..3)\n puts n[i] if s.any? {|a| a[i] == a.min}\nend"}, {"source_code": "require 'set'\n\np = [71, 72, 82, 83]\nn = [\"Gryffindor\", \"Hufflepuff\", \"Ravenclaw\", \"Slytherin\"]\n\ns = Set.new [[0, 0, 0, 0]]\ngets\ngets.chomp.each_byte do |c| \n t = Set.new []\n s.each do |a|\n if c == 63\n for i in (0..3)\n if a[i] == a.min\n b = Array.new(a)\n b[i] += 1\n t << b\n end\n end\n else\n a[p.index(c)] += 1\n t << a \n end\n end \n \n s = t\nend\nfor i in (0..3)\n puts n[i] if s.any? {|a| a[i] == a.min}\nend"}], "negative_code": [], "src_uid": "a8a3ea10c3c5003dab0e549453b63b3e"} {"source_code": "#!/usr/bin/ruby\n\nn = STDIN.readline.to_i\nheights = STDIN.readline.split.collect {|s| s.to_i }\nheights.unshift(0)\n\nboost, energy = 0, 0\n(1..n).each do |pos|\n\tenergy -= heights[pos] - heights[pos-1]\n\tif energy < 0\n\t\tboost -= energy\n\t\tenergy = 0\n\tend\nend\n\nputs boost\n", "positive_code": [{"source_code": "n, *a = gets(p).split.map(&:to_i)\nputs a.max"}, {"source_code": "n=gets\nx=gets.split.map{|e| e.to_i}\nx.shift(0)\nsum=0\nans=0\nx.inject(0){|e1,e2|\n\tsum+=(e2-e1)\n\tif sum>0 then\n\t\tans+=sum\n\t\tsum=0\n\tend\n\te2\n}\nputs ans\n\n"}, {"source_code": "n = gets.to_i\nh = gets.split.map{|s| s.to_i}\n\nputs h.max\n"}, {"source_code": "n = gets.chomp.split(' ').map(&:to_i)\n\ne = 0\ncost = 0\nlast_h = 0\n\ngets.chomp.split(' ').each do |s|\n h = s.to_i\n de = last_h - h + e\n if de < 0\n cost += de.abs\n e += de.abs\n end\n e += last_h - h\n last_h = h\nend\n\nputs cost"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == 0\n# end\n\nn = gets.to_i\nprev = 0\nenergy = 0\npeak = 0\ngets.split.map { |i|\n i = i.to_i\n energy += prev - i\n if energy < peak\n peak = energy\n end\n prev = i\n}\nif peak < 0\n puts -peak\nelse\n puts 0\nend"}, {"source_code": "#!/usr/bin/env ruby\n# coding: utf-8\n\n# $stdin = File.new('rf','r')\n\nn = readline.chomp.to_i\na = [0] + readline.chomp.split(' ').map(&:to_i)\ne,m = 0,0\n\nloop do\n cur, nex = a.shift, a.first\n if e < nex - cur\n m += nex - cur - e \n e += nex - cur - e\n end\n e += cur - nex\n break if a.size == 1\nend\n\nputs m"}, {"source_code": "n = gets.to_i\n\na = gets.chomp.split(' ').map(&:to_i)\n\nputs a.max\n"}, {"source_code": "n, *a = gets(p).split.map(&:to_i)\nputs a.max\n"}, {"source_code": "n, *a = gets(p).split.map(&:to_i)\nputs a.max\n"}, {"source_code": "r = s = d = 0\ngets.to_i\ngets.chomp.split.map(&:to_i).each { |x|\n d += r - x\n if d < 0\n s -= d\n d = 0\n end\n r = x\n}\nputs s"}, {"source_code": "#!/usr/bin/env ruby\n\nn = Integer(gets)\n\nh= gets.chomp.split(\" \").map(&:to_i)\ndollars = 0\nh.each do |h|\n\tdollars = [dollars, h].max\nend\n\nputs dollars"}, {"source_code": "#!/usr/bin/env ruby\n\nn = Integer(gets)\n\nh= gets.chomp.split(\" \").map(&:to_i)\nenergy = 0\ndollars = 0\nc_h = 0\nh.each do |h|\n\tenergy+= c_h - h\n\tc_h = h\t\n\tdollars+=[0,energy].min.abs\n\tenergy=[0,energy].max\nend\n\nputs dollars"}, {"source_code": "n, *a = gets(p).split.map(&:to_i)\nputs a.max\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |x| x.to_i }\nputs a.max"}, {"source_code": "n, *a = gets(p).split.map(&:to_i)\nputs a.max\n"}, {"source_code": "n, *a = gets(p).split.map(&:to_i)\nputs a.max\n"}, {"source_code": "n = gets\na = gets.split.map { |i| i.to_i }\nputs a.max\n"}, {"source_code": "n, *a = gets(p).split.map(&:to_i)\nputs a.max\n"}, {"source_code": "n, *a = gets(p).split.map(&:to_i)\nputs a.max"}, {"source_code": "require 'pp'\n\nn = STDIN.gets.chomp.to_i\nm = STDIN.gets.chomp.split(/ /).map(&:to_i)\n\nputs m.max\n"}, {"source_code": "n = gets.split\nputs gets.split.map(&:to_i).max"}, {"source_code": "gets\narr = gets.split.map { |x| x.to_i }\nk = arr.first\narr.shift\narr.each do |x|\n k += (x - k) if k < x\nend\nputs k\n"}, {"source_code": "n, *a = gets(p).split.map(&:to_i)\nputs a.max\n"}, {"source_code": "n, *a = gets(p).split.map(&:to_i)\nputs a.max\n"}], "negative_code": [{"source_code": "n=gets\nx=gets.split.map{|e| e.to_i}\nx.shift(0)\nsum=0\nx.inject(0){|e1,e2|\n\tsum+=(e2-e1)\n\te2\n}\nputs sum\n\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == 0\n# end\n\nn = gets.to_i\nprev = 0\nenergy = 0\ngets.split.map { |i|\n i = i.to_i\n energy += prev - i\n prev = i\n}\nif energy < 0\n puts -energy\nelse\n puts 0\nend"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == 0\n# end\n\nn = gets.to_i\nprev = 0\nenergy = 0\ngets.split.map { |i|\n i = i.to_i\n energy += prev - i\n prev = i\n}\n\nputs energy"}, {"source_code": "#!/usr/bin/env ruby\n# coding: utf-8\n\n# $stdin = File.new('rf','r')\n\nn = readline.chomp.to_i\na = [0] + readline.chomp.split(' ').map(&:to_i)\ne = 0\n\nloop do\n e += a.shift - a.first\n break if a.size == 1\nend\n\nputs [0, -e].max"}, {"source_code": "gets.to_i\nputs -gets.chomp.split.map(&:to_i).inject([0, 0]) { |a, x| a[0] += a[1] - x; a[1] = x; a }[0]"}, {"source_code": "n = gets.split\nputs gets.split.map(&:to_s).max"}], "src_uid": "d03ad531630cbecc43f8da53b02d842e"} {"source_code": "n,q = gets.chomp.split.map(&:to_i)\np = gets.chomp.split.map(&:to_i).sort\nc = [p[0]]\n1.upto(n-1) do |i|\n c[i] = c[i-1] + p[i]\nend\n#puts c.inspect\nq.times do \n x,y = gets.chomp.split.map(&:to_i)\n #puts c[n-x+y-1]\n #puts c[n-x-1]\n puts c[n-x+y-1] - (n-x-1 >= 0 ? c[n-x-1] : 0)\nend\n\n", "positive_code": [{"source_code": "n, q = gets.split.map(&:to_i)\r\nps = gets.split.map(&:to_i).sort.reverse\r\nsums = [0]\r\nps.each { |p| sums << p + sums.last }\r\nrs = []\r\nq.times do\r\n x, y = gets.split.map(&:to_i)\r\n rs << sums[x] - sums[x - y]\r\nend\r\nputs rs.join(\"\\n\")\r\n"}, {"source_code": "n, q = gets.split.map &:to_i\np = gets.split.map(&:to_i).sort\nblah = 0\nprefix_sum = []\nfor i in (0...p.size)\n blah += p[i]\n prefix_sum.push(blah)\nend\nq.times{\n x, y = gets.split.map &:to_i\n if x == n\n puts prefix_sum[-x+y-1]\n else\n puts prefix_sum[-x+y-1] - prefix_sum[-x-1]\n end\n}\n"}, {"source_code": "def solve(cs, x, y)\n cs[-x + y - 1] - cs[-x - 1] \nend\n\nn, q = gets.chomp.split.map(&:to_i)\nxs = gets.chomp.split.map(&:to_i).sort\ncs = [0]\nxs.each do |x|\n cs << x + cs[-1]\nend\n\nresults = []\n\nq.times do\n x, y = gets.chomp.split.map(&:to_i)\n results << solve(cs, x, y) \nend\n\nputs results\n"}, {"source_code": "n, q = gets.split.map(&:to_i)\r\np = gets.split.map(&:to_i).sort\r\ni = 0\r\npsum = p.map{|e| i+=e }\r\npsum.unshift(0)\r\n\r\nq.times do\r\n x, y = gets.split.map(&:to_i)\r\n\r\n puts psum[n-x+y] - psum[n-x]\r\nend\r\n"}], "negative_code": [], "src_uid": "2dc69231824db013161e4f223e25ccb9"} {"source_code": "n, k, a, b = gets.chomp.split(\" \").map(&:to_i)\ns = ''\nif a<=b\n ctr = 1\nelse\n ctr = -1\nend\na1 = [a,b].min # a1 = b\nb1 = [a,b].max #\nif b1 > k*(a1+1)\n print \"NO\"\nelse\n while(b1 - a1 > k)\n if (ctr == 1)\n s = s + \"B\"*k + \"G\"\n else\n s = s + \"G\"*k + \"B\"\n end\n b1-=k\n a1-=1\n end\n if ctr == 1\n s += \"B\"*(b1-a1)\n s += \"GB\"*a1\n else\n s += \"G\"*(b1-a1)\n s +=\"BG\"*a1\n end\n puts s\nend\n", "positive_code": [{"source_code": "n, k, g, b = gets.chomp.split.map(&:to_i)\n\ninverse = false\na = []\nif g < b \n inverse = true\n g, b = b, g\nend\n\nif (b + 1) * k < g\n puts \"NO\"\n exit\nend\n\nwhile g != b and b > 0\n cnt = [k, g - (b - 1)].min\n g -= cnt\n b -= 1\n cnt.times {a.push(true)}\n a.push(false)\nend\n\nwhile g > 0 \n g -= 1\n a.push(true)\n if b > 0\n b -= 1\n a.push(false)\n end\nend\n\nif inverse\n a.map!(&:!)\nend\n\nputs a.map {|x| x ? 'G' : 'B'}.join\n\n"}, {"source_code": "n,k,a,b=gets.split.map &:to_i\nx=?G\ny=?B\nx,y,a,b=y,x,b,a if a>b\n\nq=[b,k].min\n\nr=[]\ni=0\nwhile b>0\n if i.even?\n t=[b, q].min\n r<0\n a-=1\n end\n i+=1\nend\n\nif a<0\n puts \"NO\"\nelse\n if a>0\n r<0\n r[i]+=x\n if r[i].size>k\n puts a\n r=\"NO\"\n break\n end\n a-=1\n i+=2\n i=1 if i>=r.size\n end\n puts (r==\"NO\" ? r : r*'')\nend\n"}], "negative_code": [{"source_code": "n,k,a,b=gets.split.map &:to_i\nx=?G\ny=?B\nx,y,a,b=y,x,b,a if a>b\n\nq=[b,k].min\np=[[a/(b/q), 1].max, a, k].min\n\nr=''\ni=0\nwhile a>0 or b>0\n if i.even?\n t=[b, q].min\n r<b\n\nq=[b,k].min\n\nr=[]\ni=0\nwhile b>0\n if i.even?\n t=[b, q].min\n r<0\n a-=1\n end\n i+=1\nend\nif a<0\n puts \"NO\"\nelse\n if a>0\n r<0\n r[i] << x\n if r[i].size>k\n r=\"NO\"\n break\n end\n a-=1\n i=(i+2) % r.size\n end\n puts (r==\"NO\" ? r : r*'')\nend\n"}], "src_uid": "2a14f4a526ad2237b897102bfa298003"} {"source_code": "def gcd(a,b)\nif b == 0\n return a;\nelse\n return gcd(b, a % b);\nend\nend\n\nn,m = gets.split(\" \").map(&:to_i)\na = gets.split(\" \").map(&:to_i)\nb = gets.split(\" \").map(&:to_i)\n\nsign = nil\nans = nil\nif n > m\n\tans = \"Infinity\"\n\tsign = \"-\" if (a[0]/b[0]) < 0\nelsif n < m\n\tans = \"0/1\"\n\t# sign = \"-\" if (a[0]/b[0]) < 0\nelse\n\tnum = a[0]\n\tden = b[0]\n\tif num < den\n\t\ta,b = den,num \n\telse\n\t\ta,b = num,den\n\tend\n\tgc = gcd(a,b)\n\tnum /= gc\n\tden /= gc\n\tans = \"#{num.abs}/#{den.abs}\"\n\t# puts \"here\"\n\tsign = \"-\" if (num/den) < 0\nend\n\n\n\nputs \"#{sign}#{ans}\"\n\n# https://en.wikipedia.org/wiki/Limit_of_a_function\n# Rational functions\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\ndef gcd(a, b)\n\treturn (b != 0) ? gcd(b, a % b) : a\nend\n\nwhile line = gets\n\tm, n = line.split.map(&:to_i)\n\tas = gets.split.map(&:to_i)\n\tbs = gets.split.map(&:to_i)\n\tif m > n\n\t\tputs (as[0] * bs[0] < 0) ? \"-Infinity\" : \"Infinity\"\n\telsif m < n\n\t\tputs \"0/1\"\n\telse\n\t\tp = as[0]\n\t\tq = bs[0]\n\t\tg = gcd(p, q);\n\t\tp /= g\n\t\tq /= g\n\t\tif q < 0\n\t\t\tp *= -1\n\t\t\tq *= -1\n\t\tend\n\t\tputs \"#{p}/#{q}\"\n\tend\nend\n"}, {"source_code": "# cook your code here\n\nn,m = gets.split.map{ |x| x.to_i } \n\nfirst = gets.split.map{ |x| x.to_i } \nsecond = gets.split.map{ |x| x.to_i } \n\nif n>m\n if first[0]*second[0]>0 \n puts \"Infinity\" \n else \n puts \"-Infinity\" \n end \nelsif n m\n\tif p.last.to_i * q.last.to_i > 0\n\t\tprint \"Infinity\\n\"\n\telse\n\t\tprint \"-Infinity\\n\"\n\tend\nelsif n == m\n\ta, b = p.last.to_i, q.last.to_i\n\tif a * b > 0\n\t\tif a < 0\n\t\t\ta, b = -a, -b\n\t\tend\n\t\tg = gcd(a, b)\n\t\tprint \"%d/%d\\n\" % [a / g, b / g]\n\telse\n\t\tif a < 0\n\t\t\ta = -a\n\t\tend\n\t\tif b < 0\n\t\t\tb = -b\n\t\tend\n\t\tg = gcd(a, b)\n\t\tprint \"-%d/%d\\n\" % [a / g, b / g]\n\tend\nelse\n\tprint \"0/1\\n\"\nend\n"}, {"source_code": "n,m = gets.split.map{|e| e.to_i}\na1 = gets.split.map{|e| e.to_i}\na2 = gets.split.map{|e| e.to_i}\nif m>n\n puts \"0/1\"\n exit\nend\nif n>m\n k = a1[0]*a2[0]\n if k>0 then puts \"Infinity\" else puts \"-Infinity\" end\n exit \nend\nif a2[0]<0\n a2[0]*=-1\n a1[0]*=-1\nend\n\ng = a1[0].gcd(a2[0])\nputs \"#{a1[0]/g}/#{a2[0]/g}\"\n"}, {"source_code": "require 'mathn'\n\nn, m = gets.split.map(&:to_i)\npn = gets.split.first.to_i\nqm = gets.split.first.to_i\n\nsign = pn/qm < 0\n\nif n > m\n puts \"#{sign ? \"-\" : \"\"}Infinity\"\nelsif n < m\n puts \"0/1\"\nelse\n divs_p = pn.abs.prime_division Prime::TrialDivisionGenerator.new\n divs_q = qm.abs.prime_division Prime::TrialDivisionGenerator.new\n divs_p.each_with_index do |d, ip|\n l = divs_q.assoc d.first\n if l\n iq = divs_q.index l\n delta = [d.last, l.last].min\n divs_p[ip] = [d.first, d.last - delta]\n divs_q[iq] = [d.first, l.last - delta]\n end\n end\n\n puts \"#{sign ? \"-\" : \"\"}#{Integer.from_prime_division divs_p }/#{Integer.from_prime_division divs_q }\"\nend\n"}, {"source_code": "n,m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\n\nif n==m\n g = a[0].gcd(b[0])\n if b[0]<0 then a[0], b[0] = -a[0], -b[0] end\n print a[0]/g,'/',b[0]/g\nelsif n>m\n print (a[0]*b[0]<0 ? \"-\" :\"\"),\"Infinity\"\nelsif nm\n print (a[0]*b[0]<0 ? \"-\" :\"\"),\"Infinity\"\nelsif nm\n if n*m>0 \n puts \"Infinity\" \n else \n puts \"-Infinity\" \n end \nelsif n m\n\tif p.last.to_i > 0\n\t\tprint \"Infinity\\n\"\n\telse\n\t\tprint \"-Infinity\\n\"\n\tend\nelsif n == m\n\ta, b = p.last.to_i, q.last.to_i\n\tif a * b > 0\n\t\tif a < 0\n\t\t\ta, b = -a, -b\n\t\tend\n\t\tg = gcd(a, b)\n\t\tprint \"%d/%d\\n\" % [a / g, b / g]\n\telse\n\t\tif a < 0\n\t\t\ta = -a\n\t\tend\n\t\tif b < 0\n\t\t\tb = -b\n\t\tend\n\t\tg = gcd(a, b)\n\t\tprint \"-%d/%d\\n\" % [a / g, b / g]\n\tend\nelse\n\tprint \"0/1\\n\"\nend\n"}, {"source_code": "require 'mathn'\n\nn, m = gets.split.map(&:to_i)\npn = gets.split.first.to_i\nqm = gets.split.first.to_i\n\nif n > m\n puts \"#{pn < 0 ? \"-\" : \"\"}Infinity\"\nelsif n < m\n puts \"#{qm < 0 ? \"-\" : \"\"}0/1\"\nelse\n sign = pn/qm < 0\n divs_p = pn.abs.prime_division Prime::EratosthenesGenerator.new\n divs_q = qm.abs.prime_division Prime::EratosthenesGenerator.new\n divs_p.each_with_index do |d, ip|\n l = divs_q.assoc d.first\n if l\n iq = divs_q.index l\n delta = [d.last, l.last].min\n divs_p[ip] = [d.first, d.last - delta]\n divs_q[iq] = [d.first, l.last - delta]\n end\n end\n\n puts \"#{sign ? \"-\" : \"\"}#{Integer.from_prime_division divs_p }/#{Integer.from_prime_division divs_q }\"\nend\n"}, {"source_code": "require 'mathn'\n\nn, m = gets.split.map(&:to_i)\npn = gets.split.first.to_i\nqm = gets.split.first.to_i\n\nif n > m\n puts \"#{pn < 0 ? \"-\" : \"\"}Infinity\"\nelsif n < m\n puts \"#{qm < 0 ? \"-\" : \"\"}0/1\"\nelse\n sign = pn/qm < 0\n divs_p = pn.abs.prime_division\n divs_q = qm.abs.prime_division\n divs_p.each_with_index do |d, ip|\n l = divs_q.assoc d.first\n if l\n iq = divs_q.index l\n delta = [d.last, l.last].min\n divs_p[ip] = [d.first, d.last - delta]\n divs_q[iq] = [d.first, l.last - delta]\n end\n end\n\n puts \"#{sign ? \"-\" : \"\"}#{Integer.from_prime_division divs_p }/#{Integer.from_prime_division divs_q }\"\nend\n"}, {"source_code": "require 'mathn'\n\nn, m = gets.split.map(&:to_i)\npn = gets.split.first.to_i\nqm = gets.split.first.to_i\n\nif n > m\n puts \"#{pn < 0 ? \"-\" : \"\"}Infinity\"\nelsif n < m\n puts \"0/1\"\nelse\n sign = pn/qm < 0\n divs_p = pn.abs.prime_division Prime::TrialDivisionGenerator.new\n divs_q = qm.abs.prime_division Prime::TrialDivisionGenerator.new\n divs_p.each_with_index do |d, ip|\n l = divs_q.assoc d.first\n if l\n iq = divs_q.index l\n delta = [d.last, l.last].min\n divs_p[ip] = [d.first, d.last - delta]\n divs_q[iq] = [d.first, l.last - delta]\n end\n end\n\n puts \"#{sign ? \"-\" : \"\"}#{Integer.from_prime_division divs_p }/#{Integer.from_prime_division divs_q }\"\nend\n"}, {"source_code": "require 'mathn'\n\nn, m = gets.split.map(&:to_i)\npn = gets.split.first.to_i\nqm = gets.split.first.to_i\n\nif n > m\n puts \"#{pn < 0 ? \"-\" : \"\"}Infinity\"\nelsif n < m\n puts \"#{qm < 0 ? \"-\" : \"\"}0/1\"\nelse\n sign = pn/qm < 0\n divs_p = pn.abs.prime_division\n divs_q = qm.abs.prime_division\n divs_p.each_with_index do |d, ip|\n l = divs_q.assoc d.first\n if l\n iq = divs_q.index l\n delta = (d.last - l.last).abs\n divs_p[ip] = [d.first, d.last - delta]\n divs_q[iq] = [d.first, l.last - delta]\n end\n end\n\n puts \"#{sign ? \"-\" : \"\"}#{Integer.from_prime_division divs_p }/#{Integer.from_prime_division divs_q }\"\nend\n"}, {"source_code": "require 'mathn'\n\nn, m = gets.split.map(&:to_i)\npn = gets.split.first.to_i\nqm = gets.split.first.to_i\n\nif n > m\n puts \"#{pn < 0 ? \"-\" : \"\"}Infinity\"\nelsif n < m\n puts \"#{qm < 0 ? \"-\" : \"\"}0/1\"\nelse\n sign = pn/qm < 0\n divs_p = pn.abs.prime_division Prime::TrialDivisionGenerator.new\n divs_q = qm.abs.prime_division Prime::TrialDivisionGenerator.new\n divs_p.each_with_index do |d, ip|\n l = divs_q.assoc d.first\n if l\n iq = divs_q.index l\n delta = [d.last, l.last].min\n divs_p[ip] = [d.first, d.last - delta]\n divs_q[iq] = [d.first, l.last - delta]\n end\n end\n\n puts \"#{sign ? \"-\" : \"\"}#{Integer.from_prime_division divs_p }/#{Integer.from_prime_division divs_q }\"\nend\n"}, {"source_code": "def gcd(a,b)\nif b == 0\n return a;\nelse\n return gcd(b, a % b);\nend\nend\n\nn,m = gets.split(\" \").map(&:to_i)\na = gets.split(\" \").map(&:to_i)\nb = gets.split(\" \").map(&:to_i)\n\nsign = nil\nans = nil\nif n > m\n\tans = \"Infinity\"\n\tsign = \"-\" if (a[0]/b[0]) < 0\nelsif n < m\n\tans = \"0/1\"\n\tsign = \"-\" if (a[0]/b[0]) < 0\nelse\n\tnum = a[0]\n\tden = b[0]\n\tif num < den\n\t\ta,b = den,num \n\telse\n\t\ta,b = num,den\n\tend\n\tgc = gcd(a,b)\n\tnum /= gc\n\tden /= gc\n\tans = \"#{num}/#{den}\"\n\t# puts \"here\"\n\t# sign = \"-\" if (num/den) < 0\nend\n\n\n\nputs \"#{sign}#{ans}\"\n\n# https://en.wikipedia.org/wiki/Limit_of_a_function\n# Rational functions\n"}, {"source_code": "def gcd(a,b)\nif b == 0\n return a;\nelse\n return gcd(b, a % b);\nend\nend\n\nn,m = gets.split(\" \").map(&:to_i)\na = gets.split(\" \").map(&:to_i)\nb = gets.split(\" \").map(&:to_i)\n\nsign = nil\nans = nil\nif n > m\n\tans = \"Infinity\"\n\tsign = \"-\" if (a[0]/b[0]) < 0\nelsif n < m\n\tans = \"0/1\"\n\t# sign = \"-\" if (a[0]/b[0]) < 0\nelse\n\tnum = a[0]\n\tden = b[0]\n\tif num < den\n\t\ta,b = den,num \n\telse\n\t\ta,b = num,den\n\tend\n\tgc = gcd(a,b)\n\tnum /= gc\n\tden /= gc\n\tans = \"#{num}/#{den}\"\n\t# puts \"here\"\n\t# sign = \"-\" if (num/den) < 0\nend\n\n\n\nputs \"#{sign}#{ans}\"\n\n# https://en.wikipedia.org/wiki/Limit_of_a_function\n# Rational functions\n"}, {"source_code": "def gcd(x,y)\n return x==0?y:gcd(y%x, x)\nend\n\nn,m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\n\nif n==m\n g = gcd(a[0].abs, b[0].abs)\n if b[0]<0 then a[0], b[0] = -a[0], -b[0] end\n print a[0]/g,'/',b[0]/g\nelsif n>m\n print (a[0]<0?\"-\":\"\"),\"Infinity\"\nelsif n 0\n if arr[row][column]\n if odd.size > 0\n print odd.pop\n else\n print 0\n end\n else\n if even.size > 0\n print even.pop\n else\n print 0\n end\n end\n end\n puts()\nend\n"}, {"source_code": "g = gets.split(\" \")\nn,a,b=g[0].to_i,g[1].to_i,g[2].to_i\nif n>a*b\n\tputs -1\nelse\n\tf=Array.new(a)\n\tfor i in 0..a-1\n\t\tf[i] = Array.new(b, 0)\n\tend\n\tx=y=0\n\tdir=c=1\n\twhile x=b\n\t\t\ty-=dir\n\t\t\tx+=1\n\t\t\tdir*=-1 \n\t\tend\n\tend\n\tfor i in 0..a-1\n\t\tputs f[i].join(\" \")\n\tend\nend"}, {"source_code": "array_as_string = gets\nn, a, b = array_as_string.split.map(&:to_i)\nif ((a * b + 1) / 2 < (n + 1) / 2)\n puts -1\nelse\n oddidx = 0\n evenidx = 0\n 1.upto a do |row|\n arr = []\n 1.upto b do |column|\n if ((row + column) % 2 == 0)\n if (oddidx < (n + 1) / 2)\n arr << (oddidx * 2 + 1)\n oddidx = oddidx + 1\n else \n arr << 0\n end\n else\n if (evenidx < n / 2)\n evenidx = evenidx + 1\n arr << evenidx * 2\n else \n arr << 0\n end\n end\n end\n puts arr.join(\" \")\n end\nend"}, {"source_code": "n,a,b = gets.split.map(&:to_i)\nres = ''\nans = []\nif n>a*b\n p -1\nelse\n if b.odd?\n for i in (0..(a-1))\n for j in (0..(b-1))\n res+=n.to_s+' '\n if (n > 0)\n n-=1\n end\n end\n puts res\n res=''\n end\n else\n for i in (0..(a-1))\n if i.odd?\n for j in (0..(b-1))\n ans[b-1-j] = n\n if (n > 0)\n n-=1\n end\n end\n else\n for j in (0..(b-1))\n ans[j] = n\n if (n > 0)\n n-=1\n end\n end\n end\n puts ans.join(' ')\n ans.clear\n end\n end\nend"}], "negative_code": [{"source_code": "n, a, b = gets.split.map(&:to_i)\nres = ''\ntemp = []\ntemp.push(0)\nif (n > a*b)\n p -1\nelse\n if b.odd?\n for i in (0..(a-1))\n for j in (0..(b-1))\n res+=n.to_s+' '\n if (n > 0)\n n-=1\n end\n end\n puts res\n res=''\n end\n else\n for i in (0..(a-1))\n for j in (0..(b-1))\n if ((n == 0) and (temp != []))\n res+=temp[0].to_s+' '\n temp.delete(temp[0])\n else\n res+=n.to_s+' '\n end\n if (n > 0)\n n-=1\n end\n end\n if (n > 0)\n temp.push(n)\n n-=1\n end\n puts res\n res=''\n end\n end\nend"}], "src_uid": "6e0dafeaf85e92f959c388c72e158f68"} {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i).sort\n\n puts a[n] - a[n - 1]\nend\n", "positive_code": [{"source_code": "n = gets.to_i\narr = []\nnums = []\nn.times do\n nums << gets.to_i\n arr << gets.split.map(&:to_i).sort\nend\n\narr.each_with_index do |ar, i|\n puts ar[nums[i]] - ar[nums[i] - 1]\nend"}], "negative_code": [], "src_uid": "adb0f6082367dc432e2e096c64f13a56"} {"source_code": "n = gets.to_i\na = Array.new(n)\nw = 0\nh = 0\ns1 = 0\ns2 = 0\nb = Array.new(n, 0)\nc = Array.new(n, 0)\nn.times{|i|\n a[i] = gets.split.map(&:to_i)\n n.times{|j|\n if a[i][j] == 0\n w = j\n h = i\n end\n if i == j\n s1 += a[i][j]\n end\n if i + j == n - 1\n s2 += a[i][j]\n end\n b[i] += a[i][j]\n c[j] += a[i][j]\n }\n }\nif h == 0\n if n == 1\n p 1 \n exit\n end\n sum = b[1]\nelse\n sum = b[0]\nend\nn.times{|i|\n if i != h && sum != b[i]\n p -1 \n exit\n end\n }\nn.times{|i|\n if i != w && sum != c[i]\n p -1 \n exit\n end\n }\ntmp1 = b[h]\ntmp2 = c[w]\nif tmp1 == tmp2 && sum > tmp1\n if w == h\n if s1 != tmp1\n p -1\n exit\n end\n elsif s1 != sum\n p -1\n exit\n end\n if w + h == n - 1\n if s2 != tmp1\n p -1\n exit\n end\n elsif s2 != sum\n p -1\n exit\n end\n p sum - tmp1\nelse\n p -1\nend", "positive_code": [{"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nsum_row, sum_col, sum_dia = Array.new(n, 0), Array.new(n, 0), Array.new(2, 0)\nx, y = 0, 0\nn.times do |i|\n n.times do |j|\n sum_row[i] += a[i][j]\n sum_col[j] += a[i][j]\n sum_dia[0] += a[i][j] if i == j\n sum_dia[1] += a[i][j] if i + j == n - 1\n x, y = i, j if a[i][j] == 0\n end\nend\ncandidate = ( sum_row.uniq.last - sum_row.uniq.first ).abs\nif n == 1\n puts 1\nelse\n sum_row[x] += candidate\n sum_col[y] += candidate\n sum_dia[0] += candidate if x == y\n sum_dia[1] += candidate if x + y == n - 1\n possible = candidate != 0 && \n sum_row.uniq.size == 1 &&\n sum_col.uniq.size == 1 &&\n sum_dia.uniq.size == 1 &&\n sum_row.first == sum_col.first &&\n sum_col.first == sum_dia.first\n puts possible ? candidate : -1\nend\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nsum_row = Array.new(n, 0)\nsum_col = Array.new(n, 0)\nsum_dia = Array.new(2, 0)\nx, y = nil, nil\nn.times do |i|\n n.times do |j|\n cur = a[i][j]\n sum_row[i] += cur\n sum_col[j] += cur\n sum_dia[0] += cur if i == j\n sum_dia[1] += cur if i + j == n - 1\n x, y = i, j if cur == 0\n end\nend\nans = (sum_row.uniq.last - sum_row.uniq.first).abs\nif n == 1\n puts 1437\nelse\n sum_row[x] += ans\n sum_col[y] += ans\n sum_dia[0] += ans if x == y\n sum_dia[1] += ans if x + y == n - 1\n valid = ans != 0 && (sum_row + sum_col + sum_dia).uniq.size == 1\n puts valid ? ans : -1\nend\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nsum_row, sum_col, sum_dia = Array.new(n, 0), Array.new(n, 0), Array.new(2, 0)\nx, y = 0, 0\nn.times do |i|\n n.times do |j|\n sum_row[i] += a[i][j]\n sum_col[j] += a[i][j]\n sum_dia[0] += a[i][j] if i == j\n sum_dia[1] += a[i][j] if i + j == n - 1\n x, y = i, j if a[i][j] == 0\n end\nend\ncandidate = ( sum_row.uniq.last - sum_row.uniq.first ).abs\nif n == 1\n puts 1\nelse\n sum_row[x] += candidate\n sum_col[y] += candidate\n sum_dia[0] += candidate if x == y\n sum_dia[1] += candidate if x + y == n - 1\n possible = candidate != 0 && \n sum_row.uniq.size == 1 &&\n sum_col.uniq.size == 1 &&\n sum_dia.uniq.size == 1 &&\n sum_row.first == sum_col.first &&\n sum_col.first == sum_dia.first\n puts possible ? candidate : -1\nend\n"}, {"source_code": "#!/usr/bin/ruby\ndef chk(m)\n\tn=m.size\n\tx=y=0\n\tn.times{|i|\n\t\tx+=m[i][i]\n\t\ty+=m[i][n-i-1]\n\t}\n\t(\n\t\t[x]+[y]+\n\t\tm.map{|e|e.reduce(:+)}+\n\t\tm.transpose.map{|e|e.reduce(:+)}\n\t).group_by{|e|e}\nend\n\nn=gets.to_i\nif n==1\n\tp 1\nelse\n\tm=$<.map{|e|e.split.map(&:to_i)}\n\ta=chk(m)\n\tif a.size!=2\n\t\tp -1\n\telse\n\t\tk=-a.map(&:first).minmax.reduce(:-)\n\t\tn.times{|i|n.times{|j|\n\t\t\tm[i][j]=k if m[i][j]==0\n\t\t}}\n\t\ta=chk(m)\n\t\tp a.size!=1 ? -1 : k\n\tend\nend"}, {"source_code": "# http://codeforces.com/contest/711/problem/B\nn = gets.chomp.to_i\nrows = [].tap do |a|\n n.times { a << gets.chomp.split.map(&:to_i) }\nend\narr = rows.tap do |a|\n # cols\n (0...n).each { |i| a << (0...n).map { |j| rows[j][i] } }\n # diagonal\n a << (0...n).map { |i| rows[i][i] }\n a << (0...n).map { |i| rows[n - i - 1][i] }\nend\nnot_filled, filled = arr.partition { |a| a.include?(0) }\nsum_of_not_filled = not_filled.map { |a| a.inject(0, :+) }.uniq\nsum_of_filled = filled.map { |a| a.inject(0, :+) }.uniq\nif n == 1\n puts 1\nelsif sum_of_filled.length == 1 && sum_of_not_filled.length == 1\n diff = sum_of_filled.first - sum_of_not_filled.first\n puts diff > 0 ? diff : -1\nelse\n puts -1\nend\n"}, {"source_code": "def magic_grid?( grid )\n n = grid.length\n sum_rows = Array.new(n, 0)\n sum_cols = Array.new(n, 0)\n sum_diag_left = sum_diag_right = 0\n n.times do |i|\n n.times do |j|\n sum_rows[i] += grid[i][j]\n sum_cols[i] += grid[j][i]\n end\n sum_diag_right += grid[i][i]\n sum_diag_left += grid[i][n - i - 1]\n end\n return false if sum_rows.uniq.length != 1 || sum_cols.uniq.length != 1\n sum_cols[0] == sum_rows[0] && sum_rows[0] == sum_diag_left && sum_diag_left == sum_diag_right\nend\nn = gets.strip.to_i\ngrid = Array.new(n) { Array.new(n, 0) }\nmissing_pos = Array.new(2, 0)\nin_left_diag = false\nin_right_diag = false\nif n == 1\n puts 1\nelse\n n.times do |i|\n grid[i] = gets.strip.split.map(&:to_i)\n j = grid[i].each_index.select { |z| grid[i][z] == 0 } [0]\n if !j.nil?\n in_right_diag = true if i == j\n in_left_diag = true if n - i - 1 == j\n missing_pos[0] = i\n missing_pos[1] = j\n end\n end\n sum_rows = Array.new(n, 0)\n sum_cols = Array.new(n, 0)\n sum_diag_left = sum_diag_right = 0\n n.times do |i|\n n.times do |j|\n sum_rows[i] += grid[i][j]\n sum_cols[i] += grid[j][i]\n end\n sum_diag_right += grid[i][i]\n sum_diag_left += grid[i][n - i - 1]\n end\n x, y = missing_pos\n sum_req = 0\n if in_left_diag && in_right_diag\n if x == 0\n sum_req = sum_rows[n - 1]\n elsif x == n - 1\n sum_req = sum_rows[0]\n else\n sum_req = sum_rows[x - 1]\n end\n ans = sum_req - sum_diag_left\n elsif in_right_diag\n sum_req = sum_diag_left\n ans = sum_req - sum_diag_right\n elsif in_left_diag\n sum_req = sum_diag_right\n ans = sum_req - sum_diag_left\n else\n sum_req = sum_diag_left\n ans = sum_req - sum_rows[x]\n end\n grid[x][y] = ans\n if magic_grid? grid\n if ans <= 0\n puts \"-1\"\n else\n puts ans\n end\n else\n puts \"-1\"\n end\nend\n"}, {"source_code": "n=readline.to_i \na = []\nfound = false\n(1..n).each do\n\tai = readline.split.map(&:to_i)\n\ta << ai\nend\n\nfilled = []\nnot_filled = []\n(0...n).each do |i|\n\trow = a[i]\n\tif row.include? 0\n\t\tnot_filled << row.reduce(&:+)\n\telse\n\t\tfilled << row.reduce(&:+)\n\tend\n\t\t\n\tcol = (0...n).map{|j| a[j][i]}\n\tif col.include? 0\n\t\tnot_filled << col.reduce(&:+)\n\telse\n\t\tfilled << col.reduce(&:+)\n\tend\nend\n\ndia_1 = (0...n).map{|j| a[j][j]}\ndia_2 = (0...n).map{|j| a[n-j-1][j]}\n\nif dia_1.include? 0\n\tnot_filled << dia_1.reduce(&:+)\nelse\n\tfilled << dia_1.reduce(&:+)\nend\n\nif dia_2.include? 0\n\tnot_filled << dia_2.reduce(&:+)\nelse\n\tfilled << dia_2.reduce(&:+)\nend\n\nfilled.uniq!\nnot_filled.uniq!\nif n == 1 \n\tputs 1\nelsif filled.size == 1 && not_filled.size == 1 && filled[0] > not_filled[0]\n\tputs filled[0]-not_filled[0]\nelse\n\tputs -1 \nend"}, {"source_code": "def mysum(a)\n nozero = true\n sum = 0\n a.each do |e|\n if e != 0\n sum += e\n else\n nozero = false\n break\n end\n end\n if nozero\n return sum\n else\n return -1\n end\nend\n\ndef realsum(a)\n sum = 0\n a.each do |e|\n sum += e\n end\n return sum\nend\n\ndef checkmat(mat, num)\n valid = true\n for i in 0..(mat.length-1) do\n rowsum = 0\n for ii in 0..(mat[i].length-1) do\n rowsum += mat[i][ii]\n end\n if rowsum != num\n valid = false\n break\n end\n end\n if not valid\n return false\n end\n for i in 0..(mat[0].length-1) do\n colsum = 0\n for ii in 0..(mat.length-1) do\n colsum += mat[ii][i]\n end\n if colsum != num\n valid = false\n break\n end\n end\n if not valid\n return false\n end\n dia1 = 0\n for i in 0..(mat.length-1) do\n dia1 += mat[i][i]\n end\n if dia1 != num\n return false\n end\n dia2 = 0\n for i in 0..(mat.length-1) do\n dia2 += mat[i][mat.length-1-i]\n end\n if dia2 != num\n return false\n end\n return true\nend\n \n\nn = gets.strip.to_i\nmatris = []\nn.times do\n input = gets.strip.split(' ').map(&:to_i)\n matris << input\nend\n\nif n == 1\n puts 3\nelse\n thesum = 0\n zeroline = -1\n for i in 0..(matris.length-1) do\n x = mysum(matris[i])\n if x != -1\n thesum = x\n if zeroline != -1\n break\n end\n else\n zeroline = i\n next\n end\n end\n\n lol = realsum(matris[zeroline])\n trol = thesum - lol\n if trol > 0\n for i in 0..(matris[zeroline].length-1) do\n if matris[zeroline][i] == 0\n matris[zeroline][i] = trol\n break\n end\n end\n if checkmat(matris, thesum)\n puts trol\n else\n puts -1\n end\n else\n puts -1\n end\nend\n\n"}, {"source_code": "def func(a, n, s, t)\n a.each{|v|\n v.include?(0) ? s<1 or t.uniq.size>1 or s[0]>=t[0]\n p -1\nelse\n p t[0]-s[0]\nend\n"}, {"source_code": "n=gets.to_i\nif n==1\n p 1\n exit(0)\nend\na=[]\nx=n\ny=n\nmax=0\nmin=10**15\nn.times{|i|a<< gets.split.map(&:to_i)}\nn.times{|i|\n l=0\n n.times{|j|\n l+=a[i][j]\n x,y=i,j if a[i][j]==0\n }\n max=[max,l].max\n min=[min,l].min\n}\na[x][y] =[max-min,1].max\nmax=0\nn.times{|i| max+=a[x][i]}\nn.times{|i|\n v,h=0,0\n n.times{|j|\n v+=a[i][j]\n h+=a[j][i]\n }\n if v!=max || h!=max\n p -1\n exit(0)\n end\n}\nv,h=0,0\nn.times{|i|\n v+=a[i][i]\n h+=a[i][n-1-i]\n}\nif (v!=max)||(h!=max)\n p -1\n exit(0)\nend\np a[x][y]\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nsum_row, sum_col, sum_dia = Array.new(n, 0), Array.new(n, 0), Array.new(2, 0)\nx, y = 0, 0\nn.times do |i|\n n.times do |j|\n sum_row[i] += a[i][j]\n sum_col[j] += a[i][j]\n sum_dia[0] += a[i][j] if i == j\n sum_dia[1] += a[i][j] if i + j == n - 1\n x, y = i, j if a[i][j] == 0\n end\nend\ncandidate = ( sum_row.uniq.last - sum_row.uniq.first ).abs\nif n == 1\n puts 1\nelse\n sum_row[x] += candidate\n sum_col[y] += candidate\n sum_dia[0] += candidate if x == y\n sum_dia[1] += candidate if x + y == n - 1\n possible = candidate != 0 && \n sum_row.uniq.size == 1 &&\n sum_col.uniq.size == 1 &&\n sum_dia.uniq.size == 1 &&\n sum_row.first == sum_col.first &&\n sum_col.first == sum_dia.first\n puts possible ? candidate : -1\nend\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nsum_row, sum_col, sum_dia = Array.new(n, 0), Array.new(n, 0), Array.new(2, 0)\nx, y = 0, 0\nn.times do |i|\n n.times do |j|\n sum_row[i] += a[i][j]\n sum_col[j] += a[i][j]\n sum_dia[0] += a[i][j] if i == j\n sum_dia[1] += a[i][j] if i + j == n - 1\n x, y = i, j if a[i][j] == 0\n end\nend\ncandidate = ( sum_row.uniq.last - sum_row.uniq.first ).abs\nif n == 1\n puts 1\nelse\n sum_row[x] += candidate\n sum_col[y] += candidate\n sum_dia[0] += candidate if x == y\n sum_dia[1] += candidate if x + y == n - 1\n possible = candidate != 0 && \n sum_row.uniq.size == 1 &&\n sum_col.uniq.size == 1 &&\n sum_dia.uniq.size == 1 &&\n sum_row.first == sum_col.first &&\n sum_col.first == sum_dia.first\n puts possible ? candidate : -1\nend\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\nn=gets.to_i\nif n==1\n\tp 1\nelse\n\tm=$<.map{|e|e.split.map(&:to_i)}\n\tx=y=0\n\tn.times{|i|\n\t\tx+=m[i][i]\n\t\ty+=m[i][n-i-1]\n\t}\n\ta=(\n\t\t[x]+[y]+\n\t\tm.map{|e|e.reduce(:+)}+\n\t\tm.transpose.map{|e|e.reduce(:+)}\n\t).group_by{|e|e}\n\tif a.size==2\n\t\tp -a.map(&:first).minmax.reduce(:-)\n\telse\n\t\tp -1\n\tend\nend"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\nif n==1\n\tp 1\nelse\n\tm=$<.map{|e|e.split}\n\ta=(\n\t\tm.map{|e|e.map(&:to_i).reduce(:+)}+\n\t\tm.transpose.map{|e|e.map(&:to_i).reduce(:+)}\n\t).group_by{|e|e}\n\tif a.size==2\n\t\tp -a.map(&:first).minmax.reduce(:-)\n\telse\n\t\tp -1\n\tend\nend"}, {"source_code": "#!/usr/bin/ruby\ndef chk(m)\n\tn=m.size\n\tx=y=0\n\tn.times{|i|\n\t\tx+=m[i][i]\n\t\ty+=m[i][n-i-1]\n\t}\n\t(\n\t\t[x]+[y]+\n\t\tm.map{|e|e.reduce(:+)}+\n\t\tm.transpose.map{|e|e.reduce(:+)}\n\t).group_by{|e|e}\nend\n\nn=gets.to_i\nif n==1\n\tp 1\nelse\n\tm=$<.map{|e|e.split.map(&:to_i)}\n\ta=chk(m)\n\tif a.size!=2\n\t\tp -1\n\telse\n\t\tk=-a.map(&:first).minmax.reduce(:-)\n\t\tn.times{|i|n.times{|j|\n\t\t\tm[i][j]=k if m[i][j]==0\n\t\t}}\n\t\ta=chk(m)\n\t\tp a.size!=2 ? -1 : k\n\tend\nend"}, {"source_code": "# http://codeforces.com/contest/711/problem/B\nn = gets.chomp.to_i\nrows = [].tap do |a|\n n.times { a << gets.chomp.split.map(&:to_i) }\nend\narr = rows.tap do |a|\n # cols\n (0...n).each { |i| a << (0...n).map { |j| rows[j][i] } }\n # diagonal\n a << (0...n).map { |i| rows[i][i] }\n a << (0...n).map { |i| rows[n - i - 1][i] }\nend\nnot_filled, filled = arr.partition { |a| a.include?(0) }\nsum_of_not_filled = not_filled.map { |a| a.inject(0, :+) }.uniq\nsum_of_filled = filled.map { |a| a.inject(0, :+) }.uniq\nif n == 1\n puts 1\nelsif sum_of_filled.length == 1 && sum_of_not_filled.length == 1\n puts sum_of_filled.first - sum_of_not_filled.first\nelse\n puts -1\nend\n"}, {"source_code": "def magic_grid?( grid )\n n = grid.length\n sum_rows = Array.new(n, 0)\n sum_cols = Array.new(n, 0)\n sum_diag_left = sum_diag_right = 0\n n.times do |i|\n n.times do |j|\n sum_rows[i] += grid[i][j]\n sum_cols[i] += grid[j][i]\n end\n sum_diag_right += grid[i][i]\n sum_diag_left += grid[i][n - i - 1]\n end\n return false if sum_rows.uniq.length != 1 || sum_cols.uniq.length != 1\n sum_cols[0] == sum_rows[0] && sum_rows[0] == sum_diag_left && sum_diag_left == sum_diag_right\nend\nn = gets.strip.to_i\ngrid = Array.new(n) { Array.new(n, 0) }\nmissing_pos = Array.new(2, 0)\nin_left_diag = false\nin_right_diag = false\nn.times do |i|\n grid[i] = gets.strip.split.map(&:to_i)\n j = grid[i].each_index.select { |z| grid[i][z] == 0 } [0]\n if !j.nil?\n in_right_diag = true if i == j\n in_left_diag = true if n - i - 1 == j\n missing_pos[0] = i\n missing_pos[1] = j\n end\nend\nsum_rows = Array.new(n, 0)\nsum_cols = Array.new(n, 0)\nsum_diag_left = sum_diag_right = 0\nn.times do |i|\n n.times do |j|\n sum_rows[i] += grid[i][j]\n sum_cols[i] += grid[j][i]\n end\n sum_diag_right += grid[i][i]\n sum_diag_left += grid[i][n - i - 1]\nend\nx, y = missing_pos\nsum_req = 0\nif in_left_diag && in_right_diag\n if x == 0\n sum_req = sum_rows[n - 1]\n elsif x == n - 1\n sum_req = sum_rows[0]\n else\n sum_req = sum_rows[x - 1]\n end\n ans = sum_req - sum_diag_left\nelsif in_right_diag\n sum_req = sum_diag_left\n ans = sum_req - sum_diag_right\nelsif in_left_diag\n sum_req = sum_diag_right\n ans = sum_req - sum_diag_left\nelse\n sum_req = sum_diag_left\n ans = sum_req - sum_rows[x]\nend\ngrid[x][y] = ans\nif magic_grid? grid\n puts ans\nelse\n puts \"-1\"\nend\n"}, {"source_code": "def magic_grid?( grid )\n n = grid.length\n sum_rows = Array.new(n, 0)\n sum_cols = Array.new(n, 0)\n sum_diag_left = sum_diag_right = 0\n n.times do |i|\n n.times do |j|\n sum_rows[i] += grid[i][j]\n sum_cols[i] += grid[j][i]\n end\n sum_diag_right += grid[i][i]\n sum_diag_left += grid[i][n - i - 1]\n end\n return false if sum_rows.uniq.length != 1 || sum_cols.uniq.length != 1\n sum_cols[0] == sum_rows[0] && sum_rows[0] == sum_diag_left && sum_diag_left == sum_diag_right\nend\nn = gets.strip.to_i\ngrid = Array.new(n) { Array.new(n, 0) }\nmissing_pos = Array.new(2, 0)\nin_left_diag = false\nin_right_diag = false\nif n == 1\n puts 1\nelse\n n.times do |i|\n grid[i] = gets.strip.split.map(&:to_i)\n j = grid[i].each_index.select { |z| grid[i][z] == 0 } [0]\n if !j.nil?\n in_right_diag = true if i == j\n in_left_diag = true if n - i - 1 == j\n missing_pos[0] = i\n missing_pos[1] = j\n end\n end\n sum_rows = Array.new(n, 0)\n sum_cols = Array.new(n, 0)\n sum_diag_left = sum_diag_right = 0\n n.times do |i|\n n.times do |j|\n sum_rows[i] += grid[i][j]\n sum_cols[i] += grid[j][i]\n end\n sum_diag_right += grid[i][i]\n sum_diag_left += grid[i][n - i - 1]\n end\n x, y = missing_pos\n sum_req = 0\n if in_left_diag && in_right_diag\n if x == 0\n sum_req = sum_rows[n - 1]\n elsif x == n - 1\n sum_req = sum_rows[0]\n else\n sum_req = sum_rows[x - 1]\n end\n ans = sum_req - sum_diag_left\n elsif in_right_diag\n sum_req = sum_diag_left\n ans = sum_req - sum_diag_right\n elsif in_left_diag\n sum_req = sum_diag_right\n ans = sum_req - sum_diag_left\n else\n sum_req = sum_diag_left\n ans = sum_req - sum_rows[x]\n end\n grid[x][y] = ans\n if magic_grid? grid\n puts ans\n else\n puts \"-1\"\n end\nend\n"}, {"source_code": "def magic_grid?( grid )\n n = grid.length\n sum_rows = Array.new(n, 0)\n sum_cols = Array.new(n, 0)\n sum_diag_left = sum_diag_right = 0\n n.times do |i|\n n.times do |j|\n sum_rows[i] += grid[i][j]\n sum_cols[i] += grid[j][i]\n end\n sum_diag_right += grid[i][i]\n sum_diag_left += grid[i][n - i - 1]\n end\n return false if sum_rows.uniq.length != 1 || sum_cols.uniq.length != 1\n sum_cols[0] == sum_rows[0] && sum_rows[0] == sum_diag_left && sum_diag_left == sum_diag_right\nend\nn = gets.strip.to_i\ngrid = Array.new(n) { Array.new(n, 0) }\nmissing_pos = Array.new(2, 0)\nin_left_diag = false\nin_right_diag = false\nif n == 1\n puts 1\nelse\n n.times do |i|\n grid[i] = gets.strip.split.map(&:to_i)\n j = grid[i].each_index.select { |z| grid[i][z] == 0 } [0]\n if !j.nil?\n in_right_diag = true if i == j\n in_left_diag = true if n - i - 1 == j\n missing_pos[0] = i\n missing_pos[1] = j\n end\n end\n sum_rows = Array.new(n, 0)\n sum_cols = Array.new(n, 0)\n sum_diag_left = sum_diag_right = 0\n n.times do |i|\n n.times do |j|\n sum_rows[i] += grid[i][j]\n sum_cols[i] += grid[j][i]\n end\n sum_diag_right += grid[i][i]\n sum_diag_left += grid[i][n - i - 1]\n end\n x, y = missing_pos\n sum_req = 0\n if in_left_diag && in_right_diag\n if x == 0\n sum_req = sum_rows[n - 1]\n elsif x == n - 1\n sum_req = sum_rows[0]\n else\n sum_req = sum_rows[x - 1]\n end\n ans = sum_req - sum_diag_left\n elsif in_right_diag\n sum_req = sum_diag_left\n ans = sum_req - sum_diag_right\n elsif in_left_diag\n sum_req = sum_diag_right\n ans = sum_req - sum_diag_left\n else\n sum_req = sum_diag_left\n ans = sum_req - sum_rows[x]\n end\n grid[x][y] = ans\n if magic_grid? grid\n if ans == 0\n puts \"-1\"\n else\n puts ans\n end\n else\n puts \"-1\"\n end\nend\n"}, {"source_code": "def magic_grid?( grid )\n n = grid.length\n sum_rows = Array.new(n, 0)\n sum_cols = Array.new(n, 0)\n sum_diag_left = sum_diag_right = 0\n n.times do |i|\n n.times do |j|\n sum_rows[i] += grid[i][j]\n sum_cols[i] += grid[j][i]\n end\n sum_diag_right += grid[i][i]\n sum_diag_left += grid[i][n - i - 1]\n end\n return false if sum_rows.uniq.length != 1 || sum_cols.uniq.length != 1\n sum_cols[0] == sum_rows[0] && sum_rows[0] == sum_diag_left && sum_diag_left == sum_diag_right\nend\nn = gets.strip.to_i\ngrid = Array.new(n) { Array.new(n, 0) }\nmissing_pos = Array.new(2, 0)\nin_left_diag = false\nin_right_diag = false\nn.times do |i|\n grid[i] = gets.strip.split.map(&:to_i)\n j = grid[i].each_index.select { |z| grid[i][z] == 0 } [0]\n if !j.nil?\n in_right_diag = true if i == j\n in_left_diag = true if n - i - 1 == j\n missing_pos[0] = i\n missing_pos[1] = j\n end\nend\nsum_rows = Array.new(n, 0)\nsum_cols = Array.new(n, 0)\nsum_diag_left = sum_diag_right = 0\nn.times do |i|\n n.times do |j|\n sum_rows[i] += grid[i][j]\n sum_cols[i] += grid[j][i]\n end\n sum_diag_right += grid[i][i]\n sum_diag_left += grid[i][n - i - 1]\nend\nx, y = missing_pos\nsum_req = 0\nif in_left_diag && in_right_diag\n if x == 0\n sum_req = sum_rows[n - 1]\n elsif x == n - 1\n sum_req = sum_rows[0]\n else\n sum_req = sum_rows[x - 1]\n end\n ans = sum_req - sum_diag_left\nelsif in_right_diag\n if x == 0\n sum_req = sum_rows[n - 1]\n elsif x == n - 1\n sum_req = sum_rows[0]\n else\n sum_req = sum_rows[x - 1]\n end\n ans = sum_req - sum_diag_right\nelsif in_left_diag\n if x == 0\n sum_req = sum_rows[n - 1]\n elsif x == n - 1\n sum_req = sum_rows[0]\n else\n sum_req = sum_rows[x - 1]\n end\n ans = sum_req - sum_diag_left\nelse\n sum_req = sum_diag_left\n ans = sum_req - sum_rows[x]\nend\ngrid[x][y] = ans\nif magic_grid? grid\n puts ans\nelse\n puts \"-1\"\nend\n"}, {"source_code": "def mysum(a)\n nozero = true\n sum = 0\n a.each do |e|\n if e != 0\n sum += e\n else\n nozero = false\n break\n end\n end\n if nozero\n return sum\n else\n return -1\n end\nend\n\ndef realsum(a)\n sum = 0\n a.each do |e|\n sum += e\n end\n return sum\nend\n\ndef checkmat(mat, num)\n valid = true\n for i in 0..(mat.length-1) do\n rowsum = 0\n for ii in 0..(mat[i].length-1) do\n rowsum += mat[i][ii]\n end\n if rowsum != num\n valid = false\n break\n end\n end\n if not valid\n return false\n end\n for i in 0..(mat[0].length-1) do\n colsum = 0\n for ii in 0..(mat.length-1) do\n colsum += mat[ii][i]\n end\n if colsum != num\n valid = false\n break\n end\n end\n if not valid\n return false\n end\n dia1 = 0\n for i in 0..(mat.length-1) do\n dia1 += mat[i][i]\n end\n if dia1 != num\n return false\n end\n dia2 = 0\n for i in 0..(mat.length-1) do\n dia2 += mat[i][mat.length-1-i]\n end\n if dia2 != num\n return false\n end\n return true\nend\n \n\nn = gets.strip.to_i\nmatris = []\nn.times do\n input = gets.strip.split(' ').map(&:to_i)\n matris << input\nend\n\nif n == 1\n puts matris[0][0]\nelse\n thesum = 0\n zeroline = -1\n for i in 0..(matris.length-1) do\n x = mysum(matris[i])\n if x != -1\n thesum = x\n if zeroline != -1\n break\n end\n else\n zeroline = i\n next\n end\n end\n\n lol = realsum(matris[zeroline])\n trol = thesum - lol\n if trol > 0\n for i in 0..(matris[zeroline].length-1) do\n if matris[zeroline][i] == 0\n matris[zeroline][i] = trol\n break\n end\n end\n if checkmat(matris, thesum)\n puts trol\n else\n puts -1\n end\n else\n puts -1\n end\nend\n\n"}, {"source_code": "def mysum(a)\n nozero = true\n sum = 0\n a.each do |e|\n if e != 0\n sum += e\n else\n nozero = false\n break\n end\n end\n if nozero\n return sum\n else\n return -1\n end\nend\n\ndef realsum(a)\n sum = 0\n a.each do |e|\n sum += e\n end\n return sum\nend\n\ndef checkmat(mat, num)\n valid = true\n for i in 0..(mat.length-1) do\n rowsum = 0\n for ii in 0..(mat[i].length-1) do\n rowsum += mat[i][ii]\n end\n if rowsum != num\n valid = false\n break\n end\n end\n if not valid\n return false\n end\n for i in 0..(mat[0].length-1) do\n colsum = 0\n for ii in 0..(mat.length-1) do\n colsum += mat[i][ii]\n end\n if colsum != num\n valid = false\n break\n end\n end\n if not valid\n return false\n end\n dia1 = 0\n for i in 0..(mat.length-1) do\n dia1 += mat[i][i]\n end\n if dia1 != num\n return false\n end\n dia2 = 0\n for i in 0..(mat.length-1) do\n dia2 += mat[i][mat.length-1-i]\n end\n if dia2 != num\n return false\n end\n return true\nend\n \n\nn = gets.strip.to_i\nmatris = []\nn.times do\n input = gets.strip.split(' ').map(&:to_i)\n matris << input\nend\n\nif n == 1\n puts matris[0][0]\nelse\n thesum = 0\n zeroline = -1\n for i in 0..(matris.length-1) do\n x = mysum(matris[i])\n if x != -1\n thesum = x\n if zeroline != -1\n break\n end\n else\n zeroline = i\n next\n end\n end\n\n lol = realsum(matris[zeroline])\n trol = thesum - lol\n if trol > 0\n for i in 0..(matris[zeroline].length-1) do\n if matris[zeroline][i] == 0\n matris[zeroline][i] = trol\n break\n end\n end\n if checkmat(matris, thesum)\n puts trol\n else\n puts -1\n end\n else\n puts -1\n end\nend\n\n"}, {"source_code": "def func(a, n, s, t)\n a.each do |v|\n if v.include?(0)\n s<1 or t.uniq.size>1 or s[0]>=t[0]\n p -1\nelse\n p s[0]-t[0]\nend\n\n"}, {"source_code": "def func(a, n, s, t)\n a.each{|v|\n v.include?(0) ? s<1 or t.uniq.size>1 or s[0]>=t[0]\n p -1\nelse\n p t[0]-s[0]\nend\n\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nsummed = a.map{|x| x.inject(&:+)}.sort\npossible = true\nif n == 1\n possible = false\nelsif !(summed.uniq.size == 2 && summed.last - summed.first > 0)\n possible = false\nelse\n possible = n.times.map{|x| a[x][x] == 0 ? summed.last - summed.first : a[x][x]}.inject(&:+) == n.times.map{|x| a[x][n - x - 1] == 0 ? summed.last - summed.first : a[x][n - x - 1]}.inject(&:+)\nend\nputs possible ? summed.last - summed.first : -1\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nsummed = a.map{|x| x.inject(&:+)}.sort\npossible = true\nif n == 1\n possible = false\nelsif summed.uniq.size != 2\n possible = false\nelsif summed.last - summed.first <= 0\n possible = false\nelse\n possible = ( n.times.map{|x| a[x][x] == 0 ? summed.last - summed.first : a[x][x]}.inject(&:+) == n.times.map{|x| a[x][n - x - 1] == 0 ? summed.last - summed.first : a[x][n - x - 1]}.inject(&:+) )\nend\nputs possible ? summed.last - summed.first : -1\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nrow, col = Array.new(n, 0), Array.new(n, 0)\nn.times do |i|\n n.times do |j|\n row[i] += a[i][j]\n col[j] += a[i][j]\n end\nend\nguess1 = row.uniq.sort.last - row.uniq.sort.first\nguess2 = col.uniq.sort.last - col.uniq.sort.first\ndia1 = n.times.map{|x| a[x][x] == 0 ? guess1 : a[x][x]}.inject(&:+)\ndia2 = n.times.map{|x| a[x][n - 1 - x] == 0 ? guess1 : a[x][n - 1 - x]}.inject(&:+)\nif n == 1\n puts 1\nelse\n puts row.uniq.size == 2 && col.uniq.size == 2 && guess1 == guess2 && dia1 == dia2 ? guess1 : -1\nend\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nsummed = a.map{|x| x.inject(&:+)}.sort\nif n == 1\n puts 1\nelse\n puts summed.uniq.size == 2 && summed.last - summed.first > 0 ? summed.last - summed.first : -1\nend\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nrow, col = Array.new(n, 0), Array.new(n, 0)\nn.times do |i|\n n.times do |j|\n row[i] += a[i][j]\n col[j] += a[i][j]\n end\nend\nguess1 = row.uniq.sort.last - row.uniq.sort.first\nguess2 = col.uniq.sort.last - col.uniq.sort.first\ndia1 = n.times.map{|x| a[x][x] == 0 ? guess1 : a[x][x]}.inject(&:+)\ndia2 = n.times.map{|x| a[x][n - 1 - x] == 0 ? guess1 : a[x][n - 1 - x]}.inject(&:+)\nif n == 1\n puts 1\nelse\n puts guess1 == guess2 && dia1 == dia2 ? guess1 : -1\nend\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nsummed = a.map{|x| x.inject(&:+)}.sort\nputs summed.uniq.size == 2 && summed.last - summed.first > 0 ? summed.last - summed.first : -1\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nsum_row, sum_col, sum_dia = Array.new(n, 0), Array.new(n, 0), Array.new(2, 0)\nx, y = 0, 0\nn.times do |i|\n n.times do |j|\n sum_row[i] += a[i][j]\n sum_col[j] += a[i][j]\n sum_dia[0] += a[i][j] if i == j\n sum_dia[1] += a[i][j] if i + j == n - 1\n x, y = i, j if a[i][j] == 0\n end\nend\ncandidate = ( sum_row.uniq.last - sum_row.uniq.first ).abs\nif n == 1\n puts 1\nelse\n sum_row[x] += candidate\n sum_col[y] += candidate\n sum_dia[0] += candidate if x == y\n sum_dia[1] += candidate if x + y == n - 1\n puts sum_row.uniq.size == 1 && sum_col.uniq.size == 1 && sum_dia.uniq.size == 1 && candidate != 0 ? candidate : -1\nend\n"}, {"source_code": "n = gets.to_i\na = n.times.map{gets.split.map(&:to_i)}\nsum_row, sum_col, sum_dia = Array.new(n, 0), Array.new(n, 0), Array.new(2, 0)\nx, y = 0, 0\nn.times do |i|\n n.times do |j|\n sum_row[i] += a[i][j]\n sum_col[j] += a[i][j]\n sum_dia[0] += a[i][j] if i == j\n sum_dia[1] += a[i][j] if i + j == n - 1\n x, y = i, j if a[i][j] == 0\n end\nend\ncandidate = ( sum_row.uniq.last - sum_row.uniq.first ).abs\nif n == 1\n puts 1\nelse\n sum_row[x] += candidate\n sum_col[y] += candidate\n sum_dia[0] += candidate if x == y\n sum_dia[1] += candidate if x + y == n - 1\n puts sum_row.uniq.size == 1 && sum_col.uniq.size == 1 && sum_dia.uniq.size == 1 ? candidate : -1\nend\n"}, {"source_code": "n = gets.to_i\na = Array.new(n)\nw = 0\nh = 0\nn.times{|i|\n a[i] = gets.split.map(&:to_i)\n n.times{|j|\n if a[i][j] == 0\n w = j\n h = i\n end\n }\n }\nsum = 0\nif h == 0\n if n == 1\n p 1 \n exit\n end\n sum = a[1].inject(:+)\nelse\n sum = a[0].inject(:+)\nend\ntmp = a[h].inject(:+)\nif tmp == a.transpose[w].inject(:+) && sum > tmp\n p sum - tmp\nelse\n p -1\nend"}, {"source_code": "n = gets.to_i\na = Array.new(n)\nw = 0\nh = 0\ns1 = 0\ns2 = 0\nn.times{|i|\n a[i] = gets.split.map(&:to_i)\n n.times{|j|\n if a[i][j] == 0\n w = j\n h = i\n end\n if i == j\n s1 += a[i][j]\n end\n if i + j == n - 1\n s2 += a[i][j]\n end\n }\n }\nsum = 0\nif h == 0\n if n == 1\n p 1 \n exit\n end\n sum = a[1].inject(:+)\nelse\n sum = a[0].inject(:+)\nend\ntmp1 = a[h].inject(:+)\ntmp2 = a.transpose[w].inject(:+)\nif tmp1 == tmp2 && sum > tmp1\n if w == h && s1 != tmp1\n p -1\n exit\n end\n if w + h == n - 1 && s2 != tmp1\n p -1\n exit\n end \n p sum - tmp1\nelse\n p -1\nend"}, {"source_code": "n = gets.to_i\na = Array.new(n)\nw = 0\nh = 0\ns1 = 0\ns2 = 0\nb = Array.new(n, 0)\nc = Array.new(n, 0)\nn.times{|i|\n a[i] = gets.split.map(&:to_i)\n n.times{|j|\n if a[i][j] == 0\n w = j\n h = i\n end\n if i == j\n s1 += a[i][j]\n end\n if i + j == n - 1\n s2 += a[i][j]\n end\n b[i] += a[i][j]\n c[j] += a[i][j]\n }\n }\nif h == 0\n if n == 1\n p 1 \n exit\n end\n sum = b[1]\nelse\n sum = b[0]\nend\nn.times{|i|\n if i != h && sum != b[i]\n p -1 \n exit\n end\n }\nn.times{|i|\n if i != w && sum != c[i]\n p -1 \n exit\n end\n }\ntmp1 = b[h]\ntmp2 = c[w]\nif tmp1 == tmp2 && sum > tmp1\n if w == h && s1 != tmp1\n p -1\n exit\n end\n if w + h == n - 1 && s2 != tmp1\n p -1\n exit\n end \n p sum - tmp1\nelse\n p -1\nend"}, {"source_code": "n = gets.to_i\na = Array.new(n)\nw = 0\nh = 0\ns1 = 0\ns2 = 0\nb = Array.new(n, 0)\nc = Array.new(n, 0)\nn.times{|i|\n a[i] = gets.split.map(&:to_i)\n n.times{|j|\n if a[i][j] == 0\n w = j\n h = i\n end\n if i == j\n s1 += a[i][j]\n end\n if i + j == n - 1\n s2 += a[i][j]\n end\n b[i] += a[i][j]\n c[j] += a[i][j]\n }\n }\nif h == 0\n if n == 1\n p 1 \n exit\n end\n sum = b[1]\nelse\n sum = b[0]\nend\nn.times{|i|\n if i != h && sum != b[i]\n p -1 \n exit\n end\n }\nn.times{|i|\n if i != w && sum != c[i]\n p -1 \n exit\n end\n }\ntmp1 = b[h]\ntmp2 = c[w]\nif tmp1 == tmp2 && sum > tmp1\n if w == h && s1 != tmp1 || s1 != sum\n p -1\n exit\n end\n if w + h == n - 1 && s2 != tmp1 || s2 != sum\n p -1\n exit\n end \n p sum - tmp1\nelse\n p -1\nend"}, {"source_code": "n=readline.to_i \na = []\nfound = false\n(1..n).each do\n\tai = readline.split.map(&:to_i)\n\ta << ai\nend\n\nfilled = []\nnot_filled = []\n(0...n).each do |i|\n\trow = a[i]\n\tif row.include? 0\n\t\tnot_filled << row.reduce(&:+)\n\telse\n\t\tfilled << row.reduce(&:+)\n\tend\n\t\t\n\tcol = (0...n).map{|j| a[j][i]}\n\tif col.include? 0\n\t\tnot_filled << col.reduce(&:+)\n\telse\n\t\tfilled << col.reduce(&:+)\n\tend\nend\n\ndia_1 = (0...n).map{|j| a[j][j]}\ndia_2 = (0...n).map{|j| a[n-j-1][j]}\n\nif dia_1.include? 0\n\tnot_filled << dia_1.reduce(&:+)\nelse\n\tfilled << dia_1.reduce(&:+)\nend\n\nif dia_2.include? 0\n\tnot_filled << dia_2.reduce(&:+)\nelse\n\tfilled << dia_2.reduce(&:+)\nend\n\nfilled.uniq!\nnot_filled.uniq!\nif filled.size == 1 && not_filled.size == 1 && filled[0] > not_filled[0]\n\tputs filled[0]-not_filled[0]\nelse\n\tputs -1 \nend"}, {"source_code": "n=readline.to_i \na = []\nfound = false\n(1..n).each do\n\tai = readline.split.map(&:to_i)\n\ta << ai\nend\n\nfilled = []\nnot_filled = []\n(0...n).each do |i|\n\trow = a[i]\n\tif row.include? 0\n\t\tnot_filled << row.reduce(&:+)\n\telse\n\t\tfilled << row.reduce(&:+)\n\tend\n\t\t\n\tcol = (0...n).map{|j| a[j][i]}\n\tif col.include? 0\n\t\tnot_filled << col.reduce(&:+)\n\telse\n\t\tfilled << col.reduce(&:+)\n\tend\nend\n\ndia_1 = (0...n).map{|j| a[j][j]}\ndia_2 = (0...n).map{|j| a[n-j-1][j]}\n\nif dia_1.include? 0\n\tnot_filled << dia_1.reduce(&:+)\nelse\n\tfilled << dia_1.reduce(&:+)\nend\n\nif dia_2.include? 0\n\tnot_filled << dia_2.reduce(&:+)\nelse\n\tfilled << dia_2.reduce(&:+)\nend\n\nfilled.uniq!\nnot_filled.uniq!\nif filled.size == 1 && not_filled.size == 1\n\tputs filled[0]-not_filled[0]\nelse\n\tputs -1 \nend"}], "src_uid": "3bd5a228ed5faf997956570f96becd73"} {"source_code": "def rot(a)\n a.push(a.shift)\nend\ndef already(h,a)\n h.include?(a) || h.include?(rot(a)) || h.include?(rot(rot(a))) || h.include?(rot(rot(rot(a))))\nend\n\nn=gets.to_i\na=Array.new(4)\nh={}\ncnt=0\nn.times{|x|\n\ta[0]=gets(1)\n\ta[1]=gets(1)\n\tgets\n\ta[3]=gets(1)\n\ta[2]=gets(1)\n\tgets\n\tif x!=n-1 then gets; end\n\tif !already(h,a) then\n\t\tcnt+=1\n\t h[a]=true\n\tend\n}\nputs cnt", "positive_code": [{"source_code": "a=gets.to_i\narr={}\na.times{\n z=gets.to_i\n zz=gets.to_i\n z=z*100+(zz%10)*10+zz/10\n m=z\n z=1000*(z%10)+z/10\n m=m>z ? m : z\n z=1000*(z%10)+z/10\n m=m>z ? m : z\n z=1000*(z%10)+z/10\n m=m>z ? m : z\n arr[m]=1\n gets\n}\np arr.size\n"}, {"source_code": "def r(s)\n s[1..-1] + s[0..0]\nend\n\nn = gets.to_i\n\na = Array.new(n) do |i|\n s = gets[0..1] + gets[0..1].reverse\n gets if i != n - 1\n s\nend\n\na = a.map do |s|\n [s, r(s), r(r(s)), r(r(r(s)))].min\nend\n\nputs a.uniq.count"}, {"source_code": "def rotate(amulet)\n a = amulet[0][0]\n b = amulet[0][1]\n c = amulet[1][0]\n d = amulet[1][1]\n\n [[c, a], [d, b]]\nend\ndef equal(a, b)\n if a == b\n true\n elsif rotate(a) == b || rotate(rotate(a)) == b || rotate(rotate(rotate(a))) == b\n true\n else\n false\n end\nend\n\nnumber = gets.chomp.to_i\n\namulets = []\nnumber.times {|i|\n str = gets.chomp\n a = str[0..0]\n b = str[1..1]\n str = gets.chomp\n c = str[0..0]\n d = str[1..1]\n amulets << [[a, b], [c, d]]\n gets if not i == number - 1\n}\n\npiles = []\namulets.each {|amulet|\n if index = piles.index {|item| equal(item[0], amulet)}\n piles[index] << amulet\n else\n piles << [amulet]\n end\n}\n\nputs piles.length\n"}, {"source_code": "amulets, piles = [], []\nn = STDIN.gets.to_i\n\nn.times do\n li1, li2, sep = STDIN.gets.chomp, STDIN.gets.chomp.reverse, STDIN.gets\n amulets << li1 + li2\nend\n\namulets.each do |amu|\n 4.times do |n|\n amu_rotate = (amu * 2)[n, 4]\n break if piles.include?(amu_rotate)\n piles << amu if n == 3\n end\nend\n\nputs piles.count"}], "negative_code": [{"source_code": "amulets = []\npiles = {}\n\nn = STDIN.gets\nn.to_i.times do\n line1 = STDIN.gets.chomp\n line2 = STDIN.gets.chomp.reverse\n sep = STDIN.gets\n \n amulets << line1 + line2\nend\n\nputs 1"}, {"source_code": "def rot(a)\n a[0],a[1],a[2],a[3] = a[2],a[0],a[3],a[1]\nend\ndef already(h,a)\n h.include?(a) || h.include?(rot(a)) || h.include?(rot(rot(a))) || h.include?(rot(rot(rot(a))))\nend\n\nn=gets.to_i\na=Array.new(4)\nh={}\ncnt=0\nn.times{|x|\n\ta[0]=gets(1)\n\ta[1]=gets(1)\n\tgets\n\ta[2]=gets(1)\n\ta[3]=gets(1)\n\tgets\n\tif x!=n-1 then gets; end\n\tif !already(h,a) then\n\t\tcnt+=1\n\t h[a]=true\n\tend\n}\nputs cnt"}, {"source_code": "def rot(a)\n a[0],a[1],a[2],a[3] = a[2],a[0],a[2],a[1]\nend\ndef already(h,a)\n h.include?(a) || h.include?(rot(a)) || h.include?(rot(rot(a))) || h.include?(rot(rot(rot(a))))\nend\n\nn=gets.to_i\na=Array.new(4)\nh={}\ncnt=0\nn.times{|x|\n\ta[0]=gets(1)\n\ta[1]=gets(1)\n\tgets\n\ta[2]=gets(1)\n\ta[3]=gets(1)\n\tgets\n\tif x!=n-1 then gets; end\n\tif !already(h,a) then\n\t\tcnt+=1\n\t h[a]=true\n\tend\n}\nputs cnt"}, {"source_code": "def rot(a)\n a.push(a.shift)\nend\ndef already(h,a)\n h.include?(a) || h.include?(rot(a)) || h.include?(rot(rot(a))) || h.include?(rot(rot(rot(a))))\nend\n\nn=gets.to_i\na=Array.new(4)\nh={}\ncnt=0\nn.times{|x|\n\tgets\n\ta[0]=gets(1)\n\ta[1]=gets(1)\n\tgets\n\ta[2]=gets(1)\n\ta[3]=gets(1)\n\tgets\n\tif !already(h,a) then\n\t\tcnt+=1\n\t h[a]=true\n\tend\n}\nputs cnt"}, {"source_code": "def rotate(amulet)\n a = amulet[0][0]\n b = amulet[0][1]\n c = amulet[1][0]\n d = amulet[1][1]\n\n [[c, a], [d, b]]\nend\ndef equal(a, b)\n if a == b\n true\n elsif rotate(a) == b || rotate(rotate(a)) == b || rotate(rotate(rotate(a))) == b\n true\n else\n false\n end\nend\n\nnumber = gets.chomp.to_i\n\namulets = []\nnumber.times {|i|\n str = gets.chomp\n a = str[0..0]\n b = str[1..1]\n str = gets.chomp\n c = str[0..0]\n d = str[1..1]\n amulets << [[a, b], [c, d]]\n gets if not i == number - 1\n}\n\npiles = []\namulets.each {|amulet|\n if index = piles.index {|item| equal(item[0], amulet)}\n piles[index] << amulet\n else\n piles << [amulet]\n end\n}\n \nputs piles.select {|pile| pile.length != 1}.length\n"}], "src_uid": "3de36638239deacac56e104d3dce1670"} {"source_code": "def solve(n, k, a)\n type = -1\n ans = -1\n for i in 0...k.to_i\n cmp = (n.to_i / a[i].to_i) * a[i].to_i\n if cmp > ans\n ans = cmp\n type = i\n end\n end\n\n ret = []\n ret.push(type.to_i + 1)\n ret.push(n.to_i / a[type.to_i].to_i)\n return ret;\nend\n\nn, k = gets.split(&:to_i)\na = gets.split(&:to_i)\n\nans = solve(n, k, a)\nprint ans[0].to_s + \" \" + ans[1].to_s", "positive_code": [{"source_code": "m, n = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).shift(n)\nans = [0]\na.each_with_index do |i, j|\n ans = [ans, [m - m % i, j + 1, m / i]].max\nend\nputs \"#{ans[1]} #{ans[2]}\"\n"}, {"source_code": "#Hamster farm\n\ninp = gets.chomp.split().map(&:to_i)\nk = inp[0] ; n = inp[1]\ninp = gets.chomp.split().map(&:to_i)\nremain = inp.map { |e| k%e }\nind = remain.each_with_index.min[1]\nmodel = ind + 1\nnum = k/inp[ind]\nputs [model ,num]"}, {"source_code": "def solve(n, k, a)\n type = -1\n ans = -1\n for i in 0...k.to_i\n cmp = (n.to_i / a[i].to_i) * a[i].to_i\n if cmp > ans\n ans = cmp\n type = i\n end\n end\n\n ret = []\n ret.push(type.to_i + 1)\n ret.push(n.to_i / a[type.to_i].to_i)\n return ret;\nend\n\nn, k = gets.split(&:to_i)\na = gets.split(&:to_i)\n\nans = solve(n, k, a)\nprint ans[0].to_s + \" \" + ans[1].to_s\n"}], "negative_code": [], "src_uid": "8e36566b5e0c74730ea118e23b030778"} {"source_code": "def binary_search(range)\n lower = 0\n upper = range.size\n while lower < upper\n mi = (lower + upper)/2\n yield(range[mi]) ? upper = mi : lower = mi + 1\n end\n [range[upper], upper]\nend\n\n\nn = gets.to_i\np = gets.split.map(&:to_i).sort\nq = gets.to_i\n(0...q).each do |i|\n b = gets.to_i\n puts binary_search(p){ |j| j > b}[1]\nend", "positive_code": [{"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n @shopNum = Integer(line)\n when 1\n @priceArr = line.split(\" \")\n @priceArr = @priceArr.map{ |i| i = Integer(i) }\n @priceArr.sort!\n when 2\n @dayNum = Integer(line)\n else\n coin = Integer(line)\n puts searchResult(coin,0,@shopNum-1)\n end\n end\n end\n \n def searchResult(coin,lo,hi)\n while lo <= hi do\n mid = lo + (hi-lo)/2\n if coin < @priceArr[mid] \n hi = mid - 1\n elsif coin == @priceArr[mid]\n rtn = mid + 1;\n lo = mid + 1;\n else\n lo = mid + 1 \n end\n end\n \n return rtn ? rtn : (coin > @priceArr[mid] ? mid + 1 : mid)\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "max1=100000\nc=(0..max1).map{0}\ngets\nx=gets.split.map{|e| e.to_i}\nx.each{|e|\n\tc[e]+=1\n}\n\nsum=0\n0.upto(max1){|i|\n\tsum+=c[i]\n\tc[i]=sum\n}\ngets.to_i.times{\n\tn=gets.to_i\n\tif n>=max1 then\n\t\tputs c[max1]\n\telse\n\t\tputs c[n]\n\tend\n}\n\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\n\nprev = -1\nprices = gets.split.map(&:to_i)\ndays_staying = gets.to_i\nlast_pos = {}\nprices.sort!\nprev = -1\nprices.each_with_index { |item, index|\n if prev != item\n prev = item\n end\n\n last_pos[prev] = index\n}\n\ndays_staying.times {\n coins = gets.to_i\n\n # binary search (end will be exclusive b <= i < e)\n b, e = 0, prices.length\n # p last_pos # index test\n loop {\n mid = (b + e) / 2\n midval = prices[mid]\n # p [b, e, mid, coins]\n if midval < coins\n # p '#1'\n if (e - b) <= 1\n puts e\n break\n end\n\n b = mid\n elsif midval == coins\n # p '#2'\n puts last_pos[midval] + 1\n break\n else\n # p '#3'\n \n if (e - b) <= 1\n puts b\n break\n end\n \n e = mid\n end\n }\n}"}, {"source_code": "n = gets.chomp.to_i\nx = gets.chomp.split.map(&:to_i).sort\nq = gets.chomp.to_i\nm = []\nfor i in (0..q-1)\n\tm[i] = gets.chomp.to_i\nend\n\nfor i in (0..q-1)\n\tfirst = 0\n\tlast = n-1\n\tmid = (first + last)/2\n\twhile first < last\n\t\tif x[mid] <= m[i]\n\t\t\tfirst = mid+1\n\t\telse\n\t\t\tlast = mid-1\n\t\tend\n\t\tmid = (first+last)/2\n\tend\n\tif x[mid] <= m[i]\n\t\tputs mid+1\n\telse\n\t\tif mid < 0\n\t\t\tputs 0\n\t\telse\n\t\t\tputs mid\n\t\tend\n\tend\nend"}, {"source_code": "n = gets.to_i\narr = gets.split(' ').map {|a| a.to_i}.sort!\ngets.to_i.times do\n\tc = gets.to_i\n\tl = 0\n\th = n-1\n\twhile l<=h\n\t\tm = (l+h)/2\n\t\tif arr[m]>c then h = m - 1 else l = m + 1 end\n\tend\n\tputs l\nend"}, {"source_code": "n = gets.to_i\narr = gets.split(' ').map {|a| a.to_i}.sort!\ngets.to_i.times do\n\tc = gets.to_i\n\tl = 0\n\th = n-1\n\t17.times do\n\t\tm = (l+h)/2\n\t\tif arr[m]>c then h = m - 1 else l = m + 1 end\n\tend\n\tputs l\nend"}, {"source_code": "n = gets.to_i\narr = gets.split(' ').map {|a| a.to_i}.sort!\ngets.to_i.times do\n\tc = gets.to_i\n\tl = 0\n\th = n-1\n\t64.times do\n\t\tm = (l+h)/2\n\t\tif arr[m]>c then h = m - 1 else l = m + 1 end\n\tend\n\tputs l\nend"}, {"source_code": "n = gets.to_i\nprices = gets.split.map(&:to_i).sort!\ndays = gets.to_i\n\nfor i in 0..(days - 1)\n money = gets.to_i\n left = 0\n right = n - 1\n\n while left != right do\n middle = (left + right) / 2\n\n if prices[middle] <= money\n left = middle + 1\n else\n right = middle\n end\n\n end\n\n if prices[left] <= money\n puts left + 1\n else\n puts left\n end\nend\n"}, {"source_code": "answer = {}\nn = gets.to_i\nprices = gets.split.map(&:to_i)\ndays = gets.to_i\n\nprices.sort!\n\n\nprices.each_with_index do |x, index|\n answer[x] = index if answer[x].nil?\nend\n\ndays.times do\n money = gets.to_i\n value = prices.bsearch{ |x| x > money }\n puts value.nil? ? n : answer[value]\nend"}, {"source_code": "n = gets.to_i\nprices = gets.split.map(&:to_i).sort!\ndays = gets.to_i\n\nfor i in 0..(days - 1)\n money = gets.to_i\n left = 0\n right = n - 1\n\n while left != right do\n middle = (left + right) / 2\n\n if prices[middle] < money\n left = middle + 1\n elsif prices[middle] > money\n right = middle\n else\n left = middle + 1\n end\n end\n\n if prices[left] <= money\n puts left + 1\n else\n puts left\n end\nend\n"}, {"source_code": "def bs(a, t, l, r)\n return l if l == r\n if a[(l + r) / 2] > t\n bs(a, t, l, (l + r) / 2)\n else\n bs(a, t, (l + r) / 2 + 1, r)\n end\nend\n\nn = gets.to_i\na = gets.split.map(&:to_i).sort\nm = gets.to_i\nans = []\nm.times do\n t = gets.to_i\n ans << bs(a, t, 0, n)\nend\nputs ans * \"\\n\"\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort\nm = gets.to_i\nans = []\nm.times do\n t = gets.to_i\n ans << ((0...n).bsearch{|i| a[i] > t} || n)\nend\nputs ans * \"\\n\"\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.split.map(&:to_i).sort\n\nq = gets.chomp.to_i\n1.upto(q) do\n\tm = gets.chomp.to_i\n\tl = 0\n\tr = n-1\n\n\twhile (r-l > 1) do\n\t\tif a[(r+l)/2]>m then\n\t\t\tr = (r+l)/2\n\t\telse\n\t\t\tl = (r+l)/2\n\t\tend\n\tend\n\n\tresult = 0\n\tif a[l]<=m then\n\t\tif a[r]>m then\n\t\t\tresult = r\n\t\telse\n\t\t\tresult = n\n\t\tend\n\tend\n\n\tputs result\nend\n"}, {"source_code": "shopNum = gets.chomp.to_i\nshopPrices = gets.chomp.split(' ').map(&:to_i)\ndayNum = gets.chomp.to_i\n\nshopPrices.sort!\nindexHash = {}\nduplicate = {}\n\nshopPrices.each_with_index do |p, i|\n\tindexHash[p] = i + 1\n\n\tif duplicate.has_key? p\n\t\tduplicate[p] += 1\n\telse\n\t\tduplicate[p] = 0\n\tend\nend\n\n\ndayNum.times do\n\tcoin = gets.chomp.to_i\n\tidx = shopPrices.bsearch { |x| x >= coin }\n\t\n\t#puts \"idx : #{idx}\"\n\n\tif idx.nil?\n\t\tputs shopPrices.length\n\telse\n\t\tif coin < idx\n\t\t\tputs indexHash[idx] - 1 - duplicate[idx]\n\t\telse\n\t\t\tputs indexHash[idx]\n\t\tend\n\tend\nend"}, {"source_code": "n = gets.to_i\nmas = gets.split.map(&:to_i)\nq = gets.to_i\n\nmas.sort!\n\nans = {}\n\ncnt = 0\nmas.each do |x|\n ans[x] = cnt if ans[x].nil?\n cnt+=1\nend\n\nq.times do\n m = gets.to_i\n f = mas.bsearch{|x| x > m}\n \n puts f.nil? ? n : ans[f]\nend"}, {"source_code": "n = gets.chomp.to_i\nhash = Hash.new { 0 }\narr = gets.chomp.split.map(&:to_i).sort\nc = 0\narr.each do |x|\n hash[x] = c unless hash.key?(x)\n c += 1\nend\n\nq = gets.chomp.to_i\nq.times do\n x = gets.chomp.to_i\n ans = arr.bsearch { |e| e > x }\n puts ans ? hash[ans] : n\nend\n"}, {"source_code": "c = []\nfor i in (1..100001)\n c.push(0)\nend\n\nn = gets.to_i()\nx = gets.split(' ')\nfor i in x\n c[i.to_i()] += 1\nend\n\nfor i in (1..100000)\n c[i] += c[i-1]\nend\n\nq = gets.to_i()\nfor i in (1..q)\n t = gets.to_i()\n if t > 100000\n puts c[100000]\n else\n puts (c[t])\n end\nend\n"}], "negative_code": [{"source_code": "c = []\nfor i in (1..100001)\n c.push(0)\nend\n\nn = gets.to_i()\nx = gets.split(' ')\nfor i in x\n c[i.to_i()] += 1\nend\n\nfor i in (1..100000)\n c[i] += c[i-1]\nend\n\nq = gets.to_i()\nfor i in (1..q)\n t = gets.to_i()\n puts (c[t])\nend\n"}, {"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n @shopNum = Integer(line)\n when 1\n @priceArr = line.split(\" \")\n @priceArr = @priceArr.map{ |i| i = Integer(i) }\n @priceArr.sort!\n when 2\n @dayNum = Integer(line)\n else\n coin = Integer(line)\n p searchResult(coin,@shopNum/2)\n end\n end\n end\n \n def searchResult(coin,partition)\n\n if partition >= @shopNum - 1\n return @shopNum\n elsif @priceArr[partition] == coin\n return partition + 1\n elsif coin > @priceArr[partition] and coin < @priceArr[partition + 1]\n return partition + 1\n elsif coin < @priceArr[partition] and coin > @priceArr[partition - 1]\n return partition\n elsif coin < @priceArr[partition] and partition == 0\n return partition\n elsif @priceArr[partition] > coin\n return searchResult(coin,partition/2)\n elsif @priceArr[partition] < coin\n return searchResult(coin,(@shopNum + partition)/2 )\n end\n\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n @shopNum = Integer(line)\n when 1\n @priceArr = line.split(\" \")\n @priceArr = @priceArr.map{ |i| i = Integer(i) }\n @priceArr.sort!\n when 2\n @dayNum = Integer(line)\n else\n coin = Integer(line)\n puts searchResult(coin,0,@shopNum-1)\n end\n end\n end\n \n def searchResult(coin,lo,hi)\n while lo <= hi do\n mid = lo + (hi-lo)/2\n if coin < @priceArr[mid] \n hi = mid - 1\n elsif coin == @priceArr[mid]\n rtn = mid + 1;\n lo = mid + 1;\n else\n lo = mid + 1 \n end\n end\n \n return rtn ? rtn : (mid == 0 ? 0 : mid + 1)\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n @shopNum = Integer(line)\n when 1\n @priceArr = line.split(\" \")\n @priceArr = @priceArr.map{ |i| i = Integer(i) }\n @priceArr.sort!\n when 2\n @dayNum = Integer(line)\n else\n coin = Integer(line)\n p searchResult(coin,@shopNum/2)\n end\n end\n end\n \n def searchResult(coin,partition)\n if partition <= 0\n return 0\n elsif partition >= @shopNum - 1\n return @shopNum\n elsif @priceArr[partition] == coin\n return partition + 1\n elsif coin > @priceArr[partition] and coin < @priceArr[partition + 1]\n return partition + 1\n elsif coin < @priceArr[partition] and coin > @priceArr[partition - 1]\n return partition\n elsif @priceArr[partition] > coin\n return searchResult(coin,partition/2)\n elsif @priceArr[partition] < coin\n return searchResult(coin,(@shopNum + partition)/2 )\n end\n\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n @shopNum = Integer(line)\n when 1\n @priceArr = line.split(\" \")\n @priceArr = @priceArr.map{ |i| i = Integer(i) }\n @priceArr.sort!\n when 2\n @dayNum = Integer(line)\n else\n coin = Integer(line)\n p searchResult(coin,1,@shopNum)\n end\n end\n end\n \n def searchResult(coin,lo,hi)\n mid = lo+(hi-lo)/2\n if lo >= hi\n return mid\n elsif coin > @priceArr[mid-1]\n return searchResult(coin,mid+1,hi)\n elsif coin < @priceArr[mid-1]\n return searchResult(coin,lo,mid-1)\n elsif coin == @priceArr[mid-1] \n return mid\n end\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n @shopNum = Integer(line)\n when 1\n @priceArr = line.split(\" \")\n @priceArr = @priceArr.map{ |i| i = Integer(i) }\n @priceArr.sort!\n when 2\n @dayNum = Integer(line)\n else\n coin = Integer(line)\n puts searchResult(coin,0,@shopNum-1)\n end\n end\n end\n \n def searchResult(coin,lo,hi)\n while lo <= hi do\n mid = lo + (hi-lo)/2\n if coin < @priceArr[mid] \n hi = mid - 1\n elsif coin == @priceArr[mid]\n rtn = mid + 1;\n lo = mid + 1;\n else\n lo = mid + 1 \n end\n end\n \n return rtn ? rtn : mid\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n @shopNum = Integer(line)\n when 1\n @priceArr = line.split(\" \")\n @priceArr = @priceArr.map{ |i| i = Integer(i) }\n @priceArr.sort!\n when 2\n @dayNum = Integer(line)\n else\n coin = Integer(line)\n p searchResult(coin,1,@shopNum)\n end\n end\n end\n \n def searchResult(coin,lo,hi)\n mid = lo+(hi-lo)/2\n if lo >= hi\n return lo - 1\n elsif coin > @priceArr[mid-1]\n return searchResult(coin,mid+1,hi)\n elsif coin < @priceArr[mid-1]\n return searchResult(coin,lo,mid-1)\n elsif coin == @priceArr[mid-1] \n return mid\n end\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "class Program\n def initialize(input)\n input.each_with_index do |line, idx|\n case idx\n when 0\n @shopNum = Integer(line)\n when 1\n @priceArr = line.split(\" \")\n @priceArr = @priceArr.map{ |i| i = Integer(i) }\n @priceArr.sort!\n when 2\n @dayNum = Integer(line)\n else\n coin = Integer(line)\n puts searchResult(coin,1,@shopNum)\n end\n end\n end\n \n def searchResult(coin,lo,hi)\n mid = lo+(hi-lo)/2\n if lo >= hi\n if coin < @priceArr[mid-1] && mid != 0\n return mid - 1\n else\n return mid\n end\n elsif coin > @priceArr[mid-1]\n return searchResult(coin,mid+1,hi)\n elsif coin < @priceArr[mid-1]\n return searchResult(coin,lo,mid-1)\n elsif coin == @priceArr[mid-1] \n return mid\n end\n end\nend\n\nmain = Program.new(ARGF)"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nprices = gets.split.map(&:to_i)\ndays_staying = gets.to_i\nprices.sort!\ndays_staying.times {\n coins = gets.to_i\n\n # binary search (end will be exclusive b <= i < e)\n b, e = 0, prices.length\n loop {\n mid = (b + e) / 2\n p [b, e, mid, coins]\n if prices[mid] < coins\n p '#1'\n if (e - b) <= 1\n puts e\n break\n end\n\n b = mid\n elsif prices[mid] == coins\n p '#2'\n printed = false\n for i in mid...e\n if prices[i] > coins\n puts i\n printed = true\n break\n end\n end\n\n puts e if !printed\n break\n elsif prices[mid-1] <= coins && prices[mid+1] >= coins\n p '#3'\n puts mid\n break\n else\n p '#4'\n \n if (e - b) <= 1\n puts b\n break\n end\n \n e = mid\n end\n }\n}"}, {"source_code": "n = gets.chomp.to_i\nx = gets.chomp.split\nq = gets.chomp.to_i\nm = []\nfor i in (0..q-1)\n\tm[i] = gets.chomp.to_i\nend\n\nx = x.sort_by { |a,b| a.to_i }\nx = x.map(&:to_i)\n\nfor i in (0..q-1)\n\tif x.min.to_i > m[i]\n\t\tputs 0\n\telsif x.max.to_i <= m[i]\n\t\tputs n\n\telsif x.find_index(m[i]) != nil\n\t\tputs x.find_index(m[i]) + 1\n\telse\n\t\tmid = 0\n\t\tfirst = 0\n\t\tlast = n\n\t\twhile first < last\n\t\t\tmid = first + (last-first)/2\n\t\t\tif m[i] > x[mid]\n\t\t\t\tfirst = mid + 1\n\t\t\telse\n\t\t\t\tlast = mid\n\t\t\tend\n\t\tend\n\t\tputs first\n\tend\n\nend"}, {"source_code": "n = gets.chomp.to_i\nx = gets.chomp.split.map(&:to_i).sort\nq = gets.chomp.to_i\nm = []\nfor i in (0..q-1)\n\tm[i] = gets.chomp.to_i\nend\n\nfor i in (0..q-1)\n\tfirst = 0\n\tlast = n-1\n\tmid = (first + last)/2\n\twhile first < last\n\t\tif x[mid] < m[i]\n\t\t\tfirst = mid+1\n\t\telse\n\t\t\tlast = mid\n\t\tend\n\t\tmid = (first + last)/2\n\tend\n\tif x[mid] <= m[i]\n\t\tputs mid+1\n\telse\n\t\tputs mid\n\tend\nend"}, {"source_code": "n = gets.chomp.to_i\nx = gets.chomp.split\nq = gets.chomp.to_i\nm = []\nfor i in (0..q-1)\n\tm[i] = gets.chomp.to_i\nend\n\nx = x.sort_by { |a,b| a.to_i }\nx = x.map(&:to_i)\n\nfor i in (0..q-1)\n\tif x.min.to_i > m[i]\n\t\tputs 0\n\telsif x.max.to_i <= m[i]\n\t\tputs n\n\telsif x.find_index(m[i]) != nil\n\t\tputs x.find_index(m[i]) + 1\n\telse\n\t\tmid = 0\n\t\tfirst = 0\n\t\tlast = n-1\n\t\twhile first < last\n\t\t\tmid = first + (last-first)/2\n\t\t\tif m[i] > x[mid]\n\t\t\t\tfirst = mid + 1\n\t\t\telse\n\t\t\t\tlast = mid\n\t\t\tend\n\t\tend\n\t\tputs first\n\tend\n\nend"}, {"source_code": "n = gets.chomp.to_i\nx = gets.chomp.split\nq = gets.chomp.to_i\nm = []\nfor i in (0..q-1)\n\tm[i] = gets.chomp.to_i\nend\n\n# sorted_x = []\n# for i in (0..n-1)\n# \tsorted_x << [x[i].to_i, i]\n# end\n# x = sorted_x.sort { |a,b| a[0] <=> b[0] }\nx = x.sort_by { |a,b| a.to_i }\nx = x.map(&:to_i)\n\nfor i in (0..q-1)\n\tif x.min.to_i > m[i]\n\t\tputs 0\n\telsif x.max.to_i <= m[i]\n\t\tputs n\n\telsif x.find_index(m[i]) != nil\n\t\tputs x.find_index(m[i]) + 1\n\telse\n\t\tif m[i] < x[(n/2) + 1]\n\t\t\ttemp = n/2\n\t\t\twhile x[temp] > m[i]\n\t\t\t\ttemp /= 2\n\t\t\tend\n\t\telse\n\t\t\ttemp = (n/2) + 1\n\t\t\twhile x[temp] > m[i]\n\t\t\t\ttemp *= 2\n\t\t\tend\n\t\tend\n\t\tputs temp + 1\n\tend\nend"}, {"source_code": "class BinaryTree\n attr_accessor :root\n\n def insert(value)\n if @root.nil?\n @root = Node.new(value)\n else\n @root.insert(value)\n end\n end\n\n def count_elements(node = @root, sum_elements = 0)\n sum_elements = count_elements(node.left, sum_elements) if node.left\n sum_elements = sum_elements + 1\n node.count = sum_elements\n sum_elements = count_elements(node.right, node.count) if node.right\n sum_elements\n end\n\n def search(searched_value, last_count, node = @root)\n return last_count if node.nil?\n if searched_value < node.node_value\n search(searched_value, last_count, node.left)\n elsif searched_value > node.node_value\n search(searched_value, node.count, node.right)\n else\n return node.count\n end\n end\n\n class Node\n attr_reader :node_value\n attr_accessor :left, :right, :count\n\n def initialize(value)\n @node_value = value\n @count = 0\n end\n\n def insert(value)\n case node_value <=> value\n when 1 then insert_left(value)\n when -1 then insert_right(value)\n when 0 then false\n end\n end\n\n private\n\n def insert_left(value)\n if left\n left.insert(value)\n else\n self.left = Node.new(value)\n end\n end\n\n def insert_right(value)\n if right\n right.insert(value)\n else\n self.right = Node.new(value)\n end\n end\n end\nend\n\nbt = BinaryTree.new\nn = gets.to_i\nprices = gets.split.each do |price|\n bt.insert(price.to_i)\nend\ndays = gets.to_i\n\nbt.count_elements\n\nfor i in 0..(days - 1)\n money = gets.to_i\n puts bt.search(money, 0)\nend\n"}, {"source_code": "class BinaryTree\n attr_accessor :root\n\n def insert(value)\n if @root.nil?\n @root = Node.new(value)\n else\n @root.insert(value)\n end\n end\n\n def count_elements(node = @root, sum_elements = 0)\n sum_elements = count_elements(node.left, sum_elements) if node.left\n sum_elements = sum_elements + 1\n node.count = sum_elements\n sum_elements = count_elements(node.right, node.count) if node.right\n sum_elements\n end\n\n def search(value, node = @root, last_value = 0)\n return last_value if node.nil?\n if value < node.node_value\n search(value, node.left, node.count - 1)\n elsif value > node.node_value\n search(value, node.right, node.count)\n else\n return node.count\n end\n end\n\n class Node\n attr_reader :node_value\n attr_accessor :left, :right, :count\n\n def initialize(value)\n @node_value = value\n @count = 0\n end\n\n def insert(value)\n case node_value <=> value\n when 1 then insert_left(value)\n when -1 then insert_right(value)\n when 0 then false\n end\n end\n\n private\n\n def insert_left(value)\n if left\n left.insert(value)\n else\n self.left = Node.new(value)\n end\n end\n\n def insert_right(value)\n if right\n right.insert(value)\n else\n self.right = Node.new(value)\n end\n end\n end\nend\n\nbt = BinaryTree.new\nn = gets.to_i\nprices = gets.split.each do |price|\n bt.insert(price.to_i)\nend\ndays = gets.to_i\n\nbt.count_elements\n\nfor i in 0..(days - 1)\n money = gets.to_i\n puts bt.search(money)\nend\n"}, {"source_code": "shopNum = gets.chomp.to_i\nshopPrices = gets.chomp.split(' ').map(&:to_i)\ndayNum = gets.chomp.to_i\n\nshopPrices.sort!\nindexHash = {}\n\nshopPrices.each_with_index do |p, i|\n\tindexHash[p] = i + 1\nend\n\n\ndayNum.times do\n\tcoin = gets.chomp.to_i\n\tidx = shopPrices.bsearch { |x| x >= coin }\n\t\n\t#puts \"idx : #{idx}\"\n\n\tif idx.nil?\n\t\tputs shopPrices.length\n\telse\n\t\tif coin < idx\n\t\t\tputs indexHash[idx] - 1\n\t\telse\n\t\t\tputs indexHash[idx]\n\t\tend\n\tend\nend"}], "src_uid": "80a03e6d513f4051175cd5cd1dea33b4"} {"source_code": "n, k = gets.split.map &:to_i; a = Array.new(n, 1); a << 0; c = Array.new(n+1)\nk.times{\n\t1.upto(n){|i|c[i] = a[i]+a[i]<=n-i ? i : a[i]+i}\n\tprint c[1..-1]*' ',\"\\n\"\n\t1.upto(n){|i|a[i] += a[c[i]]}\t\n}", "positive_code": [{"source_code": "args = gets.split(\" \").map(&:to_i)\nn = args[0]\nk = args[1]\n\narr1 = [1]*(n-1) + [0]\narr2 = arr1\nadd = []\n\nk.times do |j|\n arr1.each_with_index do |e, i|\n if (2*e < n-i) and (i ub\n res << \"#{i + 1} \"\n else\n res << \"#{n - t + lb} \"\n end\n end\n puts res\nend\n"}, {"source_code": "at_exit do\n n,k = get_numbers_from_line[0..1]\n numbers = [1]*n\n numbers[n-1] = 0\n\n targets = (n-1).downto(0).to_a\n\n ds = (0...n).map{|i| targets[i] - numbers[i] }\n\n max = 1\n (0...k).each do |i|\n ci = []\n (0...n).each do |j|\n t = ds[j]\n if t == 0\n ci << n\n elsif t >= max\n ci << n - max\n ds[j] -= max\n else\n ci << n - ds[j]\n ds[j] = 0\n end\n end\n puts ci.join(' ')\n max *= 2\n end\n\nend\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend"}], "negative_code": [{"source_code": "args = gets.split(\" \").map(&:to_i)\nn = args[0]\nk = args[1]\n\narr1 = [1]*(n-1) + [0]\narr2 = arr1\nadd = []\n\nk.times do |j|\n arr1.each_with_index do |e, i|\n if 2*e < n-i then\n arr2[i] = arr1[i]+e \n add[i] = i\n else\n arr2[i] = arr1[i]+arr1[i+arr1[i]]\n add[i] = i+arr1[i]\n end\n end\n arr1 = arr2\n puts add.map{ |e| e+1 }.join(\" \")\nend"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\nlb = ub = 1\n\nk.times do\n res = ''\n lb = ub\n ub *= 2\n n.times do |i|\n t = n - i - 1\n if t <= lb\n res << \"#{n} \"\n elsif t > ub\n res << \"#{i + 1} \"\n else\n res << \"#{t} \"\n end\n end\n puts res\nend\n"}], "src_uid": "c8800840e52d4141acdff0420e7ec73c"} {"source_code": "lays = gets.to_i\nlights = [0, 0] + gets.split(' ').map(&:to_i)\n\ncalc_addit = lambda do |root|\n return [0, 0] if 2*root >= lights.size\n\n l, l_add = calc_addit.(2*root)\n l += lights[2*root]\n r, r_add = calc_addit.(2*root+1)\n r += lights[2*root+1]\n if l == r\n [l, l_add+r_add]\n elsif l > r\n [l, l_add + r_add + (l-r)]\n else\n [r, l_add + r_add + (r-l)]\n end\nend\n\nputs calc_addit.(1).last\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.strip.split(\" \").map(&:to_i)\nanswer = 0\ncount = Array.new\n(2**(n+1)-2).downto(2**n-1) do |i|\n count[i] = 0\nend\n(2**n-2).downto(0) do |i|\n candidates = [count[i*2+1]+a[i*2], count[i*2+2]+a[i*2+1]]\n count[i] = candidates.max\n answer += candidates.max - candidates.min\nend\nputs answer\n"}, {"source_code": "n = gets.to_i\na = gets.strip.split(\" \").map(&:to_i)\nanswer = 0\ncount = Array.new\n(2**(n+1)-2).downto(2**n-1) do |i|\n count[i] = 0\nend\n(2**n-2).downto(0) do |i|\n candidates = [count[i*2+1]+a[i*2], count[i*2+2]+a[i*2+1]]\n count[i] = candidates.max\n answer += candidates.max - candidates.min\nend\nputs answer"}, {"source_code": "$gl = 0\n$h = []\n$n\ndef f(v)\n\n\tif(v >= 2**$n and v < 2**($n+1)) then \n\t\treturn 0\n\tend\n \n\ta = f(2*v) + $h[2*v-2]\n\tb = f(2*v+1) + $h[2*v-1]\n\t$gl += (a-b).abs\n\n\treturn [a,b].max\nend\n\n\n$n = gets.to_i\n$h = gets.split.collect{|i| i.to_i}\n\nf(1)\nputs $gl"}], "negative_code": [], "src_uid": "ae61e1270eeda8c30effc9ed999bf531"} {"source_code": "results = []\n\nt = gets.chomp\n(1..t.to_i).each do |iteration|\n\tn, k = gets.chomp.split(' ').map{|e| e.to_i}\n\trest = gets.chomp\n\tindex = 0\n\tfragments = []\n\tplaces_count = 0\n\twhile index < rest.length do\n\t\tif rest[index] == '0'\n\t\t\tplaces_count += 1\n\t\t\tindex += 1\n\t\telse\n\t\t\tplaces_count -= k\n\t\t\tif places_count > 0\n\t\t\t\tfragments.push(places_count)\n\t\t\tend\n\t\t\tplaces_count = 0\n\t\t\tindex += k + 1\n\t\tend\n\tend\n\tif places_count > 0\n\t\tfragments.push(places_count)\n\tend\n\n\toptimal_tables = 0\n\tfragments.each do |el|\n\t\toptimal_tables += el / (k + 1)\n\t\toptimal_tables += 1 if el % (k + 1) > 0\n\tend\n\n\tresults.push(optimal_tables)\nend\n\nresults.each do |result|\n\tputs result\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\n\tn, k = gets.split.map(&:to_i)\n\ts = gets.chomp\n\ts = '1' + '0' * k + s if s[0] == '0'\n\ts = s + '0' * k + '1' if s[-1] == '0'\n\tp s.chars.chunk { _1 }.select { _1[0] == '0' }.map { _2.size }.sum {\n\t\t\t(_1 - k) / (k + 1)\n\t }\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n\tn, k = gets.split.map(&:to_i)\n\ts = \"1\" + \"0\" * k + gets.chomp + \"0\" * k + \"1\" # append sentinel\n\n\toccupy = 0\n\n\t# count continous 0s and check\n\tcount = 0\n\ts.each_char do |c|\n\t\tcase c\n\t\twhen \"0\"\n\t\t\tcount += 1\n\t\twhen \"1\"\n\t\t\tavail = [(count + 1) / (k+1) - 1, 0].max\n\t\t\toccupy += avail\n\t\t\t#puts \" #{count} -> #{avail}\"\n\t\t\tcount = 0\n\t\tend\n\tend\n\n\tp occupy\nend\n"}, {"source_code": "results = []\nt = gets.chomp\n(1..t.to_i).each do\n\ttables_count, k = gets.chomp.split(' ').map{|e| e.to_i}\n\ttabels_map = gets.chomp\n\tindex = 0\n\tempty_places_counts = []\n\tempty_places_count = 0\n\twhile index < tables_count do\n\t\tif tabels_map[index] == '0'\n\t\t\tempty_places_count += 1\n\t\t\tindex += 1\n\t\telse\n\t\t\tempty_places_count -= k\n\t\t\tif empty_places_count > 0\n\t\t\t\tempty_places_counts.push(empty_places_count)\n\t\t\tend\n\t\t\tempty_places_count = 0\n\t\t\tindex += k + 1\n\t\tend\n\tend\n\tif empty_places_count > 0\n\t\tempty_places_counts.push(empty_places_count)\n\tend\n\toptimal_tables = 0\n\tempty_places_counts.each do |el|\n\t\toptimal_tables += el / (k + 1)\n\t\toptimal_tables += 1 if el % (k + 1) > 0\n\tend\n\n\tresults.push(optimal_tables)\nend\n\nresults.each do |res|\n\tputs res\nend\n"}, {"source_code": "def solve(arr_str, k)\n\tparts = arr_str\n\t\t.scan(/1+|0+/)\n\t\t.map { |i| i[0] == '0' ? i.size : 0}\n\n\tparts.map.with_index\n\t\t.reduce(0) do |res, (i, ind)|\n\t\t\twithout_borders = i\n\t\t\twithout_borders -= k unless ind == 0\n\t\t\twithout_borders -= k unless ind == parts.size - 1\n\t\t\tif without_borders > 0\n\t\t\t\tres += 1 + (without_borders - 1) / (k + 1)\n\t\t\tend\n\n\t\t\tres\n\t\tend\nend\n\ntotal_qty = ARGF.gets.to_i\ntotal_qty.times do\n\t_n, k = ARGF.gets.split.map(&:to_i)\n\ta = ARGF.gets.strip\n\tputs solve(a, k)\nend"}], "negative_code": [{"source_code": "data_lines = gets.chomp\nresult = []\n(1..data_lines.to_i).each do\n\tallows = gets.chomp.split(\" \")\n\ttables_count = allows.first.to_i\n\tk = allows.last.to_i\n\tmap = gets.chomp\n\treserved_count = 0\n\t(0..(map.length-1)).each do |index|\n\t\tif map[index] == '1'\n\t\t\treserved_count += 1\n\t\t\tif reserved_count == 1\n\t\t\t\tost = index % (k+1)\n\t\t\t\tif ost > 0\n\t\t\t\t\ttables_count -= ost\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\tif tables_count <= k \n\t\tresult.push(1 - reserved_count)\n\t\tnext\n\tend\n\tall_possible_tables = tables_count / (k + 1)\n\tif tables_count % (k + 1) > 0\n\t\tall_possible_tables += 1\n\tend\n\tres = all_possible_tables - reserved_count\n\tresult.push(res)\nend\nresult.each do |res|\n\tputs res\nend"}, {"source_code": "data_lines = gets.chomp\nresult = []\n(1..data_lines.to_i).each do\n\tallows = gets.chomp.split(\" \")\n\ttables_count = allows.first.to_i\n\tk = allows.last.to_i\n\tmap = gets.chomp\n\treserved_count = 0\n\t(0..(map.length-1)).each do |index|\n\t\tif map[index] == '1'\n\t\t\treserved_count += 1\n\t\t\tif reserved_count == 1\n\t\t\t\tost = index % (k+1)\n\t\t\t\tif ost > 0\n\t\t\t\t\ttables_count -= ost\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\tall_possible_tables = tables_count / (k + 1)\n\tif tables_count % (k + 1) > 0\n\t\tall_possible_tables += 1\n\tend\n\tres = all_possible_tables - reserved_count\n\tif res < 0\n\t\tresult.push(1)\n\t\tnext\n\tend\n\tif reserved_count == 0 && res < 1\n\t\tresult.push(1)\n\t\tnext\n\tend\n\tresult.push(res)\nend\nresult.each do |res|\n\tputs res\nend"}, {"source_code": "data_lines = gets.chomp\nresult = []\n(1..data_lines.to_i).each do\n\tallows = gets.chomp.split(\" \")\n\ttables_count = allows.first.to_i\n\tk = allows.last.to_i\n\tmap = gets.chomp\n\treserved_count = 0\n\t(0..(map.length-1)).each do |index|\n\t\tif map[index] == '1'\n\t\t\treserved_count += 1\n\t\t\tif reserved_count == 1\n\t\t\t\tost = index % (k+1)\n\t\t\t\tif ost > 0\n\t\t\t\t\ttables_count -= ost\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\tall_possible_tables = tables_count / (k + 1)\n\tif tables_count % (k + 1) > 0\n\t\tall_possible_tables += 1\n\tend\n\tresult.push(all_possible_tables - reserved_count)\nend\nresult.each do |res|\n\tputs res\nend"}, {"source_code": "def solve(arr_str, k)\n\tparts = arr_str\n\t\t.split('1')\n\t\t.map(&:size)\n\t\t.reject(&:zero?)\n\t\n\tparts.map.with_index\n\t\t.reduce(0) do |res, (i, ind)|\n\t\t\twithout_borders = i\n\t\t\twithout_borders -= k unless ind == 0\n\t\t\twithout_borders -= k unless ind == parts.size - 1\n\t\t\tif without_borders > 0\n\t\t\t\tres += 1 + (without_borders - 1) / (k + 1)\n\t\t\tend\n\n\t\t\tres\n\t\tend\nend\n\ntotal_qty = ARGF.gets.to_i\ntotal_qty.times do\n\t_n, k = ARGF.gets.split.map(&:to_i)\n\ta = ARGF.gets.strip\n\tputs solve(a, k)\nend"}], "src_uid": "fd85ebe1dc975a71c72fac7eeb944a4a"} {"source_code": " t = gets.to_i\n t.times do\n n, k = gets.split(' ').map(&:to_i)\n\n # solution 3\n\n if n == k\n puts n + 1\n next\n end\n if k < n\n puts k\n next\n end\n # puts n*(k/n) + (k-1)\n # puts n*(k/n-1) + (k-1)\n # 5 12\n ra = k / (n - 1)\n re = k % (n - 1)\n koef = re == 0 ? -1 : re\n puts n * ra + koef\n end", "positive_code": [{"source_code": "t = gets.to_i\n\n(1).upto(t) do\n x = gets.split(' ')\n n = x[0].to_i\n k = x[1].to_i\n val = k/(n-1)\n val+=k\n val-= (k.modulo(n-1)==0?1:0)\n puts val\nend\n"}, {"source_code": "# Created by IntelliJ IDEA.\n# User: gautam.roy\n# Date: 5/10/20\n# Time: 1:25 PM\n# To change this template use File | Settings | File Templates.\n\n# if n > k -> k\n# return k/n + k\nt = gets.to_i\nfor i in 1..t do\n n, k = gets.split(' ').map { |s| s.to_i }\n if n > k\n puts k\n next\n end\n puts (k - 1) / (n-1) + k\nend"}, {"source_code": "def func(n, k)\n res=2**40-1\n a=2**39\n while a>0\n t=res^a\n cnt=t-t/n\n res=t if cnt>=k\n a>>=1\n end\n res\nend\n\ngets.to_i.times{\n n, k=gets.split.map &:to_i\n puts func(n, k)\n}\n"}, {"source_code": "1.upto(gets.to_i) do\n n, k = gets.split(' ').map(&:to_i)\n\n puts k.div(n-1)*n + (k.modulo(n-1).zero? ? -1 : k.modulo(n-1))\nend\n\n"}], "negative_code": [{"source_code": " t = gets.to_i\n t.times do\n n, k = gets.split(' ').map(&:to_i)\n if n == k\n puts n + 1\n next\n end\n if k < n\n puts k\n next\n end\n ra = k / (n - 1)\n re = k % ra\n koef = re == 0 ? -1 : re\n puts n * ra + koef\nend"}], "src_uid": "7d6f76e24fe9a352beea820ab56f03b6"} {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n px, py = gets.chomp.split(' ').map(&:to_i)\r\n s = gets.chomp.split('')\r\n lx = rx = uy = ly = 0\r\n s.each do |el|\r\n case el\r\n when \"U\" \r\n uy += 1\r\n when \"D\"\r\n ly -= 1\r\n when \"R\"\r\n rx += 1\r\n when \"L\"\r\n lx -= 1\r\n end\r\n end\r\n resx = px > 0 && px <= rx || px < 0 && px >= lx || px == 0\r\n resy = py > 0 && py <= uy || py < 0 && py >= ly || py == 0\r\n puts resx && resy ? \"YES\" : \"NO\"\r\nend", "positive_code": [{"source_code": "def solve\n x, y = ints\n s = string.chars.tally\n enough = true\n enough = false if x > 0 and (s[?R] || 0) < x.abs\n enough = false if x < 0 and (s[?L] || 0) < x.abs\n enough = false if y > 0 and (s[?U] || 0) < y.abs\n enough = false if y < 0 and (s[?D] || 0) < y.abs\n yesno enough\nend\n\ndef main\n t = int\n t.times do\n solve\n end\nend\n\nDEBUG = true\nMOD = 10**9+7\nYESNO = %w(NO YES)\nINF = 10**9\n\ndef int; gets.to_s.to_i end\ndef ints; gets.to_s.split.map { |s| s.to_i } end\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\ndef float; gets.to_s.to_f end\ndef floats; gets.to_s.split.map { |s| s.to_f } end\ndef array_of(&convert); gets.to_s.split.map(&convert) end\ndef string; gets.to_s.chomp end\ndef rep(n, &b); Array.new(n, &b) end\ndef yes; puts YESNO[1] end\ndef no; puts YESNO[0] end\ndef yesno t; puts YESNO[t] end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\ndef gcd(*xs); xs.inject(0, :gcd) end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\ndef if_debug; yield if DEBUG end\n\nmodule Boolean\n def coerce(other); [other, to_i] end\n def +@; to_i end\n def to_int; to_i end\n def *(other); to_i * other end\nend\n\nclass TrueClass\n include Boolean\n def to_i; 1 end\nend\n\nclass FalseClass\n include Boolean\n def to_i; 0 end\nend\n\nclass Integer\n def div_ceil(y); (self + y - 1) / y end\n def mod_inv(mod = MOD); pow(mod-2, mod) end\n def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\nend\n\nclass Array\n def power(&block); (0 ... 1 << size).each(&block) end\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\nend\n\nmodule Enumerable\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\nend\n\nmain"}, {"source_code": "gets.to_i.times do\r\n x,y=gets.split.map(&:to_i)\r\n s=gets.chomp.chars\r\n s.each do |ss|\r\n if ss==\"U\"&&y>0\r\n y-=1\r\n elsif ss==\"D\"&&y<0\r\n y+=1\r\n elsif ss==\"R\"&&x>0\r\n x-=1\r\n elsif ss==\"L\"&&x<0\r\n x+=1\r\n end\r\n end\r\n if [x,y]==[0,0]\r\n puts \"YES\"\r\n else\r\n puts \"NO\"\r\n end\r\nend\r\n"}, {"source_code": "t= gets.chomp.to_i\nwhile t > 0\n flag = false\t\n x, y = \tgets.chomp.split(' ')\n s = gets.chomp\n x = x.to_i\n y = y.to_i\n count_u = s.count('U')\n count_r = s.count('R')\n count_l = s.count('L')\n count_d = s.count('D')\n if (x >= 0 && y >= 0)\n if (count_r >= x.abs && count_u >= y.abs)\n puts \"YES\"\n flag = true\n end\n elsif (x >= 0 && y < 0)\n if (count_r >= x.abs && count_d >= y.abs)\n \t puts \"YES\"\n flag = true\n end\n elsif (x < 0 && y >= 0)\n \tif (count_l >= x.abs && count_u >= y.abs)\n \t\t puts \"YES\"\n flag = true\n end\n elsif (x < 0 && y < 0)\n if (count_l >= x.abs && count_d >= y.abs)\n \t puts \"YES\"\n flag = true\n end\n end\n if(!flag)\n puts \"NO\"\n end\n t = t - 1\nend\n\n\n\n\n\n"}, {"source_code": "gets.to_i.times do\r\n x, y = gets.split.map &:to_i\r\n s = gets.chomp\r\n l, r, d, u = 0, 0, 0, 0\r\n s.each_char do |c|\r\n case c\r\n when 'L'\r\n l += 1\r\n when 'R'\r\n r += 1\r\n when 'D'\r\n d += 1\r\n else\r\n u += 1\r\n end\r\n end\r\n x = 0 if x > 0 && r >= x || x < 0 && l >= -x\r\n y = 0 if y > 0 && u >= y || y < 0 && d >= -y\r\n puts x == 0 && y == 0 ? \"YES\" : \"NO\"\r\nend"}], "negative_code": [{"source_code": "t= gets.chomp.to_i\nwhile t > 0\n flag = false\t\n x, y = \tgets.chomp.split(' ')\n s = gets.chomp\n x = x.to_i\n y = y.to_i\n count_u = s.count('U')\n count_r = s.count('R')\n count_l = s.count('L')\n count_d = s.count('D')\n if (x > 0 && y > 0)\n if (count_r >= x.abs && count_u >= y.abs)\n puts \"YES\"\n flag = true\n end\n elsif (x > 0 && y < 0)\n if (count_r >= x.abs && count_d >= y.abs)\n \t puts \"YES\"\n flag = true\n end\n elsif (x < 0 && y > 0)\n \tif (count_l >= x.abs && count_u >= y.abs)\n \t\t puts \"YES\"\n flag = true\n end\n elsif (x < 0 && y < 0)\n if (count_l >= x.abs && count_d >= y.abs)\n \t puts \"YES\"\n flag = true\n end\n end\n if(!flag)\n puts \"NO\"\n end\n t = t - 1\nend\n\n\n\n\n\n"}], "src_uid": "65a64ea63153fec4d660bad1287169d3"} {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\ncnt = 0\ncur = a[0]\n1.upto(n - 1) do |i|\n if cur == n\n puts n\n break\n elsif cur > a[i]\n cnt += 1\n if cnt == k\n puts cur\n break\n end\n else\n cnt = 1\n cur = a[i]\n if cnt == k || cur == n\n puts cur\n break\n end\n end\nend", "positive_code": [{"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\ny=x.max\nc=m\nwhile true\n\tif x[0]==y\n\t\tbreak\n\tend\n\tif x[0]>x[1]\n\t\ta=x.shift\n\t\tb=x.shift\n\t\tx.unshift(a)\n\t\tx.push(b)\n\t\tc-=1\n\telse\n\t\ta=x.shift\n\t\tx.push(a)\n\t\tc=m-1\n\tend\n\tbreak if c==0\nend\nputs x[0]"}, {"source_code": "n, k = gets.split.map &:to_i\nb, c = 0, 0\ngets.split.map(&:to_i).each{|v|\n\tc = b > 0 ? (b > v ? c + 1 : 1) : 0\n\tb = [b, v].max\n\tc == k && break\n}\np b"}], "negative_code": [{"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\ny=x.max\nhs=Hash.new(0)\nwhile true\n\tif x[0]==y\n\t\ths[y]+=m\n\t\tbreak\n\tend\n\tif x[0]>x[1]\n\t\ta=x.shift\n\t\tb=x.shift\n\t\tx.unshift(a)\n\t\tx.push(b)\n\t\ths[a]+=1\n\telse\n\t\ta=x.shift\n\t\tx.push(a)\n\t\ths[x[0]]+=1\n\tend\n\tm-=1\nend\nans=-1\nansV=-1\nhs.each{|k,v|\n\tif v>ansV\n\t\tansV=v\n\t\tans=k\n\tend\n}\nputs ans"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\ny=x.max\nhs=Hash.new(0)\nwhile true\n\tif x[0]==y\n\t\tbreak\n\tend\n\tif x[0]>x[1]\n\t\ta=x.shift\n\t\tb=x.shift\n\t\tx.unshift(a)\n\t\tx.push(b)\n\t\ths[a]+=1\n\telse\n\t\ta=x.shift\n\t\tx.push(a)\n\t\ths[x[0]]+=1\n\tend\nend\nputs x[0]"}, {"source_code": "n,m=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\ny=x.max\nhs=Hash.new(0)\nwhile true\n\tbreak if m==0\n\tif x[0]==y\n\t\tbreak\n\tend\n\tif x[0]>x[1]\n\t\ta=x.shift\n\t\tb=x.shift\n\t\tx.unshift(a)\n\t\tx.push(b)\n\t\ths[a]+=1\n\telse\n\t\ta=x.shift\n\t\tx.push(a)\n\t\ths[x[0]]+=1\n\tend\n\tm-=1\nend\nputs x[0]"}], "src_uid": "8d5fe8eee1cce522e494231bb210950a"} {"source_code": "n , m = gets.chomp.split(\" \").map(&:to_i)\nns = gets.chomp.split(\" \")\nms = gets.chomp.split(\" \")\nngo = gets.chomp.to_i\nngo.times do |i|\n\toil = gets.chomp.to_i - 1\n\tputs ns[oil % n] + ms[oil % m]\nend\n", "positive_code": [{"source_code": "n,m=gets.split().map(&:to_i)\na=gets.split().map(&:to_s)\nb=gets.split().map(&:to_s)\nt=gets.to_i\n for i in 1..t do\n q=gets.to_i-1\n f1,f2=q % n,q % m\n puts a[f1]+b[f2]\nend"}, {"source_code": "n, m = gets.split.map &:to_i\ns = gets.split\nt = gets.split\nq = gets.to_i\nq.times do\n y = gets.to_i - 1\n puts s[y%n] + t[y%m]\nend\n"}, {"source_code": "n, m = gets.chomp.split.map(&:to_i)\na = gets.chomp.split\nb = gets.chomp.split\nq = gets.chomp.to_i\n\n(0...q).each do |_|\n t = gets.chomp.to_i\n puts \"#{a[(t-1) % n]}#{b[(t-1) % m]}\"\nend"}], "negative_code": [], "src_uid": "efa201456f8703fcdc29230248d91c54"} {"source_code": "gets\na = gets.split.map(&:to_i)\nb = a.size - 1\nwhile b > 0 do\n break if a[b - 1] > a[b]\n b -= 1\nend\np b\n\n", "positive_code": [{"source_code": "gets\na = gets.split.map(&:to_i)\nb = a.size - 1\nwhile b > 0 do\n break if a[b - 1] > a[b]\n b -= 1\nend\np b\n\n"}, {"source_code": "n = gets.chomp.to_i\nline = gets.chomp.split(\" \").collect! {|x| x.to_i}\np = n-1\nok = true\nq = n\nwhile p>0 and ok\n\t\n\tif line[p] 0 do\n break if a[b - 1] > a[b]\n b -= 1\nend\np b\n\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn, mn, tot = gets.to_i, 0x3f3f3f3f, 0\ngets.split.map(&:to_i).reverse.each_with_index do |v, i|\n\tif v > mn\n\t\ttot = n - i\n\t\tbreak\n\tend\n\tmn = v\nend\nputs tot\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\nb = a.size - 1\nwhile b > 0 do\n break if a[b - 1] > a[b]\n b -= 1\nend\np b\n\n"}, {"source_code": "n = gets.to_i\n\na = gets.split.collect{|x| x.to_i}\n\na.reverse!\n\nl = 0\nresult = 0\nok = false\n\na.each do |i|\n\tif l == 0\n\t\tl = i\n\telse\n\t\tif ok \n\t\t\tresult += 1\n\t\t\tnext\n\t\tend\n\t\tif i > l\n\t\t\tok = true\n\t\t\tresult = 1\n\t\telse \n\t\t\tl = i\n\t\tend\t\t\n\tend\nend\n\nputs result"}, {"source_code": "gets\na = gets.split.map(&:to_i)\nb = a.size - 1\nwhile b > 0 do\n break if a[b - 1] > a[b]\n b -= 1\nend\np b\n\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\nb = a.size - 1\nwhile b > 0 do\n break if a[b - 1] > a[b]\n b -= 1\nend\np b\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\nb = a.size - 1\nwhile b > 0 do\n break if a[b - 1] > a[b]\n b -= 1\nend\np b\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ni = n-1\nwhile i >= 1 and a[i] > a[i-1] do\n\ti -= 1\nend\nputs i\n"}, {"source_code": "n = Integer(gets.chomp)\ncount = 1\ninput = gets.split.collect{|element| element.to_i}\n(input.length-1).downto 1 do |i|\n if input[i-1] 0\n\tbreak if a[i-1] > a[i]\n\ti -= 1\nend\nputs i\n\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\nb = a.size - 1\nwhile b > 0 do\n break if a[b - 1] > a[b]\n b -= 1\nend\np b\n"}, {"source_code": "n = gets.to_i\na = gets.split(\" \").map(&:to_i)\nj = 0\nn.times{ |i|\n if ( i==n-1 || a[n-1-i] < a [n-2-i] ) then j = i; break; end;\n}\nputs n - j - 1\n"}, {"source_code": "gets\na = gets.split.map{|e| e.to_i}\nl = a.pop\nans = a.length\na.reverse.each do |e|\n if e < l\n ans -= 1\n l = e\n else\n break\n end\nend\nputs ans\n"}, {"source_code": "def run\n n = ARGF.readline\n s = ARGF.readline.split.map(&:to_i)\n len = s.length\n\n cnt = 0\n (len - 1).times do |i|\n cnt = i + 1 if s[i] > s[i + 1]\n end\n\n puts cnt\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\nb = a.size - 1\nwhile b > 0 do\n break if a[b - 1] > a[b]\n b -= 1\nend\np b\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\ni = n-1\nwhile (i > 0) && (a[i-1] < a[i]) do\n i -= 1\nend\nputs i"}, {"source_code": "gets\na = gets.split.map(&:to_i)\nb = a.size - 1\nwhile b > 0 do\n break if a[b - 1] > a[b]\n b -= 1\nend\np b\n\n"}, {"source_code": "n=gets.to_i\na = gets.split(' ').collect!{|i| i.to_i}\n\nx = 0\nn.times do |i|\n\tbreak if i == n-1\n\tif a[n-i-1] < a[n-i-2]\n\t\tx = n-i-1\n\t\tbreak\n\tend\nend\nputs x"}], "negative_code": [{"source_code": "gets\na = gets.split.map(&:to_i)\nb = a.size - 1\nwhile b >= 0 do\n break if a[b - 1] > a[b]\n b -= 1\nend\np b\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ni = n-1\nwhile i >= 1 and a[i] < a[i-1] do\n\ti -= 1\nend\nputs n-i-1\n\t\n\n\t\t\n\n\n\n\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nans = 0\ni = 0\nwhile a[i] != 1 do\n\tans +=1 \n\ti += 1\nend\nputs ans\n\t\t\n\n\n\n\n\n"}, {"source_code": "n = gets.to_i\nputs gets.split.map(&:to_i).index(1)\n\n\t\t\n\n\n\n\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ni = 0\nans = 0\nwhile a[i] != 1 and i <= n-1 do\n\ti += 1\n\tans += 1\nend\nwhile i < n-2 do\n\tif a[i+1] > a[i+2] then\n\t\tans += 1\n\tend\n\ti+=1\nend\n\t\nputs ans\n\t\t\n\n\n\n\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nans = 0\nfor i in 0...(n-1) do\n\tans +=1 if a[i] > a[i+1]\nend\nputs ans\n\t\t\n\n\n\n\n\n"}, {"source_code": "n = Integer(gets.chomp)\ncount = 1\ninput = gets\ninput = input.split\n(input.length-1).downto 1 do |i|\n if input[i-1] s[i + 1]\n end\n\n puts cnt\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n=gets.to_i\na = gets.split(' ')\n\nx = 0\nn.times do |i|\n\tif a[n-i-1] < a[n-i-2]\n\t\tx = n-i-1\n\t\tbreak\n\tend\nend\nputs x"}, {"source_code": "_, mn, tot = gets, 0x3f3f3f3f, 0\ngets.split.map(&:to_i).reverse.each { |i| i < mn ? mn = i : tot += 1 }\nputs tot\n"}, {"source_code": "n = gets.to_i\n\na = gets.split.collect{|x| x.to_i}\n\na.reverse!\n\nl = 0\nresult = 0\n\na.each do |i|\n\tif l == 0\n\t\tl = i\n\telse\n\t\tif i > l\n\t\t\tresult += 1\n\t\tend\n\t\tl = i\n\tend\nend\n\nputs result"}, {"source_code": "n = gets.to_i\n\na = gets.split.collect{|x| x.to_i}\n\na.reverse!\n\nl = 0\nresult = 0\n\na.each do |i|\n\tif l == 0\n\t\tl = i\n\telse\n\t\tif i > l\n\t\t\tresult += 1\n\t\telse \n\t\t\tl = i\n\t\tend\t\t\n\tend\nend\n\nputs result"}], "src_uid": "310a0596c0a459f496b8d6b57676d25e"} {"source_code": "n=gets.chomp.to_i\na=gets.chomp.split('').to_a.collect{|i| i.to_i}\nb=gets.chomp.split('').to_a.collect{|i| i.to_i}\nx=0\nn.times{|i| t = (a[i]-b[i]).abs; x+=[t,10-t].min}\nputs x\n", "positive_code": [{"source_code": "#!/usr/bin/env ruby\ngets\np$<.map{|e|e.chomp.chars.map(&:to_i)}.transpose.map{|x,y|(x-y).abs}.map{|e|[10-e,e].min}.reduce(:+)"}, {"source_code": "num = gets.to_i\nstart = gets\nfinish = gets\n\n# a > b\ndef cnt_forward(a, b)\n return a - b\nend\n\n# a > b\ndef cnt_backward(a, b)\n return (10 - a) + b\nend\n\n\n\nstart_a = start.split('').map { |s| s.to_i }\nfinish_a = finish.split('').map { |s| s.to_i }\ndata = start_a.zip(finish_a)\n\nresult = 0\n\ndata.each { |pair|\n fcnt = cnt_forward(pair.max, pair.min)\n bcnt = cnt_backward(pair.max, pair.min)\n if fcnt > bcnt\n result += bcnt\n else\n result += fcnt\n end\n}\n\nputs result"}, {"source_code": "# http://codeforces.com/contest/540/problem/A\nn = gets.chomp.to_i\norigin = gets.chomp.chars.map(&:to_i)\npresent = gets.chomp.chars.map(&:to_i)\n\narr = (0...n).map do |idx|\n a, b = [origin[idx], present[idx]].sort\n\n (b - a <= 10 - b + a) ? b - a : 10 - b + a\nend\n\nputs arr.inject(0, :+)\n"}, {"source_code": "n = gets.to_i\n\na = gets\nb = gets\n\ns = 0\n\n(0..n - 1).each do |i|\n ai = a[i].to_i\n bi = b[i].to_i\n x = (ai - bi).abs\n x = [x, (ai + 10 - bi).abs].min\n x = [x, (bi + 10 - ai).abs].min\n\n s += x\nend\n\nputs s"}, {"source_code": "def count(currNum, targetNum)\n\treturn (currNum - targetNum).abs if (currNum - targetNum).abs <= 5\n\treturn ([currNum, targetNum].min + 10) - ([currNum, targetNum].max)\nend\n\ndiskNum = gets.chomp.to_i\noriginState = gets.chomp.split('').map {|item| item.to_i}\ncorrectState = gets.chomp.split('').map {|item| item.to_i}\n\nresult = 0\nloopNum = 0\n\nuntil loopNum == originState.length\n\t#puts originState[loopNum]\n\t#puts correctState[loopNum]\n\tresult += count(originState[loopNum], correctState[loopNum])\n\n\t#puts \"result is #{result}\"\n\tloopNum += 1\nend\n\nputs result"}, {"source_code": "n=gets.chomp.strip.to_i\n#puts n\na=gets.chomp.strip\nb=gets.chomp.strip\ncount=0\ni=0\nwhile i5\n\t\tcount+=10-k\n\telse\n\t\tcount+=k\n\tend\n\ti+=1\nend\nputs count"}, {"source_code": "def f a\n a = -a if a < 0\n return 10 - a if a > 5\n a\nend\nn = gets.to_i; a = gets; b = gets;\nsum = 0\nn.times {|i| sum += f(a[i].to_i-b[i].to_i)}\nputs sum"}, {"source_code": "number = gets.to_i\norigin = gets\nfinal = gets\nans = 0\nfor i in 0...number\n c1 = origin[i]\n c2 = final[i]\n moves = (c1.to_i - c2.to_i).abs\n moves = 10 - moves if moves > 5 \n ans = ans + moves\nend\nputs ans"}, {"source_code": "n = gets.to_i\ns = gets.chomp\nt = gets.chomp\n\na = s.split(//).map{|r| r.to_i}\nb = t.split(//).map{|r| r.to_i}\n\ncounter = 0\nfor i in 0..n-1\n counter+=[(a[i]-b[i]).abs,(10-a[i]+b[i]).abs,(10-b[i]+a[i]).abs].min\nend\nputs counter"}, {"source_code": "mv = 0\ngets\ninit = gets.chomp.split(\"\").map &:to_i\npass = gets.chomp.split(\"\").map &:to_i\ninit.each_with_index do |value, index|\n mv += [(value - pass[index]).abs,\n (10 - value).abs + pass[index],\n (10 - pass[index]).abs + value].min\nend\nputs mv\n"}, {"source_code": " n = gets.chomp.to_i\n a = gets.chomp ; b = gets.chomp\n res = 0\n n.times do |i|\n res += [(a[i].to_i - b[i].to_i).abs , 10 - (a[i].to_i - b[i].to_i).abs].min\n end\n puts res"}, {"source_code": "n = gets.to_i\na = gets.split(//)\nb = gets.split(//)\nsum=0\n(0..n-1).each{ |i|\n a[i]=a[i].to_i\n b[i]=b[i].to_i\n sum += [(a[i]-b[i]).abs,10-(a[i]-b[i]).abs].min\n}\nprint sum\n"}, {"source_code": "n = gets.to_i\norigin = gets.chomp.chars.map(&:to_i)\nafter = gets.chomp.chars.map(&:to_i)\n\nans = 0\n(0..n-1).each do |i|\n o = origin[i]\n a = after[i]\n ans += [(o-a).abs, (o+10-a).abs, (a+10-o)].min\nend\nputs ans\n"}, {"source_code": "n=gets.chomp.to_i\n\nposition=gets.chomp.split(//)\n\npos=[]\nposition.each do |i|\n\tpos.push(i.to_i)\nend\n\ncode=gets.chomp.split(//)\n\nscript=[]\ncode.each do |i|\n\tscript.push(i.to_i)\nend\n\nchange=0\nfor item in(0..script.length-1)\n\tb=(pos[item]-script[item]).abs\n\tif b>5\n\t\tchange=change+10-b\n\telse\n\t\tchange=change+b\n\tend\nend\n\nputs change"}, {"source_code": "n=gets.to_i\ns=gets.chomp\nt=gets.chomp\n\nans=0\ns.chars.zip(t.chars).each{|a|\n\te1=a[0].to_i\n\te2=a[1].to_i\n\tf1=(e1-e2).abs\n\tf2=([e1,e2].min+10-[e1,e2].max).abs\n\tans=ans+[f1,f2].min\n}\nputs ans"}, {"source_code": "t = gets.chomp.to_i\nstart = gets.chomp.split('').map(&:to_i)\nstop = gets.chomp.split('').map(&:to_i)\n\nr = 0\nt.times.each do |i|\n# p [start[i],stop[i],(start[i]-stop[i]).abs]\n if ((start[i]-stop[i]).abs) > 5\n r += (10 - ((start[i]-stop[i]).abs))\n else\n r += (start[i]-stop[i]).abs\n end\nend\n\nputs r"}, {"source_code": "gets\na = gets.chomp\nb = gets.chomp\nr = 0\n0.upto(a.length) do |i|\n\tx = a[i].to_i\n\ty = b[i].to_i\n\tif x > y\n\n\t\tr += [ x - y, x + 10 - y, y + 10 - x ].min\n\telse\n\t\tr += [ y - x, y + 10 - y, x + 10 - y].min\n\tend\nend\nputs r"}, {"source_code": "n = gets.chomp.to_i\norig = gets.chomp\ncombi = gets.chomp\nfirst_state = orig.split(\"\")\ncombination = combi.split(\"\")\n\ncount = 0\nfor i in (0..n-1)\n\tif first_state[i].to_i - combination[i].to_i > 5\n\t\tcount += (10 - (first_state[i].to_i - combination[i].to_i))\n\telsif combination[i].to_i - first_state[i].to_i > 5\n\t\tcount += (10 - (combination[i].to_i - first_state[i].to_i))\n\telse\n\t\ttemp = combination[i].to_i - first_state[i].to_i\n\t\tif temp < 0\n\t\t\ttemp = temp * -1\n\t\t\tcount += temp\n\t\telse\n\t\t\tcount += temp\n\t\tend\n\tend\nend\t\t\n\nputs count"}, {"source_code": "gets\np gets.chomp.split(//).zip(gets.chomp.split(//)).map { |x, y| [(x.to_i - y.to_i).abs, (x.to_i - y.to_i - 10).abs, (x.to_i - y.to_i + 10).abs].min }.reduce(:+)"}, {"source_code": "n = gets.to_i\norigin = gets.split(\"\").collect{|i| i.to_i}\ndestin = gets.split(\"\").collect{|i| i.to_i}\nans = 0\n(0...n).each do |i|\n tmp = (origin[i]-destin[i]).abs\n ans += [tmp,10-tmp].min\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.chomp.chars.map(&:to_i)\nb = gets.chomp.chars.map(&:to_i)\nans = 0\nn.times do |i|\n c = (a[i] - b[i]).abs\n if c > 5\n c = 10 - c\n end\n ans += c\nend\nputs ans\n"}, {"source_code": "len = gets.to_i\ncurr = gets.strip\nansw = gets.strip\nacts = 0\n\nfor pos in 0...len\n if not curr[pos] == answ[pos]\n first = (curr[pos].to_i - answ[pos].to_i).abs\n acts += [first, 10 - first].min\n end\nend\n\nputs acts\n"}, {"source_code": "gets\na = gets.chomp.chars.map(&:to_i)\nb = gets.chomp.chars.map(&:to_i)\n\nputs(a.zip(b).inject(0) { |s, d| [d.max-d.min, 10-d.max+d.min].min + s })\n"}], "negative_code": [{"source_code": "n = gets.to_i\ns = gets.chomp\nt = gets.chomp\n\na = s.split(//).map{|r| r.to_i}\nb = t.split(//).map{|r| r.to_i}\n\ndef MIN(q,w,c)\n if q>w && ww && ww && w= 'n'.ord\n while k > 0 && c.ord > 'a'.ord\n k -= 1\n c = (c.ord - 1).chr\n end\n else\n while k > 0 && c.ord < 'z'.ord\n k -= 1\n c = c.ord.next.chr\n end\n end\n newStr += c\n if k == 0\n newStr += str[i+1..str.length]\n break\n end\nend\nif k == 0\n puts newStr\nelse\n puts -1\nend\n", "positive_code": [{"source_code": "$an_str = \"\"\n\ndef solve1(el)\n if el.ord + $k < 'z'.ord + 1\n $an_str += (el.ord + $k).chr\n $k = 0\n else\n $an_str += 'z'\n $k -= ('z'.ord - el.ord)\n end\nend\n\ndef solve2(el)\n if el.ord - $k >= 'a'.ord\n $an_str += (el.ord - $k).chr\n $k = 0\n else\n $an_str += 'a'\n $k -= (el.ord - 'a'.ord)\n end\nend\n\n_ , $k = gets.strip.split(' ').map(&:to_i)\nstr = gets.strip\n\nstr.each_char.with_index { |el, i|\n if $k == 0\n $an_str += str[i..str.length]\n break\n end\n if 'z'.ord - el.ord > el.ord - 'a'.ord\n solve1(el)\n else\n solve2(el)\n end\n}\n\nif !$k.zero?\n puts \"-1\"\nelse\n puts $an_str\nend\n"}, {"source_code": "$an_str = \"\"\n\ndef solve1(el)\n if el.ord + $k < 'z'.ord + 1\n $an_str += (el.ord + $k).chr\n $k = 0\n else\n $an_str += 'z'\n $k -= ('z'.ord - el.ord)\n end\nend\n\ndef solve2(el)\n if el.ord - $k >= 'a'.ord\n $an_str += (el.ord - $k).chr\n $k = 0\n else\n $an_str += 'a'\n $k -= (el.ord - 'a'.ord)\n end\nend\n\n_ , $k = gets.strip.split(' ').map(&:to_i)\nstr = gets.strip\n\nstr.each_char.with_index { |el, i|\n if $k == 0\n $an_str += str[i..str.length]\n break\n end\n if 'z'.ord - el.ord > el.ord - 'a'.ord\n solve1(el)\n else\n solve2(el)\n end\n}\n\nif !$k.zero?\n puts \"-1\"\nelse\n puts $an_str\nend\n"}], "negative_code": [{"source_code": "n, k = gets.split.map(&:to_i)\nstr = gets.chomp\nnewStr = \"\"\nstr.each_char.with_index do |c, i|\n if c.ord > 'n'.ord\n while k > 0 && c.ord > 'a'.ord\n k -= 1\n c = (c.ord - 1).chr\n end\n else\n while k > 0 && c.ord < 'z'.ord\n k -= 1\n c = c.ord.next.chr\n end\n end\n newStr += c\n if k == 0\n newStr += str[i+1..str.length]\n break\n end\nend\nif k == 0\n puts newStr\nelse\n puts -1\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nstr = gets\nnewStr = \"\"\nstr.each_char do |c|\n if c.ord > 'n'.ord\n while k > 0 && c.ord > 'a'.ord\n k -= 1\n c = (c.ord - 1).chr\n end\n else\n while k > 0 && c.ord < 'z'.ord\n k -= 1\n c = c.ord.next.chr\n end\n end\n newStr += c\nend\nif k == 0\n puts newStr\nelse\n puts -1\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nstr = gets.strip\nnewStr = \"\"\nstr.each_char.with_index do |c, i|\n if c.ord > 'n'.ord\n while k > 0 && c.ord > 'a'.ord\n k -= 1\n c = (c.ord - 1).chr\n end\n else\n while k > 0 && c.ord < 'z'.ord\n k -= 1\n c = c.ord.next.chr\n puts \"#{k} #{c}\"\n end\n end\n newStr += c\n if k == 0\n newStr += str[i+1..str.length]\n break\n end\nend\nif k == 0\n puts newStr\nelse\n puts -1\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nstr = gets.strip\nnewStr = \"\"\nstr.each_char.with_index do |c, i|\n if c.ord > 'n'.ord\n while k > 0 && c.ord > 'a'.ord\n k -= 1\n c = (c.ord - 1).chr\n end\n else\n while k > 0 && c.ord < 'z'.ord\n k -= 1\n c = c.ord.next.chr\n end\n end\n newStr += c\n if k == 0\n newStr += str[i+1..str.length]\n break\n end\nend\nif k == 0\n puts newStr\nelse\n puts -1\nend\n"}, {"source_code": "$an_str = \"\"\n\ndef solve1(el)\n if el.ord + $k < 'z'.ord + 1\n $an_str += (el.ord + $k).chr\n $k = 0\n else\n $an_str += 'z'\n $k -= ('z'.ord - el.ord)\n end\nend\n\ndef solve2(el)\n if el.ord - $k >= 'a'.ord\n $an_str += (el.ord - $k).chr\n $k = 0\n else\n $an_str += 'a'\n $k -= (el.ord - 'a'.ord)\n end\nend\n\n_ , $k = gets.strip.split(' ').map(&:to_i)\nstr = gets.strip\n\nstr.each_char { |el|\n puts $k\n if 'z'.ord - el.ord > el.ord - 'a'.ord\n solve1(el)\n else\n solve2(el)\n end\n}\n\nif !$k.zero?\n puts \"-1\"\nelse\n puts $an_str\nend\n"}, {"source_code": "c = ('a'..'z').to_a\n\n_ , k = gets.strip.split(' ').map(&:to_i)\nstr = gets.strip.split('')\nan_str = \"\"\n\nstr.each { |el|\n mx = -1\n c.each { |el2|\n if (el2.ord - el.ord).abs <= k\n mx = [mx, (el2.ord - el.ord).abs].max\n end\n }\n an_str += (el.ord + mx).chr\n k -= mx\n}\n\nif !k.zero?\n puts \"-1\"\nelse\n puts an_str\nend\n"}, {"source_code": "c = ('a'..'z').to_a\n\n_ , k = gets.strip.split(' ').map(&:to_i)\nstr = gets.strip.split('')\nan_str = \"\"\n\nstr.each { |el|\n mx = -1\n c.each { |el2|\n if (el2.ord - el.ord).abs <= k\n\n mx = [mx, el2.ord - el.ord].max\n end\n }\n an_str += (el.ord + mx).chr\n k -= mx\n}\n\nif !k.zero?\n puts \"-1\"\nelse\n puts an_str\nend\n\n\n\n"}], "src_uid": "b5d0870ee99e06e8b99c74aeb8e81e01"} {"source_code": "v = STDIN.readline().to_i\n@costs = STDIN.readline().split().collect(&:to_i)\n\ndef solve(v)\n x, xv = @costs.rindex(@costs.min), @costs.min\n @costs.collect! { |y| y - xv }\n n, r = v / xv, v % xv\n\n if n == 0\n STDOUT.write(-1)\n return\n end\n\n while r > 0\n y = @costs.rindex {|y| y <= r}\n break if !y || @costs[y] == 0\n STDOUT.write(y + 1)\n r -= @costs[y]\n n -= 1\n end\n\n STDOUT.write ((x+1).to_s * n)\nend\n\nsolve v", "positive_code": [{"source_code": "total = gets.to_i\na = gets.split(\" \").map{|ai| ai.to_i}\nres = []\ndigit = -1\nminw = a.min\na.each_index{|i|\n\tif a[i] == minw\n\t\tdigit = i\n\tend\n}\nmcnt = total / minw\nif mcnt == 0\n\tprint \"-1\"\nelsif total % a[digit] == 0\n\tprint (digit+1).to_s*mcnt\t\nelse\n\tresult = \"\"\n\trest = total % a[digit]\n\tquant = a[digit]\n\t8.downto(digit+1) {|i|\n\t\tn = 1\n\t\twhile rest + quant*n >= a[i]*n\n\t\t\tn += 1\n\t\tend\n\t\tn -= 1\n\t\tif n > 0\n\t\t\tmcnt -= n\n\t\t\tresult += (i+1).to_s * n\n\t\tend\n\t\trest = rest + quant*n - a[i]*n\n\t\tbreak if rest == 0\n\t}\n\tresult += (digit+1).to_s * mcnt\n\tprint result \nend"}, {"source_code": "m=gets.to_i\na=gets.chomp.split.map(&:to_i)\nmin,len=a.min,m/a.min\nif len==0\n\tputs \"-1\"\n\texit\nend\nmod=m%min\nfor i in 0...len\n\tj=8\n\twhile j>=0\n\t\tif a[j]-min<=mod\n\t\t\tmod-=a[j]-min\n\t\t\tbreak\n\t\tend\n\t\tj-=1\n\tend\n\tprint j+1\nend\nputs"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\n\nmin = arr.min\nmax = n/min\nmax_ind = arr.index(min)\ndigit = max_ind + 1\nif max == 0 \n\tans = \"-1\"\nelse\n\tans = \"#{digit}\" * max\n\tcurr_paint = n - (max * arr[digit - 1])\n\t# puts \"digit #{digit - 1}\"\n\t# puts \"#{curr_paint}\"\n\tpos = 0\n\twhile curr_paint >= 0\n\t\treplace = false\n \t\t8.downto(digit).each do |ind|\n \t\t\t# puts \"rem #{ind} #{curr_paint + arr[a-1] - arr[ind]}\"\n \t\t\tx = arr[ind] - arr[digit-1]\n \t\t\tif curr_paint >= x \n \t\t\t\tans[pos] = (ind + 1).to_s\n \t\t\t\tcurr_paint = curr_paint - x\n \t\t\t\treplace = true\n \t\t\t\tbreak\n \t\t\tend\n \t\tend\n \t\tbreak unless replace\n \t\tpos += 1\n \t\tbreak if pos == max\n\tend\n \t\nend\n\nputs ans"}, {"source_code": "v=gets.to_i\na=gets.split.map(&:to_i)\nb,c=a.each_with_index.to_a.min_by{|x,i|[x,-i]}\nc+=1\nd=v/b\n(p -1;exit)if d==0\ne=d*b\nf=8\nr=''\nwhile true\n f-=1 while v-e+b 0\n best_digit = a.select{|d| d[1] <= p}.first\n can = true if best_digit\nend\nif !can\n puts -1\nelse\n ans = [best_digit[0]] * (p / best_digit[1])\n p -= best_digit[1] * ans.length\n # puts p\n a = a.sort_by{|d| -d[0]}\n ans.each_with_index do |dig_in_ans, ind|\n better_dig = a.select{|d| dig_in_ans < d[0] && d[1] - inp[dig_in_ans - 1] <= p}.first\n break if better_dig.nil?\n # puts better_dig.join(\" - \")\n ans[ind] = better_dig[0]\n p -= better_dig[1] - inp[dig_in_ans - 1]\n end\n puts ans.join(\"\")\nend\n"}, {"source_code": "#! /usr/bin/env ruby\n\npaint = STDIN.gets.to_i\ndigits = STDIN.gets.to_s.split(' ').map(&:to_i).first(9)\n\ndef paint_fence(paint, digits)\n if paint == 0 || digits.min > paint\n puts '-1'\n return\n end\n\n min = 100000\n idx = nil\n digits.each_with_index do |require_digit, i|\n next if require_digit > min\n\n min = require_digit\n idx = i + 1\n end\n\n count = paint / min\n rest = paint % min\n suppl = []\n\n end_flg = false\n while rest > 0 && !end_flg\n digits.reverse.each_with_index do |require_digit, i|\n if (digit = 9 - i) <= idx\n end_flg = true\n break\n end\n if rest >= (require_digit - min)\n rest -= (require_digit - min)\n suppl << digit\n break\n end\n end\n end\n\n puts (idx.to_s * count).chars.map {|i|\n (alter = suppl.shift) ? alter : i\n }.join\nend\n\npaint_fence(paint, digits)\n\n"}], "negative_code": [{"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\ndp = []\narr.each do |a|\n\tdp << n / a\nend\nmax = dp.max\nputs \"#{dp}\"\nmax_ind = dp.rindex(max)\ndigit = max_ind + 1\nif max == 0 \n\tans = \"-1\"\nelse\n\tans = \"#{digit}\" * max\n\tcurr_paint = n - max * arr[digit - 1]\n\tputs \"#{curr_paint}\"\n\tans.each_char.with_index do |a,i|\n \t\ta = a.to_i \t\t\n \t\t8.downto(0).each do |ind|\n \t\t\t# puts \"rem #{ind} #{curr_paint + arr[a-1] - arr[ind]}\"\n \t\t\tif curr_paint + arr[a-1] - arr[ind] >= 0 \n \t\t\t\tans[i] = (ind + 1).to_s\n \t\t\t\tcurr_paint = curr_paint + arr[a-1] - arr[ind]\n \t\t\t\tbreak\n \t\t\tend\n \t\tend\n \tend\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\ndp = []\narr.each do |a|\n\tdp << n / a\nend\nmax = dp.max\n# puts \"#{dp}\"\nmax_ind = dp.index(max)\ndigit = max_ind + 1\nif max == 0 \n\tans = \"-1\"\nelse\n\tans = \"#{digit}\" * max\n\tcurr_paint = n - (max * arr[digit - 1])\n\t# puts \"digit #{digit - 1}\"\n\t# puts \"#{curr_paint}\"\n\tpos = 0\n\twhile curr_paint > 0\t\n\t\treplace = false\t\n \t\t8.downto(digit).each do |ind|\n \t\t\t# puts \"rem #{ind} #{curr_paint + arr[a-1] - arr[ind]}\"\n \t\t\tx = arr[ind] - arr[digit-1]\n \t\t\tif curr_paint >= x \n \t\t\t\tans[pos] = (ind + 1).to_s\n \t\t\t\tcurr_paint = curr_paint - x\n \t\t\t\treplace = true\n \t\t\t\tbreak\n \t\t\tend\n \t\tend\n \t\tbreak unless replace\n \t\tpos += 1\n \t\tbreak if pos == max\n\tend\n \t\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\ndp = []\narr.each do |a|\n\tdp << n / a\nend\nmax = dp.max\n# puts \"#{dp}\"\nmax_ind = dp.rindex(max)\ndigit = max_ind + 1\nif max == 0 \n\tans = \"-1\"\nelse\n\tans = \"#{digit}\" * max\n\tcurr_paint = n - max * arr[digit - 1]\n\t# puts \"#{curr_paint}\"\n\tans.each_char.with_index do |a,i|\n \t\ta = a.to_i \t\t\n \t\t8.downto(0).each do |ind|\n \t\t\t# puts \"rem #{ind} #{curr_paint + arr[a-1] - arr[ind]}\"\n \t\t\tif curr_paint + arr[a-1] - arr[ind] >= 0 \n \t\t\t\tans[i] = (ind + 1).to_s\n \t\t\t\tcurr_paint = curr_paint + arr[a-1] - arr[ind]\n \t\t\t\tbreak\n \t\t\tend\n \t\tend\n \tend\nend\n\nputs ans"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\ndp = []\narr.each do |a|\n\tdp << n / a\nend\nmax = dp.max\nmax_ind = dp.rindex(max)\ndigit = max_ind + 1\nputs max == 0 ? \"-1\" : \"#{digit}\" * max"}, {"source_code": "v=gets.to_i\na=gets.split.map(&:to_i)\nb,c=a.each_with_index.to_a.min_by{|x,i|[x,-i]}\nc+=1\nd=v/b\n(p -1;exit)if d==0\ne=d*b\nf=8\nr=''\nwhile true\n f-=1 while v-e+b 0\n digit = a.select{|d| d[1] <= p}.first\n break if digit.nil?\n can = true\n p -= digit[1]\n printf(\"%d\", digit[0])\nend\nif !can\n puts -1\nelse\n puts\nend\n"}, {"source_code": "p = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\na = (1..a.length).zip(a).sort_by{|d| [d[1], -d[0]]}\ninitp = p\ncan = true\nwhile p > 0\n digit = a.select{|d| d[1] <= p}.first\n if digit.nil? && p == initp\n can = false\n break\n end\n p -= digit[1]\n printf(\"%d\", digit[0])\nend\nif can\n puts\nelse\n puts -1\nend"}, {"source_code": "p = gets.strip.to_i\na = gets.strip.split.map(&:to_i)\na = (1..a.length).zip(a).sort_by{|d| [d[1], -d[0]]}\ninitp = p\ncan = true\nwhile p > 0\n digit = a.select{|d| d[1] <= p}.first\n if digit.nil? && p == initp\n can = false\n break\n end\n p -= digit[1]\n printf(\"%d\", digit[0])\nend\nif !can || p == 0\n puts -1\nelse\n puts\nend\n"}, {"source_code": "v = STDIN.readline().to_i\n@costs = STDIN.readline().split().collect(&:to_i)\n@memo = {}\n\ndef solve(v)\n return -1 if v <= 0\n return @memo[v] if @memo[v]\n\n ret = 0\n @costs.each_with_index do |x, idx|\n if v >= x\n rest = solve(v - x) * 10\n ans = [0, rest].max + idx + 1\n ret = [ret, ans].max\n end\n end\n\n @memo[v] = ret\nend\n\nputs solve(v).to_s"}, {"source_code": "v = STDIN.readline().to_i\n@costs = STDIN.readline().split().collect(&:to_i)\n\n#v = 1000000\n#@costs = %w(1 1 1 1 1 1 1 1 1).collect(&:to_i)\n#v = 898207\n#@costs = %w(99745 99746 99748 99752 99760 99776 99808 99872 100000).collect(&:to_i)\n\n\ndef solve(v)\n x, xv = @costs.rindex(@costs.min), @costs.min\n @costs.collect! { |y| y - xv }\n n, r = v / xv, v % xv\n\n return -1 if n == 0\n\n while r > 0\n y = @costs.rindex {|y| y <= r}\n break if !y || @costs[y] == 0\n STDOUT.write(y + 1)\n r -= @costs[y]\n n -= 1\n end\n\n while n > 0\n STDOUT.write(x + 1)\n n -= 1\n end\nend\n\nsolve v\n"}, {"source_code": "v = STDIN.readline().to_i\n@costs = STDIN.readline().split().collect(&:to_i)\n#v = 5\n#@costs = %w(5 4 3 2 1 2 3 4 5).collect(&:to_i)\n\ndef solve(v)\n x, xv = @costs.rindex(@costs.min), @costs.min\n @costs.collect! { |y| y - x }\n n, r = v / xv, v % xv\n\n return -1 if n == 0\n\n ans = []\n while r > 0\n y = @costs.rindex {|y| y <= x}\n break if !y || @costs[y] == 0\n ans << (y + 1)\n r -= @costs[y]\n end\n\n while ans.length < n\n ans << (x + 1)\n end\n\n ans.collect(&:to_s).join().to_i\nend\n\nputs solve(v).to_s\n"}, {"source_code": "def iter1 t, arr, lh\n\tcnt = t/arr[0]\n\tdigit = lh[arr[0]]\n\tarr[1..-1].each {|cl|\n\t\tccnt = t/cl\n\t\tbreak if ccnt < cnt\n\t\tdigit = lh[cl] if lh[cl] > digit\n\t}\n\tcnt == 0 ? -1 : digit\nend\n\ntotal = gets.to_i\na = gets.split(\" \").map{|ai| ai.to_i}\nln = {}\na.each_index{|i| ln[a[i]] = i}\nlen = a.sort.uniq\nres = []\nwhile total>0\n\tcd = iter1(total, len, ln)\n\tbreak if cd == -1\n\tres << cd + 1\n\ttotal -= a[cd]\nend\n\nif res.size == 0\n\tprint \"-1\"\nelse\n\tprint res.sort.reverse.join\nend"}, {"source_code": "def iter t, arr\n\tmlen = 0\n\tdigit = -1\n\tarr.each_index {|i|\n\t\tcml = t/arr[i]\n\t\t# digit weights are ordered from 1 to 9\n\t\tif cml >= mlen\n\t\t\tmlen = cml\n\t\t\tdigit = i\n\t\tend\n\t}\n\tmlen == 0 ? -1 : digit\nend\n\ntotal = gets.to_i\na = gets.split(\" \").map{|ai| ai.to_i}\nexit if a.include?(0)\nres = []\nwhile total > 0\n\tcd = iter(total, a)\n\tbreak if cd == -1\n\tres << cd + 1\n\ttotal -= a[cd]\nend\n\nif res.size == 0\n\tprint \"-1\"\nelse\n\tprint res.sort.reverse.join\nend"}], "src_uid": "ace9fbabc2eda81b4e4adf4f2d5ad402"} {"source_code": "def func(i)\n if i == 0\n 0\n else\n func(i / 2) + i % 2\n end\nend\n\ndef run\n n = ARGF.readline.to_i\n list = ARGF.readline.split.map(&:to_i)\n\n hash = Hash.new(0)\n list.each { |a| hash[func(a)] += 1 }\n\n cnt = 0\n hash.each do |key, val|\n cnt += (val * (val - 1)) / 2\n end\n\n puts cnt\nend\n\nrun if $0 == __FILE__\n", "positive_code": [{"source_code": "def no_of_ones t\n\tp = 0\n\twhile t>0 \n\t p += (t%2)\n\t t = t/2\n\tend\n\treturn p\nend\n\nn =gets.chomp.to_i\na = [0]*40\narr = gets.chomp.split(\" \").collect! {|x| x.to_i}\narr.each { |k|\t\n\ta[no_of_ones(k)] += 1\n}\n\ns = 0\na.each { |p|\n\ts += (p*(p-1))/2\n}\n\np s"}, {"source_code": "def func(x)\n return 0 if x == 0\n return func(x / 2) if x % 2 == 0\n func(x / 2) + 1\nend\n\nn = gets.to_i\nf = Array.new(100,0)\ngets.split(' ').each { |i|\n f[func(i.to_i)] += 1\n}\nans = 0\nf.each { |i| \n j = i.to_i\n ans += j * (j - 1) / 2\n}\np ans\n\n"}], "negative_code": [{"source_code": "def run\n n = ARGF.readline.to_i\n list = ARGF.readline.split.map(&:to_i)\n\n f = [0]\n 1.upto(10 ** 5) {|i| f[i] = f[i / 2] + i % 2 }\n\n hash = Hash.new(0)\n list.each { |a| hash[f[a]] += 1 }\n\n cnt = 0\n hash.each do |key, val|\n cnt += (val * (val - 1)) / 2\n end\n\n puts cnt\nend\n\nrun if $0 == __FILE__\n"}], "src_uid": "c547e32f114546638973e0f0dd16d1a4"} {"source_code": "n, j = gets.to_i, 1; (1...n).each { |i| puts (g=(j+=i)%n).zero? ? n : g }", "positive_code": [{"source_code": "puts (1...n=gets.to_i).map{|i|i*(i+1)/2%n+1}*' '\n"}, {"source_code": "n=gets.to_i;k=[];1.upto(n-1) {|x| k<<((x*(x+1)/2)%n+1) };puts k*' '"}, {"source_code": "n = gets.to_i\n\ncurr = 0\nresult = \"\"\nfor i in 1..n-1\n curr = (curr + i) % n\n result += (curr+1).to_s + \" \"\nend\n\nputs(result)"}, {"source_code": "n = gets.chomp.to_i\n\nstep = 1\nlast_child = 1\n(n - 1).times do\n last_child += step\n step += 1\n ch = last_child % n\n print \"#{ch == 0 ? n : ch} \"\nend\nputs"}, {"source_code": "puts (1...n=gets.to_i).map{|i|i*(i+1)/2%n+1}*' '\n"}, {"source_code": "n = gets.to_i\na = []\na[0] = k = 1\nfor i in 1...n\n a[i] = a[i - 1] + k\n a[i] %= n if a[i] > n\n k += 1\nend\nputs a[1..-1] * ' '"}, {"source_code": "puts (1...n=gets.to_i).map{|i|i*(i+1)/2%n+1}*' '\n"}, {"source_code": "n = gets.to_i\n\ncur, step = 0, 0\n\n(n - 1).times do\n step += 1\n cur = (cur + step) % n\n printf(\"%d \", cur + 1)\nend\n\nprintf(\"\\n\")\n"}, {"source_code": "n, c, str = gets.to_i, 1, \"\"\n0.upto(n - 2) { |i| str << (c = ((c + i) % n) + 1).to_s << \" \" }\nprint str.chop"}, {"source_code": "puts (1...n=gets.to_i).map{|i|i*(i+1)/2%n+1}*' '\n"}, {"source_code": "n = gets.chop.to_i\nkids = Array.new\ni = 0\na = 1\n(n - 1).times do\n i += 1\n a += i\n (a > n)? a = a - n : a \n kids.push(a)\nend\n\nputs kids"}, {"source_code": "n,i,a = gets.to_i,0,1;(n - 1).times{i += 1;a += i;(a > n)? a = a - n : a;print \"#{a} \"}"}, {"source_code": "n = gets.chop.to_i\ni = 0\na = 1\n(n - 1).times do\n i += 1\n a += i\n (a > n)? a = a - n : a \n print \"#{a} \"\nend\n"}, {"source_code": "c=0\nn=gets.to_i\n(1..n-1).each{|i|\n\tc=(c+i)%n\n\tprint (c+1),\" \"\n}\n"}, {"source_code": "puts (1...n=gets.to_i).map{|i|i*(i+1)/2%n+1}*' '\n"}, {"source_code": "puts (1...n=gets.to_i).map{|i|i*(i+1)/2%n+1}*' '\n"}, {"source_code": "n = gets.to_i\npasser = 0\npassed = []\n(1...n).each do |i|\n passer += i\n passed << passer % n + 1\nend\nputs passed.join(\" \")"}, {"source_code": "\nn = gets.to_i\n\nr = 1\nres = []\n1.upto(n-1) do |m|\n r += m\n r %= n\n r = n if r == 0\n res << r\n res << ' '\nend\nres.pop\nres.each {|e| print e}\n"}, {"source_code": "puts (1...n=gets.to_i).map{|i|i*(i+1)/2%n+1}*' '"}, {"source_code": "puts (1...n=gets.to_i).map{|i|i*(i+1)/2%n+1}*' '\n"}, {"source_code": "puts (1...n=gets.to_i).map{|i|i*(i+1)/2%n+1}*' '\n"}, {"source_code": "n = gets.to_i\ni=1\n(n-1).times{|x|i+=x;i%=n;i+=1;print i;print \" \"}"}, {"source_code": "puts (1...n=gets.to_i).map{|i|i*(i+1)/2%n+1}*' '"}, {"source_code": "n=gets.to_i\n\nc=[*1..n]\ns=0\nfor i in 1..n-1\n\ts+=i\n\tif c[s].nil?\n\t\tprint \"#{c[s%n]} \"\n\telse\n\t\tprint \"#{c[s]} \"\n\tend\nend\n"}, {"source_code": "puts (1...n=gets.to_i).map{|i|i*(i+1)/2%n+1}*' '"}, {"source_code": "puts (1...n=gets.to_i).map{|i|(i*(i+1)/2)%n+1}*' '"}], "negative_code": [{"source_code": "n = gets.to_i\npasser = 1\npassed = []\n(1...n).each do |i|\n passer = (passer + i) % n\n passed << passer\nend\nputs passed.join(\" \")"}, {"source_code": "\nn = gets.to_i\n\nr = 1\nres = []\n1.upto(n-1) do |m|\n r += m\n r %= n\n res << r\n res << ' '\nend\nres.pop\nres.each {|e| print e}\n"}, {"source_code": "\nn = gets.to_i\n\nr = 1\nres = []\n1.upto(n-1) do |m|\n r += m\n r %= n\n res << r\n res << ' '\nend\nres.pop\nres.each {|e| print e}\n\n"}, {"source_code": "\ndef f(n)\n l = [nil] * 5 + ['S','M','L','XL','XXL'] + [nil] * 5\n i = n+5\n r = []\n r << l[i]\n r << l[i+1]\n r << l[i-1]\n r << l[i+2]\n r << l[i-2]\n r << l[i+3]\n r << l[i-3]\n r << l[i+4]\n r << l[i-4]\n r << l[i+5]\n r << l[i-5]\n r.select {|e| e}\nend\n\npr = []\nl = ['S','M','L','XL','XXL']\n1.upto(5) {|n| pr << f(n)}\n\n\n\n\na = gets.split(' ')\na = a.map{|e| e.to_i}\n\ngets.to_i.times do\n size = gets.chomp\n tl = pr[l.index(size)]\n n = 0\n while a[l.index(tl[n])] == 0\n n += 1\n end\n a[l.index(tl[n])] -= 1\n puts tl[n]\nend\n\n\n"}, {"source_code": "\nn = gets.to_i\n\nr = 1\n1.upto(n-1) do |m|\n r += m\n r %= n\n print r,\" \"\nend\n"}, {"source_code": "n, j = gets.to_i, 1; (1...n).each { |i| puts (j+=i)%n }"}, {"source_code": "n=gets.to_i\n\nman_id = 1\n[*1..n-1].each do |v|\n\tman_id+=v\n\t\n\trem=man_id%n\n\trem+=1 if rem==0\n\tprint \"#{rem} \"\t\n\t\t\n\tman_id=rem\nend\n"}, {"source_code": "puts (1...n=gets.to_i).map{|i|((i*(i+1)/2+1))%n}*' '"}, {"source_code": "n = gets.chomp.to_i\nputs 2 or exit if n == 2\nstep = 1\nlast_child = 1\n(n - 1).times do\n last_child += step\n step += 1\n print \"#{last_child % n} \"\nend\nputs"}, {"source_code": "n, c, str = gets.to_i, 1, \"\"\n1.upto(n - 1) { |i| str << (c = (c + i) % n).to_s << \" \" }\nprint str.chop"}, {"source_code": "n, c, str = gets.to_i, 1, \"\"\n1.upto(n - 1) do |i|\n\tc = (c + i) % n\n\tc = 4 if c == 0\n\tstr << c.to_s << \" \"\nend\nprint str.chop\n"}, {"source_code": "n, c, str = \"3\".to_i, 0, \"\"\n1.upto(n - 1) { |i| str << (c = (c + i) % n).to_s << \" \" }\nprint str.chop"}, {"source_code": "n, c, str = gets.to_i, 0, \"\"\n1.upto(n - 1) { |i| str << (c = (c + i) % n).to_s << \" \" }\nprint str.chop"}], "src_uid": "7170c40405cf7a5e0f2bd15e4c7d189d"} {"source_code": "def get_array(hash, pos)\n arr = []\n until pos.nil? or pos == 0\n arr.push(pos)\n pos = hash[pos]\n end\n arr\nend\n\nn = gets.to_i\n\nprev = {}\nfor s in STDIN.each_line.take n\n p, n = s.split(' ').map &:to_i\n prev[p] = n\nend\n\nfirst = (prev.keys - prev.values)[0]\nfrs = get_array(prev, first)\nscn = get_array(prev, prev[0])\n\nputs frs.zip(scn).join(\" \")", "positive_code": [{"source_code": "require 'set'\nn = gets.to_i\na = Set.new\nb = Set.new\nmap = Hash.new\n(0...n).each do |i|\n aa, bb = gets.split.collect{|j| j.to_i}\n a.add(aa)\n b.add(bb)\n map[aa] = bb\nend\nans = Array.new(n)\nans[0] = (a-b).to_a[0]\nans[1] = map[0]\nfor i in 2...n\n ans[i] = map[ans[i-2]]\nend\nputs ans.join(\" \")\n"}, {"source_code": "def get_array(hash, pos, array, ind)\n until pos.nil? or pos == 0\n array[ind] = pos\n pos = hash[pos]\n ind += 2\n end\nend\n\nn = gets.to_i\narray = Array.new(n, 0)\n\nprev = {}\nfor s in STDIN.each_line.take n\n p, n = s.split(' ').map &:to_i\n prev[p] = n\nend\n\nfirst = (prev.keys - prev.values)[0]\nget_array(prev, first, array, 0)\nget_array(prev, prev[0], array, 1)\n\nputs array.join(\" \")"}, {"source_code": "def get_array(hash, pos)\n arr = []\n until pos.nil? or pos == 0\n arr << pos\n pos = hash[pos]\n end\n arr\nend\n\nn = gets.to_i\n\nprev, after = {}, {}\nfor s in STDIN.each_line.take n\n p, n =s.split(' ').map &:to_i\n\n prev[p], after[n] = n, p\nend\n\nfirst = (prev.keys - after.keys)[0]\nfrs = get_array(prev, first)\n\nscn = get_array(prev, prev[0])\n\nputs frs.zip(scn).join(\" \")"}, {"source_code": "def get_array(hash, pos)\n arr = []\n until pos.nil? or pos == 0\n arr << pos\n pos = hash[pos]\n end\n arr\nend\n\nn = gets.to_i\n\nprev = {}\nfor s in STDIN.each_line.take n\n p, n =s.split(' ').map &:to_i\n\n prev[p] = n\nend\n\nfirst = (prev.keys - prev.values)[0]\nfrs = get_array(prev, first)\n\nscn = get_array(prev, prev[0])\n\nputs frs.zip(scn).join(\" \")"}, {"source_code": "n = gets.to_i\nbef_s = {}\naft_s = {}\n\nn.times do\n bef, aft = gets.split.map(&:to_i)\n bef_s[bef] = aft\n aft_s[aft] = bef\nend\n\nans = []\nstart_id = 0\nstart_pos = 1\nwhile true\n if bef_s[start_id] and start_pos < n\n ans[start_pos] = bef_s[start_id]\n start_id = bef_s[start_id]\n start_pos += 2\n else\n break\n end\nend\n\nbef_s.each_key do |k|\n is_break = false\n if !aft_s[k]\n start_id = k\n break\n end\nend\n\nans[0] = start_id\nstart_pos = 2\nwhile true\n if bef_s[start_id] and start_pos < n\n ans[start_pos] = bef_s[start_id]\n start_id = bef_s[start_id]\n start_pos += 2\n else\n break\n end\nend\n\nputs ans.join(' ')\n"}], "negative_code": [{"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\ndef increment(i, a)\n i += 1\n i = 0 if a.length <= i\n i\nend\n\nn = gets.to_i\n\nans = Array.new(n, -1)\nbef_s = []\naft_s = []\nn.times do |i|\n bef, aft = gets.split.map(&:to_i)\n if (bef != 0 and aft != 0) and (!ans.index(bef) and !ans.index(aft))\n bef_s << bef\n aft_s << aft\n next\n else\n ans[1] = aft and next if bef == 0\n ans[-2] = bef and next if aft == 0\n\n if ans.index(bef)\n index = ans.index(bef)\n ans[index + 2] = aft\n next\n end\n\n if ans.index(aft)\n index = ans.index(aft)\n ans[index - 2] = bef\n next\n end\n end\nend\n\nformals = []\nwhile 0 < bef_s.length\n bef = bef_s.shift\n aft = aft_s.shift\n\n if ans.index(bef)\n i = ans.index(bef)\n tmp_b = ans[0..(i + 1)]\n tmp_a = ans[(i + 2)..-1]\n tmp_a.unshift(aft)\n ans = tmp_b + tmp_a\n next\n end\n\n if ans.index(aft)\n i = ans.index(aft)\n tmp_b = nil\n tmp_a = nil\n if 0 <= i - 2\n tmp_b = ans[0..(i - 2)]\n tmp_a = ans[(i - 1)..-1]\n tmp_a.unshift(bef)\n ans = tmp_b + tmp_a\n else\n ans.unshift(bef)\n end\n next\n end\n\n if formals.length == 0\n formals << bef\n formals << aft\n next\n end\n\n if formals.index(bef)\n i = formals.index(bef)\n if i + 2 < formals.length\n tmp_b = formals[0..(i + 1)]\n tmp_a = formals[(i + 2)..-1]\n tmp_a.unshift(aft)\n formals = tmp_b + tmp_a\n else\n formals << aft\n end\n next\n end\n\n if formals.index(aft)\n i = formals.index(aft)\n tmp_b = nil\n tmp_a = nil\n if 0 <= i - 2\n tmp_b = formals[0..(i - 2)]\n tmp_a = formals[(i - 1)..-1]\n tmp_a.unshift(bef)\n formals = tmp_b + tmp_a\n else\n formals.unshift(bef)\n end\n next\n end\n\n bef_s << bef\n aft_s << aft\nend\n\nformals.each do |i|\n if ans.index(-1) and !ans.index(i)\n index = ans.index(-1)\n puts \"#{ans}\"\n ans[index] = i\n end\nend\n\nputs ans.uniq.select {|i| i != -1}.join(' ')\n"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\ndef increment(i, a)\n i += 1\n i = 0 if a.length <= i\n i\nend\n\nn = gets.to_i\n\nans = Array.new(n, -1)\nbef_s = []\naft_s = []\nn.times do |i|\n bef, aft = gets.split.map(&:to_i)\n if (bef != 0 and aft != 0) and (!ans.index(bef) and !ans.index(aft))\n bef_s << bef\n aft_s << aft\n next\n else\n ans[1] = aft and next if bef == 0\n ans[-2] = bef and next if aft == 0\n\n if ans.index(bef)\n index = ans.index(bef)\n ans[index + 2] = aft\n next\n end\n\n if ans.index(aft)\n index = ans.index(aft)\n ans[index - 2] = bef\n next\n end\n end\nend\n\nformals = []\nwhile 0 < bef_s.length\n bef = bef_s.shift\n aft = aft_s.shift\n\n if ans.index(bef)\n i = ans.index(bef)\n tmp_b = ans[0..(i + 1)]\n tmp_a = ans[(i + 2)..-1]\n tmp_a.unshift(aft)\n ans = tmp_b + tmp_a\n next\n end\n\n if ans.index(aft)\n i = ans.index(aft)\n tmp_b = nil\n tmp_a = nil\n if 0 <= i - 2\n tmp_b = ans[0..(i - 2)]\n tmp_a = ans[(i - 1)..-1]\n tmp_a.unshift(bef)\n ans = tmp_b + tmp_a\n else\n ans.unshift(bef)\n end\n next\n end\n\n if formals.length == 0\n formals << bef\n formals << aft\n next\n end\n\n if formals.index(bef)\n i = formals.index(bef)\n if i + 2 < formals.length\n tmp_b = formals[0..(i + 1)]\n tmp_a = formals[(i + 2)..-1]\n tmp_a.unshift(aft)\n formals = tmp_b + tmp_a\n else\n formals << aft\n end\n next\n end\n\n if formals.index(aft)\n i = formals.index(aft)\n tmp_b = nil\n tmp_a = nil\n if 0 <= i - 2\n tmp_b = formals[0..(i - 2)]\n tmp_a = formals[(i - 1)..-1]\n tmp_a.unshift(bef)\n formals = tmp_b + tmp_a\n else\n formals.unshift(bef)\n end\n next\n end\n\n bef_s << bef\n aft_s << aft\nend\n\nformals.each do |i|\n if ans.index(-1) and !ans.index(i)\n index = ans.index(-1)\n ans[index] = i\n end\nend\n\nputs ans.select {|i| i != -1}.join(' ')\n"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\ndef increment(i, a)\n i += 1\n i = 0 if a.length <= i\n i\nend\n\nn = gets.to_i\n\nans = Array.new(n, -1)\nbef_s = []\naft_s = []\nn.times do |i|\n bef, aft = gets.split.map(&:to_i)\n if (bef != 0 and aft != 0) and (!ans.index(bef) and !ans.index(aft))\n bef_s << bef\n aft_s << aft\n next\n else\n ans[1] = aft and next if bef == 0\n ans[-2] = bef and next if aft == 0\n\n if ans.index(bef)\n index = ans.index(bef)\n ans[index + 2] = aft\n next\n end\n\n if ans.index(aft)\n index = ans.index(aft)\n ans[index - 2] = bef\n next\n end\n end\nend\n\nformals = []\nwhile 0 < bef_s.length\n bef = bef_s.shift\n aft = aft_s.shift\n\n if ans.index(bef)\n i = ans.index(bef)\n tmp_b = ans[0..(i + 1)]\n tmp_a = ans[(i + 2)..-1]\n tmp_a.unshift(aft)\n ans = tmp_b + tmp_a\n next\n end\n\n if ans.index(aft)\n i = ans.index(aft)\n tmp_b = nil\n tmp_a = nil\n if 0 <= i - 2\n tmp_b = ans[0..(i - 2)]\n tmp_a = ans[(i - 1)..-1]\n tmp_a.unshift(bef)\n ans = tmp_b + tmp_a\n else\n ans.unshift(bef)\n end\n next\n end\n\n if formals.length == 0\n formals << bef\n formals << aft\n next\n end\n\n if formals.index(bef)\n i = formals.index(bef)\n if i + 2 < formals.length\n tmp_b = formals[0..(i + 1)]\n tmp_a = formals[(i + 2)..-1]\n tmp_a.unshift(aft)\n formals = tmp_b + tmp_a\n else\n formals << aft\n end\n next\n end\n\n if formals.index(aft)\n i = formals.index(aft)\n tmp_b = nil\n tmp_a = nil\n if 0 <= i - 2\n tmp_b = formals[0..(i - 2)]\n tmp_a = formals[(i - 1)..-1]\n tmp_a.unshift(bef)\n formals = tmp_b + tmp_a\n else\n formals.unshift(bef)\n end\n next\n end\n\n bef_s << bef\n aft_s << aft\nend\n\nputs \"ans: #{ans}, formals: #{formals}\"\nformals.each do |i|\n if ans.index(-1) and !ans.index(i)\n index = ans.index(-1)\n ans[index] = i\n end\nend\n\nputs ans.select {|i| i != -1}.join(' ')\n"}, {"source_code": "def find_pos(arr, pos, reverse = false)\n p = reverse ? 1 : 0\n\n arr.each_with_index do |x, i|\n if pos == x[p]\n return i\n end\n end\n\n -1\nend\n\nn = gets.to_i\n\narr = []\nfor s in STDIN.each_line.take n\n i, j = s.split(\" \").map &:to_i\n\n arr << [i, j]\nend\n\npos, start = 1, 0\nresult = Array.new(n, 0)\nwhile pos < n\n p = find_pos(arr, start)\n\n if p != -1\n result[pos] = arr[p][1]\n start = arr[p][1]\n pos += 2\n else\n break\n end\nend\n\npos = arr.length - 2\nstart = 0\nwhile pos < n\n p = find_pos(arr, start, true)\n\n if p != -1\n result[pos] = arr[p][0]\n start = arr[p][0]\n pos -= 2\n else\n break\n end\n\nend\n\nputs result.inspect"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\ndef increment(i, a)\n i += 1\n i = 0 if a.length <= i\n i\nend\n\nn = gets.to_i\n\nans = Array.new(n, -1)\nbef_s = []\naft_s = []\nn.times do |i|\n bef, aft = gets.split.map(&:to_i)\n if (bef != 0 and aft != 0) and (!ans.index(bef) and !ans.index(aft))\n bef_s << bef\n aft_s << aft\n next\n else\n ans[1] = aft and next if bef == 0\n ans[-2] = bef and next if aft == 0\n\n if ans.index(bef)\n index = ans.index(bef)\n ans[index + 2] = aft\n next\n end\n\n if ans.index(aft)\n index = ans.index(aft)\n ans[index - 2] = bef\n next\n end\n end\nend\n\nformals = []\nwhile 0 < bef_s.length\n bef = bef_s.shift\n aft = aft_s.shift\n\n if formals.length == 0\n formals << bef\n formals << aft\n next\n end\n\n if formals.index(bef)\n i = formals.index(bef)\n tmp_b = formals[0..(i + 1)]\n tmp_a = formals[(i + 2)..-1]\n tmp_a.unshift(aft)\n formals = tmp_b + tmp_a\n next\n end\n\n if formals.index(aft)\n i = formals.index(aft)\n tmp_b = nil\n tmp_a = nil\n if 0 <= i - 2\n tmp_b = formals[0..(i - 2)]\n tmp_a = formals[(i - 1)..-1]\n tmp_a.unshift(bef)\n formals = tmp_b + tmp_a\n else\n formals.unshift(bef)\n end\n next\n end\n bef_s << bef\n aft_s << aft\nend\n\nformals.each do |i|\n if ans.index(-1)\n index = ans.index(-1)\n ans[index] = i\n end\nend\n\nputs ans.join(' ')\n"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\ndef increment(i, a)\n i += 1\n i = 0 if a.length <= i\n i\nend\n\nn = gets.to_i\n\nans = Array.new(n, -1)\nbef_s = []\naft_s = []\nn.times do |i|\n bef, aft = gets.split.map(&:to_i)\n if (bef != 0 and aft != 0) and (!ans.index(bef) and !ans.index(aft))\n bef_s << bef\n aft_s << aft\n next\n else\n ans[1] = aft and next if bef == 0\n ans[-2] = bef and next if aft == 0\n\n if ans.index(bef)\n index = ans.index(bef)\n ans[index + 2] = aft\n next\n end\n\n if ans.index(aft)\n index = ans.index(aft)\n ans[index - 2] = bef\n next\n end\n end\nend\n\nformals = []\nwhile 0 < bef_s.length\n bef = bef_s.shift\n aft = aft_s.shift\n\n if ans.index(bef)\n i = ans.index(bef)\n tmp_b = ans[0..(i + 1)]\n tmp_a = ans[(i + 2)..-1]\n tmp_a.unshift(aft)\n ans = tmp_b + tmp_a\n next\n end\n\n if ans.index(aft)\n i = ans.index(aft)\n tmp_b = nil\n tmp_a = nil\n if 0 <= i - 2\n tmp_b = ans[0..(i - 2)]\n tmp_a = ans[(i - 1)..-1]\n tmp_a.unshift(bef)\n ans = tmp_b + tmp_a\n else\n ans.unshift(bef)\n end\n next\n end\n\n if formals.length == 0\n formals << bef\n formals << aft\n next\n end\n\n if formals.index(bef)\n i = formals.index(bef)\n if i + 2 < formals.length\n tmp_b = formals[0..(i + 1)]\n tmp_a = formals[(i + 2)..-1]\n tmp_a.unshift(aft)\n formals = tmp_b + tmp_a\n else\n formals << aft\n end\n next\n end\n\n if formals.index(aft)\n i = formals.index(aft)\n tmp_b = nil\n tmp_a = nil\n if 0 <= i - 2\n tmp_b = formals[0..(i - 2)]\n tmp_a = formals[(i - 1)..-1]\n tmp_a.unshift(bef)\n formals = tmp_b + tmp_a\n else\n formals.unshift(bef)\n end\n next\n end\n\n bef_s << bef\n aft_s << aft\nend\n\nformals.each do |i|\n if ans.index(-1) and !ans.index(i)\n index = ans.index(-1)\n ans[index] = i\n end\nend\n\nputs ans.uniq.select {|i| i != -1}.join(' ')\n"}], "src_uid": "1aaced1322c47f1908f2bc667bca1dbe"} {"source_code": "n = gets.to_i\ns = gets\na = []\nfor i in 0...n\n l = r = 1\n j = i - 1\n while j < n - 2 && s[j += 1] != 'R'\n l += s[j].ord / 70\n end\n j = i\n while j > 0 && s[j -= 1] != 'L'\n r += s[j].ord / 70\n end\n a << [l, r].max\nend\nputs a.join(' ')", "positive_code": [{"source_code": "class Fairness\n def initialize(num_students, directions)\n @num_students = num_students\n @directions = directions\n @toffees = (1..num_students).map { 1 }\n end\n\n def solve\n @directions.each_with_index { |direction, index| reward direction, index }\n reversed.each { |index| reward @directions[index], index }\n end\n\n def display\n @toffees.each {|n| print \"#{n} \"}\n print \"\\n\"\n end\n\n private\n\n def reward(direction, index)\n reward_left(index) if direction == 'L'\n reward_right(index) if direction == 'R'\n equalize(index) if direction == '='\n end\n\n def reward_left(index)\n while @toffees[index] <= @toffees[index+1]\n @toffees[index] += 1\n end\n end\n\n def reward_right(index)\n while @toffees[index+1] <= @toffees[index]\n @toffees[index+1] += 1\n end\n end\n\n def equalize(index)\n max = [@toffees[index], @toffees[index+1]].max\n @toffees[index] = max\n @toffees[index+1] = max\n end\n\n def reversed\n (0...@directions.length).to_a.reverse\n end\nend\n\n\nfair = Fairness.new(gets.chomp.to_i, gets.chomp.split(\"\"))\nfair.solve()\nfair.display()\n"}, {"source_code": "n = gets.to_i\na = []\ns = gets.chomp\n(0...n).each { |i|\n l = r = 1\n j = i - 1\n while j < n - 2 && s[j += 1] != 'R'\n l += 1 if s[j] == 'L'\n end\n j = i\n while j > 0 && s[j -= 1] != 'L'\n r += 1 if s[j] == 'R'\n end\n a << [l, r].max\n}\nputs a.join(' ')"}, {"source_code": "n = gets.to_i\na = []\ns = gets.chomp\n(0...n).each { |i|\n l = r = 1\n (i..n-2).each { |j|\n break if s[j] == 'R'\n l += 1 if s[j] == 'L'\n }\n (i-1).downto(0) { |j|\n break if s[j] == 'L'\n r += 1 if s[j] == 'R'\n }\n a << [l, r].max\n}\nputs a.join(' ')"}, {"source_code": "n = gets.to_i\na = [1] * n\ns = gets.chomp\n([n / 4, 1].max).times {\n (0...n - 1).each { |i|\n a[i + 1] = [a[i] + 1, a[i + 1]].max if s[i] == 'R'\n a[i] = a[i + 1] = [a[i], a[i + 1]].max if s[i] == '='\n }\n (n - 2).downto(0) { |i|\n a[i] = [a[i], a[i + 1] + 1].max if s[i] == 'L'\n }\n}\nputs a.join(' ')"}, {"source_code": "n = gets.to_i\ns = gets.chomp\n\nn = s.size+1\no = [nil]*n\n\n(n-1).times do |i|\n if s[i] == 'R' || s[i] == '='\n o[i+1] = (o[i]||=1) + (s[i] == 'R' ? 1 : 0)\n end\nend\n\ns.reverse!\no.reverse!\n(n-1).times do |i|\n if s[i] == 'L' || s[i] == '='\n v = (o[i]||=1) + (s[i] == 'L' ? 1 : 0)\n o[i+1] = [o[i+1]||v, v].max\n end\nend\n\ns.reverse!\no.reverse!\n\ns2 = o.each_cons(2).map{|a,b|\"R=L\"[(a<=>b)+1]}*\"\"\nputs o*\" \"\n"}], "negative_code": [{"source_code": "class Fairness\n def initialize(num_students, directions)\n @num_students = num_students\n @directions = directions\n @toffees = (1..num_students).map { 1 }\n end\n\n def solve\n @directions.each_with_index do |direction, index|\n reward_left(index) if direction == 'L'\n reward_right(index) if direction == 'R'\n equalize(index) if direction == '='\n end\n\n @toffees.each do |toffee|\n print \"#{toffee} \"\n end\n print \"\\n\"\n end\n\n def reward_left(index)\n while @toffees[index] <= @toffees[index+1]\n @toffees[index] += 1\n end\n end\n\n def reward_right(index)\n while @toffees[index+1] <= @toffees[index]\n @toffees[index+1] += 1\n end\n end\n\n def equalize(index)\n max = [@toffees[index], @toffees[index+1]].max\n @toffees[index] = max\n @toffees[index+1] = max\n end\nend\n\n\nfair = Fairness.new(gets.chomp.to_i, gets.chomp.split(\"\"))\nfair.solve()"}, {"source_code": "gets\nt = 1\na = [1]\ngets.chomp.each_byte { |c|\n t += (c - 79) / 3 if c != 61\n a << t\n}\nt = a.min - 1\nputs a.map{|x| x - t}.join(' ')"}, {"source_code": "n = gets.to_i\na = []\ns = gets.chomp\n(0...n).each { |i|\n l = r = 1\n j = i - 1\n while j < n - 3 && s[j += 1] != 'R'\n l += 1 if s[j] == 'L'\n end\n j = i\n while j > 1 && s[j -= 1] != 'L'\n r += 1 if s[j] == 'R'\n end\n a << [l, r].max\n}\nputs a.join(' ')"}, {"source_code": "n = gets.to_i\na = []\ns = gets.chomp\n(0...n).each { |i|\n l = r = 1\n j = i - 1\n while j < n - 3 && s[j += 1] != 'R'\n l += 1 if s[j] == 'L'\n end\n j = i + 1\n while j > 1 && s[j -= 1] != 'L'\n r += 1 if s[j] == 'R'\n end\n a << [l, r].max\n}\nputs a.join(' ')"}], "src_uid": "8c2a6a29dc238b55d0bc99d7e203f1bf"} {"source_code": "h,w=gets.split.map(&:to_i)\nb=h.times.map{gets.chomp.split(//).map(&:to_sym)}\n\nbh=Array.new(h){Array.new(w,0)}\nbw=Array.new(h){Array.new(w,0)}\n\n0.upto(h-2){|x|0.upto(w-1){|y|\n\tbh[x][y]=1 if b[x][y]==b[x+1][y]&&b[x+1][y]==\".\".to_sym\n}}\n\n0.upto(h-1){|x|0.upto(w-2){|y|\n\tbw[x][y]=1 if b[x][y]==b[x][y+1]&&b[x][y+1]==\".\".to_sym\n}}\n\ndp_bh=Array.new(h+1){Array.new(w+1,0)}\ndp_bw=Array.new(h+1){Array.new(w+1,0)}\n\n0.upto(h-1){|x|d=0\n0.upto(w-1){|y|\n\td+=bh[x][y]\n\tdp_bh[x][y]=dp_bh[x-1][y]+d\n}}\n\n0.upto(h-1){|x|d=0\n0.upto(w-1){|y|\n\td+=bw[x][y]\n\tdp_bw[x][y]=dp_bw[x-1][y]+d\n}}\n\nq=gets.to_i\nq.times{\n\tr1,c1,r2,c2=gets.split.map{|v|v.to_i-1}\n\thh=ww=0\n\thh=dp_bh[r2-1][c2]+dp_bh[r1-1][c1-1]-dp_bh[r2-1][c1-1]-dp_bh[r1-1][c2] unless r2==r1\n\tww=dp_bw[r2][c2-1]+dp_bw[r1-1][c1-1]-dp_bw[r2][c1-1]-dp_bw[r1-1][c2-1] unless c2==c1\n\tputs hh+ww\n}\n", "positive_code": [{"source_code": "h, w = gets.chomp.split.map(&:to_i)\nboard = []\nh.times do\n board << gets.chomp\nend\n\nrs = Array.new(h).map {Array.new(w, 0)}\nfor r in 0...h\n cnt = 0\n for c in 1...w\n cnt += 1 if board[r][c] == '.' && board[r][c - 1] == '.'\n rs[r][c] = cnt\n rs[r][c] += rs[r - 1][c] if 0 < r\n end\nend\n\ncs = Array.new(h).map {Array.new(w, 0)}\nfor c in 0...w\n cnt = 0\n for r in 1...h\n cnt += 1 if board[r][c] == '.' && board[r - 1][c] == '.'\n cs[r][c] = cnt\n cs[r][c] += cs[r][c - 1] if 0 < c\n end\nend\n\nq = gets.chomp.to_i\nq.times do\n cnt = 0\n r1, c1, r2, c2 = gets.chomp.split.map { |x| x.to_i - 1 }\n cnt += rs[r2][c2]\n cnt += rs[r1 - 1][c1] if 0 < r1\n cnt -= rs[r1 - 1][c2] if 0 < r1\n cnt -= rs[r2][c1]\n\n cnt += cs[r2][c2]\n cnt += cs[r1][c1 - 1] if 0 < c1\n cnt -= cs[r1][c2]\n cnt -= cs[r2][c1 - 1] if 0 < c1\n puts cnt\nend\n"}, {"source_code": "h,w = gets.split.map(&:to_i)\nb = h.times.map{gets.chomp.split(//)}\n\nq = gets.to_i\n\nhs = Array.new( h+1 ){Array.new( w+1 , 0 )}\nws = Array.new( h+1 ){Array.new( w+1 , 0 )}\n\n\nfor i in (0..h-1)\n\tfor j in (1..w-1)\n\t\tif (b[i][j]=='.' && b[i][j-1]=='.') then\n\t\t\ths[i][j] = hs[i][j-1]+1;\n\t\telse\n\t\t\ths[i][j] = hs[i][j-1];\n\t\tend\n\tend\n\tif (i>0) \n\t\tfor j in (1..w-1) \n\t\t\ths[i][j] += hs[i-1][j] \n\t\tend\n\tend\nend\n\n\nfor j in (0..w-1)\n\tfor i in (1..h-1)\n\t\tws[i][j] = ws[i-1][j] + ((b[i-1][j]==\".\" && b[i][j]==\".\")?1:0)\n\tend\n\tif (j>0)\n\t\tfor i in (1..h-1)\n\t\t\tws[i][j] += ws[i][j-1]\n\t\tend\n\tend\nend\n\n\nq.times{\n\tr1,c1,r2,c2 = gets.split.map{|e| e.to_i - 1}\n\tt1 = hs[r2][c2]-hs[r2][c1] - ((r1>0)? (hs[r1-1][c2]-hs[r1-1][c1]) : 0 )\n\tt2 = ws[r2][c2]-ws[r1][c2] - ((c1>0)? (ws[r2][c1-1]-ws[r1][c1-1]) : 0 )\n\tputs \"#{t1+t2}\"\n}"}], "negative_code": [], "src_uid": "d9fdf0827940883069bead0d00b3da53"} {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nm = a.min\nf = (0...n).find_all{|x| a[x]==m}\nif f.size == 1\n puts f[0] + 1\nelse\n puts \"Still Rozdil\"\nend", "positive_code": [{"source_code": "gets\na=gets.split.map &:to_i\nputs(a.count(m=a.min)>1?\"Still Rozdil\":1+a.index(m))"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nif a.count(a.min)>1\n puts \"Still Rozdil\"\nelse\n puts a.index(a.min)+1\nend\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nputs(a.count(m=a.min)>1?\"Still Rozdil\":1+a.index(m))\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nputs(a.count(m=a.min)>1?\"Still Rozdil\":1+a.index(m))\n"}, {"source_code": "gets\na = gets.split.map { |i| i.to_i } \nputs a.count(a.min) == 1 ? a.index(a.min) + 1 : \"Still Rozdil\"\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nm=a.min\nputs a.count(m)>1 ? \"Still Rozdil\" : a.index(m)+1\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nputs(a.count(m=a.min)>1?\"Still Rozdil\":1+a.index(m))\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nputs(a.count(m=a.min)>1?\"Still Rozdil\":1+a.index(m))\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nputs(a.count(m=a.min)>1?\"Still Rozdil\":1+a.index(m))\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nputs(a.count(m=a.min)>1?\"Still Rozdil\":1+a.index(m))\n"}, {"source_code": "n = gets.to_i\n\ncity = gets.split.map{|i| i.to_i}\n\nmin = 10**9 + 1\ni = -1\nt = false\nn.times do |k|\n if city[k] < min then\n min = city[k]\n t = false\n i = k\n elsif city[k] == min then\n t = true\n end\nend\n\nif t then \n puts \"Still Rozdil\"\nelse\n puts i+1\nend"}, {"source_code": "gets\na=gets.split.map &:to_i\nputs(a.count(m=a.min)>1?\"Still Rozdil\":1+a.index(m))"}, {"source_code": "gets\na = gets.split.map &:to_i\nm = a.min\ni = a.index m\nj = a.rindex m\nputs (i != j ? \"Still Rozdil\" : i+1)\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nputs(a.count(m=a.min)>1?\"Still Rozdil\":1+a.index(m))\n"}, {"source_code": "\ufeffn = gets.chomp.to_i\ntimes = gets.chomp.split(\" \").map{|e| e.to_i}\n\nmin = times.min\nif times.count(min) == 1\n puts times.index(min) + 1\nelse\n puts \"Still Rozdil\"\nend"}, {"source_code": "num_cities = gets\ndistances = gets.split.collect {|i| i.to_i}\nmin_distance = distances.min\nnum_occured = distances.count(min_distance)\nif num_occured == 1\n\tputs distances.index(min_distance) + 1\nelse\n\tputs \"Still Rozdil\"\nend\n"}, {"source_code": "gets\na=gets.split.map &:to_i\nputs(a.count(m=a.min)>1?\"Still Rozdil\":1+a.index(m))\n"}, {"source_code": "#!/usr/bin/ruby\n\nnum_entries = gets.to_i\n\nline = gets\n\nnumbers = line.split(' ')\nnumbers.map! { |e| e.to_i}\nmin = numbers.min\ncounter = 0\nnumbers.each { |n|\n if(n == min) then\n counter += 1\n end\n}\n\nif (counter > 1) then\n puts \"Still Rozdil\"\nelse\n puts numbers.index(min) + 1\nend\n\n"}], "negative_code": [{"source_code": "n = gets.to_i\n\ncity = gets.split.map{|i| i.to_i}\n\nmin = 10**5\ni = -1\nt = false\nn.times do |k|\n if city[k] < min then\n min = city[k]\n t = false\n i = k\n elsif city[k] == min then\n t = true\n end\nend\n\nif t then \n puts \"Still Rozdil\"\nelse\n puts i+1\nend"}, {"source_code": "num_cities = gets\ndistances = gets.split.collect {|i| i.to_i}\nmin_distance = distances.min\nnum_occured = distances.count(min_distance)\nif num_occured == 1\n\tputs min_distance.to_s\nelse\n\tputs \"Still Rozdil\"\nend\n"}], "src_uid": "ce68f1171d9972a1b40b0450a05aa9cd"} {"source_code": "gets;$<.map{p gets.split.count{|x|x!=\"2\"}}", "positive_code": [{"source_code": "t = gets.strip.to_i\r\nt.times do\r\n\tn = gets.strip.to_i\r\n\tr = gets.strip.split.map(&:to_i)\r\n\tup_votes = ans = 0\r\n\tn.times do |i|\r\n\t\tcurrent = r[i]\r\n\t\tans += 1 if current == 1 || current == 3\r\n\tend\r\n\tputs ans\r\nend"}, {"source_code": "t = gets.to_s.to_i\n\n1.upto(t) do |casenum|\n n = gets.to_s.split.map {|x| x.to_i }\n ar = gets.to_s.split.map {|x| x.to_i }\n\n vn = 0\n vp = 0\n\n ar.each do |r|\n if r == 1\n vp += 1\n elsif r == 2\n vn -= 1\n else\n vp += 1\n end\n end\n\n printf(\"%d\\n\", vp)\nend\n"}], "negative_code": [], "src_uid": "a063705bd0ce1e17ccaafbbfc2663d93"} {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\n\ndef puts_yesno(can) puts(can ? 'Yes' : 'No') end\ndef putsend(s) puts s; exit end\ndef debug(k,v) puts \"#{k}:#{v}\" end\n########### ( \u02d8\u03c9\u02d8 )\uff7d\uff94\uff67\u2026 ###########\nq = gi\nans = []\nMAX = 10**5\nMIN = -10**5\nq.times do |i|\n n = gi\n xf = n.times.map{gsmi}\n # x,y,xl,yu,xr,yd\n x_ran = [MIN,MAX]\n y_ran = [MIN,MAX]\n xf.each do |x,y,xl,yu,xr,yd|\n if xl==0&&xr==0\n unless x_ran[0]<=x && x<=x_ran[1]\n ans<<'0'\n break\n else\n x_ran = [x,x]\n end\n elsif xl==1&&xr==0\n if x k\n puts -1\nelsif n == 1\n puts -1 if k > 0\n puts 1 if k == 0\nelse\n ans = Array.new(n)\n ans[0] = k-n/2+1\n ans[1] = 2*ans[0]\n for i in 2...n\n ans[i] = ans[i-1]+1\n end\n puts ans.join(' ')\nend\n", "positive_code": [{"source_code": "n, m = gets.split.map &:to_i\nif n == 1\n\tputs m == 0 ? '1' : '-1'\n\texit\nend\none = n / 2 - 1\nnoone = m - one\nif noone <= 0\n\tputs '-1'\n\texit\nend\nans = []\nuse = {}\nif noone > 0\n\tans << noone\n\tans << noone * 2\n\tuse[noone] = true\n\tuse[noone * 2] = true\nend\nif one > 0\n\t1.step(1000000000,2) do |i|\n\t\tif !use[i] && !use[i + 1]\n\t\t\tans << i\n\t\t\tans << i + 1\n\t\t\tone -= 1\n\t\t\tbreak if one == 0\n\t\tend\n\tend\nend\nans << 1000000000 if ans.size < n\nflag = false\nans.each do |x|\n\tflag = true if x > 1000000000\nend\nputs flag ? '-1' : ans.join(' ')\n"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\n\npairs = n / 2\n\nremaining = k - (pairs - 1)\nif n == 1\n\tans = k == 0 ? [1] : [-1]\nelsif remaining > 0\n\tans = [] \n\tx = remaining * 2 + 2\n\t((pairs-1)*2).times do\n\t\tans << x\n\t\tx += 1\t\n\tend\n\tans << remaining << remaining * 2\n\tone_off = ans[-1] + 1\n\tans << one_off if n % 2 != 0\nelse\n\tans = [-1]\nend\n\nputs ans.join(\" \")"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\nif n/2 > k\n puts -1\nelsif n == 1\n if k > 0\n puts -1\n else\n puts 1\n end\nelse\n ans = Array.new(n)\n ans[0] = k-n/2+1\n ans[1] = 2*ans[0]\n for i in 2...n\n ans[i] = ans[i-1]+1\n end\n puts ans.join(' ')\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nif k < n / 2 || n == 1 && k > 0\n\tputs -1\n\texit 0\nend\nif n == 1 && k == 0\n\tputs 1\n\texit 0\nend\nm = n / 2 - 1\nk -= m\ns = []\n(2*m).times{|i| s<<(i+1)}\nx = (2 * m) / k + 1\ns << k * x << k * (x + 1)\ns << k * (x + 1) + 1 if n % 2 == 1\nputs s.join(' ')\n"}, {"source_code": "n ,k = gets.split(' ').map { |x| x.to_i }\narr = Array.new\n\nif ( k < (n/2).floor)\n\tputs '-1'\n\texit\nend\narr[0] = k - ((n-2)/2).floor\narr[1] = arr[0]*2\nfor i in 2..n-1\n\tarr[i] = arr[i-1]+1\nend\n\nif n == 1 && k != 0\n\tputs '-1'\n\texit\nelsif n == 1 && k == 0\n\tputs '1'\n\texit\nend\n\narr.each do|x|\n\tprint x\n\tprint ' '\n\tend"}, {"source_code": "require 'set'\n\nn, k = gets.split.map(&:to_i)\nused = Set.new\nans = []\n\nif k == 0 and n == 1\n p 1\n exit\nelsif n == 1\n if k == 0\n p 1\n else\n p (-1)\n end\n exit\nelsif n / 2 > k\n p (-1)\n exit\nend\n\nm = k - (n - 2) / 2\nans << m\nans << m * 2\nused << m\nused << m * 2\nn -= 2\n\nc = 1\n\nwhile n >= 2\n a = c\n b = c + 1\n c += 2\n while used.member?(a) || used.member?(b)\n a = c\n b = c + 1\n c += 2\n end\n ans << a\n ans << b\n n -= 2\nend\n\nif n == 1\n a = c\n while used.member?(a) || used.member?(b)\n c += 1\n a = c\n end\n ans << a\nend\n\nputs ans.join(' ')\n"}], "negative_code": [{"source_code": "n ,k = gets.split(' ').map { |x| x.to_i }\narr = Array.new\n\nif ( k < n/2)\n\tputs '-1'\n\texit\nend\narr[0] = k - (n-2)/2\narr[1] = arr[0]*2\nfor i in 2..n-1\n\tarr[i] = arr[i-1]+1\nend\n\narr.each do|x|\n\tprint x\n\tprint ' '\n\tend"}, {"source_code": "n ,k = gets.split(' ').map { |x| x.to_i }\narr = Array.new\n\nif ( k < n/2)\n\tputs '-1'\n\texit\nend\narr[0] = k - (n-2)/2\narr[1] = arr[0]*2\nfor i in 2..n-1\n\tarr[i] = arr[i-1]*2\nend\n\narr.each do|x|\n\tprint x\n\tprint ' '\n\tend"}, {"source_code": "n ,k = gets.split(' ').map { |x| x.to_i }\narr = Array.new\n\nif ( k < n/2)\n\tputs '-1'\n\texit\nend\narr[0] = k - (n-2)/2\narr[1] = arr[0]*2\nfor i in 2..n\n\tarr[i] = arr[i-1]*2\nend\n\narr.each do|x|\n\tprint x\n\tprint ' '\n\tend"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\n\npairs = n / 2\n\nremaining = k - (pairs - 1)\nif n == 1\n\tans = k == 0 ? [1] : [-1]\nelsif remaining > 0\n\tans = [] \n\tx = remaining * 2 + 1\n\t((pairs-1)*2).times do\n\t\tans << x\n\t\tx += 1\t\n\tend\n\tone_off = ans[-1] + 1 if ans[-1]\n\tans << remaining << remaining * 2\n\tans << one_off if n % 2 != 0\nelse\n\tans = [-1]\nend\n\nputs ans.join(\" \")"}, {"source_code": "n,k = gets.split(\" \").map(&:to_i)\n\npairs = n / 2\n\nremaining = k - (pairs - 1)\n\nif n > 1 && remaining > 0\n\tans = [] \n\tx = remaining * 2 + 1\n\t((pairs-1)*2).times do\n\t\tans << x\n\t\tx += 1\t\n\tend\n\tone_off = ans[-1] + 1\n\tans << remaining << remaining * 2\n\tans << one_off if n % 2 != 0\nelse\n\tans = [-1]\nend\n\nputs ans.join(\" \")"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\nif n/2 > k\n puts -1\nelse\n ans = Array.new(n)\n ans[0] = k-n/2+1\n ans[1] = 2*ans[0]\n for i in 2...n\n ans[i] = ans[i-1]+1\n end\n puts ans.join(' ')\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nif k < n / 2 || n == 1 && k > 0\n\tputs -1\n\texit 0\nend\nm = n / 2 - 1\nk -= m\ns = []\n(2*m).times{|i| s<<(i+1)}\nx = (2 * m) / k + 1\ns << k * x << k * (x + 1)\ns << k * (x + 1) + 1 if n % 2 == 1\nputs s.join(' ')\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nif k < n / 2\n\tputs -1\n\texit 0\nend\nm = n / 2 - 1\nk -= m\ns = []\n(2*m).times{|i| s<<(i+1)}\nx = (2 * m) / k + 1\ns << k * x << k * (x + 1)\ns << k * (x + 1) + 1 if n % 2 == 1\nputs s.join(' ')\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nif k < n / 2\n\tputs -1\n\texit 0\nend\nm = n / 2 - 1\ns = \"1 1 \" * m + (k - m).to_s + \" \" + (k - m).to_s\ns = s + \" 1\" if n % 2 == 1\nputs s\n"}, {"source_code": "require 'set'\n\nn, k = gets.split.map(&:to_i)\nused = Set.new\nans = []\nc = 1\n\nif n / 2 > k\n p (-1)\n exit\nend\n\nwhile n > 1\n m = k - (n - 2) / 2\n\n while true\n\n if m == 1\n a = c\n b = c + 1\n c += 2\n while used.member?(b) || used.member?(a)\n a = c\n b = c + 1\n c += 2\n end\n else\n a = m\n b = 2 * m\n end\n\n if used.member?(b) || used.member?(a)\n m -= 1\n next\n else\n break\n end\n end\n\n used << a\n used << b\n ans << a\n ans << b\n k -= a.gcd(b)\n # p [[a, b], a.gcd(b)]\n\n n -= 2\nend\n\nwhile n > 0\n while used.member?(c)\n c += 1\n end\n ans << c\n n = 0\nend\n\nputs ans.join(' ')\n"}, {"source_code": "require 'set'\n\nn, k = gets.split.map(&:to_i)\nused = Set.new\nans = []\n\nif k == 0 and n == 1\n p 1\n exit\nelsif n / 2 > k\n p (-1)\n exit\nend\n\nm = k - (n - 2) / 2\nans << m\nans << m * 2\nused << m\nused << m * 2\nn -= 2\n\nc = 1\n\nwhile n >= 2\n a = c\n b = c + 1\n c += 2\n while used.member?(a) || used.member?(b)\n a = c\n b = c + 1\n c += 2\n end\n ans << a\n ans << b\n n -= 2\nend\n\nif n == 1\n a = c\n while used.member?(a) || used.member?(b)\n c += 1\n a = c\n end\n ans << a\nend\n\nputs ans.join(' ')\n"}, {"source_code": "n ,k = gets.split(' ').map { |x| x.to_i }\narr = Array.new\n\nif ( k < n/2)\n\tputs '-1'\n\texit\nend\narr[0] = k - (n-2)/2\narr[1] = arr[0]*2\nfor i in 2..n-1\n\tarr[i] = arr[i-1]+1\nend\n\nif n == 1\n\tputs '-1'\n\texit\n\tend\n\narr.each do|x|\n\tprint x\n\tprint ' '\n\tend"}, {"source_code": "n ,k = gets.split(' ').map { |x| x.to_i }\narr = Array.new\n\nif ( k < n/2)\n\tputs '-1'\n\texit\nend\narr[0] = k - (n-2)/2\narr[1] = arr[0]*2\narr[2] = 1\nfor i in 3..n-1\n\tarr[i] = arr[i-1]+1\nend\n\nif n == 1\n\tputs '-1'\n\texit\n\tend\n\narr.each do|x|\n\tprint x\n\tprint ' '\n\tend"}, {"source_code": "n ,k = gets.split(' ').map { |x| x.to_i }\narr = Array.new\n\nif ( k < (n/2).floor)\n\tputs '-1'\n\texit\nend\narr[0] = k - ((n-2)/2).floor\narr[1] = arr[0]*2\nfor i in 2..n-1\n\tarr[i] = arr[i-1]+1\nend\n\nif n == 1\n\tputs '-1'\n\texit\n\tend\n\narr.each do|x|\n\tprint x\n\tprint ' '\n\tend"}, {"source_code": "require 'set'\n\nn, k = gets.split.map(&:to_i)\nused = Set.new\nans = []\n\nif n / 2 > k\n\n if n == 1\n p 1\n else\n p (-1)\n end\n exit\nend\n\nm = k - (n - 2) / 2\nans << m\nans << m * 2\nused << m\nused << m * 2\nn -= 2\n\nc = 1\n\nwhile n >= 2\n a = c\n b = c + 1\n c += 2\n while used.member?(a) || used.member?(b)\n a = c\n b = c + 1\n c += 2\n end\n ans << a\n ans << b\n n -= 2\nend\n\nif n == 1\n a = c\n while used.member?(a) || used.member?(b)\n c += 1\n a = c\n end\n ans << a\nend\n\nputs ans.join(' ')\n"}, {"source_code": "require 'set'\n\nn, k = gets.split.map(&:to_i)\nused = Set.new\nans = []\n\nif n / 2 > k\n p (-1)\n exit\nend\n\nm = k - (n - 2) / 2\nans << m\nans << m * 2\nused << m\nused << m * 2\nn -= 2\n\nc = 1\n\nwhile n >= 2\n a = c\n b = c + 1\n c += 2\n if used.member?(a) || used.member?(b)\n a = c\n b = c + 1\n c += 2\n end\n ans << a\n ans << b\n n -= 2\nend\n\nif n == 1\n a = c\n if used.member?(a) || used.member?(b)\n c += 1\n a = c\n end\n ans << a\nend\n\nputs ans.join(' ')\n"}, {"source_code": "require 'set'\n\nn, k = gets.split.map(&:to_i)\nused = Set.new\nans = []\n\nif n / 2 > k\n p (-1)\n exit\nend\n\nm = k - (n - 2) / 2\nans << m\nans << m * 2\nused << m\nused << m * 2\nn -= 2\n\nc = 1\n\nwhile n >= 2\n a = c\n b = c + 1\n c += 2\n while used.member?(a) || used.member?(b)\n a = c\n b = c + 1\n c += 2\n end\n ans << a\n ans << b\n n -= 2\nend\n\nif n == 1\n a = c\n while used.member?(a) || used.member?(b)\n c += 1\n a = c\n end\n ans << a\nend\n\nputs ans.join(' ')\n"}], "src_uid": "b85c8bfbe67a23a81bef755f9313115a"} {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2i\n putsend 0\n end\nend\nw.times do |i|\n tar = c[i]\n next if tar==h\n if r[tar]>i\n putsend 0\n end\nend\n\n# cnt\nh.times do |i|\n w.times do |j|\n cnt+=1 if r[i] n\n\nFile.open(\"output.txt\", \"w\") do |f|\n f.puts r\nend\n"}], "negative_code": [{"source_code": "f = File.open('input.txt', 'r') or die \"Unable to open file...\"\ninput = [] # start with an empty array\n f.each_line {|line|\n input.push line\n } \n\nselected = input[0].scan(/\\w+/)[1].to_i\nitems = input[1].scan(/\\w+/)\n\nuntil items[selected].to_i == 1 do\n (selected < items.length)? selected += 1 : selected = 0\n if (items[selected].to_i == 1)\n File.open('output.txt', 'w') { |o| o.puts \"#{selected+1}\"} \n end \nend\n"}], "src_uid": "1378b4c9ba8029d310f07a1027a8c7a6"} {"source_code": "n=gets.to_i\na,b,c,d={},0,-1,[0]*n\n1.upto(n){a[c+=1]=gets.split.map(&:to_i)}\nn.times{|i|\n\tx,t=a.to_a.sort_by{|x,(y,z)|(10**7+1)*[y,b+1].max+z}.shift\n\ty,z=t\n\tb=b b.st\n\telse\n\t\ta.en <=> b.en\n\tend\n}\n\nfor i in 0..n-1\n\tst = ar[i].st\n\twhile aused[st-1] == true\n\t\tst += 1\n\tend\n\taused[st-1] = true\n\tar[i].used = st\nend\n\nret = \"\"\nar.sort!{|a,b|\n\ta.id <=> b.id\n}\nfor i in 0..n-1\n\tret << \" \" if i > 0\n\tret << ar[i].used.to_s\nend\nputs ret\n"}, {"source_code": "class Segment\n attr_accessor :from, :to\n\n def initialize(from, to)\n @from, @to = from, to\n end\n\n def <=> (rhs)\n return -1 if from < rhs.from\n return to <=> rhs.to if from == rhs.from\n return +1\n end\nend\n\ndef max(a, b)\n a > b ? a : b\nend\n\nn = gets.to_i\nsegs = Array.new(n) { Segment.new(*gets.split.map { |v| v.to_i }) }\nresult = Array.new(n)\norder = (0 ... n).to_a\n\nwhile not order.empty?\n order = order.sort_by { |i| segs[i] }\n cur = order.shift\n result[cur] = segs[cur].from\n order.each do |index|\n segs[index].from = max(segs[index].from, segs[cur].from + 1)\n end\nend\n\nputs result.join(' ')\n"}], "negative_code": [{"source_code": "class Event\n\tdef initialize(st, en)\n\t\t@st = st\n\t\t@en = en\n\t\t@used = false\n\tend\n\tattr_accessor :st, :en, :used\nend\n\nn = gets.chop.to_i\n\nar = Array.new\nfor i in 0..n-1\n\ts,e = gets.chomp.split(/ /).map!{|x| x.to_i}\n\tar.push(Event.new(s,e))\nend\n\nar.sort!{|a,b|\n\tif a.st == b.st\n\t\ta.en <=> b.en\n\telse\n\t\ta.st <=> b.st\n\tend\n}\n\nret = \"\"\ncnt = 0\nstartidx = 0\nseq = 0\nwhile cnt < n\n\twkidx = -1\n\twken = 0\n\tfor i in startidx..n-1\n\t\tnext if ar[i].used\n\t\tif seq < ar[i].st\n\t\t\twkidx = i\n\t\t\twken = ar[i].st\n\t\t\tbreak\n\t\telse\n\t\t\tif wkidx < 0\n\t\t\t\twkidx = i\n\t\t\t\twken = ar[i].en \n\t\t\telsif ar[i].en < wken\n\t\t\t\twkidx = i \n\t\t\t\twken = ar[i].en \n\t\t\tend\n\t\tend\n\t\tbreak if ar[i].st > seq\n\tend\n\tret << \" \" if cnt > 0\n\tcnt += 1\n\tar[wkidx].used = true\n\tseq = wken\n\tret << seq.to_s\n\tfor i in startidx+1..n-1\n\t\tbreak if ar[i].used == false\n\t\tstartidx = i\n\tend\nend\n\nputs ret\n"}, {"source_code": "class Event\n\tdef initialize(st, en)\n\t\t@st = st\n\t\t@en = en\n\tend\n\tattr_accessor :st, :en\nend\n\nn = gets.chop.to_i\n\nar = Array.new\nfor i in 0..n-1\n\ts,e = gets.chomp.split(/ /).map!{|x| x.to_i}\n\tar.push(Event.new(s,e))\nend\n\nret = \"\"\nseq = 0\n\nfor i in 0..n-1\n\tif seq < ar[i].st\n\t\twkidx = i\n\t\tseq = ar[i].st\n\telse\n\t\tseq = seq+1\n\tend\n\tret << \" \" if i > 0\n\tret << seq.to_s\nend\n\nputs ret\n"}, {"source_code": "class Event\n\tdef initialize(st, en)\n\t\t@st = st\n\t\t@en = en\n\t\t@used = false\n\tend\n\tattr_accessor :st, :en, :used\nend\n\nn = gets.chop.to_i\n\nar = Array.new\nfor i in 0..n-1\n\ts,e = gets.chomp.split(/ /).map!{|x| x.to_i}\n\tar.push(Event.new(s,e))\nend\n\nar.sort!{|a,b|\n\tif a.st == b.st\n\t\ta.en <=> b.en\n\telse\n\t\ta.st <=> b.st\n\tend\n}\n\nret = \"\"\ncnt = 0\nstartidx = 0\nseq = 0\nnseq = 0\nwhile cnt < n\n\twkidx = -1\n\twken = 0\n\tfor i in startidx..n-1\n\t\tnext if ar[i].used\n\t\tif seq < ar[i].st\n\t\t\twkidx = i\n\t\t\tnseq = ar[i].st\n\t\t\tbreak\n\t\telse\n\t\t\tif wkidx < 0\n\t\t\t\twkidx = i\n\t\t\t\twken = ar[i].en \n\t\t\telsif ar[i].en < wken\n\t\t\t\twkidx = i \n\t\t\t\twken = ar[i].en \n\t\t\tend\n\t\t\tnseq = seq+1\n\t\tend\n\t\tbreak if ar[i].st > seq\n\tend\n\tret << \" \" if cnt > 0\n\tcnt += 1\n\tar[wkidx].used = true\n\tseq = nseq\n\tret << seq.to_s\n\tfor i in startidx+1..n-1\n\t\tbreak if ar[i].used == false\n\t\tstartidx = i\n\tend\nend\n\nputs ret\n"}, {"source_code": "class Event\n\tdef initialize(st, en, id)\n\t\t@st = st\n\t\t@en = en\n\t\t@id = id\n\t\t@used = 0\n\tend\n\tattr_accessor :st, :en, :id, :used\nend\n\nn = gets.chop.to_i\n\nar = Array.new\nfor i in 0..n-1\n\ts,e = gets.chomp.split(/ /).map!{|x| x.to_i}\n\tar.push(Event.new(s,e,i))\nend\n\nar.sort!{|a,b|\n\tif a.st == b.st\n\t\ta.en <=> b.en\n\telse\n\t\ta.st <=> b.st\n\tend\n}\n\ncnt = 0\nstartidx = 0\nseq = 0\nnseq = 0\nwhile cnt < n\n\twkidx = -1\n\twken = 0\n\tfor i in startidx..n-1\n\t\tnext if ar[i].used > 0\n\t\tif seq < ar[i].st\n\t\t\twkidx = i\n\t\t\tnseq = ar[i].st\n\t\t\tbreak\n\t\telse\n\t\t\tif wkidx < 0\n\t\t\t\twkidx = i\n\t\t\t\twken = ar[i].en \n\t\t\telsif ar[i].en < wken\n\t\t\t\twkidx = i \n\t\t\t\twken = ar[i].en \n\t\t\tend\n\t\t\tnseq = seq+1\n\t\tend\n\t\tbreak if ar[i].st > seq\n\tend\n\n\tcnt += 1\n\tar[wkidx].used = nseq\n\tseq = nseq\n\n\tfor i in startidx+1..n-1\n\t\tbreak if ar[i].used == 0\n\t\tstartidx = i\n\tend\nend\n\nret = \"\"\nar.sort!{|a,b|\n\ta.id <=> b.id\n}\nfor i in 0..n-1\n\tret << \" \" if i > 0\n\tret << ar[i].used.to_s\nend\nputs ret\n"}, {"source_code": "class Event\n\tdef initialize(st, en)\n\t\t@st = st\n\t\t@en = en\n\t\t@used = false\n\tend\n\tattr_accessor :st, :en, :used\nend\n\nn = gets.chop.to_i\n\nar = Array.new\nfor i in 0..n-1\n\ts,e = gets.chomp.split(/ /).map!{|x| x.to_i}\n\tar.push(Event.new(s,e))\nend\n\nar.sort!{|a,b|\n\tif a.st == b.st\n\t\ta.en <=> b.en\n\telse\n\t\ta.st <=> b.st\n\tend\n}\n\nret = \"\"\ncnt = 0\nstartidx = 0\nseq = 0\nwhile cnt < n\n\twkidx = -1\n\twken = 0\n\tnseq = 0\n\tfor i in startidx..n-1\n\t\tnext if ar[i].used\n\t\tif seq < ar[i].st\n\t\t\twkidx = i\n\t\t\tnseq = ar[i].st\n\t\t\tbreak\n\t\telse\n\t\t\tif wkidx < 0\n\t\t\t\twkidx = i\n\t\t\t\twken = ar[i].en \n\t\t\telsif ar[i].en < wken\n\t\t\t\twkidx = i \n\t\t\t\twken = ar[i].en \n\t\t\tend\n\t\t\tnseq = seq+1\n\t\tend\n\t\tbreak if ar[i].st > seq\n\tend\n\tret << \" \" if cnt > 0\n\tcnt += 1\n\tar[wkidx].used = true\n\tseq = nseq\n\tret << seq.to_s\n\tfor i in startidx+1..n-1\n\t\tbreak if ar[i].used == false\n\t\tstartidx = i\n\tend\nend\n\nputs ret\n"}, {"source_code": "class Segment\n attr_reader :from, :to\n \n def initialize(from, to)\n @from, @to = from, to\n end\n\n def <=> (rhs)\n return -1 if @to < rhs.to\n return @from <=> rhs.from if @to == rhs.to\n return +1\n end\nend\n\ndef max(a, b)\n a > b ? a : b\nend\n\nn = gets.to_i\nsegs = Array.new(n) { Segment.new(*gets.split.map { |v| v.to_i }) }\nresult, last = [], -1\n\n(0 ... n).to_a.sort_by { |i| segs[i] }.each do |i|\n last = max(last, segs[i].from) + 1\n result[i] = last - 1\nend\n\nputs result.join(' ')\n"}, {"source_code": "class Segment\n attr_reader :from, :to\n \n def initialize(from, to)\n @from, @to = from, to\n end\n\n def <=> (rhs)\n return -1 if @from < rhs.from\n return @to <=> rhs.to if @from == rhs.from\n return +1\n end\nend\n\ndef max(a, b)\n a > b ? a : b\nend\n\nn = gets.to_i\nsegs = Array.new(n) { Segment.new(*gets.split.map { |v| v.to_i }) }\nresult, last = [], -1\n\n(0 ... n).to_a.sort_by { |i| segs[i] }.each do |i|\n last = max(last, segs[i].from) + 1\n result[i] = last - 1\nend\n\nputs result.join(' ')\n"}, {"source_code": "class Segment\n attr_reader :from, :to\n \n def initialize(from, to)\n @from, @to = from, to\n end\n\n def <=> (rhs)\n return -1 if @from < rhs.from\n return @to <=> rhs.to if @from == rhs.from\n return +1\n end\nend\n\ndef max(a, b)\n a > b ? a : b\nend\n\nn = gets.to_i\nsegs = Array.new(n) { Segment.new(*gets.split.map { |v| v.to_i }) }.sort\n\nresult, from = [], -1\n\nsegs.each do |seg|\n result.push(max(seg.from, from))\n from = max(seg.from, from) + 1\nend\n\nputs result.join(' ')\n"}, {"source_code": "a,b,c=[],0,0\n\"1\n\".upto(gets){a<<([b+=1]+gets.split.map(&:to_i))}\nputs a.sort_by{|x,y,z|101*y+z}.map{|x,y,z|cn[2] : m[1]<=>n[1]}.map{|x,y,z|b m\r\n if m[i] == 1 && n[i] == 0\r\n s |= 1 << i\r\n end\r\n end\r\n if (s ^ n) == m\r\n s = ((s ^ n) + 1) & ~n\r\n end\r\n puts s\r\nend"}], "negative_code": [{"source_code": "gets\r\n$stdin.each do |t|\r\n n, m = t.split.map(&:to_i)\r\n s = m & (-1 << n.bit_length)\r\n (n.bit_length - 1).downto(0) do |i|\r\n break if (s ^ n) > m\r\n if m[i] == 1 && n[i] == 0\r\n s |= 1 << i\r\n end\r\n end\r\n s += 1 if (s ^ n) == m\r\n puts s\r\nend"}], "src_uid": "96b0879628b233173d54e3ed9e2c4fce"} {"source_code": "gets.to_i.times do\n a, b, x, y, n = gets.split.map &:to_i\n res = 1E18.to_i\n 3.times do |i|\n d1 = [n, a - x].min\n d2 = [n - d1, b - y].min\n res = [res, (a - d1) * (b - d2)].min\n a, b, x, y = b, a, y, x\n end\n puts res\nend", "positive_code": [{"source_code": "def solve\n a, b, x, y, n = gets.strip.split(' ').map(&:to_i)\n ck1 = a - x > n ? a - n : a - (a - x)\n ck2 = b - y > n ? b - n : b - (b - y)\n if ck1 < ck2\n n -= (a - ck1)\n if (b - y) > n\n b = b - n\n else\n b = b - (b - y)\n end\n puts ck1 * b\n else\n n = n - (b - ck2)\n if (a - x) > n\n a = a - n\n else\n a = a - (a - x)\n end\n puts ck2 * a\n end\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "def solve(a, b, x, y, n)\n\tb_dec = [[0, b - y].max, n].min\n\tb -= b_dec\n\tn -= b_dec\n\ta_dec = [[0, a - x].max, n].min\n\ta -= a_dec\n\tn -= a_dec\n\ta * b\nend\n\nt = gets.to_i\nt.times do\n\ta, b, x, y, n = gets.split.map &:to_i\n\tp [solve(a, b, x, y, n), solve(b, a, y, x, n)].min\nend\n"}, {"source_code": "t = gets.to_i\nt.times do \n a, b, x, y, n = gets.chomp.split(\" \").map(&:to_i)\n if a < b\n tmp = a\n a = b\n b = tmp\n tmpx = x\n x = y\n y = tmpx\n end\n iti = b - n\n if iti >= y\n b = b - n\n else\n #puts \"IIII\"\n if y <= x\n over = n - (b - y)\n a = [x,a-over].max\n b = y\n elsif x < y\n point = a - n\n if point >= y\n over = n - (b - y)\n a = [x,a-over].max\n b = y\n elsif point < y\n if point >= x\n a = point\n # puts \"OOOOOO\"\n # p a\n # p b\n # puts \"UU\"\n else\n over = n - (a - x)\n b = [b - over,y].max\n a = x\n end\n end\n end\n end\n puts a * b\nend\n"}], "negative_code": [], "src_uid": "04753f73af685b4e7339d30d6d47c161"} {"source_code": "n=gets\ns=gets.chomp\n\narr=[]\n\"a\".upto(\"z\"){|e|\n\tarr<26 ? -1 : n-h.size"}, {"source_code": "# http://codeforces.com/contest/672/problem/B\nn = gets.chomp.to_i\nchars = gets.chomp.chars\n\nif n > 26\n puts \"-1\"\nelse\n puts n - chars.uniq.length\nend"}, {"source_code": "n = readline.to_i\nstr = readline.strip.each_char.to_a\nn = str.length\nm = str.uniq.length\nif n > 26\n puts -1\nelse\n puts n - m\nend\n\n"}, {"source_code": "n=gets.chomp.to_i\na=gets.chomp.split(\"\")\nif n>26\nputs\"-1\"\nelse\nn=n-a.uniq.length\nputs\"#{n}\"\nend"}, {"source_code": "n = gets.chomp.to_i\ns = gets.chomp.split \"\"\nrep = 0\nstore = Array.new(255, 0)\ns.each do |c|\n store[c.ord] += 1\n rep += store[c.ord] if store[c.ord] == 1\nend\nif n > 26\n puts \"-1\"\nelse\n puts n - rep\nend\n"}, {"source_code": "\n n=gets.chomp.to_i\na=gets.chomp.split(\"\")\nif n>26\nputs\"-1\"\nelse\nn=n-a.uniq.length\nputs\"#{n}\"\nend"}, {"source_code": "a = Hash.new(0)\nn = gets.chomp.to_i\ns = gets.chomp\nfor i in 0..n-1\n\ta[s[i]]+=1\nend\nsum = 0\nfor i in'a'..'z'\n\tsum += a[i]-1 if a[i]>1\nend\nif n > 26\n\tputs \"-1\"\nelse\n\tputs sum\nend\n"}, {"source_code": "# coding: utf-8\n\nn = gets.to_i\ns = gets.chomp\ncounter = {}\nsubcnt = 0\nfor c in s.split(//)\n counter[c] ||= 0\n counter[c] += 1\n\n if counter[c] > 1\n subcnt += 1\n end\nend\n\nif 26 - (subcnt + counter.length) >= 0\n puts subcnt\nelse\n puts -1\nend\n\n"}, {"source_code": "n = gets.to_i\nputs n <= 26 ? n - gets.chomp.chars.uniq.size : -1\n"}, {"source_code": "input = gets.chomp.to_i\nstr = gets.chomp\nflag = {}\ndupCount = 0\nblank = 0\n\nif str.length > 26\n\tputs '-1'\n\texit\nend\n\nstr.each_char do |c|\n\tif flag.has_key? c\n\t\tflag[c] += 1\n\telse\n\t\tflag[c] = 1\n\tend\nend\n\nfor c in ('a'..'z') do\n\tblank += 1 if !flag.has_key?(c)\nend\n\nflag.each do |k, v|\n\tdupCount += (v - 1) if v > 1\nend\n\nans = 0\n\n#puts \"Dup : #{dupCount}\"\n#puts \"Blank #{blank}\"\n\nuntil dupCount == 0 || blank == 0\n\tblank -= 1\n\tdupCount -= 1\n\tans += 1\nend\n\nputs ans"}, {"source_code": "gets\n\ns = gets.chomp\n\nlet = Hash.new\nlet.default = 0\n\nif s.length > 26\n print -1\n exit\nend\n\nres = 0\n\ns.length.times { |num|\n ch = s[num]\n if let[ch] == 0\n let[ch] = 1\n else\n let[ch] += 1\n res += 1\n end\n}\n\nputs res\n\n# qwertyuiopasdfghjklzxcvbnm\n# mmmmmmmmmmmmmmmmmmmmmmmmmm\n\n"}], "negative_code": [{"source_code": "# coding: utf-8\n\nn = gets.to_i\ns = gets.chomp\ncounter = {}\nsubcnt = 0\nfor c in s.split(//)\n counter[c] ||= 0\n counter[c] += 1\n\n if counter[c] > 1\n subcnt += 1\n end\nend\n\nputs subcnt\n\n"}, {"source_code": "n = gets.to_i\nputs n - gets.chomp.chars.uniq.size\n"}, {"source_code": "input = gets.chomp.to_i\nstr = gets.chomp\nflag = {}\ndupCount = 0\nblank = 0\n\nif str.length > 26\n\tputs '-1'\n\texit\nend\n\nstr.each_char do |c|\n\tif flag.has_key? c\n\t\tflag[c] += 1\n\telse\n\t\tflag[c] = 1\n\tend\nend\n\nfor c in ('a'..'z') do\n\tblank += 1 if !flag.has_key?(c)\nend\n\nflag.each do |k, v|\n\tdupCount += 1 if v > 1\nend\n\nans = 0\n\nuntil dupCount == 0 || blank == 0\n\tblank -= 1\n\tdupCount -= 1\n\tans += 1\nend\n\nputs ans"}], "src_uid": "d9e9c53b391eb44f469cc92fdcf3ea0a"} {"source_code": "n,v=gets.split.map(&:to_i)\na=1.step(n).select{|i|\ngets.split.map(&:to_i)[1..-1].any?{|e|ex\n\t\t\tq.push(i+1)\n\t\t\tbreak\n\t\tend\n\tend\nend\nputs q.count\nif (!q.empty?)\n\tfor i in q\n\t\tprint i.to_s+' '\n\tend\nend\nputs\n"}, {"source_code": "n, v = gets.chomp.split(/ /).map(&:to_i)\nsellers = []\nn.times do\n line = gets.chomp.split(/ /).map(&:to_i)\n prices = line[1...line.length]\n sellers << prices\nend\ndeal = []\nsellers.each_index do |seller|\n prices = sellers[seller]\n prices.each do |price|\n if price < v\n deal << seller + 1\n break\n end\n end\nend\ndeal.sort!\nputs deal.length\nputs deal.join(\" \")\n"}, {"source_code": "n,v=gets.split.map{|e| e.to_i}\nans=[]\nn.times{|i|\n\tx=gets.split.map{|e| e.to_i}\n\tx.shift\n\tif x.min0 then\n\tputs ans*\" \"\nend\n\n"}, {"source_code": "input = gets.split(\" \").map{|el| el.to_i }\nsellers = input[0]\nmoney = input[1]\noutput = []\n\n\nfor i in 1..sellers\n input = []\n input = gets.split(\" \").map{|el| el.to_i}\n for j in 1...input.size\n if input[j] < money\n output << i \n break\n end\n end\nend\n\nputs output.size\nputs output.join(\" \")\n"}, {"source_code": "# coding: utf-8\n\nn, v = gets.split.map(&:to_i)\ndealers = []\nn.times { |dealer|\n _, *prices = gets.split.map(&:to_i)\n if v > prices.min\n dealers << dealer + 1\n end\n}\nputs dealers.length\nputs dealers.join(' ')\n"}, {"source_code": "nk = gets.chomp.split.map(&:to_i)\nn = nk[0]\nk = nk[1]\narr = []\ncount = 0\na = []\nfor i in (0..n-1)\n\tarr << gets.chomp.split.map(&:to_i)\n\tarr[i].delete_at(0)\n\tif arr[i].min < k\n\t\tcount += 1\n\t\ta << i+1\n\tend\nend\n\nputs count\nfor num in a\n\tprint num\n\tprint \" \"\nend"}, {"source_code": "n,v=gets.split.map(&:to_i)\na=1.step(n).select{|i|\ngets.split.map(&:to_i)[1..-1].any?{|e|e 0\n count += 1\n indices << arr.index(x) + 1\n end\nend\nputs count\nindices.each { |x| print x, \" \" }\n"}, {"source_code": "n,v=gets.split.map(&:to_i)\na=1.step(n).select{|i|\ngets.split.map(&:to_i)[1..-1].any?{|e|e x}\nend\nputs sellers.count\nputs sellers.join(\" \")\n"}, {"source_code": "n,v = gets.split.map(&:to_i)\nd = (1..n).select { |_|\n items = gets.split.map(&:to_i).drop 1\n items.select { |i| v > i }.size >= 1\n}\nputs d.size\nputs d.join \" \"\n"}, {"source_code": "n,v=gets.split.map(&:to_i)\na=1.step(n).select{|i|\ngets.split.map(&:to_i)[1..-1].any?{|e|emas[i]\n k+=1\n p+=j.to_s+\" \"\n break\n end\n i+=1\n end\nj+=1\nend\nputs k\nputs p"}, {"source_code": "n,v=gets.split.map(&:to_i)\na=1.step(n).select{|i|\ngets.split.map(&:to_i)[1..-1].any?{|e|ex\n\t\t\tq.push(i+1)\n\t\t\tbreak\n\t\tend\n\tend\nend\nputs q.count\nif (!q.empty?)\n\tfor i in q\n\t\tprint i.to_s+' '\n\tend\nend\nputs\n"}], "negative_code": [{"source_code": "n, v = gets.chomp.split(/ /).map(&:to_i)\nsellers = []\nn.times do\n line = gets.chomp.split(/ /).map(&:to_i)\n prices = line[1...line.length]\n sellers << prices\nend\ndeal = []\nsellers.each_index do |seller|\n prices = sellers[seller]\n prices.each do |price|\n if price < v\n deal << seller + 1\n end\n end\nend\ndeal.sort!\nputs deal.length\nputs deal.join(\" \")\n"}, {"source_code": "# coding: utf-8\n\nn, v = gets.split.map(&:to_i)\ndealers = []\nn.times {\n dealer, *prices = gets.split.map(&:to_i)\n prices.each { |i|\n if i < v\n dealers << dealer\n break\n end\n }\n}\nputs dealers.length\nputs dealers.join(' ')\n"}, {"source_code": "first_line=gets().split(\" \")\nans=[]\nn=first_line[0].to_i;money=first_line[1].to_i\nfor i in 0...n\n line=gets().split(\" \")\n line.map!{|x| x.to_i}\n for i in 1...line.size\n if line[i]x\n\t\t\tq.push(k)\n\t\t\tbreak\n\t\tend\n\tend\nend\nputs q.count\nif (!q.empty?)\n\tfor i in q\n\t\tprint i.to_s+' '\n\tend\nend\nputs\n"}], "src_uid": "7804152ee14264afef019c5ad33094f9"} {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n l2 = a.max\n l1 = n - l2\n count = 0\n pair = []\n p1 = a.slice(0, l1)\n p2 = a.slice(l1, l2)\n if p1.min == 1 && p1.max == l1 && p2.min == 1 && p2.max == l2\n if p1.uniq.length == l1 && p2.uniq.length == l2\n count += 1\n pair.push([l1, l2])\n end\n end\n if l1 != l2\n p1 = a.slice(0, l2)\n p2 = a.slice(l2, l1)\n if p1.min == 1 && p1.max == l2 && p2.min == 1 && p2.max == l1\n if p1.uniq.length == l2 && p2.uniq.length == l1\n count += 1\n pair.push([l2, l1])\n end\n end\n end\n puts count\n pair.each do |pa|\n puts pa.join(\" \")\n end\nend", "positive_code": [{"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n l2 = a.max\n l1 = n - l2\n count = 0\n pair = []\n p1 = a.slice(0, l1)\n p2 = a.slice(l1, l2)\n if p1.min == 1 && p1.max == l1 && p2.min == 1 && p2.max == l2\n if p1.uniq.length == l1 && p2.uniq.length == l2\n count += 1\n pair.push([l1, l2])\n end\n end\n if l1 != l2\n p1 = a.slice(0, l2)\n p2 = a.slice(l2, l1)\n if p1.min == 1 && p1.max == l2 && p2.min == 1 && p2.max == l1\n if p1.uniq.length == l2 && p2.uniq.length == l1\n count += 1\n pair.push([l2, l1])\n end\n end\n end\n puts count\n pair.each do |pa|\n puts pa.join(\" \")\n end\nend\n"}], "negative_code": [{"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n l2 = a.max\n l1 = n - l2\n count = 0\n pair = []\n p1 = a.slice(0, l1)\n p2 = a.slice(l1, l2)\n if p1.uniq.length == l1 && p2.uniq.length == l2\n count += 1\n pair.push([l1, l2])\n end\n if l1 != l2\n p1 = a.slice(0, l2)\n p2 = a.slice(l2, l1)\n if p1.uniq.length == l2 && p2.uniq.length == l1\n count += 1\n pair.push([l2, l1])\n end\n end\n puts count\n pair.each do |pa|\n puts pa.join(\" \")\n end\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n l2 = a.max\n l1 = n - l2\n count = 0\n pair = []\n p1 = a.slice(0, l1)\n p2 = a.slice(l1, l2)\n if p1.uniq.length == l1 && p2.uniq.length == l2\n count += 1\n pair.push([l1, l2])\n end\n p1 = a.slice(0, l2)\n p2 = a.slice(l2, l1)\n if p1.uniq.length == l2 && p2.uniq.length == l1\n count += 1\n pair.push([l2, l1])\n end\n puts count\n pair.each do |pa|\n puts pa.join(\" \")\n end\nend\n"}], "src_uid": "5f0f79e39aaf4abc8c7414990d1f8be1"} {"source_code": "#!/usr/bin/ruby\n \nn = gets.chomp.to_i\n\ns1 = \"I hate \"\ns2 = \"I love \"\ns3 = \"that \"\ns4 = \"it\"\n\nfor i in 1..n \n if (i % 2 != 0)\n print s1\n else \n print s2\n end\n if i != n\n print s3\n else \n print s4\n end\nend\n\n", "positive_code": [{"source_code": "n=gets.chomp().to_i\ns3=\"I love\"\ns2=\" that \"\ns1=\"I hate\"\ns4=\"I hate\"\ns5=\" it\"\ni=2\nwhile i<=n\n if i%2==0\n s1+=s2+s3\n else\n s1+=s2+s4\n end\n i=i+1\nend\ns1=s1+s5\nputs(s1)"}, {"source_code": "#!/usr/bin/ruby\nN=gets.to_i\nN.times{|i|\n\tprint i%2==0?'I hate ':'I love '\n\tprint i 0\n print \"that I hate \"\n else\n print \"that I love \"\n end\nend\nputs \"it\""}, {"source_code": "hate = \"I hate\"\nlove = \"I love\"\n\nlvl = Integer(STDIN.gets())\n\nprev_emotion = false\nemotion = \"\"\n\nlvl.times { |x|\n\n if prev_emotion\n emotion += \" that \"\n else\n prev_emotion = true\n end\n \n if x.even?\n emotion += hate\n else\n emotion += love\n end\n}\n\nemotion += \" it\"\n\nputs emotion\n"}, {"source_code": "feel_number = gets.strip.to_i\nfeels = []\n\nindex = 1\nfeel_number.times do\n if index.odd?\n feels.push('I hate')\n else\n feels.push('I love')\n end\n index += 1\nend\n\noutput = feels.join(' that ')\noutput += ' it'\nputs output\n"}, {"source_code": "n = gets.to_i\nn.times{ |x|\n print x % 2 == 0 ? \"I hate \" : \"I love \"\n print x + 1 == n ? \"it \" : \"that \"\n}\n"}, {"source_code": "n = gets.to_i\n\nps = 'I hate '\np1 = 'that I love '\np2 = 'that I hate '\npe = 'it'\ni = 1\nwhile(i < n) do\n\n if (i % 2 ==1)\n ps += p1\n else\n ps += p2\n end\n \n i = i + 1\nend\nps+=pe\nputs ps"}, {"source_code": "number = gets.chomp.to_i\n\nhate = \"I hate \"\nlove = \"I love \"\n\nif number == 1\n\tprint hate \n\tprint \"it\"\nelse\n\tfor i in (1..number)\n\t\tif i % 2 != 0 # odd = hate\n\t\t\tprint hate \n\t\t\tif i != number\n\t\t\t\tprint \"that \"\n\t\t\telse\n\t\t\t\tprint \"it\"\n\t\t\tend\n\t\telse\t# even = love\n\t\t\tprint love\n\t\t\tif i != number\n\t\t\t\tprint \"that \"\n\t\t\telse\n\t\t\t\tprint \"it\"\n\t\t\tend\n\t\tend\n\tend\nend"}, {"source_code": "n = gets.to_i\nresult = []\n(1..n).each_with_index do |index|\n\tresult << (index.even? ? 'I love' : 'I hate')\n\tresult << (index == n ? 'it' : 'that')\nend\nprint result.join(' ')"}, {"source_code": "word = [\"I hate\", \"I love\"]\ninput = gets.chomp!.to_i \nputs word.cycle.take(input).join(\" that \").concat(' it')"}, {"source_code": "layers = gets.to_i\nreduced = 0;\nresult = \"\"\nuntil layers == 0\n if reduced == 0\n result = result + \"I hate\"\n end\n\n if reduced == 1\n result = result + \" that I love\"\n end\n\n if reduced > 1\n if reduced % 2 == 0\n result = result + \" that I hate\"\n end\n if reduced % 2 > 0\n result = result + \" that I love\"\n end\n end\n\n layers = layers - 1\n reduced = reduced + 1\nend\nresult = result + \" it\"\nputs result"}, {"source_code": "s = \"\"\nn = gets.to_i\n\nfor i in (1..n-1)\n i%2 == 1 ? s += \"I hate that \" : s += \"I love that \"\nend\n\nputs s + (n%2 == 0 ? \"I love it\" : \"I hate it\")\n"}, {"source_code": "$n = gets\n$n = $n.to_i\nprint \"I \"\n(1..$n).each do |i|\n\tif ((i%2 == 0)and(i == $n))\n\t\tprint \"love it\"\n\t\tbreak\n\tend\n\tif ((i%2 == 1)and(i == $n))\n\t\tprint \"hate it\"\n\t\tbreak\n\tend\n\tif i%2 == 0\n\t\tprint \"love that I \"\n\tend\n\tif i%2 == 1\n\t\tprint \"hate that I \"\n\tend\nend\n"}, {"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\nn = STDIN.gets.to_i\nres = \"\"\nhate = true\nfor i in 1..n - 1 do\n if hate\n res += \"I hate that \"\n hate = false\n else\n hate = true\n res += \"I love that \"\n end\nend\n\nif hate\n res += \"I hate it\"\nelse\n res += \"I love it\"\nend\n\nputs res\n"}, {"source_code": "LEVELS = ['I hate', 'I love']\n\nlevel = gets.to_i\n\nputs LEVELS.cycle.take(level).join(' that ').concat(' it')"}, {"source_code": "n = gets.to_i\nans = 'I hate'\n(2..n).each do |i|\n if i.odd?\n ans += ' that I hate'\n else\n ans += ' that I love'\n end\nend\nputs ans + ' it'"}, {"source_code": "n = gets.chomp.to_i\n\nn.times do |i|\n\tif (i + 1).even? then\n\t\tprint \"I love\"\n\telse\n\t\tprint \"I hate\"\n\tend\n\tprint i == n - 1 ? \" it \" : \" that \"\nend\nputs \n\n"}, {"source_code": "n = gets.strip.to_i\nodd_s = \"I hate\"\neven_s = \"I love\"\ns = Array.new(n) { |i| (i + 1).odd? ? odd_s : even_s }\nans = s.join(\" that \") + \" it\"\nputs ans\n"}, {"source_code": "n = gets.to_i\nputs n.times.map{|i| i.even? ? 'I hate' : 'I love'}.join(' that ') + ' it'\n"}, {"source_code": "n=gets.to_i\na=[\"I hate\",\"I love\"]\nstr=\"\"\np1=0\nn.times{|i|\n\t\n\tif i==0 then\n\t\tstr=a[0]\n\telse\n\t\tstr=str+\" that \"+a[p1]\n\tend\n\tp1=((p1==1)?0:1)\n}\nputs str+\" it\""}, {"source_code": "t = gets.to_i\nfor i in 0..t-1\n\tif i%2 == 0\n\t\tprint \"I hate \"\n\t\tif i == t-1\n\t\t\tprint \"it\"\n\t\telse\n\t\t\tprint \"that \"\n\t\tend\n\telse\n\t\tprint \"I love \"\n\t\tif i == t-1\n\t\t\tprint \"it\"\n\t\telse\n\t\t\tprint \"that \"\n\t\tend\n\tend\nend\nprint \"\\n\""}, {"source_code": "input = gets.to_i\n\nans = [\"I hate \" , \"I love \"].cycle(input).to_a[0..input-1].join(\"that \")\nputs ans + \"it\""}, {"source_code": "input = gets.chomp.to_i\n1.upto(input-1){ |i|\n\t if i.even?\n\t\tprint \"I love \"\n\telse\n\t\tprint \"I hate \"\n\tend\n\tprint \"that \"\n}\nif input.even?\n\t\tprint \"I love it\"\nelse\n\t\tprint \"I hate it\"\n\tend\n\n\t"}, {"source_code": "n = gets.chomp.to_i\ns = \"\"\n\nco = 0\nn.times.each do\n if co == 0\n s += 'I hate it'\n co +=1\n elsif co %2 == 0\n s.gsub!('it', 'that I love it')\n else\n s.gsub!('it', 'that I hate it')\n end\n co +=1\nend\n\nputs s"}, {"source_code": "input = gets.to_i\ninput.times {|i|\nprint i % 2 == 0 ?\"I hate\" : \"I love\"\nprint i == input - 1 ? \" it\" : \" that \"\n}"}, {"source_code": "n = gets.chomp.to_i\nsentence = \"\"\n\nfor i in (1...n+1)\n if i % 2 != 0\n sentence += \"I hate\"\n else\n sentence += \"I love\"\n end\n if i != n\n sentence += \" that \"\n end\nend\n\nsentence += \" it\"\nputs sentence"}, {"source_code": "n = gets.to_i\n0.upto(n-1) do |i|\n\tif i != 0 \n\t\tprint 'that '\n\tend\n\tif i % 2 == 0 \n\t\tprint 'I hate '\n\telse\n\t\tprint 'I love '\n\tend\nend\nputs 'it'\n"}, {"source_code": "# https://codeforces.com/problemset/problem/705/A\n\nn = gets.to_i\n\nfeeling = \"I hate it\"\n\n\n2.upto(n) do |i|\n if i % 2 == 0\n feeling.gsub!(\"it\", \"that I love it\")\n else\n feeling.gsub!(\"it\", \"that I hate it\")\n end\nend\n\nputs feeling"}, {"source_code": "n = gets.chomp.to_i\n\nw = [\"I hate that\", \"I love that\"]\n\nresult = \"I hate it\"\npos = 1\nif n%2 == 0 then\n\tresult = \"I love it\"\n\tpos = 0\nend\n\n1.upto(n-1) do\n\tresult = w[pos] + \" \" + result\n\tpos = (pos+1)%2\nend\n\nputs result\n"}, {"source_code": "n = STDIN.gets.to_i\ns = '' \nn.times do |i|\n\ts += 'I '+((i%2)==0 ? 'hate' : 'love')+' '+(i==n-1 ? 'it' : 'that ')\nend \nputs s\n\n"}, {"source_code": "input = gets.to_i\nfeeling1 = \"I hate\"\nfeeling2 = \"I love\"\nfeeling = \"\"\nif(input == 1)\n feeling = \"I hate it\"\nelse\n c = 1\n while(c <= input)\n if(c%2 == 1)\n feeling += feeling1\n if(c!=input)\n feeling += \" that \"\n end\n else\n feeling += feeling2\n if(c!=input)\n feeling += \" that \"\n end\n end\n c += 1\n end\n feeling += \" it\"\nend\nputs feeling\n\n"}, {"source_code": "n=gets.to_i\ns=\"\"\nn.times do |x|\n\ts+=\"I love \" if x%2==1\n\ts+=\"I hate \" if x%2==0\n\ts+=\"that \" if x!=n-1\n\ts+=\"it\" if x==n-1\nend\nputs s\n"}, {"source_code": "n = gets.chomp.to_i\nans = ''\n\nn.times do |i|\n\ti += 1\n\n\tans += 'I hate ' if i % 2 == 1\n\tans += 'I love ' if i % 2 == 0\n\n\tans += 'that ' if i != n\nend\n\nans += 'it'\n\nputs ans"}, {"source_code": "def love(n)\n\tphrase = \"\"\n\twhile n > 0\n\t\tphrase << \"I hate \"\n\t\tn = n - 1\n\t\tphrase << \"that \" if n > 0\n\t\tphrase << \"I love \" if n > 0\n\t\tn = n - 1\n\t\tphrase << \"that \" if n > 0\n\tend\n\tphrase << \"it\"\n\treturn phrase\nend\n\nn = gets.chomp.to_i\nputs(love(n))"}, {"source_code": "n=gets.to_i\nres=\"\"\nn.times {|i|\n res+=\"that \" if res.size>0\n if i.even?\n res+=\"I hate \"\n else\n res+=\"I love \" \n end\n}\nres+=\"it\"\nputs res\n"}], "negative_code": [{"source_code": "n = gets.to_i\n\npc = 'I hate it'\np1 = 'I love that '\np2 = 'I hate that '\ni = 1\nwhile(i < n) do\n i = i + 1;\n if (i % 2 ==1)\n pc = p1 + pc\n else\n pc = p2 + pc\n end\nend\n\nputs pc"}, {"source_code": "s = \"\"\nn = gets.to_i\n\nfor i in (1..n-1)\n (n-i)%2 == 0 ? s += \"I hate that \" : s += \"I love that \"\nend\n\nputs s + \"I hate it\"\n"}, {"source_code": "s = \"\"\nn = gets.to_i\n\nfor i in (1..n-1)\n (n-i)%2 == 1 ? s += \"I hate that \" : s += \"I love that \"\nend\n\nputs s + (n%2 == 0 ? \"I love it\" : \"I hate it\")\n"}, {"source_code": "LEVELS = ['I hate that I love that I hate it', 'I hate it', 'I hate that I love it']\n\nlevel = gets.to_i\n\nputs LEVELS[level % 3]"}, {"source_code": "n = gets.chomp.to_i\n\nn.times do |i|\n\tif (i + 1).even? then\n\t\tprint \"I love it \"\n\telse\n\t\tprint \"I hate that\"\n\tend\nend\nputs \n\n"}, {"source_code": "n = gets.to_i\nputs n.times.map{|i| i.even? ? 'I hate it' : 'I love it'}.join(' that ')\n"}, {"source_code": "input = gets.chomp.to_i\n1.upto(input-1){ |i|\n\t if i.even?\n\t\tprint \"I Love \"\n\telse\n\t\tprint \"I Hate \"\n\tend\n\tprint \"that \"\n}\nif input.even?\n\t\tprint \"I Love it\"\nelse\n\t\tprint \"I Hate it\"\n\tend\n\n\t"}, {"source_code": "n = gets.chomp.to_i\nsentence = \"\"\n\nfor i in (1...n+1)\n if i % 2 != 0\n sentence += \"I hate\"\n else\n sentence += \"I love\"\n end\n if i != n\n sentence += \" that \"\n end\nend\n\nsentence += \" It\"\nputs sentence"}, {"source_code": "word = [\"I hate\", \"I love\"]\ninput = gets.chomp!.to_i \np word.cycle.take(input).join(\" that \").concat(' it')"}, {"source_code": "word = [\"I hate\", \"I love\"]\ninput = gets.chomp!.to_i \np word.cycle.take(input).join(\" that \").concat(' it ')"}, {"source_code": "layers = gets.to_i\nreduced = 0;\nresult = \"\"\nuntil layers == 0\n if reduced == 0\n result = result + \"I hate\"\n end\n\n if reduced == 1\n result = result + \" that I love\"\n end\n\n if reduced > 1\n if reduced % 2 == 0\n result = result + \" that I hate\"\n end\n if reduced % 3 == 0\n result = result + \" that I love\"\n end\n end\n\n layers = layers - 1\n reduced = reduced + 1\nend\nresult = result + \" it\"\nputs result"}, {"source_code": "layers = gets.to_i\nreduced = 0;\nresult = \"\"\nuntil layers == 0\n if reduced == 0\n result = result + \"I hate it\"\n end\n\n if reduced == 1\n result = result + \" that I love it\"\n end\n\n if reduced > 1\n if reduced % 2 == 0\n result = result + \" that I hate it\"\n end\n if reduced % 3 == 0\n result = result + \" that I love it\"\n end\n end\n \n layers = layers - 1\n reduced = reduced + 1\nend\nputs result"}, {"source_code": "numbers = gets.chomp\nstart = 1\nresult = \"\"\nwhile start <= numbers.to_i\n if start > 1\n result = result + \" that \"\n end\n if start % 2 == 0\n result = result + \"I hate it\"\n else\n result = result + \"I love it\"\n end\n start = start + 1\nend\nputs result\n"}, {"source_code": "numbers = gets.chomp\nstart = 1\nresult = \"\"\nwhile start <= numbers.to_i\n if start > 1\n result = result + \" that \"\n if start % 2 == 0\n result = result + \"I hate it\"\n else\n result = result + \"I love it\"\n end\n else\n result = result + \"I hate it\"\n end\n # if start % 2 == 0 && start > 1\n # result = result + \"I hate it\"\n # elsif\n # result = result + \"I love it\"\n # end\n start = start + 1\nend\nputs result\n"}, {"source_code": "n=gets.to_i\na=[\"I hate\",\"I love\",\"I hate\"]\nstr=\"\"\nn.times{|i|\n\tif i==0 then\n\t\tstr=a[0]\n\telse\n\t\tstr=str+\" that \"+a[i%3]\n\tend\n}\nputs str+\" it\"\n"}, {"source_code": "n=gets.chomp().to_i\ns3=\"i love it\"\ns2=\" that \"\ns1=\"i hate it\"\ns4=\"i hate it\"\ni=2\nwhile i<=n\n if i%2==0\n s1+=s2+s3\n else\n s1+=s2+s4\n end\n i=i+1\nend\nputs(s1)"}, {"source_code": "n=gets.chomp().to_i\ns3=\" ilove it \"\ns2=\" that \"\ns1=\"i hate it \"\ns4=\"i hate it \"\ni=2\nwhile i<=n\n if i%2==0\n s1+=s2+s3\n else\n s1+=s2+s4\n end\n i=i+1\nend\nputs(s1)"}, {"source_code": "n=gets.chomp().to_i\ns3=\"I love it\"\ns2=\" that \"\ns1=\"I hate it\"\ns4=\"I hate it\"\ni=2\nwhile i<=n\n if i%2==0\n s1+=s2+s3\n else\n s1+=s2+s4\n end\n i=i+1\nend\nputs(s1)"}], "src_uid": "7f2441cfb32d105607e63020bed0e145"} {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nl = r = 0\narr.each_with_index do |a,i|\n\ts = i + 1\n\tif a != s\n\t\tl = s\n\t\tr = a\n\t\tbreak\n\tend\nend\n# puts \"#{l} #{r}\"\nif l != 0 && r != 0\n\t(l..r).each do |z|\n\t\ti = z-1\n\t\tarr[i] = z\t\n\tend\n\tval = (1..n).to_a\n\t# puts \"#{arr} #{val}\"\n\tif arr != val\n\t\tl = 0\n\t\tr = 0\n\tend\nend\nputs \"#{l} #{r}\"", "positive_code": [{"source_code": "n = gets.to_i\ns = gets.chomp!.split(\" \")\nmas = Array.new()\n\nfor i in 0..n-1\n mas[i] = s[i].to_i\nend\n\nstart,finish = 0, 0\nwrong = false\nfor i in 1..n-1\n if mas[i] == mas[i-1] - 1\n start = i if start == 0\n else\n finish = i if start != 0 && finish == 0\n end\nend\n\nfinish = n if finish == 0 && start != 0\n\nfor i in 0..start-3\n wrong = true if mas[i] + 1 != mas[i+1]\nend\nfor i in finish..n-2\n wrong = true if mas[i] + 1 != mas[i+1]\nend\n \nputs wrong ? \"0 0\" : start.to_s + \" \"+finish.to_s\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nl,r=99999,0\n1.upto(n){|i|\n if a[i-1]!=i then\n l=[l,i].min\n r=[r,i].max\n end\n}\nif l==99999 then\n puts \"0 0\"\n exit\nend\na=((l-2>=0)?a[0..(l-2)]:[])+a[(l-1)..(r-1)].reverse+a[(r)..(a.length-1)]\n1.upto(n){|i|\n if(a[i-1]!=i) then\n puts \"0 0\"\n exit\n end\n}\nputs \"#{l} #{r}\"\n"}, {"source_code": "def check a,n\n i = 0\n z = []\n while i < n do\n z[i]= i+1\n if a[i]!=z[i] then\n return false\n end\n i += 1\n end\n return true\nend\n\ndef get_sub_array a,i\n j = i\n res = []\n while j < a.length-1 do\n if a[j]-a[j+1]==1 then\n if !res.include?(a[j]) then\n res << a[j]\n end\n if !res.include?(a[j+1]) then\n res << a[j+1]\n end\n else\n if !res.include?(a[j]) then\n res << a[j]\n end\n break\n end\n j+=1\n end\n return res.reverse\nend\n\ndef conc a,b,i,n\n j,count = 0,0\n while j < a.length do\n if i == j - 1 then\n count = i;\n j2 = 0\n while j2 < b.length do\n a[count] = b[j2];\n count += 1\n j2 += 1\n end\n break\n end\n j += 1\n end\n if check(a, n) then\n return true\n end\n return false\nend\n\n\ndef solve!\n m = gets.to_i\n s = gets.chomp\n a = s.split(\" \")\n q = a.map { |x| x.to_i }\n if check(q,m) then\n print \"0 0\"\n else\n i = 0\n for c in q\n if c != i+1 then\n z = get_sub_array(q , i)\n if conc(q, z, i, m)then\n print \"#{z[0]} #{z[z.length - 1]}\"\n break\n else\n print \"0 0\"\n break\n end\n end\n i += 1\n end\n end\nend\n\nsolve!"}], "negative_code": [{"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nl = r = 0\narr.each_with_index do |a,i|\n\ts = i + 1\n\tif a != s\n\t\tl = s\n\t\tr = a\n\t\tbreak\n\tend\nend\n# puts \"#{l} #{r}\"\nif l != 0 && r != 0\n\tx = r\n\tarr[(l-1)..(r-1)].each do |a|\n\t\tif a != x\n\t\t\tl = 0\n\t\t\tr = 0\n\t\t\tbreak\n\t\tend\n\t\tx -= 1\n\tend\nend\nputs \"#{l} #{r}\""}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map(&:to_i)\nl = r = 0\narr.each_with_index do |a,i|\n\ts = i + 1\n\tif a != s\n\t\tl = s\n\t\tr = a\n\t\tbreak\n\tend\nend\n# puts \"#{l} #{r}\"\nif l != 0 && r != 0\n\t(l..r).each do |z|\n\t\ti = z-1\n\t\tarr[i] = z\t\n\tend\n\tval = (1..n).to_a\n\tputs \"#{arr} #{val}\"\n\tif arr != val\n\t\tl = 0\n\t\tr = 0\n\tend\nend\nputs \"#{l} #{r}\""}, {"source_code": "n = gets.to_i\ns = gets.chomp!.split(\" \")\nmas = Array.new()\n\nfor i in 0..n-1\n mas[i] = s[i].to_i\nend\n\nstart,finish = 0, 0\nwrong, first_wrong = false, true\nfor i in 1..n-1\n if mas[i] == mas[i-1] - 1\n start = i if start == 0\n \n wrong = true if finish != 0\n else\n finish = i if start != 0 && finish == 0\n\n first_wrong ? first_wrong = false : wrong = true if mas[i-1] + 1 != mas[i]\n end\nend\n\nfinish = n if finish == 0 && start != 0\n \nputs wrong ? \"0 0\" : start.to_s + \" \"+finish.to_s\n\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp!.split(\" \")\nmas = Array.new()\n\nfor i in 0..n-1\n mas[i] = s[i].to_i\nend\n\nstart,finish = 0, 0\nfor i in 1..n-1\n if mas[i] == mas[i-1] - 1\n if start == 0\n start = i\n end\n if finish != 0\n puts \"0 0\"\n exit\n end\n else\n if start != 0 && finish == 0\n finish = i\n end\n end\nend\n\nif finish == 0 && start != 0\n finish = n\nend\n\nputs start.to_s + \" \"+finish.to_s\n\n"}, {"source_code": "n = gets.to_i\ns = gets.chomp!.split(\" \")\nmas = Array.new()\n\nfor i in 0..n-1\n mas[i] = s[i].to_i\nend\n\nstart,finish = 0, 0\nwrong, first_wrong = false, true\nfor i in 1..n-1\n if mas[i] == mas[i-1] - 1\n start = i if start == 0\n \n wrong = true if finish != 0\n else\n finish = i if start != 0 && finish == 0\n\n first_wrong ? firstwrong = false : wrong = true if mas[i-1] + 1 != mas[i]\n end\nend\n\nfinish = n if finish == 0 && start != 0\n \nputs wrong ? \"0 0\" : start.to_s + \" \"+finish.to_s\n\n"}], "src_uid": "a440099306ef411a4deca7fe3305c08b"} {"source_code": "n = gets.to_i\ns = gets\ns = s.gsub(/[a]+/, 'a')\ns = s.gsub(/[i]+/, 'i')\ns = s.gsub(/[u]+/, 'u')\ns = s.gsub(/[y]+/, 'y')\ns = s.gsub(/[e]{3,100000}/, 'e')\ns = s.gsub(/[o]{3,100000}/, 'o')\nputs s", "positive_code": [{"source_code": "gets\nputs gets.chomp.squeeze(\"aiuy\").gsub(/e{3,}/, 'e').gsub(/o{3,}/, 'o')\n"}, {"source_code": "gets\nputs gets.chomp.squeeze(\"aiuy\").gsub(/e{3,}/, 'e').gsub(/o{3,}/, 'o')"}, {"source_code": "while l = gets\n\ta = gets\n\tb = a.squeeze(\"aiuy\")\n\tc = b.gsub(/e{3,}/, 'e').gsub(/o{3,}/, 'o')\n\tprint c\nend"}, {"source_code": "n = gets\ns = gets\ns = s.gsub(/a{2,}/, 'a')\ns = s.gsub(/e{3,}/, 'e')\ns = s.gsub(/i{2,}/, 'i')\ns = s.gsub(/o{3,}/, 'o')\ns = s.gsub(/u{2,}/, 'u')\ns = s.gsub(/y{2,}/, 'y')\nputs s"}, {"source_code": "n = gets\ns = gets\ni = 0\nlast = '$'\nvowels = 'aiuy'\necount = 0\nocount = 0\ns.split(\"\").each do |c|\n if c == 'e'\n ecount += 1\n elsif ecount > 0\n if ecount == 2\n print 'ee'\n else\n print 'e'\n end\n ecount = 0\n end\n\n if c == 'o'\n ocount += 1\n elsif ocount > 0\n if ocount == 2\n print 'oo'\n else\n print 'o'\n end\n ocount = 0\n end\n\n if vowels.include? c\n unless c === last\n print c\n end\n elsif c != 'e' and c != 'o'\n print c\n end\n\n last = c\nend\n# puts \"#{s}\""}, {"source_code": "# require 'rubygems'\n# gem 'capataz'\n# require 'capataz'\n#\n# class A\n# def m1\n# 1\n# # end\n#\n# def m2\n# 2\n# end\n#\n# def self.m3\n# 3\n# end\n#\n# def self.m4\n# 4\n# end\n# end\n#\n# Capataz.config do\n#\n# set_max_allowed_iterations 6\n#\n# set_max_allowed_invocations :new, 6, :casecmp, 5\n#\n# deny_declarations_of :module\n#\n# deny_invoke_of :constantize\n#\n# allowed_constants A, Set\n#\n# #deny_for A, :m2\n#\n# deny_on A, :m4\n#\n# end\n#\n# puts Capataz.eval <<-RUBY\n#\n# x = A.new\n# x.m1\n# x.m2\n#\n# A.m4\n#\n# RUBY\n\ndef cons(x)\n if ['a','e','i','o','u','y'].include?(x)\n return false\n else\n return true\n end\nend\n\ndef a(x)\n if ['a','i','u','y'].include?(x)\n return true\n else\n return false\n end\nend\n\ndef last(i,n,s)\n while true\n if i == n - 1 or s[i + 1] != s[i]\n return i\n end\n i += 1\n end\nend\n\nn = readline().to_i\ns = readline()\n\n\ni = 0\nwhile i < n\n if cons(s[i])\n print s[i]\n elsif a(s[i])\n unless i < n - 1 and s[i] == s[i + 1]\n print s[i]\n else\n end\n else\n print s[i]\n pos = last(i,n,s)\n if pos > i + 1\n i = pos\n end\n end\n i += 1\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "def is_vowel( ch )\n vowel = \"aeiouy\"\n for i in 0..( vowel.length - 1 ) do\n if vowel[ i ] == ch then\n return true\n end\n end\n return false\nend\n\nN = gets.chomp.to_i\nS = gets.chomp\nans = \"\"\nprev = '$'\nptr = 0\nwhile ptr < N do\n if not is_vowel( S[ ptr ] ) then\n ans.concat( S[ ptr ] )\n ptr += 1\n next # continue \u306e\u8eab\u4ee3\u308f\u308a\u3089\u3057\u3044\n end\n nxt = ptr\n while nxt < N do\n if S[ nxt ] != S[ ptr ] then\n break\n end\n nxt += 1\n end\n if nxt - ptr == 2 and ( S[ ptr ] == 'e' or S[ ptr ] == 'o' ) then\n ans.concat( S[ ptr ] )\n ans.concat( S[ ptr ] )\n else\n ans.concat( S[ ptr ] )\n end\n ptr = nxt\nend\nprint ans"}, {"source_code": "n = gets.to_i\nn = n-1\ns = gets.chomp\nlast = '#'\ncnt = 0\nfor i in (0..n)\n if s[i] != last then\n if \"oe\".count(last) > 0 and cnt == 2 then\n print last\n end\n end\n if \"aeiouy\".count(s[i]) > 0 then\n if s[i] == last then\n cnt = cnt + 1\n else\n print s[i]\n cnt = 1\n end\n else\n print s[i]\n cnt = 1\n end\n last = s[i]\nend\nif \"oe\".count(last) > 0 and cnt == 2 then\n print last\nend\nprint \"\\n\""}], "negative_code": [{"source_code": "gets\nputs gets.chomp.squeeze(\"aiuy\").sub(/e{3,}/, 'e').sub(/o{3,}/, 'o')\n"}, {"source_code": "while l = gets\n\ta = gets\n\tb = a.squeeze(\"aiuy\")\n\tc = b.gsub(/e{3,}/, 'e').gsub(/o{3,}/, 'o')\n\tp c\nend"}, {"source_code": "while l = gets\n\ta = gets\n\tb = a.squeeze(\"aiuy\")\n\tc = b.gsub(/e{3,}/, 'e').gsub(/o{3,}/, 'o')\n\tp \"#{c}\\n\"\nend"}], "src_uid": "8ff1b4cf9875f1301e603b47626d06b4"} {"source_code": "gets; input = gets.strip.split.map &:to_i\nodd, even = [], []\ninput.each {|i| i % 2 == 0 ? even.push(i) : odd.push(i) }\nprint even.length == 1 ? input.index(even.first) + 1 : input.index(odd.first) + 1\n", "positive_code": [{"source_code": "n=gets.chomp.to_i\nmemo=gets.chomp.split.map{|i| i.to_i}\neven=0\nodd=0\nevenIndex=-1\noddIndex=-1\nn.times do |i| \n if memo[i]%2 == 0\n even=even+1\n evenIndex=i\n elsif\n odd=odd+1\n oddIndex=i\n end\nend\nif even > odd\n puts oddIndex+1\nelse\n puts evenIndex+1\nend\n"}, {"source_code": "gets\narr = gets.split.map &:to_i\nputs arr.count { |x| x % 2 == 0 } > arr.count { |x| x % 2 != 0 } ?\n arr.index { |x| x % 2 != 0 } + 1 : arr.index { |x| x % 2 == 0 } + 1\n"}, {"source_code": "n = gets.to_i\na = gets.split.map!{|t| t.to_i}\nb = a.sort{|x,y| x%2 <=> y%2}\nif b[0]%2 != b[1]%2\n puts a.index(b[0])+1\nelse\n puts a.index(b[-1])+1\nend\n"}, {"source_code": "gets.chomp\nnums = gets.chomp.split(/ /).map(&:to_i)\nodds = []\nevens = []\n(0...nums.length).each do |num|\n evens << num + 1 if nums[num].even?\n odds << num + 1 if nums[num].odd?\nend\nans = 0\nif odds.length == 1\n ans = odds[0]\nelse\n ans = evens[0]\nend\nputs ans\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\nb = { 0 => [], 1 => [] }\na.each_with_index do |x, i|\n b[x % 2] << i + 1\nend\nb.each_value do |ns|\n puts ns.first if ns.size == 1\nend\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split.map(&:to_i)\nco = 0\naco = {'odd'=>0,'even'=>0}\narr.each_with_index do |el,i|\n aco['even'] += 1 if el %2 == 0\n aco['odd'] += 1 if el %2 != 0\nend\n\narr.each_with_index do |el,i|\n if aco['odd'] == 1\n if el % 2 != 0\n co = i\n break\n end\n else\n if el % 2 == 0\n co = i\n break\n end\n end\nend\n\nputs co+1"}, {"source_code": "n = gets.to_i\narr = gets.split.map { |e| e.to_i }\nc = 0\n3.times do |i|\n\tarr[i].even? ? c += 1 : c = c\n\ti += 1\nend\nx = 1\nif c >= 2\n\tfor i in arr \n\t\tif i.even? \n\t\t\tx += 1\n\t\telse\n\t\t\tp x\n\t\tend\n\tend\nelse\n\tfor i in arr\n\t\tif i.even?\n\t\t\tp x\n\t\telse\n\t\t\tx += 1\n\t\tend\n\tend\nend"}, {"source_code": "gets\nq = gets.split.map { |e| e.to_i }\n\ns = q.find_all { |x| x.even? }\nif s.size == 1\n puts q.index(s[0]) + 1\n exit\nend\n\ns = q.find_all { |x| x.odd? }\nputs q.index(s[0]) + 1\n"}, {"source_code": "def fn()\nn=gets.to_i\narr=gets.split.collect{|a| a.to_i%2}\neven=arr.count 0\nodd= arr.count 1\nwild=0\nif odd == 1\n wild=1\nend\n\nreturn (arr.index wild)+1\n\nend\n\n\n\np fn()\n"}, {"source_code": "amount = gets.chomp\nn = gets.chomp\n\nnumbers = n.split\neven = 0\nodd = 0\n\nif amount.to_i == numbers.count\n\tfor i in (1..amount.to_i)\n\t\tif numbers[i-1].to_i%2 != numbers[i].to_i%2\n\t\t\ta = numbers[i-1].to_i\n\t\t\tb = numbers[i].to_i\n\t\t\tpos_a = i\n\t\t\tpos_b = i+1\n\t\t\tbreak\n\t\tend\n\tend\nend\n\nnumbers.each do |number|\n\tif number.to_i%2 == 0\n\t\teven += 1\n\telse\n\t\todd += 1\n\tend\nend\n\nif even == 1 && a%2 == 0\n\tprint pos_a\nelsif even == 1 && b%2 == 0\n\tprint pos_b\nelsif odd == 1 && a%2 != 0\n\tprint pos_a\nelse\n\tprint pos_b\nend\n\n"}, {"source_code": "#!/bin/ruby\n\nn = gets.chomp.to_i\n\na = gets.chomp.split(\" \").map {|e| e.to_i}\n\nj = 1\nvitri = 0\nodd = 0\neven = 0\nwE = 0\nwO = 0\na.each do |i|\n if i % 2 == 0\n even += 1\n wE = j\n else\n odd += 1\n wO = j\n end\n j += 1\nend\n\nif even > odd\n puts wO.to_i\nelse\n puts wE.to_i\nend\n"}, {"source_code": "#puts \"Enter total number of integers\\n\" \nn = gets.to_i\n#puts \"Enter the numbers in a line\\n\"\ns = gets.chomp.to_s.split(\" \")\nl = s.length\na = [l]\nfor i in 0...l do\n a[i] = s[i].to_i\nend\ne = []\no = []\nj = 0\nk = 0\nfor c in 0...l do\n if a[c] % 2 == 0\n e[j] = c\n j += 1\n else\n o[k] = c\n k += 1\n end\nend\n#puts o.length\n#puts e.length\nif o.length < e.length\n puts o[0] + 1\nelse\n puts e[0] + 1\nend\n"}, {"source_code": "gets.to_i\nnumbers = gets.split(\" \").map(&:to_i)\nodd_count = 0\neven_count = 0\nnumbers[0..2].each do |n|\n if n % 2 == 0\n even_count += 1\n else\n odd_count += 1\n end\nend\n\nremainder = 1\nremainder = 0 if even_count > odd_count\nnumbers.each_with_index do |n,i|\n puts i + 1 and break if n % 2 != remainder\nend\n"}, {"source_code": "gets\na = gets.split.map &:to_i\na.partition{|x| x.even? }[0].size == 1 ? a.map{|x| puts a.index(x) + 1 if x.even? } : a.map{|x| puts a.index(x) + 1 if x.odd? }\n"}, {"source_code": "n = gets\nl = gets.split\ni = l.index{ |x| (l[0].to_i.even? and x.to_i.odd?) or (not l[0].to_i.even? and x.to_i.even?) } + 1\nif l[i..-1].find{ |x| (l[0].to_i.even? and x.to_i.odd?) or (not l[0].to_i.even? and x.to_i.even?) }\n\tputs 1\nelse\n\tputs i\nend"}, {"source_code": "n, nums, odd, even, cur = gets, gets.chomp.split(' ').map { |item| item.to_i }, [], [], 1\nnums.each{|i|\n even << cur if i.even?\n odd << cur if i.odd?\n cur=cur+1\n}\nputs even[0] if even.size==1\nputs odd[0] if odd.size==1"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nm = a.take(3).map{|x| x % 2}.sort[1]\nputs a.find_index{|x| x % 2 != m} + 1\n"}, {"source_code": "n = gets.to_i\na = [nil] + gets.split.map(&:to_i)\ne = 0\no = 0\na[1..3].map{|x| x % 2 == 0 ? e += 1 : o += 1}\nm = 1\nm = 0 if e > o\nfor i in 1..a.size\n if a[i] % 2 != m\n puts i\n break\n end\nend\n"}, {"source_code": "gets\nnums = gets.chomp.split.map(&:to_i)\n\nres = nums.partition{ |e| e.even? }\nelem = res.min_by{ |e| e.size }\nputs nums.find_index(elem[0]) + 1"}, {"source_code": "gets\ns=gets.split.map{|s|s.to_i%2}*\"\"\np (s.count(?0)>1 ? s=~/1/ : s=~/0/)+1"}, {"source_code": "\nclass Euler\n n=gets.to_i;\n a=gets;\n a=a.split(\" \");\n a.each_index do |i|\n a[i]=(a[i].to_i)%2;\n end\n b=a.sort;\n if (b[0]==b[1])\n a.each_index do |i|\n if (a[i].to_i%2==1)\n puts (i+1);\n exit;\n end\n end\n else\n a.each_index do |i|\n if (a[i].to_i%2==0)\n puts (i+1);\n exit;\n end\n end\n end\nend\n"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\n\nputs (a.one?(&:odd?) ? a.index(&:odd?) : a.index(&:even?)) + 1\n"}, {"source_code": "gets\nnums = gets.split\neven = 0\nodd = 0\nfirst_odd = nil\nfirst_even = nil\nnums.each_with_index do |num,index|\n num_even = num.to_i % 2 == 0\n if(!num_even)\n first_odd = index + 1 if odd == 0\n odd += 1\n else\n first_even = index + 1 if even == 0\n even +=1\n end\n if(odd >= 2 && even == 1)\n puts first_even \n break\n end\n if(even >= 2 && odd == 1)\n puts first_odd \n break\n end\nend\n \n\n \n \n \n \n "}, {"source_code": "gets\nnums = gets.split(\" \")\n\neven = odd = even_pos = odd_pos = 0\n\nnums.each_with_index do |num, i|\n buff = num.to_i\n if buff.even?\n\teven += 1\n\teven_pos = i + 1\n elsif buff.odd?\n\todd += 1\n\todd_pos = i + 1\n end\n\n if even >= 2 && odd == 1\n\tputs odd_pos\n\texit\n elsif odd >= 2 && even == 1\n\tputs even_pos\n\texit\n end\nend"}, {"source_code": "gets\ns=gets.split.map{|s|s.to_i%2}*\"\"\np (s.count(?0)>1 ? s=~/1/ : s=~/0/)+1"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\ne = a.select {|x| x % 2 == 0 }\nputs a.each_with_index.select {|x| x[0] % 2 == (e.length == 1 ? 0 : 1)}.first.last + 1\n"}, {"source_code": "n = gets.to_i\nhs = gets.split(' ').map(&:to_i).map.with_index{|x,id| [x,id]}.group_by{|x,id| x%2}\nputs hs.min_by{|x,y| y.length}.last.last.last + 1 \n"}, {"source_code": "def func(n)\n if n % 2 == 0 then\n return true\n else\n return false\n end\nend\n\nn = gets.to_i\nch = []\nnech = []\n\nnums = gets.split.map{|i| i.to_i}\n\ni = 0\nwhile ch.size < 2 && nech.size < 2 do\n if func(nums[i]) then\n ch << nums[i]\n else\n nech << nums[i]\n end\n i += 1\nend\n\nif ch.size == 2 then\n i = 0\n while func(nums[i]) do\n i += 1\n end\nelse\n i = 0\n while !func(nums[i]) do\n i += 1\n end\nend\n\nputs i+1"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /)\nidx = 1\nfirste = 0\nlaste = 0\nfirsto = 0\nlasto = 0\na.each {|aa|\n\tif aa.to_i % 2 == 0\n\t\tlaste = idx\n\t\tfirste = idx if firste == 0\n\telse\n\t\tlasto = idx\n\t\tfirsto = idx if firsto == 0\n\tend\n\tidx += 1\n}\nif laste == firste\n\tputs laste\nelse\n\tputs lasto\nend\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(/ /)\nidx = 1\nfirste = 0\nlaste = 0\nfirsto = 0\nlasto = 0\na.each {|aa|\n\tif aa.to_i % 2 == 0\n\t\tlaste = idx\n\t\tfirste = idx if firste == 0\n\telse\n\t\tlasto = idx\n\t\tfirsto = idx if firsto == 0\n\tend\n\tidx += 1\n}\nif laste == firste\n\tputs laste\nelse\n\tputs lasto\nend\n"}, {"source_code": "gets\ns=gets.split.map{|s|s.to_i%2}*\"\"\np (s.count(?0)>1 ? s=~/1/ : s=~/0/)+1 \n"}, {"source_code": "n = gets.to_i\ntask = gets.strip.split.map &:to_i\n\nodd_even_indexes = {odd: [], even:[]}\n\ntask.each_index do |i|\n if task[i].odd?\n odd_even_indexes[:odd] << (i + 1)\n else\n odd_even_indexes[:even] << (i + 1)\n end\nend\n\nif odd_even_indexes[:odd].length == 1\n puts odd_even_indexes[:odd].first\nelse\n puts odd_even_indexes[:even].first\nend\n"}, {"source_code": "#!/usr/bin/ruby\ngets;a=gets.split.map(&:to_i);puts a.index(a.partition(&:odd?).min_by(&:size)[0])+1"}, {"source_code": "gets\ncnt = 0\na = gets().chomp.split(/[ \\n]/) \na.map{|x| cnt += 1 if x.to_i.odd?}\nputs a.index{|x| cnt == 1 ? x.to_i.odd? : x.to_i.even?} + 1\n"}, {"source_code": "gets\ns=gets.split.map{|s|s.to_i%2}*\"\"\np (s.count(?0)>1 ? s=~/1/ : s=~/0/)+1\n\n"}, {"source_code": "gets\ns=gets.split.map{|s|s.to_i%2}*\"\"\np (s.count(?0)>1 ? s=~/1/ : s=~/0/)+1"}, {"source_code": "def string_to_int(string, delim = \" \")\n result = []\n string = string.split(delim)\n for i in 0...string.length\n result[i] = string[i].to_i % 2\n end\n return result\nend\n\nn = gets.chomp.to_i\ntest = string_to_int(gets.chomp)\nif test.count(0) > test.count(1)\n\tputs test.index(1) + 1\nelse\n\tputs test.index(0) + 1\nend\n\n"}, {"source_code": "n=gets.to_i\na=gets.chomp.split(' ').map(&:to_i)\nc=[a[0]&1, a[1]&1, a[2]&1]\nch=(c.count(0)>c.count(1))?0:1\nputs a.index { |x| x%2 != ch } + 1"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = [a[0], a[1], a[2]].map {|x| x%2}\nc.count(0) > c.count(1) ? ch = 0 : ch = 1\nputs a.index { |x| x%2 != ch } + 1"}, {"source_code": "n = gets.to_i\narr = gets.split(\" \").map{|i| i.to_i}\nodd, even = [], []\nn.times{|i| odd << i if arr[i].odd?; even << i if arr[i].even?} \nputs (odd.count == 1 ? odd : even)[0]+1"}, {"source_code": "n = gets.to_i\nf = gets.split.map{|r| r.to_i}\n\ncounters = 0\nfor i in 0..n-1\n if f[i]%2 == 0\n par = i+1\n counters+=1\n else\n nep = i+1\n end\nend\n\nif counters > 1\n puts nep\nelse\n puts par\nend\n"}, {"source_code": "gets\na = gets.split.map{|i| i.to_i%2}*\"\"\np (a.count(?0)>1? a=~/1/ : a=~/0/)+1"}, {"source_code": "\ndef find(n,even: false, odd: false )\n if even \n n.each_with_index do |val,ind| \n if val.even? \n puts ind +1 \n break \n end\n end \n elsif odd\n n.each_with_index do |val,ind| \n if val.odd? \n puts ind+1 \n break\n end \n end \n end \nend \n\ntotal = gets.chop! \nn = gets.chop.split(\" \").map(&:to_i)\ncount = 0\neven=0 \nodd =0 \nn.each do |i| \n if count <3 \n if i.even? \n even+=1 \n count+=1 \n else \n odd+=1 \n count+=1 \n end \n end \nend \nif even>odd\n find(n,odd: true)\nelse \n find(n,even: true)\nend \n\n\n\n \n \n \n \n \n\n\n \n \n"}], "negative_code": [{"source_code": "gets\ncnt = 0\na = gets().chomp.split(/[ \\n]/)\na.map{|x| cnt += 1 if x.to_i.odd?}\nputs a.select{|x| cnt == 1 ? x.to_i.odd? : x.to_i.even?}\n"}, {"source_code": "n = gets.to_i\nf = gets.split.map{|r| r.to_i}\na = Array.new(n)\nb = Array.new(n)\n\nfor i in 0..n-1\n if f[i]%2 == 0\n a[i] = f[i]\n else\n b[i] = f[i]\n end\nend\n\nif a.compact.size < b.compact.size \n puts a.compact\nelse\n puts b.compact\nend\n"}, {"source_code": "gets\np gets.split.collect{|i| i.to_i}.index{|x| x%2!=0}+1"}, {"source_code": "gets\na = gets.split.map{|i| i.to_i%2}\np (a.count(0)>1?a.index{|x| x!=0}+1 : a.index{|x|x=0}+1)"}, {"source_code": "gets\na = gets.split.map{|i| i.to_i%2}\np (a.count(0)>1?a.index{|x| x!=0} : a.index{|x|x=0})+1"}, {"source_code": "gets\na = gets.split.map{|i| i.to_i%2}\np (a.count(?0)>1?a.index{|x| x!=0} : a.index{|x|x=0})+1"}, {"source_code": "\ndef find(n,even: false, odd: false )\n if even \n n.each_with_index do |val,ind| \n if val.even? \n return ind +1 \n end\n end \n elsif odd\n n.each_with_index do |val,ind| \n if val.odd? \n return ind+1 \n end \n end \n end \nend \n\nn = gets.chop.split(\" \").map(&:to_i)\ncount = 0\neven=0 \nodd =0 \nn.each do |i| \n if count <3 \n if i.even? \n even+=1 \n count+=1 \n else \n odd+=1 \n count+=1 \n end \n else \n if even>odd \n puts find(n,odd: true).to_i\n break \n else \n puts find(n,even: true).to_i\n break \n end \n end \nend \n\n\n \n \n \n \n \n\n\n \n \n"}, {"source_code": "\ndef find(n,even: false, odd: false )\n if even \n n.each_with_index do |val,ind| \n if val.even? \n puts ind +1 \n break \n end\n end \n elsif odd\n n.each_with_index do |val,ind| \n if val.odd? \n puts ind+1 \n break\n end \n end \n end \nend \n\nn = gets.chop.split(\" \").map(&:to_i)\ncount = 0\neven=0 \nodd =0 \nn.each do |i| \n if count <3 \n if i.even? \n even+=1 \n count+=1 \n else \n odd+=1 \n count+=1 \n end \n else \n if even>odd \n find(n,odd: true)\n break \n else \n find(n,even: true)\n break \n end \n end \nend \n\n\n \n \n \n \n \n\n\n \n \n"}, {"source_code": "# cook your code here\ndef find(n,even: false, odd: false )\n if even \n n.each_with_index do |val,ind| \n if val.even? \n return ind +1 \n end\n end \n elsif odd\n n.each_with_index do |val,ind| \n if val.odd? \n return ind+1 \n end \n end \n end \nend \n\nn = gets.chop.split(\" \").map(&:to_i)\ncount = 0\neven=0 \nodd =0 \nn.each do |i| \n if count <3 \n if i.even? \n even+=1 \n count+=1 \n else \n odd+=1 \n count+=1 \n end \n else \n if even>odd \n puts find(n,odd: true)\n break \n else \n puts find(n,even: true)\n break \n end \n end \nend \n\n"}, {"source_code": "\ndef find(n,even: false, odd: false )\n if even \n n.each_with_index do |val,ind| \n if val.even? \n puts ind +1 \n break \n end\n end \n elsif odd\n n.each_with_index do |val,ind| \n if val.odd? \n puts ind+1 \n break\n end \n end \n end \nend \n\ntotal = gets.chop! \nn = gets.chop.split(\" \").map(&:to_i)\ncount = 0\neven=0 \nodd =0 \nn.each do |i| \n if count <3 \n if i.even? \n even+=1 \n count+=1 \n else \n odd+=1 \n count+=1 \n end \n else \n if even>odd \n find(n,odd: true)\n break \n else \n find(n,even: true)\n break \n end \n end \nend \n\n\n \n \n \n \n \n\n\n \n \n"}, {"source_code": "n=gets.chomp.to_i\nnumber=gets.chomp.split.map{|i| i.to_i}\nmemo=Array.new(4)\nif n==3 \n puts 2\n exit(0)\nend\nmhash=Hash.new\nnum=0\n(n-1).times do |i|\n memo[i]= number[i+1]-number[i]\n if mhash.include?(memo[i])==false\n mhash[memo[i]]=true\n elsif\n num=memo[i]\n end\nend\n(n-1).times do |i|\n if memo[i]!=num\n puts i+2\n break\n end\nend\n"}, {"source_code": "gets.chomp\nnums = gets.chomp.split(/ /).map(&:to_i)\nodds = []\nevens = []\nans = 0\nputs ans"}, {"source_code": "n = gets.to_i\narr = gets.split.map { |e| e.to_i }\nc = 0\n3.times do |i|\n\tarr[i].even? ? c += 1 : c = c\n\ti += 1\nend\nx = 1\nif c == 2\n\tfor i in arr \n\t\tif i.even? \n\t\t\tx += 1\n\t\telse\n\t\t\tp x\n\t\tend\n\tend\nelse\n\tfor i in arr\n\t\tif i.even?\n\t\t\tp x\n\t\telse\n\t\t\tx += 1\n\t\tend\n\tend\nend"}, {"source_code": "def fn()\nn=gets.to_i\narr=gets.split.collect{|a| a.to_i }\nx=arr.pop\ny=arr.pop\nz=arr.pop\nif x%2==y%2 && x%2!= z%2\n return z\nelsif x%2==z%2 &&x%2 !=y%2\nreturn y\nelsif z%2==y%2 && z%2 !=x%2\nreturn x\nend\n\nreturn arr.select{|a| a%3 != x%2}.first\n\nend\n\n\n\np fn()\n"}, {"source_code": "n = gets\nl = gets.split\nputs l.index{ |x| (l[0].to_i.even? and x.to_i.odd?) or (not l[0].to_i.even? and x.to_i.even?) } + 1\n"}, {"source_code": "gets; input = gets.strip.split.map &:to_i\nk = input[0] % 2\n\ninput.length.times {|i| print i + 1 if k != input[i] % 2 }"}], "src_uid": "dd84c2c3c429501208649ffaf5d91cee"} {"source_code": "DBG = true\nn = gets.to_i\na = gets.split.map{|z| z.to_i}\nm = gets.to_i\nq = gets.split.map{|z| z.to_i}\nsum = a.inject(:+)\na.sort_by!{|z| -z}\nfor i in 0...m\n x = q[i]\n puts \"#{sum - a[x-1]}\"\nend\n", "positive_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nn = gets.to_i\narr = gets.chomp.split(\" \").map(&:to_i).sort\nsum = arr.inject(:+)\nm = gets.to_i\nqarr = gets.chomp.split(\" \").map(&:to_i)\n\nqarr.each do |q|\n\tputs sum-arr[-q]\nend"}], "negative_code": [], "src_uid": "c1608f6f71cac56690e31aa130c1990e"} {"source_code": "while !STDIN.eof? && (string1 = STDIN.readline.strip) && (string2 = STDIN.readline.strip)\n n = string1.split(\" \").first.to_i\n k = string1.split(\" \").last.to_i\n successes = string2.split(\" \").map { |s| s.strip == \"YES\" }\n name = \"a\"\n names = []\n successes.each_with_index do |success, index|\n if(index > 0)\n if(success)\n names.push(name.capitalize)\n name = name.next\n else\n names.push(names[index].capitalize)\n end\n else\n if(success)\n k.times do\n names.push(name.capitalize)\n name = name.next\n end\n else\n (k-1).times do\n names.push(name.capitalize)\n name = name.next\n end\n names.push(names[index].capitalize)\n end\n end\n end\n string = \"\"\n names.each { |name| string << name << \" \" }\n STDOUT << string.strip << \"\\n\"\nend\n", "positive_code": [{"source_code": "#1. Collect Input\nn = gets(\" \").to_i\nk = gets.chomp.to_i\n\narr = gets.chomp.split(\" \")\narr.map! { |s| s == \"YES\" ? true : false }\n\nnames = Array.new()\nc_name = 0\nstop_i = 0\nout = Array.new(n, \"\")\n\nnames =\n\"Joyce \nAbbey \nJenine \nArleen \nCammie \nLizbeth \nMario \nCortney \nShauna \nJenae \nErich \nFaviola \nLexie \nErlinda \nAlethia \nJacklyn \nYvone \nJudy \nCassy \nHilda \nNettie \nFlorencia \nPattie \nZula \nDebrah \nCeleste \nLeia \nLisette \nMargarito \nJosephina \nLanie \nJustin \nKacie \nDelores \nSherita \nCarolynn \nEdra \nHiedi \nNeville \nRhona \nZane \nDevona \nSigrid \nPhillis \nDelana \nNathanial \nRoni \nMelvina \nTerri \nKandra\".split(\"\\n\").each{ |s| s.strip! }\n\n\n#2. First Advance\n(0...arr.length).each do |i|\n if arr[i]\n (i...i+k).each do |j|\n out[j] = names[c_name]\n c_name += 1\n end\n stop_i = i\n break\n else\n out[i] = names[0]\n end\nend\n\n\n#3. Rest\nif c_name == 0\n (arr.length...n).each { |i| out[i] = names[0] }\nelse\n (stop_i+1...arr.length).each do |i|\n if arr[i]\n out[i+k-1] = names[c_name]\n c_name += 1\n else\n out[i+k-1] = out[i]\n end\n end\nend\n\nout.each do |e|\n print e\n print \" \"\nend"}, {"source_code": "n, k=gets.split.map &:to_i\ns=gets.split\nc=?A\nres=(1..n).map{c.next!.capitalize}\ns.each_with_index{|e, i|\n res[i+k-1]=res[i] if e==\"NO\"\n}\nputs res*' '"}, {"source_code": "names = ('A'..'Z').to_a + ('Aa'..'Az').to_a\nn, k = gets.split.map(&:to_i)\nbools = gets.split(' ').map{|x| x == 'YES'}\nans = Array.new(n)\nans[0, k - 1] = names[0, k - 1]\nnn = k - 1\n(n - k + 1).times do |i|\n if bools[i]\n ans[i + k - 1] = names[nn]\n nn += 1\n else\n ans[i + k - 1] = ans[i]\n end\nend\nputs ans.join(' ')\n"}, {"source_code": "n, k=gets.split.map &:to_i\ns=gets.split\nc=?A\nres=(1..n).map{c.next!.capitalize}\ns.each_with_index{|e, i|\n res[i+k-1]=res[i] if e==\"NO\"\n}\nputs res*' '\n"}], "negative_code": [{"source_code": "names = ('A'..'Z').to_a + ('AA'..'AZ').to_a\nnn = 0\nn, k = gets.split.map(&:to_i)\nbools = gets.split(' ').map{|x| x == 'YES'}\nans = Array.new(n)\nif bools[0]\n ans[0, k] = names[nn, k]\n nn += k\nelse\n ans[0, k - 1] = names[nn, k - 1]\n ans[0 + k - 1] = ans[0]\n nn += k - 1\nend\n(n - k).times do |i|\n if bools[i + 1]\n ans[i + k] = names[nn]\n nn += 1\n else\n ans[i + k] = ans[i + 1]\n end\nend\nputs ans.join(' ')\n"}, {"source_code": "n, k=gets.split.map &:to_i\ns=gets.split\nif !s.include?(\"YES\")\n puts \"A \"*n\nelse \n c=?A\n res=(1..n).map{c.next!.capitalize}\n s.reverse.each_with_index{|e, i|\n res[i]=res[i+k-1] if e==\"NO\"\n }\n puts res.reverse*' '\nend\n"}, {"source_code": "while !STDIN.eof? && (string1 = STDIN.readline.strip) && (string2 = STDIN.readline.strip)\n n = string1.split(\" \").first.to_i\n k = string1.split(\" \").last.to_i\n successes = string2.split(\" \").map { |s| s.strip == \"YES\" }\n name = \"a\"\n names = []\n successes.each_with_index do |success, index|\n if(index > 0)\n if(success)\n names.push(name)\n name = name.next\n else\n names.push(names[index])\n end\n else\n if(success)\n k.times do\n names.push(name)\n name = name.next\n end\n else\n (k-1).times do\n names.push(name)\n name = name.next\n end\n names.push(names[index])\n end\n end\n end\n\n p names\nend\n"}, {"source_code": "while !STDIN.eof? && (string1 = STDIN.readline.strip) && (string2 = STDIN.readline.strip)\n n = string1.split(\" \").first.to_i\n k = string1.split(\" \").last.to_i\n successes = string2.split(\" \").map { |s| s.strip == \"YES\" }\n name = \"a\"\n names = []\n successes.each_with_index do |success, index|\n if(index > 0)\n if(success)\n names.push(name)\n name = name.next\n else\n names.push(names[index])\n end\n else\n if(success)\n k.times do\n names.push(name)\n name = name.next\n end\n else\n (k-1).times do\n names.push(name)\n name = name.next\n end\n names.push(names[index])\n end\n end\n end\n string = \"\"\n names.each { |name| string << name << \" \" }\n STDOUT << string.strip << \"\\n\"\nend\n"}], "src_uid": "046d6f213fe2d565bfa5ce537346da4f"} {"source_code": "main = -> {\r\n m, s = ints\r\n b = ints\r\n\r\n return \"NO\" if b.uniq.size != m\r\n\r\n b_max = b.max\r\n\r\n exist = [false] * (b_max + 1)\r\n b.each do |bi|\r\n exist[bi] = true\r\n end\r\n\r\n acc = 0\r\n (1..b_max).each do |i|\r\n acc += i unless exist[i]\r\n end\r\n\r\n (b_max+1..30000).each do |i|\r\n return \"YES\" if acc + (b_max + 1...i).sum == s\r\n end\r\n\r\n return \"NO\"\r\n}\r\n\r\ndef int; gets.to_i end\r\ndef ints; gets.split.map(&:to_i) end\r\n\r\nt = gets.to_i\r\nputs t.times.map{ main.call }.join(\"\\n\")", "positive_code": [{"source_code": "gets.to_i.times do\n m, s=gets.chomp.split(' ').map(&:to_i)\n arr=gets.chomp.split(' ').map(&:to_i)\n n= Math.sqrt((arr.sum+s)*2).floor\n mx=arr.max\n if arr.uniq.length==m && n*(n+1)==(arr.sum+s)*2 && n>=mx\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}], "negative_code": [{"source_code": "gets.to_i.times do\n m, s=gets.chomp.split(' ').map(&:to_i)\n arr=gets.chomp.split(' ').map(&:to_i)\n n= Math.sqrt((arr.sum+s)*2).floor\n if arr.uniq.length==m and n*(n+1)==(arr.sum+s)*2\n puts \"YES\"\n else\n puts \"NO\"\n end\nend"}], "src_uid": "447c17cba953d6e2da50c242ac431ab4"} {"source_code": "gets.to_i.times do\n n=gets.to_i\n h=Hash.new (0)\n (n*2+1).times do\n gets.each_char do |c|\n h[c]=h[c]+1\n end\n end\n h.each do |x,y|\n if y%2!=0 && x>='a' and x<='z'\n puts x\n end\n end\nend", "positive_code": [{"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n = gets.chomp.to_i\r\n list = {}\r\n ('a'..'z').each do |i|\r\n list.store(i, 0)\r\n end\r\n possible_answers = []\r\n \r\n ((2*n)+1).times do\r\n x = gets.chomp\r\n x.each_char do |i|\r\n list[i] += 1;\r\n end\r\n end\r\n \r\n list.keys.each do |key|\r\n if list[key]%2 == 1\r\n puts key\r\n break\r\n end\r\n end\r\nend\r\n\r\n\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n freq = [0] * 26\r\n (2 * n + 1).times do |i|\r\n gets.chomp.bytes.each do |c|\r\n freq[c - 97] += 1\r\n end\r\n end\r\n freq.each.with_index do |f, i|\r\n puts (97 + i).chr if f % 2 == 1\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n freq = Array.new(26) { [0] * (2 * n + 1) }\r\n (2 * n + 1).times do |i|\r\n gets.chomp.bytes.each do |c|\r\n freq[c - 97][i] += 1\r\n end\r\n end\r\n freq.each.with_index do |f, i|\r\n left, right = 0, 0\r\n f.sort.reverse.each do |x|\r\n if left < right\r\n left += x\r\n else\r\n right += x\r\n end\r\n end\r\n if left != right\r\n puts (97 + i).chr\r\n break\r\n end\r\n end\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n freq = Array.new(26) { [0] * (2 * n + 1) }\r\n (2 * n + 1).times do |i|\r\n gets.chomp.bytes.each do |c|\r\n freq[c - 97][i] += 1\r\n end\r\n end\r\n freq.each.with_index do |f, i|\r\n left, right = 0, 0\r\n f.sort.each do |x|\r\n if left < right\r\n left += x\r\n else\r\n right += x\r\n end\r\n end\r\n if left != right\r\n puts (97 + i).chr\r\n break\r\n end\r\n end\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n freq = Array.new(26) { [0] * (2 * n + 1) }\r\n (2 * n + 1).times do |i|\r\n gets.chomp.bytes.each do |c|\r\n freq[c - 97][i] += 1\r\n end\r\n end\r\n freq.each.with_index do |f, i|\r\n sum = 0\r\n f.sort.each do |x|\r\n if (sum + x).abs < (sum - x).abs\r\n sum += x\r\n else\r\n sum -= x\r\n end\r\n end\r\n if sum != 0\r\n puts (97 + i).chr\r\n break\r\n end\r\n end\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n freq = Array.new(26) { [0] * (2 * n + 1) }\r\n (2 * n + 1).times do |i|\r\n gets.chomp.bytes.each do |c|\r\n freq[c - 97][i] += 1\r\n end\r\n end\r\n freq.each.with_index do |f, i|\r\n sum = 0\r\n f.sort.reverse.each do |x|\r\n if (sum + x).abs < (sum - x).abs\r\n sum += x\r\n else\r\n sum -= x\r\n end\r\n end\r\n if sum != 0\r\n puts (97 + i).chr\r\n break\r\n end\r\n end\r\nend\r\n"}, {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n = gets.chomp.to_i\r\n list = {}\r\n ('a'..'z').each do |i|\r\n list.store(i, 0)\r\n end\r\n possible_answers = []\r\n cnt = 0\r\n ((2*n)+1).times do\r\n x = gets.chomp\r\n cnt+=1\r\n if cnt != 2*n+1\r\n if x.length == 1\r\n possible_answers << x\r\n end\r\n end\r\n temp_list = {}\r\n x.each_char do |i|\r\n temp_list[i] = 1;\r\n end\r\n temp_list.keys.each do |key|\r\n list[key]+=1\r\n end\r\n \r\n \r\n end\r\n \r\n possible_answers.each do |x|\r\n if list[x]%2 == 1\r\n puts x\r\n break\r\n end\r\n end\r\nend\r\n\r\n\r\n"}, {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n = gets.chomp.to_i\r\n list = {}\r\n ('a'..'z').each do |i|\r\n list.store(i, 0)\r\n end\r\n possible_answers = []\r\n ((2*n)+1).times do\r\n x = gets.chomp\r\n if x.length == 1\r\n possible_answers << x\r\n end\r\n temp_list = {}\r\n x.each_char do |i|\r\n temp_list[i] = 1;\r\n end\r\n temp_list.keys.each do |key|\r\n list[key]+=1\r\n end\r\n \r\n end\r\n \r\n possible_answers.each do |x|\r\n if list[x]%2 == 1\r\n puts x\r\n break\r\n end\r\n end\r\nend\r\n\r\n\r\n"}, {"source_code": "t = gets.chomp.to_i\r\nt.times do\r\n n = gets.chomp.to_i\r\n list = {}\r\n ('a'..'z').each do |i|\r\n list.store(i, 0)\r\n end\r\n possible_answers = []\r\n ((2*n)+1).times do\r\n x = gets.chomp\r\n if x.length == 1\r\n possible_answers << x\r\n end\r\n temp_list = {}\r\n x.each_char do |i|\r\n temp_list[i] = 1;\r\n end\r\n temp_list.keys.each do |key|\r\n list[key]+=1\r\n end\r\n \r\n end\r\n \r\n possible_answers.each do |x|\r\n if list[x]%2 == 1\r\n p x\r\n break\r\n end\r\n end\r\nend\r\n\r\n\r\n"}, {"source_code": "gets.to_i.times do\n n=gets.to_i\n h=Hash.new (0)\n (n*2+1).times do\n gets.each_char do |c|\n h[c]=h[c]+1\n end\n end\n h.each do |x,y|\n if y%2!=0\n print x\n end\n end\nend"}, {"source_code": "gets.to_i.times do\n n=gets.to_i\n h=Hash.new (0)\n (n*2+1).times do\n gets.each_char do |c|\n h[c]=h[c]+1\n end\n end\n h.each do |x,y|\n if y%2!=0\n puts x\n end\n end\nend"}], "src_uid": "b663dadb1033d435775bf000c2041d43"} {"source_code": "def compress(s)\n a = Array.new(s.size)\n last = nil\n cnt = 0\n s.split('').each do |c|\n if c == last\n cnt += 1\n else\n a.push [last, cnt] if last\n last = c\n cnt = 1\n end\n end\n a.push([last, cnt]).compact\nend\n\ndef good(a, b)\n if a.size != b.size\n false\n else\n !(a.map.with_index do |e, i|\n e[0] == b[i][0] && e[1] <= b[i][1]\n end.include? false)\n end\nend\n\nn = gets.strip.to_i\nn.times do\n a = gets.strip\n b = gets.strip\n puts good(compress(a), compress(b)) ? 'YES' : 'NO'\nend\n", "positive_code": [{"source_code": "n = gets.to_i\nn.times do\n s = gets.chomp\n t = gets.chomp\n flg = true\n i,j=0,0\n sl,tl = s.length,t.length\n while i < sl && j < tl\n ci,cj = 0,0\n #p [i,j]\n while i < sl-1 && s[i] == s[i+1]\n i += 1\n ci += 1\n end\n while j < tl-1 && t[j] == t[j+1]\n j += 1\n cj += 1\n end\n if s[i] != t[j] || ci > cj\n flg = false\n break\n end\n i+=1\n j+=1\n end\n flg = false if i != sl || j != tl\n puts flg ? \"YES\" : \"NO\"\nend"}, {"source_code": "def compress(s)\n a = []\n last = nil\n cnt = 0\n s.split('').each do |c|\n if c == last\n cnt += 1\n else\n a.push [last, cnt] if last\n last = c\n cnt = 1\n end\n end\n a.push [last, cnt]\nend\n\ndef good(a, b)\n if a.size != b.size\n false\n else\n !(a.map.with_index do |e, i|\n e[0] == b[i][0] && e[1] <= b[i][1]\n end.include? false)\n end\nend\n\nn = gets.strip.to_i\nn.times do\n a = gets.strip\n b = gets.strip\n puts good(compress(a), compress(b)) ? 'YES' : 'NO'\nend\n"}, {"source_code": "def compress(s)\n a = []\n last = nil\n cnt = 0\n s.split('').each do |c|\n if c == last\n cnt += 1\n else\n a << [last, cnt] if last\n last = c\n cnt = 1\n end\n end\n a << [last, cnt]\nend\n\ndef good(a, b)\n if a.size != b.size\n false\n else\n !(a.map.with_index do |e, i|\n e[0] == b[i][0] && e[1] <= b[i][1]\n end.include? false)\n end\nend\n\nn = gets.strip.to_i\nn.times do\n a = gets.strip\n b = gets.strip\n puts good(compress(a), compress(b)) ? 'YES' : 'NO'\nend\n"}, {"source_code": "def compress(s)\n a = []\n last = nil\n cnt = 0\n index = 0\n s.split('').each do |c|\n if c == last\n cnt += 1\n else\n a << [last, cnt] if last\n last = c\n cnt = 1\n end\n end\n a << [last, cnt]\n a.compact\nend\n\ndef good(a, b)\n if a.size != b.size\n false\n else\n !(a.map.with_index do |e, i|\n e[0] == b[i][0] && e[1] <= b[i][1]\n end.include? false)\n end\nend\n\nn = gets.strip.to_i\nn.times do\n a = gets.strip\n b = gets.strip\n puts good(compress(a), compress(b)) ? 'YES' : 'NO'\nend\n"}, {"source_code": "def compress(s)\n a = []\n last = nil\n cnt = 0\n index = 0\n s.split('').each do |c|\n if c == last\n cnt += 1\n else\n a << [last, cnt] if last\n last = c\n cnt = 1\n end\n end\n a << [last, cnt]\n a.compact\nend\n\ndef good(a, b)\n if a.size != b.size\n false\n else\n (0...(a.size)).each do |i|\n if !(a[i][0] == b[i][0] && a[i][1] <= b[i][1])\n return false\n end\n end\n true\n end\nend\n\nn = gets.chomp.to_i\nn.times do\n a = gets.chomp\n b = gets.chomp\n puts good(compress(a), compress(b)) ? 'YES' : 'NO'\nend\n"}, {"source_code": "def compress(s)\n a = []\n last = nil\n cnt = 0\n index = 0\n s.split('').each do |c|\n if c == last\n cnt += 1\n else\n a << [last, cnt] if last\n last = c\n cnt = 1\n end\n end\n a << [last, cnt]\n a.compact\nend\n\ndef good(a, b)\n if a.size != b.size\n false\n else\n (0...(a.size)).each do |i|\n if !(a[i][0] == b[i][0] && a[i][1] <= b[i][1])\n return false\n end\n end\n true\n end\nend\n\nn = gets.strip.to_i\nn.times do\n a = gets.strip\n b = gets.strip\n puts good(compress(a), compress(b)) ? 'YES' : 'NO'\nend\n"}, {"source_code": "def compress(s)\n a = []\n last = nil\n cnt = 0\n index = 0\n s.split('').each do |c|\n if c == last\n cnt += 1\n else\n a << [last, cnt] if last\n last = c\n cnt = 1\n end\n end\n a << [last, cnt]\n a.compact\nend\n\ndef good(a, b)\n if a.size != b.size\n false\n else\n a.each.with_index do |e, i|\n if !(e[0] == b[i][0] && e[1] <= b[i][1])\n return false\n end\n end\n true\n end\nend\n\nn = gets.strip.to_i\nn.times do\n a = gets.strip\n b = gets.strip\n puts good(compress(a), compress(b)) ? 'YES' : 'NO'\nend\n"}], "negative_code": [{"source_code": "def compress s\n a = []\n last = nil\n cnt = 0\n s.split('').each do |c|\n if c == last\n cnt += 1\n else\n if last\n a << [c, cnt]\n end\n last = c\n cnt = 1\n end\n end\n a << [last, cnt]\nend\n\ndef good a, b\n if a.size != b.size\n false\n else\n !(a.map.with_index do |e, i|\n e[0] == b[i][0] && e[1] <= b[i][1]\n end.include? false)\n end\nend\n\nn = gets.strip.to_i\nn.times do\n a, b = gets.strip, gets.strip\n puts good(compress(a), compress(b)) ? \"YES\" : \"NO\"\nend"}, {"source_code": "def compress(s)\n a = []\n last = nil\n cnt = 0\n s.split('').each do |c|\n if c == last\n cnt += 1\n else\n a << [c, cnt] if last\n last = c\n cnt = 1\n end\n end\n a << [last, cnt]\nend\n\ndef good(a, b)\n if a.size != b.size\n false\n else\n (0...(a.size)).each do |i|\n if !((a[i][0] == b[i][0]) && (a[i][1] <= b[i][1]))\n return false\n end\n end\n true\n end\nend\n\nn = gets.strip.to_i\nn.times do\n a = gets.strip\n b = gets.strip\n puts good(compress(a), compress(b)) ? 'YES' : 'NO'\nend\n"}, {"source_code": "def compress(s)\n a = []\n last = nil\n cnt = 0\n s.split('').each do |c|\n if c == last\n cnt += 1\n else\n a << [c, cnt] if last\n last = c\n cnt = 1\n end\n end\n a << [last, cnt]\nend\n\ndef good(a, b)\n if a.size != b.size\n false\n else\n a.each.with_index do |e, i|\n if !((e[0] == b[i][0]) && (e[1] <= b[i][1]))\n return false\n end\n end\n true\n end\nend\n\nn = gets.strip.to_i\nn.times do\n a = gets.strip\n b = gets.strip\n puts good(compress(a), compress(b)) ? 'YES' : 'NO'\nend\n"}], "src_uid": "6709c8078cd29e69cf1be285071b2527"} {"source_code": "n = gets.to_i\nans = 0\np = 0\nn.times do\n a, b = gets.split.map(&:to_i)\n p += - a + b\n ans = [ans, p].max\nend\nputs ans\n", "positive_code": [{"source_code": "n = gets.to_i\nm, sv = 0, 0\nn.times do\n a, b = gets.split(' ').map{|_|_.to_i}\n sv += b-a\n m = sv if sv>m\nend\nputs m"}, {"source_code": "n = max_n = 0\ngets.to_i.times do\n x,y = gets.split.map &:to_i\n n = n-x+y\n max_n = n if n > max_n\nend\np max_n"}, {"source_code": "stations = Array.new\ntram = 0\ngets.to_i.times do\n station = gets.split.map(&:to_i)\n tram += station[1] - station[0]\n stations.push(tram)\nend\nputs stations.max"}, {"source_code": "\n@stopCount = STDIN.gets.to_i\n@minSlot = 0;\n@currentSlot = 0;\nwhile (@stopCount > 0)\n stopInfo = STDIN.gets\n passengers_info = stopInfo.split(\" \")\n @currentSlot = @currentSlot - passengers_info[0].to_i + passengers_info[1].to_i\n if(@minSlot < @currentSlot)\n @minSlot = @currentSlot\n end\n @stopCount -= 1\nend\nputs @minSlot"}, {"source_code": "n = gets.to_i\n\nmax = 0\ntram = 0\nn.times do |i|\n s = gets.split.map{|i| i.to_i}\n tram -= s[0]\n tram += s[1]\n if tram > max then\n max = tram\n end\nend\n\nputs max"}, {"source_code": "total=0\nmax=0\nk=gets.to_i\nk.times{|x|a,b=gets.split.map(&:to_i)\ntotal=total+b-a\nmax=total if total>max}\nprint max"}, {"source_code": "n=m=0;gets(p).scan(/(.+) (.+)/){|i,j|m=n if m passengers_count ? max_passengers_count : passengers_count\nend\n\nputs max_passengers_count"}, {"source_code": "n = gets.to_i\n\nmax = 0\ncol = 0\nwhile n > 0 do\n a, b = gets.split.map &:to_i\n col += b - a\n max = col if col > max\n n -= 1\nend\n\nputs max"}, {"source_code": "def main\n number_of_stops = gets.to_i\n\n max_people_on_tram = 0\n current_people_on_tram = 0\n\n until number_of_stops.zero?\n leaving, entering = gets.split.map(&:to_i)\n\n current_people_on_tram = current_people_on_tram - leaving + entering\n\n if current_people_on_tram > max_people_on_tram\n max_people_on_tram = current_people_on_tram\n end\n\n number_of_stops -= 1\n end\n\n puts max_people_on_tram\n\nend\n\nmain if __FILE__ == $PROGRAM_NAME\n"}, {"source_code": "n=0;gets;p$<.map{|s|n-=eval s.tr\" \",?-}.max\n"}, {"source_code": "n=0;gets;p$<.map{|s|n-=eval s.tr\" \",?-}.max"}, {"source_code": "def get_min_capacity(passangers)\n temp_p = passangers.shift.sum\n # removing the last stop which is not important because all passangers exit the tram\n passangers.pop\n min = temp_p\n passangers.each do |a,b|\n temp_p = (temp_p-a) + b\n min = temp_p if temp_p > min\n end\n min\nend\n\ns = gets.to_i\na_p = []\n(1..s).each do\n a = gets.split(/\\s/).map(&:to_i)\n a_p << a\nend\nputs get_min_capacity(a_p)"}, {"source_code": "ret = 0\nrunning = 0\ngets.to_i.times do\n chu, jin = gets.split.map &:to_i\n running += jin - chu;\n ret = [ret, running].max\nend\nputs ret"}, {"source_code": "def tram ()\n n = gets.chomp\n capacity = 0\n count = 0\n for i in 0...n.to_i\n stops = gets.chomp\n stop = stops.split(\" \")\n count = count + stop[1].to_i - (stop[0].to_i)\n if count > capacity\n capacity = count\n end\n end\n puts capacity\nend\n\ntram"}, {"source_code": "def func()\n a=STDIN.readchar;\n b=0;\n while (a!=\" \"&& a!=\"\\n\")\n b=b*10+a.to_i;\n a=STDIN.readchar;\nend\nreturn b;\nend\nclass Euler\n n=func;\n kol=0;\n max=0;\n (1..n).each do |i|\n a=func;\n b=func;\n kol-=a;\n kol+=b;\n if (kol>max) \n max=kol;\n end;\n end\n puts max;\n end\n"}, {"source_code": "res=0; puts gets.to_i.times.map{res+=-gets(' ').to_i+gets.to_i}.max"}, {"source_code": "n=m=0;gets(p).scan(/(.+) (.+)/){|i,j|m=n if m rmax then\n rmax = tmax\n end\nend\n\nputs rmax\n"}, {"source_code": "n = gets.to_i\nanswer = 0\nmax = 0\n\nwhile(n>0)\n a, b = gets.split.map(&:to_i)\n answer -= a\n answer += b\n if answer > max\n max = answer\n end\n \n n-=1\nend\nputs max \n"}, {"source_code": "def max(a, b)\n return a>b ? a : b\nend\nn = gets.to_i\nans = 0\ntk = 0\nwhile (n > 0) \n a,b = gets.split(' ').map{|s| s.to_i}\n tk = tk - a + b\n ans = max(ans, tk)\n n -= 1\nend\nputs ans"}, {"source_code": "n, k, s = gets.to_i, 0, 0\nn.times do\n a, b = gets.split.map(&:to_i)\n s += -a + b\n k = [s, k].max\nend\nputs k"}, {"source_code": "max = 0\ncount = 0\nn = gets.chomp.to_i\na = []\nb = []\nn.times.each do |_|\n a_n, b_n = gets.chomp.split(/ /).map(&:to_i)\n a << a_n\n b << b_n\n count += b_n - a_n\n max = count if count > max\nend\nputs max\n"}, {"source_code": "a=[0]\ngets.to_i.times{\n i,j=gets.split.map &:to_i\n a< xounter\nend\n\nputs xounter"}, {"source_code": "n = gets.strip.to_i\ncapacity = 0\ncurrent_passenger = 0\nn.times do \n a, b = gets.strip.split(\" \").map(&:to_i)\n current_passenger = current_passenger - a + b\n capacity = [capacity, current_passenger].max \nend\nputs capacity"}, {"source_code": "gets; input = STDIN.read.split(\"\\n\").map {|i| i.split.map! &:to_i }\n\nmax, up = 0, 0\n\ninput.each do |i|\n up -= i[0]\n up += i[1]\n max = up if max < up\nend\n\nprint max"}, {"source_code": "n=0;gets;p$<.map{|s|n-=eval s.tr\" \",?-}.max\n"}, {"source_code": "n=0;gets;p$<.map{|s|n-=eval s.tr\" \",?-}.max\n"}, {"source_code": "capacity, max = 0, 0\ngets.to_i.times do\n inp = gets.split.map &:to_i\n capacity += inp[1] - inp[0]\n max = capacity if capacity > max\nend\nputs max"}, {"source_code": "n = gets.chomp.to_i\nmaxCap = 0\ncurrentCap = 0\n\nfor i in 0...n\n\tinput = gets.chomp.split(' ').map {|item| item.to_i}\n\n\tcurrentCap = currentCap - input[0] + input[1]\n\tmaxCap = currentCap if maxCap < currentCap\nend\n\nputs maxCap"}, {"source_code": "ret = 0\ncur = 0\nfor i in 1..gets.to_i do\n a,b = gets.split.map(&:to_i)\n cur += b-a\n if (cur > ret) then ret = cur end\nend\nputs ret"}, {"source_code": "n=0;gets;p$<.map{|s|n-=eval s.tr\" \",?-}.max\n"}, {"source_code": "n = gets.strip.to_i\nin_count = max_capacity = 0\nn.times do\n a, b = gets.strip.split.map(&:to_i)\n in_count += (b - a)\n max_capacity = [max_capacity, in_count].max\nend\nputs max_capacity\n"}, {"source_code": "t = $stdin.readline.split\nn = t[0].to_i\n\nm = 0\ns = 0\nn.times do\n t = $stdin.readline.split\n a, b = t.map(&:to_i)\n s += (b-a)\n m = s if s>m\nend\n\nputs m"}, {"source_code": "a=gets.chomp.to_i\nans=0\ntemp=0\na.times do\nk=gets.chomp.split(\" \")\ntemp=temp+k[1].to_i-k[0].to_i\nif temp> ans\nans = temp\nend\nend\n\nputs \"#{ans}\""}, {"source_code": "n=0\nans=0\ngets.to_i.times{\n\ta,b=gets.split.map{|e| e.to_i}\n\tn=n-a+b\n\tans=[ans,n].max\n}\nputs ans"}, {"source_code": "n=0;gets;p$<.map{|s|n-=eval s.tr\" \",?-}.max"}, {"source_code": "n=gets.to_i\n\nans=bus=0\nn.times{\n\ta,b=gets.split.map(&:to_i)\n\t\n\tbus=bus-a+b\n\tans=[bus, ans].max\n}\n\np ans\n"}, {"source_code": "class C116A\n q = 0\n m = 0\n gets.to_i.times{\n a, b = gets.split.map &:to_i\n q -= a\n q += b\n q > m && m = q\n }\n puts m\nend"}, {"source_code": "n = gets.to_i\n \ns = max = 0\n(0..n-1).each{|i|\n a,b=gets.split.map(&:to_i)\n s = s - a + b \n max < s ? max = s : max = max\n}\np max"}, {"source_code": "n=gets.to_i\nans = 0\nt = 0\nn.times do\n a,b = gets.split.map(&:to_i)\n t += b - a\n ans = t if t > ans\nend\n\nputs ans\n"}, {"source_code": "stop_count = gets.chomp.to_i\naccum = 0\nmax = 0\nfor i in 1..stop_count\n stop = gets.chomp.split ' '\n\n accum += stop[1].to_i - stop[0].to_i\n\n if accum > max\n max = accum\n end\nend\n\nputs max\n"}, {"source_code": "q=[0];gets.to_i.times{a,b=gets.split.map &:to_i;q+=[q[-1]-a+b]};p q.max\n"}, {"source_code": "stops = gets.chomp.to_i\npassengers = []\ni = 0\nwhile i < stops\n\tn = gets.chomp\n\tpassengers << n.split(\" \")\n\ti += 1\nend\n\narr = []\ncount = 0\npassengers.each do |pair|\n\tif passengers[0] == pair\n\t\tcount += pair[1].to_i \n\t\tarr << count\n\telse\n\t\tcount -= pair[0].to_i\n\t\tcount += pair[1].to_i\n\t\tarr << count\n\tend\nend\n\nprint arr.max "}, {"source_code": "s=0\nres=[]\ngets.to_i.times{\n a,b=gets.split.map(&:to_i)\n res< max_cnt\n}\n\nputs max_cnt\n"}, {"source_code": "n = gets.chomp.to_i\nans = 0\npeople = 0\n\nn.times do |i|\n a, b = gets.chomp.split(\" \").map(&:to_i)\n people = people + b - a\n ans = [ans,people].max\nend\n\nputs ans \n"}, {"source_code": "caps = 0\npass = 0\ngets.to_i.times {\n a, b = gets.split.map(&:to_i)\n pass = pass - a + b\n caps = [caps, pass].max\n}\nputs caps\n"}, {"source_code": "s = t = 0\ngets.to_i.times do\n x, y = gets.split.map &:to_i\n s += y - x\n t = s if s > t\nend\nputs t\n"}, {"source_code": "n=0;gets;p$<.map{|s|n-=eval s.tr\" \",?-}.max"}, {"source_code": "n = gets.chomp.to_i\narray = []\npassenger = 0\nans = 0\nn.times do\n\tinput = gets.chomp.split.map{|x| array.push x.to_i}\nend\ni = 0\nwhile i < array.length\n\tpassenger = passenger - array[i] + array[i+1]\n\tif passenger >= ans\n\t\tans = passenger\n\tend\n\ti += 2\nend\nputs ans\n"}, {"source_code": "num = gets.chomp.to_i\nentra = []\nsale = []\na1 = 0\na2 = 0\ni = 0\nwhile (i < num)\n\tline = gets.chomp.split\n\tsale.push line[0].to_i\n\tentra.push line[1].to_i\n\ti = i + 1\nend\nj = 0\nwhile (j < num)\n\ta1 = a1 + (entra[j] - sale[j])\n\tif (a1 > a2)\n\t\ta2 = a1\n\tend\n\tj = j + 1\nend\nputs a2.to_s"}, {"source_code": "max, passengers = 0, 0\ngets.to_i.times do\n tramio = gets.split.map(&:to_i)\n passengers += tramio[1] - tramio[0]\n max = passengers > max ? passengers : max\nend\nputs max"}, {"source_code": "n = gets.chomp.to_i\n\nres = 0\nact = 0\n\nfor i in 1..n\n\tinput = gets.chomp.split(\" \")\n\ta = input[0].to_i\n\tb = input[1].to_i\n\n\tact -= a\n\tact += b\n\n\tif act>res\n\t\tres = act\n\tend\nend\n\nputs res\n"}, {"source_code": "n = gets.to_i\nc = 0\nmax = 0\nfor i in 1..n do\n\ta,b = gets.split.map(&:to_i)\n\tc = c - a + b\n\tif c > max\n\t\tmax = c\n\tend\nend\n\nputs max\n"}], "negative_code": [{"source_code": "n = gets.to_i\na = []\nb = []\nfor i in 1..n do\n\tb = gets.split.map(&:to_i)\n\ta.push(b)\nend\n\nj = 1\nc = a[0][1]\nmax = 0\nwhile j < (n-1) do\n\tc = c - a[j][0] + a[j][1]\n\tj = j+1\n\tif c > max\n\t\tmax = c\n\tend\nend\n\nputs max\n\n\n"}, {"source_code": "stops = gets.to_i\nmax = 0\npassengers = 0\n0.upto(stops - 1) do\n stop = gets.split\n passengers = passengers - stop[0].to_i\n passengers = passengers + stop[1].to_i\n max = passengers if passengers > max\nend\n\nputs passengers\n"}, {"source_code": "n=m=0;gets(p).scan(/.+( ).+/){m=n if m min\n end\n min\nend\n\ns = gets.to_i\na_p = []\n(1..s).each do\n a = gets.split(/\\s/).map(&:to_i)\n a_p << a\nend\nputs get_min_capacity(a_p)"}, {"source_code": "def get_min_capacity(passangers)\n min = passangers.shift.sum\n # removing the last stop which is not important because all passangers exit the tram\n passangers.pop\n\n passangers.each do |a,b|\n temp_p = (min-a) + b\n min = temp_p if temp_p > min\n end\n min\nend\n\ns = gets.to_i\na_p = []\n(1..s).each do\n a = gets.split(/\\s/).map(&:to_i)\n a_p << a\nend\nputs get_min_capacity(a_p)"}, {"source_code": "def get_min_capacity(passangers)\n temp_p = passangers.shift.sum\n # removing the last stop which is not important because all passangers exit the tram\n passangers.pop\n min = 1\n passangers.each do |a,b|\n temp_p = (temp_p-a) + b\n min = temp_p if temp_p > min\n end\n min\nend\n\ns = gets.to_i\na_p = []\n(1..s).each do\n a = gets.split(/\\s/).map(&:to_i)\n a_p << a\nend\nputs get_min_capacity(a_p)"}, {"source_code": "def tram ()\n n = gets.chomp\n capacity = 0\n count = 0\n for i in 0...n.to_i\n stops = gets.chomp\n count = count + stops[2].to_i - stops[0].to_i\n if count > capacity\n capacity = count\n end\n end\n puts capacity\nend\n\ntram"}, {"source_code": "ret = 0\nfor i in 1..gets.to_i do\n a,b = gets.split.map(&:to_i)\n if (b-a>0) then ret += b-a end\nend\nputs ret"}, {"source_code": "a=gets.chomp\nres=0\nif a.length==1\nif a==a.upcase\nputs \"#{a.downcase}\"\nelse\nputs \"#{a.upcase}\"\nend\nelse\n1.upto(a.length-1) do|i|\nif a[i]!=a[i].upcase\nres=1\nend\nbreak if res==1\nend\nif res==1\nputs \"#{a}\"\nelsif (a[0]==a[0].upcase)\nputs \"#{a.downcase}\"\nelse \na=a.downcase\nb=a[0].upcase+a[1..a.length-1]\nputs \"#{b}\"\nend\nend"}, {"source_code": "n=gets.to_i\n\nans=bus=0\nn.times{\n\ta,b=gets.split.map(&:to_i)\n\t\n\tbus-=(-a+b)\n\tans=[bus, ans].max\n}\n\np ans\n"}, {"source_code": "n = gets.to_i\n a,b=gets.split.map(&:to_i)\ns = max = 0\n(0..n-1).each{|i|\n s = s - a[i] + b[i] \n max < s ? max = s : max = max\n}\np max"}, {"source_code": "stops = gets.chomp.to_i\npassengers = []\ni = 0\nwhile i < stops\n\tn = gets.chomp\n\tpassengers << n.split(\" \")\n\ti += 1\nend\n\narr = []\ncount = 0\npassengers.each do |pair|\n\tif passengers[0] == pair\n\t\tcount += pair[1].to_i \n\telse\n\t\tcount -= pair[0].to_i\n\t\tcount += pair[1].to_i\n\t\tarr << count\n\tend\nend\n\nprint arr.max "}, {"source_code": "caps = 0\ngets.to_i.times {\n a, b = gets.split.map(&:to_i)\n caps = [caps, caps - a + b].max\n}\nputs caps\n"}, {"source_code": "tramio, results = [], []\ngets.to_i.times { tramio << gets.split.map(&:to_i) }\n(tramio.size-1).times {|index| results << (tramio[index][1] - tramio[index+1][0] + tramio[index+1][1]) }\nputs results.max"}, {"source_code": "n = gets.to_i\na = []\nb = []\nfor i in 1..n do\n\tb = gets.split.map(&:to_i)\n\ta.push(b)\nend\nprint a\nj = 1\nc = a[0][1]\nmax = 0\nwhile j < (n-1) do\n\tc = c - a[j][0] + a[j][1]\n\tj = j+1\n\tif c > max\n\t\tmax = c\n\tend\nend\n\nputs max\n\n\n"}], "src_uid": "74b90fe9458b147568ac9bd09f219aab"} {"source_code": "n = gets.chomp.to_i\na = gets.split(\" \").map{|e| e.to_i}\nb = a.each_cons(2).map.with_index{|e, i| (e[0] - e[1]).abs * (i & 1 == 0 ? 1 : -1)}\nc = b.map{|e| -e}\ndef get_max_sum(a)\n l = 0\n r = 0\n sum = a[0]\n max = sum\n while r < a.length - 1\n while r < a.length - 1 && sum >= 0\n r += 1\n sum += a[r]\n max = [max, sum].max\n end\n while sum < 0\n sum -= a[l]\n l += 1\n max = [max, sum].max\n end\n end\n while l < a.length\n sum -= a[l]\n l += 1\n max = [max, sum].max\n end\n return max\nend\nputs [get_max_sum(b), get_max_sum(c)].max\n", "positive_code": [{"source_code": "n = gets.strip.to_i\na = gets.split.map(&:to_i)\n\ns = (0...n-1).map { |i| (a[i] - a[i+1]).abs }\n\ns1 = s.map.with_index { |v, i| i % 2 == 0 ? v : -v }\ns2 = s.drop(1).map.with_index { |v, i| i % 2 == 0 ? v : -v }\n\ndef solve(arr)\n arr.push(0)\n mn = 0\n (1...arr.length).each { |i| arr[i] += arr[i-1] }\n (0...arr.length).map { |i|\n mn = [mn, arr[i]].min if i % 2 == 1\n arr[i] - mn\n }.max\nend\n\nputs [solve(s1), solve(s2)].max\n\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nb = (n - 1).times.map{|i| (a[i + 1] - a[i]).abs * (-1) ** i}\nbs = [0]\n(n - 1).times{|i| bs[i + 1] = bs[i] + b[i]}\ncmi = bs[0]\ncmx = bs.max\nmx = 0\nmi = 0\nn.times do |i|\n t = bs[i] - cmi\n mx = [t, mx].max\n cmi = [bs[i], cmi].min\n\n t = bs[i] - cmx\n mi = [t, mi].min\n cmx = [bs[i], cmx].max\nend\np [mx, mi.abs].max\n"}], "negative_code": [{"source_code": "n = gets.strip.to_i\na = gets.split.map(&:to_i)\n\ns = (0...n-1).map { |i| (a[i] - a[i+1]).abs }\n\ns1 = s.map.with_index { |v, i| i % 2 == 0 ? v : -v }\ns2 = s.drop(1).map.with_index { |v, i| i % 2 == 0 ? v : -v }\n\ndef solve(arr)\n arr.push(0)\n (1...arr.length).each { |i| arr[i] += arr[i-1] }\n mn = 0\n (0...arr.length).step(2).map { |i|\n mn = [mn, arr[i]] if i % 2 == 1\n arr[i] - mn\n }.max\nend\n\nputs [solve(s1), solve(s2)].max\n\n"}], "src_uid": "7ff7f47cee182d2542754e412f6aab1a"} {"source_code": "st0 = Time.now\nn = gets().to_i\narr = [0] * n\nn.times do |i|\n arr[i] = gets().chomp\nend\n# puts \"0- #{Time.now - st0}\"\nst1 = Time.now\nb = Array.new(arr.size) {[0, '']}\n# b = Hash.new([0, ''])\n# puts \"1- #{Time.now - st1}\"\nt = 0\n\nst2 = Time.now\narr.each_with_index do |e, ind|\n l = true\n r = e[-1] == ')'\n min_i = 0\n min = 1e9\n lst = 0\n # b[ind] = [0, '']\n e.each_char.with_index do |s, indd|\n lst = indd\n b[ind][0] += (s == '(') ? 1 : -1\n l = l && (b[ind][0] >= 0)\n if (b[ind][0] <= min)\n min = b[ind][0]\n min_i = indd\n end\n end\n r = r && min_i == lst && b[ind][0] <= 0\n b[ind][1] += 'l' if l\n b[ind][1] += 'r' if r\n if l && r\n t += 1\n end\nend\n# puts \"2- #{Time.now - st2}\"\n# puts arr.to_s\n# puts b.to_s\np = Hash.new(0)\nm = Hash.new(0)\nst3 = Time.now\nb.each do |e|\n if e[0] < 0 && e[1] != ''\n m[-e[0]] += 1\n end\n if e[0] > 0 && e[1] != ''\n p[e[0]] += 1\n end\nend\n# puts \"3- #{Time.now - st3}\"\n# puts p\n# puts m\nres = 0\nst4 = Time.now\n(p.keys & m.keys).each do |e|\n lp = p[e]\n rm = m[e]\n res += [lp, rm].min\nend\n\n# puts \"4- #{Time.now - st4}\"\n# puts \"sum- #{Time.now - st0}\"\n# puts t\nputs res + t/2", "positive_code": [{"source_code": "# Utility\nclass BracketsSequence\n attr_reader :str, :correct, :clear_open, :clear_close\n\n def initialize(str)\n @str = str.strip\n \n @clear_open = 0\n @clear_close = 0\n \n @str.each_char do |c| \n if c == \"(\"\n @clear_open += 1\n else\n @clear_open == 0 ? (@clear_close += 1) : (@clear_open -= 1)\n end\n end\n \n @correct = (@clear_open == 0) && (@clear_close == 0)\n end\n\n def to_s\n @str\n end\nend\n\n\n# Input and processing\nn = gets.to_i\nseq = Array.new\n\ncorrect_count = 0\nn.times do |i| \n s = BracketsSequence.new(gets)\n if s.correct\n correct_count += 1\n else\n seq << s\n end\nend\n\ncount = 0\nleft = Hash.new(0) # Amount of sequences with only N of opening brackets\nright = Hash.new(0) # Amount of sequences with only N of closing brackets\nseq.each do |s|\n if s.clear_close == 0\n left[s.clear_open] += 1\n elsif s.clear_open == 0\n right[s.clear_close] += 1\n end \nend\n\nleft.each { |key, value| count += [value, right[key]].min }\n\n\n# Output\nputs correct_count / 2 + count\n"}, {"source_code": "def stack_output(s)\n stack = Array.new\n opening_count = 0\n closing_count = 0\n s.split('').each do |char|\n if char == '('\n stack.push(char)\n opening_count += 1\n elsif char == ')'\n unless stack.empty?\n stack.pop\n opening_count -= 1\n else\n closing_count += 1\n end\n end\n end\n if opening_count != 0 && closing_count != 0\n return ['unbalanced', -1]\n elsif opening_count != 0\n return ['open', opening_count]\n elsif closing_count != 0\n return ['close', closing_count]\n else\n return ['balanced', -1]\n end\nend\n\ns_arr = []\nn = gets.chomp.to_i\n\n0.upto(n-1) do |i|\n s_arr << gets.chomp\nend\n\nopen_bracket = {}\nclosing_bracket = {}\nbalanced_bracket = 0\n\ns_arr.each do |s|\n type, count = stack_output(s)\n case type\n when 'open'\n open_bracket[count] ||= 0\n open_bracket[count] += 1\n when 'close'\n closing_bracket[count] ||= 0\n closing_bracket[count] += 1\n when 'balanced'\n balanced_bracket += 1\n end\nend\n\nac = 0\nopen_bracket.each do |k, v|\n ac += [v, closing_bracket[k]].min unless closing_bracket[k].nil?\nend\n\nac += balanced_bracket/2\nprint ac\n"}, {"source_code": "N = gets.to_i\nes = {}\n\ndef judge(s)\n t = []\n s.each{ |c|\n if t.size > 0 && t[-1] == \"(\" && c == \")\"\n t.pop\n else\n t << c\n end\n }\n t.size == 0 ? 0 : (t[0] == t[-1] ? (t[0] == \"(\" ? t.size : -t.size) : nil)\nend\n\nN.times {\n s = gets.chomp.split(\"\")\n x = judge(s)\n #p [s.join(\"\"),x]\n next if !x\n es[x] = (es[x] || 0) + 1\n}\n#p es\np es.keys.select{ |x| x > 0 }.reduce(0){ |a,x| a + [es[x] || 0, es[-x] || 0].min } + (es[0] || 0)/2"}], "negative_code": [{"source_code": "st0 = Time.now\nn = gets().to_i\narr = []\nn.times do\n arr += [gets().chomp]\nend\nst1 = Time.now\nb = Hash.new([0, ''])\n# arr.size.times do\n# b += [[0, '']]\n# end\n# puts \"1- #{Time.now - st1}\"\nt = 0\n\nst2 = Time.now\narr.each_with_index do |e, ind|\n l = true\n r = e[-1] == ')'\n min_i = 0\n min = 1e9\n lst = 0\n b[ind] = [0, '']\n e.each_char.with_index do |s, indd|\n lst = indd\n b[ind][0] += (s == '(') ? 1 : -1\n l = l && (b[ind][0] >= 0)\n if (b[ind][0] <= min)\n min = b[ind][0]\n min_i = indd\n end\n end\n r = r && min_i == lst && b[ind][0] <= 0\n b[ind][1] += 'l' if l\n b[ind][1] += 'r' if r\n if l && r\n t += 1\n end\nend\n# puts \"2- #{Time.now - st2}\"\n# puts arr.to_s\n# puts b.to_s\np = Hash.new(0)\nm = Hash.new(0)\nst3 = Time.now\nb.values.each do |e|\n if e[0] < 0\n m[-e[0]] += 1\n end\n if e[0] > 0\n p[e[0]] += 1\n end\nend\n# puts \"3- #{Time.now - st3}\"\n# puts p\n# puts m\nres = 0\nst4 = Time.now\n(p.keys & m.keys).each do |e|\n lp = p[e]\n rm = m[e]\n res += [lp, rm].min\nend\n\n# puts \"4- #{Time.now - st4}\"\n# puts \"sum- #{Time.now - st0}\"\n# puts t\nputs res + t/2"}, {"source_code": "n = gets().to_i\narr = []\nn.times do\n arr += [gets().chomp]\nend\nb = []\narr.size.times do\n b += [[0, '']]\nend\nt = 0\narr.each_with_index do |e, ind|\n l = true\n r = e[-1] == ')'\n min_i = 0\n min = 1e9\n lst = 0\n e.each_char.with_index do |s, indd|\n lst = indd\n b[ind][0] += (s == '(') ? 1 : -1\n l = l && (b[ind][0] >= 0)\n if (b[ind][0] <= min)\n min = b[ind][0]\n min_i = indd\n end\n end\n r = r && min_i == lst\n b[ind][1] += 'l' if l\n b[ind][1] += 'r' if r\n if l && r\n t += 1\n end\nend\n# puts arr.to_s\n# puts b.to_s\np = Hash.new('')\nm = Hash.new('')\nb.each do |e| #TODO: e[0] == 0\n if e[0] < 0\n m[-e[0]] += e[1]\n end\n if e[0] > 0\n p[e[0]] += e[1]\n end\nend\nres = 0\n(p.keys & m.keys).each do |e|\n lp = p[e].count('l')\n rp = p[e].count('r')\n lm = m[e].count('l')\n rm = m[e].count('r')\n res += [lp, rm].min + [rp, lm].min\nend\nputs res + t/2"}, {"source_code": "st0 = Time.now\nn = gets().to_i\narr = []\nn.times do\n arr += [gets().chomp]\nend\nst1 = Time.now\nb = Array.new(arr.size) {[0, '']}\n# b = Hash.new([0, ''])\n# puts \"1- #{Time.now - st1}\"\nt = 0\n\nst2 = Time.now\narr.each_with_index do |e, ind|\n l = true\n r = e[-1] == ')'\n min_i = 0\n min = 1e9\n lst = 0\n # b[ind] = [0, '']\n e.each_char.with_index do |s, indd|\n lst = indd\n b[ind][0] += (s == '(') ? 1 : -1\n l = l && (b[ind][0] >= 0)\n if (b[ind][0] <= min)\n min = b[ind][0]\n min_i = indd\n end\n end\n r = r && min_i == lst && b[ind][0] <= 0\n b[ind][1] += 'l' if l\n b[ind][1] += 'r' if r\n if l && r\n t += 1\n end\nend\n# puts \"2- #{Time.now - st2}\"\n# puts arr.to_s\n# puts b.to_s\np = Hash.new(0)\nm = Hash.new(0)\nst3 = Time.now\nb.each do |e|\n if e[0] < 0\n m[-e[0]] += 1\n end\n if e[0] > 0\n p[e[0]] += 1\n end\nend\n# puts \"3- #{Time.now - st3}\"\n# puts p\n# puts m\nres = 0\nst4 = Time.now\n(p.keys & m.keys).each do |e|\n lp = p[e]\n rm = m[e]\n res += [lp, rm].min\nend\n\n# puts \"4- #{Time.now - st4}\"\n# puts \"sum- #{Time.now - st0}\"\n# puts t\nputs res + t/2"}, {"source_code": "N = gets.to_i\nes = {}\nN.times {\n s = gets.chomp.split(\"\")\n t = [0,0]\n s.each{ |c|\n case c\n when \"(\"\n if t[1] > 0\n t[1] -= 1\n else\n t[0] += 1\n end\n when \")\"\n if t[0] > 0\n t[0] -= 1\n else\n t[1] += 1\n end\n end\n }\n #p [s,t]\n next if t[0] > 0 && t[1] > 0\n x = t[0] > 0 ? t[0] : -t[1]\n es[x] = (es[x] || 0) + 1\n}\n\np es.keys.select{ |x| x > 0 }.reduce(0){ |a,x| a + [es[x] || 0, es[-x] || 0].min } + (es[0] || 0)/2"}], "src_uid": "2cfb08b2269dbf5417c1758def4c035f"} {"source_code": "$a = [0]\ndef bs(w,x,y)\n\t\tpi = (x+y)/2\n\t\tif w <= $a[pi] and w > $a[pi-1]\n\t\t\treturn pi\n\t\telsif w > $a[pi]\n\t\t\treturn bs(w,pi+1,y)\n\t\telse\n\t\t\treturn bs(w,x,pi-1)\n\t\tend\n\t\t\t\nend\nn = gets.to_i\nc = 1\ngets.split.map(&:to_i).each do |i|\n\t$a[c] = $a[c-1] + i\n\tc += 1\nend\nm = gets.to_i\ngets.split.map(&:to_i).each do |i|\n\tputs bs(i,0,n)\nend", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nm = gets.to_i\nq = gets.split.map &:to_i\n(1...n).each do |i|\n a[i] += a[i - 1]\nend\na = [0] + a\nn.downto(1).each do |i|\n a[i] = a[i - 1] + 1\nend\nq.each do |x|\n ans = 1\n l, r = 1, n\n while l <= r do\n mid = (l + r) / 2\n if x >= a[mid] then\n l = mid + 1\n ans = [ans, mid].max\n else\n r = mid - 1\n end\n end\n puts ans\nend\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split(\" \").map { |e| e.to_i }\nm = gets.chomp.to_i\nq = gets.chomp.split(\" \").map { |e| e.to_i }\n\nhash = {}\nc = 1\na.each_with_index { |val, idx|\n val.times { \n hash[c] = idx + 1\n c += 1\n }\n}\n\nq.each { |val|\n puts hash[val]\n}\n"}, {"source_code": "n = STDIN.readline.to_i\npiles = STDIN.readline.split.map {|s| s.to_i }\ntotal = piles.inject(:+)\nindex = Array.new(total+1)\npos = 0\npiles.each_with_index do |pile, i|\n\tpile.times do\n\t\tpos += 1\n\t\tindex[pos] = i+1\n\tend\nend\nm = STDIN.readline.to_i\nresults = []\nxs = STDIN.readline.split.map {|s| s.to_i }\nxs.each {|x| results.push(index[x]) }\nputs results.join(\"\\n\")\n"}, {"source_code": "#!/usr/bin/ruby\nt = 0\np = []\ngets\ngets.split(' ').each{|x|\n t += 1\n p << [t] * x.to_i\n}\np.flatten!\ngets\ngets.split(' ').each{|x|\n puts p[x.to_i - 1]\n}"}, {"source_code": "gets\narr = gets.split.map &:to_i\ngets\nbest = gets.split.map &:to_i\nkey = 1\nhash = {}\narr.each_with_index do |item, index| \n item.times do |x|\n hash[key] = index + 1\n key += 1\n end\nend\nbest.each { |x| puts hash[x] }\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\ns = []\ntemp = 0\na.each.with_index do |i, id|\n s << [temp + 1, temp + i, id + 1]\n temp += i\nend\ngets\nqs = gets.split.map(&:to_i)\nqs.each do |q|\n ans = s.bsearch do |x|\n if x[0] <= q && q <= x[1]\n 0\n elsif q < x[0]\n -1\n else\n 1\n end\n end\n puts ans[2]\nend"}, {"source_code": "n = Integer(gets.chomp)\nnumbers = gets\nnumbers_split = numbers.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(numbers_split[i])\nend\nm = Integer(gets.chomp)\nnumbers2 = gets\nnumbers2_split = numbers2.split\nq = Array.new\nfor i in 0...m\n q[i] = Integer(numbers2_split[i])\nend\n\ndef binary_search(object,a)\n lo = 0\n hi = a.length - 1\n while lo != hi - 1\n mid = lo + (hi - lo) / 2\n if object <= a[mid]\n hi = mid\n elsif object > a[mid]\n lo = mid\n end \n end\n return lo + 1\nend \n\na2 = Array.new\na2[0] = 0\nmy = 0\nfor i in 0...n\n my += a[i]\n a2.push(my)\nend\n\nfor i in 0...m\n puts binary_search(q[i],a2)\nend"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\nm = gets.chomp.to_i\nq = gets.chomp.split.map(&:to_i)\n\narr = []\nfor i in (0..n-1)\n\tif i != 0\n\t\tsum = arr[i-1] + a[i]\n\t\tarr << sum\n\telse\n\t\tarr << a[i]\n\tend\nend\n\nfor i in (0..m-1)\n\tfirst = 0\n\tlast = n-1\n\tmid = (first + last)/2\n\twhile first < last\n\t\tif arr[mid] < q[i]\n\t\t\tfirst = mid+1\n\t\telse\n\t\t\tlast = mid\n\t\tend\n\t\tmid = (first + last)/2\n\tend\n\tputs first+1\nend"}, {"source_code": "=begin\n5\n2 7 3 4 9\n3\n1 25 11 \n=end\nn = gets.to_i\nns = gets.split.map(&:to_i)\nm = gets.to_i\nms = gets.split.map(&:to_i)\ns = []\nstack = 1\nn.times do |i|\n ns[i].times do\n s.push stack\n end\n stack += 1\nend\nm.times do |i|\n puts s[ms[i] - 1]\nend\n"}, {"source_code": "n = gets.chomp\nm = Array.new\nk = 0\n\ngets.split.map do |e|\n\n k += 1\n\n for i in 1..e.to_i\n m << k\n end\n\nend\n\ngets.chomp\n\ngets.split.map do |e|\n\n puts m[e.to_i-1]\n\nend"}, {"source_code": "def read_int_array\n $stdin.readline.split(' ').map(&:to_i)\nend\n\nunless Array.method_defined? :bsearch_index\n class Array\n def bsearch_index\n ibegin, iend = 0, length\n found = false\n while ibegin < iend\n imid = ibegin + (iend - ibegin) / 2\n val = at(imid)\n if yield val\n found = true\n iend = imid\n else\n ibegin = imid + 1\n end\n end\n found ? ibegin : nil\n end\n end\nend\n\nPILES_AMOUNT = $stdin.readline.to_i\n\nPILES = read_int_array.reduce([]) { |array, pile| array.push (array[-1] or 0) + pile }\n\nWORMS_AMOUNT = $stdin.readline.to_i\n\nresult = read_int_array.map { |worm| PILES.bsearch_index { |pile| pile >= worm } + 1 }\nputs result"}, {"source_code": "gets\na = gets.split(' ').each_with_index.map { |n, i| [i+1]*n.to_i }.flatten.unshift(0)\n\ngets\ngets.split(' ').each do |x|\n puts a[x.to_i]\nend\n"}, {"source_code": "i=0;\nj=[];\n\ngets\ngets.split(' ').each{|x| i+=1; j << [i] * x.to_i}\nj.flatten!\ngets\ngets.split(' ').each{|x| puts j[x.to_i-1]}"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\nm = gets.to_i\nq = gets.split(' ').map(&:to_i)\n(1).upto(n-1) do |i|\n a[i]+=a[i-1]\nend\nb=[1]\na.each {|ai| b.push(ai+1)}\nq.each do |i|\n s,e,mid,best=0,n,0,0\n while s<=e\n mid=s+e>>1\n if(b[mid]<=i)\n best=mid\n s=mid+1\n else\n e=mid-1\n end\n end\n puts best+1\nend\n"}], "negative_code": [{"source_code": "n = Integer(gets.chomp)\nnumbers = gets\nnumbers_split = numbers.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(numbers_split[i])\nend\nm = Integer(gets.chomp)\nnumbers2 = gets\nnumbers2_split = numbers2.split\nq = Array.new\nfor i in 0...m\n q[i] = Integer(numbers2_split[i])\nend\n\ndef binary_search(object,a)\n lo = 0\n hi = a.length - 1\n while lo != hi - 1\n mid = lo + (hi - lo) / 2\n if object <= a[mid]\n hi = mid\n elsif object > a[mid]\n lo = mid\n end \n end\n return mid + 1\nend \n\na2 = Array.new\na2[0] = 0\nmy = 0\nfor i in 0...n\n my += a[i]\n a2.push(my)\nend\n\nfor i in 0...m\n puts binary_search(q[i],a2)\nend"}, {"source_code": "n = Integer(gets.chomp)\nnumbers = gets\nnumbers_split = numbers.split\na = Array.new\nfor i in 0...n\n a[i] = Integer(numbers_split[i])\nend\nm = Integer(gets.chomp)\nnumbers2 = gets\nnumbers2_split = numbers2.split\nq = Array.new\nfor i in 0...m\n q[i] = Integer(numbers2_split[i])\nend\n\ndef binary_search(object,a)\n lo = 0\n hi = a.length - 1\n while lo <= hi\n mid = lo + (hi - lo) / 2\n if object < a[mid]\n hi = mid - 1\n elsif object > a[mid]\n lo = mid + 1\n else object = a[mid]\n return mid\n end \n end\n return mid\nend \n\na2 = Array.new\na2[0] = 0\nmy = 0\nfor i in 0...n\n my += a[i]\n a2.push(my)\nend\n\nfor i in 0...m\n puts binary_search(q[i],a2)\nend"}], "src_uid": "10f4fc5cc2fcec02ebfb7f34d83debac"} {"source_code": "N = gets.to_i\nNames = Hash.new\nNames[\"Anka\"] = 0\nNames[\"Chapay\"] = 1\nNames[\"Cleo\"] = 2\nNames[\"Troll\"] = 3\nNames[\"Dracul\"] = 4\nNames[\"Snowy\"] = 5\nNames[\"Hexadecimal\"] = 6\n\nLikings = Array.new(7) {Array.new(7, 0)}\n\nN.times do\n inputs = gets.split(' ')\n s = Names[inputs[0]]\n o = Names[inputs[2]]\n Likings[s][o] = 1\nend\n\nScores = gets.chomp.split.map{|e| e.to_i}\n\ndef dfs(cur, choices)\n if (cur.size < 7)\n 3.times do |i|\n nc = cur.clone\n nc.push i\n dfs(nc, choices)\n end\n else\n choices.push cur\n end\nend\n\nchoices = []\ndfs([], choices)\n\nbest_diff = 9999999999\nbest_liking = 0\n\nchoices.each do |c|\n counts = [0, 0, 0]\n 7.times do |i|\n counts[c[i]] += 1\n end\n next if (counts[0] == 0 || counts[1] == 0 || counts[2] == 0)\n \n score_min = [Scores[0] / counts[0], Scores[1] / counts[1], Scores[2] / counts[2]].min\n score_max = [Scores[0] / counts[0], Scores[1] / counts[1], Scores[2] / counts[2]].max\n \n score_diff = score_max - score_min\n\n liking = 0\n 7.times do |i|\n 7.times do |j|\n if (Likings[i][j] == 1 && c[i] == c[j])\n liking += 1\n end\n end\n end\n\n if (score_diff < best_diff)\n best_diff = score_diff\n best_liking = liking\n elsif (score_diff == best_diff)\n if (liking > best_liking)\n best_liking = liking\n end\n end\nend\n\nputs \"#{best_diff} #{best_liking}\"\n\n\n \n", "positive_code": [{"source_code": "n = gets.to_i\n\n$likes = Array.new(7){Array.new(7) {0}}\n\nheroes = %w{Anka Chapay Cleo Troll Dracul Snowy Hexadecimal}\nn.times do\n l = gets\n l =~ /(\\w+) likes (\\w+)/\n $likes[heroes.index($1)][heroes.index($2)]=1\nend\n\nexp = gets.split.map {|e| e.to_i}\n\nd = []\nfor i0 in 1 .. 7 do\n for i1 in 1 .. (7-i0-1) do\n i2 = 7-i0-i1\n c = []\n c[0] = exp[0] / i0\n c[1] = exp[1] / i1\n c[2] = exp[2] / i2\n d.push([c.max - c.min, i0, i1, i2])\n end\nend\nd.select! {|e| e[0] == d.min[0]}\ndiff = d[0][0]\n\n$team = [] #hero => team\n\ndef countfr\n count = 0\n 7.times do |i|\n 7.times do |j|\n next if i == j\n count += $likes[i][j] if $team[i] == $team[j]\n end\n end\n count\nend\n\ndef rec(v=0)\n if v < 7\n 3.times do |i|\n $team[v] = i\n rec(v+1)\n end\n elsif $team.count(0) == $g[0] \\\n and $team.count(1) == $g[1] \\\n and $team.count(2) == $g[2]\n $fr = [$fr, countfr].max\n end\nend\n\n$maxfr = 0\nd.each do |dn|\n $g = dn[1..3]\n $fr = 0\n rec\n $maxfr = [$maxfr, $fr].max\nend\n\nprint diff, ' ', $maxfr\n"}, {"source_code": "def get_max_like(group, likes)\n ml = 0\n (0..6).to_a.permutation.each do |array|\n l = 0\n g = []\n g << array.slice!(0...group[0])\n g << array.slice!(0...group[1])\n g << array\n g.each do |gr|\n gr.each do |x|\n (gr - [x]).each do |y|\n l += 1 if likes[x].include?(y)\n end\n end\n end\n ml = l if ml < l\n end\n return ml\nend\n\nheroes = {\n 'Anka' => 0,\n 'Chapay' => 1,\n 'Cleo' => 2,\n 'Dracul' => 3,\n 'Hexadecimal' => 4,\n 'Snowy' => 5,\n 'Troll' => 6\n}\n\nlikes = []\n7.times{likes << Array.new}\n\ngets.to_i.times do\n h = gets.strip.split(/ likes /)\n likes[heroes[h[0]]] << heroes[h[1]]\nend\n#p likes\n\ngroups = []\nmin_diff = nil\npoints = gets.strip.split.map{|s| s.to_i}.sort\n1.step(2) do |x|\n 1.step(3) do |y|\n next if x > y\n 3.step(5) do |z|\n if x + y + z == 7\n p1 = points[0] / x\n p2 = points[1] / y\n p3 = points[2] / z\n max = min = 0\n if p1 > p2\n max = p1 > p3 ? p1 : p2 > p3 ? p2 : p3\n min = p2 < p3 ? p2 : p1 < p3 ? p1 : p3\n else\n max = p2 > p3 ? p2 : p1 > p3 ? p1 : p3\n min = p1 < p3 ? p1 : p2 < p3 ? p2 : p3\n end\n if min_diff.nil? || min_diff >= max - min\n unless min_diff == max - min\n groups.clear\n end\n min_diff = max - min\n groups << [x, y, z]\n end\n end\n end\n end\nend\n\nmax_like = 0\ngroups.each do |group|\n like = get_max_like(group, likes)\n max_like = like if like > max_like\nend\n\nputs [min_diff, max_like].join(\" \")\n"}, {"source_code": " n = gets.to_i\n members = %w(Anka Chapay Cleo Troll Dracul Snowy Hexadecimal)\n \n like = {}\n n.times do\n fr, to = gets.split.values_at(0, 2)\n like[[fr, to]] = true\n end\n exa, exb, exc = gets.split.map(&:to_i)\n cc = 0\n od = exa+exb+exc\n olk = 0\n (1..5).each do |i|\n members.combination(i) do |a|\n (1..(6-i)).each do |j|\n (members-a).combination(j) do |b|\n k = 7-i-j\n d = [(exa/i-exb/j).abs, (exb/j-exc/k).abs, (exc/k-exa/i).abs].max\n if od >= d\n c = members - a - b\n \n lk = 0\n lk += a.permutation(2).count{|x| like[x]}\n lk += b.permutation(2).count{|x| like[x]}\n lk += c.permutation(2).count{|x| like[x]}\n \n if od > d || (od == d && olk < lk)\n od = d\n olk = lk\n end\n \n end\n end\n end\n end\n end\n puts [od, olk]*\" \""}, {"source_code": "n = gets.to_i\nmembers = %w(Anka Chapay Cleo Troll Dracul Snowy Hexadecimal)\n\nlike = {}\nn.times do\n fr, to = gets.split.values_at(0, 2)\n like[[fr, to]] = true\nend\nexa, exb, exc = gets.split.map(&:to_i)\n\ncc = 0\n\nod = exa+exb+exc\nolk = 0\n(1..5).each do |i|\n members.combination(i) do |a|\n (1..(6-i)).each do |j|\n (members-a).combination(j) do |b|\n k = 7-i-j\n d = [(exa/i-exb/j).abs, (exb/j-exc/k).abs, (exc/k-exa/i).abs].max\n if od >= d\n c = members - a - b\n\n lk = 0\n lk += a.permutation(2).count{|x| like[x]}\n lk += b.permutation(2).count{|x| like[x]}\n lk += c.permutation(2).count{|x| like[x]}\n\n if od > d || (od == d && olk < lk)\n od = d\n olk = lk\n end\n\n end\n end\n end\n end\nend\n\nputs [od, olk]*\" \"\n"}, {"source_code": "def get_max_like(group, likes)\n ml = 0\n (0..6).to_a.permutation.each do |array|\n l = 0\n g = []\n g << array[0, group[0]]\n g << array[group[0], group[1]]\n g << array[group[0] + group[1], group[2]]\n g.each do |gr|\n gr.each do |x|\n (gr - [x]).each do |y|\n l += 1 if likes[x].include?(y)\n end\n end\n end\n ml = l if ml < l\n end\n return ml\nend\n\nheroes = {\n 'Anka' => 0,\n 'Chapay' => 1,\n 'Cleo' => 2,\n 'Dracul' => 3,\n 'Hexadecimal' => 4,\n 'Snowy' => 5,\n 'Troll' => 6\n}\n\nlikes = []\n7.times{likes << Array.new}\n\ngets.to_i.times do\n h = gets.strip.split(/ likes /)\n likes[heroes[h[0]]] << heroes[h[1]]\nend\n#p likes\n\ngroups = []\nmin_diff = nil\npoints = gets.strip.split.map{|s| s.to_i}.sort\n1.step(2) do |x|\n 1.step(3) do |y|\n next if x > y\n 3.step(5) do |z|\n if x + y + z == 7\n p1 = points[0] / x\n p2 = points[1] / y\n p3 = points[2] / z\n max = min = 0\n if p1 > p2\n max = p1 > p3 ? p1 : p2 > p3 ? p2 : p3\n min = p2 < p3 ? p2 : p1 < p3 ? p1 : p3\n else\n max = p2 > p3 ? p2 : p1 > p3 ? p1 : p3\n min = p1 < p3 ? p1 : p2 < p3 ? p2 : p3\n end\n if min_diff.nil? || min_diff >= max - min\n unless min_diff == max - min\n groups.clear\n end\n min_diff = max - min\n groups << [x, y, z]\n end\n end\n end\n end\nend\n\nmax_like = 0\ngroups.each do |group|\n like = get_max_like(group, likes)\n max_like = like if like > max_like\nend\n\nputs [min_diff, max_like].join(\" \")\n"}], "negative_code": [{"source_code": "n = gets.to_i\n\n$likes = Array.new(7){Array.new(7) {0}}\n\nheroes = %w{Anka Chapay Cleo Troll Dracul Snowy Hexadecimal}\nn.times do\n l = gets\n l =~ /(\\w+) likes (\\w+)/\n $likes[heroes.index($1)][heroes.index($2)]=1\nend\n\nexp = gets.split.map {|e| e.to_i}\n\nd = []\nfor i0 in 1 .. 7 do\n for i1 in 1 .. (7-i0-1) do\n i2 = 7-i0-i1\n c = []\n c[0] = exp[0] / i0\n c[1] = exp[1] / i1\n c[2] = exp[2] / i2\n d.push([c.max - c.min, i0, i1, i2])\n end\nend\n\nd = d.min\ndiff = d[0]\n$g = d[1..3]\n\n$team = [] #hero => team\n$maxfr = 0\n\ndef countfr\n count = 0\n 7.times do |i|\n 7.times do |j|\n next if i == j\n count += $likes[i][j] if $team[i] == $team[j]\n end\n end\n count\nend\n\ndef rec(v=0)\n if v < 7\n 3.times do |i|\n $team[v] = i\n rec(v+1)\n end\n elsif $team.count(0) == $g[0] \\\n and $team.count(1) == $g[1] \\\n and $team.count(2) == $g[2]\n $maxfr = [$maxfr, countfr].max\n end\nend\n\nrec\n\nprint diff, ' ', $maxfr\n"}, {"source_code": "n = gets.to_i\n\n$likes = Array.new(7){Array.new(7) {0}}\n\nheroes = %w{Anka Chapay Cleo Troll Dracul Snowy Hexadecimal}\nn.times do\n l = gets\n l =~ /(\\w+) likes (\\w+)/\n $likes[heroes.index($1)][heroes.index($2)]=1\nend\n\nexp = gets.split.map {|e| e.to_i}\n\nd = []\nfor i0 in 1 .. 7 do\n for i1 in 1 .. (7-i0-1) do\n i2 = 7-i0-i1\n c = []\n c[0] = exp[0] / i0\n c[1] = exp[1] / i1\n c[2] = exp[2] / i2\n d.push([c.max - c.min, i0, i1, i2])\n end\nend\n\nd.select! {|e| e[0] = d.min[0]}\ndiff = d[0][0]\n\n$team = [] #hero => team\n$maxfr = 0\n\ndef countfr\n count = 0\n 7.times do |i|\n 7.times do |j|\n next if i == j\n count += $likes[i][j] if $team[i] == $team[j]\n end\n end\n count\nend\n\ndef rec(v=0)\n if v < 7\n 3.times do |i|\n $team[v] = i\n rec(v+1)\n end\n elsif $team.count(0) == $g[0] \\\n and $team.count(1) == $g[1] \\\n and $team.count(2) == $g[2]\n $maxfr = [$maxfr, countfr].max\n end\nend\n\nd.each do |dn|\n $g = dn[1..3]\n rec\nend\n\nprint diff, ' ', $maxfr\n"}, {"source_code": "n = gets.to_i\n\n$likes = Array.new(7){Array.new(7) {0}}\n\nheroes = %w{Anka Chapay Cleo Troll Dracul Snowy Hexadecimal}\nn.times do\n l = gets\n l =~ /(\\w+) likes (\\w+)/\n $likes[heroes.index($1)][heroes.index($2)]=1\nend\n\nexp = gets.split.map {|e| e.to_i}\n\nd = []\nfor i0 in 1 .. 7 do\n for i1 in 1 .. (7-i0-1) do\n i2 = 7-i0-i1\n c = []\n c[0] = exp[0] / i0\n c[1] = exp[1] / i1\n c[2] = exp[2] / i2\n d.push([c.max - c.min, i0, i1, i2])\n end\nend\nd.select! {|e| e[0] == d.min[0]}\ndiff = d[0][0]\n\n$team = [] #hero => team\n\ndef countfr\n count = 0\n 7.times do |i|\n 7.times do |j|\n next if i == j\n count += $likes[i][j] if $team[i] == $team[j]\n end\n end\n count\nend\n\ndef rec(v=0)\n if v < 7\n 3.times do |i|\n next if $team.count(i) == $g[i]\n $team[v] = i\n rec(v+1)\n end\n else #if $team.count(0) == $g[0] \\\n #and $team.count(1) == $g[1] \\\n #and $team.count(2) == $g[2]\n $fr = [$fr, countfr].max\n end\nend\n\nmaxfr = 0\nd.each do |dn|\n $g = dn[1..3]\n $fr = 0\n rec\n $maxfr = [maxfr, $fr].max\nend\n\nprint diff, ' ', maxfr\n"}, {"source_code": "n = gets.to_i\nlike = Struct.new(:p, :q)\nlikes = []\nheroes = [\"Anka\", \"Chapay\", \"Cleo\", \"Troll\", \"Dracul\", \"Snowy\", \"Hexadecimal\"]\nn.times do\n l = gets\n l =~ /(\\w+) likes (\\w+)/\n likes.push(like.new(heroes.index($1), heroes.index($2)))\nend\n\nexp = gets.split.map {|e| e.to_i}\nc = []\nd = []\nfor i0 in 1 .. 7 do\n for i1 in 1 .. (7-i0-1) do\n i2 = 7-i0-i1\n c[0] = exp[0] / i0\n c[1] = exp[1] / i1\n c[2] = exp[2] / i2\n d.push([c.max - c.min, i0, i1, i2])\n end\nend\n\nd = d.min\ndiff = d[0]\ng = d[1..3].max\n\nprint diff, ' ', [g, likes.size].min\n\n"}, {"source_code": "def get_max_like(group, likes)\n ml = 0\n (0..6).to_a.permutation.each do |array|\n l = 0\n g = []\n g << array.slice!(0...group[0])\n g << array.slice!(0...group[1])\n g << array\n g.each do |gr|\n gr.each do |x|\n (gr - [x]).each do |y|\n l += 1 if likes[x].include?(y)\n end\n end\n end\n ml = l if ml < l\n return ml if ml == 7\n end\n return ml\nend\n\nheroes = {\n 'Anka' => 0,\n 'Chapay' => 1,\n 'Cleo' => 2,\n 'Dracul' => 3,\n 'Hexadecimal' => 4,\n 'Snowy' => 5,\n 'Troll' => 6\n}\n\nlikes = []\n7.times{likes << Array.new}\n\ngets.to_i.times do\n h = gets.strip.split(/ likes /)\n likes[heroes[h[0]]] << heroes[h[1]]\nend\n#p likes\n\ngroups = []\nmin_diff = nil\npoints = gets.strip.split.map{|s| s.to_i}.sort\n1.step(2) do |x|\n 1.step(3) do |y|\n next if x > y\n 3.step(5) do |z|\n if x + y + z == 7\n p1 = points[0] / x\n p2 = points[1] / y\n p3 = points[2] / z\n max = min = 0\n if p1 > p2\n max = p1 > p3 ? p1 : p2 > p3 ? p2 : p3\n min = p2 < p3 ? p2 : p1 < p3 ? p1 : p3\n else\n max = p2 > p3 ? p2 : p1 > p3 ? p1 : p3\n min = p1 < p3 ? p1 : p2 < p3 ? p2 : p3\n end\n if min_diff.nil? || min_diff >= max - min\n unless min_diff == max - min\n groups.clear\n end\n min_diff = max - min\n groups << [x, y, z]\n end\n end\n end\n end\nend\n\nmax_like = 0\ngroups.each do |group|\n like = get_max_like(group, likes)\n max_like = like if like > max_like\nend\n\nputs [min_diff, max_like].join(\" \")\n"}, {"source_code": "def get_max_like(group, likes)\n ml = 0\n (0..6).to_a.permutation.each do |array|\n l = 0\n g = []\n g << array[0, group[0]]\n g << array[group[0], group[1]]\n g << array[group[1], group[2]]\n g.each do |gr|\n gr.each do |x|\n (gr - [x]).each do |y|\n l += 1 if likes[x].include?(y)\n end\n end\n end\n ml = l if ml < l\n end\n return ml\nend\n\nheroes = {\n 'Anka' => 0,\n 'Chapay' => 1,\n 'Cleo' => 2,\n 'Dracul' => 3,\n 'Hexadecimal' => 4,\n 'Snowy' => 5,\n 'Troll' => 6\n}\n\nlikes = []\n7.times{likes << Array.new}\n\ngets.to_i.times do\n h = gets.strip.split(/ likes /)\n likes[heroes[h[0]]] << heroes[h[1]]\nend\n#p likes\n\ngroups = []\nmin_diff = nil\npoints = gets.strip.split.map{|s| s.to_i}.sort\n1.step(2) do |x|\n 1.step(3) do |y|\n next if x > y\n 3.step(5) do |z|\n if x + y + z == 7\n p1 = points[0] / x\n p2 = points[1] / y\n p3 = points[2] / z\n max = min = 0\n if p1 > p2\n max = p1 > p3 ? p1 : p2 > p3 ? p2 : p3\n min = p2 < p3 ? p2 : p1 < p3 ? p1 : p3\n else\n max = p2 > p3 ? p2 : p1 > p3 ? p1 : p3\n min = p1 < p3 ? p1 : p2 < p3 ? p2 : p3\n end\n if min_diff.nil? || min_diff >= max - min\n unless min_diff == max - min\n groups.clear\n end\n min_diff = max - min\n groups << [x, y, z]\n end\n end\n end\n end\nend\n\nmax_like = 0\ngroups.each do |group|\n like = get_max_like(group, likes)\n max_like = like if like > max_like\nend\n\nputs [min_diff, max_like].join(\" \")\n"}], "src_uid": "4ee20979c25c37eed38da902011988d1"} {"source_code": "main = -> {\n# possible_moves = []\n# (1 .. 50).each do |dx|\n# (1 .. 50).each do |dy|\n# if square?(dx**2 + dy**2)\n# possible_moves << [dx, dy]\n# end\n# end\n# end\n \n t = int\n t.times do\n x, y = ints\n \n if x == 0 and y == 0\n puts 0\n next\n end\n \n if square?(x**2 + y**2)\n puts 1\n next\n end\n \n puts 2\n end\n}\n\ndef square?(a)\n (0 ..).bsearch { _1**2 >= a }**2 == a\nend\n\nDEBUG = true\nMOD = 10**9+7\n$yesno = %w(No Yes)\nYesNo = %w(No Yes)\nYESNO = %w(NO YES)\nINF = 10**18\n\nrequire \"set\"\nrequire \"prime\"\n\ndef int; gets.to_s.to_i end\ndef ints; gets.to_s.split.map { |s| s.to_i } end\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\ndef float; gets.to_s.to_f end\ndef floats; gets.to_s.split.map { |s| s.to_f } end\ndef array_of(&convert); gets.to_s.split.map(&convert) end\ndef string; gets.to_s.chomp end\ndef strings; gets.to_s.split end\ndef rep(n, &b); Array.new(n, &b) end\ndef yes; puts $yesno[1] end\ndef no; puts $yesno[0] end\ndef yesno t; puts $yesno[t] end\ndef YesNo t; puts YesNo[t] end\ndef YESNO t; puts YESNO[t] end\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\ndef gcd(*xs); xs.inject(0, :gcd) end\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\ndef if_debug; yield if DEBUG end\n\nmodule Boolean\n def coerce(other); [other, to_i] end\n def +@; to_i end\n def to_int; to_i end\n def *(other); to_i * other end\nend\n\nclass TrueClass\n include Boolean\n def to_i; 1 end\nend\n\nclass FalseClass\n include Boolean\n def to_i; 0 end\nend\n\nclass Integer\n def div_ceil(y); (self + y - 1) / y end\n def mod_inv(mod = MOD); pow(mod-2, mod) end\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\nend\n\nclass Array\n def power(&block); (0 ... 1 << size).each(&block) end\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\nend\n\nmodule Enumerable\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\nend\n\nmain[]", "positive_code": [{"source_code": "gets.to_i.times do\r\n x, y = gets.split.map(&:to_i)\r\n sq = x * x + y * y\r\n p x == 0 && y == 0 ? 0 : Integer.sqrt(sq) ** 2 == sq ? 1 : 2\r\nend"}, {"source_code": "require \"set\"\r\n\r\nsquares = (0..100).map { |i| i * i }.to_set\r\n\r\npairs = (0..50).flat_map do |a|\r\n (0..50).flat_map do |b|\r\n if squares.include?(a * a + b * b)\r\n [[a, b], [-a, -b], [a, -b], [-a, b]]\r\n else\r\n []\r\n end\r\n end\r\nend.to_set\r\n\r\nfind = ->(x, y) {\r\n stack = [[x, y]]\r\n depth = 1\r\n loop do\r\n depth += 1\r\n stack = stack.flat_map do |x, y|\r\n pairs.map do |dx, dy|\r\n xy = [x + dx, y + dy]\r\n return depth if pairs.include?(xy)\r\n xy\r\n end\r\n end\r\n end\r\n}\r\n\r\ngets.to_i.times do\r\n x, y = gets.split.map(&:to_i)\r\n if x == 0 && y == 0\r\n p 0\r\n elsif pairs.include?([x, y])\r\n p 1\r\n else\r\n p find[x, y]\r\n end\r\nend\r\n"}], "negative_code": [{"source_code": "require \"set\"\r\n\r\nsquares = (1..100).map { |i| i * i }.to_set\r\n\r\npairs = (1..50).flat_map do |a|\r\n (1..50).flat_map do |b|\r\n if squares.include?(a * a + b * b)\r\n [[a, b], [-a, -b], [a, -b], [-a, b]]\r\n else\r\n []\r\n end\r\n end\r\nend.to_set\r\n\r\nfind = ->(x, y) {\r\n stack = [[x, y]]\r\n depth = 1\r\n loop do\r\n depth += 1\r\n stack = stack.flat_map do |x, y|\r\n pairs.map do |dx, dy|\r\n xy = [x + dx, y + dy]\r\n return depth if pairs.include?(xy)\r\n xy\r\n end\r\n end\r\n end\r\n}\r\n\r\ngets.to_i.times do\r\n x, y = gets.split.map(&:to_i)\r\n if x == 0 && y == 0\r\n p 0\r\n elsif pairs.include?([x, y])\r\n p 1\r\n else\r\n p find[x, y]\r\n end\r\nend\r\n"}], "src_uid": "fce6d690c2790951f7e04c622c3c2d44"} {"source_code": "N, M, Q = gets.split.map(&:to_i)\nG = N.gcd(M)\nQ.times do\n sx, sy, ex, ey = gets.split.map(&:to_i)\n s = (sy-1) * G / (sx == 1 ? N : M)\n e = (ey-1) * G / (ex == 1 ? N : M)\n puts s==e ? \"YES\" : \"NO\"\nend", "positive_code": [{"source_code": "N, M, Q = gets.split.map(&:to_i)\nG = N.gcd(M)\n\nQ.times do\n sx, sy, ex, ey = gets.split.map(&:to_i)\n s = (sy-1) * G / (sx==1 ? N : M)\n e = (ey-1) * G / (ex==1 ? N : M)\n puts s==e ? \"YES\" : \"NO\"\nend"}, {"source_code": "\nN, M, Q = gets.split.map(&:to_i)\nGCD = N.gcd(M)\nQ.times do\n\tarr = gets.split.map(&:to_i)\n\tidx1 = idx2 = 0\n\tif arr.shift == 1\n\t\tidx1 = arr.shift.to_r / N * GCD\n\telse\n\t\tidx1 = arr.shift.to_r / M * GCD\n\tend\n\tif arr.shift == 1\n\t\tidx2 = arr.shift.to_r / N * GCD\n\telse\n\t\tidx2 = arr.shift.to_r / M * GCD\n\tend\n#\tputs idx1 \n#\tputs idx2\n\tif idx1.ceil == idx2.ceil\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\n"}], "negative_code": [{"source_code": "\nN, M, Q = gets.split.map(&:to_i)\nGCD = N.gcd(M)\nQ.times do\n\tarr = gets.split.map(&:to_i)\n\tidx1 = idx2 = 0\n\tif arr.shift == 1\n\t\tidx1 = arr.shift.to_r / GCD\n\telse\n\t\tidx1 = (arr.shift.to_r * N / M) / GCD\n\tend\n\tif arr.shift == 1\n\t\tidx2 = arr.shift.to_r / GCD\n\telse\n\t\tidx2 = (arr.shift.to_r * N / M) / GCD\n\tend\n#\tputs idx1 \n#\tputs idx2\n\tif idx1.ceil == idx2.ceil\n\t\tputs \"YES\"\n\telse\n\t\tputs \"NO\"\n\tend\nend\n"}], "src_uid": "d4ae071cf261ec3d91187a9a7dddcda0"} {"source_code": "n,b=gets.split.map &:to_i\na=gets.split.map &:to_i\nt=(b+eval(a*'+')).to_f/n\nif t b\n puts \"-1\"\nelse\n wkf = (b - wk).to_f / a.length\n for i in 0..af.length-1\n puts format(\"%.6f\",(wkf+af[i]))\n end\nend\n"}, {"source_code": "n,b=gets.split.map &:to_i\na=gets.split.map &:to_i\nt=(b+eval(a*'+')).to_f/n\nif t prum\n\t\tputs \"-1\"\n\t\texit\n\tend\nend\nc.each do |a|\n\tprintf \"%0.6f\\n\", prum-a.to_i\nend\n"}, {"source_code": "n,b=gets.split.map &:to_i\na=gets.split.map &:to_i\nt=(b+eval(a*'+')).to_f/n\nif t 0 then\n\tputs -1\nelse\n\tputs m\nend"}, {"source_code": "n,b=gets.split.map &:to_i\na=gets.split.map &:to_i\nt=(b+eval(a*'+')).to_f/n\nif t b/n then\n\t\tputs -1\n\t\tbreak\n\tend\n\t\n\tm[i] = (b+sum)/n - m[i]\n\tputs m[i]\n\nend"}, {"source_code": "k = gets.chomp.split(\" \")\nn = k[0].to_i\nb = k[1].to_f\nm = gets.chomp.split(\" \")\nsum = 0\n\nfor i in(0..n-1)\n\tm[i] = m[i].to_f\n\tsum += m[i]\nend\n\nl = 0\n\nfor i in(0..n-1)\n\tif m[i] > b then\n\t\tl = 1\n\t\tbreak\n\tend\n\n\tm[i] = (b+sum)/n - m[i]\nend\n\n\nif l == 1 then\n\tputs -1\nelse\n\tputs m\nend"}, {"source_code": "k = gets.chomp.split(\" \")\nn = k[0].to_i\nb = k[1].to_f\nm = gets.chomp.split(\" \")\nsum = 0\n\nfor i in(0..n-1)\n\tm[i] = m[i].to_f\n\tsum += m[i]\nend\n\n\n\nfor i in(0..n-1)\n\tif b/n < m[i] then\n\t\tputs -1\n\t\tbreak\n\tend\n\n\tm[i] = (b+sum)/n - m[i]\n\tputs m[i]\nend"}], "src_uid": "65fea461d3caa5a932d1e2c13e99a59e"} {"source_code": "n = gets.strip.to_i\nprev_stops = []\nresults = gets.strip.split.map(&:to_i)\nresults.shift\n(n-1).times do\n current_stops = gets.strip.split.map(&:to_i)\n current_stops.shift\n results = results & current_stops\nend\nprint results.join(\" \")\n", "positive_code": [{"source_code": "gets;puts$<.map{|e|e.split[1..-1]}.reduce(:&)*' '"}, {"source_code": "n = gets.to_i\nh = {}\nn.times do\n r, *a = gets.split.map{|x| x.to_i}\n a.each do |x|\n h[x] = 0 unless h[x]\n h[x] += 1\n end\nend\nans = []\nh.each{|x| ans << x[0] if x[1] == n}\nputs ans.join(' ')\n"}, {"source_code": "n = gets.to_i\nstops = []\narr = gets.chomp.split(\" \").map(&:to_i)\narr.shift\n(n-1).times do\n newarr = (gets.chomp.split(\" \").map(&:to_i))\n newarr.shift\n arr = arr&newarr\nend\n\narr.each do |x|\n print \"#{x} \"\nend\n\nputs"}], "negative_code": [{"source_code": "n = gets.to_i\nstops = []\narr = gets.chomp.split(\" \").map(&:to_i)\n(n-1).times do\n arr = arr&(gets.chomp.split(\" \").map(&:to_i))\nend\n\narr.each do |x|\n print \"#{x} \"\nend\nputs\n"}, {"source_code": "n = gets.to_i\nstops = []\narr = gets.chomp.split(\" \").map(&:to_i)\n(n-1).times do\n newarr = (gets.chomp.split(\" \").map(&:to_i))\n newarr.shift\n arr = arr&newarr\nend\n\narr.each do |x|\n print \"#{x} \"\nend\n\nputs\n"}, {"source_code": "n = gets.to_i\nstops = []\narr = gets.chomp.split(\" \").map(&:to_i)\n(n-1).times do\n newarr = (gets.chomp.split(\" \").map(&:to_i))\n newarr.shift\n arr = arr&newarr\nend\n\narr.each do |x|\n print \"#{x} \"\nend\n\nputs"}, {"source_code": "n = gets.to_i\nstops = []\narr = gets.chomp.split(\" \").map(&:to_i)\n(n-1).times do\n newarr = (gets.chomp.split(\" \").map(&:to_i))\n arr = arr&newarr\nend\n\narr.each do |x|\n print \"#{x} \"\nend\n\nputs\n"}], "src_uid": "16c54cf7d8b484b5e22a7d391fdc5cd3"} {"source_code": "def solve\n n = gets.strip.to_i\n h = Hash.new(0)\n a = gets.strip.split(' ').map(&:to_i).each { |e| h[e] += 1 }\n ans = 0\n (2..n*2).each { |i|\n cnt = 0\n (1...(i / 2.0).ceil).each { |j| cnt += [h[j], h[i - j]].min }\n cnt += (h[(i / 2.0).to_i] / 2.0).to_i if i.even?\n ans = [ans, cnt].max\n }\n puts ans\nend\n\ngets.strip.to_i.times { solve } ", "positive_code": [{"source_code": "gets.to_i.times do\n n = gets.to_i\n w = gets.split.map &:to_i\n cnt = [0] * (n + 1)\n w.each do |i|\n cnt[i] += 1\n end\n res = 0\n (2..2 * n).each do |s|\n cur = 0\n (1...(s + 1) / 2).each do |i|\n next if s - i > n\n cur += [cnt[i], cnt[s - i]].min\n end\n cur += cnt[s / 2] / 2 if s % 2 == 0\n res = [res, cur].max\n end\n puts res\nend"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n n = gets.to_i\n w = gets.chomp.split(\" \").map(&:to_i).sort\n hash = Hash.new(0)\n w.each do |x|\n hash[x] += 1\n end\n min = w.min\n max = w.max\n maxans = 0\n (min*2).upto(max*2) do |i|\n cnt = 0\n ((i-1)/2).times do |j|\n cnt += [hash[j+1],hash[i-j-1]].min\n end\n if i % 2 == 0\n cnt += hash[i/2] / 2\n end\n maxans = cnt if cnt > maxans\n end\n ans << maxans\nend\nans.each do |x|\n puts x\nend"}], "negative_code": [], "src_uid": "0048623eeb27c6f7c6900d8b6e620f19"} {"source_code": "n = gets.chomp.to_i\nna = gets.chomp.split(/ /).map!{|x| x.to_i}\nna.sort!\nwk = 10\ncnt = 0\npen = 0\nfor i in 0..n-1\n wk += na[i]\n if wk > 720\n break\n end\n cnt += 1\n if wk > 360\n pen += (wk - 360)\n end\nend\nputs cnt.to_s + \" \" + pen.to_s\n", "positive_code": [{"source_code": "gets\n\nmins = gets.split.map{|_|_.to_i}.sort\n\nt = 10\nsolved = 0\npen = 0\n\nmins.each do |m|\n t += m\n if t > 720\n break\n end\n solved += 1\n if t > 360\n pen += t - 360\n end\nend\n\nputs \"#{solved} #{pen}\"\n"}], "negative_code": [], "src_uid": "76f94436b4388682b25c7213248b76a2"} {"source_code": "#!/usr/bin/ruby\n\nn, k, l, r, s_all, s_k = gets.split.map(&:to_i)\n\nhigh_base = s_k / k\nlow_base = ((k == n) ? 0 : (s_all - s_k) / (n - k))\n\nhigh_count = k\nlow_count = n - k\n\nhigh_elevated_count = s_k - k * high_base\nlow_elevated_count = (s_all - s_k) - (n - k) * low_base\n\nr = []\nhigh_elevated_count.times { r << (high_base + 1) }\n(high_count - high_elevated_count).times { r << high_base }\nlow_elevated_count.times { r << (low_base + 1) }\n(low_count - low_elevated_count).times { r << low_base }\n\nputs r.join(' ')\n", "positive_code": [{"source_code": "def populate_scores(a, x, k, s)\n d = k - x\n t = s / d\n rem = s % d\n for i in x...x + rem\n a[i] = t + 1\n end\n for i in x + rem...k\n a[i] = t\n end\nend\n\nn, k, _, _, s_all, s_k = gets.split.map { |x| x.to_i }\n\na = Array.new(n)\n\npopulate_scores(a, 0, k, s_k)\ns_rem = s_all - s_k\npopulate_scores(a, k, n, s_rem) if s_rem > 0\nputs a * ' '"}], "negative_code": [], "src_uid": "59154ca15716f0c1c91a37d34c5bbf1d"} {"source_code": "parse_int = lambda { gets.split.map{|x| x.to_i} }\n$stdout.sync = true\n\nchars = []\nfor lt in (0...10)\n puts lt.to_s*4\n $stdout.flush\n\n chars << lt unless parse_int.call == [0, 0]\nend\n\nfor perm in chars.permutation\n puts perm.join\n $stdout.flush\n \n break if parse_int.call == [4, 0]\nend\n", "positive_code": [{"source_code": "parse_int = lambda { gets.split.map{|x| x.to_i} }\n$stdout.sync = true\n \nchars = []\nfor lt in (0...10)\n puts lt.to_s*4\n $stdout.flush\n \n chars << lt unless parse_int.call == [0, 0]\nend\n \nfor perm in chars.permutation\n puts perm.join\n $stdout.flush\n \n break if parse_int.call == [4, 0]\nend\n"}, {"source_code": "parse_int = lambda { gets.split.map{|x| x.to_i} }\n$stdout.sync = true\n\nchars = []\nfor lt in (0...10)\n puts lt.to_s*4\n\n chars << lt if gets.chomp == '1 0'\nend\n\nfor vv in chars.permutation\n puts vv.join\n \n break if gets.chomp == '4 0'\nend"}], "negative_code": [], "src_uid": "6a260fc32ae8153a2741137becc6cfb4"} {"source_code": "gets.to_i.times do\n\ts = gets.chomp\n\tcnt = %w[U D L R].map { s.count _1 }\n\tud, lr = cnt[0, 2].min, cnt[2, 2].min\n\tud = 1 if lr == 0 && ud != 0\n\tlr = 1 if ud == 0 && lr != 0\n\tans = 'U' * ud + 'L' * lr + 'D' * ud + 'R' * lr\n\tputs ans.size, ans\nend\n", "positive_code": [{"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n\ndef C(a,b) b==0||a==b ? 1 : (b=a-b if a/2= 0 and arr[pos] == x\n\tputs pos+1\nelse\n\tputs -1\nend\n"}, {"source_code": "n,k=gets.split.map &:to_i;a=gets.split.map &:to_i;b=a.rindex{|i|i!=a[k-1]}||-1;p b= 0 && a[count]==a[-1]\n count -= 1\n end\n puts count+1\nelse\n puts -1\nend"}, {"source_code": "n,k= gets.chomp.split(' ').map(&:to_i)\na=gets.chomp.split(' ').map(&:to_i)\nif a[k-1..-1].uniq.length == 1\n count=k-2\n while count >= 0 && a[count]==a[-1]\n count -= 1\n end\n puts count+1\nelse\n puts -1\nend"}, {"source_code": "n, k = gets.split.map(&:to_i)\nk -= 1\na = gets.split.map(&:to_i)\nif (k..n-1).map { |i| a[i] }.uniq.size == 1\n el = (k..n-1).map { |i| a[i] }.uniq[0]\n c = -1\n c -= 1 while a[c] == el\n puts n+c+1\nelse\n puts(-1)\nend"}, {"source_code": "n,k=gets.split.map &:to_i;a=gets.split.map &:to_i;b=a.rindex{|i|i!=a[k-1]}||-1;p b= 0 && a[i] == a[a.size - 1] do\n i -= 1\nend\n\nif i >= k - 1 then\n puts -1\nelse\n puts i + 1\nend"}, {"source_code": "n,k=gets.split.map &:to_i;a=gets.split.map &:to_i;b=a.rindex{|i|i!=a[k-1]}||-1;p b{ gets.split.map(&:to_i) }\nn, k = I[]\na = I[]\nb = a.rindex{|i| i != a[k - 1]} || -1\nputs b < k - 1 ? b + 1 : -1\n"}, {"source_code": "n,k=gets.split.map &:to_i;a=gets.split.map &:to_i;b=a.rindex{|i|i!=a[k-1]}||-1;p b{gets.split.map &:to_i}\nn, k = I[]; a = I[]; a.unshift(0)\nb = a.rindex{|ai| ai != a[k]}\nputs b= 0 and a[ans] == a[-1]\n ans -= 1\n end\n puts ans+1\nelse\n puts -1\nend\n"}, {"source_code": "n, k = gets.split.collect{|i| i.to_i}\na = Array.new(gets.split)\nif a[k-1..-1].uniq.length == 1\n if k == 1\n puts 0\n exit\n end\n ans = k-2\n while ans >= 0 and a[ans] == a[-1]\n ans -= 1\n end\n puts ans+1\nelse\n puts -1\nend\n"}, {"source_code": "n,k=gets.split.map &:to_i;a=gets.split.map &:to_i;b=a.rindex{|i|i!=a[k-1]}||-1;p b= 0 && a[i] == a[d]\n i -= 1\nend\nputs i + 1"}, {"source_code": "fl = gets.split.map(&:to_i)\nn, k = fl[0] ,fl[1] - 1\nseq = gets.split.map(&:to_i)\n\nps = seq[k]\n\nk +=1 \n\nif !!seq.drop(k).find {|x| x != ps}\n puts (-1)\nelse\n aux = seq.zip((1..n).to_a).select { |x,y| x != ps}\n puts (aux.empty? ? 0 : aux.last[1])\nend"}, {"source_code": "n,k=gets.split.map &:to_i;a=gets.split.map &:to_i;b=a.rindex{|i|i!=a[k-1]}||-1;p b= 0)\n\t\treturn i+1 if (a[i] != a[k-1]) \n\t\ti -= 1\n\tend\n\treturn 0\nend\n\nputs f"}, {"source_code": "#!/usr/bin/env ruby\n\nn, k = gets.split.map(&:to_i)\nas = gets.split.map(&:to_i)\nsubseq = as[k-1...as.size]\nif subseq.any?{|v| v != subseq.first}\n puts -1\n exit\nend\npos = k-2\nturn = k-1\nwhile pos >= 0 && as[pos] == subseq.first\n pos -= 1\n turn -= 1\nend\nputs turn\n"}], "negative_code": [{"source_code": "I =->{gets.split.map &:to_i}[]\nn, k = I; a = I; a.unshift(0)\nb = a.rindex{|ai| ai != a[k]}\nputs b a.first + b.first) || (ab.first == nil && a.first && b.first)\n min_t += a.first + b.first\n a.shift\n b.shift\n else\n puts -1\n return\n end\n\n i += 1\n end\n\n puts min_t\nend\n\nrun\n", "positive_code": [{"source_code": "n, k = gets.split.map &:to_i\nbooks_alice_likes = []\nbooks_bob_likes = []\nbooks_both_like = []\nn.times do\n\tt, a, b = gets.split.map &:to_i\n\tif a == 1\n\t\tif b == 1\n\t\t\tbooks_both_like << t\n\t\telse\n\t\t\tbooks_alice_likes << t\n\t\tend\n\telsif b == 1\n\t\tbooks_bob_likes << t\n\tend\nend\n\nbooks_alice_likes.sort!\nbooks_bob_likes.sort!\nbooks_both_like.sort!\n\nbooks_read = 0\ntime = 0\nwhile books_read < k\n\tif books_both_like.empty?\n\t\tif books_alice_likes.empty? or books_bob_likes.empty?\n\t\t\tputs \"-1\"\n\t\t\texit\n\t\tend\n\n\t\ttime += books_alice_likes.shift + books_bob_likes.shift\n\t\tbooks_read += 1\n\n\telse\n\n\t\tif not (books_alice_likes.empty? or books_bob_likes.empty?) and books_alice_likes[0] + books_bob_likes[0] < books_both_like[0]\n\t\t\ttime += books_alice_likes.shift + books_bob_likes.shift\n\t\telse\n\t\t\ttime += books_both_like.shift\n\t\tend\n\t\tbooks_read += 1\n\tend\nend\n\nputs time\n"}], "negative_code": [{"source_code": "n, k = gets.split.map &:to_i\nbooks_alice_likes = []\nbooks_bob_likes = []\nbooks_both_like = []\nn.times do\n\tt, a, b = gets.split.map &:to_i\n\tif a == 1\n\t\tif b == 1\n\t\t\tbooks_both_like << t\n\t\telse\n\t\t\tbooks_alice_likes << t\n\t\tend\n\telsif b == 1\n\t\tbooks_bob_likes << t\n\tend\nend\n\nbooks_alice_likes.sort!\nbooks_bob_likes.sort!\nbooks_both_like.sort!\n\nbooks_read = 0\ntime = 0\nwhile books_read < k\n\tif books_both_like.empty?\n\t\tif books_alice_likes.empty? or books_bob_likes.empty?\n\t\t\tputs \"-1\"\n\t\t\texit\n\t\tend\n\n\t\ttime += books_alice_likes.shift + books_bob_likes.shift\n\t\tbooks_read += 1\n\n\telse\n\n\t\t#if not (books_alice_likes.empty? or books_bob_likes.empty?) and books_alice_likes[0] + books_bob_likes[0] < books_both_like[0]\n\t\t#\ttime += books_alice_likes.shift + books_bob_likes.shift\n\t\t#else\n\t\t\ttime += books_both_like.shift\n\t\t#end\n\t\tbooks_read += 1\n\tend\nend\n\nputs time\n"}, {"source_code": "def run\n n, k = gets.chomp.split(\" \").map(&:to_i)\n tab = []\n n.times do\n x, y, z = gets.chomp.split(\" \").map(&:to_i)\n if y == 0 && z == 0\n next\n end\n tab << [x, y, z]\n end\n\n tab.sort_by!{|t, a, b| a == 1 ? [0, t] : [1, 0]}\n\n i = 0\n b_i = 0\n min_t = 0\n\n while i < k\n\n if tab[i][1] == 1\n min_t += tab[i][0]\n if tab[i][2] == 1\n b_i += 1\n tab[i][3] = true\n end\n else\n puts -1\n return\n end\n\n i += 1\n end\n\n tab.sort_by!{|t, a, b| b == 1 ? [0, t] : [1, 0]}\n\n i = 0\n while i < k - b_i\n if tab[i][2] == 1\n unless tab[i][3]\n min_t += tab[i][0]\n end\n else\n puts -1\n return\n end\n\n i += 1\n end\n\n puts min_t\n\nend\n\nrun\n"}], "src_uid": "6a80b2af22cf8e5bb01ff47d257db196"} {"source_code": "n=gets.to_i\nh=gets.split.map &:to_i\ng=Hash.new{[]}\na=->b{s=[];b.zip(0..).map{|x,i|g[i]<<=s.shift while s[0]&&b[s[0]]b{s=[];b.zip(0..).map{|x,i|g[i]<<=s.shift while s[0]&&b[s[0]]b{s=[];b.zip(0..).map{|x,i|g[i]<<=s.shift while s[0]&&b[s[0]]b{s=[];b.zip(0..).map{|x,i|q=->a{g[i]=[g[i],g[a]+1].min}\nq[s.shift]while s[0]&&b[s[0]]b[1]}.reverse\nret = Array::new(m)\naset = Set::new()\nb = -1;\nstm = m\nm.times{|i|\n\taset.merge(a[ls[i][1]..b])\n\tret[ls[i][0]]=aset.size\n\tif (aset.size == maxuniq)\n\t\tstm = i+1;\n\t\tbreak\n\tend\n\tb = ls[i][1]-1\n}\nstm.upto(m-1) {|i| \n\tret[ls[i][0]] = maxuniq\n}\nret.each{|r| puts r}"}, {"source_code": "require 'set'\nn,m=gets.split.map{|e| e.to_i}\nx=gets.split.map{|e| e.to_i}\n\nls=[]\nm.times{|e|\n\tls<=0 && !ss.empty?\n\te1=ss.last-1\n\tif e1 n - l -1 + 1\n # <-> n - l Q.E.D\n puts unique_counter_reversed[n - l]\n}"}], "negative_code": [{"source_code": "require 'set'\n\nn, m = gets.split(\" \").map{|s| s.to_i}\na = gets.split(\" \").map{|s| s.to_i}\nl = Hash::new()\nm.times{|i| l[i] = gets.to_i-1}\nls = l.sort{|a,b| a[1]<=>b[1]}.reverse\nret = Array::new(m)\naset = Set::new()\nb = -1;\na.each{|el| puts el}\nm.times{|i|\n\taset.merge(a[ls[i][1]..b])\n\tret[ls[i][0]]=aset.size\n\taset.each{|el| puts el}\n\tb = ls[i][1]-1\n}\nret.each{|r| puts r}"}, {"source_code": "require 'set'\n\nn, m = gets.split(\" \").map{|s| s.to_i}\na = gets.split(\" \").map{|s| s.to_i}\nl = Hash::new()\nm.times{|i| l[i] = gets.to_i-1}\nls = l.sort{|a,b| a[1]<=>b[1]}.reverse\nret = Array::new(m)\naset = Set::new()\nb = -1;\na.each{|el| puts el}\nm.times{|i|\n\taset.merge(a[ls[i][1]..b])\n\tputs ls[i][1]\n\tret[ls[i][0]]=aset.size\n\taset.each{|el| puts el}\n\tb = ls[i][1]-1\n}\nret.each{|r| puts r}"}, {"source_code": "def solution(fence, take)\n\n prefix_sum = fence.inject([0]) { |v, i| v << v.last + i }\n\n min_cost = Float::INFINITY\n index = -1\n \n for i in 1...fence.size-take do\n if min_cost > prefix_sum[i+take-1] - prefix_sum[i-1]\n min_cost = prefix_sum[i+take-1] - prefix_sum[i-1]\n index = i\n end\n end\n index\nend\n\ntables, take = gets.split.map(&:to_i)\nfence = gets.split.map(&:to_i)\n\nputs solution(fence, take)"}, {"source_code": "gets\nrequire 'set'\n\nprev = Set.new\ncurrent = 0\nlongest = 0\ngets.split(/\\s+/).each_with_index do |n,i|\n n = n.to_i\n\n if prev.member?(n)\n prev = Set.new\n current = 1\n else\n prev.add(n)\n current += 1\n end\n\n longest = current if current > longest\nend\n\nwhile n = gets\n n = n.to_i\n if n < longest\n puts longest\n else\n x = 2*longest - n - 1\n puts x >= 0 ? x : 0\n end\nend\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nans = []\nm.times do |i|\n l = gets.to_i\n ans[i] = a[l...n].uniq.size\nend\nputs ans\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\na = [0] + gets.split.map(&:to_i)\nb = Array.new(100010, 0)\nbb = Array.new(100010, 0)\nc = 0\nfor i in 1..n\n b[a[i]] += 1\n c += 1 if bb[a[i]] == 0\n bb[a[i]] = 1\nend\n\ns = []\nfor i in 1..n\n s[i] = c\n b[a[i]] -= 1\n c -= 1 if b[a[i]] == 0\nend\nans = []\nm.times do |i|\n l = gets.to_i\n ans[i] = s[i + 1]\nend\nputs ans\n"}], "src_uid": "1e156dfc65ef88f19ca1833f75192259"} {"source_code": "gets.to_i.times do\n\tgets\n\tputs gets.split.map(&:to_i).uniq.size\nend", "positive_code": [{"source_code": "#! /usr/bin/env ruby\n# encoding: UTF-8\n\n=begin\n=end\n\ndef solve\n\tn = gets.to_i\n\txs = gets.split.map{|x| x.to_i }\n\tputs xs.uniq.size\nend\n\ngets.to_i.times{ solve }\n\n"}, {"source_code": "require 'set'; require 'prime'\nINF=Float::INFINITY; MOD=10**9+7\nt = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n a = gets.chomp.split.map(&:to_i)\n puts Set.new(a).size\nend\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n a = gets.split.map(&:to_i)\n\n puts a.uniq.size\nend\n"}, {"source_code": "1.upto(gets.to_i) do\n gets\n puts gets.split(' ').map(&:to_i).uniq.size\nend\n"}, {"source_code": "t = gets.chomp.to_i\n(0...t).each do |_|\n n = gets.chomp.to_i\n arr = gets.chomp.split.map(&:to_i).uniq\n puts arr.size\nend\n\n"}], "negative_code": [], "src_uid": "b978ca6fdef4a02cc027485294caa0f5"} {"source_code": "# http://codeforces.com/problemset/problem/381/A\n\nn = gets.chomp.to_i\nlist = gets.chomp.split.map(&:to_i)\n\nl, r = 0, n - 1\nsereja_move = true\nresult1 = 0\nresult2 = 0\n\nwhile l < n && r >= 0 && l <= r\n if list[l] < list[r]\n max = list[r]\n r -= 1\n else\n max = list[l]\n l += 1\n end\n\n sereja_move ? result1 += max : result2 += max\n sereja_move = !sereja_move\nend\n\nprint result1, \" \", result2\n", "positive_code": [{"source_code": "def solution(n, cards) \n l, sereja, dima, count = 0, 0, 0, 0\n r = n-1\n while (l <= r ) do \n if cards[l] > cards [r]\n sereja += cards[l]\n l += 1\n count += 1\n else\n sereja += cards[r]\n r -= 1\n count += 1\n end\n if count <= n/2\n if cards[l] > cards[r]\n dima += cards[l] \n l += 1\n else\n dima += cards[r] \n r -= 1\n end\n end\n end\n puts \"#{sereja} #{dima}\"\nend\n\nsolution(gets.chomp.to_i, gets.split.map(&:to_i))"}, {"source_code": "def solution(n, cards) \n l, sereja, dima, count = 0, 0, 0, 0\n r = n-1\n while (l <= r ) do \n if cards[l] > cards [r]\n sereja += cards[l]\n l += 1\n count += 1\n else\n sereja += cards[r]\n r -= 1\n count += 1\n end\n if r >= 0 && count <= n/2\n if cards[l] > cards[r]\n dima += cards[l] \n l += 1\n else\n dima += cards[r] \n r -= 1\n end\n end\n end\n puts \"#{sereja} #{dima}\"\nend\n\nsolution(gets.chomp.to_i, gets.split.map(&:to_i))"}, {"source_code": "# http://codeforces.com/problemset/problem/381/A\n\nn = gets.chomp.to_i\n\nlist = gets.chomp.split.map(&:to_i)\n\nl, r = 0, n - 1\n\nsereja_move = true\nresult = 0\nwhile l < n && r >= 0 && l <= r\n max = [list[l], list[r]].max\n\n if sereja_move\n result += max\n end\n\n if list[l] < list[r]\n r -= 1\n else\n l += 1\n end\n sereja_move = !sereja_move\nend\n\nprint result, \" \", list.inject(:+) - result\n"}, {"source_code": "# http://codeforces.com/problemset/problem/381/A\n\nn = gets.chomp.to_i\nlist = gets.chomp.split.map(&:to_i)\n\nl, r = 0, n - 1\nsereja_move = true\nresult = 0\n\nwhile l < n && r >= 0 && l <= r\n if list[l] < list[r]\n max = list[r]\n r -= 1\n else\n max = list[l]\n l += 1\n end\n\n result += max if sereja_move\n sereja_move = !sereja_move\nend\n\nprint result, \" \", list.inject(:+) - result\n"}, {"source_code": "gets\na = gets.split(' ').map(&:to_i)\ns = [0, 0]\n\n0.upto(a.size-1) do |i|\n s[i % 2] += [a.first, a.last].max\n\n a.__send__(a.first > a.last ? :shift : :pop)\nend\n\nputs s.join(' ')\n"}, {"source_code": "gets\ncards = gets.split.map(&:to_i)\nresult = [0, 0]\ni = 0\nuntil cards.empty?\n if cards.first > cards.last\n result[i] += cards.shift\n else\n result[i] += cards.pop\n end\n i += 1\n i %= 2\nend\nputs result.join ' '\n"}, {"source_code": "n = gets().to_i\narr = gets.split.map(&:to_i)\nl = 0\nr = n-1\none = 0\ntwo = 0\nturn = true\nwhile l <= r do\n if arr[l] >= arr[r]\n if turn\n one += arr[l]\n else\n two += arr[l]\n end\n l+=1\n else\n if turn \n one += arr[r]\n else\n two += arr[r]\n end\n r-=1\n end\n turn = !turn\nend\nprint one,\" \",two,\"\\n\""}, {"source_code": "n=gets.to_i\na=gets.split(' ').map(&:to_i)\ni,j=0,n-1\np=[0,0]\nv=0\nwhile(i<=j) do\n if(a[i]>a[j])\n p[v&1]+=a[i]\n i+=1\n else\n p[v&1]+=a[j]\n j-=1\n end\n v+=1\nend\nputs \"#{p[0]} #{p[1]}\"\n"}, {"source_code": "cardNum = gets.chomp.to_i\ncards = gets.chomp.split(' ').map {|i| i.to_i}\n\nplayers = Array.new(2) {|i| i = 0}\nnowTurn = 0\n\nuntil cards.length == 0\n\tif cards[0] > cards[cards.length - 1]\n\t\tplayers[nowTurn] += cards[0]\n\t\tcards.delete_at(0)\n\telse\n\t\tplayers[nowTurn] += cards[cards.length - 1]\n\t\tcards.delete_at(cards.length - 1)\n\tend\n\n\tnowTurn = (nowTurn + 1) % players.length\nend\n\nputs \"#{players[0]} #{players[1]}\""}, {"source_code": "n = gets.to_i\ncard = gets.split(' ').map(&:to_i)\nchange = {Sereja: :Dima, Dima: :Sereja}\nplayer = :Sereja\npoint = {Sereja: 0, Dima: 0}\nuntil card.length == 0\n if card.first > card.last\n point[player] += card.delete_at(0)\n else\n point[player] += card.delete_at(-1)\n end\n player = change[player]\nend\nputs \"#{point[:Sereja]} #{point[:Dima]}\""}, {"source_code": "#!/usr/bin/ruby\ngets\na=gets.split.map(&:to_i)\nr=[0,0]\nf=0\nwhile !a.empty?\n\tif a.first>a.last\n\t\tr[f]+=a.shift\n\telse\n\t\tr[f]+=a.pop\n\tend\n\tf^=1\nend\nputs r*' '"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split(' ').map{|x| x.to_i}\nl = 0\nr = n-1\nb = [0, 0]\np = 0\nwhile l <= r \n\tif arr[l] >= arr[r]\n\t\tb[p] += arr[l]\n\t\tl += 1\n\telsif\n\t\tb[p] += arr[r] \n\t\tr -= 1\n\tend\n\tp = 1-p\nend\nprint b[0], \" \", b[1]"}, {"source_code": "n = gets.to_i\na = gets.split.map &:to_i\nl = 0\nr = n - 1\ns = [0, 0]\nturn = 0\nwhile l <= r do\n if a[l] >= a[r] then\n s[turn] += a[l]\n l += 1\n else\n s[turn] += a[r]\n r -= 1\n end\n turn = 1 - turn\nend\nputs s[0].to_s + ' ' + s[1].to_s\n"}, {"source_code": "n = gets.chomp.to_i;\narr = gets.chomp.split(' ').map(&:to_i);\n\ni, j = 0, n - 1;\nans = [0, 0];\ncount = 0;\n\nn.times {\n if (arr[i] > arr[j])\n ans[count] += arr[i];\n i += 1;\n else\n ans[count] += arr[j];\n j -= 1;\n end\n count = 1 - count;\n}\n# print ans , \"\\n\";\nputs ans;"}, {"source_code": "n = gets.to_i\ncards = gets.split.map(&:to_i)\nsereja = 0\ndima = 0\nturn = 1\nuntil cards.size == 0\n\tif turn == 1\n\t\tif cards[0] > cards[-1]\n\t\t\tsereja += cards[0]\n\t\t\tcards.shift\n\t\telse\n\t\t\tsereja += cards[-1]\n\t\t\tcards.pop\n\t\tend\n\telse\n\t\tif cards[0] > cards[-1]\n\t\t\tdima += cards[0]\n\t\t\tcards.shift\n\t\telse\n\t\t\tdima += cards[-1]\n\t\t\tcards.pop\n\t\tend\n\tend\n\tturn *= -1\nend\n\nputs \"#{sereja} #{dima}\""}, {"source_code": "#!/usr/bin/ruby\n\ngets\na = gets.split.map(&:to_i)\n\nseq = []\nwhile a.size > 0\n if a.first > a.last\n seq << a.shift\n else\n seq << a.pop\n end\nend\n\nif seq.size % 2 == 1\n seq << 0\nend\n\ns1 = 0\ns2 = 0\nwhile seq.size > 0\n s1 += seq.shift\n s2 += seq.shift\nend\n\nputs \"#{s1} #{s2}\"\n"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\nans = Array.new(2, 0)\nl, r, turn = 0, n - 1, 0\nwhile l <= r do\n if a[l] > a[r]\n ans[turn] += a[l]\n l += 1\n else\n ans[turn] += a[r]\n r -= 1\n end\n turn = 1 - turn\nend\nputs [ans[0], ans[1]].join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\ns=[0]*2\nc=0\nwhile ca[-1] ? a.shift : a.pop\n c+=1\nend\nputs s*' '\n"}, {"source_code": "def run\n n = $stdin.gets.to_i\n a = $stdin.gets.split.map(&:to_i)\n s = [0, 0]\n c = 0\n while a.length > 0\n s[c % 2] += a[0] > a[-1] ? a.shift : a.pop\n c += 1\n end\n puts s.join(\" \")\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.to_i \narr = gets.split(\" \").map(&:to_i)\nans = [0,0]\ntoggle_bit = 0 \nuntil arr.empty?\n if (arr.first > arr.last)\n ans[toggle_bit] += arr.shift \n else \n ans[toggle_bit] += arr.pop \n end \n toggle_bit ^=1 \nend \n\nputs \"#{ans[0]} #{ans[1]}\""}, {"source_code": "# cook your code here\nn = gets.to_i \narr = gets.split(\" \").map(&:to_i)\nsereja = 0 \ndima = 0 \ncount =0\nval =0 \nlen = arr.size-1 \nlast_ind = len \nfirt_ind = 0 \nwhile firt_ind <= last_ind \n if arr[firt_ind] < arr[last_ind] \n val = arr[last_ind]\n last_ind -=1 \n else \n val = arr[firt_ind]\n firt_ind +=1 \n end \n \n \n sereja += val if count ==0 \n dima += val if count == 1 \n if count ==0 \n count = 1 \n else \n count =0 \n end \n \nend \n\nputs \"#{sereja} #{dima}\""}, {"source_code": "class A\n def initialize\n n = gets.chomp.to_i\n cards = gets.chomp.split(' ').map(&:to_i)\n sere = 0\n dima = 0\n turn = 0\n val = 0\n\n until cards.size.zero? do\n val = ( cards.first < cards.last )? cards.pop : cards.shift\n if turn.odd?\n dima += val\n else\n sere += val\n end\n turn += 1\n end\n puts \"#{sere} #{dima}\"\n end\nend\n\nA.new"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nif a%2==0\ns=0\nr=0\n(a/2).times do\nif b[0].to_i > b[ b.length-1].to_i\ns+=b[0].to_i\nb.delete_at(0)\nelse\ns+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nif b[0].to_i>b[b.length-1].to_i\nr+=b[0].to_i\nb.delete_at(0)\nelse\nr+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nend\nelse\ns=0\nr=0\n(a/2).times do\nif b[0].to_i > b[ b.length-1].to_i\ns+=b[0].to_i\nb.delete_at(0)\nelse\ns+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nif b[0].to_i>b[b.length-1].to_i\nr+=b[0].to_i\nb.delete_at(0)\nelse\nr+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nend\ns+=b[0].to_i \nend\n\n\nputs \"#{s} #{r}\""}, {"source_code": "n = gets.to_i\ncs = gets.split.map(&:to_i)\n\ns = 0\nd = 0\nt = 0\nwhile !cs.empty? do\n if cs[0] > cs[-1]\n c = cs.shift\n else\n c = cs.pop\n end\n\n if t % 2 == 0\n s += c\n else\n d += c\n end\n t += 1\nend\n\nputs \"#{s} #{d}\""}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nif a%2==0\ns=0\nr=0\n(a/2).times do\nif b[0].to_i > b[ b.length-1].to_i\ns+=b[0].to_i\nb.delete_at(0)\nelse\ns+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nif b[0].to_i>b[b.length-1].to_i\nr+=b[0].to_i\nb.delete_at(0)\nelse\nr+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nend\nelse\ns=0\nr=0\n(a/2).times do\nif b[0].to_i > b[ b.length-1].to_i\ns+=b[0].to_i\nb.delete_at(0)\nelse\ns+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nif b[0].to_i>b[b.length-1].to_i\nr+=b[0].to_i\nb.delete_at(0)\nelse\nr+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nend\ns+=b[0].to_i \nend\n\n\nputs \"#{s} #{r}\""}, {"source_code": "n=gets.to_i\nx=gets.split.map{|e| e.to_i}\n\ni=0\na=0\nb=0\nwhile !x.empty?\n\tt=0\n\tif x[0] cards.last\n scores[player] += cards.shift\n else\n scores[player] += cards.pop\n end\n player = (player + 1) % 2\nend\n \nputs \"#{scores[0]} #{scores[1]}\"\n"}, {"source_code": "# coding : utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\ncards = gets.split.map(&:to_i)\nsereja, dima = 0, 0 # sereja goes first\n\nwhile !cards.empty?\n # serja\n if cards.first > cards.last\n sereja += cards.shift\n else\n sereja += cards.pop\n end\n\n unless cards.empty?\n # dima\n if cards.first > cards.last\n dima += cards.shift\n else\n dima += cards.pop\n end\n end\nend\n\nputs \"#{sereja} #{dima}\"\n"}, {"source_code": "n = $stdin.gets.to_i\ncards = $stdin.gets.chomp.split(' ').map{|e| e.to_i}\n\npls = [0, 0]\nplnum = 0\nuntil cards.empty?\n d = [cards.first, cards.last].max\n pls[plnum] += d\n cards.delete d\n plnum = plnum == 0 ? 1 : 0\nend\n\nputs pls.join ' '"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nsol = [0, 0]\nn.times do |i|\n if a.first > a.last\n sol[i % 2] += a.first\n a.shift\n else\n sol[i % 2] += a.last\n a.pop\n end\nend\nputs sol.join(\" \")\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nif a%2==0\ns=0\nr=0\n(a/2).times do\nif b[0].to_i > b[ b.length-1].to_i\ns+=b[0].to_i\nb.delete_at(0)\nelse\ns+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nif b[0].to_i>b[b.length-1].to_i\nr+=b[0].to_i\nb.delete_at(0)\nelse\nr+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nend\nelse\ns=0\nr=0\n(a/2).times do\nif b[0].to_i > b[ b.length-1].to_i\ns+=b[0].to_i\nb.delete_at(0)\nelse\ns+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nif b[0].to_i>b[b.length-1].to_i\nr+=b[0].to_i\nb.delete_at(0)\nelse\nr+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nend\ns+=b[0].to_i \nend\n\n\nputs \"#{s} #{r}\""}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nnpoints, i = [0, 0], 0\nwhile a.size > 0\n if a[0] > a[-1]\n npoints[i%2] += a[0]\n a = a[1..-1]\n else\n npoints[i%2] += a[-1]\n a = a[0..-2]\n end\n i += 1\nend\nputs npoints.join(' ')"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nc=0\nb=[0,0]\nwhile a.size>0\n if a[0]>a[-1]\n b[c%2]+=a[0]\n a.shift\n else\n b[c%2]+=a[-1]\n a.pop\n end\n c+=1\nend\nputs b*' '\n\n\n"}], "negative_code": [{"source_code": "n = gets.to_i \narr = gets.split(\" \").map(&:to_i)\narr.sort!\nsereja = 0 \ndima = 0 \ncount =0 \narr.reverse.each do |a| \n sereja += a if count == 0 \n dima +=a if count ==1 \n if count == 0 \n count = 1 \n else \n count =0 \n end \n \n \nend \nputs \"#{sereja} #{dima}\""}, {"source_code": "# cook your code here\nn = gets.to_i \narr = gets.split(\" \").map(&:to_i)\narr.sort!\nsereja = 0 \ndima = 0 \narr.each_with_index do |a,ind|\n if ind.even? \n dima += a \n else \n sereja +=a \n end \n \nend \nputs \"#{dima} #{sereja}\""}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nif a%2==0\ns=0\nr=0\n(a/2).times do\nif b[0].to_i > b[ b.length-1].to_i\ns+=b[0].to_i\nb.delete_at(0)\nelse\ns+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nif b[0].to_i>b[b.length-1].to_i\nr+=b[0].to_i\nb.delete_at(0)\nelse\nr+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nend\nelse\ns=0\nr=0\n(a/2).times do\nif b[0].to_i > b[ b.length-1].to_i\ns+=b[0].to_i\nb.delete_at(0)\nelse\ns+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nif b[0].to_i>b[b.length-1].to_i\nr+=b[0].to_i\nb.delete_at(0)\nelse\nr+=b[b.length-1].to_i\nb.delete_at(b.length-1)\nend\nend\ns+=b[0].to_i \nend\n"}, {"source_code": "def solution(n, cards) \n l, sereja, dima = 0, 0, 0\n r = n-1\n while (l <= r ) do \n \n if cards[l] > cards [r]\n sereja += cards[l]\n l += 1\n else\n sereja += cards[r]\n r -= 1\n end\n if cards[l] > cards[r]\n dima += cards[l] if l < n \n l += 1\n else\n dima += cards[r] if r >0\n r -= 1\n end\n end\n puts \"#{sereja} #{dima}\"\nend\n\nsolution(gets.chomp.to_i, gets.split.map(&:to_i))"}, {"source_code": "gets\ncards = gets.split.map(&:to_i).sort.each_slice(2)\nresult = cards.inject { |a, b|\n a[0] += b[0]\n a[1] += b[1].to_i\n a\n}\n# p result\nputs result.sort.reverse.join ' '\n"}, {"source_code": "gets\ncards = gets.split.map(&:to_i)\nresult = [0, 0]\ni = 0\nuntil cards.empty?\n if cards.first > cards.last\n result[i] += cards.shift\n else\n result[i] += cards.pop\n end\n i += 1\n i %= 2\nend\nputs result.sort.reverse.join ' '\n"}], "src_uid": "a7e98ed8ee1b0a4fd03dfcd222b68c6f"} {"source_code": "def m1 n\n\tn%2==0 ? 1 : -1\nend\nn,j=gets.split.map(&:to_i)\nx,y=gets.split.map(&:to_i)\na=[]\nn.times{a<= a[i] - x && b[j] <= a[i] + y\n result << [i + 1, j + 1]\n i += 1\n j += 1\n elsif b[j] < a[i] + y\n j += 1\n else\n i += 1\n end\nend\n\nputs result.length\nresult.each do |pair|\n print pair[0], \" \", pair[1], \"\\n\"\nend\n"}], "negative_code": [{"source_code": "n, m, x, y = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nb = gets.split.map(&:to_i)\n\nres = []\n(0...n).each do |i|\n res.push (0...m).find_all {|j| a[i]-x <= b[j] and b[j] <= a[i]+y }\nend\ntaken = []\nputs [res.flatten.uniq.size, m].min\nres.each_with_index do |e, i|\n next if e.size.zero?\n jj = (0...e.size).find { |j| !taken.include?(e[j]) }\n next if jj.nil? or e[jj].nil?\n puts \"#{i+1} #{e[jj]+1}\"\n taken.push e[jj]\nend"}], "src_uid": "c6bbb16b1a3946ce38e67dc4824ecf89"} {"source_code": "# ProblemA.rb\n\nn, a, b = gets.split().map {|s| s.to_i}\nchores = gets.split().map {|s| s.to_i}\n\nchores = chores.sort\n\nvasya = chores[0...b]\npetya = chores[b..-1]\n\nif petya.index(vasya[-1]) || vasya.index(petya[0])\n puts \"0\"\n exit\nend\n\nputs petya[0] - vasya[-1] \n\n", "positive_code": [{"source_code": "chore_number, petya_chore_number, vasya_chore_number = gets.split(' ').map(&:to_i)\n\nchores = gets.split(' ').map(&:to_i).sort\n\nputs chores[chore_number - petya_chore_number] - chores[vasya_chore_number - 1]\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]\n\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]\n\n"}, {"source_code": "n, a, b = gets.rstrip.split(' ').map(&:to_i)\narr = gets.rstrip.split.map(&:to_i)\n\nsorted_arr = arr.sort\n\nb_last_chore = b - 1\nb_chore = sorted_arr[b_last_chore]\n\na_chores = []\ni = b_last_chore + 1\na.times do\n a_chores.push sorted_arr[i]\n i += 1\nend\n\n\ndiff = a_chores.first - b_chore\nputs diff\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]"}, {"source_code": "def chores\n chores = STDIN.gets.split(' ').map{|i| i.to_i}\n c = STDIN.gets.split(' ').map{|i| i.to_i}\n c.sort!\n\n max = c[c.size-chores[1]]\n\n n = max\n (c.size-chores[1]).downto(0) do |i|\n if c.select{|j| j > c[i]}.size > chores[1]\n break\n else\n n = c[i]\n end\n end\n puts max - n\nend\n\n#plant\n\nchores"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]\n\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]"}, {"source_code": "n, a, b = gets.split.collect{|i| i.to_i}\nvalues = gets.split.collect{|i| i.to_i}.sort\n\nif values[b-1] == values[b]\n puts 0\nelse\n puts values[b] - values[b-1]\nend"}, {"source_code": "n, a, b = gets.chomp.split.map(&:to_i)\nlist = gets.chomp.split.map(&:to_i).sort\n\nlist[n - a]\nlist[n - a - 1]\n\nx = list[n - a] - list[n - a - 1]\nputs x > 0 ? x : 0\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]\n\n"}, {"source_code": "s = gets.chomp.split(\" \")\nkolvo = s[0].to_i\na = s[1].to_i\nb = s[2].to_i\np = gets.chomp.split(\" \")\nmassiv = Array.new(kolvo){}\nfor i in(0..kolvo-1)\n massiv[i] = p[i].to_i\nend\nmassiv = massiv.sort\nif massiv[b]-massiv[b-1]!=0 then\n k = massiv[b]-massiv[b-1]\n puts k\nelse \n puts 0\nend\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]\n\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]\n\n"}, {"source_code": "def execute(n, a, b, h)\n h.sort! {|x, y| x <=> y }\n x = h[n - a] - h[b - 1]\nend\n\n# puts execute(5, 2, 3, %w(6 2 3 100 1).map(&:to_i))\n# puts execute(7, 3, 4, %w(1 1 9 1 1 1 1).map(&:to_i))\nn, a, b = gets.chomp.split(' ').map(&:to_i)\nh = gets.chomp.split(' ').map(&:to_i)\nputs execute(n, a, b, h)\n"}, {"source_code": "n,a,b = gets.chomp.split(/ /).map!{|x| x.to_i}\nh = gets.chomp.split(/ /).map!{|x| x.to_i}\nh.sort!()\nret = h[b] - h[b-1]\nputs ret\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b, a].min - c[0, b].max\n"}, {"source_code": "def checks(n_a_b, h)\n\tn_a_b = n_a_b.split.map(&:to_i)\n\tn = n_a_b[0]\n\ta = n_a_b[1]\n\tb = n_a_b[2]\n\n\th = h.split.map(&:to_i)\n\n\th.sort!\n\n\tn_a = h.last(a)\n\tn_e = h.first(b)\n\n\t\n\n\tputs n_a.first - n_e.last\nend\n\nchecks(gets, gets)\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]\n\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]\n\n"}, {"source_code": "I = ->{gets.split.map(&:to_i)}\nn, a, b = I[]\nc = I[].sort\np c[b] - c[b - 1]\n"}, {"source_code": "n,b,c=gets.chomp.split.map(&:to_i)\na=gets.chomp.split.map(&:to_i)\ni=1\nwhile i=0\n\t\tif a[j] y }\n puts h.inspect # [1, 2, 3, 6, 100]\n x = h[n - a] - h[b - 1]\nend\n\n# puts execute(5, 2, 3, %w(6 2 3 100 1).map(&:to_i))\n# puts execute(7, 3, 4, %w(1 1 9 1 1 1 1).map(&:to_i))\nn, a, b = gets.chomp.split(' ').map(&:to_i)\nh = gets.chomp.split(' ').map(&:to_i)\nputs execute(n, a, b, h)\n"}, {"source_code": "def checks(n_a_b, h)\n\tn_a_b = n_a_b.split.map(&:to_i)\n\tn = n_a_b[0]\n\ta = n_a_b[1]\n\tb = n_a_b[2]\n\n\th = h.split.map(&:to_i)\n\n\th.sort!\n\n\tn_a = h.last(a)\n\tn_e = h.first(b)\n\n\tx = n_a.first - 1\n\n\tcount = 0\n\tfor i in (0..n - 1)\n\t\tif x < n_a.first && x >= n_e.last\n\t\t\tx -=1\n\t\tend\n\tend\n\n\tputs 4\nend\n\nchecks(gets, gets)\n"}, {"source_code": "def checks(n_a_b, h)\n\tn_a_b = n_a_b.split.map(&:to_i)\n\tn = n_a_b[0]\n\ta = n_a_b[1]\n\tb = n_a_b[2]\n\n\th = h.split.map(&:to_i)\n\n\th.sort!\n\n\tn_a = h.last(a)\n\tn_e = h.first(b)\n\n\tx = n_a.first - 1\n\t\n\tcount = 0\n\tfor i in (0..n - 1)\n\t\tif x < n_a.first && x >= n_e.last\n\t\t\tx -=1\n\t\t\tcount += 1\n\t\tend\n\tend\n\n\tputs count\nend\n\nchecks(gets, gets)\n"}, {"source_code": "def checks(n_a_b, h)\n\tn_a_b = n_a_b.split.map(&:to_i)\n\tn = n_a_b[0]\n\ta = n_a_b[1]\n\tb = n_a_b[2]\n\n\th = h.split.map(&:to_i)\n\n\th.sort!\n\n\tputs h[n - a] - h[a]\nend\n\nchecks(gets, gets)\n"}, {"source_code": "def chores\n chores = STDIN.gets.split(' ').map{|i| i.to_i}\n c = STDIN.gets.split(' ').map{|i| i.to_i}\n c.sort!\n\n max = c[c.size-chores[1]]\n min = max\n\n (c.size-chores[1]).downto(0) do |i|\n if c[i] > min\n break\n else\n min -= 1\n end\n end\n puts max-min-1\nend\n\nchores"}], "src_uid": "d3c8c1e32dcf4286bef19e9f2b79c8bd"} {"source_code": "def ans(aa)\n bb = {}\n for v in aa\n bb[v] = 1\n end\n\n tt = []\n for v in (0..aa.length)\n bb[v].nil? and tt << v\n end\n\n t =aa.first\n ret = []\n ti = 0\n aa.each {|e|\n if e != t\n ret << t\n else\n ret << tt[ti]\n ti+=1\n end\n t =e \n }\n\n ret\nend\n\n\ngets\na = gets.chomp.split(' ').map &:to_i\nputs ans(a).join(' ')\n", "positive_code": [{"source_code": "def ans(aa)\n bb = {}\n for v in aa\n bb[v] = 1\n end\n\n tt = []\n for v in (0..aa.length)\n bb[v].nil? and tt << v\n end\n\n t =aa.first\n ret = []\n ti = 0\n aa.each {|e|\n if e != t\n ret << t\n else\n ret << tt[ti]\n ti+=1\n end\n t =e \n }\n\n ret\nend\n\n\ngets\na = gets.chomp.split(' ').map &:to_i\nputs ans(a).join(' ')\n"}, {"source_code": "def ans(aa)\n bb = {}\n for v in aa\n bb[v] = 1\n end\n\n tt = []\n for v in (0..aa.length)\n bb[v].nil? and tt << v\n end\n\n t =aa.first\n ret = []\n ti = 0\n aa.each {|e|\n if e != t\n ret << t\n else\n ret << tt[ti]\n ti+=1\n end\n t =e \n }\n\n ret\nend\n\n\ngets\na = gets.chomp.split(' ').map &:to_i\nputs ans(a).join(' ')\n"}], "negative_code": [{"source_code": "def ans(aa)\n bb = {}\n for v in aa\n bb[v] = 1\n end\n\n tt = []\n for v in (0..aa.length)\n bb[v].nil? and tt << v\n end\n\n t = 0\n ret = []\n ti = 0\n aa.each {|e|\n if e != t\n ret << t\n else\n ret << tt[ti]\n ti+=1\n end\n t =e \n }\n\n ret\nend\n\n\ngets\na = gets.chomp.split(' ').map &:to_i\nputs ans(a).join(' ')\n"}, {"source_code": "def ans(aa)\n bb = {}\n for v in aa\n bb[v] = 1\n end\n\n tt = []\n for v in (0..aa.length)\n bb[v].nil? and tt << v\n end\n\n t = 0\n ret = []\n ti = 0\n aa.each {|e|\n if e != t\n ret << t\n else\n ret << tt[ti]\n ti+=1\n end\n t =e\n }\n\n ret\nend\n\n\ngets\na = gets.chomp.split(' ').map &:to_i\nputs ans(a)\n\n"}, {"source_code": "def ans(aa)\n ret = []\n v = aa.first\n vi = 0\n if aa.first == 0\n ret << 1\n elsif aa.first == 1\n ret << 0\n else\n return -1\n end\n retMax = ret.max\n aa.each_with_index {|e,i|\n if e != v\n ret[i]= v\n retMax = [retMax, v].max\n t = ret[vi]\n #printf(\"ret:%s i:%d e:%d\\n\", ret.to_s, i, e)\n if e-v >= i - vi\n t = v + 1\n t == e and t+=1\n end\n (vi+1...i).each { |j|\n ret[j] = [t, e-1].min\n retMax = [retMax, ret[j]].max\n t+=1 \n t == e and t+=1\n }\n retMax < e-1 and return -1\n v = e\n vi = i\n end\n }\n\n while ret.length < aa.length\n ret << ret.last\n end\n return ret\nend\n\ngets\na = gets.chomp.split(\" \").map &:to_i\nputs ans(a)\n"}], "src_uid": "9a31d88a2fcaf8f3d059ef0e74d6e821"} {"source_code": "n = gets.to_i\na = []\nn.times do |i|\n s = gets.chomp\n if a.include?(s)\n puts \"YES\"\n else\n puts \"NO\"\n a.push(s)\n end\nend", "positive_code": [{"source_code": "require 'set'\n\nread = Set.new\n\ngets.to_i.times do\n\tname = gets.chomp;\n\t\n\tputs read.include?(name) ? \"YES\" : \"NO\"\n\t\n\tread.add(name)\nend"}, {"source_code": "n = gets.to_i\ns = [gets.chomp]\nputs 'NO'\n(n - 1).times do\n flag = FALSE\n t = gets.chomp\n s.each do |name|\n if t == name\n puts 'YES'\n flag = TRUE\n break\n end\n end\n if !flag\n puts 'NO'\n s << t\n end\nend"}, {"source_code": "h={}\ngets.to_i.times{s=gets.chomp;puts h[s]?:YES: :NO;h[s]=1}"}, {"source_code": "n = gets.to_i\nnames = []\nn.times do\n s = gets.chomp\n if names.include?(s)\n puts 'YES'\n else\n puts 'NO'\n end\n names << s\nend"}, {"source_code": "n = gets.strip.to_i\nlist = {}\nn.times do\n s = gets.strip\n if list.has_key? s\n puts \"YES\"\n else\n list[s] = 1\n puts \"NO\"\n end\nend\n"}, {"source_code": "n = gets.to_i\nname = {}\nn.times do\n s = gets\n if name[s]\n puts 'YES'\n else\n puts 'NO'\n name[s] = true\n end\nend\n"}, {"source_code": "t = gets.chomp.to_i\narr = []\nt.times do\n\tt = gets.chomp\n\tif arr.include? t\n\t\tputs \"yes\"\n\telse\n\t\tputs \"no\"\n\t\tarr << t\n\tend\nend"}, {"source_code": "n = gets\n\na={}\nb=[]\nfor i in 0..n.to_i-1 do\n value = gets\n b[i]=value\nend\n\nfor i in 0..n.to_i-1 do\n value = b[i]\n if a[value]\n print \"YES\"\n print \"\\n\" if i!=n.to_i-1\n else\n print \"NO\"\n a[value]=1\n print \"\\n\" if i!=n.to_i-1\n end\nend\n"}], "negative_code": [{"source_code": "n = gets\n\na={}\nfor i in 1..n.to_i do\n value = gets\n if a[value]\n p \"YES\"\n else\n p \"NO\"\n a[value]=1\n end\nend\n"}], "src_uid": "7f934f96cbe3990945e5ebcf5c208043"} {"source_code": "n, m = *gets.split(' ').map { |s| s.to_i }\na = []\nn.times do\n a << gets.chomp\nend\n\ndef ok?(a, x1, y1, x2, y2)\n x1.upto(x2) do |i|\n y1.upto(y2) do |j|\n return false if a[i][j] == ?1\n end\n end\n return true\nend\n\nperimeter = -1\n0.upto(n-1) do |x2|\n 0.upto(m-1) do |y2|\n 0.upto(x2) do |x1|\n 0.upto(y2) do |y1|\n p = x2+y2-x1-y1\n next if p <= perimeter\n next unless ok?(a, x1, y1, x2, y2)\n perimeter = p\n end\n end\n end\nend\n\nputs perimeter * 2 + 4\n ", "positive_code": [{"source_code": "n,m = gets.split.map(&:to_i)\nr = Array.new(n){gets.split ''}\na = 4\nfor i in 0...n\nfor j in 0...m\n next if r[i][j]=='1'\n for ii in i...n\n break if r[ii][j]=='1'\nper = 2*(2+ii-i)\na=per if per>a\n for jj in (j+1)...m\n break unless for iii in i..ii\n break if r[iii][jj]=='1'\n end\n per = 2*((1+ii-i)+(1+jj-j))\n a=per if per>a\n end\n end\nend\nend\np a"}], "negative_code": [{"source_code": "n,m = gets.split.map(&:to_i)\nr = Array.new(n){gets.split ''}\na = 4\nfor i in 0...n\nfor j in 0...m\n next if r[i][j]=='1'\n for ii in (i+1)...n\n break if r[ii][j]=='1'\n for jj in (j+1)...m\n break unless for iii in i..ii\n break nil if r[iii][jj]=='1'\n end\n per = 2*((1+ii-i)+(1+jj-j))\n a=per if per>a\n end\n end\nend\nend\np a"}, {"source_code": "n,m = gets.split.map(&:to_i)\nr = Array.new(n){gets.split ''}\na = 4\nfor i in 0...n\nfor j in 0...m\n next if r[i][j]=='1'\n for ii in (i+1)...n\nper = 2*((1+ii-i)+1)\na=per if per>a\n break if r[ii][j]=='1'\n for jj in (j+1)...m\n break unless for iii in i..ii\n break nil if r[iii][jj]=='1'\n end\n per = 2*((1+ii-i)+(1+jj-j))\n a=per if per>a\n end\n end\nend\nend\np a"}], "src_uid": "99f1db0155f3d6dd580a2c1479c34585"} {"source_code": "a=gets.chomp.to_i\nb=[]\na.times do\ntemp=gets.chomp.split(\" \")\nc=(temp[2].to_i-temp[0].to_i+1)*(temp[3].to_i-temp[1].to_i+1)\nb< Made With LOVE <3 <==\n\nn = gets.to_i\nsum=0\n\nn.times do\n\tx1, x2, y1, y2 = gets.split.map(&:to_i) \n\tsum += (y1 - x1 + 1) * (y2 - x2 + 1)\nend\n\nputs sum\n"}, {"source_code": "rectangleNum = gets.chomp.to_i\nrectangle = []\n\n\n(0...rectangleNum).each do |iter|\n\trectangle << gets.chomp.split(' ').map {|item| item.to_i}\nend\n\nresult = 0\nrectangle.each do |rec|\n\tresult += (rec[2] - rec[0] + 1) * (rec[3] - rec[1] + 1)\nend\n\n\nputs result"}, {"source_code": "a=gets.chomp.to_i\nb=[]\na.times do\ntemp=gets.chomp.split(\" \")\nc=(temp[2].to_i-temp[0].to_i+1)*(temp[3].to_i-temp[1].to_i+1)\nb< secondRec[2]\n\tfirstRec[2]\nelse\n\tsecondRec[2]\nend\n\nmaxY = if firstRec[3] > secondRec[3]\n\tfirstRec[3]\nelse\n\tsecondRec[3]\nend\n\n(1..maxY).each do |y|\n\t(1..maxX).each do |x|\n\t\tif x >= firstRec[0] && x <= firstRec[2] && y >= firstRec[1] && y <= firstRec[3]\n\t\t\tresult += 1\n\t\tend\n\n\t\tif x >= secondRec[0] && x <= secondRec[2] && y >= secondRec[1] && y <= secondRec[3]\n\t\t\tresult += 1\n\t\tend\n\tend\nend\n\nputs result"}], "src_uid": "ca5c44093b1ab7c01970d83b5f49d0c6"} {"source_code": "gets.to_i.times do\r\n a, b = gets.split.map(&:to_i)\r\n if a > b\r\n puts \"10\" * b + \"0\" * (a - b)\r\n else\r\n puts \"01\" * a + \"1\" * (b - a)\r\n end\r\nend\r\n", "positive_code": [{"source_code": "# gets.to_i\r\n# gets.split.map(&:to_i)\r\n\r\ngets.to_i.times do\r\n a, b = gets.split.map(&:to_i)\r\n if a > b\r\n ans = Array.new(a+b, 0)\r\n i = 0\r\n while b > 0\r\n ans[i] = 1\r\n i += 2\r\n b -= 1\r\n end\r\n else\r\n ans = Array.new(a+b, 1)\r\n i = 0\r\n while a > 0\r\n ans[i] = 0\r\n i += 2\r\n a -= 1\r\n end\r\n end\r\n\r\n puts ans.join\r\nend\r\n\r\n"}, {"source_code": "gets.to_i.times do\n a, b = gets.split.map(&:to_i)\n\n s = \"\"\n while a + b > 0\n if a > 0\n s += '0'\n a -= 1\n end\n\n if b > 0\n s += '1'\n b -= 1\n end\n end\n\n puts s\nend\n"}, {"source_code": "gets.to_i.times do\n a, b = gets.split.map(&:to_i)\n d = [(a - b).abs, 1].max\n\n s = \"\"\n while a + b > 0\n ta = a - [a - d, 0].max\n tb = b - [b - d, 0].max\n s += '0' * ta\n s += '1' * tb\n a -= ta\n b -= tb\n end\n\n puts s\nend\n"}], "negative_code": [], "src_uid": "7767e47571c7ea82ba4fb6a0bd0fbdc5"} {"source_code": "file = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nt = file.gets.to_i\n\nwhile t != 0\n n = file.gets.to_i\n ans = n / 2\n if ans == 0 || ans == 1\n puts n == 2 ? 0 : ans\n else\n res = if n.even? \n (ans - 1) <= 0 ? 0 : ans-1\n else \n ans\n end \n puts res\n end\n t -= 1\nend\n\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n n = gets.chomp.to_i\n n-=1 if n%2 == 0\n puts n/2\nend\n"}, {"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\tputs (n - 1) / 2\nend\n"}, {"source_code": "t = gets.to_i\nt.times do\n\tn = gets.to_i\n\tputs n-n/2-1\nend"}, {"source_code": "\nt = gets.to_i\nfor i in 1..t do\n n = gets.to_i\n puts n - (n/2 + 1)\nend\n"}, {"source_code": "t = gets.chomp.to_i\n\n(1..t).each{\n n = gets.chomp.to_i\n \n puts (n-1)/2\n}"}, {"source_code": "# https://codeforces.com/problemset/problem/1335/A\ndef solution(n)\n return (n / 2.0).ceil - 1\nend\n\nt = gets.chomp.to_i\n\nwhile t > 0 do\n puts solution(gets.chomp.to_i)\n t -= 1\nend\n"}, {"source_code": "gets.to_i.times do\n n = gets.to_i\n puts (n - 1)/2\nend\n"}, {"source_code": "t = gets.to_i\n\n1.upto(t) do\n n = gets.to_i\n puts n.div(2) - 1 + n.modulo(2)\nend\n"}, {"source_code": "t = gets.to_i\n(1).upto(t) do\n n = gets.to_i\n puts (n-1)/2\nend\n"}], "negative_code": [{"source_code": "file = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nt = file.gets.to_i\n\nwhile t != 0\n n = file.gets.to_i\n ans = n / 2\n if ans == 0 || ans == 1\n puts n == 2 ? 0 : ans\n else\n res = if ans.even? \n (ans - 1) <= 0 ? 0 : ans-1\n else \n ans\n end \n puts res\n end\n t -= 1\nend\n\n"}, {"source_code": "file = File.exist?('in.in') ? File.new('in.in','r') : STDIN\n\nt = file.gets.to_i\n\nwhile t != 0\n n = file.gets.to_i\n ans = n / 2\n res = if ans.even? \n (ans - 1) <= 0 ? 0 : ans-1\n else \n ans\n end \n puts res\n t -= 1\nend\n\n"}], "src_uid": "b69170c8377623beb66db4706a02ffc6"} {"source_code": "n = gets.to_i\nsum = 0\n\narr = gets.split(\" \").map(&:to_i).sort\narea = arr.map { |e| e * e * Math::PI }\n\nif n.even?\n\tstart = 1 \nelse\n\tsum += area[0]\n\tstart = 2\nend\n\n(start..(n-1)).step(2).each do |i|\n\tsum += area[i] - area[i-1]\nend\nputs sum", "positive_code": [{"source_code": "n = gets.to_i\na = Array.new\ns = gets.split(' ')\nfor i in 0..n-1\n a[i] = s[i].to_i\nend\na = a.sort\na = a.reverse\nans = 0\n0.step(n-2, 2) { |i|\n ans += a[i] * a[i] - a[i+1] * a[i+1]\n}\nif n % 2 == 1\n ans += a[n-1] * a[n-1]\nend\nputs ans * Math::PI\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i).sort.reverse\nans = 0\n0.step(n-2, 2) { |i|\n ans += a[i] * a[i] - a[i+1] * a[i+1]\n}\nans += a[n-1] * a[n-1] if n % 2 == 1\np ans * Math::PI\n"}, {"source_code": "def area rad\n\tMath::PI * rad * rad\nend\n\nn = STDIN.gets.chomp.to_i\nradius = STDIN.gets.chomp.split(' ').map{|ch| ch.to_i}.sort\ntotal = 0.0\nnum = 0\n(n - 1).downto(0).each do |i|\n\tif num % 2 == 0\n\t\ttotal += area radius[i]\n\telse\n\t\ttotal -= area radius[i]\n\tend\n\tnum += 1\nend\n\nputs total"}, {"source_code": "def area rad\n\tMath::PI * rad * rad\nend\n\nn = STDIN.gets.chomp.to_i\nradius = STDIN.gets.chomp.split(' ').map{|ch| ch.to_i}.sort\ntotal = 0.0\nnum = 0\n(n - 1).downto(0).each do |i|\n\ttotal += (num % 2 == 0) ? area(radius[i]) : -(area radius[i])\n\tnum += 1\nend\n\nputs total"}, {"source_code": "n = gets.to_i\nr = gets.split.map &:to_i\nr << 0 if r.size.odd?\ns = 0\nr.sort.each_slice(2) do |x, y|\n s += y**2 - x**2\nend\np s * Math::PI\n"}, {"source_code": "n = gets.to_i\nrads = gets.split.map{|i| i.to_i}.sort\n\ns = 0\nif rads.size % 2 == 0 then\n i = 0\n while 2*i < rads.size do\n s += (rads[2*i+1]**2 - rads[2*i]**2)\n i += 1\n end\nelse\n i = 1\n s += rads[0]**2 \n while 2*i < rads.size\n s += (rads[2*i]**2 - rads[2*i-1]**2)\n i += 1\n end\nend\n\ns *= Math::PI\n\nputs s"}, {"source_code": "#!/usr/bin/ruby\ngets;p gets.split.map(&:to_i).sort.reverse.each_with_index.map{|e,i|(-1)**i*Math::PI*e**2}.reduce(:+)"}, {"source_code": "gets\np Math::PI * gets.split.map{|_| _.to_f ** 2}.sort.inject{|i, j| j - i}\n"}, {"source_code": "n = gets.to_i\nr = gets.split.map(&:to_i).sort.reverse\n\nback = 0\nans = 0\nr.each do |x|\n if back b)}\n\nsum = 0.0\nfor i in 0..(n - 1) do\n if (i % 2 != 0)\n next\n end\n\n if (i + 1 >= n)\n sum += r[i] ** 2 * Math::PI\n else \n sum += (r[i] ** 2 - r[i + 1] ** 2) * Math::PI\n end\nend\nputs sum\n\n\n"}, {"source_code": "gets\np Math::PI * gets.split.map{|_| _.to_f ** 2}.sort.inject{|i, j| j - i}\n\n"}, {"source_code": "gets\np Math::PI * gets.split.map{|_| _.to_f ** 2}.sort.inject{|i, j| j - i}\n"}, {"source_code": "n=gets.to_i\nr=gets.chomp.split.map(&:to_i).sort.reverse\ni,sign,ans=0,1,0\nwhile ia }.map { |r| Math::PI*r*r }.each_with_index.inject(0){ |sum, (value,index)| index.even? ? sum + value : sum - value }"}, {"source_code": "gets\np Math::PI * gets.split.map{|_| _.to_f ** 2}.sort.inject{|i, j| j - i}\n\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\ngets;p gets.split.each_with_index.map{|e,i|e.to_i**(-1*i)*Math::PI}.reduce(:+)"}, {"source_code": "#!/usr/bin/ruby\ngets;p gets.split.map(&:to_i).sort.reverse.each_with_index.map{|e,i|(e*e)**(-1*i)*Math::PI}.reduce(:+)"}, {"source_code": "#!/usr/bin/ruby\ngets;p gets.split.each_with_index{|e,i|e.to_i**(-1*i)*Math::PI}.reduce(:+)"}, {"source_code": "#!/usr/bin/ruby\ngets;p gets.split.map(&:to_i).sort.reverse.each_with_index.map{|e,i|e**2**(-1*i)*Math::PI}.reduce(:+)"}, {"source_code": "#!/usr/bin/ruby\ngets;p gets.split.each_with_index.map{|e,i|e.to_i**2**(-1*i)*Math::PI}.reduce(:+)"}, {"source_code": "#!/usr/bin/ruby\ngets;p gets.split.each_with_index.map{|e,i|(e.to_i**2)**(-1*i)*Math::PI}.reduce(:+)"}, {"source_code": "gets\np Math::PI * gets.split.map{|_| _.to_f ** 2}.sort.reverse.inject{|i, j| j - i}\n"}, {"source_code": "n = gets.to_i\nr = gets.split.map(&:to_i)\n\nback = 0\nans = 0\nr.each do |x|\n if back 0 && (c == ')' || c == ']') && rev[c] == st.last[1])\n seq.push(st.last)\n seq.push([i, c])\n st.pop\n else\n while (st.size() > 0)\n st.pop\n end\n end\n i += 1\nend\nseq.sort!\nres = \"\", mx = -1, prv = -1, c = 0, t = \"\"\nfor i in seq\n # puts \"#{i[0]} #{i[1]}\"\n if (i[0] - prv == 1)\n c += 1 if (i[1] == '[')\n t << i[1]\n else\n if (mx < c)\n mx = c\n res = t.dup\n end\n t.clear\n c = 0\n c += 1 if (i[1] == '[')\n t << i[1]\n end\n prv = i[0]\nend\n\nif (mx < c)\n mx = c\n res = t.dup\nend\nputs mx, res\n\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\ns = STDIN.readline.strip + '$'\nparens, brackets = [], []\nleft, right = 0, 0\ncount, best_count = 0, 0\nbest_left, best_right = 1, 0\nwhile right < s.length\n\t#puts 'left = %d, right = %d, count = %d, brackets = %s, parens = %s' % [\n\t#\t\tleft, right, count, brackets, parens]\n\tch = s[right]\n\terror = false\n\tif ch == '('\n\t\tparens.push(right)\n\telsif ch == '['\n\t\tbrackets.push(right)\n\t\tcount += 1\n\telsif ch == ')'\n\t\tif parens.length == 0\n\t\t\terror = true\n\t\telsif brackets.length != 0 and brackets[-1] > parens[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tparens.pop\n\t\tend\n\telsif ch == ']'\n\t\tif brackets.length == 0\n\t\t\terror = true\n\t\telsif parens.length != 0 and parens[-1] > brackets[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tbrackets.pop\n\t\tend\n\telse\n\t\terror = true\n\tend\n\tif not error\n\t\tif parens.length == 0 and brackets.length == 0\n\t\t\tif count > best_count\n\t\t\t\tbest_count, best_left, best_right = count, left, right\n\t\t\tend\n\t\tend\n\t\tright += 1\n\telse\n\t\tnext_left = right+1\n\n\t\t# find the longest correct substring preceding the error\n\t\tright -= 1\n\t\tseek = right\n\t\tb, p, count = 0, 0, 0\n\t\twhile seek >= left\n\t\t\tch = s[seek]\n\t\t\tif ch == '['\n\t\t\t\tb -= 1\n\t\t\t\tcount += 1\n\t\t\telsif ch == ']'\n\t\t\t\tb += 1\n\t\t\telsif ch == '('\n\t\t\t\tp -= 1\n\t\t\telsif ch == ')'\n\t\t\t\tp += 1\n\t\t\tend\n\t\t\tif b == 0 and p == 0 and count > best_count\n\t\t\t\tbest_count, best_left, best_right = count, seek, right\n\t\t\tend\n\t\t\tif b < 0 or p < 0\n\t\t\t\tb, p, count = 0, 0, 0\n\t\t\t\tright = seek-1\n\t\t\tend\n\t\t\tseek -= 1\n\t\tend\n\t\t\n\t\tparens, brackets = [], []\n\t\tleft = right = next_left\n\t\tcount = 0\n\tend\nend\nputs best_count\nputs s[best_left..best_right]\n"}, {"source_code": "s = gets.chomp\nst = []\nseq = []\nrev = {}\nrev[')'] = '('\nrev[']'] = '['\ni = 0\ns.each_char do |c|\n if (c == '(' || c == '[')\n st.push([i, c])\n elsif (st.size() > 0 && (c == ')' || c == ']') && rev[c] == st.last[1])\n seq.push(st.last)\n seq.push([i, c])\n st.pop\n else\n while (st.size() > 0)\n st.pop\n end\n end\n i += 1\nend\nseq.sort!\nres = \"\", mx = -1, prv = -1, c = 0, t = \"\"\nfor i in seq\n if (i[0] - prv == 1)\n c += 1 if (i[1] == '[')\n t.concat(i[1])\n else\n if (mx < c)\n mx = c\n res = t.dup\n end\n t.clear\n c = 0\n c += 1 if (i[1] == '[')\n t.concat(i[1])\n end\n prv = i[0]\nend\n\nif (mx < c)\n mx = c\n res = t.dup\nend\nputs mx, res\n\n"}, {"source_code": "A,B,C,D=[?[,?],?(,?)].map(&:ord)\ndef match(c,d)\n\treturn 1 if (c==A)&&(d==B)\n\treturn 0 if (c==C)&&(d==D)\n\tfalse\nend\nt=gets.chomp\ns=t.bytes.each_with_index.map.to_a\nsize=s.size\ntable=Array.new(size+1)\nstack=[]\ns.each{|chr|\n\tord,idx=chr\n\tif (ord==A)||(ord==C)||stack.empty?\n\t\tstack.push chr\n\telse\n\t\tif m=match(stack.last.first,ord)\n\t\t\t_ord,_idx=stack.pop\n\t\t\ttable[idx]=0\n\t\t\ttable[_idx]=m\n\t\telse\n\t\t\tstack.push chr\n\t\tend\n\tend\n}\nmax=0\nsum=0\n_l=l=r=0\ntable.each_with_index{|n,idx|\n\tif n\n\t\tsum+=n\n\telse\n\t\tif sum>max\n\t\t\tmax=sum\n\t\t\tl=_l\n\t\t\tr=idx-1\n\t\tend\n\t\tsum=0\n\t\t_l=idx+1\n\tend\n}\nputs max\nputs max==0 ? \"\" : t[l..r]"}, {"source_code": "s = gets.chomp\nst = []\nseq = []\nrev = {}\nrev[')'] = '('\nrev[']'] = '['\ni = 0\ns.each_char do |c|\n if (c == '(' || c == '[')\n st.push([i, c])\n elsif (st.size() > 0 && (c == ')' || c == ']') && rev[c] == st.last[1])\n seq.push(st.last)\n seq.push([i, c])\n st.pop\n else\n while (st.size() > 0)\n st.pop\n end\n end\n i += 1\nend\nseq.sort!\nres = \"\", mx = -1, prv = -1, c = 0, t = \"\"\nfor i in seq\n # puts \"#{i[0]} #{i[1]}\"\n if (i[0] - prv == 1)\n c += 1 if (i[1] == '[')\n t << i[1]\n else\n if (mx < c)\n mx = c\n res = t.dup\n end\n t = \"\"\n c = 0\n c += 1 if (i[1] == '[')\n t += i[1]\n end\n prv = i[0]\nend\n\nif (mx < c)\n mx = c\n res = t.dup\nend\nputs mx, res\n\n"}, {"source_code": "s = gets.chomp\nst = []\nseq = []\nrev = {}\nrev[')'] = '('\nrev[']'] = '['\ni = 0\ns.each_char do |c|\n if (c == '(' || c == '[')\n st.push([i, c])\n elsif (st.size() > 0 && (c == ')' || c == ']') && rev[c] == st.last[1])\n seq.push(st.last)\n seq.push([i, c])\n st.pop\n else\n while (st.size() > 0)\n st.pop\n end\n end\n i += 1\nend\nseq.sort!\nres = \"\", mx = -1, prv = -1, c = 0, t = \"\"\nfor i in seq\n # puts \"#{i[0]} #{i[1]}\"\n if (i[0] - prv == 1)\n c += 1 if (i[1] == '[')\n t << i[1]\n else\n if (mx < c)\n mx = c\n res = t.dup\n end\n t.clear\n c = 0\n c += 1 if (i[1] == '[')\n t += i[1]\n end\n prv = i[0]\nend\n\nif (mx < c)\n mx = c\n res = t.dup\nend\nputs mx, res\n\n"}, {"source_code": "#!/usr/bin/ruby\n\ns = STDIN.readline.strip + '$'\nparens, brackets = [], []\nleft, right = 0, 0\nbest_count = 0\nbest_left, best_right = 1, 0\nwhile right < s.length\n\tch = s[right]\n\terror = false\n\tif ch == '('\n\t\tparens.push(right)\n\telsif ch == '['\n\t\tbrackets.push(right)\n\telsif ch == ')'\n\t\tif parens.length == 0\n\t\t\terror = true\n\t\telsif brackets.length != 0 and brackets[-1] > parens[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tparens.pop\n\t\tend\n\telsif ch == ']'\n\t\tif brackets.length == 0\n\t\t\terror = true\n\t\telsif parens.length != 0 and parens[-1] > brackets[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tbrackets.pop\n\t\tend\n\telse\n\t\terror = true\n\tend\n\tif not error\n\t\tright += 1\n\telse\n\t\tnext_left = right+1\n\t\tseek = right = right-1\n\t\tb, p, count = 0, 0, 0\n\t\twhile seek >= left\n\t\t\tch = s[seek]\n\t\t\tif ch == '['\n\t\t\t\tb -= 1\n\t\t\t\tcount += 1\n\t\t\telsif ch == ']'\n\t\t\t\tb += 1\n\t\t\telsif ch == '('\n\t\t\t\tp -= 1\n\t\t\telsif ch == ')'\n\t\t\t\tp += 1\n\t\t\tend\n\t\t\tif b == 0 and p == 0 and count > best_count\n\t\t\t\tbest_count, best_left, best_right = count, seek, right\n\t\t\tend\n\t\t\tif b < 0 or p < 0\n\t\t\t\tb, p, count = 0, 0, 0\n\t\t\t\tright = seek-1\n\t\t\tend\n\t\t\tseek -= 1\n\t\tend\n\t\tparens, brackets = [], []\n\t\tleft = right = next_left\n\tend\nend\nputs best_count\nputs s[best_left..best_right]\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\n\ns = STDIN.readline.strip + '$'\nparens, brackets = [], []\nleft, right = 0, 0\ncount, best_count = 0, 0\nbest_left, best_right = 1, 0\nwhile right < s.length\n\tch = s[right]\n\terror = false\n\tif ch == '('\n\t\tparens.push(right)\n\telsif ch == '['\n\t\tbrackets.push(right)\n\t\tcount += 1\n\telsif ch == ')'\n\t\tif parens.length == 0\n\t\t\terror = true\n\t\telsif brackets.length != 0 and brackets[-1] > parens[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tparens.pop\n\t\tend\n\telsif ch == ']'\n\t\tif brackets.length == 0\n\t\t\terror = true\n\t\telsif parens.length != 0 and parens[-1] > brackets[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tbrackets.pop\n\t\tend\n\telse\n\t\terror = true\n\tend\n\tif not error\n\t\tif parens.length == 0 and brackets.length == 0\n\t\t\tif count > best_count\n\t\t\t\tbest_count, best_left, best_right = count, left, right\n\t\t\tend\n\t\tend\n\t\tright += 1\n\telse\n\t\twhile left != right\n\t\t\tif parens.length == 0 and brackets.length == 0\n\t\t\t\tif count > best_count\n\t\t\t\t\tbest_count, best_left, best_right = count, left, right-1\n\t\t\t\tend\n\t\t\tend\n\t\t\tif s[left] == '('\n\t\t\t\tparens.shift\n\t\t\telsif s[left] == '['\n\t\t\t\tbrackets.shift\n\t\t\t\tcount -= 1\n\t\t\tend\n\t\t\tleft += 1\n\t\tend\n\t\tparens = []\n\t\tbrackets = []\n\t\tleft = right = right+1\n\t\tcount = 0\n\tend\nend\nputs best_count\nputs s[best_left..best_right]\n"}, {"source_code": "#!/usr/bin/ruby\n\ns = STDIN.readline.strip + '$'\nparens, brackets = [], []\nleft, right = 0, 0\ncount, best_count = 0, 0\nbest_left, best_right = 1, 0\nwhile right < s.length\n\tch = s[right]\n\terror = false\n\tif ch == '('\n\t\tparens.push(right)\n\telsif ch == '['\n\t\tbrackets.push(right)\n\t\tcount += 1\n\telsif ch == ')'\n\t\tif parens.length == 0\n\t\t\terror = true\n\t\telsif brackets.length != 0 and brackets[-1] > parens[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tparens.pop\n\t\tend\n\telsif ch == ']'\n\t\tif brackets.length == 0\n\t\t\terror = true\n\t\telsif parens.length != 0 and parens[-1] > brackets[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tbrackets.pop\n\t\tend\n\telse\n\t\terror = true\n\tend\n\tif not error\n\t\tright += 1\n\telse\n\t\twhile left != right\n\t\t\tif parens.length == 0 and brackets.length == 0\n\t\t\t\tif count > best_count\n\t\t\t\t\tbest_count, best_left, best_right = count, left, right-1\n\t\t\t\tend\n\t\t\tend\n\t\t\tif s[left] == '('\n\t\t\t\tparens.shift\n\t\t\telsif s[left] == '['\n\t\t\t\tbrackets.shift\n\t\t\t\tcount -= 1\n\t\t\tend\n\t\t\tleft += 1\n\t\tend\n\t\tleft = right = right+1\n\t\tcount = 0\n\tend\nend\nputs best_count\nputs s[best_left..best_right]\n"}, {"source_code": "#!/usr/bin/ruby\n\ns = STDIN.readline.strip + '$'\nparens, brackets = [], []\nleft, right = 0, 0\ncount, best_count = 0, 0\nbest_left, best_right = 1, 0\nwhile right < s.length\n\t#puts 'left = %d, right = %d, count = %d, brackets = %s, parens = %s' % [\n\t#\t\tleft, right, count, brackets, parens]\n\tch = s[right]\n\terror = false\n\tif ch == '('\n\t\tparens.push(right)\n\telsif ch == '['\n\t\tbrackets.push(right)\n\t\tcount += 1\n\telsif ch == ')'\n\t\tif parens.length == 0\n\t\t\terror = true\n\t\telsif brackets.length != 0 and brackets[-1] > parens[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tparens.pop\n\t\tend\n\telsif ch == ']'\n\t\tif brackets.length == 0\n\t\t\terror = true\n\t\telsif parens.length != 0 and parens[-1] > brackets[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tbrackets.pop\n\t\tend\n\telse\n\t\terror = true\n\tend\n\tif not error\n\t\tif parens.length == 0 and brackets.length == 0\n\t\t\tif count > best_count\n\t\t\t\tbest_count, best_left, best_right = count, left, right\n\t\t\tend\n\t\tend\n\t\tright += 1\n\telse\n\t\tnext_left = right+1\n\n\t\t# find the longest correct substring preceding the error\n\t\tseek = right-1\n\t\tb, p, count = 0, 0, 0\n\t\twhile seek >= left\n\t\t\tch = s[seek]\n\t\t\tif ch == '['\n\t\t\t\tb -= 1\n\t\t\t\tcount += 1\n\t\t\telsif ch == ']'\n\t\t\t\tb += 1\n\t\t\telsif ch == '('\n\t\t\t\tp -= 1\n\t\t\telsif ch == ')'\n\t\t\t\tp += 1\n\t\t\tend\n\t\t\tif b == 0 and p == 0 and count > best_count\n\t\t\t\tbest_count, best_left, best_right = count, seek, right\n\t\t\tend\n\t\t\tif b < 0 or p < 0\n\t\t\t\tb, p, count = 0, 0, 0\n\t\t\tend\n\t\t\tseek -= 1\n\t\tend\n\t\t\n\t\tparens, brackets = [], []\n\t\tleft = right = next_left\n\t\tcount = 0\n\tend\nend\nputs best_count\nputs s[best_left..best_right]\n"}, {"source_code": "#!/usr/bin/ruby\n\ns = STDIN.readline.strip + '('\nparens, brackets = [], []\nleft, right = 0, 0\ncount, best_count = 0, 0\nbest_left, best_right = 1, 0\nwhile right < s.length\n\tch = s[right]\n\tcomplete, error = false, false\n\tif ch == '('\n\t\tparens.push(right)\n\telsif ch == '['\n\t\tbrackets.push(right)\n\t\tcount += 1\n\telsif ch == ')'\n\t\tif parens.length == 0\n\t\t\terror = true\n\t\telsif brackets.length != 0 and brackets[-1] > parens[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tparens.pop\n\t\t\tcomplete = true if parens.length == 0 and brackets.length == 0\n\t\tend\n\telsif ch == ']'\n\t\tif brackets.length == 0\n\t\t\terror = true\n\t\telsif parens.length != 0 and parens[-1] > brackets[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tbrackets.pop\n\t\t\tcomplete = true if parens.length == 0 and brackets.length == 0\n\t\tend\n\tend\n\tif not complete and not error\n\t\tright += 1\n\t\tnext\n\tend\n\tif complete\n\t\tif count > best_count\n\t\t\tbest_count, best_left, best_right = count, left, right\n\t\tend\n\telsif error\n\t\twhile left != right\n\t\t\tif parens.length == 0 and brackets.length == 0\n\t\t\t\tif count > best_count\n\t\t\t\t\tbest_count, best_left, best_right = count, left, right-1\n\t\t\t\tend\n\t\t\tend\n\t\t\tif s[left] == '('\n\t\t\t\tparens.shift\n\t\t\telsif s[left] == '['\n\t\t\t\tbrackets.shift\n\t\t\t\tcount -= 1\n\t\t\tend\n\t\t\tleft += 1\n\t\tend\n\tend\n\tleft = right = right+1\n\tcount = 0\nend\nputs best_count\nputs s[best_left..best_right]\n"}, {"source_code": "#!/usr/bin/ruby\n\ns = STDIN.readline.strip + '$'\nparens, brackets = [], []\nleft, right = 0, 0\ncount, best_count = 0, 0\nbest_left, best_right = 1, 0\nwhile right < s.length\n\tch = s[right]\n\terror = false\n\tif ch == '('\n\t\tparens.push(right)\n\telsif ch == '['\n\t\tbrackets.push(right)\n\t\tcount += 1\n\telsif ch == ')'\n\t\tif parens.length == 0\n\t\t\terror = true\n\t\telsif brackets.length != 0 and brackets[-1] > parens[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tparens.pop\n\t\tend\n\telsif ch == ']'\n\t\tif brackets.length == 0\n\t\t\terror = true\n\t\telsif parens.length != 0 and parens[-1] > brackets[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tbrackets.pop\n\t\tend\n\telse\n\t\terror = true\n\tend\n\tif not error\n\t\tif parens.length == 0 and brackets.length == 0\n\t\t\tif count > best_count\n\t\t\t\tbest_count, best_left, best_right = count, left, right\n\t\t\tend\n\t\tend\n\t\tright += 1\n\telse\n\t\twhile left != right\n\t\t\tif parens.length == 0 and brackets.length == 0\n\t\t\t\tif count > best_count\n\t\t\t\t\tbest_count, best_left, best_right = count, left, right-1\n\t\t\t\tend\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tif s[left] == '('\n\t\t\t\tparens.shift\n\t\t\telsif s[left] == '['\n\t\t\t\tbrackets.shift\n\t\t\t\tcount -= 1\n\t\t\tend\n\t\t\tleft += 1\n\t\tend\n\t\tparens = []\n\t\tbrackets = []\n\t\tleft = right+1\n\t\tright = right+1\n\t\tcount = 0\n\tend\nend\nputs best_count\nputs s[best_left..best_right]\n"}, {"source_code": "#!/usr/bin/ruby\n\ns = STDIN.readline.strip + '$'\nparens, brackets = [], []\nleft, right = 0, 0\ncount, best_count = 0, 0\nbest_left, best_right = 1, 0\nwhile right < s.length\n\t#puts 'left = %d, right = %d, count = %d, brackets = %s, parens = %s' % [\n\t#\t\tleft, right, count, brackets, parens]\n\tch = s[right]\n\terror = false\n\tif ch == '('\n\t\tparens.push(right)\n\telsif ch == '['\n\t\tbrackets.push(right)\n\t\tcount += 1\n\telsif ch == ')'\n\t\tif parens.length == 0\n\t\t\terror = true\n\t\telsif brackets.length != 0 and brackets[-1] > parens[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tparens.pop\n\t\tend\n\telsif ch == ']'\n\t\tif brackets.length == 0\n\t\t\terror = true\n\t\telsif parens.length != 0 and parens[-1] > brackets[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tbrackets.pop\n\t\tend\n\telse\n\t\terror = true\n\tend\n\tif not error\n\t\tif parens.length == 0 and brackets.length == 0\n\t\t\tif count > best_count\n\t\t\t\tbest_count, best_left, best_right = count, left, right\n\t\t\tend\n\t\tend\n\t\tright += 1\n\telse\n\t\tnext_left = right+1\n\n\t\t# find the longest correct substring preceding the error\n\t\tright -= 1\n\t\tright -= 1 while right != left and s[right] != ']'\n\t\tif right != left\n\t\t\tb, p, count = 0, 0, 0\n\t\t\tseek = right\n\t\t\twhile seek >= left\n\t\t\t\tch = s[seek]\n\t\t\t\tif ch == '['\n\t\t\t\t\tb -= 1\n\t\t\t\t\tcount += 1\n\t\t\t\telsif ch == ']'\n\t\t\t\t\tb += 1\n\t\t\t\telsif ch == '('\n\t\t\t\t\tp -= 1\n\t\t\t\telsif ch == ')'\n\t\t\t\t\tp += 1\n\t\t\t\tend\n\t\t\t\tif b == 0 and p == 0 and count > best_count\n\t\t\t\t\tbest_count, best_left, best_right = count, seek, right\n\t\t\t\tend\n\t\t\t\tbreak if b < 0 or p < 0\n\t\t\t\tseek -= 1\n\t\t\tend\n\t\tend\n\t\t\n\t\tparens, brackets = [], []\n\t\tleft = right = next_left\n\t\tcount = 0\n\tend\nend\nputs best_count\nputs s[best_left..best_right]\n"}, {"source_code": "#!/usr/bin/ruby\n\ns = STDIN.readline.strip + '$'\nparens, brackets = [], []\nleft, right = 0, 0\ncount, best_count = 0, 0\nbest_left, best_right = 1, 0\nbest_case = nil\nwhile right < s.length\n\tch = s[right]\n\terror = false\n\tif ch == '('\n\t\tparens.push(right)\n\telsif ch == '['\n\t\tbrackets.push(right)\n\t\tcount += 1\n\telsif ch == ')'\n\t\tif parens.length == 0\n\t\t\terror = true\n\t\telsif brackets.length != 0 and brackets[-1] > parens[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tparens.pop\n\t\tend\n\telsif ch == ']'\n\t\tif brackets.length == 0\n\t\t\terror = true\n\t\telsif parens.length != 0 and parens[-1] > brackets[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tbrackets.pop\n\t\tend\n\telse\n\t\terror = true\n\tend\n\tif not error\n\t\tif parens.length == 0 and brackets.length == 0\n\t\t\tif count > best_count\n\t\t\t\tbest_count, best_left, best_right = count, left, right\n\t\t\t\tbest_case = 0\n\t\t\tend\n\t\tend\n\t\tright += 1\n\telse\n\t\twhile left != right\n\t\t\tif parens.length == 0 and brackets.length == 0\n\t\t\t\tif count > best_count\n\t\t\t\t\tbest_count, best_left, best_right = count, left, right-1\n\t\t\t\t\tbest_case = 1\n\t\t\t\tend\n\t\t\t\tbreak\n\t\t\tend\n\t\t\tif s[left] == '('\n\t\t\t\tparens.shift\n\t\t\telsif s[left] == '['\n\t\t\t\tbrackets.shift\n\t\t\t\tcount -= 1\n\t\t\tend\n\t\t\tleft += 1\n\t\tend\n\t\tparens = []\n\t\tbrackets = []\n\t\tleft = right+1\n\t\tright = right+1\n\t\tcount = 0\n\tend\nend\nif s[best_left..best_right] == ']][[[[[]'\n\tputs 'best_case == %d' % best_case\nend\nputs best_count\nputs s[best_left..best_right]\n"}, {"source_code": "#!/usr/bin/ruby\n\ns = STDIN.readline.strip + '$'\nparens, brackets = [], []\nleft, right = 0, 0\ncount, best_count = 0, 0\nbest_left, best_right = 1, 0\nwhile right < s.length\n\tch = s[right]\n\terror = false\n\tif ch == '('\n\t\tparens.push(right)\n\telsif ch == '['\n\t\tbrackets.push(right)\n\t\tcount += 1\n\telsif ch == ')'\n\t\tif parens.length == 0\n\t\t\terror = true\n\t\telsif brackets.length != 0 and brackets[-1] > parens[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tparens.pop\n\t\tend\n\telsif ch == ']'\n\t\tif brackets.length == 0\n\t\t\terror = true\n\t\telsif parens.length != 0 and parens[-1] > brackets[-1]\n\t\t\terror = true\n\t\telse\n\t\t\tbrackets.pop\n\t\tend\n\telse\n\t\terror = true\n\tend\n\tif not error\n\t\tif parens.length == 0 and brackets.length == 0\n\t\t\tif count > best_count\n\t\t\t\tbest_count, best_left, best_right = count, left, right\n\t\t\tend\n\t\tend\n\t\tright += 1\n\telse\n\t\twhile left != right\n\t\t\tif parens.length == 0 and brackets.length == 0\n\t\t\t\tif count > best_count\n\t\t\t\t\tbest_count, best_left, best_right = count, left, right-1\n\t\t\t\tend\n\t\t\tend\n\t\t\tif s[left] == '('\n\t\t\t\tparens.shift\n\t\t\telsif s[left] == '['\n\t\t\t\tbrackets.shift\n\t\t\t\tcount -= 1\n\t\t\tend\n\t\t\tleft += 1\n\t\tend\n\t\tleft = right = right+1\n\t\tcount = 0\n\tend\nend\nputs best_count\nputs s[best_left..best_right]\n"}, {"source_code": "s = gets.chomp\nst = []\nseq = []\nrev = {}\nrev[')'] = '('\nrev[']'] = '['\ni = 0\ns.each_char do |c|\n if (c == '(' || c == '[')\n st.push([i, c])\n elsif (st.size() > 0 && (c == ')' || c == ']') && rev[c] == st.last[1])\n seq.push(st.last)\n seq.push([i, c])\n st.pop\n else\n while (st.size() > 0)\n st.pop\n end\n end\n i += 1\nend\nseq.sort!\nres = \"\", mx = -1, prv = -1, c = 0, t = \"\"\nfor i in seq\n # puts \"#{i[0]} #{i[1]}\"\n if (i[0] - prv == 1 || prv == -1)\n c += 1 if (i[1] == '[')\n t += i[1]\n else\n if (mx < c)\n mx = c\n res = t.dup\n t = \"\"\n c = 0\n c += 1 if (i[1] == '[')\n t += i[1]\n end\n end\n prv = i[0]\nend\n\nif (mx < c)\n mx = c\n res = t.dup\nend\nputs mx, res\n\n"}], "src_uid": "5ce8de80c6953cd1e6e6eefd9ad35f7e"} {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\nv = x[0]\nc = [0,0,0,0,0]\nn.times do |i|\n c[x[i]-v+2] += 1\nend\nmaxidx = minidx = 2\n5.times do |i|\n if c[i] != 0\n minidx = i if i < minidx\n maxidx = i if i > maxidx\n end\nend\ndiff = maxidx - minidx\nif diff != 2\n p n\n puts x.join(\" \")\nelse\n num = []\n cnt = [c[minidx],c[minidx+1],c[minidx+2]]\n a = [cnt[0],cnt[2]].min * 4 #incrase cnt[1]\n b = cnt[1]/2 * 4 #decrease cnt[1]\n if a > b\n k = [cnt[0],cnt[2]].min\n num[0] = cnt[0]-k\n num[2] = cnt[2]-k\n num[1] = cnt[1] + k*2\n ans = num[0] + num[1] +num[2] - k*2\n else\n k = cnt[1]/2\n num[0] = cnt[0] + k\n num[1] = cnt[1] - k*2\n num[2] = cnt[2] + k\n ans = num[0] + num[1] +num[2] - k*2\n end\n p ans\n res = []\n 3.times do |i|\n res += [v+minidx-2+i] * num[i] if num[i] > 0\n end\n puts res.join(\" \")\nend\n#p c\n#p cnt\n#p num\n", "positive_code": [{"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split(\" \").map {|e| e.to_i}\nmi = arr.min\nma = arr.max\n\nout = n\nmac = 0\nmic = 0\nif ma - mi > 1\n\tarr.each do |e|\n\t\tif e == mi\n\t\t\tmic +=1\n\t\telsif e == ma\n\t\t\tmac +=1\n\t\tend\n\tend\nend\nmmc = (n - mic - mac)\n\nif mic > mac\n\tmic = mac\nelse\n\tmac = mic\nend\nif mmc % 2 != 0\n\tmmc = mmc - 1\nend\nif mmc <= (2*mic)\n\tout -= mic*2\n\tarr = arr.map do |e|\n\t\tif e == mi && mic > 0\n\t\t\tmic -= 1\n\t\t\te + 1\n\t\telsif e == ma && mac > 0\n\t\t\tmac -= 1\n\t\t\te-1\n\t\telse\n\t\t\te\n\t\tend\n\tend\nelsif (ma - mi) > 1\n\tout -= mmc\n\tmm = mi + 1\n\ti = 1\n\tarr = arr.map do |e|\n\t\tif e == mm && mmc > 0\n\t\t\ti = -i\n\t\t\tmmc -= 1\n\t\t\te + i\n\t\telse\n\t\t\te\n\t\tend\n\tend\nend\nputs out\nputs arr.join(\" \")\n"}], "negative_code": [{"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\nv = x[0]\nc = [0,0,0,0,0]\nn.times do |i|\n c[x[i]-v+2] += 1\nend\nmaxidx = minidx = 2\n5.times do |i|\n if c[i] != 0\n minidx = i if i < minidx\n maxidx = i if i > maxidx\n end\nend\ndiff = maxidx - minidx\nif diff != 2\n p 0\n puts x.join(\" \")\nelse\n num = []\n cnt = [c[minidx],c[minidx+1],c[minidx+2]]\n a = [cnt[0],cnt[2]].min * 4 #incrase cnt[1]\n b = cnt[1]/2 * 4 #decrease cnt[1]\n if a > b\n k = [cnt[0],cnt[2]].min\n num[0] = cnt[0]-k\n num[2] = cnt[2]-k\n num[1] = cnt[1] + k*2\n ans = num[0] + num[1] +num[2] - k*2\n else\n k = cnt[1]/2\n num[0] = cnt[0] + k\n num[1] = cnt[1] - k*2\n num[2] = cnt[2] + k\n ans = num[0] + num[1] +num[2] - k*2\n end\n p ans\n m = num[2] - 1 < 0 ? 0 : num[2] - 1\n print \"#{v+minidx-2} \" * num[0] + \"#{v+minidx-1} \" * num[1] + \"#{v+minidx} \" * m\n print \"#{v+minidx}\" if num[2] > 0\nend\n#p c\n#p cnt\n#p num\n"}, {"source_code": "n = gets.to_i\nx = gets.split.map(&:to_i)\nv = x[0]\nc = [0,0,0,0,0]\nn.times do |i|\n c[x[i]-v+2] += 1\nend\nmaxidx = minidx = 2\n5.times do |i|\n if c[i] != 0\n minidx = i if i < minidx\n maxidx = i if i > maxidx\n end\nend\ndiff = maxidx - minidx\nif diff != 2\n p 0\n puts x.join(\" \")\nelse\n num = []\n cnt = [c[minidx],c[minidx+1],c[minidx+2]]\n a = [cnt[0],cnt[2]].min * 4 #incrase cnt[1]\n b = cnt[1]/2 * 4 #decrease cnt[1]\n if a > b\n k = [cnt[0],cnt[2]].min\n num[0] = cnt[0]-k\n num[2] = cnt[2]-k\n num[1] = cnt[1] + k*2\n ans = num[0] + num[1] +num[2] - k*2\n else\n k = cnt[1]/2\n num[0] = cnt[0] + k\n num[1] = cnt[1] - k*2\n num[2] = cnt[2] + k\n ans = num[0] + num[1] +num[2] - k*2\n end\n p ans\n res = []\n 3.times do |i|\n res += [v+minidx-2+i] * num[i] if num[i] > 0\n end\n puts res.join(\" \")\nend\n#p c\n#p cnt\n#p num\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split(\" \").map {|e| e.to_i}\nmi = arr.min\nma = arr.max\n\nout = n\nmac = 0\nmic = 0\nif ma - mi > 1\n\tarr.each do |e|\n\t\tif e == mi\n\t\t\tmic +=1\n\t\telsif e == ma\n\t\t\tmac +=1\n\t\tend\n\tend\nend\nif mic > mac\n\tmic = mac\nelse\n\tmac = mic\nend\nmic = mic\nout -= mic*2\ni = 0\narr = arr.map do |e|\n\tif e == mi && mic > 0\n\t\tmic -= 1\n\t\te + 1\n\telsif e == ma && mac > 0\n\t\tmac -= 1\n\t\te-1\n\telse\n\t\te\n\tend\nend\nputs out\nputs arr.join(\" \")\n"}], "src_uid": "dbbea6784cafdd4244f56729996e9187"} {"source_code": "gets.to_i.times do \n n = gets.to_i.to_s(2).chars.select { |i| i == ?1 } .size\n puts 2**n\nend\n", "positive_code": [{"source_code": "gets;p *$<.map{|e|1< 0\nend\np n - h.max{|a, b| a[1] <=> b[1]}[1]\n", "positive_code": [{"source_code": "n = gets.to_i\nh = Hash.new(0)\ngets.split.map(&:to_i).each_with_index do |i, j|\n\tk = i - [j, n - 1 - j].min\n\th[k] += 1 if k > 0\nend\np n - h.max{|a, b| a[1] <=> b[1]}[1]\n"}, {"source_code": "=begin\n , \\ / ,\n / \\ )\\__/( / \\\n / \\ (_\\ /_) / \\\n ____/_____\\__\\@ @/___/_____\\____\n | |\\../| |\n | \\VV/ |\n | ------hoi------- |\n |_________________________________|\n | /\\ / \\\\ \\ /\\ |\n | / V )) V \\ |\n |/ ` // ' \\|\n ` V '\n=end\n\nn = gets.to_i\nh = Hash.new(0)\ngets.split.map(&:to_i).each_with_index do |i, j|\n\tk = i - [j, n - 1 - j].min\n\th[k] += 1 if k > 0\nend\np n - h.max{|a, b| a[1] <=> b[1]}[1]"}, {"source_code": "N = gets.to_i\na = gets.split(/\\s+/).map {|i| i.to_i}\nd = {}\nd.default = 0\ni, j = 0, N - 1\nwhile i <= j\n if a[i] - i > 0\n d[a[i] - i] += 1\n end\n if i != j && a[j] - i > 0\n d[a[j] - i] += 1\n end\n i += 1\n j -= 1\nend\n\nputs N - [1, d.values.max].max\n"}, {"source_code": "N = gets.to_i\na = gets.split(/\\s+/).map {|i| i.to_i}\nd = Array.new(100001, 0)\ni, j = 0, N - 1\nwhile i <= j\n d[a[i] - i] += 1 if a[i] - i > 0\n d[a[j] - i] += 1 if i != j && a[j] - i > 0\n i += 1\n j -= 1\nend\nputs N - [1, d.max].max\n"}, {"source_code": "N = gets.to_i\na = gets.split(/\\s+/).map {|i| i.to_i}\nd = Hash.new(0)\ni, j = 0, N - 1\nwhile i <= j\n d[a[i] - i] += 1 if a[i] - i > 0\n d[a[j] - i] += 1 if i != j && a[j] - i > 0\n i += 1\n j -= 1\nend\nputs N - [1, d.values.max].max\n"}], "negative_code": [{"source_code": "n = gets.to_i\nh = Hash.new(0)\ngets.split.map(&:to_i).each_with_index do |i, j|\n\th[i - [j, n - 1 - j].min] += 1\nend\np n - h.max{|a, b| a[1] <=> b[1]}[1]\n"}, {"source_code": "puts RUBY_VERSION"}], "src_uid": "391be6b61e289ec9c14222ea580cfcdc"} {"source_code": "info = gets.chomp.to_i\r\ninfo.times do\r\n input = gets.chomp.to_i\r\n if input.positive?\r\n print -(input-1), ' ', input\r\n puts\r\n elsif input.negative?\r\n print input, ' ', -(input)-1\r\n puts\r\n else\r\n print 0, ' ', 0\r\n puts\r\n end\r\nend\r\n", "positive_code": [{"source_code": "def i(x)\n\tx.to_i\nend\n\nt = gets\nfor k in 1..i(t)\n\tn = gets\n\tputs \"#{-i(n) + 1} #{n}\"\nend\n"}, {"source_code": "def i(x)\n\tx.to_i\nend\n\nt = gets\nfor k in 1..i(t)\n\tn = gets\n\tif i(n) == 1\n\t\tputs \"0 1\"\n\t\tnext\n\tend\n\tputs \"-#{i(n) - 1} #{n}\"\nend"}, {"source_code": "Array.new(gets.to_i) {a = gets.to_i; puts (a==0?\"0 0\": a==1 ? \"0 1\" : a==-1 ? \"-1 0\" : a < -1 ? \"#{a} #{a*-1-1}\" : a > 1 ? \"-#{a-1} #{a}\" : \"\")}"}, {"source_code": "Array.new(gets.to_i) {gets.to_i}.map{|a| a==0?\"0 0\": a==1 ? \"0 1\" : a==-1 ? \"-1 0\" : a < -1 ? \"#{a} #{a*-1-1}\" : a > 1 ? \"-#{a-1} #{a}\" : \"\"}.map{|a| puts a}"}], "negative_code": [{"source_code": "def i(x)\n\tx.to_i\nend\n\nt = gets\nfor k in 1..i(t)\n\tn = gets\n\tif n == 1\n\t\tputs \"0 1\"\n\t\tnext\n\tend\n\tputs \"-#{i(n) - 1} #{n}\"\nend"}], "src_uid": "a4628208668e9d838cd019e9dc03e470"} {"source_code": "#I could just assign 0 to some graph[i][j] instead of using path\ndef DFS(v,p)\n\t#puts v+1\n\tp.push(v)\n\t$colour[v] = :grey\n\t$n.times do |i|\n\t\tif $graph[v][i] == 1\n\t\t\tif $colour[i] == :white\n\t\t\t\tDFS(i,p)\n\t\t\t\t#p = Array.new\n\t\t\telsif $colour[i] == :grey\n\t\t\t\tunless p[p.length-2] == i\n\t\t\t\t\tif $cycle == :void\n\t\t\t\t\t\t$cycle = true\n\t\t\t\t\t\tif p.length % 2 == 1\n\t\t\t\t\t\t\t$students += 1 #p.length - 2\n\t\t\t\t\t\t\t#puts \"ALALAH!: \" + v.to_s + \", \" + i.to_s\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\t\tbreak\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\t$colour[v] = :black\n\tif $cycle == :void\n\t\t$cycle = :false\n\tend\nend\n\n#input = File.open('input.txt','r')\n$n, m = gets.split#input.\n$n = $n.to_i\nm = m.to_i\n$graph = Array.new($n)#,Array.new(n,0))\n$n.times do |i|\n\t$graph[i] = Array.new($n,0)\nend\nm.times do |i|\n\ta, b = gets.split#input.\n\t#print(a,' ',b,\"\\n\")\n\t#puts graph[a.to_i-1][b.to_i-1]\n\t$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1\n\t#puts graph[a.to_i-1][b.to_i-1]\nend\n# $graph.each do |i|\n\t# i.each do |j|\n\t\t# print j\n\t\t# print ' '\n\t# end\n\t# puts\n# end\n$colour = Array.new($n,:white)\n$cycle = :void\n$students = 0\n$n.times do |i|\n\tif $colour[i] == :white\n\t\tpath = Array.new\n\t\tDFS(i,path)\n\t\t$cycle = :void\n\tend\nend\n# if $cycle\n\t# puts \"No\"\n# else\n\t# puts \"Yes\"\n# end\nif ($n - $students) % 2 == 1\n\t$students += 1\nend\nputs $students\n#assign a value to a variable only if that variable isn't already set:\n#@variable ||= \"default value\"\n\n#x, y = y, x will interchange the values of x and y\n\n#names2 = %w{ ann richard william susan pat } \n\n#puts \"Enrollments will now Stop\" if participants > 2500 \n\n#Negative index values count from the end of the array\n", "positive_code": [{"source_code": "n, m = STDIN.readline.split.map {|s| s.to_i }\nenemies = {}\n(1..n).each {|i| enemies[i] = [] }\nm.times do\n\ta, b = STDIN.readline.split.map {|s| s.to_i }\n\tenemies[a].push(b)\n\tenemies[b].push(a)\nend\nvalue_side = {}\nsides = [[], [], []]\ndef add(i, target, value_side, sides, enemies)\n\tokay = true\n\tvalue_side[i] = target\n\tsides[target].push(i)\n\tnext_target = (target == 0 ? 1 : 0)\n\tenemies[i].each do |j|\n\t\tif not value_side[j]\n\t\t\tadd(j, next_target, value_side, sides, enemies)\n\t\telsif value_side[j] == target\n\t\t\tsides[target].delete i\n\t\t\tvalue_side[i] = 2\n\t\t\tsides[2].push(i)\n\t\tend\n\tend\nend\n(1..n).each do |i|\n\tnext if value_side[i]\n\ttarget = (sides[0].length <= sides[1].length ? 0 : 1)\n\tadd(i, target, value_side, sides, enemies)\nend\nputs sides[2].length + (sides[0].length + sides[1].length)%2\n"}], "negative_code": [{"source_code": "n, m = STDIN.readline.split.map {|s| s.to_i }\nenemies = {}\n(1..n).each {|i| enemies[i] = [] }\nm.times do\n\ta, b = STDIN.readline.split.map {|s| s.to_i }\n\tenemies[a].push(b)\n\tenemies[b].push(a)\nend\nvalue_side = {}\nsides = [[], [], []]\ndef add(i, target, value_side, sides, enemies)\n\tokay = true\n\tvalue_side[i] = target\n\tsides[target].push(i)\n\tnext_target = (target == 0 ? 1 : 0)\n\tenemies[i].each do |j|\n\t\tif not value_side[j]\n\t\t\tadd(j, next_target, value_side, sides, enemies)\n\t\telsif value_side[j] == target\n\t\t\tsides[target].delete i\n\t\t\tvalue_side[i] = 2\n\t\t\tsides[2].push(i)\n\t\tend\n\tend\nend\n(1..n).each do |i|\n\tnext if value_side[i]\n\ttarget = (sides[0].length <= sides[1].length ? 0 : 1)\n\tadd(i, target, value_side, sides, enemies)\nend\nputs sides[2].length\n"}, {"source_code": "#I could just assign 0 to some graph[i][j] instead of using path\ndef DFS(v,p)\n\t#puts v+1\n\tp.push(v)\n\t$colour[v] = :grey\n\t$n.times do |i|\n\t\tif $graph[v][i] == 1\n\t\t\tif $colour[i] == :white\n\t\t\t\tDFS(i,p)\n\t\t\t\t#p = Array.new\n\t\t\telsif $colour[i] == :grey\n\t\t\t\tunless p[p.length-2] == i\n\t\t\t\t\tif $cycle == :void\n\t\t\t\t\t\t$cycle = true\n\t\t\t\t\t\tif p.length % 2 == 1\n\t\t\t\t\t\t\t$students += 1 #p.length - 2\n\t\t\t\t\t\t\t#puts \"ALALAH!: \" + v.to_s + \", \" + i.to_s\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\t\tbreak\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\t$colour[v] = :black\n\tif $cycle == :void\n\t\t$cycle = :false\n\tend\nend\n\n#input = File.open('input.txt','r')\n$n, m = gets.split#input.\n$n = $n.to_i\nm = m.to_i\n$graph = Array.new($n)#,Array.new(n,0))\n$n.times do |i|\n\t$graph[i] = Array.new($n,0)\nend\nm.times do |i|\n\ta, b = gets.split#input.\n\t#print(a,' ',b,\"\\n\")\n\t#puts graph[a.to_i-1][b.to_i-1]\n\t$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1\n\t#puts graph[a.to_i-1][b.to_i-1]\nend\n# $graph.each do |i|\n\t# i.each do |j|\n\t\t# print j\n\t\t# print ' '\n\t# end\n\t# puts\n# end\n$colour = Array.new($n,:white)\n$cycle = :void\n$students = 0\n$n.times do |i|\n\tif $colour[i] == :white\n\t\tpath = Array.new\n\t\tDFS(i,path)\n\tend\nend\n# if $cycle\n\t# puts \"No\"\n# else\n\t# puts \"Yes\"\n# end\nif ($n - $students) % 2 == 1\n\t$students += 1\nend\nputs $students\n#assign a value to a variable only if that variable isn't already set:\n#@variable ||= \"default value\"\n\n#x, y = y, x will interchange the values of x and y\n\n#names2 = %w{ ann richard william susan pat } \n\n#puts \"Enrollments will now Stop\" if participants > 2500 \n\n#Negative index values count from the end of the array\n"}, {"source_code": "#I could just assign 0 to some graph[i][j] instead of using path\ndef DFS(v,p)\n\t#puts v+1\n\tp.push(v)\n\t$colour[v] = :grey\n\t$n.times do |i|\n\t\tif $graph[v][i] == 1\n\t\t\tif $colour[i] == :white\n\t\t\t\tDFS(i,p)\n\t\t\telsif $colour[i] == :grey\n\t\t\t\tunless p[p.length-2] == i\n\t\t\t\t\t$cycle = true\n\t\t\t\t\tif p.length % 2 == 1\n\t\t\t\t\t\t$students += 1 #p.length - 2\n\t\t\t\t\tend\n\t\t\t\t\tbreak\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\t$colour[v] = :black\nend\n\n#input = File.open('input.txt','r')\n$n, m = gets.split#input.\n$n = $n.to_i\nm = m.to_i\n$graph = Array.new($n)#,Array.new(n,0))\n$n.times do |i|\n\t$graph[i] = Array.new($n,0)\nend\nm.times do |i|\n\ta, b = gets.split#input.\n\t#print(a,' ',b,\"\\n\")\n\t#puts graph[a.to_i-1][b.to_i-1]\n\t$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1\n\t#puts graph[a.to_i-1][b.to_i-1]\nend\n# $graph.each do |i|\n\t# i.each do |j|\n\t\t# print j\n\t\t# print ' '\n\t# end\n\t# puts\n# end\n$colour = Array.new($n,:white)\n$cycle = false\n$students = 0\n$n.times do |i|\n\tif $colour[i] == :white\n\t\tpath = Array.new\n\t\tDFS(i,path)\n\tend\nend\n# if $cycle\n\t# puts \"No\"\n# else\n\t# puts \"Yes\"\n# end\nif ($n - $students) % 2 == 1\n\t$students += 1\nend\nputs $students\n#assign a value to a variable only if that variable isn't already set:\n#@variable ||= \"default value\"\n\n#x, y = y, x will interchange the values of x and y\n\n#names2 = %w{ ann richard william susan pat } \n\n#puts \"Enrollments will now Stop\" if participants > 2500 \n\n#Negative index values count from the end of the array\n"}, {"source_code": "#I could just assign 0 to some graph[i][j] instead of using path\ndef DFS(v,p)\n\t#puts v+1\n\tp.push(v)\n\t$colour[v] = :grey\n\t$n.times do |i|\n\t\tif $graph[v][i] == 1\n\t\t\tif $colour[i] == :white\n\t\t\t\tDFS(i,p)\n\t\t\telsif $colour[i] == :grey\n\t\t\t\tunless p[p.length-2] == i\n\t\t\t\t\t$cycle = true\n\t\t\t\t\t$students += p.length - 2\n\t\t\t\t\tbreak\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\t$colour[v] = :black\nend\n\n#input = File.open('input.txt','r')\n$n, m = gets.split#input.\n$n = $n.to_i\nm = m.to_i\n$graph = Array.new($n)#,Array.new(n,0))\n$n.times do |i|\n\t$graph[i] = Array.new($n,0)\nend\nm.times do |i|\n\ta, b = gets.split#input.\n\t#print(a,' ',b,\"\\n\")\n\t#puts graph[a.to_i-1][b.to_i-1]\n\t$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1\n\t#puts graph[a.to_i-1][b.to_i-1]\nend\n# $graph.each do |i|\n\t# i.each do |j|\n\t\t# print j\n\t\t# print ' '\n\t# end\n\t# puts\n# end\n$colour = Array.new($n,:white)\n$cycle = false\n$students = 0\n$n.times do |i|\n\tif $colour[i] == :white\n\t\tpath = Array.new\n\t\tDFS(i,path)\n\tend\nend\n# if $cycle\n\t# puts \"No\"\n# else\n\t# puts \"Yes\"\n# end\nif ($n - $students) % 2 == 1\n\t$students += 1\nend\nputs $students\n#assign a value to a variable only if that variable isn't already set:\n#@variable ||= \"default value\"\n\n#x, y = y, x will interchange the values of x and y\n\n#names2 = %w{ ann richard william susan pat } \n\n#puts \"Enrollments will now Stop\" if participants > 2500 \n\n#Negative index values count from the end of the array\n"}, {"source_code": "#I could just assign 0 to some graph[i][j] instead of using path\ndef DFS(v,p)\n\t#puts v+1\n\tp.push(v)\n\t$colour[v] = :grey\n\t$n.times do |i|\n\t\tif $graph[v][i] == 1\n\t\t\tif $colour[i] == :white\n\t\t\t\tDFS(i,p)\n\t\t\telsif $colour[i] == :grey\n\t\t\t\tunless p[p.length-2] == i\n\t\t\t\t\t$cycle = true\n\t\t\t\t\t$students += p.length - 2\n\t\t\t\t\tbreak\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\t$colour[v] = :black\nend\n\n#input = File.open('input.txt','r')\n$n, m = gets.split#input.\n$n = $n.to_i\nm = m.to_i\n$graph = Array.new($n)#,Array.new(n,0))\n$n.times do |i|\n\t$graph[i] = Array.new($n,0)\nend\nm.times do |i|\n\ta, b = gets.split#input.\n\t#print(a,' ',b,\"\\n\")\n\t#puts graph[a.to_i-1][b.to_i-1]\n\t$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1\n\t#puts graph[a.to_i-1][b.to_i-1]\nend\n# $graph.each do |i|\n\t# i.each do |j|\n\t\t# print j\n\t\t# print ' '\n\t# end\n\t# puts\n# end\n$colour = Array.new($n,:white)\n$cycle = false\n$students = 0\n$n.times do |i|\n\tif $colour[i] == :white\n\t\tpath = Array.new\n\t\tDFS(i,path)\n\tend\nend\n# if $cycle\n\t# puts \"No\"\n# else\n\t# puts \"Yes\"\n# end\nputs $students\n#assign a value to a variable only if that variable isn't already set:\n#@variable ||= \"default value\"\n\n#x, y = y, x will interchange the values of x and y\n\n#names2 = %w{ ann richard william susan pat } \n\n#puts \"Enrollments will now Stop\" if participants > 2500 \n\n#Negative index values count from the end of the array\n"}, {"source_code": "#I could just assign 0 to some graph[i][j] instead of using path\ndef DFS(v,p)\n\t#puts v+1\n\tp.push(v)\n\t$colour[v] = :grey\n\t$n.times do |i|\n\t\tif $graph[v][i] == 1\n\t\t\tif $colour[i] == :white\n\t\t\t\tDFS(i,p)\n\t\t\telsif $colour[i] == :grey\n\t\t\t\tunless p[p.length-2] == i\n\t\t\t\t\t$cycle = true\n\t\t\t\t\t$students += p.length - 2\n\t\t\t\t\tbreak\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\t$colour[v] = :black\nend\n\n#input = File.open('input.txt','r')\n$n, m = gets.split#input.\n$n = $n.to_i\nm = m.to_i\n$graph = Array.new($n)#,Array.new(n,0))\n$n.times do |i|\n\t$graph[i] = Array.new($n,0)\nend\nm.times do |i|\n\ta, b = gets.split#input.\n\t#print(a,' ',b,\"\\n\")\n\t#puts graph[a.to_i-1][b.to_i-1]\n\t$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1\n\t#puts graph[a.to_i-1][b.to_i-1]\nend\n# $graph.each do |i|\n\t# i.each do |j|\n\t\t# print j\n\t\t# print ' '\n\t# end\n\t# puts\n# end\n$colour = Array.new($n,:white)\n$cycle = false\n$students = 0\n$n.times do |i|\n\tif $colour[i] == :white\n\t\tpath = Array.new\n\t\tDFS(i,path)\n\tend\nend\n# if $cycle\n\t# puts \"No\"\n# else\n\t# puts \"Yes\"\n# end\nif $students % 2 == 1\n\t$students -= 1\nend\nputs $students\n#assign a value to a variable only if that variable isn't already set:\n#@variable ||= \"default value\"\n\n#x, y = y, x will interchange the values of x and y\n\n#names2 = %w{ ann richard william susan pat } \n\n#puts \"Enrollments will now Stop\" if participants > 2500 \n\n#Negative index values count from the end of the array\n"}], "src_uid": "a0e55bfbdeb3dc550e1f86b9fa7cb06d"} {"source_code": "N = gets.to_i\nA = gets.chomp\nB = gets.chomp\n\nn00, n01, n10, n11 = 0, 0, 0, 0\n\nN.times do |i|\n if A[i] == '0'\n if B[i] == '0'\n n00 += 1\n else\n n01 += 1\n end\n else\n if B[i] == '0'\n n10 += 1\n else\n n11 += 1\n end\n end\nend\n\nputs (n00+n01) * (n10+n11) - n01*n11", "positive_code": [{"source_code": "n = gets.to_i\na = gets.chomp\nb = gets.chomp\n\nazerocount = 0\nbzerocount = 0\n\nb.each_char.with_index do |c,i|\n if c==\"0\"\n if a[i] == \"0\"\n azerocount+=1\n end\n bzerocount += 1\n end\nend\n\naone = a.count('1')\n\n#p azerocount\n#p bzerocount\n#p aone\nputs azerocount*aone+(bzerocount-azerocount)*(n-aone-azerocount)"}], "negative_code": [], "src_uid": "621c82478be3dadcf60c383ba078a49e"} {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\n\ndef puts_yesno(can) puts(can ? 'Yes' : 'No') end\ndef putsend(s) puts s; exit end\ndef debug(k,v) puts \"#{k}:#{v}\" end\n########### ( \u02d8\u03c9\u02d8 )\uff7d\uff94\uff67\u2026 ###########\nq = gi\nans = []\nbase = [\"0\",\"1\",\"2\"]\nq.times do |i|\n n, k = gsmi\n # RGB\u306f012\u306b\u5909\u63db\n s = gs.gsub(/R/,\"0\").gsub(/G/,\"1\").gsub(/B/,\"2\")\n last =\n if s.length%3==1\n \"0\"\n elsif s.length%3==2\n \"01\"\n else\n \"\"\n end\n ex = base.join * (s.length/3) + last\n\n #RGBRGB...\u3068\u306e\u5dee\u5206(\u8ddd\u96e2)\u3092\u3068\u308b\n diff = []\n ex.chars.each.with_index do |str,j|\n d = str.to_i - s[j].to_i\n d = d+3 if d<0\n diff << d\n end\n #debug 'diff', diff.to_s\n # 0,1,2\u306e\u3046\u3061\u3044\u305a\u308c\u304b\u304ck\u56de\u7d9a\u3051\u3070\u3044\u3044\n a0 = diff[0..(k-1)]\n h=Hash.new(0)\n a0.each{|j|h[j]+=1}\n ar = h.to_a\n #puts ar.to_s\n max = ar.each.map{|j|j[1]}.max\n prev = h\n 1.upto(n-k) do |idx|\n prev_i = idx-1\n en = idx+k-1\n h[diff[prev_i]]-=1\n h[diff[en]]+=1\n ar = h.to_a\n #puts ar.to_s\n cnt = ar.each.map{|j|j[1]}.max\n max = cnt if cnt>max\n prev = h\n end\n\n ans << k-max\nend\nputs ans\n", "positive_code": [{"source_code": "S = \"RGB\"\ngets.to_i.times do\n n, k = gets.split.map(&:to_i)\n s = gets\n a = []\n (0...n - k + 1).each do |i|\n (0...3).each do |j|\n cur = 0\n (0...k).each do |shift|\n cur += 1 if s[i+shift] != S[(j + shift) % 3]\n end\n a << cur\n end\n end\n puts a.min\nend"}, {"source_code": "MOD=10**9+7\ncnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gsmi() gets.chomp.split.map(&:to_i) end\n\ndef desc(ar) ar.sort!{|x,y|y<=>x} end\ndef min(a,b) a<=b ? a : b end\ndef max(a,b) a>=b ? a : b end\ndef sum(ar) ar.inject(:+) end\n#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end\n\ndef puts_yesno(can) puts(can ? 'Yes' : 'No') end\ndef putsend(s) puts s; exit end\ndef debug(k,v) puts \"#{k}:#{v}\" end\n########### ( \u02d8\u03c9\u02d8 )\uff7d\uff94\uff67\u2026 ###########\nq = gi\nans = []\nbase = [\"0\",\"1\",\"2\"]\nq.times do |i|\n n, k = gsmi\n # RGB\u306f012\u306b\u5909\u63db\n s = gs.gsub(/R/,\"0\").gsub(/G/,\"1\").gsub(/B/,\"2\")\n last =\n if s.length%3==1\n \"0\"\n elsif s.length%3==2\n \"01\"\n else\n \"\"\n end\n ex = base.join * (s.length/3) + last\n\n #RGBRGB...\u3068\u306e\u5dee\u5206(\u8ddd\u96e2)\u3092\u3068\u308b\n diff = []\n ex.chars.each.with_index do |str,j|\n d = str.to_i - s[j].to_i\n d = d+3 if d<0\n diff << d\n end\n #debug 'diff', diff.to_s\n # 0,1,2\u306e\u3046\u3061\u3044\u305a\u308c\u304b\u304ck\u56de\u7d9a\u3051\u3070\u3044\u3044\n a0 = diff[0..(k-1)]\n h=Hash.new(0)\n a0.each{|j|h[j]+=1}\n ar = h.to_a\n #puts ar.to_s\n max = ar.each.map{|j|j[1]}.max\n prev = h\n 1.upto(n-k) do |idx|\n prev_i = idx-1\n en = idx+k-1\n h[diff[prev_i]]-=1\n h[diff[en]]+=1\n ar = h.to_a\n #puts ar.to_s\n cnt = ar.each.map{|j|j[1]}.max\n max = cnt if cnt>max\n prev = h\n end\n\n ans << k-max\nend\nputs ans\n"}, {"source_code": "S = \"RGB\"\ngets.to_i.times do\n n, k = gets.split.map(&:to_i)\n s = gets\n a = []\n (0...3).each do |shift|\n d = [0] * n\n cur = 0\n (0...n).each do |i|\n d[i] = (s[i] != S[(i + shift) % 3]) ? 1 : 0\n cur += d[i]\n cur -= d[i - k] if i >= k\n a << cur if i >= k - 1\n end\n end\n puts a.min\nend"}], "negative_code": [], "src_uid": "1aa8f887eb3b09decb223c71b40bb25b"} {"source_code": "n, k = gets.split(\" \").map(&:to_i)\n\nif k == 1\n p 0\n exit\nend\n\nk.times {\n a = gets.split(\" \")[1..-1].map(&:to_i) \n if a[0] == 1\n i = 0\n i += 1 while i < a.size && a[i] == i + 1\n puts 2 * (n - i) - k + 1\n exit\n end\n}\n\n", "positive_code": [{"source_code": "n,m = gets.split.map{ |x| x.to_i }\n\nv = Array.new(n) { [0,0] }\ncost,merge = 0,0\nreal_start = 0\nm.times do |i|\n a = gets.split.map{ |x| x.to_i }\n start = 1\n while (a[start] == start)\n start += 1\n end\n if start == 1\n cost += a.size - 1 - start\n else\n cost += a.size - start\n real_start = start\n end\nend\n\n\nmerge = n-real_start+1;\n#puts \"split = #{cost}\"\n#puts \"merge = #{merge}\"\nputs \"#{cost + merge}\"\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = k.times.map{gets.split.map(&:to_i)}\na = a.sort_by{|x| x[1]}\naccumulate, c = 1, 0\na[0][1..-1].each do |x|\n if x == accumulate\n c += 1\n accumulate += 1\n else\n break\n end\nend\nans = (a[0].size - 1 - c) * 2\na[1..-1].each{|x| ans += 2 * x.size - 3}\nputs ans\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = k.times.map{gets.split.map(&:to_i)}.sort_by{|x| x[1]}\ni = 1\ni += 1 while a[0][i + 1] == i + 1 \nans = (a[0][1..-1].size - i) * 2\na[1..-1].each{|x| ans += 2 * x[1..-1].size - 1}\nputs ans\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = k.times.map{gets.split.map(&:to_i)}.sort_by{|x| x[1]}\naccumulate, c = 1, 0\na[0][1..-1].each do |x|\n break if x != accumulate\n c += 1\n accumulate += 1\nend\nans = (a[0][1..-1].size - c) * 2\na[1..-1].each{|x| ans += 2 * x[1..-1].size - 1}\nputs ans\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = k.times.map{gets.split.map(&:to_i).drop(1)}.find{|x| x[0] == 1}\nputs n + n - k + 1 - 2 * a.map.with_index(1).take_while{|x, i| x == i}.size\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\n\nif m == 1\n puts 0\n exit\nend\n\nm.times do\n a = gets.split.map(&:to_i)\n a = a[1..-1]\n\n if a[0] == 1\n i = 0\n i += 1 while i < a.size && a[i] == i + 1\n\n puts((n - i) + (n - i - (m - 1)))\n exit\n end\nend\n"}], "negative_code": [{"source_code": "n, k = gets.split.map(&:to_i)\na = k.times.map{gets.split.map(&:to_i)}\naccumulate, c = 1, 0\na[0][1..-1].each do |x|\n if x == accumulate\n c += 1\n accumulate += 1\n else\n break\n end\nend\nans = (a[0].size - 1 - c) * 2\na[1..-1].each{|x| ans += 2 * x.size - 3}\nputs ans\n"}], "src_uid": "6590c99e35f6f65e1b1bbd4f5bdca43a"} {"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z\n", "positive_code": [{"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z"}, {"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z\n"}, {"source_code": "#!/usr/bin/ruby\nr=m=1\ngets\ngets.split.map(&:to_i).each_cons(2){|x,y|\n\tm=x>y ? 1 : m+1\n\tr=[r,m].max\n}\np r"}, {"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z\n"}, {"source_code": "gets\ncount=1\nmx = 0\ngets.split(' ').map(&:to_i).each_cons(2){|x,y|\n if x>y\n mx = [mx,count].max\n count =1\n else\n count+=1\n end\n}\np [count,mx].max\n"}, {"source_code": "n = gets\nli = gets.split(' ').map(&:to_i)\ncount=1\nmx = 0\nfor i in 1...li.length\n if li[i]>=li[i-1]\n count+=1\n else\n mx = [count,mx].max\n count=1\n end \nend\nputs [count,mx].max"}, {"source_code": "n = gets.to_i\nnumbers = gets.split(' ').map!(&:to_i)\narr = Array.new(numbers.size, 1)\n(numbers.size-1).times do |i|\n number = numbers[i+1]\n if number >= numbers[i]\n arr[i]+=arr[i-1]\n end\nend\nputs arr.max"}, {"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z\n"}, {"source_code": "n = gets.chomp.to_i\narr = gets.chomp.split(\" \").map{|val| val = val.to_i}\ncurmax = 1\ncur = 1\narr.each_with_index do |val,i|\n\tif i != 0 && val >= arr[i-1]\n\t\tcur += 1\n\telsif cur > curmax\n\t\tcurmax = cur\n\t\tcur = 1\n\telse\n\t\tcur = 1\n\tend\nend\nif cur > curmax\n\tcurmax = cur\nend\nputs curmax"}, {"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z\n"}, {"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z"}, {"source_code": "n = gets.chomp.to_i() - 1;\na = gets.chomp.split.map(&:to_i);\nans = 1;\nmax = 1;\n(1..n).each do |x|\n if (a[x] >= a[x - 1])\n ans += 1;\n max = [max, ans].max;\n else\n ans = 1;\n end\nend\np max;\n"}, {"source_code": "def solution(earnings)\n\n front = 0\n tail = 0\n max_days = 0\n last_earning = earnings[0]\n \n for i in 0...earnings.size do\n front += 1\n tail = i if last_earning > earnings[i]\n max_days = [max_days, front - tail].max\n last_earning = earnings[i]\n end\n\n max_days \nend\n\nn = gets()\nearnings = gets.strip.split.map { |i| i.to_i }\nputs solution(earnings)\n"}, {"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\ni = 1 \nmax_length = 1\ncount = 1\nwhile (i < n) do \n if arr[i] >= arr[i-1] then\n count += 1\n else\n count = 1\n end\n max_length = [count, max_length].max\n i += 1\nend\nputs max_length\n"}, {"source_code": "arrSize = gets.chomp.to_i\narr = gets.chomp.split\n\ncnt = 1\ni = 0\nres =0\n\nwhile i < (arr.length - 1)\n if arr[i].to_i <= arr[i+1].to_i\n cnt = cnt + 1\n else\n cnt = 1\n end\n if res < cnt\n res = cnt\n end\n i = i +1\nend\n\nif arrSize.to_i == 1\n print arrSize.to_i\nelse\n print res\nend\n"}, {"source_code": "n = $stdin.gets.to_i\na = $stdin.gets.split.map(&:to_i)\n\nprev = a.first\nl = 1\nmaxl = 1\nfor i in 1...n do\n cur = a[i]\n if cur >= prev then\n l += 1\n else\n if l >= maxl then\n maxl = l\n end\n l = 1\n end\n prev = cur\nend\n\nif l >= maxl then\n maxl = l\nend\n\nputs maxl"}, {"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z\n"}, {"source_code": "n = gets.to_i\na = gets.split(\" \")\ncur = 0\nbest = 1\n(1..n-1).each { |i|\n if a[i-1].to_i<=a[i].to_i\n if best \"Michael Hartl\", :email => \"michael@example.com\" }\nputs user[:name]\nputs user[:password]\n\ndef pow(x, y)\n p = 1\n y.times{p *= x}\n return p\nend\nz = pow(3,4)\nputs z\n=end"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nmx, j = 1, 1\n(n - 1).times do |i|\n if a[i] <= a[i + 1]\n j += 1\n else\n mx = [mx, j].max\n j = 1\n end\nend\np [mx, j].max\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nmax=1\ntemp=b[0].to_i\nmaray=[]\n1.upto(a-1) do |i|\nif b[i].to_i=l ?k+1:1].max;l=i};p z\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nmax=1\ntemp=b[0].to_i\nmaray=[]\n1.upto(a-1) do |i|\nif b[i].to_i=l ?k+1:1].max;l=i};p z\n"}, {"source_code": "gets\nx=gets.split.map{|e| e.to_i}\no=x[0]\nc=1\nans=1\n1.upto(x.size-1){|i|\n\tif o<=x[i] then\n\t\tc=c+1\n\telse\n\t\tc=1\n\tend\n\tans=[ans,c].max\n\to=x[i]\n}\nputs ans"}, {"source_code": "# https://codeforces.com/problemset/problem/580/A\nn = gets.chomp.to_i\na = gets.chomp.split(\" \").map(&:to_i)\n\nmax = 1\ni = 1\nlast = a[0]\nsum = 1\nwhile(i < a.length)\n if a[i] >= last\n sum += 1\n max = sum if sum > max\n else\n sum = 1\n end\n last = a[i]\n i += 1\nend\n\nputs max"}, {"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z"}, {"source_code": "n = gets.to_i\na = gets.split(' ').map(&:to_i)\n\nresult = a.each_with_object({prev: 0, max: 0, step: 0}) do |i, o|\n if i >= o[:prev]\n o[:step] += 1\n o[:max] = [o[:max], o[:step]].max\n else\n o[:step] = 1\n end\n o[:prev] = i\nend\n\np result[:max]\n"}, {"source_code": "number = STDIN.gets.to_i\nnumbers = STDIN.gets\n\n\n\nnumbers = numbers.split(' ').map{|x| x.to_i}\n\nunoozable = 1;\nmaxunoozable = 1;\n\n0.upto(number-1) do |i|\n if i>0\n if numbers[i] >= numbers[i-1]\n\n unoozable+=1;\n else\n\n if unoozable > maxunoozable\n maxunoozable = unoozable;\n\n end\n unoozable = 1;\n\n end\n else\n unoozable = 1\n\n end\nend\nif unoozable > maxunoozable\n maxunoozable = unoozable;\n\nend\nputs maxunoozable"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\narr = []\ni = 0\nif n == 1\n\tprint 1\nelse\nwhile i < n-1\n\tcount = 1\n\tx = i\n\twhile a[x] <= a[x+1]\n\t\tcount += 1\n\t\tx += 1\n\t\tif x == n-1\n\t\t\tbreak\n\t\tend\n\tend\n\tarr << count\n\tif count == 1\n\t\ti += 1\n\telsif x <= n-2\n\t\ti = x\n\telse\n\t\tbreak\n\tend\nend\nprint arr.max\nend"}, {"source_code": "n = gets.to_i\narr = gets.split.map(&:to_i)\nans = 1\nl = 1\n\nfor i in 1..n-1\n if arr[i] >= arr[i-1]\n l += 1\n else\n l = 1\n end\n ans = [l,ans].max\nend\n\nputs ans\n"}, {"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\ndp = [1]\n(1...n).each do |i|\n dp[i] = a[i] >= a[i-1] ? dp[i-1]+1 : 1\nend\nputs dp.max"}, {"source_code": "def read_int\n\tc = 0\n\twhile c < 48 || c > 57 do\n\t\tc = $stdin.readbyte\n\tend\n\tret = 0\n\twhile c >= 48 && c <= 57 do\n\t\tret = (ret << 3) + (ret << 1) + c - 48\n\t\tc = $stdin.readbyte\n\tend\n\n\tret\nend\n\nn = gets.to_i\n# a = gets.split.map { |s| s.to_i }\na = []\nn.times do \n\ta << read_int\nend\n\ntmp = 1\nans = 1\n(1...n).each do |i|\n\tif a[i] < a[i - 1]\n\t\ttmp = 1\n\telse\n\t\ttmp = tmp + 1\n\t\tans = [ans, tmp].max\n\tend\nend\n\nputs ans\n"}, {"source_code": "def read_int\n\tc = 0\n\twhile c < 48 || c > 57 do\n\t\tc = $stdin.readbyte\n\tend\n\tret = 0\n\twhile c >= 48 && c <= 57 do\n\t\tret = ret * 10 + c - 48\n\t\tc = $stdin.readbyte\n\tend\n\n\tret\nend\n\nn = gets.to_i\n# a = gets.split.map { |s| s.to_i }\na = []\nn.times do \n\ta << read_int\nend\n\ntmp = 1\nans = 1\n(1...n).each do |i|\n\tif a[i] < a[i - 1]\n\t\ttmp = 1\n\telse\n\t\ttmp = tmp + 1\n\t\tans = [ans, tmp].max\n\tend\nend\n\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map { |s| s.to_i }\n\ntmp = 1\nans = 1\n(1...n).each do |i|\n\tif a[i] < a[i - 1]\n\t\ttmp = 1\n\telse\n\t\ttmp = tmp + 1\n\t\tans = [ans, tmp].max\n\tend\nend\n\nputs ans\n"}, {"source_code": "def read_int\n\tc = ?\\0\n\twhile c < '0' || c > '9' do\n\t\tc = $stdin.readchar\n\tend\n\tret = 0\n\twhile c >= '0' && c <= '9' do\n\t\tret = ret * 10 + (c.ord - '0'.ord)\n\t\tc = $stdin.readchar\n\tend\n\n\tret\nend\n\nn = gets.to_i\n# a = gets.split.map { |s| s.to_i }\na = []\nn.times do \n\ta << read_int\nend\n\ntmp = 1\nans = 1\n(1...n).each do |i|\n\tif a[i] < a[i - 1]\n\t\ttmp = 1\n\telse\n\t\ttmp = tmp + 1\n\t\tans = [ans, tmp].max\n\tend\nend\n\nputs ans\n"}, {"source_code": "gets;z=l=k=0;gets.split.map{|i|z=[z,k=(i=i.to_i)>=l ?k+1:1].max;l=i};p z\n"}, {"source_code": "dayNumber = gets.chomp.to_i\ninput = gets.chomp.split(' ').map {|item| item.to_i}\nans = 1\nbest = 1\nfor i in (0...(input.length - 1))\n\t#puts \"ans : #{ans}\"\n\tans += 1 if input[i] <= input[i + 1]\n\tans = 1 if input[i] > input[i + 1]\n\tbest = ans if best <= ans\nend\n\nputs best"}, {"source_code": "n = gets.to_i\nm = gets.split.map(&:to_i)\nj=0;max=0\nif n == 1\n p 1\nelse\nfor i in(1..(n-1))\n if(m[i]max)\n max=i-j\n end\n j=i\n end\nend\nif i+1-j>max\n max = i+1-j\nend\np max\nend"}, {"source_code": "n = gets.chomp.to_i\nstr_arr = gets.chomp.split\nint_arr = str_arr.map(&:to_i)\n\nprev = -1\nmax = 1\nstreak = 0\nint_arr.each do |val|\n if val >= prev\n streak += 1\n else\n streak = 1\n end\n\n prev = val\n max = [max, streak].max\nend\n\nputs max\n\n"}, {"source_code": "a=gets.chomp.to_i\nb=gets.chomp.split(\" \")\nmax=1\ntemp=b[0].to_i\nmaray=[]\n1.upto(a-1) do |i|\nif b[i].to_i= a[x - 1])\n ans += 1;\n max = [max, ans].max;\n else\n ans = 1;\n end\nend\np max;\n"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\ni = 1 \nmax_length = 0\ncount = 1\nwhile (i < n) do \n if arr[i] >= arr[i-1] then\n count += 1\n else\n count = 1\n end\n max_length = [count, max_length].max\n i += 1\nend\nputs max_length\n"}, {"source_code": "n = gets.strip.to_i\narr = gets.strip.split(\" \").map(&:to_i)\ni = 1 \nmax_length = 0\ncount = 1\nwhile (i < n) do \n if count == 0 then\n count += 1\n elsif arr[i] >= arr[i-1] then\n count += 1\n else\n count = 0\n end\n max_length = [count, max_length].max\n i += 1\nend\nputs max_length\n"}, {"source_code": "n = gets.to_i\na = gets.split(\" \")\ncur = 0\nbest = 1\n(1..n-1).each { |i|\n if a[i-1].to_i \"Michael Hartl\", :email => \"michael@example.com\" }\nputs user[:name]\nputs user[:password]\n\ndef pow(x, y)\n p = 1\n y.times{p *= x}\n return p\nend\nz = pow(3,4)\nputs z\n=end"}, {"source_code": "gets\nx=gets.split.map{|e| e.to_i}\no=x[0]\nc=1\nans=0\n1.upto(x.size-1){|i|\n\tif o<=x[i] then\n\t\tc=c+1\n\telse\n\t\tc=1\n\tend\n\tans=[ans,c].max\n\to=x[i]\n}\nputs ans"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\narr = []\ni = 0\nwhile i < n-1\n\tcount = 1\n\tx = i\n\twhile a[x] <= a[x+1]\n\t\tcount += 1\n\t\tx += 1\n\t\tif x == n-1\n\t\t\tbreak\n\t\tend\n\tend\n\tarr << count\n\tif count == 1\n\t\ti += 1\n\telsif x <= n-2\n\t\ti = x\n\telse\n\t\tbreak\n\tend\nend\nprint arr.max"}, {"source_code": "def solution(earnings)\n\n front = 0\n tail = 0\n max_days = 0\n last_earning = earnings[0]\n \n for i in 1...earnings.size do\n front = i + 1\n tail = i if last_earning > earnings[i]\n max_days = [max_days, front - tail].max\n last_earning = earnings[i]\n end\n\n max_days \nend\n\nn = gets()\n\nearnings = gets.strip.split.map { |i| i.to_i }\nputs solution(earnings)\n"}, {"source_code": "arrSize = gets.chomp.to_i\narr = gets.chomp.split\n\ncnt = 1\ni = 0\ncntArr = []\n\nwhile i < (arr.length - 1)\n if arr[i].to_i <= arr[i+1].to_i\n cnt = cnt + 1\n else\n cntArr.push cnt\n cnt = 1\n end\n i = i +1\nend\n\nif cntArr.empty?()\n print cnt\nelse\n print cntArr.max\nend\n"}, {"source_code": "arrSize = gets.chomp.to_i\narr = gets.chomp.split\n\ncnt = 1\ni = 0\nres =0\n\nwhile i < (arr.length - 1)\n if arr[i].to_i <= arr[i+1].to_i\n cnt = cnt + 1\n else\n cnt = 1\n end\n if res < cnt\n res = cnt\n end\n i = i +1\nend\n\nprint res\n"}, {"source_code": "n = gets.to_i\nm = gets.split.map(&:to_i)\nj=0;max=0\nfor i in(1..(n-1))\n if(m[i]max)\n max=i-j\n j=i\n end\nend\nif i-j+1>max\n max = i-j+1\nend\np max"}, {"source_code": "n = gets.to_i\nans = 1\nl = 1\nnum = gets.to_i\n\nfor i in 2..n\n x = gets.to_i\n\n if x >= num\n l += 1\n else\n l = 1\n end\n ans = [l,ans].max\n num = x\nend\n\nputs ans\n"}, {"source_code": "dayNumber = gets.chomp.to_i\ninput = gets.chomp.split(' ').map {|item| item.to_i}\nindex = 0\nans = 1\nbest = 0\nfor i in (0...(input.length - 1))\n\t#puts \"ans : #{ans}\"\n\tans += 1 if input[i] <= input[i + 1]\n\tans = 1 if input[1] > input[i + 1]\n\tbest = ans if best <= ans\nend\n\nputs best"}, {"source_code": "dayNumber = gets.chomp.to_i\ninput = gets.chomp.split(' ').map {|item| item.to_i}\nindex = 0\nans = 0\nbest = 0\nfor i in (0...(input.length - 1))\n\t#puts \"ans : #{ans}\"\n\tans += 1 if input[i] <= input[i + 1]\n\tans = 0 if input[1] > input[i + 1]\n\tbest = ans if best < ans\nend\n\nputs best + 1"}, {"source_code": "dayNumber = gets.chomp.to_i\ninput = gets.chomp.split(' ').map {|item| item.to_i}\nans = 1\nbest = 0\nfor i in (0...(input.length - 1))\n\t#puts \"ans : #{ans}\"\n\tans += 1 if input[i] <= input[i + 1]\n\tans = 1 if input[i] > input[i + 1]\n\tbest = ans if best <= ans\nend\n\nputs best"}], "src_uid": "1312b680d43febdc7898ffb0753a9950"} {"source_code": "#!/usr/bin/ruby\ncount = gets.chop.to_i\nlaptops = Array.new(count){Array.new(5)}\ni = 0\nwhile line = gets\n\tline.chomp!\n\tlaptop = line.split(' ')\n\tlaptops[i][0] = laptop[0].to_i\n laptops[i][1] = laptop[1].to_i\n laptops[i][2] = laptop[2].to_i\n laptops[i][3] = laptop[3].to_i\n\tlaptops[i][4] = 1;\n\ti = i+1\nend\nfor i in 0..laptops.count-1\n\tfor i2 in 0..laptops.count-1\n\t\ttrues = 0\n\t\tfor i3 in 0..2\n\t\t\tif laptops[i][i3] < laptops[i2][i3]\n\t\t\t\ttrues = trues+1\n\t\t\tend\n\t\tend\n\t\tif trues == 3\n\t\t\tlaptops[i][4] = 0\n\t\t\t#puts \"vyhozen \" + i.to_s\n\t\t\tbreak\n\t\tend\n\tend\nend\nfor a in 0..laptops.count-1\n if laptops[a][4] == 1\n min = a;\n\t\tbreak\n end\nend\n#puts min.to_s\nfor a in 0..laptops.count-1\n\tif laptops[a][3] < laptops[min][3]\n\t\tif laptops[a][4] == 1\t\n\t\t\tmin = a;\n\t\tend\n\tend\n\t#puts min.to_s\nend \nputs (min+1).to_s\n", "positive_code": [{"source_code": "#$stdin = File.open(\"./input\", \"r\")\n\nNotebook = Struct.new(:id, :speed, :ram, :hdd, :cost)\n\nn=gets.to_i\n\ndata=[]\nn.times{|i|\n\tspeed, ram, hdd, cost=gets.split.map(&:to_i)\n\tid=i+1\n\tdata << Notebook.new(id, speed, ram , hdd, cost)\n}\n\nn.times{|i|\n\tn.times{|j|\n\t\tnext if i==j || data[i].nil? || data[j].nil?\n\t\t\n\t\ta, b = data[i], data[j]\n\t\t\n\t\tif a.speed other.hdd and @ram > other.ram and @cpu > other.cpu)\n return true\n end\n return false\n end\nend\n\ncomps = Hash.new\ncount = gets.to_i\ncount.times { |i|\n cpus, rams, hdds, costs = gets.chop.split(/\\s+/)\n comp = Comp.new\n comp.hdd = hdds.to_i\n comp.cpu = cpus.to_i\n comp.ram = rams.to_i\n comp.cost = costs.to_i\n comp.id = i+1\n comps[comp.id] = comp\n}\nlastCount = 0\ncurrCount = count\nwhile (lastCount != currCount) do\n lastCount = comps.length\n \n comps.each { |id1, comp1|\n comps.each { |id2, comp2|\n if (id1 != id2 and comp1 != nil and comp2 != nil)\n if (comp1.greater_than(comp2))\n comps[id2] = nil\n elsif (comp2.greater_than(comp1))\n comps[id1] = nil\n end\n end\n } \n }\n currCount = comps.length\n # p comps\nend\n\nmincomp = nil\ncomps.each { |id, comp|\n if comp != nil\n if (mincomp == nil)\n mincomp = comp\n end\n if (comp.cost < mincomp.cost)\n mincomp = comp\n end\n end\n}\n\nputs mincomp.id"}, {"source_code": "def choosing_laptop\n specs = []\n gets.to_i.times do\n specs << gets.split(' ').map{|i| i.to_i}\n end\n\n (0...specs.size).each do |i|\n (0...specs.size).each do |j|\n next if specs[j].nil? or specs[i].nil?\n\n if specs[i][0] > specs[j][0] and specs[i][1] > specs[j][1] and specs[i][2] > specs[j][2]\n specs[j] = nil\n end\n end\n end\n\n min = min_ind = nil\n (0...specs.size).each do |i|\n next if specs[i].nil?\n\n if min.nil? or specs[i][3] < min\n min, min_ind = specs[i][3], i\n end\n end\n\n puts min_ind+1\nend\n\n\nchoosing_laptop"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.chomp.to_i\narr = []\nn.times do |i|\n arr.push gets.chomp.split(/ /).map{|n| n.to_i} + [i+1]\nend\n\nn.times do |i|\n n.times do |j|\n if arr[i][0] < arr[j][0] and arr[i][1] < arr[j][1] and arr[i][2] < arr[j][2]\n arr[i][4] = 0\n end\n end\nend\n\nputs arr.select{|a| a[4] != 0}.min{|a,b| a[3] <=> b[3]}[4]\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.chomp.to_i\narr = []\nn.times do |i|\n arr.push gets.chomp.split(/ /).map{|n| n.to_i} + [i+1]\nend\n\nn.times do |i|\n n.times do |j|\n if arr[i][0] < arr[j][0] and arr[i][1] < arr[j][1] and arr[i][2] < arr[j][2]\n arr[i][4] = 0\n end\n end\nend\n\nid = 0\nminv = 10000\narr.select{|a| a[4] != 0}.each do |a|\n if a[3] < minv\n minv = a[3]\n id = a[4]\n end\nend\nputs id\n"}, {"source_code": "laptops=[]\ngets.to_i.times{laptops<a&&bb>b&&cc>c&&dd>d}\n\t\tnext\n\telse\n\t\tputs i+1\n\t\tbreak\n\tend\n}"}, {"source_code": "#!/usr/bin/env ruby\n\nn = STDIN.gets.to_i\nlaptops=[]\nn.times do\n laptops << STDIN.gets.split(\" \").map {|i| i.to_i}\nend\n\nflag = (0..n-1).map {|i| true}\n(laptops.length-1).times do |i|\n (i+1..laptops.length-1).each do |j|\n flag[i] = nil if laptops[i][0] < laptops[j][0] and laptops[i][1] < laptops[j][1] and laptops[i][2] < laptops[j][2]\n flag[j] = nil if laptops[j][0] < laptops[i][0] and laptops[j][1] < laptops[i][1] and laptops[j][2] < laptops[i][2]\n end\nend\n\nmin = 10000\nid = 0\nflag.length.times do |i|\n #p [i,flag[i]]\n if flag[i] and laptops[i][3] < min\n #p [i,flag[i]]\n id = i\n min = laptops[i][3]\n end\nend\nputs id+1\n"}, {"source_code": "gets; laptops, old = STDIN.read.split(\"\\n\").map {|l| l.split.map! &:to_i }, []\n\nlaptops.each do |l|\n laptops.each do |a|\n (old.push l; break) if l[0] < a[0] && l[1] < a[1] && l[2] < a[2]\n end\nend\n\nmin = 1001\n(laptops - old).each { |l| min = l[3] if l[3] < min }\n\nlaptops.each.with_index { |l, i| (print i + 1 ;break) if l[3] == min }\n"}, {"source_code": "n=gets.to_i\ncomputer=Struct.new(\"Computer\",:cpu,:ram,:hdd,:cost)\nc=[]\nfor i in 1..n\n input=gets.split.map(&:to_i)\n c.push(computer.new(input[0],input[1],input[2],input[3]))\nend\nu=Array.new(n,0)\nfor i in 0..n-1\n for j in 0..n-1\n if c[i].cpuc[i].cost then\n mincost=c[i].cost\n res=i+1\n end\n end\nend\nputs res"}, {"source_code": "n = STDIN.readline.to_i\nlaptops = []\nn.times {|i| laptops.push(STDIN.readline.split.map {|s| s.to_i } + [i] ) }\nconsider = []\nn.times do |i|\n a = laptops[i]\n okay = true\n n.times do |j|\n b = laptops[j]\n if a[0] < b[0] and a[1] < b[1] and a[2] < b[2]\n okay = false\n break\n end\n end\n consider.push(a) if okay\nend\nconsider.sort_by! {|a| a[3] }\nputs consider[0][4] + 1\n"}, {"source_code": "#!/usr/bin/ruby\ncount = gets.chop.to_i\nlaptops = Array.new(count){Array.new(5)}\ni = 0\nwhile line = gets\n line.chomp!\n laptop = line.split(' ')\n laptops[i][0] = laptop[0].to_i\n laptops[i][1] = laptop[1].to_i\n laptops[i][2] = laptop[2].to_i\n laptops[i][3] = laptop[3].to_i\n laptops[i][4] = 1;\n i = i+1\nend\nfor i in 0..laptops.count-1\n for i2 in 0..laptops.count-1\n trues = 0\n for i3 in 0..2\n if laptops[i][i3] < laptops[i2][i3]\n trues = trues+1\n end\n end\n if trues == 3\n laptops[i][4] = 0\n #puts \"vyhozen \" + i.to_s\n break\n end\n end\nend\nminprice = -1\nminindex = -1\nfor a in 0..laptops.count-1\n if laptops[a][3] < minprice || minprice == -1\n if laptops[a][4] == 1\n minprice = laptops[a][3];\n minindex = a;\n end\n end\n #puts min.to_s\nend\nputs (minindex+1).to_s"}, {"source_code": "n = gets.to_i\na = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}\nok = a.find_all { |i| !a.any? { |x| i[0]tb\n if(ta==tb)\n puts (fa-fb).abs\n else\n tt = (ta-tb).abs\n if fa>b && fb>b\n tt += ( (fa-b).abs + (fb-b).abs )\n elsif fab\n floor = b\n ans += fa-b\n end\n\n\n ans += (tb-ta).abs\n ans += (floor-fb).abs\n \n puts ans\nend"}, {"source_code": "N, H, A, B, K = gets.split.map(&:to_i)\nK.times do\n ta, fa, tb, fb = gets.split.map(&:to_i)\n if ta == tb\n dh = (fa-fb).abs\n elsif faB && fb>B\n dh = fa+fb - 2*B\n else\n dh = (fa-fb).abs\n end\n puts dh + (ta-tb).abs\nend\n"}, {"source_code": "n,h,a,b,k = gets.chomp.split(\" \").map(&:to_i)\nk.times do\n o,p,q,r = gets.chomp.split(\" \").map(&:to_i)\n ans = 0\n ans += (o-q).abs\n if ((p < a && r < a) || (p > b && r > b)) && o != q\n ans += [(p-a).abs,(p-b).abs].min\n ans += [(r-a).abs,(r-b).abs].min\n else\n ans += (p-r).abs\n end\n puts ans\nend\n"}, {"source_code": "n, h, a, b, k = gets.split.map(&:to_i)\nk.times do \n ta, fa, tb, fb = gets.split.map(&:to_i)\n if ta == tb\n puts (fa - fb).abs\n next\n end\n ans = (ta - tb).abs\n if fa > fb\n fa, fb = fb, fa\n end\n if fa <= b && fb >= a\n ans += fb - fa\n elsif fa > b\n ans += (fa - b) + (fb - b)\n elsif fb < a\n ans += (a - fb) + (a - fa)\n end\n puts ans\nend"}], "negative_code": [{"source_code": "N, H, A, B, K = gets.split.map(&:to_i)\nK.times do\n ta, fa, tb, fb = gets.split.map(&:to_i)\n if faB && fb>B\n dh = fa+fb - 2*B\n else\n dh = (fa-fb).abs\n end\n puts dh + (ta-tb).abs\nend\n"}, {"source_code": "n,h,a,b,k = gets.chomp.split(\" \").map(&:to_i)\nk.times do\n o,p,q,r = gets.chomp.split(\" \").map(&:to_i)\n ans = 0\n ans += (o-q).abs\n if (p < a && r < a) || (p > b && r > b)\n ans += [(p-a).abs,(p-b).abs].min\n ans += [(r-a).abs,(r-b).abs].min\n else\n ans += (p-r).abs\n end\n puts ans\nend\n"}, {"source_code": "nhabk = gets.chomp.split(\" \").map(&:to_i)\nn = nhabk[0]\nh = nhabk[1]\na = nhabk[2]\nb = nhabk[3]\nk = nhabk[4]\n\narr = []\nk.times {arr.push gets.chomp.split(\" \").map(&:to_i)}\n\narr.each do |z|\n ta = z[0]\n fa = z[1]\n tb = z[2]\n fb = z[3]\n\n ans = 0\n floor = fa\n\n if fab\n floor = b\n ans += fa-b\n end\n\n\n ans += tb-ta\n ans += (floor-fb).abs\n \n puts ans\nend"}, {"source_code": "nhabk = gets.chomp.split(\" \").map(&:to_i)\nn = nhabk[0]\nh = nhabk[1]\na = nhabk[2]\nb = nhabk[3]\nk = nhabk[4]\n\narr = []\nk.times {arr.push gets.chomp.split(\" \").map(&:to_i)}\n\narr.each do |z|\n ta = z[0]\n fa = z[1]\n tb = z[2]\n fb = z[3]\n\n ans = 0\n floor = fa\n\n if fab\n floor = b\n ans += fa-b\n end\n\n\n ans += (tb-ta).abs\n ans += (floor-fb).abs\n \n puts ans\nend"}], "src_uid": "bdce4761496c88a3de00aa863ba7308d"} {"source_code": "\n#$stdin.reopen('/cygdrive/d/input.txt', 'r')\n\nclass Friend\n\tdef initialize(cost, monitor, nsolve, array)\n\t\t@cost,@monitor, @nsolve, @array = cost,\n\t\t\tmonitor, nsolve, array\n\tend\n\tattr_accessor :cost, :monitor, :nsolve, :array\nend\n\nclass Min\n\tdef initialize(cost,monitor,ruble)\n\t\t@cost,@monitor,@ruble=cost,monitor,ruble\n\n\tend\n\tattr_accessor :cost, :monitor, :ruble\nend\n\ndef init\n\n\tfriend_list = []\n\tn,m,b = gets.split.map(&:to_i)\n\n\t(1..n).each do |ind|\n\t\tcost,monitor,nsolve=gets.split.map(&:to_i)\n\t\tarray = gets.split.map(&:to_i)\n\t\tfriend_list.push(Friend.new(cost,monitor,nsolve,array))\n\tend\n\n\tarray = [0]*(m+1)\n\n\t(0..m).each do |ind|\n\t\tarray[ind] = []\n\tend\n\n\t(0...friend_list.size).each do |ind|\n\t\tfriend_list[ind].array.each do |e|\n\t\t\tarray[e].push(friend_list[ind])\n\t\tend\n\tend \n\n\t#each element in array should be sorted.\n=begin\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n=end\n\treturn n,m,b,array\nend\n\ndef index(problem)\n\n\ti,s=1,0\n\tsize = problem.size\n\twhile i=1\n\t\ti+=1\n\tend\n\ts\nend\n\ndef solve(array,ind,problem,t,current,min)\n\n\tif ind==array.size\n\t\t#puts current.cost\n\t\tif min.cost == -1 or current.cost= 1\n\t\tsolve(array, ind+1, problem, t, current, min)\n\telse\n\n\t\tif array[ind].empty?\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\n\t\tarray[ind].each do |e|\n\n\t\t\ti=e.monitor>current.monitor ? e.monitor-current.monitor : 0\n\t\t\tcost = current.cost+i*min.ruble+e.cost\n\t\t\tnext if (min.cost!=-1 and cost >= min.cost)\n\t\t\tcurrent.cost, current.monitor = cost, current.monitor+i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]+=1\n\t\t\tend\n\t\t\t#print problem; puts\n=begin\n\t\t\tm= index(problem)\n\t\t\tif t[m] == -1 or current.cost< t[m]\n\t\t\t\tt[m] = current.cost\n\t\t\t\tsolve(array, ind+1, problem,t, current,min)\n\t\t\tend\n=end\n\t\t\t\n\t\t\tm =problem.to_s+current.monitor.to_s\n\t\t\tif !t.has_key?(m) or current.cost < t[m]\n\t\t\t\tt[m] = current.cost\n\t\t\t\tsolve(array,ind+1,problem, t, current, min)\n\t\t\tend\n\n\t\t\tcurrent.cost-= (e.cost+i*min.ruble)\n\t\t\tcurrent.monitor -= i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]-=1\n\t\t\tend\n\t\t\n\t\tend\n\tend\nend\n\n\ndef main\n\tn,m,b,array = init\n=begin\n\tarray[1].each do |e|\n\t\tputs (e.cost+e.monitor*b)/e.nsolve.to_f\n\tend\n=end\n\tcurrent, min, problem = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)\n\n\t#t = [-1]*(1<<22)\n\tt=Hash.new\n\n\tsolve(array, 1, problem, t,current, min)\n\tputs min.cost\n\n\nend\n\nmain\n\n\n\n\n\n\n\n", "positive_code": [{"source_code": "\n#$stdin.reopen('/cygdrive/d/input.txt', 'r')\n\nclass Friend\n\tdef initialize(cost, monitor, nsolve, array)\n\t\t@cost,@monitor, @nsolve, @array = cost,\n\t\t\tmonitor, nsolve, array\n\tend\n\tattr_accessor :cost, :monitor, :nsolve, :array\nend\n\nclass Min\n\tdef initialize(cost,monitor,ruble)\n\t\t@cost,@monitor,@ruble=cost,monitor,ruble\n\n\tend\n\tattr_accessor :cost, :monitor, :ruble\nend\n\ndef init\n\n\tfriend_list = []\n\tn,m,b = gets.split.map(&:to_i)\n\n\t(1..n).each do |ind|\n\t\tcost,monitor,nsolve=gets.split.map(&:to_i)\n\t\tarray = gets.split.map(&:to_i)\n\t\tfriend_list.push(Friend.new(cost,monitor,nsolve,array))\n\tend\n\n\tarray = [0]*(m+1)\n\n\t(0..m).each do |ind|\n\t\tarray[ind] = []\n\tend\n\n\t(0...friend_list.size).each do |ind|\n\t\tfriend_list[ind].array.each do |e|\n\t\t\tarray[e].push(friend_list[ind])\n\t\tend\n\tend \n\n\t#each element in array should be sorted.\n\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n\n=begin\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif a.monitor< c.monitor\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n=end\n\treturn n,m,b,array\nend\n\ndef index(problem)\n\n\ti,s=1,0\n\tsize = problem.size\n\twhile i=1\n\t\ti+=1\n\tend\n\ts\nend\n\ndef solve(array,ind,problem,t,current,min)\n\n\tif ind==array.size\n\t\t#puts current.cost\n\t\tif min.cost == -1 or current.cost= 1\n\t\tsolve(array, ind+1, problem, t, current, min)\n\telse\n\n\t\tif array[ind].empty?\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\n\t\tarray[ind].each do |e|\n\n\t\t\ti=e.monitor>current.monitor ? e.monitor-current.monitor : 0\n\t\t\tcost = current.cost+i*min.ruble+e.cost\n\t\t\tnext if (min.cost!=-1 and cost >= min.cost)\n\t\t\tcurrent.cost, current.monitor = cost, current.monitor+i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]+=1\n\t\t\tend\n\t\t\t#print problem; puts\n=begin\n\t\t\tm= index(problem)\n\t\t\tif t[m] == -1 or current.cost< t[m]\n\t\t\t\tt[m] = current.cost\n\t\t\t\tsolve(array, ind+1, problem,t, current,min)\n\t\t\tend\n=end\n\t\t\t\n\t\t\tm =problem.to_s+current.monitor.to_s\n\t\t\tif !t.has_key?(m) or current.cost < t[m]\n\t\t\t\tt[m] = current.cost\n\t\t\t\tsolve(array,ind+1,problem, t, current, min)\n\t\t\tend\n\n\t\t\tcurrent.cost-= (e.cost+i*min.ruble)\n\t\t\tcurrent.monitor -= i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]-=1\n\t\t\tend\n\t\t\n\t\tend\n\tend\nend\n\n\ndef main\n\tn,m,b,array = init\n=begin\n\tarray[1].each do |e|\n\t\tputs (e.cost+e.monitor*b)/e.nsolve.to_f\n\tend\n=end\n\tcurrent, min, problem = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)\n\n\t#t = [-1]*(1<<22)\n\tt=Hash.new\n\n\tsolve(array, 1, problem, t,current, min)\n\tputs min.cost\n\n\nend\n\nmain\n\n\n\n\n\n\n\n"}, {"source_code": "\n#$stdin.reopen('/cygdrive/d/input.txt', 'r')\n\nclass Friend\n\tdef initialize(cost, monitor, nsolve, array)\n\t\t@cost,@monitor, @nsolve, @array = cost,\n\t\t\tmonitor, nsolve, array\n\tend\n\tattr_accessor :cost, :monitor, :nsolve, :array\nend\n\nclass Min\n\tdef initialize(cost,monitor,ruble)\n\t\t@cost,@monitor,@ruble=cost,monitor,ruble\n\n\tend\n\tattr_accessor :cost, :monitor, :ruble\nend\n\ndef init\n\n\tfriend_list = []\n\tn,m,b = gets.split.map(&:to_i)\n\n\t(1..n).each do |ind|\n\t\tcost,monitor,nsolve=gets.split.map(&:to_i)\n\t\tarray = gets.split.map(&:to_i)\n\t\tfriend_list.push(Friend.new(cost,monitor,nsolve,array))\n\tend\n\n\tarray = [0]*(m+1)\n\n\t(0..m).each do |ind|\n\t\tarray[ind] = []\n\tend\n\n\t(0...friend_list.size).each do |ind|\n\t\tfriend_list[ind].array.each do |e|\n\t\t\tarray[e].push(friend_list[ind])\n\t\tend\n\tend \n\n\t#each element in array should be sorted.\n=begin\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n=end\n\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif a.monitor> c.monitor\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n\treturn n,m,b,array\nend\n\ndef index(problem)\n\n\ti,s=1,0\n\tsize = problem.size\n\twhile i=1\n\t\ti+=1\n\tend\n\ts\nend\n\ndef solve(array,ind,problem,t,current,min)\n\n\tif ind==array.size\n\t\t#puts current.cost\n\t\tif min.cost == -1 or current.cost= 1\n\t\tsolve(array, ind+1, problem, t, current, min)\n\telse\n\n\t\tif array[ind].empty?\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\n\t\tarray[ind].each do |e|\n\n\t\t\ti=e.monitor>current.monitor ? e.monitor-current.monitor : 0\n\t\t\tcost = current.cost+i*min.ruble+e.cost\n\t\t\tnext if (min.cost!=-1 and cost >= min.cost)\n\t\t\tcurrent.cost, current.monitor = cost, current.monitor+i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]+=1\n\t\t\tend\n\t\t\t#print problem; puts\n=begin\n\t\t\tm= index(problem)\n\t\t\tif t[m] == -1 or current.cost< t[m]\n\t\t\t\tt[m] = current.cost\n\t\t\t\tsolve(array, ind+1, problem,t, current,min)\n\t\t\tend\n=end\n\t\t\t\n\t\t\tm =problem.to_s+current.monitor.to_s\n\t\t\tif !t.has_key?(m) or current.cost < t[m]\n\t\t\t\tt[m] = current.cost\n\t\t\t\tsolve(array,ind+1,problem, t, current, min)\n\t\t\tend\n\n\t\t\tcurrent.cost-= (e.cost+i*min.ruble)\n\t\t\tcurrent.monitor -= i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]-=1\n\t\t\tend\n\t\t\n\t\tend\n\tend\nend\n\n\ndef main\n\tn,m,b,array = init\n=begin\n\tarray[1].each do |e|\n\t\tputs (e.cost+e.monitor*b)/e.nsolve.to_f\n\tend\n=end\n\tcurrent, min, problem = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)\n\n\t#t = [-1]*(1<<22)\n\tt=Hash.new\n\n\tsolve(array, 1, problem, t,current, min)\n\tputs min.cost\n\n\nend\n\nmain\n\n\n\n\n\n\n\n"}, {"source_code": "\n#$stdin.reopen('/cygdrive/d/input.txt', 'r')\n\nclass Friend\n\tdef initialize(cost, monitor, nsolve, array)\n\t\t@cost,@monitor, @nsolve, @array = cost,\n\t\t\tmonitor, nsolve, array\n\tend\n\tattr_accessor :cost, :monitor, :nsolve, :array\nend\n\nclass Min\n\tdef initialize(cost,monitor,ruble)\n\t\t@cost,@monitor,@ruble=cost,monitor,ruble\n\n\tend\n\tattr_accessor :cost, :monitor, :ruble\nend\n\ndef init\n\n\tfriend_list = []\n\tn,m,b = gets.split.map(&:to_i)\n\n\t(1..n).each do |ind|\n\t\tcost,monitor,nsolve=gets.split.map(&:to_i)\n\t\tarray = gets.split.map(&:to_i)\n\t\tfriend_list.push(Friend.new(cost,monitor,nsolve,array))\n\tend\n\n\tarray = [0]*(m+1)\n\n\t(0..m).each do |ind|\n\t\tarray[ind] = []\n\tend\n\n\t(0...friend_list.size).each do |ind|\n\t\tfriend_list[ind].array.each do |e|\n\t\t\tarray[e].push(friend_list[ind])\n\t\tend\n\tend \n\n\t#each element in array should be sorted.\n=begin\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n=end\n\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif a.monitor< c.monitor\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n\treturn n,m,b,array\nend\n\ndef index(problem)\n\n\ti,s=1,0\n\tsize = problem.size\n\twhile i=1\n\t\ti+=1\n\tend\n\ts\nend\n\ndef solve(array,ind,problem,t,current,min)\n\n\tif ind==array.size\n\t\t#puts current.cost\n\t\tif min.cost == -1 or current.cost= 1\n\t\tsolve(array, ind+1, problem, t, current, min)\n\telse\n\n\t\tif array[ind].empty?\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\n\t\tarray[ind].each do |e|\n\n\t\t\ti=e.monitor>current.monitor ? e.monitor-current.monitor : 0\n\t\t\tcost = current.cost+i*min.ruble+e.cost\n\t\t\tnext if (min.cost!=-1 and cost >= min.cost)\n\t\t\tcurrent.cost, current.monitor = cost, current.monitor+i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]+=1\n\t\t\tend\n\t\t\t#print problem; puts\n=begin\n\t\t\tm= index(problem)\n\t\t\tif t[m] == -1 or current.cost< t[m]\n\t\t\t\tt[m] = current.cost\n\t\t\t\tsolve(array, ind+1, problem,t, current,min)\n\t\t\tend\n=end\n\t\t\t\n\t\t\tm =problem.to_s+current.monitor.to_s\n\t\t\tif !t.has_key?(m) or current.cost < t[m]\n\t\t\t\tt[m] = current.cost\n\t\t\t\tsolve(array,ind+1,problem, t, current, min)\n\t\t\tend\n\n\t\t\tcurrent.cost-= (e.cost+i*min.ruble)\n\t\t\tcurrent.monitor -= i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]-=1\n\t\t\tend\n\t\t\n\t\tend\n\tend\nend\n\n\ndef main\n\tn,m,b,array = init\n=begin\n\tarray[1].each do |e|\n\t\tputs (e.cost+e.monitor*b)/e.nsolve.to_f\n\tend\n=end\n\tcurrent, min, problem = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)\n\n\t#t = [-1]*(1<<22)\n\tt=Hash.new\n\n\tsolve(array, 1, problem, t,current, min)\n\tputs min.cost\n\n\nend\n\nmain\n\n\n\n\n\n\n\n"}, {"source_code": "\n#$stdin.reopen('/cygdrive/d/input.txt', 'r')\n\nclass Friend\n\tdef initialize(cost, monitor, nsolve, array)\n\t\t@cost,@monitor, @nsolve, @array = cost,\n\t\t\tmonitor, nsolve, array\n\tend\n\tattr_accessor :cost, :monitor, :nsolve, :array\nend\n\nclass Min\n\tdef initialize(cost,monitor,ruble)\n\t\t@cost,@monitor,@ruble=cost,monitor,ruble\n\n\tend\n\tattr_accessor :cost, :monitor, :ruble\nend\n\ndef init\n\n\tfriend_list = []\n\tn,m,b = gets.split.map(&:to_i)\n\n\t(1..n).each do |ind|\n\t\tcost,monitor,nsolve=gets.split.map(&:to_i)\n\t\tarray = gets.split.map(&:to_i)\n\t\tfriend_list.push(Friend.new(cost,monitor,nsolve,array))\n\tend\n\n\tarray = [0]*(m+1)\n\n\t(0..m).each do |ind|\n\t\tarray[ind] = []\n\tend\n\n\t(0...friend_list.size).each do |ind|\n\t\tfriend_list[ind].array.each do |e|\n\t\t\tarray[e].push(friend_list[ind])\n\t\tend\n\tend \n\n\t#each element in array should be sorted.\n\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n\t\n\treturn n,m,b,array\nend\n\ndef index(problem)\n\n\ti,s=1,0\n\tsize = problem.size\n\twhile i=1\n\t\ti+=1\n\tend\n\ts\nend\n\ndef solve(array,ind,problem,t,current,min)\n\n\tif ind==array.size\n\t\t#puts current.cost\n\t\tif min.cost == -1 or current.cost= 1\n\t\tsolve(array, ind+1, problem, t, current, min)\n\telse\n\n\t\tif array[ind].empty?\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\n\t\tarray[ind].each do |e|\n\n\t\t\ti=e.monitor>current.monitor ? e.monitor-current.monitor : 0\n\t\t\tcost = current.cost+i*min.ruble+e.cost\n\t\t\tnext if (min.cost!=-1 and cost >= min.cost)\n\t\t\tcurrent.cost, current.monitor = cost, current.monitor+i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]+=1\n\t\t\tend\n\t\t\t#print problem; puts\n=begin\n\t\t\tm= index(problem)\n\t\t\tif t[m] == -1 or current.cost< t[m]\n\t\t\t\tt[m] = current.cost\n\t\t\t\tsolve(array, ind+1, problem,t, current,min)\n\t\t\tend\n=end\n\t\t\t\n\t\t\tm =problem.to_s+current.monitor.to_s\n\t\t\tif !t.has_key?(m) or current.cost < t[m]\n\t\t\t\tt[m] = current.cost\n\t\t\t\tsolve(array,ind+1,problem, t, current, min)\n\t\t\tend\n\n\t\t\tcurrent.cost-= (e.cost+i*min.ruble)\n\t\t\tcurrent.monitor -= i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]-=1\n\t\t\tend\n\t\t\n\t\tend\n\tend\nend\n\n\ndef main\n\tn,m,b,array = init\n=begin\n\tarray[1].each do |e|\n\t\tputs (e.cost+e.monitor*b)/e.nsolve.to_f\n\tend\n=end\n\tcurrent, min, problem = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)\n\n\t#t = [-1]*(1<<22)\n\tt=Hash.new\n\n\tsolve(array, 1, problem, t,current, min)\n\tputs min.cost\n\n\nend\n\nmain\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "\n#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')\n\nclass Friend\n\tdef initialize(cost, monitor, nsolve, array)\n\t\t@cost,@monitor, @nsolve, @array = cost,\n\t\t\tmonitor, nsolve, array\n\tend\n\tattr_accessor :cost, :monitor, :nsolve, :array\nend\n\nclass Min\n\tdef initialize(cost,monitor,ruble)\n\t\t@cost,@monitor,@ruble=cost,monitor,ruble\n\n\tend\n\tattr_accessor :cost, :monitor, :ruble\nend\n\ndef init\n\n\tfriend_list = []\n\tn,m,b = gets.split.map(&:to_i)\n\n\t(1..n).each do |ind|\n\t\tcost,monitor,nsolve=gets.split.map(&:to_i)\n\t\tarray = gets.split.map(&:to_i)\n\t\tfriend_list.push(Friend.new(cost,monitor,nsolve,array))\n\tend\n\n\tarray = [0]*(m+1)\n\n\t(0..m).each do |ind|\n\t\tarray[ind] = []\n\tend\n\n\t(0...friend_list.size).each do |ind|\n\t\tfriend_list[ind].array.each do |e|\n\t\t\tarray[e].push(friend_list[ind])\n\t\tend\n\tend \n\n\t#each element in array should be sorted.\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n\t\n\treturn n,m,b,array\nend\n\ndef solve(array,ind,problem,current,min)\n\n\tif ind==array.size\n\t\tif current.cost= 1\n\t\tsolve(array, ind+1, problem, current, min)\n\telse\n\n\t\tif array[ind].empty?\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\n\t\tarray[ind].each do |e|\n\n\t\t\ti=e.monitor>current.monitor ? e.monitor-current.monitor : 0\n\t\t\tcost = current.cost+i*min.ruble+e.cost\n\t\t\tnext if cost > min.cost\n\t\t\tcurrent.cost, current.monitor = cost, current.monitor+i\n\t\t\te.array.each do |m|\n\t\t\t\tproblem[m]+=1\n\t\t\tend\n\t\t\tprint problem\n\t\t\tsolve(array, ind+1, problem, current,min)\n\t\t\tcurrent.cost-= (e.cost+i*min.ruble)\n\t\t\tcurrent.monitor -= i\n\t\t\te.array.each do |m|\n\t\t\t\tproblem[m]-=1\n\t\t\tend\n\t\t\n\t\tend\n\tend\nend\n\n\ndef main\n\tn,m,b,array = init\n\n\tarray[1].each do |e|\n\t\tputs (e.cost+e.monitor*b)/e.nsolve.to_f\n\tend\n\tcurrent, min, problem = Min.new(0,0,b), Min.new(1<<32,0,b), [0]*(m+1)\n\tsolve(array, 1, problem, current, min)\n\tputs min.cost\n\nend\n\nmain\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "\n#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')\n\nclass Friend\n\tdef initialize(cost, monitor, nsolve, array)\n\t\t@cost,@monitor, @nsolve, @array = cost,\n\t\t\tmonitor, nsolve, array\n\tend\n\tattr_accessor :cost, :monitor, :nsolve, :array\nend\n\nclass Min\n\tdef initialize(cost,monitor,ruble)\n\t\t@cost,@monitor,@ruble=cost,monitor,ruble\n\n\tend\n\tattr_accessor :cost, :monitor, :ruble\nend\n\ndef init\n\n\tfriend_list = []\n\tn,m,b = gets.split.map(&:to_i)\n\n\t(1..n).each do |ind|\n\t\tcost,monitor,nsolve=gets.split.map(&:to_i)\n\t\tarray = gets.split.map(&:to_i)\n\t\tfriend_list.push(Friend.new(cost,monitor,nsolve,array))\n\tend\n\n\tarray = [0]*(m+1)\n\n\t(0..m).each do |ind|\n\t\tarray[ind] = []\n\tend\n\n\t(0...friend_list.size).each do |ind|\n\t\tfriend_list[ind].array.each do |e|\n\t\t\tarray[e].push(friend_list[ind])\n\t\tend\n\tend \n\n\t#each element in array should be sorted.\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n\t\n\treturn n,m,b,array\nend\ndef index(problem)\n\n\ti,s=1,0\n\tsize = problem.size\n\twhile i= 1\n\t\tsolve(array, ind+1, problem, t, current, min)\n\telse\n\n\t\tif array[ind].empty?\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\n\t\tarray[ind].each do |e|\n\n\t\t\ti=e.monitor>current.monitor ? e.monitor-current.monitor : 0\n\t\t\tcost = current.cost+i*min.ruble+e.cost\n\t\t\tnext if min.cost!=-1 and cost >= min.cost\n\t\t\tcurrent.cost, current.monitor = cost, current.monitor+i\n\t\t\te.array.each do |m|\n\t\t\t\tproblem[m]+=1\n\t\t\tend\n\n\n\t\t\t#print problem; puts\n\t\t\tx= index(problem)\n\t\t\tif t[x] == -1 or current.cost< t[x]\n\t\t\t\tt[x] = current.cost\n\t\t\t\tsolve(array, ind+1, problem,t, current,min)\n\t\t\tend\n\t\t\tcurrent.cost-= (e.cost+i*min.ruble)\n\t\t\tcurrent.monitor -= i\n\t\t\te.array.each do |m|\n\t\t\t\tproblem[m]-=1\n\t\t\tend\n\t\t\n\t\tend\n\tend\nend\n\n\ndef main\n\tn,m,b,array = init\n\n\n=begin \n\tarray[1].each do |e|\n\t\tputs (e.cost+e.monitor*b)/e.nsolve.to_f\n\tend\n=end\n\tcurrent, min, problem = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)\n\tt = [-1]*(1<<22)\n\tsolve(array, 1, problem, t,current, min)\n\tputs min.cost\n\nend\n\nmain\n\n\n\n\n\n\n\n"}, {"source_code": "\n#$stdin.reopen('/cygdrive/d/input.txt', 'r')\n\nclass Friend\n\tdef initialize(cost, monitor, nsolve, array)\n\t\t@cost,@monitor, @nsolve, @array = cost,\n\t\t\tmonitor, nsolve, array\n\tend\n\tattr_accessor :cost, :monitor, :nsolve, :array\nend\n\nclass Min\n\tdef initialize(cost,monitor,ruble)\n\t\t@cost,@monitor,@ruble=cost,monitor,ruble\n\n\tend\n\tattr_accessor :cost, :monitor, :ruble\nend\n\ndef init\n\n\tfriend_list = []\n\tn,m,b = gets.split.map(&:to_i)\n\n\t(1..n).each do |ind|\n\t\tcost,monitor,nsolve=gets.split.map(&:to_i)\n\t\tarray = gets.split.map(&:to_i)\n\t\tfriend_list.push(Friend.new(cost,monitor,nsolve,array))\n\tend\n\n\tarray = [0]*(m+1)\n\n\t(0..m).each do |ind|\n\t\tarray[ind] = []\n\tend\n\n\t(0...friend_list.size).each do |ind|\n\t\tfriend_list[ind].array.each do |e|\n\t\t\tarray[e].push(friend_list[ind])\n\t\tend\n\tend \n\n\t#each element in array should be sorted.\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n\t\n\treturn n,m,b,array\nend\n\ndef index(problem)\n\n\ti,s=1,0\n\tsize = problem.size\n\twhile i=1\n\t\t\ts= (s<<1)+1\n\t\tend\n\t\ti+=1\n\tend\n\ts\nend\n\ndef solve(array,ind,problem,t,current,min)\n\n\tif ind==array.size\n\t\t\n\t\tif min.cost == -1 or current.cost= 1\n\t\tsolve(array, ind+1, problem, t, current, min)\n\telse\n\n\t\tif array[ind].empty?\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\n\t\tarray[ind].each do |e|\n\n\t\t\ti=e.monitor>current.monitor ? e.monitor-current.monitor : 0\n\t\t\tcost = current.cost+i*min.ruble+e.cost\n\t\t\tnext if (min.cost!=-1 and cost >= min.cost)\n\t\t\tcurrent.cost, current.monitor = cost, current.monitor+i\n\t\t\te.array.each do |m|\n\t\t\t\tproblem[m]+=1\n\t\t\tend\n\t\t\t#print problem; puts\n\t\t\tx= index(problem)\n\t\t\tif t[x] == -1 or current.cost< t[x]\n\t\t\t\tt[x] = current.cost\n\t\t\t\tsolve(array, ind+1, problem,t, current,min)\n\t\t\tend\n\t\t\tcurrent.cost-= (e.cost+i*min.ruble)\n\t\t\tcurrent.monitor -= i\n\t\t\te.array.each do |m|\n\t\t\t\tproblem[m]-=1\n\t\t\tend\n\t\t\n\t\tend\n\tend\nend\n\n\ndef main\n\tn,m,b,array = init\n\n=begin \n\tarray[1].each do |e|\n\t\tputs (e.cost+e.monitor*b)/e.nsolve.to_f\n\tend\n=end\n\tcurrent, min, problem = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)\n\tt = [-1]*(1<<22)\n\tsolve(array, 1, problem, t,current, min)\n\tputs min.cost\n\nend\n\nmain\n\n\n\n\n\n\n\n"}, {"source_code": "\n#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')\n\nclass Friend\n\tdef initialize(cost, monitor, nsolve, array)\n\t\t@cost,@monitor, @nsolve, @array = cost,\n\t\t\tmonitor, nsolve, array\n\tend\n\tattr_accessor :cost, :monitor, :nsolve, :array\nend\n\nclass Min\n\tdef initialize(cost,monitor,ruble)\n\t\t@cost,@monitor,@ruble=cost,monitor,ruble\n\n\tend\n\tattr_accessor :cost, :monitor, :ruble\nend\n\ndef init\n\n\tfriend_list = []\n\tn,m,b = gets.split.map(&:to_i)\n\n\t(1..n).each do |ind|\n\t\tcost,monitor,nsolve=gets.split.map(&:to_i)\n\t\tarray = gets.split.map(&:to_i)\n\t\tfriend_list.push(Friend.new(cost,monitor,nsolve,array))\n\tend\n\n\tarray = [0]*(m+1)\n\n\t(0..m).each do |ind|\n\t\tarray[ind] = []\n\tend\n\n\t(0...friend_list.size).each do |ind|\n\t\tfriend_list[ind].array.each do |e|\n\t\t\tarray[e].push(friend_list[ind])\n\t\tend\n\tend \n\n\t#each element in array should be sorted.\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n\t\n\treturn n,m,b,array\nend\ndef index(problem)\n\n\ti,s=1,0\n\tsize = problem.size\n\twhile i= 1\n\t\tsolve(array, ind+1, problem, t, current, min)\n\telse\n\n\t\tif array[ind].empty?\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\n\t\tarray[ind].each do |e|\n\n\t\t\ti=e.monitor>current.monitor ? e.monitor-current.monitor : 0\n\t\t\tcost = current.cost+i*min.ruble+e.cost\n\t\t\tnext if min.cost!=-1 and cost >= min.cost\n\t\t\tcurrent.cost, current.monitor = cost, current.monitor+i\n\t\t\te.array.each do |m|\n\t\t\t\tproblem[m]+=1\n\t\t\tend\n\n\n\t\t\t#print problem; puts\n\t\t\ti= index(problem)\n\t\t\tif t[i] == -1 or current.cost< t[i]\n\t\t\t\tt[i] = current.cost\n\t\t\t\tsolve(array, ind+1, problem,t, current,min)\n\t\t\tend\n\t\t\tcurrent.cost-= (e.cost+i*min.ruble)\n\t\t\tcurrent.monitor -= i\n\t\t\te.array.each do |m|\n\t\t\t\tproblem[m]-=1\n\t\t\tend\n\t\t\n\t\tend\n\tend\nend\n\n\ndef main\n\tn,m,b,array = init\n\n\n=begin \n\tarray[1].each do |e|\n\t\tputs (e.cost+e.monitor*b)/e.nsolve.to_f\n\tend\n=end\n\tcurrent, min, problem = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)\n\tt = [-1]*(1<<22)\n\tsolve(array, 1, problem, t,current, min)\n\tputs min.cost\n\nend\n\nmain\n\n\n\n\n\n\n\n"}, {"source_code": "\n#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')\n\nclass Friend\n\tdef initialize(cost, monitor, nsolve, array)\n\t\t@cost,@monitor, @nsolve, @array = cost,\n\t\t\tmonitor, nsolve, array\n\tend\n\tattr_accessor :cost, :monitor, :nsolve, :array\nend\n\nclass Min\n\tdef initialize(cost,monitor,ruble)\n\t\t@cost,@monitor,@ruble=cost,monitor,ruble\n\n\tend\n\tattr_accessor :cost, :monitor, :ruble\nend\n\ndef init\n\n\tfriend_list = []\n\tn,m,b = gets.split.map(&:to_i)\n\n\t(1..n).each do |ind|\n\t\tcost,monitor,nsolve=gets.split.map(&:to_i)\n\t\tarray = gets.split.map(&:to_i)\n\t\tfriend_list.push(Friend.new(cost,monitor,nsolve,array))\n\tend\n\n\tarray = [0]*(m+1)\n\n\t(0..m).each do |ind|\n\t\tarray[ind] = []\n\tend\n\n\t(0...friend_list.size).each do |ind|\n\t\tfriend_list[ind].array.each do |e|\n\t\t\tarray[e].push(friend_list[ind])\n\t\tend\n\tend \n\n\t#each element in array should be sorted.\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n\t\n\treturn n,m,b,array\nend\n\ndef solve(array,ind,problem,current,min)\n\n\tif ind==array.size\n\t\tif current.cost= 1\n\t\tsolve(array, ind+1, problem, current, min)\n\telse\n\n\t\tif array[ind].empty?\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\n\t\tarray[ind].each do |e|\n\n\t\t\ti=e.monitor>current.monitor ? e.monitor-current.monitor : 0\n\t\t\tcost = current.cost+i*min.ruble+e.cost\n\t\t\tnext if cost > min.cost\n\t\t\tcurrent.cost, current.monitor = cost, current.monitor+i\n\t\t\te.array.each do |m|\n\t\t\t\tproblem[m]+=1\n\t\t\tend\n\t\t\t#print problem\n\t\t\tsolve(array, ind+1, problem, current,min)\n\t\t\tcurrent.cost-= (e.cost+i*min.ruble)\n\t\t\tcurrent.monitor -= i\n\t\t\te.array.each do |m|\n\t\t\t\tproblem[m]-=1\n\t\t\tend\n\t\t\n\t\tend\n\tend\nend\n\n\ndef main\n\tn,m,b,array = init\n\n\n=begin \n\tarray[1].each do |e|\n\t\tputs (e.cost+e.monitor*b)/e.nsolve.to_f\n\tend\n=end\n\tcurrent, min, problem = Min.new(0,0,b), Min.new(1<<32,0,b), [0]*(m+1)\n\tsolve(array, 1, problem, current, min)\n\tputs min.cost\n\nend\n\nmain\n\n\n\n\n\n\n\n"}, {"source_code": "\n#$stdin.reopen('/cygdrive/d/input.txt', 'r')\n\nclass Friend\n\tdef initialize(cost, monitor, nsolve, array)\n\t\t@cost,@monitor, @nsolve, @array = cost,\n\t\t\tmonitor, nsolve, array\n\tend\n\tattr_accessor :cost, :monitor, :nsolve, :array\nend\n\nclass Min\n\tdef initialize(cost,monitor,ruble)\n\t\t@cost,@monitor,@ruble=cost,monitor,ruble\n\n\tend\n\tattr_accessor :cost, :monitor, :ruble\nend\n\ndef init\n\n\tfriend_list = []\n\tn,m,b = gets.split.map(&:to_i)\n\n\t(1..n).each do |ind|\n\t\tcost,monitor,nsolve=gets.split.map(&:to_i)\n\t\tarray = gets.split.map(&:to_i)\n\t\tfriend_list.push(Friend.new(cost,monitor,nsolve,array))\n\tend\n\n\tarray = [0]*(m+1)\n\n\t(0..m).each do |ind|\n\t\tarray[ind] = []\n\tend\n\n\t(0...friend_list.size).each do |ind|\n\t\tfriend_list[ind].array.each do |e|\n\t\t\tarray[e].push(friend_list[ind])\n\t\tend\n\tend \n\n\t#each element in array should be sorted.\n\n\tarray.each do |e|\n\t\te.sort! do |a,c|\n\t\t\tif (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f\n\t\t\t\t1\n\t\t\telse\n\t\t\t\t-1\n\t\t\tend\n\t\tend\n\tend\n\t\n\treturn n,m,b,array\nend\n\ndef index(problem)\n\n\ti,s=1,0\n\tsize = problem.size\n\twhile i=1\n\t\ti+=1\n\tend\n\ts\nend\n\ndef solve(array,ind,problem,t,current,min)\n\n\tif ind==array.size\n\t\t\n\t\tif min.cost == -1 or current.cost= 1\n\t\tsolve(array, ind+1, problem, t, current, min)\n\telse\n\n\t\tif array[ind].empty?\n\t\t\tputs -1\n\t\t\texit 0\n\t\tend\n\n\t\tarray[ind].each do |e|\n\n\t\t\ti=e.monitor>current.monitor ? e.monitor-current.monitor : 0\n\t\t\tcost = current.cost+i*min.ruble+e.cost\n\t\t\tnext if (min.cost!=-1 and cost >= min.cost)\n\t\t\tcurrent.cost, current.monitor = cost, current.monitor+i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]+=1\n\t\t\tend\n\t\t\t#print problem; puts\n\n\t\t\tm= index(problem)\n\t\t\tif t[m] == -1 or current.cost< t[m]\n\t\t\t\tt[m] = current.cost\n\t\t\t\tsolve(array, ind+1, problem,t, current,min)\n\t\t\tend\n\t\t\tcurrent.cost-= (e.cost+i*min.ruble)\n\t\t\tcurrent.monitor -= i\n\t\t\te.array.each do |ind|\n\t\t\t\tproblem[ind]-=1\n\t\t\tend\n\t\t\n\t\tend\n\tend\nend\n\n\ndef main\n\tn,m,b,array = init\n=begin\n\tarray[1].each do |e|\n\t\tputs (e.cost+e.monitor*b)/e.nsolve.to_f\n\tend\n=end\n\tcurrent, min, problem = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)\n\tt = [-1]*(1<<22)\n\tsolve(array, 1, problem, t,current, min)\n\tputs min.cost\n\n\nend\n\nmain\n\n\n\n\n\n\n\n"}], "src_uid": "bc5b2d1413efcaddbf3bf1d905000159"} {"source_code": "buf = STDIN.gets.chomp.split\nn = buf[0].to_i\nm = buf[1].to_i\nprices = STDIN.gets.chomp.split\nfor i in 0 .. prices.size-1\n prices[i] = prices[i].to_i\nend\nprices.sort!\n\nhash = Hash.new\nm.times { |i|\n name = STDIN.gets.chomp\n if (name == nil)\n puts \"ERROR\"\n end\n if (hash[name] == nil)\n hash[name] = 1\n else\n hash[name] += 1\n end\n}\n\nnums = []\nhash.each_value { |i|\n nums.push(i)\n}\n\nnums.sort!\n\nminT = 0\nmaxT = 0\nfor i in 0..nums.size-1\n minT += nums[nums.size-1-i]*prices[i]\n maxT += nums[nums.size-1-i]*prices[prices.size-1-i]\nend\nputs minT.to_s + \" \" + maxT.to_s\n\n\n \n", "positive_code": [{"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\nprices = gets.chomp.split(/ /).map!{|x| x.to_i}\nh = Hash.new\nfor i in 0..m-1\n\ts = gets.chomp\n\tif h.key?(s)\n\t\twk = h[s]\n\t\th[s] = wk+1\n\telse\n\t\th[s] = 1\n\tend\nend\n\nsum1 = 0\nsum2 = 0\nha = h.to_a.sort!{ |a,b| b[1] <=> a[1] }\nprices.sort!\nfor i in 0..ha.length-1\n\tsum1 += ha[i][1]*prices[i]\n\tsum2 += ha[i][1]*prices[(prices.length-1)-i]\nend\nputs sum1.to_s + \" \" + sum2.to_s"}, {"source_code": "#!/usr/bin/ruby\nn=gets.chomp.split(\" \").map!{|i|i=i.to_i}\na=gets.chomp.split(\" \").map!{|i|i=i.to_i}.sort\nb=a.reverse\nh=Hash.new\nh.default=0\nn[1].times{|i|\n h[gets.chomp]+=1;\n}\ng=h.values.sort.reverse\nm=M=0\ng.length.times{|i|\n m+=g[i]*a[i]\n M+=g[i]*b[i]\n}\nputs \"#{m} #{M}\"\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\ncosts=[gets.split.map(&:to_i).sort]\ncosts.push(costs[0].reverse)\nfruit=Hash.new\nfruit.default=0\nm.times{ fruit[gets.split[0]]+=1 }\nans=[0,0]\nfruit.size.times{|i|\n found=false\n m.downto(1){|j|\n fruit.each{|a,b|\n if b==j then\n 2.times{|k| ans[k]+=j*costs[k][i] }\n found=a\n break\n end\n }\n fruit[found]=0\n break if found!=false\n }\n}\nprintf \"%d %d\\n\",ans[0],ans[1]\n"}, {"source_code": "fruits = {}\n\nn,m = gets.split.map(&:to_i)\nprices = gets.split.map(&:to_i)\nm.times do\n\tfruit = gets.chomp\n\tif !fruits[fruit]\n\t\tfruits[fruit] = 1\n\telse\n\t\tfruits[fruit] += 1\n\tend\nend\n\nnumbers = fruits.values.sort!.reverse!\n\nprices.sort!\nmin_cost = 0\nfor i in 0...numbers.size\n\tmin_cost += prices[i] * numbers[i]\nend\nprint \"#{min_cost} \"\n\nprices.reverse!\nmax_cost = 0\nfor i in 0...numbers.size\n\tmax_cost += prices[i] * numbers[i]\nend\nputs max_cost"}, {"source_code": " #!/usr/bin/ruby\n n=gets.chomp.split(\" \").map!{|i|i=i.to_i}\n a=gets.chomp.split(\" \").map!{|i|i=i.to_i}.sort\n b=a.reverse\n h=Hash.new\n h.default=0\n n[1].times{|i|\n h[gets.chomp]+=1;\n }\n g=h.values.sort.reverse\n m=M=0\n g.length.times{|i|\n m+=g[i]*a[i]\n M+=g[i]*b[i]\n }\n puts \"#{m} #{M}\""}, {"source_code": "str=gets\nstr.chomp!\ntmp=str.split()\nnum=tmp[1].to_i\nstr2=gets\nstr2.chomp!\nmemo=[]\nstr2.split().each do |s|\n memo << s.to_i\nend\nmemo.sort!\nmax=0\nmin=0\nhash=Hash.new\nwhile name=gets\n name.chomp!\n if(hash.key?(name)==false)\n hash.store(name,1)\n else\n hash.store(name,hash[name]+1)\n end\nend\nnumber=hash.values\nnumber=number.sort_by{|i| -i}\nhash.length.times do |i|\n min+=number[i]*memo[i]\n max+=number[i]*memo[memo.length-1-i]\nend\nprintf(\"%d %d\\n\",min,max)\n"}, {"source_code": "n,m=gets.split.map(&:to_i)\nprices = gets.split.map(&:to_i)\nprices.sort!\n#p prices\nfruits = Hash.new\nm.times do\n f = gets.chomp\n if fruits[f] == nil then \n fruits[f] = 1\n else\n fruits[f] += 1\n end\nend\n#p fruits\nfvalues = fruits.values\nfvalues.sort!\nfvalues.reverse!\nlen = n < fvalues.length() ? n : fvalues.length()\n\nsum = 0\nlen.times do |i|\n sum += fvalues[i] * prices[i]\nend\nprint sum, \" \"\n\nprices.reverse!\nsum = 0\nlen.times do |i|\n sum += fvalues[i] * prices[i]\nend\nprint sum\nputs\n\n\n"}, {"source_code": "n,m = gets.chomp.split(/ /).map!{|x| x.to_i}\nprices = gets.chomp.split(/ /).map!{|x| x.to_i}\nh = Hash.new\nfor i in 0..m-1\n s = gets.chomp\n if h.key?(s)\n wk = h[s]\n h[s] = wk+1\n else\n h[s] = 1\n end\nend\n\nsum1 = 0\nsum2 = 0\nha = h.to_a.sort!{ |a,b| b[1] <=> a[1] }\nprices.sort!\nfor i in 0..ha.length-1\n sum1 += ha[i][1]*prices[i]\n sum2 += ha[i][1]*prices[(prices.length-1)-i]\nend\nputs sum1.to_s + \" \" + sum2.to_s"}, {"source_code": "a=gets().chomp().split(' ').map(&:to_i)\nb = gets().chomp().split(' ').map(&:to_i).sort!{|x,y| x<=>y}\nh=Hash.new\na[1].times { temp=gets().chomp; (h.has_key?(temp)) ? h[temp]+=1 : h[temp]=1 }\nh= (h.sort_by{|_key, value| value}).reverse\ns=0;e=b.length()-1;max=0;min=0\nh.each(){|key,value| min+=value.to_i*b[s];max+=value.to_i*b[e];s+=1;e-=1; }\nprint min,' ', max"}, {"source_code": "\nfruits = Hash.new { |hash, key| hash[key] = 0 }\nn, m = STDIN.readline.chomp.split.map { |c| Integer(c) }\nprices = STDIN.readline.chomp.split.map { |c| Integer(c) }\nm.times do \n fruits[STDIN.readline.chomp] += 1\nend\n\nprices.sort!\nfruits_sorted_d = fruits.sort { |a, b| b[1] <=> a[1] }\n\nmin_value, max_value = 0, 0\nfruits_sorted_d.each_with_index do |value, index|\n min_value += (prices[index] * value[1])\n max_value += (prices[prices.size - 1 - index] * value[1])\nend\n\nputs \"#{min_value} #{max_value}\"\n\n"}, {"source_code": "n, m = gets.split.map(&:to_i)\nprice = gets.split.map(&:to_i).sort\nfruits = {}\nm.times do\n\tfruit = gets.chomp\n\tfruits.has_key?(fruit) ? fruits[fruit] += 1 : fruits[fruit] = 1\nend\ncount = fruits.values.sort.reverse\nmn, mx = 0, 0\ncount.each_index{|i| mn, mx = mn + price[i] * count[i], mx + price[n-1-i] * count[i]}\nputs \"#{mn} #{mx}\"\n"}], "negative_code": [], "src_uid": "31c43b62784a514cfdb9ebb835e94cad"} {"source_code": "\n\nn = gets.to_i\na = gets.strip.split(' ').map {|x| x.to_i}\nh = Hash.new 0\na.each do |e|\n if e > 0\n h[1] += 1\n elsif e < 0\n h[-1] += 1\n else\n h[0] += 1\n end\nend\nm = h[-1]%2\nk = (n%2 == 1) ? 0 : m\naa = a.map {|e| e.abs}.sort\na1 = aa[0,k]\na2 = aa[k..-1]\nputs( a2.inject(0, :+) - a1.inject(0, :+) )", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nm = a.count{|i| i < 0}\na = a.map(&:abs)\ns = a.inject(&:+)\ns -= 2 * a.min if n.even? && m.odd?\np s\n"}, {"source_code": "def run\n n = $stdin.gets.to_i\n a = $stdin.gets.split.map(&:to_i)\n m = a.count {|x| x < 0}\n a.map!(&:abs)\n s = a.reduce(&:+)\n s -= 2 * a.min if n.even? && m.odd?\n p s\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n = gets.to_i\na = gets.split(\" \").map{|s| s.to_i}\na = a.sort\nans = 0\nif n%2==1\n a.each {|x| ans+=x.abs}\nelse\n\tdlt=0\n\ta.each_with_index {|x,i| ans+=x;dlt=[-ans,dlt].max if i%2==1}\n\tans+=dlt+dlt\nend\np ans"}], "negative_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nm = a.count{|i| i < 0}\na = a.map(&:abs)\ns = a.inject(&:+)\ns -= 2 * a.min if m.odd?\np s\n"}, {"source_code": "def convert(a, n)\n a[0, n].map {|x| x *= -1} + a[n, n - 1]\nend\n\ndef run\n n = $stdin.gets.to_i\n a = $stdin.gets.split.map(&:to_i).sort\n s = a.reduce(:+)\n\n 2.times do\n a1 = convert(a, n)\n s1 = a1.reduce(:+)\n a = a1.sort if s1 > s\n end\n\n puts a.reduce(:+)\nend\n\nrun if $0 == __FILE__\n"}], "src_uid": "9b907b3e96e78c84d11032a0f0b0fa53"} {"source_code": "class DisjointSet\n\tdef initialize(n)\n\t\t@p = [*0..n]\n\tend\n\t\n\tdef root(i)\n\t\ti == @p[i] ? i : @p[i] = root(@p[i])\n\tend\n\n\tdef setp(i, j)\n\t\ti = root(i)\n\t\tj = root(j)\n\t\treturn if i == j\n\t\t@p[i] = j\n\tend\nend\n\nn = gets.to_i\ne = n.times.map{[]}\nd = DisjointSet.new(n + 1)\nx = []\n(2..n).each{\n\ta, b = gets.split.map(&:to_i)\n\tx << [a, b] unless d.setp(a, b)\n}\np x.size\n(2..n).each{|i|\n\tnext unless d.setp(i - 1, i)\n\tputs \"#{x[0][0]} #{x[0][1]} #{i - 1} #{i}\"\n\tx.shift\n}\n\n\n", "positive_code": [{"source_code": "class DisjointSet\n\tdef initialize(n)\n\t\t@p = [*0..n]\n\tend\n\t\n\tdef root(i)\n\t\ti == @p[i] ? i : @p[i] = root(@p[i])\n\tend\n\n\tdef setp(i, j)\n\t\ti = root(i)\n\t\tj = root(j)\n\t\treturn if i == j\n\t\t@p[i] = j\n\tend\nend\n\nn = gets.to_i\ne = n.times.map{[]}\nd = DisjointSet.new(n + 1)\nx = []\n(2..n).each{\n\ta, b = gets.split.map(&:to_i)\n\tx << [a, b] unless d.setp(a, b)\n}\np x.size\n(2..n).each{|i|\n\tnext unless d.setp(i - 1, i)\n\tputs \"#{x[0][0]} #{x[0][1]} #{i - 1} #{i}\"\n\tx.shift\n}\n\n\n"}, {"source_code": "class DisjointSet\n\tdef initialize(n)\n\t\t@p = [*0..n]\n\tend\n\t\n\tdef root(i)\n\t\ti == @p[i] ? i : @p[i] = root(@p[i])\n\tend\n\n\tdef setp(i, j)\n\t\ti = root(i)\n\t\tj = root(j)\n\t\treturn if i == j\n\t\t@p[i] = j\n\tend\nend\n\nn = gets.to_i\ne = n.times.map{[]}\nd = DisjointSet.new(n + 1)\nx = []\n(2..n).each{\n\ta, b = gets.split.map(&:to_i)\n\tx << [a, b] unless d.setp(a, b)\n}\np x.size\n(2..n).each{|i|\n\tnext unless d.setp(i - 1, i)\n\tputs \"#{x[0][0]} #{x[0][1]} #{i - 1} #{i}\"\n\tx.shift\n}\n\n\n"}, {"source_code": "$n = gets.chomp.to_i\n\n$p = Array.new($n+1) {|i| i}\n$rank = Array.new($n+1, 0)\n\ndef find(x)\n while ($p[x]!=x)\n x=$p[x]\n end\n x\nend\n\ndef union(x, y)\n px = find(x)\n py = find(y)\n return if px==py\n if $rank[px]<$rank[py]\n $p[px]=py\n else\n $p[py]=px\n $rank[px]=$rank[px]+1 if $rank[px]==$rank[py]\n end\nend\n\ndef find_need_road()\n 1.upto($n-1){|i|\n (i+1).upto($n){|j|\n return i, j if find(i)!=find(j)\n }\n }\nend\n\nbad_roads = []\n($n-1).times{\n x, y = gets.chomp.split(' ').map{|i| i.to_i}\n x, y = y, x if x > y\n if find(x)!=find(y)\n union(x, y)\n else\n bad_roads << [x, y]\n end\n}\n\nputs bad_roads.size\nbad_roads.size.times{|t|\n a, b = find_need_road()\n union(a, b)\n puts \"#{bad_roads[t][0]} #{bad_roads[t][1]} #{a} #{b}\"\n}"}, {"source_code": "class DisjointSet\n\tdef initialize(n)\n\t\t@p = [*0..n]\n\tend\n\t\n\tdef root(i)\n\t\ti == @p[i] ? i : @p[i] = root(@p[i])\n\tend\n\n\tdef setp(i, j)\n\t\ti = root(i)\n\t\tj = root(j)\n\t\treturn if i == j\n\t\t@p[i] = j\n\tend\nend\n\nn = gets.to_i\ne = n.times.map{[]}\nd = DisjointSet.new(n + 1)\nx = []\n(2..n).each{\n\ta, b = gets.split.map(&:to_i)\n\tx << [a, b] unless d.setp(a, b)\n}\np x.size\n(2..n).each{|i|\n\tnext unless d.setp(i - 1, i)\n\tputs \"#{x[0][0]} #{x[0][1]} #{i - 1} #{i}\"\n\tx.shift\n}\n\n\n"}, {"source_code": "class DisjointSet\n\tdef initialize(n)\n\t\t@p = [*0..n]\n\tend\n\t\n\tdef root(i)\n\t\ti == @p[i] ? i : @p[i] = root(@p[i])\n\tend\n\n\tdef setp(i, j)\n\t\ti = root(i)\n\t\tj = root(j)\n\t\treturn if i == j\n\t\t@p[i] = j\n\tend\nend\n\nn = gets.to_i\ne = n.times.map{[]}\nd = DisjointSet.new(n + 1)\nx = []\n(2..n).each{\n\ta, b = gets.split.map(&:to_i)\n\tx << [a, b] unless d.setp(a, b)\n}\np x.size\n(2..n).each{|i|\n\tnext unless d.setp(i - 1, i)\n\tputs \"#{x[0][0]} #{x[0][1]} #{i - 1} #{i}\"\n\tx.shift\n}\n\n\n"}, {"source_code": "class DisjointSet\n\tdef initialize(n)\n\t\t@p = [*0..n]\n\tend\n\t\n\tdef root(i)\n\t\ti == @p[i] ? i : @p[i] = root(@p[i])\n\tend\n\n\tdef setp(i, j)\n\t\ti = root(i)\n\t\tj = root(j)\n\t\treturn if i == j\n\t\t@p[i] = j\n\tend\nend\n\nn = gets.to_i\ne = n.times.map{[]}\nd = DisjointSet.new(n + 1)\nx = []\n(2..n).each{\n\ta, b = gets.split.map(&:to_i)\n\tx << [a, b] unless d.setp(a, b)\n}\np x.size\n(2..n).each{|i|\n\tnext unless d.setp(i - 1, i)\n\tputs \"#{x[0][0]} #{x[0][1]} #{i - 1} #{i}\"\n\tx.shift\n}\n\n"}, {"source_code": "class DisjointSet\n\tdef initialize(n)\n\t\t@p = [*0..n]\n\tend\n\t\n\tdef root(i)\n\t\ti == @p[i] ? i : @p[i] = root(@p[i])\n\tend\n\n\tdef setp(i, j)\n\t\ti = root(i)\n\t\tj = root(j)\n\t\treturn if i == j\n\t\t@p[i] = j\n\tend\nend\n\nn = gets.to_i\ne = n.times.map{[]}\nd = DisjointSet.new(n + 1)\nx = []\n(2..n).each{\n\ta, b = gets.split.map(&:to_i)\n\tx << [a, b] unless d.setp(a, b)\n}\np x.size\n(2..n).each{|i|\n\tnext unless d.setp(i - 1, i)\n\tputs \"#{x[0][0]} #{x[0][1]} #{i - 1} #{i}\"\n\tx.shift\n}\n\n\n"}, {"source_code": "class DisjointSet\n\tdef initialize(n)\n\t\t@p = [*0..n]\n\tend\n\t\n\tdef root(i)\n\t\ti == @p[i] ? i : @p[i] = root(@p[i])\n\tend\n\n\tdef setp(i, j)\n\t\ti = root(i)\n\t\tj = root(j)\n\t\treturn if i == j\n\t\t@p[i] = j\n\tend\nend\n\nn = gets.to_i\ne = n.times.map{[]}\nd = DisjointSet.new(n + 1)\nx = []\n(2..n).each{\n\ta, b = gets.split.map(&:to_i)\n\tx << [a, b] unless d.setp(a, b)\n}\np x.size\n(2..n).each{|i|\n\tnext unless d.setp(i - 1, i)\n\tputs \"#{x[0][0]} #{x[0][1]} #{i - 1} #{i}\"\n\tx.shift\n}\n\n\n"}, {"source_code": "class DisjointSet\n\tdef initialize(n)\n\t\t@p = [*0..n]\n\tend\n\t\n\tdef root(i)\n\t\ti == @p[i] ? i : @p[i] = root(@p[i])\n\tend\n\n\tdef setp(i, j)\n\t\ti = root(i)\n\t\tj = root(j)\n\t\treturn if i == j\n\t\t@p[i] = j\n\tend\nend\n\nn = gets.to_i\ne = n.times.map{[]}\nd = DisjointSet.new(n + 1)\nx = []\n(2..n).each{\n\ta, b = gets.split.map(&:to_i)\n\tx << [a, b] unless d.setp(a, b)\n}\np x.size\n(2..n).each{|i|\n\tnext unless d.setp(i - 1, i)\n\tputs \"#{x[0][0]} #{x[0][1]} #{i - 1} #{i}\"\n\tx.shift\n}\n\n\n"}], "negative_code": [], "src_uid": "1c1641aeb850e5b20a4054e839cc22e4"} {"source_code": "n = gets.to_i\n\nif n == 1 or n == 2\n\tputs -1\nelsif n.odd?\n\tu = n\n\tv = 1\n\tputs [(u ** 2 - v ** 2) / 2, (u ** 2 + v ** 2) / 2].join ' '\nelse\n\tu = n / 2\n\tv = 1\n\tputs [u ** 2 - v ** 2, u ** 2 + v ** 2].join ' '\nend", "positive_code": [{"source_code": "n = gets.chomp.to_i\nfound = false\nm = 0\nk = 0\n\nif n % 2 == 1 && (1 + (n ** 2)) % 2 == 0\n\tm = (1 + (n ** 2)) / 2\n\tk = ((n ** 2 ) - 1) / 2\n\t\n\tif k != 0\n\t\tputs \"#{m} #{k}\"\n\t\texit\n\tend\nend\n\nif n % 2 == 0 && (2 + ((n ** 2) / 2)) % 2 == 0\n\tm = (2 + ((n ** 2) / 2)) / 2\n\tk = (((n ** 2) / 2) - 2) / 2\n\n\tif k != 0\n\t\tputs \"#{m} #{k}\"\n\t\texit\n\tend\nend\n\n\n\nputs -1\n"}, {"source_code": "n = gets.to_i \n\nif n == 1 or n == 2 \n puts \"-1\" \nelsif n%2 != 0 \n x = (n**2)/2 \n puts x.to_s + \" \" + (x+1).to_s \nelse \n x = (n**2)/4\n puts (x-1).to_s + \" \" + (x+1).to_s \nend \n"}, {"source_code": "# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n############################################################\ndef gs() gets.chomp end\ndef gi() gets.to_i end\ndef gss() gs.split end\ndef gis() gss.map(&:to_i) end\ndef nmapf(n,f) n.times.map{ __send__ f } end\ndef ngs(n) nmapf n,:gs end\ndef ngi(n) nmapf n,:gi end\ndef ngss(n) nmapf n,:gss end\ndef ngis(n) nmapf n,:gis end\ndef arr2d(h,w,v=0) h.times.map{[v] * w} end\ndef for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end\ndef nsum(n) n * (n + 1) / 2 end\ndef vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end\n############################################################\n\nn = gi\n\n# x ** 2 == z ** 2 - y ** 2 = (z + y) * (z - y)\n\nm = (n ** 2) / 2\nk = m + 1\nif n.even?\n m /= 2\n k = m + 1\n m -= 1\nend\n\nif m > 0 && k > 0 && n ** 2 + m ** 2 == k ** 2\n puts \"%d %d\" % [m, k]\nelse\n puts -1\nend\n\n"}, {"source_code": "a = gets.to_i\nputs a<3 ? -1 : a%2==1 ? [a**2/2, a**2/2+1] : [a**2/4-1, a**2/4+1]"}, {"source_code": "n = gets.to_i\nif n == 1 || n == 2\n puts -1\nelse\n n2 = n\n n2 /= 2 while n2 % 2 == 0\n if n2 == 1\n time = n / 4\n puts \"#{3 * time} #{5 * time}\"\n else\n time = n / n2\n a = n2 * n2 / 2\n m, k = a * time, (a + 1) * time\n puts \"#{m} #{k}\"\n end\nend\n"}, {"source_code": "require 'prime'\nn = gets.to_i\nfactors = n.prime_division\nif n == 1 || n == 2\n puts -1\nelsif factors.size == 1 && factors[0][0] == 2\n time = n / 4\n puts \"#{3 * time} #{5 * time}\"\nelse\n n2 = n\n n2 /= 2 while n2 % 2 == 0\n time = n / n2\n a = ((n2 ** 2) - 1) / 2\n m, k = a * time, (a + 1) * time\n puts \"#{m} #{k}\"\nend\n"}, {"source_code": "n = gets.to_i\nif n == 1 || n == 2\n puts -1\n exit\nend\n\nif (n & (-n)) == n\n puts [3 * n / 4, 5 * n / 4]*' '\nelse\n d = n & (-n)\n q = n / d\n puts [(q * q - 1) / 2 * d, (q * q + 1) / 2 * d]*' '\nend\n\n"}], "negative_code": [{"source_code": "a = gets.to_i\nputs a<3 ? -1 : a%2 ? [a**2/2, a**2/2+1] : [a**2/4*2, a**2/4*2+2]"}, {"source_code": "a = gets.to_i\nputs a<3 ? -1 : a%2 ? [a**2/2, a**2/2+1] : [a**2/2, a**2/2+2]"}, {"source_code": "n = gets.to_i\nif (n ** 2).odd?\n a = ((n ** 2) - 1) / 2\n m, k = a, a + 1\nelse\n nn = n / 2\n a = ((nn ** 2) - 1) / 2\n m, k = a * 2, a * 2 + 1\nend\nputs n == 1 || n == 2 ? -1 : \"#{m} #{k}\"\n"}, {"source_code": "n = gets.to_i\nif (n ** 2).odd?\n a = ((n ** 2) - 1) / 2\n m, k = a, a + 1\nelse\n nn = n / 2\n a = ((nn ** 2) - 1) / 2\n m, k = a * 2, (a + 1) * 2\nend\nputs n == 1 || n == 2 ? -1 : \"#{m} #{k}\"\n"}], "src_uid": "df92643983d6866cfe406f2b36bec17f"} {"source_code": "(1..(n=gets.to_i)).to_a.each_slice((n**0.5).to_i).to_a.reverse.flatten.each {|x| print \"#{x} \"}", "positive_code": [{"source_code": "N = gets.to_i\nM = Math.sqrt(N).floor\nans = []\n(N/M).downto(0) do |i|\n ((i*M+1)..(i*M+M)).each do |j|\n ans.push(j) if j <= N\n end\nend\nputs ans.join(' ')"}, {"source_code": "n = gets.chomp.to_i\n\nst = Math.sqrt(n).to_i\n\n(1..n).step(st) do |i|\n [i+st-1,n].min.downto(i) { |j| print \"#{j} \" }\nend\n\nputs \"\"\n"}], "negative_code": [], "src_uid": "6ea899e915cfc95a43f0e16d6d08cc1e"} {"source_code": "gets.to_i.times {\n puts gets.to_i / 2\n}\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do \n n = gets.chomp.to_i\n if n % 2 == 0\n aa = n\n puts aa / 2\n elsif n % 2 == 1\n a = n - 1\n puts a / 2\n end\nend\n"}, {"source_code": "gets.to_i.times do\n puts gets.to_i.div(2)\nend\n"}], "negative_code": [], "src_uid": "b46244f39e30c0cfab592a97105c60f4"} {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\n\ndef jo(n,d)\n return n if(d == 1)\n a = jo(n,d/2)\n return a if(a > 100000)\n return a * jo(n,d-d/2)\n return jo(n,d/2) * jo(n,d-d/2)\nend\n\nrequire 'prime'\n\n\ntrr = Hash.new(0)\n\nn,k = inp\nt = inp\nper = 0\nans = 0\nt.each.with_index do |d,i|\n f = true\n tt = d.prime_division\n ttt = 1\n tttttt = 1\n f = false\n tt.each.with_index do |a,i|\n r = a[1]%k\n next if r == 0\n ttt *= jo(a[0],r)\n tttttt *= jo(a[0],(k-r))\n if(tttttt > 100000)\n f = true\n break\n end\n end\n next if f\n ans += trr[tttttt]\n trr[ttt] += 1\nend\n\n\np ans", "positive_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n \ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n \ndef inps() a=gets.chomp.split(\" \")end\n \ndef copy(a) Marshal.load(Marshal.dump(a)) end\n \ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n \ndef na(n,d=0) Array.new(n,d)end\n \ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n \ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n \ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n \ndef r_up(a, b) (a+b-1)/b end\n \ndef sum(a) a.inject(:+) end\n \n \ndef jo(n,d)\n return n if(d == 1)\n a = jo(n,d/2)\n return a if(a > 100000)\n return a * jo(n,d-d/2)\n return jo(n,d/2) * jo(n,d-d/2)\nend\n \nrequire 'prime'\n \n \ntrr = Hash.new(0)\n \nn,k = inp\nt = inp\nper = 0\nans = 0\nt.each.with_index do |d,i|\n f = true\n tt = d.prime_division\n ttt = 1\n tttttt = 1\n f = false\n tt.each.with_index do |a,i|\n r = a[1]%k\n next if r == 0\n ttt *= jo(a[0],r)\n tttttt *= jo(a[0],(k-r))\n if(tttttt > 100000)\n f = true\n break\n end\n end\n next if f\n ans += trr[tttttt]\n trr[ttt] += 1\nend\n \n \np ans"}], "negative_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\n\ndef jo(n,d)\n return n if(d == 1)\n return jo(n,d/2) * jo(n,d-d/2)\nend\n\nrequire 'prime'\n\n\ntrr = Hash.new(0)\n\nn,k = inp\nt = inp\nper = 0\nans = 0\nhh = {}\nt.each.with_index do |d,i|\n f = true\n tt = d.prime_division\n ttt = 1\n tttttt = 1\n f = false\n tt.each.with_index do |a,i|\n r = a[1]%k\n if(hh[a[0]] == true)\n f = true\n break\n elsif(hh[a[0]] == nil)\n hh[a[0]] = (jo(a[0],k) > 100000)\n f = hh[a[0]]\n break if f\n end\n next if r == 0\n ttt *= jo(a[0],r)\n tttttt *= jo(a[0],(k-r))\n end\n next if f == true\n ans += trr[tttttt]\n trr[ttt] += 1\nend\n\n\np ans"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nrequire 'prime'\n\nh = Hash.new(0)\n\nn,k = inp\nt = inp\ntf = na(n,false)\nper = 0\nt.each.with_index do |d,i|\n f = true\n tt = d.prime_division\n ttt = []\n tt.each.with_index do |a,i|\n f = false if a[1]%k != 0\n ttt << [a[0],a[1]%k] if a[1]%k != 0\n end\n if f\n tf[i] = true\n per += 1\n end\n h[ttt] += 1\nend\nans = 0\n\nt.each.with_index do |d,i|\n if tf[i]\n per -= 1\n ans += per\n else\n tt = d.prime_division\n h[tt] -= 1\n ttt = []\n tt.each do |a|\n ttt << [a[0],k-a[1]%k]\n end\n ans += h[ttt]\n end\nend\n\np ans"}, {"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\nrequire 'prime'\n\nh = Hash.new(0)\n\nn,k = inp\nt = inp\ntf = na(n,false)\nper = 0\nt.each.with_index do |d,i|\n f = true\n tt = d.prime_division\n ttt = []\n tt.each.with_index do |a,i|\n f = false if a[1] != k\n ttt << a if a[1]%3 != 0\n end\n if f\n tf[i] = true\n per += 1\n end\n h[ttt] += 1\nend\nans = 0\nt.each.with_index do |d,i|\n if tf[i]\n per -= 1\n ans += per\n else\n tt = d.prime_division\n h[tt] -= 1\n ttt = []\n tt.each do |a|\n ttt << [a[0],k-a[1]%3]\n end\n ans += h[ttt]\n end\nend\n\np ans"}], "src_uid": "a8c5b1377035f0a772510b5b80588d47"} {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nx=a.min\nres=n+1\nl=-n, r=-n\na.each_with_index{|e, i|\n next if e!=x\n if r<0\n r=i\n else\n l=r\n r=i\n res=r-l if res>r-l\n end\n}\nputs res\n", "positive_code": [{"source_code": "n,*a=$<.read.split.map &:to_i\nb=[]\nm=1<<30\na.each_with_index{|e,i|(b=[];m=e)if m>e;b< n\n puts \"-1\"\n else\n ret = []\n n.times do |i|\n if i < k * 2\n ret << (i / 2) + 1\n else\n ret << (i % k) + 1\n end\n end\n puts ret.join(\" \")\n end\nend\n\nrun if $0 == __FILE__\n", "positive_code": [{"source_code": "n, k = gets.split.map &:to_i\n\nif n < 3*k\n\tputs -1\n\texit\nend\n\nt = 1\nfor i in 1..k\n\tprint t.to_s + \" \" + t.to_s + \" \"\n\tt+=1\nend\n\nt=1\nfor i in 1..k\n\tprint t.to_s + \" \"\n\tt+=1\nend\n\nfor i in 1..(n-3*k)\n\tprint 1, \" \"\nend"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\nif 3*k > n\n\tputs -1\n\texit\nend\n\nkeepers = (1..k).collect {|x| x }\nassignments = []\n(1..k).each do |i|\n\tassignments.push(i)\n\tassignments.push(i)\nend\n(2*k..n-1).each do |i|\n\tassignments.push(keepers[i%k])\nend\nputs assignments.join(' ')\n\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\n# def arifm?(arr)\n# \tresult = true\n# \tarr.each_index do |i|\n# \t\tif i < arr.length - 3\n# \t\t\tresult = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]\n# \t\tend\n# \tend\n# \treturn result\n# end\n\n# p arifm?([1,\u20095,\u20099])\n\nif 3*k > n\n\tp -1\nelse\n\tmydr = Array.new(k)\n\tmydr.each_index do |i|\n\t\tmydr[i] = i % k + 1\n\tend\n\t# p mydr\n\tans = Array.new(n)\n\trot = false\n\tj = 0\n\tn.times do |i|\n\t\tif i < 2*k\n\t\t\tans[i] = mydr[j]\n\t\t\tj += 1 if rot\n\t\t\trot = !rot\n\t\t\tj = 0 if j > k-1\n\t\telse\n\t\t\tans[i] = mydr[i % k]\n\t\tend\n\tend\n\n\tprint ans.join(' ')\n\t# print \"\\n\"\nend\n"}], "negative_code": [{"source_code": "#!/usr/bin/ruby1.9\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\nif 3*k > n\n\tputs -1\n\texit\nend\n\nkeepers = (1..k).collect {|x| x }\nassignments = []\nkeeper_ix = 0\n(1..n).each do |pos|\n\tassignments.push(keepers[keeper_ix])\n\tkeeper_ix += 1\n\tif keeper_ix == keepers.length\n\t\tkeepers = keepers.rotate\n\t\tkeeper_ix = 0\n\tend\nend\nputs assignments.join(' ')\n\n"}, {"source_code": "def run\n n, k = ARGF.readline.split.map(&:to_i)\n if k * 3 > n\n puts \"-1\"\n else\n ret = []\n for i in 0..n\n if i < k * 2\n ret << (i / 2) + 1\n else\n ret << (i % k) + 1\n end\n end\n puts ret.join(\" \")\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\n# def arifm?(arr)\n# \tresult = true\n# \tarr.each_index do |i|\n# \t\tif i < arr.length - 3\n# \t\t\tresult = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]\n# \t\tend\n# \tend\n# \treturn result\n# end\n\n# p arifm?([1,\u20095,\u20099])\n\nif n / 3.0 < k\n\tp -1\nelse\n\tans = Array.new(n)\n\n\tn.times do |i|\n\t\tif i < k\n\t\t\tans[i] = k - i\n\t\telsif i < 2*k \n\t\t\tans[i] = i % k + 1\n\t\telsif i < 3*k\n\t\t\tans[i] = 3*k - i\n\t\telse\n\t\t\tans[i] = i % k + 1\n\t\tend\n\tend\n\n\tprint ans.join(' ')\n\t# print \"\\n\"\nend\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\n# def arifm?(arr)\n# \tresult = true\n# \tarr.each_index do |i|\n# \t\tif i < arr.length - 3\n# \t\t\tresult = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]\n# \t\tend\n# \tend\n# \treturn result\n# end\n\n# p arifm?([1,\u20095,\u20099])\n\nif n / 3.0 < k\n\tp -1\nelse\n\tmydr = Array.new(k)\n\tmydr.each_index do |i|\n\t\tmydr[i] = i % k + 1\n\tend\n\tmydr.rotate!\n\t# p mydr\n\tans = Array.new(n)\n\n\tn.times do |i|\n\t\tif i < k\n\t\t\tans[i] = k - i\n\t\telsif i < 2*k \n\t\t\tans[i] = i % k + 1\n\t\t# elsif i < 3*k\n\t\t# \tans[i] = 3*k - i\n\t\telse\n\t\t\tans[i] = mydr[i % k]\n\t\tend\n\tend\n\n\tprint ans.join(' ')\n\t# print \"\\n\"\nend\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\n# def arifm?(arr)\n# \tresult = true\n# \tarr.each_index do |i|\n# \t\tif i < arr.length - 3\n# \t\t\tresult = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]\n# \t\tend\n# \tend\n# \treturn result\n# end\n\n# p arifm?([1,\u20095,\u20099])\n\nif n / 3.0 < k\n\tp -1\nelse\n\tans = Array.new(n)\n\n\tn.times do |i|\n\t\tif i < k\n\t\t\tans[i] = k - i\n\t\telse\n\t\t\tans[i] = i % k + 1\n\t\tend\n\t\t\n\tend\n\n\tprint ans.join(' ')\n\t# print \"\\n\"\nend\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\n# def arifm?(arr)\n# \tresult = true\n# \tarr.each_index do |i|\n# \t\tif i < arr.length - 3\n# \t\t\tresult = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]\n# \t\tend\n# \tend\n# \treturn result\n# end\n\n# p arifm?([1,\u20095,\u20099])\n\nif 3*k > n\n\tp -1\nelse\n\tmydr = Array.new(k)\n\tmydr.each_index do |i|\n\t\tmydr[i] = i % k + 1\n\tend\n\tp mydr\n\tans = Array.new(n)\n\trot = false\n\tj = 0\n\tn.times do |i|\n\t\tif i < 2*k\n\t\t\tans[i] = mydr[j]\n\t\t\tj += 1 if rot\n\t\t\trot = !rot\n\t\t\tj = 0 if j > k-1\n\t\telse\n\t\t\tans[i] = mydr[i % k]\n\t\tend\n\tend\n\n\tprint ans.join(' ')\n\t# print \"\\n\"\nend\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\n# def arifm?(arr)\n# \tresult = true\n# \tarr.each_index do |i|\n# \t\tif i < arr.length - 3\n# \t\t\tresult = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]\n# \t\tend\n# \tend\n# \treturn result\n# end\n\n# p arifm?([1,\u20095,\u20099])\n\nif n / 3.0 < k\n\tp -1\nelse\n\tmydr = Array.new(k)\n\tmydr.each_index do |i|\n\t\tmydr[i] = i % k + 1\n\tend\n\tmydr.rotate!\n\t# p mydr\n\tans = Array.new(n)\n\trot = false\n\trot2 = false\n\tn.times do |i|\n\t\tif i < k\n\t\t\tans[i] = k - i\n\t\telsif i < 2*k \n\t\t\tans[i] = i % k + 1\n\t\telsif i < 3*k\n\t\t\tans[i] = mydr[i % k]\n\t\telsif i < 4*k\n\t\t\tans[i] = i % k + 1\n\t\telsif i < 5*k\n\t\t\tif !rot\n\t\t\t\tmydr.rotate!\n\t\t\t\trot = true\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\telse\n\t\t\tif !rot2\n\t\t\t\tmydr.rotate!.reverse!\n\t\t\t\trot2 = true\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\tend\n\tend\n\n\tprint ans.join(' ')\n\t# print \"\\n\"\nend\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\n# def arifm?(arr)\n# \tresult = true\n# \tarr.each_index do |i|\n# \t\tif i < arr.length - 3\n# \t\t\tresult = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]\n# \t\tend\n# \tend\n# \treturn result\n# end\n\n# p arifm?([1,\u20095,\u20099])\n\nif n / 3.0 < k\n\tp -1\nelse\n\tmydr = Array.new(k)\n\tmydr.each_index do |i|\n\t\tmydr[i] = i % k + 1\n\tend\n\tmydr.rotate!\n\t# p mydr\n\tans = Array.new(n)\n\trot = false\n\trot2 = false\n\tn.times do |i|\n\t\tif i < k\n\t\t\tans[i] = k - i\n\t\telsif i < 2*k \n\t\t\tans[i] = i % k + 1\n\t\telsif i < 100*k\n\t\t\tans[i] = mydr[i % k]\n\t\telsif i < 1000*k\n\t\t\tans[i] = i % k + 1\n\t\telsif i < 10000*k\n\t\t\tif !rot\n\t\t\t\tmydr.rotate!\n\t\t\t\trot = true\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\telse\n\t\t\tif !rot2\n\t\t\t\tmydr.rotate!\n\t\t\t\trot2 = true\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\tend\n\tend\n\n\tprint ans.join(' ')\n\t# print \"\\n\"\nend\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\n# def arifm?(arr)\n# \tresult = true\n# \tarr.each_index do |i|\n# \t\tif i < arr.length - 3\n# \t\t\tresult = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]\n# \t\tend\n# \tend\n# \treturn result\n# end\n\n# p arifm?([1,\u20095,\u20099])\n\nif n / 3.0 < k\n\tp -1\nelse\n\tmydr = Array.new(k)\n\tmydr.each_index do |i|\n\t\tmydr[i] = i % k + 1\n\tend\n\tmydr.rotate!\n\t# p mydr\n\tans = Array.new(n)\n\trot = false\n\trot2 = false\n\tn.times do |i|\n\t\tif i < k\n\t\t\tans[i] = k - i\n\t\telsif i < 2*k \n\t\t\tans[i] = i % k + 1\n\t\telsif i < 100*k\n\t\t\tans[i] = mydr[i % k]\n\t\telsif i < 1000*k\n\t\t\tans[i] = i % k + 1\n\t\telsif i < 10000*k\n\t\t\tif !rot\n\t\t\t\tmydr.rotate!\n\t\t\t\trot = true\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\telse\n\t\t\tif !rot2\n\t\t\t\tmydr.rotate!.reverse!\n\t\t\t\trot2 = true\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\tend\n\tend\n\n\tprint ans.join(' ')\n\t# print \"\\n\"\nend\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\n# def arifm?(arr)\n# \tresult = true\n# \tarr.each_index do |i|\n# \t\tif i < arr.length - 3\n# \t\t\tresult = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]\n# \t\tend\n# \tend\n# \treturn result\n# end\n\n# p arifm?([1,\u20095,\u20099])\n\nif n / 3.0 < k\n\tp -1\nelse\n\tmydr = Array.new(k)\n\tmydr.each_index do |i|\n\t\tmydr[i] = i % k + 1\n\tend\n\tmydr.rotate!\n\t# p mydr\n\tans = Array.new(n)\n\trot = false\n\tn.times do |i|\n\t\tif i < k\n\t\t\tans[i] = k - i\n\t\telsif i < 2*k \n\t\t\tans[i] = i % k + 1\n\t\telsif i < 100*k\n\t\t\tans[i] = mydr[i % k]\n\t\telsif i < 1000*k\n\t\t\tans[i] = i % k + 1\n\t\telse\n\t\t\tif !rot\n\t\t\t\tmydr.rotate!\n\t\t\t\trot = true\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\tend\n\tend\n\n\tprint ans.join(' ')\n\t# print \"\\n\"\nend\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\n# def arifm?(arr)\n# \tresult = true\n# \tarr.each_index do |i|\n# \t\tif i < arr.length - 3\n# \t\t\tresult = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]\n# \t\tend\n# \tend\n# \treturn result\n# end\n\n# p arifm?([1,\u20095,\u20099])\n\nif n / 3.0 < k\n\tp -1\nelse\n\tmydr = Array.new(k)\n\tmydr.each_index do |i|\n\t\tmydr[i] = i % k + 1\n\tend\n\tmydr.rotate!\n\t# p mydr\n\tans = Array.new(n)\n\trot = false\n\tn.times do |i|\n\t\tif i < k\n\t\t\tans[i] = mydr[i % k]\n\t\telsif i < 2*k \n\t\t\tans[i] = i % k + 1\n\t\telsif i < 3*k\n\t\t\tif !rot\n\t\t\t\tmydr.reverse!\n\t\t\t\trot = true\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\telsif i < 4*k\n\t\t\tans[i] = i % k + 1\n\t\telsif i < 5*k\n\t\t\tif rot\n\t\t\t\tmydr.rotate!\n\t\t\t\trot = false\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\telse\n\t\t\tif !rot\n\t\t\t\tmydr.rotate!.reverse!\n\t\t\t\trot = true\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\tend\n\tend\n\n\tprint ans.join(' ')\n\t# print \"\\n\"\nend\n"}, {"source_code": "n, k = gets.split(' ').collect!{|i| i.to_i}\n\n# def arifm?(arr)\n# \tresult = true\n# \tarr.each_index do |i|\n# \t\tif i < arr.length - 3\n# \t\t\tresult = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]\n# \t\tend\n# \tend\n# \treturn result\n# end\n\n# p arifm?([1,\u20095,\u20099])\n\nif n / 3.0 < k\n\tp -1\nelse\n\tmydr = Array.new(k)\n\tmydr.each_index do |i|\n\t\tmydr[i] = i % k + 1\n\tend\n\tmydr.rotate!\n\t# p mydr\n\tans = Array.new(n)\n\trot = false\n\tn.times do |i|\n\t\tif i < k\n\t\t\tans[i] = k - i\n\t\telsif i < 2*k \n\t\t\tans[i] = i % k + 1\n\t\telsif i < 3*k\n\t\t\tif !rot\n\t\t\t\tmydr.rotate!.reverse!\n\t\t\t\trot = true\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\telse\n\t\t\tif rot\n\t\t\t\tmydr.rotate!.reverse!\n\t\t\t\trot = false\n\t\t\tend\n\t\t\tans[i] = mydr[i % k]\n\t\tend\n\tend\n\n\tprint ans.join(' ')\n\t# print \"\\n\"\nend\n"}, {"source_code": "n, k = gets.split.map &:to_i\n\nif n < 3*k\n\tputs -1\n\texit\nend\n\nt = 1\nfor i in 1..k\n\tprint t.to_s + \" \" + t.to_s + \" \"\n\tt+=1\nend\n\nt=1\nfor i in 1..k\n\tprint t.to_s + \" \"\n\tt+=1\nend\n\nfor i in 1..(n-k)\n\tprint 1, \" \"\nend"}], "src_uid": "aba3bb100e2d3d30dc4b00818f190bff"} {"source_code": "n = gets.to_i\nm = n/2+1\nputs m\n(1..m).each do |i|\n puts \"#{1} #{i}\"\nend\n(2..m).each do |i|\n puts \"#{m} #{i}\" if n.odd? || i < m\nend", "positive_code": [{"source_code": "n = gets.to_i\nk = 1\np n/2+1\n(n/2).times do |i|\n t = k+i\n puts \"#{t} #{t}\"\n puts \"#{t} #{t+1}\"\nend\nif n%2 == 1\n puts \"#{k+n/2} #{k+n/2}\"\nend\n"}, {"source_code": "def lscan;gets.split.map(&:to_i);end\n\nn = gets.to_i\n\nw = n / 2 + 1\n\np w\nx = 1\ny = 1\nvx = 1\nvy = 0\nn.times do |i|\n puts \"#{x} #{y}\"\n x += vx\n y += vy\n if x > w\n x -= vx\n y -= vy\n vx,vy = vy,vx\n x += vx\n y += vy\n end\nend"}], "negative_code": [], "src_uid": "6bd7cab93a779e066af39a671aba3239"} {"source_code": "# f = File.open 'input.txt', 'r'\nf = STDIN\n\ndef fuzzy_equal?(a, b)\n a == b || a - 1 == b\nend\n\ndef find_pairs(sticks)\n marked_indices = []\n start_idx = 0\n sticks.each_with_index do |item, idx|\n next if idx < start_idx\n break if idx >= sticks.length - 1\n if fuzzy_equal?(item, sticks[idx + 1])\n start_idx = idx + 2\n marked_indices << sticks[idx + 1]\n end\n end\n marked_indices\nend\n\ndef area(width, height)\n width * height\nend\n\ndef total_areas(marked_indices)\n total_area = 0\n\n marked_indices.each_with_index do |item, idx|\n next if idx % 2 == 0\n total_area += area item, marked_indices[idx - 1]\n end\n total_area\nend\n\ndef compute(n, sticks)\n marked_indices = find_pairs sticks\n total_areas marked_indices\nend\n\nwhile true\n raw_n = f.gets\n break unless raw_n\n n = raw_n.chomp.to_i\n sticks = f.gets.chomp.split.map &:to_i\n desc_sticks = sticks.sort{ |a, b| b <=> a }\n p compute(n, desc_sticks)\nend\n", "positive_code": [{"source_code": "n=gets.chomp.to_i\na=gets.chomp.split(\" \").map{|x| x.to_i}\nb=a.sort\ni=n-1\nx=1\nc=0\ns=0\nwhile i>=1 do\n\tif (b[i]==b[i-1])\n\t\tx=x*b[i]\n\t\ti=i-1\n\t\tc=c+1\t\t\n\telse\n\t\tif (b[i-1]==b[i]-1)\n\t\t\tx=x*b[i-1]\n\t\t\ti=i-1\n\t\t\tc=c+1\n\t\tend\n\tend\n\tif c==2\n\t\ts=s+x\n\t\tx=1\n\t\tc=0\n\tend\ni=i-1\nend\n\nputs s\n\n"}, {"source_code": "gets\na = gets.split.map(&:to_i)\n\na.sort!\n\ns = 0\nt = 0\n\nwhile a.size > 1\n ta, tb = a[-2..-1]\n \n if (ta - tb).abs <= 1\n if t == 0\n t = [ta, tb].min\n else\n s += t * [ta, tb].min\n t = 0\n end\n a = a[0..-3]\n else\n a = a[0..-2]\n end\nend\n\nputs s"}, {"source_code": "n = gets.to_i\nl = Hash.new(0)\nll = Hash.new(0)\ngets.split.each{|i| l[i.to_i]+=1}\nl = l.sort_by{|key, value| key}.reverse\n(0...l.size).each do |i|\n if i > 0 and l[i-1][0] == l[i][0]+1 and l[i-1][1] > 0 and l[i][1] > 0\n ll[l[i][0]] += 1\n l[i-1][1] = 0\n l[i][1] -= 1\n end\n if l[i][1] >= 2\n ll[l[i][0]] += l[i][1]/2\n l[i][1] %= 2\n end\nend\nll = ll.sort_by{|key, value| key}.reverse\nans = 0\n(0...ll.size).each do |i|\n if ll[i][1] >= 2\n ans += ll[i][1]/2*ll[i][0]*ll[i][0]\n ll[i][1] %= 2\n end\n if ll[i][1] > 0 and i < ll.size-1\n ans += ll[i][0]*ll[i+1][0]\n ll[i][1] = 0\n ll[i+1][1] -= 1\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\nl = gets.split.map(&:to_i).sort.reverse\nans = 0\na = 0\nb = 0\nfor i in 0...l.size - 1 do\n if l[i] == l[i + 1]\n if a == 0\n a = l[i]\n elsif b == 0\n b = l[i]\n ans += a * b\n a = 0\n b = 0\n end\n l[i] = 0\n l[i + 1] = 0\n elsif l[i] == l[i + 1] + 1\n if a == 0\n a = l[i + 1]\n elsif b == 0\n b = l[i + 1]\n ans += a * b\n a = 0\n b = 0\n end\n l[i] = 0\n l[i + 1] = 0\n end\nend\nputs ans\n\n"}], "negative_code": [{"source_code": "n=gets.chomp.to_i\na=gets.chomp.split(\" \").map{|x| x.to_i}\nb=a.sort\ni=n-1\nf=0\nx=[]\ny=[]\nwhile i>=1 do\n\tif (b[i]==b[i-1])\n\t\tx<<(b[i])\n\t\ti=i-1\t\t\n\tend\n\tif x.length==2\n\t\tf=1\n\t\tbreak\n\tend\n\tif (b[i-1]==b[i]-1)\n\t\ty<<(b[i-1])\n\t\ti=i-1\n\tend\ni=i-1\nend\nif f==1\nputs x[0]*x[1]\nelse\n\tif x.length==0\n\t\tif y.length>=2\n\t\t\tputs y[0]*y[1]\n\t\telse\n\t\t\tputs 0\n\t\tend\n\telse\n\t\tif y.length>=1\n\t\t\tputs x[0]*y[0]\n\t\telse\n\t\t\tputs 0\n\t\tend\n\tend\nend\n"}, {"source_code": "n=gets.chomp.to_i\na=gets.chomp.split(\" \").map{|x| x.to_i}\nb=a.sort\ni=n-1\nx=[]\ny=[]\nc=0\nwhile i>=1 do\n\tif (b[i]==b[i-1])\n\t\tx<<(b[i])\n\t\ti=i-1\n\t\tc=c+1\t\t\n\tend\n\tif (b[i-1]==b[i]-1)\n\t\ty<<(b[i-1])\n\t\ti=i-1\n\t\tc=c+1\n\tend\n\tif c==2\n\t\tbreak\n\tend\ni=i-1\nend\n\nif c==2\n\tif x.length==2\n\tputs x[0]*x[1]\n\telse\n\t\tif y.length==2\n\t\tputs y[0]*y[1]\n\t\telse\n\t\tputs x[0]*y[0]\t\n\t\tend\n\tend\nelse\nputs 0\nend\n\n"}, {"source_code": "n = gets.to_i\nl = Hash.new(0)\nll = Hash.new(0)\ngets.split.each{|i| l[i.to_i]+=1}\nl = l.sort_by{|key, value| key}.reverse\n(0...l.size).each do |i|\n if l[i][1] >= 2\n ll[l[i][0]] += l[i][1]/2\n l[i][1] %= 2\n end\nend\n(1...l.size).each do |i|\n if l[i-1][0] == l[i][0]+1 and l[i-1][1] > 0 and l[i][1] > 0\n ll[l[i][0]] += 1\n l[i-1][1] = 0\n l[i][1] = 0\n end\nend\nll = ll.sort_by{|key, value| key}.reverse\nans = 0\n(0...ll.size).each do |i|\n if ll[i][1] >= 2\n ans += ll[i][1]/2*ll[i][0]*ll[i][0]\n ll[i][1] %= 2\n end\n if ll[i][1] > 0 and i < ll.size-1\n ans += ll[i][0]*ll[i+1][0]\n ll[i][1] = 0\n ll[i+1][1] -= 1\n end\nend\nputs ans\n"}, {"source_code": "# f = File.open 'input.txt', 'r'\nf = STDIN\n\ndef fuzzy_equal?(a, b)\n a == b || a + 1 == b\nend\n\ndef find_eql_sticks(n, sticks)\n [*0...(n - 1)].rindex{ |idx| fuzzy_equal? sticks[idx], sticks[idx + 1] }\nend\n\ndef length(idx, sticks)\n idx ? sticks[idx] : 0\nend\n\ndef area(width_idx, height_idx, sticks)\n length(width_idx, sticks) * length(height_idx, sticks)\nend\n\ndef compute(n, sticks)\n first_pair_index = find_eql_sticks(n, sticks)\n second_pair_index = find_eql_sticks(first_pair_index, sticks)\n area(first_pair_index, second_pair_index, sticks)\nend\n\nwhile true\n raw_n = f.gets\n break unless raw_n\n n = raw_n.chomp.to_i\n sticks = f.gets.chomp.split.map &:to_i\n sorted_sticks = sticks.sort\n puts compute(n, sorted_sticks)\nend\n"}], "src_uid": "0e162ea665732714283317e7c052e234"} {"source_code": "n,k=gets.split.map(&:to_i)\nputs k>n ? -1 : \"#{gets.split.map(&:to_i).sort[-k]} 0\"\n\n", "positive_code": [{"source_code": "n, k = gets.split(' ').map(&:to_i)\nar = gets.split(' ').map(&:to_i).sort\nif k<=n\n puts \"#{ar[-k]} #{ar[-k]}\"\nelse\n puts -1\nend"}, {"source_code": "st = gets.split\nn = st[0].to_i\nk = st[1].to_i\n\nst = gets.split\nquad = []\nn.times do |i|\n quad << st[i].to_i\nend\n\nquad = quad.sort\nif quad[-k] then\n result = quad[-k].to_s + \" \" + quad[-k].to_s\nelse\n result = -1\nend\n\nputs result"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs k>n ? -1 : \"#{gets.split.map(&:to_i).sort[-k]} 0\"\n\n"}, {"source_code": " n,k=gets.split.map(&:to_i)\n a=gets.split.map(&:to_i)\n f=a.find_all{|ch| ch>0}.size\n if f n\n \n points.sort!\n \n x = points[n - k]\n y = 0\n \n return [x, y]\nend\n\n\nn, k = gets.chomp.split(\" \").map{|n| n.to_i}\npoints = gets.chomp.split(\" \").map{|n| n.to_i}\n\nputs solve(n, k, points).join(\" \")"}, {"source_code": "#!/usr/bin/ruby1.9\n\nn, k = STDIN.readline.split.collect {|s| s.to_i }\nas = STDIN.readline.split.collect {|s| s.to_i }\nas.sort!\nif k > n\n\tputs -1\n\texit\nend\n\nix = n-k\nputs '%d %d' % [as[ix], as[ix]]\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nnums = gets.split.map(&:to_i).sort.reverse\nputs n >= k ? \"#{nums[k - 1]} #{nums[k - 1]}\" : \"-1\"\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs k>n ? -1 : \"#{gets.split.map(&:to_i).sort[-k]} 0\"\n"}, {"source_code": "def run\n n, k = ARGF.readline.split.map(&:to_i)\n ary = ARGF.readline.split.map(&:to_i).sort\n\n if ary.length - k >= 0\n puts ary[ary.length - k].to_s + \" 0\"\n else\n puts \"-1\"\n end\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs k>n ? -1 : \"#{gets.split.map(&:to_i).sort[-k]} 0\"\n\n"}, {"source_code": "a=gets.chomp.split(\" \").map {|i| i.to_i}\nb=gets.chomp.split(\" \").map {|i| i.to_i}\nb.sort!\nif a[0]-a[1]>=0\nc=b[a[0]-a[1]]\nputs \"#{c} #{c-1}\"\nelse\nputs \"-1\"\nend\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs k>n ? -1 : \"#{gets.split.map(&:to_i).sort[-k]} 0\"\n\n"}, {"source_code": "a=gets.chomp.split(\" \").map {|i| i.to_i}\nb=gets.chomp.split(\" \").map {|i| i.to_i}\nb.sort!\nif a[0]-a[1]>=0\nc=b[a[0]-a[1]]\nputs \"#{c} #{c-1}\"\nelse\nputs \"-1\"\nend\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\np=gets.split.map(&:to_i).sort\nprint k>n ? -1 : \"#{p[-k]} 0\""}, {"source_code": "n,k=gets.split.map(&:to_i)\np=gets.split.map(&:to_i).sort\nprint ((k>n)? -1 : \"#{p[-k]} #{0}\")"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn, k = gets.split.map(&:to_i)\npoints = gets.split.map(&:to_i)\n\n# -1\nif k > n then\n puts -1\n exit\nend\n\n# other\npoints.sort!\nputs \"#{points[-k]} #{0}\""}, {"source_code": "n, k = gets.split.map(&:to_i)\np = gets.split.map(&:to_i)\n(puts -1) & exit if k>n\nprint ([p.sort[-k]]*2).join ' '"}, {"source_code": "n,k = gets.split.map &:to_i\nif k>n\n p -1 \nelse\n v = []\n v = gets.split.map &:to_i\n v = v.sort\n puts \"#{v[n-k]} #{v[n-k]}\"\nend"}, {"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).sort\nputs n= k\n print a[n-k], \" \", 0\nelse\n print -1\nend"}, {"source_code": "m,k = gets.split.map &:to_i\nv = gets.split.map &:to_i\nif k>m\n puts \"-1\"\nelse\n v = v.sort\n puts v[m-k].to_s+\" 0\"\nend"}, {"source_code": "n,k = gets.split.map &:to_i\nv = gets.split.map &:to_i\nif k>n\n puts \"-1\"\nelse\n v = v.sort\n puts v[n-k].to_s+\" 0\"\nend"}, {"source_code": "m,k = gets.split.map &:to_i\nv = gets.split.map &:to_i\nif k>m\n puts \"-1\"\nelse\n v = v.sort\n puts v[m-k].to_s+\" 0\"\nend"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs k>n ? -1 : \"#{gets.split.map(&:to_i).sort[-k]} 0\"\n\n"}, {"source_code": "x, m = STDIN.readline.split.map(&:to_i)\narr = STDIN.readline.split.map(&:to_i).sort\nif arr.size - m >= 0\n\tprint \"#{arr[arr.size-m]} #{arr[arr.size-m]}\\n\"\nelse\n\tp -1\nend\n"}, {"source_code": "n,k = gets.chomp.split(\" \").collect! {|x| x.to_i}\nline = gets.chomp.split(\" \").collect! {|x| x.to_i}\nline.sort!\nif k > n\n puts \"-1\"\nelse\nputs \"#{line[n-k]} #{line[n-k]}\"\nend"}, {"source_code": "def read_line\n gets.chomp.split.map &:to_i\nend\n\nn, k = read_line\na = read_line.sort\n\nif k>n\n\tputs -1\nelse\t\n\tprint a[n-k]\n\tprint ' '\n\tputs a[n-k] \nend\t"}, {"source_code": "n,k = gets.split.map(&:to_i)\na=gets.split.map(&:to_i).sort.reverse\n\nif k>n \n puts -1\nelse\n puts \"%d %d\" % [a[k-1],a[k-1]]\nend\n\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort\nif k > n\n p -1\nelse\n print a[n-k],' ',a[n-k]\nend\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs k>n ? -1 : \"#{gets.split.map(&:to_i).sort[-k]} 0\"\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs k>n ? -1 : \"#{gets.split.map(&:to_i).sort[-k]} 0\"\n\n"}, {"source_code": "n, k = gets.chomp.split.map { |x| x.to_i }\na = gets.chomp.split.map { |x| x.to_i }.sort\nputs(k <= n ? \"#{a[n - k]} 0\" : -1)"}, {"source_code": "n, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort\nif k > n\n puts(-1)\nelse\n puts(([a[n - k]] * 2).join(' '))\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nn, k = gets.split.map(&:to_i)\na = gets.split.map(&:to_i).sort.reverse\ni, t = 0, 0\nwhile i < n\n\tc, j = 0, i\n\tc, j = c + 1, j + 1 while a[j] == a[i]\n\tt = t + c\n\tif t == k\n\t\tputs \"#{a[i]} #{a[i]}\"\n\t\texit 0\n\tend\n\ti = j\nend\nputs -1\n"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs k>n ? -1 : \"#{gets.split.map(&:to_i).sort[-k]} 0\"\n\n"}, {"source_code": "BEGIN{\n\tdef gint()\n\t\treturn gets.split.map(&:to_i)\n\tend\n\tdef main()\n\t\tn, k = gint\n\t\ta = gint\n\t\ta = [0] + a\n\t\ta.sort!\n\t\tputs -1 if k > n\n\t\treturn if k > n\n\t\tprint a[-1] + 1, \" \", a[-1] + 1, \"\\n\" if k == 0\n\t\treturn if k == 0\n\t\tp = n - k + 1\n\t\tprint a[p], \" \", a[p], \"\\n\"\n\tend\n\tTest_case = 1\n\tTest_case.times do\n\t\tmain()\n\tend\n}\n"}, {"source_code": "t = gets.split.collect{|x| x.to_i}\nn = t[0]\nk = t[1]\n\na = gets.split.collect{|x| x.to_i}\na.sort!{|x,y| y <=> x}\n\nx = 10**9\n\na.each{|ai|\n\tif k > 0\n\t\tx = ai\n\t\tk -= 1\n\telsif ai == x\n\t\tk -= 1\n\tend\n}\n\nif k != 0\n\tputs -1\nelse\n\tprint x, ' ', x\nend"}, {"source_code": "n,k=gets.split.map(&:to_i)\nputs k>n ? -1 : \"#{gets.split.map(&:to_i).sort[-k]} 0\"\n\n"}], "negative_code": [{"source_code": "n,k=gets.split.map(&:to_i)\na=gets.split.map(&:to_i).sort\nputs k0\n first += val\n last_player = \"first\"\n firsts << val\n else\n second += - val\n last_player = \"second\"\n seconds << - val\n end\n}\nseq_first = false\nseq_second = false\n\n(0...[firsts.size, seconds.size].max).each{|i|\n if(firsts[i].to_i > seconds[i].to_i)\n seq_first = true\n break\n elsif(firsts[i].to_i < seconds[i].to_i)\n seq_second = true\n break\n end\n}\n# puts \"first=#{first}, second=#{second}\"\nif first > second then\n puts \"first\"\n exit 0\nelsif second > first then\n puts \"second\"\n exit 0\nend\nif seq_first then\n puts \"first\"\n exit 0\nelsif seq_second then\n puts \"second\"\n exit 0\nend\nputs last_player\n\n", "positive_code": [{"source_code": "# 493B\n\na_sum = b_sum = 0\na_ary, b_ary = [], []\nval = nil\ngets.to_i.times {\n val = gets.to_i\n if val > 0\n a_sum += val\n a_ary << val\n else\n b_sum += -val\n b_ary << -val\n end\n}\nres = if a_sum > b_sum\n true\n elsif a_sum < b_sum\n false\n else\n res = a_ary <=> b_ary\n if res > 0\n true\n elsif res < 0\n false\n else\n val > 0\n end\n end\nputs res ? 'first' : 'second'"}, {"source_code": "n = STDIN.readline.to_i\na, b = [], []\nlast = nil\nn.times do\n x = STDIN.readline.to_i\n if x > 0\n a.push(x)\n last = 'first'\n else\n b.push(-x)\n last = 'second'\n end\nend\n\nsum_a, sum_b = a.inject(0, :+), b.inject(0, :+)\nif sum_a > sum_b\n puts 'first'\n exit\nend\nif sum_a < sum_b\n puts 'second'\n exit\nend\n\nif a == b\n puts last\n exit\nend\n\ngreater = ([a, b].sort)[1]\nif greater == a\n puts 'first'\nelse\n puts 'second'\nend\n"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\nn = gets.to_i\n\nt = nil\na = [[0], [0]]\nn.times do\n c = gets.to_i\n t = c < 0 ? 1 : 0\n a[t] << c.abs\n a[t][0] += c.abs\nend\na[t] << 1\nresult = [a[0] ,a[1]].max == a[0] ? \"first\" : \"second\"\nputs result\n\n"}, {"source_code": "n=gets.to_i\nar,br,a,b,flag,i,t=Array.new(200001,0),Array.new(200001,0),0,0,0,0,nil\nsumA,sumB=0,0\nn.times do\n\tt=gets.to_i\n\tif t>0\n\t\tsumA+=t\n\t\tar[a]=t\n\t\ta+=1\n\telse\n\t\tsumB-=t\n\t\tbr[b]=-t\n\t\tb+=1\n\tend\nend\nflag=1 if sumA>sumB\nflag=2 if sumB>sumA\nif flag==0\n\twhile ibr[i]\n\t\t\tflag=1\n\t\t\tbreak\n\t\telsif br[i]>ar[i]\n\t\t\tflag=2\n\t\t\tbreak\n\t\tend\n\t\ti+=1\n\tend\n\tif flag==0\n\t\tflag = (t>0) ? 1 : 2\n\tend\nend\nputs (flag==1) ? \"first\" : \"second\""}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\nclass GameProcess\n def initialize(n)\n @n = n\n @f = Wrestler.new\n @s = Wrestler.new\n @f_w = \"first\"\n @s_w = \"second\"\n @last = @f_w\n start\n end\n\n def start\n if @n == 1\n @last = gets.chomp.to_i < 0 ? @s_w : @f_w\n return\n end\n @n.times do |i|\n p = gets.chomp.to_i\n distribute_point(p)\n @last = 0 < p ? @f_w : @s_w\n end\n end\n\n def distribute_point(p)\n return @f.get_point(p) if 0 < p\n @s.get_point(-1 * p)\n end\n\n def result\n f_s = @f.sum_points\n s_s = @s.sum_points\n return @f_w if s_s < f_s\n return @s_w if f_s < s_s\n return lexicographic_order\n end\n\n def lexicographic_order\n f_l = @f.number_of_point\n s_l = @s.number_of_point\n result = @last\n n = 0\n if f_l < s_l\n n = f_l\n else\n n = s_l\n end\n n.times do |i|\n f_p = @f.point_at(i)\n s_p = @s.point_at(i)\n next if f_p == s_p\n if f_p < s_p\n result = @s_w\n break\n else\n result = @f_w\n break\n end\n end\n return result\n end\nend\n\nclass Wrestler\n def initialize()\n @sum = 0\n @points = []\n end \n\n def get_point(p)\n @points << p\n @sum += p\n end\n\n def point_at(i)\n @points[i]\n end\n\n def sum_points\n @sum\n end\n\n def number_of_point\n @points.length\n end\nend\n\ngp = GameProcess.new(gets.chomp.to_i)\nputs gp.result\n"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\nn = gets.to_i\n\nt = nil\na = [[0], [0]]\nn.times do\n c = gets.to_i\n t = c < 0 ? 1 : 0\n a[t] << c.abs\n a[t][0] += c.abs\nend\na[t] << 1\nresult = [a[0] ,a[1]].max == a[0] ? \"first\" : \"second\"\nputs result\n\n"}, {"source_code": "l=(1..gets.to_i).map{gets.to_i}\na={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})\na[true]#.sort!\na[false].map!{|i|-i}#.sort!\n#a.values.map(&:sort!)\nb=Hash[a.map{|k,v|[k,v.inject(:+)]}]\n#p a,b\nputs (if b[true]==b[false]\n if a[true]==a[false]\n l[-1]>0\n else\n a.keys.max_by{|i|a[i]}\n end\nelse\n b[true]>b[false]\nend)?\"first\":\"second\""}, {"source_code": "def min(a, b)\n (a < b)? a : b\nend\n\ndef cmp(a, b)\n (a < b)? -1 : ((a == b)? 0 : +1)\nend\n\nn = gets.to_i\np, u = 0, []\nq, v = 0, []\nl = 0\n\nfor i in 0...n\n x = gets.to_i\n y = x.abs\n \n if x > 0\n p += y\n u << y\n l = 1\n else\n q += y\n v << y\n l = -1\n end\nend\n\nans = cmp(p, q)\n\nif ans == 0\n min = min(u.size, v.size)\n \n for i in 0...min\n ans = cmp(u[i], v[i])\n break if ans != 0\n end\n \n ans = l if ans == 0\nend\n\ndata = {1 => 'first', -1 => 'second'}\n\nputs data[ans]"}, {"source_code": "def lex(first,second)\n\tlexi = true\n\ti = 0\n\tj = 0\n\tans = nil\n\twhile i < first.length && j < second.length\n\t\tif first[i] < second[i]\n\t\t\tans = \"second\"\n\t\t\tbreak\n\t\telsif first[i] > second[i]\n\t\t\tans = \"first\"\n\t\t\tbreak\n\t\tend\n\t\ti += 1\n\t\tj += 1\n\tend\n\tif !ans && first.length != second.length\n\t\tif first.length < second.length\n\t\t\tans = \"second\"\n\t\telse\n\t\t\tans = \"first\"\n\t\tend\n\tend\n\tans\nend\n\nn = gets.to_i\narr = []\nn.times do\n\tarr << gets.to_i\nend\nfirst = arr.select{|a| a > 0}\nsecond = arr.select{|a| a < 0}.map { |e| e.abs }\n\nfirst_score = first.inject(0,:+)\nsecond_score = second.inject(0,:+)\n\nif first_score < second_score\n\tans = \"second\"\nelsif first_score > second_score\n\tans = \"first\"\nelse\n\tans = lex(first,second)\n\tunless ans\n\t\tif arr[-1] > 0\n\t\t\tans = \"first\"\n\t\telse\n\t\t\tans = \"second\"\n\t\tend\n\tend\n\nend\nputs ans"}, {"source_code": "l=(1..gets.to_i).map{gets.to_i}\na={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})\na[true]#.sort!\na[false].map!{|i|-i}#.sort!\n#a.values.map(&:sort!)\nb=Hash[a.map{|k,v|[k,v.inject(:+)]}]\n#p a,b\nputs (if b[true]==b[false]\n if a[true]==a[false]\n l[-1]>0\n else\n a.keys.max_by{|i|a[i]}\n end\nelse\n b[true]>b[false]\nend)?\"first\":\"second\""}, {"source_code": "def lex(first,second)\n\tlexi = true\n\ti = 0\n\tj = 0\n\tans = nil\n\twhile i < first.length && j < second.length\n\t\tif first[i] < second[i]\n\t\t\tans = \"second\"\n\t\t\tbreak\n\t\telsif first[i] > second[i]\n\t\t\tans = \"first\"\n\t\t\tbreak\n\t\tend\n\t\ti += 1\n\t\tj += 1\n\tend\n\tif !ans && first.length != second.length\n\t\tif first.length < second.length\n\t\t\tans = \"second\"\n\t\telse\n\t\t\tans = \"first\"\n\t\tend\n\tend\n\tans\nend\n\nn = gets.to_i\narr = []\nn.times do\n\tarr << gets.to_i\nend\nfirst = arr.select{|a| a > 0}\nsecond = arr.select{|a| a < 0}.map { |e| e.abs }\n\nfirst_score = first.inject(0,:+)\nsecond_score = second.inject(0,:+)\n\nif first_score < second_score\n\tans = \"second\"\nelsif first_score > second_score\n\tans = \"first\"\nelse\n\tans = lex(first,second)\n\tunless ans\n\t\tif arr[-1] > 0\n\t\t\tans = \"first\"\n\t\telse\n\t\t\tans = \"second\"\n\t\tend\n\tend\n\nend\nputs ans"}, {"source_code": "def compare_arrays(f, s)\n\n for i in f.zip s\n if i[0] > i[1]\n return 1\n elsif i[1] > i[0]\n return 2\n end\n end\n\n if f.length > s.length\n return 1\n elsif f.length < s.length\n return 2\n end\n\n 0\nend\n\n\nn = gets.to_i\n\nsum = 0\nfirst = []\nsecond = []\n\nfor _ in 1..n\n cur = gets.to_i\n\n sum += cur\n\n if cur > 0\n first << cur.abs\n else\n second << cur.abs\n end\nend\n\nif sum > 0\n puts \"first\"\nelsif sum < 0\n puts \"second\"\nelse\n case compare_arrays(first, second)\n when 0\n if cur > 1\n puts \"first\"\n elsif cur < 2\n puts \"second\"\n end\n when 1\n puts \"first\"\n else\n puts \"second\"\n end\n\nend\n\n# puts \"First #{first}\"\n# puts \"Second #{second}\""}, {"source_code": "pa=Array.new\npb=Array.new\nx=y=k=sa=sb=0\n\nn=gets.to_i\nfor i in 0..n-1\n h=gets.to_i\n if h>0\n k=1\n pa[x]=h\n x+=1\n sa+=h\n else\n k=2\n pb[y]=-h\n y+=1\n sb+=-h\n end\nend\n\ng=0\nif sa>sb\n puts \"first\" \n g=1\nelsif sapb[i]\n puts \"first\"\n g=1\n break\n elsif pa[i]0\n\t\tsumA+=t\n\t\tar[a]=t\n\t\ta+=1\n\telse\n\t\tsumB-=t\n\t\tbr[b]=-t\n\t\tb+=1\n\tend\nend\nflag=1 if sumA>sumB\nflag=2 if sumB>sumA\nif flag==0\n\twhile ibr[i]\n\t\t\tflag=1\n\t\t\tbreak\n\t\telsif br[i]>ar[i]\n\t\t\tflag=2\n\t\t\tbreak\n\t\tend\n\t\ti+=1\n\tend\nend\nputs (flag==1) ? \"first\" : \"second\""}, {"source_code": "ans = {}\nans[-1] = 'second'\nans[ 0] = ''\nans[+1] = 'first'\n\nn = gets.to_i\nu = []\nv = []\n\nfor i in 0...n\n x = gets.to_i\n y = x.abs\n \n if x > 0\n u << y\n ans[0] = 'first'\n else\n v << y\n ans[0] = 'second'\n end\nend\n\nu << 0 if u.size == 0\nv << 0 if v.size == 0\n\np = u.map{|x| x.to_i}.reduce(:+)\nq = v.map{|x| x.to_i}.reduce(:+)\n\nif p > q\n puts ans[1]\nelsif p < q\n puts ans[-1]\nelse\n puts ans[u.join.casecmp(v.join)]\nend"}, {"source_code": "ans = {}\nans[-1] = 'second'\nans[ 0] = ''\nans[+1] = 'first'\n\nn = gets.to_i\nu = []\nv = []\n\nfor i in 0...n\n x = gets.to_i\n y = x.abs\n \n if x > 0\n u << y\n ans[0] = 'first'\n else\n v << y\n ans[0] = 'second'\n end\nend\n\nputs ans[u.join.casecmp(v.join)]"}, {"source_code": "N = gets.to_i\nvals = STDIN.read.split.map(&:to_i)\nfirsts = []\nseconds = []\nfirst = 0\nsecond = 0\nlast_player = nil\nvals.each{|val|\n if val>0\n first += val\n last_player = \"first\"\n firsts << val\n else\n second += - val\n last_player = \"second\"\n seconds << - val\n end\n}\nseq_first = false\nseq_second = false\n\n(0...[firsts.size, seconds.size].max).each{|i|\n if(firsts[i].to_i > seconds[i].to_i)\n seq_first = true\n elsif(firsts[i].to_i < seconds[i].to_i)\n seq_second = true\n end\n}\n# puts \"first=#{first}, second=#{second}\"\nif first > second then\n puts \"first\"\n exit 0\nelsif second > first then\n puts \"second\"\n exit 0\nend\nif seq_first then\n puts \"first\"\n exit 0\nelsif seq_second then\n puts \"second\"\n exit 0\nend\nputs last_player\n\n"}, {"source_code": "l=(1..gets.to_i).map{gets.to_i}\na=l.group_by{|i|i>0}\na[true].sort!\na[false].map!{|i|-i}.sort!\na.values.map(&:sort!)\nb=Hash[a.map{|k,v|[k,v.inject(:+)]}]\nputs (if b[true]==b[false]\n if a[true]==a[false]\n l[-1]>0\n else\n a.keys.max_by{|i|a[i]}\n end\nelse\n a.keys.max_by{|i|b[i]}\nend)?\"first\":\"second\""}, {"source_code": "l=(1..gets.to_i).map{gets.to_i}\na=l.group_by{|i|i>0}\n#a[true].sort!\na[false].map!{|i|-i}#.sort!\na.values.map(&:sort!)\nb=Hash[a.map{|k,v|[k,v.inject(:+)]}]\n#p a,b\nputs (if b[true]==b[false]\n if a[true]==a[false]\n l[-1]>0\n else\n a.keys.max_by{|i|a[i]}\n end\nelse\n a.keys.max_by{|i|b[i]}\nend)?\"first\":\"second\""}, {"source_code": "l=(1..gets.to_i).map{gets.to_i}\na={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})\na[true].sort!\na[false].map!{|i|-i}.sort!\na.values.map(&:sort!)\nb=Hash[a.map{|k,v|[k,v.inject(:+)]}]\n#p a,b\nputs (if b[true]==b[false]\n if a[true]==a[false]\n l[-1]>0\n else\n a.keys.max_by{|i|a[i]}\n end\nelse\n a.keys.max_by{|i|b[i]}\nend)?\"first\":\"second\""}, {"source_code": "l=(1..gets.to_i).map{gets.to_i}\na={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})\n#a[true].sort!\na[false].map!{|i|-i}#.sort!\na.values.map(&:sort!)\nb=Hash[a.map{|k,v|[k,v.inject(:+)]}]\n#p a,b\nputs (if b[true]==b[false]\n if a[true]==a[false]\n l[-1]>0\n else\n a.keys.max_by{|i|a[i]}\n end\nelse\n a.keys.max_by{|i|b[i]}\nend)?\"first\":\"second\""}, {"source_code": "l=(1..gets.to_i).map{gets.to_i}\na={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})\na[true].sort!\na[false].map!{|i|-i}.sort!\n#a.values.map(&:sort!)\nb=Hash[a.map{|k,v|[k,v.inject(:+)]}]\n#p a,b\nputs (if b[true]==b[false]\n if a[true]==a[false]\n l[-1]>0\n else\n a.keys.max_by{|i|a[i]}\n end\nelse\n b[true]>b[false]\nend)?\"first\":\"second\""}, {"source_code": "pa=Array.new\npb=Array.new\nx=y=k=sa=sb=0\n\nn=gets.to_i\nfor i in 0..n-1\n h=gets.to_i\n if h>0\n k=1\n pa[x]=h\n x+=1\n sa+=h\n else\n k=2\n pb[y]=-h\n y+=1\n sb+=-h\n end\nend\n\nflag=0\nif sa>sb\n puts \"first\" \n flag=1\nelsif say[i]\n puts \"first\"\n flag=1\n break\n elsif x[i]0\n k=1\n pa[x]=h\n x+=1\n sa+=h\n else\n k=2\n pb[y]=-h\n y+=1\n sb+=-h\n end\nend\nsta=pa.join\nstb=pb.join\n\nif sa!=sb\n if sa>sb\n puts \"first\"\n else\n puts \"second\"\n end\nelsif sta!=stb\n if sta>stb\n puts \"first\"\n else\n puts \"second\"\n end\nelse\n if k==1\n puts \"first\"\n elsif k==2\n puts \"second\"\n end\nend"}, {"source_code": "pa=Array.new\npb=Array.new\nx=y=k=sa=sb=0\n\nn=gets.to_i\nfor i in 0..n-1\n h=gets.to_i\n if h>0\n k=1\n pa[x]=h\n x+=1\n sa+=h\n else\n k=2\n pb[y]=-h\n y+=1\n sb+=-h\n end\nend\n\nflag=0\nif sa>sb\n puts \"first\" \n flag=1\nelse\n puts \"second\"\n flag=1\nend\n\nif flag==0\n i=0\n while iy[i]\n puts \"first\"\n flag=1\n break\n elsif x[i]0\n k=1\n pa[x]=h\n x+=1\n sa+=h\n else\n k=2\n pb[y]=-h\n y+=1\n sb+=-h\n end\nend\n\ng=0\nif sa>sb\n puts \"first\" \n g=1\nelsif say[i]\n puts \"first\"\n g=1\n break\n elsif x[i] 0\n a_sum += val\n a_str << val\n else\n b_sum += -val\n b_str << -val\n end\n}\nres = if a_sum > b_sum\n true\n elsif a_sum < b_sum\n false\n elsif a_str > b_str\n true\n elsif a_str < b_str\n false\n else\n val > 0\n end\nputs res ? 'first' : 'second'"}], "src_uid": "d3684227d1f12cf36dc302e1ffee8370"} {"source_code": "gets.to_i.times do\n x,y = gets.split.map(&:to_i)\n puts (x-y > 1) ? \"Yes\" : \"No\"\nend", "positive_code": [{"source_code": "gets.to_i.times{puts gets.split.map(&:to_i).inject(:-)==1?:NO: :YES}\n"}, {"source_code": "t = gets.to_i\nt.times do\n x, y = gets.split.map(&:to_i)\n d = x - y\n puts d == 1 ? 'NO' : 'YES'\nend\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nt = gets.to_i\nprimes = [2,3]\nt.times {\n x, y = gets.split.map(&:to_i)\n # x > y, guaranteed\n d = x - y\n if d < 2\n puts \"NO\"\n else\n puts \"YES\"\n end\n}"}, {"source_code": "t = gets.to_i\nfor i in 1..t\n a,b = gets.split.map(&:to_i);\n flag = 0\n if (a-b>=2)\n print \"YES\"\n puts \"\\n\"\n flag = 1\n end\n if flag != 1\n print \"NO\"\n puts \"\\n\"\n end\nend \n"}, {"source_code": "t = gets.to_i\nt.times do\n x, y = gets.split.map &:to_i\n puts x - y == 1 ? 'NO' : 'YES'\nend\n"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nt = gets.to_i\nprimes = [2,3]\nt.times {\n x, y = gets.split.map(&:to_i)\n # x > y, guaranteed\n d = x - y\n if d < 2\n puts \"NO\"\n else\n if d%2 == 0\n puts \"YES\"\n else\n # prime sub check\n is_prime_sub = false\n for i in primes\n break if i > d\n if d%i == 0\n is_prime_sub = true\n break\n end\n end\n\n # generate primes and check prime sub\n sqd = Math.sqrt(d).ceil\n if primes.last < sqd\n for i in (primes.last)..sqd\n is_prime = true\n for j in primes\n if i%j == 0\n is_prime = false\n break\n end\n end\n \n primes << i if is_prime\n\n if d%i == 0\n is_prime_sub = true\n break\n end\n end\n end\n \n if is_prime_sub\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\n end\n}"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nt = gets.to_i\nprimes = [2,3]\nt.times {\n x, y = gets.split.map(&:to_i)\n # x > y, guaranteed\n d = x - y\n if d < 2\n puts \"NO\"\n else\n if d%2 == 0\n puts \"YES\"\n else\n # prime sub check\n is_prime_sub = false\n sqd = Math.sqrt(d).floor\n\n for j in primes\n break if j > sqd\n if sqd%j == 0\n is_prime_sub = true\n break\n end\n end\n\n if is_prime_sub == false\n for i in (primes.last)..sqd\n next if i%2 == 0\n is_prime = true\n for j in primes\n if i%j == 0\n is_prime = false\n break\n end\n end\n\n if is_prime\n primes << i\n\n if sqd%i == 0\n is_prime_sub = true\n break\n end\n end\n end\n end\n \n\n # \uc548\ub418\uba74 \ub05d\uae4c\uc9c0 \uad6c\ud574\uc57c\uc9c0 \ubcc4 \uc218 \uc788\ub098\n # \uac00\uc988\uc544! (\uadfc\ub370 \uc774\uac78\ub85c\ub294 submission \ubabb\ud574\ubd04.)\n # 1\n # 999984 1\n\n # p primes\n if is_prime_sub\n puts \"YES\"\n else\n puts \"NO\"\n end\n end\n end\n}"}], "src_uid": "0671972bc2b6452d51d048329e6e0106"} {"source_code": "n = gets.to_i\n\nn.times{\n s = gets\n n = s.length-1\n if n <= 10\n puts s\n else\n puts s[0] + (n-2).to_s + s[n-1]\n end\n}\n", "positive_code": [{"source_code": "array = STDIN\narray.each { |x| if x.size > 11 then puts \"#{x[0]}#{x.size - 3}#{x[-2]}\" elsif x =~ /[0-9]/ then nil else puts x end }\n"}, {"source_code": "n = gets.to_i\nn.times.map { gets.chomp }.each do |word|\n if (s = word.size - 2) > 8\n puts \"#{word[0]}#{s}#{word[-1]}\"\n else\n puts word\n end\nend"}, {"source_code": "n = gets.to_i\nn.times do\n str = gets.chomp\n if str.length>10\n puts str[0]+(str.length-2).to_s+str[-1]\n else\n puts str\n end\n\nend"}, {"source_code": "n = gets.to_i\nwhile n > 0 do\n word = gets.chomp\n if (s = word.size - 2) > 8\n puts [word[0], s, word[-1]].join\n else\n puts word\n end\n n -= 1\nend"}, {"source_code": "n = gets.to_i\nwords = n.times.map { gets.chomp }\nwords.map do |word|\n if (s = word.size - 2) > 8\n \"#{word[0]}#{s}#{word[-1]}\"\n else\n word\n end\nend.each { |w| puts w }"}, {"source_code": "n = gets.to_i\nwhile n > 0 do\n word = gets.chomp\n if word.size > 10\n puts [word[0], word.size-2, word[-1]].join\n else\n puts word\n end\n n -= 1\nend"}, {"source_code": "puts gets(gets).gsub(/\\B.{9,}\\B/){$&.size}"}, {"source_code": "n = gets.to_i\n\nn.times{\n s = gets\n n = s.length-1\n if n <= 10\n puts s\n else\n puts s[0] + (s[1..n-2].length.to_s) + s[n-1]\n end\n}\n"}, {"source_code": "n = gets.chomp.to_i\nwords = []\n(1..n).each do |_i|\n words << gets.chomp\nend\n\nwords.each do |w|\n if w.size < 11\n puts w\n else\n puts \"#{w[0]}#{w.size - 2}#{w[-1]}\"\n end\nend\n"}, {"source_code": "n = gets.to_i\n\n$i = 0\n\nwhile $i < n\n s = gets\n if s.length < 12\n puts s\n elsif \n puts \"#{s[0]}#{s.length - 3}#{s[s.length - 2]}\"\n end\n \n $i += 1\nend"}, {"source_code": "t = gets.to_i\n\nlines = []\nt.times do\n current = gets.chomp\n if current.length > 10\n lines.push(current[0] + (current.length - 2).to_s + current[current.length-1])\n else\n lines.push(current)\n end\nend\n\nlines.each do |line|\n puts line\nend"}, {"source_code": "n = gets.to_i\n\nn.times do\n input = gets.chomp\n if input.size > 10\n puts \"#{input.chars.first}#{input.length - 2}#{input.chars.last}\"\n else\n puts input\n end\nend\n"}, {"source_code": "gets.to_i.times{s=gets; s.size>11? (puts \"#{s[0]}#{s.size-3}#{s[-2]}\"):(puts s)};\n"}, {"source_code": "ans=Array.new\ngets.to_i.times{s=gets; s.size>11? (ans<<\"#{s[0]}#{s.size-3}#{s[-2]}\"):(ans< 10 ? \"#{word.first}#{word.size-2}#{word.to_a.last}\\n\" : \"#{word.to_a.join}\\n\")\nend"}, {"source_code": "t=gets.to_i\nt.times{\n\n s=gets.chomp\n n=s.size\n if n<=10\n puts s\n else\n puts \"#{s[0]}#{n-2}#{s[-1]}\"\n end\n\n}\n"}, {"source_code": "number = gets.chomp.to_i\nnumber.times do\n word = gets.chomp\n\n if word.size > 10\n puts word[0] + (word.size - 2).to_s + word[-1]\n else\n puts word\n end\nend\n\n\n\n"}, {"source_code": "gets.to_i.times do\ns=gets.chomp\n\tif s.length > 10\n\tputs s[0] << (s.length - 2).to_s << s[s.length - 1]\n\telse\n\tputs s\n\tend\nend"}, {"source_code": "n = gets.to_i\na =[]\nfor i in 0..n-1 do\n a = a + [gets]\n if a[i].size > 11\n a[i] = (a[i][0] + (a[i].size - 3).to_s + a[i][a[i].size - 2])\n end\nend\nputs a"}, {"source_code": "n = gets.to_i\nn.times do |i|\n l = gets.strip\n s = l.size \n puts s>10 ? l[0]+(s-2).to_s+l[s-1] : l\nend"}, {"source_code": "#!/usr/bin/ruby\nn = STDIN.gets.chop.to_i\n\nn.times do\n word = STDIN.gets\n word.chop!\n\n if word.length > 10\n print word[0, 1]\n print word.length-2\n print word[-1, 1]\n else\n print word\n end\n\n print \"\\n\"\nend\n"}, {"source_code": "n=gets.to_i\n\nn.times {\ni=gets\na=i.length\nif (a <= 11)\n puts i\nelse\n out= i[0] + (a-3).to_s + i[a-2]\n puts out\nend\n}\n"}, {"source_code": "n = gets.to_i\n\na = Array.new(n)\nfor i in 0..(n - 1)\n a[i] = gets.to_s\nend\n\na.each {|b|\nif b.length >= 12\n f = b.split(\"\")[0]\n l = b.split(\"\")[(b.length-2)]\n c = b.split(\"\")[1..(b.length-3)].join(\"\")\n puts \"#{f}#{c.length}#{l}\"\nelse\n puts \"#{b}\"\nend\n}\n"}, {"source_code": "lines = STDIN.read.split(\"\\n\")\nif 2 <= lines.size\n lines[1..(lines.size - 1)].each do |word|\n puts word.length <= 10 ? word : \"#{word[0]}#{word.length - 2}#{word[word.length - 1]}\"\n end\nend\n\n"}, {"source_code": "limit =gets.chomp()\nlimit = limit.to_i\nwhile limit>0\n\tword = gets.chomp()\n\tif word.length>10\n\t\tprint word[0],word.length-2,word[-1]\n\t\tprint \"\\n\"\n\telse\n\t\tputs word\n\tend\n\tlimit-=1\nend"}, {"source_code": "gets.to_i.times do\n\tword = gets.chomp\n\tif word.length <= 10\n\t\tputs word\n\telse\n\t\tprint word[0], word.length - 2, word[-1], \"\\n\"\n\tend\nend"}, {"source_code": "T = gets.chomp.to_i\nfor i in (0...T)\n a = gets.chomp\n if(a.length > 10)\n puts a[0] + (a.length - 2).to_s + a[a.length - 1]\n else\n puts a\n end\nend"}, {"source_code": "number = gets.chomp.to_i\n\nnumber.times do\nword = gets.chomp\n\nif word.length > 10\nstr = ''\nnumber = word.length - 2\nstr = word[0] + number.to_s + word[word.length - 1]\nputs str\nelse\nputs word\nend\nend"}, {"source_code": "def abb ()\n n = gets.to_i \n words = Array.new(n)\n for i in 0...n\n word = gets.to_s\n words[i] = word.chomp!\n end\n words.each{ |word|\n if word.length <= 10\n puts word\n else\n puts \"#{word[0]}#{word.length-2}#{word[-1]}\"\n end\n }\nend\n\nabb "}, {"source_code": "gets.to_i.times {gets; puts ($_.length>11)?(\"#{$_[0]}#{$_.length-3}#{$_[$_.length-2]}\") : $_}"}, {"source_code": "n = gets.to_i\nn.times do\na = gets.chomp\nd = Array.new\nb = a[0]\nc = a[-1, 1]\nx = a[1..-2]\ns = x.size.to_i\n if s > 8\n d << b << s << c\n d.map { |sammy| sammy} \n puts d.join\n else\n puts a\n end\n end\n \n "}, {"source_code": "num = gets.chomp\nnum = num.to_i\n \nnum.times do \n input = gets.chomp #get the next lines of input\n if (input.size > 10) #if the size of the string is 10 or more..\n firstLetter = input.split(\"\").first\n lastLetter = input.split(\"\").last\n input = input.split(\"\")\n input.pop\n input.shift\n input = input.join\n new_word = \"#{firstLetter}#{input.length}#{lastLetter}\\n\"\n print new_word\n else\n word = \"#{input}\\n\"\n print word\n end\nend"}, {"source_code": "x = gets.chomp.to_i\n\nfor i in 0...x do\n words = gets.chomp.to_s \n if words.length > 10\n puts words[0].to_s + (words.length-2).to_s + words[-1]\n else\n puts words\n end\nend\n"}, {"source_code": "input = STDIN.read\n\nn, lines = input.split(\"\\n\", 2)\n\nlines = lines.split(\"\\n\")\n# n = n.to_i\nlines.each do |line|\n if line.length < 11\n puts line\n else\n puts \"#{line[0]}#{line.length - 2}#{line[line.length - 1]}\"\n end\nend\n\n"}, {"source_code": "# frozen_string_literal: true\n\nn = gets.to_i\n\n1.upto(n).each do |_i|\n str = gets.strip\n if str.length <= 10\n puts str\n next\n end\n len = str.length - 2\n puts \"#{str[0]}#{len}#{str[str.length - 1]}\"\nend\n"}, {"source_code": "(gets.to_i).times do\n ss=gets\n if(ss.length>11)\n ss[1,ss.length-3] = (ss.length-3).to_s\n end\n puts (ss)\nend\n"}, {"source_code": "n = gets.chomp.to_i\ni = 0 \nwhile i < n do\n s = gets.chomp\n t = s.size \n if t > 10 \n print s[0]\n print t - 2\n puts s[t-1]\n else\n puts s\n end \n i += 1\n end"}, {"source_code": "class LongWord\n def initialize(word)\n @word = word\n end\n\n def short_version\n return @word if @word.size <= 10\n\n first_char = @word[0]\n last_char = @word[-1]\n rest_word_count = @word[1..-2].size\n\n \"#{first_char}#{rest_word_count}#{last_char}\"\n end\nend\n\n# Main\ncount_of_input = gets.strip.to_i\nword_collection = []\ncount_of_input.times do\n word = gets.strip\n word_collection << word\nend\n\nword_collection.each do |word|\n long_word = LongWord.new(word)\n puts long_word.short_version\nend"}, {"source_code": "n=gets.chomp.to_i\nn.times do\n\ta=gets.chomp.to_s\n\tnum=a.length - 2\n\tif a.length>10\n\t\tword=a[0]+num.to_s+a[num+1]\n\telse\n\t\tword=a\n\tend\n\tputs word\nend"}, {"source_code": "n=gets.chomp.strip.to_i\nn.times do\n\ta=gets.chomp.to_s\n\tnum=a.length - 2\n\tif a.length>10\n\t\tword=a[0]+num.to_s+a[num+1]\n\telse\n\t\tword=a\n\tend\n\tputs word\nend"}, {"source_code": "gets.to_i.times{|i|w=gets.chomp;s=w.size-2;puts s>8?w[0]+s.to_s+w[-1]:w}"}, {"source_code": "n = gets.chomp.to_i\nfor i in(0...n)\n s = gets.chomp\n if s.length() < 11\n puts s\n else\n print s[0],s.length()-2,s[s.length()-1]\n puts\n end\nend"}, {"source_code": "gets.chomp.to_i.times do\n word = gets.chomp\n if word.length > 10\n print word[0], ((word.length)-2).to_s, word[-1], \"\\n\"\n else\n print word, \"\\n\"\n end\nend"}, {"source_code": "gets.to_i.times do\n s = gets.chomp\n puts s.size>10?\"#{s[0]}#{s.size-2}#{s[-1]}\":s\nend\n"}, {"source_code": "n = gets.strip.to_i\nn.times do |i| \n word = gets.strip\n result = \"\"\n if word.length > 10 then\n result = \"#{word[0]}#{word[1..-2].length}#{word[-1]}\"\n else\n result = word\n end\n puts result\nend\n"}, {"source_code": "n=gets.to_i\na= []\nfor i in 0..n-1\n\ta[i] = gets\nend\na.each do |val|\n\tval = val.gsub(\"\\n\",\"\")\n\tlen = val.length\n\tputs len <= 10 ? val : \"#{val[0]}#{len-2}#{val[len-1]}\"\nend"}, {"source_code": "#!/usr/bin/ruby\n\nn = gets.chomp.to_i\n\nn.times do\n s = gets.chomp.to_s\n\n if s.length > 10\n first_letter = s[0]\n last_letter = s[s.length-1]\n abbr = (s.length - 2).to_s\n puts (first_letter + abbr + last_letter)\n else\n puts s\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\n0.upto n-1 do |i|\n w = gets.chomp\n if w.length > 10 then\n\tww = \"#{w[0]}#{w.length-2}#{w[w.length-1]}\"\n\tputs ww\n else\n puts w\n end\nend"}, {"source_code": "n = gets.to_i\n\nfor i in 0...n\n x = gets;\n if x.size > 11\n print x[0]\n print x.size-3;\n print x[x.size-2].chr;\n puts\n elsif\n puts x;\n end\nend"}, {"source_code": "n = gets.chomp.to_i.times do |i| a = gets.chomp.to_s; if a.length>10 then print(a[0]); print(a.length-2); puts(a[a.length-1]); else puts(a) end end"}, {"source_code": "#!/usr/bin/env ruby\nclass Test\n\tkol = gets.chomp\n\tik = kol.to_i\n\tfor num in 1..ik\n\t\tstr = gets.chomp\n\tif str.length > 10\n\tlen = str.length - 2\n\tlen = len.to_s\n\ttemp = str[0..0] + len + str[str.length-1..str.length-1]\n\t\tputs temp\n\telse\n\t\tputs str\n\tend\n\tend\nend\n"}, {"source_code": "n=gets.chomp.to_i.times{a=gets.chomp.to_s;o=a.length;if o>10 then printf(\"%c%d%c\\n\",a[0],o-2,a[o-1]);else puts(a)end}\n"}, {"source_code": "a = gets.to_i\n\nfor arr in (1..a)\n arr = gets.to_s\n if arr.length > 11\n startLetter = arr[0]\n lastLetter = arr[arr.length - 2]\n puts arr = startLetter + (arr.length.to_i - 3).to_s + lastLetter.to_s\n else\n puts arr.to_s\n end\nend "}, {"source_code": "n = gets.to_i\n\nwords = []\n\nn.times do\n\tcurr = gets\n\n\tif curr.length > 11\n\t\tlast = curr[curr.length - 2, 1]\n\t\tcurr = curr[0] + (curr.length - 3).to_s\n\t\tcurr = curr + last\n\tend\n\n\twords << curr\nend\n\nputs words"}, {"source_code": "n = gets.to_i\nn.times do\n s = gets.chomp\n if s.size <= 10\n puts s\n else\n puts \"#{s[0]}#{s.size - 2}#{s[-1]}\"\n end\nend"}, {"source_code": "len = 10\nn = gets.to_i\nwhile n > 0 do\n word = gets.chomp\n if word.size > len\n puts [word.chars.first, word.size-2, word.chars.last].join\n else\n puts word\n end\n n -= 1\nend"}, {"source_code": "def too_long_word (word) \n x = 0\n n = gets\n num = n.to_i\n\t \n while x < num\n word = gets \n char = word.chomp.split('')\n sum_char = char.size\n char_min = ((sum_char) - 2).to_s \n if sum_char <= 10 \n puts word\n else\n puts char.first + char_min + char.last\n end\n x+=1\n end\nend\n\ntoo_long_word ()"}, {"source_code": "n = readline.to_i\n\ni = 0\na = Array.new()\n\nwhile i < n do\n begin\n a[i] = readline\n i += 1\n end\nend\na.each do\n |i|\n if (i.size > 11) \n puts i[0] + (i.size - 3).to_s + i[i.size - 2]\n else\n puts i\n end\nend\n"}, {"source_code": "gets.chomp.to_i.times {\n\ts=gets.chomp\n\tif(s.length<=10)\n\t\tputs s\n\telsif\n\t\tputs \"#{s[0]}#{s.length-2.to_i}#{s[-1]}\"\n\tend\n}"}, {"source_code": "gets.chomp.to_i.times do\n str = gets.chomp\n puts str.length > 10 ? \"#{str[0]}#{str.length - 2}#{str[-1]}\" : str\nend\n"}, {"source_code": "x = gets.to_i \n\ndef check(j)\n\tif j.length <= 10\n\t\tputs j\n\telse\n\t\tputs j[0] + (j.length - 2).to_s + j[-1]\n\tend\nend\n\nfor i in 1..x do\n\ty = gets.chomp\n\tcheck(y)\nend\n\t"}, {"source_code": "m=gets.to_i\nm.times do\n s = gets.chomp\n if s.size <= 10\n puts s\n else\n puts \"#{s[0]}#{s.size - 2}#{s[-1]}\"\n end\nend\n"}, {"source_code": "a = gets.to_i\nfor i in 1..a\n b = gets\n c = b.length\n c = c - 1 \n if c <= 10\n puts b\n else\n d = c - 2\n print b[0]\n print d\n print b[c-1]\n puts\n end\nend"}, {"source_code": "1.upto(gets.to_i) do\n a = gets.chomp\n a = \"#{a[0, 1]}#{a.length - 2}#{a[-1, 1]}\" if a.length > 10\n\n puts a\nend\n"}, {"source_code": "a = gets.split(\" \")\nn = a[0].to_i\nfor i in 1..n\n s = gets.chomp\n if(s.size > 10) \n s1 = s[0]+(s.size-2).to_s+s[s.size - 1]\n puts(s1)\n else puts(s)\n end\nend "}, {"source_code": "x=gets.to_i\nx.times do\nn=gets.chomp\nz=n.length\nif z > 10\nprint n[0]\nprint z-2\nprint n[z-1]\nprint \"\\n\"\nelse\nprint n\nprint \"\\n\"\nend\nend"}, {"source_code": "a=Array.new;\nn=gets;\nn.to_i.times{|i|a[i]=gets.chop}\na=a.map{|i|if i.size>10 then i=i[0..0]+(i.size-2).to_s+i[-1..-1] else i=i end}\na.each{|i|puts i}"}, {"source_code": "n = gets.chomp.to_i\n\nn.times do\n word = gets.chomp\n if word.size > 10\n n = word.size\n puts \"#{word[0]}#{n - 2}#{word[n-1]}\"\n else\n puts word\n end\nend\n"}], "negative_code": [{"source_code": "a = Array.new\nn = gets.to_i\nn.times do \n a << gets.to_s.chop\nend\na.each do |i|\n if i.size <= 10\n p i\n else\n p \"#{i[0]}#{i.size-2}#{i[(i.size-1)]}\" \n end\nend"}, {"source_code": "n = gets.chomp.to_i\n(0...n).each do |i|\n\tword = gets.chomp\n\tif word.length > 4\n\t\tprint word[0], (word.length - 2), word[(word.length - 1)], \"\\n\"\n\telse puts word\n\tend\nend\n"}, {"source_code": "(gets.to_i).times do\n str=gets\n if str.length > 10 then\n str[1,str.length - 2] = (str.length - 2).to_s \n end \n puts str\n end"}, {"source_code": "a = gets.to_s\nd = []\nb = a[0]\nc = a[-1, 1]\nx = a[1..-2]\ns = x.size.to_i\ny = s.to_s\n d << b << y << c\n if s > 10\n puts d.join\n else\n puts a\n end"}, {"source_code": "n = gets.to_i\n\n$i = 0\n\nwhile $i < n\n s = gets\n if s.size < 11\n puts s\n elsif \n puts \"#{s[0]}#{s.size - 3}#{s[s.size - 2]}\"\n end\n \n $i += 1\nend"}, {"source_code": "n = gets.chomp.to_i\nfor i in(0...n)\n s = gets.chomp\n if s.length() < 10\n puts s\n else\n print s[0],s.length()-2,s[s.length()-1]\n puts\n end\nend"}, {"source_code": "a = gets.to_s\nb = a[0]\nc = a[-1]\ns = a.size\nx = s - 2\nz = x.to_s\n if s > 10\n puts b + z + c\n else\n puts a\n end"}, {"source_code": "a = gets.to_i\n\nfor arr in (1..a)\n arr = gets.to_s\n if arr.length > 10\n startLetter = arr[0]\n lastLetter = arr[arr.length - 2]\n puts arr = startLetter + (arr.length.to_i - 3).to_s + lastLetter.to_s\n else\n puts arr.to_s\n end\nend "}, {"source_code": "def abb ()\n n = gets.to_i \n for i in 0...n\n word = gets.to_s\n word.chomp!\n if word.length < 10\n puts word\n else\n puts \"#{word[0]}#{word.length-2}#{word[-1]}\"\nend\nend\nend\n\nabb "}, {"source_code": "#!/usr/bin/env ruby\nclass Test\n\tkol = gets.chomp\n\tik = kol.to_i\n\tfor num in 1..ik\n\t\tstr = gets.chomp\n\tif str.length > 10\n\tlen = str.length.to_s\n\ttemp = str[0..0] + len + str[str.length-1..str.length-1]\n\t\tputs temp\n\telse\n\t\tputs str\n\tend\n\tend\nend\n"}, {"source_code": "n = gets.chomp.to_i\n\nn.times do\n s = gets.chomp\n if s.length >= 10 \n p \"#{s[0]}#{s.length-2}#{s[s.length-1]}\" \n else\n p s\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\nfor i in(0...n)\n s = gets.chomp\n if s.length() < 11\n puts s\n else\n print s[0],s.length()-2,s[s.length()-1]\n end\nend"}, {"source_code": "n = gets.to_i\nn.times do |i|\n\ttemp = gets\n\tif (temp.size < 11)\n\t\tputs temp\n\telse\n\t\tk = temp.size - 2\n\t\tcurr = temp[0] + k.to_s + temp[k]\n\t\tputs curr\n\tend\nend"}, {"source_code": "a = gets.to_s\nb = a[0]\nc = a[-1]\nd = a[1...-2]\n if a.length > 10\n puts b + d + c\n else\n puts a\n end"}, {"source_code": "array = STDIN\narray.each { |x| if x.size > 10 then puts \"#{x[0]}#{x.size - 2}#{x[-1]}\" elsif x =~ /[0-9]/ then nil else puts x end }\n"}, {"source_code": "counter = gets.chomp.to_i\n\ncounter.times do\n word = gets.chomp.to_s\n\n if word.length > 10\n word = word[0,1] + ( word.length - 2 ).to_s + word[word.length-1, 1]\n end\n\n p word\nend"}, {"source_code": "n = gets.chomp.to_i\nfor i in(0...n)\n s = gets.chomp\n if s.length() < 10\n puts s\n else\n puts s[0],s.length(),s[s.length()-1]\n end\nend"}, {"source_code": "x = gets.to_i \n\ndef check(j)\n\tif j.length <= 10\n\t\tputs j\n\telse\n\t\tputs j[0] + j.length.to_s + j[-1]\n\tend\nend\n\nfor i in 1..x do\n\ty = gets.chomp\n\tcheck(y)\nend\n\t"}, {"source_code": "n = gets.to_i\n\n$i = 0\n\nwhile $i < n\n s = gets\n puts s.length\n if s.length < 12\n puts s\n elsif \n puts \"#{s[0]}#{s.length - 3}#{s[s.length - 2]}\"\n end\n \n $i += 1\nend"}, {"source_code": "#!/usr/bin/env ruby\nstr = ARGF.read\n\nif str.scan(/\\D/).empty?\n exit\nelsif str.size <= 10\n puts str \nelse\n puts str[0] + (str.length - 2).to_s + str[str.length - 1]\nend\n"}, {"source_code": "n = gets.to_i\nn.times do\na = gets.chomp\nd = Array.new\nb = a[0]\nc = a[-1, 1]\nx = a[1..-2]\ns = x.size.to_i\n if s >= 10\n d << b << s << c\n d.map { |sammy| sammy} \n puts d.join\n else\n puts a\n end\n end\n \n "}, {"source_code": "a = gets.to_i\nfor i in 1..a\n b = gets\n c = b.length\n c = c - 1 \n if c <=4\n puts b\n else\n d = c - 2\n print b[0]\n print d\n print b[c-1]\n end\nend"}, {"source_code": "n = gets.split.map &:to_i\nn.each do |i|\n word = gets.split.map\n if word.count > 10\n p w[0] + w.count-2 + w[-1]\n else\n p word\n end\nend"}, {"source_code": "string = gets.chomp\nputs (string[0] + (string.length-2).to_s + string[-1])"}, {"source_code": "n = gets.to_i\nn.times do\na = gets.chomp\nd = Array.new\nb = a[0]\nc = a[-1, 1]\nx = a[1..-2]\ns = x.size.to_i\n if s > 10\n d << b << s << c\n d.map { |sammy| sammy} \n puts d.join\n else\n puts a\n end\n end\n "}, {"source_code": "i=gets\na=i.length\nif (a <= 11)\n puts i\nelse\n out= i[0] + (a-2).to_s + i[a-2]\n puts out\nend\n"}, {"source_code": "c, arr = gets.to_i, []\nc.times { arr << gets }\n\narr.map! do |w|\n w.length > 10 ? \"#{w[0]}#{w.length-3}#{w[-2]}\" : w\nend\n\nputs arr\n"}, {"source_code": "n = gets.to_i\n\na = Array.new(n)\nfor i in 0..(n - 1)\n a[i] = gets.to_s\nend\n\n\na.each {|b|\n\nif b.length >= 10\n f = b.split(\"\")[0]\n l = b.split(\"\")[(b.length-2)]\n c = b.split(\"\")[1..(b.length-3)].join(\"\")\n puts \"#{f}#{c.length}#{l}\"\nelse\n puts \"#{b}\"\nend\n}"}, {"source_code": "a = gets.to_s\nb = a[0]\nc = a[-1]\ns = a.size\nz = s.to_s\n if s > 10\n puts b z c\n else\n puts a\n end"}, {"source_code": "a = String.new\na = gets\nb = a[0]\nc = a[-1]\nd = a[1..-2]\n s = a.size.to_i\n if s >= 10\n puts b + d + c\n else\n puts a\n end"}, {"source_code": "n = gets.to_i\nn.times do\na = gets.chomp\nd = Array.new\nb = a[0]\nc = a[-1, 1]\nx = a[1..-2]\ns = x.size.to_i\n if s >= 10\n d << b << s << c\n d.map { |sammy| sammy} \n puts d.join\n else\n puts a\n end\n end\n \n "}, {"source_code": "n = gets.split.map &:to_i\nn.each do |i|\n w = gets.strip\n if w.size > 10\n puts w[0] + w.size-2 + w[-1]\n else\n puts w\n end\nend"}, {"source_code": "n = gets.to_i\nn.times do\n s = gets.chomp\n if s.size < 10\n puts s\n else\n puts \"#{s[0]}#{s.size - 2}#{s[-1]}\"\n end\nend"}, {"source_code": "n=gets.to_i\nn.times do\nstr=gets.chomp.to_s\nputs \"#{str[0]}#{str.size-2}#{str[str.size-1]}\"\nend\n"}, {"source_code": "x=gets.to_i\nx.times do\nn=gets.chomp\nz=n.length\nif z > 10\nprint n[0]\nprint z-2\nprint n[z-1]\nelse\nprint n\nend\nend"}, {"source_code": "x=gets.to_i\nx.times do\nn=gets.chomp\nz=n.length\nif z > 10\nprint n[0]\nprint z-2\nprint n[z-1]\nelse\nprint n\nprint \"\\n\"\nend\nend"}, {"source_code": "n = gets.to_i\nn.times do\na = gets.chomp\nd = Array.new\nb = a[0]\nc = a[-1, 1]\nx = a[1..-2]\ns = x.size.to_i\n if s > 10\n d << b << s << c\n d.map { |sammy| sammy} \n puts d.join\n else\n puts a\n end\n end\n "}, {"source_code": "n = Integer(gets)\na = Array.new\nfor i in 0...n\n\ta[i] = gets\nend\n\t\tdef word_to_long(b)\n\t\t\tl = b.length\n\t\t\tif l > 10\n\t\t\t\treturn b[0] + \"#{l - 3}\"+ b[l-2]\n\t\t\telse\n\t\t\t\treturn b\n\t\t\tend\n\t\tend\n\n\tfor i in 0...n\n\t\tputs word_to_long(a[i])\n\tend\n\t\t\n\n"}, {"source_code": "t = gets.chomp.to_i\n\nfor i in 1..t\n s = gets.chomp\n if s.length < 5\n puts s\n next\n end\n print s[0];print s.length-2; puts s[-1]\nend"}, {"source_code": "def abb ()\n n = gets.to_i \n for i in 0...n\n word = gets.to_s\n word.chomp!\n if word.length < 10\n puts word\n else\n puts \"#{word[0]}#{word.length-2}#{word[-1]}\"\nend\nend\nend\n\nabb "}, {"source_code": "line_count = gets.to_i\n\nfor i in 1..line_count\n line = gets\n if line.length > 10\n p line[0] + (line.length-2).to_s + line[-1,1]\n else\n p line\n end\nend"}, {"source_code": "n = gets\nn.to_i.times do \n word = gets.chomp\n l = word.size\n puts l\n if l > 10\n puts \"#{word[0]}#{l-2}#{word[-1]}\"\n else\n puts word\n end \nend"}, {"source_code": "a = gets.to_s\nb = a[0]\nc = a[-1]\ns = a.size\nx = s - 2\nz = x.to_s\n if x >= 10\n puts b + z + c\n else\n puts a\n end"}, {"source_code": "a = gets.to_s\nb = a[0]\nc = a[-1]\ns = a.size\nx = s - 2\nz = x.to_s\n if s >= 10\n puts b + z + c\n else\n puts a\n end"}, {"source_code": "line_count = gets.to_i\n\nfor i in 1..line_count\n line = gets.chomp\n if line.length > 10\n p line[0] + (line.length-2).to_s + line[-1,1]\n else\n p line\n end\nend\n"}, {"source_code": "n = gets.chomp.to_i\n(0...n).each do |i|\n\tword = gets.chomp\n\tif word.length >= 4\n\t\tprint word[0], (word.length - 2), word[(word.length - 1)], \"\\n\"\n\telse puts i\n\tend\nend\n"}, {"source_code": "class LongWord\n def initialize(word)\n @word = word\n end\n\n def short_version\n return @word if @word.size <= 10\n\n first_char = @word[0]\n last_char = @word[-1]\n rest_word_count = @word[1..-2].size\n\n \"#{first_char}#{rest_word_count}#{last_char}\"\n end\nend\n\n# Main\nword = gets.strip\nshort_version = LongWord.new(word).short_version\nputs short_version\n\n"}, {"source_code": "line_count = gets.to_i\n\nfor i in 1..line_count\n line = gets.chomp\n if line.length > 10\n p line[0] + (line.length-2).to_s + line[-1,1]\n else\n p line\n end\nend\n"}, {"source_code": "x=gets.to_i\nx.times do\nn=gets.chomp\nz=n.length\nif z > 10\nprint n[0]\nprint z-2\nprint n[z-1]\nelse\nprint n\nprint \"\\n\"\nend\nend"}, {"source_code": "n = gets.to_i\nwhile n > 0 do\n word = gets.chomp\n if (s = word.size - 2) >= 10\n puts [word[0], s, word[-1]].join\n else\n puts word\n end\n n -= 1\nend"}, {"source_code": "a = Array.new\nn = gets.to_i\nn.times do \n a << gets.to_s.chop\nend\na.each do |i|\n if i.size < 10\n p i\n else\n p \"#{i[0]}#{i.size-2}#{i[(i.size-1)]}\" \n end\nend"}, {"source_code": "t = gets.chomp.to_i\n\nfor i in 1..t\n s = gets.chomp\n if s.length < 5\n puts s\n next\n end\n print s[0];print s.length-2; puts s[-1]\nend"}, {"source_code": "#!/usr/bin/env ruby\nstr = gets\n\nif str.scan(/\\D/).empty?\n return\nend\n\nif str.size <= 10\n puts str \n return\nend\n\nputs str[0] + (str.length - 2).to_s + str[str.length - 1]\n"}, {"source_code": "x=gets.to_i\nx.times do\nn=gets.chomp\nz=n.length\nif z > 10\nprint n[0]\nprint z-2\nprint n[z-1]\nelse\nprint n\nend\nend"}, {"source_code": "puts \"How many words would ou like to abreviate?\"\nwords = gets.to_i\nputs \"Write down below #{words} words\"\n\nabreviadas = []\nfor number in 1..words\n\tpalavra = gets.strip\n\ttamanho = (palavra.size) -2\n\tif palavra.size > 10\n\t\tpalavras = palavra[0] + tamanho.to_s + palavra[(palavra.size)-1]\n\telse\n\t\tpalavras = palavra\n\tend\n\t\tabreviadas<= 10\n puts b s c\n else\n puts a\n end"}, {"source_code": "a = gets.split(\" \")\nn = a[0].to_i\nfor i in 1..n\n s = gets.chomp\n if(s.size > 10) \n s1 = s[0]+(s.size-2).to_s+s[s.size - 1]\n p(s1)\n else p(s)\n end\nend "}, {"source_code": "lines = []\nwhile line =(ARGV.shift or (!STDIN.tty? and STDIN.gets) )\n lines.push(line)\nend\n\nputs lines"}, {"source_code": "a = Array.new\nn = gets.to_i\nn.times do \n a << gets.to_s.chop\nend\na.each do |i|\n if i.size <= 10\n p i\n else\n p \"#{i[0]}#{i.size-2}#{i[(i.size-1)]}\" \n end\nend"}, {"source_code": "num_line = gets.to_i()\nnum_line.times {\n str = gets()\n puts str.length()>10 ? str[0]+(str.length()-3).to_s+str[str.length()-2] : str\n}\n"}, {"source_code": "n=gets.to_i\na= []\nfor i in 0..n-1\n\ta[i] = gets\nend\na.each do |val|\n\tlen = val.length\n\tputs len <= 10 ? val : \"#{val[0]}#{len-3}#{val[len-2]}\"\nend"}, {"source_code": "n=gets.to_i\na= []\nfor i in 0..n-1\n\ta[i] = gets\nend\na.each do |val|\n\tlen = val.length\n\tputs len < 10 ? val : \"#{val[0]}#{len-3}#{val[len-2]}\"\nend"}, {"source_code": "n = gets.to_i\n\na = Array.new(n)\nfor i in 0..(n - 1)\n a[i] = gets.to_s\nend\n\n\na.each {|b|\n\nif b.length >= 10\n f = b.split(\"\")[0]\n l = b.split(\"\")[(b.length-2)]\n c = b.split(\"\")[1..(b.length-3)].join(\"\")\n puts \"#{f}#{c.length}#{l}\"\nelse\n puts \"#{b}\"\nend\n}"}, {"source_code": "a = gets.to_s\nb = a[0]\nc = a[-1]\ns = a.size\nx = s - 2\nz = x.to_s\n if s > 10\n puts b + z + c\n else\n puts a\n end"}, {"source_code": "x = gets.chomp.to_i\n\nfor i in 0...x do\n words = gets.chomp.to_s \n if words.length >= 10\n puts words[0].to_s + (words.length-2).to_s + words[-1]\n else\n puts words\n end\nend\n"}, {"source_code": "(gets.to_i).times do\n ss=gets\n ss[1,ss.length-3] = ss.length>10? (ss.length-3).to_s : ss[1,ss.length-3]\n puts (ss)\nend\n"}, {"source_code": "gets.chomp.to_i.times do\n a = gets.chomp\n if a.length<10\n puts a\n else\n print a[0],a.length-2,a[a.length-1],\"\\n\"\n end\nend"}, {"source_code": "len = 10\nn = gets.to_i\nwhile n > 0 do\n word = gets.chomp\n if word.size > len\n p [word.chars.first, word.size-2, word.chars.last].join\n else\n p word\n end\n n -= 1\nend"}, {"source_code": "n = gets\nn = n.to_i\n\nfor i in (1..n) \n\tstring = gets\n\tif(string.size()<11)\n\t\tputs string\n\telse\n\t\tstringFinal = string[0]\n\t\tnumero = string.size - 3\n\t\tstringFinal << numero.to_s\n\t\tstringFinal << string[string.size - 2]\n\t\tputs stringFinal\n\tend\nend"}, {"source_code": "n = STDIN.gets\nwhile word = STDIN.gets\n word.strip!\n if word.length > 10\n puts \"#{word[0,1]}#{word.length - 2}#{word[word.length-1,1]}\"\n end\nend\n"}, {"source_code": "n = gets.to_i\n\n$i = 0\n\nwhile $i < n\n s = gets\n if s.size < 11\n puts s\n elsif \n puts \"#{s[0]}#{s.size - 3}#{s[s.size - 2]}\"\n end\n \n $i += 1\nend"}, {"source_code": "number_of_words = gets.to_i\n\nwords = []\n\nnumber_of_words.times do |n|\n word = gets\n words.push(word)\nend\n\nwords.each do |word|\n if word.length <= 10\n puts word\n else\n number_of_letters_between = word.length - 3\n fist_letter = word[0]\n last_letter = word[-2]\n puts \"#{fist_letter}#{number_of_letters_between}#{last_letter}\"\n end\nend"}, {"source_code": "n = gets.to_i\ni = 0\ny = []\nwhile i < n\n x = gets\n if x.length > 10\n x[1...x.length-2] = (x.length-2).to_s\n end\n y << x\n i +=1\nend\n\nputs y\n"}, {"source_code": "n = gets.to_i\n\na = Array.new(n)\nfor i in 0..(n - 1)\n a[i] = gets.to_s\nend\n\n\na.each {|b|\n\nif b.length >= 10\n f = b.split(\"\")[0]\n l = b.split(\"\")[(b.length-2)]\n c = b.split(\"\")[1..(b.length-3)].join(\"\")\n puts \"#{f}#{c.length}#{l}\"\nelse\n puts \"#{b}\"\nend\n}"}, {"source_code": "gets.chomp.to_i.times do\n word = gets.chomp\n if word.length >= 10\n print word[0], ((word.length)-2).to_s, word[-1], \"\\n\"\n else\n print word, \"\\n\"\n end\nend"}, {"source_code": "n = gets.to_i\n\nwords = []\n\nn.times do\n\tcurr = gets\n\n\tif curr.length > 10\n\t\tlast = curr[curr.length - 2, 1]\n\t\tcurr = curr[0] + (curr.length - 3).to_s\n\t\tcurr = curr + last\n\tend\n\n\twords << curr\nend\n\nputs words"}, {"source_code": "len = gets.to_i\n\nwhile word = gets do\n word = word.chomp\n if word.size > len\n p [word.chars.first, word.size-2, word.chars.last].join\n else\n p word\n end\nend"}, {"source_code": "gets.to_i.times {gets.chomp; puts ($_.length>10)?(\"#{$_[0]}#{$_.length-3}#{$_[$_.length-2]}\") : $_}\n"}, {"source_code": "a = gets\nb = []\nc = a[0]\nb << c\nd = a[1..-2].length\nb << d\ne = a[-1]\nb << e\nf = b.join\n\n\nif d > 10\nputs f\n\nelse\nputs a\n\nend\n\n\n\n\n"}, {"source_code": "(gets.to_i).times do\n str = gets\n if str.length > 10 then\n str= str[0..0] + (str.length - 2).to_s + str[-1..-1] \n end \n p str\nend\n"}, {"source_code": "number_of_words = gets.to_i\n\nwords = []\n\nnumber_of_words.times do |n|\n word = gets\n words.push(word)\nend\n\nwords.each do |word|\n if word.length < 10\n puts word\n else\n number_of_letters_between = word.length - 3\n fist_letter = word[0]\n last_letter = word[-2]\n puts \"#{fist_letter}#{number_of_letters_between}#{last_letter}\"\n end\nend"}, {"source_code": "n = gets.chomp.to_i\nfor i in(0...n)\n s = gets.chomp\n if s.length() < 10\n puts s\n else\n print s[0],s.length()-2,s[s.length()-1]\n puts\n end\nend"}, {"source_code": "n=gets.chomp.to_i.times{a=gets.chomp.to_s;o=a.length;if o>10 then printf(\"%c%d%c\",a[0],o-2,a[o-1]);else puts(a)end}\n"}, {"source_code": "n=gets.to_i\na= []\nfor i in 0..n-1\n\ta[i] = gets\nend\na.each do |val|\n\tlen = val.length\n\tputs len <= 10 ? val : \"#{val[0]}#{len-3}#{val[len-2]}\"\nend"}, {"source_code": "array = STDIN\narray.each { |x| if x.size > 10 then puts \"#{x[0]}#{x.size - 2}#{x[-1]}\" elsif x =~ /[0-9]/ then nil else puts x end }\n"}, {"source_code": "n = gets.to_i\ni = 0\ny = []\nwhile i < n\n x = gets\n if x.length > 10\n x[1...x.length-2] = (x.length-3).to_s\n end\n y << x\n i +=1\nend\n\nputs y\n"}, {"source_code": "array = [4, \"word\", \"localization\", \"internationalization\", \"pneumonoultramicroscopicsilicovolcanoconiosis\"]\narray.each { |x| if x.size > 10 then puts \"#{x[0]}#{x.size - 2}#{x[-1]}\" elsif x == x.to_s then puts x end }\n"}, {"source_code": "n = gets.to_i\na =[]\nfor i in 0..n-1 do\n a = a + [gets]\n if a[i].size >= 10\n a[i] = (a[i][0] + (a[i].size - 3).to_s + a[i][a[i].size - 2])\n end\nend\nputs a"}, {"source_code": "x = gets.to_i \n\ndef check(j)\n\tif j.length <= 10\n\t\tputs j\n\telse\n\t\tputs j[0] + j.length.to_s + j[-1]\n\tend\nend\n\nfor i in 1..x do\n\ty = gets.chomp\n\tcheck(y)\nend\n\t"}, {"source_code": "x=gets.to_i\nx.times do\nn=gets.chomp\nz=n.length\nif z > 10\nprint n[0]\nprint z-2\nprint n[z-1]\nelse\nprint n\nprint \"\\n\"\nend\nend"}, {"source_code": "b = /[0-9]/\nx = gets.chomp\nif x.size > 10\n puts \"#{x[0]}#{x.size - 2}#{x[-1]}\"\nelsif x =~ /[0-9]/\n nil\nelse\n puts x\nend"}, {"source_code": "a = gets.to_s\nb = a[0]\nc = a[-1]\ns = a.size\n if s >= 12\n puts b\n puts s\n puts c\n else\n puts a\n end"}, {"source_code": "n = gets.to_i\nn.times do |i|\n\ttemp = gets\n\tif (temp.size < 11)\n\t\tputs temp\n\telse\n\t\tk = temp.size - 2\n\t\tcurr = temp[0] + k.to_s + temp[k]\n\t\tputs curr\n\tend\nend"}, {"source_code": "a = gets.to_s\nb = a[0]\nc = a[-1]\ns = a.size\nx = s - 2\nz = x.to_s\n if x >= 10\n puts b + z + c\n else\n puts a\n end"}, {"source_code": "n = gets.chomp.to_i\n\nn.times do\n s = gets.chomp\n if s.length >= 10 \n p \"#{s[0]}#{s.length-2}#{s[s.length-1]}\" \n else\n p s\n end\nend\n"}, {"source_code": "def abb ()\n n = gets.to_i \n words = Array.new(n)\n for i in 0...n\n word = gets.to_s\n words[i] = word.chomp!\n end\n words.each{ |word|\n if word.length < 10\n puts word\n else\n puts \"#{word[0]}#{word.length-2}#{word[-1]}\"\n end\n }\nend\n\nabb"}, {"source_code": "n = gets.to_i\nn.times do\na = gets.chomp\nd = Array.new\nb = a[0]\nc = a[-1, 1]\nx = a[1..-2]\ns = x.size.to_i\n if s >= 10\n d << b << s << c\n d.map { |sammy| sammy} \n puts d.join\n else\n puts a\n end\n end\n \n "}, {"source_code": "gets.to_i.times do\n s=gets\n puts s.size>10 ? \"#{s[0]}#{s.size-1}#{s[-1]}\": s\nend\n"}, {"source_code": "number_of_words = gets.to_i\n\nwords = []\n\nnumber_of_words.times do |n|\n word = gets\n words.push(word)\nend\n\nwords.each do |word|\n if word.length < 10\n puts word\n else\n number_of_letters_between = word.length - 3\n fist_letter = word[0]\n last_letter = word[-2]\n puts \"#{fist_letter}#{number_of_letters_between}#{last_letter}\"\n end\nend"}], "src_uid": "6639d6c53951f8c1a8324fb24ef68f7a"} {"source_code": "gets.strip.to_i.times {\n\tn = gets.strip.to_i\n\tsq = Math.sqrt(n).to_i\n\tan = []\n\tsq.times { |i|\n\t\tan << i + 1 \n\t\tan << n / (i + 1)\n\t}\n\tan << 0\n\tan = an.uniq.sort\n\tputs an.size\n\tputs an.join(' ')\n}", "positive_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a mae\n mae = n/d\n ans.push(mae)\n end\n end\n p ans.size\n puts ans.join(\" \")\nend\n\n"}], "negative_code": [{"source_code": "#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']\n\nrequire 'prime'\n\ndef inpf() a=gets.chomp.split(\" \").map(&:to_f)end\n\ndef inps() a=gets.chomp.split(\" \")end\n\ndef copy(a) Marshal.load(Marshal.dump(a)) end\n\ndef kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end\n\ndef na(n,d=0) Array.new(n,d)end\n\ndef na2(n,m,d=0) Array.new(n){Array.new(m,d)}end\n\ndef na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end\n\ndef inp() a=gets.chomp.split(\" \").map(&:to_i)end\n\ndef r_up(a, b) (a+b-1)/b end\n\ndef sum(a) a.inject(:+) end\n\ndef big(a,b) return (a>b)? a:b end\n\ndef small(a,b) return (a mae\n mae = n/d\n ans.push(mae)\n end\n end\n puts ans.size\n puts ans.join(\" \")\nend\n\n"}, {"source_code": "gets.strip.to_i.times {\n\tn = gets.strip.to_i\n\tsq = Math.sqrt(n).to_i\n\tan = []\n\tsq.times { |i|\n\t\tnext if i == 0\n\t\tan << i \n\t\tan << n / i\n\t}\n\tan << 0\n\tputs an.size\n\tprint an.uniq.sort.join(' ')\n}"}, {"source_code": "gets.strip.to_i.times {\n\tn = gets.strip.to_i\n\tsq = Math.sqrt(n).to_i\n\tan = []\n\tsq.times { |i|\n\t\tnext if i == 0\n\t\tan << i \n\t\tan << n / i\n\t}\n\tan << 0\n\tputs an.uniq.sort.join(' ')\n}"}, {"source_code": "gets.strip.to_i.times {\n\tn = gets.strip.to_i\n\tsq = Math.sqrt(n).to_i\n\tan = []\n\tsq.times { |i|\n\t\tan << i + 1 \n\t\tan << n / (i + 1)\n\t}\n\tan << 0\n\tputs an.size\n\tputs an.uniq.sort.join(' ')\n}"}], "src_uid": "1fea14a5c21bf301981656cbe015864d"} {"source_code": "t = gets.chomp.to_i\nt.times do\n a, b = gets.chomp.split(' ').map(&:to_i)\n s = gets.chomp.split('')\n del = []\n cur = 0\n s.each do |el|\n if el == '1'\n del << cur if cur > 0\n cur = 0\n else\n cur += 1\n end\n end\n del.shift if s[0] == '0'\n\n sum = a\n del.each do |el|\n sum += [a, b * el].min\n end\n if s.count('1') >= 1\n puts sum \n else\n puts 0\n end\nend ", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n a, b = gets.chomp.split(\" \").map(&:to_i)\n x = gets.chomp.split(\"\")\n ookisa = x.size\n dp = Array.new(ookisa+1,Float::INFINITY)\n dp[0] = 0\n cost = 0\n i = 1\n renzoku = 0\n zero = 0\n first = 0\n until x == []\n me = x.shift\n #p me\n #p renzoku\n if me == \"1\"\n #p renzoku\n if renzoku >= 1\n dp[i] = dp[i-1]\n else\n #p dp\n #p zero\n if first >= 1\n dp[i] = [zero*b+dp[i-1],dp[i-1]+a].min\n else\n dp[i] = a\n first += 1\n end\n end\n # p renzoku\n # p zero\n zero = 0\n renzoku += 1\n else\n zero += 1\n renzoku = 0\n dp[i] = dp[i-1]\n end\n i += 1\n #p zero\n #p dp\n end\n puts dp.pop\nend"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n a, b = gets.chomp.split(' ').map(&:to_i)\n s = gets.chomp.split('')\n del = []\n cur = 0\n s.each do |el|\n if el == '1'\n del << cur if cur > 0\n cur = 0\n else\n cur += 1\n end\n end\n del.shift if s[0] == '0'\n\n sum = a\n del.each do |el|\n sum += [a, b * el].min\n end\n if s.count('1') > 1\n puts sum \n else\n puts 0\n end\nend "}, {"source_code": "t = gets.chomp.to_i\nt.times do\n a, b = gets.chomp.split(' ').map(&:to_i)\n s = gets.chomp.split('')\n del = []\n cur = 0\n s.each do |el|\n if el == '1'\n del << cur if cur > 0\n cur = 0\n else\n cur += 1\n end\n end\n puts \"s = \" + s.to_s\n del.shift if s[0] == '0'\n\n sum = a\n del.each do |el|\n sum += [a, b * el].min\n end\n if s.count('1') >= 1\n puts sum \n else\n puts 0\n end\nend "}], "src_uid": "fc01082e3ed7877126e750bc380f5c63"} {"source_code": "gets.to_i.times{p (gets.split.map(&:to_i)<<0).reject{|i|i<0}.inject:|}\n", "positive_code": [{"source_code": "gets.to_i.times{p (gets.split.map(&:to_i)<<0).reject{|i|i<0}.inject:|}\n"}, {"source_code": "gets.to_i.times{\n a=gets.split.map(&:to_i)-[-1]\n ans=a.inject(0,:|)\n print ans.to_s+' '\n}\n"}, {"source_code": "gets.to_i.times{\n a=gets.split.map(&:to_i)-[-1]\n p a.inject(0,:|)\n}\n"}, {"source_code": "gets.to_i.times{p (gets.split.map(&:to_i)<<0).reject{|i|i<0}.inject:|}"}], "negative_code": [{"source_code": "gets.to_i.times{p gets.split.map(&:to_i).reject{|i|i<0}.inject:|}\n"}, {"source_code": "gets.to_i.times{\n a=gets.split.map(&:to_i)-[-1]\n ans=a.inject(:|)\n print ans.to_s+' '\n}\n"}], "src_uid": "8f342e167e77088ce47f17e5cd475b17"} {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n vis = Array.new(n, false)\r\n\r\n l = 1\r\n cnt = 1\r\n max = 1\r\n\r\n num = a[0]\r\n a_l = 0\r\n a_r = 0\r\n\r\n n_l = nil\r\n n_r = 0\r\n\r\n while l < n\r\n next l += 1 if vis[l-1] && vis[l]\r\n if a[l-1] == a[l]\r\n n_l ||= l-1\r\n n_r = l\r\n cnt += 1\r\n else\r\n if cnt > 1\r\n r = l\r\n cnt1 = cnt\r\n while r < n\r\n if a[r] == a[n_l]\r\n vis[r] = true\r\n cnt1 += 1\r\n else\r\n cnt1 -= 1\r\n end\r\n if cnt1 > cnt\r\n cnt = cnt1\r\n n_r = r\r\n end\r\n break if cnt1 <= 0\r\n r += 1\r\n end\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[a_l]\r\n end\r\n n_l = nil\r\n n_r = 0\r\n cnt = 1\r\n end\r\n l += 1\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[n_l]\r\n end\r\n\r\n puts [num, a_l+1, a_r+1].join(\" \")\r\nend\r\n\r\n", "positive_code": [{"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n n = int\r\n a = ints\r\n \r\n indices = {}\r\n a.each_with_index do |x, i|\r\n (indices[x] ||= []) << i\r\n end\r\n \r\n ans = 1\r\n ans_value = [a[0], 1, 1]\r\n indices.each do |x, row|\r\n sum = 1\r\n first = row[0]\r\n prev = row[0]\r\n row[1..].each do |i|\r\n sum = sum - (i - prev) + 2\r\n prev = i\r\n # p [x, first, i, sum]\r\n if sum < 1\r\n sum = 1\r\n first = i\r\n end\r\n if ans < sum\r\n ans = sum\r\n ans_value = [x, first + 1, i + 1]\r\n end\r\n end\r\n end\r\n \r\n puts ans_value * \" \"\r\n end\r\n}\r\n\r\nDEBUG = false\r\nMOD = 10**9+7\r\nINF = 10**18\r\n$yesno = %w(No Yes)\r\n$YesNo = %w(No Yes)\r\n$YESNO = %w(NO YES)\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t ? 1 : 0] end\r\ndef YesNo t; puts $YesNo[t ? 1 : 0] end\r\ndef YESNO t; puts $YESNO[t ? 1 : 0] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]"}, {"source_code": "gets.to_i.times do\r\n gets\r\n xs = gets.split.map(&:to_i)\r\n last = {}\r\n dp = [0] * xs.size\r\n xs.each.with_index do |x, i|\r\n if y = last[x]\r\n dp[i] = [dp[y] - (i - y) + 2, 1].max\r\n else\r\n dp[i] = 1\r\n end\r\n last[x] = i\r\n end\r\n max = dp.max\r\n l = r = dp.index(max)\r\n a = xs[l]\r\n count = 1\r\n until count == max\r\n l -= 1\r\n count += xs[l] == a ? 1 : -1\r\n end\r\n puts \"#{a} #{l + 1} #{r + 1}\"\r\nend\r\n"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n x = gets.split.map(&:to_i)\r\n indices = {}\r\n x.each_with_index do |a, i|\r\n (indices[a] ||= []) << i\r\n end\r\n \r\n ans = 1\r\n ans_value = [x[0], 1, 1]\r\n indices.each do |a, row|\r\n b = [1]\r\n row.each_cons(2) do |i, j|\r\n b << (i - j + 1) << 1\r\n end\r\n \r\n l = 0\r\n sum = 0\r\n b.each_with_index do |x, r|\r\n if sum < 0\r\n l = r\r\n sum = x\r\n else\r\n sum += x\r\n end\r\n if sum > ans\r\n ans = sum\r\n ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]\r\n end\r\n end\r\n end\r\n \r\n puts ans_value.join(\" \")\r\nend"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n index = {}\r\n\r\n a.each_with_index do |e, i|\r\n index[e] ||= []\r\n index[e] << i\r\n end\r\n\r\n cnt = 1\r\n\r\n ans = a[0]\r\n l = 1\r\n r = 1\r\n index.each do |k, v|\r\n sum = 1\r\n first = v[0]\r\n prev = v[0]\r\n\r\n v[1..].each do |i|\r\n sum = sum-(i-prev)+2\r\n prev = i\r\n if sum < 1\r\n sum = 1\r\n first = i\r\n end\r\n\r\n if cnt < sum\r\n cnt = sum\r\n ans = k\r\n l = first+1\r\n r = i+1\r\n end\r\n end\r\n end\r\n\r\n puts [ans, l, r].join(\" \")\r\nend\r\n\r\n"}], "negative_code": [{"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n vis = Array.new(n, false)\r\n\r\n l = 1\r\n cnt = 1\r\n max = 1\r\n\r\n num = a[0]\r\n a_l = 0\r\n a_r = 0\r\n\r\n n_l = nil\r\n n_r = 0\r\n\r\n while l < n\r\n next l += 1 if vis[l-1] && vis[l]\r\n if a[l-1] == a[l]\r\n n_l ||= l-1\r\n n_r = l\r\n cnt += 1\r\n else\r\n if cnt > 1\r\n r = l\r\n cnt1 = cnt\r\n while r < n\r\n if a[r] == a[n_l]\r\n vis[r] = true\r\n cnt1 += 1\r\n else\r\n cnt1 -= 1\r\n end\r\n if cnt1 > cnt\r\n cnt = cnt1\r\n n_r = r\r\n end\r\n break if cnt1 <= 0\r\n r += 1\r\n end\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n end\r\n n_l = nil\r\n n_r = 0\r\n cnt = 1\r\n end\r\n l += 1\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[n_l]\r\n end\r\n\r\n puts [num, a_l+1, a_r+1].join(\" \")\r\nend\r\n\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n vis = Array.new(n, false)\r\n\r\n l = 1\r\n cnt = 1\r\n max = 1\r\n\r\n num = a[0]\r\n a_l = 0\r\n a_r = 0\r\n\r\n n_l = nil\r\n n_r = 0\r\n\r\n while l < n\r\n next l += 1 if vis[l]\r\n vis[l] = true\r\n\r\n if a[l-1] == a[l]\r\n n_l ||= l-1\r\n n_r = l\r\n cnt += 1\r\n else\r\n if cnt > 1\r\n r = l\r\n cnt1 = cnt\r\n while r < n\r\n if a[r] == a[l-1]\r\n vis[r] = true\r\n cnt1 += 1\r\n else\r\n cnt1 -= 1\r\n end\r\n if cnt1 > cnt\r\n cnt = cnt1\r\n n_r = r\r\n end\r\n break if cnt1 <= 0\r\n r += 1\r\n end\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[l-1]\r\n end\r\n n_l = nil\r\n n_r = 0\r\n cnt = 1\r\n end\r\n l += 1\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[n_l]\r\n end\r\n\r\n puts [num, a_l+1, a_r+1].join(\" \")\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n vis = Array.new(n, false)\r\n\r\n l = 1\r\n cnt = 1\r\n max = 1\r\n\r\n num = a[0]\r\n a_l = 0\r\n a_r = 0\r\n\r\n n_l = nil\r\n n_r = 0\r\n\r\n while l < n\r\n next l += 1 if vis[l]\r\n vis[l] = true\r\n\r\n if a[l-1] == a[l]\r\n n_l ||= l-1\r\n n_r = l\r\n cnt += 1\r\n else\r\n if cnt > 1\r\n r = l\r\n cnt1 = cnt\r\n while r < n\r\n if a[r] == a[l-1]\r\n vis[r] = true\r\n cnt1 += 1\r\n else\r\n cnt1 -= 1\r\n end\r\n if cnt1 > cnt\r\n cnt = cnt1\r\n n_r = r\r\n end\r\n break if cnt1 < 0\r\n r += 1\r\n end\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[l-1]\r\n end\r\n n_l = nil\r\n n_r = 0\r\n cnt = 1\r\n end\r\n l += 1\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[n_l]\r\n end\r\n\r\n puts [num, a_l+1, a_r+1].join(\" \")\r\nend\r\n\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n vis = Array.new(n, false)\r\n\r\n l = 1\r\n cnt = 0\r\n max = 0\r\n num = -1\r\n\r\n n_l = nil\r\n n_r = 0\r\n\r\n a_l = -1\r\n a_r = -1\r\n\r\n while l < n\r\n next l += 1 if vis[l]\r\n vis[l] = true\r\n\r\n if a[l-1] == a[l]\r\n n_l ||= l-1\r\n n_r = l\r\n cnt += 1\r\n else\r\n if cnt > 0\r\n r = l\r\n cnt1 = cnt\r\n while r < n\r\n if a[r] == a[l-1]\r\n vis[r] = true\r\n cnt1 += 1\r\n else\r\n cnt1 -= 1\r\n end\r\n if cnt1 > cnt\r\n cnt = cnt1\r\n n_r = r\r\n end\r\n break if cnt1 < 0\r\n r += 1\r\n end\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[l-1]\r\n end\r\n n_l = nil\r\n n_r = 0\r\n cnt = 0\r\n end\r\n l += 1\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[n_l]\r\n end\r\n\r\n if n == 1 || num == -1\r\n num = a[0]\r\n a_l = 0\r\n a_r = 0\r\n end\r\n puts [num, a_l+1, a_r+1].join(\" \")\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n vis = Array.new(n, false)\r\n\r\n l = 1\r\n cnt = 0\r\n max = 0\r\n num = -1\r\n\r\n n_l = nil\r\n n_r = 0\r\n\r\n a_l = -1\r\n a_r = -1\r\n\r\n while l < n\r\n next l += 1 if vis[l]\r\n vis[l] = true\r\n\r\n if a[l-1] == a[l]\r\n n_l ||= l-1\r\n n_r = l\r\n cnt += 1\r\n else\r\n if cnt > 0\r\n r = l\r\n cnt1 = cnt\r\n while r < n\r\n if a[r] == a[l-1]\r\n vis[r] = true\r\n cnt1 += 1\r\n else\r\n cnt1 -= 1\r\n end\r\n if cnt1 > cnt\r\n cnt = cnt1\r\n n_r = r\r\n end\r\n break if cnt1 < 0\r\n r += 1\r\n end\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[l-1]\r\n end\r\n n_l = nil\r\n n_r = 0\r\n cnt = 0\r\n end\r\n l += 1\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[l-1]\r\n end\r\n if n == 1 || num == -1\r\n num = a[0]\r\n a_l = 0\r\n a_r = 0\r\n end\r\n puts [num, a_l+1, a_r+1].join(\" \")\r\nend\r\n\r\n"}, {"source_code": "gets.to_i.times do\r\n n = gets.to_i\r\n a = gets.split.map(&:to_i)\r\n vis = Array.new(n, false)\r\n\r\n l = 1\r\n cnt = 0\r\n max = 0\r\n num = 0\r\n\r\n n_l = nil\r\n n_r = 0\r\n\r\n a_l = -1\r\n a_r = -1\r\n\r\n while l < n\r\n next l += 1 if vis[l]\r\n vis[l] = true\r\n\r\n if a[l-1] == a[l]\r\n n_l ||= l-1\r\n cnt += 1\r\n else\r\n if cnt > 0\r\n r = l\r\n n_r = r-1\r\n cnt1 = cnt\r\n while r < n\r\n if a[r] == a[l-1]\r\n vis[r] = true\r\n cnt1 += 1\r\n else\r\n cnt1 -= 1\r\n end\r\n if cnt1 > cnt\r\n cnt = cnt1\r\n n_r = r\r\n end\r\n break if cnt1 < 0\r\n r += 1\r\n end\r\n end\r\n if cnt > max\r\n a_l = n_l\r\n a_r = n_r\r\n max = cnt\r\n num = a[l-1]\r\n end\r\n n_l = nil\r\n n_r = 0\r\n cnt = 0\r\n end\r\n l += 1\r\n end\r\n if n == 1 || a_l == -1\r\n num = a[0]\r\n a_l = 0\r\n a_r = 0\r\n end\r\n puts [num, a_l+1, a_r+1].join(\" \")\r\nend\r\n\r\n"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n x = gets.split.map(&:to_i)\r\n indices = {}\r\n x.each_with_index do |a, i|\r\n (indices[a] ||= []) << i\r\n end\r\n \r\n ans = 1\r\n ans_value = [x[0], 1, 1]\r\n indices.each do |a, row|\r\n b = [1]\r\n row.each_cons(2) do |i, j|\r\n b << (i - j + 1) << 1\r\n end\r\n \r\n l = 0\r\n sum = 1\r\n b.each_with_index do |x, r|\r\n if sum < 0\r\n l = r\r\n sum = x\r\n else\r\n sum += x\r\n end\r\n if sum > ans\r\n ans = sum\r\n ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]\r\n end\r\n end\r\n end\r\n \r\n p ans\r\n puts ans_value.join(\" \")\r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n x = gets.split.map(&:to_i)\r\n indices = {}\r\n x.each_with_index do |a, i|\r\n (indices[a] ||= []) << i\r\n end\r\n \r\n ans = 1\r\n ans_value = [x[0], 1, 1]\r\n indices.each do |a, row|\r\n b = [1]\r\n row.each_cons(2) do |i, j|\r\n b << (i - j + 1) << 1\r\n end\r\n \r\n l = 0\r\n sum = 1\r\n b.each_with_index do |x, r|\r\n if sum < 0\r\n l = r\r\n sum = x\r\n else\r\n sum += x\r\n end\r\n if sum > ans\r\n ans = sum\r\n ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]\r\n end\r\n end\r\n end\r\n \r\n puts ans_value.join(\" \")\r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n x = gets.split.map(&:to_i)\r\n indices = {}\r\n x.each_with_index do |a, i|\r\n (indices[a] ||= []) << i\r\n end\r\n \r\n ans = 0\r\n ans_value = nil\r\n indices.each do |a, row|\r\n b = [1]\r\n row.each_cons(2) do |i, j|\r\n b << (i - j + 1) << 1\r\n end\r\n \r\n l = 0\r\n sum = 1\r\n b.each_with_index do |x, r|\r\n if sum < 0\r\n l = r\r\n sum = x\r\n else\r\n sum += x\r\n end\r\n if sum > ans\r\n ans = sum\r\n ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]\r\n end\r\n end\r\n end\r\n \r\n puts ans_value.join(\" \")\r\nend"}, {"source_code": "t = gets.to_i\r\nt.times do\r\n n = gets.to_i\r\n x = gets.split.map(&:to_i)\r\n indices = {}\r\n x.each_with_index do |a, i|\r\n (indices[a] ||= []) << i\r\n end\r\n \r\n ans = 0\r\n ans_value = nil\r\n indices.each do |a, row|\r\n b = [1]\r\n row.each_cons(2) do |i, j|\r\n b << (j - i + 1) << 1\r\n end\r\n \r\n l = 0\r\n sum = 1\r\n b.each_with_index do |x, r|\r\n if sum < 0\r\n l = r\r\n\tsum = x\r\n else\r\n sum += x\r\n end\r\n if sum > ans\r\n ans = sum\r\n\tans_value = [a, row[l / 2] + 1, row[r / 2] + 1]\r\n end\r\n end\r\n end\r\n \r\n puts ans_value.join(\" \")\r\nend"}], "src_uid": "a07c199ca02f0abaab6c73efdb2a5b2d"} {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\nC = Struct.new(:x, :y)\nt = gets.to_i\nt.times {\n n = gets.to_i\n ar = []\n n.times {\n ar << C.new(*gets.split.map(&:to_i))\n }\n ar.sort! { |a, b|\n if a.x != b.x\n a.x - b.x\n else\n a.y - b.y\n end\n }\n possible = true\n commands = []\n cx, cy = 0, 0\n ar.each { |c|\n # p ar\n if cx <= c.x && cy <= c.y\n # lexicographical move\n # ABCDEFG.....OPQ'R'ST'U'\n # R first, U last\n commands << 'R'*(c.x-cx)\n commands << 'U'*(c.y-cy)\n cx = c.x\n cy = c.y\n else\n possible = false\n break\n end\n }\n\n if possible\n puts \"YES\"\n puts commands.join('')\n else\n puts \"NO\"\n end\n}", "positive_code": [{"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/contest/1294/problem/B\n\nrequire 'set'\n\nn = gets.to_i\n\nn.times do\n size = gets.to_i\n pkgs = {}\n size.times do \n cords = gets.split(' ').map(&:to_i)\n\n pkgs[cords[0]] ||= []\n pkgs[cords[0]] << cords[1] \n end\n\n x = y = 0\n answer = \"\"\n failed = false\n\n while !pkgs.empty? do\n if pkgs[x].nil?\n x += 1\n answer += \"R\"\n else\n mini = pkgs[x].min\n maxi = pkgs[x].max\n\n if mini < y\n failed = true\n break\n else\n answer += \"U\" * (maxi - y)\n y = maxi\n pkgs.delete x\n end\n end\n end\n\n if failed\n puts \"NO\"\n else\n puts \"YES\"\n puts answer\n end\nend"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/contest/1294/problem/B\n\nn = gets.to_i\n\nn.times do\n size = gets.to_i\n pkgs = {}\n size.times do \n cords = gets.split(' ').map(&:to_i)\n\n pkgs[cords[0]] ||= []\n pkgs[cords[0]] << cords[1] \n end\n\n x = y = 0\n answer = \"\"\n failed = false\n\n while !pkgs.empty? do\n if pkgs[x].nil?\n x += 1\n answer += \"R\"\n else\n mini = maxi = y\n \n pkgs[x].each do |val|\n mini = val if val < mini\n maxi = val if val > maxi\n end\n\n if mini < y\n failed = true\n break\n else\n answer += \"U\" * (maxi - y)\n y = maxi\n pkgs.delete x\n end\n end\n end\n\n if failed\n puts \"NO\"\n else\n puts \"YES\"\n puts answer\n end\nend"}, {"source_code": "#!usr/bin/env ruby\n\n# https://codeforces.com/contest/1294/problem/B\n\nn = gets.to_i\n\nn.times do\n size = gets.to_i\n pkgs = []\n size.times do\n pkgs << gets.split(' ').map(&:to_i)\n end\n\n pkgs.sort!\n\n x = y = 0\n failed = false\n answer = \"\"\n\n pkgs.each do |p|\n dx = p[0] - x\n dy = p[1] - y\n\n if dx < 0 || dy < 0\n failed = true\n break\n else\n answer += \"R\" * dx + \"U\" * dy\n x = p[0]\n y = p[1]\n end\n end\n\n if failed\n puts \"NO\"\n else\n puts \"YES\"\n puts answer\n end\nend\n"}, {"source_code": "T = gets.to_i\n\nT.times do\n n = gets.to_i\n\n packages = n.times.map { gets.split.map(&:to_i) }\n\n packages.sort_by! { |x, y| [x, y] }\n\n ans = ''\n cx = 0\n cy = 0\n success = true\n\n packages.each do |x, y|\n dx = x - cx\n dy = y - cy\n\n if dx < 0 || dy < 0\n success = false\n break\n end\n\n ans += 'R' * dx + 'U' * dy\n cx = x\n cy = y\n end\n\n if success\n puts 'YES'\n puts ans\n else\n puts 'NO'\n end\nend\n"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\nC = Struct.new(:x, :y)\nt = gets.to_i\nt.times {\n n = gets.to_i\n ar = []\n n.times {\n ar << gets.chomp\n }\n ar.sort!\n possible = true\n commands = []\n cx, cy = 0, 0\n ar.each { |c|\n x, y = c.split.map(&:to_i)\n if cx <= x && cy <= y\n commands << 'R'*(x-cx)\n commands << 'U'*(y-cy)\n cx = x\n cy = y\n else\n possible = false\n break\n end\n }\n\n if possible\n puts \"YES\"\n puts commands.join('')\n else\n puts \"NO\"\n end\n}"}], "src_uid": "b01c627abc00f97767c237e304f8c17f"} {"source_code": "def solve\n n, m, x, y = gets.strip.split(' ').map(&:to_i)\n an = 0\n n.times {\n str = gets.strip.split('')\n count = 0\n str.each_with_index { |e, i|\n if e == '.' && i < str.size - 1\n count += 1\n else\n count += 1 if e == '.'\n two = (count / 2).floor\n if two * y < two * 2 * x && !two.zero?\n an += (two * y)\n else\n an += (two * 2 * x) \n end\n an += x if count.odd? \n count = 0\n end\n }\n }\n puts an\nend\n\ngets.strip.to_i.times { solve }", "positive_code": [{"source_code": "def solve\n n, m, x, y = gets.strip.split(' ').map(&:to_i)\n an = 0\n n.times {\n str = gets.strip.split('')\n count = 0\n str.each_with_index { |e, i|\n if e == '.' && i < str.size - 1\n count += 1\n else\n count += 1 if e == '.'\n two = (count / 2).floor\n if two * y < two * 2 * x && !two.zero?\n an += (two * y)\n else\n an += (two * 2 * x) \n end\n an += x if count.odd? \n count = 0\n end\n }\n }\n puts an\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": " q = gets.chomp.to_i\n\n q.times {\n\n n, m, x, y = gets.split.map(&:to_i)\n\n table = []\n n.times { \n row = gets.chomp\n table << row\n }\n\n d = []\n n.times { |i|\n d << []\n m.times {\n d[i] << 0\n }\n }\n\n n.times { |i|\n m.times { |j|\n \n if j == 0\n\n if table[i][j] == '.'\n d[i][j] = x\n end\n \n next\n end\n\n d[i][j] = d[i][j - 1]\n \n if table[i][j] == '*'\n next\n end\n\n d[i][j] = d[i][j - 1] + x\n\n if table[i][j - 1] == '.'\n curVal = 0\n if j == 1\n curVal = y\n else\n curVal = d[i][j - 2] + y\n end\n\n d[i][j] = [d[i][j], curVal].min\n end\n }\n }\n\n sum = 0\n d.each { |row|\n sum += row.last\n }\n\n puts sum\n }"}], "negative_code": [{"source_code": "def solve\n n, m, x, y = gets.strip.split(' ').map(&:to_i)\n an = 0\n n.times {\n str = gets.strip.split('')\n count = 0\n str.each_with_index { |e, i|\n if e == '.' && i < str.size - 1\n count += 1\n else\n count += 1 if e == '.'\n two = (count / 2).floor\n if two * y < two * 2 * x && !two.zero?\n an += (two * y)\n else\n an += (two * 2 * x)\n an += x if count.odd? \n end\n count = 0\n end\n }\n }\n puts an\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "def solve\n n, m, x, y = gets.strip.split(' ').map(&:to_i)\n an = 0\n n.times {\n str = gets.strip.split('')\n count = 0\n str.each_with_index { |e, i|\n if e == '.' && i < str.size - 1\n count += 1\n else\n count += 1 if e == '.'\n two = (count / 2).to_i\n if two * y < count * x && !two.zero?\n an += (two * y)\n else\n an += (count * x) \n end\n count = 0\n end\n }\n }\n puts an\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "def solve\n n, m, x, y = gets.strip.split(' ').map(&:to_i)\n an = 0\n n.times {\n str = gets.strip.split('')\n count = 0\n str.each_with_index { |e, i|\n if e == '.' && i < str.size - 1\n count += 1\n else\n count += 1 if e == '.'\n two = (count / 2).to_i\n if two * y < two * 2 * x && !two.zero?\n an += (two * y)\n else\n an += (two * 2 * x)\n an += x if count.odd? \n end\n count = 0\n end\n }\n }\n puts an\nend\n\ngets.strip.to_i.times { solve }"}, {"source_code": "def solve\n n, m, x, y = gets.strip.split(' ').map(&:to_i)\n an = 0\n n.times {\n str = gets.strip.split('')\n count = 0\n p str\n str.each_with_index { |e, i|\n if e == '.' && i < str.size - 1\n count += 1\n else\n count += 1 if e == '.'\n two = (count / 2).to_i\n if two * y < count * x && !two.zero?\n an += (two * y)\n else\n an += (count * x) \n end\n count = 0\n end\n }\n }\n puts an\nend\n\ngets.strip.to_i.times { solve }"}], "src_uid": "69ef9492fcdcc979cb31fa95c3e76db9"} {"source_code": "n, m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\np (0...n).map{|i|b.map{|x| (0...n).select{|j|i!=j}.map{|j|a[j]*x}.max}.max}.min\n", "positive_code": [{"source_code": "n, m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\np (0...n).map{|i|b.map{|x| (0...n).select{|j|i!=j}.map{|j|a[j]*x}.max}.max}.min\n"}, {"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\ntat=1\nres=-1e18\nfor i in 0..n-1\n for j in 0..m-1\n if a[i]*b[j]>res\n res=a[i]*b[j]\n tat=i\n end\n end\nend\nres=-1e18.to_i\na[tat]=a[n-1]\nfor i in 0..n-2\n for j in b\n res=[res,a[i]*j].max\n end\nend\np res"}, {"source_code": "n, m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\np (0...n).map{ |i| \nb.map{|x| \n(0...n).select{ |j| i!=j }.map{|j|a[j]*x}.max}.max}.min"}], "negative_code": [{"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\nif a[0]==-1000000000\n p b[0]\nend\ntat=1\nres=-1e18\nfor i in 0..n-1\n for j in 0..m-1\n if a[i]*b[j]>res\n res=a[i]*b[j]\n tat=i\n end\n end\nend\nres=-1e18\na[tat]=0\nfor i in a\n for j in b\n res=[res,i*j].max\n end\nend\np res\n"}, {"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\ntat=1\nres=-1e18\nfor i in 0..n-1\n for j in 0..m-1\n if a[i]*b[j]>res\n res=a[i]*b[j]\n tat=i\n end\n end\nend\nres=-1e18\na[tat]=0\nfor i in a\n for j in b\n res=[res,i*j].max\n end\nend\np res"}, {"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\ntat=1\nres=-1e9\nfor i in 0..n-1\n for j in 0..m-1\n if a[i]*b[j]>res\n res=a[i]*b[j]\n tat=i\n end\n end\nend\nres=-1e9\na[tat]=0\nfor i in a\n for j in b\n res=[res,i*j].max\n end\nend\np res"}, {"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\nif a[0]==-1000000000\n p b[0]\nend\ntat=1\nres=-1e18\nfor i in 0..n-1\n for j in 0..m-1\n if a[i]*b[j]>res\n res=a[i]*b[j]\n tat=i\n end\n end\nend\nres=-1e18\na[tat]=a[n-1]\nfor i in 0..n-2\n for j in b\n res=[res,a[i]*j].max\n end\nend\np res\n"}, {"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\ntat=1\nres=-1e18\nfor i in 0..n-1\n for j in 0..m-1\n if a[i]*b[j]>res\n res=a[i]*b[j]\n tat=i\n end\n end\nend\nres=-1e18\na[tat]=a[n-1]\nfor i in 0..n-2\n for j in b\n res=[res,a[i]*j].max\n end\nend\np res"}, {"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\ntat=1\nres=-1e18\nfor i in 0..n-1\n for j in 0..m-1\n if a[i]*b[j]>res\n res=a[i]*b[j]\n tat=i\n end\n end\nend\nres=-1e18\na[tat]=0\nfor i in a\n for j in b\n if i!=tat\n res=[res,i*j].max\n end\n end\nend\np res\n"}, {"source_code": "n,m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\nif a[0]==-1000000000\n p b[0]\nend\ntat=1\nres=-1e18\nfor i in 0..n-1\n for j in 0..m-1\n if a[i]*b[j]>res\n res=a[i]*b[j]\n tat=i\n end\n end\nend\nres=-1e18.to_i\na[tat]=a[n-1]\nfor i in 0..n-2\n for j in b\n res=[res,a[i]*j].max\n end\nend\np res"}, {"source_code": "n, m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\na.delete a.max\nputs a.max * b.max"}, {"source_code": "n, m=gets.split.map &:to_i\na=gets.split.map &:to_i\nb=gets.split.map &:to_i\na.sort!\nputs a[n-2] * b.max"}], "src_uid": "c408b1d198c7c88fc635936d960c962a"} {"source_code": "n, k = gets.split(' ').map(&:to_i)\n\ns,b = Hash.new(0),Hash.new(0)\n\nn.times do \n d,p,q = gets.split(' ').map{|e| e}\n p,q = p.to_i,q.to_i\n \n s[p] += q if d == 'S'\n b[p] += q if d == 'B'\nend\n\ns.keys.sort.first(k).reverse_each{|e| puts \"S #{e} #{s[e]}\"}\nb.keys.sort.last(k).reverse_each{ |e| puts \"B #{e} #{b[e]}\"}", "positive_code": [{"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|k}[0,s].reverse.each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n\n"}, {"source_code": "#!/usr/bin/ruby\n\nB = {}\nS = {}\n\ndef algo\n n, s = gets.split(\" \").map { |e| e.to_i }\n n.times.each do\n d, p, v = gets.split(\" \")\n p = p.to_i\n v = v.to_i\n eval(d)[p] ||= 0\n eval(d)[p] += v\n end\n ks = S.keys.sort.take(s).reverse\n kb = B.keys.sort.reverse.take(s)\n ks.each { |e| puts \"S #{e} #{S[e]}\" }\n kb.each { |e| puts \"B #{e} #{B[e]}\" }\nend\n\nalgo\n"}, {"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|k}[0,s].reverse.each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n\n"}, {"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|k}[0,s].reverse.each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n\n"}, {"source_code": "\nn,s = gets.split(\" \").map(&:to_i)\nsell = Hash.new(0)\nbuy = Hash.new(0)\nn.times{\n ccc,p,q = gets.split(\" \")\n p = p.to_i\n q = q.to_i\n if ccc == 'B'\n buy[p]+=q\n else\n sell[p]+=q\n end \n}\nans = sell.keys.sort.take(s).reverse.map{|x| \"S #{x} #{sell[x]}\"}\nans += buy.keys.sort.last(s).reverse.map{|x| \"B #{x} #{buy[x]}\"}\nputs ans"}, {"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|k}[0,s].reverse.each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n\n"}, {"source_code": "# http://codeforces.com/contest/572/problem/B\nn, m = gets.chomp.split.map(&:to_i)\nb = Hash.new { 0 }\ns = Hash.new { 0 }\n\nn.times do\n d, p, q = gets.chomp.split\n p = p.to_i\n q = q.to_i\n b[p] += q if d == 'B'\n s[p] += q if d == 'S'\nend\n\ns.keys.sort.first(m).reverse.each do |key|\n puts ['S', key, s[key]].join(' ')\nend\n\nb.keys.sort.last(m).reverse.each do |key|\n puts ['B', key, b[key]].join(' ')\nend\n"}, {"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|k}[0,s].reverse.each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\ns = Hash.new(0)\nb = Hash.new(0)\nn.times do\n d, p, q = gets.split(' ')\n p = p.to_i\n q = q.to_i\n s[p] += q if (d==\"S\")\n b[p] += q if (d==\"B\")\nend\ns.sort.first(k).reverse_each{|x|\t\n\tputs \"S #{x.first} #{x.last}\"\n}\nb.sort.last(k).reverse_each{|x| \n puts \"B #{x.first} #{x.last}\"\n}"}, {"source_code": "n, k = gets.split.map(&:to_i)\ns = Hash.new(0)\nb = Hash.new(0)\nn.times do\n d, p, q = gets.split(\" \")\n p = p.to_i\n q = q.to_i\n s[p] += q if (d==\"S\")\n b[p] += q if (d==\"B\")\nend\ns.sort.first(k).reverse.each{|x|\t\n\tputs \"S #{x.first} #{x.last}\"\n}\nb.sort.last(k).reverse.each{|x| \n puts \"B #{x.first} #{x.last}\"\n}"}, {"source_code": "n, k = gets.split.map(&:to_i)\ns = Hash.new(0)\n\nb = Hash.new(0)\nn.times do\n d, p, q = gets.split(\" \")\n p = p.to_i\n q = q.to_i\n s[p] += q if (d==\"S\")\n b[p] += q if (d==\"B\")\nend\ns.sort.first(k).reverse_each{|x|\t\n\tputs \"S #{x.first} #{x.last}\"\n}\nb.sort.last(k).reverse_each{|x| \n puts \"B #{x.first} #{x.last}\"\n}"}, {"source_code": "n, k = gets.split.map(&:to_i)\ns = Hash.new(0)\nb = Hash.new(0)\nn.times do\n d, p, q = gets.split(\" \")\n p = p.to_i\n q = q.to_i\n s[p] += q if (d==\"S\")\n b[p] += q if (d==\"B\")\nend\ns.sort.first(k).reverse_each{|x|\t\n\tputs \"S #{x.first} #{x.last}\"\n}\nb.sort.last(k).reverse_each{|x| \n puts \"B #{x.first} #{x.last}\"\n}"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\ns = Hash.new(0)\nb = Hash.new(0)\n\nn.times do\n d, p, q = gets.split\n p = p.to_i\n q = q.to_i\n s[p] += q if d == 'S'\n b[p] += q if d == 'B'\nend\ns.keys.sort.first(k).reverse_each { |e| puts \"S #{e} #{s[e]}\" }\nb.keys.sort.last(k).reverse_each { |e| puts \"B #{e} #{b[e]}\" }\n"}, {"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|k}[0,s].reverse.each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n"}, {"source_code": "total_num, depth = *gets.chomp.split(\" \").map(&:to_i)\n\naggregated = { \n 'B' => {}, \n 'S' => {}\n}\n\ntotal_num.times do |index|\n input = gets.chomp.split(\" \")\n direction, price, amount = input[0], input[1].to_i, input[2].to_i\n aggregated[direction][price] = aggregated[direction][price] ? aggregated[direction][price] + amount : amount\nend\n\n%w(S B).each do |direction|\n prices = aggregated[direction].keys.sort\n prices = direction == 'B' ? prices.reverse.first(depth) : prices.reverse.last(depth)\n prices.each { |price| puts \"#{direction} #{price} #{aggregated[direction][price]}\" }\nend\n"}, {"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|k}[0,s].reverse.each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n\n"}, {"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|k}[0,s].reverse.each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n\n"}, {"source_code": "n, s = gets.split(' ').map(&:to_i)\n\nag_buy = {}\nag_sell = {}\n\nn.times {\n dir, price, vol = gets.split(' ')\n price = price.to_i\n vol = vol.to_i\n ag = dir == \"S\" ? ag_sell : ag_buy\n ag[price] ||= 0\n ag[price] += vol\n}\n\nar = ag_sell.keys.sort.take(s).reverse.map { |p| \"S #{p} #{ag_sell[p]}\" }\nar += ag_buy.keys.sort.last(s).reverse.map { |p| \"B #{p} #{ag_buy[p]}\" }\n\nputs ar\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\n\ns = Hash.new(0)\nb = Hash.new(0)\n\nn.times do\n d, p, q = gets.split.map{|e| e}\n p = p.to_i\n q = q.to_i\n\n s[p] += q if d == 'S'\n b[p] += q if d == 'B'\nend\n\ns.keys.sort.first(k).reverse_each{ |e| puts \"S #{e} #{s[e]}\" }\nb.keys.sort.last(k).reverse_each{ |e| puts \"B #{e} #{b[e]}\" }"}, {"source_code": "n, k = gets.split.map(&:to_i)\nd, p, q = 0, 0, 0\n\ns = Hash.new\nb = Hash.new\ns.default, b.default = 0, 0\n\nfor i in 1..n\n d, p, q = gets.split.map{|e| e}\n p = p.to_i\n q = q.to_i\n\n s[p] += q if d == 'S'\n b[p] += q if d == 'B'\nend\n\nout = ''\n\nfor i in 1..[k, s.size].min\n min = s.keys.min\n out = \"S #{min} #{s[min]}\\n\" + out\n s.delete(min)\nend\n\nprint out\n\nfor i in 1..[k, b.size].min\n max = b.keys.max\n puts \"B #{max} #{b[max]}\"\n b.delete(max)\nend"}, {"source_code": "n, k = gets.split.map(&:to_i)\nd, p, q = 0, 0, 0\n\ns = Hash.new\nb = Hash.new\n\nfor i in 1..n\n d, p, q = gets.split.map{|e| e}\n p = p.to_i\n q = q.to_i\n\n if d == 'S'\n if s.has_key?(p)\n s[p] += q\n else\n s[p] = q\n end\n end\n\n if d == 'B'\n if b.has_key?(p)\n b[p] += q\n else\n b[p] = q\n end\n end\nend\n\nout = ''\n\nfor i in 1..[k, s.size].min\n min = s.keys.min\n out = \"S #{min} #{s[min]}\\n\" + out\n s.delete(min)\nend\n\nprint out\n\nfor i in 1..[k, b.size].min\n max = b.keys.max\n puts \"B #{max} #{b[max]}\"\n b.delete(max)\nend"}, {"source_code": "n, s = gets.chomp.split(' ').map(&:to_i)\nds = []\nps = []\nqs = []\nn.times do\n d, p, q = gets.chomp.split(' ')\n ds << d\n ps << p.to_i\n qs << q.to_i\nend\n\nbuy = Hash.new(0)\nbp = []\nsell = Hash.new(0)\nsp = []\nfor i in 0..n-1\n if ds[i] == 'B'\n buy[ps[i]] += qs[i]\n bp << ps[i]\n else\n sell[ps[i]] += qs[i]\n sp << ps[i]\n end\nend\n\nbp.sort!.uniq!\nsp.sort!.uniq!\n\nns = ([] << s << sp.size).min\nfor i in 0..ns - 1\n puts \"S #{sp[ns - i - 1]} #{sell[sp[ns - i - 1]]}\"\nend\n\nnb = ([] << s << bp.size).min\nfor i in 0..nb - 1\n puts \"B #{bp[bp.size - i - 1]} #{buy[bp[bp.size - i - 1]]}\"\nend\n"}, {"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|k}[0,s].reverse.each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n\n"}, {"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|k}[0,s].reverse.each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\na = n.times.map{gets.split.tap{|x| x[1], x[2] = x[1].to_i, x[2].to_i}}.sort_by{|x| x[1]}\nbuy, sell = a.partition{|x| x[0] == 'B'}\ndef f(a)\n a.group_by{|x| x[1]}\n .map{|_, x| [x[0][0], x[0][1], x.map(&:last).inject(:+)]}\nend\nbuy = f(buy).reverse.take(s)\nsell = f(sell).take(s).reverse\n\nputs (sell + buy).map{|x| x.join(' ')}\n"}, {"source_code": "n, s = gets.split.map(&:to_i)\na = n.times.map{gets.split}.sort_by{|x| x[1].to_i}\na.each{|x| x[1], x[2] = x[1].to_i, x[2].to_i}\nbuy, sell = a.partition{|x| x[0] == 'B'}\ndef f(a)\n b = a.group_by{|x| x[1]}\n b.map{|x| [x[1][0][0], x[1][0][1], x[1].reduce(0){|sum, y| sum + y[2]}]}\nend\nbuy = f(buy).reverse[0...[s, buy.size].min]\nsell = f(sell)[0...[s, sell.size].min].reverse\n\nputs (sell + buy).map{|x| x.join(' ')}\n"}], "negative_code": [{"source_code": "n,s = gets.split(\" \").map(&:to_i)\nsell = Hash.new(0)\nbuy = Hash.new(0)\nn.times{\n ccc,p,q = gets.split(\" \")\n p = p.to_i\n q = q.to_i\n if ccc == 'B'\n buy[p]+=q\n else\n sell[p]+=q\n end \n}\nans = sell.values.sort.last(s).reverse.map{|x| \"S #{sell.index(x)} #{x}\"}\nans += buy.values.sort.last(s).reverse.map{|x| \"B #{buy.index(x)} #{x}\"}\nputs ans"}, {"source_code": "n,s = gets.split(\" \").map(&:to_i)\nbuy = Hash.new(0)\nsell = Hash.new(0)\nfor i in 1..n\n ccc,p,q = gets.split(\" \")\n p = p.to_i\n q = q.to_i\n if ccc=='B'\n buy[p]+=q\n else\n sell[p]+=q\n end \nend\nbuy = buy.sort_by { |x, y| [ -Integer(y), x ] }\nsell = sell.sort_by { |x, y| [ -Integer(y), x ] }\ni=0\nsell.each do |key,value|\n puts \"S #{key} #{value}\"\n i+=1\n if i==s || i==sell.size\n break\n end \nend \ni=0\nbuy.each do |key,value|\n puts \"B #{key} #{value}\"\n i+=1\n if i==s || i==buy.size\n break\n end \nend\n "}, {"source_code": "# http://codeforces.com/contest/572/problem/B\nn, m = gets.chomp.split.map(&:to_i)\nb = Hash.new { 0 }\ns = Hash.new { 0 }\n\nn.times do\n d, p, q = gets.chomp.split\n p = p.to_i\n q = q.to_i\n\n if d == 'B'\n b[p] += q\n else\n s[p] += q\n end\nend\n\nb = b.to_a.sort_by { |x, y| -(x * y) }\ns = s.to_a.sort_by { |x, y| x * y }\n\n(0...m).each do |idx|\n puts (['S'] + s[idx]).join(' ')\nend\n\n(0...m).each do |idx|\n puts (['B'] + b[idx]).join(' ')\nend\n"}, {"source_code": "# http://codeforces.com/contest/572/problem/B\nn, m = gets.chomp.split.map(&:to_i)\nb = Hash.new { 0 }\ns = Hash.new { 0 }\n\nn.times do\n d, p, q = gets.chomp.split\n p = p.to_i\n q = q.to_i\n\n if d == 'B'\n b[p] += q\n else\n s[p] += q\n end\nend\n\nb = b.to_a.sort_by { |x, y| -(x * y) }\ns = s.to_a.sort_by { |x, y| x * y }\n\n\n(0...m).each do |idx|\n puts (['S'] + s[idx]).join(' ')\nend\n\n(0...m).each do |idx|\n puts (['B'] + b[idx]).join(' ')\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\ns = Hash.new(0)\nb = Hash.new(0)\nn.times do\n d, p, q = gets.split(\" \")\n p = p.to_i\n q = q.to_i\n s[p] += q if (d==\"S\")\n b[p] += q if (d==\"B\")\nend\ns.sort.first(k).each{|x| \n print \"S \"\n puts \"#{x.first} #{x.last}\"\n}\nb.sort.last(k).each{|x| \n print \"B \"\n puts \"#{x.first} #{x.last}\"\n}"}, {"source_code": "total_num, depth = *gets.chomp.split(\" \").map(&:to_i)\n\naggregated = { \n 'B' => {}, \n 'S' => {}\n}\n\ntotal_num.times do |index|\n input = gets.chomp.split(\" \")\n direction, price, amount = input[0], input[1].to_i, input[2].to_i\n aggregated[direction][price] = aggregated[direction][price] ? aggregated[direction][price] + amount : amount\nend\n\n%w(S B).each do |direction|\n prices = aggregated[direction].keys.sort\n prices = prices.reverse if direction == 'B'\n prices.first(depth).each do |price|\n puts \"#{direction} #{price} #{aggregated[direction][price]}\" \n end\nend\n"}, {"source_code": "total_num, depth = *gets.chomp.split(\" \").map(&:to_i)\n\naggregated = { \n 'B' => {}, \n 'S' => {}\n}\n\ntotal_num.times do |index|\n input = gets.chomp.split(\" \")\n direction, price, amount = input[0], input[1].to_i, input[2].to_i\n aggregated[direction][price] = aggregated[direction][price] ? aggregated[direction][price] + amount : amount\nend\n\n\n%w(S B).each do |direction|\n aggregated[direction].keys.sort.reverse.first(depth).each do |price|\n \tputs \"#{direction} #{price} #{aggregated[direction][price]}\" \n end\nend\n"}, {"source_code": "n, k = gets.split.map(&:to_i)\nd, p, q = 0, 0, 0\n\ns = Hash.new\nb = Hash.new\n\nfor i in 1..n\n d, p, q = gets.split.map{|e| e}\n q = q.to_i\n\n if d == 'S'\n if s.has_key?(p)\n s[p] += q\n else\n s[p] = q\n end\n end\n\n if d == 'B'\n if b.has_key?(p)\n b[p] += q\n else\n b[p] = q\n end\n end\nend\n\nout = ''\n\nfor i in 1..[k, s.size].min\n min = s.keys.min\n out = \"S #{min} #{s[min]}\\n\" + out\n s.delete(min)\nend\n\nprint out\n\nfor i in 1..[k, b.size].min\n max = b.keys.max\n puts \"B #{max} #{b[max]}\"\n b.delete(max)\nend"}, {"source_code": "n, k = gets.split.map(&:to_i)\nd, p, q = 0, 0, 0\n\ns = Hash.new\nb = Hash.new\n\nfor i in 1..n\n d, p, q = gets.split.map{|e| e}\n q = q.to_i\n\n if d == 'S'\n if s.has_key?(p)\n s[p] += q\n else\n s[p] = q\n end\n end\n\n if d == 'B'\n if b.has_key?(p)\n b[p] += q\n else\n b[p] = q\n end\n end\nend\n\nout = ''\n\nfor i in 1..[k, s.size].min\n min = s.keys.min\n out = \"S #{min} #{s[min]}\\n\" + out\n s.delete(min)\nend\n\nputs out\n\nfor i in 1..[k, b.size].min\n max = b.keys.max\n puts \"B #{max} #{b[max]}\"\n b.delete(max)\nend"}, {"source_code": "n, s = gets.chomp.split(' ').map(&:to_i)\nds = []\nps = []\nqs = []\nn.times do\n d, p, q = gets.chomp.split(' ')\n ds << d\n ps << p.to_i\n qs << q.to_i\nend\n\nbuy = Hash.new(0)\nbp = []\nsell = Hash.new(0)\nsp = []\nfor i in 0..n-1\n if ds[i] == 'B'\n buy[ps[i]] += qs[i]\n bp << ps[i]\n else\n sell[ps[i]] += qs[i]\n sp << ps[i]\n end\nend\n\nbp.sort!.uniq!\nsp.sort!.uniq!\n\nfor i in 0..([] << s << sp.size).min - 1\n puts \"S #{sp[sp.size-i-1]} #{sell[sp[s-i-1]]}\"\nend\n\nfor i in 0..([] << s << bp.size).min - 1\n puts \"B #{bp[bp.size-i-1]} #{buy[bp[bp.size-i-1]]}\"\nend\n"}, {"source_code": "n, s = gets.chomp.split(' ').map(&:to_i)\nds = []\nps = []\nqs = []\nn.times do\n d, p, q = gets.chomp.split(' ')\n ds << d\n ps << p.to_i\n qs << q.to_i\nend\n\nbuy = Hash.new(0)\nbp = []\nsell = Hash.new(0)\nsp = []\nfor i in 0..n-1\n if ds[i] == 'B'\n buy[ps[i]] += qs[i]\n bp << ps[i]\n else\n sell[ps[i]] += qs[i]\n sp << ps[i]\n end\nend\n\nbp.sort!.uniq!\nsp.sort!.uniq!\n\nfor i in 0..([] << s << sp.size).min - 1\n puts \"S #{sp[s-i-1]} #{sell[sp[s-i-1]]}\"\nend\n\nfor i in 0..([] << s << bp.size).min - 1\n puts \"B #{bp[bp.size-i-1]} #{buy[bp[bp.size-i-1]]}\"\nend\n"}, {"source_code": "n, s = gets.chomp.split(' ').map(&:to_i)\nds = []\nps = []\nqs = []\nn.times do\n d, p, q = gets.chomp.split(' ')\n ds << d\n ps << p.to_i\n qs << q.to_i\nend\n\nbuy = Hash.new(0)\nbp = []\nsell = Hash.new(0)\nsp = []\nfor i in 0..n-1\n if ds[i] == 'B'\n buy[ps[i]] += qs[i]\n bp << ps[i]\n else\n sell[ps[i]] += qs[i]\n sp << ps[i]\n end\nend\n\nbp.sort!.uniq!\nsp.sort!.uniq!\n\nfor i in 0..([] << s << sp.size).min - 1\n puts \"S #{sp[sp.size-i-1]} #{sell[sp[sp.size-i-1]]}\"\nend\n\nfor i in 0..([] << s << bp.size).min - 1\n puts \"B #{bp[bp.size-i-1]} #{buy[bp[bp.size-i-1]]}\"\nend\n"}, {"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|k}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n"}, {"source_code": "n,s=gets.split.map &:to_i\nB={}\nS={}\n$<.map{|l|\n d,p,q=l.split\n (d==?B ? B : S)[p.to_i] ||= 0\n (d==?B ? B : S)[p.to_i] += q.to_i\n}\nS.sort_by{|k,v|v}.reverse[0,s].each{|k,v|puts\"S #{k} #{v}\"}\nB.sort_by{|k,v|v}.reverse[0,s].each{|k,v|puts\"B #{k} #{v}\"}\n"}, {"source_code": "#!/usr/bin/ruby\n\nB = {}\nS = {}\n\ndef algo\n n, s = gets.split(\" \").map { |e| e.to_i }\n n.times.each do\n d, p, v = gets.split(\" \")\n p = p.to_i\n v = v.to_i\n eval(d)[p] ||= 0\n eval(d)[p] += v\n end\n ks = S.keys.sort.reverse.take(s)\n kb = B.keys.sort.reverse.take(s)\n ks.each { |e| puts \"S #{e} #{S[e]}\" }\n kb.each { |e| puts \"B #{e} #{B[e]}\" }\nend\n\nalgo\n"}, {"source_code": "#!/usr/bin/ruby\n\nB = {}\nS = {}\n\ndef algo\n n, s = gets.split(\" \").map { |e| e.to_i }\n n.times.each do\n d, p, v = gets.split(\" \")\n p = p.to_i\n v = v.to_i\n eval(d)[p] ||= 0\n eval(d)[p] += v\n end\n ks = S.keys.sort.take(s)\n kb = B.keys.sort.reverse.take(s)\n ks.each { |e| puts \"S #{e} #{S[e]}\" }\n kb.each { |e| puts \"B #{e} #{B[e]}\" }\nend\n\nalgo\n"}], "src_uid": "267c04c77f97bbdf7697dc88c7bfa4af"} {"source_code": "STDIN.reopen 'input.txt'\nSTDOUT.reopen 'output.txt'\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+\n", "positive_code": [{"source_code": "f = File.open('input.txt', 'r') or die \"Unable to open file...\"\ninput = [] # start with an empty array\n f.each_line {|line|\n input.push line\n } \n\nk = input[0].scan(/\\w+/)[1].to_i\njars = input[1].scan(/\\w+/).map!(&:to_i)\ntotal = jars.inject(0) do |give, jar|\n nom = 0\n until jar < k or nom == 3 do\n jar = jar - k\n nom += 1\n end\n \n if jar < k or nom == 3\n give += jar\n end \n\nend\n\n File.open('output.txt', 'w') { |o| o.puts total} \n\n"}, {"source_code": "STDIN.reopen 'input.txt'\nSTDOUT.reopen 'output.txt'\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+\n"}, {"source_code": "STDIN.reopen 'input.txt'\nSTDOUT.reopen 'output.txt'\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+\n"}, {"source_code": "STDIN.reopen 'input.txt'\nSTDOUT.reopen 'output.txt'\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+\n"}, {"source_code": "STDIN.reopen 'input.txt'\nSTDOUT.reopen 'output.txt'\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+"}, {"source_code": "if File.exist?('input.txt')\n input = IO.readlines(\"input.txt\")\n input.each do |word| \n word.delete!(\"\\n\")\n end\nend\ninput1 = input[0]\ninput2 = input[1]\n\n# a = []\n\nk = input1.split(\" \")[1].to_i\n\npiglet_honey = 0\n\ninput2.split(\" \").each do |e|\n\n if e.to_i > 3*k\n piglet_honey += e.to_i - 3*k \n else\n piglet_honey += e.to_i%k \n end\nend\n\noutput = File.open( \"output.txt\",\"w\" )\noutput << piglet_honey\noutput.close\n"}, {"source_code": "$stdin.reopen 'input.txt'\n$stdout.reopen 'output.txt'\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+\n"}, {"source_code": "STDIN.reopen 'input.txt'\nSTDOUT.reopen 'output.txt'\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+"}, {"source_code": "$stdin.reopen('input.txt')\n$stdout.reopen('output.txt')\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+\n"}, {"source_code": "STDIN.reopen 'input.txt'\nSTDOUT.reopen 'output.txt'\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+\n"}, {"source_code": "n, k, a = nil\nFile.open(\"input.txt\") do |f|\n n, k = f.gets.split.map(&:to_i)\n a = f.gets.split.map(&:to_i)\nend\n\ns = a.inject(0){|r, x| r+(x>=3*k ? x-3*k : x%k)}\n\nFile.open(\"output.txt\", \"w\") do |f|\n f.puts s\nend\n"}, {"source_code": "require 'scanf'\n\ninput = open(\"input.txt\")\n\nline = input.gets\nl1 = line.scanf(\"%d %d\")\nn = l1[0]\nk = l1[1]\n\nline = input.gets\na = line.scan(/[\\d]+/)\n\nret = 0\n\na.each do |i|\n ret += [i.to_i % k, i.to_i - 3 * k].max\nend\n\noutput = open(\"output.txt\", \"w\")\noutput.printf \"%d\\n\" % [ret]\n"}, {"source_code": "STDIN.reopen 'input.txt'\nSTDOUT.reopen 'output.txt'\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+\n"}, {"source_code": "STDIN.reopen 'input.txt'\nSTDOUT.reopen 'output.txt'\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+\n"}, {"source_code": "STDIN.reopen 'input.txt'\nSTDOUT.reopen 'output.txt'\nN, K = gets.split.map &:to_i\nA = gets.split.map &:to_i\np A.map { |v| v - [v / K, 3].min * K }.reduce :+\n"}], "negative_code": [], "src_uid": "f9a691cdf7047ab82d2e2c903a53fc7e"} {"source_code": "$h = Hash.new(0)\n$l = 0\n$r = 0\n\ndef solve\n type, id = gets.strip.split(' ')\n id = id.to_i\n if type == \"L\"\n $l += 1\n $h[[id, 0]] = $l\n elsif type == \"R\"\n $r += 1\n $h[[id, 1]] = $r\n else\n flg_left = false; flg_right = false\n if $h[[id, 0]].zero? && !$h[[id, 1]].zero?\n ok = $h[[id, 1]]\n flg_right = true\n elsif !$h[[id, 0]].zero? && $h[[id, 1]].zero?\n flg_left = true\n ok = $h[[id, 0]]\n end\n if flg_left == true\n s = [$l - ok, ok - 1 + $r].min\n puts s\n elsif flg_right == true\n s = [$r - ok, ok - 1 + $l].min\n puts s\n end\n end\nend\n\ngets.strip.to_i.times { solve }\n", "positive_code": [{"source_code": "\ndef solution\n n = read_int\n\n left = 500_000\n right = left + 1\n shelf = {}\n\n n.times do\n command, id = read_string.split\n case command\n when ?L\n shelf[id] = left\n left -= 1\n when ?R\n shelf[id] = right\n right += 1\n when ??\n pos = shelf[id]\n puts [pos - left - 1, right - pos - 1].min\n end\n\n end\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"}], "negative_code": [{"source_code": "$h = Hash.new(0)\n$l = 0\n$r = 0\n\ndef solve\n type, id = gets.strip.split(' ')\n id = id.to_i\n if type == \"L\"\n $l += 1\n $h[[id, 0]] = $l\n elsif type == \"R\"\n $r += 1\n $h[[id, 1]] = $r\n else\n ok = -1\n flg_left = false; flg_right = false\n if $h[[id, 0]].zero? && !$h[[id, 1]].zero?\n ok = $h[[id, 1]]\n flg_right = true\n elsif !$h[[id, 0]].zero? && $h[[id, 1]].zero?\n flg_left = true\n ok = $h[[id, 0]]\n end\n if flg_left == true\n s = [$l - ok, $l - ok + $r].min\n puts s\n elsif flg_right == true\n s = [$r - ok, $r - ok + $l].min\n puts s\n end\n end\nend\n\ngets.strip.to_i.times { solve }\n"}], "src_uid": "e61509d5f0bcd405b1a0c9ba74449df2"} {"source_code": "def count(a,d)\n tot = 0\n if a > d/2\n tot = d-a\n else\n # as the doors opened are fewer we need to count that amount of time to close them\n tot = a\n end\n tot\nend\n\ndef calculate(n,l,r)\n # I choose to count 1s and then do the calculation for both sides\n lopens = l.count(1)\n ropens = r.count(1)\n tot_sec = 0\n\n tot_sec += count(lopens,n)\n tot_sec += count(ropens,n)\n\n tot_sec\nend\n\nn = gets.to_i\nr = []\nl = []\n(1..n).each do\n a,b = gets.split(/\\s/).map(&:to_i)\n l << a\n r << b\nend\n\nputs calculate(n,l,r)", "positive_code": [{"source_code": "def min(x, y)\n if x < y then\n return x\n else \n return y\n end\nend\n\nn = gets.to_i\n\nleft_open = 0\nleft_close = 0\nright_open = 0\nright_close = 0\nn.times do |i|\n s = gets.split.collect{|j| j.to_i}\n if s[0] == 1 then\n left_open += 1\n else\n left_close += 1\n end\n if s[1] == 1 then\n right_open += 1\n else\n right_close += 1\n end\nend\nright = min(right_close, right_open)\nleft = min(left_close, left_open)\nt = right + left\nputs t"}, {"source_code": "n=gets.to_i\na,b=0,0\nn.times{\n\tc,d=gets.split.map(&:to_i)\n\ta += c \n\tb += d\n}\nputs [a,n-a].min + [b,n-b].min\n\n"}, {"source_code": "n,a = gets.to_i ,Array.new{|el| el=Array.new(2)}\nn.times{a<=a1/2\n rez+=a-sum1\nelse\n rez+=sum1\nend\n\nif sum2>=a1/2\n rez+=a-sum2\nelse\n rez+=sum2\nend\nputs rez\n\n"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\ndata = []\n\nleft_open = 0\nright_open = 0\nn.times{\n left, right = gets.split.map(&:to_i)\n \n left_open+=left\n right_open+=right\n}\n\nleft_closed = n - left_open\nright_closed = n - right_open\n\nprint [left_open, left_closed].min + [right_open, right_closed].min"}, {"source_code": "require 'set'\nrequire 'rational'\nrequire 'mathn'\ninclude Math\n$stdin = File.open(\"./input.txt\", \"r\") if ENV[\"USER\"] == \"new\"\n# ====================================\n\nn = gets.to_i\ndata = []\n\nn.times{\n data << gets.split.map(&:to_i)\n}\n\nleft_open = 0\nright_open = 0\ndata.each{|left, right|\n left_open+=left\n right_open+=right\n}\n\nleft_closed = n - left_open\nright_closed = n - right_open\n\nprint [left_open, left_closed].min + [right_open, right_closed].min"}, {"source_code": "n=gets.to_i\na=b=0\nn.times {\n\tl,r=gets.split.map(&:to_i)\n\ta+=1 if l==0\n\tb+=1 if r==0\n}\nputs ([a,n-a].min + [b,n-b].min)"}, {"source_code": "n=gets.to_i\na,b=0,0\nn.times{\n\tc,d=gets.split.map(&:to_i)\n\ta +=1 if c == 1\n\tb +=1 if d == 1\n}\nputs [a,n-a].min + [b,n-b].min\n"}, {"source_code": "n=gets.to_i\na,b=0,0\nn.times{\n\tc,d=gets.split.map(&:to_i)\n\ta += c \n\tb += d\n}\nputs [a,n-a].min + [b,n-b].min\n"}, {"source_code": "state_amount = 2\ncol_amount = 2\nrow_amount = gets.strip.to_i\n\nstate_count = Array.new(col_amount) { Array.new(state_amount, 0) }\n\n1.upto(row_amount).each do |row|\n row_states = gets.strip.split(' ')\n row_states.each_with_index do |state, col|\n state_count[col][state.to_i] += 1\n end\nend\n\nmovement_count = 0\n1.upto(col_amount) do |col|\n movement_count += row_amount - state_count[col - 1].max\nend\n\nputs movement_count\n"}, {"source_code": "n = Integer(gets)\na = Array.new\nfor i in 0...n\n a[i] = Array.new\n input = gets.chomp\n nums = input.split\n for j in 0...2\n a[i][j] = Integer(nums[j])\n end\nend\n\namount_0 = 0\namount_1 = 0\nfor i in 0...n\n if a[i][0] == 0\n amount_0 += 1\n end\nend\nfor i in 0...n\n if a[i][1] == 0\n amount_1 += 1\n end\nend\nans1 = 0\nif amount_0 <= n - amount_0\n ans1 = amount_0\nelse\n ans1 = n - amount_0\nend\nans2 = 0\nif amount_1 <= n - amount_1\n ans2 = amount_1\nelse\n ans2 = n - amount_1\nend\nputs ans1 + ans2"}, {"source_code": "n=gets.to_i\na,b=0,0\nn.times{\n\tc,d=gets.split.map(&:to_i)\n\ta += c \n\tb += d\n}\nputs [a,n-a].min + [b,n-b].min\n\n"}, {"source_code": "#file_contents = File.read('test.in')\nn = gets.to_i\n\nleft_count = right_count = 0\nn.times do\n l, r = gets.split.map(&:to_i)\n left_count += l\n right_count += r\nend\nputs [left_count, n - left_count].min + [right_count, n - right_count].min"}, {"source_code": "n=gets.to_i\na,b=0,0\nn.times{\n\tc,d=gets.split.map(&:to_i)\n\ta += c \n\tb += d\n}\nputs [a,n-a].min + [b,n-b].min\n\n"}, {"source_code": "zeros = [0, 0]\nn = gets.chomp.to_i\nfor _ in 1..n\n gets.chomp.split.each_with_index { |x, i| zeros[i] += 1 if x == '0' }\nend\nputs zeros.map { |z| [z, n - z].min }.inject(:+)"}, {"source_code": "n=gets.to_i\na,b=0,0\nn.times{\n\tc,d=gets.split.map(&:to_i)\n\ta += c \n\tb += d\n}\nputs [a,n-a].min + [b,n-b].min\n\n"}, {"source_code": "n = gets.to_i\n\nl = Array.new(n)\nr = Array.new(n)\n\nn.times do |i|\n\tt = gets.split.collect{|x| x.to_i}\n\tl[i] = t[0]\n\tr[i] = t[1]\nend\n\nlr = l.inject { |s,x| s+x }\nrr = r.inject { |s,x| s+x}\n\nputs [n - lr, lr].min + [n - rr, rr].min"}, {"source_code": "n=gets.to_i\na,b=0,0\nn.times{\n\tc,d=gets.split.map(&:to_i)\n\ta += c \n\tb += d\n}\nputs [a,n-a].min + [b,n-b].min\n\n"}], "negative_code": [{"source_code": "\ufeffn = gets.chomp.to_i\nright = 0\nleft = 0\n\nn.times do \n l, r = gets.chomp.split(\" \").map{|n| n.to_i}\n left += 1 if l == 0\n right += 1 if r == 0\nend\n\nputs [left, right].max"}, {"source_code": "\nn = gets.to_i\nret = 0\nfor i in 0 .. n - 1\n line = gets\n for j in 0 .. 1\n if line.split(\" \")[j].to_i == 1\n ret += 0.5\n end\n end\nend\n\nputs ret.to_i\n"}, {"source_code": "n = Integer(gets)\na = Array.new\nfor i in 0...n\n a[i] = Array.new\n input = gets.chomp\n nums = input.split\n for j in 0...2\n a[i][j] = Integer(nums[j])\n end\nend\n\nleft1 = 0\nleft2 = 0\nfor i in 0...n\n if a[i][0] == 0\n left1 += 1\n end\nend\nfor i in 0...n\n if a[i][1] == 1\n left2 += 1\n end\nend\nleft = left1 + left2\nif left >= 2*n - left\n puts 2*n - left\nelse\n puts left\nend"}, {"source_code": "n = Integer(gets)\na = Array.new\nfor i in 0...n\n a[i] = Array.new\n input = gets.chomp\n nums = input.split\n for j in 0...2\n a[i][j] = Integer(nums[j])\n end\nend\n\nleft1 = 0\nleft2 = 0\nfor i in 0...n\n if a[i][0] == 0\n left1 += 1\n end\nend\nfor i in 0...n\n if a[i][1] == 1\n left2 += 1\n end\nend\nleft = left1 + left2\nif left1 == n - left2 && left1 == n\n puts 0\nelsif left1 == n - left2 && left1 == 0\n puts 0\nelsif\n\n if left >= 2*n - left\n puts 2*n - left\n else\n puts left\n end\nend"}, {"source_code": "#file_contents = File.read('test.in')\nnumbers = gets.scan(/\\d+/)\nnumbers.collect! &:to_i\n\nn = numbers.shift\nleft_count = right_count = 0\nnumbers.each_index {|index|\n if index.even?\n left_count += numbers[index]\n else\n right_count += numbers[index]\n end\n}\nputs [left_count, n - left_count].min + [right_count, n - right_count].min"}, {"source_code": "numbers = gets.chomp.scan(/\\d+/)\nnumbers.collect! &:to_i\n\nn = numbers.shift\nleft_count = right_count = 0\nnumbers.each_index {|index|\n if index.even?\n left_count += numbers[index]\n else\n right_count += numbers[index]\n end\n}\nputs [left_count, n - left_count].min + [right_count, n - right_count].min"}], "src_uid": "2052b0b4abdcf7d613b56842b1267f60"} {"source_code": "a,b,c=gets.split.map &:to_f;p (a**3/12+b**3/6)*Math.sqrt(2)+c**3*(5+Math.sqrt(5))/24", "positive_code": [{"source_code": "a,b,c=gets.split.map &:to_f;p (a**3/12+b**3/6)*Math.sqrt(2)+c**3*(5+Math.sqrt(5))/24"}, {"source_code": "a,b,c=gets.split.map &:to_f;p (a**3/12+b**3/6)*Math.sqrt(2)+c**3*(5+Math.sqrt(5))/24\n"}], "negative_code": [], "src_uid": "560bc97986a355d461bd462c4e1ea9db"} {"source_code": "lines = gets.chomp.to_i\r\nlines.times do\r\n input = (1..gets.chomp.to_i).to_a\r\n for i in (0..input.size-2).step 2 do\r\n aux = input[i]\r\n input[i] = input[i+1] \r\n input[i+1] = aux \r\n end\r\n if input.size % 2 == 1 and input.size > 1\r\n aux = input[-1]\r\n input[-1] = input[-2] \r\n input[-2] = aux \r\n end\r\n puts input * \" \"\r\nend\r\n", "positive_code": [{"source_code": "def main\n t = inp.to_i\n t.times do\n n = inp.to_i\n if n & 1 == 0\n 1.upto(n) do |i|\n print (i & 1 == 0)? (i - 1) : (i + 1)\n print \" \" if i != n\n end\n else\n print 1\n 2.upto(n) do |i|\n print \" \"\n print (i & 1 == 0)? (i + 1) : (i - 1)\n end\n end\n puts \"\"\n\n end\n\nend\n\n# lib\ndef inp\n gets.chomp\nend\n\ndef inarr\n gets.chomp.split\nend\n\ndef mapint(lst)\n lst.map(&:to_i)\nend\n\ndef max(a, b)\n (a > b)? a:b\nend\n\ndef min(a, b)\n (a < b)? a:b\nend\n\nmain"}], "negative_code": [{"source_code": "lines = gets.chomp.to_i\r\nlines.times do\r\n input = (1..gets.chomp.to_i).to_a\r\n for i in (0..input.size-2).step 2 do\r\n aux = input[i]\r\n input[i] = input[i+1] \r\n input[i+1] = aux \r\n end\r\n if input.size % 2 == 1 and input.size > 1\r\n aux = input[-1]\r\n input[-1] = input[-2] \r\n input[-2] = aux \r\n end\r\n puts input * \"\"\r\nend\r\n"}], "src_uid": "955bc1e2769ea407ef02506bf1e4259b"} {"source_code": "gets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n go = ->x { x -= 1; x == 0 ? 0 : x % 2 == 1 ? 1 : 2 }\r\n steps = go[n] + go[m]\r\n puts steps % 2 == 0 ? \"Tonya\" : \"Burenka\"\r\nend\r\n", "positive_code": [{"source_code": "def main\n t = inp.to_i\n t.times do\n n, m = mapint(inarr)\n if n % 2 == 0\n puts (m % 2 == 0)? \"Tonya\": \"Burenka\"\n else\n puts (m % 2 == 1)? \"Tonya\": \"Burenka\"\n end\n\n end\nend\n\n# lib\ndef inp\n gets.chomp\nend\n\ndef inarr\n gets.chomp.split\nend\n\ndef mapint(lst)\n lst.map(&:to_i)\nend\n\ndef max(a, b)\n (a > b)? a:b\nend\n\ndef min(a, b)\n (a < b)? a:b\nend\n\nmain"}], "negative_code": [], "src_uid": "13611e428c24b94023811063bbbfa077"} {"source_code": "gets.to_i.times do\n n=gets.to_i\n if n==1\n puts 3\n elsif n%2==1\n puts 1\n else\n t=n\n while t%2==0 do\n t/=2\n end\n if t==1\n puts n+1\n else\n puts n/t\n end\n end\nend", "positive_code": [{"source_code": "gets.to_i.times do\r\n x = gets.to_i\r\n start = 1 << x.to_s(2).reverse.index(\"1\")\r\n p (start..).find { |y| x & y > 0 && x ^ y > 0 }\r\nend\r\n"}], "negative_code": [], "src_uid": "288b36b64473326ea434dc74f05ae456"} {"source_code": "def solve n, xs\n xs.sort!\n ans = [1, xs[0], n+1-xs[xs.size-1]].max\n (xs.size - 1).times do |i|\n ans = [ans, (xs[i+1] - xs[i] + 2)/ 2].max\n end\n p ans\nend\n\nq = gets.to_i\nq.times do\n n, m = gets.chomp.split.map(&:to_i)\n xs = gets.chomp.split.map(&:to_i)\n solve n, xs\nend\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n beds = gets.chomp.split(' ').map{|x| x.to_i}[0]\n taplist = gets.chomp.split(' ').map{|x| x.to_i - 1}\n taplist = [-1] + taplist + [beds]\n\n longest = 0\n (0..taplist.size-2).each do |i|\n time = 0\n if i == 0 then\n time = taplist[i+1] - taplist[0]\n # puts \"time between #{taplist[0]} and #{taplist[i+1]} is #{time}\"\n elsif i == taplist.size-2 then\n time = taplist[-1] - taplist[i]\n # puts \"time between #{taplist[-1]} and #{taplist[i]} is #{time}\"\n\n else\n if (taplist[i+1] - taplist[i]) == 1\n time = 1\n else\n time = (taplist[i+1] - taplist[i])/2 + 1\n end\n # puts \"time between #{taplist[i+1]} and #{taplist[i]} is #{time}\"\n\n end\n\n longest = time if time > longest\n end\n puts longest\nend\n"}, {"source_code": "gets.to_i.times{\n\tn,k=gets.split.map &:to_i\n\ta=gets.split.map &:to_i\n\tp [a[0],n+1-a[-1],*a.each_cons(2).map{|x,y|(y-x+2)/2}].max\n}"}, {"source_code": "def solve\n n, k = gets.strip.split.map(&:to_i)\n a = gets.strip.split.map(&:to_i)\n mx = [a.first, n - a.last + 1].max\n (1...(a.size)).each do |i|\n mx = [mx, ((a[i] - a[i-1] - 1) / 2.0).ceil + 1].max\n end\n mx\nend\n\ngets.strip.to_i.times do\n puts solve\nend\n"}, {"source_code": "gets.to_i.times do\n n, m = gets.split.map(&:to_i)\n a = gets.chomp.split.map(&:to_i)\n ans = 0\n (1..n).each do |i|\n tmp = 300\n a.each do |j|\n tmp = [tmp, (i-j).abs + 1].min\n end\n ans = [ans, tmp].max\n end\n puts ans\nend\n"}, {"source_code": "inp = gets.chomp.to_i\notv = []\n\ninp.times{ |w|\ncount = 0\nmap = []\n\nrow = gets.chomp.split(\" \")\ngryadok = row[0]\n\n(0..gryadok.to_i-1).each {|w| map[w] = 0}\n\ncrans = gets.chomp.split(\" \")\n\nstartup = []\nstartdown = []\n\ncrans.size.times{|e|\nstartup[e] = crans[e].to_i-1\nstartdown[e] = crans[e].to_i-1\n}\n\n\nloop do\n\ncrans.size.times{|e|\n\nmap[startup[e]] = 1\nmap[startdown[e]] = 1\nif startup[e] > 0 \nstartup[e]-=1\nend\nif startdown[e] < (gryadok.to_i-1)\nstartdown[e]+=1\nend\n\n}\n\n#puts map.to_s\n\n\ncount+=1\nif map.index(0).nil? then otv.push(count);break; end\n\n\nend\n\n\n\n}\n\notv.size.times{|w|\nputs otv[w]\n}"}], "negative_code": [{"source_code": "t = gets.chomp.to_i\nt.times do\n beds = gets.chomp.split(' ').map{|x| x.to_i}[0]\n taplist = gets.chomp.split(' ').map{|x| x.to_i - 1}\n taplist = [-1] + taplist + [beds]\n\n longest = 0\n (0..taplist.size-2).each do |i|\n time = 0\n if i == 0 then\n time = taplist[i+1] - taplist[0] + 1\n elsif i == taplist.size-2 then\n time = taplist[-1] - taplist[i] + 1\n else\n time = (taplist[i+1] - taplist[i])/2\n end\n\n longest = time if time > longest\n end\n puts longest - 1\nend\n"}, {"source_code": "gets.to_i.times{\n\tn,k=gets.split.map &:to_i\n\ta=gets.split.map &:to_i\n\tp [n+1-a[-1],*a.each_cons(2).map{|x,y|(y-x+2)/2}].max\n}"}, {"source_code": "def solve\n n, k = gets.strip.split.map(&:to_i)\n a = gets.strip.split.map(&:to_i)\n mx = [a.first, n - a.last + 1].max\n (1...(a.size)).each do |i|\n mx = [mx, ((a[i] - a[i-1] - 1) / 2).ceil + 1].max\n end\n mx\nend\n\ngets.strip.to_i.times do\n puts solve\nend\n"}, {"source_code": "inp = gets.chomp.to_i\notv = []\n\ninp.times{ |w|\ncount = 0\n\nrow = gets.chomp.split(\" \")\ngryadok = row[0]\n\ncrans = gets.chomp.split(\" \")\ncrans.each{|w| count+=w.to_i}\n\nif (gryadok.to_i - count.to_i) < 0\n\notv.push(1)\n\nelse\n\notv.push(gryadok.to_i - count.to_i + 1)\n\nend\n\n}\n\n\notv.size.times{ |w|\nputs otv[w]\n}\n"}, {"source_code": "def solve n, xs\n xs.sort!\n ans = [1, xs[0], n+1-xs[xs.size-1]].max\n (xs.size - 1).times do |i|\n ans = [ans, (xs[i+1] - xs[i] + 1)/ 2].max\n end\n p ans\nend\n\nq = gets.to_i\nq.times do\n n, m = gets.chomp.split.map(&:to_i)\n xs = gets.chomp.split.map(&:to_i)\n solve n, xs\nend\n"}], "src_uid": "5de25068af66273c83cc7914910c4c84"} {"source_code": "DBG = true\nt = gets.to_i\nfor i in 0...t\n n = gets.to_i\n lr = []\n for j in 0...n\n ll,rr = gets.split.map{|z| z.to_i}\n lr << [ll,rr]\n end\n slr = lr.sort_by{|x| x[0]}\n rmax = slr[0][1]\n bdr = -1\n for j in 1...n\n if rmax < slr[j][0]\n bdr = rmax\n break\n end\n rmax = [rmax, slr[j][1]].max\n end\n if bdr == -1\n puts \"-1\"\n else\n for j in 0...n\n if lr[j][0] <= bdr\n print \"1 \"\n else\n print \"2 \"\n end\n end\n puts \"\"\n end\nend\n", "positive_code": [{"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nt = gets.to_i\n\nt.times do\n n = gets.to_i\n arr = []\n \n (0..n-1).each do |i|\n arr.push gets.chomp.split(\" \").map(&:to_i)+[i]\n end\n\n# p arr\n\n arr.sort_by!{|x| [x[0],x[1]]}\n\n# p arr\n\n newarr = []\n\n z = 1\n\n=begin\n done = false\n arr.each_with_index do |x,i|\n \tif i+2=arr[i+2][0]\n \t\tputs -1\n \t\tdone = true\n \t\tbreak\n \tend\n \tnewarr.push (x+[z])\n \tif i=arr[i+1][0]\n\t \tz = 3-z\n\tend\n end\n=end\n\n hasone = false\n hastwo = false\n\n maxtillnow = -1.0/0.0\n\n arr.each_with_index do |x,i|\n newarr.push (x+[z])\n if z==1\n \thasone = true\n else\n \thastwo = true\n end\n maxtillnow = x[1] if x[1]>maxtillnow\n \tif i+1=arr[i+2][0]\n \t\tputs -1\n \t\tdone = true\n \t\tbreak\n \tend\n \tnewarr.push (x+[z])\n \tz = 3-z\n end\n\n next if done\n\n newarr.sort_by{|x| x[2]}\n newarr.each do |x|\n \tprint x[3]\n \tprint \" \"\n end\n puts\nend\n"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nt = gets.to_i\n\nt.times do\n n = gets.to_i\n arr = []\n \n (0..n-1).each do |i|\n arr.push gets.chomp.split(\" \").map(&:to_i)+[i]\n end\n\n# p arr\n\n arr.sort_by!{|x| [x[0],x[1]]}\n\n# p arr\n\n newarr = []\n\n z = 1\n\n=begin\n done = false\n arr.each_with_index do |x,i|\n \tif i+2=arr[i+2][0]\n \t\tputs -1\n \t\tdone = true\n \t\tbreak\n \tend\n \tnewarr.push (x+[z])\n \tif i=arr[i+1][0]\n\t \tz = 3-z\n\tend\n end\n=end\n\n arr.each_with_index do |x,i|\n newarr.push (x+[z])\n \tif i=arr[i+1][0]\n# \t\tgood = true\n\t \tz = 3-z\n\tend\n end\n\n# next if done\n\n# p newarr\n newarr.sort_by!{|x| x[2]}\n# p newarr\n\n hasone = false\n hastwo = false\n newarr.each do |x|\n \tif x[3]==1\n \t\thasone = true\n \telse\n \t\thastwo = true\n \tend\n \tif hasone and hastwo\n \t\tbreak\n \tend\n end\n\n# p hasone\n# p hastwo\n\n if not (hasone and hastwo)\n \tputs -1\n \tnext\n end\n\n\n newarr.each do |x|\n \tprint x[3]\n \tprint \" \"\n end\n puts\nend\n"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nt = gets.to_i\n\nt.times do\n n = gets.to_i\n arr = []\n \n (0..n-1).each do |i|\n arr.push gets.chomp.split(\" \").map(&:to_i)+[i]\n end\n\n# p arr\n\n arr.sort_by!{|x| [x[0],x[1]]}\n\n# p arr\n\n newarr = []\n\n z = 1\n\n=begin\n done = false\n arr.each_with_index do |x,i|\n \tif i+2=arr[i+2][0]\n \t\tputs -1\n \t\tdone = true\n \t\tbreak\n \tend\n \tnewarr.push (x+[z])\n \tif i=arr[i+1][0]\n\t \tz = 3-z\n\tend\n end\n=end\n\n arr.each_with_index do |x,i|\n newarr.push (x+[z])\n \tif i=arr[i+1][0]\n\t \tz = 3-z\n\tend\n end\n\n# next if done\n\n# p newarr\n newarr.sort_by!{|x| x[2]}\n# p newarr\n\n hasone = false\n hastwo = false\n newarr.each do |x|\n \tif x[3]==1\n \t\thasone = true\n \telse\n \t\thastwo = true\n \tend\n \tif hasone and hastwo\n \t\tbreak\n \tend\n end\n\n# p hasone\n# p hastwo\n\n if not (hasone and hastwo)\n \tputs -1\n \tnext\n end\n\n\n newarr.each do |x|\n \tprint x[3]\n \tprint \" \"\n end\n puts\nend\n"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nt = gets.to_i\n\nt.times do\n n = gets.to_i\n arr = []\n \n (0..n-1).each do |i|\n arr.push gets.chomp.split(\" \").map(&:to_i)+[i]\n end\n\n# p arr\n\n arr.sort_by!{|x| [x[0],x[1]]}\n\n# p arr\n\n newarr = []\n\n z = 1\n done = false\n arr.each_with_index do |x,i|\n \tif i+2=arr[i+2][0]\n \t\tputs -1\n \t\tdone = true\n \t\tbreak\n \tend\n \tnewarr.push (x+[z])\n \tz = 3-z\n end\n\n next if done\n\n newarr.sort_by!{|x| x[2]}\n newarr.each do |x|\n \tprint x[3]\n \tprint \" \"\n end\n puts\nend\n"}, {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nt = gets.to_i\n\nt.times do\n n = gets.to_i\n arr = []\n \n (0..n-1).each do |i|\n arr.push gets.chomp.split(\" \").map(&:to_i)+[i]\n end\n\n arr.sort_by{|x| [x[0],x[1]]}\n\n newarr = []\n\n z = 1\n done = false\n arr.each_with_index do |x,i|\n \tif i+2arr[i+2][0]\n \t\tputs -1\n \t\tdone = true\n \t\tbreak\n \tend\n \tnewarr.push (x+[z])\n \tz = 3-z\n end\n\n next if done\n\n newarr.sort_by{|x| x[2]}\n newarr.each do |x|\n \tprint x[3]\n \tprint \" \"\n end\n puts\nend\n"}], "src_uid": "13fbcd245965ff6d1bf08915c4d2a2d3"} {"source_code": "valid_pos = [[0, 4], [4, 0], [4, 4]]\n\nn = gets.to_i\nfor k in 1..n\n kings = []\n for i in 0..7\n s = gets.chomp.split('')\n for j in 0..7\n kings << [i, j] if s[j] == 'K'\n end\n end\n puts(valid_pos.include?([(kings[1][0] - kings[0][0]).abs, (kings[1][1] - kings[0][1]).abs]) ? 'YES' : 'NO')\n gets if k < n\nend", "positive_code": [{"source_code": "t = gets.to_i\nfor i in 0...t\n\txs = []\n\tys = []\n\tfor y in 0...8\n\t\tgets.split('').each.with_index do |c, x|\n\t\t\tif c == 'K'\n\t\t\t\txs << x % 4\n\t\t\t\tys << y % 4\n\t\t\tend\n\t\tend\n\tend\n\tif xs[0] == xs[1] and ys[0] == ys[1]\n\t\tputs 'YES'\n\telse\n\t\tputs 'NO'\n\tend\n\tif i < t-1\n\t\tgets\n\tend\nend"}, {"source_code": "n=gets.to_i\nn.times do |m|\n k = []\n a = []\n 8.times do |y|\n s = gets.chomp\n a << s\n 8.times do |x|\n k << [x,y] if s[x] == 'K'\n end\n end\n gets if m < n-1\n\n f = false\n if k[0][0] % 4 == k[1][0] % 4 && k[0][1] % 4 == k[1][1] % 4\n 8.times do |y|\n 8.times do |x|\n if x % 4 == k[0][0] % 4 && y % 4 == k[0][1] % 4 || (x +2) % 4 == k[0][0] % 4 && (y+2) % 4 == k[0][1] % 4\n f||=true if a[y][x] != '#'\n end\n end\n end\n end\n\n puts (f ? 'YES' : 'NO')\n\nend\n\n"}], "negative_code": [{"source_code": "t = gets.to_i\nfor i in 0...t\n\tsum = []\n\tdiff = []\n\tfor y in 0...8\n\t\tgets.split('').each.with_index do |c, x|\n\t\t\tif c == 'K'\n\t\t\t\tsum << (x + y) % 4\n\t\t\t\tdiff << (x - y) % 4\n\t\t\tend\n\t\tend\n\tend\n\tif sum[0] == sum[1] and diff[0] == diff[1]\n\t\tputs 'YES'\n\telse\n\t\tputs 'NO'\n\tend\n\tif i < t-1\n\t\tgets\n\tend\nend"}, {"source_code": "n=gets.to_i\na=[]\nn.times do |m|\n b = []\n k = []\n a = []\n 8.times do |y|\n s = gets.chomp\n a << s\n 8.times do |x|\n if s[x] == 'K'\n k << [x,y]\n elsif s[x] == '#'\n b << [x,y]\n end\n end\n end\n gets if m < n-1\n\n f = false\n if k[0][0] % 4 == k[1][0] % 4 && k[0][1] % 4 == k[1][1] % 4 ||\n (k[0][0] + 2) % 4 == k[1][0] % 4 && (k[0][1] + 2) % 4 == k[1][1]\n 8.times do |x|\n 8.times do |y|\n if x % 4 == k[0][0] % 4 && y % 4 == k[0][1] % 4 || (x +2) % 4 == k[0][0] % 4 && (y+2) % 4 == k[0][1] % 4\n f||=true if a[y][x] != '#'\n end\n end\n end\n end\n\n puts (f ? 'YES' : 'NO')\n\nend\n\n"}, {"source_code": "n=gets.to_i\na=[]\nn.times do |m|\n b = []\n k = []\n a = []\n 8.times do |y|\n s = gets.chomp\n a << s\n 8.times do |x|\n if s[x] == 'K'\n k << [x,y]\n elsif s[x] == '#'\n b << [x,y]\n end\n end\n end\n gets if m < n-1\n\n f = false\n if k[0][0] % 4 == k[1][0] % 4 && k[0][1] % 4 == k[1][1] % 4 ||\n (k[0][0] + 2) % 4 == k[1][0] % 4 && (k[0][1] + 2) % 4 == k[1][1]\n 8.times do |y|\n 8.times do |x|\n if x % 4 == k[0][0] % 4 && y % 4 == k[0][1] % 4 || (x +2) % 4 == k[0][0] % 4 && (y+2) % 4 == k[0][1] % 4\n f||=true if a[y][x] != '#'\n end\n end\n end\n end\n\n puts (f ? 'YES' : 'NO')\n\nend\n\n"}, {"source_code": "n=gets.to_i\na=[]\nn.times do |m|\n b = []\n k = []\n a = []\n 8.times do |y|\n s = gets.chomp\n a << s\n 8.times do |x|\n if s[x] == 'K'\n k << [x,y]\n elsif s[x] == '#'\n b << [x,y]\n end\n end\n end\n gets if m < n-1\n\n f = false\n if k[0][0] % 4 == k[1][0] % 4 && k[0][1] % 4 == k[1][1] % 4 ||\n (k[0][0] + 2) % 4 == k[1][0] % 4 && (k[0][1] + 2) % 4 == k[1][1]\n 8.times do |x|\n 8.times do |y|\n if x % 4 == k[0][0] % 4 && y % 4 == k[0][1] % 4 || (x +2) % 4 == k[0][0] % 4 && (y+2) % 4 == k[0][1] % 4\n f||=true if a[x][y] != '#'\n end\n end\n end\n end\n\n puts (f ? 'YES' : 'NO')\n\nend\n\n"}, {"source_code": "valid_pos = [[2, 2], [0, 4], [4, 0], [4, 4], [5, 2], [2, 6], [6, 6]]\n\nn = gets.to_i\nfor k in 1..n\n kings = []\n for i in 0..7\n s = gets.chomp.split('')\n for j in 0..7\n kings << [i, j] if s[j] == 'K'\n end\n end\n puts(valid_pos.include?([(kings[1][0] - kings[0][0]).abs, (kings[1][1] - kings[0][1]).abs]) ? 'YES' : 'NO')\n gets if k < n\nend"}, {"source_code": "valid_pos = [[2, 2], [0, 4], [4, 0], [4, 4], [4, 2], [2, 6], [6, 6]]\n\nn = gets.to_i\nfor k in 1..n\n kings = []\n for i in 0..7\n s = gets.chomp.split('')\n for j in 0..7\n kings << [i, j] if s[j] == 'K'\n end\n end\n puts(valid_pos.include?([(kings[1][0] - kings[0][0]).abs, (kings[1][1] - kings[0][1]).abs]) ? 'YES' : 'NO')\n gets if k < n\nend"}, {"source_code": "valid_pos = [[2, 2], [0, 4], [4, 0], [4, 4]]\n\nn = gets.to_i\nfor k in 1..n\n kings = []\n for i in 0..7\n s = gets.chomp.split('')\n for j in 0..7\n kings << [i, j] if s[j] == 'K'\n end\n end\n puts(valid_pos.include?([(kings[1][0] - kings[0][0]).abs, (kings[1][1] - kings[0][1]).abs]) ? 'YES' : 'NO')\n gets if k < n\nend"}], "src_uid": "4f3bec9c36d0ac2fdb8041469133458c"} {"source_code": "if File.exists?(\"input\")\n $stdin = File.open(\"input\")\n $stdout = File.open(\"output\",\"w\")\nend\n\nnmk = gets.chomp.split(\" \").map(&:to_i)\nn = nmk[0]\nm = nmk[1]\nk = nmk[2]\n\npower = gets.chomp.split(\" \").map(&:to_i)\nschools = gets.chomp.split(\" \").map(&:to_i)\nchosen = gets.chomp.split(\" \").map(&:to_i)\n\nschoolsarr = []\nm.times {schoolsarr.push []}\n\n(0..n-1).each do |i|\n\tschoolsarr[schools[i]-1].push power[i]\nend\n\n(0..m-1).each do |i|\n\tschoolsarr[i].sort!\nend\n\nans = 0\n\n#p schoolsarr\n\nchosen.each do |z|\n\tind = z-1\n#\tp ind\n#\tp schools[ind]\n\tif (power[ind]!=schoolsarr[schools[ind]-1][-1])\n\t\tans+=1\n\tend\nend\n\nputs ans", "positive_code": [{"source_code": "a = gets.rstrip.split.map(&:to_i)\nn = a[0]\nm = a[1]\nk = a[2]\n\npowers = gets.rstrip.split.map(&:to_i)\nschools = gets.rstrip.split.map(&:to_i)\nchosen = gets.rstrip.split.map(&:to_i)\ncount = 0\nchosen.each do |chosen_one|\n\tschool = schools[chosen_one - 1]\n\tmax_power = 0\n\tschools.each_with_index do |student, i|\n\t\tnext unless student == school\n\t\tmax_power = powers[i] if max_power < powers[i]\n\tend\n\tcount += 1 if powers[chosen_one - 1] < max_power\nend\n\np count"}, {"source_code": "n, m, k = gets.strip.split(\" \").map(&:to_i)\n\npowers = gets.split(\" \").map(&:to_i)\nschools = gets.split(\" \").map(&:to_i)\nchoosens = gets.split(\" \").map(&:to_i)\n\nmade_up_cnt = 0\nchoosens.each do |student|\n schools.each_with_index do |school, index|\n if student-1 != index and schools[student-1] == school and powers[student-1] < powers[index]\n made_up_cnt += 1\n break\n end\n end\nend\n\nputs made_up_cnt\n"}], "negative_code": [{"source_code": "n, m, k = gets.strip.split(\" \").map(&:to_i)\n\npowers = gets.split(\" \").map(&:to_i)\nschools = gets.split(\" \").map(&:to_i)\nchoosens = gets.split(\" \").map(&:to_i)\n\nmade_up_cnt = 0\nchoosens.each do |student|\n schools.each_with_index do |school, index|\n if schools[student-1] == school and powers[student-1] < powers[index]\n made_up_cnt += 1\n end\n end\nend\n\nputs made_up_cnt\n"}, {"source_code": "n, m, k = gets.strip.split(\" \").map(&:to_i)\n\npowers = gets.split(\" \").map(&:to_i)\nschools = gets.split(\" \").map(&:to_i)\nchoosens = gets.split(\" \").map(&:to_i)\n\nmade_up_cnt = 0\nchoosens.each do |student|\n schools.each_with_index do |school, index|\n if student-1 != index and schools[student-1] == school and powers[student-1] < powers[index]\n made_up_cnt += 1\n end\n end\nend\n\nputs made_up_cnt\n"}], "src_uid": "e34f110440942a841624d0f42e0ddec4"} {"source_code": "#!/usr/bin/env ruby\n\nclass MeetingPlace\n attr_accessor :n, :x, :v, :zip, :result\n\n def get_data\n # fl=File.new \"test0.txt\"\n # @n,@x,@v = fl.readlines.map {|x| x.split.map(&:to_i)}\n @n, @x, @v = $stdin.readlines.map { |x| x.split.map(&:to_i) }\n @n = @n[0]\n end\n\n def output\n puts @result\n end\n\n def init\n @zip = @x.zip @v\n @x, @v = nil, nil\n @zip = @zip.sort { |a, b| a[0]<=>b[0] }\n @zipUp = @zip.each\n @zipDown = @zip.reverse_each\n @upper = @zipDown.next\n @lower =@zipUp.next\n @upperPrev = @upper\n @lowerPrev = @lower\n @direction = nil\n @result = (@upper[0] - @lower[0]).to_f / (@upper[1] + @lower[1])\n @lowerPtr = 0\n @upperPtr = @zip.length - 1\n end\n\n def getNext\n return false if @lowerPtr == @upperPtr\n if @upper[1] > @lower[1]\n @upper = @zipDown.next\n @direction = :down\n @upperPtr-=1\n else\n @lower = @zipUp.next\n @direction = :up\n @lowerPtr+=1\n end\n true\n end\n\n def get_result\n init\n while getNext\n if @direction == :down\n tmp = (@upper[0] - @lowerPrev[0]).to_f / (@upper[1] + @lowerPrev[1])\n else\n tmp = (@upperPrev[0] - @lower[0]).to_f / (@upperPrev[1] + @lower[1])\n end\n if tmp > @result\n @result = tmp\n if @upper[1] != @upperPrev[1]\n @upperPrev = @upper\n else\n @lowerPrev = @lower\n end\n end\n end\n @result = @result.round(6)\n end\nend\n\nif __FILE__ == $0\n mp = MeetingPlace.new\n mp.get_data\n mp.get_result\n mp.output\nend", "positive_code": [{"source_code": "gets\nxv = gets.split.map(&:to_f).zip(gets.split.map(&:to_f)).sort\naa, res = (bb = []), [0.0]\nbegin\n u = 2e9\n xv.each { |x, v|\n if u > v\n u = v\n bb << [x, v]\n end\n }\n break if !aa.equal?(bb)\n bb = []\n xv.reverse!\nend while true\naa.each { |x, v|\n bb.each { |y, u|\n break if y <= x\n res << (y - x) / (u + v)\n }\n}\np res.max"}, {"source_code": "def read_ints\n gets.split.map(&:to_i)\nend\n\nn = gets.to_i\na = read_ints.zip(read_ints)\n\nl = 0.0\nr = 1e9\n100.times do\n c = (l + r) / 2\n mx = a.map{|x, v| x - v * c}.max\n mi = a.map{|x, v| x + v * c}.min\n if mx > mi\n l = c\n else\n r = c\n end\nend\np (l + r) / 2\n"}], "negative_code": [{"source_code": "#!/usr/bin/env ruby\n\nclass MeetingPlace\n attr_accessor :n, :x, :v, :zip, :result\n\n def get_data\n # fl=File.new \"test0.txt\"\n # @n,@x,@v = fl.readlines.map {|x| x.split.map(&:to_i)}\n @n, @x, @v = $stdin.readlines.map { |x| x.split.map(&:to_i) }\n @n = @n[0]\n end\n\n def output\n puts @result\n end\n\n def init\n @zip = @x.zip @v\n @x, @v = nil, nil\n @zip = @zip.sort { |a, b| a[0]<=>b[0] }\n @zipUp = @zip.each\n @zipDown = @zip.reverse_each\n @upper = @zipDown.next\n @lower =@zipUp.next\n @upperPrev = @upper\n @lowerPrev = @lower\n @result = (@upper[0] - @lower[0]).to_f / (@upper[1] + @lower[1])\n end\n\n def getNext\n return false if @upper[0] == @lower[0]\n if @upper[1] > @lower[1]\n @upper = @zipDown.next\n else\n @lower = @zipUp.next\n end\n true\n end\n\n def get_result\n init\n while getNext\n tmp = (@upper[0] - @lower[0]).to_f / (@upper[1] + @lower[1])\n @result = tmp if tmp > @result\n end\n @result = @result.round(6)\n end\nend\n\nif __FILE__ == $0\n mp = MeetingPlace.new\n mp.get_data\n mp.get_result\n mp.output\nend"}, {"source_code": "n = gets.to_i\nxx = gets.split.map(&:to_i)\nv = gets.split.map(&:to_i)\na = n.times.map{|i| [xx[i], v[i]]}.sort_by{|x, y| x}\nb = a[0]\ne = a[-1]\nmiddle = 1.0 * (b[0] * e[1] + e[0] * b[1]) / (b[1] + e[1])\nmi = (middle - b[0]) / b[1]\n0.upto(n - 1) do |i|\n if a[i][0] < middle && (middle - a[i][0]) / a[i][1] > mi\n b = a[i]\n middle = 1.0 * (b[0] * e[1] + e[0] * b[1]) / (b[1] + e[1])\n mi = (middle - b[0]) / b[1]\n elsif a[i][0] > middle && (a[i][0] - middle) / a[i][1] > mi\n e = a[i]\n middle = 1.0 * (b[0] * e[1] + e[0] * b[1]) / (b[1] + e[1])\n mi = (middle - b[0]) / b[1]\n end\nend\np mi\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nv = gets.split.map(&:to_i)\naa = n.times.map{|i| [a[i], v[i]]}.sort_by{|x, y| x}\naa.shift while aa.size > 2 && aa[1][0] - aa[0][0] <= aa[0][1] - aa[1][1]\naa.pop while aa.size > 2 && aa[-1][0] - aa[-2][0] <= aa[-1][1] - aa[-2][1]\nmiddle = 1.0 * (aa[0][0] * aa[-1][1] + aa[-1][0] * aa[0][1]) / (aa[0][1] + aa[-1][1])\nputs 1.0 * (middle - aa[0][0]) / aa[0][1]\n"}], "src_uid": "f13f27a131b9315ebbb8688e2f43ddde"} {"source_code": "#!/usr/bin/env ruby\n# encoding: utf-8\nn = gets.to_i\na = gets.split.map(&:to_i)\ng = Array.new(n) { [] }\n\n(n-1).times do\n u, v = gets.split.map(&:to_i)\n u, v = u-1, v-1\n g[u] << v\n g[v] << u\nend\n\ndef GCD(a, b)\n return b == 0 ? a : GCD(b, a%b)\nend\n\ndp = Array.new(n) { Array.new(2) { [] } }\ndp[0] = [[a[0]], [0]]\npar = [-1]*n\n\nst = [0]\nuntil st.empty?\n u = st.pop\n g[u].each do |v|\n next if v == par[u]\n par[v] = u\n st.push(v)\n dp[v][0] += dp[u][0].map{|x| GCD(x,a[v])}\n dp[v][1] += dp[u][0]\n dp[v][1] += dp[u][1].map{|x| GCD(x,a[v]) }\n 2.times do |i|\n dp[v][i].uniq!\n end\n end\nend\n\nprint a[0]\nfor u in 1...n do\n print \" #{dp[u][1].max}\"\nend\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map &:to_i\ng = Array.new(n) { [] }\n\n(n-1).times do\n u, v = gets.split.map &:to_i\n u, v = u-1, v-1\n g[u] << v\n g[v] << u\nend\n\ndef GCD(a, b)\n return (b == 0) ? a : GCD(b, a%b)\nend\n\ndp = Array.new(n) { Array.new(2) { [] } }\ndp[0] = [[a[0]], [0]]\npar = [-1]*n\n\nq = [0]\nuntil q.empty?\n u = q.shift\n g[u].each do |v|\n next if v == par[u]\n par[v] = u\n q.unshift(v)\n dp[u][0].each do |x|\n dp[v][0] << GCD(x, a[v]);\n dp[v][1] << x\n end\n dp[u][1].each do |x|\n dp[v][1] << GCD(x, a[v])\n end\n for i in 0..1 do\n dp[v][i].uniq!\n end\n end\nend\n\nprint a[0]\nfor u in 1...n do\n print \" #{dp[u][1].max}\"\nend\n"}], "negative_code": [], "src_uid": "3d347323920a00f8f4df19e549ab6804"} {"source_code": "n, r, avg = gets.split.map(&:to_i)\ntotal = avg * n\n\narr = []\nn.times do\n ai, bi = gets.split.map(&:to_i)\n total -= ai\n arr << [bi, ai]\nend\n\nres = 0\nif total > 0\n arr = arr.sort\n arr.each do |item|\n tmp = [total, r - item[1]].min\n res += tmp * item[0]\n total -= tmp\n end\nend\n\nputs res", "positive_code": [{"source_code": "n, r, avg = gets.split.map(&:to_i)\ntotal = avg * n\n\narr = []\nn.times do\n ai, bi = gets.split.map(&:to_i)\n total -= ai\n if r > ai\n arr << [bi, r - ai]\n end\nend\n\nres = 0\nif total > 0\n arr = arr.sort\n arr.each do |item|\n tmp = [total, item[1]].min\n res += tmp * item[0]\n total -= tmp\n end\nend\n\nputs res"}, {"source_code": "n, r, avg = gets.split.collect {|x| x.to_i}\ntotal = avg * n\n\narr = []\nn.times do\n ai, bi = gets.split.collect {|x| x.to_i}\n total -= ai\n arr.push [bi, ai]\nend\n\nres = 0\nif total > 0\n arr = arr.sort\n arr.each do |item|\n tmp = [total, r - item[1]].min\n res += tmp * item[0]\n total -= tmp\n end\nend\n\nputs res"}, {"source_code": "n, r, avg = gets.split(\" \").collect {|x| x.to_i}\ntotal = avg * n\n\narr = []\nn.times do\n ai, bi = gets.split(\" \").collect {|x| x.to_i}\n total -= ai\n arr.push [bi, ai]\nend\n\nres = 0\nif total > 0\n arr = arr.sort\n arr.each do |item|\n tmp = [total, r - item[1]].min\n res += tmp * item[0]\n total -= tmp\n end\nend\n\nputs res"}, {"source_code": "n, r, avg = gets.split.map(&:to_i)\ntotal = avg * n\n\narr = []\nn.times do\n ai, bi = gets.split.map(&:to_i)\n total -= ai\n arr.push [bi, ai]\nend\n\nres = 0\nif total > 0\n arr = arr.sort\n arr.each do |item|\n tmp = [total, r - item[1]].min\n res += tmp * item[0]\n total -= tmp\n end\nend\n\nputs res"}, {"source_code": "n, r, avg = gets.split(' ').map(&:to_i)\ntotal = avg * n\n\narr = []\nn.times do\n ai, bi = gets.split(' ').map(&:to_i)\n total -= ai\n arr.push [bi, ai]\nend\n\nres = 0\nif total > 0\n arr = arr.sort\n arr.each do |item|\n tmp = [total, r - item[1]].min\n res += tmp * item[0]\n total -= tmp\n end\nend\n\nputs res"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\nn, r, avg = gets.chomp.split.map(&:to_i)\nreq = n * avg\n\ns = []\nn.times do\n tmp = gets.split.map(&:to_i)\n req -= tmp[0]\n unless r <= tmp[0]\n tmp[0] = r - tmp[0]\n s << tmp\n end\nend\n\nif req <= 0\n puts 0\n exit 0\nend\n\ns.sort_by! { |a| a[1] }\n\ni = 0\nessays = 0\nwhile 0 < req and i < n\n a = s[i][0]\n essay = s[i][1]\n if req <= a\n essays += req * essay\n break\n end\n essays += a * essay\n i += 1\n req -= a\nend\n\nputs essays\n"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\nn, r, avg = gets.chomp.split.map(&:to_i)\nreq = n * avg\n\ns = []\nn.times do\n tmp = gets.split.map(&:to_i)\n req -= tmp[0]\n unless r <= tmp[0]\n #tmp[0] = r - tmp[0]\n s << tmp\n end\nend\n\nif req <= 0\n puts 0\n exit 0\nend\n\ns.sort_by! { |a| a[1] }\n\ni = 0\nessays = 0\nwhile 0 < req and i < n\n grade = s[i][0]\n essay = s[i][1]\n a = (r - grade)\n if req <= a\n essays += req * essay\n break\n end\n essays += a * essay\n i += 1\n req -= a\nend\n\nputs essays\n"}, {"source_code": "class Point\n def initialize(a,b)\n @a = a\n @b = b\n end\n def a\n @a\n end\n def b\n @b\n end\nend\n\np= Array.new\nn , r , avg = gets.split.map(&:to_i)\nsum, ans, i= 0, 0, 0\nn.times do\n x, y= gets.split.map(&:to_i)\n p<=avg*n\n sum += r-p[i].a\n ans += (r-p[i].a)*p[i].b\n i += 1\n end\n r=ans-(sum-avg*n)*p[i-1].b\n puts r>0?r:0\n"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\n\nn, r, avg = read_ints\navg *= n\na = []\ncur_avg = 0\nn.times do\n a << read_ints\n cur_avg += a[-1][0]\nend\nans = 0\na.sort_by!{|x| x[1]} \na.each do |x|\n break if cur_avg >= avg\n mn =[r - x[0], avg - cur_avg].min\n ans += mn * x[1]\n cur_avg += mn\nend\nputs ans\n"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\n\nn, r, avg = read_ints\navg *= n\na = []\ncur_avg = 0\nn.times do\n a << read_ints\n cur_avg += a[-1][0]\nend\nif cur_avg >= avg\n puts 0\n exit 0\nend\nans = 0\na.sort_by!{|x| x[1]}\na.each do |x|\n if r - x[0] >= avg - cur_avg\n ans += x[1] * (avg - cur_avg)\n break\n end\n ans += (r - x[0]) * x[1]\n cur_avg += (r - x[0])\nend\n\nputs ans\n"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\n\nn, r, avg = read_ints\navg *= n\na = []\ncur_avg = 0\nn.times do\n a << read_ints\n cur_avg += a[-1][0]\nend\nif cur_avg >= avg\n puts 0\n exit 0\nend\nans = 0\na.sort_by{|x| x[1]}.each do |x|\n if r - x[0] >= avg - cur_avg\n ans += x[1] * (avg - cur_avg)\n break\n end\n ans += (r - x[0]) * x[1]\n cur_avg += (r - x[0])\nend\n\nputs ans\n"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\n\nn, r, avg = read_ints\navg *= n\na = []\ncur_avg = 0\nn.times do\n a << read_ints\n cur_avg += a[-1][0]\nend\nans = 0\na.sort_by!{|x| x[1]}\na.each do |x|\n break if cur_avg >= avg\n mn =[r - x[0], avg - cur_avg].min\n ans += mn * x[1]\n cur_avg += mn\nend\nputs ans\n"}, {"source_code": "#$stdin = File.open(\"input.txt\")\n\nn, r, avg = gets.split.map &:to_i\nexams = gets(nil).split(\"\\n\").map { |line| line.split.map &:to_i }\n\nneed = avg * n\nhave = exams.transpose.first.inject(:+)\n\nexams.sort! { |a, b| a.last <=> b.last }\n\nessays = 0\nwhile have < need\n\ta, b = exams.first\n\t\n\tup = [need - have, r - a].min\n\t\n\thave += up\n\tessays += up * b\n\t\n\texams.shift\nend\n\nputs essays"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\nn, r, avg = read_ints\na = []\ni = 0\ncurSum = 0\nn.times do\n a << read_ints\n a[i].reverse!\n curSum+= a[i][1]\n i+=1\nend\na.sort!\navgSum = avg*n\nresEssays = 0\ni=0\nwhile(curSum=s\n k+=pb[i].b*s\n break\n else\n s-=pb[i].a\n k+=pb[i].b*pb[i].a\n end\nend\n\nputs k"}, {"source_code": "class Stu\n attr_accessor:a,:b\nend\n\npa=Array.new\npb=Array.new\n\nstr=gets.to_s\npa=str.split\nn=pa[0].to_i\nr=pa[1].to_i\navg=pa[2].to_i\ns=n*avg\n\nfor i in 0..n-1\n str=gets.to_s\n pa=str.split\n pb[i]=Stu.new\n s-=pa[0].to_i\n pb[i].a=r-pa[0].to_i\n pb[i].b=pa[1].to_i\nend\n\nif s<0\n s=0\nend\n\npb.sort! {|x,y| x.b<=>y.b }\n#p pb\n\nk=0\nfor i in 0..n-1\n if pb[i].a>=s\n k+=pb[i].b*s\n break\n else\n s-=pb[i].a\n k+=pb[i].b*pb[i].a\n end\nend\n\nputs k"}], "negative_code": [{"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\nn, r, avg = gets.chomp.split.map(&:to_i)\nreq = n * avg\n\ns = []\nn.times do\n tmp = gets.split.map(&:to_i)\n req -= tmp[0]\n unless r <= tmp[0]\n tmp[0] = r - tmp[0]\n s << tmp\n end\nend\n\ns.sort_by! { |a| a[1] }\n\nessays = 0\ns.each do |a|\n is_break = false\n a[0].times do |i|\n req -= 1\n essays += a[1]\n is_break = true and break if req <= 0\n end\n break if is_break\nend\n\nputs essays\n"}, {"source_code": "#! /usr/bin/env ruby\n# coding: utf-8\n\nn, r, avg = gets.chomp.split.map(&:to_i)\nreq = n * avg\n\ns = []\nn.times do\n tmp = gets.split.map(&:to_i)\n req -= tmp[0]\n unless r <= tmp[0]\n tmp[0] = r - tmp[0]\n s << tmp\n end\nend\n\nif req <= 0\n puts 0\n exit 0\nend\n\ns.sort_by! { |a| a[1] }\n\nessays = 0\ns.each do |a|\n if 0 <= req - a[0]\n req -= a[0]\n essays += a[0] * a[1]\n break if req <= 0\n next\n end\n req -= 1\n essays += a[1]\n break if req <= 0\nend\n\nputs essays\n"}, {"source_code": "def read_ints; STDIN.gets.split.map(&:to_i); end\n\nn, r, avg = read_ints\navg *= n\na = []\ncur_avg = 0\nn.times do\n a << read_ints\n cur_avg += a[-1][0]\nend\nif cur_avg > avg\n puts 0\n exit 0\nend\nans = 0\na.each do |x|\n if r - x[0] >= avg - cur_avg\n ans += x[1] * (avg - cur_avg)\n break\n end\n ans += (r - x[0]) * x[1]\n cur_avg += (r - x[0])\nend\n\nputs ans\n"}, {"source_code": "n, r, avg = gets.split.map &:to_i\nexams = gets(nil).split(\"\\n\").map { |line| line.split.map &:to_i }\n\nneed = avg * n\nhave = exams.transpose.first.inject(:+)\n\nexams.sort! { |a, b| a.last <=> b.last }\n\nessays = 0\nwhile have < need\n a, b = exams.first\n \n up = [need - have, r - a].min\n \n have += up\n essays += up * b\n \n exams.unshift\nend\n\nputs essays"}], "src_uid": "55270ee4e6aae7fc0c9bb070fcbf5560"} {"source_code": "#!/usr/bin/env ruby\nphone_length, block_length = gets.split(' ').map(&:to_i)\n\na = gets.split(' ').map(&:to_i)\nb = gets.split(' ').map(&:to_i)\n\npossibilities_in_each_block = a.zip(b).map do |a_i, b_i|\n vsego_kratnix = (10**(block_length) - 1).div(a_i)\n\n #require 'byebug'\n #debugger\n kratnix_i_startujut_s_b_itogo = ((b_i+1)*(10**(block_length-1)) - 1).div(a_i) - (b_i*(10**(block_length-1)) - 1).div(a_i)\n\n nulevoi_element = 1\n\n nulevoi_element + vsego_kratnix - kratnix_i_startujut_s_b_itogo\nend\n\nbig_modulo = 10**9 + 7\n\ndef fast_product_stupid(int_arr_product, big_modulo)\n total = 1\n int_arr_product.each do |num|\n total = (num*total).modulo(big_modulo)\n end\n total\nend\n\nputs fast_product_stupid(possibilities_in_each_block, big_modulo)\n", "positive_code": [{"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn, k = gets.chomp.split.map(&:to_i)\na = gets.chomp.split\nb = gets.chomp.split\n\nx = 10 ** k\nxx = 10 ** k.pred\nmd = (10 ** 9) + 7\n\nf = \"%0\" + k.to_s + \"d\"\nans = 1\n\na.size.times do |i|\n c = 0\n v = 0\n ai = a[i].to_i\n bi = b[i].to_i\n if a[i].size == k\n while v < x\n if (f % [v])[0] != b[i]\n c += 1\n end\n v += ai\n end\n else\n c = x.pred.div(ai).succ\n if bi == 0\n c -= xx.pred.div(ai).succ\n else\n c -= bi.succ.*(xx).pred.div(ai).succ - bi.*(xx).pred.div(ai).succ\n end\n end\n ans *= c\n ans %= md\nend\n\nputs ans.%(md)"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nas = gets.chomp.split.map(&:to_i)\nbs = gets.chomp.split.map(&:to_i)\nmod = (1E9 + 7).to_i\n\nans = 1\nfor i in 0...(n / k)\n ans = ans * ((10**k - 1) / as[i] + 1 - (bs[i] * 10**(k - 1) + 10**(k - 1) - 1) / as[i] + (bs[i] * 10**(k - 1) - 1) / as[i]) % mod\nend\n\nputs ans\n"}, {"source_code": "#!/usr/bin/ruby\n\nn, k = gets.strip().split(\" \")\nn = n.to_i\nk = k.to_i\na = gets.strip().split(\" \")\na = a.map(&:to_i)\nb = gets.strip().split(\" \")\nb = b.map(&:to_i)\nm = n / k;\nans = 1;\nfor i in 0..m - 1\n if b[i] == 0 \n tmp = 10 ** (k - 1)\n mul = (tmp * 10 - 1) / a[i] - tmp / a[i] + 1\n if tmp % a[i] > 0\n mul -= 1\n end\n else\n tmp = 10 ** (k - 1) \n mul = (tmp * 10 - 1) / a[i] - tmp * (b[i] + 1) / a[i] + 1 + (tmp * b[i] - 1) / a[i] + 1\n if tmp * (b[i] + 1) % a[i] > 0\n mul -= 1\n end\n end\n ans = ans * mul\n ans %= 10 ** 9 + 7\nend\nprint ans, \"\\n\"\n"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\n\nblock = n / k\n\n\na = gets.chomp.split.map(&:to_i)\nb = gets.chomp.split.map(&:to_i)\n\nanswer = 1\n\nfor i in 0..(block - 1)\n ans = (10**k - 1) / a[i] + 1\n\n degree = 10**(k - 1)\n ans -= ((b[i] + 1) * degree - 1) / a[i]\n ans += (b[i] * degree - 1) / a[i]\n\n answer *= ans\n answer %= 1000000007\nend\n\nputs answer"}], "negative_code": [{"source_code": "n, k = gets.chomp.split.map(&:to_i)\n\nblock = n / k\n\na = gets.chomp.split.map(&:to_i)\nb = gets.chomp.split.map(&:to_i)\n\nanswer = 1\n\nfor i in 0..(block - 1)\n degree = 10**(k - 1)\n\n ans = (10**k - 1) / a[i] + 1\n\n ans -= ((b[i] + 1) * degree - 1) / a[i]\n ans += (b[i] * degree - 1) / a[i]\n\n answer *= ans\nend\n\nputs answer\n\n"}, {"source_code": "#! ruby\n# Try Codeforces\n# author: Leonardone @ NEETSDKASU\n\nn, k = gets.chomp.split.map(&:to_i)\na = gets.chomp.split\nb = gets.chomp.split\n\nx = 10 ** k\nxx = 10 ** k.pred\n\nf = \"%0\" + k.to_s + \"d\"\nans = 1\n\nn.div(k).times do |i|\n c = 0\n v = 0\n ai = a[i].to_i\n bi = b[i].to_i\n if a[i].size == k\n while v < x\n if (f % v)[0] != b[i]\n c += 1\n end\n v += ai\n end\n else\n c = x.pred.div(ai).succ\n if bi == 0\n c -= xx.pred.div(ai).succ\n else\n c -= bi.*(xx).div(ai).succ - bi.pred.*(xx).div(ai).succ\n end\n end\n ans *= c\nend\n\nputs ans.%((10 ** 9) + 7)"}, {"source_code": "#!/usr/bin/env ruby\nphone_length, block_length = gets.split(' ').map(&:to_i)\n\na = gets.split(' ').map(&:to_i)\nb = gets.split(' ')\n\npossibilities_in_each_block = a.zip(b).map do |a_i, b_i|\n valid_parts_in_block = ('9'*block_length).to_i.div(a_i)\n next 1 if valid_parts_in_block == 0\n\n valid_parts_in_block.downto(1).take_while do |kratnoe|\n num = (kratnoe*a_i).to_s\n\n longest_kratnoe = num.length == block_length\n if (longest_kratnoe && num[0] == b_i)\n valid_parts_in_block -= 1\n end\n\n longest_kratnoe\n end\n\n next valid_parts_in_block+1 # zero\nend\n\nbig_modulo = 10**9 + 7\n\ndef fast_product_stupid(int_arr_product, big_modulo)\n total = 1\n int_arr_product.each do |num|\n total = (num*total).modulo(big_modulo)\n end\n total\nend\n\nputs fast_product_stupid(possibilities_in_each_block, big_modulo)\n"}, {"source_code": "n, k = gets.chomp.split.map(&:to_i)\nas = gets.chomp.split.map(&:to_i)\nbs = gets.chomp.split.map(&:to_i)\nmod = (1E9 + 7).to_i\nans = 1\nfor i in 0...(n / k)\n ans = ans * (99 / as[i] - ((bs[i] * 10 + 9) / as[i]) + (bs[i] * 10 - 1) / as[i] + 1) % mod\nend\n\nputs ans\n"}, {"source_code": "#!/usr/bin/ruby\n\nn, k = gets.strip().split(\" \")\nn = n.to_i\nk = k.to_i\na = gets.strip().split(\" \")\na = a.map(&:to_i)\nb = gets.strip().split(\" \")\nb = b.map(&:to_i)\nm = n / k;\nans = 1;\nfor i in 0..m - 1\n if b[i] == 0 \n tmp = 10 ** (k - 1)\n mul = (tmp * 10 - 1) / a[i] - tmp / a[i] + 1\n if tmp % a[i] > 0\n mul -= 1\n end\n else\n tmp = 10 ** (k - 1) \n mul = (tmp * 10 - 1) / a[i] - tmp * (b[i] + 1) / a[i] + 1 + (tmp * b[i] - 1) / a[i] + 1\n if tmp * (b[i] + 1) % a[i] \n mul -= 1\n end\n end\n ans = ans * mul\n ans %= 10 ** 9 + 7\nend\nprint ans, \"\\n\"\n"}], "src_uid": "dcb483886c81d2cc0ded065aa1e74091"} {"source_code": "gets.to_i.times do\n a,v,l,r = gets.split.map(&:to_i)\n puts a/v-r/v+(l-1)/v\nend", "positive_code": [{"source_code": "gets.to_i.times do\n\tn, v, l, r = gets.split.map(&:to_i)\n\tputs n / v - (r / v - l.pred / v)\nend\n"}, {"source_code": "\ndef go\n l, v, s, e = read_ints\n\n count = 0\n # interval before train\n from = v\n to = s - 1\n count += ((to-from)/v) + 1 if from <= to\n\n # interval after train\n from = e + 1\n to = (l.to_f / v).floor * v\n count += ((to-from)/v) + 1 if from <= to\n\n puts count\nend\n\ndef solution\n n = read_int\n n.times do\n go\n end\nend\n\ndef read_int\n gets.to_i\nend\n\ndef read_ints\n gets.split.map(&:to_i)\nend\n\ndef read_string\n gets.chomp\nend\n\nsolution unless ENV['TEST__MODE']\n\n"}, {"source_code": "def solve\n t = gets.strip.to_i\n t.times do\n d, v, l, r = gets.strip.split.map(&:to_i)\n puts (d / v) - ( (r / v) - (l / v) + (l % v == 0 ? 1 : 0))\n end\nend\n\nsolve"}, {"source_code": "gets.to_i.times do\n a,v,l,r = gets.split.map(&:to_i)\n puts a/v-r/v+(l-1)/v\nend\n"}, {"source_code": "# https://codeforces.com/problemset/problem/1066/A\ndef solution(d, v, l, r)\n return (d / v) - (r / v) + ((l - 1) / v)\nend\n\nn = gets.chomp.to_i\nn.times do\n d, v, l, r = gets.chomp.split(\" \").map(&:to_i)\n puts solution(d, v, l, r)\nend\n"}, {"source_code": "def lights(len, v)\n\t(len + v)/v - 1\nend\nn = gets.chomp\nn.to_i.times do |i| \n\tline = gets.chomp\n\tlen, v, l, r = line.split.map(&:to_i)\n\tres = lights(len, v)\n\t#puts res\n\tres = res - ( lights(r,v) - lights(l - 1,v) )\n\tputs res\nend\n"}, {"source_code": "n = gets.strip.to_i\n\nout = []\nn.times do\n arr = gets.strip.split(' ').map(&:to_i)\n start = arr[2] - 1\n\n start2 = arr[3] + 1\n end2 = arr[0]\n\n final = (start / arr[1]).floor + (end2 / arr[1]).floor - (start2 / arr[1]).floor\n if (start2 % arr[1] == 0 && end2 % arr[1] == 0)\n final += 1\n elsif (start2 % arr[1] == 0 && end2 % arr[1] != 0)\n final += 1\n end\n out << final\nend\n\nout.each do |o|\n puts o\nend\n"}], "negative_code": [{"source_code": "n = gets.strip.to_i\n\nout = []\nn.times do\n arr = gets.strip.split(' ').map(&:to_i)\n start = arr[2] - 1\n\n start2 = arr[3] + 1\n end2 = arr[0]\n\n final = (start / arr[1]).floor + (end2 / arr[1]).floor - (start2 / arr[1]).floor\n if (start2 % arr[1] == 0 && end2 % arr[1] == 0)\n final += 1\n end\n out << final\nend\n\nout.each do |o|\n puts o\nend\n"}, {"source_code": "n = gets.strip.to_i\n\nout = []\nn.times do\n arr = gets.strip.split(' ').map(&:to_i)\n start = arr[2] - 1\n\n start2 = arr[3] + 1\n end2 = arr[0]\n\n final = (start / arr[1]).floor + (end2 / arr[1]).floor - (start2 / arr[1]).floor\n if (start2 % arr[1] == 0 || end2 % arr[1] == 0)\n final += 1\n end\n out << final\nend\n\nout.each do |o|\n puts o\nend\n"}], "src_uid": "5194846a503c2087fcd299eaf3c20b2b"} {"source_code": "Pointer = Struct.new(:value)\r\n\r\ngets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n ass = n.times.map { gets.split.map(&:to_i) }\r\n go = ->(i, j, di, dj, map) {\r\n pointer = Pointer.new(0)\r\n while i < n && j < m && i >= 0 && j >= 0\r\n map[[i, j]] = pointer\r\n pointer.value += ass[i][j]\r\n i += di\r\n j += dj\r\n end\r\n }\r\n ltr, rtl = {}, {}\r\n 0.upto(n - 1) { |i| go[i, 0, 1, 1, ltr] }\r\n 0.upto(m - 1) { |j| go[0, j, 1, 1, ltr] }\r\n 0.upto(n - 1) { |i| go[i, m - 1, 1, -1, rtl] }\r\n 0.upto(m - 1) { |j| go[0, j, 1, -1, rtl] }\r\n answer = 0.upto(n - 1).map do |i|\r\n 0.upto(m - 1).map do |j|\r\n ltr[[i, j]].value + rtl[[i, j]].value - ass[i][j]\r\n end.max\r\n end.max\r\n p answer\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, m = gets.split.map(&:to_i)\r\n ass = n.times.map { gets.split.map(&:to_i) }\r\n answer = 0.upto(n - 1).map do |i|\r\n 0.upto(m - 1).map do |j|\r\n sum = ass[i][j]\r\n [[-1, -1], [-1, 1], [1, -1], [1, 1]].map do |di, dj|\r\n ii, jj = i + di, j + dj\r\n while ii >= 0 && ii <= n - 1 && jj >= 0 && jj <= m - 1\r\n sum += ass[ii][jj]\r\n ii += di\r\n jj += dj\r\n end\r\n end\r\n sum\r\n end.max\r\n end.max\r\n p answer\r\nend\r\n"}, {"source_code": "gets.to_i.times do\n n, m = gets.split.map(&:to_i)\n diag = {}\n rdiag = {}\n\n as = Array.new(n) { gets.split.map(&:to_i) }\n\n n.times { |i|\n m.times { |j|\n di = j - i\n diag[di] ||= 0\n diag[di] += as[i][j]\n\n rdi = m - 1 - j - i\n rdiag[rdi] ||= 0\n rdiag[rdi] += as[i][j]\n }\n }\n\n ans = nil\n n.times { |i|\n m.times { |j|\n cur = diag[j - i] + rdiag[m - 1 - j - i] - as[i][j]\n ans = cur if !ans || cur > ans\n }\n }\n\n p ans\nend\n"}, {"source_code": "def solve\n h, w = gli\n b = []\n h.times { b << gli }\n ans = 0\n (0...h).each do |i|\n (0...w).each do |j|\n tmp = b[i][j]\n (1..i).each do |q|\n break if i - q < 0 || j - q < 0\n\n tmp += b[i - q][j - q]\n end\n (1..i).each do |q|\n break if i - q < 0 || j + q >= w\n\n tmp += b[i - q][j + q]\n end\n (i + 1...h).each do |q|\n break if j - (q - i) < 0\n\n tmp += b[q][j - (q - i)]\n end\n (i + 1...h).each do |q|\n break if j + (q - i) >= w\n\n tmp += b[q][j + (q - i)]\n end\n\n ans = [ans, tmp].max\n end\n end\n puts ans\nend\n\nMOD = 10**9 + 7\ndef gs = gets.chomp\ndef gi = gets.to_i\ndef gli = gets.split.map(&:to_i)\ndef cyesno(x) = x ? :Yes : :No\ndef uyesno(x) = x ? :YES : :NO\n\ngets.to_i.times { solve }\n"}, {"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n n, m = ints\r\n a = rep(n) { ints }\r\n sum_x = Hash.new(0)\r\n sum_y = Hash.new(0)\r\n n.times do |i|\r\n m.times do |j|\r\n sum_x[i + j] += a[i][j]\r\n sum_y[i - j] += a[i][j]\r\n end\r\n end\r\n ans = 0\r\n n.times do |i|\r\n m.times do |j|\r\n ans = [ans, sum_x[i + j] + sum_y[i - j] - a[i][j]].max\r\n end\r\n end\r\n puts ans\r\n end\r\n}\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\n$yesno = %w(No Yes)\r\nYesNo = %w(No Yes)\r\nYESNO = %w(NO YES)\r\nINF = 10**18\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t] end\r\ndef YesNo t; puts YesNo[t] end\r\ndef YESNO t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]"}], "negative_code": [], "src_uid": "1b0c53ec666cdfea31a74f73d6ff70f2"} {"source_code": "n=gets.to_i\n\nans=[]\nn.times{|i|\n\tans<0 then\nputs ans.select{|e| e>0}*\" \"\nend\n\n", "positive_code": [{"source_code": "n = gets.to_i\ncars = 1.upto(n).select do |_|\n collisions = gets.split(' ').map(&:to_i)\n !collisions.include?(1) && !collisions.include?(3)\nend\n\nputs cars.length\nputs cars.join(' ')\n"}, {"source_code": "n = gets.to_i\nans = Array.new\nn.times do |i|\n tmp = gets.split\n ans.push(i+1) if not tmp.include?(\"1\") and not tmp.include?(\"3\")\nend\nputs ans.size\nputs ans.join(\" \") unless ans.empty?\n"}, {"source_code": "n = gets.chomp.to_i\nans = [*1..n]\nar = Array.new(n) { Array.new(n) }\nfor i in 0...n\n ar[i] = gets.split(\" \").map{|i| i.to_i}\nend\nfor i in 0...n\n\tfor j in 0...n\n\t\tif ar[i][j] == 3\n\t\t\tans.delete(i + 1)\n\t\t\tans.delete(j + 1)\n\t\telsif ar[i][j] == 1\n\t\t\tans.delete(i + 1)\n\t\telsif ar[i][j] == 2\n\t\t\tans.delete(j + 1)\n\t\tend\n\tend\nend\nputs ans.size\nputs ans.join(\" \")\n\n"}, {"source_code": "n, c, s = Integer(gets), 0, \"\"\n\n(1..n).each do |i|\n\tx = gets.split(\" \")\n\tunless x.include? \"1\" or x.include? \"3\"\n\t\tc += 1\n\t\ts += \"#{i} \"\n\tend\nend\n\nputs c\nif c > 0\n\tputs s\nend\n"}, {"source_code": "n = gets.to_i\nans = []\n(1..n).each do |i|\n row = gets.split.map &:to_i\n ans.push i if not row.include? 1 and not row.include? 3\nend\nputs ans.size\nans.each do |a|\n print a.to_s + ' '\nend\nputs"}, {"source_code": "# http://codeforces.com/contest/545/problem/A\nn = gets.chomp.to_i\nmatrix = [].tap do |arr|\n n.times { arr << gets.chomp.split.map(&:to_i) }\nend\n\ngood_cars = []\nmatrix.transpose.each.with_index do |row, idx|\n good_cars << idx + 1 unless (row.include?(2) || row.include?(3))\nend\n\nputs good_cars.length\nputs good_cars.join(\" \") unless good_cars.empty?\n"}, {"source_code": "arr = []\ngets.to_i.times do\n arr << gets.split.map { |x| x.to_i }.to_a\nend\nindices = []\ncount = 0\narr.each do |i|\n if !i.include?(1) && !i.include?(3)\n count += 1\n indices << arr.index(i) + 1\n end\nend\nputs count\nindices.each { |x| print x, \" \" }\n"}, {"source_code": "#!/usr/bin/env ruby\n# -*- coding: utf-8 -*-\n\n# a.rb\n\ndef main()\n n = gets.to_i\n r = []\n n.times do |i|\n a = gets.chomp.split(\" \").map{|s| next s.to_i }\n r << (i + 1) if !(a.index(1) || a.index(3))\n end\n puts r.size\n puts r * \" \" if r.size > 0\nend\n\nif __FILE__ == $0 then\n main()\nend\n"}, {"source_code": "n = gets.to_i\ngoodCars = []\namountOfGoodCar = 0\nn.times do |i|\n crashes = gets.split(' ')\n .map{|x| x.to_i}\n .select{|x| x > 0 && x % 2 == 1}\n next if crashes.size > 0\n amountOfGoodCar += 1\n goodCars << i + 1\nend\n\nputs amountOfGoodCar\ngoodCars.each {|car| print \"#{car} \"}"}], "negative_code": [], "src_uid": "3fc0ac711b113fa98f41740536dad44f"} {"source_code": "ab = gets.split(' ')\ninitial1 = ab[0]\ninitial2 = ab[1]\nn = gets.to_i()\nputs \"#{initial1} #{initial2}\"\nfor i in 1..n do\n ab = gets.split(' ')\n if initial1 == ab[0]\n initial1 = ab[1]\n else\n initial2 = ab[1]\n end\n puts \"#{initial1} #{initial2}\"\nend\n\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\na,b=gets.split\nputs [a,b]*' '\ngets\n$<.each{|e|\n\tx,y=e.split\n\tif a==x\n\t\ta=y\n\telsif b==x\n\t\tb=y\n\tend\n\tputs [a,b]*' '\n}"}, {"source_code": "#\u5728ruby\u91cc\u6211\u90fd\u4e0d\u9700\u8981\u5173\u5fc3\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u4e86\uff01\nname=gets.chomp.split(\" \")\na=name[0]\nb=name[1]\nn=gets.chomp.to_i\nputs \"#{a} #{b}\"\nn.times do\n name=gets.chomp.split(\" \")\n x=name[0]\n y=name[1]\n if x==a\n puts \"#{b} #{y}\"\n a=y\n else\n puts \"#{a} #{y}\"\n b=y\n end\nend\n"}, {"source_code": "a = gets.split\nputs a * ' '\ngets.to_i.times{\n\tx, y = gets.split\n\ta[a.index(x)] = y\n\tputs a * ' '\n}"}, {"source_code": "p = gets.split\nn = gets.to_i\nans = [p]\nn.times do\n a, b = gets.split\n p = p - [a] + [b]\n ans << p\nend\nputs ans.map{|x| x.join(' ')}\n"}, {"source_code": "x = gets.split\nn = gets.to_i\nans = [[*x]]\nn.times do\n a1, a2 = gets.split\n if x.delete(a1)\n x.push(a2)\n elsif x.delete(a2)\n x.push(a1)\n end\n ans << x.flatten\nend\nputs ans.map{|x| x.join(' ')}\n\n"}, {"source_code": "l = gets.split\nputs l * ' '\ngets.to_i.times {\n a, b = gets.split\n l[(l[0] == a) ? 0 : 1] = b\n puts l * ' '\n}"}, {"source_code": "a, b = gets.split\nprint(a, ' ', b)\ngets.to_i.times do\n c, d = gets.split\n if a == c\n a = d\n else\n b = d\n end\n print(\"\\n\", a, ' ', b)\nend"}], "negative_code": [{"source_code": "#!/usr/bin/ruby\na,b=gets.split\ngets\n$<.each{|e|\n\tx,y=e.split\n\tif a==x\n\t\ta=y\n\telsif b==x\n\t\tb=y\n\tend\n}\nputs [a,b]*' '"}], "src_uid": "3c06e3cb2d8468e738b736a9bf88b4ca"} {"source_code": "N,X,Y = gets.split.map &:to_i\nA = gets.split.map &:to_i\nif X > Y\n p N; exit\nend\n\np (A.count{ |a| a <= X }+1)/2", "positive_code": [{"source_code": "n, x, y = gets.split.map(&:to_i)\na = gets.split.map(&:to_i)\nif x > y\n\tputs n\nelse\n\tputs a.count { _1 <= x }.succ / 2\nend\n"}, {"source_code": "# Input\nn, x, y = gets.split(\" \").map { |e| e.to_i }\na = gets.split(\" \").map { |e| e.to_i }\n\n# total_moves = 10**100, and maximum_hp = 100 * 10**5 = 10**7 => If we are stronger then everything will be destroyed *evil laugh*\n\n# Processing\nd = x - y\none_hit = a.count { |n| n <= x }\ncase\nwhen d > 0\n result = n\nwhen d <= 0\n result = one_hit / 2 + one_hit % 2\nend\n\n# Output\nputs result\n"}, {"source_code": "n, x, y = gets.split.map(&:to_i)\narr = gets.split.map(&:to_i)\nif x > y\n puts n\n exit\nend\nif x == y\n puts (arr.select{|a| a <= x}.size / 2.0).ceil\n exit\nend\nif x < y\n puts (arr.select{|a| a <= x}.size / 2.0).ceil\n exit\nend"}], "negative_code": [{"source_code": "# Input\nn, k = gets.split(\" \").map { |e| e.to_i }\na = gets.split(\" \").map { |e| e }\n\n# Processing\ncount = Hash.new(0)\ncurrent_color = Hash.new\n\na.each do |n|\n count[n] += 1\nend\n\ncount.each do |n, amount|\n if amount > k\n puts \"NO\"\n #puts \"#{n} amount > k\"\n exit\n end\n current_color[n] = (current_color.length % k) + 1\nend\n\nc = Array.new(n) do |i|\n #puts current_color\n color = current_color[a[i]]\n current_color[a[i]] = current_color[a[i]] % k + 1\n color\nend\n\n# Output\nputs \"YES\"\nputs c.join(\" \")\n"}, {"source_code": "# Input\nn, x, y = gets.split(\" \").map { |e| e.to_i }\na = gets.split(\" \").map { |e| e.to_i }\n\n# total_moves = 10**100, and maximum_hp = 100 * 10**5 = 10**7 => If we are stronger then everything will be destroyed *evil laugh*\n\n# Processing\nd = x - y\none_hit = a.count { |n| n < x }\ncase\nwhen d > 0\n result = n\nwhen d <= 0\n result = one_hit / 2 + one_hit % 2\nend\n\n# Output\nputs result\n"}], "src_uid": "c173e2695562dfa1f603e6a925a2e1f3"} {"source_code": "int,frac = gets.split('.')\nif int[-1] == '9'\n puts \"GOTO Vasilisa.\"\nelsif frac[0].to_i < 5\n puts int\nelse\n puts int.to_i+1\nend\n", "positive_code": [{"source_code": "ss = gets.chomp.split(/\\./)\ni = ss[0].to_i\n\ns = ss[0]\nch = s[s.length-1]\nif ch == \"9\" then\n puts \"GOTO Vasilisa.\"\nelse\n rnd = ss[1][0].to_i\n if rnd < 5 then\n puts i\n else\n puts i+1\n end\nend\n\n\n"}, {"source_code": "gets\nif /(.*(.))\\.(.)/\n\tputs $2 == '9' ? 'GOTO Vasilisa.' : $1.to_i + ($3 < '5' ? 0 : 1)\nend\n"}, {"source_code": "n=gets\ns=n.split('\\n')[0].split('.')\ns[0]=s[0].to_i\n\nif s[0]%10 == 9 then\n puts \"GOTO Vasilisa.\"\nelse\n if s[1].slice(0)>='5' then\n s[0]+=1\n end\n puts s[0]\nend\n"}, {"source_code": "num = gets\nthe_dot = num.index('.')\nif num[the_dot-1] == '9'\n\tputs \"GOTO Vasilisa.\"\nelse\n\tif num[the_dot+1].to_i >= 5\n\t\tputs ((num[0...the_dot].to_i)+1).to_s\n\telse\n\t\tputs num[0...the_dot]\n\tend\nend\n"}, {"source_code": "if(gets =~ /(.*)(.)\\.(.)/)\n puts $2 == '9' ? 'GOTO Vasilisa.' : ($1 + $2).to_i + ($3 < '5' ? 0: 1)\nend\n"}, {"source_code": "s = gets.chomp\nt = s.index(\".\")\nif s[t-1] == '9'\n puts \"GOTO Vasilisa.\"\n exit\nend\nputs s[t+1] <= \"4\" ? s[0...t] : s[0...t].succ"}, {"source_code": "a,b = gets.chomp.split('.')\nif a.to_i % 10 == 9 then puts \"GOTO Vasilisa.\"\nelse if b[0].to_i >= 5 then p a.to_i + 1\nelse p a.to_i end end"}, {"source_code": "a,b=gets.split(?.);c,g=a[-1,1],b[0,1];puts c!=?9&&g?4?a.to_i+1:\"GOTO Vasilisa.\"\n"}, {"source_code": "a,b=gets.split(?.);c,g=a[-1,1],b[0,1];puts c!=?9&&g=?5? a.to_i+1:\"GOTO Vasilisa.\")\n"}, {"source_code": "a,b=gets.split('.')\n\nch1, ch2 = a[-1,1], b[0,1]\n\nif ch1!='9' && ch2<'5'\n\tputs a\nelsif ch1!='9' && ch2>='5'\n\tputs a.to_i+1\nelse\n\tputs \"GOTO Vasilisa.\"\nend\n"}, {"source_code": "gets;if /(.*(.))\\.(.)/ then puts $2=='9'?'GOTO Vasilisa.':$1.to_i+($3<'5'?0:1);end"}, {"source_code": "def help_far_away_kingdom\n i, f = gets.split('.')\n\n if i[i.length-1] == '9'\n puts 'GOTO Vasilisa.'\n else\n if f.nil? or f[0].to_i < 5\n puts i.to_i\n else\n puts i.to_i+1\n end\n end\nend\nhelp_far_away_kingdom"}, {"source_code": "int, frac = gets.split('.')\nif int[-1] == '9'\n puts \"GOTO Vasilisa.\"\nelsif frac[0].to_i < 5\n puts int\nelse\n puts int.to_i+1\nend\n"}, {"source_code": "while !gets.nil?\n\ninteger, float = $_.split('.')\n\nif integer[-1] == '9'\n puts \"GOTO Vasilisa.\"\nelsif float[0].to_i <= 4\n puts integer\nelse\n integer[-1] = integer[-1].succ\n puts integer\nend\n\n\nend\n"}, {"source_code": "inp = gets.split('.')\n\nint_part = inp[0]\n\nif int_part.rindex('9') == int_part.size-1\n puts \"GOTO Vasilisa.\"\nelsif inp[1][0..0].to_i >= 5\n puts inp[0].to_i + 1\nelse\n puts inp[0]\nend \n\n"}, {"source_code": "i, f = gets.chomp.split(\".\")\nif i[-1] == \"9\"\n puts \"GOTO Vasilisa.\"\nelsif f[0] < \"5\"\n puts i\nelse\n puts i.to_i+1\nend\n"}, {"source_code": "s = gets\ncase s\nwhen /9\\./\n puts 'GOTO Vasilisa.'\nwhen /(\\d+)\\.[0-4]/\n puts $1.to_i\nelse\n puts s.to_i + 1\nend\n\n"}, {"source_code": "#!/usr/bin/ruby\ns = $stdin.gets.strip.split(\".\")\nint = s[0].to_i\nflt = s[1][0].to_i\nBlah = \"GOTO Vasilisa.\"\nif int % 10 == 9 then\n puts \"#{Blah}\"\nelse\n int += 1 if flt >= 5\n puts \"#{int}\"\nend\n"}, {"source_code": "x = gets.strip\n\nif x =~ /9\\./\n\tprint :\"GOTO Vasilisa.\"\nelse\n\tx =~ /(\\d+)\\.(\\d)/\n\tprint $2.to_i < 5 ? $1 : $1.to_i + 1\nend"}], "negative_code": [{"source_code": "a,b = gets.chomp.split('.')\nif a.to_i % 9 == 0 then puts \"GOTO Vasilisa.\"\nelse if b[0].to_i >= 5 then p a.to_i + 1\nelse p a.to_i end end"}, {"source_code": "def help_far_away_kingdom\n n = gets.strip\n r, ind = '', 0\n\n while ind < n.length\n if n[ind+1] == '.'\n if n[ind] == '9'\n puts 'GOTO Vasilisa.'\n else\n fraction = (\"0.#{n[ind+2..-1]}\").to_f\n if fraction < 0.5\n puts n[0..ind].to_i\n else\n puts n[0..ind].to_i + 1\n end\n end\n break\n end\n ind += 1\n end\n puts n if ind == n.length\nend\n\nhelp_far_away_kingdom"}, {"source_code": "\ndef help_far_away_kingdom\n n = gets.strip\n r, ind = '', 0\n\n while ind < n.length\n if n[ind+1] == '.'\n if n[ind] == '9'\n puts 'GOTO Vasilisa.'\n else\n fraction = (\"0.#{n[ind+2..-1]}\").to_f\n if fraction < 0.5\n puts n[0..ind].to_i\n else\n puts n[0..ind].to_i + 1\n end\n end\n break\n end\n ind += 1\n end\nend\n\nhelp_far_away_kingdom"}, {"source_code": "while !gets.nil?\n\ninteger, float = $_.split('.')\nif integer[-1] == '9'\n puts \"GOTO Vasilisa.\"\nelsif float[0].to_i < 4\n integer[-1] = integer[-1].succ\n puts integer\nelse\n puts integer\nend\n\n\nend\n"}, {"source_code": "while !gets.nil?\n\ninteger, float = $_.split('.')\n\nif integer[-1] == '9'\n puts \"GOTO Vasilisa.\"\nelsif float[0].to_i < 4\n integer[-1] = integer[-1].succ\n puts integer\nelse\n puts integer\nend\n\n\nend\n"}, {"source_code": "x = gets.strip\nf = x.split('.')[1]\nprint f.count(\"9\") == f.length ? :\"GOTO Vasilisa.\" : x.to_f.round\n"}, {"source_code": "x = gets.strip\nl, r = x.split('.').map &:to_i\n\nif l % 10 == 9\n\tprint :\"GOTO Vasilisa.\"\nelse\n\tl += 1 if r.to_s[0].to_i >= 5\n\tprint l\nend"}, {"source_code": "x = gets.strip\nprint x[-1] == \"9\" ? :\"GOTO Vasilisa.\" : x.to_f.round"}], "src_uid": "3060ecad253a2b4d4fac39e91fcd6c95"} {"source_code": "\r\n\r\ndef solve(cur_ram, arr1, arr2)\r\n merge_arr = []\r\n for index in 0..(arr1.length-1)\r\n merge_arr << [arr1[index], arr2[index]]\r\n end\r\n \r\n merge_arr.sort_by! {|x, y| x}\r\n \r\n # puts \"merge_arr = #{merge_arr}\"\r\n \r\n for index in 0..(merge_arr.length-1)\r\n break if merge_arr[index][0] > cur_ram\r\n cur_ram += merge_arr[index][1]\r\n end\r\n cur_ram\r\nend\r\n\r\n\r\n\r\ntestcases = gets.chomp.to_i\r\n\r\nfor testcase in 1..testcases\r\n n, k = gets.chomp.split(\" \").map(&:to_i)\r\n arr1 = gets.chomp.split(\" \").map(&:to_i)\r\n arr2 = gets.chomp.split(\" \").map(&:to_i)\r\n # puts \"n, k, arr1, arr2 = #{[n, k, arr1, arr2]}\"\r\n res = solve(k, arr1, arr2)\r\n puts res\r\nend", "positive_code": [{"source_code": "t = gets.chomp.to_i\r\n\r\nfor i in (1..t)\r\n n, k = gets.chomp.split.map {|e| e.to_i}\r\n a = gets.chomp.split.map {|e| e.to_i}\r\n b = gets.chomp.split.map {|e| e.to_i}\r\n c = (a.zip b).sort\r\n for j in (0..n-1)\r\n if k >= c[j][0]\r\n k += c[j][1]\r\n end\r\n end\r\n puts k\r\nend\r\n"}, {"source_code": "gets.to_i.times do\r\n n, k = gets.split.map(&:to_i)\r\n abs = gets.split.map(&:to_i).zip(gets.split.map(&:to_i)).sort_by(&:first)\r\n abs.each do |a, b|\r\n break if k < a\r\n k += b\r\n end\r\n p k\r\nend\r\n"}], "negative_code": [], "src_uid": "168f2a740d21a3a916a9d560fbcffeb9"} {"source_code": "n,*a=$<.read.split.map &:to_i;(n/2).times{|i|a[i],a[n-i-1]=a[n-i-1],a[i]if i.even?};puts a*' '", "positive_code": [{"source_code": "n,*a=$<.read.split.map &:to_i;(n/2).times{|i|a[i],a[n-i-1]=a[n-i-1],a[i]if i.even?};puts a*' '"}, {"source_code": "n = gets.chomp.to_i\na = gets.chomp.split.map(&:to_i)\n\n(0...(n / 2)).each do |i|\n next if i.odd?\n t = a[i]\n a[i] = a[n - i - 1]\n a[n - i - 1] = t\nend\n\nputs a.join(\" \")\n"}, {"source_code": "TEST_MODE = ARGV[0] == 't'\n\ndef evaluate(actual, expected); actual == expected ? \"OK\" : \"**NG**\"; end\ndef tests(); yield if TEST_MODE; end\ndef to_array(val); val.kind_of?(Array) ? val : [val]; end\ndef parse_int_array(str); str.split(\" \").collect{|s| s.to_i}; end\n\ndef t(input, expected_output)\n input = to_array(input)\n expected_output = to_array(expected_output)\n output = []\n solve(input, output)\n puts \"#{evaluate(output, expected_output)} : input=#{input.to_s}, expected=#{expected_output.to_s}, actual=#{output.to_s}\"\nend\n\ndef solve(input, output)\n arr = parse_int_array(input[1])\n (0..arr.size/2-1).step(2) {|i|\n temp = arr[i]\n arr[i] = arr[arr.size-i-1]\n arr[arr.size-i-1] = temp\n }\n output << arr.join(\" \")\nend\n\ntests do\n # test cases\n t([\"7\",\"4 3 7 6 9 1 2\"], \"2 3 9 6 7 1 4\")\n t([\"8\",\"6 1 4 2 5 6 9 2\"], \"2 1 6 2 5 4 9 6\")\nend\n\nputs solve(STDIN.read.split(\"\\n\"), []) unless TEST_MODE\n"}, {"source_code": "n=gets.to_i\ns=gets.chomp.split\n(s.size/2).times{|i|\n\tif i%2==0 then\n\t\ts[i],s[n-i-1]=s[n-i-1],s[i]\n\tend\n}\nputs s*\" \"\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nb=[]\nif n.odd?\n (0...n).each{|i| b[i.odd? ? i : n-i-1]=a[i]}\nelse\n (0...n/2).each{|i| b[i.odd? ? i : n-i-1]=a[i]}\n (0...n/2).each{|i| b[i.odd? ? n-i-1 : i]=a[n-i-1]}\nend\nputs b*' '\n"}, {"source_code": "n,*a=$<.read.split.map &:to_i;(n/2).times{|i|a[i],a[n-i-1]=a[n-i-1],a[i]if i.even?};puts a*' '"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nc = n / 2 + (n.even? ? 0 : 1) - 1\nans = []\nc.times do |i|\n if i % 2 == 0\n ans[i] = a[n - 1 - i]\n ans[n - 1 - i] = a[i]\n else\n ans[i] = a[i]\n ans[n - 1 - i] = a[n - 1 - i]\n end\nend\na2 = a[c..(n - 1 - c)]\na2.reverse! if c % 2 == 0\nans[c..(n - 1 - c)] = a2\nputs ans.join(' ')\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\n(n / 2).times do |i|\n a[i], a[-1 - i] = a[-1 - i], a[i] if i % 2 == 0\nend\nputs a.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map &:to_i\nfor i in 0 ... n / 2\n if i % 2 == 0\n tmp = a[i]\n a[i] = a[n - 1 - i]\n a[n - 1 - i] = tmp\n end\nend\nputs a*' '\n"}], "negative_code": [], "src_uid": "7d2f22fc06d4f0b8ff8be6c6862046e7"} {"source_code": "MOD = 10 ** 9 + 7\r\ndef gs; gets.chomp; end\r\ndef gi; gets.to_i; end\r\ndef gli; gets.split.map(&:to_i); end\r\ndef cyesno(x); puts x ? :Yes : :No; end\r\ndef uyesno(x); puts x ? :YES : :NO; end\r\ndef array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end\r\n\r\ndef main\r\n gi.times do\r\n n = gi\r\n d = 1\r\n s = 0\r\n c = 0\r\n while n > s\r\n s += d\r\n c += 1\r\n d += 2\r\n end\r\n puts c\r\n end\r\nend\r\n\r\nmain\r\n", "positive_code": [{"source_code": "\n\nt = gets.chomp.to_i\n\nt.times do\n n = gets.chomp.to_i\n ans = 0\n curr_max = 1\n sum = 0\n while sum < n do\n ans += 1\n n -= curr_max\n curr_max += 2\n end\n \n ans += 1 if n > 0\n\n puts \"#{ans}\\n\"\nend\n\n"}], "negative_code": [], "src_uid": "322792a11d3eb1df6b54e8f89c9a0490"} {"source_code": "T=gets().to_i\nline=gets().split(\" \").map!{|x|x.to_i}\nsum=(T*(T+1))/2\nsb=line.inject(:+)\nputs sum-sb", "positive_code": [{"source_code": "n=gets.to_i\nmas=gets.split.map &:to_i\nputs (n*(n+1)/2) - mas.inject(:+)"}, {"source_code": "i=->{gets.split.map &:to_i}\nn=i[][0]\np n*(n+1)/2-i[].inject(:+)"}], "negative_code": [], "src_uid": "0e4ff955c1e653fbeb003987fa701729"} {"source_code": "regs = [/(\\w+) posted on (\\w+)'s wall/,\n /(\\w+) commented on (\\w+)'s post/,\n /(\\w+) likes (\\w+)'s post/]\n\nmyname = gets.chomp\naction = gets.to_i\nplayer = {}\naction.times do |i|\n tmp = gets\n if tmp =~ regs[0]\n # p $1,$2\n if myname == $1\n if myname != $2\n player.store($2,0) if player[$2] == nil\n player[$2] += 15\n end\n elsif myname == $2\n if myname != $1\n player.store($1,0) if player[$1] == nil\n player[$1] += 15\n end\n else\n player.store($1,0) if player[$1] == nil\n player.store($2,0) if player[$2] == nil\n end\n elsif tmp =~ regs[1]\n# p $1,$2\n if myname == $1\n if myname != $2\n player.store($2,0) if player[$2] == nil\n player[$2] += 10\n end\n elsif myname == $2\n if myname != $1\n player.store($1,0) if player[$1] == nil\n player[$1] += 10\n end\n else\n player.store($1,0) if player[$1] == nil\n player.store($2,0) if player[$2] == nil\n end\n elsif tmp =~ regs[2]\n# p $1,$2\n if myname == $1\n if myname != $2\n player.store($2,0) if player[$2] == nil\n player[$2] += 5\n end\n elsif myname == $2\n if myname != $1\n player.store($1,0) if player[$1] == nil\n player[$1] += 5\n end\n else\n player.store($1,0) if player[$1] == nil\n player.store($2,0) if player[$2] == nil\n end\n end\nend\nvalues = player.values\nkeys = player.keys\nwhile true do\n maxary = []\n max = values.max\n while true do\n maxpos = values.index(max)\n maxary << keys[maxpos].dup\n #p max,maxpos,maxary\n values.delete_at(maxpos)\n keys.delete_at(maxpos)\n break if values == []\n break if max > values.max\n end\n maxary.map{|item| item.extend Comparable}\n sorted = maxary\n sorted = maxary.sort if maxary.size > 1\n\n puts sorted\n break if values == []\nend", "positive_code": [{"source_code": "my_name = STDIN.gets.strip\nn = STDIN.gets.strip.to_i\nactions = []\nn.times do \n actions.push STDIN.gets.strip\nend\npersons = {}\nregexps = [/(.*) posted on (.*)'s wall/,/(.*) commented on (.*)'s post/,/(.*) likes (.*)'s post/]\npoints = [15,10,5]\nactions.each do |action|\n 3.times do |i|\n if match = regexps[i].match(action)\n if match[1] == my_name || match[2] == my_name\n if persons[match[1]]\n persons[match[1]] += points[i]\n else\n persons[match[1]] = points[i]\n end\n if persons[match[2]]\n persons[match[2]] += points[i]\n else\n persons[match[2]] = points[i]\n end\n else\n if !persons[match[1]]\n persons[match[1]] = 0\n end\n if !persons[match[2]]\n persons[match[2]] = 0\n end\n end\n end\n end\nend\npersons.delete(my_name)\nsorted = persons.to_a.sort_by{|x| [-x[1],x[0]]}\nsorted.each do |person|\n puts person[0]\nend\n"}, {"source_code": "me = gets.chomp\n\nmap = Hash.new {|hash, key| hash[key] = 0 }\n\n(gets.to_i).times do \n line = gets.chomp.split\n x = line[0]\n y = nil\n points = 0\n if line[1] == \"posted\"\n points = 15\n y = line[3]\n elsif line[1] == \"commented\"\n points = 10\n y = line[3]\n elsif line[1] == \"likes\"\n points = 5\n y = line[2]\n end\n y = y[0..y.size - 3]\n if x == me \n map[y] += points\n elsif y == me\n map[x] += points\n else\n map[y] += 0\n map[x] += 0\n end\nend\n\n(map.sort {|a, b| if a[1] == b[1]\n a[0] <=> b[0] else b[1] <=> a[1] end }).each do |m|\n puts m[0]\nend\n\n"}, {"source_code": "my_name = gets.chomp\nnames = Hash.new(0)\ngets.to_i.times do\n gets.chomp =~ /^(\\w+) (posted on|commented on|likes) (\\w+)'s (wall|post)$/\n n1, n2 = $1, $3\n other_name = if n1 == my_name\n n2\n elsif n2 == my_name\n n1\n end\n if other_name\n point = case $2\n when \"posted on\"\n 15\n when \"commented on\"\n 10\n else # \"likes\"\n 5\n end\n names[other_name] += point \n else\n names[n1] += 0\n names[n2] += 0\n end\nend\n\nnames.sort{|a,b| (b[1] <=> a[1]).nonzero? || a[0] <=> b[0] }.each{|n| puts n[0]}\n"}, {"source_code": "h = Hash.new(0)\nu = gets.chomp\ngets.to_i.times do\n\t$_ = gets\n\tif /(\\w+) posted on (\\w+)'s wall/\n\t\tx, y, z = $1, $2, 15\n\telsif /(\\w+) commented on (\\w+)'s post/\n\t\tx, y, z = $1, $2, 10\n\telsif /(\\w+) likes (\\w+)'s post/\n\t\tx, y, z = $1, $2, 5\n\telse\n\t\twarn 555\n\tend\n\tif x == u\n\t\th[y] += z\n\telsif y == u\n\t\th[x] += z\n\telse\n\t\th[x] += 0\n\t\th[y] += 0\n\tend\nend\nputs h.map{|k, v| [-v, k]}.sort.map{|a, b| b} * \"\\n\"\n"}, {"source_code": "regs = [/(\\w+) posted on (\\w+)'s wall/,\n /(\\w+) commented on (\\w+)'s post/,\n /(\\w+) likes (\\w+)'s post/]\n\nmyname = gets.chomp\naction = gets.to_i\nplayer = {}\naction.times do |i|\n tmp = gets\n if tmp =~ regs[0]\n # p $1,$2\n if myname == $1\n if myname != $2\n player.store($2,0) if player[$2] == nil\n player[$2] += 15\n end\n elsif myname == $2\n if myname != $1\n player.store($1,0) if player[$1] == nil\n player[$1] += 15\n end\n else\n player.store($1,0) if player[$1] == nil\n player.store($2,0) if player[$2] == nil\n end\n elsif tmp =~ regs[1]\n# p $1,$2\n if myname == $1\n if myname != $2\n player.store($2,0) if player[$2] == nil\n player[$2] += 10\n end\n elsif myname == $2\n if myname != $1\n player.store($1,0) if player[$1] == nil\n player[$1] += 10\n end\n else\n player.store($1,0) if player[$1] == nil\n player.store($2,0) if player[$2] == nil\n end\n elsif tmp =~ regs[2]\n# p $1,$2\n if myname == $1\n if myname != $2\n player.store($2,0) if player[$2] == nil\n player[$2] += 5\n end\n elsif myname == $2\n if myname != $1\n player.store($1,0) if player[$1] == nil\n player[$1] += 5\n end\n else\n player.store($1,0) if player[$1] == nil\n player.store($2,0) if player[$2] == nil\n end\n end\nend\nvalues = player.values\nkeys = player.keys\nwhile true do\n maxary = []\n max = values.max\n while true do\n maxpos = values.index(max)\n maxary << keys[maxpos].dup\n #p max,maxpos,maxary\n values.delete_at(maxpos)\n keys.delete_at(maxpos)\n break if values == []\n break if max > values.max\n end\n maxary.map{|item| item.extend Comparable}\n sorted = maxary\n sorted = maxary.sort if maxary.size > 1\n\n puts sorted\n break if values == []\nend"}, {"source_code": "MYNAME = gets.chomp\nN = gets.to_i\npersons = Hash.new(0)\nN.times do\n str = gets.split(' ')\n add = 0\n x = str[0]\n y = str[3]\n if (str[1] == \"posted\")\n add = 15\n elsif (str[1] == \"commented\")\n add = 10\n else\n add = 5\n y = str[2]\n end\n y.gsub!(\"'s\", \"\")\n if (x != MYNAME && y != MYNAME) # Priority factor according to me!\n add = 0 # but we have to print ALL persons\n end\n persons[x] += add\n persons[y] += add\nend\n\nresult = persons.to_a.sort{|l, r|\n if (l[1] != r[1])\n r[1] <=> l[1]\n else\n l[0] <=> r[0]\n end\n}\n\n#p result\n\nresult.each {|e|\n puts e[0] if (e[0] != MYNAME)\n}\n"}, {"source_code": "name = gets.chomp\nn = gets.to_i\npriority = Hash.new(0)\nn.times do\n\tv = gets.chomp.downcase\n\tarr = v.split(\" \")\n\ta = arr[0]\n\tp = 0\n\tif arr[1].eql?(\"posted\") \n\t\tp = 15\n\t\tb = arr[3]\n\telsif arr[1].eql?(\"commented\") \n\t\tp = 10\n\t\tb = arr[3]\n\telse\n\t\tp = 5\n\t\tb = arr[2]\n\tend\n\tb = b.sub(\"'s\",\"\")\n\tp = 0 unless (a.eql?(name) || b.eql?(name))\n\tpriority[a] += p\n\tpriority[b] += p\t\nend\n\npriority.keys.sort{|k1,k2| priority[k1] != priority[k2] ? -(priority[k1] <=> priority[k2]) : k1 <=> k2}.each do |k|\n\tputs k unless k.eql?(name)\nend\n"}], "negative_code": [{"source_code": "regs = [/(\\w+) posted on (\\w+)'s wall/,\n /(\\w+) commented on (\\w+)'s post/,\n /(\\w+) likes (\\w+)'s post/]\n\nmyname = gets.chomp\naction = gets.to_i\nplayer = {}\naction.times do |i|\n tmp = gets\n if tmp =~ regs[0]\n # p $1,$2\n if myname == $1\n if myname != $2\n player.store($2,0) if player[$2] == nil\n player[$2] += 15\n end\n elsif myname == $2\n if myname != $1\n player.store($1,0) if player[$1] == nil\n player[$1] += 15\n end\n else\n player.store($1,0) if player[$1] == nil\n player.store($2,0) if player[$2] == nil\n end\n elsif tmp =~ regs[1]\n# p $1,$2\n if myname == $1\n if myname != $2\n player.store($2,0) if player[$2] == nil\n player[$2] += 10\n end\n elsif myname == $2\n if myname != $1\n player.store($1,0) if player[$1] == nil\n player[$1] += 10\n end\n else\n player.store($1,0) if player[$1] == nil\n player.store($2,0) if player[$2] == nil\n end\n elsif tmp =~ regs[2]\n# p $1,$2\n if myname == $1\n if myname != $2\n player.store($2,0) if player[$2] == nil\n player[$2] += 5\n end\n elsif myname == $2\n if myname != $1\n player.store($1,0) if player[$1] == nil\n player[$1] += 5\n end\n else\n player.store($1,0) if player[$1] == nil\n player.store($2,0) if player[$2] == nil\n end\n end\nend\nvalues = player.values\nkeys = player.keys\n\nwhile true do\n while true do\n maxary = []\n max = values.max\n maxpos = values.index(values.max)\n maxary << keys[maxpos]\n# p max,maxpos,maxary\n values.delete_at(maxpos)\n keys.delete_at(maxpos)\n break if max > values.max.to_i\n end\n #maxary.sort_by!{|a,b| b <=> a} if maxary.size > 1\n# puts maxary\n break if values == []\nend"}, {"source_code": "MYNAME = gets.chomp\nN = gets.to_i\npersons = Hash.new(0)\nN.times do\n str = gets.split(' ')\n add = 0\n x = str[0]\n y = str[3]\n if (str[1] == \"posted\")\n add = 15\n elsif (str[1] == \"commented\")\n add = 10\n else\n add = 5\n y = str[2]\n end\n y.gsub!(\"'s\", \"\")\n persons[x] += add\n persons[y] += add\nend\n\nresult = persons.to_a.sort{|l, r|\n if (l[1] != r[1])\n r[1] <=> l[1]\n else\n l[0] <=> r[0]\n end\n}\n\n#p result\n\nresult.each {|e|\n puts e[0] if (e[0] != MYNAME)\n}\n"}, {"source_code": "name = gets.chomp\nn = gets.to_i\npriority = Hash.new(0)\nn.times do\n\tv = gets.chomp.downcase\n\tarr = v.split(\" \")\n\ta = arr[0]\n\tp = 0\n\tif arr.include?(\"posted\") \n\t\tp = 15\n\t\tb = arr[3]\n\telsif arr.include?(\"commented\") \n\t\tp = 10\n\t\tb = arr[3]\n\telse\n\t\tp = 5\n\t\tb = arr[2]\n\tend\n\tb = b.sub(\"'s\",\"\")\n\tp = 0 unless (a.eql?(name) || b.eql?(name))\n\tpriority[a] += p\n\tpriority[b] += p\t\nend\n\npriority.keys.sort{|k1,k2| priority[k1] != priority[k2] ? -(priority[k1] <=> priority[k2]) : k1 <=> k2}.each do |k|\n\tputs k unless k.eql?(name)\nend\n"}, {"source_code": "name = gets.chomp\nn = gets.to_i\npriority = Hash.new(0)\nn.times do\n\tv = gets.chomp.downcase\n\tarr = v.split(\" \")\n\ta = arr[0]\n\tp = 0\n\tif arr.include?(\"posted\") \n\t\tp = 15\n\t\tb = arr[3]\n\telsif arr.include?(\"commented\") \n\t\tp = 10\n\t\tb = arr[3]\n\telse\n\t\tp = 5\n\t\tb = arr[2]\n\tend\n\tb = b.sub(\"'s\",\"\")\n\tp = 0 unless (a.include?(name) || b.include?(name))\n\tpriority[a] += p\n\tpriority[b] += p\t\nend\n\npriority.keys.sort{|k1,k2| priority[k1] != priority[k2] ? -(priority[k1] <=> priority[k2]) : k1 <=> k2}.each do |k|\n\tputs k unless k.eql?(name)\nend\n"}, {"source_code": "me = gets.chomp\n\nmap = Hash.new {|hash, key| hash[key] = 0 }\n\n(gets.to_i).times do \n line = gets.chomp.split\n x = line[0]\n y = nil\n points = 0\n if line[1] == \"posted\"\n points = 15\n y = line[3]\n elsif line[1] == \"commented\"\n points = 10\n y = line[3]\n elsif line[1] == \"likes\"\n points = 5\n y = line[2]\n end\n y = y[0..y.size - 3]\n map[x] += points\n map[y] += points\nend\n\n(map.sort {|a, b| if a[1] == b[1]\n a[0] <=> b[0] else b[1] <=> a[1] end }).each do |m|\n if m[0] != me \n puts m[0]\n end\nend\n\n"}, {"source_code": "my_name = gets.chomp\nnames = Hash.new(0)\ngets.to_i.times do\n gets.chomp =~ /^(\\w+) (posted on|commented on|likes|) (\\w+)'s (wall|post)$/\n n1, n2 = $1, $3\n other_name = if n1 == my_name\n n2\n elsif n2 == my_name\n n1\n end\n if other_name\n point = case $2\n when \"posted on\"\n 15\n when \"commented on\"\n 10\n else # \"likes\"\n 5\n end\n names[other_name] += 5\n else\n names[n1] += 0\n names[n2] += 0\n end\nend\n\nnames.sort{|a,b| (b[1] <=> a[1]).nonzero? || a[0] <=> b[0] }.each{|n| puts n[0]}\n"}], "src_uid": "b1a86308739067f2b6c9940b564e2648"} {"source_code": "times = gets.to_i\n\ndef resolve(binary_s)\n game_a = binary_s.split(\"0\").map(&:size).sort{|a,b| b <=> a}\n game_a.delete(0)\n alice_points = 0\n game_a.each_with_index {|e,i| alice_points += e if i % 2 == 0}\n alice_points\nend\n\n(1..times).each do |i|\n s = gets.chomp\n puts resolve(s)\nend", "positive_code": [{"source_code": "gets.to_i.times do\n puts gets.chomp.split(/0+/).map(&:length).sort{ |a, b| b <=> a }.select.each_with_index{|_, index| index.even?}.sum\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times do \n s = gets.chomp.split(\"\")\n ookisa = s.size\n ans = 0\n count = 0\n arr = []\n (0..ookisa-1).each_with_index do |item,i|\n if item == \"1\" && s[i] == \"1\" && s[i-1] == \"1\" && i != 0\n count += 1\n elsif s[i] == \"1\"\n count += 1\n elsif s[i] == \"0\"\n arr << count\n count = 0\n end\n if ans <= count\n ans = count\n point = i\n end\n end\n arr << count\n arr = arr.sort\n arisa = 0\n bob = 0\n while true\n if arr != []\n arisa += arr.pop\n else\n break\n end\n if arr != []\n bob += arr.pop\n else\n break\n end\n end\n puts arisa\nend"}, {"source_code": "t = gets.chomp.to_i\nt.times {\n str = gets.chomp\n index = -1\n (0...str.size).each do |ind|\n next if str[ind] == '0'\n\n index = ind\n break\n end\n\n list = []\n count = 1\n\n if index == -1\n puts '0'\n next\n end\n (index+1...str.size).each do |ind|\n if str[ind] == '1'\n count += 1\n else\n list << count if count != 0\n count = 0\n end\n end\n \n\n list << count if count != 0\n list.sort_by! {|ele| -1 * ele}\n\n ans = 0\n i = 0\n while ( i < list.size ) do\n ans += list[i]\n i += 2\n end\n puts ans\n}\n"}, {"source_code": "t = gets.to_i\nans = []\nt.times do\n a = gets.chomp.split(\"\").map(&:to_i)\n arr = []\n cnt = 0\n a.each do |v|\n if v == 1\n cnt += 1\n else\n if cnt > 0\n arr << cnt\n cnt = 0\n end\n end\n end\n if cnt > 0\n arr << cnt\n end\n arr = arr.sort.reverse\n len = arr.length\n value = 0\n len.times do |i|\n value += arr[i] if i%2 == 0\n end\n ans << value\nend\nans.each do |x|\n puts x\nend"}], "negative_code": [{"source_code": "gets.to_i.times do\n puts gets.split(/0+/).map(&:length).sort{ |a, b| b <=> a }.select.each_with_index{|_, index| index.even?}.sum\nend\n"}, {"source_code": "t = gets.chomp.to_i\nt.times {\n str = gets.chomp\n index = -1\n (0...str.size).each do |ind|\n next if str[ind] == '0'\n\n index = ind\n break\n end\n\n list = []\n count = 1\n\n if index == -1 \n puts '0'\n next\n end\n\n (index+1...str.size).each do |ind|\n if str[ind] == '1'\n count += 1\n else\n list << count if count != 0\n count = 0\n end\n end\n \n\n list << count if count != 0\n list.sort_by {|ele| -1 * ele}\n\n ans = 0\n i = 0\n while ( i < list.size ) do\n ans += list[i]\n i += 2\n end\n puts ans\n}\n"}], "src_uid": "ebf0bf949a29eeaba3bcc35091487199"} {"source_code": "at_exit do\n task_count = get_numbers_from_line[0]\n tasks = []\n task_count.times do\n t,c = get_numbers_from_line[0..1]\n tasks << {t: t, sms_count: c}\n end\n\n time = 0\n max_queue_length = 0\n task_in_queue_count = 0\n while true\n next_task = tasks.shift\n if next_task != nil\n dt = next_task[:t] - time\n task_in_queue_count = [0, task_in_queue_count - dt].max\n task_in_queue_count += next_task[:sms_count]\n max_queue_length = task_in_queue_count if task_in_queue_count > max_queue_length\n time += dt\n elsif task_in_queue_count != 0\n time += task_in_queue_count\n break\n else\n break\n end\n end\n\n puts [time, max_queue_length].join(' ')\nend\n\ndef get_numbers_from_line\n gets.strip.split.map(&:to_i)\nend", "positive_code": [{"source_code": "num_tasks = gets.to_i\ntasks = Array.new\nfor i in 0...num_tasks\n tasks << gets.split.collect{ |n| n.to_i }\nend\ncurrent_task = tasks.shift\nt = current_task[0]\nto_send = current_task[1]\nmax_queries = to_send\nif tasks.length < 1\n puts (t+to_send).to_s + \" \" + max_queries.to_s\n exit\nend\ncurrent_task = tasks.shift\nwhile true\n t = t+1\n to_send -= 1 if to_send > 0\n if t == current_task[0]\n to_send += current_task[1]\n if to_send > max_queries\n max_queries = to_send\n end\n if tasks.length < 1\n break\n end\n current_task = tasks.shift\n end\nend\nputs (t+to_send).to_s + \" \" + max_queries.to_s"}, {"source_code": "class A\n def initialize\n n = $stdin.gets.chomp.to_i\n queue_size = 0\n b_time = 0\n next_time = 0\n max_size = 0\n\n n.times do \n time, task = $stdin.gets.chomp.split(' ').map(&:to_i)\n d_time = time - b_time\n \n queue_size = [0, queue_size-d_time].max\n\n b_time = time\n \n queue_size += task\n\n max_size = queue_size if max_size < queue_size\n end\n\n puts \"#{b_time+queue_size} #{max_size}\"\n end\nend\n\na = A.new"}, {"source_code": "n = gets.to_i\n\ntc = n.times.map{ gets.split.map(&:to_i) }\n\nt = 1\nmax = 0\nprev = [0, 0]\n\ntc.each do |i|\n t = (t < i[0] ? i[0] : t) + i[1]\n m = prev[1] + prev[0] - i[0]\n m = m > 0 ? m + i[1] : i[1]\n max = m if max < m\n prev = [i[0], m]\nend\n\nputs \"#{t} #{max}\"\n"}, {"source_code": "n = gets.chomp.to_i\n\ntimes = []\nmessages_count = []\n\nmax_queue = 1\nqueue = 0\n\nftime = true\n\nr_queue = 0\n\nn.times do |i|\n input = gets.chomp.split(\" \")\n\n times << input[0].to_i\n messages_count << input[1].to_i\n\n if ftime == false\n queue = queue - (input[0].to_i - times[i-1])\n end\n\n if queue < 0\n queue = 0\n end\n\n queue += input[1].to_i\n\n if queue > max_queue\n max_queue = queue\n end\n\n r_queue = queue\n\n if ftime\n ftime = false\n end\nend\n\n\ntime = times.last + r_queue\n\nputs \"#{time} #{max_queue}\"\n"}], "negative_code": [{"source_code": "n = gets.chomp.to_i\n\ntimes = []\nmessages_count = []\n\nmax_queue = 1\nqueue = 0\n\nr_queue = 0\n\nn.times do\n input = gets.chomp.split(\" \")\n\n times << input[0].to_i\n messages_count << input[1].to_i\n\n queue += input[1].to_i\n\n r_queue = queue\n\n if queue > max_queue\n max_queue = queue\n end\n\n queue -= input[0].to_i\n if queue < 0\n queue = 0\n end\nend\n\ntime = times.last + r_queue\n\nputs \"#{time} #{max_queue}\"\n"}, {"source_code": "n = gets.chomp.to_i\n\ntimes = []\nmessages_count = []\n\nmax_queue = 1\nqueue = 0\n\nn.times do\n input = gets.chomp.split(\" \")\n times << input[0].to_i\n messages_count << input[1].to_i\n queue += input[1].to_i\n\n if queue > max_queue\n max_queue = queue\n end\n\n queue -= 1\nend\n\ntime = times.first + messages_count.inject(:+)\n\nputs \"#{time} #{max_queue}\"\n"}, {"source_code": "n = gets.chomp.to_i\n\ntimes = []\nmessages_count = []\n\nmax_queue = 1\nqueue = 0\n\nr_queue = 0\n\nn.times do |i|\n input = gets.chomp.split(\" \")\n\n times << input[0].to_i\n messages_count << input[1].to_i\n\n queue += input[1].to_i\n\n r_queue = queue\n\n if queue > max_queue\n max_queue = queue\n end\n\n queue = queue - (input[0].to_i - times[i-1])\n\n if queue < 0\n queue = 0\n end\nend\n\n\ntime = times.last + r_queue\n\ntime -= 1 if times.size != 1\nmax_queue -= 1 if times.size != 1\n\nputs \"#{time} #{max_queue}\"\n"}], "src_uid": "608f8246bc6067e259898e8ed94db4c4"} {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nl=[]\nr=[]\nh={}\n(n+1).times do |i|\n h.delete_if do |k,v|\n if i==n||a[i]%k>0\n (v..i).each {|x|r[x]=i-1 if a[x]==k}\n true\n else\n false\n end\n end\n h[a[i]]||=i if a[i]\nend\n\n(n+1).times do |i|\n h.delete_if do |k,v|\n if i==n||a[n-1-i]%k>0\n ([n-1-i,0].max..v).each {|x|l[x]=n-i if a[x]==k}\n true\n else\n false\n end\n end\n h[a[n-1-i]]||=n-1-i if a[i]\nend\n\nb=n.times.map{|x|r[x]-l[x]}\nm=b.max\nc=n.times.map{|x| l[x]+1 if b[x]==m}.select{|x|x}.sort.uniq\nputs \"#{c.size} #{m}\"\nputs c.join(' ')\n", "positive_code": [{"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nll = Array.new(n)\nrr = Array.new(n)\n\ni = 0\nloop do\n r = i+1\n while r < n\n break if a[r] % a[i] != 0\n r += 1\n end\n rr[i] = r-1\n break if r == n\n i = r\nend\n\ni = n-1\nloop do\n l = i-1\n while l >= 0\n break if a[l] % a[i] != 0\n l -= 1\n end\n i.downto(l+1) do |j|\n ll[j] = l+1\n end\n break if l < 0\n i = l\nend\n\nbest = 0\nn.times do |i|\n best = [best, rr[i]-ll[i]].max if rr[i]\nend\n\nans = []\nn.times do |i|\n if rr[i] and rr[i]-ll[i] == best\n ans << ll[i]+1\n end\nend\n\nputs \"#{ans.size} #{best}\"\nputs ans.join(' ')\n# p ll, rr\n\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\ndef f a,n,d\n h={}\n b=[]\n (n+1).times do |i|\n j=d>0 ? n-i-1 : i\n h.delete_if do |k,v|\n if i==n||a[j]%k>0\n p=v>j ? j : v\n q=v>j ? v : j\n p=0 if p<0\n q=n-1 if q==n\n (p..q).each {|x|b[x]=j+d if a[x]==k}\n true\n else\n false\n end\n end\n h[a[j]]||=j\n end\n b\nend\nr=f(a,n,-1)\nl=f(a,n,1)\n\nb=n.times.map{|x|r[x]-l[x]}\nm=b.max\nc=n.times.map{|x| l[x]+1 if b[x]==m}.select{|x|x}.sort.uniq\nputs \"#{c.size} #{m}\"\nputs c.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nl=[]\nr=[]\nh={}\nn.times do |i|\n h.delete_if do |k,v|\n if a[i]%k>0\n (v..i).each {|x|r[x]=i-1 if a[x]==k}\n true\n else\n false\n end\n end\n h[a[i]]||=i\nend\n\nh.delete_if do |k,v|\n (v..n-1).each {|x|r[x]=n-1 if a[x]==k}\n true\nend\n\nn.times do |i|\n h.delete_if do |k,v|\n if a[n-1-i]%k>0\n (n-1-i..v).each {|x|l[x]=n-i if a[x]==k}\n true\n else\n false\n end\n end\n h[a[n-1-i]]||=n-1-i\nend\n\nh.delete_if do |k,v|\n (0..v).each {|x|l[x]=0 if a[x]==k}\n true\nend\n\nb=n.times.map{|x|r[x]-l[x]}\nm=b.max\nc=n.times.map{|x| l[x]+1 if b[x]==m}.select{|x|x}.sort.uniq\nputs \"#{c.size} #{m}\"\nputs c.join(' ')\n"}], "negative_code": [{"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nl=[]\nr=[]\nh={}\nn.times do |i|\n h.delete_if do |k,v|\n if a[i]%k>0\n (v..i).each {|x|r[x]=i-1 if a[x]==k}\n true\n else\n false\n end\n end\n h[a[i]]||=i\nend\n\nh.delete_if do |k,v|\n (v..n-1).each {|x|r[x]=n-1 if a[x]==k}\n true\nend\n\nn.times do |i|\n h.delete_if do |k,v|\n if a[n-1-i]%k>0\n (n-1-i..v).each {|x|l[x]=n-i if a[x]==k}\n true\n else\n false\n end\n end\n h[a[n-1-i]]||=n-1-i\nend\n\nh.delete_if do |k,v|\n (0..v).each {|x|l[x]=0 if a[x]==k}\n true\nend\n\nb=n.times.map{|x|r[x]-l[x]}\nm=b.max\nputs \"#{b.count(m)} #{m}\"\nn.times.map{|x| print \"#{l[x]+1} \" if b[x]==m}\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nl=[]\nr=[]\nh={}\nn.times do |i|\n h.delete_if do |k,v|\n if a[i]%k>0\n (v..i).each {|x|r[x]=i-1 if a[x]==k}\n true\n else\n false\n end\n end\n h[a[i]]||=i\nend\n\nh.delete_if do |k,v|\n (v..n-1).each {|x|r[x]=n-1 if a[x]==k}\n true\nend\n\nn.times do |i|\n h.delete_if do |k,v|\n if a[n-1-i]%k>0\n (n-1-i..v).each {|x|l[x]=n-i if a[x]==k}\n true\n else\n false\n end\n end\n h[a[n-1-i]]||=n-1-i\nend\n\nh.delete_if do |k,v|\n (0..v).each {|x|l[x]=0 if a[x]==k}\n true\nend\n\nb=n.times.map{|x|r[x]-l[x]}\nm=b.max\nputs \"#{b.count(m)} #{m}\"\nputs n.times.map{|x| l[x]+1 if b[x]==m}.select{|x|x}.sort\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\ndef f a,n,d\n h={}\n b=[]\n (n+1).times do |i|\n j=d>0 ? n-i-1 : i\n h.delete_if do |k,v|\n if i==n||a[j]%k>0\n ([[v,j].min,0].max..[[v,j].max,n-1].min).each {|x|b[x]=j+d if a[x]==k}\n true\n else\n false\n end\n end\n h[a[j]]||=j\n end\n b\nend\nr=f(a,n,1)\nl=f(a,n,-1)\n\nb=n.times.map{|x|r[x]-l[x]}\nm=b.max\nc=n.times.map{|x| l[x]+1 if b[x]==m}.select{|x|x}.sort.uniq\nputs \"#{c.size} #{m}\"\nputs c.join(' ')\n"}, {"source_code": "n=gets.to_i\na=gets.split.map(&:to_i)\nl=[]\nr=[]\nh={}\nn.times do |i|\n h.delete_if do |k,v|\n if a[i]%k>0\n (v..i).each {|x|r[x]=i-1 if a[x]==k}\n true\n else\n false\n end\n end\n h[a[i]]||=i\nend\n\nh.delete_if do |k,v|\n (v..n-1).each {|x|r[x]=n-1 if a[x]==k}\n true\nend\n\nn.times do |i|\n h.delete_if do |k,v|\n if a[n-1-i]%k>0\n (n-1-i..v).each {|x|l[x]=n-i if a[x]==k}\n true\n else\n false\n end\n end\n h[a[n-1-i]]||=n-1-i\nend\n\nh.delete_if do |k,v|\n (0..v).each {|x|l[x]=0 if a[x]==k}\n true\nend\n\nb=n.times.map{|x|r[x]-l[x]}\nm=b.max\nputs \"#{b.count(m)} #{m}\"\nputs n.times.map{|x| l[x]+1 if b[x]==m}.select{|x|x}.sort.uniq\n"}], "src_uid": "da517ae908ba466da8ded87cec12a9fa"} {"source_code": "n = gets.to_i\n(0...n).each{|x|\n puts '*' * ((n - 1) / 2 - x).abs + 'D' * (n - ((n - 1) - 2 * x).abs) + '*' * ((n - 1) / 2 - x).abs\n}", "positive_code": [{"source_code": "n = gets.to_i\nmax_stars = (n - 1) / 2\ncounter = 0\nn.times do |iteration|\n counter = (iteration - max_stars).abs\n puts \"*\" * counter + \"D\" * (n - 2 * counter).abs + \"*\" * counter\nend\n"}, {"source_code": "n = gets.to_i\n\nn.times do |i|\n aaa = n - (n/2 - i).abs * 2\n bbb = (n-aaa)/2\n puts \"*\" * bbb + \"D\" * aaa + \"*\" * bbb\nend"}, {"source_code": "n=gets.to_i\n\nn2=n/2\narr=[]\nn2.times{|i|\n\ts=i-n2\n\td=1\n\tstr=\"\"\n\tn.times{\n\t\tif 0<=s then\n\t\t\tstr<<\"D\"\n\t\telse\n\t\t\tstr<<\"*\"\n\t\tend\n\t\ts=s+d\n\t\tif s==i then\n\t\t\td=-1\n\t\tend\n\t}\n\tarr< q\n t = n - i + 1\n else\n t = i\n end\n r = q - t + 1\n r.times do\n print \"*\"\n end\n (t * 2 - 1).times do\n print \"D\"\n end\n r.times do\n print \"*\"\n end \n puts \"\"\nend "}, {"source_code": "n = gets.to_i\n(0...n).each { |i|\n a = (n / 2 - i).abs\n b = n - a * 2\n puts '*' * a + 'D' * b + '*' * a\n}"}, {"source_code": "n = gets.to_i\na = Array.new(n)\ni = Array.new(n / 2, \"*\")\nj = [\"D\"]\nfor k in 0...n / 2 do\n a[k] = a[n - 1 - k] = (i + j + i).join\n i.pop\n 2.times do\n j.push \"D\"\n end\nend\n\na[n / 2] = Array.new(n, \"D\").join\nputs a\n"}, {"source_code": "n = gets.to_i\nn.times do |i|\n nasterisks, nds = (n/2 - i).abs\n nds = n - nasterisks*2\n nasterisks.times { print '*' }\n nds.times { print 'D' }\n nasterisks.times { print '*' }\n puts\nend\n"}, {"source_code": "n=gets.to_i\n\ndiamond=Array.new(n){Array.new(n) {'*'}}\nfor i in 0..(n/2) do\n for j in (n/2-i)..(n/2+i) do\n diamond[i][j]='D'\n diamond[n-i-1][j]='D'\n end\nend\n\nfor i in 0...n do \n for j in 0...n do\n print diamond[i][j]\n end\n puts ''\nend"}, {"source_code": "n = gets.to_i\n\nstr = \"\"\n\ni = 1\nwhile i < n\n stars = (n - i) / 2\n\n str += ('*' * stars)\n str += ('D' * i)\n str += ('*' * stars)\n str += \"\\n\"\n\n i += 2\nend\n\nstr += ('D' * n) + \"\\n\"\n\ni -= 2\nwhile i > 0\n stars = (n - i) / 2\n\n str += ('*' * stars)\n str += ('D' * i)\n str += ('*' * stars)\n str += \"\\n\"\n\n i -= 2\nend\n\nputs str"}, {"source_code": "n = gets.to_i\nfor i in 0 ... n\n puts (0 ... n).map{|j|(2*i-n+1).abs+(2*j-n+1).abs<=n-1?\"D\":\"*\"}*''\nend\n"}, {"source_code": "size = gets.chomp.to_i\n\n(1..(size/2 + 1)).each do |i|\n\tdn = (2 * i - 1)\n\tprint \"*\" * ((size - dn) / 2)\n\tprint \"D\" * dn\n\tprint \"*\" * ((size - dn) / 2)\n\tputs \"\"\nend\n\n((size/2 + 2)..size).each do |j|\n\ti = size - j + 1\n\tdn = (2 * i - 1)\n\tprint \"*\" * ((size - dn) / 2)\n\tprint \"D\" * dn\n\tprint \"*\" * ((size - dn) / 2)\n\tputs \"\"\nend\n"}, {"source_code": "\nn=gets.to_i\n(0...n).each {|x| puts '*' * ((n-1)/2 - x).abs + 'D' * (n - ((n-1) - 2*x).abs) + '*' * ((n-1)/2 - x).abs}\n\n"}, {"source_code": "n = gets.chomp.to_i\nstart = (n / 2) + 1\ndNum = 0\n\n(0...n).each do |row|\n\tif row <= n / 2\n\t\tdNum = 2 * (row + 1) - 1\n\t\tstart -= 1\n\telse\n\t\tdNum = (-2 * row + (2 * n - 1))\n\t\tstart += 1 if row > n / 2\n\tend\n\n\t(0...n).each do |col|\n\t\tif col >= start && dNum > 0\n\t\t\tprint 'D'\n\t\t\tdNum -= 1\n\t\telse\n\t\t\tprint '*'\n\t\tend\n\tend\n\n\tputs ''\nend"}, {"source_code": "class Crystal\n def initialize(size)\n @size = size\n end\n\n def draw_diamond\n @size.times do |i|\n if i <= @size / 2\n cut_size = @size / 2 - i\n else\n cut_size = i - @size / 2\n end\n puts((\"*\" * cut_size ) +\n (\"D\" * (@size - cut_size * 2)) +\n (\"*\" * cut_size ))\n end\n end\nend\n\nCrystal.new(gets.to_i).draw_diamond\n"}, {"source_code": "#!/usr/bin/ruby\nn=gets.to_i\n(n/2).downto(1){|i|\n\tputs '*'*i+'D'*(n-i*2)+'*'*i\n}\nputs 'D'*n\n1.upto(n/2){|i|\n\tputs '*'*i+'D'*(n-i*2)+'*'*i\n}"}, {"source_code": "#!/usr/bin/env ruby\n\nn = gets.to_i\n\narr = []\n(n/2).times do |r|\n l = (\"D\" * (r+1)).rjust((n+1)/2, \"*\")\n arr << l + l.reverse[1..-1]\nend\n\nputs arr\nputs \"D\" * n\nputs arr.reverse\n"}, {"source_code": "n = gets.to_i\n\ni = 1\nwhile i<=n\n t = (n-i)/2\n for j in 1..t\n print \"*\"\n end\n for j in 1..i\n print \"D\"\n end\n for j in 1..t\n print \"*\"\n end\n puts \"\"\n i+=2\nend\ni = n-2\nwhile i>=1\n t = (n-i)/2\n for j in 1..t\n print \"*\"\n end\n for j in 1..i\n print \"D\"\n end\n for j in 1..t\n print \"*\"\n end\n puts \"\"\n i-=2\nend"}, {"source_code": "class A\n\n def run\n n = $stdin.gets.to_i\n (1..n).each do |i|\n pad = (n - 2 * i + 1).abs / 2\n fill = n - pad * 2\n puts '*' * pad + 'D' * fill + '*' * pad\n end\n end\n\nend\n\nA.new.run if __FILE__ == $0"}, {"source_code": "n = gets.to_i\n(0...n).each do |i|\n a = (n / 2 - i).abs\n b = n - a * 2\n puts '*' * a + 'D' * b + '*' * a\nend"}, {"source_code": "n = gets.to_i\n\nsize = 1\n\nwhile size <= n\n ((n - size) / 2).times do print '*' end\n size.times do print 'D' end\n ((n - size) / 2).times do print '*' end\n puts ''\n size += 2\nend\n\nsize -= 2\n\nwhile size != 1\n size -= 2\n ((n - size) / 2).times do print '*' end\n size.times do print 'D' end\n ((n - size) / 2).times do print '*' end\n puts ''\nend\n"}], "negative_code": [{"source_code": "n = gets.to_i\nmax_stars = (n / 3.0).ceil\ncounter = 0\nn.times do |iteration|\n counter = (iteration - max_stars).abs\n puts \"*\" * counter + \"D\" * (n - 2 * counter).abs + \"*\" * counter\nend\n"}], "src_uid": "a003d645999934c255f7b05d8494fa40"} {"source_code": "#require \"prime\"\n#input of int(split by space)\ndef get_i()\n return gets.chomp.split(\" \").map(&:to_i)\nend\n#input of float(split by space)\ndef get_f()\n return gets.chomp.split(\" \").map(&:to_f)\nend\n#input of string(split by space)\ndef get()\n return gets.chomp.split(\" \")\nend\n#input of string(split per one character)\ndef get_nsp()\n return gets.chomp.split(\"\")\nend\n#yes or no decision\ndef yn_judge(bool,y=\"Yes\",n=\"No\")\n return bool ? y : n \nend\n#output grid(two dimensional array)\ndef puts_grid(grid,join_char=\"\")\n grid.each do|line|\n puts line.join(join_char)\n end\nend\n\nDirxy4=[[1,0],[-1,0],[0,1],[0,-1]]\nDirxy8=[[1,0],[1,-1],[1,1],[0,-1],[0,1],[-1,0],[-1,-1],[-1,1]]\n\nINF=Float::INFINITY\n\n#MOD=998_244_353\nMOD=10**9+7\n\nT=gets.to_i\nT.times do\n n=gets.to_i\n s=get_i\n f=get_i\n ans=[]\n prev=-1\n n.times do |i|\n ans< n}\n puts \"Impossible\"\nelse\n puts s.scan(/.{,#{n-1}}[.?!] ?/).size\nend\n", "positive_code": [{"source_code": "def min2(x, y)\n if x < y then return x\n else return y\n end\nend\n\ndef min3(x, y, z)\n if x < y then\n if z < x then return z\n else return x\n end\n else\n if z < y then return z\n else return y\n end\n end\nend\n\ndef min(x, y, z)\n if x && y && z then return min3(x,y,z)\n elsif x && y then return min2(x,y)\n elsif x && z then return min2(x,z)\n elsif y && z then return min2(y,z)\n elsif x then return x\n elsif y then return y\n else return z\n end\nend\n\nn = gets.to_i\ns = gets.chomp\ns = s.gsub(\"..\", \".\").gsub(\"!!\", \"!\").gsub(\"??\", \"?\")\nresult = \"\"\nk = []\ndot = s.index(\".\")\nask = s.index(\"?\")\nexp = s.index(\"!\")\nk[0] = min(dot, ask, exp)\ni = 0\nwhile k[i] && k[i] != s.size-1 do\n i += 1\n dot = s.index(\".\", k[i-1] + 1) \n ask = s.index(\"?\", k[i-1] + 1) \n exp = s.index(\"!\", k[i-1] + 1)\n k[i] = min(dot, ask, exp)\nend\nk = k.compact\nk = k.sort\nstr = []\nstr[0] = s[0..k[0]]\nif str[0].size > n\n then result = \"Impossible\"\nelse\n i = 1\n while i < k.size do \n str[i] = s[k[i-1]+1..k[i]]\n if str[i].start_with? \" \" then \n str[i] = str[i][1..-1]\n end\n if str[i].size > n then \n result = \"Impossible\"\n end \n i += 1\n end\nend\nif result != \"Impossible\" then\n if s.size < n then \n result = 1\n else\n result = 0\n i = 0\n while i < k.size do\n sum = str[i].size\n while i + 1 < k.size && sum + str[i+1].size + 1 <= n do\n i += 1\n sum += str[i].size + 1\n end\n i += 1\n result += 1\n end \n end\nend\nputs \"#{result}\""}, {"source_code": "n = gets.to_i\ns = gets.scan(/.*?[\\.?!]/).map{|_| _.strip.size}\nx, y = 0, 0\ns.each do |_|\n\tif _ > n\n\t\tputs :Impossible\n\t\texit\n\telsif x == 0\n\t\tx = _\n\telse\n\t\tx += 1 + _\n\t\tif x > n\n\t\t\tx = _\n\t\t\ty += 1\n\t\tend\n\tend\nend\nif x > 0\n\ty += 1\nend\np y\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\na = s.split(/[.?!] ?/)\nif a.any?{|x|x.size > n}\n puts \"Impossible\"\nelse\n p s.scan(/.{,#{n-1}}[.?!] ?/).size\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\na = s.split(/[.?!] ?/)\nif a.any?{|x|x.size > n}\n puts \"Impossible\"\nelse\n p s.scan(/.{,#{n-1}}[.?!] ?/).size\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\na = s.split(/[.?!] ?/)\nif a.any?{|x|x.size > n}\n puts \"Impossible\"\nelse\n p s.scan(/.{,#{n-1}}[.?!] ?/).size\nend"}, {"source_code": "n = gets.to_i\ns = gets.strip\na = s.split(/[.?!] ?/)\nif a.any?{|x|x.size > n}\n puts \"Impossible\"\nelse\n p s.scan(/.{,#{n-1}}[.?!] ?/).size\nend"}, {"source_code": "msgSize, txt=gets.to_i, [gets]\nwhile txt.last.size>msgSize\n if (idx=txt.last[0, msgSize].rindex(/[?.!]/))==nil\n print \"Impossible\"\n exit\n else\n txt< n}\n puts \"Impossible\"\nelse\n p s.scan(/.{,#{n-1}}[.?!] ?/).size\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\na = s.split(/[.?!] ?/)\nif a.any?{|x|x.size > n}\n puts \"Impossible\"\nelse\n p s.scan(/.{,#{n-1}}[.?!] ?/).size\nend\n"}, {"source_code": "N = gets.to_i\nstr = gets.chomp\n\ncount = 1\ncurrent = -1\n\nsentences = str.split(/[.?!]/).map{|e| e.gsub(/^ /, '')}\n\n#p sentences\ns = \"\"\nsentences.each {|e|\n# print current \n \n e += \".\"\n if e.size > N\n puts \"Impossible\"\n exit\n end\n current += e.size + 1\n s += \" \" + e\n# p [e, current]\n if current > N \n# p e\n count += 1\n current = e.size # check! 10 ab ab. ab. abcd abcd.\n s = e\n end\n}\nputs count\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\na = s.split(/[.?!] ?/)\nif a.any?{|x|x.size > n}\n puts \"Impossible\"\nelse\n p s.scan(/.{,#{n-1}}[.?!] ?/).size\nend"}, {"source_code": "n = gets.to_i\ns = gets.strip\nif s.split(/[.?!] ?/).any? { |t| t.size >= n }\n puts :Impossible\nelse\n puts s.scan(/.{,#{n - 1}}[.?!] ?/).size\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\na = s.split(/[.?!] ?/)\nif a.any?{|x|x.size > n}\n puts \"Impossible\"\nelse\n p s.scan(/.{,#{n-1}}[.?!] ?/).size\nend\n"}, {"source_code": "n = STDIN.gets.to_i\ntext = STDIN.gets.strip\nsentences = text.split(/[?|.|!]/)\nif !!sentences.find{|s| s.strip.length+1 > n}\n puts \"Impossible\" \n exit\nend\nleft = n\ncount = 1\nwhile sentence = sentences.shift\n len = sentence.length + 1\n if left >= len\n #puts sentence\n left -= len\n else\n #puts \"new #{sentence}\"\n count += 1\n left = n - (sentence.strip.length + 1)\n end\nend\nputs count\n"}, {"source_code": "#!/usr/bin/env ruby\n\nmax_size = gets.to_i\ntext = gets.chomp\n\nregexp = /[a-zA-Z]+(\\s[a-zA-Z]+)*[.?!]+\\s?/\ncount = 0\ntotal_size = 0\nstr = \"\"\nloop do\n if text.sub!(regexp, '').nil? || (str = $&).strip.size > max_size\n puts \"Impossible\"\n exit\n end\n if total_size + str.size <= max_size\n total_size += str.size\n else\n if total_size + str.strip.size <= max_size\n total_size = 0\n count += 1\n else\n total_size = str.size\n count += 1\n end\n end\n \n if text == \"\"\n puts count + 1\n exit\n end\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\na = s.split(/[.?!] ?/)\nif a.any?{|x|x.size > n}\n puts \"Impossible\"\nelse\n p s.scan(/.{,#{n-1}}[.?!] ?/).size\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\na = s.split(/[.?!] ?/)\nif a.any?{|x|x.size > n}\n puts \"Impossible\"\nelse\n p s.scan(/.{,#{n-1}}[.?!] ?/).size\nend\n"}, {"source_code": "n = gets.to_i\ns = gets.strip\na = s.split(/[.?!] ?/)\nif a.any?{|x|x.size > n}\n puts \"Impossible\"\nelse\n p s.scan(/.{,#{n-1}}[.?!] ?/).size\nend\n"}], "negative_code": [{"source_code": "def min2(x, y)\n if x < y then return x\n else return y\n end\nend\n\ndef min3(x, y, z)\n if x < y then\n if z < x then return z\n else return x\n end\n else\n if z < y then return z\n else return y\n end\n end\nend\n\ndef min(x, y, z)\n if x && y && z then return min3(x,y,z)\n elsif x && y then return min2(x,y)\n elsif x && z then return min2(x,z)\n elsif y && z then return min2(y,z)\n elsif x then return x\n elsif y then return y\n else return z\n end\nend\n\nn = gets.to_i\ns = gets.chomp\ns = s.gsub(\"..\", \".\").gsub(\"!!\", \"!\").gsub(\"??\", \"?\")\nresult = \"\"\nk = []\ndot = s.index(\".\")\nask = s.index(\"?\")\nexp = s.index(\"!\")\nk[0] = min(dot, ask, exp)\ni = 0\nwhile k[i] && k[i] != s.size-1 do\n i += 1\n dot = s.index(\".\", k[i-1] + 1) \n ask = s.index(\"?\", k[i-1] + 1) \n exp = s.index(\"!\", k[i-1] + 1)\n k[i] = min(dot, ask, exp)\nend\nk = k.compact\nk = k.sort\nstr = []\nstr[0] = s[0..k[0]]\nif str[0].size > n\n then result = \"Impossible\"\nelse\n i = 1\n while i < k.size do \n str[i] = s[k[i-1]+1..k[i]]\n if str[i].start_with? \" \" then \n str[i] = str[i][1..-1]\n end\n if str[i].size > n then \n result = \"Impossible\"\n end \n i += 1\n end\nend\nif result != \"Impossible\" then\n if s.size < n then \n result = 1\n else\n result = 0\n i = 0\n while i < k.size do\n sum = str[i].size\n while i + 1 < k.size && sum + str[i+1].size + 1 < n do\n i += 1\n sum += str[i].size + 1\n end\n i += 1\n result += 1\n end \n end\nend\nputs \"#{result}\""}, {"source_code": "def min2(x, y)\n if x < y then return x\n else return y\n end\nend\n\ndef min3(x, y, z)\n if x < y then\n if z < x then return z\n else return x\n end\n else\n if z < y then return z\n else return y\n end\n end\nend\n\ndef min(x, y, z)\n if x && y && z then return min3(x,y,z)\n elsif x && y then return min2(x,y)\n elsif x && z then return min2(x,z)\n elsif y && z then return min2(y,z)\n elsif x then return x\n elsif y then return y\n else return z\n end\nend\n\nn = gets.to_i\ns = gets.chomp\nresult = \"\"\nk = []\ndot = s.index(\".\")\nask = s.index(\"?\")\nexp = s.index(\"!\")\nk[0] = min(dot, ask, exp)\nst = s[k[0]+1..-1]\ni = 0\nwhile k[i] && k[i] != s.size-1 do\n i += 1\n if st.include? \".\" then\n k[i] = st.index(\".\") + k[i-1] + 1\n elsif st.include? \"?\" then\n k[i] = st.index(\"?\") + k[i-1] + 1\n else\n k[i] = st.index(\"!\")\n if k[i] then\n k[i] += k[i-1] + 1\n end\n end\n if k[i] then\n st = s[k[i]+1..-1]\n end\nend\nk = k.compact\nk = k.sort\nstr = []\nstr[0] = s[0..k[0]]\nif str[0].size > n\n then result = \"Impossible\"\nelse\n i = 1\n while i < k.size do \n str[i] = s[k[i-1]+1..k[i]]\n if str[i].start_with? \" \" then \n str[i] = str[i][1..-1]\n end\n if str[i].size > n then \n result = \"Impossible\"\n end \n i += 1\n end\nend\nif result != \"Impossible\" then\n if s.size < n then \n result = 1\n else\n result = 0\n i = 0\n while i < k.size do\n sum = k[i]\n while i + 1 < k.size && sum + k[i+1] + 1 < n do\n i += 1\n sum += k[i] + 1\n end\n i += 1\n result += 1\n end \n end\nend\nputs \"#{result}\""}, {"source_code": "def min2(x, y)\n if x < y then return x\n else return y\n end\nend\n\ndef min3(x, y, z)\n if x < y then\n if z < x then return z\n else return x\n end\n else\n if z < y then return z\n else return y\n end\n end\nend\n\ndef min(x, y, z)\n if x && y && z then return min3(x,y,z)\n elsif x && y then return min2(x,y)\n elsif x && z then return min2(x,z)\n elsif y && z then return min2(y,z)\n elsif x then return x\n elsif y then return y\n else return z\n end\nend\n\nn = gets.to_i\ns = gets.chomp\ns = s.gsub(\"..\", \".\").gsub(\"!!\", \"!\").gsub(\"??\", \"?\")\nresult = \"\"\nk = []\ndot = s.index(\".\")\nask = s.index(\"?\")\nexp = s.index(\"!\")\nk[0] = min(dot, ask, exp)\ni = 0\nwhile k[i] && k[i] != s.size-1 do\n i += 1\n dot = s.index(\".\", k[i-1] + 1) \n ask = s.index(\"?\", k[i-1] + 1) \n exp = s.index(\"!\", k[i-1] + 1)\n k[i] = min(dot, ask, exp)\nend\nk = k.compact\nk = k.sort\nstr = []\nstr[0] = s[0..k[0]]\nif str[0].size > n\n then result = \"Impossible\"\nelse\n i = 1\n while i < k.size do \n str[i] = s[k[i-1]+1..k[i]]\n if str[i].start_with? \" \" then \n str[i] = str[i][1..-1]\n end\n if str[i].size > n then \n result = \"Impossible\"\n end \n i += 1\n end\nend\nif result != \"Impossible\" then\n if s.size < n then \n result = 1\n else\n result = 0\n i = 0\n while i < k.size do\n sum = str[i].size\n while i + 1 < k.size && sum + str[i+1].size + 1 <= n do\n i += 1\n sum += str[i].size + 1\n end\n i += 1\n result += 1\n end \n end\nend\np k\np str\nputs \"#{result}\""}, {"source_code": "msgSize, txt=gets.to_i, [gets]\nwhile txt.last.size>msgSize\n if (idx=txt.last[0, msgSize].rindex(/[?.!]/))==nil\n print \"Impossible\"\n exit\n else\n txt< N\n puts \"Impossible\"\n exit\n end\n current += e.size + 1\n s += \" \" + e\n if current - 1 > N\n# p e\n count += 1\n current = e.size # check! 10 ab ab. ab. abcd abcd.\n s = e\n end\n}\nputs count\n"}, {"source_code": "n = STDIN.gets.to_i\ntext = STDIN.gets.strip\nsentences = text.split(/[?|.|!]/)\nif !!sentences.find{|s| s.length+1 > n}\n puts \"Impossible\" \n exit\nend\nleft = n\ncount = 1\nwhile sentence = sentences.shift\n len = sentence.length + 1\n if left > len\n left -= len\n else\n count += 1\n left = n - (sentence.strip.length + 1)\n end\nend\nputs count\n"}, {"source_code": "n = STDIN.gets.to_i\ntext = STDIN.gets.strip\nsentences = text.split(/[?|.|!]/)\nif !!sentences.find{|s| s.length+1 > n}\n puts \"Impossible\" \n exit\nend\nleft = n\ncount = 1\nwhile sentence = sentences.shift\n len = sentence.length + 1\n if left >= len\n puts sentence\n left -= len\n else\n puts \"new #{sentence}\"\n count += 1\n left = n - (sentence.strip.length + 1)\n end\nend\nputs count\n"}, {"source_code": "n = STDIN.gets.to_i\ntext = STDIN.gets.strip\nsentences = text.split(/[?|.|!]/)\nif !!sentences.find{|s| s.length+1 > n}\n puts \"Impossible\" \n exit\nend\nleft = n\ncount = 1\nwhile sentence = sentences.shift\n len = sentence.length + 1\n if left >= len\n #puts sentence\n left -= len\n else\n #puts \"new #{sentence}\"\n count += 1\n left = n - (sentence.strip.length + 1)\n end\nend\nputs count\n"}, {"source_code": "#!/usr/bin/env ruby\n\nmax_size = gets.to_i\ntext = gets.chomp\n\nregexp = /\\s?[a-zA-Z]+(\\s[a-zA-Z]+)*[.?!]+(?=\\s?)/\ncount = 0\ntotal_size = 0\nloop do\n text.strip!\n size = 0\n if text.sub!(regexp){|s| size = s.size; nil}.nil? || size > max_size\n puts \"Impossible\"\n exit\n end\n if total_size + size <= max_size\n total_size += size\n else\n count += 1\n total_size = size\n end\n \n if text == \"\"\n puts count + 1\n exit\n end\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nmax_size = gets.to_i\ntext = gets.chomp\n\nregexp = /[a-zA-Z]+(\\s[a-zA-Z]+)*[.?!]\\s?/\ncount = 0\nloop do\n size = 0\n res = text.sub!(regexp){|s| size = s.size; nil}\n if res.nil? || size > max_size\n puts \"Impossible\"\n exit\n end\n count += 1\n if text == \"\"\n puts count\n exit\n end\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nmax_size = gets.to_i\ntext = gets.chomp\n\nregexp = /\\s?[a-zA-Z]+(\\s[a-zA-Z]+)*[.?!]+(?=\\s?)/\ncount = 0\ntotal_size = 0\nloop do\n size = 0\n if text.sub!(regexp){|s| size = s.size; nil}.nil? || size > max_size\n puts \"Impossible\"\n exit\n end\n if total_size + size <= max_size\n total_size += size\n else\n count += 1\n total_size = size\n end\n \n if text == \"\"\n puts count + 1\n exit\n end\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nmax_size = gets.to_i\ntext = gets.chomp\n\nregexp = /[a-zA-Z]+(\\s[a-zA-Z]+)*[.?!]+\\s?/\ncount = 0\ntotal_size = 0\nloop do\n size = 0\n if text.sub!(regexp){|s| size = s.size; nil}.nil? || size > max_size\n puts \"Impossible\"\n exit\n end\n if total_size + size < max_size\n total_size += size\n else\n count += 1\n total_size = size\n end\n \n if text == \"\"\n puts count + 1\n exit\n end\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nmax_size = gets.to_i\ntext = gets.chomp\n\nregexp = /[a-zA-Z]+(\\s[a-zA-Z]+)*[.?!]+(?=\\s?)/\ncount = 0\ntotal_size = 0\nloop do\n size = 0\n if text.sub!(regexp){|s| size = s.size; nil}.nil? || size > max_size\n puts \"Impossible\"\n exit\n end\n if total_size + size <= max_size\n total_size += size\n else\n count += 1\n total_size = size\n end\n \n if text == \"\"\n puts count + 1\n exit\n end\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nmax_size = gets.to_i\ntext = gets.chomp\n\nregexp = /[a-zA-Z]+(\\s[a-zA-Z]+)*[.?!]+\\s?/\ncount = 0\ntotal_size = 0\nloop do\n size = 0\n if text.sub!(regexp){|s| size = s.size; nil}.nil? || size > max_size\n puts \"Impossible\"\n exit\n end\n if total_size + size <= max_size\n total_size += size\n else\n count += 1\n total_size = size\n end\n \n if text == \"\"\n puts count + 1\n exit\n end\nend\n"}, {"source_code": "#!/usr/bin/env ruby\n\nmax_size = gets.to_i\ntext = gets.chomp\n\nregexp = /\\s?[a-zA-Z]+(\\s[a-zA-Z]+)*[.?!]+(?=\\s?)/\ncount = 0\ntotal_size = 0\nloop do\n text.strip!\n size = 0\n if text.sub!(regexp){|s| size = s.size; nil}.nil? || size > max_size\n puts \"Impossible\"\n exit\n end\n if total_size + size <= max_size\n total_size += size\n else\n count += 1\n total_size = size\n end\n \n if text == \"\"\n puts count + 1\n exit\n end\nend\n"}, {"source_code": "n = gets.to_i\ntext = gets.chomp\nx = n\nret = 0\nimpossible = false\ntext.split(/[\\!\\.\\?]/).each do |sentence|\n if sentence.size + 1 > n\n impossible = true\n break\n end\n ret += 1\nend\n\nif impossible\n puts \"Impossible\"\nelse\n puts ret\nend"}], "src_uid": "12b64f77fc9dd44a7e0287ff0a716a6a"} {"source_code": "n,m,c = gets.split.map{|e| e.to_i}\na = gets.split.map{|e| e.to_i}\nb = gets.split.map{|e| e.to_i}\nch = []\nch[0]=0\nr = []\nn-=1\nm-=1\nfor i in 0..m\n ch[i+1]=(ch[i]+b[i]).modulo(c) \nend\n\nfor i in 0..n\n z = [m+1, i+1].min\n k = [0, m-n+i].max\n r[i] = (a[i]+ch[z]-ch[k]).modulo(c)\nend\nputs r.join(' ')\n", "positive_code": [{"source_code": "n,m,c = gets.split.map{|e| e.to_i}\na = gets.split.map{|e| e.to_i}\nb = gets.split.map{|e| e.to_i}\nch = []\nch[0]=0\nr = []\nn-=1\nm-=1\nfor i in 0..m\n ch[i+1]=(ch[i]+b[i]).modulo(c) \nend\n\nfor i in 0..n\n z = [m+1, i+1].min\n k = [0, m-n+i].max\n r[i] = (a[i]+ch[z]-ch[k]).modulo(c)\nend\nputs r.join(' ')\n"}], "negative_code": [{"source_code": "n,m,c = gets.split.map{|e| e.to_i}\na = gets.split.map{|e| e.to_i}\nb = gets.split.map{|e| e.to_i}\nch = []\nch[0] = b[0]\nr = []\nn-=1\nm-=1\nfor i in 1..m\n ch[i]=(ch[i-1]+b[i]).modulo(c) \nend\n\nr[0]=(a[0]+b[0]).modulo(c)\nr[n]=(a[n]+b[m]).modulo(c)\nfor i in 1..n-1\n if i>=m && n-i>=m\n r[i] = (a[i]+ch[m]).modulo(c)\n next\n end\n if i masha_mod\n swap = price - sasha_mod\n sasha += swap\n masha -= swap\nelse\n swap = price - masha_mod\n masha += swap\n sasha -= swap\nend\n\nmax_temp = (sasha / price) + (masha / price)\nmax_temp = 0 if max_temp.eql?(nil)\n\nif max_temp > max\n puts \"#{max_temp} #{swap}\"\nelse\n puts \"#{max} 0\"\nend\n", "positive_code": [{"source_code": "x,y,z = gets.split.map(&:to_i)\na = (x+y)/z\nb = x%z+y%z >= z ? [z-x%z,z-y%z].min : 0\nputs \"#{a} #{b}\"\n"}, {"source_code": "x, y, z = gets.split.map(&:to_i)\n\na = (x/z) + (y/z)\nam = x % z\nbm = y % z\naa = (am + bm)/z\nif aa > 0\n b = [z-am, z-bm].min\nelse\n b = 0\nend\na += aa\nputs \"#{a} #{b}\""}, {"source_code": "x,y,z = gets.split.map(&:to_i)\nif x/z+y/z < (x+y)/z\n puts \"#{(x+y)/z} #{z-[x%z,y%z].max}\"\nelse\n puts \"#{x/z+y/z} 0\"\nend"}, {"source_code": "def prog()\n str = gets\n x,y,z = str.split(\" \").map(&:to_i)\n calc(x,y,z)\nend\n\ndef calc(x,y,z)\n min = 0\n num = 0\n if (x%z + y%z >= z)\n max = (x%z > y%z) ? (x%z) : (y%z)\n min = z - max\n num = 1\n end\n puts \"#{x/z + y/z + num} #{min}\"\nend\n\nprog()"}, {"source_code": "x, y, z = gets.split(' ').map(&:to_i)\nputs \"#{(x + y) / z} #{[-x % z, -y % z, ((x + y) / z - x / z - y / z) * z].min}\""}, {"source_code": "# frozen_string_literal: true\n\nclass ChungaChanga\n def initialize(sasha_chizhics, masha_chizhics, coconut_price)\n @sasha_chizhics = sasha_chizhics\n @masha_chizhics = masha_chizhics\n @coconut_price = coconut_price\n end\n\n def calculate\n sasha_coconuts, remaining_sasha_chizhics = @sasha_chizhics.divmod(@coconut_price)\n masha_coconuts, remaining_masha_chizhics = @masha_chizhics.divmod(@coconut_price)\n\n if (remaining_sasha_chizhics + remaining_masha_chizhics) < @coconut_price\n [sasha_coconuts + masha_coconuts, 0]\n else\n bigger_remaining = [remaining_sasha_chizhics, remaining_masha_chizhics].max\n [sasha_coconuts + masha_coconuts + 1, @coconut_price - bigger_remaining]\n end\n end\nend\n\ninput = gets.chomp.split(' ').map(&:to_i)\nresult = ChungaChanga.new(*input).calculate\nputs result.join(' ')\n"}], "negative_code": [{"source_code": "input = gets.chomp\ninput_array = input.split(' ').map(&:to_i)\n\nsasha = input_array[0]\nmasha = input_array[1]\nprice = input_array[2]\n\nsasha_coconut, sasha_mod = sasha.divmod(price)\nmasha_coconut, masha_mod = masha.divmod(price)\n\nif sasha_mod.eql?(0) || masha_mod.eql?(0)\n max = sasha_coconut + masha_coconut\n puts \"#{max} 0\"\nelse\n if sasha_mod > masha_mod\n swap = price - sasha_mod\n sasha += swap\n masha -= swap\n else\n swap = price - masha_mod\n masha += swap\n sasha -= swap\n end\n max = (sasha / price) + (masha / price)\n puts \"#{max} #{swap}\"\nend\n"}, {"source_code": "input = gets.chomp\ninput_array = input.split(' ').map(&:to_i)\n\nsasha = input_array[0]\nmasha = input_array[1]\nprice = input_array[2]\n\nsasha_coconut, sasha_mod = sasha.divmod(price)\nmasha_coconut, masha_mod = masha.divmod(price)\n\nif sasha_mod.eql?(0) && masha_mod.eql?(0)\n max = sasha_coconut + masha_coconut\n puts \"#{max} 0\"\nelse\n if sasha_mod > masha_mod\n swap = price - sasha_mod\n sasha += swap\n masha -= swap\n else\n swap = price - masha_mod\n masha += swap\n sasha -= swap\n end\n max = (sasha / price) + (masha / price)\n puts \"#{max} #{swap}\"\nend\n"}, {"source_code": "input = gets.chomp\ninput_array = input.split(' ').map(&:to_i)\n\nsasha = input_array[0]\nmasha = input_array[1]\nprice = input_array[2]\n\nmax = (sasha / price) + (masha / price)\n\n# Choose big number\nbig_number = [sasha, masha].max\nsmall_number = [sasha, masha].min\n\nmod = big_number % price\nswap = price - mod\n\nbig_number += swap\nsmall_number -= swap\n\nmax_temp = (big_number / price) + (small_number / price)\nif max_temp > max\n puts \"#{max_temp} #{swap}\"\nelse\n puts \"#{max} 0\"\nend\n"}, {"source_code": "x, y, z = gets.split.map(&:to_i)\n\na = (x/z) + (y/z)\nam = x % z\nbm = y % z\naa = (am + bm)/z\nif aa > 0\n b = [am % z, bm%z].min\nelse\n b = 0\nend\na += aa\nputs \"#{a} #{b}\""}, {"source_code": "x, y, z = gets.split.map(&:to_i)\n\na = (x + y) / z\nb = [x%z, y%z].min\nputs \"#{a} #{b}\""}, {"source_code": "x, y, z = gets.split.map(&:to_i)\n\na = (x/z) + (y/z)\nam = x % z\nbm = y % z\naa = (am + bm)/z\nif aa > 0\n b = (am+bm)%z\nelse\n b = 0\nend\na += aa\nputs \"#{a} #{b}\""}, {"source_code": "x, y, z = gets.split.map(&:to_i)\n\na = (x + y) / z\nif (x+y) >= z\n b = [x%z, y%z].min\nelse\n b = 0\nend\nputs \"#{a} #{b}\""}, {"source_code": "x, y, z = gets.split.map(&:to_i)\n\na = (x + y) / z\nb = [x, y].min % z\nputs \"#{a} #{b}\""}, {"source_code": "def prog()\n str = gets\n x,y,z = str.split(\" \").map(&:to_i)\n calc(x,y,z)\nend\n\ndef calc(x,y,z)\n min = 0\n num = 0\n if (x%z + y%z >= z)\n min = (x%z > y%z) ? (y%z) : (x%z)\n num = (x%z + y%z)/z\n end\n puts \"#{x/z + y/z + min} #{num}\"\nend\n\nprog()"}, {"source_code": "def prog()\n str = gets\n x,y,z = str.split(\" \").map(&:to_i)\n calc(x,y,z)\nend\n\ndef calc(x,y,z)\n min = 0\n num = 0\n if (x%z + y%z >= z)\n min = (x%z > y%z) ? (y%z) : (x%z)\n num = (x%z + y%z)/z\n end\n puts \"#{x/z + y/z + num} #{min}\"\nend\n\nprog()"}, {"source_code": "x, y, z = gets.split(' ').map(&:to_i)\nputs \"#{(x + y) / z} #{[x % z, y % z].min}\""}, {"source_code": "x, y, z = gets.split(' ').map(&:to_i)\nputs \"#{(x + y) / z} #{[x % z, y % z, ((x + y) / z - x / z - y / z) * z].min}\""}, {"source_code": "x, y, z = gets.split(' ').map(&:to_i)\nputs \"#{(x + y) / z} #{[-x % z, -y % z].min}\""}], "src_uid": "863a8124d46bb09b49fc88939fb5f364"} {"source_code": " n, q = gets.split.map(&:to_i)\n a = gets.split.map(&:to_i)\n b = [ 0 ] * n\n sum = a.inject(:+)\n all_t = -1\n all_x = 0\n q.times do |t| \n qq = gets.split.map(&:to_i)\n if qq[0] == 1 then\n _, i, x = qq\n if b[i-1] > all_t then\n c = a[i-1]\n else\n c = all_x\n end\n sum += x - c\n a[i-1] = x\n b[i-1] = t\n else\n _, x = qq\n all_t = t\n all_x = x\n sum = x * n\n end\n puts sum\n end\n", "positive_code": [{"source_code": "n,q=gets.split.map(&:to_i)\narr=gets.split.map(&:to_i)\nsum=arr.sum\nhash=Hash.new(0)\ncur_mod=1\nq.times do \n mod, *arg=gets.split.map(&:to_i)\n if mod==2\n cur_mod=2\n hash=Hash.new(arg[0])\n puts sum= n*arg[0]\n elsif cur_mod==1\n sum+=arg[1]-arr[arg[0]-1]\n arr[arg[0]-1]=arg[1]\n puts sum\n else\n sum+=arg[1]-hash[arg[0]]\n hash[arg[0]]=arg[1]\n puts sum\n end\nend"}], "negative_code": [{"source_code": "n,q=gets.split.map(&:to_i)\narr=gets.split.map(&:to_i)\nsum=arr.sum\nhash=Hash.new(0)\ncur_mod=1\nq.times do \n mod, *arg=gets.split.map(&:to_i)\n if mod==2\n cur_mod=2\n hash=Hash.new(arg[0])\n puts sum= n*arg[0]\n elsif cur_mod==1\n sum+=arg[1]-arr[arg[0]-1]\n puts sum\n else\n sum+=arg[1]-hash[arg[0]]\n hash[arg[0]]=arg[1]\n puts sum\n end\nend"}], "src_uid": "b9771f941967b030aa13d0bfcc4d0a61"} {"source_code": "n=gets.to_i\nx=gets.split\nh=Hash.new(0)\n\nans=0\nc1=0\nx.each{|e|\n\t\tif h.key?(e) then\n\t\t\th.delete(e)\n\t\t\tc1-=1\n\t\telse\n\t\t\th[e]=1\n\t\t\tc1+=1\n\t\tend\n\t\tans=[ans,c1].max\n}\nputs ans\n\n", "positive_code": [{"source_code": "gets\nb, c, maxc = Hash.new, 0, 0\nfor a in gets.chomp.split.map{|x| Integer(x)}\n if b.include?(a) then\n b[a], c = true, c-1 if not b[a] \n else\n b[a], c = false, c+1\n end\n maxc = [c, maxc].max\nend\nputs maxc"}, {"source_code": "#\u5176\u5b9e\u8fd9\u4e9b\u7b80\u5355\u95ee\u9898\u521a\u597d\u9002\u5408ruby\u89e3\u51b3\uff0c\u8ba9\u6211\u53ef\u4ee5\u638c\u63e1ruby\u7684\u57fa\u672c\u8bed\u6cd5\uff01\n#\u5c31\u6a21\u62df\u6574\u4e2a\u8fc7\u7a0b\uff0c\u5f97\u5230\u90a3\u4e2a\u6700\u5927\u6570\u5c31\u53ef\u4ee5\uff01\nn=gets.chomp.to_i\nexist=Array.new(100001)\nsocks=gets.chomp.split(\" \")\ntable=0\ncount=0\nfor i in 0..2*n\n if exist[socks[i].to_i]\n exist[socks[i].to_i]=0\n count=count-1 if table > 0\n else\n exist[socks[i].to_i]=1\n count=count+1\n end\n if count>table\n table=count\n end\nend\nputs table\n"}, {"source_code": "require 'set'\nn=gets.chomp.to_i\n#table=Array.new\ntable = Set.new\nsocks=gets.chomp.split(\" \")\nmax=0\ncount=0\n#\u8d85\u65f6\u4e86\uff0cruby\u91cc\u4e0d\u63d0\u4f9b\u7c7b\u4f3cred black\u7684\u63d2\u5165\uff1f\nfor i in 0..2*n\n if table.include?(socks[i])\n table.delete(socks[i])\n count=count-1 if count > 0\n else\n table.add(socks[i])\n count=count+1\n end\n if count>max\n max=count\n end\nend\nputs max\n"}, {"source_code": "gets\nv, res = Hash.new(nil), []\ngets.split.each { |s|\n if v[s]\n v.delete(s)\n else\n v[s] = true\n res.push(v.length)\n end\n}\np res.max"}, {"source_code": "#!/usr/bin/ruby\ngets;t={};r=0;gets.split.each{|e|\n\tif t.has_key?(e)\n\t\tt.delete(e)\n\telse\n\t\tt[e]=1\n\t\tr=[r,t.size].max\n\tend\n};p r"}, {"source_code": "n = gets.strip.to_i\ns = gets.strip.split.map(&:to_i)\ntrack = Array.new((2 * n) + 1, false)\nans = count = 0\n(2 * n).times do |i|\n curr = s[i]\n if track[curr]\n ans = [ans, count].max\n count -= 1\n else\n track[curr] = true\n count += 1\n end\nend\nputs ans\n"}, {"source_code": "n = gets.to_i\na = gets.split.map(&:to_i)\nvis = Array.new(n + 1)\ncnt = 0\nmx = 0\na.each do |x|\n cnt -= 2 if vis[x]\n vis[x] = true\n cnt += 1\n mx = [cnt, mx].max\nend\np mx\n\n"}], "negative_code": [{"source_code": "n = gets.strip.to_i\ns = gets.strip.split.map(&:to_i)\ntrack = {}\nans = 0\nn.times do |i|\n curr = s[i]\n track[curr] = 0 if !track[curr]\n track[curr] += 1\n ans += 1 if track[curr] < 2\nend\nputs ans\n"}], "src_uid": "7f98c9258f3e127a782041c421d6317b"} {"source_code": "gets.to_i.times do\r\n\r\nn = gets.to_i\r\na = gets.split.map!(&:to_i)\r\n\r\na_min = a.min\r\na.map! { |ai| ai - a_min }\r\na.delete_if { |ai| ai == 0 }\r\n\r\nif a.empty?\r\n puts -1\r\nelse\r\n puts a.inject(0, :gcd)\r\nend\r\n\r\nend\r\n", "positive_code": [{"source_code": "gets.to_i.times do\n\tn = gets.to_i\n\ta = gets.split.map(&:to_i)\n\ta = a.sort\n\tres = 0; tmp = a[0] \n\ta.map! {|ai| ai - tmp}\n\ta.map! {|x| res = res.gcd(x)}\n\tputs res != 0? res:-1\nend"}], "negative_code": [], "src_uid": "57f0f36905d7769167b7ba9d3d9be351"} {"source_code": "t=gets.to_i\n(1).upto(t) do\n n=gets.to_i\n freq=Array.new(n+1,0)\n a=gets.split(' ').map(&:to_i)\n x=0\n y=0\n a.each do |e|\n freq[e]+=1\n y=[y,freq[e]].max\n x+=1 if freq[e]==1\n end\n if(y>x)\n puts x\n elsif y==x\n puts x-1\n else\n puts y\n end\nend\n", "positive_code": [{"source_code": "t = gets.chomp.to_i\n\n(1..t).each{\n n = gets.chomp.to_i\n a = gets.chomp.split.map{|x| x.to_i}\n count = Hash.new 0\n a.each{|x|\n count[x] += 1;\n }\n \n max_diff = count.keys.size\n max_same = count.values.max\n \n if max_same == max_diff then\n puts (max_same - 1)\n else\n puts [max_same, max_diff].min\n end\n}"}, {"source_code": "1.upto(gets.to_i) do\n gets\n h = Hash.new { 0 }\n gets.split(' ').map(&:to_i).each { |x| h[x] += 1 }\n\n u = h.keys.size\n m = h.max_by(&:last).last\n\n puts [[u-1, m].min, [u, m-1].min].max\nend\n"}], "negative_code": [{"source_code": "t=gets.to_i\n(1).upto(t) do\n n=gets.to_i\n freq=Array.new(n+1,0)\n a=gets.split(' ').map(&:to_i)\n x=0\n y=0\n a.each do |e|\n freq[e]+=1\n y=[y,freq[e]].max\n x+=1 if freq[e]==1\n end\n puts [y,x-1].min\nend\n"}], "src_uid": "a1951e7d11b504273765fc9fb2f18a5e"} {"source_code": "UF=Hash.new{|_,k|k}\ndef u a,b;UF[f a]=UF[f b]end\ndef f c;c==UF[c]?c:UF[c]=f(UF[c])end\n\nn=gets.to_i\na=gets.split.map(&:to_i)\nm=(1..n).map{gets.chomp.chars.map{|c|c>?0}}\nr=0...n\nr.each{|i|r.each{|j|\n u(i,j) if m[i][j]\n}}\ngroup=r.map{|i|f i}\ng=a.group_by.with_index{|i,j|group[j]}\ng.values.map(&:sort!)\nputs r.map{|i|g[group[i]].shift}*\" \"\n", "positive_code": [{"source_code": "class DSU\n\tdef initialize n\n\t\t@p = Array.new(n) { |i, v| v = i }\n\tend\n\tdef find x\n\t\treturn x if @p[x] == x\n\t\t@p[x] = find @p[x]\n\tend\n\tdef merge a, b\n\t\t@p[find(a)] = find(b)\n\tend\n\tdef query? a, b\n\t\tfind(a) == find(b)\n\tend\nend\n\nn = gets.to_i\ndsu = DSU.new n\np = gets.split.map { |x| x.to_i - 1 }\nn.times do |i|\n\ts = gets.chomp\n\tn.times do |j|\n\t\tif s[j] == '1' and !dsu.query?(i, j)\n\t\t\tdsu.merge i, j\n\t\tend\n\tend\nend\n\nans = Array.new n\nn.times do |i|\n\tif dsu.find(i) == i\n\t\ta = []\n\t\tb = []\n\t\tn.times do |j|\n\t\t\tif dsu.find(j) == i\n\t\t\t\ta << j\n\t\t\t\tb << p[j]\n\t\t\tend\n\t\tend\n\t\tb.sort!\n\t\ta.size.times do |j|\n\t\t\tans[a[j]] = b[j] + 1\n\t\tend\n\tend\nend\nputs ans.join ' '"}, {"source_code": "UF=Hash.new{|_,k|k}\ndef u a,b;UF[f a]=UF[f b]end\ndef f c;c==UF[c]?c:UF[c]=f(UF[c])end\n\nn=gets.to_i\na=gets.split.map(&:to_i)\nm=(1..n).map{gets.chomp.chars.map{|c|c>?0}}\nr=0...n\nr.each{|i|r.each{|j|\n u(i,j) if m[i][j]\n}}\ngroup=r.map{|i|f i}\ng=a.group_by.with_index{|i,j|group[j]}\ng.values.map(&:sort!)\nputs r.map{|i|g[group[i]].shift}*\" \"\n"}, {"source_code": "UF=Hash.new{|_,k|k}\ndef u a,b;UF[f a]=UF[f b]end\ndef f c;c==UF[c]?c:UF[c]=f(UF[c])end\n\nn=gets.to_i\na=gets.split.map(&:to_i)\nm=(1..n).map{gets.chomp.chars.map{|c|c>?0}}\nr=0...n\nr.each{|i|r.each{|j|\n u(i,j) if m[i][j]\n}}\ngroup=r.map{|i|f i}\ng=a.group_by.with_index{|i,j|group[j]}\ng.values.map(&:sort!)\nputs r.map{|i|g[group[i]].shift}*\" \"\n"}, {"source_code": "UF=Hash.new{|_,k|k}\ndef u a,b;UF[f a]=UF[f b]end\ndef f c;c==UF[c]?c:UF[c]=f(UF[c])end\n\nn=gets.to_i\na=gets.split.map(&:to_i)\nm=(1..n).map{gets.chomp.chars.map{|c|c>?0}}\nr=0...n\nr.each{|i|r.each{|j|\n u(i,j) if m[i][j]\n}}\ngroup=r.map{|i|f i}\ng=a.group_by.with_index{|i,j|group[j]}\ng.values.map(&:sort!)\nputs r.map{|i|g[group[i]].shift}*\" \"\n"}, {"source_code": "UF=Hash.new{|_,k|k}\ndef u a,b;UF[f a]=UF[f b]end\ndef f c;c==UF[c]?c:UF[c]=f(UF[c])end\n\nn=gets.to_i\na=gets.split.map(&:to_i)\nm=(1..n).map{gets.chomp.chars.map{|c|c>?0}}\nr=0...n\nr.each{|i|r.each{|j|\n u(i,j) if m[i][j]\n}}\ngroup=r.map{|i|f i}\ng=a.group_by.with_index{|i,j|group[j]}\ng.values.map(&:sort!)\nputs r.map{|i|g[group[i]].shift}*\" \""}, {"source_code": "UF=Hash.new{|_,k|k}\ndef u a,b;UF[f a]=UF[f b]end\ndef f c;c==UF[c]?c:UF[c]=f(UF[c])end\n\nn=gets.to_i\na=gets.split.map(&:to_i)\nm=(1..n).map{gets.chomp.chars.map{|c|c>?0}}\nr=0...n\nr.each{|i|r.each{|j|\n u(i,j) if m[i][j]\n}}\ngroup=r.map{|i|f i}\ng=a.group_by.with_index{|i,j|group[j]}\ng.values.map(&:sort!)\nputs r.map{|i|g[group[i]].shift}*\" \"\n"}, {"source_code": "UF=Hash.new{|_,k|k}\ndef u a,b;UF[f a]=UF[f b]end\ndef f c;c==UF[c]?c:UF[c]=f(UF[c])end\n\nn=gets.to_i\na=gets.split.map(&:to_i)\nm=(1..n).map{gets.chomp.chars.map{|c|c>?0}}\nr=0...n\nr.each{|i|r.each{|j|\n u(i,j) if m[i][j]\n}}\ngroup=r.map{|i|f i}\ng=a.group_by.with_index{|i,j|group[j]}\ng.values.map(&:sort!)\nputs r.map{|i|g[group[i]].shift}*\" \"\n"}, {"source_code": "UF=Hash.new{|_,k|k}\ndef u a,b;UF[f a]=UF[f b]end\ndef f c;c==UF[c]?c:UF[c]=f(UF[c])end\n\nn=gets.to_i\na=gets.split.map(&:to_i)\nm=(1..n).map{gets.chomp.chars.map{|c|c>?0}}\nr=0...n\nr.each{|i|r.each{|j|\n u(i,j) if m[i][j]\n}}\ngroup=r.map{|i|f i}\ng=a.group_by.with_index{|i,j|group[j]}\ng.values.map(&:sort!)\nputs r.map{|i|g[group[i]].shift}*\" \""}, {"source_code": "n = gets.to_i\nps = gets.split.map(&:to_i)\naij = []\nn.times do |i|\n aij[i] = gets.split(\"\").map(&:to_i)\nend\n\nret = Array.new(n)\ngs = []\ngn = []\ngi = 0\nni = 0\nflags = Array.new(n){ |x| false }\nwhile ni\n gs[gi] = []\n gn[gi] = []\n target = [ni]\n flags[ni] = true\n until target.size == 0 do\n x = target.pop\n gs[gi] << x\n gn[gi] << ps[x]\n aij[x].each_with_index do |y,j|\n if y==1 && !flags[j]\n target << j \n flags[j] = true\n end \n end\n end\n gs[gi].sort!\n gn[gi].sort!\n gs[gi].each_with_index do |x,i|\n ret[x] = gn[gi][i]\n end\n STDERR.puts \"#{ni} #{ret.join(\" \")}\"\n ni = flags.index{ |x| x==false }\n gi += 1\nend\nputs ret.join(\" \")\n\n"}, {"source_code": "UF=Hash.new{|_,k|k}\ndef u a,b;UF[f a]=UF[f b]end\ndef f c;c==UF[c]?c:UF[c]=f(UF[c])end\n\nn=gets.to_i\na=gets.split.map(&:to_i)\nm=(1..n).map{gets.chomp.chars.map{|c|c>?0}}\nr=0...n\nr.each{|i|r.each{|j|\n u(i,j) if m[i][j]\n}}\ngroup=r.map{|i|f i}\ng=a.group_by.with_index{|i,j|group[j]}\ng.values.map(&:sort!)\nputs r.map{|i|g[group[i]].shift}*\" \"\n"}, {"source_code": "UF=Hash.new{|_,k|k}\ndef u a,b;UF[f a]=UF[f b]end\ndef f c;c==UF[c]?c:UF[c]=f(UF[c])end\n\nn=gets.to_i\na=gets.split.map(&:to_i)\nm=(1..n).map{gets.chomp.chars.map{|c|c>?0}}\nr=0...n\nr.each{|i|r.each{|j|\n u(i,j) if m[i][j]\n}}\ngroup=r.map{|i|f i}\ng=a.group_by.with_index{|i,j|group[j]}\ng.values.map(&:sort!)\nputs r.map{|i|g[group[i]].shift}*\" \"\n"}], "negative_code": [{"source_code": "n = gets.to_i\nps = gets.split.map(&:to_i)\naij = []\nn.times do |i|\n aij[i] = gets.split(\"\").map(&:to_i)\nend\n\nret = Array.new(n)\ngs = []\ngn = []\ngi = 0\nni = 0\nflags = Array.new(n){ |x| false }\nwhile ni < n\n gs[gi] = []\n gn[gi] = []\n target = [ni]\n flags[ni] = true\n ni += 1\n until target.size == 0 do\n x = target.pop\n gs[gi] << x\n gn[gi] << ps[x]\n aij[x].each_with_index do |y,j|\n if y==1 && !flags[j]\n target << j \n flags[j] = true\n end \n end\n end\n gs[gi].sort!\n gn[gi].sort!\n gs[gi].each_with_index do |x,i|\n ret[x] = gn[gi][i]\n end\n break if ni == n\n (ni...n).each do |x|\n ni = x\n break unless flags[x]\n end\n gi += 1\nend\nputs ret.join(\" \")\n\n"}, {"source_code": "n = gets.to_i\nps = gets.split.map(&:to_i)\naij = []\nn.times do |i|\n aij[i] = gets.split(\"\").map(&:to_i)\nend\n\nret = Array.new(n)\ngs = []\ngn = []\ngi = 0\nni = 0\nflags = Array.new(n){ |x| false }\nwhile ni < n\n gs[gi] = []\n gn[gi] = []\n target = [ni]\n flags[ni] = true\n ni += 1\n #break if ni == n\n until target.size == 0 do\n x = target.pop\n gs[gi] << x\n gn[gi] << ps[x]\n aij[x].each_with_index do |y,j|\n if y==1 && !flags[j]\n target << j \n flags[j] = true\n end \n end\n end\n gs[gi].sort!\n gn[gi].sort!\n gs[gi].each_with_index do |x,i|\n ret[x] = gn[gi][i]\n end\n (ni...n).each do |x|\n ni = x\n break unless flags[x]\n end\n gi += 1\nend\nputs ret.join(\" \")\n\n"}, {"source_code": "n = gets.to_i\nps = gets.split.map(&:to_i)\naij = []\nn.times do |i|\n aij[i] = gets.split(\"\").map(&:to_i)\nend\n\nret = Array.new(n)\ngs = []\ngn = []\ngi = 0\nni = 0\nflags = Array.new(n){ |x| false }\nwhile ni < n\n gs[gi] = []\n gn[gi] = []\n target = [ni]\n flags[ni] = true\n ni += 1\n break if ni == n\n until target.size == 0 do\n x = target.pop\n gs[gi] << x\n gn[gi] << ps[x]\n aij[x].each_with_index do |y,j|\n if y==1 && !flags[j]\n target << j \n flags[j] = true\n end \n end\n end\n gs[gi].sort!\n gn[gi].sort!\n gs[gi].each_with_index do |x,i|\n ret[x] = gn[gi][i]\n end\n (ni...n).each do |x|\n ni = x\n break unless flags[x]\n end\n gi += 1\nend\nputs ret.join(\" \")\n\n"}], "src_uid": "a67ea891cd6084ceeaace8894cf18e60"} {"source_code": "fw = []\ngets.to_i.times do\n fw << gets.strip.downcase\nend\nret = gets.strip\nstr = ret.downcase\nletter = gets.strip\nfw.each do |w|\n pos = 0\n while i = str.index(w, pos)\n (i...(i + w.size)).each do |n|\n if str[n] == letter\n if str[n] == 'a'\n c = 'b'\n else\n c = 'a'\n end\n else\n c = letter\n end\n ret[n] = ret[n] == ret[n].upcase ? c.upcase : c\n end\n pos += 1\n end\nend\nputs ret\n", "positive_code": [{"source_code": "#sharyo\ndef isupper(c)\n if (/[[:upper:]]/.match(c))\n\treturn true\n\tend\n return false\nend\nn=gets.to_i\nm=Hash.new\nv=Array.new\nfor i in 0..n-1\n x=gets.chop\n y=\"\"\n x.split('').each{|j|\n \ty+=j.downcase\n } \n m[y]=true\nend \na=gets.chop.split('')\nb=a.join\nn=b.length\n\nb=b.split('')\n\nfor i in 0..n-1\na[i]=a[i].downcase\nend \nc=Array.new(n,false)\n\nfor i in 0..n-1\n\tx=\"\"\n\tfor j in i..n-1\n\t\tx+=a[j]\n\t\tif m[x]\n\t\t\tv.push([i,j])\n\t\tend\n\tend\nend\nv.each do |(x,y)|\n\tfor j in x..y\n\t\tc[j]=true\n\tend\nend\nz=gets.chop\nfor i in 0..n-1 \n\tnext unless c[i]\n\tif z.downcase!=b[i].downcase\n\t\tif \tisupper(b[i])\n\t\t\tb[i]=z.upcase\n\t\telse\t\n b[i]=z\n\t\tend\t\n\n\telsif b[i].downcase=='a'\n if isupper(b[i])\n\t\t\tb[i]='B'\n\t\telse\t\n b[i]='b'\n\t\tend\t\n\n\telse\n\t\tif \tisupper(b[i])\n\t\t\tb[i]='A'\n\t\telse\t\n b[i]='a'\n\t\tend\t\t\n\tend\n\nend \n\nprint b.join\n\n"}, {"source_code": "n = gets.to_i\nps = (1..n).map { |s| gets.strip }\nt = gets.strip\nc = gets.strip\nx = [0] * t.size\n(0...t.size).each do |i|\n ps.each do |s|\n x[i, s.size] = [1] * s.size if t[i, s.size].downcase == s.downcase\n end\nend\nx.size.times do |i|\n if x[i] == 1\n if t[i].downcase == c.downcase\n if t[i].downcase == t[i]\n t[i] = c == ?a || c == ?A ? ?b : ?a\n else\n t[i] = c == ?a || c == ?A ? ?B : ?A\n end\n else\n if t[i].downcase == t[i]\n t[i] = c\n else\n t[i] = c.upcase\n end\n end\n end\nend\nputs t\n"}, {"source_code": "n = gets.chomp.to_i\nss = Array.new(n)\nfor i in 1..n\n ss[i-1] = gets.chomp.upcase\nend\ns0 = gets.chomp\nc = gets.chomp\ns = s0.upcase\nii = Array.new(s.length).map!{|x| false}\nfor i in 1..n\n previdx = 0\n while true\n wkidx = s.index(ss[i-1], previdx)\n if wkidx != nil then\n for j in 0..ss[i-1].length-1\n ii[wkidx+j] = true\n end\n else\n break\n end\n previdx = wkidx+1\n end\nend\n\nc2 = c.upcase\nfor i in 0..s0.length-1\n next if ii[i] == false\n wkup = false\n wkup = true if s0[i] == s[i]\n wk = c\n if s[i] == c2 then\n if c == \"a\" then\n wk = \"b\"\n else\n wk = \"a\"\n end\n end\n wk = wk.upcase if wkup\n s0[i] = wk\nend\nputs s0\n"}, {"source_code": "fw = []\ngets.to_i.times do\n fw << gets.strip.downcase\nend\nret = gets.strip\nstr = ret.downcase\nletter = gets.strip\nfw.each do |w|\n pos = 0\n while i = str.index(w, pos)\n (i...(i + w.size)).each do |n|\n if str[n] == letter\n if str[n] == 'a'\n c = 'b'\n else\n c = 'a'\n end\n else\n c = letter\n end\n ret[n] = ret[n] == ret[n].upcase ? c.upcase : c\n end\n pos += 1\n end\nend\nputs ret"}, {"source_code": "def optimal_letter(ch,l)\n\treturn(ch e\n puts e\nend\n"}, {"source_code": "begin\nn = gets.to_i\nps = (1..n).map { |s| gets.strip }\nt = gets.strip\nc = gets.strip\nx = [0] * t.size\n(0...t.size).each do |i|\n ps.each do |s|\n x[i, s.size] = [1] * s.size if t[i, s.size].downcase == s.downcase\n end\nx.size.times do |i|\n if x[i] == 1\n if t[i] == c\n t[i] = c == ?a ? ?b : ?a\n else\n if t[i].match?(/[a-z]/)\n t[i] = c\n else\n t[i] = c.upcase\n end\n end\n end\nend\nputs t\nend\nrescue => e\n puts e\nend\n"}, {"source_code": "n = gets.to_i\nps = (1..n).map { |s| gets.strip }\nt = gets.strip\nc = gets.strip\nx = [0] * t.size\n(0...t.size).each do |i|\n ps.each do |s|\n x[i, s.size] = [1] * s.size if t[i, s.size].downcase == s.downcase\n end\nend\nx.size.times do |i|\n if x[i] == 1\n if t[i] == c\n t[i] = c == ?a ? ?b : ?a\n else\n if t[i].downcase == t[i]\n t[i] = c\n else\n t[i] = c.upcase\n end\n end\n end\nend\nputs t\n"}, {"source_code": "def optimal_letter(ch,l)\n\treturn(ch y[0] }\n visited = [false] * c.size\n result = 1\n c.each_index do |i|\n result = (result * 2) % 1000000007 unless visited[i]\n j = i\n while !visited[j]\n visited[j] = true\n j = c[j][1]\n end\n end\n puts result\nend\n", "positive_code": [{"source_code": "gets.to_s.to_i.times do\n n = gets.to_s.to_i\n a = gets.to_s.strip.split.map {|x| x.to_i - 1 }\n b = gets.to_s.strip.split.map {|x| x.to_i - 1 }\n c = a.zip(b).sort {|x, y| x[0] <=> y[0] }\n visited = [false] * c.size\n result = 0\n c.each_index do |i|\n result += 1 unless visited[i]\n j = i\n while !visited[j]\n visited[j] = true\n j = c[j][1]\n end\n end\n puts 2.pow(result, 1000000007)\nend\n"}, {"source_code": "gets.to_s.to_i.times do\n n = gets.to_s.to_i\n a = gets.to_s.strip.split.map {|x| x.to_i - 1 }\n b = gets.to_s.strip.split.map {|x| x.to_i - 1 }\n c = a.zip(b).sort {|x, y| x[0] <=> y[0] }.map {|x| x[1] }\n result = 1\n c.each_with_index do |ci, i|\n next if ci < 0\n result = (result * 2) % 1000000007\n j = i\n c[j], j = -1, c[j] until j < 0\n end\n puts result\nend\n"}], "negative_code": [], "src_uid": "3f1e2549d7342364b08f976fcbb7b1fa"} {"source_code": "a = $<.read.split.map(&:to_i)\np (1.upto(a[0]).map do |i|\n c = 1\n c += 1 while (i = a[i]) != -1\n c\nend.max)\n\n", "positive_code": [{"source_code": "a=gets.chomp.to_i\nar=[]\na.times do \nar << gets.chomp.to_i\nend\nmax=0\n0.upto(a-1) do |i|\ntemp=1\nk=ar[i]\nloop do \nbreak if k==-1\nk=ar[k-1]\ntemp+=1\nend\nif temp >max\nmax=temp\nend\nend\nputs \"#{max}\""}, {"source_code": "a = $<.read.split.map(&:to_i)\np (1.upto(a[0]).map do |i|\n c = 1\n c += 1 while (i = a[i]) != -1\n c\nend.max)\n\n"}, {"source_code": "n = gets.to_i\nmg = n.times.map{gets.to_i}\nmx = 0\nn.times do |i|\n m = i\n cnt = 1\n n.times do\n if mg[m] == -1\n mx = [cnt, mx].max\n break\n end\n m = mg[m] - 1\n cnt += 1\n end\nend\nputs mx\n"}, {"source_code": "a = $<.read.split.map(&:to_i)\np (1.upto(a[0]).map do |i|\n c = 1\n c += 1 while (i = a[i]) != -1\n c\nend.max)\n\n"}, {"source_code": "n = gets.to_i\nmg = [nil] + n.times.map{gets.to_i}\n$e = Array.new(n + 1){Array.new}\n1.upto(n){|i| $e[[0, mg[i]].max] << i}\n$cnt = []\n\ndef dfs(u, lv)\n $cnt[u] = lv\n $e[u].each do |v|\n dfs(v, lv + 1)\n end\nend\n\ndfs(0, 0)\nputs $cnt.max\n"}, {"source_code": "a = $<.read.split.map(&:to_i)\np (1.upto(a[0]).map do |i|\n c = 1\n c += 1 while (i = a[i]) != -1\n c\nend.max)\n"}, {"source_code": "def dep(v)\n result = 1\n pos = v\n while pos > 0\n result += 1\n pos = $a[pos]\n end\n\n result\nend\n\nn = gets.to_i\n\n$a = (1..n).map { gets.to_i }\n$a.unshift 0\nputs $a.map { |x| dep(x) }.max\n"}, {"source_code": "a=gets.chomp.to_i\nar=[]\na.times do \nar << gets.chomp.to_i\nend\nmax=0\n0.upto(a-1) do |i|\ntemp=1\nk=ar[i]\nloop do \nbreak if k==-1\nk=ar[k-1]\ntemp+=1\nend\nif temp >max\nmax=temp\nend\nend\nputs \"#{max}\""}, {"source_code": "n=gets.to_i\na=(0..n).map{[]}\nb=[]\n\nn.times{|i|\n\te=i+1\n\te2=gets.to_i\n\ta[e2]< max\n}\nputs max\n\n# The following O(n) solution works on my machine but fails on codeforces with RUNTIME_ERROR\n=begin\nclass Node\n attr_accessor :parent\n attr_reader :children\n\n def initialize()\n @children = []\n end\n\n def len\n @children.size > 0 ? @children.map(&:len).max + 1 : 1\n end\nend\n\nn = gets.to_i\nnodes = Array.new(n)\nn.times { |i|\n p = gets.to_i - 1\n node = nodes[i] || Node.new\n if p >= 0\n parent = nodes[p] || Node.new\n node.parent = parent\n parent.children << node\n nodes[p] = parent\n end\n nodes[i] = node\n}\n\nputs nodes.select { |node| node.parent.nil? }.map(&:len).max\n=end"}, {"source_code": "a = $<.read.split.map(&:to_i)\np (1.upto(a[0]).map do |i|\n c = 1\n c += 1 while (i = a[i]) != -1\n c\nend.max)\n\n"}, {"source_code": "n=gets.to_i\ng=Array.new(n+1)\n(1).upto(n) {|i| g[i]=[]}\nq=Queue.new\n(1).upto(n) do |i|\n p=gets.to_i\n g[p].push(i) if(p!=-1)\n q.push([i,1]) if(p==-1)\nend\nmx=0\nwhile !(q.empty?) do\n cur = q.pop\n mx=cur[1]\n g[cur[0]].each do |node|\n q.push([node,mx+1])\n end\nend\nputs mx\n\n"}, {"source_code": "a = $<.read.split.map(&:to_i)\np (1.upto(a[0]).map do |i|\n c = 1\n c += 1 while (i = a[i]) != -1\n c\nend.max)\n\n"}, {"source_code": "a = $<.read.split.map(&:to_i)\np (1.upto(a[0]).map do |i|\n c = 1\n c += 1 while (i = a[i]) != -1\n c\nend.max)"}, {"source_code": "\n\nn = gets.to_i\ne = Array.new(n) { [] }\nroots = []\nn.times {|i|\n j = gets.to_i\n if j == -1\n roots << i\n else\n e[j-1] << i\n end\n}\n\ndef depth(i, e)\n return 1 if e[i].empty?\n e[i].map{|c| depth(c, e)}.max + 1\nend\n\nputs roots.map{|r| depth(r, e)}.max\n"}, {"source_code": "n = gets.chomp.to_i\nmaxlevel = 0\na = Array.new(n)\nfor i in 0..n-1\n a[i] = gets.chomp.to_i\nend\nfor i in 0..n-1\n lvl = 1\n j = i\n while a[j] != -1\n j = a[j]-1\n lvl += 1\n end\n maxlevel = lvl if maxlevel < lvl\nend\nputs maxlevel"}, {"source_code": "n = gets.strip.to_i\n\npairs = []\nrank = Array.new(n,0)\nn.times do |i|\n\tman = gets.strip.to_i\n\tif man ==-1\n\t\trank[i] = 1\n\telse\n\t\tpairs << [man, i+1]\n\tend\nend\n\nwhile rank.include? 0\n\tpairs.each do |v|\n\t\tu,l = v\n\t\tnext if rank[l-1]!=0\n\n\t\tsurank = rank[u-1]\n\t\tif surank!=0\n\t\t\trank[l-1] = surank+1\n\t\tend\n\tend\nend\n\nputs rank.max\n"}, {"source_code": "num = 0\nanswer = 0\nemployees = []\n\nwhile line = STDIN.gets\n count = 0\n num += 1\n if (/exit/ =~ line)\n break;\n elsif (num == 1)\n line = line.chomp.to_i\n employee_count = line\n else\n employees.push([nil, line = line.chomp.to_i])\n end\nend\n\nemployees.each do |employee|\n count = 0\n employee_tmp = employee\n while true\n count += 1\n if employee_tmp[1] == -1\n break\n else\n employee_tmp = employees[employee_tmp[1]-1]\n end\n end\n if count > answer\n answer = count\n end\nend\nSTDOUT.puts answer\n"}, {"source_code": "n = gets.chomp.to_i\nh = Hash.new\n\n1.upto(n).each do |i|\n\tv = gets.chomp.to_i\n\th[v] ||= []\n\th[v] << i\nend\n\n# p h\nvisited = Hash.new\n-1.upto(n) do |i|\n\tnext if h[i].nil? || !visited[i].nil?\n\tvisited[i] = 0\n\tq = Queue.new\n\tq.push(i)\n\twhile(!q.empty?)\n\t\tf = q.pop\n\t\th[f].each do |x|\n\t\t\tif visited[x].nil?\n\t\t\t\tvisited[x] = visited[f] + 1\n\t\t\t\tif !h[x].nil?\n\t\t\t\t\tq.push(x)\n\t\t\t\tend \n\t\t\tend\n\t\tend\n\tend\nend\n\n# print visited\nprint visited.values.max"}, {"source_code": "\ndef solve(x)\n if $p[x]<0 then\n return 0\n end\n if $dp[x]>=0 then\n return $dp[x]\n end\n return $dp[x]=solve($p[x])+1\nend\nn=gets.to_i\n$p=[]\nn.times{|i|\n $p.push(gets.to_i-1)\n}\n$dp=Array.new(n,-1)\nans=0\nn.times{|i|\n ans=[ans,solve(i)].max\n}\np ans+1\n"}, {"source_code": "a = $<.read.split.map(&:to_i)\np (1.upto(a[0]).map do |i|\n c = 1\n c += 1 while (i = a[i]) != -1\n c\nend.max)\n\n"}, {"source_code": "a = $<.read.split.map(&:to_i)\np (1.upto(a[0]).map do |i|\n c = 1\n c += 1 while (i = a[i]) != -1\n c\nend.max)\n\n"}, {"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(index1, index2)\n if vertices[index1].nil? then\n vertices[index1] = List.new(index2, nil)\n else\n vert = List.new(index2, vertices[index1])\n vertices[index1] = List.new(index2, vertices[index1])\n end\n end\n\n def print_edges\n vertices.each_with_index do |vertex, index|\n while !vertex.nil? do \n # puts \"edge #{index} - #{vertex.element}\"\n vertex = vertex.next_elem\n end\n end\n end\nend\n\ndef depth(graph, index)\n return 1 if graph.vertices[index].nil?\n max_depth = depth(graph, graph.vertices[index].element)\n next_vertex = graph.vertices[index].next_elem\n while !next_vertex.nil? do\n current_max_depth = depth(graph, next_vertex.element) \n max_depth = [max_depth, current_max_depth].max\n next_vertex = next_vertex.next_elem\n end\n return max_depth + 1\nend\n\nemployees = Graph.new([])\nroot_managers = []\nn = gets.strip.to_i\nn.times do |i|\n manager = gets.strip.to_i\n if manager == -1 then\n root_managers.push(i)\n else\n employees.add_edge(manager - 1, i)\n end\nend \nemployees.print_edges\n# puts \"root managerts: #{root_managers.join(\" \")}\"\nmax_depth = 1\nroot_managers.each do |i|\n if !employees.vertices[i].nil? \n max_depth = [depth(employees, i), max_depth].max\n end\nend\nputs max_depth\n"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# 5\n# -1 : 1\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 \uc5c6\uc74c\n# 1 : 2\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 1\ubc88\uc784\n# 2 : 3\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 2\ubc88\uc784\n# 1 : 4\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 1\ubc88\uc784\n# -1 : 5\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 \uc5c6\uc74c\n# transitive\ub97c \ud5c8\uc6a9\ud558\uc9c0 \uc54a\uc74c(2\uc758 \uc0c1\uc0ac\ub294 3\uc778\ub370, 3\uc758 \uc0c1\uc0ac\ub294 1\uc774\uba74 2-1\uc740 \uac19\uc774 \uc788\uc744 \uc218 \uc5c6\ub2e4)\n\n# \uc774\uac70 LCA (Lowest Common Ancestor) \ubb38\uc81c\ub85c \uc811\uadfc\ud558\uba74 \uac04\ub2e8\ud558\uace0,\n# \uadf8\ub9bc\uc744 \uc801\uc5b4\ub3c4 \ud55c\ubc88\uc740 \uadf8\ub824\ubcf4\uae38 \uad8c\ud568\n# depth\ub9c8\ub2e4 \uc218\ud3c9\ud558\uac8c \uc798\ub77c\ub0b4\uba74 \uc5b4\ub5a4 \uc0c1\uc0ac\ub3c4 \uacb9\uce58\uc9c0 \uc54a\ub294\ub2e4.\n# \uc989, \ucd5c\uace0 depth\uc758 \uc218\ub294 \ub9cc\ub4e4 \uc218 \uc788\ub294 \uc801\uc808\ud55c \uadf8\ub8f9\uc758 \uc218\uac00 \ub41c\ub2e4.\n\nn = gets.to_i\nee = []\nn.times {\n ee << gets.to_i - 1 # -1 -> -2\n}\nmap = {}\ngroups_max = 0\nfor i in 0...n\n map[i] = []\n j = i\n loop do\n sup = ee[j]\n if sup < 0\n break\n else\n map[i] << sup\n j = sup\n end\n end\n\n if map[i].length > groups_max\n groups_max = map[i].length\n end\nend\n\nputs groups_max + 1 # value excludes itself"}, {"source_code": "a = $<.read.split.map(&:to_i)\np (1.upto(a[0]).map do |i|\n c = 1\n c += 1 while (i = a[i]) != -1\n c\nend.max)\n\n"}], "negative_code": [{"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# 5\n# -1 : 1\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 \uc5c6\uc74c\n# 1 : 2\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 1\ubc88\uc784\n# 2 : 3\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 2\ubc88\uc784\n# 1 : 4\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 1\ubc88\uc784\n# -1 : 5\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 \uc5c6\uc74c\n# transitive\ub97c \ud5c8\uc6a9\ud558\uc9c0 \uc54a\uc74c(2\uc758 \uc0c1\uc0ac\ub294 3\uc778\ub370, 3\uc758 \uc0c1\uc0ac\ub294 1\uc774\uba74 2-1\uc740 \uac19\uc774 \uc788\uc744 \uc218 \uc5c6\ub2e4)\n\nn = gets.to_i\nee = []\nLOCATED = 2001\nn.times {\n ee << gets.to_i - 1 # -1 -> -2\n}\ngroups = 0\ni = 0\n# p ee\nwhile ee.count(LOCATED) < n\n forming = []\n forming << i\n \n loop do\n i += 1\n break if i >= n\n \n if ee[i] == LOCATED\n next\n else\n sup_resides_in_forming = false\n j = i\n while j < ee.length\n if ee[j] == LOCATED || ee[j] < 0\n # safely append it\n break\n elsif forming.include?(ee[j])\n sup_resides_in_forming = true\n break\n else\n j = ee[j]\n end\n end\n\n unless sup_resides_in_forming\n forming << i\n end\n end\n end\n\n # p forming\n unless forming.empty?\n # if reaches end, group them and clear\n forming.each { |idx|\n ee[idx] = LOCATED\n }\n groups += 1\n forming.clear\n end\n\n # p ee\n ni = ee.index { |x| x != LOCATED }\n if ni == nil\n # p \"--- #{ni}\"\n break\n else\n i = ni\n end\nend\n\nputs groups"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\nn = gets.to_i\nee = []\nn.times {\n ee << gets.to_i\n}\n\nee.sort!\nprev = nil\nbcounter = 0\nee.each { |i|\n if prev != i\n bcounter += 1\n prev = i\n end\n}\n\nputs bcounter"}, {"source_code": "# coding: utf-8\n\n# if __FILE__ == $0\n# end\n\n# 5\n# -1 : 1\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 \uc5c6\uc74c\n# 1 : 2\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 1\ubc88\uc784\n# 2 : 3\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 2\ubc88\uc784\n# 1 : 4\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 1\ubc88\uc784\n# -1 : 5\ubc88 \uc0ac\uc6d0\uc758 \uc0c1\uc0ac\ub294 \uc5c6\uc74c\n# transitive\ub97c \ud5c8\uc6a9\ud558\uc9c0 \uc54a\uc74c(2\uc758 \uc0c1\uc0ac\ub294 3\uc778\ub370, 3\uc758 \uc0c1\uc0ac\ub294 1\uc774\uba74 2-1\uc740 \uac19\uc774 \uc788\uc744 \uc218 \uc5c6\ub2e4)\n\nn = gets.to_i\nee = []\nLOCATED = 2001\nn.times {\n ee << gets.to_i - 1 # -1 -> -2\n}\ngroups = 0\ni = 0\n# p ee\nwhile ee.count(LOCATED) < n\n forming = []\n forming << i\n \n loop do\n i += 1\n break if i >= n\n \n if ee[i] == LOCATED\n next\n else\n sup_resides_in_forming = false\n j = i\n while j < ee.length && !sup_resides_in_forming\n if ee[j] == LOCATED\n # safely append it\n break\n elsif ee[j] < 0\n # check him/herself is a superior from someone\n for idx in forming\n sup = ee[idx]\n if sup == j\n sup_resides_in_forming = true\n break\n end\n end\n\n break\n elsif forming.include?(ee[j])\n sup_resides_in_forming = true\n break\n else\n j = ee[j]\n end\n end\n\n unless sup_resides_in_forming\n forming << i\n end\n end\n end\n\n # p forming\n unless forming.empty?\n # if reaches end, group them and clear\n forming.each { |idx|\n ee[idx] = LOCATED\n }\n groups += 1\n forming.clear\n end\n\n # p ee\n ni = ee.index { |x| x != LOCATED }\n if ni == nil\n # p \"--- #{ni}\"\n break\n else\n i = ni\n end\nend\n\nputs groups"}, {"source_code": "n = gets.to_i\nh = Hash.new(0)\nn.times do\n i = gets.to_i\n h[i] += 1 if i != -1\nend\np h.values.max + 1\n"}, {"source_code": "n = gets.to_i\n\nputs 1 + (1..n).count { gets.to_i == -1 }\n"}, {"source_code": "# 115A\n\nclass Node\n attr_accessor :parent\n attr_reader :children\n\n def initialize()\n @children = []\n end\n\n def len\n @children.size > 0 ? @children.map(&:len).max + 1 : 1\n end\nend\n\nn = gets.to_i\nnodes = Array.new(n)\nn.times { |i|\n p = gets.to_i - 1\n node = nodes[i] || Node.new\n if p >= 0\n parent = nodes[p] || Node.new\n node.parent = parent\n parent.children << node\n nodes[p] = parent\n end\n nodes[i] = node\n if i >= 90\n puts p\n end\n}\n\nputs nodes.select { |node| node.parent.nil? }.map(&:len).max"}, {"source_code": "n = gets.chomp.to_i\nh = Hash.new\n\n1.upto(n).each do |i|\n\tv = gets.chomp.to_i\n\th[v] ||= []\n\th[v] << i\nend\n\n# p h\nvisited = Hash.new\nif !h[-1].nil?\n\tvisited[-1] = 1\nend\n\n1.upto(n) do |i|\n\tnext if h[i].nil? || !visited[i].nil?\n\tvisited[i] = 1\n\tq = Queue.new\n\tq.push(i)\n\twhile(!q.empty?)\n\t\tf = q.pop\n\t\th[f].each do |x|\n\t\t\tif visited[x].nil?\n\t\t\t\tvisited[x] = visited[f] + 1\n\t\t\t\tif !h[x].nil?\n\t\t\t\t\tq.push(x)\n\t\t\t\tend \n\t\t\tend\n\t\tend\n\tend\nend\n\nprint visited.values.max"}, {"source_code": "n = gets.chomp.to_i\nh = Hash.new\n\n1.upto(n).each do |i|\n\tv = gets.chomp.to_i\n\th[v] ||= []\n\th[v] << i\nend\n\n# p h\nac = 0\nif !h[-1].nil?\n\tac += 1\nend\n\nvisited = Hash.new\n\n1.upto(n) do |i|\n\tnext if h[i].nil? || !visited[i].nil?\n\tvisited[i] = 1\n\tq = Queue.new\n\tq.push(i)\n\twhile(!q.empty?)\n\t\tf = q.pop\n\t\tnext if h[f].nil?\n\n\t\th[f].each do |x|\n\t\t\tif visited[x].nil?\n\t\t\t\tvisited[x] = visited[f] + 1\n\t\t\t\tac = [ac, visited[x]].max\n\t\t\t\tq.push(x)\n\t\t\tend\n\t\tend\n\tend\nend\n\nprint ac"}, {"source_code": "class List\n attr_accessor :element, :next_elem\n\n def initialize(element, next_elem)\n @element = element\n @next_elem = next_elem\n end\nend\n\nclass Graph\n attr_accessor :vertices\n\n def initialize(vertices)\n @vertices = vertices\n end\n\n def add_edge(index1, index2)\n if vertices[index1].nil? then\n vertices[index1] = List.new(index2, nil)\n else\n vert = List.new(index2, vertices[index1])\n vertices[index1] = List.new(index2, vertices[index1])\n end\n end\n\n def print_edges\n vertices.each_with_index do |vertex, index|\n while !vertex.nil? do \n # puts \"edge #{index} - #{vertex.element}\"\n vertex = vertex.next_elem\n end\n end\n end\nend\n\ndef depth(graph, index)\n return 1 if graph.vertices[index].nil?\n max_depth = depth(graph, graph.vertices[index].element)\n next_vertex = graph.vertices[index].next_elem\n while !next_vertex.nil? do\n current_max_depth = depth(graph, next_vertex.element) \n max_depth = [max_depth, current_max_depth].max\n next_vertex = next_vertex.next_elem\n end\n return max_depth + 1\nend\n\nemployees = Graph.new([])\nroot_managers = []\nn = gets.strip.to_i\nn.times do |i|\n manager = gets.strip.to_i\n if manager == -1 then\n root_managers.push(i)\n else\n employees.add_edge(manager - 1, i)\n end\nend \nemployees.print_edges\n# puts \"root managerts: #{root_managers.join(\" \")}\"\nmax_depth = 0\nroot_managers.each do |i|\n current_depth = 0\n if !employees.vertices[i].nil? \n max_depth = [depth(employees, i), max_depth].max\n end\nend\nputs max_depth\n"}], "src_uid": "8d911f79dde31f2c6f62e73b925e6996"} {"source_code": "t = gets.to_i\r\n(1..t).each do\r\n n = gets.to_i\r\n s = 0\r\n p = 1\r\n i = 2\r\n while n > 0\r\n d = i / p.gcd(i)\r\n s += i * (n - n / d)\r\n n /= d\r\n p *= d\r\n i += 1\r\n end\r\n puts s % (10 ** 9 + 7)\r\nend", "positive_code": [{"source_code": "ff=[1,2,3,2,5,1,7,2,3,1,11,1,13,1,1,2,17,1,19,1,1,1,23,1,5,1,3,1,29,1,31,2,1,1,1,1,37,1,1,1,41]\r\nf=[1]\r\n41.times do |i|\r\n f << f[-1]*ff[i]\r\nend\r\nm=1000000007\r\ngets.to_i.times do\r\n n=gets.to_i\r\n c=0\r\n l=0\r\n 41.downto(1) do |k|\r\n ll=n/f[k]\r\n# p [k,ll,n,f[k]] if n==12\r\n c=(c+(ll-l)*(k+1))%m\r\n l=ll\r\n# p [k,c] if n==12\r\n end\r\n puts c\r\nend\r\n"}], "negative_code": [], "src_uid": "2b15a299c25254f265cce106dffd6174"} {"source_code": "#!/usr/bin/ruby\n\nn, k = STDIN.readline.split.map {|s| s.to_i }\narr = STDIN.readline.split.map {|s| s.to_i }.sort\nsums = [0]\nsum = 0\narr.each {|x| sums.push(sum += x) }\nbest_count, best_value = -1, -1\nn.times do |i|\n\tlow, high = 0, i\n\twhile low != high\n\t\tpos = (low+high)/2\n\t\twidth = i-pos+1\n\t\tneed = width*arr[i] - sums[i+1] + sums[pos]\n\t\tif need > k\n\t\t\tlow = pos+1\n\t\telse\n\t\t\thigh = pos\n\t\tend\n\tend\n\tcount = i-low+1\n\tif count > best_count\n\t\tbest_count = count\n\t\tbest_value = arr[i]\n\tend\nend\nputs '%d %d' % [best_count, best_value]\n", "positive_code": [{"source_code": "#!/usr/bin/ruby\n\nn, k = STDIN.readline.split.map {|s| s.to_i }\narr = STDIN.readline.split.map {|s| s.to_i }.sort\nsums = [0]\nsum = 0\narr.each {|x| sums.push(sum += x) }\nbest_count, best_value = 1, arr[0]\npos = 0\n(1..n-1).each do |i|\n\twhile true\n\t\tcount = i-pos+1\n\t\tneed = count*arr[i] - sums[i+1] + sums[pos]\n\t\tif need <= k\n\t\t\tif count > best_count\n\t\t\t\tbest_count = count\n\t\t\t\tbest_value = arr[i]\n\t\t\tend\n\t\t\tbreak\n\t\tend\n\t\tpos += 1\n\tend\nend\nputs '%d %d' % [best_count, best_value]\n"}], "negative_code": [], "src_uid": "3791d1a504b39eb2e72472bcfd9a7e22"} {"source_code": "def gs() = gets.chomp\r\ndef gi() = gets.to_i\r\ndef gli() = gets.split.map(&:to_i)\r\ndef cyesno(x) = x ? :Yes : :No\r\ndef uyesno(x) = x ? :YES : :NO\r\n\r\nT = gi\r\nT.times do\r\n s = gs.split(\"\").map(&:to_i)\r\n if s.count { |x| x.even? }.zero?\r\n puts '-1'\r\n else\r\n if s[-1].even?\r\n puts 0\r\n elsif s[0].even?\r\n puts 1\r\n else\r\n puts 2\r\n end\r\n end\r\nend", "positive_code": [{"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |inp|\r\n if inp.to_i % 2 == 0\r\n puts \"0\"\r\n next\r\n end\r\n if !inp.chars.any?{|c| c.to_i % 2 == 0}\r\n puts \"-1\"\r\n next\r\n end\r\n if inp[0].to_i % 2 == 0\r\n puts \"1\"\r\n next\r\n end\r\n\r\n puts \"2\"\r\nend"}, {"source_code": "t = gets.to_i\r\nans = []\r\nt.times do |i|\r\n n = gets.chomp.split(\"\").map(&:to_i)\r\n if n[-1] % 2 == 0\r\n ans << 0\r\n elsif n[0] % 2 == 0\r\n ans << 1\r\n elsif n.any?{|v| v%2==0}\r\n ans << 2\r\n else\r\n ans << -1\r\n end\r\nend\r\nputs ans"}, {"source_code": "def solve\n n = gets.strip.split('').map(&:to_i)\n if n.last.even?\n puts 0\n elsif n.first.even?\n puts 1\n elsif n.any?(&:even?)\n puts 2\n else\n puts '-1'\n end\nend\n\n\ngets.strip.to_i.times { solve }\n"}, {"source_code": "t = gets.to_i\nt.times do\n s = gets.chomp.chars.map(&:to_i)\n if s.all?(&:odd?)\n puts -1\n elsif s[-1].even?\n puts 0\n elsif s[0].even?\n puts 1\n else\n puts 2\n end\nend"}, {"source_code": "t = gets.split\r\nt = t[0].to_i\r\n\r\nfor i in 0..t-1 do\r\n b = gets.split\r\n a = b[0].split(\"\")\r\n if b[0].to_i % 2 == 0\r\n puts 0\r\n elsif a[0].to_i % 2 == 0\r\n puts 1\r\n else\r\n n = a.length\r\n s = 0\r\n for j in 1..n-1 do\r\n if a[j].to_i % 2 == 0\r\n puts 2\r\n s = 1\r\n break\r\n end\r\n end\r\n if s==0\r\n puts -1\r\n end\r\n end\r\nend"}], "negative_code": [{"source_code": "inputs = STDIN.read.strip.split(\"\\n\")\r\ninputs.shift\r\n\r\ninputs.each do |inp|\r\n if inp.to_i % 2 == 0\r\n puts \"0\"\r\n next\r\n end\r\n if inp.length == 1\r\n puts \"-1\"\r\n next\r\n end\r\n if inp[0].to_i % 2 == 0\r\n puts \"1\"\r\n next\r\n end\r\n\r\n puts \"2\"\r\nend"}], "src_uid": "03e5f71810b10318fed344878d226a10"} {"source_code": "_n = STDIN.gets.chomp.to_i\nxs = STDIN.gets.chomp.split.map { |x| x.to_i }\n\ndef sum(arr)\n arr.inject(0) { |sum, x| sum + x }\nend\n\np_even_sum = xs.select { |x| x > 0 && x % 2 == 0 }.inject(0) { |sum, x| sum + x }\np_odds = xs.select { |x| x > 0 && x % 2 == 1 }.sort\nm_odd = xs.select { |x| x < 0 && x % 2 == 1 }.max\n\nanswer = p_even_sum\n\nif p_odds.length == 0\n answer += m_odd\nelse\n if p_odds.length % 2 == 0\n if !m_odd.nil? && m_odd + p_odds.first > 0\n answer += m_odd\n else\n p_odds.shift\n end\n end\n # p_odds.shift if p_odds.length % 2 == 0\n answer += sum(p_odds)\nend\n\nputs answer\n\n# -6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\n", "positive_code": [{"source_code": "n = gets.strip.to_i\ndata = gets.split.map(&:to_i)\n\neven = data.select { |x| x > 0 and x % 2 == 0 }\nodd_pos = data.select { |x| x > 0 and x % 2 == 1 }\nodd_neg = data.select { |x| x < 0 and x % 2 == 1 }\n\nif odd_pos.length > 0\n odd_neg.push(-odd_pos.min)\n exchange = (odd_pos.length % 2 == 0 ? [-odd_pos.min, odd_neg.max].max : 0)\n puts (even.reduce(0, :+) + odd_pos.reduce(:+) + exchange)\nelse\n puts (even.reduce(0, :+) + odd_neg.max)\nend\n\n"}, {"source_code": "gets\nres, aa = 0, []\ngets.split.map(&:to_i).each do |a|\n if a & 1 == 1\n aa.push(a)\n elsif a > 0\n res += a\n end\nend\naa.sort!\naa.shift if aa.length & 1 == 0\nres += aa.pop\nuntil aa.empty? do\n a = aa.pop + aa.pop\n break if a <= 0\n res += a\nend\np res"}, {"source_code": "def ascan; gets.split.map(&:to_i); end\ndef scan; gets.to_i; end\n\ngets\naa = ascan.sort!\n\nao = []\nae = []\naa.each{|e| if e.odd? ; ao << e ; else ; ae << e ; end }\n\nbest = ae.inject(0){|s,e| 0 < e ? s+e : s}\n\nbest += ao.pop\n\nwhile 2<=ao.size\n x,y = ao.pop(2)\n break if x+y <= 0\n best += x+y\nend\n\np best"}, {"source_code": "gets\nres, aa = 0, []\ngets.split.map(&:to_i).each do |a|\n if a & 1 == 1\n aa.push(a)\n elsif a > 0\n res += a\n end\nend\naa.sort!\naa.shift if aa.length & 1 == 0\nres += aa.pop\nuntil aa.empty? || (a = aa.pop + aa.pop) <= 0\n res += a\nend\np res"}], "negative_code": [{"source_code": "_n = STDIN.gets.chomp.to_i\nxs = STDIN.gets.chomp.split.map { |x| x.to_i }\n\ndef sum(arr)\n arr.inject(0) { |sum, x| sum + x }\nend\n\np_even_sum = xs.select { |x| x > 0 && x % 2 == 0 }.inject(0) { |sum, x| sum + x }\np_odds = xs.select { |x| x > 0 && x % 2 == 1 }.sort\nm_odd = xs.select { |x| x < 0 && x % 2 == 1 }.first\n\nanswer = p_even_sum\n\nif p_odds.length == 0\n answer += m_odd\nelse\n p_odds.shift if p_odds.length % 2 == 0\n answer += sum(p_odds)\nend\n\nputs answer\n\n# -6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\n"}, {"source_code": "_n = STDIN.gets.chomp.to_i\nxs = STDIN.gets.chomp.split.map { |x| x.to_i }\n\ndef sum(arr)\n arr.inject(0) { |sum, x| sum + x }\nend\n\np_even_sum = xs.select { |x| x > 0 && x % 2 == 0 }.inject(0) { |sum, x| sum + x }\np_odds = xs.select { |x| x > 0 && x % 2 == 1 }.sort\nm_odd = xs.select { |x| x < 0 && x % 2 == 1 }.max\n\nanswer = p_even_sum\n\nif p_odds.length == 0\n answer += m_odd\nelse\n p_odds.shift if p_odds.length % 2 == 0\n answer += sum(p_odds)\nend\n\nputs answer\n\n# -6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\n"}, {"source_code": "_n = STDIN.gets.chomp.to_i\nxs = STDIN.gets.chomp.split.map { |x| x.to_i }\n\nmax_odd = nil\nmax_even = 0\n\nxs.each do |x|\n if x % 2 == 1\n if max_odd.nil?\n max_odd = x\n else\n max_odd = [ max_odd, max_even + x ].max\n max_even = [ max_even, max_odd + x ].max\n end\n else\n max_even = [ max_even, max_even + x ].max\n end\nend\n\nputs max_odd\n"}, {"source_code": "def ascan; gets.split.map(&:to_i); end\ndef scan; gets.to_i; end\n\ngets\naa = ascan.sort!\n\nao = []\nae = []\naa.each{|e| if e.odd? ; ao << e ; else ; ae << e ; end }\n\nbest = ae.inject(0){|s,e| 0 < e ? e : 0}\n\nbest += ao.pop\n\nwhile 2<=ao.size\n x,y = ao.pop(2)\n break if x+y <= 0\n best += x+y\nend\n\np best"}, {"source_code": "n = gets.strip.to_i\ndata = gets.split.map(&:to_i)\n\neven = data.select { |x| x > 0 and x % 2 == 0 }\nodd_pos = data.select { |x| x > 0 and x % 2 == 1 }\nodd_neg = data.select { |x| x < 0 and x % 2 == 1 }\n\nif odd_pos.length > 0\n puts (even.reduce(0, :+) + odd_pos.reduce(:+) - (odd_pos.length % 2 == 0 ? odd_pos.min : 0))\nelse\n puts (even.reduce(0, :+) + odd_neg.max)\nend\n\n"}, {"source_code": "n = gets.strip.to_i\ndata = gets.split.map(&:to_i)\n\neven = data.select { |x| x > 0 and x % 2 == 0 }\nodd_pos = data.select { |x| x > 0 and x % 2 == 1 }\nodd_neg = data.select { |x| x < 0 and x % 2 == 1 }\n\nif odd_pos.length > 0\n puts (even.reduce(0, :+) + odd_pos.reduce(:+))\nelse\n puts (even.reduce(0, :+) + odd_neg.max)\nend\n\n"}, {"source_code": "gets\nres, aa = 0, []\n\"-2 2 -3 1\".split.map(&:to_i).each do |a|\n if a & 1 == 1\n aa.push(a)\n elsif a > 0\n res += a\n end\nend\naa.sort!\naa.shift if aa.length & 1 == 0\nres += aa.pop\nuntil aa.empty? do\n a = aa.pop + aa.pop\n break if a <= 0\n res += a\nend\np res"}], "src_uid": "76dd49c5545770a1dfbb2da4140199c1"} {"source_code": "m = gets.to_i\n\nq = gets.split(\" \").collect{|x| x.to_i}\nn = gets.to_i\na = gets.split(\" \").collect{|x| x.to_i}\n\nresult = 0\n\na.sort! { |a, b| b <=> a }\nqm = q.min\n\nt = qm\nk = 0\n\na.each_index { |i|\n\tif t > 0\n\t\tresult += a[i]\n\t\tt -= 1\n\t\tk = 2\n\telsif k > 0\n\t\tk -= 1\n\t\tif k == 0\n\t\t\tt= qm\n\t\tend\n\tend\n}\n\nputs result", "positive_code": [{"source_code": "m=gets.to_i\nmin=gets.split.map(&:to_i).min\nn=gets.to_i\n\na=gets.split.map(&:to_i).sort {|a,b| b<=>a}\n\ni=0\nans=0\nwhile i(other)\n val<=>other.val\n end \nend\n\npairs=[nil]*10\n10.times {|i| pairs[i]=Pair.new(0,0)}\n\nm=gets.to_i\nmin=gets.split.map(&:to_i).min\nn=gets.to_i\n\na=gets.split.map(&:to_i).sort {|a,b| b<=>a}\n\ni=0\nans=0\nwhile i(other)\n val<=>other.val\n end \nend\n\npair=Pair.new(0,0)\nm=gets.to_i\nmin=gets.split.map(&:to_i).min\nn=gets.to_i\n\na=gets.split.map(&:to_i).sort {|a,b| b<=>a}\n\ni=0\nans=0\nwhile i(other)\n val<=>other.val\n end \nend\n\nm=gets.to_i\nmin=gets.split.map(&:to_i).min\nn=gets.to_i\n\na=gets.split.map(&:to_i).sort {|a,b| b<=>a}\n\ni=0\nans=0\nwhile i= 0 do\n#\t\t\tputs \"START\"\n#\t\t\tputs i\n\t\t\tw.times do |u|\n#\t\t\t\tputs u\n\t\t\t\tsum += a[i - u] if i - u >= 0\n\t\t\tend\n\t\t\ti -= w\n\t\t\ti -= 2\n\t\tend\n#\t\t\tputs \"ENDS\"\n\t\tputs sum\n\tend\n\tTest_case = 1\n\tTest_case.times do\n\t\tmain()\n\tend\n}\n"}, {"source_code": "def run\n lines = ARGF.readlines\n\n m = lines.shift.chomp.to_i\n q = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n n = lines.shift.chomp.to_i\n a = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n\n a.sort_by! { |x| -x }\n q.sort!\n\n ans = 0\n a.each_slice(q.first + 2) do |items|\n ans += items[0, q.first].reduce(&:+)\n end\n\n puts ans\nend\n\nrun if $0 == __FILE__\n"}], "negative_code": [{"source_code": "def run\n lines = ARGF.readlines\n\n m = lines.shift.chomp.to_i\n q = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n n = lines.shift.chomp.to_i\n a = lines.shift.chomp.split(\" \").map {|x| x.to_i }\n\n a.sort_by! { |x| -x }\n costs = []\n\n sum = 0\n a.length.times do |i|\n sum += a[i]\n costs[i] = sum\n end\n costs.unshift(0)\n\n a.length.times do |i|\n q.each do |item|\n if item <= (a.length - i)\n sum = costs[i]\n\n item.times do |c|\n sum += a[i + c]\n end\n\n costs[i + item + 0] = sum if costs[i + item + 0] and costs[i + item + 0] > sum\n costs[i + item + 1] = sum if costs[i + item + 1] and costs[i + item + 1] > sum\n costs[i + item + 2] = sum if costs[i + item + 2] and costs[i + item + 2] > sum\n end\n end\n end\n\n puts costs[a.length]\nend\n\nrun if $0 == __FILE__\n"}], "src_uid": "08803b63ae803e4a76afe7258a4004aa"} {"source_code": "require 'mathn'\n\nMAX = 10 ** 5 + 10\n\nflag = Array.new(MAX, true)\nflag[0] = false\nflag[1] = false\n2.upto(Math::sqrt(MAX)) do |i|\n if flag[i]\n (2 * i).upto(MAX) do |j|\n flag[j] = false if j % i == 0\n end\n end\nend\n\n$diff = Array.new(MAX, 0)\n$diff[0] = 2\n$diff[1] = 1\n\nprev = MAX\nMAX.downto(2) do |i|\n if flag[i]\n prev = i\n $diff[i] = 0\n else\n $diff[i] = prev - i\n end\nend\n\ndef run\n m, n = ARGF.readline.split.map(&:to_i)\n\n ary = []\n ARGF.readlines.each do |line|\n ary << line.split.map(&:to_i)\n end\n\n min = 1 << 30\n m.times do |i|\n sum = 0\n n.times do |j|\n sum += $diff[ary[i][j]]\n end\n\n min = [min, sum].min\n end\n\n n.times do |i|\n sum = 0\n m.times do|j|\n sum += $diff[ary[j][i]]\n end\n\n min = [min, sum].min\n end\n\n puts min\nend\n\nrun if $0 == __FILE__\n", "positive_code": [{"source_code": "#!/usr/bin/ruby1.9\n\ndef eratosthenes(n)\n\tprimes = []\n\tsieve = (0..n).collect {|x| x}\n\tstart = 2\n\twhile true\n\t\twhile sieve[start] == 0\n\t\t\treturn primes if start == n\n\t\t\tstart += 1\n\t\tend\n\t\tprimes.push(start)\n\t\tpos = 2*start\n\t\twhile pos <= n\n\t\t\tsieve[pos] = 0\n\t\t\tpos += start\n\t\tend\n\t\tsieve[start] = 0\n\tend\nend\n\nprimes = eratosthenes(101*1000)\nup = Array.new(100*1000+1)\nprime_ix = 0\nprime = primes[prime_ix]\nup.length.times do |i|\n\tif i <= prime\n\t\tup[i] = prime\n\telse\n\t\tprime_ix += 1\n\t\tprime = up[i] = primes[prime_ix]\n\tend\nend\n\nr_num, c_num = STDIN.readline.split.collect {|s| s.to_i}\nr_totals = Array.new(r_num, 0)\nc_totals = Array.new(c_num, 0)\n\nr_num.times do |r|\n\trow = STDIN.readline.split.collect {|s| s.to_i}\n\tc_num.times do |c|\n\t\tx = row[c]\n\t\tr_totals[r] += up[x]-x\n\t\tc_totals[c] += up[x]-x\n\tend\nend\n\nputs [r_totals.min, c_totals.min].min\n\n"}, {"source_code": "require 'mathn'\nMAX = 10 ** 5 + 10\n\nflag = Array.new(MAX, true)\nflag[0] = false\nflag[1] = false\n2.upto(Math::sqrt(MAX)) do |i|\n if flag[i]\n (2 * i).upto(MAX) do |j|\n flag[j] = false if j % i == 0\n end\n end\nend\n\n$diff = Array.new(MAX, 0)\nprev = MAX\nMAX.downto(0) do |i|\n prev = i if flag[i]\n $diff[i] = prev - i\nend\n\ndef run\n m, n = ARGF.readline.split.map(&:to_i)\n\n ary = []\n ARGF.readlines.each do |line|\n ary << line.split.map(&:to_i)\n end\n\n list = []\n list += ary.map { |x| x.reduce(0) { |sum, y| sum + $diff[y] } }\n list += ary.transpose.map { |x| x.reduce(0) { |sum, y| sum + $diff[y] } }\n puts list.min\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "require 'mathn'\n\nMAX = 10 ** 5 + 10\n\nflag = Array.new(MAX, true)\nflag[0] = false\nflag[1] = false\n2.upto(Math::sqrt(MAX)) do |i|\n if flag[i]\n (2 * i).upto(MAX) do |j|\n flag[j] = false if j % i == 0\n end\n end\nend\n\n$diff = Array.new(MAX, 0)\nprev = MAX\nMAX.downto(0) do |i|\n if flag[i]\n prev = i\n $diff[i] = 0\n else\n $diff[i] = prev - i\n end\nend\n\ndef run\n m, n = ARGF.readline.split.map(&:to_i)\n\n ary = []\n ARGF.readlines.each do |line|\n ary << line.split.map(&:to_i)\n end\n\n list = []\n list += ary.map { |x| x.reduce(0) { |sum, y| sum + $diff[y] } }\n list += ary.transpose.map { |x| x.reduce(0) { |sum, y| sum + $diff[y] } }\n puts list.min\nend\n\nrun if $0 == __FILE__\n"}, {"source_code": "require 'prime'\n\nn, m = gets.split(' ').collect!{|i| i.to_i}\n\nk = []\nn.times do |j|\n\tk[j] = gets.split(' ').collect!{|i| i.to_i}\nend\n\nmin = 100000\ncolumn = Array.new(m, 0)\n\narr = []\npr = []\nPrime.each(100010) do |prime|\n pr << prime\nend\n# p = pr[0]\ni = 0\n(1..100000).each do |y|\n\ti += 1 if y > pr[i]\n\tarr[y] = pr[i]\nend\n\nn.times do |i|\n\trow = 0\n\tm.times do |j|\n\t\t# x = 0\n\t\t# y = k[i][j]\n\t\t# while !y.prime?\n\t\t# \tx += 1\n\t\t# \ty += 1\n\t\t# end\n\t\tx = arr[k[i][j]] - k[i][j]\n\t\trow += x\n\t\tcolumn[j] += x\n\tend\n\tmin = row if row < min\nend\n\ncolumn.each do |x|\n\tmin = x if x < min\nend\n\np min"}, {"source_code": "\ufeff# -*- encoding: utf-8 -*-\nrequire 'prime'\n\nn, m = gets.chomp.split(\" \").map{ |e| e.to_i }\nmatrix = []\nn.times do\n matrix << gets.chomp.split(\" \").map{ |e| e.to_i }\nend\nprimes = Prime.each(100000 + 1000).to_a\nmin = 100000 * [n, m].max\n\nmemo = []\nidx = 0\nfor i in 0 .. 100000 do\n if not i <= primes[idx]\n idx += 1\n end\n memo << primes[idx]\nend\n\n\nmatrix.concat matrix.transpose\n\nfor i in 0 .. (n + m - 1) do\n col = matrix[i]\n \n num = 0\n col.each do |n|\n num += memo[n] - n\n end\n min = [min, num].min\nend\n\nputs min\n\n\n\n \n\n"}], "negative_code": [{"source_code": "\ufeff# -*- encoding: utf-8 -*-\nrequire 'prime'\n\nclass Array\n def binary_search(val, left = 0, right = nil)\n right = self.size - 1 unless right\n mid = (left + right) / 2\n \n return nil if left > right\n \n a = (mid > 0) ? self[mid - 1] : 0 \n if val < self[mid] and val > a\n return self[mid]\n elsif val > self[mid]\n binary_search(val, mid + 1, right)\n else\n binary_search(val, left, mid - 1)\n end\n end\nend\n\nn, m = gets.chomp.split(\" \").map{ |e| e.to_i }\nmatrix = []\nn.times do\n matrix << gets.chomp.split(\" \").map{ |e| e.to_i }\nend\n# \u884c\u5217\u3092\u5165\u308c\u66ff\u3048\u305f\u3082\u306e\u3092\u7d50\u5408\nmatrix.concat matrix.transpose\nprimes = Prime.each(100000).to_a\nmin = 100000 * [n, m].max\nmemo = {}\n\nfor i in 0 .. (n + m - 1) do\n col = matrix[i]\n \n num = 0\n col.each do |n|\n if not primes.include? n\n if memo.include? n\n num += memo[n]\n else\n tmp = primes.binary_search(n)\n memo[n] = tmp\n \n num += tmp - n\n end\n end\n end\n min = [min, num].min\nend\n\nputs min\n\n\n\n \n\n"}], "src_uid": "d549f70d028a884f0313743c09c685f1"} {"source_code": "def is_alph(s)\n s = s.chars\n cur = ('a'.ord + s.size - 1).chr\n\n while !s.empty? && cur >= 'a'\n if s.first == cur\n s = s[1..]\n elsif s.last == cur\n s = s[0..-2]\n else\n break\n end\n cur = (cur.ord - 1).chr\n end\n\n s.empty? && (cur.ord + 1).chr == 'a'\nend\n\ngets.to_i.times {\n s = gets.strip\n puts(is_alph(s) ? 'YES' : 'NO')\n}\n", "positive_code": [{"source_code": "ALL_CHARS = 'abcdefghijklmnopqrstuvwxyz'.freeze\n\n\ndef solve(inp)\n orig_size = inp.size\n ptr = 0\n chars = ALL_CHARS[0...orig_size].reverse\n\n while inp.size > 0 do\n return false unless inp[0] == chars[ptr] || inp[-1] == chars[ptr]\n inp = inp.sub(chars[ptr], '')\n ptr += 1\n end\n\n orig_size == ptr\nend\n\nt = gets.chomp.to_i\nt.times do\n inp = gets.chomp\n solve(inp) ? puts(\"YES\\n\") : puts(\"NO\\n\")\nend\n"}], "negative_code": [], "src_uid": "801bf7c73c44c68eaa61c714d5aedf50"} {"source_code": "t = gets.to_i\r\n\r\nt.times do\r\n n = gets.to_i\r\n arr = gets.split(' ').map(&:to_i)\r\n\r\n puts arr[0] == arr.sort[0] ? 'YES' : 'NO'\r\nend", "positive_code": [{"source_code": "gets.to_i.times do\n _=gets.chomp.to_i\n arr=gets.chomp.split.map(&:to_i)\n if arr[0]==1\n puts \"Yes\"\n else\n puts \"No\"\n end\nend"}], "negative_code": [], "src_uid": "76b3667cce9e23675e21caf6926f608d"} {"source_code": "gets.to_i.times do\n n, q = gets.split.map(&:to_i)\n as = [0] + gets.split.map(&:to_i).sort_by { -_1 }\n (1...as.size).each { |i| as[i] += as[i - 1] }\n\n q.times do\n query = gets.to_i\n\n l = 0\n r = as.size\n while l + 1 < r\n m = (l + r) / 2\n if as[m] >= query\n r = m\n else\n l = m\n end\n end\n\n p -1 if r > n\n p r if r <= n\n end\nend\n", "positive_code": [{"source_code": "gets.to_i.times do\r\n n, q = gets.split.map(&:to_i)\r\n as = gets.split.map(&:to_i).sort.reverse\r\n sums = [0]\r\n as.each { |a| sums << sums.last + a }\r\n q.times do\r\n x = gets.to_i\r\n p sums.bsearch_index { |s| s >= x } || -1\r\n end\r\nend\r\n"}, {"source_code": "def solve\n n, q = gli\n b = gli.sort.reverse\n (1...n).each { |i| b[i] += b[i - 1] }\n q.times do\n d = gi\n z = b.bsearch_index { |x| x >= d }\n if z\n puts z + 1\n else\n puts(-1)\n end\n end\nend\n\nMOD = 10**9 + 7\ndef gs = gets.chomp\ndef gi = gets.to_i\ndef gli = gets.split.map(&:to_i)\ndef cyesno(x) = x ? :Yes : :No\ndef uyesno(x) = x ? :YES : :NO\n\ngets.to_i.times { solve }\n"}, {"source_code": "main = -> {\r\n t = int\r\n t.times do\r\n n, q = ints\r\n a = ints\r\n a.sort!\r\n a.reverse!\r\n sum = [0]\r\n a.each do |x|\r\n sum << sum[-1] + x\r\n end\r\n q.times do\r\n x = int\r\n puts sum.bsearch_index { |s| s >= x } || -1\r\n end\r\n end\r\n}\r\n\r\nDEBUG = true\r\nMOD = 10**9+7\r\n$yesno = %w(No Yes)\r\nYesNo = %w(No Yes)\r\nYESNO = %w(NO YES)\r\nINF = 10**18\r\n\r\nrequire \"set\"\r\nrequire \"prime\"\r\n\r\ndef int; gets.to_s.to_i end\r\ndef ints; gets.to_s.split.map { |s| s.to_i } end\r\ndef int1s; gets.to_s.split.map { |s| s.to_i - 1 } end\r\ndef float; gets.to_s.to_f end\r\ndef floats; gets.to_s.split.map { |s| s.to_f } end\r\ndef array_of(&convert); gets.to_s.split.map(&convert) end\r\ndef string; gets.to_s.chomp end\r\ndef strings; gets.to_s.split end\r\ndef rep(n, &b); Array.new(n, &b) end\r\ndef yes; puts $yesno[1] end\r\ndef no; puts $yesno[0] end\r\ndef yesno t; puts $yesno[t] end\r\ndef YesNo t; puts YesNo[t] end\r\ndef YESNO t; puts YESNO[t] end\r\ndef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end\r\ndef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end\r\ndef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end\r\ndef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end\r\ndef gcd(*xs); xs.inject(0, :gcd) end\r\ndef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end\r\ndef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end\r\ndef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join(\"\") } if DEBUG; grid end\r\ndef if_debug; yield if DEBUG end\r\n\r\nmodule Boolean\r\n def coerce(other); [other, to_i] end\r\n def +@; to_i end\r\n def to_int; to_i end\r\n def *(other); to_i * other end\r\nend\r\n\r\nclass TrueClass\r\n include Boolean\r\n def to_i; 1 end\r\nend\r\n\r\nclass FalseClass\r\n include Boolean\r\n def to_i; 0 end\r\nend\r\n\r\nclass Integer\r\n def div_ceil(y); (self + y - 1) / y end\r\n def mod_inv(mod = MOD); pow(mod-2, mod) end\r\n def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end\r\n def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end\r\n def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end\r\n def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster\r\n def bitbrute(&block); (1< 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end\r\n def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end\r\n def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end\r\nend\r\n\r\nclass Array\r\n def power(&block); (0 ... 1 << size).each(&block) end\r\n def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end\r\n def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end\r\n def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end\r\n def cumdiff(range); self[range.end_open] - self[range.begin]; end\r\n def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end\r\nend\r\n\r\nmodule Enumerable\r\n def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end\r\n def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end\r\nend\r\n\r\nmain[]"}], "negative_code": [], "src_uid": "a3df5d51538658e8c9356f9e848debcf"}