Codeforces Beta Round 79 (Div. 2 Only)


A. Clothes
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2 3
1 2
2 3
3 1
Output
6
Input
3 2
2 3 4
2 3
2 1
Output
-1
Input
4 4
1 1 1 1
1 2
2 3
3 4
4 1
Output
-1
----------------------------------------------------------------------------------------------------
B. Sum of Digits
time limit per test: 2 seconds
memory limit per test: 265 megabytes
input: standard input
output: standard output

Examples
Input
0
Output
0
Input
10
Output
1
Input
991
Output
3
----------------------------------------------------------------------------------------------------
C. Homework
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
aaaaa
4
Output
1
aaaaa
Input
abacaba
4
Output
1
aaaa
Input
abcdefgh
10
Output
0
----------------------------------------------------------------------------------------------------
D. Buses
time limit per test: 2 seconds
memory limit per test: 265 megabytes
input: standard input
output: standard output

Examples
Input
2 2
0 1
1 2
Output
1
Input
3 2
0 1
1 2
Output
0
Input
5 5
0 1
0 2
0 3
0 4
0 5
Output
16
----------------------------------------------------------------------------------------------------
E. Vectors
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
0 0
1 1
0 1
Output
YES
Input
0 0
1 1
1 1
Output
YES
Input
0 0
1 1
2 2
Output
NO
----------------------------------------------------------------------------------------------------
