Codeforces Beta Round 10


A. Power Consumption Calculation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 3 2 1 5 10
0 10
Output
30
Input
2 8 4 2 5 10
20 30
50 100
Output
570
----------------------------------------------------------------------------------------------------
B. Cinema Cashier
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
1 1
Output
1 1 1
-1
Input
4 3
1 2 3 1
Output
2 2 2
1 1 2
3 1 3
2 1 1
----------------------------------------------------------------------------------------------------
C. Digital Root
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
Output
2
Input
5
Output
6
----------------------------------------------------------------------------------------------------
D. LCIS
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
2 3 1 6 5 4 6
4
1 3 5 6
Output
3
3 5 6 
Input
5
1 2 0 2 1
3
1 0 1
Output
2
0 1 
----------------------------------------------------------------------------------------------------
E. Greedy Change
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
25 10 5 2 1
Output
-1
Input
3
4 3 1
Output
6
----------------------------------------------------------------------------------------------------
