Universal Cup Judging System

Universal Cup

時間限制: 2.0 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓
统计

Yachiyo has an integer sequence $S$ of length $n$, and each position in the sequence (indexed from $1$) has a weight $a_i$.

She can copy this sequence together with its weights and concatenate the copies end to end several times. Specifically, if she chooses to concatenate $m$ copies in total ($m \ge 1$), she will obtain a new sequence $S'$ of length $m \times n$ and a corresponding new weight sequence $a'$. For any $0 \le c < m$ and $1 \le i \le n$, we have $S'_{cn+i} = S_i$ and $a'_{cn+i} = a_i$.

Now Yachiyo wants to perform several elimination operations on the resulting sequence $S'$ (possibly zero times). Each operation works as follows:

  • Choose two indices $i, j$ such that $1 \le i < j \le |S'|$ and $S'_i = S'_j$.
  • Delete the $(i + 1)$-th through $j$-th elements from both $S'$ and $a'$.
  • After the operation, the remaining elements are compacted in their original order, and the total length decreases accordingly.

Yachiyo wants to know: after choosing an appropriate number of copies and performing any number of elimination operations, what is the minimum possible sum of the weights of the remaining sequence? Also, under the condition that this minimum weight sum is achieved, what is the minimum number of copies of the original sequence needed (that is, the minimum $m$)?

Input

The input contains three lines.

The first line contains an integer $n$ ($1 \le n \le 3 \times 10^5$), the length of the initial sequence $S$.

The second line contains $n$ integers $S_1, S_2, \dots, S_n$ ($1 \le S_i \le 3 \times 10^5$), representing the elements of the initial sequence $S$.

The third line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 3 \times 10^5$), representing the weight of each position.

Output

Output one line containing two integers separated by a space:

  • The first integer is the minimum possible sum of weights of the remaining sequence after the operations.
  • The second integer is the minimum total number of copies of the original sequence needed to achieve that minimum weight sum.

Example

Input

6
1 1 4 5 1 4
1 9 1 9 8 10

Output

2 1

Note

In this sample, the optimal strategy is to use only $1$ copy of the original sequence (that is, $m = 1$, with no extra copying).

The initial sequence $S'$ is $[1, 1, 4, 5, 1, 4]$, and the corresponding weight sequence $a'$ is $[1, 9, 1, 9, 8, 10]$.

Yachiyo can perform the following two operations:

  1. Choose $i = 1, j = 2$ (at this time $S'_1 = S'_2 = 1$), and delete the $(i + 1)$-th through $j$-th elements (that is, delete the $2$-nd element). After the operation, $S'$ becomes $[1, 4, 5, 1, 4]$, and $a'$ becomes $[1, 1, 9, 8, 10]$.
  2. In the new sequence, choose $i = 2, j = 5$ (at this time $S'_2 = S'_5 = 4$), and delete the $(i + 1)$-th through $j$-th elements (that is, delete the $3$-rd, $4$-th, and $5$-th elements). After the operation, the remaining $S'$ is $[1, 4]$, and the remaining $a'$ is $[1, 1]$.

At this point, no further elimination is possible, and the sum of the remaining weights is $1 + 1 = 2$. It can be proved that under any number of copies and any sequence of operations, the weight sum cannot be smaller than $2$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.