func main() var n: int :: cui@inputInt() var a: []int :: #[n]int for i(0, n - 1) do a[i] :: cui@inputInt() end for var mid: int :: 0 var b: []int :: #[n]int for i(0, n - 1) do b[i] :: cui@inputInt() do mid :+ b[i] end for do mid :/ 2 var c: []@C :: #[n]@C for i(0, n - 1) do c[i] :: (#@C).init(a[i], b[i]) end for do c.sort() var sum: int :: 0 var x: int :: 0 for i(0, n - 1) do sum :+ c[i].b if(sum >= mid) do x :: c[i].a break i end if end for var ans: int :: 0 for i(0, n - 1) do ans :+ c[i].b * (x - c[i].a).abs() end for do cui@print("\{x} \{ans}\n") end func class C() +var a: int +var b: int +func init(a: int, b: int): C do me.a :: a do me.b :: b ret me end func +*func cmp(t: kuin@Class): int if(me.a < (t $ C).a) ret - 1 elif(me.a > (t $ C).a) ret 1 end if ret 0 end func end class