# [Desmos](https://desmos.com/calculator), 93 bytes ``` C=(L[2...]-L)^2 g(L)=∑_{n=1}^{[1...C.count]}C[n] f(A,B)=sort(join(A,B),join(0,g(A),0,g(B))) ``` Ok this can probably be improved somehow but for now this is good enough. [Try It On Desmos!](https://www.desmos.com/calculator/qjs8xuw8r3) [Try It On Desmos! - Prettified](https://www.desmos.com/calculator/gcehwkjeta)