A printable version(PDF) can be downloaded here.
Multiple input terminated by EOF. In this problem, N<=100000.
3 1 1 2 3 5 3 9 2 6 8 8 5 7 9 9 9 1 5
4 24 48
Migrated from old NTUJ.
JAG 2011 winter camp