P12556 [AOJ] Black Company
普及
题目描述

Example

Input

3
1 3 3
2
1 2
1 3

Output

5

输入格式

见题面

输出格式

见题面

样例输入
3 1 3 3 2 1 2 1 3
样例输出
5