2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)


A. Union of Doubly Linked Lists
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
4 7
5 0
0 0
6 1
0 2
0 4
1 0
Output
4 7
5 6
0 5
6 1
3 2
2 4
1 0
----------------------------------------------------------------------------------------------------
B. Preparing for Merge Sort
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 3 2 5 4
Output
1 3 5 
2 4 
Input
4
4 3 2 1
Output
4 
3 
2 
1 
Input
4
10 30 50 101
Output
10 30 50 101 
----------------------------------------------------------------------------------------------------
C. Sum of Nestings
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1
Output
()(())
Input
4 6
Output
(((())))
Input
2 5
Output
Impossible
----------------------------------------------------------------------------------------------------
D. Dog Show
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
7
*..P*P*
Output
3
Input
10
.**PP.*P.*
Output
2
----------------------------------------------------------------------------------------------------
F. Berland Elections
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1 5 4
1 2 1 3
Output
1 3 3 
Input
3 1 5 3
1 3 1
Output
2 3 2 
Input
3 2 5 3
1 3 1
Output
1 2 2 
----------------------------------------------------------------------------------------------------
G. University Classes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
0101010
1010101
Output
1
Input
3
0101011
0011001
0110111
Output
3
----------------------------------------------------------------------------------------------------
H. Load Testing
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 4 3 2 5
Output
6
Input
5
1 2 2 2 1
Output
1
Input
7
10 20 40 50 70 90 30
Output
0
----------------------------------------------------------------------------------------------------
I. Noise Level
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 100 140
...
A*.
.B.
Output
3
Input
3 3 2 8
B*.
BB*
BBB
Output
4
Input
3 4 5 4
..*B
..**
D...
Output
7
----------------------------------------------------------------------------------------------------
J. Students Initiation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
2 1
1 3
2 3
2 5
Output
1
1 2
2 3
3 1
5 2
Input
4 3
1 2
1 3
1 4
Output
1
1 4
2 1
3 1
Input
4 6
1 2
4 1
4 2
3 2
4 3
1 3
Output
2
1 3
2 1
2 4
3 2
4 1
4 3
----------------------------------------------------------------------------------------------------
K. Travel Cards
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 5 3 1 8
BerBank University
University BerMall
University BerBank
Output
11
Input
4 2 1 300 1000
a A
A aa
aa AA
AA a
Output
5
----------------------------------------------------------------------------------------------------
L. Berland SU Computer Network
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2:3,2
1:1-1:3
2:1,2
Output
2
2 1
2 3
Input
5
4:2,5,3,4
1:4-1:1-2:5,3
4:4,5,2,1
4:2,1,3,5
1:3-3:4,2,1
Output
4
2 1
2 4
5 2
3 5
Input
3
1:2-1:3
1:1-1:3
1:1-1:2
Output
-1
----------------------------------------------------------------------------------------------------
M. Weather Tomorrow
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
10 5 0 -5 -10
Output
-15
Input
4
1 1 1 1
Output
1
Input
3
5 1 -5
Output
-5
Input
2
900 1000
Output
1100
----------------------------------------------------------------------------------------------------
