367. Contest

Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



In compliance with the traditional rules of ACM International Collegiate Programming Contest teams are ranked according to the amount solved problems and penalty time. For the purpose of this problem we will define penalty time as a sum of minutes when all problems solved by the team were submitted (thus, let's think that all problems were accepted from the first attempt). For example, if some team solved three problems: on 10-th, 45-th and 123-rd minutes, the penalty time would be 10 + 45 + 123 = 178 minutes.

On one of numerous trainings one famous team was solving old competition it had solved previously. For each problem participants estimated time ti required to solve this problem. Moreover, they defined a set of constraints on problem solving. Each constraint is an ordered pair (a, b), denoting that the problem a must be solved before the problem b (i. e. if the problem b will be solved, than the problem a also must be solved, and must be solved earlier than the problem b). This is due to the fact that the problem a is a subtask of the problem b. Obviously the problem a is easier than the problem b, i. e. tatb. The training lasts T minutes.

What is the best performance can show the team? You may assume that the team will not do failed attempts and that they estimated time for solving each problem correctly. Calculate maximal number of problems that they can solve and the corresponding minimal penalty time. Please also determine which problems and in what order the team should solve.

Input
The first line of the input file contains two integer numbers N and T (1 ≤ N ≤ 1000; 1 ≤ T ≤ 109), where N is the number of problems, T is the duration of the training. The second line contains N integer numbers ti (1 ≤ ti ≤ 3500), where ti is the time required to solve i-th problem. The third line contains integer number M (0 ≤ M ≤ 10000) — number of constraints. Each of the next M lines contains one constraint represented by pair of integer numbers ai, bi (1 ≤ ai,biN; ai <> bi), denoting that the problem ai must be solved before the problem bi can be solved. It is guaranteed that taitbi. All numbers in the input file are integer.

Output
On the first line of the output file print the maximal number of problems that the team can solve and the corresponding minimal penalty time. On the second line print numbers of problems that need to be solved in the order they must be solved. Problems are numbered 1 through N. If there are several solutions, output any of them.

Example(s)
sample input
sample output
1 1
1
0
1 1
1

sample input
sample output
3 10
1 1 1
3
1 2
2 3
3 1
0 0

sample input
sample output
4 2
1 2 1 2
1
1 3
2 3
1 3




Online Contester Team © 2002 - 2010. All rights reserved.