#coding = utf-8 require "set" 💩 = gets.to_i; 💩💩 = gets.split().map(&:to_i); 💩💩💩💩 = 💩💩.sort().uniq() 👾 = 💩💩💩💩.size; for 🚽 in 0...💩 do 👇 = -1; 👆 = 👾-1; while (👆-👇>1) do 💪 = (👇+👆)/2; if 💩💩[🚽] <= 💩💩💩💩[💪] then 👆 = 💪; else 👇 = 💪; end end 💩💩[🚽] = 👆; end 🐕💩 = Array.new(👾); 🐈💩 = Array.new(👾); 0.upto(💩-1) { |🚽| 🐕💩[ 💩💩[🚽] ] = 🚽; } (💩-1).downto(0) { |🚽| 🐈💩[ 💩💩[🚽] ] = 🚽; } $👉💩 = Array.new(👾+5, 0); $💩👈 = 👾; def うんこ(🐦💩,x) 🐦💩+=1; while(🐦💩<=$💩👈) do $👉💩[🐦💩] += x; 🐦💩 += 🐦💩&-🐦💩; end end def 💩_bound(💩💩💩💩💩) if (💩💩💩💩💩<=0) then return 0; end ___💩💩💩 = 0; _____💩💩💩 = 1; while (_____💩💩💩<<1) <= $💩👈 do _____💩💩💩<<=1; end while _____💩💩💩>0 do if(___💩💩💩+_____💩💩💩<=$💩👈 && $👉💩[___💩💩💩+_____💩💩💩] < 💩💩💩💩💩) then 💩💩💩💩💩 -= $👉💩[___💩💩💩+_____💩💩💩]; ___💩💩💩 += _____💩💩💩; end _____💩💩💩 >>= 1; end return ___💩💩💩+1; end 🎅 = Array.new(💩, "🎅"); contain_💩 = 0; 0.upto(💩-1) { |🚽| if 🐈💩[ 💩💩[🚽] ] == 🚽 then うんこ(💩💩[🚽], 1); contain_💩 += 1; end 🎅[🚽] = 💩💩💩💩[💩_bound(contain_💩)-1]; if 🐕💩[ 💩💩[🚽] ] == 🚽 then うんこ(💩💩[🚽], -1); contain_💩 -= 1; end } puts 🎅.join(" ")