#P9160. multiset

multiset

Background

ZHY has many sets. When there are many sets, they become a multiset.

Problem Description

Given a multiset (elements in the set may repeat) SS, find the largest multiset TT such that TT is a proper subset of SS, and for every element ii in TT, either ii has no predecessor in SS, or the predecessor of ii in SS T\in T. If there are multiple sets with the same maximum size that satisfy the conditions, then choose the one with the largest sum of all elements. Output the size of TT and the sum of its elements.


The predecessor of a number xx in a set SS is defined as the maximum element yy among all elements in SS with y<xy < x.

Input Format

The first line contains a positive integer nn, representing the size of SS.

The second line contains nn positive integers, representing the elements in SS.

Output Format

Output one line with two integers. The first number is the size of TT, and the second number is the sum of all elements in TT.

4
4 5 1 4
3 10
6
1 4 2 8 5 7
5 19

Hint

Sample 1 Explanation

TT is {5,1,4}\{5,1,4\}.

Sample 2 Explanation

TT is {1,4,2,5,7}\{1,4,2,5,7\}.

Constraints

For 30%30\% of the testdata, n15n \le 15.

For 100%100\% of the testdata, 2n1052 \le n \le 10^5, and 11 \le elements in S109S \le 10^9.

Translated by ChatGPT 5