lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end class CulSum(T) def initialize(a : Array(T)) @n = a.size @s = Array(T).new(@n + 1, T.zero) @n.times do |i| @s[i + 1] = @s[i] + a[i] end end def initialize(@n : Int32, &f : Int32 -> T) @s = Array(T).new(@n + 1, T.zero) @n.times do |i| @s[i + 1] = @s[i] + yield(i) end end def initialize(a, &f) @n = a.size @s = Array(T).new(@n + 1, T.zero) @n.times do |i| @s[i + 1] = @s[i] + yield(a[i]) end end def [](l : Int32, r : Int32) l < r ? @s[r] - @s[l] : 0 end def [](i : Int32) @s[i] end def [](r : Range(Int32, Int32)) @s[r.exclusive? ? r.end : r.end + 1] - @s[r.begin] end def to_a (0...@n).map { |i| self[i..i] } end end n = read_line.to_i a = read_line.split.map(&.to_i) b = read_line.split.map(&.to_i64) MAX_A = 2 * 10**6 c = Array(Int64).new(MAX_A + 1, 0) n.times { |i| c[a[i] + MAX_A // 2] += b[i] } c_sum = CulSum.new(c) val_left = Array(Int64).new(MAX_A + 1, 0) (1..MAX_A).each do |i| val_left[i] = val_left[i - 1] + c_sum[0...i] end val_right = Array(Int64).new(MAX_A + 1, 0) (0...MAX_A).reverse_each do |i| val_right[i] = val_right[i + 1] + c_sum[i + 1..MAX_A] end min_val, min_index = (0..MAX_A).map { |i| val_left[i] + val_right[i] }.each_with_index.min puts [min_index - MAX_A // 2, min_val].join(' ')